blob: 69b1ba9e58f6987c8ef51ebcc4bdb99621aa199c [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 Gudipatif2ee7602011-07-20 17:01:34 -0700883bfad_iocmd_ratelim(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
884{
885 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
886 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
887 unsigned long flags;
888
889 spin_lock_irqsave(&bfad->bfad_lock, flags);
890
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700891 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
892 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
893 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
894 else {
895 if (cmd == IOCMD_RATELIM_ENABLE)
896 fcport->cfg.ratelimit = BFA_TRUE;
897 else if (cmd == IOCMD_RATELIM_DISABLE)
898 fcport->cfg.ratelimit = BFA_FALSE;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -0700899
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700900 if (fcport->cfg.trl_def_speed == BFA_PORT_SPEED_UNKNOWN)
901 fcport->cfg.trl_def_speed = BFA_PORT_SPEED_1GBPS;
902
903 iocmd->status = BFA_STATUS_OK;
904 }
Krishna Gudipatif2ee7602011-07-20 17:01:34 -0700905
906 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
Krishna Gudipatif2ee7602011-07-20 17:01:34 -0700907
908 return 0;
909}
910
911int
912bfad_iocmd_ratelim_speed(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
913{
914 struct bfa_bsg_trl_speed_s *iocmd = (struct bfa_bsg_trl_speed_s *)pcmd;
915 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
916 unsigned long flags;
917
918 spin_lock_irqsave(&bfad->bfad_lock, flags);
919
920 /* Auto and speeds greater than the supported speed, are invalid */
921 if ((iocmd->speed == BFA_PORT_SPEED_AUTO) ||
922 (iocmd->speed > fcport->speed_sup)) {
923 iocmd->status = BFA_STATUS_UNSUPP_SPEED;
924 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
925 return 0;
926 }
927
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -0700928 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
929 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
930 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
931 else {
932 fcport->cfg.trl_def_speed = iocmd->speed;
933 iocmd->status = BFA_STATUS_OK;
934 }
Krishna Gudipatif2ee7602011-07-20 17:01:34 -0700935 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
936
937 return 0;
938}
939
940int
941bfad_iocmd_cfg_fcpim(struct bfad_s *bfad, void *cmd)
942{
943 struct bfa_bsg_fcpim_s *iocmd = (struct bfa_bsg_fcpim_s *)cmd;
944 unsigned long flags;
945
946 spin_lock_irqsave(&bfad->bfad_lock, flags);
947 bfa_fcpim_path_tov_set(&bfad->bfa, iocmd->param);
948 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
949 iocmd->status = BFA_STATUS_OK;
950 return 0;
951}
952
953int
Krishna Gudipati60138062011-06-24 20:25:15 -0700954bfad_iocmd_fcpim_get_modstats(struct bfad_s *bfad, void *cmd)
955{
956 struct bfa_bsg_fcpim_modstats_s *iocmd =
957 (struct bfa_bsg_fcpim_modstats_s *)cmd;
958 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
959 struct list_head *qe, *qen;
960 struct bfa_itnim_s *itnim;
961 unsigned long flags;
962
963 spin_lock_irqsave(&bfad->bfad_lock, flags);
964 /* accumulate IO stats from itnim */
965 memset((void *)&iocmd->modstats, 0, sizeof(struct bfa_itnim_iostats_s));
966 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
967 itnim = (struct bfa_itnim_s *) qe;
968 bfa_fcpim_add_stats(&iocmd->modstats, &(itnim->stats));
969 }
970 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
971 iocmd->status = BFA_STATUS_OK;
972 return 0;
973}
974
975int
Krishna Gudipatif2ee7602011-07-20 17:01:34 -0700976bfad_iocmd_fcpim_clr_modstats(struct bfad_s *bfad, void *cmd)
977{
978 struct bfa_bsg_fcpim_modstatsclr_s *iocmd =
979 (struct bfa_bsg_fcpim_modstatsclr_s *)cmd;
980 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
981 struct list_head *qe, *qen;
982 struct bfa_itnim_s *itnim;
983 unsigned long flags;
984
985 spin_lock_irqsave(&bfad->bfad_lock, flags);
986 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
987 itnim = (struct bfa_itnim_s *) qe;
988 bfa_itnim_clear_stats(itnim);
989 }
990 memset(&fcpim->del_itn_stats, 0,
991 sizeof(struct bfa_fcpim_del_itn_stats_s));
992 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
993 iocmd->status = BFA_STATUS_OK;
994 return 0;
995}
996
997int
Krishna Gudipati60138062011-06-24 20:25:15 -0700998bfad_iocmd_fcpim_get_del_itn_stats(struct bfad_s *bfad, void *cmd)
999{
1000 struct bfa_bsg_fcpim_del_itn_stats_s *iocmd =
1001 (struct bfa_bsg_fcpim_del_itn_stats_s *)cmd;
1002 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
1003 unsigned long flags;
1004
1005 spin_lock_irqsave(&bfad->bfad_lock, flags);
1006 memcpy((void *)&iocmd->modstats, (void *)&fcpim->del_itn_stats,
1007 sizeof(struct bfa_fcpim_del_itn_stats_s));
1008 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1009
1010 iocmd->status = BFA_STATUS_OK;
1011 return 0;
1012}
1013
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001014static int
1015bfad_iocmd_itnim_get_attr(struct bfad_s *bfad, void *cmd)
1016{
1017 struct bfa_bsg_itnim_attr_s *iocmd = (struct bfa_bsg_itnim_attr_s *)cmd;
1018 struct bfa_fcs_lport_s *fcs_port;
1019 unsigned long flags;
1020
1021 spin_lock_irqsave(&bfad->bfad_lock, flags);
1022 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1023 iocmd->vf_id, iocmd->lpwwn);
1024 if (!fcs_port)
1025 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1026 else
1027 iocmd->status = bfa_fcs_itnim_attr_get(fcs_port,
1028 iocmd->rpwwn, &iocmd->attr);
1029 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1030 return 0;
1031}
1032
Krishna Gudipati60138062011-06-24 20:25:15 -07001033static int
1034bfad_iocmd_itnim_get_iostats(struct bfad_s *bfad, void *cmd)
1035{
1036 struct bfa_bsg_itnim_iostats_s *iocmd =
1037 (struct bfa_bsg_itnim_iostats_s *)cmd;
1038 struct bfa_fcs_lport_s *fcs_port;
1039 struct bfa_fcs_itnim_s *itnim;
1040 unsigned long flags;
1041
1042 spin_lock_irqsave(&bfad->bfad_lock, flags);
1043 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1044 iocmd->vf_id, iocmd->lpwwn);
1045 if (!fcs_port) {
1046 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1047 bfa_trc(bfad, 0);
1048 } else {
1049 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
1050 if (itnim == NULL)
1051 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
1052 else {
1053 iocmd->status = BFA_STATUS_OK;
Krishna Gudipati61ba4392012-08-22 19:52:58 -07001054 if (bfa_fcs_itnim_get_halitn(itnim))
1055 memcpy((void *)&iocmd->iostats, (void *)
1056 &(bfa_fcs_itnim_get_halitn(itnim)->stats),
1057 sizeof(struct bfa_itnim_iostats_s));
Krishna Gudipati60138062011-06-24 20:25:15 -07001058 }
1059 }
1060 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1061 return 0;
1062}
1063
1064static int
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07001065bfad_iocmd_itnim_reset_stats(struct bfad_s *bfad, void *cmd)
1066{
1067 struct bfa_bsg_rport_reset_stats_s *iocmd =
1068 (struct bfa_bsg_rport_reset_stats_s *)cmd;
1069 struct bfa_fcs_lport_s *fcs_port;
1070 struct bfa_fcs_itnim_s *itnim;
1071 unsigned long flags;
1072
1073 spin_lock_irqsave(&bfad->bfad_lock, flags);
1074 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1075 iocmd->vf_id, iocmd->pwwn);
1076 if (!fcs_port)
1077 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1078 else {
1079 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
1080 if (itnim == NULL)
1081 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
1082 else {
1083 iocmd->status = BFA_STATUS_OK;
1084 bfa_fcs_itnim_stats_clear(fcs_port, iocmd->rpwwn);
1085 bfa_itnim_clear_stats(bfa_fcs_itnim_get_halitn(itnim));
1086 }
1087 }
1088 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1089
1090 return 0;
1091}
1092
1093static int
Krishna Gudipati60138062011-06-24 20:25:15 -07001094bfad_iocmd_itnim_get_itnstats(struct bfad_s *bfad, void *cmd)
1095{
1096 struct bfa_bsg_itnim_itnstats_s *iocmd =
1097 (struct bfa_bsg_itnim_itnstats_s *)cmd;
1098 struct bfa_fcs_lport_s *fcs_port;
1099 struct bfa_fcs_itnim_s *itnim;
1100 unsigned long flags;
1101
1102 spin_lock_irqsave(&bfad->bfad_lock, flags);
1103 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
1104 iocmd->vf_id, iocmd->lpwwn);
1105 if (!fcs_port) {
1106 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
1107 bfa_trc(bfad, 0);
1108 } else {
1109 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
1110 if (itnim == NULL)
1111 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
1112 else {
1113 iocmd->status = BFA_STATUS_OK;
1114 bfa_fcs_itnim_stats_get(fcs_port, iocmd->rpwwn,
1115 &iocmd->itnstats);
1116 }
1117 }
1118 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1119 return 0;
1120}
1121
1122int
1123bfad_iocmd_fcport_enable(struct bfad_s *bfad, void *cmd)
1124{
1125 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1126 unsigned long flags;
1127
1128 spin_lock_irqsave(&bfad->bfad_lock, flags);
1129 iocmd->status = bfa_fcport_enable(&bfad->bfa);
1130 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1131
1132 return 0;
1133}
1134
1135int
1136bfad_iocmd_fcport_disable(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_disable(&bfad->bfa);
1143 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1144
1145 return 0;
1146}
1147
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07001148int
1149bfad_iocmd_ioc_get_pcifn_cfg(struct bfad_s *bfad, void *cmd)
1150{
1151 struct bfa_bsg_pcifn_cfg_s *iocmd = (struct bfa_bsg_pcifn_cfg_s *)cmd;
1152 struct bfad_hal_comp fcomp;
1153 unsigned long flags;
1154
1155 init_completion(&fcomp.comp);
1156 spin_lock_irqsave(&bfad->bfad_lock, flags);
1157 iocmd->status = bfa_ablk_query(&bfad->bfa.modules.ablk,
1158 &iocmd->pcifn_cfg,
1159 bfad_hcb_comp, &fcomp);
1160 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1161 if (iocmd->status != BFA_STATUS_OK)
1162 goto out;
1163
1164 wait_for_completion(&fcomp.comp);
1165 iocmd->status = fcomp.status;
1166out:
1167 return 0;
1168}
1169
1170int
1171bfad_iocmd_pcifn_create(struct bfad_s *bfad, void *cmd)
1172{
1173 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
1174 struct bfad_hal_comp fcomp;
1175 unsigned long flags;
1176
1177 init_completion(&fcomp.comp);
1178 spin_lock_irqsave(&bfad->bfad_lock, flags);
1179 iocmd->status = bfa_ablk_pf_create(&bfad->bfa.modules.ablk,
1180 &iocmd->pcifn_id, iocmd->port,
1181 iocmd->pcifn_class, iocmd->bandwidth,
1182 bfad_hcb_comp, &fcomp);
1183 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1184 if (iocmd->status != BFA_STATUS_OK)
1185 goto out;
1186
1187 wait_for_completion(&fcomp.comp);
1188 iocmd->status = fcomp.status;
1189out:
1190 return 0;
1191}
1192
1193int
1194bfad_iocmd_pcifn_delete(struct bfad_s *bfad, void *cmd)
1195{
1196 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
1197 struct bfad_hal_comp fcomp;
1198 unsigned long flags;
1199
1200 init_completion(&fcomp.comp);
1201 spin_lock_irqsave(&bfad->bfad_lock, flags);
1202 iocmd->status = bfa_ablk_pf_delete(&bfad->bfa.modules.ablk,
1203 iocmd->pcifn_id,
1204 bfad_hcb_comp, &fcomp);
1205 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1206 if (iocmd->status != BFA_STATUS_OK)
1207 goto out;
1208
1209 wait_for_completion(&fcomp.comp);
1210 iocmd->status = fcomp.status;
1211out:
1212 return 0;
1213}
1214
1215int
1216bfad_iocmd_pcifn_bw(struct bfad_s *bfad, void *cmd)
1217{
1218 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
1219 struct bfad_hal_comp fcomp;
1220 unsigned long flags;
1221
1222 init_completion(&fcomp.comp);
1223 spin_lock_irqsave(&bfad->bfad_lock, flags);
1224 iocmd->status = bfa_ablk_pf_update(&bfad->bfa.modules.ablk,
1225 iocmd->pcifn_id, iocmd->bandwidth,
1226 bfad_hcb_comp, &fcomp);
1227 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1228 bfa_trc(bfad, iocmd->status);
1229 if (iocmd->status != BFA_STATUS_OK)
1230 goto out;
1231
1232 wait_for_completion(&fcomp.comp);
1233 iocmd->status = fcomp.status;
1234 bfa_trc(bfad, iocmd->status);
1235out:
1236 return 0;
1237}
1238
1239int
1240bfad_iocmd_adapter_cfg_mode(struct bfad_s *bfad, void *cmd)
1241{
1242 struct bfa_bsg_adapter_cfg_mode_s *iocmd =
1243 (struct bfa_bsg_adapter_cfg_mode_s *)cmd;
1244 struct bfad_hal_comp fcomp;
1245 unsigned long flags = 0;
1246
1247 init_completion(&fcomp.comp);
1248 spin_lock_irqsave(&bfad->bfad_lock, flags);
1249 iocmd->status = bfa_ablk_adapter_config(&bfad->bfa.modules.ablk,
1250 iocmd->cfg.mode, iocmd->cfg.max_pf,
1251 iocmd->cfg.max_vf, bfad_hcb_comp, &fcomp);
1252 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1253 if (iocmd->status != BFA_STATUS_OK)
1254 goto out;
1255
1256 wait_for_completion(&fcomp.comp);
1257 iocmd->status = fcomp.status;
1258out:
1259 return 0;
1260}
1261
1262int
1263bfad_iocmd_port_cfg_mode(struct bfad_s *bfad, void *cmd)
1264{
1265 struct bfa_bsg_port_cfg_mode_s *iocmd =
1266 (struct bfa_bsg_port_cfg_mode_s *)cmd;
1267 struct bfad_hal_comp fcomp;
1268 unsigned long flags = 0;
1269
1270 init_completion(&fcomp.comp);
1271 spin_lock_irqsave(&bfad->bfad_lock, flags);
1272 iocmd->status = bfa_ablk_port_config(&bfad->bfa.modules.ablk,
1273 iocmd->instance, iocmd->cfg.mode,
1274 iocmd->cfg.max_pf, iocmd->cfg.max_vf,
1275 bfad_hcb_comp, &fcomp);
1276 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1277 if (iocmd->status != BFA_STATUS_OK)
1278 goto out;
1279
1280 wait_for_completion(&fcomp.comp);
1281 iocmd->status = fcomp.status;
1282out:
1283 return 0;
1284}
1285
1286int
1287bfad_iocmd_ablk_optrom(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
1288{
1289 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
1290 struct bfad_hal_comp fcomp;
1291 unsigned long flags;
1292
1293 init_completion(&fcomp.comp);
1294 spin_lock_irqsave(&bfad->bfad_lock, flags);
1295 if (cmd == IOCMD_FLASH_ENABLE_OPTROM)
1296 iocmd->status = bfa_ablk_optrom_en(&bfad->bfa.modules.ablk,
1297 bfad_hcb_comp, &fcomp);
1298 else
1299 iocmd->status = bfa_ablk_optrom_dis(&bfad->bfa.modules.ablk,
1300 bfad_hcb_comp, &fcomp);
1301 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1302
1303 if (iocmd->status != BFA_STATUS_OK)
1304 goto out;
1305
1306 wait_for_completion(&fcomp.comp);
1307 iocmd->status = fcomp.status;
1308out:
1309 return 0;
1310}
1311
Krishna Gudipatia7141342011-06-24 20:23:19 -07001312int
Krishna Gudipatia7141342011-06-24 20:23:19 -07001313bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd)
1314{
1315 struct bfa_bsg_faa_attr_s *iocmd = (struct bfa_bsg_faa_attr_s *)cmd;
1316 struct bfad_hal_comp fcomp;
1317 unsigned long flags;
1318
1319 init_completion(&fcomp.comp);
1320 iocmd->status = BFA_STATUS_OK;
1321 spin_lock_irqsave(&bfad->bfad_lock, flags);
1322 iocmd->status = bfa_faa_query(&bfad->bfa, &iocmd->faa_attr,
1323 bfad_hcb_comp, &fcomp);
1324 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1325
1326 if (iocmd->status != BFA_STATUS_OK)
1327 goto out;
1328
1329 wait_for_completion(&fcomp.comp);
1330 iocmd->status = fcomp.status;
1331out:
1332 return 0;
1333}
1334
Krishna Gudipati148d6102011-06-24 20:25:36 -07001335int
1336bfad_iocmd_cee_attr(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
1337{
1338 struct bfa_bsg_cee_attr_s *iocmd =
1339 (struct bfa_bsg_cee_attr_s *)cmd;
1340 void *iocmd_bufptr;
1341 struct bfad_hal_comp cee_comp;
1342 unsigned long flags;
1343
1344 if (bfad_chk_iocmd_sz(payload_len,
1345 sizeof(struct bfa_bsg_cee_attr_s),
1346 sizeof(struct bfa_cee_attr_s)) != BFA_STATUS_OK) {
1347 iocmd->status = BFA_STATUS_VERSION_FAIL;
1348 return 0;
1349 }
1350
1351 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_attr_s);
1352
1353 cee_comp.status = 0;
1354 init_completion(&cee_comp.comp);
1355 mutex_lock(&bfad_mutex);
1356 spin_lock_irqsave(&bfad->bfad_lock, flags);
1357 iocmd->status = bfa_cee_get_attr(&bfad->bfa.modules.cee, iocmd_bufptr,
1358 bfad_hcb_comp, &cee_comp);
1359 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1360 if (iocmd->status != BFA_STATUS_OK) {
1361 mutex_unlock(&bfad_mutex);
1362 bfa_trc(bfad, 0x5555);
1363 goto out;
1364 }
1365 wait_for_completion(&cee_comp.comp);
1366 mutex_unlock(&bfad_mutex);
1367out:
1368 return 0;
1369}
1370
1371int
1372bfad_iocmd_cee_get_stats(struct bfad_s *bfad, void *cmd,
1373 unsigned int payload_len)
1374{
1375 struct bfa_bsg_cee_stats_s *iocmd =
1376 (struct bfa_bsg_cee_stats_s *)cmd;
1377 void *iocmd_bufptr;
1378 struct bfad_hal_comp cee_comp;
1379 unsigned long flags;
1380
1381 if (bfad_chk_iocmd_sz(payload_len,
1382 sizeof(struct bfa_bsg_cee_stats_s),
1383 sizeof(struct bfa_cee_stats_s)) != BFA_STATUS_OK) {
1384 iocmd->status = BFA_STATUS_VERSION_FAIL;
1385 return 0;
1386 }
1387
1388 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_cee_stats_s);
1389
1390 cee_comp.status = 0;
1391 init_completion(&cee_comp.comp);
1392 mutex_lock(&bfad_mutex);
1393 spin_lock_irqsave(&bfad->bfad_lock, flags);
1394 iocmd->status = bfa_cee_get_stats(&bfad->bfa.modules.cee, iocmd_bufptr,
1395 bfad_hcb_comp, &cee_comp);
1396 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1397 if (iocmd->status != BFA_STATUS_OK) {
1398 mutex_unlock(&bfad_mutex);
1399 bfa_trc(bfad, 0x5555);
1400 goto out;
1401 }
1402 wait_for_completion(&cee_comp.comp);
1403 mutex_unlock(&bfad_mutex);
1404out:
1405 return 0;
1406}
1407
1408int
1409bfad_iocmd_cee_reset_stats(struct bfad_s *bfad, void *cmd)
1410{
1411 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1412 unsigned long flags;
1413
1414 spin_lock_irqsave(&bfad->bfad_lock, flags);
1415 iocmd->status = bfa_cee_reset_stats(&bfad->bfa.modules.cee, NULL, NULL);
1416 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1417 if (iocmd->status != BFA_STATUS_OK)
1418 bfa_trc(bfad, 0x5555);
1419 return 0;
1420}
1421
Krishna Gudipati51e569a2011-06-24 20:26:25 -07001422int
1423bfad_iocmd_sfp_media(struct bfad_s *bfad, void *cmd)
1424{
1425 struct bfa_bsg_sfp_media_s *iocmd = (struct bfa_bsg_sfp_media_s *)cmd;
1426 struct bfad_hal_comp fcomp;
1427 unsigned long flags;
1428
1429 init_completion(&fcomp.comp);
1430 spin_lock_irqsave(&bfad->bfad_lock, flags);
1431 iocmd->status = bfa_sfp_media(BFA_SFP_MOD(&bfad->bfa), &iocmd->media,
1432 bfad_hcb_comp, &fcomp);
1433 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1434 bfa_trc(bfad, iocmd->status);
1435 if (iocmd->status != BFA_STATUS_SFP_NOT_READY)
1436 goto out;
1437
1438 wait_for_completion(&fcomp.comp);
1439 iocmd->status = fcomp.status;
1440out:
1441 return 0;
1442}
1443
1444int
1445bfad_iocmd_sfp_speed(struct bfad_s *bfad, void *cmd)
1446{
1447 struct bfa_bsg_sfp_speed_s *iocmd = (struct bfa_bsg_sfp_speed_s *)cmd;
1448 struct bfad_hal_comp fcomp;
1449 unsigned long flags;
1450
1451 init_completion(&fcomp.comp);
1452 spin_lock_irqsave(&bfad->bfad_lock, flags);
1453 iocmd->status = bfa_sfp_speed(BFA_SFP_MOD(&bfad->bfa), iocmd->speed,
1454 bfad_hcb_comp, &fcomp);
1455 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1456 bfa_trc(bfad, iocmd->status);
1457 if (iocmd->status != BFA_STATUS_SFP_NOT_READY)
1458 goto out;
1459 wait_for_completion(&fcomp.comp);
1460 iocmd->status = fcomp.status;
1461out:
1462 return 0;
1463}
1464
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07001465int
1466bfad_iocmd_flash_get_attr(struct bfad_s *bfad, void *cmd)
1467{
1468 struct bfa_bsg_flash_attr_s *iocmd =
1469 (struct bfa_bsg_flash_attr_s *)cmd;
1470 struct bfad_hal_comp fcomp;
1471 unsigned long flags;
1472
1473 init_completion(&fcomp.comp);
1474 spin_lock_irqsave(&bfad->bfad_lock, flags);
1475 iocmd->status = bfa_flash_get_attr(BFA_FLASH(&bfad->bfa), &iocmd->attr,
1476 bfad_hcb_comp, &fcomp);
1477 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1478 if (iocmd->status != BFA_STATUS_OK)
1479 goto out;
1480 wait_for_completion(&fcomp.comp);
1481 iocmd->status = fcomp.status;
1482out:
1483 return 0;
1484}
1485
1486int
1487bfad_iocmd_flash_erase_part(struct bfad_s *bfad, void *cmd)
1488{
1489 struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
1490 struct bfad_hal_comp fcomp;
1491 unsigned long flags;
1492
1493 init_completion(&fcomp.comp);
1494 spin_lock_irqsave(&bfad->bfad_lock, flags);
1495 iocmd->status = bfa_flash_erase_part(BFA_FLASH(&bfad->bfa), iocmd->type,
1496 iocmd->instance, bfad_hcb_comp, &fcomp);
1497 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1498 if (iocmd->status != BFA_STATUS_OK)
1499 goto out;
1500 wait_for_completion(&fcomp.comp);
1501 iocmd->status = fcomp.status;
1502out:
1503 return 0;
1504}
1505
1506int
1507bfad_iocmd_flash_update_part(struct bfad_s *bfad, void *cmd,
1508 unsigned int payload_len)
1509{
1510 struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
1511 void *iocmd_bufptr;
1512 struct bfad_hal_comp fcomp;
1513 unsigned long flags;
1514
1515 if (bfad_chk_iocmd_sz(payload_len,
1516 sizeof(struct bfa_bsg_flash_s),
1517 iocmd->bufsz) != BFA_STATUS_OK) {
1518 iocmd->status = BFA_STATUS_VERSION_FAIL;
1519 return 0;
1520 }
1521
1522 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s);
1523
1524 init_completion(&fcomp.comp);
1525 spin_lock_irqsave(&bfad->bfad_lock, flags);
1526 iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
1527 iocmd->type, iocmd->instance, iocmd_bufptr,
1528 iocmd->bufsz, 0, bfad_hcb_comp, &fcomp);
1529 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1530 if (iocmd->status != BFA_STATUS_OK)
1531 goto out;
1532 wait_for_completion(&fcomp.comp);
1533 iocmd->status = fcomp.status;
1534out:
1535 return 0;
1536}
1537
1538int
1539bfad_iocmd_flash_read_part(struct bfad_s *bfad, void *cmd,
1540 unsigned int payload_len)
1541{
1542 struct bfa_bsg_flash_s *iocmd = (struct bfa_bsg_flash_s *)cmd;
1543 struct bfad_hal_comp fcomp;
1544 void *iocmd_bufptr;
1545 unsigned long flags;
1546
1547 if (bfad_chk_iocmd_sz(payload_len,
1548 sizeof(struct bfa_bsg_flash_s),
1549 iocmd->bufsz) != BFA_STATUS_OK) {
1550 iocmd->status = BFA_STATUS_VERSION_FAIL;
1551 return 0;
1552 }
1553
1554 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_flash_s);
1555
1556 init_completion(&fcomp.comp);
1557 spin_lock_irqsave(&bfad->bfad_lock, flags);
1558 iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa), iocmd->type,
1559 iocmd->instance, iocmd_bufptr, iocmd->bufsz, 0,
1560 bfad_hcb_comp, &fcomp);
1561 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1562 if (iocmd->status != BFA_STATUS_OK)
1563 goto out;
1564 wait_for_completion(&fcomp.comp);
1565 iocmd->status = fcomp.status;
1566out:
1567 return 0;
1568}
1569
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07001570int
1571bfad_iocmd_diag_temp(struct bfad_s *bfad, void *cmd)
1572{
1573 struct bfa_bsg_diag_get_temp_s *iocmd =
1574 (struct bfa_bsg_diag_get_temp_s *)cmd;
1575 struct bfad_hal_comp fcomp;
1576 unsigned long flags;
1577
1578 init_completion(&fcomp.comp);
1579 spin_lock_irqsave(&bfad->bfad_lock, flags);
1580 iocmd->status = bfa_diag_tsensor_query(BFA_DIAG_MOD(&bfad->bfa),
1581 &iocmd->result, bfad_hcb_comp, &fcomp);
1582 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1583 bfa_trc(bfad, iocmd->status);
1584 if (iocmd->status != BFA_STATUS_OK)
1585 goto out;
1586 wait_for_completion(&fcomp.comp);
1587 iocmd->status = fcomp.status;
1588out:
1589 return 0;
1590}
1591
1592int
1593bfad_iocmd_diag_memtest(struct bfad_s *bfad, void *cmd)
1594{
1595 struct bfa_bsg_diag_memtest_s *iocmd =
1596 (struct bfa_bsg_diag_memtest_s *)cmd;
1597 struct bfad_hal_comp fcomp;
1598 unsigned long flags;
1599
1600 init_completion(&fcomp.comp);
1601 spin_lock_irqsave(&bfad->bfad_lock, flags);
1602 iocmd->status = bfa_diag_memtest(BFA_DIAG_MOD(&bfad->bfa),
1603 &iocmd->memtest, iocmd->pat,
1604 &iocmd->result, bfad_hcb_comp, &fcomp);
1605 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1606 bfa_trc(bfad, iocmd->status);
1607 if (iocmd->status != BFA_STATUS_OK)
1608 goto out;
1609 wait_for_completion(&fcomp.comp);
1610 iocmd->status = fcomp.status;
1611out:
1612 return 0;
1613}
1614
1615int
1616bfad_iocmd_diag_loopback(struct bfad_s *bfad, void *cmd)
1617{
1618 struct bfa_bsg_diag_loopback_s *iocmd =
1619 (struct bfa_bsg_diag_loopback_s *)cmd;
1620 struct bfad_hal_comp fcomp;
1621 unsigned long flags;
1622
1623 init_completion(&fcomp.comp);
1624 spin_lock_irqsave(&bfad->bfad_lock, flags);
1625 iocmd->status = bfa_fcdiag_loopback(&bfad->bfa, iocmd->opmode,
1626 iocmd->speed, iocmd->lpcnt, iocmd->pat,
1627 &iocmd->result, bfad_hcb_comp, &fcomp);
1628 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1629 bfa_trc(bfad, iocmd->status);
1630 if (iocmd->status != BFA_STATUS_OK)
1631 goto out;
1632 wait_for_completion(&fcomp.comp);
1633 iocmd->status = fcomp.status;
1634out:
1635 return 0;
1636}
1637
1638int
1639bfad_iocmd_diag_fwping(struct bfad_s *bfad, void *cmd)
1640{
1641 struct bfa_bsg_diag_fwping_s *iocmd =
1642 (struct bfa_bsg_diag_fwping_s *)cmd;
1643 struct bfad_hal_comp fcomp;
1644 unsigned long flags;
1645
1646 init_completion(&fcomp.comp);
1647 spin_lock_irqsave(&bfad->bfad_lock, flags);
1648 iocmd->status = bfa_diag_fwping(BFA_DIAG_MOD(&bfad->bfa), iocmd->cnt,
1649 iocmd->pattern, &iocmd->result,
1650 bfad_hcb_comp, &fcomp);
1651 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1652 bfa_trc(bfad, iocmd->status);
1653 if (iocmd->status != BFA_STATUS_OK)
1654 goto out;
1655 bfa_trc(bfad, 0x77771);
1656 wait_for_completion(&fcomp.comp);
1657 iocmd->status = fcomp.status;
1658out:
1659 return 0;
1660}
1661
1662int
1663bfad_iocmd_diag_queuetest(struct bfad_s *bfad, void *cmd)
1664{
1665 struct bfa_bsg_diag_qtest_s *iocmd = (struct bfa_bsg_diag_qtest_s *)cmd;
1666 struct bfad_hal_comp fcomp;
1667 unsigned long flags;
1668
1669 init_completion(&fcomp.comp);
1670 spin_lock_irqsave(&bfad->bfad_lock, flags);
1671 iocmd->status = bfa_fcdiag_queuetest(&bfad->bfa, iocmd->force,
1672 iocmd->queue, &iocmd->result,
1673 bfad_hcb_comp, &fcomp);
1674 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1675 if (iocmd->status != BFA_STATUS_OK)
1676 goto out;
1677 wait_for_completion(&fcomp.comp);
1678 iocmd->status = fcomp.status;
1679out:
1680 return 0;
1681}
1682
1683int
1684bfad_iocmd_diag_sfp(struct bfad_s *bfad, void *cmd)
1685{
1686 struct bfa_bsg_sfp_show_s *iocmd =
1687 (struct bfa_bsg_sfp_show_s *)cmd;
1688 struct bfad_hal_comp fcomp;
1689 unsigned long flags;
1690
1691 init_completion(&fcomp.comp);
1692 spin_lock_irqsave(&bfad->bfad_lock, flags);
1693 iocmd->status = bfa_sfp_show(BFA_SFP_MOD(&bfad->bfa), &iocmd->sfp,
1694 bfad_hcb_comp, &fcomp);
1695 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1696 bfa_trc(bfad, iocmd->status);
1697 if (iocmd->status != BFA_STATUS_OK)
1698 goto out;
1699 wait_for_completion(&fcomp.comp);
1700 iocmd->status = fcomp.status;
1701 bfa_trc(bfad, iocmd->status);
1702out:
1703 return 0;
1704}
1705
1706int
1707bfad_iocmd_diag_led(struct bfad_s *bfad, void *cmd)
1708{
1709 struct bfa_bsg_diag_led_s *iocmd = (struct bfa_bsg_diag_led_s *)cmd;
1710 unsigned long flags;
1711
1712 spin_lock_irqsave(&bfad->bfad_lock, flags);
1713 iocmd->status = bfa_diag_ledtest(BFA_DIAG_MOD(&bfad->bfa),
1714 &iocmd->ledtest);
1715 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1716 return 0;
1717}
1718
1719int
1720bfad_iocmd_diag_beacon_lport(struct bfad_s *bfad, void *cmd)
1721{
1722 struct bfa_bsg_diag_beacon_s *iocmd =
1723 (struct bfa_bsg_diag_beacon_s *)cmd;
1724 unsigned long flags;
1725
1726 spin_lock_irqsave(&bfad->bfad_lock, flags);
1727 iocmd->status = bfa_diag_beacon_port(BFA_DIAG_MOD(&bfad->bfa),
1728 iocmd->beacon, iocmd->link_e2e_beacon,
1729 iocmd->second);
1730 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1731 return 0;
1732}
1733
1734int
1735bfad_iocmd_diag_lb_stat(struct bfad_s *bfad, void *cmd)
1736{
1737 struct bfa_bsg_diag_lb_stat_s *iocmd =
1738 (struct bfa_bsg_diag_lb_stat_s *)cmd;
1739 unsigned long flags;
1740
1741 spin_lock_irqsave(&bfad->bfad_lock, flags);
1742 iocmd->status = bfa_fcdiag_lb_is_running(&bfad->bfa);
1743 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1744 bfa_trc(bfad, iocmd->status);
1745
1746 return 0;
1747}
1748
Krishna Gudipati3350d982011-06-24 20:28:37 -07001749int
Krishna Gudipatie3535462012-09-21 17:26:07 -07001750bfad_iocmd_diag_cfg_dport(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
1751{
1752 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
1753 unsigned long flags;
1754 struct bfad_hal_comp fcomp;
1755
1756 init_completion(&fcomp.comp);
1757 spin_lock_irqsave(&bfad->bfad_lock, flags);
1758 if (cmd == IOCMD_DIAG_DPORT_ENABLE)
1759 iocmd->status = bfa_dport_enable(&bfad->bfa,
1760 bfad_hcb_comp, &fcomp);
1761 else if (cmd == IOCMD_DIAG_DPORT_DISABLE)
1762 iocmd->status = bfa_dport_disable(&bfad->bfa,
1763 bfad_hcb_comp, &fcomp);
1764 else {
1765 bfa_trc(bfad, 0);
1766 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1767 return -EINVAL;
1768 }
1769 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1770
1771 if (iocmd->status != BFA_STATUS_OK)
1772 bfa_trc(bfad, iocmd->status);
1773 else {
1774 wait_for_completion(&fcomp.comp);
1775 iocmd->status = fcomp.status;
1776 }
1777
1778 return 0;
1779}
1780
1781int
1782bfad_iocmd_diag_dport_get_state(struct bfad_s *bfad, void *pcmd)
1783{
1784 struct bfa_bsg_diag_dport_get_state_s *iocmd =
1785 (struct bfa_bsg_diag_dport_get_state_s *)pcmd;
1786 unsigned long flags;
1787
1788 spin_lock_irqsave(&bfad->bfad_lock, flags);
1789 iocmd->status = bfa_dport_get_state(&bfad->bfa, &iocmd->state);
1790 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1791
1792 return 0;
1793}
1794
1795int
Krishna Gudipati3350d982011-06-24 20:28:37 -07001796bfad_iocmd_phy_get_attr(struct bfad_s *bfad, void *cmd)
1797{
1798 struct bfa_bsg_phy_attr_s *iocmd =
1799 (struct bfa_bsg_phy_attr_s *)cmd;
1800 struct bfad_hal_comp fcomp;
1801 unsigned long flags;
1802
1803 init_completion(&fcomp.comp);
1804 spin_lock_irqsave(&bfad->bfad_lock, flags);
1805 iocmd->status = bfa_phy_get_attr(BFA_PHY(&bfad->bfa), iocmd->instance,
1806 &iocmd->attr, bfad_hcb_comp, &fcomp);
1807 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1808 if (iocmd->status != BFA_STATUS_OK)
1809 goto out;
1810 wait_for_completion(&fcomp.comp);
1811 iocmd->status = fcomp.status;
1812out:
1813 return 0;
1814}
1815
1816int
1817bfad_iocmd_phy_get_stats(struct bfad_s *bfad, void *cmd)
1818{
1819 struct bfa_bsg_phy_stats_s *iocmd =
1820 (struct bfa_bsg_phy_stats_s *)cmd;
1821 struct bfad_hal_comp fcomp;
1822 unsigned long flags;
1823
1824 init_completion(&fcomp.comp);
1825 spin_lock_irqsave(&bfad->bfad_lock, flags);
1826 iocmd->status = bfa_phy_get_stats(BFA_PHY(&bfad->bfa), iocmd->instance,
1827 &iocmd->stats, bfad_hcb_comp, &fcomp);
1828 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1829 if (iocmd->status != BFA_STATUS_OK)
1830 goto out;
1831 wait_for_completion(&fcomp.comp);
1832 iocmd->status = fcomp.status;
1833out:
1834 return 0;
1835}
1836
1837int
1838bfad_iocmd_phy_read(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
1839{
1840 struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd;
1841 struct bfad_hal_comp fcomp;
1842 void *iocmd_bufptr;
1843 unsigned long flags;
1844
1845 if (bfad_chk_iocmd_sz(payload_len,
1846 sizeof(struct bfa_bsg_phy_s),
1847 iocmd->bufsz) != BFA_STATUS_OK) {
1848 iocmd->status = BFA_STATUS_VERSION_FAIL;
1849 return 0;
1850 }
1851
1852 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s);
1853 init_completion(&fcomp.comp);
1854 spin_lock_irqsave(&bfad->bfad_lock, flags);
1855 iocmd->status = bfa_phy_read(BFA_PHY(&bfad->bfa),
1856 iocmd->instance, iocmd_bufptr, iocmd->bufsz,
1857 0, bfad_hcb_comp, &fcomp);
1858 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1859 if (iocmd->status != BFA_STATUS_OK)
1860 goto out;
1861 wait_for_completion(&fcomp.comp);
1862 iocmd->status = fcomp.status;
1863 if (iocmd->status != BFA_STATUS_OK)
1864 goto out;
1865out:
1866 return 0;
1867}
1868
1869int
Krishna Gudipati61e62e22011-06-24 20:29:07 -07001870bfad_iocmd_vhba_query(struct bfad_s *bfad, void *cmd)
1871{
1872 struct bfa_bsg_vhba_attr_s *iocmd =
1873 (struct bfa_bsg_vhba_attr_s *)cmd;
1874 struct bfa_vhba_attr_s *attr = &iocmd->attr;
1875 unsigned long flags;
1876
1877 spin_lock_irqsave(&bfad->bfad_lock, flags);
1878 attr->pwwn = bfad->bfa.ioc.attr->pwwn;
1879 attr->nwwn = bfad->bfa.ioc.attr->nwwn;
1880 attr->plog_enabled = (bfa_boolean_t)bfad->bfa.plog->plog_enabled;
1881 attr->io_profile = bfa_fcpim_get_io_profile(&bfad->bfa);
1882 attr->path_tov = bfa_fcpim_path_tov_get(&bfad->bfa);
1883 iocmd->status = BFA_STATUS_OK;
1884 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1885 return 0;
1886}
1887
1888int
Krishna Gudipati3350d982011-06-24 20:28:37 -07001889bfad_iocmd_phy_update(struct bfad_s *bfad, void *cmd, unsigned int payload_len)
1890{
1891 struct bfa_bsg_phy_s *iocmd = (struct bfa_bsg_phy_s *)cmd;
1892 void *iocmd_bufptr;
1893 struct bfad_hal_comp fcomp;
1894 unsigned long flags;
1895
1896 if (bfad_chk_iocmd_sz(payload_len,
1897 sizeof(struct bfa_bsg_phy_s),
1898 iocmd->bufsz) != BFA_STATUS_OK) {
1899 iocmd->status = BFA_STATUS_VERSION_FAIL;
1900 return 0;
1901 }
1902
1903 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_phy_s);
1904 init_completion(&fcomp.comp);
1905 spin_lock_irqsave(&bfad->bfad_lock, flags);
1906 iocmd->status = bfa_phy_update(BFA_PHY(&bfad->bfa),
1907 iocmd->instance, iocmd_bufptr, iocmd->bufsz,
1908 0, bfad_hcb_comp, &fcomp);
1909 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1910 if (iocmd->status != BFA_STATUS_OK)
1911 goto out;
1912 wait_for_completion(&fcomp.comp);
1913 iocmd->status = fcomp.status;
1914out:
1915 return 0;
1916}
1917
Krishna Gudipati61e62e22011-06-24 20:29:07 -07001918int
1919bfad_iocmd_porglog_get(struct bfad_s *bfad, void *cmd)
1920{
1921 struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd;
1922 void *iocmd_bufptr;
1923
1924 if (iocmd->bufsz < sizeof(struct bfa_plog_s)) {
1925 bfa_trc(bfad, sizeof(struct bfa_plog_s));
1926 iocmd->status = BFA_STATUS_EINVAL;
1927 goto out;
1928 }
1929
1930 iocmd->status = BFA_STATUS_OK;
1931 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s);
1932 memcpy(iocmd_bufptr, (u8 *) &bfad->plog_buf, sizeof(struct bfa_plog_s));
1933out:
1934 return 0;
1935}
1936
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07001937#define BFA_DEBUG_FW_CORE_CHUNK_SZ 0x4000U /* 16K chunks for FW dump */
1938int
1939bfad_iocmd_debug_fw_core(struct bfad_s *bfad, void *cmd,
1940 unsigned int payload_len)
1941{
1942 struct bfa_bsg_debug_s *iocmd = (struct bfa_bsg_debug_s *)cmd;
1943 void *iocmd_bufptr;
1944 unsigned long flags;
Santosh Nayak76c8ae42012-03-06 22:36:59 +05301945 u32 offset;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07001946
1947 if (bfad_chk_iocmd_sz(payload_len, sizeof(struct bfa_bsg_debug_s),
1948 BFA_DEBUG_FW_CORE_CHUNK_SZ) != BFA_STATUS_OK) {
1949 iocmd->status = BFA_STATUS_VERSION_FAIL;
1950 return 0;
1951 }
1952
1953 if (iocmd->bufsz < BFA_DEBUG_FW_CORE_CHUNK_SZ ||
1954 !IS_ALIGNED(iocmd->bufsz, sizeof(u16)) ||
1955 !IS_ALIGNED(iocmd->offset, sizeof(u32))) {
1956 bfa_trc(bfad, BFA_DEBUG_FW_CORE_CHUNK_SZ);
1957 iocmd->status = BFA_STATUS_EINVAL;
1958 goto out;
1959 }
1960
1961 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_debug_s);
1962 spin_lock_irqsave(&bfad->bfad_lock, flags);
Santosh Nayak76c8ae42012-03-06 22:36:59 +05301963 offset = iocmd->offset;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07001964 iocmd->status = bfa_ioc_debug_fwcore(&bfad->bfa.ioc, iocmd_bufptr,
Santosh Nayak76c8ae42012-03-06 22:36:59 +05301965 &offset, &iocmd->bufsz);
1966 iocmd->offset = offset;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07001967 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1968out:
1969 return 0;
1970}
1971
1972int
1973bfad_iocmd_debug_ctl(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
1974{
1975 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
1976 unsigned long flags;
1977
1978 if (v_cmd == IOCMD_DEBUG_FW_STATE_CLR) {
1979 spin_lock_irqsave(&bfad->bfad_lock, flags);
1980 bfad->bfa.ioc.dbg_fwsave_once = BFA_TRUE;
1981 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1982 } else if (v_cmd == IOCMD_DEBUG_PORTLOG_CLR)
1983 bfad->plog_buf.head = bfad->plog_buf.tail = 0;
1984 else if (v_cmd == IOCMD_DEBUG_START_DTRC)
1985 bfa_trc_init(bfad->trcmod);
1986 else if (v_cmd == IOCMD_DEBUG_STOP_DTRC)
1987 bfa_trc_stop(bfad->trcmod);
1988
1989 iocmd->status = BFA_STATUS_OK;
1990 return 0;
1991}
1992
1993int
1994bfad_iocmd_porglog_ctl(struct bfad_s *bfad, void *cmd)
1995{
1996 struct bfa_bsg_portlogctl_s *iocmd = (struct bfa_bsg_portlogctl_s *)cmd;
1997
1998 if (iocmd->ctl == BFA_TRUE)
1999 bfad->plog_buf.plog_enabled = 1;
2000 else
2001 bfad->plog_buf.plog_enabled = 0;
2002
2003 iocmd->status = BFA_STATUS_OK;
2004 return 0;
2005}
2006
Krishna Gudipati42a8e6e2011-07-20 17:01:52 -07002007int
2008bfad_iocmd_fcpim_cfg_profile(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
2009{
2010 struct bfa_bsg_fcpim_profile_s *iocmd =
2011 (struct bfa_bsg_fcpim_profile_s *)cmd;
2012 struct timeval tv;
2013 unsigned long flags;
2014
2015 do_gettimeofday(&tv);
2016 spin_lock_irqsave(&bfad->bfad_lock, flags);
2017 if (v_cmd == IOCMD_FCPIM_PROFILE_ON)
2018 iocmd->status = bfa_fcpim_profile_on(&bfad->bfa, tv.tv_sec);
2019 else if (v_cmd == IOCMD_FCPIM_PROFILE_OFF)
2020 iocmd->status = bfa_fcpim_profile_off(&bfad->bfa);
2021 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2022
2023 return 0;
2024}
2025
2026static int
2027bfad_iocmd_itnim_get_ioprofile(struct bfad_s *bfad, void *cmd)
2028{
2029 struct bfa_bsg_itnim_ioprofile_s *iocmd =
2030 (struct bfa_bsg_itnim_ioprofile_s *)cmd;
2031 struct bfa_fcs_lport_s *fcs_port;
2032 struct bfa_fcs_itnim_s *itnim;
2033 unsigned long flags;
2034
2035 spin_lock_irqsave(&bfad->bfad_lock, flags);
2036 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
2037 iocmd->vf_id, iocmd->lpwwn);
2038 if (!fcs_port)
2039 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
2040 else {
2041 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
2042 if (itnim == NULL)
2043 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
2044 else
2045 iocmd->status = bfa_itnim_get_ioprofile(
2046 bfa_fcs_itnim_get_halitn(itnim),
2047 &iocmd->ioprofile);
2048 }
2049 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2050 return 0;
2051}
2052
Krishna Gudipati37ea0552011-07-20 17:02:11 -07002053int
2054bfad_iocmd_fcport_get_stats(struct bfad_s *bfad, void *cmd)
2055{
2056 struct bfa_bsg_fcport_stats_s *iocmd =
2057 (struct bfa_bsg_fcport_stats_s *)cmd;
2058 struct bfad_hal_comp fcomp;
2059 unsigned long flags;
2060 struct bfa_cb_pending_q_s cb_qe;
2061
2062 init_completion(&fcomp.comp);
2063 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2064 &fcomp, &iocmd->stats);
2065 spin_lock_irqsave(&bfad->bfad_lock, flags);
2066 iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
2067 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2068 if (iocmd->status != BFA_STATUS_OK) {
2069 bfa_trc(bfad, iocmd->status);
2070 goto out;
2071 }
2072 wait_for_completion(&fcomp.comp);
2073 iocmd->status = fcomp.status;
2074out:
2075 return 0;
2076}
2077
2078int
2079bfad_iocmd_fcport_reset_stats(struct bfad_s *bfad, void *cmd)
2080{
2081 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2082 struct bfad_hal_comp fcomp;
2083 unsigned long flags;
2084 struct bfa_cb_pending_q_s cb_qe;
2085
2086 init_completion(&fcomp.comp);
2087 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp, &fcomp, NULL);
2088
2089 spin_lock_irqsave(&bfad->bfad_lock, flags);
2090 iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
2091 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2092 if (iocmd->status != BFA_STATUS_OK) {
2093 bfa_trc(bfad, iocmd->status);
2094 goto out;
2095 }
2096 wait_for_completion(&fcomp.comp);
2097 iocmd->status = fcomp.status;
2098out:
2099 return 0;
2100}
2101
Krishna Gudipatia46bd302011-07-20 17:02:32 -07002102int
2103bfad_iocmd_boot_cfg(struct bfad_s *bfad, void *cmd)
2104{
2105 struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
2106 struct bfad_hal_comp fcomp;
2107 unsigned long flags;
2108
2109 init_completion(&fcomp.comp);
2110 spin_lock_irqsave(&bfad->bfad_lock, flags);
2111 iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
2112 BFA_FLASH_PART_BOOT, PCI_FUNC(bfad->pcidev->devfn),
2113 &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
2114 bfad_hcb_comp, &fcomp);
2115 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2116 if (iocmd->status != BFA_STATUS_OK)
2117 goto out;
2118 wait_for_completion(&fcomp.comp);
2119 iocmd->status = fcomp.status;
2120out:
2121 return 0;
2122}
2123
2124int
2125bfad_iocmd_boot_query(struct bfad_s *bfad, void *cmd)
2126{
2127 struct bfa_bsg_boot_s *iocmd = (struct bfa_bsg_boot_s *)cmd;
2128 struct bfad_hal_comp fcomp;
2129 unsigned long flags;
2130
2131 init_completion(&fcomp.comp);
2132 spin_lock_irqsave(&bfad->bfad_lock, flags);
2133 iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
2134 BFA_FLASH_PART_BOOT, PCI_FUNC(bfad->pcidev->devfn),
2135 &iocmd->cfg, sizeof(struct bfa_boot_cfg_s), 0,
2136 bfad_hcb_comp, &fcomp);
2137 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2138 if (iocmd->status != BFA_STATUS_OK)
2139 goto out;
2140 wait_for_completion(&fcomp.comp);
2141 iocmd->status = fcomp.status;
2142out:
2143 return 0;
2144}
2145
2146int
2147bfad_iocmd_preboot_query(struct bfad_s *bfad, void *cmd)
2148{
2149 struct bfa_bsg_preboot_s *iocmd = (struct bfa_bsg_preboot_s *)cmd;
2150 struct bfi_iocfc_cfgrsp_s *cfgrsp = bfad->bfa.iocfc.cfgrsp;
2151 struct bfa_boot_pbc_s *pbcfg = &iocmd->cfg;
2152 unsigned long flags;
2153
2154 spin_lock_irqsave(&bfad->bfad_lock, flags);
2155 pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
2156 pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
2157 pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
2158 memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
2159 iocmd->status = BFA_STATUS_OK;
2160 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2161
2162 return 0;
2163}
2164
2165int
2166bfad_iocmd_ethboot_cfg(struct bfad_s *bfad, void *cmd)
2167{
2168 struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
2169 struct bfad_hal_comp fcomp;
2170 unsigned long flags;
2171
2172 init_completion(&fcomp.comp);
2173 spin_lock_irqsave(&bfad->bfad_lock, flags);
2174 iocmd->status = bfa_flash_update_part(BFA_FLASH(&bfad->bfa),
2175 BFA_FLASH_PART_PXECFG,
2176 bfad->bfa.ioc.port_id, &iocmd->cfg,
2177 sizeof(struct bfa_ethboot_cfg_s), 0,
2178 bfad_hcb_comp, &fcomp);
2179 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2180 if (iocmd->status != BFA_STATUS_OK)
2181 goto out;
2182 wait_for_completion(&fcomp.comp);
2183 iocmd->status = fcomp.status;
2184out:
2185 return 0;
2186}
2187
2188int
2189bfad_iocmd_ethboot_query(struct bfad_s *bfad, void *cmd)
2190{
2191 struct bfa_bsg_ethboot_s *iocmd = (struct bfa_bsg_ethboot_s *)cmd;
2192 struct bfad_hal_comp fcomp;
2193 unsigned long flags;
2194
2195 init_completion(&fcomp.comp);
2196 spin_lock_irqsave(&bfad->bfad_lock, flags);
2197 iocmd->status = bfa_flash_read_part(BFA_FLASH(&bfad->bfa),
2198 BFA_FLASH_PART_PXECFG,
2199 bfad->bfa.ioc.port_id, &iocmd->cfg,
2200 sizeof(struct bfa_ethboot_cfg_s), 0,
2201 bfad_hcb_comp, &fcomp);
2202 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2203 if (iocmd->status != BFA_STATUS_OK)
2204 goto out;
2205 wait_for_completion(&fcomp.comp);
2206 iocmd->status = fcomp.status;
2207out:
2208 return 0;
2209}
2210
Krishna Gudipati45191232011-07-20 17:02:50 -07002211int
2212bfad_iocmd_cfg_trunk(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
2213{
2214 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2215 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2216 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2217 unsigned long flags;
2218
2219 spin_lock_irqsave(&bfad->bfad_lock, flags);
2220
Krishna Gudipatie3535462012-09-21 17:26:07 -07002221 if (bfa_fcport_is_dport(&bfad->bfa))
2222 return BFA_STATUS_DPORT_ERR;
2223
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002224 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) ||
2225 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
2226 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
2227 else {
2228 if (v_cmd == IOCMD_TRUNK_ENABLE) {
2229 trunk->attr.state = BFA_TRUNK_OFFLINE;
2230 bfa_fcport_disable(&bfad->bfa);
2231 fcport->cfg.trunked = BFA_TRUE;
2232 } else if (v_cmd == IOCMD_TRUNK_DISABLE) {
2233 trunk->attr.state = BFA_TRUNK_DISABLED;
2234 bfa_fcport_disable(&bfad->bfa);
2235 fcport->cfg.trunked = BFA_FALSE;
2236 }
Krishna Gudipati45191232011-07-20 17:02:50 -07002237
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002238 if (!bfa_fcport_is_disabled(&bfad->bfa))
2239 bfa_fcport_enable(&bfad->bfa);
2240
2241 iocmd->status = BFA_STATUS_OK;
2242 }
Krishna Gudipati45191232011-07-20 17:02:50 -07002243
2244 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2245
Krishna Gudipati45191232011-07-20 17:02:50 -07002246 return 0;
2247}
2248
2249int
2250bfad_iocmd_trunk_get_attr(struct bfad_s *bfad, void *cmd)
2251{
2252 struct bfa_bsg_trunk_attr_s *iocmd = (struct bfa_bsg_trunk_attr_s *)cmd;
2253 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2254 struct bfa_fcport_trunk_s *trunk = &fcport->trunk;
2255 unsigned long flags;
2256
2257 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002258 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) ||
2259 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
2260 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
2261 else {
2262 memcpy((void *)&iocmd->attr, (void *)&trunk->attr,
2263 sizeof(struct bfa_trunk_attr_s));
2264 iocmd->attr.port_id = bfa_lps_get_base_pid(&bfad->bfa);
2265 iocmd->status = BFA_STATUS_OK;
2266 }
Krishna Gudipati45191232011-07-20 17:02:50 -07002267 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2268
Krishna Gudipati45191232011-07-20 17:02:50 -07002269 return 0;
2270}
2271
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002272int
2273bfad_iocmd_qos(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
2274{
2275 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2276 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2277 unsigned long flags;
2278
2279 spin_lock_irqsave(&bfad->bfad_lock, flags);
2280 if (bfa_ioc_get_type(&bfad->bfa.ioc) == BFA_IOC_TYPE_FC) {
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002281 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
2282 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
2283 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
2284 else {
2285 if (v_cmd == IOCMD_QOS_ENABLE)
2286 fcport->cfg.qos_enabled = BFA_TRUE;
2287 else if (v_cmd == IOCMD_QOS_DISABLE)
2288 fcport->cfg.qos_enabled = BFA_FALSE;
2289 }
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002290 }
2291 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2292
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002293 return 0;
2294}
2295
2296int
2297bfad_iocmd_qos_get_attr(struct bfad_s *bfad, void *cmd)
2298{
2299 struct bfa_bsg_qos_attr_s *iocmd = (struct bfa_bsg_qos_attr_s *)cmd;
2300 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2301 unsigned long flags;
2302
2303 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002304 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
2305 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
2306 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
2307 else {
2308 iocmd->attr.state = fcport->qos_attr.state;
2309 iocmd->attr.total_bb_cr =
2310 be32_to_cpu(fcport->qos_attr.total_bb_cr);
2311 iocmd->status = BFA_STATUS_OK;
2312 }
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002313 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2314
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002315 return 0;
2316}
2317
2318int
2319bfad_iocmd_qos_get_vc_attr(struct bfad_s *bfad, void *cmd)
2320{
2321 struct bfa_bsg_qos_vc_attr_s *iocmd =
2322 (struct bfa_bsg_qos_vc_attr_s *)cmd;
2323 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
2324 struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
2325 unsigned long flags;
2326 u32 i = 0;
2327
2328 spin_lock_irqsave(&bfad->bfad_lock, flags);
2329 iocmd->attr.total_vc_count = be16_to_cpu(bfa_vc_attr->total_vc_count);
2330 iocmd->attr.shared_credit = be16_to_cpu(bfa_vc_attr->shared_credit);
2331 iocmd->attr.elp_opmode_flags =
2332 be32_to_cpu(bfa_vc_attr->elp_opmode_flags);
2333
2334 /* Individual VC info */
2335 while (i < iocmd->attr.total_vc_count) {
2336 iocmd->attr.vc_info[i].vc_credit =
2337 bfa_vc_attr->vc_info[i].vc_credit;
2338 iocmd->attr.vc_info[i].borrow_credit =
2339 bfa_vc_attr->vc_info[i].borrow_credit;
2340 iocmd->attr.vc_info[i].priority =
2341 bfa_vc_attr->vc_info[i].priority;
2342 i++;
2343 }
2344 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2345
2346 iocmd->status = BFA_STATUS_OK;
2347 return 0;
2348}
2349
2350int
2351bfad_iocmd_qos_get_stats(struct bfad_s *bfad, void *cmd)
2352{
2353 struct bfa_bsg_fcport_stats_s *iocmd =
2354 (struct bfa_bsg_fcport_stats_s *)cmd;
2355 struct bfad_hal_comp fcomp;
2356 unsigned long flags;
2357 struct bfa_cb_pending_q_s cb_qe;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002358 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002359
2360 init_completion(&fcomp.comp);
2361 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2362 &fcomp, &iocmd->stats);
2363
2364 spin_lock_irqsave(&bfad->bfad_lock, flags);
2365 WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002366 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
2367 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
2368 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
2369 else
2370 iocmd->status = bfa_fcport_get_stats(&bfad->bfa, &cb_qe);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002371 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2372 if (iocmd->status != BFA_STATUS_OK) {
2373 bfa_trc(bfad, iocmd->status);
2374 goto out;
2375 }
2376 wait_for_completion(&fcomp.comp);
2377 iocmd->status = fcomp.status;
2378out:
2379 return 0;
2380}
2381
2382int
2383bfad_iocmd_qos_reset_stats(struct bfad_s *bfad, void *cmd)
2384{
2385 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
2386 struct bfad_hal_comp fcomp;
2387 unsigned long flags;
2388 struct bfa_cb_pending_q_s cb_qe;
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002389 struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(&bfad->bfa);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002390
2391 init_completion(&fcomp.comp);
2392 bfa_pending_q_init(&cb_qe, (bfa_cb_cbfn_t)bfad_hcb_comp,
2393 &fcomp, NULL);
2394
2395 spin_lock_irqsave(&bfad->bfad_lock, flags);
2396 WARN_ON(!bfa_ioc_get_fcmode(&bfad->bfa.ioc));
Krishna Gudipatibc0e2c22012-09-21 17:23:59 -07002397 if ((fcport->cfg.topology == BFA_PORT_TOPOLOGY_LOOP) &&
2398 (fcport->topology == BFA_PORT_TOPOLOGY_LOOP))
2399 iocmd->status = BFA_STATUS_TOPOLOGY_LOOP;
2400 else
2401 iocmd->status = bfa_fcport_clear_stats(&bfad->bfa, &cb_qe);
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002402 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2403 if (iocmd->status != BFA_STATUS_OK) {
2404 bfa_trc(bfad, iocmd->status);
2405 goto out;
2406 }
2407 wait_for_completion(&fcomp.comp);
2408 iocmd->status = fcomp.status;
2409out:
2410 return 0;
2411}
2412
Krishna Gudipatic0350bf2011-07-20 17:03:27 -07002413int
2414bfad_iocmd_vf_get_stats(struct bfad_s *bfad, void *cmd)
2415{
2416 struct bfa_bsg_vf_stats_s *iocmd =
2417 (struct bfa_bsg_vf_stats_s *)cmd;
2418 struct bfa_fcs_fabric_s *fcs_vf;
2419 unsigned long flags;
2420
2421 spin_lock_irqsave(&bfad->bfad_lock, flags);
2422 fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
2423 if (fcs_vf == NULL) {
2424 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2425 iocmd->status = BFA_STATUS_UNKNOWN_VFID;
2426 goto out;
2427 }
2428 memcpy((void *)&iocmd->stats, (void *)&fcs_vf->stats,
2429 sizeof(struct bfa_vf_stats_s));
2430 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2431 iocmd->status = BFA_STATUS_OK;
2432out:
2433 return 0;
2434}
2435
2436int
2437bfad_iocmd_vf_clr_stats(struct bfad_s *bfad, void *cmd)
2438{
2439 struct bfa_bsg_vf_reset_stats_s *iocmd =
2440 (struct bfa_bsg_vf_reset_stats_s *)cmd;
2441 struct bfa_fcs_fabric_s *fcs_vf;
2442 unsigned long flags;
2443
2444 spin_lock_irqsave(&bfad->bfad_lock, flags);
2445 fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
2446 if (fcs_vf == NULL) {
2447 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2448 iocmd->status = BFA_STATUS_UNKNOWN_VFID;
2449 goto out;
2450 }
2451 memset((void *)&fcs_vf->stats, 0, sizeof(struct bfa_vf_stats_s));
2452 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2453 iocmd->status = BFA_STATUS_OK;
2454out:
2455 return 0;
2456}
2457
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -08002458/* Function to reset the LUN SCAN mode */
2459static void
2460bfad_iocmd_lunmask_reset_lunscan_mode(struct bfad_s *bfad, int lunmask_cfg)
2461{
2462 struct bfad_im_port_s *pport_im = bfad->pport.im_port;
2463 struct bfad_vport_s *vport = NULL;
2464
2465 /* Set the scsi device LUN SCAN flags for base port */
2466 bfad_reset_sdev_bflags(pport_im, lunmask_cfg);
2467
2468 /* Set the scsi device LUN SCAN flags for the vports */
2469 list_for_each_entry(vport, &bfad->vport_list, list_entry)
2470 bfad_reset_sdev_bflags(vport->drv_port.im_port, lunmask_cfg);
2471}
2472
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002473int
2474bfad_iocmd_lunmask(struct bfad_s *bfad, void *pcmd, unsigned int v_cmd)
2475{
2476 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
2477 unsigned long flags;
2478
2479 spin_lock_irqsave(&bfad->bfad_lock, flags);
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -08002480 if (v_cmd == IOCMD_FCPIM_LUNMASK_ENABLE) {
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002481 iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_TRUE);
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -08002482 /* Set the LUN Scanning mode to be Sequential scan */
2483 if (iocmd->status == BFA_STATUS_OK)
2484 bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_TRUE);
2485 } else if (v_cmd == IOCMD_FCPIM_LUNMASK_DISABLE) {
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002486 iocmd->status = bfa_fcpim_lunmask_update(&bfad->bfa, BFA_FALSE);
Krishna Gudipati5b7db7a2011-12-20 18:58:32 -08002487 /* Set the LUN Scanning mode to default REPORT_LUNS scan */
2488 if (iocmd->status == BFA_STATUS_OK)
2489 bfad_iocmd_lunmask_reset_lunscan_mode(bfad, BFA_FALSE);
2490 } else if (v_cmd == IOCMD_FCPIM_LUNMASK_CLEAR)
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002491 iocmd->status = bfa_fcpim_lunmask_clear(&bfad->bfa);
2492 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2493 return 0;
2494}
2495
2496int
2497bfad_iocmd_fcpim_lunmask_query(struct bfad_s *bfad, void *cmd)
2498{
2499 struct bfa_bsg_fcpim_lunmask_query_s *iocmd =
2500 (struct bfa_bsg_fcpim_lunmask_query_s *)cmd;
2501 struct bfa_lunmask_cfg_s *lun_mask = &iocmd->lun_mask;
2502 unsigned long flags;
2503
2504 spin_lock_irqsave(&bfad->bfad_lock, flags);
2505 iocmd->status = bfa_fcpim_lunmask_query(&bfad->bfa, lun_mask);
2506 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2507 return 0;
2508}
2509
2510int
2511bfad_iocmd_fcpim_cfg_lunmask(struct bfad_s *bfad, void *cmd, unsigned int v_cmd)
2512{
2513 struct bfa_bsg_fcpim_lunmask_s *iocmd =
2514 (struct bfa_bsg_fcpim_lunmask_s *)cmd;
2515 unsigned long flags;
2516
2517 spin_lock_irqsave(&bfad->bfad_lock, flags);
2518 if (v_cmd == IOCMD_FCPIM_LUNMASK_ADD)
2519 iocmd->status = bfa_fcpim_lunmask_add(&bfad->bfa, iocmd->vf_id,
2520 &iocmd->pwwn, iocmd->rpwwn, iocmd->lun);
2521 else if (v_cmd == IOCMD_FCPIM_LUNMASK_DELETE)
2522 iocmd->status = bfa_fcpim_lunmask_delete(&bfad->bfa,
2523 iocmd->vf_id, &iocmd->pwwn,
2524 iocmd->rpwwn, iocmd->lun);
2525 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
2526 return 0;
2527}
2528
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002529static int
2530bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd,
2531 unsigned int payload_len)
2532{
Krishna Gudipati9afbcfa2011-07-20 16:59:44 -07002533 int rc = -EINVAL;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002534
2535 switch (cmd) {
Krishna Gudipati60138062011-06-24 20:25:15 -07002536 case IOCMD_IOC_ENABLE:
2537 rc = bfad_iocmd_ioc_enable(bfad, iocmd);
2538 break;
2539 case IOCMD_IOC_DISABLE:
2540 rc = bfad_iocmd_ioc_disable(bfad, iocmd);
2541 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002542 case IOCMD_IOC_GET_INFO:
2543 rc = bfad_iocmd_ioc_get_info(bfad, iocmd);
2544 break;
2545 case IOCMD_IOC_GET_ATTR:
2546 rc = bfad_iocmd_ioc_get_attr(bfad, iocmd);
2547 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002548 case IOCMD_IOC_GET_STATS:
2549 rc = bfad_iocmd_ioc_get_stats(bfad, iocmd);
2550 break;
2551 case IOCMD_IOC_GET_FWSTATS:
2552 rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len);
2553 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002554 case IOCMD_IOC_RESET_STATS:
2555 case IOCMD_IOC_RESET_FWSTATS:
2556 rc = bfad_iocmd_ioc_reset_stats(bfad, iocmd, cmd);
2557 break;
2558 case IOCMD_IOC_SET_ADAPTER_NAME:
2559 case IOCMD_IOC_SET_PORT_NAME:
2560 rc = bfad_iocmd_ioc_set_name(bfad, iocmd, cmd);
2561 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002562 case IOCMD_IOCFC_GET_ATTR:
2563 rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd);
2564 break;
2565 case IOCMD_IOCFC_SET_INTR:
2566 rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd);
2567 break;
2568 case IOCMD_PORT_ENABLE:
2569 rc = bfad_iocmd_port_enable(bfad, iocmd);
2570 break;
2571 case IOCMD_PORT_DISABLE:
2572 rc = bfad_iocmd_port_disable(bfad, iocmd);
2573 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002574 case IOCMD_PORT_GET_ATTR:
2575 rc = bfad_iocmd_port_get_attr(bfad, iocmd);
2576 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002577 case IOCMD_PORT_GET_STATS:
2578 rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len);
2579 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002580 case IOCMD_PORT_RESET_STATS:
2581 rc = bfad_iocmd_port_reset_stats(bfad, iocmd);
2582 break;
2583 case IOCMD_PORT_CFG_TOPO:
2584 case IOCMD_PORT_CFG_SPEED:
2585 case IOCMD_PORT_CFG_ALPA:
2586 case IOCMD_PORT_CLR_ALPA:
2587 rc = bfad_iocmd_set_port_cfg(bfad, iocmd, cmd);
2588 break;
2589 case IOCMD_PORT_CFG_MAXFRSZ:
2590 rc = bfad_iocmd_port_cfg_maxfrsize(bfad, iocmd);
2591 break;
2592 case IOCMD_PORT_BBSC_ENABLE:
2593 case IOCMD_PORT_BBSC_DISABLE:
2594 rc = bfad_iocmd_port_cfg_bbsc(bfad, iocmd, cmd);
2595 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002596 case IOCMD_LPORT_GET_ATTR:
2597 rc = bfad_iocmd_lport_get_attr(bfad, iocmd);
2598 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002599 case IOCMD_LPORT_GET_STATS:
2600 rc = bfad_iocmd_lport_get_stats(bfad, iocmd);
2601 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002602 case IOCMD_LPORT_RESET_STATS:
2603 rc = bfad_iocmd_lport_reset_stats(bfad, iocmd);
2604 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002605 case IOCMD_LPORT_GET_IOSTATS:
2606 rc = bfad_iocmd_lport_get_iostats(bfad, iocmd);
2607 break;
2608 case IOCMD_LPORT_GET_RPORTS:
2609 rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len);
2610 break;
2611 case IOCMD_RPORT_GET_ATTR:
2612 rc = bfad_iocmd_rport_get_attr(bfad, iocmd);
2613 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002614 case IOCMD_RPORT_GET_ADDR:
2615 rc = bfad_iocmd_rport_get_addr(bfad, iocmd);
2616 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002617 case IOCMD_RPORT_GET_STATS:
2618 rc = bfad_iocmd_rport_get_stats(bfad, iocmd);
2619 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002620 case IOCMD_RPORT_RESET_STATS:
2621 rc = bfad_iocmd_rport_clr_stats(bfad, iocmd);
2622 break;
2623 case IOCMD_RPORT_SET_SPEED:
2624 rc = bfad_iocmd_rport_set_speed(bfad, iocmd);
2625 break;
2626 case IOCMD_VPORT_GET_ATTR:
2627 rc = bfad_iocmd_vport_get_attr(bfad, iocmd);
2628 break;
2629 case IOCMD_VPORT_GET_STATS:
2630 rc = bfad_iocmd_vport_get_stats(bfad, iocmd);
2631 break;
2632 case IOCMD_VPORT_RESET_STATS:
2633 rc = bfad_iocmd_vport_clr_stats(bfad, iocmd);
2634 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002635 case IOCMD_FABRIC_GET_LPORTS:
2636 rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len);
2637 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002638 case IOCMD_RATELIM_ENABLE:
2639 case IOCMD_RATELIM_DISABLE:
2640 rc = bfad_iocmd_ratelim(bfad, cmd, iocmd);
2641 break;
2642 case IOCMD_RATELIM_DEF_SPEED:
2643 rc = bfad_iocmd_ratelim_speed(bfad, cmd, iocmd);
2644 break;
2645 case IOCMD_FCPIM_FAILOVER:
2646 rc = bfad_iocmd_cfg_fcpim(bfad, iocmd);
2647 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002648 case IOCMD_FCPIM_MODSTATS:
2649 rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd);
2650 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002651 case IOCMD_FCPIM_MODSTATSCLR:
2652 rc = bfad_iocmd_fcpim_clr_modstats(bfad, iocmd);
2653 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002654 case IOCMD_FCPIM_DEL_ITN_STATS:
2655 rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd);
2656 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002657 case IOCMD_ITNIM_GET_ATTR:
2658 rc = bfad_iocmd_itnim_get_attr(bfad, iocmd);
2659 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002660 case IOCMD_ITNIM_GET_IOSTATS:
2661 rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd);
2662 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002663 case IOCMD_ITNIM_RESET_STATS:
2664 rc = bfad_iocmd_itnim_reset_stats(bfad, iocmd);
2665 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07002666 case IOCMD_ITNIM_GET_ITNSTATS:
2667 rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd);
2668 break;
2669 case IOCMD_FCPORT_ENABLE:
2670 rc = bfad_iocmd_fcport_enable(bfad, iocmd);
2671 break;
2672 case IOCMD_FCPORT_DISABLE:
2673 rc = bfad_iocmd_fcport_disable(bfad, iocmd);
2674 break;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002675 case IOCMD_IOC_PCIFN_CFG:
2676 rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd);
2677 break;
2678 case IOCMD_PCIFN_CREATE:
2679 rc = bfad_iocmd_pcifn_create(bfad, iocmd);
2680 break;
2681 case IOCMD_PCIFN_DELETE:
2682 rc = bfad_iocmd_pcifn_delete(bfad, iocmd);
2683 break;
2684 case IOCMD_PCIFN_BW:
2685 rc = bfad_iocmd_pcifn_bw(bfad, iocmd);
2686 break;
2687 case IOCMD_ADAPTER_CFG_MODE:
2688 rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd);
2689 break;
2690 case IOCMD_PORT_CFG_MODE:
2691 rc = bfad_iocmd_port_cfg_mode(bfad, iocmd);
2692 break;
2693 case IOCMD_FLASH_ENABLE_OPTROM:
2694 case IOCMD_FLASH_DISABLE_OPTROM:
2695 rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd);
2696 break;
Krishna Gudipatia7141342011-06-24 20:23:19 -07002697 case IOCMD_FAA_QUERY:
2698 rc = bfad_iocmd_faa_query(bfad, iocmd);
2699 break;
Krishna Gudipati148d6102011-06-24 20:25:36 -07002700 case IOCMD_CEE_GET_ATTR:
2701 rc = bfad_iocmd_cee_attr(bfad, iocmd, payload_len);
2702 break;
2703 case IOCMD_CEE_GET_STATS:
2704 rc = bfad_iocmd_cee_get_stats(bfad, iocmd, payload_len);
2705 break;
2706 case IOCMD_CEE_RESET_STATS:
2707 rc = bfad_iocmd_cee_reset_stats(bfad, iocmd);
2708 break;
Krishna Gudipati51e569a2011-06-24 20:26:25 -07002709 case IOCMD_SFP_MEDIA:
2710 rc = bfad_iocmd_sfp_media(bfad, iocmd);
2711 break;
2712 case IOCMD_SFP_SPEED:
2713 rc = bfad_iocmd_sfp_speed(bfad, iocmd);
2714 break;
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07002715 case IOCMD_FLASH_GET_ATTR:
2716 rc = bfad_iocmd_flash_get_attr(bfad, iocmd);
2717 break;
2718 case IOCMD_FLASH_ERASE_PART:
2719 rc = bfad_iocmd_flash_erase_part(bfad, iocmd);
2720 break;
2721 case IOCMD_FLASH_UPDATE_PART:
2722 rc = bfad_iocmd_flash_update_part(bfad, iocmd, payload_len);
2723 break;
2724 case IOCMD_FLASH_READ_PART:
2725 rc = bfad_iocmd_flash_read_part(bfad, iocmd, payload_len);
2726 break;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07002727 case IOCMD_DIAG_TEMP:
2728 rc = bfad_iocmd_diag_temp(bfad, iocmd);
2729 break;
2730 case IOCMD_DIAG_MEMTEST:
2731 rc = bfad_iocmd_diag_memtest(bfad, iocmd);
2732 break;
2733 case IOCMD_DIAG_LOOPBACK:
2734 rc = bfad_iocmd_diag_loopback(bfad, iocmd);
2735 break;
2736 case IOCMD_DIAG_FWPING:
2737 rc = bfad_iocmd_diag_fwping(bfad, iocmd);
2738 break;
2739 case IOCMD_DIAG_QUEUETEST:
2740 rc = bfad_iocmd_diag_queuetest(bfad, iocmd);
2741 break;
2742 case IOCMD_DIAG_SFP:
2743 rc = bfad_iocmd_diag_sfp(bfad, iocmd);
2744 break;
2745 case IOCMD_DIAG_LED:
2746 rc = bfad_iocmd_diag_led(bfad, iocmd);
2747 break;
2748 case IOCMD_DIAG_BEACON_LPORT:
2749 rc = bfad_iocmd_diag_beacon_lport(bfad, iocmd);
2750 break;
2751 case IOCMD_DIAG_LB_STAT:
2752 rc = bfad_iocmd_diag_lb_stat(bfad, iocmd);
2753 break;
Krishna Gudipatie3535462012-09-21 17:26:07 -07002754 case IOCMD_DIAG_DPORT_ENABLE:
2755 case IOCMD_DIAG_DPORT_DISABLE:
2756 rc = bfad_iocmd_diag_cfg_dport(bfad, cmd, iocmd);
2757 break;
2758 case IOCMD_DIAG_DPORT_GET_STATE:
2759 rc = bfad_iocmd_diag_dport_get_state(bfad, iocmd);
2760 break;
Krishna Gudipati3350d982011-06-24 20:28:37 -07002761 case IOCMD_PHY_GET_ATTR:
2762 rc = bfad_iocmd_phy_get_attr(bfad, iocmd);
2763 break;
2764 case IOCMD_PHY_GET_STATS:
2765 rc = bfad_iocmd_phy_get_stats(bfad, iocmd);
2766 break;
2767 case IOCMD_PHY_UPDATE_FW:
2768 rc = bfad_iocmd_phy_update(bfad, iocmd, payload_len);
2769 break;
2770 case IOCMD_PHY_READ_FW:
2771 rc = bfad_iocmd_phy_read(bfad, iocmd, payload_len);
2772 break;
Krishna Gudipati61e62e22011-06-24 20:29:07 -07002773 case IOCMD_VHBA_QUERY:
2774 rc = bfad_iocmd_vhba_query(bfad, iocmd);
2775 break;
2776 case IOCMD_DEBUG_PORTLOG:
2777 rc = bfad_iocmd_porglog_get(bfad, iocmd);
2778 break;
Krishna Gudipatif2ee7602011-07-20 17:01:34 -07002779 case IOCMD_DEBUG_FW_CORE:
2780 rc = bfad_iocmd_debug_fw_core(bfad, iocmd, payload_len);
2781 break;
2782 case IOCMD_DEBUG_FW_STATE_CLR:
2783 case IOCMD_DEBUG_PORTLOG_CLR:
2784 case IOCMD_DEBUG_START_DTRC:
2785 case IOCMD_DEBUG_STOP_DTRC:
2786 rc = bfad_iocmd_debug_ctl(bfad, iocmd, cmd);
2787 break;
2788 case IOCMD_DEBUG_PORTLOG_CTL:
2789 rc = bfad_iocmd_porglog_ctl(bfad, iocmd);
2790 break;
Krishna Gudipati42a8e6e2011-07-20 17:01:52 -07002791 case IOCMD_FCPIM_PROFILE_ON:
2792 case IOCMD_FCPIM_PROFILE_OFF:
2793 rc = bfad_iocmd_fcpim_cfg_profile(bfad, iocmd, cmd);
2794 break;
2795 case IOCMD_ITNIM_GET_IOPROFILE:
2796 rc = bfad_iocmd_itnim_get_ioprofile(bfad, iocmd);
2797 break;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07002798 case IOCMD_FCPORT_GET_STATS:
2799 rc = bfad_iocmd_fcport_get_stats(bfad, iocmd);
2800 break;
2801 case IOCMD_FCPORT_RESET_STATS:
2802 rc = bfad_iocmd_fcport_reset_stats(bfad, iocmd);
2803 break;
Krishna Gudipatia46bd302011-07-20 17:02:32 -07002804 case IOCMD_BOOT_CFG:
2805 rc = bfad_iocmd_boot_cfg(bfad, iocmd);
2806 break;
2807 case IOCMD_BOOT_QUERY:
2808 rc = bfad_iocmd_boot_query(bfad, iocmd);
2809 break;
2810 case IOCMD_PREBOOT_QUERY:
2811 rc = bfad_iocmd_preboot_query(bfad, iocmd);
2812 break;
2813 case IOCMD_ETHBOOT_CFG:
2814 rc = bfad_iocmd_ethboot_cfg(bfad, iocmd);
2815 break;
2816 case IOCMD_ETHBOOT_QUERY:
2817 rc = bfad_iocmd_ethboot_query(bfad, iocmd);
2818 break;
Krishna Gudipati45191232011-07-20 17:02:50 -07002819 case IOCMD_TRUNK_ENABLE:
2820 case IOCMD_TRUNK_DISABLE:
2821 rc = bfad_iocmd_cfg_trunk(bfad, iocmd, cmd);
2822 break;
2823 case IOCMD_TRUNK_GET_ATTR:
2824 rc = bfad_iocmd_trunk_get_attr(bfad, iocmd);
2825 break;
Krishna Gudipati3ec4f2c2011-07-20 17:03:09 -07002826 case IOCMD_QOS_ENABLE:
2827 case IOCMD_QOS_DISABLE:
2828 rc = bfad_iocmd_qos(bfad, iocmd, cmd);
2829 break;
2830 case IOCMD_QOS_GET_ATTR:
2831 rc = bfad_iocmd_qos_get_attr(bfad, iocmd);
2832 break;
2833 case IOCMD_QOS_GET_VC_ATTR:
2834 rc = bfad_iocmd_qos_get_vc_attr(bfad, iocmd);
2835 break;
2836 case IOCMD_QOS_GET_STATS:
2837 rc = bfad_iocmd_qos_get_stats(bfad, iocmd);
2838 break;
2839 case IOCMD_QOS_RESET_STATS:
2840 rc = bfad_iocmd_qos_reset_stats(bfad, iocmd);
2841 break;
Krishna Gudipatic0350bf2011-07-20 17:03:27 -07002842 case IOCMD_VF_GET_STATS:
2843 rc = bfad_iocmd_vf_get_stats(bfad, iocmd);
2844 break;
2845 case IOCMD_VF_RESET_STATS:
2846 rc = bfad_iocmd_vf_clr_stats(bfad, iocmd);
2847 break;
Krishna Gudipati4c5d22b2011-07-20 17:04:24 -07002848 case IOCMD_FCPIM_LUNMASK_ENABLE:
2849 case IOCMD_FCPIM_LUNMASK_DISABLE:
2850 case IOCMD_FCPIM_LUNMASK_CLEAR:
2851 rc = bfad_iocmd_lunmask(bfad, iocmd, cmd);
2852 break;
2853 case IOCMD_FCPIM_LUNMASK_QUERY:
2854 rc = bfad_iocmd_fcpim_lunmask_query(bfad, iocmd);
2855 break;
2856 case IOCMD_FCPIM_LUNMASK_ADD:
2857 case IOCMD_FCPIM_LUNMASK_DELETE:
2858 rc = bfad_iocmd_fcpim_cfg_lunmask(bfad, iocmd, cmd);
2859 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002860 default:
Krishna Gudipati9afbcfa2011-07-20 16:59:44 -07002861 rc = -EINVAL;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002862 break;
2863 }
Krishna Gudipati9afbcfa2011-07-20 16:59:44 -07002864 return rc;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002865}
2866
2867static int
2868bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
2869{
2870 uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
2871 struct bfad_im_port_s *im_port =
2872 (struct bfad_im_port_s *) job->shost->hostdata[0];
2873 struct bfad_s *bfad = im_port->bfad;
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07002874 struct request_queue *request_q = job->req->q;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002875 void *payload_kbuf;
2876 int rc = -EINVAL;
2877
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07002878 /*
2879 * Set the BSG device request_queue size to 256 to support
2880 * payloads larger than 512*1024K bytes.
2881 */
2882 blk_queue_max_segments(request_q, 256);
2883
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07002884 /* Allocate a temp buffer to hold the passed in user space command */
2885 payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
2886 if (!payload_kbuf) {
2887 rc = -ENOMEM;
2888 goto out;
2889 }
2890
2891 /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */
2892 sg_copy_to_buffer(job->request_payload.sg_list,
2893 job->request_payload.sg_cnt, payload_kbuf,
2894 job->request_payload.payload_len);
2895
2896 /* Invoke IOCMD handler - to handle all the vendor command requests */
2897 rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf,
2898 job->request_payload.payload_len);
2899 if (rc != BFA_STATUS_OK)
2900 goto error;
2901
2902 /* Copy the response data to the job->reply_payload sg_list */
2903 sg_copy_from_buffer(job->reply_payload.sg_list,
2904 job->reply_payload.sg_cnt,
2905 payload_kbuf,
2906 job->reply_payload.payload_len);
2907
2908 /* free the command buffer */
2909 kfree(payload_kbuf);
2910
2911 /* Fill the BSG job reply data */
2912 job->reply_len = job->reply_payload.payload_len;
2913 job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
2914 job->reply->result = rc;
2915
2916 job->job_done(job);
2917 return rc;
2918error:
2919 /* free the command buffer */
2920 kfree(payload_kbuf);
2921out:
2922 job->reply->result = rc;
2923 job->reply_len = sizeof(uint32_t);
2924 job->reply->reply_payload_rcv_len = 0;
2925 return rc;
2926}
2927
2928/* FC passthru call backs */
2929u64
2930bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid)
2931{
2932 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2933 struct bfa_sge_s *sge;
2934 u64 addr;
2935
2936 sge = drv_fcxp->req_sge + sgeid;
2937 addr = (u64)(size_t) sge->sg_addr;
2938 return addr;
2939}
2940
2941u32
2942bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid)
2943{
2944 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2945 struct bfa_sge_s *sge;
2946
2947 sge = drv_fcxp->req_sge + sgeid;
2948 return sge->sg_len;
2949}
2950
2951u64
2952bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid)
2953{
2954 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2955 struct bfa_sge_s *sge;
2956 u64 addr;
2957
2958 sge = drv_fcxp->rsp_sge + sgeid;
2959 addr = (u64)(size_t) sge->sg_addr;
2960 return addr;
2961}
2962
2963u32
2964bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid)
2965{
2966 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2967 struct bfa_sge_s *sge;
2968
2969 sge = drv_fcxp->rsp_sge + sgeid;
2970 return sge->sg_len;
2971}
2972
2973void
2974bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
2975 bfa_status_t req_status, u32 rsp_len, u32 resid_len,
2976 struct fchs_s *rsp_fchs)
2977{
2978 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
2979
2980 drv_fcxp->req_status = req_status;
2981 drv_fcxp->rsp_len = rsp_len;
2982
2983 /* bfa_fcxp will be automatically freed by BFA */
2984 drv_fcxp->bfa_fcxp = NULL;
2985 complete(&drv_fcxp->comp);
2986}
2987
2988struct bfad_buf_info *
2989bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf,
2990 uint32_t payload_len, uint32_t *num_sgles)
2991{
2992 struct bfad_buf_info *buf_base, *buf_info;
2993 struct bfa_sge_s *sg_table;
2994 int sge_num = 1;
2995
2996 buf_base = kzalloc((sizeof(struct bfad_buf_info) +
2997 sizeof(struct bfa_sge_s)) * sge_num, GFP_KERNEL);
2998 if (!buf_base)
2999 return NULL;
3000
3001 sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) +
3002 (sizeof(struct bfad_buf_info) * sge_num));
3003
3004 /* Allocate dma coherent memory */
3005 buf_info = buf_base;
3006 buf_info->size = payload_len;
3007 buf_info->virt = dma_alloc_coherent(&bfad->pcidev->dev, buf_info->size,
3008 &buf_info->phys, GFP_KERNEL);
3009 if (!buf_info->virt)
3010 goto out_free_mem;
3011
3012 /* copy the linear bsg buffer to buf_info */
3013 memset(buf_info->virt, 0, buf_info->size);
3014 memcpy(buf_info->virt, payload_kbuf, buf_info->size);
3015
3016 /*
3017 * Setup SG table
3018 */
3019 sg_table->sg_len = buf_info->size;
3020 sg_table->sg_addr = (void *)(size_t) buf_info->phys;
3021
3022 *num_sgles = sge_num;
3023
3024 return buf_base;
3025
3026out_free_mem:
3027 kfree(buf_base);
3028 return NULL;
3029}
3030
3031void
3032bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base,
3033 uint32_t num_sgles)
3034{
3035 int i;
3036 struct bfad_buf_info *buf_info = buf_base;
3037
3038 if (buf_base) {
3039 for (i = 0; i < num_sgles; buf_info++, i++) {
3040 if (buf_info->virt != NULL)
3041 dma_free_coherent(&bfad->pcidev->dev,
3042 buf_info->size, buf_info->virt,
3043 buf_info->phys);
3044 }
3045 kfree(buf_base);
3046 }
3047}
3048
3049int
3050bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp,
3051 bfa_bsg_fcpt_t *bsg_fcpt)
3052{
3053 struct bfa_fcxp_s *hal_fcxp;
3054 struct bfad_s *bfad = drv_fcxp->port->bfad;
3055 unsigned long flags;
3056 uint8_t lp_tag;
3057
3058 spin_lock_irqsave(&bfad->bfad_lock, flags);
3059
3060 /* Allocate bfa_fcxp structure */
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003061 hal_fcxp = bfa_fcxp_req_rsp_alloc(drv_fcxp, &bfad->bfa,
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003062 drv_fcxp->num_req_sgles,
3063 drv_fcxp->num_rsp_sgles,
3064 bfad_fcxp_get_req_sgaddr_cb,
3065 bfad_fcxp_get_req_sglen_cb,
3066 bfad_fcxp_get_rsp_sgaddr_cb,
Krishna Gudipatic3f1b122012-08-22 19:51:08 -07003067 bfad_fcxp_get_rsp_sglen_cb, BFA_TRUE);
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003068 if (!hal_fcxp) {
3069 bfa_trc(bfad, 0);
3070 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3071 return BFA_STATUS_ENOMEM;
3072 }
3073
3074 drv_fcxp->bfa_fcxp = hal_fcxp;
3075
3076 lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id);
3077
3078 bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag,
3079 bsg_fcpt->cts, bsg_fcpt->cos,
3080 job->request_payload.payload_len,
3081 &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad,
3082 job->reply_payload.payload_len, bsg_fcpt->tsecs);
3083
3084 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3085
3086 return BFA_STATUS_OK;
3087}
3088
3089int
3090bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
3091{
3092 struct bfa_bsg_data *bsg_data;
3093 struct bfad_im_port_s *im_port =
3094 (struct bfad_im_port_s *) job->shost->hostdata[0];
3095 struct bfad_s *bfad = im_port->bfad;
3096 bfa_bsg_fcpt_t *bsg_fcpt;
3097 struct bfad_fcxp *drv_fcxp;
3098 struct bfa_fcs_lport_s *fcs_port;
3099 struct bfa_fcs_rport_s *fcs_rport;
3100 uint32_t command_type = job->request->msgcode;
3101 unsigned long flags;
3102 struct bfad_buf_info *rsp_buf_info;
3103 void *req_kbuf = NULL, *rsp_kbuf = NULL;
3104 int rc = -EINVAL;
3105
3106 job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */
3107 job->reply->reply_payload_rcv_len = 0;
3108
3109 /* Get the payload passed in from userspace */
3110 bsg_data = (struct bfa_bsg_data *) (((char *)job->request) +
3111 sizeof(struct fc_bsg_request));
3112 if (bsg_data == NULL)
3113 goto out;
3114
3115 /*
3116 * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload
3117 * buffer of size bsg_data->payload_len
3118 */
Jesper Juhl64b8aa72012-01-28 00:23:41 +01003119 bsg_fcpt = kzalloc(bsg_data->payload_len, GFP_KERNEL);
Krishna Gudipati529f9a72012-07-13 16:08:22 -07003120 if (!bsg_fcpt) {
3121 rc = -ENOMEM;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003122 goto out;
Krishna Gudipati529f9a72012-07-13 16:08:22 -07003123 }
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003124
3125 if (copy_from_user((uint8_t *)bsg_fcpt, bsg_data->payload,
3126 bsg_data->payload_len)) {
3127 kfree(bsg_fcpt);
Krishna Gudipati529f9a72012-07-13 16:08:22 -07003128 rc = -EIO;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003129 goto out;
3130 }
3131
3132 drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL);
3133 if (drv_fcxp == NULL) {
Jesper Juhl64b8aa72012-01-28 00:23:41 +01003134 kfree(bsg_fcpt);
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003135 rc = -ENOMEM;
3136 goto out;
3137 }
3138
3139 spin_lock_irqsave(&bfad->bfad_lock, flags);
3140 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id,
3141 bsg_fcpt->lpwwn);
3142 if (fcs_port == NULL) {
3143 bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN;
3144 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3145 goto out_free_mem;
3146 }
3147
3148 /* Check if the port is online before sending FC Passthru cmd */
3149 if (!bfa_fcs_lport_is_online(fcs_port)) {
3150 bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE;
3151 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3152 goto out_free_mem;
3153 }
3154
3155 drv_fcxp->port = fcs_port->bfad_port;
3156
3157 if (drv_fcxp->port->bfad == 0)
3158 drv_fcxp->port->bfad = bfad;
3159
3160 /* Fetch the bfa_rport - if nexus needed */
3161 if (command_type == FC_BSG_HST_ELS_NOLOGIN ||
3162 command_type == FC_BSG_HST_CT) {
3163 /* BSG HST commands: no nexus needed */
3164 drv_fcxp->bfa_rport = NULL;
3165
3166 } else if (command_type == FC_BSG_RPT_ELS ||
3167 command_type == FC_BSG_RPT_CT) {
3168 /* BSG RPT commands: nexus needed */
3169 fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port,
3170 bsg_fcpt->dpwwn);
3171 if (fcs_rport == NULL) {
3172 bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN;
3173 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3174 goto out_free_mem;
3175 }
3176
3177 drv_fcxp->bfa_rport = fcs_rport->bfa_rport;
3178
3179 } else { /* Unknown BSG msgcode; return -EINVAL */
3180 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3181 goto out_free_mem;
3182 }
3183
3184 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
3185
3186 /* allocate memory for req / rsp buffers */
3187 req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
3188 if (!req_kbuf) {
3189 printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n",
3190 bfad->pci_name);
3191 rc = -ENOMEM;
3192 goto out_free_mem;
3193 }
3194
3195 rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL);
3196 if (!rsp_kbuf) {
3197 printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n",
3198 bfad->pci_name);
3199 rc = -ENOMEM;
3200 goto out_free_mem;
3201 }
3202
3203 /* map req sg - copy the sg_list passed in to the linear buffer */
3204 sg_copy_to_buffer(job->request_payload.sg_list,
3205 job->request_payload.sg_cnt, req_kbuf,
3206 job->request_payload.payload_len);
3207
3208 drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf,
3209 job->request_payload.payload_len,
3210 &drv_fcxp->num_req_sgles);
3211 if (!drv_fcxp->reqbuf_info) {
3212 printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n",
3213 bfad->pci_name);
3214 rc = -ENOMEM;
3215 goto out_free_mem;
3216 }
3217
3218 drv_fcxp->req_sge = (struct bfa_sge_s *)
3219 (((uint8_t *)drv_fcxp->reqbuf_info) +
3220 (sizeof(struct bfad_buf_info) *
3221 drv_fcxp->num_req_sgles));
3222
3223 /* map rsp sg */
3224 drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf,
3225 job->reply_payload.payload_len,
3226 &drv_fcxp->num_rsp_sgles);
3227 if (!drv_fcxp->rspbuf_info) {
3228 printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n",
3229 bfad->pci_name);
3230 rc = -ENOMEM;
3231 goto out_free_mem;
3232 }
3233
3234 rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info;
3235 drv_fcxp->rsp_sge = (struct bfa_sge_s *)
3236 (((uint8_t *)drv_fcxp->rspbuf_info) +
3237 (sizeof(struct bfad_buf_info) *
3238 drv_fcxp->num_rsp_sgles));
3239
3240 /* fcxp send */
3241 init_completion(&drv_fcxp->comp);
3242 rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt);
3243 if (rc == BFA_STATUS_OK) {
3244 wait_for_completion(&drv_fcxp->comp);
3245 bsg_fcpt->status = drv_fcxp->req_status;
3246 } else {
3247 bsg_fcpt->status = rc;
3248 goto out_free_mem;
3249 }
3250
3251 /* fill the job->reply data */
3252 if (drv_fcxp->req_status == BFA_STATUS_OK) {
3253 job->reply_len = drv_fcxp->rsp_len;
3254 job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len;
3255 job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
3256 } else {
3257 job->reply->reply_payload_rcv_len =
3258 sizeof(struct fc_bsg_ctels_reply);
3259 job->reply_len = sizeof(uint32_t);
3260 job->reply->reply_data.ctels_reply.status =
3261 FC_CTELS_STATUS_REJECT;
3262 }
3263
3264 /* Copy the response data to the reply_payload sg list */
3265 sg_copy_from_buffer(job->reply_payload.sg_list,
3266 job->reply_payload.sg_cnt,
3267 (uint8_t *)rsp_buf_info->virt,
3268 job->reply_payload.payload_len);
3269
3270out_free_mem:
3271 bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info,
3272 drv_fcxp->num_rsp_sgles);
3273 bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info,
3274 drv_fcxp->num_req_sgles);
3275 kfree(req_kbuf);
3276 kfree(rsp_kbuf);
3277
3278 /* Need a copy to user op */
3279 if (copy_to_user(bsg_data->payload, (void *) bsg_fcpt,
3280 bsg_data->payload_len))
3281 rc = -EIO;
3282
3283 kfree(bsg_fcpt);
3284 kfree(drv_fcxp);
3285out:
3286 job->reply->result = rc;
3287
3288 if (rc == BFA_STATUS_OK)
3289 job->job_done(job);
3290
3291 return rc;
3292}
3293
3294int
3295bfad_im_bsg_request(struct fc_bsg_job *job)
3296{
3297 uint32_t rc = BFA_STATUS_OK;
3298
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003299 switch (job->request->msgcode) {
3300 case FC_BSG_HST_VENDOR:
3301 /* Process BSG HST Vendor requests */
3302 rc = bfad_im_bsg_vendor_request(job);
3303 break;
3304 case FC_BSG_HST_ELS_NOLOGIN:
3305 case FC_BSG_RPT_ELS:
3306 case FC_BSG_HST_CT:
3307 case FC_BSG_RPT_CT:
3308 /* Process BSG ELS/CT commands */
3309 rc = bfad_im_bsg_els_ct_request(job);
3310 break;
3311 default:
3312 job->reply->result = rc = -EINVAL;
3313 job->reply->reply_payload_rcv_len = 0;
3314 break;
3315 }
3316
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07003317 return rc;
3318}
3319
3320int
3321bfad_im_bsg_timeout(struct fc_bsg_job *job)
3322{
3323 /* Don't complete the BSG job request - return -EAGAIN
3324 * to reset bsg job timeout : for ELS/CT pass thru we
3325 * already have timer to track the request.
3326 */
3327 return -EAGAIN;
3328}