blob: b17637aab9a792a959558ef79184800f9f0280a2 [file] [log] [blame]
Michael Chancf4e6362009-06-08 18:14:44 -07001/* bnx2i.c: Broadcom NetXtreme II iSCSI driver.
2 *
Eddie Wai9ebd99c2012-04-25 15:08:37 -07003 * Copyright (c) 2006 - 2012 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 Wai9ebd99c2012-04-25 15:08:37 -070021#define DRV_MODULE_VERSION "2.7.2.2"
22#define DRV_MODULE_RELDATE "Apr 25, 2012"
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"
Michael Chanf4b5ad22011-06-20 15:15:56 +000033 "/57800/57810/57840 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;
Eddie Wai70fc8722012-02-02 15:22:00 -080052module_param(error_mask1, uint, 0664);
Michael Chancf4e6362009-06-08 18:14:44 -070053MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1");
54
55unsigned int error_mask2 = 0x00;
Eddie Wai70fc8722012-02-02 15:22:00 -080056module_param(error_mask2, uint, 0664);
Michael Chancf4e6362009-06-08 18:14:44 -070057MODULE_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;
Michael Chanf4b5ad22011-06-20 15:15:56 +0000100 } 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 ||
105 hba->pci_did == PCI_DEVICE_ID_NX2_57800 ||
106 hba->pci_did == PCI_DEVICE_ID_NX2_57800_MF ||
107 hba->pci_did == PCI_DEVICE_ID_NX2_57800_VF ||
108 hba->pci_did == PCI_DEVICE_ID_NX2_57810 ||
109 hba->pci_did == PCI_DEVICE_ID_NX2_57810_MF ||
110 hba->pci_did == PCI_DEVICE_ID_NX2_57810_VF ||
111 hba->pci_did == PCI_DEVICE_ID_NX2_57840 ||
112 hba->pci_did == PCI_DEVICE_ID_NX2_57840_MF ||
113 hba->pci_did == PCI_DEVICE_ID_NX2_57840_VF)
Michael Chancf4e6362009-06-08 18:14:44 -0700114 set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
Anil Veerabhadrappa5d9e1fa2009-12-07 11:39:33 -0800115 else
116 printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
117 hba->pci_did);
Michael Chancf4e6362009-06-08 18:14:44 -0700118}
119
120
121/**
122 * get_adapter_list_head - returns head of adapter list
123 */
124struct bnx2i_hba *get_adapter_list_head(void)
125{
126 struct bnx2i_hba *hba = NULL;
127 struct bnx2i_hba *tmp_hba;
128
129 if (!adapter_count)
130 goto hba_not_found;
131
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700132 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700133 list_for_each_entry(tmp_hba, &adapter_list, link) {
134 if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) {
135 hba = tmp_hba;
136 break;
137 }
138 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700139 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700140hba_not_found:
141 return hba;
142}
143
144
145/**
146 * bnx2i_find_hba_for_cnic - maps cnic device instance to bnx2i adapter instance
147 * @cnic: pointer to cnic device instance
148 *
149 */
150struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic)
151{
152 struct bnx2i_hba *hba, *temp;
153
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700154 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700155 list_for_each_entry_safe(hba, temp, &adapter_list, link) {
156 if (hba->cnic == cnic) {
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700157 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700158 return hba;
159 }
160 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700161 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700162 return NULL;
163}
164
165
166/**
167 * bnx2i_start - cnic callback to initialize & start adapter instance
168 * @handle: transparent handle pointing to adapter structure
169 *
170 * This function maps adapter structure to pcidev structure and initiates
171 * firmware handshake to enable/initialize on chip iscsi components
172 * This bnx2i - cnic interface api callback is issued after following
173 * 2 conditions are met -
174 * a) underlying network interface is up (marked by event 'NETDEV_UP'
175 * from netdev
176 * b) bnx2i adapter instance is registered
177 */
178void bnx2i_start(void *handle)
179{
180#define BNX2I_INIT_POLL_TIME (1000 / HZ)
181 struct bnx2i_hba *hba = handle;
182 int i = HZ;
183
Eddie Wai3601b532011-06-23 15:51:35 -0700184 /*
185 * We should never register devices that don't support iSCSI
186 * (see bnx2i_init_one), so something is wrong if we try to
187 * start a iSCSI adapter on hardware with 0 supported iSCSI
188 * connections
189 */
190 BUG_ON(!hba->cnic->max_iscsi_conn);
Eddie Waia977d2c2011-02-16 15:04:27 -0600191
Michael Chancf4e6362009-06-08 18:14:44 -0700192 bnx2i_send_fw_iscsi_init_msg(hba);
193 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
194 msleep(BNX2I_INIT_POLL_TIME);
195}
196
197
198/**
Eddie Wai250ae982010-08-12 16:44:30 -0700199 * bnx2i_chip_cleanup - local routine to handle chip cleanup
200 * @hba: Adapter instance to register
201 *
202 * Driver checks if adapter still has any active connections before
203 * executing the cleanup process
204 */
205static void bnx2i_chip_cleanup(struct bnx2i_hba *hba)
206{
207 struct bnx2i_endpoint *bnx2i_ep;
208 struct list_head *pos, *tmp;
209
210 if (hba->ofld_conns_active) {
211 /* Stage to force the disconnection
212 * This is the case where the daemon is either slow or
213 * not present
214 */
215 printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active "
216 "connections\n", hba->netdev->name,
217 hba->ofld_conns_active);
218 mutex_lock(&hba->net_dev_lock);
219 list_for_each_safe(pos, tmp, &hba->ep_active_list) {
220 bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link);
221 /* Clean up the chip only */
222 bnx2i_hw_ep_disconnect(bnx2i_ep);
223 bnx2i_ep->cm_sk = NULL;
224 }
225 mutex_unlock(&hba->net_dev_lock);
226 }
227}
228
229
230/**
Michael Chancf4e6362009-06-08 18:14:44 -0700231 * bnx2i_stop - cnic callback to shutdown adapter instance
232 * @handle: transparent handle pointing to adapter structure
233 *
234 * driver checks if adapter is already in shutdown mode, if not start
235 * the shutdown process
236 */
237void bnx2i_stop(void *handle)
238{
239 struct bnx2i_hba *hba = handle;
Eddie Wai55e15c972010-07-01 15:34:52 -0700240 int conns_active;
Eddie Wai842158d2010-11-23 15:29:28 -0800241 int wait_delay = 1 * HZ;
Michael Chancf4e6362009-06-08 18:14:44 -0700242
243 /* check if cleanup happened in GOING_DOWN context */
Eddie Wai842158d2010-11-23 15:29:28 -0800244 if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN,
245 &hba->adapter_state)) {
Michael Chancf4e6362009-06-08 18:14:44 -0700246 iscsi_host_for_each_session(hba->shost,
247 bnx2i_drop_session);
Eddie Wai842158d2010-11-23 15:29:28 -0800248 wait_delay = hba->hba_shutdown_tmo;
249 }
250 /* Wait for inflight offload connection tasks to complete before
251 * proceeding. Forcefully terminate all connection recovery in
252 * progress at the earliest, either in bind(), send_pdu(LOGIN),
253 * or conn_start()
254 */
255 wait_event_interruptible_timeout(hba->eh_wait,
256 (list_empty(&hba->ep_ofld_list) &&
257 list_empty(&hba->ep_destroy_list)),
Eddie Waid5307a072011-05-16 11:13:19 -0700258 2 * HZ);
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700259 /* Wait for all endpoints to be torn down, Chip will be reset once
260 * control returns to network driver. So it is required to cleanup and
261 * release all connection resources before returning from this routine.
262 */
Eddie Wai55e15c972010-07-01 15:34:52 -0700263 while (hba->ofld_conns_active) {
264 conns_active = hba->ofld_conns_active;
265 wait_event_interruptible_timeout(hba->eh_wait,
266 (hba->ofld_conns_active != conns_active),
Eddie Wai842158d2010-11-23 15:29:28 -0800267 wait_delay);
Eddie Wai55e15c972010-07-01 15:34:52 -0700268 if (hba->ofld_conns_active == conns_active)
269 break;
270 }
Eddie Wai250ae982010-08-12 16:44:30 -0700271 bnx2i_chip_cleanup(hba);
Eddie Wai55e15c972010-07-01 15:34:52 -0700272
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700273 /* This flag should be cleared last so that ep_disconnect() gracefully
274 * cleans up connection context
275 */
Eddie Wai842158d2010-11-23 15:29:28 -0800276 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
Anil Veerabhadrappa490475a2010-04-08 15:59:15 -0700277 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
Michael Chancf4e6362009-06-08 18:14:44 -0700278}
279
Eddie Wai842158d2010-11-23 15:29:28 -0800280
Michael Chancf4e6362009-06-08 18:14:44 -0700281/**
Michael Chancf4e6362009-06-08 18:14:44 -0700282 * bnx2i_init_one - initialize an adapter instance and allocate memory resources
283 * @hba: bnx2i adapter instance
284 * @cnic: cnic device handle
285 *
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700286 * Global resource lock is held during critical sections below. This routine is
287 * called from either cnic_register_driver() or device hot plug context and
288 * and does majority of device specific initialization
Michael Chancf4e6362009-06-08 18:14:44 -0700289 */
290static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic)
291{
292 int rc;
293
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700294 mutex_lock(&bnx2i_dev_lock);
Eddie Wai3601b532011-06-23 15:51:35 -0700295 if (!cnic->max_iscsi_conn) {
296 printk(KERN_ALERT "bnx2i: dev %s does not support "
297 "iSCSI\n", hba->netdev->name);
298 rc = -EOPNOTSUPP;
299 goto out;
300 }
301
Anil Veerabhadrappace2d7632010-03-25 10:54:42 -0700302 hba->cnic = cnic;
Anil Veerabhadrappa4e85f152009-06-23 14:04:23 -0700303 rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba);
304 if (!rc) {
Michael Chancf4e6362009-06-08 18:14:44 -0700305 hba->age++;
Michael Chancf4e6362009-06-08 18:14:44 -0700306 set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700307 list_add_tail(&hba->link, &adapter_list);
308 adapter_count++;
Anil Veerabhadrappa4e85f152009-06-23 14:04:23 -0700309 } else if (rc == -EBUSY) /* duplicate registration */
310 printk(KERN_ALERT "bnx2i, duplicate registration"
311 "hba=%p, cnic=%p\n", hba, cnic);
312 else if (rc == -EAGAIN)
313 printk(KERN_ERR "bnx2i, driver not registered\n");
314 else if (rc == -EINVAL)
315 printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI);
316 else
317 printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc);
Michael Chancf4e6362009-06-08 18:14:44 -0700318
Eddie Wai3601b532011-06-23 15:51:35 -0700319out:
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700320 mutex_unlock(&bnx2i_dev_lock);
Anil Veerabhadrappa4e85f152009-06-23 14:04:23 -0700321
322 return rc;
Michael Chancf4e6362009-06-08 18:14:44 -0700323}
324
325
326/**
327 * bnx2i_ulp_init - initialize an adapter instance
328 * @dev: cnic device handle
329 *
330 * Called from cnic_register_driver() context to initialize all enumerated
331 * cnic devices. This routine allocate adapter structure and other
332 * device specific resources.
333 */
334void bnx2i_ulp_init(struct cnic_dev *dev)
335{
336 struct bnx2i_hba *hba;
337
338 /* Allocate a HBA structure for this device */
339 hba = bnx2i_alloc_hba(dev);
340 if (!hba) {
341 printk(KERN_ERR "bnx2i init: hba initialization failed\n");
342 return;
343 }
344
345 /* Get PCI related information and update hba struct members */
346 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
347 if (bnx2i_init_one(hba, dev)) {
348 printk(KERN_ERR "bnx2i - hba %p init failed\n", hba);
349 bnx2i_free_hba(hba);
Anil Veerabhadrappace2d7632010-03-25 10:54:42 -0700350 }
Michael Chancf4e6362009-06-08 18:14:44 -0700351}
352
353
354/**
355 * bnx2i_ulp_exit - shuts down adapter instance and frees all resources
356 * @dev: cnic device handle
357 *
358 */
359void bnx2i_ulp_exit(struct cnic_dev *dev)
360{
361 struct bnx2i_hba *hba;
362
363 hba = bnx2i_find_hba_for_cnic(dev);
364 if (!hba) {
365 printk(KERN_INFO "bnx2i_ulp_exit: hba not "
366 "found, dev 0x%p\n", dev);
367 return;
368 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700369 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700370 list_del_init(&hba->link);
371 adapter_count--;
372
373 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
374 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
375 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
Michael Chancf4e6362009-06-08 18:14:44 -0700376 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700377 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700378
379 bnx2i_free_hba(hba);
380}
381
382
383/**
Barak Witkowski2e499d32012-06-26 01:31:19 +0000384 * bnx2i_get_stats - Retrieve various statistic from iSCSI offload
385 * @handle: bnx2i_hba
386 *
387 * function callback exported via bnx2i - cnic driver interface to
388 * retrieve various iSCSI offload related statistics.
389 */
390int bnx2i_get_stats(void *handle)
391{
392 struct bnx2i_hba *hba = handle;
393 struct iscsi_stats_info *stats;
394
395 if (!hba)
396 return -EINVAL;
397
398 stats = (struct iscsi_stats_info *)hba->cnic->stats_addr;
399
400 if (!stats)
401 return -ENOMEM;
402
Dan Carpenter12aba9e2012-06-30 01:49:35 +0000403 strlcpy(stats->version, DRV_MODULE_VERSION, sizeof(stats->version));
Barak Witkowski2e499d32012-06-26 01:31:19 +0000404 memcpy(stats->mac_add1 + 2, hba->cnic->mac_addr, ETH_ALEN);
405
406 stats->max_frame_size = hba->netdev->mtu;
407 stats->txq_size = hba->max_sqes;
408 stats->rxq_size = hba->max_cqes;
409
410 stats->txq_avg_depth = 0;
411 stats->rxq_avg_depth = 0;
412
413 GET_STATS_64(hba, stats, rx_pdus);
414 GET_STATS_64(hba, stats, rx_bytes);
415
416 GET_STATS_64(hba, stats, tx_pdus);
417 GET_STATS_64(hba, stats, tx_bytes);
418
419 return 0;
420}
421
422
423/**
Eddie Waib5cf6b62011-06-23 15:51:34 -0700424 * bnx2i_percpu_thread_create - Create a receive thread for an
425 * online CPU
426 *
427 * @cpu: cpu index for the online cpu
428 */
429static void bnx2i_percpu_thread_create(unsigned int cpu)
430{
431 struct bnx2i_percpu_s *p;
432 struct task_struct *thread;
433
434 p = &per_cpu(bnx2i_percpu, cpu);
435
Eric Dumazet93713f32012-02-02 14:03:22 +0100436 thread = kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p,
437 cpu_to_node(cpu),
438 "bnx2i_thread/%d", cpu);
Eddie Waib5cf6b62011-06-23 15:51:34 -0700439 /* bind thread to the cpu */
440 if (likely(!IS_ERR(thread))) {
441 kthread_bind(thread, cpu);
442 p->iothread = thread;
443 wake_up_process(thread);
444 }
445}
446
447
448static void bnx2i_percpu_thread_destroy(unsigned int cpu)
449{
450 struct bnx2i_percpu_s *p;
451 struct task_struct *thread;
452 struct bnx2i_work *work, *tmp;
453
454 /* Prevent any new work from being queued for this CPU */
455 p = &per_cpu(bnx2i_percpu, cpu);
456 spin_lock_bh(&p->p_work_lock);
457 thread = p->iothread;
458 p->iothread = NULL;
459
460 /* Free all work in the list */
461 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
462 list_del_init(&work->list);
463 bnx2i_process_scsi_cmd_resp(work->session,
464 work->bnx2i_conn, &work->cqe);
465 kfree(work);
466 }
467
468 spin_unlock_bh(&p->p_work_lock);
469 if (thread)
470 kthread_stop(thread);
471}
472
473
474/**
475 * bnx2i_cpu_callback - Handler for CPU hotplug events
476 *
477 * @nfb: The callback data block
478 * @action: The event triggering the callback
479 * @hcpu: The index of the CPU that the event is for
480 *
481 * This creates or destroys per-CPU data for iSCSI
482 *
483 * Returns NOTIFY_OK always.
484 */
485static int bnx2i_cpu_callback(struct notifier_block *nfb,
486 unsigned long action, void *hcpu)
487{
488 unsigned cpu = (unsigned long)hcpu;
489
490 switch (action) {
491 case CPU_ONLINE:
492 case CPU_ONLINE_FROZEN:
493 printk(KERN_INFO "bnx2i: CPU %x online: Create Rx thread\n",
494 cpu);
495 bnx2i_percpu_thread_create(cpu);
496 break;
497 case CPU_DEAD:
498 case CPU_DEAD_FROZEN:
499 printk(KERN_INFO "CPU %x offline: Remove Rx thread\n", cpu);
500 bnx2i_percpu_thread_destroy(cpu);
501 break;
502 default:
503 break;
504 }
505 return NOTIFY_OK;
506}
507
508
509/**
Michael Chancf4e6362009-06-08 18:14:44 -0700510 * bnx2i_mod_init - module init entry point
511 *
512 * initialize any driver wide global data structures such as endpoint pool,
513 * tcp port manager/queue, sysfs. finally driver will register itself
514 * with the cnic module
515 */
516static int __init bnx2i_mod_init(void)
517{
518 int err;
Eddie Waib5cf6b62011-06-23 15:51:34 -0700519 unsigned cpu = 0;
520 struct bnx2i_percpu_s *p;
Michael Chancf4e6362009-06-08 18:14:44 -0700521
522 printk(KERN_INFO "%s", version);
523
Anil Veerabhadrappaf8c9abe2009-12-07 11:39:54 -0800524 if (sq_size && !is_power_of_2(sq_size))
Michael Chancf4e6362009-06-08 18:14:44 -0700525 sq_size = roundup_pow_of_two(sq_size);
526
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700527 mutex_init(&bnx2i_dev_lock);
528
Michael Chancf4e6362009-06-08 18:14:44 -0700529 bnx2i_scsi_xport_template =
530 iscsi_register_transport(&bnx2i_iscsi_transport);
531 if (!bnx2i_scsi_xport_template) {
532 printk(KERN_ERR "Could not register bnx2i transport.\n");
533 err = -ENOMEM;
534 goto out;
535 }
536
537 err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb);
538 if (err) {
539 printk(KERN_ERR "Could not register bnx2i cnic driver.\n");
540 goto unreg_xport;
541 }
542
Eddie Waib5cf6b62011-06-23 15:51:34 -0700543 /* Create percpu kernel threads to handle iSCSI I/O completions */
544 for_each_possible_cpu(cpu) {
545 p = &per_cpu(bnx2i_percpu, cpu);
546 INIT_LIST_HEAD(&p->work_list);
547 spin_lock_init(&p->p_work_lock);
548 p->iothread = NULL;
549 }
550
551 for_each_online_cpu(cpu)
552 bnx2i_percpu_thread_create(cpu);
553
554 /* Initialize per CPU interrupt thread */
555 register_hotcpu_notifier(&bnx2i_cpu_notifier);
556
Michael Chancf4e6362009-06-08 18:14:44 -0700557 return 0;
558
559unreg_xport:
560 iscsi_unregister_transport(&bnx2i_iscsi_transport);
561out:
562 return err;
563}
564
565
566/**
567 * bnx2i_mod_exit - module cleanup/exit entry point
568 *
569 * Global resource lock and host adapter lock is held during critical sections
570 * in this function. Driver will browse through the adapter list, cleans-up
571 * each instance, unregisters iscsi transport name and finally driver will
572 * unregister itself with the cnic module
573 */
574static void __exit bnx2i_mod_exit(void)
575{
576 struct bnx2i_hba *hba;
Eddie Waib5cf6b62011-06-23 15:51:34 -0700577 unsigned cpu = 0;
Michael Chancf4e6362009-06-08 18:14:44 -0700578
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700579 mutex_lock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700580 while (!list_empty(&adapter_list)) {
581 hba = list_entry(adapter_list.next, struct bnx2i_hba, link);
582 list_del(&hba->link);
583 adapter_count--;
584
585 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
Eddie Wai250ae982010-08-12 16:44:30 -0700586 bnx2i_chip_cleanup(hba);
Michael Chancf4e6362009-06-08 18:14:44 -0700587 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
588 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
Michael Chancf4e6362009-06-08 18:14:44 -0700589 }
590
Michael Chancf4e6362009-06-08 18:14:44 -0700591 bnx2i_free_hba(hba);
Michael Chancf4e6362009-06-08 18:14:44 -0700592 }
Anil Veerabhadrappa3be924f2009-06-23 14:07:40 -0700593 mutex_unlock(&bnx2i_dev_lock);
Michael Chancf4e6362009-06-08 18:14:44 -0700594
Eddie Waib5cf6b62011-06-23 15:51:34 -0700595 unregister_hotcpu_notifier(&bnx2i_cpu_notifier);
596
597 for_each_online_cpu(cpu)
598 bnx2i_percpu_thread_destroy(cpu);
599
Michael Chancf4e6362009-06-08 18:14:44 -0700600 iscsi_unregister_transport(&bnx2i_iscsi_transport);
601 cnic_unregister_driver(CNIC_ULP_ISCSI);
602}
603
604module_init(bnx2i_mod_init);
605module_exit(bnx2i_mod_exit);