// SPDX-License-Identifier: GPL-2.0-only /* * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved. * * Maintained at www.Open-FCoE.org */ #include <linux/types.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/list.h> #include <linux/netdevice.h> #include <linux/ethtool.h> #include <linux/errno.h> #include <linux/crc32.h> #include <scsi/libfcoe.h> #include "libfcoe.h" MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …; static int fcoe_transport_create(const char *, const struct kernel_param *); static int fcoe_transport_destroy(const char *, const struct kernel_param *); static int fcoe_transport_show(char *buffer, const struct kernel_param *kp); static struct fcoe_transport *fcoe_transport_lookup(struct net_device *device); static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *device); static int fcoe_transport_enable(const char *, const struct kernel_param *); static int fcoe_transport_disable(const char *, const struct kernel_param *); static int libfcoe_device_notification(struct notifier_block *notifier, ulong event, void *ptr); static LIST_HEAD(fcoe_transports); static DEFINE_MUTEX(ft_mutex); static LIST_HEAD(fcoe_netdevs); static DEFINE_MUTEX(fn_mutex); unsigned int libfcoe_debug_logging; module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR); MODULE_PARM_DESC(…) …; module_param_call(…); __MODULE_PARM_TYPE(…) …; MODULE_PARM_DESC(…) …; module_param_call(…); __MODULE_PARM_TYPE(…) …; MODULE_PARM_DESC(…) …; module_param_call(…); __MODULE_PARM_TYPE(…) …; MODULE_PARM_DESC(…) …; module_param_call(…); __MODULE_PARM_TYPE(…) …; MODULE_PARM_DESC(…) …; module_param_call(…); __MODULE_PARM_TYPE(…) …; MODULE_PARM_DESC(…) …; module_param_call(…); __MODULE_PARM_TYPE(…) …; MODULE_PARM_DESC(…) …; /* notification function for packets from net device */ static struct notifier_block libfcoe_notifier = …; static const struct { … } fcoe_port_speed_mapping[] = …; static inline u32 eth2fc_speed(u32 eth_port_speed) { … } /** * fcoe_link_speed_update() - Update the supported and actual link speeds * @lport: The local port to update speeds for * * Returns: 0 if the ethtool query was successful * -1 if the ethtool query failed */ int fcoe_link_speed_update(struct fc_lport *lport) { … } EXPORT_SYMBOL_GPL(…); /** * __fcoe_get_lesb() - Get the Link Error Status Block (LESB) for a given lport * @lport: The local port to update speeds for * @fc_lesb: Pointer to the LESB to be filled up * @netdev: Pointer to the netdev that is associated with the lport * * Note, the Link Error Status Block (LESB) for FCoE is defined in FC-BB-6 * Clause 7.11 in v1.04. */ void __fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb, struct net_device *netdev) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_get_lesb() - Fill the FCoE Link Error Status Block * @lport: the local port * @fc_lesb: the link error status block */ void fcoe_get_lesb(struct fc_lport *lport, struct fc_els_lesb *fc_lesb) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_ctlr_get_lesb() - Get the Link Error Status Block (LESB) for a given * fcoe controller device * @ctlr_dev: The given fcoe controller device * */ void fcoe_ctlr_get_lesb(struct fcoe_ctlr_device *ctlr_dev) { … } EXPORT_SYMBOL_GPL(…); void fcoe_wwn_to_str(u64 wwn, char *buf, int len) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_validate_vport_create() - Validate a vport before creating it * @vport: NPIV port to be created * * This routine is meant to add validation for a vport before creating it * via fcoe_vport_create(). * Current validations are: * - WWPN supplied is unique for given lport */ int fcoe_validate_vport_create(struct fc_vport *vport) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_get_wwn() - Get the world wide name from LLD if it supports it * @netdev: the associated net device * @wwn: the output WWN * @type: the type of WWN (WWPN or WWNN) * * Returns: 0 for success */ int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_fc_crc() - Calculates the CRC for a given frame * @fp: The frame to be checksumed * * This uses crc32() routine to calculate the CRC for a frame * * Return: The 32 bit CRC value */ u32 fcoe_fc_crc(struct fc_frame *fp) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_start_io() - Start FCoE I/O * @skb: The packet to be transmitted * * This routine is called from the net device to start transmitting * FCoE packets. * * Returns: 0 for success */ int fcoe_start_io(struct sk_buff *skb) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_clean_pending_queue() - Dequeue a skb and free it * @lport: The local port to dequeue a skb on */ void fcoe_clean_pending_queue(struct fc_lport *lport) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_check_wait_queue() - Attempt to clear the transmit backlog * @lport: The local port whose backlog is to be cleared * @skb: The received FIP packet * * This empties the wait_queue, dequeues the head of the wait_queue queue * and calls fcoe_start_io() for each packet. If all skb have been * transmitted it returns the qlen. If an error occurs it restores * wait_queue (to try again later) and returns -1. * * The wait_queue is used when the skb transmit fails. The failed skb * will go in the wait_queue which will be emptied by the timer function or * by the next skb transmit. */ void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_queue_timer() - The fcoe queue timer * @t: Timer context use to obtain the FCoE port * * Calls fcoe_check_wait_queue on timeout */ void fcoe_queue_timer(struct timer_list *t) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC * @skb: The packet to be transmitted * @tlen: The total length of the trailer * @fps: The fcoe context * * This routine allocates a page for frame trailers. The page is re-used if * there is enough room left on it for the current trailer. If there isn't * enough buffer left a new page is allocated for the trailer. Reference to * the page from this function as well as the skbs using the page fragments * ensure that the page is freed at the appropriate time. * * Returns: 0 for success */ int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen, struct fcoe_percpu_s *fps) { … } EXPORT_SYMBOL_GPL(…); /** * fcoe_transport_lookup - find an fcoe transport that matches a netdev * @netdev: The netdev to look for from all attached transports * * Returns : ptr to the fcoe transport that supports this netdev or NULL * if not found. * * The ft_mutex should be held when this is called */ static struct fcoe_transport *fcoe_transport_lookup(struct net_device *netdev) { … } /** * fcoe_transport_attach - Attaches an FCoE transport * @ft: The fcoe transport to be attached * * Returns : 0 for success */ int fcoe_transport_attach(struct fcoe_transport *ft) { … } EXPORT_SYMBOL(…); /** * fcoe_transport_detach - Detaches an FCoE transport * @ft: The fcoe transport to be attached * * Returns : 0 for success */ int fcoe_transport_detach(struct fcoe_transport *ft) { … } EXPORT_SYMBOL(…); static int fcoe_transport_show(char *buffer, const struct kernel_param *kp) { … } static int __init fcoe_transport_init(void) { … } static int fcoe_transport_exit(void) { … } static int fcoe_add_netdev_mapping(struct net_device *netdev, struct fcoe_transport *ft) { … } static void fcoe_del_netdev_mapping(struct net_device *netdev) { … } /** * fcoe_netdev_map_lookup - find the fcoe transport that matches the netdev on which * it was created * @netdev: The net device that the FCoE interface is on * * Returns : ptr to the fcoe transport that supports this netdev or NULL * if not found. * * The ft_mutex should be held when this is called */ static struct fcoe_transport *fcoe_netdev_map_lookup(struct net_device *netdev) { … } /** * fcoe_if_to_netdev() - Parse a name buffer to get a net device * @buffer: The name of the net device * * Returns: NULL or a ptr to net_device */ static struct net_device *fcoe_if_to_netdev(const char *buffer) { … } /** * libfcoe_device_notification() - Handler for net device events * @notifier: The context of the notification * @event: The type of event * @ptr: The net device that the event was on * * This function is called by the Ethernet driver in case of link change event. * * Returns: 0 for success */ static int libfcoe_device_notification(struct notifier_block *notifier, ulong event, void *ptr) { … } ssize_t fcoe_ctlr_create_store(const char *buf, size_t count) { … } ssize_t fcoe_ctlr_destroy_store(const char *buf, size_t count) { … } /** * fcoe_transport_create() - Create a fcoe interface * @buffer: The name of the Ethernet interface to create on * @kp: The associated kernel param * * Called from sysfs. This holds the ft_mutex while calling the * registered fcoe transport's create function. * * Returns: 0 for success */ static int fcoe_transport_create(const char *buffer, const struct kernel_param *kp) { … } /** * fcoe_transport_destroy() - Destroy a FCoE interface * @buffer: The name of the Ethernet interface to be destroyed * @kp: The associated kernel parameter * * Called from sysfs. This holds the ft_mutex while calling the * registered fcoe transport's destroy function. * * Returns: 0 for success */ static int fcoe_transport_destroy(const char *buffer, const struct kernel_param *kp) { … } /** * fcoe_transport_disable() - Disables a FCoE interface * @buffer: The name of the Ethernet interface to be disabled * @kp: The associated kernel parameter * * Called from sysfs. * * Returns: 0 for success */ static int fcoe_transport_disable(const char *buffer, const struct kernel_param *kp) { … } /** * fcoe_transport_enable() - Enables a FCoE interface * @buffer: The name of the Ethernet interface to be enabled * @kp: The associated kernel parameter * * Called from sysfs. * * Returns: 0 for success */ static int fcoe_transport_enable(const char *buffer, const struct kernel_param *kp) { … } /** * libfcoe_init() - Initialization routine for libfcoe.ko */ static int __init libfcoe_init(void) { … } module_init(…) …; /** * libfcoe_exit() - Tear down libfcoe.ko */ static void __exit libfcoe_exit(void) { … } module_exit(libfcoe_exit);