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 a 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 a 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 a 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 a 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_cmd ecmd;
98 if (!__ethtool_get_settings(netdev, &ecmd)) {
99 lport->link_supported_speeds &=
100 ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT);
101 if (ecmd.supported & (SUPPORTED_1000baseT_Half |
102 SUPPORTED_1000baseT_Full))
103 lport->link_supported_speeds |= FC_PORTSPEED_1GBIT;
104 if (ecmd.supported & SUPPORTED_10000baseT_Full)
105 lport->link_supported_speeds |=
107 switch (ethtool_cmd_speed(&ecmd)) {
109 lport->link_speed = FC_PORTSPEED_1GBIT;
112 lport->link_speed = FC_PORTSPEED_10GBIT;
119 EXPORT_SYMBOL_GPL(fcoe_link_speed_update);
121 void __fcoe_get_lesb(struct fc_lport *lport,
122 struct fc_els_lesb *fc_lesb,
123 struct net_device *netdev)
127 struct fc_stats *stats;
128 struct fcoe_fc_els_lesb *lesb;
129 struct rtnl_link_stats64 temp;
134 lesb = (struct fcoe_fc_els_lesb *)fc_lesb;
135 memset(lesb, 0, sizeof(*lesb));
136 for_each_possible_cpu(cpu) {
137 stats = per_cpu_ptr(lport->stats, cpu);
138 lfc += stats->LinkFailureCount;
139 vlfc += stats->VLinkFailureCount;
140 mdac += stats->MissDiscAdvCount;
142 lesb->lesb_link_fail = htonl(lfc);
143 lesb->lesb_vlink_fail = htonl(vlfc);
144 lesb->lesb_miss_fka = htonl(mdac);
145 lesb->lesb_fcs_error =
146 htonl(dev_get_stats(netdev, &temp)->rx_crc_errors);
148 EXPORT_SYMBOL_GPL(__fcoe_get_lesb);
150 void fcoe_wwn_to_str(u64 wwn, char *buf, int len)
154 u64_to_wwn(wwn, wwpn);
155 snprintf(buf, len, "%02x%02x%02x%02x%02x%02x%02x%02x",
156 wwpn[0], wwpn[1], wwpn[2], wwpn[3],
157 wwpn[4], wwpn[5], wwpn[6], wwpn[7]);
159 EXPORT_SYMBOL_GPL(fcoe_wwn_to_str);
162 * fcoe_validate_vport_create() - Validate a vport before creating it
163 * @vport: NPIV port to be created
165 * This routine is meant to add validation for a vport before creating it
166 * via fcoe_vport_create().
167 * Current validations are:
168 * - WWPN supplied is unique for given lport
170 int fcoe_validate_vport_create(struct fc_vport *vport)
172 struct Scsi_Host *shost = vport_to_shost(vport);
173 struct fc_lport *n_port = shost_priv(shost);
174 struct fc_lport *vn_port;
178 mutex_lock(&n_port->lp_mutex);
180 fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf));
181 /* Check if the wwpn is not same as that of the lport */
182 if (!memcmp(&n_port->wwpn, &vport->port_name, sizeof(u64))) {
183 LIBFCOE_TRANSPORT_DBG("vport WWPN 0x%s is same as that of the "
184 "base port WWPN\n", buf);
189 /* Check if there is any existing vport with same wwpn */
190 list_for_each_entry(vn_port, &n_port->vports, list) {
191 if (!memcmp(&vn_port->wwpn, &vport->port_name, sizeof(u64))) {
192 LIBFCOE_TRANSPORT_DBG("vport with given WWPN 0x%s "
193 "already exists\n", buf);
199 mutex_unlock(&n_port->lp_mutex);
202 EXPORT_SYMBOL_GPL(fcoe_validate_vport_create);
205 * fcoe_get_wwn() - Get the world wide name from LLD if it supports it
206 * @netdev: the associated net device
207 * @wwn: the output WWN
208 * @type: the type of WWN (WWPN or WWNN)
210 * Returns: 0 for success
212 int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type)
214 const struct net_device_ops *ops = netdev->netdev_ops;
216 if (ops->ndo_fcoe_get_wwn)
217 return ops->ndo_fcoe_get_wwn(netdev, wwn, type);
220 EXPORT_SYMBOL_GPL(fcoe_get_wwn);
223 * fcoe_fc_crc() - Calculates the CRC for a given frame
224 * @fp: The frame to be checksumed
226 * This uses crc32() routine to calculate the CRC for a frame
228 * Return: The 32 bit CRC value
230 u32 fcoe_fc_crc(struct fc_frame *fp)
232 struct sk_buff *skb = fp_skb(fp);
233 struct skb_frag_struct *frag;
235 unsigned long off, len, clen;
239 crc = crc32(~0, skb->data, skb_headlen(skb));
241 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
242 frag = &skb_shinfo(skb)->frags[i];
243 off = frag->page_offset;
244 len = skb_frag_size(frag);
246 clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK));
248 skb_frag_page(frag) + (off >> PAGE_SHIFT));
249 crc = crc32(crc, data + (off & ~PAGE_MASK), clen);
257 EXPORT_SYMBOL_GPL(fcoe_fc_crc);
260 * fcoe_start_io() - Start FCoE I/O
261 * @skb: The packet to be transmitted
263 * This routine is called from the net device to start transmitting
266 * Returns: 0 for success
268 int fcoe_start_io(struct sk_buff *skb)
270 struct sk_buff *nskb;
273 nskb = skb_clone(skb, GFP_ATOMIC);
276 rc = dev_queue_xmit(nskb);
282 EXPORT_SYMBOL_GPL(fcoe_start_io);
286 * fcoe_clean_pending_queue() - Dequeue a skb and free it
287 * @lport: The local port to dequeue a skb on
289 void fcoe_clean_pending_queue(struct fc_lport *lport)
291 struct fcoe_port *port = lport_priv(lport);
294 spin_lock_bh(&port->fcoe_pending_queue.lock);
295 while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) {
296 spin_unlock_bh(&port->fcoe_pending_queue.lock);
298 spin_lock_bh(&port->fcoe_pending_queue.lock);
300 spin_unlock_bh(&port->fcoe_pending_queue.lock);
302 EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue);
305 * fcoe_check_wait_queue() - Attempt to clear the transmit backlog
306 * @lport: The local port whose backlog is to be cleared
308 * This empties the wait_queue, dequeues the head of the wait_queue queue
309 * and calls fcoe_start_io() for each packet. If all skb have been
310 * transmitted it returns the qlen. If an error occurs it restores
311 * wait_queue (to try again later) and returns -1.
313 * The wait_queue is used when the skb transmit fails. The failed skb
314 * will go in the wait_queue which will be emptied by the timer function or
315 * by the next skb transmit.
317 void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb)
319 struct fcoe_port *port = lport_priv(lport);
322 spin_lock_bh(&port->fcoe_pending_queue.lock);
325 __skb_queue_tail(&port->fcoe_pending_queue, skb);
327 if (port->fcoe_pending_queue_active)
329 port->fcoe_pending_queue_active = 1;
331 while (port->fcoe_pending_queue.qlen) {
332 /* keep qlen > 0 until fcoe_start_io succeeds */
333 port->fcoe_pending_queue.qlen++;
334 skb = __skb_dequeue(&port->fcoe_pending_queue);
336 spin_unlock_bh(&port->fcoe_pending_queue.lock);
337 rc = fcoe_start_io(skb);
338 spin_lock_bh(&port->fcoe_pending_queue.lock);
341 __skb_queue_head(&port->fcoe_pending_queue, skb);
342 /* undo temporary increment above */
343 port->fcoe_pending_queue.qlen--;
346 /* undo temporary increment above */
347 port->fcoe_pending_queue.qlen--;
350 if (port->fcoe_pending_queue.qlen < port->min_queue_depth)
352 if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer))
353 mod_timer(&port->timer, jiffies + 2);
354 port->fcoe_pending_queue_active = 0;
356 if (port->fcoe_pending_queue.qlen > port->max_queue_depth)
358 spin_unlock_bh(&port->fcoe_pending_queue.lock);
360 EXPORT_SYMBOL_GPL(fcoe_check_wait_queue);
363 * fcoe_queue_timer() - The fcoe queue timer
364 * @lport: The local port
366 * Calls fcoe_check_wait_queue on timeout
368 void fcoe_queue_timer(ulong lport)
370 fcoe_check_wait_queue((struct fc_lport *)lport, NULL);
372 EXPORT_SYMBOL_GPL(fcoe_queue_timer);
375 * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC
376 * @skb: The packet to be transmitted
377 * @tlen: The total length of the trailer
378 * @fps: The fcoe context
380 * This routine allocates a page for frame trailers. The page is re-used if
381 * there is enough room left on it for the current trailer. If there isn't
382 * enough buffer left a new page is allocated for the trailer. Reference to
383 * the page from this function as well as the skbs using the page fragments
384 * ensure that the page is freed at the appropriate time.
386 * Returns: 0 for success
388 int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen,
389 struct fcoe_percpu_s *fps)
393 page = fps->crc_eof_page;
395 page = alloc_page(GFP_ATOMIC);
399 fps->crc_eof_page = page;
400 fps->crc_eof_offset = 0;
404 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page,
405 fps->crc_eof_offset, tlen);
407 skb->data_len += tlen;
408 skb->truesize += tlen;
409 fps->crc_eof_offset += sizeof(struct fcoe_crc_eof);
411 if (fps->crc_eof_offset >= PAGE_SIZE) {
412 fps->crc_eof_page = NULL;
413 fps->crc_eof_offset = 0;
419 EXPORT_SYMBOL_GPL(fcoe_get_paged_crc_eof);
422 * fcoe_transport_lookup - find an fcoe transport that matches a netdev
423 * @netdev: The netdev to look for from all attached transports
425 * Returns : ptr to the fcoe transport that supports this netdev or NULL
428 * The ft_mutex should be held when this is called
430 static struct fcoe_transport *fcoe_transport_lookup(struct net_device *netdev)
432 struct fcoe_transport *ft = NULL;
434 list_for_each_entry(ft, &fcoe_transports, list)
435 if (ft->match && ft->match(netdev))
441 * fcoe_transport_attach - Attaches an FCoE transport
442 * @ft: The fcoe transport to be attached
444 * Returns : 0 for success
446 int fcoe_transport_attach(struct fcoe_transport *ft)
450 mutex_lock(&ft_mutex);
452 LIBFCOE_TRANSPORT_DBG("transport %s already attached\n",
458 /* Add default transport to the tail */
459 if (strcmp(ft->name, FCOE_TRANSPORT_DEFAULT))
460 list_add(&ft->list, &fcoe_transports);
462 list_add_tail(&ft->list, &fcoe_transports);
465 LIBFCOE_TRANSPORT_DBG("attaching transport %s\n", ft->name);
468 mutex_unlock(&ft_mutex);
471 EXPORT_SYMBOL(fcoe_transport_attach);
474 * fcoe_transport_detach - Detaches an FCoE transport
475 * @ft: The fcoe transport to be attached
477 * Returns : 0 for success
479 int fcoe_transport_detach(struct fcoe_transport *ft)
482 struct fcoe_netdev_mapping *nm = NULL, *tmp;
484 mutex_lock(&ft_mutex);
486 LIBFCOE_TRANSPORT_DBG("transport %s already detached\n",
492 /* remove netdev mapping for this transport as it is going away */
493 mutex_lock(&fn_mutex);
494 list_for_each_entry_safe(nm, tmp, &fcoe_netdevs, list) {
496 LIBFCOE_TRANSPORT_DBG("transport %s going away, "
497 "remove its netdev mapping for %s\n",
498 ft->name, nm->netdev->name);
503 mutex_unlock(&fn_mutex);
506 ft->attached = false;
507 LIBFCOE_TRANSPORT_DBG("detaching transport %s\n", ft->name);
510 mutex_unlock(&ft_mutex);
514 EXPORT_SYMBOL(fcoe_transport_detach);
516 static int fcoe_transport_show(char *buffer, const struct kernel_param *kp)
519 struct fcoe_transport *ft = NULL;
521 i = j = sprintf(buffer, "Attached FCoE transports:");
522 mutex_lock(&ft_mutex);
523 list_for_each_entry(ft, &fcoe_transports, list) {
524 if (i >= PAGE_SIZE - IFNAMSIZ)
526 i += snprintf(&buffer[i], IFNAMSIZ, "%s ", ft->name);
528 mutex_unlock(&ft_mutex);
530 i += snprintf(&buffer[i], IFNAMSIZ, "none");
534 static int __init fcoe_transport_init(void)
536 register_netdevice_notifier(&libfcoe_notifier);
540 static int fcoe_transport_exit(void)
542 struct fcoe_transport *ft;
544 unregister_netdevice_notifier(&libfcoe_notifier);
545 mutex_lock(&ft_mutex);
546 list_for_each_entry(ft, &fcoe_transports, list)
547 printk(KERN_ERR "FCoE transport %s is still attached!\n",
549 mutex_unlock(&ft_mutex);
554 static int fcoe_add_netdev_mapping(struct net_device *netdev,
555 struct fcoe_transport *ft)
557 struct fcoe_netdev_mapping *nm;
559 nm = kmalloc(sizeof(*nm), GFP_KERNEL);
561 printk(KERN_ERR "Unable to allocate netdev_mapping");
568 mutex_lock(&fn_mutex);
569 list_add(&nm->list, &fcoe_netdevs);
570 mutex_unlock(&fn_mutex);
575 static void fcoe_del_netdev_mapping(struct net_device *netdev)
577 struct fcoe_netdev_mapping *nm = NULL, *tmp;
579 mutex_lock(&fn_mutex);
580 list_for_each_entry_safe(nm, tmp, &fcoe_netdevs, list) {
581 if (nm->netdev == netdev) {
584 mutex_unlock(&fn_mutex);
588 mutex_unlock(&fn_mutex);
593 * fcoe_netdev_map_lookup - find the fcoe transport that matches the netdev on which
596 * Returns : ptr to the fcoe transport that supports this netdev or NULL
599 * The ft_mutex should be held when this is called
601 static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *netdev)
603 struct fcoe_transport *ft = NULL;
604 struct fcoe_netdev_mapping *nm;
606 mutex_lock(&fn_mutex);
607 list_for_each_entry(nm, &fcoe_netdevs, list) {
608 if (netdev == nm->netdev) {
610 mutex_unlock(&fn_mutex);
615 mutex_unlock(&fn_mutex);
620 * fcoe_if_to_netdev() - Parse a name buffer to get a net device
621 * @buffer: The name of the net device
623 * Returns: NULL or a ptr to net_device
625 static struct net_device *fcoe_if_to_netdev(const char *buffer)
628 char ifname[IFNAMSIZ + 2];
631 strlcpy(ifname, buffer, IFNAMSIZ);
632 cp = ifname + strlen(ifname);
633 while (--cp >= ifname && *cp == '\n')
635 return dev_get_by_name(&init_net, ifname);
641 * libfcoe_device_notification() - Handler for net device events
642 * @notifier: The context of the notification
643 * @event: The type of event
644 * @ptr: The net device that the event was on
646 * This function is called by the Ethernet driver in case of link change event.
648 * Returns: 0 for success
650 static int libfcoe_device_notification(struct notifier_block *notifier,
651 ulong event, void *ptr)
653 struct net_device *netdev = ptr;
656 case NETDEV_UNREGISTER:
657 LIBFCOE_TRANSPORT_DBG("NETDEV_UNREGISTER %s\n",
659 fcoe_del_netdev_mapping(netdev);
665 ssize_t fcoe_ctlr_create_store(struct bus_type *bus,
666 const char *buf, size_t count)
668 struct net_device *netdev = NULL;
669 struct fcoe_transport *ft = NULL;
670 struct fcoe_ctlr_device *ctlr_dev = NULL;
674 mutex_lock(&ft_mutex);
676 netdev = fcoe_if_to_netdev(buf);
678 LIBFCOE_TRANSPORT_DBG("Invalid device %s.\n", buf);
683 ft = fcoe_netdev_map_lookup(netdev);
685 LIBFCOE_TRANSPORT_DBG("transport %s already has existing "
686 "FCoE instance on %s.\n",
687 ft->name, netdev->name);
692 ft = fcoe_transport_lookup(netdev);
694 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
700 /* pass to transport create */
701 err = ft->alloc ? ft->alloc(netdev) : -ENODEV;
703 fcoe_del_netdev_mapping(netdev);
708 err = fcoe_add_netdev_mapping(netdev, ft);
710 LIBFCOE_TRANSPORT_DBG("failed to add new netdev mapping "
711 "for FCoE transport %s for %s.\n",
712 ft->name, netdev->name);
717 LIBFCOE_TRANSPORT_DBG("transport %s %s to create fcoe on %s.\n",
718 ft->name, (ctlr_dev) ? "succeeded" : "failed",
724 mutex_unlock(&ft_mutex);
730 ssize_t fcoe_ctlr_destroy_store(struct bus_type *bus,
731 const char *buf, size_t count)
734 struct net_device *netdev = NULL;
735 struct fcoe_transport *ft = NULL;
737 mutex_lock(&ft_mutex);
739 netdev = fcoe_if_to_netdev(buf);
741 LIBFCOE_TRANSPORT_DBG("invalid device %s.\n", buf);
745 ft = fcoe_netdev_map_lookup(netdev);
747 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
752 /* pass to transport destroy */
753 rc = ft->destroy(netdev);
757 fcoe_del_netdev_mapping(netdev);
758 LIBFCOE_TRANSPORT_DBG("transport %s %s to destroy fcoe on %s.\n",
759 ft->name, (rc) ? "failed" : "succeeded",
761 rc = count; /* required for successful return */
765 mutex_unlock(&ft_mutex);
768 EXPORT_SYMBOL(fcoe_ctlr_destroy_store);
771 * fcoe_transport_create() - Create a fcoe interface
772 * @buffer: The name of the Ethernet interface to create on
773 * @kp: The associated kernel param
775 * Called from sysfs. This holds the ft_mutex while calling the
776 * registered fcoe transport's create function.
778 * Returns: 0 for success
780 static int fcoe_transport_create(const char *buffer, struct kernel_param *kp)
783 struct net_device *netdev = NULL;
784 struct fcoe_transport *ft = NULL;
785 enum fip_state fip_mode = (enum fip_state)(long)kp->arg;
787 mutex_lock(&ft_mutex);
789 netdev = fcoe_if_to_netdev(buffer);
791 LIBFCOE_TRANSPORT_DBG("Invalid device %s.\n", buffer);
795 ft = fcoe_netdev_map_lookup(netdev);
797 LIBFCOE_TRANSPORT_DBG("transport %s already has existing "
798 "FCoE instance on %s.\n",
799 ft->name, netdev->name);
804 ft = fcoe_transport_lookup(netdev);
806 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
811 rc = fcoe_add_netdev_mapping(netdev, ft);
813 LIBFCOE_TRANSPORT_DBG("failed to add new netdev mapping "
814 "for FCoE transport %s for %s.\n",
815 ft->name, netdev->name);
819 /* pass to transport create */
820 rc = ft->create ? ft->create(netdev, fip_mode) : -ENODEV;
822 fcoe_del_netdev_mapping(netdev);
824 LIBFCOE_TRANSPORT_DBG("transport %s %s to create fcoe on %s.\n",
825 ft->name, (rc) ? "failed" : "succeeded",
831 mutex_unlock(&ft_mutex);
836 * fcoe_transport_destroy() - Destroy a FCoE interface
837 * @buffer: The name of the Ethernet interface to be destroyed
838 * @kp: The associated kernel parameter
840 * Called from sysfs. This holds the ft_mutex while calling the
841 * registered fcoe transport's destroy function.
843 * Returns: 0 for success
845 static int fcoe_transport_destroy(const char *buffer, struct kernel_param *kp)
848 struct net_device *netdev = NULL;
849 struct fcoe_transport *ft = NULL;
851 mutex_lock(&ft_mutex);
853 netdev = fcoe_if_to_netdev(buffer);
855 LIBFCOE_TRANSPORT_DBG("invalid device %s.\n", buffer);
859 ft = fcoe_netdev_map_lookup(netdev);
861 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
866 /* pass to transport destroy */
867 rc = ft->destroy ? ft->destroy(netdev) : -ENODEV;
868 fcoe_del_netdev_mapping(netdev);
869 LIBFCOE_TRANSPORT_DBG("transport %s %s to destroy fcoe on %s.\n",
870 ft->name, (rc) ? "failed" : "succeeded",
876 mutex_unlock(&ft_mutex);
881 * fcoe_transport_disable() - Disables a FCoE interface
882 * @buffer: The name of the Ethernet interface to be disabled
883 * @kp: The associated kernel parameter
887 * Returns: 0 for success
889 static int fcoe_transport_disable(const char *buffer, struct kernel_param *kp)
892 struct net_device *netdev = NULL;
893 struct fcoe_transport *ft = NULL;
895 mutex_lock(&ft_mutex);
897 netdev = fcoe_if_to_netdev(buffer);
901 ft = fcoe_netdev_map_lookup(netdev);
905 rc = ft->disable ? ft->disable(netdev) : -ENODEV;
910 mutex_unlock(&ft_mutex);
912 if (rc == -ERESTARTSYS)
913 return restart_syscall();
919 * fcoe_transport_enable() - Enables a FCoE interface
920 * @buffer: The name of the Ethernet interface to be enabled
921 * @kp: The associated kernel parameter
925 * Returns: 0 for success
927 static int fcoe_transport_enable(const char *buffer, struct kernel_param *kp)
930 struct net_device *netdev = NULL;
931 struct fcoe_transport *ft = NULL;
933 mutex_lock(&ft_mutex);
935 netdev = fcoe_if_to_netdev(buffer);
939 ft = fcoe_netdev_map_lookup(netdev);
943 rc = ft->enable ? ft->enable(netdev) : -ENODEV;
948 mutex_unlock(&ft_mutex);
953 * libfcoe_init() - Initialization routine for libfcoe.ko
955 static int __init libfcoe_init(void)
959 rc = fcoe_transport_init();
963 rc = fcoe_sysfs_setup();
965 fcoe_transport_exit();
969 module_init(libfcoe_init);
972 * libfcoe_exit() - Tear down libfcoe.ko
974 static void __exit libfcoe_exit(void)
976 fcoe_sysfs_teardown();
977 fcoe_transport_exit();
979 module_exit(libfcoe_exit);