]>
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 | ||
60138066 KG |
25 | int |
26 | bfad_iocmd_ioc_enable(struct bfad_s *bfad, void *cmd) | |
27 | { | |
28 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
29 | int rc = 0; | |
30 | unsigned long flags; | |
31 | ||
32 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
33 | /* If IOC is not in disabled state - return */ | |
34 | if (!bfa_ioc_is_disabled(&bfad->bfa.ioc)) { | |
35 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
36 | iocmd->status = BFA_STATUS_IOC_FAILURE; | |
37 | return rc; | |
38 | } | |
39 | ||
40 | init_completion(&bfad->enable_comp); | |
41 | bfa_iocfc_enable(&bfad->bfa); | |
42 | iocmd->status = BFA_STATUS_OK; | |
43 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
44 | wait_for_completion(&bfad->enable_comp); | |
45 | ||
46 | return rc; | |
47 | } | |
48 | ||
49 | int | |
50 | bfad_iocmd_ioc_disable(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 (bfad->disable_active) { | |
58 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
9afbcfab | 59 | return -EBUSY; |
60138066 KG |
60 | } |
61 | ||
62 | bfad->disable_active = BFA_TRUE; | |
63 | init_completion(&bfad->disable_comp); | |
64 | bfa_iocfc_disable(&bfad->bfa); | |
65 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
66 | ||
67 | wait_for_completion(&bfad->disable_comp); | |
68 | bfad->disable_active = BFA_FALSE; | |
69 | iocmd->status = BFA_STATUS_OK; | |
70 | ||
71 | return rc; | |
72 | } | |
73 | ||
b85daafe KG |
74 | static int |
75 | bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd) | |
76 | { | |
77 | int i; | |
78 | struct bfa_bsg_ioc_info_s *iocmd = (struct bfa_bsg_ioc_info_s *)cmd; | |
79 | struct bfad_im_port_s *im_port; | |
80 | struct bfa_port_attr_s pattr; | |
81 | unsigned long flags; | |
82 | ||
83 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
84 | bfa_fcport_get_attr(&bfad->bfa, &pattr); | |
85 | iocmd->nwwn = pattr.nwwn; | |
86 | iocmd->pwwn = pattr.pwwn; | |
87 | iocmd->ioc_type = bfa_get_type(&bfad->bfa); | |
88 | iocmd->mac = bfa_get_mac(&bfad->bfa); | |
89 | iocmd->factory_mac = bfa_get_mfg_mac(&bfad->bfa); | |
90 | bfa_get_adapter_serial_num(&bfad->bfa, iocmd->serialnum); | |
91 | iocmd->factorynwwn = pattr.factorynwwn; | |
92 | iocmd->factorypwwn = pattr.factorypwwn; | |
7826f304 | 93 | iocmd->bfad_num = bfad->inst_no; |
b85daafe KG |
94 | im_port = bfad->pport.im_port; |
95 | iocmd->host = im_port->shost->host_no; | |
96 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
97 | ||
98 | strcpy(iocmd->name, bfad->adapter_name); | |
99 | strcpy(iocmd->port_name, bfad->port_name); | |
100 | strcpy(iocmd->hwpath, bfad->pci_name); | |
101 | ||
102 | /* set adapter hw path */ | |
103 | strcpy(iocmd->adapter_hwpath, bfad->pci_name); | |
104 | i = strlen(iocmd->adapter_hwpath) - 1; | |
105 | while (iocmd->adapter_hwpath[i] != '.') | |
106 | i--; | |
107 | iocmd->adapter_hwpath[i] = '\0'; | |
108 | iocmd->status = BFA_STATUS_OK; | |
109 | return 0; | |
110 | } | |
111 | ||
112 | static int | |
113 | bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd) | |
114 | { | |
115 | struct bfa_bsg_ioc_attr_s *iocmd = (struct bfa_bsg_ioc_attr_s *)cmd; | |
116 | unsigned long flags; | |
117 | ||
118 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
119 | bfa_ioc_get_attr(&bfad->bfa.ioc, &iocmd->ioc_attr); | |
120 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
121 | ||
122 | /* fill in driver attr info */ | |
123 | strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME); | |
124 | strncpy(iocmd->ioc_attr.driver_attr.driver_ver, | |
125 | BFAD_DRIVER_VERSION, BFA_VERSION_LEN); | |
126 | strcpy(iocmd->ioc_attr.driver_attr.fw_ver, | |
127 | iocmd->ioc_attr.adapter_attr.fw_ver); | |
128 | strcpy(iocmd->ioc_attr.driver_attr.bios_ver, | |
129 | iocmd->ioc_attr.adapter_attr.optrom_ver); | |
130 | ||
131 | /* copy chip rev info first otherwise it will be overwritten */ | |
132 | memcpy(bfad->pci_attr.chip_rev, iocmd->ioc_attr.pci_attr.chip_rev, | |
133 | sizeof(bfad->pci_attr.chip_rev)); | |
134 | memcpy(&iocmd->ioc_attr.pci_attr, &bfad->pci_attr, | |
135 | sizeof(struct bfa_ioc_pci_attr_s)); | |
136 | ||
137 | iocmd->status = BFA_STATUS_OK; | |
138 | return 0; | |
139 | } | |
140 | ||
60138066 KG |
141 | int |
142 | bfad_iocmd_ioc_get_stats(struct bfad_s *bfad, void *cmd) | |
143 | { | |
144 | struct bfa_bsg_ioc_stats_s *iocmd = (struct bfa_bsg_ioc_stats_s *)cmd; | |
145 | ||
146 | bfa_ioc_get_stats(&bfad->bfa, &iocmd->ioc_stats); | |
147 | iocmd->status = BFA_STATUS_OK; | |
148 | return 0; | |
149 | } | |
150 | ||
151 | int | |
152 | bfad_iocmd_ioc_get_fwstats(struct bfad_s *bfad, void *cmd, | |
153 | unsigned int payload_len) | |
154 | { | |
155 | struct bfa_bsg_ioc_fwstats_s *iocmd = | |
156 | (struct bfa_bsg_ioc_fwstats_s *)cmd; | |
157 | void *iocmd_bufptr; | |
158 | unsigned long flags; | |
159 | ||
160 | if (bfad_chk_iocmd_sz(payload_len, | |
161 | sizeof(struct bfa_bsg_ioc_fwstats_s), | |
162 | sizeof(struct bfa_fw_stats_s)) != BFA_STATUS_OK) { | |
163 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
164 | goto out; | |
165 | } | |
166 | ||
167 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_ioc_fwstats_s); | |
168 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
169 | iocmd->status = bfa_ioc_fw_stats_get(&bfad->bfa.ioc, iocmd_bufptr); | |
170 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
171 | ||
172 | if (iocmd->status != BFA_STATUS_OK) { | |
173 | bfa_trc(bfad, iocmd->status); | |
174 | goto out; | |
175 | } | |
176 | out: | |
177 | bfa_trc(bfad, 0x6666); | |
178 | return 0; | |
179 | } | |
180 | ||
f2ee7601 KG |
181 | int |
182 | bfad_iocmd_ioc_reset_stats(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
183 | { | |
184 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
185 | unsigned long flags; | |
186 | ||
187 | if (v_cmd == IOCMD_IOC_RESET_STATS) { | |
188 | bfa_ioc_clear_stats(&bfad->bfa); | |
189 | iocmd->status = BFA_STATUS_OK; | |
190 | } else if (v_cmd == IOCMD_IOC_RESET_FWSTATS) { | |
191 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
192 | iocmd->status = bfa_ioc_fw_stats_clear(&bfad->bfa.ioc); | |
193 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
194 | } | |
195 | ||
196 | return 0; | |
197 | } | |
198 | ||
199 | int | |
200 | bfad_iocmd_ioc_set_name(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
201 | { | |
202 | struct bfa_bsg_ioc_name_s *iocmd = (struct bfa_bsg_ioc_name_s *) cmd; | |
203 | ||
204 | if (v_cmd == IOCMD_IOC_SET_ADAPTER_NAME) | |
205 | strcpy(bfad->adapter_name, iocmd->name); | |
206 | else if (v_cmd == IOCMD_IOC_SET_PORT_NAME) | |
207 | strcpy(bfad->port_name, iocmd->name); | |
208 | ||
209 | iocmd->status = BFA_STATUS_OK; | |
210 | return 0; | |
211 | } | |
212 | ||
60138066 KG |
213 | int |
214 | bfad_iocmd_iocfc_get_attr(struct bfad_s *bfad, void *cmd) | |
215 | { | |
216 | struct bfa_bsg_iocfc_attr_s *iocmd = (struct bfa_bsg_iocfc_attr_s *)cmd; | |
217 | ||
218 | iocmd->status = BFA_STATUS_OK; | |
219 | bfa_iocfc_get_attr(&bfad->bfa, &iocmd->iocfc_attr); | |
220 | ||
221 | return 0; | |
222 | } | |
223 | ||
224 | int | |
225 | bfad_iocmd_iocfc_set_intr(struct bfad_s *bfad, void *cmd) | |
226 | { | |
227 | struct bfa_bsg_iocfc_intr_s *iocmd = (struct bfa_bsg_iocfc_intr_s *)cmd; | |
228 | unsigned long flags; | |
229 | ||
230 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
231 | iocmd->status = bfa_iocfc_israttr_set(&bfad->bfa, &iocmd->attr); | |
232 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
233 | ||
234 | return 0; | |
235 | } | |
236 | ||
237 | int | |
238 | bfad_iocmd_port_enable(struct bfad_s *bfad, void *cmd) | |
239 | { | |
240 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
241 | struct bfad_hal_comp fcomp; | |
242 | unsigned long flags; | |
243 | ||
244 | init_completion(&fcomp.comp); | |
245 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
246 | iocmd->status = bfa_port_enable(&bfad->bfa.modules.port, | |
247 | bfad_hcb_comp, &fcomp); | |
248 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
249 | if (iocmd->status != BFA_STATUS_OK) { | |
250 | bfa_trc(bfad, iocmd->status); | |
251 | return 0; | |
252 | } | |
253 | wait_for_completion(&fcomp.comp); | |
254 | iocmd->status = fcomp.status; | |
255 | return 0; | |
256 | } | |
257 | ||
258 | int | |
259 | bfad_iocmd_port_disable(struct bfad_s *bfad, void *cmd) | |
260 | { | |
261 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
262 | struct bfad_hal_comp fcomp; | |
263 | unsigned long flags; | |
264 | ||
265 | init_completion(&fcomp.comp); | |
266 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
267 | iocmd->status = bfa_port_disable(&bfad->bfa.modules.port, | |
268 | bfad_hcb_comp, &fcomp); | |
269 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
270 | ||
271 | if (iocmd->status != BFA_STATUS_OK) { | |
272 | bfa_trc(bfad, iocmd->status); | |
273 | return 0; | |
274 | } | |
275 | wait_for_completion(&fcomp.comp); | |
276 | iocmd->status = fcomp.status; | |
277 | return 0; | |
278 | } | |
279 | ||
b85daafe KG |
280 | static int |
281 | bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd) | |
282 | { | |
283 | struct bfa_bsg_port_attr_s *iocmd = (struct bfa_bsg_port_attr_s *)cmd; | |
284 | struct bfa_lport_attr_s port_attr; | |
285 | unsigned long flags; | |
286 | ||
287 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
288 | bfa_fcport_get_attr(&bfad->bfa, &iocmd->attr); | |
289 | bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr); | |
290 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
291 | ||
292 | if (iocmd->attr.topology != BFA_PORT_TOPOLOGY_NONE) | |
293 | iocmd->attr.pid = port_attr.pid; | |
294 | else | |
295 | iocmd->attr.pid = 0; | |
296 | ||
297 | iocmd->attr.port_type = port_attr.port_type; | |
298 | iocmd->attr.loopback = port_attr.loopback; | |
299 | iocmd->attr.authfail = port_attr.authfail; | |
300 | strncpy(iocmd->attr.port_symname.symname, | |
301 | port_attr.port_cfg.sym_name.symname, | |
302 | sizeof(port_attr.port_cfg.sym_name.symname)); | |
303 | ||
304 | iocmd->status = BFA_STATUS_OK; | |
305 | return 0; | |
306 | } | |
307 | ||
60138066 KG |
308 | int |
309 | bfad_iocmd_port_get_stats(struct bfad_s *bfad, void *cmd, | |
310 | unsigned int payload_len) | |
311 | { | |
312 | struct bfa_bsg_port_stats_s *iocmd = (struct bfa_bsg_port_stats_s *)cmd; | |
313 | struct bfad_hal_comp fcomp; | |
314 | void *iocmd_bufptr; | |
315 | unsigned long flags; | |
316 | ||
317 | if (bfad_chk_iocmd_sz(payload_len, | |
318 | sizeof(struct bfa_bsg_port_stats_s), | |
319 | sizeof(union bfa_port_stats_u)) != BFA_STATUS_OK) { | |
320 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
321 | return 0; | |
322 | } | |
323 | ||
324 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_port_stats_s); | |
325 | ||
326 | init_completion(&fcomp.comp); | |
327 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
328 | iocmd->status = bfa_port_get_stats(&bfad->bfa.modules.port, | |
329 | iocmd_bufptr, bfad_hcb_comp, &fcomp); | |
330 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
331 | if (iocmd->status != BFA_STATUS_OK) { | |
332 | bfa_trc(bfad, iocmd->status); | |
333 | goto out; | |
334 | } | |
335 | ||
336 | wait_for_completion(&fcomp.comp); | |
337 | iocmd->status = fcomp.status; | |
338 | out: | |
339 | return 0; | |
340 | } | |
341 | ||
f2ee7601 KG |
342 | int |
343 | bfad_iocmd_port_reset_stats(struct bfad_s *bfad, void *cmd) | |
344 | { | |
345 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
346 | struct bfad_hal_comp fcomp; | |
347 | unsigned long flags; | |
348 | ||
349 | init_completion(&fcomp.comp); | |
350 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
351 | iocmd->status = bfa_port_clear_stats(&bfad->bfa.modules.port, | |
352 | bfad_hcb_comp, &fcomp); | |
353 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
354 | if (iocmd->status != BFA_STATUS_OK) { | |
355 | bfa_trc(bfad, iocmd->status); | |
356 | return 0; | |
357 | } | |
358 | wait_for_completion(&fcomp.comp); | |
359 | iocmd->status = fcomp.status; | |
360 | return 0; | |
361 | } | |
362 | ||
363 | int | |
364 | bfad_iocmd_set_port_cfg(struct bfad_s *bfad, void *iocmd, unsigned int v_cmd) | |
365 | { | |
366 | struct bfa_bsg_port_cfg_s *cmd = (struct bfa_bsg_port_cfg_s *)iocmd; | |
367 | unsigned long flags; | |
368 | ||
369 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
370 | if (v_cmd == IOCMD_PORT_CFG_TOPO) | |
371 | cmd->status = bfa_fcport_cfg_topology(&bfad->bfa, cmd->param); | |
372 | else if (v_cmd == IOCMD_PORT_CFG_SPEED) | |
373 | cmd->status = bfa_fcport_cfg_speed(&bfad->bfa, cmd->param); | |
374 | else if (v_cmd == IOCMD_PORT_CFG_ALPA) | |
375 | cmd->status = bfa_fcport_cfg_hardalpa(&bfad->bfa, cmd->param); | |
376 | else if (v_cmd == IOCMD_PORT_CLR_ALPA) | |
377 | cmd->status = bfa_fcport_clr_hardalpa(&bfad->bfa); | |
378 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
379 | ||
380 | return 0; | |
381 | } | |
382 | ||
383 | int | |
384 | bfad_iocmd_port_cfg_maxfrsize(struct bfad_s *bfad, void *cmd) | |
385 | { | |
386 | struct bfa_bsg_port_cfg_maxfrsize_s *iocmd = | |
387 | (struct bfa_bsg_port_cfg_maxfrsize_s *)cmd; | |
388 | unsigned long flags; | |
389 | ||
390 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
391 | iocmd->status = bfa_fcport_cfg_maxfrsize(&bfad->bfa, iocmd->maxfrsize); | |
392 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
393 | ||
394 | return 0; | |
395 | } | |
396 | ||
397 | int | |
398 | bfad_iocmd_port_cfg_bbsc(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
399 | { | |
400 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
401 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
402 | unsigned long flags; | |
403 | ||
404 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
405 | if (bfa_ioc_get_type(&bfad->bfa.ioc) == BFA_IOC_TYPE_FC) { | |
406 | if (v_cmd == IOCMD_PORT_BBSC_ENABLE) | |
407 | fcport->cfg.bb_scn_state = BFA_TRUE; | |
408 | else if (v_cmd == IOCMD_PORT_BBSC_DISABLE) | |
409 | fcport->cfg.bb_scn_state = BFA_FALSE; | |
410 | } | |
411 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
412 | ||
413 | iocmd->status = BFA_STATUS_OK; | |
414 | return 0; | |
415 | } | |
416 | ||
b85daafe KG |
417 | static int |
418 | bfad_iocmd_lport_get_attr(struct bfad_s *bfad, void *cmd) | |
419 | { | |
420 | struct bfa_fcs_lport_s *fcs_port; | |
421 | struct bfa_bsg_lport_attr_s *iocmd = (struct bfa_bsg_lport_attr_s *)cmd; | |
422 | unsigned long flags; | |
423 | ||
424 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
425 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
426 | iocmd->vf_id, iocmd->pwwn); | |
427 | if (fcs_port == NULL) { | |
428 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
429 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
430 | goto out; | |
431 | } | |
432 | ||
433 | bfa_fcs_lport_get_attr(fcs_port, &iocmd->port_attr); | |
434 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
435 | iocmd->status = BFA_STATUS_OK; | |
436 | out: | |
437 | return 0; | |
438 | } | |
439 | ||
60138066 KG |
440 | int |
441 | bfad_iocmd_lport_get_stats(struct bfad_s *bfad, void *cmd) | |
442 | { | |
443 | struct bfa_fcs_lport_s *fcs_port; | |
444 | struct bfa_bsg_lport_stats_s *iocmd = | |
445 | (struct bfa_bsg_lport_stats_s *)cmd; | |
446 | unsigned long flags; | |
447 | ||
448 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
449 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
450 | iocmd->vf_id, iocmd->pwwn); | |
451 | if (fcs_port == NULL) { | |
452 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
453 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
454 | goto out; | |
455 | } | |
456 | ||
457 | bfa_fcs_lport_get_stats(fcs_port, &iocmd->port_stats); | |
458 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
459 | iocmd->status = BFA_STATUS_OK; | |
460 | out: | |
461 | return 0; | |
462 | } | |
463 | ||
f2ee7601 KG |
464 | int |
465 | bfad_iocmd_lport_reset_stats(struct bfad_s *bfad, void *cmd) | |
466 | { | |
467 | struct bfa_fcs_lport_s *fcs_port; | |
468 | struct bfa_bsg_reset_stats_s *iocmd = | |
469 | (struct bfa_bsg_reset_stats_s *)cmd; | |
470 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); | |
471 | struct list_head *qe, *qen; | |
472 | struct bfa_itnim_s *itnim; | |
473 | unsigned long flags; | |
474 | ||
475 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
476 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
477 | iocmd->vf_id, iocmd->vpwwn); | |
478 | if (fcs_port == NULL) { | |
479 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
480 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
481 | goto out; | |
482 | } | |
483 | ||
484 | bfa_fcs_lport_clear_stats(fcs_port); | |
485 | /* clear IO stats from all active itnims */ | |
486 | list_for_each_safe(qe, qen, &fcpim->itnim_q) { | |
487 | itnim = (struct bfa_itnim_s *) qe; | |
488 | if (itnim->rport->rport_info.lp_tag != fcs_port->lp_tag) | |
489 | continue; | |
490 | bfa_itnim_clear_stats(itnim); | |
491 | } | |
492 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
493 | iocmd->status = BFA_STATUS_OK; | |
494 | out: | |
495 | return 0; | |
496 | } | |
497 | ||
60138066 KG |
498 | int |
499 | bfad_iocmd_lport_get_iostats(struct bfad_s *bfad, void *cmd) | |
500 | { | |
501 | struct bfa_fcs_lport_s *fcs_port; | |
502 | struct bfa_bsg_lport_iostats_s *iocmd = | |
503 | (struct bfa_bsg_lport_iostats_s *)cmd; | |
504 | unsigned long flags; | |
505 | ||
506 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
507 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
508 | iocmd->vf_id, iocmd->pwwn); | |
509 | if (fcs_port == NULL) { | |
510 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
511 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
512 | goto out; | |
513 | } | |
514 | ||
515 | bfa_fcpim_port_iostats(&bfad->bfa, &iocmd->iostats, | |
516 | fcs_port->lp_tag); | |
517 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
518 | iocmd->status = BFA_STATUS_OK; | |
519 | out: | |
520 | return 0; | |
521 | } | |
522 | ||
523 | int | |
524 | bfad_iocmd_lport_get_rports(struct bfad_s *bfad, void *cmd, | |
525 | unsigned int payload_len) | |
526 | { | |
527 | struct bfa_bsg_lport_get_rports_s *iocmd = | |
528 | (struct bfa_bsg_lport_get_rports_s *)cmd; | |
529 | struct bfa_fcs_lport_s *fcs_port; | |
530 | unsigned long flags; | |
531 | void *iocmd_bufptr; | |
532 | ||
533 | if (iocmd->nrports == 0) | |
9afbcfab | 534 | return -EINVAL; |
60138066 KG |
535 | |
536 | if (bfad_chk_iocmd_sz(payload_len, | |
537 | sizeof(struct bfa_bsg_lport_get_rports_s), | |
ee1a4a42 KG |
538 | sizeof(struct bfa_rport_qualifier_s) * iocmd->nrports) |
539 | != BFA_STATUS_OK) { | |
60138066 KG |
540 | iocmd->status = BFA_STATUS_VERSION_FAIL; |
541 | return 0; | |
542 | } | |
543 | ||
544 | iocmd_bufptr = (char *)iocmd + | |
545 | sizeof(struct bfa_bsg_lport_get_rports_s); | |
546 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
547 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
548 | iocmd->vf_id, iocmd->pwwn); | |
549 | if (fcs_port == NULL) { | |
550 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
551 | bfa_trc(bfad, 0); | |
552 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
553 | goto out; | |
554 | } | |
555 | ||
ee1a4a42 KG |
556 | bfa_fcs_lport_get_rport_quals(fcs_port, |
557 | (struct bfa_rport_qualifier_s *)iocmd_bufptr, | |
558 | &iocmd->nrports); | |
60138066 KG |
559 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
560 | iocmd->status = BFA_STATUS_OK; | |
561 | out: | |
562 | return 0; | |
563 | } | |
564 | ||
565 | int | |
566 | bfad_iocmd_rport_get_attr(struct bfad_s *bfad, void *cmd) | |
567 | { | |
568 | struct bfa_bsg_rport_attr_s *iocmd = (struct bfa_bsg_rport_attr_s *)cmd; | |
569 | struct bfa_fcs_lport_s *fcs_port; | |
570 | struct bfa_fcs_rport_s *fcs_rport; | |
571 | unsigned long flags; | |
572 | ||
573 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
574 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
575 | iocmd->vf_id, iocmd->pwwn); | |
576 | if (fcs_port == NULL) { | |
577 | bfa_trc(bfad, 0); | |
578 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
579 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
580 | goto out; | |
581 | } | |
582 | ||
ee1a4a42 KG |
583 | if (iocmd->pid) |
584 | fcs_rport = bfa_fcs_lport_get_rport_by_qualifier(fcs_port, | |
585 | iocmd->rpwwn, iocmd->pid); | |
586 | else | |
587 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); | |
60138066 KG |
588 | if (fcs_rport == NULL) { |
589 | bfa_trc(bfad, 0); | |
590 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
591 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
592 | goto out; | |
593 | } | |
594 | ||
595 | bfa_fcs_rport_get_attr(fcs_rport, &iocmd->attr); | |
596 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
597 | iocmd->status = BFA_STATUS_OK; | |
598 | out: | |
599 | return 0; | |
600 | } | |
601 | ||
b85daafe KG |
602 | static int |
603 | bfad_iocmd_rport_get_addr(struct bfad_s *bfad, void *cmd) | |
604 | { | |
605 | struct bfa_bsg_rport_scsi_addr_s *iocmd = | |
606 | (struct bfa_bsg_rport_scsi_addr_s *)cmd; | |
607 | struct bfa_fcs_lport_s *fcs_port; | |
608 | struct bfa_fcs_itnim_s *fcs_itnim; | |
609 | struct bfad_itnim_s *drv_itnim; | |
610 | unsigned long flags; | |
611 | ||
612 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
613 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
614 | iocmd->vf_id, iocmd->pwwn); | |
615 | if (fcs_port == NULL) { | |
616 | bfa_trc(bfad, 0); | |
617 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
618 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
619 | goto out; | |
620 | } | |
621 | ||
622 | fcs_itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
623 | if (fcs_itnim == NULL) { | |
624 | bfa_trc(bfad, 0); | |
625 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
626 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
627 | goto out; | |
628 | } | |
629 | ||
630 | drv_itnim = fcs_itnim->itnim_drv; | |
631 | ||
632 | if (drv_itnim && drv_itnim->im_port) | |
633 | iocmd->host = drv_itnim->im_port->shost->host_no; | |
634 | else { | |
635 | bfa_trc(bfad, 0); | |
636 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
637 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
638 | goto out; | |
639 | } | |
640 | ||
641 | iocmd->target = drv_itnim->scsi_tgt_id; | |
642 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
643 | ||
644 | iocmd->bus = 0; | |
645 | iocmd->lun = 0; | |
646 | iocmd->status = BFA_STATUS_OK; | |
647 | out: | |
648 | return 0; | |
649 | } | |
650 | ||
60138066 KG |
651 | int |
652 | bfad_iocmd_rport_get_stats(struct bfad_s *bfad, void *cmd) | |
653 | { | |
654 | struct bfa_bsg_rport_stats_s *iocmd = | |
655 | (struct bfa_bsg_rport_stats_s *)cmd; | |
656 | struct bfa_fcs_lport_s *fcs_port; | |
657 | struct bfa_fcs_rport_s *fcs_rport; | |
658 | unsigned long flags; | |
659 | ||
660 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
661 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
662 | iocmd->vf_id, iocmd->pwwn); | |
663 | if (fcs_port == NULL) { | |
664 | bfa_trc(bfad, 0); | |
665 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
666 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
667 | goto out; | |
668 | } | |
669 | ||
670 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); | |
671 | if (fcs_rport == NULL) { | |
672 | bfa_trc(bfad, 0); | |
673 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
674 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
675 | goto out; | |
676 | } | |
677 | ||
678 | memcpy((void *)&iocmd->stats, (void *)&fcs_rport->stats, | |
679 | sizeof(struct bfa_rport_stats_s)); | |
61ba4394 KG |
680 | if (bfa_fcs_rport_get_halrport(fcs_rport)) { |
681 | memcpy((void *)&iocmd->stats.hal_stats, | |
682 | (void *)&(bfa_fcs_rport_get_halrport(fcs_rport)->stats), | |
683 | sizeof(struct bfa_rport_hal_stats_s)); | |
684 | } | |
60138066 KG |
685 | |
686 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
687 | iocmd->status = BFA_STATUS_OK; | |
688 | out: | |
689 | return 0; | |
690 | } | |
691 | ||
f2ee7601 KG |
692 | int |
693 | bfad_iocmd_rport_clr_stats(struct bfad_s *bfad, void *cmd) | |
694 | { | |
695 | struct bfa_bsg_rport_reset_stats_s *iocmd = | |
696 | (struct bfa_bsg_rport_reset_stats_s *)cmd; | |
697 | struct bfa_fcs_lport_s *fcs_port; | |
698 | struct bfa_fcs_rport_s *fcs_rport; | |
699 | struct bfa_rport_s *rport; | |
700 | unsigned long flags; | |
701 | ||
702 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
703 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
704 | iocmd->vf_id, iocmd->pwwn); | |
705 | if (fcs_port == NULL) { | |
706 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
707 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
708 | goto out; | |
709 | } | |
710 | ||
711 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); | |
712 | if (fcs_rport == NULL) { | |
713 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
714 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
715 | goto out; | |
716 | } | |
717 | ||
718 | memset((char *)&fcs_rport->stats, 0, sizeof(struct bfa_rport_stats_s)); | |
719 | rport = bfa_fcs_rport_get_halrport(fcs_rport); | |
61ba4394 KG |
720 | if (rport) |
721 | memset(&rport->stats, 0, sizeof(rport->stats)); | |
f2ee7601 KG |
722 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
723 | iocmd->status = BFA_STATUS_OK; | |
724 | out: | |
725 | return 0; | |
726 | } | |
727 | ||
728 | int | |
729 | bfad_iocmd_rport_set_speed(struct bfad_s *bfad, void *cmd) | |
730 | { | |
731 | struct bfa_bsg_rport_set_speed_s *iocmd = | |
732 | (struct bfa_bsg_rport_set_speed_s *)cmd; | |
733 | struct bfa_fcs_lport_s *fcs_port; | |
734 | struct bfa_fcs_rport_s *fcs_rport; | |
735 | unsigned long flags; | |
736 | ||
737 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
738 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
739 | iocmd->vf_id, iocmd->pwwn); | |
740 | if (fcs_port == NULL) { | |
741 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
742 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
743 | goto out; | |
744 | } | |
745 | ||
746 | fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn); | |
747 | if (fcs_rport == NULL) { | |
748 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
749 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
750 | goto out; | |
751 | } | |
752 | ||
753 | fcs_rport->rpf.assigned_speed = iocmd->speed; | |
754 | /* Set this speed in f/w only if the RPSC speed is not available */ | |
755 | if (fcs_rport->rpf.rpsc_speed == BFA_PORT_SPEED_UNKNOWN) | |
61ba4394 KG |
756 | if (fcs_rport->bfa_rport) |
757 | bfa_rport_speed(fcs_rport->bfa_rport, iocmd->speed); | |
f2ee7601 KG |
758 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
759 | iocmd->status = BFA_STATUS_OK; | |
760 | out: | |
761 | return 0; | |
762 | } | |
763 | ||
764 | int | |
765 | bfad_iocmd_vport_get_attr(struct bfad_s *bfad, void *cmd) | |
766 | { | |
767 | struct bfa_fcs_vport_s *fcs_vport; | |
768 | struct bfa_bsg_vport_attr_s *iocmd = (struct bfa_bsg_vport_attr_s *)cmd; | |
769 | unsigned long flags; | |
770 | ||
771 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
772 | fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, | |
773 | iocmd->vf_id, iocmd->vpwwn); | |
774 | if (fcs_vport == NULL) { | |
775 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
776 | iocmd->status = BFA_STATUS_UNKNOWN_VWWN; | |
777 | goto out; | |
778 | } | |
779 | ||
780 | bfa_fcs_vport_get_attr(fcs_vport, &iocmd->vport_attr); | |
781 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
782 | iocmd->status = BFA_STATUS_OK; | |
783 | out: | |
784 | return 0; | |
785 | } | |
786 | ||
787 | int | |
788 | bfad_iocmd_vport_get_stats(struct bfad_s *bfad, void *cmd) | |
789 | { | |
790 | struct bfa_fcs_vport_s *fcs_vport; | |
791 | struct bfa_bsg_vport_stats_s *iocmd = | |
792 | (struct bfa_bsg_vport_stats_s *)cmd; | |
793 | unsigned long flags; | |
794 | ||
795 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
796 | fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, | |
797 | iocmd->vf_id, iocmd->vpwwn); | |
798 | if (fcs_vport == NULL) { | |
799 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
800 | iocmd->status = BFA_STATUS_UNKNOWN_VWWN; | |
801 | goto out; | |
802 | } | |
803 | ||
804 | memcpy((void *)&iocmd->vport_stats, (void *)&fcs_vport->vport_stats, | |
805 | sizeof(struct bfa_vport_stats_s)); | |
806 | memcpy((void *)&iocmd->vport_stats.port_stats, | |
807 | (void *)&fcs_vport->lport.stats, | |
808 | sizeof(struct bfa_lport_stats_s)); | |
809 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
810 | iocmd->status = BFA_STATUS_OK; | |
811 | out: | |
812 | return 0; | |
813 | } | |
814 | ||
815 | int | |
816 | bfad_iocmd_vport_clr_stats(struct bfad_s *bfad, void *cmd) | |
817 | { | |
818 | struct bfa_fcs_vport_s *fcs_vport; | |
819 | struct bfa_bsg_reset_stats_s *iocmd = | |
820 | (struct bfa_bsg_reset_stats_s *)cmd; | |
821 | unsigned long flags; | |
822 | ||
823 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
824 | fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, | |
825 | iocmd->vf_id, iocmd->vpwwn); | |
826 | if (fcs_vport == NULL) { | |
827 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
828 | iocmd->status = BFA_STATUS_UNKNOWN_VWWN; | |
829 | goto out; | |
830 | } | |
831 | ||
832 | memset(&fcs_vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s)); | |
833 | memset(&fcs_vport->lport.stats, 0, sizeof(struct bfa_lport_stats_s)); | |
834 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
835 | iocmd->status = BFA_STATUS_OK; | |
836 | out: | |
837 | return 0; | |
838 | } | |
839 | ||
b85daafe KG |
840 | static int |
841 | bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd, | |
842 | unsigned int payload_len) | |
843 | { | |
844 | struct bfa_bsg_fabric_get_lports_s *iocmd = | |
845 | (struct bfa_bsg_fabric_get_lports_s *)cmd; | |
846 | bfa_fcs_vf_t *fcs_vf; | |
847 | uint32_t nports = iocmd->nports; | |
848 | unsigned long flags; | |
849 | void *iocmd_bufptr; | |
850 | ||
851 | if (nports == 0) { | |
852 | iocmd->status = BFA_STATUS_EINVAL; | |
853 | goto out; | |
854 | } | |
855 | ||
856 | if (bfad_chk_iocmd_sz(payload_len, | |
857 | sizeof(struct bfa_bsg_fabric_get_lports_s), | |
858 | sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) { | |
859 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
860 | goto out; | |
861 | } | |
862 | ||
863 | iocmd_bufptr = (char *)iocmd + | |
864 | sizeof(struct bfa_bsg_fabric_get_lports_s); | |
865 | ||
866 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
867 | fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id); | |
868 | if (fcs_vf == NULL) { | |
869 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
870 | iocmd->status = BFA_STATUS_UNKNOWN_VFID; | |
871 | goto out; | |
872 | } | |
873 | bfa_fcs_vf_get_ports(fcs_vf, (wwn_t *)iocmd_bufptr, &nports); | |
874 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
875 | ||
876 | iocmd->nports = nports; | |
877 | iocmd->status = BFA_STATUS_OK; | |
878 | out: | |
879 | return 0; | |
880 | } | |
881 | ||
6894f013 KG |
882 | int |
883 | bfad_iocmd_qos_set_bw(struct bfad_s *bfad, void *pcmd) | |
884 | { | |
885 | struct bfa_bsg_qos_bw_s *iocmd = (struct bfa_bsg_qos_bw_s *)pcmd; | |
886 | unsigned long flags; | |
887 | ||
888 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
889 | iocmd->status = bfa_fcport_set_qos_bw(&bfad->bfa, &iocmd->qos_bw); | |
890 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
891 | ||
892 | return 0; | |
893 | } | |
894 | ||
f2ee7601 KG |
895 | int |
896 | bfad_iocmd_ratelim(struct bfad_s *bfad, unsigned int cmd, void *pcmd) | |
897 | { | |
898 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd; | |
899 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
900 | unsigned long flags; | |
901 | ||
902 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
903 | ||
bc0e2c2a KG |
904 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) && |
905 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
906 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
907 | else { | |
908 | if (cmd == IOCMD_RATELIM_ENABLE) | |
909 | fcport->cfg.ratelimit = BFA_TRUE; | |
910 | else if (cmd == IOCMD_RATELIM_DISABLE) | |
911 | fcport->cfg.ratelimit = BFA_FALSE; | |
f2ee7601 | 912 | |
bc0e2c2a KG |
913 | if (fcport->cfg.trl_def_speed == BFA_PORT_SPEED_UNKNOWN) |
914 | fcport->cfg.trl_def_speed = BFA_PORT_SPEED_1GBPS; | |
915 | ||
916 | iocmd->status = BFA_STATUS_OK; | |
917 | } | |
f2ee7601 KG |
918 | |
919 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
f2ee7601 KG |
920 | |
921 | return 0; | |
922 | } | |
923 | ||
924 | int | |
925 | bfad_iocmd_ratelim_speed(struct bfad_s *bfad, unsigned int cmd, void *pcmd) | |
926 | { | |
927 | struct bfa_bsg_trl_speed_s *iocmd = (struct bfa_bsg_trl_speed_s *)pcmd; | |
928 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
929 | unsigned long flags; | |
930 | ||
931 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
932 | ||
933 | /* Auto and speeds greater than the supported speed, are invalid */ | |
934 | if ((iocmd->speed == BFA_PORT_SPEED_AUTO) || | |
935 | (iocmd->speed > fcport->speed_sup)) { | |
936 | iocmd->status = BFA_STATUS_UNSUPP_SPEED; | |
937 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
938 | return 0; | |
939 | } | |
940 | ||
bc0e2c2a KG |
941 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) && |
942 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
943 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
944 | else { | |
945 | fcport->cfg.trl_def_speed = iocmd->speed; | |
946 | iocmd->status = BFA_STATUS_OK; | |
947 | } | |
f2ee7601 KG |
948 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
949 | ||
950 | return 0; | |
951 | } | |
952 | ||
953 | int | |
954 | bfad_iocmd_cfg_fcpim(struct bfad_s *bfad, void *cmd) | |
955 | { | |
956 | struct bfa_bsg_fcpim_s *iocmd = (struct bfa_bsg_fcpim_s *)cmd; | |
957 | unsigned long flags; | |
958 | ||
959 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
960 | bfa_fcpim_path_tov_set(&bfad->bfa, iocmd->param); | |
961 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
962 | iocmd->status = BFA_STATUS_OK; | |
963 | return 0; | |
964 | } | |
965 | ||
60138066 KG |
966 | int |
967 | bfad_iocmd_fcpim_get_modstats(struct bfad_s *bfad, void *cmd) | |
968 | { | |
969 | struct bfa_bsg_fcpim_modstats_s *iocmd = | |
970 | (struct bfa_bsg_fcpim_modstats_s *)cmd; | |
971 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); | |
972 | struct list_head *qe, *qen; | |
973 | struct bfa_itnim_s *itnim; | |
974 | unsigned long flags; | |
975 | ||
976 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
977 | /* accumulate IO stats from itnim */ | |
978 | memset((void *)&iocmd->modstats, 0, sizeof(struct bfa_itnim_iostats_s)); | |
979 | list_for_each_safe(qe, qen, &fcpim->itnim_q) { | |
980 | itnim = (struct bfa_itnim_s *) qe; | |
981 | bfa_fcpim_add_stats(&iocmd->modstats, &(itnim->stats)); | |
982 | } | |
983 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
984 | iocmd->status = BFA_STATUS_OK; | |
985 | return 0; | |
986 | } | |
987 | ||
f2ee7601 KG |
988 | int |
989 | bfad_iocmd_fcpim_clr_modstats(struct bfad_s *bfad, void *cmd) | |
990 | { | |
991 | struct bfa_bsg_fcpim_modstatsclr_s *iocmd = | |
992 | (struct bfa_bsg_fcpim_modstatsclr_s *)cmd; | |
993 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); | |
994 | struct list_head *qe, *qen; | |
995 | struct bfa_itnim_s *itnim; | |
996 | unsigned long flags; | |
997 | ||
998 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
999 | list_for_each_safe(qe, qen, &fcpim->itnim_q) { | |
1000 | itnim = (struct bfa_itnim_s *) qe; | |
1001 | bfa_itnim_clear_stats(itnim); | |
1002 | } | |
1003 | memset(&fcpim->del_itn_stats, 0, | |
1004 | sizeof(struct bfa_fcpim_del_itn_stats_s)); | |
1005 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1006 | iocmd->status = BFA_STATUS_OK; | |
1007 | return 0; | |
1008 | } | |
1009 | ||
60138066 KG |
1010 | int |
1011 | bfad_iocmd_fcpim_get_del_itn_stats(struct bfad_s *bfad, void *cmd) | |
1012 | { | |
1013 | struct bfa_bsg_fcpim_del_itn_stats_s *iocmd = | |
1014 | (struct bfa_bsg_fcpim_del_itn_stats_s *)cmd; | |
1015 | struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa); | |
1016 | unsigned long flags; | |
1017 | ||
1018 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1019 | memcpy((void *)&iocmd->modstats, (void *)&fcpim->del_itn_stats, | |
1020 | sizeof(struct bfa_fcpim_del_itn_stats_s)); | |
1021 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1022 | ||
1023 | iocmd->status = BFA_STATUS_OK; | |
1024 | return 0; | |
1025 | } | |
1026 | ||
b85daafe KG |
1027 | static int |
1028 | bfad_iocmd_itnim_get_attr(struct bfad_s *bfad, void *cmd) | |
1029 | { | |
1030 | struct bfa_bsg_itnim_attr_s *iocmd = (struct bfa_bsg_itnim_attr_s *)cmd; | |
1031 | struct bfa_fcs_lport_s *fcs_port; | |
1032 | unsigned long flags; | |
1033 | ||
1034 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1035 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
1036 | iocmd->vf_id, iocmd->lpwwn); | |
1037 | if (!fcs_port) | |
1038 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
1039 | else | |
1040 | iocmd->status = bfa_fcs_itnim_attr_get(fcs_port, | |
1041 | iocmd->rpwwn, &iocmd->attr); | |
1042 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1043 | return 0; | |
1044 | } | |
1045 | ||
60138066 KG |
1046 | static int |
1047 | bfad_iocmd_itnim_get_iostats(struct bfad_s *bfad, void *cmd) | |
1048 | { | |
1049 | struct bfa_bsg_itnim_iostats_s *iocmd = | |
1050 | (struct bfa_bsg_itnim_iostats_s *)cmd; | |
1051 | struct bfa_fcs_lport_s *fcs_port; | |
1052 | struct bfa_fcs_itnim_s *itnim; | |
1053 | unsigned long flags; | |
1054 | ||
1055 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1056 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
1057 | iocmd->vf_id, iocmd->lpwwn); | |
1058 | if (!fcs_port) { | |
1059 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
1060 | bfa_trc(bfad, 0); | |
1061 | } else { | |
1062 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
1063 | if (itnim == NULL) | |
1064 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
1065 | else { | |
1066 | iocmd->status = BFA_STATUS_OK; | |
61ba4394 KG |
1067 | if (bfa_fcs_itnim_get_halitn(itnim)) |
1068 | memcpy((void *)&iocmd->iostats, (void *) | |
1069 | &(bfa_fcs_itnim_get_halitn(itnim)->stats), | |
1070 | sizeof(struct bfa_itnim_iostats_s)); | |
60138066 KG |
1071 | } |
1072 | } | |
1073 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1074 | return 0; | |
1075 | } | |
1076 | ||
f2ee7601 KG |
1077 | static int |
1078 | bfad_iocmd_itnim_reset_stats(struct bfad_s *bfad, void *cmd) | |
1079 | { | |
1080 | struct bfa_bsg_rport_reset_stats_s *iocmd = | |
1081 | (struct bfa_bsg_rport_reset_stats_s *)cmd; | |
1082 | struct bfa_fcs_lport_s *fcs_port; | |
1083 | struct bfa_fcs_itnim_s *itnim; | |
1084 | unsigned long flags; | |
1085 | ||
1086 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1087 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
1088 | iocmd->vf_id, iocmd->pwwn); | |
1089 | if (!fcs_port) | |
1090 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
1091 | else { | |
1092 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
1093 | if (itnim == NULL) | |
1094 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
1095 | else { | |
1096 | iocmd->status = BFA_STATUS_OK; | |
1097 | bfa_fcs_itnim_stats_clear(fcs_port, iocmd->rpwwn); | |
1098 | bfa_itnim_clear_stats(bfa_fcs_itnim_get_halitn(itnim)); | |
1099 | } | |
1100 | } | |
1101 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1102 | ||
1103 | return 0; | |
1104 | } | |
1105 | ||
60138066 KG |
1106 | static int |
1107 | bfad_iocmd_itnim_get_itnstats(struct bfad_s *bfad, void *cmd) | |
1108 | { | |
1109 | struct bfa_bsg_itnim_itnstats_s *iocmd = | |
1110 | (struct bfa_bsg_itnim_itnstats_s *)cmd; | |
1111 | struct bfa_fcs_lport_s *fcs_port; | |
1112 | struct bfa_fcs_itnim_s *itnim; | |
1113 | unsigned long flags; | |
1114 | ||
1115 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1116 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
1117 | iocmd->vf_id, iocmd->lpwwn); | |
1118 | if (!fcs_port) { | |
1119 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
1120 | bfa_trc(bfad, 0); | |
1121 | } else { | |
1122 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
1123 | if (itnim == NULL) | |
1124 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
1125 | else { | |
1126 | iocmd->status = BFA_STATUS_OK; | |
1127 | bfa_fcs_itnim_stats_get(fcs_port, iocmd->rpwwn, | |
1128 | &iocmd->itnstats); | |
1129 | } | |
1130 | } | |
1131 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1132 | return 0; | |
1133 | } | |
1134 | ||
1135 | int | |
1136 | bfad_iocmd_fcport_enable(struct bfad_s *bfad, void *cmd) | |
1137 | { | |
1138 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
1139 | unsigned long flags; | |
1140 | ||
1141 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1142 | iocmd->status = bfa_fcport_enable(&bfad->bfa); | |
1143 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1144 | ||
1145 | return 0; | |
1146 | } | |
1147 | ||
1148 | int | |
1149 | bfad_iocmd_fcport_disable(struct bfad_s *bfad, void *cmd) | |
1150 | { | |
1151 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
1152 | unsigned long flags; | |
1153 | ||
1154 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1155 | iocmd->status = bfa_fcport_disable(&bfad->bfa); | |
1156 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1157 | ||
1158 | return 0; | |
1159 | } | |
1160 | ||
1a4d8e1b KG |
1161 | int |
1162 | bfad_iocmd_ioc_get_pcifn_cfg(struct bfad_s *bfad, void *cmd) | |
1163 | { | |
1164 | struct bfa_bsg_pcifn_cfg_s *iocmd = (struct bfa_bsg_pcifn_cfg_s *)cmd; | |
1165 | struct bfad_hal_comp fcomp; | |
1166 | unsigned long flags; | |
1167 | ||
1168 | init_completion(&fcomp.comp); | |
1169 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1170 | iocmd->status = bfa_ablk_query(&bfad->bfa.modules.ablk, | |
1171 | &iocmd->pcifn_cfg, | |
1172 | bfad_hcb_comp, &fcomp); | |
1173 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1174 | if (iocmd->status != BFA_STATUS_OK) | |
1175 | goto out; | |
1176 | ||
1177 | wait_for_completion(&fcomp.comp); | |
1178 | iocmd->status = fcomp.status; | |
1179 | out: | |
1180 | return 0; | |
1181 | } | |
1182 | ||
1183 | int | |
1184 | bfad_iocmd_pcifn_create(struct bfad_s *bfad, void *cmd) | |
1185 | { | |
1186 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; | |
1187 | struct bfad_hal_comp fcomp; | |
1188 | unsigned long flags; | |
1189 | ||
1190 | init_completion(&fcomp.comp); | |
1191 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1192 | iocmd->status = bfa_ablk_pf_create(&bfad->bfa.modules.ablk, | |
1193 | &iocmd->pcifn_id, iocmd->port, | |
1194 | iocmd->pcifn_class, iocmd->bandwidth, | |
1195 | bfad_hcb_comp, &fcomp); | |
1196 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1197 | if (iocmd->status != BFA_STATUS_OK) | |
1198 | goto out; | |
1199 | ||
1200 | wait_for_completion(&fcomp.comp); | |
1201 | iocmd->status = fcomp.status; | |
1202 | out: | |
1203 | return 0; | |
1204 | } | |
1205 | ||
1206 | int | |
1207 | bfad_iocmd_pcifn_delete(struct bfad_s *bfad, void *cmd) | |
1208 | { | |
1209 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; | |
1210 | struct bfad_hal_comp fcomp; | |
1211 | unsigned long flags; | |
1212 | ||
1213 | init_completion(&fcomp.comp); | |
1214 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1215 | iocmd->status = bfa_ablk_pf_delete(&bfad->bfa.modules.ablk, | |
1216 | iocmd->pcifn_id, | |
1217 | bfad_hcb_comp, &fcomp); | |
1218 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1219 | if (iocmd->status != BFA_STATUS_OK) | |
1220 | goto out; | |
1221 | ||
1222 | wait_for_completion(&fcomp.comp); | |
1223 | iocmd->status = fcomp.status; | |
1224 | out: | |
1225 | return 0; | |
1226 | } | |
1227 | ||
1228 | int | |
1229 | bfad_iocmd_pcifn_bw(struct bfad_s *bfad, void *cmd) | |
1230 | { | |
1231 | struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd; | |
1232 | struct bfad_hal_comp fcomp; | |
1233 | unsigned long flags; | |
1234 | ||
1235 | init_completion(&fcomp.comp); | |
1236 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1237 | iocmd->status = bfa_ablk_pf_update(&bfad->bfa.modules.ablk, | |
1238 | iocmd->pcifn_id, iocmd->bandwidth, | |
1239 | bfad_hcb_comp, &fcomp); | |
1240 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1241 | bfa_trc(bfad, iocmd->status); | |
1242 | if (iocmd->status != BFA_STATUS_OK) | |
1243 | goto out; | |
1244 | ||
1245 | wait_for_completion(&fcomp.comp); | |
1246 | iocmd->status = fcomp.status; | |
1247 | bfa_trc(bfad, iocmd->status); | |
1248 | out: | |
1249 | return 0; | |
1250 | } | |
1251 | ||
1252 | int | |
1253 | bfad_iocmd_adapter_cfg_mode(struct bfad_s *bfad, void *cmd) | |
1254 | { | |
1255 | struct bfa_bsg_adapter_cfg_mode_s *iocmd = | |
1256 | (struct bfa_bsg_adapter_cfg_mode_s *)cmd; | |
1257 | struct bfad_hal_comp fcomp; | |
1258 | unsigned long flags = 0; | |
1259 | ||
1260 | init_completion(&fcomp.comp); | |
1261 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1262 | iocmd->status = bfa_ablk_adapter_config(&bfad->bfa.modules.ablk, | |
1263 | iocmd->cfg.mode, iocmd->cfg.max_pf, | |
1264 | iocmd->cfg.max_vf, bfad_hcb_comp, &fcomp); | |
1265 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1266 | if (iocmd->status != BFA_STATUS_OK) | |
1267 | goto out; | |
1268 | ||
1269 | wait_for_completion(&fcomp.comp); | |
1270 | iocmd->status = fcomp.status; | |
1271 | out: | |
1272 | return 0; | |
1273 | } | |
1274 | ||
1275 | int | |
1276 | bfad_iocmd_port_cfg_mode(struct bfad_s *bfad, void *cmd) | |
1277 | { | |
1278 | struct bfa_bsg_port_cfg_mode_s *iocmd = | |
1279 | (struct bfa_bsg_port_cfg_mode_s *)cmd; | |
1280 | struct bfad_hal_comp fcomp; | |
1281 | unsigned long flags = 0; | |
1282 | ||
1283 | init_completion(&fcomp.comp); | |
1284 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1285 | iocmd->status = bfa_ablk_port_config(&bfad->bfa.modules.ablk, | |
1286 | iocmd->instance, iocmd->cfg.mode, | |
1287 | iocmd->cfg.max_pf, iocmd->cfg.max_vf, | |
1288 | bfad_hcb_comp, &fcomp); | |
1289 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1290 | if (iocmd->status != BFA_STATUS_OK) | |
1291 | goto out; | |
1292 | ||
1293 | wait_for_completion(&fcomp.comp); | |
1294 | iocmd->status = fcomp.status; | |
1295 | out: | |
1296 | return 0; | |
1297 | } | |
1298 | ||
1299 | int | |
1300 | bfad_iocmd_ablk_optrom(struct bfad_s *bfad, unsigned int cmd, void *pcmd) | |
1301 | { | |
1302 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd; | |
1303 | struct bfad_hal_comp fcomp; | |
1304 | unsigned long flags; | |
1305 | ||
1306 | init_completion(&fcomp.comp); | |
1307 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1308 | if (cmd == IOCMD_FLASH_ENABLE_OPTROM) | |
1309 | iocmd->status = bfa_ablk_optrom_en(&bfad->bfa.modules.ablk, | |
1310 | bfad_hcb_comp, &fcomp); | |
1311 | else | |
1312 | iocmd->status = bfa_ablk_optrom_dis(&bfad->bfa.modules.ablk, | |
1313 | bfad_hcb_comp, &fcomp); | |
1314 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1315 | ||
1316 | if (iocmd->status != BFA_STATUS_OK) | |
1317 | goto out; | |
1318 | ||
1319 | wait_for_completion(&fcomp.comp); | |
1320 | iocmd->status = fcomp.status; | |
1321 | out: | |
1322 | return 0; | |
1323 | } | |
1324 | ||
a714134a KG |
1325 | int |
1326 | bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd) | |
1327 | { | |
1328 | struct bfa_bsg_faa_attr_s *iocmd = (struct bfa_bsg_faa_attr_s *)cmd; | |
1329 | struct bfad_hal_comp fcomp; | |
1330 | unsigned long flags; | |
1331 | ||
1332 | init_completion(&fcomp.comp); | |
1333 | iocmd->status = BFA_STATUS_OK; | |
1334 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1335 | iocmd->status = bfa_faa_query(&bfad->bfa, &iocmd->faa_attr, | |
1336 | bfad_hcb_comp, &fcomp); | |
1337 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1338 | ||
1339 | if (iocmd->status != BFA_STATUS_OK) | |
1340 | goto out; | |
1341 | ||
1342 | wait_for_completion(&fcomp.comp); | |
1343 | iocmd->status = fcomp.status; | |
1344 | out: | |
1345 | return 0; | |
1346 | } | |
1347 | ||
148d6103 KG |
1348 | int |
1349 | bfad_iocmd_cee_attr(struct bfad_s *bfad, void *cmd, unsigned int payload_len) | |
1350 | { | |
1351 | struct bfa_bsg_cee_attr_s *iocmd = | |
1352 | (struct bfa_bsg_cee_attr_s *)cmd; | |
1353 | void *iocmd_bufptr; | |
1354 | struct bfad_hal_comp cee_comp; | |
1355 | unsigned long flags; | |
1356 | ||
1357 | if (bfad_chk_iocmd_sz(payload_len, | |
1358 | sizeof(struct bfa_bsg_cee_attr_s), | |
1359 | sizeof(struct bfa_cee_attr_s)) != BFA_STATUS_OK) { | |
1360 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1361 | return 0; | |
1362 | } | |
1363 | ||
1364 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_attr_s); | |
1365 | ||
1366 | cee_comp.status = 0; | |
1367 | init_completion(&cee_comp.comp); | |
1368 | mutex_lock(&bfad_mutex); | |
1369 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1370 | iocmd->status = bfa_cee_get_attr(&bfad->bfa.modules.cee, iocmd_bufptr, | |
1371 | bfad_hcb_comp, &cee_comp); | |
1372 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1373 | if (iocmd->status != BFA_STATUS_OK) { | |
1374 | mutex_unlock(&bfad_mutex); | |
1375 | bfa_trc(bfad, 0x5555); | |
1376 | goto out; | |
1377 | } | |
1378 | wait_for_completion(&cee_comp.comp); | |
1379 | mutex_unlock(&bfad_mutex); | |
1380 | out: | |
1381 | return 0; | |
1382 | } | |
1383 | ||
1384 | int | |
1385 | bfad_iocmd_cee_get_stats(struct bfad_s *bfad, void *cmd, | |
1386 | unsigned int payload_len) | |
1387 | { | |
1388 | struct bfa_bsg_cee_stats_s *iocmd = | |
1389 | (struct bfa_bsg_cee_stats_s *)cmd; | |
1390 | void *iocmd_bufptr; | |
1391 | struct bfad_hal_comp cee_comp; | |
1392 | unsigned long flags; | |
1393 | ||
1394 | if (bfad_chk_iocmd_sz(payload_len, | |
1395 | sizeof(struct bfa_bsg_cee_stats_s), | |
1396 | sizeof(struct bfa_cee_stats_s)) != BFA_STATUS_OK) { | |
1397 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1398 | return 0; | |
1399 | } | |
1400 | ||
1401 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_stats_s); | |
1402 | ||
1403 | cee_comp.status = 0; | |
1404 | init_completion(&cee_comp.comp); | |
1405 | mutex_lock(&bfad_mutex); | |
1406 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1407 | iocmd->status = bfa_cee_get_stats(&bfad->bfa.modules.cee, iocmd_bufptr, | |
1408 | bfad_hcb_comp, &cee_comp); | |
1409 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1410 | if (iocmd->status != BFA_STATUS_OK) { | |
1411 | mutex_unlock(&bfad_mutex); | |
1412 | bfa_trc(bfad, 0x5555); | |
1413 | goto out; | |
1414 | } | |
1415 | wait_for_completion(&cee_comp.comp); | |
1416 | mutex_unlock(&bfad_mutex); | |
1417 | out: | |
1418 | return 0; | |
1419 | } | |
1420 | ||
1421 | int | |
1422 | bfad_iocmd_cee_reset_stats(struct bfad_s *bfad, void *cmd) | |
1423 | { | |
1424 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
1425 | unsigned long flags; | |
1426 | ||
1427 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1428 | iocmd->status = bfa_cee_reset_stats(&bfad->bfa.modules.cee, NULL, NULL); | |
1429 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1430 | if (iocmd->status != BFA_STATUS_OK) | |
1431 | bfa_trc(bfad, 0x5555); | |
1432 | return 0; | |
1433 | } | |
1434 | ||
51e569aa KG |
1435 | int |
1436 | bfad_iocmd_sfp_media(struct bfad_s *bfad, void *cmd) | |
1437 | { | |
1438 | struct bfa_bsg_sfp_media_s *iocmd = (struct bfa_bsg_sfp_media_s *)cmd; | |
1439 | struct bfad_hal_comp fcomp; | |
1440 | unsigned long flags; | |
1441 | ||
1442 | init_completion(&fcomp.comp); | |
1443 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1444 | iocmd->status = bfa_sfp_media(BFA_SFP_MOD(&bfad->bfa), &iocmd->media, | |
1445 | bfad_hcb_comp, &fcomp); | |
1446 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1447 | bfa_trc(bfad, iocmd->status); | |
1448 | if (iocmd->status != BFA_STATUS_SFP_NOT_READY) | |
1449 | goto out; | |
1450 | ||
1451 | wait_for_completion(&fcomp.comp); | |
1452 | iocmd->status = fcomp.status; | |
1453 | out: | |
1454 | return 0; | |
1455 | } | |
1456 | ||
1457 | int | |
1458 | bfad_iocmd_sfp_speed(struct bfad_s *bfad, void *cmd) | |
1459 | { | |
1460 | struct bfa_bsg_sfp_speed_s *iocmd = (struct bfa_bsg_sfp_speed_s *)cmd; | |
1461 | struct bfad_hal_comp fcomp; | |
1462 | unsigned long flags; | |
1463 | ||
1464 | init_completion(&fcomp.comp); | |
1465 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1466 | iocmd->status = bfa_sfp_speed(BFA_SFP_MOD(&bfad->bfa), iocmd->speed, | |
1467 | bfad_hcb_comp, &fcomp); | |
1468 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1469 | bfa_trc(bfad, iocmd->status); | |
1470 | if (iocmd->status != BFA_STATUS_SFP_NOT_READY) | |
1471 | goto out; | |
1472 | wait_for_completion(&fcomp.comp); | |
1473 | iocmd->status = fcomp.status; | |
1474 | out: | |
1475 | return 0; | |
1476 | } | |
1477 | ||
5a54b1d5 KG |
1478 | int |
1479 | bfad_iocmd_flash_get_attr(struct bfad_s *bfad, void *cmd) | |
1480 | { | |
1481 | struct bfa_bsg_flash_attr_s *iocmd = | |
1482 | (struct bfa_bsg_flash_attr_s *)cmd; | |
1483 | struct bfad_hal_comp fcomp; | |
1484 | unsigned long flags; | |
1485 | ||
1486 | init_completion(&fcomp.comp); | |
1487 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1488 | iocmd->status = bfa_flash_get_attr(BFA_FLASH(&bfad->bfa), &iocmd->attr, | |
1489 | bfad_hcb_comp, &fcomp); | |
1490 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1491 | if (iocmd->status != BFA_STATUS_OK) | |
1492 | goto out; | |
1493 | wait_for_completion(&fcomp.comp); | |
1494 | iocmd->status = fcomp.status; | |
1495 | out: | |
1496 | return 0; | |
1497 | } | |
1498 | ||
1499 | int | |
1500 | bfad_iocmd_flash_erase_part(struct bfad_s *bfad, void *cmd) | |
1501 | { | |
1502 | struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd; | |
1503 | struct bfad_hal_comp fcomp; | |
1504 | unsigned long flags; | |
1505 | ||
1506 | init_completion(&fcomp.comp); | |
1507 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1508 | iocmd->status = bfa_flash_erase_part(BFA_FLASH(&bfad->bfa), iocmd->type, | |
1509 | iocmd->instance, bfad_hcb_comp, &fcomp); | |
1510 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1511 | if (iocmd->status != BFA_STATUS_OK) | |
1512 | goto out; | |
1513 | wait_for_completion(&fcomp.comp); | |
1514 | iocmd->status = fcomp.status; | |
1515 | out: | |
1516 | return 0; | |
1517 | } | |
1518 | ||
1519 | int | |
1520 | bfad_iocmd_flash_update_part(struct bfad_s *bfad, void *cmd, | |
1521 | unsigned int payload_len) | |
1522 | { | |
1523 | struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd; | |
1524 | void *iocmd_bufptr; | |
1525 | struct bfad_hal_comp fcomp; | |
1526 | unsigned long flags; | |
1527 | ||
1528 | if (bfad_chk_iocmd_sz(payload_len, | |
1529 | sizeof(struct bfa_bsg_flash_s), | |
1530 | iocmd->bufsz) != BFA_STATUS_OK) { | |
1531 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1532 | return 0; | |
1533 | } | |
1534 | ||
1535 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s); | |
1536 | ||
1537 | init_completion(&fcomp.comp); | |
1538 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1539 | iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa), | |
1540 | iocmd->type, iocmd->instance, iocmd_bufptr, | |
1541 | iocmd->bufsz, 0, bfad_hcb_comp, &fcomp); | |
1542 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1543 | if (iocmd->status != BFA_STATUS_OK) | |
1544 | goto out; | |
1545 | wait_for_completion(&fcomp.comp); | |
1546 | iocmd->status = fcomp.status; | |
1547 | out: | |
1548 | return 0; | |
1549 | } | |
1550 | ||
1551 | int | |
1552 | bfad_iocmd_flash_read_part(struct bfad_s *bfad, void *cmd, | |
1553 | unsigned int payload_len) | |
1554 | { | |
1555 | struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd; | |
1556 | struct bfad_hal_comp fcomp; | |
1557 | void *iocmd_bufptr; | |
1558 | unsigned long flags; | |
1559 | ||
1560 | if (bfad_chk_iocmd_sz(payload_len, | |
1561 | sizeof(struct bfa_bsg_flash_s), | |
1562 | iocmd->bufsz) != BFA_STATUS_OK) { | |
1563 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1564 | return 0; | |
1565 | } | |
1566 | ||
1567 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s); | |
1568 | ||
1569 | init_completion(&fcomp.comp); | |
1570 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1571 | iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa), iocmd->type, | |
1572 | iocmd->instance, iocmd_bufptr, iocmd->bufsz, 0, | |
1573 | bfad_hcb_comp, &fcomp); | |
1574 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1575 | if (iocmd->status != BFA_STATUS_OK) | |
1576 | goto out; | |
1577 | wait_for_completion(&fcomp.comp); | |
1578 | iocmd->status = fcomp.status; | |
1579 | out: | |
1580 | return 0; | |
1581 | } | |
1582 | ||
3d7fc66d KG |
1583 | int |
1584 | bfad_iocmd_diag_temp(struct bfad_s *bfad, void *cmd) | |
1585 | { | |
1586 | struct bfa_bsg_diag_get_temp_s *iocmd = | |
1587 | (struct bfa_bsg_diag_get_temp_s *)cmd; | |
1588 | struct bfad_hal_comp fcomp; | |
1589 | unsigned long flags; | |
1590 | ||
1591 | init_completion(&fcomp.comp); | |
1592 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1593 | iocmd->status = bfa_diag_tsensor_query(BFA_DIAG_MOD(&bfad->bfa), | |
1594 | &iocmd->result, bfad_hcb_comp, &fcomp); | |
1595 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1596 | bfa_trc(bfad, iocmd->status); | |
1597 | if (iocmd->status != BFA_STATUS_OK) | |
1598 | goto out; | |
1599 | wait_for_completion(&fcomp.comp); | |
1600 | iocmd->status = fcomp.status; | |
1601 | out: | |
1602 | return 0; | |
1603 | } | |
1604 | ||
1605 | int | |
1606 | bfad_iocmd_diag_memtest(struct bfad_s *bfad, void *cmd) | |
1607 | { | |
1608 | struct bfa_bsg_diag_memtest_s *iocmd = | |
1609 | (struct bfa_bsg_diag_memtest_s *)cmd; | |
1610 | struct bfad_hal_comp fcomp; | |
1611 | unsigned long flags; | |
1612 | ||
1613 | init_completion(&fcomp.comp); | |
1614 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1615 | iocmd->status = bfa_diag_memtest(BFA_DIAG_MOD(&bfad->bfa), | |
1616 | &iocmd->memtest, iocmd->pat, | |
1617 | &iocmd->result, bfad_hcb_comp, &fcomp); | |
1618 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1619 | bfa_trc(bfad, iocmd->status); | |
1620 | if (iocmd->status != BFA_STATUS_OK) | |
1621 | goto out; | |
1622 | wait_for_completion(&fcomp.comp); | |
1623 | iocmd->status = fcomp.status; | |
1624 | out: | |
1625 | return 0; | |
1626 | } | |
1627 | ||
1628 | int | |
1629 | bfad_iocmd_diag_loopback(struct bfad_s *bfad, void *cmd) | |
1630 | { | |
1631 | struct bfa_bsg_diag_loopback_s *iocmd = | |
1632 | (struct bfa_bsg_diag_loopback_s *)cmd; | |
1633 | struct bfad_hal_comp fcomp; | |
1634 | unsigned long flags; | |
1635 | ||
1636 | init_completion(&fcomp.comp); | |
1637 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1638 | iocmd->status = bfa_fcdiag_loopback(&bfad->bfa, iocmd->opmode, | |
1639 | iocmd->speed, iocmd->lpcnt, iocmd->pat, | |
1640 | &iocmd->result, bfad_hcb_comp, &fcomp); | |
1641 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1642 | bfa_trc(bfad, iocmd->status); | |
1643 | if (iocmd->status != BFA_STATUS_OK) | |
1644 | goto out; | |
1645 | wait_for_completion(&fcomp.comp); | |
1646 | iocmd->status = fcomp.status; | |
1647 | out: | |
1648 | return 0; | |
1649 | } | |
1650 | ||
1651 | int | |
1652 | bfad_iocmd_diag_fwping(struct bfad_s *bfad, void *cmd) | |
1653 | { | |
1654 | struct bfa_bsg_diag_fwping_s *iocmd = | |
1655 | (struct bfa_bsg_diag_fwping_s *)cmd; | |
1656 | struct bfad_hal_comp fcomp; | |
1657 | unsigned long flags; | |
1658 | ||
1659 | init_completion(&fcomp.comp); | |
1660 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1661 | iocmd->status = bfa_diag_fwping(BFA_DIAG_MOD(&bfad->bfa), iocmd->cnt, | |
1662 | iocmd->pattern, &iocmd->result, | |
1663 | bfad_hcb_comp, &fcomp); | |
1664 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1665 | bfa_trc(bfad, iocmd->status); | |
1666 | if (iocmd->status != BFA_STATUS_OK) | |
1667 | goto out; | |
1668 | bfa_trc(bfad, 0x77771); | |
1669 | wait_for_completion(&fcomp.comp); | |
1670 | iocmd->status = fcomp.status; | |
1671 | out: | |
1672 | return 0; | |
1673 | } | |
1674 | ||
1675 | int | |
1676 | bfad_iocmd_diag_queuetest(struct bfad_s *bfad, void *cmd) | |
1677 | { | |
1678 | struct bfa_bsg_diag_qtest_s *iocmd = (struct bfa_bsg_diag_qtest_s *)cmd; | |
1679 | struct bfad_hal_comp fcomp; | |
1680 | unsigned long flags; | |
1681 | ||
1682 | init_completion(&fcomp.comp); | |
1683 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1684 | iocmd->status = bfa_fcdiag_queuetest(&bfad->bfa, iocmd->force, | |
1685 | iocmd->queue, &iocmd->result, | |
1686 | bfad_hcb_comp, &fcomp); | |
1687 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1688 | if (iocmd->status != BFA_STATUS_OK) | |
1689 | goto out; | |
1690 | wait_for_completion(&fcomp.comp); | |
1691 | iocmd->status = fcomp.status; | |
1692 | out: | |
1693 | return 0; | |
1694 | } | |
1695 | ||
1696 | int | |
1697 | bfad_iocmd_diag_sfp(struct bfad_s *bfad, void *cmd) | |
1698 | { | |
1699 | struct bfa_bsg_sfp_show_s *iocmd = | |
1700 | (struct bfa_bsg_sfp_show_s *)cmd; | |
1701 | struct bfad_hal_comp fcomp; | |
1702 | unsigned long flags; | |
1703 | ||
1704 | init_completion(&fcomp.comp); | |
1705 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1706 | iocmd->status = bfa_sfp_show(BFA_SFP_MOD(&bfad->bfa), &iocmd->sfp, | |
1707 | bfad_hcb_comp, &fcomp); | |
1708 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1709 | bfa_trc(bfad, iocmd->status); | |
1710 | if (iocmd->status != BFA_STATUS_OK) | |
1711 | goto out; | |
1712 | wait_for_completion(&fcomp.comp); | |
1713 | iocmd->status = fcomp.status; | |
1714 | bfa_trc(bfad, iocmd->status); | |
1715 | out: | |
1716 | return 0; | |
1717 | } | |
1718 | ||
1719 | int | |
1720 | bfad_iocmd_diag_led(struct bfad_s *bfad, void *cmd) | |
1721 | { | |
1722 | struct bfa_bsg_diag_led_s *iocmd = (struct bfa_bsg_diag_led_s *)cmd; | |
1723 | unsigned long flags; | |
1724 | ||
1725 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1726 | iocmd->status = bfa_diag_ledtest(BFA_DIAG_MOD(&bfad->bfa), | |
1727 | &iocmd->ledtest); | |
1728 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1729 | return 0; | |
1730 | } | |
1731 | ||
1732 | int | |
1733 | bfad_iocmd_diag_beacon_lport(struct bfad_s *bfad, void *cmd) | |
1734 | { | |
1735 | struct bfa_bsg_diag_beacon_s *iocmd = | |
1736 | (struct bfa_bsg_diag_beacon_s *)cmd; | |
1737 | unsigned long flags; | |
1738 | ||
1739 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1740 | iocmd->status = bfa_diag_beacon_port(BFA_DIAG_MOD(&bfad->bfa), | |
1741 | iocmd->beacon, iocmd->link_e2e_beacon, | |
1742 | iocmd->second); | |
1743 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1744 | return 0; | |
1745 | } | |
1746 | ||
1747 | int | |
1748 | bfad_iocmd_diag_lb_stat(struct bfad_s *bfad, void *cmd) | |
1749 | { | |
1750 | struct bfa_bsg_diag_lb_stat_s *iocmd = | |
1751 | (struct bfa_bsg_diag_lb_stat_s *)cmd; | |
1752 | unsigned long flags; | |
1753 | ||
1754 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1755 | iocmd->status = bfa_fcdiag_lb_is_running(&bfad->bfa); | |
1756 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1757 | bfa_trc(bfad, iocmd->status); | |
1758 | ||
1759 | return 0; | |
1760 | } | |
1761 | ||
e353546e KG |
1762 | int |
1763 | bfad_iocmd_diag_cfg_dport(struct bfad_s *bfad, unsigned int cmd, void *pcmd) | |
1764 | { | |
1765 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd; | |
1766 | unsigned long flags; | |
1767 | struct bfad_hal_comp fcomp; | |
1768 | ||
1769 | init_completion(&fcomp.comp); | |
1770 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1771 | if (cmd == IOCMD_DIAG_DPORT_ENABLE) | |
1772 | iocmd->status = bfa_dport_enable(&bfad->bfa, | |
1773 | bfad_hcb_comp, &fcomp); | |
1774 | else if (cmd == IOCMD_DIAG_DPORT_DISABLE) | |
1775 | iocmd->status = bfa_dport_disable(&bfad->bfa, | |
1776 | bfad_hcb_comp, &fcomp); | |
1777 | else { | |
1778 | bfa_trc(bfad, 0); | |
1779 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1780 | return -EINVAL; | |
1781 | } | |
1782 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1783 | ||
1784 | if (iocmd->status != BFA_STATUS_OK) | |
1785 | bfa_trc(bfad, iocmd->status); | |
1786 | else { | |
1787 | wait_for_completion(&fcomp.comp); | |
1788 | iocmd->status = fcomp.status; | |
1789 | } | |
1790 | ||
1791 | return 0; | |
1792 | } | |
1793 | ||
1794 | int | |
1795 | bfad_iocmd_diag_dport_get_state(struct bfad_s *bfad, void *pcmd) | |
1796 | { | |
1797 | struct bfa_bsg_diag_dport_get_state_s *iocmd = | |
1798 | (struct bfa_bsg_diag_dport_get_state_s *)pcmd; | |
1799 | unsigned long flags; | |
1800 | ||
1801 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1802 | iocmd->status = bfa_dport_get_state(&bfad->bfa, &iocmd->state); | |
1803 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1804 | ||
1805 | return 0; | |
1806 | } | |
1807 | ||
3350d98d KG |
1808 | int |
1809 | bfad_iocmd_phy_get_attr(struct bfad_s *bfad, void *cmd) | |
1810 | { | |
1811 | struct bfa_bsg_phy_attr_s *iocmd = | |
1812 | (struct bfa_bsg_phy_attr_s *)cmd; | |
1813 | struct bfad_hal_comp fcomp; | |
1814 | unsigned long flags; | |
1815 | ||
1816 | init_completion(&fcomp.comp); | |
1817 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1818 | iocmd->status = bfa_phy_get_attr(BFA_PHY(&bfad->bfa), iocmd->instance, | |
1819 | &iocmd->attr, bfad_hcb_comp, &fcomp); | |
1820 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1821 | if (iocmd->status != BFA_STATUS_OK) | |
1822 | goto out; | |
1823 | wait_for_completion(&fcomp.comp); | |
1824 | iocmd->status = fcomp.status; | |
1825 | out: | |
1826 | return 0; | |
1827 | } | |
1828 | ||
1829 | int | |
1830 | bfad_iocmd_phy_get_stats(struct bfad_s *bfad, void *cmd) | |
1831 | { | |
1832 | struct bfa_bsg_phy_stats_s *iocmd = | |
1833 | (struct bfa_bsg_phy_stats_s *)cmd; | |
1834 | struct bfad_hal_comp fcomp; | |
1835 | unsigned long flags; | |
1836 | ||
1837 | init_completion(&fcomp.comp); | |
1838 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1839 | iocmd->status = bfa_phy_get_stats(BFA_PHY(&bfad->bfa), iocmd->instance, | |
1840 | &iocmd->stats, bfad_hcb_comp, &fcomp); | |
1841 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1842 | if (iocmd->status != BFA_STATUS_OK) | |
1843 | goto out; | |
1844 | wait_for_completion(&fcomp.comp); | |
1845 | iocmd->status = fcomp.status; | |
1846 | out: | |
1847 | return 0; | |
1848 | } | |
1849 | ||
1850 | int | |
1851 | bfad_iocmd_phy_read(struct bfad_s *bfad, void *cmd, unsigned int payload_len) | |
1852 | { | |
1853 | struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd; | |
1854 | struct bfad_hal_comp fcomp; | |
1855 | void *iocmd_bufptr; | |
1856 | unsigned long flags; | |
1857 | ||
1858 | if (bfad_chk_iocmd_sz(payload_len, | |
1859 | sizeof(struct bfa_bsg_phy_s), | |
1860 | iocmd->bufsz) != BFA_STATUS_OK) { | |
1861 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1862 | return 0; | |
1863 | } | |
1864 | ||
1865 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s); | |
1866 | init_completion(&fcomp.comp); | |
1867 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1868 | iocmd->status = bfa_phy_read(BFA_PHY(&bfad->bfa), | |
1869 | iocmd->instance, iocmd_bufptr, iocmd->bufsz, | |
1870 | 0, bfad_hcb_comp, &fcomp); | |
1871 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1872 | if (iocmd->status != BFA_STATUS_OK) | |
1873 | goto out; | |
1874 | wait_for_completion(&fcomp.comp); | |
1875 | iocmd->status = fcomp.status; | |
1876 | if (iocmd->status != BFA_STATUS_OK) | |
1877 | goto out; | |
1878 | out: | |
1879 | return 0; | |
1880 | } | |
1881 | ||
61e62e21 KG |
1882 | int |
1883 | bfad_iocmd_vhba_query(struct bfad_s *bfad, void *cmd) | |
1884 | { | |
1885 | struct bfa_bsg_vhba_attr_s *iocmd = | |
1886 | (struct bfa_bsg_vhba_attr_s *)cmd; | |
1887 | struct bfa_vhba_attr_s *attr = &iocmd->attr; | |
1888 | unsigned long flags; | |
1889 | ||
1890 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1891 | attr->pwwn = bfad->bfa.ioc.attr->pwwn; | |
1892 | attr->nwwn = bfad->bfa.ioc.attr->nwwn; | |
1893 | attr->plog_enabled = (bfa_boolean_t)bfad->bfa.plog->plog_enabled; | |
1894 | attr->io_profile = bfa_fcpim_get_io_profile(&bfad->bfa); | |
1895 | attr->path_tov = bfa_fcpim_path_tov_get(&bfad->bfa); | |
1896 | iocmd->status = BFA_STATUS_OK; | |
1897 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1898 | return 0; | |
1899 | } | |
1900 | ||
3350d98d KG |
1901 | int |
1902 | bfad_iocmd_phy_update(struct bfad_s *bfad, void *cmd, unsigned int payload_len) | |
1903 | { | |
1904 | struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd; | |
1905 | void *iocmd_bufptr; | |
1906 | struct bfad_hal_comp fcomp; | |
1907 | unsigned long flags; | |
1908 | ||
1909 | if (bfad_chk_iocmd_sz(payload_len, | |
1910 | sizeof(struct bfa_bsg_phy_s), | |
1911 | iocmd->bufsz) != BFA_STATUS_OK) { | |
1912 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1913 | return 0; | |
1914 | } | |
1915 | ||
1916 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s); | |
1917 | init_completion(&fcomp.comp); | |
1918 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1919 | iocmd->status = bfa_phy_update(BFA_PHY(&bfad->bfa), | |
1920 | iocmd->instance, iocmd_bufptr, iocmd->bufsz, | |
1921 | 0, bfad_hcb_comp, &fcomp); | |
1922 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1923 | if (iocmd->status != BFA_STATUS_OK) | |
1924 | goto out; | |
1925 | wait_for_completion(&fcomp.comp); | |
1926 | iocmd->status = fcomp.status; | |
1927 | out: | |
1928 | return 0; | |
1929 | } | |
1930 | ||
61e62e21 KG |
1931 | int |
1932 | bfad_iocmd_porglog_get(struct bfad_s *bfad, void *cmd) | |
1933 | { | |
1934 | struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd; | |
1935 | void *iocmd_bufptr; | |
1936 | ||
1937 | if (iocmd->bufsz < sizeof(struct bfa_plog_s)) { | |
1938 | bfa_trc(bfad, sizeof(struct bfa_plog_s)); | |
1939 | iocmd->status = BFA_STATUS_EINVAL; | |
1940 | goto out; | |
1941 | } | |
1942 | ||
1943 | iocmd->status = BFA_STATUS_OK; | |
1944 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s); | |
1945 | memcpy(iocmd_bufptr, (u8 *) &bfad->plog_buf, sizeof(struct bfa_plog_s)); | |
1946 | out: | |
1947 | return 0; | |
1948 | } | |
1949 | ||
f2ee7601 KG |
1950 | #define BFA_DEBUG_FW_CORE_CHUNK_SZ 0x4000U /* 16K chunks for FW dump */ |
1951 | int | |
1952 | bfad_iocmd_debug_fw_core(struct bfad_s *bfad, void *cmd, | |
1953 | unsigned int payload_len) | |
1954 | { | |
1955 | struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd; | |
1956 | void *iocmd_bufptr; | |
1957 | unsigned long flags; | |
76c8ae4b | 1958 | u32 offset; |
f2ee7601 KG |
1959 | |
1960 | if (bfad_chk_iocmd_sz(payload_len, sizeof(struct bfa_bsg_debug_s), | |
1961 | BFA_DEBUG_FW_CORE_CHUNK_SZ) != BFA_STATUS_OK) { | |
1962 | iocmd->status = BFA_STATUS_VERSION_FAIL; | |
1963 | return 0; | |
1964 | } | |
1965 | ||
1966 | if (iocmd->bufsz < BFA_DEBUG_FW_CORE_CHUNK_SZ || | |
1967 | !IS_ALIGNED(iocmd->bufsz, sizeof(u16)) || | |
1968 | !IS_ALIGNED(iocmd->offset, sizeof(u32))) { | |
1969 | bfa_trc(bfad, BFA_DEBUG_FW_CORE_CHUNK_SZ); | |
1970 | iocmd->status = BFA_STATUS_EINVAL; | |
1971 | goto out; | |
1972 | } | |
1973 | ||
1974 | iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s); | |
1975 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
76c8ae4b | 1976 | offset = iocmd->offset; |
f2ee7601 | 1977 | iocmd->status = bfa_ioc_debug_fwcore(&bfad->bfa.ioc, iocmd_bufptr, |
76c8ae4b SN |
1978 | &offset, &iocmd->bufsz); |
1979 | iocmd->offset = offset; | |
f2ee7601 KG |
1980 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
1981 | out: | |
1982 | return 0; | |
1983 | } | |
1984 | ||
1985 | int | |
1986 | bfad_iocmd_debug_ctl(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
1987 | { | |
1988 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
1989 | unsigned long flags; | |
1990 | ||
1991 | if (v_cmd == IOCMD_DEBUG_FW_STATE_CLR) { | |
1992 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
1993 | bfad->bfa.ioc.dbg_fwsave_once = BFA_TRUE; | |
1994 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
1995 | } else if (v_cmd == IOCMD_DEBUG_PORTLOG_CLR) | |
1996 | bfad->plog_buf.head = bfad->plog_buf.tail = 0; | |
1997 | else if (v_cmd == IOCMD_DEBUG_START_DTRC) | |
1998 | bfa_trc_init(bfad->trcmod); | |
1999 | else if (v_cmd == IOCMD_DEBUG_STOP_DTRC) | |
2000 | bfa_trc_stop(bfad->trcmod); | |
2001 | ||
2002 | iocmd->status = BFA_STATUS_OK; | |
2003 | return 0; | |
2004 | } | |
2005 | ||
2006 | int | |
2007 | bfad_iocmd_porglog_ctl(struct bfad_s *bfad, void *cmd) | |
2008 | { | |
2009 | struct bfa_bsg_portlogctl_s *iocmd = (struct bfa_bsg_portlogctl_s *)cmd; | |
2010 | ||
2011 | if (iocmd->ctl == BFA_TRUE) | |
2012 | bfad->plog_buf.plog_enabled = 1; | |
2013 | else | |
2014 | bfad->plog_buf.plog_enabled = 0; | |
2015 | ||
2016 | iocmd->status = BFA_STATUS_OK; | |
2017 | return 0; | |
2018 | } | |
2019 | ||
42a8e6e2 KG |
2020 | int |
2021 | bfad_iocmd_fcpim_cfg_profile(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
2022 | { | |
2023 | struct bfa_bsg_fcpim_profile_s *iocmd = | |
2024 | (struct bfa_bsg_fcpim_profile_s *)cmd; | |
2025 | struct timeval tv; | |
2026 | unsigned long flags; | |
2027 | ||
2028 | do_gettimeofday(&tv); | |
2029 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2030 | if (v_cmd == IOCMD_FCPIM_PROFILE_ON) | |
2031 | iocmd->status = bfa_fcpim_profile_on(&bfad->bfa, tv.tv_sec); | |
2032 | else if (v_cmd == IOCMD_FCPIM_PROFILE_OFF) | |
2033 | iocmd->status = bfa_fcpim_profile_off(&bfad->bfa); | |
2034 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2035 | ||
2036 | return 0; | |
2037 | } | |
2038 | ||
2039 | static int | |
2040 | bfad_iocmd_itnim_get_ioprofile(struct bfad_s *bfad, void *cmd) | |
2041 | { | |
2042 | struct bfa_bsg_itnim_ioprofile_s *iocmd = | |
2043 | (struct bfa_bsg_itnim_ioprofile_s *)cmd; | |
2044 | struct bfa_fcs_lport_s *fcs_port; | |
2045 | struct bfa_fcs_itnim_s *itnim; | |
2046 | unsigned long flags; | |
2047 | ||
2048 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2049 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, | |
2050 | iocmd->vf_id, iocmd->lpwwn); | |
2051 | if (!fcs_port) | |
2052 | iocmd->status = BFA_STATUS_UNKNOWN_LWWN; | |
2053 | else { | |
2054 | itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn); | |
2055 | if (itnim == NULL) | |
2056 | iocmd->status = BFA_STATUS_UNKNOWN_RWWN; | |
2057 | else | |
2058 | iocmd->status = bfa_itnim_get_ioprofile( | |
2059 | bfa_fcs_itnim_get_halitn(itnim), | |
2060 | &iocmd->ioprofile); | |
2061 | } | |
2062 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2063 | return 0; | |
2064 | } | |
2065 | ||
37ea0558 KG |
2066 | int |
2067 | bfad_iocmd_fcport_get_stats(struct bfad_s *bfad, void *cmd) | |
2068 | { | |
2069 | struct bfa_bsg_fcport_stats_s *iocmd = | |
2070 | (struct bfa_bsg_fcport_stats_s *)cmd; | |
2071 | struct bfad_hal_comp fcomp; | |
2072 | unsigned long flags; | |
2073 | struct bfa_cb_pending_q_s cb_qe; | |
2074 | ||
2075 | init_completion(&fcomp.comp); | |
2076 | bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, | |
2077 | &fcomp, &iocmd->stats); | |
2078 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2079 | iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe); | |
2080 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2081 | if (iocmd->status != BFA_STATUS_OK) { | |
2082 | bfa_trc(bfad, iocmd->status); | |
2083 | goto out; | |
2084 | } | |
2085 | wait_for_completion(&fcomp.comp); | |
2086 | iocmd->status = fcomp.status; | |
2087 | out: | |
2088 | return 0; | |
2089 | } | |
2090 | ||
2091 | int | |
2092 | bfad_iocmd_fcport_reset_stats(struct bfad_s *bfad, void *cmd) | |
2093 | { | |
2094 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
2095 | struct bfad_hal_comp fcomp; | |
2096 | unsigned long flags; | |
2097 | struct bfa_cb_pending_q_s cb_qe; | |
2098 | ||
2099 | init_completion(&fcomp.comp); | |
2100 | bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, &fcomp, NULL); | |
2101 | ||
2102 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2103 | iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe); | |
2104 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2105 | if (iocmd->status != BFA_STATUS_OK) { | |
2106 | bfa_trc(bfad, iocmd->status); | |
2107 | goto out; | |
2108 | } | |
2109 | wait_for_completion(&fcomp.comp); | |
2110 | iocmd->status = fcomp.status; | |
2111 | out: | |
2112 | return 0; | |
2113 | } | |
2114 | ||
a46bd300 KG |
2115 | int |
2116 | bfad_iocmd_boot_cfg(struct bfad_s *bfad, void *cmd) | |
2117 | { | |
2118 | struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd; | |
2119 | struct bfad_hal_comp fcomp; | |
2120 | unsigned long flags; | |
2121 | ||
2122 | init_completion(&fcomp.comp); | |
2123 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2124 | iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa), | |
2125 | BFA_FLASH_PART_BOOT, PCI_FUNC(bfad->pcidev->devfn), | |
2126 | &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0, | |
2127 | bfad_hcb_comp, &fcomp); | |
2128 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2129 | if (iocmd->status != BFA_STATUS_OK) | |
2130 | goto out; | |
2131 | wait_for_completion(&fcomp.comp); | |
2132 | iocmd->status = fcomp.status; | |
2133 | out: | |
2134 | return 0; | |
2135 | } | |
2136 | ||
2137 | int | |
2138 | bfad_iocmd_boot_query(struct bfad_s *bfad, void *cmd) | |
2139 | { | |
2140 | struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd; | |
2141 | struct bfad_hal_comp fcomp; | |
2142 | unsigned long flags; | |
2143 | ||
2144 | init_completion(&fcomp.comp); | |
2145 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2146 | iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa), | |
2147 | BFA_FLASH_PART_BOOT, PCI_FUNC(bfad->pcidev->devfn), | |
2148 | &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0, | |
2149 | bfad_hcb_comp, &fcomp); | |
2150 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2151 | if (iocmd->status != BFA_STATUS_OK) | |
2152 | goto out; | |
2153 | wait_for_completion(&fcomp.comp); | |
2154 | iocmd->status = fcomp.status; | |
2155 | out: | |
2156 | return 0; | |
2157 | } | |
2158 | ||
2159 | int | |
2160 | bfad_iocmd_preboot_query(struct bfad_s *bfad, void *cmd) | |
2161 | { | |
2162 | struct bfa_bsg_preboot_s *iocmd = (struct bfa_bsg_preboot_s *)cmd; | |
2163 | struct bfi_iocfc_cfgrsp_s *cfgrsp = bfad->bfa.iocfc.cfgrsp; | |
2164 | struct bfa_boot_pbc_s *pbcfg = &iocmd->cfg; | |
2165 | unsigned long flags; | |
2166 | ||
2167 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2168 | pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled; | |
2169 | pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns; | |
2170 | pbcfg->speed = cfgrsp->pbc_cfg.port_speed; | |
2171 | memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun)); | |
2172 | iocmd->status = BFA_STATUS_OK; | |
2173 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2174 | ||
2175 | return 0; | |
2176 | } | |
2177 | ||
2178 | int | |
2179 | bfad_iocmd_ethboot_cfg(struct bfad_s *bfad, void *cmd) | |
2180 | { | |
2181 | struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd; | |
2182 | struct bfad_hal_comp fcomp; | |
2183 | unsigned long flags; | |
2184 | ||
2185 | init_completion(&fcomp.comp); | |
2186 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2187 | iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa), | |
2188 | BFA_FLASH_PART_PXECFG, | |
2189 | bfad->bfa.ioc.port_id, &iocmd->cfg, | |
2190 | sizeof(struct bfa_ethboot_cfg_s), 0, | |
2191 | bfad_hcb_comp, &fcomp); | |
2192 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2193 | if (iocmd->status != BFA_STATUS_OK) | |
2194 | goto out; | |
2195 | wait_for_completion(&fcomp.comp); | |
2196 | iocmd->status = fcomp.status; | |
2197 | out: | |
2198 | return 0; | |
2199 | } | |
2200 | ||
2201 | int | |
2202 | bfad_iocmd_ethboot_query(struct bfad_s *bfad, void *cmd) | |
2203 | { | |
2204 | struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd; | |
2205 | struct bfad_hal_comp fcomp; | |
2206 | unsigned long flags; | |
2207 | ||
2208 | init_completion(&fcomp.comp); | |
2209 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2210 | iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa), | |
2211 | BFA_FLASH_PART_PXECFG, | |
2212 | bfad->bfa.ioc.port_id, &iocmd->cfg, | |
2213 | sizeof(struct bfa_ethboot_cfg_s), 0, | |
2214 | bfad_hcb_comp, &fcomp); | |
2215 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2216 | if (iocmd->status != BFA_STATUS_OK) | |
2217 | goto out; | |
2218 | wait_for_completion(&fcomp.comp); | |
2219 | iocmd->status = fcomp.status; | |
2220 | out: | |
2221 | return 0; | |
2222 | } | |
2223 | ||
45191236 KG |
2224 | int |
2225 | bfad_iocmd_cfg_trunk(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
2226 | { | |
2227 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
2228 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
2229 | struct bfa_fcport_trunk_s *trunk = &fcport->trunk; | |
2230 | unsigned long flags; | |
2231 | ||
2232 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2233 | ||
e353546e KG |
2234 | if (bfa_fcport_is_dport(&bfad->bfa)) |
2235 | return BFA_STATUS_DPORT_ERR; | |
2236 | ||
bc0e2c2a KG |
2237 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) || |
2238 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
2239 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
2240 | else { | |
2241 | if (v_cmd == IOCMD_TRUNK_ENABLE) { | |
2242 | trunk->attr.state = BFA_TRUNK_OFFLINE; | |
2243 | bfa_fcport_disable(&bfad->bfa); | |
2244 | fcport->cfg.trunked = BFA_TRUE; | |
2245 | } else if (v_cmd == IOCMD_TRUNK_DISABLE) { | |
2246 | trunk->attr.state = BFA_TRUNK_DISABLED; | |
2247 | bfa_fcport_disable(&bfad->bfa); | |
2248 | fcport->cfg.trunked = BFA_FALSE; | |
2249 | } | |
2250 | ||
2251 | if (!bfa_fcport_is_disabled(&bfad->bfa)) | |
2252 | bfa_fcport_enable(&bfad->bfa); | |
45191236 | 2253 | |
bc0e2c2a KG |
2254 | iocmd->status = BFA_STATUS_OK; |
2255 | } | |
45191236 KG |
2256 | |
2257 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2258 | ||
45191236 KG |
2259 | return 0; |
2260 | } | |
2261 | ||
2262 | int | |
2263 | bfad_iocmd_trunk_get_attr(struct bfad_s *bfad, void *cmd) | |
2264 | { | |
2265 | struct bfa_bsg_trunk_attr_s *iocmd = (struct bfa_bsg_trunk_attr_s *)cmd; | |
2266 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
2267 | struct bfa_fcport_trunk_s *trunk = &fcport->trunk; | |
2268 | unsigned long flags; | |
2269 | ||
2270 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
bc0e2c2a KG |
2271 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) || |
2272 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
2273 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
2274 | else { | |
2275 | memcpy((void *)&iocmd->attr, (void *)&trunk->attr, | |
2276 | sizeof(struct bfa_trunk_attr_s)); | |
2277 | iocmd->attr.port_id = bfa_lps_get_base_pid(&bfad->bfa); | |
2278 | iocmd->status = BFA_STATUS_OK; | |
2279 | } | |
45191236 KG |
2280 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
2281 | ||
45191236 KG |
2282 | return 0; |
2283 | } | |
2284 | ||
3ec4f2c8 KG |
2285 | int |
2286 | bfad_iocmd_qos(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
2287 | { | |
2288 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
2289 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
2290 | unsigned long flags; | |
2291 | ||
2292 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2293 | if (bfa_ioc_get_type(&bfad->bfa.ioc) == BFA_IOC_TYPE_FC) { | |
bc0e2c2a KG |
2294 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) && |
2295 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
2296 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
2297 | else { | |
2298 | if (v_cmd == IOCMD_QOS_ENABLE) | |
2299 | fcport->cfg.qos_enabled = BFA_TRUE; | |
6894f013 | 2300 | else if (v_cmd == IOCMD_QOS_DISABLE) { |
bc0e2c2a | 2301 | fcport->cfg.qos_enabled = BFA_FALSE; |
6894f013 KG |
2302 | fcport->cfg.qos_bw.high = BFA_QOS_BW_HIGH; |
2303 | fcport->cfg.qos_bw.med = BFA_QOS_BW_MED; | |
2304 | fcport->cfg.qos_bw.low = BFA_QOS_BW_LOW; | |
2305 | } | |
bc0e2c2a | 2306 | } |
3ec4f2c8 KG |
2307 | } |
2308 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2309 | ||
3ec4f2c8 KG |
2310 | return 0; |
2311 | } | |
2312 | ||
2313 | int | |
2314 | bfad_iocmd_qos_get_attr(struct bfad_s *bfad, void *cmd) | |
2315 | { | |
2316 | struct bfa_bsg_qos_attr_s *iocmd = (struct bfa_bsg_qos_attr_s *)cmd; | |
2317 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
2318 | unsigned long flags; | |
2319 | ||
2320 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
bc0e2c2a KG |
2321 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) && |
2322 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
2323 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
2324 | else { | |
2325 | iocmd->attr.state = fcport->qos_attr.state; | |
2326 | iocmd->attr.total_bb_cr = | |
2327 | be32_to_cpu(fcport->qos_attr.total_bb_cr); | |
6894f013 KG |
2328 | iocmd->attr.qos_bw.high = fcport->cfg.qos_bw.high; |
2329 | iocmd->attr.qos_bw.med = fcport->cfg.qos_bw.med; | |
2330 | iocmd->attr.qos_bw.low = fcport->cfg.qos_bw.low; | |
2331 | iocmd->attr.qos_bw_op = fcport->qos_attr.qos_bw_op; | |
bc0e2c2a KG |
2332 | iocmd->status = BFA_STATUS_OK; |
2333 | } | |
3ec4f2c8 KG |
2334 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
2335 | ||
3ec4f2c8 KG |
2336 | return 0; |
2337 | } | |
2338 | ||
2339 | int | |
2340 | bfad_iocmd_qos_get_vc_attr(struct bfad_s *bfad, void *cmd) | |
2341 | { | |
2342 | struct bfa_bsg_qos_vc_attr_s *iocmd = | |
2343 | (struct bfa_bsg_qos_vc_attr_s *)cmd; | |
2344 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); | |
2345 | struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr; | |
2346 | unsigned long flags; | |
2347 | u32 i = 0; | |
2348 | ||
2349 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2350 | iocmd->attr.total_vc_count = be16_to_cpu(bfa_vc_attr->total_vc_count); | |
2351 | iocmd->attr.shared_credit = be16_to_cpu(bfa_vc_attr->shared_credit); | |
2352 | iocmd->attr.elp_opmode_flags = | |
2353 | be32_to_cpu(bfa_vc_attr->elp_opmode_flags); | |
2354 | ||
2355 | /* Individual VC info */ | |
2356 | while (i < iocmd->attr.total_vc_count) { | |
2357 | iocmd->attr.vc_info[i].vc_credit = | |
2358 | bfa_vc_attr->vc_info[i].vc_credit; | |
2359 | iocmd->attr.vc_info[i].borrow_credit = | |
2360 | bfa_vc_attr->vc_info[i].borrow_credit; | |
2361 | iocmd->attr.vc_info[i].priority = | |
2362 | bfa_vc_attr->vc_info[i].priority; | |
2363 | i++; | |
2364 | } | |
2365 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2366 | ||
2367 | iocmd->status = BFA_STATUS_OK; | |
2368 | return 0; | |
2369 | } | |
2370 | ||
2371 | int | |
2372 | bfad_iocmd_qos_get_stats(struct bfad_s *bfad, void *cmd) | |
2373 | { | |
2374 | struct bfa_bsg_fcport_stats_s *iocmd = | |
2375 | (struct bfa_bsg_fcport_stats_s *)cmd; | |
2376 | struct bfad_hal_comp fcomp; | |
2377 | unsigned long flags; | |
2378 | struct bfa_cb_pending_q_s cb_qe; | |
bc0e2c2a | 2379 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); |
3ec4f2c8 KG |
2380 | |
2381 | init_completion(&fcomp.comp); | |
2382 | bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, | |
2383 | &fcomp, &iocmd->stats); | |
2384 | ||
2385 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2386 | WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc)); | |
bc0e2c2a KG |
2387 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) && |
2388 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
2389 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
2390 | else | |
2391 | iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe); | |
3ec4f2c8 KG |
2392 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
2393 | if (iocmd->status != BFA_STATUS_OK) { | |
2394 | bfa_trc(bfad, iocmd->status); | |
2395 | goto out; | |
2396 | } | |
2397 | wait_for_completion(&fcomp.comp); | |
2398 | iocmd->status = fcomp.status; | |
2399 | out: | |
2400 | return 0; | |
2401 | } | |
2402 | ||
2403 | int | |
2404 | bfad_iocmd_qos_reset_stats(struct bfad_s *bfad, void *cmd) | |
2405 | { | |
2406 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd; | |
2407 | struct bfad_hal_comp fcomp; | |
2408 | unsigned long flags; | |
2409 | struct bfa_cb_pending_q_s cb_qe; | |
bc0e2c2a | 2410 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa); |
3ec4f2c8 KG |
2411 | |
2412 | init_completion(&fcomp.comp); | |
2413 | bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, | |
2414 | &fcomp, NULL); | |
2415 | ||
2416 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2417 | WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc)); | |
bc0e2c2a KG |
2418 | if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) && |
2419 | (fcport->topology == BFA_PORT_TOPOLOGY_LOOP)) | |
2420 | iocmd->status = BFA_STATUS_TOPOLOGY_LOOP; | |
2421 | else | |
2422 | iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe); | |
3ec4f2c8 KG |
2423 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
2424 | if (iocmd->status != BFA_STATUS_OK) { | |
2425 | bfa_trc(bfad, iocmd->status); | |
2426 | goto out; | |
2427 | } | |
2428 | wait_for_completion(&fcomp.comp); | |
2429 | iocmd->status = fcomp.status; | |
2430 | out: | |
2431 | return 0; | |
2432 | } | |
2433 | ||
c0350bf5 KG |
2434 | int |
2435 | bfad_iocmd_vf_get_stats(struct bfad_s *bfad, void *cmd) | |
2436 | { | |
2437 | struct bfa_bsg_vf_stats_s *iocmd = | |
2438 | (struct bfa_bsg_vf_stats_s *)cmd; | |
2439 | struct bfa_fcs_fabric_s *fcs_vf; | |
2440 | unsigned long flags; | |
2441 | ||
2442 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2443 | fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id); | |
2444 | if (fcs_vf == NULL) { | |
2445 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2446 | iocmd->status = BFA_STATUS_UNKNOWN_VFID; | |
2447 | goto out; | |
2448 | } | |
2449 | memcpy((void *)&iocmd->stats, (void *)&fcs_vf->stats, | |
2450 | sizeof(struct bfa_vf_stats_s)); | |
2451 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2452 | iocmd->status = BFA_STATUS_OK; | |
2453 | out: | |
2454 | return 0; | |
2455 | } | |
2456 | ||
2457 | int | |
2458 | bfad_iocmd_vf_clr_stats(struct bfad_s *bfad, void *cmd) | |
2459 | { | |
2460 | struct bfa_bsg_vf_reset_stats_s *iocmd = | |
2461 | (struct bfa_bsg_vf_reset_stats_s *)cmd; | |
2462 | struct bfa_fcs_fabric_s *fcs_vf; | |
2463 | unsigned long flags; | |
2464 | ||
2465 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2466 | fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id); | |
2467 | if (fcs_vf == NULL) { | |
2468 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2469 | iocmd->status = BFA_STATUS_UNKNOWN_VFID; | |
2470 | goto out; | |
2471 | } | |
2472 | memset((void *)&fcs_vf->stats, 0, sizeof(struct bfa_vf_stats_s)); | |
2473 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2474 | iocmd->status = BFA_STATUS_OK; | |
2475 | out: | |
2476 | return 0; | |
2477 | } | |
2478 | ||
5b7db7af KG |
2479 | /* Function to reset the LUN SCAN mode */ |
2480 | static void | |
2481 | bfad_iocmd_lunmask_reset_lunscan_mode(struct bfad_s *bfad, int lunmask_cfg) | |
2482 | { | |
2483 | struct bfad_im_port_s *pport_im = bfad->pport.im_port; | |
2484 | struct bfad_vport_s *vport = NULL; | |
2485 | ||
2486 | /* Set the scsi device LUN SCAN flags for base port */ | |
2487 | bfad_reset_sdev_bflags(pport_im, lunmask_cfg); | |
2488 | ||
2489 | /* Set the scsi device LUN SCAN flags for the vports */ | |
2490 | list_for_each_entry(vport, &bfad->vport_list, list_entry) | |
2491 | bfad_reset_sdev_bflags(vport->drv_port.im_port, lunmask_cfg); | |
2492 | } | |
2493 | ||
4c5d22bf KG |
2494 | int |
2495 | bfad_iocmd_lunmask(struct bfad_s *bfad, void *pcmd, unsigned int v_cmd) | |
2496 | { | |
2497 | struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd; | |
2498 | unsigned long flags; | |
2499 | ||
2500 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
5b7db7af | 2501 | if (v_cmd == IOCMD_FCPIM_LUNMASK_ENABLE) { |
4c5d22bf | 2502 | iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_TRUE); |
5b7db7af KG |
2503 | /* Set the LUN Scanning mode to be Sequential scan */ |
2504 | if (iocmd->status == BFA_STATUS_OK) | |
2505 | bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_TRUE); | |
2506 | } else if (v_cmd == IOCMD_FCPIM_LUNMASK_DISABLE) { | |
4c5d22bf | 2507 | iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_FALSE); |
5b7db7af KG |
2508 | /* Set the LUN Scanning mode to default REPORT_LUNS scan */ |
2509 | if (iocmd->status == BFA_STATUS_OK) | |
2510 | bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_FALSE); | |
2511 | } else if (v_cmd == IOCMD_FCPIM_LUNMASK_CLEAR) | |
4c5d22bf KG |
2512 | iocmd->status = bfa_fcpim_lunmask_clear(&bfad->bfa); |
2513 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2514 | return 0; | |
2515 | } | |
2516 | ||
2517 | int | |
2518 | bfad_iocmd_fcpim_lunmask_query(struct bfad_s *bfad, void *cmd) | |
2519 | { | |
2520 | struct bfa_bsg_fcpim_lunmask_query_s *iocmd = | |
2521 | (struct bfa_bsg_fcpim_lunmask_query_s *)cmd; | |
2522 | struct bfa_lunmask_cfg_s *lun_mask = &iocmd->lun_mask; | |
2523 | unsigned long flags; | |
2524 | ||
2525 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2526 | iocmd->status = bfa_fcpim_lunmask_query(&bfad->bfa, lun_mask); | |
2527 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2528 | return 0; | |
2529 | } | |
2530 | ||
2531 | int | |
2532 | bfad_iocmd_fcpim_cfg_lunmask(struct bfad_s *bfad, void *cmd, unsigned int v_cmd) | |
2533 | { | |
2534 | struct bfa_bsg_fcpim_lunmask_s *iocmd = | |
2535 | (struct bfa_bsg_fcpim_lunmask_s *)cmd; | |
2536 | unsigned long flags; | |
2537 | ||
2538 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2539 | if (v_cmd == IOCMD_FCPIM_LUNMASK_ADD) | |
2540 | iocmd->status = bfa_fcpim_lunmask_add(&bfad->bfa, iocmd->vf_id, | |
2541 | &iocmd->pwwn, iocmd->rpwwn, iocmd->lun); | |
2542 | else if (v_cmd == IOCMD_FCPIM_LUNMASK_DELETE) | |
2543 | iocmd->status = bfa_fcpim_lunmask_delete(&bfad->bfa, | |
2544 | iocmd->vf_id, &iocmd->pwwn, | |
2545 | iocmd->rpwwn, iocmd->lun); | |
2546 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2547 | return 0; | |
2548 | } | |
2549 | ||
7ace27ae KG |
2550 | int |
2551 | bfad_iocmd_fcpim_throttle_query(struct bfad_s *bfad, void *cmd) | |
2552 | { | |
2553 | struct bfa_bsg_fcpim_throttle_s *iocmd = | |
2554 | (struct bfa_bsg_fcpim_throttle_s *)cmd; | |
2555 | unsigned long flags; | |
2556 | ||
2557 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2558 | iocmd->status = bfa_fcpim_throttle_get(&bfad->bfa, | |
2559 | (void *)&iocmd->throttle); | |
2560 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2561 | ||
2562 | return 0; | |
2563 | } | |
2564 | ||
2565 | int | |
2566 | bfad_iocmd_fcpim_throttle_set(struct bfad_s *bfad, void *cmd) | |
2567 | { | |
2568 | struct bfa_bsg_fcpim_throttle_s *iocmd = | |
2569 | (struct bfa_bsg_fcpim_throttle_s *)cmd; | |
2570 | unsigned long flags; | |
2571 | ||
2572 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
2573 | iocmd->status = bfa_fcpim_throttle_set(&bfad->bfa, | |
2574 | iocmd->throttle.cfg_value); | |
2575 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
2576 | ||
2577 | return 0; | |
2578 | } | |
2579 | ||
b85daafe KG |
2580 | static int |
2581 | bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd, | |
2582 | unsigned int payload_len) | |
2583 | { | |
9afbcfab | 2584 | int rc = -EINVAL; |
b85daafe KG |
2585 | |
2586 | switch (cmd) { | |
60138066 KG |
2587 | case IOCMD_IOC_ENABLE: |
2588 | rc = bfad_iocmd_ioc_enable(bfad, iocmd); | |
2589 | break; | |
2590 | case IOCMD_IOC_DISABLE: | |
2591 | rc = bfad_iocmd_ioc_disable(bfad, iocmd); | |
2592 | break; | |
b85daafe KG |
2593 | case IOCMD_IOC_GET_INFO: |
2594 | rc = bfad_iocmd_ioc_get_info(bfad, iocmd); | |
2595 | break; | |
2596 | case IOCMD_IOC_GET_ATTR: | |
2597 | rc = bfad_iocmd_ioc_get_attr(bfad, iocmd); | |
2598 | break; | |
60138066 KG |
2599 | case IOCMD_IOC_GET_STATS: |
2600 | rc = bfad_iocmd_ioc_get_stats(bfad, iocmd); | |
2601 | break; | |
2602 | case IOCMD_IOC_GET_FWSTATS: | |
2603 | rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len); | |
2604 | break; | |
f2ee7601 KG |
2605 | case IOCMD_IOC_RESET_STATS: |
2606 | case IOCMD_IOC_RESET_FWSTATS: | |
2607 | rc = bfad_iocmd_ioc_reset_stats(bfad, iocmd, cmd); | |
2608 | break; | |
2609 | case IOCMD_IOC_SET_ADAPTER_NAME: | |
2610 | case IOCMD_IOC_SET_PORT_NAME: | |
2611 | rc = bfad_iocmd_ioc_set_name(bfad, iocmd, cmd); | |
2612 | break; | |
60138066 KG |
2613 | case IOCMD_IOCFC_GET_ATTR: |
2614 | rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd); | |
2615 | break; | |
2616 | case IOCMD_IOCFC_SET_INTR: | |
2617 | rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd); | |
2618 | break; | |
2619 | case IOCMD_PORT_ENABLE: | |
2620 | rc = bfad_iocmd_port_enable(bfad, iocmd); | |
2621 | break; | |
2622 | case IOCMD_PORT_DISABLE: | |
2623 | rc = bfad_iocmd_port_disable(bfad, iocmd); | |
2624 | break; | |
b85daafe KG |
2625 | case IOCMD_PORT_GET_ATTR: |
2626 | rc = bfad_iocmd_port_get_attr(bfad, iocmd); | |
2627 | break; | |
60138066 KG |
2628 | case IOCMD_PORT_GET_STATS: |
2629 | rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len); | |
2630 | break; | |
f2ee7601 KG |
2631 | case IOCMD_PORT_RESET_STATS: |
2632 | rc = bfad_iocmd_port_reset_stats(bfad, iocmd); | |
2633 | break; | |
2634 | case IOCMD_PORT_CFG_TOPO: | |
2635 | case IOCMD_PORT_CFG_SPEED: | |
2636 | case IOCMD_PORT_CFG_ALPA: | |
2637 | case IOCMD_PORT_CLR_ALPA: | |
2638 | rc = bfad_iocmd_set_port_cfg(bfad, iocmd, cmd); | |
2639 | break; | |
2640 | case IOCMD_PORT_CFG_MAXFRSZ: | |
2641 | rc = bfad_iocmd_port_cfg_maxfrsize(bfad, iocmd); | |
2642 | break; | |
2643 | case IOCMD_PORT_BBSC_ENABLE: | |
2644 | case IOCMD_PORT_BBSC_DISABLE: | |
2645 | rc = bfad_iocmd_port_cfg_bbsc(bfad, iocmd, cmd); | |
2646 | break; | |
b85daafe KG |
2647 | case IOCMD_LPORT_GET_ATTR: |
2648 | rc = bfad_iocmd_lport_get_attr(bfad, iocmd); | |
2649 | break; | |
60138066 KG |
2650 | case IOCMD_LPORT_GET_STATS: |
2651 | rc = bfad_iocmd_lport_get_stats(bfad, iocmd); | |
2652 | break; | |
f2ee7601 KG |
2653 | case IOCMD_LPORT_RESET_STATS: |
2654 | rc = bfad_iocmd_lport_reset_stats(bfad, iocmd); | |
2655 | break; | |
60138066 KG |
2656 | case IOCMD_LPORT_GET_IOSTATS: |
2657 | rc = bfad_iocmd_lport_get_iostats(bfad, iocmd); | |
2658 | break; | |
2659 | case IOCMD_LPORT_GET_RPORTS: | |
2660 | rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len); | |
2661 | break; | |
2662 | case IOCMD_RPORT_GET_ATTR: | |
2663 | rc = bfad_iocmd_rport_get_attr(bfad, iocmd); | |
2664 | break; | |
b85daafe KG |
2665 | case IOCMD_RPORT_GET_ADDR: |
2666 | rc = bfad_iocmd_rport_get_addr(bfad, iocmd); | |
2667 | break; | |
60138066 KG |
2668 | case IOCMD_RPORT_GET_STATS: |
2669 | rc = bfad_iocmd_rport_get_stats(bfad, iocmd); | |
2670 | break; | |
f2ee7601 KG |
2671 | case IOCMD_RPORT_RESET_STATS: |
2672 | rc = bfad_iocmd_rport_clr_stats(bfad, iocmd); | |
2673 | break; | |
2674 | case IOCMD_RPORT_SET_SPEED: | |
2675 | rc = bfad_iocmd_rport_set_speed(bfad, iocmd); | |
2676 | break; | |
2677 | case IOCMD_VPORT_GET_ATTR: | |
2678 | rc = bfad_iocmd_vport_get_attr(bfad, iocmd); | |
2679 | break; | |
2680 | case IOCMD_VPORT_GET_STATS: | |
2681 | rc = bfad_iocmd_vport_get_stats(bfad, iocmd); | |
2682 | break; | |
2683 | case IOCMD_VPORT_RESET_STATS: | |
2684 | rc = bfad_iocmd_vport_clr_stats(bfad, iocmd); | |
2685 | break; | |
b85daafe KG |
2686 | case IOCMD_FABRIC_GET_LPORTS: |
2687 | rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len); | |
2688 | break; | |
f2ee7601 KG |
2689 | case IOCMD_RATELIM_ENABLE: |
2690 | case IOCMD_RATELIM_DISABLE: | |
2691 | rc = bfad_iocmd_ratelim(bfad, cmd, iocmd); | |
2692 | break; | |
2693 | case IOCMD_RATELIM_DEF_SPEED: | |
2694 | rc = bfad_iocmd_ratelim_speed(bfad, cmd, iocmd); | |
2695 | break; | |
2696 | case IOCMD_FCPIM_FAILOVER: | |
2697 | rc = bfad_iocmd_cfg_fcpim(bfad, iocmd); | |
2698 | break; | |
60138066 KG |
2699 | case IOCMD_FCPIM_MODSTATS: |
2700 | rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd); | |
2701 | break; | |
f2ee7601 KG |
2702 | case IOCMD_FCPIM_MODSTATSCLR: |
2703 | rc = bfad_iocmd_fcpim_clr_modstats(bfad, iocmd); | |
2704 | break; | |
60138066 KG |
2705 | case IOCMD_FCPIM_DEL_ITN_STATS: |
2706 | rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd); | |
2707 | break; | |
b85daafe KG |
2708 | case IOCMD_ITNIM_GET_ATTR: |
2709 | rc = bfad_iocmd_itnim_get_attr(bfad, iocmd); | |
2710 | break; | |
60138066 KG |
2711 | case IOCMD_ITNIM_GET_IOSTATS: |
2712 | rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd); | |
2713 | break; | |
f2ee7601 KG |
2714 | case IOCMD_ITNIM_RESET_STATS: |
2715 | rc = bfad_iocmd_itnim_reset_stats(bfad, iocmd); | |
2716 | break; | |
60138066 KG |
2717 | case IOCMD_ITNIM_GET_ITNSTATS: |
2718 | rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd); | |
2719 | break; | |
2720 | case IOCMD_FCPORT_ENABLE: | |
2721 | rc = bfad_iocmd_fcport_enable(bfad, iocmd); | |
2722 | break; | |
2723 | case IOCMD_FCPORT_DISABLE: | |
2724 | rc = bfad_iocmd_fcport_disable(bfad, iocmd); | |
2725 | break; | |
1a4d8e1b KG |
2726 | case IOCMD_IOC_PCIFN_CFG: |
2727 | rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd); | |
2728 | break; | |
2729 | case IOCMD_PCIFN_CREATE: | |
2730 | rc = bfad_iocmd_pcifn_create(bfad, iocmd); | |
2731 | break; | |
2732 | case IOCMD_PCIFN_DELETE: | |
2733 | rc = bfad_iocmd_pcifn_delete(bfad, iocmd); | |
2734 | break; | |
2735 | case IOCMD_PCIFN_BW: | |
2736 | rc = bfad_iocmd_pcifn_bw(bfad, iocmd); | |
2737 | break; | |
2738 | case IOCMD_ADAPTER_CFG_MODE: | |
2739 | rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd); | |
2740 | break; | |
2741 | case IOCMD_PORT_CFG_MODE: | |
2742 | rc = bfad_iocmd_port_cfg_mode(bfad, iocmd); | |
2743 | break; | |
2744 | case IOCMD_FLASH_ENABLE_OPTROM: | |
2745 | case IOCMD_FLASH_DISABLE_OPTROM: | |
2746 | rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd); | |
2747 | break; | |
a714134a KG |
2748 | case IOCMD_FAA_QUERY: |
2749 | rc = bfad_iocmd_faa_query(bfad, iocmd); | |
2750 | break; | |
148d6103 KG |
2751 | case IOCMD_CEE_GET_ATTR: |
2752 | rc = bfad_iocmd_cee_attr(bfad, iocmd, payload_len); | |
2753 | break; | |
2754 | case IOCMD_CEE_GET_STATS: | |
2755 | rc = bfad_iocmd_cee_get_stats(bfad, iocmd, payload_len); | |
2756 | break; | |
2757 | case IOCMD_CEE_RESET_STATS: | |
2758 | rc = bfad_iocmd_cee_reset_stats(bfad, iocmd); | |
2759 | break; | |
51e569aa KG |
2760 | case IOCMD_SFP_MEDIA: |
2761 | rc = bfad_iocmd_sfp_media(bfad, iocmd); | |
2762 | break; | |
2763 | case IOCMD_SFP_SPEED: | |
2764 | rc = bfad_iocmd_sfp_speed(bfad, iocmd); | |
2765 | break; | |
5a54b1d5 KG |
2766 | case IOCMD_FLASH_GET_ATTR: |
2767 | rc = bfad_iocmd_flash_get_attr(bfad, iocmd); | |
2768 | break; | |
2769 | case IOCMD_FLASH_ERASE_PART: | |
2770 | rc = bfad_iocmd_flash_erase_part(bfad, iocmd); | |
2771 | break; | |
2772 | case IOCMD_FLASH_UPDATE_PART: | |
2773 | rc = bfad_iocmd_flash_update_part(bfad, iocmd, payload_len); | |
2774 | break; | |
2775 | case IOCMD_FLASH_READ_PART: | |
2776 | rc = bfad_iocmd_flash_read_part(bfad, iocmd, payload_len); | |
2777 | break; | |
3d7fc66d KG |
2778 | case IOCMD_DIAG_TEMP: |
2779 | rc = bfad_iocmd_diag_temp(bfad, iocmd); | |
2780 | break; | |
2781 | case IOCMD_DIAG_MEMTEST: | |
2782 | rc = bfad_iocmd_diag_memtest(bfad, iocmd); | |
2783 | break; | |
2784 | case IOCMD_DIAG_LOOPBACK: | |
2785 | rc = bfad_iocmd_diag_loopback(bfad, iocmd); | |
2786 | break; | |
2787 | case IOCMD_DIAG_FWPING: | |
2788 | rc = bfad_iocmd_diag_fwping(bfad, iocmd); | |
2789 | break; | |
2790 | case IOCMD_DIAG_QUEUETEST: | |
2791 | rc = bfad_iocmd_diag_queuetest(bfad, iocmd); | |
2792 | break; | |
2793 | case IOCMD_DIAG_SFP: | |
2794 | rc = bfad_iocmd_diag_sfp(bfad, iocmd); | |
2795 | break; | |
2796 | case IOCMD_DIAG_LED: | |
2797 | rc = bfad_iocmd_diag_led(bfad, iocmd); | |
2798 | break; | |
2799 | case IOCMD_DIAG_BEACON_LPORT: | |
2800 | rc = bfad_iocmd_diag_beacon_lport(bfad, iocmd); | |
2801 | break; | |
2802 | case IOCMD_DIAG_LB_STAT: | |
2803 | rc = bfad_iocmd_diag_lb_stat(bfad, iocmd); | |
2804 | break; | |
e353546e KG |
2805 | case IOCMD_DIAG_DPORT_ENABLE: |
2806 | case IOCMD_DIAG_DPORT_DISABLE: | |
2807 | rc = bfad_iocmd_diag_cfg_dport(bfad, cmd, iocmd); | |
2808 | break; | |
2809 | case IOCMD_DIAG_DPORT_GET_STATE: | |
2810 | rc = bfad_iocmd_diag_dport_get_state(bfad, iocmd); | |
2811 | break; | |
3350d98d KG |
2812 | case IOCMD_PHY_GET_ATTR: |
2813 | rc = bfad_iocmd_phy_get_attr(bfad, iocmd); | |
2814 | break; | |
2815 | case IOCMD_PHY_GET_STATS: | |
2816 | rc = bfad_iocmd_phy_get_stats(bfad, iocmd); | |
2817 | break; | |
2818 | case IOCMD_PHY_UPDATE_FW: | |
2819 | rc = bfad_iocmd_phy_update(bfad, iocmd, payload_len); | |
2820 | break; | |
2821 | case IOCMD_PHY_READ_FW: | |
2822 | rc = bfad_iocmd_phy_read(bfad, iocmd, payload_len); | |
2823 | break; | |
61e62e21 KG |
2824 | case IOCMD_VHBA_QUERY: |
2825 | rc = bfad_iocmd_vhba_query(bfad, iocmd); | |
2826 | break; | |
2827 | case IOCMD_DEBUG_PORTLOG: | |
2828 | rc = bfad_iocmd_porglog_get(bfad, iocmd); | |
2829 | break; | |
f2ee7601 KG |
2830 | case IOCMD_DEBUG_FW_CORE: |
2831 | rc = bfad_iocmd_debug_fw_core(bfad, iocmd, payload_len); | |
2832 | break; | |
2833 | case IOCMD_DEBUG_FW_STATE_CLR: | |
2834 | case IOCMD_DEBUG_PORTLOG_CLR: | |
2835 | case IOCMD_DEBUG_START_DTRC: | |
2836 | case IOCMD_DEBUG_STOP_DTRC: | |
2837 | rc = bfad_iocmd_debug_ctl(bfad, iocmd, cmd); | |
2838 | break; | |
2839 | case IOCMD_DEBUG_PORTLOG_CTL: | |
2840 | rc = bfad_iocmd_porglog_ctl(bfad, iocmd); | |
2841 | break; | |
42a8e6e2 KG |
2842 | case IOCMD_FCPIM_PROFILE_ON: |
2843 | case IOCMD_FCPIM_PROFILE_OFF: | |
2844 | rc = bfad_iocmd_fcpim_cfg_profile(bfad, iocmd, cmd); | |
2845 | break; | |
2846 | case IOCMD_ITNIM_GET_IOPROFILE: | |
2847 | rc = bfad_iocmd_itnim_get_ioprofile(bfad, iocmd); | |
2848 | break; | |
37ea0558 KG |
2849 | case IOCMD_FCPORT_GET_STATS: |
2850 | rc = bfad_iocmd_fcport_get_stats(bfad, iocmd); | |
2851 | break; | |
2852 | case IOCMD_FCPORT_RESET_STATS: | |
2853 | rc = bfad_iocmd_fcport_reset_stats(bfad, iocmd); | |
2854 | break; | |
a46bd300 KG |
2855 | case IOCMD_BOOT_CFG: |
2856 | rc = bfad_iocmd_boot_cfg(bfad, iocmd); | |
2857 | break; | |
2858 | case IOCMD_BOOT_QUERY: | |
2859 | rc = bfad_iocmd_boot_query(bfad, iocmd); | |
2860 | break; | |
2861 | case IOCMD_PREBOOT_QUERY: | |
2862 | rc = bfad_iocmd_preboot_query(bfad, iocmd); | |
2863 | break; | |
2864 | case IOCMD_ETHBOOT_CFG: | |
2865 | rc = bfad_iocmd_ethboot_cfg(bfad, iocmd); | |
2866 | break; | |
2867 | case IOCMD_ETHBOOT_QUERY: | |
2868 | rc = bfad_iocmd_ethboot_query(bfad, iocmd); | |
2869 | break; | |
45191236 KG |
2870 | case IOCMD_TRUNK_ENABLE: |
2871 | case IOCMD_TRUNK_DISABLE: | |
2872 | rc = bfad_iocmd_cfg_trunk(bfad, iocmd, cmd); | |
2873 | break; | |
2874 | case IOCMD_TRUNK_GET_ATTR: | |
2875 | rc = bfad_iocmd_trunk_get_attr(bfad, iocmd); | |
2876 | break; | |
3ec4f2c8 KG |
2877 | case IOCMD_QOS_ENABLE: |
2878 | case IOCMD_QOS_DISABLE: | |
2879 | rc = bfad_iocmd_qos(bfad, iocmd, cmd); | |
2880 | break; | |
2881 | case IOCMD_QOS_GET_ATTR: | |
2882 | rc = bfad_iocmd_qos_get_attr(bfad, iocmd); | |
2883 | break; | |
2884 | case IOCMD_QOS_GET_VC_ATTR: | |
2885 | rc = bfad_iocmd_qos_get_vc_attr(bfad, iocmd); | |
2886 | break; | |
2887 | case IOCMD_QOS_GET_STATS: | |
2888 | rc = bfad_iocmd_qos_get_stats(bfad, iocmd); | |
2889 | break; | |
2890 | case IOCMD_QOS_RESET_STATS: | |
2891 | rc = bfad_iocmd_qos_reset_stats(bfad, iocmd); | |
2892 | break; | |
6894f013 KG |
2893 | case IOCMD_QOS_SET_BW: |
2894 | rc = bfad_iocmd_qos_set_bw(bfad, iocmd); | |
2895 | break; | |
c0350bf5 KG |
2896 | case IOCMD_VF_GET_STATS: |
2897 | rc = bfad_iocmd_vf_get_stats(bfad, iocmd); | |
2898 | break; | |
2899 | case IOCMD_VF_RESET_STATS: | |
2900 | rc = bfad_iocmd_vf_clr_stats(bfad, iocmd); | |
2901 | break; | |
4c5d22bf KG |
2902 | case IOCMD_FCPIM_LUNMASK_ENABLE: |
2903 | case IOCMD_FCPIM_LUNMASK_DISABLE: | |
2904 | case IOCMD_FCPIM_LUNMASK_CLEAR: | |
2905 | rc = bfad_iocmd_lunmask(bfad, iocmd, cmd); | |
2906 | break; | |
2907 | case IOCMD_FCPIM_LUNMASK_QUERY: | |
2908 | rc = bfad_iocmd_fcpim_lunmask_query(bfad, iocmd); | |
2909 | break; | |
2910 | case IOCMD_FCPIM_LUNMASK_ADD: | |
2911 | case IOCMD_FCPIM_LUNMASK_DELETE: | |
2912 | rc = bfad_iocmd_fcpim_cfg_lunmask(bfad, iocmd, cmd); | |
2913 | break; | |
7ace27ae KG |
2914 | case IOCMD_FCPIM_THROTTLE_QUERY: |
2915 | rc = bfad_iocmd_fcpim_throttle_query(bfad, iocmd); | |
2916 | break; | |
2917 | case IOCMD_FCPIM_THROTTLE_SET: | |
2918 | rc = bfad_iocmd_fcpim_throttle_set(bfad, iocmd); | |
2919 | break; | |
b85daafe | 2920 | default: |
9afbcfab | 2921 | rc = -EINVAL; |
b85daafe KG |
2922 | break; |
2923 | } | |
9afbcfab | 2924 | return rc; |
b85daafe KG |
2925 | } |
2926 | ||
2927 | static int | |
2928 | bfad_im_bsg_vendor_request(struct fc_bsg_job *job) | |
2929 | { | |
2930 | uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0]; | |
2931 | struct bfad_im_port_s *im_port = | |
2932 | (struct bfad_im_port_s *) job->shost->hostdata[0]; | |
2933 | struct bfad_s *bfad = im_port->bfad; | |
bd5a0260 | 2934 | struct request_queue *request_q = job->req->q; |
b85daafe KG |
2935 | void *payload_kbuf; |
2936 | int rc = -EINVAL; | |
2937 | ||
bd5a0260 KG |
2938 | /* |
2939 | * Set the BSG device request_queue size to 256 to support | |
2940 | * payloads larger than 512*1024K bytes. | |
2941 | */ | |
2942 | blk_queue_max_segments(request_q, 256); | |
2943 | ||
b85daafe KG |
2944 | /* Allocate a temp buffer to hold the passed in user space command */ |
2945 | payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL); | |
2946 | if (!payload_kbuf) { | |
2947 | rc = -ENOMEM; | |
2948 | goto out; | |
2949 | } | |
2950 | ||
2951 | /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */ | |
2952 | sg_copy_to_buffer(job->request_payload.sg_list, | |
2953 | job->request_payload.sg_cnt, payload_kbuf, | |
2954 | job->request_payload.payload_len); | |
2955 | ||
2956 | /* Invoke IOCMD handler - to handle all the vendor command requests */ | |
2957 | rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf, | |
2958 | job->request_payload.payload_len); | |
2959 | if (rc != BFA_STATUS_OK) | |
2960 | goto error; | |
2961 | ||
2962 | /* Copy the response data to the job->reply_payload sg_list */ | |
2963 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
2964 | job->reply_payload.sg_cnt, | |
2965 | payload_kbuf, | |
2966 | job->reply_payload.payload_len); | |
2967 | ||
2968 | /* free the command buffer */ | |
2969 | kfree(payload_kbuf); | |
2970 | ||
2971 | /* Fill the BSG job reply data */ | |
2972 | job->reply_len = job->reply_payload.payload_len; | |
2973 | job->reply->reply_payload_rcv_len = job->reply_payload.payload_len; | |
2974 | job->reply->result = rc; | |
2975 | ||
2976 | job->job_done(job); | |
2977 | return rc; | |
2978 | error: | |
2979 | /* free the command buffer */ | |
2980 | kfree(payload_kbuf); | |
2981 | out: | |
2982 | job->reply->result = rc; | |
2983 | job->reply_len = sizeof(uint32_t); | |
2984 | job->reply->reply_payload_rcv_len = 0; | |
2985 | return rc; | |
2986 | } | |
2987 | ||
2988 | /* FC passthru call backs */ | |
2989 | u64 | |
2990 | bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid) | |
2991 | { | |
2992 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
2993 | struct bfa_sge_s *sge; | |
2994 | u64 addr; | |
2995 | ||
2996 | sge = drv_fcxp->req_sge + sgeid; | |
2997 | addr = (u64)(size_t) sge->sg_addr; | |
2998 | return addr; | |
2999 | } | |
3000 | ||
3001 | u32 | |
3002 | bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid) | |
3003 | { | |
3004 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
3005 | struct bfa_sge_s *sge; | |
3006 | ||
3007 | sge = drv_fcxp->req_sge + sgeid; | |
3008 | return sge->sg_len; | |
3009 | } | |
3010 | ||
3011 | u64 | |
3012 | bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid) | |
3013 | { | |
3014 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
3015 | struct bfa_sge_s *sge; | |
3016 | u64 addr; | |
3017 | ||
3018 | sge = drv_fcxp->rsp_sge + sgeid; | |
3019 | addr = (u64)(size_t) sge->sg_addr; | |
3020 | return addr; | |
3021 | } | |
3022 | ||
3023 | u32 | |
3024 | bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid) | |
3025 | { | |
3026 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
3027 | struct bfa_sge_s *sge; | |
3028 | ||
3029 | sge = drv_fcxp->rsp_sge + sgeid; | |
3030 | return sge->sg_len; | |
3031 | } | |
3032 | ||
3033 | void | |
3034 | bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg, | |
3035 | bfa_status_t req_status, u32 rsp_len, u32 resid_len, | |
3036 | struct fchs_s *rsp_fchs) | |
3037 | { | |
3038 | struct bfad_fcxp *drv_fcxp = bfad_fcxp; | |
3039 | ||
3040 | drv_fcxp->req_status = req_status; | |
3041 | drv_fcxp->rsp_len = rsp_len; | |
3042 | ||
3043 | /* bfa_fcxp will be automatically freed by BFA */ | |
3044 | drv_fcxp->bfa_fcxp = NULL; | |
3045 | complete(&drv_fcxp->comp); | |
3046 | } | |
3047 | ||
3048 | struct bfad_buf_info * | |
3049 | bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf, | |
3050 | uint32_t payload_len, uint32_t *num_sgles) | |
3051 | { | |
3052 | struct bfad_buf_info *buf_base, *buf_info; | |
3053 | struct bfa_sge_s *sg_table; | |
3054 | int sge_num = 1; | |
3055 | ||
3056 | buf_base = kzalloc((sizeof(struct bfad_buf_info) + | |
3057 | sizeof(struct bfa_sge_s)) * sge_num, GFP_KERNEL); | |
3058 | if (!buf_base) | |
3059 | return NULL; | |
3060 | ||
3061 | sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) + | |
3062 | (sizeof(struct bfad_buf_info) * sge_num)); | |
3063 | ||
3064 | /* Allocate dma coherent memory */ | |
3065 | buf_info = buf_base; | |
3066 | buf_info->size = payload_len; | |
3067 | buf_info->virt = dma_alloc_coherent(&bfad->pcidev->dev, buf_info->size, | |
3068 | &buf_info->phys, GFP_KERNEL); | |
3069 | if (!buf_info->virt) | |
3070 | goto out_free_mem; | |
3071 | ||
3072 | /* copy the linear bsg buffer to buf_info */ | |
3073 | memset(buf_info->virt, 0, buf_info->size); | |
3074 | memcpy(buf_info->virt, payload_kbuf, buf_info->size); | |
3075 | ||
3076 | /* | |
3077 | * Setup SG table | |
3078 | */ | |
3079 | sg_table->sg_len = buf_info->size; | |
3080 | sg_table->sg_addr = (void *)(size_t) buf_info->phys; | |
3081 | ||
3082 | *num_sgles = sge_num; | |
3083 | ||
3084 | return buf_base; | |
3085 | ||
3086 | out_free_mem: | |
3087 | kfree(buf_base); | |
3088 | return NULL; | |
3089 | } | |
3090 | ||
3091 | void | |
3092 | bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base, | |
3093 | uint32_t num_sgles) | |
3094 | { | |
3095 | int i; | |
3096 | struct bfad_buf_info *buf_info = buf_base; | |
3097 | ||
3098 | if (buf_base) { | |
3099 | for (i = 0; i < num_sgles; buf_info++, i++) { | |
3100 | if (buf_info->virt != NULL) | |
3101 | dma_free_coherent(&bfad->pcidev->dev, | |
3102 | buf_info->size, buf_info->virt, | |
3103 | buf_info->phys); | |
3104 | } | |
3105 | kfree(buf_base); | |
3106 | } | |
3107 | } | |
3108 | ||
3109 | int | |
3110 | bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp, | |
3111 | bfa_bsg_fcpt_t *bsg_fcpt) | |
3112 | { | |
3113 | struct bfa_fcxp_s *hal_fcxp; | |
3114 | struct bfad_s *bfad = drv_fcxp->port->bfad; | |
3115 | unsigned long flags; | |
3116 | uint8_t lp_tag; | |
3117 | ||
3118 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
3119 | ||
3120 | /* Allocate bfa_fcxp structure */ | |
c3f1b123 | 3121 | hal_fcxp = bfa_fcxp_req_rsp_alloc(drv_fcxp, &bfad->bfa, |
b85daafe KG |
3122 | drv_fcxp->num_req_sgles, |
3123 | drv_fcxp->num_rsp_sgles, | |
3124 | bfad_fcxp_get_req_sgaddr_cb, | |
3125 | bfad_fcxp_get_req_sglen_cb, | |
3126 | bfad_fcxp_get_rsp_sgaddr_cb, | |
c3f1b123 | 3127 | bfad_fcxp_get_rsp_sglen_cb, BFA_TRUE); |
b85daafe KG |
3128 | if (!hal_fcxp) { |
3129 | bfa_trc(bfad, 0); | |
3130 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
3131 | return BFA_STATUS_ENOMEM; | |
3132 | } | |
3133 | ||
3134 | drv_fcxp->bfa_fcxp = hal_fcxp; | |
3135 | ||
3136 | lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id); | |
3137 | ||
3138 | bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag, | |
3139 | bsg_fcpt->cts, bsg_fcpt->cos, | |
3140 | job->request_payload.payload_len, | |
3141 | &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad, | |
3142 | job->reply_payload.payload_len, bsg_fcpt->tsecs); | |
3143 | ||
3144 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
3145 | ||
3146 | return BFA_STATUS_OK; | |
3147 | } | |
3148 | ||
3149 | int | |
3150 | bfad_im_bsg_els_ct_request(struct fc_bsg_job *job) | |
3151 | { | |
3152 | struct bfa_bsg_data *bsg_data; | |
3153 | struct bfad_im_port_s *im_port = | |
3154 | (struct bfad_im_port_s *) job->shost->hostdata[0]; | |
3155 | struct bfad_s *bfad = im_port->bfad; | |
3156 | bfa_bsg_fcpt_t *bsg_fcpt; | |
3157 | struct bfad_fcxp *drv_fcxp; | |
3158 | struct bfa_fcs_lport_s *fcs_port; | |
3159 | struct bfa_fcs_rport_s *fcs_rport; | |
3160 | uint32_t command_type = job->request->msgcode; | |
3161 | unsigned long flags; | |
3162 | struct bfad_buf_info *rsp_buf_info; | |
3163 | void *req_kbuf = NULL, *rsp_kbuf = NULL; | |
3164 | int rc = -EINVAL; | |
3165 | ||
3166 | job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */ | |
3167 | job->reply->reply_payload_rcv_len = 0; | |
3168 | ||
3169 | /* Get the payload passed in from userspace */ | |
3170 | bsg_data = (struct bfa_bsg_data *) (((char *)job->request) + | |
3171 | sizeof(struct fc_bsg_request)); | |
3172 | if (bsg_data == NULL) | |
3173 | goto out; | |
3174 | ||
3175 | /* | |
3176 | * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload | |
3177 | * buffer of size bsg_data->payload_len | |
3178 | */ | |
64b8aa75 | 3179 | bsg_fcpt = kzalloc(bsg_data->payload_len, GFP_KERNEL); |
529f9a76 KG |
3180 | if (!bsg_fcpt) { |
3181 | rc = -ENOMEM; | |
b85daafe | 3182 | goto out; |
529f9a76 | 3183 | } |
b85daafe KG |
3184 | |
3185 | if (copy_from_user((uint8_t *)bsg_fcpt, bsg_data->payload, | |
3186 | bsg_data->payload_len)) { | |
3187 | kfree(bsg_fcpt); | |
529f9a76 | 3188 | rc = -EIO; |
b85daafe KG |
3189 | goto out; |
3190 | } | |
3191 | ||
3192 | drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL); | |
3193 | if (drv_fcxp == NULL) { | |
64b8aa75 | 3194 | kfree(bsg_fcpt); |
b85daafe KG |
3195 | rc = -ENOMEM; |
3196 | goto out; | |
3197 | } | |
3198 | ||
3199 | spin_lock_irqsave(&bfad->bfad_lock, flags); | |
3200 | fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id, | |
3201 | bsg_fcpt->lpwwn); | |
3202 | if (fcs_port == NULL) { | |
3203 | bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN; | |
3204 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
3205 | goto out_free_mem; | |
3206 | } | |
3207 | ||
3208 | /* Check if the port is online before sending FC Passthru cmd */ | |
3209 | if (!bfa_fcs_lport_is_online(fcs_port)) { | |
3210 | bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE; | |
3211 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
3212 | goto out_free_mem; | |
3213 | } | |
3214 | ||
3215 | drv_fcxp->port = fcs_port->bfad_port; | |
3216 | ||
3217 | if (drv_fcxp->port->bfad == 0) | |
3218 | drv_fcxp->port->bfad = bfad; | |
3219 | ||
3220 | /* Fetch the bfa_rport - if nexus needed */ | |
3221 | if (command_type == FC_BSG_HST_ELS_NOLOGIN || | |
3222 | command_type == FC_BSG_HST_CT) { | |
3223 | /* BSG HST commands: no nexus needed */ | |
3224 | drv_fcxp->bfa_rport = NULL; | |
3225 | ||
3226 | } else if (command_type == FC_BSG_RPT_ELS || | |
3227 | command_type == FC_BSG_RPT_CT) { | |
3228 | /* BSG RPT commands: nexus needed */ | |
3229 | fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port, | |
3230 | bsg_fcpt->dpwwn); | |
3231 | if (fcs_rport == NULL) { | |
3232 | bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN; | |
3233 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
3234 | goto out_free_mem; | |
3235 | } | |
3236 | ||
3237 | drv_fcxp->bfa_rport = fcs_rport->bfa_rport; | |
3238 | ||
3239 | } else { /* Unknown BSG msgcode; return -EINVAL */ | |
3240 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
3241 | goto out_free_mem; | |
3242 | } | |
3243 | ||
3244 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); | |
3245 | ||
3246 | /* allocate memory for req / rsp buffers */ | |
3247 | req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL); | |
3248 | if (!req_kbuf) { | |
3249 | printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n", | |
3250 | bfad->pci_name); | |
3251 | rc = -ENOMEM; | |
3252 | goto out_free_mem; | |
3253 | } | |
3254 | ||
3255 | rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL); | |
3256 | if (!rsp_kbuf) { | |
3257 | printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n", | |
3258 | bfad->pci_name); | |
3259 | rc = -ENOMEM; | |
3260 | goto out_free_mem; | |
3261 | } | |
3262 | ||
3263 | /* map req sg - copy the sg_list passed in to the linear buffer */ | |
3264 | sg_copy_to_buffer(job->request_payload.sg_list, | |
3265 | job->request_payload.sg_cnt, req_kbuf, | |
3266 | job->request_payload.payload_len); | |
3267 | ||
3268 | drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf, | |
3269 | job->request_payload.payload_len, | |
3270 | &drv_fcxp->num_req_sgles); | |
3271 | if (!drv_fcxp->reqbuf_info) { | |
3272 | printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n", | |
3273 | bfad->pci_name); | |
3274 | rc = -ENOMEM; | |
3275 | goto out_free_mem; | |
3276 | } | |
3277 | ||
3278 | drv_fcxp->req_sge = (struct bfa_sge_s *) | |
3279 | (((uint8_t *)drv_fcxp->reqbuf_info) + | |
3280 | (sizeof(struct bfad_buf_info) * | |
3281 | drv_fcxp->num_req_sgles)); | |
3282 | ||
3283 | /* map rsp sg */ | |
3284 | drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf, | |
3285 | job->reply_payload.payload_len, | |
3286 | &drv_fcxp->num_rsp_sgles); | |
3287 | if (!drv_fcxp->rspbuf_info) { | |
3288 | printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n", | |
3289 | bfad->pci_name); | |
3290 | rc = -ENOMEM; | |
3291 | goto out_free_mem; | |
3292 | } | |
3293 | ||
3294 | rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info; | |
3295 | drv_fcxp->rsp_sge = (struct bfa_sge_s *) | |
3296 | (((uint8_t *)drv_fcxp->rspbuf_info) + | |
3297 | (sizeof(struct bfad_buf_info) * | |
3298 | drv_fcxp->num_rsp_sgles)); | |
3299 | ||
3300 | /* fcxp send */ | |
3301 | init_completion(&drv_fcxp->comp); | |
3302 | rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt); | |
3303 | if (rc == BFA_STATUS_OK) { | |
3304 | wait_for_completion(&drv_fcxp->comp); | |
3305 | bsg_fcpt->status = drv_fcxp->req_status; | |
3306 | } else { | |
3307 | bsg_fcpt->status = rc; | |
3308 | goto out_free_mem; | |
3309 | } | |
3310 | ||
3311 | /* fill the job->reply data */ | |
3312 | if (drv_fcxp->req_status == BFA_STATUS_OK) { | |
3313 | job->reply_len = drv_fcxp->rsp_len; | |
3314 | job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len; | |
3315 | job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK; | |
3316 | } else { | |
3317 | job->reply->reply_payload_rcv_len = | |
3318 | sizeof(struct fc_bsg_ctels_reply); | |
3319 | job->reply_len = sizeof(uint32_t); | |
3320 | job->reply->reply_data.ctels_reply.status = | |
3321 | FC_CTELS_STATUS_REJECT; | |
3322 | } | |
3323 | ||
3324 | /* Copy the response data to the reply_payload sg list */ | |
3325 | sg_copy_from_buffer(job->reply_payload.sg_list, | |
3326 | job->reply_payload.sg_cnt, | |
3327 | (uint8_t *)rsp_buf_info->virt, | |
3328 | job->reply_payload.payload_len); | |
3329 | ||
3330 | out_free_mem: | |
3331 | bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info, | |
3332 | drv_fcxp->num_rsp_sgles); | |
3333 | bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info, | |
3334 | drv_fcxp->num_req_sgles); | |
3335 | kfree(req_kbuf); | |
3336 | kfree(rsp_kbuf); | |
3337 | ||
3338 | /* Need a copy to user op */ | |
3339 | if (copy_to_user(bsg_data->payload, (void *) bsg_fcpt, | |
3340 | bsg_data->payload_len)) | |
3341 | rc = -EIO; | |
3342 | ||
3343 | kfree(bsg_fcpt); | |
3344 | kfree(drv_fcxp); | |
3345 | out: | |
3346 | job->reply->result = rc; | |
3347 | ||
3348 | if (rc == BFA_STATUS_OK) | |
3349 | job->job_done(job); | |
3350 | ||
3351 | return rc; | |
3352 | } | |
3353 | ||
3354 | int | |
3355 | bfad_im_bsg_request(struct fc_bsg_job *job) | |
3356 | { | |
3357 | uint32_t rc = BFA_STATUS_OK; | |
3358 | ||
b85daafe KG |
3359 | switch (job->request->msgcode) { |
3360 | case FC_BSG_HST_VENDOR: | |
3361 | /* Process BSG HST Vendor requests */ | |
3362 | rc = bfad_im_bsg_vendor_request(job); | |
3363 | break; | |
3364 | case FC_BSG_HST_ELS_NOLOGIN: | |
3365 | case FC_BSG_RPT_ELS: | |
3366 | case FC_BSG_HST_CT: | |
3367 | case FC_BSG_RPT_CT: | |
3368 | /* Process BSG ELS/CT commands */ | |
3369 | rc = bfad_im_bsg_els_ct_request(job); | |
3370 | break; | |
3371 | default: | |
3372 | job->reply->result = rc = -EINVAL; | |
3373 | job->reply->reply_payload_rcv_len = 0; | |
3374 | break; | |
3375 | } | |
3376 | ||
b85daafe KG |
3377 | return rc; |
3378 | } | |
3379 | ||
3380 | int | |
3381 | bfad_im_bsg_timeout(struct fc_bsg_job *job) | |
3382 | { | |
3383 | /* Don't complete the BSG job request - return -EAGAIN | |
3384 | * to reset bsg job timeout : for ELS/CT pass thru we | |
3385 | * already have timer to track the request. | |
3386 | */ | |
3387 | return -EAGAIN; | |
3388 | } |