i2c-eg20t: change timeout value 50msec to 1000msec
[zen-stable.git] / drivers / scsi / bfa / bfad_bsg.c
blob530de2b1200a20c58b0e88a49c299ed97c2d1126
1 /*
2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
18 #include <linux/uaccess.h>
19 #include "bfad_drv.h"
20 #include "bfad_im.h"
21 #include "bfad_bsg.h"
23 BFA_TRC_FILE(LDRV, BSG);
25 int
26 bfad_iocmd_ioc_enable(struct bfad_s *bfad, void *cmd)
28 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
29 int rc = 0;
30 unsigned long flags;
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;
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);
46 return rc;
49 int
50 bfad_iocmd_ioc_disable(struct bfad_s *bfad, void *cmd)
52 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
53 int rc = 0;
54 unsigned long flags;
56 spin_lock_irqsave(&bfad->bfad_lock, flags);
57 if (bfad->disable_active) {
58 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
59 return -EBUSY;
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);
67 wait_for_completion(&bfad->disable_comp);
68 bfad->disable_active = BFA_FALSE;
69 iocmd->status = BFA_STATUS_OK;
71 return rc;
74 static int
75 bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd)
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;
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;
93 iocmd->bfad_num = bfad->inst_no;
94 im_port = bfad->pport.im_port;
95 iocmd->host = im_port->shost->host_no;
96 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
98 strcpy(iocmd->name, bfad->adapter_name);
99 strcpy(iocmd->port_name, bfad->port_name);
100 strcpy(iocmd->hwpath, bfad->pci_name);
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;
112 static int
113 bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd)
115 struct bfa_bsg_ioc_attr_s *iocmd = (struct bfa_bsg_ioc_attr_s *)cmd;
116 unsigned long flags;
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);
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);
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));
137 iocmd->status = BFA_STATUS_OK;
138 return 0;
142 bfad_iocmd_ioc_get_stats(struct bfad_s *bfad, void *cmd)
144 struct bfa_bsg_ioc_stats_s *iocmd = (struct bfa_bsg_ioc_stats_s *)cmd;
146 bfa_ioc_get_stats(&bfad->bfa, &iocmd->ioc_stats);
147 iocmd->status = BFA_STATUS_OK;
148 return 0;
152 bfad_iocmd_ioc_get_fwstats(struct bfad_s *bfad, void *cmd,
153 unsigned int payload_len)
155 struct bfa_bsg_ioc_fwstats_s *iocmd =
156 (struct bfa_bsg_ioc_fwstats_s *)cmd;
157 void *iocmd_bufptr;
158 unsigned long flags;
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;
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);
172 if (iocmd->status != BFA_STATUS_OK) {
173 bfa_trc(bfad, iocmd->status);
174 goto out;
176 out:
177 bfa_trc(bfad, 0x6666);
178 return 0;
182 bfad_iocmd_ioc_reset_stats(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
184 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
185 unsigned long flags;
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);
196 return 0;
200 bfad_iocmd_ioc_set_name(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
202 struct bfa_bsg_ioc_name_s *iocmd = (struct bfa_bsg_ioc_name_s *) cmd;
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);
209 iocmd->status = BFA_STATUS_OK;
210 return 0;
214 bfad_iocmd_iocfc_get_attr(struct bfad_s *bfad, void *cmd)
216 struct bfa_bsg_iocfc_attr_s *iocmd = (struct bfa_bsg_iocfc_attr_s *)cmd;
218 iocmd->status = BFA_STATUS_OK;
219 bfa_iocfc_get_attr(&bfad->bfa, &iocmd->iocfc_attr);
221 return 0;
225 bfad_iocmd_iocfc_set_intr(struct bfad_s *bfad, void *cmd)
227 struct bfa_bsg_iocfc_intr_s *iocmd = (struct bfa_bsg_iocfc_intr_s *)cmd;
228 unsigned long flags;
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);
234 return 0;
238 bfad_iocmd_port_enable(struct bfad_s *bfad, void *cmd)
240 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
241 struct bfad_hal_comp fcomp;
242 unsigned long flags;
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;
253 wait_for_completion(&fcomp.comp);
254 iocmd->status = fcomp.status;
255 return 0;
259 bfad_iocmd_port_disable(struct bfad_s *bfad, void *cmd)
261 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
262 struct bfad_hal_comp fcomp;
263 unsigned long flags;
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);
271 if (iocmd->status != BFA_STATUS_OK) {
272 bfa_trc(bfad, iocmd->status);
273 return 0;
275 wait_for_completion(&fcomp.comp);
276 iocmd->status = fcomp.status;
277 return 0;
280 static int
281 bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd)
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;
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);
292 if (iocmd->attr.topology != BFA_PORT_TOPOLOGY_NONE)
293 iocmd->attr.pid = port_attr.pid;
294 else
295 iocmd->attr.pid = 0;
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));
304 iocmd->status = BFA_STATUS_OK;
305 return 0;
309 bfad_iocmd_port_get_stats(struct bfad_s *bfad, void *cmd,
310 unsigned int payload_len)
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;
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;
324 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_port_stats_s);
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;
336 wait_for_completion(&fcomp.comp);
337 iocmd->status = fcomp.status;
338 out:
339 return 0;
343 bfad_iocmd_port_reset_stats(struct bfad_s *bfad, void *cmd)
345 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
346 struct bfad_hal_comp fcomp;
347 unsigned long flags;
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;
358 wait_for_completion(&fcomp.comp);
359 iocmd->status = fcomp.status;
360 return 0;
364 bfad_iocmd_set_port_cfg(struct bfad_s *bfad, void *iocmd, unsigned int v_cmd)
366 struct bfa_bsg_port_cfg_s *cmd = (struct bfa_bsg_port_cfg_s *)iocmd;
367 unsigned long flags;
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);
380 return 0;
384 bfad_iocmd_port_cfg_maxfrsize(struct bfad_s *bfad, void *cmd)
386 struct bfa_bsg_port_cfg_maxfrsize_s *iocmd =
387 (struct bfa_bsg_port_cfg_maxfrsize_s *)cmd;
388 unsigned long flags;
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);
394 return 0;
398 bfad_iocmd_port_cfg_bbsc(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
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;
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;
411 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
413 iocmd->status = BFA_STATUS_OK;
414 return 0;
417 static int
418 bfad_iocmd_lport_get_attr(struct bfad_s *bfad, void *cmd)
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;
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;
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;
441 bfad_iocmd_lport_get_stats(struct bfad_s *bfad, void *cmd)
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;
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;
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;
465 bfad_iocmd_lport_reset_stats(struct bfad_s *bfad, void *cmd)
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;
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;
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);
492 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
493 iocmd->status = BFA_STATUS_OK;
494 out:
495 return 0;
499 bfad_iocmd_lport_get_iostats(struct bfad_s *bfad, void *cmd)
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;
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;
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;
524 bfad_iocmd_lport_get_rports(struct bfad_s *bfad, void *cmd,
525 unsigned int payload_len)
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;
533 if (iocmd->nrports == 0)
534 return -EINVAL;
536 if (bfad_chk_iocmd_sz(payload_len,
537 sizeof(struct bfa_bsg_lport_get_rports_s),
538 sizeof(wwn_t) * iocmd->nrports) != BFA_STATUS_OK) {
539 iocmd->status = BFA_STATUS_VERSION_FAIL;
540 return 0;
543 iocmd_bufptr = (char *)iocmd +
544 sizeof(struct bfa_bsg_lport_get_rports_s);
545 spin_lock_irqsave(&bfad->bfad_lock, flags);
546 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
547 iocmd->vf_id, iocmd->pwwn);
548 if (fcs_port == NULL) {
549 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
550 bfa_trc(bfad, 0);
551 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
552 goto out;
555 bfa_fcs_lport_get_rports(fcs_port, (wwn_t *)iocmd_bufptr,
556 &iocmd->nrports);
557 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
558 iocmd->status = BFA_STATUS_OK;
559 out:
560 return 0;
564 bfad_iocmd_rport_get_attr(struct bfad_s *bfad, void *cmd)
566 struct bfa_bsg_rport_attr_s *iocmd = (struct bfa_bsg_rport_attr_s *)cmd;
567 struct bfa_fcs_lport_s *fcs_port;
568 struct bfa_fcs_rport_s *fcs_rport;
569 unsigned long flags;
571 spin_lock_irqsave(&bfad->bfad_lock, flags);
572 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
573 iocmd->vf_id, iocmd->pwwn);
574 if (fcs_port == NULL) {
575 bfa_trc(bfad, 0);
576 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
577 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
578 goto out;
581 fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
582 if (fcs_rport == NULL) {
583 bfa_trc(bfad, 0);
584 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
585 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
586 goto out;
589 bfa_fcs_rport_get_attr(fcs_rport, &iocmd->attr);
590 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
591 iocmd->status = BFA_STATUS_OK;
592 out:
593 return 0;
596 static int
597 bfad_iocmd_rport_get_addr(struct bfad_s *bfad, void *cmd)
599 struct bfa_bsg_rport_scsi_addr_s *iocmd =
600 (struct bfa_bsg_rport_scsi_addr_s *)cmd;
601 struct bfa_fcs_lport_s *fcs_port;
602 struct bfa_fcs_itnim_s *fcs_itnim;
603 struct bfad_itnim_s *drv_itnim;
604 unsigned long flags;
606 spin_lock_irqsave(&bfad->bfad_lock, flags);
607 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
608 iocmd->vf_id, iocmd->pwwn);
609 if (fcs_port == NULL) {
610 bfa_trc(bfad, 0);
611 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
612 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
613 goto out;
616 fcs_itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
617 if (fcs_itnim == NULL) {
618 bfa_trc(bfad, 0);
619 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
620 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
621 goto out;
624 drv_itnim = fcs_itnim->itnim_drv;
626 if (drv_itnim && drv_itnim->im_port)
627 iocmd->host = drv_itnim->im_port->shost->host_no;
628 else {
629 bfa_trc(bfad, 0);
630 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
631 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
632 goto out;
635 iocmd->target = drv_itnim->scsi_tgt_id;
636 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
638 iocmd->bus = 0;
639 iocmd->lun = 0;
640 iocmd->status = BFA_STATUS_OK;
641 out:
642 return 0;
646 bfad_iocmd_rport_get_stats(struct bfad_s *bfad, void *cmd)
648 struct bfa_bsg_rport_stats_s *iocmd =
649 (struct bfa_bsg_rport_stats_s *)cmd;
650 struct bfa_fcs_lport_s *fcs_port;
651 struct bfa_fcs_rport_s *fcs_rport;
652 unsigned long flags;
654 spin_lock_irqsave(&bfad->bfad_lock, flags);
655 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
656 iocmd->vf_id, iocmd->pwwn);
657 if (fcs_port == NULL) {
658 bfa_trc(bfad, 0);
659 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
660 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
661 goto out;
664 fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
665 if (fcs_rport == NULL) {
666 bfa_trc(bfad, 0);
667 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
668 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
669 goto out;
672 memcpy((void *)&iocmd->stats, (void *)&fcs_rport->stats,
673 sizeof(struct bfa_rport_stats_s));
674 memcpy((void *)&iocmd->stats.hal_stats,
675 (void *)&(bfa_fcs_rport_get_halrport(fcs_rport)->stats),
676 sizeof(struct bfa_rport_hal_stats_s));
678 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
679 iocmd->status = BFA_STATUS_OK;
680 out:
681 return 0;
685 bfad_iocmd_rport_clr_stats(struct bfad_s *bfad, void *cmd)
687 struct bfa_bsg_rport_reset_stats_s *iocmd =
688 (struct bfa_bsg_rport_reset_stats_s *)cmd;
689 struct bfa_fcs_lport_s *fcs_port;
690 struct bfa_fcs_rport_s *fcs_rport;
691 struct bfa_rport_s *rport;
692 unsigned long flags;
694 spin_lock_irqsave(&bfad->bfad_lock, flags);
695 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
696 iocmd->vf_id, iocmd->pwwn);
697 if (fcs_port == NULL) {
698 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
699 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
700 goto out;
703 fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
704 if (fcs_rport == NULL) {
705 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
706 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
707 goto out;
710 memset((char *)&fcs_rport->stats, 0, sizeof(struct bfa_rport_stats_s));
711 rport = bfa_fcs_rport_get_halrport(fcs_rport);
712 memset(&rport->stats, 0, sizeof(rport->stats));
713 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
714 iocmd->status = BFA_STATUS_OK;
715 out:
716 return 0;
720 bfad_iocmd_rport_set_speed(struct bfad_s *bfad, void *cmd)
722 struct bfa_bsg_rport_set_speed_s *iocmd =
723 (struct bfa_bsg_rport_set_speed_s *)cmd;
724 struct bfa_fcs_lport_s *fcs_port;
725 struct bfa_fcs_rport_s *fcs_rport;
726 unsigned long flags;
728 spin_lock_irqsave(&bfad->bfad_lock, flags);
729 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
730 iocmd->vf_id, iocmd->pwwn);
731 if (fcs_port == NULL) {
732 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
733 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
734 goto out;
737 fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
738 if (fcs_rport == NULL) {
739 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
740 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
741 goto out;
744 fcs_rport->rpf.assigned_speed = iocmd->speed;
745 /* Set this speed in f/w only if the RPSC speed is not available */
746 if (fcs_rport->rpf.rpsc_speed == BFA_PORT_SPEED_UNKNOWN)
747 bfa_rport_speed(fcs_rport->bfa_rport, iocmd->speed);
748 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
749 iocmd->status = BFA_STATUS_OK;
750 out:
751 return 0;
755 bfad_iocmd_vport_get_attr(struct bfad_s *bfad, void *cmd)
757 struct bfa_fcs_vport_s *fcs_vport;
758 struct bfa_bsg_vport_attr_s *iocmd = (struct bfa_bsg_vport_attr_s *)cmd;
759 unsigned long flags;
761 spin_lock_irqsave(&bfad->bfad_lock, flags);
762 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs,
763 iocmd->vf_id, iocmd->vpwwn);
764 if (fcs_vport == NULL) {
765 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
766 iocmd->status = BFA_STATUS_UNKNOWN_VWWN;
767 goto out;
770 bfa_fcs_vport_get_attr(fcs_vport, &iocmd->vport_attr);
771 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
772 iocmd->status = BFA_STATUS_OK;
773 out:
774 return 0;
778 bfad_iocmd_vport_get_stats(struct bfad_s *bfad, void *cmd)
780 struct bfa_fcs_vport_s *fcs_vport;
781 struct bfa_bsg_vport_stats_s *iocmd =
782 (struct bfa_bsg_vport_stats_s *)cmd;
783 unsigned long flags;
785 spin_lock_irqsave(&bfad->bfad_lock, flags);
786 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs,
787 iocmd->vf_id, iocmd->vpwwn);
788 if (fcs_vport == NULL) {
789 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
790 iocmd->status = BFA_STATUS_UNKNOWN_VWWN;
791 goto out;
794 memcpy((void *)&iocmd->vport_stats, (void *)&fcs_vport->vport_stats,
795 sizeof(struct bfa_vport_stats_s));
796 memcpy((void *)&iocmd->vport_stats.port_stats,
797 (void *)&fcs_vport->lport.stats,
798 sizeof(struct bfa_lport_stats_s));
799 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
800 iocmd->status = BFA_STATUS_OK;
801 out:
802 return 0;
806 bfad_iocmd_vport_clr_stats(struct bfad_s *bfad, void *cmd)
808 struct bfa_fcs_vport_s *fcs_vport;
809 struct bfa_bsg_reset_stats_s *iocmd =
810 (struct bfa_bsg_reset_stats_s *)cmd;
811 unsigned long flags;
813 spin_lock_irqsave(&bfad->bfad_lock, flags);
814 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs,
815 iocmd->vf_id, iocmd->vpwwn);
816 if (fcs_vport == NULL) {
817 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
818 iocmd->status = BFA_STATUS_UNKNOWN_VWWN;
819 goto out;
822 memset(&fcs_vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s));
823 memset(&fcs_vport->lport.stats, 0, sizeof(struct bfa_lport_stats_s));
824 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
825 iocmd->status = BFA_STATUS_OK;
826 out:
827 return 0;
830 static int
831 bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd,
832 unsigned int payload_len)
834 struct bfa_bsg_fabric_get_lports_s *iocmd =
835 (struct bfa_bsg_fabric_get_lports_s *)cmd;
836 bfa_fcs_vf_t *fcs_vf;
837 uint32_t nports = iocmd->nports;
838 unsigned long flags;
839 void *iocmd_bufptr;
841 if (nports == 0) {
842 iocmd->status = BFA_STATUS_EINVAL;
843 goto out;
846 if (bfad_chk_iocmd_sz(payload_len,
847 sizeof(struct bfa_bsg_fabric_get_lports_s),
848 sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
849 iocmd->status = BFA_STATUS_VERSION_FAIL;
850 goto out;
853 iocmd_bufptr = (char *)iocmd +
854 sizeof(struct bfa_bsg_fabric_get_lports_s);
856 spin_lock_irqsave(&bfad->bfad_lock, flags);
857 fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
858 if (fcs_vf == NULL) {
859 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
860 iocmd->status = BFA_STATUS_UNKNOWN_VFID;
861 goto out;
863 bfa_fcs_vf_get_ports(fcs_vf, (wwn_t *)iocmd_bufptr, &nports);
864 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
866 iocmd->nports = nports;
867 iocmd->status = BFA_STATUS_OK;
868 out:
869 return 0;
873 bfad_iocmd_ratelim(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
875 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
876 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
877 unsigned long flags;
879 spin_lock_irqsave(&bfad->bfad_lock, flags);
881 if (cmd == IOCMD_RATELIM_ENABLE)
882 fcport->cfg.ratelimit = BFA_TRUE;
883 else if (cmd == IOCMD_RATELIM_DISABLE)
884 fcport->cfg.ratelimit = BFA_FALSE;
886 if (fcport->cfg.trl_def_speed == BFA_PORT_SPEED_UNKNOWN)
887 fcport->cfg.trl_def_speed = BFA_PORT_SPEED_1GBPS;
889 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
890 iocmd->status = BFA_STATUS_OK;
892 return 0;
896 bfad_iocmd_ratelim_speed(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
898 struct bfa_bsg_trl_speed_s *iocmd = (struct bfa_bsg_trl_speed_s *)pcmd;
899 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
900 unsigned long flags;
902 spin_lock_irqsave(&bfad->bfad_lock, flags);
904 /* Auto and speeds greater than the supported speed, are invalid */
905 if ((iocmd->speed == BFA_PORT_SPEED_AUTO) ||
906 (iocmd->speed > fcport->speed_sup)) {
907 iocmd->status = BFA_STATUS_UNSUPP_SPEED;
908 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
909 return 0;
912 fcport->cfg.trl_def_speed = iocmd->speed;
913 iocmd->status = BFA_STATUS_OK;
914 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
916 return 0;
920 bfad_iocmd_cfg_fcpim(struct bfad_s *bfad, void *cmd)
922 struct bfa_bsg_fcpim_s *iocmd = (struct bfa_bsg_fcpim_s *)cmd;
923 unsigned long flags;
925 spin_lock_irqsave(&bfad->bfad_lock, flags);
926 bfa_fcpim_path_tov_set(&bfad->bfa, iocmd->param);
927 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
928 iocmd->status = BFA_STATUS_OK;
929 return 0;
933 bfad_iocmd_fcpim_get_modstats(struct bfad_s *bfad, void *cmd)
935 struct bfa_bsg_fcpim_modstats_s *iocmd =
936 (struct bfa_bsg_fcpim_modstats_s *)cmd;
937 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
938 struct list_head *qe, *qen;
939 struct bfa_itnim_s *itnim;
940 unsigned long flags;
942 spin_lock_irqsave(&bfad->bfad_lock, flags);
943 /* accumulate IO stats from itnim */
944 memset((void *)&iocmd->modstats, 0, sizeof(struct bfa_itnim_iostats_s));
945 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
946 itnim = (struct bfa_itnim_s *) qe;
947 bfa_fcpim_add_stats(&iocmd->modstats, &(itnim->stats));
949 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
950 iocmd->status = BFA_STATUS_OK;
951 return 0;
955 bfad_iocmd_fcpim_clr_modstats(struct bfad_s *bfad, void *cmd)
957 struct bfa_bsg_fcpim_modstatsclr_s *iocmd =
958 (struct bfa_bsg_fcpim_modstatsclr_s *)cmd;
959 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
960 struct list_head *qe, *qen;
961 struct bfa_itnim_s *itnim;
962 unsigned long flags;
964 spin_lock_irqsave(&bfad->bfad_lock, flags);
965 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
966 itnim = (struct bfa_itnim_s *) qe;
967 bfa_itnim_clear_stats(itnim);
969 memset(&fcpim->del_itn_stats, 0,
970 sizeof(struct bfa_fcpim_del_itn_stats_s));
971 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
972 iocmd->status = BFA_STATUS_OK;
973 return 0;
977 bfad_iocmd_fcpim_get_del_itn_stats(struct bfad_s *bfad, void *cmd)
979 struct bfa_bsg_fcpim_del_itn_stats_s *iocmd =
980 (struct bfa_bsg_fcpim_del_itn_stats_s *)cmd;
981 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
982 unsigned long flags;
984 spin_lock_irqsave(&bfad->bfad_lock, flags);
985 memcpy((void *)&iocmd->modstats, (void *)&fcpim->del_itn_stats,
986 sizeof(struct bfa_fcpim_del_itn_stats_s));
987 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
989 iocmd->status = BFA_STATUS_OK;
990 return 0;
993 static int
994 bfad_iocmd_itnim_get_attr(struct bfad_s *bfad, void *cmd)
996 struct bfa_bsg_itnim_attr_s *iocmd = (struct bfa_bsg_itnim_attr_s *)cmd;
997 struct bfa_fcs_lport_s *fcs_port;
998 unsigned long flags;
1000 spin_lock_irqsave(&bfad->bfad_lock, flags);
1001 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1002 iocmd->vf_id, iocmd->lpwwn);
1003 if (!fcs_port)
1004 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1005 else
1006 iocmd->status = bfa_fcs_itnim_attr_get(fcs_port,
1007 iocmd->rpwwn, &iocmd->attr);
1008 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1009 return 0;
1012 static int
1013 bfad_iocmd_itnim_get_iostats(struct bfad_s *bfad, void *cmd)
1015 struct bfa_bsg_itnim_iostats_s *iocmd =
1016 (struct bfa_bsg_itnim_iostats_s *)cmd;
1017 struct bfa_fcs_lport_s *fcs_port;
1018 struct bfa_fcs_itnim_s *itnim;
1019 unsigned long flags;
1021 spin_lock_irqsave(&bfad->bfad_lock, flags);
1022 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1023 iocmd->vf_id, iocmd->lpwwn);
1024 if (!fcs_port) {
1025 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1026 bfa_trc(bfad, 0);
1027 } else {
1028 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
1029 if (itnim == NULL)
1030 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
1031 else {
1032 iocmd->status = BFA_STATUS_OK;
1033 memcpy((void *)&iocmd->iostats, (void *)
1034 &(bfa_fcs_itnim_get_halitn(itnim)->stats),
1035 sizeof(struct bfa_itnim_iostats_s));
1038 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1039 return 0;
1042 static int
1043 bfad_iocmd_itnim_reset_stats(struct bfad_s *bfad, void *cmd)
1045 struct bfa_bsg_rport_reset_stats_s *iocmd =
1046 (struct bfa_bsg_rport_reset_stats_s *)cmd;
1047 struct bfa_fcs_lport_s *fcs_port;
1048 struct bfa_fcs_itnim_s *itnim;
1049 unsigned long flags;
1051 spin_lock_irqsave(&bfad->bfad_lock, flags);
1052 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1053 iocmd->vf_id, iocmd->pwwn);
1054 if (!fcs_port)
1055 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1056 else {
1057 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
1058 if (itnim == NULL)
1059 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
1060 else {
1061 iocmd->status = BFA_STATUS_OK;
1062 bfa_fcs_itnim_stats_clear(fcs_port, iocmd->rpwwn);
1063 bfa_itnim_clear_stats(bfa_fcs_itnim_get_halitn(itnim));
1066 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1068 return 0;
1071 static int
1072 bfad_iocmd_itnim_get_itnstats(struct bfad_s *bfad, void *cmd)
1074 struct bfa_bsg_itnim_itnstats_s *iocmd =
1075 (struct bfa_bsg_itnim_itnstats_s *)cmd;
1076 struct bfa_fcs_lport_s *fcs_port;
1077 struct bfa_fcs_itnim_s *itnim;
1078 unsigned long flags;
1080 spin_lock_irqsave(&bfad->bfad_lock, flags);
1081 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1082 iocmd->vf_id, iocmd->lpwwn);
1083 if (!fcs_port) {
1084 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1085 bfa_trc(bfad, 0);
1086 } else {
1087 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
1088 if (itnim == NULL)
1089 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
1090 else {
1091 iocmd->status = BFA_STATUS_OK;
1092 bfa_fcs_itnim_stats_get(fcs_port, iocmd->rpwwn,
1093 &iocmd->itnstats);
1096 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1097 return 0;
1101 bfad_iocmd_fcport_enable(struct bfad_s *bfad, void *cmd)
1103 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1104 unsigned long flags;
1106 spin_lock_irqsave(&bfad->bfad_lock, flags);
1107 iocmd->status = bfa_fcport_enable(&bfad->bfa);
1108 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1110 return 0;
1114 bfad_iocmd_fcport_disable(struct bfad_s *bfad, void *cmd)
1116 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1117 unsigned long flags;
1119 spin_lock_irqsave(&bfad->bfad_lock, flags);
1120 iocmd->status = bfa_fcport_disable(&bfad->bfa);
1121 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1123 return 0;
1127 bfad_iocmd_ioc_get_pcifn_cfg(struct bfad_s *bfad, void *cmd)
1129 struct bfa_bsg_pcifn_cfg_s *iocmd = (struct bfa_bsg_pcifn_cfg_s *)cmd;
1130 struct bfad_hal_comp fcomp;
1131 unsigned long flags;
1133 init_completion(&fcomp.comp);
1134 spin_lock_irqsave(&bfad->bfad_lock, flags);
1135 iocmd->status = bfa_ablk_query(&bfad->bfa.modules.ablk,
1136 &iocmd->pcifn_cfg,
1137 bfad_hcb_comp, &fcomp);
1138 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1139 if (iocmd->status != BFA_STATUS_OK)
1140 goto out;
1142 wait_for_completion(&fcomp.comp);
1143 iocmd->status = fcomp.status;
1144 out:
1145 return 0;
1149 bfad_iocmd_pcifn_create(struct bfad_s *bfad, void *cmd)
1151 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
1152 struct bfad_hal_comp fcomp;
1153 unsigned long flags;
1155 init_completion(&fcomp.comp);
1156 spin_lock_irqsave(&bfad->bfad_lock, flags);
1157 iocmd->status = bfa_ablk_pf_create(&bfad->bfa.modules.ablk,
1158 &iocmd->pcifn_id, iocmd->port,
1159 iocmd->pcifn_class, iocmd->bandwidth,
1160 bfad_hcb_comp, &fcomp);
1161 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1162 if (iocmd->status != BFA_STATUS_OK)
1163 goto out;
1165 wait_for_completion(&fcomp.comp);
1166 iocmd->status = fcomp.status;
1167 out:
1168 return 0;
1172 bfad_iocmd_pcifn_delete(struct bfad_s *bfad, void *cmd)
1174 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
1175 struct bfad_hal_comp fcomp;
1176 unsigned long flags;
1178 init_completion(&fcomp.comp);
1179 spin_lock_irqsave(&bfad->bfad_lock, flags);
1180 iocmd->status = bfa_ablk_pf_delete(&bfad->bfa.modules.ablk,
1181 iocmd->pcifn_id,
1182 bfad_hcb_comp, &fcomp);
1183 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1184 if (iocmd->status != BFA_STATUS_OK)
1185 goto out;
1187 wait_for_completion(&fcomp.comp);
1188 iocmd->status = fcomp.status;
1189 out:
1190 return 0;
1194 bfad_iocmd_pcifn_bw(struct bfad_s *bfad, void *cmd)
1196 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
1197 struct bfad_hal_comp fcomp;
1198 unsigned long flags;
1200 init_completion(&fcomp.comp);
1201 spin_lock_irqsave(&bfad->bfad_lock, flags);
1202 iocmd->status = bfa_ablk_pf_update(&bfad->bfa.modules.ablk,
1203 iocmd->pcifn_id, iocmd->bandwidth,
1204 bfad_hcb_comp, &fcomp);
1205 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1206 bfa_trc(bfad, iocmd->status);
1207 if (iocmd->status != BFA_STATUS_OK)
1208 goto out;
1210 wait_for_completion(&fcomp.comp);
1211 iocmd->status = fcomp.status;
1212 bfa_trc(bfad, iocmd->status);
1213 out:
1214 return 0;
1218 bfad_iocmd_adapter_cfg_mode(struct bfad_s *bfad, void *cmd)
1220 struct bfa_bsg_adapter_cfg_mode_s *iocmd =
1221 (struct bfa_bsg_adapter_cfg_mode_s *)cmd;
1222 struct bfad_hal_comp fcomp;
1223 unsigned long flags = 0;
1225 init_completion(&fcomp.comp);
1226 spin_lock_irqsave(&bfad->bfad_lock, flags);
1227 iocmd->status = bfa_ablk_adapter_config(&bfad->bfa.modules.ablk,
1228 iocmd->cfg.mode, iocmd->cfg.max_pf,
1229 iocmd->cfg.max_vf, bfad_hcb_comp, &fcomp);
1230 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1231 if (iocmd->status != BFA_STATUS_OK)
1232 goto out;
1234 wait_for_completion(&fcomp.comp);
1235 iocmd->status = fcomp.status;
1236 out:
1237 return 0;
1241 bfad_iocmd_port_cfg_mode(struct bfad_s *bfad, void *cmd)
1243 struct bfa_bsg_port_cfg_mode_s *iocmd =
1244 (struct bfa_bsg_port_cfg_mode_s *)cmd;
1245 struct bfad_hal_comp fcomp;
1246 unsigned long flags = 0;
1248 init_completion(&fcomp.comp);
1249 spin_lock_irqsave(&bfad->bfad_lock, flags);
1250 iocmd->status = bfa_ablk_port_config(&bfad->bfa.modules.ablk,
1251 iocmd->instance, iocmd->cfg.mode,
1252 iocmd->cfg.max_pf, iocmd->cfg.max_vf,
1253 bfad_hcb_comp, &fcomp);
1254 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1255 if (iocmd->status != BFA_STATUS_OK)
1256 goto out;
1258 wait_for_completion(&fcomp.comp);
1259 iocmd->status = fcomp.status;
1260 out:
1261 return 0;
1265 bfad_iocmd_ablk_optrom(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
1267 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
1268 struct bfad_hal_comp fcomp;
1269 unsigned long flags;
1271 init_completion(&fcomp.comp);
1272 spin_lock_irqsave(&bfad->bfad_lock, flags);
1273 if (cmd == IOCMD_FLASH_ENABLE_OPTROM)
1274 iocmd->status = bfa_ablk_optrom_en(&bfad->bfa.modules.ablk,
1275 bfad_hcb_comp, &fcomp);
1276 else
1277 iocmd->status = bfa_ablk_optrom_dis(&bfad->bfa.modules.ablk,
1278 bfad_hcb_comp, &fcomp);
1279 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1281 if (iocmd->status != BFA_STATUS_OK)
1282 goto out;
1284 wait_for_completion(&fcomp.comp);
1285 iocmd->status = fcomp.status;
1286 out:
1287 return 0;
1291 bfad_iocmd_faa_enable(struct bfad_s *bfad, void *cmd)
1293 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1294 unsigned long flags;
1295 struct bfad_hal_comp fcomp;
1297 init_completion(&fcomp.comp);
1298 iocmd->status = BFA_STATUS_OK;
1299 spin_lock_irqsave(&bfad->bfad_lock, flags);
1300 iocmd->status = bfa_faa_enable(&bfad->bfa, bfad_hcb_comp, &fcomp);
1301 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1303 if (iocmd->status != BFA_STATUS_OK)
1304 goto out;
1306 wait_for_completion(&fcomp.comp);
1307 iocmd->status = fcomp.status;
1308 out:
1309 return 0;
1313 bfad_iocmd_faa_disable(struct bfad_s *bfad, void *cmd)
1315 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1316 unsigned long flags;
1317 struct bfad_hal_comp fcomp;
1319 init_completion(&fcomp.comp);
1320 iocmd->status = BFA_STATUS_OK;
1321 spin_lock_irqsave(&bfad->bfad_lock, flags);
1322 iocmd->status = bfa_faa_disable(&bfad->bfa, bfad_hcb_comp, &fcomp);
1323 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1325 if (iocmd->status != BFA_STATUS_OK)
1326 goto out;
1328 wait_for_completion(&fcomp.comp);
1329 iocmd->status = fcomp.status;
1330 out:
1331 return 0;
1335 bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd)
1337 struct bfa_bsg_faa_attr_s *iocmd = (struct bfa_bsg_faa_attr_s *)cmd;
1338 struct bfad_hal_comp fcomp;
1339 unsigned long flags;
1341 init_completion(&fcomp.comp);
1342 iocmd->status = BFA_STATUS_OK;
1343 spin_lock_irqsave(&bfad->bfad_lock, flags);
1344 iocmd->status = bfa_faa_query(&bfad->bfa, &iocmd->faa_attr,
1345 bfad_hcb_comp, &fcomp);
1346 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1348 if (iocmd->status != BFA_STATUS_OK)
1349 goto out;
1351 wait_for_completion(&fcomp.comp);
1352 iocmd->status = fcomp.status;
1353 out:
1354 return 0;
1358 bfad_iocmd_cee_attr(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
1360 struct bfa_bsg_cee_attr_s *iocmd =
1361 (struct bfa_bsg_cee_attr_s *)cmd;
1362 void *iocmd_bufptr;
1363 struct bfad_hal_comp cee_comp;
1364 unsigned long flags;
1366 if (bfad_chk_iocmd_sz(payload_len,
1367 sizeof(struct bfa_bsg_cee_attr_s),
1368 sizeof(struct bfa_cee_attr_s)) != BFA_STATUS_OK) {
1369 iocmd->status = BFA_STATUS_VERSION_FAIL;
1370 return 0;
1373 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_attr_s);
1375 cee_comp.status = 0;
1376 init_completion(&cee_comp.comp);
1377 mutex_lock(&bfad_mutex);
1378 spin_lock_irqsave(&bfad->bfad_lock, flags);
1379 iocmd->status = bfa_cee_get_attr(&bfad->bfa.modules.cee, iocmd_bufptr,
1380 bfad_hcb_comp, &cee_comp);
1381 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1382 if (iocmd->status != BFA_STATUS_OK) {
1383 mutex_unlock(&bfad_mutex);
1384 bfa_trc(bfad, 0x5555);
1385 goto out;
1387 wait_for_completion(&cee_comp.comp);
1388 mutex_unlock(&bfad_mutex);
1389 out:
1390 return 0;
1394 bfad_iocmd_cee_get_stats(struct bfad_s *bfad, void *cmd,
1395 unsigned int payload_len)
1397 struct bfa_bsg_cee_stats_s *iocmd =
1398 (struct bfa_bsg_cee_stats_s *)cmd;
1399 void *iocmd_bufptr;
1400 struct bfad_hal_comp cee_comp;
1401 unsigned long flags;
1403 if (bfad_chk_iocmd_sz(payload_len,
1404 sizeof(struct bfa_bsg_cee_stats_s),
1405 sizeof(struct bfa_cee_stats_s)) != BFA_STATUS_OK) {
1406 iocmd->status = BFA_STATUS_VERSION_FAIL;
1407 return 0;
1410 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_stats_s);
1412 cee_comp.status = 0;
1413 init_completion(&cee_comp.comp);
1414 mutex_lock(&bfad_mutex);
1415 spin_lock_irqsave(&bfad->bfad_lock, flags);
1416 iocmd->status = bfa_cee_get_stats(&bfad->bfa.modules.cee, iocmd_bufptr,
1417 bfad_hcb_comp, &cee_comp);
1418 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1419 if (iocmd->status != BFA_STATUS_OK) {
1420 mutex_unlock(&bfad_mutex);
1421 bfa_trc(bfad, 0x5555);
1422 goto out;
1424 wait_for_completion(&cee_comp.comp);
1425 mutex_unlock(&bfad_mutex);
1426 out:
1427 return 0;
1431 bfad_iocmd_cee_reset_stats(struct bfad_s *bfad, void *cmd)
1433 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1434 unsigned long flags;
1436 spin_lock_irqsave(&bfad->bfad_lock, flags);
1437 iocmd->status = bfa_cee_reset_stats(&bfad->bfa.modules.cee, NULL, NULL);
1438 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1439 if (iocmd->status != BFA_STATUS_OK)
1440 bfa_trc(bfad, 0x5555);
1441 return 0;
1445 bfad_iocmd_sfp_media(struct bfad_s *bfad, void *cmd)
1447 struct bfa_bsg_sfp_media_s *iocmd = (struct bfa_bsg_sfp_media_s *)cmd;
1448 struct bfad_hal_comp fcomp;
1449 unsigned long flags;
1451 init_completion(&fcomp.comp);
1452 spin_lock_irqsave(&bfad->bfad_lock, flags);
1453 iocmd->status = bfa_sfp_media(BFA_SFP_MOD(&bfad->bfa), &iocmd->media,
1454 bfad_hcb_comp, &fcomp);
1455 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1456 bfa_trc(bfad, iocmd->status);
1457 if (iocmd->status != BFA_STATUS_SFP_NOT_READY)
1458 goto out;
1460 wait_for_completion(&fcomp.comp);
1461 iocmd->status = fcomp.status;
1462 out:
1463 return 0;
1467 bfad_iocmd_sfp_speed(struct bfad_s *bfad, void *cmd)
1469 struct bfa_bsg_sfp_speed_s *iocmd = (struct bfa_bsg_sfp_speed_s *)cmd;
1470 struct bfad_hal_comp fcomp;
1471 unsigned long flags;
1473 init_completion(&fcomp.comp);
1474 spin_lock_irqsave(&bfad->bfad_lock, flags);
1475 iocmd->status = bfa_sfp_speed(BFA_SFP_MOD(&bfad->bfa), iocmd->speed,
1476 bfad_hcb_comp, &fcomp);
1477 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1478 bfa_trc(bfad, iocmd->status);
1479 if (iocmd->status != BFA_STATUS_SFP_NOT_READY)
1480 goto out;
1481 wait_for_completion(&fcomp.comp);
1482 iocmd->status = fcomp.status;
1483 out:
1484 return 0;
1488 bfad_iocmd_flash_get_attr(struct bfad_s *bfad, void *cmd)
1490 struct bfa_bsg_flash_attr_s *iocmd =
1491 (struct bfa_bsg_flash_attr_s *)cmd;
1492 struct bfad_hal_comp fcomp;
1493 unsigned long flags;
1495 init_completion(&fcomp.comp);
1496 spin_lock_irqsave(&bfad->bfad_lock, flags);
1497 iocmd->status = bfa_flash_get_attr(BFA_FLASH(&bfad->bfa), &iocmd->attr,
1498 bfad_hcb_comp, &fcomp);
1499 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1500 if (iocmd->status != BFA_STATUS_OK)
1501 goto out;
1502 wait_for_completion(&fcomp.comp);
1503 iocmd->status = fcomp.status;
1504 out:
1505 return 0;
1509 bfad_iocmd_flash_erase_part(struct bfad_s *bfad, void *cmd)
1511 struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
1512 struct bfad_hal_comp fcomp;
1513 unsigned long flags;
1515 init_completion(&fcomp.comp);
1516 spin_lock_irqsave(&bfad->bfad_lock, flags);
1517 iocmd->status = bfa_flash_erase_part(BFA_FLASH(&bfad->bfa), iocmd->type,
1518 iocmd->instance, bfad_hcb_comp, &fcomp);
1519 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1520 if (iocmd->status != BFA_STATUS_OK)
1521 goto out;
1522 wait_for_completion(&fcomp.comp);
1523 iocmd->status = fcomp.status;
1524 out:
1525 return 0;
1529 bfad_iocmd_flash_update_part(struct bfad_s *bfad, void *cmd,
1530 unsigned int payload_len)
1532 struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
1533 void *iocmd_bufptr;
1534 struct bfad_hal_comp fcomp;
1535 unsigned long flags;
1537 if (bfad_chk_iocmd_sz(payload_len,
1538 sizeof(struct bfa_bsg_flash_s),
1539 iocmd->bufsz) != BFA_STATUS_OK) {
1540 iocmd->status = BFA_STATUS_VERSION_FAIL;
1541 return 0;
1544 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s);
1546 init_completion(&fcomp.comp);
1547 spin_lock_irqsave(&bfad->bfad_lock, flags);
1548 iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
1549 iocmd->type, iocmd->instance, iocmd_bufptr,
1550 iocmd->bufsz, 0, bfad_hcb_comp, &fcomp);
1551 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1552 if (iocmd->status != BFA_STATUS_OK)
1553 goto out;
1554 wait_for_completion(&fcomp.comp);
1555 iocmd->status = fcomp.status;
1556 out:
1557 return 0;
1561 bfad_iocmd_flash_read_part(struct bfad_s *bfad, void *cmd,
1562 unsigned int payload_len)
1564 struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
1565 struct bfad_hal_comp fcomp;
1566 void *iocmd_bufptr;
1567 unsigned long flags;
1569 if (bfad_chk_iocmd_sz(payload_len,
1570 sizeof(struct bfa_bsg_flash_s),
1571 iocmd->bufsz) != BFA_STATUS_OK) {
1572 iocmd->status = BFA_STATUS_VERSION_FAIL;
1573 return 0;
1576 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s);
1578 init_completion(&fcomp.comp);
1579 spin_lock_irqsave(&bfad->bfad_lock, flags);
1580 iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa), iocmd->type,
1581 iocmd->instance, iocmd_bufptr, iocmd->bufsz, 0,
1582 bfad_hcb_comp, &fcomp);
1583 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1584 if (iocmd->status != BFA_STATUS_OK)
1585 goto out;
1586 wait_for_completion(&fcomp.comp);
1587 iocmd->status = fcomp.status;
1588 out:
1589 return 0;
1593 bfad_iocmd_diag_temp(struct bfad_s *bfad, void *cmd)
1595 struct bfa_bsg_diag_get_temp_s *iocmd =
1596 (struct bfa_bsg_diag_get_temp_s *)cmd;
1597 struct bfad_hal_comp fcomp;
1598 unsigned long flags;
1600 init_completion(&fcomp.comp);
1601 spin_lock_irqsave(&bfad->bfad_lock, flags);
1602 iocmd->status = bfa_diag_tsensor_query(BFA_DIAG_MOD(&bfad->bfa),
1603 &iocmd->result, bfad_hcb_comp, &fcomp);
1604 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1605 bfa_trc(bfad, iocmd->status);
1606 if (iocmd->status != BFA_STATUS_OK)
1607 goto out;
1608 wait_for_completion(&fcomp.comp);
1609 iocmd->status = fcomp.status;
1610 out:
1611 return 0;
1615 bfad_iocmd_diag_memtest(struct bfad_s *bfad, void *cmd)
1617 struct bfa_bsg_diag_memtest_s *iocmd =
1618 (struct bfa_bsg_diag_memtest_s *)cmd;
1619 struct bfad_hal_comp fcomp;
1620 unsigned long flags;
1622 init_completion(&fcomp.comp);
1623 spin_lock_irqsave(&bfad->bfad_lock, flags);
1624 iocmd->status = bfa_diag_memtest(BFA_DIAG_MOD(&bfad->bfa),
1625 &iocmd->memtest, iocmd->pat,
1626 &iocmd->result, bfad_hcb_comp, &fcomp);
1627 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1628 bfa_trc(bfad, iocmd->status);
1629 if (iocmd->status != BFA_STATUS_OK)
1630 goto out;
1631 wait_for_completion(&fcomp.comp);
1632 iocmd->status = fcomp.status;
1633 out:
1634 return 0;
1638 bfad_iocmd_diag_loopback(struct bfad_s *bfad, void *cmd)
1640 struct bfa_bsg_diag_loopback_s *iocmd =
1641 (struct bfa_bsg_diag_loopback_s *)cmd;
1642 struct bfad_hal_comp fcomp;
1643 unsigned long flags;
1645 init_completion(&fcomp.comp);
1646 spin_lock_irqsave(&bfad->bfad_lock, flags);
1647 iocmd->status = bfa_fcdiag_loopback(&bfad->bfa, iocmd->opmode,
1648 iocmd->speed, iocmd->lpcnt, iocmd->pat,
1649 &iocmd->result, bfad_hcb_comp, &fcomp);
1650 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1651 bfa_trc(bfad, iocmd->status);
1652 if (iocmd->status != BFA_STATUS_OK)
1653 goto out;
1654 wait_for_completion(&fcomp.comp);
1655 iocmd->status = fcomp.status;
1656 out:
1657 return 0;
1661 bfad_iocmd_diag_fwping(struct bfad_s *bfad, void *cmd)
1663 struct bfa_bsg_diag_fwping_s *iocmd =
1664 (struct bfa_bsg_diag_fwping_s *)cmd;
1665 struct bfad_hal_comp fcomp;
1666 unsigned long flags;
1668 init_completion(&fcomp.comp);
1669 spin_lock_irqsave(&bfad->bfad_lock, flags);
1670 iocmd->status = bfa_diag_fwping(BFA_DIAG_MOD(&bfad->bfa), iocmd->cnt,
1671 iocmd->pattern, &iocmd->result,
1672 bfad_hcb_comp, &fcomp);
1673 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1674 bfa_trc(bfad, iocmd->status);
1675 if (iocmd->status != BFA_STATUS_OK)
1676 goto out;
1677 bfa_trc(bfad, 0x77771);
1678 wait_for_completion(&fcomp.comp);
1679 iocmd->status = fcomp.status;
1680 out:
1681 return 0;
1685 bfad_iocmd_diag_queuetest(struct bfad_s *bfad, void *cmd)
1687 struct bfa_bsg_diag_qtest_s *iocmd = (struct bfa_bsg_diag_qtest_s *)cmd;
1688 struct bfad_hal_comp fcomp;
1689 unsigned long flags;
1691 init_completion(&fcomp.comp);
1692 spin_lock_irqsave(&bfad->bfad_lock, flags);
1693 iocmd->status = bfa_fcdiag_queuetest(&bfad->bfa, iocmd->force,
1694 iocmd->queue, &iocmd->result,
1695 bfad_hcb_comp, &fcomp);
1696 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1697 if (iocmd->status != BFA_STATUS_OK)
1698 goto out;
1699 wait_for_completion(&fcomp.comp);
1700 iocmd->status = fcomp.status;
1701 out:
1702 return 0;
1706 bfad_iocmd_diag_sfp(struct bfad_s *bfad, void *cmd)
1708 struct bfa_bsg_sfp_show_s *iocmd =
1709 (struct bfa_bsg_sfp_show_s *)cmd;
1710 struct bfad_hal_comp fcomp;
1711 unsigned long flags;
1713 init_completion(&fcomp.comp);
1714 spin_lock_irqsave(&bfad->bfad_lock, flags);
1715 iocmd->status = bfa_sfp_show(BFA_SFP_MOD(&bfad->bfa), &iocmd->sfp,
1716 bfad_hcb_comp, &fcomp);
1717 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1718 bfa_trc(bfad, iocmd->status);
1719 if (iocmd->status != BFA_STATUS_OK)
1720 goto out;
1721 wait_for_completion(&fcomp.comp);
1722 iocmd->status = fcomp.status;
1723 bfa_trc(bfad, iocmd->status);
1724 out:
1725 return 0;
1729 bfad_iocmd_diag_led(struct bfad_s *bfad, void *cmd)
1731 struct bfa_bsg_diag_led_s *iocmd = (struct bfa_bsg_diag_led_s *)cmd;
1732 unsigned long flags;
1734 spin_lock_irqsave(&bfad->bfad_lock, flags);
1735 iocmd->status = bfa_diag_ledtest(BFA_DIAG_MOD(&bfad->bfa),
1736 &iocmd->ledtest);
1737 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1738 return 0;
1742 bfad_iocmd_diag_beacon_lport(struct bfad_s *bfad, void *cmd)
1744 struct bfa_bsg_diag_beacon_s *iocmd =
1745 (struct bfa_bsg_diag_beacon_s *)cmd;
1746 unsigned long flags;
1748 spin_lock_irqsave(&bfad->bfad_lock, flags);
1749 iocmd->status = bfa_diag_beacon_port(BFA_DIAG_MOD(&bfad->bfa),
1750 iocmd->beacon, iocmd->link_e2e_beacon,
1751 iocmd->second);
1752 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1753 return 0;
1757 bfad_iocmd_diag_lb_stat(struct bfad_s *bfad, void *cmd)
1759 struct bfa_bsg_diag_lb_stat_s *iocmd =
1760 (struct bfa_bsg_diag_lb_stat_s *)cmd;
1761 unsigned long flags;
1763 spin_lock_irqsave(&bfad->bfad_lock, flags);
1764 iocmd->status = bfa_fcdiag_lb_is_running(&bfad->bfa);
1765 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1766 bfa_trc(bfad, iocmd->status);
1768 return 0;
1772 bfad_iocmd_phy_get_attr(struct bfad_s *bfad, void *cmd)
1774 struct bfa_bsg_phy_attr_s *iocmd =
1775 (struct bfa_bsg_phy_attr_s *)cmd;
1776 struct bfad_hal_comp fcomp;
1777 unsigned long flags;
1779 init_completion(&fcomp.comp);
1780 spin_lock_irqsave(&bfad->bfad_lock, flags);
1781 iocmd->status = bfa_phy_get_attr(BFA_PHY(&bfad->bfa), iocmd->instance,
1782 &iocmd->attr, bfad_hcb_comp, &fcomp);
1783 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1784 if (iocmd->status != BFA_STATUS_OK)
1785 goto out;
1786 wait_for_completion(&fcomp.comp);
1787 iocmd->status = fcomp.status;
1788 out:
1789 return 0;
1793 bfad_iocmd_phy_get_stats(struct bfad_s *bfad, void *cmd)
1795 struct bfa_bsg_phy_stats_s *iocmd =
1796 (struct bfa_bsg_phy_stats_s *)cmd;
1797 struct bfad_hal_comp fcomp;
1798 unsigned long flags;
1800 init_completion(&fcomp.comp);
1801 spin_lock_irqsave(&bfad->bfad_lock, flags);
1802 iocmd->status = bfa_phy_get_stats(BFA_PHY(&bfad->bfa), iocmd->instance,
1803 &iocmd->stats, bfad_hcb_comp, &fcomp);
1804 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1805 if (iocmd->status != BFA_STATUS_OK)
1806 goto out;
1807 wait_for_completion(&fcomp.comp);
1808 iocmd->status = fcomp.status;
1809 out:
1810 return 0;
1814 bfad_iocmd_phy_read(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
1816 struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd;
1817 struct bfad_hal_comp fcomp;
1818 void *iocmd_bufptr;
1819 unsigned long flags;
1821 if (bfad_chk_iocmd_sz(payload_len,
1822 sizeof(struct bfa_bsg_phy_s),
1823 iocmd->bufsz) != BFA_STATUS_OK) {
1824 iocmd->status = BFA_STATUS_VERSION_FAIL;
1825 return 0;
1828 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s);
1829 init_completion(&fcomp.comp);
1830 spin_lock_irqsave(&bfad->bfad_lock, flags);
1831 iocmd->status = bfa_phy_read(BFA_PHY(&bfad->bfa),
1832 iocmd->instance, iocmd_bufptr, iocmd->bufsz,
1833 0, bfad_hcb_comp, &fcomp);
1834 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1835 if (iocmd->status != BFA_STATUS_OK)
1836 goto out;
1837 wait_for_completion(&fcomp.comp);
1838 iocmd->status = fcomp.status;
1839 if (iocmd->status != BFA_STATUS_OK)
1840 goto out;
1841 out:
1842 return 0;
1846 bfad_iocmd_vhba_query(struct bfad_s *bfad, void *cmd)
1848 struct bfa_bsg_vhba_attr_s *iocmd =
1849 (struct bfa_bsg_vhba_attr_s *)cmd;
1850 struct bfa_vhba_attr_s *attr = &iocmd->attr;
1851 unsigned long flags;
1853 spin_lock_irqsave(&bfad->bfad_lock, flags);
1854 attr->pwwn = bfad->bfa.ioc.attr->pwwn;
1855 attr->nwwn = bfad->bfa.ioc.attr->nwwn;
1856 attr->plog_enabled = (bfa_boolean_t)bfad->bfa.plog->plog_enabled;
1857 attr->io_profile = bfa_fcpim_get_io_profile(&bfad->bfa);
1858 attr->path_tov = bfa_fcpim_path_tov_get(&bfad->bfa);
1859 iocmd->status = BFA_STATUS_OK;
1860 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1861 return 0;
1865 bfad_iocmd_phy_update(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
1867 struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd;
1868 void *iocmd_bufptr;
1869 struct bfad_hal_comp fcomp;
1870 unsigned long flags;
1872 if (bfad_chk_iocmd_sz(payload_len,
1873 sizeof(struct bfa_bsg_phy_s),
1874 iocmd->bufsz) != BFA_STATUS_OK) {
1875 iocmd->status = BFA_STATUS_VERSION_FAIL;
1876 return 0;
1879 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s);
1880 init_completion(&fcomp.comp);
1881 spin_lock_irqsave(&bfad->bfad_lock, flags);
1882 iocmd->status = bfa_phy_update(BFA_PHY(&bfad->bfa),
1883 iocmd->instance, iocmd_bufptr, iocmd->bufsz,
1884 0, bfad_hcb_comp, &fcomp);
1885 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1886 if (iocmd->status != BFA_STATUS_OK)
1887 goto out;
1888 wait_for_completion(&fcomp.comp);
1889 iocmd->status = fcomp.status;
1890 out:
1891 return 0;
1895 bfad_iocmd_porglog_get(struct bfad_s *bfad, void *cmd)
1897 struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd;
1898 void *iocmd_bufptr;
1900 if (iocmd->bufsz < sizeof(struct bfa_plog_s)) {
1901 bfa_trc(bfad, sizeof(struct bfa_plog_s));
1902 iocmd->status = BFA_STATUS_EINVAL;
1903 goto out;
1906 iocmd->status = BFA_STATUS_OK;
1907 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s);
1908 memcpy(iocmd_bufptr, (u8 *) &bfad->plog_buf, sizeof(struct bfa_plog_s));
1909 out:
1910 return 0;
1913 #define BFA_DEBUG_FW_CORE_CHUNK_SZ 0x4000U /* 16K chunks for FW dump */
1915 bfad_iocmd_debug_fw_core(struct bfad_s *bfad, void *cmd,
1916 unsigned int payload_len)
1918 struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd;
1919 void *iocmd_bufptr;
1920 unsigned long flags;
1922 if (bfad_chk_iocmd_sz(payload_len, sizeof(struct bfa_bsg_debug_s),
1923 BFA_DEBUG_FW_CORE_CHUNK_SZ) != BFA_STATUS_OK) {
1924 iocmd->status = BFA_STATUS_VERSION_FAIL;
1925 return 0;
1928 if (iocmd->bufsz < BFA_DEBUG_FW_CORE_CHUNK_SZ ||
1929 !IS_ALIGNED(iocmd->bufsz, sizeof(u16)) ||
1930 !IS_ALIGNED(iocmd->offset, sizeof(u32))) {
1931 bfa_trc(bfad, BFA_DEBUG_FW_CORE_CHUNK_SZ);
1932 iocmd->status = BFA_STATUS_EINVAL;
1933 goto out;
1936 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s);
1937 spin_lock_irqsave(&bfad->bfad_lock, flags);
1938 iocmd->status = bfa_ioc_debug_fwcore(&bfad->bfa.ioc, iocmd_bufptr,
1939 (u32 *)&iocmd->offset, &iocmd->bufsz);
1940 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1941 out:
1942 return 0;
1946 bfad_iocmd_debug_ctl(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
1948 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1949 unsigned long flags;
1951 if (v_cmd == IOCMD_DEBUG_FW_STATE_CLR) {
1952 spin_lock_irqsave(&bfad->bfad_lock, flags);
1953 bfad->bfa.ioc.dbg_fwsave_once = BFA_TRUE;
1954 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1955 } else if (v_cmd == IOCMD_DEBUG_PORTLOG_CLR)
1956 bfad->plog_buf.head = bfad->plog_buf.tail = 0;
1957 else if (v_cmd == IOCMD_DEBUG_START_DTRC)
1958 bfa_trc_init(bfad->trcmod);
1959 else if (v_cmd == IOCMD_DEBUG_STOP_DTRC)
1960 bfa_trc_stop(bfad->trcmod);
1962 iocmd->status = BFA_STATUS_OK;
1963 return 0;
1967 bfad_iocmd_porglog_ctl(struct bfad_s *bfad, void *cmd)
1969 struct bfa_bsg_portlogctl_s *iocmd = (struct bfa_bsg_portlogctl_s *)cmd;
1971 if (iocmd->ctl == BFA_TRUE)
1972 bfad->plog_buf.plog_enabled = 1;
1973 else
1974 bfad->plog_buf.plog_enabled = 0;
1976 iocmd->status = BFA_STATUS_OK;
1977 return 0;
1981 bfad_iocmd_fcpim_cfg_profile(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
1983 struct bfa_bsg_fcpim_profile_s *iocmd =
1984 (struct bfa_bsg_fcpim_profile_s *)cmd;
1985 struct timeval tv;
1986 unsigned long flags;
1988 do_gettimeofday(&tv);
1989 spin_lock_irqsave(&bfad->bfad_lock, flags);
1990 if (v_cmd == IOCMD_FCPIM_PROFILE_ON)
1991 iocmd->status = bfa_fcpim_profile_on(&bfad->bfa, tv.tv_sec);
1992 else if (v_cmd == IOCMD_FCPIM_PROFILE_OFF)
1993 iocmd->status = bfa_fcpim_profile_off(&bfad->bfa);
1994 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1996 return 0;
1999 static int
2000 bfad_iocmd_itnim_get_ioprofile(struct bfad_s *bfad, void *cmd)
2002 struct bfa_bsg_itnim_ioprofile_s *iocmd =
2003 (struct bfa_bsg_itnim_ioprofile_s *)cmd;
2004 struct bfa_fcs_lport_s *fcs_port;
2005 struct bfa_fcs_itnim_s *itnim;
2006 unsigned long flags;
2008 spin_lock_irqsave(&bfad->bfad_lock, flags);
2009 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
2010 iocmd->vf_id, iocmd->lpwwn);
2011 if (!fcs_port)
2012 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
2013 else {
2014 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
2015 if (itnim == NULL)
2016 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
2017 else
2018 iocmd->status = bfa_itnim_get_ioprofile(
2019 bfa_fcs_itnim_get_halitn(itnim),
2020 &iocmd->ioprofile);
2022 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2023 return 0;
2027 bfad_iocmd_fcport_get_stats(struct bfad_s *bfad, void *cmd)
2029 struct bfa_bsg_fcport_stats_s *iocmd =
2030 (struct bfa_bsg_fcport_stats_s *)cmd;
2031 struct bfad_hal_comp fcomp;
2032 unsigned long flags;
2033 struct bfa_cb_pending_q_s cb_qe;
2035 init_completion(&fcomp.comp);
2036 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2037 &fcomp, &iocmd->stats);
2038 spin_lock_irqsave(&bfad->bfad_lock, flags);
2039 iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
2040 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2041 if (iocmd->status != BFA_STATUS_OK) {
2042 bfa_trc(bfad, iocmd->status);
2043 goto out;
2045 wait_for_completion(&fcomp.comp);
2046 iocmd->status = fcomp.status;
2047 out:
2048 return 0;
2052 bfad_iocmd_fcport_reset_stats(struct bfad_s *bfad, void *cmd)
2054 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2055 struct bfad_hal_comp fcomp;
2056 unsigned long flags;
2057 struct bfa_cb_pending_q_s cb_qe;
2059 init_completion(&fcomp.comp);
2060 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, &fcomp, NULL);
2062 spin_lock_irqsave(&bfad->bfad_lock, flags);
2063 iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
2064 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2065 if (iocmd->status != BFA_STATUS_OK) {
2066 bfa_trc(bfad, iocmd->status);
2067 goto out;
2069 wait_for_completion(&fcomp.comp);
2070 iocmd->status = fcomp.status;
2071 out:
2072 return 0;
2076 bfad_iocmd_boot_cfg(struct bfad_s *bfad, void *cmd)
2078 struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
2079 struct bfad_hal_comp fcomp;
2080 unsigned long flags;
2082 init_completion(&fcomp.comp);
2083 spin_lock_irqsave(&bfad->bfad_lock, flags);
2084 iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
2085 BFA_FLASH_PART_BOOT, PCI_FUNC(bfad->pcidev->devfn),
2086 &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
2087 bfad_hcb_comp, &fcomp);
2088 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2089 if (iocmd->status != BFA_STATUS_OK)
2090 goto out;
2091 wait_for_completion(&fcomp.comp);
2092 iocmd->status = fcomp.status;
2093 out:
2094 return 0;
2098 bfad_iocmd_boot_query(struct bfad_s *bfad, void *cmd)
2100 struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
2101 struct bfad_hal_comp fcomp;
2102 unsigned long flags;
2104 init_completion(&fcomp.comp);
2105 spin_lock_irqsave(&bfad->bfad_lock, flags);
2106 iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
2107 BFA_FLASH_PART_BOOT, PCI_FUNC(bfad->pcidev->devfn),
2108 &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
2109 bfad_hcb_comp, &fcomp);
2110 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2111 if (iocmd->status != BFA_STATUS_OK)
2112 goto out;
2113 wait_for_completion(&fcomp.comp);
2114 iocmd->status = fcomp.status;
2115 out:
2116 return 0;
2120 bfad_iocmd_preboot_query(struct bfad_s *bfad, void *cmd)
2122 struct bfa_bsg_preboot_s *iocmd = (struct bfa_bsg_preboot_s *)cmd;
2123 struct bfi_iocfc_cfgrsp_s *cfgrsp = bfad->bfa.iocfc.cfgrsp;
2124 struct bfa_boot_pbc_s *pbcfg = &iocmd->cfg;
2125 unsigned long flags;
2127 spin_lock_irqsave(&bfad->bfad_lock, flags);
2128 pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
2129 pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
2130 pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
2131 memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
2132 iocmd->status = BFA_STATUS_OK;
2133 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2135 return 0;
2139 bfad_iocmd_ethboot_cfg(struct bfad_s *bfad, void *cmd)
2141 struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
2142 struct bfad_hal_comp fcomp;
2143 unsigned long flags;
2145 init_completion(&fcomp.comp);
2146 spin_lock_irqsave(&bfad->bfad_lock, flags);
2147 iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
2148 BFA_FLASH_PART_PXECFG,
2149 bfad->bfa.ioc.port_id, &iocmd->cfg,
2150 sizeof(struct bfa_ethboot_cfg_s), 0,
2151 bfad_hcb_comp, &fcomp);
2152 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2153 if (iocmd->status != BFA_STATUS_OK)
2154 goto out;
2155 wait_for_completion(&fcomp.comp);
2156 iocmd->status = fcomp.status;
2157 out:
2158 return 0;
2162 bfad_iocmd_ethboot_query(struct bfad_s *bfad, void *cmd)
2164 struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
2165 struct bfad_hal_comp fcomp;
2166 unsigned long flags;
2168 init_completion(&fcomp.comp);
2169 spin_lock_irqsave(&bfad->bfad_lock, flags);
2170 iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
2171 BFA_FLASH_PART_PXECFG,
2172 bfad->bfa.ioc.port_id, &iocmd->cfg,
2173 sizeof(struct bfa_ethboot_cfg_s), 0,
2174 bfad_hcb_comp, &fcomp);
2175 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2176 if (iocmd->status != BFA_STATUS_OK)
2177 goto out;
2178 wait_for_completion(&fcomp.comp);
2179 iocmd->status = fcomp.status;
2180 out:
2181 return 0;
2185 bfad_iocmd_cfg_trunk(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
2187 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2188 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2189 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2190 unsigned long flags;
2192 spin_lock_irqsave(&bfad->bfad_lock, flags);
2194 if (v_cmd == IOCMD_TRUNK_ENABLE) {
2195 trunk->attr.state = BFA_TRUNK_OFFLINE;
2196 bfa_fcport_disable(&bfad->bfa);
2197 fcport->cfg.trunked = BFA_TRUE;
2198 } else if (v_cmd == IOCMD_TRUNK_DISABLE) {
2199 trunk->attr.state = BFA_TRUNK_DISABLED;
2200 bfa_fcport_disable(&bfad->bfa);
2201 fcport->cfg.trunked = BFA_FALSE;
2204 if (!bfa_fcport_is_disabled(&bfad->bfa))
2205 bfa_fcport_enable(&bfad->bfa);
2207 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2209 iocmd->status = BFA_STATUS_OK;
2210 return 0;
2214 bfad_iocmd_trunk_get_attr(struct bfad_s *bfad, void *cmd)
2216 struct bfa_bsg_trunk_attr_s *iocmd = (struct bfa_bsg_trunk_attr_s *)cmd;
2217 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2218 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2219 unsigned long flags;
2221 spin_lock_irqsave(&bfad->bfad_lock, flags);
2222 memcpy((void *)&iocmd->attr, (void *)&trunk->attr,
2223 sizeof(struct bfa_trunk_attr_s));
2224 iocmd->attr.port_id = bfa_lps_get_base_pid(&bfad->bfa);
2225 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2227 iocmd->status = BFA_STATUS_OK;
2228 return 0;
2232 bfad_iocmd_qos(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
2234 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2235 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2236 unsigned long flags;
2238 spin_lock_irqsave(&bfad->bfad_lock, flags);
2239 if (bfa_ioc_get_type(&bfad->bfa.ioc) == BFA_IOC_TYPE_FC) {
2240 if (v_cmd == IOCMD_QOS_ENABLE)
2241 fcport->cfg.qos_enabled = BFA_TRUE;
2242 else if (v_cmd == IOCMD_QOS_DISABLE)
2243 fcport->cfg.qos_enabled = BFA_FALSE;
2245 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2247 iocmd->status = BFA_STATUS_OK;
2248 return 0;
2252 bfad_iocmd_qos_get_attr(struct bfad_s *bfad, void *cmd)
2254 struct bfa_bsg_qos_attr_s *iocmd = (struct bfa_bsg_qos_attr_s *)cmd;
2255 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2256 unsigned long flags;
2258 spin_lock_irqsave(&bfad->bfad_lock, flags);
2259 iocmd->attr.state = fcport->qos_attr.state;
2260 iocmd->attr.total_bb_cr = be32_to_cpu(fcport->qos_attr.total_bb_cr);
2261 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2263 iocmd->status = BFA_STATUS_OK;
2264 return 0;
2268 bfad_iocmd_qos_get_vc_attr(struct bfad_s *bfad, void *cmd)
2270 struct bfa_bsg_qos_vc_attr_s *iocmd =
2271 (struct bfa_bsg_qos_vc_attr_s *)cmd;
2272 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2273 struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
2274 unsigned long flags;
2275 u32 i = 0;
2277 spin_lock_irqsave(&bfad->bfad_lock, flags);
2278 iocmd->attr.total_vc_count = be16_to_cpu(bfa_vc_attr->total_vc_count);
2279 iocmd->attr.shared_credit = be16_to_cpu(bfa_vc_attr->shared_credit);
2280 iocmd->attr.elp_opmode_flags =
2281 be32_to_cpu(bfa_vc_attr->elp_opmode_flags);
2283 /* Individual VC info */
2284 while (i < iocmd->attr.total_vc_count) {
2285 iocmd->attr.vc_info[i].vc_credit =
2286 bfa_vc_attr->vc_info[i].vc_credit;
2287 iocmd->attr.vc_info[i].borrow_credit =
2288 bfa_vc_attr->vc_info[i].borrow_credit;
2289 iocmd->attr.vc_info[i].priority =
2290 bfa_vc_attr->vc_info[i].priority;
2291 i++;
2293 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2295 iocmd->status = BFA_STATUS_OK;
2296 return 0;
2300 bfad_iocmd_qos_get_stats(struct bfad_s *bfad, void *cmd)
2302 struct bfa_bsg_fcport_stats_s *iocmd =
2303 (struct bfa_bsg_fcport_stats_s *)cmd;
2304 struct bfad_hal_comp fcomp;
2305 unsigned long flags;
2306 struct bfa_cb_pending_q_s cb_qe;
2308 init_completion(&fcomp.comp);
2309 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2310 &fcomp, &iocmd->stats);
2312 spin_lock_irqsave(&bfad->bfad_lock, flags);
2313 WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
2314 iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
2315 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2316 if (iocmd->status != BFA_STATUS_OK) {
2317 bfa_trc(bfad, iocmd->status);
2318 goto out;
2320 wait_for_completion(&fcomp.comp);
2321 iocmd->status = fcomp.status;
2322 out:
2323 return 0;
2327 bfad_iocmd_qos_reset_stats(struct bfad_s *bfad, void *cmd)
2329 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2330 struct bfad_hal_comp fcomp;
2331 unsigned long flags;
2332 struct bfa_cb_pending_q_s cb_qe;
2334 init_completion(&fcomp.comp);
2335 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2336 &fcomp, NULL);
2338 spin_lock_irqsave(&bfad->bfad_lock, flags);
2339 WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
2340 iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
2341 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2342 if (iocmd->status != BFA_STATUS_OK) {
2343 bfa_trc(bfad, iocmd->status);
2344 goto out;
2346 wait_for_completion(&fcomp.comp);
2347 iocmd->status = fcomp.status;
2348 out:
2349 return 0;
2353 bfad_iocmd_vf_get_stats(struct bfad_s *bfad, void *cmd)
2355 struct bfa_bsg_vf_stats_s *iocmd =
2356 (struct bfa_bsg_vf_stats_s *)cmd;
2357 struct bfa_fcs_fabric_s *fcs_vf;
2358 unsigned long flags;
2360 spin_lock_irqsave(&bfad->bfad_lock, flags);
2361 fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
2362 if (fcs_vf == NULL) {
2363 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2364 iocmd->status = BFA_STATUS_UNKNOWN_VFID;
2365 goto out;
2367 memcpy((void *)&iocmd->stats, (void *)&fcs_vf->stats,
2368 sizeof(struct bfa_vf_stats_s));
2369 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2370 iocmd->status = BFA_STATUS_OK;
2371 out:
2372 return 0;
2376 bfad_iocmd_vf_clr_stats(struct bfad_s *bfad, void *cmd)
2378 struct bfa_bsg_vf_reset_stats_s *iocmd =
2379 (struct bfa_bsg_vf_reset_stats_s *)cmd;
2380 struct bfa_fcs_fabric_s *fcs_vf;
2381 unsigned long flags;
2383 spin_lock_irqsave(&bfad->bfad_lock, flags);
2384 fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
2385 if (fcs_vf == NULL) {
2386 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2387 iocmd->status = BFA_STATUS_UNKNOWN_VFID;
2388 goto out;
2390 memset((void *)&fcs_vf->stats, 0, sizeof(struct bfa_vf_stats_s));
2391 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2392 iocmd->status = BFA_STATUS_OK;
2393 out:
2394 return 0;
2397 /* Function to reset the LUN SCAN mode */
2398 static void
2399 bfad_iocmd_lunmask_reset_lunscan_mode(struct bfad_s *bfad, int lunmask_cfg)
2401 struct bfad_im_port_s *pport_im = bfad->pport.im_port;
2402 struct bfad_vport_s *vport = NULL;
2404 /* Set the scsi device LUN SCAN flags for base port */
2405 bfad_reset_sdev_bflags(pport_im, lunmask_cfg);
2407 /* Set the scsi device LUN SCAN flags for the vports */
2408 list_for_each_entry(vport, &bfad->vport_list, list_entry)
2409 bfad_reset_sdev_bflags(vport->drv_port.im_port, lunmask_cfg);
2413 bfad_iocmd_lunmask(struct bfad_s *bfad, void *pcmd, unsigned int v_cmd)
2415 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
2416 unsigned long flags;
2418 spin_lock_irqsave(&bfad->bfad_lock, flags);
2419 if (v_cmd == IOCMD_FCPIM_LUNMASK_ENABLE) {
2420 iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_TRUE);
2421 /* Set the LUN Scanning mode to be Sequential scan */
2422 if (iocmd->status == BFA_STATUS_OK)
2423 bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_TRUE);
2424 } else if (v_cmd == IOCMD_FCPIM_LUNMASK_DISABLE) {
2425 iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_FALSE);
2426 /* Set the LUN Scanning mode to default REPORT_LUNS scan */
2427 if (iocmd->status == BFA_STATUS_OK)
2428 bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_FALSE);
2429 } else if (v_cmd == IOCMD_FCPIM_LUNMASK_CLEAR)
2430 iocmd->status = bfa_fcpim_lunmask_clear(&bfad->bfa);
2431 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2432 return 0;
2436 bfad_iocmd_fcpim_lunmask_query(struct bfad_s *bfad, void *cmd)
2438 struct bfa_bsg_fcpim_lunmask_query_s *iocmd =
2439 (struct bfa_bsg_fcpim_lunmask_query_s *)cmd;
2440 struct bfa_lunmask_cfg_s *lun_mask = &iocmd->lun_mask;
2441 unsigned long flags;
2443 spin_lock_irqsave(&bfad->bfad_lock, flags);
2444 iocmd->status = bfa_fcpim_lunmask_query(&bfad->bfa, lun_mask);
2445 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2446 return 0;
2450 bfad_iocmd_fcpim_cfg_lunmask(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
2452 struct bfa_bsg_fcpim_lunmask_s *iocmd =
2453 (struct bfa_bsg_fcpim_lunmask_s *)cmd;
2454 unsigned long flags;
2456 spin_lock_irqsave(&bfad->bfad_lock, flags);
2457 if (v_cmd == IOCMD_FCPIM_LUNMASK_ADD)
2458 iocmd->status = bfa_fcpim_lunmask_add(&bfad->bfa, iocmd->vf_id,
2459 &iocmd->pwwn, iocmd->rpwwn, iocmd->lun);
2460 else if (v_cmd == IOCMD_FCPIM_LUNMASK_DELETE)
2461 iocmd->status = bfa_fcpim_lunmask_delete(&bfad->bfa,
2462 iocmd->vf_id, &iocmd->pwwn,
2463 iocmd->rpwwn, iocmd->lun);
2464 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2465 return 0;
2468 static int
2469 bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd,
2470 unsigned int payload_len)
2472 int rc = -EINVAL;
2474 switch (cmd) {
2475 case IOCMD_IOC_ENABLE:
2476 rc = bfad_iocmd_ioc_enable(bfad, iocmd);
2477 break;
2478 case IOCMD_IOC_DISABLE:
2479 rc = bfad_iocmd_ioc_disable(bfad, iocmd);
2480 break;
2481 case IOCMD_IOC_GET_INFO:
2482 rc = bfad_iocmd_ioc_get_info(bfad, iocmd);
2483 break;
2484 case IOCMD_IOC_GET_ATTR:
2485 rc = bfad_iocmd_ioc_get_attr(bfad, iocmd);
2486 break;
2487 case IOCMD_IOC_GET_STATS:
2488 rc = bfad_iocmd_ioc_get_stats(bfad, iocmd);
2489 break;
2490 case IOCMD_IOC_GET_FWSTATS:
2491 rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len);
2492 break;
2493 case IOCMD_IOC_RESET_STATS:
2494 case IOCMD_IOC_RESET_FWSTATS:
2495 rc = bfad_iocmd_ioc_reset_stats(bfad, iocmd, cmd);
2496 break;
2497 case IOCMD_IOC_SET_ADAPTER_NAME:
2498 case IOCMD_IOC_SET_PORT_NAME:
2499 rc = bfad_iocmd_ioc_set_name(bfad, iocmd, cmd);
2500 break;
2501 case IOCMD_IOCFC_GET_ATTR:
2502 rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd);
2503 break;
2504 case IOCMD_IOCFC_SET_INTR:
2505 rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd);
2506 break;
2507 case IOCMD_PORT_ENABLE:
2508 rc = bfad_iocmd_port_enable(bfad, iocmd);
2509 break;
2510 case IOCMD_PORT_DISABLE:
2511 rc = bfad_iocmd_port_disable(bfad, iocmd);
2512 break;
2513 case IOCMD_PORT_GET_ATTR:
2514 rc = bfad_iocmd_port_get_attr(bfad, iocmd);
2515 break;
2516 case IOCMD_PORT_GET_STATS:
2517 rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len);
2518 break;
2519 case IOCMD_PORT_RESET_STATS:
2520 rc = bfad_iocmd_port_reset_stats(bfad, iocmd);
2521 break;
2522 case IOCMD_PORT_CFG_TOPO:
2523 case IOCMD_PORT_CFG_SPEED:
2524 case IOCMD_PORT_CFG_ALPA:
2525 case IOCMD_PORT_CLR_ALPA:
2526 rc = bfad_iocmd_set_port_cfg(bfad, iocmd, cmd);
2527 break;
2528 case IOCMD_PORT_CFG_MAXFRSZ:
2529 rc = bfad_iocmd_port_cfg_maxfrsize(bfad, iocmd);
2530 break;
2531 case IOCMD_PORT_BBSC_ENABLE:
2532 case IOCMD_PORT_BBSC_DISABLE:
2533 rc = bfad_iocmd_port_cfg_bbsc(bfad, iocmd, cmd);
2534 break;
2535 case IOCMD_LPORT_GET_ATTR:
2536 rc = bfad_iocmd_lport_get_attr(bfad, iocmd);
2537 break;
2538 case IOCMD_LPORT_GET_STATS:
2539 rc = bfad_iocmd_lport_get_stats(bfad, iocmd);
2540 break;
2541 case IOCMD_LPORT_RESET_STATS:
2542 rc = bfad_iocmd_lport_reset_stats(bfad, iocmd);
2543 break;
2544 case IOCMD_LPORT_GET_IOSTATS:
2545 rc = bfad_iocmd_lport_get_iostats(bfad, iocmd);
2546 break;
2547 case IOCMD_LPORT_GET_RPORTS:
2548 rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len);
2549 break;
2550 case IOCMD_RPORT_GET_ATTR:
2551 rc = bfad_iocmd_rport_get_attr(bfad, iocmd);
2552 break;
2553 case IOCMD_RPORT_GET_ADDR:
2554 rc = bfad_iocmd_rport_get_addr(bfad, iocmd);
2555 break;
2556 case IOCMD_RPORT_GET_STATS:
2557 rc = bfad_iocmd_rport_get_stats(bfad, iocmd);
2558 break;
2559 case IOCMD_RPORT_RESET_STATS:
2560 rc = bfad_iocmd_rport_clr_stats(bfad, iocmd);
2561 break;
2562 case IOCMD_RPORT_SET_SPEED:
2563 rc = bfad_iocmd_rport_set_speed(bfad, iocmd);
2564 break;
2565 case IOCMD_VPORT_GET_ATTR:
2566 rc = bfad_iocmd_vport_get_attr(bfad, iocmd);
2567 break;
2568 case IOCMD_VPORT_GET_STATS:
2569 rc = bfad_iocmd_vport_get_stats(bfad, iocmd);
2570 break;
2571 case IOCMD_VPORT_RESET_STATS:
2572 rc = bfad_iocmd_vport_clr_stats(bfad, iocmd);
2573 break;
2574 case IOCMD_FABRIC_GET_LPORTS:
2575 rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len);
2576 break;
2577 case IOCMD_RATELIM_ENABLE:
2578 case IOCMD_RATELIM_DISABLE:
2579 rc = bfad_iocmd_ratelim(bfad, cmd, iocmd);
2580 break;
2581 case IOCMD_RATELIM_DEF_SPEED:
2582 rc = bfad_iocmd_ratelim_speed(bfad, cmd, iocmd);
2583 break;
2584 case IOCMD_FCPIM_FAILOVER:
2585 rc = bfad_iocmd_cfg_fcpim(bfad, iocmd);
2586 break;
2587 case IOCMD_FCPIM_MODSTATS:
2588 rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd);
2589 break;
2590 case IOCMD_FCPIM_MODSTATSCLR:
2591 rc = bfad_iocmd_fcpim_clr_modstats(bfad, iocmd);
2592 break;
2593 case IOCMD_FCPIM_DEL_ITN_STATS:
2594 rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd);
2595 break;
2596 case IOCMD_ITNIM_GET_ATTR:
2597 rc = bfad_iocmd_itnim_get_attr(bfad, iocmd);
2598 break;
2599 case IOCMD_ITNIM_GET_IOSTATS:
2600 rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd);
2601 break;
2602 case IOCMD_ITNIM_RESET_STATS:
2603 rc = bfad_iocmd_itnim_reset_stats(bfad, iocmd);
2604 break;
2605 case IOCMD_ITNIM_GET_ITNSTATS:
2606 rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd);
2607 break;
2608 case IOCMD_FCPORT_ENABLE:
2609 rc = bfad_iocmd_fcport_enable(bfad, iocmd);
2610 break;
2611 case IOCMD_FCPORT_DISABLE:
2612 rc = bfad_iocmd_fcport_disable(bfad, iocmd);
2613 break;
2614 case IOCMD_IOC_PCIFN_CFG:
2615 rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd);
2616 break;
2617 case IOCMD_PCIFN_CREATE:
2618 rc = bfad_iocmd_pcifn_create(bfad, iocmd);
2619 break;
2620 case IOCMD_PCIFN_DELETE:
2621 rc = bfad_iocmd_pcifn_delete(bfad, iocmd);
2622 break;
2623 case IOCMD_PCIFN_BW:
2624 rc = bfad_iocmd_pcifn_bw(bfad, iocmd);
2625 break;
2626 case IOCMD_ADAPTER_CFG_MODE:
2627 rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd);
2628 break;
2629 case IOCMD_PORT_CFG_MODE:
2630 rc = bfad_iocmd_port_cfg_mode(bfad, iocmd);
2631 break;
2632 case IOCMD_FLASH_ENABLE_OPTROM:
2633 case IOCMD_FLASH_DISABLE_OPTROM:
2634 rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd);
2635 break;
2636 case IOCMD_FAA_ENABLE:
2637 rc = bfad_iocmd_faa_enable(bfad, iocmd);
2638 break;
2639 case IOCMD_FAA_DISABLE:
2640 rc = bfad_iocmd_faa_disable(bfad, iocmd);
2641 break;
2642 case IOCMD_FAA_QUERY:
2643 rc = bfad_iocmd_faa_query(bfad, iocmd);
2644 break;
2645 case IOCMD_CEE_GET_ATTR:
2646 rc = bfad_iocmd_cee_attr(bfad, iocmd, payload_len);
2647 break;
2648 case IOCMD_CEE_GET_STATS:
2649 rc = bfad_iocmd_cee_get_stats(bfad, iocmd, payload_len);
2650 break;
2651 case IOCMD_CEE_RESET_STATS:
2652 rc = bfad_iocmd_cee_reset_stats(bfad, iocmd);
2653 break;
2654 case IOCMD_SFP_MEDIA:
2655 rc = bfad_iocmd_sfp_media(bfad, iocmd);
2656 break;
2657 case IOCMD_SFP_SPEED:
2658 rc = bfad_iocmd_sfp_speed(bfad, iocmd);
2659 break;
2660 case IOCMD_FLASH_GET_ATTR:
2661 rc = bfad_iocmd_flash_get_attr(bfad, iocmd);
2662 break;
2663 case IOCMD_FLASH_ERASE_PART:
2664 rc = bfad_iocmd_flash_erase_part(bfad, iocmd);
2665 break;
2666 case IOCMD_FLASH_UPDATE_PART:
2667 rc = bfad_iocmd_flash_update_part(bfad, iocmd, payload_len);
2668 break;
2669 case IOCMD_FLASH_READ_PART:
2670 rc = bfad_iocmd_flash_read_part(bfad, iocmd, payload_len);
2671 break;
2672 case IOCMD_DIAG_TEMP:
2673 rc = bfad_iocmd_diag_temp(bfad, iocmd);
2674 break;
2675 case IOCMD_DIAG_MEMTEST:
2676 rc = bfad_iocmd_diag_memtest(bfad, iocmd);
2677 break;
2678 case IOCMD_DIAG_LOOPBACK:
2679 rc = bfad_iocmd_diag_loopback(bfad, iocmd);
2680 break;
2681 case IOCMD_DIAG_FWPING:
2682 rc = bfad_iocmd_diag_fwping(bfad, iocmd);
2683 break;
2684 case IOCMD_DIAG_QUEUETEST:
2685 rc = bfad_iocmd_diag_queuetest(bfad, iocmd);
2686 break;
2687 case IOCMD_DIAG_SFP:
2688 rc = bfad_iocmd_diag_sfp(bfad, iocmd);
2689 break;
2690 case IOCMD_DIAG_LED:
2691 rc = bfad_iocmd_diag_led(bfad, iocmd);
2692 break;
2693 case IOCMD_DIAG_BEACON_LPORT:
2694 rc = bfad_iocmd_diag_beacon_lport(bfad, iocmd);
2695 break;
2696 case IOCMD_DIAG_LB_STAT:
2697 rc = bfad_iocmd_diag_lb_stat(bfad, iocmd);
2698 break;
2699 case IOCMD_PHY_GET_ATTR:
2700 rc = bfad_iocmd_phy_get_attr(bfad, iocmd);
2701 break;
2702 case IOCMD_PHY_GET_STATS:
2703 rc = bfad_iocmd_phy_get_stats(bfad, iocmd);
2704 break;
2705 case IOCMD_PHY_UPDATE_FW:
2706 rc = bfad_iocmd_phy_update(bfad, iocmd, payload_len);
2707 break;
2708 case IOCMD_PHY_READ_FW:
2709 rc = bfad_iocmd_phy_read(bfad, iocmd, payload_len);
2710 break;
2711 case IOCMD_VHBA_QUERY:
2712 rc = bfad_iocmd_vhba_query(bfad, iocmd);
2713 break;
2714 case IOCMD_DEBUG_PORTLOG:
2715 rc = bfad_iocmd_porglog_get(bfad, iocmd);
2716 break;
2717 case IOCMD_DEBUG_FW_CORE:
2718 rc = bfad_iocmd_debug_fw_core(bfad, iocmd, payload_len);
2719 break;
2720 case IOCMD_DEBUG_FW_STATE_CLR:
2721 case IOCMD_DEBUG_PORTLOG_CLR:
2722 case IOCMD_DEBUG_START_DTRC:
2723 case IOCMD_DEBUG_STOP_DTRC:
2724 rc = bfad_iocmd_debug_ctl(bfad, iocmd, cmd);
2725 break;
2726 case IOCMD_DEBUG_PORTLOG_CTL:
2727 rc = bfad_iocmd_porglog_ctl(bfad, iocmd);
2728 break;
2729 case IOCMD_FCPIM_PROFILE_ON:
2730 case IOCMD_FCPIM_PROFILE_OFF:
2731 rc = bfad_iocmd_fcpim_cfg_profile(bfad, iocmd, cmd);
2732 break;
2733 case IOCMD_ITNIM_GET_IOPROFILE:
2734 rc = bfad_iocmd_itnim_get_ioprofile(bfad, iocmd);
2735 break;
2736 case IOCMD_FCPORT_GET_STATS:
2737 rc = bfad_iocmd_fcport_get_stats(bfad, iocmd);
2738 break;
2739 case IOCMD_FCPORT_RESET_STATS:
2740 rc = bfad_iocmd_fcport_reset_stats(bfad, iocmd);
2741 break;
2742 case IOCMD_BOOT_CFG:
2743 rc = bfad_iocmd_boot_cfg(bfad, iocmd);
2744 break;
2745 case IOCMD_BOOT_QUERY:
2746 rc = bfad_iocmd_boot_query(bfad, iocmd);
2747 break;
2748 case IOCMD_PREBOOT_QUERY:
2749 rc = bfad_iocmd_preboot_query(bfad, iocmd);
2750 break;
2751 case IOCMD_ETHBOOT_CFG:
2752 rc = bfad_iocmd_ethboot_cfg(bfad, iocmd);
2753 break;
2754 case IOCMD_ETHBOOT_QUERY:
2755 rc = bfad_iocmd_ethboot_query(bfad, iocmd);
2756 break;
2757 case IOCMD_TRUNK_ENABLE:
2758 case IOCMD_TRUNK_DISABLE:
2759 rc = bfad_iocmd_cfg_trunk(bfad, iocmd, cmd);
2760 break;
2761 case IOCMD_TRUNK_GET_ATTR:
2762 rc = bfad_iocmd_trunk_get_attr(bfad, iocmd);
2763 break;
2764 case IOCMD_QOS_ENABLE:
2765 case IOCMD_QOS_DISABLE:
2766 rc = bfad_iocmd_qos(bfad, iocmd, cmd);
2767 break;
2768 case IOCMD_QOS_GET_ATTR:
2769 rc = bfad_iocmd_qos_get_attr(bfad, iocmd);
2770 break;
2771 case IOCMD_QOS_GET_VC_ATTR:
2772 rc = bfad_iocmd_qos_get_vc_attr(bfad, iocmd);
2773 break;
2774 case IOCMD_QOS_GET_STATS:
2775 rc = bfad_iocmd_qos_get_stats(bfad, iocmd);
2776 break;
2777 case IOCMD_QOS_RESET_STATS:
2778 rc = bfad_iocmd_qos_reset_stats(bfad, iocmd);
2779 break;
2780 case IOCMD_VF_GET_STATS:
2781 rc = bfad_iocmd_vf_get_stats(bfad, iocmd);
2782 break;
2783 case IOCMD_VF_RESET_STATS:
2784 rc = bfad_iocmd_vf_clr_stats(bfad, iocmd);
2785 break;
2786 case IOCMD_FCPIM_LUNMASK_ENABLE:
2787 case IOCMD_FCPIM_LUNMASK_DISABLE:
2788 case IOCMD_FCPIM_LUNMASK_CLEAR:
2789 rc = bfad_iocmd_lunmask(bfad, iocmd, cmd);
2790 break;
2791 case IOCMD_FCPIM_LUNMASK_QUERY:
2792 rc = bfad_iocmd_fcpim_lunmask_query(bfad, iocmd);
2793 break;
2794 case IOCMD_FCPIM_LUNMASK_ADD:
2795 case IOCMD_FCPIM_LUNMASK_DELETE:
2796 rc = bfad_iocmd_fcpim_cfg_lunmask(bfad, iocmd, cmd);
2797 break;
2798 default:
2799 rc = -EINVAL;
2800 break;
2802 return rc;
2805 static int
2806 bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
2808 uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
2809 struct bfad_im_port_s *im_port =
2810 (struct bfad_im_port_s *) job->shost->hostdata[0];
2811 struct bfad_s *bfad = im_port->bfad;
2812 void *payload_kbuf;
2813 int rc = -EINVAL;
2815 /* Allocate a temp buffer to hold the passed in user space command */
2816 payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
2817 if (!payload_kbuf) {
2818 rc = -ENOMEM;
2819 goto out;
2822 /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */
2823 sg_copy_to_buffer(job->request_payload.sg_list,
2824 job->request_payload.sg_cnt, payload_kbuf,
2825 job->request_payload.payload_len);
2827 /* Invoke IOCMD handler - to handle all the vendor command requests */
2828 rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf,
2829 job->request_payload.payload_len);
2830 if (rc != BFA_STATUS_OK)
2831 goto error;
2833 /* Copy the response data to the job->reply_payload sg_list */
2834 sg_copy_from_buffer(job->reply_payload.sg_list,
2835 job->reply_payload.sg_cnt,
2836 payload_kbuf,
2837 job->reply_payload.payload_len);
2839 /* free the command buffer */
2840 kfree(payload_kbuf);
2842 /* Fill the BSG job reply data */
2843 job->reply_len = job->reply_payload.payload_len;
2844 job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
2845 job->reply->result = rc;
2847 job->job_done(job);
2848 return rc;
2849 error:
2850 /* free the command buffer */
2851 kfree(payload_kbuf);
2852 out:
2853 job->reply->result = rc;
2854 job->reply_len = sizeof(uint32_t);
2855 job->reply->reply_payload_rcv_len = 0;
2856 return rc;
2859 /* FC passthru call backs */
2861 bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid)
2863 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2864 struct bfa_sge_s *sge;
2865 u64 addr;
2867 sge = drv_fcxp->req_sge + sgeid;
2868 addr = (u64)(size_t) sge->sg_addr;
2869 return addr;
2873 bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid)
2875 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2876 struct bfa_sge_s *sge;
2878 sge = drv_fcxp->req_sge + sgeid;
2879 return sge->sg_len;
2883 bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid)
2885 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2886 struct bfa_sge_s *sge;
2887 u64 addr;
2889 sge = drv_fcxp->rsp_sge + sgeid;
2890 addr = (u64)(size_t) sge->sg_addr;
2891 return addr;
2895 bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid)
2897 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2898 struct bfa_sge_s *sge;
2900 sge = drv_fcxp->rsp_sge + sgeid;
2901 return sge->sg_len;
2904 void
2905 bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
2906 bfa_status_t req_status, u32 rsp_len, u32 resid_len,
2907 struct fchs_s *rsp_fchs)
2909 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2911 drv_fcxp->req_status = req_status;
2912 drv_fcxp->rsp_len = rsp_len;
2914 /* bfa_fcxp will be automatically freed by BFA */
2915 drv_fcxp->bfa_fcxp = NULL;
2916 complete(&drv_fcxp->comp);
2919 struct bfad_buf_info *
2920 bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf,
2921 uint32_t payload_len, uint32_t *num_sgles)
2923 struct bfad_buf_info *buf_base, *buf_info;
2924 struct bfa_sge_s *sg_table;
2925 int sge_num = 1;
2927 buf_base = kzalloc((sizeof(struct bfad_buf_info) +
2928 sizeof(struct bfa_sge_s)) * sge_num, GFP_KERNEL);
2929 if (!buf_base)
2930 return NULL;
2932 sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) +
2933 (sizeof(struct bfad_buf_info) * sge_num));
2935 /* Allocate dma coherent memory */
2936 buf_info = buf_base;
2937 buf_info->size = payload_len;
2938 buf_info->virt = dma_alloc_coherent(&bfad->pcidev->dev, buf_info->size,
2939 &buf_info->phys, GFP_KERNEL);
2940 if (!buf_info->virt)
2941 goto out_free_mem;
2943 /* copy the linear bsg buffer to buf_info */
2944 memset(buf_info->virt, 0, buf_info->size);
2945 memcpy(buf_info->virt, payload_kbuf, buf_info->size);
2948 * Setup SG table
2950 sg_table->sg_len = buf_info->size;
2951 sg_table->sg_addr = (void *)(size_t) buf_info->phys;
2953 *num_sgles = sge_num;
2955 return buf_base;
2957 out_free_mem:
2958 kfree(buf_base);
2959 return NULL;
2962 void
2963 bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base,
2964 uint32_t num_sgles)
2966 int i;
2967 struct bfad_buf_info *buf_info = buf_base;
2969 if (buf_base) {
2970 for (i = 0; i < num_sgles; buf_info++, i++) {
2971 if (buf_info->virt != NULL)
2972 dma_free_coherent(&bfad->pcidev->dev,
2973 buf_info->size, buf_info->virt,
2974 buf_info->phys);
2976 kfree(buf_base);
2981 bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp,
2982 bfa_bsg_fcpt_t *bsg_fcpt)
2984 struct bfa_fcxp_s *hal_fcxp;
2985 struct bfad_s *bfad = drv_fcxp->port->bfad;
2986 unsigned long flags;
2987 uint8_t lp_tag;
2989 spin_lock_irqsave(&bfad->bfad_lock, flags);
2991 /* Allocate bfa_fcxp structure */
2992 hal_fcxp = bfa_fcxp_alloc(drv_fcxp, &bfad->bfa,
2993 drv_fcxp->num_req_sgles,
2994 drv_fcxp->num_rsp_sgles,
2995 bfad_fcxp_get_req_sgaddr_cb,
2996 bfad_fcxp_get_req_sglen_cb,
2997 bfad_fcxp_get_rsp_sgaddr_cb,
2998 bfad_fcxp_get_rsp_sglen_cb);
2999 if (!hal_fcxp) {
3000 bfa_trc(bfad, 0);
3001 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3002 return BFA_STATUS_ENOMEM;
3005 drv_fcxp->bfa_fcxp = hal_fcxp;
3007 lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id);
3009 bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag,
3010 bsg_fcpt->cts, bsg_fcpt->cos,
3011 job->request_payload.payload_len,
3012 &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad,
3013 job->reply_payload.payload_len, bsg_fcpt->tsecs);
3015 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3017 return BFA_STATUS_OK;
3021 bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
3023 struct bfa_bsg_data *bsg_data;
3024 struct bfad_im_port_s *im_port =
3025 (struct bfad_im_port_s *) job->shost->hostdata[0];
3026 struct bfad_s *bfad = im_port->bfad;
3027 bfa_bsg_fcpt_t *bsg_fcpt;
3028 struct bfad_fcxp *drv_fcxp;
3029 struct bfa_fcs_lport_s *fcs_port;
3030 struct bfa_fcs_rport_s *fcs_rport;
3031 uint32_t command_type = job->request->msgcode;
3032 unsigned long flags;
3033 struct bfad_buf_info *rsp_buf_info;
3034 void *req_kbuf = NULL, *rsp_kbuf = NULL;
3035 int rc = -EINVAL;
3037 job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */
3038 job->reply->reply_payload_rcv_len = 0;
3040 /* Get the payload passed in from userspace */
3041 bsg_data = (struct bfa_bsg_data *) (((char *)job->request) +
3042 sizeof(struct fc_bsg_request));
3043 if (bsg_data == NULL)
3044 goto out;
3047 * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload
3048 * buffer of size bsg_data->payload_len
3050 bsg_fcpt = (struct bfa_bsg_fcpt_s *)
3051 kzalloc(bsg_data->payload_len, GFP_KERNEL);
3052 if (!bsg_fcpt)
3053 goto out;
3055 if (copy_from_user((uint8_t *)bsg_fcpt, bsg_data->payload,
3056 bsg_data->payload_len)) {
3057 kfree(bsg_fcpt);
3058 goto out;
3061 drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL);
3062 if (drv_fcxp == NULL) {
3063 rc = -ENOMEM;
3064 goto out;
3067 spin_lock_irqsave(&bfad->bfad_lock, flags);
3068 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id,
3069 bsg_fcpt->lpwwn);
3070 if (fcs_port == NULL) {
3071 bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN;
3072 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3073 goto out_free_mem;
3076 /* Check if the port is online before sending FC Passthru cmd */
3077 if (!bfa_fcs_lport_is_online(fcs_port)) {
3078 bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE;
3079 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3080 goto out_free_mem;
3083 drv_fcxp->port = fcs_port->bfad_port;
3085 if (drv_fcxp->port->bfad == 0)
3086 drv_fcxp->port->bfad = bfad;
3088 /* Fetch the bfa_rport - if nexus needed */
3089 if (command_type == FC_BSG_HST_ELS_NOLOGIN ||
3090 command_type == FC_BSG_HST_CT) {
3091 /* BSG HST commands: no nexus needed */
3092 drv_fcxp->bfa_rport = NULL;
3094 } else if (command_type == FC_BSG_RPT_ELS ||
3095 command_type == FC_BSG_RPT_CT) {
3096 /* BSG RPT commands: nexus needed */
3097 fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port,
3098 bsg_fcpt->dpwwn);
3099 if (fcs_rport == NULL) {
3100 bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN;
3101 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3102 goto out_free_mem;
3105 drv_fcxp->bfa_rport = fcs_rport->bfa_rport;
3107 } else { /* Unknown BSG msgcode; return -EINVAL */
3108 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3109 goto out_free_mem;
3112 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3114 /* allocate memory for req / rsp buffers */
3115 req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
3116 if (!req_kbuf) {
3117 printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n",
3118 bfad->pci_name);
3119 rc = -ENOMEM;
3120 goto out_free_mem;
3123 rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL);
3124 if (!rsp_kbuf) {
3125 printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n",
3126 bfad->pci_name);
3127 rc = -ENOMEM;
3128 goto out_free_mem;
3131 /* map req sg - copy the sg_list passed in to the linear buffer */
3132 sg_copy_to_buffer(job->request_payload.sg_list,
3133 job->request_payload.sg_cnt, req_kbuf,
3134 job->request_payload.payload_len);
3136 drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf,
3137 job->request_payload.payload_len,
3138 &drv_fcxp->num_req_sgles);
3139 if (!drv_fcxp->reqbuf_info) {
3140 printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n",
3141 bfad->pci_name);
3142 rc = -ENOMEM;
3143 goto out_free_mem;
3146 drv_fcxp->req_sge = (struct bfa_sge_s *)
3147 (((uint8_t *)drv_fcxp->reqbuf_info) +
3148 (sizeof(struct bfad_buf_info) *
3149 drv_fcxp->num_req_sgles));
3151 /* map rsp sg */
3152 drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf,
3153 job->reply_payload.payload_len,
3154 &drv_fcxp->num_rsp_sgles);
3155 if (!drv_fcxp->rspbuf_info) {
3156 printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n",
3157 bfad->pci_name);
3158 rc = -ENOMEM;
3159 goto out_free_mem;
3162 rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info;
3163 drv_fcxp->rsp_sge = (struct bfa_sge_s *)
3164 (((uint8_t *)drv_fcxp->rspbuf_info) +
3165 (sizeof(struct bfad_buf_info) *
3166 drv_fcxp->num_rsp_sgles));
3168 /* fcxp send */
3169 init_completion(&drv_fcxp->comp);
3170 rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt);
3171 if (rc == BFA_STATUS_OK) {
3172 wait_for_completion(&drv_fcxp->comp);
3173 bsg_fcpt->status = drv_fcxp->req_status;
3174 } else {
3175 bsg_fcpt->status = rc;
3176 goto out_free_mem;
3179 /* fill the job->reply data */
3180 if (drv_fcxp->req_status == BFA_STATUS_OK) {
3181 job->reply_len = drv_fcxp->rsp_len;
3182 job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len;
3183 job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
3184 } else {
3185 job->reply->reply_payload_rcv_len =
3186 sizeof(struct fc_bsg_ctels_reply);
3187 job->reply_len = sizeof(uint32_t);
3188 job->reply->reply_data.ctels_reply.status =
3189 FC_CTELS_STATUS_REJECT;
3192 /* Copy the response data to the reply_payload sg list */
3193 sg_copy_from_buffer(job->reply_payload.sg_list,
3194 job->reply_payload.sg_cnt,
3195 (uint8_t *)rsp_buf_info->virt,
3196 job->reply_payload.payload_len);
3198 out_free_mem:
3199 bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info,
3200 drv_fcxp->num_rsp_sgles);
3201 bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info,
3202 drv_fcxp->num_req_sgles);
3203 kfree(req_kbuf);
3204 kfree(rsp_kbuf);
3206 /* Need a copy to user op */
3207 if (copy_to_user(bsg_data->payload, (void *) bsg_fcpt,
3208 bsg_data->payload_len))
3209 rc = -EIO;
3211 kfree(bsg_fcpt);
3212 kfree(drv_fcxp);
3213 out:
3214 job->reply->result = rc;
3216 if (rc == BFA_STATUS_OK)
3217 job->job_done(job);
3219 return rc;
3223 bfad_im_bsg_request(struct fc_bsg_job *job)
3225 uint32_t rc = BFA_STATUS_OK;
3227 switch (job->request->msgcode) {
3228 case FC_BSG_HST_VENDOR:
3229 /* Process BSG HST Vendor requests */
3230 rc = bfad_im_bsg_vendor_request(job);
3231 break;
3232 case FC_BSG_HST_ELS_NOLOGIN:
3233 case FC_BSG_RPT_ELS:
3234 case FC_BSG_HST_CT:
3235 case FC_BSG_RPT_CT:
3236 /* Process BSG ELS/CT commands */
3237 rc = bfad_im_bsg_els_ct_request(job);
3238 break;
3239 default:
3240 job->reply->result = rc = -EINVAL;
3241 job->reply->reply_payload_rcv_len = 0;
3242 break;
3245 return rc;
3249 bfad_im_bsg_timeout(struct fc_bsg_job *job)
3251 /* Don't complete the BSG job request - return -EAGAIN
3252 * to reset bsg job timeout : for ELS/CT pass thru we
3253 * already have timer to track the request.
3255 return -EAGAIN;