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