blob: 5ae591b062b37fa646dc06798edc4bd0942b5911 [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
25/* bfad_im_bsg_get_kobject - increment the bfa refcnt */
26static void
27bfad_im_bsg_get_kobject(struct fc_bsg_job *job)
28{
29 struct Scsi_Host *shost = job->shost;
30 unsigned long flags;
31
32 spin_lock_irqsave(shost->host_lock, flags);
33 __module_get(shost->dma_dev->driver->owner);
34 spin_unlock_irqrestore(shost->host_lock, flags);
35}
36
37/* bfad_im_bsg_put_kobject - decrement the bfa refcnt */
38static void
39bfad_im_bsg_put_kobject(struct fc_bsg_job *job)
40{
41 struct Scsi_Host *shost = job->shost;
42 unsigned long flags;
43
44 spin_lock_irqsave(shost->host_lock, flags);
45 module_put(shost->dma_dev->driver->owner);
46 spin_unlock_irqrestore(shost->host_lock, flags);
47}
48
Krishna Gudipati60138062011-06-24 20:25:15 -070049int
50bfad_iocmd_ioc_enable(struct bfad_s *bfad, void *cmd)
51{
52 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
53 int rc = 0;
54 unsigned long flags;
55
56 spin_lock_irqsave(&bfad->bfad_lock, flags);
57 /* If IOC is not in disabled state - return */
58 if (!bfa_ioc_is_disabled(&bfad->bfa.ioc)) {
59 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
60 iocmd->status = BFA_STATUS_IOC_FAILURE;
61 return rc;
62 }
63
64 init_completion(&bfad->enable_comp);
65 bfa_iocfc_enable(&bfad->bfa);
66 iocmd->status = BFA_STATUS_OK;
67 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
68 wait_for_completion(&bfad->enable_comp);
69
70 return rc;
71}
72
73int
74bfad_iocmd_ioc_disable(struct bfad_s *bfad, void *cmd)
75{
76 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
77 int rc = 0;
78 unsigned long flags;
79
80 spin_lock_irqsave(&bfad->bfad_lock, flags);
81 if (bfad->disable_active) {
82 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
83 return EBUSY;
84 }
85
86 bfad->disable_active = BFA_TRUE;
87 init_completion(&bfad->disable_comp);
88 bfa_iocfc_disable(&bfad->bfa);
89 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
90
91 wait_for_completion(&bfad->disable_comp);
92 bfad->disable_active = BFA_FALSE;
93 iocmd->status = BFA_STATUS_OK;
94
95 return rc;
96}
97
Krishna Gudipatib85daaf2011-06-13 15:55:11 -070098static int
99bfad_iocmd_ioc_get_info(struct bfad_s *bfad, void *cmd)
100{
101 int i;
102 struct bfa_bsg_ioc_info_s *iocmd = (struct bfa_bsg_ioc_info_s *)cmd;
103 struct bfad_im_port_s *im_port;
104 struct bfa_port_attr_s pattr;
105 unsigned long flags;
106
107 spin_lock_irqsave(&bfad->bfad_lock, flags);
108 bfa_fcport_get_attr(&bfad->bfa, &pattr);
109 iocmd->nwwn = pattr.nwwn;
110 iocmd->pwwn = pattr.pwwn;
111 iocmd->ioc_type = bfa_get_type(&bfad->bfa);
112 iocmd->mac = bfa_get_mac(&bfad->bfa);
113 iocmd->factory_mac = bfa_get_mfg_mac(&bfad->bfa);
114 bfa_get_adapter_serial_num(&bfad->bfa, iocmd->serialnum);
115 iocmd->factorynwwn = pattr.factorynwwn;
116 iocmd->factorypwwn = pattr.factorypwwn;
117 im_port = bfad->pport.im_port;
118 iocmd->host = im_port->shost->host_no;
119 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
120
121 strcpy(iocmd->name, bfad->adapter_name);
122 strcpy(iocmd->port_name, bfad->port_name);
123 strcpy(iocmd->hwpath, bfad->pci_name);
124
125 /* set adapter hw path */
126 strcpy(iocmd->adapter_hwpath, bfad->pci_name);
127 i = strlen(iocmd->adapter_hwpath) - 1;
128 while (iocmd->adapter_hwpath[i] != '.')
129 i--;
130 iocmd->adapter_hwpath[i] = '\0';
131 iocmd->status = BFA_STATUS_OK;
132 return 0;
133}
134
135static int
136bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd)
137{
138 struct bfa_bsg_ioc_attr_s *iocmd = (struct bfa_bsg_ioc_attr_s *)cmd;
139 unsigned long flags;
140
141 spin_lock_irqsave(&bfad->bfad_lock, flags);
142 bfa_ioc_get_attr(&bfad->bfa.ioc, &iocmd->ioc_attr);
143 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
144
145 /* fill in driver attr info */
146 strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME);
147 strncpy(iocmd->ioc_attr.driver_attr.driver_ver,
148 BFAD_DRIVER_VERSION, BFA_VERSION_LEN);
149 strcpy(iocmd->ioc_attr.driver_attr.fw_ver,
150 iocmd->ioc_attr.adapter_attr.fw_ver);
151 strcpy(iocmd->ioc_attr.driver_attr.bios_ver,
152 iocmd->ioc_attr.adapter_attr.optrom_ver);
153
154 /* copy chip rev info first otherwise it will be overwritten */
155 memcpy(bfad->pci_attr.chip_rev, iocmd->ioc_attr.pci_attr.chip_rev,
156 sizeof(bfad->pci_attr.chip_rev));
157 memcpy(&iocmd->ioc_attr.pci_attr, &bfad->pci_attr,
158 sizeof(struct bfa_ioc_pci_attr_s));
159
160 iocmd->status = BFA_STATUS_OK;
161 return 0;
162}
163
Krishna Gudipati60138062011-06-24 20:25:15 -0700164int
165bfad_iocmd_ioc_get_stats(struct bfad_s *bfad, void *cmd)
166{
167 struct bfa_bsg_ioc_stats_s *iocmd = (struct bfa_bsg_ioc_stats_s *)cmd;
168
169 bfa_ioc_get_stats(&bfad->bfa, &iocmd->ioc_stats);
170 iocmd->status = BFA_STATUS_OK;
171 return 0;
172}
173
174int
175bfad_iocmd_ioc_get_fwstats(struct bfad_s *bfad, void *cmd,
176 unsigned int payload_len)
177{
178 struct bfa_bsg_ioc_fwstats_s *iocmd =
179 (struct bfa_bsg_ioc_fwstats_s *)cmd;
180 void *iocmd_bufptr;
181 unsigned long flags;
182
183 if (bfad_chk_iocmd_sz(payload_len,
184 sizeof(struct bfa_bsg_ioc_fwstats_s),
185 sizeof(struct bfa_fw_stats_s)) != BFA_STATUS_OK) {
186 iocmd->status = BFA_STATUS_VERSION_FAIL;
187 goto out;
188 }
189
190 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_ioc_fwstats_s);
191 spin_lock_irqsave(&bfad->bfad_lock, flags);
192 iocmd->status = bfa_ioc_fw_stats_get(&bfad->bfa.ioc, iocmd_bufptr);
193 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
194
195 if (iocmd->status != BFA_STATUS_OK) {
196 bfa_trc(bfad, iocmd->status);
197 goto out;
198 }
199out:
200 bfa_trc(bfad, 0x6666);
201 return 0;
202}
203
204int
205bfad_iocmd_iocfc_get_attr(struct bfad_s *bfad, void *cmd)
206{
207 struct bfa_bsg_iocfc_attr_s *iocmd = (struct bfa_bsg_iocfc_attr_s *)cmd;
208
209 iocmd->status = BFA_STATUS_OK;
210 bfa_iocfc_get_attr(&bfad->bfa, &iocmd->iocfc_attr);
211
212 return 0;
213}
214
215int
216bfad_iocmd_iocfc_set_intr(struct bfad_s *bfad, void *cmd)
217{
218 struct bfa_bsg_iocfc_intr_s *iocmd = (struct bfa_bsg_iocfc_intr_s *)cmd;
219 unsigned long flags;
220
221 spin_lock_irqsave(&bfad->bfad_lock, flags);
222 iocmd->status = bfa_iocfc_israttr_set(&bfad->bfa, &iocmd->attr);
223 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
224
225 return 0;
226}
227
228int
229bfad_iocmd_port_enable(struct bfad_s *bfad, void *cmd)
230{
231 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
232 struct bfad_hal_comp fcomp;
233 unsigned long flags;
234
235 init_completion(&fcomp.comp);
236 spin_lock_irqsave(&bfad->bfad_lock, flags);
237 iocmd->status = bfa_port_enable(&bfad->bfa.modules.port,
238 bfad_hcb_comp, &fcomp);
239 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
240 if (iocmd->status != BFA_STATUS_OK) {
241 bfa_trc(bfad, iocmd->status);
242 return 0;
243 }
244 wait_for_completion(&fcomp.comp);
245 iocmd->status = fcomp.status;
246 return 0;
247}
248
249int
250bfad_iocmd_port_disable(struct bfad_s *bfad, void *cmd)
251{
252 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
253 struct bfad_hal_comp fcomp;
254 unsigned long flags;
255
256 init_completion(&fcomp.comp);
257 spin_lock_irqsave(&bfad->bfad_lock, flags);
258 iocmd->status = bfa_port_disable(&bfad->bfa.modules.port,
259 bfad_hcb_comp, &fcomp);
260 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
261
262 if (iocmd->status != BFA_STATUS_OK) {
263 bfa_trc(bfad, iocmd->status);
264 return 0;
265 }
266 wait_for_completion(&fcomp.comp);
267 iocmd->status = fcomp.status;
268 return 0;
269}
270
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700271static int
272bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd)
273{
274 struct bfa_bsg_port_attr_s *iocmd = (struct bfa_bsg_port_attr_s *)cmd;
275 struct bfa_lport_attr_s port_attr;
276 unsigned long flags;
277
278 spin_lock_irqsave(&bfad->bfad_lock, flags);
279 bfa_fcport_get_attr(&bfad->bfa, &iocmd->attr);
280 bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
281 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
282
283 if (iocmd->attr.topology != BFA_PORT_TOPOLOGY_NONE)
284 iocmd->attr.pid = port_attr.pid;
285 else
286 iocmd->attr.pid = 0;
287
288 iocmd->attr.port_type = port_attr.port_type;
289 iocmd->attr.loopback = port_attr.loopback;
290 iocmd->attr.authfail = port_attr.authfail;
291 strncpy(iocmd->attr.port_symname.symname,
292 port_attr.port_cfg.sym_name.symname,
293 sizeof(port_attr.port_cfg.sym_name.symname));
294
295 iocmd->status = BFA_STATUS_OK;
296 return 0;
297}
298
Krishna Gudipati60138062011-06-24 20:25:15 -0700299int
300bfad_iocmd_port_get_stats(struct bfad_s *bfad, void *cmd,
301 unsigned int payload_len)
302{
303 struct bfa_bsg_port_stats_s *iocmd = (struct bfa_bsg_port_stats_s *)cmd;
304 struct bfad_hal_comp fcomp;
305 void *iocmd_bufptr;
306 unsigned long flags;
307
308 if (bfad_chk_iocmd_sz(payload_len,
309 sizeof(struct bfa_bsg_port_stats_s),
310 sizeof(union bfa_port_stats_u)) != BFA_STATUS_OK) {
311 iocmd->status = BFA_STATUS_VERSION_FAIL;
312 return 0;
313 }
314
315 iocmd_bufptr = (char *)iocmd + sizeof(struct bfa_bsg_port_stats_s);
316
317 init_completion(&fcomp.comp);
318 spin_lock_irqsave(&bfad->bfad_lock, flags);
319 iocmd->status = bfa_port_get_stats(&bfad->bfa.modules.port,
320 iocmd_bufptr, bfad_hcb_comp, &fcomp);
321 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
322 if (iocmd->status != BFA_STATUS_OK) {
323 bfa_trc(bfad, iocmd->status);
324 goto out;
325 }
326
327 wait_for_completion(&fcomp.comp);
328 iocmd->status = fcomp.status;
329out:
330 return 0;
331}
332
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700333static int
334bfad_iocmd_lport_get_attr(struct bfad_s *bfad, void *cmd)
335{
336 struct bfa_fcs_lport_s *fcs_port;
337 struct bfa_bsg_lport_attr_s *iocmd = (struct bfa_bsg_lport_attr_s *)cmd;
338 unsigned long flags;
339
340 spin_lock_irqsave(&bfad->bfad_lock, flags);
341 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
342 iocmd->vf_id, iocmd->pwwn);
343 if (fcs_port == NULL) {
344 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
345 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
346 goto out;
347 }
348
349 bfa_fcs_lport_get_attr(fcs_port, &iocmd->port_attr);
350 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
351 iocmd->status = BFA_STATUS_OK;
352out:
353 return 0;
354}
355
Krishna Gudipati60138062011-06-24 20:25:15 -0700356int
357bfad_iocmd_lport_get_stats(struct bfad_s *bfad, void *cmd)
358{
359 struct bfa_fcs_lport_s *fcs_port;
360 struct bfa_bsg_lport_stats_s *iocmd =
361 (struct bfa_bsg_lport_stats_s *)cmd;
362 unsigned long flags;
363
364 spin_lock_irqsave(&bfad->bfad_lock, flags);
365 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
366 iocmd->vf_id, iocmd->pwwn);
367 if (fcs_port == NULL) {
368 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
369 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
370 goto out;
371 }
372
373 bfa_fcs_lport_get_stats(fcs_port, &iocmd->port_stats);
374 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
375 iocmd->status = BFA_STATUS_OK;
376out:
377 return 0;
378}
379
380int
381bfad_iocmd_lport_get_iostats(struct bfad_s *bfad, void *cmd)
382{
383 struct bfa_fcs_lport_s *fcs_port;
384 struct bfa_bsg_lport_iostats_s *iocmd =
385 (struct bfa_bsg_lport_iostats_s *)cmd;
386 unsigned long flags;
387
388 spin_lock_irqsave(&bfad->bfad_lock, flags);
389 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
390 iocmd->vf_id, iocmd->pwwn);
391 if (fcs_port == NULL) {
392 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
393 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
394 goto out;
395 }
396
397 bfa_fcpim_port_iostats(&bfad->bfa, &iocmd->iostats,
398 fcs_port->lp_tag);
399 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
400 iocmd->status = BFA_STATUS_OK;
401out:
402 return 0;
403}
404
405int
406bfad_iocmd_lport_get_rports(struct bfad_s *bfad, void *cmd,
407 unsigned int payload_len)
408{
409 struct bfa_bsg_lport_get_rports_s *iocmd =
410 (struct bfa_bsg_lport_get_rports_s *)cmd;
411 struct bfa_fcs_lport_s *fcs_port;
412 unsigned long flags;
413 void *iocmd_bufptr;
414
415 if (iocmd->nrports == 0)
416 return EINVAL;
417
418 if (bfad_chk_iocmd_sz(payload_len,
419 sizeof(struct bfa_bsg_lport_get_rports_s),
420 sizeof(wwn_t) * iocmd->nrports) != BFA_STATUS_OK) {
421 iocmd->status = BFA_STATUS_VERSION_FAIL;
422 return 0;
423 }
424
425 iocmd_bufptr = (char *)iocmd +
426 sizeof(struct bfa_bsg_lport_get_rports_s);
427 spin_lock_irqsave(&bfad->bfad_lock, flags);
428 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
429 iocmd->vf_id, iocmd->pwwn);
430 if (fcs_port == NULL) {
431 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
432 bfa_trc(bfad, 0);
433 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
434 goto out;
435 }
436
437 bfa_fcs_lport_get_rports(fcs_port, (wwn_t *)iocmd_bufptr,
438 &iocmd->nrports);
439 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
440 iocmd->status = BFA_STATUS_OK;
441out:
442 return 0;
443}
444
445int
446bfad_iocmd_rport_get_attr(struct bfad_s *bfad, void *cmd)
447{
448 struct bfa_bsg_rport_attr_s *iocmd = (struct bfa_bsg_rport_attr_s *)cmd;
449 struct bfa_fcs_lport_s *fcs_port;
450 struct bfa_fcs_rport_s *fcs_rport;
451 unsigned long flags;
452
453 spin_lock_irqsave(&bfad->bfad_lock, flags);
454 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
455 iocmd->vf_id, iocmd->pwwn);
456 if (fcs_port == NULL) {
457 bfa_trc(bfad, 0);
458 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
459 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
460 goto out;
461 }
462
463 fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
464 if (fcs_rport == NULL) {
465 bfa_trc(bfad, 0);
466 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
467 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
468 goto out;
469 }
470
471 bfa_fcs_rport_get_attr(fcs_rport, &iocmd->attr);
472 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
473 iocmd->status = BFA_STATUS_OK;
474out:
475 return 0;
476}
477
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700478static int
479bfad_iocmd_rport_get_addr(struct bfad_s *bfad, void *cmd)
480{
481 struct bfa_bsg_rport_scsi_addr_s *iocmd =
482 (struct bfa_bsg_rport_scsi_addr_s *)cmd;
483 struct bfa_fcs_lport_s *fcs_port;
484 struct bfa_fcs_itnim_s *fcs_itnim;
485 struct bfad_itnim_s *drv_itnim;
486 unsigned long flags;
487
488 spin_lock_irqsave(&bfad->bfad_lock, flags);
489 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
490 iocmd->vf_id, iocmd->pwwn);
491 if (fcs_port == NULL) {
492 bfa_trc(bfad, 0);
493 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
494 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
495 goto out;
496 }
497
498 fcs_itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
499 if (fcs_itnim == NULL) {
500 bfa_trc(bfad, 0);
501 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
502 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
503 goto out;
504 }
505
506 drv_itnim = fcs_itnim->itnim_drv;
507
508 if (drv_itnim && drv_itnim->im_port)
509 iocmd->host = drv_itnim->im_port->shost->host_no;
510 else {
511 bfa_trc(bfad, 0);
512 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
513 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
514 goto out;
515 }
516
517 iocmd->target = drv_itnim->scsi_tgt_id;
518 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
519
520 iocmd->bus = 0;
521 iocmd->lun = 0;
522 iocmd->status = BFA_STATUS_OK;
523out:
524 return 0;
525}
526
Krishna Gudipati60138062011-06-24 20:25:15 -0700527int
528bfad_iocmd_rport_get_stats(struct bfad_s *bfad, void *cmd)
529{
530 struct bfa_bsg_rport_stats_s *iocmd =
531 (struct bfa_bsg_rport_stats_s *)cmd;
532 struct bfa_fcs_lport_s *fcs_port;
533 struct bfa_fcs_rport_s *fcs_rport;
534 unsigned long flags;
535
536 spin_lock_irqsave(&bfad->bfad_lock, flags);
537 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
538 iocmd->vf_id, iocmd->pwwn);
539 if (fcs_port == NULL) {
540 bfa_trc(bfad, 0);
541 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
542 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
543 goto out;
544 }
545
546 fcs_rport = bfa_fcs_rport_lookup(fcs_port, iocmd->rpwwn);
547 if (fcs_rport == NULL) {
548 bfa_trc(bfad, 0);
549 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
550 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
551 goto out;
552 }
553
554 memcpy((void *)&iocmd->stats, (void *)&fcs_rport->stats,
555 sizeof(struct bfa_rport_stats_s));
556 memcpy((void *)&iocmd->stats.hal_stats,
557 (void *)&(bfa_fcs_rport_get_halrport(fcs_rport)->stats),
558 sizeof(struct bfa_rport_hal_stats_s));
559
560 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
561 iocmd->status = BFA_STATUS_OK;
562out:
563 return 0;
564}
565
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700566static int
567bfad_iocmd_fabric_get_lports(struct bfad_s *bfad, void *cmd,
568 unsigned int payload_len)
569{
570 struct bfa_bsg_fabric_get_lports_s *iocmd =
571 (struct bfa_bsg_fabric_get_lports_s *)cmd;
572 bfa_fcs_vf_t *fcs_vf;
573 uint32_t nports = iocmd->nports;
574 unsigned long flags;
575 void *iocmd_bufptr;
576
577 if (nports == 0) {
578 iocmd->status = BFA_STATUS_EINVAL;
579 goto out;
580 }
581
582 if (bfad_chk_iocmd_sz(payload_len,
583 sizeof(struct bfa_bsg_fabric_get_lports_s),
584 sizeof(wwn_t[iocmd->nports])) != BFA_STATUS_OK) {
585 iocmd->status = BFA_STATUS_VERSION_FAIL;
586 goto out;
587 }
588
589 iocmd_bufptr = (char *)iocmd +
590 sizeof(struct bfa_bsg_fabric_get_lports_s);
591
592 spin_lock_irqsave(&bfad->bfad_lock, flags);
593 fcs_vf = bfa_fcs_vf_lookup(&bfad->bfa_fcs, iocmd->vf_id);
594 if (fcs_vf == NULL) {
595 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
596 iocmd->status = BFA_STATUS_UNKNOWN_VFID;
597 goto out;
598 }
599 bfa_fcs_vf_get_ports(fcs_vf, (wwn_t *)iocmd_bufptr, &nports);
600 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
601
602 iocmd->nports = nports;
603 iocmd->status = BFA_STATUS_OK;
604out:
605 return 0;
606}
607
Krishna Gudipati60138062011-06-24 20:25:15 -0700608int
609bfad_iocmd_fcpim_get_modstats(struct bfad_s *bfad, void *cmd)
610{
611 struct bfa_bsg_fcpim_modstats_s *iocmd =
612 (struct bfa_bsg_fcpim_modstats_s *)cmd;
613 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
614 struct list_head *qe, *qen;
615 struct bfa_itnim_s *itnim;
616 unsigned long flags;
617
618 spin_lock_irqsave(&bfad->bfad_lock, flags);
619 /* accumulate IO stats from itnim */
620 memset((void *)&iocmd->modstats, 0, sizeof(struct bfa_itnim_iostats_s));
621 list_for_each_safe(qe, qen, &fcpim->itnim_q) {
622 itnim = (struct bfa_itnim_s *) qe;
623 bfa_fcpim_add_stats(&iocmd->modstats, &(itnim->stats));
624 }
625 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
626 iocmd->status = BFA_STATUS_OK;
627 return 0;
628}
629
630int
631bfad_iocmd_fcpim_get_del_itn_stats(struct bfad_s *bfad, void *cmd)
632{
633 struct bfa_bsg_fcpim_del_itn_stats_s *iocmd =
634 (struct bfa_bsg_fcpim_del_itn_stats_s *)cmd;
635 struct bfa_fcpim_s *fcpim = BFA_FCPIM(&bfad->bfa);
636 unsigned long flags;
637
638 spin_lock_irqsave(&bfad->bfad_lock, flags);
639 memcpy((void *)&iocmd->modstats, (void *)&fcpim->del_itn_stats,
640 sizeof(struct bfa_fcpim_del_itn_stats_s));
641 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
642
643 iocmd->status = BFA_STATUS_OK;
644 return 0;
645}
646
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700647static int
648bfad_iocmd_itnim_get_attr(struct bfad_s *bfad, void *cmd)
649{
650 struct bfa_bsg_itnim_attr_s *iocmd = (struct bfa_bsg_itnim_attr_s *)cmd;
651 struct bfa_fcs_lport_s *fcs_port;
652 unsigned long flags;
653
654 spin_lock_irqsave(&bfad->bfad_lock, flags);
655 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
656 iocmd->vf_id, iocmd->lpwwn);
657 if (!fcs_port)
658 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
659 else
660 iocmd->status = bfa_fcs_itnim_attr_get(fcs_port,
661 iocmd->rpwwn, &iocmd->attr);
662 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
663 return 0;
664}
665
Krishna Gudipati60138062011-06-24 20:25:15 -0700666static int
667bfad_iocmd_itnim_get_iostats(struct bfad_s *bfad, void *cmd)
668{
669 struct bfa_bsg_itnim_iostats_s *iocmd =
670 (struct bfa_bsg_itnim_iostats_s *)cmd;
671 struct bfa_fcs_lport_s *fcs_port;
672 struct bfa_fcs_itnim_s *itnim;
673 unsigned long flags;
674
675 spin_lock_irqsave(&bfad->bfad_lock, flags);
676 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
677 iocmd->vf_id, iocmd->lpwwn);
678 if (!fcs_port) {
679 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
680 bfa_trc(bfad, 0);
681 } else {
682 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
683 if (itnim == NULL)
684 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
685 else {
686 iocmd->status = BFA_STATUS_OK;
687 memcpy((void *)&iocmd->iostats, (void *)
688 &(bfa_fcs_itnim_get_halitn(itnim)->stats),
689 sizeof(struct bfa_itnim_iostats_s));
690 }
691 }
692 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
693 return 0;
694}
695
696static int
697bfad_iocmd_itnim_get_itnstats(struct bfad_s *bfad, void *cmd)
698{
699 struct bfa_bsg_itnim_itnstats_s *iocmd =
700 (struct bfa_bsg_itnim_itnstats_s *)cmd;
701 struct bfa_fcs_lport_s *fcs_port;
702 struct bfa_fcs_itnim_s *itnim;
703 unsigned long flags;
704
705 spin_lock_irqsave(&bfad->bfad_lock, flags);
706 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs,
707 iocmd->vf_id, iocmd->lpwwn);
708 if (!fcs_port) {
709 iocmd->status = BFA_STATUS_UNKNOWN_LWWN;
710 bfa_trc(bfad, 0);
711 } else {
712 itnim = bfa_fcs_itnim_lookup(fcs_port, iocmd->rpwwn);
713 if (itnim == NULL)
714 iocmd->status = BFA_STATUS_UNKNOWN_RWWN;
715 else {
716 iocmd->status = BFA_STATUS_OK;
717 bfa_fcs_itnim_stats_get(fcs_port, iocmd->rpwwn,
718 &iocmd->itnstats);
719 }
720 }
721 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
722 return 0;
723}
724
725int
726bfad_iocmd_fcport_enable(struct bfad_s *bfad, void *cmd)
727{
728 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
729 unsigned long flags;
730
731 spin_lock_irqsave(&bfad->bfad_lock, flags);
732 iocmd->status = bfa_fcport_enable(&bfad->bfa);
733 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
734
735 return 0;
736}
737
738int
739bfad_iocmd_fcport_disable(struct bfad_s *bfad, void *cmd)
740{
741 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
742 unsigned long flags;
743
744 spin_lock_irqsave(&bfad->bfad_lock, flags);
745 iocmd->status = bfa_fcport_disable(&bfad->bfa);
746 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
747
748 return 0;
749}
750
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700751int
752bfad_iocmd_ioc_get_pcifn_cfg(struct bfad_s *bfad, void *cmd)
753{
754 struct bfa_bsg_pcifn_cfg_s *iocmd = (struct bfa_bsg_pcifn_cfg_s *)cmd;
755 struct bfad_hal_comp fcomp;
756 unsigned long flags;
757
758 init_completion(&fcomp.comp);
759 spin_lock_irqsave(&bfad->bfad_lock, flags);
760 iocmd->status = bfa_ablk_query(&bfad->bfa.modules.ablk,
761 &iocmd->pcifn_cfg,
762 bfad_hcb_comp, &fcomp);
763 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
764 if (iocmd->status != BFA_STATUS_OK)
765 goto out;
766
767 wait_for_completion(&fcomp.comp);
768 iocmd->status = fcomp.status;
769out:
770 return 0;
771}
772
773int
774bfad_iocmd_pcifn_create(struct bfad_s *bfad, void *cmd)
775{
776 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
777 struct bfad_hal_comp fcomp;
778 unsigned long flags;
779
780 init_completion(&fcomp.comp);
781 spin_lock_irqsave(&bfad->bfad_lock, flags);
782 iocmd->status = bfa_ablk_pf_create(&bfad->bfa.modules.ablk,
783 &iocmd->pcifn_id, iocmd->port,
784 iocmd->pcifn_class, iocmd->bandwidth,
785 bfad_hcb_comp, &fcomp);
786 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
787 if (iocmd->status != BFA_STATUS_OK)
788 goto out;
789
790 wait_for_completion(&fcomp.comp);
791 iocmd->status = fcomp.status;
792out:
793 return 0;
794}
795
796int
797bfad_iocmd_pcifn_delete(struct bfad_s *bfad, void *cmd)
798{
799 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
800 struct bfad_hal_comp fcomp;
801 unsigned long flags;
802
803 init_completion(&fcomp.comp);
804 spin_lock_irqsave(&bfad->bfad_lock, flags);
805 iocmd->status = bfa_ablk_pf_delete(&bfad->bfa.modules.ablk,
806 iocmd->pcifn_id,
807 bfad_hcb_comp, &fcomp);
808 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
809 if (iocmd->status != BFA_STATUS_OK)
810 goto out;
811
812 wait_for_completion(&fcomp.comp);
813 iocmd->status = fcomp.status;
814out:
815 return 0;
816}
817
818int
819bfad_iocmd_pcifn_bw(struct bfad_s *bfad, void *cmd)
820{
821 struct bfa_bsg_pcifn_s *iocmd = (struct bfa_bsg_pcifn_s *)cmd;
822 struct bfad_hal_comp fcomp;
823 unsigned long flags;
824
825 init_completion(&fcomp.comp);
826 spin_lock_irqsave(&bfad->bfad_lock, flags);
827 iocmd->status = bfa_ablk_pf_update(&bfad->bfa.modules.ablk,
828 iocmd->pcifn_id, iocmd->bandwidth,
829 bfad_hcb_comp, &fcomp);
830 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
831 bfa_trc(bfad, iocmd->status);
832 if (iocmd->status != BFA_STATUS_OK)
833 goto out;
834
835 wait_for_completion(&fcomp.comp);
836 iocmd->status = fcomp.status;
837 bfa_trc(bfad, iocmd->status);
838out:
839 return 0;
840}
841
842int
843bfad_iocmd_adapter_cfg_mode(struct bfad_s *bfad, void *cmd)
844{
845 struct bfa_bsg_adapter_cfg_mode_s *iocmd =
846 (struct bfa_bsg_adapter_cfg_mode_s *)cmd;
847 struct bfad_hal_comp fcomp;
848 unsigned long flags = 0;
849
850 init_completion(&fcomp.comp);
851 spin_lock_irqsave(&bfad->bfad_lock, flags);
852 iocmd->status = bfa_ablk_adapter_config(&bfad->bfa.modules.ablk,
853 iocmd->cfg.mode, iocmd->cfg.max_pf,
854 iocmd->cfg.max_vf, bfad_hcb_comp, &fcomp);
855 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
856 if (iocmd->status != BFA_STATUS_OK)
857 goto out;
858
859 wait_for_completion(&fcomp.comp);
860 iocmd->status = fcomp.status;
861out:
862 return 0;
863}
864
865int
866bfad_iocmd_port_cfg_mode(struct bfad_s *bfad, void *cmd)
867{
868 struct bfa_bsg_port_cfg_mode_s *iocmd =
869 (struct bfa_bsg_port_cfg_mode_s *)cmd;
870 struct bfad_hal_comp fcomp;
871 unsigned long flags = 0;
872
873 init_completion(&fcomp.comp);
874 spin_lock_irqsave(&bfad->bfad_lock, flags);
875 iocmd->status = bfa_ablk_port_config(&bfad->bfa.modules.ablk,
876 iocmd->instance, iocmd->cfg.mode,
877 iocmd->cfg.max_pf, iocmd->cfg.max_vf,
878 bfad_hcb_comp, &fcomp);
879 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
880 if (iocmd->status != BFA_STATUS_OK)
881 goto out;
882
883 wait_for_completion(&fcomp.comp);
884 iocmd->status = fcomp.status;
885out:
886 return 0;
887}
888
889int
890bfad_iocmd_ablk_optrom(struct bfad_s *bfad, unsigned int cmd, void *pcmd)
891{
892 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)pcmd;
893 struct bfad_hal_comp fcomp;
894 unsigned long flags;
895
896 init_completion(&fcomp.comp);
897 spin_lock_irqsave(&bfad->bfad_lock, flags);
898 if (cmd == IOCMD_FLASH_ENABLE_OPTROM)
899 iocmd->status = bfa_ablk_optrom_en(&bfad->bfa.modules.ablk,
900 bfad_hcb_comp, &fcomp);
901 else
902 iocmd->status = bfa_ablk_optrom_dis(&bfad->bfa.modules.ablk,
903 bfad_hcb_comp, &fcomp);
904 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
905
906 if (iocmd->status != BFA_STATUS_OK)
907 goto out;
908
909 wait_for_completion(&fcomp.comp);
910 iocmd->status = fcomp.status;
911out:
912 return 0;
913}
914
Krishna Gudipatia7141342011-06-24 20:23:19 -0700915int
916bfad_iocmd_faa_enable(struct bfad_s *bfad, void *cmd)
917{
918 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
919 unsigned long flags;
920 struct bfad_hal_comp fcomp;
921
922 init_completion(&fcomp.comp);
923 iocmd->status = BFA_STATUS_OK;
924 spin_lock_irqsave(&bfad->bfad_lock, flags);
925 iocmd->status = bfa_faa_enable(&bfad->bfa, bfad_hcb_comp, &fcomp);
926 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
927
928 if (iocmd->status != BFA_STATUS_OK)
929 goto out;
930
931 wait_for_completion(&fcomp.comp);
932 iocmd->status = fcomp.status;
933out:
934 return 0;
935}
936
937int
938bfad_iocmd_faa_disable(struct bfad_s *bfad, void *cmd)
939{
940 struct bfa_bsg_gen_s *iocmd = (struct bfa_bsg_gen_s *)cmd;
941 unsigned long flags;
942 struct bfad_hal_comp fcomp;
943
944 init_completion(&fcomp.comp);
945 iocmd->status = BFA_STATUS_OK;
946 spin_lock_irqsave(&bfad->bfad_lock, flags);
947 iocmd->status = bfa_faa_disable(&bfad->bfa, bfad_hcb_comp, &fcomp);
948 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
949
950 if (iocmd->status != BFA_STATUS_OK)
951 goto out;
952
953 wait_for_completion(&fcomp.comp);
954 iocmd->status = fcomp.status;
955out:
956 return 0;
957}
958
959int
960bfad_iocmd_faa_query(struct bfad_s *bfad, void *cmd)
961{
962 struct bfa_bsg_faa_attr_s *iocmd = (struct bfa_bsg_faa_attr_s *)cmd;
963 struct bfad_hal_comp fcomp;
964 unsigned long flags;
965
966 init_completion(&fcomp.comp);
967 iocmd->status = BFA_STATUS_OK;
968 spin_lock_irqsave(&bfad->bfad_lock, flags);
969 iocmd->status = bfa_faa_query(&bfad->bfa, &iocmd->faa_attr,
970 bfad_hcb_comp, &fcomp);
971 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
972
973 if (iocmd->status != BFA_STATUS_OK)
974 goto out;
975
976 wait_for_completion(&fcomp.comp);
977 iocmd->status = fcomp.status;
978out:
979 return 0;
980}
981
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700982static int
983bfad_iocmd_handler(struct bfad_s *bfad, unsigned int cmd, void *iocmd,
984 unsigned int payload_len)
985{
986 int rc = EINVAL;
987
988 switch (cmd) {
Krishna Gudipati60138062011-06-24 20:25:15 -0700989 case IOCMD_IOC_ENABLE:
990 rc = bfad_iocmd_ioc_enable(bfad, iocmd);
991 break;
992 case IOCMD_IOC_DISABLE:
993 rc = bfad_iocmd_ioc_disable(bfad, iocmd);
994 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -0700995 case IOCMD_IOC_GET_INFO:
996 rc = bfad_iocmd_ioc_get_info(bfad, iocmd);
997 break;
998 case IOCMD_IOC_GET_ATTR:
999 rc = bfad_iocmd_ioc_get_attr(bfad, iocmd);
1000 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07001001 case IOCMD_IOC_GET_STATS:
1002 rc = bfad_iocmd_ioc_get_stats(bfad, iocmd);
1003 break;
1004 case IOCMD_IOC_GET_FWSTATS:
1005 rc = bfad_iocmd_ioc_get_fwstats(bfad, iocmd, payload_len);
1006 break;
1007 case IOCMD_IOCFC_GET_ATTR:
1008 rc = bfad_iocmd_iocfc_get_attr(bfad, iocmd);
1009 break;
1010 case IOCMD_IOCFC_SET_INTR:
1011 rc = bfad_iocmd_iocfc_set_intr(bfad, iocmd);
1012 break;
1013 case IOCMD_PORT_ENABLE:
1014 rc = bfad_iocmd_port_enable(bfad, iocmd);
1015 break;
1016 case IOCMD_PORT_DISABLE:
1017 rc = bfad_iocmd_port_disable(bfad, iocmd);
1018 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001019 case IOCMD_PORT_GET_ATTR:
1020 rc = bfad_iocmd_port_get_attr(bfad, iocmd);
1021 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07001022 case IOCMD_PORT_GET_STATS:
1023 rc = bfad_iocmd_port_get_stats(bfad, iocmd, payload_len);
1024 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001025 case IOCMD_LPORT_GET_ATTR:
1026 rc = bfad_iocmd_lport_get_attr(bfad, iocmd);
1027 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07001028 case IOCMD_LPORT_GET_STATS:
1029 rc = bfad_iocmd_lport_get_stats(bfad, iocmd);
1030 break;
1031 case IOCMD_LPORT_GET_IOSTATS:
1032 rc = bfad_iocmd_lport_get_iostats(bfad, iocmd);
1033 break;
1034 case IOCMD_LPORT_GET_RPORTS:
1035 rc = bfad_iocmd_lport_get_rports(bfad, iocmd, payload_len);
1036 break;
1037 case IOCMD_RPORT_GET_ATTR:
1038 rc = bfad_iocmd_rport_get_attr(bfad, iocmd);
1039 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001040 case IOCMD_RPORT_GET_ADDR:
1041 rc = bfad_iocmd_rport_get_addr(bfad, iocmd);
1042 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07001043 case IOCMD_RPORT_GET_STATS:
1044 rc = bfad_iocmd_rport_get_stats(bfad, iocmd);
1045 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001046 case IOCMD_FABRIC_GET_LPORTS:
1047 rc = bfad_iocmd_fabric_get_lports(bfad, iocmd, payload_len);
1048 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07001049 case IOCMD_FCPIM_MODSTATS:
1050 rc = bfad_iocmd_fcpim_get_modstats(bfad, iocmd);
1051 break;
1052 case IOCMD_FCPIM_DEL_ITN_STATS:
1053 rc = bfad_iocmd_fcpim_get_del_itn_stats(bfad, iocmd);
1054 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001055 case IOCMD_ITNIM_GET_ATTR:
1056 rc = bfad_iocmd_itnim_get_attr(bfad, iocmd);
1057 break;
Krishna Gudipati60138062011-06-24 20:25:15 -07001058 case IOCMD_ITNIM_GET_IOSTATS:
1059 rc = bfad_iocmd_itnim_get_iostats(bfad, iocmd);
1060 break;
1061 case IOCMD_ITNIM_GET_ITNSTATS:
1062 rc = bfad_iocmd_itnim_get_itnstats(bfad, iocmd);
1063 break;
1064 case IOCMD_FCPORT_ENABLE:
1065 rc = bfad_iocmd_fcport_enable(bfad, iocmd);
1066 break;
1067 case IOCMD_FCPORT_DISABLE:
1068 rc = bfad_iocmd_fcport_disable(bfad, iocmd);
1069 break;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07001070 case IOCMD_IOC_PCIFN_CFG:
1071 rc = bfad_iocmd_ioc_get_pcifn_cfg(bfad, iocmd);
1072 break;
1073 case IOCMD_PCIFN_CREATE:
1074 rc = bfad_iocmd_pcifn_create(bfad, iocmd);
1075 break;
1076 case IOCMD_PCIFN_DELETE:
1077 rc = bfad_iocmd_pcifn_delete(bfad, iocmd);
1078 break;
1079 case IOCMD_PCIFN_BW:
1080 rc = bfad_iocmd_pcifn_bw(bfad, iocmd);
1081 break;
1082 case IOCMD_ADAPTER_CFG_MODE:
1083 rc = bfad_iocmd_adapter_cfg_mode(bfad, iocmd);
1084 break;
1085 case IOCMD_PORT_CFG_MODE:
1086 rc = bfad_iocmd_port_cfg_mode(bfad, iocmd);
1087 break;
1088 case IOCMD_FLASH_ENABLE_OPTROM:
1089 case IOCMD_FLASH_DISABLE_OPTROM:
1090 rc = bfad_iocmd_ablk_optrom(bfad, cmd, iocmd);
1091 break;
Krishna Gudipatia7141342011-06-24 20:23:19 -07001092 case IOCMD_FAA_ENABLE:
1093 rc = bfad_iocmd_faa_enable(bfad, iocmd);
1094 break;
1095 case IOCMD_FAA_DISABLE:
1096 rc = bfad_iocmd_faa_disable(bfad, iocmd);
1097 break;
1098 case IOCMD_FAA_QUERY:
1099 rc = bfad_iocmd_faa_query(bfad, iocmd);
1100 break;
Krishna Gudipatib85daaf2011-06-13 15:55:11 -07001101 default:
1102 rc = EINVAL;
1103 break;
1104 }
1105 return -rc;
1106}
1107
1108static int
1109bfad_im_bsg_vendor_request(struct fc_bsg_job *job)
1110{
1111 uint32_t vendor_cmd = job->request->rqst_data.h_vendor.vendor_cmd[0];
1112 struct bfad_im_port_s *im_port =
1113 (struct bfad_im_port_s *) job->shost->hostdata[0];
1114 struct bfad_s *bfad = im_port->bfad;
1115 void *payload_kbuf;
1116 int rc = -EINVAL;
1117
1118 /* Allocate a temp buffer to hold the passed in user space command */
1119 payload_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
1120 if (!payload_kbuf) {
1121 rc = -ENOMEM;
1122 goto out;
1123 }
1124
1125 /* Copy the sg_list passed in to a linear buffer: holds the cmnd data */
1126 sg_copy_to_buffer(job->request_payload.sg_list,
1127 job->request_payload.sg_cnt, payload_kbuf,
1128 job->request_payload.payload_len);
1129
1130 /* Invoke IOCMD handler - to handle all the vendor command requests */
1131 rc = bfad_iocmd_handler(bfad, vendor_cmd, payload_kbuf,
1132 job->request_payload.payload_len);
1133 if (rc != BFA_STATUS_OK)
1134 goto error;
1135
1136 /* Copy the response data to the job->reply_payload sg_list */
1137 sg_copy_from_buffer(job->reply_payload.sg_list,
1138 job->reply_payload.sg_cnt,
1139 payload_kbuf,
1140 job->reply_payload.payload_len);
1141
1142 /* free the command buffer */
1143 kfree(payload_kbuf);
1144
1145 /* Fill the BSG job reply data */
1146 job->reply_len = job->reply_payload.payload_len;
1147 job->reply->reply_payload_rcv_len = job->reply_payload.payload_len;
1148 job->reply->result = rc;
1149
1150 job->job_done(job);
1151 return rc;
1152error:
1153 /* free the command buffer */
1154 kfree(payload_kbuf);
1155out:
1156 job->reply->result = rc;
1157 job->reply_len = sizeof(uint32_t);
1158 job->reply->reply_payload_rcv_len = 0;
1159 return rc;
1160}
1161
1162/* FC passthru call backs */
1163u64
1164bfad_fcxp_get_req_sgaddr_cb(void *bfad_fcxp, int sgeid)
1165{
1166 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
1167 struct bfa_sge_s *sge;
1168 u64 addr;
1169
1170 sge = drv_fcxp->req_sge + sgeid;
1171 addr = (u64)(size_t) sge->sg_addr;
1172 return addr;
1173}
1174
1175u32
1176bfad_fcxp_get_req_sglen_cb(void *bfad_fcxp, int sgeid)
1177{
1178 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
1179 struct bfa_sge_s *sge;
1180
1181 sge = drv_fcxp->req_sge + sgeid;
1182 return sge->sg_len;
1183}
1184
1185u64
1186bfad_fcxp_get_rsp_sgaddr_cb(void *bfad_fcxp, int sgeid)
1187{
1188 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
1189 struct bfa_sge_s *sge;
1190 u64 addr;
1191
1192 sge = drv_fcxp->rsp_sge + sgeid;
1193 addr = (u64)(size_t) sge->sg_addr;
1194 return addr;
1195}
1196
1197u32
1198bfad_fcxp_get_rsp_sglen_cb(void *bfad_fcxp, int sgeid)
1199{
1200 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
1201 struct bfa_sge_s *sge;
1202
1203 sge = drv_fcxp->rsp_sge + sgeid;
1204 return sge->sg_len;
1205}
1206
1207void
1208bfad_send_fcpt_cb(void *bfad_fcxp, struct bfa_fcxp_s *fcxp, void *cbarg,
1209 bfa_status_t req_status, u32 rsp_len, u32 resid_len,
1210 struct fchs_s *rsp_fchs)
1211{
1212 struct bfad_fcxp *drv_fcxp = bfad_fcxp;
1213
1214 drv_fcxp->req_status = req_status;
1215 drv_fcxp->rsp_len = rsp_len;
1216
1217 /* bfa_fcxp will be automatically freed by BFA */
1218 drv_fcxp->bfa_fcxp = NULL;
1219 complete(&drv_fcxp->comp);
1220}
1221
1222struct bfad_buf_info *
1223bfad_fcxp_map_sg(struct bfad_s *bfad, void *payload_kbuf,
1224 uint32_t payload_len, uint32_t *num_sgles)
1225{
1226 struct bfad_buf_info *buf_base, *buf_info;
1227 struct bfa_sge_s *sg_table;
1228 int sge_num = 1;
1229
1230 buf_base = kzalloc((sizeof(struct bfad_buf_info) +
1231 sizeof(struct bfa_sge_s)) * sge_num, GFP_KERNEL);
1232 if (!buf_base)
1233 return NULL;
1234
1235 sg_table = (struct bfa_sge_s *) (((uint8_t *)buf_base) +
1236 (sizeof(struct bfad_buf_info) * sge_num));
1237
1238 /* Allocate dma coherent memory */
1239 buf_info = buf_base;
1240 buf_info->size = payload_len;
1241 buf_info->virt = dma_alloc_coherent(&bfad->pcidev->dev, buf_info->size,
1242 &buf_info->phys, GFP_KERNEL);
1243 if (!buf_info->virt)
1244 goto out_free_mem;
1245
1246 /* copy the linear bsg buffer to buf_info */
1247 memset(buf_info->virt, 0, buf_info->size);
1248 memcpy(buf_info->virt, payload_kbuf, buf_info->size);
1249
1250 /*
1251 * Setup SG table
1252 */
1253 sg_table->sg_len = buf_info->size;
1254 sg_table->sg_addr = (void *)(size_t) buf_info->phys;
1255
1256 *num_sgles = sge_num;
1257
1258 return buf_base;
1259
1260out_free_mem:
1261 kfree(buf_base);
1262 return NULL;
1263}
1264
1265void
1266bfad_fcxp_free_mem(struct bfad_s *bfad, struct bfad_buf_info *buf_base,
1267 uint32_t num_sgles)
1268{
1269 int i;
1270 struct bfad_buf_info *buf_info = buf_base;
1271
1272 if (buf_base) {
1273 for (i = 0; i < num_sgles; buf_info++, i++) {
1274 if (buf_info->virt != NULL)
1275 dma_free_coherent(&bfad->pcidev->dev,
1276 buf_info->size, buf_info->virt,
1277 buf_info->phys);
1278 }
1279 kfree(buf_base);
1280 }
1281}
1282
1283int
1284bfad_fcxp_bsg_send(struct fc_bsg_job *job, struct bfad_fcxp *drv_fcxp,
1285 bfa_bsg_fcpt_t *bsg_fcpt)
1286{
1287 struct bfa_fcxp_s *hal_fcxp;
1288 struct bfad_s *bfad = drv_fcxp->port->bfad;
1289 unsigned long flags;
1290 uint8_t lp_tag;
1291
1292 spin_lock_irqsave(&bfad->bfad_lock, flags);
1293
1294 /* Allocate bfa_fcxp structure */
1295 hal_fcxp = bfa_fcxp_alloc(drv_fcxp, &bfad->bfa,
1296 drv_fcxp->num_req_sgles,
1297 drv_fcxp->num_rsp_sgles,
1298 bfad_fcxp_get_req_sgaddr_cb,
1299 bfad_fcxp_get_req_sglen_cb,
1300 bfad_fcxp_get_rsp_sgaddr_cb,
1301 bfad_fcxp_get_rsp_sglen_cb);
1302 if (!hal_fcxp) {
1303 bfa_trc(bfad, 0);
1304 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1305 return BFA_STATUS_ENOMEM;
1306 }
1307
1308 drv_fcxp->bfa_fcxp = hal_fcxp;
1309
1310 lp_tag = bfa_lps_get_tag_from_pid(&bfad->bfa, bsg_fcpt->fchs.s_id);
1311
1312 bfa_fcxp_send(hal_fcxp, drv_fcxp->bfa_rport, bsg_fcpt->vf_id, lp_tag,
1313 bsg_fcpt->cts, bsg_fcpt->cos,
1314 job->request_payload.payload_len,
1315 &bsg_fcpt->fchs, bfad_send_fcpt_cb, bfad,
1316 job->reply_payload.payload_len, bsg_fcpt->tsecs);
1317
1318 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1319
1320 return BFA_STATUS_OK;
1321}
1322
1323int
1324bfad_im_bsg_els_ct_request(struct fc_bsg_job *job)
1325{
1326 struct bfa_bsg_data *bsg_data;
1327 struct bfad_im_port_s *im_port =
1328 (struct bfad_im_port_s *) job->shost->hostdata[0];
1329 struct bfad_s *bfad = im_port->bfad;
1330 bfa_bsg_fcpt_t *bsg_fcpt;
1331 struct bfad_fcxp *drv_fcxp;
1332 struct bfa_fcs_lport_s *fcs_port;
1333 struct bfa_fcs_rport_s *fcs_rport;
1334 uint32_t command_type = job->request->msgcode;
1335 unsigned long flags;
1336 struct bfad_buf_info *rsp_buf_info;
1337 void *req_kbuf = NULL, *rsp_kbuf = NULL;
1338 int rc = -EINVAL;
1339
1340 job->reply_len = sizeof(uint32_t); /* Atleast uint32_t reply_len */
1341 job->reply->reply_payload_rcv_len = 0;
1342
1343 /* Get the payload passed in from userspace */
1344 bsg_data = (struct bfa_bsg_data *) (((char *)job->request) +
1345 sizeof(struct fc_bsg_request));
1346 if (bsg_data == NULL)
1347 goto out;
1348
1349 /*
1350 * Allocate buffer for bsg_fcpt and do a copy_from_user op for payload
1351 * buffer of size bsg_data->payload_len
1352 */
1353 bsg_fcpt = (struct bfa_bsg_fcpt_s *)
1354 kzalloc(bsg_data->payload_len, GFP_KERNEL);
1355 if (!bsg_fcpt)
1356 goto out;
1357
1358 if (copy_from_user((uint8_t *)bsg_fcpt, bsg_data->payload,
1359 bsg_data->payload_len)) {
1360 kfree(bsg_fcpt);
1361 goto out;
1362 }
1363
1364 drv_fcxp = kzalloc(sizeof(struct bfad_fcxp), GFP_KERNEL);
1365 if (drv_fcxp == NULL) {
1366 rc = -ENOMEM;
1367 goto out;
1368 }
1369
1370 spin_lock_irqsave(&bfad->bfad_lock, flags);
1371 fcs_port = bfa_fcs_lookup_port(&bfad->bfa_fcs, bsg_fcpt->vf_id,
1372 bsg_fcpt->lpwwn);
1373 if (fcs_port == NULL) {
1374 bsg_fcpt->status = BFA_STATUS_UNKNOWN_LWWN;
1375 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1376 goto out_free_mem;
1377 }
1378
1379 /* Check if the port is online before sending FC Passthru cmd */
1380 if (!bfa_fcs_lport_is_online(fcs_port)) {
1381 bsg_fcpt->status = BFA_STATUS_PORT_OFFLINE;
1382 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1383 goto out_free_mem;
1384 }
1385
1386 drv_fcxp->port = fcs_port->bfad_port;
1387
1388 if (drv_fcxp->port->bfad == 0)
1389 drv_fcxp->port->bfad = bfad;
1390
1391 /* Fetch the bfa_rport - if nexus needed */
1392 if (command_type == FC_BSG_HST_ELS_NOLOGIN ||
1393 command_type == FC_BSG_HST_CT) {
1394 /* BSG HST commands: no nexus needed */
1395 drv_fcxp->bfa_rport = NULL;
1396
1397 } else if (command_type == FC_BSG_RPT_ELS ||
1398 command_type == FC_BSG_RPT_CT) {
1399 /* BSG RPT commands: nexus needed */
1400 fcs_rport = bfa_fcs_lport_get_rport_by_pwwn(fcs_port,
1401 bsg_fcpt->dpwwn);
1402 if (fcs_rport == NULL) {
1403 bsg_fcpt->status = BFA_STATUS_UNKNOWN_RWWN;
1404 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1405 goto out_free_mem;
1406 }
1407
1408 drv_fcxp->bfa_rport = fcs_rport->bfa_rport;
1409
1410 } else { /* Unknown BSG msgcode; return -EINVAL */
1411 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1412 goto out_free_mem;
1413 }
1414
1415 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
1416
1417 /* allocate memory for req / rsp buffers */
1418 req_kbuf = kzalloc(job->request_payload.payload_len, GFP_KERNEL);
1419 if (!req_kbuf) {
1420 printk(KERN_INFO "bfa %s: fcpt request buffer alloc failed\n",
1421 bfad->pci_name);
1422 rc = -ENOMEM;
1423 goto out_free_mem;
1424 }
1425
1426 rsp_kbuf = kzalloc(job->reply_payload.payload_len, GFP_KERNEL);
1427 if (!rsp_kbuf) {
1428 printk(KERN_INFO "bfa %s: fcpt response buffer alloc failed\n",
1429 bfad->pci_name);
1430 rc = -ENOMEM;
1431 goto out_free_mem;
1432 }
1433
1434 /* map req sg - copy the sg_list passed in to the linear buffer */
1435 sg_copy_to_buffer(job->request_payload.sg_list,
1436 job->request_payload.sg_cnt, req_kbuf,
1437 job->request_payload.payload_len);
1438
1439 drv_fcxp->reqbuf_info = bfad_fcxp_map_sg(bfad, req_kbuf,
1440 job->request_payload.payload_len,
1441 &drv_fcxp->num_req_sgles);
1442 if (!drv_fcxp->reqbuf_info) {
1443 printk(KERN_INFO "bfa %s: fcpt request fcxp_map_sg failed\n",
1444 bfad->pci_name);
1445 rc = -ENOMEM;
1446 goto out_free_mem;
1447 }
1448
1449 drv_fcxp->req_sge = (struct bfa_sge_s *)
1450 (((uint8_t *)drv_fcxp->reqbuf_info) +
1451 (sizeof(struct bfad_buf_info) *
1452 drv_fcxp->num_req_sgles));
1453
1454 /* map rsp sg */
1455 drv_fcxp->rspbuf_info = bfad_fcxp_map_sg(bfad, rsp_kbuf,
1456 job->reply_payload.payload_len,
1457 &drv_fcxp->num_rsp_sgles);
1458 if (!drv_fcxp->rspbuf_info) {
1459 printk(KERN_INFO "bfa %s: fcpt response fcxp_map_sg failed\n",
1460 bfad->pci_name);
1461 rc = -ENOMEM;
1462 goto out_free_mem;
1463 }
1464
1465 rsp_buf_info = (struct bfad_buf_info *)drv_fcxp->rspbuf_info;
1466 drv_fcxp->rsp_sge = (struct bfa_sge_s *)
1467 (((uint8_t *)drv_fcxp->rspbuf_info) +
1468 (sizeof(struct bfad_buf_info) *
1469 drv_fcxp->num_rsp_sgles));
1470
1471 /* fcxp send */
1472 init_completion(&drv_fcxp->comp);
1473 rc = bfad_fcxp_bsg_send(job, drv_fcxp, bsg_fcpt);
1474 if (rc == BFA_STATUS_OK) {
1475 wait_for_completion(&drv_fcxp->comp);
1476 bsg_fcpt->status = drv_fcxp->req_status;
1477 } else {
1478 bsg_fcpt->status = rc;
1479 goto out_free_mem;
1480 }
1481
1482 /* fill the job->reply data */
1483 if (drv_fcxp->req_status == BFA_STATUS_OK) {
1484 job->reply_len = drv_fcxp->rsp_len;
1485 job->reply->reply_payload_rcv_len = drv_fcxp->rsp_len;
1486 job->reply->reply_data.ctels_reply.status = FC_CTELS_STATUS_OK;
1487 } else {
1488 job->reply->reply_payload_rcv_len =
1489 sizeof(struct fc_bsg_ctels_reply);
1490 job->reply_len = sizeof(uint32_t);
1491 job->reply->reply_data.ctels_reply.status =
1492 FC_CTELS_STATUS_REJECT;
1493 }
1494
1495 /* Copy the response data to the reply_payload sg list */
1496 sg_copy_from_buffer(job->reply_payload.sg_list,
1497 job->reply_payload.sg_cnt,
1498 (uint8_t *)rsp_buf_info->virt,
1499 job->reply_payload.payload_len);
1500
1501out_free_mem:
1502 bfad_fcxp_free_mem(bfad, drv_fcxp->rspbuf_info,
1503 drv_fcxp->num_rsp_sgles);
1504 bfad_fcxp_free_mem(bfad, drv_fcxp->reqbuf_info,
1505 drv_fcxp->num_req_sgles);
1506 kfree(req_kbuf);
1507 kfree(rsp_kbuf);
1508
1509 /* Need a copy to user op */
1510 if (copy_to_user(bsg_data->payload, (void *) bsg_fcpt,
1511 bsg_data->payload_len))
1512 rc = -EIO;
1513
1514 kfree(bsg_fcpt);
1515 kfree(drv_fcxp);
1516out:
1517 job->reply->result = rc;
1518
1519 if (rc == BFA_STATUS_OK)
1520 job->job_done(job);
1521
1522 return rc;
1523}
1524
1525int
1526bfad_im_bsg_request(struct fc_bsg_job *job)
1527{
1528 uint32_t rc = BFA_STATUS_OK;
1529
1530 /* Increment the bfa module refcnt - if bsg request is in service */
1531 bfad_im_bsg_get_kobject(job);
1532
1533 switch (job->request->msgcode) {
1534 case FC_BSG_HST_VENDOR:
1535 /* Process BSG HST Vendor requests */
1536 rc = bfad_im_bsg_vendor_request(job);
1537 break;
1538 case FC_BSG_HST_ELS_NOLOGIN:
1539 case FC_BSG_RPT_ELS:
1540 case FC_BSG_HST_CT:
1541 case FC_BSG_RPT_CT:
1542 /* Process BSG ELS/CT commands */
1543 rc = bfad_im_bsg_els_ct_request(job);
1544 break;
1545 default:
1546 job->reply->result = rc = -EINVAL;
1547 job->reply->reply_payload_rcv_len = 0;
1548 break;
1549 }
1550
1551 /* Decrement the bfa module refcnt - on completion of bsg request */
1552 bfad_im_bsg_put_kobject(job);
1553
1554 return rc;
1555}
1556
1557int
1558bfad_im_bsg_timeout(struct fc_bsg_job *job)
1559{
1560 /* Don't complete the BSG job request - return -EAGAIN
1561 * to reset bsg job timeout : for ELS/CT pass thru we
1562 * already have timer to track the request.
1563 */
1564 return -EAGAIN;
1565}