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 */ 5505cc7390SYi Zou static unsigned int fcoe_ddp_min; 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_clean_pending_queue(struct fc_lport *); 791875f27eSRobert Love static void fcoe_percpu_clean(struct fc_lport *); 805e4f8fe7SRobert Love static int fcoe_link_speed_update(struct fc_lport *); 811875f27eSRobert Love static int fcoe_link_ok(struct fc_lport *); 82fdd78027SVasu Dev 83fdd78027SVasu Dev static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *); 84fdd78027SVasu Dev static int fcoe_hostlist_add(const struct fc_lport *); 85fdd78027SVasu Dev 864bb6b515SVasu Dev static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *); 87a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *, ulong, void *); 88a703e490SVasu Dev static void fcoe_dev_setup(void); 89a703e490SVasu Dev static void fcoe_dev_cleanup(void); 901875f27eSRobert Love static struct fcoe_interface 911875f27eSRobert Love *fcoe_hostlist_lookup_port(const struct net_device *); 92a703e490SVasu Dev 931875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *, struct net_device *, 941875f27eSRobert Love struct packet_type *, struct net_device *); 951875f27eSRobert Love 961875f27eSRobert Love static void fcoe_fip_send(struct fcoe_ctlr *, struct sk_buff *); 971875f27eSRobert Love static void fcoe_update_src_mac(struct fc_lport *, u8 *); 981875f27eSRobert Love static u8 *fcoe_get_src_mac(struct fc_lport *); 991875f27eSRobert Love static void fcoe_destroy_work(struct work_struct *); 1001875f27eSRobert Love 1011875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *, 1021875f27eSRobert Love unsigned int); 1031875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *, u16); 1041875f27eSRobert Love 1051875f27eSRobert Love static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *); 1061875f27eSRobert Love 10778a58246SYi Zou static bool fcoe_match(struct net_device *netdev); 10878a58246SYi Zou static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode); 10978a58246SYi Zou static int fcoe_destroy(struct net_device *netdev); 11078a58246SYi Zou static int fcoe_enable(struct net_device *netdev); 11178a58246SYi Zou static int fcoe_disable(struct net_device *netdev); 1121875f27eSRobert Love 1131875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *, 1141875f27eSRobert Love u32 did, struct fc_frame *, 1151875f27eSRobert Love unsigned int op, 1161875f27eSRobert Love void (*resp)(struct fc_seq *, 1171875f27eSRobert Love struct fc_frame *, 1181875f27eSRobert Love void *), 1191875f27eSRobert Love void *, u32 timeout); 120859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb); 1211875f27eSRobert Love 122b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *); 123b84056bfSYi Zou 1241875f27eSRobert Love /* notification function for packets from net device */ 125a703e490SVasu Dev static struct notifier_block fcoe_notifier = { 126a703e490SVasu Dev .notifier_call = fcoe_device_notification, 127a703e490SVasu Dev }; 128a703e490SVasu Dev 1291875f27eSRobert Love /* notification function for CPU hotplug events */ 1301875f27eSRobert Love static struct notifier_block fcoe_cpu_notifier = { 1311875f27eSRobert Love .notifier_call = fcoe_cpu_callback, 1321875f27eSRobert Love }; 1331875f27eSRobert Love 1348ca86f84SYi Zou static struct scsi_transport_template *fcoe_nport_scsi_transport; 1358ca86f84SYi Zou static struct scsi_transport_template *fcoe_vport_scsi_transport; 136a703e490SVasu Dev 1371875f27eSRobert Love static int fcoe_vport_destroy(struct fc_vport *); 1381875f27eSRobert Love static int fcoe_vport_create(struct fc_vport *, bool disabled); 1391875f27eSRobert Love static int fcoe_vport_disable(struct fc_vport *, bool disable); 1401875f27eSRobert Love static void fcoe_set_vport_symbolic_name(struct fc_vport *); 1417d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *); 1421875f27eSRobert Love 1431875f27eSRobert Love static struct libfc_function_template fcoe_libfc_fcn_templ = { 1441875f27eSRobert Love .frame_send = fcoe_xmit, 1451875f27eSRobert Love .ddp_setup = fcoe_ddp_setup, 1461875f27eSRobert Love .ddp_done = fcoe_ddp_done, 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 */ 27454b649f8SChris Leech if ((netdev->priv_flags & IFF_MASTER_ALB) || 27554b649f8SChris Leech (netdev->priv_flags & IFF_SLAVE_INACTIVE) || 27654b649f8SChris Leech (netdev->priv_flags & IFF_MASTER_8023AD)) { 27759d92516Sjohn fastabend FCOE_NETDEV_DBG(netdev, "Bonded interfaces not supported\n"); 27854b649f8SChris Leech return -EOPNOTSUPP; 27954b649f8SChris Leech } 28054b649f8SChris Leech 28154b649f8SChris Leech /* look for SAN MAC address, if multiple SAN MACs exist, only 28254b649f8SChris Leech * use the first one for SPMA */ 2835bab87e6SYi Zou real_dev = (netdev->priv_flags & IFF_802_1Q_VLAN) ? 2845bab87e6SYi Zou vlan_dev_real_dev(netdev) : netdev; 28554b649f8SChris Leech rcu_read_lock(); 2865bab87e6SYi Zou for_each_dev_addr(real_dev, ha) { 28754b649f8SChris Leech if ((ha->type == NETDEV_HW_ADDR_T_SAN) && 288bf361707SYi Zou (is_valid_ether_addr(ha->addr))) { 28954b649f8SChris Leech memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN); 29054b649f8SChris Leech fip->spma = 1; 29154b649f8SChris Leech break; 29254b649f8SChris Leech } 29354b649f8SChris Leech } 29454b649f8SChris Leech rcu_read_unlock(); 29554b649f8SChris Leech 29654b649f8SChris Leech /* setup Source Mac Address */ 29754b649f8SChris Leech if (!fip->spma) 29854b649f8SChris Leech memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len); 29954b649f8SChris Leech 30054b649f8SChris Leech /* 30154b649f8SChris Leech * Add FCoE MAC address as second unicast MAC address 30254b649f8SChris Leech * or enter promiscuous mode if not capable of listening 30354b649f8SChris Leech * for multiple unicast MACs. 30454b649f8SChris Leech */ 30554b649f8SChris Leech memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 306a748ee24SJiri Pirko dev_uc_add(netdev, flogi_maddr); 30754b649f8SChris Leech if (fip->spma) 308a748ee24SJiri Pirko dev_uc_add(netdev, fip->ctl_src_addr); 309e10f8c66SJoe Eykholt if (fip->mode == FIP_MODE_VN2VN) { 310e10f8c66SJoe Eykholt dev_mc_add(netdev, FIP_ALL_VN2VN_MACS); 311e10f8c66SJoe Eykholt dev_mc_add(netdev, FIP_ALL_P2P_MACS); 312e10f8c66SJoe Eykholt } else 31322bedad3SJiri Pirko dev_mc_add(netdev, FIP_ALL_ENODE_MACS); 31454b649f8SChris Leech 31554b649f8SChris Leech /* 31654b649f8SChris Leech * setup the receive function from ethernet driver 31754b649f8SChris Leech * on the ethertype for the given device 31854b649f8SChris Leech */ 31954b649f8SChris Leech fcoe->fcoe_packet_type.func = fcoe_rcv; 32054b649f8SChris Leech fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); 32154b649f8SChris Leech fcoe->fcoe_packet_type.dev = netdev; 32254b649f8SChris Leech dev_add_pack(&fcoe->fcoe_packet_type); 32354b649f8SChris Leech 32454b649f8SChris Leech fcoe->fip_packet_type.func = fcoe_fip_recv; 32554b649f8SChris Leech fcoe->fip_packet_type.type = htons(ETH_P_FIP); 32654b649f8SChris Leech fcoe->fip_packet_type.dev = netdev; 32754b649f8SChris Leech dev_add_pack(&fcoe->fip_packet_type); 32854b649f8SChris Leech 32954b649f8SChris Leech return 0; 33054b649f8SChris Leech } 33154b649f8SChris Leech 332a703e490SVasu Dev /** 3331875f27eSRobert Love * fcoe_interface_create() - Create a FCoE interface on a net device 3341875f27eSRobert Love * @netdev: The net device to create the FCoE interface on 3351dd454d9SJoe Eykholt * @fip_mode: The mode to use for FIP 336030f4e00SChris Leech * 337030f4e00SChris Leech * Returns: pointer to a struct fcoe_interface or NULL on error 338030f4e00SChris Leech */ 3391dd454d9SJoe Eykholt static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev, 3401dd454d9SJoe Eykholt enum fip_state fip_mode) 341030f4e00SChris Leech { 342030f4e00SChris Leech struct fcoe_interface *fcoe; 34359d92516Sjohn fastabend int err; 344030f4e00SChris Leech 3457287fb91SRobert Love if (!try_module_get(THIS_MODULE)) { 3467287fb91SRobert Love FCOE_NETDEV_DBG(netdev, 3477287fb91SRobert Love "Could not get a reference to the module\n"); 3487287fb91SRobert Love fcoe = ERR_PTR(-EBUSY); 3497287fb91SRobert Love goto out; 3507287fb91SRobert Love } 3517287fb91SRobert Love 352030f4e00SChris Leech fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL); 353030f4e00SChris Leech if (!fcoe) { 354030f4e00SChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n"); 3557287fb91SRobert Love fcoe = ERR_PTR(-ENOMEM); 3567287fb91SRobert Love goto out_nomod; 357030f4e00SChris Leech } 358030f4e00SChris Leech 3592e70e241SChris Leech dev_hold(netdev); 360030f4e00SChris Leech kref_init(&fcoe->kref); 36154b649f8SChris Leech 36254b649f8SChris Leech /* 36354b649f8SChris Leech * Initialize FIP. 36454b649f8SChris Leech */ 3651dd454d9SJoe Eykholt fcoe_ctlr_init(&fcoe->ctlr, fip_mode); 36654b649f8SChris Leech fcoe->ctlr.send = fcoe_fip_send; 36754b649f8SChris Leech fcoe->ctlr.update_mac = fcoe_update_src_mac; 36811b56188SChris Leech fcoe->ctlr.get_src_addr = fcoe_get_src_mac; 36954b649f8SChris Leech 37059d92516Sjohn fastabend err = fcoe_interface_setup(fcoe, netdev); 37159d92516Sjohn fastabend if (err) { 37259d92516Sjohn fastabend fcoe_ctlr_destroy(&fcoe->ctlr); 37359d92516Sjohn fastabend kfree(fcoe); 37459d92516Sjohn fastabend dev_put(netdev); 3757287fb91SRobert Love fcoe = ERR_PTR(err); 3767287fb91SRobert Love goto out_nomod; 37759d92516Sjohn fastabend } 378030f4e00SChris Leech 3797287fb91SRobert Love goto out; 3807287fb91SRobert Love 3817287fb91SRobert Love out_nomod: 3827287fb91SRobert Love module_put(THIS_MODULE); 3837287fb91SRobert Love out: 384030f4e00SChris Leech return fcoe; 385030f4e00SChris Leech } 386030f4e00SChris Leech 387030f4e00SChris Leech /** 3881875f27eSRobert Love * fcoe_interface_cleanup() - Clean up a FCoE interface 3891875f27eSRobert Love * @fcoe: The FCoE interface to be cleaned up 3902e70e241SChris Leech * 3912e70e241SChris Leech * Caller must be holding the RTNL mutex 39254b649f8SChris Leech */ 39354b649f8SChris Leech void fcoe_interface_cleanup(struct fcoe_interface *fcoe) 39454b649f8SChris Leech { 39554b649f8SChris Leech struct net_device *netdev = fcoe->netdev; 39654b649f8SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 39754b649f8SChris Leech u8 flogi_maddr[ETH_ALEN]; 398b7a727f1SYi Zou const struct net_device_ops *ops; 39954b649f8SChris Leech 40054b649f8SChris Leech /* 40154b649f8SChris Leech * Don't listen for Ethernet packets anymore. 40254b649f8SChris Leech * synchronize_net() ensures that the packet handlers are not running 40354b649f8SChris Leech * on another CPU. dev_remove_pack() would do that, this calls the 40454b649f8SChris Leech * unsyncronized version __dev_remove_pack() to avoid multiple delays. 40554b649f8SChris Leech */ 40654b649f8SChris Leech __dev_remove_pack(&fcoe->fcoe_packet_type); 40754b649f8SChris Leech __dev_remove_pack(&fcoe->fip_packet_type); 40854b649f8SChris Leech synchronize_net(); 40954b649f8SChris Leech 41054b649f8SChris Leech /* Delete secondary MAC addresses */ 41154b649f8SChris Leech memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 412a748ee24SJiri Pirko dev_uc_del(netdev, flogi_maddr); 41354b649f8SChris Leech if (fip->spma) 414a748ee24SJiri Pirko dev_uc_del(netdev, fip->ctl_src_addr); 415e10f8c66SJoe Eykholt if (fip->mode == FIP_MODE_VN2VN) { 416e10f8c66SJoe Eykholt dev_mc_del(netdev, FIP_ALL_VN2VN_MACS); 417e10f8c66SJoe Eykholt dev_mc_del(netdev, FIP_ALL_P2P_MACS); 418e10f8c66SJoe Eykholt } else 41922bedad3SJiri Pirko dev_mc_del(netdev, FIP_ALL_ENODE_MACS); 420b7a727f1SYi Zou 421b7a727f1SYi Zou /* Tell the LLD we are done w/ FCoE */ 422b7a727f1SYi Zou ops = netdev->netdev_ops; 423b7a727f1SYi Zou if (ops->ndo_fcoe_disable) { 424b7a727f1SYi Zou if (ops->ndo_fcoe_disable(netdev)) 425b7a727f1SYi Zou FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE" 426b7a727f1SYi Zou " specific feature for LLD.\n"); 427b7a727f1SYi Zou } 42854b649f8SChris Leech } 42954b649f8SChris Leech 43054b649f8SChris Leech /** 431030f4e00SChris Leech * fcoe_interface_release() - fcoe_port kref release function 4321875f27eSRobert Love * @kref: Embedded reference count in an fcoe_interface struct 433030f4e00SChris Leech */ 434030f4e00SChris Leech static void fcoe_interface_release(struct kref *kref) 435030f4e00SChris Leech { 436030f4e00SChris Leech struct fcoe_interface *fcoe; 4372e70e241SChris Leech struct net_device *netdev; 438030f4e00SChris Leech 439030f4e00SChris Leech fcoe = container_of(kref, struct fcoe_interface, kref); 4402e70e241SChris Leech netdev = fcoe->netdev; 4412e70e241SChris Leech /* tear-down the FCoE controller */ 4422e70e241SChris Leech fcoe_ctlr_destroy(&fcoe->ctlr); 443030f4e00SChris Leech kfree(fcoe); 4442e70e241SChris Leech dev_put(netdev); 4457287fb91SRobert Love module_put(THIS_MODULE); 446030f4e00SChris Leech } 447030f4e00SChris Leech 448030f4e00SChris Leech /** 4491875f27eSRobert Love * fcoe_interface_get() - Get a reference to a FCoE interface 4501875f27eSRobert Love * @fcoe: The FCoE interface to be held 451030f4e00SChris Leech */ 452030f4e00SChris Leech static inline void fcoe_interface_get(struct fcoe_interface *fcoe) 453030f4e00SChris Leech { 454030f4e00SChris Leech kref_get(&fcoe->kref); 455030f4e00SChris Leech } 456030f4e00SChris Leech 457030f4e00SChris Leech /** 4581875f27eSRobert Love * fcoe_interface_put() - Put a reference to a FCoE interface 4591875f27eSRobert Love * @fcoe: The FCoE interface to be released 460030f4e00SChris Leech */ 461030f4e00SChris Leech static inline void fcoe_interface_put(struct fcoe_interface *fcoe) 462030f4e00SChris Leech { 463030f4e00SChris Leech kref_put(&fcoe->kref, fcoe_interface_release); 464030f4e00SChris Leech } 465030f4e00SChris Leech 466030f4e00SChris Leech /** 4671875f27eSRobert Love * fcoe_fip_recv() - Handler for received FIP frames 4681875f27eSRobert Love * @skb: The receive skb 4691875f27eSRobert Love * @netdev: The associated net device 4701875f27eSRobert Love * @ptype: The packet_type structure which was used to register this handler 4711875f27eSRobert Love * @orig_dev: The original net_device the the skb was received on. 4721875f27eSRobert Love * (in case dev is a bond) 473ab6b85c1SVasu Dev * 474ab6b85c1SVasu Dev * Returns: 0 for success 475ab6b85c1SVasu Dev */ 4761875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev, 477ab6b85c1SVasu Dev struct packet_type *ptype, 478ab6b85c1SVasu Dev struct net_device *orig_dev) 479ab6b85c1SVasu Dev { 480259ad85dSChris Leech struct fcoe_interface *fcoe; 481ab6b85c1SVasu Dev 482259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type); 4833fe9a0baSChris Leech fcoe_ctlr_recv(&fcoe->ctlr, skb); 484ab6b85c1SVasu Dev return 0; 485ab6b85c1SVasu Dev } 486ab6b85c1SVasu Dev 487ab6b85c1SVasu Dev /** 4881875f27eSRobert Love * fcoe_fip_send() - Send an Ethernet-encapsulated FIP frame 4891875f27eSRobert Love * @fip: The FCoE controller 4901875f27eSRobert Love * @skb: The FIP packet to be sent 491ab6b85c1SVasu Dev */ 492ab6b85c1SVasu Dev static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 493ab6b85c1SVasu Dev { 4943fe9a0baSChris Leech skb->dev = fcoe_from_ctlr(fip)->netdev; 495ab6b85c1SVasu Dev dev_queue_xmit(skb); 496ab6b85c1SVasu Dev } 497ab6b85c1SVasu Dev 498ab6b85c1SVasu Dev /** 4991875f27eSRobert Love * fcoe_update_src_mac() - Update the Ethernet MAC filters 5001875f27eSRobert Love * @lport: The local port to update the source MAC on 5011875f27eSRobert Love * @addr: Unicast MAC address to add 502ab6b85c1SVasu Dev * 503ab6b85c1SVasu Dev * Remove any previously-set unicast MAC filter. 504ab6b85c1SVasu Dev * Add secondary FCoE MAC address filter for our OUI. 505ab6b85c1SVasu Dev */ 50611b56188SChris Leech static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr) 507ab6b85c1SVasu Dev { 50811b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 50911b56188SChris Leech struct fcoe_interface *fcoe = port->fcoe; 510ab6b85c1SVasu Dev 511ab6b85c1SVasu Dev rtnl_lock(); 51211b56188SChris Leech if (!is_zero_ether_addr(port->data_src_addr)) 513a748ee24SJiri Pirko dev_uc_del(fcoe->netdev, port->data_src_addr); 51411b56188SChris Leech if (!is_zero_ether_addr(addr)) 515a748ee24SJiri Pirko dev_uc_add(fcoe->netdev, addr); 51611b56188SChris Leech memcpy(port->data_src_addr, addr, ETH_ALEN); 517ab6b85c1SVasu Dev rtnl_unlock(); 518ab6b85c1SVasu Dev } 519ab6b85c1SVasu Dev 520ab6b85c1SVasu Dev /** 52111b56188SChris Leech * fcoe_get_src_mac() - return the Ethernet source address for an lport 52211b56188SChris Leech * @lport: libfc lport 52311b56188SChris Leech */ 52411b56188SChris Leech static u8 *fcoe_get_src_mac(struct fc_lport *lport) 52511b56188SChris Leech { 52611b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 52711b56188SChris Leech 52811b56188SChris Leech return port->data_src_addr; 52911b56188SChris Leech } 53011b56188SChris Leech 53111b56188SChris Leech /** 5321875f27eSRobert Love * fcoe_lport_config() - Set up a local port 5331875f27eSRobert Love * @lport: The local port to be setup 534a703e490SVasu Dev * 535a703e490SVasu Dev * Returns: 0 for success 536a703e490SVasu Dev */ 5371875f27eSRobert Love static int fcoe_lport_config(struct fc_lport *lport) 538a703e490SVasu Dev { 5391875f27eSRobert Love lport->link_up = 0; 5401875f27eSRobert Love lport->qfull = 0; 5411875f27eSRobert Love lport->max_retry_count = 3; 5421875f27eSRobert Love lport->max_rport_retry_count = 3; 5431875f27eSRobert Love lport->e_d_tov = 2 * 1000; /* FC-FS default */ 5441875f27eSRobert Love lport->r_a_tov = 2 * 2 * 1000; 5451875f27eSRobert Love lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | 546a703e490SVasu Dev FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); 5471875f27eSRobert Love lport->does_npiv = 1; 548a703e490SVasu Dev 5491875f27eSRobert Love fc_lport_init_stats(lport); 550a703e490SVasu Dev 551a703e490SVasu Dev /* lport fc_lport related configuration */ 5521875f27eSRobert Love fc_lport_config(lport); 553a703e490SVasu Dev 554a703e490SVasu Dev /* offload related configuration */ 5551875f27eSRobert Love lport->crc_offload = 0; 5561875f27eSRobert Love lport->seq_offload = 0; 5571875f27eSRobert Love lport->lro_enabled = 0; 5581875f27eSRobert Love lport->lro_xid = 0; 5591875f27eSRobert Love lport->lso_max = 0; 560a703e490SVasu Dev 561a703e490SVasu Dev return 0; 562a703e490SVasu Dev } 563a703e490SVasu Dev 564a703e490SVasu Dev /** 5651875f27eSRobert Love * fcoe_queue_timer() - The fcoe queue timer 5661875f27eSRobert Love * @lport: The local port 5671047f221SVasu Dev * 5681047f221SVasu Dev * Calls fcoe_check_wait_queue on timeout 5691047f221SVasu Dev */ 5701875f27eSRobert Love static void fcoe_queue_timer(ulong lport) 5711047f221SVasu Dev { 5721875f27eSRobert Love fcoe_check_wait_queue((struct fc_lport *)lport, NULL); 5731047f221SVasu Dev } 5741047f221SVasu Dev 5751047f221SVasu Dev /** 576dcece412SYi Zou * fcoe_get_wwn() - Get the world wide name from LLD if it supports it 577dcece412SYi Zou * @netdev: the associated net device 578dcece412SYi Zou * @wwn: the output WWN 579dcece412SYi Zou * @type: the type of WWN (WWPN or WWNN) 580dcece412SYi Zou * 581dcece412SYi Zou * Returns: 0 for success 582dcece412SYi Zou */ 583dcece412SYi Zou static int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) 584dcece412SYi Zou { 585dcece412SYi Zou const struct net_device_ops *ops = netdev->netdev_ops; 586dcece412SYi Zou 587dcece412SYi Zou if (ops->ndo_fcoe_get_wwn) 588dcece412SYi Zou return ops->ndo_fcoe_get_wwn(netdev, wwn, type); 589dcece412SYi Zou return -EINVAL; 590dcece412SYi Zou } 591dcece412SYi Zou 592dcece412SYi Zou /** 59354a5b21dSYi Zou * fcoe_netdev_features_change - Updates the lport's offload flags based 59454a5b21dSYi Zou * on the LLD netdev's FCoE feature flags 59554a5b21dSYi Zou */ 59654a5b21dSYi Zou static void fcoe_netdev_features_change(struct fc_lport *lport, 59754a5b21dSYi Zou struct net_device *netdev) 59854a5b21dSYi Zou { 59954a5b21dSYi Zou mutex_lock(&lport->lp_mutex); 60054a5b21dSYi Zou 60154a5b21dSYi Zou if (netdev->features & NETIF_F_SG) 60254a5b21dSYi Zou lport->sg_supp = 1; 60354a5b21dSYi Zou else 60454a5b21dSYi Zou lport->sg_supp = 0; 60554a5b21dSYi Zou 60654a5b21dSYi Zou if (netdev->features & NETIF_F_FCOE_CRC) { 60754a5b21dSYi Zou lport->crc_offload = 1; 60854a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n"); 60954a5b21dSYi Zou } else { 61054a5b21dSYi Zou lport->crc_offload = 0; 61154a5b21dSYi Zou } 61254a5b21dSYi Zou 61354a5b21dSYi Zou if (netdev->features & NETIF_F_FSO) { 61454a5b21dSYi Zou lport->seq_offload = 1; 61554a5b21dSYi Zou lport->lso_max = netdev->gso_max_size; 61654a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n", 61754a5b21dSYi Zou lport->lso_max); 61854a5b21dSYi Zou } else { 61954a5b21dSYi Zou lport->seq_offload = 0; 62054a5b21dSYi Zou lport->lso_max = 0; 62154a5b21dSYi Zou } 62254a5b21dSYi Zou 62354a5b21dSYi Zou if (netdev->fcoe_ddp_xid) { 62454a5b21dSYi Zou lport->lro_enabled = 1; 62554a5b21dSYi Zou lport->lro_xid = netdev->fcoe_ddp_xid; 62654a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n", 62754a5b21dSYi Zou lport->lro_xid); 62854a5b21dSYi Zou } else { 62954a5b21dSYi Zou lport->lro_enabled = 0; 63054a5b21dSYi Zou lport->lro_xid = 0; 63154a5b21dSYi Zou } 63254a5b21dSYi Zou 63354a5b21dSYi Zou mutex_unlock(&lport->lp_mutex); 63454a5b21dSYi Zou } 63554a5b21dSYi Zou 63654a5b21dSYi Zou /** 6371875f27eSRobert Love * fcoe_netdev_config() - Set up net devive for SW FCoE 6381875f27eSRobert Love * @lport: The local port that is associated with the net device 6391875f27eSRobert Love * @netdev: The associated net device 640a703e490SVasu Dev * 6411875f27eSRobert Love * Must be called after fcoe_lport_config() as it will use local port mutex 642a703e490SVasu Dev * 643a703e490SVasu Dev * Returns: 0 for success 644a703e490SVasu Dev */ 6451875f27eSRobert Love static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev) 646a703e490SVasu Dev { 647a703e490SVasu Dev u32 mfs; 648a703e490SVasu Dev u64 wwnn, wwpn; 64925024989SChris Leech struct fcoe_interface *fcoe; 650014f5c3fSChris Leech struct fcoe_port *port; 651a703e490SVasu Dev 652a703e490SVasu Dev /* Setup lport private data to point to fcoe softc */ 6531875f27eSRobert Love port = lport_priv(lport); 65425024989SChris Leech fcoe = port->fcoe; 655a703e490SVasu Dev 656a703e490SVasu Dev /* 657a703e490SVasu Dev * Determine max frame size based on underlying device and optional 658a703e490SVasu Dev * user-configured limit. If the MFS is too low, fcoe_link_ok() 659a703e490SVasu Dev * will return 0, so do this first. 660a703e490SVasu Dev */ 6617221d7e5SYi Zou mfs = netdev->mtu; 6627221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) { 6637221d7e5SYi Zou mfs = FCOE_MTU; 6647221d7e5SYi Zou FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs); 6657221d7e5SYi Zou } 6667221d7e5SYi Zou mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof)); 6671875f27eSRobert Love if (fc_set_mfs(lport, mfs)) 668a703e490SVasu Dev return -EINVAL; 669a703e490SVasu Dev 670a703e490SVasu Dev /* offload features support */ 67154a5b21dSYi Zou fcoe_netdev_features_change(lport, netdev); 672a703e490SVasu Dev 673014f5c3fSChris Leech skb_queue_head_init(&port->fcoe_pending_queue); 674014f5c3fSChris Leech port->fcoe_pending_queue_active = 0; 6751875f27eSRobert Love setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lport); 676a703e490SVasu Dev 6775e4f8fe7SRobert Love fcoe_link_speed_update(lport); 6785e4f8fe7SRobert Love 6791875f27eSRobert Love if (!lport->vport) { 680dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN)) 68175ea89efSYi Zou wwnn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 1, 0); 6821875f27eSRobert Love fc_set_wwnn(lport, wwnn); 683dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN)) 684dcece412SYi Zou wwpn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 685cf4aebcaSVasu Dev 2, 0); 6861875f27eSRobert Love fc_set_wwpn(lport, wwpn); 6879a05753bSChris Leech } 688a703e490SVasu Dev 689a703e490SVasu Dev return 0; 690a703e490SVasu Dev } 691a703e490SVasu Dev 692a703e490SVasu Dev /** 6931875f27eSRobert Love * fcoe_shost_config() - Set up the SCSI host associated with a local port 6941875f27eSRobert Love * @lport: The local port 6951875f27eSRobert Love * @dev: The device associated with the SCSI host 696a703e490SVasu Dev * 697a703e490SVasu Dev * Must be called after fcoe_lport_config() and fcoe_netdev_config() 698a703e490SVasu Dev * 699a703e490SVasu Dev * Returns: 0 for success 700a703e490SVasu Dev */ 7018ba00a4bSVasu Dev static int fcoe_shost_config(struct fc_lport *lport, struct device *dev) 702a703e490SVasu Dev { 703a703e490SVasu Dev int rc = 0; 704a703e490SVasu Dev 705a703e490SVasu Dev /* lport scsi host config */ 7061875f27eSRobert Love lport->host->max_lun = FCOE_MAX_LUN; 7071875f27eSRobert Love lport->host->max_id = FCOE_MAX_FCP_TARGET; 7081875f27eSRobert Love lport->host->max_channel = 0; 709da87bfabSVasu Dev lport->host->max_cmd_len = FCOE_MAX_CMD_LEN; 710da87bfabSVasu Dev 7111875f27eSRobert Love if (lport->vport) 7128ca86f84SYi Zou lport->host->transportt = fcoe_vport_scsi_transport; 713e9084bb8SChris Leech else 7148ca86f84SYi Zou lport->host->transportt = fcoe_nport_scsi_transport; 715a703e490SVasu Dev 716a703e490SVasu Dev /* add the new host to the SCSI-ml */ 7171875f27eSRobert Love rc = scsi_add_host(lport->host, dev); 718a703e490SVasu Dev if (rc) { 7191875f27eSRobert Love FCOE_NETDEV_DBG(fcoe_netdev(lport), "fcoe_shost_config: " 720d5488eb9SRobert Love "error on scsi_add_host\n"); 721a703e490SVasu Dev return rc; 722a703e490SVasu Dev } 7239a05753bSChris Leech 7241875f27eSRobert Love if (!lport->vport) 7254be929beSAlexey Dobriyan fc_host_max_npiv_vports(lport->host) = USHRT_MAX; 7269a05753bSChris Leech 7271875f27eSRobert Love snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 7285baa17c3SChris Leech "%s v%s over %s", FCOE_NAME, FCOE_VERSION, 7291875f27eSRobert Love fcoe_netdev(lport)->name); 730a703e490SVasu Dev 731a703e490SVasu Dev return 0; 732a703e490SVasu Dev } 733a703e490SVasu Dev 7341875f27eSRobert Love /** 7351875f27eSRobert Love * fcoe_oem_match() - The match routine for the offloaded exchange manager 7361875f27eSRobert Love * @fp: The I/O frame 737d7179680SVasu Dev * 7381875f27eSRobert Love * This routine will be associated with an exchange manager (EM). When 7391875f27eSRobert Love * the libfc exchange handling code is looking for an EM to use it will 7401875f27eSRobert Love * call this routine and pass it the frame that it wishes to send. This 7411875f27eSRobert Love * routine will return True if the associated EM is to be used and False 7421875f27eSRobert Love * if the echange code should continue looking for an EM. 7431875f27eSRobert Love * 7441875f27eSRobert Love * The offload EM that this routine is associated with will handle any 7451875f27eSRobert Love * packets that are for SCSI read requests. 7461875f27eSRobert Love * 7471875f27eSRobert Love * Returns: True for read types I/O, otherwise returns false. 748d7179680SVasu Dev */ 749d7179680SVasu Dev bool fcoe_oem_match(struct fc_frame *fp) 750d7179680SVasu Dev { 75105cc7390SYi Zou return fc_fcp_is_read(fr_fsp(fp)) && 75205cc7390SYi Zou (fr_fsp(fp)->data_len > fcoe_ddp_min); 753d7179680SVasu Dev } 754d7179680SVasu Dev 755a703e490SVasu Dev /** 7561875f27eSRobert Love * fcoe_em_config() - Allocate and configure an exchange manager 7571875f27eSRobert Love * @lport: The local port that the new EM will be associated with 758a703e490SVasu Dev * 759a703e490SVasu Dev * Returns: 0 on success 760a703e490SVasu Dev */ 7611875f27eSRobert Love static inline int fcoe_em_config(struct fc_lport *lport) 762a703e490SVasu Dev { 7631875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 76425024989SChris Leech struct fcoe_interface *fcoe = port->fcoe; 76525024989SChris Leech struct fcoe_interface *oldfcoe = NULL; 7661d1b88dcSVasu Dev struct net_device *old_real_dev, *cur_real_dev; 767d7179680SVasu Dev u16 min_xid = FCOE_MIN_XID; 768d7179680SVasu Dev u16 max_xid = FCOE_MAX_XID; 769d7179680SVasu Dev 770d7179680SVasu Dev /* 771d7179680SVasu Dev * Check if need to allocate an em instance for 772d7179680SVasu Dev * offload exchange ids to be shared across all VN_PORTs/lport. 773d7179680SVasu Dev */ 7741875f27eSRobert Love if (!lport->lro_enabled || !lport->lro_xid || 7751875f27eSRobert Love (lport->lro_xid >= max_xid)) { 7761875f27eSRobert Love lport->lro_xid = 0; 777d7179680SVasu Dev goto skip_oem; 778d7179680SVasu Dev } 779d7179680SVasu Dev 780d7179680SVasu Dev /* 781d7179680SVasu Dev * Reuse existing offload em instance in case 7821d1b88dcSVasu Dev * it is already allocated on real eth device 783d7179680SVasu Dev */ 78425024989SChris Leech if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 78525024989SChris Leech cur_real_dev = vlan_dev_real_dev(fcoe->netdev); 7861d1b88dcSVasu Dev else 78725024989SChris Leech cur_real_dev = fcoe->netdev; 7881d1b88dcSVasu Dev 78925024989SChris Leech list_for_each_entry(oldfcoe, &fcoe_hostlist, list) { 79025024989SChris Leech if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 79125024989SChris Leech old_real_dev = vlan_dev_real_dev(oldfcoe->netdev); 7921d1b88dcSVasu Dev else 79325024989SChris Leech old_real_dev = oldfcoe->netdev; 7941d1b88dcSVasu Dev 7951d1b88dcSVasu Dev if (cur_real_dev == old_real_dev) { 796991cbb60SChris Leech fcoe->oem = oldfcoe->oem; 797d7179680SVasu Dev break; 798d7179680SVasu Dev } 799d7179680SVasu Dev } 800d7179680SVasu Dev 801991cbb60SChris Leech if (fcoe->oem) { 8021875f27eSRobert Love if (!fc_exch_mgr_add(lport, fcoe->oem, fcoe_oem_match)) { 803d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to add " 804d7179680SVasu Dev "offload em:%p on interface:%s\n", 805991cbb60SChris Leech fcoe->oem, fcoe->netdev->name); 806a703e490SVasu Dev return -ENOMEM; 807d7179680SVasu Dev } 808d7179680SVasu Dev } else { 8091875f27eSRobert Love fcoe->oem = fc_exch_mgr_alloc(lport, FC_CLASS_3, 8101875f27eSRobert Love FCOE_MIN_XID, lport->lro_xid, 811d7179680SVasu Dev fcoe_oem_match); 812991cbb60SChris Leech if (!fcoe->oem) { 813d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to allocate " 814d7179680SVasu Dev "em for offload exches on interface:%s\n", 81525024989SChris Leech fcoe->netdev->name); 816d7179680SVasu Dev return -ENOMEM; 817d7179680SVasu Dev } 818d7179680SVasu Dev } 819d7179680SVasu Dev 820d7179680SVasu Dev /* 821d7179680SVasu Dev * Exclude offload EM xid range from next EM xid range. 822d7179680SVasu Dev */ 8231875f27eSRobert Love min_xid += lport->lro_xid + 1; 824d7179680SVasu Dev 825d7179680SVasu Dev skip_oem: 8261875f27eSRobert Love if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, min_xid, max_xid, NULL)) { 827d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to " 82825024989SChris Leech "allocate em on interface %s\n", fcoe->netdev->name); 829d7179680SVasu Dev return -ENOMEM; 830d7179680SVasu Dev } 831a703e490SVasu Dev 832a703e490SVasu Dev return 0; 833a703e490SVasu Dev } 834a703e490SVasu Dev 835a703e490SVasu Dev /** 8361875f27eSRobert Love * fcoe_if_destroy() - Tear down a SW FCoE instance 8371875f27eSRobert Love * @lport: The local port to be destroyed 83834ce27bcSVasu Dev * 83934ce27bcSVasu Dev * Locking: must be called with the RTNL mutex held and RTNL mutex 84034ce27bcSVasu Dev * needed to be dropped by this function since not dropping RTNL 84134ce27bcSVasu Dev * would cause circular locking warning on synchronous fip worker 84234ce27bcSVasu Dev * cancelling thru fcoe_interface_put invoked by this function. 84334ce27bcSVasu Dev * 844a703e490SVasu Dev */ 845af7f85d9SChris Leech static void fcoe_if_destroy(struct fc_lport *lport) 846a703e490SVasu Dev { 847014f5c3fSChris Leech struct fcoe_port *port = lport_priv(lport); 848014f5c3fSChris Leech struct fcoe_interface *fcoe = port->fcoe; 84925024989SChris Leech struct net_device *netdev = fcoe->netdev; 850a703e490SVasu Dev 851d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Destroying interface\n"); 852a703e490SVasu Dev 853a703e490SVasu Dev /* Logout of the fabric */ 854af7f85d9SChris Leech fc_fabric_logoff(lport); 855a703e490SVasu Dev 856a703e490SVasu Dev /* Cleanup the fc_lport */ 857af7f85d9SChris Leech fc_lport_destroy(lport); 858a703e490SVasu Dev 85954b649f8SChris Leech /* Stop the transmit retry timer */ 86054b649f8SChris Leech del_timer_sync(&port->timer); 86154b649f8SChris Leech 86254b649f8SChris Leech /* Free existing transmit skbs */ 86354b649f8SChris Leech fcoe_clean_pending_queue(lport); 86454b649f8SChris Leech 86511b56188SChris Leech if (!is_zero_ether_addr(port->data_src_addr)) 866a748ee24SJiri Pirko dev_uc_del(netdev, port->data_src_addr); 86711b56188SChris Leech rtnl_unlock(); 86811b56188SChris Leech 86954b649f8SChris Leech /* receives may not be stopped until after this */ 87054b649f8SChris Leech fcoe_interface_put(fcoe); 87154b649f8SChris Leech 87254b649f8SChris Leech /* Free queued packets for the per-CPU receive threads */ 87354b649f8SChris Leech fcoe_percpu_clean(lport); 87454b649f8SChris Leech 875a703e490SVasu Dev /* Detach from the scsi-ml */ 876af7f85d9SChris Leech fc_remove_host(lport->host); 877af7f85d9SChris Leech scsi_remove_host(lport->host); 878a703e490SVasu Dev 87980e736f8SYi Zou /* Destroy lport scsi_priv */ 88080e736f8SYi Zou fc_fcp_destroy(lport); 88180e736f8SYi Zou 882a703e490SVasu Dev /* There are no more rports or I/O, free the EM */ 883af7f85d9SChris Leech fc_exch_mgr_free(lport); 884a703e490SVasu Dev 885a703e490SVasu Dev /* Free memory used by statistical counters */ 886af7f85d9SChris Leech fc_lport_free_stats(lport); 887a703e490SVasu Dev 8882e70e241SChris Leech /* Release the Scsi_Host */ 889af7f85d9SChris Leech scsi_host_put(lport->host); 890a703e490SVasu Dev } 891a703e490SVasu Dev 8921875f27eSRobert Love /** 8931875f27eSRobert Love * fcoe_ddp_setup() - Call a LLD's ddp_setup through the net device 8941875f27eSRobert Love * @lport: The local port to setup DDP for 8951875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 8961875f27eSRobert Love * @sgl: The scatterlist describing this transfer 8971875f27eSRobert Love * @sgc: The number of sg items 898a703e490SVasu Dev * 8991875f27eSRobert Love * Returns: 0 if the DDP context was not configured 900a703e490SVasu Dev */ 9011875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid, 902a703e490SVasu Dev struct scatterlist *sgl, unsigned int sgc) 903a703e490SVasu Dev { 9041875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 905a703e490SVasu Dev 9061875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_setup) 9071875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_setup(netdev, 9081875f27eSRobert Love xid, sgl, 9091875f27eSRobert Love sgc); 910a703e490SVasu Dev 911a703e490SVasu Dev return 0; 912a703e490SVasu Dev } 913a703e490SVasu Dev 914a703e490SVasu Dev /** 9151875f27eSRobert Love * fcoe_ddp_done() - Call a LLD's ddp_done through the net device 9161875f27eSRobert Love * @lport: The local port to complete DDP on 9171875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 918a703e490SVasu Dev * 9191875f27eSRobert Love * Returns: the length of data that have been completed by DDP 9201875f27eSRobert Love */ 9211875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *lport, u16 xid) 9221875f27eSRobert Love { 9231875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 9241875f27eSRobert Love 9251875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_done) 9261875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_done(netdev, xid); 9271875f27eSRobert Love return 0; 9281875f27eSRobert Love } 9291875f27eSRobert Love 9301875f27eSRobert Love /** 9311875f27eSRobert Love * fcoe_if_create() - Create a FCoE instance on an interface 9321875f27eSRobert Love * @fcoe: The FCoE interface to create a local port on 9331875f27eSRobert Love * @parent: The device pointer to be the parent in sysfs for the SCSI host 9341875f27eSRobert Love * @npiv: Indicates if the port is a vport or not 9351875f27eSRobert Love * 9361875f27eSRobert Love * Creates a fc_lport instance and a Scsi_Host instance and configure them. 937a703e490SVasu Dev * 938af7f85d9SChris Leech * Returns: The allocated fc_lport or an error pointer 939a703e490SVasu Dev */ 940030f4e00SChris Leech static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe, 9419a05753bSChris Leech struct device *parent, int npiv) 942a703e490SVasu Dev { 9431875f27eSRobert Love struct net_device *netdev = fcoe->netdev; 944af7f85d9SChris Leech struct fc_lport *lport = NULL; 945014f5c3fSChris Leech struct fcoe_port *port; 9461875f27eSRobert Love int rc; 9479a05753bSChris Leech /* 9489a05753bSChris Leech * parent is only a vport if npiv is 1, 9499a05753bSChris Leech * but we'll only use vport in that case so go ahead and set it 9509a05753bSChris Leech */ 9519a05753bSChris Leech struct fc_vport *vport = dev_to_vport(parent); 952a703e490SVasu Dev 953d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Create Interface\n"); 954a703e490SVasu Dev 9559a05753bSChris Leech if (!npiv) { 95686221969SChris Leech lport = libfc_host_alloc(&fcoe_shost_template, 957014f5c3fSChris Leech sizeof(struct fcoe_port)); 9589a05753bSChris Leech } else { 9599a05753bSChris Leech lport = libfc_vport_create(vport, 9609a05753bSChris Leech sizeof(struct fcoe_port)); 9619a05753bSChris Leech } 96286221969SChris Leech if (!lport) { 963014f5c3fSChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n"); 964014f5c3fSChris Leech rc = -ENOMEM; 965030f4e00SChris Leech goto out; 966014f5c3fSChris Leech } 967014f5c3fSChris Leech port = lport_priv(lport); 9682e70e241SChris Leech port->lport = lport; 969014f5c3fSChris Leech port->fcoe = fcoe; 9702e70e241SChris Leech INIT_WORK(&port->destroy_work, fcoe_destroy_work); 971a703e490SVasu Dev 9721875f27eSRobert Love /* configure a fc_lport including the exchange manager */ 973af7f85d9SChris Leech rc = fcoe_lport_config(lport); 974a703e490SVasu Dev if (rc) { 975d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure lport for the " 976d5488eb9SRobert Love "interface\n"); 977a703e490SVasu Dev goto out_host_put; 978a703e490SVasu Dev } 979a703e490SVasu Dev 9809a05753bSChris Leech if (npiv) { 9819f8f3aa6SChris Leech FCOE_NETDEV_DBG(netdev, "Setting vport names, " 9829f8f3aa6SChris Leech "%16.16llx %16.16llx\n", 9839a05753bSChris Leech vport->node_name, vport->port_name); 9849a05753bSChris Leech fc_set_wwnn(lport, vport->node_name); 9859a05753bSChris Leech fc_set_wwpn(lport, vport->port_name); 9869a05753bSChris Leech } 9879a05753bSChris Leech 988ab6b85c1SVasu Dev /* configure lport network properties */ 989af7f85d9SChris Leech rc = fcoe_netdev_config(lport, netdev); 990ab6b85c1SVasu Dev if (rc) { 991d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the " 992d5488eb9SRobert Love "interface\n"); 99354b649f8SChris Leech goto out_lp_destroy; 994ab6b85c1SVasu Dev } 99597c8389dSJoe Eykholt 996a703e490SVasu Dev /* configure lport scsi host properties */ 9978ba00a4bSVasu Dev rc = fcoe_shost_config(lport, parent); 998a703e490SVasu Dev if (rc) { 999d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure shost for the " 1000d5488eb9SRobert Love "interface\n"); 100154b649f8SChris Leech goto out_lp_destroy; 1002a703e490SVasu Dev } 1003a703e490SVasu Dev 1004a703e490SVasu Dev /* Initialize the library */ 1005e10f8c66SJoe Eykholt rc = fcoe_libfc_config(lport, &fcoe->ctlr, &fcoe_libfc_fcn_templ, 1); 1006a703e490SVasu Dev if (rc) { 1007d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the " 1008d5488eb9SRobert Love "interface\n"); 1009a703e490SVasu Dev goto out_lp_destroy; 1010a703e490SVasu Dev } 1011a703e490SVasu Dev 10129a05753bSChris Leech if (!npiv) { 1013e8af4d43SVasu Dev /* 1014e8af4d43SVasu Dev * fcoe_em_alloc() and fcoe_hostlist_add() both 10159a05753bSChris Leech * need to be atomic with respect to other changes to the 10169a05753bSChris Leech * hostlist since fcoe_em_alloc() looks for an existing EM 1017e8af4d43SVasu Dev * instance on host list updated by fcoe_hostlist_add(). 1018c863df33SChris Leech * 10199a05753bSChris Leech * This is currently handled through the fcoe_config_mutex 10209a05753bSChris Leech * begin held. 1021e8af4d43SVasu Dev */ 1022c863df33SChris Leech 102396316099SVasu Dev /* lport exch manager allocation */ 1024af7f85d9SChris Leech rc = fcoe_em_config(lport); 102596316099SVasu Dev if (rc) { 10269a05753bSChris Leech FCOE_NETDEV_DBG(netdev, "Could not configure the EM " 10279a05753bSChris Leech "for the interface\n"); 102896316099SVasu Dev goto out_lp_destroy; 102996316099SVasu Dev } 10309a05753bSChris Leech } 103196316099SVasu Dev 1032030f4e00SChris Leech fcoe_interface_get(fcoe); 1033af7f85d9SChris Leech return lport; 1034a703e490SVasu Dev 1035a703e490SVasu Dev out_lp_destroy: 1036af7f85d9SChris Leech fc_exch_mgr_free(lport); 1037a703e490SVasu Dev out_host_put: 1038af7f85d9SChris Leech scsi_host_put(lport->host); 1039af7f85d9SChris Leech out: 1040af7f85d9SChris Leech return ERR_PTR(rc); 1041a703e490SVasu Dev } 1042a703e490SVasu Dev 1043a703e490SVasu Dev /** 10441875f27eSRobert Love * fcoe_if_init() - Initialization routine for fcoe.ko 10451875f27eSRobert Love * 10461875f27eSRobert Love * Attaches the SW FCoE transport to the FC transport 1047a703e490SVasu Dev * 1048a703e490SVasu Dev * Returns: 0 on success 1049a703e490SVasu Dev */ 1050a703e490SVasu Dev static int __init fcoe_if_init(void) 1051a703e490SVasu Dev { 1052a703e490SVasu Dev /* attach to scsi transport */ 10538ca86f84SYi Zou fcoe_nport_scsi_transport = 10548ca86f84SYi Zou fc_attach_transport(&fcoe_nport_fc_functions); 10558ca86f84SYi Zou fcoe_vport_scsi_transport = 10568ca86f84SYi Zou fc_attach_transport(&fcoe_vport_fc_functions); 1057a703e490SVasu Dev 10588ca86f84SYi Zou if (!fcoe_nport_scsi_transport) { 1059d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); 1060a703e490SVasu Dev return -ENODEV; 1061a703e490SVasu Dev } 1062a703e490SVasu Dev 1063a703e490SVasu Dev return 0; 1064a703e490SVasu Dev } 1065a703e490SVasu Dev 1066a703e490SVasu Dev /** 10671875f27eSRobert Love * fcoe_if_exit() - Tear down fcoe.ko 10681875f27eSRobert Love * 10691875f27eSRobert Love * Detaches the SW FCoE transport from the FC transport 1070a703e490SVasu Dev * 1071a703e490SVasu Dev * Returns: 0 on success 1072a703e490SVasu Dev */ 1073a703e490SVasu Dev int __exit fcoe_if_exit(void) 1074a703e490SVasu Dev { 10758ca86f84SYi Zou fc_release_transport(fcoe_nport_scsi_transport); 10768ca86f84SYi Zou fc_release_transport(fcoe_vport_scsi_transport); 10778ca86f84SYi Zou fcoe_nport_scsi_transport = NULL; 10788ca86f84SYi Zou fcoe_vport_scsi_transport = NULL; 1079a703e490SVasu Dev return 0; 1080a703e490SVasu Dev } 1081a703e490SVasu Dev 1082a703e490SVasu Dev /** 10831875f27eSRobert Love * fcoe_percpu_thread_create() - Create a receive thread for an online CPU 10841875f27eSRobert Love * @cpu: The CPU index of the CPU to create a receive thread for 1085a703e490SVasu Dev */ 1086a703e490SVasu Dev static void fcoe_percpu_thread_create(unsigned int cpu) 1087a703e490SVasu Dev { 1088a703e490SVasu Dev struct fcoe_percpu_s *p; 1089a703e490SVasu Dev struct task_struct *thread; 1090a703e490SVasu Dev 1091a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1092a703e490SVasu Dev 1093a703e490SVasu Dev thread = kthread_create(fcoe_percpu_receive_thread, 1094a703e490SVasu Dev (void *)p, "fcoethread/%d", cpu); 1095a703e490SVasu Dev 1096e7a51997SJoe Eykholt if (likely(!IS_ERR(thread))) { 1097a703e490SVasu Dev kthread_bind(thread, cpu); 1098a703e490SVasu Dev wake_up_process(thread); 1099a703e490SVasu Dev 1100a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1101a703e490SVasu Dev p->thread = thread; 1102a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1103a703e490SVasu Dev } 1104a703e490SVasu Dev } 1105a703e490SVasu Dev 1106a703e490SVasu Dev /** 11071875f27eSRobert Love * fcoe_percpu_thread_destroy() - Remove the receive thread of a CPU 11081875f27eSRobert Love * @cpu: The CPU index of the CPU whose receive thread is to be destroyed 1109a703e490SVasu Dev * 1110a703e490SVasu Dev * Destroys a per-CPU Rx thread. Any pending skbs are moved to the 1111a703e490SVasu Dev * current CPU's Rx thread. If the thread being destroyed is bound to 1112a703e490SVasu Dev * the CPU processing this context the skbs will be freed. 1113a703e490SVasu Dev */ 1114a703e490SVasu Dev static void fcoe_percpu_thread_destroy(unsigned int cpu) 1115a703e490SVasu Dev { 1116a703e490SVasu Dev struct fcoe_percpu_s *p; 1117a703e490SVasu Dev struct task_struct *thread; 1118a703e490SVasu Dev struct page *crc_eof; 1119a703e490SVasu Dev struct sk_buff *skb; 1120a703e490SVasu Dev #ifdef CONFIG_SMP 1121a703e490SVasu Dev struct fcoe_percpu_s *p0; 1122f018b73aSJoe Eykholt unsigned targ_cpu = get_cpu(); 1123a703e490SVasu Dev #endif /* CONFIG_SMP */ 1124a703e490SVasu Dev 1125d5488eb9SRobert Love FCOE_DBG("Destroying receive thread for CPU %d\n", cpu); 1126a703e490SVasu Dev 1127a703e490SVasu Dev /* Prevent any new skbs from being queued for this CPU. */ 1128a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1129a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1130a703e490SVasu Dev thread = p->thread; 1131a703e490SVasu Dev p->thread = NULL; 1132a703e490SVasu Dev crc_eof = p->crc_eof_page; 1133a703e490SVasu Dev p->crc_eof_page = NULL; 1134a703e490SVasu Dev p->crc_eof_offset = 0; 1135a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1136a703e490SVasu Dev 1137a703e490SVasu Dev #ifdef CONFIG_SMP 1138a703e490SVasu Dev /* 1139a703e490SVasu Dev * Don't bother moving the skb's if this context is running 1140a703e490SVasu Dev * on the same CPU that is having its thread destroyed. This 1141a703e490SVasu Dev * can easily happen when the module is removed. 1142a703e490SVasu Dev */ 1143a703e490SVasu Dev if (cpu != targ_cpu) { 1144a703e490SVasu Dev p0 = &per_cpu(fcoe_percpu, targ_cpu); 1145a703e490SVasu Dev spin_lock_bh(&p0->fcoe_rx_list.lock); 1146a703e490SVasu Dev if (p0->thread) { 1147d5488eb9SRobert Love FCOE_DBG("Moving frames from CPU %d to CPU %d\n", 1148a703e490SVasu Dev cpu, targ_cpu); 1149a703e490SVasu Dev 1150a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1151a703e490SVasu Dev __skb_queue_tail(&p0->fcoe_rx_list, skb); 1152a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1153a703e490SVasu Dev } else { 1154a703e490SVasu Dev /* 1155a703e490SVasu Dev * The targeted CPU is not initialized and cannot accept 1156a703e490SVasu Dev * new skbs. Unlock the targeted CPU and drop the skbs 1157a703e490SVasu Dev * on the CPU that is going offline. 1158a703e490SVasu Dev */ 1159a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1160a703e490SVasu Dev kfree_skb(skb); 1161a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1162a703e490SVasu Dev } 1163a703e490SVasu Dev } else { 1164a703e490SVasu Dev /* 1165a703e490SVasu Dev * This scenario occurs when the module is being removed 1166a703e490SVasu Dev * and all threads are being destroyed. skbs will continue 1167a703e490SVasu Dev * to be shifted from the CPU thread that is being removed 1168a703e490SVasu Dev * to the CPU thread associated with the CPU that is processing 1169a703e490SVasu Dev * the module removal. Once there is only one CPU Rx thread it 1170a703e490SVasu Dev * will reach this case and we will drop all skbs and later 1171a703e490SVasu Dev * stop the thread. 1172a703e490SVasu Dev */ 1173a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1174a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1175a703e490SVasu Dev kfree_skb(skb); 1176a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1177a703e490SVasu Dev } 1178f018b73aSJoe Eykholt put_cpu(); 1179a703e490SVasu Dev #else 1180a703e490SVasu Dev /* 1181dd3fd72eSChris Leech * This a non-SMP scenario where the singular Rx thread is 1182a703e490SVasu Dev * being removed. Free all skbs and stop the thread. 1183a703e490SVasu Dev */ 1184a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1185a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1186a703e490SVasu Dev kfree_skb(skb); 1187a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1188a703e490SVasu Dev #endif 1189a703e490SVasu Dev 1190a703e490SVasu Dev if (thread) 1191a703e490SVasu Dev kthread_stop(thread); 1192a703e490SVasu Dev 1193a703e490SVasu Dev if (crc_eof) 1194a703e490SVasu Dev put_page(crc_eof); 1195a703e490SVasu Dev } 1196a703e490SVasu Dev 1197a703e490SVasu Dev /** 11981875f27eSRobert Love * fcoe_cpu_callback() - Handler for CPU hotplug events 11991875f27eSRobert Love * @nfb: The callback data block 12001875f27eSRobert Love * @action: The event triggering the callback 12011875f27eSRobert Love * @hcpu: The index of the CPU that the event is for 1202a703e490SVasu Dev * 12031875f27eSRobert Love * This creates or destroys per-CPU data for fcoe 1204a703e490SVasu Dev * 1205a703e490SVasu Dev * Returns NOTIFY_OK always. 1206a703e490SVasu Dev */ 1207a703e490SVasu Dev static int fcoe_cpu_callback(struct notifier_block *nfb, 1208a703e490SVasu Dev unsigned long action, void *hcpu) 1209a703e490SVasu Dev { 1210a703e490SVasu Dev unsigned cpu = (unsigned long)hcpu; 1211a703e490SVasu Dev 1212a703e490SVasu Dev switch (action) { 1213a703e490SVasu Dev case CPU_ONLINE: 1214a703e490SVasu Dev case CPU_ONLINE_FROZEN: 1215d5488eb9SRobert Love FCOE_DBG("CPU %x online: Create Rx thread\n", cpu); 1216a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 1217a703e490SVasu Dev break; 1218a703e490SVasu Dev case CPU_DEAD: 1219a703e490SVasu Dev case CPU_DEAD_FROZEN: 1220d5488eb9SRobert Love FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu); 1221a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 1222a703e490SVasu Dev break; 1223a703e490SVasu Dev default: 1224a703e490SVasu Dev break; 1225a703e490SVasu Dev } 1226a703e490SVasu Dev return NOTIFY_OK; 1227a703e490SVasu Dev } 1228a703e490SVasu Dev 1229a703e490SVasu Dev /** 12301875f27eSRobert Love * fcoe_rcv() - Receive packets from a net device 12311875f27eSRobert Love * @skb: The received packet 12321875f27eSRobert Love * @netdev: The net device that the packet was received on 12331875f27eSRobert Love * @ptype: The packet type context 12341875f27eSRobert Love * @olddev: The last device net device 1235a703e490SVasu Dev * 12361875f27eSRobert Love * This routine is called by NET_RX_SOFTIRQ. It receives a packet, builds a 12371875f27eSRobert Love * FC frame and passes the frame to libfc. 1238a703e490SVasu Dev * 1239a703e490SVasu Dev * Returns: 0 for success 1240a703e490SVasu Dev */ 12411875f27eSRobert Love int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, 1242a703e490SVasu Dev struct packet_type *ptype, struct net_device *olddev) 1243a703e490SVasu Dev { 12441875f27eSRobert Love struct fc_lport *lport; 1245a703e490SVasu Dev struct fcoe_rcv_info *fr; 1246259ad85dSChris Leech struct fcoe_interface *fcoe; 1247a703e490SVasu Dev struct fc_frame_header *fh; 1248a703e490SVasu Dev struct fcoe_percpu_s *fps; 1249519e5135SVasu Dev struct ethhdr *eh; 1250b2f0091fSVasu Dev unsigned int cpu; 1251a703e490SVasu Dev 1252259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type); 12531875f27eSRobert Love lport = fcoe->ctlr.lp; 12541875f27eSRobert Love if (unlikely(!lport)) { 12551875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "Cannot find hba structure"); 1256a703e490SVasu Dev goto err2; 1257a703e490SVasu Dev } 12581875f27eSRobert Love if (!lport->link_up) 125997c8389dSJoe Eykholt goto err2; 1260a703e490SVasu Dev 12611875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "skb_info: len:%d data_len:%d head:%p " 1262d5488eb9SRobert Love "data:%p tail:%p end:%p sum:%d dev:%s", 1263d5488eb9SRobert Love skb->len, skb->data_len, skb->head, skb->data, 1264d5488eb9SRobert Love skb_tail_pointer(skb), skb_end_pointer(skb), 1265d5488eb9SRobert Love skb->csum, skb->dev ? skb->dev->name : "<NULL>"); 1266a703e490SVasu Dev 1267519e5135SVasu Dev eh = eth_hdr(skb); 1268519e5135SVasu Dev 1269519e5135SVasu Dev if (is_fip_mode(&fcoe->ctlr) && 1270519e5135SVasu Dev compare_ether_addr(eh->h_source, fcoe->ctlr.dest_addr)) { 1271519e5135SVasu Dev FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n", 1272519e5135SVasu Dev eh->h_source); 1273a703e490SVasu Dev goto err; 1274a703e490SVasu Dev } 1275a703e490SVasu Dev 1276a703e490SVasu Dev /* 1277a703e490SVasu Dev * Check for minimum frame length, and make sure required FCoE 1278a703e490SVasu Dev * and FC headers are pulled into the linear data area. 1279a703e490SVasu Dev */ 1280a703e490SVasu Dev if (unlikely((skb->len < FCOE_MIN_FRAME) || 1281a703e490SVasu Dev !pskb_may_pull(skb, FCOE_HEADER_LEN))) 1282a703e490SVasu Dev goto err; 1283a703e490SVasu Dev 1284a703e490SVasu Dev skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); 1285a703e490SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 1286a703e490SVasu Dev 12870ee31cb5SRobert Love if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id)) { 12880ee31cb5SRobert Love FCOE_NETDEV_DBG(netdev, "FC frame d_id mismatch with MAC:%pM\n", 12890ee31cb5SRobert Love eh->h_dest); 12900ee31cb5SRobert Love goto err; 12910ee31cb5SRobert Love } 12920ee31cb5SRobert Love 1293a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 12941875f27eSRobert Love fr->fr_dev = lport; 1295a703e490SVasu Dev fr->ptype = ptype; 1296a703e490SVasu Dev 1297a703e490SVasu Dev /* 1298b2f0091fSVasu Dev * In case the incoming frame's exchange is originated from 1299b2f0091fSVasu Dev * the initiator, then received frame's exchange id is ANDed 1300b2f0091fSVasu Dev * with fc_cpu_mask bits to get the same cpu on which exchange 1301b2f0091fSVasu Dev * was originated, otherwise just use the current cpu. 1302a703e490SVasu Dev */ 1303b2f0091fSVasu Dev if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX) 1304b2f0091fSVasu Dev cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask; 1305b2f0091fSVasu Dev else 1306b2f0091fSVasu Dev cpu = smp_processor_id(); 1307a703e490SVasu Dev 1308a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1309a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1310a703e490SVasu Dev if (unlikely(!fps->thread)) { 1311a703e490SVasu Dev /* 1312a703e490SVasu Dev * The targeted CPU is not ready, let's target 1313a703e490SVasu Dev * the first CPU now. For non-SMP systems this 1314a703e490SVasu Dev * will check the same CPU twice. 1315a703e490SVasu Dev */ 13161875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "CPU is online, but no receive thread " 1317d5488eb9SRobert Love "ready for incoming skb- using first online " 1318d5488eb9SRobert Love "CPU.\n"); 1319a703e490SVasu Dev 1320a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 13216957177fSRusty Russell cpu = cpumask_first(cpu_online_mask); 1322a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1323a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1324a703e490SVasu Dev if (!fps->thread) { 1325a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1326a703e490SVasu Dev goto err; 1327a703e490SVasu Dev } 1328a703e490SVasu Dev } 1329a703e490SVasu Dev 1330a703e490SVasu Dev /* 1331a703e490SVasu Dev * We now have a valid CPU that we're targeting for 1332a703e490SVasu Dev * this skb. We also have this receive thread locked, 1333a703e490SVasu Dev * so we're free to queue skbs into it's queue. 1334a703e490SVasu Dev */ 1335859b7b64SChris Leech 1336859b7b64SChris Leech /* If this is a SCSI-FCP frame, and this is already executing on the 1337859b7b64SChris Leech * correct CPU, and the queue for this CPU is empty, then go ahead 1338859b7b64SChris Leech * and process the frame directly in the softirq context. 1339859b7b64SChris Leech * This lets us process completions without context switching from the 1340859b7b64SChris Leech * NET_RX softirq, to our receive processing thread, and then back to 1341859b7b64SChris Leech * BLOCK softirq context. 1342859b7b64SChris Leech */ 1343859b7b64SChris Leech if (fh->fh_type == FC_TYPE_FCP && 1344859b7b64SChris Leech cpu == smp_processor_id() && 1345859b7b64SChris Leech skb_queue_empty(&fps->fcoe_rx_list)) { 1346859b7b64SChris Leech spin_unlock_bh(&fps->fcoe_rx_list.lock); 1347859b7b64SChris Leech fcoe_recv_frame(skb); 1348859b7b64SChris Leech } else { 1349a703e490SVasu Dev __skb_queue_tail(&fps->fcoe_rx_list, skb); 1350a703e490SVasu Dev if (fps->fcoe_rx_list.qlen == 1) 1351a703e490SVasu Dev wake_up_process(fps->thread); 1352a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1353859b7b64SChris Leech } 1354a703e490SVasu Dev 1355a703e490SVasu Dev return 0; 1356a703e490SVasu Dev err: 1357f018b73aSJoe Eykholt per_cpu_ptr(lport->dev_stats, get_cpu())->ErrorFrames++; 1358f018b73aSJoe Eykholt put_cpu(); 1359a703e490SVasu Dev err2: 1360a703e490SVasu Dev kfree_skb(skb); 1361a703e490SVasu Dev return -1; 1362a703e490SVasu Dev } 1363a703e490SVasu Dev 1364a703e490SVasu Dev /** 13651875f27eSRobert Love * fcoe_start_io() - Start FCoE I/O 13661875f27eSRobert Love * @skb: The packet to be transmitted 13671875f27eSRobert Love * 13681875f27eSRobert Love * This routine is called from the net device to start transmitting 13691875f27eSRobert Love * FCoE packets. 1370a703e490SVasu Dev * 1371a703e490SVasu Dev * Returns: 0 for success 1372a703e490SVasu Dev */ 1373a703e490SVasu Dev static inline int fcoe_start_io(struct sk_buff *skb) 1374a703e490SVasu Dev { 137518fa11efSChris Leech struct sk_buff *nskb; 1376a703e490SVasu Dev int rc; 1377a703e490SVasu Dev 137818fa11efSChris Leech nskb = skb_clone(skb, GFP_ATOMIC); 137918fa11efSChris Leech rc = dev_queue_xmit(nskb); 1380a703e490SVasu Dev if (rc != 0) 1381a703e490SVasu Dev return rc; 1382a703e490SVasu Dev kfree_skb(skb); 1383a703e490SVasu Dev return 0; 1384a703e490SVasu Dev } 1385a703e490SVasu Dev 1386a703e490SVasu Dev /** 13871875f27eSRobert Love * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC 13881875f27eSRobert Love * @skb: The packet to be transmitted 13891875f27eSRobert Love * @tlen: The total length of the trailer 13901875f27eSRobert Love * 13911875f27eSRobert Love * This routine allocates a page for frame trailers. The page is re-used if 13921875f27eSRobert Love * there is enough room left on it for the current trailer. If there isn't 13931875f27eSRobert Love * enough buffer left a new page is allocated for the trailer. Reference to 13941875f27eSRobert Love * the page from this function as well as the skbs using the page fragments 13951875f27eSRobert Love * ensure that the page is freed at the appropriate time. 1396a703e490SVasu Dev * 1397a703e490SVasu Dev * Returns: 0 for success 1398a703e490SVasu Dev */ 1399a703e490SVasu Dev static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen) 1400a703e490SVasu Dev { 1401a703e490SVasu Dev struct fcoe_percpu_s *fps; 1402a703e490SVasu Dev struct page *page; 1403a703e490SVasu Dev 1404a703e490SVasu Dev fps = &get_cpu_var(fcoe_percpu); 1405a703e490SVasu Dev page = fps->crc_eof_page; 1406a703e490SVasu Dev if (!page) { 1407a703e490SVasu Dev page = alloc_page(GFP_ATOMIC); 1408a703e490SVasu Dev if (!page) { 1409a703e490SVasu Dev put_cpu_var(fcoe_percpu); 1410a703e490SVasu Dev return -ENOMEM; 1411a703e490SVasu Dev } 1412a703e490SVasu Dev fps->crc_eof_page = page; 1413a703e490SVasu Dev fps->crc_eof_offset = 0; 1414a703e490SVasu Dev } 1415a703e490SVasu Dev 1416a703e490SVasu Dev get_page(page); 1417a703e490SVasu Dev skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page, 1418a703e490SVasu Dev fps->crc_eof_offset, tlen); 1419a703e490SVasu Dev skb->len += tlen; 1420a703e490SVasu Dev skb->data_len += tlen; 1421a703e490SVasu Dev skb->truesize += tlen; 1422a703e490SVasu Dev fps->crc_eof_offset += sizeof(struct fcoe_crc_eof); 1423a703e490SVasu Dev 1424a703e490SVasu Dev if (fps->crc_eof_offset >= PAGE_SIZE) { 1425a703e490SVasu Dev fps->crc_eof_page = NULL; 1426a703e490SVasu Dev fps->crc_eof_offset = 0; 1427a703e490SVasu Dev put_page(page); 1428a703e490SVasu Dev } 1429a703e490SVasu Dev put_cpu_var(fcoe_percpu); 1430a703e490SVasu Dev return 0; 1431a703e490SVasu Dev } 1432a703e490SVasu Dev 1433a703e490SVasu Dev /** 14341875f27eSRobert Love * fcoe_fc_crc() - Calculates the CRC for a given frame 14351875f27eSRobert Love * @fp: The frame to be checksumed 1436a703e490SVasu Dev * 14371875f27eSRobert Love * This uses crc32() routine to calculate the CRC for a frame 14381875f27eSRobert Love * 14391875f27eSRobert Love * Return: The 32 bit CRC value 1440a703e490SVasu Dev */ 1441a703e490SVasu Dev u32 fcoe_fc_crc(struct fc_frame *fp) 1442a703e490SVasu Dev { 1443a703e490SVasu Dev struct sk_buff *skb = fp_skb(fp); 1444a703e490SVasu Dev struct skb_frag_struct *frag; 1445a703e490SVasu Dev unsigned char *data; 1446a703e490SVasu Dev unsigned long off, len, clen; 1447a703e490SVasu Dev u32 crc; 1448a703e490SVasu Dev unsigned i; 1449a703e490SVasu Dev 1450a703e490SVasu Dev crc = crc32(~0, skb->data, skb_headlen(skb)); 1451a703e490SVasu Dev 1452a703e490SVasu Dev for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 1453a703e490SVasu Dev frag = &skb_shinfo(skb)->frags[i]; 1454a703e490SVasu Dev off = frag->page_offset; 1455a703e490SVasu Dev len = frag->size; 1456a703e490SVasu Dev while (len > 0) { 1457a703e490SVasu Dev clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK)); 1458a703e490SVasu Dev data = kmap_atomic(frag->page + (off >> PAGE_SHIFT), 1459a703e490SVasu Dev KM_SKB_DATA_SOFTIRQ); 1460a703e490SVasu Dev crc = crc32(crc, data + (off & ~PAGE_MASK), clen); 1461a703e490SVasu Dev kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ); 1462a703e490SVasu Dev off += clen; 1463a703e490SVasu Dev len -= clen; 1464a703e490SVasu Dev } 1465a703e490SVasu Dev } 1466a703e490SVasu Dev return crc; 1467a703e490SVasu Dev } 1468a703e490SVasu Dev 1469a703e490SVasu Dev /** 14701875f27eSRobert Love * fcoe_xmit() - Transmit a FCoE frame 14711875f27eSRobert Love * @lport: The local port that the frame is to be transmitted for 14721875f27eSRobert Love * @fp: The frame to be transmitted 1473a703e490SVasu Dev * 1474a703e490SVasu Dev * Return: 0 for success 1475a703e490SVasu Dev */ 14761875f27eSRobert Love int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp) 1477a703e490SVasu Dev { 14784bb6b515SVasu Dev int wlen; 1479a703e490SVasu Dev u32 crc; 1480a703e490SVasu Dev struct ethhdr *eh; 1481a703e490SVasu Dev struct fcoe_crc_eof *cp; 1482a703e490SVasu Dev struct sk_buff *skb; 1483a703e490SVasu Dev struct fcoe_dev_stats *stats; 1484a703e490SVasu Dev struct fc_frame_header *fh; 1485a703e490SVasu Dev unsigned int hlen; /* header length implies the version */ 1486a703e490SVasu Dev unsigned int tlen; /* trailer length */ 1487a703e490SVasu Dev unsigned int elen; /* eth header, may include vlan */ 14881875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 14893fe9a0baSChris Leech struct fcoe_interface *fcoe = port->fcoe; 1490a703e490SVasu Dev u8 sof, eof; 1491a703e490SVasu Dev struct fcoe_hdr *hp; 1492a703e490SVasu Dev 1493a703e490SVasu Dev WARN_ON((fr_len(fp) % sizeof(u32)) != 0); 1494a703e490SVasu Dev 1495a703e490SVasu Dev fh = fc_frame_header_get(fp); 149697c8389dSJoe Eykholt skb = fp_skb(fp); 149797c8389dSJoe Eykholt wlen = skb->len / FCOE_WORD_TO_BYTE; 149897c8389dSJoe Eykholt 14991875f27eSRobert Love if (!lport->link_up) { 15003caf02eeSDan Carpenter kfree_skb(skb); 150197c8389dSJoe Eykholt return 0; 1502a703e490SVasu Dev } 1503a703e490SVasu Dev 15049860eeb4SJoe Eykholt if (unlikely(fh->fh_type == FC_TYPE_ELS) && 15051875f27eSRobert Love fcoe_ctlr_els_send(&fcoe->ctlr, lport, skb)) 150697c8389dSJoe Eykholt return 0; 150797c8389dSJoe Eykholt 1508a703e490SVasu Dev sof = fr_sof(fp); 1509a703e490SVasu Dev eof = fr_eof(fp); 1510a703e490SVasu Dev 15114e57e1cbSVasu Dev elen = sizeof(struct ethhdr); 1512a703e490SVasu Dev hlen = sizeof(struct fcoe_hdr); 1513a703e490SVasu Dev tlen = sizeof(struct fcoe_crc_eof); 1514a703e490SVasu Dev wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; 1515a703e490SVasu Dev 1516a703e490SVasu Dev /* crc offload */ 15171875f27eSRobert Love if (likely(lport->crc_offload)) { 1518a703e490SVasu Dev skb->ip_summed = CHECKSUM_PARTIAL; 1519a703e490SVasu Dev skb->csum_start = skb_headroom(skb); 1520a703e490SVasu Dev skb->csum_offset = skb->len; 1521a703e490SVasu Dev crc = 0; 1522a703e490SVasu Dev } else { 1523a703e490SVasu Dev skb->ip_summed = CHECKSUM_NONE; 1524a703e490SVasu Dev crc = fcoe_fc_crc(fp); 1525a703e490SVasu Dev } 1526a703e490SVasu Dev 1527014f5c3fSChris Leech /* copy port crc and eof to the skb buff */ 1528a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1529a703e490SVasu Dev skb_frag_t *frag; 1530a703e490SVasu Dev if (fcoe_get_paged_crc_eof(skb, tlen)) { 1531a703e490SVasu Dev kfree_skb(skb); 1532a703e490SVasu Dev return -ENOMEM; 1533a703e490SVasu Dev } 1534a703e490SVasu Dev frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; 1535a703e490SVasu Dev cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ) 1536a703e490SVasu Dev + frag->page_offset; 1537a703e490SVasu Dev } else { 1538a703e490SVasu Dev cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); 1539a703e490SVasu Dev } 1540a703e490SVasu Dev 1541a703e490SVasu Dev memset(cp, 0, sizeof(*cp)); 1542a703e490SVasu Dev cp->fcoe_eof = eof; 1543a703e490SVasu Dev cp->fcoe_crc32 = cpu_to_le32(~crc); 1544a703e490SVasu Dev 1545a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1546a703e490SVasu Dev kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ); 1547a703e490SVasu Dev cp = NULL; 1548a703e490SVasu Dev } 1549a703e490SVasu Dev 1550014f5c3fSChris Leech /* adjust skb network/transport offsets to match mac/fcoe/port */ 1551a703e490SVasu Dev skb_push(skb, elen + hlen); 1552a703e490SVasu Dev skb_reset_mac_header(skb); 1553a703e490SVasu Dev skb_reset_network_header(skb); 1554a703e490SVasu Dev skb->mac_len = elen; 1555a703e490SVasu Dev skb->protocol = htons(ETH_P_FCOE); 15563fe9a0baSChris Leech skb->dev = fcoe->netdev; 1557a703e490SVasu Dev 1558a703e490SVasu Dev /* fill up mac and fcoe headers */ 1559a703e490SVasu Dev eh = eth_hdr(skb); 1560a703e490SVasu Dev eh->h_proto = htons(ETH_P_FCOE); 15613fe9a0baSChris Leech memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN); 1562cd229e42SJoe Eykholt if (fcoe->ctlr.map_dest) 1563cd229e42SJoe Eykholt memcpy(eh->h_dest + 3, fh->fh_d_id, 3); 1564a703e490SVasu Dev 15653fe9a0baSChris Leech if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN)) 15663fe9a0baSChris Leech memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN); 1567a703e490SVasu Dev else 156811b56188SChris Leech memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); 1569a703e490SVasu Dev 1570a703e490SVasu Dev hp = (struct fcoe_hdr *)(eh + 1); 1571a703e490SVasu Dev memset(hp, 0, sizeof(*hp)); 1572a703e490SVasu Dev if (FC_FCOE_VER) 1573a703e490SVasu Dev FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); 1574a703e490SVasu Dev hp->fcoe_sof = sof; 1575a703e490SVasu Dev 1576a703e490SVasu Dev /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ 15771875f27eSRobert Love if (lport->seq_offload && fr_max_payload(fp)) { 1578a703e490SVasu Dev skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; 1579a703e490SVasu Dev skb_shinfo(skb)->gso_size = fr_max_payload(fp); 1580a703e490SVasu Dev } else { 1581a703e490SVasu Dev skb_shinfo(skb)->gso_type = 0; 1582a703e490SVasu Dev skb_shinfo(skb)->gso_size = 0; 1583a703e490SVasu Dev } 1584a703e490SVasu Dev /* update tx stats: regardless if LLD fails */ 1585f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1586a703e490SVasu Dev stats->TxFrames++; 1587a703e490SVasu Dev stats->TxWords += wlen; 1588f018b73aSJoe Eykholt put_cpu(); 1589a703e490SVasu Dev 1590a703e490SVasu Dev /* send down to lld */ 15911875f27eSRobert Love fr_dev(fp) = lport; 1592014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen) 15931875f27eSRobert Love fcoe_check_wait_queue(lport, skb); 15944bb6b515SVasu Dev else if (fcoe_start_io(skb)) 15951875f27eSRobert Love fcoe_check_wait_queue(lport, skb); 1596a703e490SVasu Dev 1597a703e490SVasu Dev return 0; 1598a703e490SVasu Dev } 1599a703e490SVasu Dev 1600a703e490SVasu Dev /** 16011875f27eSRobert Love * fcoe_percpu_flush_done() - Indicate per-CPU queue flush completion 16021875f27eSRobert Love * @skb: The completed skb (argument required by destructor) 1603e7a51997SJoe Eykholt */ 1604e7a51997SJoe Eykholt static void fcoe_percpu_flush_done(struct sk_buff *skb) 1605e7a51997SJoe Eykholt { 1606e7a51997SJoe Eykholt complete(&fcoe_flush_completion); 1607e7a51997SJoe Eykholt } 1608e7a51997SJoe Eykholt 1609e7a51997SJoe Eykholt /** 161052ee8321SVasu Dev * fcoe_filter_frames() - filter out bad fcoe frames, i.e. bad CRC 161152ee8321SVasu Dev * @lport: The local port the frame was received on 161252ee8321SVasu Dev * @fp: The received frame 161352ee8321SVasu Dev * 161452ee8321SVasu Dev * Return: 0 on passing filtering checks 161552ee8321SVasu Dev */ 161652ee8321SVasu Dev static inline int fcoe_filter_frames(struct fc_lport *lport, 161752ee8321SVasu Dev struct fc_frame *fp) 161852ee8321SVasu Dev { 161952ee8321SVasu Dev struct fcoe_interface *fcoe; 162052ee8321SVasu Dev struct fc_frame_header *fh; 162152ee8321SVasu Dev struct sk_buff *skb = (struct sk_buff *)fp; 162252ee8321SVasu Dev struct fcoe_dev_stats *stats; 162352ee8321SVasu Dev 162452ee8321SVasu Dev /* 162552ee8321SVasu Dev * We only check CRC if no offload is available and if it is 162652ee8321SVasu Dev * it's solicited data, in which case, the FCP layer would 162752ee8321SVasu Dev * check it during the copy. 162852ee8321SVasu Dev */ 162952ee8321SVasu Dev if (lport->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY) 163052ee8321SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 163152ee8321SVasu Dev else 163252ee8321SVasu Dev fr_flags(fp) |= FCPHF_CRC_UNCHECKED; 163352ee8321SVasu Dev 163452ee8321SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 163552ee8321SVasu Dev fh = fc_frame_header_get(fp); 163652ee8321SVasu Dev if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && fh->fh_type == FC_TYPE_FCP) 163752ee8321SVasu Dev return 0; 163852ee8321SVasu Dev 163952ee8321SVasu Dev fcoe = ((struct fcoe_port *)lport_priv(lport))->fcoe; 164052ee8321SVasu Dev if (is_fip_mode(&fcoe->ctlr) && fc_frame_payload_op(fp) == ELS_LOGO && 164152ee8321SVasu Dev ntoh24(fh->fh_s_id) == FC_FID_FLOGI) { 164252ee8321SVasu Dev FCOE_DBG("fcoe: dropping FCoE lport LOGO in fip mode\n"); 164352ee8321SVasu Dev return -EINVAL; 164452ee8321SVasu Dev } 164552ee8321SVasu Dev 164652ee8321SVasu Dev if (!fr_flags(fp) & FCPHF_CRC_UNCHECKED || 164752ee8321SVasu Dev le32_to_cpu(fr_crc(fp)) == ~crc32(~0, skb->data, skb->len)) { 164852ee8321SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 164952ee8321SVasu Dev return 0; 165052ee8321SVasu Dev } 165152ee8321SVasu Dev 165252ee8321SVasu Dev stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 165352ee8321SVasu Dev stats->InvalidCRCCount++; 165452ee8321SVasu Dev if (stats->InvalidCRCCount < 5) 165552ee8321SVasu Dev printk(KERN_WARNING "fcoe: dropping frame with CRC error\n"); 165652ee8321SVasu Dev return -EINVAL; 165752ee8321SVasu Dev } 165852ee8321SVasu Dev 165952ee8321SVasu Dev /** 1660859b7b64SChris Leech * fcoe_recv_frame() - process a single received frame 1661859b7b64SChris Leech * @skb: frame to process 1662a703e490SVasu Dev */ 1663859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb) 1664a703e490SVasu Dev { 1665a703e490SVasu Dev u32 fr_len; 16661875f27eSRobert Love struct fc_lport *lport; 1667a703e490SVasu Dev struct fcoe_rcv_info *fr; 1668a703e490SVasu Dev struct fcoe_dev_stats *stats; 1669a703e490SVasu Dev struct fcoe_crc_eof crc_eof; 1670a703e490SVasu Dev struct fc_frame *fp; 1671014f5c3fSChris Leech struct fcoe_port *port; 1672a703e490SVasu Dev struct fcoe_hdr *hp; 1673a703e490SVasu Dev 1674a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 16751875f27eSRobert Love lport = fr->fr_dev; 16761875f27eSRobert Love if (unlikely(!lport)) { 1677e7a51997SJoe Eykholt if (skb->destructor != fcoe_percpu_flush_done) 1678e7a51997SJoe Eykholt FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb"); 1679a703e490SVasu Dev kfree_skb(skb); 1680859b7b64SChris Leech return; 1681a703e490SVasu Dev } 1682a703e490SVasu Dev 1683d5488eb9SRobert Love FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d " 1684d5488eb9SRobert Love "head:%p data:%p tail:%p end:%p sum:%d dev:%s", 1685a703e490SVasu Dev skb->len, skb->data_len, 1686a703e490SVasu Dev skb->head, skb->data, skb_tail_pointer(skb), 1687a703e490SVasu Dev skb_end_pointer(skb), skb->csum, 1688a703e490SVasu Dev skb->dev ? skb->dev->name : "<NULL>"); 1689a703e490SVasu Dev 16901875f27eSRobert Love port = lport_priv(lport); 1691a703e490SVasu Dev if (skb_is_nonlinear(skb)) 1692a703e490SVasu Dev skb_linearize(skb); /* not ideal */ 1693a703e490SVasu Dev 1694a703e490SVasu Dev /* 1695a703e490SVasu Dev * Frame length checks and setting up the header pointers 1696a703e490SVasu Dev * was done in fcoe_rcv already. 1697a703e490SVasu Dev */ 1698a703e490SVasu Dev hp = (struct fcoe_hdr *) skb_network_header(skb); 1699a703e490SVasu Dev 1700f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1701a703e490SVasu Dev if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { 1702a703e490SVasu Dev if (stats->ErrorFrames < 5) 1703d5488eb9SRobert Love printk(KERN_WARNING "fcoe: FCoE version " 1704a703e490SVasu Dev "mismatch: The frame has " 1705a703e490SVasu Dev "version %x, but the " 1706a703e490SVasu Dev "initiator supports version " 1707a703e490SVasu Dev "%x\n", FC_FCOE_DECAPS_VER(hp), 1708a703e490SVasu Dev FC_FCOE_VER); 1709f018b73aSJoe Eykholt goto drop; 1710a703e490SVasu Dev } 1711a703e490SVasu Dev 1712a703e490SVasu Dev skb_pull(skb, sizeof(struct fcoe_hdr)); 1713a703e490SVasu Dev fr_len = skb->len - sizeof(struct fcoe_crc_eof); 1714a703e490SVasu Dev 1715a703e490SVasu Dev stats->RxFrames++; 1716a703e490SVasu Dev stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; 1717a703e490SVasu Dev 1718a703e490SVasu Dev fp = (struct fc_frame *)skb; 1719a703e490SVasu Dev fc_frame_init(fp); 17201875f27eSRobert Love fr_dev(fp) = lport; 1721a703e490SVasu Dev fr_sof(fp) = hp->fcoe_sof; 1722a703e490SVasu Dev 1723a703e490SVasu Dev /* Copy out the CRC and EOF trailer for access */ 1724f018b73aSJoe Eykholt if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) 1725f018b73aSJoe Eykholt goto drop; 1726a703e490SVasu Dev fr_eof(fp) = crc_eof.fcoe_eof; 1727a703e490SVasu Dev fr_crc(fp) = crc_eof.fcoe_crc32; 1728f018b73aSJoe Eykholt if (pskb_trim(skb, fr_len)) 1729f018b73aSJoe Eykholt goto drop; 1730a703e490SVasu Dev 173152ee8321SVasu Dev if (!fcoe_filter_frames(lport, fp)) { 1732f018b73aSJoe Eykholt put_cpu(); 17331875f27eSRobert Love fc_exch_recv(lport, fp); 1734f018b73aSJoe Eykholt return; 173552ee8321SVasu Dev } 1736f018b73aSJoe Eykholt drop: 1737f018b73aSJoe Eykholt stats->ErrorFrames++; 1738f018b73aSJoe Eykholt put_cpu(); 1739f018b73aSJoe Eykholt kfree_skb(skb); 1740a703e490SVasu Dev } 1741859b7b64SChris Leech 1742859b7b64SChris Leech /** 1743859b7b64SChris Leech * fcoe_percpu_receive_thread() - The per-CPU packet receive thread 1744859b7b64SChris Leech * @arg: The per-CPU context 1745859b7b64SChris Leech * 1746859b7b64SChris Leech * Return: 0 for success 1747859b7b64SChris Leech */ 1748859b7b64SChris Leech int fcoe_percpu_receive_thread(void *arg) 1749859b7b64SChris Leech { 1750859b7b64SChris Leech struct fcoe_percpu_s *p = arg; 1751859b7b64SChris Leech struct sk_buff *skb; 1752859b7b64SChris Leech 1753859b7b64SChris Leech set_user_nice(current, -20); 1754859b7b64SChris Leech 1755859b7b64SChris Leech while (!kthread_should_stop()) { 1756859b7b64SChris Leech 1757859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1758859b7b64SChris Leech while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) { 1759859b7b64SChris Leech set_current_state(TASK_INTERRUPTIBLE); 1760859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1761859b7b64SChris Leech schedule(); 1762859b7b64SChris Leech set_current_state(TASK_RUNNING); 1763859b7b64SChris Leech if (kthread_should_stop()) 1764859b7b64SChris Leech return 0; 1765859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1766859b7b64SChris Leech } 1767859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1768859b7b64SChris Leech fcoe_recv_frame(skb); 1769859b7b64SChris Leech } 1770a703e490SVasu Dev return 0; 1771a703e490SVasu Dev } 1772a703e490SVasu Dev 1773a703e490SVasu Dev /** 17741875f27eSRobert Love * fcoe_check_wait_queue() - Attempt to clear the transmit backlog 17751875f27eSRobert Love * @lport: The local port whose backlog is to be cleared 1776a703e490SVasu Dev * 17771875f27eSRobert Love * This empties the wait_queue, dequeues the head of the wait_queue queue 17781875f27eSRobert Love * and calls fcoe_start_io() for each packet. If all skb have been 17791875f27eSRobert Love * transmitted it returns the qlen. If an error occurs it restores 17801875f27eSRobert Love * wait_queue (to try again later) and returns -1. 1781a703e490SVasu Dev * 17821875f27eSRobert Love * The wait_queue is used when the skb transmit fails. The failed skb 17831875f27eSRobert Love * will go in the wait_queue which will be emptied by the timer function or 1784a703e490SVasu Dev * by the next skb transmit. 1785a703e490SVasu Dev */ 17861875f27eSRobert Love static void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb) 1787a703e490SVasu Dev { 17881875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 17894bb6b515SVasu Dev int rc; 1790a703e490SVasu Dev 1791014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 17924bb6b515SVasu Dev 17934bb6b515SVasu Dev if (skb) 1794014f5c3fSChris Leech __skb_queue_tail(&port->fcoe_pending_queue, skb); 17954bb6b515SVasu Dev 1796014f5c3fSChris Leech if (port->fcoe_pending_queue_active) 1797a703e490SVasu Dev goto out; 1798014f5c3fSChris Leech port->fcoe_pending_queue_active = 1; 1799a703e490SVasu Dev 1800014f5c3fSChris Leech while (port->fcoe_pending_queue.qlen) { 1801a703e490SVasu Dev /* keep qlen > 0 until fcoe_start_io succeeds */ 1802014f5c3fSChris Leech port->fcoe_pending_queue.qlen++; 1803014f5c3fSChris Leech skb = __skb_dequeue(&port->fcoe_pending_queue); 1804a703e490SVasu Dev 1805014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 1806a703e490SVasu Dev rc = fcoe_start_io(skb); 1807014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 1808a703e490SVasu Dev 1809a703e490SVasu Dev if (rc) { 1810014f5c3fSChris Leech __skb_queue_head(&port->fcoe_pending_queue, skb); 1811a703e490SVasu Dev /* undo temporary increment above */ 1812014f5c3fSChris Leech port->fcoe_pending_queue.qlen--; 1813a703e490SVasu Dev break; 1814a703e490SVasu Dev } 1815a703e490SVasu Dev /* undo temporary increment above */ 1816014f5c3fSChris Leech port->fcoe_pending_queue.qlen--; 1817a703e490SVasu Dev } 1818a703e490SVasu Dev 1819014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH) 18201875f27eSRobert Love lport->qfull = 0; 1821014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer)) 1822014f5c3fSChris Leech mod_timer(&port->timer, jiffies + 2); 1823014f5c3fSChris Leech port->fcoe_pending_queue_active = 0; 1824a703e490SVasu Dev out: 1825014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH) 18261875f27eSRobert Love lport->qfull = 1; 1827014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 18284bb6b515SVasu Dev return; 1829a703e490SVasu Dev } 1830a703e490SVasu Dev 1831a703e490SVasu Dev /** 18321875f27eSRobert Love * fcoe_dev_setup() - Setup the link change notification interface 1833a703e490SVasu Dev */ 1834b0d428adSRandy Dunlap static void fcoe_dev_setup(void) 1835a703e490SVasu Dev { 1836a703e490SVasu Dev register_netdevice_notifier(&fcoe_notifier); 1837a703e490SVasu Dev } 1838a703e490SVasu Dev 1839a703e490SVasu Dev /** 18401875f27eSRobert Love * fcoe_dev_cleanup() - Cleanup the link change notification interface 1841a703e490SVasu Dev */ 1842a703e490SVasu Dev static void fcoe_dev_cleanup(void) 1843a703e490SVasu Dev { 1844a703e490SVasu Dev unregister_netdevice_notifier(&fcoe_notifier); 1845a703e490SVasu Dev } 1846a703e490SVasu Dev 1847a703e490SVasu Dev /** 18481875f27eSRobert Love * fcoe_device_notification() - Handler for net device events 18491875f27eSRobert Love * @notifier: The context of the notification 18501875f27eSRobert Love * @event: The type of event 18511875f27eSRobert Love * @ptr: The net device that the event was on 1852a703e490SVasu Dev * 18531875f27eSRobert Love * This function is called by the Ethernet driver in case of link change event. 1854a703e490SVasu Dev * 1855a703e490SVasu Dev * Returns: 0 for success 1856a703e490SVasu Dev */ 1857a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *notifier, 1858a703e490SVasu Dev ulong event, void *ptr) 1859a703e490SVasu Dev { 18601875f27eSRobert Love struct fc_lport *lport = NULL; 18611d1b88dcSVasu Dev struct net_device *netdev = ptr; 1862014f5c3fSChris Leech struct fcoe_interface *fcoe; 18632e70e241SChris Leech struct fcoe_port *port; 1864a703e490SVasu Dev struct fcoe_dev_stats *stats; 186597c8389dSJoe Eykholt u32 link_possible = 1; 1866a703e490SVasu Dev u32 mfs; 1867a703e490SVasu Dev int rc = NOTIFY_OK; 1868a703e490SVasu Dev 1869014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 187025024989SChris Leech if (fcoe->netdev == netdev) { 18711875f27eSRobert Love lport = fcoe->ctlr.lp; 1872a703e490SVasu Dev break; 1873a703e490SVasu Dev } 1874a703e490SVasu Dev } 18751875f27eSRobert Love if (!lport) { 1876a703e490SVasu Dev rc = NOTIFY_DONE; 1877a703e490SVasu Dev goto out; 1878a703e490SVasu Dev } 1879a703e490SVasu Dev 1880a703e490SVasu Dev switch (event) { 1881a703e490SVasu Dev case NETDEV_DOWN: 1882a703e490SVasu Dev case NETDEV_GOING_DOWN: 188397c8389dSJoe Eykholt link_possible = 0; 1884a703e490SVasu Dev break; 1885a703e490SVasu Dev case NETDEV_UP: 1886a703e490SVasu Dev case NETDEV_CHANGE: 1887a703e490SVasu Dev break; 1888a703e490SVasu Dev case NETDEV_CHANGEMTU: 18897221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) 18907221d7e5SYi Zou break; 18911d1b88dcSVasu Dev mfs = netdev->mtu - (sizeof(struct fcoe_hdr) + 1892a703e490SVasu Dev sizeof(struct fcoe_crc_eof)); 1893a703e490SVasu Dev if (mfs >= FC_MIN_MAX_FRAME) 18941875f27eSRobert Love fc_set_mfs(lport, mfs); 1895a703e490SVasu Dev break; 1896a703e490SVasu Dev case NETDEV_REGISTER: 1897a703e490SVasu Dev break; 18982e70e241SChris Leech case NETDEV_UNREGISTER: 18992e70e241SChris Leech list_del(&fcoe->list); 19002e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 19012e70e241SChris Leech fcoe_interface_cleanup(fcoe); 19022ca32b48STejun Heo queue_work(fcoe_wq, &port->destroy_work); 19032e70e241SChris Leech goto out; 19042e70e241SChris Leech break; 190554a5b21dSYi Zou case NETDEV_FEAT_CHANGE: 190654a5b21dSYi Zou fcoe_netdev_features_change(lport, netdev); 190754a5b21dSYi Zou break; 1908a703e490SVasu Dev default: 19091d1b88dcSVasu Dev FCOE_NETDEV_DBG(netdev, "Unknown event %ld " 1910d5488eb9SRobert Love "from netdev netlink\n", event); 1911a703e490SVasu Dev } 19125e4f8fe7SRobert Love 19135e4f8fe7SRobert Love fcoe_link_speed_update(lport); 19145e4f8fe7SRobert Love 19151875f27eSRobert Love if (link_possible && !fcoe_link_ok(lport)) 19163fe9a0baSChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 19173fe9a0baSChris Leech else if (fcoe_ctlr_link_down(&fcoe->ctlr)) { 1918f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1919a703e490SVasu Dev stats->LinkFailureCount++; 1920f018b73aSJoe Eykholt put_cpu(); 19211875f27eSRobert Love fcoe_clean_pending_queue(lport); 1922a703e490SVasu Dev } 1923a703e490SVasu Dev out: 1924a703e490SVasu Dev return rc; 1925a703e490SVasu Dev } 1926a703e490SVasu Dev 1927a703e490SVasu Dev /** 192855a66d3cSVasu Dev * fcoe_disable() - Disables a FCoE interface 192978a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 193055a66d3cSVasu Dev * 193178a58246SYi Zou * Called from fcoe transport. 193255a66d3cSVasu Dev * 193355a66d3cSVasu Dev * Returns: 0 for success 193455a66d3cSVasu Dev */ 193578a58246SYi Zou static int fcoe_disable(struct net_device *netdev) 193655a66d3cSVasu Dev { 193755a66d3cSVasu Dev struct fcoe_interface *fcoe; 193855a66d3cSVasu Dev int rc = 0; 193955a66d3cSVasu Dev 194055a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 194155a66d3cSVasu Dev #ifdef CONFIG_FCOE_MODULE 194255a66d3cSVasu Dev /* 194355a66d3cSVasu Dev * Make sure the module has been initialized, and is not about to be 194455a66d3cSVasu Dev * removed. Module paramter sysfs files are writable before the 194555a66d3cSVasu Dev * module_init function is called and after module_exit. 194655a66d3cSVasu Dev */ 194755a66d3cSVasu Dev if (THIS_MODULE->state != MODULE_STATE_LIVE) { 194855a66d3cSVasu Dev rc = -ENODEV; 194955a66d3cSVasu Dev goto out_nodev; 195055a66d3cSVasu Dev } 195155a66d3cSVasu Dev #endif 195255a66d3cSVasu Dev 195334ce27bcSVasu Dev if (!rtnl_trylock()) { 195434ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 195578a58246SYi Zou return -ERESTARTSYS; 195634ce27bcSVasu Dev } 195734ce27bcSVasu Dev 195855a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 195955a66d3cSVasu Dev rtnl_unlock(); 196055a66d3cSVasu Dev 19619ee50e48SChris Leech if (fcoe) { 19629ee50e48SChris Leech fcoe_ctlr_link_down(&fcoe->ctlr); 19639d4cbc05SVasu Dev fcoe_clean_pending_queue(fcoe->ctlr.lp); 19649ee50e48SChris Leech } else 196555a66d3cSVasu Dev rc = -ENODEV; 196655a66d3cSVasu Dev 196755a66d3cSVasu Dev out_nodev: 196855a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 196955a66d3cSVasu Dev return rc; 197055a66d3cSVasu Dev } 197155a66d3cSVasu Dev 197255a66d3cSVasu Dev /** 197355a66d3cSVasu Dev * fcoe_enable() - Enables a FCoE interface 197478a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 197555a66d3cSVasu Dev * 197678a58246SYi Zou * Called from fcoe transport. 197755a66d3cSVasu Dev * 197855a66d3cSVasu Dev * Returns: 0 for success 197955a66d3cSVasu Dev */ 198078a58246SYi Zou static int fcoe_enable(struct net_device *netdev) 198155a66d3cSVasu Dev { 198255a66d3cSVasu Dev struct fcoe_interface *fcoe; 198355a66d3cSVasu Dev int rc = 0; 198455a66d3cSVasu Dev 198555a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 198655a66d3cSVasu Dev #ifdef CONFIG_FCOE_MODULE 198755a66d3cSVasu Dev /* 198855a66d3cSVasu Dev * Make sure the module has been initialized, and is not about to be 198955a66d3cSVasu Dev * removed. Module paramter sysfs files are writable before the 199055a66d3cSVasu Dev * module_init function is called and after module_exit. 199155a66d3cSVasu Dev */ 199255a66d3cSVasu Dev if (THIS_MODULE->state != MODULE_STATE_LIVE) { 199355a66d3cSVasu Dev rc = -ENODEV; 199455a66d3cSVasu Dev goto out_nodev; 199555a66d3cSVasu Dev } 199655a66d3cSVasu Dev #endif 199734ce27bcSVasu Dev if (!rtnl_trylock()) { 199834ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 199978a58246SYi Zou return -ERESTARTSYS; 200034ce27bcSVasu Dev } 200134ce27bcSVasu Dev 200255a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 200355a66d3cSVasu Dev rtnl_unlock(); 200455a66d3cSVasu Dev 20059d4cbc05SVasu Dev if (!fcoe) 200655a66d3cSVasu Dev rc = -ENODEV; 20079d4cbc05SVasu Dev else if (!fcoe_link_ok(fcoe->ctlr.lp)) 20089d4cbc05SVasu Dev fcoe_ctlr_link_up(&fcoe->ctlr); 200955a66d3cSVasu Dev 201055a66d3cSVasu Dev out_nodev: 201155a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 201255a66d3cSVasu Dev return rc; 201355a66d3cSVasu Dev } 201455a66d3cSVasu Dev 201555a66d3cSVasu Dev /** 20161875f27eSRobert Love * fcoe_destroy() - Destroy a FCoE interface 201778a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 20181875f27eSRobert Love * 201978a58246SYi Zou * Called from fcoe transport 2020a703e490SVasu Dev * 2021a703e490SVasu Dev * Returns: 0 for success 2022a703e490SVasu Dev */ 202378a58246SYi Zou static int fcoe_destroy(struct net_device *netdev) 2024a703e490SVasu Dev { 2025030f4e00SChris Leech struct fcoe_interface *fcoe; 20268eca355fSMike Christie int rc = 0; 2027a703e490SVasu Dev 2028dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2029dfc1d0feSChris Leech #ifdef CONFIG_FCOE_MODULE 2030dfc1d0feSChris Leech /* 2031dfc1d0feSChris Leech * Make sure the module has been initialized, and is not about to be 2032dfc1d0feSChris Leech * removed. Module paramter sysfs files are writable before the 2033dfc1d0feSChris Leech * module_init function is called and after module_exit. 2034dfc1d0feSChris Leech */ 2035dfc1d0feSChris Leech if (THIS_MODULE->state != MODULE_STATE_LIVE) { 2036dfc1d0feSChris Leech rc = -ENODEV; 2037dfc1d0feSChris Leech goto out_nodev; 2038dfc1d0feSChris Leech } 2039dfc1d0feSChris Leech #endif 204034ce27bcSVasu Dev if (!rtnl_trylock()) { 204134ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 204278a58246SYi Zou return -ERESTARTSYS; 204334ce27bcSVasu Dev } 204434ce27bcSVasu Dev 20452e70e241SChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 20462e70e241SChris Leech if (!fcoe) { 2047090eb6c4SChris Leech rtnl_unlock(); 2048a703e490SVasu Dev rc = -ENODEV; 204978a58246SYi Zou goto out_nodev; 2050a703e490SVasu Dev } 20512e70e241SChris Leech fcoe_interface_cleanup(fcoe); 205254a5b21dSYi Zou list_del(&fcoe->list); 205334ce27bcSVasu Dev /* RTNL mutex is dropped by fcoe_if_destroy */ 20542e70e241SChris Leech fcoe_if_destroy(fcoe->ctlr.lp); 2055a703e490SVasu Dev out_nodev: 2056dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2057a703e490SVasu Dev return rc; 2058a703e490SVasu Dev } 2059a703e490SVasu Dev 20601875f27eSRobert Love /** 20611875f27eSRobert Love * fcoe_destroy_work() - Destroy a FCoE port in a deferred work context 20621875f27eSRobert Love * @work: Handle to the FCoE port to be destroyed 20631875f27eSRobert Love */ 20642e70e241SChris Leech static void fcoe_destroy_work(struct work_struct *work) 20652e70e241SChris Leech { 20662e70e241SChris Leech struct fcoe_port *port; 20672e70e241SChris Leech 20682e70e241SChris Leech port = container_of(work, struct fcoe_port, destroy_work); 20692e70e241SChris Leech mutex_lock(&fcoe_config_mutex); 207034ce27bcSVasu Dev rtnl_lock(); 207134ce27bcSVasu Dev /* RTNL mutex is dropped by fcoe_if_destroy */ 20722e70e241SChris Leech fcoe_if_destroy(port->lport); 20732e70e241SChris Leech mutex_unlock(&fcoe_config_mutex); 20742e70e241SChris Leech } 20752e70e241SChris Leech 2076a703e490SVasu Dev /** 207778a58246SYi Zou * fcoe_match() - Check if the FCoE is supported on the given netdevice 207878a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 20791875f27eSRobert Love * 208078a58246SYi Zou * Called from fcoe transport. 208178a58246SYi Zou * 208278a58246SYi Zou * Returns: always returns true as this is the default FCoE transport, 208378a58246SYi Zou * i.e., support all netdevs. 208478a58246SYi Zou */ 208578a58246SYi Zou static bool fcoe_match(struct net_device *netdev) 208678a58246SYi Zou { 208778a58246SYi Zou return true; 208878a58246SYi Zou } 208978a58246SYi Zou 209078a58246SYi Zou /** 209178a58246SYi Zou * fcoe_create() - Create a fcoe interface 209278a58246SYi Zou * @netdev : The net_device object the Ethernet interface to create on 209378a58246SYi Zou * @fip_mode: The FIP mode for this creation 209478a58246SYi Zou * 209578a58246SYi Zou * Called from fcoe transport 2096a703e490SVasu Dev * 2097a703e490SVasu Dev * Returns: 0 for success 2098a703e490SVasu Dev */ 209978a58246SYi Zou static int fcoe_create(struct net_device *netdev, enum fip_state fip_mode) 2100a703e490SVasu Dev { 2101a703e490SVasu Dev int rc; 2102030f4e00SChris Leech struct fcoe_interface *fcoe; 2103af7f85d9SChris Leech struct fc_lport *lport; 2104a703e490SVasu Dev 2105dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 210634ce27bcSVasu Dev 210734ce27bcSVasu Dev if (!rtnl_trylock()) { 210834ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 210978a58246SYi Zou return -ERESTARTSYS; 211034ce27bcSVasu Dev } 211134ce27bcSVasu Dev 2112dfc1d0feSChris Leech #ifdef CONFIG_FCOE_MODULE 2113dfc1d0feSChris Leech /* 2114dfc1d0feSChris Leech * Make sure the module has been initialized, and is not about to be 2115dfc1d0feSChris Leech * removed. Module paramter sysfs files are writable before the 2116dfc1d0feSChris Leech * module_init function is called and after module_exit. 2117dfc1d0feSChris Leech */ 2118dfc1d0feSChris Leech if (THIS_MODULE->state != MODULE_STATE_LIVE) { 2119dfc1d0feSChris Leech rc = -ENODEV; 21207287fb91SRobert Love goto out_nodev; 2121dfc1d0feSChris Leech } 2122dfc1d0feSChris Leech #endif 2123dfc1d0feSChris Leech 2124a703e490SVasu Dev /* look for existing lport */ 2125a703e490SVasu Dev if (fcoe_hostlist_lookup(netdev)) { 2126a703e490SVasu Dev rc = -EEXIST; 212778a58246SYi Zou goto out_nodev; 2128a703e490SVasu Dev } 2129a703e490SVasu Dev 21301dd454d9SJoe Eykholt fcoe = fcoe_interface_create(netdev, fip_mode); 21317287fb91SRobert Love if (IS_ERR(fcoe)) { 21327287fb91SRobert Love rc = PTR_ERR(fcoe); 213378a58246SYi Zou goto out_nodev; 2134030f4e00SChris Leech } 2135030f4e00SChris Leech 21369a05753bSChris Leech lport = fcoe_if_create(fcoe, &netdev->dev, 0); 2137af7f85d9SChris Leech if (IS_ERR(lport)) { 2138d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to create interface (%s)\n", 2139a703e490SVasu Dev netdev->name); 2140a703e490SVasu Dev rc = -EIO; 21412e70e241SChris Leech fcoe_interface_cleanup(fcoe); 2142030f4e00SChris Leech goto out_free; 2143a703e490SVasu Dev } 2144030f4e00SChris Leech 214554b649f8SChris Leech /* Make this the "master" N_Port */ 214654b649f8SChris Leech fcoe->ctlr.lp = lport; 2147030f4e00SChris Leech 2148c863df33SChris Leech /* add to lports list */ 2149c863df33SChris Leech fcoe_hostlist_add(lport); 2150c863df33SChris Leech 215154b649f8SChris Leech /* start FIP Discovery and FLOGI */ 215254b649f8SChris Leech lport->boot_time = jiffies; 215354b649f8SChris Leech fc_fabric_login(lport); 215454b649f8SChris Leech if (!fcoe_link_ok(lport)) 215554b649f8SChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 215654b649f8SChris Leech 215754b649f8SChris Leech /* 215854b649f8SChris Leech * Release from init in fcoe_interface_create(), on success lport 215954b649f8SChris Leech * should be holding a reference taken in fcoe_if_create(). 216054b649f8SChris Leech */ 2161030f4e00SChris Leech fcoe_interface_put(fcoe); 21626409ea65SRob Love rtnl_unlock(); 21636409ea65SRob Love mutex_unlock(&fcoe_config_mutex); 21646409ea65SRob Love 21656409ea65SRob Love return 0; 21666409ea65SRob Love out_free: 21676409ea65SRob Love fcoe_interface_put(fcoe); 2168a703e490SVasu Dev out_nodev: 216934ce27bcSVasu Dev rtnl_unlock(); 2170dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2171a703e490SVasu Dev return rc; 2172a703e490SVasu Dev } 2173a703e490SVasu Dev 2174a703e490SVasu Dev /** 21755e4f8fe7SRobert Love * fcoe_link_speed_update() - Update the supported and actual link speeds 21765e4f8fe7SRobert Love * @lport: The local port to update speeds for 2177a703e490SVasu Dev * 21785e4f8fe7SRobert Love * Returns: 0 if the ethtool query was successful 21795e4f8fe7SRobert Love * -1 if the ethtool query failed 2180a703e490SVasu Dev */ 21815e4f8fe7SRobert Love int fcoe_link_speed_update(struct fc_lport *lport) 2182a703e490SVasu Dev { 21831875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 21841875f27eSRobert Love struct net_device *netdev = port->fcoe->netdev; 2185a703e490SVasu Dev struct ethtool_cmd ecmd = { ETHTOOL_GSET }; 2186a703e490SVasu Dev 21875e4f8fe7SRobert Love if (!dev_ethtool_get_settings(netdev, &ecmd)) { 21881875f27eSRobert Love lport->link_supported_speeds &= 2189a703e490SVasu Dev ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT); 2190a703e490SVasu Dev if (ecmd.supported & (SUPPORTED_1000baseT_Half | 2191a703e490SVasu Dev SUPPORTED_1000baseT_Full)) 21921875f27eSRobert Love lport->link_supported_speeds |= FC_PORTSPEED_1GBIT; 2193a703e490SVasu Dev if (ecmd.supported & SUPPORTED_10000baseT_Full) 21941875f27eSRobert Love lport->link_supported_speeds |= 2195a703e490SVasu Dev FC_PORTSPEED_10GBIT; 2196a703e490SVasu Dev if (ecmd.speed == SPEED_1000) 21971875f27eSRobert Love lport->link_speed = FC_PORTSPEED_1GBIT; 2198a703e490SVasu Dev if (ecmd.speed == SPEED_10000) 21991875f27eSRobert Love lport->link_speed = FC_PORTSPEED_10GBIT; 2200a703e490SVasu Dev 22012f718d64SYi Zou return 0; 22022f718d64SYi Zou } 22032f718d64SYi Zou return -1; 2204a703e490SVasu Dev } 2205a703e490SVasu Dev 2206a703e490SVasu Dev /** 22075e4f8fe7SRobert Love * fcoe_link_ok() - Check if the link is OK for a local port 22085e4f8fe7SRobert Love * @lport: The local port to check link on 22095e4f8fe7SRobert Love * 22105e4f8fe7SRobert Love * Returns: 0 if link is UP and OK, -1 if not 22115e4f8fe7SRobert Love * 22125e4f8fe7SRobert Love */ 22135e4f8fe7SRobert Love int fcoe_link_ok(struct fc_lport *lport) 22145e4f8fe7SRobert Love { 22155e4f8fe7SRobert Love struct fcoe_port *port = lport_priv(lport); 22165e4f8fe7SRobert Love struct net_device *netdev = port->fcoe->netdev; 22175e4f8fe7SRobert Love 22185e4f8fe7SRobert Love if (netif_oper_up(netdev)) 22195e4f8fe7SRobert Love return 0; 22205e4f8fe7SRobert Love return -1; 22215e4f8fe7SRobert Love } 22225e4f8fe7SRobert Love 22235e4f8fe7SRobert Love /** 22241875f27eSRobert Love * fcoe_percpu_clean() - Clear all pending skbs for an local port 22251875f27eSRobert Love * @lport: The local port whose skbs are to be cleared 2226e7a51997SJoe Eykholt * 2227e7a51997SJoe Eykholt * Must be called with fcoe_create_mutex held to single-thread completion. 2228e7a51997SJoe Eykholt * 2229e7a51997SJoe Eykholt * This flushes the pending skbs by adding a new skb to each queue and 2230e7a51997SJoe Eykholt * waiting until they are all freed. This assures us that not only are 2231e7a51997SJoe Eykholt * there no packets that will be handled by the lport, but also that any 2232e7a51997SJoe Eykholt * threads already handling packet have returned. 2233a703e490SVasu Dev */ 22341875f27eSRobert Love void fcoe_percpu_clean(struct fc_lport *lport) 2235a703e490SVasu Dev { 2236a703e490SVasu Dev struct fcoe_percpu_s *pp; 2237a703e490SVasu Dev struct fcoe_rcv_info *fr; 2238a703e490SVasu Dev struct sk_buff_head *list; 2239a703e490SVasu Dev struct sk_buff *skb, *next; 2240a703e490SVasu Dev struct sk_buff *head; 2241a703e490SVasu Dev unsigned int cpu; 2242a703e490SVasu Dev 2243a703e490SVasu Dev for_each_possible_cpu(cpu) { 2244a703e490SVasu Dev pp = &per_cpu(fcoe_percpu, cpu); 2245a703e490SVasu Dev spin_lock_bh(&pp->fcoe_rx_list.lock); 2246a703e490SVasu Dev list = &pp->fcoe_rx_list; 2247a703e490SVasu Dev head = list->next; 2248a703e490SVasu Dev for (skb = head; skb != (struct sk_buff *)list; 2249a703e490SVasu Dev skb = next) { 2250a703e490SVasu Dev next = skb->next; 2251a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 22521875f27eSRobert Love if (fr->fr_dev == lport) { 2253a703e490SVasu Dev __skb_unlink(skb, list); 2254a703e490SVasu Dev kfree_skb(skb); 2255a703e490SVasu Dev } 2256a703e490SVasu Dev } 2257e7a51997SJoe Eykholt 2258e7a51997SJoe Eykholt if (!pp->thread || !cpu_online(cpu)) { 2259a703e490SVasu Dev spin_unlock_bh(&pp->fcoe_rx_list.lock); 2260e7a51997SJoe Eykholt continue; 2261e7a51997SJoe Eykholt } 2262e7a51997SJoe Eykholt 2263e7a51997SJoe Eykholt skb = dev_alloc_skb(0); 2264e7a51997SJoe Eykholt if (!skb) { 2265e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2266e7a51997SJoe Eykholt continue; 2267e7a51997SJoe Eykholt } 2268e7a51997SJoe Eykholt skb->destructor = fcoe_percpu_flush_done; 2269e7a51997SJoe Eykholt 2270e7a51997SJoe Eykholt __skb_queue_tail(&pp->fcoe_rx_list, skb); 2271e7a51997SJoe Eykholt if (pp->fcoe_rx_list.qlen == 1) 2272e7a51997SJoe Eykholt wake_up_process(pp->thread); 2273e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2274e7a51997SJoe Eykholt 2275e7a51997SJoe Eykholt wait_for_completion(&fcoe_flush_completion); 2276a703e490SVasu Dev } 2277a703e490SVasu Dev } 2278a703e490SVasu Dev 2279a703e490SVasu Dev /** 2280a703e490SVasu Dev * fcoe_clean_pending_queue() - Dequeue a skb and free it 22811875f27eSRobert Love * @lport: The local port to dequeue a skb on 2282a703e490SVasu Dev */ 22831875f27eSRobert Love void fcoe_clean_pending_queue(struct fc_lport *lport) 2284a703e490SVasu Dev { 22851875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 2286a703e490SVasu Dev struct sk_buff *skb; 2287a703e490SVasu Dev 2288014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 2289014f5c3fSChris Leech while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) { 2290014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 2291a703e490SVasu Dev kfree_skb(skb); 2292014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 2293a703e490SVasu Dev } 2294014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 2295a703e490SVasu Dev } 2296a703e490SVasu Dev 2297a703e490SVasu Dev /** 22981875f27eSRobert Love * fcoe_reset() - Reset a local port 22991875f27eSRobert Love * @shost: The SCSI host associated with the local port to be reset 2300a703e490SVasu Dev * 23011875f27eSRobert Love * Returns: Always 0 (return value required by FC transport template) 2302a703e490SVasu Dev */ 2303a703e490SVasu Dev int fcoe_reset(struct Scsi_Host *shost) 2304a703e490SVasu Dev { 2305a703e490SVasu Dev struct fc_lport *lport = shost_priv(shost); 2306a703e490SVasu Dev fc_lport_reset(lport); 2307a703e490SVasu Dev return 0; 2308a703e490SVasu Dev } 2309a703e490SVasu Dev 2310a703e490SVasu Dev /** 23111875f27eSRobert Love * fcoe_hostlist_lookup_port() - Find the FCoE interface associated with a net device 23121875f27eSRobert Love * @netdev: The net device used as a key 2313a703e490SVasu Dev * 23141875f27eSRobert Love * Locking: Must be called with the RNL mutex held. 23151875f27eSRobert Love * 23161875f27eSRobert Love * Returns: NULL or the FCoE interface 2317a703e490SVasu Dev */ 2318014f5c3fSChris Leech static struct fcoe_interface * 23191875f27eSRobert Love fcoe_hostlist_lookup_port(const struct net_device *netdev) 2320a703e490SVasu Dev { 2321014f5c3fSChris Leech struct fcoe_interface *fcoe; 2322a703e490SVasu Dev 2323014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 23241875f27eSRobert Love if (fcoe->netdev == netdev) 2325014f5c3fSChris Leech return fcoe; 2326a703e490SVasu Dev } 2327a703e490SVasu Dev return NULL; 2328a703e490SVasu Dev } 2329a703e490SVasu Dev 2330a703e490SVasu Dev /** 23311875f27eSRobert Love * fcoe_hostlist_lookup() - Find the local port associated with a 23321875f27eSRobert Love * given net device 23331875f27eSRobert Love * @netdev: The netdevice used as a key 2334a703e490SVasu Dev * 23351875f27eSRobert Love * Locking: Must be called with the RTNL mutex held 23361875f27eSRobert Love * 23371875f27eSRobert Love * Returns: NULL or the local port 2338a703e490SVasu Dev */ 2339090eb6c4SChris Leech static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev) 2340a703e490SVasu Dev { 2341014f5c3fSChris Leech struct fcoe_interface *fcoe; 2342a703e490SVasu Dev 2343014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 23443fe9a0baSChris Leech return (fcoe) ? fcoe->ctlr.lp : NULL; 2345a703e490SVasu Dev } 2346a703e490SVasu Dev 2347a703e490SVasu Dev /** 23481875f27eSRobert Love * fcoe_hostlist_add() - Add the FCoE interface identified by a local 23491875f27eSRobert Love * port to the hostlist 23501875f27eSRobert Love * @lport: The local port that identifies the FCoE interface to be added 23511875f27eSRobert Love * 23521875f27eSRobert Love * Locking: must be called with the RTNL mutex held 2353a703e490SVasu Dev * 2354a703e490SVasu Dev * Returns: 0 for success 2355a703e490SVasu Dev */ 2356090eb6c4SChris Leech static int fcoe_hostlist_add(const struct fc_lport *lport) 2357a703e490SVasu Dev { 2358014f5c3fSChris Leech struct fcoe_interface *fcoe; 2359014f5c3fSChris Leech struct fcoe_port *port; 2360a703e490SVasu Dev 2361014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport)); 2362014f5c3fSChris Leech if (!fcoe) { 2363014f5c3fSChris Leech port = lport_priv(lport); 2364014f5c3fSChris Leech fcoe = port->fcoe; 2365014f5c3fSChris Leech list_add_tail(&fcoe->list, &fcoe_hostlist); 2366a703e490SVasu Dev } 2367a703e490SVasu Dev return 0; 2368a703e490SVasu Dev } 2369a703e490SVasu Dev 237078a58246SYi Zou 237178a58246SYi Zou static struct fcoe_transport fcoe_sw_transport = { 237278a58246SYi Zou .name = {FCOE_TRANSPORT_DEFAULT}, 237378a58246SYi Zou .attached = false, 237478a58246SYi Zou .list = LIST_HEAD_INIT(fcoe_sw_transport.list), 237578a58246SYi Zou .match = fcoe_match, 237678a58246SYi Zou .create = fcoe_create, 237778a58246SYi Zou .destroy = fcoe_destroy, 237878a58246SYi Zou .enable = fcoe_enable, 237978a58246SYi Zou .disable = fcoe_disable, 238078a58246SYi Zou }; 238178a58246SYi Zou 2382a703e490SVasu Dev /** 23831875f27eSRobert Love * fcoe_init() - Initialize fcoe.ko 2384a703e490SVasu Dev * 23851875f27eSRobert Love * Returns: 0 on success, or a negative value on failure 2386a703e490SVasu Dev */ 2387a703e490SVasu Dev static int __init fcoe_init(void) 2388a703e490SVasu Dev { 23891875f27eSRobert Love struct fcoe_percpu_s *p; 2390a703e490SVasu Dev unsigned int cpu; 2391a703e490SVasu Dev int rc = 0; 2392a703e490SVasu Dev 23932ca32b48STejun Heo fcoe_wq = alloc_workqueue("fcoe", 0, 0); 23942ca32b48STejun Heo if (!fcoe_wq) 23952ca32b48STejun Heo return -ENOMEM; 23962ca32b48STejun Heo 239778a58246SYi Zou /* register as a fcoe transport */ 239878a58246SYi Zou rc = fcoe_transport_attach(&fcoe_sw_transport); 239978a58246SYi Zou if (rc) { 240078a58246SYi Zou printk(KERN_ERR "failed to register an fcoe transport, check " 240178a58246SYi Zou "if libfcoe is loaded\n"); 240278a58246SYi Zou return rc; 240378a58246SYi Zou } 240478a58246SYi Zou 2405dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2406dfc1d0feSChris Leech 2407a703e490SVasu Dev for_each_possible_cpu(cpu) { 2408a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 2409a703e490SVasu Dev skb_queue_head_init(&p->fcoe_rx_list); 2410a703e490SVasu Dev } 2411a703e490SVasu Dev 2412a703e490SVasu Dev for_each_online_cpu(cpu) 2413a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 2414a703e490SVasu Dev 2415a703e490SVasu Dev /* Initialize per CPU interrupt thread */ 2416a703e490SVasu Dev rc = register_hotcpu_notifier(&fcoe_cpu_notifier); 2417a703e490SVasu Dev if (rc) 2418a703e490SVasu Dev goto out_free; 2419a703e490SVasu Dev 2420a703e490SVasu Dev /* Setup link change notification */ 2421a703e490SVasu Dev fcoe_dev_setup(); 2422a703e490SVasu Dev 24235892c32fSChris Leech rc = fcoe_if_init(); 24245892c32fSChris Leech if (rc) 24255892c32fSChris Leech goto out_free; 2426a703e490SVasu Dev 2427dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2428a703e490SVasu Dev return 0; 2429a703e490SVasu Dev 2430a703e490SVasu Dev out_free: 2431a703e490SVasu Dev for_each_online_cpu(cpu) { 2432a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2433a703e490SVasu Dev } 2434dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 24352ca32b48STejun Heo destroy_workqueue(fcoe_wq); 2436a703e490SVasu Dev return rc; 2437a703e490SVasu Dev } 2438a703e490SVasu Dev module_init(fcoe_init); 2439a703e490SVasu Dev 2440a703e490SVasu Dev /** 24411875f27eSRobert Love * fcoe_exit() - Clean up fcoe.ko 2442a703e490SVasu Dev * 24431875f27eSRobert Love * Returns: 0 on success or a negative value on failure 2444a703e490SVasu Dev */ 2445a703e490SVasu Dev static void __exit fcoe_exit(void) 2446a703e490SVasu Dev { 2447014f5c3fSChris Leech struct fcoe_interface *fcoe, *tmp; 24482e70e241SChris Leech struct fcoe_port *port; 24491875f27eSRobert Love unsigned int cpu; 2450a703e490SVasu Dev 2451dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2452dfc1d0feSChris Leech 2453a703e490SVasu Dev fcoe_dev_cleanup(); 2454a703e490SVasu Dev 2455a703e490SVasu Dev /* releases the associated fcoe hosts */ 2456090eb6c4SChris Leech rtnl_lock(); 2457090eb6c4SChris Leech list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) { 2458c863df33SChris Leech list_del(&fcoe->list); 24592e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 24602e70e241SChris Leech fcoe_interface_cleanup(fcoe); 24612ca32b48STejun Heo queue_work(fcoe_wq, &port->destroy_work); 2462c863df33SChris Leech } 2463090eb6c4SChris Leech rtnl_unlock(); 2464a703e490SVasu Dev 2465a703e490SVasu Dev unregister_hotcpu_notifier(&fcoe_cpu_notifier); 2466a703e490SVasu Dev 2467014f5c3fSChris Leech for_each_online_cpu(cpu) 2468a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2469a703e490SVasu Dev 2470dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 24712e70e241SChris Leech 24722ca32b48STejun Heo /* 24732ca32b48STejun Heo * destroy_work's may be chained but destroy_workqueue() 24742ca32b48STejun Heo * can take care of them. Just kill the fcoe_wq. 24752ca32b48STejun Heo */ 24762ca32b48STejun Heo destroy_workqueue(fcoe_wq); 24772e70e241SChris Leech 24782ca32b48STejun Heo /* 24792ca32b48STejun Heo * Detaching from the scsi transport must happen after all 24802ca32b48STejun Heo * destroys are done on the fcoe_wq. destroy_workqueue will 24812ca32b48STejun Heo * enusre the fcoe_wq is flushed. 24822ca32b48STejun Heo */ 24832e70e241SChris Leech fcoe_if_exit(); 248478a58246SYi Zou 248578a58246SYi Zou /* detach from fcoe transport */ 248678a58246SYi Zou fcoe_transport_detach(&fcoe_sw_transport); 2487a703e490SVasu Dev } 2488a703e490SVasu Dev module_exit(fcoe_exit); 248911b56188SChris Leech 249011b56188SChris Leech /** 249111b56188SChris Leech * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler 249211b56188SChris Leech * @seq: active sequence in the FLOGI or FDISC exchange 249311b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 249411b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 249511b56188SChris Leech * 249665155b37SUwe Kleine-König * This handles MAC address management for FCoE, then passes control on to 249711b56188SChris Leech * the libfc FLOGI response handler. 249811b56188SChris Leech */ 249911b56188SChris Leech static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 250011b56188SChris Leech { 250111b56188SChris Leech struct fcoe_ctlr *fip = arg; 250211b56188SChris Leech struct fc_exch *exch = fc_seq_exch(seq); 250311b56188SChris Leech struct fc_lport *lport = exch->lp; 250411b56188SChris Leech u8 *mac; 250511b56188SChris Leech 250611b56188SChris Leech if (IS_ERR(fp)) 250711b56188SChris Leech goto done; 250811b56188SChris Leech 250911b56188SChris Leech mac = fr_cb(fp)->granted_mac; 251011b56188SChris Leech if (is_zero_ether_addr(mac)) { 251111b56188SChris Leech /* pre-FIP */ 2512386309ceSJoe Eykholt if (fcoe_ctlr_recv_flogi(fip, lport, fp)) { 251311b56188SChris Leech fc_frame_free(fp); 251411b56188SChris Leech return; 251511b56188SChris Leech } 251611b56188SChris Leech } 2517386309ceSJoe Eykholt fcoe_update_src_mac(lport, mac); 251811b56188SChris Leech done: 251911b56188SChris Leech fc_lport_flogi_resp(seq, fp, lport); 252011b56188SChris Leech } 252111b56188SChris Leech 252211b56188SChris Leech /** 252311b56188SChris Leech * fcoe_logo_resp() - FCoE specific LOGO response handler 252411b56188SChris Leech * @seq: active sequence in the LOGO exchange 252511b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 252611b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 252711b56188SChris Leech * 252865155b37SUwe Kleine-König * This handles MAC address management for FCoE, then passes control on to 252911b56188SChris Leech * the libfc LOGO response handler. 253011b56188SChris Leech */ 253111b56188SChris Leech static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 253211b56188SChris Leech { 2533386309ceSJoe Eykholt struct fc_lport *lport = arg; 253411b56188SChris Leech static u8 zero_mac[ETH_ALEN] = { 0 }; 253511b56188SChris Leech 253611b56188SChris Leech if (!IS_ERR(fp)) 2537386309ceSJoe Eykholt fcoe_update_src_mac(lport, zero_mac); 253811b56188SChris Leech fc_lport_logo_resp(seq, fp, lport); 253911b56188SChris Leech } 254011b56188SChris Leech 254111b56188SChris Leech /** 254211b56188SChris Leech * fcoe_elsct_send - FCoE specific ELS handler 254311b56188SChris Leech * 254411b56188SChris Leech * This does special case handling of FIP encapsualted ELS exchanges for FCoE, 254511b56188SChris Leech * using FCoE specific response handlers and passing the FIP controller as 254611b56188SChris Leech * the argument (the lport is still available from the exchange). 254711b56188SChris Leech * 254811b56188SChris Leech * Most of the work here is just handed off to the libfc routine. 254911b56188SChris Leech */ 25501875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did, 25511875f27eSRobert Love struct fc_frame *fp, unsigned int op, 25521875f27eSRobert Love void (*resp)(struct fc_seq *, 25531875f27eSRobert Love struct fc_frame *, 25541875f27eSRobert Love void *), 255511b56188SChris Leech void *arg, u32 timeout) 255611b56188SChris Leech { 255711b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 255811b56188SChris Leech struct fcoe_interface *fcoe = port->fcoe; 255911b56188SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 256011b56188SChris Leech struct fc_frame_header *fh = fc_frame_header_get(fp); 256111b56188SChris Leech 256211b56188SChris Leech switch (op) { 256311b56188SChris Leech case ELS_FLOGI: 256411b56188SChris Leech case ELS_FDISC: 2565e10f8c66SJoe Eykholt if (lport->point_to_multipoint) 2566e10f8c66SJoe Eykholt break; 256711b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp, 256811b56188SChris Leech fip, timeout); 256911b56188SChris Leech case ELS_LOGO: 257011b56188SChris Leech /* only hook onto fabric logouts, not port logouts */ 257111b56188SChris Leech if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) 257211b56188SChris Leech break; 257311b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp, 2574386309ceSJoe Eykholt lport, timeout); 257511b56188SChris Leech } 257611b56188SChris Leech return fc_elsct_send(lport, did, fp, op, resp, arg, timeout); 257711b56188SChris Leech } 257811b56188SChris Leech 25799a05753bSChris Leech /** 25809a05753bSChris Leech * fcoe_vport_create() - create an fc_host/scsi_host for a vport 25819a05753bSChris Leech * @vport: fc_vport object to create a new fc_host for 25829a05753bSChris Leech * @disabled: start the new fc_host in a disabled state by default? 25839a05753bSChris Leech * 25849a05753bSChris Leech * Returns: 0 for success 25859a05753bSChris Leech */ 25869a05753bSChris Leech static int fcoe_vport_create(struct fc_vport *vport, bool disabled) 25879a05753bSChris Leech { 25889a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 25899a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 25909a05753bSChris Leech struct fcoe_port *port = lport_priv(n_port); 25919a05753bSChris Leech struct fcoe_interface *fcoe = port->fcoe; 25929a05753bSChris Leech struct net_device *netdev = fcoe->netdev; 25939a05753bSChris Leech struct fc_lport *vn_port; 25949a05753bSChris Leech 25959a05753bSChris Leech mutex_lock(&fcoe_config_mutex); 25969a05753bSChris Leech vn_port = fcoe_if_create(fcoe, &vport->dev, 1); 25979a05753bSChris Leech mutex_unlock(&fcoe_config_mutex); 25989a05753bSChris Leech 25999a05753bSChris Leech if (IS_ERR(vn_port)) { 26009a05753bSChris Leech printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n", 26019a05753bSChris Leech netdev->name); 26029a05753bSChris Leech return -EIO; 26039a05753bSChris Leech } 26049a05753bSChris Leech 26059a05753bSChris Leech if (disabled) { 26069a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 26079a05753bSChris Leech } else { 26089a05753bSChris Leech vn_port->boot_time = jiffies; 26099a05753bSChris Leech fc_fabric_login(vn_port); 26109a05753bSChris Leech fc_vport_setlink(vn_port); 26119a05753bSChris Leech } 26129a05753bSChris Leech return 0; 26139a05753bSChris Leech } 26149a05753bSChris Leech 26159a05753bSChris Leech /** 26169a05753bSChris Leech * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport 26179a05753bSChris Leech * @vport: fc_vport object that is being destroyed 26189a05753bSChris Leech * 26199a05753bSChris Leech * Returns: 0 for success 26209a05753bSChris Leech */ 26219a05753bSChris Leech static int fcoe_vport_destroy(struct fc_vport *vport) 26229a05753bSChris Leech { 26239a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 26249a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 26259a05753bSChris Leech struct fc_lport *vn_port = vport->dd_data; 26269a05753bSChris Leech struct fcoe_port *port = lport_priv(vn_port); 26279a05753bSChris Leech 26289a05753bSChris Leech mutex_lock(&n_port->lp_mutex); 26299a05753bSChris Leech list_del(&vn_port->list); 26309a05753bSChris Leech mutex_unlock(&n_port->lp_mutex); 26312ca32b48STejun Heo queue_work(fcoe_wq, &port->destroy_work); 26329a05753bSChris Leech return 0; 26339a05753bSChris Leech } 26349a05753bSChris Leech 26359a05753bSChris Leech /** 26369a05753bSChris Leech * fcoe_vport_disable() - change vport state 26379a05753bSChris Leech * @vport: vport to bring online/offline 26389a05753bSChris Leech * @disable: should the vport be disabled? 26399a05753bSChris Leech */ 26409a05753bSChris Leech static int fcoe_vport_disable(struct fc_vport *vport, bool disable) 26419a05753bSChris Leech { 26429a05753bSChris Leech struct fc_lport *lport = vport->dd_data; 26439a05753bSChris Leech 26449a05753bSChris Leech if (disable) { 26459a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 26469a05753bSChris Leech fc_fabric_logoff(lport); 26479a05753bSChris Leech } else { 26489a05753bSChris Leech lport->boot_time = jiffies; 26499a05753bSChris Leech fc_fabric_login(lport); 26509a05753bSChris Leech fc_vport_setlink(lport); 26519a05753bSChris Leech } 26529a05753bSChris Leech 26539a05753bSChris Leech return 0; 26549a05753bSChris Leech } 26559a05753bSChris Leech 2656dc8596d3SChris Leech /** 2657dc8596d3SChris Leech * fcoe_vport_set_symbolic_name() - append vport string to symbolic name 2658dc8596d3SChris Leech * @vport: fc_vport with a new symbolic name string 2659dc8596d3SChris Leech * 2660dc8596d3SChris Leech * After generating a new symbolic name string, a new RSPN_ID request is 2661dc8596d3SChris Leech * sent to the name server. There is no response handler, so if it fails 2662dc8596d3SChris Leech * for some reason it will not be retried. 2663dc8596d3SChris Leech */ 2664dc8596d3SChris Leech static void fcoe_set_vport_symbolic_name(struct fc_vport *vport) 2665dc8596d3SChris Leech { 2666dc8596d3SChris Leech struct fc_lport *lport = vport->dd_data; 2667dc8596d3SChris Leech struct fc_frame *fp; 2668dc8596d3SChris Leech size_t len; 2669dc8596d3SChris Leech 2670dc8596d3SChris Leech snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 2671dc8596d3SChris Leech "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION, 2672dc8596d3SChris Leech fcoe_netdev(lport)->name, vport->symbolic_name); 2673dc8596d3SChris Leech 2674dc8596d3SChris Leech if (lport->state != LPORT_ST_READY) 2675dc8596d3SChris Leech return; 2676dc8596d3SChris Leech 2677dc8596d3SChris Leech len = strnlen(fc_host_symbolic_name(lport->host), 255); 2678dc8596d3SChris Leech fp = fc_frame_alloc(lport, 2679dc8596d3SChris Leech sizeof(struct fc_ct_hdr) + 2680dc8596d3SChris Leech sizeof(struct fc_ns_rspn) + len); 2681dc8596d3SChris Leech if (!fp) 2682dc8596d3SChris Leech return; 2683dc8596d3SChris Leech lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID, 2684b94f8951SJoe Eykholt NULL, NULL, 3 * lport->r_a_tov); 2685dc8596d3SChris Leech } 2686b84056bfSYi Zou 2687b84056bfSYi Zou /** 2688b84056bfSYi Zou * fcoe_get_lesb() - Fill the FCoE Link Error Status Block 2689b84056bfSYi Zou * @lport: the local port 2690b84056bfSYi Zou * @fc_lesb: the link error status block 2691b84056bfSYi Zou */ 2692b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *lport, 2693b84056bfSYi Zou struct fc_els_lesb *fc_lesb) 2694b84056bfSYi Zou { 2695b84056bfSYi Zou unsigned int cpu; 2696b84056bfSYi Zou u32 lfc, vlfc, mdac; 2697b84056bfSYi Zou struct fcoe_dev_stats *devst; 2698b84056bfSYi Zou struct fcoe_fc_els_lesb *lesb; 269928172739SEric Dumazet struct rtnl_link_stats64 temp; 2700b84056bfSYi Zou struct net_device *netdev = fcoe_netdev(lport); 2701b84056bfSYi Zou 2702b84056bfSYi Zou lfc = 0; 2703b84056bfSYi Zou vlfc = 0; 2704b84056bfSYi Zou mdac = 0; 2705b84056bfSYi Zou lesb = (struct fcoe_fc_els_lesb *)fc_lesb; 2706b84056bfSYi Zou memset(lesb, 0, sizeof(*lesb)); 2707b84056bfSYi Zou for_each_possible_cpu(cpu) { 2708b84056bfSYi Zou devst = per_cpu_ptr(lport->dev_stats, cpu); 2709b84056bfSYi Zou lfc += devst->LinkFailureCount; 2710b84056bfSYi Zou vlfc += devst->VLinkFailureCount; 2711b84056bfSYi Zou mdac += devst->MissDiscAdvCount; 2712b84056bfSYi Zou } 2713b84056bfSYi Zou lesb->lesb_link_fail = htonl(lfc); 2714b84056bfSYi Zou lesb->lesb_vlink_fail = htonl(vlfc); 2715b84056bfSYi Zou lesb->lesb_miss_fka = htonl(mdac); 271628172739SEric Dumazet lesb->lesb_fcs_error = htonl(dev_get_stats(netdev, &temp)->rx_crc_errors); 2717b84056bfSYi Zou } 27187d65b0dfSJoe Eykholt 27197d65b0dfSJoe Eykholt /** 27207d65b0dfSJoe Eykholt * fcoe_set_port_id() - Callback from libfc when Port_ID is set. 27217d65b0dfSJoe Eykholt * @lport: the local port 27227d65b0dfSJoe Eykholt * @port_id: the port ID 27237d65b0dfSJoe Eykholt * @fp: the received frame, if any, that caused the port_id to be set. 27247d65b0dfSJoe Eykholt * 27257d65b0dfSJoe Eykholt * This routine handles the case where we received a FLOGI and are 27267d65b0dfSJoe Eykholt * entering point-to-point mode. We need to call fcoe_ctlr_recv_flogi() 27277d65b0dfSJoe Eykholt * so it can set the non-mapped mode and gateway address. 27287d65b0dfSJoe Eykholt * 27297d65b0dfSJoe Eykholt * The FLOGI LS_ACC is handled by fcoe_flogi_resp(). 27307d65b0dfSJoe Eykholt */ 27317d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *lport, 27327d65b0dfSJoe Eykholt u32 port_id, struct fc_frame *fp) 27337d65b0dfSJoe Eykholt { 27347d65b0dfSJoe Eykholt struct fcoe_port *port = lport_priv(lport); 27357d65b0dfSJoe Eykholt struct fcoe_interface *fcoe = port->fcoe; 27367d65b0dfSJoe Eykholt 27377d65b0dfSJoe Eykholt if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) 27387d65b0dfSJoe Eykholt fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp); 27397d65b0dfSJoe Eykholt } 2740