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