1a703e490SVasu Dev /* 2af7f85d9SChris Leech * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved. 3a703e490SVasu Dev * 4a703e490SVasu Dev * This program is free software; you can redistribute it and/or modify it 5a703e490SVasu Dev * under the terms and conditions of the GNU General Public License, 6a703e490SVasu Dev * version 2, as published by the Free Software Foundation. 7a703e490SVasu Dev * 8a703e490SVasu Dev * This program is distributed in the hope it will be useful, but WITHOUT 9a703e490SVasu Dev * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10a703e490SVasu Dev * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11a703e490SVasu Dev * more details. 12a703e490SVasu Dev * 13a703e490SVasu Dev * You should have received a copy of the GNU General Public License along with 14a703e490SVasu Dev * this program; if not, write to the Free Software Foundation, Inc., 15a703e490SVasu Dev * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 16a703e490SVasu Dev * 17a703e490SVasu Dev * Maintained at www.Open-FCoE.org 18a703e490SVasu Dev */ 19a703e490SVasu Dev 20a703e490SVasu Dev #include <linux/module.h> 21a703e490SVasu Dev #include <linux/version.h> 22a703e490SVasu Dev #include <linux/spinlock.h> 23a703e490SVasu Dev #include <linux/netdevice.h> 24a703e490SVasu Dev #include <linux/etherdevice.h> 25a703e490SVasu Dev #include <linux/ethtool.h> 26a703e490SVasu Dev #include <linux/if_ether.h> 27a703e490SVasu Dev #include <linux/if_vlan.h> 28a703e490SVasu Dev #include <linux/crc32.h> 295a0e3ad6STejun Heo #include <linux/slab.h> 30a703e490SVasu Dev #include <linux/cpu.h> 31a703e490SVasu Dev #include <linux/fs.h> 32a703e490SVasu Dev #include <linux/sysfs.h> 33a703e490SVasu Dev #include <linux/ctype.h> 34a703e490SVasu Dev #include <scsi/scsi_tcq.h> 35a703e490SVasu Dev #include <scsi/scsicam.h> 36a703e490SVasu Dev #include <scsi/scsi_transport.h> 37a703e490SVasu Dev #include <scsi/scsi_transport_fc.h> 38a703e490SVasu Dev #include <net/rtnetlink.h> 39a703e490SVasu Dev 40a703e490SVasu Dev #include <scsi/fc/fc_encaps.h> 4197c8389dSJoe Eykholt #include <scsi/fc/fc_fip.h> 42a703e490SVasu Dev 43a703e490SVasu Dev #include <scsi/libfc.h> 44a703e490SVasu Dev #include <scsi/fc_frame.h> 45a703e490SVasu Dev #include <scsi/libfcoe.h> 46a703e490SVasu Dev 47fdd78027SVasu Dev #include "fcoe.h" 48fdd78027SVasu Dev 49a703e490SVasu Dev MODULE_AUTHOR("Open-FCoE.org"); 50a703e490SVasu Dev MODULE_DESCRIPTION("FCoE"); 519b34ecffSVasu Dev MODULE_LICENSE("GPL v2"); 52a703e490SVasu Dev 5305cc7390SYi Zou /* Performance tuning parameters for fcoe */ 5405cc7390SYi Zou static unsigned int fcoe_ddp_min; 5505cc7390SYi Zou module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR); 5605cc7390SYi Zou MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \ 5705cc7390SYi Zou "Direct Data Placement (DDP)."); 5805cc7390SYi Zou 59dfc1d0feSChris Leech DEFINE_MUTEX(fcoe_config_mutex); 60dfc1d0feSChris Leech 61e7a51997SJoe Eykholt /* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */ 62e7a51997SJoe Eykholt static DECLARE_COMPLETION(fcoe_flush_completion); 63e7a51997SJoe Eykholt 64a703e490SVasu Dev /* fcoe host list */ 65090eb6c4SChris Leech /* must only by accessed under the RTNL mutex */ 66a703e490SVasu Dev LIST_HEAD(fcoe_hostlist); 67a703e490SVasu Dev DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu); 68a703e490SVasu Dev 69dd3fd72eSChris Leech /* Function Prototypes */ 701875f27eSRobert Love static int fcoe_reset(struct Scsi_Host *); 71fdd78027SVasu Dev static int fcoe_xmit(struct fc_lport *, struct fc_frame *); 72fdd78027SVasu Dev static int fcoe_rcv(struct sk_buff *, struct net_device *, 73fdd78027SVasu Dev struct packet_type *, struct net_device *); 741875f27eSRobert Love static int fcoe_percpu_receive_thread(void *); 751875f27eSRobert Love static void fcoe_clean_pending_queue(struct fc_lport *); 761875f27eSRobert Love static void fcoe_percpu_clean(struct fc_lport *); 775e4f8fe7SRobert Love static int fcoe_link_speed_update(struct fc_lport *); 781875f27eSRobert Love static int fcoe_link_ok(struct fc_lport *); 79fdd78027SVasu Dev 80fdd78027SVasu Dev static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *); 81fdd78027SVasu Dev static int fcoe_hostlist_add(const struct fc_lport *); 82fdd78027SVasu Dev 834bb6b515SVasu Dev static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *); 84a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *, ulong, void *); 85a703e490SVasu Dev static void fcoe_dev_setup(void); 86a703e490SVasu Dev static void fcoe_dev_cleanup(void); 871875f27eSRobert Love static struct fcoe_interface 881875f27eSRobert Love *fcoe_hostlist_lookup_port(const struct net_device *); 89a703e490SVasu Dev 901875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *, struct net_device *, 911875f27eSRobert Love struct packet_type *, struct net_device *); 921875f27eSRobert Love 931875f27eSRobert Love static void fcoe_fip_send(struct fcoe_ctlr *, struct sk_buff *); 941875f27eSRobert Love static void fcoe_update_src_mac(struct fc_lport *, u8 *); 951875f27eSRobert Love static u8 *fcoe_get_src_mac(struct fc_lport *); 961875f27eSRobert Love static void fcoe_destroy_work(struct work_struct *); 971875f27eSRobert Love 981875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *, 991875f27eSRobert Love unsigned int); 1001875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *, u16); 1011875f27eSRobert Love 1021875f27eSRobert Love static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *); 1031875f27eSRobert Love 1041875f27eSRobert Love static int fcoe_create(const char *, struct kernel_param *); 1051875f27eSRobert Love static int fcoe_destroy(const char *, struct kernel_param *); 10655a66d3cSVasu Dev static int fcoe_enable(const char *, struct kernel_param *); 10755a66d3cSVasu Dev static int fcoe_disable(const char *, struct kernel_param *); 1081875f27eSRobert Love 1091875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *, 1101875f27eSRobert Love u32 did, struct fc_frame *, 1111875f27eSRobert Love unsigned int op, 1121875f27eSRobert Love void (*resp)(struct fc_seq *, 1131875f27eSRobert Love struct fc_frame *, 1141875f27eSRobert Love void *), 1151875f27eSRobert Love void *, u32 timeout); 116859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb); 1171875f27eSRobert Love 118b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *); 119b84056bfSYi Zou 1201875f27eSRobert Love module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR); 1211875f27eSRobert Love __MODULE_PARM_TYPE(create, "string"); 12255a66d3cSVasu Dev MODULE_PARM_DESC(create, " Creates fcoe instance on a ethernet interface"); 1231875f27eSRobert Love module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR); 1241875f27eSRobert Love __MODULE_PARM_TYPE(destroy, "string"); 12555a66d3cSVasu Dev MODULE_PARM_DESC(destroy, " Destroys fcoe instance on a ethernet interface"); 12655a66d3cSVasu Dev module_param_call(enable, fcoe_enable, NULL, NULL, S_IWUSR); 12755a66d3cSVasu Dev __MODULE_PARM_TYPE(enable, "string"); 12855a66d3cSVasu Dev MODULE_PARM_DESC(enable, " Enables fcoe on a ethernet interface."); 12955a66d3cSVasu Dev module_param_call(disable, fcoe_disable, NULL, NULL, S_IWUSR); 13055a66d3cSVasu Dev __MODULE_PARM_TYPE(disable, "string"); 13155a66d3cSVasu Dev MODULE_PARM_DESC(disable, " Disables fcoe on a ethernet interface."); 1321875f27eSRobert Love 1331875f27eSRobert Love /* notification function for packets from net device */ 134a703e490SVasu Dev static struct notifier_block fcoe_notifier = { 135a703e490SVasu Dev .notifier_call = fcoe_device_notification, 136a703e490SVasu Dev }; 137a703e490SVasu Dev 1381875f27eSRobert Love /* notification function for CPU hotplug events */ 1391875f27eSRobert Love static struct notifier_block fcoe_cpu_notifier = { 1401875f27eSRobert Love .notifier_call = fcoe_cpu_callback, 1411875f27eSRobert Love }; 1421875f27eSRobert Love 143e9084bb8SChris Leech static struct scsi_transport_template *fcoe_transport_template; 144e9084bb8SChris Leech static struct scsi_transport_template *fcoe_vport_transport_template; 145a703e490SVasu Dev 1461875f27eSRobert Love static int fcoe_vport_destroy(struct fc_vport *); 1471875f27eSRobert Love static int fcoe_vport_create(struct fc_vport *, bool disabled); 1481875f27eSRobert Love static int fcoe_vport_disable(struct fc_vport *, bool disable); 1491875f27eSRobert Love static void fcoe_set_vport_symbolic_name(struct fc_vport *); 1507d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *); 1511875f27eSRobert Love 1521875f27eSRobert Love static struct libfc_function_template fcoe_libfc_fcn_templ = { 1531875f27eSRobert Love .frame_send = fcoe_xmit, 1541875f27eSRobert Love .ddp_setup = fcoe_ddp_setup, 1551875f27eSRobert Love .ddp_done = fcoe_ddp_done, 1561875f27eSRobert Love .elsct_send = fcoe_elsct_send, 157b84056bfSYi Zou .get_lesb = fcoe_get_lesb, 1587d65b0dfSJoe Eykholt .lport_set_port_id = fcoe_set_port_id, 1591875f27eSRobert Love }; 1609a05753bSChris Leech 161a703e490SVasu Dev struct fc_function_template fcoe_transport_function = { 162a703e490SVasu Dev .show_host_node_name = 1, 163a703e490SVasu Dev .show_host_port_name = 1, 164a703e490SVasu Dev .show_host_supported_classes = 1, 165a703e490SVasu Dev .show_host_supported_fc4s = 1, 166a703e490SVasu Dev .show_host_active_fc4s = 1, 167a703e490SVasu Dev .show_host_maxframe_size = 1, 168a703e490SVasu Dev 169a703e490SVasu Dev .show_host_port_id = 1, 170a703e490SVasu Dev .show_host_supported_speeds = 1, 171a703e490SVasu Dev .get_host_speed = fc_get_host_speed, 172a703e490SVasu Dev .show_host_speed = 1, 173a703e490SVasu Dev .show_host_port_type = 1, 174a703e490SVasu Dev .get_host_port_state = fc_get_host_port_state, 175a703e490SVasu Dev .show_host_port_state = 1, 176a703e490SVasu Dev .show_host_symbolic_name = 1, 177a703e490SVasu Dev 178a703e490SVasu Dev .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), 179a703e490SVasu Dev .show_rport_maxframe_size = 1, 180a703e490SVasu Dev .show_rport_supported_classes = 1, 181a703e490SVasu Dev 182a703e490SVasu Dev .show_host_fabric_name = 1, 183a703e490SVasu Dev .show_starget_node_name = 1, 184a703e490SVasu Dev .show_starget_port_name = 1, 185a703e490SVasu Dev .show_starget_port_id = 1, 186a703e490SVasu Dev .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, 187a703e490SVasu Dev .show_rport_dev_loss_tmo = 1, 188a703e490SVasu Dev .get_fc_host_stats = fc_get_host_stats, 189a703e490SVasu Dev .issue_fc_host_lip = fcoe_reset, 190a703e490SVasu Dev 191a703e490SVasu Dev .terminate_rport_io = fc_rport_terminate_io, 1929a05753bSChris Leech 1939a05753bSChris Leech .vport_create = fcoe_vport_create, 1949a05753bSChris Leech .vport_delete = fcoe_vport_destroy, 1959a05753bSChris Leech .vport_disable = fcoe_vport_disable, 196dc8596d3SChris Leech .set_vport_symbolic_name = fcoe_set_vport_symbolic_name, 197a51ab396SSteve Ma 198a51ab396SSteve Ma .bsg_request = fc_lport_bsg_request, 199a703e490SVasu Dev }; 200a703e490SVasu Dev 201e9084bb8SChris Leech struct fc_function_template fcoe_vport_transport_function = { 202e9084bb8SChris Leech .show_host_node_name = 1, 203e9084bb8SChris Leech .show_host_port_name = 1, 204e9084bb8SChris Leech .show_host_supported_classes = 1, 205e9084bb8SChris Leech .show_host_supported_fc4s = 1, 206e9084bb8SChris Leech .show_host_active_fc4s = 1, 207e9084bb8SChris Leech .show_host_maxframe_size = 1, 208e9084bb8SChris Leech 209e9084bb8SChris Leech .show_host_port_id = 1, 210e9084bb8SChris Leech .show_host_supported_speeds = 1, 211e9084bb8SChris Leech .get_host_speed = fc_get_host_speed, 212e9084bb8SChris Leech .show_host_speed = 1, 213e9084bb8SChris Leech .show_host_port_type = 1, 214e9084bb8SChris Leech .get_host_port_state = fc_get_host_port_state, 215e9084bb8SChris Leech .show_host_port_state = 1, 216e9084bb8SChris Leech .show_host_symbolic_name = 1, 217e9084bb8SChris Leech 218e9084bb8SChris Leech .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), 219e9084bb8SChris Leech .show_rport_maxframe_size = 1, 220e9084bb8SChris Leech .show_rport_supported_classes = 1, 221e9084bb8SChris Leech 222e9084bb8SChris Leech .show_host_fabric_name = 1, 223e9084bb8SChris Leech .show_starget_node_name = 1, 224e9084bb8SChris Leech .show_starget_port_name = 1, 225e9084bb8SChris Leech .show_starget_port_id = 1, 226e9084bb8SChris Leech .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, 227e9084bb8SChris Leech .show_rport_dev_loss_tmo = 1, 228e9084bb8SChris Leech .get_fc_host_stats = fc_get_host_stats, 229e9084bb8SChris Leech .issue_fc_host_lip = fcoe_reset, 230e9084bb8SChris Leech 231e9084bb8SChris Leech .terminate_rport_io = fc_rport_terminate_io, 232a51ab396SSteve Ma 233a51ab396SSteve Ma .bsg_request = fc_lport_bsg_request, 234e9084bb8SChris Leech }; 235e9084bb8SChris Leech 236a703e490SVasu Dev static struct scsi_host_template fcoe_shost_template = { 237a703e490SVasu Dev .module = THIS_MODULE, 238a703e490SVasu Dev .name = "FCoE Driver", 239a703e490SVasu Dev .proc_name = FCOE_NAME, 240a703e490SVasu Dev .queuecommand = fc_queuecommand, 241a703e490SVasu Dev .eh_abort_handler = fc_eh_abort, 242a703e490SVasu Dev .eh_device_reset_handler = fc_eh_device_reset, 243a703e490SVasu Dev .eh_host_reset_handler = fc_eh_host_reset, 244a703e490SVasu Dev .slave_alloc = fc_slave_alloc, 245a703e490SVasu Dev .change_queue_depth = fc_change_queue_depth, 246a703e490SVasu Dev .change_queue_type = fc_change_queue_type, 247a703e490SVasu Dev .this_id = -1, 24814caf44cSVasu Dev .cmd_per_lun = 3, 249a703e490SVasu Dev .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS, 250a703e490SVasu Dev .use_clustering = ENABLE_CLUSTERING, 251a703e490SVasu Dev .sg_tablesize = SG_ALL, 252a703e490SVasu Dev .max_sectors = 0xffff, 253a703e490SVasu Dev }; 254a703e490SVasu Dev 25554b649f8SChris Leech /** 2561875f27eSRobert Love * fcoe_interface_setup() - Setup a FCoE interface 2571875f27eSRobert Love * @fcoe: The new FCoE interface 2581875f27eSRobert Love * @netdev: The net device that the fcoe interface is on 25954b649f8SChris Leech * 26054b649f8SChris Leech * Returns : 0 for success 2612e70e241SChris Leech * Locking: must be called with the RTNL mutex held 26254b649f8SChris Leech */ 26354b649f8SChris Leech static int fcoe_interface_setup(struct fcoe_interface *fcoe, 26454b649f8SChris Leech struct net_device *netdev) 26554b649f8SChris Leech { 26654b649f8SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 26754b649f8SChris Leech struct netdev_hw_addr *ha; 2685bab87e6SYi Zou struct net_device *real_dev; 26954b649f8SChris Leech u8 flogi_maddr[ETH_ALEN]; 270b7a727f1SYi Zou const struct net_device_ops *ops; 27154b649f8SChris Leech 27254b649f8SChris Leech fcoe->netdev = netdev; 27354b649f8SChris Leech 274b7a727f1SYi Zou /* Let LLD initialize for FCoE */ 275b7a727f1SYi Zou ops = netdev->netdev_ops; 276b7a727f1SYi Zou if (ops->ndo_fcoe_enable) { 277b7a727f1SYi Zou if (ops->ndo_fcoe_enable(netdev)) 278b7a727f1SYi Zou FCOE_NETDEV_DBG(netdev, "Failed to enable FCoE" 279b7a727f1SYi Zou " specific feature for LLD.\n"); 280b7a727f1SYi Zou } 281b7a727f1SYi Zou 28254b649f8SChris Leech /* Do not support for bonding device */ 28354b649f8SChris Leech if ((netdev->priv_flags & IFF_MASTER_ALB) || 28454b649f8SChris Leech (netdev->priv_flags & IFF_SLAVE_INACTIVE) || 28554b649f8SChris Leech (netdev->priv_flags & IFF_MASTER_8023AD)) { 28659d92516Sjohn fastabend FCOE_NETDEV_DBG(netdev, "Bonded interfaces not supported\n"); 28754b649f8SChris Leech return -EOPNOTSUPP; 28854b649f8SChris Leech } 28954b649f8SChris Leech 29054b649f8SChris Leech /* look for SAN MAC address, if multiple SAN MACs exist, only 29154b649f8SChris Leech * use the first one for SPMA */ 2925bab87e6SYi Zou real_dev = (netdev->priv_flags & IFF_802_1Q_VLAN) ? 2935bab87e6SYi Zou vlan_dev_real_dev(netdev) : netdev; 29454b649f8SChris Leech rcu_read_lock(); 2955bab87e6SYi Zou for_each_dev_addr(real_dev, ha) { 29654b649f8SChris Leech if ((ha->type == NETDEV_HW_ADDR_T_SAN) && 297bf361707SYi Zou (is_valid_ether_addr(ha->addr))) { 29854b649f8SChris Leech memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN); 29954b649f8SChris Leech fip->spma = 1; 30054b649f8SChris Leech break; 30154b649f8SChris Leech } 30254b649f8SChris Leech } 30354b649f8SChris Leech rcu_read_unlock(); 30454b649f8SChris Leech 30554b649f8SChris Leech /* setup Source Mac Address */ 30654b649f8SChris Leech if (!fip->spma) 30754b649f8SChris Leech memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len); 30854b649f8SChris Leech 30954b649f8SChris Leech /* 31054b649f8SChris Leech * Add FCoE MAC address as second unicast MAC address 31154b649f8SChris Leech * or enter promiscuous mode if not capable of listening 31254b649f8SChris Leech * for multiple unicast MACs. 31354b649f8SChris Leech */ 31454b649f8SChris Leech memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 31554b649f8SChris Leech dev_unicast_add(netdev, flogi_maddr); 31654b649f8SChris Leech if (fip->spma) 31754b649f8SChris Leech dev_unicast_add(netdev, fip->ctl_src_addr); 31854b649f8SChris Leech dev_mc_add(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0); 31954b649f8SChris Leech 32054b649f8SChris Leech /* 32154b649f8SChris Leech * setup the receive function from ethernet driver 32254b649f8SChris Leech * on the ethertype for the given device 32354b649f8SChris Leech */ 32454b649f8SChris Leech fcoe->fcoe_packet_type.func = fcoe_rcv; 32554b649f8SChris Leech fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); 32654b649f8SChris Leech fcoe->fcoe_packet_type.dev = netdev; 32754b649f8SChris Leech dev_add_pack(&fcoe->fcoe_packet_type); 32854b649f8SChris Leech 32954b649f8SChris Leech fcoe->fip_packet_type.func = fcoe_fip_recv; 33054b649f8SChris Leech fcoe->fip_packet_type.type = htons(ETH_P_FIP); 33154b649f8SChris Leech fcoe->fip_packet_type.dev = netdev; 33254b649f8SChris Leech dev_add_pack(&fcoe->fip_packet_type); 33354b649f8SChris Leech 33454b649f8SChris Leech return 0; 33554b649f8SChris Leech } 33654b649f8SChris Leech 337a703e490SVasu Dev /** 3381875f27eSRobert Love * fcoe_interface_create() - Create a FCoE interface on a net device 3391875f27eSRobert Love * @netdev: The net device to create the FCoE interface on 340030f4e00SChris Leech * 341030f4e00SChris Leech * Returns: pointer to a struct fcoe_interface or NULL on error 342030f4e00SChris Leech */ 343030f4e00SChris Leech static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev) 344030f4e00SChris Leech { 345030f4e00SChris Leech struct fcoe_interface *fcoe; 34659d92516Sjohn fastabend int err; 347030f4e00SChris Leech 348030f4e00SChris Leech fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL); 349030f4e00SChris Leech if (!fcoe) { 350030f4e00SChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n"); 351030f4e00SChris Leech return NULL; 352030f4e00SChris Leech } 353030f4e00SChris Leech 3542e70e241SChris Leech dev_hold(netdev); 355030f4e00SChris Leech kref_init(&fcoe->kref); 35654b649f8SChris Leech 35754b649f8SChris Leech /* 35854b649f8SChris Leech * Initialize FIP. 35954b649f8SChris Leech */ 36054b649f8SChris Leech fcoe_ctlr_init(&fcoe->ctlr); 36154b649f8SChris Leech fcoe->ctlr.send = fcoe_fip_send; 36254b649f8SChris Leech fcoe->ctlr.update_mac = fcoe_update_src_mac; 36311b56188SChris Leech fcoe->ctlr.get_src_addr = fcoe_get_src_mac; 36454b649f8SChris Leech 36559d92516Sjohn fastabend err = fcoe_interface_setup(fcoe, netdev); 36659d92516Sjohn fastabend if (err) { 36759d92516Sjohn fastabend fcoe_ctlr_destroy(&fcoe->ctlr); 36859d92516Sjohn fastabend kfree(fcoe); 36959d92516Sjohn fastabend dev_put(netdev); 37059d92516Sjohn fastabend return NULL; 37159d92516Sjohn fastabend } 372030f4e00SChris Leech 373030f4e00SChris Leech return fcoe; 374030f4e00SChris Leech } 375030f4e00SChris Leech 376030f4e00SChris Leech /** 3771875f27eSRobert Love * fcoe_interface_cleanup() - Clean up a FCoE interface 3781875f27eSRobert Love * @fcoe: The FCoE interface to be cleaned up 3792e70e241SChris Leech * 3802e70e241SChris Leech * Caller must be holding the RTNL mutex 38154b649f8SChris Leech */ 38254b649f8SChris Leech void fcoe_interface_cleanup(struct fcoe_interface *fcoe) 38354b649f8SChris Leech { 38454b649f8SChris Leech struct net_device *netdev = fcoe->netdev; 38554b649f8SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 38654b649f8SChris Leech u8 flogi_maddr[ETH_ALEN]; 387b7a727f1SYi Zou const struct net_device_ops *ops; 38854b649f8SChris Leech 38954b649f8SChris Leech /* 39054b649f8SChris Leech * Don't listen for Ethernet packets anymore. 39154b649f8SChris Leech * synchronize_net() ensures that the packet handlers are not running 39254b649f8SChris Leech * on another CPU. dev_remove_pack() would do that, this calls the 39354b649f8SChris Leech * unsyncronized version __dev_remove_pack() to avoid multiple delays. 39454b649f8SChris Leech */ 39554b649f8SChris Leech __dev_remove_pack(&fcoe->fcoe_packet_type); 39654b649f8SChris Leech __dev_remove_pack(&fcoe->fip_packet_type); 39754b649f8SChris Leech synchronize_net(); 39854b649f8SChris Leech 39954b649f8SChris Leech /* Delete secondary MAC addresses */ 40054b649f8SChris Leech memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 40154b649f8SChris Leech dev_unicast_delete(netdev, flogi_maddr); 40254b649f8SChris Leech if (fip->spma) 40354b649f8SChris Leech dev_unicast_delete(netdev, fip->ctl_src_addr); 40454b649f8SChris Leech dev_mc_delete(netdev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0); 405b7a727f1SYi Zou 406b7a727f1SYi Zou /* Tell the LLD we are done w/ FCoE */ 407b7a727f1SYi Zou ops = netdev->netdev_ops; 408b7a727f1SYi Zou if (ops->ndo_fcoe_disable) { 409b7a727f1SYi Zou if (ops->ndo_fcoe_disable(netdev)) 410b7a727f1SYi Zou FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE" 411b7a727f1SYi Zou " specific feature for LLD.\n"); 412b7a727f1SYi Zou } 41354b649f8SChris Leech } 41454b649f8SChris Leech 41554b649f8SChris Leech /** 416030f4e00SChris Leech * fcoe_interface_release() - fcoe_port kref release function 4171875f27eSRobert Love * @kref: Embedded reference count in an fcoe_interface struct 418030f4e00SChris Leech */ 419030f4e00SChris Leech static void fcoe_interface_release(struct kref *kref) 420030f4e00SChris Leech { 421030f4e00SChris Leech struct fcoe_interface *fcoe; 4222e70e241SChris Leech struct net_device *netdev; 423030f4e00SChris Leech 424030f4e00SChris Leech fcoe = container_of(kref, struct fcoe_interface, kref); 4252e70e241SChris Leech netdev = fcoe->netdev; 4262e70e241SChris Leech /* tear-down the FCoE controller */ 4272e70e241SChris Leech fcoe_ctlr_destroy(&fcoe->ctlr); 428030f4e00SChris Leech kfree(fcoe); 4292e70e241SChris Leech dev_put(netdev); 430030f4e00SChris Leech } 431030f4e00SChris Leech 432030f4e00SChris Leech /** 4331875f27eSRobert Love * fcoe_interface_get() - Get a reference to a FCoE interface 4341875f27eSRobert Love * @fcoe: The FCoE interface to be held 435030f4e00SChris Leech */ 436030f4e00SChris Leech static inline void fcoe_interface_get(struct fcoe_interface *fcoe) 437030f4e00SChris Leech { 438030f4e00SChris Leech kref_get(&fcoe->kref); 439030f4e00SChris Leech } 440030f4e00SChris Leech 441030f4e00SChris Leech /** 4421875f27eSRobert Love * fcoe_interface_put() - Put a reference to a FCoE interface 4431875f27eSRobert Love * @fcoe: The FCoE interface to be released 444030f4e00SChris Leech */ 445030f4e00SChris Leech static inline void fcoe_interface_put(struct fcoe_interface *fcoe) 446030f4e00SChris Leech { 447030f4e00SChris Leech kref_put(&fcoe->kref, fcoe_interface_release); 448030f4e00SChris Leech } 449030f4e00SChris Leech 450030f4e00SChris Leech /** 4511875f27eSRobert Love * fcoe_fip_recv() - Handler for received FIP frames 4521875f27eSRobert Love * @skb: The receive skb 4531875f27eSRobert Love * @netdev: The associated net device 4541875f27eSRobert Love * @ptype: The packet_type structure which was used to register this handler 4551875f27eSRobert Love * @orig_dev: The original net_device the the skb was received on. 4561875f27eSRobert Love * (in case dev is a bond) 457ab6b85c1SVasu Dev * 458ab6b85c1SVasu Dev * Returns: 0 for success 459ab6b85c1SVasu Dev */ 4601875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev, 461ab6b85c1SVasu Dev struct packet_type *ptype, 462ab6b85c1SVasu Dev struct net_device *orig_dev) 463ab6b85c1SVasu Dev { 464259ad85dSChris Leech struct fcoe_interface *fcoe; 465ab6b85c1SVasu Dev 466259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type); 4673fe9a0baSChris Leech fcoe_ctlr_recv(&fcoe->ctlr, skb); 468ab6b85c1SVasu Dev return 0; 469ab6b85c1SVasu Dev } 470ab6b85c1SVasu Dev 471ab6b85c1SVasu Dev /** 4721875f27eSRobert Love * fcoe_fip_send() - Send an Ethernet-encapsulated FIP frame 4731875f27eSRobert Love * @fip: The FCoE controller 4741875f27eSRobert Love * @skb: The FIP packet to be sent 475ab6b85c1SVasu Dev */ 476ab6b85c1SVasu Dev static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 477ab6b85c1SVasu Dev { 4783fe9a0baSChris Leech skb->dev = fcoe_from_ctlr(fip)->netdev; 479ab6b85c1SVasu Dev dev_queue_xmit(skb); 480ab6b85c1SVasu Dev } 481ab6b85c1SVasu Dev 482ab6b85c1SVasu Dev /** 4831875f27eSRobert Love * fcoe_update_src_mac() - Update the Ethernet MAC filters 4841875f27eSRobert Love * @lport: The local port to update the source MAC on 4851875f27eSRobert Love * @addr: Unicast MAC address to add 486ab6b85c1SVasu Dev * 487ab6b85c1SVasu Dev * Remove any previously-set unicast MAC filter. 488ab6b85c1SVasu Dev * Add secondary FCoE MAC address filter for our OUI. 489ab6b85c1SVasu Dev */ 49011b56188SChris Leech static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr) 491ab6b85c1SVasu Dev { 49211b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 49311b56188SChris Leech struct fcoe_interface *fcoe = port->fcoe; 494ab6b85c1SVasu Dev 495ab6b85c1SVasu Dev rtnl_lock(); 49611b56188SChris Leech if (!is_zero_ether_addr(port->data_src_addr)) 49711b56188SChris Leech dev_unicast_delete(fcoe->netdev, port->data_src_addr); 49811b56188SChris Leech if (!is_zero_ether_addr(addr)) 49911b56188SChris Leech dev_unicast_add(fcoe->netdev, addr); 50011b56188SChris Leech memcpy(port->data_src_addr, addr, ETH_ALEN); 501ab6b85c1SVasu Dev rtnl_unlock(); 502ab6b85c1SVasu Dev } 503ab6b85c1SVasu Dev 504ab6b85c1SVasu Dev /** 50511b56188SChris Leech * fcoe_get_src_mac() - return the Ethernet source address for an lport 50611b56188SChris Leech * @lport: libfc lport 50711b56188SChris Leech */ 50811b56188SChris Leech static u8 *fcoe_get_src_mac(struct fc_lport *lport) 50911b56188SChris Leech { 51011b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 51111b56188SChris Leech 51211b56188SChris Leech return port->data_src_addr; 51311b56188SChris Leech } 51411b56188SChris Leech 51511b56188SChris Leech /** 5161875f27eSRobert Love * fcoe_lport_config() - Set up a local port 5171875f27eSRobert Love * @lport: The local port to be setup 518a703e490SVasu Dev * 519a703e490SVasu Dev * Returns: 0 for success 520a703e490SVasu Dev */ 5211875f27eSRobert Love static int fcoe_lport_config(struct fc_lport *lport) 522a703e490SVasu Dev { 5231875f27eSRobert Love lport->link_up = 0; 5241875f27eSRobert Love lport->qfull = 0; 5251875f27eSRobert Love lport->max_retry_count = 3; 5261875f27eSRobert Love lport->max_rport_retry_count = 3; 5271875f27eSRobert Love lport->e_d_tov = 2 * 1000; /* FC-FS default */ 5281875f27eSRobert Love lport->r_a_tov = 2 * 2 * 1000; 5291875f27eSRobert Love lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | 530a703e490SVasu Dev FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); 5311875f27eSRobert Love lport->does_npiv = 1; 532a703e490SVasu Dev 5331875f27eSRobert Love fc_lport_init_stats(lport); 534a703e490SVasu Dev 535a703e490SVasu Dev /* lport fc_lport related configuration */ 5361875f27eSRobert Love fc_lport_config(lport); 537a703e490SVasu Dev 538a703e490SVasu Dev /* offload related configuration */ 5391875f27eSRobert Love lport->crc_offload = 0; 5401875f27eSRobert Love lport->seq_offload = 0; 5411875f27eSRobert Love lport->lro_enabled = 0; 5421875f27eSRobert Love lport->lro_xid = 0; 5431875f27eSRobert Love lport->lso_max = 0; 544a703e490SVasu Dev 545a703e490SVasu Dev return 0; 546a703e490SVasu Dev } 547a703e490SVasu Dev 548a703e490SVasu Dev /** 5491875f27eSRobert Love * fcoe_queue_timer() - The fcoe queue timer 5501875f27eSRobert Love * @lport: The local port 5511047f221SVasu Dev * 5521047f221SVasu Dev * Calls fcoe_check_wait_queue on timeout 5531047f221SVasu Dev */ 5541875f27eSRobert Love static void fcoe_queue_timer(ulong lport) 5551047f221SVasu Dev { 5561875f27eSRobert Love fcoe_check_wait_queue((struct fc_lport *)lport, NULL); 5571047f221SVasu Dev } 5581047f221SVasu Dev 5591047f221SVasu Dev /** 560dcece412SYi Zou * fcoe_get_wwn() - Get the world wide name from LLD if it supports it 561dcece412SYi Zou * @netdev: the associated net device 562dcece412SYi Zou * @wwn: the output WWN 563dcece412SYi Zou * @type: the type of WWN (WWPN or WWNN) 564dcece412SYi Zou * 565dcece412SYi Zou * Returns: 0 for success 566dcece412SYi Zou */ 567dcece412SYi Zou static int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) 568dcece412SYi Zou { 569dcece412SYi Zou const struct net_device_ops *ops = netdev->netdev_ops; 570dcece412SYi Zou 571dcece412SYi Zou if (ops->ndo_fcoe_get_wwn) 572dcece412SYi Zou return ops->ndo_fcoe_get_wwn(netdev, wwn, type); 573dcece412SYi Zou return -EINVAL; 574dcece412SYi Zou } 575dcece412SYi Zou 576dcece412SYi Zou /** 5771875f27eSRobert Love * fcoe_netdev_config() - Set up net devive for SW FCoE 5781875f27eSRobert Love * @lport: The local port that is associated with the net device 5791875f27eSRobert Love * @netdev: The associated net device 580a703e490SVasu Dev * 5811875f27eSRobert Love * Must be called after fcoe_lport_config() as it will use local port mutex 582a703e490SVasu Dev * 583a703e490SVasu Dev * Returns: 0 for success 584a703e490SVasu Dev */ 5851875f27eSRobert Love static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev) 586a703e490SVasu Dev { 587a703e490SVasu Dev u32 mfs; 588a703e490SVasu Dev u64 wwnn, wwpn; 58925024989SChris Leech struct fcoe_interface *fcoe; 590014f5c3fSChris Leech struct fcoe_port *port; 591cc0136c2SYi Zou int vid = 0; 592a703e490SVasu Dev 593a703e490SVasu Dev /* Setup lport private data to point to fcoe softc */ 5941875f27eSRobert Love port = lport_priv(lport); 59525024989SChris Leech fcoe = port->fcoe; 596a703e490SVasu Dev 597a703e490SVasu Dev /* 598a703e490SVasu Dev * Determine max frame size based on underlying device and optional 599a703e490SVasu Dev * user-configured limit. If the MFS is too low, fcoe_link_ok() 600a703e490SVasu Dev * will return 0, so do this first. 601a703e490SVasu Dev */ 6027221d7e5SYi Zou mfs = netdev->mtu; 6037221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) { 6047221d7e5SYi Zou mfs = FCOE_MTU; 6057221d7e5SYi Zou FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs); 6067221d7e5SYi Zou } 6077221d7e5SYi Zou mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof)); 6081875f27eSRobert Love if (fc_set_mfs(lport, mfs)) 609a703e490SVasu Dev return -EINVAL; 610a703e490SVasu Dev 611a703e490SVasu Dev /* offload features support */ 6121d1b88dcSVasu Dev if (netdev->features & NETIF_F_SG) 6131875f27eSRobert Love lport->sg_supp = 1; 614a703e490SVasu Dev 615a703e490SVasu Dev if (netdev->features & NETIF_F_FCOE_CRC) { 6161875f27eSRobert Love lport->crc_offload = 1; 617d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n"); 618a703e490SVasu Dev } 619a703e490SVasu Dev if (netdev->features & NETIF_F_FSO) { 6201875f27eSRobert Love lport->seq_offload = 1; 6211875f27eSRobert Love lport->lso_max = netdev->gso_max_size; 622d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n", 6231875f27eSRobert Love lport->lso_max); 624a703e490SVasu Dev } 625a703e490SVasu Dev if (netdev->fcoe_ddp_xid) { 6261875f27eSRobert Love lport->lro_enabled = 1; 6271875f27eSRobert Love lport->lro_xid = netdev->fcoe_ddp_xid; 628d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n", 6291875f27eSRobert Love lport->lro_xid); 630a703e490SVasu Dev } 631014f5c3fSChris Leech skb_queue_head_init(&port->fcoe_pending_queue); 632014f5c3fSChris Leech port->fcoe_pending_queue_active = 0; 6331875f27eSRobert Love setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lport); 634a703e490SVasu Dev 6355e4f8fe7SRobert Love fcoe_link_speed_update(lport); 6365e4f8fe7SRobert Love 6371875f27eSRobert Love if (!lport->vport) { 638cc0136c2SYi Zou /* 639cc0136c2SYi Zou * Use NAA 1&2 (FC-FS Rev. 2.0, Sec. 15) to generate WWNN/WWPN: 640cc0136c2SYi Zou * For WWNN, we use NAA 1 w/ bit 27-16 of word 0 as 0. 641cc0136c2SYi Zou * For WWPN, we use NAA 2 w/ bit 27-16 of word 0 from VLAN ID 642cc0136c2SYi Zou */ 643cc0136c2SYi Zou if (netdev->priv_flags & IFF_802_1Q_VLAN) 644cc0136c2SYi Zou vid = vlan_dev_vlan_id(netdev); 645dcece412SYi Zou 646dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN)) 64775ea89efSYi Zou wwnn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 1, 0); 6481875f27eSRobert Love fc_set_wwnn(lport, wwnn); 649dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN)) 650dcece412SYi Zou wwpn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 651dcece412SYi Zou 2, vid); 6521875f27eSRobert Love fc_set_wwpn(lport, wwpn); 6539a05753bSChris Leech } 654a703e490SVasu Dev 655a703e490SVasu Dev return 0; 656a703e490SVasu Dev } 657a703e490SVasu Dev 658a703e490SVasu Dev /** 6591875f27eSRobert Love * fcoe_shost_config() - Set up the SCSI host associated with a local port 6601875f27eSRobert Love * @lport: The local port 6611875f27eSRobert Love * @dev: The device associated with the SCSI host 662a703e490SVasu Dev * 663a703e490SVasu Dev * Must be called after fcoe_lport_config() and fcoe_netdev_config() 664a703e490SVasu Dev * 665a703e490SVasu Dev * Returns: 0 for success 666a703e490SVasu Dev */ 6678ba00a4bSVasu Dev static int fcoe_shost_config(struct fc_lport *lport, struct device *dev) 668a703e490SVasu Dev { 669a703e490SVasu Dev int rc = 0; 670a703e490SVasu Dev 671a703e490SVasu Dev /* lport scsi host config */ 6721875f27eSRobert Love lport->host->max_lun = FCOE_MAX_LUN; 6731875f27eSRobert Love lport->host->max_id = FCOE_MAX_FCP_TARGET; 6741875f27eSRobert Love lport->host->max_channel = 0; 675da87bfabSVasu Dev lport->host->max_cmd_len = FCOE_MAX_CMD_LEN; 676da87bfabSVasu Dev 6771875f27eSRobert Love if (lport->vport) 6781875f27eSRobert Love lport->host->transportt = fcoe_vport_transport_template; 679e9084bb8SChris Leech else 6801875f27eSRobert Love lport->host->transportt = fcoe_transport_template; 681a703e490SVasu Dev 682a703e490SVasu Dev /* add the new host to the SCSI-ml */ 6831875f27eSRobert Love rc = scsi_add_host(lport->host, dev); 684a703e490SVasu Dev if (rc) { 6851875f27eSRobert Love FCOE_NETDEV_DBG(fcoe_netdev(lport), "fcoe_shost_config: " 686d5488eb9SRobert Love "error on scsi_add_host\n"); 687a703e490SVasu Dev return rc; 688a703e490SVasu Dev } 6899a05753bSChris Leech 6901875f27eSRobert Love if (!lport->vport) 6911875f27eSRobert Love fc_host_max_npiv_vports(lport->host) = USHORT_MAX; 6929a05753bSChris Leech 6931875f27eSRobert Love snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 6945baa17c3SChris Leech "%s v%s over %s", FCOE_NAME, FCOE_VERSION, 6951875f27eSRobert Love fcoe_netdev(lport)->name); 696a703e490SVasu Dev 697a703e490SVasu Dev return 0; 698a703e490SVasu Dev } 699a703e490SVasu Dev 7001875f27eSRobert Love /** 7011875f27eSRobert Love * fcoe_oem_match() - The match routine for the offloaded exchange manager 7021875f27eSRobert Love * @fp: The I/O frame 703d7179680SVasu Dev * 7041875f27eSRobert Love * This routine will be associated with an exchange manager (EM). When 7051875f27eSRobert Love * the libfc exchange handling code is looking for an EM to use it will 7061875f27eSRobert Love * call this routine and pass it the frame that it wishes to send. This 7071875f27eSRobert Love * routine will return True if the associated EM is to be used and False 7081875f27eSRobert Love * if the echange code should continue looking for an EM. 7091875f27eSRobert Love * 7101875f27eSRobert Love * The offload EM that this routine is associated with will handle any 7111875f27eSRobert Love * packets that are for SCSI read requests. 7121875f27eSRobert Love * 7131875f27eSRobert Love * Returns: True for read types I/O, otherwise returns false. 714d7179680SVasu Dev */ 715d7179680SVasu Dev bool fcoe_oem_match(struct fc_frame *fp) 716d7179680SVasu Dev { 71705cc7390SYi Zou return fc_fcp_is_read(fr_fsp(fp)) && 71805cc7390SYi Zou (fr_fsp(fp)->data_len > fcoe_ddp_min); 719d7179680SVasu Dev } 720d7179680SVasu Dev 721a703e490SVasu Dev /** 7221875f27eSRobert Love * fcoe_em_config() - Allocate and configure an exchange manager 7231875f27eSRobert Love * @lport: The local port that the new EM will be associated with 724a703e490SVasu Dev * 725a703e490SVasu Dev * Returns: 0 on success 726a703e490SVasu Dev */ 7271875f27eSRobert Love static inline int fcoe_em_config(struct fc_lport *lport) 728a703e490SVasu Dev { 7291875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 73025024989SChris Leech struct fcoe_interface *fcoe = port->fcoe; 73125024989SChris Leech struct fcoe_interface *oldfcoe = NULL; 7321d1b88dcSVasu Dev struct net_device *old_real_dev, *cur_real_dev; 733d7179680SVasu Dev u16 min_xid = FCOE_MIN_XID; 734d7179680SVasu Dev u16 max_xid = FCOE_MAX_XID; 735d7179680SVasu Dev 736d7179680SVasu Dev /* 737d7179680SVasu Dev * Check if need to allocate an em instance for 738d7179680SVasu Dev * offload exchange ids to be shared across all VN_PORTs/lport. 739d7179680SVasu Dev */ 7401875f27eSRobert Love if (!lport->lro_enabled || !lport->lro_xid || 7411875f27eSRobert Love (lport->lro_xid >= max_xid)) { 7421875f27eSRobert Love lport->lro_xid = 0; 743d7179680SVasu Dev goto skip_oem; 744d7179680SVasu Dev } 745d7179680SVasu Dev 746d7179680SVasu Dev /* 747d7179680SVasu Dev * Reuse existing offload em instance in case 7481d1b88dcSVasu Dev * it is already allocated on real eth device 749d7179680SVasu Dev */ 75025024989SChris Leech if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 75125024989SChris Leech cur_real_dev = vlan_dev_real_dev(fcoe->netdev); 7521d1b88dcSVasu Dev else 75325024989SChris Leech cur_real_dev = fcoe->netdev; 7541d1b88dcSVasu Dev 75525024989SChris Leech list_for_each_entry(oldfcoe, &fcoe_hostlist, list) { 75625024989SChris Leech if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 75725024989SChris Leech old_real_dev = vlan_dev_real_dev(oldfcoe->netdev); 7581d1b88dcSVasu Dev else 75925024989SChris Leech old_real_dev = oldfcoe->netdev; 7601d1b88dcSVasu Dev 7611d1b88dcSVasu Dev if (cur_real_dev == old_real_dev) { 762991cbb60SChris Leech fcoe->oem = oldfcoe->oem; 763d7179680SVasu Dev break; 764d7179680SVasu Dev } 765d7179680SVasu Dev } 766d7179680SVasu Dev 767991cbb60SChris Leech if (fcoe->oem) { 7681875f27eSRobert Love if (!fc_exch_mgr_add(lport, fcoe->oem, fcoe_oem_match)) { 769d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to add " 770d7179680SVasu Dev "offload em:%p on interface:%s\n", 771991cbb60SChris Leech fcoe->oem, fcoe->netdev->name); 772a703e490SVasu Dev return -ENOMEM; 773d7179680SVasu Dev } 774d7179680SVasu Dev } else { 7751875f27eSRobert Love fcoe->oem = fc_exch_mgr_alloc(lport, FC_CLASS_3, 7761875f27eSRobert Love FCOE_MIN_XID, lport->lro_xid, 777d7179680SVasu Dev fcoe_oem_match); 778991cbb60SChris Leech if (!fcoe->oem) { 779d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to allocate " 780d7179680SVasu Dev "em for offload exches on interface:%s\n", 78125024989SChris Leech fcoe->netdev->name); 782d7179680SVasu Dev return -ENOMEM; 783d7179680SVasu Dev } 784d7179680SVasu Dev } 785d7179680SVasu Dev 786d7179680SVasu Dev /* 787d7179680SVasu Dev * Exclude offload EM xid range from next EM xid range. 788d7179680SVasu Dev */ 7891875f27eSRobert Love min_xid += lport->lro_xid + 1; 790d7179680SVasu Dev 791d7179680SVasu Dev skip_oem: 7921875f27eSRobert Love if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, min_xid, max_xid, NULL)) { 793d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to " 79425024989SChris Leech "allocate em on interface %s\n", fcoe->netdev->name); 795d7179680SVasu Dev return -ENOMEM; 796d7179680SVasu Dev } 797a703e490SVasu Dev 798a703e490SVasu Dev return 0; 799a703e490SVasu Dev } 800a703e490SVasu Dev 801a703e490SVasu Dev /** 8021875f27eSRobert Love * fcoe_if_destroy() - Tear down a SW FCoE instance 8031875f27eSRobert Love * @lport: The local port to be destroyed 80434ce27bcSVasu Dev * 80534ce27bcSVasu Dev * Locking: must be called with the RTNL mutex held and RTNL mutex 80634ce27bcSVasu Dev * needed to be dropped by this function since not dropping RTNL 80734ce27bcSVasu Dev * would cause circular locking warning on synchronous fip worker 80834ce27bcSVasu Dev * cancelling thru fcoe_interface_put invoked by this function. 80934ce27bcSVasu Dev * 810a703e490SVasu Dev */ 811af7f85d9SChris Leech static void fcoe_if_destroy(struct fc_lport *lport) 812a703e490SVasu Dev { 813014f5c3fSChris Leech struct fcoe_port *port = lport_priv(lport); 814014f5c3fSChris Leech struct fcoe_interface *fcoe = port->fcoe; 81525024989SChris Leech struct net_device *netdev = fcoe->netdev; 816a703e490SVasu Dev 817d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Destroying interface\n"); 818a703e490SVasu Dev 819a703e490SVasu Dev /* Logout of the fabric */ 820af7f85d9SChris Leech fc_fabric_logoff(lport); 821a703e490SVasu Dev 822a703e490SVasu Dev /* Cleanup the fc_lport */ 823af7f85d9SChris Leech fc_lport_destroy(lport); 824af7f85d9SChris Leech fc_fcp_destroy(lport); 825a703e490SVasu Dev 82654b649f8SChris Leech /* Stop the transmit retry timer */ 82754b649f8SChris Leech del_timer_sync(&port->timer); 82854b649f8SChris Leech 82954b649f8SChris Leech /* Free existing transmit skbs */ 83054b649f8SChris Leech fcoe_clean_pending_queue(lport); 83154b649f8SChris Leech 83211b56188SChris Leech if (!is_zero_ether_addr(port->data_src_addr)) 83311b56188SChris Leech dev_unicast_delete(netdev, port->data_src_addr); 83411b56188SChris Leech rtnl_unlock(); 83511b56188SChris Leech 83654b649f8SChris Leech /* receives may not be stopped until after this */ 83754b649f8SChris Leech fcoe_interface_put(fcoe); 83854b649f8SChris Leech 83954b649f8SChris Leech /* Free queued packets for the per-CPU receive threads */ 84054b649f8SChris Leech fcoe_percpu_clean(lport); 84154b649f8SChris Leech 842a703e490SVasu Dev /* Detach from the scsi-ml */ 843af7f85d9SChris Leech fc_remove_host(lport->host); 844af7f85d9SChris Leech scsi_remove_host(lport->host); 845a703e490SVasu Dev 846a703e490SVasu Dev /* There are no more rports or I/O, free the EM */ 847af7f85d9SChris Leech fc_exch_mgr_free(lport); 848a703e490SVasu Dev 849a703e490SVasu Dev /* Free memory used by statistical counters */ 850af7f85d9SChris Leech fc_lport_free_stats(lport); 851a703e490SVasu Dev 8522e70e241SChris Leech /* Release the Scsi_Host */ 853af7f85d9SChris Leech scsi_host_put(lport->host); 854a703e490SVasu Dev } 855a703e490SVasu Dev 8561875f27eSRobert Love /** 8571875f27eSRobert Love * fcoe_ddp_setup() - Call a LLD's ddp_setup through the net device 8581875f27eSRobert Love * @lport: The local port to setup DDP for 8591875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 8601875f27eSRobert Love * @sgl: The scatterlist describing this transfer 8611875f27eSRobert Love * @sgc: The number of sg items 862a703e490SVasu Dev * 8631875f27eSRobert Love * Returns: 0 if the DDP context was not configured 864a703e490SVasu Dev */ 8651875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid, 866a703e490SVasu Dev struct scatterlist *sgl, unsigned int sgc) 867a703e490SVasu Dev { 8681875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 869a703e490SVasu Dev 8701875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_setup) 8711875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_setup(netdev, 8721875f27eSRobert Love xid, sgl, 8731875f27eSRobert Love sgc); 874a703e490SVasu Dev 875a703e490SVasu Dev return 0; 876a703e490SVasu Dev } 877a703e490SVasu Dev 878a703e490SVasu Dev /** 8791875f27eSRobert Love * fcoe_ddp_done() - Call a LLD's ddp_done through the net device 8801875f27eSRobert Love * @lport: The local port to complete DDP on 8811875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 882a703e490SVasu Dev * 8831875f27eSRobert Love * Returns: the length of data that have been completed by DDP 8841875f27eSRobert Love */ 8851875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *lport, u16 xid) 8861875f27eSRobert Love { 8871875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 8881875f27eSRobert Love 8891875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_done) 8901875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_done(netdev, xid); 8911875f27eSRobert Love return 0; 8921875f27eSRobert Love } 8931875f27eSRobert Love 8941875f27eSRobert Love /** 8951875f27eSRobert Love * fcoe_if_create() - Create a FCoE instance on an interface 8961875f27eSRobert Love * @fcoe: The FCoE interface to create a local port on 8971875f27eSRobert Love * @parent: The device pointer to be the parent in sysfs for the SCSI host 8981875f27eSRobert Love * @npiv: Indicates if the port is a vport or not 8991875f27eSRobert Love * 9001875f27eSRobert Love * Creates a fc_lport instance and a Scsi_Host instance and configure them. 901a703e490SVasu Dev * 902af7f85d9SChris Leech * Returns: The allocated fc_lport or an error pointer 903a703e490SVasu Dev */ 904030f4e00SChris Leech static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe, 9059a05753bSChris Leech struct device *parent, int npiv) 906a703e490SVasu Dev { 9071875f27eSRobert Love struct net_device *netdev = fcoe->netdev; 908af7f85d9SChris Leech struct fc_lport *lport = NULL; 909014f5c3fSChris Leech struct fcoe_port *port; 9101875f27eSRobert Love int rc; 9119a05753bSChris Leech /* 9129a05753bSChris Leech * parent is only a vport if npiv is 1, 9139a05753bSChris Leech * but we'll only use vport in that case so go ahead and set it 9149a05753bSChris Leech */ 9159a05753bSChris Leech struct fc_vport *vport = dev_to_vport(parent); 916a703e490SVasu Dev 917d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Create Interface\n"); 918a703e490SVasu Dev 9199a05753bSChris Leech if (!npiv) { 92086221969SChris Leech lport = libfc_host_alloc(&fcoe_shost_template, 921014f5c3fSChris Leech sizeof(struct fcoe_port)); 9229a05753bSChris Leech } else { 9239a05753bSChris Leech lport = libfc_vport_create(vport, 9249a05753bSChris Leech sizeof(struct fcoe_port)); 9259a05753bSChris Leech } 92686221969SChris Leech if (!lport) { 927014f5c3fSChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n"); 928014f5c3fSChris Leech rc = -ENOMEM; 929030f4e00SChris Leech goto out; 930014f5c3fSChris Leech } 931014f5c3fSChris Leech port = lport_priv(lport); 9322e70e241SChris Leech port->lport = lport; 933014f5c3fSChris Leech port->fcoe = fcoe; 9342e70e241SChris Leech INIT_WORK(&port->destroy_work, fcoe_destroy_work); 935a703e490SVasu Dev 9361875f27eSRobert Love /* configure a fc_lport including the exchange manager */ 937af7f85d9SChris Leech rc = fcoe_lport_config(lport); 938a703e490SVasu Dev if (rc) { 939d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure lport for the " 940d5488eb9SRobert Love "interface\n"); 941a703e490SVasu Dev goto out_host_put; 942a703e490SVasu Dev } 943a703e490SVasu Dev 9449a05753bSChris Leech if (npiv) { 9459f8f3aa6SChris Leech FCOE_NETDEV_DBG(netdev, "Setting vport names, " 9469f8f3aa6SChris Leech "%16.16llx %16.16llx\n", 9479a05753bSChris Leech vport->node_name, vport->port_name); 9489a05753bSChris Leech fc_set_wwnn(lport, vport->node_name); 9499a05753bSChris Leech fc_set_wwpn(lport, vport->port_name); 9509a05753bSChris Leech } 9519a05753bSChris Leech 952ab6b85c1SVasu Dev /* configure lport network properties */ 953af7f85d9SChris Leech rc = fcoe_netdev_config(lport, netdev); 954ab6b85c1SVasu Dev if (rc) { 955d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the " 956d5488eb9SRobert Love "interface\n"); 95754b649f8SChris Leech goto out_lp_destroy; 958ab6b85c1SVasu Dev } 95997c8389dSJoe Eykholt 960a703e490SVasu Dev /* configure lport scsi host properties */ 9618ba00a4bSVasu Dev rc = fcoe_shost_config(lport, parent); 962a703e490SVasu Dev if (rc) { 963d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure shost for the " 964d5488eb9SRobert Love "interface\n"); 96554b649f8SChris Leech goto out_lp_destroy; 966a703e490SVasu Dev } 967a703e490SVasu Dev 968a703e490SVasu Dev /* Initialize the library */ 969af7f85d9SChris Leech rc = fcoe_libfc_config(lport, &fcoe_libfc_fcn_templ); 970a703e490SVasu Dev if (rc) { 971d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the " 972d5488eb9SRobert Love "interface\n"); 973a703e490SVasu Dev goto out_lp_destroy; 974a703e490SVasu Dev } 975a703e490SVasu Dev 9769a05753bSChris Leech if (!npiv) { 977e8af4d43SVasu Dev /* 978e8af4d43SVasu Dev * fcoe_em_alloc() and fcoe_hostlist_add() both 9799a05753bSChris Leech * need to be atomic with respect to other changes to the 9809a05753bSChris Leech * hostlist since fcoe_em_alloc() looks for an existing EM 981e8af4d43SVasu Dev * instance on host list updated by fcoe_hostlist_add(). 982c863df33SChris Leech * 9839a05753bSChris Leech * This is currently handled through the fcoe_config_mutex 9849a05753bSChris Leech * begin held. 985e8af4d43SVasu Dev */ 986c863df33SChris Leech 98796316099SVasu Dev /* lport exch manager allocation */ 988af7f85d9SChris Leech rc = fcoe_em_config(lport); 98996316099SVasu Dev if (rc) { 9909a05753bSChris Leech FCOE_NETDEV_DBG(netdev, "Could not configure the EM " 9919a05753bSChris Leech "for the interface\n"); 99296316099SVasu Dev goto out_lp_destroy; 99396316099SVasu Dev } 9949a05753bSChris Leech } 99596316099SVasu Dev 996030f4e00SChris Leech fcoe_interface_get(fcoe); 997af7f85d9SChris Leech return lport; 998a703e490SVasu Dev 999a703e490SVasu Dev out_lp_destroy: 1000af7f85d9SChris Leech fc_exch_mgr_free(lport); 1001a703e490SVasu Dev out_host_put: 1002af7f85d9SChris Leech scsi_host_put(lport->host); 1003af7f85d9SChris Leech out: 1004af7f85d9SChris Leech return ERR_PTR(rc); 1005a703e490SVasu Dev } 1006a703e490SVasu Dev 1007a703e490SVasu Dev /** 10081875f27eSRobert Love * fcoe_if_init() - Initialization routine for fcoe.ko 10091875f27eSRobert Love * 10101875f27eSRobert Love * Attaches the SW FCoE transport to the FC transport 1011a703e490SVasu Dev * 1012a703e490SVasu Dev * Returns: 0 on success 1013a703e490SVasu Dev */ 1014a703e490SVasu Dev static int __init fcoe_if_init(void) 1015a703e490SVasu Dev { 1016a703e490SVasu Dev /* attach to scsi transport */ 1017e9084bb8SChris Leech fcoe_transport_template = fc_attach_transport(&fcoe_transport_function); 1018e9084bb8SChris Leech fcoe_vport_transport_template = 1019e9084bb8SChris Leech fc_attach_transport(&fcoe_vport_transport_function); 1020a703e490SVasu Dev 1021e9084bb8SChris Leech if (!fcoe_transport_template) { 1022d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); 1023a703e490SVasu Dev return -ENODEV; 1024a703e490SVasu Dev } 1025a703e490SVasu Dev 1026a703e490SVasu Dev return 0; 1027a703e490SVasu Dev } 1028a703e490SVasu Dev 1029a703e490SVasu Dev /** 10301875f27eSRobert Love * fcoe_if_exit() - Tear down fcoe.ko 10311875f27eSRobert Love * 10321875f27eSRobert Love * Detaches the SW FCoE transport from the FC transport 1033a703e490SVasu Dev * 1034a703e490SVasu Dev * Returns: 0 on success 1035a703e490SVasu Dev */ 1036a703e490SVasu Dev int __exit fcoe_if_exit(void) 1037a703e490SVasu Dev { 1038e9084bb8SChris Leech fc_release_transport(fcoe_transport_template); 1039e9084bb8SChris Leech fc_release_transport(fcoe_vport_transport_template); 1040e9084bb8SChris Leech fcoe_transport_template = NULL; 1041e9084bb8SChris Leech fcoe_vport_transport_template = NULL; 1042a703e490SVasu Dev return 0; 1043a703e490SVasu Dev } 1044a703e490SVasu Dev 1045a703e490SVasu Dev /** 10461875f27eSRobert Love * fcoe_percpu_thread_create() - Create a receive thread for an online CPU 10471875f27eSRobert Love * @cpu: The CPU index of the CPU to create a receive thread for 1048a703e490SVasu Dev */ 1049a703e490SVasu Dev static void fcoe_percpu_thread_create(unsigned int cpu) 1050a703e490SVasu Dev { 1051a703e490SVasu Dev struct fcoe_percpu_s *p; 1052a703e490SVasu Dev struct task_struct *thread; 1053a703e490SVasu Dev 1054a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1055a703e490SVasu Dev 1056a703e490SVasu Dev thread = kthread_create(fcoe_percpu_receive_thread, 1057a703e490SVasu Dev (void *)p, "fcoethread/%d", cpu); 1058a703e490SVasu Dev 1059e7a51997SJoe Eykholt if (likely(!IS_ERR(thread))) { 1060a703e490SVasu Dev kthread_bind(thread, cpu); 1061a703e490SVasu Dev wake_up_process(thread); 1062a703e490SVasu Dev 1063a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1064a703e490SVasu Dev p->thread = thread; 1065a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1066a703e490SVasu Dev } 1067a703e490SVasu Dev } 1068a703e490SVasu Dev 1069a703e490SVasu Dev /** 10701875f27eSRobert Love * fcoe_percpu_thread_destroy() - Remove the receive thread of a CPU 10711875f27eSRobert Love * @cpu: The CPU index of the CPU whose receive thread is to be destroyed 1072a703e490SVasu Dev * 1073a703e490SVasu Dev * Destroys a per-CPU Rx thread. Any pending skbs are moved to the 1074a703e490SVasu Dev * current CPU's Rx thread. If the thread being destroyed is bound to 1075a703e490SVasu Dev * the CPU processing this context the skbs will be freed. 1076a703e490SVasu Dev */ 1077a703e490SVasu Dev static void fcoe_percpu_thread_destroy(unsigned int cpu) 1078a703e490SVasu Dev { 1079a703e490SVasu Dev struct fcoe_percpu_s *p; 1080a703e490SVasu Dev struct task_struct *thread; 1081a703e490SVasu Dev struct page *crc_eof; 1082a703e490SVasu Dev struct sk_buff *skb; 1083a703e490SVasu Dev #ifdef CONFIG_SMP 1084a703e490SVasu Dev struct fcoe_percpu_s *p0; 1085f018b73aSJoe Eykholt unsigned targ_cpu = get_cpu(); 1086a703e490SVasu Dev #endif /* CONFIG_SMP */ 1087a703e490SVasu Dev 1088d5488eb9SRobert Love FCOE_DBG("Destroying receive thread for CPU %d\n", cpu); 1089a703e490SVasu Dev 1090a703e490SVasu Dev /* Prevent any new skbs from being queued for this CPU. */ 1091a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1092a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1093a703e490SVasu Dev thread = p->thread; 1094a703e490SVasu Dev p->thread = NULL; 1095a703e490SVasu Dev crc_eof = p->crc_eof_page; 1096a703e490SVasu Dev p->crc_eof_page = NULL; 1097a703e490SVasu Dev p->crc_eof_offset = 0; 1098a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1099a703e490SVasu Dev 1100a703e490SVasu Dev #ifdef CONFIG_SMP 1101a703e490SVasu Dev /* 1102a703e490SVasu Dev * Don't bother moving the skb's if this context is running 1103a703e490SVasu Dev * on the same CPU that is having its thread destroyed. This 1104a703e490SVasu Dev * can easily happen when the module is removed. 1105a703e490SVasu Dev */ 1106a703e490SVasu Dev if (cpu != targ_cpu) { 1107a703e490SVasu Dev p0 = &per_cpu(fcoe_percpu, targ_cpu); 1108a703e490SVasu Dev spin_lock_bh(&p0->fcoe_rx_list.lock); 1109a703e490SVasu Dev if (p0->thread) { 1110d5488eb9SRobert Love FCOE_DBG("Moving frames from CPU %d to CPU %d\n", 1111a703e490SVasu Dev cpu, targ_cpu); 1112a703e490SVasu Dev 1113a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1114a703e490SVasu Dev __skb_queue_tail(&p0->fcoe_rx_list, skb); 1115a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1116a703e490SVasu Dev } else { 1117a703e490SVasu Dev /* 1118a703e490SVasu Dev * The targeted CPU is not initialized and cannot accept 1119a703e490SVasu Dev * new skbs. Unlock the targeted CPU and drop the skbs 1120a703e490SVasu Dev * on the CPU that is going offline. 1121a703e490SVasu Dev */ 1122a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1123a703e490SVasu Dev kfree_skb(skb); 1124a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1125a703e490SVasu Dev } 1126a703e490SVasu Dev } else { 1127a703e490SVasu Dev /* 1128a703e490SVasu Dev * This scenario occurs when the module is being removed 1129a703e490SVasu Dev * and all threads are being destroyed. skbs will continue 1130a703e490SVasu Dev * to be shifted from the CPU thread that is being removed 1131a703e490SVasu Dev * to the CPU thread associated with the CPU that is processing 1132a703e490SVasu Dev * the module removal. Once there is only one CPU Rx thread it 1133a703e490SVasu Dev * will reach this case and we will drop all skbs and later 1134a703e490SVasu Dev * stop the thread. 1135a703e490SVasu Dev */ 1136a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1137a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1138a703e490SVasu Dev kfree_skb(skb); 1139a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1140a703e490SVasu Dev } 1141f018b73aSJoe Eykholt put_cpu(); 1142a703e490SVasu Dev #else 1143a703e490SVasu Dev /* 1144dd3fd72eSChris Leech * This a non-SMP scenario where the singular Rx thread is 1145a703e490SVasu Dev * being removed. Free all skbs and stop the thread. 1146a703e490SVasu Dev */ 1147a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1148a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1149a703e490SVasu Dev kfree_skb(skb); 1150a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1151a703e490SVasu Dev #endif 1152a703e490SVasu Dev 1153a703e490SVasu Dev if (thread) 1154a703e490SVasu Dev kthread_stop(thread); 1155a703e490SVasu Dev 1156a703e490SVasu Dev if (crc_eof) 1157a703e490SVasu Dev put_page(crc_eof); 1158a703e490SVasu Dev } 1159a703e490SVasu Dev 1160a703e490SVasu Dev /** 11611875f27eSRobert Love * fcoe_cpu_callback() - Handler for CPU hotplug events 11621875f27eSRobert Love * @nfb: The callback data block 11631875f27eSRobert Love * @action: The event triggering the callback 11641875f27eSRobert Love * @hcpu: The index of the CPU that the event is for 1165a703e490SVasu Dev * 11661875f27eSRobert Love * This creates or destroys per-CPU data for fcoe 1167a703e490SVasu Dev * 1168a703e490SVasu Dev * Returns NOTIFY_OK always. 1169a703e490SVasu Dev */ 1170a703e490SVasu Dev static int fcoe_cpu_callback(struct notifier_block *nfb, 1171a703e490SVasu Dev unsigned long action, void *hcpu) 1172a703e490SVasu Dev { 1173a703e490SVasu Dev unsigned cpu = (unsigned long)hcpu; 1174a703e490SVasu Dev 1175a703e490SVasu Dev switch (action) { 1176a703e490SVasu Dev case CPU_ONLINE: 1177a703e490SVasu Dev case CPU_ONLINE_FROZEN: 1178d5488eb9SRobert Love FCOE_DBG("CPU %x online: Create Rx thread\n", cpu); 1179a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 1180a703e490SVasu Dev break; 1181a703e490SVasu Dev case CPU_DEAD: 1182a703e490SVasu Dev case CPU_DEAD_FROZEN: 1183d5488eb9SRobert Love FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu); 1184a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 1185a703e490SVasu Dev break; 1186a703e490SVasu Dev default: 1187a703e490SVasu Dev break; 1188a703e490SVasu Dev } 1189a703e490SVasu Dev return NOTIFY_OK; 1190a703e490SVasu Dev } 1191a703e490SVasu Dev 1192a703e490SVasu Dev /** 11931875f27eSRobert Love * fcoe_rcv() - Receive packets from a net device 11941875f27eSRobert Love * @skb: The received packet 11951875f27eSRobert Love * @netdev: The net device that the packet was received on 11961875f27eSRobert Love * @ptype: The packet type context 11971875f27eSRobert Love * @olddev: The last device net device 1198a703e490SVasu Dev * 11991875f27eSRobert Love * This routine is called by NET_RX_SOFTIRQ. It receives a packet, builds a 12001875f27eSRobert Love * FC frame and passes the frame to libfc. 1201a703e490SVasu Dev * 1202a703e490SVasu Dev * Returns: 0 for success 1203a703e490SVasu Dev */ 12041875f27eSRobert Love int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, 1205a703e490SVasu Dev struct packet_type *ptype, struct net_device *olddev) 1206a703e490SVasu Dev { 12071875f27eSRobert Love struct fc_lport *lport; 1208a703e490SVasu Dev struct fcoe_rcv_info *fr; 1209259ad85dSChris Leech struct fcoe_interface *fcoe; 1210a703e490SVasu Dev struct fc_frame_header *fh; 1211a703e490SVasu Dev struct fcoe_percpu_s *fps; 1212b2f0091fSVasu Dev unsigned int cpu; 1213a703e490SVasu Dev 1214259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type); 12151875f27eSRobert Love lport = fcoe->ctlr.lp; 12161875f27eSRobert Love if (unlikely(!lport)) { 12171875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "Cannot find hba structure"); 1218a703e490SVasu Dev goto err2; 1219a703e490SVasu Dev } 12201875f27eSRobert Love if (!lport->link_up) 122197c8389dSJoe Eykholt goto err2; 1222a703e490SVasu Dev 12231875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "skb_info: len:%d data_len:%d head:%p " 1224d5488eb9SRobert Love "data:%p tail:%p end:%p sum:%d dev:%s", 1225d5488eb9SRobert Love skb->len, skb->data_len, skb->head, skb->data, 1226d5488eb9SRobert Love skb_tail_pointer(skb), skb_end_pointer(skb), 1227d5488eb9SRobert Love skb->csum, skb->dev ? skb->dev->name : "<NULL>"); 1228a703e490SVasu Dev 1229a703e490SVasu Dev /* check for FCOE packet type */ 1230a703e490SVasu Dev if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { 12311875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "Wrong FC type frame"); 1232a703e490SVasu Dev goto err; 1233a703e490SVasu Dev } 1234a703e490SVasu Dev 1235a703e490SVasu Dev /* 1236a703e490SVasu Dev * Check for minimum frame length, and make sure required FCoE 1237a703e490SVasu Dev * and FC headers are pulled into the linear data area. 1238a703e490SVasu Dev */ 1239a703e490SVasu Dev if (unlikely((skb->len < FCOE_MIN_FRAME) || 1240a703e490SVasu Dev !pskb_may_pull(skb, FCOE_HEADER_LEN))) 1241a703e490SVasu Dev goto err; 1242a703e490SVasu Dev 1243a703e490SVasu Dev skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); 1244a703e490SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 1245a703e490SVasu Dev 1246a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 12471875f27eSRobert Love fr->fr_dev = lport; 1248a703e490SVasu Dev fr->ptype = ptype; 1249a703e490SVasu Dev 1250a703e490SVasu Dev /* 1251b2f0091fSVasu Dev * In case the incoming frame's exchange is originated from 1252b2f0091fSVasu Dev * the initiator, then received frame's exchange id is ANDed 1253b2f0091fSVasu Dev * with fc_cpu_mask bits to get the same cpu on which exchange 1254b2f0091fSVasu Dev * was originated, otherwise just use the current cpu. 1255a703e490SVasu Dev */ 1256b2f0091fSVasu Dev if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX) 1257b2f0091fSVasu Dev cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask; 1258b2f0091fSVasu Dev else 1259b2f0091fSVasu Dev cpu = smp_processor_id(); 1260a703e490SVasu Dev 1261a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1262a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1263a703e490SVasu Dev if (unlikely(!fps->thread)) { 1264a703e490SVasu Dev /* 1265a703e490SVasu Dev * The targeted CPU is not ready, let's target 1266a703e490SVasu Dev * the first CPU now. For non-SMP systems this 1267a703e490SVasu Dev * will check the same CPU twice. 1268a703e490SVasu Dev */ 12691875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "CPU is online, but no receive thread " 1270d5488eb9SRobert Love "ready for incoming skb- using first online " 1271d5488eb9SRobert Love "CPU.\n"); 1272a703e490SVasu Dev 1273a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 12746957177fSRusty Russell cpu = cpumask_first(cpu_online_mask); 1275a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1276a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1277a703e490SVasu Dev if (!fps->thread) { 1278a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1279a703e490SVasu Dev goto err; 1280a703e490SVasu Dev } 1281a703e490SVasu Dev } 1282a703e490SVasu Dev 1283a703e490SVasu Dev /* 1284a703e490SVasu Dev * We now have a valid CPU that we're targeting for 1285a703e490SVasu Dev * this skb. We also have this receive thread locked, 1286a703e490SVasu Dev * so we're free to queue skbs into it's queue. 1287a703e490SVasu Dev */ 1288859b7b64SChris Leech 1289859b7b64SChris Leech /* If this is a SCSI-FCP frame, and this is already executing on the 1290859b7b64SChris Leech * correct CPU, and the queue for this CPU is empty, then go ahead 1291859b7b64SChris Leech * and process the frame directly in the softirq context. 1292859b7b64SChris Leech * This lets us process completions without context switching from the 1293859b7b64SChris Leech * NET_RX softirq, to our receive processing thread, and then back to 1294859b7b64SChris Leech * BLOCK softirq context. 1295859b7b64SChris Leech */ 1296859b7b64SChris Leech if (fh->fh_type == FC_TYPE_FCP && 1297859b7b64SChris Leech cpu == smp_processor_id() && 1298859b7b64SChris Leech skb_queue_empty(&fps->fcoe_rx_list)) { 1299859b7b64SChris Leech spin_unlock_bh(&fps->fcoe_rx_list.lock); 1300859b7b64SChris Leech fcoe_recv_frame(skb); 1301859b7b64SChris Leech } else { 1302a703e490SVasu Dev __skb_queue_tail(&fps->fcoe_rx_list, skb); 1303a703e490SVasu Dev if (fps->fcoe_rx_list.qlen == 1) 1304a703e490SVasu Dev wake_up_process(fps->thread); 1305a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1306859b7b64SChris Leech } 1307a703e490SVasu Dev 1308a703e490SVasu Dev return 0; 1309a703e490SVasu Dev err: 1310f018b73aSJoe Eykholt per_cpu_ptr(lport->dev_stats, get_cpu())->ErrorFrames++; 1311f018b73aSJoe Eykholt put_cpu(); 1312a703e490SVasu Dev err2: 1313a703e490SVasu Dev kfree_skb(skb); 1314a703e490SVasu Dev return -1; 1315a703e490SVasu Dev } 1316a703e490SVasu Dev 1317a703e490SVasu Dev /** 13181875f27eSRobert Love * fcoe_start_io() - Start FCoE I/O 13191875f27eSRobert Love * @skb: The packet to be transmitted 13201875f27eSRobert Love * 13211875f27eSRobert Love * This routine is called from the net device to start transmitting 13221875f27eSRobert Love * FCoE packets. 1323a703e490SVasu Dev * 1324a703e490SVasu Dev * Returns: 0 for success 1325a703e490SVasu Dev */ 1326a703e490SVasu Dev static inline int fcoe_start_io(struct sk_buff *skb) 1327a703e490SVasu Dev { 132818fa11efSChris Leech struct sk_buff *nskb; 1329a703e490SVasu Dev int rc; 1330a703e490SVasu Dev 133118fa11efSChris Leech nskb = skb_clone(skb, GFP_ATOMIC); 133218fa11efSChris Leech rc = dev_queue_xmit(nskb); 1333a703e490SVasu Dev if (rc != 0) 1334a703e490SVasu Dev return rc; 1335a703e490SVasu Dev kfree_skb(skb); 1336a703e490SVasu Dev return 0; 1337a703e490SVasu Dev } 1338a703e490SVasu Dev 1339a703e490SVasu Dev /** 13401875f27eSRobert Love * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC 13411875f27eSRobert Love * @skb: The packet to be transmitted 13421875f27eSRobert Love * @tlen: The total length of the trailer 13431875f27eSRobert Love * 13441875f27eSRobert Love * This routine allocates a page for frame trailers. The page is re-used if 13451875f27eSRobert Love * there is enough room left on it for the current trailer. If there isn't 13461875f27eSRobert Love * enough buffer left a new page is allocated for the trailer. Reference to 13471875f27eSRobert Love * the page from this function as well as the skbs using the page fragments 13481875f27eSRobert Love * ensure that the page is freed at the appropriate time. 1349a703e490SVasu Dev * 1350a703e490SVasu Dev * Returns: 0 for success 1351a703e490SVasu Dev */ 1352a703e490SVasu Dev static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen) 1353a703e490SVasu Dev { 1354a703e490SVasu Dev struct fcoe_percpu_s *fps; 1355a703e490SVasu Dev struct page *page; 1356a703e490SVasu Dev 1357a703e490SVasu Dev fps = &get_cpu_var(fcoe_percpu); 1358a703e490SVasu Dev page = fps->crc_eof_page; 1359a703e490SVasu Dev if (!page) { 1360a703e490SVasu Dev page = alloc_page(GFP_ATOMIC); 1361a703e490SVasu Dev if (!page) { 1362a703e490SVasu Dev put_cpu_var(fcoe_percpu); 1363a703e490SVasu Dev return -ENOMEM; 1364a703e490SVasu Dev } 1365a703e490SVasu Dev fps->crc_eof_page = page; 1366a703e490SVasu Dev fps->crc_eof_offset = 0; 1367a703e490SVasu Dev } 1368a703e490SVasu Dev 1369a703e490SVasu Dev get_page(page); 1370a703e490SVasu Dev skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page, 1371a703e490SVasu Dev fps->crc_eof_offset, tlen); 1372a703e490SVasu Dev skb->len += tlen; 1373a703e490SVasu Dev skb->data_len += tlen; 1374a703e490SVasu Dev skb->truesize += tlen; 1375a703e490SVasu Dev fps->crc_eof_offset += sizeof(struct fcoe_crc_eof); 1376a703e490SVasu Dev 1377a703e490SVasu Dev if (fps->crc_eof_offset >= PAGE_SIZE) { 1378a703e490SVasu Dev fps->crc_eof_page = NULL; 1379a703e490SVasu Dev fps->crc_eof_offset = 0; 1380a703e490SVasu Dev put_page(page); 1381a703e490SVasu Dev } 1382a703e490SVasu Dev put_cpu_var(fcoe_percpu); 1383a703e490SVasu Dev return 0; 1384a703e490SVasu Dev } 1385a703e490SVasu Dev 1386a703e490SVasu Dev /** 13871875f27eSRobert Love * fcoe_fc_crc() - Calculates the CRC for a given frame 13881875f27eSRobert Love * @fp: The frame to be checksumed 1389a703e490SVasu Dev * 13901875f27eSRobert Love * This uses crc32() routine to calculate the CRC for a frame 13911875f27eSRobert Love * 13921875f27eSRobert Love * Return: The 32 bit CRC value 1393a703e490SVasu Dev */ 1394a703e490SVasu Dev u32 fcoe_fc_crc(struct fc_frame *fp) 1395a703e490SVasu Dev { 1396a703e490SVasu Dev struct sk_buff *skb = fp_skb(fp); 1397a703e490SVasu Dev struct skb_frag_struct *frag; 1398a703e490SVasu Dev unsigned char *data; 1399a703e490SVasu Dev unsigned long off, len, clen; 1400a703e490SVasu Dev u32 crc; 1401a703e490SVasu Dev unsigned i; 1402a703e490SVasu Dev 1403a703e490SVasu Dev crc = crc32(~0, skb->data, skb_headlen(skb)); 1404a703e490SVasu Dev 1405a703e490SVasu Dev for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 1406a703e490SVasu Dev frag = &skb_shinfo(skb)->frags[i]; 1407a703e490SVasu Dev off = frag->page_offset; 1408a703e490SVasu Dev len = frag->size; 1409a703e490SVasu Dev while (len > 0) { 1410a703e490SVasu Dev clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK)); 1411a703e490SVasu Dev data = kmap_atomic(frag->page + (off >> PAGE_SHIFT), 1412a703e490SVasu Dev KM_SKB_DATA_SOFTIRQ); 1413a703e490SVasu Dev crc = crc32(crc, data + (off & ~PAGE_MASK), clen); 1414a703e490SVasu Dev kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ); 1415a703e490SVasu Dev off += clen; 1416a703e490SVasu Dev len -= clen; 1417a703e490SVasu Dev } 1418a703e490SVasu Dev } 1419a703e490SVasu Dev return crc; 1420a703e490SVasu Dev } 1421a703e490SVasu Dev 1422a703e490SVasu Dev /** 14231875f27eSRobert Love * fcoe_xmit() - Transmit a FCoE frame 14241875f27eSRobert Love * @lport: The local port that the frame is to be transmitted for 14251875f27eSRobert Love * @fp: The frame to be transmitted 1426a703e490SVasu Dev * 1427a703e490SVasu Dev * Return: 0 for success 1428a703e490SVasu Dev */ 14291875f27eSRobert Love int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp) 1430a703e490SVasu Dev { 14314bb6b515SVasu Dev int wlen; 1432a703e490SVasu Dev u32 crc; 1433a703e490SVasu Dev struct ethhdr *eh; 1434a703e490SVasu Dev struct fcoe_crc_eof *cp; 1435a703e490SVasu Dev struct sk_buff *skb; 1436a703e490SVasu Dev struct fcoe_dev_stats *stats; 1437a703e490SVasu Dev struct fc_frame_header *fh; 1438a703e490SVasu Dev unsigned int hlen; /* header length implies the version */ 1439a703e490SVasu Dev unsigned int tlen; /* trailer length */ 1440a703e490SVasu Dev unsigned int elen; /* eth header, may include vlan */ 14411875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 14423fe9a0baSChris Leech struct fcoe_interface *fcoe = port->fcoe; 1443a703e490SVasu Dev u8 sof, eof; 1444a703e490SVasu Dev struct fcoe_hdr *hp; 1445a703e490SVasu Dev 1446a703e490SVasu Dev WARN_ON((fr_len(fp) % sizeof(u32)) != 0); 1447a703e490SVasu Dev 1448a703e490SVasu Dev fh = fc_frame_header_get(fp); 144997c8389dSJoe Eykholt skb = fp_skb(fp); 145097c8389dSJoe Eykholt wlen = skb->len / FCOE_WORD_TO_BYTE; 145197c8389dSJoe Eykholt 14521875f27eSRobert Love if (!lport->link_up) { 14533caf02eeSDan Carpenter kfree_skb(skb); 145497c8389dSJoe Eykholt return 0; 1455a703e490SVasu Dev } 1456a703e490SVasu Dev 14579860eeb4SJoe Eykholt if (unlikely(fh->fh_type == FC_TYPE_ELS) && 14581875f27eSRobert Love fcoe_ctlr_els_send(&fcoe->ctlr, lport, skb)) 145997c8389dSJoe Eykholt return 0; 146097c8389dSJoe Eykholt 1461a703e490SVasu Dev sof = fr_sof(fp); 1462a703e490SVasu Dev eof = fr_eof(fp); 1463a703e490SVasu Dev 14644e57e1cbSVasu Dev elen = sizeof(struct ethhdr); 1465a703e490SVasu Dev hlen = sizeof(struct fcoe_hdr); 1466a703e490SVasu Dev tlen = sizeof(struct fcoe_crc_eof); 1467a703e490SVasu Dev wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; 1468a703e490SVasu Dev 1469a703e490SVasu Dev /* crc offload */ 14701875f27eSRobert Love if (likely(lport->crc_offload)) { 1471a703e490SVasu Dev skb->ip_summed = CHECKSUM_PARTIAL; 1472a703e490SVasu Dev skb->csum_start = skb_headroom(skb); 1473a703e490SVasu Dev skb->csum_offset = skb->len; 1474a703e490SVasu Dev crc = 0; 1475a703e490SVasu Dev } else { 1476a703e490SVasu Dev skb->ip_summed = CHECKSUM_NONE; 1477a703e490SVasu Dev crc = fcoe_fc_crc(fp); 1478a703e490SVasu Dev } 1479a703e490SVasu Dev 1480014f5c3fSChris Leech /* copy port crc and eof to the skb buff */ 1481a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1482a703e490SVasu Dev skb_frag_t *frag; 1483a703e490SVasu Dev if (fcoe_get_paged_crc_eof(skb, tlen)) { 1484a703e490SVasu Dev kfree_skb(skb); 1485a703e490SVasu Dev return -ENOMEM; 1486a703e490SVasu Dev } 1487a703e490SVasu Dev frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; 1488a703e490SVasu Dev cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ) 1489a703e490SVasu Dev + frag->page_offset; 1490a703e490SVasu Dev } else { 1491a703e490SVasu Dev cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); 1492a703e490SVasu Dev } 1493a703e490SVasu Dev 1494a703e490SVasu Dev memset(cp, 0, sizeof(*cp)); 1495a703e490SVasu Dev cp->fcoe_eof = eof; 1496a703e490SVasu Dev cp->fcoe_crc32 = cpu_to_le32(~crc); 1497a703e490SVasu Dev 1498a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1499a703e490SVasu Dev kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ); 1500a703e490SVasu Dev cp = NULL; 1501a703e490SVasu Dev } 1502a703e490SVasu Dev 1503014f5c3fSChris Leech /* adjust skb network/transport offsets to match mac/fcoe/port */ 1504a703e490SVasu Dev skb_push(skb, elen + hlen); 1505a703e490SVasu Dev skb_reset_mac_header(skb); 1506a703e490SVasu Dev skb_reset_network_header(skb); 1507a703e490SVasu Dev skb->mac_len = elen; 1508a703e490SVasu Dev skb->protocol = htons(ETH_P_FCOE); 15093fe9a0baSChris Leech skb->dev = fcoe->netdev; 1510a703e490SVasu Dev 1511a703e490SVasu Dev /* fill up mac and fcoe headers */ 1512a703e490SVasu Dev eh = eth_hdr(skb); 1513a703e490SVasu Dev eh->h_proto = htons(ETH_P_FCOE); 15143fe9a0baSChris Leech if (fcoe->ctlr.map_dest) 1515a703e490SVasu Dev fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); 1516a703e490SVasu Dev else 1517a703e490SVasu Dev /* insert GW address */ 15183fe9a0baSChris Leech memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN); 1519a703e490SVasu Dev 15203fe9a0baSChris Leech if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN)) 15213fe9a0baSChris Leech memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN); 1522a703e490SVasu Dev else 152311b56188SChris Leech memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); 1524a703e490SVasu Dev 1525a703e490SVasu Dev hp = (struct fcoe_hdr *)(eh + 1); 1526a703e490SVasu Dev memset(hp, 0, sizeof(*hp)); 1527a703e490SVasu Dev if (FC_FCOE_VER) 1528a703e490SVasu Dev FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); 1529a703e490SVasu Dev hp->fcoe_sof = sof; 1530a703e490SVasu Dev 1531a703e490SVasu Dev /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ 15321875f27eSRobert Love if (lport->seq_offload && fr_max_payload(fp)) { 1533a703e490SVasu Dev skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; 1534a703e490SVasu Dev skb_shinfo(skb)->gso_size = fr_max_payload(fp); 1535a703e490SVasu Dev } else { 1536a703e490SVasu Dev skb_shinfo(skb)->gso_type = 0; 1537a703e490SVasu Dev skb_shinfo(skb)->gso_size = 0; 1538a703e490SVasu Dev } 1539a703e490SVasu Dev /* update tx stats: regardless if LLD fails */ 1540f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1541a703e490SVasu Dev stats->TxFrames++; 1542a703e490SVasu Dev stats->TxWords += wlen; 1543f018b73aSJoe Eykholt put_cpu(); 1544a703e490SVasu Dev 1545a703e490SVasu Dev /* send down to lld */ 15461875f27eSRobert Love fr_dev(fp) = lport; 1547014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen) 15481875f27eSRobert Love fcoe_check_wait_queue(lport, skb); 15494bb6b515SVasu Dev else if (fcoe_start_io(skb)) 15501875f27eSRobert Love fcoe_check_wait_queue(lport, skb); 1551a703e490SVasu Dev 1552a703e490SVasu Dev return 0; 1553a703e490SVasu Dev } 1554a703e490SVasu Dev 1555a703e490SVasu Dev /** 15561875f27eSRobert Love * fcoe_percpu_flush_done() - Indicate per-CPU queue flush completion 15571875f27eSRobert Love * @skb: The completed skb (argument required by destructor) 1558e7a51997SJoe Eykholt */ 1559e7a51997SJoe Eykholt static void fcoe_percpu_flush_done(struct sk_buff *skb) 1560e7a51997SJoe Eykholt { 1561e7a51997SJoe Eykholt complete(&fcoe_flush_completion); 1562e7a51997SJoe Eykholt } 1563e7a51997SJoe Eykholt 1564e7a51997SJoe Eykholt /** 1565859b7b64SChris Leech * fcoe_recv_frame() - process a single received frame 1566859b7b64SChris Leech * @skb: frame to process 1567a703e490SVasu Dev */ 1568859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb) 1569a703e490SVasu Dev { 1570a703e490SVasu Dev u32 fr_len; 15711875f27eSRobert Love struct fc_lport *lport; 1572a703e490SVasu Dev struct fcoe_rcv_info *fr; 1573a703e490SVasu Dev struct fcoe_dev_stats *stats; 1574a703e490SVasu Dev struct fc_frame_header *fh; 1575a703e490SVasu Dev struct fcoe_crc_eof crc_eof; 1576a703e490SVasu Dev struct fc_frame *fp; 1577014f5c3fSChris Leech struct fcoe_port *port; 1578a703e490SVasu Dev struct fcoe_hdr *hp; 1579a703e490SVasu Dev 1580a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 15811875f27eSRobert Love lport = fr->fr_dev; 15821875f27eSRobert Love if (unlikely(!lport)) { 1583e7a51997SJoe Eykholt if (skb->destructor != fcoe_percpu_flush_done) 1584e7a51997SJoe Eykholt FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb"); 1585a703e490SVasu Dev kfree_skb(skb); 1586859b7b64SChris Leech return; 1587a703e490SVasu Dev } 1588a703e490SVasu Dev 1589d5488eb9SRobert Love FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d " 1590d5488eb9SRobert Love "head:%p data:%p tail:%p end:%p sum:%d dev:%s", 1591a703e490SVasu Dev skb->len, skb->data_len, 1592a703e490SVasu Dev skb->head, skb->data, skb_tail_pointer(skb), 1593a703e490SVasu Dev skb_end_pointer(skb), skb->csum, 1594a703e490SVasu Dev skb->dev ? skb->dev->name : "<NULL>"); 1595a703e490SVasu Dev 15961875f27eSRobert Love port = lport_priv(lport); 1597a703e490SVasu Dev if (skb_is_nonlinear(skb)) 1598a703e490SVasu Dev skb_linearize(skb); /* not ideal */ 1599a703e490SVasu Dev 1600a703e490SVasu Dev /* 1601a703e490SVasu Dev * Frame length checks and setting up the header pointers 1602a703e490SVasu Dev * was done in fcoe_rcv already. 1603a703e490SVasu Dev */ 1604a703e490SVasu Dev hp = (struct fcoe_hdr *) skb_network_header(skb); 1605a703e490SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 1606a703e490SVasu Dev 1607f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1608a703e490SVasu Dev if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { 1609a703e490SVasu Dev if (stats->ErrorFrames < 5) 1610d5488eb9SRobert Love printk(KERN_WARNING "fcoe: FCoE version " 1611a703e490SVasu Dev "mismatch: The frame has " 1612a703e490SVasu Dev "version %x, but the " 1613a703e490SVasu Dev "initiator supports version " 1614a703e490SVasu Dev "%x\n", FC_FCOE_DECAPS_VER(hp), 1615a703e490SVasu Dev FC_FCOE_VER); 1616f018b73aSJoe Eykholt goto drop; 1617a703e490SVasu Dev } 1618a703e490SVasu Dev 1619a703e490SVasu Dev skb_pull(skb, sizeof(struct fcoe_hdr)); 1620a703e490SVasu Dev fr_len = skb->len - sizeof(struct fcoe_crc_eof); 1621a703e490SVasu Dev 1622a703e490SVasu Dev stats->RxFrames++; 1623a703e490SVasu Dev stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; 1624a703e490SVasu Dev 1625a703e490SVasu Dev fp = (struct fc_frame *)skb; 1626a703e490SVasu Dev fc_frame_init(fp); 16271875f27eSRobert Love fr_dev(fp) = lport; 1628a703e490SVasu Dev fr_sof(fp) = hp->fcoe_sof; 1629a703e490SVasu Dev 1630a703e490SVasu Dev /* Copy out the CRC and EOF trailer for access */ 1631f018b73aSJoe Eykholt if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) 1632f018b73aSJoe Eykholt goto drop; 1633a703e490SVasu Dev fr_eof(fp) = crc_eof.fcoe_eof; 1634a703e490SVasu Dev fr_crc(fp) = crc_eof.fcoe_crc32; 1635f018b73aSJoe Eykholt if (pskb_trim(skb, fr_len)) 1636f018b73aSJoe Eykholt goto drop; 1637a703e490SVasu Dev 1638a703e490SVasu Dev /* 1639a703e490SVasu Dev * We only check CRC if no offload is available and if it is 1640a703e490SVasu Dev * it's solicited data, in which case, the FCP layer would 1641a703e490SVasu Dev * check it during the copy. 1642a703e490SVasu Dev */ 16431875f27eSRobert Love if (lport->crc_offload && 16441875f27eSRobert Love skb->ip_summed == CHECKSUM_UNNECESSARY) 1645a703e490SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 1646a703e490SVasu Dev else 1647a703e490SVasu Dev fr_flags(fp) |= FCPHF_CRC_UNCHECKED; 1648a703e490SVasu Dev 1649a703e490SVasu Dev fh = fc_frame_header_get(fp); 1650f018b73aSJoe Eykholt if ((fh->fh_r_ctl != FC_RCTL_DD_SOL_DATA || 1651f018b73aSJoe Eykholt fh->fh_type != FC_TYPE_FCP) && 1652f018b73aSJoe Eykholt (fr_flags(fp) & FCPHF_CRC_UNCHECKED)) { 1653a703e490SVasu Dev if (le32_to_cpu(fr_crc(fp)) != 1654a703e490SVasu Dev ~crc32(~0, skb->data, fr_len)) { 1655d5488eb9SRobert Love if (stats->InvalidCRCCount < 5) 1656a703e490SVasu Dev printk(KERN_WARNING "fcoe: dropping " 1657a703e490SVasu Dev "frame with CRC error\n"); 1658a703e490SVasu Dev stats->InvalidCRCCount++; 1659f018b73aSJoe Eykholt goto drop; 1660a703e490SVasu Dev } 1661a703e490SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 1662a703e490SVasu Dev } 1663f018b73aSJoe Eykholt put_cpu(); 16641875f27eSRobert Love fc_exch_recv(lport, fp); 1665f018b73aSJoe Eykholt return; 1666f018b73aSJoe Eykholt 1667f018b73aSJoe Eykholt drop: 1668f018b73aSJoe Eykholt stats->ErrorFrames++; 1669f018b73aSJoe Eykholt put_cpu(); 1670f018b73aSJoe Eykholt kfree_skb(skb); 1671a703e490SVasu Dev } 1672859b7b64SChris Leech 1673859b7b64SChris Leech /** 1674859b7b64SChris Leech * fcoe_percpu_receive_thread() - The per-CPU packet receive thread 1675859b7b64SChris Leech * @arg: The per-CPU context 1676859b7b64SChris Leech * 1677859b7b64SChris Leech * Return: 0 for success 1678859b7b64SChris Leech */ 1679859b7b64SChris Leech int fcoe_percpu_receive_thread(void *arg) 1680859b7b64SChris Leech { 1681859b7b64SChris Leech struct fcoe_percpu_s *p = arg; 1682859b7b64SChris Leech struct sk_buff *skb; 1683859b7b64SChris Leech 1684859b7b64SChris Leech set_user_nice(current, -20); 1685859b7b64SChris Leech 1686859b7b64SChris Leech while (!kthread_should_stop()) { 1687859b7b64SChris Leech 1688859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1689859b7b64SChris Leech while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) { 1690859b7b64SChris Leech set_current_state(TASK_INTERRUPTIBLE); 1691859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1692859b7b64SChris Leech schedule(); 1693859b7b64SChris Leech set_current_state(TASK_RUNNING); 1694859b7b64SChris Leech if (kthread_should_stop()) 1695859b7b64SChris Leech return 0; 1696859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1697859b7b64SChris Leech } 1698859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1699859b7b64SChris Leech fcoe_recv_frame(skb); 1700859b7b64SChris Leech } 1701a703e490SVasu Dev return 0; 1702a703e490SVasu Dev } 1703a703e490SVasu Dev 1704a703e490SVasu Dev /** 17051875f27eSRobert Love * fcoe_check_wait_queue() - Attempt to clear the transmit backlog 17061875f27eSRobert Love * @lport: The local port whose backlog is to be cleared 1707a703e490SVasu Dev * 17081875f27eSRobert Love * This empties the wait_queue, dequeues the head of the wait_queue queue 17091875f27eSRobert Love * and calls fcoe_start_io() for each packet. If all skb have been 17101875f27eSRobert Love * transmitted it returns the qlen. If an error occurs it restores 17111875f27eSRobert Love * wait_queue (to try again later) and returns -1. 1712a703e490SVasu Dev * 17131875f27eSRobert Love * The wait_queue is used when the skb transmit fails. The failed skb 17141875f27eSRobert Love * will go in the wait_queue which will be emptied by the timer function or 1715a703e490SVasu Dev * by the next skb transmit. 1716a703e490SVasu Dev */ 17171875f27eSRobert Love static void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb) 1718a703e490SVasu Dev { 17191875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 17204bb6b515SVasu Dev int rc; 1721a703e490SVasu Dev 1722014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 17234bb6b515SVasu Dev 17244bb6b515SVasu Dev if (skb) 1725014f5c3fSChris Leech __skb_queue_tail(&port->fcoe_pending_queue, skb); 17264bb6b515SVasu Dev 1727014f5c3fSChris Leech if (port->fcoe_pending_queue_active) 1728a703e490SVasu Dev goto out; 1729014f5c3fSChris Leech port->fcoe_pending_queue_active = 1; 1730a703e490SVasu Dev 1731014f5c3fSChris Leech while (port->fcoe_pending_queue.qlen) { 1732a703e490SVasu Dev /* keep qlen > 0 until fcoe_start_io succeeds */ 1733014f5c3fSChris Leech port->fcoe_pending_queue.qlen++; 1734014f5c3fSChris Leech skb = __skb_dequeue(&port->fcoe_pending_queue); 1735a703e490SVasu Dev 1736014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 1737a703e490SVasu Dev rc = fcoe_start_io(skb); 1738014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 1739a703e490SVasu Dev 1740a703e490SVasu Dev if (rc) { 1741014f5c3fSChris Leech __skb_queue_head(&port->fcoe_pending_queue, skb); 1742a703e490SVasu Dev /* undo temporary increment above */ 1743014f5c3fSChris Leech port->fcoe_pending_queue.qlen--; 1744a703e490SVasu Dev break; 1745a703e490SVasu Dev } 1746a703e490SVasu Dev /* undo temporary increment above */ 1747014f5c3fSChris Leech port->fcoe_pending_queue.qlen--; 1748a703e490SVasu Dev } 1749a703e490SVasu Dev 1750014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH) 17511875f27eSRobert Love lport->qfull = 0; 1752014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer)) 1753014f5c3fSChris Leech mod_timer(&port->timer, jiffies + 2); 1754014f5c3fSChris Leech port->fcoe_pending_queue_active = 0; 1755a703e490SVasu Dev out: 1756014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH) 17571875f27eSRobert Love lport->qfull = 1; 1758014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 17594bb6b515SVasu Dev return; 1760a703e490SVasu Dev } 1761a703e490SVasu Dev 1762a703e490SVasu Dev /** 17631875f27eSRobert Love * fcoe_dev_setup() - Setup the link change notification interface 1764a703e490SVasu Dev */ 1765b0d428adSRandy Dunlap static void fcoe_dev_setup(void) 1766a703e490SVasu Dev { 1767a703e490SVasu Dev register_netdevice_notifier(&fcoe_notifier); 1768a703e490SVasu Dev } 1769a703e490SVasu Dev 1770a703e490SVasu Dev /** 17711875f27eSRobert Love * fcoe_dev_cleanup() - Cleanup the link change notification interface 1772a703e490SVasu Dev */ 1773a703e490SVasu Dev static void fcoe_dev_cleanup(void) 1774a703e490SVasu Dev { 1775a703e490SVasu Dev unregister_netdevice_notifier(&fcoe_notifier); 1776a703e490SVasu Dev } 1777a703e490SVasu Dev 1778a703e490SVasu Dev /** 17791875f27eSRobert Love * fcoe_device_notification() - Handler for net device events 17801875f27eSRobert Love * @notifier: The context of the notification 17811875f27eSRobert Love * @event: The type of event 17821875f27eSRobert Love * @ptr: The net device that the event was on 1783a703e490SVasu Dev * 17841875f27eSRobert Love * This function is called by the Ethernet driver in case of link change event. 1785a703e490SVasu Dev * 1786a703e490SVasu Dev * Returns: 0 for success 1787a703e490SVasu Dev */ 1788a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *notifier, 1789a703e490SVasu Dev ulong event, void *ptr) 1790a703e490SVasu Dev { 17911875f27eSRobert Love struct fc_lport *lport = NULL; 17921d1b88dcSVasu Dev struct net_device *netdev = ptr; 1793014f5c3fSChris Leech struct fcoe_interface *fcoe; 17942e70e241SChris Leech struct fcoe_port *port; 1795a703e490SVasu Dev struct fcoe_dev_stats *stats; 179697c8389dSJoe Eykholt u32 link_possible = 1; 1797a703e490SVasu Dev u32 mfs; 1798a703e490SVasu Dev int rc = NOTIFY_OK; 1799a703e490SVasu Dev 1800014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 180125024989SChris Leech if (fcoe->netdev == netdev) { 18021875f27eSRobert Love lport = fcoe->ctlr.lp; 1803a703e490SVasu Dev break; 1804a703e490SVasu Dev } 1805a703e490SVasu Dev } 18061875f27eSRobert Love if (!lport) { 1807a703e490SVasu Dev rc = NOTIFY_DONE; 1808a703e490SVasu Dev goto out; 1809a703e490SVasu Dev } 1810a703e490SVasu Dev 1811a703e490SVasu Dev switch (event) { 1812a703e490SVasu Dev case NETDEV_DOWN: 1813a703e490SVasu Dev case NETDEV_GOING_DOWN: 181497c8389dSJoe Eykholt link_possible = 0; 1815a703e490SVasu Dev break; 1816a703e490SVasu Dev case NETDEV_UP: 1817a703e490SVasu Dev case NETDEV_CHANGE: 1818a703e490SVasu Dev break; 1819a703e490SVasu Dev case NETDEV_CHANGEMTU: 18207221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) 18217221d7e5SYi Zou break; 18221d1b88dcSVasu Dev mfs = netdev->mtu - (sizeof(struct fcoe_hdr) + 1823a703e490SVasu Dev sizeof(struct fcoe_crc_eof)); 1824a703e490SVasu Dev if (mfs >= FC_MIN_MAX_FRAME) 18251875f27eSRobert Love fc_set_mfs(lport, mfs); 1826a703e490SVasu Dev break; 1827a703e490SVasu Dev case NETDEV_REGISTER: 1828a703e490SVasu Dev break; 18292e70e241SChris Leech case NETDEV_UNREGISTER: 18302e70e241SChris Leech list_del(&fcoe->list); 18312e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 18322e70e241SChris Leech fcoe_interface_cleanup(fcoe); 18332e70e241SChris Leech schedule_work(&port->destroy_work); 18342e70e241SChris Leech goto out; 18352e70e241SChris Leech break; 1836a703e490SVasu Dev default: 18371d1b88dcSVasu Dev FCOE_NETDEV_DBG(netdev, "Unknown event %ld " 1838d5488eb9SRobert Love "from netdev netlink\n", event); 1839a703e490SVasu Dev } 18405e4f8fe7SRobert Love 18415e4f8fe7SRobert Love fcoe_link_speed_update(lport); 18425e4f8fe7SRobert Love 18431875f27eSRobert Love if (link_possible && !fcoe_link_ok(lport)) 18443fe9a0baSChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 18453fe9a0baSChris Leech else if (fcoe_ctlr_link_down(&fcoe->ctlr)) { 1846f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1847a703e490SVasu Dev stats->LinkFailureCount++; 1848f018b73aSJoe Eykholt put_cpu(); 18491875f27eSRobert Love fcoe_clean_pending_queue(lport); 1850a703e490SVasu Dev } 1851a703e490SVasu Dev out: 1852a703e490SVasu Dev return rc; 1853a703e490SVasu Dev } 1854a703e490SVasu Dev 1855a703e490SVasu Dev /** 18561875f27eSRobert Love * fcoe_if_to_netdev() - Parse a name buffer to get a net device 18571875f27eSRobert Love * @buffer: The name of the net device 1858a703e490SVasu Dev * 18591875f27eSRobert Love * Returns: NULL or a ptr to net_device 1860a703e490SVasu Dev */ 1861a703e490SVasu Dev static struct net_device *fcoe_if_to_netdev(const char *buffer) 1862a703e490SVasu Dev { 1863a703e490SVasu Dev char *cp; 1864a703e490SVasu Dev char ifname[IFNAMSIZ + 2]; 1865a703e490SVasu Dev 1866a703e490SVasu Dev if (buffer) { 1867a703e490SVasu Dev strlcpy(ifname, buffer, IFNAMSIZ); 1868a703e490SVasu Dev cp = ifname + strlen(ifname); 1869a703e490SVasu Dev while (--cp >= ifname && *cp == '\n') 1870a703e490SVasu Dev *cp = '\0'; 1871a703e490SVasu Dev return dev_get_by_name(&init_net, ifname); 1872a703e490SVasu Dev } 1873a703e490SVasu Dev return NULL; 1874a703e490SVasu Dev } 1875a703e490SVasu Dev 1876a703e490SVasu Dev /** 187755a66d3cSVasu Dev * fcoe_disable() - Disables a FCoE interface 187855a66d3cSVasu Dev * @buffer: The name of the Ethernet interface to be disabled 187955a66d3cSVasu Dev * @kp: The associated kernel parameter 188055a66d3cSVasu Dev * 188155a66d3cSVasu Dev * Called from sysfs. 188255a66d3cSVasu Dev * 188355a66d3cSVasu Dev * Returns: 0 for success 188455a66d3cSVasu Dev */ 188555a66d3cSVasu Dev static int fcoe_disable(const char *buffer, struct kernel_param *kp) 188655a66d3cSVasu Dev { 188755a66d3cSVasu Dev struct fcoe_interface *fcoe; 188855a66d3cSVasu Dev struct net_device *netdev; 188955a66d3cSVasu Dev int rc = 0; 189055a66d3cSVasu Dev 189155a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 189255a66d3cSVasu Dev #ifdef CONFIG_FCOE_MODULE 189355a66d3cSVasu Dev /* 189455a66d3cSVasu Dev * Make sure the module has been initialized, and is not about to be 189555a66d3cSVasu Dev * removed. Module paramter sysfs files are writable before the 189655a66d3cSVasu Dev * module_init function is called and after module_exit. 189755a66d3cSVasu Dev */ 189855a66d3cSVasu Dev if (THIS_MODULE->state != MODULE_STATE_LIVE) { 189955a66d3cSVasu Dev rc = -ENODEV; 190055a66d3cSVasu Dev goto out_nodev; 190155a66d3cSVasu Dev } 190255a66d3cSVasu Dev #endif 190355a66d3cSVasu Dev 190455a66d3cSVasu Dev netdev = fcoe_if_to_netdev(buffer); 190555a66d3cSVasu Dev if (!netdev) { 190655a66d3cSVasu Dev rc = -ENODEV; 190755a66d3cSVasu Dev goto out_nodev; 190855a66d3cSVasu Dev } 190955a66d3cSVasu Dev 191034ce27bcSVasu Dev if (!rtnl_trylock()) { 191134ce27bcSVasu Dev dev_put(netdev); 191234ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 191334ce27bcSVasu Dev return restart_syscall(); 191434ce27bcSVasu Dev } 191534ce27bcSVasu Dev 191655a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 191755a66d3cSVasu Dev rtnl_unlock(); 191855a66d3cSVasu Dev 19199ee50e48SChris Leech if (fcoe) { 192055a66d3cSVasu Dev fc_fabric_logoff(fcoe->ctlr.lp); 19219ee50e48SChris Leech fcoe_ctlr_link_down(&fcoe->ctlr); 19229ee50e48SChris Leech } else 192355a66d3cSVasu Dev rc = -ENODEV; 192455a66d3cSVasu Dev 192555a66d3cSVasu Dev dev_put(netdev); 192655a66d3cSVasu Dev out_nodev: 192755a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 192855a66d3cSVasu Dev return rc; 192955a66d3cSVasu Dev } 193055a66d3cSVasu Dev 193155a66d3cSVasu Dev /** 193255a66d3cSVasu Dev * fcoe_enable() - Enables a FCoE interface 193355a66d3cSVasu Dev * @buffer: The name of the Ethernet interface to be enabled 193455a66d3cSVasu Dev * @kp: The associated kernel parameter 193555a66d3cSVasu Dev * 193655a66d3cSVasu Dev * Called from sysfs. 193755a66d3cSVasu Dev * 193855a66d3cSVasu Dev * Returns: 0 for success 193955a66d3cSVasu Dev */ 194055a66d3cSVasu Dev static int fcoe_enable(const char *buffer, struct kernel_param *kp) 194155a66d3cSVasu Dev { 194255a66d3cSVasu Dev struct fcoe_interface *fcoe; 194355a66d3cSVasu Dev struct net_device *netdev; 194455a66d3cSVasu Dev int rc = 0; 194555a66d3cSVasu Dev 194655a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 194755a66d3cSVasu Dev #ifdef CONFIG_FCOE_MODULE 194855a66d3cSVasu Dev /* 194955a66d3cSVasu Dev * Make sure the module has been initialized, and is not about to be 195055a66d3cSVasu Dev * removed. Module paramter sysfs files are writable before the 195155a66d3cSVasu Dev * module_init function is called and after module_exit. 195255a66d3cSVasu Dev */ 195355a66d3cSVasu Dev if (THIS_MODULE->state != MODULE_STATE_LIVE) { 195455a66d3cSVasu Dev rc = -ENODEV; 195555a66d3cSVasu Dev goto out_nodev; 195655a66d3cSVasu Dev } 195755a66d3cSVasu Dev #endif 195855a66d3cSVasu Dev 195955a66d3cSVasu Dev netdev = fcoe_if_to_netdev(buffer); 196055a66d3cSVasu Dev if (!netdev) { 196155a66d3cSVasu Dev rc = -ENODEV; 196255a66d3cSVasu Dev goto out_nodev; 196355a66d3cSVasu Dev } 196455a66d3cSVasu Dev 196534ce27bcSVasu Dev if (!rtnl_trylock()) { 196634ce27bcSVasu Dev dev_put(netdev); 196734ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 196834ce27bcSVasu Dev return restart_syscall(); 196934ce27bcSVasu Dev } 197034ce27bcSVasu Dev 197155a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 197255a66d3cSVasu Dev rtnl_unlock(); 197355a66d3cSVasu Dev 19749ee50e48SChris Leech if (fcoe) { 19759ee50e48SChris Leech if (!fcoe_link_ok(fcoe->ctlr.lp)) 19769ee50e48SChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 197755a66d3cSVasu Dev rc = fc_fabric_login(fcoe->ctlr.lp); 19789ee50e48SChris Leech } else 197955a66d3cSVasu Dev rc = -ENODEV; 198055a66d3cSVasu Dev 198155a66d3cSVasu Dev dev_put(netdev); 198255a66d3cSVasu Dev out_nodev: 198355a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 198455a66d3cSVasu Dev return rc; 198555a66d3cSVasu Dev } 198655a66d3cSVasu Dev 198755a66d3cSVasu Dev /** 19881875f27eSRobert Love * fcoe_destroy() - Destroy a FCoE interface 19891875f27eSRobert Love * @buffer: The name of the Ethernet interface to be destroyed 19901875f27eSRobert Love * @kp: The associated kernel parameter 19911875f27eSRobert Love * 19921875f27eSRobert Love * Called from sysfs. 1993a703e490SVasu Dev * 1994a703e490SVasu Dev * Returns: 0 for success 1995a703e490SVasu Dev */ 1996a703e490SVasu Dev static int fcoe_destroy(const char *buffer, struct kernel_param *kp) 1997a703e490SVasu Dev { 1998030f4e00SChris Leech struct fcoe_interface *fcoe; 19992e70e241SChris Leech struct net_device *netdev; 20008eca355fSMike Christie int rc = 0; 2001a703e490SVasu Dev 2002dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2003dfc1d0feSChris Leech #ifdef CONFIG_FCOE_MODULE 2004dfc1d0feSChris Leech /* 2005dfc1d0feSChris Leech * Make sure the module has been initialized, and is not about to be 2006dfc1d0feSChris Leech * removed. Module paramter sysfs files are writable before the 2007dfc1d0feSChris Leech * module_init function is called and after module_exit. 2008dfc1d0feSChris Leech */ 2009dfc1d0feSChris Leech if (THIS_MODULE->state != MODULE_STATE_LIVE) { 2010dfc1d0feSChris Leech rc = -ENODEV; 2011dfc1d0feSChris Leech goto out_nodev; 2012dfc1d0feSChris Leech } 2013dfc1d0feSChris Leech #endif 2014dfc1d0feSChris Leech 2015a703e490SVasu Dev netdev = fcoe_if_to_netdev(buffer); 2016a703e490SVasu Dev if (!netdev) { 2017a703e490SVasu Dev rc = -ENODEV; 2018a703e490SVasu Dev goto out_nodev; 2019a703e490SVasu Dev } 20202e70e241SChris Leech 202134ce27bcSVasu Dev if (!rtnl_trylock()) { 202234ce27bcSVasu Dev dev_put(netdev); 202334ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 202434ce27bcSVasu Dev return restart_syscall(); 202534ce27bcSVasu Dev } 202634ce27bcSVasu Dev 20272e70e241SChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 20282e70e241SChris Leech if (!fcoe) { 2029090eb6c4SChris Leech rtnl_unlock(); 2030a703e490SVasu Dev rc = -ENODEV; 2031a703e490SVasu Dev goto out_putdev; 2032a703e490SVasu Dev } 20332e70e241SChris Leech list_del(&fcoe->list); 20342e70e241SChris Leech fcoe_interface_cleanup(fcoe); 203534ce27bcSVasu Dev /* RTNL mutex is dropped by fcoe_if_destroy */ 20362e70e241SChris Leech fcoe_if_destroy(fcoe->ctlr.lp); 20376409ea65SRob Love module_put(THIS_MODULE); 20386409ea65SRob Love 2039a703e490SVasu Dev out_putdev: 2040a703e490SVasu Dev dev_put(netdev); 2041a703e490SVasu Dev out_nodev: 2042dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2043a703e490SVasu Dev return rc; 2044a703e490SVasu Dev } 2045a703e490SVasu Dev 20461875f27eSRobert Love /** 20471875f27eSRobert Love * fcoe_destroy_work() - Destroy a FCoE port in a deferred work context 20481875f27eSRobert Love * @work: Handle to the FCoE port to be destroyed 20491875f27eSRobert Love */ 20502e70e241SChris Leech static void fcoe_destroy_work(struct work_struct *work) 20512e70e241SChris Leech { 20522e70e241SChris Leech struct fcoe_port *port; 20532e70e241SChris Leech 20542e70e241SChris Leech port = container_of(work, struct fcoe_port, destroy_work); 20552e70e241SChris Leech mutex_lock(&fcoe_config_mutex); 205634ce27bcSVasu Dev rtnl_lock(); 205734ce27bcSVasu Dev /* RTNL mutex is dropped by fcoe_if_destroy */ 20582e70e241SChris Leech fcoe_if_destroy(port->lport); 20592e70e241SChris Leech mutex_unlock(&fcoe_config_mutex); 20602e70e241SChris Leech } 20612e70e241SChris Leech 2062a703e490SVasu Dev /** 20631875f27eSRobert Love * fcoe_create() - Create a fcoe interface 20641875f27eSRobert Love * @buffer: The name of the Ethernet interface to create on 20651875f27eSRobert Love * @kp: The associated kernel param 20661875f27eSRobert Love * 20671875f27eSRobert Love * Called from sysfs. 2068a703e490SVasu Dev * 2069a703e490SVasu Dev * Returns: 0 for success 2070a703e490SVasu Dev */ 2071a703e490SVasu Dev static int fcoe_create(const char *buffer, struct kernel_param *kp) 2072a703e490SVasu Dev { 2073a703e490SVasu Dev int rc; 2074030f4e00SChris Leech struct fcoe_interface *fcoe; 2075af7f85d9SChris Leech struct fc_lport *lport; 2076a703e490SVasu Dev struct net_device *netdev; 2077a703e490SVasu Dev 2078dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 207934ce27bcSVasu Dev 208034ce27bcSVasu Dev if (!rtnl_trylock()) { 208134ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 208234ce27bcSVasu Dev return restart_syscall(); 208334ce27bcSVasu Dev } 208434ce27bcSVasu Dev 2085dfc1d0feSChris Leech #ifdef CONFIG_FCOE_MODULE 2086dfc1d0feSChris Leech /* 2087dfc1d0feSChris Leech * Make sure the module has been initialized, and is not about to be 2088dfc1d0feSChris Leech * removed. Module paramter sysfs files are writable before the 2089dfc1d0feSChris Leech * module_init function is called and after module_exit. 2090dfc1d0feSChris Leech */ 2091dfc1d0feSChris Leech if (THIS_MODULE->state != MODULE_STATE_LIVE) { 2092dfc1d0feSChris Leech rc = -ENODEV; 2093721cafafSVasu Dev goto out_nomod; 2094dfc1d0feSChris Leech } 2095dfc1d0feSChris Leech #endif 2096dfc1d0feSChris Leech 20976409ea65SRob Love if (!try_module_get(THIS_MODULE)) { 20986409ea65SRob Love rc = -EINVAL; 20996409ea65SRob Love goto out_nomod; 21006409ea65SRob Love } 21016409ea65SRob Love 2102a703e490SVasu Dev netdev = fcoe_if_to_netdev(buffer); 2103a703e490SVasu Dev if (!netdev) { 2104a703e490SVasu Dev rc = -ENODEV; 2105a703e490SVasu Dev goto out_nodev; 2106a703e490SVasu Dev } 21072e70e241SChris Leech 2108a703e490SVasu Dev /* look for existing lport */ 2109a703e490SVasu Dev if (fcoe_hostlist_lookup(netdev)) { 2110a703e490SVasu Dev rc = -EEXIST; 2111a703e490SVasu Dev goto out_putdev; 2112a703e490SVasu Dev } 2113a703e490SVasu Dev 2114030f4e00SChris Leech fcoe = fcoe_interface_create(netdev); 2115030f4e00SChris Leech if (!fcoe) { 2116030f4e00SChris Leech rc = -ENOMEM; 2117030f4e00SChris Leech goto out_putdev; 2118030f4e00SChris Leech } 2119030f4e00SChris Leech 21209a05753bSChris Leech lport = fcoe_if_create(fcoe, &netdev->dev, 0); 2121af7f85d9SChris Leech if (IS_ERR(lport)) { 2122d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to create interface (%s)\n", 2123a703e490SVasu Dev netdev->name); 2124a703e490SVasu Dev rc = -EIO; 21252e70e241SChris Leech fcoe_interface_cleanup(fcoe); 2126030f4e00SChris Leech goto out_free; 2127a703e490SVasu Dev } 2128030f4e00SChris Leech 212954b649f8SChris Leech /* Make this the "master" N_Port */ 213054b649f8SChris Leech fcoe->ctlr.lp = lport; 2131030f4e00SChris Leech 2132c863df33SChris Leech /* add to lports list */ 2133c863df33SChris Leech fcoe_hostlist_add(lport); 2134c863df33SChris Leech 213554b649f8SChris Leech /* start FIP Discovery and FLOGI */ 213654b649f8SChris Leech lport->boot_time = jiffies; 213754b649f8SChris Leech fc_fabric_login(lport); 213854b649f8SChris Leech if (!fcoe_link_ok(lport)) 213954b649f8SChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 214054b649f8SChris Leech 214154b649f8SChris Leech /* 214254b649f8SChris Leech * Release from init in fcoe_interface_create(), on success lport 214354b649f8SChris Leech * should be holding a reference taken in fcoe_if_create(). 214454b649f8SChris Leech */ 2145030f4e00SChris Leech fcoe_interface_put(fcoe); 21466409ea65SRob Love dev_put(netdev); 21476409ea65SRob Love rtnl_unlock(); 21486409ea65SRob Love mutex_unlock(&fcoe_config_mutex); 21496409ea65SRob Love 21506409ea65SRob Love return 0; 21516409ea65SRob Love out_free: 21526409ea65SRob Love fcoe_interface_put(fcoe); 2153a703e490SVasu Dev out_putdev: 2154a703e490SVasu Dev dev_put(netdev); 2155a703e490SVasu Dev out_nodev: 21566409ea65SRob Love module_put(THIS_MODULE); 21576409ea65SRob Love out_nomod: 215834ce27bcSVasu Dev rtnl_unlock(); 2159dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2160a703e490SVasu Dev return rc; 2161a703e490SVasu Dev } 2162a703e490SVasu Dev 2163a703e490SVasu Dev /** 21645e4f8fe7SRobert Love * fcoe_link_speed_update() - Update the supported and actual link speeds 21655e4f8fe7SRobert Love * @lport: The local port to update speeds for 2166a703e490SVasu Dev * 21675e4f8fe7SRobert Love * Returns: 0 if the ethtool query was successful 21685e4f8fe7SRobert Love * -1 if the ethtool query failed 2169a703e490SVasu Dev */ 21705e4f8fe7SRobert Love int fcoe_link_speed_update(struct fc_lport *lport) 2171a703e490SVasu Dev { 21721875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 21731875f27eSRobert Love struct net_device *netdev = port->fcoe->netdev; 2174a703e490SVasu Dev struct ethtool_cmd ecmd = { ETHTOOL_GSET }; 2175a703e490SVasu Dev 21765e4f8fe7SRobert Love if (!dev_ethtool_get_settings(netdev, &ecmd)) { 21771875f27eSRobert Love lport->link_supported_speeds &= 2178a703e490SVasu Dev ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT); 2179a703e490SVasu Dev if (ecmd.supported & (SUPPORTED_1000baseT_Half | 2180a703e490SVasu Dev SUPPORTED_1000baseT_Full)) 21811875f27eSRobert Love lport->link_supported_speeds |= FC_PORTSPEED_1GBIT; 2182a703e490SVasu Dev if (ecmd.supported & SUPPORTED_10000baseT_Full) 21831875f27eSRobert Love lport->link_supported_speeds |= 2184a703e490SVasu Dev FC_PORTSPEED_10GBIT; 2185a703e490SVasu Dev if (ecmd.speed == SPEED_1000) 21861875f27eSRobert Love lport->link_speed = FC_PORTSPEED_1GBIT; 2187a703e490SVasu Dev if (ecmd.speed == SPEED_10000) 21881875f27eSRobert Love lport->link_speed = FC_PORTSPEED_10GBIT; 2189a703e490SVasu Dev 21902f718d64SYi Zou return 0; 21912f718d64SYi Zou } 21922f718d64SYi Zou return -1; 2193a703e490SVasu Dev } 2194a703e490SVasu Dev 2195a703e490SVasu Dev /** 21965e4f8fe7SRobert Love * fcoe_link_ok() - Check if the link is OK for a local port 21975e4f8fe7SRobert Love * @lport: The local port to check link on 21985e4f8fe7SRobert Love * 21995e4f8fe7SRobert Love * Returns: 0 if link is UP and OK, -1 if not 22005e4f8fe7SRobert Love * 22015e4f8fe7SRobert Love */ 22025e4f8fe7SRobert Love int fcoe_link_ok(struct fc_lport *lport) 22035e4f8fe7SRobert Love { 22045e4f8fe7SRobert Love struct fcoe_port *port = lport_priv(lport); 22055e4f8fe7SRobert Love struct net_device *netdev = port->fcoe->netdev; 22065e4f8fe7SRobert Love 22075e4f8fe7SRobert Love if (netif_oper_up(netdev)) 22085e4f8fe7SRobert Love return 0; 22095e4f8fe7SRobert Love return -1; 22105e4f8fe7SRobert Love } 22115e4f8fe7SRobert Love 22125e4f8fe7SRobert Love /** 22131875f27eSRobert Love * fcoe_percpu_clean() - Clear all pending skbs for an local port 22141875f27eSRobert Love * @lport: The local port whose skbs are to be cleared 2215e7a51997SJoe Eykholt * 2216e7a51997SJoe Eykholt * Must be called with fcoe_create_mutex held to single-thread completion. 2217e7a51997SJoe Eykholt * 2218e7a51997SJoe Eykholt * This flushes the pending skbs by adding a new skb to each queue and 2219e7a51997SJoe Eykholt * waiting until they are all freed. This assures us that not only are 2220e7a51997SJoe Eykholt * there no packets that will be handled by the lport, but also that any 2221e7a51997SJoe Eykholt * threads already handling packet have returned. 2222a703e490SVasu Dev */ 22231875f27eSRobert Love void fcoe_percpu_clean(struct fc_lport *lport) 2224a703e490SVasu Dev { 2225a703e490SVasu Dev struct fcoe_percpu_s *pp; 2226a703e490SVasu Dev struct fcoe_rcv_info *fr; 2227a703e490SVasu Dev struct sk_buff_head *list; 2228a703e490SVasu Dev struct sk_buff *skb, *next; 2229a703e490SVasu Dev struct sk_buff *head; 2230a703e490SVasu Dev unsigned int cpu; 2231a703e490SVasu Dev 2232a703e490SVasu Dev for_each_possible_cpu(cpu) { 2233a703e490SVasu Dev pp = &per_cpu(fcoe_percpu, cpu); 2234a703e490SVasu Dev spin_lock_bh(&pp->fcoe_rx_list.lock); 2235a703e490SVasu Dev list = &pp->fcoe_rx_list; 2236a703e490SVasu Dev head = list->next; 2237a703e490SVasu Dev for (skb = head; skb != (struct sk_buff *)list; 2238a703e490SVasu Dev skb = next) { 2239a703e490SVasu Dev next = skb->next; 2240a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 22411875f27eSRobert Love if (fr->fr_dev == lport) { 2242a703e490SVasu Dev __skb_unlink(skb, list); 2243a703e490SVasu Dev kfree_skb(skb); 2244a703e490SVasu Dev } 2245a703e490SVasu Dev } 2246e7a51997SJoe Eykholt 2247e7a51997SJoe Eykholt if (!pp->thread || !cpu_online(cpu)) { 2248a703e490SVasu Dev spin_unlock_bh(&pp->fcoe_rx_list.lock); 2249e7a51997SJoe Eykholt continue; 2250e7a51997SJoe Eykholt } 2251e7a51997SJoe Eykholt 2252e7a51997SJoe Eykholt skb = dev_alloc_skb(0); 2253e7a51997SJoe Eykholt if (!skb) { 2254e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2255e7a51997SJoe Eykholt continue; 2256e7a51997SJoe Eykholt } 2257e7a51997SJoe Eykholt skb->destructor = fcoe_percpu_flush_done; 2258e7a51997SJoe Eykholt 2259e7a51997SJoe Eykholt __skb_queue_tail(&pp->fcoe_rx_list, skb); 2260e7a51997SJoe Eykholt if (pp->fcoe_rx_list.qlen == 1) 2261e7a51997SJoe Eykholt wake_up_process(pp->thread); 2262e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2263e7a51997SJoe Eykholt 2264e7a51997SJoe Eykholt wait_for_completion(&fcoe_flush_completion); 2265a703e490SVasu Dev } 2266a703e490SVasu Dev } 2267a703e490SVasu Dev 2268a703e490SVasu Dev /** 2269a703e490SVasu Dev * fcoe_clean_pending_queue() - Dequeue a skb and free it 22701875f27eSRobert Love * @lport: The local port to dequeue a skb on 2271a703e490SVasu Dev */ 22721875f27eSRobert Love void fcoe_clean_pending_queue(struct fc_lport *lport) 2273a703e490SVasu Dev { 22741875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 2275a703e490SVasu Dev struct sk_buff *skb; 2276a703e490SVasu Dev 2277014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 2278014f5c3fSChris Leech while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) { 2279014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 2280a703e490SVasu Dev kfree_skb(skb); 2281014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 2282a703e490SVasu Dev } 2283014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 2284a703e490SVasu Dev } 2285a703e490SVasu Dev 2286a703e490SVasu Dev /** 22871875f27eSRobert Love * fcoe_reset() - Reset a local port 22881875f27eSRobert Love * @shost: The SCSI host associated with the local port to be reset 2289a703e490SVasu Dev * 22901875f27eSRobert Love * Returns: Always 0 (return value required by FC transport template) 2291a703e490SVasu Dev */ 2292a703e490SVasu Dev int fcoe_reset(struct Scsi_Host *shost) 2293a703e490SVasu Dev { 2294a703e490SVasu Dev struct fc_lport *lport = shost_priv(shost); 2295a703e490SVasu Dev fc_lport_reset(lport); 2296a703e490SVasu Dev return 0; 2297a703e490SVasu Dev } 2298a703e490SVasu Dev 2299a703e490SVasu Dev /** 23001875f27eSRobert Love * fcoe_hostlist_lookup_port() - Find the FCoE interface associated with a net device 23011875f27eSRobert Love * @netdev: The net device used as a key 2302a703e490SVasu Dev * 23031875f27eSRobert Love * Locking: Must be called with the RNL mutex held. 23041875f27eSRobert Love * 23051875f27eSRobert Love * Returns: NULL or the FCoE interface 2306a703e490SVasu Dev */ 2307014f5c3fSChris Leech static struct fcoe_interface * 23081875f27eSRobert Love fcoe_hostlist_lookup_port(const struct net_device *netdev) 2309a703e490SVasu Dev { 2310014f5c3fSChris Leech struct fcoe_interface *fcoe; 2311a703e490SVasu Dev 2312014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 23131875f27eSRobert Love if (fcoe->netdev == netdev) 2314014f5c3fSChris Leech return fcoe; 2315a703e490SVasu Dev } 2316a703e490SVasu Dev return NULL; 2317a703e490SVasu Dev } 2318a703e490SVasu Dev 2319a703e490SVasu Dev /** 23201875f27eSRobert Love * fcoe_hostlist_lookup() - Find the local port associated with a 23211875f27eSRobert Love * given net device 23221875f27eSRobert Love * @netdev: The netdevice used as a key 2323a703e490SVasu Dev * 23241875f27eSRobert Love * Locking: Must be called with the RTNL mutex held 23251875f27eSRobert Love * 23261875f27eSRobert Love * Returns: NULL or the local port 2327a703e490SVasu Dev */ 2328090eb6c4SChris Leech static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev) 2329a703e490SVasu Dev { 2330014f5c3fSChris Leech struct fcoe_interface *fcoe; 2331a703e490SVasu Dev 2332014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 23333fe9a0baSChris Leech return (fcoe) ? fcoe->ctlr.lp : NULL; 2334a703e490SVasu Dev } 2335a703e490SVasu Dev 2336a703e490SVasu Dev /** 23371875f27eSRobert Love * fcoe_hostlist_add() - Add the FCoE interface identified by a local 23381875f27eSRobert Love * port to the hostlist 23391875f27eSRobert Love * @lport: The local port that identifies the FCoE interface to be added 23401875f27eSRobert Love * 23411875f27eSRobert Love * Locking: must be called with the RTNL mutex held 2342a703e490SVasu Dev * 2343a703e490SVasu Dev * Returns: 0 for success 2344a703e490SVasu Dev */ 2345090eb6c4SChris Leech static int fcoe_hostlist_add(const struct fc_lport *lport) 2346a703e490SVasu Dev { 2347014f5c3fSChris Leech struct fcoe_interface *fcoe; 2348014f5c3fSChris Leech struct fcoe_port *port; 2349a703e490SVasu Dev 2350014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport)); 2351014f5c3fSChris Leech if (!fcoe) { 2352014f5c3fSChris Leech port = lport_priv(lport); 2353014f5c3fSChris Leech fcoe = port->fcoe; 2354014f5c3fSChris Leech list_add_tail(&fcoe->list, &fcoe_hostlist); 2355a703e490SVasu Dev } 2356a703e490SVasu Dev return 0; 2357a703e490SVasu Dev } 2358a703e490SVasu Dev 2359a703e490SVasu Dev /** 23601875f27eSRobert Love * fcoe_init() - Initialize fcoe.ko 2361a703e490SVasu Dev * 23621875f27eSRobert Love * Returns: 0 on success, or a negative value on failure 2363a703e490SVasu Dev */ 2364a703e490SVasu Dev static int __init fcoe_init(void) 2365a703e490SVasu Dev { 23661875f27eSRobert Love struct fcoe_percpu_s *p; 2367a703e490SVasu Dev unsigned int cpu; 2368a703e490SVasu Dev int rc = 0; 2369a703e490SVasu Dev 2370dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2371dfc1d0feSChris Leech 2372a703e490SVasu Dev for_each_possible_cpu(cpu) { 2373a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 2374a703e490SVasu Dev skb_queue_head_init(&p->fcoe_rx_list); 2375a703e490SVasu Dev } 2376a703e490SVasu Dev 2377a703e490SVasu Dev for_each_online_cpu(cpu) 2378a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 2379a703e490SVasu Dev 2380a703e490SVasu Dev /* Initialize per CPU interrupt thread */ 2381a703e490SVasu Dev rc = register_hotcpu_notifier(&fcoe_cpu_notifier); 2382a703e490SVasu Dev if (rc) 2383a703e490SVasu Dev goto out_free; 2384a703e490SVasu Dev 2385a703e490SVasu Dev /* Setup link change notification */ 2386a703e490SVasu Dev fcoe_dev_setup(); 2387a703e490SVasu Dev 23885892c32fSChris Leech rc = fcoe_if_init(); 23895892c32fSChris Leech if (rc) 23905892c32fSChris Leech goto out_free; 2391a703e490SVasu Dev 2392dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2393a703e490SVasu Dev return 0; 2394a703e490SVasu Dev 2395a703e490SVasu Dev out_free: 2396a703e490SVasu Dev for_each_online_cpu(cpu) { 2397a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2398a703e490SVasu Dev } 2399dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2400a703e490SVasu Dev return rc; 2401a703e490SVasu Dev } 2402a703e490SVasu Dev module_init(fcoe_init); 2403a703e490SVasu Dev 2404a703e490SVasu Dev /** 24051875f27eSRobert Love * fcoe_exit() - Clean up fcoe.ko 2406a703e490SVasu Dev * 24071875f27eSRobert Love * Returns: 0 on success or a negative value on failure 2408a703e490SVasu Dev */ 2409a703e490SVasu Dev static void __exit fcoe_exit(void) 2410a703e490SVasu Dev { 2411014f5c3fSChris Leech struct fcoe_interface *fcoe, *tmp; 24122e70e241SChris Leech struct fcoe_port *port; 24131875f27eSRobert Love unsigned int cpu; 2414a703e490SVasu Dev 2415dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2416dfc1d0feSChris Leech 2417a703e490SVasu Dev fcoe_dev_cleanup(); 2418a703e490SVasu Dev 2419a703e490SVasu Dev /* releases the associated fcoe hosts */ 2420090eb6c4SChris Leech rtnl_lock(); 2421090eb6c4SChris Leech list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) { 2422c863df33SChris Leech list_del(&fcoe->list); 24232e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 24242e70e241SChris Leech fcoe_interface_cleanup(fcoe); 24252e70e241SChris Leech schedule_work(&port->destroy_work); 2426c863df33SChris Leech } 2427090eb6c4SChris Leech rtnl_unlock(); 2428a703e490SVasu Dev 2429a703e490SVasu Dev unregister_hotcpu_notifier(&fcoe_cpu_notifier); 2430a703e490SVasu Dev 2431014f5c3fSChris Leech for_each_online_cpu(cpu) 2432a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2433a703e490SVasu Dev 2434dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 24352e70e241SChris Leech 24362e70e241SChris Leech /* flush any asyncronous interface destroys, 24372e70e241SChris Leech * this should happen after the netdev notifier is unregistered */ 24382e70e241SChris Leech flush_scheduled_work(); 24399a05753bSChris Leech /* That will flush out all the N_Ports on the hostlist, but now we 24409a05753bSChris Leech * may have NPIV VN_Ports scheduled for destruction */ 24419a05753bSChris Leech flush_scheduled_work(); 24422e70e241SChris Leech 24432e70e241SChris Leech /* detach from scsi transport 24442e70e241SChris Leech * must happen after all destroys are done, therefor after the flush */ 24452e70e241SChris Leech fcoe_if_exit(); 2446a703e490SVasu Dev } 2447a703e490SVasu Dev module_exit(fcoe_exit); 244811b56188SChris Leech 244911b56188SChris Leech /** 245011b56188SChris Leech * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler 245111b56188SChris Leech * @seq: active sequence in the FLOGI or FDISC exchange 245211b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 245311b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 245411b56188SChris Leech * 245511b56188SChris Leech * This handles MAC address managment for FCoE, then passes control on to 245611b56188SChris Leech * the libfc FLOGI response handler. 245711b56188SChris Leech */ 245811b56188SChris Leech static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 245911b56188SChris Leech { 246011b56188SChris Leech struct fcoe_ctlr *fip = arg; 246111b56188SChris Leech struct fc_exch *exch = fc_seq_exch(seq); 246211b56188SChris Leech struct fc_lport *lport = exch->lp; 246311b56188SChris Leech u8 *mac; 246411b56188SChris Leech 246511b56188SChris Leech if (IS_ERR(fp)) 246611b56188SChris Leech goto done; 246711b56188SChris Leech 246811b56188SChris Leech mac = fr_cb(fp)->granted_mac; 246911b56188SChris Leech if (is_zero_ether_addr(mac)) { 247011b56188SChris Leech /* pre-FIP */ 2471386309ceSJoe Eykholt if (fcoe_ctlr_recv_flogi(fip, lport, fp)) { 247211b56188SChris Leech fc_frame_free(fp); 247311b56188SChris Leech return; 247411b56188SChris Leech } 247511b56188SChris Leech } 2476386309ceSJoe Eykholt fcoe_update_src_mac(lport, mac); 247711b56188SChris Leech done: 247811b56188SChris Leech fc_lport_flogi_resp(seq, fp, lport); 247911b56188SChris Leech } 248011b56188SChris Leech 248111b56188SChris Leech /** 248211b56188SChris Leech * fcoe_logo_resp() - FCoE specific LOGO response handler 248311b56188SChris Leech * @seq: active sequence in the LOGO exchange 248411b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 248511b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 248611b56188SChris Leech * 248711b56188SChris Leech * This handles MAC address managment for FCoE, then passes control on to 248811b56188SChris Leech * the libfc LOGO response handler. 248911b56188SChris Leech */ 249011b56188SChris Leech static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 249111b56188SChris Leech { 2492386309ceSJoe Eykholt struct fc_lport *lport = arg; 249311b56188SChris Leech static u8 zero_mac[ETH_ALEN] = { 0 }; 249411b56188SChris Leech 249511b56188SChris Leech if (!IS_ERR(fp)) 2496386309ceSJoe Eykholt fcoe_update_src_mac(lport, zero_mac); 249711b56188SChris Leech fc_lport_logo_resp(seq, fp, lport); 249811b56188SChris Leech } 249911b56188SChris Leech 250011b56188SChris Leech /** 250111b56188SChris Leech * fcoe_elsct_send - FCoE specific ELS handler 250211b56188SChris Leech * 250311b56188SChris Leech * This does special case handling of FIP encapsualted ELS exchanges for FCoE, 250411b56188SChris Leech * using FCoE specific response handlers and passing the FIP controller as 250511b56188SChris Leech * the argument (the lport is still available from the exchange). 250611b56188SChris Leech * 250711b56188SChris Leech * Most of the work here is just handed off to the libfc routine. 250811b56188SChris Leech */ 25091875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did, 25101875f27eSRobert Love struct fc_frame *fp, unsigned int op, 25111875f27eSRobert Love void (*resp)(struct fc_seq *, 25121875f27eSRobert Love struct fc_frame *, 25131875f27eSRobert Love void *), 251411b56188SChris Leech void *arg, u32 timeout) 251511b56188SChris Leech { 251611b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 251711b56188SChris Leech struct fcoe_interface *fcoe = port->fcoe; 251811b56188SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 251911b56188SChris Leech struct fc_frame_header *fh = fc_frame_header_get(fp); 252011b56188SChris Leech 252111b56188SChris Leech switch (op) { 252211b56188SChris Leech case ELS_FLOGI: 252311b56188SChris Leech case ELS_FDISC: 252411b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp, 252511b56188SChris Leech fip, timeout); 252611b56188SChris Leech case ELS_LOGO: 252711b56188SChris Leech /* only hook onto fabric logouts, not port logouts */ 252811b56188SChris Leech if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) 252911b56188SChris Leech break; 253011b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp, 2531386309ceSJoe Eykholt lport, timeout); 253211b56188SChris Leech } 253311b56188SChris Leech return fc_elsct_send(lport, did, fp, op, resp, arg, timeout); 253411b56188SChris Leech } 253511b56188SChris Leech 25369a05753bSChris Leech /** 25379a05753bSChris Leech * fcoe_vport_create() - create an fc_host/scsi_host for a vport 25389a05753bSChris Leech * @vport: fc_vport object to create a new fc_host for 25399a05753bSChris Leech * @disabled: start the new fc_host in a disabled state by default? 25409a05753bSChris Leech * 25419a05753bSChris Leech * Returns: 0 for success 25429a05753bSChris Leech */ 25439a05753bSChris Leech static int fcoe_vport_create(struct fc_vport *vport, bool disabled) 25449a05753bSChris Leech { 25459a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 25469a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 25479a05753bSChris Leech struct fcoe_port *port = lport_priv(n_port); 25489a05753bSChris Leech struct fcoe_interface *fcoe = port->fcoe; 25499a05753bSChris Leech struct net_device *netdev = fcoe->netdev; 25509a05753bSChris Leech struct fc_lport *vn_port; 25519a05753bSChris Leech 25529a05753bSChris Leech mutex_lock(&fcoe_config_mutex); 25539a05753bSChris Leech vn_port = fcoe_if_create(fcoe, &vport->dev, 1); 25549a05753bSChris Leech mutex_unlock(&fcoe_config_mutex); 25559a05753bSChris Leech 25569a05753bSChris Leech if (IS_ERR(vn_port)) { 25579a05753bSChris Leech printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n", 25589a05753bSChris Leech netdev->name); 25599a05753bSChris Leech return -EIO; 25609a05753bSChris Leech } 25619a05753bSChris Leech 25629a05753bSChris Leech if (disabled) { 25639a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 25649a05753bSChris Leech } else { 25659a05753bSChris Leech vn_port->boot_time = jiffies; 25669a05753bSChris Leech fc_fabric_login(vn_port); 25679a05753bSChris Leech fc_vport_setlink(vn_port); 25689a05753bSChris Leech } 25699a05753bSChris Leech return 0; 25709a05753bSChris Leech } 25719a05753bSChris Leech 25729a05753bSChris Leech /** 25739a05753bSChris Leech * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport 25749a05753bSChris Leech * @vport: fc_vport object that is being destroyed 25759a05753bSChris Leech * 25769a05753bSChris Leech * Returns: 0 for success 25779a05753bSChris Leech */ 25789a05753bSChris Leech static int fcoe_vport_destroy(struct fc_vport *vport) 25799a05753bSChris Leech { 25809a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 25819a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 25829a05753bSChris Leech struct fc_lport *vn_port = vport->dd_data; 25839a05753bSChris Leech struct fcoe_port *port = lport_priv(vn_port); 25849a05753bSChris Leech 25859a05753bSChris Leech mutex_lock(&n_port->lp_mutex); 25869a05753bSChris Leech list_del(&vn_port->list); 25879a05753bSChris Leech mutex_unlock(&n_port->lp_mutex); 25889a05753bSChris Leech schedule_work(&port->destroy_work); 25899a05753bSChris Leech return 0; 25909a05753bSChris Leech } 25919a05753bSChris Leech 25929a05753bSChris Leech /** 25939a05753bSChris Leech * fcoe_vport_disable() - change vport state 25949a05753bSChris Leech * @vport: vport to bring online/offline 25959a05753bSChris Leech * @disable: should the vport be disabled? 25969a05753bSChris Leech */ 25979a05753bSChris Leech static int fcoe_vport_disable(struct fc_vport *vport, bool disable) 25989a05753bSChris Leech { 25999a05753bSChris Leech struct fc_lport *lport = vport->dd_data; 26009a05753bSChris Leech 26019a05753bSChris Leech if (disable) { 26029a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 26039a05753bSChris Leech fc_fabric_logoff(lport); 26049a05753bSChris Leech } else { 26059a05753bSChris Leech lport->boot_time = jiffies; 26069a05753bSChris Leech fc_fabric_login(lport); 26079a05753bSChris Leech fc_vport_setlink(lport); 26089a05753bSChris Leech } 26099a05753bSChris Leech 26109a05753bSChris Leech return 0; 26119a05753bSChris Leech } 26129a05753bSChris Leech 2613dc8596d3SChris Leech /** 2614dc8596d3SChris Leech * fcoe_vport_set_symbolic_name() - append vport string to symbolic name 2615dc8596d3SChris Leech * @vport: fc_vport with a new symbolic name string 2616dc8596d3SChris Leech * 2617dc8596d3SChris Leech * After generating a new symbolic name string, a new RSPN_ID request is 2618dc8596d3SChris Leech * sent to the name server. There is no response handler, so if it fails 2619dc8596d3SChris Leech * for some reason it will not be retried. 2620dc8596d3SChris Leech */ 2621dc8596d3SChris Leech static void fcoe_set_vport_symbolic_name(struct fc_vport *vport) 2622dc8596d3SChris Leech { 2623dc8596d3SChris Leech struct fc_lport *lport = vport->dd_data; 2624dc8596d3SChris Leech struct fc_frame *fp; 2625dc8596d3SChris Leech size_t len; 2626dc8596d3SChris Leech 2627dc8596d3SChris Leech snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 2628dc8596d3SChris Leech "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION, 2629dc8596d3SChris Leech fcoe_netdev(lport)->name, vport->symbolic_name); 2630dc8596d3SChris Leech 2631dc8596d3SChris Leech if (lport->state != LPORT_ST_READY) 2632dc8596d3SChris Leech return; 2633dc8596d3SChris Leech 2634dc8596d3SChris Leech len = strnlen(fc_host_symbolic_name(lport->host), 255); 2635dc8596d3SChris Leech fp = fc_frame_alloc(lport, 2636dc8596d3SChris Leech sizeof(struct fc_ct_hdr) + 2637dc8596d3SChris Leech sizeof(struct fc_ns_rspn) + len); 2638dc8596d3SChris Leech if (!fp) 2639dc8596d3SChris Leech return; 2640dc8596d3SChris Leech lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID, 2641b94f8951SJoe Eykholt NULL, NULL, 3 * lport->r_a_tov); 2642dc8596d3SChris Leech } 2643b84056bfSYi Zou 2644b84056bfSYi Zou /** 2645b84056bfSYi Zou * fcoe_get_lesb() - Fill the FCoE Link Error Status Block 2646b84056bfSYi Zou * @lport: the local port 2647b84056bfSYi Zou * @fc_lesb: the link error status block 2648b84056bfSYi Zou */ 2649b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *lport, 2650b84056bfSYi Zou struct fc_els_lesb *fc_lesb) 2651b84056bfSYi Zou { 2652b84056bfSYi Zou unsigned int cpu; 2653b84056bfSYi Zou u32 lfc, vlfc, mdac; 2654b84056bfSYi Zou struct fcoe_dev_stats *devst; 2655b84056bfSYi Zou struct fcoe_fc_els_lesb *lesb; 2656b84056bfSYi Zou struct net_device *netdev = fcoe_netdev(lport); 2657b84056bfSYi Zou 2658b84056bfSYi Zou lfc = 0; 2659b84056bfSYi Zou vlfc = 0; 2660b84056bfSYi Zou mdac = 0; 2661b84056bfSYi Zou lesb = (struct fcoe_fc_els_lesb *)fc_lesb; 2662b84056bfSYi Zou memset(lesb, 0, sizeof(*lesb)); 2663b84056bfSYi Zou for_each_possible_cpu(cpu) { 2664b84056bfSYi Zou devst = per_cpu_ptr(lport->dev_stats, cpu); 2665b84056bfSYi Zou lfc += devst->LinkFailureCount; 2666b84056bfSYi Zou vlfc += devst->VLinkFailureCount; 2667b84056bfSYi Zou mdac += devst->MissDiscAdvCount; 2668b84056bfSYi Zou } 2669b84056bfSYi Zou lesb->lesb_link_fail = htonl(lfc); 2670b84056bfSYi Zou lesb->lesb_vlink_fail = htonl(vlfc); 2671b84056bfSYi Zou lesb->lesb_miss_fka = htonl(mdac); 2672b84056bfSYi Zou lesb->lesb_fcs_error = htonl(dev_get_stats(netdev)->rx_crc_errors); 2673b84056bfSYi Zou } 26747d65b0dfSJoe Eykholt 26757d65b0dfSJoe Eykholt /** 26767d65b0dfSJoe Eykholt * fcoe_set_port_id() - Callback from libfc when Port_ID is set. 26777d65b0dfSJoe Eykholt * @lport: the local port 26787d65b0dfSJoe Eykholt * @port_id: the port ID 26797d65b0dfSJoe Eykholt * @fp: the received frame, if any, that caused the port_id to be set. 26807d65b0dfSJoe Eykholt * 26817d65b0dfSJoe Eykholt * This routine handles the case where we received a FLOGI and are 26827d65b0dfSJoe Eykholt * entering point-to-point mode. We need to call fcoe_ctlr_recv_flogi() 26837d65b0dfSJoe Eykholt * so it can set the non-mapped mode and gateway address. 26847d65b0dfSJoe Eykholt * 26857d65b0dfSJoe Eykholt * The FLOGI LS_ACC is handled by fcoe_flogi_resp(). 26867d65b0dfSJoe Eykholt */ 26877d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *lport, 26887d65b0dfSJoe Eykholt u32 port_id, struct fc_frame *fp) 26897d65b0dfSJoe Eykholt { 26907d65b0dfSJoe Eykholt struct fcoe_port *port = lport_priv(lport); 26917d65b0dfSJoe Eykholt struct fcoe_interface *fcoe = port->fcoe; 26927d65b0dfSJoe Eykholt 26937d65b0dfSJoe Eykholt if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) 26947d65b0dfSJoe Eykholt fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp); 26957d65b0dfSJoe Eykholt } 2696