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