Commit | Line | Data |
---|---|---|
cfdda9d7 SW |
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 | ||
40dbf6ee | 57 | static int fastreg_support = 1; |
cfdda9d7 | 58 | module_param(fastreg_support, int, 0644); |
40dbf6ee | 59 | MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)"); |
cfdda9d7 | 60 | |
cfdda9d7 SW |
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, | |
a97e2d86 IW |
83 | u8 port_num, const struct ib_wc *in_wc, |
84 | const struct ib_grh *in_grh, | |
4cd7c947 IW |
85 | 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) | |
cfdda9d7 SW |
90 | { |
91 | return -ENOSYS; | |
92 | } | |
93 | ||
94 | static 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 | ||
108 | static 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); | |
05eb2389 SW |
113 | static int warned; |
114 | struct c4iw_alloc_ucontext_resp uresp; | |
115 | int ret = 0; | |
116 | struct c4iw_mm_entry *mm = NULL; | |
cfdda9d7 SW |
117 | |
118 | PDBG("%s ibdev %p\n", __func__, ibdev); | |
119 | context = kzalloc(sizeof(*context), GFP_KERNEL); | |
05eb2389 SW |
120 | if (!context) { |
121 | ret = -ENOMEM; | |
122 | goto err; | |
123 | } | |
124 | ||
cfdda9d7 SW |
125 | c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx); |
126 | INIT_LIST_HEAD(&context->mmaps); | |
127 | spin_lock_init(&context->mmap_lock); | |
05eb2389 | 128 | |
b7dfa889 | 129 | if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) { |
05eb2389 SW |
130 | 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); | |
bfd2793c YD |
135 | if (!mm) { |
136 | ret = -ENOMEM; | |
05eb2389 | 137 | goto err_free; |
bfd2793c | 138 | } |
05eb2389 SW |
139 | |
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 | ||
b7dfa889 YD |
147 | ret = ib_copy_to_udata(udata, &uresp, |
148 | sizeof(uresp) - sizeof(uresp.reserved)); | |
05eb2389 SW |
149 | 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 | } | |
cfdda9d7 | 157 | return &context->ibucontext; |
05eb2389 SW |
158 | err_mm: |
159 | kfree(mm); | |
160 | err_free: | |
161 | kfree(context); | |
162 | err: | |
163 | return ERR_PTR(ret); | |
cfdda9d7 SW |
164 | } |
165 | ||
166 | static 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 | ||
c6d7b267 SW |
191 | 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)))) { | |
cfdda9d7 SW |
194 | |
195 | /* | |
c6d7b267 | 196 | * MA_SYNC register... |
cfdda9d7 | 197 | */ |
cfdda9d7 | 198 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
c6d7b267 SW |
199 | 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); | |
f079af7a | 211 | else { |
963cab50 | 212 | if (!is_t4(rdev->lldi.adapter_type)) |
f079af7a VP |
213 | 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 | } | |
cfdda9d7 SW |
219 | 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 | ||
235 | static 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); | |
ec3eead2 | 243 | c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid); |
8d81ef34 VP |
244 | mutex_lock(&rhp->rdev.stats.lock); |
245 | rhp->rdev.stats.pd.cur--; | |
246 | mutex_unlock(&rhp->rdev.stats.lock); | |
cfdda9d7 SW |
247 | kfree(php); |
248 | return 0; | |
249 | } | |
250 | ||
251 | static 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; | |
ec3eead2 | 261 | pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table); |
cfdda9d7 SW |
262 | if (!pdid) |
263 | return ERR_PTR(-EINVAL); | |
264 | php = kzalloc(sizeof(*php), GFP_KERNEL); | |
265 | if (!php) { | |
ec3eead2 | 266 | c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid); |
cfdda9d7 SW |
267 | 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 | } | |
8d81ef34 VP |
277 | 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); | |
cfdda9d7 SW |
282 | PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php); |
283 | return &php->ibpd; | |
284 | } | |
285 | ||
286 | static 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 | ||
294 | static 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 | ||
2528e33e MB |
308 | static int c4iw_query_device(struct ib_device *ibdev, struct ib_device_attr *props, |
309 | struct ib_udata *uhw) | |
cfdda9d7 SW |
310 | { |
311 | ||
312 | struct c4iw_dev *dev; | |
2528e33e | 313 | |
cfdda9d7 SW |
314 | PDBG("%s ibdev %p\n", __func__, ibdev); |
315 | ||
2528e33e MB |
316 | if (uhw->inlen || uhw->outlen) |
317 | return -EINVAL; | |
318 | ||
cfdda9d7 SW |
319 | 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); | |
f079af7a | 322 | props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type); |
cfdda9d7 SW |
323 | 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; | |
66eb19af | 329 | props->max_qp = dev->rdev.lldi.vr->qp.size / 2; |
04e10e21 | 330 | props->max_qp_wr = dev->rdev.hw_queue.t4_max_qp_depth; |
cfdda9d7 SW |
331 | props->max_sge = T4_MAX_RECV_SGE; |
332 | props->max_sge_rd = 1; | |
4c2c5763 HS |
333 | 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; | |
66eb19af | 337 | props->max_cq = dev->rdev.lldi.vr->qp.size; |
04e10e21 | 338 | props->max_cqe = dev->rdev.hw_queue.t4_max_cq_depth; |
cfdda9d7 SW |
339 | props->max_mr = c4iw_num_stags(&dev->rdev); |
340 | props->max_pd = T4_MAX_NUM_PD; | |
341 | props->local_ca_ack_delay = 0; | |
a03d9f94 | 342 | props->max_fast_reg_page_list_len = t4_max_fr_depth(use_dsgl); |
cfdda9d7 SW |
343 | |
344 | return 0; | |
345 | } | |
346 | ||
347 | static int c4iw_query_port(struct ib_device *ibdev, u8 port, | |
348 | struct ib_port_attr *props) | |
349 | { | |
350 | struct c4iw_dev *dev; | |
351 | struct net_device *netdev; | |
352 | struct in_device *inetdev; | |
353 | ||
354 | PDBG("%s ibdev %p\n", __func__, ibdev); | |
355 | ||
356 | dev = to_c4iw_dev(ibdev); | |
357 | netdev = dev->rdev.lldi.ports[port-1]; | |
358 | ||
359 | memset(props, 0, sizeof(struct ib_port_attr)); | |
360 | props->max_mtu = IB_MTU_4096; | |
361 | if (netdev->mtu >= 4096) | |
362 | props->active_mtu = IB_MTU_4096; | |
363 | else if (netdev->mtu >= 2048) | |
364 | props->active_mtu = IB_MTU_2048; | |
365 | else if (netdev->mtu >= 1024) | |
366 | props->active_mtu = IB_MTU_1024; | |
367 | else if (netdev->mtu >= 512) | |
368 | props->active_mtu = IB_MTU_512; | |
369 | else | |
370 | props->active_mtu = IB_MTU_256; | |
371 | ||
372 | if (!netif_carrier_ok(netdev)) | |
373 | props->state = IB_PORT_DOWN; | |
374 | else { | |
375 | inetdev = in_dev_get(netdev); | |
376 | if (inetdev) { | |
377 | if (inetdev->ifa_list) | |
378 | props->state = IB_PORT_ACTIVE; | |
379 | else | |
380 | props->state = IB_PORT_INIT; | |
381 | in_dev_put(inetdev); | |
382 | } else | |
383 | props->state = IB_PORT_INIT; | |
384 | } | |
385 | ||
386 | props->port_cap_flags = | |
387 | IB_PORT_CM_SUP | | |
388 | IB_PORT_SNMP_TUNNEL_SUP | | |
389 | IB_PORT_REINIT_SUP | | |
390 | IB_PORT_DEVICE_MGMT_SUP | | |
391 | IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP; | |
392 | props->gid_tbl_len = 1; | |
393 | props->pkey_tbl_len = 1; | |
394 | props->active_width = 2; | |
2e96691c | 395 | props->active_speed = IB_SPEED_DDR; |
cfdda9d7 SW |
396 | props->max_msg_sz = -1; |
397 | ||
398 | return 0; | |
399 | } | |
400 | ||
401 | static ssize_t show_rev(struct device *dev, struct device_attribute *attr, | |
402 | char *buf) | |
403 | { | |
404 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, | |
405 | ibdev.dev); | |
406 | PDBG("%s dev 0x%p\n", __func__, dev); | |
f079af7a VP |
407 | return sprintf(buf, "%d\n", |
408 | CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type)); | |
cfdda9d7 SW |
409 | } |
410 | ||
411 | static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr, | |
412 | char *buf) | |
413 | { | |
414 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, | |
415 | ibdev.dev); | |
416 | PDBG("%s dev 0x%p\n", __func__, dev); | |
417 | ||
418 | return sprintf(buf, "%u.%u.%u.%u\n", | |
b2e1a3f0 HS |
419 | FW_HDR_FW_VER_MAJOR_G(c4iw_dev->rdev.lldi.fw_vers), |
420 | FW_HDR_FW_VER_MINOR_G(c4iw_dev->rdev.lldi.fw_vers), | |
421 | FW_HDR_FW_VER_MICRO_G(c4iw_dev->rdev.lldi.fw_vers), | |
422 | FW_HDR_FW_VER_BUILD_G(c4iw_dev->rdev.lldi.fw_vers)); | |
cfdda9d7 SW |
423 | } |
424 | ||
425 | static ssize_t show_hca(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 | struct ethtool_drvinfo info; | |
431 | struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0]; | |
432 | ||
433 | PDBG("%s dev 0x%p\n", __func__, dev); | |
434 | lldev->ethtool_ops->get_drvinfo(lldev, &info); | |
435 | return sprintf(buf, "%s\n", info.driver); | |
436 | } | |
437 | ||
438 | static ssize_t show_board(struct device *dev, struct device_attribute *attr, | |
439 | char *buf) | |
440 | { | |
441 | struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev, | |
442 | ibdev.dev); | |
443 | PDBG("%s dev 0x%p\n", __func__, dev); | |
444 | return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor, | |
445 | c4iw_dev->rdev.lldi.pdev->device); | |
446 | } | |
447 | ||
448 | static int c4iw_get_mib(struct ib_device *ibdev, | |
449 | union rdma_protocol_stats *stats) | |
450 | { | |
de5dd81b SW |
451 | struct tp_tcp_stats v4, v6; |
452 | struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev); | |
453 | ||
454 | cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6); | |
455 | memset(stats, 0, sizeof *stats); | |
a4cfd929 HS |
456 | stats->iw.tcpInSegs = v4.tcp_in_segs + v6.tcp_in_segs; |
457 | stats->iw.tcpOutSegs = v4.tcp_out_segs + v6.tcp_out_segs; | |
458 | stats->iw.tcpRetransSegs = v4.tcp_retrans_segs + v6.tcp_retrans_segs; | |
459 | stats->iw.tcpOutRsts = v4.tcp_out_rsts + v6.tcp_out_rsts; | |
de5dd81b SW |
460 | |
461 | return 0; | |
cfdda9d7 SW |
462 | } |
463 | ||
464 | static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); | |
465 | static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); | |
466 | static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); | |
467 | static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); | |
468 | ||
469 | static struct device_attribute *c4iw_class_attributes[] = { | |
470 | &dev_attr_hw_rev, | |
471 | &dev_attr_fw_ver, | |
472 | &dev_attr_hca_type, | |
473 | &dev_attr_board_id, | |
474 | }; | |
475 | ||
7738613e IW |
476 | static int c4iw_port_immutable(struct ib_device *ibdev, u8 port_num, |
477 | struct ib_port_immutable *immutable) | |
478 | { | |
479 | struct ib_port_attr attr; | |
480 | int err; | |
481 | ||
482 | err = c4iw_query_port(ibdev, port_num, &attr); | |
483 | if (err) | |
484 | return err; | |
485 | ||
486 | immutable->pkey_tbl_len = attr.pkey_tbl_len; | |
487 | immutable->gid_tbl_len = attr.gid_tbl_len; | |
f9b22e35 | 488 | immutable->core_cap_flags = RDMA_CORE_PORT_IWARP; |
7738613e IW |
489 | |
490 | return 0; | |
491 | } | |
492 | ||
cfdda9d7 SW |
493 | int c4iw_register_device(struct c4iw_dev *dev) |
494 | { | |
495 | int ret; | |
496 | int i; | |
497 | ||
498 | PDBG("%s c4iw_dev %p\n", __func__, dev); | |
499 | BUG_ON(!dev->rdev.lldi.ports[0]); | |
500 | strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX); | |
501 | memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid)); | |
502 | memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6); | |
503 | dev->ibdev.owner = THIS_MODULE; | |
504 | dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW; | |
505 | if (fastreg_support) | |
506 | dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS; | |
507 | dev->ibdev.local_dma_lkey = 0; | |
508 | dev->ibdev.uverbs_cmd_mask = | |
509 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | | |
510 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | | |
511 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | | |
512 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | | |
513 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | | |
514 | (1ull << IB_USER_VERBS_CMD_REG_MR) | | |
515 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | | |
516 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | | |
517 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | | |
518 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | | |
519 | (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | | |
520 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | | |
521 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | | |
67bbc055 | 522 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | |
cfdda9d7 SW |
523 | (1ull << IB_USER_VERBS_CMD_POLL_CQ) | |
524 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | | |
525 | (1ull << IB_USER_VERBS_CMD_POST_SEND) | | |
526 | (1ull << IB_USER_VERBS_CMD_POST_RECV); | |
527 | dev->ibdev.node_type = RDMA_NODE_RNIC; | |
528 | memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC)); | |
529 | dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports; | |
cf38be6d | 530 | dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq; |
cfdda9d7 SW |
531 | dev->ibdev.dma_device = &(dev->rdev.lldi.pdev->dev); |
532 | dev->ibdev.query_device = c4iw_query_device; | |
533 | dev->ibdev.query_port = c4iw_query_port; | |
cfdda9d7 SW |
534 | dev->ibdev.query_pkey = c4iw_query_pkey; |
535 | dev->ibdev.query_gid = c4iw_query_gid; | |
536 | dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext; | |
537 | dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext; | |
538 | dev->ibdev.mmap = c4iw_mmap; | |
539 | dev->ibdev.alloc_pd = c4iw_allocate_pd; | |
540 | dev->ibdev.dealloc_pd = c4iw_deallocate_pd; | |
541 | dev->ibdev.create_ah = c4iw_ah_create; | |
542 | dev->ibdev.destroy_ah = c4iw_ah_destroy; | |
543 | dev->ibdev.create_qp = c4iw_create_qp; | |
544 | dev->ibdev.modify_qp = c4iw_ib_modify_qp; | |
67bbc055 | 545 | dev->ibdev.query_qp = c4iw_ib_query_qp; |
cfdda9d7 SW |
546 | dev->ibdev.destroy_qp = c4iw_destroy_qp; |
547 | dev->ibdev.create_cq = c4iw_create_cq; | |
548 | dev->ibdev.destroy_cq = c4iw_destroy_cq; | |
549 | dev->ibdev.resize_cq = c4iw_resize_cq; | |
550 | dev->ibdev.poll_cq = c4iw_poll_cq; | |
551 | dev->ibdev.get_dma_mr = c4iw_get_dma_mr; | |
cfdda9d7 SW |
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; | |
cfdda9d7 | 555 | dev->ibdev.dealloc_mw = c4iw_dealloc_mw; |
a2164034 | 556 | dev->ibdev.alloc_mr = c4iw_alloc_mr; |
8376b86d | 557 | dev->ibdev.map_mr_sg = c4iw_map_mr_sg; |
cfdda9d7 SW |
558 | dev->ibdev.attach_mcast = c4iw_multicast_attach; |
559 | dev->ibdev.detach_mcast = c4iw_multicast_detach; | |
560 | dev->ibdev.process_mad = c4iw_process_mad; | |
561 | dev->ibdev.req_notify_cq = c4iw_arm_cq; | |
562 | dev->ibdev.post_send = c4iw_post_send; | |
563 | dev->ibdev.post_recv = c4iw_post_receive; | |
564 | dev->ibdev.get_protocol_stats = c4iw_get_mib; | |
c6d7b267 | 565 | dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION; |
7738613e | 566 | dev->ibdev.get_port_immutable = c4iw_port_immutable; |
086dc6e3 SW |
567 | dev->ibdev.drain_sq = c4iw_drain_sq; |
568 | dev->ibdev.drain_rq = c4iw_drain_rq; | |
cfdda9d7 SW |
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 | ||
9a6edb60 | 583 | ret = ib_register_device(&dev->ibdev, NULL); |
cfdda9d7 SW |
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); | |
611 | return; | |
612 | } |