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