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> 342ca32b48STejun Heo #include <linux/workqueue.h> 35a703e490SVasu Dev #include <scsi/scsi_tcq.h> 36a703e490SVasu Dev #include <scsi/scsicam.h> 37a703e490SVasu Dev #include <scsi/scsi_transport.h> 38a703e490SVasu Dev #include <scsi/scsi_transport_fc.h> 39a703e490SVasu Dev #include <net/rtnetlink.h> 40a703e490SVasu Dev 41a703e490SVasu Dev #include <scsi/fc/fc_encaps.h> 4297c8389dSJoe Eykholt #include <scsi/fc/fc_fip.h> 43a703e490SVasu Dev 44a703e490SVasu Dev #include <scsi/libfc.h> 45a703e490SVasu Dev #include <scsi/fc_frame.h> 46a703e490SVasu Dev #include <scsi/libfcoe.h> 47a703e490SVasu Dev 48fdd78027SVasu Dev #include "fcoe.h" 49fdd78027SVasu Dev 50a703e490SVasu Dev MODULE_AUTHOR("Open-FCoE.org"); 51a703e490SVasu Dev MODULE_DESCRIPTION("FCoE"); 529b34ecffSVasu Dev MODULE_LICENSE("GPL v2"); 53a703e490SVasu Dev 5405cc7390SYi Zou /* Performance tuning parameters for fcoe */ 55860eca2bSVasu Dev static unsigned int fcoe_ddp_min = 4096; 5605cc7390SYi Zou module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR); 5705cc7390SYi Zou MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \ 5805cc7390SYi Zou "Direct Data Placement (DDP)."); 5905cc7390SYi Zou 60dfc1d0feSChris Leech DEFINE_MUTEX(fcoe_config_mutex); 61dfc1d0feSChris Leech 622ca32b48STejun Heo static struct workqueue_struct *fcoe_wq; 632ca32b48STejun Heo 64e7a51997SJoe Eykholt /* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */ 65e7a51997SJoe Eykholt static DECLARE_COMPLETION(fcoe_flush_completion); 66e7a51997SJoe Eykholt 67a703e490SVasu Dev /* fcoe host list */ 68090eb6c4SChris Leech /* must only by accessed under the RTNL mutex */ 69a703e490SVasu Dev LIST_HEAD(fcoe_hostlist); 70a703e490SVasu Dev DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu); 71a703e490SVasu Dev 72dd3fd72eSChris Leech /* Function Prototypes */ 731875f27eSRobert Love static int fcoe_reset(struct Scsi_Host *); 74fdd78027SVasu Dev static int fcoe_xmit(struct fc_lport *, struct fc_frame *); 75fdd78027SVasu Dev static int fcoe_rcv(struct sk_buff *, struct net_device *, 76fdd78027SVasu Dev struct packet_type *, struct net_device *); 771875f27eSRobert Love static int fcoe_percpu_receive_thread(void *); 781875f27eSRobert Love static void fcoe_percpu_clean(struct fc_lport *); 795e4f8fe7SRobert Love static int fcoe_link_speed_update(struct fc_lport *); 801875f27eSRobert Love static int fcoe_link_ok(struct fc_lport *); 81fdd78027SVasu Dev 82fdd78027SVasu Dev static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *); 83fdd78027SVasu Dev static int fcoe_hostlist_add(const struct fc_lport *); 84fdd78027SVasu Dev 85a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *, ulong, void *); 86a703e490SVasu Dev static void fcoe_dev_setup(void); 87a703e490SVasu Dev static void fcoe_dev_cleanup(void); 881875f27eSRobert Love static struct fcoe_interface 891875f27eSRobert Love *fcoe_hostlist_lookup_port(const struct net_device *); 90a703e490SVasu Dev 911875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *, struct net_device *, 921875f27eSRobert Love struct packet_type *, struct net_device *); 931875f27eSRobert Love 941875f27eSRobert Love static void fcoe_fip_send(struct fcoe_ctlr *, struct sk_buff *); 951875f27eSRobert Love static void fcoe_update_src_mac(struct fc_lport *, u8 *); 961875f27eSRobert Love static u8 *fcoe_get_src_mac(struct fc_lport *); 971875f27eSRobert Love static void fcoe_destroy_work(struct work_struct *); 981875f27eSRobert Love 991875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *, 1001875f27eSRobert Love unsigned int); 1011875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *, u16); 10271f89491SYi Zou static int fcoe_ddp_target(struct fc_lport *, u16, struct scatterlist *, 10371f89491SYi Zou unsigned int); 1041875f27eSRobert Love static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *); 1051875f27eSRobert Love 10678a58246SYi Zou static bool fcoe_match(struct net_device *netdev); 10778a58246SYi Zou static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode); 10878a58246SYi Zou static int fcoe_destroy(struct net_device *netdev); 10978a58246SYi Zou static int fcoe_enable(struct net_device *netdev); 11078a58246SYi Zou static int fcoe_disable(struct net_device *netdev); 1111875f27eSRobert Love 1121875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *, 1131875f27eSRobert Love u32 did, struct fc_frame *, 1141875f27eSRobert Love unsigned int op, 1151875f27eSRobert Love void (*resp)(struct fc_seq *, 1161875f27eSRobert Love struct fc_frame *, 1171875f27eSRobert Love void *), 1181875f27eSRobert Love void *, u32 timeout); 119859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb); 1201875f27eSRobert Love 121b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *); 122b84056bfSYi Zou 1231875f27eSRobert Love /* notification function for packets from net device */ 124a703e490SVasu Dev static struct notifier_block fcoe_notifier = { 125a703e490SVasu Dev .notifier_call = fcoe_device_notification, 126a703e490SVasu Dev }; 127a703e490SVasu Dev 1281875f27eSRobert Love /* notification function for CPU hotplug events */ 1291875f27eSRobert Love static struct notifier_block fcoe_cpu_notifier = { 1301875f27eSRobert Love .notifier_call = fcoe_cpu_callback, 1311875f27eSRobert Love }; 1321875f27eSRobert Love 1338ca86f84SYi Zou static struct scsi_transport_template *fcoe_nport_scsi_transport; 1348ca86f84SYi Zou static struct scsi_transport_template *fcoe_vport_scsi_transport; 135a703e490SVasu Dev 1361875f27eSRobert Love static int fcoe_vport_destroy(struct fc_vport *); 1371875f27eSRobert Love static int fcoe_vport_create(struct fc_vport *, bool disabled); 1381875f27eSRobert Love static int fcoe_vport_disable(struct fc_vport *, bool disable); 1391875f27eSRobert Love static void fcoe_set_vport_symbolic_name(struct fc_vport *); 1407d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *); 1411875f27eSRobert Love 1421875f27eSRobert Love static struct libfc_function_template fcoe_libfc_fcn_templ = { 1431875f27eSRobert Love .frame_send = fcoe_xmit, 1441875f27eSRobert Love .ddp_setup = fcoe_ddp_setup, 1451875f27eSRobert Love .ddp_done = fcoe_ddp_done, 14671f89491SYi Zou .ddp_target = fcoe_ddp_target, 1471875f27eSRobert Love .elsct_send = fcoe_elsct_send, 148b84056bfSYi Zou .get_lesb = fcoe_get_lesb, 1497d65b0dfSJoe Eykholt .lport_set_port_id = fcoe_set_port_id, 1501875f27eSRobert Love }; 1519a05753bSChris Leech 1528ca86f84SYi Zou struct fc_function_template fcoe_nport_fc_functions = { 153a703e490SVasu Dev .show_host_node_name = 1, 154a703e490SVasu Dev .show_host_port_name = 1, 155a703e490SVasu Dev .show_host_supported_classes = 1, 156a703e490SVasu Dev .show_host_supported_fc4s = 1, 157a703e490SVasu Dev .show_host_active_fc4s = 1, 158a703e490SVasu Dev .show_host_maxframe_size = 1, 159a703e490SVasu Dev 160a703e490SVasu Dev .show_host_port_id = 1, 161a703e490SVasu Dev .show_host_supported_speeds = 1, 162a703e490SVasu Dev .get_host_speed = fc_get_host_speed, 163a703e490SVasu Dev .show_host_speed = 1, 164a703e490SVasu Dev .show_host_port_type = 1, 165a703e490SVasu Dev .get_host_port_state = fc_get_host_port_state, 166a703e490SVasu Dev .show_host_port_state = 1, 167a703e490SVasu Dev .show_host_symbolic_name = 1, 168a703e490SVasu Dev 169a703e490SVasu Dev .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), 170a703e490SVasu Dev .show_rport_maxframe_size = 1, 171a703e490SVasu Dev .show_rport_supported_classes = 1, 172a703e490SVasu Dev 173a703e490SVasu Dev .show_host_fabric_name = 1, 174a703e490SVasu Dev .show_starget_node_name = 1, 175a703e490SVasu Dev .show_starget_port_name = 1, 176a703e490SVasu Dev .show_starget_port_id = 1, 177a703e490SVasu Dev .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, 178a703e490SVasu Dev .show_rport_dev_loss_tmo = 1, 179a703e490SVasu Dev .get_fc_host_stats = fc_get_host_stats, 180a703e490SVasu Dev .issue_fc_host_lip = fcoe_reset, 181a703e490SVasu Dev 182a703e490SVasu Dev .terminate_rport_io = fc_rport_terminate_io, 1839a05753bSChris Leech 1849a05753bSChris Leech .vport_create = fcoe_vport_create, 1859a05753bSChris Leech .vport_delete = fcoe_vport_destroy, 1869a05753bSChris Leech .vport_disable = fcoe_vport_disable, 187dc8596d3SChris Leech .set_vport_symbolic_name = fcoe_set_vport_symbolic_name, 188a51ab396SSteve Ma 189a51ab396SSteve Ma .bsg_request = fc_lport_bsg_request, 190a703e490SVasu Dev }; 191a703e490SVasu Dev 1928ca86f84SYi Zou struct fc_function_template fcoe_vport_fc_functions = { 193e9084bb8SChris Leech .show_host_node_name = 1, 194e9084bb8SChris Leech .show_host_port_name = 1, 195e9084bb8SChris Leech .show_host_supported_classes = 1, 196e9084bb8SChris Leech .show_host_supported_fc4s = 1, 197e9084bb8SChris Leech .show_host_active_fc4s = 1, 198e9084bb8SChris Leech .show_host_maxframe_size = 1, 199e9084bb8SChris Leech 200e9084bb8SChris Leech .show_host_port_id = 1, 201e9084bb8SChris Leech .show_host_supported_speeds = 1, 202e9084bb8SChris Leech .get_host_speed = fc_get_host_speed, 203e9084bb8SChris Leech .show_host_speed = 1, 204e9084bb8SChris Leech .show_host_port_type = 1, 205e9084bb8SChris Leech .get_host_port_state = fc_get_host_port_state, 206e9084bb8SChris Leech .show_host_port_state = 1, 207e9084bb8SChris Leech .show_host_symbolic_name = 1, 208e9084bb8SChris Leech 209e9084bb8SChris Leech .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), 210e9084bb8SChris Leech .show_rport_maxframe_size = 1, 211e9084bb8SChris Leech .show_rport_supported_classes = 1, 212e9084bb8SChris Leech 213e9084bb8SChris Leech .show_host_fabric_name = 1, 214e9084bb8SChris Leech .show_starget_node_name = 1, 215e9084bb8SChris Leech .show_starget_port_name = 1, 216e9084bb8SChris Leech .show_starget_port_id = 1, 217e9084bb8SChris Leech .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, 218e9084bb8SChris Leech .show_rport_dev_loss_tmo = 1, 219e9084bb8SChris Leech .get_fc_host_stats = fc_get_host_stats, 220e9084bb8SChris Leech .issue_fc_host_lip = fcoe_reset, 221e9084bb8SChris Leech 222e9084bb8SChris Leech .terminate_rport_io = fc_rport_terminate_io, 223a51ab396SSteve Ma 224a51ab396SSteve Ma .bsg_request = fc_lport_bsg_request, 225e9084bb8SChris Leech }; 226e9084bb8SChris Leech 227a703e490SVasu Dev static struct scsi_host_template fcoe_shost_template = { 228a703e490SVasu Dev .module = THIS_MODULE, 229a703e490SVasu Dev .name = "FCoE Driver", 230a703e490SVasu Dev .proc_name = FCOE_NAME, 231a703e490SVasu Dev .queuecommand = fc_queuecommand, 232a703e490SVasu Dev .eh_abort_handler = fc_eh_abort, 233a703e490SVasu Dev .eh_device_reset_handler = fc_eh_device_reset, 234a703e490SVasu Dev .eh_host_reset_handler = fc_eh_host_reset, 235a703e490SVasu Dev .slave_alloc = fc_slave_alloc, 236a703e490SVasu Dev .change_queue_depth = fc_change_queue_depth, 237a703e490SVasu Dev .change_queue_type = fc_change_queue_type, 238a703e490SVasu Dev .this_id = -1, 23914caf44cSVasu Dev .cmd_per_lun = 3, 240a703e490SVasu Dev .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS, 241a703e490SVasu Dev .use_clustering = ENABLE_CLUSTERING, 242a703e490SVasu Dev .sg_tablesize = SG_ALL, 243a703e490SVasu Dev .max_sectors = 0xffff, 244a703e490SVasu Dev }; 245a703e490SVasu Dev 24654b649f8SChris Leech /** 2471875f27eSRobert Love * fcoe_interface_setup() - Setup a FCoE interface 2481875f27eSRobert Love * @fcoe: The new FCoE interface 2491875f27eSRobert Love * @netdev: The net device that the fcoe interface is on 25054b649f8SChris Leech * 25154b649f8SChris Leech * Returns : 0 for success 2522e70e241SChris Leech * Locking: must be called with the RTNL mutex held 25354b649f8SChris Leech */ 25454b649f8SChris Leech static int fcoe_interface_setup(struct fcoe_interface *fcoe, 25554b649f8SChris Leech struct net_device *netdev) 25654b649f8SChris Leech { 25754b649f8SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 25854b649f8SChris Leech struct netdev_hw_addr *ha; 2595bab87e6SYi Zou struct net_device *real_dev; 26054b649f8SChris Leech u8 flogi_maddr[ETH_ALEN]; 261b7a727f1SYi Zou const struct net_device_ops *ops; 26254b649f8SChris Leech 26354b649f8SChris Leech fcoe->netdev = netdev; 26454b649f8SChris Leech 265b7a727f1SYi Zou /* Let LLD initialize for FCoE */ 266b7a727f1SYi Zou ops = netdev->netdev_ops; 267b7a727f1SYi Zou if (ops->ndo_fcoe_enable) { 268b7a727f1SYi Zou if (ops->ndo_fcoe_enable(netdev)) 269b7a727f1SYi Zou FCOE_NETDEV_DBG(netdev, "Failed to enable FCoE" 270b7a727f1SYi Zou " specific feature for LLD.\n"); 271b7a727f1SYi Zou } 272b7a727f1SYi Zou 27354b649f8SChris Leech /* Do not support for bonding device */ 274cc8bdf06SJiri Pirko if (netdev->priv_flags & IFF_BONDING && netdev->flags & IFF_MASTER) { 27559d92516Sjohn fastabend FCOE_NETDEV_DBG(netdev, "Bonded interfaces not supported\n"); 27654b649f8SChris Leech return -EOPNOTSUPP; 27754b649f8SChris Leech } 27854b649f8SChris Leech 27954b649f8SChris Leech /* look for SAN MAC address, if multiple SAN MACs exist, only 28054b649f8SChris Leech * use the first one for SPMA */ 2815bab87e6SYi Zou real_dev = (netdev->priv_flags & IFF_802_1Q_VLAN) ? 2825bab87e6SYi Zou vlan_dev_real_dev(netdev) : netdev; 283d1483bb9SVasu Dev fcoe->realdev = real_dev; 28454b649f8SChris Leech rcu_read_lock(); 2855bab87e6SYi Zou for_each_dev_addr(real_dev, ha) { 28654b649f8SChris Leech if ((ha->type == NETDEV_HW_ADDR_T_SAN) && 287bf361707SYi Zou (is_valid_ether_addr(ha->addr))) { 28854b649f8SChris Leech memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN); 28954b649f8SChris Leech fip->spma = 1; 29054b649f8SChris Leech break; 29154b649f8SChris Leech } 29254b649f8SChris Leech } 29354b649f8SChris Leech rcu_read_unlock(); 29454b649f8SChris Leech 29554b649f8SChris Leech /* setup Source Mac Address */ 29654b649f8SChris Leech if (!fip->spma) 29754b649f8SChris Leech memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len); 29854b649f8SChris Leech 29954b649f8SChris Leech /* 30054b649f8SChris Leech * Add FCoE MAC address as second unicast MAC address 30154b649f8SChris Leech * or enter promiscuous mode if not capable of listening 30254b649f8SChris Leech * for multiple unicast MACs. 30354b649f8SChris Leech */ 30454b649f8SChris Leech memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 305a748ee24SJiri Pirko dev_uc_add(netdev, flogi_maddr); 30654b649f8SChris Leech if (fip->spma) 307a748ee24SJiri Pirko dev_uc_add(netdev, fip->ctl_src_addr); 308e10f8c66SJoe Eykholt if (fip->mode == FIP_MODE_VN2VN) { 309e10f8c66SJoe Eykholt dev_mc_add(netdev, FIP_ALL_VN2VN_MACS); 310e10f8c66SJoe Eykholt dev_mc_add(netdev, FIP_ALL_P2P_MACS); 311e10f8c66SJoe Eykholt } else 31222bedad3SJiri Pirko dev_mc_add(netdev, FIP_ALL_ENODE_MACS); 31354b649f8SChris Leech 31454b649f8SChris Leech /* 31554b649f8SChris Leech * setup the receive function from ethernet driver 31654b649f8SChris Leech * on the ethertype for the given device 31754b649f8SChris Leech */ 31854b649f8SChris Leech fcoe->fcoe_packet_type.func = fcoe_rcv; 31954b649f8SChris Leech fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); 32054b649f8SChris Leech fcoe->fcoe_packet_type.dev = netdev; 32154b649f8SChris Leech dev_add_pack(&fcoe->fcoe_packet_type); 32254b649f8SChris Leech 32354b649f8SChris Leech fcoe->fip_packet_type.func = fcoe_fip_recv; 32454b649f8SChris Leech fcoe->fip_packet_type.type = htons(ETH_P_FIP); 32554b649f8SChris Leech fcoe->fip_packet_type.dev = netdev; 32654b649f8SChris Leech dev_add_pack(&fcoe->fip_packet_type); 32754b649f8SChris Leech 32854b649f8SChris Leech return 0; 32954b649f8SChris Leech } 33054b649f8SChris Leech 331a703e490SVasu Dev /** 3321875f27eSRobert Love * fcoe_interface_create() - Create a FCoE interface on a net device 3331875f27eSRobert Love * @netdev: The net device to create the FCoE interface on 3341dd454d9SJoe Eykholt * @fip_mode: The mode to use for FIP 335030f4e00SChris Leech * 336030f4e00SChris Leech * Returns: pointer to a struct fcoe_interface or NULL on error 337030f4e00SChris Leech */ 3381dd454d9SJoe Eykholt static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev, 3391dd454d9SJoe Eykholt enum fip_state fip_mode) 340030f4e00SChris Leech { 341030f4e00SChris Leech struct fcoe_interface *fcoe; 34259d92516Sjohn fastabend int err; 343030f4e00SChris Leech 3447287fb91SRobert Love if (!try_module_get(THIS_MODULE)) { 3457287fb91SRobert Love FCOE_NETDEV_DBG(netdev, 3467287fb91SRobert Love "Could not get a reference to the module\n"); 3477287fb91SRobert Love fcoe = ERR_PTR(-EBUSY); 3487287fb91SRobert Love goto out; 3497287fb91SRobert Love } 3507287fb91SRobert Love 351030f4e00SChris Leech fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL); 352030f4e00SChris Leech if (!fcoe) { 353030f4e00SChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n"); 3547287fb91SRobert Love fcoe = ERR_PTR(-ENOMEM); 3557287fb91SRobert Love goto out_nomod; 356030f4e00SChris Leech } 357030f4e00SChris Leech 3582e70e241SChris Leech dev_hold(netdev); 359030f4e00SChris Leech kref_init(&fcoe->kref); 36054b649f8SChris Leech 36154b649f8SChris Leech /* 36254b649f8SChris Leech * Initialize FIP. 36354b649f8SChris Leech */ 3641dd454d9SJoe Eykholt fcoe_ctlr_init(&fcoe->ctlr, fip_mode); 36554b649f8SChris Leech fcoe->ctlr.send = fcoe_fip_send; 36654b649f8SChris Leech fcoe->ctlr.update_mac = fcoe_update_src_mac; 36711b56188SChris Leech fcoe->ctlr.get_src_addr = fcoe_get_src_mac; 36854b649f8SChris Leech 36959d92516Sjohn fastabend err = fcoe_interface_setup(fcoe, netdev); 37059d92516Sjohn fastabend if (err) { 37159d92516Sjohn fastabend fcoe_ctlr_destroy(&fcoe->ctlr); 37259d92516Sjohn fastabend kfree(fcoe); 37359d92516Sjohn fastabend dev_put(netdev); 3747287fb91SRobert Love fcoe = ERR_PTR(err); 3757287fb91SRobert Love goto out_nomod; 37659d92516Sjohn fastabend } 377030f4e00SChris Leech 3787287fb91SRobert Love goto out; 3797287fb91SRobert Love 3807287fb91SRobert Love out_nomod: 3817287fb91SRobert Love module_put(THIS_MODULE); 3827287fb91SRobert Love out: 383030f4e00SChris Leech return fcoe; 384030f4e00SChris Leech } 385030f4e00SChris Leech 386030f4e00SChris Leech /** 387030f4e00SChris Leech * fcoe_interface_release() - fcoe_port kref release function 3881875f27eSRobert Love * @kref: Embedded reference count in an fcoe_interface struct 389030f4e00SChris Leech */ 390030f4e00SChris Leech static void fcoe_interface_release(struct kref *kref) 391030f4e00SChris Leech { 392030f4e00SChris Leech struct fcoe_interface *fcoe; 3932e70e241SChris Leech struct net_device *netdev; 394030f4e00SChris Leech 395030f4e00SChris Leech fcoe = container_of(kref, struct fcoe_interface, kref); 3962e70e241SChris Leech netdev = fcoe->netdev; 3972e70e241SChris Leech /* tear-down the FCoE controller */ 3982e70e241SChris Leech fcoe_ctlr_destroy(&fcoe->ctlr); 399030f4e00SChris Leech kfree(fcoe); 4002e70e241SChris Leech dev_put(netdev); 4017287fb91SRobert Love module_put(THIS_MODULE); 402030f4e00SChris Leech } 403030f4e00SChris Leech 404030f4e00SChris Leech /** 4051875f27eSRobert Love * fcoe_interface_get() - Get a reference to a FCoE interface 4061875f27eSRobert Love * @fcoe: The FCoE interface to be held 407030f4e00SChris Leech */ 408030f4e00SChris Leech static inline void fcoe_interface_get(struct fcoe_interface *fcoe) 409030f4e00SChris Leech { 410030f4e00SChris Leech kref_get(&fcoe->kref); 411030f4e00SChris Leech } 412030f4e00SChris Leech 413030f4e00SChris Leech /** 4141875f27eSRobert Love * fcoe_interface_put() - Put a reference to a FCoE interface 4151875f27eSRobert Love * @fcoe: The FCoE interface to be released 416030f4e00SChris Leech */ 417030f4e00SChris Leech static inline void fcoe_interface_put(struct fcoe_interface *fcoe) 418030f4e00SChris Leech { 419030f4e00SChris Leech kref_put(&fcoe->kref, fcoe_interface_release); 420030f4e00SChris Leech } 421030f4e00SChris Leech 422030f4e00SChris Leech /** 423f04ca1b6SVasu Dev * fcoe_interface_cleanup() - Clean up a FCoE interface 424f04ca1b6SVasu Dev * @fcoe: The FCoE interface to be cleaned up 425f04ca1b6SVasu Dev * 426f04ca1b6SVasu Dev * Caller must be holding the RTNL mutex 427f04ca1b6SVasu Dev */ 428f04ca1b6SVasu Dev void fcoe_interface_cleanup(struct fcoe_interface *fcoe) 429f04ca1b6SVasu Dev { 430f04ca1b6SVasu Dev struct net_device *netdev = fcoe->netdev; 431f04ca1b6SVasu Dev struct fcoe_ctlr *fip = &fcoe->ctlr; 432f04ca1b6SVasu Dev u8 flogi_maddr[ETH_ALEN]; 433f04ca1b6SVasu Dev const struct net_device_ops *ops; 434f04ca1b6SVasu Dev 435f04ca1b6SVasu Dev /* 436f04ca1b6SVasu Dev * Don't listen for Ethernet packets anymore. 437f04ca1b6SVasu Dev * synchronize_net() ensures that the packet handlers are not running 438f04ca1b6SVasu Dev * on another CPU. dev_remove_pack() would do that, this calls the 439f04ca1b6SVasu Dev * unsyncronized version __dev_remove_pack() to avoid multiple delays. 440f04ca1b6SVasu Dev */ 441f04ca1b6SVasu Dev __dev_remove_pack(&fcoe->fcoe_packet_type); 442f04ca1b6SVasu Dev __dev_remove_pack(&fcoe->fip_packet_type); 443f04ca1b6SVasu Dev synchronize_net(); 444f04ca1b6SVasu Dev 445f04ca1b6SVasu Dev /* Delete secondary MAC addresses */ 446f04ca1b6SVasu Dev memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 447f04ca1b6SVasu Dev dev_uc_del(netdev, flogi_maddr); 448f04ca1b6SVasu Dev if (fip->spma) 449f04ca1b6SVasu Dev dev_uc_del(netdev, fip->ctl_src_addr); 450f04ca1b6SVasu Dev if (fip->mode == FIP_MODE_VN2VN) { 451f04ca1b6SVasu Dev dev_mc_del(netdev, FIP_ALL_VN2VN_MACS); 452f04ca1b6SVasu Dev dev_mc_del(netdev, FIP_ALL_P2P_MACS); 453f04ca1b6SVasu Dev } else 454f04ca1b6SVasu Dev dev_mc_del(netdev, FIP_ALL_ENODE_MACS); 455f04ca1b6SVasu Dev 456f04ca1b6SVasu Dev /* Tell the LLD we are done w/ FCoE */ 457f04ca1b6SVasu Dev ops = netdev->netdev_ops; 458f04ca1b6SVasu Dev if (ops->ndo_fcoe_disable) { 459f04ca1b6SVasu Dev if (ops->ndo_fcoe_disable(netdev)) 460f04ca1b6SVasu Dev FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE" 461f04ca1b6SVasu Dev " specific feature for LLD.\n"); 462f04ca1b6SVasu Dev } 463b2085a4eSNeerav Parikh 464b2085a4eSNeerav Parikh /* Release the self-reference taken during fcoe_interface_create() */ 465f04ca1b6SVasu Dev fcoe_interface_put(fcoe); 466f04ca1b6SVasu Dev } 467f04ca1b6SVasu Dev 468f04ca1b6SVasu Dev /** 4691875f27eSRobert Love * fcoe_fip_recv() - Handler for received FIP frames 4701875f27eSRobert Love * @skb: The receive skb 4711875f27eSRobert Love * @netdev: The associated net device 4721875f27eSRobert Love * @ptype: The packet_type structure which was used to register this handler 4731875f27eSRobert Love * @orig_dev: The original net_device the the skb was received on. 4741875f27eSRobert Love * (in case dev is a bond) 475ab6b85c1SVasu Dev * 476ab6b85c1SVasu Dev * Returns: 0 for success 477ab6b85c1SVasu Dev */ 4781875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev, 479ab6b85c1SVasu Dev struct packet_type *ptype, 480ab6b85c1SVasu Dev struct net_device *orig_dev) 481ab6b85c1SVasu Dev { 482259ad85dSChris Leech struct fcoe_interface *fcoe; 483ab6b85c1SVasu Dev 484259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type); 4853fe9a0baSChris Leech fcoe_ctlr_recv(&fcoe->ctlr, skb); 486ab6b85c1SVasu Dev return 0; 487ab6b85c1SVasu Dev } 488ab6b85c1SVasu Dev 489ab6b85c1SVasu Dev /** 490980f5156SVasu Dev * fcoe_port_send() - Send an Ethernet-encapsulated FIP/FCoE frame 491980f5156SVasu Dev * @port: The FCoE port 492980f5156SVasu Dev * @skb: The FIP/FCoE packet to be sent 493980f5156SVasu Dev */ 494980f5156SVasu Dev static void fcoe_port_send(struct fcoe_port *port, struct sk_buff *skb) 495980f5156SVasu Dev { 496980f5156SVasu Dev if (port->fcoe_pending_queue.qlen) 497980f5156SVasu Dev fcoe_check_wait_queue(port->lport, skb); 498980f5156SVasu Dev else if (fcoe_start_io(skb)) 499980f5156SVasu Dev fcoe_check_wait_queue(port->lport, skb); 500980f5156SVasu Dev } 501980f5156SVasu Dev 502980f5156SVasu Dev /** 5031875f27eSRobert Love * fcoe_fip_send() - Send an Ethernet-encapsulated FIP frame 5041875f27eSRobert Love * @fip: The FCoE controller 5051875f27eSRobert Love * @skb: The FIP packet to be sent 506ab6b85c1SVasu Dev */ 507ab6b85c1SVasu Dev static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 508ab6b85c1SVasu Dev { 5093fe9a0baSChris Leech skb->dev = fcoe_from_ctlr(fip)->netdev; 510980f5156SVasu Dev fcoe_port_send(lport_priv(fip->lp), skb); 511ab6b85c1SVasu Dev } 512ab6b85c1SVasu Dev 513ab6b85c1SVasu Dev /** 5141875f27eSRobert Love * fcoe_update_src_mac() - Update the Ethernet MAC filters 5151875f27eSRobert Love * @lport: The local port to update the source MAC on 5161875f27eSRobert Love * @addr: Unicast MAC address to add 517ab6b85c1SVasu Dev * 518ab6b85c1SVasu Dev * Remove any previously-set unicast MAC filter. 519ab6b85c1SVasu Dev * Add secondary FCoE MAC address filter for our OUI. 520ab6b85c1SVasu Dev */ 52111b56188SChris Leech static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr) 522ab6b85c1SVasu Dev { 52311b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 5248597ae8bSBhanu Prakash Gollapudi struct fcoe_interface *fcoe = port->priv; 525ab6b85c1SVasu Dev 526ab6b85c1SVasu Dev rtnl_lock(); 52711b56188SChris Leech if (!is_zero_ether_addr(port->data_src_addr)) 528a748ee24SJiri Pirko dev_uc_del(fcoe->netdev, port->data_src_addr); 52911b56188SChris Leech if (!is_zero_ether_addr(addr)) 530a748ee24SJiri Pirko dev_uc_add(fcoe->netdev, addr); 53111b56188SChris Leech memcpy(port->data_src_addr, addr, ETH_ALEN); 532ab6b85c1SVasu Dev rtnl_unlock(); 533ab6b85c1SVasu Dev } 534ab6b85c1SVasu Dev 535ab6b85c1SVasu Dev /** 53611b56188SChris Leech * fcoe_get_src_mac() - return the Ethernet source address for an lport 53711b56188SChris Leech * @lport: libfc lport 53811b56188SChris Leech */ 53911b56188SChris Leech static u8 *fcoe_get_src_mac(struct fc_lport *lport) 54011b56188SChris Leech { 54111b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 54211b56188SChris Leech 54311b56188SChris Leech return port->data_src_addr; 54411b56188SChris Leech } 54511b56188SChris Leech 54611b56188SChris Leech /** 5471875f27eSRobert Love * fcoe_lport_config() - Set up a local port 5481875f27eSRobert Love * @lport: The local port to be setup 549a703e490SVasu Dev * 550a703e490SVasu Dev * Returns: 0 for success 551a703e490SVasu Dev */ 5521875f27eSRobert Love static int fcoe_lport_config(struct fc_lport *lport) 553a703e490SVasu Dev { 5541875f27eSRobert Love lport->link_up = 0; 5551875f27eSRobert Love lport->qfull = 0; 5561875f27eSRobert Love lport->max_retry_count = 3; 5571875f27eSRobert Love lport->max_rport_retry_count = 3; 5581875f27eSRobert Love lport->e_d_tov = 2 * 1000; /* FC-FS default */ 5591875f27eSRobert Love lport->r_a_tov = 2 * 2 * 1000; 5601875f27eSRobert Love lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | 561a703e490SVasu Dev FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); 5621875f27eSRobert Love lport->does_npiv = 1; 563a703e490SVasu Dev 5641875f27eSRobert Love fc_lport_init_stats(lport); 565a703e490SVasu Dev 566a703e490SVasu Dev /* lport fc_lport related configuration */ 5671875f27eSRobert Love fc_lport_config(lport); 568a703e490SVasu Dev 569a703e490SVasu Dev /* offload related configuration */ 5701875f27eSRobert Love lport->crc_offload = 0; 5711875f27eSRobert Love lport->seq_offload = 0; 5721875f27eSRobert Love lport->lro_enabled = 0; 5731875f27eSRobert Love lport->lro_xid = 0; 5741875f27eSRobert Love lport->lso_max = 0; 575a703e490SVasu Dev 576a703e490SVasu Dev return 0; 577a703e490SVasu Dev } 578a703e490SVasu Dev 579a703e490SVasu Dev /** 58054a5b21dSYi Zou * fcoe_netdev_features_change - Updates the lport's offload flags based 58154a5b21dSYi Zou * on the LLD netdev's FCoE feature flags 58254a5b21dSYi Zou */ 58354a5b21dSYi Zou static void fcoe_netdev_features_change(struct fc_lport *lport, 58454a5b21dSYi Zou struct net_device *netdev) 58554a5b21dSYi Zou { 58654a5b21dSYi Zou mutex_lock(&lport->lp_mutex); 58754a5b21dSYi Zou 58854a5b21dSYi Zou if (netdev->features & NETIF_F_SG) 58954a5b21dSYi Zou lport->sg_supp = 1; 59054a5b21dSYi Zou else 59154a5b21dSYi Zou lport->sg_supp = 0; 59254a5b21dSYi Zou 59354a5b21dSYi Zou if (netdev->features & NETIF_F_FCOE_CRC) { 59454a5b21dSYi Zou lport->crc_offload = 1; 59554a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n"); 59654a5b21dSYi Zou } else { 59754a5b21dSYi Zou lport->crc_offload = 0; 59854a5b21dSYi Zou } 59954a5b21dSYi Zou 60054a5b21dSYi Zou if (netdev->features & NETIF_F_FSO) { 60154a5b21dSYi Zou lport->seq_offload = 1; 60254a5b21dSYi Zou lport->lso_max = netdev->gso_max_size; 60354a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n", 60454a5b21dSYi Zou lport->lso_max); 60554a5b21dSYi Zou } else { 60654a5b21dSYi Zou lport->seq_offload = 0; 60754a5b21dSYi Zou lport->lso_max = 0; 60854a5b21dSYi Zou } 60954a5b21dSYi Zou 61054a5b21dSYi Zou if (netdev->fcoe_ddp_xid) { 61154a5b21dSYi Zou lport->lro_enabled = 1; 61254a5b21dSYi Zou lport->lro_xid = netdev->fcoe_ddp_xid; 61354a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n", 61454a5b21dSYi Zou lport->lro_xid); 61554a5b21dSYi Zou } else { 61654a5b21dSYi Zou lport->lro_enabled = 0; 61754a5b21dSYi Zou lport->lro_xid = 0; 61854a5b21dSYi Zou } 61954a5b21dSYi Zou 62054a5b21dSYi Zou mutex_unlock(&lport->lp_mutex); 62154a5b21dSYi Zou } 62254a5b21dSYi Zou 62354a5b21dSYi Zou /** 6241875f27eSRobert Love * fcoe_netdev_config() - Set up net devive for SW FCoE 6251875f27eSRobert Love * @lport: The local port that is associated with the net device 6261875f27eSRobert Love * @netdev: The associated net device 627a703e490SVasu Dev * 6281875f27eSRobert Love * Must be called after fcoe_lport_config() as it will use local port mutex 629a703e490SVasu Dev * 630a703e490SVasu Dev * Returns: 0 for success 631a703e490SVasu Dev */ 6321875f27eSRobert Love static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev) 633a703e490SVasu Dev { 634a703e490SVasu Dev u32 mfs; 635a703e490SVasu Dev u64 wwnn, wwpn; 63625024989SChris Leech struct fcoe_interface *fcoe; 637014f5c3fSChris Leech struct fcoe_port *port; 638a703e490SVasu Dev 639a703e490SVasu Dev /* Setup lport private data to point to fcoe softc */ 6401875f27eSRobert Love port = lport_priv(lport); 6418597ae8bSBhanu Prakash Gollapudi fcoe = port->priv; 642a703e490SVasu Dev 643a703e490SVasu Dev /* 644a703e490SVasu Dev * Determine max frame size based on underlying device and optional 645a703e490SVasu Dev * user-configured limit. If the MFS is too low, fcoe_link_ok() 646a703e490SVasu Dev * will return 0, so do this first. 647a703e490SVasu Dev */ 6487221d7e5SYi Zou mfs = netdev->mtu; 6497221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) { 6507221d7e5SYi Zou mfs = FCOE_MTU; 6517221d7e5SYi Zou FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs); 6527221d7e5SYi Zou } 6537221d7e5SYi Zou mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof)); 6541875f27eSRobert Love if (fc_set_mfs(lport, mfs)) 655a703e490SVasu Dev return -EINVAL; 656a703e490SVasu Dev 657a703e490SVasu Dev /* offload features support */ 65854a5b21dSYi Zou fcoe_netdev_features_change(lport, netdev); 659a703e490SVasu Dev 660014f5c3fSChris Leech skb_queue_head_init(&port->fcoe_pending_queue); 661014f5c3fSChris Leech port->fcoe_pending_queue_active = 0; 6621875f27eSRobert Love setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lport); 663a703e490SVasu Dev 6645e4f8fe7SRobert Love fcoe_link_speed_update(lport); 6655e4f8fe7SRobert Love 6661875f27eSRobert Love if (!lport->vport) { 667dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN)) 66875ea89efSYi Zou wwnn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 1, 0); 6691875f27eSRobert Love fc_set_wwnn(lport, wwnn); 670dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN)) 671dcece412SYi Zou wwpn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 672cf4aebcaSVasu Dev 2, 0); 6731875f27eSRobert Love fc_set_wwpn(lport, wwpn); 6749a05753bSChris Leech } 675a703e490SVasu Dev 676a703e490SVasu Dev return 0; 677a703e490SVasu Dev } 678a703e490SVasu Dev 679a703e490SVasu Dev /** 6801875f27eSRobert Love * fcoe_shost_config() - Set up the SCSI host associated with a local port 6811875f27eSRobert Love * @lport: The local port 6821875f27eSRobert Love * @dev: The device associated with the SCSI host 683a703e490SVasu Dev * 684a703e490SVasu Dev * Must be called after fcoe_lport_config() and fcoe_netdev_config() 685a703e490SVasu Dev * 686a703e490SVasu Dev * Returns: 0 for success 687a703e490SVasu Dev */ 6888ba00a4bSVasu Dev static int fcoe_shost_config(struct fc_lport *lport, struct device *dev) 689a703e490SVasu Dev { 690a703e490SVasu Dev int rc = 0; 691a703e490SVasu Dev 692a703e490SVasu Dev /* lport scsi host config */ 6931875f27eSRobert Love lport->host->max_lun = FCOE_MAX_LUN; 6941875f27eSRobert Love lport->host->max_id = FCOE_MAX_FCP_TARGET; 6951875f27eSRobert Love lport->host->max_channel = 0; 696da87bfabSVasu Dev lport->host->max_cmd_len = FCOE_MAX_CMD_LEN; 697da87bfabSVasu Dev 6981875f27eSRobert Love if (lport->vport) 6998ca86f84SYi Zou lport->host->transportt = fcoe_vport_scsi_transport; 700e9084bb8SChris Leech else 7018ca86f84SYi Zou lport->host->transportt = fcoe_nport_scsi_transport; 702a703e490SVasu Dev 703a703e490SVasu Dev /* add the new host to the SCSI-ml */ 7041875f27eSRobert Love rc = scsi_add_host(lport->host, dev); 705a703e490SVasu Dev if (rc) { 7061875f27eSRobert Love FCOE_NETDEV_DBG(fcoe_netdev(lport), "fcoe_shost_config: " 707d5488eb9SRobert Love "error on scsi_add_host\n"); 708a703e490SVasu Dev return rc; 709a703e490SVasu Dev } 7109a05753bSChris Leech 7111875f27eSRobert Love if (!lport->vport) 7124be929beSAlexey Dobriyan fc_host_max_npiv_vports(lport->host) = USHRT_MAX; 7139a05753bSChris Leech 7141875f27eSRobert Love snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 7155baa17c3SChris Leech "%s v%s over %s", FCOE_NAME, FCOE_VERSION, 7161875f27eSRobert Love fcoe_netdev(lport)->name); 717a703e490SVasu Dev 718a703e490SVasu Dev return 0; 719a703e490SVasu Dev } 720a703e490SVasu Dev 7211875f27eSRobert Love /** 7221875f27eSRobert Love * fcoe_oem_match() - The match routine for the offloaded exchange manager 7231875f27eSRobert Love * @fp: The I/O frame 724d7179680SVasu Dev * 7251875f27eSRobert Love * This routine will be associated with an exchange manager (EM). When 7261875f27eSRobert Love * the libfc exchange handling code is looking for an EM to use it will 7271875f27eSRobert Love * call this routine and pass it the frame that it wishes to send. This 7281875f27eSRobert Love * routine will return True if the associated EM is to be used and False 7291875f27eSRobert Love * if the echange code should continue looking for an EM. 7301875f27eSRobert Love * 7311875f27eSRobert Love * The offload EM that this routine is associated with will handle any 7321875f27eSRobert Love * packets that are for SCSI read requests. 7331875f27eSRobert Love * 7341ff9918bSKiran Patil * This has been enhanced to work when FCoE stack is operating in target 7351ff9918bSKiran Patil * mode. 7361ff9918bSKiran Patil * 7371875f27eSRobert Love * Returns: True for read types I/O, otherwise returns false. 738d7179680SVasu Dev */ 739d7179680SVasu Dev bool fcoe_oem_match(struct fc_frame *fp) 740d7179680SVasu Dev { 7411ff9918bSKiran Patil struct fc_frame_header *fh = fc_frame_header_get(fp); 7421ff9918bSKiran Patil struct fcp_cmnd *fcp; 7431ff9918bSKiran Patil 7441ff9918bSKiran Patil if (fc_fcp_is_read(fr_fsp(fp)) && 7451ff9918bSKiran Patil (fr_fsp(fp)->data_len > fcoe_ddp_min)) 7461ff9918bSKiran Patil return true; 7471ff9918bSKiran Patil else if (!(ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX)) { 7481ff9918bSKiran Patil fcp = fc_frame_payload_get(fp, sizeof(*fcp)); 7491ff9918bSKiran Patil if (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN && 7501ff9918bSKiran Patil fcp && (ntohl(fcp->fc_dl) > fcoe_ddp_min) && 7511ff9918bSKiran Patil (fcp->fc_flags & FCP_CFL_WRDATA)) 7521ff9918bSKiran Patil return true; 7531ff9918bSKiran Patil } 7541ff9918bSKiran Patil return false; 755d7179680SVasu Dev } 756d7179680SVasu Dev 757a703e490SVasu Dev /** 7581875f27eSRobert Love * fcoe_em_config() - Allocate and configure an exchange manager 7591875f27eSRobert Love * @lport: The local port that the new EM will be associated with 760a703e490SVasu Dev * 761a703e490SVasu Dev * Returns: 0 on success 762a703e490SVasu Dev */ 7631875f27eSRobert Love static inline int fcoe_em_config(struct fc_lport *lport) 764a703e490SVasu Dev { 7651875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 7668597ae8bSBhanu Prakash Gollapudi struct fcoe_interface *fcoe = port->priv; 76725024989SChris Leech struct fcoe_interface *oldfcoe = NULL; 7681d1b88dcSVasu Dev struct net_device *old_real_dev, *cur_real_dev; 769d7179680SVasu Dev u16 min_xid = FCOE_MIN_XID; 770d7179680SVasu Dev u16 max_xid = FCOE_MAX_XID; 771d7179680SVasu Dev 772d7179680SVasu Dev /* 773d7179680SVasu Dev * Check if need to allocate an em instance for 774d7179680SVasu Dev * offload exchange ids to be shared across all VN_PORTs/lport. 775d7179680SVasu Dev */ 7761875f27eSRobert Love if (!lport->lro_enabled || !lport->lro_xid || 7771875f27eSRobert Love (lport->lro_xid >= max_xid)) { 7781875f27eSRobert Love lport->lro_xid = 0; 779d7179680SVasu Dev goto skip_oem; 780d7179680SVasu Dev } 781d7179680SVasu Dev 782d7179680SVasu Dev /* 783d7179680SVasu Dev * Reuse existing offload em instance in case 7841d1b88dcSVasu Dev * it is already allocated on real eth device 785d7179680SVasu Dev */ 78625024989SChris Leech if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 78725024989SChris Leech cur_real_dev = vlan_dev_real_dev(fcoe->netdev); 7881d1b88dcSVasu Dev else 78925024989SChris Leech cur_real_dev = fcoe->netdev; 7901d1b88dcSVasu Dev 79125024989SChris Leech list_for_each_entry(oldfcoe, &fcoe_hostlist, list) { 79225024989SChris Leech if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 79325024989SChris Leech old_real_dev = vlan_dev_real_dev(oldfcoe->netdev); 7941d1b88dcSVasu Dev else 79525024989SChris Leech old_real_dev = oldfcoe->netdev; 7961d1b88dcSVasu Dev 7971d1b88dcSVasu Dev if (cur_real_dev == old_real_dev) { 798991cbb60SChris Leech fcoe->oem = oldfcoe->oem; 799d7179680SVasu Dev break; 800d7179680SVasu Dev } 801d7179680SVasu Dev } 802d7179680SVasu Dev 803991cbb60SChris Leech if (fcoe->oem) { 8041875f27eSRobert Love if (!fc_exch_mgr_add(lport, fcoe->oem, fcoe_oem_match)) { 805d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to add " 806d7179680SVasu Dev "offload em:%p on interface:%s\n", 807991cbb60SChris Leech fcoe->oem, fcoe->netdev->name); 808a703e490SVasu Dev return -ENOMEM; 809d7179680SVasu Dev } 810d7179680SVasu Dev } else { 8111875f27eSRobert Love fcoe->oem = fc_exch_mgr_alloc(lport, FC_CLASS_3, 8121875f27eSRobert Love FCOE_MIN_XID, lport->lro_xid, 813d7179680SVasu Dev fcoe_oem_match); 814991cbb60SChris Leech if (!fcoe->oem) { 815d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to allocate " 816d7179680SVasu Dev "em for offload exches on interface:%s\n", 81725024989SChris Leech fcoe->netdev->name); 818d7179680SVasu Dev return -ENOMEM; 819d7179680SVasu Dev } 820d7179680SVasu Dev } 821d7179680SVasu Dev 822d7179680SVasu Dev /* 823d7179680SVasu Dev * Exclude offload EM xid range from next EM xid range. 824d7179680SVasu Dev */ 8251875f27eSRobert Love min_xid += lport->lro_xid + 1; 826d7179680SVasu Dev 827d7179680SVasu Dev skip_oem: 8281875f27eSRobert Love if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, min_xid, max_xid, NULL)) { 829d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to " 83025024989SChris Leech "allocate em on interface %s\n", fcoe->netdev->name); 831d7179680SVasu Dev return -ENOMEM; 832d7179680SVasu Dev } 833a703e490SVasu Dev 834a703e490SVasu Dev return 0; 835a703e490SVasu Dev } 836a703e490SVasu Dev 837a703e490SVasu Dev /** 8381875f27eSRobert Love * fcoe_if_destroy() - Tear down a SW FCoE instance 8391875f27eSRobert Love * @lport: The local port to be destroyed 84034ce27bcSVasu Dev * 841a703e490SVasu Dev */ 842af7f85d9SChris Leech static void fcoe_if_destroy(struct fc_lport *lport) 843a703e490SVasu Dev { 844b2085a4eSNeerav Parikh struct fcoe_port *port = lport_priv(lport); 845b2085a4eSNeerav Parikh struct fcoe_interface *fcoe = port->priv; 846b2085a4eSNeerav Parikh struct net_device *netdev = fcoe->netdev; 847b2085a4eSNeerav Parikh 848b2085a4eSNeerav Parikh FCOE_NETDEV_DBG(netdev, "Destroying interface\n"); 849b2085a4eSNeerav Parikh 850b2085a4eSNeerav Parikh /* Logout of the fabric */ 851b2085a4eSNeerav Parikh fc_fabric_logoff(lport); 852b2085a4eSNeerav Parikh 853b2085a4eSNeerav Parikh /* Cleanup the fc_lport */ 854b2085a4eSNeerav Parikh fc_lport_destroy(lport); 855b2085a4eSNeerav Parikh 856b2085a4eSNeerav Parikh /* Stop the transmit retry timer */ 857b2085a4eSNeerav Parikh del_timer_sync(&port->timer); 858b2085a4eSNeerav Parikh 859b2085a4eSNeerav Parikh /* Free existing transmit skbs */ 860b2085a4eSNeerav Parikh fcoe_clean_pending_queue(lport); 861b2085a4eSNeerav Parikh 862b2085a4eSNeerav Parikh rtnl_lock(); 863b2085a4eSNeerav Parikh if (!is_zero_ether_addr(port->data_src_addr)) 864b2085a4eSNeerav Parikh dev_uc_del(netdev, port->data_src_addr); 865b2085a4eSNeerav Parikh rtnl_unlock(); 866b2085a4eSNeerav Parikh 867b2085a4eSNeerav Parikh /* Release reference held in fcoe_if_create() */ 868b2085a4eSNeerav Parikh fcoe_interface_put(fcoe); 869b2085a4eSNeerav Parikh 87054b649f8SChris Leech /* Free queued packets for the per-CPU receive threads */ 87154b649f8SChris Leech fcoe_percpu_clean(lport); 87254b649f8SChris Leech 873a703e490SVasu Dev /* Detach from the scsi-ml */ 874af7f85d9SChris Leech fc_remove_host(lport->host); 875af7f85d9SChris Leech scsi_remove_host(lport->host); 876a703e490SVasu Dev 87780e736f8SYi Zou /* Destroy lport scsi_priv */ 87880e736f8SYi Zou fc_fcp_destroy(lport); 87980e736f8SYi Zou 880a703e490SVasu Dev /* There are no more rports or I/O, free the EM */ 881af7f85d9SChris Leech fc_exch_mgr_free(lport); 882a703e490SVasu Dev 883a703e490SVasu Dev /* Free memory used by statistical counters */ 884af7f85d9SChris Leech fc_lport_free_stats(lport); 885a703e490SVasu Dev 8862e70e241SChris Leech /* Release the Scsi_Host */ 887af7f85d9SChris Leech scsi_host_put(lport->host); 888a703e490SVasu Dev } 889a703e490SVasu Dev 8901875f27eSRobert Love /** 8911875f27eSRobert Love * fcoe_ddp_setup() - Call a LLD's ddp_setup through the net device 8921875f27eSRobert Love * @lport: The local port to setup DDP for 8931875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 8941875f27eSRobert Love * @sgl: The scatterlist describing this transfer 8951875f27eSRobert Love * @sgc: The number of sg items 896a703e490SVasu Dev * 8971875f27eSRobert Love * Returns: 0 if the DDP context was not configured 898a703e490SVasu Dev */ 8991875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid, 900a703e490SVasu Dev struct scatterlist *sgl, unsigned int sgc) 901a703e490SVasu Dev { 9021875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 903a703e490SVasu Dev 9041875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_setup) 9051875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_setup(netdev, 9061875f27eSRobert Love xid, sgl, 9071875f27eSRobert Love sgc); 908a703e490SVasu Dev 909a703e490SVasu Dev return 0; 910a703e490SVasu Dev } 911a703e490SVasu Dev 912a703e490SVasu Dev /** 91371f89491SYi Zou * fcoe_ddp_target() - Call a LLD's ddp_target through the net device 91471f89491SYi Zou * @lport: The local port to setup DDP for 91571f89491SYi Zou * @xid: The exchange ID for this DDP transfer 91671f89491SYi Zou * @sgl: The scatterlist describing this transfer 91771f89491SYi Zou * @sgc: The number of sg items 91871f89491SYi Zou * 91971f89491SYi Zou * Returns: 0 if the DDP context was not configured 92071f89491SYi Zou */ 92171f89491SYi Zou static int fcoe_ddp_target(struct fc_lport *lport, u16 xid, 92271f89491SYi Zou struct scatterlist *sgl, unsigned int sgc) 92371f89491SYi Zou { 92471f89491SYi Zou struct net_device *netdev = fcoe_netdev(lport); 92571f89491SYi Zou 92671f89491SYi Zou if (netdev->netdev_ops->ndo_fcoe_ddp_target) 92771f89491SYi Zou return netdev->netdev_ops->ndo_fcoe_ddp_target(netdev, xid, 92871f89491SYi Zou sgl, sgc); 92971f89491SYi Zou 93071f89491SYi Zou return 0; 93171f89491SYi Zou } 93271f89491SYi Zou 93371f89491SYi Zou 93471f89491SYi Zou /** 9351875f27eSRobert Love * fcoe_ddp_done() - Call a LLD's ddp_done through the net device 9361875f27eSRobert Love * @lport: The local port to complete DDP on 9371875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 938a703e490SVasu Dev * 9391875f27eSRobert Love * Returns: the length of data that have been completed by DDP 9401875f27eSRobert Love */ 9411875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *lport, u16 xid) 9421875f27eSRobert Love { 9431875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 9441875f27eSRobert Love 9451875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_done) 9461875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_done(netdev, xid); 9471875f27eSRobert Love return 0; 9481875f27eSRobert Love } 9491875f27eSRobert Love 9501875f27eSRobert Love /** 9511875f27eSRobert Love * fcoe_if_create() - Create a FCoE instance on an interface 9521875f27eSRobert Love * @fcoe: The FCoE interface to create a local port on 9531875f27eSRobert Love * @parent: The device pointer to be the parent in sysfs for the SCSI host 9541875f27eSRobert Love * @npiv: Indicates if the port is a vport or not 9551875f27eSRobert Love * 9561875f27eSRobert Love * Creates a fc_lport instance and a Scsi_Host instance and configure them. 957a703e490SVasu Dev * 958af7f85d9SChris Leech * Returns: The allocated fc_lport or an error pointer 959a703e490SVasu Dev */ 960030f4e00SChris Leech static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe, 9619a05753bSChris Leech struct device *parent, int npiv) 962a703e490SVasu Dev { 9631875f27eSRobert Love struct net_device *netdev = fcoe->netdev; 96472fa396bSVasu Dev struct fc_lport *lport, *n_port; 965014f5c3fSChris Leech struct fcoe_port *port; 96672fa396bSVasu Dev struct Scsi_Host *shost; 9671875f27eSRobert Love int rc; 9689a05753bSChris Leech /* 9699a05753bSChris Leech * parent is only a vport if npiv is 1, 9709a05753bSChris Leech * but we'll only use vport in that case so go ahead and set it 9719a05753bSChris Leech */ 9729a05753bSChris Leech struct fc_vport *vport = dev_to_vport(parent); 973a703e490SVasu Dev 974d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Create Interface\n"); 975a703e490SVasu Dev 97672fa396bSVasu Dev if (!npiv) 97772fa396bSVasu Dev lport = libfc_host_alloc(&fcoe_shost_template, sizeof(*port)); 97872fa396bSVasu Dev else 97972fa396bSVasu Dev lport = libfc_vport_create(vport, sizeof(*port)); 98072fa396bSVasu Dev 98186221969SChris Leech if (!lport) { 982014f5c3fSChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n"); 983014f5c3fSChris Leech rc = -ENOMEM; 984030f4e00SChris Leech goto out; 985014f5c3fSChris Leech } 986014f5c3fSChris Leech port = lport_priv(lport); 9872e70e241SChris Leech port->lport = lport; 9888597ae8bSBhanu Prakash Gollapudi port->priv = fcoe; 9898597ae8bSBhanu Prakash Gollapudi port->max_queue_depth = FCOE_MAX_QUEUE_DEPTH; 9908597ae8bSBhanu Prakash Gollapudi port->min_queue_depth = FCOE_MIN_QUEUE_DEPTH; 9912e70e241SChris Leech INIT_WORK(&port->destroy_work, fcoe_destroy_work); 992a703e490SVasu Dev 9931875f27eSRobert Love /* configure a fc_lport including the exchange manager */ 994af7f85d9SChris Leech rc = fcoe_lport_config(lport); 995a703e490SVasu Dev if (rc) { 996d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure lport for the " 997d5488eb9SRobert Love "interface\n"); 998a703e490SVasu Dev goto out_host_put; 999a703e490SVasu Dev } 1000a703e490SVasu Dev 10019a05753bSChris Leech if (npiv) { 10029f8f3aa6SChris Leech FCOE_NETDEV_DBG(netdev, "Setting vport names, " 10039f8f3aa6SChris Leech "%16.16llx %16.16llx\n", 10049a05753bSChris Leech vport->node_name, vport->port_name); 10059a05753bSChris Leech fc_set_wwnn(lport, vport->node_name); 10069a05753bSChris Leech fc_set_wwpn(lport, vport->port_name); 10079a05753bSChris Leech } 10089a05753bSChris Leech 1009ab6b85c1SVasu Dev /* configure lport network properties */ 1010af7f85d9SChris Leech rc = fcoe_netdev_config(lport, netdev); 1011ab6b85c1SVasu Dev if (rc) { 1012d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the " 1013d5488eb9SRobert Love "interface\n"); 101454b649f8SChris Leech goto out_lp_destroy; 1015ab6b85c1SVasu Dev } 101697c8389dSJoe Eykholt 1017a703e490SVasu Dev /* configure lport scsi host properties */ 10188ba00a4bSVasu Dev rc = fcoe_shost_config(lport, parent); 1019a703e490SVasu Dev if (rc) { 1020d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure shost for the " 1021d5488eb9SRobert Love "interface\n"); 102254b649f8SChris Leech goto out_lp_destroy; 1023a703e490SVasu Dev } 1024a703e490SVasu Dev 1025a703e490SVasu Dev /* Initialize the library */ 1026e10f8c66SJoe Eykholt rc = fcoe_libfc_config(lport, &fcoe->ctlr, &fcoe_libfc_fcn_templ, 1); 1027a703e490SVasu Dev if (rc) { 1028d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the " 1029d5488eb9SRobert Love "interface\n"); 1030a703e490SVasu Dev goto out_lp_destroy; 1031a703e490SVasu Dev } 1032a703e490SVasu Dev 1033e8af4d43SVasu Dev /* 1034e8af4d43SVasu Dev * fcoe_em_alloc() and fcoe_hostlist_add() both 10359a05753bSChris Leech * need to be atomic with respect to other changes to the 10369a05753bSChris Leech * hostlist since fcoe_em_alloc() looks for an existing EM 1037e8af4d43SVasu Dev * instance on host list updated by fcoe_hostlist_add(). 1038c863df33SChris Leech * 10399a05753bSChris Leech * This is currently handled through the fcoe_config_mutex 10409a05753bSChris Leech * begin held. 1041e8af4d43SVasu Dev */ 104272fa396bSVasu Dev if (!npiv) 104396316099SVasu Dev /* lport exch manager allocation */ 1044af7f85d9SChris Leech rc = fcoe_em_config(lport); 104572fa396bSVasu Dev else { 104672fa396bSVasu Dev shost = vport_to_shost(vport); 104772fa396bSVasu Dev n_port = shost_priv(shost); 104872fa396bSVasu Dev rc = fc_exch_mgr_list_clone(n_port, lport); 104996316099SVasu Dev } 105072fa396bSVasu Dev 105172fa396bSVasu Dev if (rc) { 105272fa396bSVasu Dev FCOE_NETDEV_DBG(netdev, "Could not configure the EM\n"); 105372fa396bSVasu Dev goto out_lp_destroy; 10549a05753bSChris Leech } 105596316099SVasu Dev 1056030f4e00SChris Leech fcoe_interface_get(fcoe); 1057af7f85d9SChris Leech return lport; 1058a703e490SVasu Dev 1059a703e490SVasu Dev out_lp_destroy: 1060af7f85d9SChris Leech fc_exch_mgr_free(lport); 1061a703e490SVasu Dev out_host_put: 1062af7f85d9SChris Leech scsi_host_put(lport->host); 1063af7f85d9SChris Leech out: 1064af7f85d9SChris Leech return ERR_PTR(rc); 1065a703e490SVasu Dev } 1066a703e490SVasu Dev 1067a703e490SVasu Dev /** 10681875f27eSRobert Love * fcoe_if_init() - Initialization routine for fcoe.ko 10691875f27eSRobert Love * 10701875f27eSRobert Love * Attaches the SW FCoE transport to the FC transport 1071a703e490SVasu Dev * 1072a703e490SVasu Dev * Returns: 0 on success 1073a703e490SVasu Dev */ 1074a703e490SVasu Dev static int __init fcoe_if_init(void) 1075a703e490SVasu Dev { 1076a703e490SVasu Dev /* attach to scsi transport */ 10778ca86f84SYi Zou fcoe_nport_scsi_transport = 10788ca86f84SYi Zou fc_attach_transport(&fcoe_nport_fc_functions); 10798ca86f84SYi Zou fcoe_vport_scsi_transport = 10808ca86f84SYi Zou fc_attach_transport(&fcoe_vport_fc_functions); 1081a703e490SVasu Dev 10828ca86f84SYi Zou if (!fcoe_nport_scsi_transport) { 1083d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); 1084a703e490SVasu Dev return -ENODEV; 1085a703e490SVasu Dev } 1086a703e490SVasu Dev 1087a703e490SVasu Dev return 0; 1088a703e490SVasu Dev } 1089a703e490SVasu Dev 1090a703e490SVasu Dev /** 10911875f27eSRobert Love * fcoe_if_exit() - Tear down fcoe.ko 10921875f27eSRobert Love * 10931875f27eSRobert Love * Detaches the SW FCoE transport from the FC transport 1094a703e490SVasu Dev * 1095a703e490SVasu Dev * Returns: 0 on success 1096a703e490SVasu Dev */ 1097a703e490SVasu Dev int __exit fcoe_if_exit(void) 1098a703e490SVasu Dev { 10998ca86f84SYi Zou fc_release_transport(fcoe_nport_scsi_transport); 11008ca86f84SYi Zou fc_release_transport(fcoe_vport_scsi_transport); 11018ca86f84SYi Zou fcoe_nport_scsi_transport = NULL; 11028ca86f84SYi Zou fcoe_vport_scsi_transport = NULL; 1103a703e490SVasu Dev return 0; 1104a703e490SVasu Dev } 1105a703e490SVasu Dev 1106a703e490SVasu Dev /** 11071875f27eSRobert Love * fcoe_percpu_thread_create() - Create a receive thread for an online CPU 11081875f27eSRobert Love * @cpu: The CPU index of the CPU to create a receive thread for 1109a703e490SVasu Dev */ 1110a703e490SVasu Dev static void fcoe_percpu_thread_create(unsigned int cpu) 1111a703e490SVasu Dev { 1112a703e490SVasu Dev struct fcoe_percpu_s *p; 1113a703e490SVasu Dev struct task_struct *thread; 1114a703e490SVasu Dev 1115a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1116a703e490SVasu Dev 11175c609ff9SEric Dumazet thread = kthread_create_on_node(fcoe_percpu_receive_thread, 11185c609ff9SEric Dumazet (void *)p, cpu_to_node(cpu), 11195c609ff9SEric Dumazet "fcoethread/%d", cpu); 1120a703e490SVasu Dev 1121e7a51997SJoe Eykholt if (likely(!IS_ERR(thread))) { 1122a703e490SVasu Dev kthread_bind(thread, cpu); 1123a703e490SVasu Dev wake_up_process(thread); 1124a703e490SVasu Dev 1125a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1126a703e490SVasu Dev p->thread = thread; 1127a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1128a703e490SVasu Dev } 1129a703e490SVasu Dev } 1130a703e490SVasu Dev 1131a703e490SVasu Dev /** 11321875f27eSRobert Love * fcoe_percpu_thread_destroy() - Remove the receive thread of a CPU 11331875f27eSRobert Love * @cpu: The CPU index of the CPU whose receive thread is to be destroyed 1134a703e490SVasu Dev * 1135a703e490SVasu Dev * Destroys a per-CPU Rx thread. Any pending skbs are moved to the 1136a703e490SVasu Dev * current CPU's Rx thread. If the thread being destroyed is bound to 1137a703e490SVasu Dev * the CPU processing this context the skbs will be freed. 1138a703e490SVasu Dev */ 1139a703e490SVasu Dev static void fcoe_percpu_thread_destroy(unsigned int cpu) 1140a703e490SVasu Dev { 1141a703e490SVasu Dev struct fcoe_percpu_s *p; 1142a703e490SVasu Dev struct task_struct *thread; 1143a703e490SVasu Dev struct page *crc_eof; 1144a703e490SVasu Dev struct sk_buff *skb; 1145a703e490SVasu Dev #ifdef CONFIG_SMP 1146a703e490SVasu Dev struct fcoe_percpu_s *p0; 1147f018b73aSJoe Eykholt unsigned targ_cpu = get_cpu(); 1148a703e490SVasu Dev #endif /* CONFIG_SMP */ 1149a703e490SVasu Dev 1150d5488eb9SRobert Love FCOE_DBG("Destroying receive thread for CPU %d\n", cpu); 1151a703e490SVasu Dev 1152a703e490SVasu Dev /* Prevent any new skbs from being queued for this CPU. */ 1153a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1154a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1155a703e490SVasu Dev thread = p->thread; 1156a703e490SVasu Dev p->thread = NULL; 1157a703e490SVasu Dev crc_eof = p->crc_eof_page; 1158a703e490SVasu Dev p->crc_eof_page = NULL; 1159a703e490SVasu Dev p->crc_eof_offset = 0; 1160a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1161a703e490SVasu Dev 1162a703e490SVasu Dev #ifdef CONFIG_SMP 1163a703e490SVasu Dev /* 1164a703e490SVasu Dev * Don't bother moving the skb's if this context is running 1165a703e490SVasu Dev * on the same CPU that is having its thread destroyed. This 1166a703e490SVasu Dev * can easily happen when the module is removed. 1167a703e490SVasu Dev */ 1168a703e490SVasu Dev if (cpu != targ_cpu) { 1169a703e490SVasu Dev p0 = &per_cpu(fcoe_percpu, targ_cpu); 1170a703e490SVasu Dev spin_lock_bh(&p0->fcoe_rx_list.lock); 1171a703e490SVasu Dev if (p0->thread) { 1172d5488eb9SRobert Love FCOE_DBG("Moving frames from CPU %d to CPU %d\n", 1173a703e490SVasu Dev cpu, targ_cpu); 1174a703e490SVasu Dev 1175a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1176a703e490SVasu Dev __skb_queue_tail(&p0->fcoe_rx_list, skb); 1177a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1178a703e490SVasu Dev } else { 1179a703e490SVasu Dev /* 1180a703e490SVasu Dev * The targeted CPU is not initialized and cannot accept 1181a703e490SVasu Dev * new skbs. Unlock the targeted CPU and drop the skbs 1182a703e490SVasu Dev * on the CPU that is going offline. 1183a703e490SVasu Dev */ 1184a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1185a703e490SVasu Dev kfree_skb(skb); 1186a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1187a703e490SVasu Dev } 1188a703e490SVasu Dev } else { 1189a703e490SVasu Dev /* 1190a703e490SVasu Dev * This scenario occurs when the module is being removed 1191a703e490SVasu Dev * and all threads are being destroyed. skbs will continue 1192a703e490SVasu Dev * to be shifted from the CPU thread that is being removed 1193a703e490SVasu Dev * to the CPU thread associated with the CPU that is processing 1194a703e490SVasu Dev * the module removal. Once there is only one CPU Rx thread it 1195a703e490SVasu Dev * will reach this case and we will drop all skbs and later 1196a703e490SVasu Dev * stop the thread. 1197a703e490SVasu Dev */ 1198a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1199a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1200a703e490SVasu Dev kfree_skb(skb); 1201a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1202a703e490SVasu Dev } 1203f018b73aSJoe Eykholt put_cpu(); 1204a703e490SVasu Dev #else 1205a703e490SVasu Dev /* 1206dd3fd72eSChris Leech * This a non-SMP scenario where the singular Rx thread is 1207a703e490SVasu Dev * being removed. Free all skbs and stop the thread. 1208a703e490SVasu Dev */ 1209a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1210a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1211a703e490SVasu Dev kfree_skb(skb); 1212a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1213a703e490SVasu Dev #endif 1214a703e490SVasu Dev 1215a703e490SVasu Dev if (thread) 1216a703e490SVasu Dev kthread_stop(thread); 1217a703e490SVasu Dev 1218a703e490SVasu Dev if (crc_eof) 1219a703e490SVasu Dev put_page(crc_eof); 1220a703e490SVasu Dev } 1221a703e490SVasu Dev 1222a703e490SVasu Dev /** 12231875f27eSRobert Love * fcoe_cpu_callback() - Handler for CPU hotplug events 12241875f27eSRobert Love * @nfb: The callback data block 12251875f27eSRobert Love * @action: The event triggering the callback 12261875f27eSRobert Love * @hcpu: The index of the CPU that the event is for 1227a703e490SVasu Dev * 12281875f27eSRobert Love * This creates or destroys per-CPU data for fcoe 1229a703e490SVasu Dev * 1230a703e490SVasu Dev * Returns NOTIFY_OK always. 1231a703e490SVasu Dev */ 1232a703e490SVasu Dev static int fcoe_cpu_callback(struct notifier_block *nfb, 1233a703e490SVasu Dev unsigned long action, void *hcpu) 1234a703e490SVasu Dev { 1235a703e490SVasu Dev unsigned cpu = (unsigned long)hcpu; 1236a703e490SVasu Dev 1237a703e490SVasu Dev switch (action) { 1238a703e490SVasu Dev case CPU_ONLINE: 1239a703e490SVasu Dev case CPU_ONLINE_FROZEN: 1240d5488eb9SRobert Love FCOE_DBG("CPU %x online: Create Rx thread\n", cpu); 1241a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 1242a703e490SVasu Dev break; 1243a703e490SVasu Dev case CPU_DEAD: 1244a703e490SVasu Dev case CPU_DEAD_FROZEN: 1245d5488eb9SRobert Love FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu); 1246a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 1247a703e490SVasu Dev break; 1248a703e490SVasu Dev default: 1249a703e490SVasu Dev break; 1250a703e490SVasu Dev } 1251a703e490SVasu Dev return NOTIFY_OK; 1252a703e490SVasu Dev } 1253a703e490SVasu Dev 1254a703e490SVasu Dev /** 1255064287eeSKiran Patil * fcoe_select_cpu() - Selects CPU to handle post-processing of incoming 1256064287eeSKiran Patil * command. 1257064287eeSKiran Patil * 1258d272281cSVasu Dev * This routine selects next CPU based on cpumask to distribute 1259d272281cSVasu Dev * incoming requests in round robin. 1260064287eeSKiran Patil * 1261d272281cSVasu Dev * Returns: int CPU number 1262064287eeSKiran Patil */ 1263d272281cSVasu Dev static inline unsigned int fcoe_select_cpu(void) 1264064287eeSKiran Patil { 1265064287eeSKiran Patil static unsigned int selected_cpu; 1266064287eeSKiran Patil 1267064287eeSKiran Patil selected_cpu = cpumask_next(selected_cpu, cpu_online_mask); 1268064287eeSKiran Patil if (selected_cpu >= nr_cpu_ids) 1269064287eeSKiran Patil selected_cpu = cpumask_first(cpu_online_mask); 1270d272281cSVasu Dev 1271064287eeSKiran Patil return selected_cpu; 1272064287eeSKiran Patil } 1273064287eeSKiran Patil 1274064287eeSKiran Patil /** 12751875f27eSRobert Love * fcoe_rcv() - Receive packets from a net device 12761875f27eSRobert Love * @skb: The received packet 12771875f27eSRobert Love * @netdev: The net device that the packet was received on 12781875f27eSRobert Love * @ptype: The packet type context 12791875f27eSRobert Love * @olddev: The last device net device 1280a703e490SVasu Dev * 12811875f27eSRobert Love * This routine is called by NET_RX_SOFTIRQ. It receives a packet, builds a 12821875f27eSRobert Love * FC frame and passes the frame to libfc. 1283a703e490SVasu Dev * 1284a703e490SVasu Dev * Returns: 0 for success 1285a703e490SVasu Dev */ 12861875f27eSRobert Love int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, 1287a703e490SVasu Dev struct packet_type *ptype, struct net_device *olddev) 1288a703e490SVasu Dev { 12891875f27eSRobert Love struct fc_lport *lport; 1290a703e490SVasu Dev struct fcoe_rcv_info *fr; 1291259ad85dSChris Leech struct fcoe_interface *fcoe; 1292a703e490SVasu Dev struct fc_frame_header *fh; 1293a703e490SVasu Dev struct fcoe_percpu_s *fps; 1294519e5135SVasu Dev struct ethhdr *eh; 1295b2f0091fSVasu Dev unsigned int cpu; 1296a703e490SVasu Dev 1297259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type); 12981875f27eSRobert Love lport = fcoe->ctlr.lp; 12991875f27eSRobert Love if (unlikely(!lport)) { 13001875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "Cannot find hba structure"); 1301a703e490SVasu Dev goto err2; 1302a703e490SVasu Dev } 13031875f27eSRobert Love if (!lport->link_up) 130497c8389dSJoe Eykholt goto err2; 1305a703e490SVasu Dev 13061875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "skb_info: len:%d data_len:%d head:%p " 1307d5488eb9SRobert Love "data:%p tail:%p end:%p sum:%d dev:%s", 1308d5488eb9SRobert Love skb->len, skb->data_len, skb->head, skb->data, 1309d5488eb9SRobert Love skb_tail_pointer(skb), skb_end_pointer(skb), 1310d5488eb9SRobert Love skb->csum, skb->dev ? skb->dev->name : "<NULL>"); 1311a703e490SVasu Dev 1312519e5135SVasu Dev eh = eth_hdr(skb); 1313519e5135SVasu Dev 1314519e5135SVasu Dev if (is_fip_mode(&fcoe->ctlr) && 1315519e5135SVasu Dev compare_ether_addr(eh->h_source, fcoe->ctlr.dest_addr)) { 1316519e5135SVasu Dev FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n", 1317519e5135SVasu Dev eh->h_source); 1318a703e490SVasu Dev goto err; 1319a703e490SVasu Dev } 1320a703e490SVasu Dev 1321a703e490SVasu Dev /* 1322a703e490SVasu Dev * Check for minimum frame length, and make sure required FCoE 1323a703e490SVasu Dev * and FC headers are pulled into the linear data area. 1324a703e490SVasu Dev */ 1325a703e490SVasu Dev if (unlikely((skb->len < FCOE_MIN_FRAME) || 1326a703e490SVasu Dev !pskb_may_pull(skb, FCOE_HEADER_LEN))) 1327a703e490SVasu Dev goto err; 1328a703e490SVasu Dev 1329a703e490SVasu Dev skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); 1330a703e490SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 1331a703e490SVasu Dev 13320ee31cb5SRobert Love if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id)) { 13330ee31cb5SRobert Love FCOE_NETDEV_DBG(netdev, "FC frame d_id mismatch with MAC:%pM\n", 13340ee31cb5SRobert Love eh->h_dest); 13350ee31cb5SRobert Love goto err; 13360ee31cb5SRobert Love } 13370ee31cb5SRobert Love 1338a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 13391875f27eSRobert Love fr->fr_dev = lport; 1340a703e490SVasu Dev 1341a703e490SVasu Dev /* 1342b2f0091fSVasu Dev * In case the incoming frame's exchange is originated from 1343b2f0091fSVasu Dev * the initiator, then received frame's exchange id is ANDed 1344b2f0091fSVasu Dev * with fc_cpu_mask bits to get the same cpu on which exchange 1345d272281cSVasu Dev * was originated, otherwise select cpu using rx exchange id 1346d272281cSVasu Dev * or fcoe_select_cpu(). 1347a703e490SVasu Dev */ 1348b2f0091fSVasu Dev if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX) 1349b2f0091fSVasu Dev cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask; 1350064287eeSKiran Patil else { 1351d272281cSVasu Dev if (ntohs(fh->fh_rx_id) == FC_XID_UNKNOWN) 1352d272281cSVasu Dev cpu = fcoe_select_cpu(); 1353d272281cSVasu Dev else 135429bdd2bbSKiran Patil cpu = ntohs(fh->fh_rx_id) & fc_cpu_mask; 1355064287eeSKiran Patil } 1356324f6678SVasu Dev 1357324f6678SVasu Dev if (cpu >= nr_cpu_ids) 1358324f6678SVasu Dev goto err; 1359324f6678SVasu Dev 1360a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1361a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1362a703e490SVasu Dev if (unlikely(!fps->thread)) { 1363a703e490SVasu Dev /* 1364a703e490SVasu Dev * The targeted CPU is not ready, let's target 1365a703e490SVasu Dev * the first CPU now. For non-SMP systems this 1366a703e490SVasu Dev * will check the same CPU twice. 1367a703e490SVasu Dev */ 13681875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "CPU is online, but no receive thread " 1369d5488eb9SRobert Love "ready for incoming skb- using first online " 1370d5488eb9SRobert Love "CPU.\n"); 1371a703e490SVasu Dev 1372a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 13736957177fSRusty Russell cpu = cpumask_first(cpu_online_mask); 1374a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1375a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1376a703e490SVasu Dev if (!fps->thread) { 1377a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1378a703e490SVasu Dev goto err; 1379a703e490SVasu Dev } 1380a703e490SVasu Dev } 1381a703e490SVasu Dev 1382a703e490SVasu Dev /* 1383a703e490SVasu Dev * We now have a valid CPU that we're targeting for 1384a703e490SVasu Dev * this skb. We also have this receive thread locked, 1385a703e490SVasu Dev * so we're free to queue skbs into it's queue. 1386a703e490SVasu Dev */ 1387859b7b64SChris Leech 1388859b7b64SChris Leech /* If this is a SCSI-FCP frame, and this is already executing on the 1389859b7b64SChris Leech * correct CPU, and the queue for this CPU is empty, then go ahead 1390859b7b64SChris Leech * and process the frame directly in the softirq context. 1391859b7b64SChris Leech * This lets us process completions without context switching from the 1392859b7b64SChris Leech * NET_RX softirq, to our receive processing thread, and then back to 1393859b7b64SChris Leech * BLOCK softirq context. 1394859b7b64SChris Leech */ 1395859b7b64SChris Leech if (fh->fh_type == FC_TYPE_FCP && 1396859b7b64SChris Leech cpu == smp_processor_id() && 1397859b7b64SChris Leech skb_queue_empty(&fps->fcoe_rx_list)) { 1398859b7b64SChris Leech spin_unlock_bh(&fps->fcoe_rx_list.lock); 1399859b7b64SChris Leech fcoe_recv_frame(skb); 1400859b7b64SChris Leech } else { 1401a703e490SVasu Dev __skb_queue_tail(&fps->fcoe_rx_list, skb); 1402a703e490SVasu Dev if (fps->fcoe_rx_list.qlen == 1) 1403a703e490SVasu Dev wake_up_process(fps->thread); 1404a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1405859b7b64SChris Leech } 1406a703e490SVasu Dev 1407a703e490SVasu Dev return 0; 1408a703e490SVasu Dev err: 1409f018b73aSJoe Eykholt per_cpu_ptr(lport->dev_stats, get_cpu())->ErrorFrames++; 1410f018b73aSJoe Eykholt put_cpu(); 1411a703e490SVasu Dev err2: 1412a703e490SVasu Dev kfree_skb(skb); 1413a703e490SVasu Dev return -1; 1414a703e490SVasu Dev } 1415a703e490SVasu Dev 1416a703e490SVasu Dev /** 14178597ae8bSBhanu Prakash Gollapudi * fcoe_alloc_paged_crc_eof() - Allocate a page to be used for the trailer CRC 14181875f27eSRobert Love * @skb: The packet to be transmitted 14191875f27eSRobert Love * @tlen: The total length of the trailer 14201875f27eSRobert Love * 1421a703e490SVasu Dev * Returns: 0 for success 1422a703e490SVasu Dev */ 14238597ae8bSBhanu Prakash Gollapudi static int fcoe_alloc_paged_crc_eof(struct sk_buff *skb, int tlen) 1424a703e490SVasu Dev { 1425a703e490SVasu Dev struct fcoe_percpu_s *fps; 14268597ae8bSBhanu Prakash Gollapudi int rc; 1427a703e490SVasu Dev 1428a703e490SVasu Dev fps = &get_cpu_var(fcoe_percpu); 14298597ae8bSBhanu Prakash Gollapudi rc = fcoe_get_paged_crc_eof(skb, tlen, fps); 1430a703e490SVasu Dev put_cpu_var(fcoe_percpu); 1431a703e490SVasu Dev 14328597ae8bSBhanu Prakash Gollapudi return rc; 1433a703e490SVasu Dev } 1434a703e490SVasu Dev 1435a703e490SVasu Dev /** 14361875f27eSRobert Love * fcoe_xmit() - Transmit a FCoE frame 14371875f27eSRobert Love * @lport: The local port that the frame is to be transmitted for 14381875f27eSRobert Love * @fp: The frame to be transmitted 1439a703e490SVasu Dev * 1440a703e490SVasu Dev * Return: 0 for success 1441a703e490SVasu Dev */ 14421875f27eSRobert Love int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp) 1443a703e490SVasu Dev { 14444bb6b515SVasu Dev int wlen; 1445a703e490SVasu Dev u32 crc; 1446a703e490SVasu Dev struct ethhdr *eh; 1447a703e490SVasu Dev struct fcoe_crc_eof *cp; 1448a703e490SVasu Dev struct sk_buff *skb; 1449a703e490SVasu Dev struct fcoe_dev_stats *stats; 1450a703e490SVasu Dev struct fc_frame_header *fh; 1451a703e490SVasu Dev unsigned int hlen; /* header length implies the version */ 1452a703e490SVasu Dev unsigned int tlen; /* trailer length */ 1453a703e490SVasu Dev unsigned int elen; /* eth header, may include vlan */ 14541875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 14558597ae8bSBhanu Prakash Gollapudi struct fcoe_interface *fcoe = port->priv; 1456a703e490SVasu Dev u8 sof, eof; 1457a703e490SVasu Dev struct fcoe_hdr *hp; 1458a703e490SVasu Dev 1459a703e490SVasu Dev WARN_ON((fr_len(fp) % sizeof(u32)) != 0); 1460a703e490SVasu Dev 1461a703e490SVasu Dev fh = fc_frame_header_get(fp); 146297c8389dSJoe Eykholt skb = fp_skb(fp); 146397c8389dSJoe Eykholt wlen = skb->len / FCOE_WORD_TO_BYTE; 146497c8389dSJoe Eykholt 14651875f27eSRobert Love if (!lport->link_up) { 14663caf02eeSDan Carpenter kfree_skb(skb); 146797c8389dSJoe Eykholt return 0; 1468a703e490SVasu Dev } 1469a703e490SVasu Dev 14709860eeb4SJoe Eykholt if (unlikely(fh->fh_type == FC_TYPE_ELS) && 14711875f27eSRobert Love fcoe_ctlr_els_send(&fcoe->ctlr, lport, skb)) 147297c8389dSJoe Eykholt return 0; 147397c8389dSJoe Eykholt 1474a703e490SVasu Dev sof = fr_sof(fp); 1475a703e490SVasu Dev eof = fr_eof(fp); 1476a703e490SVasu Dev 14774e57e1cbSVasu Dev elen = sizeof(struct ethhdr); 1478a703e490SVasu Dev hlen = sizeof(struct fcoe_hdr); 1479a703e490SVasu Dev tlen = sizeof(struct fcoe_crc_eof); 1480a703e490SVasu Dev wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; 1481a703e490SVasu Dev 1482a703e490SVasu Dev /* crc offload */ 14831875f27eSRobert Love if (likely(lport->crc_offload)) { 1484a703e490SVasu Dev skb->ip_summed = CHECKSUM_PARTIAL; 1485a703e490SVasu Dev skb->csum_start = skb_headroom(skb); 1486a703e490SVasu Dev skb->csum_offset = skb->len; 1487a703e490SVasu Dev crc = 0; 1488a703e490SVasu Dev } else { 1489a703e490SVasu Dev skb->ip_summed = CHECKSUM_NONE; 1490a703e490SVasu Dev crc = fcoe_fc_crc(fp); 1491a703e490SVasu Dev } 1492a703e490SVasu Dev 1493014f5c3fSChris Leech /* copy port crc and eof to the skb buff */ 1494a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1495a703e490SVasu Dev skb_frag_t *frag; 14968597ae8bSBhanu Prakash Gollapudi if (fcoe_alloc_paged_crc_eof(skb, tlen)) { 1497a703e490SVasu Dev kfree_skb(skb); 1498a703e490SVasu Dev return -ENOMEM; 1499a703e490SVasu Dev } 1500a703e490SVasu Dev frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; 1501a703e490SVasu Dev cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ) 1502a703e490SVasu Dev + frag->page_offset; 1503a703e490SVasu Dev } else { 1504a703e490SVasu Dev cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); 1505a703e490SVasu Dev } 1506a703e490SVasu Dev 1507a703e490SVasu Dev memset(cp, 0, sizeof(*cp)); 1508a703e490SVasu Dev cp->fcoe_eof = eof; 1509a703e490SVasu Dev cp->fcoe_crc32 = cpu_to_le32(~crc); 1510a703e490SVasu Dev 1511a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1512a703e490SVasu Dev kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ); 1513a703e490SVasu Dev cp = NULL; 1514a703e490SVasu Dev } 1515a703e490SVasu Dev 1516014f5c3fSChris Leech /* adjust skb network/transport offsets to match mac/fcoe/port */ 1517a703e490SVasu Dev skb_push(skb, elen + hlen); 1518a703e490SVasu Dev skb_reset_mac_header(skb); 1519a703e490SVasu Dev skb_reset_network_header(skb); 1520a703e490SVasu Dev skb->mac_len = elen; 1521a703e490SVasu Dev skb->protocol = htons(ETH_P_FCOE); 1522d1483bb9SVasu Dev if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN && 1523d1483bb9SVasu Dev fcoe->realdev->features & NETIF_F_HW_VLAN_TX) { 1524d1483bb9SVasu Dev skb->vlan_tci = VLAN_TAG_PRESENT | 1525d1483bb9SVasu Dev vlan_dev_vlan_id(fcoe->netdev); 1526d1483bb9SVasu Dev skb->dev = fcoe->realdev; 1527d1483bb9SVasu Dev } else 15283fe9a0baSChris Leech skb->dev = fcoe->netdev; 1529a703e490SVasu Dev 1530a703e490SVasu Dev /* fill up mac and fcoe headers */ 1531a703e490SVasu Dev eh = eth_hdr(skb); 1532a703e490SVasu Dev eh->h_proto = htons(ETH_P_FCOE); 15333fe9a0baSChris Leech memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN); 1534cd229e42SJoe Eykholt if (fcoe->ctlr.map_dest) 1535cd229e42SJoe Eykholt memcpy(eh->h_dest + 3, fh->fh_d_id, 3); 1536a703e490SVasu Dev 15373fe9a0baSChris Leech if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN)) 15383fe9a0baSChris Leech memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN); 1539a703e490SVasu Dev else 154011b56188SChris Leech memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); 1541a703e490SVasu Dev 1542a703e490SVasu Dev hp = (struct fcoe_hdr *)(eh + 1); 1543a703e490SVasu Dev memset(hp, 0, sizeof(*hp)); 1544a703e490SVasu Dev if (FC_FCOE_VER) 1545a703e490SVasu Dev FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); 1546a703e490SVasu Dev hp->fcoe_sof = sof; 1547a703e490SVasu Dev 1548a703e490SVasu Dev /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ 15491875f27eSRobert Love if (lport->seq_offload && fr_max_payload(fp)) { 1550a703e490SVasu Dev skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; 1551a703e490SVasu Dev skb_shinfo(skb)->gso_size = fr_max_payload(fp); 1552a703e490SVasu Dev } else { 1553a703e490SVasu Dev skb_shinfo(skb)->gso_type = 0; 1554a703e490SVasu Dev skb_shinfo(skb)->gso_size = 0; 1555a703e490SVasu Dev } 1556a703e490SVasu Dev /* update tx stats: regardless if LLD fails */ 1557f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1558a703e490SVasu Dev stats->TxFrames++; 1559a703e490SVasu Dev stats->TxWords += wlen; 1560f018b73aSJoe Eykholt put_cpu(); 1561a703e490SVasu Dev 1562a703e490SVasu Dev /* send down to lld */ 15631875f27eSRobert Love fr_dev(fp) = lport; 1564980f5156SVasu Dev fcoe_port_send(port, skb); 1565a703e490SVasu Dev return 0; 1566a703e490SVasu Dev } 1567a703e490SVasu Dev 1568a703e490SVasu Dev /** 15691875f27eSRobert Love * fcoe_percpu_flush_done() - Indicate per-CPU queue flush completion 15701875f27eSRobert Love * @skb: The completed skb (argument required by destructor) 1571e7a51997SJoe Eykholt */ 1572e7a51997SJoe Eykholt static void fcoe_percpu_flush_done(struct sk_buff *skb) 1573e7a51997SJoe Eykholt { 1574e7a51997SJoe Eykholt complete(&fcoe_flush_completion); 1575e7a51997SJoe Eykholt } 1576e7a51997SJoe Eykholt 1577e7a51997SJoe Eykholt /** 157852ee8321SVasu Dev * fcoe_filter_frames() - filter out bad fcoe frames, i.e. bad CRC 157952ee8321SVasu Dev * @lport: The local port the frame was received on 158052ee8321SVasu Dev * @fp: The received frame 158152ee8321SVasu Dev * 158252ee8321SVasu Dev * Return: 0 on passing filtering checks 158352ee8321SVasu Dev */ 158452ee8321SVasu Dev static inline int fcoe_filter_frames(struct fc_lport *lport, 158552ee8321SVasu Dev struct fc_frame *fp) 158652ee8321SVasu Dev { 158752ee8321SVasu Dev struct fcoe_interface *fcoe; 158852ee8321SVasu Dev struct fc_frame_header *fh; 158952ee8321SVasu Dev struct sk_buff *skb = (struct sk_buff *)fp; 159052ee8321SVasu Dev struct fcoe_dev_stats *stats; 159152ee8321SVasu Dev 159252ee8321SVasu Dev /* 159352ee8321SVasu Dev * We only check CRC if no offload is available and if it is 159452ee8321SVasu Dev * it's solicited data, in which case, the FCP layer would 159552ee8321SVasu Dev * check it during the copy. 159652ee8321SVasu Dev */ 159752ee8321SVasu Dev if (lport->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY) 159852ee8321SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 159952ee8321SVasu Dev else 160052ee8321SVasu Dev fr_flags(fp) |= FCPHF_CRC_UNCHECKED; 160152ee8321SVasu Dev 160252ee8321SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 160352ee8321SVasu Dev fh = fc_frame_header_get(fp); 160452ee8321SVasu Dev if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && fh->fh_type == FC_TYPE_FCP) 160552ee8321SVasu Dev return 0; 160652ee8321SVasu Dev 16078597ae8bSBhanu Prakash Gollapudi fcoe = ((struct fcoe_port *)lport_priv(lport))->priv; 160852ee8321SVasu Dev if (is_fip_mode(&fcoe->ctlr) && fc_frame_payload_op(fp) == ELS_LOGO && 160952ee8321SVasu Dev ntoh24(fh->fh_s_id) == FC_FID_FLOGI) { 161052ee8321SVasu Dev FCOE_DBG("fcoe: dropping FCoE lport LOGO in fip mode\n"); 161152ee8321SVasu Dev return -EINVAL; 161252ee8321SVasu Dev } 161352ee8321SVasu Dev 1614f2f96d20SDan Carpenter if (!(fr_flags(fp) & FCPHF_CRC_UNCHECKED) || 161552ee8321SVasu Dev le32_to_cpu(fr_crc(fp)) == ~crc32(~0, skb->data, skb->len)) { 161652ee8321SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 161752ee8321SVasu Dev return 0; 161852ee8321SVasu Dev } 161952ee8321SVasu Dev 162052ee8321SVasu Dev stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 162152ee8321SVasu Dev stats->InvalidCRCCount++; 162252ee8321SVasu Dev if (stats->InvalidCRCCount < 5) 162352ee8321SVasu Dev printk(KERN_WARNING "fcoe: dropping frame with CRC error\n"); 162452ee8321SVasu Dev return -EINVAL; 162552ee8321SVasu Dev } 162652ee8321SVasu Dev 162752ee8321SVasu Dev /** 1628859b7b64SChris Leech * fcoe_recv_frame() - process a single received frame 1629859b7b64SChris Leech * @skb: frame to process 1630a703e490SVasu Dev */ 1631859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb) 1632a703e490SVasu Dev { 1633a703e490SVasu Dev u32 fr_len; 16341875f27eSRobert Love struct fc_lport *lport; 1635a703e490SVasu Dev struct fcoe_rcv_info *fr; 1636a703e490SVasu Dev struct fcoe_dev_stats *stats; 1637a703e490SVasu Dev struct fcoe_crc_eof crc_eof; 1638a703e490SVasu Dev struct fc_frame *fp; 1639014f5c3fSChris Leech struct fcoe_port *port; 1640a703e490SVasu Dev struct fcoe_hdr *hp; 1641a703e490SVasu Dev 1642a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 16431875f27eSRobert Love lport = fr->fr_dev; 16441875f27eSRobert Love if (unlikely(!lport)) { 1645e7a51997SJoe Eykholt if (skb->destructor != fcoe_percpu_flush_done) 1646e7a51997SJoe Eykholt FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb"); 1647a703e490SVasu Dev kfree_skb(skb); 1648859b7b64SChris Leech return; 1649a703e490SVasu Dev } 1650a703e490SVasu Dev 1651d5488eb9SRobert Love FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d " 1652d5488eb9SRobert Love "head:%p data:%p tail:%p end:%p sum:%d dev:%s", 1653a703e490SVasu Dev skb->len, skb->data_len, 1654a703e490SVasu Dev skb->head, skb->data, skb_tail_pointer(skb), 1655a703e490SVasu Dev skb_end_pointer(skb), skb->csum, 1656a703e490SVasu Dev skb->dev ? skb->dev->name : "<NULL>"); 1657a703e490SVasu Dev 16581875f27eSRobert Love port = lport_priv(lport); 1659a703e490SVasu Dev if (skb_is_nonlinear(skb)) 1660a703e490SVasu Dev skb_linearize(skb); /* not ideal */ 1661a703e490SVasu Dev 1662a703e490SVasu Dev /* 1663a703e490SVasu Dev * Frame length checks and setting up the header pointers 1664a703e490SVasu Dev * was done in fcoe_rcv already. 1665a703e490SVasu Dev */ 1666a703e490SVasu Dev hp = (struct fcoe_hdr *) skb_network_header(skb); 1667a703e490SVasu Dev 1668f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1669a703e490SVasu Dev if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { 1670a703e490SVasu Dev if (stats->ErrorFrames < 5) 1671d5488eb9SRobert Love printk(KERN_WARNING "fcoe: FCoE version " 1672a703e490SVasu Dev "mismatch: The frame has " 1673a703e490SVasu Dev "version %x, but the " 1674a703e490SVasu Dev "initiator supports version " 1675a703e490SVasu Dev "%x\n", FC_FCOE_DECAPS_VER(hp), 1676a703e490SVasu Dev FC_FCOE_VER); 1677f018b73aSJoe Eykholt goto drop; 1678a703e490SVasu Dev } 1679a703e490SVasu Dev 1680a703e490SVasu Dev skb_pull(skb, sizeof(struct fcoe_hdr)); 1681a703e490SVasu Dev fr_len = skb->len - sizeof(struct fcoe_crc_eof); 1682a703e490SVasu Dev 1683a703e490SVasu Dev stats->RxFrames++; 1684a703e490SVasu Dev stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; 1685a703e490SVasu Dev 1686a703e490SVasu Dev fp = (struct fc_frame *)skb; 1687a703e490SVasu Dev fc_frame_init(fp); 16881875f27eSRobert Love fr_dev(fp) = lport; 1689a703e490SVasu Dev fr_sof(fp) = hp->fcoe_sof; 1690a703e490SVasu Dev 1691a703e490SVasu Dev /* Copy out the CRC and EOF trailer for access */ 1692f018b73aSJoe Eykholt if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) 1693f018b73aSJoe Eykholt goto drop; 1694a703e490SVasu Dev fr_eof(fp) = crc_eof.fcoe_eof; 1695a703e490SVasu Dev fr_crc(fp) = crc_eof.fcoe_crc32; 1696f018b73aSJoe Eykholt if (pskb_trim(skb, fr_len)) 1697f018b73aSJoe Eykholt goto drop; 1698a703e490SVasu Dev 169952ee8321SVasu Dev if (!fcoe_filter_frames(lport, fp)) { 1700f018b73aSJoe Eykholt put_cpu(); 17011875f27eSRobert Love fc_exch_recv(lport, fp); 1702f018b73aSJoe Eykholt return; 170352ee8321SVasu Dev } 1704f018b73aSJoe Eykholt drop: 1705f018b73aSJoe Eykholt stats->ErrorFrames++; 1706f018b73aSJoe Eykholt put_cpu(); 1707f018b73aSJoe Eykholt kfree_skb(skb); 1708a703e490SVasu Dev } 1709859b7b64SChris Leech 1710859b7b64SChris Leech /** 1711859b7b64SChris Leech * fcoe_percpu_receive_thread() - The per-CPU packet receive thread 1712859b7b64SChris Leech * @arg: The per-CPU context 1713859b7b64SChris Leech * 1714859b7b64SChris Leech * Return: 0 for success 1715859b7b64SChris Leech */ 1716859b7b64SChris Leech int fcoe_percpu_receive_thread(void *arg) 1717859b7b64SChris Leech { 1718859b7b64SChris Leech struct fcoe_percpu_s *p = arg; 1719859b7b64SChris Leech struct sk_buff *skb; 1720859b7b64SChris Leech 1721859b7b64SChris Leech set_user_nice(current, -20); 1722859b7b64SChris Leech 1723859b7b64SChris Leech while (!kthread_should_stop()) { 1724859b7b64SChris Leech 1725859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1726859b7b64SChris Leech while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) { 1727859b7b64SChris Leech set_current_state(TASK_INTERRUPTIBLE); 1728859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1729859b7b64SChris Leech schedule(); 1730859b7b64SChris Leech set_current_state(TASK_RUNNING); 1731859b7b64SChris Leech if (kthread_should_stop()) 1732859b7b64SChris Leech return 0; 1733859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1734859b7b64SChris Leech } 1735859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1736859b7b64SChris Leech fcoe_recv_frame(skb); 1737859b7b64SChris Leech } 1738a703e490SVasu Dev return 0; 1739a703e490SVasu Dev } 1740a703e490SVasu Dev 1741a703e490SVasu Dev /** 17421875f27eSRobert Love * fcoe_dev_setup() - Setup the link change notification interface 1743a703e490SVasu Dev */ 1744b0d428adSRandy Dunlap static void fcoe_dev_setup(void) 1745a703e490SVasu Dev { 1746a703e490SVasu Dev register_netdevice_notifier(&fcoe_notifier); 1747a703e490SVasu Dev } 1748a703e490SVasu Dev 1749a703e490SVasu Dev /** 17501875f27eSRobert Love * fcoe_dev_cleanup() - Cleanup the link change notification interface 1751a703e490SVasu Dev */ 1752a703e490SVasu Dev static void fcoe_dev_cleanup(void) 1753a703e490SVasu Dev { 1754a703e490SVasu Dev unregister_netdevice_notifier(&fcoe_notifier); 1755a703e490SVasu Dev } 1756a703e490SVasu Dev 1757a703e490SVasu Dev /** 17581875f27eSRobert Love * fcoe_device_notification() - Handler for net device events 17591875f27eSRobert Love * @notifier: The context of the notification 17601875f27eSRobert Love * @event: The type of event 17611875f27eSRobert Love * @ptr: The net device that the event was on 1762a703e490SVasu Dev * 17631875f27eSRobert Love * This function is called by the Ethernet driver in case of link change event. 1764a703e490SVasu Dev * 1765a703e490SVasu Dev * Returns: 0 for success 1766a703e490SVasu Dev */ 1767a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *notifier, 1768a703e490SVasu Dev ulong event, void *ptr) 1769a703e490SVasu Dev { 17701875f27eSRobert Love struct fc_lport *lport = NULL; 17711d1b88dcSVasu Dev struct net_device *netdev = ptr; 1772014f5c3fSChris Leech struct fcoe_interface *fcoe; 17732e70e241SChris Leech struct fcoe_port *port; 1774a703e490SVasu Dev struct fcoe_dev_stats *stats; 177597c8389dSJoe Eykholt u32 link_possible = 1; 1776a703e490SVasu Dev u32 mfs; 1777a703e490SVasu Dev int rc = NOTIFY_OK; 1778a703e490SVasu Dev 1779014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 178025024989SChris Leech if (fcoe->netdev == netdev) { 17811875f27eSRobert Love lport = fcoe->ctlr.lp; 1782a703e490SVasu Dev break; 1783a703e490SVasu Dev } 1784a703e490SVasu Dev } 17851875f27eSRobert Love if (!lport) { 1786a703e490SVasu Dev rc = NOTIFY_DONE; 1787a703e490SVasu Dev goto out; 1788a703e490SVasu Dev } 1789a703e490SVasu Dev 1790a703e490SVasu Dev switch (event) { 1791a703e490SVasu Dev case NETDEV_DOWN: 1792a703e490SVasu Dev case NETDEV_GOING_DOWN: 179397c8389dSJoe Eykholt link_possible = 0; 1794a703e490SVasu Dev break; 1795a703e490SVasu Dev case NETDEV_UP: 1796a703e490SVasu Dev case NETDEV_CHANGE: 1797a703e490SVasu Dev break; 1798a703e490SVasu Dev case NETDEV_CHANGEMTU: 17997221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) 18007221d7e5SYi Zou break; 18011d1b88dcSVasu Dev mfs = netdev->mtu - (sizeof(struct fcoe_hdr) + 1802a703e490SVasu Dev sizeof(struct fcoe_crc_eof)); 1803a703e490SVasu Dev if (mfs >= FC_MIN_MAX_FRAME) 18041875f27eSRobert Love fc_set_mfs(lport, mfs); 1805a703e490SVasu Dev break; 1806a703e490SVasu Dev case NETDEV_REGISTER: 1807a703e490SVasu Dev break; 18082e70e241SChris Leech case NETDEV_UNREGISTER: 18092e70e241SChris Leech list_del(&fcoe->list); 18102e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 18112ca32b48STejun Heo queue_work(fcoe_wq, &port->destroy_work); 18122e70e241SChris Leech goto out; 18132e70e241SChris Leech break; 181454a5b21dSYi Zou case NETDEV_FEAT_CHANGE: 181554a5b21dSYi Zou fcoe_netdev_features_change(lport, netdev); 181654a5b21dSYi Zou break; 1817a703e490SVasu Dev default: 18181d1b88dcSVasu Dev FCOE_NETDEV_DBG(netdev, "Unknown event %ld " 1819d5488eb9SRobert Love "from netdev netlink\n", event); 1820a703e490SVasu Dev } 18215e4f8fe7SRobert Love 18225e4f8fe7SRobert Love fcoe_link_speed_update(lport); 18235e4f8fe7SRobert Love 18241875f27eSRobert Love if (link_possible && !fcoe_link_ok(lport)) 18253fe9a0baSChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 18263fe9a0baSChris Leech else if (fcoe_ctlr_link_down(&fcoe->ctlr)) { 1827f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1828a703e490SVasu Dev stats->LinkFailureCount++; 1829f018b73aSJoe Eykholt put_cpu(); 18301875f27eSRobert Love fcoe_clean_pending_queue(lport); 1831a703e490SVasu Dev } 1832a703e490SVasu Dev out: 1833a703e490SVasu Dev return rc; 1834a703e490SVasu Dev } 1835a703e490SVasu Dev 1836a703e490SVasu Dev /** 183755a66d3cSVasu Dev * fcoe_disable() - Disables a FCoE interface 183878a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 183955a66d3cSVasu Dev * 184078a58246SYi Zou * Called from fcoe transport. 184155a66d3cSVasu Dev * 184255a66d3cSVasu Dev * Returns: 0 for success 184355a66d3cSVasu Dev */ 184478a58246SYi Zou static int fcoe_disable(struct net_device *netdev) 184555a66d3cSVasu Dev { 184655a66d3cSVasu Dev struct fcoe_interface *fcoe; 184755a66d3cSVasu Dev int rc = 0; 184855a66d3cSVasu Dev 184955a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 185055a66d3cSVasu Dev 1851ee5df628SRobert Love rtnl_lock(); 185255a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 185355a66d3cSVasu Dev rtnl_unlock(); 185455a66d3cSVasu Dev 18559ee50e48SChris Leech if (fcoe) { 18569ee50e48SChris Leech fcoe_ctlr_link_down(&fcoe->ctlr); 18579d4cbc05SVasu Dev fcoe_clean_pending_queue(fcoe->ctlr.lp); 18589ee50e48SChris Leech } else 185955a66d3cSVasu Dev rc = -ENODEV; 186055a66d3cSVasu Dev 186155a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 186255a66d3cSVasu Dev return rc; 186355a66d3cSVasu Dev } 186455a66d3cSVasu Dev 186555a66d3cSVasu Dev /** 186655a66d3cSVasu Dev * fcoe_enable() - Enables a FCoE interface 186778a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 186855a66d3cSVasu Dev * 186978a58246SYi Zou * Called from fcoe transport. 187055a66d3cSVasu Dev * 187155a66d3cSVasu Dev * Returns: 0 for success 187255a66d3cSVasu Dev */ 187378a58246SYi Zou static int fcoe_enable(struct net_device *netdev) 187455a66d3cSVasu Dev { 187555a66d3cSVasu Dev struct fcoe_interface *fcoe; 187655a66d3cSVasu Dev int rc = 0; 187755a66d3cSVasu Dev 187855a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 1879ee5df628SRobert Love rtnl_lock(); 188055a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 188155a66d3cSVasu Dev rtnl_unlock(); 188255a66d3cSVasu Dev 18839d4cbc05SVasu Dev if (!fcoe) 188455a66d3cSVasu Dev rc = -ENODEV; 18859d4cbc05SVasu Dev else if (!fcoe_link_ok(fcoe->ctlr.lp)) 18869d4cbc05SVasu Dev fcoe_ctlr_link_up(&fcoe->ctlr); 188755a66d3cSVasu Dev 188855a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 188955a66d3cSVasu Dev return rc; 189055a66d3cSVasu Dev } 189155a66d3cSVasu Dev 189255a66d3cSVasu Dev /** 18931875f27eSRobert Love * fcoe_destroy() - Destroy a FCoE interface 189478a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 18951875f27eSRobert Love * 189678a58246SYi Zou * Called from fcoe transport 1897a703e490SVasu Dev * 1898a703e490SVasu Dev * Returns: 0 for success 1899a703e490SVasu Dev */ 190078a58246SYi Zou static int fcoe_destroy(struct net_device *netdev) 1901a703e490SVasu Dev { 1902030f4e00SChris Leech struct fcoe_interface *fcoe; 1903f04ca1b6SVasu Dev struct fc_lport *lport; 1904b2085a4eSNeerav Parikh struct fcoe_port *port; 19058eca355fSMike Christie int rc = 0; 1906a703e490SVasu Dev 1907dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 1908ee5df628SRobert Love rtnl_lock(); 19092e70e241SChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 19102e70e241SChris Leech if (!fcoe) { 1911a703e490SVasu Dev rc = -ENODEV; 191278a58246SYi Zou goto out_nodev; 1913a703e490SVasu Dev } 1914f04ca1b6SVasu Dev lport = fcoe->ctlr.lp; 1915b2085a4eSNeerav Parikh port = lport_priv(lport); 191654a5b21dSYi Zou list_del(&fcoe->list); 1917b2085a4eSNeerav Parikh queue_work(fcoe_wq, &port->destroy_work); 1918a703e490SVasu Dev out_nodev: 1919b2085a4eSNeerav Parikh rtnl_unlock(); 1920dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 1921a703e490SVasu Dev return rc; 1922a703e490SVasu Dev } 1923a703e490SVasu Dev 19241875f27eSRobert Love /** 19251875f27eSRobert Love * fcoe_destroy_work() - Destroy a FCoE port in a deferred work context 19261875f27eSRobert Love * @work: Handle to the FCoE port to be destroyed 19271875f27eSRobert Love */ 19282e70e241SChris Leech static void fcoe_destroy_work(struct work_struct *work) 19292e70e241SChris Leech { 19302e70e241SChris Leech struct fcoe_port *port; 1931b2085a4eSNeerav Parikh struct fcoe_interface *fcoe; 1932b2085a4eSNeerav Parikh int npiv = 0; 19332e70e241SChris Leech 19342e70e241SChris Leech port = container_of(work, struct fcoe_port, destroy_work); 19352e70e241SChris Leech mutex_lock(&fcoe_config_mutex); 1936b2085a4eSNeerav Parikh 1937b2085a4eSNeerav Parikh /* set if this is an NPIV port */ 1938b2085a4eSNeerav Parikh npiv = port->lport->vport ? 1 : 0; 1939b2085a4eSNeerav Parikh 1940b2085a4eSNeerav Parikh fcoe = port->priv; 19412e70e241SChris Leech fcoe_if_destroy(port->lport); 1942b2085a4eSNeerav Parikh 1943b2085a4eSNeerav Parikh /* Do not tear down the fcoe interface for NPIV port */ 1944b2085a4eSNeerav Parikh if (!npiv) { 1945b2085a4eSNeerav Parikh rtnl_lock(); 1946b2085a4eSNeerav Parikh fcoe_interface_cleanup(fcoe); 1947b2085a4eSNeerav Parikh rtnl_unlock(); 1948b2085a4eSNeerav Parikh } 1949b2085a4eSNeerav Parikh 19502e70e241SChris Leech mutex_unlock(&fcoe_config_mutex); 19512e70e241SChris Leech } 19522e70e241SChris Leech 1953a703e490SVasu Dev /** 195478a58246SYi Zou * fcoe_match() - Check if the FCoE is supported on the given netdevice 195578a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 19561875f27eSRobert Love * 195778a58246SYi Zou * Called from fcoe transport. 195878a58246SYi Zou * 195978a58246SYi Zou * Returns: always returns true as this is the default FCoE transport, 196078a58246SYi Zou * i.e., support all netdevs. 196178a58246SYi Zou */ 196278a58246SYi Zou static bool fcoe_match(struct net_device *netdev) 196378a58246SYi Zou { 196478a58246SYi Zou return true; 196578a58246SYi Zou } 196678a58246SYi Zou 196778a58246SYi Zou /** 196878a58246SYi Zou * fcoe_create() - Create a fcoe interface 196978a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 197078a58246SYi Zou * @fip_mode: The FIP mode for this creation 197178a58246SYi Zou * 197278a58246SYi Zou * Called from fcoe transport 1973a703e490SVasu Dev * 1974a703e490SVasu Dev * Returns: 0 for success 1975a703e490SVasu Dev */ 197678a58246SYi Zou static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode) 1977a703e490SVasu Dev { 1978b2085a4eSNeerav Parikh int rc = 0; 1979030f4e00SChris Leech struct fcoe_interface *fcoe; 1980af7f85d9SChris Leech struct fc_lport *lport; 1981a703e490SVasu Dev 1982dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 1983ee5df628SRobert Love rtnl_lock(); 198434ce27bcSVasu Dev 1985a703e490SVasu Dev /* look for existing lport */ 1986a703e490SVasu Dev if (fcoe_hostlist_lookup(netdev)) { 1987a703e490SVasu Dev rc = -EEXIST; 198878a58246SYi Zou goto out_nodev; 1989a703e490SVasu Dev } 1990a703e490SVasu Dev 19911dd454d9SJoe Eykholt fcoe = fcoe_interface_create(netdev, fip_mode); 19927287fb91SRobert Love if (IS_ERR(fcoe)) { 19937287fb91SRobert Love rc = PTR_ERR(fcoe); 199478a58246SYi Zou goto out_nodev; 1995030f4e00SChris Leech } 1996030f4e00SChris Leech 19979a05753bSChris Leech lport = fcoe_if_create(fcoe, &netdev->dev, 0); 1998af7f85d9SChris Leech if (IS_ERR(lport)) { 1999d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to create interface (%s)\n", 2000a703e490SVasu Dev netdev->name); 2001a703e490SVasu Dev rc = -EIO; 20022e70e241SChris Leech fcoe_interface_cleanup(fcoe); 2003b2085a4eSNeerav Parikh goto out_nodev; 2004a703e490SVasu Dev } 2005030f4e00SChris Leech 200654b649f8SChris Leech /* Make this the "master" N_Port */ 200754b649f8SChris Leech fcoe->ctlr.lp = lport; 2008030f4e00SChris Leech 2009c863df33SChris Leech /* add to lports list */ 2010c863df33SChris Leech fcoe_hostlist_add(lport); 2011c863df33SChris Leech 201254b649f8SChris Leech /* start FIP Discovery and FLOGI */ 201354b649f8SChris Leech lport->boot_time = jiffies; 201454b649f8SChris Leech fc_fabric_login(lport); 201554b649f8SChris Leech if (!fcoe_link_ok(lport)) 201654b649f8SChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 201754b649f8SChris Leech 2018a703e490SVasu Dev out_nodev: 201934ce27bcSVasu Dev rtnl_unlock(); 2020dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2021a703e490SVasu Dev return rc; 2022a703e490SVasu Dev } 2023a703e490SVasu Dev 2024a703e490SVasu Dev /** 20255e4f8fe7SRobert Love * fcoe_link_speed_update() - Update the supported and actual link speeds 20265e4f8fe7SRobert Love * @lport: The local port to update speeds for 2027a703e490SVasu Dev * 20285e4f8fe7SRobert Love * Returns: 0 if the ethtool query was successful 20295e4f8fe7SRobert Love * -1 if the ethtool query failed 2030a703e490SVasu Dev */ 20315e4f8fe7SRobert Love int fcoe_link_speed_update(struct fc_lport *lport) 2032a703e490SVasu Dev { 20338597ae8bSBhanu Prakash Gollapudi struct net_device *netdev = fcoe_netdev(lport); 20348ae6dacaSDavid Decotigny struct ethtool_cmd ecmd; 2035a703e490SVasu Dev 20365e4f8fe7SRobert Love if (!dev_ethtool_get_settings(netdev, &ecmd)) { 20371875f27eSRobert Love lport->link_supported_speeds &= 2038a703e490SVasu Dev ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT); 2039a703e490SVasu Dev if (ecmd.supported & (SUPPORTED_1000baseT_Half | 2040a703e490SVasu Dev SUPPORTED_1000baseT_Full)) 20411875f27eSRobert Love lport->link_supported_speeds |= FC_PORTSPEED_1GBIT; 2042a703e490SVasu Dev if (ecmd.supported & SUPPORTED_10000baseT_Full) 20431875f27eSRobert Love lport->link_supported_speeds |= 2044a703e490SVasu Dev FC_PORTSPEED_10GBIT; 20458ae6dacaSDavid Decotigny switch (ethtool_cmd_speed(&ecmd)) { 20468ae6dacaSDavid Decotigny case SPEED_1000: 20471875f27eSRobert Love lport->link_speed = FC_PORTSPEED_1GBIT; 20488ae6dacaSDavid Decotigny break; 20498ae6dacaSDavid Decotigny case SPEED_10000: 20501875f27eSRobert Love lport->link_speed = FC_PORTSPEED_10GBIT; 20518ae6dacaSDavid Decotigny break; 20528ae6dacaSDavid Decotigny } 20532f718d64SYi Zou return 0; 20542f718d64SYi Zou } 20552f718d64SYi Zou return -1; 2056a703e490SVasu Dev } 2057a703e490SVasu Dev 2058a703e490SVasu Dev /** 20595e4f8fe7SRobert Love * fcoe_link_ok() - Check if the link is OK for a local port 20605e4f8fe7SRobert Love * @lport: The local port to check link on 20615e4f8fe7SRobert Love * 20625e4f8fe7SRobert Love * Returns: 0 if link is UP and OK, -1 if not 20635e4f8fe7SRobert Love * 20645e4f8fe7SRobert Love */ 20655e4f8fe7SRobert Love int fcoe_link_ok(struct fc_lport *lport) 20665e4f8fe7SRobert Love { 20678597ae8bSBhanu Prakash Gollapudi struct net_device *netdev = fcoe_netdev(lport); 20685e4f8fe7SRobert Love 20695e4f8fe7SRobert Love if (netif_oper_up(netdev)) 20705e4f8fe7SRobert Love return 0; 20715e4f8fe7SRobert Love return -1; 20725e4f8fe7SRobert Love } 20735e4f8fe7SRobert Love 20745e4f8fe7SRobert Love /** 20751875f27eSRobert Love * fcoe_percpu_clean() - Clear all pending skbs for an local port 20761875f27eSRobert Love * @lport: The local port whose skbs are to be cleared 2077e7a51997SJoe Eykholt * 2078e7a51997SJoe Eykholt * Must be called with fcoe_create_mutex held to single-thread completion. 2079e7a51997SJoe Eykholt * 2080e7a51997SJoe Eykholt * This flushes the pending skbs by adding a new skb to each queue and 2081e7a51997SJoe Eykholt * waiting until they are all freed. This assures us that not only are 2082e7a51997SJoe Eykholt * there no packets that will be handled by the lport, but also that any 2083e7a51997SJoe Eykholt * threads already handling packet have returned. 2084a703e490SVasu Dev */ 20851875f27eSRobert Love void fcoe_percpu_clean(struct fc_lport *lport) 2086a703e490SVasu Dev { 2087a703e490SVasu Dev struct fcoe_percpu_s *pp; 2088a703e490SVasu Dev struct fcoe_rcv_info *fr; 2089a703e490SVasu Dev struct sk_buff_head *list; 2090a703e490SVasu Dev struct sk_buff *skb, *next; 2091a703e490SVasu Dev struct sk_buff *head; 2092a703e490SVasu Dev unsigned int cpu; 2093a703e490SVasu Dev 2094a703e490SVasu Dev for_each_possible_cpu(cpu) { 2095a703e490SVasu Dev pp = &per_cpu(fcoe_percpu, cpu); 2096a703e490SVasu Dev spin_lock_bh(&pp->fcoe_rx_list.lock); 2097a703e490SVasu Dev list = &pp->fcoe_rx_list; 2098a703e490SVasu Dev head = list->next; 2099a703e490SVasu Dev for (skb = head; skb != (struct sk_buff *)list; 2100a703e490SVasu Dev skb = next) { 2101a703e490SVasu Dev next = skb->next; 2102a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 21031875f27eSRobert Love if (fr->fr_dev == lport) { 2104a703e490SVasu Dev __skb_unlink(skb, list); 2105a703e490SVasu Dev kfree_skb(skb); 2106a703e490SVasu Dev } 2107a703e490SVasu Dev } 2108e7a51997SJoe Eykholt 2109e7a51997SJoe Eykholt if (!pp->thread || !cpu_online(cpu)) { 2110a703e490SVasu Dev spin_unlock_bh(&pp->fcoe_rx_list.lock); 2111e7a51997SJoe Eykholt continue; 2112e7a51997SJoe Eykholt } 2113e7a51997SJoe Eykholt 2114e7a51997SJoe Eykholt skb = dev_alloc_skb(0); 2115e7a51997SJoe Eykholt if (!skb) { 2116e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2117e7a51997SJoe Eykholt continue; 2118e7a51997SJoe Eykholt } 2119e7a51997SJoe Eykholt skb->destructor = fcoe_percpu_flush_done; 2120e7a51997SJoe Eykholt 2121e7a51997SJoe Eykholt __skb_queue_tail(&pp->fcoe_rx_list, skb); 2122e7a51997SJoe Eykholt if (pp->fcoe_rx_list.qlen == 1) 2123e7a51997SJoe Eykholt wake_up_process(pp->thread); 2124e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2125e7a51997SJoe Eykholt 2126e7a51997SJoe Eykholt wait_for_completion(&fcoe_flush_completion); 2127a703e490SVasu Dev } 2128a703e490SVasu Dev } 2129a703e490SVasu Dev 2130a703e490SVasu Dev /** 21311875f27eSRobert Love * fcoe_reset() - Reset a local port 21321875f27eSRobert Love * @shost: The SCSI host associated with the local port to be reset 2133a703e490SVasu Dev * 21341875f27eSRobert Love * Returns: Always 0 (return value required by FC transport template) 2135a703e490SVasu Dev */ 2136a703e490SVasu Dev int fcoe_reset(struct Scsi_Host *shost) 2137a703e490SVasu Dev { 2138a703e490SVasu Dev struct fc_lport *lport = shost_priv(shost); 2139d2f80952SVasu Dev struct fcoe_port *port = lport_priv(lport); 2140d2f80952SVasu Dev struct fcoe_interface *fcoe = port->priv; 2141d2f80952SVasu Dev 2142d2f80952SVasu Dev fcoe_ctlr_link_down(&fcoe->ctlr); 2143d2f80952SVasu Dev fcoe_clean_pending_queue(fcoe->ctlr.lp); 2144d2f80952SVasu Dev if (!fcoe_link_ok(fcoe->ctlr.lp)) 2145d2f80952SVasu Dev fcoe_ctlr_link_up(&fcoe->ctlr); 2146a703e490SVasu Dev return 0; 2147a703e490SVasu Dev } 2148a703e490SVasu Dev 2149a703e490SVasu Dev /** 21501875f27eSRobert Love * fcoe_hostlist_lookup_port() - Find the FCoE interface associated with a net device 21511875f27eSRobert Love * @netdev: The net device used as a key 2152a703e490SVasu Dev * 21531875f27eSRobert Love * Locking: Must be called with the RNL mutex held. 21541875f27eSRobert Love * 21551875f27eSRobert Love * Returns: NULL or the FCoE interface 2156a703e490SVasu Dev */ 2157014f5c3fSChris Leech static struct fcoe_interface * 21581875f27eSRobert Love fcoe_hostlist_lookup_port(const struct net_device *netdev) 2159a703e490SVasu Dev { 2160014f5c3fSChris Leech struct fcoe_interface *fcoe; 2161a703e490SVasu Dev 2162014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 21631875f27eSRobert Love if (fcoe->netdev == netdev) 2164014f5c3fSChris Leech return fcoe; 2165a703e490SVasu Dev } 2166a703e490SVasu Dev return NULL; 2167a703e490SVasu Dev } 2168a703e490SVasu Dev 2169a703e490SVasu Dev /** 21701875f27eSRobert Love * fcoe_hostlist_lookup() - Find the local port associated with a 21711875f27eSRobert Love * given net device 21721875f27eSRobert Love * @netdev: The netdevice used as a key 2173a703e490SVasu Dev * 21741875f27eSRobert Love * Locking: Must be called with the RTNL mutex held 21751875f27eSRobert Love * 21761875f27eSRobert Love * Returns: NULL or the local port 2177a703e490SVasu Dev */ 2178090eb6c4SChris Leech static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev) 2179a703e490SVasu Dev { 2180014f5c3fSChris Leech struct fcoe_interface *fcoe; 2181a703e490SVasu Dev 2182014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 21833fe9a0baSChris Leech return (fcoe) ? fcoe->ctlr.lp : NULL; 2184a703e490SVasu Dev } 2185a703e490SVasu Dev 2186a703e490SVasu Dev /** 21871875f27eSRobert Love * fcoe_hostlist_add() - Add the FCoE interface identified by a local 21881875f27eSRobert Love * port to the hostlist 21891875f27eSRobert Love * @lport: The local port that identifies the FCoE interface to be added 21901875f27eSRobert Love * 21911875f27eSRobert Love * Locking: must be called with the RTNL mutex held 2192a703e490SVasu Dev * 2193a703e490SVasu Dev * Returns: 0 for success 2194a703e490SVasu Dev */ 2195090eb6c4SChris Leech static int fcoe_hostlist_add(const struct fc_lport *lport) 2196a703e490SVasu Dev { 2197014f5c3fSChris Leech struct fcoe_interface *fcoe; 2198014f5c3fSChris Leech struct fcoe_port *port; 2199a703e490SVasu Dev 2200014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport)); 2201014f5c3fSChris Leech if (!fcoe) { 2202014f5c3fSChris Leech port = lport_priv(lport); 22038597ae8bSBhanu Prakash Gollapudi fcoe = port->priv; 2204014f5c3fSChris Leech list_add_tail(&fcoe->list, &fcoe_hostlist); 2205a703e490SVasu Dev } 2206a703e490SVasu Dev return 0; 2207a703e490SVasu Dev } 2208a703e490SVasu Dev 220978a58246SYi Zou 221078a58246SYi Zou static struct fcoe_transport fcoe_sw_transport = { 221178a58246SYi Zou .name = {FCOE_TRANSPORT_DEFAULT}, 221278a58246SYi Zou .attached = false, 221378a58246SYi Zou .list = LIST_HEAD_INIT(fcoe_sw_transport.list), 221478a58246SYi Zou .match = fcoe_match, 221578a58246SYi Zou .create = fcoe_create, 221678a58246SYi Zou .destroy = fcoe_destroy, 221778a58246SYi Zou .enable = fcoe_enable, 221878a58246SYi Zou .disable = fcoe_disable, 221978a58246SYi Zou }; 222078a58246SYi Zou 2221a703e490SVasu Dev /** 22221875f27eSRobert Love * fcoe_init() - Initialize fcoe.ko 2223a703e490SVasu Dev * 22241875f27eSRobert Love * Returns: 0 on success, or a negative value on failure 2225a703e490SVasu Dev */ 2226a703e490SVasu Dev static int __init fcoe_init(void) 2227a703e490SVasu Dev { 22281875f27eSRobert Love struct fcoe_percpu_s *p; 2229a703e490SVasu Dev unsigned int cpu; 2230a703e490SVasu Dev int rc = 0; 2231a703e490SVasu Dev 22322ca32b48STejun Heo fcoe_wq = alloc_workqueue("fcoe", 0, 0); 22332ca32b48STejun Heo if (!fcoe_wq) 22342ca32b48STejun Heo return -ENOMEM; 22352ca32b48STejun Heo 223678a58246SYi Zou /* register as a fcoe transport */ 223778a58246SYi Zou rc = fcoe_transport_attach(&fcoe_sw_transport); 223878a58246SYi Zou if (rc) { 223978a58246SYi Zou printk(KERN_ERR "failed to register an fcoe transport, check " 224078a58246SYi Zou "if libfcoe is loaded\n"); 224178a58246SYi Zou return rc; 224278a58246SYi Zou } 224378a58246SYi Zou 2244dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2245dfc1d0feSChris Leech 2246a703e490SVasu Dev for_each_possible_cpu(cpu) { 2247a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 2248a703e490SVasu Dev skb_queue_head_init(&p->fcoe_rx_list); 2249a703e490SVasu Dev } 2250a703e490SVasu Dev 2251a703e490SVasu Dev for_each_online_cpu(cpu) 2252a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 2253a703e490SVasu Dev 2254a703e490SVasu Dev /* Initialize per CPU interrupt thread */ 2255a703e490SVasu Dev rc = register_hotcpu_notifier(&fcoe_cpu_notifier); 2256a703e490SVasu Dev if (rc) 2257a703e490SVasu Dev goto out_free; 2258a703e490SVasu Dev 2259a703e490SVasu Dev /* Setup link change notification */ 2260a703e490SVasu Dev fcoe_dev_setup(); 2261a703e490SVasu Dev 22625892c32fSChris Leech rc = fcoe_if_init(); 22635892c32fSChris Leech if (rc) 22645892c32fSChris Leech goto out_free; 2265a703e490SVasu Dev 2266dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2267a703e490SVasu Dev return 0; 2268a703e490SVasu Dev 2269a703e490SVasu Dev out_free: 2270a703e490SVasu Dev for_each_online_cpu(cpu) { 2271a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2272a703e490SVasu Dev } 2273dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 22742ca32b48STejun Heo destroy_workqueue(fcoe_wq); 2275a703e490SVasu Dev return rc; 2276a703e490SVasu Dev } 2277a703e490SVasu Dev module_init(fcoe_init); 2278a703e490SVasu Dev 2279a703e490SVasu Dev /** 22801875f27eSRobert Love * fcoe_exit() - Clean up fcoe.ko 2281a703e490SVasu Dev * 22821875f27eSRobert Love * Returns: 0 on success or a negative value on failure 2283a703e490SVasu Dev */ 2284a703e490SVasu Dev static void __exit fcoe_exit(void) 2285a703e490SVasu Dev { 2286014f5c3fSChris Leech struct fcoe_interface *fcoe, *tmp; 22872e70e241SChris Leech struct fcoe_port *port; 22881875f27eSRobert Love unsigned int cpu; 2289a703e490SVasu Dev 2290dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2291dfc1d0feSChris Leech 2292a703e490SVasu Dev fcoe_dev_cleanup(); 2293a703e490SVasu Dev 2294a703e490SVasu Dev /* releases the associated fcoe hosts */ 2295090eb6c4SChris Leech rtnl_lock(); 2296090eb6c4SChris Leech list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) { 2297c863df33SChris Leech list_del(&fcoe->list); 22982e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 22992ca32b48STejun Heo queue_work(fcoe_wq, &port->destroy_work); 2300c863df33SChris Leech } 2301090eb6c4SChris Leech rtnl_unlock(); 2302a703e490SVasu Dev 2303a703e490SVasu Dev unregister_hotcpu_notifier(&fcoe_cpu_notifier); 2304a703e490SVasu Dev 2305014f5c3fSChris Leech for_each_online_cpu(cpu) 2306a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2307a703e490SVasu Dev 2308dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 23092e70e241SChris Leech 23102ca32b48STejun Heo /* 23112ca32b48STejun Heo * destroy_work's may be chained but destroy_workqueue() 23122ca32b48STejun Heo * can take care of them. Just kill the fcoe_wq. 23132ca32b48STejun Heo */ 23142ca32b48STejun Heo destroy_workqueue(fcoe_wq); 23152e70e241SChris Leech 23162ca32b48STejun Heo /* 23172ca32b48STejun Heo * Detaching from the scsi transport must happen after all 23182ca32b48STejun Heo * destroys are done on the fcoe_wq. destroy_workqueue will 23192ca32b48STejun Heo * enusre the fcoe_wq is flushed. 23202ca32b48STejun Heo */ 23212e70e241SChris Leech fcoe_if_exit(); 232278a58246SYi Zou 232378a58246SYi Zou /* detach from fcoe transport */ 232478a58246SYi Zou fcoe_transport_detach(&fcoe_sw_transport); 2325a703e490SVasu Dev } 2326a703e490SVasu Dev module_exit(fcoe_exit); 232711b56188SChris Leech 232811b56188SChris Leech /** 232911b56188SChris Leech * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler 233011b56188SChris Leech * @seq: active sequence in the FLOGI or FDISC exchange 233111b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 233211b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 233311b56188SChris Leech * 233465155b37SUwe Kleine-König * This handles MAC address management for FCoE, then passes control on to 233511b56188SChris Leech * the libfc FLOGI response handler. 233611b56188SChris Leech */ 233711b56188SChris Leech static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 233811b56188SChris Leech { 233911b56188SChris Leech struct fcoe_ctlr *fip = arg; 234011b56188SChris Leech struct fc_exch *exch = fc_seq_exch(seq); 234111b56188SChris Leech struct fc_lport *lport = exch->lp; 234211b56188SChris Leech u8 *mac; 234311b56188SChris Leech 234411b56188SChris Leech if (IS_ERR(fp)) 234511b56188SChris Leech goto done; 234611b56188SChris Leech 234711b56188SChris Leech mac = fr_cb(fp)->granted_mac; 234811b56188SChris Leech if (is_zero_ether_addr(mac)) { 234911b56188SChris Leech /* pre-FIP */ 2350386309ceSJoe Eykholt if (fcoe_ctlr_recv_flogi(fip, lport, fp)) { 235111b56188SChris Leech fc_frame_free(fp); 235211b56188SChris Leech return; 235311b56188SChris Leech } 235411b56188SChris Leech } 2355386309ceSJoe Eykholt fcoe_update_src_mac(lport, mac); 235611b56188SChris Leech done: 235711b56188SChris Leech fc_lport_flogi_resp(seq, fp, lport); 235811b56188SChris Leech } 235911b56188SChris Leech 236011b56188SChris Leech /** 236111b56188SChris Leech * fcoe_logo_resp() - FCoE specific LOGO response handler 236211b56188SChris Leech * @seq: active sequence in the LOGO exchange 236311b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 236411b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 236511b56188SChris Leech * 236665155b37SUwe Kleine-König * This handles MAC address management for FCoE, then passes control on to 236711b56188SChris Leech * the libfc LOGO response handler. 236811b56188SChris Leech */ 236911b56188SChris Leech static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 237011b56188SChris Leech { 2371386309ceSJoe Eykholt struct fc_lport *lport = arg; 237211b56188SChris Leech static u8 zero_mac[ETH_ALEN] = { 0 }; 237311b56188SChris Leech 237411b56188SChris Leech if (!IS_ERR(fp)) 2375386309ceSJoe Eykholt fcoe_update_src_mac(lport, zero_mac); 237611b56188SChris Leech fc_lport_logo_resp(seq, fp, lport); 237711b56188SChris Leech } 237811b56188SChris Leech 237911b56188SChris Leech /** 238011b56188SChris Leech * fcoe_elsct_send - FCoE specific ELS handler 238111b56188SChris Leech * 238211b56188SChris Leech * This does special case handling of FIP encapsualted ELS exchanges for FCoE, 238311b56188SChris Leech * using FCoE specific response handlers and passing the FIP controller as 238411b56188SChris Leech * the argument (the lport is still available from the exchange). 238511b56188SChris Leech * 238611b56188SChris Leech * Most of the work here is just handed off to the libfc routine. 238711b56188SChris Leech */ 23881875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did, 23891875f27eSRobert Love struct fc_frame *fp, unsigned int op, 23901875f27eSRobert Love void (*resp)(struct fc_seq *, 23911875f27eSRobert Love struct fc_frame *, 23921875f27eSRobert Love void *), 239311b56188SChris Leech void *arg, u32 timeout) 239411b56188SChris Leech { 239511b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 23968597ae8bSBhanu Prakash Gollapudi struct fcoe_interface *fcoe = port->priv; 239711b56188SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 239811b56188SChris Leech struct fc_frame_header *fh = fc_frame_header_get(fp); 239911b56188SChris Leech 240011b56188SChris Leech switch (op) { 240111b56188SChris Leech case ELS_FLOGI: 240211b56188SChris Leech case ELS_FDISC: 2403e10f8c66SJoe Eykholt if (lport->point_to_multipoint) 2404e10f8c66SJoe Eykholt break; 240511b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp, 240611b56188SChris Leech fip, timeout); 240711b56188SChris Leech case ELS_LOGO: 240811b56188SChris Leech /* only hook onto fabric logouts, not port logouts */ 240911b56188SChris Leech if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) 241011b56188SChris Leech break; 241111b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp, 2412386309ceSJoe Eykholt lport, timeout); 241311b56188SChris Leech } 241411b56188SChris Leech return fc_elsct_send(lport, did, fp, op, resp, arg, timeout); 241511b56188SChris Leech } 241611b56188SChris Leech 24179a05753bSChris Leech /** 24189a05753bSChris Leech * fcoe_vport_create() - create an fc_host/scsi_host for a vport 24199a05753bSChris Leech * @vport: fc_vport object to create a new fc_host for 24209a05753bSChris Leech * @disabled: start the new fc_host in a disabled state by default? 24219a05753bSChris Leech * 24229a05753bSChris Leech * Returns: 0 for success 24239a05753bSChris Leech */ 24249a05753bSChris Leech static int fcoe_vport_create(struct fc_vport *vport, bool disabled) 24259a05753bSChris Leech { 24269a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 24279a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 24289a05753bSChris Leech struct fcoe_port *port = lport_priv(n_port); 24298597ae8bSBhanu Prakash Gollapudi struct fcoe_interface *fcoe = port->priv; 24309a05753bSChris Leech struct net_device *netdev = fcoe->netdev; 24319a05753bSChris Leech struct fc_lport *vn_port; 2432bdf25218SNeerav Parikh int rc; 2433bdf25218SNeerav Parikh char buf[32]; 2434bdf25218SNeerav Parikh 2435bdf25218SNeerav Parikh rc = fcoe_validate_vport_create(vport); 2436bdf25218SNeerav Parikh if (rc) { 2437d834895cSBhanu Prakash Gollapudi fcoe_wwn_to_str(vport->port_name, buf, sizeof(buf)); 2438bdf25218SNeerav Parikh printk(KERN_ERR "fcoe: Failed to create vport, " 2439bdf25218SNeerav Parikh "WWPN (0x%s) already exists\n", 2440bdf25218SNeerav Parikh buf); 2441bdf25218SNeerav Parikh return rc; 2442bdf25218SNeerav Parikh } 24439a05753bSChris Leech 24449a05753bSChris Leech mutex_lock(&fcoe_config_mutex); 24459a05753bSChris Leech vn_port = fcoe_if_create(fcoe, &vport->dev, 1); 24469a05753bSChris Leech mutex_unlock(&fcoe_config_mutex); 24479a05753bSChris Leech 24489a05753bSChris Leech if (IS_ERR(vn_port)) { 24499a05753bSChris Leech printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n", 24509a05753bSChris Leech netdev->name); 24519a05753bSChris Leech return -EIO; 24529a05753bSChris Leech } 24539a05753bSChris Leech 24549a05753bSChris Leech if (disabled) { 24559a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 24569a05753bSChris Leech } else { 24579a05753bSChris Leech vn_port->boot_time = jiffies; 24589a05753bSChris Leech fc_fabric_login(vn_port); 24599a05753bSChris Leech fc_vport_setlink(vn_port); 24609a05753bSChris Leech } 24619a05753bSChris Leech return 0; 24629a05753bSChris Leech } 24639a05753bSChris Leech 24649a05753bSChris Leech /** 24659a05753bSChris Leech * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport 24669a05753bSChris Leech * @vport: fc_vport object that is being destroyed 24679a05753bSChris Leech * 24689a05753bSChris Leech * Returns: 0 for success 24699a05753bSChris Leech */ 24709a05753bSChris Leech static int fcoe_vport_destroy(struct fc_vport *vport) 24719a05753bSChris Leech { 24729a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 24739a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 24749a05753bSChris Leech struct fc_lport *vn_port = vport->dd_data; 24759a05753bSChris Leech struct fcoe_port *port = lport_priv(vn_port); 24769a05753bSChris Leech 24779a05753bSChris Leech mutex_lock(&n_port->lp_mutex); 24789a05753bSChris Leech list_del(&vn_port->list); 24799a05753bSChris Leech mutex_unlock(&n_port->lp_mutex); 24802ca32b48STejun Heo queue_work(fcoe_wq, &port->destroy_work); 24819a05753bSChris Leech return 0; 24829a05753bSChris Leech } 24839a05753bSChris Leech 24849a05753bSChris Leech /** 24859a05753bSChris Leech * fcoe_vport_disable() - change vport state 24869a05753bSChris Leech * @vport: vport to bring online/offline 24879a05753bSChris Leech * @disable: should the vport be disabled? 24889a05753bSChris Leech */ 24899a05753bSChris Leech static int fcoe_vport_disable(struct fc_vport *vport, bool disable) 24909a05753bSChris Leech { 24919a05753bSChris Leech struct fc_lport *lport = vport->dd_data; 24929a05753bSChris Leech 24939a05753bSChris Leech if (disable) { 24949a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 24959a05753bSChris Leech fc_fabric_logoff(lport); 24969a05753bSChris Leech } else { 24979a05753bSChris Leech lport->boot_time = jiffies; 24989a05753bSChris Leech fc_fabric_login(lport); 24999a05753bSChris Leech fc_vport_setlink(lport); 25009a05753bSChris Leech } 25019a05753bSChris Leech 25029a05753bSChris Leech return 0; 25039a05753bSChris Leech } 25049a05753bSChris Leech 2505dc8596d3SChris Leech /** 2506dc8596d3SChris Leech * fcoe_vport_set_symbolic_name() - append vport string to symbolic name 2507dc8596d3SChris Leech * @vport: fc_vport with a new symbolic name string 2508dc8596d3SChris Leech * 2509dc8596d3SChris Leech * After generating a new symbolic name string, a new RSPN_ID request is 2510dc8596d3SChris Leech * sent to the name server. There is no response handler, so if it fails 2511dc8596d3SChris Leech * for some reason it will not be retried. 2512dc8596d3SChris Leech */ 2513dc8596d3SChris Leech static void fcoe_set_vport_symbolic_name(struct fc_vport *vport) 2514dc8596d3SChris Leech { 2515dc8596d3SChris Leech struct fc_lport *lport = vport->dd_data; 2516dc8596d3SChris Leech struct fc_frame *fp; 2517dc8596d3SChris Leech size_t len; 2518dc8596d3SChris Leech 2519dc8596d3SChris Leech snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 2520dc8596d3SChris Leech "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION, 2521dc8596d3SChris Leech fcoe_netdev(lport)->name, vport->symbolic_name); 2522dc8596d3SChris Leech 2523dc8596d3SChris Leech if (lport->state != LPORT_ST_READY) 2524dc8596d3SChris Leech return; 2525dc8596d3SChris Leech 2526dc8596d3SChris Leech len = strnlen(fc_host_symbolic_name(lport->host), 255); 2527dc8596d3SChris Leech fp = fc_frame_alloc(lport, 2528dc8596d3SChris Leech sizeof(struct fc_ct_hdr) + 2529dc8596d3SChris Leech sizeof(struct fc_ns_rspn) + len); 2530dc8596d3SChris Leech if (!fp) 2531dc8596d3SChris Leech return; 2532dc8596d3SChris Leech lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID, 2533b94f8951SJoe Eykholt NULL, NULL, 3 * lport->r_a_tov); 2534dc8596d3SChris Leech } 2535b84056bfSYi Zou 2536b84056bfSYi Zou /** 2537b84056bfSYi Zou * fcoe_get_lesb() - Fill the FCoE Link Error Status Block 2538b84056bfSYi Zou * @lport: the local port 2539b84056bfSYi Zou * @fc_lesb: the link error status block 2540b84056bfSYi Zou */ 2541b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *lport, 2542b84056bfSYi Zou struct fc_els_lesb *fc_lesb) 2543b84056bfSYi Zou { 2544b84056bfSYi Zou struct net_device *netdev = fcoe_netdev(lport); 2545b84056bfSYi Zou 2546814740d5SBhanu Prakash Gollapudi __fcoe_get_lesb(lport, fc_lesb, netdev); 2547b84056bfSYi Zou } 25487d65b0dfSJoe Eykholt 25497d65b0dfSJoe Eykholt /** 25507d65b0dfSJoe Eykholt * fcoe_set_port_id() - Callback from libfc when Port_ID is set. 25517d65b0dfSJoe Eykholt * @lport: the local port 25527d65b0dfSJoe Eykholt * @port_id: the port ID 25537d65b0dfSJoe Eykholt * @fp: the received frame, if any, that caused the port_id to be set. 25547d65b0dfSJoe Eykholt * 25557d65b0dfSJoe Eykholt * This routine handles the case where we received a FLOGI and are 25567d65b0dfSJoe Eykholt * entering point-to-point mode. We need to call fcoe_ctlr_recv_flogi() 25577d65b0dfSJoe Eykholt * so it can set the non-mapped mode and gateway address. 25587d65b0dfSJoe Eykholt * 25597d65b0dfSJoe Eykholt * The FLOGI LS_ACC is handled by fcoe_flogi_resp(). 25607d65b0dfSJoe Eykholt */ 25617d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *lport, 25627d65b0dfSJoe Eykholt u32 port_id, struct fc_frame *fp) 25637d65b0dfSJoe Eykholt { 25647d65b0dfSJoe Eykholt struct fcoe_port *port = lport_priv(lport); 25658597ae8bSBhanu Prakash Gollapudi struct fcoe_interface *fcoe = port->priv; 25667d65b0dfSJoe Eykholt 25677d65b0dfSJoe Eykholt if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) 25687d65b0dfSJoe Eykholt fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp); 25697d65b0dfSJoe Eykholt } 2570