12e0cbc4dSRam Amrani /* QLogic qedr NIC Driver 22e0cbc4dSRam Amrani * Copyright (c) 2015-2016 QLogic Corporation 32e0cbc4dSRam Amrani * 42e0cbc4dSRam Amrani * This software is available to you under a choice of one of two 52e0cbc4dSRam Amrani * licenses. You may choose to be licensed under the terms of the GNU 62e0cbc4dSRam Amrani * General Public License (GPL) Version 2, available from the file 72e0cbc4dSRam Amrani * COPYING in the main directory of this source tree, or the 82e0cbc4dSRam Amrani * OpenIB.org BSD license below: 92e0cbc4dSRam Amrani * 102e0cbc4dSRam Amrani * Redistribution and use in source and binary forms, with or 112e0cbc4dSRam Amrani * without modification, are permitted provided that the following 122e0cbc4dSRam Amrani * conditions are met: 132e0cbc4dSRam Amrani * 142e0cbc4dSRam Amrani * - Redistributions of source code must retain the above 152e0cbc4dSRam Amrani * copyright notice, this list of conditions and the following 162e0cbc4dSRam Amrani * disclaimer. 172e0cbc4dSRam Amrani * 182e0cbc4dSRam Amrani * - Redistributions in binary form must reproduce the above 192e0cbc4dSRam Amrani * copyright notice, this list of conditions and the following 202e0cbc4dSRam Amrani * disclaimer in the documentation and /or other materials 212e0cbc4dSRam Amrani * provided with the distribution. 222e0cbc4dSRam Amrani * 232e0cbc4dSRam Amrani * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 242e0cbc4dSRam Amrani * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 252e0cbc4dSRam Amrani * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 262e0cbc4dSRam Amrani * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 272e0cbc4dSRam Amrani * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 282e0cbc4dSRam Amrani * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 292e0cbc4dSRam Amrani * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 302e0cbc4dSRam Amrani * SOFTWARE. 312e0cbc4dSRam Amrani */ 322e0cbc4dSRam Amrani #include <linux/module.h> 332e0cbc4dSRam Amrani #include <rdma/ib_verbs.h> 342e0cbc4dSRam Amrani #include <rdma/ib_addr.h> 35ac1b36e5SRam Amrani #include <rdma/ib_user_verbs.h> 362e0cbc4dSRam Amrani #include <linux/netdevice.h> 372e0cbc4dSRam Amrani #include <linux/iommu.h> 382e0cbc4dSRam Amrani #include <net/addrconf.h> 392e0cbc4dSRam Amrani #include <linux/qed/qede_roce.h> 40ec72fce4SRam Amrani #include <linux/qed/qed_chain.h> 41ec72fce4SRam Amrani #include <linux/qed/qed_if.h> 422e0cbc4dSRam Amrani #include "qedr.h" 43ac1b36e5SRam Amrani #include "verbs.h" 44ac1b36e5SRam Amrani #include <rdma/qedr-abi.h> 452e0cbc4dSRam Amrani 462e0cbc4dSRam Amrani MODULE_DESCRIPTION("QLogic 40G/100G ROCE Driver"); 472e0cbc4dSRam Amrani MODULE_AUTHOR("QLogic Corporation"); 482e0cbc4dSRam Amrani MODULE_LICENSE("Dual BSD/GPL"); 492e0cbc4dSRam Amrani MODULE_VERSION(QEDR_MODULE_VERSION); 502e0cbc4dSRam Amrani 51*cecbcddfSRam Amrani #define QEDR_WQ_MULTIPLIER_DFT (3) 52*cecbcddfSRam Amrani 532e0cbc4dSRam Amrani void qedr_ib_dispatch_event(struct qedr_dev *dev, u8 port_num, 542e0cbc4dSRam Amrani enum ib_event_type type) 552e0cbc4dSRam Amrani { 562e0cbc4dSRam Amrani struct ib_event ibev; 572e0cbc4dSRam Amrani 582e0cbc4dSRam Amrani ibev.device = &dev->ibdev; 592e0cbc4dSRam Amrani ibev.element.port_num = port_num; 602e0cbc4dSRam Amrani ibev.event = type; 612e0cbc4dSRam Amrani 622e0cbc4dSRam Amrani ib_dispatch_event(&ibev); 632e0cbc4dSRam Amrani } 642e0cbc4dSRam Amrani 652e0cbc4dSRam Amrani static enum rdma_link_layer qedr_link_layer(struct ib_device *device, 662e0cbc4dSRam Amrani u8 port_num) 672e0cbc4dSRam Amrani { 682e0cbc4dSRam Amrani return IB_LINK_LAYER_ETHERNET; 692e0cbc4dSRam Amrani } 702e0cbc4dSRam Amrani 71ec72fce4SRam Amrani static void qedr_get_dev_fw_str(struct ib_device *ibdev, char *str, 72ec72fce4SRam Amrani size_t str_len) 73ec72fce4SRam Amrani { 74ec72fce4SRam Amrani struct qedr_dev *qedr = get_qedr_dev(ibdev); 75ec72fce4SRam Amrani u32 fw_ver = (u32)qedr->attr.fw_ver; 76ec72fce4SRam Amrani 77ec72fce4SRam Amrani snprintf(str, str_len, "%d. %d. %d. %d", 78ec72fce4SRam Amrani (fw_ver >> 24) & 0xFF, (fw_ver >> 16) & 0xFF, 79ec72fce4SRam Amrani (fw_ver >> 8) & 0xFF, fw_ver & 0xFF); 80ec72fce4SRam Amrani } 81ec72fce4SRam Amrani 822e0cbc4dSRam Amrani static int qedr_register_device(struct qedr_dev *dev) 832e0cbc4dSRam Amrani { 842e0cbc4dSRam Amrani strlcpy(dev->ibdev.name, "qedr%d", IB_DEVICE_NAME_MAX); 852e0cbc4dSRam Amrani 862e0cbc4dSRam Amrani memcpy(dev->ibdev.node_desc, QEDR_NODE_DESC, sizeof(QEDR_NODE_DESC)); 872e0cbc4dSRam Amrani dev->ibdev.owner = THIS_MODULE; 88ac1b36e5SRam Amrani dev->ibdev.uverbs_abi_ver = QEDR_ABI_VERSION; 89ac1b36e5SRam Amrani 90ac1b36e5SRam Amrani dev->ibdev.uverbs_cmd_mask = QEDR_UVERBS(GET_CONTEXT) | 91ac1b36e5SRam Amrani QEDR_UVERBS(QUERY_DEVICE) | 92a7efd777SRam Amrani QEDR_UVERBS(QUERY_PORT) | 93a7efd777SRam Amrani QEDR_UVERBS(ALLOC_PD) | 94a7efd777SRam Amrani QEDR_UVERBS(DEALLOC_PD) | 95a7efd777SRam Amrani QEDR_UVERBS(CREATE_COMP_CHANNEL) | 96a7efd777SRam Amrani QEDR_UVERBS(CREATE_CQ) | 97a7efd777SRam Amrani QEDR_UVERBS(RESIZE_CQ) | 98a7efd777SRam Amrani QEDR_UVERBS(DESTROY_CQ) | 99*cecbcddfSRam Amrani QEDR_UVERBS(REQ_NOTIFY_CQ) | 100*cecbcddfSRam Amrani QEDR_UVERBS(CREATE_QP) | 101*cecbcddfSRam Amrani QEDR_UVERBS(MODIFY_QP) | 102*cecbcddfSRam Amrani QEDR_UVERBS(QUERY_QP) | 103*cecbcddfSRam Amrani QEDR_UVERBS(DESTROY_QP); 104ac1b36e5SRam Amrani 105ac1b36e5SRam Amrani dev->ibdev.phys_port_cnt = 1; 106ac1b36e5SRam Amrani dev->ibdev.num_comp_vectors = dev->num_cnq; 107ac1b36e5SRam Amrani dev->ibdev.node_type = RDMA_NODE_IB_CA; 108ac1b36e5SRam Amrani 109ac1b36e5SRam Amrani dev->ibdev.query_device = qedr_query_device; 110ac1b36e5SRam Amrani dev->ibdev.query_port = qedr_query_port; 111ac1b36e5SRam Amrani dev->ibdev.modify_port = qedr_modify_port; 112ac1b36e5SRam Amrani 113ac1b36e5SRam Amrani dev->ibdev.query_gid = qedr_query_gid; 114ac1b36e5SRam Amrani dev->ibdev.add_gid = qedr_add_gid; 115ac1b36e5SRam Amrani dev->ibdev.del_gid = qedr_del_gid; 116ac1b36e5SRam Amrani 117ac1b36e5SRam Amrani dev->ibdev.alloc_ucontext = qedr_alloc_ucontext; 118ac1b36e5SRam Amrani dev->ibdev.dealloc_ucontext = qedr_dealloc_ucontext; 119ac1b36e5SRam Amrani dev->ibdev.mmap = qedr_mmap; 120ac1b36e5SRam Amrani 121a7efd777SRam Amrani dev->ibdev.alloc_pd = qedr_alloc_pd; 122a7efd777SRam Amrani dev->ibdev.dealloc_pd = qedr_dealloc_pd; 123a7efd777SRam Amrani 124a7efd777SRam Amrani dev->ibdev.create_cq = qedr_create_cq; 125a7efd777SRam Amrani dev->ibdev.destroy_cq = qedr_destroy_cq; 126a7efd777SRam Amrani dev->ibdev.resize_cq = qedr_resize_cq; 127a7efd777SRam Amrani dev->ibdev.req_notify_cq = qedr_arm_cq; 128a7efd777SRam Amrani 129*cecbcddfSRam Amrani dev->ibdev.create_qp = qedr_create_qp; 130*cecbcddfSRam Amrani dev->ibdev.modify_qp = qedr_modify_qp; 131*cecbcddfSRam Amrani dev->ibdev.query_qp = qedr_query_qp; 132*cecbcddfSRam Amrani dev->ibdev.destroy_qp = qedr_destroy_qp; 133*cecbcddfSRam Amrani 134a7efd777SRam Amrani dev->ibdev.query_pkey = qedr_query_pkey; 135a7efd777SRam Amrani 136ac1b36e5SRam Amrani dev->ibdev.dma_device = &dev->pdev->dev; 1372e0cbc4dSRam Amrani 1382e0cbc4dSRam Amrani dev->ibdev.get_link_layer = qedr_link_layer; 139ec72fce4SRam Amrani dev->ibdev.get_dev_fw_str = qedr_get_dev_fw_str; 1402e0cbc4dSRam Amrani 1412e0cbc4dSRam Amrani return 0; 1422e0cbc4dSRam Amrani } 1432e0cbc4dSRam Amrani 144ec72fce4SRam Amrani /* This function allocates fast-path status block memory */ 145ec72fce4SRam Amrani static int qedr_alloc_mem_sb(struct qedr_dev *dev, 146ec72fce4SRam Amrani struct qed_sb_info *sb_info, u16 sb_id) 147ec72fce4SRam Amrani { 148ec72fce4SRam Amrani struct status_block *sb_virt; 149ec72fce4SRam Amrani dma_addr_t sb_phys; 150ec72fce4SRam Amrani int rc; 151ec72fce4SRam Amrani 152ec72fce4SRam Amrani sb_virt = dma_alloc_coherent(&dev->pdev->dev, 153ec72fce4SRam Amrani sizeof(*sb_virt), &sb_phys, GFP_KERNEL); 154ec72fce4SRam Amrani if (!sb_virt) 155ec72fce4SRam Amrani return -ENOMEM; 156ec72fce4SRam Amrani 157ec72fce4SRam Amrani rc = dev->ops->common->sb_init(dev->cdev, sb_info, 158ec72fce4SRam Amrani sb_virt, sb_phys, sb_id, 159ec72fce4SRam Amrani QED_SB_TYPE_CNQ); 160ec72fce4SRam Amrani if (rc) { 161ec72fce4SRam Amrani pr_err("Status block initialization failed\n"); 162ec72fce4SRam Amrani dma_free_coherent(&dev->pdev->dev, sizeof(*sb_virt), 163ec72fce4SRam Amrani sb_virt, sb_phys); 164ec72fce4SRam Amrani return rc; 165ec72fce4SRam Amrani } 166ec72fce4SRam Amrani 167ec72fce4SRam Amrani return 0; 168ec72fce4SRam Amrani } 169ec72fce4SRam Amrani 170ec72fce4SRam Amrani static void qedr_free_mem_sb(struct qedr_dev *dev, 171ec72fce4SRam Amrani struct qed_sb_info *sb_info, int sb_id) 172ec72fce4SRam Amrani { 173ec72fce4SRam Amrani if (sb_info->sb_virt) { 174ec72fce4SRam Amrani dev->ops->common->sb_release(dev->cdev, sb_info, sb_id); 175ec72fce4SRam Amrani dma_free_coherent(&dev->pdev->dev, sizeof(*sb_info->sb_virt), 176ec72fce4SRam Amrani (void *)sb_info->sb_virt, sb_info->sb_phys); 177ec72fce4SRam Amrani } 178ec72fce4SRam Amrani } 179ec72fce4SRam Amrani 180ec72fce4SRam Amrani static void qedr_free_resources(struct qedr_dev *dev) 181ec72fce4SRam Amrani { 182ec72fce4SRam Amrani int i; 183ec72fce4SRam Amrani 184ec72fce4SRam Amrani for (i = 0; i < dev->num_cnq; i++) { 185ec72fce4SRam Amrani qedr_free_mem_sb(dev, &dev->sb_array[i], dev->sb_start + i); 186ec72fce4SRam Amrani dev->ops->common->chain_free(dev->cdev, &dev->cnq_array[i].pbl); 187ec72fce4SRam Amrani } 188ec72fce4SRam Amrani 189ec72fce4SRam Amrani kfree(dev->cnq_array); 190ec72fce4SRam Amrani kfree(dev->sb_array); 191ec72fce4SRam Amrani kfree(dev->sgid_tbl); 192ec72fce4SRam Amrani } 193ec72fce4SRam Amrani 194ec72fce4SRam Amrani static int qedr_alloc_resources(struct qedr_dev *dev) 195ec72fce4SRam Amrani { 196ec72fce4SRam Amrani struct qedr_cnq *cnq; 197ec72fce4SRam Amrani __le16 *cons_pi; 198ec72fce4SRam Amrani u16 n_entries; 199ec72fce4SRam Amrani int i, rc; 200ec72fce4SRam Amrani 201ec72fce4SRam Amrani dev->sgid_tbl = kzalloc(sizeof(union ib_gid) * 202ec72fce4SRam Amrani QEDR_MAX_SGID, GFP_KERNEL); 203ec72fce4SRam Amrani if (!dev->sgid_tbl) 204ec72fce4SRam Amrani return -ENOMEM; 205ec72fce4SRam Amrani 206ec72fce4SRam Amrani spin_lock_init(&dev->sgid_lock); 207ec72fce4SRam Amrani 208ec72fce4SRam Amrani /* Allocate Status blocks for CNQ */ 209ec72fce4SRam Amrani dev->sb_array = kcalloc(dev->num_cnq, sizeof(*dev->sb_array), 210ec72fce4SRam Amrani GFP_KERNEL); 211ec72fce4SRam Amrani if (!dev->sb_array) { 212ec72fce4SRam Amrani rc = -ENOMEM; 213ec72fce4SRam Amrani goto err1; 214ec72fce4SRam Amrani } 215ec72fce4SRam Amrani 216ec72fce4SRam Amrani dev->cnq_array = kcalloc(dev->num_cnq, 217ec72fce4SRam Amrani sizeof(*dev->cnq_array), GFP_KERNEL); 218ec72fce4SRam Amrani if (!dev->cnq_array) { 219ec72fce4SRam Amrani rc = -ENOMEM; 220ec72fce4SRam Amrani goto err2; 221ec72fce4SRam Amrani } 222ec72fce4SRam Amrani 223ec72fce4SRam Amrani dev->sb_start = dev->ops->rdma_get_start_sb(dev->cdev); 224ec72fce4SRam Amrani 225ec72fce4SRam Amrani /* Allocate CNQ PBLs */ 226ec72fce4SRam Amrani n_entries = min_t(u32, QED_RDMA_MAX_CNQ_SIZE, QEDR_ROCE_MAX_CNQ_SIZE); 227ec72fce4SRam Amrani for (i = 0; i < dev->num_cnq; i++) { 228ec72fce4SRam Amrani cnq = &dev->cnq_array[i]; 229ec72fce4SRam Amrani 230ec72fce4SRam Amrani rc = qedr_alloc_mem_sb(dev, &dev->sb_array[i], 231ec72fce4SRam Amrani dev->sb_start + i); 232ec72fce4SRam Amrani if (rc) 233ec72fce4SRam Amrani goto err3; 234ec72fce4SRam Amrani 235ec72fce4SRam Amrani rc = dev->ops->common->chain_alloc(dev->cdev, 236ec72fce4SRam Amrani QED_CHAIN_USE_TO_CONSUME, 237ec72fce4SRam Amrani QED_CHAIN_MODE_PBL, 238ec72fce4SRam Amrani QED_CHAIN_CNT_TYPE_U16, 239ec72fce4SRam Amrani n_entries, 240ec72fce4SRam Amrani sizeof(struct regpair *), 241ec72fce4SRam Amrani &cnq->pbl); 242ec72fce4SRam Amrani if (rc) 243ec72fce4SRam Amrani goto err4; 244ec72fce4SRam Amrani 245ec72fce4SRam Amrani cnq->dev = dev; 246ec72fce4SRam Amrani cnq->sb = &dev->sb_array[i]; 247ec72fce4SRam Amrani cons_pi = dev->sb_array[i].sb_virt->pi_array; 248ec72fce4SRam Amrani cnq->hw_cons_ptr = &cons_pi[QED_ROCE_PROTOCOL_INDEX]; 249ec72fce4SRam Amrani cnq->index = i; 250ec72fce4SRam Amrani sprintf(cnq->name, "qedr%d@pci:%s", i, pci_name(dev->pdev)); 251ec72fce4SRam Amrani 252ec72fce4SRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, "cnq[%d].cons=%d\n", 253ec72fce4SRam Amrani i, qed_chain_get_cons_idx(&cnq->pbl)); 254ec72fce4SRam Amrani } 255ec72fce4SRam Amrani 256ec72fce4SRam Amrani return 0; 257ec72fce4SRam Amrani err4: 258ec72fce4SRam Amrani qedr_free_mem_sb(dev, &dev->sb_array[i], dev->sb_start + i); 259ec72fce4SRam Amrani err3: 260ec72fce4SRam Amrani for (--i; i >= 0; i--) { 261ec72fce4SRam Amrani dev->ops->common->chain_free(dev->cdev, &dev->cnq_array[i].pbl); 262ec72fce4SRam Amrani qedr_free_mem_sb(dev, &dev->sb_array[i], dev->sb_start + i); 263ec72fce4SRam Amrani } 264ec72fce4SRam Amrani kfree(dev->cnq_array); 265ec72fce4SRam Amrani err2: 266ec72fce4SRam Amrani kfree(dev->sb_array); 267ec72fce4SRam Amrani err1: 268ec72fce4SRam Amrani kfree(dev->sgid_tbl); 269ec72fce4SRam Amrani return rc; 270ec72fce4SRam Amrani } 271ec72fce4SRam Amrani 2722e0cbc4dSRam Amrani /* QEDR sysfs interface */ 2732e0cbc4dSRam Amrani static ssize_t show_rev(struct device *device, struct device_attribute *attr, 2742e0cbc4dSRam Amrani char *buf) 2752e0cbc4dSRam Amrani { 2762e0cbc4dSRam Amrani struct qedr_dev *dev = dev_get_drvdata(device); 2772e0cbc4dSRam Amrani 2782e0cbc4dSRam Amrani return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->pdev->vendor); 2792e0cbc4dSRam Amrani } 2802e0cbc4dSRam Amrani 2812e0cbc4dSRam Amrani static ssize_t show_hca_type(struct device *device, 2822e0cbc4dSRam Amrani struct device_attribute *attr, char *buf) 2832e0cbc4dSRam Amrani { 2842e0cbc4dSRam Amrani return scnprintf(buf, PAGE_SIZE, "%s\n", "HCA_TYPE_TO_SET"); 2852e0cbc4dSRam Amrani } 2862e0cbc4dSRam Amrani 2872e0cbc4dSRam Amrani static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); 2882e0cbc4dSRam Amrani static DEVICE_ATTR(hca_type, S_IRUGO, show_hca_type, NULL); 2892e0cbc4dSRam Amrani 2902e0cbc4dSRam Amrani static struct device_attribute *qedr_attributes[] = { 2912e0cbc4dSRam Amrani &dev_attr_hw_rev, 2922e0cbc4dSRam Amrani &dev_attr_hca_type 2932e0cbc4dSRam Amrani }; 2942e0cbc4dSRam Amrani 2952e0cbc4dSRam Amrani static void qedr_remove_sysfiles(struct qedr_dev *dev) 2962e0cbc4dSRam Amrani { 2972e0cbc4dSRam Amrani int i; 2982e0cbc4dSRam Amrani 2992e0cbc4dSRam Amrani for (i = 0; i < ARRAY_SIZE(qedr_attributes); i++) 3002e0cbc4dSRam Amrani device_remove_file(&dev->ibdev.dev, qedr_attributes[i]); 3012e0cbc4dSRam Amrani } 3022e0cbc4dSRam Amrani 3032e0cbc4dSRam Amrani static void qedr_pci_set_atomic(struct qedr_dev *dev, struct pci_dev *pdev) 3042e0cbc4dSRam Amrani { 3052e0cbc4dSRam Amrani struct pci_dev *bridge; 3062e0cbc4dSRam Amrani u32 val; 3072e0cbc4dSRam Amrani 3082e0cbc4dSRam Amrani dev->atomic_cap = IB_ATOMIC_NONE; 3092e0cbc4dSRam Amrani 3102e0cbc4dSRam Amrani bridge = pdev->bus->self; 3112e0cbc4dSRam Amrani if (!bridge) 3122e0cbc4dSRam Amrani return; 3132e0cbc4dSRam Amrani 3142e0cbc4dSRam Amrani /* Check whether we are connected directly or via a switch */ 3152e0cbc4dSRam Amrani while (bridge && bridge->bus->parent) { 3162e0cbc4dSRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, 3172e0cbc4dSRam Amrani "Device is not connected directly to root. bridge->bus->number=%d primary=%d\n", 3182e0cbc4dSRam Amrani bridge->bus->number, bridge->bus->primary); 3192e0cbc4dSRam Amrani /* Need to check Atomic Op Routing Supported all the way to 3202e0cbc4dSRam Amrani * root complex. 3212e0cbc4dSRam Amrani */ 3222e0cbc4dSRam Amrani pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &val); 3232e0cbc4dSRam Amrani if (!(val & PCI_EXP_DEVCAP2_ATOMIC_ROUTE)) { 3242e0cbc4dSRam Amrani pcie_capability_clear_word(pdev, 3252e0cbc4dSRam Amrani PCI_EXP_DEVCTL2, 3262e0cbc4dSRam Amrani PCI_EXP_DEVCTL2_ATOMIC_REQ); 3272e0cbc4dSRam Amrani return; 3282e0cbc4dSRam Amrani } 3292e0cbc4dSRam Amrani bridge = bridge->bus->parent->self; 3302e0cbc4dSRam Amrani } 3312e0cbc4dSRam Amrani bridge = pdev->bus->self; 3322e0cbc4dSRam Amrani 3332e0cbc4dSRam Amrani /* according to bridge capability */ 3342e0cbc4dSRam Amrani pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &val); 3352e0cbc4dSRam Amrani if (val & PCI_EXP_DEVCAP2_ATOMIC_COMP64) { 3362e0cbc4dSRam Amrani pcie_capability_set_word(pdev, PCI_EXP_DEVCTL2, 3372e0cbc4dSRam Amrani PCI_EXP_DEVCTL2_ATOMIC_REQ); 3382e0cbc4dSRam Amrani dev->atomic_cap = IB_ATOMIC_GLOB; 3392e0cbc4dSRam Amrani } else { 3402e0cbc4dSRam Amrani pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL2, 3412e0cbc4dSRam Amrani PCI_EXP_DEVCTL2_ATOMIC_REQ); 3422e0cbc4dSRam Amrani } 3432e0cbc4dSRam Amrani } 3442e0cbc4dSRam Amrani 345ec72fce4SRam Amrani static const struct qed_rdma_ops *qed_ops; 346ec72fce4SRam Amrani 347ec72fce4SRam Amrani #define HILO_U64(hi, lo) ((((u64)(hi)) << 32) + (lo)) 348ec72fce4SRam Amrani 349ec72fce4SRam Amrani static irqreturn_t qedr_irq_handler(int irq, void *handle) 350ec72fce4SRam Amrani { 351ec72fce4SRam Amrani u16 hw_comp_cons, sw_comp_cons; 352ec72fce4SRam Amrani struct qedr_cnq *cnq = handle; 353a7efd777SRam Amrani struct regpair *cq_handle; 354a7efd777SRam Amrani struct qedr_cq *cq; 355ec72fce4SRam Amrani 356ec72fce4SRam Amrani qed_sb_ack(cnq->sb, IGU_INT_DISABLE, 0); 357ec72fce4SRam Amrani 358ec72fce4SRam Amrani qed_sb_update_sb_idx(cnq->sb); 359ec72fce4SRam Amrani 360ec72fce4SRam Amrani hw_comp_cons = le16_to_cpu(*cnq->hw_cons_ptr); 361ec72fce4SRam Amrani sw_comp_cons = qed_chain_get_cons_idx(&cnq->pbl); 362ec72fce4SRam Amrani 363ec72fce4SRam Amrani /* Align protocol-index and chain reads */ 364ec72fce4SRam Amrani rmb(); 365ec72fce4SRam Amrani 366ec72fce4SRam Amrani while (sw_comp_cons != hw_comp_cons) { 367a7efd777SRam Amrani cq_handle = (struct regpair *)qed_chain_consume(&cnq->pbl); 368a7efd777SRam Amrani cq = (struct qedr_cq *)(uintptr_t)HILO_U64(cq_handle->hi, 369a7efd777SRam Amrani cq_handle->lo); 370a7efd777SRam Amrani 371a7efd777SRam Amrani if (cq == NULL) { 372a7efd777SRam Amrani DP_ERR(cnq->dev, 373a7efd777SRam Amrani "Received NULL CQ cq_handle->hi=%d cq_handle->lo=%d sw_comp_cons=%d hw_comp_cons=%d\n", 374a7efd777SRam Amrani cq_handle->hi, cq_handle->lo, sw_comp_cons, 375a7efd777SRam Amrani hw_comp_cons); 376a7efd777SRam Amrani 377a7efd777SRam Amrani break; 378a7efd777SRam Amrani } 379a7efd777SRam Amrani 380a7efd777SRam Amrani if (cq->sig != QEDR_CQ_MAGIC_NUMBER) { 381a7efd777SRam Amrani DP_ERR(cnq->dev, 382a7efd777SRam Amrani "Problem with cq signature, cq_handle->hi=%d ch_handle->lo=%d cq=%p\n", 383a7efd777SRam Amrani cq_handle->hi, cq_handle->lo, cq); 384a7efd777SRam Amrani break; 385a7efd777SRam Amrani } 386a7efd777SRam Amrani 387a7efd777SRam Amrani cq->arm_flags = 0; 388a7efd777SRam Amrani 389a7efd777SRam Amrani if (cq->ibcq.comp_handler) 390a7efd777SRam Amrani (*cq->ibcq.comp_handler) 391a7efd777SRam Amrani (&cq->ibcq, cq->ibcq.cq_context); 392a7efd777SRam Amrani 393ec72fce4SRam Amrani sw_comp_cons = qed_chain_get_cons_idx(&cnq->pbl); 394a7efd777SRam Amrani 395ec72fce4SRam Amrani cnq->n_comp++; 396a7efd777SRam Amrani 397ec72fce4SRam Amrani } 398ec72fce4SRam Amrani 399ec72fce4SRam Amrani qed_ops->rdma_cnq_prod_update(cnq->dev->rdma_ctx, cnq->index, 400ec72fce4SRam Amrani sw_comp_cons); 401ec72fce4SRam Amrani 402ec72fce4SRam Amrani qed_sb_ack(cnq->sb, IGU_INT_ENABLE, 1); 403ec72fce4SRam Amrani 404ec72fce4SRam Amrani return IRQ_HANDLED; 405ec72fce4SRam Amrani } 406ec72fce4SRam Amrani 407ec72fce4SRam Amrani static void qedr_sync_free_irqs(struct qedr_dev *dev) 408ec72fce4SRam Amrani { 409ec72fce4SRam Amrani u32 vector; 410ec72fce4SRam Amrani int i; 411ec72fce4SRam Amrani 412ec72fce4SRam Amrani for (i = 0; i < dev->int_info.used_cnt; i++) { 413ec72fce4SRam Amrani if (dev->int_info.msix_cnt) { 414ec72fce4SRam Amrani vector = dev->int_info.msix[i * dev->num_hwfns].vector; 415ec72fce4SRam Amrani synchronize_irq(vector); 416ec72fce4SRam Amrani free_irq(vector, &dev->cnq_array[i]); 417ec72fce4SRam Amrani } 418ec72fce4SRam Amrani } 419ec72fce4SRam Amrani 420ec72fce4SRam Amrani dev->int_info.used_cnt = 0; 421ec72fce4SRam Amrani } 422ec72fce4SRam Amrani 423ec72fce4SRam Amrani static int qedr_req_msix_irqs(struct qedr_dev *dev) 424ec72fce4SRam Amrani { 425ec72fce4SRam Amrani int i, rc = 0; 426ec72fce4SRam Amrani 427ec72fce4SRam Amrani if (dev->num_cnq > dev->int_info.msix_cnt) { 428ec72fce4SRam Amrani DP_ERR(dev, 429ec72fce4SRam Amrani "Interrupt mismatch: %d CNQ queues > %d MSI-x vectors\n", 430ec72fce4SRam Amrani dev->num_cnq, dev->int_info.msix_cnt); 431ec72fce4SRam Amrani return -EINVAL; 432ec72fce4SRam Amrani } 433ec72fce4SRam Amrani 434ec72fce4SRam Amrani for (i = 0; i < dev->num_cnq; i++) { 435ec72fce4SRam Amrani rc = request_irq(dev->int_info.msix[i * dev->num_hwfns].vector, 436ec72fce4SRam Amrani qedr_irq_handler, 0, dev->cnq_array[i].name, 437ec72fce4SRam Amrani &dev->cnq_array[i]); 438ec72fce4SRam Amrani if (rc) { 439ec72fce4SRam Amrani DP_ERR(dev, "Request cnq %d irq failed\n", i); 440ec72fce4SRam Amrani qedr_sync_free_irqs(dev); 441ec72fce4SRam Amrani } else { 442ec72fce4SRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, 443ec72fce4SRam Amrani "Requested cnq irq for %s [entry %d]. Cookie is at %p\n", 444ec72fce4SRam Amrani dev->cnq_array[i].name, i, 445ec72fce4SRam Amrani &dev->cnq_array[i]); 446ec72fce4SRam Amrani dev->int_info.used_cnt++; 447ec72fce4SRam Amrani } 448ec72fce4SRam Amrani } 449ec72fce4SRam Amrani 450ec72fce4SRam Amrani return rc; 451ec72fce4SRam Amrani } 452ec72fce4SRam Amrani 453ec72fce4SRam Amrani static int qedr_setup_irqs(struct qedr_dev *dev) 454ec72fce4SRam Amrani { 455ec72fce4SRam Amrani int rc; 456ec72fce4SRam Amrani 457ec72fce4SRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, "qedr_setup_irqs\n"); 458ec72fce4SRam Amrani 459ec72fce4SRam Amrani /* Learn Interrupt configuration */ 460ec72fce4SRam Amrani rc = dev->ops->rdma_set_rdma_int(dev->cdev, dev->num_cnq); 461ec72fce4SRam Amrani if (rc < 0) 462ec72fce4SRam Amrani return rc; 463ec72fce4SRam Amrani 464ec72fce4SRam Amrani rc = dev->ops->rdma_get_rdma_int(dev->cdev, &dev->int_info); 465ec72fce4SRam Amrani if (rc) { 466ec72fce4SRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, "get_rdma_int failed\n"); 467ec72fce4SRam Amrani return rc; 468ec72fce4SRam Amrani } 469ec72fce4SRam Amrani 470ec72fce4SRam Amrani if (dev->int_info.msix_cnt) { 471ec72fce4SRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, "rdma msix_cnt = %d\n", 472ec72fce4SRam Amrani dev->int_info.msix_cnt); 473ec72fce4SRam Amrani rc = qedr_req_msix_irqs(dev); 474ec72fce4SRam Amrani if (rc) 475ec72fce4SRam Amrani return rc; 476ec72fce4SRam Amrani } 477ec72fce4SRam Amrani 478ec72fce4SRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, "qedr_setup_irqs succeeded\n"); 479ec72fce4SRam Amrani 480ec72fce4SRam Amrani return 0; 481ec72fce4SRam Amrani } 482ec72fce4SRam Amrani 483ec72fce4SRam Amrani static int qedr_set_device_attr(struct qedr_dev *dev) 484ec72fce4SRam Amrani { 485ec72fce4SRam Amrani struct qed_rdma_device *qed_attr; 486ec72fce4SRam Amrani struct qedr_device_attr *attr; 487ec72fce4SRam Amrani u32 page_size; 488ec72fce4SRam Amrani 489ec72fce4SRam Amrani /* Part 1 - query core capabilities */ 490ec72fce4SRam Amrani qed_attr = dev->ops->rdma_query_device(dev->rdma_ctx); 491ec72fce4SRam Amrani 492ec72fce4SRam Amrani /* Part 2 - check capabilities */ 493ec72fce4SRam Amrani page_size = ~dev->attr.page_size_caps + 1; 494ec72fce4SRam Amrani if (page_size > PAGE_SIZE) { 495ec72fce4SRam Amrani DP_ERR(dev, 496ec72fce4SRam Amrani "Kernel PAGE_SIZE is %ld which is smaller than minimum page size (%d) required by qedr\n", 497ec72fce4SRam Amrani PAGE_SIZE, page_size); 498ec72fce4SRam Amrani return -ENODEV; 499ec72fce4SRam Amrani } 500ec72fce4SRam Amrani 501ec72fce4SRam Amrani /* Part 3 - copy and update capabilities */ 502ec72fce4SRam Amrani attr = &dev->attr; 503ec72fce4SRam Amrani attr->vendor_id = qed_attr->vendor_id; 504ec72fce4SRam Amrani attr->vendor_part_id = qed_attr->vendor_part_id; 505ec72fce4SRam Amrani attr->hw_ver = qed_attr->hw_ver; 506ec72fce4SRam Amrani attr->fw_ver = qed_attr->fw_ver; 507ec72fce4SRam Amrani attr->node_guid = qed_attr->node_guid; 508ec72fce4SRam Amrani attr->sys_image_guid = qed_attr->sys_image_guid; 509ec72fce4SRam Amrani attr->max_cnq = qed_attr->max_cnq; 510ec72fce4SRam Amrani attr->max_sge = qed_attr->max_sge; 511ec72fce4SRam Amrani attr->max_inline = qed_attr->max_inline; 512ec72fce4SRam Amrani attr->max_sqe = min_t(u32, qed_attr->max_wqe, QEDR_MAX_SQE); 513ec72fce4SRam Amrani attr->max_rqe = min_t(u32, qed_attr->max_wqe, QEDR_MAX_RQE); 514ec72fce4SRam Amrani attr->max_qp_resp_rd_atomic_resc = qed_attr->max_qp_resp_rd_atomic_resc; 515ec72fce4SRam Amrani attr->max_qp_req_rd_atomic_resc = qed_attr->max_qp_req_rd_atomic_resc; 516ec72fce4SRam Amrani attr->max_dev_resp_rd_atomic_resc = 517ec72fce4SRam Amrani qed_attr->max_dev_resp_rd_atomic_resc; 518ec72fce4SRam Amrani attr->max_cq = qed_attr->max_cq; 519ec72fce4SRam Amrani attr->max_qp = qed_attr->max_qp; 520ec72fce4SRam Amrani attr->max_mr = qed_attr->max_mr; 521ec72fce4SRam Amrani attr->max_mr_size = qed_attr->max_mr_size; 522ec72fce4SRam Amrani attr->max_cqe = min_t(u64, qed_attr->max_cqe, QEDR_MAX_CQES); 523ec72fce4SRam Amrani attr->max_mw = qed_attr->max_mw; 524ec72fce4SRam Amrani attr->max_fmr = qed_attr->max_fmr; 525ec72fce4SRam Amrani attr->max_mr_mw_fmr_pbl = qed_attr->max_mr_mw_fmr_pbl; 526ec72fce4SRam Amrani attr->max_mr_mw_fmr_size = qed_attr->max_mr_mw_fmr_size; 527ec72fce4SRam Amrani attr->max_pd = qed_attr->max_pd; 528ec72fce4SRam Amrani attr->max_ah = qed_attr->max_ah; 529ec72fce4SRam Amrani attr->max_pkey = qed_attr->max_pkey; 530ec72fce4SRam Amrani attr->max_srq = qed_attr->max_srq; 531ec72fce4SRam Amrani attr->max_srq_wr = qed_attr->max_srq_wr; 532ec72fce4SRam Amrani attr->dev_caps = qed_attr->dev_caps; 533ec72fce4SRam Amrani attr->page_size_caps = qed_attr->page_size_caps; 534ec72fce4SRam Amrani attr->dev_ack_delay = qed_attr->dev_ack_delay; 535ec72fce4SRam Amrani attr->reserved_lkey = qed_attr->reserved_lkey; 536ec72fce4SRam Amrani attr->bad_pkey_counter = qed_attr->bad_pkey_counter; 537ec72fce4SRam Amrani attr->max_stats_queues = qed_attr->max_stats_queues; 538ec72fce4SRam Amrani 539ec72fce4SRam Amrani return 0; 540ec72fce4SRam Amrani } 541ec72fce4SRam Amrani 542ec72fce4SRam Amrani static int qedr_init_hw(struct qedr_dev *dev) 543ec72fce4SRam Amrani { 544ec72fce4SRam Amrani struct qed_rdma_add_user_out_params out_params; 545ec72fce4SRam Amrani struct qed_rdma_start_in_params *in_params; 546ec72fce4SRam Amrani struct qed_rdma_cnq_params *cur_pbl; 547ec72fce4SRam Amrani struct qed_rdma_events events; 548ec72fce4SRam Amrani dma_addr_t p_phys_table; 549ec72fce4SRam Amrani u32 page_cnt; 550ec72fce4SRam Amrani int rc = 0; 551ec72fce4SRam Amrani int i; 552ec72fce4SRam Amrani 553ec72fce4SRam Amrani in_params = kzalloc(sizeof(*in_params), GFP_KERNEL); 554ec72fce4SRam Amrani if (!in_params) { 555ec72fce4SRam Amrani rc = -ENOMEM; 556ec72fce4SRam Amrani goto out; 557ec72fce4SRam Amrani } 558ec72fce4SRam Amrani 559ec72fce4SRam Amrani in_params->desired_cnq = dev->num_cnq; 560ec72fce4SRam Amrani for (i = 0; i < dev->num_cnq; i++) { 561ec72fce4SRam Amrani cur_pbl = &in_params->cnq_pbl_list[i]; 562ec72fce4SRam Amrani 563ec72fce4SRam Amrani page_cnt = qed_chain_get_page_cnt(&dev->cnq_array[i].pbl); 564ec72fce4SRam Amrani cur_pbl->num_pbl_pages = page_cnt; 565ec72fce4SRam Amrani 566ec72fce4SRam Amrani p_phys_table = qed_chain_get_pbl_phys(&dev->cnq_array[i].pbl); 567ec72fce4SRam Amrani cur_pbl->pbl_ptr = (u64)p_phys_table; 568ec72fce4SRam Amrani } 569ec72fce4SRam Amrani 570ec72fce4SRam Amrani events.context = dev; 571ec72fce4SRam Amrani 572ec72fce4SRam Amrani in_params->events = &events; 573ec72fce4SRam Amrani in_params->cq_mode = QED_RDMA_CQ_MODE_32_BITS; 574ec72fce4SRam Amrani in_params->max_mtu = dev->ndev->mtu; 575ec72fce4SRam Amrani ether_addr_copy(&in_params->mac_addr[0], dev->ndev->dev_addr); 576ec72fce4SRam Amrani 577ec72fce4SRam Amrani rc = dev->ops->rdma_init(dev->cdev, in_params); 578ec72fce4SRam Amrani if (rc) 579ec72fce4SRam Amrani goto out; 580ec72fce4SRam Amrani 581ec72fce4SRam Amrani rc = dev->ops->rdma_add_user(dev->rdma_ctx, &out_params); 582ec72fce4SRam Amrani if (rc) 583ec72fce4SRam Amrani goto out; 584ec72fce4SRam Amrani 585ec72fce4SRam Amrani dev->db_addr = (void *)(uintptr_t)out_params.dpi_addr; 586ec72fce4SRam Amrani dev->db_phys_addr = out_params.dpi_phys_addr; 587ec72fce4SRam Amrani dev->db_size = out_params.dpi_size; 588ec72fce4SRam Amrani dev->dpi = out_params.dpi; 589ec72fce4SRam Amrani 590ec72fce4SRam Amrani rc = qedr_set_device_attr(dev); 591ec72fce4SRam Amrani out: 592ec72fce4SRam Amrani kfree(in_params); 593ec72fce4SRam Amrani if (rc) 594ec72fce4SRam Amrani DP_ERR(dev, "Init HW Failed rc = %d\n", rc); 595ec72fce4SRam Amrani 596ec72fce4SRam Amrani return rc; 597ec72fce4SRam Amrani } 598ec72fce4SRam Amrani 599ec72fce4SRam Amrani void qedr_stop_hw(struct qedr_dev *dev) 600ec72fce4SRam Amrani { 601ec72fce4SRam Amrani dev->ops->rdma_remove_user(dev->rdma_ctx, dev->dpi); 602ec72fce4SRam Amrani dev->ops->rdma_stop(dev->rdma_ctx); 603ec72fce4SRam Amrani } 604ec72fce4SRam Amrani 6052e0cbc4dSRam Amrani static struct qedr_dev *qedr_add(struct qed_dev *cdev, struct pci_dev *pdev, 6062e0cbc4dSRam Amrani struct net_device *ndev) 6072e0cbc4dSRam Amrani { 608ec72fce4SRam Amrani struct qed_dev_rdma_info dev_info; 6092e0cbc4dSRam Amrani struct qedr_dev *dev; 6102e0cbc4dSRam Amrani int rc = 0, i; 6112e0cbc4dSRam Amrani 6122e0cbc4dSRam Amrani dev = (struct qedr_dev *)ib_alloc_device(sizeof(*dev)); 6132e0cbc4dSRam Amrani if (!dev) { 6142e0cbc4dSRam Amrani pr_err("Unable to allocate ib device\n"); 6152e0cbc4dSRam Amrani return NULL; 6162e0cbc4dSRam Amrani } 6172e0cbc4dSRam Amrani 6182e0cbc4dSRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, "qedr add device called\n"); 6192e0cbc4dSRam Amrani 6202e0cbc4dSRam Amrani dev->pdev = pdev; 6212e0cbc4dSRam Amrani dev->ndev = ndev; 6222e0cbc4dSRam Amrani dev->cdev = cdev; 6232e0cbc4dSRam Amrani 624ec72fce4SRam Amrani qed_ops = qed_get_rdma_ops(); 625ec72fce4SRam Amrani if (!qed_ops) { 626ec72fce4SRam Amrani DP_ERR(dev, "Failed to get qed roce operations\n"); 627ec72fce4SRam Amrani goto init_err; 628ec72fce4SRam Amrani } 629ec72fce4SRam Amrani 630ec72fce4SRam Amrani dev->ops = qed_ops; 631ec72fce4SRam Amrani rc = qed_ops->fill_dev_info(cdev, &dev_info); 632ec72fce4SRam Amrani if (rc) 633ec72fce4SRam Amrani goto init_err; 634ec72fce4SRam Amrani 635ec72fce4SRam Amrani dev->num_hwfns = dev_info.common.num_hwfns; 636ec72fce4SRam Amrani dev->rdma_ctx = dev->ops->rdma_get_rdma_ctx(cdev); 637ec72fce4SRam Amrani 638ec72fce4SRam Amrani dev->num_cnq = dev->ops->rdma_get_min_cnq_msix(cdev); 639ec72fce4SRam Amrani if (!dev->num_cnq) { 640ec72fce4SRam Amrani DP_ERR(dev, "not enough CNQ resources.\n"); 641ec72fce4SRam Amrani goto init_err; 642ec72fce4SRam Amrani } 643ec72fce4SRam Amrani 644*cecbcddfSRam Amrani dev->wq_multiplier = QEDR_WQ_MULTIPLIER_DFT; 645*cecbcddfSRam Amrani 6462e0cbc4dSRam Amrani qedr_pci_set_atomic(dev, pdev); 6472e0cbc4dSRam Amrani 648ec72fce4SRam Amrani rc = qedr_alloc_resources(dev); 649ec72fce4SRam Amrani if (rc) 650ec72fce4SRam Amrani goto init_err; 651ec72fce4SRam Amrani 652ec72fce4SRam Amrani rc = qedr_init_hw(dev); 653ec72fce4SRam Amrani if (rc) 654ec72fce4SRam Amrani goto alloc_err; 655ec72fce4SRam Amrani 656ec72fce4SRam Amrani rc = qedr_setup_irqs(dev); 657ec72fce4SRam Amrani if (rc) 658ec72fce4SRam Amrani goto irq_err; 659ec72fce4SRam Amrani 6602e0cbc4dSRam Amrani rc = qedr_register_device(dev); 6612e0cbc4dSRam Amrani if (rc) { 6622e0cbc4dSRam Amrani DP_ERR(dev, "Unable to allocate register device\n"); 663ec72fce4SRam Amrani goto reg_err; 6642e0cbc4dSRam Amrani } 6652e0cbc4dSRam Amrani 6662e0cbc4dSRam Amrani for (i = 0; i < ARRAY_SIZE(qedr_attributes); i++) 6672e0cbc4dSRam Amrani if (device_create_file(&dev->ibdev.dev, qedr_attributes[i])) 668ec72fce4SRam Amrani goto reg_err; 6692e0cbc4dSRam Amrani 6702e0cbc4dSRam Amrani DP_DEBUG(dev, QEDR_MSG_INIT, "qedr driver loaded successfully\n"); 6712e0cbc4dSRam Amrani return dev; 6722e0cbc4dSRam Amrani 673ec72fce4SRam Amrani reg_err: 674ec72fce4SRam Amrani qedr_sync_free_irqs(dev); 675ec72fce4SRam Amrani irq_err: 676ec72fce4SRam Amrani qedr_stop_hw(dev); 677ec72fce4SRam Amrani alloc_err: 678ec72fce4SRam Amrani qedr_free_resources(dev); 6792e0cbc4dSRam Amrani init_err: 6802e0cbc4dSRam Amrani ib_dealloc_device(&dev->ibdev); 6812e0cbc4dSRam Amrani DP_ERR(dev, "qedr driver load failed rc=%d\n", rc); 6822e0cbc4dSRam Amrani 6832e0cbc4dSRam Amrani return NULL; 6842e0cbc4dSRam Amrani } 6852e0cbc4dSRam Amrani 6862e0cbc4dSRam Amrani static void qedr_remove(struct qedr_dev *dev) 6872e0cbc4dSRam Amrani { 6882e0cbc4dSRam Amrani /* First unregister with stack to stop all the active traffic 6892e0cbc4dSRam Amrani * of the registered clients. 6902e0cbc4dSRam Amrani */ 6912e0cbc4dSRam Amrani qedr_remove_sysfiles(dev); 6922e0cbc4dSRam Amrani 693ec72fce4SRam Amrani qedr_stop_hw(dev); 694ec72fce4SRam Amrani qedr_sync_free_irqs(dev); 695ec72fce4SRam Amrani qedr_free_resources(dev); 6962e0cbc4dSRam Amrani ib_dealloc_device(&dev->ibdev); 6972e0cbc4dSRam Amrani } 6982e0cbc4dSRam Amrani 6992e0cbc4dSRam Amrani static int qedr_close(struct qedr_dev *dev) 7002e0cbc4dSRam Amrani { 7012e0cbc4dSRam Amrani qedr_ib_dispatch_event(dev, 1, IB_EVENT_PORT_ERR); 7022e0cbc4dSRam Amrani 7032e0cbc4dSRam Amrani return 0; 7042e0cbc4dSRam Amrani } 7052e0cbc4dSRam Amrani 7062e0cbc4dSRam Amrani static void qedr_shutdown(struct qedr_dev *dev) 7072e0cbc4dSRam Amrani { 7082e0cbc4dSRam Amrani qedr_close(dev); 7092e0cbc4dSRam Amrani qedr_remove(dev); 7102e0cbc4dSRam Amrani } 7112e0cbc4dSRam Amrani 7122e0cbc4dSRam Amrani /* event handling via NIC driver ensures that all the NIC specific 7132e0cbc4dSRam Amrani * initialization done before RoCE driver notifies 7142e0cbc4dSRam Amrani * event to stack. 7152e0cbc4dSRam Amrani */ 7162e0cbc4dSRam Amrani static void qedr_notify(struct qedr_dev *dev, enum qede_roce_event event) 7172e0cbc4dSRam Amrani { 7182e0cbc4dSRam Amrani switch (event) { 7192e0cbc4dSRam Amrani case QEDE_UP: 7202e0cbc4dSRam Amrani qedr_ib_dispatch_event(dev, 1, IB_EVENT_PORT_ACTIVE); 7212e0cbc4dSRam Amrani break; 7222e0cbc4dSRam Amrani case QEDE_DOWN: 7232e0cbc4dSRam Amrani qedr_close(dev); 7242e0cbc4dSRam Amrani break; 7252e0cbc4dSRam Amrani case QEDE_CLOSE: 7262e0cbc4dSRam Amrani qedr_shutdown(dev); 7272e0cbc4dSRam Amrani break; 7282e0cbc4dSRam Amrani case QEDE_CHANGE_ADDR: 7292e0cbc4dSRam Amrani qedr_ib_dispatch_event(dev, 1, IB_EVENT_GID_CHANGE); 7302e0cbc4dSRam Amrani break; 7312e0cbc4dSRam Amrani default: 7322e0cbc4dSRam Amrani pr_err("Event not supported\n"); 7332e0cbc4dSRam Amrani } 7342e0cbc4dSRam Amrani } 7352e0cbc4dSRam Amrani 7362e0cbc4dSRam Amrani static struct qedr_driver qedr_drv = { 7372e0cbc4dSRam Amrani .name = "qedr_driver", 7382e0cbc4dSRam Amrani .add = qedr_add, 7392e0cbc4dSRam Amrani .remove = qedr_remove, 7402e0cbc4dSRam Amrani .notify = qedr_notify, 7412e0cbc4dSRam Amrani }; 7422e0cbc4dSRam Amrani 7432e0cbc4dSRam Amrani static int __init qedr_init_module(void) 7442e0cbc4dSRam Amrani { 7452e0cbc4dSRam Amrani return qede_roce_register_driver(&qedr_drv); 7462e0cbc4dSRam Amrani } 7472e0cbc4dSRam Amrani 7482e0cbc4dSRam Amrani static void __exit qedr_exit_module(void) 7492e0cbc4dSRam Amrani { 7502e0cbc4dSRam Amrani qede_roce_unregister_driver(&qedr_drv); 7512e0cbc4dSRam Amrani } 7522e0cbc4dSRam Amrani 7532e0cbc4dSRam Amrani module_init(qedr_init_module); 7542e0cbc4dSRam Amrani module_exit(qedr_exit_module); 755