2 * Copyright(c) 2008 - 2011 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/types.h>
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/list.h>
24 #include <linux/netdevice.h>
25 #include <linux/errno.h>
26 #include <linux/crc32.h>
27 #include <scsi/libfcoe.h>
31 MODULE_AUTHOR("Open-FCoE.org");
32 MODULE_DESCRIPTION("FIP discovery protocol and FCoE transport for FCoE HBAs");
33 MODULE_LICENSE("GPL v2");
35 static int fcoe_transport_create(const char *, struct kernel_param *);
36 static int fcoe_transport_destroy(const char *, struct kernel_param *);
37 static int fcoe_transport_show(char *buffer, const struct kernel_param *kp);
38 static struct fcoe_transport *fcoe_transport_lookup(struct net_device *device);
39 static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *device);
40 static int fcoe_transport_enable(const char *, struct kernel_param *);
41 static int fcoe_transport_disable(const char *, struct kernel_param *);
42 static int libfcoe_device_notification(struct notifier_block *notifier,
43 ulong event, void *ptr);
45 static LIST_HEAD(fcoe_transports);
46 static DEFINE_MUTEX(ft_mutex);
47 static LIST_HEAD(fcoe_netdevs);
48 static DEFINE_MUTEX(fn_mutex);
50 unsigned int libfcoe_debug_logging;
51 module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR);
52 MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
54 module_param_call(show, NULL, fcoe_transport_show, NULL, S_IRUSR);
55 __MODULE_PARM_TYPE(show, "string");
56 MODULE_PARM_DESC(show, " Show attached FCoE transports");
58 module_param_call(create, fcoe_transport_create, NULL,
59 (void *)FIP_MODE_FABRIC, S_IWUSR);
60 __MODULE_PARM_TYPE(create, "string");
61 MODULE_PARM_DESC(create, " Creates fcoe instance on an ethernet interface");
63 module_param_call(create_vn2vn, fcoe_transport_create, NULL,
64 (void *)FIP_MODE_VN2VN, S_IWUSR);
65 __MODULE_PARM_TYPE(create_vn2vn, "string");
66 MODULE_PARM_DESC(create_vn2vn, " Creates a VN_node to VN_node FCoE instance "
67 "on an Ethernet interface");
69 module_param_call(destroy, fcoe_transport_destroy, NULL, NULL, S_IWUSR);
70 __MODULE_PARM_TYPE(destroy, "string");
71 MODULE_PARM_DESC(destroy, " Destroys fcoe instance on an ethernet interface");
73 module_param_call(enable, fcoe_transport_enable, NULL, NULL, S_IWUSR);
74 __MODULE_PARM_TYPE(enable, "string");
75 MODULE_PARM_DESC(enable, " Enables fcoe on an ethernet interface.");
77 module_param_call(disable, fcoe_transport_disable, NULL, NULL, S_IWUSR);
78 __MODULE_PARM_TYPE(disable, "string");
79 MODULE_PARM_DESC(disable, " Disables fcoe on an ethernet interface.");
81 /* notification function for packets from net device */
82 static struct notifier_block libfcoe_notifier = {
83 .notifier_call = libfcoe_device_notification,
87 * fcoe_link_speed_update() - Update the supported and actual link speeds
88 * @lport: The local port to update speeds for
90 * Returns: 0 if the ethtool query was successful
91 * -1 if the ethtool query failed
93 int fcoe_link_speed_update(struct fc_lport *lport)
95 struct net_device *netdev = fcoe_get_netdev(lport);
96 struct ethtool_link_ksettings ecmd;
98 if (!__ethtool_get_link_ksettings(netdev, &ecmd)) {
99 lport->link_supported_speeds &= ~(FC_PORTSPEED_1GBIT |
100 FC_PORTSPEED_10GBIT |
101 FC_PORTSPEED_20GBIT |
102 FC_PORTSPEED_40GBIT);
104 if (ecmd.link_modes.supported[0] & (
105 SUPPORTED_1000baseT_Half |
106 SUPPORTED_1000baseT_Full |
107 SUPPORTED_1000baseKX_Full))
108 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
110 if (ecmd.link_modes.supported[0] & (
111 SUPPORTED_10000baseT_Full |
112 SUPPORTED_10000baseKX4_Full |
113 SUPPORTED_10000baseKR_Full |
114 SUPPORTED_10000baseR_FEC))
115 lport->link_supported_speeds |= FC_PORTSPEED_10GBIT;
117 if (ecmd.link_modes.supported[0] & (
118 SUPPORTED_20000baseMLD2_Full |
119 SUPPORTED_20000baseKR2_Full))
120 lport->link_supported_speeds |= FC_PORTSPEED_20GBIT;
122 if (ecmd.link_modes.supported[0] & (
123 SUPPORTED_40000baseKR4_Full |
124 SUPPORTED_40000baseCR4_Full |
125 SUPPORTED_40000baseSR4_Full |
126 SUPPORTED_40000baseLR4_Full))
127 lport->link_supported_speeds |= FC_PORTSPEED_40GBIT;
129 switch (ecmd.base.speed) {
131 lport->link_speed = FC_PORTSPEED_1GBIT;
134 lport->link_speed = FC_PORTSPEED_10GBIT;
137 lport->link_speed = FC_PORTSPEED_20GBIT;
140 lport->link_speed = FC_PORTSPEED_40GBIT;
143 lport->link_speed = FC_PORTSPEED_UNKNOWN;
150 EXPORT_SYMBOL_GPL(fcoe_link_speed_update);
153 * __fcoe_get_lesb() - Get the Link Error Status Block (LESB) for a given lport
154 * @lport: The local port to update speeds for
155 * @fc_lesb: Pointer to the LESB to be filled up
156 * @netdev: Pointer to the netdev that is associated with the lport
158 * Note, the Link Error Status Block (LESB) for FCoE is defined in FC-BB-6
159 * Clause 7.11 in v1.04.
161 void __fcoe_get_lesb(struct fc_lport *lport,
162 struct fc_els_lesb *fc_lesb,
163 struct net_device *netdev)
167 struct fc_stats *stats;
168 struct fcoe_fc_els_lesb *lesb;
169 struct rtnl_link_stats64 temp;
174 lesb = (struct fcoe_fc_els_lesb *)fc_lesb;
175 memset(lesb, 0, sizeof(*lesb));
176 for_each_possible_cpu(cpu) {
177 stats = per_cpu_ptr(lport->stats, cpu);
178 lfc += stats->LinkFailureCount;
179 vlfc += stats->VLinkFailureCount;
180 mdac += stats->MissDiscAdvCount;
182 lesb->lesb_link_fail = htonl(lfc);
183 lesb->lesb_vlink_fail = htonl(vlfc);
184 lesb->lesb_miss_fka = htonl(mdac);
185 lesb->lesb_fcs_error =
186 htonl(dev_get_stats(netdev, &temp)->rx_crc_errors);
188 EXPORT_SYMBOL_GPL(__fcoe_get_lesb);
191 * fcoe_get_lesb() - Fill the FCoE Link Error Status Block
192 * @lport: the local port
193 * @fc_lesb: the link error status block
195 void fcoe_get_lesb(struct fc_lport *lport,
196 struct fc_els_lesb *fc_lesb)
198 struct net_device *netdev = fcoe_get_netdev(lport);
200 __fcoe_get_lesb(lport, fc_lesb, netdev);
202 EXPORT_SYMBOL_GPL(fcoe_get_lesb);
205 * fcoe_ctlr_get_lesb() - Get the Link Error Status Block (LESB) for a given
206 * fcoe controller device
207 * @ctlr_dev: The given fcoe controller device
210 void fcoe_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev)
212 struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr_dev);
213 struct net_device *netdev = fcoe_get_netdev(fip->lp);
214 struct fc_els_lesb *fc_lesb;
216 fc_lesb = (struct fc_els_lesb *)(&ctlr_dev->lesb);
217 __fcoe_get_lesb(fip->lp, fc_lesb, netdev);
219 EXPORT_SYMBOL_GPL(fcoe_ctlr_get_lesb);
221 void fcoe_wwn_to_str(u64 wwn, char *buf, int len)
225 u64_to_wwn(wwn, wwpn);
226 snprintf(buf, len, "%02x%02x%02x%02x%02x%02x%02x%02x",
227 wwpn[0], wwpn[1], wwpn[2], wwpn[3],
228 wwpn[4], wwpn[5], wwpn[6], wwpn[7]);
230 EXPORT_SYMBOL_GPL(fcoe_wwn_to_str);
233 * fcoe_validate_vport_create() - Validate a vport before creating it
234 * @vport: NPIV port to be created
236 * This routine is meant to add validation for a vport before creating it
237 * via fcoe_vport_create().
238 * Current validations are:
239 * - WWPN supplied is unique for given lport
241 int fcoe_validate_vport_create(struct fc_vport *vport)
243 struct Scsi_Host *shost = vport_to_shost(vport);
244 struct fc_lport *n_port = shost_priv(shost);
245 struct fc_lport *vn_port;
249 mutex_lock(&n_port->lp_mutex);
251 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
252 /* Check if the wwpn is not same as that of the lport */
253 if (!memcmp(&n_port->wwpn, &vport->port_name, sizeof(u64))) {
254 LIBFCOE_TRANSPORT_DBG("vport WWPN 0x%s is same as that of the "
255 "base port WWPN\n", buf);
260 /* Check if there is any existing vport with same wwpn */
261 list_for_each_entry(vn_port, &n_port->vports, list) {
262 if (!memcmp(&vn_port->wwpn, &vport->port_name, sizeof(u64))) {
263 LIBFCOE_TRANSPORT_DBG("vport with given WWPN 0x%s "
264 "already exists\n", buf);
270 mutex_unlock(&n_port->lp_mutex);
273 EXPORT_SYMBOL_GPL(fcoe_validate_vport_create);
276 * fcoe_get_wwn() - Get the world wide name from LLD if it supports it
277 * @netdev: the associated net device
278 * @wwn: the output WWN
279 * @type: the type of WWN (WWPN or WWNN)
281 * Returns: 0 for success
283 int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
285 const struct net_device_ops *ops = netdev->netdev_ops;
287 if (ops->ndo_fcoe_get_wwn)
288 return ops->ndo_fcoe_get_wwn(netdev, wwn, type);
291 EXPORT_SYMBOL_GPL(fcoe_get_wwn);
294 * fcoe_fc_crc() - Calculates the CRC for a given frame
295 * @fp: The frame to be checksumed
297 * This uses crc32() routine to calculate the CRC for a frame
299 * Return: The 32 bit CRC value
301 u32 fcoe_fc_crc(struct fc_frame *fp)
303 struct sk_buff *skb = fp_skb(fp);
304 struct skb_frag_struct *frag;
306 unsigned long off, len, clen;
310 crc = crc32(~0, skb->data, skb_headlen(skb));
312 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
313 frag = &skb_shinfo(skb)->frags[i];
314 off = frag->page_offset;
315 len = skb_frag_size(frag);
317 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
319 skb_frag_page(frag) + (off >> PAGE_SHIFT));
320 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
328 EXPORT_SYMBOL_GPL(fcoe_fc_crc);
331 * fcoe_start_io() - Start FCoE I/O
332 * @skb: The packet to be transmitted
334 * This routine is called from the net device to start transmitting
337 * Returns: 0 for success
339 int fcoe_start_io(struct sk_buff *skb)
341 struct sk_buff *nskb;
344 nskb = skb_clone(skb, GFP_ATOMIC);
347 rc = dev_queue_xmit(nskb);
353 EXPORT_SYMBOL_GPL(fcoe_start_io);
357 * fcoe_clean_pending_queue() - Dequeue a skb and free it
358 * @lport: The local port to dequeue a skb on
360 void fcoe_clean_pending_queue(struct fc_lport *lport)
362 struct fcoe_port *port = lport_priv(lport);
365 spin_lock_bh(&port->fcoe_pending_queue.lock);
366 while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
367 spin_unlock_bh(&port->fcoe_pending_queue.lock);
369 spin_lock_bh(&port->fcoe_pending_queue.lock);
371 spin_unlock_bh(&port->fcoe_pending_queue.lock);
373 EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue);
376 * fcoe_check_wait_queue() - Attempt to clear the transmit backlog
377 * @lport: The local port whose backlog is to be cleared
379 * This empties the wait_queue, dequeues the head of the wait_queue queue
380 * and calls fcoe_start_io() for each packet. If all skb have been
381 * transmitted it returns the qlen. If an error occurs it restores
382 * wait_queue (to try again later) and returns -1.
384 * The wait_queue is used when the skb transmit fails. The failed skb
385 * will go in the wait_queue which will be emptied by the timer function or
386 * by the next skb transmit.
388 void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb)
390 struct fcoe_port *port = lport_priv(lport);
393 spin_lock_bh(&port->fcoe_pending_queue.lock);
396 __skb_queue_tail(&port->fcoe_pending_queue, skb);
398 if (port->fcoe_pending_queue_active)
400 port->fcoe_pending_queue_active = 1;
402 while (port->fcoe_pending_queue.qlen) {
403 /* keep qlen > 0 until fcoe_start_io succeeds */
404 port->fcoe_pending_queue.qlen++;
405 skb = __skb_dequeue(&port->fcoe_pending_queue);
407 spin_unlock_bh(&port->fcoe_pending_queue.lock);
408 rc = fcoe_start_io(skb);
409 spin_lock_bh(&port->fcoe_pending_queue.lock);
412 __skb_queue_head(&port->fcoe_pending_queue, skb);
413 /* undo temporary increment above */
414 port->fcoe_pending_queue.qlen--;
417 /* undo temporary increment above */
418 port->fcoe_pending_queue.qlen--;
421 if (port->fcoe_pending_queue.qlen < port->min_queue_depth)
423 if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
424 mod_timer(&port->timer, jiffies + 2);
425 port->fcoe_pending_queue_active = 0;
427 if (port->fcoe_pending_queue.qlen > port->max_queue_depth)
429 spin_unlock_bh(&port->fcoe_pending_queue.lock);
431 EXPORT_SYMBOL_GPL(fcoe_check_wait_queue);
434 * fcoe_queue_timer() - The fcoe queue timer
435 * @lport: The local port
437 * Calls fcoe_check_wait_queue on timeout
439 void fcoe_queue_timer(ulong lport)
441 fcoe_check_wait_queue((struct fc_lport *)lport, NULL);
443 EXPORT_SYMBOL_GPL(fcoe_queue_timer);
446 * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC
447 * @skb: The packet to be transmitted
448 * @tlen: The total length of the trailer
449 * @fps: The fcoe context
451 * This routine allocates a page for frame trailers. The page is re-used if
452 * there is enough room left on it for the current trailer. If there isn't
453 * enough buffer left a new page is allocated for the trailer. Reference to
454 * the page from this function as well as the skbs using the page fragments
455 * ensure that the page is freed at the appropriate time.
457 * Returns: 0 for success
459 int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
460 struct fcoe_percpu_s *fps)
464 page = fps->crc_eof_page;
466 page = alloc_page(GFP_ATOMIC);
470 fps->crc_eof_page = page;
471 fps->crc_eof_offset = 0;
475 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
476 fps->crc_eof_offset, tlen);
478 skb->data_len += tlen;
479 skb->truesize += tlen;
480 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
482 if (fps->crc_eof_offset >= PAGE_SIZE) {
483 fps->crc_eof_page = NULL;
484 fps->crc_eof_offset = 0;
490 EXPORT_SYMBOL_GPL(fcoe_get_paged_crc_eof);
493 * fcoe_transport_lookup - find an fcoe transport that matches a netdev
494 * @netdev: The netdev to look for from all attached transports
496 * Returns : ptr to the fcoe transport that supports this netdev or NULL
499 * The ft_mutex should be held when this is called
501 static struct fcoe_transport *fcoe_transport_lookup(struct net_device *netdev)
503 struct fcoe_transport *ft = NULL;
505 list_for_each_entry(ft, &fcoe_transports, list)
506 if (ft->match && ft->match(netdev))
512 * fcoe_transport_attach - Attaches an FCoE transport
513 * @ft: The fcoe transport to be attached
515 * Returns : 0 for success
517 int fcoe_transport_attach(struct fcoe_transport *ft)
521 mutex_lock(&ft_mutex);
523 LIBFCOE_TRANSPORT_DBG("transport %s already attached\n",
529 /* Add default transport to the tail */
530 if (strcmp(ft->name, FCOE_TRANSPORT_DEFAULT))
531 list_add(&ft->list, &fcoe_transports);
533 list_add_tail(&ft->list, &fcoe_transports);
536 LIBFCOE_TRANSPORT_DBG("attaching transport %s\n", ft->name);
539 mutex_unlock(&ft_mutex);
542 EXPORT_SYMBOL(fcoe_transport_attach);
545 * fcoe_transport_detach - Detaches an FCoE transport
546 * @ft: The fcoe transport to be attached
548 * Returns : 0 for success
550 int fcoe_transport_detach(struct fcoe_transport *ft)
553 struct fcoe_netdev_mapping *nm = NULL, *tmp;
555 mutex_lock(&ft_mutex);
557 LIBFCOE_TRANSPORT_DBG("transport %s already detached\n",
563 /* remove netdev mapping for this transport as it is going away */
564 mutex_lock(&fn_mutex);
565 list_for_each_entry_safe(nm, tmp, &fcoe_netdevs, list) {
567 LIBFCOE_TRANSPORT_DBG("transport %s going away, "
568 "remove its netdev mapping for %s\n",
569 ft->name, nm->netdev->name);
574 mutex_unlock(&fn_mutex);
577 ft->attached = false;
578 LIBFCOE_TRANSPORT_DBG("detaching transport %s\n", ft->name);
581 mutex_unlock(&ft_mutex);
585 EXPORT_SYMBOL(fcoe_transport_detach);
587 static int fcoe_transport_show(char *buffer, const struct kernel_param *kp)
590 struct fcoe_transport *ft = NULL;
592 i = j = sprintf(buffer, "Attached FCoE transports:");
593 mutex_lock(&ft_mutex);
594 list_for_each_entry(ft, &fcoe_transports, list) {
595 if (i >= PAGE_SIZE - IFNAMSIZ)
597 i += snprintf(&buffer[i], IFNAMSIZ, "%s ", ft->name);
599 mutex_unlock(&ft_mutex);
601 i += snprintf(&buffer[i], IFNAMSIZ, "none");
605 static int __init fcoe_transport_init(void)
607 register_netdevice_notifier(&libfcoe_notifier);
611 static int fcoe_transport_exit(void)
613 struct fcoe_transport *ft;
615 unregister_netdevice_notifier(&libfcoe_notifier);
616 mutex_lock(&ft_mutex);
617 list_for_each_entry(ft, &fcoe_transports, list)
618 printk(KERN_ERR "FCoE transport %s is still attached!\n",
620 mutex_unlock(&ft_mutex);
625 static int fcoe_add_netdev_mapping(struct net_device *netdev,
626 struct fcoe_transport *ft)
628 struct fcoe_netdev_mapping *nm;
630 nm = kmalloc(sizeof(*nm), GFP_KERNEL);
632 printk(KERN_ERR "Unable to allocate netdev_mapping");
639 mutex_lock(&fn_mutex);
640 list_add(&nm->list, &fcoe_netdevs);
641 mutex_unlock(&fn_mutex);
646 static void fcoe_del_netdev_mapping(struct net_device *netdev)
648 struct fcoe_netdev_mapping *nm = NULL, *tmp;
650 mutex_lock(&fn_mutex);
651 list_for_each_entry_safe(nm, tmp, &fcoe_netdevs, list) {
652 if (nm->netdev == netdev) {
655 mutex_unlock(&fn_mutex);
659 mutex_unlock(&fn_mutex);
664 * fcoe_netdev_map_lookup - find the fcoe transport that matches the netdev on which
667 * Returns : ptr to the fcoe transport that supports this netdev or NULL
670 * The ft_mutex should be held when this is called
672 static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *netdev)
674 struct fcoe_transport *ft = NULL;
675 struct fcoe_netdev_mapping *nm;
677 mutex_lock(&fn_mutex);
678 list_for_each_entry(nm, &fcoe_netdevs, list) {
679 if (netdev == nm->netdev) {
681 mutex_unlock(&fn_mutex);
686 mutex_unlock(&fn_mutex);
691 * fcoe_if_to_netdev() - Parse a name buffer to get a net device
692 * @buffer: The name of the net device
694 * Returns: NULL or a ptr to net_device
696 static struct net_device *fcoe_if_to_netdev(const char *buffer)
699 char ifname[IFNAMSIZ + 2];
702 strlcpy(ifname, buffer, IFNAMSIZ);
703 cp = ifname + strlen(ifname);
704 while (--cp >= ifname && *cp == '\n')
706 return dev_get_by_name(&init_net, ifname);
712 * libfcoe_device_notification() - Handler for net device events
713 * @notifier: The context of the notification
714 * @event: The type of event
715 * @ptr: The net device that the event was on
717 * This function is called by the Ethernet driver in case of link change event.
719 * Returns: 0 for success
721 static int libfcoe_device_notification(struct notifier_block *notifier,
722 ulong event, void *ptr)
724 struct net_device *netdev = netdev_notifier_info_to_dev(ptr);
727 case NETDEV_UNREGISTER:
728 LIBFCOE_TRANSPORT_DBG("NETDEV_UNREGISTER %s\n",
730 fcoe_del_netdev_mapping(netdev);
736 ssize_t fcoe_ctlr_create_store(struct bus_type *bus,
737 const char *buf, size_t count)
739 struct net_device *netdev = NULL;
740 struct fcoe_transport *ft = NULL;
744 mutex_lock(&ft_mutex);
746 netdev = fcoe_if_to_netdev(buf);
748 LIBFCOE_TRANSPORT_DBG("Invalid device %s.\n", buf);
753 ft = fcoe_netdev_map_lookup(netdev);
755 LIBFCOE_TRANSPORT_DBG("transport %s already has existing "
756 "FCoE instance on %s.\n",
757 ft->name, netdev->name);
762 ft = fcoe_transport_lookup(netdev);
764 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
770 /* pass to transport create */
771 err = ft->alloc ? ft->alloc(netdev) : -ENODEV;
773 fcoe_del_netdev_mapping(netdev);
778 err = fcoe_add_netdev_mapping(netdev, ft);
780 LIBFCOE_TRANSPORT_DBG("failed to add new netdev mapping "
781 "for FCoE transport %s for %s.\n",
782 ft->name, netdev->name);
787 LIBFCOE_TRANSPORT_DBG("transport %s succeeded to create fcoe on %s.\n",
788 ft->name, netdev->name);
793 mutex_unlock(&ft_mutex);
799 ssize_t fcoe_ctlr_destroy_store(struct bus_type *bus,
800 const char *buf, size_t count)
803 struct net_device *netdev = NULL;
804 struct fcoe_transport *ft = NULL;
806 mutex_lock(&ft_mutex);
808 netdev = fcoe_if_to_netdev(buf);
810 LIBFCOE_TRANSPORT_DBG("invalid device %s.\n", buf);
814 ft = fcoe_netdev_map_lookup(netdev);
816 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
821 /* pass to transport destroy */
822 rc = ft->destroy(netdev);
826 fcoe_del_netdev_mapping(netdev);
827 LIBFCOE_TRANSPORT_DBG("transport %s %s to destroy fcoe on %s.\n",
828 ft->name, (rc) ? "failed" : "succeeded",
830 rc = count; /* required for successful return */
834 mutex_unlock(&ft_mutex);
837 EXPORT_SYMBOL(fcoe_ctlr_destroy_store);
840 * fcoe_transport_create() - Create a fcoe interface
841 * @buffer: The name of the Ethernet interface to create on
842 * @kp: The associated kernel param
844 * Called from sysfs. This holds the ft_mutex while calling the
845 * registered fcoe transport's create function.
847 * Returns: 0 for success
849 static int fcoe_transport_create(const char *buffer, struct kernel_param *kp)
852 struct net_device *netdev = NULL;
853 struct fcoe_transport *ft = NULL;
854 enum fip_state fip_mode = (enum fip_state)(long)kp->arg;
856 mutex_lock(&ft_mutex);
858 netdev = fcoe_if_to_netdev(buffer);
860 LIBFCOE_TRANSPORT_DBG("Invalid device %s.\n", buffer);
864 ft = fcoe_netdev_map_lookup(netdev);
866 LIBFCOE_TRANSPORT_DBG("transport %s already has existing "
867 "FCoE instance on %s.\n",
868 ft->name, netdev->name);
873 ft = fcoe_transport_lookup(netdev);
875 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
880 rc = fcoe_add_netdev_mapping(netdev, ft);
882 LIBFCOE_TRANSPORT_DBG("failed to add new netdev mapping "
883 "for FCoE transport %s for %s.\n",
884 ft->name, netdev->name);
888 /* pass to transport create */
889 rc = ft->create ? ft->create(netdev, fip_mode) : -ENODEV;
891 fcoe_del_netdev_mapping(netdev);
893 LIBFCOE_TRANSPORT_DBG("transport %s %s to create fcoe on %s.\n",
894 ft->name, (rc) ? "failed" : "succeeded",
900 mutex_unlock(&ft_mutex);
905 * fcoe_transport_destroy() - Destroy a FCoE interface
906 * @buffer: The name of the Ethernet interface to be destroyed
907 * @kp: The associated kernel parameter
909 * Called from sysfs. This holds the ft_mutex while calling the
910 * registered fcoe transport's destroy function.
912 * Returns: 0 for success
914 static int fcoe_transport_destroy(const char *buffer, struct kernel_param *kp)
917 struct net_device *netdev = NULL;
918 struct fcoe_transport *ft = NULL;
920 mutex_lock(&ft_mutex);
922 netdev = fcoe_if_to_netdev(buffer);
924 LIBFCOE_TRANSPORT_DBG("invalid device %s.\n", buffer);
928 ft = fcoe_netdev_map_lookup(netdev);
930 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
935 /* pass to transport destroy */
936 rc = ft->destroy ? ft->destroy(netdev) : -ENODEV;
937 fcoe_del_netdev_mapping(netdev);
938 LIBFCOE_TRANSPORT_DBG("transport %s %s to destroy fcoe on %s.\n",
939 ft->name, (rc) ? "failed" : "succeeded",
945 mutex_unlock(&ft_mutex);
950 * fcoe_transport_disable() - Disables a FCoE interface
951 * @buffer: The name of the Ethernet interface to be disabled
952 * @kp: The associated kernel parameter
956 * Returns: 0 for success
958 static int fcoe_transport_disable(const char *buffer, struct kernel_param *kp)
961 struct net_device *netdev = NULL;
962 struct fcoe_transport *ft = NULL;
964 mutex_lock(&ft_mutex);
966 netdev = fcoe_if_to_netdev(buffer);
970 ft = fcoe_netdev_map_lookup(netdev);
974 rc = ft->disable ? ft->disable(netdev) : -ENODEV;
979 mutex_unlock(&ft_mutex);
984 * fcoe_transport_enable() - Enables a FCoE interface
985 * @buffer: The name of the Ethernet interface to be enabled
986 * @kp: The associated kernel parameter
990 * Returns: 0 for success
992 static int fcoe_transport_enable(const char *buffer, struct kernel_param *kp)
995 struct net_device *netdev = NULL;
996 struct fcoe_transport *ft = NULL;
998 mutex_lock(&ft_mutex);
1000 netdev = fcoe_if_to_netdev(buffer);
1004 ft = fcoe_netdev_map_lookup(netdev);
1008 rc = ft->enable ? ft->enable(netdev) : -ENODEV;
1013 mutex_unlock(&ft_mutex);
1018 * libfcoe_init() - Initialization routine for libfcoe.ko
1020 static int __init libfcoe_init(void)
1024 rc = fcoe_transport_init();
1028 rc = fcoe_sysfs_setup();
1030 fcoe_transport_exit();
1034 module_init(libfcoe_init);
1037 * libfcoe_exit() - Tear down libfcoe.ko
1039 static void __exit libfcoe_exit(void)
1041 fcoe_sysfs_teardown();
1042 fcoe_transport_exit();
1044 module_exit(libfcoe_exit);