1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "bnx2fc.h"
18
19static struct list_head adapter_list;
20static struct list_head if_list;
21static u32 adapter_count;
22static DEFINE_MUTEX(bnx2fc_dev_lock);
23DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
24
25#define DRV_MODULE_NAME "bnx2fc"
26#define DRV_MODULE_VERSION BNX2FC_VERSION
27#define DRV_MODULE_RELDATE "October 15, 2015"
28
29
30static char version[] =
31 "QLogic FCoE Driver " DRV_MODULE_NAME \
32 " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
33
34
35MODULE_AUTHOR("Bhanu Prakash Gollapudi <bprakash@broadcom.com>");
36MODULE_DESCRIPTION("QLogic FCoE Driver");
37MODULE_LICENSE("GPL");
38MODULE_VERSION(DRV_MODULE_VERSION);
39
40#define BNX2FC_MAX_QUEUE_DEPTH 256
41#define BNX2FC_MIN_QUEUE_DEPTH 32
42#define FCOE_WORD_TO_BYTE 4
43
44static struct scsi_transport_template *bnx2fc_transport_template;
45static struct scsi_transport_template *bnx2fc_vport_xport_template;
46
47struct workqueue_struct *bnx2fc_wq;
48
49
50
51
52struct fcoe_percpu_s bnx2fc_global;
53DEFINE_SPINLOCK(bnx2fc_global_lock);
54
55static struct cnic_ulp_ops bnx2fc_cnic_cb;
56static struct libfc_function_template bnx2fc_libfc_fcn_templ;
57static struct scsi_host_template bnx2fc_shost_template;
58static struct fc_function_template bnx2fc_transport_function;
59static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ;
60static struct fc_function_template bnx2fc_vport_xport_function;
61static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode);
62static void __bnx2fc_destroy(struct bnx2fc_interface *interface);
63static int bnx2fc_destroy(struct net_device *net_device);
64static int bnx2fc_enable(struct net_device *netdev);
65static int bnx2fc_disable(struct net_device *netdev);
66
67
68static int bnx2fc_ctlr_alloc(struct net_device *netdev);
69static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev);
70
71static void bnx2fc_recv_frame(struct sk_buff *skb);
72
73static void bnx2fc_start_disc(struct bnx2fc_interface *interface);
74static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev);
75static int bnx2fc_lport_config(struct fc_lport *lport);
76static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba);
77static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba);
78static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba);
79static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba);
80static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba);
81static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
82 struct device *parent, int npiv);
83static void bnx2fc_destroy_work(struct work_struct *work);
84
85static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device *phys_dev);
86static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
87 *phys_dev);
88static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface);
89static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic);
90
91static int bnx2fc_fw_init(struct bnx2fc_hba *hba);
92static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba);
93
94static void bnx2fc_port_shutdown(struct fc_lport *lport);
95static void bnx2fc_stop(struct bnx2fc_interface *interface);
96static int __init bnx2fc_mod_init(void);
97static void __exit bnx2fc_mod_exit(void);
98
99unsigned int bnx2fc_debug_level;
100module_param_named(debug_logging, bnx2fc_debug_level, int, S_IRUGO|S_IWUSR);
101MODULE_PARM_DESC(debug_logging,
102 "Option to enable extended logging,\n"
103 "\t\tDefault is 0 - no logging.\n"
104 "\t\t0x01 - SCSI cmd error, cleanup.\n"
105 "\t\t0x02 - Session setup, cleanup, etc.\n"
106 "\t\t0x04 - lport events, link, mtu, etc.\n"
107 "\t\t0x08 - ELS logs.\n"
108 "\t\t0x10 - fcoe L2 fame related logs.\n"
109 "\t\t0xff - LOG all messages.");
110
111uint bnx2fc_devloss_tmo;
112module_param_named(devloss_tmo, bnx2fc_devloss_tmo, uint, S_IRUGO);
113MODULE_PARM_DESC(devloss_tmo, " Change devloss_tmo for the remote ports "
114 "attached via bnx2fc.");
115
116uint bnx2fc_max_luns = BNX2FC_MAX_LUN;
117module_param_named(max_luns, bnx2fc_max_luns, uint, S_IRUGO);
118MODULE_PARM_DESC(max_luns, " Change the default max_lun per SCSI host. Default "
119 "0xffff.");
120
121uint bnx2fc_queue_depth;
122module_param_named(queue_depth, bnx2fc_queue_depth, uint, S_IRUGO);
123MODULE_PARM_DESC(queue_depth, " Change the default queue depth of SCSI devices "
124 "attached via bnx2fc.");
125
126uint bnx2fc_log_fka;
127module_param_named(log_fka, bnx2fc_log_fka, uint, S_IRUGO|S_IWUSR);
128MODULE_PARM_DESC(log_fka, " Print message to kernel log when fcoe is "
129 "initiating a FIP keep alive when debug logging is enabled.");
130
131static inline struct net_device *bnx2fc_netdev(const struct fc_lport *lport)
132{
133 return ((struct bnx2fc_interface *)
134 ((struct fcoe_port *)lport_priv(lport))->priv)->netdev;
135}
136
137static void bnx2fc_fcf_get_vlan_id(struct fcoe_fcf_device *fcf_dev)
138{
139 struct fcoe_ctlr_device *ctlr_dev =
140 fcoe_fcf_dev_to_ctlr_dev(fcf_dev);
141 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev);
142 struct bnx2fc_interface *fcoe = fcoe_ctlr_priv(ctlr);
143
144 fcf_dev->vlan_id = fcoe->vlan_id;
145}
146
147static void bnx2fc_clean_rx_queue(struct fc_lport *lp)
148{
149 struct fcoe_percpu_s *bg;
150 struct fcoe_rcv_info *fr;
151 struct sk_buff_head *list;
152 struct sk_buff *skb, *next;
153
154 bg = &bnx2fc_global;
155 spin_lock_bh(&bg->fcoe_rx_list.lock);
156 list = &bg->fcoe_rx_list;
157 skb_queue_walk_safe(list, skb, next) {
158 fr = fcoe_dev_from_skb(skb);
159 if (fr->fr_dev == lp) {
160 __skb_unlink(skb, list);
161 kfree_skb(skb);
162 }
163 }
164 spin_unlock_bh(&bg->fcoe_rx_list.lock);
165}
166
167int bnx2fc_get_paged_crc_eof(struct sk_buff *skb, int tlen)
168{
169 int rc;
170 spin_lock(&bnx2fc_global_lock);
171 rc = fcoe_get_paged_crc_eof(skb, tlen, &bnx2fc_global);
172 spin_unlock(&bnx2fc_global_lock);
173
174 return rc;
175}
176
177static void bnx2fc_abort_io(struct fc_lport *lport)
178{
179
180
181
182
183
184
185}
186
187static void bnx2fc_cleanup(struct fc_lport *lport)
188{
189 struct fcoe_port *port = lport_priv(lport);
190 struct bnx2fc_interface *interface = port->priv;
191 struct bnx2fc_hba *hba = interface->hba;
192 struct bnx2fc_rport *tgt;
193 int i;
194
195 BNX2FC_MISC_DBG("Entered %s\n", __func__);
196 mutex_lock(&hba->hba_mutex);
197 spin_lock_bh(&hba->hba_lock);
198 for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
199 tgt = hba->tgt_ofld_list[i];
200 if (tgt) {
201
202 if (tgt->port == port) {
203 spin_unlock_bh(&hba->hba_lock);
204 BNX2FC_TGT_DBG(tgt, "flush/cleanup\n");
205 bnx2fc_flush_active_ios(tgt);
206 spin_lock_bh(&hba->hba_lock);
207 }
208 }
209 }
210 spin_unlock_bh(&hba->hba_lock);
211 mutex_unlock(&hba->hba_mutex);
212}
213
214static int bnx2fc_xmit_l2_frame(struct bnx2fc_rport *tgt,
215 struct fc_frame *fp)
216{
217 struct fc_rport_priv *rdata = tgt->rdata;
218 struct fc_frame_header *fh;
219 int rc = 0;
220
221 fh = fc_frame_header_get(fp);
222 BNX2FC_TGT_DBG(tgt, "Xmit L2 frame rport = 0x%x, oxid = 0x%x, "
223 "r_ctl = 0x%x\n", rdata->ids.port_id,
224 ntohs(fh->fh_ox_id), fh->fh_r_ctl);
225 if ((fh->fh_type == FC_TYPE_ELS) &&
226 (fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
227
228 switch (fc_frame_payload_op(fp)) {
229 case ELS_ADISC:
230 rc = bnx2fc_send_adisc(tgt, fp);
231 break;
232 case ELS_LOGO:
233 rc = bnx2fc_send_logo(tgt, fp);
234 break;
235 case ELS_RLS:
236 rc = bnx2fc_send_rls(tgt, fp);
237 break;
238 default:
239 break;
240 }
241 } else if ((fh->fh_type == FC_TYPE_BLS) &&
242 (fh->fh_r_ctl == FC_RCTL_BA_ABTS))
243 BNX2FC_TGT_DBG(tgt, "ABTS frame\n");
244 else {
245 BNX2FC_TGT_DBG(tgt, "Send L2 frame type 0x%x "
246 "rctl 0x%x thru non-offload path\n",
247 fh->fh_type, fh->fh_r_ctl);
248 return -ENODEV;
249 }
250 if (rc)
251 return -ENOMEM;
252 else
253 return 0;
254}
255
256
257
258
259
260
261
262static int bnx2fc_xmit(struct fc_lport *lport, struct fc_frame *fp)
263{
264 struct ethhdr *eh;
265 struct fcoe_crc_eof *cp;
266 struct sk_buff *skb;
267 struct fc_frame_header *fh;
268 struct bnx2fc_interface *interface;
269 struct fcoe_ctlr *ctlr;
270 struct bnx2fc_hba *hba;
271 struct fcoe_port *port;
272 struct fcoe_hdr *hp;
273 struct bnx2fc_rport *tgt;
274 struct fc_stats *stats;
275 u8 sof, eof;
276 u32 crc;
277 unsigned int hlen, tlen, elen;
278 int wlen, rc = 0;
279
280 port = (struct fcoe_port *)lport_priv(lport);
281 interface = port->priv;
282 ctlr = bnx2fc_to_ctlr(interface);
283 hba = interface->hba;
284
285 fh = fc_frame_header_get(fp);
286
287 skb = fp_skb(fp);
288 if (!lport->link_up) {
289 BNX2FC_HBA_DBG(lport, "bnx2fc_xmit link down\n");
290 kfree_skb(skb);
291 return 0;
292 }
293
294 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
295 if (!ctlr->sel_fcf) {
296 BNX2FC_HBA_DBG(lport, "FCF not selected yet!\n");
297 kfree_skb(skb);
298 return -EINVAL;
299 }
300 if (fcoe_ctlr_els_send(ctlr, lport, skb))
301 return 0;
302 }
303
304 sof = fr_sof(fp);
305 eof = fr_eof(fp);
306
307
308
309
310
311
312
313
314
315
316
317 spin_lock_bh(&hba->hba_lock);
318 tgt = bnx2fc_tgt_lookup(port, ntoh24(fh->fh_d_id));
319 if (tgt && (test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags))) {
320
321 BNX2FC_HBA_DBG(lport, "xmit: Frame is for offloaded session "
322 "port_id = 0x%x\n", ntoh24(fh->fh_d_id));
323 spin_unlock_bh(&hba->hba_lock);
324 rc = bnx2fc_xmit_l2_frame(tgt, fp);
325 if (rc != -ENODEV) {
326 kfree_skb(skb);
327 return rc;
328 }
329 } else {
330 spin_unlock_bh(&hba->hba_lock);
331 }
332
333 elen = sizeof(struct ethhdr);
334 hlen = sizeof(struct fcoe_hdr);
335 tlen = sizeof(struct fcoe_crc_eof);
336 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
337
338 skb->ip_summed = CHECKSUM_NONE;
339 crc = fcoe_fc_crc(fp);
340
341
342 if (skb_is_nonlinear(skb)) {
343 skb_frag_t *frag;
344 if (bnx2fc_get_paged_crc_eof(skb, tlen)) {
345 kfree_skb(skb);
346 return -ENOMEM;
347 }
348 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
349 cp = kmap_atomic(skb_frag_page(frag)) + frag->page_offset;
350 } else {
351 cp = skb_put(skb, tlen);
352 }
353
354 memset(cp, 0, sizeof(*cp));
355 cp->fcoe_eof = eof;
356 cp->fcoe_crc32 = cpu_to_le32(~crc);
357 if (skb_is_nonlinear(skb)) {
358 kunmap_atomic(cp);
359 cp = NULL;
360 }
361
362
363 skb_push(skb, elen + hlen);
364 skb_reset_mac_header(skb);
365 skb_reset_network_header(skb);
366 skb->mac_len = elen;
367 skb->protocol = htons(ETH_P_FCOE);
368 skb->dev = interface->netdev;
369
370
371 eh = eth_hdr(skb);
372 eh->h_proto = htons(ETH_P_FCOE);
373 if (ctlr->map_dest)
374 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
375 else
376
377 memcpy(eh->h_dest, ctlr->dest_addr, ETH_ALEN);
378
379 if (unlikely(ctlr->flogi_oxid != FC_XID_UNKNOWN))
380 memcpy(eh->h_source, ctlr->ctl_src_addr, ETH_ALEN);
381 else
382 memcpy(eh->h_source, port->data_src_addr, ETH_ALEN);
383
384 hp = (struct fcoe_hdr *)(eh + 1);
385 memset(hp, 0, sizeof(*hp));
386 if (FC_FCOE_VER)
387 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
388 hp->fcoe_sof = sof;
389
390
391 if (lport->seq_offload && fr_max_payload(fp)) {
392 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
393 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
394 } else {
395 skb_shinfo(skb)->gso_type = 0;
396 skb_shinfo(skb)->gso_size = 0;
397 }
398
399
400 stats = per_cpu_ptr(lport->stats, get_cpu());
401 stats->TxFrames++;
402 stats->TxWords += wlen;
403 put_cpu();
404
405
406 fr_dev(fp) = lport;
407 if (port->fcoe_pending_queue.qlen)
408 fcoe_check_wait_queue(lport, skb);
409 else if (fcoe_start_io(skb))
410 fcoe_check_wait_queue(lport, skb);
411
412 return 0;
413}
414
415
416
417
418
419
420
421
422
423
424
425static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
426 struct packet_type *ptype, struct net_device *olddev)
427{
428 struct fc_lport *lport;
429 struct bnx2fc_interface *interface;
430 struct fcoe_ctlr *ctlr;
431 struct fc_frame_header *fh;
432 struct fcoe_rcv_info *fr;
433 struct fcoe_percpu_s *bg;
434 struct sk_buff *tmp_skb;
435
436 interface = container_of(ptype, struct bnx2fc_interface,
437 fcoe_packet_type);
438 ctlr = bnx2fc_to_ctlr(interface);
439 lport = ctlr->lp;
440
441 if (unlikely(lport == NULL)) {
442 printk(KERN_ERR PFX "bnx2fc_rcv: lport is NULL\n");
443 goto err;
444 }
445
446 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
447 if (!tmp_skb)
448 goto err;
449
450 skb = tmp_skb;
451
452 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
453 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
454 goto err;
455 }
456
457
458
459
460
461 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
462 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
463 goto err;
464
465 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
466 fh = (struct fc_frame_header *) skb_transport_header(skb);
467
468 fr = fcoe_dev_from_skb(skb);
469 fr->fr_dev = lport;
470
471 bg = &bnx2fc_global;
472 spin_lock(&bg->fcoe_rx_list.lock);
473
474 __skb_queue_tail(&bg->fcoe_rx_list, skb);
475 if (bg->fcoe_rx_list.qlen == 1)
476 wake_up_process(bg->kthread);
477
478 spin_unlock(&bg->fcoe_rx_list.lock);
479
480 return 0;
481err:
482 kfree_skb(skb);
483 return -1;
484}
485
486static int bnx2fc_l2_rcv_thread(void *arg)
487{
488 struct fcoe_percpu_s *bg = arg;
489 struct sk_buff *skb;
490
491 set_user_nice(current, MIN_NICE);
492 set_current_state(TASK_INTERRUPTIBLE);
493 while (!kthread_should_stop()) {
494 schedule();
495 spin_lock_bh(&bg->fcoe_rx_list.lock);
496 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL) {
497 spin_unlock_bh(&bg->fcoe_rx_list.lock);
498 bnx2fc_recv_frame(skb);
499 spin_lock_bh(&bg->fcoe_rx_list.lock);
500 }
501 __set_current_state(TASK_INTERRUPTIBLE);
502 spin_unlock_bh(&bg->fcoe_rx_list.lock);
503 }
504 __set_current_state(TASK_RUNNING);
505 return 0;
506}
507
508
509static void bnx2fc_recv_frame(struct sk_buff *skb)
510{
511 u32 fr_len;
512 struct fc_lport *lport;
513 struct fcoe_rcv_info *fr;
514 struct fc_stats *stats;
515 struct fc_frame_header *fh;
516 struct fcoe_crc_eof crc_eof;
517 struct fc_frame *fp;
518 struct fc_lport *vn_port;
519 struct fcoe_port *port, *phys_port;
520 u8 *mac = NULL;
521 u8 *dest_mac = NULL;
522 struct fcoe_hdr *hp;
523 struct bnx2fc_interface *interface;
524 struct fcoe_ctlr *ctlr;
525
526 fr = fcoe_dev_from_skb(skb);
527 lport = fr->fr_dev;
528 if (unlikely(lport == NULL)) {
529 printk(KERN_ERR PFX "Invalid lport struct\n");
530 kfree_skb(skb);
531 return;
532 }
533
534 if (skb_is_nonlinear(skb))
535 skb_linearize(skb);
536 mac = eth_hdr(skb)->h_source;
537 dest_mac = eth_hdr(skb)->h_dest;
538
539
540 hp = (struct fcoe_hdr *) skb_network_header(skb);
541 fh = (struct fc_frame_header *) skb_transport_header(skb);
542 skb_pull(skb, sizeof(struct fcoe_hdr));
543 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
544
545 fp = (struct fc_frame *)skb;
546 fc_frame_init(fp);
547 fr_dev(fp) = lport;
548 fr_sof(fp) = hp->fcoe_sof;
549 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
550 kfree_skb(skb);
551 return;
552 }
553 fr_eof(fp) = crc_eof.fcoe_eof;
554 fr_crc(fp) = crc_eof.fcoe_crc32;
555 if (pskb_trim(skb, fr_len)) {
556 kfree_skb(skb);
557 return;
558 }
559
560 phys_port = lport_priv(lport);
561 interface = phys_port->priv;
562 ctlr = bnx2fc_to_ctlr(interface);
563
564 fh = fc_frame_header_get(fp);
565
566 if (ntoh24(&dest_mac[3]) != ntoh24(fh->fh_d_id)) {
567 BNX2FC_HBA_DBG(lport, "FC frame d_id mismatch with MAC %pM.\n",
568 dest_mac);
569 kfree_skb(skb);
570 return;
571 }
572
573 vn_port = fc_vport_id_lookup(lport, ntoh24(fh->fh_d_id));
574 if (vn_port) {
575 port = lport_priv(vn_port);
576 if (!ether_addr_equal(port->data_src_addr, dest_mac)) {
577 BNX2FC_HBA_DBG(lport, "fpma mismatch\n");
578 kfree_skb(skb);
579 return;
580 }
581 }
582 if (ctlr->state) {
583 if (!ether_addr_equal(mac, ctlr->dest_addr)) {
584 BNX2FC_HBA_DBG(lport, "Wrong source address: mac:%pM dest_addr:%pM.\n",
585 mac, ctlr->dest_addr);
586 kfree_skb(skb);
587 return;
588 }
589 }
590 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
591 fh->fh_type == FC_TYPE_FCP) {
592
593 kfree_skb(skb);
594 return;
595 }
596 if (fh->fh_r_ctl == FC_RCTL_ELS_REQ &&
597 fh->fh_type == FC_TYPE_ELS) {
598 switch (fc_frame_payload_op(fp)) {
599 case ELS_LOGO:
600 if (ntoh24(fh->fh_s_id) == FC_FID_FLOGI) {
601
602 kfree_skb(skb);
603 return;
604 }
605 break;
606 }
607 }
608
609 if (fh->fh_r_ctl == FC_RCTL_BA_ABTS) {
610
611 kfree_skb(skb);
612 return;
613 }
614
615
616
617
618
619
620 if (lport->port_id != ntoh24(fh->fh_d_id) && !vn_port) {
621 BNX2FC_HBA_DBG(lport, "Dropping frame due to destination mismatch: lport->port_id=%x fh->d_id=%x.\n",
622 lport->port_id, ntoh24(fh->fh_d_id));
623 kfree_skb(skb);
624 return;
625 }
626
627 stats = per_cpu_ptr(lport->stats, smp_processor_id());
628 stats->RxFrames++;
629 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
630
631 if (le32_to_cpu(fr_crc(fp)) !=
632 ~crc32(~0, skb->data, fr_len)) {
633 if (stats->InvalidCRCCount < 5)
634 printk(KERN_WARNING PFX "dropping frame with "
635 "CRC error\n");
636 stats->InvalidCRCCount++;
637 kfree_skb(skb);
638 return;
639 }
640 fc_exch_recv(lport, fp);
641}
642
643
644
645
646
647
648static int bnx2fc_percpu_io_thread(void *arg)
649{
650 struct bnx2fc_percpu_s *p = arg;
651 struct bnx2fc_work *work, *tmp;
652 LIST_HEAD(work_list);
653
654 set_user_nice(current, MIN_NICE);
655 set_current_state(TASK_INTERRUPTIBLE);
656 while (!kthread_should_stop()) {
657 schedule();
658 spin_lock_bh(&p->fp_work_lock);
659 while (!list_empty(&p->work_list)) {
660 list_splice_init(&p->work_list, &work_list);
661 spin_unlock_bh(&p->fp_work_lock);
662
663 list_for_each_entry_safe(work, tmp, &work_list, list) {
664 list_del_init(&work->list);
665 bnx2fc_process_cq_compl(work->tgt, work->wqe);
666 kfree(work);
667 }
668
669 spin_lock_bh(&p->fp_work_lock);
670 }
671 __set_current_state(TASK_INTERRUPTIBLE);
672 spin_unlock_bh(&p->fp_work_lock);
673 }
674 __set_current_state(TASK_RUNNING);
675
676 return 0;
677}
678
679static struct fc_host_statistics *bnx2fc_get_host_stats(struct Scsi_Host *shost)
680{
681 struct fc_host_statistics *bnx2fc_stats;
682 struct fc_lport *lport = shost_priv(shost);
683 struct fcoe_port *port = lport_priv(lport);
684 struct bnx2fc_interface *interface = port->priv;
685 struct bnx2fc_hba *hba = interface->hba;
686 struct fcoe_statistics_params *fw_stats;
687 int rc = 0;
688
689 fw_stats = (struct fcoe_statistics_params *)hba->stats_buffer;
690 if (!fw_stats)
691 return NULL;
692
693 mutex_lock(&hba->hba_stats_mutex);
694
695 bnx2fc_stats = fc_get_host_stats(shost);
696
697 init_completion(&hba->stat_req_done);
698 if (bnx2fc_send_stat_req(hba))
699 goto unlock_stats_mutex;
700 rc = wait_for_completion_timeout(&hba->stat_req_done, (2 * HZ));
701 if (!rc) {
702 BNX2FC_HBA_DBG(lport, "FW stat req timed out\n");
703 goto unlock_stats_mutex;
704 }
705 BNX2FC_STATS(hba, rx_stat2, fc_crc_cnt);
706 bnx2fc_stats->invalid_crc_count += hba->bfw_stats.fc_crc_cnt;
707 BNX2FC_STATS(hba, tx_stat, fcoe_tx_pkt_cnt);
708 bnx2fc_stats->tx_frames += hba->bfw_stats.fcoe_tx_pkt_cnt;
709 BNX2FC_STATS(hba, tx_stat, fcoe_tx_byte_cnt);
710 bnx2fc_stats->tx_words += ((hba->bfw_stats.fcoe_tx_byte_cnt) / 4);
711 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_pkt_cnt);
712 bnx2fc_stats->rx_frames += hba->bfw_stats.fcoe_rx_pkt_cnt;
713 BNX2FC_STATS(hba, rx_stat0, fcoe_rx_byte_cnt);
714 bnx2fc_stats->rx_words += ((hba->bfw_stats.fcoe_rx_byte_cnt) / 4);
715
716 bnx2fc_stats->dumped_frames = 0;
717 bnx2fc_stats->lip_count = 0;
718 bnx2fc_stats->nos_count = 0;
719 bnx2fc_stats->loss_of_sync_count = 0;
720 bnx2fc_stats->loss_of_signal_count = 0;
721 bnx2fc_stats->prim_seq_protocol_err_count = 0;
722
723 memcpy(&hba->prev_stats, hba->stats_buffer,
724 sizeof(struct fcoe_statistics_params));
725
726unlock_stats_mutex:
727 mutex_unlock(&hba->hba_stats_mutex);
728 return bnx2fc_stats;
729}
730
731static int bnx2fc_shost_config(struct fc_lport *lport, struct device *dev)
732{
733 struct fcoe_port *port = lport_priv(lport);
734 struct bnx2fc_interface *interface = port->priv;
735 struct bnx2fc_hba *hba = interface->hba;
736 struct Scsi_Host *shost = lport->host;
737 int rc = 0;
738
739 shost->max_cmd_len = BNX2FC_MAX_CMD_LEN;
740 shost->max_lun = bnx2fc_max_luns;
741 shost->max_id = BNX2FC_MAX_FCP_TGT;
742 shost->max_channel = 0;
743 if (lport->vport)
744 shost->transportt = bnx2fc_vport_xport_template;
745 else
746 shost->transportt = bnx2fc_transport_template;
747
748
749 rc = scsi_add_host(lport->host, dev);
750 if (rc) {
751 printk(KERN_ERR PFX "Error on scsi_add_host\n");
752 return rc;
753 }
754 if (!lport->vport)
755 fc_host_max_npiv_vports(lport->host) = USHRT_MAX;
756 snprintf(fc_host_symbolic_name(lport->host), 256,
757 "%s (QLogic %s) v%s over %s",
758 BNX2FC_NAME, hba->chip_num, BNX2FC_VERSION,
759 interface->netdev->name);
760
761 return 0;
762}
763
764static int bnx2fc_link_ok(struct fc_lport *lport)
765{
766 struct fcoe_port *port = lport_priv(lport);
767 struct bnx2fc_interface *interface = port->priv;
768 struct bnx2fc_hba *hba = interface->hba;
769 struct net_device *dev = hba->phys_dev;
770 int rc = 0;
771
772 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev))
773 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
774 else {
775 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
776 rc = -1;
777 }
778 return rc;
779}
780
781
782
783
784
785
786
787
788void bnx2fc_get_link_state(struct bnx2fc_hba *hba)
789{
790 if (test_bit(__LINK_STATE_NOCARRIER, &hba->phys_dev->state))
791 set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
792 else
793 clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
794}
795
796static int bnx2fc_net_config(struct fc_lport *lport, struct net_device *netdev)
797{
798 struct bnx2fc_hba *hba;
799 struct bnx2fc_interface *interface;
800 struct fcoe_ctlr *ctlr;
801 struct fcoe_port *port;
802 u64 wwnn, wwpn;
803
804 port = lport_priv(lport);
805 interface = port->priv;
806 ctlr = bnx2fc_to_ctlr(interface);
807 hba = interface->hba;
808
809
810 if (!hba->phys_dev->ethtool_ops ||
811 !hba->phys_dev->ethtool_ops->get_pauseparam)
812 return -EOPNOTSUPP;
813
814 if (fc_set_mfs(lport, BNX2FC_MFS))
815 return -EINVAL;
816
817 skb_queue_head_init(&port->fcoe_pending_queue);
818 port->fcoe_pending_queue_active = 0;
819 timer_setup(&port->timer, fcoe_queue_timer, 0);
820
821 fcoe_link_speed_update(lport);
822
823 if (!lport->vport) {
824 if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN))
825 wwnn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
826 1, 0);
827 BNX2FC_HBA_DBG(lport, "WWNN = 0x%llx\n", wwnn);
828 fc_set_wwnn(lport, wwnn);
829
830 if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN))
831 wwpn = fcoe_wwn_from_mac(ctlr->ctl_src_addr,
832 2, 0);
833
834 BNX2FC_HBA_DBG(lport, "WWPN = 0x%llx\n", wwpn);
835 fc_set_wwpn(lport, wwpn);
836 }
837
838 return 0;
839}
840
841static void bnx2fc_destroy_timer(struct timer_list *t)
842{
843 struct bnx2fc_hba *hba = from_timer(hba, t, destroy_timer);
844
845 printk(KERN_ERR PFX "ERROR:bnx2fc_destroy_timer - "
846 "Destroy compl not received!!\n");
847 set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
848 wake_up_interruptible(&hba->destroy_wait);
849}
850
851
852
853
854
855
856
857
858
859
860
861static void bnx2fc_indicate_netevent(void *context, unsigned long event,
862 u16 vlan_id)
863{
864 struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
865 struct fcoe_ctlr_device *cdev;
866 struct fc_lport *lport;
867 struct fc_lport *vport;
868 struct bnx2fc_interface *interface, *tmp;
869 struct fcoe_ctlr *ctlr;
870 int wait_for_upload = 0;
871 u32 link_possible = 1;
872
873 if (vlan_id != 0 && event != NETDEV_UNREGISTER)
874 return;
875
876 switch (event) {
877 case NETDEV_UP:
878 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
879 printk(KERN_ERR "indicate_netevent: "\
880 "hba is not UP!!\n");
881 break;
882
883 case NETDEV_DOWN:
884 clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
885 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
886 link_possible = 0;
887 break;
888
889 case NETDEV_GOING_DOWN:
890 set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
891 link_possible = 0;
892 break;
893
894 case NETDEV_CHANGE:
895 break;
896
897 case NETDEV_UNREGISTER:
898 if (!vlan_id)
899 return;
900 mutex_lock(&bnx2fc_dev_lock);
901 list_for_each_entry_safe(interface, tmp, &if_list, list) {
902 if (interface->hba == hba &&
903 interface->vlan_id == (vlan_id & VLAN_VID_MASK))
904 __bnx2fc_destroy(interface);
905 }
906 mutex_unlock(&bnx2fc_dev_lock);
907
908
909 flush_workqueue(bnx2fc_wq);
910 return;
911
912 default:
913 return;
914 }
915
916 mutex_lock(&bnx2fc_dev_lock);
917 list_for_each_entry(interface, &if_list, list) {
918
919 if (interface->hba != hba)
920 continue;
921
922 ctlr = bnx2fc_to_ctlr(interface);
923 lport = ctlr->lp;
924 BNX2FC_HBA_DBG(lport, "netevent handler - event=%s %ld\n",
925 interface->netdev->name, event);
926
927 fcoe_link_speed_update(lport);
928
929 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
930
931 if (link_possible && !bnx2fc_link_ok(lport)) {
932 switch (cdev->enabled) {
933 case FCOE_CTLR_DISABLED:
934 pr_info("Link up while interface is disabled.\n");
935 break;
936 case FCOE_CTLR_ENABLED:
937 case FCOE_CTLR_UNUSED:
938
939 fc_set_mfs(lport, BNX2FC_MFS);
940
941
942
943
944
945 if (interface->enabled)
946 fcoe_ctlr_link_up(ctlr);
947 };
948 } else if (fcoe_ctlr_link_down(ctlr)) {
949 switch (cdev->enabled) {
950 case FCOE_CTLR_DISABLED:
951 pr_info("Link down while interface is disabled.\n");
952 break;
953 case FCOE_CTLR_ENABLED:
954 case FCOE_CTLR_UNUSED:
955 mutex_lock(&lport->lp_mutex);
956 list_for_each_entry(vport, &lport->vports, list)
957 fc_host_port_type(vport->host) =
958 FC_PORTTYPE_UNKNOWN;
959 mutex_unlock(&lport->lp_mutex);
960 fc_host_port_type(lport->host) =
961 FC_PORTTYPE_UNKNOWN;
962 per_cpu_ptr(lport->stats,
963 get_cpu())->LinkFailureCount++;
964 put_cpu();
965 fcoe_clean_pending_queue(lport);
966 wait_for_upload = 1;
967 };
968 }
969 }
970 mutex_unlock(&bnx2fc_dev_lock);
971
972 if (wait_for_upload) {
973 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
974 init_waitqueue_head(&hba->shutdown_wait);
975 BNX2FC_MISC_DBG("indicate_netevent "
976 "num_ofld_sess = %d\n",
977 hba->num_ofld_sess);
978 hba->wait_for_link_down = 1;
979 wait_event_interruptible(hba->shutdown_wait,
980 (hba->num_ofld_sess == 0));
981 BNX2FC_MISC_DBG("wakeup - num_ofld_sess = %d\n",
982 hba->num_ofld_sess);
983 hba->wait_for_link_down = 0;
984
985 if (signal_pending(current))
986 flush_signals(current);
987 }
988}
989
990static int bnx2fc_libfc_config(struct fc_lport *lport)
991{
992
993
994 memcpy(&lport->tt, &bnx2fc_libfc_fcn_templ,
995 sizeof(struct libfc_function_template));
996 fc_elsct_init(lport);
997 fc_exch_init(lport);
998 fc_disc_init(lport);
999 fc_disc_config(lport, lport);
1000 return 0;
1001}
1002
1003static int bnx2fc_em_config(struct fc_lport *lport, struct bnx2fc_hba *hba)
1004{
1005 int fcoe_min_xid, fcoe_max_xid;
1006
1007 fcoe_min_xid = hba->max_xid + 1;
1008 if (nr_cpu_ids <= 2)
1009 fcoe_max_xid = hba->max_xid + FCOE_XIDS_PER_CPU_OFFSET;
1010 else
1011 fcoe_max_xid = hba->max_xid + FCOE_MAX_XID_OFFSET;
1012 if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, fcoe_min_xid,
1013 fcoe_max_xid, NULL)) {
1014 printk(KERN_ERR PFX "em_config:fc_exch_mgr_alloc failed\n");
1015 return -ENOMEM;
1016 }
1017
1018 return 0;
1019}
1020
1021static int bnx2fc_lport_config(struct fc_lport *lport)
1022{
1023 lport->link_up = 0;
1024 lport->qfull = 0;
1025 lport->max_retry_count = BNX2FC_MAX_RETRY_CNT;
1026 lport->max_rport_retry_count = BNX2FC_MAX_RPORT_RETRY_CNT;
1027 lport->e_d_tov = 2 * 1000;
1028 lport->r_a_tov = 10 * 1000;
1029
1030 lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
1031 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
1032 lport->does_npiv = 1;
1033
1034 memset(&lport->rnid_gen, 0, sizeof(struct fc_els_rnid_gen));
1035 lport->rnid_gen.rnid_atype = BNX2FC_RNID_HBA;
1036
1037
1038 if (fc_lport_init_stats(lport))
1039 return -ENOMEM;
1040
1041
1042 fc_lport_config(lport);
1043
1044 return 0;
1045}
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057static int bnx2fc_fip_recv(struct sk_buff *skb, struct net_device *dev,
1058 struct packet_type *ptype,
1059 struct net_device *orig_dev)
1060{
1061 struct bnx2fc_interface *interface;
1062 struct fcoe_ctlr *ctlr;
1063 interface = container_of(ptype, struct bnx2fc_interface,
1064 fip_packet_type);
1065 ctlr = bnx2fc_to_ctlr(interface);
1066 fcoe_ctlr_recv(ctlr, skb);
1067 return 0;
1068}
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080static void bnx2fc_update_src_mac(struct fc_lport *lport, u8 *addr)
1081{
1082 struct fcoe_port *port = lport_priv(lport);
1083
1084 memcpy(port->data_src_addr, addr, ETH_ALEN);
1085}
1086
1087
1088
1089
1090
1091
1092static u8 *bnx2fc_get_src_mac(struct fc_lport *lport)
1093{
1094 struct fcoe_port *port;
1095
1096 port = (struct fcoe_port *)lport_priv(lport);
1097 return port->data_src_addr;
1098}
1099
1100
1101
1102
1103
1104
1105
1106static void bnx2fc_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
1107{
1108 struct fip_header *fiph;
1109 struct ethhdr *eth_hdr;
1110 u16 op;
1111 u8 sub;
1112
1113 fiph = (struct fip_header *) ((void *)skb->data + 2 * ETH_ALEN + 2);
1114 eth_hdr = (struct ethhdr *)skb_mac_header(skb);
1115 op = ntohs(fiph->fip_op);
1116 sub = fiph->fip_subcode;
1117
1118 if (op == FIP_OP_CTRL && sub == FIP_SC_SOL && bnx2fc_log_fka)
1119 BNX2FC_MISC_DBG("Sending FKA from %pM to %pM.\n",
1120 eth_hdr->h_source, eth_hdr->h_dest);
1121
1122 skb->dev = bnx2fc_from_ctlr(fip)->netdev;
1123 dev_queue_xmit(skb);
1124}
1125
1126static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1127{
1128 struct Scsi_Host *shost = vport_to_shost(vport);
1129 struct fc_lport *n_port = shost_priv(shost);
1130 struct fcoe_port *port = lport_priv(n_port);
1131 struct bnx2fc_interface *interface = port->priv;
1132 struct net_device *netdev = interface->netdev;
1133 struct fc_lport *vn_port;
1134 int rc;
1135 char buf[32];
1136
1137 rc = fcoe_validate_vport_create(vport);
1138 if (rc) {
1139 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
1140 printk(KERN_ERR PFX "Failed to create vport, "
1141 "WWPN (0x%s) already exists\n",
1142 buf);
1143 return rc;
1144 }
1145
1146 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
1147 printk(KERN_ERR PFX "vn ports cannot be created on"
1148 "this interface\n");
1149 return -EIO;
1150 }
1151 rtnl_lock();
1152 mutex_lock(&bnx2fc_dev_lock);
1153 vn_port = bnx2fc_if_create(interface, &vport->dev, 1);
1154 mutex_unlock(&bnx2fc_dev_lock);
1155 rtnl_unlock();
1156
1157 if (!vn_port) {
1158 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1159 netdev->name);
1160 return -EIO;
1161 }
1162
1163 if (bnx2fc_devloss_tmo)
1164 fc_host_dev_loss_tmo(vn_port->host) = bnx2fc_devloss_tmo;
1165
1166 if (disabled) {
1167 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1168 } else {
1169 vn_port->boot_time = jiffies;
1170 fc_lport_init(vn_port);
1171 fc_fabric_login(vn_port);
1172 fc_vport_setlink(vn_port);
1173 }
1174 return 0;
1175}
1176
1177static void bnx2fc_free_vport(struct bnx2fc_hba *hba, struct fc_lport *lport)
1178{
1179 struct bnx2fc_lport *blport, *tmp;
1180
1181 spin_lock_bh(&hba->hba_lock);
1182 list_for_each_entry_safe(blport, tmp, &hba->vports, list) {
1183 if (blport->lport == lport) {
1184 list_del(&blport->list);
1185 kfree(blport);
1186 }
1187 }
1188 spin_unlock_bh(&hba->hba_lock);
1189}
1190
1191static int bnx2fc_vport_destroy(struct fc_vport *vport)
1192{
1193 struct Scsi_Host *shost = vport_to_shost(vport);
1194 struct fc_lport *n_port = shost_priv(shost);
1195 struct fc_lport *vn_port = vport->dd_data;
1196 struct fcoe_port *port = lport_priv(vn_port);
1197 struct bnx2fc_interface *interface = port->priv;
1198 struct fc_lport *v_port;
1199 bool found = false;
1200
1201 mutex_lock(&n_port->lp_mutex);
1202 list_for_each_entry(v_port, &n_port->vports, list)
1203 if (v_port->vport == vport) {
1204 found = true;
1205 break;
1206 }
1207
1208 if (!found) {
1209 mutex_unlock(&n_port->lp_mutex);
1210 return -ENOENT;
1211 }
1212 list_del(&vn_port->list);
1213 mutex_unlock(&n_port->lp_mutex);
1214 bnx2fc_free_vport(interface->hba, port->lport);
1215 bnx2fc_port_shutdown(port->lport);
1216 bnx2fc_interface_put(interface);
1217 queue_work(bnx2fc_wq, &port->destroy_work);
1218 return 0;
1219}
1220
1221static int bnx2fc_vport_disable(struct fc_vport *vport, bool disable)
1222{
1223 struct fc_lport *lport = vport->dd_data;
1224
1225 if (disable) {
1226 fc_vport_set_state(vport, FC_VPORT_DISABLED);
1227 fc_fabric_logoff(lport);
1228 } else {
1229 lport->boot_time = jiffies;
1230 fc_fabric_login(lport);
1231 fc_vport_setlink(lport);
1232 }
1233 return 0;
1234}
1235
1236
1237static int bnx2fc_interface_setup(struct bnx2fc_interface *interface)
1238{
1239 struct net_device *netdev = interface->netdev;
1240 struct net_device *physdev = interface->hba->phys_dev;
1241 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1242 struct netdev_hw_addr *ha;
1243 int sel_san_mac = 0;
1244
1245
1246 rcu_read_lock();
1247 for_each_dev_addr(physdev, ha) {
1248 BNX2FC_MISC_DBG("net_config: ha->type = %d, fip_mac = ",
1249 ha->type);
1250 printk(KERN_INFO "%2x:%2x:%2x:%2x:%2x:%2x\n", ha->addr[0],
1251 ha->addr[1], ha->addr[2], ha->addr[3],
1252 ha->addr[4], ha->addr[5]);
1253
1254 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
1255 (is_valid_ether_addr(ha->addr))) {
1256 memcpy(ctlr->ctl_src_addr, ha->addr,
1257 ETH_ALEN);
1258 sel_san_mac = 1;
1259 BNX2FC_MISC_DBG("Found SAN MAC\n");
1260 }
1261 }
1262 rcu_read_unlock();
1263
1264 if (!sel_san_mac)
1265 return -ENODEV;
1266
1267 interface->fip_packet_type.func = bnx2fc_fip_recv;
1268 interface->fip_packet_type.type = htons(ETH_P_FIP);
1269 interface->fip_packet_type.dev = netdev;
1270 dev_add_pack(&interface->fip_packet_type);
1271
1272 interface->fcoe_packet_type.func = bnx2fc_rcv;
1273 interface->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
1274 interface->fcoe_packet_type.dev = netdev;
1275 dev_add_pack(&interface->fcoe_packet_type);
1276
1277 return 0;
1278}
1279
1280static int bnx2fc_attach_transport(void)
1281{
1282 bnx2fc_transport_template =
1283 fc_attach_transport(&bnx2fc_transport_function);
1284
1285 if (bnx2fc_transport_template == NULL) {
1286 printk(KERN_ERR PFX "Failed to attach FC transport\n");
1287 return -ENODEV;
1288 }
1289
1290 bnx2fc_vport_xport_template =
1291 fc_attach_transport(&bnx2fc_vport_xport_function);
1292 if (bnx2fc_vport_xport_template == NULL) {
1293 printk(KERN_ERR PFX
1294 "Failed to attach FC transport for vport\n");
1295 fc_release_transport(bnx2fc_transport_template);
1296 bnx2fc_transport_template = NULL;
1297 return -ENODEV;
1298 }
1299 return 0;
1300}
1301static void bnx2fc_release_transport(void)
1302{
1303 fc_release_transport(bnx2fc_transport_template);
1304 fc_release_transport(bnx2fc_vport_xport_template);
1305 bnx2fc_transport_template = NULL;
1306 bnx2fc_vport_xport_template = NULL;
1307}
1308
1309static void bnx2fc_interface_release(struct kref *kref)
1310{
1311 struct fcoe_ctlr_device *ctlr_dev;
1312 struct bnx2fc_interface *interface;
1313 struct fcoe_ctlr *ctlr;
1314 struct net_device *netdev;
1315
1316 interface = container_of(kref, struct bnx2fc_interface, kref);
1317 BNX2FC_MISC_DBG("Interface is being released\n");
1318
1319 ctlr = bnx2fc_to_ctlr(interface);
1320 ctlr_dev = fcoe_ctlr_to_ctlr_dev(ctlr);
1321 netdev = interface->netdev;
1322
1323
1324 if (test_and_clear_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags))
1325 fcoe_ctlr_destroy(ctlr);
1326
1327 fcoe_ctlr_device_delete(ctlr_dev);
1328
1329 dev_put(netdev);
1330 module_put(THIS_MODULE);
1331}
1332
1333static inline void bnx2fc_interface_get(struct bnx2fc_interface *interface)
1334{
1335 kref_get(&interface->kref);
1336}
1337
1338static inline void bnx2fc_interface_put(struct bnx2fc_interface *interface)
1339{
1340 kref_put(&interface->kref, bnx2fc_interface_release);
1341}
1342static void bnx2fc_hba_destroy(struct bnx2fc_hba *hba)
1343{
1344
1345 if (hba->cmd_mgr) {
1346 bnx2fc_cmd_mgr_free(hba->cmd_mgr);
1347 hba->cmd_mgr = NULL;
1348 }
1349 kfree(hba->tgt_ofld_list);
1350 bnx2fc_unbind_pcidev(hba);
1351 kfree(hba);
1352}
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362static struct bnx2fc_hba *bnx2fc_hba_create(struct cnic_dev *cnic)
1363{
1364 struct bnx2fc_hba *hba;
1365 struct fcoe_capabilities *fcoe_cap;
1366 int rc;
1367
1368 hba = kzalloc(sizeof(*hba), GFP_KERNEL);
1369 if (!hba) {
1370 printk(KERN_ERR PFX "Unable to allocate hba structure\n");
1371 return NULL;
1372 }
1373 spin_lock_init(&hba->hba_lock);
1374 mutex_init(&hba->hba_mutex);
1375 mutex_init(&hba->hba_stats_mutex);
1376
1377 hba->cnic = cnic;
1378
1379 hba->max_tasks = cnic->max_fcoe_exchanges;
1380 hba->elstm_xids = (hba->max_tasks / 2);
1381 hba->max_outstanding_cmds = hba->elstm_xids;
1382 hba->max_xid = (hba->max_tasks - 1);
1383
1384 rc = bnx2fc_bind_pcidev(hba);
1385 if (rc) {
1386 printk(KERN_ERR PFX "create_adapter: bind error\n");
1387 goto bind_err;
1388 }
1389 hba->phys_dev = cnic->netdev;
1390 hba->next_conn_id = 0;
1391
1392 hba->tgt_ofld_list =
1393 kcalloc(BNX2FC_NUM_MAX_SESS, sizeof(struct bnx2fc_rport *),
1394 GFP_KERNEL);
1395 if (!hba->tgt_ofld_list) {
1396 printk(KERN_ERR PFX "Unable to allocate tgt offload list\n");
1397 goto tgtofld_err;
1398 }
1399
1400 hba->num_ofld_sess = 0;
1401
1402 hba->cmd_mgr = bnx2fc_cmd_mgr_alloc(hba);
1403 if (!hba->cmd_mgr) {
1404 printk(KERN_ERR PFX "em_config:bnx2fc_cmd_mgr_alloc failed\n");
1405 goto cmgr_err;
1406 }
1407 fcoe_cap = &hba->fcoe_cap;
1408
1409 fcoe_cap->capability1 = BNX2FC_TM_MAX_SQES <<
1410 FCOE_IOS_PER_CONNECTION_SHIFT;
1411 fcoe_cap->capability1 |= BNX2FC_NUM_MAX_SESS <<
1412 FCOE_LOGINS_PER_PORT_SHIFT;
1413 fcoe_cap->capability2 = hba->max_outstanding_cmds <<
1414 FCOE_NUMBER_OF_EXCHANGES_SHIFT;
1415 fcoe_cap->capability2 |= BNX2FC_MAX_NPIV <<
1416 FCOE_NPIV_WWN_PER_PORT_SHIFT;
1417 fcoe_cap->capability3 = BNX2FC_NUM_MAX_SESS <<
1418 FCOE_TARGETS_SUPPORTED_SHIFT;
1419 fcoe_cap->capability3 |= hba->max_outstanding_cmds <<
1420 FCOE_OUTSTANDING_COMMANDS_SHIFT;
1421 fcoe_cap->capability4 = FCOE_CAPABILITY4_STATEFUL;
1422
1423 init_waitqueue_head(&hba->shutdown_wait);
1424 init_waitqueue_head(&hba->destroy_wait);
1425 INIT_LIST_HEAD(&hba->vports);
1426
1427 return hba;
1428
1429cmgr_err:
1430 kfree(hba->tgt_ofld_list);
1431tgtofld_err:
1432 bnx2fc_unbind_pcidev(hba);
1433bind_err:
1434 kfree(hba);
1435 return NULL;
1436}
1437
1438static struct bnx2fc_interface *
1439bnx2fc_interface_create(struct bnx2fc_hba *hba,
1440 struct net_device *netdev,
1441 enum fip_mode fip_mode)
1442{
1443 struct fcoe_ctlr_device *ctlr_dev;
1444 struct bnx2fc_interface *interface;
1445 struct fcoe_ctlr *ctlr;
1446 int size;
1447 int rc = 0;
1448
1449 size = (sizeof(*interface) + sizeof(struct fcoe_ctlr));
1450 ctlr_dev = fcoe_ctlr_device_add(&netdev->dev, &bnx2fc_fcoe_sysfs_templ,
1451 size);
1452 if (!ctlr_dev) {
1453 printk(KERN_ERR PFX "Unable to allocate interface structure\n");
1454 return NULL;
1455 }
1456 ctlr = fcoe_ctlr_device_priv(ctlr_dev);
1457 ctlr->cdev = ctlr_dev;
1458 interface = fcoe_ctlr_priv(ctlr);
1459 dev_hold(netdev);
1460 kref_init(&interface->kref);
1461 interface->hba = hba;
1462 interface->netdev = netdev;
1463
1464
1465 fcoe_ctlr_init(ctlr, fip_mode);
1466 ctlr->send = bnx2fc_fip_send;
1467 ctlr->update_mac = bnx2fc_update_src_mac;
1468 ctlr->get_src_addr = bnx2fc_get_src_mac;
1469 set_bit(BNX2FC_CTLR_INIT_DONE, &interface->if_flags);
1470
1471 rc = bnx2fc_interface_setup(interface);
1472 if (!rc)
1473 return interface;
1474
1475 fcoe_ctlr_destroy(ctlr);
1476 dev_put(netdev);
1477 fcoe_ctlr_device_delete(ctlr_dev);
1478 return NULL;
1479}
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492static struct fc_lport *bnx2fc_if_create(struct bnx2fc_interface *interface,
1493 struct device *parent, int npiv)
1494{
1495 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1496 struct fc_lport *lport, *n_port;
1497 struct fcoe_port *port;
1498 struct Scsi_Host *shost;
1499 struct fc_vport *vport = dev_to_vport(parent);
1500 struct bnx2fc_lport *blport;
1501 struct bnx2fc_hba *hba = interface->hba;
1502 int rc = 0;
1503
1504 blport = kzalloc(sizeof(struct bnx2fc_lport), GFP_KERNEL);
1505 if (!blport) {
1506 BNX2FC_HBA_DBG(ctlr->lp, "Unable to alloc blport\n");
1507 return NULL;
1508 }
1509
1510
1511 bnx2fc_shost_template.can_queue = hba->max_outstanding_cmds;
1512 if (!npiv)
1513 lport = libfc_host_alloc(&bnx2fc_shost_template, sizeof(*port));
1514 else
1515 lport = libfc_vport_create(vport, sizeof(*port));
1516
1517 if (!lport) {
1518 printk(KERN_ERR PFX "could not allocate scsi host structure\n");
1519 goto free_blport;
1520 }
1521 shost = lport->host;
1522 port = lport_priv(lport);
1523 port->lport = lport;
1524 port->priv = interface;
1525 port->get_netdev = bnx2fc_netdev;
1526 INIT_WORK(&port->destroy_work, bnx2fc_destroy_work);
1527
1528
1529 rc = bnx2fc_lport_config(lport);
1530 if (rc)
1531 goto lp_config_err;
1532
1533 if (npiv) {
1534 printk(KERN_ERR PFX "Setting vport names, 0x%llX 0x%llX\n",
1535 vport->node_name, vport->port_name);
1536 fc_set_wwnn(lport, vport->node_name);
1537 fc_set_wwpn(lport, vport->port_name);
1538 }
1539
1540 rc = bnx2fc_net_config(lport, interface->netdev);
1541 if (rc) {
1542 printk(KERN_ERR PFX "Error on bnx2fc_net_config\n");
1543 goto lp_config_err;
1544 }
1545
1546 rc = bnx2fc_shost_config(lport, parent);
1547 if (rc) {
1548 printk(KERN_ERR PFX "Couldn't configure shost for %s\n",
1549 interface->netdev->name);
1550 goto lp_config_err;
1551 }
1552
1553
1554 rc = bnx2fc_libfc_config(lport);
1555 if (rc) {
1556 printk(KERN_ERR PFX "Couldn't configure libfc\n");
1557 goto shost_err;
1558 }
1559 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1560
1561 if (bnx2fc_devloss_tmo)
1562 fc_host_dev_loss_tmo(shost) = bnx2fc_devloss_tmo;
1563
1564
1565 if (!npiv)
1566 rc = bnx2fc_em_config(lport, hba);
1567 else {
1568 shost = vport_to_shost(vport);
1569 n_port = shost_priv(shost);
1570 rc = fc_exch_mgr_list_clone(n_port, lport);
1571 }
1572
1573 if (rc) {
1574 printk(KERN_ERR PFX "Error on bnx2fc_em_config\n");
1575 goto shost_err;
1576 }
1577
1578 bnx2fc_interface_get(interface);
1579
1580 spin_lock_bh(&hba->hba_lock);
1581 blport->lport = lport;
1582 list_add_tail(&blport->list, &hba->vports);
1583 spin_unlock_bh(&hba->hba_lock);
1584
1585 return lport;
1586
1587shost_err:
1588 scsi_remove_host(shost);
1589lp_config_err:
1590 scsi_host_put(lport->host);
1591free_blport:
1592 kfree(blport);
1593 return NULL;
1594}
1595
1596static void bnx2fc_net_cleanup(struct bnx2fc_interface *interface)
1597{
1598
1599 __dev_remove_pack(&interface->fcoe_packet_type);
1600 __dev_remove_pack(&interface->fip_packet_type);
1601 synchronize_net();
1602}
1603
1604static void bnx2fc_interface_cleanup(struct bnx2fc_interface *interface)
1605{
1606 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1607 struct fc_lport *lport = ctlr->lp;
1608 struct fcoe_port *port = lport_priv(lport);
1609 struct bnx2fc_hba *hba = interface->hba;
1610
1611
1612 del_timer_sync(&port->timer);
1613
1614
1615 fcoe_clean_pending_queue(lport);
1616
1617 bnx2fc_net_cleanup(interface);
1618
1619 bnx2fc_free_vport(hba, lport);
1620}
1621
1622static void bnx2fc_if_destroy(struct fc_lport *lport)
1623{
1624
1625
1626 bnx2fc_clean_rx_queue(lport);
1627
1628
1629 fc_remove_host(lport->host);
1630 scsi_remove_host(lport->host);
1631
1632
1633
1634
1635
1636 fc_exch_mgr_free(lport);
1637
1638
1639 fc_lport_free_stats(lport);
1640
1641
1642 scsi_host_put(lport->host);
1643}
1644
1645static void __bnx2fc_destroy(struct bnx2fc_interface *interface)
1646{
1647 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1648 struct fc_lport *lport = ctlr->lp;
1649 struct fcoe_port *port = lport_priv(lport);
1650
1651 bnx2fc_interface_cleanup(interface);
1652 bnx2fc_stop(interface);
1653 list_del(&interface->list);
1654 bnx2fc_interface_put(interface);
1655 queue_work(bnx2fc_wq, &port->destroy_work);
1656}
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668static int bnx2fc_destroy(struct net_device *netdev)
1669{
1670 struct bnx2fc_interface *interface = NULL;
1671 struct workqueue_struct *timer_work_queue;
1672 struct fcoe_ctlr *ctlr;
1673 int rc = 0;
1674
1675 rtnl_lock();
1676 mutex_lock(&bnx2fc_dev_lock);
1677
1678 interface = bnx2fc_interface_lookup(netdev);
1679 ctlr = bnx2fc_to_ctlr(interface);
1680 if (!interface || !ctlr->lp) {
1681 rc = -ENODEV;
1682 printk(KERN_ERR PFX "bnx2fc_destroy: interface or lport not found\n");
1683 goto netdev_err;
1684 }
1685
1686 timer_work_queue = interface->timer_work_queue;
1687 __bnx2fc_destroy(interface);
1688 destroy_workqueue(timer_work_queue);
1689
1690netdev_err:
1691 mutex_unlock(&bnx2fc_dev_lock);
1692 rtnl_unlock();
1693 return rc;
1694}
1695
1696static void bnx2fc_destroy_work(struct work_struct *work)
1697{
1698 struct fcoe_port *port;
1699 struct fc_lport *lport;
1700
1701 port = container_of(work, struct fcoe_port, destroy_work);
1702 lport = port->lport;
1703
1704 BNX2FC_HBA_DBG(lport, "Entered bnx2fc_destroy_work\n");
1705
1706 bnx2fc_if_destroy(lport);
1707}
1708
1709static void bnx2fc_unbind_adapter_devices(struct bnx2fc_hba *hba)
1710{
1711 bnx2fc_free_fw_resc(hba);
1712 bnx2fc_free_task_ctx(hba);
1713}
1714
1715
1716
1717
1718
1719
1720
1721static int bnx2fc_bind_adapter_devices(struct bnx2fc_hba *hba)
1722{
1723 if (bnx2fc_setup_task_ctx(hba))
1724 goto mem_err;
1725
1726 if (bnx2fc_setup_fw_resc(hba))
1727 goto mem_err;
1728
1729 return 0;
1730mem_err:
1731 bnx2fc_unbind_adapter_devices(hba);
1732 return -ENOMEM;
1733}
1734
1735static int bnx2fc_bind_pcidev(struct bnx2fc_hba *hba)
1736{
1737 struct cnic_dev *cnic;
1738 struct pci_dev *pdev;
1739
1740 if (!hba->cnic) {
1741 printk(KERN_ERR PFX "cnic is NULL\n");
1742 return -ENODEV;
1743 }
1744 cnic = hba->cnic;
1745 pdev = hba->pcidev = cnic->pcidev;
1746 if (!hba->pcidev)
1747 return -ENODEV;
1748
1749 switch (pdev->device) {
1750 case PCI_DEVICE_ID_NX2_57710:
1751 strncpy(hba->chip_num, "BCM57710", BCM_CHIP_LEN);
1752 break;
1753 case PCI_DEVICE_ID_NX2_57711:
1754 strncpy(hba->chip_num, "BCM57711", BCM_CHIP_LEN);
1755 break;
1756 case PCI_DEVICE_ID_NX2_57712:
1757 case PCI_DEVICE_ID_NX2_57712_MF:
1758 case PCI_DEVICE_ID_NX2_57712_VF:
1759 strncpy(hba->chip_num, "BCM57712", BCM_CHIP_LEN);
1760 break;
1761 case PCI_DEVICE_ID_NX2_57800:
1762 case PCI_DEVICE_ID_NX2_57800_MF:
1763 case PCI_DEVICE_ID_NX2_57800_VF:
1764 strncpy(hba->chip_num, "BCM57800", BCM_CHIP_LEN);
1765 break;
1766 case PCI_DEVICE_ID_NX2_57810:
1767 case PCI_DEVICE_ID_NX2_57810_MF:
1768 case PCI_DEVICE_ID_NX2_57810_VF:
1769 strncpy(hba->chip_num, "BCM57810", BCM_CHIP_LEN);
1770 break;
1771 case PCI_DEVICE_ID_NX2_57840:
1772 case PCI_DEVICE_ID_NX2_57840_MF:
1773 case PCI_DEVICE_ID_NX2_57840_VF:
1774 case PCI_DEVICE_ID_NX2_57840_2_20:
1775 case PCI_DEVICE_ID_NX2_57840_4_10:
1776 strncpy(hba->chip_num, "BCM57840", BCM_CHIP_LEN);
1777 break;
1778 default:
1779 pr_err(PFX "Unknown device id 0x%x\n", pdev->device);
1780 break;
1781 }
1782 pci_dev_get(hba->pcidev);
1783 return 0;
1784}
1785
1786static void bnx2fc_unbind_pcidev(struct bnx2fc_hba *hba)
1787{
1788 if (hba->pcidev) {
1789 hba->chip_num[0] = '\0';
1790 pci_dev_put(hba->pcidev);
1791 }
1792 hba->pcidev = NULL;
1793}
1794
1795
1796
1797
1798
1799
1800static int bnx2fc_ulp_get_stats(void *handle)
1801{
1802 struct bnx2fc_hba *hba = handle;
1803 struct cnic_dev *cnic;
1804 struct fcoe_stats_info *stats_addr;
1805
1806 if (!hba)
1807 return -EINVAL;
1808
1809 cnic = hba->cnic;
1810 stats_addr = &cnic->stats_addr->fcoe_stat;
1811 if (!stats_addr)
1812 return -EINVAL;
1813
1814 strncpy(stats_addr->version, BNX2FC_VERSION,
1815 sizeof(stats_addr->version));
1816 stats_addr->txq_size = BNX2FC_SQ_WQES_MAX;
1817 stats_addr->rxq_size = BNX2FC_CQ_WQES_MAX;
1818
1819 return 0;
1820}
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836static void bnx2fc_ulp_start(void *handle)
1837{
1838 struct bnx2fc_hba *hba = handle;
1839 struct bnx2fc_interface *interface;
1840 struct fcoe_ctlr *ctlr;
1841 struct fc_lport *lport;
1842
1843 mutex_lock(&bnx2fc_dev_lock);
1844
1845 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1846 bnx2fc_fw_init(hba);
1847
1848 BNX2FC_MISC_DBG("bnx2fc started.\n");
1849
1850 list_for_each_entry(interface, &if_list, list) {
1851 if (interface->hba == hba) {
1852 ctlr = bnx2fc_to_ctlr(interface);
1853 lport = ctlr->lp;
1854
1855 printk(KERN_ERR PFX "ulp_init: start discovery\n");
1856 lport->tt.frame_send = bnx2fc_xmit;
1857 bnx2fc_start_disc(interface);
1858 }
1859 }
1860
1861 mutex_unlock(&bnx2fc_dev_lock);
1862}
1863
1864static void bnx2fc_port_shutdown(struct fc_lport *lport)
1865{
1866 BNX2FC_MISC_DBG("Entered %s\n", __func__);
1867 fc_fabric_logoff(lport);
1868 fc_lport_destroy(lport);
1869}
1870
1871static void bnx2fc_stop(struct bnx2fc_interface *interface)
1872{
1873 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
1874 struct fc_lport *lport;
1875 struct fc_lport *vport;
1876
1877 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags))
1878 return;
1879
1880 lport = ctlr->lp;
1881 bnx2fc_port_shutdown(lport);
1882
1883 mutex_lock(&lport->lp_mutex);
1884 list_for_each_entry(vport, &lport->vports, list)
1885 fc_host_port_type(vport->host) =
1886 FC_PORTTYPE_UNKNOWN;
1887 mutex_unlock(&lport->lp_mutex);
1888 fc_host_port_type(lport->host) = FC_PORTTYPE_UNKNOWN;
1889 fcoe_ctlr_link_down(ctlr);
1890 fcoe_clean_pending_queue(lport);
1891}
1892
1893static int bnx2fc_fw_init(struct bnx2fc_hba *hba)
1894{
1895#define BNX2FC_INIT_POLL_TIME (1000 / HZ)
1896 int rc = -1;
1897 int i = HZ;
1898
1899 rc = bnx2fc_bind_adapter_devices(hba);
1900 if (rc) {
1901 printk(KERN_ALERT PFX
1902 "bnx2fc_bind_adapter_devices failed - rc = %d\n", rc);
1903 goto err_out;
1904 }
1905
1906 rc = bnx2fc_send_fw_fcoe_init_msg(hba);
1907 if (rc) {
1908 printk(KERN_ALERT PFX
1909 "bnx2fc_send_fw_fcoe_init_msg failed - rc = %d\n", rc);
1910 goto err_unbind;
1911 }
1912
1913
1914
1915
1916
1917 while (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state) && i--)
1918 msleep(BNX2FC_INIT_POLL_TIME);
1919
1920 if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state)) {
1921 printk(KERN_ERR PFX "bnx2fc_start: %s failed to initialize. "
1922 "Ignoring...\n",
1923 hba->cnic->netdev->name);
1924 rc = -1;
1925 goto err_unbind;
1926 }
1927
1928
1929 set_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags);
1930 return 0;
1931
1932err_unbind:
1933 bnx2fc_unbind_adapter_devices(hba);
1934err_out:
1935 return rc;
1936}
1937
1938static void bnx2fc_fw_destroy(struct bnx2fc_hba *hba)
1939{
1940 if (test_and_clear_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags)) {
1941 if (bnx2fc_send_fw_fcoe_destroy_msg(hba) == 0) {
1942 timer_setup(&hba->destroy_timer, bnx2fc_destroy_timer,
1943 0);
1944 hba->destroy_timer.expires = BNX2FC_FW_TIMEOUT +
1945 jiffies;
1946 add_timer(&hba->destroy_timer);
1947 wait_event_interruptible(hba->destroy_wait,
1948 test_bit(BNX2FC_FLAG_DESTROY_CMPL,
1949 &hba->flags));
1950 clear_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
1951
1952 if (signal_pending(current))
1953 flush_signals(current);
1954
1955 del_timer_sync(&hba->destroy_timer);
1956 }
1957 bnx2fc_unbind_adapter_devices(hba);
1958 }
1959}
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969static void bnx2fc_ulp_stop(void *handle)
1970{
1971 struct bnx2fc_hba *hba = handle;
1972 struct bnx2fc_interface *interface;
1973
1974 printk(KERN_ERR "ULP_STOP\n");
1975
1976 mutex_lock(&bnx2fc_dev_lock);
1977 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &hba->flags))
1978 goto exit;
1979 list_for_each_entry(interface, &if_list, list) {
1980 if (interface->hba == hba)
1981 bnx2fc_stop(interface);
1982 }
1983 BUG_ON(hba->num_ofld_sess != 0);
1984
1985 mutex_lock(&hba->hba_mutex);
1986 clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
1987 clear_bit(ADAPTER_STATE_GOING_DOWN,
1988 &hba->adapter_state);
1989
1990 clear_bit(ADAPTER_STATE_READY, &hba->adapter_state);
1991 mutex_unlock(&hba->hba_mutex);
1992
1993 bnx2fc_fw_destroy(hba);
1994exit:
1995 mutex_unlock(&bnx2fc_dev_lock);
1996}
1997
1998static void bnx2fc_start_disc(struct bnx2fc_interface *interface)
1999{
2000 struct fcoe_ctlr *ctlr = bnx2fc_to_ctlr(interface);
2001 struct fc_lport *lport;
2002 int wait_cnt = 0;
2003
2004 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2005
2006 if (!test_bit(BNX2FC_FLAG_FW_INIT_DONE, &interface->hba->flags)) {
2007 printk(KERN_ERR PFX "Init not done yet\n");
2008 return;
2009 }
2010
2011 lport = ctlr->lp;
2012 BNX2FC_HBA_DBG(lport, "calling fc_fabric_login\n");
2013
2014 if (!bnx2fc_link_ok(lport) && interface->enabled) {
2015 BNX2FC_HBA_DBG(lport, "ctlr_link_up\n");
2016 fcoe_ctlr_link_up(ctlr);
2017 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2018 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2019 }
2020
2021
2022 while (!ctlr->sel_fcf) {
2023 msleep(250);
2024
2025 if (++wait_cnt > 12)
2026 break;
2027 }
2028
2029
2030 if (fc_set_mfs(lport, BNX2FC_MFS))
2031 return;
2032
2033 fc_lport_init(lport);
2034 fc_fabric_login(lport);
2035}
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046static void bnx2fc_ulp_init(struct cnic_dev *dev)
2047{
2048 struct bnx2fc_hba *hba;
2049 int rc = 0;
2050
2051 BNX2FC_MISC_DBG("Entered %s\n", __func__);
2052
2053 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags) ||
2054 (dev->max_fcoe_conn == 0)) {
2055 printk(KERN_ERR PFX "bnx2fc FCoE not supported on %s,"
2056 " flags: %lx fcoe_conn: %d\n",
2057 dev->netdev->name, dev->flags, dev->max_fcoe_conn);
2058 return;
2059 }
2060
2061 hba = bnx2fc_hba_create(dev);
2062 if (!hba) {
2063 printk(KERN_ERR PFX "hba initialization failed\n");
2064 return;
2065 }
2066
2067 pr_info(PFX "FCoE initialized for %s.\n", dev->netdev->name);
2068
2069
2070 mutex_lock(&bnx2fc_dev_lock);
2071 list_add_tail(&hba->list, &adapter_list);
2072 adapter_count++;
2073 mutex_unlock(&bnx2fc_dev_lock);
2074
2075 dev->fcoe_cap = &hba->fcoe_cap;
2076 clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2077 rc = dev->register_device(dev, CNIC_ULP_FCOE,
2078 (void *) hba);
2079 if (rc)
2080 printk(KERN_ERR PFX "register_device failed, rc = %d\n", rc);
2081 else
2082 set_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic);
2083}
2084
2085
2086static int __bnx2fc_disable(struct fcoe_ctlr *ctlr)
2087{
2088 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2089
2090 if (interface->enabled == true) {
2091 if (!ctlr->lp) {
2092 pr_err(PFX "__bnx2fc_disable: lport not found\n");
2093 return -ENODEV;
2094 } else {
2095 interface->enabled = false;
2096 fcoe_ctlr_link_down(ctlr);
2097 fcoe_clean_pending_queue(ctlr->lp);
2098 }
2099 }
2100 return 0;
2101}
2102
2103
2104
2105
2106static int bnx2fc_disable(struct net_device *netdev)
2107{
2108 struct bnx2fc_interface *interface;
2109 struct fcoe_ctlr *ctlr;
2110 int rc = 0;
2111
2112 rtnl_lock();
2113 mutex_lock(&bnx2fc_dev_lock);
2114
2115 interface = bnx2fc_interface_lookup(netdev);
2116 ctlr = bnx2fc_to_ctlr(interface);
2117
2118 if (!interface) {
2119 rc = -ENODEV;
2120 pr_err(PFX "bnx2fc_disable: interface not found\n");
2121 } else {
2122 rc = __bnx2fc_disable(ctlr);
2123 }
2124 mutex_unlock(&bnx2fc_dev_lock);
2125 rtnl_unlock();
2126 return rc;
2127}
2128
2129static uint bnx2fc_npiv_create_vports(struct fc_lport *lport,
2130 struct cnic_fc_npiv_tbl *npiv_tbl)
2131{
2132 struct fc_vport_identifiers vpid;
2133 uint i, created = 0;
2134 u64 wwnn = 0;
2135 char wwpn_str[32];
2136 char wwnn_str[32];
2137
2138 if (npiv_tbl->count > MAX_NPIV_ENTRIES) {
2139 BNX2FC_HBA_DBG(lport, "Exceeded count max of npiv table\n");
2140 goto done;
2141 }
2142
2143
2144 if (wwn_to_u64(npiv_tbl->wwnn[0]) == 0 &&
2145 wwn_to_u64(npiv_tbl->wwpn[0]) == 0) {
2146 BNX2FC_HBA_DBG(lport, "First NPIV table entries invalid.\n");
2147 goto done;
2148 }
2149
2150 vpid.roles = FC_PORT_ROLE_FCP_INITIATOR;
2151 vpid.vport_type = FC_PORTTYPE_NPIV;
2152 vpid.disable = false;
2153
2154 for (i = 0; i < npiv_tbl->count; i++) {
2155 wwnn = wwn_to_u64(npiv_tbl->wwnn[i]);
2156 if (wwnn == 0) {
2157
2158
2159
2160
2161 wwnn = lport->wwnn;
2162 }
2163 vpid.node_name = wwnn;
2164 vpid.port_name = wwn_to_u64(npiv_tbl->wwpn[i]);
2165 scnprintf(vpid.symbolic_name, sizeof(vpid.symbolic_name),
2166 "NPIV[%u]:%016llx-%016llx",
2167 created, vpid.port_name, vpid.node_name);
2168 fcoe_wwn_to_str(vpid.node_name, wwnn_str, sizeof(wwnn_str));
2169 fcoe_wwn_to_str(vpid.port_name, wwpn_str, sizeof(wwpn_str));
2170 BNX2FC_HBA_DBG(lport, "Creating vport %s:%s.\n", wwnn_str,
2171 wwpn_str);
2172 if (fc_vport_create(lport->host, 0, &vpid))
2173 created++;
2174 else
2175 BNX2FC_HBA_DBG(lport, "Failed to create vport\n");
2176 }
2177done:
2178 return created;
2179}
2180
2181static int __bnx2fc_enable(struct fcoe_ctlr *ctlr)
2182{
2183 struct bnx2fc_interface *interface = fcoe_ctlr_priv(ctlr);
2184 struct bnx2fc_hba *hba;
2185 struct cnic_fc_npiv_tbl *npiv_tbl;
2186 struct fc_lport *lport;
2187
2188 if (interface->enabled == false) {
2189 if (!ctlr->lp) {
2190 pr_err(PFX "__bnx2fc_enable: lport not found\n");
2191 return -ENODEV;
2192 } else if (!bnx2fc_link_ok(ctlr->lp)) {
2193 fcoe_ctlr_link_up(ctlr);
2194 interface->enabled = true;
2195 }
2196 }
2197
2198
2199 hba = interface->hba;
2200 lport = ctlr->lp;
2201
2202 if (!hba)
2203 goto done;
2204
2205 if (!hba->cnic)
2206 goto done;
2207
2208 if (!lport)
2209 goto done;
2210
2211 if (!lport->host)
2212 goto done;
2213
2214 if (!hba->cnic->get_fc_npiv_tbl)
2215 goto done;
2216
2217 npiv_tbl = kzalloc(sizeof(struct cnic_fc_npiv_tbl), GFP_KERNEL);
2218 if (!npiv_tbl)
2219 goto done;
2220
2221 if (hba->cnic->get_fc_npiv_tbl(hba->cnic, npiv_tbl))
2222 goto done_free;
2223
2224 bnx2fc_npiv_create_vports(lport, npiv_tbl);
2225done_free:
2226 kfree(npiv_tbl);
2227done:
2228 return 0;
2229}
2230
2231
2232
2233
2234static int bnx2fc_enable(struct net_device *netdev)
2235{
2236 struct bnx2fc_interface *interface;
2237 struct fcoe_ctlr *ctlr;
2238 int rc = 0;
2239
2240 rtnl_lock();
2241 mutex_lock(&bnx2fc_dev_lock);
2242
2243 interface = bnx2fc_interface_lookup(netdev);
2244 ctlr = bnx2fc_to_ctlr(interface);
2245 if (!interface) {
2246 rc = -ENODEV;
2247 pr_err(PFX "bnx2fc_enable: interface not found\n");
2248 } else {
2249 rc = __bnx2fc_enable(ctlr);
2250 }
2251
2252 mutex_unlock(&bnx2fc_dev_lock);
2253 rtnl_unlock();
2254 return rc;
2255}
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267static int bnx2fc_ctlr_enabled(struct fcoe_ctlr_device *cdev)
2268{
2269 struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(cdev);
2270
2271 switch (cdev->enabled) {
2272 case FCOE_CTLR_ENABLED:
2273 return __bnx2fc_enable(ctlr);
2274 case FCOE_CTLR_DISABLED:
2275 return __bnx2fc_disable(ctlr);
2276 case FCOE_CTLR_UNUSED:
2277 default:
2278 return -ENOTSUPP;
2279 };
2280}
2281
2282enum bnx2fc_create_link_state {
2283 BNX2FC_CREATE_LINK_DOWN,
2284 BNX2FC_CREATE_LINK_UP,
2285};
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302static int _bnx2fc_create(struct net_device *netdev,
2303 enum fip_mode fip_mode,
2304 enum bnx2fc_create_link_state link_state)
2305{
2306 struct fcoe_ctlr_device *cdev;
2307 struct fcoe_ctlr *ctlr;
2308 struct bnx2fc_interface *interface;
2309 struct bnx2fc_hba *hba;
2310 struct net_device *phys_dev = netdev;
2311 struct fc_lport *lport;
2312 struct ethtool_drvinfo drvinfo;
2313 int rc = 0;
2314 int vlan_id = 0;
2315
2316 BNX2FC_MISC_DBG("Entered bnx2fc_create\n");
2317 if (fip_mode != FIP_MODE_FABRIC) {
2318 printk(KERN_ERR "fip mode not FABRIC\n");
2319 return -EIO;
2320 }
2321
2322 rtnl_lock();
2323
2324 mutex_lock(&bnx2fc_dev_lock);
2325
2326 if (!try_module_get(THIS_MODULE)) {
2327 rc = -EINVAL;
2328 goto mod_err;
2329 }
2330
2331
2332 if (is_vlan_dev(netdev))
2333 phys_dev = vlan_dev_real_dev(netdev);
2334
2335
2336 if (phys_dev->ethtool_ops && phys_dev->ethtool_ops->get_drvinfo) {
2337 memset(&drvinfo, 0, sizeof(drvinfo));
2338 phys_dev->ethtool_ops->get_drvinfo(phys_dev, &drvinfo);
2339 if (strncmp(drvinfo.driver, "bnx2x", strlen("bnx2x"))) {
2340 printk(KERN_ERR PFX "Not a netxtreme2 device\n");
2341 rc = -EINVAL;
2342 goto netdev_err;
2343 }
2344 } else {
2345 printk(KERN_ERR PFX "unable to obtain drv_info\n");
2346 rc = -EINVAL;
2347 goto netdev_err;
2348 }
2349
2350
2351 hba = bnx2fc_hba_lookup(phys_dev);
2352 if (!hba) {
2353 rc = -ENODEV;
2354 printk(KERN_ERR PFX "bnx2fc_create: hba not found\n");
2355 goto netdev_err;
2356 }
2357
2358 if (bnx2fc_interface_lookup(netdev)) {
2359 rc = -EEXIST;
2360 goto netdev_err;
2361 }
2362
2363 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2364 if (!interface) {
2365 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2366 rc = -ENOMEM;
2367 goto netdev_err;
2368 }
2369
2370 if (is_vlan_dev(netdev)) {
2371 vlan_id = vlan_dev_vlan_id(netdev);
2372 interface->vlan_enabled = 1;
2373 }
2374
2375 ctlr = bnx2fc_to_ctlr(interface);
2376 cdev = fcoe_ctlr_to_ctlr_dev(ctlr);
2377 interface->vlan_id = vlan_id;
2378 interface->tm_timeout = BNX2FC_TM_TIMEOUT;
2379
2380 interface->timer_work_queue =
2381 create_singlethread_workqueue("bnx2fc_timer_wq");
2382 if (!interface->timer_work_queue) {
2383 printk(KERN_ERR PFX "ulp_init could not create timer_wq\n");
2384 rc = -EINVAL;
2385 goto ifput_err;
2386 }
2387
2388 lport = bnx2fc_if_create(interface, &cdev->dev, 0);
2389 if (!lport) {
2390 printk(KERN_ERR PFX "Failed to create interface (%s)\n",
2391 netdev->name);
2392 rc = -EINVAL;
2393 goto if_create_err;
2394 }
2395
2396
2397 list_add_tail(&interface->list, &if_list);
2398
2399 lport->boot_time = jiffies;
2400
2401
2402 ctlr->lp = lport;
2403
2404 if (link_state == BNX2FC_CREATE_LINK_UP)
2405 cdev->enabled = FCOE_CTLR_ENABLED;
2406 else
2407 cdev->enabled = FCOE_CTLR_DISABLED;
2408
2409 if (link_state == BNX2FC_CREATE_LINK_UP &&
2410 !bnx2fc_link_ok(lport)) {
2411 fcoe_ctlr_link_up(ctlr);
2412 fc_host_port_type(lport->host) = FC_PORTTYPE_NPORT;
2413 set_bit(ADAPTER_STATE_READY, &interface->hba->adapter_state);
2414 }
2415
2416 BNX2FC_HBA_DBG(lport, "create: START DISC\n");
2417 bnx2fc_start_disc(interface);
2418
2419 if (link_state == BNX2FC_CREATE_LINK_UP)
2420 interface->enabled = true;
2421
2422
2423
2424
2425
2426 bnx2fc_interface_put(interface);
2427
2428 mutex_unlock(&bnx2fc_dev_lock);
2429 rtnl_unlock();
2430 return 0;
2431
2432if_create_err:
2433 destroy_workqueue(interface->timer_work_queue);
2434ifput_err:
2435 bnx2fc_net_cleanup(interface);
2436 bnx2fc_interface_put(interface);
2437 goto mod_err;
2438netdev_err:
2439 module_put(THIS_MODULE);
2440mod_err:
2441 mutex_unlock(&bnx2fc_dev_lock);
2442 rtnl_unlock();
2443 return rc;
2444}
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455static int bnx2fc_create(struct net_device *netdev, enum fip_mode fip_mode)
2456{
2457 return _bnx2fc_create(netdev, fip_mode, BNX2FC_CREATE_LINK_UP);
2458}
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471static int bnx2fc_ctlr_alloc(struct net_device *netdev)
2472{
2473 return _bnx2fc_create(netdev, FIP_MODE_FABRIC,
2474 BNX2FC_CREATE_LINK_DOWN);
2475}
2476
2477
2478
2479
2480
2481
2482
2483static struct bnx2fc_hba *bnx2fc_find_hba_for_cnic(struct cnic_dev *cnic)
2484{
2485 struct bnx2fc_hba *hba;
2486
2487
2488 list_for_each_entry(hba, &adapter_list, list) {
2489 if (hba->cnic == cnic)
2490 return hba;
2491 }
2492 return NULL;
2493}
2494
2495static struct bnx2fc_interface *bnx2fc_interface_lookup(struct net_device
2496 *netdev)
2497{
2498 struct bnx2fc_interface *interface;
2499
2500
2501 list_for_each_entry(interface, &if_list, list) {
2502 if (interface->netdev == netdev)
2503 return interface;
2504 }
2505 return NULL;
2506}
2507
2508static struct bnx2fc_hba *bnx2fc_hba_lookup(struct net_device
2509 *phys_dev)
2510{
2511 struct bnx2fc_hba *hba;
2512
2513
2514 list_for_each_entry(hba, &adapter_list, list) {
2515 if (hba->phys_dev == phys_dev)
2516 return hba;
2517 }
2518 printk(KERN_ERR PFX "adapter_lookup: hba NULL\n");
2519 return NULL;
2520}
2521
2522
2523
2524
2525
2526
2527static void bnx2fc_ulp_exit(struct cnic_dev *dev)
2528{
2529 struct bnx2fc_hba *hba;
2530 struct bnx2fc_interface *interface, *tmp;
2531
2532 BNX2FC_MISC_DBG("Entered bnx2fc_ulp_exit\n");
2533
2534 if (!test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
2535 printk(KERN_ERR PFX "bnx2fc port check: %s, flags: %lx\n",
2536 dev->netdev->name, dev->flags);
2537 return;
2538 }
2539
2540 mutex_lock(&bnx2fc_dev_lock);
2541 hba = bnx2fc_find_hba_for_cnic(dev);
2542 if (!hba) {
2543 printk(KERN_ERR PFX "bnx2fc_ulp_exit: hba not found, dev 0%p\n",
2544 dev);
2545 mutex_unlock(&bnx2fc_dev_lock);
2546 return;
2547 }
2548
2549 list_del_init(&hba->list);
2550 adapter_count--;
2551
2552 list_for_each_entry_safe(interface, tmp, &if_list, list)
2553
2554 if (interface->hba == hba)
2555 __bnx2fc_destroy(interface);
2556 mutex_unlock(&bnx2fc_dev_lock);
2557
2558
2559 flush_workqueue(bnx2fc_wq);
2560
2561 bnx2fc_ulp_stop(hba);
2562
2563 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED, &hba->reg_with_cnic))
2564 hba->cnic->unregister_device(hba->cnic, CNIC_ULP_FCOE);
2565 bnx2fc_hba_destroy(hba);
2566}
2567
2568static void bnx2fc_rport_terminate_io(struct fc_rport *rport)
2569{
2570
2571}
2572
2573
2574
2575
2576
2577
2578
2579
2580static int bnx2fc_fcoe_reset(struct Scsi_Host *shost)
2581{
2582 struct fc_lport *lport = shost_priv(shost);
2583 fc_lport_reset(lport);
2584 return 0;
2585}
2586
2587
2588static bool bnx2fc_match(struct net_device *netdev)
2589{
2590 struct net_device *phys_dev = netdev;
2591
2592 mutex_lock(&bnx2fc_dev_lock);
2593 if (is_vlan_dev(netdev))
2594 phys_dev = vlan_dev_real_dev(netdev);
2595
2596 if (bnx2fc_hba_lookup(phys_dev)) {
2597 mutex_unlock(&bnx2fc_dev_lock);
2598 return true;
2599 }
2600
2601 mutex_unlock(&bnx2fc_dev_lock);
2602 return false;
2603}
2604
2605
2606static struct fcoe_transport bnx2fc_transport = {
2607 .name = {"bnx2fc"},
2608 .attached = false,
2609 .list = LIST_HEAD_INIT(bnx2fc_transport.list),
2610 .alloc = bnx2fc_ctlr_alloc,
2611 .match = bnx2fc_match,
2612 .create = bnx2fc_create,
2613 .destroy = bnx2fc_destroy,
2614 .enable = bnx2fc_enable,
2615 .disable = bnx2fc_disable,
2616};
2617
2618
2619
2620
2621
2622
2623static int bnx2fc_cpu_online(unsigned int cpu)
2624{
2625 struct bnx2fc_percpu_s *p;
2626 struct task_struct *thread;
2627
2628 p = &per_cpu(bnx2fc_percpu, cpu);
2629
2630 thread = kthread_create_on_node(bnx2fc_percpu_io_thread,
2631 (void *)p, cpu_to_node(cpu),
2632 "bnx2fc_thread/%d", cpu);
2633 if (IS_ERR(thread))
2634 return PTR_ERR(thread);
2635
2636
2637 kthread_bind(thread, cpu);
2638 p->iothread = thread;
2639 wake_up_process(thread);
2640 return 0;
2641}
2642
2643static int bnx2fc_cpu_offline(unsigned int cpu)
2644{
2645 struct bnx2fc_percpu_s *p;
2646 struct task_struct *thread;
2647 struct bnx2fc_work *work, *tmp;
2648
2649 BNX2FC_MISC_DBG("destroying io thread for CPU %d\n", cpu);
2650
2651
2652 p = &per_cpu(bnx2fc_percpu, cpu);
2653 spin_lock_bh(&p->fp_work_lock);
2654 thread = p->iothread;
2655 p->iothread = NULL;
2656
2657
2658 list_for_each_entry_safe(work, tmp, &p->work_list, list) {
2659 list_del_init(&work->list);
2660 bnx2fc_process_cq_compl(work->tgt, work->wqe);
2661 kfree(work);
2662 }
2663
2664 spin_unlock_bh(&p->fp_work_lock);
2665
2666 if (thread)
2667 kthread_stop(thread);
2668 return 0;
2669}
2670
2671static int bnx2fc_slave_configure(struct scsi_device *sdev)
2672{
2673 if (!bnx2fc_queue_depth)
2674 return 0;
2675
2676 scsi_change_queue_depth(sdev, bnx2fc_queue_depth);
2677 return 0;
2678}
2679
2680static enum cpuhp_state bnx2fc_online_state;
2681
2682
2683
2684
2685
2686
2687
2688static int __init bnx2fc_mod_init(void)
2689{
2690 struct fcoe_percpu_s *bg;
2691 struct task_struct *l2_thread;
2692 int rc = 0;
2693 unsigned int cpu = 0;
2694 struct bnx2fc_percpu_s *p;
2695
2696 printk(KERN_INFO PFX "%s", version);
2697
2698
2699 rc = fcoe_transport_attach(&bnx2fc_transport);
2700 if (rc) {
2701 printk(KERN_ERR "failed to register an fcoe transport, check "
2702 "if libfcoe is loaded\n");
2703 goto out;
2704 }
2705
2706 INIT_LIST_HEAD(&adapter_list);
2707 INIT_LIST_HEAD(&if_list);
2708 mutex_init(&bnx2fc_dev_lock);
2709 adapter_count = 0;
2710
2711
2712 rc = bnx2fc_attach_transport();
2713 if (rc)
2714 goto detach_ft;
2715
2716 bnx2fc_wq = alloc_workqueue("bnx2fc", 0, 0);
2717 if (!bnx2fc_wq) {
2718 rc = -ENOMEM;
2719 goto release_bt;
2720 }
2721
2722 bg = &bnx2fc_global;
2723 skb_queue_head_init(&bg->fcoe_rx_list);
2724 l2_thread = kthread_create(bnx2fc_l2_rcv_thread,
2725 (void *)bg,
2726 "bnx2fc_l2_thread");
2727 if (IS_ERR(l2_thread)) {
2728 rc = PTR_ERR(l2_thread);
2729 goto free_wq;
2730 }
2731 wake_up_process(l2_thread);
2732 spin_lock_bh(&bg->fcoe_rx_list.lock);
2733 bg->kthread = l2_thread;
2734 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2735
2736 for_each_possible_cpu(cpu) {
2737 p = &per_cpu(bnx2fc_percpu, cpu);
2738 INIT_LIST_HEAD(&p->work_list);
2739 spin_lock_init(&p->fp_work_lock);
2740 }
2741
2742 rc = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "scsi/bnx2fc:online",
2743 bnx2fc_cpu_online, bnx2fc_cpu_offline);
2744 if (rc < 0)
2745 goto stop_thread;
2746 bnx2fc_online_state = rc;
2747
2748 cnic_register_driver(CNIC_ULP_FCOE, &bnx2fc_cnic_cb);
2749 return 0;
2750
2751stop_thread:
2752 kthread_stop(l2_thread);
2753free_wq:
2754 destroy_workqueue(bnx2fc_wq);
2755release_bt:
2756 bnx2fc_release_transport();
2757detach_ft:
2758 fcoe_transport_detach(&bnx2fc_transport);
2759out:
2760 return rc;
2761}
2762
2763static void __exit bnx2fc_mod_exit(void)
2764{
2765 LIST_HEAD(to_be_deleted);
2766 struct bnx2fc_hba *hba, *next;
2767 struct fcoe_percpu_s *bg;
2768 struct task_struct *l2_thread;
2769 struct sk_buff *skb;
2770
2771
2772
2773
2774
2775
2776
2777 mutex_lock(&bnx2fc_dev_lock);
2778 list_splice_init(&adapter_list, &to_be_deleted);
2779 adapter_count = 0;
2780 mutex_unlock(&bnx2fc_dev_lock);
2781
2782
2783 list_for_each_entry_safe(hba, next, &to_be_deleted, list) {
2784 list_del_init(&hba->list);
2785 printk(KERN_ERR PFX "MOD_EXIT:destroy hba = 0x%p\n",
2786 hba);
2787 bnx2fc_ulp_stop(hba);
2788
2789 if (test_and_clear_bit(BNX2FC_CNIC_REGISTERED,
2790 &hba->reg_with_cnic))
2791 hba->cnic->unregister_device(hba->cnic,
2792 CNIC_ULP_FCOE);
2793 bnx2fc_hba_destroy(hba);
2794 }
2795 cnic_unregister_driver(CNIC_ULP_FCOE);
2796
2797
2798 bg = &bnx2fc_global;
2799 spin_lock_bh(&bg->fcoe_rx_list.lock);
2800 l2_thread = bg->kthread;
2801 bg->kthread = NULL;
2802 while ((skb = __skb_dequeue(&bg->fcoe_rx_list)) != NULL)
2803 kfree_skb(skb);
2804
2805 spin_unlock_bh(&bg->fcoe_rx_list.lock);
2806
2807 if (l2_thread)
2808 kthread_stop(l2_thread);
2809
2810 cpuhp_remove_state(bnx2fc_online_state);
2811
2812 destroy_workqueue(bnx2fc_wq);
2813
2814
2815
2816
2817 bnx2fc_release_transport();
2818
2819
2820 fcoe_transport_detach(&bnx2fc_transport);
2821}
2822
2823module_init(bnx2fc_mod_init);
2824module_exit(bnx2fc_mod_exit);
2825
2826static struct fcoe_sysfs_function_template bnx2fc_fcoe_sysfs_templ = {
2827 .set_fcoe_ctlr_enabled = bnx2fc_ctlr_enabled,
2828 .get_fcoe_ctlr_link_fail = fcoe_ctlr_get_lesb,
2829 .get_fcoe_ctlr_vlink_fail = fcoe_ctlr_get_lesb,
2830 .get_fcoe_ctlr_miss_fka = fcoe_ctlr_get_lesb,
2831 .get_fcoe_ctlr_symb_err = fcoe_ctlr_get_lesb,
2832 .get_fcoe_ctlr_err_block = fcoe_ctlr_get_lesb,
2833 .get_fcoe_ctlr_fcs_error = fcoe_ctlr_get_lesb,
2834
2835 .get_fcoe_fcf_selected = fcoe_fcf_get_selected,
2836 .get_fcoe_fcf_vlan_id = bnx2fc_fcf_get_vlan_id,
2837};
2838
2839static struct fc_function_template bnx2fc_transport_function = {
2840 .show_host_node_name = 1,
2841 .show_host_port_name = 1,
2842 .show_host_supported_classes = 1,
2843 .show_host_supported_fc4s = 1,
2844 .show_host_active_fc4s = 1,
2845 .show_host_maxframe_size = 1,
2846
2847 .show_host_port_id = 1,
2848 .show_host_supported_speeds = 1,
2849 .get_host_speed = fc_get_host_speed,
2850 .show_host_speed = 1,
2851 .show_host_port_type = 1,
2852 .get_host_port_state = fc_get_host_port_state,
2853 .show_host_port_state = 1,
2854 .show_host_symbolic_name = 1,
2855
2856 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2857 sizeof(struct bnx2fc_rport)),
2858 .show_rport_maxframe_size = 1,
2859 .show_rport_supported_classes = 1,
2860
2861 .show_host_fabric_name = 1,
2862 .show_starget_node_name = 1,
2863 .show_starget_port_name = 1,
2864 .show_starget_port_id = 1,
2865 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2866 .show_rport_dev_loss_tmo = 1,
2867 .get_fc_host_stats = bnx2fc_get_host_stats,
2868
2869 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2870
2871 .terminate_rport_io = bnx2fc_rport_terminate_io,
2872
2873 .vport_create = bnx2fc_vport_create,
2874 .vport_delete = bnx2fc_vport_destroy,
2875 .vport_disable = bnx2fc_vport_disable,
2876 .bsg_request = fc_lport_bsg_request,
2877};
2878
2879static struct fc_function_template bnx2fc_vport_xport_function = {
2880 .show_host_node_name = 1,
2881 .show_host_port_name = 1,
2882 .show_host_supported_classes = 1,
2883 .show_host_supported_fc4s = 1,
2884 .show_host_active_fc4s = 1,
2885 .show_host_maxframe_size = 1,
2886
2887 .show_host_port_id = 1,
2888 .show_host_supported_speeds = 1,
2889 .get_host_speed = fc_get_host_speed,
2890 .show_host_speed = 1,
2891 .show_host_port_type = 1,
2892 .get_host_port_state = fc_get_host_port_state,
2893 .show_host_port_state = 1,
2894 .show_host_symbolic_name = 1,
2895
2896 .dd_fcrport_size = (sizeof(struct fc_rport_libfc_priv) +
2897 sizeof(struct bnx2fc_rport)),
2898 .show_rport_maxframe_size = 1,
2899 .show_rport_supported_classes = 1,
2900
2901 .show_host_fabric_name = 1,
2902 .show_starget_node_name = 1,
2903 .show_starget_port_name = 1,
2904 .show_starget_port_id = 1,
2905 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
2906 .show_rport_dev_loss_tmo = 1,
2907 .get_fc_host_stats = fc_get_host_stats,
2908 .issue_fc_host_lip = bnx2fc_fcoe_reset,
2909 .terminate_rport_io = fc_rport_terminate_io,
2910 .bsg_request = fc_lport_bsg_request,
2911};
2912
2913
2914
2915
2916static ssize_t
2917bnx2fc_tm_timeout_show(struct device *dev, struct device_attribute *attr,
2918 char *buf)
2919{
2920 struct Scsi_Host *shost = class_to_shost(dev);
2921 struct fc_lport *lport = shost_priv(shost);
2922 struct fcoe_port *port = lport_priv(lport);
2923 struct bnx2fc_interface *interface = port->priv;
2924
2925 sprintf(buf, "%u\n", interface->tm_timeout);
2926 return strlen(buf);
2927}
2928
2929static ssize_t
2930bnx2fc_tm_timeout_store(struct device *dev,
2931 struct device_attribute *attr, const char *buf, size_t count)
2932{
2933 struct Scsi_Host *shost = class_to_shost(dev);
2934 struct fc_lport *lport = shost_priv(shost);
2935 struct fcoe_port *port = lport_priv(lport);
2936 struct bnx2fc_interface *interface = port->priv;
2937 int rval, val;
2938
2939 rval = kstrtouint(buf, 10, &val);
2940 if (rval)
2941 return rval;
2942 if (val > 255)
2943 return -ERANGE;
2944
2945 interface->tm_timeout = (u8)val;
2946 return strlen(buf);
2947}
2948
2949static DEVICE_ATTR(tm_timeout, S_IRUGO|S_IWUSR, bnx2fc_tm_timeout_show,
2950 bnx2fc_tm_timeout_store);
2951
2952static struct device_attribute *bnx2fc_host_attrs[] = {
2953 &dev_attr_tm_timeout,
2954 NULL,
2955};
2956
2957
2958
2959
2960static struct scsi_host_template bnx2fc_shost_template = {
2961 .module = THIS_MODULE,
2962 .name = "QLogic Offload FCoE Initiator",
2963 .queuecommand = bnx2fc_queuecommand,
2964 .eh_timed_out = fc_eh_timed_out,
2965 .eh_abort_handler = bnx2fc_eh_abort,
2966 .eh_device_reset_handler = bnx2fc_eh_device_reset,
2967 .eh_target_reset_handler = bnx2fc_eh_target_reset,
2968 .eh_host_reset_handler = fc_eh_host_reset,
2969 .slave_alloc = fc_slave_alloc,
2970 .change_queue_depth = scsi_change_queue_depth,
2971 .this_id = -1,
2972 .cmd_per_lun = 3,
2973 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2974 .dma_boundary = 0x7fff,
2975 .max_sectors = 0x3fbf,
2976 .track_queue_depth = 1,
2977 .slave_configure = bnx2fc_slave_configure,
2978 .shost_attrs = bnx2fc_host_attrs,
2979};
2980
2981static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
2982 .frame_send = bnx2fc_xmit,
2983 .elsct_send = bnx2fc_elsct_send,
2984 .fcp_abort_io = bnx2fc_abort_io,
2985 .fcp_cleanup = bnx2fc_cleanup,
2986 .get_lesb = fcoe_get_lesb,
2987 .rport_event_callback = bnx2fc_rport_event_handler,
2988};
2989
2990
2991
2992
2993
2994static struct cnic_ulp_ops bnx2fc_cnic_cb = {
2995 .owner = THIS_MODULE,
2996 .cnic_init = bnx2fc_ulp_init,
2997 .cnic_exit = bnx2fc_ulp_exit,
2998 .cnic_start = bnx2fc_ulp_start,
2999 .cnic_stop = bnx2fc_ulp_stop,
3000 .indicate_kcqes = bnx2fc_indicate_kcqe,
3001 .indicate_netevent = bnx2fc_indicate_netevent,
3002 .cnic_get_stats = bnx2fc_ulp_get_stats,
3003};
3004