1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include "bnx2i.h"
16
17static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list);
18static u32 adapter_count;
19
20#define DRV_MODULE_NAME "bnx2i"
21#define DRV_MODULE_VERSION "2.7.6.2"
22#define DRV_MODULE_RELDATE "Jun 06, 2013"
23
24static char version[] =
25 "Broadcom NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
26 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
27
28
29MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and "
30 "Eddie Wai <eddie.wai@broadcom.com>");
31
32MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708/5709/57710/57711/57712"
33 "/57800/57810/57840 iSCSI Driver");
34MODULE_LICENSE("GPL");
35MODULE_VERSION(DRV_MODULE_VERSION);
36
37static DEFINE_MUTEX(bnx2i_dev_lock);
38
39unsigned int event_coal_min = 24;
40module_param(event_coal_min, int, 0664);
41MODULE_PARM_DESC(event_coal_min, "Event Coalescing Minimum Commands");
42
43unsigned int event_coal_div = 2;
44module_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, uint, 0664);
53MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1");
54
55unsigned int error_mask2 = 0x00;
56module_param(error_mask2, uint, 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
69DEFINE_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
74static struct notifier_block bnx2i_cpu_notifier = {
75 .notifier_call = bnx2i_cpu_callback,
76};
77
78
79
80
81
82
83
84
85
86
87
88void bnx2i_identify_device(struct bnx2i_hba *hba, struct cnic_dev *dev)
89{
90 hba->cnic_dev_type = 0;
91 if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
92 if (hba->pci_did == PCI_DEVICE_ID_NX2_5706 ||
93 hba->pci_did == PCI_DEVICE_ID_NX2_5706S) {
94 set_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type);
95 } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5708 ||
96 hba->pci_did == PCI_DEVICE_ID_NX2_5708S) {
97 set_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type);
98 } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5709 ||
99 hba->pci_did == PCI_DEVICE_ID_NX2_5709S) {
100 set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type);
101 hba->mail_queue_access = BNX2I_MQ_BIN_MODE;
102 }
103 } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
104 set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
105 } else {
106 printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
107 hba->pci_did);
108 }
109}
110
111
112
113
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
123 mutex_lock(&bnx2i_dev_lock);
124 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 }
130 mutex_unlock(&bnx2i_dev_lock);
131hba_not_found:
132 return hba;
133}
134
135
136
137
138
139
140
141struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic)
142{
143 struct bnx2i_hba *hba, *temp;
144
145 mutex_lock(&bnx2i_dev_lock);
146 list_for_each_entry_safe(hba, temp, &adapter_list, link) {
147 if (hba->cnic == cnic) {
148 mutex_unlock(&bnx2i_dev_lock);
149 return hba;
150 }
151 }
152 mutex_unlock(&bnx2i_dev_lock);
153 return NULL;
154}
155
156
157
158
159
160
161
162
163
164
165
166
167
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
175
176
177
178
179
180 bnx2i_send_fw_iscsi_init_msg(hba);
181 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) &&
182 !test_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state) && i--)
183 msleep(BNX2I_INIT_POLL_TIME);
184}
185
186
187
188
189
190
191
192
193
194static 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
201
202
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
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
220
221
222
223
224
225
226void bnx2i_stop(void *handle)
227{
228 struct bnx2i_hba *hba = handle;
229 int conns_active;
230 int wait_delay = 1 * HZ;
231
232
233 if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN,
234 &hba->adapter_state)) {
235 iscsi_host_for_each_session(hba->shost,
236 bnx2i_drop_session);
237 wait_delay = hba->hba_shutdown_tmo;
238 }
239
240
241
242
243
244 wait_event_interruptible_timeout(hba->eh_wait,
245 (list_empty(&hba->ep_ofld_list) &&
246 list_empty(&hba->ep_destroy_list)),
247 2 * HZ);
248
249
250
251
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),
256 wait_delay);
257 if (hba->ofld_conns_active == conns_active)
258 break;
259 }
260 bnx2i_chip_cleanup(hba);
261
262
263
264
265 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
266 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
267}
268
269
270
271
272
273
274
275
276
277
278
279static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic)
280{
281 int rc;
282
283 mutex_lock(&bnx2i_dev_lock);
284 if (!cnic->max_iscsi_conn) {
285 printk(KERN_ALERT "bnx2i: dev %s does not support "
286 "iSCSI\n", hba->netdev->name);
287 rc = -EOPNOTSUPP;
288 goto out;
289 }
290
291 hba->cnic = cnic;
292 rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba);
293 if (!rc) {
294 hba->age++;
295 set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
296 list_add_tail(&hba->link, &adapter_list);
297 adapter_count++;
298 } else if (rc == -EBUSY)
299 printk(KERN_ALERT "bnx2i, duplicate registration"
300 "hba=%p, cnic=%p\n", hba, cnic);
301 else if (rc == -EAGAIN)
302 printk(KERN_ERR "bnx2i, driver not registered\n");
303 else if (rc == -EINVAL)
304 printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI);
305 else
306 printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc);
307
308out:
309 mutex_unlock(&bnx2i_dev_lock);
310
311 return rc;
312}
313
314
315
316
317
318
319
320
321
322
323void bnx2i_ulp_init(struct cnic_dev *dev)
324{
325 struct bnx2i_hba *hba;
326
327
328 hba = bnx2i_alloc_hba(dev);
329 if (!hba) {
330 printk(KERN_ERR "bnx2i init: hba initialization failed\n");
331 return;
332 }
333
334
335 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
336 if (bnx2i_init_one(hba, dev)) {
337 printk(KERN_ERR "bnx2i - hba %p init failed\n", hba);
338 bnx2i_free_hba(hba);
339 }
340}
341
342
343
344
345
346
347
348void bnx2i_ulp_exit(struct cnic_dev *dev)
349{
350 struct bnx2i_hba *hba;
351
352 hba = bnx2i_find_hba_for_cnic(dev);
353 if (!hba) {
354 printk(KERN_INFO "bnx2i_ulp_exit: hba not "
355 "found, dev 0x%p\n", dev);
356 return;
357 }
358 mutex_lock(&bnx2i_dev_lock);
359 list_del_init(&hba->link);
360 adapter_count--;
361
362 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
363 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
364 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
365 }
366 mutex_unlock(&bnx2i_dev_lock);
367
368 bnx2i_free_hba(hba);
369}
370
371
372
373
374
375
376
377
378
379int bnx2i_get_stats(void *handle)
380{
381 struct bnx2i_hba *hba = handle;
382 struct iscsi_stats_info *stats;
383
384 if (!hba)
385 return -EINVAL;
386
387 stats = (struct iscsi_stats_info *)hba->cnic->stats_addr;
388
389 if (!stats)
390 return -ENOMEM;
391
392 strlcpy(stats->version, DRV_MODULE_VERSION, sizeof(stats->version));
393 memcpy(stats->mac_add1 + 2, hba->cnic->mac_addr, ETH_ALEN);
394
395 stats->max_frame_size = hba->netdev->mtu;
396 stats->txq_size = hba->max_sqes;
397 stats->rxq_size = hba->max_cqes;
398
399 stats->txq_avg_depth = 0;
400 stats->rxq_avg_depth = 0;
401
402 GET_STATS_64(hba, stats, rx_pdus);
403 GET_STATS_64(hba, stats, rx_bytes);
404
405 GET_STATS_64(hba, stats, tx_pdus);
406 GET_STATS_64(hba, stats, tx_bytes);
407
408 return 0;
409}
410
411
412
413
414
415
416
417
418static void bnx2i_percpu_thread_create(unsigned int cpu)
419{
420 struct bnx2i_percpu_s *p;
421 struct task_struct *thread;
422
423 p = &per_cpu(bnx2i_percpu, cpu);
424
425 thread = kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p,
426 cpu_to_node(cpu),
427 "bnx2i_thread/%d", cpu);
428
429 if (likely(!IS_ERR(thread))) {
430 kthread_bind(thread, cpu);
431 p->iothread = thread;
432 wake_up_process(thread);
433 }
434}
435
436
437static void bnx2i_percpu_thread_destroy(unsigned int cpu)
438{
439 struct bnx2i_percpu_s *p;
440 struct task_struct *thread;
441 struct bnx2i_work *work, *tmp;
442
443
444 p = &per_cpu(bnx2i_percpu, cpu);
445 spin_lock_bh(&p->p_work_lock);
446 thread = p->iothread;
447 p->iothread = NULL;
448
449
450 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
451 list_del_init(&work->list);
452 bnx2i_process_scsi_cmd_resp(work->session,
453 work->bnx2i_conn, &work->cqe);
454 kfree(work);
455 }
456
457 spin_unlock_bh(&p->p_work_lock);
458 if (thread)
459 kthread_stop(thread);
460}
461
462
463
464
465
466
467
468
469
470
471
472
473
474static int bnx2i_cpu_callback(struct notifier_block *nfb,
475 unsigned long action, void *hcpu)
476{
477 unsigned cpu = (unsigned long)hcpu;
478
479 switch (action) {
480 case CPU_ONLINE:
481 case CPU_ONLINE_FROZEN:
482 printk(KERN_INFO "bnx2i: CPU %x online: Create Rx thread\n",
483 cpu);
484 bnx2i_percpu_thread_create(cpu);
485 break;
486 case CPU_DEAD:
487 case CPU_DEAD_FROZEN:
488 printk(KERN_INFO "CPU %x offline: Remove Rx thread\n", cpu);
489 bnx2i_percpu_thread_destroy(cpu);
490 break;
491 default:
492 break;
493 }
494 return NOTIFY_OK;
495}
496
497
498
499
500
501
502
503
504
505static int __init bnx2i_mod_init(void)
506{
507 int err;
508 unsigned cpu = 0;
509 struct bnx2i_percpu_s *p;
510
511 printk(KERN_INFO "%s", version);
512
513 if (sq_size && !is_power_of_2(sq_size))
514 sq_size = roundup_pow_of_two(sq_size);
515
516 mutex_init(&bnx2i_dev_lock);
517
518 bnx2i_scsi_xport_template =
519 iscsi_register_transport(&bnx2i_iscsi_transport);
520 if (!bnx2i_scsi_xport_template) {
521 printk(KERN_ERR "Could not register bnx2i transport.\n");
522 err = -ENOMEM;
523 goto out;
524 }
525
526 err = cnic_register_driver(CNIC_ULP_ISCSI, &bnx2i_cnic_cb);
527 if (err) {
528 printk(KERN_ERR "Could not register bnx2i cnic driver.\n");
529 goto unreg_xport;
530 }
531
532
533 for_each_possible_cpu(cpu) {
534 p = &per_cpu(bnx2i_percpu, cpu);
535 INIT_LIST_HEAD(&p->work_list);
536 spin_lock_init(&p->p_work_lock);
537 p->iothread = NULL;
538 }
539
540 cpu_notifier_register_begin();
541
542 for_each_online_cpu(cpu)
543 bnx2i_percpu_thread_create(cpu);
544
545
546 __register_hotcpu_notifier(&bnx2i_cpu_notifier);
547
548 cpu_notifier_register_done();
549
550 return 0;
551
552unreg_xport:
553 iscsi_unregister_transport(&bnx2i_iscsi_transport);
554out:
555 return err;
556}
557
558
559
560
561
562
563
564
565
566
567static void __exit bnx2i_mod_exit(void)
568{
569 struct bnx2i_hba *hba;
570 unsigned cpu = 0;
571
572 mutex_lock(&bnx2i_dev_lock);
573 while (!list_empty(&adapter_list)) {
574 hba = list_entry(adapter_list.next, struct bnx2i_hba, link);
575 list_del(&hba->link);
576 adapter_count--;
577
578 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
579 bnx2i_chip_cleanup(hba);
580 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
581 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
582 }
583
584 bnx2i_free_hba(hba);
585 }
586 mutex_unlock(&bnx2i_dev_lock);
587
588 cpu_notifier_register_begin();
589
590 for_each_online_cpu(cpu)
591 bnx2i_percpu_thread_destroy(cpu);
592
593 __unregister_hotcpu_notifier(&bnx2i_cpu_notifier);
594
595 cpu_notifier_register_done();
596
597 iscsi_unregister_transport(&bnx2i_iscsi_transport);
598 cnic_unregister_driver(CNIC_ULP_ISCSI);
599}
600
601module_init(bnx2i_mod_init);
602module_exit(bnx2i_mod_exit);
603