Vikas Chaudhary | f39a775 | 2014-07-03 08:18:27 -0400 | [diff] [blame] | 1 | /* bnx2i.c: QLogic NetXtreme II iSCSI driver. |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 2 | * |
Eddie Wai | 0b3bf38 | 2013-07-11 17:15:55 -0700 | [diff] [blame] | 3 | * Copyright (c) 2006 - 2013 Broadcom Corporation |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 4 | * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved. |
| 5 | * Copyright (c) 2007, 2008 Mike Christie |
Vikas Chaudhary | f39a775 | 2014-07-03 08:18:27 -0400 | [diff] [blame] | 6 | * Copyright (c) 2014, QLogic Corporation |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation. |
| 11 | * |
| 12 | * Written by: Anil Veerabhadrappa (anilgv@broadcom.com) |
Vikas Chaudhary | f39a775 | 2014-07-03 08:18:27 -0400 | [diff] [blame] | 13 | * Previously Maintained by: Eddie Wai (eddie.wai@broadcom.com) |
| 14 | * Maintained by: QLogic-Storage-Upstream@qlogic.com |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include "bnx2i.h" |
| 18 | |
| 19 | static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list); |
| 20 | static u32 adapter_count; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 21 | |
| 22 | #define DRV_MODULE_NAME "bnx2i" |
Vikas Chaudhary | e090cc9 | 2014-07-17 05:19:49 -0400 | [diff] [blame] | 23 | #define DRV_MODULE_VERSION "2.7.10.1" |
| 24 | #define DRV_MODULE_RELDATE "Jul 16, 2014" |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 25 | |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 26 | static char version[] = |
Vikas Chaudhary | f39a775 | 2014-07-03 08:18:27 -0400 | [diff] [blame] | 27 | "QLogic NetXtreme II iSCSI Driver " DRV_MODULE_NAME \ |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 28 | " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 29 | |
| 30 | |
Eddie Wai | fc91961 | 2010-08-12 16:44:31 -0700 | [diff] [blame] | 31 | MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and " |
| 32 | "Eddie Wai <eddie.wai@broadcom.com>"); |
| 33 | |
Vikas Chaudhary | f39a775 | 2014-07-03 08:18:27 -0400 | [diff] [blame] | 34 | MODULE_DESCRIPTION("QLogic NetXtreme II BCM5706/5708/5709/57710/57711/57712" |
Michael Chan | f4b5ad2 | 2011-06-20 15:15:56 +0000 | [diff] [blame] | 35 | "/57800/57810/57840 iSCSI Driver"); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 36 | MODULE_LICENSE("GPL"); |
| 37 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 38 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 39 | static DEFINE_MUTEX(bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 40 | |
Anil Veerabhadrappa | 8776193 | 2009-12-07 11:40:18 -0800 | [diff] [blame] | 41 | unsigned int event_coal_min = 24; |
| 42 | module_param(event_coal_min, int, 0664); |
| 43 | MODULE_PARM_DESC(event_coal_min, "Event Coalescing Minimum Commands"); |
| 44 | |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 45 | unsigned int event_coal_div = 2; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 46 | module_param(event_coal_div, int, 0664); |
| 47 | MODULE_PARM_DESC(event_coal_div, "Event Coalescing Divide Factor"); |
| 48 | |
| 49 | unsigned int en_tcp_dack = 1; |
| 50 | module_param(en_tcp_dack, int, 0664); |
| 51 | MODULE_PARM_DESC(en_tcp_dack, "Enable TCP Delayed ACK"); |
| 52 | |
| 53 | unsigned int error_mask1 = 0x00; |
Eddie Wai | 70fc872 | 2012-02-02 15:22:00 -0800 | [diff] [blame] | 54 | module_param(error_mask1, uint, 0664); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 55 | MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1"); |
| 56 | |
| 57 | unsigned int error_mask2 = 0x00; |
Eddie Wai | 70fc872 | 2012-02-02 15:22:00 -0800 | [diff] [blame] | 58 | module_param(error_mask2, uint, 0664); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 59 | MODULE_PARM_DESC(error_mask2, "Config FW iSCSI Error Mask #2"); |
| 60 | |
| 61 | unsigned int sq_size; |
| 62 | module_param(sq_size, int, 0664); |
| 63 | MODULE_PARM_DESC(sq_size, "Configure SQ size"); |
| 64 | |
| 65 | unsigned int rq_size = BNX2I_RQ_WQES_DEFAULT; |
| 66 | module_param(rq_size, int, 0664); |
| 67 | MODULE_PARM_DESC(rq_size, "Configure RQ size"); |
| 68 | |
| 69 | u64 iscsi_error_mask = 0x00; |
| 70 | |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 71 | DEFINE_PER_CPU(struct bnx2i_percpu_s, bnx2i_percpu); |
| 72 | |
| 73 | static int bnx2i_cpu_callback(struct notifier_block *nfb, |
| 74 | unsigned long action, void *hcpu); |
| 75 | /* notification function for CPU hotplug events */ |
| 76 | static struct notifier_block bnx2i_cpu_notifier = { |
| 77 | .notifier_call = bnx2i_cpu_callback, |
| 78 | }; |
| 79 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * bnx2i_identify_device - identifies NetXtreme II device type |
| 83 | * @hba: Adapter structure pointer |
Eddie Wai | b83908c | 2012-10-15 17:31:37 -0700 | [diff] [blame] | 84 | * @cnic: Corresponding cnic device |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 85 | * |
| 86 | * This function identifies the NX2 device type and sets appropriate |
| 87 | * queue mailbox register access method, 5709 requires driver to |
| 88 | * access MBOX regs using *bin* mode |
| 89 | */ |
Eddie Wai | b83908c | 2012-10-15 17:31:37 -0700 | [diff] [blame] | 90 | void bnx2i_identify_device(struct bnx2i_hba *hba, struct cnic_dev *dev) |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 91 | { |
| 92 | hba->cnic_dev_type = 0; |
Eddie Wai | b83908c | 2012-10-15 17:31:37 -0700 | [diff] [blame] | 93 | if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) { |
| 94 | if (hba->pci_did == PCI_DEVICE_ID_NX2_5706 || |
| 95 | hba->pci_did == PCI_DEVICE_ID_NX2_5706S) { |
| 96 | set_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type); |
| 97 | } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5708 || |
| 98 | hba->pci_did == PCI_DEVICE_ID_NX2_5708S) { |
| 99 | set_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type); |
| 100 | } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5709 || |
| 101 | hba->pci_did == PCI_DEVICE_ID_NX2_5709S) { |
| 102 | set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type); |
| 103 | hba->mail_queue_access = BNX2I_MQ_BIN_MODE; |
| 104 | } |
| 105 | } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) { |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 106 | set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type); |
Eddie Wai | b83908c | 2012-10-15 17:31:37 -0700 | [diff] [blame] | 107 | } else { |
Anil Veerabhadrappa | 5d9e1fa | 2009-12-07 11:39:33 -0800 | [diff] [blame] | 108 | printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n", |
| 109 | hba->pci_did); |
Eddie Wai | b83908c | 2012-10-15 17:31:37 -0700 | [diff] [blame] | 110 | } |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | |
| 114 | /** |
| 115 | * get_adapter_list_head - returns head of adapter list |
| 116 | */ |
| 117 | struct bnx2i_hba *get_adapter_list_head(void) |
| 118 | { |
| 119 | struct bnx2i_hba *hba = NULL; |
| 120 | struct bnx2i_hba *tmp_hba; |
| 121 | |
| 122 | if (!adapter_count) |
| 123 | goto hba_not_found; |
| 124 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 125 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 126 | list_for_each_entry(tmp_hba, &adapter_list, link) { |
| 127 | if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) { |
| 128 | hba = tmp_hba; |
| 129 | break; |
| 130 | } |
| 131 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 132 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 133 | hba_not_found: |
| 134 | return hba; |
| 135 | } |
| 136 | |
| 137 | |
| 138 | /** |
| 139 | * bnx2i_find_hba_for_cnic - maps cnic device instance to bnx2i adapter instance |
| 140 | * @cnic: pointer to cnic device instance |
| 141 | * |
| 142 | */ |
| 143 | struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic) |
| 144 | { |
| 145 | struct bnx2i_hba *hba, *temp; |
| 146 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 147 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 148 | list_for_each_entry_safe(hba, temp, &adapter_list, link) { |
| 149 | if (hba->cnic == cnic) { |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 150 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 151 | return hba; |
| 152 | } |
| 153 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 154 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 155 | return NULL; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | /** |
| 160 | * bnx2i_start - cnic callback to initialize & start adapter instance |
| 161 | * @handle: transparent handle pointing to adapter structure |
| 162 | * |
| 163 | * This function maps adapter structure to pcidev structure and initiates |
| 164 | * firmware handshake to enable/initialize on chip iscsi components |
| 165 | * This bnx2i - cnic interface api callback is issued after following |
| 166 | * 2 conditions are met - |
| 167 | * a) underlying network interface is up (marked by event 'NETDEV_UP' |
| 168 | * from netdev |
| 169 | * b) bnx2i adapter instance is registered |
| 170 | */ |
| 171 | void bnx2i_start(void *handle) |
| 172 | { |
| 173 | #define BNX2I_INIT_POLL_TIME (1000 / HZ) |
| 174 | struct bnx2i_hba *hba = handle; |
| 175 | int i = HZ; |
| 176 | |
Michael Chan | 9e9402e | 2013-08-02 11:28:23 -0700 | [diff] [blame] | 177 | /* On some bnx2x devices, it is possible that iSCSI is no |
| 178 | * longer supported after firmware is downloaded. In that |
| 179 | * case, the iscsi_init_msg will return failure. |
Eddie Wai | 3601b53 | 2011-06-23 15:51:35 -0700 | [diff] [blame] | 180 | */ |
Eddie Wai | a977d2c | 2011-02-16 15:04:27 -0600 | [diff] [blame] | 181 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 182 | bnx2i_send_fw_iscsi_init_msg(hba); |
Michael Chan | 9e9402e | 2013-08-02 11:28:23 -0700 | [diff] [blame] | 183 | while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && |
| 184 | !test_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state) && i--) |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 185 | msleep(BNX2I_INIT_POLL_TIME); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /** |
Eddie Wai | 250ae98 | 2010-08-12 16:44:30 -0700 | [diff] [blame] | 190 | * bnx2i_chip_cleanup - local routine to handle chip cleanup |
| 191 | * @hba: Adapter instance to register |
| 192 | * |
| 193 | * Driver checks if adapter still has any active connections before |
| 194 | * executing the cleanup process |
| 195 | */ |
| 196 | static void bnx2i_chip_cleanup(struct bnx2i_hba *hba) |
| 197 | { |
| 198 | struct bnx2i_endpoint *bnx2i_ep; |
| 199 | struct list_head *pos, *tmp; |
| 200 | |
| 201 | if (hba->ofld_conns_active) { |
| 202 | /* Stage to force the disconnection |
| 203 | * This is the case where the daemon is either slow or |
| 204 | * not present |
| 205 | */ |
| 206 | printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active " |
| 207 | "connections\n", hba->netdev->name, |
| 208 | hba->ofld_conns_active); |
| 209 | mutex_lock(&hba->net_dev_lock); |
| 210 | list_for_each_safe(pos, tmp, &hba->ep_active_list) { |
| 211 | bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link); |
| 212 | /* Clean up the chip only */ |
| 213 | bnx2i_hw_ep_disconnect(bnx2i_ep); |
| 214 | bnx2i_ep->cm_sk = NULL; |
| 215 | } |
| 216 | mutex_unlock(&hba->net_dev_lock); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /** |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 222 | * bnx2i_stop - cnic callback to shutdown adapter instance |
| 223 | * @handle: transparent handle pointing to adapter structure |
| 224 | * |
| 225 | * driver checks if adapter is already in shutdown mode, if not start |
| 226 | * the shutdown process |
| 227 | */ |
| 228 | void bnx2i_stop(void *handle) |
| 229 | { |
| 230 | struct bnx2i_hba *hba = handle; |
Eddie Wai | 55e15c97 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 231 | int conns_active; |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 232 | int wait_delay = 1 * HZ; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 233 | |
| 234 | /* check if cleanup happened in GOING_DOWN context */ |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 235 | if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN, |
| 236 | &hba->adapter_state)) { |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 237 | iscsi_host_for_each_session(hba->shost, |
| 238 | bnx2i_drop_session); |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 239 | wait_delay = hba->hba_shutdown_tmo; |
| 240 | } |
| 241 | /* Wait for inflight offload connection tasks to complete before |
| 242 | * proceeding. Forcefully terminate all connection recovery in |
| 243 | * progress at the earliest, either in bind(), send_pdu(LOGIN), |
| 244 | * or conn_start() |
| 245 | */ |
| 246 | wait_event_interruptible_timeout(hba->eh_wait, |
| 247 | (list_empty(&hba->ep_ofld_list) && |
| 248 | list_empty(&hba->ep_destroy_list)), |
Eddie Wai | d5307a07 | 2011-05-16 11:13:19 -0700 | [diff] [blame] | 249 | 2 * HZ); |
Anil Veerabhadrappa | 490475a | 2010-04-08 15:59:15 -0700 | [diff] [blame] | 250 | /* Wait for all endpoints to be torn down, Chip will be reset once |
| 251 | * control returns to network driver. So it is required to cleanup and |
| 252 | * release all connection resources before returning from this routine. |
| 253 | */ |
Eddie Wai | 55e15c97 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 254 | while (hba->ofld_conns_active) { |
| 255 | conns_active = hba->ofld_conns_active; |
| 256 | wait_event_interruptible_timeout(hba->eh_wait, |
| 257 | (hba->ofld_conns_active != conns_active), |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 258 | wait_delay); |
Eddie Wai | 55e15c97 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 259 | if (hba->ofld_conns_active == conns_active) |
| 260 | break; |
| 261 | } |
Eddie Wai | 250ae98 | 2010-08-12 16:44:30 -0700 | [diff] [blame] | 262 | bnx2i_chip_cleanup(hba); |
Eddie Wai | 55e15c97 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 263 | |
Anil Veerabhadrappa | 490475a | 2010-04-08 15:59:15 -0700 | [diff] [blame] | 264 | /* This flag should be cleared last so that ep_disconnect() gracefully |
| 265 | * cleans up connection context |
| 266 | */ |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 267 | clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); |
Anil Veerabhadrappa | 490475a | 2010-04-08 15:59:15 -0700 | [diff] [blame] | 268 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 271 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 272 | /** |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 273 | * bnx2i_init_one - initialize an adapter instance and allocate memory resources |
| 274 | * @hba: bnx2i adapter instance |
| 275 | * @cnic: cnic device handle |
| 276 | * |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 277 | * Global resource lock is held during critical sections below. This routine is |
| 278 | * called from either cnic_register_driver() or device hot plug context and |
| 279 | * and does majority of device specific initialization |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 280 | */ |
| 281 | static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic) |
| 282 | { |
| 283 | int rc; |
| 284 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 285 | mutex_lock(&bnx2i_dev_lock); |
Eddie Wai | 3601b53 | 2011-06-23 15:51:35 -0700 | [diff] [blame] | 286 | if (!cnic->max_iscsi_conn) { |
| 287 | printk(KERN_ALERT "bnx2i: dev %s does not support " |
| 288 | "iSCSI\n", hba->netdev->name); |
| 289 | rc = -EOPNOTSUPP; |
| 290 | goto out; |
| 291 | } |
| 292 | |
Anil Veerabhadrappa | ce2d763 | 2010-03-25 10:54:42 -0700 | [diff] [blame] | 293 | hba->cnic = cnic; |
Anil Veerabhadrappa | 4e85f15 | 2009-06-23 14:04:23 -0700 | [diff] [blame] | 294 | rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba); |
| 295 | if (!rc) { |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 296 | hba->age++; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 297 | set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 298 | list_add_tail(&hba->link, &adapter_list); |
| 299 | adapter_count++; |
Anil Veerabhadrappa | 4e85f15 | 2009-06-23 14:04:23 -0700 | [diff] [blame] | 300 | } else if (rc == -EBUSY) /* duplicate registration */ |
| 301 | printk(KERN_ALERT "bnx2i, duplicate registration" |
| 302 | "hba=%p, cnic=%p\n", hba, cnic); |
| 303 | else if (rc == -EAGAIN) |
| 304 | printk(KERN_ERR "bnx2i, driver not registered\n"); |
| 305 | else if (rc == -EINVAL) |
| 306 | printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI); |
| 307 | else |
| 308 | printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 309 | |
Eddie Wai | 3601b53 | 2011-06-23 15:51:35 -0700 | [diff] [blame] | 310 | out: |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 311 | mutex_unlock(&bnx2i_dev_lock); |
Anil Veerabhadrappa | 4e85f15 | 2009-06-23 14:04:23 -0700 | [diff] [blame] | 312 | |
| 313 | return rc; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | |
| 317 | /** |
| 318 | * bnx2i_ulp_init - initialize an adapter instance |
| 319 | * @dev: cnic device handle |
| 320 | * |
| 321 | * Called from cnic_register_driver() context to initialize all enumerated |
| 322 | * cnic devices. This routine allocate adapter structure and other |
| 323 | * device specific resources. |
| 324 | */ |
| 325 | void bnx2i_ulp_init(struct cnic_dev *dev) |
| 326 | { |
| 327 | struct bnx2i_hba *hba; |
| 328 | |
| 329 | /* Allocate a HBA structure for this device */ |
| 330 | hba = bnx2i_alloc_hba(dev); |
| 331 | if (!hba) { |
| 332 | printk(KERN_ERR "bnx2i init: hba initialization failed\n"); |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | /* Get PCI related information and update hba struct members */ |
| 337 | clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
| 338 | if (bnx2i_init_one(hba, dev)) { |
| 339 | printk(KERN_ERR "bnx2i - hba %p init failed\n", hba); |
| 340 | bnx2i_free_hba(hba); |
Anil Veerabhadrappa | ce2d763 | 2010-03-25 10:54:42 -0700 | [diff] [blame] | 341 | } |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | |
| 345 | /** |
| 346 | * bnx2i_ulp_exit - shuts down adapter instance and frees all resources |
| 347 | * @dev: cnic device handle |
| 348 | * |
| 349 | */ |
| 350 | void bnx2i_ulp_exit(struct cnic_dev *dev) |
| 351 | { |
| 352 | struct bnx2i_hba *hba; |
| 353 | |
| 354 | hba = bnx2i_find_hba_for_cnic(dev); |
| 355 | if (!hba) { |
| 356 | printk(KERN_INFO "bnx2i_ulp_exit: hba not " |
| 357 | "found, dev 0x%p\n", dev); |
| 358 | return; |
| 359 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 360 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 361 | list_del_init(&hba->link); |
| 362 | adapter_count--; |
| 363 | |
| 364 | if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) { |
| 365 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI); |
| 366 | clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 367 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 368 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 369 | |
| 370 | bnx2i_free_hba(hba); |
| 371 | } |
| 372 | |
| 373 | |
| 374 | /** |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 375 | * bnx2i_get_stats - Retrieve various statistic from iSCSI offload |
| 376 | * @handle: bnx2i_hba |
| 377 | * |
| 378 | * function callback exported via bnx2i - cnic driver interface to |
| 379 | * retrieve various iSCSI offload related statistics. |
| 380 | */ |
| 381 | int bnx2i_get_stats(void *handle) |
| 382 | { |
| 383 | struct bnx2i_hba *hba = handle; |
| 384 | struct iscsi_stats_info *stats; |
| 385 | |
| 386 | if (!hba) |
| 387 | return -EINVAL; |
| 388 | |
| 389 | stats = (struct iscsi_stats_info *)hba->cnic->stats_addr; |
| 390 | |
| 391 | if (!stats) |
| 392 | return -ENOMEM; |
| 393 | |
Dan Carpenter | 12aba9e | 2012-06-30 01:49:35 +0000 | [diff] [blame] | 394 | strlcpy(stats->version, DRV_MODULE_VERSION, sizeof(stats->version)); |
Barak Witkowski | 2e499d3 | 2012-06-26 01:31:19 +0000 | [diff] [blame] | 395 | memcpy(stats->mac_add1 + 2, hba->cnic->mac_addr, ETH_ALEN); |
| 396 | |
| 397 | stats->max_frame_size = hba->netdev->mtu; |
| 398 | stats->txq_size = hba->max_sqes; |
| 399 | stats->rxq_size = hba->max_cqes; |
| 400 | |
| 401 | stats->txq_avg_depth = 0; |
| 402 | stats->rxq_avg_depth = 0; |
| 403 | |
| 404 | GET_STATS_64(hba, stats, rx_pdus); |
| 405 | GET_STATS_64(hba, stats, rx_bytes); |
| 406 | |
| 407 | GET_STATS_64(hba, stats, tx_pdus); |
| 408 | GET_STATS_64(hba, stats, tx_bytes); |
| 409 | |
| 410 | return 0; |
| 411 | } |
| 412 | |
| 413 | |
| 414 | /** |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 415 | * bnx2i_percpu_thread_create - Create a receive thread for an |
| 416 | * online CPU |
| 417 | * |
| 418 | * @cpu: cpu index for the online cpu |
| 419 | */ |
| 420 | static void bnx2i_percpu_thread_create(unsigned int cpu) |
| 421 | { |
| 422 | struct bnx2i_percpu_s *p; |
| 423 | struct task_struct *thread; |
| 424 | |
| 425 | p = &per_cpu(bnx2i_percpu, cpu); |
| 426 | |
Eric Dumazet | 93713f3 | 2012-02-02 14:03:22 +0100 | [diff] [blame] | 427 | thread = kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p, |
| 428 | cpu_to_node(cpu), |
| 429 | "bnx2i_thread/%d", cpu); |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 430 | /* bind thread to the cpu */ |
| 431 | if (likely(!IS_ERR(thread))) { |
| 432 | kthread_bind(thread, cpu); |
| 433 | p->iothread = thread; |
| 434 | wake_up_process(thread); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | |
| 439 | static void bnx2i_percpu_thread_destroy(unsigned int cpu) |
| 440 | { |
| 441 | struct bnx2i_percpu_s *p; |
| 442 | struct task_struct *thread; |
| 443 | struct bnx2i_work *work, *tmp; |
| 444 | |
| 445 | /* Prevent any new work from being queued for this CPU */ |
| 446 | p = &per_cpu(bnx2i_percpu, cpu); |
| 447 | spin_lock_bh(&p->p_work_lock); |
| 448 | thread = p->iothread; |
| 449 | p->iothread = NULL; |
| 450 | |
| 451 | /* Free all work in the list */ |
| 452 | list_for_each_entry_safe(work, tmp, &p->work_list, list) { |
| 453 | list_del_init(&work->list); |
| 454 | bnx2i_process_scsi_cmd_resp(work->session, |
| 455 | work->bnx2i_conn, &work->cqe); |
| 456 | kfree(work); |
| 457 | } |
| 458 | |
| 459 | spin_unlock_bh(&p->p_work_lock); |
| 460 | if (thread) |
| 461 | kthread_stop(thread); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | /** |
| 466 | * bnx2i_cpu_callback - Handler for CPU hotplug events |
| 467 | * |
| 468 | * @nfb: The callback data block |
| 469 | * @action: The event triggering the callback |
| 470 | * @hcpu: The index of the CPU that the event is for |
| 471 | * |
| 472 | * This creates or destroys per-CPU data for iSCSI |
| 473 | * |
| 474 | * Returns NOTIFY_OK always. |
| 475 | */ |
| 476 | static int bnx2i_cpu_callback(struct notifier_block *nfb, |
| 477 | unsigned long action, void *hcpu) |
| 478 | { |
| 479 | unsigned cpu = (unsigned long)hcpu; |
| 480 | |
| 481 | switch (action) { |
| 482 | case CPU_ONLINE: |
| 483 | case CPU_ONLINE_FROZEN: |
| 484 | printk(KERN_INFO "bnx2i: CPU %x online: Create Rx thread\n", |
| 485 | cpu); |
| 486 | bnx2i_percpu_thread_create(cpu); |
| 487 | break; |
| 488 | case CPU_DEAD: |
| 489 | case CPU_DEAD_FROZEN: |
| 490 | printk(KERN_INFO "CPU %x offline: Remove Rx thread\n", cpu); |
| 491 | bnx2i_percpu_thread_destroy(cpu); |
| 492 | break; |
| 493 | default: |
| 494 | break; |
| 495 | } |
| 496 | return NOTIFY_OK; |
| 497 | } |
| 498 | |
| 499 | |
| 500 | /** |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 501 | * bnx2i_mod_init - module init entry point |
| 502 | * |
| 503 | * initialize any driver wide global data structures such as endpoint pool, |
| 504 | * tcp port manager/queue, sysfs. finally driver will register itself |
| 505 | * with the cnic module |
| 506 | */ |
| 507 | static int __init bnx2i_mod_init(void) |
| 508 | { |
| 509 | int err; |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 510 | unsigned cpu = 0; |
| 511 | struct bnx2i_percpu_s *p; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 512 | |
| 513 | printk(KERN_INFO "%s", version); |
| 514 | |
Anil Veerabhadrappa | f8c9abe | 2009-12-07 11:39:54 -0800 | [diff] [blame] | 515 | if (sq_size && !is_power_of_2(sq_size)) |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 516 | sq_size = roundup_pow_of_two(sq_size); |
| 517 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 518 | mutex_init(&bnx2i_dev_lock); |
| 519 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 520 | bnx2i_scsi_xport_template = |
| 521 | iscsi_register_transport(&bnx2i_iscsi_transport); |
| 522 | if (!bnx2i_scsi_xport_template) { |
| 523 | printk(KERN_ERR "Could not register bnx2i transport.\n"); |
| 524 | err = -ENOMEM; |
| 525 | goto out; |
| 526 | } |
| 527 | |
| 528 | err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb); |
| 529 | if (err) { |
| 530 | printk(KERN_ERR "Could not register bnx2i cnic driver.\n"); |
| 531 | goto unreg_xport; |
| 532 | } |
| 533 | |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 534 | /* Create percpu kernel threads to handle iSCSI I/O completions */ |
| 535 | for_each_possible_cpu(cpu) { |
| 536 | p = &per_cpu(bnx2i_percpu, cpu); |
| 537 | INIT_LIST_HEAD(&p->work_list); |
| 538 | spin_lock_init(&p->p_work_lock); |
| 539 | p->iothread = NULL; |
| 540 | } |
| 541 | |
Srivatsa S. Bhat | bc0003c | 2014-03-11 02:09:39 +0530 | [diff] [blame] | 542 | cpu_notifier_register_begin(); |
| 543 | |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 544 | for_each_online_cpu(cpu) |
| 545 | bnx2i_percpu_thread_create(cpu); |
| 546 | |
| 547 | /* Initialize per CPU interrupt thread */ |
Srivatsa S. Bhat | bc0003c | 2014-03-11 02:09:39 +0530 | [diff] [blame] | 548 | __register_hotcpu_notifier(&bnx2i_cpu_notifier); |
| 549 | |
| 550 | cpu_notifier_register_done(); |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 551 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 552 | return 0; |
| 553 | |
| 554 | unreg_xport: |
| 555 | iscsi_unregister_transport(&bnx2i_iscsi_transport); |
| 556 | out: |
| 557 | return err; |
| 558 | } |
| 559 | |
| 560 | |
| 561 | /** |
| 562 | * bnx2i_mod_exit - module cleanup/exit entry point |
| 563 | * |
| 564 | * Global resource lock and host adapter lock is held during critical sections |
| 565 | * in this function. Driver will browse through the adapter list, cleans-up |
| 566 | * each instance, unregisters iscsi transport name and finally driver will |
| 567 | * unregister itself with the cnic module |
| 568 | */ |
| 569 | static void __exit bnx2i_mod_exit(void) |
| 570 | { |
| 571 | struct bnx2i_hba *hba; |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 572 | unsigned cpu = 0; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 573 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 574 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 575 | while (!list_empty(&adapter_list)) { |
| 576 | hba = list_entry(adapter_list.next, struct bnx2i_hba, link); |
| 577 | list_del(&hba->link); |
| 578 | adapter_count--; |
| 579 | |
| 580 | if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) { |
Eddie Wai | 250ae98 | 2010-08-12 16:44:30 -0700 | [diff] [blame] | 581 | bnx2i_chip_cleanup(hba); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 582 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI); |
| 583 | clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 586 | bnx2i_free_hba(hba); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 587 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 588 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 589 | |
Srivatsa S. Bhat | bc0003c | 2014-03-11 02:09:39 +0530 | [diff] [blame] | 590 | cpu_notifier_register_begin(); |
Eddie Wai | b5cf6b6 | 2011-06-23 15:51:34 -0700 | [diff] [blame] | 591 | |
| 592 | for_each_online_cpu(cpu) |
| 593 | bnx2i_percpu_thread_destroy(cpu); |
| 594 | |
Srivatsa S. Bhat | bc0003c | 2014-03-11 02:09:39 +0530 | [diff] [blame] | 595 | __unregister_hotcpu_notifier(&bnx2i_cpu_notifier); |
| 596 | |
| 597 | cpu_notifier_register_done(); |
| 598 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 599 | iscsi_unregister_transport(&bnx2i_iscsi_transport); |
| 600 | cnic_unregister_driver(CNIC_ULP_ISCSI); |
| 601 | } |
| 602 | |
| 603 | module_init(bnx2i_mod_init); |
| 604 | module_exit(bnx2i_mod_exit); |