1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4 * Copyright (c) 2014- QLogic Corporation.
8 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
12 * bfad.c Linux driver PCI interface module.
14 #include <linux/module.h>
15 #include <linux/kthread.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/init.h>
20 #include <linux/pci.h>
21 #include <linux/firmware.h>
22 #include <linux/uaccess.h>
23 #include <asm/fcntl.h>
31 BFA_TRC_FILE(LDRV
, BFAD
);
32 DEFINE_MUTEX(bfad_mutex
);
36 static int num_sgpgs_parm
;
38 char *host_name
, *os_name
, *os_patch
;
39 int num_rports
, num_ios
, num_tms
;
40 int num_fcxps
, num_ufbufs
;
41 int reqq_size
, rspq_size
, num_sgpgs
;
42 int rport_del_timeout
= BFA_FCS_RPORT_DEF_DEL_TIMEOUT
;
43 int bfa_lun_queue_depth
= BFAD_LUN_QUEUE_DEPTH
;
44 int bfa_io_max_sge
= BFAD_IO_MAX_SGE
;
45 int bfa_log_level
= 3; /* WARNING log level */
46 int ioc_auto_recover
= BFA_TRUE
;
47 int bfa_linkup_delay
= -1;
48 int fdmi_enable
= BFA_TRUE
;
49 int pcie_max_read_reqsz
;
50 int bfa_debugfs_enable
= 1;
51 int msix_disable_cb
= 0, msix_disable_ct
= 0;
52 int max_xfer_size
= BFAD_MAX_SECTORS
>> 1;
53 int max_rport_logins
= BFA_FCS_MAX_RPORT_LOGINS
;
55 /* Firmware releated */
56 u32 bfi_image_cb_size
, bfi_image_ct_size
, bfi_image_ct2_size
;
57 u32
*bfi_image_cb
, *bfi_image_ct
, *bfi_image_ct2
;
59 #define BFAD_FW_FILE_CB "cbfw-3.2.5.1.bin"
60 #define BFAD_FW_FILE_CT "ctfw-3.2.5.1.bin"
61 #define BFAD_FW_FILE_CT2 "ct2fw-3.2.5.1.bin"
63 static u32
*bfad_load_fwimg(struct pci_dev
*pdev
);
64 static void bfad_free_fwimg(void);
65 static void bfad_read_firmware(struct pci_dev
*pdev
, u32
**bfi_image
,
66 u32
*bfi_image_size
, char *fw_name
);
68 static const char *msix_name_ct
[] = {
70 "cpe0", "cpe1", "cpe2", "cpe3",
71 "rme0", "rme1", "rme2", "rme3" };
73 static const char *msix_name_cb
[] = {
74 "cpe0", "cpe1", "cpe2", "cpe3",
75 "rme0", "rme1", "rme2", "rme3",
76 "eemc", "elpu0", "elpu1", "epss", "mlpu" };
78 MODULE_FIRMWARE(BFAD_FW_FILE_CB
);
79 MODULE_FIRMWARE(BFAD_FW_FILE_CT
);
80 MODULE_FIRMWARE(BFAD_FW_FILE_CT2
);
82 module_param(os_name
, charp
, S_IRUGO
| S_IWUSR
);
83 MODULE_PARM_DESC(os_name
, "OS name of the hba host machine");
84 module_param(os_patch
, charp
, S_IRUGO
| S_IWUSR
);
85 MODULE_PARM_DESC(os_patch
, "OS patch level of the hba host machine");
86 module_param(host_name
, charp
, S_IRUGO
| S_IWUSR
);
87 MODULE_PARM_DESC(host_name
, "Hostname of the hba host machine");
88 module_param(num_rports
, int, S_IRUGO
| S_IWUSR
);
89 MODULE_PARM_DESC(num_rports
, "Max number of rports supported per port "
90 "(physical/logical), default=1024");
91 module_param(num_ios
, int, S_IRUGO
| S_IWUSR
);
92 MODULE_PARM_DESC(num_ios
, "Max number of ioim requests, default=2000");
93 module_param(num_tms
, int, S_IRUGO
| S_IWUSR
);
94 MODULE_PARM_DESC(num_tms
, "Max number of task im requests, default=128");
95 module_param(num_fcxps
, int, S_IRUGO
| S_IWUSR
);
96 MODULE_PARM_DESC(num_fcxps
, "Max number of fcxp requests, default=64");
97 module_param(num_ufbufs
, int, S_IRUGO
| S_IWUSR
);
98 MODULE_PARM_DESC(num_ufbufs
, "Max number of unsolicited frame "
99 "buffers, default=64");
100 module_param(reqq_size
, int, S_IRUGO
| S_IWUSR
);
101 MODULE_PARM_DESC(reqq_size
, "Max number of request queue elements, "
103 module_param(rspq_size
, int, S_IRUGO
| S_IWUSR
);
104 MODULE_PARM_DESC(rspq_size
, "Max number of response queue elements, "
106 module_param(num_sgpgs
, int, S_IRUGO
| S_IWUSR
);
107 MODULE_PARM_DESC(num_sgpgs
, "Number of scatter/gather pages, default=2048");
108 module_param(rport_del_timeout
, int, S_IRUGO
| S_IWUSR
);
109 MODULE_PARM_DESC(rport_del_timeout
, "Rport delete timeout, default=90 secs, "
111 module_param(bfa_lun_queue_depth
, int, S_IRUGO
| S_IWUSR
);
112 MODULE_PARM_DESC(bfa_lun_queue_depth
, "Lun queue depth, default=32, Range[>0]");
113 module_param(bfa_io_max_sge
, int, S_IRUGO
| S_IWUSR
);
114 MODULE_PARM_DESC(bfa_io_max_sge
, "Max io scatter/gather elements, default=255");
115 module_param(bfa_log_level
, int, S_IRUGO
| S_IWUSR
);
116 MODULE_PARM_DESC(bfa_log_level
, "Driver log level, default=3, "
117 "Range[Critical:1|Error:2|Warning:3|Info:4]");
118 module_param(ioc_auto_recover
, int, S_IRUGO
| S_IWUSR
);
119 MODULE_PARM_DESC(ioc_auto_recover
, "IOC auto recovery, default=1, "
120 "Range[off:0|on:1]");
121 module_param(bfa_linkup_delay
, int, S_IRUGO
| S_IWUSR
);
122 MODULE_PARM_DESC(bfa_linkup_delay
, "Link up delay, default=30 secs for "
123 "boot port. Otherwise 10 secs in RHEL4 & 0 for "
124 "[RHEL5, SLES10, ESX40] Range[>0]");
125 module_param(msix_disable_cb
, int, S_IRUGO
| S_IWUSR
);
126 MODULE_PARM_DESC(msix_disable_cb
, "Disable Message Signaled Interrupts for QLogic-415/425/815/825 cards, default=0 Range[false:0|true:1]");
127 module_param(msix_disable_ct
, int, S_IRUGO
| S_IWUSR
);
128 MODULE_PARM_DESC(msix_disable_ct
, "Disable Message Signaled Interrupts if possible for QLogic-1010/1020/804/1007/902/1741 cards, default=0, Range[false:0|true:1]");
129 module_param(fdmi_enable
, int, S_IRUGO
| S_IWUSR
);
130 MODULE_PARM_DESC(fdmi_enable
, "Enables fdmi registration, default=1, "
131 "Range[false:0|true:1]");
132 module_param(pcie_max_read_reqsz
, int, S_IRUGO
| S_IWUSR
);
133 MODULE_PARM_DESC(pcie_max_read_reqsz
, "PCIe max read request size, default=0 "
134 "(use system setting), Range[128|256|512|1024|2048|4096]");
135 module_param(bfa_debugfs_enable
, int, S_IRUGO
| S_IWUSR
);
136 MODULE_PARM_DESC(bfa_debugfs_enable
, "Enables debugfs feature, default=1,"
137 " Range[false:0|true:1]");
138 module_param(max_xfer_size
, int, S_IRUGO
| S_IWUSR
);
139 MODULE_PARM_DESC(max_xfer_size
, "default=32MB,"
140 " Range[64k|128k|256k|512k|1024k|2048k]");
141 module_param(max_rport_logins
, int, S_IRUGO
| S_IWUSR
);
142 MODULE_PARM_DESC(max_rport_logins
, "Max number of logins to initiator and target rports on a port (physical/logical), default=1024");
145 bfad_sm_uninit(struct bfad_s
*bfad
, enum bfad_sm_event event
);
147 bfad_sm_created(struct bfad_s
*bfad
, enum bfad_sm_event event
);
149 bfad_sm_initializing(struct bfad_s
*bfad
, enum bfad_sm_event event
);
151 bfad_sm_operational(struct bfad_s
*bfad
, enum bfad_sm_event event
);
153 bfad_sm_stopping(struct bfad_s
*bfad
, enum bfad_sm_event event
);
155 bfad_sm_failed(struct bfad_s
*bfad
, enum bfad_sm_event event
);
157 bfad_sm_fcs_exit(struct bfad_s
*bfad
, enum bfad_sm_event event
);
160 * Beginning state for the driver instance, awaiting the pci_probe event
163 bfad_sm_uninit(struct bfad_s
*bfad
, enum bfad_sm_event event
)
165 bfa_trc(bfad
, event
);
169 bfa_sm_set_state(bfad
, bfad_sm_created
);
170 bfad
->bfad_tsk
= kthread_create(bfad_worker
, (void *) bfad
,
171 "%s", "bfad_worker");
172 if (IS_ERR(bfad
->bfad_tsk
)) {
173 printk(KERN_INFO
"bfad[%d]: Kernel thread "
174 "creation failed!\n", bfad
->inst_no
);
175 bfa_sm_send_event(bfad
, BFAD_E_KTHREAD_CREATE_FAILED
);
177 bfa_sm_send_event(bfad
, BFAD_E_INIT
);
181 /* Ignore stop; already in uninit */
185 bfa_sm_fault(bfad
, event
);
190 * Driver Instance is created, awaiting event INIT to initialize the bfad
193 bfad_sm_created(struct bfad_s
*bfad
, enum bfad_sm_event event
)
198 bfa_trc(bfad
, event
);
202 bfa_sm_set_state(bfad
, bfad_sm_initializing
);
204 init_completion(&bfad
->comp
);
206 /* Enable Interrupt and wait bfa_init completion */
207 if (bfad_setup_intr(bfad
)) {
208 printk(KERN_WARNING
"bfad%d: bfad_setup_intr failed\n",
210 bfa_sm_send_event(bfad
, BFAD_E_INIT_FAILED
);
214 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
215 bfa_iocfc_init(&bfad
->bfa
);
216 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
218 /* Set up interrupt handler for each vectors */
219 if ((bfad
->bfad_flags
& BFAD_MSIX_ON
) &&
220 bfad_install_msix_handler(bfad
)) {
221 printk(KERN_WARNING
"%s: install_msix failed, bfad%d\n",
222 __func__
, bfad
->inst_no
);
225 bfad_init_timer(bfad
);
227 wait_for_completion(&bfad
->comp
);
229 if ((bfad
->bfad_flags
& BFAD_HAL_INIT_DONE
)) {
230 bfa_sm_send_event(bfad
, BFAD_E_INIT_SUCCESS
);
233 "bfa %s: bfa init failed\n",
235 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
236 bfa_fcs_init(&bfad
->bfa_fcs
);
237 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
239 ret
= bfad_cfg_pport(bfad
, BFA_LPORT_ROLE_FCP_IM
);
240 if (ret
!= BFA_STATUS_OK
) {
241 init_completion(&bfad
->comp
);
243 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
244 bfad
->pport
.flags
|= BFAD_PORT_DELETE
;
245 bfa_fcs_exit(&bfad
->bfa_fcs
);
246 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
248 wait_for_completion(&bfad
->comp
);
250 bfa_sm_send_event(bfad
, BFAD_E_INIT_FAILED
);
253 bfad
->bfad_flags
|= BFAD_HAL_INIT_FAIL
;
254 bfa_sm_send_event(bfad
, BFAD_E_HAL_INIT_FAILED
);
259 case BFAD_E_KTHREAD_CREATE_FAILED
:
260 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
264 bfa_sm_fault(bfad
, event
);
269 bfad_sm_initializing(struct bfad_s
*bfad
, enum bfad_sm_event event
)
274 bfa_trc(bfad
, event
);
277 case BFAD_E_INIT_SUCCESS
:
278 kthread_stop(bfad
->bfad_tsk
);
279 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
280 bfad
->bfad_tsk
= NULL
;
281 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
283 retval
= bfad_start_ops(bfad
);
284 if (retval
!= BFA_STATUS_OK
) {
285 bfa_sm_set_state(bfad
, bfad_sm_failed
);
288 bfa_sm_set_state(bfad
, bfad_sm_operational
);
291 case BFAD_E_INIT_FAILED
:
292 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
293 kthread_stop(bfad
->bfad_tsk
);
294 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
295 bfad
->bfad_tsk
= NULL
;
296 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
299 case BFAD_E_HAL_INIT_FAILED
:
300 bfa_sm_set_state(bfad
, bfad_sm_failed
);
303 bfa_sm_fault(bfad
, event
);
308 bfad_sm_failed(struct bfad_s
*bfad
, enum bfad_sm_event event
)
312 bfa_trc(bfad
, event
);
315 case BFAD_E_INIT_SUCCESS
:
316 retval
= bfad_start_ops(bfad
);
317 if (retval
!= BFA_STATUS_OK
)
319 bfa_sm_set_state(bfad
, bfad_sm_operational
);
323 bfa_sm_set_state(bfad
, bfad_sm_fcs_exit
);
324 bfa_sm_send_event(bfad
, BFAD_E_FCS_EXIT_COMP
);
327 case BFAD_E_EXIT_COMP
:
328 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
329 bfad_remove_intr(bfad
);
330 del_timer_sync(&bfad
->hal_tmo
);
334 bfa_sm_fault(bfad
, event
);
339 bfad_sm_operational(struct bfad_s
*bfad
, enum bfad_sm_event event
)
341 bfa_trc(bfad
, event
);
345 bfa_sm_set_state(bfad
, bfad_sm_fcs_exit
);
350 bfa_sm_fault(bfad
, event
);
355 bfad_sm_fcs_exit(struct bfad_s
*bfad
, enum bfad_sm_event event
)
357 bfa_trc(bfad
, event
);
360 case BFAD_E_FCS_EXIT_COMP
:
361 bfa_sm_set_state(bfad
, bfad_sm_stopping
);
366 bfa_sm_fault(bfad
, event
);
371 bfad_sm_stopping(struct bfad_s
*bfad
, enum bfad_sm_event event
)
373 bfa_trc(bfad
, event
);
376 case BFAD_E_EXIT_COMP
:
377 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
378 bfad_remove_intr(bfad
);
379 del_timer_sync(&bfad
->hal_tmo
);
380 bfad_im_probe_undo(bfad
);
381 bfad
->bfad_flags
&= ~BFAD_FC4_PROBE_DONE
;
382 bfad_uncfg_pport(bfad
);
386 bfa_sm_fault(bfad
, event
);
395 bfad_hcb_comp(void *arg
, bfa_status_t status
)
397 struct bfad_hal_comp
*fcomp
= (struct bfad_hal_comp
*)arg
;
399 fcomp
->status
= status
;
400 complete(&fcomp
->comp
);
407 bfa_cb_init(void *drv
, bfa_status_t init_status
)
409 struct bfad_s
*bfad
= drv
;
411 if (init_status
== BFA_STATUS_OK
) {
412 bfad
->bfad_flags
|= BFAD_HAL_INIT_DONE
;
415 * If BFAD_HAL_INIT_FAIL flag is set:
416 * Wake up the kernel thread to start
417 * the bfad operations after HAL init done
419 if ((bfad
->bfad_flags
& BFAD_HAL_INIT_FAIL
)) {
420 bfad
->bfad_flags
&= ~BFAD_HAL_INIT_FAIL
;
421 wake_up_process(bfad
->bfad_tsk
);
425 complete(&bfad
->comp
);
432 bfa_fcb_lport_new(struct bfad_s
*bfad
, struct bfa_fcs_lport_s
*port
,
433 enum bfa_lport_role roles
, struct bfad_vf_s
*vf_drv
,
434 struct bfad_vport_s
*vp_drv
)
437 struct bfad_port_s
*port_drv
;
439 if (!vp_drv
&& !vf_drv
) {
440 port_drv
= &bfad
->pport
;
441 port_drv
->pvb_type
= BFAD_PORT_PHYS_BASE
;
442 } else if (!vp_drv
&& vf_drv
) {
443 port_drv
= &vf_drv
->base_port
;
444 port_drv
->pvb_type
= BFAD_PORT_VF_BASE
;
445 } else if (vp_drv
&& !vf_drv
) {
446 port_drv
= &vp_drv
->drv_port
;
447 port_drv
->pvb_type
= BFAD_PORT_PHYS_VPORT
;
449 port_drv
= &vp_drv
->drv_port
;
450 port_drv
->pvb_type
= BFAD_PORT_VF_VPORT
;
453 port_drv
->fcs_port
= port
;
454 port_drv
->roles
= roles
;
456 if (roles
& BFA_LPORT_ROLE_FCP_IM
) {
457 rc
= bfad_im_port_new(bfad
, port_drv
);
458 if (rc
!= BFA_STATUS_OK
) {
459 bfad_im_port_delete(bfad
, port_drv
);
468 * FCS RPORT alloc callback, after successful PLOGI by FCS
471 bfa_fcb_rport_alloc(struct bfad_s
*bfad
, struct bfa_fcs_rport_s
**rport
,
472 struct bfad_rport_s
**rport_drv
)
474 bfa_status_t rc
= BFA_STATUS_OK
;
476 *rport_drv
= kzalloc(sizeof(struct bfad_rport_s
), GFP_ATOMIC
);
477 if (*rport_drv
== NULL
) {
478 rc
= BFA_STATUS_ENOMEM
;
482 *rport
= &(*rport_drv
)->fcs_rport
;
489 * FCS PBC VPORT Create
492 bfa_fcb_pbc_vport_create(struct bfad_s
*bfad
, struct bfi_pbc_vport_s pbc_vport
)
495 struct bfa_lport_cfg_s port_cfg
= {0};
496 struct bfad_vport_s
*vport
;
499 vport
= kzalloc(sizeof(struct bfad_vport_s
), GFP_ATOMIC
);
505 vport
->drv_port
.bfad
= bfad
;
506 port_cfg
.roles
= BFA_LPORT_ROLE_FCP_IM
;
507 port_cfg
.pwwn
= pbc_vport
.vp_pwwn
;
508 port_cfg
.nwwn
= pbc_vport
.vp_nwwn
;
509 port_cfg
.preboot_vp
= BFA_TRUE
;
511 rc
= bfa_fcs_pbc_vport_create(&vport
->fcs_vport
, &bfad
->bfa_fcs
, 0,
514 if (rc
!= BFA_STATUS_OK
) {
519 list_add_tail(&vport
->list_entry
, &bfad
->pbc_vport_list
);
523 bfad_hal_mem_release(struct bfad_s
*bfad
)
525 struct bfa_meminfo_s
*hal_meminfo
= &bfad
->meminfo
;
526 struct bfa_mem_dma_s
*dma_info
, *dma_elem
;
527 struct bfa_mem_kva_s
*kva_info
, *kva_elem
;
528 struct list_head
*dm_qe
, *km_qe
;
530 dma_info
= &hal_meminfo
->dma_info
;
531 kva_info
= &hal_meminfo
->kva_info
;
533 /* Iterate through the KVA meminfo queue */
534 list_for_each(km_qe
, &kva_info
->qe
) {
535 kva_elem
= (struct bfa_mem_kva_s
*) km_qe
;
536 vfree(kva_elem
->kva
);
539 /* Iterate through the DMA meminfo queue */
540 list_for_each(dm_qe
, &dma_info
->qe
) {
541 dma_elem
= (struct bfa_mem_dma_s
*) dm_qe
;
542 dma_free_coherent(&bfad
->pcidev
->dev
,
543 dma_elem
->mem_len
, dma_elem
->kva
,
544 (dma_addr_t
) dma_elem
->dma
);
547 memset(hal_meminfo
, 0, sizeof(struct bfa_meminfo_s
));
551 bfad_update_hal_cfg(struct bfa_iocfc_cfg_s
*bfa_cfg
)
554 bfa_cfg
->fwcfg
.num_rports
= num_rports
;
556 bfa_cfg
->fwcfg
.num_ioim_reqs
= num_ios
;
558 bfa_cfg
->fwcfg
.num_tskim_reqs
= num_tms
;
559 if (num_fcxps
> 0 && num_fcxps
<= BFA_FCXP_MAX
)
560 bfa_cfg
->fwcfg
.num_fcxp_reqs
= num_fcxps
;
561 if (num_ufbufs
> 0 && num_ufbufs
<= BFA_UF_MAX
)
562 bfa_cfg
->fwcfg
.num_uf_bufs
= num_ufbufs
;
564 bfa_cfg
->drvcfg
.num_reqq_elems
= reqq_size
;
566 bfa_cfg
->drvcfg
.num_rspq_elems
= rspq_size
;
567 if (num_sgpgs
> 0 && num_sgpgs
<= BFA_SGPG_MAX
)
568 bfa_cfg
->drvcfg
.num_sgpgs
= num_sgpgs
;
571 * populate the hal values back to the driver for sysfs use.
572 * otherwise, the default values will be shown as 0 in sysfs
574 num_rports
= bfa_cfg
->fwcfg
.num_rports
;
575 num_ios
= bfa_cfg
->fwcfg
.num_ioim_reqs
;
576 num_tms
= bfa_cfg
->fwcfg
.num_tskim_reqs
;
577 num_fcxps
= bfa_cfg
->fwcfg
.num_fcxp_reqs
;
578 num_ufbufs
= bfa_cfg
->fwcfg
.num_uf_bufs
;
579 reqq_size
= bfa_cfg
->drvcfg
.num_reqq_elems
;
580 rspq_size
= bfa_cfg
->drvcfg
.num_rspq_elems
;
581 num_sgpgs
= bfa_cfg
->drvcfg
.num_sgpgs
;
585 bfad_hal_mem_alloc(struct bfad_s
*bfad
)
587 struct bfa_meminfo_s
*hal_meminfo
= &bfad
->meminfo
;
588 struct bfa_mem_dma_s
*dma_info
, *dma_elem
;
589 struct bfa_mem_kva_s
*kva_info
, *kva_elem
;
590 struct list_head
*dm_qe
, *km_qe
;
591 bfa_status_t rc
= BFA_STATUS_OK
;
592 dma_addr_t phys_addr
;
594 bfa_cfg_get_default(&bfad
->ioc_cfg
);
595 bfad_update_hal_cfg(&bfad
->ioc_cfg
);
596 bfad
->cfg_data
.ioc_queue_depth
= bfad
->ioc_cfg
.fwcfg
.num_ioim_reqs
;
597 bfa_cfg_get_meminfo(&bfad
->ioc_cfg
, hal_meminfo
, &bfad
->bfa
);
599 dma_info
= &hal_meminfo
->dma_info
;
600 kva_info
= &hal_meminfo
->kva_info
;
602 /* Iterate through the KVA meminfo queue */
603 list_for_each(km_qe
, &kva_info
->qe
) {
604 kva_elem
= (struct bfa_mem_kva_s
*) km_qe
;
605 kva_elem
->kva
= vzalloc(kva_elem
->mem_len
);
606 if (kva_elem
->kva
== NULL
) {
607 bfad_hal_mem_release(bfad
);
608 rc
= BFA_STATUS_ENOMEM
;
613 /* Iterate through the DMA meminfo queue */
614 list_for_each(dm_qe
, &dma_info
->qe
) {
615 dma_elem
= (struct bfa_mem_dma_s
*) dm_qe
;
616 dma_elem
->kva
= dma_alloc_coherent(&bfad
->pcidev
->dev
,
618 &phys_addr
, GFP_KERNEL
);
619 if (dma_elem
->kva
== NULL
) {
620 bfad_hal_mem_release(bfad
);
621 rc
= BFA_STATUS_ENOMEM
;
624 dma_elem
->dma
= phys_addr
;
625 memset(dma_elem
->kva
, 0, dma_elem
->mem_len
);
632 * Create a vport under a vf.
635 bfad_vport_create(struct bfad_s
*bfad
, u16 vf_id
,
636 struct bfa_lport_cfg_s
*port_cfg
, struct device
*dev
)
638 struct bfad_vport_s
*vport
;
639 int rc
= BFA_STATUS_OK
;
641 struct completion fcomp
;
643 vport
= kzalloc(sizeof(struct bfad_vport_s
), GFP_KERNEL
);
645 rc
= BFA_STATUS_ENOMEM
;
649 vport
->drv_port
.bfad
= bfad
;
650 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
651 rc
= bfa_fcs_vport_create(&vport
->fcs_vport
, &bfad
->bfa_fcs
, vf_id
,
653 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
655 if (rc
!= BFA_STATUS_OK
)
658 if (port_cfg
->roles
& BFA_LPORT_ROLE_FCP_IM
) {
659 rc
= bfad_im_scsi_host_alloc(bfad
, vport
->drv_port
.im_port
,
661 if (rc
!= BFA_STATUS_OK
)
662 goto ext_free_fcs_vport
;
665 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
666 bfa_fcs_vport_start(&vport
->fcs_vport
);
667 list_add_tail(&vport
->list_entry
, &bfad
->vport_list
);
668 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
670 return BFA_STATUS_OK
;
673 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
674 vport
->comp_del
= &fcomp
;
675 init_completion(vport
->comp_del
);
676 bfa_fcs_vport_delete(&vport
->fcs_vport
);
677 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
678 wait_for_completion(vport
->comp_del
);
686 bfad_bfa_tmo(struct timer_list
*t
)
688 struct bfad_s
*bfad
= from_timer(bfad
, t
, hal_tmo
);
690 struct list_head doneq
;
692 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
694 bfa_timer_beat(&bfad
->bfa
.timer_mod
);
696 bfa_comp_deq(&bfad
->bfa
, &doneq
);
697 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
699 if (!list_empty(&doneq
)) {
700 bfa_comp_process(&bfad
->bfa
, &doneq
);
701 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
702 bfa_comp_free(&bfad
->bfa
, &doneq
);
703 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
706 mod_timer(&bfad
->hal_tmo
,
707 jiffies
+ msecs_to_jiffies(BFA_TIMER_FREQ
));
711 bfad_init_timer(struct bfad_s
*bfad
)
713 timer_setup(&bfad
->hal_tmo
, bfad_bfa_tmo
, 0);
715 mod_timer(&bfad
->hal_tmo
,
716 jiffies
+ msecs_to_jiffies(BFA_TIMER_FREQ
));
720 bfad_pci_init(struct pci_dev
*pdev
, struct bfad_s
*bfad
)
724 if (pci_enable_device(pdev
)) {
725 printk(KERN_ERR
"pci_enable_device fail %p\n", pdev
);
729 if (pci_request_regions(pdev
, BFAD_DRIVER_NAME
))
730 goto out_disable_device
;
732 pci_set_master(pdev
);
734 rc
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(64));
736 rc
= dma_set_mask_and_coherent(&pdev
->dev
, DMA_BIT_MASK(32));
740 printk(KERN_ERR
"dma_set_mask_and_coherent fail %p\n", pdev
);
741 goto out_release_region
;
744 /* Enable PCIE Advanced Error Recovery (AER) if kernel supports */
745 pci_enable_pcie_error_reporting(pdev
);
747 bfad
->pci_bar0_kva
= pci_iomap(pdev
, 0, pci_resource_len(pdev
, 0));
748 bfad
->pci_bar2_kva
= pci_iomap(pdev
, 2, pci_resource_len(pdev
, 2));
750 if (bfad
->pci_bar0_kva
== NULL
) {
751 printk(KERN_ERR
"Fail to map bar0\n");
752 goto out_release_region
;
755 bfad
->hal_pcidev
.pci_slot
= PCI_SLOT(pdev
->devfn
);
756 bfad
->hal_pcidev
.pci_func
= PCI_FUNC(pdev
->devfn
);
757 bfad
->hal_pcidev
.pci_bar_kva
= bfad
->pci_bar0_kva
;
758 bfad
->hal_pcidev
.device_id
= pdev
->device
;
759 bfad
->hal_pcidev
.ssid
= pdev
->subsystem_device
;
760 bfad
->pci_name
= pci_name(pdev
);
762 bfad
->pci_attr
.vendor_id
= pdev
->vendor
;
763 bfad
->pci_attr
.device_id
= pdev
->device
;
764 bfad
->pci_attr
.ssid
= pdev
->subsystem_device
;
765 bfad
->pci_attr
.ssvid
= pdev
->subsystem_vendor
;
766 bfad
->pci_attr
.pcifn
= PCI_FUNC(pdev
->devfn
);
770 /* Adjust PCIe Maximum Read Request Size */
771 if (pci_is_pcie(pdev
) && pcie_max_read_reqsz
) {
772 if (pcie_max_read_reqsz
>= 128 &&
773 pcie_max_read_reqsz
<= 4096 &&
774 is_power_of_2(pcie_max_read_reqsz
)) {
775 int max_rq
= pcie_get_readrq(pdev
);
776 printk(KERN_WARNING
"BFA[%s]: "
777 "pcie_max_read_request_size is %d, "
778 "reset to %d\n", bfad
->pci_name
, max_rq
,
779 pcie_max_read_reqsz
);
780 pcie_set_readrq(pdev
, pcie_max_read_reqsz
);
782 printk(KERN_WARNING
"BFA[%s]: invalid "
783 "pcie_max_read_request_size %d ignored\n",
784 bfad
->pci_name
, pcie_max_read_reqsz
);
788 pci_save_state(pdev
);
793 pci_release_regions(pdev
);
795 pci_disable_device(pdev
);
801 bfad_pci_uninit(struct pci_dev
*pdev
, struct bfad_s
*bfad
)
803 pci_iounmap(pdev
, bfad
->pci_bar0_kva
);
804 pci_iounmap(pdev
, bfad
->pci_bar2_kva
);
805 pci_release_regions(pdev
);
806 /* Disable PCIE Advanced Error Recovery (AER) */
807 pci_disable_pcie_error_reporting(pdev
);
808 pci_disable_device(pdev
);
812 bfad_drv_init(struct bfad_s
*bfad
)
817 bfad
->cfg_data
.rport_del_timeout
= rport_del_timeout
;
818 bfad
->cfg_data
.lun_queue_depth
= bfa_lun_queue_depth
;
819 bfad
->cfg_data
.io_max_sge
= bfa_io_max_sge
;
820 bfad
->cfg_data
.binding_method
= FCP_PWWN_BINDING
;
822 rc
= bfad_hal_mem_alloc(bfad
);
823 if (rc
!= BFA_STATUS_OK
) {
824 printk(KERN_WARNING
"bfad%d bfad_hal_mem_alloc failure\n",
827 "Not enough memory to attach all QLogic BR-series HBA ports. System may need more memory.\n");
828 return BFA_STATUS_FAILED
;
831 bfad
->bfa
.trcmod
= bfad
->trcmod
;
832 bfad
->bfa
.plog
= &bfad
->plog_buf
;
833 bfa_plog_init(&bfad
->plog_buf
);
834 bfa_plog_str(&bfad
->plog_buf
, BFA_PL_MID_DRVR
, BFA_PL_EID_DRIVER_START
,
837 bfa_attach(&bfad
->bfa
, bfad
, &bfad
->ioc_cfg
, &bfad
->meminfo
,
841 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
842 bfad
->bfa_fcs
.trcmod
= bfad
->trcmod
;
843 bfa_fcs_attach(&bfad
->bfa_fcs
, &bfad
->bfa
, bfad
, BFA_FALSE
);
844 bfad
->bfa_fcs
.fdmi_enabled
= fdmi_enable
;
845 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
847 bfad
->bfad_flags
|= BFAD_DRV_INIT_DONE
;
849 return BFA_STATUS_OK
;
853 bfad_drv_uninit(struct bfad_s
*bfad
)
857 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
858 init_completion(&bfad
->comp
);
859 bfa_iocfc_stop(&bfad
->bfa
);
860 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
861 wait_for_completion(&bfad
->comp
);
863 del_timer_sync(&bfad
->hal_tmo
);
864 bfa_isr_disable(&bfad
->bfa
);
865 bfa_detach(&bfad
->bfa
);
866 bfad_remove_intr(bfad
);
867 bfad_hal_mem_release(bfad
);
869 bfad
->bfad_flags
&= ~BFAD_DRV_INIT_DONE
;
873 bfad_drv_start(struct bfad_s
*bfad
)
877 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
878 bfa_iocfc_start(&bfad
->bfa
);
879 bfa_fcs_pbc_vport_init(&bfad
->bfa_fcs
);
880 bfa_fcs_fabric_modstart(&bfad
->bfa_fcs
);
881 bfad
->bfad_flags
|= BFAD_HAL_START_DONE
;
882 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
885 flush_workqueue(bfad
->im
->drv_workq
);
889 bfad_fcs_stop(struct bfad_s
*bfad
)
893 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
894 init_completion(&bfad
->comp
);
895 bfad
->pport
.flags
|= BFAD_PORT_DELETE
;
896 bfa_fcs_exit(&bfad
->bfa_fcs
);
897 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
898 wait_for_completion(&bfad
->comp
);
900 bfa_sm_send_event(bfad
, BFAD_E_FCS_EXIT_COMP
);
904 bfad_stop(struct bfad_s
*bfad
)
908 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
909 init_completion(&bfad
->comp
);
910 bfa_iocfc_stop(&bfad
->bfa
);
911 bfad
->bfad_flags
&= ~BFAD_HAL_START_DONE
;
912 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
913 wait_for_completion(&bfad
->comp
);
915 bfa_sm_send_event(bfad
, BFAD_E_EXIT_COMP
);
919 bfad_cfg_pport(struct bfad_s
*bfad
, enum bfa_lport_role role
)
921 int rc
= BFA_STATUS_OK
;
923 /* Allocate scsi_host for the physical port */
924 if ((supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
) &&
925 (role
& BFA_LPORT_ROLE_FCP_IM
)) {
926 if (bfad
->pport
.im_port
== NULL
) {
927 rc
= BFA_STATUS_FAILED
;
931 rc
= bfad_im_scsi_host_alloc(bfad
, bfad
->pport
.im_port
,
933 if (rc
!= BFA_STATUS_OK
)
936 bfad
->pport
.roles
|= BFA_LPORT_ROLE_FCP_IM
;
939 bfad
->bfad_flags
|= BFAD_CFG_PPORT_DONE
;
946 bfad_uncfg_pport(struct bfad_s
*bfad
)
948 if ((supported_fc4s
& BFA_LPORT_ROLE_FCP_IM
) &&
949 (bfad
->pport
.roles
& BFA_LPORT_ROLE_FCP_IM
)) {
950 bfad_im_scsi_host_free(bfad
, bfad
->pport
.im_port
);
951 bfad_im_port_clean(bfad
->pport
.im_port
);
952 kfree(bfad
->pport
.im_port
);
953 bfad
->pport
.roles
&= ~BFA_LPORT_ROLE_FCP_IM
;
956 bfad
->bfad_flags
&= ~BFAD_CFG_PPORT_DONE
;
960 bfad_start_ops(struct bfad_s
*bfad
) {
964 struct bfad_vport_s
*vport
, *vport_new
;
965 struct bfa_fcs_driver_info_s driver_info
;
967 /* Limit min/max. xfer size to [64k-32MB] */
968 if (max_xfer_size
< BFAD_MIN_SECTORS
>> 1)
969 max_xfer_size
= BFAD_MIN_SECTORS
>> 1;
970 if (max_xfer_size
> BFAD_MAX_SECTORS
>> 1)
971 max_xfer_size
= BFAD_MAX_SECTORS
>> 1;
973 /* Fill the driver_info info to fcs*/
974 memset(&driver_info
, 0, sizeof(driver_info
));
975 strlcpy(driver_info
.version
, BFAD_DRIVER_VERSION
,
976 sizeof(driver_info
.version
));
978 strlcpy(driver_info
.host_machine_name
, host_name
,
979 sizeof(driver_info
.host_machine_name
));
981 strlcpy(driver_info
.host_os_name
, os_name
,
982 sizeof(driver_info
.host_os_name
));
984 strlcpy(driver_info
.host_os_patch
, os_patch
,
985 sizeof(driver_info
.host_os_patch
));
987 strlcpy(driver_info
.os_device_name
, bfad
->pci_name
,
988 sizeof(driver_info
.os_device_name
));
990 /* FCS driver info init */
991 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
992 bfa_fcs_driver_info_init(&bfad
->bfa_fcs
, &driver_info
);
994 if (bfad
->bfad_flags
& BFAD_CFG_PPORT_DONE
)
995 bfa_fcs_update_cfg(&bfad
->bfa_fcs
);
997 bfa_fcs_init(&bfad
->bfa_fcs
);
999 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1001 if (!(bfad
->bfad_flags
& BFAD_CFG_PPORT_DONE
)) {
1002 retval
= bfad_cfg_pport(bfad
, BFA_LPORT_ROLE_FCP_IM
);
1003 if (retval
!= BFA_STATUS_OK
)
1004 return BFA_STATUS_FAILED
;
1007 /* Setup fc host fixed attribute if the lk supports */
1008 bfad_fc_host_init(bfad
->pport
.im_port
);
1010 /* BFAD level FC4 IM specific resource allocation */
1011 retval
= bfad_im_probe(bfad
);
1012 if (retval
!= BFA_STATUS_OK
) {
1013 printk(KERN_WARNING
"bfad_im_probe failed\n");
1014 if (bfa_sm_cmp_state(bfad
, bfad_sm_initializing
))
1015 bfa_sm_set_state(bfad
, bfad_sm_failed
);
1016 return BFA_STATUS_FAILED
;
1018 bfad
->bfad_flags
|= BFAD_FC4_PROBE_DONE
;
1020 bfad_drv_start(bfad
);
1022 /* Complete pbc vport create */
1023 list_for_each_entry_safe(vport
, vport_new
, &bfad
->pbc_vport_list
,
1025 struct fc_vport_identifiers vid
;
1026 struct fc_vport
*fc_vport
;
1027 char pwwn_buf
[BFA_STRING_32
];
1029 memset(&vid
, 0, sizeof(vid
));
1030 vid
.roles
= FC_PORT_ROLE_FCP_INITIATOR
;
1031 vid
.vport_type
= FC_PORTTYPE_NPIV
;
1032 vid
.disable
= false;
1033 vid
.node_name
= wwn_to_u64((u8
*)
1034 (&((vport
->fcs_vport
).lport
.port_cfg
.nwwn
)));
1035 vid
.port_name
= wwn_to_u64((u8
*)
1036 (&((vport
->fcs_vport
).lport
.port_cfg
.pwwn
)));
1037 fc_vport
= fc_vport_create(bfad
->pport
.im_port
->shost
, 0, &vid
);
1039 wwn2str(pwwn_buf
, vid
.port_name
);
1040 printk(KERN_WARNING
"bfad%d: failed to create pbc vport"
1041 " %s\n", bfad
->inst_no
, pwwn_buf
);
1043 list_del(&vport
->list_entry
);
1048 * If bfa_linkup_delay is set to -1 default; try to retrive the
1049 * value using the bfad_get_linkup_delay(); else use the
1050 * passed in module param value as the bfa_linkup_delay.
1052 if (bfa_linkup_delay
< 0) {
1053 bfa_linkup_delay
= bfad_get_linkup_delay(bfad
);
1054 bfad_rport_online_wait(bfad
);
1055 bfa_linkup_delay
= -1;
1057 bfad_rport_online_wait(bfad
);
1059 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
, "bfa device claimed\n");
1061 return BFA_STATUS_OK
;
1065 bfad_worker(void *ptr
)
1067 struct bfad_s
*bfad
= ptr
;
1068 unsigned long flags
;
1070 if (kthread_should_stop())
1073 /* Send event BFAD_E_INIT_SUCCESS */
1074 bfa_sm_send_event(bfad
, BFAD_E_INIT_SUCCESS
);
1076 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1077 bfad
->bfad_tsk
= NULL
;
1078 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1084 * BFA driver interrupt functions
1087 bfad_intx(int irq
, void *dev_id
)
1089 struct bfad_s
*bfad
= dev_id
;
1090 struct list_head doneq
;
1091 unsigned long flags
;
1094 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1095 rc
= bfa_intx(&bfad
->bfa
);
1097 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1101 bfa_comp_deq(&bfad
->bfa
, &doneq
);
1102 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1104 if (!list_empty(&doneq
)) {
1105 bfa_comp_process(&bfad
->bfa
, &doneq
);
1107 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1108 bfa_comp_free(&bfad
->bfa
, &doneq
);
1109 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1117 bfad_msix(int irq
, void *dev_id
)
1119 struct bfad_msix_s
*vec
= dev_id
;
1120 struct bfad_s
*bfad
= vec
->bfad
;
1121 struct list_head doneq
;
1122 unsigned long flags
;
1124 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1126 bfa_msix(&bfad
->bfa
, vec
->msix
.entry
);
1127 bfa_comp_deq(&bfad
->bfa
, &doneq
);
1128 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1130 if (!list_empty(&doneq
)) {
1131 bfa_comp_process(&bfad
->bfa
, &doneq
);
1133 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1134 bfa_comp_free(&bfad
->bfa
, &doneq
);
1135 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1142 * Initialize the MSIX entry table.
1145 bfad_init_msix_entry(struct bfad_s
*bfad
, struct msix_entry
*msix_entries
,
1146 int mask
, int max_bit
)
1149 int match
= 0x00000001;
1151 for (i
= 0, bfad
->nvec
= 0; i
< MAX_MSIX_ENTRY
; i
++) {
1153 bfad
->msix_tab
[bfad
->nvec
].msix
.entry
= i
;
1154 bfad
->msix_tab
[bfad
->nvec
].bfad
= bfad
;
1155 msix_entries
[bfad
->nvec
].entry
= i
;
1165 bfad_install_msix_handler(struct bfad_s
*bfad
)
1169 for (i
= 0; i
< bfad
->nvec
; i
++) {
1170 sprintf(bfad
->msix_tab
[i
].name
, "bfa-%s-%s",
1172 ((bfa_asic_id_cb(bfad
->hal_pcidev
.device_id
)) ?
1173 msix_name_cb
[i
] : msix_name_ct
[i
]));
1175 error
= request_irq(bfad
->msix_tab
[i
].msix
.vector
,
1176 (irq_handler_t
) bfad_msix
, 0,
1177 bfad
->msix_tab
[i
].name
, &bfad
->msix_tab
[i
]);
1179 bfa_trc(bfad
, bfad
->msix_tab
[i
].msix
.vector
);
1183 for (j
= 0; j
< i
; j
++)
1184 free_irq(bfad
->msix_tab
[j
].msix
.vector
,
1185 &bfad
->msix_tab
[j
]);
1187 bfad
->bfad_flags
&= ~BFAD_MSIX_ON
;
1188 pci_disable_msix(bfad
->pcidev
);
1198 * Setup MSIX based interrupt.
1201 bfad_setup_intr(struct bfad_s
*bfad
)
1204 u32 mask
= 0, i
, num_bit
= 0, max_bit
= 0;
1205 struct msix_entry msix_entries
[MAX_MSIX_ENTRY
];
1206 struct pci_dev
*pdev
= bfad
->pcidev
;
1209 /* Call BFA to get the msix map for this PCI function. */
1210 bfa_msix_getvecs(&bfad
->bfa
, &mask
, &num_bit
, &max_bit
);
1212 /* Set up the msix entry table */
1213 bfad_init_msix_entry(bfad
, msix_entries
, mask
, max_bit
);
1215 if ((bfa_asic_id_ctc(pdev
->device
) && !msix_disable_ct
) ||
1216 (bfa_asic_id_cb(pdev
->device
) && !msix_disable_cb
)) {
1218 error
= pci_enable_msix_exact(bfad
->pcidev
,
1219 msix_entries
, bfad
->nvec
);
1220 /* In CT1 & CT2, try to allocate just one vector */
1221 if (error
== -ENOSPC
&& bfa_asic_id_ctc(pdev
->device
)) {
1222 printk(KERN_WARNING
"bfa %s: trying one msix "
1223 "vector failed to allocate %d[%d]\n",
1224 bfad
->pci_name
, bfad
->nvec
, error
);
1226 error
= pci_enable_msix_exact(bfad
->pcidev
,
1231 printk(KERN_WARNING
"bfad%d: "
1232 "pci_enable_msix_exact failed (%d), "
1233 "use line based.\n",
1234 bfad
->inst_no
, error
);
1238 /* Disable INTX in MSI-X mode */
1239 pci_read_config_word(pdev
, PCI_COMMAND
, ®
);
1241 if (!(reg
& PCI_COMMAND_INTX_DISABLE
))
1242 pci_write_config_word(pdev
, PCI_COMMAND
,
1243 reg
| PCI_COMMAND_INTX_DISABLE
);
1245 /* Save the vectors */
1246 for (i
= 0; i
< bfad
->nvec
; i
++) {
1247 bfa_trc(bfad
, msix_entries
[i
].vector
);
1248 bfad
->msix_tab
[i
].msix
.vector
= msix_entries
[i
].vector
;
1251 bfa_msix_init(&bfad
->bfa
, bfad
->nvec
);
1253 bfad
->bfad_flags
|= BFAD_MSIX_ON
;
1259 error
= request_irq(bfad
->pcidev
->irq
, (irq_handler_t
)bfad_intx
,
1260 BFAD_IRQ_FLAGS
, BFAD_DRIVER_NAME
, bfad
);
1264 bfad
->bfad_flags
|= BFAD_INTX_ON
;
1270 bfad_remove_intr(struct bfad_s
*bfad
)
1274 if (bfad
->bfad_flags
& BFAD_MSIX_ON
) {
1275 for (i
= 0; i
< bfad
->nvec
; i
++)
1276 free_irq(bfad
->msix_tab
[i
].msix
.vector
,
1277 &bfad
->msix_tab
[i
]);
1279 pci_disable_msix(bfad
->pcidev
);
1280 bfad
->bfad_flags
&= ~BFAD_MSIX_ON
;
1281 } else if (bfad
->bfad_flags
& BFAD_INTX_ON
) {
1282 free_irq(bfad
->pcidev
->irq
, bfad
);
1290 bfad_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*pid
)
1292 struct bfad_s
*bfad
;
1293 int error
= -ENODEV
, retval
, i
;
1295 /* For single port cards - only claim function 0 */
1296 if ((pdev
->device
== BFA_PCI_DEVICE_ID_FC_8G1P
) &&
1297 (PCI_FUNC(pdev
->devfn
) != 0))
1300 bfad
= kzalloc(sizeof(struct bfad_s
), GFP_KERNEL
);
1306 bfad
->trcmod
= kzalloc(sizeof(struct bfa_trc_mod_s
), GFP_KERNEL
);
1307 if (!bfad
->trcmod
) {
1308 printk(KERN_WARNING
"Error alloc trace buffer!\n");
1310 goto out_alloc_trace_failure
;
1314 bfa_trc_init(bfad
->trcmod
);
1315 bfa_trc(bfad
, bfad_inst
);
1318 INIT_LIST_HEAD(&bfad
->free_aen_q
);
1319 INIT_LIST_HEAD(&bfad
->active_aen_q
);
1320 for (i
= 0; i
< BFA_AEN_MAX_ENTRY
; i
++)
1321 list_add_tail(&bfad
->aen_list
[i
].qe
, &bfad
->free_aen_q
);
1323 if (!(bfad_load_fwimg(pdev
))) {
1324 kfree(bfad
->trcmod
);
1325 goto out_alloc_trace_failure
;
1328 retval
= bfad_pci_init(pdev
, bfad
);
1330 printk(KERN_WARNING
"bfad_pci_init failure!\n");
1332 goto out_pci_init_failure
;
1335 mutex_lock(&bfad_mutex
);
1336 bfad
->inst_no
= bfad_inst
++;
1337 list_add_tail(&bfad
->list_entry
, &bfad_list
);
1338 mutex_unlock(&bfad_mutex
);
1340 /* Initializing the state machine: State set to uninit */
1341 bfa_sm_set_state(bfad
, bfad_sm_uninit
);
1343 spin_lock_init(&bfad
->bfad_lock
);
1344 spin_lock_init(&bfad
->bfad_aen_spinlock
);
1346 pci_set_drvdata(pdev
, bfad
);
1348 bfad
->ref_count
= 0;
1349 bfad
->pport
.bfad
= bfad
;
1350 INIT_LIST_HEAD(&bfad
->pbc_vport_list
);
1351 INIT_LIST_HEAD(&bfad
->vport_list
);
1353 /* Setup the debugfs node for this bfad */
1354 if (bfa_debugfs_enable
)
1355 bfad_debugfs_init(&bfad
->pport
);
1357 retval
= bfad_drv_init(bfad
);
1358 if (retval
!= BFA_STATUS_OK
)
1359 goto out_drv_init_failure
;
1361 bfa_sm_send_event(bfad
, BFAD_E_CREATE
);
1363 if (bfa_sm_cmp_state(bfad
, bfad_sm_uninit
))
1364 goto out_bfad_sm_failure
;
1368 out_bfad_sm_failure
:
1369 bfad_hal_mem_release(bfad
);
1370 out_drv_init_failure
:
1371 /* Remove the debugfs node for this bfad */
1372 kfree(bfad
->regdata
);
1373 bfad_debugfs_exit(&bfad
->pport
);
1374 mutex_lock(&bfad_mutex
);
1376 list_del(&bfad
->list_entry
);
1377 mutex_unlock(&bfad_mutex
);
1378 bfad_pci_uninit(pdev
, bfad
);
1379 out_pci_init_failure
:
1380 kfree(bfad
->trcmod
);
1381 out_alloc_trace_failure
:
1391 bfad_pci_remove(struct pci_dev
*pdev
)
1393 struct bfad_s
*bfad
= pci_get_drvdata(pdev
);
1394 unsigned long flags
;
1396 bfa_trc(bfad
, bfad
->inst_no
);
1398 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1399 if (bfad
->bfad_tsk
!= NULL
) {
1400 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1401 kthread_stop(bfad
->bfad_tsk
);
1403 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1406 /* Send Event BFAD_E_STOP */
1407 bfa_sm_send_event(bfad
, BFAD_E_STOP
);
1409 /* Driver detach and dealloc mem */
1410 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1411 bfa_detach(&bfad
->bfa
);
1412 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1413 bfad_hal_mem_release(bfad
);
1415 /* Remove the debugfs node for this bfad */
1416 kfree(bfad
->regdata
);
1417 bfad_debugfs_exit(&bfad
->pport
);
1419 /* Cleaning the BFAD instance */
1420 mutex_lock(&bfad_mutex
);
1422 list_del(&bfad
->list_entry
);
1423 mutex_unlock(&bfad_mutex
);
1424 bfad_pci_uninit(pdev
, bfad
);
1426 kfree(bfad
->trcmod
);
1431 * PCI Error Recovery entry, error detected.
1433 static pci_ers_result_t
1434 bfad_pci_error_detected(struct pci_dev
*pdev
, pci_channel_state_t state
)
1436 struct bfad_s
*bfad
= pci_get_drvdata(pdev
);
1437 unsigned long flags
;
1438 pci_ers_result_t ret
= PCI_ERS_RESULT_NONE
;
1440 dev_printk(KERN_ERR
, &pdev
->dev
,
1441 "error detected state: %d - flags: 0x%x\n",
1442 state
, bfad
->bfad_flags
);
1445 case pci_channel_io_normal
: /* non-fatal error */
1446 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1447 bfad
->bfad_flags
&= ~BFAD_EEH_BUSY
;
1448 /* Suspend/fail all bfa operations */
1449 bfa_ioc_suspend(&bfad
->bfa
.ioc
);
1450 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1451 del_timer_sync(&bfad
->hal_tmo
);
1452 ret
= PCI_ERS_RESULT_CAN_RECOVER
;
1454 case pci_channel_io_frozen
: /* fatal error */
1455 init_completion(&bfad
->comp
);
1456 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1457 bfad
->bfad_flags
|= BFAD_EEH_BUSY
;
1458 /* Suspend/fail all bfa operations */
1459 bfa_ioc_suspend(&bfad
->bfa
.ioc
);
1460 bfa_fcs_stop(&bfad
->bfa_fcs
);
1461 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1462 wait_for_completion(&bfad
->comp
);
1464 bfad_remove_intr(bfad
);
1465 del_timer_sync(&bfad
->hal_tmo
);
1466 pci_disable_device(pdev
);
1467 ret
= PCI_ERS_RESULT_NEED_RESET
;
1469 case pci_channel_io_perm_failure
: /* PCI Card is DEAD */
1470 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1471 bfad
->bfad_flags
|= BFAD_EEH_BUSY
|
1472 BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE
;
1473 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1475 /* If the error_detected handler is called with the reason
1476 * pci_channel_io_perm_failure - it will subsequently call
1477 * pci_remove() entry point to remove the pci device from the
1478 * system - So defer the cleanup to pci_remove(); cleaning up
1479 * here causes inconsistent state during pci_remove().
1481 ret
= PCI_ERS_RESULT_DISCONNECT
;
1490 static int restart_bfa(struct bfad_s
*bfad
)
1492 unsigned long flags
;
1493 struct pci_dev
*pdev
= bfad
->pcidev
;
1495 bfa_attach(&bfad
->bfa
, bfad
, &bfad
->ioc_cfg
,
1496 &bfad
->meminfo
, &bfad
->hal_pcidev
);
1498 /* Enable Interrupt and wait bfa_init completion */
1499 if (bfad_setup_intr(bfad
)) {
1500 dev_printk(KERN_WARNING
, &pdev
->dev
,
1501 "%s: bfad_setup_intr failed\n", bfad
->pci_name
);
1502 bfa_sm_send_event(bfad
, BFAD_E_INIT_FAILED
);
1506 init_completion(&bfad
->comp
);
1507 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1508 bfa_iocfc_init(&bfad
->bfa
);
1509 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1511 /* Set up interrupt handler for each vectors */
1512 if ((bfad
->bfad_flags
& BFAD_MSIX_ON
) &&
1513 bfad_install_msix_handler(bfad
))
1514 dev_printk(KERN_WARNING
, &pdev
->dev
,
1515 "%s: install_msix failed.\n", bfad
->pci_name
);
1517 bfad_init_timer(bfad
);
1518 wait_for_completion(&bfad
->comp
);
1519 bfad_drv_start(bfad
);
1525 * PCI Error Recovery entry, re-initialize the chip.
1527 static pci_ers_result_t
1528 bfad_pci_slot_reset(struct pci_dev
*pdev
)
1530 struct bfad_s
*bfad
= pci_get_drvdata(pdev
);
1534 dev_printk(KERN_ERR
, &pdev
->dev
,
1535 "bfad_pci_slot_reset flags: 0x%x\n", bfad
->bfad_flags
);
1537 if (pci_enable_device(pdev
)) {
1538 dev_printk(KERN_ERR
, &pdev
->dev
, "Cannot re-enable "
1539 "PCI device after reset.\n");
1540 return PCI_ERS_RESULT_DISCONNECT
;
1543 pci_restore_state(pdev
);
1546 * Read some byte (e.g. DMA max. payload size which can't
1547 * be 0xff any time) to make sure - we did not hit another PCI error
1548 * in the middle of recovery. If we did, then declare permanent failure.
1550 pci_read_config_byte(pdev
, 0x68, &byte
);
1552 dev_printk(KERN_ERR
, &pdev
->dev
,
1553 "slot_reset failed ... got another PCI error !\n");
1554 goto out_disable_device
;
1557 pci_save_state(pdev
);
1558 pci_set_master(pdev
);
1560 rc
= dma_set_mask_and_coherent(&bfad
->pcidev
->dev
, DMA_BIT_MASK(64));
1562 rc
= dma_set_mask_and_coherent(&bfad
->pcidev
->dev
,
1565 goto out_disable_device
;
1567 if (restart_bfa(bfad
) == -1)
1568 goto out_disable_device
;
1570 pci_enable_pcie_error_reporting(pdev
);
1571 dev_printk(KERN_WARNING
, &pdev
->dev
,
1572 "slot_reset completed flags: 0x%x!\n", bfad
->bfad_flags
);
1574 return PCI_ERS_RESULT_RECOVERED
;
1577 pci_disable_device(pdev
);
1578 return PCI_ERS_RESULT_DISCONNECT
;
1581 static pci_ers_result_t
1582 bfad_pci_mmio_enabled(struct pci_dev
*pdev
)
1584 unsigned long flags
;
1585 struct bfad_s
*bfad
= pci_get_drvdata(pdev
);
1587 dev_printk(KERN_INFO
, &pdev
->dev
, "mmio_enabled\n");
1589 /* Fetch FW diagnostic information */
1590 bfa_ioc_debug_save_ftrc(&bfad
->bfa
.ioc
);
1592 /* Cancel all pending IOs */
1593 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1594 init_completion(&bfad
->comp
);
1595 bfa_fcs_stop(&bfad
->bfa_fcs
);
1596 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1597 wait_for_completion(&bfad
->comp
);
1599 bfad_remove_intr(bfad
);
1600 del_timer_sync(&bfad
->hal_tmo
);
1601 pci_disable_device(pdev
);
1603 return PCI_ERS_RESULT_NEED_RESET
;
1607 bfad_pci_resume(struct pci_dev
*pdev
)
1609 unsigned long flags
;
1610 struct bfad_s
*bfad
= pci_get_drvdata(pdev
);
1612 dev_printk(KERN_WARNING
, &pdev
->dev
, "resume\n");
1614 /* wait until the link is online */
1615 bfad_rport_online_wait(bfad
);
1617 spin_lock_irqsave(&bfad
->bfad_lock
, flags
);
1618 bfad
->bfad_flags
&= ~BFAD_EEH_BUSY
;
1619 spin_unlock_irqrestore(&bfad
->bfad_lock
, flags
);
1622 struct pci_device_id bfad_id_table
[] = {
1624 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1625 .device
= BFA_PCI_DEVICE_ID_FC_8G2P
,
1626 .subvendor
= PCI_ANY_ID
,
1627 .subdevice
= PCI_ANY_ID
,
1630 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1631 .device
= BFA_PCI_DEVICE_ID_FC_8G1P
,
1632 .subvendor
= PCI_ANY_ID
,
1633 .subdevice
= PCI_ANY_ID
,
1636 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1637 .device
= BFA_PCI_DEVICE_ID_CT
,
1638 .subvendor
= PCI_ANY_ID
,
1639 .subdevice
= PCI_ANY_ID
,
1640 .class = (PCI_CLASS_SERIAL_FIBER
<< 8),
1644 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1645 .device
= BFA_PCI_DEVICE_ID_CT_FC
,
1646 .subvendor
= PCI_ANY_ID
,
1647 .subdevice
= PCI_ANY_ID
,
1648 .class = (PCI_CLASS_SERIAL_FIBER
<< 8),
1652 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1653 .device
= BFA_PCI_DEVICE_ID_CT2
,
1654 .subvendor
= PCI_ANY_ID
,
1655 .subdevice
= PCI_ANY_ID
,
1656 .class = (PCI_CLASS_SERIAL_FIBER
<< 8),
1661 .vendor
= BFA_PCI_VENDOR_ID_BROCADE
,
1662 .device
= BFA_PCI_DEVICE_ID_CT2_QUAD
,
1663 .subvendor
= PCI_ANY_ID
,
1664 .subdevice
= PCI_ANY_ID
,
1665 .class = (PCI_CLASS_SERIAL_FIBER
<< 8),
1671 MODULE_DEVICE_TABLE(pci
, bfad_id_table
);
1674 * PCI error recovery handlers.
1676 static struct pci_error_handlers bfad_err_handler
= {
1677 .error_detected
= bfad_pci_error_detected
,
1678 .slot_reset
= bfad_pci_slot_reset
,
1679 .mmio_enabled
= bfad_pci_mmio_enabled
,
1680 .resume
= bfad_pci_resume
,
1683 static struct pci_driver bfad_pci_driver
= {
1684 .name
= BFAD_DRIVER_NAME
,
1685 .id_table
= bfad_id_table
,
1686 .probe
= bfad_pci_probe
,
1687 .remove
= bfad_pci_remove
,
1688 .err_handler
= &bfad_err_handler
,
1692 * Driver module init.
1699 pr_info("QLogic BR-series BFA FC/FCOE SCSI driver - version: %s\n",
1700 BFAD_DRIVER_VERSION
);
1703 num_sgpgs_parm
= num_sgpgs
;
1705 error
= bfad_im_module_init();
1708 printk(KERN_WARNING
"bfad_im_module_init failure\n");
1712 if (strcmp(FCPI_NAME
, " fcpim") == 0)
1713 supported_fc4s
|= BFA_LPORT_ROLE_FCP_IM
;
1715 bfa_auto_recover
= ioc_auto_recover
;
1716 bfa_fcs_rport_set_del_timeout(rport_del_timeout
);
1717 bfa_fcs_rport_set_max_logins(max_rport_logins
);
1719 error
= pci_register_driver(&bfad_pci_driver
);
1721 printk(KERN_WARNING
"pci_register_driver failure\n");
1728 bfad_im_module_exit();
1733 * Driver module exit.
1738 pci_unregister_driver(&bfad_pci_driver
);
1739 bfad_im_module_exit();
1743 /* Firmware handling */
1745 bfad_read_firmware(struct pci_dev
*pdev
, u32
**bfi_image
,
1746 u32
*bfi_image_size
, char *fw_name
)
1748 const struct firmware
*fw
;
1750 if (request_firmware(&fw
, fw_name
, &pdev
->dev
)) {
1751 printk(KERN_ALERT
"Can't locate firmware %s\n", fw_name
);
1756 *bfi_image
= vmalloc(fw
->size
);
1757 if (NULL
== *bfi_image
) {
1758 printk(KERN_ALERT
"Fail to allocate buffer for fw image "
1759 "size=%x!\n", (u32
) fw
->size
);
1763 memcpy(*bfi_image
, fw
->data
, fw
->size
);
1764 *bfi_image_size
= fw
->size
/sizeof(u32
);
1766 release_firmware(fw
);
1770 bfad_load_fwimg(struct pci_dev
*pdev
)
1772 if (bfa_asic_id_ct2(pdev
->device
)) {
1773 if (bfi_image_ct2_size
== 0)
1774 bfad_read_firmware(pdev
, &bfi_image_ct2
,
1775 &bfi_image_ct2_size
, BFAD_FW_FILE_CT2
);
1776 return bfi_image_ct2
;
1777 } else if (bfa_asic_id_ct(pdev
->device
)) {
1778 if (bfi_image_ct_size
== 0)
1779 bfad_read_firmware(pdev
, &bfi_image_ct
,
1780 &bfi_image_ct_size
, BFAD_FW_FILE_CT
);
1781 return bfi_image_ct
;
1782 } else if (bfa_asic_id_cb(pdev
->device
)) {
1783 if (bfi_image_cb_size
== 0)
1784 bfad_read_firmware(pdev
, &bfi_image_cb
,
1785 &bfi_image_cb_size
, BFAD_FW_FILE_CB
);
1786 return bfi_image_cb
;
1793 bfad_free_fwimg(void)
1795 if (bfi_image_ct2_size
&& bfi_image_ct2
)
1796 vfree(bfi_image_ct2
);
1797 if (bfi_image_ct_size
&& bfi_image_ct
)
1798 vfree(bfi_image_ct
);
1799 if (bfi_image_cb_size
&& bfi_image_cb
)
1800 vfree(bfi_image_cb
);
1803 module_init(bfad_init
);
1804 module_exit(bfad_exit
);
1805 MODULE_LICENSE("GPL");
1806 MODULE_DESCRIPTION("QLogic BR-series Fibre Channel HBA Driver" BFAD_PROTO_NAME
);
1807 MODULE_AUTHOR("QLogic Corporation");
1808 MODULE_VERSION(BFAD_DRIVER_VERSION
);