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