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