blob: df127ce6b6ec31772f4b6ce1f4a3e980b2800bf3 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
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 Wise40dbf6e2010-09-17 15:40:15 -050057static int fastreg_support = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -070058module_param(fastreg_support, int, 0644);
Steve Wise40dbf6e2010-09-17 15:40:15 -050059MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -070060
Steve Wisecfdda9d2010-04-21 15:30:06 -070061static 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
67static int c4iw_ah_destroy(struct ib_ah *ah)
68{
69 return -ENOSYS;
70}
71
72static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
73{
74 return -ENOSYS;
75}
76
77static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
78{
79 return -ENOSYS;
80}
81
82static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags,
Ira Weinya97e2d82015-05-31 17:15:30 -040083 u8 port_num, const struct ib_wc *in_wc,
84 const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -040085 const struct ib_mad_hdr *in_mad,
86 size_t in_mad_size,
87 struct ib_mad_hdr *out_mad,
88 size_t *out_mad_size,
89 u16 *out_mad_pkey_index)
Steve Wisecfdda9d2010-04-21 15:30:06 -070090{
91 return -ENOSYS;
92}
93
94static int c4iw_dealloc_ucontext(struct ib_ucontext *context)
95{
96 struct c4iw_dev *rhp = to_c4iw_dev(context->device);
97 struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
98 struct c4iw_mm_entry *mm, *tmp;
99
100 PDBG("%s context %p\n", __func__, context);
101 list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
102 kfree(mm);
103 c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
104 kfree(ucontext);
105 return 0;
106}
107
108static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
109 struct ib_udata *udata)
110{
111 struct c4iw_ucontext *context;
112 struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
Steve Wise05eb2382014-03-14 21:52:08 +0530113 static int warned;
114 struct c4iw_alloc_ucontext_resp uresp;
115 int ret = 0;
116 struct c4iw_mm_entry *mm = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700117
118 PDBG("%s ibdev %p\n", __func__, ibdev);
119 context = kzalloc(sizeof(*context), GFP_KERNEL);
Steve Wise05eb2382014-03-14 21:52:08 +0530120 if (!context) {
121 ret = -ENOMEM;
122 goto err;
123 }
124
Steve Wisecfdda9d2010-04-21 15:30:06 -0700125 c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
126 INIT_LIST_HEAD(&context->mmaps);
127 spin_lock_init(&context->mmap_lock);
Steve Wise05eb2382014-03-14 21:52:08 +0530128
Yann Droneaudb7dfa882014-05-05 19:35:26 +0200129 if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
Steve Wise05eb2382014-03-14 21:52:08 +0530130 if (!warned++)
131 pr_err(MOD "Warning - downlevel libcxgb4 (non-fatal), device status page disabled.");
132 rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
133 } else {
134 mm = kmalloc(sizeof(*mm), GFP_KERNEL);
Yann Droneaudbfd27932014-03-28 14:55:21 -0400135 if (!mm) {
136 ret = -ENOMEM;
Steve Wise05eb2382014-03-14 21:52:08 +0530137 goto err_free;
Yann Droneaudbfd27932014-03-28 14:55:21 -0400138 }
Steve Wise05eb2382014-03-14 21:52:08 +0530139
140 uresp.status_page_size = PAGE_SIZE;
141
142 spin_lock(&context->mmap_lock);
143 uresp.status_page_key = context->key;
144 context->key += PAGE_SIZE;
145 spin_unlock(&context->mmap_lock);
146
Yann Droneaudb7dfa882014-05-05 19:35:26 +0200147 ret = ib_copy_to_udata(udata, &uresp,
148 sizeof(uresp) - sizeof(uresp.reserved));
Steve Wise05eb2382014-03-14 21:52:08 +0530149 if (ret)
150 goto err_mm;
151
152 mm->key = uresp.status_page_key;
153 mm->addr = virt_to_phys(rhp->rdev.status_page);
154 mm->len = PAGE_SIZE;
155 insert_mmap(context, mm);
156 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700157 return &context->ibucontext;
Steve Wise05eb2382014-03-14 21:52:08 +0530158err_mm:
159 kfree(mm);
160err_free:
161 kfree(context);
162err:
163 return ERR_PTR(ret);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700164}
165
166static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
167{
168 int len = vma->vm_end - vma->vm_start;
169 u32 key = vma->vm_pgoff << PAGE_SHIFT;
170 struct c4iw_rdev *rdev;
171 int ret = 0;
172 struct c4iw_mm_entry *mm;
173 struct c4iw_ucontext *ucontext;
174 u64 addr;
175
176 PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __func__, vma->vm_pgoff,
177 key, len);
178
179 if (vma->vm_start & (PAGE_SIZE-1))
180 return -EINVAL;
181
182 rdev = &(to_c4iw_dev(context->device)->rdev);
183 ucontext = to_c4iw_ucontext(context);
184
185 mm = remove_mmap(ucontext, key, len);
186 if (!mm)
187 return -EINVAL;
188 addr = mm->addr;
189 kfree(mm);
190
Steve Wisec6d7b262010-09-13 11:23:57 -0500191 if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
192 (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
193 pci_resource_len(rdev->lldi.pdev, 0)))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -0700194
195 /*
Steve Wisec6d7b262010-09-13 11:23:57 -0500196 * MA_SYNC register...
Steve Wisecfdda9d2010-04-21 15:30:06 -0700197 */
Steve Wisecfdda9d2010-04-21 15:30:06 -0700198 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
Steve Wisec6d7b262010-09-13 11:23:57 -0500199 ret = io_remap_pfn_range(vma, vma->vm_start,
200 addr >> PAGE_SHIFT,
201 len, vma->vm_page_prot);
202 } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
203 (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
204 pci_resource_len(rdev->lldi.pdev, 2)))) {
205
206 /*
207 * Map user DB or OCQP memory...
208 */
209 if (addr >= rdev->oc_mw_pa)
210 vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
Vipul Pandyaf079af72013-03-14 05:08:58 +0000211 else {
Hariprasad S963cab52015-09-23 17:19:27 +0530212 if (!is_t4(rdev->lldi.adapter_type))
Vipul Pandyaf079af72013-03-14 05:08:58 +0000213 vma->vm_page_prot =
214 t4_pgprot_wc(vma->vm_page_prot);
215 else
216 vma->vm_page_prot =
217 pgprot_noncached(vma->vm_page_prot);
218 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700219 ret = io_remap_pfn_range(vma, vma->vm_start,
220 addr >> PAGE_SHIFT,
221 len, vma->vm_page_prot);
222 } else {
223
224 /*
225 * Map WQ or CQ contig dma memory...
226 */
227 ret = remap_pfn_range(vma, vma->vm_start,
228 addr >> PAGE_SHIFT,
229 len, vma->vm_page_prot);
230 }
231
232 return ret;
233}
234
235static int c4iw_deallocate_pd(struct ib_pd *pd)
236{
237 struct c4iw_dev *rhp;
238 struct c4iw_pd *php;
239
240 php = to_c4iw_pd(pd);
241 rhp = php->rhp;
242 PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid);
Vipul Pandyaec3eead2012-05-18 15:29:32 +0530243 c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
Vipul Pandya8d81ef32012-05-18 15:29:27 +0530244 mutex_lock(&rhp->rdev.stats.lock);
245 rhp->rdev.stats.pd.cur--;
246 mutex_unlock(&rhp->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700247 kfree(php);
248 return 0;
249}
250
251static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev,
252 struct ib_ucontext *context,
253 struct ib_udata *udata)
254{
255 struct c4iw_pd *php;
256 u32 pdid;
257 struct c4iw_dev *rhp;
258
259 PDBG("%s ibdev %p\n", __func__, ibdev);
260 rhp = (struct c4iw_dev *) ibdev;
Vipul Pandyaec3eead2012-05-18 15:29:32 +0530261 pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 if (!pdid)
263 return ERR_PTR(-EINVAL);
264 php = kzalloc(sizeof(*php), GFP_KERNEL);
265 if (!php) {
Vipul Pandyaec3eead2012-05-18 15:29:32 +0530266 c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700267 return ERR_PTR(-ENOMEM);
268 }
269 php->pdid = pdid;
270 php->rhp = rhp;
271 if (context) {
272 if (ib_copy_to_udata(udata, &php->pdid, sizeof(u32))) {
273 c4iw_deallocate_pd(&php->ibpd);
274 return ERR_PTR(-EFAULT);
275 }
276 }
Vipul Pandya8d81ef32012-05-18 15:29:27 +0530277 mutex_lock(&rhp->rdev.stats.lock);
278 rhp->rdev.stats.pd.cur++;
279 if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
280 rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
281 mutex_unlock(&rhp->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700282 PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php);
283 return &php->ibpd;
284}
285
286static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
287 u16 *pkey)
288{
289 PDBG("%s ibdev %p\n", __func__, ibdev);
290 *pkey = 0;
291 return 0;
292}
293
294static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
295 union ib_gid *gid)
296{
297 struct c4iw_dev *dev;
298
299 PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
300 __func__, ibdev, port, index, gid);
301 dev = to_c4iw_dev(ibdev);
302 BUG_ON(port == 0);
303 memset(&(gid->raw[0]), 0, sizeof(gid->raw));
304 memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
305 return 0;
306}
307
Matan Barak2528e332015-06-11 16:35:25 +0300308static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
309 struct ib_udata *uhw)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700310{
311
312 struct c4iw_dev *dev;
Matan Barak2528e332015-06-11 16:35:25 +0300313
Steve Wisecfdda9d2010-04-21 15:30:06 -0700314 PDBG("%s ibdev %p\n", __func__, ibdev);
315
Matan Barak2528e332015-06-11 16:35:25 +0300316 if (uhw->inlen || uhw->outlen)
317 return -EINVAL;
318
Steve Wisecfdda9d2010-04-21 15:30:06 -0700319 dev = to_c4iw_dev(ibdev);
320 memset(props, 0, sizeof *props);
321 memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
Vipul Pandyaf079af72013-03-14 05:08:58 +0000322 props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700323 props->fw_ver = dev->rdev.lldi.fw_vers;
324 props->device_cap_flags = dev->device_cap_flags;
325 props->page_size_cap = T4_PAGESIZE_MASK;
326 props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
327 props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
328 props->max_mr_size = T4_MAX_MR_SIZE;
Hariprasad Shenai66eb19a2014-07-21 20:55:15 +0530329 props->max_qp = dev->rdev.lldi.vr->qp.size / 2;
Hariprasad Shenai04e10e22014-07-14 21:34:51 +0530330 props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700331 props->max_sge = T4_MAX_RECV_SGE;
332 props->max_sge_rd = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530333 props->max_res_rd_atom = dev->rdev.lldi.max_ird_adapter;
334 props->max_qp_rd_atom = min(dev->rdev.lldi.max_ordird_qp,
335 c4iw_max_read_depth);
336 props->max_qp_init_rd_atom = props->max_qp_rd_atom;
Hariprasad Shenai66eb19a2014-07-21 20:55:15 +0530337 props->max_cq = dev->rdev.lldi.vr->qp.size;
Hariprasad Shenai04e10e22014-07-14 21:34:51 +0530338 props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700339 props->max_mr = c4iw_num_stags(&dev->rdev);
340 props->max_pd = T4_MAX_NUM_PD;
341 props->local_ca_ack_delay = 0;
Hariprasad See30f7d2016-02-12 16:10:35 +0530342 props->max_fast_reg_page_list_len =
343 t4_max_fr_depth(dev->rdev.lldi.ulptx_memwrite_dsgl && use_dsgl);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700344
345 return 0;
346}
347
348static int c4iw_query_port(struct ib_device *ibdev, u8 port,
349 struct ib_port_attr *props)
350{
351 struct c4iw_dev *dev;
352 struct net_device *netdev;
353 struct in_device *inetdev;
354
355 PDBG("%s ibdev %p\n", __func__, ibdev);
356
357 dev = to_c4iw_dev(ibdev);
358 netdev = dev->rdev.lldi.ports[port-1];
359
360 memset(props, 0, sizeof(struct ib_port_attr));
361 props->max_mtu = IB_MTU_4096;
362 if (netdev->mtu >= 4096)
363 props->active_mtu = IB_MTU_4096;
364 else if (netdev->mtu >= 2048)
365 props->active_mtu = IB_MTU_2048;
366 else if (netdev->mtu >= 1024)
367 props->active_mtu = IB_MTU_1024;
368 else if (netdev->mtu >= 512)
369 props->active_mtu = IB_MTU_512;
370 else
371 props->active_mtu = IB_MTU_256;
372
373 if (!netif_carrier_ok(netdev))
374 props->state = IB_PORT_DOWN;
375 else {
376 inetdev = in_dev_get(netdev);
377 if (inetdev) {
378 if (inetdev->ifa_list)
379 props->state = IB_PORT_ACTIVE;
380 else
381 props->state = IB_PORT_INIT;
382 in_dev_put(inetdev);
383 } else
384 props->state = IB_PORT_INIT;
385 }
386
387 props->port_cap_flags =
388 IB_PORT_CM_SUP |
389 IB_PORT_SNMP_TUNNEL_SUP |
390 IB_PORT_REINIT_SUP |
391 IB_PORT_DEVICE_MGMT_SUP |
392 IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
393 props->gid_tbl_len = 1;
394 props->pkey_tbl_len = 1;
395 props->active_width = 2;
Or Gerlitz2e966912012-02-28 18:49:50 +0200396 props->active_speed = IB_SPEED_DDR;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700397 props->max_msg_sz = -1;
398
399 return 0;
400}
401
402static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
403 char *buf)
404{
405 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
406 ibdev.dev);
407 PDBG("%s dev 0x%p\n", __func__, dev);
Vipul Pandyaf079af72013-03-14 05:08:58 +0000408 return sprintf(buf, "%d\n",
409 CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700410}
411
Steve Wisecfdda9d2010-04-21 15:30:06 -0700412static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
413 char *buf)
414{
415 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
416 ibdev.dev);
417 struct ethtool_drvinfo info;
418 struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
419
420 PDBG("%s dev 0x%p\n", __func__, dev);
421 lldev->ethtool_ops->get_drvinfo(lldev, &info);
422 return sprintf(buf, "%s\n", info.driver);
423}
424
425static ssize_t show_board(struct device *dev, struct device_attribute *attr,
426 char *buf)
427{
428 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
429 ibdev.dev);
430 PDBG("%s dev 0x%p\n", __func__, dev);
431 return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
432 c4iw_dev->rdev.lldi.pdev->device);
433}
434
Christoph Lameterb40f4752016-05-16 12:49:33 -0500435enum counters {
436 IP4INSEGS,
437 IP4OUTSEGS,
438 IP4RETRANSSEGS,
439 IP4OUTRSTS,
440 IP6INSEGS,
441 IP6OUTSEGS,
442 IP6RETRANSSEGS,
443 IP6OUTRSTS,
444 NR_COUNTERS
445};
446
447static const char * const names[] = {
448 [IP4INSEGS] = "ip4InSegs",
449 [IP4OUTSEGS] = "ip4OutSegs",
450 [IP4RETRANSSEGS] = "ip4RetransSegs",
451 [IP4OUTRSTS] = "ip4OutRsts",
452 [IP6INSEGS] = "ip6InSegs",
453 [IP6OUTSEGS] = "ip6OutSegs",
454 [IP6RETRANSSEGS] = "ip6RetransSegs",
455 [IP6OUTRSTS] = "ip6OutRsts"
456};
457
458static struct rdma_hw_stats *c4iw_alloc_stats(struct ib_device *ibdev,
459 u8 port_num)
460{
461 BUILD_BUG_ON(ARRAY_SIZE(names) != NR_COUNTERS);
462
463 if (port_num != 0)
464 return NULL;
465
466 return rdma_alloc_hw_stats_struct(names, NR_COUNTERS,
467 RDMA_HW_STATS_DEFAULT_LIFESPAN);
468}
469
Steve Wisecfdda9d2010-04-21 15:30:06 -0700470static int c4iw_get_mib(struct ib_device *ibdev,
Christoph Lameterb40f4752016-05-16 12:49:33 -0500471 struct rdma_hw_stats *stats,
472 u8 port, int index)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700473{
Steve Wisede5dd812010-10-18 15:16:40 +0000474 struct tp_tcp_stats v4, v6;
475 struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
476
477 cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
Christoph Lameterb40f4752016-05-16 12:49:33 -0500478 stats->value[IP4INSEGS] = v4.tcp_in_segs;
479 stats->value[IP4OUTSEGS] = v4.tcp_out_segs;
480 stats->value[IP4RETRANSSEGS] = v4.tcp_retrans_segs;
481 stats->value[IP4OUTRSTS] = v4.tcp_out_rsts;
482 stats->value[IP6INSEGS] = v6.tcp_in_segs;
483 stats->value[IP6OUTSEGS] = v6.tcp_out_segs;
484 stats->value[IP6RETRANSSEGS] = v6.tcp_retrans_segs;
485 stats->value[IP6OUTRSTS] = v6.tcp_out_rsts;
Steve Wisede5dd812010-10-18 15:16:40 +0000486
Christoph Lameterb40f4752016-05-16 12:49:33 -0500487 return stats->num_counters;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700488}
489
490static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700491static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
492static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
493
494static struct device_attribute *c4iw_class_attributes[] = {
495 &dev_attr_hw_rev,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700496 &dev_attr_hca_type,
497 &dev_attr_board_id,
498};
499
Ira Weiny77386132015-05-13 20:02:58 -0400500static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num,
501 struct ib_port_immutable *immutable)
502{
503 struct ib_port_attr attr;
504 int err;
505
506 err = c4iw_query_port(ibdev, port_num, &attr);
507 if (err)
508 return err;
509
510 immutable->pkey_tbl_len = attr.pkey_tbl_len;
511 immutable->gid_tbl_len = attr.gid_tbl_len;
Ira Weinyf9b22e32015-05-13 20:02:59 -0400512 immutable->core_cap_flags = RDMA_CORE_PORT_IWARP;
Ira Weiny77386132015-05-13 20:02:58 -0400513
514 return 0;
515}
516
Ira Weinyce192242016-06-15 02:21:58 -0400517static void get_dev_fw_str(struct ib_device *dev, char *str,
518 size_t str_len)
519{
520 struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
521 ibdev);
522 PDBG("%s dev 0x%p\n", __func__, dev);
523
524 snprintf(str, str_len, "%u.%u.%u.%u",
525 FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers),
526 FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers),
527 FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers),
528 FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers));
529}
530
Steve Wisecfdda9d2010-04-21 15:30:06 -0700531int c4iw_register_device(struct c4iw_dev *dev)
532{
533 int ret;
534 int i;
535
536 PDBG("%s c4iw_dev %p\n", __func__, dev);
537 BUG_ON(!dev->rdev.lldi.ports[0]);
538 strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX);
539 memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
540 memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
541 dev->ibdev.owner = THIS_MODULE;
542 dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
543 if (fastreg_support)
544 dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
545 dev->ibdev.local_dma_lkey = 0;
546 dev->ibdev.uverbs_cmd_mask =
547 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
548 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
549 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
550 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
551 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
552 (1ull << IB_USER_VERBS_CMD_REG_MR) |
553 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
554 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
555 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
556 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
557 (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
558 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
559 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
Vipul Pandya67bbc052012-05-18 15:29:33 +0530560 (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700561 (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
562 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
563 (1ull << IB_USER_VERBS_CMD_POST_SEND) |
564 (1ull << IB_USER_VERBS_CMD_POST_RECV);
565 dev->ibdev.node_type = RDMA_NODE_RNIC;
566 memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
567 dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
Hariprasad Shenaicf38be62014-06-06 21:40:42 +0530568 dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700569 dev->ibdev.dma_device = &(dev->rdev.lldi.pdev->dev);
570 dev->ibdev.query_device = c4iw_query_device;
571 dev->ibdev.query_port = c4iw_query_port;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700572 dev->ibdev.query_pkey = c4iw_query_pkey;
573 dev->ibdev.query_gid = c4iw_query_gid;
574 dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext;
575 dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext;
576 dev->ibdev.mmap = c4iw_mmap;
577 dev->ibdev.alloc_pd = c4iw_allocate_pd;
578 dev->ibdev.dealloc_pd = c4iw_deallocate_pd;
579 dev->ibdev.create_ah = c4iw_ah_create;
580 dev->ibdev.destroy_ah = c4iw_ah_destroy;
581 dev->ibdev.create_qp = c4iw_create_qp;
582 dev->ibdev.modify_qp = c4iw_ib_modify_qp;
Vipul Pandya67bbc052012-05-18 15:29:33 +0530583 dev->ibdev.query_qp = c4iw_ib_query_qp;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700584 dev->ibdev.destroy_qp = c4iw_destroy_qp;
585 dev->ibdev.create_cq = c4iw_create_cq;
586 dev->ibdev.destroy_cq = c4iw_destroy_cq;
587 dev->ibdev.resize_cq = c4iw_resize_cq;
588 dev->ibdev.poll_cq = c4iw_poll_cq;
589 dev->ibdev.get_dma_mr = c4iw_get_dma_mr;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700590 dev->ibdev.reg_user_mr = c4iw_reg_user_mr;
591 dev->ibdev.dereg_mr = c4iw_dereg_mr;
592 dev->ibdev.alloc_mw = c4iw_alloc_mw;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700593 dev->ibdev.dealloc_mw = c4iw_dealloc_mw;
Sagi Grimberga2164032015-07-30 10:32:44 +0300594 dev->ibdev.alloc_mr = c4iw_alloc_mr;
Sagi Grimberg8376b862015-10-13 19:11:30 +0300595 dev->ibdev.map_mr_sg = c4iw_map_mr_sg;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700596 dev->ibdev.attach_mcast = c4iw_multicast_attach;
597 dev->ibdev.detach_mcast = c4iw_multicast_detach;
598 dev->ibdev.process_mad = c4iw_process_mad;
599 dev->ibdev.req_notify_cq = c4iw_arm_cq;
600 dev->ibdev.post_send = c4iw_post_send;
601 dev->ibdev.post_recv = c4iw_post_receive;
Christoph Lameterb40f4752016-05-16 12:49:33 -0500602 dev->ibdev.alloc_hw_stats = c4iw_alloc_stats;
603 dev->ibdev.get_hw_stats = c4iw_get_mib;
Steve Wisec6d7b262010-09-13 11:23:57 -0500604 dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION;
Ira Weiny77386132015-05-13 20:02:58 -0400605 dev->ibdev.get_port_immutable = c4iw_port_immutable;
Ira Weinyce192242016-06-15 02:21:58 -0400606 dev->ibdev.get_dev_fw_str = get_dev_fw_str;
Steve Wise086dc6e2016-02-17 08:15:42 -0800607 dev->ibdev.drain_sq = c4iw_drain_sq;
608 dev->ibdev.drain_rq = c4iw_drain_rq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700609
610 dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
611 if (!dev->ibdev.iwcm)
612 return -ENOMEM;
613
614 dev->ibdev.iwcm->connect = c4iw_connect;
615 dev->ibdev.iwcm->accept = c4iw_accept_cr;
616 dev->ibdev.iwcm->reject = c4iw_reject_cr;
617 dev->ibdev.iwcm->create_listen = c4iw_create_listen;
618 dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen;
619 dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref;
620 dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref;
621 dev->ibdev.iwcm->get_qp = c4iw_get_qp;
Steve Wise851d7b62016-04-12 06:54:54 -0700622 memcpy(dev->ibdev.iwcm->ifname, dev->rdev.lldi.ports[0]->name,
623 sizeof(dev->ibdev.iwcm->ifname));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700624
Ralph Campbell9a6edb62010-05-06 17:03:25 -0700625 ret = ib_register_device(&dev->ibdev, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700626 if (ret)
627 goto bail1;
628
629 for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) {
630 ret = device_create_file(&dev->ibdev.dev,
631 c4iw_class_attributes[i]);
632 if (ret)
633 goto bail2;
634 }
635 return 0;
636bail2:
637 ib_unregister_device(&dev->ibdev);
638bail1:
639 kfree(dev->ibdev.iwcm);
640 return ret;
641}
642
643void c4iw_unregister_device(struct c4iw_dev *dev)
644{
645 int i;
646
647 PDBG("%s c4iw_dev %p\n", __func__, dev);
648 for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i)
649 device_remove_file(&dev->ibdev.dev,
650 c4iw_class_attributes[i]);
651 ib_unregister_device(&dev->ibdev);
652 kfree(dev->ibdev.iwcm);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700653 return;
654}