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