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>
41 #include <scsi/libfc.h>
42 #include <scsi/fc_frame.h>
43 #include <scsi/libfcoe.h>
47 static int debug_fcoe;
49 MODULE_AUTHOR("Open-FCoE.org");
50 MODULE_DESCRIPTION("FCoE");
51 MODULE_LICENSE("GPL v2");
54 LIST_HEAD(fcoe_hostlist);
55 DEFINE_RWLOCK(fcoe_hostlist_lock);
56 DEFINE_TIMER(fcoe_timer, NULL, 0, 0);
57 DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu);
59 /* Function Prototyes */
60 static int fcoe_reset(struct Scsi_Host *shost);
61 static int fcoe_xmit(struct fc_lport *, struct fc_frame *);
62 static int fcoe_rcv(struct sk_buff *, struct net_device *,
63 struct packet_type *, struct net_device *);
64 static int fcoe_percpu_receive_thread(void *arg);
65 static void fcoe_clean_pending_queue(struct fc_lport *lp);
66 static void fcoe_percpu_clean(struct fc_lport *lp);
67 static int fcoe_link_ok(struct fc_lport *lp);
69 static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *);
70 static int fcoe_hostlist_add(const struct fc_lport *);
71 static int fcoe_hostlist_remove(const struct fc_lport *);
73 static struct Scsi_Host *fcoe_host_alloc(struct scsi_host_template *, int);
75 static int fcoe_check_wait_queue(struct fc_lport *);
76 static void fcoe_recv_flogi(struct fcoe_softc *, struct fc_frame *, u8 *);
77 static int fcoe_device_notification(struct notifier_block *, ulong, void *);
78 static void fcoe_dev_setup(void);
79 static void fcoe_dev_cleanup(void);
81 /* notification function from net device */
82 static struct notifier_block fcoe_notifier = {
83 .notifier_call = fcoe_device_notification,
86 static struct scsi_transport_template *scsi_transport_fcoe_sw;
88 struct fc_function_template fcoe_transport_function = {
89 .show_host_node_name = 1,
90 .show_host_port_name = 1,
91 .show_host_supported_classes = 1,
92 .show_host_supported_fc4s = 1,
93 .show_host_active_fc4s = 1,
94 .show_host_maxframe_size = 1,
96 .show_host_port_id = 1,
97 .show_host_supported_speeds = 1,
98 .get_host_speed = fc_get_host_speed,
100 .show_host_port_type = 1,
101 .get_host_port_state = fc_get_host_port_state,
102 .show_host_port_state = 1,
103 .show_host_symbolic_name = 1,
105 .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv),
106 .show_rport_maxframe_size = 1,
107 .show_rport_supported_classes = 1,
109 .show_host_fabric_name = 1,
110 .show_starget_node_name = 1,
111 .show_starget_port_name = 1,
112 .show_starget_port_id = 1,
113 .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo,
114 .show_rport_dev_loss_tmo = 1,
115 .get_fc_host_stats = fc_get_host_stats,
116 .issue_fc_host_lip = fcoe_reset,
118 .terminate_rport_io = fc_rport_terminate_io,
121 static struct scsi_host_template fcoe_shost_template = {
122 .module = THIS_MODULE,
123 .name = "FCoE Driver",
124 .proc_name = FCOE_NAME,
125 .queuecommand = fc_queuecommand,
126 .eh_abort_handler = fc_eh_abort,
127 .eh_device_reset_handler = fc_eh_device_reset,
128 .eh_host_reset_handler = fc_eh_host_reset,
129 .slave_alloc = fc_slave_alloc,
130 .change_queue_depth = fc_change_queue_depth,
131 .change_queue_type = fc_change_queue_type,
134 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
135 .use_clustering = ENABLE_CLUSTERING,
136 .sg_tablesize = SG_ALL,
137 .max_sectors = 0xffff,
141 * fcoe_lport_config() - sets up the fc_lport
142 * @lp: ptr to the fc_lport
143 * @shost: ptr to the parent scsi host
145 * Returns: 0 for success
147 static int fcoe_lport_config(struct fc_lport *lp)
151 lp->max_retry_count = 3;
152 lp->e_d_tov = 2 * 1000; /* FC-FS default */
153 lp->r_a_tov = 2 * 2 * 1000;
154 lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS |
155 FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL);
157 fc_lport_init_stats(lp);
159 /* lport fc_lport related configuration */
162 /* offload related configuration */
173 * fcoe_netdev_config() - Set up netdev for SW FCoE
174 * @lp : ptr to the fc_lport
175 * @netdev : ptr to the associated netdevice struct
177 * Must be called after fcoe_lport_config() as it will use lport mutex
179 * Returns : 0 for success
181 static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev)
185 struct fcoe_softc *fc;
186 u8 flogi_maddr[ETH_ALEN];
188 /* Setup lport private data to point to fcoe softc */
191 fc->real_dev = netdev;
192 fc->phys_dev = netdev;
194 /* Require support for get_pauseparam ethtool op. */
195 if (netdev->priv_flags & IFF_802_1Q_VLAN)
196 fc->phys_dev = vlan_dev_real_dev(netdev);
198 /* Do not support for bonding device */
199 if ((fc->real_dev->priv_flags & IFF_MASTER_ALB) ||
200 (fc->real_dev->priv_flags & IFF_SLAVE_INACTIVE) ||
201 (fc->real_dev->priv_flags & IFF_MASTER_8023AD)) {
206 * Determine max frame size based on underlying device and optional
207 * user-configured limit. If the MFS is too low, fcoe_link_ok()
208 * will return 0, so do this first.
210 mfs = fc->real_dev->mtu - (sizeof(struct fcoe_hdr) +
211 sizeof(struct fcoe_crc_eof));
212 if (fc_set_mfs(lp, mfs))
215 if (!fcoe_link_ok(lp))
218 /* offload features support */
219 if (fc->real_dev->features & NETIF_F_SG)
222 #ifdef NETIF_F_FCOE_CRC
223 if (netdev->features & NETIF_F_FCOE_CRC) {
225 printk(KERN_DEBUG "fcoe:%s supports FCCRC offload\n",
230 if (netdev->features & NETIF_F_FSO) {
232 lp->lso_max = netdev->gso_max_size;
233 printk(KERN_DEBUG "fcoe:%s supports LSO for max len 0x%x\n",
234 netdev->name, lp->lso_max);
237 if (netdev->fcoe_ddp_xid) {
239 lp->lro_xid = netdev->fcoe_ddp_xid;
240 printk(KERN_DEBUG "fcoe:%s supports LRO for max xid 0x%x\n",
241 netdev->name, lp->lro_xid);
243 skb_queue_head_init(&fc->fcoe_pending_queue);
244 fc->fcoe_pending_queue_active = 0;
246 /* setup Source Mac Address */
247 memcpy(fc->ctl_src_addr, fc->real_dev->dev_addr,
248 fc->real_dev->addr_len);
250 wwnn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 1, 0);
251 fc_set_wwnn(lp, wwnn);
252 /* XXX - 3rd arg needs to be vlan id */
253 wwpn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 2, 0);
254 fc_set_wwpn(lp, wwpn);
257 * Add FCoE MAC address as second unicast MAC address
258 * or enter promiscuous mode if not capable of listening
259 * for multiple unicast MACs.
262 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
263 dev_unicast_add(fc->real_dev, flogi_maddr, ETH_ALEN);
267 * setup the receive function from ethernet driver
268 * on the ethertype for the given device
270 fc->fcoe_packet_type.func = fcoe_rcv;
271 fc->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE);
272 fc->fcoe_packet_type.dev = fc->real_dev;
273 dev_add_pack(&fc->fcoe_packet_type);
279 * fcoe_shost_config() - Sets up fc_lport->host
280 * @lp : ptr to the fc_lport
281 * @shost : ptr to the associated scsi host
282 * @dev : device associated to scsi host
284 * Must be called after fcoe_lport_config() and fcoe_netdev_config()
286 * Returns : 0 for success
288 static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost,
293 /* lport scsi host config */
296 lp->host->max_lun = FCOE_MAX_LUN;
297 lp->host->max_id = FCOE_MAX_FCP_TARGET;
298 lp->host->max_channel = 0;
299 lp->host->transportt = scsi_transport_fcoe_sw;
301 /* add the new host to the SCSI-ml */
302 rc = scsi_add_host(lp->host, dev);
304 FC_DBG("fcoe_shost_config:error on scsi_add_host\n");
307 sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s",
308 FCOE_NAME, FCOE_VERSION,
309 fcoe_netdev(lp)->name);
315 * fcoe_em_config() - allocates em for this lport
316 * @lp: the port that em is to allocated for
318 * Returns : 0 on success
320 static inline int fcoe_em_config(struct fc_lport *lp)
324 lp->emp = fc_exch_mgr_alloc(lp, FC_CLASS_3,
325 FCOE_MIN_XID, FCOE_MAX_XID);
333 * fcoe_if_destroy() - FCoE software HBA tear-down function
334 * @netdev: ptr to the associated net_device
336 * Returns: 0 if link is OK for use by FCoE.
338 static int fcoe_if_destroy(struct net_device *netdev)
340 struct fc_lport *lp = NULL;
341 struct fcoe_softc *fc;
342 u8 flogi_maddr[ETH_ALEN];
346 printk(KERN_DEBUG "fcoe_if_destroy:interface on %s\n",
349 lp = fcoe_hostlist_lookup(netdev);
355 /* Logout of the fabric */
356 fc_fabric_logoff(lp);
358 /* Remove the instance from fcoe's list */
359 fcoe_hostlist_remove(lp);
361 /* Don't listen for Ethernet packets anymore */
362 dev_remove_pack(&fc->fcoe_packet_type);
364 /* Cleanup the fc_lport */
365 fc_lport_destroy(lp);
368 /* Detach from the scsi-ml */
369 fc_remove_host(lp->host);
370 scsi_remove_host(lp->host);
372 /* There are no more rports or I/O, free the EM */
374 fc_exch_mgr_free(lp->emp);
376 /* Delete secondary MAC addresses */
378 memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN);
379 dev_unicast_delete(fc->real_dev, flogi_maddr, ETH_ALEN);
380 if (compare_ether_addr(fc->data_src_addr, (u8[6]) { 0 }))
381 dev_unicast_delete(fc->real_dev, fc->data_src_addr, ETH_ALEN);
384 /* Free the per-CPU revieve threads */
385 fcoe_percpu_clean(lp);
387 /* Free existing skbs */
388 fcoe_clean_pending_queue(lp);
390 /* Free memory used by statistical counters */
391 fc_lport_free_stats(lp);
393 /* Release the net_device and Scsi_Host */
394 dev_put(fc->real_dev);
395 scsi_host_put(lp->host);
401 * fcoe_ddp_setup - calls LLD's ddp_setup through net_device
402 * @lp: the corresponding fc_lport
403 * @xid: the exchange id for this ddp transfer
404 * @sgl: the scatterlist describing this transfer
405 * @sgc: number of sg items
409 static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid,
410 struct scatterlist *sgl, unsigned int sgc)
412 struct net_device *n = fcoe_netdev(lp);
414 if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_setup)
415 return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc);
421 * fcoe_ddp_done - calls LLD's ddp_done through net_device
422 * @lp: the corresponding fc_lport
423 * @xid: the exchange id for this ddp transfer
425 * Returns : the length of data that have been completed by ddp
427 static int fcoe_ddp_done(struct fc_lport *lp, u16 xid)
429 struct net_device *n = fcoe_netdev(lp);
431 if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_done)
432 return n->netdev_ops->ndo_fcoe_ddp_done(n, xid);
436 static struct libfc_function_template fcoe_libfc_fcn_templ = {
437 .frame_send = fcoe_xmit,
438 .ddp_setup = fcoe_ddp_setup,
439 .ddp_done = fcoe_ddp_done,
443 * fcoe_if_create() - this function creates the fcoe interface
444 * @netdev: pointer the associated netdevice
446 * Creates fc_lport struct and scsi_host for lport, configures lport
447 * and starts fabric login.
449 * Returns : 0 on success
451 static int fcoe_if_create(struct net_device *netdev)
454 struct fc_lport *lp = NULL;
455 struct fcoe_softc *fc;
456 struct Scsi_Host *shost;
460 printk(KERN_DEBUG "fcoe_if_create:interface on %s\n",
463 lp = fcoe_hostlist_lookup(netdev);
467 shost = fcoe_host_alloc(&fcoe_shost_template,
468 sizeof(struct fcoe_softc));
470 FC_DBG("Could not allocate host structure\n");
473 lp = shost_priv(shost);
476 /* configure fc_lport, e.g., em */
477 rc = fcoe_lport_config(lp);
479 FC_DBG("Could not configure lport\n");
483 /* configure lport network properties */
484 rc = fcoe_netdev_config(lp, netdev);
486 FC_DBG("Could not configure netdev for lport\n");
490 /* configure lport scsi host properties */
491 rc = fcoe_shost_config(lp, shost, &netdev->dev);
493 FC_DBG("Could not configure shost for lport\n");
497 /* lport exch manager allocation */
498 rc = fcoe_em_config(lp);
500 FC_DBG("Could not configure em for lport\n");
504 /* Initialize the library */
505 rc = fcoe_libfc_config(lp, &fcoe_libfc_fcn_templ);
507 FC_DBG("Could not configure libfc for lport!\n");
511 /* add to lports list */
512 fcoe_hostlist_add(lp);
514 lp->boot_time = jiffies;
523 fc_exch_mgr_free(lp->emp); /* Free the EM */
525 scsi_host_put(lp->host);
530 * fcoe_if_init() - attach to scsi transport
532 * Returns : 0 on success
534 static int __init fcoe_if_init(void)
536 /* attach to scsi transport */
537 scsi_transport_fcoe_sw =
538 fc_attach_transport(&fcoe_transport_function);
540 if (!scsi_transport_fcoe_sw) {
541 printk(KERN_ERR "fcoe_init:fc_attach_transport() failed\n");
549 * fcoe_if_exit() - detach from scsi transport
551 * Returns : 0 on success
553 int __exit fcoe_if_exit(void)
555 fc_release_transport(scsi_transport_fcoe_sw);
560 * fcoe_percpu_thread_create() - Create a receive thread for an online cpu
561 * @cpu: cpu index for the online cpu
563 static void fcoe_percpu_thread_create(unsigned int cpu)
565 struct fcoe_percpu_s *p;
566 struct task_struct *thread;
568 p = &per_cpu(fcoe_percpu, cpu);
570 thread = kthread_create(fcoe_percpu_receive_thread,
571 (void *)p, "fcoethread/%d", cpu);
573 if (likely(!IS_ERR(p->thread))) {
574 kthread_bind(thread, cpu);
575 wake_up_process(thread);
577 spin_lock_bh(&p->fcoe_rx_list.lock);
579 spin_unlock_bh(&p->fcoe_rx_list.lock);
584 * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu
585 * @cpu: cpu index the rx thread is to be removed
587 * Destroys a per-CPU Rx thread. Any pending skbs are moved to the
588 * current CPU's Rx thread. If the thread being destroyed is bound to
589 * the CPU processing this context the skbs will be freed.
591 static void fcoe_percpu_thread_destroy(unsigned int cpu)
593 struct fcoe_percpu_s *p;
594 struct task_struct *thread;
595 struct page *crc_eof;
598 struct fcoe_percpu_s *p0;
599 unsigned targ_cpu = smp_processor_id();
600 #endif /* CONFIG_SMP */
602 printk(KERN_DEBUG "fcoe: Destroying receive thread for CPU %d\n", cpu);
604 /* Prevent any new skbs from being queued for this CPU. */
605 p = &per_cpu(fcoe_percpu, cpu);
606 spin_lock_bh(&p->fcoe_rx_list.lock);
609 crc_eof = p->crc_eof_page;
610 p->crc_eof_page = NULL;
611 p->crc_eof_offset = 0;
612 spin_unlock_bh(&p->fcoe_rx_list.lock);
616 * Don't bother moving the skb's if this context is running
617 * on the same CPU that is having its thread destroyed. This
618 * can easily happen when the module is removed.
620 if (cpu != targ_cpu) {
621 p0 = &per_cpu(fcoe_percpu, targ_cpu);
622 spin_lock_bh(&p0->fcoe_rx_list.lock);
624 FC_DBG("Moving frames from CPU %d to CPU %d\n",
627 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
628 __skb_queue_tail(&p0->fcoe_rx_list, skb);
629 spin_unlock_bh(&p0->fcoe_rx_list.lock);
632 * The targeted CPU is not initialized and cannot accept
633 * new skbs. Unlock the targeted CPU and drop the skbs
634 * on the CPU that is going offline.
636 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
638 spin_unlock_bh(&p0->fcoe_rx_list.lock);
642 * This scenario occurs when the module is being removed
643 * and all threads are being destroyed. skbs will continue
644 * to be shifted from the CPU thread that is being removed
645 * to the CPU thread associated with the CPU that is processing
646 * the module removal. Once there is only one CPU Rx thread it
647 * will reach this case and we will drop all skbs and later
650 spin_lock_bh(&p->fcoe_rx_list.lock);
651 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
653 spin_unlock_bh(&p->fcoe_rx_list.lock);
657 * This a non-SMP scenario where the singluar Rx thread is
658 * being removed. Free all skbs and stop the thread.
660 spin_lock_bh(&p->fcoe_rx_list.lock);
661 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL)
663 spin_unlock_bh(&p->fcoe_rx_list.lock);
667 kthread_stop(thread);
674 * fcoe_cpu_callback() - fcoe cpu hotplug event callback
675 * @nfb: callback data block
676 * @action: event triggering the callback
677 * @hcpu: index for the cpu of this event
679 * This creates or destroys per cpu data for fcoe
681 * Returns NOTIFY_OK always.
683 static int fcoe_cpu_callback(struct notifier_block *nfb,
684 unsigned long action, void *hcpu)
686 unsigned cpu = (unsigned long)hcpu;
690 case CPU_ONLINE_FROZEN:
691 FC_DBG("CPU %x online: Create Rx thread\n", cpu);
692 fcoe_percpu_thread_create(cpu);
695 case CPU_DEAD_FROZEN:
696 FC_DBG("CPU %x offline: Remove Rx thread\n", cpu);
697 fcoe_percpu_thread_destroy(cpu);
705 static struct notifier_block fcoe_cpu_notifier = {
706 .notifier_call = fcoe_cpu_callback,
710 * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ
711 * @skb: the receive skb
712 * @dev: associated net device
714 * @odldev: last device
716 * this function will receive the packet and build fc frame and pass it up
718 * Returns: 0 for success
720 int fcoe_rcv(struct sk_buff *skb, struct net_device *dev,
721 struct packet_type *ptype, struct net_device *olddev)
724 struct fcoe_rcv_info *fr;
725 struct fcoe_softc *fc;
726 struct fc_frame_header *fh;
727 struct fcoe_percpu_s *fps;
729 unsigned int cpu = 0;
731 fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type);
733 if (unlikely(lp == NULL)) {
734 FC_DBG("cannot find hba structure");
738 if (unlikely(debug_fcoe)) {
739 FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p tail:%p "
740 "end:%p sum:%d dev:%s", skb->len, skb->data_len,
741 skb->head, skb->data, skb_tail_pointer(skb),
742 skb_end_pointer(skb), skb->csum,
743 skb->dev ? skb->dev->name : "<NULL>");
747 /* check for FCOE packet type */
748 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
749 FC_DBG("wrong FC type frame");
754 * Check for minimum frame length, and make sure required FCoE
755 * and FC headers are pulled into the linear data area.
757 if (unlikely((skb->len < FCOE_MIN_FRAME) ||
758 !pskb_may_pull(skb, FCOE_HEADER_LEN)))
761 skb_set_transport_header(skb, sizeof(struct fcoe_hdr));
762 fh = (struct fc_frame_header *) skb_transport_header(skb);
764 oxid = ntohs(fh->fh_ox_id);
766 fr = fcoe_dev_from_skb(skb);
772 * The incoming frame exchange id(oxid) is ANDed with num of online
773 * cpu bits to get cpu and then this cpu is used for selecting
774 * a per cpu kernel thread from fcoe_percpu.
776 cpu = oxid & (num_online_cpus() - 1);
779 fps = &per_cpu(fcoe_percpu, cpu);
780 spin_lock_bh(&fps->fcoe_rx_list.lock);
781 if (unlikely(!fps->thread)) {
783 * The targeted CPU is not ready, let's target
784 * the first CPU now. For non-SMP systems this
785 * will check the same CPU twice.
787 FC_DBG("CPU is online, but no receive thread ready "
788 "for incoming skb- using first online CPU.\n");
790 spin_unlock_bh(&fps->fcoe_rx_list.lock);
791 cpu = first_cpu(cpu_online_map);
792 fps = &per_cpu(fcoe_percpu, cpu);
793 spin_lock_bh(&fps->fcoe_rx_list.lock);
795 spin_unlock_bh(&fps->fcoe_rx_list.lock);
801 * We now have a valid CPU that we're targeting for
802 * this skb. We also have this receive thread locked,
803 * so we're free to queue skbs into it's queue.
805 __skb_queue_tail(&fps->fcoe_rx_list, skb);
806 if (fps->fcoe_rx_list.qlen == 1)
807 wake_up_process(fps->thread);
809 spin_unlock_bh(&fps->fcoe_rx_list.lock);
813 fc_lport_get_stats(lp)->ErrorFrames++;
819 EXPORT_SYMBOL_GPL(fcoe_rcv);
822 * fcoe_start_io() - pass to netdev to start xmit for fcoe
823 * @skb: the skb to be xmitted
825 * Returns: 0 for success
827 static inline int fcoe_start_io(struct sk_buff *skb)
832 rc = dev_queue_xmit(skb);
840 * fcoe_get_paged_crc_eof() - in case we need alloc a page for crc_eof
841 * @skb: the skb to be xmitted
844 * Returns: 0 for success
846 static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen)
848 struct fcoe_percpu_s *fps;
851 fps = &get_cpu_var(fcoe_percpu);
852 page = fps->crc_eof_page;
854 page = alloc_page(GFP_ATOMIC);
856 put_cpu_var(fcoe_percpu);
859 fps->crc_eof_page = page;
860 fps->crc_eof_offset = 0;
864 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
865 fps->crc_eof_offset, tlen);
867 skb->data_len += tlen;
868 skb->truesize += tlen;
869 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
871 if (fps->crc_eof_offset >= PAGE_SIZE) {
872 fps->crc_eof_page = NULL;
873 fps->crc_eof_offset = 0;
876 put_cpu_var(fcoe_percpu);
881 * fcoe_fc_crc() - calculates FC CRC in this fcoe skb
882 * @fp: the fc_frame containg data to be checksummed
884 * This uses crc32() to calculate the crc for fc frame
885 * Return : 32 bit crc
887 u32 fcoe_fc_crc(struct fc_frame *fp)
889 struct sk_buff *skb = fp_skb(fp);
890 struct skb_frag_struct *frag;
892 unsigned long off, len, clen;
896 crc = crc32(~0, skb->data, skb_headlen(skb));
898 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
899 frag = &skb_shinfo(skb)->frags[i];
900 off = frag->page_offset;
903 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
904 data = kmap_atomic(frag->page + (off >> PAGE_SHIFT),
905 KM_SKB_DATA_SOFTIRQ);
906 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
907 kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ);
916 * fcoe_xmit() - FCoE frame transmit function
917 * @lp: the associated local port
918 * @fp: the fc_frame to be transmitted
920 * Return : 0 for success
922 int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp)
927 struct fcoe_crc_eof *cp;
929 struct fcoe_dev_stats *stats;
930 struct fc_frame_header *fh;
931 unsigned int hlen; /* header length implies the version */
932 unsigned int tlen; /* trailer length */
933 unsigned int elen; /* eth header, may include vlan */
934 int flogi_in_progress = 0;
935 struct fcoe_softc *fc;
939 WARN_ON((fr_len(fp) % sizeof(u32)) != 0);
943 * if it is a flogi then we need to learn gw-addr
946 fh = fc_frame_header_get(fp);
947 if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ)) {
948 if (fc_frame_payload_op(fp) == ELS_FLOGI) {
949 fc->flogi_oxid = ntohs(fh->fh_ox_id);
950 fc->address_mode = FCOE_FCOUI_ADDR_MODE;
951 fc->flogi_progress = 1;
952 flogi_in_progress = 1;
953 } else if (fc->flogi_progress && ntoh24(fh->fh_s_id) != 0) {
955 * Here we must've gotten an SID by accepting an FLOGI
956 * from a point-to-point connection. Switch to using
957 * the source mac based on the SID. The destination
958 * MAC in this case would have been set by receving the
961 fc_fcoe_set_mac(fc->data_src_addr, fh->fh_s_id);
962 fc->flogi_progress = 0;
970 elen = (fc->real_dev->priv_flags & IFF_802_1Q_VLAN) ?
971 sizeof(struct vlan_ethhdr) : sizeof(struct ethhdr);
972 hlen = sizeof(struct fcoe_hdr);
973 tlen = sizeof(struct fcoe_crc_eof);
974 wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE;
977 if (likely(lp->crc_offload)) {
978 skb->ip_summed = CHECKSUM_PARTIAL;
979 skb->csum_start = skb_headroom(skb);
980 skb->csum_offset = skb->len;
983 skb->ip_summed = CHECKSUM_NONE;
984 crc = fcoe_fc_crc(fp);
987 /* copy fc crc and eof to the skb buff */
988 if (skb_is_nonlinear(skb)) {
990 if (fcoe_get_paged_crc_eof(skb, tlen)) {
994 frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1];
995 cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ)
998 cp = (struct fcoe_crc_eof *)skb_put(skb, tlen);
1001 memset(cp, 0, sizeof(*cp));
1003 cp->fcoe_crc32 = cpu_to_le32(~crc);
1005 if (skb_is_nonlinear(skb)) {
1006 kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ);
1010 /* adjust skb netowrk/transport offsets to match mac/fcoe/fc */
1011 skb_push(skb, elen + hlen);
1012 skb_reset_mac_header(skb);
1013 skb_reset_network_header(skb);
1014 skb->mac_len = elen;
1015 skb->protocol = htons(ETH_P_FCOE);
1016 skb->dev = fc->real_dev;
1018 /* fill up mac and fcoe headers */
1020 eh->h_proto = htons(ETH_P_FCOE);
1021 if (fc->address_mode == FCOE_FCOUI_ADDR_MODE)
1022 fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id);
1024 /* insert GW address */
1025 memcpy(eh->h_dest, fc->dest_addr, ETH_ALEN);
1027 if (unlikely(flogi_in_progress))
1028 memcpy(eh->h_source, fc->ctl_src_addr, ETH_ALEN);
1030 memcpy(eh->h_source, fc->data_src_addr, ETH_ALEN);
1032 hp = (struct fcoe_hdr *)(eh + 1);
1033 memset(hp, 0, sizeof(*hp));
1035 FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER);
1039 /* fcoe lso, mss is in max_payload which is non-zero for FCP data */
1040 if (lp->seq_offload && fr_max_payload(fp)) {
1041 skb_shinfo(skb)->gso_type = SKB_GSO_FCOE;
1042 skb_shinfo(skb)->gso_size = fr_max_payload(fp);
1044 skb_shinfo(skb)->gso_type = 0;
1045 skb_shinfo(skb)->gso_size = 0;
1048 /* update tx stats: regardless if LLD fails */
1049 stats = fc_lport_get_stats(lp);
1051 stats->TxWords += wlen;
1053 /* send down to lld */
1055 if (fc->fcoe_pending_queue.qlen)
1056 rc = fcoe_check_wait_queue(lp);
1059 rc = fcoe_start_io(skb);
1062 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1063 __skb_queue_tail(&fc->fcoe_pending_queue, skb);
1064 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1065 if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH)
1071 EXPORT_SYMBOL_GPL(fcoe_xmit);
1074 * fcoe_percpu_receive_thread() - recv thread per cpu
1075 * @arg: ptr to the fcoe per cpu struct
1077 * Return: 0 for success
1079 int fcoe_percpu_receive_thread(void *arg)
1081 struct fcoe_percpu_s *p = arg;
1083 struct fc_lport *lp;
1084 struct fcoe_rcv_info *fr;
1085 struct fcoe_dev_stats *stats;
1086 struct fc_frame_header *fh;
1087 struct sk_buff *skb;
1088 struct fcoe_crc_eof crc_eof;
1089 struct fc_frame *fp;
1091 struct fcoe_softc *fc;
1092 struct fcoe_hdr *hp;
1094 set_user_nice(current, -20);
1096 while (!kthread_should_stop()) {
1098 spin_lock_bh(&p->fcoe_rx_list.lock);
1099 while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) {
1100 set_current_state(TASK_INTERRUPTIBLE);
1101 spin_unlock_bh(&p->fcoe_rx_list.lock);
1103 set_current_state(TASK_RUNNING);
1104 if (kthread_should_stop())
1106 spin_lock_bh(&p->fcoe_rx_list.lock);
1108 spin_unlock_bh(&p->fcoe_rx_list.lock);
1109 fr = fcoe_dev_from_skb(skb);
1111 if (unlikely(lp == NULL)) {
1112 FC_DBG("invalid HBA Structure");
1117 if (unlikely(debug_fcoe)) {
1118 FC_DBG("skb_info: len:%d data_len:%d head:%p data:%p "
1119 "tail:%p end:%p sum:%d dev:%s",
1120 skb->len, skb->data_len,
1121 skb->head, skb->data, skb_tail_pointer(skb),
1122 skb_end_pointer(skb), skb->csum,
1123 skb->dev ? skb->dev->name : "<NULL>");
1127 * Save source MAC address before discarding header.
1129 fc = lport_priv(lp);
1130 if (unlikely(fc->flogi_progress))
1131 mac = eth_hdr(skb)->h_source;
1133 if (skb_is_nonlinear(skb))
1134 skb_linearize(skb); /* not ideal */
1137 * Frame length checks and setting up the header pointers
1138 * was done in fcoe_rcv already.
1140 hp = (struct fcoe_hdr *) skb_network_header(skb);
1141 fh = (struct fc_frame_header *) skb_transport_header(skb);
1143 stats = fc_lport_get_stats(lp);
1144 if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) {
1145 if (stats->ErrorFrames < 5)
1146 printk(KERN_WARNING "FCoE version "
1147 "mismatch: The frame has "
1148 "version %x, but the "
1149 "initiator supports version "
1150 "%x\n", FC_FCOE_DECAPS_VER(hp),
1152 stats->ErrorFrames++;
1157 skb_pull(skb, sizeof(struct fcoe_hdr));
1158 fr_len = skb->len - sizeof(struct fcoe_crc_eof);
1161 stats->RxWords += fr_len / FCOE_WORD_TO_BYTE;
1163 fp = (struct fc_frame *)skb;
1166 fr_sof(fp) = hp->fcoe_sof;
1168 /* Copy out the CRC and EOF trailer for access */
1169 if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) {
1173 fr_eof(fp) = crc_eof.fcoe_eof;
1174 fr_crc(fp) = crc_eof.fcoe_crc32;
1175 if (pskb_trim(skb, fr_len)) {
1181 * We only check CRC if no offload is available and if it is
1182 * it's solicited data, in which case, the FCP layer would
1183 * check it during the copy.
1185 if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY)
1186 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1188 fr_flags(fp) |= FCPHF_CRC_UNCHECKED;
1190 fh = fc_frame_header_get(fp);
1191 if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA &&
1192 fh->fh_type == FC_TYPE_FCP) {
1193 fc_exch_recv(lp, lp->emp, fp);
1196 if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) {
1197 if (le32_to_cpu(fr_crc(fp)) !=
1198 ~crc32(~0, skb->data, fr_len)) {
1199 if (debug_fcoe || stats->InvalidCRCCount < 5)
1200 printk(KERN_WARNING "fcoe: dropping "
1201 "frame with CRC error\n");
1202 stats->InvalidCRCCount++;
1203 stats->ErrorFrames++;
1207 fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED;
1209 /* non flogi and non data exchanges are handled here */
1210 if (unlikely(fc->flogi_progress))
1211 fcoe_recv_flogi(fc, fp, mac);
1212 fc_exch_recv(lp, lp->emp, fp);
1218 * fcoe_recv_flogi() - flogi receive function
1219 * @fc: associated fcoe_softc
1220 * @fp: the recieved frame
1221 * @sa: the source address of this flogi
1223 * This is responsible to parse the flogi response and sets the corresponding
1224 * mac address for the initiator, eitehr OUI based or GW based.
1228 static void fcoe_recv_flogi(struct fcoe_softc *fc, struct fc_frame *fp, u8 *sa)
1230 struct fc_frame_header *fh;
1233 fh = fc_frame_header_get(fp);
1234 if (fh->fh_type != FC_TYPE_ELS)
1236 op = fc_frame_payload_op(fp);
1237 if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP &&
1238 fc->flogi_oxid == ntohs(fh->fh_ox_id)) {
1241 * If the src mac addr is FC_OUI-based, then we mark the
1242 * address_mode flag to use FC_OUI-based Ethernet DA.
1243 * Otherwise we use the FCoE gateway addr
1245 if (!compare_ether_addr(sa, (u8[6]) FC_FCOE_FLOGI_MAC)) {
1246 fc->address_mode = FCOE_FCOUI_ADDR_MODE;
1248 memcpy(fc->dest_addr, sa, ETH_ALEN);
1249 fc->address_mode = FCOE_GW_ADDR_MODE;
1253 * Remove any previously-set unicast MAC filter.
1254 * Add secondary FCoE MAC address filter for our OUI.
1257 if (compare_ether_addr(fc->data_src_addr, (u8[6]) { 0 }))
1258 dev_unicast_delete(fc->real_dev, fc->data_src_addr,
1260 fc_fcoe_set_mac(fc->data_src_addr, fh->fh_d_id);
1261 dev_unicast_add(fc->real_dev, fc->data_src_addr, ETH_ALEN);
1264 fc->flogi_progress = 0;
1265 } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) {
1267 * Save source MAC for point-to-point responses.
1269 memcpy(fc->dest_addr, sa, ETH_ALEN);
1270 fc->address_mode = FCOE_GW_ADDR_MODE;
1275 * fcoe_watchdog() - fcoe timer callback
1278 * This checks the pending queue length for fcoe and set lport qfull
1279 * if the FCOE_MAX_QUEUE_DEPTH is reached. This is done for all fc_lport on the
1282 * Returns: 0 for success
1284 void fcoe_watchdog(ulong vp)
1286 struct fcoe_softc *fc;
1288 read_lock(&fcoe_hostlist_lock);
1289 list_for_each_entry(fc, &fcoe_hostlist, list) {
1291 fcoe_check_wait_queue(fc->lp);
1293 read_unlock(&fcoe_hostlist_lock);
1295 fcoe_timer.expires = jiffies + (1 * HZ);
1296 add_timer(&fcoe_timer);
1301 * fcoe_check_wait_queue() - put the skb into fcoe pending xmit queue
1302 * @lp: the fc_port for this skb
1303 * @skb: the associated skb to be xmitted
1305 * This empties the wait_queue, dequeue the head of the wait_queue queue
1306 * and calls fcoe_start_io() for each packet, if all skb have been
1307 * transmitted, return qlen or -1 if a error occurs, then restore
1308 * wait_queue and try again later.
1310 * The wait_queue is used when the skb transmit fails. skb will go
1311 * in the wait_queue which will be emptied by the time function OR
1312 * by the next skb transmit.
1314 * Returns: 0 for success
1316 static int fcoe_check_wait_queue(struct fc_lport *lp)
1318 struct fcoe_softc *fc = lport_priv(lp);
1319 struct sk_buff *skb;
1322 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1323 if (fc->fcoe_pending_queue_active)
1325 fc->fcoe_pending_queue_active = 1;
1327 while (fc->fcoe_pending_queue.qlen) {
1328 /* keep qlen > 0 until fcoe_start_io succeeds */
1329 fc->fcoe_pending_queue.qlen++;
1330 skb = __skb_dequeue(&fc->fcoe_pending_queue);
1332 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1333 rc = fcoe_start_io(skb);
1334 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1337 __skb_queue_head(&fc->fcoe_pending_queue, skb);
1338 /* undo temporary increment above */
1339 fc->fcoe_pending_queue.qlen--;
1342 /* undo temporary increment above */
1343 fc->fcoe_pending_queue.qlen--;
1346 if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH)
1348 fc->fcoe_pending_queue_active = 0;
1349 rc = fc->fcoe_pending_queue.qlen;
1351 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1356 * fcoe_dev_setup() - setup link change notification interface
1358 static void fcoe_dev_setup()
1361 * here setup a interface specific wd time to
1362 * monitor the link state
1364 register_netdevice_notifier(&fcoe_notifier);
1368 * fcoe_dev_setup() - cleanup link change notification interface
1370 static void fcoe_dev_cleanup(void)
1372 unregister_netdevice_notifier(&fcoe_notifier);
1376 * fcoe_device_notification() - netdev event notification callback
1377 * @notifier: context of the notification
1378 * @event: type of event
1379 * @ptr: fixed array for output parsed ifname
1381 * This function is called by the ethernet driver in case of link change event
1383 * Returns: 0 for success
1385 static int fcoe_device_notification(struct notifier_block *notifier,
1386 ulong event, void *ptr)
1388 struct fc_lport *lp = NULL;
1389 struct net_device *real_dev = ptr;
1390 struct fcoe_softc *fc;
1391 struct fcoe_dev_stats *stats;
1396 read_lock(&fcoe_hostlist_lock);
1397 list_for_each_entry(fc, &fcoe_hostlist, list) {
1398 if (fc->real_dev == real_dev) {
1403 read_unlock(&fcoe_hostlist_lock);
1409 new_link_up = lp->link_up;
1412 case NETDEV_GOING_DOWN:
1417 new_link_up = !fcoe_link_ok(lp);
1419 case NETDEV_CHANGEMTU:
1420 mfs = fc->real_dev->mtu -
1421 (sizeof(struct fcoe_hdr) +
1422 sizeof(struct fcoe_crc_eof));
1423 if (mfs >= FC_MIN_MAX_FRAME)
1424 fc_set_mfs(lp, mfs);
1425 new_link_up = !fcoe_link_ok(lp);
1427 case NETDEV_REGISTER:
1430 FC_DBG("unknown event %ld call", event);
1432 if (lp->link_up != new_link_up) {
1436 stats = fc_lport_get_stats(lp);
1437 stats->LinkFailureCount++;
1439 fcoe_clean_pending_queue(lp);
1447 * fcoe_if_to_netdev() - parse a name buffer to get netdev
1448 * @ifname: fixed array for output parsed ifname
1449 * @buffer: incoming buffer to be copied
1451 * Returns: NULL or ptr to netdeive
1453 static struct net_device *fcoe_if_to_netdev(const char *buffer)
1456 char ifname[IFNAMSIZ + 2];
1459 strlcpy(ifname, buffer, IFNAMSIZ);
1460 cp = ifname + strlen(ifname);
1461 while (--cp >= ifname && *cp == '\n')
1463 return dev_get_by_name(&init_net, ifname);
1469 * fcoe_netdev_to_module_owner() - finds out the nic drive moddule of the netdev
1470 * @netdev: the target netdev
1472 * Returns: ptr to the struct module, NULL for failure
1474 static struct module *
1475 fcoe_netdev_to_module_owner(const struct net_device *netdev)
1482 dev = netdev->dev.parent;
1489 return dev->driver->owner;
1493 * fcoe_ethdrv_get() - Hold the Ethernet driver
1494 * @netdev: the target netdev
1496 * Holds the Ethernet driver module by try_module_get() for
1497 * the corresponding netdev.
1499 * Returns: 0 for succsss
1501 static int fcoe_ethdrv_get(const struct net_device *netdev)
1503 struct module *owner;
1505 owner = fcoe_netdev_to_module_owner(netdev);
1507 printk(KERN_DEBUG "fcoe:hold driver module %s for %s\n",
1508 module_name(owner), netdev->name);
1509 return try_module_get(owner);
1515 * fcoe_ethdrv_put() - Release the Ethernet driver
1516 * @netdev: the target netdev
1518 * Releases the Ethernet driver module by module_put for
1519 * the corresponding netdev.
1521 * Returns: 0 for succsss
1523 static int fcoe_ethdrv_put(const struct net_device *netdev)
1525 struct module *owner;
1527 owner = fcoe_netdev_to_module_owner(netdev);
1529 printk(KERN_DEBUG "fcoe:release driver module %s for %s\n",
1530 module_name(owner), netdev->name);
1538 * fcoe_destroy() - handles the destroy from sysfs
1539 * @buffer: expcted to be a eth if name
1540 * @kp: associated kernel param
1542 * Returns: 0 for success
1544 static int fcoe_destroy(const char *buffer, struct kernel_param *kp)
1547 struct net_device *netdev;
1549 netdev = fcoe_if_to_netdev(buffer);
1554 /* look for existing lport */
1555 if (!fcoe_hostlist_lookup(netdev)) {
1559 rc = fcoe_if_destroy(netdev);
1561 printk(KERN_ERR "fcoe: fcoe_if_destroy(%s) failed\n",
1566 fcoe_ethdrv_put(netdev);
1575 * fcoe_create() - Handles the create call from sysfs
1576 * @buffer: expcted to be a eth if name
1577 * @kp: associated kernel param
1579 * Returns: 0 for success
1581 static int fcoe_create(const char *buffer, struct kernel_param *kp)
1584 struct net_device *netdev;
1586 netdev = fcoe_if_to_netdev(buffer);
1591 /* look for existing lport */
1592 if (fcoe_hostlist_lookup(netdev)) {
1596 fcoe_ethdrv_get(netdev);
1598 rc = fcoe_if_create(netdev);
1600 printk(KERN_ERR "fcoe: fcoe_if_create(%s) failed\n",
1602 fcoe_ethdrv_put(netdev);
1613 module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR);
1614 __MODULE_PARM_TYPE(create, "string");
1615 MODULE_PARM_DESC(create, "Create fcoe port using net device passed in.");
1616 module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR);
1617 __MODULE_PARM_TYPE(destroy, "string");
1618 MODULE_PARM_DESC(destroy, "Destroy fcoe port");
1621 * fcoe_link_ok() - Check if link is ok for the fc_lport
1622 * @lp: ptr to the fc_lport
1624 * Any permanently-disqualifying conditions have been previously checked.
1625 * This also updates the speed setting, which may change with link for 100/1000.
1627 * This function should probably be checking for PAUSE support at some point
1628 * in the future. Currently Per-priority-pause is not determinable using
1629 * ethtool, so we shouldn't be restrictive until that problem is resolved.
1631 * Returns: 0 if link is OK for use by FCoE.
1634 int fcoe_link_ok(struct fc_lport *lp)
1636 struct fcoe_softc *fc = lport_priv(lp);
1637 struct net_device *dev = fc->real_dev;
1638 struct ethtool_cmd ecmd = { ETHTOOL_GSET };
1641 if ((dev->flags & IFF_UP) && netif_carrier_ok(dev)) {
1643 if (dev->ethtool_ops->get_settings) {
1644 dev->ethtool_ops->get_settings(dev, &ecmd);
1645 lp->link_supported_speeds &=
1646 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
1647 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
1648 SUPPORTED_1000baseT_Full))
1649 lp->link_supported_speeds |= FC_PORTSPEED_1GBIT;
1650 if (ecmd.supported & SUPPORTED_10000baseT_Full)
1651 lp->link_supported_speeds |=
1652 FC_PORTSPEED_10GBIT;
1653 if (ecmd.speed == SPEED_1000)
1654 lp->link_speed = FC_PORTSPEED_1GBIT;
1655 if (ecmd.speed == SPEED_10000)
1656 lp->link_speed = FC_PORTSPEED_10GBIT;
1663 EXPORT_SYMBOL_GPL(fcoe_link_ok);
1666 * fcoe_percpu_clean() - Clear the pending skbs for an lport
1669 void fcoe_percpu_clean(struct fc_lport *lp)
1671 struct fcoe_percpu_s *pp;
1672 struct fcoe_rcv_info *fr;
1673 struct sk_buff_head *list;
1674 struct sk_buff *skb, *next;
1675 struct sk_buff *head;
1678 for_each_possible_cpu(cpu) {
1679 pp = &per_cpu(fcoe_percpu, cpu);
1680 spin_lock_bh(&pp->fcoe_rx_list.lock);
1681 list = &pp->fcoe_rx_list;
1683 for (skb = head; skb != (struct sk_buff *)list;
1686 fr = fcoe_dev_from_skb(skb);
1687 if (fr->fr_dev == lp) {
1688 __skb_unlink(skb, list);
1692 spin_unlock_bh(&pp->fcoe_rx_list.lock);
1695 EXPORT_SYMBOL_GPL(fcoe_percpu_clean);
1698 * fcoe_clean_pending_queue() - Dequeue a skb and free it
1699 * @lp: the corresponding fc_lport
1703 void fcoe_clean_pending_queue(struct fc_lport *lp)
1705 struct fcoe_softc *fc = lport_priv(lp);
1706 struct sk_buff *skb;
1708 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1709 while ((skb = __skb_dequeue(&fc->fcoe_pending_queue)) != NULL) {
1710 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1712 spin_lock_bh(&fc->fcoe_pending_queue.lock);
1714 spin_unlock_bh(&fc->fcoe_pending_queue.lock);
1716 EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue);
1719 * libfc_host_alloc() - Allocate a Scsi_Host with room for the fc_lport
1720 * @sht: ptr to the scsi host templ
1721 * @priv_size: size of private data after fc_lport
1723 * Returns: ptr to Scsi_Host
1726 static inline struct Scsi_Host *
1727 libfc_host_alloc(struct scsi_host_template *sht, int priv_size)
1729 return scsi_host_alloc(sht, sizeof(struct fc_lport) + priv_size);
1733 * fcoe_host_alloc() - Allocate a Scsi_Host with room for the fcoe_softc
1734 * @sht: ptr to the scsi host templ
1735 * @priv_size: size of private data after fc_lport
1737 * Returns: ptr to Scsi_Host
1739 struct Scsi_Host *fcoe_host_alloc(struct scsi_host_template *sht, int priv_size)
1741 return libfc_host_alloc(sht, sizeof(struct fcoe_softc) + priv_size);
1743 EXPORT_SYMBOL_GPL(fcoe_host_alloc);
1746 * fcoe_reset() - Resets the fcoe
1747 * @shost: shost the reset is from
1751 int fcoe_reset(struct Scsi_Host *shost)
1753 struct fc_lport *lport = shost_priv(shost);
1754 fc_lport_reset(lport);
1757 EXPORT_SYMBOL_GPL(fcoe_reset);
1760 * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device
1761 * @device: this is currently ptr to net_device
1763 * Returns: NULL or the located fcoe_softc
1765 static struct fcoe_softc *
1766 fcoe_hostlist_lookup_softc(const struct net_device *dev)
1768 struct fcoe_softc *fc;
1770 read_lock(&fcoe_hostlist_lock);
1771 list_for_each_entry(fc, &fcoe_hostlist, list) {
1772 if (fc->real_dev == dev) {
1773 read_unlock(&fcoe_hostlist_lock);
1777 read_unlock(&fcoe_hostlist_lock);
1782 * fcoe_hostlist_lookup() - Find the corresponding lport by netdev
1783 * @netdev: ptr to net_device
1785 * Returns: 0 for success
1787 struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev)
1789 struct fcoe_softc *fc;
1791 fc = fcoe_hostlist_lookup_softc(netdev);
1793 return (fc) ? fc->lp : NULL;
1795 EXPORT_SYMBOL_GPL(fcoe_hostlist_lookup);
1798 * fcoe_hostlist_add() - Add a lport to lports list
1799 * @lp: ptr to the fc_lport to badded
1801 * Returns: 0 for success
1803 int fcoe_hostlist_add(const struct fc_lport *lp)
1805 struct fcoe_softc *fc;
1807 fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
1809 fc = lport_priv(lp);
1810 write_lock_bh(&fcoe_hostlist_lock);
1811 list_add_tail(&fc->list, &fcoe_hostlist);
1812 write_unlock_bh(&fcoe_hostlist_lock);
1816 EXPORT_SYMBOL_GPL(fcoe_hostlist_add);
1819 * fcoe_hostlist_remove() - remove a lport from lports list
1820 * @lp: ptr to the fc_lport to badded
1822 * Returns: 0 for success
1824 int fcoe_hostlist_remove(const struct fc_lport *lp)
1826 struct fcoe_softc *fc;
1828 fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp));
1830 write_lock_bh(&fcoe_hostlist_lock);
1831 list_del(&fc->list);
1832 write_unlock_bh(&fcoe_hostlist_lock);
1836 EXPORT_SYMBOL_GPL(fcoe_hostlist_remove);
1839 * fcoe_init() - fcoe module loading initialization
1841 * Returns 0 on success, negative on failure
1843 static int __init fcoe_init(void)
1847 struct fcoe_percpu_s *p;
1849 INIT_LIST_HEAD(&fcoe_hostlist);
1850 rwlock_init(&fcoe_hostlist_lock);
1852 for_each_possible_cpu(cpu) {
1853 p = &per_cpu(fcoe_percpu, cpu);
1854 skb_queue_head_init(&p->fcoe_rx_list);
1857 for_each_online_cpu(cpu)
1858 fcoe_percpu_thread_create(cpu);
1860 /* Initialize per CPU interrupt thread */
1861 rc = register_hotcpu_notifier(&fcoe_cpu_notifier);
1865 /* Setup link change notification */
1868 setup_timer(&fcoe_timer, fcoe_watchdog, 0);
1870 mod_timer(&fcoe_timer, jiffies + (10 * HZ));
1877 for_each_online_cpu(cpu) {
1878 fcoe_percpu_thread_destroy(cpu);
1883 module_init(fcoe_init);
1886 * fcoe_exit() - fcoe module unloading cleanup
1888 * Returns 0 on success, negative on failure
1890 static void __exit fcoe_exit(void)
1893 struct fcoe_softc *fc, *tmp;
1897 /* Stop the timer */
1898 del_timer_sync(&fcoe_timer);
1900 /* releases the associated fcoe hosts */
1901 list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list)
1902 fcoe_if_destroy(fc->real_dev);
1904 unregister_hotcpu_notifier(&fcoe_cpu_notifier);
1906 for_each_online_cpu(cpu) {
1907 fcoe_percpu_thread_destroy(cpu);
1910 /* detach from scsi transport */
1913 module_exit(fcoe_exit);