x86/amd-iommu: Add function to complete a tlb flush
[linux/fpc-iii.git] / drivers / infiniband / hw / amso1100 / c2_provider.c
blobad723bd8bf498090560c72bc78a1a06dc72e9730
1 /*
2 * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
3 * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/pci.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/inetdevice.h>
41 #include <linux/delay.h>
42 #include <linux/ethtool.h>
43 #include <linux/mii.h>
44 #include <linux/if_vlan.h>
45 #include <linux/crc32.h>
46 #include <linux/in.h>
47 #include <linux/ip.h>
48 #include <linux/tcp.h>
49 #include <linux/init.h>
50 #include <linux/dma-mapping.h>
51 #include <linux/if_arp.h>
52 #include <linux/vmalloc.h>
54 #include <asm/io.h>
55 #include <asm/irq.h>
56 #include <asm/byteorder.h>
58 #include <rdma/ib_smi.h>
59 #include <rdma/ib_umem.h>
60 #include <rdma/ib_user_verbs.h>
61 #include "c2.h"
62 #include "c2_provider.h"
63 #include "c2_user.h"
65 static int c2_query_device(struct ib_device *ibdev,
66 struct ib_device_attr *props)
68 struct c2_dev *c2dev = to_c2dev(ibdev);
70 pr_debug("%s:%u\n", __func__, __LINE__);
72 *props = c2dev->props;
73 return 0;
76 static int c2_query_port(struct ib_device *ibdev,
77 u8 port, struct ib_port_attr *props)
79 pr_debug("%s:%u\n", __func__, __LINE__);
81 props->max_mtu = IB_MTU_4096;
82 props->lid = 0;
83 props->lmc = 0;
84 props->sm_lid = 0;
85 props->sm_sl = 0;
86 props->state = IB_PORT_ACTIVE;
87 props->phys_state = 0;
88 props->port_cap_flags =
89 IB_PORT_CM_SUP |
90 IB_PORT_REINIT_SUP |
91 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
92 props->gid_tbl_len = 1;
93 props->pkey_tbl_len = 1;
94 props->qkey_viol_cntr = 0;
95 props->active_width = 1;
96 props->active_speed = 1;
98 return 0;
101 static int c2_modify_port(struct ib_device *ibdev,
102 u8 port, int port_modify_mask,
103 struct ib_port_modify *props)
105 pr_debug("%s:%u\n", __func__, __LINE__);
106 return 0;
109 static int c2_query_pkey(struct ib_device *ibdev,
110 u8 port, u16 index, u16 * pkey)
112 pr_debug("%s:%u\n", __func__, __LINE__);
113 *pkey = 0;
114 return 0;
117 static int c2_query_gid(struct ib_device *ibdev, u8 port,
118 int index, union ib_gid *gid)
120 struct c2_dev *c2dev = to_c2dev(ibdev);
122 pr_debug("%s:%u\n", __func__, __LINE__);
123 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
124 memcpy(&(gid->raw[0]), c2dev->pseudo_netdev->dev_addr, 6);
126 return 0;
129 /* Allocate the user context data structure. This keeps track
130 * of all objects associated with a particular user-mode client.
132 static struct ib_ucontext *c2_alloc_ucontext(struct ib_device *ibdev,
133 struct ib_udata *udata)
135 struct c2_ucontext *context;
137 pr_debug("%s:%u\n", __func__, __LINE__);
138 context = kmalloc(sizeof(*context), GFP_KERNEL);
139 if (!context)
140 return ERR_PTR(-ENOMEM);
142 return &context->ibucontext;
145 static int c2_dealloc_ucontext(struct ib_ucontext *context)
147 pr_debug("%s:%u\n", __func__, __LINE__);
148 kfree(context);
149 return 0;
152 static int c2_mmap_uar(struct ib_ucontext *context, struct vm_area_struct *vma)
154 pr_debug("%s:%u\n", __func__, __LINE__);
155 return -ENOSYS;
158 static struct ib_pd *c2_alloc_pd(struct ib_device *ibdev,
159 struct ib_ucontext *context,
160 struct ib_udata *udata)
162 struct c2_pd *pd;
163 int err;
165 pr_debug("%s:%u\n", __func__, __LINE__);
167 pd = kmalloc(sizeof(*pd), GFP_KERNEL);
168 if (!pd)
169 return ERR_PTR(-ENOMEM);
171 err = c2_pd_alloc(to_c2dev(ibdev), !context, pd);
172 if (err) {
173 kfree(pd);
174 return ERR_PTR(err);
177 if (context) {
178 if (ib_copy_to_udata(udata, &pd->pd_id, sizeof(__u32))) {
179 c2_pd_free(to_c2dev(ibdev), pd);
180 kfree(pd);
181 return ERR_PTR(-EFAULT);
185 return &pd->ibpd;
188 static int c2_dealloc_pd(struct ib_pd *pd)
190 pr_debug("%s:%u\n", __func__, __LINE__);
191 c2_pd_free(to_c2dev(pd->device), to_c2pd(pd));
192 kfree(pd);
194 return 0;
197 static struct ib_ah *c2_ah_create(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
199 pr_debug("%s:%u\n", __func__, __LINE__);
200 return ERR_PTR(-ENOSYS);
203 static int c2_ah_destroy(struct ib_ah *ah)
205 pr_debug("%s:%u\n", __func__, __LINE__);
206 return -ENOSYS;
209 static void c2_add_ref(struct ib_qp *ibqp)
211 struct c2_qp *qp;
212 BUG_ON(!ibqp);
213 qp = to_c2qp(ibqp);
214 atomic_inc(&qp->refcount);
217 static void c2_rem_ref(struct ib_qp *ibqp)
219 struct c2_qp *qp;
220 BUG_ON(!ibqp);
221 qp = to_c2qp(ibqp);
222 if (atomic_dec_and_test(&qp->refcount))
223 wake_up(&qp->wait);
226 struct ib_qp *c2_get_qp(struct ib_device *device, int qpn)
228 struct c2_dev* c2dev = to_c2dev(device);
229 struct c2_qp *qp;
231 qp = c2_find_qpn(c2dev, qpn);
232 pr_debug("%s Returning QP=%p for QPN=%d, device=%p, refcount=%d\n",
233 __func__, qp, qpn, device,
234 (qp?atomic_read(&qp->refcount):0));
236 return (qp?&qp->ibqp:NULL);
239 static struct ib_qp *c2_create_qp(struct ib_pd *pd,
240 struct ib_qp_init_attr *init_attr,
241 struct ib_udata *udata)
243 struct c2_qp *qp;
244 int err;
246 pr_debug("%s:%u\n", __func__, __LINE__);
248 if (init_attr->create_flags)
249 return ERR_PTR(-EINVAL);
251 switch (init_attr->qp_type) {
252 case IB_QPT_RC:
253 qp = kzalloc(sizeof(*qp), GFP_KERNEL);
254 if (!qp) {
255 pr_debug("%s: Unable to allocate QP\n", __func__);
256 return ERR_PTR(-ENOMEM);
258 spin_lock_init(&qp->lock);
259 if (pd->uobject) {
260 /* userspace specific */
263 err = c2_alloc_qp(to_c2dev(pd->device),
264 to_c2pd(pd), init_attr, qp);
266 if (err && pd->uobject) {
267 /* userspace specific */
270 break;
271 default:
272 pr_debug("%s: Invalid QP type: %d\n", __func__,
273 init_attr->qp_type);
274 return ERR_PTR(-EINVAL);
277 if (err) {
278 kfree(qp);
279 return ERR_PTR(err);
282 return &qp->ibqp;
285 static int c2_destroy_qp(struct ib_qp *ib_qp)
287 struct c2_qp *qp = to_c2qp(ib_qp);
289 pr_debug("%s:%u qp=%p,qp->state=%d\n",
290 __func__, __LINE__, ib_qp, qp->state);
291 c2_free_qp(to_c2dev(ib_qp->device), qp);
292 kfree(qp);
293 return 0;
296 static struct ib_cq *c2_create_cq(struct ib_device *ibdev, int entries, int vector,
297 struct ib_ucontext *context,
298 struct ib_udata *udata)
300 struct c2_cq *cq;
301 int err;
303 cq = kmalloc(sizeof(*cq), GFP_KERNEL);
304 if (!cq) {
305 pr_debug("%s: Unable to allocate CQ\n", __func__);
306 return ERR_PTR(-ENOMEM);
309 err = c2_init_cq(to_c2dev(ibdev), entries, NULL, cq);
310 if (err) {
311 pr_debug("%s: error initializing CQ\n", __func__);
312 kfree(cq);
313 return ERR_PTR(err);
316 return &cq->ibcq;
319 static int c2_destroy_cq(struct ib_cq *ib_cq)
321 struct c2_cq *cq = to_c2cq(ib_cq);
323 pr_debug("%s:%u\n", __func__, __LINE__);
325 c2_free_cq(to_c2dev(ib_cq->device), cq);
326 kfree(cq);
328 return 0;
331 static inline u32 c2_convert_access(int acc)
333 return (acc & IB_ACCESS_REMOTE_WRITE ? C2_ACF_REMOTE_WRITE : 0) |
334 (acc & IB_ACCESS_REMOTE_READ ? C2_ACF_REMOTE_READ : 0) |
335 (acc & IB_ACCESS_LOCAL_WRITE ? C2_ACF_LOCAL_WRITE : 0) |
336 C2_ACF_LOCAL_READ | C2_ACF_WINDOW_BIND;
339 static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
340 struct ib_phys_buf *buffer_list,
341 int num_phys_buf, int acc, u64 * iova_start)
343 struct c2_mr *mr;
344 u64 *page_list;
345 u32 total_len;
346 int err, i, j, k, page_shift, pbl_depth;
348 pbl_depth = 0;
349 total_len = 0;
351 page_shift = PAGE_SHIFT;
353 * If there is only 1 buffer we assume this could
354 * be a map of all phy mem...use a 32k page_shift.
356 if (num_phys_buf == 1)
357 page_shift += 3;
359 for (i = 0; i < num_phys_buf; i++) {
361 if (buffer_list[i].addr & ~PAGE_MASK) {
362 pr_debug("Unaligned Memory Buffer: 0x%x\n",
363 (unsigned int) buffer_list[i].addr);
364 return ERR_PTR(-EINVAL);
367 if (!buffer_list[i].size) {
368 pr_debug("Invalid Buffer Size\n");
369 return ERR_PTR(-EINVAL);
372 total_len += buffer_list[i].size;
373 pbl_depth += ALIGN(buffer_list[i].size,
374 (1 << page_shift)) >> page_shift;
377 page_list = vmalloc(sizeof(u64) * pbl_depth);
378 if (!page_list) {
379 pr_debug("couldn't vmalloc page_list of size %zd\n",
380 (sizeof(u64) * pbl_depth));
381 return ERR_PTR(-ENOMEM);
384 for (i = 0, j = 0; i < num_phys_buf; i++) {
386 int naddrs;
388 naddrs = ALIGN(buffer_list[i].size,
389 (1 << page_shift)) >> page_shift;
390 for (k = 0; k < naddrs; k++)
391 page_list[j++] = (buffer_list[i].addr +
392 (k << page_shift));
395 mr = kmalloc(sizeof(*mr), GFP_KERNEL);
396 if (!mr) {
397 vfree(page_list);
398 return ERR_PTR(-ENOMEM);
401 mr->pd = to_c2pd(ib_pd);
402 mr->umem = NULL;
403 pr_debug("%s - page shift %d, pbl_depth %d, total_len %u, "
404 "*iova_start %llx, first pa %llx, last pa %llx\n",
405 __func__, page_shift, pbl_depth, total_len,
406 (unsigned long long) *iova_start,
407 (unsigned long long) page_list[0],
408 (unsigned long long) page_list[pbl_depth-1]);
409 err = c2_nsmr_register_phys_kern(to_c2dev(ib_pd->device), page_list,
410 (1 << page_shift), pbl_depth,
411 total_len, 0, iova_start,
412 c2_convert_access(acc), mr);
413 vfree(page_list);
414 if (err) {
415 kfree(mr);
416 return ERR_PTR(err);
419 return &mr->ibmr;
422 static struct ib_mr *c2_get_dma_mr(struct ib_pd *pd, int acc)
424 struct ib_phys_buf bl;
425 u64 kva = 0;
427 pr_debug("%s:%u\n", __func__, __LINE__);
429 /* AMSO1100 limit */
430 bl.size = 0xffffffff;
431 bl.addr = 0;
432 return c2_reg_phys_mr(pd, &bl, 1, acc, &kva);
435 static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
436 u64 virt, int acc, struct ib_udata *udata)
438 u64 *pages;
439 u64 kva = 0;
440 int shift, n, len;
441 int i, j, k;
442 int err = 0;
443 struct ib_umem_chunk *chunk;
444 struct c2_pd *c2pd = to_c2pd(pd);
445 struct c2_mr *c2mr;
447 pr_debug("%s:%u\n", __func__, __LINE__);
449 c2mr = kmalloc(sizeof(*c2mr), GFP_KERNEL);
450 if (!c2mr)
451 return ERR_PTR(-ENOMEM);
452 c2mr->pd = c2pd;
454 c2mr->umem = ib_umem_get(pd->uobject->context, start, length, acc, 0);
455 if (IS_ERR(c2mr->umem)) {
456 err = PTR_ERR(c2mr->umem);
457 kfree(c2mr);
458 return ERR_PTR(err);
461 shift = ffs(c2mr->umem->page_size) - 1;
463 n = 0;
464 list_for_each_entry(chunk, &c2mr->umem->chunk_list, list)
465 n += chunk->nents;
467 pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
468 if (!pages) {
469 err = -ENOMEM;
470 goto err;
473 i = 0;
474 list_for_each_entry(chunk, &c2mr->umem->chunk_list, list) {
475 for (j = 0; j < chunk->nmap; ++j) {
476 len = sg_dma_len(&chunk->page_list[j]) >> shift;
477 for (k = 0; k < len; ++k) {
478 pages[i++] =
479 sg_dma_address(&chunk->page_list[j]) +
480 (c2mr->umem->page_size * k);
485 kva = virt;
486 err = c2_nsmr_register_phys_kern(to_c2dev(pd->device),
487 pages,
488 c2mr->umem->page_size,
490 length,
491 c2mr->umem->offset,
492 &kva,
493 c2_convert_access(acc),
494 c2mr);
495 kfree(pages);
496 if (err)
497 goto err;
498 return &c2mr->ibmr;
500 err:
501 ib_umem_release(c2mr->umem);
502 kfree(c2mr);
503 return ERR_PTR(err);
506 static int c2_dereg_mr(struct ib_mr *ib_mr)
508 struct c2_mr *mr = to_c2mr(ib_mr);
509 int err;
511 pr_debug("%s:%u\n", __func__, __LINE__);
513 err = c2_stag_dealloc(to_c2dev(ib_mr->device), ib_mr->lkey);
514 if (err)
515 pr_debug("c2_stag_dealloc failed: %d\n", err);
516 else {
517 if (mr->umem)
518 ib_umem_release(mr->umem);
519 kfree(mr);
522 return err;
525 static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
526 char *buf)
528 struct c2_dev *c2dev = container_of(dev, struct c2_dev, ibdev.dev);
529 pr_debug("%s:%u\n", __func__, __LINE__);
530 return sprintf(buf, "%x\n", c2dev->props.hw_ver);
533 static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
534 char *buf)
536 struct c2_dev *c2dev = container_of(dev, struct c2_dev, ibdev.dev);
537 pr_debug("%s:%u\n", __func__, __LINE__);
538 return sprintf(buf, "%x.%x.%x\n",
539 (int) (c2dev->props.fw_ver >> 32),
540 (int) (c2dev->props.fw_ver >> 16) & 0xffff,
541 (int) (c2dev->props.fw_ver & 0xffff));
544 static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
545 char *buf)
547 pr_debug("%s:%u\n", __func__, __LINE__);
548 return sprintf(buf, "AMSO1100\n");
551 static ssize_t show_board(struct device *dev, struct device_attribute *attr,
552 char *buf)
554 pr_debug("%s:%u\n", __func__, __LINE__);
555 return sprintf(buf, "%.*s\n", 32, "AMSO1100 Board ID");
558 static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
559 static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
560 static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
561 static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
563 static struct device_attribute *c2_dev_attributes[] = {
564 &dev_attr_hw_rev,
565 &dev_attr_fw_ver,
566 &dev_attr_hca_type,
567 &dev_attr_board_id
570 static int c2_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
571 int attr_mask, struct ib_udata *udata)
573 int err;
575 err =
576 c2_qp_modify(to_c2dev(ibqp->device), to_c2qp(ibqp), attr,
577 attr_mask);
579 return err;
582 static int c2_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
584 pr_debug("%s:%u\n", __func__, __LINE__);
585 return -ENOSYS;
588 static int c2_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
590 pr_debug("%s:%u\n", __func__, __LINE__);
591 return -ENOSYS;
594 static int c2_process_mad(struct ib_device *ibdev,
595 int mad_flags,
596 u8 port_num,
597 struct ib_wc *in_wc,
598 struct ib_grh *in_grh,
599 struct ib_mad *in_mad, struct ib_mad *out_mad)
601 pr_debug("%s:%u\n", __func__, __LINE__);
602 return -ENOSYS;
605 static int c2_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
607 pr_debug("%s:%u\n", __func__, __LINE__);
609 /* Request a connection */
610 return c2_llp_connect(cm_id, iw_param);
613 static int c2_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)
615 pr_debug("%s:%u\n", __func__, __LINE__);
617 /* Accept the new connection */
618 return c2_llp_accept(cm_id, iw_param);
621 static int c2_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
623 int err;
625 pr_debug("%s:%u\n", __func__, __LINE__);
627 err = c2_llp_reject(cm_id, pdata, pdata_len);
628 return err;
631 static int c2_service_create(struct iw_cm_id *cm_id, int backlog)
633 int err;
635 pr_debug("%s:%u\n", __func__, __LINE__);
636 err = c2_llp_service_create(cm_id, backlog);
637 pr_debug("%s:%u err=%d\n",
638 __func__, __LINE__,
639 err);
640 return err;
643 static int c2_service_destroy(struct iw_cm_id *cm_id)
645 int err;
646 pr_debug("%s:%u\n", __func__, __LINE__);
648 err = c2_llp_service_destroy(cm_id);
650 return err;
653 static int c2_pseudo_up(struct net_device *netdev)
655 struct in_device *ind;
656 struct c2_dev *c2dev = netdev->ml_priv;
658 ind = in_dev_get(netdev);
659 if (!ind)
660 return 0;
662 pr_debug("adding...\n");
663 for_ifa(ind) {
664 #ifdef DEBUG
665 u8 *ip = (u8 *) & ifa->ifa_address;
667 pr_debug("%s: %d.%d.%d.%d\n",
668 ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);
669 #endif
670 c2_add_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);
672 endfor_ifa(ind);
673 in_dev_put(ind);
675 return 0;
678 static int c2_pseudo_down(struct net_device *netdev)
680 struct in_device *ind;
681 struct c2_dev *c2dev = netdev->ml_priv;
683 ind = in_dev_get(netdev);
684 if (!ind)
685 return 0;
687 pr_debug("deleting...\n");
688 for_ifa(ind) {
689 #ifdef DEBUG
690 u8 *ip = (u8 *) & ifa->ifa_address;
692 pr_debug("%s: %d.%d.%d.%d\n",
693 ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);
694 #endif
695 c2_del_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);
697 endfor_ifa(ind);
698 in_dev_put(ind);
700 return 0;
703 static int c2_pseudo_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
705 kfree_skb(skb);
706 return NETDEV_TX_OK;
709 static int c2_pseudo_change_mtu(struct net_device *netdev, int new_mtu)
711 if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)
712 return -EINVAL;
714 netdev->mtu = new_mtu;
716 /* TODO: Tell rnic about new rmda interface mtu */
717 return 0;
720 static const struct net_device_ops c2_pseudo_netdev_ops = {
721 .ndo_open = c2_pseudo_up,
722 .ndo_stop = c2_pseudo_down,
723 .ndo_start_xmit = c2_pseudo_xmit_frame,
724 .ndo_change_mtu = c2_pseudo_change_mtu,
725 .ndo_validate_addr = eth_validate_addr,
728 static void setup(struct net_device *netdev)
730 netdev->netdev_ops = &c2_pseudo_netdev_ops;
732 netdev->watchdog_timeo = 0;
733 netdev->type = ARPHRD_ETHER;
734 netdev->mtu = 1500;
735 netdev->hard_header_len = ETH_HLEN;
736 netdev->addr_len = ETH_ALEN;
737 netdev->tx_queue_len = 0;
738 netdev->flags |= IFF_NOARP;
741 static struct net_device *c2_pseudo_netdev_init(struct c2_dev *c2dev)
743 char name[IFNAMSIZ];
744 struct net_device *netdev;
746 /* change ethxxx to iwxxx */
747 strcpy(name, "iw");
748 strcat(name, &c2dev->netdev->name[3]);
749 netdev = alloc_netdev(0, name, setup);
750 if (!netdev) {
751 printk(KERN_ERR PFX "%s - etherdev alloc failed",
752 __func__);
753 return NULL;
756 netdev->ml_priv = c2dev;
758 SET_NETDEV_DEV(netdev, &c2dev->pcidev->dev);
760 memcpy_fromio(netdev->dev_addr, c2dev->kva + C2_REGS_RDMA_ENADDR, 6);
762 /* Print out the MAC address */
763 pr_debug("%s: MAC %02X:%02X:%02X:%02X:%02X:%02X\n",
764 netdev->name,
765 netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],
766 netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);
768 #if 0
769 /* Disable network packets */
770 netif_stop_queue(netdev);
771 #endif
772 return netdev;
775 int c2_register_device(struct c2_dev *dev)
777 int ret = -ENOMEM;
778 int i;
780 /* Register pseudo network device */
781 dev->pseudo_netdev = c2_pseudo_netdev_init(dev);
782 if (!dev->pseudo_netdev)
783 goto out;
785 ret = register_netdev(dev->pseudo_netdev);
786 if (ret)
787 goto out_free_netdev;
789 pr_debug("%s:%u\n", __func__, __LINE__);
790 strlcpy(dev->ibdev.name, "amso%d", IB_DEVICE_NAME_MAX);
791 dev->ibdev.owner = THIS_MODULE;
792 dev->ibdev.uverbs_cmd_mask =
793 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
794 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
795 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
796 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
797 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
798 (1ull << IB_USER_VERBS_CMD_REG_MR) |
799 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
800 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
801 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
802 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
803 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
804 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
805 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
806 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
807 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
808 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
809 (1ull << IB_USER_VERBS_CMD_POST_RECV);
811 dev->ibdev.node_type = RDMA_NODE_RNIC;
812 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
813 memcpy(&dev->ibdev.node_guid, dev->pseudo_netdev->dev_addr, 6);
814 dev->ibdev.phys_port_cnt = 1;
815 dev->ibdev.num_comp_vectors = 1;
816 dev->ibdev.dma_device = &dev->pcidev->dev;
817 dev->ibdev.query_device = c2_query_device;
818 dev->ibdev.query_port = c2_query_port;
819 dev->ibdev.modify_port = c2_modify_port;
820 dev->ibdev.query_pkey = c2_query_pkey;
821 dev->ibdev.query_gid = c2_query_gid;
822 dev->ibdev.alloc_ucontext = c2_alloc_ucontext;
823 dev->ibdev.dealloc_ucontext = c2_dealloc_ucontext;
824 dev->ibdev.mmap = c2_mmap_uar;
825 dev->ibdev.alloc_pd = c2_alloc_pd;
826 dev->ibdev.dealloc_pd = c2_dealloc_pd;
827 dev->ibdev.create_ah = c2_ah_create;
828 dev->ibdev.destroy_ah = c2_ah_destroy;
829 dev->ibdev.create_qp = c2_create_qp;
830 dev->ibdev.modify_qp = c2_modify_qp;
831 dev->ibdev.destroy_qp = c2_destroy_qp;
832 dev->ibdev.create_cq = c2_create_cq;
833 dev->ibdev.destroy_cq = c2_destroy_cq;
834 dev->ibdev.poll_cq = c2_poll_cq;
835 dev->ibdev.get_dma_mr = c2_get_dma_mr;
836 dev->ibdev.reg_phys_mr = c2_reg_phys_mr;
837 dev->ibdev.reg_user_mr = c2_reg_user_mr;
838 dev->ibdev.dereg_mr = c2_dereg_mr;
840 dev->ibdev.alloc_fmr = NULL;
841 dev->ibdev.unmap_fmr = NULL;
842 dev->ibdev.dealloc_fmr = NULL;
843 dev->ibdev.map_phys_fmr = NULL;
845 dev->ibdev.attach_mcast = c2_multicast_attach;
846 dev->ibdev.detach_mcast = c2_multicast_detach;
847 dev->ibdev.process_mad = c2_process_mad;
849 dev->ibdev.req_notify_cq = c2_arm_cq;
850 dev->ibdev.post_send = c2_post_send;
851 dev->ibdev.post_recv = c2_post_receive;
853 dev->ibdev.iwcm = kmalloc(sizeof(*dev->ibdev.iwcm), GFP_KERNEL);
854 if (dev->ibdev.iwcm == NULL) {
855 ret = -ENOMEM;
856 goto out_unregister_netdev;
858 dev->ibdev.iwcm->add_ref = c2_add_ref;
859 dev->ibdev.iwcm->rem_ref = c2_rem_ref;
860 dev->ibdev.iwcm->get_qp = c2_get_qp;
861 dev->ibdev.iwcm->connect = c2_connect;
862 dev->ibdev.iwcm->accept = c2_accept;
863 dev->ibdev.iwcm->reject = c2_reject;
864 dev->ibdev.iwcm->create_listen = c2_service_create;
865 dev->ibdev.iwcm->destroy_listen = c2_service_destroy;
867 ret = ib_register_device(&dev->ibdev);
868 if (ret)
869 goto out_free_iwcm;
871 for (i = 0; i < ARRAY_SIZE(c2_dev_attributes); ++i) {
872 ret = device_create_file(&dev->ibdev.dev,
873 c2_dev_attributes[i]);
874 if (ret)
875 goto out_unregister_ibdev;
877 goto out;
879 out_unregister_ibdev:
880 ib_unregister_device(&dev->ibdev);
881 out_free_iwcm:
882 kfree(dev->ibdev.iwcm);
883 out_unregister_netdev:
884 unregister_netdev(dev->pseudo_netdev);
885 out_free_netdev:
886 free_netdev(dev->pseudo_netdev);
887 out:
888 pr_debug("%s:%u ret=%d\n", __func__, __LINE__, ret);
889 return ret;
892 void c2_unregister_device(struct c2_dev *dev)
894 pr_debug("%s:%u\n", __func__, __LINE__);
895 unregister_netdev(dev->pseudo_netdev);
896 free_netdev(dev->pseudo_netdev);
897 ib_unregister_device(&dev->ibdev);