2 * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved.
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.
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
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.
17 * Maintained at www.Open-FCoE.org
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>
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>
39 #include <scsi/fc/fc_encaps.h>
40 #include <scsi/fc/fc_fip.h>
42 #include <scsi/libfc.h>
43 #include <scsi/fc_frame.h>
44 #include <scsi/libfcoe.h>
48 static int debug_fcoe;
50 MODULE_AUTHOR("Open-FCoE.org");
51 MODULE_DESCRIPTION("FCoE");
52 MODULE_LICENSE("GPL v2");
55 LIST_HEAD(fcoe_hostlist);
56 DEFINE_RWLOCK(fcoe_hostlist_lock);
57 DEFINE_TIMER(fcoe_timer, NULL, 0, 0);
58 DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
60 /* Function Prototyes */
61 static int fcoe_reset(struct Scsi_Host *shost);
62 static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
63 static int fcoe_rcv(struct sk_buff *, struct net_device *,
64 struct packet_type *, struct net_device *);
65 static int fcoe_percpu_receive_thread(void *arg);
66 static void fcoe_clean_pending_queue(struct fc_lport *lp);
67 static void fcoe_percpu_clean(struct fc_lport *lp);
68 static int fcoe_link_ok(struct fc_lport *lp);
70 static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
71 static int fcoe_hostlist_add(const struct fc_lport *);
72 static int fcoe_hostlist_remove(const struct fc_lport *);
74 static int fcoe_check_wait_queue(struct fc_lport *);
75 static int fcoe_device_notification(struct notifier_block *, ulong, void *);
76 static void fcoe_dev_setup(void);
77 static void fcoe_dev_cleanup(void);
79 /* notification function from net device */
80 static struct notifier_block fcoe_notifier = {
81 .notifier_call = fcoe_device_notification,
84 static struct scsi_transport_template *scsi_transport_fcoe_sw;
86 struct 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,
94 .show_host_port_id = 1,
95 .show_host_supported_speeds = 1,
96 .get_host_speed = fc_get_host_speed,
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,
103 .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
104 .show_rport_maxframe_size = 1,
105 .show_rport_supported_classes = 1,
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,
116 .terminate_rport_io = fc_rport_terminate_io,
119 static 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,
132 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
133 .use_clustering = ENABLE_CLUSTERING,
134 .sg_tablesize = SG_ALL,
135 .max_sectors = 0xffff,
139 * fcoe_lport_config() - sets up the fc_lport
140 * @lp: ptr to the fc_lport
141 * @shost: ptr to the parent scsi host
143 * Returns: 0 for success
145 static int fcoe_lport_config(struct fc_lport *lp)
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);
155 fc_lport_init_stats(lp);
157 /* lport fc_lport related configuration */
160 /* offload related configuration */
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
175 * Must be called after fcoe_lport_config() as it will use lport mutex
177 * Returns : 0 for success
179 static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
183 struct fcoe_softc *fc;
184 u8 flogi_maddr[ETH_ALEN];
186 /* Setup lport private data to point to fcoe softc */
189 fc->real_dev = netdev;
190 fc->phys_dev = netdev;
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);
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)) {
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.
208 mfs = fc->real_dev->mtu - (sizeof(struct fcoe_hdr) +
209 sizeof(struct fcoe_crc_eof));
210 if (fc_set_mfs(lp, mfs))
213 /* offload features support */
214 if (fc->real_dev->features & NETIF_F_SG)
217 #ifdef NETIF_F_FCOE_CRC
218 if (netdev->features & NETIF_F_FCOE_CRC) {
220 printk(KERN_DEBUG "fcoe:%s supports FCCRC offload\n",
225 if (netdev->features & NETIF_F_FSO) {
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);
232 if (netdev->fcoe_ddp_xid) {
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);
238 skb_queue_head_init(&fc->fcoe_pending_queue);
239 fc->fcoe_pending_queue_active = 0;
241 /* setup Source Mac Address */
242 memcpy(fc->ctlr.ctl_src_addr, fc->real_dev->dev_addr,
243 fc->real_dev->addr_len);
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);
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.
257 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
258 dev_unicast_add(fc->real_dev, flogi_maddr, ETH_ALEN);
262 * setup the receive function from ethernet driver
263 * on the ethertype for the given device
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);
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
279 * Must be called after fcoe_lport_config() and fcoe_netdev_config()
281 * Returns : 0 for success
283 static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
288 /* lport scsi host config */
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;
296 /* add the new host to the SCSI-ml */
297 rc = scsi_add_host(lp->host, dev);
299 FC_DBG("fcoe_shost_config:error on scsi_add_host\n");
302 sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
303 FCOE_NAME, FCOE_VERSION,
304 fcoe_netdev(lp)->name);
310 * fcoe_em_config() - allocates em for this lport
311 * @lp: the port that em is to allocated for
313 * Returns : 0 on success
315 static inline int fcoe_em_config(struct fc_lport *lp)
319 lp->emp = fc_exch_mgr_alloc(lp, FC_CLASS_3,
320 FCOE_MIN_XID, FCOE_MAX_XID);
328 * fcoe_if_destroy() - FCoE software HBA tear-down function
329 * @netdev: ptr to the associated net_device
331 * Returns: 0 if link is OK for use by FCoE.
333 static int fcoe_if_destroy(struct net_device *netdev)
335 struct fc_lport *lp = NULL;
336 struct fcoe_softc *fc;
337 u8 flogi_maddr[ETH_ALEN];
341 printk(KERN_DEBUG "fcoe_if_destroy:interface on %s\n",
344 lp = fcoe_hostlist_lookup(netdev);
350 /* Logout of the fabric */
351 fc_fabric_logoff(lp);
353 /* Remove the instance from fcoe's list */
354 fcoe_hostlist_remove(lp);
356 /* Don't listen for Ethernet packets anymore */
357 dev_remove_pack(&fc->fcoe_packet_type);
358 dev_remove_pack(&fc->fip_packet_type);
359 fcoe_ctlr_destroy(&fc->ctlr);
361 /* Cleanup the fc_lport */
362 fc_lport_destroy(lp);
365 /* Detach from the scsi-ml */
366 fc_remove_host(lp->host);
367 scsi_remove_host(lp->host);
369 /* There are no more rports or I/O, free the EM */
371 fc_exch_mgr_free(lp->emp);
373 /* Delete secondary MAC addresses */
375 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
376 dev_unicast_delete(fc->real_dev, flogi_maddr, ETH_ALEN);
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);
383 /* Free the per-CPU revieve threads */
384 fcoe_percpu_clean(lp);
386 /* Free existing skbs */
387 fcoe_clean_pending_queue(lp);
389 /* Free memory used by statistical counters */
390 fc_lport_free_stats(lp);
392 /* Release the net_device and Scsi_Host */
393 dev_put(fc->real_dev);
394 scsi_host_put(lp->host);
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
408 static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
409 struct scatterlist *sgl, unsigned int sgc)
411 struct net_device *n = fcoe_netdev(lp);
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);
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
424 * Returns : the length of data that have been completed by ddp
426 static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
428 struct net_device *n = fcoe_netdev(lp);
430 if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_done)
431 return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
435 static 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,
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.
448 * Returns: 0 for success
450 static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev,
451 struct packet_type *ptype,
452 struct net_device *orig_dev)
454 struct fcoe_softc *fc;
456 fc = container_of(ptype, struct fcoe_softc, fip_packet_type);
457 fcoe_ctlr_recv(&fc->ctlr, skb);
462 * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame.
463 * @fip: FCoE controller.
466 static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb)
468 skb->dev = fcoe_from_ctlr(fip)->real_dev;
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.
478 * Remove any previously-set unicast MAC filter.
479 * Add secondary FCoE MAC address filter for our OUI.
481 static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new)
483 struct fcoe_softc *fc;
485 fc = fcoe_from_ctlr(fip);
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);
494 * fcoe_if_create() - this function creates the fcoe interface
495 * @netdev: pointer the associated netdevice
497 * Creates fc_lport struct and scsi_host for lport, configures lport
498 * and starts fabric login.
500 * Returns : 0 on success
502 static int fcoe_if_create(struct net_device *netdev)
505 struct fc_lport *lp = NULL;
506 struct fcoe_softc *fc;
507 struct Scsi_Host *shost;
511 printk(KERN_DEBUG "fcoe_if_create:interface on %s\n",
514 lp = fcoe_hostlist_lookup(netdev);
518 shost = libfc_host_alloc(&fcoe_shost_template,
519 sizeof(struct fcoe_softc));
521 FC_DBG("Could not allocate host structure\n");
524 lp = shost_priv(shost);
527 /* configure fc_lport, e.g., em */
528 rc = fcoe_lport_config(lp);
530 FC_DBG("Could not configure lport\n");
534 /* configure lport network properties */
535 rc = fcoe_netdev_config(lp, netdev);
537 FC_DBG("Could not configure netdev for lport\n");
544 fcoe_ctlr_init(&fc->ctlr);
545 fc->ctlr.send = fcoe_fip_send;
546 fc->ctlr.update_mac = fcoe_update_src_mac;
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);
553 /* configure lport scsi host properties */
554 rc = fcoe_shost_config(lp, shost, &netdev->dev);
556 FC_DBG("Could not configure shost for lport\n");
560 /* lport exch manager allocation */
561 rc = fcoe_em_config(lp);
563 FC_DBG("Could not configure em for lport\n");
567 /* Initialize the library */
568 rc = fcoe_libfc_config(lp, &fcoe_libfc_fcn_templ);
570 FC_DBG("Could not configure libfc for lport!\n");
574 /* add to lports list */
575 fcoe_hostlist_add(lp);
577 lp->boot_time = jiffies;
581 if (!fcoe_link_ok(lp))
582 fcoe_ctlr_link_up(&fc->ctlr);
589 fc_exch_mgr_free(lp->emp); /* Free the EM */
591 scsi_host_put(lp->host);
596 * fcoe_if_init() - attach to scsi transport
598 * Returns : 0 on success
600 static int __init fcoe_if_init(void)
602 /* attach to scsi transport */
603 scsi_transport_fcoe_sw =
604 fc_attach_transport(&fcoe_transport_function);
606 if (!scsi_transport_fcoe_sw) {
607 printk(KERN_ERR "fcoe_init:fc_attach_transport() failed\n");
615 * fcoe_if_exit() - detach from scsi transport
617 * Returns : 0 on success
619 int __exit fcoe_if_exit(void)
621 fc_release_transport(scsi_transport_fcoe_sw);
626 * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
627 * @cpu: cpu index for the online cpu
629 static void fcoe_percpu_thread_create(unsigned int cpu)
631 struct fcoe_percpu_s *p;
632 struct task_struct *thread;
634 p = &per_cpu(fcoe_percpu, cpu);
636 thread = kthread_create(fcoe_percpu_receive_thread,
637 (void *)p, "fcoethread/%d", cpu);
639 if (likely(!IS_ERR(p->thread))) {
640 kthread_bind(thread, cpu);
641 wake_up_process(thread);
643 spin_lock_bh(&p->fcoe_rx_list.lock);
645 spin_unlock_bh(&p->fcoe_rx_list.lock);
650 * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
651 * @cpu: cpu index the rx thread is to be removed
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.
657 static void fcoe_percpu_thread_destroy(unsigned int cpu)
659 struct fcoe_percpu_s *p;
660 struct task_struct *thread;
661 struct page *crc_eof;
664 struct fcoe_percpu_s *p0;
665 unsigned targ_cpu = smp_processor_id();
666 #endif /* CONFIG_SMP */
668 printk(KERN_DEBUG "fcoe: Destroying receive thread for CPU %d\n", cpu);
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);
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);
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.
686 if (cpu != targ_cpu) {
687 p0 = &per_cpu(fcoe_percpu, targ_cpu);
688 spin_lock_bh(&p0->fcoe_rx_list.lock);
690 FC_DBG("Moving frames from CPU %d to CPU %d\n",
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);
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.
702 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
704 spin_unlock_bh(&p0->fcoe_rx_list.lock);
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
716 spin_lock_bh(&p->fcoe_rx_list.lock);
717 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
719 spin_unlock_bh(&p->fcoe_rx_list.lock);
723 * This a non-SMP scenario where the singluar Rx thread is
724 * being removed. Free all skbs and stop the thread.
726 spin_lock_bh(&p->fcoe_rx_list.lock);
727 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
729 spin_unlock_bh(&p->fcoe_rx_list.lock);
733 kthread_stop(thread);
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
745 * This creates or destroys per cpu data for fcoe
747 * Returns NOTIFY_OK always.
749 static int fcoe_cpu_callback(struct notifier_block *nfb,
750 unsigned long action, void *hcpu)
752 unsigned cpu = (unsigned long)hcpu;
756 case CPU_ONLINE_FROZEN:
757 FC_DBG("CPU %x online: Create Rx thread\n", cpu);
758 fcoe_percpu_thread_create(cpu);
761 case CPU_DEAD_FROZEN:
762 FC_DBG("CPU %x offline: Remove Rx thread\n", cpu);
763 fcoe_percpu_thread_destroy(cpu);
771 static struct notifier_block fcoe_cpu_notifier = {
772 .notifier_call = fcoe_cpu_callback,
776 * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
777 * @skb: the receive skb
778 * @dev: associated net device
780 * @odldev: last device
782 * this function will receive the packet and build fc frame and pass it up
784 * Returns: 0 for success
786 int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
787 struct packet_type *ptype, struct net_device *olddev)
790 struct fcoe_rcv_info *fr;
791 struct fcoe_softc *fc;
792 struct fc_frame_header *fh;
793 struct fcoe_percpu_s *fps;
795 unsigned int cpu = 0;
797 fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type);
799 if (unlikely(lp == NULL)) {
800 FC_DBG("cannot find hba structure");
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>");
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");
822 * Check for minimum frame length, and make sure required FCoE
823 * and FC headers are pulled into the linear data area.
825 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
826 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
829 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
830 fh = (struct fc_frame_header *) skb_transport_header(skb);
832 oxid = ntohs(fh->fh_ox_id);
834 fr = fcoe_dev_from_skb(skb);
840 * The incoming frame exchange id(oxid) is ANDed with num of online
841 * cpu bits to get cpu and then this cpu is used for selecting
842 * a per cpu kernel thread from fcoe_percpu.
844 cpu = oxid & (num_online_cpus() - 1);
847 fps = &per_cpu(fcoe_percpu, cpu);
848 spin_lock_bh(&fps->fcoe_rx_list.lock);
849 if (unlikely(!fps->thread)) {
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.
855 FC_DBG("CPU is online, but no receive thread ready "
856 "for incoming skb- using first online CPU.\n");
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);
863 spin_unlock_bh(&fps->fcoe_rx_list.lock);
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.
873 __skb_queue_tail(&fps->fcoe_rx_list, skb);
874 if (fps->fcoe_rx_list.qlen == 1)
875 wake_up_process(fps->thread);
877 spin_unlock_bh(&fps->fcoe_rx_list.lock);
881 fc_lport_get_stats(lp)->ErrorFrames++;
887 EXPORT_SYMBOL_GPL(fcoe_rcv);
890 * fcoe_start_io() - pass to netdev to start xmit for fcoe
891 * @skb: the skb to be xmitted
893 * Returns: 0 for success
895 static inline int fcoe_start_io(struct sk_buff *skb)
900 rc = dev_queue_xmit(skb);
908 * fcoe_get_paged_crc_eof() - in case we need alloc a page for crc_eof
909 * @skb: the skb to be xmitted
912 * Returns: 0 for success
914 static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
916 struct fcoe_percpu_s *fps;
919 fps = &get_cpu_var(fcoe_percpu);
920 page = fps->crc_eof_page;
922 page = alloc_page(GFP_ATOMIC);
924 put_cpu_var(fcoe_percpu);
927 fps->crc_eof_page = page;
928 fps->crc_eof_offset = 0;
932 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
933 fps->crc_eof_offset, tlen);
935 skb->data_len += tlen;
936 skb->truesize += tlen;
937 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
939 if (fps->crc_eof_offset >= PAGE_SIZE) {
940 fps->crc_eof_page = NULL;
941 fps->crc_eof_offset = 0;
944 put_cpu_var(fcoe_percpu);
949 * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
950 * @fp: the fc_frame containg data to be checksummed
952 * This uses crc32() to calculate the crc for fc frame
953 * Return : 32 bit crc
955 u32 fcoe_fc_crc(struct fc_frame *fp)
957 struct sk_buff *skb = fp_skb(fp);
958 struct skb_frag_struct *frag;
960 unsigned long off, len, clen;
964 crc = crc32(~0, skb->data, skb_headlen(skb));
966 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
967 frag = &skb_shinfo(skb)->frags[i];
968 off = frag->page_offset;
971 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
972 data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
973 KM_SKB_DATA_SOFTIRQ);
974 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
975 kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
984 * fcoe_xmit() - FCoE frame transmit function
985 * @lp: the associated local port
986 * @fp: the fc_frame to be transmitted
988 * Return : 0 for success
990 int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
995 struct fcoe_crc_eof *cp;
997 struct fcoe_dev_stats *stats;
998 struct fc_frame_header *fh;
999 unsigned int hlen; /* header length implies the version */
1000 unsigned int tlen; /* trailer length */
1001 unsigned int elen; /* eth header, may include vlan */
1002 struct fcoe_softc *fc;
1004 struct fcoe_hdr *hp;
1006 WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
1008 fc = lport_priv(lp);
1009 fh = fc_frame_header_get(fp);
1011 wlen = skb->len / FCOE_WORD_TO_BYTE;
1018 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) &&
1019 fcoe_ctlr_els_send(&fc->ctlr, skb))
1025 elen = (fc->real_dev->priv_flags & IFF_802_1Q_VLAN) ?
1026 sizeof(struct vlan_ethhdr) : sizeof(struct ethhdr);
1027 hlen = sizeof(struct fcoe_hdr);
1028 tlen = sizeof(struct fcoe_crc_eof);
1029 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
1032 if (likely(lp->crc_offload)) {
1033 skb->ip_summed = CHECKSUM_PARTIAL;
1034 skb->csum_start = skb_headroom(skb);
1035 skb->csum_offset = skb->len;
1038 skb->ip_summed = CHECKSUM_NONE;
1039 crc = fcoe_fc_crc(fp);
1042 /* copy fc crc and eof to the skb buff */
1043 if (skb_is_nonlinear(skb)) {
1045 if (fcoe_get_paged_crc_eof(skb, tlen)) {
1049 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
1050 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
1051 + frag->page_offset;
1053 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
1056 memset(cp, 0, sizeof(*cp));
1058 cp->fcoe_crc32 = cpu_to_le32(~crc);
1060 if (skb_is_nonlinear(skb)) {
1061 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
1065 /* adjust skb netowrk/transport offsets to match mac/fcoe/fc */
1066 skb_push(skb, elen + hlen);
1067 skb_reset_mac_header(skb);
1068 skb_reset_network_header(skb);
1069 skb->mac_len = elen;
1070 skb->protocol = htons(ETH_P_FCOE);
1071 skb->dev = fc->real_dev;
1073 /* fill up mac and fcoe headers */
1075 eh->h_proto = htons(ETH_P_FCOE);
1076 if (fc->ctlr.map_dest)
1077 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
1079 /* insert GW address */
1080 memcpy(eh->h_dest, fc->ctlr.dest_addr, ETH_ALEN);
1082 if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN))
1083 memcpy(eh->h_source, fc->ctlr.ctl_src_addr, ETH_ALEN);
1085 memcpy(eh->h_source, fc->ctlr.data_src_addr, ETH_ALEN);
1087 hp = (struct fcoe_hdr *)(eh + 1);
1088 memset(hp, 0, sizeof(*hp));
1090 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
1094 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
1095 if (lp->seq_offload && fr_max_payload(fp)) {
1096 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
1097 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
1099 skb_shinfo(skb)->gso_type = 0;
1100 skb_shinfo(skb)->gso_size = 0;
1103 /* update tx stats: regardless if LLD fails */
1104 stats = fc_lport_get_stats(lp);
1106 stats->TxWords += wlen;
1108 /* send down to lld */
1110 if (fc->fcoe_pending_queue.qlen)
1111 rc = fcoe_check_wait_queue(lp);
1114 rc = fcoe_start_io(skb);
1117 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1118 __skb_queue_tail(&fc->fcoe_pending_queue, skb);
1119 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1120 if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1126 EXPORT_SYMBOL_GPL(fcoe_xmit);
1129 * fcoe_percpu_receive_thread() - recv thread per cpu
1130 * @arg: ptr to the fcoe per cpu struct
1132 * Return: 0 for success
1134 int fcoe_percpu_receive_thread(void *arg)
1136 struct fcoe_percpu_s *p = arg;
1138 struct fc_lport *lp;
1139 struct fcoe_rcv_info *fr;
1140 struct fcoe_dev_stats *stats;
1141 struct fc_frame_header *fh;
1142 struct sk_buff *skb;
1143 struct fcoe_crc_eof crc_eof;
1144 struct fc_frame *fp;
1146 struct fcoe_softc *fc;
1147 struct fcoe_hdr *hp;
1149 set_user_nice(current, -20);
1151 while (!kthread_should_stop()) {
1153 spin_lock_bh(&p->fcoe_rx_list.lock);
1154 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
1155 set_current_state(TASK_INTERRUPTIBLE);
1156 spin_unlock_bh(&p->fcoe_rx_list.lock);
1158 set_current_state(TASK_RUNNING);
1159 if (kthread_should_stop())
1161 spin_lock_bh(&p->fcoe_rx_list.lock);
1163 spin_unlock_bh(&p->fcoe_rx_list.lock);
1164 fr = fcoe_dev_from_skb(skb);
1166 if (unlikely(lp == NULL)) {
1167 FC_DBG("invalid HBA Structure");
1172 if (unlikely(debug_fcoe)) {
1173 FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p "
1174 "tail:%p end:%p sum:%d dev:%s",
1175 skb->len, skb->data_len,
1176 skb->head, skb->data, skb_tail_pointer(skb),
1177 skb_end_pointer(skb), skb->csum,
1178 skb->dev ? skb->dev->name : "<NULL>");
1182 * Save source MAC address before discarding header.
1184 fc = lport_priv(lp);
1185 if (skb_is_nonlinear(skb))
1186 skb_linearize(skb); /* not ideal */
1187 mac = eth_hdr(skb)->h_source;
1190 * Frame length checks and setting up the header pointers
1191 * was done in fcoe_rcv already.
1193 hp = (struct fcoe_hdr *) skb_network_header(skb);
1194 fh = (struct fc_frame_header *) skb_transport_header(skb);
1196 stats = fc_lport_get_stats(lp);
1197 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
1198 if (stats->ErrorFrames < 5)
1199 printk(KERN_WARNING "FCoE version "
1200 "mismatch: The frame has "
1201 "version %x, but the "
1202 "initiator supports version "
1203 "%x\n", FC_FCOE_DECAPS_VER(hp),
1205 stats->ErrorFrames++;
1210 skb_pull(skb, sizeof(struct fcoe_hdr));
1211 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
1214 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
1216 fp = (struct fc_frame *)skb;
1219 fr_sof(fp) = hp->fcoe_sof;
1221 /* Copy out the CRC and EOF trailer for access */
1222 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
1226 fr_eof(fp) = crc_eof.fcoe_eof;
1227 fr_crc(fp) = crc_eof.fcoe_crc32;
1228 if (pskb_trim(skb, fr_len)) {
1234 * We only check CRC if no offload is available and if it is
1235 * it's solicited data, in which case, the FCP layer would
1236 * check it during the copy.
1238 if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
1239 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1241 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1243 fh = fc_frame_header_get(fp);
1244 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
1245 fh->fh_type == FC_TYPE_FCP) {
1246 fc_exch_recv(lp, lp->emp, fp);
1249 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
1250 if (le32_to_cpu(fr_crc(fp)) !=
1251 ~crc32(~0, skb->data, fr_len)) {
1252 if (debug_fcoe || stats->InvalidCRCCount < 5)
1253 printk(KERN_WARNING "fcoe: dropping "
1254 "frame with CRC error\n");
1255 stats->InvalidCRCCount++;
1256 stats->ErrorFrames++;
1260 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1262 if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN) &&
1263 fcoe_ctlr_recv_flogi(&fc->ctlr, fp, mac)) {
1267 fc_exch_recv(lp, lp->emp, fp);
1273 * fcoe_watchdog() - fcoe timer callback
1276 * This checks the pending queue length for fcoe and set lport qfull
1277 * if the FCOE_MAX_QUEUE_DEPTH is reached. This is done for all fc_lport on the
1280 * Returns: 0 for success
1282 void fcoe_watchdog(ulong vp)
1284 struct fcoe_softc *fc;
1286 read_lock(&fcoe_hostlist_lock);
1287 list_for_each_entry(fc, &fcoe_hostlist, list) {
1289 fcoe_check_wait_queue(fc->ctlr.lp);
1291 read_unlock(&fcoe_hostlist_lock);
1293 fcoe_timer.expires = jiffies + (1 * HZ);
1294 add_timer(&fcoe_timer);
1299 * fcoe_check_wait_queue() - put the skb into fcoe pending xmit queue
1300 * @lp: the fc_port for this skb
1301 * @skb: the associated skb to be xmitted
1303 * This empties the wait_queue, dequeue the head of the wait_queue queue
1304 * and calls fcoe_start_io() for each packet, if all skb have been
1305 * transmitted, return qlen or -1 if a error occurs, then restore
1306 * wait_queue and try again later.
1308 * The wait_queue is used when the skb transmit fails. skb will go
1309 * in the wait_queue which will be emptied by the time function OR
1310 * by the next skb transmit.
1312 * Returns: 0 for success
1314 static int fcoe_check_wait_queue(struct fc_lport *lp)
1316 struct fcoe_softc *fc = lport_priv(lp);
1317 struct sk_buff *skb;
1320 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1321 if (fc->fcoe_pending_queue_active)
1323 fc->fcoe_pending_queue_active = 1;
1325 while (fc->fcoe_pending_queue.qlen) {
1326 /* keep qlen > 0 until fcoe_start_io succeeds */
1327 fc->fcoe_pending_queue.qlen++;
1328 skb = __skb_dequeue(&fc->fcoe_pending_queue);
1330 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1331 rc = fcoe_start_io(skb);
1332 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1335 __skb_queue_head(&fc->fcoe_pending_queue, skb);
1336 /* undo temporary increment above */
1337 fc->fcoe_pending_queue.qlen--;
1340 /* undo temporary increment above */
1341 fc->fcoe_pending_queue.qlen--;
1344 if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
1346 fc->fcoe_pending_queue_active = 0;
1347 rc = fc->fcoe_pending_queue.qlen;
1349 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1354 * fcoe_dev_setup() - setup link change notification interface
1356 static void fcoe_dev_setup()
1359 * here setup a interface specific wd time to
1360 * monitor the link state
1362 register_netdevice_notifier(&fcoe_notifier);
1366 * fcoe_dev_setup() - cleanup link change notification interface
1368 static void fcoe_dev_cleanup(void)
1370 unregister_netdevice_notifier(&fcoe_notifier);
1374 * fcoe_device_notification() - netdev event notification callback
1375 * @notifier: context of the notification
1376 * @event: type of event
1377 * @ptr: fixed array for output parsed ifname
1379 * This function is called by the ethernet driver in case of link change event
1381 * Returns: 0 for success
1383 static int fcoe_device_notification(struct notifier_block *notifier,
1384 ulong event, void *ptr)
1386 struct fc_lport *lp = NULL;
1387 struct net_device *real_dev = ptr;
1388 struct fcoe_softc *fc;
1389 struct fcoe_dev_stats *stats;
1390 u32 link_possible = 1;
1394 read_lock(&fcoe_hostlist_lock);
1395 list_for_each_entry(fc, &fcoe_hostlist, list) {
1396 if (fc->real_dev == real_dev) {
1401 read_unlock(&fcoe_hostlist_lock);
1409 case NETDEV_GOING_DOWN:
1415 case NETDEV_CHANGEMTU:
1416 mfs = fc->real_dev->mtu -
1417 (sizeof(struct fcoe_hdr) +
1418 sizeof(struct fcoe_crc_eof));
1419 if (mfs >= FC_MIN_MAX_FRAME)
1420 fc_set_mfs(lp, mfs);
1422 case NETDEV_REGISTER:
1425 FC_DBG("Unknown event %ld from netdev netlink\n", event);
1427 if (link_possible && !fcoe_link_ok(lp))
1428 fcoe_ctlr_link_up(&fc->ctlr);
1429 else if (fcoe_ctlr_link_down(&fc->ctlr)) {
1430 stats = fc_lport_get_stats(lp);
1431 stats->LinkFailureCount++;
1432 fcoe_clean_pending_queue(lp);
1439 * fcoe_if_to_netdev() - parse a name buffer to get netdev
1440 * @ifname: fixed array for output parsed ifname
1441 * @buffer: incoming buffer to be copied
1443 * Returns: NULL or ptr to netdeive
1445 static struct net_device *fcoe_if_to_netdev(const char *buffer)
1448 char ifname[IFNAMSIZ + 2];
1451 strlcpy(ifname, buffer, IFNAMSIZ);
1452 cp = ifname + strlen(ifname);
1453 while (--cp >= ifname && *cp == '\n')
1455 return dev_get_by_name(&init_net, ifname);
1461 * fcoe_netdev_to_module_owner() - finds out the nic drive moddule of the netdev
1462 * @netdev: the target netdev
1464 * Returns: ptr to the struct module, NULL for failure
1466 static struct module *
1467 fcoe_netdev_to_module_owner(const struct net_device *netdev)
1474 dev = netdev->dev.parent;
1481 return dev->driver->owner;
1485 * fcoe_ethdrv_get() - Hold the Ethernet driver
1486 * @netdev: the target netdev
1488 * Holds the Ethernet driver module by try_module_get() for
1489 * the corresponding netdev.
1491 * Returns: 0 for succsss
1493 static int fcoe_ethdrv_get(const struct net_device *netdev)
1495 struct module *owner;
1497 owner = fcoe_netdev_to_module_owner(netdev);
1499 printk(KERN_DEBUG "fcoe:hold driver module %s for %s\n",
1500 module_name(owner), netdev->name);
1501 return try_module_get(owner);
1507 * fcoe_ethdrv_put() - Release the Ethernet driver
1508 * @netdev: the target netdev
1510 * Releases the Ethernet driver module by module_put for
1511 * the corresponding netdev.
1513 * Returns: 0 for succsss
1515 static int fcoe_ethdrv_put(const struct net_device *netdev)
1517 struct module *owner;
1519 owner = fcoe_netdev_to_module_owner(netdev);
1521 printk(KERN_DEBUG "fcoe:release driver module %s for %s\n",
1522 module_name(owner), netdev->name);
1530 * fcoe_destroy() - handles the destroy from sysfs
1531 * @buffer: expcted to be a eth if name
1532 * @kp: associated kernel param
1534 * Returns: 0 for success
1536 static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
1539 struct net_device *netdev;
1541 netdev = fcoe_if_to_netdev(buffer);
1546 /* look for existing lport */
1547 if (!fcoe_hostlist_lookup(netdev)) {
1551 rc = fcoe_if_destroy(netdev);
1553 printk(KERN_ERR "fcoe: fcoe_if_destroy(%s) failed\n",
1558 fcoe_ethdrv_put(netdev);
1567 * fcoe_create() - Handles the create call from sysfs
1568 * @buffer: expcted to be a eth if name
1569 * @kp: associated kernel param
1571 * Returns: 0 for success
1573 static int fcoe_create(const char *buffer, struct kernel_param *kp)
1576 struct net_device *netdev;
1578 netdev = fcoe_if_to_netdev(buffer);
1583 /* look for existing lport */
1584 if (fcoe_hostlist_lookup(netdev)) {
1588 fcoe_ethdrv_get(netdev);
1590 rc = fcoe_if_create(netdev);
1592 printk(KERN_ERR "fcoe: fcoe_if_create(%s) failed\n",
1594 fcoe_ethdrv_put(netdev);
1605 module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
1606 __MODULE_PARM_TYPE(create, "string");
1607 MODULE_PARM_DESC(create, "Create fcoe port using net device passed in.");
1608 module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
1609 __MODULE_PARM_TYPE(destroy, "string");
1610 MODULE_PARM_DESC(destroy, "Destroy fcoe port");
1613 * fcoe_link_ok() - Check if link is ok for the fc_lport
1614 * @lp: ptr to the fc_lport
1616 * Any permanently-disqualifying conditions have been previously checked.
1617 * This also updates the speed setting, which may change with link for 100/1000.
1619 * This function should probably be checking for PAUSE support at some point
1620 * in the future. Currently Per-priority-pause is not determinable using
1621 * ethtool, so we shouldn't be restrictive until that problem is resolved.
1623 * Returns: 0 if link is OK for use by FCoE.
1626 int fcoe_link_ok(struct fc_lport *lp)
1628 struct fcoe_softc *fc = lport_priv(lp);
1629 struct net_device *dev = fc->real_dev;
1630 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
1633 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) {
1635 if (dev->ethtool_ops->get_settings) {
1636 dev->ethtool_ops->get_settings(dev, &ecmd);
1637 lp->link_supported_speeds &=
1638 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
1639 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
1640 SUPPORTED_1000baseT_Full))
1641 lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
1642 if (ecmd.supported & SUPPORTED_10000baseT_Full)
1643 lp->link_supported_speeds |=
1644 FC_PORTSPEED_10GBIT;
1645 if (ecmd.speed == SPEED_1000)
1646 lp->link_speed = FC_PORTSPEED_1GBIT;
1647 if (ecmd.speed == SPEED_10000)
1648 lp->link_speed = FC_PORTSPEED_10GBIT;
1655 EXPORT_SYMBOL_GPL(fcoe_link_ok);
1658 * fcoe_percpu_clean() - Clear the pending skbs for an lport
1661 void fcoe_percpu_clean(struct fc_lport *lp)
1663 struct fcoe_percpu_s *pp;
1664 struct fcoe_rcv_info *fr;
1665 struct sk_buff_head *list;
1666 struct sk_buff *skb, *next;
1667 struct sk_buff *head;
1670 for_each_possible_cpu(cpu) {
1671 pp = &per_cpu(fcoe_percpu, cpu);
1672 spin_lock_bh(&pp->fcoe_rx_list.lock);
1673 list = &pp->fcoe_rx_list;
1675 for (skb = head; skb != (struct sk_buff *)list;
1678 fr = fcoe_dev_from_skb(skb);
1679 if (fr->fr_dev == lp) {
1680 __skb_unlink(skb, list);
1684 spin_unlock_bh(&pp->fcoe_rx_list.lock);
1687 EXPORT_SYMBOL_GPL(fcoe_percpu_clean);
1690 * fcoe_clean_pending_queue() - Dequeue a skb and free it
1691 * @lp: the corresponding fc_lport
1695 void fcoe_clean_pending_queue(struct fc_lport *lp)
1697 struct fcoe_softc *fc = lport_priv(lp);
1698 struct sk_buff *skb;
1700 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1701 while ((skb = __skb_dequeue(&fc->fcoe_pending_queue)) != NULL) {
1702 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1704 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1706 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1708 EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue);
1711 * fcoe_reset() - Resets the fcoe
1712 * @shost: shost the reset is from
1716 int fcoe_reset(struct Scsi_Host *shost)
1718 struct fc_lport *lport = shost_priv(shost);
1719 fc_lport_reset(lport);
1722 EXPORT_SYMBOL_GPL(fcoe_reset);
1725 * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device
1726 * @device: this is currently ptr to net_device
1728 * Returns: NULL or the located fcoe_softc
1730 static struct fcoe_softc *
1731 fcoe_hostlist_lookup_softc(const struct net_device *dev)
1733 struct fcoe_softc *fc;
1735 read_lock(&fcoe_hostlist_lock);
1736 list_for_each_entry(fc, &fcoe_hostlist, list) {
1737 if (fc->real_dev == dev) {
1738 read_unlock(&fcoe_hostlist_lock);
1742 read_unlock(&fcoe_hostlist_lock);
1747 * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
1748 * @netdev: ptr to net_device
1750 * Returns: 0 for success
1752 struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
1754 struct fcoe_softc *fc;
1756 fc = fcoe_hostlist_lookup_softc(netdev);
1758 return (fc) ? fc->ctlr.lp : NULL;
1760 EXPORT_SYMBOL_GPL(fcoe_hostlist_lookup);
1763 * fcoe_hostlist_add() - Add a lport to lports list
1764 * @lp: ptr to the fc_lport to badded
1766 * Returns: 0 for success
1768 int fcoe_hostlist_add(const struct fc_lport *lp)
1770 struct fcoe_softc *fc;
1772 fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
1774 fc = lport_priv(lp);
1775 write_lock_bh(&fcoe_hostlist_lock);
1776 list_add_tail(&fc->list, &fcoe_hostlist);
1777 write_unlock_bh(&fcoe_hostlist_lock);
1781 EXPORT_SYMBOL_GPL(fcoe_hostlist_add);
1784 * fcoe_hostlist_remove() - remove a lport from lports list
1785 * @lp: ptr to the fc_lport to badded
1787 * Returns: 0 for success
1789 int fcoe_hostlist_remove(const struct fc_lport *lp)
1791 struct fcoe_softc *fc;
1793 fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
1795 write_lock_bh(&fcoe_hostlist_lock);
1796 list_del(&fc->list);
1797 write_unlock_bh(&fcoe_hostlist_lock);
1801 EXPORT_SYMBOL_GPL(fcoe_hostlist_remove);
1804 * fcoe_init() - fcoe module loading initialization
1806 * Returns 0 on success, negative on failure
1808 static int __init fcoe_init(void)
1812 struct fcoe_percpu_s *p;
1814 INIT_LIST_HEAD(&fcoe_hostlist);
1815 rwlock_init(&fcoe_hostlist_lock);
1817 for_each_possible_cpu(cpu) {
1818 p = &per_cpu(fcoe_percpu, cpu);
1819 skb_queue_head_init(&p->fcoe_rx_list);
1822 for_each_online_cpu(cpu)
1823 fcoe_percpu_thread_create(cpu);
1825 /* Initialize per CPU interrupt thread */
1826 rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
1830 /* Setup link change notification */
1833 setup_timer(&fcoe_timer, fcoe_watchdog, 0);
1835 mod_timer(&fcoe_timer, jiffies + (10 * HZ));
1842 for_each_online_cpu(cpu) {
1843 fcoe_percpu_thread_destroy(cpu);
1848 module_init(fcoe_init);
1851 * fcoe_exit() - fcoe module unloading cleanup
1853 * Returns 0 on success, negative on failure
1855 static void __exit fcoe_exit(void)
1858 struct fcoe_softc *fc, *tmp;
1862 /* Stop the timer */
1863 del_timer_sync(&fcoe_timer);
1865 /* releases the associated fcoe hosts */
1866 list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
1867 fcoe_if_destroy(fc->real_dev);
1869 unregister_hotcpu_notifier(&fcoe_cpu_notifier);
1871 for_each_online_cpu(cpu) {
1872 fcoe_percpu_thread_destroy(cpu);
1875 /* detach from scsi transport */
1878 module_exit(fcoe_exit);