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