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