2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
19 * bfad.c Linux driver PCI interface module.
21 #include <linux/module.h>
22 #include <linux/kthread.h>
23 #include <linux/errno.h>
24 #include <linux/sched.h>
25 #include <linux/init.h>
27 #include <linux/pci.h>
28 #include <linux/firmware.h>
29 #include <asm/uaccess.h>
30 #include <asm/fcntl.h>
38 BFA_TRC_FILE(LDRV
, BFAD
);
39 DEFINE_MUTEX(bfad_mutex
);
43 static int num_sgpgs_parm
;
45 char *host_name
, *os_name
, *os_patch
;
46 int num_rports
, num_ios
, num_tms
;
47 int num_fcxps
, num_ufbufs
;
48 int reqq_size
, rspq_size
, num_sgpgs
;
49 int rport_del_timeout
= BFA_FCS_RPORT_DEF_DEL_TIMEOUT
;
50 int bfa_lun_queue_depth
= BFAD_LUN_QUEUE_DEPTH
;
51 int bfa_io_max_sge
= BFAD_IO_MAX_SGE
;
52 int bfa_log_level
= 3; /* WARNING log level */
53 int ioc_auto_recover
= BFA_TRUE
;
54 int bfa_linkup_delay
= -1;
55 int fdmi_enable
= BFA_TRUE
;
56 int pcie_max_read_reqsz
;
57 int bfa_debugfs_enable
= 1;
58 int msix_disable_cb
= 0, msix_disable_ct
= 0;
59 int max_xfer_size
= BFAD_MAX_SECTORS
>> 1;
61 /* Firmware releated */
62 u32 bfi_image_cb_size
, bfi_image_ct_size
, bfi_image_ct2_size
;
63 u32
*bfi_image_cb
, *bfi_image_ct
, *bfi_image_ct2
;
65 #define BFAD_FW_FILE_CB "cbfw.bin"
66 #define BFAD_FW_FILE_CT "ctfw.bin"
67 #define BFAD_FW_FILE_CT2 "ct2fw.bin"
69 static u32
*bfad_load_fwimg(struct pci_dev
*pdev
);
70 static void bfad_free_fwimg(void);
71 static void bfad_read_firmware(struct pci_dev
*pdev
, u32
**bfi_image
,
72 u32
*bfi_image_size
, char *fw_name
);
74 static const char *msix_name_ct
[] = {
76 "cpe0", "cpe1", "cpe2", "cpe3",
77 "rme0", "rme1", "rme2", "rme3" };
79 static const char *msix_name_cb
[] = {
80 "cpe0", "cpe1", "cpe2", "cpe3",
81 "rme0", "rme1", "rme2", "rme3",
82 "eemc", "elpu0", "elpu1", "epss", "mlpu" };
84 MODULE_FIRMWARE(BFAD_FW_FILE_CB
);
85 MODULE_FIRMWARE(BFAD_FW_FILE_CT
);
86 MODULE_FIRMWARE(BFAD_FW_FILE_CT2
);
88 module_param(os_name
, charp
, S_IRUGO
| S_IWUSR
);
89 MODULE_PARM_DESC(os_name
, "OS name of the hba host machine");
90 module_param(os_patch
, charp
, S_IRUGO
| S_IWUSR
);
91 MODULE_PARM_DESC(os_patch
, "OS patch level of the hba host machine");
92 module_param(host_name
, charp
, S_IRUGO
| S_IWUSR
);
93 MODULE_PARM_DESC(host_name
, "Hostname of the hba host machine");
94 module_param(num_rports
, int, S_IRUGO
| S_IWUSR
);
95 MODULE_PARM_DESC(num_rports
, "Max number of rports supported per port "
96 "(physical/logical), default=1024");
97 module_param(num_ios
, int, S_IRUGO
| S_IWUSR
);
98 MODULE_PARM_DESC(num_ios
, "Max number of ioim requests, default=2000");
99 module_param(num_tms
, int, S_IRUGO
| S_IWUSR
);
100 MODULE_PARM_DESC(num_tms
, "Max number of task im requests, default=128");
101 module_param(num_fcxps
, int, S_IRUGO
| S_IWUSR
);
102 MODULE_PARM_DESC(num_fcxps
, "Max number of fcxp requests, default=64");
103 module_param(num_ufbufs
, int, S_IRUGO
| S_IWUSR
);
104 MODULE_PARM_DESC(num_ufbufs
, "Max number of unsolicited frame "
105 "buffers, default=64");
106 module_param(reqq_size
, int, S_IRUGO
| S_IWUSR
);
107 MODULE_PARM_DESC(reqq_size
, "Max number of request queue elements, "
109 module_param(rspq_size
, int, S_IRUGO
| S_IWUSR
);
110 MODULE_PARM_DESC(rspq_size
, "Max number of response queue elements, "
112 module_param(num_sgpgs
, int, S_IRUGO
| S_IWUSR
);
113 MODULE_PARM_DESC(num_sgpgs
, "Number of scatter/gather pages, default=2048");
114 module_param(rport_del_timeout
, int, S_IRUGO
| S_IWUSR
);
115 MODULE_PARM_DESC(rport_del_timeout
, "Rport delete timeout, default=90 secs, "
117 module_param(bfa_lun_queue_depth
, int, S_IRUGO
| S_IWUSR
);
118 MODULE_PARM_DESC(bfa_lun_queue_depth
, "Lun queue depth, default=32, Range[>0]");
119 module_param(bfa_io_max_sge
, int, S_IRUGO
| S_IWUSR
);
120 MODULE_PARM_DESC(bfa_io_max_sge
, "Max io scatter/gather elements, default=255");
121 module_param(bfa_log_level
, int, S_IRUGO
| S_IWUSR
);
122 MODULE_PARM_DESC(bfa_log_level
, "Driver log level, default=3, "
123 "Range[Critical:1|Error:2|Warning:3|Info:4]");
124 module_param(ioc_auto_recover
, int, S_IRUGO
| S_IWUSR
);
125 MODULE_PARM_DESC(ioc_auto_recover
, "IOC auto recovery, default=1, "
126 "Range[off:0|on:1]");
127 module_param(bfa_linkup_delay
, int, S_IRUGO
| S_IWUSR
);
128 MODULE_PARM_DESC(bfa_linkup_delay
, "Link up delay, default=30 secs for "
129 "boot port. Otherwise 10 secs in RHEL4 & 0 for "
130 "[RHEL5, SLES10, ESX40] Range[>0]");
131 module_param(msix_disable_cb
, int, S_IRUGO
| S_IWUSR
);
132 MODULE_PARM_DESC(msix_disable_cb
, "Disable Message Signaled Interrupts "
133 "for Brocade-415/425/815/825 cards, default=0, "
134 " Range[false:0|true:1]");
135 module_param(msix_disable_ct
, int, S_IRUGO
| S_IWUSR
);
136 MODULE_PARM_DESC(msix_disable_ct
, "Disable Message Signaled Interrupts "
137 "if possible for Brocade-1010/1020/804/1007/902/1741 "
138 "cards, default=0, Range[false:0|true:1]");
139 module_param(fdmi_enable
, int, S_IRUGO
| S_IWUSR
);
140 MODULE_PARM_DESC(fdmi_enable
, "Enables fdmi registration, default=1, "
141 "Range[false:0|true:1]");
142 module_param(pcie_max_read_reqsz
, int, S_IRUGO
| S_IWUSR
);
143 MODULE_PARM_DESC(pcie_max_read_reqsz
, "PCIe max read request size, default=0 "
144 "(use system setting), Range[128|256|512|1024|2048|4096]");
145 module_param(bfa_debugfs_enable
, int, S_IRUGO
| S_IWUSR
);
146 MODULE_PARM_DESC(bfa_debugfs_enable
, "Enables debugfs feature, default=1,"
147 " Range[false:0|true:1]");
148 module_param(max_xfer_size
, int, S_IRUGO
| S_IWUSR
);
149 MODULE_PARM_DESC(max_xfer_size
, "default=32MB,"
150 " Range[64k|128k|256k|512k|1024k|2048k]");
153 bfad_sm_uninit(struct bfad_s
*bfad
, enum bfad_sm_event event
);
155 bfad_sm_created(struct bfad_s
*bfad
, enum bfad_sm_event event
);
157 bfad_sm_initializing(struct bfad_s
*bfad
, enum bfad_sm_event event
);
159 bfad_sm_operational(struct bfad_s
*bfad
, enum bfad_sm_event event
);
161 bfad_sm_stopping(struct bfad_s
*bfad
, enum bfad_sm_event event
);
163 bfad_sm_failed(struct bfad_s
*bfad
, enum bfad_sm_event event
);
165 bfad_sm_fcs_exit(struct bfad_s
*bfad
, enum bfad_sm_event event
);
168 * Beginning state for the driver instance, awaiting the pci_probe event
171 bfad_sm_uninit(struct bfad_s
*bfad
, enum bfad_sm_event event
)
173 bfa_trc(bfad
, event
);
177 bfa_sm_set_state(bfad
, bfad_sm_created
);
178 bfad
->bfad_tsk
= kthread_create(bfad_worker
, (void *) bfad
,
179 "%s", "bfad_worker");
180 if (IS_ERR(bfad
->bfad_tsk
)) {
181 printk(KERN_INFO
"bfad[%d]: Kernel thread "
182 "creation failed!\n", bfad
->inst_no
);
183 bfa_sm_send_event(bfad
, BFAD_E_KTHREAD_CREATE_FAILED
);
185 bfa_sm_send_event(bfad
, BFAD_E_INIT
);
189 /* Ignore stop; already in uninit */
193 bfa_sm_fault(bfad
, event
);
198 * Driver Instance is created, awaiting event INIT to initialize the bfad
201 bfad_sm_created(struct bfad_s
*bfad
, enum bfad_sm_event event
)
205 bfa_trc(bfad
, event
);
209 bfa_sm_set_state(bfad
, bfad_sm_initializing
);
211 init_completion(&bfad
->comp
);
213 /* Enable Interrupt and wait bfa_init completion */
214 if (bfad_setup_intr(bfad
)) {
215 printk(KERN_WARNING
"bfad%d: bfad_setup_intr failed\n",
217 bfa_sm_send_event(bfad
, BFAD_E_INTR_INIT_FAILED
);
221 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
222 bfa_iocfc_init(&bfad
->bfa
);
223 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
225 /* Set up interrupt handler for each vectors */
226 if ((bfad
->bfad_flags
& BFAD_MSIX_ON
) &&
227 bfad_install_msix_handler(bfad
)) {
228 printk(KERN_WARNING
"%s: install_msix failed, bfad%d\n",
229 __func__
, bfad
->inst_no
);
232 bfad_init_timer(bfad
);
234 wait_for_completion(&bfad
->comp
);
236 if ((bfad
->bfad_flags
& BFAD_HAL_INIT_DONE
)) {
237 bfa_sm_send_event(bfad
, BFAD_E_INIT_SUCCESS
);
240 "bfa %s: bfa init failed\n",
242 bfad
->bfad_flags
|= BFAD_HAL_INIT_FAIL
;
243 bfa_sm_send_event(bfad
, BFAD_E_INIT_FAILED
);
248 case BFAD_E_KTHREAD_CREATE_FAILED
:
249 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
253 bfa_sm_fault(bfad
, event
);
258 bfad_sm_initializing(struct bfad_s
*bfad
, enum bfad_sm_event event
)
263 bfa_trc(bfad
, event
);
266 case BFAD_E_INIT_SUCCESS
:
267 kthread_stop(bfad
->bfad_tsk
);
268 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
269 bfad
->bfad_tsk
= NULL
;
270 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
272 retval
= bfad_start_ops(bfad
);
273 if (retval
!= BFA_STATUS_OK
)
275 bfa_sm_set_state(bfad
, bfad_sm_operational
);
278 case BFAD_E_INTR_INIT_FAILED
:
279 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
280 kthread_stop(bfad
->bfad_tsk
);
281 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
282 bfad
->bfad_tsk
= NULL
;
283 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
286 case BFAD_E_INIT_FAILED
:
287 bfa_sm_set_state(bfad
, bfad_sm_failed
);
290 bfa_sm_fault(bfad
, event
);
295 bfad_sm_failed(struct bfad_s
*bfad
, enum bfad_sm_event event
)
299 bfa_trc(bfad
, event
);
302 case BFAD_E_INIT_SUCCESS
:
303 retval
= bfad_start_ops(bfad
);
304 if (retval
!= BFA_STATUS_OK
)
306 bfa_sm_set_state(bfad
, bfad_sm_operational
);
310 if (bfad
->bfad_flags
& BFAD_CFG_PPORT_DONE
)
311 bfad_uncfg_pport(bfad
);
312 if (bfad
->bfad_flags
& BFAD_FC4_PROBE_DONE
) {
313 bfad_im_probe_undo(bfad
);
314 bfad
->bfad_flags
&= ~BFAD_FC4_PROBE_DONE
;
319 case BFAD_E_EXIT_COMP
:
320 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
321 bfad_remove_intr(bfad
);
322 del_timer_sync(&bfad
->hal_tmo
);
326 bfa_sm_fault(bfad
, event
);
331 bfad_sm_operational(struct bfad_s
*bfad
, enum bfad_sm_event event
)
333 bfa_trc(bfad
, event
);
337 bfa_sm_set_state(bfad
, bfad_sm_fcs_exit
);
342 bfa_sm_fault(bfad
, event
);
347 bfad_sm_fcs_exit(struct bfad_s
*bfad
, enum bfad_sm_event event
)
349 bfa_trc(bfad
, event
);
352 case BFAD_E_FCS_EXIT_COMP
:
353 bfa_sm_set_state(bfad
, bfad_sm_stopping
);
358 bfa_sm_fault(bfad
, event
);
363 bfad_sm_stopping(struct bfad_s
*bfad
, enum bfad_sm_event event
)
365 bfa_trc(bfad
, event
);
368 case BFAD_E_EXIT_COMP
:
369 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
370 bfad_remove_intr(bfad
);
371 del_timer_sync(&bfad
->hal_tmo
);
372 bfad_im_probe_undo(bfad
);
373 bfad
->bfad_flags
&= ~BFAD_FC4_PROBE_DONE
;
374 bfad_uncfg_pport(bfad
);
378 bfa_sm_fault(bfad
, event
);
387 bfad_hcb_comp(void *arg
, bfa_status_t status
)
389 struct bfad_hal_comp
*fcomp
= (struct bfad_hal_comp
*)arg
;
391 fcomp
->status
= status
;
392 complete(&fcomp
->comp
);
399 bfa_cb_init(void *drv
, bfa_status_t init_status
)
401 struct bfad_s
*bfad
= drv
;
403 if (init_status
== BFA_STATUS_OK
) {
404 bfad
->bfad_flags
|= BFAD_HAL_INIT_DONE
;
407 * If BFAD_HAL_INIT_FAIL flag is set:
408 * Wake up the kernel thread to start
409 * the bfad operations after HAL init done
411 if ((bfad
->bfad_flags
& BFAD_HAL_INIT_FAIL
)) {
412 bfad
->bfad_flags
&= ~BFAD_HAL_INIT_FAIL
;
413 wake_up_process(bfad
->bfad_tsk
);
417 complete(&bfad
->comp
);
424 bfa_fcb_lport_new(struct bfad_s
*bfad
, struct bfa_fcs_lport_s
*port
,
425 enum bfa_lport_role roles
, struct bfad_vf_s
*vf_drv
,
426 struct bfad_vport_s
*vp_drv
)
429 struct bfad_port_s
*port_drv
;
431 if (!vp_drv
&& !vf_drv
) {
432 port_drv
= &bfad
->pport
;
433 port_drv
->pvb_type
= BFAD_PORT_PHYS_BASE
;
434 } else if (!vp_drv
&& vf_drv
) {
435 port_drv
= &vf_drv
->base_port
;
436 port_drv
->pvb_type
= BFAD_PORT_VF_BASE
;
437 } else if (vp_drv
&& !vf_drv
) {
438 port_drv
= &vp_drv
->drv_port
;
439 port_drv
->pvb_type
= BFAD_PORT_PHYS_VPORT
;
441 port_drv
= &vp_drv
->drv_port
;
442 port_drv
->pvb_type
= BFAD_PORT_VF_VPORT
;
445 port_drv
->fcs_port
= port
;
446 port_drv
->roles
= roles
;
448 if (roles
& BFA_LPORT_ROLE_FCP_IM
) {
449 rc
= bfad_im_port_new(bfad
, port_drv
);
450 if (rc
!= BFA_STATUS_OK
) {
451 bfad_im_port_delete(bfad
, port_drv
);
460 * FCS RPORT alloc callback, after successful PLOGI by FCS
463 bfa_fcb_rport_alloc(struct bfad_s
*bfad
, struct bfa_fcs_rport_s
**rport
,
464 struct bfad_rport_s
**rport_drv
)
466 bfa_status_t rc
= BFA_STATUS_OK
;
468 *rport_drv
= kzalloc(sizeof(struct bfad_rport_s
), GFP_ATOMIC
);
469 if (*rport_drv
== NULL
) {
470 rc
= BFA_STATUS_ENOMEM
;
474 *rport
= &(*rport_drv
)->fcs_rport
;
481 * FCS PBC VPORT Create
484 bfa_fcb_pbc_vport_create(struct bfad_s
*bfad
, struct bfi_pbc_vport_s pbc_vport
)
487 struct bfa_lport_cfg_s port_cfg
= {0};
488 struct bfad_vport_s
*vport
;
491 vport
= kzalloc(sizeof(struct bfad_vport_s
), GFP_KERNEL
);
497 vport
->drv_port
.bfad
= bfad
;
498 port_cfg
.roles
= BFA_LPORT_ROLE_FCP_IM
;
499 port_cfg
.pwwn
= pbc_vport
.vp_pwwn
;
500 port_cfg
.nwwn
= pbc_vport
.vp_nwwn
;
501 port_cfg
.preboot_vp
= BFA_TRUE
;
503 rc
= bfa_fcs_pbc_vport_create(&vport
->fcs_vport
, &bfad
->bfa_fcs
, 0,
506 if (rc
!= BFA_STATUS_OK
) {
511 list_add_tail(&vport
->list_entry
, &bfad
->pbc_vport_list
);
515 bfad_hal_mem_release(struct bfad_s
*bfad
)
517 struct bfa_meminfo_s
*hal_meminfo
= &bfad
->meminfo
;
518 struct bfa_mem_dma_s
*dma_info
, *dma_elem
;
519 struct bfa_mem_kva_s
*kva_info
, *kva_elem
;
520 struct list_head
*dm_qe
, *km_qe
;
522 dma_info
= &hal_meminfo
->dma_info
;
523 kva_info
= &hal_meminfo
->kva_info
;
525 /* Iterate through the KVA meminfo queue */
526 list_for_each(km_qe
, &kva_info
->qe
) {
527 kva_elem
= (struct bfa_mem_kva_s
*) km_qe
;
528 vfree(kva_elem
->kva
);
531 /* Iterate through the DMA meminfo queue */
532 list_for_each(dm_qe
, &dma_info
->qe
) {
533 dma_elem
= (struct bfa_mem_dma_s
*) dm_qe
;
534 dma_free_coherent(&bfad
->pcidev
->dev
,
535 dma_elem
->mem_len
, dma_elem
->kva
,
536 (dma_addr_t
) dma_elem
->dma
);
539 memset(hal_meminfo
, 0, sizeof(struct bfa_meminfo_s
));
543 bfad_update_hal_cfg(struct bfa_iocfc_cfg_s
*bfa_cfg
)
546 bfa_cfg
->fwcfg
.num_rports
= num_rports
;
548 bfa_cfg
->fwcfg
.num_ioim_reqs
= num_ios
;
550 bfa_cfg
->fwcfg
.num_tskim_reqs
= num_tms
;
551 if (num_fcxps
> 0 && num_fcxps
<= BFA_FCXP_MAX
)
552 bfa_cfg
->fwcfg
.num_fcxp_reqs
= num_fcxps
;
553 if (num_ufbufs
> 0 && num_ufbufs
<= BFA_UF_MAX
)
554 bfa_cfg
->fwcfg
.num_uf_bufs
= num_ufbufs
;
556 bfa_cfg
->drvcfg
.num_reqq_elems
= reqq_size
;
558 bfa_cfg
->drvcfg
.num_rspq_elems
= rspq_size
;
559 if (num_sgpgs
> 0 && num_sgpgs
<= BFA_SGPG_MAX
)
560 bfa_cfg
->drvcfg
.num_sgpgs
= num_sgpgs
;
563 * populate the hal values back to the driver for sysfs use.
564 * otherwise, the default values will be shown as 0 in sysfs
566 num_rports
= bfa_cfg
->fwcfg
.num_rports
;
567 num_ios
= bfa_cfg
->fwcfg
.num_ioim_reqs
;
568 num_tms
= bfa_cfg
->fwcfg
.num_tskim_reqs
;
569 num_fcxps
= bfa_cfg
->fwcfg
.num_fcxp_reqs
;
570 num_ufbufs
= bfa_cfg
->fwcfg
.num_uf_bufs
;
571 reqq_size
= bfa_cfg
->drvcfg
.num_reqq_elems
;
572 rspq_size
= bfa_cfg
->drvcfg
.num_rspq_elems
;
573 num_sgpgs
= bfa_cfg
->drvcfg
.num_sgpgs
;
577 bfad_hal_mem_alloc(struct bfad_s
*bfad
)
579 struct bfa_meminfo_s
*hal_meminfo
= &bfad
->meminfo
;
580 struct bfa_mem_dma_s
*dma_info
, *dma_elem
;
581 struct bfa_mem_kva_s
*kva_info
, *kva_elem
;
582 struct list_head
*dm_qe
, *km_qe
;
583 bfa_status_t rc
= BFA_STATUS_OK
;
584 dma_addr_t phys_addr
;
586 bfa_cfg_get_default(&bfad
->ioc_cfg
);
587 bfad_update_hal_cfg(&bfad
->ioc_cfg
);
588 bfad
->cfg_data
.ioc_queue_depth
= bfad
->ioc_cfg
.fwcfg
.num_ioim_reqs
;
589 bfa_cfg_get_meminfo(&bfad
->ioc_cfg
, hal_meminfo
, &bfad
->bfa
);
591 dma_info
= &hal_meminfo
->dma_info
;
592 kva_info
= &hal_meminfo
->kva_info
;
594 /* Iterate through the KVA meminfo queue */
595 list_for_each(km_qe
, &kva_info
->qe
) {
596 kva_elem
= (struct bfa_mem_kva_s
*) km_qe
;
597 kva_elem
->kva
= vmalloc(kva_elem
->mem_len
);
598 if (kva_elem
->kva
== NULL
) {
599 bfad_hal_mem_release(bfad
);
600 rc
= BFA_STATUS_ENOMEM
;
603 memset(kva_elem
->kva
, 0, kva_elem
->mem_len
);
606 /* Iterate through the DMA meminfo queue */
607 list_for_each(dm_qe
, &dma_info
->qe
) {
608 dma_elem
= (struct bfa_mem_dma_s
*) dm_qe
;
609 dma_elem
->kva
= dma_alloc_coherent(&bfad
->pcidev
->dev
,
611 &phys_addr
, GFP_KERNEL
);
612 if (dma_elem
->kva
== NULL
) {
613 bfad_hal_mem_release(bfad
);
614 rc
= BFA_STATUS_ENOMEM
;
617 dma_elem
->dma
= phys_addr
;
618 memset(dma_elem
->kva
, 0, dma_elem
->mem_len
);
625 * Create a vport under a vf.
628 bfad_vport_create(struct bfad_s
*bfad
, u16 vf_id
,
629 struct bfa_lport_cfg_s
*port_cfg
, struct device
*dev
)
631 struct bfad_vport_s
*vport
;
632 int rc
= BFA_STATUS_OK
;
634 struct completion fcomp
;
636 vport
= kzalloc(sizeof(struct bfad_vport_s
), GFP_KERNEL
);
638 rc
= BFA_STATUS_ENOMEM
;
642 vport
->drv_port
.bfad
= bfad
;
643 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
644 rc
= bfa_fcs_vport_create(&vport
->fcs_vport
, &bfad
->bfa_fcs
, vf_id
,
646 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
648 if (rc
!= BFA_STATUS_OK
)
651 if (port_cfg
->roles
& BFA_LPORT_ROLE_FCP_IM
) {
652 rc
= bfad_im_scsi_host_alloc(bfad
, vport
->drv_port
.im_port
,
654 if (rc
!= BFA_STATUS_OK
)
655 goto ext_free_fcs_vport
;
658 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
659 bfa_fcs_vport_start(&vport
->fcs_vport
);
660 list_add_tail(&vport
->list_entry
, &bfad
->vport_list
);
661 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
663 return BFA_STATUS_OK
;
666 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
667 vport
->comp_del
= &fcomp
;
668 init_completion(vport
->comp_del
);
669 bfa_fcs_vport_delete(&vport
->fcs_vport
);
670 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
671 wait_for_completion(vport
->comp_del
);
679 bfad_bfa_tmo(unsigned long data
)
681 struct bfad_s
*bfad
= (struct bfad_s
*) data
;
683 struct list_head doneq
;
685 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
687 bfa_timer_beat(&bfad
->bfa
.timer_mod
);
689 bfa_comp_deq(&bfad
->bfa
, &doneq
);
690 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
692 if (!list_empty(&doneq
)) {
693 bfa_comp_process(&bfad
->bfa
, &doneq
);
694 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
695 bfa_comp_free(&bfad
->bfa
, &doneq
);
696 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
699 mod_timer(&bfad
->hal_tmo
,
700 jiffies
+ msecs_to_jiffies(BFA_TIMER_FREQ
));
704 bfad_init_timer(struct bfad_s
*bfad
)
706 init_timer(&bfad
->hal_tmo
);
707 bfad
->hal_tmo
.function
= bfad_bfa_tmo
;
708 bfad
->hal_tmo
.data
= (unsigned long)bfad
;
710 mod_timer(&bfad
->hal_tmo
,
711 jiffies
+ msecs_to_jiffies(BFA_TIMER_FREQ
));
715 bfad_pci_init(struct pci_dev
*pdev
, struct bfad_s
*bfad
)
719 if (pci_enable_device(pdev
)) {
720 printk(KERN_ERR
"pci_enable_device fail %p\n", pdev
);
724 if (pci_request_regions(pdev
, BFAD_DRIVER_NAME
))
725 goto out_disable_device
;
727 pci_set_master(pdev
);
730 if ((pci_set_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0) ||
731 (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)) != 0)) {
732 if ((pci_set_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0) ||
733 (pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32)) != 0)) {
734 printk(KERN_ERR
"pci_set_dma_mask fail %p\n", pdev
);
735 goto out_release_region
;
739 bfad
->pci_bar0_kva
= pci_iomap(pdev
, 0, pci_resource_len(pdev
, 0));
740 bfad
->pci_bar2_kva
= pci_iomap(pdev
, 2, pci_resource_len(pdev
, 2));
742 if (bfad
->pci_bar0_kva
== NULL
) {
743 printk(KERN_ERR
"Fail to map bar0\n");
744 goto out_release_region
;
747 bfad
->hal_pcidev
.pci_slot
= PCI_SLOT(pdev
->devfn
);
748 bfad
->hal_pcidev
.pci_func
= PCI_FUNC(pdev
->devfn
);
749 bfad
->hal_pcidev
.pci_bar_kva
= bfad
->pci_bar0_kva
;
750 bfad
->hal_pcidev
.device_id
= pdev
->device
;
751 bfad
->hal_pcidev
.ssid
= pdev
->subsystem_device
;
752 bfad
->pci_name
= pci_name(pdev
);
754 bfad
->pci_attr
.vendor_id
= pdev
->vendor
;
755 bfad
->pci_attr
.device_id
= pdev
->device
;
756 bfad
->pci_attr
.ssid
= pdev
->subsystem_device
;
757 bfad
->pci_attr
.ssvid
= pdev
->subsystem_vendor
;
758 bfad
->pci_attr
.pcifn
= PCI_FUNC(pdev
->devfn
);
762 /* Adjust PCIe Maximum Read Request Size */
763 if (pcie_max_read_reqsz
> 0) {
768 switch (pcie_max_read_reqsz
) {
791 pcie_cap_reg
= pci_find_capability(pdev
, PCI_CAP_ID_EXP
);
792 if (mask
!= 0xffff && pcie_cap_reg
) {
793 pcie_cap_reg
+= 0x08;
794 pci_read_config_word(pdev
, pcie_cap_reg
, &pcie_dev_ctl
);
795 if ((pcie_dev_ctl
& 0x7000) != mask
) {
796 printk(KERN_WARNING
"BFA[%s]: "
797 "pcie_max_read_request_size is %d, "
798 "reset to %d\n", bfad
->pci_name
,
799 (1 << ((pcie_dev_ctl
& 0x7000) >> 12)) << 7,
800 pcie_max_read_reqsz
);
802 pcie_dev_ctl
&= ~0x7000;
803 pci_write_config_word(pdev
, pcie_cap_reg
,
804 pcie_dev_ctl
| mask
);
812 pci_release_regions(pdev
);
814 pci_disable_device(pdev
);
820 bfad_pci_uninit(struct pci_dev
*pdev
, struct bfad_s
*bfad
)
822 pci_iounmap(pdev
, bfad
->pci_bar0_kva
);
823 pci_iounmap(pdev
, bfad
->pci_bar2_kva
);
824 pci_release_regions(pdev
);
825 pci_disable_device(pdev
);
826 pci_set_drvdata(pdev
, NULL
);
830 bfad_drv_init(struct bfad_s
*bfad
)
835 bfad
->cfg_data
.rport_del_timeout
= rport_del_timeout
;
836 bfad
->cfg_data
.lun_queue_depth
= bfa_lun_queue_depth
;
837 bfad
->cfg_data
.io_max_sge
= bfa_io_max_sge
;
838 bfad
->cfg_data
.binding_method
= FCP_PWWN_BINDING
;
840 rc
= bfad_hal_mem_alloc(bfad
);
841 if (rc
!= BFA_STATUS_OK
) {
842 printk(KERN_WARNING
"bfad%d bfad_hal_mem_alloc failure\n",
845 "Not enough memory to attach all Brocade HBA ports, %s",
846 "System may need more memory.\n");
847 goto out_hal_mem_alloc_failure
;
850 bfad
->bfa
.trcmod
= bfad
->trcmod
;
851 bfad
->bfa
.plog
= &bfad
->plog_buf
;
852 bfa_plog_init(&bfad
->plog_buf
);
853 bfa_plog_str(&bfad
->plog_buf
, BFA_PL_MID_DRVR
, BFA_PL_EID_DRIVER_START
,
856 bfa_attach(&bfad
->bfa
, bfad
, &bfad
->ioc_cfg
, &bfad
->meminfo
,
860 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
861 bfad
->bfa_fcs
.trcmod
= bfad
->trcmod
;
862 bfa_fcs_attach(&bfad
->bfa_fcs
, &bfad
->bfa
, bfad
, BFA_FALSE
);
863 bfad
->bfa_fcs
.fdmi_enabled
= fdmi_enable
;
864 bfa_fcs_init(&bfad
->bfa_fcs
);
865 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
867 bfad
->bfad_flags
|= BFAD_DRV_INIT_DONE
;
869 /* configure base port */
870 rc
= bfad_cfg_pport(bfad
, BFA_LPORT_ROLE_FCP_IM
);
871 if (rc
!= BFA_STATUS_OK
)
872 goto out_cfg_pport_fail
;
874 return BFA_STATUS_OK
;
877 /* fcs exit - on cfg pport failure */
878 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
879 init_completion(&bfad
->comp
);
880 bfad
->pport
.flags
|= BFAD_PORT_DELETE
;
881 bfa_fcs_exit(&bfad
->bfa_fcs
);
882 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
883 wait_for_completion(&bfad
->comp
);
884 /* bfa detach - free hal memory */
885 bfa_detach(&bfad
->bfa
);
886 bfad_hal_mem_release(bfad
);
887 out_hal_mem_alloc_failure
:
888 return BFA_STATUS_FAILED
;
892 bfad_drv_uninit(struct bfad_s
*bfad
)
896 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
897 init_completion(&bfad
->comp
);
898 bfa_iocfc_stop(&bfad
->bfa
);
899 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
900 wait_for_completion(&bfad
->comp
);
902 del_timer_sync(&bfad
->hal_tmo
);
903 bfa_isr_disable(&bfad
->bfa
);
904 bfa_detach(&bfad
->bfa
);
905 bfad_remove_intr(bfad
);
906 bfad_hal_mem_release(bfad
);
908 bfad
->bfad_flags
&= ~BFAD_DRV_INIT_DONE
;
912 bfad_drv_start(struct bfad_s
*bfad
)
916 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
917 bfa_iocfc_start(&bfad
->bfa
);
918 bfa_fcs_pbc_vport_init(&bfad
->bfa_fcs
);
919 bfa_fcs_fabric_modstart(&bfad
->bfa_fcs
);
920 bfad
->bfad_flags
|= BFAD_HAL_START_DONE
;
921 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
924 flush_workqueue(bfad
->im
->drv_workq
);
928 bfad_fcs_stop(struct bfad_s
*bfad
)
932 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
933 init_completion(&bfad
->comp
);
934 bfad
->pport
.flags
|= BFAD_PORT_DELETE
;
935 bfa_fcs_exit(&bfad
->bfa_fcs
);
936 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
937 wait_for_completion(&bfad
->comp
);
939 bfa_sm_send_event(bfad
, BFAD_E_FCS_EXIT_COMP
);
943 bfad_stop(struct bfad_s
*bfad
)
947 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
948 init_completion(&bfad
->comp
);
949 bfa_iocfc_stop(&bfad
->bfa
);
950 bfad
->bfad_flags
&= ~BFAD_HAL_START_DONE
;
951 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
952 wait_for_completion(&bfad
->comp
);
954 bfa_sm_send_event(bfad
, BFAD_E_EXIT_COMP
);
958 bfad_cfg_pport(struct bfad_s
*bfad
, enum bfa_lport_role role
)
960 int rc
= BFA_STATUS_OK
;
962 /* Allocate scsi_host for the physical port */
963 if ((supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
) &&
964 (role
& BFA_LPORT_ROLE_FCP_IM
)) {
965 if (bfad
->pport
.im_port
== NULL
) {
966 rc
= BFA_STATUS_FAILED
;
970 rc
= bfad_im_scsi_host_alloc(bfad
, bfad
->pport
.im_port
,
972 if (rc
!= BFA_STATUS_OK
)
975 bfad
->pport
.roles
|= BFA_LPORT_ROLE_FCP_IM
;
978 bfad
->bfad_flags
|= BFAD_CFG_PPORT_DONE
;
985 bfad_uncfg_pport(struct bfad_s
*bfad
)
987 if ((supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
) &&
988 (bfad
->pport
.roles
& BFA_LPORT_ROLE_FCP_IM
)) {
989 bfad_im_scsi_host_free(bfad
, bfad
->pport
.im_port
);
990 bfad_im_port_clean(bfad
->pport
.im_port
);
991 kfree(bfad
->pport
.im_port
);
992 bfad
->pport
.roles
&= ~BFA_LPORT_ROLE_FCP_IM
;
995 bfad
->bfad_flags
&= ~BFAD_CFG_PPORT_DONE
;
999 bfad_start_ops(struct bfad_s
*bfad
) {
1002 unsigned long flags
;
1003 struct bfad_vport_s
*vport
, *vport_new
;
1004 struct bfa_fcs_driver_info_s driver_info
;
1006 /* Limit min/max. xfer size to [64k-32MB] */
1007 if (max_xfer_size
< BFAD_MIN_SECTORS
>> 1)
1008 max_xfer_size
= BFAD_MIN_SECTORS
>> 1;
1009 if (max_xfer_size
> BFAD_MAX_SECTORS
>> 1)
1010 max_xfer_size
= BFAD_MAX_SECTORS
>> 1;
1012 /* Fill the driver_info info to fcs*/
1013 memset(&driver_info
, 0, sizeof(driver_info
));
1014 strncpy(driver_info
.version
, BFAD_DRIVER_VERSION
,
1015 sizeof(driver_info
.version
) - 1);
1017 strncpy(driver_info
.host_machine_name
, host_name
,
1018 sizeof(driver_info
.host_machine_name
) - 1);
1020 strncpy(driver_info
.host_os_name
, os_name
,
1021 sizeof(driver_info
.host_os_name
) - 1);
1023 strncpy(driver_info
.host_os_patch
, os_patch
,
1024 sizeof(driver_info
.host_os_patch
) - 1);
1026 strncpy(driver_info
.os_device_name
, bfad
->pci_name
,
1027 sizeof(driver_info
.os_device_name
- 1));
1029 /* FCS driver info init */
1030 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1031 bfa_fcs_driver_info_init(&bfad
->bfa_fcs
, &driver_info
);
1032 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1035 * FCS update cfg - reset the pwwn/nwwn of fabric base logical port
1036 * with values learned during bfa_init firmware GETATTR REQ.
1038 bfa_fcs_update_cfg(&bfad
->bfa_fcs
);
1040 /* Setup fc host fixed attribute if the lk supports */
1041 bfad_fc_host_init(bfad
->pport
.im_port
);
1043 /* BFAD level FC4 IM specific resource allocation */
1044 retval
= bfad_im_probe(bfad
);
1045 if (retval
!= BFA_STATUS_OK
) {
1046 printk(KERN_WARNING
"bfad_im_probe failed\n");
1047 if (bfa_sm_cmp_state(bfad
, bfad_sm_initializing
))
1048 bfa_sm_set_state(bfad
, bfad_sm_failed
);
1049 bfad_im_probe_undo(bfad
);
1050 bfad
->bfad_flags
&= ~BFAD_FC4_PROBE_DONE
;
1051 bfad_uncfg_pport(bfad
);
1053 return BFA_STATUS_FAILED
;
1055 bfad
->bfad_flags
|= BFAD_FC4_PROBE_DONE
;
1057 bfad_drv_start(bfad
);
1059 /* Complete pbc vport create */
1060 list_for_each_entry_safe(vport
, vport_new
, &bfad
->pbc_vport_list
,
1062 struct fc_vport_identifiers vid
;
1063 struct fc_vport
*fc_vport
;
1064 char pwwn_buf
[BFA_STRING_32
];
1066 memset(&vid
, 0, sizeof(vid
));
1067 vid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1068 vid
.vport_type
= FC_PORTTYPE_NPIV
;
1069 vid
.disable
= false;
1070 vid
.node_name
= wwn_to_u64((u8
*)
1071 (&((vport
->fcs_vport
).lport
.port_cfg
.nwwn
)));
1072 vid
.port_name
= wwn_to_u64((u8
*)
1073 (&((vport
->fcs_vport
).lport
.port_cfg
.pwwn
)));
1074 fc_vport
= fc_vport_create(bfad
->pport
.im_port
->shost
, 0, &vid
);
1076 wwn2str(pwwn_buf
, vid
.port_name
);
1077 printk(KERN_WARNING
"bfad%d: failed to create pbc vport"
1078 " %s\n", bfad
->inst_no
, pwwn_buf
);
1080 list_del(&vport
->list_entry
);
1085 * If bfa_linkup_delay is set to -1 default; try to retrive the
1086 * value using the bfad_get_linkup_delay(); else use the
1087 * passed in module param value as the bfa_linkup_delay.
1089 if (bfa_linkup_delay
< 0) {
1090 bfa_linkup_delay
= bfad_get_linkup_delay(bfad
);
1091 bfad_rport_online_wait(bfad
);
1092 bfa_linkup_delay
= -1;
1094 bfad_rport_online_wait(bfad
);
1096 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
, "bfa device claimed\n");
1098 return BFA_STATUS_OK
;
1102 bfad_worker(void *ptr
)
1104 struct bfad_s
*bfad
;
1105 unsigned long flags
;
1107 bfad
= (struct bfad_s
*)ptr
;
1109 while (!kthread_should_stop()) {
1111 /* Send event BFAD_E_INIT_SUCCESS */
1112 bfa_sm_send_event(bfad
, BFAD_E_INIT_SUCCESS
);
1114 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1115 bfad
->bfad_tsk
= NULL
;
1116 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1125 * BFA driver interrupt functions
1128 bfad_intx(int irq
, void *dev_id
)
1130 struct bfad_s
*bfad
= dev_id
;
1131 struct list_head doneq
;
1132 unsigned long flags
;
1135 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1136 rc
= bfa_intx(&bfad
->bfa
);
1138 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1142 bfa_comp_deq(&bfad
->bfa
, &doneq
);
1143 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1145 if (!list_empty(&doneq
)) {
1146 bfa_comp_process(&bfad
->bfa
, &doneq
);
1148 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1149 bfa_comp_free(&bfad
->bfa
, &doneq
);
1150 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1158 bfad_msix(int irq
, void *dev_id
)
1160 struct bfad_msix_s
*vec
= dev_id
;
1161 struct bfad_s
*bfad
= vec
->bfad
;
1162 struct list_head doneq
;
1163 unsigned long flags
;
1165 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1167 bfa_msix(&bfad
->bfa
, vec
->msix
.entry
);
1168 bfa_comp_deq(&bfad
->bfa
, &doneq
);
1169 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1171 if (!list_empty(&doneq
)) {
1172 bfa_comp_process(&bfad
->bfa
, &doneq
);
1174 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1175 bfa_comp_free(&bfad
->bfa
, &doneq
);
1176 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1183 * Initialize the MSIX entry table.
1186 bfad_init_msix_entry(struct bfad_s
*bfad
, struct msix_entry
*msix_entries
,
1187 int mask
, int max_bit
)
1190 int match
= 0x00000001;
1192 for (i
= 0, bfad
->nvec
= 0; i
< MAX_MSIX_ENTRY
; i
++) {
1194 bfad
->msix_tab
[bfad
->nvec
].msix
.entry
= i
;
1195 bfad
->msix_tab
[bfad
->nvec
].bfad
= bfad
;
1196 msix_entries
[bfad
->nvec
].entry
= i
;
1206 bfad_install_msix_handler(struct bfad_s
*bfad
)
1210 for (i
= 0; i
< bfad
->nvec
; i
++) {
1211 sprintf(bfad
->msix_tab
[i
].name
, "bfa-%s-%s",
1213 ((bfa_asic_id_cb(bfad
->hal_pcidev
.device_id
)) ?
1214 msix_name_cb
[i
] : msix_name_ct
[i
]));
1216 error
= request_irq(bfad
->msix_tab
[i
].msix
.vector
,
1217 (irq_handler_t
) bfad_msix
, 0,
1218 bfad
->msix_tab
[i
].name
, &bfad
->msix_tab
[i
]);
1220 bfa_trc(bfad
, bfad
->msix_tab
[i
].msix
.vector
);
1224 for (j
= 0; j
< i
; j
++)
1225 free_irq(bfad
->msix_tab
[j
].msix
.vector
,
1226 &bfad
->msix_tab
[j
]);
1228 bfad
->bfad_flags
&= ~BFAD_MSIX_ON
;
1229 pci_disable_msix(bfad
->pcidev
);
1239 * Setup MSIX based interrupt.
1242 bfad_setup_intr(struct bfad_s
*bfad
)
1245 u32 mask
= 0, i
, num_bit
= 0, max_bit
= 0;
1246 struct msix_entry msix_entries
[MAX_MSIX_ENTRY
];
1247 struct pci_dev
*pdev
= bfad
->pcidev
;
1250 /* Call BFA to get the msix map for this PCI function. */
1251 bfa_msix_getvecs(&bfad
->bfa
, &mask
, &num_bit
, &max_bit
);
1253 /* Set up the msix entry table */
1254 bfad_init_msix_entry(bfad
, msix_entries
, mask
, max_bit
);
1256 if ((bfa_asic_id_ctc(pdev
->device
) && !msix_disable_ct
) ||
1257 (bfa_asic_id_cb(pdev
->device
) && !msix_disable_cb
)) {
1259 error
= pci_enable_msix(bfad
->pcidev
, msix_entries
, bfad
->nvec
);
1262 * Only error number of vector is available.
1263 * We don't have a mechanism to map multiple
1264 * interrupts into one vector, so even if we
1265 * can try to request less vectors, we don't
1266 * know how to associate interrupt events to
1267 * vectors. Linux doesn't duplicate vectors
1268 * in the MSIX table for this case.
1271 printk(KERN_WARNING
"bfad%d: "
1272 "pci_enable_msix failed (%d),"
1273 " use line based.\n", bfad
->inst_no
, error
);
1278 /* Disable INTX in MSI-X mode */
1279 pci_read_config_word(pdev
, PCI_COMMAND
, ®
);
1281 if (!(reg
& PCI_COMMAND_INTX_DISABLE
))
1282 pci_write_config_word(pdev
, PCI_COMMAND
,
1283 reg
| PCI_COMMAND_INTX_DISABLE
);
1285 /* Save the vectors */
1286 for (i
= 0; i
< bfad
->nvec
; i
++) {
1287 bfa_trc(bfad
, msix_entries
[i
].vector
);
1288 bfad
->msix_tab
[i
].msix
.vector
= msix_entries
[i
].vector
;
1291 bfa_msix_init(&bfad
->bfa
, bfad
->nvec
);
1293 bfad
->bfad_flags
|= BFAD_MSIX_ON
;
1301 (bfad
->pcidev
->irq
, (irq_handler_t
) bfad_intx
, BFAD_IRQ_FLAGS
,
1302 BFAD_DRIVER_NAME
, bfad
) != 0) {
1303 /* Enable interrupt handler failed */
1306 bfad
->bfad_flags
|= BFAD_INTX_ON
;
1312 bfad_remove_intr(struct bfad_s
*bfad
)
1316 if (bfad
->bfad_flags
& BFAD_MSIX_ON
) {
1317 for (i
= 0; i
< bfad
->nvec
; i
++)
1318 free_irq(bfad
->msix_tab
[i
].msix
.vector
,
1319 &bfad
->msix_tab
[i
]);
1321 pci_disable_msix(bfad
->pcidev
);
1322 bfad
->bfad_flags
&= ~BFAD_MSIX_ON
;
1323 } else if (bfad
->bfad_flags
& BFAD_INTX_ON
) {
1324 free_irq(bfad
->pcidev
->irq
, bfad
);
1332 bfad_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
1334 struct bfad_s
*bfad
;
1335 int error
= -ENODEV
, retval
, i
;
1337 /* For single port cards - only claim function 0 */
1338 if ((pdev
->device
== BFA_PCI_DEVICE_ID_FC_8G1P
) &&
1339 (PCI_FUNC(pdev
->devfn
) != 0))
1342 bfad
= kzalloc(sizeof(struct bfad_s
), GFP_KERNEL
);
1348 bfad
->trcmod
= kzalloc(sizeof(struct bfa_trc_mod_s
), GFP_KERNEL
);
1349 if (!bfad
->trcmod
) {
1350 printk(KERN_WARNING
"Error alloc trace buffer!\n");
1352 goto out_alloc_trace_failure
;
1356 bfa_trc_init(bfad
->trcmod
);
1357 bfa_trc(bfad
, bfad_inst
);
1360 INIT_LIST_HEAD(&bfad
->free_aen_q
);
1361 INIT_LIST_HEAD(&bfad
->active_aen_q
);
1362 for (i
= 0; i
< BFA_AEN_MAX_ENTRY
; i
++)
1363 list_add_tail(&bfad
->aen_list
[i
].qe
, &bfad
->free_aen_q
);
1365 if (!(bfad_load_fwimg(pdev
))) {
1366 kfree(bfad
->trcmod
);
1367 goto out_alloc_trace_failure
;
1370 retval
= bfad_pci_init(pdev
, bfad
);
1372 printk(KERN_WARNING
"bfad_pci_init failure!\n");
1374 goto out_pci_init_failure
;
1377 mutex_lock(&bfad_mutex
);
1378 bfad
->inst_no
= bfad_inst
++;
1379 list_add_tail(&bfad
->list_entry
, &bfad_list
);
1380 mutex_unlock(&bfad_mutex
);
1382 /* Initializing the state machine: State set to uninit */
1383 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
1385 spin_lock_init(&bfad
->bfad_lock
);
1386 pci_set_drvdata(pdev
, bfad
);
1388 bfad
->ref_count
= 0;
1389 bfad
->pport
.bfad
= bfad
;
1390 INIT_LIST_HEAD(&bfad
->pbc_vport_list
);
1391 INIT_LIST_HEAD(&bfad
->vport_list
);
1393 /* Setup the debugfs node for this bfad */
1394 if (bfa_debugfs_enable
)
1395 bfad_debugfs_init(&bfad
->pport
);
1397 retval
= bfad_drv_init(bfad
);
1398 if (retval
!= BFA_STATUS_OK
)
1399 goto out_drv_init_failure
;
1401 bfa_sm_send_event(bfad
, BFAD_E_CREATE
);
1403 if (bfa_sm_cmp_state(bfad
, bfad_sm_uninit
))
1404 goto out_bfad_sm_failure
;
1408 out_bfad_sm_failure
:
1409 bfa_detach(&bfad
->bfa
);
1410 bfad_hal_mem_release(bfad
);
1411 out_drv_init_failure
:
1412 /* Remove the debugfs node for this bfad */
1413 kfree(bfad
->regdata
);
1414 bfad_debugfs_exit(&bfad
->pport
);
1415 mutex_lock(&bfad_mutex
);
1417 list_del(&bfad
->list_entry
);
1418 mutex_unlock(&bfad_mutex
);
1419 bfad_pci_uninit(pdev
, bfad
);
1420 out_pci_init_failure
:
1421 kfree(bfad
->trcmod
);
1422 out_alloc_trace_failure
:
1432 bfad_pci_remove(struct pci_dev
*pdev
)
1434 struct bfad_s
*bfad
= pci_get_drvdata(pdev
);
1435 unsigned long flags
;
1437 bfa_trc(bfad
, bfad
->inst_no
);
1439 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1440 if (bfad
->bfad_tsk
!= NULL
) {
1441 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1442 kthread_stop(bfad
->bfad_tsk
);
1444 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1447 /* Send Event BFAD_E_STOP */
1448 bfa_sm_send_event(bfad
, BFAD_E_STOP
);
1450 /* Driver detach and dealloc mem */
1451 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1452 bfa_detach(&bfad
->bfa
);
1453 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1454 bfad_hal_mem_release(bfad
);
1456 /* Remove the debugfs node for this bfad */
1457 kfree(bfad
->regdata
);
1458 bfad_debugfs_exit(&bfad
->pport
);
1460 /* Cleaning the BFAD instance */
1461 mutex_lock(&bfad_mutex
);
1463 list_del(&bfad
->list_entry
);
1464 mutex_unlock(&bfad_mutex
);
1465 bfad_pci_uninit(pdev
, bfad
);
1467 kfree(bfad
->trcmod
);
1471 struct pci_device_id bfad_id_table
[] = {
1473 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1474 .device
= BFA_PCI_DEVICE_ID_FC_8G2P
,
1475 .subvendor
= PCI_ANY_ID
,
1476 .subdevice
= PCI_ANY_ID
,
1479 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1480 .device
= BFA_PCI_DEVICE_ID_FC_8G1P
,
1481 .subvendor
= PCI_ANY_ID
,
1482 .subdevice
= PCI_ANY_ID
,
1485 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1486 .device
= BFA_PCI_DEVICE_ID_CT
,
1487 .subvendor
= PCI_ANY_ID
,
1488 .subdevice
= PCI_ANY_ID
,
1489 .class = (PCI_CLASS_SERIAL_FIBER
<< 8),
1493 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1494 .device
= BFA_PCI_DEVICE_ID_CT_FC
,
1495 .subvendor
= PCI_ANY_ID
,
1496 .subdevice
= PCI_ANY_ID
,
1497 .class = (PCI_CLASS_SERIAL_FIBER
<< 8),
1501 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1502 .device
= BFA_PCI_DEVICE_ID_CT2
,
1503 .subvendor
= PCI_ANY_ID
,
1504 .subdevice
= PCI_ANY_ID
,
1505 .class = (PCI_CLASS_SERIAL_FIBER
<< 8),
1512 MODULE_DEVICE_TABLE(pci
, bfad_id_table
);
1514 static struct pci_driver bfad_pci_driver
= {
1515 .name
= BFAD_DRIVER_NAME
,
1516 .id_table
= bfad_id_table
,
1517 .probe
= bfad_pci_probe
,
1518 .remove
= __devexit_p(bfad_pci_remove
),
1522 * Driver module init.
1529 printk(KERN_INFO
"Brocade BFA FC/FCOE SCSI driver - version: %s\n",
1530 BFAD_DRIVER_VERSION
);
1533 num_sgpgs_parm
= num_sgpgs
;
1535 error
= bfad_im_module_init();
1538 printk(KERN_WARNING
"bfad_im_module_init failure\n");
1542 if (strcmp(FCPI_NAME
, " fcpim") == 0)
1543 supported_fc4s
|= BFA_LPORT_ROLE_FCP_IM
;
1545 bfa_auto_recover
= ioc_auto_recover
;
1546 bfa_fcs_rport_set_del_timeout(rport_del_timeout
);
1548 error
= pci_register_driver(&bfad_pci_driver
);
1550 printk(KERN_WARNING
"pci_register_driver failure\n");
1557 bfad_im_module_exit();
1562 * Driver module exit.
1567 pci_unregister_driver(&bfad_pci_driver
);
1568 bfad_im_module_exit();
1572 /* Firmware handling */
1574 bfad_read_firmware(struct pci_dev
*pdev
, u32
**bfi_image
,
1575 u32
*bfi_image_size
, char *fw_name
)
1577 const struct firmware
*fw
;
1579 if (request_firmware(&fw
, fw_name
, &pdev
->dev
)) {
1580 printk(KERN_ALERT
"Can't locate firmware %s\n", fw_name
);
1585 *bfi_image
= vmalloc(fw
->size
);
1586 if (NULL
== *bfi_image
) {
1587 printk(KERN_ALERT
"Fail to allocate buffer for fw image "
1588 "size=%x!\n", (u32
) fw
->size
);
1592 memcpy(*bfi_image
, fw
->data
, fw
->size
);
1593 *bfi_image_size
= fw
->size
/sizeof(u32
);
1595 release_firmware(fw
);
1599 bfad_load_fwimg(struct pci_dev
*pdev
)
1601 if (pdev
->device
== BFA_PCI_DEVICE_ID_CT2
) {
1602 if (bfi_image_ct2_size
== 0)
1603 bfad_read_firmware(pdev
, &bfi_image_ct2
,
1604 &bfi_image_ct2_size
, BFAD_FW_FILE_CT2
);
1605 return bfi_image_ct2
;
1606 } else if (bfa_asic_id_ct(pdev
->device
)) {
1607 if (bfi_image_ct_size
== 0)
1608 bfad_read_firmware(pdev
, &bfi_image_ct
,
1609 &bfi_image_ct_size
, BFAD_FW_FILE_CT
);
1610 return bfi_image_ct
;
1612 if (bfi_image_cb_size
== 0)
1613 bfad_read_firmware(pdev
, &bfi_image_cb
,
1614 &bfi_image_cb_size
, BFAD_FW_FILE_CB
);
1615 return bfi_image_cb
;
1620 bfad_free_fwimg(void)
1622 if (bfi_image_ct2_size
&& bfi_image_ct2
)
1623 vfree(bfi_image_ct2
);
1624 if (bfi_image_ct_size
&& bfi_image_ct
)
1625 vfree(bfi_image_ct
);
1626 if (bfi_image_cb_size
&& bfi_image_cb
)
1627 vfree(bfi_image_cb
);
1630 module_init(bfad_init
);
1631 module_exit(bfad_exit
);
1632 MODULE_LICENSE("GPL");
1633 MODULE_DESCRIPTION("Brocade Fibre Channel HBA Driver" BFAD_PROTO_NAME
);
1634 MODULE_AUTHOR("Brocade Communications Systems, Inc.");
1635 MODULE_VERSION(BFAD_DRIVER_VERSION
);