This source file includes following definitions.
- bnx2i_identify_device
- get_adapter_list_head
- bnx2i_find_hba_for_cnic
- bnx2i_start
- bnx2i_chip_cleanup
- bnx2i_stop
- bnx2i_init_one
- bnx2i_ulp_init
- bnx2i_ulp_exit
- bnx2i_get_stats
- bnx2i_cpu_online
- bnx2i_cpu_offline
- bnx2i_mod_init
- bnx2i_mod_exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include "bnx2i.h"
18
19 static struct list_head adapter_list = LIST_HEAD_INIT(adapter_list);
20 static u32 adapter_count;
21
22 #define DRV_MODULE_NAME "bnx2i"
23 #define DRV_MODULE_VERSION "2.7.10.1"
24 #define DRV_MODULE_RELDATE "Jul 16, 2014"
25
26 static char version[] =
27 "QLogic NetXtreme II iSCSI Driver " DRV_MODULE_NAME \
28 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
29
30
31 MODULE_AUTHOR("Anil Veerabhadrappa <anilgv@broadcom.com> and "
32 "Eddie Wai <eddie.wai@broadcom.com>");
33
34 MODULE_DESCRIPTION("QLogic NetXtreme II BCM5706/5708/5709/57710/57711/57712"
35 "/57800/57810/57840 iSCSI Driver");
36 MODULE_LICENSE("GPL");
37 MODULE_VERSION(DRV_MODULE_VERSION);
38
39 static DEFINE_MUTEX(bnx2i_dev_lock);
40
41 unsigned int event_coal_min = 24;
42 module_param(event_coal_min, int, 0664);
43 MODULE_PARM_DESC(event_coal_min, "Event Coalescing Minimum Commands");
44
45 unsigned int event_coal_div = 2;
46 module_param(event_coal_div, int, 0664);
47 MODULE_PARM_DESC(event_coal_div, "Event Coalescing Divide Factor");
48
49 unsigned int en_tcp_dack = 1;
50 module_param(en_tcp_dack, int, 0664);
51 MODULE_PARM_DESC(en_tcp_dack, "Enable TCP Delayed ACK");
52
53 unsigned int error_mask1 = 0x00;
54 module_param(error_mask1, uint, 0664);
55 MODULE_PARM_DESC(error_mask1, "Config FW iSCSI Error Mask #1");
56
57 unsigned int error_mask2 = 0x00;
58 module_param(error_mask2, uint, 0664);
59 MODULE_PARM_DESC(error_mask2, "Config FW iSCSI Error Mask #2");
60
61 unsigned int sq_size;
62 module_param(sq_size, int, 0664);
63 MODULE_PARM_DESC(sq_size, "Configure SQ size");
64
65 unsigned int rq_size = BNX2I_RQ_WQES_DEFAULT;
66 module_param(rq_size, int, 0664);
67 MODULE_PARM_DESC(rq_size, "Configure RQ size");
68
69 u64 iscsi_error_mask = 0x00;
70
71 DEFINE_PER_CPU(struct bnx2i_percpu_s, bnx2i_percpu);
72
73
74
75
76
77
78
79
80
81
82 void bnx2i_identify_device(struct bnx2i_hba *hba, struct cnic_dev *dev)
83 {
84 hba->cnic_dev_type = 0;
85 if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
86 if (hba->pci_did == PCI_DEVICE_ID_NX2_5706 ||
87 hba->pci_did == PCI_DEVICE_ID_NX2_5706S) {
88 set_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type);
89 } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5708 ||
90 hba->pci_did == PCI_DEVICE_ID_NX2_5708S) {
91 set_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type);
92 } else if (hba->pci_did == PCI_DEVICE_ID_NX2_5709 ||
93 hba->pci_did == PCI_DEVICE_ID_NX2_5709S) {
94 set_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type);
95 hba->mail_queue_access = BNX2I_MQ_BIN_MODE;
96 }
97 } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
98 set_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type);
99 } else {
100 printk(KERN_ALERT "bnx2i: unknown device, 0x%x\n",
101 hba->pci_did);
102 }
103 }
104
105
106
107
108
109 struct bnx2i_hba *get_adapter_list_head(void)
110 {
111 struct bnx2i_hba *hba = NULL;
112 struct bnx2i_hba *tmp_hba;
113
114 if (!adapter_count)
115 goto hba_not_found;
116
117 mutex_lock(&bnx2i_dev_lock);
118 list_for_each_entry(tmp_hba, &adapter_list, link) {
119 if (tmp_hba->cnic && tmp_hba->cnic->cm_select_dev) {
120 hba = tmp_hba;
121 break;
122 }
123 }
124 mutex_unlock(&bnx2i_dev_lock);
125 hba_not_found:
126 return hba;
127 }
128
129
130
131
132
133
134
135 struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic)
136 {
137 struct bnx2i_hba *hba, *temp;
138
139 mutex_lock(&bnx2i_dev_lock);
140 list_for_each_entry_safe(hba, temp, &adapter_list, link) {
141 if (hba->cnic == cnic) {
142 mutex_unlock(&bnx2i_dev_lock);
143 return hba;
144 }
145 }
146 mutex_unlock(&bnx2i_dev_lock);
147 return NULL;
148 }
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163 void bnx2i_start(void *handle)
164 {
165 #define BNX2I_INIT_POLL_TIME (1000 / HZ)
166 struct bnx2i_hba *hba = handle;
167 int i = HZ;
168
169
170
171
172
173
174 bnx2i_send_fw_iscsi_init_msg(hba);
175 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) &&
176 !test_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state) && i--)
177 msleep(BNX2I_INIT_POLL_TIME);
178 }
179
180
181
182
183
184
185
186
187
188 static void bnx2i_chip_cleanup(struct bnx2i_hba *hba)
189 {
190 struct bnx2i_endpoint *bnx2i_ep;
191 struct list_head *pos, *tmp;
192
193 if (hba->ofld_conns_active) {
194
195
196
197
198 printk(KERN_ALERT "bnx2i: (%s) chip cleanup for %d active "
199 "connections\n", hba->netdev->name,
200 hba->ofld_conns_active);
201 mutex_lock(&hba->net_dev_lock);
202 list_for_each_safe(pos, tmp, &hba->ep_active_list) {
203 bnx2i_ep = list_entry(pos, struct bnx2i_endpoint, link);
204
205 bnx2i_hw_ep_disconnect(bnx2i_ep);
206 bnx2i_ep->cm_sk = NULL;
207 }
208 mutex_unlock(&hba->net_dev_lock);
209 }
210 }
211
212
213
214
215
216
217
218
219
220 void bnx2i_stop(void *handle)
221 {
222 struct bnx2i_hba *hba = handle;
223 int conns_active;
224 int wait_delay = 1 * HZ;
225
226
227 if (!test_and_set_bit(ADAPTER_STATE_GOING_DOWN,
228 &hba->adapter_state)) {
229 iscsi_host_for_each_session(hba->shost,
230 bnx2i_drop_session);
231 wait_delay = hba->hba_shutdown_tmo;
232 }
233
234
235
236
237
238 wait_event_interruptible_timeout(hba->eh_wait,
239 (list_empty(&hba->ep_ofld_list) &&
240 list_empty(&hba->ep_destroy_list)),
241 2 * HZ);
242
243
244
245
246 while (hba->ofld_conns_active) {
247 conns_active = hba->ofld_conns_active;
248 wait_event_interruptible_timeout(hba->eh_wait,
249 (hba->ofld_conns_active != conns_active),
250 wait_delay);
251 if (hba->ofld_conns_active == conns_active)
252 break;
253 }
254 bnx2i_chip_cleanup(hba);
255
256
257
258
259 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
260 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
261 }
262
263
264
265
266
267
268
269
270
271
272
273 static int bnx2i_init_one(struct bnx2i_hba *hba, struct cnic_dev *cnic)
274 {
275 int rc;
276
277 mutex_lock(&bnx2i_dev_lock);
278 if (!cnic->max_iscsi_conn) {
279 printk(KERN_ALERT "bnx2i: dev %s does not support "
280 "iSCSI\n", hba->netdev->name);
281 rc = -EOPNOTSUPP;
282 goto out;
283 }
284
285 hba->cnic = cnic;
286 rc = cnic->register_device(cnic, CNIC_ULP_ISCSI, hba);
287 if (!rc) {
288 hba->age++;
289 set_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
290 list_add_tail(&hba->link, &adapter_list);
291 adapter_count++;
292 } else if (rc == -EBUSY)
293 printk(KERN_ALERT "bnx2i, duplicate registration"
294 "hba=%p, cnic=%p\n", hba, cnic);
295 else if (rc == -EAGAIN)
296 printk(KERN_ERR "bnx2i, driver not registered\n");
297 else if (rc == -EINVAL)
298 printk(KERN_ERR "bnx2i, invalid type %d\n", CNIC_ULP_ISCSI);
299 else
300 printk(KERN_ERR "bnx2i dev reg, unknown error, %d\n", rc);
301
302 out:
303 mutex_unlock(&bnx2i_dev_lock);
304
305 return rc;
306 }
307
308
309
310
311
312
313
314
315
316
317 void bnx2i_ulp_init(struct cnic_dev *dev)
318 {
319 struct bnx2i_hba *hba;
320
321
322 hba = bnx2i_alloc_hba(dev);
323 if (!hba) {
324 printk(KERN_ERR "bnx2i init: hba initialization failed\n");
325 return;
326 }
327
328
329 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
330 if (bnx2i_init_one(hba, dev)) {
331 printk(KERN_ERR "bnx2i - hba %p init failed\n", hba);
332 bnx2i_free_hba(hba);
333 }
334 }
335
336
337
338
339
340
341
342 void bnx2i_ulp_exit(struct cnic_dev *dev)
343 {
344 struct bnx2i_hba *hba;
345
346 hba = bnx2i_find_hba_for_cnic(dev);
347 if (!hba) {
348 printk(KERN_INFO "bnx2i_ulp_exit: hba not "
349 "found, dev 0x%p\n", dev);
350 return;
351 }
352 mutex_lock(&bnx2i_dev_lock);
353 list_del_init(&hba->link);
354 adapter_count--;
355
356 if (test_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic)) {
357 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
358 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
359 }
360 mutex_unlock(&bnx2i_dev_lock);
361
362 bnx2i_free_hba(hba);
363 }
364
365
366
367
368
369
370
371
372
373 int bnx2i_get_stats(void *handle)
374 {
375 struct bnx2i_hba *hba = handle;
376 struct iscsi_stats_info *stats;
377
378 if (!hba)
379 return -EINVAL;
380
381 stats = (struct iscsi_stats_info *)hba->cnic->stats_addr;
382
383 if (!stats)
384 return -ENOMEM;
385
386 strlcpy(stats->version, DRV_MODULE_VERSION, sizeof(stats->version));
387 memcpy(stats->mac_add1 + 2, hba->cnic->mac_addr, ETH_ALEN);
388
389 stats->max_frame_size = hba->netdev->mtu;
390 stats->txq_size = hba->max_sqes;
391 stats->rxq_size = hba->max_cqes;
392
393 stats->txq_avg_depth = 0;
394 stats->rxq_avg_depth = 0;
395
396 GET_STATS_64(hba, stats, rx_pdus);
397 GET_STATS_64(hba, stats, rx_bytes);
398
399 GET_STATS_64(hba, stats, tx_pdus);
400 GET_STATS_64(hba, stats, tx_bytes);
401
402 return 0;
403 }
404
405
406
407
408
409
410
411 static int bnx2i_cpu_online(unsigned int cpu)
412 {
413 struct bnx2i_percpu_s *p;
414 struct task_struct *thread;
415
416 p = &per_cpu(bnx2i_percpu, cpu);
417
418 thread = kthread_create_on_node(bnx2i_percpu_io_thread, (void *)p,
419 cpu_to_node(cpu),
420 "bnx2i_thread/%d", cpu);
421 if (IS_ERR(thread))
422 return PTR_ERR(thread);
423
424
425 kthread_bind(thread, cpu);
426 p->iothread = thread;
427 wake_up_process(thread);
428 return 0;
429 }
430
431 static int bnx2i_cpu_offline(unsigned int cpu)
432 {
433 struct bnx2i_percpu_s *p;
434 struct task_struct *thread;
435 struct bnx2i_work *work, *tmp;
436
437
438 p = &per_cpu(bnx2i_percpu, cpu);
439 spin_lock_bh(&p->p_work_lock);
440 thread = p->iothread;
441 p->iothread = NULL;
442
443
444 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
445 list_del_init(&work->list);
446 bnx2i_process_scsi_cmd_resp(work->session,
447 work->bnx2i_conn, &work->cqe);
448 kfree(work);
449 }
450
451 spin_unlock_bh(&p->p_work_lock);
452 if (thread)
453 kthread_stop(thread);
454 return 0;
455 }
456
457 static enum cpuhp_state bnx2i_online_state;
458
459
460
461
462
463
464
465
466 static int __init bnx2i_mod_init(void)
467 {
468 int err;
469 unsigned cpu = 0;
470 struct bnx2i_percpu_s *p;
471
472 printk(KERN_INFO "%s", version);
473
474 if (sq_size && !is_power_of_2(sq_size))
475 sq_size = roundup_pow_of_two(sq_size);
476
477 mutex_init(&bnx2i_dev_lock);
478
479 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
493
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 err = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2i:online",
502 bnx2i_cpu_online, bnx2i_cpu_offline);
503 if (err < 0)
504 goto unreg_driver;
505 bnx2i_online_state = err;
506 return 0;
507
508 unreg_driver:
509 cnic_unregister_driver(CNIC_ULP_ISCSI);
510 unreg_xport:
511 iscsi_unregister_transport(&bnx2i_iscsi_transport);
512 out:
513 return err;
514 }
515
516
517
518
519
520
521
522
523
524
525 static void __exit bnx2i_mod_exit(void)
526 {
527 struct bnx2i_hba *hba;
528
529 mutex_lock(&bnx2i_dev_lock);
530 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)) {
536 bnx2i_chip_cleanup(hba);
537 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_ISCSI);
538 clear_bit(BNX2I_CNIC_REGISTERED, &hba->reg_with_cnic);
539 }
540
541 bnx2i_free_hba(hba);
542 }
543 mutex_unlock(&bnx2i_dev_lock);
544
545 cpuhp_remove_state(bnx2i_online_state);
546
547 iscsi_unregister_transport(&bnx2i_iscsi_transport);
548 cnic_unregister_driver(CNIC_ULP_ISCSI);
549 }
550
551 module_init(bnx2i_mod_init);
552 module_exit(bnx2i_mod_exit);