Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved. |
| 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * 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 OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/moduleparam.h> |
| 34 | #include <linux/device.h> |
| 35 | #include <linux/netdevice.h> |
| 36 | #include <linux/etherdevice.h> |
| 37 | #include <linux/delay.h> |
| 38 | #include <linux/errno.h> |
| 39 | #include <linux/list.h> |
| 40 | #include <linux/spinlock.h> |
| 41 | #include <linux/ethtool.h> |
| 42 | #include <linux/rtnetlink.h> |
| 43 | #include <linux/inetdevice.h> |
| 44 | #include <linux/io.h> |
| 45 | |
| 46 | #include <asm/irq.h> |
| 47 | #include <asm/byteorder.h> |
| 48 | |
| 49 | #include <rdma/iw_cm.h> |
| 50 | #include <rdma/ib_verbs.h> |
| 51 | #include <rdma/ib_smi.h> |
| 52 | #include <rdma/ib_umem.h> |
| 53 | #include <rdma/ib_user_verbs.h> |
| 54 | |
| 55 | #include "iw_cxgb4.h" |
| 56 | |
Steve Wise | 40dbf6e | 2010-09-17 15:40:15 -0500 | [diff] [blame] | 57 | static int fastreg_support = 1; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 58 | module_param(fastreg_support, int, 0644); |
Steve Wise | 40dbf6e | 2010-09-17 15:40:15 -0500 | [diff] [blame] | 59 | MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)"); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 60 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 61 | static struct ib_ah *c4iw_ah_create(struct ib_pd *pd, |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 62 | struct rdma_ah_attr *ah_attr, |
Moni Shoua | 477864c | 2016-11-23 08:23:24 +0200 | [diff] [blame] | 63 | struct ib_udata *udata) |
| 64 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 65 | { |
| 66 | return ERR_PTR(-ENOSYS); |
| 67 | } |
| 68 | |
| 69 | static int c4iw_ah_destroy(struct ib_ah *ah) |
| 70 | { |
| 71 | return -ENOSYS; |
| 72 | } |
| 73 | |
| 74 | static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 75 | { |
| 76 | return -ENOSYS; |
| 77 | } |
| 78 | |
| 79 | static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 80 | { |
| 81 | return -ENOSYS; |
| 82 | } |
| 83 | |
| 84 | static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags, |
Ira Weiny | a97e2d8 | 2015-05-31 17:15:30 -0400 | [diff] [blame] | 85 | u8 port_num, const struct ib_wc *in_wc, |
| 86 | const struct ib_grh *in_grh, |
Ira Weiny | 4cd7c94 | 2015-06-06 14:38:31 -0400 | [diff] [blame] | 87 | const struct ib_mad_hdr *in_mad, |
| 88 | size_t in_mad_size, |
| 89 | struct ib_mad_hdr *out_mad, |
| 90 | size_t *out_mad_size, |
| 91 | u16 *out_mad_pkey_index) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 92 | { |
| 93 | return -ENOSYS; |
| 94 | } |
| 95 | |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 96 | void _c4iw_free_ucontext(struct kref *kref) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 97 | { |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 98 | struct c4iw_ucontext *ucontext; |
| 99 | struct c4iw_dev *rhp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 100 | struct c4iw_mm_entry *mm, *tmp; |
| 101 | |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 102 | ucontext = container_of(kref, struct c4iw_ucontext, kref); |
| 103 | rhp = to_c4iw_dev(ucontext->ibucontext.device); |
| 104 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 105 | pr_debug("ucontext %p\n", ucontext); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 106 | list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry) |
| 107 | kfree(mm); |
| 108 | c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx); |
| 109 | kfree(ucontext); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static int c4iw_dealloc_ucontext(struct ib_ucontext *context) |
| 113 | { |
| 114 | struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context); |
| 115 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 116 | pr_debug("context %p\n", context); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 117 | c4iw_put_ucontext(ucontext); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev, |
| 122 | struct ib_udata *udata) |
| 123 | { |
| 124 | struct c4iw_ucontext *context; |
| 125 | struct c4iw_dev *rhp = to_c4iw_dev(ibdev); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 126 | struct c4iw_alloc_ucontext_resp uresp; |
| 127 | int ret = 0; |
| 128 | struct c4iw_mm_entry *mm = NULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 129 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 130 | pr_debug("ibdev %p\n", ibdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 131 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 132 | if (!context) { |
| 133 | ret = -ENOMEM; |
| 134 | goto err; |
| 135 | } |
| 136 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 137 | c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx); |
| 138 | INIT_LIST_HEAD(&context->mmaps); |
| 139 | spin_lock_init(&context->mmap_lock); |
Steve Wise | c12a67f | 2016-12-22 07:40:36 -0800 | [diff] [blame] | 140 | kref_init(&context->kref); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 141 | |
Yann Droneaud | b7dfa88 | 2014-05-05 19:35:26 +0200 | [diff] [blame] | 142 | if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) { |
Joe Perches | 700456b | 2017-02-09 14:23:50 -0800 | [diff] [blame] | 143 | pr_err_once("Warning - downlevel libcxgb4 (non-fatal), device status page disabled\n"); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 144 | rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED; |
| 145 | } else { |
| 146 | mm = kmalloc(sizeof(*mm), GFP_KERNEL); |
Yann Droneaud | bfd2793 | 2014-03-28 14:55:21 -0400 | [diff] [blame] | 147 | if (!mm) { |
| 148 | ret = -ENOMEM; |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 149 | goto err_free; |
Yann Droneaud | bfd2793 | 2014-03-28 14:55:21 -0400 | [diff] [blame] | 150 | } |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 151 | |
| 152 | uresp.status_page_size = PAGE_SIZE; |
| 153 | |
| 154 | spin_lock(&context->mmap_lock); |
| 155 | uresp.status_page_key = context->key; |
| 156 | context->key += PAGE_SIZE; |
| 157 | spin_unlock(&context->mmap_lock); |
| 158 | |
Yann Droneaud | b7dfa88 | 2014-05-05 19:35:26 +0200 | [diff] [blame] | 159 | ret = ib_copy_to_udata(udata, &uresp, |
| 160 | sizeof(uresp) - sizeof(uresp.reserved)); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 161 | if (ret) |
| 162 | goto err_mm; |
| 163 | |
| 164 | mm->key = uresp.status_page_key; |
| 165 | mm->addr = virt_to_phys(rhp->rdev.status_page); |
| 166 | mm->len = PAGE_SIZE; |
| 167 | insert_mmap(context, mm); |
| 168 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 169 | return &context->ibucontext; |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 170 | err_mm: |
| 171 | kfree(mm); |
| 172 | err_free: |
| 173 | kfree(context); |
| 174 | err: |
| 175 | return ERR_PTR(ret); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 179 | { |
| 180 | int len = vma->vm_end - vma->vm_start; |
| 181 | u32 key = vma->vm_pgoff << PAGE_SHIFT; |
| 182 | struct c4iw_rdev *rdev; |
| 183 | int ret = 0; |
| 184 | struct c4iw_mm_entry *mm; |
| 185 | struct c4iw_ucontext *ucontext; |
| 186 | u64 addr; |
| 187 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 188 | pr_debug("pgoff 0x%lx key 0x%x len %d\n", vma->vm_pgoff, |
Joe Perches | a9a4288 | 2017-02-09 14:23:51 -0800 | [diff] [blame] | 189 | key, len); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 190 | |
| 191 | if (vma->vm_start & (PAGE_SIZE-1)) |
| 192 | return -EINVAL; |
| 193 | |
| 194 | rdev = &(to_c4iw_dev(context->device)->rdev); |
| 195 | ucontext = to_c4iw_ucontext(context); |
| 196 | |
| 197 | mm = remove_mmap(ucontext, key, len); |
| 198 | if (!mm) |
| 199 | return -EINVAL; |
| 200 | addr = mm->addr; |
| 201 | kfree(mm); |
| 202 | |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 203 | if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) && |
| 204 | (addr < (pci_resource_start(rdev->lldi.pdev, 0) + |
| 205 | pci_resource_len(rdev->lldi.pdev, 0)))) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 206 | |
| 207 | /* |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 208 | * MA_SYNC register... |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 209 | */ |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 210 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 211 | ret = io_remap_pfn_range(vma, vma->vm_start, |
| 212 | addr >> PAGE_SHIFT, |
| 213 | len, vma->vm_page_prot); |
| 214 | } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) && |
| 215 | (addr < (pci_resource_start(rdev->lldi.pdev, 2) + |
| 216 | pci_resource_len(rdev->lldi.pdev, 2)))) { |
| 217 | |
| 218 | /* |
| 219 | * Map user DB or OCQP memory... |
| 220 | */ |
| 221 | if (addr >= rdev->oc_mw_pa) |
| 222 | vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot); |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 223 | else { |
Hariprasad S | 963cab5 | 2015-09-23 17:19:27 +0530 | [diff] [blame] | 224 | if (!is_t4(rdev->lldi.adapter_type)) |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 225 | vma->vm_page_prot = |
| 226 | t4_pgprot_wc(vma->vm_page_prot); |
| 227 | else |
| 228 | vma->vm_page_prot = |
| 229 | pgprot_noncached(vma->vm_page_prot); |
| 230 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 231 | ret = io_remap_pfn_range(vma, vma->vm_start, |
| 232 | addr >> PAGE_SHIFT, |
| 233 | len, vma->vm_page_prot); |
| 234 | } else { |
| 235 | |
| 236 | /* |
| 237 | * Map WQ or CQ contig dma memory... |
| 238 | */ |
| 239 | ret = remap_pfn_range(vma, vma->vm_start, |
| 240 | addr >> PAGE_SHIFT, |
| 241 | len, vma->vm_page_prot); |
| 242 | } |
| 243 | |
| 244 | return ret; |
| 245 | } |
| 246 | |
| 247 | static int c4iw_deallocate_pd(struct ib_pd *pd) |
| 248 | { |
| 249 | struct c4iw_dev *rhp; |
| 250 | struct c4iw_pd *php; |
| 251 | |
| 252 | php = to_c4iw_pd(pd); |
| 253 | rhp = php->rhp; |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 254 | pr_debug("ibpd %p pdid 0x%x\n", pd, php->pdid); |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 255 | c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid); |
Vipul Pandya | 8d81ef3 | 2012-05-18 15:29:27 +0530 | [diff] [blame] | 256 | mutex_lock(&rhp->rdev.stats.lock); |
| 257 | rhp->rdev.stats.pd.cur--; |
| 258 | mutex_unlock(&rhp->rdev.stats.lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 259 | kfree(php); |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev, |
| 264 | struct ib_ucontext *context, |
| 265 | struct ib_udata *udata) |
| 266 | { |
| 267 | struct c4iw_pd *php; |
| 268 | u32 pdid; |
| 269 | struct c4iw_dev *rhp; |
| 270 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 271 | pr_debug("ibdev %p\n", ibdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 272 | rhp = (struct c4iw_dev *) ibdev; |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 273 | pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 274 | if (!pdid) |
| 275 | return ERR_PTR(-EINVAL); |
| 276 | php = kzalloc(sizeof(*php), GFP_KERNEL); |
| 277 | if (!php) { |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 278 | c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 279 | return ERR_PTR(-ENOMEM); |
| 280 | } |
| 281 | php->pdid = pdid; |
| 282 | php->rhp = rhp; |
| 283 | if (context) { |
Jason Gunthorpe | 7f86260 | 2018-03-14 16:01:50 -0600 | [diff] [blame] | 284 | struct c4iw_alloc_pd_resp uresp = {.pdid = php->pdid}; |
| 285 | |
| 286 | if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 287 | c4iw_deallocate_pd(&php->ibpd); |
| 288 | return ERR_PTR(-EFAULT); |
| 289 | } |
| 290 | } |
Vipul Pandya | 8d81ef3 | 2012-05-18 15:29:27 +0530 | [diff] [blame] | 291 | mutex_lock(&rhp->rdev.stats.lock); |
| 292 | rhp->rdev.stats.pd.cur++; |
| 293 | if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max) |
| 294 | rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur; |
| 295 | mutex_unlock(&rhp->rdev.stats.lock); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 296 | pr_debug("pdid 0x%0x ptr 0x%p\n", pdid, php); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 297 | return &php->ibpd; |
| 298 | } |
| 299 | |
| 300 | static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 301 | u16 *pkey) |
| 302 | { |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 303 | pr_debug("ibdev %p\n", ibdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 304 | *pkey = 0; |
| 305 | return 0; |
| 306 | } |
| 307 | |
| 308 | static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 309 | union ib_gid *gid) |
| 310 | { |
| 311 | struct c4iw_dev *dev; |
| 312 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 313 | pr_debug("ibdev %p, port %d, index %d, gid %p\n", |
| 314 | ibdev, port, index, gid); |
Steve Wise | ba97b74 | 2017-11-02 14:11:03 -0700 | [diff] [blame] | 315 | if (!port) |
| 316 | return -EINVAL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 317 | dev = to_c4iw_dev(ibdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 318 | memset(&(gid->raw[0]), 0, sizeof(gid->raw)); |
| 319 | memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6); |
| 320 | return 0; |
| 321 | } |
| 322 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 323 | static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props, |
| 324 | struct ib_udata *uhw) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 325 | { |
| 326 | |
| 327 | struct c4iw_dev *dev; |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 328 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 329 | pr_debug("ibdev %p\n", ibdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 330 | |
Matan Barak | 2528e33 | 2015-06-11 16:35:25 +0300 | [diff] [blame] | 331 | if (uhw->inlen || uhw->outlen) |
| 332 | return -EINVAL; |
| 333 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 334 | dev = to_c4iw_dev(ibdev); |
| 335 | memset(props, 0, sizeof *props); |
| 336 | memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6); |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 337 | props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 338 | props->fw_ver = dev->rdev.lldi.fw_vers; |
| 339 | props->device_cap_flags = dev->device_cap_flags; |
| 340 | props->page_size_cap = T4_PAGESIZE_MASK; |
| 341 | props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor; |
| 342 | props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device; |
| 343 | props->max_mr_size = T4_MAX_MR_SIZE; |
Hariprasad Shenai | 66eb19a | 2014-07-21 20:55:15 +0530 | [diff] [blame] | 344 | props->max_qp = dev->rdev.lldi.vr->qp.size / 2; |
Hariprasad Shenai | 04e10e2 | 2014-07-14 21:34:51 +0530 | [diff] [blame] | 345 | props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 346 | props->max_sge = T4_MAX_RECV_SGE; |
| 347 | props->max_sge_rd = 1; |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 348 | props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter; |
| 349 | props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp, |
| 350 | c4iw_max_read_depth); |
| 351 | props->max_qp_init_rd_atom = props->max_qp_rd_atom; |
Hariprasad Shenai | 66eb19a | 2014-07-21 20:55:15 +0530 | [diff] [blame] | 352 | props->max_cq = dev->rdev.lldi.vr->qp.size; |
Hariprasad Shenai | 04e10e2 | 2014-07-14 21:34:51 +0530 | [diff] [blame] | 353 | props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 354 | props->max_mr = c4iw_num_stags(&dev->rdev); |
| 355 | props->max_pd = T4_MAX_NUM_PD; |
| 356 | props->local_ca_ack_delay = 0; |
Hariprasad S | ee30f7d | 2016-02-12 16:10:35 +0530 | [diff] [blame] | 357 | props->max_fast_reg_page_list_len = |
| 358 | t4_max_fr_depth(dev->rdev.lldi.ulptx_memwrite_dsgl && use_dsgl); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | static int c4iw_query_port(struct ib_device *ibdev, u8 port, |
| 364 | struct ib_port_attr *props) |
| 365 | { |
| 366 | struct c4iw_dev *dev; |
| 367 | struct net_device *netdev; |
| 368 | struct in_device *inetdev; |
| 369 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 370 | pr_debug("ibdev %p\n", ibdev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 371 | |
| 372 | dev = to_c4iw_dev(ibdev); |
| 373 | netdev = dev->rdev.lldi.ports[port-1]; |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 374 | /* props being zeroed by the caller, avoid zeroing it here */ |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 375 | props->max_mtu = IB_MTU_4096; |
Amrani, Ram | d3f4aad | 2016-12-26 08:40:57 +0200 | [diff] [blame] | 376 | props->active_mtu = ib_mtu_int_to_enum(netdev->mtu); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 377 | |
| 378 | if (!netif_carrier_ok(netdev)) |
| 379 | props->state = IB_PORT_DOWN; |
| 380 | else { |
| 381 | inetdev = in_dev_get(netdev); |
| 382 | if (inetdev) { |
| 383 | if (inetdev->ifa_list) |
| 384 | props->state = IB_PORT_ACTIVE; |
| 385 | else |
| 386 | props->state = IB_PORT_INIT; |
| 387 | in_dev_put(inetdev); |
| 388 | } else |
| 389 | props->state = IB_PORT_INIT; |
| 390 | } |
| 391 | |
| 392 | props->port_cap_flags = |
| 393 | IB_PORT_CM_SUP | |
| 394 | IB_PORT_SNMP_TUNNEL_SUP | |
| 395 | IB_PORT_REINIT_SUP | |
| 396 | IB_PORT_DEVICE_MGMT_SUP | |
| 397 | IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP; |
| 398 | props->gid_tbl_len = 1; |
| 399 | props->pkey_tbl_len = 1; |
| 400 | props->active_width = 2; |
Or Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 401 | props->active_speed = IB_SPEED_DDR; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 402 | props->max_msg_sz = -1; |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static ssize_t show_rev(struct device *dev, struct device_attribute *attr, |
| 408 | char *buf) |
| 409 | { |
| 410 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 411 | ibdev.dev); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 412 | pr_debug("dev 0x%p\n", dev); |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 413 | return sprintf(buf, "%d\n", |
| 414 | CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 417 | static ssize_t show_hca(struct device *dev, struct device_attribute *attr, |
| 418 | char *buf) |
| 419 | { |
| 420 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 421 | ibdev.dev); |
| 422 | struct ethtool_drvinfo info; |
| 423 | struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0]; |
| 424 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 425 | pr_debug("dev 0x%p\n", dev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 426 | lldev->ethtool_ops->get_drvinfo(lldev, &info); |
| 427 | return sprintf(buf, "%s\n", info.driver); |
| 428 | } |
| 429 | |
| 430 | static ssize_t show_board(struct device *dev, struct device_attribute *attr, |
| 431 | char *buf) |
| 432 | { |
| 433 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 434 | ibdev.dev); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 435 | pr_debug("dev 0x%p\n", dev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 436 | return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor, |
| 437 | c4iw_dev->rdev.lldi.pdev->device); |
| 438 | } |
| 439 | |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 440 | enum counters { |
| 441 | IP4INSEGS, |
| 442 | IP4OUTSEGS, |
| 443 | IP4RETRANSSEGS, |
| 444 | IP4OUTRSTS, |
| 445 | IP6INSEGS, |
| 446 | IP6OUTSEGS, |
| 447 | IP6RETRANSSEGS, |
| 448 | IP6OUTRSTS, |
| 449 | NR_COUNTERS |
| 450 | }; |
| 451 | |
| 452 | static const char * const names[] = { |
| 453 | [IP4INSEGS] = "ip4InSegs", |
| 454 | [IP4OUTSEGS] = "ip4OutSegs", |
| 455 | [IP4RETRANSSEGS] = "ip4RetransSegs", |
| 456 | [IP4OUTRSTS] = "ip4OutRsts", |
| 457 | [IP6INSEGS] = "ip6InSegs", |
| 458 | [IP6OUTSEGS] = "ip6OutSegs", |
| 459 | [IP6RETRANSSEGS] = "ip6RetransSegs", |
| 460 | [IP6OUTRSTS] = "ip6OutRsts" |
| 461 | }; |
| 462 | |
| 463 | static struct rdma_hw_stats *c4iw_alloc_stats(struct ib_device *ibdev, |
| 464 | u8 port_num) |
| 465 | { |
| 466 | BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS); |
| 467 | |
| 468 | if (port_num != 0) |
| 469 | return NULL; |
| 470 | |
| 471 | return rdma_alloc_hw_stats_struct(names, NR_COUNTERS, |
| 472 | RDMA_HW_STATS_DEFAULT_LIFESPAN); |
| 473 | } |
| 474 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 475 | static int c4iw_get_mib(struct ib_device *ibdev, |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 476 | struct rdma_hw_stats *stats, |
| 477 | u8 port, int index) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 478 | { |
Steve Wise | de5dd81 | 2010-10-18 15:16:40 +0000 | [diff] [blame] | 479 | struct tp_tcp_stats v4, v6; |
| 480 | struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev); |
| 481 | |
| 482 | cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6); |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 483 | stats->value[IP4INSEGS] = v4.tcp_in_segs; |
| 484 | stats->value[IP4OUTSEGS] = v4.tcp_out_segs; |
| 485 | stats->value[IP4RETRANSSEGS] = v4.tcp_retrans_segs; |
| 486 | stats->value[IP4OUTRSTS] = v4.tcp_out_rsts; |
| 487 | stats->value[IP6INSEGS] = v6.tcp_in_segs; |
| 488 | stats->value[IP6OUTSEGS] = v6.tcp_out_segs; |
| 489 | stats->value[IP6RETRANSSEGS] = v6.tcp_retrans_segs; |
| 490 | stats->value[IP6OUTRSTS] = v6.tcp_out_rsts; |
Steve Wise | de5dd81 | 2010-10-18 15:16:40 +0000 | [diff] [blame] | 491 | |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 492 | return stats->num_counters; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 496 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 497 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 498 | |
| 499 | static struct device_attribute *c4iw_class_attributes[] = { |
| 500 | &dev_attr_hw_rev, |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 501 | &dev_attr_hca_type, |
| 502 | &dev_attr_board_id, |
| 503 | }; |
| 504 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 505 | static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 506 | struct ib_port_immutable *immutable) |
| 507 | { |
| 508 | struct ib_port_attr attr; |
| 509 | int err; |
| 510 | |
Or Gerlitz | c4550c6 | 2017-01-24 13:02:39 +0200 | [diff] [blame] | 511 | immutable->core_cap_flags = RDMA_CORE_PORT_IWARP; |
| 512 | |
| 513 | err = ib_query_port(ibdev, port_num, &attr); |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 514 | if (err) |
| 515 | return err; |
| 516 | |
| 517 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 518 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 519 | |
| 520 | return 0; |
| 521 | } |
| 522 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 523 | static void get_dev_fw_str(struct ib_device *dev, char *str) |
Ira Weiny | ce19224 | 2016-06-15 02:21:58 -0400 | [diff] [blame] | 524 | { |
| 525 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 526 | ibdev); |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 527 | pr_debug("dev 0x%p\n", dev); |
Ira Weiny | ce19224 | 2016-06-15 02:21:58 -0400 | [diff] [blame] | 528 | |
Leon Romanovsky | 9abb0d1 | 2017-06-27 16:49:53 +0300 | [diff] [blame] | 529 | snprintf(str, IB_FW_VERSION_NAME_MAX, "%u.%u.%u.%u", |
Ira Weiny | ce19224 | 2016-06-15 02:21:58 -0400 | [diff] [blame] | 530 | FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers), |
| 531 | FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers), |
| 532 | FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers), |
| 533 | FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers)); |
| 534 | } |
| 535 | |
Steve Wise | f215a3d | 2018-03-22 12:53:35 -0700 | [diff] [blame] | 536 | static struct net_device *get_netdev(struct ib_device *dev, u8 port) |
| 537 | { |
| 538 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, ibdev); |
| 539 | struct c4iw_rdev *rdev = &c4iw_dev->rdev; |
| 540 | struct net_device *ndev; |
| 541 | |
| 542 | if (!port || port > rdev->lldi.nports) |
| 543 | return NULL; |
| 544 | |
| 545 | rcu_read_lock(); |
| 546 | ndev = rdev->lldi.ports[port - 1]; |
| 547 | if (ndev) |
| 548 | dev_hold(ndev); |
| 549 | rcu_read_unlock(); |
| 550 | |
| 551 | return ndev; |
| 552 | } |
| 553 | |
Steve Wise | 056f9c7 | 2018-05-03 08:41:49 -0700 | [diff] [blame] | 554 | static int fill_res_entry(struct sk_buff *msg, struct rdma_restrack_entry *res) |
| 555 | { |
| 556 | return (res->type < ARRAY_SIZE(c4iw_restrack_funcs) && |
| 557 | c4iw_restrack_funcs[res->type]) ? |
| 558 | c4iw_restrack_funcs[res->type](msg, res) : 0; |
| 559 | } |
| 560 | |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 561 | void c4iw_register_device(struct work_struct *work) |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 562 | { |
| 563 | int ret; |
| 564 | int i; |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 565 | struct uld_ctx *ctx = container_of(work, struct uld_ctx, reg_work); |
| 566 | struct c4iw_dev *dev = ctx->dev; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 567 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 568 | pr_debug("c4iw_dev %p\n", dev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 569 | strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX); |
| 570 | memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid)); |
| 571 | memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6); |
| 572 | dev->ibdev.owner = THIS_MODULE; |
| 573 | dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW; |
| 574 | if (fastreg_support) |
| 575 | dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
| 576 | dev->ibdev.local_dma_lkey = 0; |
| 577 | dev->ibdev.uverbs_cmd_mask = |
| 578 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 579 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 580 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 581 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 582 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 583 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 584 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 585 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 586 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 587 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 588 | (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | |
| 589 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 590 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
Vipul Pandya | 67bbc05 | 2012-05-18 15:29:33 +0530 | [diff] [blame] | 591 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 592 | (1ull << IB_USER_VERBS_CMD_POLL_CQ) | |
| 593 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 594 | (1ull << IB_USER_VERBS_CMD_POST_SEND) | |
| 595 | (1ull << IB_USER_VERBS_CMD_POST_RECV); |
| 596 | dev->ibdev.node_type = RDMA_NODE_RNIC; |
Yuval Shaia | bd99fde | 2016-08-25 10:57:07 -0700 | [diff] [blame] | 597 | BUILD_BUG_ON(sizeof(C4IW_NODE_DESC) > IB_DEVICE_NODE_DESC_MAX); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 598 | memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC)); |
| 599 | dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports; |
Hariprasad Shenai | cf38be6 | 2014-06-06 21:40:42 +0530 | [diff] [blame] | 600 | dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq; |
Bart Van Assche | d08868a | 2017-01-20 13:04:16 -0800 | [diff] [blame] | 601 | dev->ibdev.dev.parent = &dev->rdev.lldi.pdev->dev; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 602 | dev->ibdev.query_device = c4iw_query_device; |
| 603 | dev->ibdev.query_port = c4iw_query_port; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 604 | dev->ibdev.query_pkey = c4iw_query_pkey; |
| 605 | dev->ibdev.query_gid = c4iw_query_gid; |
| 606 | dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext; |
| 607 | dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext; |
| 608 | dev->ibdev.mmap = c4iw_mmap; |
| 609 | dev->ibdev.alloc_pd = c4iw_allocate_pd; |
| 610 | dev->ibdev.dealloc_pd = c4iw_deallocate_pd; |
| 611 | dev->ibdev.create_ah = c4iw_ah_create; |
| 612 | dev->ibdev.destroy_ah = c4iw_ah_destroy; |
| 613 | dev->ibdev.create_qp = c4iw_create_qp; |
| 614 | dev->ibdev.modify_qp = c4iw_ib_modify_qp; |
Vipul Pandya | 67bbc05 | 2012-05-18 15:29:33 +0530 | [diff] [blame] | 615 | dev->ibdev.query_qp = c4iw_ib_query_qp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 616 | dev->ibdev.destroy_qp = c4iw_destroy_qp; |
| 617 | dev->ibdev.create_cq = c4iw_create_cq; |
| 618 | dev->ibdev.destroy_cq = c4iw_destroy_cq; |
| 619 | dev->ibdev.resize_cq = c4iw_resize_cq; |
| 620 | dev->ibdev.poll_cq = c4iw_poll_cq; |
| 621 | dev->ibdev.get_dma_mr = c4iw_get_dma_mr; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 622 | dev->ibdev.reg_user_mr = c4iw_reg_user_mr; |
| 623 | dev->ibdev.dereg_mr = c4iw_dereg_mr; |
| 624 | dev->ibdev.alloc_mw = c4iw_alloc_mw; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 625 | dev->ibdev.dealloc_mw = c4iw_dealloc_mw; |
Sagi Grimberg | a216403 | 2015-07-30 10:32:44 +0300 | [diff] [blame] | 626 | dev->ibdev.alloc_mr = c4iw_alloc_mr; |
Sagi Grimberg | 8376b86 | 2015-10-13 19:11:30 +0300 | [diff] [blame] | 627 | dev->ibdev.map_mr_sg = c4iw_map_mr_sg; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 628 | dev->ibdev.attach_mcast = c4iw_multicast_attach; |
| 629 | dev->ibdev.detach_mcast = c4iw_multicast_detach; |
| 630 | dev->ibdev.process_mad = c4iw_process_mad; |
| 631 | dev->ibdev.req_notify_cq = c4iw_arm_cq; |
| 632 | dev->ibdev.post_send = c4iw_post_send; |
| 633 | dev->ibdev.post_recv = c4iw_post_receive; |
Christoph Lameter | b40f475 | 2016-05-16 12:49:33 -0500 | [diff] [blame] | 634 | dev->ibdev.alloc_hw_stats = c4iw_alloc_stats; |
| 635 | dev->ibdev.get_hw_stats = c4iw_get_mib; |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 636 | dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame] | 637 | dev->ibdev.get_port_immutable = c4iw_port_immutable; |
Ira Weiny | ce19224 | 2016-06-15 02:21:58 -0400 | [diff] [blame] | 638 | dev->ibdev.get_dev_fw_str = get_dev_fw_str; |
Steve Wise | f215a3d | 2018-03-22 12:53:35 -0700 | [diff] [blame] | 639 | dev->ibdev.get_netdev = get_netdev; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 640 | |
| 641 | dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL); |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 642 | if (!dev->ibdev.iwcm) { |
| 643 | ret = -ENOMEM; |
| 644 | goto err_dealloc_ctx; |
| 645 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 646 | |
| 647 | dev->ibdev.iwcm->connect = c4iw_connect; |
| 648 | dev->ibdev.iwcm->accept = c4iw_accept_cr; |
| 649 | dev->ibdev.iwcm->reject = c4iw_reject_cr; |
| 650 | dev->ibdev.iwcm->create_listen = c4iw_create_listen; |
| 651 | dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen; |
| 652 | dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref; |
| 653 | dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref; |
| 654 | dev->ibdev.iwcm->get_qp = c4iw_get_qp; |
Steve Wise | 056f9c7 | 2018-05-03 08:41:49 -0700 | [diff] [blame] | 655 | dev->ibdev.res.fill_res_entry = fill_res_entry; |
Steve Wise | 851d7b6 | 2016-04-12 06:54:54 -0700 | [diff] [blame] | 656 | memcpy(dev->ibdev.iwcm->ifname, dev->rdev.lldi.ports[0]->name, |
| 657 | sizeof(dev->ibdev.iwcm->ifname)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 658 | |
Matan Barak | 0ede73b | 2018-03-19 15:02:34 +0200 | [diff] [blame] | 659 | dev->ibdev.driver_id = RDMA_DRIVER_CXGB4; |
Ralph Campbell | 9a6edb6 | 2010-05-06 17:03:25 -0700 | [diff] [blame] | 660 | ret = ib_register_device(&dev->ibdev, NULL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 661 | if (ret) |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 662 | goto err_kfree_iwcm; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 663 | |
| 664 | for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) { |
| 665 | ret = device_create_file(&dev->ibdev.dev, |
| 666 | c4iw_class_attributes[i]); |
| 667 | if (ret) |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 668 | goto err_unregister_device; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 669 | } |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 670 | return; |
| 671 | err_unregister_device: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 672 | ib_unregister_device(&dev->ibdev); |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 673 | err_kfree_iwcm: |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 674 | kfree(dev->ibdev.iwcm); |
Bharat Potnuri | 1c8f1da | 2017-11-09 17:47:33 +0530 | [diff] [blame] | 675 | err_dealloc_ctx: |
| 676 | pr_err("%s - Failed registering iwarp device: %d\n", |
| 677 | pci_name(ctx->lldi.pdev), ret); |
| 678 | c4iw_dealloc(ctx); |
| 679 | return; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | void c4iw_unregister_device(struct c4iw_dev *dev) |
| 683 | { |
| 684 | int i; |
| 685 | |
Bharat Potnuri | 548ddb1 | 2017-09-27 13:05:49 +0530 | [diff] [blame] | 686 | pr_debug("c4iw_dev %p\n", dev); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 687 | for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) |
| 688 | device_remove_file(&dev->ibdev.dev, |
| 689 | c4iw_class_attributes[i]); |
| 690 | ib_unregister_device(&dev->ibdev); |
| 691 | kfree(dev->ibdev.iwcm); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 692 | return; |
| 693 | } |