Commit | Line | Data |
---|---|---|
b85daafe KG |
1 | /* |
2 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. | |
3 | * All rights reserved | |
4 | * www.brocade.com | |
5 | * | |
6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License (GPL) Version 2 as | |
10 | * published by the Free Software Foundation | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | */ | |
17 | ||
18 | #include <linux/uaccess.h> | |
19 | #include "bfad_drv.h" | |
20 | #include "bfad_im.h" | |
21 | #include "bfad_bsg.h" | |
22 | ||
23 | BFA_TRC_FILE(LDRV, BSG); | |
24 | ||
25 | /* bfad_im_bsg_get_kobject - increment the bfa refcnt */ | |
26 | static void | |
27 | bfad_im_bsg_get_kobject(struct fc_bsg_job *job) | |
28 | { | |
29 | struct Scsi_Host *shost = job->shost; | |
30 | unsigned long flags; | |
31 | ||
32 | spin_lock_irqsave(shost->host_lock, flags); | |
33 | __module_get(shost->dma_dev->driver->owner); | |
34 | spin_unlock_irqrestore(shost->host_lock, flags); | |
35 | } | |
36 | ||
37 | /* bfad_im_bsg_put_kobject - decrement the bfa refcnt */ | |
38 | static void | |
39 | bfad_im_bsg_put_kobject(struct fc_bsg_job *job) | |
40 | { | |
41 | struct Scsi_Host *shost = job->shost; | |
42 | unsigned long flags; | |
43 | ||
44 | spin_lock_irqsave(shost->host_lock, flags); | |
45 | module_put(shost->dma_dev->driver->owner); | |
46 | spin_unlock_irqrestore(shost->host_lock, flags); | |
47 | } | |
48 | ||
60138066 KG |
49 | int |
50 | bfad_iocmd_ioc_enable(struct bfad_s *bfad, void *cmd) | |
51 | { | |
52 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
53 | int rc = 0; | |
54 | unsigned long flags; | |
55 | ||
56 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
57 | /* If IOC is not in disabled state - return */ | |
58 | if (!bfa_ioc_is_disabled(&bfad->bfa.ioc)) { | |
59 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
60 | iocmd->status = BFA_STATUS_IOC_FAILURE; | |
61 | return rc; | |
62 | } | |
63 | ||
64 | init_completion(&bfad->enable_comp); | |
65 | bfa_iocfc_enable(&bfad->bfa); | |
66 | iocmd->status = BFA_STATUS_OK; | |
67 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
68 | wait_for_completion(&bfad->enable_comp); | |
69 | ||
70 | return rc; | |
71 | } | |
72 | ||
73 | int | |
74 | bfad_iocmd_ioc_disable(struct bfad_s *bfad, void *cmd) | |
75 | { | |
76 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
77 | int rc = 0; | |
78 | unsigned long flags; | |
79 | ||
80 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
81 | if (bfad->disable_active) { | |
82 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
83 | return EBUSY; | |
84 | } | |
85 | ||
86 | bfad->disable_active = BFA_TRUE; | |
87 | init_completion(&bfad->disable_comp); | |
88 | bfa_iocfc_disable(&bfad->bfa); | |
89 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
90 | ||
91 | wait_for_completion(&bfad->disable_comp); | |
92 | bfad->disable_active = BFA_FALSE; | |
93 | iocmd->status = BFA_STATUS_OK; | |
94 | ||
95 | return rc; | |
96 | } | |
97 | ||
b85daafe KG |
98 | static int |
99 | bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd) | |
100 | { | |
101 | int i; | |
102 | struct bfa_bsg_ioc_info_s *iocmd = (struct bfa_bsg_ioc_info_s *)cmd; | |
103 | struct bfad_im_port_s *im_port; | |
104 | struct bfa_port_attr_s pattr; | |
105 | unsigned long flags; | |
106 | ||
107 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
108 | bfa_fcport_get_attr(&bfad->bfa, &pattr); | |
109 | iocmd->nwwn = pattr.nwwn; | |
110 | iocmd->pwwn = pattr.pwwn; | |
111 | iocmd->ioc_type = bfa_get_type(&bfad->bfa); | |
112 | iocmd->mac = bfa_get_mac(&bfad->bfa); | |
113 | iocmd->factory_mac = bfa_get_mfg_mac(&bfad->bfa); | |
114 | bfa_get_adapter_serial_num(&bfad->bfa, iocmd->serialnum); | |
115 | iocmd->factorynwwn = pattr.factorynwwn; | |
116 | iocmd->factorypwwn = pattr.factorypwwn; | |
117 | im_port = bfad->pport.im_port; | |
118 | iocmd->host = im_port->shost->host_no; | |
119 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
120 | ||
121 | strcpy(iocmd->name, bfad->adapter_name); | |
122 | strcpy(iocmd->port_name, bfad->port_name); | |
123 | strcpy(iocmd->hwpath, bfad->pci_name); | |
124 | ||
125 | /* set adapter hw path */ | |
126 | strcpy(iocmd->adapter_hwpath, bfad->pci_name); | |
127 | i = strlen(iocmd->adapter_hwpath) - 1; | |
128 | while (iocmd->adapter_hwpath[i] != '.') | |
129 | i--; | |
130 | iocmd->adapter_hwpath[i] = '\0'; | |
131 | iocmd->status = BFA_STATUS_OK; | |
132 | return 0; | |
133 | } | |
134 | ||
135 | static int | |
136 | bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd) | |
137 | { | |
138 | struct bfa_bsg_ioc_attr_s *iocmd = (struct bfa_bsg_ioc_attr_s *)cmd; | |
139 | unsigned long flags; | |
140 | ||
141 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
142 | bfa_ioc_get_attr(&bfad->bfa.ioc, &iocmd->ioc_attr); | |
143 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
144 | ||
145 | /* fill in driver attr info */ | |
146 | strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME); | |
147 | strncpy(iocmd->ioc_attr.driver_attr.driver_ver, | |
148 | BFAD_DRIVER_VERSION, BFA_VERSION_LEN); | |
149 | strcpy(iocmd->ioc_attr.driver_attr.fw_ver, | |
150 | iocmd->ioc_attr.adapter_attr.fw_ver); | |
151 | strcpy(iocmd->ioc_attr.driver_attr.bios_ver, | |
152 | iocmd->ioc_attr.adapter_attr.optrom_ver); | |
153 | ||
154 | /* copy chip rev info first otherwise it will be overwritten */ | |
155 | memcpy(bfad->pci_attr.chip_rev, iocmd->ioc_attr.pci_attr.chip_rev, | |
156 | sizeof(bfad->pci_attr.chip_rev)); | |
157 | memcpy(&iocmd->ioc_attr.pci_attr, &bfad->pci_attr, | |
158 | sizeof(struct bfa_ioc_pci_attr_s)); | |
159 | ||
160 | iocmd->status = BFA_STATUS_OK; | |
161 | return 0; | |
162 | } | |
163 | ||
60138066 KG |
164 | int |
165 | bfad_iocmd_ioc_get_stats(struct bfad_s *bfad, void *cmd) | |
166 | { | |
167 | struct bfa_bsg_ioc_stats_s *iocmd = (struct bfa_bsg_ioc_stats_s *)cmd; | |
168 | ||
169 | bfa_ioc_get_stats(&bfad->bfa, &iocmd->ioc_stats); | |
170 | iocmd->status = BFA_STATUS_OK; | |
171 | return 0; | |
172 | } | |
173 | ||
174 | int | |
175 | bfad_iocmd_ioc_get_fwstats(struct bfad_s *bfad, void *cmd, | |
176 | unsigned int payload_len) | |
177 | { | |
178 | struct bfa_bsg_ioc_fwstats_s *iocmd = | |
179 | (struct bfa_bsg_ioc_fwstats_s *)cmd; | |
180 | void *iocmd_bufptr; | |
181 | unsigned long flags; | |
182 | ||
183 | if (bfad_chk_iocmd_sz(payload_len, | |
184 | sizeof(struct bfa_bsg_ioc_fwstats_s), | |
185 | sizeof(struct bfa_fw_stats_s)) != BFA_STATUS_OK) { | |
186 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
187 | goto out; | |
188 | } | |
189 | ||
190 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_ioc_fwstats_s); | |
191 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
192 | iocmd->status = bfa_ioc_fw_stats_get(&bfad->bfa.ioc, iocmd_bufptr); | |
193 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
194 | ||
195 | if (iocmd->status != BFA_STATUS_OK) { | |
196 | bfa_trc(bfad, iocmd->status); | |
197 | goto out; | |
198 | } | |
199 | out: | |
200 | bfa_trc(bfad, 0x6666); | |
201 | return 0; | |
202 | } | |
203 | ||
204 | int | |
205 | bfad_iocmd_iocfc_get_attr(struct bfad_s *bfad, void *cmd) | |
206 | { | |
207 | struct bfa_bsg_iocfc_attr_s *iocmd = (struct bfa_bsg_iocfc_attr_s *)cmd; | |
208 | ||
209 | iocmd->status = BFA_STATUS_OK; | |
210 | bfa_iocfc_get_attr(&bfad->bfa, &iocmd->iocfc_attr); | |
211 | ||
212 | return 0; | |
213 | } | |
214 | ||
215 | int | |
216 | bfad_iocmd_iocfc_set_intr(struct bfad_s *bfad, void *cmd) | |
217 | { | |
218 | struct bfa_bsg_iocfc_intr_s *iocmd = (struct bfa_bsg_iocfc_intr_s *)cmd; | |
219 | unsigned long flags; | |
220 | ||
221 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
222 | iocmd->status = bfa_iocfc_israttr_set(&bfad->bfa, &iocmd->attr); | |
223 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
224 | ||
225 | return 0; | |
226 | } | |
227 | ||
228 | int | |
229 | bfad_iocmd_port_enable(struct bfad_s *bfad, void *cmd) | |
230 | { | |
231 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
232 | struct bfad_hal_comp fcomp; | |
233 | unsigned long flags; | |
234 | ||
235 | init_completion(&fcomp.comp); | |
236 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
237 | iocmd->status = bfa_port_enable(&bfad->bfa.modules.port, | |
238 | bfad_hcb_comp, &fcomp); | |
239 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
240 | if (iocmd->status != BFA_STATUS_OK) { | |
241 | bfa_trc(bfad, iocmd->status); | |
242 | return 0; | |
243 | } | |
244 | wait_for_completion(&fcomp.comp); | |
245 | iocmd->status = fcomp.status; | |
246 | return 0; | |
247 | } | |
248 | ||
249 | int | |
250 | bfad_iocmd_port_disable(struct bfad_s *bfad, void *cmd) | |
251 | { | |
252 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
253 | struct bfad_hal_comp fcomp; | |
254 | unsigned long flags; | |
255 | ||
256 | init_completion(&fcomp.comp); | |
257 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
258 | iocmd->status = bfa_port_disable(&bfad->bfa.modules.port, | |
259 | bfad_hcb_comp, &fcomp); | |
260 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
261 | ||
262 | if (iocmd->status != BFA_STATUS_OK) { | |
263 | bfa_trc(bfad, iocmd->status); | |
264 | return 0; | |
265 | } | |
266 | wait_for_completion(&fcomp.comp); | |
267 | iocmd->status = fcomp.status; | |
268 | return 0; | |
269 | } | |
270 | ||
b85daafe KG |
271 | static int |
272 | bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd) | |
273 | { | |
274 | struct bfa_bsg_port_attr_s *iocmd = (struct bfa_bsg_port_attr_s *)cmd; | |
275 | struct bfa_lport_attr_s port_attr; | |
276 | unsigned long flags; | |
277 | ||
278 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
279 | bfa_fcport_get_attr(&bfad->bfa, &iocmd->attr); | |
280 | bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); | |
281 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
282 | ||
283 | if (iocmd->attr.topology != BFA_PORT_TOPOLOGY_NONE) | |
284 | iocmd->attr.pid = port_attr.pid; | |
285 | else | |
286 | iocmd->attr.pid = 0; | |
287 | ||
288 | iocmd->attr.port_type = port_attr.port_type; | |
289 | iocmd->attr.loopback = port_attr.loopback; | |
290 | iocmd->attr.authfail = port_attr.authfail; | |
291 | strncpy(iocmd->attr.port_symname.symname, | |
292 | port_attr.port_cfg.sym_name.symname, | |
293 | sizeof(port_attr.port_cfg.sym_name.symname)); | |
294 | ||
295 | iocmd->status = BFA_STATUS_OK; | |
296 | return 0; | |
297 | } | |
298 | ||
60138066 KG |
299 | int |
300 | bfad_iocmd_port_get_stats(struct bfad_s *bfad, void *cmd, | |
301 | unsigned int payload_len) | |
302 | { | |
303 | struct bfa_bsg_port_stats_s *iocmd = (struct bfa_bsg_port_stats_s *)cmd; | |
304 | struct bfad_hal_comp fcomp; | |
305 | void *iocmd_bufptr; | |
306 | unsigned long flags; | |
307 | ||
308 | if (bfad_chk_iocmd_sz(payload_len, | |
309 | sizeof(struct bfa_bsg_port_stats_s), | |
310 | sizeof(union bfa_port_stats_u)) != BFA_STATUS_OK) { | |
311 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
312 | return 0; | |
313 | } | |
314 | ||
315 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_port_stats_s); | |
316 | ||
317 | init_completion(&fcomp.comp); | |
318 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
319 | iocmd->status = bfa_port_get_stats(&bfad->bfa.modules.port, | |
320 | iocmd_bufptr, bfad_hcb_comp, &fcomp); | |
321 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
322 | if (iocmd->status != BFA_STATUS_OK) { | |
323 | bfa_trc(bfad, iocmd->status); | |
324 | goto out; | |
325 | } | |
326 | ||
327 | wait_for_completion(&fcomp.comp); | |
328 | iocmd->status = fcomp.status; | |
329 | out: | |
330 | return 0; | |
331 | } | |
332 | ||
b85daafe KG |
333 | static int |
334 | bfad_iocmd_lport_get_attr(struct bfad_s *bfad, void *cmd) | |
335 | { | |
336 | struct bfa_fcs_lport_s *fcs_port; | |
337 | struct bfa_bsg_lport_attr_s *iocmd = (struct bfa_bsg_lport_attr_s *)cmd; | |
338 | unsigned long flags; | |
339 | ||
340 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
341 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
342 | iocmd->vf_id, iocmd->pwwn); | |
343 | if (fcs_port == NULL) { | |
344 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
345 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
346 | goto out; | |
347 | } | |
348 | ||
349 | bfa_fcs_lport_get_attr(fcs_port, &iocmd->port_attr); | |
350 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
351 | iocmd->status = BFA_STATUS_OK; | |
352 | out: | |
353 | return 0; | |
354 | } | |
355 | ||
60138066 KG |
356 | int |
357 | bfad_iocmd_lport_get_stats(struct bfad_s *bfad, void *cmd) | |
358 | { | |
359 | struct bfa_fcs_lport_s *fcs_port; | |
360 | struct bfa_bsg_lport_stats_s *iocmd = | |
361 | (struct bfa_bsg_lport_stats_s *)cmd; | |
362 | unsigned long flags; | |
363 | ||
364 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
365 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
366 | iocmd->vf_id, iocmd->pwwn); | |
367 | if (fcs_port == NULL) { | |
368 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
369 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
370 | goto out; | |
371 | } | |
372 | ||
373 | bfa_fcs_lport_get_stats(fcs_port, &iocmd->port_stats); | |
374 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
375 | iocmd->status = BFA_STATUS_OK; | |
376 | out: | |
377 | return 0; | |
378 | } | |
379 | ||
380 | int | |
381 | bfad_iocmd_lport_get_iostats(struct bfad_s *bfad, void *cmd) | |
382 | { | |
383 | struct bfa_fcs_lport_s *fcs_port; | |
384 | struct bfa_bsg_lport_iostats_s *iocmd = | |
385 | (struct bfa_bsg_lport_iostats_s *)cmd; | |
386 | unsigned long flags; | |
387 | ||
388 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
389 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
390 | iocmd->vf_id, iocmd->pwwn); | |
391 | if (fcs_port == NULL) { | |
392 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
393 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
394 | goto out; | |
395 | } | |
396 | ||
397 | bfa_fcpim_port_iostats(&bfad->bfa, &iocmd->iostats, | |
398 | fcs_port->lp_tag); | |
399 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
400 | iocmd->status = BFA_STATUS_OK; | |
401 | out: | |
402 | return 0; | |
403 | } | |
404 | ||
405 | int | |
406 | bfad_iocmd_lport_get_rports(struct bfad_s *bfad, void *cmd, | |
407 | unsigned int payload_len) | |
408 | { | |
409 | struct bfa_bsg_lport_get_rports_s *iocmd = | |
410 | (struct bfa_bsg_lport_get_rports_s *)cmd; | |
411 | struct bfa_fcs_lport_s *fcs_port; | |
412 | unsigned long flags; | |
413 | void *iocmd_bufptr; | |
414 | ||
415 | if (iocmd->nrports == 0) | |
416 | return EINVAL; | |
417 | ||
418 | if (bfad_chk_iocmd_sz(payload_len, | |
419 | sizeof(struct bfa_bsg_lport_get_rports_s), | |
420 | sizeof(wwn_t) * iocmd->nrports) != BFA_STATUS_OK) { | |
421 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
422 | return 0; | |
423 | } | |
424 | ||
425 | iocmd_bufptr = (char *)iocmd + | |
426 | sizeof(struct bfa_bsg_lport_get_rports_s); | |
427 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
428 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
429 | iocmd->vf_id, iocmd->pwwn); | |
430 | if (fcs_port == NULL) { | |
431 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
432 | bfa_trc(bfad, 0); | |
433 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
434 | goto out; | |
435 | } | |
436 | ||
437 | bfa_fcs_lport_get_rports(fcs_port, (wwn_t *)iocmd_bufptr, | |
438 | &iocmd->nrports); | |
439 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
440 | iocmd->status = BFA_STATUS_OK; | |
441 | out: | |
442 | return 0; | |
443 | } | |
444 | ||
445 | int | |
446 | bfad_iocmd_rport_get_attr(struct bfad_s *bfad, void *cmd) | |
447 | { | |
448 | struct bfa_bsg_rport_attr_s *iocmd = (struct bfa_bsg_rport_attr_s *)cmd; | |
449 | struct bfa_fcs_lport_s *fcs_port; | |
450 | struct bfa_fcs_rport_s *fcs_rport; | |
451 | unsigned long flags; | |
452 | ||
453 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
454 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
455 | iocmd->vf_id, iocmd->pwwn); | |
456 | if (fcs_port == NULL) { | |
457 | bfa_trc(bfad, 0); | |
458 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
459 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
460 | goto out; | |
461 | } | |
462 | ||
463 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); | |
464 | if (fcs_rport == NULL) { | |
465 | bfa_trc(bfad, 0); | |
466 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
467 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
468 | goto out; | |
469 | } | |
470 | ||
471 | bfa_fcs_rport_get_attr(fcs_rport, &iocmd->attr); | |
472 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
473 | iocmd->status = BFA_STATUS_OK; | |
474 | out: | |
475 | return 0; | |
476 | } | |
477 | ||
b85daafe KG |
478 | static int |
479 | bfad_iocmd_rport_get_addr(struct bfad_s *bfad, void *cmd) | |
480 | { | |
481 | struct bfa_bsg_rport_scsi_addr_s *iocmd = | |
482 | (struct bfa_bsg_rport_scsi_addr_s *)cmd; | |
483 | struct bfa_fcs_lport_s *fcs_port; | |
484 | struct bfa_fcs_itnim_s *fcs_itnim; | |
485 | struct bfad_itnim_s *drv_itnim; | |
486 | unsigned long flags; | |
487 | ||
488 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
489 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
490 | iocmd->vf_id, iocmd->pwwn); | |
491 | if (fcs_port == NULL) { | |
492 | bfa_trc(bfad, 0); | |
493 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
494 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
495 | goto out; | |
496 | } | |
497 | ||
498 | fcs_itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
499 | if (fcs_itnim == NULL) { | |
500 | bfa_trc(bfad, 0); | |
501 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
502 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
503 | goto out; | |
504 | } | |
505 | ||
506 | drv_itnim = fcs_itnim->itnim_drv; | |
507 | ||
508 | if (drv_itnim && drv_itnim->im_port) | |
509 | iocmd->host = drv_itnim->im_port->shost->host_no; | |
510 | else { | |
511 | bfa_trc(bfad, 0); | |
512 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
513 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
514 | goto out; | |
515 | } | |
516 | ||
517 | iocmd->target = drv_itnim->scsi_tgt_id; | |
518 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
519 | ||
520 | iocmd->bus = 0; | |
521 | iocmd->lun = 0; | |
522 | iocmd->status = BFA_STATUS_OK; | |
523 | out: | |
524 | return 0; | |
525 | } | |
526 | ||
60138066 KG |
527 | int |
528 | bfad_iocmd_rport_get_stats(struct bfad_s *bfad, void *cmd) | |
529 | { | |
530 | struct bfa_bsg_rport_stats_s *iocmd = | |
531 | (struct bfa_bsg_rport_stats_s *)cmd; | |
532 | struct bfa_fcs_lport_s *fcs_port; | |
533 | struct bfa_fcs_rport_s *fcs_rport; | |
534 | unsigned long flags; | |
535 | ||
536 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
537 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
538 | iocmd->vf_id, iocmd->pwwn); | |
539 | if (fcs_port == NULL) { | |
540 | bfa_trc(bfad, 0); | |
541 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
542 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
543 | goto out; | |
544 | } | |
545 | ||
546 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); | |
547 | if (fcs_rport == NULL) { | |
548 | bfa_trc(bfad, 0); | |
549 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
550 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
551 | goto out; | |
552 | } | |
553 | ||
554 | memcpy((void *)&iocmd->stats, (void *)&fcs_rport->stats, | |
555 | sizeof(struct bfa_rport_stats_s)); | |
556 | memcpy((void *)&iocmd->stats.hal_stats, | |
557 | (void *)&(bfa_fcs_rport_get_halrport(fcs_rport)->stats), | |
558 | sizeof(struct bfa_rport_hal_stats_s)); | |
559 | ||
560 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
561 | iocmd->status = BFA_STATUS_OK; | |
562 | out: | |
563 | return 0; | |
564 | } | |
565 | ||
b85daafe KG |
566 | static int |
567 | bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd, | |
568 | unsigned int payload_len) | |
569 | { | |
570 | struct bfa_bsg_fabric_get_lports_s *iocmd = | |
571 | (struct bfa_bsg_fabric_get_lports_s *)cmd; | |
572 | bfa_fcs_vf_t *fcs_vf; | |
573 | uint32_t nports = iocmd->nports; | |
574 | unsigned long flags; | |
575 | void *iocmd_bufptr; | |
576 | ||
577 | if (nports == 0) { | |
578 | iocmd->status = BFA_STATUS_EINVAL; | |
579 | goto out; | |
580 | } | |
581 | ||
582 | if (bfad_chk_iocmd_sz(payload_len, | |
583 | sizeof(struct bfa_bsg_fabric_get_lports_s), | |
584 | sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) { | |
585 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
586 | goto out; | |
587 | } | |
588 | ||
589 | iocmd_bufptr = (char *)iocmd + | |
590 | sizeof(struct bfa_bsg_fabric_get_lports_s); | |
591 | ||
592 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
593 | fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id); | |
594 | if (fcs_vf == NULL) { | |
595 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
596 | iocmd->status = BFA_STATUS_UNKNOWN_VFID; | |
597 | goto out; | |
598 | } | |
599 | bfa_fcs_vf_get_ports(fcs_vf, (wwn_t *)iocmd_bufptr, &nports); | |
600 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
601 | ||
602 | iocmd->nports = nports; | |
603 | iocmd->status = BFA_STATUS_OK; | |
604 | out: | |
605 | return 0; | |
606 | } | |
607 | ||
60138066 KG |
608 | int |
609 | bfad_iocmd_fcpim_get_modstats(struct bfad_s *bfad, void *cmd) | |
610 | { | |
611 | struct bfa_bsg_fcpim_modstats_s *iocmd = | |
612 | (struct bfa_bsg_fcpim_modstats_s *)cmd; | |
613 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); | |
614 | struct list_head *qe, *qen; | |
615 | struct bfa_itnim_s *itnim; | |
616 | unsigned long flags; | |
617 | ||
618 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
619 | /* accumulate IO stats from itnim */ | |
620 | memset((void *)&iocmd->modstats, 0, sizeof(struct bfa_itnim_iostats_s)); | |
621 | list_for_each_safe(qe, qen, &fcpim->itnim_q) { | |
622 | itnim = (struct bfa_itnim_s *) qe; | |
623 | bfa_fcpim_add_stats(&iocmd->modstats, &(itnim->stats)); | |
624 | } | |
625 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
626 | iocmd->status = BFA_STATUS_OK; | |
627 | return 0; | |
628 | } | |
629 | ||
630 | int | |
631 | bfad_iocmd_fcpim_get_del_itn_stats(struct bfad_s *bfad, void *cmd) | |
632 | { | |
633 | struct bfa_bsg_fcpim_del_itn_stats_s *iocmd = | |
634 | (struct bfa_bsg_fcpim_del_itn_stats_s *)cmd; | |
635 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); | |
636 | unsigned long flags; | |
637 | ||
638 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
639 | memcpy((void *)&iocmd->modstats, (void *)&fcpim->del_itn_stats, | |
640 | sizeof(struct bfa_fcpim_del_itn_stats_s)); | |
641 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
642 | ||
643 | iocmd->status = BFA_STATUS_OK; | |
644 | return 0; | |
645 | } | |
646 | ||
b85daafe KG |
647 | static int |
648 | bfad_iocmd_itnim_get_attr(struct bfad_s *bfad, void *cmd) | |
649 | { | |
650 | struct bfa_bsg_itnim_attr_s *iocmd = (struct bfa_bsg_itnim_attr_s *)cmd; | |
651 | struct bfa_fcs_lport_s *fcs_port; | |
652 | unsigned long flags; | |
653 | ||
654 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
655 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
656 | iocmd->vf_id, iocmd->lpwwn); | |
657 | if (!fcs_port) | |
658 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
659 | else | |
660 | iocmd->status = bfa_fcs_itnim_attr_get(fcs_port, | |
661 | iocmd->rpwwn, &iocmd->attr); | |
662 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
663 | return 0; | |
664 | } | |
665 | ||
60138066 KG |
666 | static int |
667 | bfad_iocmd_itnim_get_iostats(struct bfad_s *bfad, void *cmd) | |
668 | { | |
669 | struct bfa_bsg_itnim_iostats_s *iocmd = | |
670 | (struct bfa_bsg_itnim_iostats_s *)cmd; | |
671 | struct bfa_fcs_lport_s *fcs_port; | |
672 | struct bfa_fcs_itnim_s *itnim; | |
673 | unsigned long flags; | |
674 | ||
675 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
676 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
677 | iocmd->vf_id, iocmd->lpwwn); | |
678 | if (!fcs_port) { | |
679 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
680 | bfa_trc(bfad, 0); | |
681 | } else { | |
682 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
683 | if (itnim == NULL) | |
684 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
685 | else { | |
686 | iocmd->status = BFA_STATUS_OK; | |
687 | memcpy((void *)&iocmd->iostats, (void *) | |
688 | &(bfa_fcs_itnim_get_halitn(itnim)->stats), | |
689 | sizeof(struct bfa_itnim_iostats_s)); | |
690 | } | |
691 | } | |
692 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
693 | return 0; | |
694 | } | |
695 | ||
696 | static int | |
697 | bfad_iocmd_itnim_get_itnstats(struct bfad_s *bfad, void *cmd) | |
698 | { | |
699 | struct bfa_bsg_itnim_itnstats_s *iocmd = | |
700 | (struct bfa_bsg_itnim_itnstats_s *)cmd; | |
701 | struct bfa_fcs_lport_s *fcs_port; | |
702 | struct bfa_fcs_itnim_s *itnim; | |
703 | unsigned long flags; | |
704 | ||
705 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
706 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
707 | iocmd->vf_id, iocmd->lpwwn); | |
708 | if (!fcs_port) { | |
709 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
710 | bfa_trc(bfad, 0); | |
711 | } else { | |
712 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
713 | if (itnim == NULL) | |
714 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
715 | else { | |
716 | iocmd->status = BFA_STATUS_OK; | |
717 | bfa_fcs_itnim_stats_get(fcs_port, iocmd->rpwwn, | |
718 | &iocmd->itnstats); | |
719 | } | |
720 | } | |
721 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
722 | return 0; | |
723 | } | |
724 | ||
725 | int | |
726 | bfad_iocmd_fcport_enable(struct bfad_s *bfad, void *cmd) | |
727 | { | |
728 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
729 | unsigned long flags; | |
730 | ||
731 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
732 | iocmd->status = bfa_fcport_enable(&bfad->bfa); | |
733 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
734 | ||
735 | return 0; | |
736 | } | |
737 | ||
738 | int | |
739 | bfad_iocmd_fcport_disable(struct bfad_s *bfad, void *cmd) | |
740 | { | |
741 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
742 | unsigned long flags; | |
743 | ||
744 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
745 | iocmd->status = bfa_fcport_disable(&bfad->bfa); | |
746 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
747 | ||
748 | return 0; | |
749 | } | |
750 | ||
1a4d8e1b KG |
751 | int |
752 | bfad_iocmd_ioc_get_pcifn_cfg(struct bfad_s *bfad, void *cmd) | |
753 | { | |
754 | struct bfa_bsg_pcifn_cfg_s *iocmd = (struct bfa_bsg_pcifn_cfg_s *)cmd; | |
755 | struct bfad_hal_comp fcomp; | |
756 | unsigned long flags; | |
757 | ||
758 | init_completion(&fcomp.comp); | |
759 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
760 | iocmd->status = bfa_ablk_query(&bfad->bfa.modules.ablk, | |
761 | &iocmd->pcifn_cfg, | |
762 | bfad_hcb_comp, &fcomp); | |
763 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
764 | if (iocmd->status != BFA_STATUS_OK) | |
765 | goto out; | |
766 | ||
767 | wait_for_completion(&fcomp.comp); | |
768 | iocmd->status = fcomp.status; | |
769 | out: | |
770 | return 0; | |
771 | } | |
772 | ||
773 | int | |
774 | bfad_iocmd_pcifn_create(struct bfad_s *bfad, void *cmd) | |
775 | { | |
776 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; | |
777 | struct bfad_hal_comp fcomp; | |
778 | unsigned long flags; | |
779 | ||
780 | init_completion(&fcomp.comp); | |
781 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
782 | iocmd->status = bfa_ablk_pf_create(&bfad->bfa.modules.ablk, | |
783 | &iocmd->pcifn_id, iocmd->port, | |
784 | iocmd->pcifn_class, iocmd->bandwidth, | |
785 | bfad_hcb_comp, &fcomp); | |
786 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
787 | if (iocmd->status != BFA_STATUS_OK) | |
788 | goto out; | |
789 | ||
790 | wait_for_completion(&fcomp.comp); | |
791 | iocmd->status = fcomp.status; | |
792 | out: | |
793 | return 0; | |
794 | } | |
795 | ||
796 | int | |
797 | bfad_iocmd_pcifn_delete(struct bfad_s *bfad, void *cmd) | |
798 | { | |
799 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; | |
800 | struct bfad_hal_comp fcomp; | |
801 | unsigned long flags; | |
802 | ||
803 | init_completion(&fcomp.comp); | |
804 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
805 | iocmd->status = bfa_ablk_pf_delete(&bfad->bfa.modules.ablk, | |
806 | iocmd->pcifn_id, | |
807 | bfad_hcb_comp, &fcomp); | |
808 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
809 | if (iocmd->status != BFA_STATUS_OK) | |
810 | goto out; | |
811 | ||
812 | wait_for_completion(&fcomp.comp); | |
813 | iocmd->status = fcomp.status; | |
814 | out: | |
815 | return 0; | |
816 | } | |
817 | ||
818 | int | |
819 | bfad_iocmd_pcifn_bw(struct bfad_s *bfad, void *cmd) | |
820 | { | |
821 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; | |
822 | struct bfad_hal_comp fcomp; | |
823 | unsigned long flags; | |
824 | ||
825 | init_completion(&fcomp.comp); | |
826 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
827 | iocmd->status = bfa_ablk_pf_update(&bfad->bfa.modules.ablk, | |
828 | iocmd->pcifn_id, iocmd->bandwidth, | |
829 | bfad_hcb_comp, &fcomp); | |
830 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
831 | bfa_trc(bfad, iocmd->status); | |
832 | if (iocmd->status != BFA_STATUS_OK) | |
833 | goto out; | |
834 | ||
835 | wait_for_completion(&fcomp.comp); | |
836 | iocmd->status = fcomp.status; | |
837 | bfa_trc(bfad, iocmd->status); | |
838 | out: | |
839 | return 0; | |
840 | } | |
841 | ||
842 | int | |
843 | bfad_iocmd_adapter_cfg_mode(struct bfad_s *bfad, void *cmd) | |
844 | { | |
845 | struct bfa_bsg_adapter_cfg_mode_s *iocmd = | |
846 | (struct bfa_bsg_adapter_cfg_mode_s *)cmd; | |
847 | struct bfad_hal_comp fcomp; | |
848 | unsigned long flags = 0; | |
849 | ||
850 | init_completion(&fcomp.comp); | |
851 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
852 | iocmd->status = bfa_ablk_adapter_config(&bfad->bfa.modules.ablk, | |
853 | iocmd->cfg.mode, iocmd->cfg.max_pf, | |
854 | iocmd->cfg.max_vf, bfad_hcb_comp, &fcomp); | |
855 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
856 | if (iocmd->status != BFA_STATUS_OK) | |
857 | goto out; | |
858 | ||
859 | wait_for_completion(&fcomp.comp); | |
860 | iocmd->status = fcomp.status; | |
861 | out: | |
862 | return 0; | |
863 | } | |
864 | ||
865 | int | |
866 | bfad_iocmd_port_cfg_mode(struct bfad_s *bfad, void *cmd) | |
867 | { | |
868 | struct bfa_bsg_port_cfg_mode_s *iocmd = | |
869 | (struct bfa_bsg_port_cfg_mode_s *)cmd; | |
870 | struct bfad_hal_comp fcomp; | |
871 | unsigned long flags = 0; | |
872 | ||
873 | init_completion(&fcomp.comp); | |
874 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
875 | iocmd->status = bfa_ablk_port_config(&bfad->bfa.modules.ablk, | |
876 | iocmd->instance, iocmd->cfg.mode, | |
877 | iocmd->cfg.max_pf, iocmd->cfg.max_vf, | |
878 | bfad_hcb_comp, &fcomp); | |
879 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
880 | if (iocmd->status != BFA_STATUS_OK) | |
881 | goto out; | |
882 | ||
883 | wait_for_completion(&fcomp.comp); | |
884 | iocmd->status = fcomp.status; | |
885 | out: | |
886 | return 0; | |
887 | } | |
888 | ||
889 | int | |
890 | bfad_iocmd_ablk_optrom(struct bfad_s *bfad, unsigned int cmd, void *pcmd) | |
891 | { | |
892 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd; | |
893 | struct bfad_hal_comp fcomp; | |
894 | unsigned long flags; | |
895 | ||
896 | init_completion(&fcomp.comp); | |
897 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
898 | if (cmd == IOCMD_FLASH_ENABLE_OPTROM) | |
899 | iocmd->status = bfa_ablk_optrom_en(&bfad->bfa.modules.ablk, | |
900 | bfad_hcb_comp, &fcomp); | |
901 | else | |
902 | iocmd->status = bfa_ablk_optrom_dis(&bfad->bfa.modules.ablk, | |
903 | bfad_hcb_comp, &fcomp); | |
904 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
905 | ||
906 | if (iocmd->status != BFA_STATUS_OK) | |
907 | goto out; | |
908 | ||
909 | wait_for_completion(&fcomp.comp); | |
910 | iocmd->status = fcomp.status; | |
911 | out: | |
912 | return 0; | |
913 | } | |
914 | ||
a714134a KG |
915 | int |
916 | bfad_iocmd_faa_enable(struct bfad_s *bfad, void *cmd) | |
917 | { | |
918 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
919 | unsigned long flags; | |
920 | struct bfad_hal_comp fcomp; | |
921 | ||
922 | init_completion(&fcomp.comp); | |
923 | iocmd->status = BFA_STATUS_OK; | |
924 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
925 | iocmd->status = bfa_faa_enable(&bfad->bfa, bfad_hcb_comp, &fcomp); | |
926 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
927 | ||
928 | if (iocmd->status != BFA_STATUS_OK) | |
929 | goto out; | |
930 | ||
931 | wait_for_completion(&fcomp.comp); | |
932 | iocmd->status = fcomp.status; | |
933 | out: | |
934 | return 0; | |
935 | } | |
936 | ||
937 | int | |
938 | bfad_iocmd_faa_disable(struct bfad_s *bfad, void *cmd) | |
939 | { | |
940 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
941 | unsigned long flags; | |
942 | struct bfad_hal_comp fcomp; | |
943 | ||
944 | init_completion(&fcomp.comp); | |
945 | iocmd->status = BFA_STATUS_OK; | |
946 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
947 | iocmd->status = bfa_faa_disable(&bfad->bfa, bfad_hcb_comp, &fcomp); | |
948 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
949 | ||
950 | if (iocmd->status != BFA_STATUS_OK) | |
951 | goto out; | |
952 | ||
953 | wait_for_completion(&fcomp.comp); | |
954 | iocmd->status = fcomp.status; | |
955 | out: | |
956 | return 0; | |
957 | } | |
958 | ||
959 | int | |
960 | bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd) | |
961 | { | |
962 | struct bfa_bsg_faa_attr_s *iocmd = (struct bfa_bsg_faa_attr_s *)cmd; | |
963 | struct bfad_hal_comp fcomp; | |
964 | unsigned long flags; | |
965 | ||
966 | init_completion(&fcomp.comp); | |
967 | iocmd->status = BFA_STATUS_OK; | |
968 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
969 | iocmd->status = bfa_faa_query(&bfad->bfa, &iocmd->faa_attr, | |
970 | bfad_hcb_comp, &fcomp); | |
971 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
972 | ||
973 | if (iocmd->status != BFA_STATUS_OK) | |
974 | goto out; | |
975 | ||
976 | wait_for_completion(&fcomp.comp); | |
977 | iocmd->status = fcomp.status; | |
978 | out: | |
979 | return 0; | |
980 | } | |
981 | ||
148d6103 KG |
982 | int |
983 | bfad_iocmd_cee_attr(struct bfad_s *bfad, void *cmd, unsigned int payload_len) | |
984 | { | |
985 | struct bfa_bsg_cee_attr_s *iocmd = | |
986 | (struct bfa_bsg_cee_attr_s *)cmd; | |
987 | void *iocmd_bufptr; | |
988 | struct bfad_hal_comp cee_comp; | |
989 | unsigned long flags; | |
990 | ||
991 | if (bfad_chk_iocmd_sz(payload_len, | |
992 | sizeof(struct bfa_bsg_cee_attr_s), | |
993 | sizeof(struct bfa_cee_attr_s)) != BFA_STATUS_OK) { | |
994 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
995 | return 0; | |
996 | } | |
997 | ||
998 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_attr_s); | |
999 | ||
1000 | cee_comp.status = 0; | |
1001 | init_completion(&cee_comp.comp); | |
1002 | mutex_lock(&bfad_mutex); | |
1003 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1004 | iocmd->status = bfa_cee_get_attr(&bfad->bfa.modules.cee, iocmd_bufptr, | |
1005 | bfad_hcb_comp, &cee_comp); | |
1006 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1007 | if (iocmd->status != BFA_STATUS_OK) { | |
1008 | mutex_unlock(&bfad_mutex); | |
1009 | bfa_trc(bfad, 0x5555); | |
1010 | goto out; | |
1011 | } | |
1012 | wait_for_completion(&cee_comp.comp); | |
1013 | mutex_unlock(&bfad_mutex); | |
1014 | out: | |
1015 | return 0; | |
1016 | } | |
1017 | ||
1018 | int | |
1019 | bfad_iocmd_cee_get_stats(struct bfad_s *bfad, void *cmd, | |
1020 | unsigned int payload_len) | |
1021 | { | |
1022 | struct bfa_bsg_cee_stats_s *iocmd = | |
1023 | (struct bfa_bsg_cee_stats_s *)cmd; | |
1024 | void *iocmd_bufptr; | |
1025 | struct bfad_hal_comp cee_comp; | |
1026 | unsigned long flags; | |
1027 | ||
1028 | if (bfad_chk_iocmd_sz(payload_len, | |
1029 | sizeof(struct bfa_bsg_cee_stats_s), | |
1030 | sizeof(struct bfa_cee_stats_s)) != BFA_STATUS_OK) { | |
1031 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1032 | return 0; | |
1033 | } | |
1034 | ||
1035 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_stats_s); | |
1036 | ||
1037 | cee_comp.status = 0; | |
1038 | init_completion(&cee_comp.comp); | |
1039 | mutex_lock(&bfad_mutex); | |
1040 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1041 | iocmd->status = bfa_cee_get_stats(&bfad->bfa.modules.cee, iocmd_bufptr, | |
1042 | bfad_hcb_comp, &cee_comp); | |
1043 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1044 | if (iocmd->status != BFA_STATUS_OK) { | |
1045 | mutex_unlock(&bfad_mutex); | |
1046 | bfa_trc(bfad, 0x5555); | |
1047 | goto out; | |
1048 | } | |
1049 | wait_for_completion(&cee_comp.comp); | |
1050 | mutex_unlock(&bfad_mutex); | |
1051 | out: | |
1052 | return 0; | |
1053 | } | |
1054 | ||
1055 | int | |
1056 | bfad_iocmd_cee_reset_stats(struct bfad_s *bfad, void *cmd) | |
1057 | { | |
1058 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
1059 | unsigned long flags; | |
1060 | ||
1061 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1062 | iocmd->status = bfa_cee_reset_stats(&bfad->bfa.modules.cee, NULL, NULL); | |
1063 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1064 | if (iocmd->status != BFA_STATUS_OK) | |
1065 | bfa_trc(bfad, 0x5555); | |
1066 | return 0; | |
1067 | } | |
1068 | ||
51e569aa KG |
1069 | int |
1070 | bfad_iocmd_sfp_media(struct bfad_s *bfad, void *cmd) | |
1071 | { | |
1072 | struct bfa_bsg_sfp_media_s *iocmd = (struct bfa_bsg_sfp_media_s *)cmd; | |
1073 | struct bfad_hal_comp fcomp; | |
1074 | unsigned long flags; | |
1075 | ||
1076 | init_completion(&fcomp.comp); | |
1077 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1078 | iocmd->status = bfa_sfp_media(BFA_SFP_MOD(&bfad->bfa), &iocmd->media, | |
1079 | bfad_hcb_comp, &fcomp); | |
1080 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1081 | bfa_trc(bfad, iocmd->status); | |
1082 | if (iocmd->status != BFA_STATUS_SFP_NOT_READY) | |
1083 | goto out; | |
1084 | ||
1085 | wait_for_completion(&fcomp.comp); | |
1086 | iocmd->status = fcomp.status; | |
1087 | out: | |
1088 | return 0; | |
1089 | } | |
1090 | ||
1091 | int | |
1092 | bfad_iocmd_sfp_speed(struct bfad_s *bfad, void *cmd) | |
1093 | { | |
1094 | struct bfa_bsg_sfp_speed_s *iocmd = (struct bfa_bsg_sfp_speed_s *)cmd; | |
1095 | struct bfad_hal_comp fcomp; | |
1096 | unsigned long flags; | |
1097 | ||
1098 | init_completion(&fcomp.comp); | |
1099 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1100 | iocmd->status = bfa_sfp_speed(BFA_SFP_MOD(&bfad->bfa), iocmd->speed, | |
1101 | bfad_hcb_comp, &fcomp); | |
1102 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1103 | bfa_trc(bfad, iocmd->status); | |
1104 | if (iocmd->status != BFA_STATUS_SFP_NOT_READY) | |
1105 | goto out; | |
1106 | wait_for_completion(&fcomp.comp); | |
1107 | iocmd->status = fcomp.status; | |
1108 | out: | |
1109 | return 0; | |
1110 | } | |
1111 | ||
5a54b1d5 KG |
1112 | int |
1113 | bfad_iocmd_flash_get_attr(struct bfad_s *bfad, void *cmd) | |
1114 | { | |
1115 | struct bfa_bsg_flash_attr_s *iocmd = | |
1116 | (struct bfa_bsg_flash_attr_s *)cmd; | |
1117 | struct bfad_hal_comp fcomp; | |
1118 | unsigned long flags; | |
1119 | ||
1120 | init_completion(&fcomp.comp); | |
1121 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1122 | iocmd->status = bfa_flash_get_attr(BFA_FLASH(&bfad->bfa), &iocmd->attr, | |
1123 | bfad_hcb_comp, &fcomp); | |
1124 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1125 | if (iocmd->status != BFA_STATUS_OK) | |
1126 | goto out; | |
1127 | wait_for_completion(&fcomp.comp); | |
1128 | iocmd->status = fcomp.status; | |
1129 | out: | |
1130 | return 0; | |
1131 | } | |
1132 | ||
1133 | int | |
1134 | bfad_iocmd_flash_erase_part(struct bfad_s *bfad, void *cmd) | |
1135 | { | |
1136 | struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd; | |
1137 | struct bfad_hal_comp fcomp; | |
1138 | unsigned long flags; | |
1139 | ||
1140 | init_completion(&fcomp.comp); | |
1141 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1142 | iocmd->status = bfa_flash_erase_part(BFA_FLASH(&bfad->bfa), iocmd->type, | |
1143 | iocmd->instance, bfad_hcb_comp, &fcomp); | |
1144 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1145 | if (iocmd->status != BFA_STATUS_OK) | |
1146 | goto out; | |
1147 | wait_for_completion(&fcomp.comp); | |
1148 | iocmd->status = fcomp.status; | |
1149 | out: | |
1150 | return 0; | |
1151 | } | |
1152 | ||
1153 | int | |
1154 | bfad_iocmd_flash_update_part(struct bfad_s *bfad, void *cmd, | |
1155 | unsigned int payload_len) | |
1156 | { | |
1157 | struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd; | |
1158 | void *iocmd_bufptr; | |
1159 | struct bfad_hal_comp fcomp; | |
1160 | unsigned long flags; | |
1161 | ||
1162 | if (bfad_chk_iocmd_sz(payload_len, | |
1163 | sizeof(struct bfa_bsg_flash_s), | |
1164 | iocmd->bufsz) != BFA_STATUS_OK) { | |
1165 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1166 | return 0; | |
1167 | } | |
1168 | ||
1169 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s); | |
1170 | ||
1171 | init_completion(&fcomp.comp); | |
1172 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1173 | iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa), | |
1174 | iocmd->type, iocmd->instance, iocmd_bufptr, | |
1175 | iocmd->bufsz, 0, bfad_hcb_comp, &fcomp); | |
1176 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1177 | if (iocmd->status != BFA_STATUS_OK) | |
1178 | goto out; | |
1179 | wait_for_completion(&fcomp.comp); | |
1180 | iocmd->status = fcomp.status; | |
1181 | out: | |
1182 | return 0; | |
1183 | } | |
1184 | ||
1185 | int | |
1186 | bfad_iocmd_flash_read_part(struct bfad_s *bfad, void *cmd, | |
1187 | unsigned int payload_len) | |
1188 | { | |
1189 | struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd; | |
1190 | struct bfad_hal_comp fcomp; | |
1191 | void *iocmd_bufptr; | |
1192 | unsigned long flags; | |
1193 | ||
1194 | if (bfad_chk_iocmd_sz(payload_len, | |
1195 | sizeof(struct bfa_bsg_flash_s), | |
1196 | iocmd->bufsz) != BFA_STATUS_OK) { | |
1197 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1198 | return 0; | |
1199 | } | |
1200 | ||
1201 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s); | |
1202 | ||
1203 | init_completion(&fcomp.comp); | |
1204 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1205 | iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa), iocmd->type, | |
1206 | iocmd->instance, iocmd_bufptr, iocmd->bufsz, 0, | |
1207 | bfad_hcb_comp, &fcomp); | |
1208 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1209 | if (iocmd->status != BFA_STATUS_OK) | |
1210 | goto out; | |
1211 | wait_for_completion(&fcomp.comp); | |
1212 | iocmd->status = fcomp.status; | |
1213 | out: | |
1214 | return 0; | |
1215 | } | |
1216 | ||
b85daafe KG |
1217 | static int |
1218 | bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd, | |
1219 | unsigned int payload_len) | |
1220 | { | |
1221 | int rc = EINVAL; | |
1222 | ||
1223 | switch (cmd) { | |
60138066 KG |
1224 | case IOCMD_IOC_ENABLE: |
1225 | rc = bfad_iocmd_ioc_enable(bfad, iocmd); | |
1226 | break; | |
1227 | case IOCMD_IOC_DISABLE: | |
1228 | rc = bfad_iocmd_ioc_disable(bfad, iocmd); | |
1229 | break; | |
b85daafe KG |
1230 | case IOCMD_IOC_GET_INFO: |
1231 | rc = bfad_iocmd_ioc_get_info(bfad, iocmd); | |
1232 | break; | |
1233 | case IOCMD_IOC_GET_ATTR: | |
1234 | rc = bfad_iocmd_ioc_get_attr(bfad, iocmd); | |
1235 | break; | |
60138066 KG |
1236 | case IOCMD_IOC_GET_STATS: |
1237 | rc = bfad_iocmd_ioc_get_stats(bfad, iocmd); | |
1238 | break; | |
1239 | case IOCMD_IOC_GET_FWSTATS: | |
1240 | rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len); | |
1241 | break; | |
1242 | case IOCMD_IOCFC_GET_ATTR: | |
1243 | rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd); | |
1244 | break; | |
1245 | case IOCMD_IOCFC_SET_INTR: | |
1246 | rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd); | |
1247 | break; | |
1248 | case IOCMD_PORT_ENABLE: | |
1249 | rc = bfad_iocmd_port_enable(bfad, iocmd); | |
1250 | break; | |
1251 | case IOCMD_PORT_DISABLE: | |
1252 | rc = bfad_iocmd_port_disable(bfad, iocmd); | |
1253 | break; | |
b85daafe KG |
1254 | case IOCMD_PORT_GET_ATTR: |
1255 | rc = bfad_iocmd_port_get_attr(bfad, iocmd); | |
1256 | break; | |
60138066 KG |
1257 | case IOCMD_PORT_GET_STATS: |
1258 | rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len); | |
1259 | break; | |
b85daafe KG |
1260 | case IOCMD_LPORT_GET_ATTR: |
1261 | rc = bfad_iocmd_lport_get_attr(bfad, iocmd); | |
1262 | break; | |
60138066 KG |
1263 | case IOCMD_LPORT_GET_STATS: |
1264 | rc = bfad_iocmd_lport_get_stats(bfad, iocmd); | |
1265 | break; | |
1266 | case IOCMD_LPORT_GET_IOSTATS: | |
1267 | rc = bfad_iocmd_lport_get_iostats(bfad, iocmd); | |
1268 | break; | |
1269 | case IOCMD_LPORT_GET_RPORTS: | |
1270 | rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len); | |
1271 | break; | |
1272 | case IOCMD_RPORT_GET_ATTR: | |
1273 | rc = bfad_iocmd_rport_get_attr(bfad, iocmd); | |
1274 | break; | |
b85daafe KG |
1275 | case IOCMD_RPORT_GET_ADDR: |
1276 | rc = bfad_iocmd_rport_get_addr(bfad, iocmd); | |
1277 | break; | |
60138066 KG |
1278 | case IOCMD_RPORT_GET_STATS: |
1279 | rc = bfad_iocmd_rport_get_stats(bfad, iocmd); | |
1280 | break; | |
b85daafe KG |
1281 | case IOCMD_FABRIC_GET_LPORTS: |
1282 | rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len); | |
1283 | break; | |
60138066 KG |
1284 | case IOCMD_FCPIM_MODSTATS: |
1285 | rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd); | |
1286 | break; | |
1287 | case IOCMD_FCPIM_DEL_ITN_STATS: | |
1288 | rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd); | |
1289 | break; | |
b85daafe KG |
1290 | case IOCMD_ITNIM_GET_ATTR: |
1291 | rc = bfad_iocmd_itnim_get_attr(bfad, iocmd); | |
1292 | break; | |
60138066 KG |
1293 | case IOCMD_ITNIM_GET_IOSTATS: |
1294 | rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd); | |
1295 | break; | |
1296 | case IOCMD_ITNIM_GET_ITNSTATS: | |
1297 | rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd); | |
1298 | break; | |
1299 | case IOCMD_FCPORT_ENABLE: | |
1300 | rc = bfad_iocmd_fcport_enable(bfad, iocmd); | |
1301 | break; | |
1302 | case IOCMD_FCPORT_DISABLE: | |
1303 | rc = bfad_iocmd_fcport_disable(bfad, iocmd); | |
1304 | break; | |
1a4d8e1b KG |
1305 | case IOCMD_IOC_PCIFN_CFG: |
1306 | rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd); | |
1307 | break; | |
1308 | case IOCMD_PCIFN_CREATE: | |
1309 | rc = bfad_iocmd_pcifn_create(bfad, iocmd); | |
1310 | break; | |
1311 | case IOCMD_PCIFN_DELETE: | |
1312 | rc = bfad_iocmd_pcifn_delete(bfad, iocmd); | |
1313 | break; | |
1314 | case IOCMD_PCIFN_BW: | |
1315 | rc = bfad_iocmd_pcifn_bw(bfad, iocmd); | |
1316 | break; | |
1317 | case IOCMD_ADAPTER_CFG_MODE: | |
1318 | rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd); | |
1319 | break; | |
1320 | case IOCMD_PORT_CFG_MODE: | |
1321 | rc = bfad_iocmd_port_cfg_mode(bfad, iocmd); | |
1322 | break; | |
1323 | case IOCMD_FLASH_ENABLE_OPTROM: | |
1324 | case IOCMD_FLASH_DISABLE_OPTROM: | |
1325 | rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd); | |
1326 | break; | |
a714134a KG |
1327 | case IOCMD_FAA_ENABLE: |
1328 | rc = bfad_iocmd_faa_enable(bfad, iocmd); | |
1329 | break; | |
1330 | case IOCMD_FAA_DISABLE: | |
1331 | rc = bfad_iocmd_faa_disable(bfad, iocmd); | |
1332 | break; | |
1333 | case IOCMD_FAA_QUERY: | |
1334 | rc = bfad_iocmd_faa_query(bfad, iocmd); | |
1335 | break; | |
148d6103 KG |
1336 | case IOCMD_CEE_GET_ATTR: |
1337 | rc = bfad_iocmd_cee_attr(bfad, iocmd, payload_len); | |
1338 | break; | |
1339 | case IOCMD_CEE_GET_STATS: | |
1340 | rc = bfad_iocmd_cee_get_stats(bfad, iocmd, payload_len); | |
1341 | break; | |
1342 | case IOCMD_CEE_RESET_STATS: | |
1343 | rc = bfad_iocmd_cee_reset_stats(bfad, iocmd); | |
1344 | break; | |
51e569aa KG |
1345 | case IOCMD_SFP_MEDIA: |
1346 | rc = bfad_iocmd_sfp_media(bfad, iocmd); | |
1347 | break; | |
1348 | case IOCMD_SFP_SPEED: | |
1349 | rc = bfad_iocmd_sfp_speed(bfad, iocmd); | |
1350 | break; | |
5a54b1d5 KG |
1351 | case IOCMD_FLASH_GET_ATTR: |
1352 | rc = bfad_iocmd_flash_get_attr(bfad, iocmd); | |
1353 | break; | |
1354 | case IOCMD_FLASH_ERASE_PART: | |
1355 | rc = bfad_iocmd_flash_erase_part(bfad, iocmd); | |
1356 | break; | |
1357 | case IOCMD_FLASH_UPDATE_PART: | |
1358 | rc = bfad_iocmd_flash_update_part(bfad, iocmd, payload_len); | |
1359 | break; | |
1360 | case IOCMD_FLASH_READ_PART: | |
1361 | rc = bfad_iocmd_flash_read_part(bfad, iocmd, payload_len); | |
1362 | break; | |
b85daafe KG |
1363 | default: |
1364 | rc = EINVAL; | |
1365 | break; | |
1366 | } | |
1367 | return -rc; | |
1368 | } | |
1369 | ||
1370 | static int | |
1371 | bfad_im_bsg_vendor_request(struct fc_bsg_job *job) | |
1372 | { | |
1373 | uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0]; | |
1374 | struct bfad_im_port_s *im_port = | |
1375 | (struct bfad_im_port_s *) job->shost->hostdata[0]; | |
1376 | struct bfad_s *bfad = im_port->bfad; | |
1377 | void *payload_kbuf; | |
1378 | int rc = -EINVAL; | |
1379 | ||
1380 | /* Allocate a temp buffer to hold the passed in user space command */ | |
1381 | payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL); | |
1382 | if (!payload_kbuf) { | |
1383 | rc = -ENOMEM; | |
1384 | goto out; | |
1385 | } | |
1386 | ||
1387 | /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */ | |
1388 | sg_copy_to_buffer(job->request_payload.sg_list, | |
1389 | job->request_payload.sg_cnt, payload_kbuf, | |
1390 | job->request_payload.payload_len); | |
1391 | ||
1392 | /* Invoke IOCMD handler - to handle all the vendor command requests */ | |
1393 | rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf, | |
1394 | job->request_payload.payload_len); | |
1395 | if (rc != BFA_STATUS_OK) | |
1396 | goto error; | |
1397 | ||
1398 | /* Copy the response data to the job->reply_payload sg_list */ | |
1399 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
1400 | job->reply_payload.sg_cnt, | |
1401 | payload_kbuf, | |
1402 | job->reply_payload.payload_len); | |
1403 | ||
1404 | /* free the command buffer */ | |
1405 | kfree(payload_kbuf); | |
1406 | ||
1407 | /* Fill the BSG job reply data */ | |
1408 | job->reply_len = job->reply_payload.payload_len; | |
1409 | job->reply->reply_payload_rcv_len = job->reply_payload.payload_len; | |
1410 | job->reply->result = rc; | |
1411 | ||
1412 | job->job_done(job); | |
1413 | return rc; | |
1414 | error: | |
1415 | /* free the command buffer */ | |
1416 | kfree(payload_kbuf); | |
1417 | out: | |
1418 | job->reply->result = rc; | |
1419 | job->reply_len = sizeof(uint32_t); | |
1420 | job->reply->reply_payload_rcv_len = 0; | |
1421 | return rc; | |
1422 | } | |
1423 | ||
1424 | /* FC passthru call backs */ | |
1425 | u64 | |
1426 | bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid) | |
1427 | { | |
1428 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
1429 | struct bfa_sge_s *sge; | |
1430 | u64 addr; | |
1431 | ||
1432 | sge = drv_fcxp->req_sge + sgeid; | |
1433 | addr = (u64)(size_t) sge->sg_addr; | |
1434 | return addr; | |
1435 | } | |
1436 | ||
1437 | u32 | |
1438 | bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid) | |
1439 | { | |
1440 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
1441 | struct bfa_sge_s *sge; | |
1442 | ||
1443 | sge = drv_fcxp->req_sge + sgeid; | |
1444 | return sge->sg_len; | |
1445 | } | |
1446 | ||
1447 | u64 | |
1448 | bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid) | |
1449 | { | |
1450 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
1451 | struct bfa_sge_s *sge; | |
1452 | u64 addr; | |
1453 | ||
1454 | sge = drv_fcxp->rsp_sge + sgeid; | |
1455 | addr = (u64)(size_t) sge->sg_addr; | |
1456 | return addr; | |
1457 | } | |
1458 | ||
1459 | u32 | |
1460 | bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid) | |
1461 | { | |
1462 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
1463 | struct bfa_sge_s *sge; | |
1464 | ||
1465 | sge = drv_fcxp->rsp_sge + sgeid; | |
1466 | return sge->sg_len; | |
1467 | } | |
1468 | ||
1469 | void | |
1470 | bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg, | |
1471 | bfa_status_t req_status, u32 rsp_len, u32 resid_len, | |
1472 | struct fchs_s *rsp_fchs) | |
1473 | { | |
1474 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
1475 | ||
1476 | drv_fcxp->req_status = req_status; | |
1477 | drv_fcxp->rsp_len = rsp_len; | |
1478 | ||
1479 | /* bfa_fcxp will be automatically freed by BFA */ | |
1480 | drv_fcxp->bfa_fcxp = NULL; | |
1481 | complete(&drv_fcxp->comp); | |
1482 | } | |
1483 | ||
1484 | struct bfad_buf_info * | |
1485 | bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf, | |
1486 | uint32_t payload_len, uint32_t *num_sgles) | |
1487 | { | |
1488 | struct bfad_buf_info *buf_base, *buf_info; | |
1489 | struct bfa_sge_s *sg_table; | |
1490 | int sge_num = 1; | |
1491 | ||
1492 | buf_base = kzalloc((sizeof(struct bfad_buf_info) + | |
1493 | sizeof(struct bfa_sge_s)) * sge_num, GFP_KERNEL); | |
1494 | if (!buf_base) | |
1495 | return NULL; | |
1496 | ||
1497 | sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) + | |
1498 | (sizeof(struct bfad_buf_info) * sge_num)); | |
1499 | ||
1500 | /* Allocate dma coherent memory */ | |
1501 | buf_info = buf_base; | |
1502 | buf_info->size = payload_len; | |
1503 | buf_info->virt = dma_alloc_coherent(&bfad->pcidev->dev, buf_info->size, | |
1504 | &buf_info->phys, GFP_KERNEL); | |
1505 | if (!buf_info->virt) | |
1506 | goto out_free_mem; | |
1507 | ||
1508 | /* copy the linear bsg buffer to buf_info */ | |
1509 | memset(buf_info->virt, 0, buf_info->size); | |
1510 | memcpy(buf_info->virt, payload_kbuf, buf_info->size); | |
1511 | ||
1512 | /* | |
1513 | * Setup SG table | |
1514 | */ | |
1515 | sg_table->sg_len = buf_info->size; | |
1516 | sg_table->sg_addr = (void *)(size_t) buf_info->phys; | |
1517 | ||
1518 | *num_sgles = sge_num; | |
1519 | ||
1520 | return buf_base; | |
1521 | ||
1522 | out_free_mem: | |
1523 | kfree(buf_base); | |
1524 | return NULL; | |
1525 | } | |
1526 | ||
1527 | void | |
1528 | bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base, | |
1529 | uint32_t num_sgles) | |
1530 | { | |
1531 | int i; | |
1532 | struct bfad_buf_info *buf_info = buf_base; | |
1533 | ||
1534 | if (buf_base) { | |
1535 | for (i = 0; i < num_sgles; buf_info++, i++) { | |
1536 | if (buf_info->virt != NULL) | |
1537 | dma_free_coherent(&bfad->pcidev->dev, | |
1538 | buf_info->size, buf_info->virt, | |
1539 | buf_info->phys); | |
1540 | } | |
1541 | kfree(buf_base); | |
1542 | } | |
1543 | } | |
1544 | ||
1545 | int | |
1546 | bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp, | |
1547 | bfa_bsg_fcpt_t *bsg_fcpt) | |
1548 | { | |
1549 | struct bfa_fcxp_s *hal_fcxp; | |
1550 | struct bfad_s *bfad = drv_fcxp->port->bfad; | |
1551 | unsigned long flags; | |
1552 | uint8_t lp_tag; | |
1553 | ||
1554 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1555 | ||
1556 | /* Allocate bfa_fcxp structure */ | |
1557 | hal_fcxp = bfa_fcxp_alloc(drv_fcxp, &bfad->bfa, | |
1558 | drv_fcxp->num_req_sgles, | |
1559 | drv_fcxp->num_rsp_sgles, | |
1560 | bfad_fcxp_get_req_sgaddr_cb, | |
1561 | bfad_fcxp_get_req_sglen_cb, | |
1562 | bfad_fcxp_get_rsp_sgaddr_cb, | |
1563 | bfad_fcxp_get_rsp_sglen_cb); | |
1564 | if (!hal_fcxp) { | |
1565 | bfa_trc(bfad, 0); | |
1566 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1567 | return BFA_STATUS_ENOMEM; | |
1568 | } | |
1569 | ||
1570 | drv_fcxp->bfa_fcxp = hal_fcxp; | |
1571 | ||
1572 | lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id); | |
1573 | ||
1574 | bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag, | |
1575 | bsg_fcpt->cts, bsg_fcpt->cos, | |
1576 | job->request_payload.payload_len, | |
1577 | &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad, | |
1578 | job->reply_payload.payload_len, bsg_fcpt->tsecs); | |
1579 | ||
1580 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1581 | ||
1582 | return BFA_STATUS_OK; | |
1583 | } | |
1584 | ||
1585 | int | |
1586 | bfad_im_bsg_els_ct_request(struct fc_bsg_job *job) | |
1587 | { | |
1588 | struct bfa_bsg_data *bsg_data; | |
1589 | struct bfad_im_port_s *im_port = | |
1590 | (struct bfad_im_port_s *) job->shost->hostdata[0]; | |
1591 | struct bfad_s *bfad = im_port->bfad; | |
1592 | bfa_bsg_fcpt_t *bsg_fcpt; | |
1593 | struct bfad_fcxp *drv_fcxp; | |
1594 | struct bfa_fcs_lport_s *fcs_port; | |
1595 | struct bfa_fcs_rport_s *fcs_rport; | |
1596 | uint32_t command_type = job->request->msgcode; | |
1597 | unsigned long flags; | |
1598 | struct bfad_buf_info *rsp_buf_info; | |
1599 | void *req_kbuf = NULL, *rsp_kbuf = NULL; | |
1600 | int rc = -EINVAL; | |
1601 | ||
1602 | job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */ | |
1603 | job->reply->reply_payload_rcv_len = 0; | |
1604 | ||
1605 | /* Get the payload passed in from userspace */ | |
1606 | bsg_data = (struct bfa_bsg_data *) (((char *)job->request) + | |
1607 | sizeof(struct fc_bsg_request)); | |
1608 | if (bsg_data == NULL) | |
1609 | goto out; | |
1610 | ||
1611 | /* | |
1612 | * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload | |
1613 | * buffer of size bsg_data->payload_len | |
1614 | */ | |
1615 | bsg_fcpt = (struct bfa_bsg_fcpt_s *) | |
1616 | kzalloc(bsg_data->payload_len, GFP_KERNEL); | |
1617 | if (!bsg_fcpt) | |
1618 | goto out; | |
1619 | ||
1620 | if (copy_from_user((uint8_t *)bsg_fcpt, bsg_data->payload, | |
1621 | bsg_data->payload_len)) { | |
1622 | kfree(bsg_fcpt); | |
1623 | goto out; | |
1624 | } | |
1625 | ||
1626 | drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL); | |
1627 | if (drv_fcxp == NULL) { | |
1628 | rc = -ENOMEM; | |
1629 | goto out; | |
1630 | } | |
1631 | ||
1632 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1633 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id, | |
1634 | bsg_fcpt->lpwwn); | |
1635 | if (fcs_port == NULL) { | |
1636 | bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN; | |
1637 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1638 | goto out_free_mem; | |
1639 | } | |
1640 | ||
1641 | /* Check if the port is online before sending FC Passthru cmd */ | |
1642 | if (!bfa_fcs_lport_is_online(fcs_port)) { | |
1643 | bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE; | |
1644 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1645 | goto out_free_mem; | |
1646 | } | |
1647 | ||
1648 | drv_fcxp->port = fcs_port->bfad_port; | |
1649 | ||
1650 | if (drv_fcxp->port->bfad == 0) | |
1651 | drv_fcxp->port->bfad = bfad; | |
1652 | ||
1653 | /* Fetch the bfa_rport - if nexus needed */ | |
1654 | if (command_type == FC_BSG_HST_ELS_NOLOGIN || | |
1655 | command_type == FC_BSG_HST_CT) { | |
1656 | /* BSG HST commands: no nexus needed */ | |
1657 | drv_fcxp->bfa_rport = NULL; | |
1658 | ||
1659 | } else if (command_type == FC_BSG_RPT_ELS || | |
1660 | command_type == FC_BSG_RPT_CT) { | |
1661 | /* BSG RPT commands: nexus needed */ | |
1662 | fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port, | |
1663 | bsg_fcpt->dpwwn); | |
1664 | if (fcs_rport == NULL) { | |
1665 | bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN; | |
1666 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1667 | goto out_free_mem; | |
1668 | } | |
1669 | ||
1670 | drv_fcxp->bfa_rport = fcs_rport->bfa_rport; | |
1671 | ||
1672 | } else { /* Unknown BSG msgcode; return -EINVAL */ | |
1673 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1674 | goto out_free_mem; | |
1675 | } | |
1676 | ||
1677 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1678 | ||
1679 | /* allocate memory for req / rsp buffers */ | |
1680 | req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL); | |
1681 | if (!req_kbuf) { | |
1682 | printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n", | |
1683 | bfad->pci_name); | |
1684 | rc = -ENOMEM; | |
1685 | goto out_free_mem; | |
1686 | } | |
1687 | ||
1688 | rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL); | |
1689 | if (!rsp_kbuf) { | |
1690 | printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n", | |
1691 | bfad->pci_name); | |
1692 | rc = -ENOMEM; | |
1693 | goto out_free_mem; | |
1694 | } | |
1695 | ||
1696 | /* map req sg - copy the sg_list passed in to the linear buffer */ | |
1697 | sg_copy_to_buffer(job->request_payload.sg_list, | |
1698 | job->request_payload.sg_cnt, req_kbuf, | |
1699 | job->request_payload.payload_len); | |
1700 | ||
1701 | drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf, | |
1702 | job->request_payload.payload_len, | |
1703 | &drv_fcxp->num_req_sgles); | |
1704 | if (!drv_fcxp->reqbuf_info) { | |
1705 | printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n", | |
1706 | bfad->pci_name); | |
1707 | rc = -ENOMEM; | |
1708 | goto out_free_mem; | |
1709 | } | |
1710 | ||
1711 | drv_fcxp->req_sge = (struct bfa_sge_s *) | |
1712 | (((uint8_t *)drv_fcxp->reqbuf_info) + | |
1713 | (sizeof(struct bfad_buf_info) * | |
1714 | drv_fcxp->num_req_sgles)); | |
1715 | ||
1716 | /* map rsp sg */ | |
1717 | drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf, | |
1718 | job->reply_payload.payload_len, | |
1719 | &drv_fcxp->num_rsp_sgles); | |
1720 | if (!drv_fcxp->rspbuf_info) { | |
1721 | printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n", | |
1722 | bfad->pci_name); | |
1723 | rc = -ENOMEM; | |
1724 | goto out_free_mem; | |
1725 | } | |
1726 | ||
1727 | rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info; | |
1728 | drv_fcxp->rsp_sge = (struct bfa_sge_s *) | |
1729 | (((uint8_t *)drv_fcxp->rspbuf_info) + | |
1730 | (sizeof(struct bfad_buf_info) * | |
1731 | drv_fcxp->num_rsp_sgles)); | |
1732 | ||
1733 | /* fcxp send */ | |
1734 | init_completion(&drv_fcxp->comp); | |
1735 | rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt); | |
1736 | if (rc == BFA_STATUS_OK) { | |
1737 | wait_for_completion(&drv_fcxp->comp); | |
1738 | bsg_fcpt->status = drv_fcxp->req_status; | |
1739 | } else { | |
1740 | bsg_fcpt->status = rc; | |
1741 | goto out_free_mem; | |
1742 | } | |
1743 | ||
1744 | /* fill the job->reply data */ | |
1745 | if (drv_fcxp->req_status == BFA_STATUS_OK) { | |
1746 | job->reply_len = drv_fcxp->rsp_len; | |
1747 | job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len; | |
1748 | job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; | |
1749 | } else { | |
1750 | job->reply->reply_payload_rcv_len = | |
1751 | sizeof(struct fc_bsg_ctels_reply); | |
1752 | job->reply_len = sizeof(uint32_t); | |
1753 | job->reply->reply_data.ctels_reply.status = | |
1754 | FC_CTELS_STATUS_REJECT; | |
1755 | } | |
1756 | ||
1757 | /* Copy the response data to the reply_payload sg list */ | |
1758 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
1759 | job->reply_payload.sg_cnt, | |
1760 | (uint8_t *)rsp_buf_info->virt, | |
1761 | job->reply_payload.payload_len); | |
1762 | ||
1763 | out_free_mem: | |
1764 | bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info, | |
1765 | drv_fcxp->num_rsp_sgles); | |
1766 | bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info, | |
1767 | drv_fcxp->num_req_sgles); | |
1768 | kfree(req_kbuf); | |
1769 | kfree(rsp_kbuf); | |
1770 | ||
1771 | /* Need a copy to user op */ | |
1772 | if (copy_to_user(bsg_data->payload, (void *) bsg_fcpt, | |
1773 | bsg_data->payload_len)) | |
1774 | rc = -EIO; | |
1775 | ||
1776 | kfree(bsg_fcpt); | |
1777 | kfree(drv_fcxp); | |
1778 | out: | |
1779 | job->reply->result = rc; | |
1780 | ||
1781 | if (rc == BFA_STATUS_OK) | |
1782 | job->job_done(job); | |
1783 | ||
1784 | return rc; | |
1785 | } | |
1786 | ||
1787 | int | |
1788 | bfad_im_bsg_request(struct fc_bsg_job *job) | |
1789 | { | |
1790 | uint32_t rc = BFA_STATUS_OK; | |
1791 | ||
1792 | /* Increment the bfa module refcnt - if bsg request is in service */ | |
1793 | bfad_im_bsg_get_kobject(job); | |
1794 | ||
1795 | switch (job->request->msgcode) { | |
1796 | case FC_BSG_HST_VENDOR: | |
1797 | /* Process BSG HST Vendor requests */ | |
1798 | rc = bfad_im_bsg_vendor_request(job); | |
1799 | break; | |
1800 | case FC_BSG_HST_ELS_NOLOGIN: | |
1801 | case FC_BSG_RPT_ELS: | |
1802 | case FC_BSG_HST_CT: | |
1803 | case FC_BSG_RPT_CT: | |
1804 | /* Process BSG ELS/CT commands */ | |
1805 | rc = bfad_im_bsg_els_ct_request(job); | |
1806 | break; | |
1807 | default: | |
1808 | job->reply->result = rc = -EINVAL; | |
1809 | job->reply->reply_payload_rcv_len = 0; | |
1810 | break; | |
1811 | } | |
1812 | ||
1813 | /* Decrement the bfa module refcnt - on completion of bsg request */ | |
1814 | bfad_im_bsg_put_kobject(job); | |
1815 | ||
1816 | return rc; | |
1817 | } | |
1818 | ||
1819 | int | |
1820 | bfad_im_bsg_timeout(struct fc_bsg_job *job) | |
1821 | { | |
1822 | /* Don't complete the BSG job request - return -EAGAIN | |
1823 | * to reset bsg job timeout : for ELS/CT pass thru we | |
1824 | * already have timer to track the request. | |
1825 | */ | |
1826 | return -EAGAIN; | |
1827 | } |