diff options
Diffstat (limited to 'drivers/infiniband/hw/amso1100/c2_provider.c')
-rw-r--r-- | drivers/infiniband/hw/amso1100/c2_provider.c | 869 |
1 files changed, 869 insertions, 0 deletions
diff --git a/drivers/infiniband/hw/amso1100/c2_provider.c b/drivers/infiniband/hw/amso1100/c2_provider.c new file mode 100644 index 000000000000..8fddc8cccdf3 --- /dev/null +++ b/drivers/infiniband/hw/amso1100/c2_provider.c | |||
@@ -0,0 +1,869 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2005 Ammasso, Inc. All rights reserved. | ||
3 | * Copyright (c) 2005 Open Grid Computing, Inc. All rights reserved. | ||
4 | * | ||
5 | * This software is available to you under a choice of one of two | ||
6 | * licenses. You may choose to be licensed under the terms of the GNU | ||
7 | * General Public License (GPL) Version 2, available from the file | ||
8 | * COPYING in the main directory of this source tree, or the | ||
9 | * OpenIB.org BSD license below: | ||
10 | * | ||
11 | * Redistribution and use in source and binary forms, with or | ||
12 | * without modification, are permitted provided that the following | ||
13 | * conditions are met: | ||
14 | * | ||
15 | * - Redistributions of source code must retain the above | ||
16 | * copyright notice, this list of conditions and the following | ||
17 | * disclaimer. | ||
18 | * | ||
19 | * - Redistributions in binary form must reproduce the above | ||
20 | * copyright notice, this list of conditions and the following | ||
21 | * disclaimer in the documentation and/or other materials | ||
22 | * provided with the distribution. | ||
23 | * | ||
24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
31 | * SOFTWARE. | ||
32 | * | ||
33 | */ | ||
34 | |||
35 | #include <linux/module.h> | ||
36 | #include <linux/moduleparam.h> | ||
37 | #include <linux/pci.h> | ||
38 | #include <linux/netdevice.h> | ||
39 | #include <linux/etherdevice.h> | ||
40 | #include <linux/inetdevice.h> | ||
41 | #include <linux/delay.h> | ||
42 | #include <linux/ethtool.h> | ||
43 | #include <linux/mii.h> | ||
44 | #include <linux/if_vlan.h> | ||
45 | #include <linux/crc32.h> | ||
46 | #include <linux/in.h> | ||
47 | #include <linux/ip.h> | ||
48 | #include <linux/tcp.h> | ||
49 | #include <linux/init.h> | ||
50 | #include <linux/dma-mapping.h> | ||
51 | #include <linux/if_arp.h> | ||
52 | |||
53 | #include <asm/io.h> | ||
54 | #include <asm/irq.h> | ||
55 | #include <asm/byteorder.h> | ||
56 | |||
57 | #include <rdma/ib_smi.h> | ||
58 | #include <rdma/ib_user_verbs.h> | ||
59 | #include "c2.h" | ||
60 | #include "c2_provider.h" | ||
61 | #include "c2_user.h" | ||
62 | |||
63 | static int c2_query_device(struct ib_device *ibdev, | ||
64 | struct ib_device_attr *props) | ||
65 | { | ||
66 | struct c2_dev *c2dev = to_c2dev(ibdev); | ||
67 | |||
68 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
69 | |||
70 | *props = c2dev->props; | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static int c2_query_port(struct ib_device *ibdev, | ||
75 | u8 port, struct ib_port_attr *props) | ||
76 | { | ||
77 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
78 | |||
79 | props->max_mtu = IB_MTU_4096; | ||
80 | props->lid = 0; | ||
81 | props->lmc = 0; | ||
82 | props->sm_lid = 0; | ||
83 | props->sm_sl = 0; | ||
84 | props->state = IB_PORT_ACTIVE; | ||
85 | props->phys_state = 0; | ||
86 | props->port_cap_flags = | ||
87 | IB_PORT_CM_SUP | | ||
88 | IB_PORT_REINIT_SUP | | ||
89 | IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP; | ||
90 | props->gid_tbl_len = 1; | ||
91 | props->pkey_tbl_len = 1; | ||
92 | props->qkey_viol_cntr = 0; | ||
93 | props->active_width = 1; | ||
94 | props->active_speed = 1; | ||
95 | |||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | static int c2_modify_port(struct ib_device *ibdev, | ||
100 | u8 port, int port_modify_mask, | ||
101 | struct ib_port_modify *props) | ||
102 | { | ||
103 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int c2_query_pkey(struct ib_device *ibdev, | ||
108 | u8 port, u16 index, u16 * pkey) | ||
109 | { | ||
110 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
111 | *pkey = 0; | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | static int c2_query_gid(struct ib_device *ibdev, u8 port, | ||
116 | int index, union ib_gid *gid) | ||
117 | { | ||
118 | struct c2_dev *c2dev = to_c2dev(ibdev); | ||
119 | |||
120 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
121 | memset(&(gid->raw[0]), 0, sizeof(gid->raw)); | ||
122 | memcpy(&(gid->raw[0]), c2dev->pseudo_netdev->dev_addr, 6); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | /* Allocate the user context data structure. This keeps track | ||
128 | * of all objects associated with a particular user-mode client. | ||
129 | */ | ||
130 | static struct ib_ucontext *c2_alloc_ucontext(struct ib_device *ibdev, | ||
131 | struct ib_udata *udata) | ||
132 | { | ||
133 | struct c2_ucontext *context; | ||
134 | |||
135 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
136 | context = kmalloc(sizeof(*context), GFP_KERNEL); | ||
137 | if (!context) | ||
138 | return ERR_PTR(-ENOMEM); | ||
139 | |||
140 | return &context->ibucontext; | ||
141 | } | ||
142 | |||
143 | static int c2_dealloc_ucontext(struct ib_ucontext *context) | ||
144 | { | ||
145 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
146 | kfree(context); | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | static int c2_mmap_uar(struct ib_ucontext *context, struct vm_area_struct *vma) | ||
151 | { | ||
152 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
153 | return -ENOSYS; | ||
154 | } | ||
155 | |||
156 | static struct ib_pd *c2_alloc_pd(struct ib_device *ibdev, | ||
157 | struct ib_ucontext *context, | ||
158 | struct ib_udata *udata) | ||
159 | { | ||
160 | struct c2_pd *pd; | ||
161 | int err; | ||
162 | |||
163 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
164 | |||
165 | pd = kmalloc(sizeof(*pd), GFP_KERNEL); | ||
166 | if (!pd) | ||
167 | return ERR_PTR(-ENOMEM); | ||
168 | |||
169 | err = c2_pd_alloc(to_c2dev(ibdev), !context, pd); | ||
170 | if (err) { | ||
171 | kfree(pd); | ||
172 | return ERR_PTR(err); | ||
173 | } | ||
174 | |||
175 | if (context) { | ||
176 | if (ib_copy_to_udata(udata, &pd->pd_id, sizeof(__u32))) { | ||
177 | c2_pd_free(to_c2dev(ibdev), pd); | ||
178 | kfree(pd); | ||
179 | return ERR_PTR(-EFAULT); | ||
180 | } | ||
181 | } | ||
182 | |||
183 | return &pd->ibpd; | ||
184 | } | ||
185 | |||
186 | static int c2_dealloc_pd(struct ib_pd *pd) | ||
187 | { | ||
188 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
189 | c2_pd_free(to_c2dev(pd->device), to_c2pd(pd)); | ||
190 | kfree(pd); | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | static struct ib_ah *c2_ah_create(struct ib_pd *pd, struct ib_ah_attr *ah_attr) | ||
196 | { | ||
197 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
198 | return ERR_PTR(-ENOSYS); | ||
199 | } | ||
200 | |||
201 | static int c2_ah_destroy(struct ib_ah *ah) | ||
202 | { | ||
203 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
204 | return -ENOSYS; | ||
205 | } | ||
206 | |||
207 | static void c2_add_ref(struct ib_qp *ibqp) | ||
208 | { | ||
209 | struct c2_qp *qp; | ||
210 | BUG_ON(!ibqp); | ||
211 | qp = to_c2qp(ibqp); | ||
212 | atomic_inc(&qp->refcount); | ||
213 | } | ||
214 | |||
215 | static void c2_rem_ref(struct ib_qp *ibqp) | ||
216 | { | ||
217 | struct c2_qp *qp; | ||
218 | BUG_ON(!ibqp); | ||
219 | qp = to_c2qp(ibqp); | ||
220 | if (atomic_dec_and_test(&qp->refcount)) | ||
221 | wake_up(&qp->wait); | ||
222 | } | ||
223 | |||
224 | struct ib_qp *c2_get_qp(struct ib_device *device, int qpn) | ||
225 | { | ||
226 | struct c2_dev* c2dev = to_c2dev(device); | ||
227 | struct c2_qp *qp; | ||
228 | |||
229 | qp = c2_find_qpn(c2dev, qpn); | ||
230 | pr_debug("%s Returning QP=%p for QPN=%d, device=%p, refcount=%d\n", | ||
231 | __FUNCTION__, qp, qpn, device, | ||
232 | (qp?atomic_read(&qp->refcount):0)); | ||
233 | |||
234 | return (qp?&qp->ibqp:NULL); | ||
235 | } | ||
236 | |||
237 | static struct ib_qp *c2_create_qp(struct ib_pd *pd, | ||
238 | struct ib_qp_init_attr *init_attr, | ||
239 | struct ib_udata *udata) | ||
240 | { | ||
241 | struct c2_qp *qp; | ||
242 | int err; | ||
243 | |||
244 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
245 | |||
246 | switch (init_attr->qp_type) { | ||
247 | case IB_QPT_RC: | ||
248 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); | ||
249 | if (!qp) { | ||
250 | pr_debug("%s: Unable to allocate QP\n", __FUNCTION__); | ||
251 | return ERR_PTR(-ENOMEM); | ||
252 | } | ||
253 | spin_lock_init(&qp->lock); | ||
254 | if (pd->uobject) { | ||
255 | /* userspace specific */ | ||
256 | } | ||
257 | |||
258 | err = c2_alloc_qp(to_c2dev(pd->device), | ||
259 | to_c2pd(pd), init_attr, qp); | ||
260 | |||
261 | if (err && pd->uobject) { | ||
262 | /* userspace specific */ | ||
263 | } | ||
264 | |||
265 | break; | ||
266 | default: | ||
267 | pr_debug("%s: Invalid QP type: %d\n", __FUNCTION__, | ||
268 | init_attr->qp_type); | ||
269 | return ERR_PTR(-EINVAL); | ||
270 | break; | ||
271 | } | ||
272 | |||
273 | if (err) { | ||
274 | kfree(qp); | ||
275 | return ERR_PTR(err); | ||
276 | } | ||
277 | |||
278 | return &qp->ibqp; | ||
279 | } | ||
280 | |||
281 | static int c2_destroy_qp(struct ib_qp *ib_qp) | ||
282 | { | ||
283 | struct c2_qp *qp = to_c2qp(ib_qp); | ||
284 | |||
285 | pr_debug("%s:%u qp=%p,qp->state=%d\n", | ||
286 | __FUNCTION__, __LINE__,ib_qp,qp->state); | ||
287 | c2_free_qp(to_c2dev(ib_qp->device), qp); | ||
288 | kfree(qp); | ||
289 | return 0; | ||
290 | } | ||
291 | |||
292 | static struct ib_cq *c2_create_cq(struct ib_device *ibdev, int entries, | ||
293 | struct ib_ucontext *context, | ||
294 | struct ib_udata *udata) | ||
295 | { | ||
296 | struct c2_cq *cq; | ||
297 | int err; | ||
298 | |||
299 | cq = kmalloc(sizeof(*cq), GFP_KERNEL); | ||
300 | if (!cq) { | ||
301 | pr_debug("%s: Unable to allocate CQ\n", __FUNCTION__); | ||
302 | return ERR_PTR(-ENOMEM); | ||
303 | } | ||
304 | |||
305 | err = c2_init_cq(to_c2dev(ibdev), entries, NULL, cq); | ||
306 | if (err) { | ||
307 | pr_debug("%s: error initializing CQ\n", __FUNCTION__); | ||
308 | kfree(cq); | ||
309 | return ERR_PTR(err); | ||
310 | } | ||
311 | |||
312 | return &cq->ibcq; | ||
313 | } | ||
314 | |||
315 | static int c2_destroy_cq(struct ib_cq *ib_cq) | ||
316 | { | ||
317 | struct c2_cq *cq = to_c2cq(ib_cq); | ||
318 | |||
319 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
320 | |||
321 | c2_free_cq(to_c2dev(ib_cq->device), cq); | ||
322 | kfree(cq); | ||
323 | |||
324 | return 0; | ||
325 | } | ||
326 | |||
327 | static inline u32 c2_convert_access(int acc) | ||
328 | { | ||
329 | return (acc & IB_ACCESS_REMOTE_WRITE ? C2_ACF_REMOTE_WRITE : 0) | | ||
330 | (acc & IB_ACCESS_REMOTE_READ ? C2_ACF_REMOTE_READ : 0) | | ||
331 | (acc & IB_ACCESS_LOCAL_WRITE ? C2_ACF_LOCAL_WRITE : 0) | | ||
332 | C2_ACF_LOCAL_READ | C2_ACF_WINDOW_BIND; | ||
333 | } | ||
334 | |||
335 | static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd, | ||
336 | struct ib_phys_buf *buffer_list, | ||
337 | int num_phys_buf, int acc, u64 * iova_start) | ||
338 | { | ||
339 | struct c2_mr *mr; | ||
340 | u64 *page_list; | ||
341 | u32 total_len; | ||
342 | int err, i, j, k, page_shift, pbl_depth; | ||
343 | |||
344 | pbl_depth = 0; | ||
345 | total_len = 0; | ||
346 | |||
347 | page_shift = PAGE_SHIFT; | ||
348 | /* | ||
349 | * If there is only 1 buffer we assume this could | ||
350 | * be a map of all phy mem...use a 32k page_shift. | ||
351 | */ | ||
352 | if (num_phys_buf == 1) | ||
353 | page_shift += 3; | ||
354 | |||
355 | for (i = 0; i < num_phys_buf; i++) { | ||
356 | |||
357 | if (buffer_list[i].addr & ~PAGE_MASK) { | ||
358 | pr_debug("Unaligned Memory Buffer: 0x%x\n", | ||
359 | (unsigned int) buffer_list[i].addr); | ||
360 | return ERR_PTR(-EINVAL); | ||
361 | } | ||
362 | |||
363 | if (!buffer_list[i].size) { | ||
364 | pr_debug("Invalid Buffer Size\n"); | ||
365 | return ERR_PTR(-EINVAL); | ||
366 | } | ||
367 | |||
368 | total_len += buffer_list[i].size; | ||
369 | pbl_depth += ALIGN(buffer_list[i].size, | ||
370 | (1 << page_shift)) >> page_shift; | ||
371 | } | ||
372 | |||
373 | page_list = vmalloc(sizeof(u64) * pbl_depth); | ||
374 | if (!page_list) { | ||
375 | pr_debug("couldn't vmalloc page_list of size %zd\n", | ||
376 | (sizeof(u64) * pbl_depth)); | ||
377 | return ERR_PTR(-ENOMEM); | ||
378 | } | ||
379 | |||
380 | for (i = 0, j = 0; i < num_phys_buf; i++) { | ||
381 | |||
382 | int naddrs; | ||
383 | |||
384 | naddrs = ALIGN(buffer_list[i].size, | ||
385 | (1 << page_shift)) >> page_shift; | ||
386 | for (k = 0; k < naddrs; k++) | ||
387 | page_list[j++] = (buffer_list[i].addr + | ||
388 | (k << page_shift)); | ||
389 | } | ||
390 | |||
391 | mr = kmalloc(sizeof(*mr), GFP_KERNEL); | ||
392 | if (!mr) | ||
393 | return ERR_PTR(-ENOMEM); | ||
394 | |||
395 | mr->pd = to_c2pd(ib_pd); | ||
396 | pr_debug("%s - page shift %d, pbl_depth %d, total_len %u, " | ||
397 | "*iova_start %llx, first pa %llx, last pa %llx\n", | ||
398 | __FUNCTION__, page_shift, pbl_depth, total_len, | ||
399 | *iova_start, page_list[0], page_list[pbl_depth-1]); | ||
400 | err = c2_nsmr_register_phys_kern(to_c2dev(ib_pd->device), page_list, | ||
401 | (1 << page_shift), pbl_depth, | ||
402 | total_len, 0, iova_start, | ||
403 | c2_convert_access(acc), mr); | ||
404 | vfree(page_list); | ||
405 | if (err) { | ||
406 | kfree(mr); | ||
407 | return ERR_PTR(err); | ||
408 | } | ||
409 | |||
410 | return &mr->ibmr; | ||
411 | } | ||
412 | |||
413 | static struct ib_mr *c2_get_dma_mr(struct ib_pd *pd, int acc) | ||
414 | { | ||
415 | struct ib_phys_buf bl; | ||
416 | u64 kva = 0; | ||
417 | |||
418 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
419 | |||
420 | /* AMSO1100 limit */ | ||
421 | bl.size = 0xffffffff; | ||
422 | bl.addr = 0; | ||
423 | return c2_reg_phys_mr(pd, &bl, 1, acc, &kva); | ||
424 | } | ||
425 | |||
426 | static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, struct ib_umem *region, | ||
427 | int acc, struct ib_udata *udata) | ||
428 | { | ||
429 | u64 *pages; | ||
430 | u64 kva = 0; | ||
431 | int shift, n, len; | ||
432 | int i, j, k; | ||
433 | int err = 0; | ||
434 | struct ib_umem_chunk *chunk; | ||
435 | struct c2_pd *c2pd = to_c2pd(pd); | ||
436 | struct c2_mr *c2mr; | ||
437 | |||
438 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
439 | shift = ffs(region->page_size) - 1; | ||
440 | |||
441 | c2mr = kmalloc(sizeof(*c2mr), GFP_KERNEL); | ||
442 | if (!c2mr) | ||
443 | return ERR_PTR(-ENOMEM); | ||
444 | c2mr->pd = c2pd; | ||
445 | |||
446 | n = 0; | ||
447 | list_for_each_entry(chunk, ®ion->chunk_list, list) | ||
448 | n += chunk->nents; | ||
449 | |||
450 | pages = kmalloc(n * sizeof(u64), GFP_KERNEL); | ||
451 | if (!pages) { | ||
452 | err = -ENOMEM; | ||
453 | goto err; | ||
454 | } | ||
455 | |||
456 | i = 0; | ||
457 | list_for_each_entry(chunk, ®ion->chunk_list, list) { | ||
458 | for (j = 0; j < chunk->nmap; ++j) { | ||
459 | len = sg_dma_len(&chunk->page_list[j]) >> shift; | ||
460 | for (k = 0; k < len; ++k) { | ||
461 | pages[i++] = | ||
462 | sg_dma_address(&chunk->page_list[j]) + | ||
463 | (region->page_size * k); | ||
464 | } | ||
465 | } | ||
466 | } | ||
467 | |||
468 | kva = (u64)region->virt_base; | ||
469 | err = c2_nsmr_register_phys_kern(to_c2dev(pd->device), | ||
470 | pages, | ||
471 | region->page_size, | ||
472 | i, | ||
473 | region->length, | ||
474 | region->offset, | ||
475 | &kva, | ||
476 | c2_convert_access(acc), | ||
477 | c2mr); | ||
478 | kfree(pages); | ||
479 | if (err) { | ||
480 | kfree(c2mr); | ||
481 | return ERR_PTR(err); | ||
482 | } | ||
483 | return &c2mr->ibmr; | ||
484 | |||
485 | err: | ||
486 | kfree(c2mr); | ||
487 | return ERR_PTR(err); | ||
488 | } | ||
489 | |||
490 | static int c2_dereg_mr(struct ib_mr *ib_mr) | ||
491 | { | ||
492 | struct c2_mr *mr = to_c2mr(ib_mr); | ||
493 | int err; | ||
494 | |||
495 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
496 | |||
497 | err = c2_stag_dealloc(to_c2dev(ib_mr->device), ib_mr->lkey); | ||
498 | if (err) | ||
499 | pr_debug("c2_stag_dealloc failed: %d\n", err); | ||
500 | else | ||
501 | kfree(mr); | ||
502 | |||
503 | return err; | ||
504 | } | ||
505 | |||
506 | static ssize_t show_rev(struct class_device *cdev, char *buf) | ||
507 | { | ||
508 | struct c2_dev *dev = container_of(cdev, struct c2_dev, ibdev.class_dev); | ||
509 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
510 | return sprintf(buf, "%x\n", dev->props.hw_ver); | ||
511 | } | ||
512 | |||
513 | static ssize_t show_fw_ver(struct class_device *cdev, char *buf) | ||
514 | { | ||
515 | struct c2_dev *dev = container_of(cdev, struct c2_dev, ibdev.class_dev); | ||
516 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
517 | return sprintf(buf, "%x.%x.%x\n", | ||
518 | (int) (dev->props.fw_ver >> 32), | ||
519 | (int) (dev->props.fw_ver >> 16) & 0xffff, | ||
520 | (int) (dev->props.fw_ver & 0xffff)); | ||
521 | } | ||
522 | |||
523 | static ssize_t show_hca(struct class_device *cdev, char *buf) | ||
524 | { | ||
525 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
526 | return sprintf(buf, "AMSO1100\n"); | ||
527 | } | ||
528 | |||
529 | static ssize_t show_board(struct class_device *cdev, char *buf) | ||
530 | { | ||
531 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
532 | return sprintf(buf, "%.*s\n", 32, "AMSO1100 Board ID"); | ||
533 | } | ||
534 | |||
535 | static CLASS_DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL); | ||
536 | static CLASS_DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL); | ||
537 | static CLASS_DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL); | ||
538 | static CLASS_DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL); | ||
539 | |||
540 | static struct class_device_attribute *c2_class_attributes[] = { | ||
541 | &class_device_attr_hw_rev, | ||
542 | &class_device_attr_fw_ver, | ||
543 | &class_device_attr_hca_type, | ||
544 | &class_device_attr_board_id | ||
545 | }; | ||
546 | |||
547 | static int c2_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, | ||
548 | int attr_mask, struct ib_udata *udata) | ||
549 | { | ||
550 | int err; | ||
551 | |||
552 | err = | ||
553 | c2_qp_modify(to_c2dev(ibqp->device), to_c2qp(ibqp), attr, | ||
554 | attr_mask); | ||
555 | |||
556 | return err; | ||
557 | } | ||
558 | |||
559 | static int c2_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) | ||
560 | { | ||
561 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
562 | return -ENOSYS; | ||
563 | } | ||
564 | |||
565 | static int c2_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid) | ||
566 | { | ||
567 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
568 | return -ENOSYS; | ||
569 | } | ||
570 | |||
571 | static int c2_process_mad(struct ib_device *ibdev, | ||
572 | int mad_flags, | ||
573 | u8 port_num, | ||
574 | struct ib_wc *in_wc, | ||
575 | struct ib_grh *in_grh, | ||
576 | struct ib_mad *in_mad, struct ib_mad *out_mad) | ||
577 | { | ||
578 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
579 | return -ENOSYS; | ||
580 | } | ||
581 | |||
582 | static int c2_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param) | ||
583 | { | ||
584 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
585 | |||
586 | /* Request a connection */ | ||
587 | return c2_llp_connect(cm_id, iw_param); | ||
588 | } | ||
589 | |||
590 | static int c2_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *iw_param) | ||
591 | { | ||
592 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
593 | |||
594 | /* Accept the new connection */ | ||
595 | return c2_llp_accept(cm_id, iw_param); | ||
596 | } | ||
597 | |||
598 | static int c2_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len) | ||
599 | { | ||
600 | int err; | ||
601 | |||
602 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
603 | |||
604 | err = c2_llp_reject(cm_id, pdata, pdata_len); | ||
605 | return err; | ||
606 | } | ||
607 | |||
608 | static int c2_service_create(struct iw_cm_id *cm_id, int backlog) | ||
609 | { | ||
610 | int err; | ||
611 | |||
612 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
613 | err = c2_llp_service_create(cm_id, backlog); | ||
614 | pr_debug("%s:%u err=%d\n", | ||
615 | __FUNCTION__, __LINE__, | ||
616 | err); | ||
617 | return err; | ||
618 | } | ||
619 | |||
620 | static int c2_service_destroy(struct iw_cm_id *cm_id) | ||
621 | { | ||
622 | int err; | ||
623 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
624 | |||
625 | err = c2_llp_service_destroy(cm_id); | ||
626 | |||
627 | return err; | ||
628 | } | ||
629 | |||
630 | static int c2_pseudo_up(struct net_device *netdev) | ||
631 | { | ||
632 | struct in_device *ind; | ||
633 | struct c2_dev *c2dev = netdev->priv; | ||
634 | |||
635 | ind = in_dev_get(netdev); | ||
636 | if (!ind) | ||
637 | return 0; | ||
638 | |||
639 | pr_debug("adding...\n"); | ||
640 | for_ifa(ind) { | ||
641 | #ifdef DEBUG | ||
642 | u8 *ip = (u8 *) & ifa->ifa_address; | ||
643 | |||
644 | pr_debug("%s: %d.%d.%d.%d\n", | ||
645 | ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]); | ||
646 | #endif | ||
647 | c2_add_addr(c2dev, ifa->ifa_address, ifa->ifa_mask); | ||
648 | } | ||
649 | endfor_ifa(ind); | ||
650 | in_dev_put(ind); | ||
651 | |||
652 | return 0; | ||
653 | } | ||
654 | |||
655 | static int c2_pseudo_down(struct net_device *netdev) | ||
656 | { | ||
657 | struct in_device *ind; | ||
658 | struct c2_dev *c2dev = netdev->priv; | ||
659 | |||
660 | ind = in_dev_get(netdev); | ||
661 | if (!ind) | ||
662 | return 0; | ||
663 | |||
664 | pr_debug("deleting...\n"); | ||
665 | for_ifa(ind) { | ||
666 | #ifdef DEBUG | ||
667 | u8 *ip = (u8 *) & ifa->ifa_address; | ||
668 | |||
669 | pr_debug("%s: %d.%d.%d.%d\n", | ||
670 | ifa->ifa_label, ip[0], ip[1], ip[2], ip[3]); | ||
671 | #endif | ||
672 | c2_del_addr(c2dev, ifa->ifa_address, ifa->ifa_mask); | ||
673 | } | ||
674 | endfor_ifa(ind); | ||
675 | in_dev_put(ind); | ||
676 | |||
677 | return 0; | ||
678 | } | ||
679 | |||
680 | static int c2_pseudo_xmit_frame(struct sk_buff *skb, struct net_device *netdev) | ||
681 | { | ||
682 | kfree_skb(skb); | ||
683 | return NETDEV_TX_OK; | ||
684 | } | ||
685 | |||
686 | static int c2_pseudo_change_mtu(struct net_device *netdev, int new_mtu) | ||
687 | { | ||
688 | int ret = 0; | ||
689 | |||
690 | if (new_mtu < ETH_ZLEN || new_mtu > ETH_JUMBO_MTU) | ||
691 | return -EINVAL; | ||
692 | |||
693 | netdev->mtu = new_mtu; | ||
694 | |||
695 | /* TODO: Tell rnic about new rmda interface mtu */ | ||
696 | return ret; | ||
697 | } | ||
698 | |||
699 | static void setup(struct net_device *netdev) | ||
700 | { | ||
701 | SET_MODULE_OWNER(netdev); | ||
702 | netdev->open = c2_pseudo_up; | ||
703 | netdev->stop = c2_pseudo_down; | ||
704 | netdev->hard_start_xmit = c2_pseudo_xmit_frame; | ||
705 | netdev->get_stats = NULL; | ||
706 | netdev->tx_timeout = NULL; | ||
707 | netdev->set_mac_address = NULL; | ||
708 | netdev->change_mtu = c2_pseudo_change_mtu; | ||
709 | netdev->watchdog_timeo = 0; | ||
710 | netdev->type = ARPHRD_ETHER; | ||
711 | netdev->mtu = 1500; | ||
712 | netdev->hard_header_len = ETH_HLEN; | ||
713 | netdev->addr_len = ETH_ALEN; | ||
714 | netdev->tx_queue_len = 0; | ||
715 | netdev->flags |= IFF_NOARP; | ||
716 | return; | ||
717 | } | ||
718 | |||
719 | static struct net_device *c2_pseudo_netdev_init(struct c2_dev *c2dev) | ||
720 | { | ||
721 | char name[IFNAMSIZ]; | ||
722 | struct net_device *netdev; | ||
723 | |||
724 | /* change ethxxx to iwxxx */ | ||
725 | strcpy(name, "iw"); | ||
726 | strcat(name, &c2dev->netdev->name[3]); | ||
727 | netdev = alloc_netdev(sizeof(*netdev), name, setup); | ||
728 | if (!netdev) { | ||
729 | printk(KERN_ERR PFX "%s - etherdev alloc failed", | ||
730 | __FUNCTION__); | ||
731 | return NULL; | ||
732 | } | ||
733 | |||
734 | netdev->priv = c2dev; | ||
735 | |||
736 | SET_NETDEV_DEV(netdev, &c2dev->pcidev->dev); | ||
737 | |||
738 | memcpy_fromio(netdev->dev_addr, c2dev->kva + C2_REGS_RDMA_ENADDR, 6); | ||
739 | |||
740 | /* Print out the MAC address */ | ||
741 | pr_debug("%s: MAC %02X:%02X:%02X:%02X:%02X:%02X\n", | ||
742 | netdev->name, | ||
743 | netdev->dev_addr[0], netdev->dev_addr[1], netdev->dev_addr[2], | ||
744 | netdev->dev_addr[3], netdev->dev_addr[4], netdev->dev_addr[5]); | ||
745 | |||
746 | #if 0 | ||
747 | /* Disable network packets */ | ||
748 | netif_stop_queue(netdev); | ||
749 | #endif | ||
750 | return netdev; | ||
751 | } | ||
752 | |||
753 | int c2_register_device(struct c2_dev *dev) | ||
754 | { | ||
755 | int ret; | ||
756 | int i; | ||
757 | |||
758 | /* Register pseudo network device */ | ||
759 | dev->pseudo_netdev = c2_pseudo_netdev_init(dev); | ||
760 | if (dev->pseudo_netdev) { | ||
761 | ret = register_netdev(dev->pseudo_netdev); | ||
762 | if (ret) { | ||
763 | printk(KERN_ERR PFX | ||
764 | "Unable to register netdev, ret = %d\n", ret); | ||
765 | free_netdev(dev->pseudo_netdev); | ||
766 | return ret; | ||
767 | } | ||
768 | } | ||
769 | |||
770 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
771 | strlcpy(dev->ibdev.name, "amso%d", IB_DEVICE_NAME_MAX); | ||
772 | dev->ibdev.owner = THIS_MODULE; | ||
773 | dev->ibdev.uverbs_cmd_mask = | ||
774 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | | ||
775 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | | ||
776 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | | ||
777 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | | ||
778 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | | ||
779 | (1ull << IB_USER_VERBS_CMD_REG_MR) | | ||
780 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | | ||
781 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | | ||
782 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | | ||
783 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | | ||
784 | (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) | | ||
785 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | | ||
786 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | | ||
787 | (1ull << IB_USER_VERBS_CMD_POLL_CQ) | | ||
788 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | | ||
789 | (1ull << IB_USER_VERBS_CMD_POST_SEND) | | ||
790 | (1ull << IB_USER_VERBS_CMD_POST_RECV); | ||
791 | |||
792 | dev->ibdev.node_type = RDMA_NODE_RNIC; | ||
793 | memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid)); | ||
794 | memcpy(&dev->ibdev.node_guid, dev->pseudo_netdev->dev_addr, 6); | ||
795 | dev->ibdev.phys_port_cnt = 1; | ||
796 | dev->ibdev.dma_device = &dev->pcidev->dev; | ||
797 | dev->ibdev.class_dev.dev = &dev->pcidev->dev; | ||
798 | dev->ibdev.query_device = c2_query_device; | ||
799 | dev->ibdev.query_port = c2_query_port; | ||
800 | dev->ibdev.modify_port = c2_modify_port; | ||
801 | dev->ibdev.query_pkey = c2_query_pkey; | ||
802 | dev->ibdev.query_gid = c2_query_gid; | ||
803 | dev->ibdev.alloc_ucontext = c2_alloc_ucontext; | ||
804 | dev->ibdev.dealloc_ucontext = c2_dealloc_ucontext; | ||
805 | dev->ibdev.mmap = c2_mmap_uar; | ||
806 | dev->ibdev.alloc_pd = c2_alloc_pd; | ||
807 | dev->ibdev.dealloc_pd = c2_dealloc_pd; | ||
808 | dev->ibdev.create_ah = c2_ah_create; | ||
809 | dev->ibdev.destroy_ah = c2_ah_destroy; | ||
810 | dev->ibdev.create_qp = c2_create_qp; | ||
811 | dev->ibdev.modify_qp = c2_modify_qp; | ||
812 | dev->ibdev.destroy_qp = c2_destroy_qp; | ||
813 | dev->ibdev.create_cq = c2_create_cq; | ||
814 | dev->ibdev.destroy_cq = c2_destroy_cq; | ||
815 | dev->ibdev.poll_cq = c2_poll_cq; | ||
816 | dev->ibdev.get_dma_mr = c2_get_dma_mr; | ||
817 | dev->ibdev.reg_phys_mr = c2_reg_phys_mr; | ||
818 | dev->ibdev.reg_user_mr = c2_reg_user_mr; | ||
819 | dev->ibdev.dereg_mr = c2_dereg_mr; | ||
820 | |||
821 | dev->ibdev.alloc_fmr = NULL; | ||
822 | dev->ibdev.unmap_fmr = NULL; | ||
823 | dev->ibdev.dealloc_fmr = NULL; | ||
824 | dev->ibdev.map_phys_fmr = NULL; | ||
825 | |||
826 | dev->ibdev.attach_mcast = c2_multicast_attach; | ||
827 | dev->ibdev.detach_mcast = c2_multicast_detach; | ||
828 | dev->ibdev.process_mad = c2_process_mad; | ||
829 | |||
830 | dev->ibdev.req_notify_cq = c2_arm_cq; | ||
831 | dev->ibdev.post_send = c2_post_send; | ||
832 | dev->ibdev.post_recv = c2_post_receive; | ||
833 | |||
834 | dev->ibdev.iwcm = kmalloc(sizeof(*dev->ibdev.iwcm), GFP_KERNEL); | ||
835 | dev->ibdev.iwcm->add_ref = c2_add_ref; | ||
836 | dev->ibdev.iwcm->rem_ref = c2_rem_ref; | ||
837 | dev->ibdev.iwcm->get_qp = c2_get_qp; | ||
838 | dev->ibdev.iwcm->connect = c2_connect; | ||
839 | dev->ibdev.iwcm->accept = c2_accept; | ||
840 | dev->ibdev.iwcm->reject = c2_reject; | ||
841 | dev->ibdev.iwcm->create_listen = c2_service_create; | ||
842 | dev->ibdev.iwcm->destroy_listen = c2_service_destroy; | ||
843 | |||
844 | ret = ib_register_device(&dev->ibdev); | ||
845 | if (ret) | ||
846 | return ret; | ||
847 | |||
848 | for (i = 0; i < ARRAY_SIZE(c2_class_attributes); ++i) { | ||
849 | ret = class_device_create_file(&dev->ibdev.class_dev, | ||
850 | c2_class_attributes[i]); | ||
851 | if (ret) { | ||
852 | unregister_netdev(dev->pseudo_netdev); | ||
853 | free_netdev(dev->pseudo_netdev); | ||
854 | ib_unregister_device(&dev->ibdev); | ||
855 | return ret; | ||
856 | } | ||
857 | } | ||
858 | |||
859 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
860 | return 0; | ||
861 | } | ||
862 | |||
863 | void c2_unregister_device(struct c2_dev *dev) | ||
864 | { | ||
865 | pr_debug("%s:%u\n", __FUNCTION__, __LINE__); | ||
866 | unregister_netdev(dev->pseudo_netdev); | ||
867 | free_netdev(dev->pseudo_netdev); | ||
868 | ib_unregister_device(&dev->ibdev); | ||
869 | } | ||