Thomas Gleixner | 52fa7bf | 2019-05-29 07:18:06 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2 | /* |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 3 | * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. |
| 4 | * Copyright (c) 2014- QLogic Corporation. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 5 | * All rights reserved |
Anil Gurumurthy | 889d0d4 | 2015-11-26 03:54:45 -0500 | [diff] [blame] | 6 | * www.qlogic.com |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 7 | * |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 8 | * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 11 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 12 | * bfad.c Linux driver PCI interface module. |
| 13 | */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 15 | #include <linux/kthread.h> |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 16 | #include <linux/errno.h> |
| 17 | #include <linux/sched.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/fs.h> |
| 20 | #include <linux/pci.h> |
| 21 | #include <linux/firmware.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 23 | #include <asm/fcntl.h> |
| 24 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 25 | #include "bfad_drv.h" |
| 26 | #include "bfad_im.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 27 | #include "bfa_fcs.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 28 | #include "bfa_defs.h" |
| 29 | #include "bfa.h" |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 30 | |
| 31 | BFA_TRC_FILE(LDRV, BFAD); |
Jing Huang | 42b426e | 2010-03-19 11:07:09 -0700 | [diff] [blame] | 32 | DEFINE_MUTEX(bfad_mutex); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 33 | LIST_HEAD(bfad_list); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 34 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 35 | static int bfad_inst; |
| 36 | static int num_sgpgs_parm; |
| 37 | int supported_fc4s; |
| 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; |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 45 | int bfa_log_level = 3; /* WARNING log level */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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; |
Jing Huang | ab2a9ba | 2010-07-08 20:02:55 -0700 | [diff] [blame] | 50 | int bfa_debugfs_enable = 1; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 51 | int msix_disable_cb = 0, msix_disable_ct = 0; |
Krishna Gudipati | 61e62e2 | 2011-06-24 20:29:07 -0700 | [diff] [blame] | 52 | int max_xfer_size = BFAD_MAX_SECTORS >> 1; |
Jason Yan | 4d5956f | 2020-04-07 11:22:02 +0800 | [diff] [blame] | 53 | static int max_rport_logins = BFA_FCS_MAX_RPORT_LOGINS; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 54 | |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 55 | /* Firmware releated */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 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; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 58 | |
Benjamin Poirier | 2d1148f | 2016-12-23 20:40:19 -0800 | [diff] [blame] | 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" |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 62 | |
| 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); |
| 67 | |
Maggie | 52f94b6 | 2010-11-29 18:21:32 -0800 | [diff] [blame] | 68 | static const char *msix_name_ct[] = { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 69 | "ctrl", |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 70 | "cpe0", "cpe1", "cpe2", "cpe3", |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 71 | "rme0", "rme1", "rme2", "rme3" }; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 72 | |
Maggie | 52f94b6 | 2010-11-29 18:21:32 -0800 | [diff] [blame] | 73 | static const char *msix_name_cb[] = { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 74 | "cpe0", "cpe1", "cpe2", "cpe3", |
| 75 | "rme0", "rme1", "rme2", "rme3", |
| 76 | "eemc", "elpu0", "elpu1", "epss", "mlpu" }; |
| 77 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 78 | MODULE_FIRMWARE(BFAD_FW_FILE_CB); |
| 79 | MODULE_FIRMWARE(BFAD_FW_FILE_CT); |
| 80 | MODULE_FIRMWARE(BFAD_FW_FILE_CT2); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 81 | |
| 82 | module_param(os_name, charp, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 83 | MODULE_PARM_DESC(os_name, "OS name of the hba host machine"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 84 | module_param(os_patch, charp, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 85 | MODULE_PARM_DESC(os_patch, "OS patch level of the hba host machine"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 86 | module_param(host_name, charp, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 87 | MODULE_PARM_DESC(host_name, "Hostname of the hba host machine"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 88 | module_param(num_rports, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 89 | MODULE_PARM_DESC(num_rports, "Max number of rports supported per port " |
| 90 | "(physical/logical), default=1024"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 91 | module_param(num_ios, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 92 | MODULE_PARM_DESC(num_ios, "Max number of ioim requests, default=2000"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 93 | module_param(num_tms, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 94 | MODULE_PARM_DESC(num_tms, "Max number of task im requests, default=128"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 95 | module_param(num_fcxps, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 96 | MODULE_PARM_DESC(num_fcxps, "Max number of fcxp requests, default=64"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 97 | module_param(num_ufbufs, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 98 | MODULE_PARM_DESC(num_ufbufs, "Max number of unsolicited frame " |
| 99 | "buffers, default=64"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 100 | module_param(reqq_size, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 101 | MODULE_PARM_DESC(reqq_size, "Max number of request queue elements, " |
| 102 | "default=256"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 103 | module_param(rspq_size, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 104 | MODULE_PARM_DESC(rspq_size, "Max number of response queue elements, " |
| 105 | "default=64"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 106 | module_param(num_sgpgs, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 107 | MODULE_PARM_DESC(num_sgpgs, "Number of scatter/gather pages, default=2048"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 108 | module_param(rport_del_timeout, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 109 | MODULE_PARM_DESC(rport_del_timeout, "Rport delete timeout, default=90 secs, " |
| 110 | "Range[>0]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 111 | module_param(bfa_lun_queue_depth, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 112 | MODULE_PARM_DESC(bfa_lun_queue_depth, "Lun queue depth, default=32, Range[>0]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 113 | module_param(bfa_io_max_sge, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 114 | MODULE_PARM_DESC(bfa_io_max_sge, "Max io scatter/gather elements, default=255"); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 115 | module_param(bfa_log_level, int, S_IRUGO | S_IWUSR); |
| 116 | MODULE_PARM_DESC(bfa_log_level, "Driver log level, default=3, " |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 117 | "Range[Critical:1|Error:2|Warning:3|Info:4]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 118 | module_param(ioc_auto_recover, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 119 | MODULE_PARM_DESC(ioc_auto_recover, "IOC auto recovery, default=1, " |
| 120 | "Range[off:0|on:1]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 121 | module_param(bfa_linkup_delay, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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); |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 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]"); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 127 | module_param(msix_disable_ct, int, S_IRUGO | S_IWUSR); |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 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]"); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame] | 129 | module_param(fdmi_enable, int, S_IRUGO | S_IWUSR); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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]"); |
Jing Huang | ab2a9ba | 2010-07-08 20:02:55 -0700 | [diff] [blame] | 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]"); |
Krishna Gudipati | 61e62e2 | 2011-06-24 20:29:07 -0700 | [diff] [blame] | 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]"); |
Krishna Gudipati | 61ba439 | 2012-08-22 19:52:58 -0700 | [diff] [blame] | 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"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 143 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 144 | static void |
| 145 | bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event); |
| 146 | static void |
| 147 | bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event event); |
| 148 | static void |
| 149 | bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event event); |
| 150 | static void |
| 151 | bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event event); |
| 152 | static void |
| 153 | bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event); |
| 154 | static void |
| 155 | bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event); |
| 156 | static void |
| 157 | bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event); |
| 158 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 159 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 160 | * Beginning state for the driver instance, awaiting the pci_probe event |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 161 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 162 | static void |
| 163 | bfad_sm_uninit(struct bfad_s *bfad, enum bfad_sm_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 164 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 165 | bfa_trc(bfad, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 166 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 167 | switch (event) { |
| 168 | case BFAD_E_CREATE: |
| 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); |
| 176 | } |
| 177 | bfa_sm_send_event(bfad, BFAD_E_INIT); |
| 178 | break; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 179 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 180 | case BFAD_E_STOP: |
| 181 | /* Ignore stop; already in uninit */ |
| 182 | break; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 183 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 184 | default: |
| 185 | bfa_sm_fault(bfad, event); |
| 186 | } |
| 187 | } |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 188 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 189 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 190 | * Driver Instance is created, awaiting event INIT to initialize the bfad |
| 191 | */ |
| 192 | static void |
| 193 | bfad_sm_created(struct bfad_s *bfad, enum bfad_sm_event event) |
| 194 | { |
| 195 | unsigned long flags; |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 196 | bfa_status_t ret; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 197 | |
| 198 | bfa_trc(bfad, event); |
| 199 | |
| 200 | switch (event) { |
| 201 | case BFAD_E_INIT: |
| 202 | bfa_sm_set_state(bfad, bfad_sm_initializing); |
| 203 | |
| 204 | init_completion(&bfad->comp); |
| 205 | |
| 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", |
| 209 | bfad->inst_no); |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 210 | bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 211 | break; |
| 212 | } |
| 213 | |
| 214 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 215 | bfa_iocfc_init(&bfad->bfa); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 216 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 217 | |
| 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); |
| 223 | } |
| 224 | |
| 225 | bfad_init_timer(bfad); |
| 226 | |
| 227 | wait_for_completion(&bfad->comp); |
| 228 | |
| 229 | if ((bfad->bfad_flags & BFAD_HAL_INIT_DONE)) { |
| 230 | bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS); |
| 231 | } else { |
Krishna Gudipati | 7c38c05 | 2011-04-14 16:50:35 -0700 | [diff] [blame] | 232 | printk(KERN_WARNING |
| 233 | "bfa %s: bfa init failed\n", |
| 234 | bfad->pci_name); |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 235 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 236 | bfa_fcs_init(&bfad->bfa_fcs); |
| 237 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 238 | |
| 239 | ret = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM); |
| 240 | if (ret != BFA_STATUS_OK) { |
| 241 | init_completion(&bfad->comp); |
| 242 | |
| 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); |
| 247 | |
| 248 | wait_for_completion(&bfad->comp); |
| 249 | |
| 250 | bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED); |
| 251 | break; |
| 252 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 253 | bfad->bfad_flags |= BFAD_HAL_INIT_FAIL; |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 254 | bfa_sm_send_event(bfad, BFAD_E_HAL_INIT_FAILED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | break; |
| 258 | |
| 259 | case BFAD_E_KTHREAD_CREATE_FAILED: |
| 260 | bfa_sm_set_state(bfad, bfad_sm_uninit); |
| 261 | break; |
| 262 | |
| 263 | default: |
| 264 | bfa_sm_fault(bfad, event); |
| 265 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 269 | bfad_sm_initializing(struct bfad_s *bfad, enum bfad_sm_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 270 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 271 | int retval; |
| 272 | unsigned long flags; |
| 273 | |
| 274 | bfa_trc(bfad, event); |
| 275 | |
| 276 | switch (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); |
| 282 | |
| 283 | retval = bfad_start_ops(bfad); |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 284 | if (retval != BFA_STATUS_OK) { |
| 285 | bfa_sm_set_state(bfad, bfad_sm_failed); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 286 | break; |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 287 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 288 | bfa_sm_set_state(bfad, bfad_sm_operational); |
| 289 | break; |
| 290 | |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 291 | case BFAD_E_INIT_FAILED: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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); |
| 297 | break; |
| 298 | |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 299 | case BFAD_E_HAL_INIT_FAILED: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 300 | bfa_sm_set_state(bfad, bfad_sm_failed); |
| 301 | break; |
| 302 | default: |
| 303 | bfa_sm_fault(bfad, event); |
| 304 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 308 | bfad_sm_failed(struct bfad_s *bfad, enum bfad_sm_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 309 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 310 | int retval; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 311 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 312 | bfa_trc(bfad, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 313 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 314 | switch (event) { |
| 315 | case BFAD_E_INIT_SUCCESS: |
| 316 | retval = bfad_start_ops(bfad); |
| 317 | if (retval != BFA_STATUS_OK) |
| 318 | break; |
| 319 | bfa_sm_set_state(bfad, bfad_sm_operational); |
| 320 | break; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 321 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 322 | case BFAD_E_STOP: |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 323 | bfa_sm_set_state(bfad, bfad_sm_fcs_exit); |
| 324 | bfa_sm_send_event(bfad, BFAD_E_FCS_EXIT_COMP); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 325 | break; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 326 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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); |
| 331 | break; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 332 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 333 | default: |
| 334 | bfa_sm_fault(bfad, event); |
| 335 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 339 | bfad_sm_operational(struct bfad_s *bfad, enum bfad_sm_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 340 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 341 | bfa_trc(bfad, event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 342 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 343 | switch (event) { |
| 344 | case BFAD_E_STOP: |
| 345 | bfa_sm_set_state(bfad, bfad_sm_fcs_exit); |
| 346 | bfad_fcs_stop(bfad); |
| 347 | break; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 348 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 349 | default: |
| 350 | bfa_sm_fault(bfad, event); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | static void |
| 355 | bfad_sm_fcs_exit(struct bfad_s *bfad, enum bfad_sm_event event) |
| 356 | { |
| 357 | bfa_trc(bfad, event); |
| 358 | |
| 359 | switch (event) { |
| 360 | case BFAD_E_FCS_EXIT_COMP: |
| 361 | bfa_sm_set_state(bfad, bfad_sm_stopping); |
| 362 | bfad_stop(bfad); |
| 363 | break; |
| 364 | |
| 365 | default: |
| 366 | bfa_sm_fault(bfad, event); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | static void |
| 371 | bfad_sm_stopping(struct bfad_s *bfad, enum bfad_sm_event event) |
| 372 | { |
| 373 | bfa_trc(bfad, event); |
| 374 | |
| 375 | switch (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); |
| 383 | break; |
| 384 | |
| 385 | default: |
| 386 | bfa_sm_fault(bfad, event); |
| 387 | break; |
| 388 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 391 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 392 | * BFA callbacks |
| 393 | */ |
| 394 | void |
| 395 | bfad_hcb_comp(void *arg, bfa_status_t status) |
| 396 | { |
| 397 | struct bfad_hal_comp *fcomp = (struct bfad_hal_comp *)arg; |
| 398 | |
| 399 | fcomp->status = status; |
| 400 | complete(&fcomp->comp); |
| 401 | } |
| 402 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 403 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 404 | * bfa_init callback |
| 405 | */ |
| 406 | void |
| 407 | bfa_cb_init(void *drv, bfa_status_t init_status) |
| 408 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 409 | struct bfad_s *bfad = drv; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 410 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 411 | if (init_status == BFA_STATUS_OK) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 412 | bfad->bfad_flags |= BFAD_HAL_INIT_DONE; |
| 413 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 414 | /* |
| 415 | * If BFAD_HAL_INIT_FAIL flag is set: |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 416 | * Wake up the kernel thread to start |
| 417 | * the bfad operations after HAL init done |
| 418 | */ |
| 419 | if ((bfad->bfad_flags & BFAD_HAL_INIT_FAIL)) { |
| 420 | bfad->bfad_flags &= ~BFAD_HAL_INIT_FAIL; |
| 421 | wake_up_process(bfad->bfad_tsk); |
| 422 | } |
| 423 | } |
| 424 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 425 | complete(&bfad->comp); |
| 426 | } |
| 427 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 428 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 429 | * BFA_FCS callbacks |
| 430 | */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 431 | struct bfad_port_s * |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 434 | struct bfad_vport_s *vp_drv) |
| 435 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 436 | bfa_status_t rc; |
| 437 | struct bfad_port_s *port_drv; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 438 | |
| 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; |
| 448 | } else { |
| 449 | port_drv = &vp_drv->drv_port; |
| 450 | port_drv->pvb_type = BFAD_PORT_VF_VPORT; |
| 451 | } |
| 452 | |
| 453 | port_drv->fcs_port = port; |
| 454 | port_drv->roles = roles; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 455 | |
| 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); |
| 460 | port_drv = NULL; |
| 461 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | return port_drv; |
| 465 | } |
| 466 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 467 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 468 | * FCS RPORT alloc callback, after successful PLOGI by FCS |
| 469 | */ |
| 470 | bfa_status_t |
| 471 | bfa_fcb_rport_alloc(struct bfad_s *bfad, struct bfa_fcs_rport_s **rport, |
| 472 | struct bfad_rport_s **rport_drv) |
| 473 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 474 | bfa_status_t rc = BFA_STATUS_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 475 | |
| 476 | *rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC); |
| 477 | if (*rport_drv == NULL) { |
| 478 | rc = BFA_STATUS_ENOMEM; |
| 479 | goto ext; |
| 480 | } |
| 481 | |
| 482 | *rport = &(*rport_drv)->fcs_rport; |
| 483 | |
| 484 | ext: |
| 485 | return rc; |
| 486 | } |
| 487 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 488 | /* |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 489 | * FCS PBC VPORT Create |
| 490 | */ |
| 491 | void |
| 492 | bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct bfi_pbc_vport_s pbc_vport) |
| 493 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 494 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 495 | struct bfa_lport_cfg_s port_cfg = {0}; |
| 496 | struct bfad_vport_s *vport; |
| 497 | int rc; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 498 | |
Alexey Khoroshilov | dc6d2a0 | 2014-04-18 00:58:42 -0700 | [diff] [blame] | 499 | vport = kzalloc(sizeof(struct bfad_vport_s), GFP_ATOMIC); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 500 | if (!vport) { |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 501 | bfa_trc(bfad, 0); |
| 502 | return; |
| 503 | } |
| 504 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 510 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 511 | rc = bfa_fcs_pbc_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, 0, |
| 512 | &port_cfg, vport); |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 513 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 514 | if (rc != BFA_STATUS_OK) { |
| 515 | bfa_trc(bfad, 0); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | list_add_tail(&vport->list_entry, &bfad->pbc_vport_list); |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 520 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 521 | |
| 522 | void |
| 523 | bfad_hal_mem_release(struct bfad_s *bfad) |
| 524 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 525 | struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 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; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 529 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 530 | dma_info = &hal_meminfo->dma_info; |
| 531 | kva_info = &hal_meminfo->kva_info; |
| 532 | |
| 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); |
| 537 | } |
| 538 | |
| 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); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s)); |
| 548 | } |
| 549 | |
| 550 | void |
| 551 | bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg) |
| 552 | { |
| 553 | if (num_rports > 0) |
| 554 | bfa_cfg->fwcfg.num_rports = num_rports; |
| 555 | if (num_ios > 0) |
| 556 | bfa_cfg->fwcfg.num_ioim_reqs = num_ios; |
| 557 | if (num_tms > 0) |
| 558 | bfa_cfg->fwcfg.num_tskim_reqs = num_tms; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 559 | if (num_fcxps > 0 && num_fcxps <= BFA_FCXP_MAX) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 560 | bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 561 | if (num_ufbufs > 0 && num_ufbufs <= BFA_UF_MAX) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 562 | bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs; |
| 563 | if (reqq_size > 0) |
| 564 | bfa_cfg->drvcfg.num_reqq_elems = reqq_size; |
| 565 | if (rspq_size > 0) |
| 566 | bfa_cfg->drvcfg.num_rspq_elems = rspq_size; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 567 | if (num_sgpgs > 0 && num_sgpgs <= BFA_SGPG_MAX) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 568 | bfa_cfg->drvcfg.num_sgpgs = num_sgpgs; |
| 569 | |
| 570 | /* |
| 571 | * populate the hal values back to the driver for sysfs use. |
| 572 | * otherwise, the default values will be shown as 0 in sysfs |
| 573 | */ |
| 574 | num_rports = bfa_cfg->fwcfg.num_rports; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 578 | num_ufbufs = bfa_cfg->fwcfg.num_uf_bufs; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | bfa_status_t |
| 585 | bfad_hal_mem_alloc(struct bfad_s *bfad) |
| 586 | { |
| 587 | struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 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; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 591 | bfa_status_t rc = BFA_STATUS_OK; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 592 | dma_addr_t phys_addr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 593 | |
| 594 | bfa_cfg_get_default(&bfad->ioc_cfg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 595 | bfad_update_hal_cfg(&bfad->ioc_cfg); |
| 596 | bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs; |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 597 | bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo, &bfad->bfa); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 598 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 599 | dma_info = &hal_meminfo->dma_info; |
| 600 | kva_info = &hal_meminfo->kva_info; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 601 | |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 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; |
Himanshu Jha | bde70f3 | 2017-12-30 20:58:31 +0530 | [diff] [blame] | 605 | kva_elem->kva = vzalloc(kva_elem->mem_len); |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 606 | if (kva_elem->kva == NULL) { |
| 607 | bfad_hal_mem_release(bfad); |
| 608 | rc = BFA_STATUS_ENOMEM; |
| 609 | goto ext; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 610 | } |
Krishna Gudipati | 4507025 | 2011-06-24 20:24:29 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 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, |
| 617 | dma_elem->mem_len, |
| 618 | &phys_addr, GFP_KERNEL); |
| 619 | if (dma_elem->kva == NULL) { |
| 620 | bfad_hal_mem_release(bfad); |
| 621 | rc = BFA_STATUS_ENOMEM; |
| 622 | goto ext; |
| 623 | } |
| 624 | dma_elem->dma = phys_addr; |
| 625 | memset(dma_elem->kva, 0, dma_elem->mem_len); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 626 | } |
| 627 | ext: |
| 628 | return rc; |
| 629 | } |
| 630 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 631 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 632 | * Create a vport under a vf. |
| 633 | */ |
| 634 | bfa_status_t |
| 635 | bfad_vport_create(struct bfad_s *bfad, u16 vf_id, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 636 | struct bfa_lport_cfg_s *port_cfg, struct device *dev) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 637 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 638 | struct bfad_vport_s *vport; |
| 639 | int rc = BFA_STATUS_OK; |
| 640 | unsigned long flags; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 641 | struct completion fcomp; |
| 642 | |
| 643 | vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL); |
| 644 | if (!vport) { |
| 645 | rc = BFA_STATUS_ENOMEM; |
| 646 | goto ext; |
| 647 | } |
| 648 | |
| 649 | vport->drv_port.bfad = bfad; |
| 650 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 651 | rc = bfa_fcs_vport_create(&vport->fcs_vport, &bfad->bfa_fcs, vf_id, |
| 652 | port_cfg, vport); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 653 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 654 | |
| 655 | if (rc != BFA_STATUS_OK) |
| 656 | goto ext_free_vport; |
| 657 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 658 | if (port_cfg->roles & BFA_LPORT_ROLE_FCP_IM) { |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 659 | rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port, |
| 660 | dev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 661 | if (rc != BFA_STATUS_OK) |
| 662 | goto ext_free_fcs_vport; |
| 663 | } |
| 664 | |
| 665 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 666 | bfa_fcs_vport_start(&vport->fcs_vport); |
Krishna Gudipati | 5b7db7a | 2011-12-20 18:58:32 -0800 | [diff] [blame] | 667 | list_add_tail(&vport->list_entry, &bfad->vport_list); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 668 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 669 | |
| 670 | return BFA_STATUS_OK; |
| 671 | |
| 672 | ext_free_fcs_vport: |
| 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); |
| 679 | ext_free_vport: |
| 680 | kfree(vport); |
| 681 | ext: |
| 682 | return rc; |
| 683 | } |
| 684 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 685 | void |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 686 | bfad_bfa_tmo(struct timer_list *t) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 687 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 688 | struct bfad_s *bfad = from_timer(bfad, t, hal_tmo); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 689 | unsigned long flags; |
| 690 | struct list_head doneq; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 691 | |
| 692 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 693 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 694 | bfa_timer_beat(&bfad->bfa.timer_mod); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 695 | |
| 696 | bfa_comp_deq(&bfad->bfa, &doneq); |
| 697 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 698 | |
| 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); |
| 704 | } |
| 705 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 706 | mod_timer(&bfad->hal_tmo, |
| 707 | jiffies + msecs_to_jiffies(BFA_TIMER_FREQ)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | void |
| 711 | bfad_init_timer(struct bfad_s *bfad) |
| 712 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 713 | timer_setup(&bfad->hal_tmo, bfad_bfa_tmo, 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 714 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 715 | mod_timer(&bfad->hal_tmo, |
| 716 | jiffies + msecs_to_jiffies(BFA_TIMER_FREQ)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | int |
| 720 | bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad) |
| 721 | { |
Hannes Reinecke | 11ea382 | 2019-02-18 08:34:23 +0100 | [diff] [blame] | 722 | int rc = -ENODEV; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 723 | |
| 724 | if (pci_enable_device(pdev)) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 725 | printk(KERN_ERR "pci_enable_device fail %p\n", pdev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 726 | goto out; |
| 727 | } |
| 728 | |
| 729 | if (pci_request_regions(pdev, BFAD_DRIVER_NAME)) |
| 730 | goto out_disable_device; |
| 731 | |
| 732 | pci_set_master(pdev); |
| 733 | |
Hannes Reinecke | 11ea382 | 2019-02-18 08:34:23 +0100 | [diff] [blame] | 734 | rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 735 | if (rc) |
| 736 | rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 737 | |
| 738 | if (rc) { |
| 739 | rc = -ENODEV; |
Christoph Hellwig | a69b080 | 2018-10-18 15:10:14 +0200 | [diff] [blame] | 740 | printk(KERN_ERR "dma_set_mask_and_coherent fail %p\n", pdev); |
| 741 | goto out_release_region; |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 742 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 743 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 744 | /* Enable PCIE Advanced Error Recovery (AER) if kernel supports */ |
| 745 | pci_enable_pcie_error_reporting(pdev); |
| 746 | |
Jing Huang | b3522f0 | 2010-03-19 11:06:44 -0700 | [diff] [blame] | 747 | bfad->pci_bar0_kva = pci_iomap(pdev, 0, pci_resource_len(pdev, 0)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 748 | bfad->pci_bar2_kva = pci_iomap(pdev, 2, pci_resource_len(pdev, 2)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 749 | |
| 750 | if (bfad->pci_bar0_kva == NULL) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 751 | printk(KERN_ERR "Fail to map bar0\n"); |
Jing Xiangfeng | f0f6c3a | 2020-09-25 14:24:23 +0800 | [diff] [blame] | 752 | rc = -ENODEV; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 753 | goto out_release_region; |
| 754 | } |
| 755 | |
| 756 | bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn); |
| 757 | bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn); |
| 758 | bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva; |
| 759 | bfad->hal_pcidev.device_id = pdev->device; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 760 | bfad->hal_pcidev.ssid = pdev->subsystem_device; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 761 | bfad->pci_name = pci_name(pdev); |
| 762 | |
| 763 | bfad->pci_attr.vendor_id = pdev->vendor; |
| 764 | bfad->pci_attr.device_id = pdev->device; |
| 765 | bfad->pci_attr.ssid = pdev->subsystem_device; |
| 766 | bfad->pci_attr.ssvid = pdev->subsystem_vendor; |
| 767 | bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn); |
| 768 | |
| 769 | bfad->pcidev = pdev; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 770 | |
| 771 | /* Adjust PCIe Maximum Read Request Size */ |
Yijing Wang | c0102c0 | 2013-09-05 15:55:25 +0800 | [diff] [blame] | 772 | if (pci_is_pcie(pdev) && pcie_max_read_reqsz) { |
| 773 | if (pcie_max_read_reqsz >= 128 && |
| 774 | pcie_max_read_reqsz <= 4096 && |
| 775 | is_power_of_2(pcie_max_read_reqsz)) { |
| 776 | int max_rq = pcie_get_readrq(pdev); |
| 777 | printk(KERN_WARNING "BFA[%s]: " |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 778 | "pcie_max_read_request_size is %d, " |
Yijing Wang | c0102c0 | 2013-09-05 15:55:25 +0800 | [diff] [blame] | 779 | "reset to %d\n", bfad->pci_name, max_rq, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 780 | pcie_max_read_reqsz); |
Yijing Wang | c0102c0 | 2013-09-05 15:55:25 +0800 | [diff] [blame] | 781 | pcie_set_readrq(pdev, pcie_max_read_reqsz); |
| 782 | } else { |
| 783 | printk(KERN_WARNING "BFA[%s]: invalid " |
| 784 | "pcie_max_read_request_size %d ignored\n", |
| 785 | bfad->pci_name, pcie_max_read_reqsz); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 789 | pci_save_state(pdev); |
| 790 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 791 | return 0; |
| 792 | |
| 793 | out_release_region: |
| 794 | pci_release_regions(pdev); |
| 795 | out_disable_device: |
| 796 | pci_disable_device(pdev); |
| 797 | out: |
| 798 | return rc; |
| 799 | } |
| 800 | |
| 801 | void |
| 802 | bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad) |
| 803 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 804 | pci_iounmap(pdev, bfad->pci_bar0_kva); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 805 | pci_iounmap(pdev, bfad->pci_bar2_kva); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 806 | pci_release_regions(pdev); |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 807 | /* Disable PCIE Advanced Error Recovery (AER) */ |
| 808 | pci_disable_pcie_error_reporting(pdev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 809 | pci_disable_device(pdev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 812 | bfa_status_t |
| 813 | bfad_drv_init(struct bfad_s *bfad) |
| 814 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 815 | bfa_status_t rc; |
| 816 | unsigned long flags; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 817 | |
| 818 | bfad->cfg_data.rport_del_timeout = rport_del_timeout; |
| 819 | bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth; |
| 820 | bfad->cfg_data.io_max_sge = bfa_io_max_sge; |
| 821 | bfad->cfg_data.binding_method = FCP_PWWN_BINDING; |
| 822 | |
| 823 | rc = bfad_hal_mem_alloc(bfad); |
| 824 | if (rc != BFA_STATUS_OK) { |
| 825 | printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n", |
| 826 | bfad->inst_no); |
| 827 | printk(KERN_WARNING |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 828 | "Not enough memory to attach all QLogic BR-series HBA ports. System may need more memory.\n"); |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 829 | return BFA_STATUS_FAILED; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 832 | bfad->bfa.trcmod = bfad->trcmod; |
| 833 | bfad->bfa.plog = &bfad->plog_buf; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 834 | bfa_plog_init(&bfad->plog_buf); |
| 835 | bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START, |
| 836 | 0, "Driver Attach"); |
| 837 | |
| 838 | bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo, |
| 839 | &bfad->hal_pcidev); |
| 840 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 841 | /* FCS INIT */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 842 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 843 | bfad->bfa_fcs.trcmod = bfad->trcmod; |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 844 | bfa_fcs_attach(&bfad->bfa_fcs, &bfad->bfa, bfad, BFA_FALSE); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 845 | bfad->bfa_fcs.fdmi_enabled = fdmi_enable; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 846 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 847 | |
| 848 | bfad->bfad_flags |= BFAD_DRV_INIT_DONE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 849 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 850 | return BFA_STATUS_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | void |
| 854 | bfad_drv_uninit(struct bfad_s *bfad) |
| 855 | { |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 856 | unsigned long flags; |
| 857 | |
| 858 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 859 | init_completion(&bfad->comp); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 860 | bfa_iocfc_stop(&bfad->bfa); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 861 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 862 | wait_for_completion(&bfad->comp); |
| 863 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 864 | del_timer_sync(&bfad->hal_tmo); |
| 865 | bfa_isr_disable(&bfad->bfa); |
| 866 | bfa_detach(&bfad->bfa); |
| 867 | bfad_remove_intr(bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 868 | bfad_hal_mem_release(bfad); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 869 | |
| 870 | bfad->bfad_flags &= ~BFAD_DRV_INIT_DONE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | void |
| 874 | bfad_drv_start(struct bfad_s *bfad) |
| 875 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 876 | unsigned long flags; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 877 | |
| 878 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 879 | bfa_iocfc_start(&bfad->bfa); |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 880 | bfa_fcs_pbc_vport_init(&bfad->bfa_fcs); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 881 | bfa_fcs_fabric_modstart(&bfad->bfa_fcs); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 882 | bfad->bfad_flags |= BFAD_HAL_START_DONE; |
| 883 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 884 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 885 | if (bfad->im) |
| 886 | flush_workqueue(bfad->im->drv_workq); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 890 | bfad_fcs_stop(struct bfad_s *bfad) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 891 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 892 | unsigned long flags; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 893 | |
| 894 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 895 | init_completion(&bfad->comp); |
| 896 | bfad->pport.flags |= BFAD_PORT_DELETE; |
| 897 | bfa_fcs_exit(&bfad->bfa_fcs); |
| 898 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 899 | wait_for_completion(&bfad->comp); |
| 900 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 901 | bfa_sm_send_event(bfad, BFAD_E_FCS_EXIT_COMP); |
| 902 | } |
| 903 | |
| 904 | void |
| 905 | bfad_stop(struct bfad_s *bfad) |
| 906 | { |
| 907 | unsigned long flags; |
| 908 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 909 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 910 | init_completion(&bfad->comp); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 911 | bfa_iocfc_stop(&bfad->bfa); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 912 | bfad->bfad_flags &= ~BFAD_HAL_START_DONE; |
| 913 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 914 | wait_for_completion(&bfad->comp); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 915 | |
| 916 | bfa_sm_send_event(bfad, BFAD_E_EXIT_COMP); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | bfa_status_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 920 | bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 921 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 922 | int rc = BFA_STATUS_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 923 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 924 | /* Allocate scsi_host for the physical port */ |
| 925 | if ((supported_fc4s & BFA_LPORT_ROLE_FCP_IM) && |
| 926 | (role & BFA_LPORT_ROLE_FCP_IM)) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 927 | if (bfad->pport.im_port == NULL) { |
| 928 | rc = BFA_STATUS_FAILED; |
| 929 | goto out; |
| 930 | } |
| 931 | |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 932 | rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port, |
| 933 | &bfad->pcidev->dev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 934 | if (rc != BFA_STATUS_OK) |
| 935 | goto out; |
| 936 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 937 | bfad->pport.roles |= BFA_LPORT_ROLE_FCP_IM; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | bfad->bfad_flags |= BFAD_CFG_PPORT_DONE; |
| 941 | |
| 942 | out: |
| 943 | return rc; |
| 944 | } |
| 945 | |
| 946 | void |
| 947 | bfad_uncfg_pport(struct bfad_s *bfad) |
| 948 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 949 | if ((supported_fc4s & BFA_LPORT_ROLE_FCP_IM) && |
| 950 | (bfad->pport.roles & BFA_LPORT_ROLE_FCP_IM)) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 951 | bfad_im_scsi_host_free(bfad, bfad->pport.im_port); |
| 952 | bfad_im_port_clean(bfad->pport.im_port); |
| 953 | kfree(bfad->pport.im_port); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 954 | bfad->pport.roles &= ~BFA_LPORT_ROLE_FCP_IM; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE; |
| 958 | } |
| 959 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 960 | bfa_status_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 961 | bfad_start_ops(struct bfad_s *bfad) { |
| 962 | |
| 963 | int retval; |
| 964 | unsigned long flags; |
| 965 | struct bfad_vport_s *vport, *vport_new; |
| 966 | struct bfa_fcs_driver_info_s driver_info; |
| 967 | |
Krishna Gudipati | 61e62e2 | 2011-06-24 20:29:07 -0700 | [diff] [blame] | 968 | /* Limit min/max. xfer size to [64k-32MB] */ |
| 969 | if (max_xfer_size < BFAD_MIN_SECTORS >> 1) |
| 970 | max_xfer_size = BFAD_MIN_SECTORS >> 1; |
| 971 | if (max_xfer_size > BFAD_MAX_SECTORS >> 1) |
| 972 | max_xfer_size = BFAD_MAX_SECTORS >> 1; |
| 973 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 974 | /* Fill the driver_info info to fcs*/ |
| 975 | memset(&driver_info, 0, sizeof(driver_info)); |
Arnd Bergmann | 8c5a50e | 2017-12-04 15:47:00 +0100 | [diff] [blame] | 976 | strlcpy(driver_info.version, BFAD_DRIVER_VERSION, |
| 977 | sizeof(driver_info.version)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 978 | if (host_name) |
Arnd Bergmann | 8c5a50e | 2017-12-04 15:47:00 +0100 | [diff] [blame] | 979 | strlcpy(driver_info.host_machine_name, host_name, |
| 980 | sizeof(driver_info.host_machine_name)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 981 | if (os_name) |
Arnd Bergmann | 8c5a50e | 2017-12-04 15:47:00 +0100 | [diff] [blame] | 982 | strlcpy(driver_info.host_os_name, os_name, |
| 983 | sizeof(driver_info.host_os_name)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 984 | if (os_patch) |
Arnd Bergmann | 8c5a50e | 2017-12-04 15:47:00 +0100 | [diff] [blame] | 985 | strlcpy(driver_info.host_os_patch, os_patch, |
| 986 | sizeof(driver_info.host_os_patch)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 987 | |
Arnd Bergmann | 8c5a50e | 2017-12-04 15:47:00 +0100 | [diff] [blame] | 988 | strlcpy(driver_info.os_device_name, bfad->pci_name, |
| 989 | sizeof(driver_info.os_device_name)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 990 | |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 991 | /* FCS driver info init */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 992 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 993 | bfa_fcs_driver_info_init(&bfad->bfa_fcs, &driver_info); |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 994 | |
| 995 | if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE) |
| 996 | bfa_fcs_update_cfg(&bfad->bfa_fcs); |
| 997 | else |
| 998 | bfa_fcs_init(&bfad->bfa_fcs); |
| 999 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1000 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1001 | |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 1002 | if (!(bfad->bfad_flags & BFAD_CFG_PPORT_DONE)) { |
| 1003 | retval = bfad_cfg_pport(bfad, BFA_LPORT_ROLE_FCP_IM); |
| 1004 | if (retval != BFA_STATUS_OK) |
| 1005 | return BFA_STATUS_FAILED; |
| 1006 | } |
Krishna Gudipati | 75332a7 | 2011-06-13 15:54:31 -0700 | [diff] [blame] | 1007 | |
| 1008 | /* Setup fc host fixed attribute if the lk supports */ |
| 1009 | bfad_fc_host_init(bfad->pport.im_port); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1010 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1011 | /* BFAD level FC4 IM specific resource allocation */ |
| 1012 | retval = bfad_im_probe(bfad); |
| 1013 | if (retval != BFA_STATUS_OK) { |
| 1014 | printk(KERN_WARNING "bfad_im_probe failed\n"); |
| 1015 | if (bfa_sm_cmp_state(bfad, bfad_sm_initializing)) |
| 1016 | bfa_sm_set_state(bfad, bfad_sm_failed); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1017 | return BFA_STATUS_FAILED; |
| 1018 | } else |
| 1019 | bfad->bfad_flags |= BFAD_FC4_PROBE_DONE; |
| 1020 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1021 | bfad_drv_start(bfad); |
| 1022 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1023 | /* Complete pbc vport create */ |
| 1024 | list_for_each_entry_safe(vport, vport_new, &bfad->pbc_vport_list, |
| 1025 | list_entry) { |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1026 | struct fc_vport_identifiers vid; |
| 1027 | struct fc_vport *fc_vport; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1028 | char pwwn_buf[BFA_STRING_32]; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1029 | |
| 1030 | memset(&vid, 0, sizeof(vid)); |
| 1031 | vid.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 1032 | vid.vport_type = FC_PORTTYPE_NPIV; |
| 1033 | vid.disable = false; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1034 | vid.node_name = wwn_to_u64((u8 *) |
| 1035 | (&((vport->fcs_vport).lport.port_cfg.nwwn))); |
| 1036 | vid.port_name = wwn_to_u64((u8 *) |
| 1037 | (&((vport->fcs_vport).lport.port_cfg.pwwn))); |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1038 | fc_vport = fc_vport_create(bfad->pport.im_port->shost, 0, &vid); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1039 | if (!fc_vport) { |
| 1040 | wwn2str(pwwn_buf, vid.port_name); |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1041 | printk(KERN_WARNING "bfad%d: failed to create pbc vport" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1042 | " %s\n", bfad->inst_no, pwwn_buf); |
| 1043 | } |
| 1044 | list_del(&vport->list_entry); |
| 1045 | kfree(vport); |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1048 | /* |
| 1049 | * If bfa_linkup_delay is set to -1 default; try to retrive the |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1050 | * value using the bfad_get_linkup_delay(); else use the |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1051 | * passed in module param value as the bfa_linkup_delay. |
| 1052 | */ |
| 1053 | if (bfa_linkup_delay < 0) { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1054 | bfa_linkup_delay = bfad_get_linkup_delay(bfad); |
| 1055 | bfad_rport_online_wait(bfad); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1056 | bfa_linkup_delay = -1; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1057 | } else |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1058 | bfad_rport_online_wait(bfad); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1059 | |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 1060 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, "bfa device claimed\n"); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1061 | |
| 1062 | return BFA_STATUS_OK; |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | int |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1066 | bfad_worker(void *ptr) |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1067 | { |
Jiri Slaby | 8f7d3f0 | 2015-04-16 12:48:29 -0700 | [diff] [blame] | 1068 | struct bfad_s *bfad = ptr; |
| 1069 | unsigned long flags; |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1070 | |
Jiri Slaby | 8f7d3f0 | 2015-04-16 12:48:29 -0700 | [diff] [blame] | 1071 | if (kthread_should_stop()) |
| 1072 | return 0; |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1073 | |
Jiri Slaby | 8f7d3f0 | 2015-04-16 12:48:29 -0700 | [diff] [blame] | 1074 | /* Send event BFAD_E_INIT_SUCCESS */ |
| 1075 | bfa_sm_send_event(bfad, BFAD_E_INIT_SUCCESS); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1076 | |
Jiri Slaby | 8f7d3f0 | 2015-04-16 12:48:29 -0700 | [diff] [blame] | 1077 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1078 | bfad->bfad_tsk = NULL; |
| 1079 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1084 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1085 | * BFA driver interrupt functions |
| 1086 | */ |
| 1087 | irqreturn_t |
| 1088 | bfad_intx(int irq, void *dev_id) |
| 1089 | { |
| 1090 | struct bfad_s *bfad = dev_id; |
| 1091 | struct list_head doneq; |
| 1092 | unsigned long flags; |
| 1093 | bfa_boolean_t rc; |
| 1094 | |
| 1095 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1096 | rc = bfa_intx(&bfad->bfa); |
| 1097 | if (!rc) { |
| 1098 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1099 | return IRQ_NONE; |
| 1100 | } |
| 1101 | |
| 1102 | bfa_comp_deq(&bfad->bfa, &doneq); |
| 1103 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1104 | |
| 1105 | if (!list_empty(&doneq)) { |
| 1106 | bfa_comp_process(&bfad->bfa, &doneq); |
| 1107 | |
| 1108 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1109 | bfa_comp_free(&bfad->bfa, &doneq); |
| 1110 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | return IRQ_HANDLED; |
| 1114 | |
| 1115 | } |
| 1116 | |
| 1117 | static irqreturn_t |
| 1118 | bfad_msix(int irq, void *dev_id) |
| 1119 | { |
| 1120 | struct bfad_msix_s *vec = dev_id; |
| 1121 | struct bfad_s *bfad = vec->bfad; |
| 1122 | struct list_head doneq; |
| 1123 | unsigned long flags; |
| 1124 | |
| 1125 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1126 | |
| 1127 | bfa_msix(&bfad->bfa, vec->msix.entry); |
| 1128 | bfa_comp_deq(&bfad->bfa, &doneq); |
| 1129 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1130 | |
| 1131 | if (!list_empty(&doneq)) { |
| 1132 | bfa_comp_process(&bfad->bfa, &doneq); |
| 1133 | |
| 1134 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1135 | bfa_comp_free(&bfad->bfa, &doneq); |
| 1136 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1137 | } |
| 1138 | |
| 1139 | return IRQ_HANDLED; |
| 1140 | } |
| 1141 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1142 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1143 | * Initialize the MSIX entry table. |
| 1144 | */ |
| 1145 | static void |
| 1146 | bfad_init_msix_entry(struct bfad_s *bfad, struct msix_entry *msix_entries, |
| 1147 | int mask, int max_bit) |
| 1148 | { |
| 1149 | int i; |
| 1150 | int match = 0x00000001; |
| 1151 | |
| 1152 | for (i = 0, bfad->nvec = 0; i < MAX_MSIX_ENTRY; i++) { |
| 1153 | if (mask & match) { |
| 1154 | bfad->msix_tab[bfad->nvec].msix.entry = i; |
| 1155 | bfad->msix_tab[bfad->nvec].bfad = bfad; |
| 1156 | msix_entries[bfad->nvec].entry = i; |
| 1157 | bfad->nvec++; |
| 1158 | } |
| 1159 | |
| 1160 | match <<= 1; |
| 1161 | } |
| 1162 | |
| 1163 | } |
| 1164 | |
| 1165 | int |
| 1166 | bfad_install_msix_handler(struct bfad_s *bfad) |
| 1167 | { |
| 1168 | int i, error = 0; |
| 1169 | |
| 1170 | for (i = 0; i < bfad->nvec; i++) { |
| 1171 | sprintf(bfad->msix_tab[i].name, "bfa-%s-%s", |
| 1172 | bfad->pci_name, |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1173 | ((bfa_asic_id_cb(bfad->hal_pcidev.device_id)) ? |
| 1174 | msix_name_cb[i] : msix_name_ct[i])); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1175 | |
| 1176 | error = request_irq(bfad->msix_tab[i].msix.vector, |
| 1177 | (irq_handler_t) bfad_msix, 0, |
| 1178 | bfad->msix_tab[i].name, &bfad->msix_tab[i]); |
| 1179 | bfa_trc(bfad, i); |
| 1180 | bfa_trc(bfad, bfad->msix_tab[i].msix.vector); |
| 1181 | if (error) { |
| 1182 | int j; |
| 1183 | |
| 1184 | for (j = 0; j < i; j++) |
| 1185 | free_irq(bfad->msix_tab[j].msix.vector, |
| 1186 | &bfad->msix_tab[j]); |
| 1187 | |
Krishna Gudipati | 61e62e2 | 2011-06-24 20:29:07 -0700 | [diff] [blame] | 1188 | bfad->bfad_flags &= ~BFAD_MSIX_ON; |
| 1189 | pci_disable_msix(bfad->pcidev); |
| 1190 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1191 | return 1; |
| 1192 | } |
| 1193 | } |
| 1194 | |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1198 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1199 | * Setup MSIX based interrupt. |
| 1200 | */ |
| 1201 | int |
| 1202 | bfad_setup_intr(struct bfad_s *bfad) |
| 1203 | { |
Alexander Gordeev | 8cb7f63 | 2014-07-16 20:05:07 +0200 | [diff] [blame] | 1204 | int error; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1205 | u32 mask = 0, i, num_bit = 0, max_bit = 0; |
| 1206 | struct msix_entry msix_entries[MAX_MSIX_ENTRY]; |
| 1207 | struct pci_dev *pdev = bfad->pcidev; |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 1208 | u16 reg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1209 | |
| 1210 | /* Call BFA to get the msix map for this PCI function. */ |
| 1211 | bfa_msix_getvecs(&bfad->bfa, &mask, &num_bit, &max_bit); |
| 1212 | |
| 1213 | /* Set up the msix entry table */ |
| 1214 | bfad_init_msix_entry(bfad, msix_entries, mask, max_bit); |
| 1215 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1216 | if ((bfa_asic_id_ctc(pdev->device) && !msix_disable_ct) || |
| 1217 | (bfa_asic_id_cb(pdev->device) && !msix_disable_cb)) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1218 | |
Alexander Gordeev | b427d00 | 2014-07-16 20:05:08 +0200 | [diff] [blame] | 1219 | error = pci_enable_msix_exact(bfad->pcidev, |
| 1220 | msix_entries, bfad->nvec); |
Alexander Gordeev | cd69a09 | 2014-07-16 20:05:06 +0200 | [diff] [blame] | 1221 | /* In CT1 & CT2, try to allocate just one vector */ |
Alexander Gordeev | b427d00 | 2014-07-16 20:05:08 +0200 | [diff] [blame] | 1222 | if (error == -ENOSPC && bfa_asic_id_ctc(pdev->device)) { |
Alexander Gordeev | cd69a09 | 2014-07-16 20:05:06 +0200 | [diff] [blame] | 1223 | printk(KERN_WARNING "bfa %s: trying one msix " |
| 1224 | "vector failed to allocate %d[%d]\n", |
| 1225 | bfad->pci_name, bfad->nvec, error); |
| 1226 | bfad->nvec = 1; |
Alexander Gordeev | b427d00 | 2014-07-16 20:05:08 +0200 | [diff] [blame] | 1227 | error = pci_enable_msix_exact(bfad->pcidev, |
| 1228 | msix_entries, 1); |
Alexander Gordeev | cd69a09 | 2014-07-16 20:05:06 +0200 | [diff] [blame] | 1229 | } |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1230 | |
Alexander Gordeev | cd69a09 | 2014-07-16 20:05:06 +0200 | [diff] [blame] | 1231 | if (error) { |
| 1232 | printk(KERN_WARNING "bfad%d: " |
Alexander Gordeev | b427d00 | 2014-07-16 20:05:08 +0200 | [diff] [blame] | 1233 | "pci_enable_msix_exact failed (%d), " |
Alexander Gordeev | cd69a09 | 2014-07-16 20:05:06 +0200 | [diff] [blame] | 1234 | "use line based.\n", |
| 1235 | bfad->inst_no, error); |
| 1236 | goto line_based; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 1239 | /* Disable INTX in MSI-X mode */ |
| 1240 | pci_read_config_word(pdev, PCI_COMMAND, ®); |
| 1241 | |
| 1242 | if (!(reg & PCI_COMMAND_INTX_DISABLE)) |
| 1243 | pci_write_config_word(pdev, PCI_COMMAND, |
| 1244 | reg | PCI_COMMAND_INTX_DISABLE); |
| 1245 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1246 | /* Save the vectors */ |
| 1247 | for (i = 0; i < bfad->nvec; i++) { |
| 1248 | bfa_trc(bfad, msix_entries[i].vector); |
| 1249 | bfad->msix_tab[i].msix.vector = msix_entries[i].vector; |
| 1250 | } |
| 1251 | |
| 1252 | bfa_msix_init(&bfad->bfa, bfad->nvec); |
| 1253 | |
| 1254 | bfad->bfad_flags |= BFAD_MSIX_ON; |
| 1255 | |
Alexander Gordeev | 8cb7f63 | 2014-07-16 20:05:07 +0200 | [diff] [blame] | 1256 | return 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | line_based: |
Alexander Gordeev | 8cb7f63 | 2014-07-16 20:05:07 +0200 | [diff] [blame] | 1260 | error = request_irq(bfad->pcidev->irq, (irq_handler_t)bfad_intx, |
| 1261 | BFAD_IRQ_FLAGS, BFAD_DRIVER_NAME, bfad); |
| 1262 | if (error) |
| 1263 | return error; |
| 1264 | |
Krishna Gudipati | 61e62e2 | 2011-06-24 20:29:07 -0700 | [diff] [blame] | 1265 | bfad->bfad_flags |= BFAD_INTX_ON; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1266 | |
Alexander Gordeev | 8cb7f63 | 2014-07-16 20:05:07 +0200 | [diff] [blame] | 1267 | return 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | void |
| 1271 | bfad_remove_intr(struct bfad_s *bfad) |
| 1272 | { |
| 1273 | int i; |
| 1274 | |
| 1275 | if (bfad->bfad_flags & BFAD_MSIX_ON) { |
| 1276 | for (i = 0; i < bfad->nvec; i++) |
| 1277 | free_irq(bfad->msix_tab[i].msix.vector, |
| 1278 | &bfad->msix_tab[i]); |
| 1279 | |
| 1280 | pci_disable_msix(bfad->pcidev); |
| 1281 | bfad->bfad_flags &= ~BFAD_MSIX_ON; |
Krishna Gudipati | 61e62e2 | 2011-06-24 20:29:07 -0700 | [diff] [blame] | 1282 | } else if (bfad->bfad_flags & BFAD_INTX_ON) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1283 | free_irq(bfad->pcidev->irq, bfad); |
| 1284 | } |
| 1285 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1286 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1287 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1288 | * PCI probe entry. |
| 1289 | */ |
| 1290 | int |
| 1291 | bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 1292 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1293 | struct bfad_s *bfad; |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 1294 | int error = -ENODEV, retval, i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1295 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1296 | /* For single port cards - only claim function 0 */ |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 1297 | if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P) && |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1298 | (PCI_FUNC(pdev->devfn) != 0)) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1299 | return -ENODEV; |
| 1300 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1301 | bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL); |
| 1302 | if (!bfad) { |
| 1303 | error = -ENOMEM; |
| 1304 | goto out; |
| 1305 | } |
| 1306 | |
| 1307 | bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL); |
| 1308 | if (!bfad->trcmod) { |
| 1309 | printk(KERN_WARNING "Error alloc trace buffer!\n"); |
| 1310 | error = -ENOMEM; |
| 1311 | goto out_alloc_trace_failure; |
| 1312 | } |
| 1313 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1314 | /* TRACE INIT */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1315 | bfa_trc_init(bfad->trcmod); |
| 1316 | bfa_trc(bfad, bfad_inst); |
| 1317 | |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 1318 | /* AEN INIT */ |
| 1319 | INIT_LIST_HEAD(&bfad->free_aen_q); |
| 1320 | INIT_LIST_HEAD(&bfad->active_aen_q); |
| 1321 | for (i = 0; i < BFA_AEN_MAX_ENTRY; i++) |
| 1322 | list_add_tail(&bfad->aen_list[i].qe, &bfad->free_aen_q); |
| 1323 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1324 | if (!(bfad_load_fwimg(pdev))) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1325 | kfree(bfad->trcmod); |
| 1326 | goto out_alloc_trace_failure; |
| 1327 | } |
| 1328 | |
| 1329 | retval = bfad_pci_init(pdev, bfad); |
| 1330 | if (retval) { |
| 1331 | printk(KERN_WARNING "bfad_pci_init failure!\n"); |
| 1332 | error = retval; |
| 1333 | goto out_pci_init_failure; |
| 1334 | } |
| 1335 | |
| 1336 | mutex_lock(&bfad_mutex); |
| 1337 | bfad->inst_no = bfad_inst++; |
| 1338 | list_add_tail(&bfad->list_entry, &bfad_list); |
| 1339 | mutex_unlock(&bfad_mutex); |
| 1340 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1341 | /* Initializing the state machine: State set to uninit */ |
| 1342 | bfa_sm_set_state(bfad, bfad_sm_uninit); |
| 1343 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1344 | spin_lock_init(&bfad->bfad_lock); |
Kyle McMartin | 0b1017a | 2012-07-11 12:42:55 -0400 | [diff] [blame] | 1345 | spin_lock_init(&bfad->bfad_aen_spinlock); |
| 1346 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1347 | pci_set_drvdata(pdev, bfad); |
| 1348 | |
| 1349 | bfad->ref_count = 0; |
| 1350 | bfad->pport.bfad = bfad; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1351 | INIT_LIST_HEAD(&bfad->pbc_vport_list); |
Krishna Gudipati | 5b7db7a | 2011-12-20 18:58:32 -0800 | [diff] [blame] | 1352 | INIT_LIST_HEAD(&bfad->vport_list); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1353 | |
Krishna Gudipati | 7c38c05 | 2011-04-14 16:50:35 -0700 | [diff] [blame] | 1354 | /* Setup the debugfs node for this bfad */ |
| 1355 | if (bfa_debugfs_enable) |
| 1356 | bfad_debugfs_init(&bfad->pport); |
| 1357 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1358 | retval = bfad_drv_init(bfad); |
| 1359 | if (retval != BFA_STATUS_OK) |
| 1360 | goto out_drv_init_failure; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1361 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1362 | bfa_sm_send_event(bfad, BFAD_E_CREATE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1363 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1364 | if (bfa_sm_cmp_state(bfad, bfad_sm_uninit)) |
| 1365 | goto out_bfad_sm_failure; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1366 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1367 | return 0; |
| 1368 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1369 | out_bfad_sm_failure: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1370 | bfad_hal_mem_release(bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1371 | out_drv_init_failure: |
Krishna Gudipati | 7c38c05 | 2011-04-14 16:50:35 -0700 | [diff] [blame] | 1372 | /* Remove the debugfs node for this bfad */ |
| 1373 | kfree(bfad->regdata); |
| 1374 | bfad_debugfs_exit(&bfad->pport); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1375 | mutex_lock(&bfad_mutex); |
| 1376 | bfad_inst--; |
| 1377 | list_del(&bfad->list_entry); |
| 1378 | mutex_unlock(&bfad_mutex); |
| 1379 | bfad_pci_uninit(pdev, bfad); |
| 1380 | out_pci_init_failure: |
| 1381 | kfree(bfad->trcmod); |
| 1382 | out_alloc_trace_failure: |
| 1383 | kfree(bfad); |
| 1384 | out: |
| 1385 | return error; |
| 1386 | } |
| 1387 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1388 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1389 | * PCI remove entry. |
| 1390 | */ |
| 1391 | void |
| 1392 | bfad_pci_remove(struct pci_dev *pdev) |
| 1393 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1394 | struct bfad_s *bfad = pci_get_drvdata(pdev); |
| 1395 | unsigned long flags; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1396 | |
| 1397 | bfa_trc(bfad, bfad->inst_no); |
| 1398 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1399 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1400 | if (bfad->bfad_tsk != NULL) { |
| 1401 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1402 | kthread_stop(bfad->bfad_tsk); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1403 | } else { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1404 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1407 | /* Send Event BFAD_E_STOP */ |
| 1408 | bfa_sm_send_event(bfad, BFAD_E_STOP); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1409 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1410 | /* Driver detach and dealloc mem */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1411 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1412 | bfa_detach(&bfad->bfa); |
| 1413 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1414 | bfad_hal_mem_release(bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1415 | |
Krishna Gudipati | 7c38c05 | 2011-04-14 16:50:35 -0700 | [diff] [blame] | 1416 | /* Remove the debugfs node for this bfad */ |
| 1417 | kfree(bfad->regdata); |
| 1418 | bfad_debugfs_exit(&bfad->pport); |
| 1419 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1420 | /* Cleaning the BFAD instance */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1421 | mutex_lock(&bfad_mutex); |
| 1422 | bfad_inst--; |
| 1423 | list_del(&bfad->list_entry); |
| 1424 | mutex_unlock(&bfad_mutex); |
| 1425 | bfad_pci_uninit(pdev, bfad); |
| 1426 | |
| 1427 | kfree(bfad->trcmod); |
| 1428 | kfree(bfad); |
| 1429 | } |
| 1430 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1431 | /* |
| 1432 | * PCI Error Recovery entry, error detected. |
| 1433 | */ |
| 1434 | static pci_ers_result_t |
| 1435 | bfad_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state) |
| 1436 | { |
| 1437 | struct bfad_s *bfad = pci_get_drvdata(pdev); |
| 1438 | unsigned long flags; |
| 1439 | pci_ers_result_t ret = PCI_ERS_RESULT_NONE; |
| 1440 | |
| 1441 | dev_printk(KERN_ERR, &pdev->dev, |
| 1442 | "error detected state: %d - flags: 0x%x\n", |
| 1443 | state, bfad->bfad_flags); |
| 1444 | |
| 1445 | switch (state) { |
| 1446 | case pci_channel_io_normal: /* non-fatal error */ |
| 1447 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1448 | bfad->bfad_flags &= ~BFAD_EEH_BUSY; |
| 1449 | /* Suspend/fail all bfa operations */ |
| 1450 | bfa_ioc_suspend(&bfad->bfa.ioc); |
| 1451 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1452 | del_timer_sync(&bfad->hal_tmo); |
| 1453 | ret = PCI_ERS_RESULT_CAN_RECOVER; |
| 1454 | break; |
| 1455 | case pci_channel_io_frozen: /* fatal error */ |
| 1456 | init_completion(&bfad->comp); |
| 1457 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1458 | bfad->bfad_flags |= BFAD_EEH_BUSY; |
| 1459 | /* Suspend/fail all bfa operations */ |
| 1460 | bfa_ioc_suspend(&bfad->bfa.ioc); |
| 1461 | bfa_fcs_stop(&bfad->bfa_fcs); |
| 1462 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1463 | wait_for_completion(&bfad->comp); |
| 1464 | |
| 1465 | bfad_remove_intr(bfad); |
| 1466 | del_timer_sync(&bfad->hal_tmo); |
| 1467 | pci_disable_device(pdev); |
| 1468 | ret = PCI_ERS_RESULT_NEED_RESET; |
| 1469 | break; |
| 1470 | case pci_channel_io_perm_failure: /* PCI Card is DEAD */ |
| 1471 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1472 | bfad->bfad_flags |= BFAD_EEH_BUSY | |
| 1473 | BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE; |
| 1474 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1475 | |
| 1476 | /* If the error_detected handler is called with the reason |
| 1477 | * pci_channel_io_perm_failure - it will subsequently call |
| 1478 | * pci_remove() entry point to remove the pci device from the |
| 1479 | * system - So defer the cleanup to pci_remove(); cleaning up |
| 1480 | * here causes inconsistent state during pci_remove(). |
| 1481 | */ |
| 1482 | ret = PCI_ERS_RESULT_DISCONNECT; |
| 1483 | break; |
| 1484 | default: |
| 1485 | WARN_ON(1); |
| 1486 | } |
| 1487 | |
| 1488 | return ret; |
| 1489 | } |
| 1490 | |
YueHaibing | 7cd4cb9 | 2019-09-30 17:43:27 +0800 | [diff] [blame] | 1491 | static int restart_bfa(struct bfad_s *bfad) |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1492 | { |
| 1493 | unsigned long flags; |
| 1494 | struct pci_dev *pdev = bfad->pcidev; |
| 1495 | |
| 1496 | bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, |
| 1497 | &bfad->meminfo, &bfad->hal_pcidev); |
| 1498 | |
| 1499 | /* Enable Interrupt and wait bfa_init completion */ |
| 1500 | if (bfad_setup_intr(bfad)) { |
| 1501 | dev_printk(KERN_WARNING, &pdev->dev, |
| 1502 | "%s: bfad_setup_intr failed\n", bfad->pci_name); |
Vijaya Mohan Guvva | da3e0be | 2013-11-21 01:37:33 -0800 | [diff] [blame] | 1503 | bfa_sm_send_event(bfad, BFAD_E_INIT_FAILED); |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1504 | return -1; |
| 1505 | } |
| 1506 | |
| 1507 | init_completion(&bfad->comp); |
| 1508 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1509 | bfa_iocfc_init(&bfad->bfa); |
| 1510 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1511 | |
| 1512 | /* Set up interrupt handler for each vectors */ |
| 1513 | if ((bfad->bfad_flags & BFAD_MSIX_ON) && |
| 1514 | bfad_install_msix_handler(bfad)) |
| 1515 | dev_printk(KERN_WARNING, &pdev->dev, |
| 1516 | "%s: install_msix failed.\n", bfad->pci_name); |
| 1517 | |
| 1518 | bfad_init_timer(bfad); |
| 1519 | wait_for_completion(&bfad->comp); |
| 1520 | bfad_drv_start(bfad); |
| 1521 | |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
| 1525 | /* |
| 1526 | * PCI Error Recovery entry, re-initialize the chip. |
| 1527 | */ |
| 1528 | static pci_ers_result_t |
| 1529 | bfad_pci_slot_reset(struct pci_dev *pdev) |
| 1530 | { |
| 1531 | struct bfad_s *bfad = pci_get_drvdata(pdev); |
| 1532 | u8 byte; |
Hannes Reinecke | 11ea382 | 2019-02-18 08:34:23 +0100 | [diff] [blame] | 1533 | int rc; |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1534 | |
| 1535 | dev_printk(KERN_ERR, &pdev->dev, |
| 1536 | "bfad_pci_slot_reset flags: 0x%x\n", bfad->bfad_flags); |
| 1537 | |
| 1538 | if (pci_enable_device(pdev)) { |
| 1539 | dev_printk(KERN_ERR, &pdev->dev, "Cannot re-enable " |
| 1540 | "PCI device after reset.\n"); |
| 1541 | return PCI_ERS_RESULT_DISCONNECT; |
| 1542 | } |
| 1543 | |
| 1544 | pci_restore_state(pdev); |
| 1545 | |
| 1546 | /* |
| 1547 | * Read some byte (e.g. DMA max. payload size which can't |
| 1548 | * be 0xff any time) to make sure - we did not hit another PCI error |
| 1549 | * in the middle of recovery. If we did, then declare permanent failure. |
| 1550 | */ |
| 1551 | pci_read_config_byte(pdev, 0x68, &byte); |
| 1552 | if (byte == 0xff) { |
| 1553 | dev_printk(KERN_ERR, &pdev->dev, |
| 1554 | "slot_reset failed ... got another PCI error !\n"); |
| 1555 | goto out_disable_device; |
| 1556 | } |
| 1557 | |
| 1558 | pci_save_state(pdev); |
| 1559 | pci_set_master(pdev); |
| 1560 | |
Hannes Reinecke | 11ea382 | 2019-02-18 08:34:23 +0100 | [diff] [blame] | 1561 | rc = dma_set_mask_and_coherent(&bfad->pcidev->dev, DMA_BIT_MASK(64)); |
| 1562 | if (rc) |
| 1563 | rc = dma_set_mask_and_coherent(&bfad->pcidev->dev, |
| 1564 | DMA_BIT_MASK(32)); |
| 1565 | if (rc) |
Christoph Hellwig | a69b080 | 2018-10-18 15:10:14 +0200 | [diff] [blame] | 1566 | goto out_disable_device; |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1567 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1568 | if (restart_bfa(bfad) == -1) |
| 1569 | goto out_disable_device; |
| 1570 | |
| 1571 | pci_enable_pcie_error_reporting(pdev); |
| 1572 | dev_printk(KERN_WARNING, &pdev->dev, |
| 1573 | "slot_reset completed flags: 0x%x!\n", bfad->bfad_flags); |
| 1574 | |
| 1575 | return PCI_ERS_RESULT_RECOVERED; |
| 1576 | |
| 1577 | out_disable_device: |
| 1578 | pci_disable_device(pdev); |
| 1579 | return PCI_ERS_RESULT_DISCONNECT; |
| 1580 | } |
| 1581 | |
| 1582 | static pci_ers_result_t |
| 1583 | bfad_pci_mmio_enabled(struct pci_dev *pdev) |
| 1584 | { |
| 1585 | unsigned long flags; |
| 1586 | struct bfad_s *bfad = pci_get_drvdata(pdev); |
| 1587 | |
| 1588 | dev_printk(KERN_INFO, &pdev->dev, "mmio_enabled\n"); |
| 1589 | |
| 1590 | /* Fetch FW diagnostic information */ |
| 1591 | bfa_ioc_debug_save_ftrc(&bfad->bfa.ioc); |
| 1592 | |
| 1593 | /* Cancel all pending IOs */ |
| 1594 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1595 | init_completion(&bfad->comp); |
| 1596 | bfa_fcs_stop(&bfad->bfa_fcs); |
| 1597 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1598 | wait_for_completion(&bfad->comp); |
| 1599 | |
| 1600 | bfad_remove_intr(bfad); |
| 1601 | del_timer_sync(&bfad->hal_tmo); |
| 1602 | pci_disable_device(pdev); |
| 1603 | |
| 1604 | return PCI_ERS_RESULT_NEED_RESET; |
| 1605 | } |
| 1606 | |
| 1607 | static void |
| 1608 | bfad_pci_resume(struct pci_dev *pdev) |
| 1609 | { |
| 1610 | unsigned long flags; |
| 1611 | struct bfad_s *bfad = pci_get_drvdata(pdev); |
| 1612 | |
| 1613 | dev_printk(KERN_WARNING, &pdev->dev, "resume\n"); |
| 1614 | |
| 1615 | /* wait until the link is online */ |
| 1616 | bfad_rport_online_wait(bfad); |
| 1617 | |
| 1618 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1619 | bfad->bfad_flags &= ~BFAD_EEH_BUSY; |
| 1620 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1621 | } |
| 1622 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1623 | struct pci_device_id bfad_id_table[] = { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1624 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1625 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1626 | .device = BFA_PCI_DEVICE_ID_FC_8G2P, |
| 1627 | .subvendor = PCI_ANY_ID, |
| 1628 | .subdevice = PCI_ANY_ID, |
| 1629 | }, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1630 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1631 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1632 | .device = BFA_PCI_DEVICE_ID_FC_8G1P, |
| 1633 | .subvendor = PCI_ANY_ID, |
| 1634 | .subdevice = PCI_ANY_ID, |
| 1635 | }, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1636 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1637 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1638 | .device = BFA_PCI_DEVICE_ID_CT, |
| 1639 | .subvendor = PCI_ANY_ID, |
| 1640 | .subdevice = PCI_ANY_ID, |
| 1641 | .class = (PCI_CLASS_SERIAL_FIBER << 8), |
| 1642 | .class_mask = ~0, |
| 1643 | }, |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 1644 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1645 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1646 | .device = BFA_PCI_DEVICE_ID_CT_FC, |
| 1647 | .subvendor = PCI_ANY_ID, |
| 1648 | .subdevice = PCI_ANY_ID, |
| 1649 | .class = (PCI_CLASS_SERIAL_FIBER << 8), |
| 1650 | .class_mask = ~0, |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 1651 | }, |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1652 | { |
| 1653 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1654 | .device = BFA_PCI_DEVICE_ID_CT2, |
| 1655 | .subvendor = PCI_ANY_ID, |
| 1656 | .subdevice = PCI_ANY_ID, |
| 1657 | .class = (PCI_CLASS_SERIAL_FIBER << 8), |
| 1658 | .class_mask = ~0, |
| 1659 | }, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1660 | |
Vijaya Mohan Guvva | f9c867b | 2013-05-13 02:33:33 -0700 | [diff] [blame] | 1661 | { |
| 1662 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1663 | .device = BFA_PCI_DEVICE_ID_CT2_QUAD, |
| 1664 | .subvendor = PCI_ANY_ID, |
| 1665 | .subdevice = PCI_ANY_ID, |
| 1666 | .class = (PCI_CLASS_SERIAL_FIBER << 8), |
| 1667 | .class_mask = ~0, |
| 1668 | }, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1669 | {0, 0}, |
| 1670 | }; |
| 1671 | |
| 1672 | MODULE_DEVICE_TABLE(pci, bfad_id_table); |
| 1673 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1674 | /* |
| 1675 | * PCI error recovery handlers. |
| 1676 | */ |
| 1677 | static struct pci_error_handlers bfad_err_handler = { |
| 1678 | .error_detected = bfad_pci_error_detected, |
| 1679 | .slot_reset = bfad_pci_slot_reset, |
| 1680 | .mmio_enabled = bfad_pci_mmio_enabled, |
| 1681 | .resume = bfad_pci_resume, |
| 1682 | }; |
| 1683 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1684 | static struct pci_driver bfad_pci_driver = { |
| 1685 | .name = BFAD_DRIVER_NAME, |
| 1686 | .id_table = bfad_id_table, |
| 1687 | .probe = bfad_pci_probe, |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 1688 | .remove = bfad_pci_remove, |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1689 | .err_handler = &bfad_err_handler, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1690 | }; |
| 1691 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1692 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1693 | * Driver module init. |
| 1694 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1695 | static int __init |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1696 | bfad_init(void) |
| 1697 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1698 | int error = 0; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1699 | |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 1700 | pr_info("QLogic BR-series BFA FC/FCOE SCSI driver - version: %s\n", |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1701 | BFAD_DRIVER_VERSION); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1702 | |
| 1703 | if (num_sgpgs > 0) |
| 1704 | num_sgpgs_parm = num_sgpgs; |
| 1705 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1706 | error = bfad_im_module_init(); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1707 | if (error) { |
| 1708 | error = -ENOMEM; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1709 | printk(KERN_WARNING "bfad_im_module_init failure\n"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1710 | goto ext; |
| 1711 | } |
| 1712 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1713 | if (strcmp(FCPI_NAME, " fcpim") == 0) |
| 1714 | supported_fc4s |= BFA_LPORT_ROLE_FCP_IM; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1715 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1716 | bfa_auto_recover = ioc_auto_recover; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1717 | bfa_fcs_rport_set_del_timeout(rport_del_timeout); |
Krishna Gudipati | 61ba439 | 2012-08-22 19:52:58 -0700 | [diff] [blame] | 1718 | bfa_fcs_rport_set_max_logins(max_rport_logins); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1719 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1720 | error = pci_register_driver(&bfad_pci_driver); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1721 | if (error) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1722 | printk(KERN_WARNING "pci_register_driver failure\n"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1723 | goto ext; |
| 1724 | } |
| 1725 | |
| 1726 | return 0; |
| 1727 | |
| 1728 | ext: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1729 | bfad_im_module_exit(); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1730 | return error; |
| 1731 | } |
| 1732 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1733 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1734 | * Driver module exit. |
| 1735 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1736 | static void __exit |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1737 | bfad_exit(void) |
| 1738 | { |
| 1739 | pci_unregister_driver(&bfad_pci_driver); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1740 | bfad_im_module_exit(); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1741 | bfad_free_fwimg(); |
| 1742 | } |
| 1743 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1744 | /* Firmware handling */ |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 1745 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1746 | bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image, |
| 1747 | u32 *bfi_image_size, char *fw_name) |
| 1748 | { |
| 1749 | const struct firmware *fw; |
| 1750 | |
| 1751 | if (request_firmware(&fw, fw_name, &pdev->dev)) { |
| 1752 | printk(KERN_ALERT "Can't locate firmware %s\n", fw_name); |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 1753 | *bfi_image = NULL; |
| 1754 | goto out; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | *bfi_image = vmalloc(fw->size); |
| 1758 | if (NULL == *bfi_image) { |
| 1759 | printk(KERN_ALERT "Fail to allocate buffer for fw image " |
| 1760 | "size=%x!\n", (u32) fw->size); |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 1761 | goto out; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1762 | } |
| 1763 | |
| 1764 | memcpy(*bfi_image, fw->data, fw->size); |
| 1765 | *bfi_image_size = fw->size/sizeof(u32); |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 1766 | out: |
| 1767 | release_firmware(fw); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 1770 | static u32 * |
| 1771 | bfad_load_fwimg(struct pci_dev *pdev) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1772 | { |
Vijaya Mohan Guvva | dcaf9ae | 2013-12-04 05:43:58 -0800 | [diff] [blame] | 1773 | if (bfa_asic_id_ct2(pdev->device)) { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1774 | if (bfi_image_ct2_size == 0) |
| 1775 | bfad_read_firmware(pdev, &bfi_image_ct2, |
| 1776 | &bfi_image_ct2_size, BFAD_FW_FILE_CT2); |
| 1777 | return bfi_image_ct2; |
| 1778 | } else if (bfa_asic_id_ct(pdev->device)) { |
| 1779 | if (bfi_image_ct_size == 0) |
| 1780 | bfad_read_firmware(pdev, &bfi_image_ct, |
| 1781 | &bfi_image_ct_size, BFAD_FW_FILE_CT); |
| 1782 | return bfi_image_ct; |
Vijaya Mohan Guvva | dcaf9ae | 2013-12-04 05:43:58 -0800 | [diff] [blame] | 1783 | } else if (bfa_asic_id_cb(pdev->device)) { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1784 | if (bfi_image_cb_size == 0) |
| 1785 | bfad_read_firmware(pdev, &bfi_image_cb, |
| 1786 | &bfi_image_cb_size, BFAD_FW_FILE_CB); |
| 1787 | return bfi_image_cb; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1788 | } |
Vijaya Mohan Guvva | dcaf9ae | 2013-12-04 05:43:58 -0800 | [diff] [blame] | 1789 | |
| 1790 | return NULL; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1791 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1792 | |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 1793 | static void |
| 1794 | bfad_free_fwimg(void) |
| 1795 | { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1796 | if (bfi_image_ct2_size && bfi_image_ct2) |
| 1797 | vfree(bfi_image_ct2); |
| 1798 | if (bfi_image_ct_size && bfi_image_ct) |
| 1799 | vfree(bfi_image_ct); |
| 1800 | if (bfi_image_cb_size && bfi_image_cb) |
| 1801 | vfree(bfi_image_cb); |
Jing Huang | 61338a0 | 2011-04-13 11:44:03 -0700 | [diff] [blame] | 1802 | } |
| 1803 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1804 | module_init(bfad_init); |
| 1805 | module_exit(bfad_exit); |
| 1806 | MODULE_LICENSE("GPL"); |
Anil Gurumurthy | 31e1d56 | 2015-11-26 03:54:46 -0500 | [diff] [blame] | 1807 | MODULE_DESCRIPTION("QLogic BR-series Fibre Channel HBA Driver" BFAD_PROTO_NAME); |
| 1808 | MODULE_AUTHOR("QLogic Corporation"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1809 | MODULE_VERSION(BFAD_DRIVER_VERSION); |