21 #include <linux/module.h>
23 #include <linux/errno.h>
24 #include <linux/sched.h>
27 #include <linux/pci.h>
29 #include <asm/uaccess.h>
30 #include <asm/fcntl.h>
43 static int num_sgpgs_parm;
66 #define BFAD_FW_FILE_CB "cbfw-3.1.0.0.bin"
67 #define BFAD_FW_FILE_CT "ctfw-3.1.0.0.bin"
68 #define BFAD_FW_FILE_CT2 "ct2fw-3.1.0.0.bin"
70 static u32 *bfad_load_fwimg(
struct pci_dev *pdev);
71 static void bfad_free_fwimg(
void);
72 static void bfad_read_firmware(
struct pci_dev *pdev,
u32 **bfi_image,
75 static const char *msix_name_ct[] = {
77 "cpe0",
"cpe1",
"cpe2",
"cpe3",
78 "rme0",
"rme1",
"rme2",
"rme3" };
80 static const char *msix_name_cb[] = {
81 "cpe0",
"cpe1",
"cpe2",
"cpe3",
82 "rme0",
"rme1",
"rme2",
"rme3",
83 "eemc",
"elpu0",
"elpu1",
"epss",
"mlpu" };
97 "(physical/logical), default=1024");
106 "buffers, default=64");
124 "Range[Critical:1|Error:2|Warning:3|Info:4]");
127 "Range[off:0|on:1]");
130 "boot port. Otherwise 10 secs in RHEL4 & 0 for "
131 "[RHEL5, SLES10, ESX40] Range[>0]");
134 "for Brocade-415/425/815/825 cards, default=0, "
135 " Range[false:0|true:1]");
138 "if possible for Brocade-1010/1020/804/1007/902/1741 "
139 "cards, default=0, Range[false:0|true:1]");
142 "Range[false:0|true:1]");
145 "(use system setting), Range[128|256|512|1024|2048|4096]");
148 " Range[false:0|true:1]");
151 " Range[64k|128k|256k|512k|1024k|2048k]");
182 "%s",
"bfad_worker");
185 "creation failed!\n", bfad->
inst_no);
214 init_completion(&bfad->
comp);
226 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
243 "bfa %s: bfa init failed\n",
273 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
286 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
404 struct bfad_s *bfad = drv;
434 if (!vp_drv && !vf_drv) {
435 port_drv = &bfad->
pport;
437 }
else if (!vp_drv && vf_drv) {
440 }
else if (vp_drv && !vf_drv) {
472 if (*rport_drv ==
NULL) {
477 *rport = &(*rport_drv)->fcs_rport;
645 vport->drv_port.bfad = bfad;
649 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
658 goto ext_free_fcs_vport;
664 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
670 vport->comp_del = &fcomp;
671 init_completion(vport->comp_del);
673 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
693 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
695 if (!list_empty(&doneq)) {
699 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
728 goto out_disable_device;
734 (pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64)) != 0)) {
736 (pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32)) != 0)) {
738 goto out_release_region;
750 goto out_release_region;
798 if (mask != 0xffff && pcie_cap_reg) {
799 pcie_cap_reg += 0x08;
800 pci_read_config_word(pdev, pcie_cap_reg, &pcie_dev_ctl);
801 if ((pcie_dev_ctl & 0x7000) != mask) {
803 "pcie_max_read_request_size is %d, "
805 (1 << ((pcie_dev_ctl & 0x7000) >> 12)) << 7,
808 pcie_dev_ctl &= ~0x7000;
809 pci_write_config_word(pdev, pcie_cap_reg,
810 pcie_dev_ctl | mask);
836 pci_set_drvdata(pdev,
NULL);
855 "Not enough memory to attach all Brocade HBA ports, %s",
856 "System may need more memory.\n");
857 goto out_hal_mem_alloc_failure;
875 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
882 goto out_cfg_pport_fail;
889 init_completion(&bfad->
comp);
892 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
897 out_hal_mem_alloc_failure:
907 init_completion(&bfad->
comp);
909 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
931 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
943 init_completion(&bfad->
comp);
946 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
958 init_completion(&bfad->
comp);
961 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
974 (role & BFA_LPORT_ROLE_FCP_IM)) {
998 (bfad->
pport.roles & BFA_LPORT_ROLE_FCP_IM)) {
1002 bfad->
pport.roles &= ~BFA_LPORT_ROLE_FCP_IM;
1012 unsigned long flags;
1017 if (max_xfer_size < BFAD_MIN_SECTORS >> 1)
1023 memset(&driver_info, 0,
sizeof(driver_info));
1025 sizeof(driver_info.
version) - 1);
1042 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1076 memset(&vid, 0,
sizeof(vid));
1081 (&((vport->
fcs_vport).lport.port_cfg.nwwn)));
1083 (&((vport->
fcs_vport).lport.port_cfg.pwwn)));
1088 " %s\n", bfad->
inst_no, pwwn_buf);
1115 unsigned long flags;
1117 bfad = (
struct bfad_s *)ptr;
1126 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1142 unsigned long flags;
1148 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1153 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1155 if (!list_empty(&doneq)) {
1160 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1168 bfad_msix(
int irq,
void *
dev_id)
1173 unsigned long flags;
1179 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1181 if (!list_empty(&doneq)) {
1186 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1196 bfad_init_msix_entry(
struct bfad_s *bfad,
struct msix_entry *msix_entries,
1197 int mask,
int max_bit)
1200 int match = 0x00000001;
1206 msix_entries[bfad->
nvec].entry =
i;
1220 for (i = 0; i < bfad->
nvec; i++) {
1224 msix_name_cb[i] : msix_name_ct[i]));
1234 for (j = 0; j <
i; j++)
1255 u32 mask = 0,
i, num_bit = 0, max_bit = 0;
1256 struct msix_entry msix_entries[MAX_MSIX_ENTRY];
1264 bfad_init_msix_entry(bfad, msix_entries, mask, max_bit);
1274 "vector failed to allocate %d[%d]\n",
1278 msix_entries, bfad->
nvec);
1292 "pci_enable_msix failed (%d), "
1293 "use line based.\n",
1304 reg | PCI_COMMAND_INTX_DISABLE);
1307 for (i = 0; i < bfad->
nvec; i++) {
1309 bfad->
msix_tab[
i].msix.vector = msix_entries[
i].vector;
1338 for (i = 0; i < bfad->
nvec; i++)
1373 goto out_alloc_trace_failure;
1377 bfa_trc_init(bfad->
trcmod);
1386 if (!(bfad_load_fwimg(pdev))) {
1388 goto out_alloc_trace_failure;
1395 goto out_pci_init_failure;
1409 pci_set_drvdata(pdev, bfad);
1412 bfad->
pport.bfad = bfad;
1422 goto out_drv_init_failure;
1427 goto out_bfad_sm_failure;
1431 out_bfad_sm_failure:
1434 out_drv_init_failure:
1443 out_pci_init_failure:
1445 out_alloc_trace_failure:
1457 struct bfad_s *bfad = pci_get_drvdata(pdev);
1458 unsigned long flags;
1464 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1467 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1476 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1500 struct bfad_s *bfad = pci_get_drvdata(pdev);
1501 unsigned long flags;
1505 "error detected state: %d - flags: 0x%x\n",
1514 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1519 init_completion(&bfad->
comp);
1525 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1537 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1557 unsigned long flags;
1566 "%s: bfad_setup_intr failed\n", bfad->
pci_name);
1571 init_completion(&bfad->
comp);
1574 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1580 "%s: install_msix failed.\n", bfad->
pci_name);
1593 bfad_pci_slot_reset(
struct pci_dev *pdev)
1595 struct bfad_s *bfad = pci_get_drvdata(pdev);
1599 "bfad_pci_slot_reset flags: 0x%x\n", bfad->
bfad_flags);
1602 dev_printk(
KERN_ERR, &pdev->
dev,
"Cannot re-enable "
1603 "PCI device after reset.\n");
1614 pci_read_config_byte(pdev, 0x68, &byte);
1617 "slot_reset failed ... got another PCI error !\n");
1618 goto out_disable_device;
1626 goto out_disable_device;
1631 goto out_disable_device;
1635 "slot_reset completed flags: 0x%x!\n", bfad->
bfad_flags);
1645 bfad_pci_mmio_enabled(
struct pci_dev *pdev)
1647 unsigned long flags;
1648 struct bfad_s *bfad = pci_get_drvdata(pdev);
1657 init_completion(&bfad->
comp);
1659 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1670 bfad_pci_resume(
struct pci_dev *pdev)
1672 unsigned long flags;
1673 struct bfad_s *bfad = pci_get_drvdata(pdev);
1682 spin_unlock_irqrestore(&bfad->
bfad_lock, flags);
1733 .slot_reset = bfad_pci_slot_reset,
1734 .mmio_enabled = bfad_pci_mmio_enabled,
1735 .resume = bfad_pci_resume,
1743 .err_handler = &bfad_err_handler,
1774 error = pci_register_driver(&bfad_pci_driver);
1800 bfad_read_firmware(
struct pci_dev *pdev,
u32 **bfi_image,
1812 if (
NULL == *bfi_image) {
1814 "size=%x!\n", (
u32) fw->
size);
1819 *bfi_image_size = fw->
size/
sizeof(
u32);
1825 bfad_load_fwimg(
struct pci_dev *pdev)
1846 bfad_free_fwimg(
void)