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, |
| 62 | struct ib_ah_attr *ah_attr) |
| 63 | { |
| 64 | return ERR_PTR(-ENOSYS); |
| 65 | } |
| 66 | |
| 67 | static int c4iw_ah_destroy(struct ib_ah *ah) |
| 68 | { |
| 69 | return -ENOSYS; |
| 70 | } |
| 71 | |
| 72 | static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 73 | { |
| 74 | return -ENOSYS; |
| 75 | } |
| 76 | |
| 77 | static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) |
| 78 | { |
| 79 | return -ENOSYS; |
| 80 | } |
| 81 | |
| 82 | static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags, |
| 83 | u8 port_num, struct ib_wc *in_wc, |
| 84 | struct ib_grh *in_grh, struct ib_mad *in_mad, |
| 85 | struct ib_mad *out_mad) |
| 86 | { |
| 87 | return -ENOSYS; |
| 88 | } |
| 89 | |
| 90 | static int c4iw_dealloc_ucontext(struct ib_ucontext *context) |
| 91 | { |
| 92 | struct c4iw_dev *rhp = to_c4iw_dev(context->device); |
| 93 | struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context); |
| 94 | struct c4iw_mm_entry *mm, *tmp; |
| 95 | |
| 96 | PDBG("%s context %p\n", __func__, context); |
| 97 | list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry) |
| 98 | kfree(mm); |
| 99 | c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx); |
| 100 | kfree(ucontext); |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev, |
| 105 | struct ib_udata *udata) |
| 106 | { |
| 107 | struct c4iw_ucontext *context; |
| 108 | struct c4iw_dev *rhp = to_c4iw_dev(ibdev); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 109 | static int warned; |
| 110 | struct c4iw_alloc_ucontext_resp uresp; |
| 111 | int ret = 0; |
| 112 | struct c4iw_mm_entry *mm = NULL; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 113 | |
| 114 | PDBG("%s ibdev %p\n", __func__, ibdev); |
| 115 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 116 | if (!context) { |
| 117 | ret = -ENOMEM; |
| 118 | goto err; |
| 119 | } |
| 120 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 121 | c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx); |
| 122 | INIT_LIST_HEAD(&context->mmaps); |
| 123 | spin_lock_init(&context->mmap_lock); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 124 | |
Yann Droneaud | b7dfa88 | 2014-05-05 19:35:26 +0200 | [diff] [blame] | 125 | if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) { |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 126 | if (!warned++) |
| 127 | pr_err(MOD "Warning - downlevel libcxgb4 (non-fatal), device status page disabled."); |
| 128 | rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED; |
| 129 | } else { |
| 130 | mm = kmalloc(sizeof(*mm), GFP_KERNEL); |
Yann Droneaud | bfd2793 | 2014-03-28 14:55:21 -0400 | [diff] [blame] | 131 | if (!mm) { |
| 132 | ret = -ENOMEM; |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 133 | goto err_free; |
Yann Droneaud | bfd2793 | 2014-03-28 14:55:21 -0400 | [diff] [blame] | 134 | } |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 135 | |
| 136 | uresp.status_page_size = PAGE_SIZE; |
| 137 | |
| 138 | spin_lock(&context->mmap_lock); |
| 139 | uresp.status_page_key = context->key; |
| 140 | context->key += PAGE_SIZE; |
| 141 | spin_unlock(&context->mmap_lock); |
| 142 | |
Yann Droneaud | b7dfa88 | 2014-05-05 19:35:26 +0200 | [diff] [blame] | 143 | ret = ib_copy_to_udata(udata, &uresp, |
| 144 | sizeof(uresp) - sizeof(uresp.reserved)); |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 145 | if (ret) |
| 146 | goto err_mm; |
| 147 | |
| 148 | mm->key = uresp.status_page_key; |
| 149 | mm->addr = virt_to_phys(rhp->rdev.status_page); |
| 150 | mm->len = PAGE_SIZE; |
| 151 | insert_mmap(context, mm); |
| 152 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 153 | return &context->ibucontext; |
Steve Wise | 05eb238 | 2014-03-14 21:52:08 +0530 | [diff] [blame] | 154 | err_mm: |
| 155 | kfree(mm); |
| 156 | err_free: |
| 157 | kfree(context); |
| 158 | err: |
| 159 | return ERR_PTR(ret); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma) |
| 163 | { |
| 164 | int len = vma->vm_end - vma->vm_start; |
| 165 | u32 key = vma->vm_pgoff << PAGE_SHIFT; |
| 166 | struct c4iw_rdev *rdev; |
| 167 | int ret = 0; |
| 168 | struct c4iw_mm_entry *mm; |
| 169 | struct c4iw_ucontext *ucontext; |
| 170 | u64 addr; |
| 171 | |
| 172 | PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __func__, vma->vm_pgoff, |
| 173 | key, len); |
| 174 | |
| 175 | if (vma->vm_start & (PAGE_SIZE-1)) |
| 176 | return -EINVAL; |
| 177 | |
| 178 | rdev = &(to_c4iw_dev(context->device)->rdev); |
| 179 | ucontext = to_c4iw_ucontext(context); |
| 180 | |
| 181 | mm = remove_mmap(ucontext, key, len); |
| 182 | if (!mm) |
| 183 | return -EINVAL; |
| 184 | addr = mm->addr; |
| 185 | kfree(mm); |
| 186 | |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 187 | if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) && |
| 188 | (addr < (pci_resource_start(rdev->lldi.pdev, 0) + |
| 189 | pci_resource_len(rdev->lldi.pdev, 0)))) { |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 192 | * MA_SYNC register... |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 193 | */ |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 194 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 195 | ret = io_remap_pfn_range(vma, vma->vm_start, |
| 196 | addr >> PAGE_SHIFT, |
| 197 | len, vma->vm_page_prot); |
| 198 | } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) && |
| 199 | (addr < (pci_resource_start(rdev->lldi.pdev, 2) + |
| 200 | pci_resource_len(rdev->lldi.pdev, 2)))) { |
| 201 | |
| 202 | /* |
| 203 | * Map user DB or OCQP memory... |
| 204 | */ |
| 205 | if (addr >= rdev->oc_mw_pa) |
| 206 | vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot); |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 207 | else { |
| 208 | if (is_t5(rdev->lldi.adapter_type)) |
| 209 | vma->vm_page_prot = |
| 210 | t4_pgprot_wc(vma->vm_page_prot); |
| 211 | else |
| 212 | vma->vm_page_prot = |
| 213 | pgprot_noncached(vma->vm_page_prot); |
| 214 | } |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 215 | ret = io_remap_pfn_range(vma, vma->vm_start, |
| 216 | addr >> PAGE_SHIFT, |
| 217 | len, vma->vm_page_prot); |
| 218 | } else { |
| 219 | |
| 220 | /* |
| 221 | * Map WQ or CQ contig dma memory... |
| 222 | */ |
| 223 | ret = remap_pfn_range(vma, vma->vm_start, |
| 224 | addr >> PAGE_SHIFT, |
| 225 | len, vma->vm_page_prot); |
| 226 | } |
| 227 | |
| 228 | return ret; |
| 229 | } |
| 230 | |
| 231 | static int c4iw_deallocate_pd(struct ib_pd *pd) |
| 232 | { |
| 233 | struct c4iw_dev *rhp; |
| 234 | struct c4iw_pd *php; |
| 235 | |
| 236 | php = to_c4iw_pd(pd); |
| 237 | rhp = php->rhp; |
| 238 | PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid); |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 239 | c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid); |
Vipul Pandya | 8d81ef3 | 2012-05-18 15:29:27 +0530 | [diff] [blame] | 240 | mutex_lock(&rhp->rdev.stats.lock); |
| 241 | rhp->rdev.stats.pd.cur--; |
| 242 | mutex_unlock(&rhp->rdev.stats.lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 243 | kfree(php); |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev, |
| 248 | struct ib_ucontext *context, |
| 249 | struct ib_udata *udata) |
| 250 | { |
| 251 | struct c4iw_pd *php; |
| 252 | u32 pdid; |
| 253 | struct c4iw_dev *rhp; |
| 254 | |
| 255 | PDBG("%s ibdev %p\n", __func__, ibdev); |
| 256 | rhp = (struct c4iw_dev *) ibdev; |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 257 | pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 258 | if (!pdid) |
| 259 | return ERR_PTR(-EINVAL); |
| 260 | php = kzalloc(sizeof(*php), GFP_KERNEL); |
| 261 | if (!php) { |
Vipul Pandya | ec3eead | 2012-05-18 15:29:32 +0530 | [diff] [blame] | 262 | c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 263 | return ERR_PTR(-ENOMEM); |
| 264 | } |
| 265 | php->pdid = pdid; |
| 266 | php->rhp = rhp; |
| 267 | if (context) { |
| 268 | if (ib_copy_to_udata(udata, &php->pdid, sizeof(u32))) { |
| 269 | c4iw_deallocate_pd(&php->ibpd); |
| 270 | return ERR_PTR(-EFAULT); |
| 271 | } |
| 272 | } |
Vipul Pandya | 8d81ef3 | 2012-05-18 15:29:27 +0530 | [diff] [blame] | 273 | mutex_lock(&rhp->rdev.stats.lock); |
| 274 | rhp->rdev.stats.pd.cur++; |
| 275 | if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max) |
| 276 | rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur; |
| 277 | mutex_unlock(&rhp->rdev.stats.lock); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 278 | PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php); |
| 279 | return &php->ibpd; |
| 280 | } |
| 281 | |
| 282 | static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index, |
| 283 | u16 *pkey) |
| 284 | { |
| 285 | PDBG("%s ibdev %p\n", __func__, ibdev); |
| 286 | *pkey = 0; |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index, |
| 291 | union ib_gid *gid) |
| 292 | { |
| 293 | struct c4iw_dev *dev; |
| 294 | |
| 295 | PDBG("%s ibdev %p, port %d, index %d, gid %p\n", |
| 296 | __func__, ibdev, port, index, gid); |
| 297 | dev = to_c4iw_dev(ibdev); |
| 298 | BUG_ON(port == 0); |
| 299 | memset(&(gid->raw[0]), 0, sizeof(gid->raw)); |
| 300 | memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | static int c4iw_query_device(struct ib_device *ibdev, |
| 305 | struct ib_device_attr *props) |
| 306 | { |
| 307 | |
| 308 | struct c4iw_dev *dev; |
| 309 | PDBG("%s ibdev %p\n", __func__, ibdev); |
| 310 | |
| 311 | dev = to_c4iw_dev(ibdev); |
| 312 | memset(props, 0, sizeof *props); |
| 313 | 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] | 314 | props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 315 | props->fw_ver = dev->rdev.lldi.fw_vers; |
| 316 | props->device_cap_flags = dev->device_cap_flags; |
| 317 | props->page_size_cap = T4_PAGESIZE_MASK; |
| 318 | props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor; |
| 319 | props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device; |
| 320 | props->max_mr_size = T4_MAX_MR_SIZE; |
Hariprasad Shenai | 66eb19a | 2014-07-21 20:55:15 +0530 | [diff] [blame] | 321 | props->max_qp = dev->rdev.lldi.vr->qp.size / 2; |
Hariprasad Shenai | 04e10e2 | 2014-07-14 21:34:51 +0530 | [diff] [blame] | 322 | props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 323 | props->max_sge = T4_MAX_RECV_SGE; |
| 324 | props->max_sge_rd = 1; |
Hariprasad Shenai | 4c2c576 | 2014-07-14 21:34:52 +0530 | [diff] [blame] | 325 | props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter; |
| 326 | props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp, |
| 327 | c4iw_max_read_depth); |
| 328 | props->max_qp_init_rd_atom = props->max_qp_rd_atom; |
Hariprasad Shenai | 66eb19a | 2014-07-21 20:55:15 +0530 | [diff] [blame] | 329 | props->max_cq = dev->rdev.lldi.vr->qp.size; |
Hariprasad Shenai | 04e10e2 | 2014-07-14 21:34:51 +0530 | [diff] [blame] | 330 | props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 331 | props->max_mr = c4iw_num_stags(&dev->rdev); |
| 332 | props->max_pd = T4_MAX_NUM_PD; |
| 333 | props->local_ca_ack_delay = 0; |
Steve Wise | a03d9f9 | 2014-04-09 09:38:27 -0500 | [diff] [blame] | 334 | props->max_fast_reg_page_list_len = t4_max_fr_depth(use_dsgl); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int c4iw_query_port(struct ib_device *ibdev, u8 port, |
| 340 | struct ib_port_attr *props) |
| 341 | { |
| 342 | struct c4iw_dev *dev; |
| 343 | struct net_device *netdev; |
| 344 | struct in_device *inetdev; |
| 345 | |
| 346 | PDBG("%s ibdev %p\n", __func__, ibdev); |
| 347 | |
| 348 | dev = to_c4iw_dev(ibdev); |
| 349 | netdev = dev->rdev.lldi.ports[port-1]; |
| 350 | |
| 351 | memset(props, 0, sizeof(struct ib_port_attr)); |
| 352 | props->max_mtu = IB_MTU_4096; |
| 353 | if (netdev->mtu >= 4096) |
| 354 | props->active_mtu = IB_MTU_4096; |
| 355 | else if (netdev->mtu >= 2048) |
| 356 | props->active_mtu = IB_MTU_2048; |
| 357 | else if (netdev->mtu >= 1024) |
| 358 | props->active_mtu = IB_MTU_1024; |
| 359 | else if (netdev->mtu >= 512) |
| 360 | props->active_mtu = IB_MTU_512; |
| 361 | else |
| 362 | props->active_mtu = IB_MTU_256; |
| 363 | |
| 364 | if (!netif_carrier_ok(netdev)) |
| 365 | props->state = IB_PORT_DOWN; |
| 366 | else { |
| 367 | inetdev = in_dev_get(netdev); |
| 368 | if (inetdev) { |
| 369 | if (inetdev->ifa_list) |
| 370 | props->state = IB_PORT_ACTIVE; |
| 371 | else |
| 372 | props->state = IB_PORT_INIT; |
| 373 | in_dev_put(inetdev); |
| 374 | } else |
| 375 | props->state = IB_PORT_INIT; |
| 376 | } |
| 377 | |
| 378 | props->port_cap_flags = |
| 379 | IB_PORT_CM_SUP | |
| 380 | IB_PORT_SNMP_TUNNEL_SUP | |
| 381 | IB_PORT_REINIT_SUP | |
| 382 | IB_PORT_DEVICE_MGMT_SUP | |
| 383 | IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP; |
| 384 | props->gid_tbl_len = 1; |
| 385 | props->pkey_tbl_len = 1; |
| 386 | props->active_width = 2; |
Or Gerlitz | 2e96691 | 2012-02-28 18:49:50 +0200 | [diff] [blame] | 387 | props->active_speed = IB_SPEED_DDR; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 388 | props->max_msg_sz = -1; |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
Michael Wang | 6b90a6d | 2015-05-05 14:50:18 +0200 | [diff] [blame] | 393 | static enum rdma_protocol_type |
| 394 | c4iw_query_protocol(struct ib_device *device, u8 port_num) |
| 395 | { |
| 396 | return RDMA_PROTOCOL_IWARP; |
| 397 | } |
| 398 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 399 | static ssize_t show_rev(struct device *dev, struct device_attribute *attr, |
| 400 | char *buf) |
| 401 | { |
| 402 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 403 | ibdev.dev); |
| 404 | PDBG("%s dev 0x%p\n", __func__, dev); |
Vipul Pandya | f079af7 | 2013-03-14 05:08:58 +0000 | [diff] [blame] | 405 | return sprintf(buf, "%d\n", |
| 406 | CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr, |
| 410 | char *buf) |
| 411 | { |
| 412 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 413 | ibdev.dev); |
| 414 | PDBG("%s dev 0x%p\n", __func__, dev); |
| 415 | |
| 416 | return sprintf(buf, "%u.%u.%u.%u\n", |
Hariprasad Shenai | b2e1a3f | 2014-11-21 12:52:05 +0530 | [diff] [blame] | 417 | FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers), |
| 418 | FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers), |
| 419 | FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers), |
| 420 | FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers)); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static ssize_t show_hca(struct device *dev, struct device_attribute *attr, |
| 424 | char *buf) |
| 425 | { |
| 426 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 427 | ibdev.dev); |
| 428 | struct ethtool_drvinfo info; |
| 429 | struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0]; |
| 430 | |
| 431 | PDBG("%s dev 0x%p\n", __func__, dev); |
| 432 | lldev->ethtool_ops->get_drvinfo(lldev, &info); |
| 433 | return sprintf(buf, "%s\n", info.driver); |
| 434 | } |
| 435 | |
| 436 | static ssize_t show_board(struct device *dev, struct device_attribute *attr, |
| 437 | char *buf) |
| 438 | { |
| 439 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, |
| 440 | ibdev.dev); |
| 441 | PDBG("%s dev 0x%p\n", __func__, dev); |
| 442 | return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor, |
| 443 | c4iw_dev->rdev.lldi.pdev->device); |
| 444 | } |
| 445 | |
| 446 | static int c4iw_get_mib(struct ib_device *ibdev, |
| 447 | union rdma_protocol_stats *stats) |
| 448 | { |
Steve Wise | de5dd81 | 2010-10-18 15:16:40 +0000 | [diff] [blame] | 449 | struct tp_tcp_stats v4, v6; |
| 450 | struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev); |
| 451 | |
| 452 | cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6); |
| 453 | memset(stats, 0, sizeof *stats); |
| 454 | stats->iw.tcpInSegs = v4.tcpInSegs + v6.tcpInSegs; |
| 455 | stats->iw.tcpOutSegs = v4.tcpOutSegs + v6.tcpOutSegs; |
| 456 | stats->iw.tcpRetransSegs = v4.tcpRetransSegs + v6.tcpRetransSegs; |
| 457 | stats->iw.tcpOutRsts = v4.tcpOutRsts + v6.tcpOutSegs; |
| 458 | |
| 459 | return 0; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); |
| 463 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); |
| 464 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); |
| 465 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); |
| 466 | |
| 467 | static struct device_attribute *c4iw_class_attributes[] = { |
| 468 | &dev_attr_hw_rev, |
| 469 | &dev_attr_fw_ver, |
| 470 | &dev_attr_hca_type, |
| 471 | &dev_attr_board_id, |
| 472 | }; |
| 473 | |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame^] | 474 | static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num, |
| 475 | struct ib_port_immutable *immutable) |
| 476 | { |
| 477 | struct ib_port_attr attr; |
| 478 | int err; |
| 479 | |
| 480 | err = c4iw_query_port(ibdev, port_num, &attr); |
| 481 | if (err) |
| 482 | return err; |
| 483 | |
| 484 | immutable->pkey_tbl_len = attr.pkey_tbl_len; |
| 485 | immutable->gid_tbl_len = attr.gid_tbl_len; |
| 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 490 | int c4iw_register_device(struct c4iw_dev *dev) |
| 491 | { |
| 492 | int ret; |
| 493 | int i; |
| 494 | |
| 495 | PDBG("%s c4iw_dev %p\n", __func__, dev); |
| 496 | BUG_ON(!dev->rdev.lldi.ports[0]); |
| 497 | strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX); |
| 498 | memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid)); |
| 499 | memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6); |
| 500 | dev->ibdev.owner = THIS_MODULE; |
| 501 | dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW; |
| 502 | if (fastreg_support) |
| 503 | dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; |
| 504 | dev->ibdev.local_dma_lkey = 0; |
| 505 | dev->ibdev.uverbs_cmd_mask = |
| 506 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | |
| 507 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | |
| 508 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | |
| 509 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | |
| 510 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | |
| 511 | (1ull << IB_USER_VERBS_CMD_REG_MR) | |
| 512 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | |
| 513 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | |
| 514 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | |
| 515 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | |
| 516 | (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | |
| 517 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | |
| 518 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | |
Vipul Pandya | 67bbc05 | 2012-05-18 15:29:33 +0530 | [diff] [blame] | 519 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 520 | (1ull << IB_USER_VERBS_CMD_POLL_CQ) | |
| 521 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | |
| 522 | (1ull << IB_USER_VERBS_CMD_POST_SEND) | |
| 523 | (1ull << IB_USER_VERBS_CMD_POST_RECV); |
| 524 | dev->ibdev.node_type = RDMA_NODE_RNIC; |
| 525 | memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC)); |
| 526 | dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports; |
Hariprasad Shenai | cf38be6 | 2014-06-06 21:40:42 +0530 | [diff] [blame] | 527 | dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 528 | dev->ibdev.dma_device = &(dev->rdev.lldi.pdev->dev); |
| 529 | dev->ibdev.query_device = c4iw_query_device; |
| 530 | dev->ibdev.query_port = c4iw_query_port; |
Michael Wang | 6b90a6d | 2015-05-05 14:50:18 +0200 | [diff] [blame] | 531 | dev->ibdev.query_protocol = c4iw_query_protocol; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 532 | dev->ibdev.query_pkey = c4iw_query_pkey; |
| 533 | dev->ibdev.query_gid = c4iw_query_gid; |
| 534 | dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext; |
| 535 | dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext; |
| 536 | dev->ibdev.mmap = c4iw_mmap; |
| 537 | dev->ibdev.alloc_pd = c4iw_allocate_pd; |
| 538 | dev->ibdev.dealloc_pd = c4iw_deallocate_pd; |
| 539 | dev->ibdev.create_ah = c4iw_ah_create; |
| 540 | dev->ibdev.destroy_ah = c4iw_ah_destroy; |
| 541 | dev->ibdev.create_qp = c4iw_create_qp; |
| 542 | dev->ibdev.modify_qp = c4iw_ib_modify_qp; |
Vipul Pandya | 67bbc05 | 2012-05-18 15:29:33 +0530 | [diff] [blame] | 543 | dev->ibdev.query_qp = c4iw_ib_query_qp; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 544 | dev->ibdev.destroy_qp = c4iw_destroy_qp; |
| 545 | dev->ibdev.create_cq = c4iw_create_cq; |
| 546 | dev->ibdev.destroy_cq = c4iw_destroy_cq; |
| 547 | dev->ibdev.resize_cq = c4iw_resize_cq; |
| 548 | dev->ibdev.poll_cq = c4iw_poll_cq; |
| 549 | dev->ibdev.get_dma_mr = c4iw_get_dma_mr; |
| 550 | dev->ibdev.reg_phys_mr = c4iw_register_phys_mem; |
| 551 | dev->ibdev.rereg_phys_mr = c4iw_reregister_phys_mem; |
| 552 | dev->ibdev.reg_user_mr = c4iw_reg_user_mr; |
| 553 | dev->ibdev.dereg_mr = c4iw_dereg_mr; |
| 554 | dev->ibdev.alloc_mw = c4iw_alloc_mw; |
| 555 | dev->ibdev.bind_mw = c4iw_bind_mw; |
| 556 | dev->ibdev.dealloc_mw = c4iw_dealloc_mw; |
| 557 | dev->ibdev.alloc_fast_reg_mr = c4iw_alloc_fast_reg_mr; |
| 558 | dev->ibdev.alloc_fast_reg_page_list = c4iw_alloc_fastreg_pbl; |
| 559 | dev->ibdev.free_fast_reg_page_list = c4iw_free_fastreg_pbl; |
| 560 | dev->ibdev.attach_mcast = c4iw_multicast_attach; |
| 561 | dev->ibdev.detach_mcast = c4iw_multicast_detach; |
| 562 | dev->ibdev.process_mad = c4iw_process_mad; |
| 563 | dev->ibdev.req_notify_cq = c4iw_arm_cq; |
| 564 | dev->ibdev.post_send = c4iw_post_send; |
| 565 | dev->ibdev.post_recv = c4iw_post_receive; |
| 566 | dev->ibdev.get_protocol_stats = c4iw_get_mib; |
Steve Wise | c6d7b26 | 2010-09-13 11:23:57 -0500 | [diff] [blame] | 567 | dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION; |
Ira Weiny | 7738613 | 2015-05-13 20:02:58 -0400 | [diff] [blame^] | 568 | dev->ibdev.get_port_immutable = c4iw_port_immutable; |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 569 | |
| 570 | dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL); |
| 571 | if (!dev->ibdev.iwcm) |
| 572 | return -ENOMEM; |
| 573 | |
| 574 | dev->ibdev.iwcm->connect = c4iw_connect; |
| 575 | dev->ibdev.iwcm->accept = c4iw_accept_cr; |
| 576 | dev->ibdev.iwcm->reject = c4iw_reject_cr; |
| 577 | dev->ibdev.iwcm->create_listen = c4iw_create_listen; |
| 578 | dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen; |
| 579 | dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref; |
| 580 | dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref; |
| 581 | dev->ibdev.iwcm->get_qp = c4iw_get_qp; |
| 582 | |
Ralph Campbell | 9a6edb6 | 2010-05-06 17:03:25 -0700 | [diff] [blame] | 583 | ret = ib_register_device(&dev->ibdev, NULL); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 584 | if (ret) |
| 585 | goto bail1; |
| 586 | |
| 587 | for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) { |
| 588 | ret = device_create_file(&dev->ibdev.dev, |
| 589 | c4iw_class_attributes[i]); |
| 590 | if (ret) |
| 591 | goto bail2; |
| 592 | } |
| 593 | return 0; |
| 594 | bail2: |
| 595 | ib_unregister_device(&dev->ibdev); |
| 596 | bail1: |
| 597 | kfree(dev->ibdev.iwcm); |
| 598 | return ret; |
| 599 | } |
| 600 | |
| 601 | void c4iw_unregister_device(struct c4iw_dev *dev) |
| 602 | { |
| 603 | int i; |
| 604 | |
| 605 | PDBG("%s c4iw_dev %p\n", __func__, dev); |
| 606 | for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) |
| 607 | device_remove_file(&dev->ibdev.dev, |
| 608 | c4iw_class_attributes[i]); |
| 609 | ib_unregister_device(&dev->ibdev); |
| 610 | kfree(dev->ibdev.iwcm); |
Steve Wise | cfdda9d | 2010-04-21 15:30:06 -0700 | [diff] [blame] | 611 | return; |
| 612 | } |