blob: 4f252a9eb5ad6f68d819fa46410dc5087622ab93 [file] [log] [blame]
Michael Chancf4e6362009-06-08 18:14:44 -07001/* bnx2i.c: Broadcom NetXtreme II iSCSI driver.
2 *
Eddie Waiea9582d2011-06-23 15:51:37 -07003 * Copyright (c) 2006 - 2011 Broadcom Corporation
Michael Chancf4e6362009-06-08 18:14:44 -07004 * 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 Wai11cec1e2010-11-23 15:29:31 -080012 * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
Michael Chancf4e6362009-06-08 18:14:44 -070013 */
14
15#include "bnx2i.h"
16
17static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list);
18static u32 adapter_count;
Michael Chancf4e6362009-06-08 18:14:44 -070019
20#define DRV_MODULE_NAME "bnx2i"
Eddie Waiea9582d2011-06-23 15:51:37 -070021#define DRV_MODULE_VERSION "2.7.0.3"
22#define DRV_MODULE_RELDATE "Jun 15, 2011"
Michael Chancf4e6362009-06-08 18:14:44 -070023
24static char version[] __devinitdata =
25 "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
26 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
27
28
Eddie Waifc919612010-08-12 16:44:31 -070029MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and "
30 "Eddie Wai <eddie.wai@broadcom.com>");
31
Eddie Wai8a4a0f32011-02-16 15:04:28 -060032MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/57710/57711/57712"
Anil Veerabhadrappa457549d2010-03-25 10:54:44 -070033 " iSCSI Driver");
Michael Chancf4e6362009-06-08 18:14:44 -070034MODULE_LICENSE("GPL");
35MODULE_VERSION(DRV_MODULE_VERSION);
36
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -070037static DEFINE_MUTEX(bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -070038
Anil Veerabhadrappa87761932009-12-07 11:40:18 -080039unsigned int event_coal_min = 24;
40module_param(event_coal_min, int, 0664);
41MODULE_PARM_DESC(event_coal_min, "Event Coalescing Minimum Commands");
42
Eddie Waib5cf6b62011-06-23 15:51:34 -070043unsigned int event_coal_div = 2;
Michael Chancf4e6362009-06-08 18:14:44 -070044module_param(event_coal_div, int, 0664);
45MODULE_PARM_DESC(event_coal_div, "Event Coalescing Divide Factor");
46
47unsigned int en_tcp_dack = 1;
48module_param(en_tcp_dack, int, 0664);
49MODULE_PARM_DESC(en_tcp_dack, "Enable TCP Delayed ACK");
50
51unsigned int error_mask1 = 0x00;
52module_param(error_mask1, int, 0664);
53MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1");
54
55unsigned int error_mask2 = 0x00;
56module_param(error_mask2, int, 0664);
57MODULE_PARM_DESC(error_mask2, "Config FW iSCSI Error Mask #2");
58
59unsigned int sq_size;
60module_param(sq_size, int, 0664);
61MODULE_PARM_DESC(sq_size, "Configure SQ size");
62
63unsigned int rq_size = BNX2I_RQ_WQES_DEFAULT;
64module_param(rq_size, int, 0664);
65MODULE_PARM_DESC(rq_size, "Configure RQ size");
66
67u64 iscsi_error_mask = 0x00;
68
Eddie Waib5cf6b62011-06-23 15:51:34 -070069DEFINE_PER_CPU(struct bnx2i_percpu_s, bnx2i_percpu);
70
71static int bnx2i_cpu_callback(struct notifier_block *nfb,
72 unsigned long action, void *hcpu);
73/* notification function for CPU hotplug events */
74static struct notifier_block bnx2i_cpu_notifier = {
75 .notifier_call = bnx2i_cpu_callback,
76};
77
Michael Chancf4e6362009-06-08 18:14:44 -070078
79/**
80 * bnx2i_identify_device - identifies NetXtreme II device type
81 * @hba: Adapter structure pointer
82 *
83 * This function identifies the NX2 device type and sets appropriate
84 * queue mailbox register access method, 5709 requires driver to
85 * access MBOX regs using *bin* mode
86 */
87void bnx2i_identify_device(struct bnx2i_hba *hba)
88{
89 hba->cnic_dev_type = 0;
90 if ((hba->pci_did == PCI_DEVICE_ID_NX2_5706) ||
91 (hba->pci_did == PCI_DEVICE_ID_NX2_5706S))
92 set_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type);
93 else if ((hba->pci_did == PCI_DEVICE_ID_NX2_5708) ||
94 (hba->pci_did == PCI_DEVICE_ID_NX2_5708S))
95 set_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type);
96 else if ((hba->pci_did == PCI_DEVICE_ID_NX2_5709) ||
97 (hba->pci_did == PCI_DEVICE_ID_NX2_5709S)) {
98 set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type);
99 hba->mail_queue_access = BNX2I_MQ_BIN_MODE;
Eddie Wai8a4a0f32011-02-16 15:04:28 -0600100 } else if (hba->pci_did == PCI_DEVICE_ID_NX2_57710 ||
101 hba->pci_did == PCI_DEVICE_ID_NX2_57711 ||
102 hba->pci_did == PCI_DEVICE_ID_NX2_57711E ||
103 hba->pci_did == PCI_DEVICE_ID_NX2_57712 ||
104 hba->pci_did == PCI_DEVICE_ID_NX2_57712E)
Michael Chancf4e6362009-06-08 18:14:44 -0700105 set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
Anil Veerabhadrappa5d9e1fa2009-12-07 11:39:33 -0800106 else
107 printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
108 hba->pci_did);
Michael Chancf4e6362009-06-08 18:14:44 -0700109}
110
111
112/**
113 * get_adapter_list_head - returns head of adapter list
114 */
115struct bnx2i_hba *get_adapter_list_head(void)
116{
117 struct bnx2i_hba *hba = NULL;
118 struct bnx2i_hba *tmp_hba;
119
120 if (!adapter_count)
121 goto hba_not_found;
122
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700123 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700124 list_for_each_entry(tmp_hba, &adapter_list, link) {
125 if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) {
126 hba = tmp_hba;
127 break;
128 }
129 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700130 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700131hba_not_found:
132 return hba;
133}
134
135
136/**
137 * bnx2i_find_hba_for_cnic - maps cnic device instance to bnx2i adapter instance
138 * @cnic: pointer to cnic device instance
139 *
140 */
141struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic)
142{
143 struct bnx2i_hba *hba, *temp;
144
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700145 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700146 list_for_each_entry_safe(hba, temp, &adapter_list, link) {
147 if (hba->cnic == cnic) {
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700148 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700149 return hba;
150 }
151 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700152 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700153 return NULL;
154}
155
156
157/**
158 * bnx2i_start - cnic callback to initialize & start adapter instance
159 * @handle: transparent handle pointing to adapter structure
160 *
161 * This function maps adapter structure to pcidev structure and initiates
162 * firmware handshake to enable/initialize on chip iscsi components
163 * This bnx2i - cnic interface api callback is issued after following
164 * 2 conditions are met -
165 * a) underlying network interface is up (marked by event 'NETDEV_UP'
166 * from netdev
167 * b) bnx2i adapter instance is registered
168 */
169void bnx2i_start(void *handle)
170{
171#define BNX2I_INIT_POLL_TIME (1000 / HZ)
172 struct bnx2i_hba *hba = handle;
173 int i = HZ;
174
Eddie Wai3601b532011-06-23 15:51:35 -0700175 /*
176 * We should never register devices that don't support iSCSI
177 * (see bnx2i_init_one), so something is wrong if we try to
178 * start a iSCSI adapter on hardware with 0 supported iSCSI
179 * connections
180 */
181 BUG_ON(!hba->cnic->max_iscsi_conn);
Eddie Waia977d2c2011-02-16 15:04:27 -0600182
Michael Chancf4e6362009-06-08 18:14:44 -0700183 bnx2i_send_fw_iscsi_init_msg(hba);
184 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
185 msleep(BNX2I_INIT_POLL_TIME);
186}
187
188
189/**
Eddie Wai250ae982010-08-12 16:44:30 -0700190 * 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 */
196static 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 Chancf4e6362009-06-08 18:14:44 -0700222 * 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 */
228void bnx2i_stop(void *handle)
229{
230 struct bnx2i_hba *hba = handle;
Eddie Wai55e15c92010-07-01 15:34:52 -0700231 int conns_active;
Eddie Wai842158d2010-11-23 15:29:28 -0800232 int wait_delay = 1 * HZ;
Michael Chancf4e6362009-06-08 18:14:44 -0700233
234 /* check if cleanup happened in GOING_DOWN context */
Eddie Wai842158d2010-11-23 15:29:28 -0800235 if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN,
236 &hba->adapter_state)) {
Michael Chancf4e6362009-06-08 18:14:44 -0700237 iscsi_host_for_each_session(hba->shost,
238 bnx2i_drop_session);
Eddie Wai842158d2010-11-23 15:29:28 -0800239 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 Waid5307a072011-05-16 11:13:19 -0700249 2 * HZ);
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700250 /* 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 Wai55e15c92010-07-01 15:34:52 -0700254 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 Wai842158d2010-11-23 15:29:28 -0800258 wait_delay);
Eddie Wai55e15c92010-07-01 15:34:52 -0700259 if (hba->ofld_conns_active == conns_active)
260 break;
261 }
Eddie Wai250ae982010-08-12 16:44:30 -0700262 bnx2i_chip_cleanup(hba);
Eddie Wai55e15c92010-07-01 15:34:52 -0700263
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700264 /* This flag should be cleared last so that ep_disconnect() gracefully
265 * cleans up connection context
266 */
Eddie Wai842158d2010-11-23 15:29:28 -0800267 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700268 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
Michael Chancf4e6362009-06-08 18:14:44 -0700269}
270
Eddie Wai842158d2010-11-23 15:29:28 -0800271
Michael Chancf4e6362009-06-08 18:14:44 -0700272/**
Michael Chancf4e6362009-06-08 18:14:44 -0700273 * bnx2i_init_one - initialize an adapter instance and allocate memory resources
274 * @hba: bnx2i adapter instance
275 * @cnic: cnic device handle
276 *
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700277 * 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 Chancf4e6362009-06-08 18:14:44 -0700280 */
281static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic)
282{
283 int rc;
284
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700285 mutex_lock(&bnx2i_dev_lock);
Eddie Wai3601b532011-06-23 15:51:35 -0700286 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 Veerabhadrappace2d7632010-03-25 10:54:42 -0700293 hba->cnic = cnic;
Anil Veerabhadrappa4e85f152009-06-23 14:04:23 -0700294 rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba);
295 if (!rc) {
Michael Chancf4e6362009-06-08 18:14:44 -0700296 hba->age++;
Michael Chancf4e6362009-06-08 18:14:44 -0700297 set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700298 list_add_tail(&hba->link, &adapter_list);
299 adapter_count++;
Anil Veerabhadrappa4e85f152009-06-23 14:04:23 -0700300 } 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 Chancf4e6362009-06-08 18:14:44 -0700309
Eddie Wai3601b532011-06-23 15:51:35 -0700310out:
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700311 mutex_unlock(&bnx2i_dev_lock);
Anil Veerabhadrappa4e85f152009-06-23 14:04:23 -0700312
313 return rc;
Michael Chancf4e6362009-06-08 18:14:44 -0700314}
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 */
325void 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 Veerabhadrappace2d7632010-03-25 10:54:42 -0700341 }
Michael Chancf4e6362009-06-08 18:14:44 -0700342}
343
344
345/**
346 * bnx2i_ulp_exit - shuts down adapter instance and frees all resources
347 * @dev: cnic device handle
348 *
349 */
350void 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 Veerabhadrappa3be924f2009-06-23 14:07:40 -0700360 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700361 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 Chancf4e6362009-06-08 18:14:44 -0700367 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700368 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700369
370 bnx2i_free_hba(hba);
371}
372
373
374/**
Eddie Waib5cf6b62011-06-23 15:51:34 -0700375 * bnx2i_percpu_thread_create - Create a receive thread for an
376 * online CPU
377 *
378 * @cpu: cpu index for the online cpu
379 */
380static void bnx2i_percpu_thread_create(unsigned int cpu)
381{
382 struct bnx2i_percpu_s *p;
383 struct task_struct *thread;
384
385 p = &per_cpu(bnx2i_percpu, cpu);
386
387 thread = kthread_create(bnx2i_percpu_io_thread, (void *)p,
388 "bnx2i_thread/%d", cpu);
389 /* bind thread to the cpu */
390 if (likely(!IS_ERR(thread))) {
391 kthread_bind(thread, cpu);
392 p->iothread = thread;
393 wake_up_process(thread);
394 }
395}
396
397
398static void bnx2i_percpu_thread_destroy(unsigned int cpu)
399{
400 struct bnx2i_percpu_s *p;
401 struct task_struct *thread;
402 struct bnx2i_work *work, *tmp;
403
404 /* Prevent any new work from being queued for this CPU */
405 p = &per_cpu(bnx2i_percpu, cpu);
406 spin_lock_bh(&p->p_work_lock);
407 thread = p->iothread;
408 p->iothread = NULL;
409
410 /* Free all work in the list */
411 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
412 list_del_init(&work->list);
413 bnx2i_process_scsi_cmd_resp(work->session,
414 work->bnx2i_conn, &work->cqe);
415 kfree(work);
416 }
417
418 spin_unlock_bh(&p->p_work_lock);
419 if (thread)
420 kthread_stop(thread);
421}
422
423
424/**
425 * bnx2i_cpu_callback - Handler for CPU hotplug events
426 *
427 * @nfb: The callback data block
428 * @action: The event triggering the callback
429 * @hcpu: The index of the CPU that the event is for
430 *
431 * This creates or destroys per-CPU data for iSCSI
432 *
433 * Returns NOTIFY_OK always.
434 */
435static int bnx2i_cpu_callback(struct notifier_block *nfb,
436 unsigned long action, void *hcpu)
437{
438 unsigned cpu = (unsigned long)hcpu;
439
440 switch (action) {
441 case CPU_ONLINE:
442 case CPU_ONLINE_FROZEN:
443 printk(KERN_INFO "bnx2i: CPU %x online: Create Rx thread\n",
444 cpu);
445 bnx2i_percpu_thread_create(cpu);
446 break;
447 case CPU_DEAD:
448 case CPU_DEAD_FROZEN:
449 printk(KERN_INFO "CPU %x offline: Remove Rx thread\n", cpu);
450 bnx2i_percpu_thread_destroy(cpu);
451 break;
452 default:
453 break;
454 }
455 return NOTIFY_OK;
456}
457
458
459/**
Michael Chancf4e6362009-06-08 18:14:44 -0700460 * bnx2i_mod_init - module init entry point
461 *
462 * initialize any driver wide global data structures such as endpoint pool,
463 * tcp port manager/queue, sysfs. finally driver will register itself
464 * with the cnic module
465 */
466static int __init bnx2i_mod_init(void)
467{
468 int err;
Eddie Waib5cf6b62011-06-23 15:51:34 -0700469 unsigned cpu = 0;
470 struct bnx2i_percpu_s *p;
Michael Chancf4e6362009-06-08 18:14:44 -0700471
472 printk(KERN_INFO "%s", version);
473
Anil Veerabhadrappaf8c9abe2009-12-07 11:39:54 -0800474 if (sq_size && !is_power_of_2(sq_size))
Michael Chancf4e6362009-06-08 18:14:44 -0700475 sq_size = roundup_pow_of_two(sq_size);
476
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700477 mutex_init(&bnx2i_dev_lock);
478
Michael Chancf4e6362009-06-08 18:14:44 -0700479 bnx2i_scsi_xport_template =
480 iscsi_register_transport(&bnx2i_iscsi_transport);
481 if (!bnx2i_scsi_xport_template) {
482 printk(KERN_ERR "Could not register bnx2i transport.\n");
483 err = -ENOMEM;
484 goto out;
485 }
486
487 err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb);
488 if (err) {
489 printk(KERN_ERR "Could not register bnx2i cnic driver.\n");
490 goto unreg_xport;
491 }
492
Eddie Waib5cf6b62011-06-23 15:51:34 -0700493 /* Create percpu kernel threads to handle iSCSI I/O completions */
494 for_each_possible_cpu(cpu) {
495 p = &per_cpu(bnx2i_percpu, cpu);
496 INIT_LIST_HEAD(&p->work_list);
497 spin_lock_init(&p->p_work_lock);
498 p->iothread = NULL;
499 }
500
501 for_each_online_cpu(cpu)
502 bnx2i_percpu_thread_create(cpu);
503
504 /* Initialize per CPU interrupt thread */
505 register_hotcpu_notifier(&bnx2i_cpu_notifier);
506
Michael Chancf4e6362009-06-08 18:14:44 -0700507 return 0;
508
509unreg_xport:
510 iscsi_unregister_transport(&bnx2i_iscsi_transport);
511out:
512 return err;
513}
514
515
516/**
517 * bnx2i_mod_exit - module cleanup/exit entry point
518 *
519 * Global resource lock and host adapter lock is held during critical sections
520 * in this function. Driver will browse through the adapter list, cleans-up
521 * each instance, unregisters iscsi transport name and finally driver will
522 * unregister itself with the cnic module
523 */
524static void __exit bnx2i_mod_exit(void)
525{
526 struct bnx2i_hba *hba;
Eddie Waib5cf6b62011-06-23 15:51:34 -0700527 unsigned cpu = 0;
Michael Chancf4e6362009-06-08 18:14:44 -0700528
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700529 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700530 while (!list_empty(&adapter_list)) {
531 hba = list_entry(adapter_list.next, struct bnx2i_hba, link);
532 list_del(&hba->link);
533 adapter_count--;
534
535 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
Eddie Wai250ae982010-08-12 16:44:30 -0700536 bnx2i_chip_cleanup(hba);
Michael Chancf4e6362009-06-08 18:14:44 -0700537 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
538 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
Michael Chancf4e6362009-06-08 18:14:44 -0700539 }
540
Michael Chancf4e6362009-06-08 18:14:44 -0700541 bnx2i_free_hba(hba);
Michael Chancf4e6362009-06-08 18:14:44 -0700542 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700543 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700544
Eddie Waib5cf6b62011-06-23 15:51:34 -0700545 unregister_hotcpu_notifier(&bnx2i_cpu_notifier);
546
547 for_each_online_cpu(cpu)
548 bnx2i_percpu_thread_destroy(cpu);
549
Michael Chancf4e6362009-06-08 18:14:44 -0700550 iscsi_unregister_transport(&bnx2i_iscsi_transport);
551 cnic_unregister_driver(CNIC_ULP_ISCSI);
552}
553
554module_init(bnx2i_mod_init);
555module_exit(bnx2i_mod_exit);