Path: blob/master/drivers/infiniband/hw/amso1100/c2_provider.c
15112 views
/*1* Copyright (c) 2005 Ammasso, Inc. All rights reserved.2* Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved.3*4* This software is available to you under a choice of one of two5* licenses. You may choose to be licensed under the terms of the GNU6* General Public License (GPL) Version 2, available from the file7* COPYING in the main directory of this source tree, or the8* OpenIB.org BSD license below:9*10* Redistribution and use in source and binary forms, with or11* without modification, are permitted provided that the following12* conditions are met:13*14* - Redistributions of source code must retain the above15* copyright notice, this list of conditions and the following16* disclaimer.17*18* - Redistributions in binary form must reproduce the above19* copyright notice, this list of conditions and the following20* disclaimer in the documentation and/or other materials21* provided with the distribution.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND26* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS27* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN28* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN29* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE30* SOFTWARE.31*32*/3334#include <linux/module.h>35#include <linux/moduleparam.h>36#include <linux/pci.h>37#include <linux/netdevice.h>38#include <linux/etherdevice.h>39#include <linux/inetdevice.h>40#include <linux/delay.h>41#include <linux/ethtool.h>42#include <linux/mii.h>43#include <linux/if_vlan.h>44#include <linux/crc32.h>45#include <linux/in.h>46#include <linux/ip.h>47#include <linux/tcp.h>48#include <linux/init.h>49#include <linux/dma-mapping.h>50#include <linux/if_arp.h>51#include <linux/vmalloc.h>52#include <linux/slab.h>5354#include <asm/io.h>55#include <asm/irq.h>56#include <asm/byteorder.h>5758#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"6465static int c2_query_device(struct ib_device *ibdev,66struct ib_device_attr *props)67{68struct c2_dev *c2dev = to_c2dev(ibdev);6970pr_debug("%s:%u\n", __func__, __LINE__);7172*props = c2dev->props;73return 0;74}7576static int c2_query_port(struct ib_device *ibdev,77u8 port, struct ib_port_attr *props)78{79pr_debug("%s:%u\n", __func__, __LINE__);8081props->max_mtu = IB_MTU_4096;82props->lid = 0;83props->lmc = 0;84props->sm_lid = 0;85props->sm_sl = 0;86props->state = IB_PORT_ACTIVE;87props->phys_state = 0;88props->port_cap_flags =89IB_PORT_CM_SUP |90IB_PORT_REINIT_SUP |91IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;92props->gid_tbl_len = 1;93props->pkey_tbl_len = 1;94props->qkey_viol_cntr = 0;95props->active_width = 1;96props->active_speed = 1;9798return 0;99}100101static int c2_modify_port(struct ib_device *ibdev,102u8 port, int port_modify_mask,103struct ib_port_modify *props)104{105pr_debug("%s:%u\n", __func__, __LINE__);106return 0;107}108109static int c2_query_pkey(struct ib_device *ibdev,110u8 port, u16 index, u16 * pkey)111{112pr_debug("%s:%u\n", __func__, __LINE__);113*pkey = 0;114return 0;115}116117static int c2_query_gid(struct ib_device *ibdev, u8 port,118int index, union ib_gid *gid)119{120struct c2_dev *c2dev = to_c2dev(ibdev);121122pr_debug("%s:%u\n", __func__, __LINE__);123memset(&(gid->raw[0]), 0, sizeof(gid->raw));124memcpy(&(gid->raw[0]), c2dev->pseudo_netdev->dev_addr, 6);125126return 0;127}128129/* Allocate the user context data structure. This keeps track130* of all objects associated with a particular user-mode client.131*/132static struct ib_ucontext *c2_alloc_ucontext(struct ib_device *ibdev,133struct ib_udata *udata)134{135struct c2_ucontext *context;136137pr_debug("%s:%u\n", __func__, __LINE__);138context = kmalloc(sizeof(*context), GFP_KERNEL);139if (!context)140return ERR_PTR(-ENOMEM);141142return &context->ibucontext;143}144145static int c2_dealloc_ucontext(struct ib_ucontext *context)146{147pr_debug("%s:%u\n", __func__, __LINE__);148kfree(context);149return 0;150}151152static int c2_mmap_uar(struct ib_ucontext *context, struct vm_area_struct *vma)153{154pr_debug("%s:%u\n", __func__, __LINE__);155return -ENOSYS;156}157158static struct ib_pd *c2_alloc_pd(struct ib_device *ibdev,159struct ib_ucontext *context,160struct ib_udata *udata)161{162struct c2_pd *pd;163int err;164165pr_debug("%s:%u\n", __func__, __LINE__);166167pd = kmalloc(sizeof(*pd), GFP_KERNEL);168if (!pd)169return ERR_PTR(-ENOMEM);170171err = c2_pd_alloc(to_c2dev(ibdev), !context, pd);172if (err) {173kfree(pd);174return ERR_PTR(err);175}176177if (context) {178if (ib_copy_to_udata(udata, &pd->pd_id, sizeof(__u32))) {179c2_pd_free(to_c2dev(ibdev), pd);180kfree(pd);181return ERR_PTR(-EFAULT);182}183}184185return &pd->ibpd;186}187188static int c2_dealloc_pd(struct ib_pd *pd)189{190pr_debug("%s:%u\n", __func__, __LINE__);191c2_pd_free(to_c2dev(pd->device), to_c2pd(pd));192kfree(pd);193194return 0;195}196197static struct ib_ah *c2_ah_create(struct ib_pd *pd, struct ib_ah_attr *ah_attr)198{199pr_debug("%s:%u\n", __func__, __LINE__);200return ERR_PTR(-ENOSYS);201}202203static int c2_ah_destroy(struct ib_ah *ah)204{205pr_debug("%s:%u\n", __func__, __LINE__);206return -ENOSYS;207}208209static void c2_add_ref(struct ib_qp *ibqp)210{211struct c2_qp *qp;212BUG_ON(!ibqp);213qp = to_c2qp(ibqp);214atomic_inc(&qp->refcount);215}216217static void c2_rem_ref(struct ib_qp *ibqp)218{219struct c2_qp *qp;220BUG_ON(!ibqp);221qp = to_c2qp(ibqp);222if (atomic_dec_and_test(&qp->refcount))223wake_up(&qp->wait);224}225226struct ib_qp *c2_get_qp(struct ib_device *device, int qpn)227{228struct c2_dev* c2dev = to_c2dev(device);229struct c2_qp *qp;230231qp = c2_find_qpn(c2dev, qpn);232pr_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));235236return (qp?&qp->ibqp:NULL);237}238239static struct ib_qp *c2_create_qp(struct ib_pd *pd,240struct ib_qp_init_attr *init_attr,241struct ib_udata *udata)242{243struct c2_qp *qp;244int err;245246pr_debug("%s:%u\n", __func__, __LINE__);247248if (init_attr->create_flags)249return ERR_PTR(-EINVAL);250251switch (init_attr->qp_type) {252case IB_QPT_RC:253qp = kzalloc(sizeof(*qp), GFP_KERNEL);254if (!qp) {255pr_debug("%s: Unable to allocate QP\n", __func__);256return ERR_PTR(-ENOMEM);257}258spin_lock_init(&qp->lock);259if (pd->uobject) {260/* userspace specific */261}262263err = c2_alloc_qp(to_c2dev(pd->device),264to_c2pd(pd), init_attr, qp);265266if (err && pd->uobject) {267/* userspace specific */268}269270break;271default:272pr_debug("%s: Invalid QP type: %d\n", __func__,273init_attr->qp_type);274return ERR_PTR(-EINVAL);275}276277if (err) {278kfree(qp);279return ERR_PTR(err);280}281282return &qp->ibqp;283}284285static int c2_destroy_qp(struct ib_qp *ib_qp)286{287struct c2_qp *qp = to_c2qp(ib_qp);288289pr_debug("%s:%u qp=%p,qp->state=%d\n",290__func__, __LINE__, ib_qp, qp->state);291c2_free_qp(to_c2dev(ib_qp->device), qp);292kfree(qp);293return 0;294}295296static struct ib_cq *c2_create_cq(struct ib_device *ibdev, int entries, int vector,297struct ib_ucontext *context,298struct ib_udata *udata)299{300struct c2_cq *cq;301int err;302303cq = kmalloc(sizeof(*cq), GFP_KERNEL);304if (!cq) {305pr_debug("%s: Unable to allocate CQ\n", __func__);306return ERR_PTR(-ENOMEM);307}308309err = c2_init_cq(to_c2dev(ibdev), entries, NULL, cq);310if (err) {311pr_debug("%s: error initializing CQ\n", __func__);312kfree(cq);313return ERR_PTR(err);314}315316return &cq->ibcq;317}318319static int c2_destroy_cq(struct ib_cq *ib_cq)320{321struct c2_cq *cq = to_c2cq(ib_cq);322323pr_debug("%s:%u\n", __func__, __LINE__);324325c2_free_cq(to_c2dev(ib_cq->device), cq);326kfree(cq);327328return 0;329}330331static inline u32 c2_convert_access(int acc)332{333return (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) |336C2_ACF_LOCAL_READ | C2_ACF_WINDOW_BIND;337}338339static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,340struct ib_phys_buf *buffer_list,341int num_phys_buf, int acc, u64 * iova_start)342{343struct c2_mr *mr;344u64 *page_list;345u32 total_len;346int err, i, j, k, page_shift, pbl_depth;347348pbl_depth = 0;349total_len = 0;350351page_shift = PAGE_SHIFT;352/*353* If there is only 1 buffer we assume this could354* be a map of all phy mem...use a 32k page_shift.355*/356if (num_phys_buf == 1)357page_shift += 3;358359for (i = 0; i < num_phys_buf; i++) {360361if (buffer_list[i].addr & ~PAGE_MASK) {362pr_debug("Unaligned Memory Buffer: 0x%x\n",363(unsigned int) buffer_list[i].addr);364return ERR_PTR(-EINVAL);365}366367if (!buffer_list[i].size) {368pr_debug("Invalid Buffer Size\n");369return ERR_PTR(-EINVAL);370}371372total_len += buffer_list[i].size;373pbl_depth += ALIGN(buffer_list[i].size,374(1 << page_shift)) >> page_shift;375}376377page_list = vmalloc(sizeof(u64) * pbl_depth);378if (!page_list) {379pr_debug("couldn't vmalloc page_list of size %zd\n",380(sizeof(u64) * pbl_depth));381return ERR_PTR(-ENOMEM);382}383384for (i = 0, j = 0; i < num_phys_buf; i++) {385386int naddrs;387388naddrs = ALIGN(buffer_list[i].size,389(1 << page_shift)) >> page_shift;390for (k = 0; k < naddrs; k++)391page_list[j++] = (buffer_list[i].addr +392(k << page_shift));393}394395mr = kmalloc(sizeof(*mr), GFP_KERNEL);396if (!mr) {397vfree(page_list);398return ERR_PTR(-ENOMEM);399}400401mr->pd = to_c2pd(ib_pd);402mr->umem = NULL;403pr_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]);409err = c2_nsmr_register_phys_kern(to_c2dev(ib_pd->device), page_list,410(1 << page_shift), pbl_depth,411total_len, 0, iova_start,412c2_convert_access(acc), mr);413vfree(page_list);414if (err) {415kfree(mr);416return ERR_PTR(err);417}418419return &mr->ibmr;420}421422static struct ib_mr *c2_get_dma_mr(struct ib_pd *pd, int acc)423{424struct ib_phys_buf bl;425u64 kva = 0;426427pr_debug("%s:%u\n", __func__, __LINE__);428429/* AMSO1100 limit */430bl.size = 0xffffffff;431bl.addr = 0;432return c2_reg_phys_mr(pd, &bl, 1, acc, &kva);433}434435static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,436u64 virt, int acc, struct ib_udata *udata)437{438u64 *pages;439u64 kva = 0;440int shift, n, len;441int i, j, k;442int err = 0;443struct ib_umem_chunk *chunk;444struct c2_pd *c2pd = to_c2pd(pd);445struct c2_mr *c2mr;446447pr_debug("%s:%u\n", __func__, __LINE__);448449c2mr = kmalloc(sizeof(*c2mr), GFP_KERNEL);450if (!c2mr)451return ERR_PTR(-ENOMEM);452c2mr->pd = c2pd;453454c2mr->umem = ib_umem_get(pd->uobject->context, start, length, acc, 0);455if (IS_ERR(c2mr->umem)) {456err = PTR_ERR(c2mr->umem);457kfree(c2mr);458return ERR_PTR(err);459}460461shift = ffs(c2mr->umem->page_size) - 1;462463n = 0;464list_for_each_entry(chunk, &c2mr->umem->chunk_list, list)465n += chunk->nents;466467pages = kmalloc(n * sizeof(u64), GFP_KERNEL);468if (!pages) {469err = -ENOMEM;470goto err;471}472473i = 0;474list_for_each_entry(chunk, &c2mr->umem->chunk_list, list) {475for (j = 0; j < chunk->nmap; ++j) {476len = sg_dma_len(&chunk->page_list[j]) >> shift;477for (k = 0; k < len; ++k) {478pages[i++] =479sg_dma_address(&chunk->page_list[j]) +480(c2mr->umem->page_size * k);481}482}483}484485kva = virt;486err = c2_nsmr_register_phys_kern(to_c2dev(pd->device),487pages,488c2mr->umem->page_size,489i,490length,491c2mr->umem->offset,492&kva,493c2_convert_access(acc),494c2mr);495kfree(pages);496if (err)497goto err;498return &c2mr->ibmr;499500err:501ib_umem_release(c2mr->umem);502kfree(c2mr);503return ERR_PTR(err);504}505506static int c2_dereg_mr(struct ib_mr *ib_mr)507{508struct c2_mr *mr = to_c2mr(ib_mr);509int err;510511pr_debug("%s:%u\n", __func__, __LINE__);512513err = c2_stag_dealloc(to_c2dev(ib_mr->device), ib_mr->lkey);514if (err)515pr_debug("c2_stag_dealloc failed: %d\n", err);516else {517if (mr->umem)518ib_umem_release(mr->umem);519kfree(mr);520}521522return err;523}524525static ssize_t show_rev(struct device *dev, struct device_attribute *attr,526char *buf)527{528struct c2_dev *c2dev = container_of(dev, struct c2_dev, ibdev.dev);529pr_debug("%s:%u\n", __func__, __LINE__);530return sprintf(buf, "%x\n", c2dev->props.hw_ver);531}532533static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,534char *buf)535{536struct c2_dev *c2dev = container_of(dev, struct c2_dev, ibdev.dev);537pr_debug("%s:%u\n", __func__, __LINE__);538return 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));542}543544static ssize_t show_hca(struct device *dev, struct device_attribute *attr,545char *buf)546{547pr_debug("%s:%u\n", __func__, __LINE__);548return sprintf(buf, "AMSO1100\n");549}550551static ssize_t show_board(struct device *dev, struct device_attribute *attr,552char *buf)553{554pr_debug("%s:%u\n", __func__, __LINE__);555return sprintf(buf, "%.*s\n", 32, "AMSO1100 Board ID");556}557558static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);559static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);560static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);561static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);562563static 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_id568};569570static int c2_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,571int attr_mask, struct ib_udata *udata)572{573int err;574575err =576c2_qp_modify(to_c2dev(ibqp->device), to_c2qp(ibqp), attr,577attr_mask);578579return err;580}581582static int c2_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)583{584pr_debug("%s:%u\n", __func__, __LINE__);585return -ENOSYS;586}587588static int c2_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)589{590pr_debug("%s:%u\n", __func__, __LINE__);591return -ENOSYS;592}593594static int c2_process_mad(struct ib_device *ibdev,595int mad_flags,596u8 port_num,597struct ib_wc *in_wc,598struct ib_grh *in_grh,599struct ib_mad *in_mad, struct ib_mad *out_mad)600{601pr_debug("%s:%u\n", __func__, __LINE__);602return -ENOSYS;603}604605static int c2_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)606{607pr_debug("%s:%u\n", __func__, __LINE__);608609/* Request a connection */610return c2_llp_connect(cm_id, iw_param);611}612613static int c2_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param)614{615pr_debug("%s:%u\n", __func__, __LINE__);616617/* Accept the new connection */618return c2_llp_accept(cm_id, iw_param);619}620621static int c2_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)622{623int err;624625pr_debug("%s:%u\n", __func__, __LINE__);626627err = c2_llp_reject(cm_id, pdata, pdata_len);628return err;629}630631static int c2_service_create(struct iw_cm_id *cm_id, int backlog)632{633int err;634635pr_debug("%s:%u\n", __func__, __LINE__);636err = c2_llp_service_create(cm_id, backlog);637pr_debug("%s:%u err=%d\n",638__func__, __LINE__,639err);640return err;641}642643static int c2_service_destroy(struct iw_cm_id *cm_id)644{645int err;646pr_debug("%s:%u\n", __func__, __LINE__);647648err = c2_llp_service_destroy(cm_id);649650return err;651}652653static int c2_pseudo_up(struct net_device *netdev)654{655struct in_device *ind;656struct c2_dev *c2dev = netdev->ml_priv;657658ind = in_dev_get(netdev);659if (!ind)660return 0;661662pr_debug("adding...\n");663for_ifa(ind) {664#ifdef DEBUG665u8 *ip = (u8 *) & ifa->ifa_address;666667pr_debug("%s: %d.%d.%d.%d\n",668ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);669#endif670c2_add_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);671}672endfor_ifa(ind);673in_dev_put(ind);674675return 0;676}677678static int c2_pseudo_down(struct net_device *netdev)679{680struct in_device *ind;681struct c2_dev *c2dev = netdev->ml_priv;682683ind = in_dev_get(netdev);684if (!ind)685return 0;686687pr_debug("deleting...\n");688for_ifa(ind) {689#ifdef DEBUG690u8 *ip = (u8 *) & ifa->ifa_address;691692pr_debug("%s: %d.%d.%d.%d\n",693ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]);694#endif695c2_del_addr(c2dev, ifa->ifa_address, ifa->ifa_mask);696}697endfor_ifa(ind);698in_dev_put(ind);699700return 0;701}702703static int c2_pseudo_xmit_frame(struct sk_buff *skb, struct net_device *netdev)704{705kfree_skb(skb);706return NETDEV_TX_OK;707}708709static int c2_pseudo_change_mtu(struct net_device *netdev, int new_mtu)710{711if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU)712return -EINVAL;713714netdev->mtu = new_mtu;715716/* TODO: Tell rnic about new rmda interface mtu */717return 0;718}719720static 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,726};727728static void setup(struct net_device *netdev)729{730netdev->netdev_ops = &c2_pseudo_netdev_ops;731732netdev->watchdog_timeo = 0;733netdev->type = ARPHRD_ETHER;734netdev->mtu = 1500;735netdev->hard_header_len = ETH_HLEN;736netdev->addr_len = ETH_ALEN;737netdev->tx_queue_len = 0;738netdev->flags |= IFF_NOARP;739}740741static struct net_device *c2_pseudo_netdev_init(struct c2_dev *c2dev)742{743char name[IFNAMSIZ];744struct net_device *netdev;745746/* change ethxxx to iwxxx */747strcpy(name, "iw");748strcat(name, &c2dev->netdev->name[3]);749netdev = alloc_netdev(0, name, setup);750if (!netdev) {751printk(KERN_ERR PFX "%s - etherdev alloc failed",752__func__);753return NULL;754}755756netdev->ml_priv = c2dev;757758SET_NETDEV_DEV(netdev, &c2dev->pcidev->dev);759760memcpy_fromio(netdev->dev_addr, c2dev->kva + C2_REGS_RDMA_ENADDR, 6);761762/* Print out the MAC address */763pr_debug("%s: MAC %02X:%02X:%02X:%02X:%02X:%02X\n",764netdev->name,765netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2],766netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]);767768#if 0769/* Disable network packets */770netif_stop_queue(netdev);771#endif772return netdev;773}774775int c2_register_device(struct c2_dev *dev)776{777int ret = -ENOMEM;778int i;779780/* Register pseudo network device */781dev->pseudo_netdev = c2_pseudo_netdev_init(dev);782if (!dev->pseudo_netdev)783goto out;784785ret = register_netdev(dev->pseudo_netdev);786if (ret)787goto out_free_netdev;788789pr_debug("%s:%u\n", __func__, __LINE__);790strlcpy(dev->ibdev.name, "amso%d", IB_DEVICE_NAME_MAX);791dev->ibdev.owner = THIS_MODULE;792dev->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);810811dev->ibdev.node_type = RDMA_NODE_RNIC;812memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));813memcpy(&dev->ibdev.node_guid, dev->pseudo_netdev->dev_addr, 6);814dev->ibdev.phys_port_cnt = 1;815dev->ibdev.num_comp_vectors = 1;816dev->ibdev.dma_device = &dev->pcidev->dev;817dev->ibdev.query_device = c2_query_device;818dev->ibdev.query_port = c2_query_port;819dev->ibdev.modify_port = c2_modify_port;820dev->ibdev.query_pkey = c2_query_pkey;821dev->ibdev.query_gid = c2_query_gid;822dev->ibdev.alloc_ucontext = c2_alloc_ucontext;823dev->ibdev.dealloc_ucontext = c2_dealloc_ucontext;824dev->ibdev.mmap = c2_mmap_uar;825dev->ibdev.alloc_pd = c2_alloc_pd;826dev->ibdev.dealloc_pd = c2_dealloc_pd;827dev->ibdev.create_ah = c2_ah_create;828dev->ibdev.destroy_ah = c2_ah_destroy;829dev->ibdev.create_qp = c2_create_qp;830dev->ibdev.modify_qp = c2_modify_qp;831dev->ibdev.destroy_qp = c2_destroy_qp;832dev->ibdev.create_cq = c2_create_cq;833dev->ibdev.destroy_cq = c2_destroy_cq;834dev->ibdev.poll_cq = c2_poll_cq;835dev->ibdev.get_dma_mr = c2_get_dma_mr;836dev->ibdev.reg_phys_mr = c2_reg_phys_mr;837dev->ibdev.reg_user_mr = c2_reg_user_mr;838dev->ibdev.dereg_mr = c2_dereg_mr;839840dev->ibdev.alloc_fmr = NULL;841dev->ibdev.unmap_fmr = NULL;842dev->ibdev.dealloc_fmr = NULL;843dev->ibdev.map_phys_fmr = NULL;844845dev->ibdev.attach_mcast = c2_multicast_attach;846dev->ibdev.detach_mcast = c2_multicast_detach;847dev->ibdev.process_mad = c2_process_mad;848849dev->ibdev.req_notify_cq = c2_arm_cq;850dev->ibdev.post_send = c2_post_send;851dev->ibdev.post_recv = c2_post_receive;852853dev->ibdev.iwcm = kmalloc(sizeof(*dev->ibdev.iwcm), GFP_KERNEL);854if (dev->ibdev.iwcm == NULL) {855ret = -ENOMEM;856goto out_unregister_netdev;857}858dev->ibdev.iwcm->add_ref = c2_add_ref;859dev->ibdev.iwcm->rem_ref = c2_rem_ref;860dev->ibdev.iwcm->get_qp = c2_get_qp;861dev->ibdev.iwcm->connect = c2_connect;862dev->ibdev.iwcm->accept = c2_accept;863dev->ibdev.iwcm->reject = c2_reject;864dev->ibdev.iwcm->create_listen = c2_service_create;865dev->ibdev.iwcm->destroy_listen = c2_service_destroy;866867ret = ib_register_device(&dev->ibdev, NULL);868if (ret)869goto out_free_iwcm;870871for (i = 0; i < ARRAY_SIZE(c2_dev_attributes); ++i) {872ret = device_create_file(&dev->ibdev.dev,873c2_dev_attributes[i]);874if (ret)875goto out_unregister_ibdev;876}877goto out;878879out_unregister_ibdev:880ib_unregister_device(&dev->ibdev);881out_free_iwcm:882kfree(dev->ibdev.iwcm);883out_unregister_netdev:884unregister_netdev(dev->pseudo_netdev);885out_free_netdev:886free_netdev(dev->pseudo_netdev);887out:888pr_debug("%s:%u ret=%d\n", __func__, __LINE__, ret);889return ret;890}891892void c2_unregister_device(struct c2_dev *dev)893{894pr_debug("%s:%u\n", __func__, __LINE__);895unregister_netdev(dev->pseudo_netdev);896free_netdev(dev->pseudo_netdev);897ib_unregister_device(&dev->ibdev);898}899900901