35 #include <linux/module.h>
37 #include <linux/pci.h>
38 #include <linux/netdevice.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
44 #include <linux/if_vlan.h>
48 #include <linux/tcp.h>
51 #include <linux/if_arp.h>
53 #include <linux/slab.h>
57 #include <asm/byteorder.h>
66 static int c2_query_device(
struct ib_device *ibdev,
69 struct c2_dev *c2dev = to_c2dev(ibdev);
71 pr_debug(
"%s:%u\n", __func__, __LINE__);
73 *props = c2dev->
props;
80 pr_debug(
"%s:%u\n", __func__, __LINE__);
105 pr_debug(
"%s:%u\n", __func__, __LINE__);
113 struct c2_dev *c2dev = to_c2dev(ibdev);
115 pr_debug(
"%s:%u\n", __func__, __LINE__);
130 pr_debug(
"%s:%u\n", __func__, __LINE__);
138 static int c2_dealloc_ucontext(
struct ib_ucontext *context)
140 pr_debug(
"%s:%u\n", __func__, __LINE__);
147 pr_debug(
"%s:%u\n", __func__, __LINE__);
158 pr_debug(
"%s:%u\n", __func__, __LINE__);
171 if (ib_copy_to_udata(udata, &pd->
pd_id,
sizeof(
__u32))) {
181 static int c2_dealloc_pd(
struct ib_pd *pd)
183 pr_debug(
"%s:%u\n", __func__, __LINE__);
192 pr_debug(
"%s:%u\n", __func__, __LINE__);
196 static int c2_ah_destroy(
struct ib_ah *
ah)
198 pr_debug(
"%s:%u\n", __func__, __LINE__);
202 static void c2_add_ref(
struct ib_qp *ibqp)
210 static void c2_rem_ref(
struct ib_qp *
ibqp)
221 struct c2_dev* c2dev = to_c2dev(device);
225 pr_debug(
"%s Returning QP=%p for QPN=%d, device=%p, refcount=%d\n",
226 __func__, qp, qpn, device,
239 pr_debug(
"%s:%u\n", __func__, __LINE__);
248 pr_debug(
"%s: Unable to allocate QP\n", __func__);
257 to_c2pd(pd), init_attr, qp);
265 pr_debug(
"%s: Invalid QP type: %d\n", __func__,
280 struct c2_qp *qp = to_c2qp(ib_qp);
282 pr_debug(
"%s:%u qp=%p,qp->state=%d\n",
283 __func__, __LINE__, ib_qp, qp->
state);
298 pr_debug(
"%s: Unable to allocate CQ\n", __func__);
304 pr_debug(
"%s: error initializing CQ\n", __func__);
314 struct c2_cq *cq = to_c2cq(ib_cq);
316 pr_debug(
"%s:%u\n", __func__, __LINE__);
324 static inline u32 c2_convert_access(
int acc)
334 int num_phys_buf,
int acc,
u64 * iova_start)
349 if (num_phys_buf == 1)
352 for (i = 0; i < num_phys_buf; i++) {
355 pr_debug(
"Unaligned Memory Buffer: 0x%x\n",
356 (
unsigned int) buffer_list[i].
addr);
360 if (!buffer_list[i].
size) {
365 total_len += buffer_list[
i].
size;
366 pbl_depth +=
ALIGN(buffer_list[i].size,
367 (1 << page_shift)) >> page_shift;
372 pr_debug(
"couldn't vmalloc page_list of size %zd\n",
373 (
sizeof(
u64) * pbl_depth));
377 for (i = 0, j = 0; i < num_phys_buf; i++) {
381 naddrs =
ALIGN(buffer_list[i].size,
382 (1 << page_shift)) >> page_shift;
383 for (k = 0; k < naddrs; k++)
384 page_list[j++] = (buffer_list[i].
addr +
394 mr->
pd = to_c2pd(ib_pd);
396 pr_debug(
"%s - page shift %d, pbl_depth %d, total_len %u, "
397 "*iova_start %llx, first pa %llx, last pa %llx\n",
398 __func__, page_shift, pbl_depth, total_len,
399 (
unsigned long long) *iova_start,
400 (
unsigned long long) page_list[0],
401 (
unsigned long long) page_list[pbl_depth-1]);
403 (1 << page_shift), pbl_depth,
404 total_len, 0, iova_start,
405 c2_convert_access(acc), mr);
415 static struct ib_mr *c2_get_dma_mr(
struct ib_pd *pd,
int acc)
420 pr_debug(
"%s:%u\n", __func__, __LINE__);
423 bl.size = 0xffffffff;
425 return c2_reg_phys_mr(pd, &
bl, 1, acc, &kva);
437 struct c2_pd *c2pd = to_c2pd(pd);
440 pr_debug(
"%s:%u\n", __func__, __LINE__);
448 if (IS_ERR(c2mr->
umem)) {
449 err = PTR_ERR(c2mr->
umem);
454 shift =
ffs(c2mr->
umem->page_size) - 1;
468 for (j = 0; j < chunk->
nmap; ++
j) {
470 for (k = 0; k < len; ++
k) {
473 (c2mr->
umem->page_size *
k);
481 c2mr->
umem->page_size,
486 c2_convert_access(acc),
501 struct c2_mr *mr = to_c2mr(ib_mr);
504 pr_debug(
"%s:%u\n", __func__, __LINE__);
508 pr_debug(
"c2_stag_dealloc failed: %d\n", err);
522 pr_debug(
"%s:%u\n", __func__, __LINE__);
530 pr_debug(
"%s:%u\n", __func__, __LINE__);
531 return sprintf(buf,
"%x.%x.%x\n",
532 (
int) (c2dev->
props.fw_ver >> 32),
533 (
int) (c2dev->
props.fw_ver >> 16) & 0xffff,
534 (
int) (c2dev->
props.fw_ver & 0xffff));
540 pr_debug(
"%s:%u\n", __func__, __LINE__);
541 return sprintf(buf,
"AMSO1100\n");
547 pr_debug(
"%s:%u\n", __func__, __LINE__);
548 return sprintf(buf,
"%.*s\n", 32,
"AMSO1100 Board ID");
563 static int c2_modify_qp(
struct ib_qp *ibqp,
struct ib_qp_attr *attr,
564 int attr_mask,
struct ib_udata *udata)
575 static int c2_multicast_attach(
struct ib_qp *ibqp,
union ib_gid *gid,
u16 lid)
577 pr_debug(
"%s:%u\n", __func__, __LINE__);
581 static int c2_multicast_detach(
struct ib_qp *ibqp,
union ib_gid *gid,
u16 lid)
583 pr_debug(
"%s:%u\n", __func__, __LINE__);
587 static int c2_process_mad(
struct ib_device *ibdev,
594 pr_debug(
"%s:%u\n", __func__, __LINE__);
600 pr_debug(
"%s:%u\n", __func__, __LINE__);
608 pr_debug(
"%s:%u\n", __func__, __LINE__);
618 pr_debug(
"%s:%u\n", __func__, __LINE__);
628 pr_debug(
"%s:%u\n", __func__, __LINE__);
639 pr_debug(
"%s:%u\n", __func__, __LINE__);
646 static int c2_pseudo_up(
struct net_device *netdev)
648 struct in_device *
ind;
651 ind = in_dev_get(netdev);
658 u8 *
ip = (
u8 *) & ifa->ifa_address;
661 ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);
663 c2_add_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);
671 static int c2_pseudo_down(
struct net_device *netdev)
673 struct in_device *
ind;
676 ind = in_dev_get(netdev);
683 u8 *
ip = (
u8 *) & ifa->ifa_address;
686 ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);
688 c2_del_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);
702 static int c2_pseudo_change_mtu(
struct net_device *netdev,
int new_mtu)
707 netdev->
mtu = new_mtu;
714 .ndo_open = c2_pseudo_up,
715 .ndo_stop = c2_pseudo_down,
716 .ndo_start_xmit = c2_pseudo_xmit_frame,
717 .ndo_change_mtu = c2_pseudo_change_mtu,
760 netif_stop_queue(netdev);
777 goto out_free_netdev;
779 pr_debug(
"%s:%u\n", __func__, __LINE__);
782 dev->
ibdev.uverbs_cmd_mask =
804 dev->
ibdev.phys_port_cnt = 1;
805 dev->
ibdev.num_comp_vectors = 1;
807 dev->
ibdev.query_device = c2_query_device;
808 dev->
ibdev.query_port = c2_query_port;
809 dev->
ibdev.query_pkey = c2_query_pkey;
810 dev->
ibdev.query_gid = c2_query_gid;
811 dev->
ibdev.alloc_ucontext = c2_alloc_ucontext;
812 dev->
ibdev.dealloc_ucontext = c2_dealloc_ucontext;
813 dev->
ibdev.mmap = c2_mmap_uar;
814 dev->
ibdev.alloc_pd = c2_alloc_pd;
815 dev->
ibdev.dealloc_pd = c2_dealloc_pd;
816 dev->
ibdev.create_ah = c2_ah_create;
817 dev->
ibdev.destroy_ah = c2_ah_destroy;
819 dev->
ibdev.modify_qp = c2_modify_qp;
820 dev->
ibdev.destroy_qp = c2_destroy_qp;
822 dev->
ibdev.destroy_cq = c2_destroy_cq;
824 dev->
ibdev.get_dma_mr = c2_get_dma_mr;
825 dev->
ibdev.reg_phys_mr = c2_reg_phys_mr;
826 dev->
ibdev.reg_user_mr = c2_reg_user_mr;
827 dev->
ibdev.dereg_mr = c2_dereg_mr;
834 dev->
ibdev.attach_mcast = c2_multicast_attach;
835 dev->
ibdev.detach_mcast = c2_multicast_detach;
836 dev->
ibdev.process_mad = c2_process_mad;
845 goto out_unregister_netdev;
847 dev->
ibdev.iwcm->add_ref = c2_add_ref;
848 dev->
ibdev.iwcm->rem_ref = c2_rem_ref;
850 dev->
ibdev.iwcm->connect = c2_connect;
851 dev->
ibdev.iwcm->accept = c2_accept;
852 dev->
ibdev.iwcm->reject = c2_reject;
853 dev->
ibdev.iwcm->create_listen = c2_service_create;
854 dev->
ibdev.iwcm->destroy_listen = c2_service_destroy;
860 for (i = 0; i <
ARRAY_SIZE(c2_dev_attributes); ++
i) {
862 c2_dev_attributes[i]);
864 goto out_unregister_ibdev;
868 out_unregister_ibdev:
872 out_unregister_netdev:
877 pr_debug(
"%s:%u ret=%d\n", __func__, __LINE__, ret);
883 pr_debug(
"%s:%u\n", __func__, __LINE__);