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
);
122 * __fcoe_get_lesb() - Get the Link Error Status Block (LESB) for a given lport
123 * @lport: The local port to update speeds for
124 * @fc_lesb: Pointer to the LESB to be filled up
125 * @netdev: Pointer to the netdev that is associated with the lport
127 * Note, the Link Error Status Block (LESB) for FCoE is defined in FC-BB-6
128 * Clause 7.11 in v1.04.
130 void __fcoe_get_lesb(struct fc_lport
*lport
,
131 struct fc_els_lesb
*fc_lesb
,
132 struct net_device
*netdev
)
136 struct fc_stats
*stats
;
137 struct fcoe_fc_els_lesb
*lesb
;
138 struct rtnl_link_stats64 temp
;
143 lesb
= (struct fcoe_fc_els_lesb
*)fc_lesb
;
144 memset(lesb
, 0, sizeof(*lesb
));
145 for_each_possible_cpu(cpu
) {
146 stats
= per_cpu_ptr(lport
->stats
, cpu
);
147 lfc
+= stats
->LinkFailureCount
;
148 vlfc
+= stats
->VLinkFailureCount
;
149 mdac
+= stats
->MissDiscAdvCount
;
151 lesb
->lesb_link_fail
= htonl(lfc
);
152 lesb
->lesb_vlink_fail
= htonl(vlfc
);
153 lesb
->lesb_miss_fka
= htonl(mdac
);
154 lesb
->lesb_fcs_error
=
155 htonl(dev_get_stats(netdev
, &temp
)->rx_crc_errors
);
157 EXPORT_SYMBOL_GPL(__fcoe_get_lesb
);
160 * fcoe_get_lesb() - Fill the FCoE Link Error Status Block
161 * @lport: the local port
162 * @fc_lesb: the link error status block
164 void fcoe_get_lesb(struct fc_lport
*lport
,
165 struct fc_els_lesb
*fc_lesb
)
167 struct net_device
*netdev
= fcoe_get_netdev(lport
);
169 __fcoe_get_lesb(lport
, fc_lesb
, netdev
);
171 EXPORT_SYMBOL_GPL(fcoe_get_lesb
);
174 * fcoe_ctlr_get_lesb() - Get the Link Error Status Block (LESB) for a given
175 * fcoe controller device
176 * @ctlr_dev: The given fcoe controller device
179 void fcoe_ctlr_get_lesb(struct fcoe_ctlr_device
*ctlr_dev
)
181 struct fcoe_ctlr
*fip
= fcoe_ctlr_device_priv(ctlr_dev
);
182 struct net_device
*netdev
= fcoe_get_netdev(fip
->lp
);
183 struct fc_els_lesb
*fc_lesb
;
185 fc_lesb
= (struct fc_els_lesb
*)(&ctlr_dev
->lesb
);
186 __fcoe_get_lesb(fip
->lp
, fc_lesb
, netdev
);
188 EXPORT_SYMBOL_GPL(fcoe_ctlr_get_lesb
);
190 void fcoe_wwn_to_str(u64 wwn
, char *buf
, int len
)
194 u64_to_wwn(wwn
, wwpn
);
195 snprintf(buf
, len
, "%02x%02x%02x%02x%02x%02x%02x%02x",
196 wwpn
[0], wwpn
[1], wwpn
[2], wwpn
[3],
197 wwpn
[4], wwpn
[5], wwpn
[6], wwpn
[7]);
199 EXPORT_SYMBOL_GPL(fcoe_wwn_to_str
);
202 * fcoe_validate_vport_create() - Validate a vport before creating it
203 * @vport: NPIV port to be created
205 * This routine is meant to add validation for a vport before creating it
206 * via fcoe_vport_create().
207 * Current validations are:
208 * - WWPN supplied is unique for given lport
210 int fcoe_validate_vport_create(struct fc_vport
*vport
)
212 struct Scsi_Host
*shost
= vport_to_shost(vport
);
213 struct fc_lport
*n_port
= shost_priv(shost
);
214 struct fc_lport
*vn_port
;
218 mutex_lock(&n_port
->lp_mutex
);
220 fcoe_wwn_to_str(vport
->port_name
, buf
, sizeof(buf
));
221 /* Check if the wwpn is not same as that of the lport */
222 if (!memcmp(&n_port
->wwpn
, &vport
->port_name
, sizeof(u64
))) {
223 LIBFCOE_TRANSPORT_DBG("vport WWPN 0x%s is same as that of the "
224 "base port WWPN\n", buf
);
229 /* Check if there is any existing vport with same wwpn */
230 list_for_each_entry(vn_port
, &n_port
->vports
, list
) {
231 if (!memcmp(&vn_port
->wwpn
, &vport
->port_name
, sizeof(u64
))) {
232 LIBFCOE_TRANSPORT_DBG("vport with given WWPN 0x%s "
233 "already exists\n", buf
);
239 mutex_unlock(&n_port
->lp_mutex
);
242 EXPORT_SYMBOL_GPL(fcoe_validate_vport_create
);
245 * fcoe_get_wwn() - Get the world wide name from LLD if it supports it
246 * @netdev: the associated net device
247 * @wwn: the output WWN
248 * @type: the type of WWN (WWPN or WWNN)
250 * Returns: 0 for success
252 int fcoe_get_wwn(struct net_device
*netdev
, u64
*wwn
, int type
)
254 const struct net_device_ops
*ops
= netdev
->netdev_ops
;
256 if (ops
->ndo_fcoe_get_wwn
)
257 return ops
->ndo_fcoe_get_wwn(netdev
, wwn
, type
);
260 EXPORT_SYMBOL_GPL(fcoe_get_wwn
);
263 * fcoe_fc_crc() - Calculates the CRC for a given frame
264 * @fp: The frame to be checksumed
266 * This uses crc32() routine to calculate the CRC for a frame
268 * Return: The 32 bit CRC value
270 u32
fcoe_fc_crc(struct fc_frame
*fp
)
272 struct sk_buff
*skb
= fp_skb(fp
);
273 struct skb_frag_struct
*frag
;
275 unsigned long off
, len
, clen
;
279 crc
= crc32(~0, skb
->data
, skb_headlen(skb
));
281 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
282 frag
= &skb_shinfo(skb
)->frags
[i
];
283 off
= frag
->page_offset
;
284 len
= skb_frag_size(frag
);
286 clen
= min(len
, PAGE_SIZE
- (off
& ~PAGE_MASK
));
288 skb_frag_page(frag
) + (off
>> PAGE_SHIFT
));
289 crc
= crc32(crc
, data
+ (off
& ~PAGE_MASK
), clen
);
297 EXPORT_SYMBOL_GPL(fcoe_fc_crc
);
300 * fcoe_start_io() - Start FCoE I/O
301 * @skb: The packet to be transmitted
303 * This routine is called from the net device to start transmitting
306 * Returns: 0 for success
308 int fcoe_start_io(struct sk_buff
*skb
)
310 struct sk_buff
*nskb
;
313 nskb
= skb_clone(skb
, GFP_ATOMIC
);
316 rc
= dev_queue_xmit(nskb
);
322 EXPORT_SYMBOL_GPL(fcoe_start_io
);
326 * fcoe_clean_pending_queue() - Dequeue a skb and free it
327 * @lport: The local port to dequeue a skb on
329 void fcoe_clean_pending_queue(struct fc_lport
*lport
)
331 struct fcoe_port
*port
= lport_priv(lport
);
334 spin_lock_bh(&port
->fcoe_pending_queue
.lock
);
335 while ((skb
= __skb_dequeue(&port
->fcoe_pending_queue
)) != NULL
) {
336 spin_unlock_bh(&port
->fcoe_pending_queue
.lock
);
338 spin_lock_bh(&port
->fcoe_pending_queue
.lock
);
340 spin_unlock_bh(&port
->fcoe_pending_queue
.lock
);
342 EXPORT_SYMBOL_GPL(fcoe_clean_pending_queue
);
345 * fcoe_check_wait_queue() - Attempt to clear the transmit backlog
346 * @lport: The local port whose backlog is to be cleared
348 * This empties the wait_queue, dequeues the head of the wait_queue queue
349 * and calls fcoe_start_io() for each packet. If all skb have been
350 * transmitted it returns the qlen. If an error occurs it restores
351 * wait_queue (to try again later) and returns -1.
353 * The wait_queue is used when the skb transmit fails. The failed skb
354 * will go in the wait_queue which will be emptied by the timer function or
355 * by the next skb transmit.
357 void fcoe_check_wait_queue(struct fc_lport
*lport
, struct sk_buff
*skb
)
359 struct fcoe_port
*port
= lport_priv(lport
);
362 spin_lock_bh(&port
->fcoe_pending_queue
.lock
);
365 __skb_queue_tail(&port
->fcoe_pending_queue
, skb
);
367 if (port
->fcoe_pending_queue_active
)
369 port
->fcoe_pending_queue_active
= 1;
371 while (port
->fcoe_pending_queue
.qlen
) {
372 /* keep qlen > 0 until fcoe_start_io succeeds */
373 port
->fcoe_pending_queue
.qlen
++;
374 skb
= __skb_dequeue(&port
->fcoe_pending_queue
);
376 spin_unlock_bh(&port
->fcoe_pending_queue
.lock
);
377 rc
= fcoe_start_io(skb
);
378 spin_lock_bh(&port
->fcoe_pending_queue
.lock
);
381 __skb_queue_head(&port
->fcoe_pending_queue
, skb
);
382 /* undo temporary increment above */
383 port
->fcoe_pending_queue
.qlen
--;
386 /* undo temporary increment above */
387 port
->fcoe_pending_queue
.qlen
--;
390 if (port
->fcoe_pending_queue
.qlen
< port
->min_queue_depth
)
392 if (port
->fcoe_pending_queue
.qlen
&& !timer_pending(&port
->timer
))
393 mod_timer(&port
->timer
, jiffies
+ 2);
394 port
->fcoe_pending_queue_active
= 0;
396 if (port
->fcoe_pending_queue
.qlen
> port
->max_queue_depth
)
398 spin_unlock_bh(&port
->fcoe_pending_queue
.lock
);
400 EXPORT_SYMBOL_GPL(fcoe_check_wait_queue
);
403 * fcoe_queue_timer() - The fcoe queue timer
404 * @lport: The local port
406 * Calls fcoe_check_wait_queue on timeout
408 void fcoe_queue_timer(ulong lport
)
410 fcoe_check_wait_queue((struct fc_lport
*)lport
, NULL
);
412 EXPORT_SYMBOL_GPL(fcoe_queue_timer
);
415 * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC
416 * @skb: The packet to be transmitted
417 * @tlen: The total length of the trailer
418 * @fps: The fcoe context
420 * This routine allocates a page for frame trailers. The page is re-used if
421 * there is enough room left on it for the current trailer. If there isn't
422 * enough buffer left a new page is allocated for the trailer. Reference to
423 * the page from this function as well as the skbs using the page fragments
424 * ensure that the page is freed at the appropriate time.
426 * Returns: 0 for success
428 int fcoe_get_paged_crc_eof(struct sk_buff
*skb
, int tlen
,
429 struct fcoe_percpu_s
*fps
)
433 page
= fps
->crc_eof_page
;
435 page
= alloc_page(GFP_ATOMIC
);
439 fps
->crc_eof_page
= page
;
440 fps
->crc_eof_offset
= 0;
444 skb_fill_page_desc(skb
, skb_shinfo(skb
)->nr_frags
, page
,
445 fps
->crc_eof_offset
, tlen
);
447 skb
->data_len
+= tlen
;
448 skb
->truesize
+= tlen
;
449 fps
->crc_eof_offset
+= sizeof(struct fcoe_crc_eof
);
451 if (fps
->crc_eof_offset
>= PAGE_SIZE
) {
452 fps
->crc_eof_page
= NULL
;
453 fps
->crc_eof_offset
= 0;
459 EXPORT_SYMBOL_GPL(fcoe_get_paged_crc_eof
);
462 * fcoe_transport_lookup - find an fcoe transport that matches a netdev
463 * @netdev: The netdev to look for from all attached transports
465 * Returns : ptr to the fcoe transport that supports this netdev or NULL
468 * The ft_mutex should be held when this is called
470 static struct fcoe_transport
*fcoe_transport_lookup(struct net_device
*netdev
)
472 struct fcoe_transport
*ft
= NULL
;
474 list_for_each_entry(ft
, &fcoe_transports
, list
)
475 if (ft
->match
&& ft
->match(netdev
))
481 * fcoe_transport_attach - Attaches an FCoE transport
482 * @ft: The fcoe transport to be attached
484 * Returns : 0 for success
486 int fcoe_transport_attach(struct fcoe_transport
*ft
)
490 mutex_lock(&ft_mutex
);
492 LIBFCOE_TRANSPORT_DBG("transport %s already attached\n",
498 /* Add default transport to the tail */
499 if (strcmp(ft
->name
, FCOE_TRANSPORT_DEFAULT
))
500 list_add(&ft
->list
, &fcoe_transports
);
502 list_add_tail(&ft
->list
, &fcoe_transports
);
505 LIBFCOE_TRANSPORT_DBG("attaching transport %s\n", ft
->name
);
508 mutex_unlock(&ft_mutex
);
511 EXPORT_SYMBOL(fcoe_transport_attach
);
514 * fcoe_transport_detach - Detaches an FCoE transport
515 * @ft: The fcoe transport to be attached
517 * Returns : 0 for success
519 int fcoe_transport_detach(struct fcoe_transport
*ft
)
522 struct fcoe_netdev_mapping
*nm
= NULL
, *tmp
;
524 mutex_lock(&ft_mutex
);
526 LIBFCOE_TRANSPORT_DBG("transport %s already detached\n",
532 /* remove netdev mapping for this transport as it is going away */
533 mutex_lock(&fn_mutex
);
534 list_for_each_entry_safe(nm
, tmp
, &fcoe_netdevs
, list
) {
536 LIBFCOE_TRANSPORT_DBG("transport %s going away, "
537 "remove its netdev mapping for %s\n",
538 ft
->name
, nm
->netdev
->name
);
543 mutex_unlock(&fn_mutex
);
546 ft
->attached
= false;
547 LIBFCOE_TRANSPORT_DBG("detaching transport %s\n", ft
->name
);
550 mutex_unlock(&ft_mutex
);
554 EXPORT_SYMBOL(fcoe_transport_detach
);
556 static int fcoe_transport_show(char *buffer
, const struct kernel_param
*kp
)
559 struct fcoe_transport
*ft
= NULL
;
561 i
= j
= sprintf(buffer
, "Attached FCoE transports:");
562 mutex_lock(&ft_mutex
);
563 list_for_each_entry(ft
, &fcoe_transports
, list
) {
564 if (i
>= PAGE_SIZE
- IFNAMSIZ
)
566 i
+= snprintf(&buffer
[i
], IFNAMSIZ
, "%s ", ft
->name
);
568 mutex_unlock(&ft_mutex
);
570 i
+= snprintf(&buffer
[i
], IFNAMSIZ
, "none");
574 static int __init
fcoe_transport_init(void)
576 register_netdevice_notifier(&libfcoe_notifier
);
580 static int fcoe_transport_exit(void)
582 struct fcoe_transport
*ft
;
584 unregister_netdevice_notifier(&libfcoe_notifier
);
585 mutex_lock(&ft_mutex
);
586 list_for_each_entry(ft
, &fcoe_transports
, list
)
587 printk(KERN_ERR
"FCoE transport %s is still attached!\n",
589 mutex_unlock(&ft_mutex
);
594 static int fcoe_add_netdev_mapping(struct net_device
*netdev
,
595 struct fcoe_transport
*ft
)
597 struct fcoe_netdev_mapping
*nm
;
599 nm
= kmalloc(sizeof(*nm
), GFP_KERNEL
);
601 printk(KERN_ERR
"Unable to allocate netdev_mapping");
608 mutex_lock(&fn_mutex
);
609 list_add(&nm
->list
, &fcoe_netdevs
);
610 mutex_unlock(&fn_mutex
);
615 static void fcoe_del_netdev_mapping(struct net_device
*netdev
)
617 struct fcoe_netdev_mapping
*nm
= NULL
, *tmp
;
619 mutex_lock(&fn_mutex
);
620 list_for_each_entry_safe(nm
, tmp
, &fcoe_netdevs
, list
) {
621 if (nm
->netdev
== netdev
) {
624 mutex_unlock(&fn_mutex
);
628 mutex_unlock(&fn_mutex
);
633 * fcoe_netdev_map_lookup - find the fcoe transport that matches the netdev on which
636 * Returns : ptr to the fcoe transport that supports this netdev or NULL
639 * The ft_mutex should be held when this is called
641 static struct fcoe_transport
*fcoe_netdev_map_lookup(struct net_device
*netdev
)
643 struct fcoe_transport
*ft
= NULL
;
644 struct fcoe_netdev_mapping
*nm
;
646 mutex_lock(&fn_mutex
);
647 list_for_each_entry(nm
, &fcoe_netdevs
, list
) {
648 if (netdev
== nm
->netdev
) {
650 mutex_unlock(&fn_mutex
);
655 mutex_unlock(&fn_mutex
);
660 * fcoe_if_to_netdev() - Parse a name buffer to get a net device
661 * @buffer: The name of the net device
663 * Returns: NULL or a ptr to net_device
665 static struct net_device
*fcoe_if_to_netdev(const char *buffer
)
668 char ifname
[IFNAMSIZ
+ 2];
671 strlcpy(ifname
, buffer
, IFNAMSIZ
);
672 cp
= ifname
+ strlen(ifname
);
673 while (--cp
>= ifname
&& *cp
== '\n')
675 return dev_get_by_name(&init_net
, ifname
);
681 * libfcoe_device_notification() - Handler for net device events
682 * @notifier: The context of the notification
683 * @event: The type of event
684 * @ptr: The net device that the event was on
686 * This function is called by the Ethernet driver in case of link change event.
688 * Returns: 0 for success
690 static int libfcoe_device_notification(struct notifier_block
*notifier
,
691 ulong event
, void *ptr
)
693 struct net_device
*netdev
= netdev_notifier_info_to_dev(ptr
);
696 case NETDEV_UNREGISTER
:
697 LIBFCOE_TRANSPORT_DBG("NETDEV_UNREGISTER %s\n",
699 fcoe_del_netdev_mapping(netdev
);
705 ssize_t
fcoe_ctlr_create_store(struct bus_type
*bus
,
706 const char *buf
, size_t count
)
708 struct net_device
*netdev
= NULL
;
709 struct fcoe_transport
*ft
= NULL
;
713 mutex_lock(&ft_mutex
);
715 netdev
= fcoe_if_to_netdev(buf
);
717 LIBFCOE_TRANSPORT_DBG("Invalid device %s.\n", buf
);
722 ft
= fcoe_netdev_map_lookup(netdev
);
724 LIBFCOE_TRANSPORT_DBG("transport %s already has existing "
725 "FCoE instance on %s.\n",
726 ft
->name
, netdev
->name
);
731 ft
= fcoe_transport_lookup(netdev
);
733 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
739 /* pass to transport create */
740 err
= ft
->alloc
? ft
->alloc(netdev
) : -ENODEV
;
742 fcoe_del_netdev_mapping(netdev
);
747 err
= fcoe_add_netdev_mapping(netdev
, ft
);
749 LIBFCOE_TRANSPORT_DBG("failed to add new netdev mapping "
750 "for FCoE transport %s for %s.\n",
751 ft
->name
, netdev
->name
);
756 LIBFCOE_TRANSPORT_DBG("transport %s succeeded to create fcoe on %s.\n",
757 ft
->name
, netdev
->name
);
762 mutex_unlock(&ft_mutex
);
768 ssize_t
fcoe_ctlr_destroy_store(struct bus_type
*bus
,
769 const char *buf
, size_t count
)
772 struct net_device
*netdev
= NULL
;
773 struct fcoe_transport
*ft
= NULL
;
775 mutex_lock(&ft_mutex
);
777 netdev
= fcoe_if_to_netdev(buf
);
779 LIBFCOE_TRANSPORT_DBG("invalid device %s.\n", buf
);
783 ft
= fcoe_netdev_map_lookup(netdev
);
785 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
790 /* pass to transport destroy */
791 rc
= ft
->destroy(netdev
);
795 fcoe_del_netdev_mapping(netdev
);
796 LIBFCOE_TRANSPORT_DBG("transport %s %s to destroy fcoe on %s.\n",
797 ft
->name
, (rc
) ? "failed" : "succeeded",
799 rc
= count
; /* required for successful return */
803 mutex_unlock(&ft_mutex
);
806 EXPORT_SYMBOL(fcoe_ctlr_destroy_store
);
809 * fcoe_transport_create() - Create a fcoe interface
810 * @buffer: The name of the Ethernet interface to create on
811 * @kp: The associated kernel param
813 * Called from sysfs. This holds the ft_mutex while calling the
814 * registered fcoe transport's create function.
816 * Returns: 0 for success
818 static int fcoe_transport_create(const char *buffer
, struct kernel_param
*kp
)
821 struct net_device
*netdev
= NULL
;
822 struct fcoe_transport
*ft
= NULL
;
823 enum fip_state fip_mode
= (enum fip_state
)(long)kp
->arg
;
825 mutex_lock(&ft_mutex
);
827 netdev
= fcoe_if_to_netdev(buffer
);
829 LIBFCOE_TRANSPORT_DBG("Invalid device %s.\n", buffer
);
833 ft
= fcoe_netdev_map_lookup(netdev
);
835 LIBFCOE_TRANSPORT_DBG("transport %s already has existing "
836 "FCoE instance on %s.\n",
837 ft
->name
, netdev
->name
);
842 ft
= fcoe_transport_lookup(netdev
);
844 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
849 rc
= fcoe_add_netdev_mapping(netdev
, ft
);
851 LIBFCOE_TRANSPORT_DBG("failed to add new netdev mapping "
852 "for FCoE transport %s for %s.\n",
853 ft
->name
, netdev
->name
);
857 /* pass to transport create */
858 rc
= ft
->create
? ft
->create(netdev
, fip_mode
) : -ENODEV
;
860 fcoe_del_netdev_mapping(netdev
);
862 LIBFCOE_TRANSPORT_DBG("transport %s %s to create fcoe on %s.\n",
863 ft
->name
, (rc
) ? "failed" : "succeeded",
869 mutex_unlock(&ft_mutex
);
874 * fcoe_transport_destroy() - Destroy a FCoE interface
875 * @buffer: The name of the Ethernet interface to be destroyed
876 * @kp: The associated kernel parameter
878 * Called from sysfs. This holds the ft_mutex while calling the
879 * registered fcoe transport's destroy function.
881 * Returns: 0 for success
883 static int fcoe_transport_destroy(const char *buffer
, struct kernel_param
*kp
)
886 struct net_device
*netdev
= NULL
;
887 struct fcoe_transport
*ft
= NULL
;
889 mutex_lock(&ft_mutex
);
891 netdev
= fcoe_if_to_netdev(buffer
);
893 LIBFCOE_TRANSPORT_DBG("invalid device %s.\n", buffer
);
897 ft
= fcoe_netdev_map_lookup(netdev
);
899 LIBFCOE_TRANSPORT_DBG("no FCoE transport found for %s.\n",
904 /* pass to transport destroy */
905 rc
= ft
->destroy
? ft
->destroy(netdev
) : -ENODEV
;
906 fcoe_del_netdev_mapping(netdev
);
907 LIBFCOE_TRANSPORT_DBG("transport %s %s to destroy fcoe on %s.\n",
908 ft
->name
, (rc
) ? "failed" : "succeeded",
914 mutex_unlock(&ft_mutex
);
919 * fcoe_transport_disable() - Disables a FCoE interface
920 * @buffer: The name of the Ethernet interface to be disabled
921 * @kp: The associated kernel parameter
925 * Returns: 0 for success
927 static int fcoe_transport_disable(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
->disable
? ft
->disable(netdev
) : -ENODEV
;
948 mutex_unlock(&ft_mutex
);
953 * fcoe_transport_enable() - Enables a FCoE interface
954 * @buffer: The name of the Ethernet interface to be enabled
955 * @kp: The associated kernel parameter
959 * Returns: 0 for success
961 static int fcoe_transport_enable(const char *buffer
, struct kernel_param
*kp
)
964 struct net_device
*netdev
= NULL
;
965 struct fcoe_transport
*ft
= NULL
;
967 mutex_lock(&ft_mutex
);
969 netdev
= fcoe_if_to_netdev(buffer
);
973 ft
= fcoe_netdev_map_lookup(netdev
);
977 rc
= ft
->enable
? ft
->enable(netdev
) : -ENODEV
;
982 mutex_unlock(&ft_mutex
);
987 * libfcoe_init() - Initialization routine for libfcoe.ko
989 static int __init
libfcoe_init(void)
993 rc
= fcoe_transport_init();
997 rc
= fcoe_sysfs_setup();
999 fcoe_transport_exit();
1003 module_init(libfcoe_init
);
1006 * libfcoe_exit() - Tear down libfcoe.ko
1008 static void __exit
libfcoe_exit(void)
1010 fcoe_sysfs_teardown();
1011 fcoe_transport_exit();
1013 module_exit(libfcoe_exit
);