Commit | Line | Data |
---|---|---|
fab97220 HS |
1 | /* |
2 | * IBM eServer eHCA Infiniband device driver for Linux on POWER | |
3 | * | |
4 | * module start stop, hca detection | |
5 | * | |
6 | * Authors: Heiko J Schick <schickhj@de.ibm.com> | |
7 | * Hoang-Nam Nguyen <hnguyen@de.ibm.com> | |
8 | * Joachim Fenkes <fenkes@de.ibm.com> | |
9 | * | |
10 | * Copyright (c) 2005 IBM Corporation | |
11 | * | |
12 | * All rights reserved. | |
13 | * | |
14 | * This source code is distributed under a dual license of GPL v2.0 and OpenIB | |
15 | * BSD. | |
16 | * | |
17 | * OpenIB BSD License | |
18 | * | |
19 | * Redistribution and use in source and binary forms, with or without | |
20 | * modification, are permitted provided that the following conditions are met: | |
21 | * | |
22 | * Redistributions of source code must retain the above copyright notice, this | |
23 | * list of conditions and the following disclaimer. | |
24 | * | |
25 | * Redistributions in binary form must reproduce the above copyright notice, | |
26 | * this list of conditions and the following disclaimer in the documentation | |
27 | * and/or other materials | |
28 | * provided with the distribution. | |
29 | * | |
30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
31 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
32 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
33 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
34 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
35 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
36 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
37 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | |
38 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
39 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
40 | * POSSIBILITY OF SUCH DAMAGE. | |
41 | */ | |
42 | ||
7e28db5d HNN |
43 | #ifdef CONFIG_PPC_64K_PAGES |
44 | #include <linux/slab.h> | |
45 | #endif | |
fab97220 HS |
46 | #include "ehca_classes.h" |
47 | #include "ehca_iverbs.h" | |
48 | #include "ehca_mrmw.h" | |
49 | #include "ehca_tools.h" | |
50 | #include "hcp_if.h" | |
51 | ||
52 | MODULE_LICENSE("Dual BSD/GPL"); | |
53 | MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); | |
54 | MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver"); | |
4e430dcb | 55 | MODULE_VERSION("SVNEHCA_0023"); |
fab97220 HS |
56 | |
57 | int ehca_open_aqp1 = 0; | |
58 | int ehca_debug_level = 0; | |
59 | int ehca_hw_level = 0; | |
60 | int ehca_nr_ports = 2; | |
61 | int ehca_use_hp_mr = 0; | |
62 | int ehca_port_act_time = 30; | |
63 | int ehca_poll_all_eqs = 1; | |
64 | int ehca_static_rate = -1; | |
4e430dcb | 65 | int ehca_scaling_code = 0; |
fab97220 HS |
66 | |
67 | module_param_named(open_aqp1, ehca_open_aqp1, int, 0); | |
68 | module_param_named(debug_level, ehca_debug_level, int, 0); | |
69 | module_param_named(hw_level, ehca_hw_level, int, 0); | |
70 | module_param_named(nr_ports, ehca_nr_ports, int, 0); | |
71 | module_param_named(use_hp_mr, ehca_use_hp_mr, int, 0); | |
72 | module_param_named(port_act_time, ehca_port_act_time, int, 0); | |
73 | module_param_named(poll_all_eqs, ehca_poll_all_eqs, int, 0); | |
74 | module_param_named(static_rate, ehca_static_rate, int, 0); | |
4fd30060 | 75 | module_param_named(scaling_code, ehca_scaling_code, int, 0); |
fab97220 HS |
76 | |
77 | MODULE_PARM_DESC(open_aqp1, | |
78 | "AQP1 on startup (0: no (default), 1: yes)"); | |
79 | MODULE_PARM_DESC(debug_level, | |
80 | "debug level" | |
81 | " (0: no debug traces (default), 1: with debug traces)"); | |
82 | MODULE_PARM_DESC(hw_level, | |
83 | "hardware level" | |
84 | " (0: autosensing (default), 1: v. 0.20, 2: v. 0.21)"); | |
85 | MODULE_PARM_DESC(nr_ports, | |
86 | "number of connected ports (default: 2)"); | |
87 | MODULE_PARM_DESC(use_hp_mr, | |
88 | "high performance MRs (0: no (default), 1: yes)"); | |
89 | MODULE_PARM_DESC(port_act_time, | |
90 | "time to wait for port activation (default: 30 sec)"); | |
91 | MODULE_PARM_DESC(poll_all_eqs, | |
92 | "polls all event queues periodically" | |
93 | " (0: no, 1: yes (default))"); | |
94 | MODULE_PARM_DESC(static_rate, | |
95 | "set permanent static rate (default: disabled)"); | |
4fd30060 | 96 | MODULE_PARM_DESC(scaling_code, |
b8a3ba55 | 97 | "set scaling code (0: disabled/default, 1: enabled)"); |
fab97220 HS |
98 | |
99 | spinlock_t ehca_qp_idr_lock; | |
100 | spinlock_t ehca_cq_idr_lock; | |
5d88278e | 101 | spinlock_t hcall_lock; |
fab97220 HS |
102 | DEFINE_IDR(ehca_qp_idr); |
103 | DEFINE_IDR(ehca_cq_idr); | |
104 | ||
7e28db5d | 105 | |
fab97220 HS |
106 | static struct list_head shca_list; /* list of all registered ehcas */ |
107 | static spinlock_t shca_list_lock; | |
108 | ||
109 | static struct timer_list poll_eqs_timer; | |
110 | ||
7e28db5d HNN |
111 | #ifdef CONFIG_PPC_64K_PAGES |
112 | static struct kmem_cache *ctblk_cache = NULL; | |
113 | ||
f2d91361 | 114 | void *ehca_alloc_fw_ctrlblock(gfp_t flags) |
7e28db5d | 115 | { |
f2d91361 | 116 | void *ret = kmem_cache_zalloc(ctblk_cache, flags); |
7e28db5d HNN |
117 | if (!ret) |
118 | ehca_gen_err("Out of memory for ctblk"); | |
119 | return ret; | |
120 | } | |
121 | ||
122 | void ehca_free_fw_ctrlblock(void *ptr) | |
123 | { | |
124 | if (ptr) | |
125 | kmem_cache_free(ctblk_cache, ptr); | |
126 | ||
127 | } | |
128 | #endif | |
129 | ||
fab97220 HS |
130 | static int ehca_create_slab_caches(void) |
131 | { | |
132 | int ret; | |
133 | ||
134 | ret = ehca_init_pd_cache(); | |
135 | if (ret) { | |
136 | ehca_gen_err("Cannot create PD SLAB cache."); | |
137 | return ret; | |
138 | } | |
139 | ||
140 | ret = ehca_init_cq_cache(); | |
141 | if (ret) { | |
142 | ehca_gen_err("Cannot create CQ SLAB cache."); | |
143 | goto create_slab_caches2; | |
144 | } | |
145 | ||
146 | ret = ehca_init_qp_cache(); | |
147 | if (ret) { | |
148 | ehca_gen_err("Cannot create QP SLAB cache."); | |
149 | goto create_slab_caches3; | |
150 | } | |
151 | ||
152 | ret = ehca_init_av_cache(); | |
153 | if (ret) { | |
154 | ehca_gen_err("Cannot create AV SLAB cache."); | |
155 | goto create_slab_caches4; | |
156 | } | |
157 | ||
158 | ret = ehca_init_mrmw_cache(); | |
159 | if (ret) { | |
160 | ehca_gen_err("Cannot create MR&MW SLAB cache."); | |
161 | goto create_slab_caches5; | |
162 | } | |
163 | ||
7e28db5d HNN |
164 | #ifdef CONFIG_PPC_64K_PAGES |
165 | ctblk_cache = kmem_cache_create("ehca_cache_ctblk", | |
166 | EHCA_PAGESIZE, H_CB_ALIGNMENT, | |
167 | SLAB_HWCACHE_ALIGN, | |
168 | NULL, NULL); | |
169 | if (!ctblk_cache) { | |
170 | ehca_gen_err("Cannot create ctblk SLAB cache."); | |
171 | ehca_cleanup_mrmw_cache(); | |
172 | goto create_slab_caches5; | |
173 | } | |
174 | #endif | |
fab97220 HS |
175 | return 0; |
176 | ||
177 | create_slab_caches5: | |
178 | ehca_cleanup_av_cache(); | |
179 | ||
180 | create_slab_caches4: | |
181 | ehca_cleanup_qp_cache(); | |
182 | ||
183 | create_slab_caches3: | |
184 | ehca_cleanup_cq_cache(); | |
185 | ||
186 | create_slab_caches2: | |
187 | ehca_cleanup_pd_cache(); | |
188 | ||
189 | return ret; | |
190 | } | |
191 | ||
192 | static void ehca_destroy_slab_caches(void) | |
193 | { | |
194 | ehca_cleanup_mrmw_cache(); | |
195 | ehca_cleanup_av_cache(); | |
196 | ehca_cleanup_qp_cache(); | |
197 | ehca_cleanup_cq_cache(); | |
198 | ehca_cleanup_pd_cache(); | |
7e28db5d HNN |
199 | #ifdef CONFIG_PPC_64K_PAGES |
200 | if (ctblk_cache) | |
201 | kmem_cache_destroy(ctblk_cache); | |
202 | #endif | |
fab97220 HS |
203 | } |
204 | ||
205 | #define EHCA_HCAAVER EHCA_BMASK_IBM(32,39) | |
206 | #define EHCA_REVID EHCA_BMASK_IBM(40,63) | |
207 | ||
91f13aa3 JF |
208 | static struct cap_descr { |
209 | u64 mask; | |
210 | char *descr; | |
211 | } hca_cap_descr[] = { | |
212 | { HCA_CAP_AH_PORT_NR_CHECK, "HCA_CAP_AH_PORT_NR_CHECK" }, | |
213 | { HCA_CAP_ATOMIC, "HCA_CAP_ATOMIC" }, | |
214 | { HCA_CAP_AUTO_PATH_MIG, "HCA_CAP_AUTO_PATH_MIG" }, | |
215 | { HCA_CAP_BAD_P_KEY_CTR, "HCA_CAP_BAD_P_KEY_CTR" }, | |
216 | { HCA_CAP_SQD_RTS_PORT_CHANGE, "HCA_CAP_SQD_RTS_PORT_CHANGE" }, | |
217 | { HCA_CAP_CUR_QP_STATE_MOD, "HCA_CAP_CUR_QP_STATE_MOD" }, | |
218 | { HCA_CAP_INIT_TYPE, "HCA_CAP_INIT_TYPE" }, | |
219 | { HCA_CAP_PORT_ACTIVE_EVENT, "HCA_CAP_PORT_ACTIVE_EVENT" }, | |
220 | { HCA_CAP_Q_KEY_VIOL_CTR, "HCA_CAP_Q_KEY_VIOL_CTR" }, | |
221 | { HCA_CAP_WQE_RESIZE, "HCA_CAP_WQE_RESIZE" }, | |
222 | { HCA_CAP_RAW_PACKET_MCAST, "HCA_CAP_RAW_PACKET_MCAST" }, | |
223 | { HCA_CAP_SHUTDOWN_PORT, "HCA_CAP_SHUTDOWN_PORT" }, | |
224 | { HCA_CAP_RC_LL_QP, "HCA_CAP_RC_LL_QP" }, | |
225 | { HCA_CAP_SRQ, "HCA_CAP_SRQ" }, | |
226 | { HCA_CAP_UD_LL_QP, "HCA_CAP_UD_LL_QP" }, | |
227 | { HCA_CAP_RESIZE_MR, "HCA_CAP_RESIZE_MR" }, | |
228 | { HCA_CAP_MINI_QP, "HCA_CAP_MINI_QP" }, | |
229 | }; | |
230 | ||
fab97220 HS |
231 | int ehca_sense_attributes(struct ehca_shca *shca) |
232 | { | |
91f13aa3 | 233 | int i, ret = 0; |
fab97220 HS |
234 | u64 h_ret; |
235 | struct hipz_query_hca *rblock; | |
91f13aa3 | 236 | struct hipz_query_port *port; |
fab97220 | 237 | |
f2d91361 | 238 | rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
fab97220 HS |
239 | if (!rblock) { |
240 | ehca_gen_err("Cannot allocate rblock memory."); | |
241 | return -ENOMEM; | |
242 | } | |
243 | ||
244 | h_ret = hipz_h_query_hca(shca->ipz_hca_handle, rblock); | |
245 | if (h_ret != H_SUCCESS) { | |
246 | ehca_gen_err("Cannot query device properties. h_ret=%lx", | |
247 | h_ret); | |
248 | ret = -EPERM; | |
91f13aa3 | 249 | goto sense_attributes1; |
fab97220 HS |
250 | } |
251 | ||
252 | if (ehca_nr_ports == 1) | |
253 | shca->num_ports = 1; | |
254 | else | |
255 | shca->num_ports = (u8)rblock->num_ports; | |
256 | ||
257 | ehca_gen_dbg(" ... found %x ports", rblock->num_ports); | |
258 | ||
259 | if (ehca_hw_level == 0) { | |
260 | u32 hcaaver; | |
261 | u32 revid; | |
262 | ||
263 | hcaaver = EHCA_BMASK_GET(EHCA_HCAAVER, rblock->hw_ver); | |
264 | revid = EHCA_BMASK_GET(EHCA_REVID, rblock->hw_ver); | |
265 | ||
266 | ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver, revid); | |
267 | ||
268 | if ((hcaaver == 1) && (revid == 0)) | |
91f13aa3 | 269 | shca->hw_level = 0x11; |
fab97220 | 270 | else if ((hcaaver == 1) && (revid == 1)) |
91f13aa3 | 271 | shca->hw_level = 0x12; |
fab97220 | 272 | else if ((hcaaver == 1) && (revid == 2)) |
91f13aa3 JF |
273 | shca->hw_level = 0x13; |
274 | else if ((hcaaver == 2) && (revid == 0)) | |
275 | shca->hw_level = 0x21; | |
276 | else if ((hcaaver == 2) && (revid == 0x10)) | |
277 | shca->hw_level = 0x22; | |
278 | else { | |
279 | ehca_gen_warn("unknown hardware version" | |
280 | " - assuming default level"); | |
281 | shca->hw_level = 0x22; | |
282 | } | |
fab97220 HS |
283 | } |
284 | ehca_gen_dbg(" ... hardware level=%x", shca->hw_level); | |
285 | ||
286 | shca->sport[0].rate = IB_RATE_30_GBPS; | |
287 | shca->sport[1].rate = IB_RATE_30_GBPS; | |
288 | ||
91f13aa3 JF |
289 | shca->hca_cap = rblock->hca_cap_indicators; |
290 | ehca_gen_dbg(" ... HCA capabilities:"); | |
291 | for (i = 0; i < ARRAY_SIZE(hca_cap_descr); i++) | |
292 | if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap)) | |
293 | ehca_gen_dbg(" %s", hca_cap_descr[i].descr); | |
294 | ||
295 | port = (struct hipz_query_port *) rblock; | |
296 | h_ret = hipz_h_query_port(shca->ipz_hca_handle, 1, port); | |
297 | if (h_ret != H_SUCCESS) { | |
298 | ehca_gen_err("Cannot query port properties. h_ret=%lx", | |
299 | h_ret); | |
300 | ret = -EPERM; | |
301 | goto sense_attributes1; | |
302 | } | |
303 | ||
304 | shca->max_mtu = port->max_mtu; | |
305 | ||
306 | sense_attributes1: | |
7e28db5d | 307 | ehca_free_fw_ctrlblock(rblock); |
fab97220 HS |
308 | return ret; |
309 | } | |
310 | ||
311 | static int init_node_guid(struct ehca_shca *shca) | |
312 | { | |
313 | int ret = 0; | |
314 | struct hipz_query_hca *rblock; | |
315 | ||
f2d91361 | 316 | rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); |
fab97220 HS |
317 | if (!rblock) { |
318 | ehca_err(&shca->ib_device, "Can't allocate rblock memory."); | |
319 | return -ENOMEM; | |
320 | } | |
321 | ||
322 | if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { | |
323 | ehca_err(&shca->ib_device, "Can't query device properties"); | |
324 | ret = -EINVAL; | |
325 | goto init_node_guid1; | |
326 | } | |
327 | ||
328 | memcpy(&shca->ib_device.node_guid, &rblock->node_guid, sizeof(u64)); | |
329 | ||
330 | init_node_guid1: | |
7e28db5d | 331 | ehca_free_fw_ctrlblock(rblock); |
fab97220 HS |
332 | return ret; |
333 | } | |
334 | ||
0f248d9c | 335 | int ehca_init_device(struct ehca_shca *shca) |
fab97220 HS |
336 | { |
337 | int ret; | |
338 | ||
339 | ret = init_node_guid(shca); | |
340 | if (ret) | |
341 | return ret; | |
342 | ||
343 | strlcpy(shca->ib_device.name, "ehca%d", IB_DEVICE_NAME_MAX); | |
344 | shca->ib_device.owner = THIS_MODULE; | |
345 | ||
a6a12947 | 346 | shca->ib_device.uverbs_abi_ver = 7; |
fab97220 HS |
347 | shca->ib_device.uverbs_cmd_mask = |
348 | (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) | | |
349 | (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) | | |
350 | (1ull << IB_USER_VERBS_CMD_QUERY_PORT) | | |
351 | (1ull << IB_USER_VERBS_CMD_ALLOC_PD) | | |
352 | (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) | | |
353 | (1ull << IB_USER_VERBS_CMD_REG_MR) | | |
354 | (1ull << IB_USER_VERBS_CMD_DEREG_MR) | | |
355 | (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) | | |
356 | (1ull << IB_USER_VERBS_CMD_CREATE_CQ) | | |
357 | (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) | | |
358 | (1ull << IB_USER_VERBS_CMD_CREATE_QP) | | |
359 | (1ull << IB_USER_VERBS_CMD_MODIFY_QP) | | |
360 | (1ull << IB_USER_VERBS_CMD_QUERY_QP) | | |
361 | (1ull << IB_USER_VERBS_CMD_DESTROY_QP) | | |
362 | (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) | | |
363 | (1ull << IB_USER_VERBS_CMD_DETACH_MCAST); | |
364 | ||
07ebafba | 365 | shca->ib_device.node_type = RDMA_NODE_IB_CA; |
fab97220 | 366 | shca->ib_device.phys_port_cnt = shca->num_ports; |
f4fd0b22 | 367 | shca->ib_device.num_comp_vectors = 1; |
fab97220 HS |
368 | shca->ib_device.dma_device = &shca->ibmebus_dev->ofdev.dev; |
369 | shca->ib_device.query_device = ehca_query_device; | |
370 | shca->ib_device.query_port = ehca_query_port; | |
371 | shca->ib_device.query_gid = ehca_query_gid; | |
372 | shca->ib_device.query_pkey = ehca_query_pkey; | |
373 | /* shca->in_device.modify_device = ehca_modify_device */ | |
374 | shca->ib_device.modify_port = ehca_modify_port; | |
375 | shca->ib_device.alloc_ucontext = ehca_alloc_ucontext; | |
376 | shca->ib_device.dealloc_ucontext = ehca_dealloc_ucontext; | |
377 | shca->ib_device.alloc_pd = ehca_alloc_pd; | |
378 | shca->ib_device.dealloc_pd = ehca_dealloc_pd; | |
379 | shca->ib_device.create_ah = ehca_create_ah; | |
380 | /* shca->ib_device.modify_ah = ehca_modify_ah; */ | |
381 | shca->ib_device.query_ah = ehca_query_ah; | |
382 | shca->ib_device.destroy_ah = ehca_destroy_ah; | |
383 | shca->ib_device.create_qp = ehca_create_qp; | |
384 | shca->ib_device.modify_qp = ehca_modify_qp; | |
385 | shca->ib_device.query_qp = ehca_query_qp; | |
386 | shca->ib_device.destroy_qp = ehca_destroy_qp; | |
387 | shca->ib_device.post_send = ehca_post_send; | |
388 | shca->ib_device.post_recv = ehca_post_recv; | |
389 | shca->ib_device.create_cq = ehca_create_cq; | |
390 | shca->ib_device.destroy_cq = ehca_destroy_cq; | |
391 | shca->ib_device.resize_cq = ehca_resize_cq; | |
392 | shca->ib_device.poll_cq = ehca_poll_cq; | |
393 | /* shca->ib_device.peek_cq = ehca_peek_cq; */ | |
394 | shca->ib_device.req_notify_cq = ehca_req_notify_cq; | |
395 | /* shca->ib_device.req_ncomp_notif = ehca_req_ncomp_notif; */ | |
396 | shca->ib_device.get_dma_mr = ehca_get_dma_mr; | |
397 | shca->ib_device.reg_phys_mr = ehca_reg_phys_mr; | |
398 | shca->ib_device.reg_user_mr = ehca_reg_user_mr; | |
399 | shca->ib_device.query_mr = ehca_query_mr; | |
400 | shca->ib_device.dereg_mr = ehca_dereg_mr; | |
401 | shca->ib_device.rereg_phys_mr = ehca_rereg_phys_mr; | |
402 | shca->ib_device.alloc_mw = ehca_alloc_mw; | |
403 | shca->ib_device.bind_mw = ehca_bind_mw; | |
404 | shca->ib_device.dealloc_mw = ehca_dealloc_mw; | |
405 | shca->ib_device.alloc_fmr = ehca_alloc_fmr; | |
406 | shca->ib_device.map_phys_fmr = ehca_map_phys_fmr; | |
407 | shca->ib_device.unmap_fmr = ehca_unmap_fmr; | |
408 | shca->ib_device.dealloc_fmr = ehca_dealloc_fmr; | |
409 | shca->ib_device.attach_mcast = ehca_attach_mcast; | |
410 | shca->ib_device.detach_mcast = ehca_detach_mcast; | |
411 | /* shca->ib_device.process_mad = ehca_process_mad; */ | |
412 | shca->ib_device.mmap = ehca_mmap; | |
413 | ||
a6a12947 JF |
414 | if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) { |
415 | shca->ib_device.uverbs_cmd_mask |= | |
416 | (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) | | |
417 | (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) | | |
418 | (1ull << IB_USER_VERBS_CMD_QUERY_SRQ) | | |
419 | (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ); | |
420 | ||
421 | shca->ib_device.create_srq = ehca_create_srq; | |
422 | shca->ib_device.modify_srq = ehca_modify_srq; | |
423 | shca->ib_device.query_srq = ehca_query_srq; | |
424 | shca->ib_device.destroy_srq = ehca_destroy_srq; | |
425 | shca->ib_device.post_srq_recv = ehca_post_srq_recv; | |
426 | } | |
427 | ||
fab97220 HS |
428 | return ret; |
429 | } | |
430 | ||
431 | static int ehca_create_aqp1(struct ehca_shca *shca, u32 port) | |
432 | { | |
433 | struct ehca_sport *sport = &shca->sport[port - 1]; | |
434 | struct ib_cq *ibcq; | |
435 | struct ib_qp *ibqp; | |
436 | struct ib_qp_init_attr qp_init_attr; | |
437 | int ret; | |
438 | ||
439 | if (sport->ibcq_aqp1) { | |
440 | ehca_err(&shca->ib_device, "AQP1 CQ is already created."); | |
441 | return -EPERM; | |
442 | } | |
443 | ||
f4fd0b22 | 444 | ibcq = ib_create_cq(&shca->ib_device, NULL, NULL, (void*)(-1), 10, 0); |
fab97220 HS |
445 | if (IS_ERR(ibcq)) { |
446 | ehca_err(&shca->ib_device, "Cannot create AQP1 CQ."); | |
447 | return PTR_ERR(ibcq); | |
448 | } | |
449 | sport->ibcq_aqp1 = ibcq; | |
450 | ||
451 | if (sport->ibqp_aqp1) { | |
452 | ehca_err(&shca->ib_device, "AQP1 QP is already created."); | |
453 | ret = -EPERM; | |
454 | goto create_aqp1; | |
455 | } | |
456 | ||
457 | memset(&qp_init_attr, 0, sizeof(struct ib_qp_init_attr)); | |
458 | qp_init_attr.send_cq = ibcq; | |
459 | qp_init_attr.recv_cq = ibcq; | |
460 | qp_init_attr.sq_sig_type = IB_SIGNAL_ALL_WR; | |
461 | qp_init_attr.cap.max_send_wr = 100; | |
462 | qp_init_attr.cap.max_recv_wr = 100; | |
463 | qp_init_attr.cap.max_send_sge = 2; | |
464 | qp_init_attr.cap.max_recv_sge = 1; | |
465 | qp_init_attr.qp_type = IB_QPT_GSI; | |
466 | qp_init_attr.port_num = port; | |
467 | qp_init_attr.qp_context = NULL; | |
468 | qp_init_attr.event_handler = NULL; | |
469 | qp_init_attr.srq = NULL; | |
470 | ||
471 | ibqp = ib_create_qp(&shca->pd->ib_pd, &qp_init_attr); | |
472 | if (IS_ERR(ibqp)) { | |
473 | ehca_err(&shca->ib_device, "Cannot create AQP1 QP."); | |
474 | ret = PTR_ERR(ibqp); | |
475 | goto create_aqp1; | |
476 | } | |
477 | sport->ibqp_aqp1 = ibqp; | |
478 | ||
479 | return 0; | |
480 | ||
481 | create_aqp1: | |
482 | ib_destroy_cq(sport->ibcq_aqp1); | |
483 | return ret; | |
484 | } | |
485 | ||
486 | static int ehca_destroy_aqp1(struct ehca_sport *sport) | |
487 | { | |
488 | int ret; | |
489 | ||
490 | ret = ib_destroy_qp(sport->ibqp_aqp1); | |
491 | if (ret) { | |
492 | ehca_gen_err("Cannot destroy AQP1 QP. ret=%x", ret); | |
493 | return ret; | |
494 | } | |
495 | ||
496 | ret = ib_destroy_cq(sport->ibcq_aqp1); | |
497 | if (ret) | |
498 | ehca_gen_err("Cannot destroy AQP1 CQ. ret=%x", ret); | |
499 | ||
500 | return ret; | |
501 | } | |
502 | ||
503 | static ssize_t ehca_show_debug_level(struct device_driver *ddp, char *buf) | |
504 | { | |
78d8d5f9 HNN |
505 | return snprintf(buf, PAGE_SIZE, "%d\n", |
506 | ehca_debug_level); | |
fab97220 HS |
507 | } |
508 | ||
509 | static ssize_t ehca_store_debug_level(struct device_driver *ddp, | |
510 | const char *buf, size_t count) | |
511 | { | |
512 | int value = (*buf) - '0'; | |
513 | if (value >= 0 && value <= 9) | |
514 | ehca_debug_level = value; | |
515 | return 1; | |
516 | } | |
517 | ||
518 | DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR, | |
519 | ehca_show_debug_level, ehca_store_debug_level); | |
520 | ||
bba9b601 JF |
521 | static struct attribute *ehca_drv_attrs[] = { |
522 | &driver_attr_debug_level.attr, | |
523 | NULL | |
524 | }; | |
fab97220 | 525 | |
bba9b601 JF |
526 | static struct attribute_group ehca_drv_attr_grp = { |
527 | .attrs = ehca_drv_attrs | |
528 | }; | |
fab97220 HS |
529 | |
530 | #define EHCA_RESOURCE_ATTR(name) \ | |
531 | static ssize_t ehca_show_##name(struct device *dev, \ | |
532 | struct device_attribute *attr, \ | |
533 | char *buf) \ | |
534 | { \ | |
535 | struct ehca_shca *shca; \ | |
536 | struct hipz_query_hca *rblock; \ | |
537 | int data; \ | |
538 | \ | |
539 | shca = dev->driver_data; \ | |
540 | \ | |
f2d91361 | 541 | rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL); \ |
fab97220 HS |
542 | if (!rblock) { \ |
543 | dev_err(dev, "Can't allocate rblock memory."); \ | |
544 | return 0; \ | |
545 | } \ | |
546 | \ | |
547 | if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) { \ | |
548 | dev_err(dev, "Can't query device properties"); \ | |
7e28db5d | 549 | ehca_free_fw_ctrlblock(rblock); \ |
fab97220 HS |
550 | return 0; \ |
551 | } \ | |
552 | \ | |
553 | data = rblock->name; \ | |
7e28db5d | 554 | ehca_free_fw_ctrlblock(rblock); \ |
fab97220 HS |
555 | \ |
556 | if ((strcmp(#name, "num_ports") == 0) && (ehca_nr_ports == 1)) \ | |
557 | return snprintf(buf, 256, "1\n"); \ | |
558 | else \ | |
559 | return snprintf(buf, 256, "%d\n", data); \ | |
560 | \ | |
561 | } \ | |
562 | static DEVICE_ATTR(name, S_IRUGO, ehca_show_##name, NULL); | |
563 | ||
564 | EHCA_RESOURCE_ATTR(num_ports); | |
565 | EHCA_RESOURCE_ATTR(hw_ver); | |
566 | EHCA_RESOURCE_ATTR(max_eq); | |
567 | EHCA_RESOURCE_ATTR(cur_eq); | |
568 | EHCA_RESOURCE_ATTR(max_cq); | |
569 | EHCA_RESOURCE_ATTR(cur_cq); | |
570 | EHCA_RESOURCE_ATTR(max_qp); | |
571 | EHCA_RESOURCE_ATTR(cur_qp); | |
572 | EHCA_RESOURCE_ATTR(max_mr); | |
573 | EHCA_RESOURCE_ATTR(cur_mr); | |
574 | EHCA_RESOURCE_ATTR(max_mw); | |
575 | EHCA_RESOURCE_ATTR(cur_mw); | |
576 | EHCA_RESOURCE_ATTR(max_pd); | |
577 | EHCA_RESOURCE_ATTR(max_ah); | |
578 | ||
579 | static ssize_t ehca_show_adapter_handle(struct device *dev, | |
580 | struct device_attribute *attr, | |
581 | char *buf) | |
582 | { | |
583 | struct ehca_shca *shca = dev->driver_data; | |
584 | ||
585 | return sprintf(buf, "%lx\n", shca->ipz_hca_handle.handle); | |
586 | ||
587 | } | |
588 | static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL); | |
589 | ||
bba9b601 JF |
590 | static struct attribute *ehca_dev_attrs[] = { |
591 | &dev_attr_adapter_handle.attr, | |
592 | &dev_attr_num_ports.attr, | |
593 | &dev_attr_hw_ver.attr, | |
594 | &dev_attr_max_eq.attr, | |
595 | &dev_attr_cur_eq.attr, | |
596 | &dev_attr_max_cq.attr, | |
597 | &dev_attr_cur_cq.attr, | |
598 | &dev_attr_max_qp.attr, | |
599 | &dev_attr_cur_qp.attr, | |
600 | &dev_attr_max_mr.attr, | |
601 | &dev_attr_cur_mr.attr, | |
602 | &dev_attr_max_mw.attr, | |
603 | &dev_attr_cur_mw.attr, | |
604 | &dev_attr_max_pd.attr, | |
605 | &dev_attr_max_ah.attr, | |
606 | NULL | |
607 | }; | |
fab97220 | 608 | |
bba9b601 JF |
609 | static struct attribute_group ehca_dev_attr_grp = { |
610 | .attrs = ehca_dev_attrs | |
611 | }; | |
fab97220 HS |
612 | |
613 | static int __devinit ehca_probe(struct ibmebus_dev *dev, | |
614 | const struct of_device_id *id) | |
615 | { | |
616 | struct ehca_shca *shca; | |
a7edd0e6 | 617 | const u64 *handle; |
fab97220 HS |
618 | struct ib_pd *ibpd; |
619 | int ret; | |
620 | ||
40cd3a45 | 621 | handle = of_get_property(dev->ofdev.node, "ibm,hca-handle", NULL); |
fab97220 HS |
622 | if (!handle) { |
623 | ehca_gen_err("Cannot get eHCA handle for adapter: %s.", | |
624 | dev->ofdev.node->full_name); | |
625 | return -ENODEV; | |
626 | } | |
627 | ||
628 | if (!(*handle)) { | |
629 | ehca_gen_err("Wrong eHCA handle for adapter: %s.", | |
630 | dev->ofdev.node->full_name); | |
631 | return -ENODEV; | |
632 | } | |
633 | ||
634 | shca = (struct ehca_shca *)ib_alloc_device(sizeof(*shca)); | |
635 | if (!shca) { | |
636 | ehca_gen_err("Cannot allocate shca memory."); | |
637 | return -ENOMEM; | |
638 | } | |
c4ed790d | 639 | mutex_init(&shca->modify_mutex); |
fab97220 HS |
640 | |
641 | shca->ibmebus_dev = dev; | |
642 | shca->ipz_hca_handle.handle = *handle; | |
643 | dev->ofdev.dev.driver_data = shca; | |
644 | ||
645 | ret = ehca_sense_attributes(shca); | |
646 | if (ret < 0) { | |
647 | ehca_gen_err("Cannot sense eHCA attributes."); | |
648 | goto probe1; | |
649 | } | |
650 | ||
0f248d9c | 651 | ret = ehca_init_device(shca); |
fab97220 | 652 | if (ret) { |
0f248d9c | 653 | ehca_gen_err("Cannot init ehca device struct"); |
fab97220 HS |
654 | goto probe1; |
655 | } | |
656 | ||
657 | /* create event queues */ | |
658 | ret = ehca_create_eq(shca, &shca->eq, EHCA_EQ, 2048); | |
659 | if (ret) { | |
660 | ehca_err(&shca->ib_device, "Cannot create EQ."); | |
0f248d9c | 661 | goto probe1; |
fab97220 HS |
662 | } |
663 | ||
664 | ret = ehca_create_eq(shca, &shca->neq, EHCA_NEQ, 513); | |
665 | if (ret) { | |
666 | ehca_err(&shca->ib_device, "Cannot create NEQ."); | |
667 | goto probe3; | |
668 | } | |
669 | ||
670 | /* create internal protection domain */ | |
671 | ibpd = ehca_alloc_pd(&shca->ib_device, (void*)(-1), NULL); | |
672 | if (IS_ERR(ibpd)) { | |
673 | ehca_err(&shca->ib_device, "Cannot create internal PD."); | |
674 | ret = PTR_ERR(ibpd); | |
675 | goto probe4; | |
676 | } | |
677 | ||
678 | shca->pd = container_of(ibpd, struct ehca_pd, ib_pd); | |
679 | shca->pd->ib_pd.device = &shca->ib_device; | |
680 | ||
681 | /* create internal max MR */ | |
682 | ret = ehca_reg_internal_maxmr(shca, shca->pd, &shca->maxmr); | |
683 | ||
684 | if (ret) { | |
685 | ehca_err(&shca->ib_device, "Cannot create internal MR ret=%x", | |
686 | ret); | |
687 | goto probe5; | |
688 | } | |
689 | ||
0f248d9c HNN |
690 | ret = ib_register_device(&shca->ib_device); |
691 | if (ret) { | |
692 | ehca_err(&shca->ib_device, | |
693 | "ib_register_device() failed ret=%x", ret); | |
694 | goto probe6; | |
695 | } | |
696 | ||
fab97220 HS |
697 | /* create AQP1 for port 1 */ |
698 | if (ehca_open_aqp1 == 1) { | |
699 | shca->sport[0].port_state = IB_PORT_DOWN; | |
700 | ret = ehca_create_aqp1(shca, 1); | |
701 | if (ret) { | |
702 | ehca_err(&shca->ib_device, | |
703 | "Cannot create AQP1 for port 1."); | |
0f248d9c | 704 | goto probe7; |
fab97220 HS |
705 | } |
706 | } | |
707 | ||
708 | /* create AQP1 for port 2 */ | |
709 | if ((ehca_open_aqp1 == 1) && (shca->num_ports == 2)) { | |
710 | shca->sport[1].port_state = IB_PORT_DOWN; | |
711 | ret = ehca_create_aqp1(shca, 2); | |
712 | if (ret) { | |
713 | ehca_err(&shca->ib_device, | |
714 | "Cannot create AQP1 for port 2."); | |
0f248d9c | 715 | goto probe8; |
fab97220 HS |
716 | } |
717 | } | |
718 | ||
bba9b601 JF |
719 | ret = sysfs_create_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp); |
720 | if (ret) /* only complain; we can live without attributes */ | |
721 | ehca_err(&shca->ib_device, | |
722 | "Cannot create device attributes ret=%d", ret); | |
fab97220 HS |
723 | |
724 | spin_lock(&shca_list_lock); | |
725 | list_add(&shca->shca_list, &shca_list); | |
726 | spin_unlock(&shca_list_lock); | |
727 | ||
728 | return 0; | |
729 | ||
0f248d9c | 730 | probe8: |
fab97220 HS |
731 | ret = ehca_destroy_aqp1(&shca->sport[0]); |
732 | if (ret) | |
733 | ehca_err(&shca->ib_device, | |
734 | "Cannot destroy AQP1 for port 1. ret=%x", ret); | |
735 | ||
0f248d9c HNN |
736 | probe7: |
737 | ib_unregister_device(&shca->ib_device); | |
738 | ||
fab97220 HS |
739 | probe6: |
740 | ret = ehca_dereg_internal_maxmr(shca); | |
741 | if (ret) | |
742 | ehca_err(&shca->ib_device, | |
743 | "Cannot destroy internal MR. ret=%x", ret); | |
744 | ||
745 | probe5: | |
746 | ret = ehca_dealloc_pd(&shca->pd->ib_pd); | |
747 | if (ret) | |
748 | ehca_err(&shca->ib_device, | |
749 | "Cannot destroy internal PD. ret=%x", ret); | |
750 | ||
751 | probe4: | |
752 | ret = ehca_destroy_eq(shca, &shca->neq); | |
753 | if (ret) | |
754 | ehca_err(&shca->ib_device, | |
755 | "Cannot destroy NEQ. ret=%x", ret); | |
756 | ||
757 | probe3: | |
758 | ret = ehca_destroy_eq(shca, &shca->eq); | |
759 | if (ret) | |
760 | ehca_err(&shca->ib_device, | |
761 | "Cannot destroy EQ. ret=%x", ret); | |
762 | ||
fab97220 HS |
763 | probe1: |
764 | ib_dealloc_device(&shca->ib_device); | |
765 | ||
766 | return -EINVAL; | |
767 | } | |
768 | ||
769 | static int __devexit ehca_remove(struct ibmebus_dev *dev) | |
770 | { | |
771 | struct ehca_shca *shca = dev->ofdev.dev.driver_data; | |
772 | int ret; | |
773 | ||
bba9b601 | 774 | sysfs_remove_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp); |
fab97220 HS |
775 | |
776 | if (ehca_open_aqp1 == 1) { | |
777 | int i; | |
778 | for (i = 0; i < shca->num_ports; i++) { | |
779 | ret = ehca_destroy_aqp1(&shca->sport[i]); | |
780 | if (ret) | |
781 | ehca_err(&shca->ib_device, | |
782 | "Cannot destroy AQP1 for port %x " | |
783 | "ret=%x", ret, i); | |
784 | } | |
785 | } | |
786 | ||
787 | ib_unregister_device(&shca->ib_device); | |
788 | ||
789 | ret = ehca_dereg_internal_maxmr(shca); | |
790 | if (ret) | |
791 | ehca_err(&shca->ib_device, | |
792 | "Cannot destroy internal MR. ret=%x", ret); | |
793 | ||
794 | ret = ehca_dealloc_pd(&shca->pd->ib_pd); | |
795 | if (ret) | |
796 | ehca_err(&shca->ib_device, | |
797 | "Cannot destroy internal PD. ret=%x", ret); | |
798 | ||
799 | ret = ehca_destroy_eq(shca, &shca->eq); | |
800 | if (ret) | |
801 | ehca_err(&shca->ib_device, "Cannot destroy EQ. ret=%x", ret); | |
802 | ||
803 | ret = ehca_destroy_eq(shca, &shca->neq); | |
804 | if (ret) | |
805 | ehca_err(&shca->ib_device, "Canot destroy NEQ. ret=%x", ret); | |
806 | ||
807 | ib_dealloc_device(&shca->ib_device); | |
808 | ||
809 | spin_lock(&shca_list_lock); | |
810 | list_del(&shca->shca_list); | |
811 | spin_unlock(&shca_list_lock); | |
812 | ||
813 | return ret; | |
814 | } | |
815 | ||
816 | static struct of_device_id ehca_device_table[] = | |
817 | { | |
818 | { | |
819 | .name = "lhca", | |
820 | .compatible = "IBM,lhca", | |
821 | }, | |
822 | {}, | |
823 | }; | |
824 | ||
825 | static struct ibmebus_driver ehca_driver = { | |
826 | .name = "ehca", | |
827 | .id_table = ehca_device_table, | |
828 | .probe = ehca_probe, | |
829 | .remove = ehca_remove, | |
830 | }; | |
831 | ||
832 | void ehca_poll_eqs(unsigned long data) | |
833 | { | |
834 | struct ehca_shca *shca; | |
835 | ||
836 | spin_lock(&shca_list_lock); | |
837 | list_for_each_entry(shca, &shca_list, shca_list) { | |
78d8d5f9 HNN |
838 | if (shca->eq.is_initialized) { |
839 | /* call deadman proc only if eq ptr does not change */ | |
840 | struct ehca_eq *eq = &shca->eq; | |
841 | int max = 3; | |
842 | volatile u64 q_ofs, q_ofs2; | |
843 | u64 flags; | |
844 | spin_lock_irqsave(&eq->spinlock, flags); | |
845 | q_ofs = eq->ipz_queue.current_q_offset; | |
846 | spin_unlock_irqrestore(&eq->spinlock, flags); | |
847 | do { | |
848 | spin_lock_irqsave(&eq->spinlock, flags); | |
849 | q_ofs2 = eq->ipz_queue.current_q_offset; | |
850 | spin_unlock_irqrestore(&eq->spinlock, flags); | |
851 | max--; | |
852 | } while (q_ofs == q_ofs2 && max > 0); | |
853 | if (q_ofs == q_ofs2) | |
854 | ehca_process_eq(shca, 0); | |
855 | } | |
fab97220 HS |
856 | } |
857 | mod_timer(&poll_eqs_timer, jiffies + HZ); | |
858 | spin_unlock(&shca_list_lock); | |
859 | } | |
860 | ||
861 | int __init ehca_module_init(void) | |
862 | { | |
863 | int ret; | |
864 | ||
865 | printk(KERN_INFO "eHCA Infiniband Device Driver " | |
4e430dcb | 866 | "(Rel.: SVNEHCA_0023)\n"); |
fab97220 HS |
867 | idr_init(&ehca_qp_idr); |
868 | idr_init(&ehca_cq_idr); | |
869 | spin_lock_init(&ehca_qp_idr_lock); | |
870 | spin_lock_init(&ehca_cq_idr_lock); | |
5d88278e | 871 | spin_lock_init(&hcall_lock); |
fab97220 HS |
872 | |
873 | INIT_LIST_HEAD(&shca_list); | |
874 | spin_lock_init(&shca_list_lock); | |
875 | ||
876 | if ((ret = ehca_create_comp_pool())) { | |
877 | ehca_gen_err("Cannot create comp pool."); | |
878 | return ret; | |
879 | } | |
880 | ||
881 | if ((ret = ehca_create_slab_caches())) { | |
882 | ehca_gen_err("Cannot create SLAB caches"); | |
883 | ret = -ENOMEM; | |
884 | goto module_init1; | |
885 | } | |
886 | ||
887 | if ((ret = ibmebus_register_driver(&ehca_driver))) { | |
888 | ehca_gen_err("Cannot register eHCA device driver"); | |
889 | ret = -EINVAL; | |
890 | goto module_init2; | |
891 | } | |
892 | ||
bba9b601 JF |
893 | ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp); |
894 | if (ret) /* only complain; we can live without attributes */ | |
895 | ehca_gen_err("Cannot create driver attributes ret=%d", ret); | |
fab97220 HS |
896 | |
897 | if (ehca_poll_all_eqs != 1) { | |
898 | ehca_gen_err("WARNING!!!"); | |
899 | ehca_gen_err("It is possible to lose interrupts."); | |
900 | } else { | |
901 | init_timer(&poll_eqs_timer); | |
902 | poll_eqs_timer.function = ehca_poll_eqs; | |
903 | poll_eqs_timer.expires = jiffies + HZ; | |
904 | add_timer(&poll_eqs_timer); | |
905 | } | |
906 | ||
907 | return 0; | |
908 | ||
909 | module_init2: | |
910 | ehca_destroy_slab_caches(); | |
911 | ||
912 | module_init1: | |
913 | ehca_destroy_comp_pool(); | |
914 | return ret; | |
915 | }; | |
916 | ||
917 | void __exit ehca_module_exit(void) | |
918 | { | |
919 | if (ehca_poll_all_eqs == 1) | |
920 | del_timer_sync(&poll_eqs_timer); | |
921 | ||
bba9b601 | 922 | sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp); |
fab97220 HS |
923 | ibmebus_unregister_driver(&ehca_driver); |
924 | ||
925 | ehca_destroy_slab_caches(); | |
926 | ||
927 | ehca_destroy_comp_pool(); | |
928 | ||
929 | idr_destroy(&ehca_cq_idr); | |
930 | idr_destroy(&ehca_qp_idr); | |
931 | }; | |
932 | ||
933 | module_init(ehca_module_init); | |
934 | module_exit(ehca_module_exit); |