[SCSI] fcoe: move netdev to fcoe_interface
[pandora-kernel.git] / drivers / scsi / fcoe / fcoe.c
1 /*
2  * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms and conditions of the GNU General Public License,
6  * version 2, as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  * more details.
12  *
13  * You should have received a copy of the GNU General Public License along with
14  * this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16  *
17  * Maintained at www.Open-FCoE.org
18  */
19
20 #include <linux/module.h>
21 #include <linux/version.h>
22 #include <linux/spinlock.h>
23 #include <linux/netdevice.h>
24 #include <linux/etherdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/if_ether.h>
27 #include <linux/if_vlan.h>
28 #include <linux/crc32.h>
29 #include <linux/cpu.h>
30 #include <linux/fs.h>
31 #include <linux/sysfs.h>
32 #include <linux/ctype.h>
33 #include <scsi/scsi_tcq.h>
34 #include <scsi/scsicam.h>
35 #include <scsi/scsi_transport.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <net/rtnetlink.h>
38
39 #include <scsi/fc/fc_encaps.h>
40 #include <scsi/fc/fc_fip.h>
41
42 #include <scsi/libfc.h>
43 #include <scsi/fc_frame.h>
44 #include <scsi/libfcoe.h>
45
46 #include "fcoe.h"
47
48 MODULE_AUTHOR("Open-FCoE.org");
49 MODULE_DESCRIPTION("FCoE");
50 MODULE_LICENSE("GPL v2");
51
52 /* Performance tuning parameters for fcoe */
53 static unsigned int fcoe_ddp_min;
54 module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR);
55 MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for "      \
56                  "Direct Data Placement (DDP).");
57
58 /* fcoe host list */
59 LIST_HEAD(fcoe_hostlist);
60 DEFINE_RWLOCK(fcoe_hostlist_lock);
61 DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
62
63 /* Function Prototypes */
64 static int fcoe_reset(struct Scsi_Host *shost);
65 static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
66 static int fcoe_rcv(struct sk_buff *, struct net_device *,
67                     struct packet_type *, struct net_device *);
68 static int fcoe_percpu_receive_thread(void *arg);
69 static void fcoe_clean_pending_queue(struct fc_lport *lp);
70 static void fcoe_percpu_clean(struct fc_lport *lp);
71 static int fcoe_link_ok(struct fc_lport *lp);
72
73 static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
74 static int fcoe_hostlist_add(const struct fc_lport *);
75 static int fcoe_hostlist_remove(const struct fc_lport *);
76
77 static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *);
78 static int fcoe_device_notification(struct notifier_block *, ulong, void *);
79 static void fcoe_dev_setup(void);
80 static void fcoe_dev_cleanup(void);
81
82 /* notification function from net device */
83 static struct notifier_block fcoe_notifier = {
84         .notifier_call = fcoe_device_notification,
85 };
86
87 static struct scsi_transport_template *scsi_transport_fcoe_sw;
88
89 struct fc_function_template fcoe_transport_function = {
90         .show_host_node_name = 1,
91         .show_host_port_name = 1,
92         .show_host_supported_classes = 1,
93         .show_host_supported_fc4s = 1,
94         .show_host_active_fc4s = 1,
95         .show_host_maxframe_size = 1,
96
97         .show_host_port_id = 1,
98         .show_host_supported_speeds = 1,
99         .get_host_speed = fc_get_host_speed,
100         .show_host_speed = 1,
101         .show_host_port_type = 1,
102         .get_host_port_state = fc_get_host_port_state,
103         .show_host_port_state = 1,
104         .show_host_symbolic_name = 1,
105
106         .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
107         .show_rport_maxframe_size = 1,
108         .show_rport_supported_classes = 1,
109
110         .show_host_fabric_name = 1,
111         .show_starget_node_name = 1,
112         .show_starget_port_name = 1,
113         .show_starget_port_id = 1,
114         .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
115         .show_rport_dev_loss_tmo = 1,
116         .get_fc_host_stats = fc_get_host_stats,
117         .issue_fc_host_lip = fcoe_reset,
118
119         .terminate_rport_io = fc_rport_terminate_io,
120 };
121
122 static struct scsi_host_template fcoe_shost_template = {
123         .module = THIS_MODULE,
124         .name = "FCoE Driver",
125         .proc_name = FCOE_NAME,
126         .queuecommand = fc_queuecommand,
127         .eh_abort_handler = fc_eh_abort,
128         .eh_device_reset_handler = fc_eh_device_reset,
129         .eh_host_reset_handler = fc_eh_host_reset,
130         .slave_alloc = fc_slave_alloc,
131         .change_queue_depth = fc_change_queue_depth,
132         .change_queue_type = fc_change_queue_type,
133         .this_id = -1,
134         .cmd_per_lun = 32,
135         .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
136         .use_clustering = ENABLE_CLUSTERING,
137         .sg_tablesize = SG_ALL,
138         .max_sectors = 0xffff,
139 };
140
141 /**
142  * fcoe_fip_recv - handle a received FIP frame.
143  * @skb: the receive skb
144  * @dev: associated &net_device
145  * @ptype: the &packet_type structure which was used to register this handler.
146  * @orig_dev: original receive &net_device, in case @dev is a bond.
147  *
148  * Returns: 0 for success
149  */
150 static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
151                          struct packet_type *ptype,
152                          struct net_device *orig_dev)
153 {
154         struct fcoe_port *port;
155
156         port = container_of(ptype, struct fcoe_port, fip_packet_type);
157         fcoe_ctlr_recv(&port->ctlr, skb);
158         return 0;
159 }
160
161 /**
162  * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
163  * @fip: FCoE controller.
164  * @skb: FIP Packet.
165  */
166 static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
167 {
168         skb->dev = fcoe_from_ctlr(fip)->fcoe->netdev;
169         dev_queue_xmit(skb);
170 }
171
172 /**
173  * fcoe_update_src_mac() - Update Ethernet MAC filters.
174  * @fip: FCoE controller.
175  * @old: Unicast MAC address to delete if the MAC is non-zero.
176  * @new: Unicast MAC address to add.
177  *
178  * Remove any previously-set unicast MAC filter.
179  * Add secondary FCoE MAC address filter for our OUI.
180  */
181 static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
182 {
183         struct fcoe_interface *fcoe;
184         struct fcoe_port *port;
185
186         port = fcoe_from_ctlr(fip);
187         fcoe = port->fcoe;
188
189         rtnl_lock();
190         if (!is_zero_ether_addr(old))
191                 dev_unicast_delete(fcoe->netdev, old);
192         dev_unicast_add(fcoe->netdev, new);
193         rtnl_unlock();
194 }
195
196 /**
197  * fcoe_lport_config() - sets up the fc_lport
198  * @lp: ptr to the fc_lport
199  *
200  * Returns: 0 for success
201  */
202 static int fcoe_lport_config(struct fc_lport *lp)
203 {
204         lp->link_up = 0;
205         lp->qfull = 0;
206         lp->max_retry_count = 3;
207         lp->max_rport_retry_count = 3;
208         lp->e_d_tov = 2 * 1000; /* FC-FS default */
209         lp->r_a_tov = 2 * 2 * 1000;
210         lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
211                               FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
212
213         fc_lport_init_stats(lp);
214
215         /* lport fc_lport related configuration */
216         fc_lport_config(lp);
217
218         /* offload related configuration */
219         lp->crc_offload = 0;
220         lp->seq_offload = 0;
221         lp->lro_enabled = 0;
222         lp->lro_xid = 0;
223         lp->lso_max = 0;
224
225         return 0;
226 }
227
228 /**
229  * fcoe_netdev_cleanup() - clean up netdev configurations
230  * @port: ptr to the fcoe_port
231  */
232 void fcoe_netdev_cleanup(struct fcoe_port *port)
233 {
234         u8 flogi_maddr[ETH_ALEN];
235         struct fcoe_interface *fcoe = port->fcoe;
236
237         /* Don't listen for Ethernet packets anymore */
238         dev_remove_pack(&port->fcoe_packet_type);
239         dev_remove_pack(&port->fip_packet_type);
240
241         /* Delete secondary MAC addresses */
242         rtnl_lock();
243         memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
244         dev_unicast_delete(fcoe->netdev, flogi_maddr);
245         if (!is_zero_ether_addr(port->ctlr.data_src_addr))
246                 dev_unicast_delete(fcoe->netdev, port->ctlr.data_src_addr);
247         if (port->ctlr.spma)
248                 dev_unicast_delete(fcoe->netdev, port->ctlr.ctl_src_addr);
249         dev_mc_delete(fcoe->netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
250         rtnl_unlock();
251 }
252
253 /**
254  * fcoe_queue_timer() - fcoe queue timer
255  * @lp: the fc_lport pointer
256  *
257  * Calls fcoe_check_wait_queue on timeout
258  *
259  */
260 static void fcoe_queue_timer(ulong lp)
261 {
262         fcoe_check_wait_queue((struct fc_lport *)lp, NULL);
263 }
264
265 /**
266  * fcoe_netdev_config() - Set up netdev for SW FCoE
267  * @lp : ptr to the fc_lport
268  * @netdev : ptr to the associated netdevice struct
269  *
270  * Must be called after fcoe_lport_config() as it will use lport mutex
271  *
272  * Returns : 0 for success
273  */
274 static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
275 {
276         u32 mfs;
277         u64 wwnn, wwpn;
278         struct fcoe_interface *fcoe;
279         struct fcoe_port *port;
280         u8 flogi_maddr[ETH_ALEN];
281         struct netdev_hw_addr *ha;
282
283         /* Setup lport private data to point to fcoe softc */
284         port = lport_priv(lp);
285         fcoe = port->fcoe;
286         port->ctlr.lp = lp;
287         fcoe->netdev = netdev;
288
289         /* Do not support for bonding device */
290         if ((netdev->priv_flags & IFF_MASTER_ALB) ||
291             (netdev->priv_flags & IFF_SLAVE_INACTIVE) ||
292             (netdev->priv_flags & IFF_MASTER_8023AD)) {
293                 return -EOPNOTSUPP;
294         }
295
296         /*
297          * Determine max frame size based on underlying device and optional
298          * user-configured limit.  If the MFS is too low, fcoe_link_ok()
299          * will return 0, so do this first.
300          */
301         mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
302                              sizeof(struct fcoe_crc_eof));
303         if (fc_set_mfs(lp, mfs))
304                 return -EINVAL;
305
306         /* offload features support */
307         if (netdev->features & NETIF_F_SG)
308                 lp->sg_supp = 1;
309
310         if (netdev->features & NETIF_F_FCOE_CRC) {
311                 lp->crc_offload = 1;
312                 FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n");
313         }
314         if (netdev->features & NETIF_F_FSO) {
315                 lp->seq_offload = 1;
316                 lp->lso_max = netdev->gso_max_size;
317                 FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n",
318                                 lp->lso_max);
319         }
320         if (netdev->fcoe_ddp_xid) {
321                 lp->lro_enabled = 1;
322                 lp->lro_xid = netdev->fcoe_ddp_xid;
323                 FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n",
324                                 lp->lro_xid);
325         }
326         skb_queue_head_init(&port->fcoe_pending_queue);
327         port->fcoe_pending_queue_active = 0;
328         setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lp);
329
330         /* look for SAN MAC address, if multiple SAN MACs exist, only
331          * use the first one for SPMA */
332         rcu_read_lock();
333         for_each_dev_addr(netdev, ha) {
334                 if ((ha->type == NETDEV_HW_ADDR_T_SAN) &&
335                     (is_valid_ether_addr(port->ctlr.ctl_src_addr))) {
336                         memcpy(port->ctlr.ctl_src_addr, ha->addr, ETH_ALEN);
337                         port->ctlr.spma = 1;
338                         break;
339                 }
340         }
341         rcu_read_unlock();
342
343         /* setup Source Mac Address */
344         if (!port->ctlr.spma)
345                 memcpy(port->ctlr.ctl_src_addr, netdev->dev_addr,
346                        netdev->addr_len);
347
348         wwnn = fcoe_wwn_from_mac(netdev->dev_addr, 1, 0);
349         fc_set_wwnn(lp, wwnn);
350         /* XXX - 3rd arg needs to be vlan id */
351         wwpn = fcoe_wwn_from_mac(netdev->dev_addr, 2, 0);
352         fc_set_wwpn(lp, wwpn);
353
354         /*
355          * Add FCoE MAC address as second unicast MAC address
356          * or enter promiscuous mode if not capable of listening
357          * for multiple unicast MACs.
358          */
359         rtnl_lock();
360         memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
361         dev_unicast_add(netdev, flogi_maddr);
362         if (port->ctlr.spma)
363                 dev_unicast_add(netdev, port->ctlr.ctl_src_addr);
364         dev_mc_add(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0);
365         rtnl_unlock();
366
367         /*
368          * setup the receive function from ethernet driver
369          * on the ethertype for the given device
370          */
371         port->fcoe_packet_type.func = fcoe_rcv;
372         port->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
373         port->fcoe_packet_type.dev = netdev;
374         dev_add_pack(&port->fcoe_packet_type);
375
376         port->fip_packet_type.func = fcoe_fip_recv;
377         port->fip_packet_type.type = htons(ETH_P_FIP);
378         port->fip_packet_type.dev = netdev;
379         dev_add_pack(&port->fip_packet_type);
380
381         return 0;
382 }
383
384 /**
385  * fcoe_shost_config() - Sets up fc_lport->host
386  * @lp : ptr to the fc_lport
387  * @shost : ptr to the associated scsi host
388  * @dev : device associated to scsi host
389  *
390  * Must be called after fcoe_lport_config() and fcoe_netdev_config()
391  *
392  * Returns : 0 for success
393  */
394 static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
395                                 struct device *dev)
396 {
397         int rc = 0;
398
399         /* lport scsi host config */
400         lp->host = shost;
401
402         lp->host->max_lun = FCOE_MAX_LUN;
403         lp->host->max_id = FCOE_MAX_FCP_TARGET;
404         lp->host->max_channel = 0;
405         lp->host->transportt = scsi_transport_fcoe_sw;
406
407         /* add the new host to the SCSI-ml */
408         rc = scsi_add_host(lp->host, dev);
409         if (rc) {
410                 FCOE_NETDEV_DBG(fcoe_netdev(lp), "fcoe_shost_config: "
411                                 "error on scsi_add_host\n");
412                 return rc;
413         }
414         sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
415                 FCOE_NAME, FCOE_VERSION,
416                 fcoe_netdev(lp)->name);
417
418         return 0;
419 }
420
421 /*
422  * fcoe_oem_match() - match for read types IO
423  * @fp: the fc_frame for new IO.
424  *
425  * Returns : true for read types IO, otherwise returns false.
426  */
427 bool fcoe_oem_match(struct fc_frame *fp)
428 {
429         return fc_fcp_is_read(fr_fsp(fp)) &&
430                 (fr_fsp(fp)->data_len > fcoe_ddp_min);
431 }
432
433 /**
434  * fcoe_em_config() - allocates em for this lport
435  * @lp: the fcoe that em is to allocated for
436  *
437  * Called with write fcoe_hostlist_lock held.
438  *
439  * Returns : 0 on success
440  */
441 static inline int fcoe_em_config(struct fc_lport *lp)
442 {
443         struct fcoe_port *port = lport_priv(lp);
444         struct fcoe_port *oldport = NULL;
445         struct fcoe_interface *fcoe = port->fcoe;
446         struct fcoe_interface *oldfcoe = NULL;
447         struct net_device *old_real_dev, *cur_real_dev;
448         u16 min_xid = FCOE_MIN_XID;
449         u16 max_xid = FCOE_MAX_XID;
450
451         /*
452          * Check if need to allocate an em instance for
453          * offload exchange ids to be shared across all VN_PORTs/lport.
454          */
455         if (!lp->lro_enabled || !lp->lro_xid || (lp->lro_xid >= max_xid)) {
456                 lp->lro_xid = 0;
457                 goto skip_oem;
458         }
459
460         /*
461          * Reuse existing offload em instance in case
462          * it is already allocated on real eth device
463          */
464         if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
465                 cur_real_dev = vlan_dev_real_dev(fcoe->netdev);
466         else
467                 cur_real_dev = fcoe->netdev;
468
469         list_for_each_entry(oldfcoe, &fcoe_hostlist, list) {
470                 oldport = oldfcoe->priv;
471                 if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN)
472                         old_real_dev = vlan_dev_real_dev(oldfcoe->netdev);
473                 else
474                         old_real_dev = oldfcoe->netdev;
475
476                 if (cur_real_dev == old_real_dev) {
477                         port->oem = oldport->oem;
478                         break;
479                 }
480         }
481
482         if (port->oem) {
483                 if (!fc_exch_mgr_add(lp, port->oem, fcoe_oem_match)) {
484                         printk(KERN_ERR "fcoe_em_config: failed to add "
485                                "offload em:%p on interface:%s\n",
486                                port->oem, fcoe->netdev->name);
487                         return -ENOMEM;
488                 }
489         } else {
490                 port->oem = fc_exch_mgr_alloc(lp, FC_CLASS_3,
491                                             FCOE_MIN_XID, lp->lro_xid,
492                                             fcoe_oem_match);
493                 if (!port->oem) {
494                         printk(KERN_ERR "fcoe_em_config: failed to allocate "
495                                "em for offload exches on interface:%s\n",
496                                fcoe->netdev->name);
497                         return -ENOMEM;
498                 }
499         }
500
501         /*
502          * Exclude offload EM xid range from next EM xid range.
503          */
504         min_xid += lp->lro_xid + 1;
505
506 skip_oem:
507         if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, min_xid, max_xid, NULL)) {
508                 printk(KERN_ERR "fcoe_em_config: failed to "
509                        "allocate em on interface %s\n", fcoe->netdev->name);
510                 return -ENOMEM;
511         }
512
513         return 0;
514 }
515
516 /**
517  * fcoe_if_destroy() - FCoE software HBA tear-down function
518  * @lport: fc_lport to destroy
519  */
520 static void fcoe_if_destroy(struct fc_lport *lport)
521 {
522         struct fcoe_port *port = lport_priv(lport);
523         struct fcoe_interface *fcoe = port->fcoe;
524         struct net_device *netdev = fcoe->netdev;
525
526         FCOE_NETDEV_DBG(netdev, "Destroying interface\n");
527
528         /* Logout of the fabric */
529         fc_fabric_logoff(lport);
530
531         /* Remove the instance from fcoe's list */
532         fcoe_hostlist_remove(lport);
533
534         /* clean up netdev configurations */
535         fcoe_netdev_cleanup(port);
536
537         /* tear-down the FCoE controller */
538         fcoe_ctlr_destroy(&port->ctlr);
539
540         /* Free queued packets for the per-CPU receive threads */
541         fcoe_percpu_clean(lport);
542
543         /* Cleanup the fc_lport */
544         fc_lport_destroy(lport);
545         fc_fcp_destroy(lport);
546
547         /* Detach from the scsi-ml */
548         fc_remove_host(lport->host);
549         scsi_remove_host(lport->host);
550
551         /* There are no more rports or I/O, free the EM */
552         fc_exch_mgr_free(lport);
553
554         /* Free existing skbs */
555         fcoe_clean_pending_queue(lport);
556
557         /* Stop the timer */
558         del_timer_sync(&port->timer);
559
560         /* Free memory used by statistical counters */
561         fc_lport_free_stats(lport);
562
563         /* Release the net_device and Scsi_Host */
564         dev_put(netdev);
565         scsi_host_put(lport->host);
566         kfree(fcoe);            /* TODO, should be refcounted */
567 }
568
569 /*
570  * fcoe_ddp_setup - calls LLD's ddp_setup through net_device
571  * @lp: the corresponding fc_lport
572  * @xid: the exchange id for this ddp transfer
573  * @sgl: the scatterlist describing this transfer
574  * @sgc: number of sg items
575  *
576  * Returns : 0 no ddp
577  */
578 static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
579                              struct scatterlist *sgl, unsigned int sgc)
580 {
581         struct net_device *n = fcoe_netdev(lp);
582
583         if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_setup)
584                 return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc);
585
586         return 0;
587 }
588
589 /*
590  * fcoe_ddp_done - calls LLD's ddp_done through net_device
591  * @lp: the corresponding fc_lport
592  * @xid: the exchange id for this ddp transfer
593  *
594  * Returns : the length of data that have been completed by ddp
595  */
596 static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
597 {
598         struct net_device *n = fcoe_netdev(lp);
599
600         if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_done)
601                 return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
602         return 0;
603 }
604
605 static struct libfc_function_template fcoe_libfc_fcn_templ = {
606         .frame_send = fcoe_xmit,
607         .ddp_setup = fcoe_ddp_setup,
608         .ddp_done = fcoe_ddp_done,
609 };
610
611 /**
612  * fcoe_if_create() - this function creates the fcoe interface
613  * @netdev: pointer the associated netdevice
614  * @parent: device pointer to be the parent in sysfs for the SCSI host
615  *
616  * Creates fc_lport struct and scsi_host for lport, configures lport
617  * and starts fabric login.
618  *
619  * Returns : The allocated fc_lport or an error pointer
620  */
621 static struct fc_lport *fcoe_if_create(struct net_device *netdev,
622                                        struct device *parent)
623 {
624         int rc;
625         struct fc_lport *lport = NULL;
626         struct fcoe_port *port;
627         struct fcoe_interface *fcoe;
628         struct Scsi_Host *shost;
629
630         FCOE_NETDEV_DBG(netdev, "Create Interface\n");
631
632         fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL);
633         if (!fcoe) {
634                 FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n");
635                 rc = -ENOMEM;
636                 goto out;
637         }
638
639         shost = libfc_host_alloc(&fcoe_shost_template,
640                                  sizeof(struct fcoe_port));
641         if (!shost) {
642                 FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n");
643                 rc = -ENOMEM;
644                 goto out_kfree_port;
645         }
646         lport = shost_priv(shost);
647         port = lport_priv(lport);
648
649         port->fcoe = fcoe;
650         fcoe->priv = port;
651
652         /* configure fc_lport, e.g., em */
653         rc = fcoe_lport_config(lport);
654         if (rc) {
655                 FCOE_NETDEV_DBG(netdev, "Could not configure lport for the "
656                                 "interface\n");
657                 goto out_host_put;
658         }
659
660         /*
661          * Initialize FIP.
662          */
663         fcoe_ctlr_init(&port->ctlr);
664         port->ctlr.send = fcoe_fip_send;
665         port->ctlr.update_mac = fcoe_update_src_mac;
666
667         /* configure lport network properties */
668         rc = fcoe_netdev_config(lport, netdev);
669         if (rc) {
670                 FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the "
671                                 "interface\n");
672                 goto out_netdev_cleanup;
673         }
674
675         /* configure lport scsi host properties */
676         rc = fcoe_shost_config(lport, shost, parent);
677         if (rc) {
678                 FCOE_NETDEV_DBG(netdev, "Could not configure shost for the "
679                                 "interface\n");
680                 goto out_netdev_cleanup;
681         }
682
683         /* Initialize the library */
684         rc = fcoe_libfc_config(lport, &fcoe_libfc_fcn_templ);
685         if (rc) {
686                 FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the "
687                                 "interface\n");
688                 goto out_lp_destroy;
689         }
690
691         /*
692          * fcoe_em_alloc() and fcoe_hostlist_add() both
693          * need to be atomic under fcoe_hostlist_lock
694          * since fcoe_em_alloc() looks for an existing EM
695          * instance on host list updated by fcoe_hostlist_add().
696          */
697         write_lock(&fcoe_hostlist_lock);
698         /* lport exch manager allocation */
699         rc = fcoe_em_config(lport);
700         if (rc) {
701                 FCOE_NETDEV_DBG(netdev, "Could not configure the EM for the "
702                                 "interface\n");
703                 goto out_lp_destroy;
704         }
705
706         /* add to lports list */
707         fcoe_hostlist_add(lport);
708         write_unlock(&fcoe_hostlist_lock);
709
710         lport->boot_time = jiffies;
711
712         fc_fabric_login(lport);
713
714         if (!fcoe_link_ok(lport))
715                 fcoe_ctlr_link_up(&port->ctlr);
716
717         dev_hold(netdev);
718
719         return lport;
720
721 out_lp_destroy:
722         fc_exch_mgr_free(lport);
723 out_netdev_cleanup:
724         fcoe_netdev_cleanup(port);
725 out_host_put:
726         scsi_host_put(lport->host);
727 out_kfree_port:
728         kfree(fcoe);
729 out:
730         return ERR_PTR(rc);
731 }
732
733 /**
734  * fcoe_if_init() - attach to scsi transport
735  *
736  * Returns : 0 on success
737  */
738 static int __init fcoe_if_init(void)
739 {
740         /* attach to scsi transport */
741         scsi_transport_fcoe_sw =
742                 fc_attach_transport(&fcoe_transport_function);
743
744         if (!scsi_transport_fcoe_sw) {
745                 printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n");
746                 return -ENODEV;
747         }
748
749         return 0;
750 }
751
752 /**
753  * fcoe_if_exit() - detach from scsi transport
754  *
755  * Returns : 0 on success
756  */
757 int __exit fcoe_if_exit(void)
758 {
759         fc_release_transport(scsi_transport_fcoe_sw);
760         return 0;
761 }
762
763 /**
764  * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
765  * @cpu: cpu index for the online cpu
766  */
767 static void fcoe_percpu_thread_create(unsigned int cpu)
768 {
769         struct fcoe_percpu_s *p;
770         struct task_struct *thread;
771
772         p = &per_cpu(fcoe_percpu, cpu);
773
774         thread = kthread_create(fcoe_percpu_receive_thread,
775                                 (void *)p, "fcoethread/%d", cpu);
776
777         if (likely(!IS_ERR(p->thread))) {
778                 kthread_bind(thread, cpu);
779                 wake_up_process(thread);
780
781                 spin_lock_bh(&p->fcoe_rx_list.lock);
782                 p->thread = thread;
783                 spin_unlock_bh(&p->fcoe_rx_list.lock);
784         }
785 }
786
787 /**
788  * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
789  * @cpu: cpu index the rx thread is to be removed
790  *
791  * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
792  * current CPU's Rx thread. If the thread being destroyed is bound to
793  * the CPU processing this context the skbs will be freed.
794  */
795 static void fcoe_percpu_thread_destroy(unsigned int cpu)
796 {
797         struct fcoe_percpu_s *p;
798         struct task_struct *thread;
799         struct page *crc_eof;
800         struct sk_buff *skb;
801 #ifdef CONFIG_SMP
802         struct fcoe_percpu_s *p0;
803         unsigned targ_cpu = smp_processor_id();
804 #endif /* CONFIG_SMP */
805
806         FCOE_DBG("Destroying receive thread for CPU %d\n", cpu);
807
808         /* Prevent any new skbs from being queued for this CPU. */
809         p = &per_cpu(fcoe_percpu, cpu);
810         spin_lock_bh(&p->fcoe_rx_list.lock);
811         thread = p->thread;
812         p->thread = NULL;
813         crc_eof = p->crc_eof_page;
814         p->crc_eof_page = NULL;
815         p->crc_eof_offset = 0;
816         spin_unlock_bh(&p->fcoe_rx_list.lock);
817
818 #ifdef CONFIG_SMP
819         /*
820          * Don't bother moving the skb's if this context is running
821          * on the same CPU that is having its thread destroyed. This
822          * can easily happen when the module is removed.
823          */
824         if (cpu != targ_cpu) {
825                 p0 = &per_cpu(fcoe_percpu, targ_cpu);
826                 spin_lock_bh(&p0->fcoe_rx_list.lock);
827                 if (p0->thread) {
828                         FCOE_DBG("Moving frames from CPU %d to CPU %d\n",
829                                  cpu, targ_cpu);
830
831                         while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
832                                 __skb_queue_tail(&p0->fcoe_rx_list, skb);
833                         spin_unlock_bh(&p0->fcoe_rx_list.lock);
834                 } else {
835                         /*
836                          * The targeted CPU is not initialized and cannot accept
837                          * new  skbs. Unlock the targeted CPU and drop the skbs
838                          * on the CPU that is going offline.
839                          */
840                         while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
841                                 kfree_skb(skb);
842                         spin_unlock_bh(&p0->fcoe_rx_list.lock);
843                 }
844         } else {
845                 /*
846                  * This scenario occurs when the module is being removed
847                  * and all threads are being destroyed. skbs will continue
848                  * to be shifted from the CPU thread that is being removed
849                  * to the CPU thread associated with the CPU that is processing
850                  * the module removal. Once there is only one CPU Rx thread it
851                  * will reach this case and we will drop all skbs and later
852                  * stop the thread.
853                  */
854                 spin_lock_bh(&p->fcoe_rx_list.lock);
855                 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
856                         kfree_skb(skb);
857                 spin_unlock_bh(&p->fcoe_rx_list.lock);
858         }
859 #else
860         /*
861          * This a non-SMP scenario where the singular Rx thread is
862          * being removed. Free all skbs and stop the thread.
863          */
864         spin_lock_bh(&p->fcoe_rx_list.lock);
865         while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
866                 kfree_skb(skb);
867         spin_unlock_bh(&p->fcoe_rx_list.lock);
868 #endif
869
870         if (thread)
871                 kthread_stop(thread);
872
873         if (crc_eof)
874                 put_page(crc_eof);
875 }
876
877 /**
878  * fcoe_cpu_callback() - fcoe cpu hotplug event callback
879  * @nfb: callback data block
880  * @action: event triggering the callback
881  * @hcpu: index for the cpu of this event
882  *
883  * This creates or destroys per cpu data for fcoe
884  *
885  * Returns NOTIFY_OK always.
886  */
887 static int fcoe_cpu_callback(struct notifier_block *nfb,
888                              unsigned long action, void *hcpu)
889 {
890         unsigned cpu = (unsigned long)hcpu;
891
892         switch (action) {
893         case CPU_ONLINE:
894         case CPU_ONLINE_FROZEN:
895                 FCOE_DBG("CPU %x online: Create Rx thread\n", cpu);
896                 fcoe_percpu_thread_create(cpu);
897                 break;
898         case CPU_DEAD:
899         case CPU_DEAD_FROZEN:
900                 FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu);
901                 fcoe_percpu_thread_destroy(cpu);
902                 break;
903         default:
904                 break;
905         }
906         return NOTIFY_OK;
907 }
908
909 static struct notifier_block fcoe_cpu_notifier = {
910         .notifier_call = fcoe_cpu_callback,
911 };
912
913 /**
914  * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
915  * @skb: the receive skb
916  * @dev: associated net device
917  * @ptype: context
918  * @olddev: last device
919  *
920  * this function will receive the packet and build fc frame and pass it up
921  *
922  * Returns: 0 for success
923  */
924 int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
925              struct packet_type *ptype, struct net_device *olddev)
926 {
927         struct fc_lport *lp;
928         struct fcoe_rcv_info *fr;
929         struct fcoe_port *port;
930         struct fc_frame_header *fh;
931         struct fcoe_percpu_s *fps;
932         unsigned int cpu;
933
934         port = container_of(ptype, struct fcoe_port, fcoe_packet_type);
935         lp = port->ctlr.lp;
936         if (unlikely(lp == NULL)) {
937                 FCOE_NETDEV_DBG(dev, "Cannot find hba structure");
938                 goto err2;
939         }
940         if (!lp->link_up)
941                 goto err2;
942
943         FCOE_NETDEV_DBG(dev, "skb_info: len:%d data_len:%d head:%p "
944                         "data:%p tail:%p end:%p sum:%d dev:%s",
945                         skb->len, skb->data_len, skb->head, skb->data,
946                         skb_tail_pointer(skb), skb_end_pointer(skb),
947                         skb->csum, skb->dev ? skb->dev->name : "<NULL>");
948
949         /* check for FCOE packet type */
950         if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
951                 FCOE_NETDEV_DBG(dev, "Wrong FC type frame");
952                 goto err;
953         }
954
955         /*
956          * Check for minimum frame length, and make sure required FCoE
957          * and FC headers are pulled into the linear data area.
958          */
959         if (unlikely((skb->len < FCOE_MIN_FRAME) ||
960             !pskb_may_pull(skb, FCOE_HEADER_LEN)))
961                 goto err;
962
963         skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
964         fh = (struct fc_frame_header *) skb_transport_header(skb);
965
966         fr = fcoe_dev_from_skb(skb);
967         fr->fr_dev = lp;
968         fr->ptype = ptype;
969
970         /*
971          * In case the incoming frame's exchange is originated from
972          * the initiator, then received frame's exchange id is ANDed
973          * with fc_cpu_mask bits to get the same cpu on which exchange
974          * was originated, otherwise just use the current cpu.
975          */
976         if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)
977                 cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask;
978         else
979                 cpu = smp_processor_id();
980
981         fps = &per_cpu(fcoe_percpu, cpu);
982         spin_lock_bh(&fps->fcoe_rx_list.lock);
983         if (unlikely(!fps->thread)) {
984                 /*
985                  * The targeted CPU is not ready, let's target
986                  * the first CPU now. For non-SMP systems this
987                  * will check the same CPU twice.
988                  */
989                 FCOE_NETDEV_DBG(dev, "CPU is online, but no receive thread "
990                                 "ready for incoming skb- using first online "
991                                 "CPU.\n");
992
993                 spin_unlock_bh(&fps->fcoe_rx_list.lock);
994                 cpu = first_cpu(cpu_online_map);
995                 fps = &per_cpu(fcoe_percpu, cpu);
996                 spin_lock_bh(&fps->fcoe_rx_list.lock);
997                 if (!fps->thread) {
998                         spin_unlock_bh(&fps->fcoe_rx_list.lock);
999                         goto err;
1000                 }
1001         }
1002
1003         /*
1004          * We now have a valid CPU that we're targeting for
1005          * this skb. We also have this receive thread locked,
1006          * so we're free to queue skbs into it's queue.
1007          */
1008         __skb_queue_tail(&fps->fcoe_rx_list, skb);
1009         if (fps->fcoe_rx_list.qlen == 1)
1010                 wake_up_process(fps->thread);
1011
1012         spin_unlock_bh(&fps->fcoe_rx_list.lock);
1013
1014         return 0;
1015 err:
1016         fc_lport_get_stats(lp)->ErrorFrames++;
1017
1018 err2:
1019         kfree_skb(skb);
1020         return -1;
1021 }
1022
1023 /**
1024  * fcoe_start_io() - pass to netdev to start xmit for fcoe
1025  * @skb: the skb to be xmitted
1026  *
1027  * Returns: 0 for success
1028  */
1029 static inline int fcoe_start_io(struct sk_buff *skb)
1030 {
1031         int rc;
1032
1033         skb_get(skb);
1034         rc = dev_queue_xmit(skb);
1035         if (rc != 0)
1036                 return rc;
1037         kfree_skb(skb);
1038         return 0;
1039 }
1040
1041 /**
1042  * fcoe_get_paged_crc_eof() - in case we need to alloc a page for crc_eof
1043  * @skb: the skb to be xmitted
1044  * @tlen: total len
1045  *
1046  * Returns: 0 for success
1047  */
1048 static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
1049 {
1050         struct fcoe_percpu_s *fps;
1051         struct page *page;
1052
1053         fps = &get_cpu_var(fcoe_percpu);
1054         page = fps->crc_eof_page;
1055         if (!page) {
1056                 page = alloc_page(GFP_ATOMIC);
1057                 if (!page) {
1058                         put_cpu_var(fcoe_percpu);
1059                         return -ENOMEM;
1060                 }
1061                 fps->crc_eof_page = page;
1062                 fps->crc_eof_offset = 0;
1063         }
1064
1065         get_page(page);
1066         skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
1067                            fps->crc_eof_offset, tlen);
1068         skb->len += tlen;
1069         skb->data_len += tlen;
1070         skb->truesize += tlen;
1071         fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
1072
1073         if (fps->crc_eof_offset >= PAGE_SIZE) {
1074                 fps->crc_eof_page = NULL;
1075                 fps->crc_eof_offset = 0;
1076                 put_page(page);
1077         }
1078         put_cpu_var(fcoe_percpu);
1079         return 0;
1080 }
1081
1082 /**
1083  * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
1084  * @fp: the fc_frame containing data to be checksummed
1085  *
1086  * This uses crc32() to calculate the crc for port frame
1087  * Return   : 32 bit crc
1088  */
1089 u32 fcoe_fc_crc(struct fc_frame *fp)
1090 {
1091         struct sk_buff *skb = fp_skb(fp);
1092         struct skb_frag_struct *frag;
1093         unsigned char *data;
1094         unsigned long off, len, clen;
1095         u32 crc;
1096         unsigned i;
1097
1098         crc = crc32(~0, skb->data, skb_headlen(skb));
1099
1100         for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
1101                 frag = &skb_shinfo(skb)->frags[i];
1102                 off = frag->page_offset;
1103                 len = frag->size;
1104                 while (len > 0) {
1105                         clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
1106                         data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
1107                                            KM_SKB_DATA_SOFTIRQ);
1108                         crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
1109                         kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
1110                         off += clen;
1111                         len -= clen;
1112                 }
1113         }
1114         return crc;
1115 }
1116
1117 /**
1118  * fcoe_xmit() - FCoE frame transmit function
1119  * @lp: the associated local fcoe
1120  * @fp: the fc_frame to be transmitted
1121  *
1122  * Return   : 0 for success
1123  */
1124 int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
1125 {
1126         int wlen;
1127         u32 crc;
1128         struct ethhdr *eh;
1129         struct fcoe_crc_eof *cp;
1130         struct sk_buff *skb;
1131         struct fcoe_dev_stats *stats;
1132         struct fc_frame_header *fh;
1133         unsigned int hlen;              /* header length implies the version */
1134         unsigned int tlen;              /* trailer length */
1135         unsigned int elen;              /* eth header, may include vlan */
1136         struct fcoe_port *port;
1137         u8 sof, eof;
1138         struct fcoe_hdr *hp;
1139
1140         WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
1141
1142         port = lport_priv(lp);
1143         fh = fc_frame_header_get(fp);
1144         skb = fp_skb(fp);
1145         wlen = skb->len / FCOE_WORD_TO_BYTE;
1146
1147         if (!lp->link_up) {
1148                 kfree_skb(skb);
1149                 return 0;
1150         }
1151
1152         if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
1153             fcoe_ctlr_els_send(&port->ctlr, skb))
1154                 return 0;
1155
1156         sof = fr_sof(fp);
1157         eof = fr_eof(fp);
1158
1159         elen = sizeof(struct ethhdr);
1160         hlen = sizeof(struct fcoe_hdr);
1161         tlen = sizeof(struct fcoe_crc_eof);
1162         wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
1163
1164         /* crc offload */
1165         if (likely(lp->crc_offload)) {
1166                 skb->ip_summed = CHECKSUM_PARTIAL;
1167                 skb->csum_start = skb_headroom(skb);
1168                 skb->csum_offset = skb->len;
1169                 crc = 0;
1170         } else {
1171                 skb->ip_summed = CHECKSUM_NONE;
1172                 crc = fcoe_fc_crc(fp);
1173         }
1174
1175         /* copy port crc and eof to the skb buff */
1176         if (skb_is_nonlinear(skb)) {
1177                 skb_frag_t *frag;
1178                 if (fcoe_get_paged_crc_eof(skb, tlen)) {
1179                         kfree_skb(skb);
1180                         return -ENOMEM;
1181                 }
1182                 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
1183                 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
1184                         + frag->page_offset;
1185         } else {
1186                 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
1187         }
1188
1189         memset(cp, 0, sizeof(*cp));
1190         cp->fcoe_eof = eof;
1191         cp->fcoe_crc32 = cpu_to_le32(~crc);
1192
1193         if (skb_is_nonlinear(skb)) {
1194                 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
1195                 cp = NULL;
1196         }
1197
1198         /* adjust skb network/transport offsets to match mac/fcoe/port */
1199         skb_push(skb, elen + hlen);
1200         skb_reset_mac_header(skb);
1201         skb_reset_network_header(skb);
1202         skb->mac_len = elen;
1203         skb->protocol = htons(ETH_P_FCOE);
1204         skb->dev = port->fcoe->netdev;
1205
1206         /* fill up mac and fcoe headers */
1207         eh = eth_hdr(skb);
1208         eh->h_proto = htons(ETH_P_FCOE);
1209         if (port->ctlr.map_dest)
1210                 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
1211         else
1212                 /* insert GW address */
1213                 memcpy(eh->h_dest, port->ctlr.dest_addr, ETH_ALEN);
1214
1215         if (unlikely(port->ctlr.flogi_oxid != FC_XID_UNKNOWN))
1216                 memcpy(eh->h_source, port->ctlr.ctl_src_addr, ETH_ALEN);
1217         else
1218                 memcpy(eh->h_source, port->ctlr.data_src_addr, ETH_ALEN);
1219
1220         hp = (struct fcoe_hdr *)(eh + 1);
1221         memset(hp, 0, sizeof(*hp));
1222         if (FC_FCOE_VER)
1223                 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
1224         hp->fcoe_sof = sof;
1225
1226         /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
1227         if (lp->seq_offload && fr_max_payload(fp)) {
1228                 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
1229                 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
1230         } else {
1231                 skb_shinfo(skb)->gso_type = 0;
1232                 skb_shinfo(skb)->gso_size = 0;
1233         }
1234         /* update tx stats: regardless if LLD fails */
1235         stats = fc_lport_get_stats(lp);
1236         stats->TxFrames++;
1237         stats->TxWords += wlen;
1238
1239         /* send down to lld */
1240         fr_dev(fp) = lp;
1241         if (port->fcoe_pending_queue.qlen)
1242                 fcoe_check_wait_queue(lp, skb);
1243         else if (fcoe_start_io(skb))
1244                 fcoe_check_wait_queue(lp, skb);
1245
1246         return 0;
1247 }
1248
1249 /**
1250  * fcoe_percpu_receive_thread() - recv thread per cpu
1251  * @arg: ptr to the fcoe per cpu struct
1252  *
1253  * Return: 0 for success
1254  */
1255 int fcoe_percpu_receive_thread(void *arg)
1256 {
1257         struct fcoe_percpu_s *p = arg;
1258         u32 fr_len;
1259         struct fc_lport *lp;
1260         struct fcoe_rcv_info *fr;
1261         struct fcoe_dev_stats *stats;
1262         struct fc_frame_header *fh;
1263         struct sk_buff *skb;
1264         struct fcoe_crc_eof crc_eof;
1265         struct fc_frame *fp;
1266         u8 *mac = NULL;
1267         struct fcoe_port *port;
1268         struct fcoe_hdr *hp;
1269
1270         set_user_nice(current, -20);
1271
1272         while (!kthread_should_stop()) {
1273
1274                 spin_lock_bh(&p->fcoe_rx_list.lock);
1275                 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
1276                         set_current_state(TASK_INTERRUPTIBLE);
1277                         spin_unlock_bh(&p->fcoe_rx_list.lock);
1278                         schedule();
1279                         set_current_state(TASK_RUNNING);
1280                         if (kthread_should_stop())
1281                                 return 0;
1282                         spin_lock_bh(&p->fcoe_rx_list.lock);
1283                 }
1284                 spin_unlock_bh(&p->fcoe_rx_list.lock);
1285                 fr = fcoe_dev_from_skb(skb);
1286                 lp = fr->fr_dev;
1287                 if (unlikely(lp == NULL)) {
1288                         FCOE_NETDEV_DBG(skb->dev, "Invalid HBA Structure");
1289                         kfree_skb(skb);
1290                         continue;
1291                 }
1292
1293                 FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d "
1294                                 "head:%p data:%p tail:%p end:%p sum:%d dev:%s",
1295                                 skb->len, skb->data_len,
1296                                 skb->head, skb->data, skb_tail_pointer(skb),
1297                                 skb_end_pointer(skb), skb->csum,
1298                                 skb->dev ? skb->dev->name : "<NULL>");
1299
1300                 /*
1301                  * Save source MAC address before discarding header.
1302                  */
1303                 port = lport_priv(lp);
1304                 if (skb_is_nonlinear(skb))
1305                         skb_linearize(skb);     /* not ideal */
1306                 mac = eth_hdr(skb)->h_source;
1307
1308                 /*
1309                  * Frame length checks and setting up the header pointers
1310                  * was done in fcoe_rcv already.
1311                  */
1312                 hp = (struct fcoe_hdr *) skb_network_header(skb);
1313                 fh = (struct fc_frame_header *) skb_transport_header(skb);
1314
1315                 stats = fc_lport_get_stats(lp);
1316                 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
1317                         if (stats->ErrorFrames < 5)
1318                                 printk(KERN_WARNING "fcoe: FCoE version "
1319                                        "mismatch: The frame has "
1320                                        "version %x, but the "
1321                                        "initiator supports version "
1322                                        "%x\n", FC_FCOE_DECAPS_VER(hp),
1323                                        FC_FCOE_VER);
1324                         stats->ErrorFrames++;
1325                         kfree_skb(skb);
1326                         continue;
1327                 }
1328
1329                 skb_pull(skb, sizeof(struct fcoe_hdr));
1330                 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
1331
1332                 stats->RxFrames++;
1333                 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
1334
1335                 fp = (struct fc_frame *)skb;
1336                 fc_frame_init(fp);
1337                 fr_dev(fp) = lp;
1338                 fr_sof(fp) = hp->fcoe_sof;
1339
1340                 /* Copy out the CRC and EOF trailer for access */
1341                 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
1342                         kfree_skb(skb);
1343                         continue;
1344                 }
1345                 fr_eof(fp) = crc_eof.fcoe_eof;
1346                 fr_crc(fp) = crc_eof.fcoe_crc32;
1347                 if (pskb_trim(skb, fr_len)) {
1348                         kfree_skb(skb);
1349                         continue;
1350                 }
1351
1352                 /*
1353                  * We only check CRC if no offload is available and if it is
1354                  * it's solicited data, in which case, the FCP layer would
1355                  * check it during the copy.
1356                  */
1357                 if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
1358                         fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1359                 else
1360                         fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1361
1362                 fh = fc_frame_header_get(fp);
1363                 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
1364                     fh->fh_type == FC_TYPE_FCP) {
1365                         fc_exch_recv(lp, fp);
1366                         continue;
1367                 }
1368                 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
1369                         if (le32_to_cpu(fr_crc(fp)) !=
1370                             ~crc32(~0, skb->data, fr_len)) {
1371                                 if (stats->InvalidCRCCount < 5)
1372                                         printk(KERN_WARNING "fcoe: dropping "
1373                                                "frame with CRC error\n");
1374                                 stats->InvalidCRCCount++;
1375                                 stats->ErrorFrames++;
1376                                 fc_frame_free(fp);
1377                                 continue;
1378                         }
1379                         fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1380                 }
1381                 if (unlikely(port->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
1382                     fcoe_ctlr_recv_flogi(&port->ctlr, fp, mac)) {
1383                         fc_frame_free(fp);
1384                         continue;
1385                 }
1386                 fc_exch_recv(lp, fp);
1387         }
1388         return 0;
1389 }
1390
1391 /**
1392  * fcoe_check_wait_queue() - attempt to clear the transmit backlog
1393  * @lp: the fc_lport
1394  *
1395  * This empties the wait_queue, dequeue the head of the wait_queue queue
1396  * and calls fcoe_start_io() for each packet, if all skb have been
1397  * transmitted, return qlen or -1 if a error occurs, then restore
1398  * wait_queue and try again later.
1399  *
1400  * The wait_queue is used when the skb transmit fails. skb will go
1401  * in the wait_queue which will be emptied by the timer function or
1402  * by the next skb transmit.
1403  */
1404 static void fcoe_check_wait_queue(struct fc_lport *lp, struct sk_buff *skb)
1405 {
1406         struct fcoe_port *port = lport_priv(lp);
1407         int rc;
1408
1409         spin_lock_bh(&port->fcoe_pending_queue.lock);
1410
1411         if (skb)
1412                 __skb_queue_tail(&port->fcoe_pending_queue, skb);
1413
1414         if (port->fcoe_pending_queue_active)
1415                 goto out;
1416         port->fcoe_pending_queue_active = 1;
1417
1418         while (port->fcoe_pending_queue.qlen) {
1419                 /* keep qlen > 0 until fcoe_start_io succeeds */
1420                 port->fcoe_pending_queue.qlen++;
1421                 skb = __skb_dequeue(&port->fcoe_pending_queue);
1422
1423                 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1424                 rc = fcoe_start_io(skb);
1425                 spin_lock_bh(&port->fcoe_pending_queue.lock);
1426
1427                 if (rc) {
1428                         __skb_queue_head(&port->fcoe_pending_queue, skb);
1429                         /* undo temporary increment above */
1430                         port->fcoe_pending_queue.qlen--;
1431                         break;
1432                 }
1433                 /* undo temporary increment above */
1434                 port->fcoe_pending_queue.qlen--;
1435         }
1436
1437         if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
1438                 lp->qfull = 0;
1439         if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
1440                 mod_timer(&port->timer, jiffies + 2);
1441         port->fcoe_pending_queue_active = 0;
1442 out:
1443         if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1444                 lp->qfull = 1;
1445         spin_unlock_bh(&port->fcoe_pending_queue.lock);
1446         return;
1447 }
1448
1449 /**
1450  * fcoe_dev_setup() - setup link change notification interface
1451  */
1452 static void fcoe_dev_setup(void)
1453 {
1454         register_netdevice_notifier(&fcoe_notifier);
1455 }
1456
1457 /**
1458  * fcoe_dev_cleanup() - cleanup link change notification interface
1459  */
1460 static void fcoe_dev_cleanup(void)
1461 {
1462         unregister_netdevice_notifier(&fcoe_notifier);
1463 }
1464
1465 /**
1466  * fcoe_device_notification() - netdev event notification callback
1467  * @notifier: context of the notification
1468  * @event: type of event
1469  * @ptr: fixed array for output parsed ifname
1470  *
1471  * This function is called by the ethernet driver in case of link change event
1472  *
1473  * Returns: 0 for success
1474  */
1475 static int fcoe_device_notification(struct notifier_block *notifier,
1476                                     ulong event, void *ptr)
1477 {
1478         struct fc_lport *lp = NULL;
1479         struct net_device *netdev = ptr;
1480         struct fcoe_interface *fcoe;
1481         struct fcoe_port *port = NULL;
1482         struct fcoe_dev_stats *stats;
1483         u32 link_possible = 1;
1484         u32 mfs;
1485         int rc = NOTIFY_OK;
1486
1487         read_lock(&fcoe_hostlist_lock);
1488         list_for_each_entry(fcoe, &fcoe_hostlist, list) {
1489                 port = fcoe->priv;
1490                 if (fcoe->netdev == netdev) {
1491                         lp = port->ctlr.lp;
1492                         break;
1493                 }
1494         }
1495         read_unlock(&fcoe_hostlist_lock);
1496         if (lp == NULL) {
1497                 rc = NOTIFY_DONE;
1498                 goto out;
1499         }
1500
1501         switch (event) {
1502         case NETDEV_DOWN:
1503         case NETDEV_GOING_DOWN:
1504                 link_possible = 0;
1505                 break;
1506         case NETDEV_UP:
1507         case NETDEV_CHANGE:
1508                 break;
1509         case NETDEV_CHANGEMTU:
1510                 mfs = netdev->mtu - (sizeof(struct fcoe_hdr) +
1511                                      sizeof(struct fcoe_crc_eof));
1512                 if (mfs >= FC_MIN_MAX_FRAME)
1513                         fc_set_mfs(lp, mfs);
1514                 break;
1515         case NETDEV_REGISTER:
1516                 break;
1517         default:
1518                 FCOE_NETDEV_DBG(netdev, "Unknown event %ld "
1519                                 "from netdev netlink\n", event);
1520         }
1521         if (link_possible && !fcoe_link_ok(lp))
1522                 fcoe_ctlr_link_up(&port->ctlr);
1523         else if (fcoe_ctlr_link_down(&port->ctlr)) {
1524                 stats = fc_lport_get_stats(lp);
1525                 stats->LinkFailureCount++;
1526                 fcoe_clean_pending_queue(lp);
1527         }
1528 out:
1529         return rc;
1530 }
1531
1532 /**
1533  * fcoe_if_to_netdev() - parse a name buffer to get netdev
1534  * @buffer: incoming buffer to be copied
1535  *
1536  * Returns: NULL or ptr to net_device
1537  */
1538 static struct net_device *fcoe_if_to_netdev(const char *buffer)
1539 {
1540         char *cp;
1541         char ifname[IFNAMSIZ + 2];
1542
1543         if (buffer) {
1544                 strlcpy(ifname, buffer, IFNAMSIZ);
1545                 cp = ifname + strlen(ifname);
1546                 while (--cp >= ifname && *cp == '\n')
1547                         *cp = '\0';
1548                 return dev_get_by_name(&init_net, ifname);
1549         }
1550         return NULL;
1551 }
1552
1553 /**
1554  * fcoe_netdev_to_module_owner() - finds out the driver module of the netdev
1555  * @netdev: the target netdev
1556  *
1557  * Returns: ptr to the struct module, NULL for failure
1558  */
1559 static struct module *
1560 fcoe_netdev_to_module_owner(const struct net_device *netdev)
1561 {
1562         struct device *dev;
1563
1564         if (!netdev)
1565                 return NULL;
1566
1567         dev = netdev->dev.parent;
1568         if (!dev)
1569                 return NULL;
1570
1571         if (!dev->driver)
1572                 return NULL;
1573
1574         return dev->driver->owner;
1575 }
1576
1577 /**
1578  * fcoe_ethdrv_get() - Hold the Ethernet driver
1579  * @netdev: the target netdev
1580  *
1581  * Holds the Ethernet driver module by try_module_get() for
1582  * the corresponding netdev.
1583  *
1584  * Returns: 0 for success
1585  */
1586 static int fcoe_ethdrv_get(const struct net_device *netdev)
1587 {
1588         struct module *owner;
1589
1590         owner = fcoe_netdev_to_module_owner(netdev);
1591         if (owner) {
1592                 FCOE_NETDEV_DBG(netdev, "Hold driver module %s\n",
1593                                 module_name(owner));
1594                 return  try_module_get(owner);
1595         }
1596         return -ENODEV;
1597 }
1598
1599 /**
1600  * fcoe_ethdrv_put() - Release the Ethernet driver
1601  * @netdev: the target netdev
1602  *
1603  * Releases the Ethernet driver module by module_put for
1604  * the corresponding netdev.
1605  *
1606  * Returns: 0 for success
1607  */
1608 static int fcoe_ethdrv_put(const struct net_device *netdev)
1609 {
1610         struct module *owner;
1611
1612         owner = fcoe_netdev_to_module_owner(netdev);
1613         if (owner) {
1614                 FCOE_NETDEV_DBG(netdev, "Release driver module %s\n",
1615                                 module_name(owner));
1616                 module_put(owner);
1617                 return 0;
1618         }
1619         return -ENODEV;
1620 }
1621
1622 /**
1623  * fcoe_destroy() - handles the destroy from sysfs
1624  * @buffer: expected to be an eth if name
1625  * @kp: associated kernel param
1626  *
1627  * Returns: 0 for success
1628  */
1629 static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
1630 {
1631         struct net_device *netdev;
1632         struct fc_lport *lport;
1633         int rc;
1634
1635         netdev = fcoe_if_to_netdev(buffer);
1636         if (!netdev) {
1637                 rc = -ENODEV;
1638                 goto out_nodev;
1639         }
1640         /* look for existing lport */
1641         lport = fcoe_hostlist_lookup(netdev);
1642         if (!lport) {
1643                 rc = -ENODEV;
1644                 goto out_putdev;
1645         }
1646         fcoe_if_destroy(lport);
1647         fcoe_ethdrv_put(netdev);
1648         rc = 0;
1649 out_putdev:
1650         dev_put(netdev);
1651 out_nodev:
1652         return rc;
1653 }
1654
1655 /**
1656  * fcoe_create() - Handles the create call from sysfs
1657  * @buffer: expected to be an eth if name
1658  * @kp: associated kernel param
1659  *
1660  * Returns: 0 for success
1661  */
1662 static int fcoe_create(const char *buffer, struct kernel_param *kp)
1663 {
1664         int rc;
1665         struct fc_lport *lport;
1666         struct net_device *netdev;
1667
1668         netdev = fcoe_if_to_netdev(buffer);
1669         if (!netdev) {
1670                 rc = -ENODEV;
1671                 goto out_nodev;
1672         }
1673         /* look for existing lport */
1674         if (fcoe_hostlist_lookup(netdev)) {
1675                 rc = -EEXIST;
1676                 goto out_putdev;
1677         }
1678         fcoe_ethdrv_get(netdev);
1679
1680         lport = fcoe_if_create(netdev, &netdev->dev);
1681         if (IS_ERR(lport)) {
1682                 printk(KERN_ERR "fcoe: Failed to create interface (%s)\n",
1683                        netdev->name);
1684                 fcoe_ethdrv_put(netdev);
1685                 rc = -EIO;
1686                 goto out_putdev;
1687         }
1688         rc = 0;
1689 out_putdev:
1690         dev_put(netdev);
1691 out_nodev:
1692         return rc;
1693 }
1694
1695 module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
1696 __MODULE_PARM_TYPE(create, "string");
1697 MODULE_PARM_DESC(create, "Create fcoe fcoe using net device passed in.");
1698 module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
1699 __MODULE_PARM_TYPE(destroy, "string");
1700 MODULE_PARM_DESC(destroy, "Destroy fcoe fcoe");
1701
1702 /**
1703  * fcoe_link_ok() - Check if link is ok for the fc_lport
1704  * @lp: ptr to the fc_lport
1705  *
1706  * Any permanently-disqualifying conditions have been previously checked.
1707  * This also updates the speed setting, which may change with link for 100/1000.
1708  *
1709  * This function should probably be checking for PAUSE support at some point
1710  * in the future. Currently Per-priority-pause is not determinable using
1711  * ethtool, so we shouldn't be restrictive until that problem is resolved.
1712  *
1713  * Returns: 0 if link is OK for use by FCoE.
1714  *
1715  */
1716 int fcoe_link_ok(struct fc_lport *lp)
1717 {
1718         struct fcoe_port *port = lport_priv(lp);
1719         struct net_device *dev = port->fcoe->netdev;
1720         struct ethtool_cmd ecmd = { ETHTOOL_GSET };
1721
1722         if ((dev->flags & IFF_UP) && netif_carrier_ok(dev) &&
1723             (!dev_ethtool_get_settings(dev, &ecmd))) {
1724                 lp->link_supported_speeds &=
1725                         ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
1726                 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
1727                                       SUPPORTED_1000baseT_Full))
1728                         lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
1729                 if (ecmd.supported & SUPPORTED_10000baseT_Full)
1730                         lp->link_supported_speeds |=
1731                                 FC_PORTSPEED_10GBIT;
1732                 if (ecmd.speed == SPEED_1000)
1733                         lp->link_speed = FC_PORTSPEED_1GBIT;
1734                 if (ecmd.speed == SPEED_10000)
1735                         lp->link_speed = FC_PORTSPEED_10GBIT;
1736
1737                 return 0;
1738         }
1739         return -1;
1740 }
1741
1742 /**
1743  * fcoe_percpu_clean() - Clear the pending skbs for an lport
1744  * @lp: the fc_lport
1745  */
1746 void fcoe_percpu_clean(struct fc_lport *lp)
1747 {
1748         struct fcoe_percpu_s *pp;
1749         struct fcoe_rcv_info *fr;
1750         struct sk_buff_head *list;
1751         struct sk_buff *skb, *next;
1752         struct sk_buff *head;
1753         unsigned int cpu;
1754
1755         for_each_possible_cpu(cpu) {
1756                 pp = &per_cpu(fcoe_percpu, cpu);
1757                 spin_lock_bh(&pp->fcoe_rx_list.lock);
1758                 list = &pp->fcoe_rx_list;
1759                 head = list->next;
1760                 for (skb = head; skb != (struct sk_buff *)list;
1761                      skb = next) {
1762                         next = skb->next;
1763                         fr = fcoe_dev_from_skb(skb);
1764                         if (fr->fr_dev == lp) {
1765                                 __skb_unlink(skb, list);
1766                                 kfree_skb(skb);
1767                         }
1768                 }
1769                 spin_unlock_bh(&pp->fcoe_rx_list.lock);
1770         }
1771 }
1772
1773 /**
1774  * fcoe_clean_pending_queue() - Dequeue a skb and free it
1775  * @lp: the corresponding fc_lport
1776  *
1777  * Returns: none
1778  */
1779 void fcoe_clean_pending_queue(struct fc_lport *lp)
1780 {
1781         struct fcoe_port  *port = lport_priv(lp);
1782         struct sk_buff *skb;
1783
1784         spin_lock_bh(&port->fcoe_pending_queue.lock);
1785         while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
1786                 spin_unlock_bh(&port->fcoe_pending_queue.lock);
1787                 kfree_skb(skb);
1788                 spin_lock_bh(&port->fcoe_pending_queue.lock);
1789         }
1790         spin_unlock_bh(&port->fcoe_pending_queue.lock);
1791 }
1792
1793 /**
1794  * fcoe_reset() - Resets the fcoe
1795  * @shost: shost the reset is from
1796  *
1797  * Returns: always 0
1798  */
1799 int fcoe_reset(struct Scsi_Host *shost)
1800 {
1801         struct fc_lport *lport = shost_priv(shost);
1802         fc_lport_reset(lport);
1803         return 0;
1804 }
1805
1806 /**
1807  * fcoe_hostlist_lookup_port() - find the corresponding lport by a given device
1808  * @dev: this is currently ptr to net_device
1809  *
1810  * Called with fcoe_hostlist_lock held.
1811  *
1812  * Returns: NULL or the located fcoe_port
1813  */
1814 static struct fcoe_interface *
1815 fcoe_hostlist_lookup_port(const struct net_device *dev)
1816 {
1817         struct fcoe_interface *fcoe;
1818
1819         list_for_each_entry(fcoe, &fcoe_hostlist, list) {
1820                 if (fcoe->netdev == dev)
1821                         return fcoe;
1822         }
1823         return NULL;
1824 }
1825
1826 /**
1827  * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
1828  * @netdev: ptr to net_device
1829  *
1830  * Returns: 0 for success
1831  */
1832 struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
1833 {
1834         struct fcoe_interface *fcoe;
1835
1836         read_lock(&fcoe_hostlist_lock);
1837         fcoe = fcoe_hostlist_lookup_port(netdev);
1838         read_unlock(&fcoe_hostlist_lock);
1839
1840         return (fcoe) ? fcoe->priv->ctlr.lp : NULL;
1841 }
1842
1843 /**
1844  * fcoe_hostlist_add() - Add a lport to lports list
1845  * @lp: ptr to the fc_lport to be added
1846  *
1847  * Called with write fcoe_hostlist_lock held.
1848  *
1849  * Returns: 0 for success
1850  */
1851 int fcoe_hostlist_add(const struct fc_lport *lport)
1852 {
1853         struct fcoe_interface *fcoe;
1854         struct fcoe_port *port;
1855
1856         fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
1857         if (!fcoe) {
1858                 port = lport_priv(lport);
1859                 fcoe = port->fcoe;
1860                 list_add_tail(&fcoe->list, &fcoe_hostlist);
1861         }
1862         return 0;
1863 }
1864
1865 /**
1866  * fcoe_hostlist_remove() - remove a lport from lports list
1867  * @lp: ptr to the fc_lport to be removed
1868  *
1869  * Returns: 0 for success
1870  */
1871 int fcoe_hostlist_remove(const struct fc_lport *lport)
1872 {
1873         struct fcoe_interface *fcoe;
1874
1875         write_lock_bh(&fcoe_hostlist_lock);
1876         fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport));
1877         BUG_ON(!fcoe);
1878         list_del(&fcoe->list);
1879         write_unlock_bh(&fcoe_hostlist_lock);
1880
1881         return 0;
1882 }
1883
1884 /**
1885  * fcoe_init() - fcoe module loading initialization
1886  *
1887  * Returns 0 on success, negative on failure
1888  */
1889 static int __init fcoe_init(void)
1890 {
1891         unsigned int cpu;
1892         int rc = 0;
1893         struct fcoe_percpu_s *p;
1894
1895         for_each_possible_cpu(cpu) {
1896                 p = &per_cpu(fcoe_percpu, cpu);
1897                 skb_queue_head_init(&p->fcoe_rx_list);
1898         }
1899
1900         for_each_online_cpu(cpu)
1901                 fcoe_percpu_thread_create(cpu);
1902
1903         /* Initialize per CPU interrupt thread */
1904         rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
1905         if (rc)
1906                 goto out_free;
1907
1908         /* Setup link change notification */
1909         fcoe_dev_setup();
1910
1911         rc = fcoe_if_init();
1912         if (rc)
1913                 goto out_free;
1914
1915         return 0;
1916
1917 out_free:
1918         for_each_online_cpu(cpu) {
1919                 fcoe_percpu_thread_destroy(cpu);
1920         }
1921
1922         return rc;
1923 }
1924 module_init(fcoe_init);
1925
1926 /**
1927  * fcoe_exit() - fcoe module unloading cleanup
1928  *
1929  * Returns 0 on success, negative on failure
1930  */
1931 static void __exit fcoe_exit(void)
1932 {
1933         unsigned int cpu;
1934         struct fcoe_interface *fcoe, *tmp;
1935
1936         fcoe_dev_cleanup();
1937
1938         /* releases the associated fcoe hosts */
1939         list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list)
1940                 fcoe_if_destroy(fcoe->priv->ctlr.lp);
1941
1942         unregister_hotcpu_notifier(&fcoe_cpu_notifier);
1943
1944         for_each_online_cpu(cpu)
1945                 fcoe_percpu_thread_destroy(cpu);
1946
1947         /* detach from scsi transport */
1948         fcoe_if_exit();
1949 }
1950 module_exit(fcoe_exit);