Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 1 | /* bnx2i.c: Broadcom NetXtreme II iSCSI driver. |
| 2 | * |
Eddie Wai | 11cec1e | 2010-11-23 15:29:31 -0800 | [diff] [blame] | 3 | * Copyright (c) 2006 - 2010 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 |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation. |
| 10 | * |
| 11 | * Written by: Anil Veerabhadrappa (anilgv@broadcom.com) |
Eddie Wai | 11cec1e | 2010-11-23 15:29:31 -0800 | [diff] [blame] | 12 | * Maintained by: Eddie Wai (eddie.wai@broadcom.com) |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include "bnx2i.h" |
| 16 | |
| 17 | static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list); |
| 18 | static u32 adapter_count; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 19 | |
| 20 | #define DRV_MODULE_NAME "bnx2i" |
Eddie Wai | fc33638 | 2011-02-16 15:04:31 -0600 | [diff] [blame] | 21 | #define DRV_MODULE_VERSION "2.6.2.3" |
| 22 | #define DRV_MODULE_RELDATE "Dec 31, 2010" |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 23 | |
| 24 | static char version[] __devinitdata = |
| 25 | "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \ |
| 26 | " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; |
| 27 | |
| 28 | |
Eddie Wai | fc91961 | 2010-08-12 16:44:31 -0700 | [diff] [blame] | 29 | MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and " |
| 30 | "Eddie Wai <eddie.wai@broadcom.com>"); |
| 31 | |
Eddie Wai | 8a4a0f3 | 2011-02-16 15:04:28 -0600 | [diff] [blame] | 32 | MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/57710/57711/57712" |
Anil Veerabhadrappa | 457549d | 2010-03-25 10:54:44 -0700 | [diff] [blame] | 33 | " iSCSI Driver"); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 34 | MODULE_LICENSE("GPL"); |
| 35 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 36 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 37 | static DEFINE_MUTEX(bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 38 | |
Anil Veerabhadrappa | 8776193 | 2009-12-07 11:40:18 -0800 | [diff] [blame] | 39 | unsigned int event_coal_min = 24; |
| 40 | module_param(event_coal_min, int, 0664); |
| 41 | MODULE_PARM_DESC(event_coal_min, "Event Coalescing Minimum Commands"); |
| 42 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 43 | unsigned int event_coal_div = 1; |
| 44 | module_param(event_coal_div, int, 0664); |
| 45 | MODULE_PARM_DESC(event_coal_div, "Event Coalescing Divide Factor"); |
| 46 | |
| 47 | unsigned int en_tcp_dack = 1; |
| 48 | module_param(en_tcp_dack, int, 0664); |
| 49 | MODULE_PARM_DESC(en_tcp_dack, "Enable TCP Delayed ACK"); |
| 50 | |
| 51 | unsigned int error_mask1 = 0x00; |
| 52 | module_param(error_mask1, int, 0664); |
| 53 | MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1"); |
| 54 | |
| 55 | unsigned int error_mask2 = 0x00; |
| 56 | module_param(error_mask2, int, 0664); |
| 57 | MODULE_PARM_DESC(error_mask2, "Config FW iSCSI Error Mask #2"); |
| 58 | |
| 59 | unsigned int sq_size; |
| 60 | module_param(sq_size, int, 0664); |
| 61 | MODULE_PARM_DESC(sq_size, "Configure SQ size"); |
| 62 | |
| 63 | unsigned int rq_size = BNX2I_RQ_WQES_DEFAULT; |
| 64 | module_param(rq_size, int, 0664); |
| 65 | MODULE_PARM_DESC(rq_size, "Configure RQ size"); |
| 66 | |
| 67 | u64 iscsi_error_mask = 0x00; |
| 68 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * bnx2i_identify_device - identifies NetXtreme II device type |
| 72 | * @hba: Adapter structure pointer |
| 73 | * |
| 74 | * This function identifies the NX2 device type and sets appropriate |
| 75 | * queue mailbox register access method, 5709 requires driver to |
| 76 | * access MBOX regs using *bin* mode |
| 77 | */ |
| 78 | void bnx2i_identify_device(struct bnx2i_hba *hba) |
| 79 | { |
| 80 | hba->cnic_dev_type = 0; |
| 81 | if ((hba->pci_did == PCI_DEVICE_ID_NX2_5706) || |
| 82 | (hba->pci_did == PCI_DEVICE_ID_NX2_5706S)) |
| 83 | set_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type); |
| 84 | else if ((hba->pci_did == PCI_DEVICE_ID_NX2_5708) || |
| 85 | (hba->pci_did == PCI_DEVICE_ID_NX2_5708S)) |
| 86 | set_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type); |
| 87 | else if ((hba->pci_did == PCI_DEVICE_ID_NX2_5709) || |
| 88 | (hba->pci_did == PCI_DEVICE_ID_NX2_5709S)) { |
| 89 | set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type); |
| 90 | hba->mail_queue_access = BNX2I_MQ_BIN_MODE; |
Eddie Wai | 8a4a0f3 | 2011-02-16 15:04:28 -0600 | [diff] [blame] | 91 | } else if (hba->pci_did == PCI_DEVICE_ID_NX2_57710 || |
| 92 | hba->pci_did == PCI_DEVICE_ID_NX2_57711 || |
| 93 | hba->pci_did == PCI_DEVICE_ID_NX2_57711E || |
| 94 | hba->pci_did == PCI_DEVICE_ID_NX2_57712 || |
| 95 | hba->pci_did == PCI_DEVICE_ID_NX2_57712E) |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 96 | set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type); |
Anil Veerabhadrappa | 5d9e1fa | 2009-12-07 11:39:33 -0800 | [diff] [blame] | 97 | else |
| 98 | printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n", |
| 99 | hba->pci_did); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * get_adapter_list_head - returns head of adapter list |
| 105 | */ |
| 106 | struct bnx2i_hba *get_adapter_list_head(void) |
| 107 | { |
| 108 | struct bnx2i_hba *hba = NULL; |
| 109 | struct bnx2i_hba *tmp_hba; |
| 110 | |
| 111 | if (!adapter_count) |
| 112 | goto hba_not_found; |
| 113 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 114 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 115 | list_for_each_entry(tmp_hba, &adapter_list, link) { |
| 116 | if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) { |
| 117 | hba = tmp_hba; |
| 118 | break; |
| 119 | } |
| 120 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 121 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 122 | hba_not_found: |
| 123 | return hba; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | /** |
| 128 | * bnx2i_find_hba_for_cnic - maps cnic device instance to bnx2i adapter instance |
| 129 | * @cnic: pointer to cnic device instance |
| 130 | * |
| 131 | */ |
| 132 | struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic) |
| 133 | { |
| 134 | struct bnx2i_hba *hba, *temp; |
| 135 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 136 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 137 | list_for_each_entry_safe(hba, temp, &adapter_list, link) { |
| 138 | if (hba->cnic == cnic) { |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 139 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 140 | return hba; |
| 141 | } |
| 142 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 143 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 144 | return NULL; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /** |
| 149 | * bnx2i_start - cnic callback to initialize & start adapter instance |
| 150 | * @handle: transparent handle pointing to adapter structure |
| 151 | * |
| 152 | * This function maps adapter structure to pcidev structure and initiates |
| 153 | * firmware handshake to enable/initialize on chip iscsi components |
| 154 | * This bnx2i - cnic interface api callback is issued after following |
| 155 | * 2 conditions are met - |
| 156 | * a) underlying network interface is up (marked by event 'NETDEV_UP' |
| 157 | * from netdev |
| 158 | * b) bnx2i adapter instance is registered |
| 159 | */ |
| 160 | void bnx2i_start(void *handle) |
| 161 | { |
| 162 | #define BNX2I_INIT_POLL_TIME (1000 / HZ) |
| 163 | struct bnx2i_hba *hba = handle; |
| 164 | int i = HZ; |
| 165 | |
Eddie Wai | a977d2c | 2011-02-16 15:04:27 -0600 | [diff] [blame] | 166 | if (!hba->cnic->max_iscsi_conn) { |
| 167 | printk(KERN_ALERT "bnx2i: dev %s does not support " |
| 168 | "iSCSI\n", hba->netdev->name); |
| 169 | |
| 170 | if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) { |
| 171 | mutex_lock(&bnx2i_dev_lock); |
| 172 | list_del_init(&hba->link); |
| 173 | adapter_count--; |
| 174 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI); |
| 175 | clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
| 176 | mutex_unlock(&bnx2i_dev_lock); |
| 177 | bnx2i_free_hba(hba); |
| 178 | } |
| 179 | return; |
| 180 | } |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 181 | bnx2i_send_fw_iscsi_init_msg(hba); |
| 182 | while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--) |
| 183 | msleep(BNX2I_INIT_POLL_TIME); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | /** |
Eddie Wai | 250ae98 | 2010-08-12 16:44:30 -0700 | [diff] [blame] | 188 | * bnx2i_chip_cleanup - local routine to handle chip cleanup |
| 189 | * @hba: Adapter instance to register |
| 190 | * |
| 191 | * Driver checks if adapter still has any active connections before |
| 192 | * executing the cleanup process |
| 193 | */ |
| 194 | static void bnx2i_chip_cleanup(struct bnx2i_hba *hba) |
| 195 | { |
| 196 | struct bnx2i_endpoint *bnx2i_ep; |
| 197 | struct list_head *pos, *tmp; |
| 198 | |
| 199 | if (hba->ofld_conns_active) { |
| 200 | /* Stage to force the disconnection |
| 201 | * This is the case where the daemon is either slow or |
| 202 | * not present |
| 203 | */ |
| 204 | printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active " |
| 205 | "connections\n", hba->netdev->name, |
| 206 | hba->ofld_conns_active); |
| 207 | mutex_lock(&hba->net_dev_lock); |
| 208 | list_for_each_safe(pos, tmp, &hba->ep_active_list) { |
| 209 | bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link); |
| 210 | /* Clean up the chip only */ |
| 211 | bnx2i_hw_ep_disconnect(bnx2i_ep); |
| 212 | bnx2i_ep->cm_sk = NULL; |
| 213 | } |
| 214 | mutex_unlock(&hba->net_dev_lock); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /** |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 220 | * bnx2i_stop - cnic callback to shutdown adapter instance |
| 221 | * @handle: transparent handle pointing to adapter structure |
| 222 | * |
| 223 | * driver checks if adapter is already in shutdown mode, if not start |
| 224 | * the shutdown process |
| 225 | */ |
| 226 | void bnx2i_stop(void *handle) |
| 227 | { |
| 228 | struct bnx2i_hba *hba = handle; |
Eddie Wai | 55e15c9 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 229 | int conns_active; |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 230 | int wait_delay = 1 * HZ; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 231 | |
| 232 | /* check if cleanup happened in GOING_DOWN context */ |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 233 | if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN, |
| 234 | &hba->adapter_state)) { |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 235 | iscsi_host_for_each_session(hba->shost, |
| 236 | bnx2i_drop_session); |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 237 | wait_delay = hba->hba_shutdown_tmo; |
| 238 | } |
| 239 | /* Wait for inflight offload connection tasks to complete before |
| 240 | * proceeding. Forcefully terminate all connection recovery in |
| 241 | * progress at the earliest, either in bind(), send_pdu(LOGIN), |
| 242 | * or conn_start() |
| 243 | */ |
| 244 | wait_event_interruptible_timeout(hba->eh_wait, |
| 245 | (list_empty(&hba->ep_ofld_list) && |
| 246 | list_empty(&hba->ep_destroy_list)), |
Eddie Wai | d5307a07 | 2011-05-16 11:13:19 -0700 | [diff] [blame] | 247 | 2 * HZ); |
Anil Veerabhadrappa | 490475a | 2010-04-08 15:59:15 -0700 | [diff] [blame] | 248 | /* Wait for all endpoints to be torn down, Chip will be reset once |
| 249 | * control returns to network driver. So it is required to cleanup and |
| 250 | * release all connection resources before returning from this routine. |
| 251 | */ |
Eddie Wai | 55e15c9 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 252 | while (hba->ofld_conns_active) { |
| 253 | conns_active = hba->ofld_conns_active; |
| 254 | wait_event_interruptible_timeout(hba->eh_wait, |
| 255 | (hba->ofld_conns_active != conns_active), |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 256 | wait_delay); |
Eddie Wai | 55e15c9 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 257 | if (hba->ofld_conns_active == conns_active) |
| 258 | break; |
| 259 | } |
Eddie Wai | 250ae98 | 2010-08-12 16:44:30 -0700 | [diff] [blame] | 260 | bnx2i_chip_cleanup(hba); |
Eddie Wai | 55e15c9 | 2010-07-01 15:34:52 -0700 | [diff] [blame] | 261 | |
Anil Veerabhadrappa | 490475a | 2010-04-08 15:59:15 -0700 | [diff] [blame] | 262 | /* This flag should be cleared last so that ep_disconnect() gracefully |
| 263 | * cleans up connection context |
| 264 | */ |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 265 | clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state); |
Anil Veerabhadrappa | 490475a | 2010-04-08 15:59:15 -0700 | [diff] [blame] | 266 | clear_bit(ADAPTER_STATE_UP, &hba->adapter_state); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Eddie Wai | 842158d | 2010-11-23 15:29:28 -0800 | [diff] [blame] | 269 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 270 | /** |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 271 | * bnx2i_init_one - initialize an adapter instance and allocate memory resources |
| 272 | * @hba: bnx2i adapter instance |
| 273 | * @cnic: cnic device handle |
| 274 | * |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 275 | * Global resource lock is held during critical sections below. This routine is |
| 276 | * called from either cnic_register_driver() or device hot plug context and |
| 277 | * and does majority of device specific initialization |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 278 | */ |
| 279 | static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic) |
| 280 | { |
| 281 | int rc; |
| 282 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 283 | mutex_lock(&bnx2i_dev_lock); |
Anil Veerabhadrappa | ce2d763 | 2010-03-25 10:54:42 -0700 | [diff] [blame] | 284 | hba->cnic = cnic; |
Anil Veerabhadrappa | 4e85f15 | 2009-06-23 14:04:23 -0700 | [diff] [blame] | 285 | rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba); |
| 286 | if (!rc) { |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 287 | hba->age++; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 288 | set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 289 | list_add_tail(&hba->link, &adapter_list); |
| 290 | adapter_count++; |
Anil Veerabhadrappa | 4e85f15 | 2009-06-23 14:04:23 -0700 | [diff] [blame] | 291 | } else if (rc == -EBUSY) /* duplicate registration */ |
| 292 | printk(KERN_ALERT "bnx2i, duplicate registration" |
| 293 | "hba=%p, cnic=%p\n", hba, cnic); |
| 294 | else if (rc == -EAGAIN) |
| 295 | printk(KERN_ERR "bnx2i, driver not registered\n"); |
| 296 | else if (rc == -EINVAL) |
| 297 | printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI); |
| 298 | else |
| 299 | printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 300 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 301 | mutex_unlock(&bnx2i_dev_lock); |
Anil Veerabhadrappa | 4e85f15 | 2009-06-23 14:04:23 -0700 | [diff] [blame] | 302 | |
| 303 | return rc; |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | |
| 307 | /** |
| 308 | * bnx2i_ulp_init - initialize an adapter instance |
| 309 | * @dev: cnic device handle |
| 310 | * |
| 311 | * Called from cnic_register_driver() context to initialize all enumerated |
| 312 | * cnic devices. This routine allocate adapter structure and other |
| 313 | * device specific resources. |
| 314 | */ |
| 315 | void bnx2i_ulp_init(struct cnic_dev *dev) |
| 316 | { |
| 317 | struct bnx2i_hba *hba; |
| 318 | |
| 319 | /* Allocate a HBA structure for this device */ |
| 320 | hba = bnx2i_alloc_hba(dev); |
| 321 | if (!hba) { |
| 322 | printk(KERN_ERR "bnx2i init: hba initialization failed\n"); |
| 323 | return; |
| 324 | } |
| 325 | |
| 326 | /* Get PCI related information and update hba struct members */ |
| 327 | clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
| 328 | if (bnx2i_init_one(hba, dev)) { |
| 329 | printk(KERN_ERR "bnx2i - hba %p init failed\n", hba); |
| 330 | bnx2i_free_hba(hba); |
Anil Veerabhadrappa | ce2d763 | 2010-03-25 10:54:42 -0700 | [diff] [blame] | 331 | } |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | |
| 335 | /** |
| 336 | * bnx2i_ulp_exit - shuts down adapter instance and frees all resources |
| 337 | * @dev: cnic device handle |
| 338 | * |
| 339 | */ |
| 340 | void bnx2i_ulp_exit(struct cnic_dev *dev) |
| 341 | { |
| 342 | struct bnx2i_hba *hba; |
| 343 | |
| 344 | hba = bnx2i_find_hba_for_cnic(dev); |
| 345 | if (!hba) { |
| 346 | printk(KERN_INFO "bnx2i_ulp_exit: hba not " |
| 347 | "found, dev 0x%p\n", dev); |
| 348 | return; |
| 349 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 350 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 351 | list_del_init(&hba->link); |
| 352 | adapter_count--; |
| 353 | |
| 354 | if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) { |
| 355 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI); |
| 356 | clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 357 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 358 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 359 | |
| 360 | bnx2i_free_hba(hba); |
| 361 | } |
| 362 | |
| 363 | |
| 364 | /** |
| 365 | * bnx2i_mod_init - module init entry point |
| 366 | * |
| 367 | * initialize any driver wide global data structures such as endpoint pool, |
| 368 | * tcp port manager/queue, sysfs. finally driver will register itself |
| 369 | * with the cnic module |
| 370 | */ |
| 371 | static int __init bnx2i_mod_init(void) |
| 372 | { |
| 373 | int err; |
| 374 | |
| 375 | printk(KERN_INFO "%s", version); |
| 376 | |
Anil Veerabhadrappa | f8c9abe | 2009-12-07 11:39:54 -0800 | [diff] [blame] | 377 | if (sq_size && !is_power_of_2(sq_size)) |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 378 | sq_size = roundup_pow_of_two(sq_size); |
| 379 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 380 | mutex_init(&bnx2i_dev_lock); |
| 381 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 382 | bnx2i_scsi_xport_template = |
| 383 | iscsi_register_transport(&bnx2i_iscsi_transport); |
| 384 | if (!bnx2i_scsi_xport_template) { |
| 385 | printk(KERN_ERR "Could not register bnx2i transport.\n"); |
| 386 | err = -ENOMEM; |
| 387 | goto out; |
| 388 | } |
| 389 | |
| 390 | err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb); |
| 391 | if (err) { |
| 392 | printk(KERN_ERR "Could not register bnx2i cnic driver.\n"); |
| 393 | goto unreg_xport; |
| 394 | } |
| 395 | |
| 396 | return 0; |
| 397 | |
| 398 | unreg_xport: |
| 399 | iscsi_unregister_transport(&bnx2i_iscsi_transport); |
| 400 | out: |
| 401 | return err; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | /** |
| 406 | * bnx2i_mod_exit - module cleanup/exit entry point |
| 407 | * |
| 408 | * Global resource lock and host adapter lock is held during critical sections |
| 409 | * in this function. Driver will browse through the adapter list, cleans-up |
| 410 | * each instance, unregisters iscsi transport name and finally driver will |
| 411 | * unregister itself with the cnic module |
| 412 | */ |
| 413 | static void __exit bnx2i_mod_exit(void) |
| 414 | { |
| 415 | struct bnx2i_hba *hba; |
| 416 | |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 417 | mutex_lock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 418 | while (!list_empty(&adapter_list)) { |
| 419 | hba = list_entry(adapter_list.next, struct bnx2i_hba, link); |
| 420 | list_del(&hba->link); |
| 421 | adapter_count--; |
| 422 | |
| 423 | if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) { |
Eddie Wai | 250ae98 | 2010-08-12 16:44:30 -0700 | [diff] [blame] | 424 | bnx2i_chip_cleanup(hba); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 425 | hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI); |
| 426 | clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 429 | bnx2i_free_hba(hba); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 430 | } |
Anil Veerabhadrappa | 3be924f | 2009-06-23 14:07:40 -0700 | [diff] [blame] | 431 | mutex_unlock(&bnx2i_dev_lock); |
Michael Chan | cf4e636 | 2009-06-08 18:14:44 -0700 | [diff] [blame] | 432 | |
| 433 | iscsi_unregister_transport(&bnx2i_iscsi_transport); |
| 434 | cnic_unregister_driver(CNIC_ULP_ISCSI); |
| 435 | } |
| 436 | |
| 437 | module_init(bnx2i_mod_init); |
| 438 | module_exit(bnx2i_mod_exit); |