1a703e490SVasu Dev /* 2af7f85d9SChris Leech * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved. 3a703e490SVasu Dev * 4a703e490SVasu Dev * This program is free software; you can redistribute it and/or modify it 5a703e490SVasu Dev * under the terms and conditions of the GNU General Public License, 6a703e490SVasu Dev * version 2, as published by the Free Software Foundation. 7a703e490SVasu Dev * 8a703e490SVasu Dev * This program is distributed in the hope it will be useful, but WITHOUT 9a703e490SVasu Dev * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10a703e490SVasu Dev * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11a703e490SVasu Dev * more details. 12a703e490SVasu Dev * 13a703e490SVasu Dev * You should have received a copy of the GNU General Public License along with 14a703e490SVasu Dev * this program; if not, write to the Free Software Foundation, Inc., 15a703e490SVasu Dev * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 16a703e490SVasu Dev * 17a703e490SVasu Dev * Maintained at www.Open-FCoE.org 18a703e490SVasu Dev */ 19a703e490SVasu Dev 20a703e490SVasu Dev #include <linux/module.h> 21a703e490SVasu Dev #include <linux/version.h> 22a703e490SVasu Dev #include <linux/spinlock.h> 23a703e490SVasu Dev #include <linux/netdevice.h> 24a703e490SVasu Dev #include <linux/etherdevice.h> 25a703e490SVasu Dev #include <linux/ethtool.h> 26a703e490SVasu Dev #include <linux/if_ether.h> 27a703e490SVasu Dev #include <linux/if_vlan.h> 28a703e490SVasu Dev #include <linux/crc32.h> 295a0e3ad6STejun Heo #include <linux/slab.h> 30a703e490SVasu Dev #include <linux/cpu.h> 31a703e490SVasu Dev #include <linux/fs.h> 32a703e490SVasu Dev #include <linux/sysfs.h> 33a703e490SVasu Dev #include <linux/ctype.h> 34a703e490SVasu Dev #include <scsi/scsi_tcq.h> 35a703e490SVasu Dev #include <scsi/scsicam.h> 36a703e490SVasu Dev #include <scsi/scsi_transport.h> 37a703e490SVasu Dev #include <scsi/scsi_transport_fc.h> 38a703e490SVasu Dev #include <net/rtnetlink.h> 39a703e490SVasu Dev 40a703e490SVasu Dev #include <scsi/fc/fc_encaps.h> 4197c8389dSJoe Eykholt #include <scsi/fc/fc_fip.h> 42a703e490SVasu Dev 43a703e490SVasu Dev #include <scsi/libfc.h> 44a703e490SVasu Dev #include <scsi/fc_frame.h> 45a703e490SVasu Dev #include <scsi/libfcoe.h> 46a703e490SVasu Dev 47fdd78027SVasu Dev #include "fcoe.h" 48fdd78027SVasu Dev 49a703e490SVasu Dev MODULE_AUTHOR("Open-FCoE.org"); 50a703e490SVasu Dev MODULE_DESCRIPTION("FCoE"); 519b34ecffSVasu Dev MODULE_LICENSE("GPL v2"); 52a703e490SVasu Dev 5305cc7390SYi Zou /* Performance tuning parameters for fcoe */ 5405cc7390SYi Zou static unsigned int fcoe_ddp_min; 5505cc7390SYi Zou module_param_named(ddp_min, fcoe_ddp_min, uint, S_IRUGO | S_IWUSR); 5605cc7390SYi Zou MODULE_PARM_DESC(ddp_min, "Minimum I/O size in bytes for " \ 5705cc7390SYi Zou "Direct Data Placement (DDP)."); 5805cc7390SYi Zou 59dfc1d0feSChris Leech DEFINE_MUTEX(fcoe_config_mutex); 60dfc1d0feSChris Leech 61e7a51997SJoe Eykholt /* fcoe_percpu_clean completion. Waiter protected by fcoe_create_mutex */ 62e7a51997SJoe Eykholt static DECLARE_COMPLETION(fcoe_flush_completion); 63e7a51997SJoe Eykholt 64a703e490SVasu Dev /* fcoe host list */ 65090eb6c4SChris Leech /* must only by accessed under the RTNL mutex */ 66a703e490SVasu Dev LIST_HEAD(fcoe_hostlist); 67a703e490SVasu Dev DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu); 68a703e490SVasu Dev 69dd3fd72eSChris Leech /* Function Prototypes */ 701875f27eSRobert Love static int fcoe_reset(struct Scsi_Host *); 71fdd78027SVasu Dev static int fcoe_xmit(struct fc_lport *, struct fc_frame *); 72fdd78027SVasu Dev static int fcoe_rcv(struct sk_buff *, struct net_device *, 73fdd78027SVasu Dev struct packet_type *, struct net_device *); 741875f27eSRobert Love static int fcoe_percpu_receive_thread(void *); 751875f27eSRobert Love static void fcoe_clean_pending_queue(struct fc_lport *); 761875f27eSRobert Love static void fcoe_percpu_clean(struct fc_lport *); 775e4f8fe7SRobert Love static int fcoe_link_speed_update(struct fc_lport *); 781875f27eSRobert Love static int fcoe_link_ok(struct fc_lport *); 79fdd78027SVasu Dev 80fdd78027SVasu Dev static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *); 81fdd78027SVasu Dev static int fcoe_hostlist_add(const struct fc_lport *); 82fdd78027SVasu Dev 834bb6b515SVasu Dev static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *); 84a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *, ulong, void *); 85a703e490SVasu Dev static void fcoe_dev_setup(void); 86a703e490SVasu Dev static void fcoe_dev_cleanup(void); 871875f27eSRobert Love static struct fcoe_interface 881875f27eSRobert Love *fcoe_hostlist_lookup_port(const struct net_device *); 89a703e490SVasu Dev 901875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *, struct net_device *, 911875f27eSRobert Love struct packet_type *, struct net_device *); 921875f27eSRobert Love 931875f27eSRobert Love static void fcoe_fip_send(struct fcoe_ctlr *, struct sk_buff *); 941875f27eSRobert Love static void fcoe_update_src_mac(struct fc_lport *, u8 *); 951875f27eSRobert Love static u8 *fcoe_get_src_mac(struct fc_lport *); 961875f27eSRobert Love static void fcoe_destroy_work(struct work_struct *); 971875f27eSRobert Love 981875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *, u16, struct scatterlist *, 991875f27eSRobert Love unsigned int); 1001875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *, u16); 1011875f27eSRobert Love 1021875f27eSRobert Love static int fcoe_cpu_callback(struct notifier_block *, unsigned long, void *); 1031875f27eSRobert Love 1041875f27eSRobert Love static int fcoe_create(const char *, struct kernel_param *); 1051875f27eSRobert Love static int fcoe_destroy(const char *, struct kernel_param *); 10655a66d3cSVasu Dev static int fcoe_enable(const char *, struct kernel_param *); 10755a66d3cSVasu Dev static int fcoe_disable(const char *, struct kernel_param *); 1081875f27eSRobert Love 1091875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *, 1101875f27eSRobert Love u32 did, struct fc_frame *, 1111875f27eSRobert Love unsigned int op, 1121875f27eSRobert Love void (*resp)(struct fc_seq *, 1131875f27eSRobert Love struct fc_frame *, 1141875f27eSRobert Love void *), 1151875f27eSRobert Love void *, u32 timeout); 116859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb); 1171875f27eSRobert Love 118b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *, struct fc_els_lesb *); 119b84056bfSYi Zou 1203067817aSVasu Dev module_param_call(create, fcoe_create, NULL, (void *)FIP_MODE_FABRIC, S_IWUSR); 1211875f27eSRobert Love __MODULE_PARM_TYPE(create, "string"); 12255a66d3cSVasu Dev MODULE_PARM_DESC(create, " Creates fcoe instance on a ethernet interface"); 1231dd454d9SJoe Eykholt module_param_call(create_vn2vn, fcoe_create, NULL, 1241dd454d9SJoe Eykholt (void *)FIP_MODE_VN2VN, S_IWUSR); 1251dd454d9SJoe Eykholt __MODULE_PARM_TYPE(create_vn2vn, "string"); 1261dd454d9SJoe Eykholt MODULE_PARM_DESC(create_vn2vn, " Creates a VN_node to VN_node FCoE instance " 1271dd454d9SJoe Eykholt "on an Ethernet interface"); 1281875f27eSRobert Love module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR); 1291875f27eSRobert Love __MODULE_PARM_TYPE(destroy, "string"); 13055a66d3cSVasu Dev MODULE_PARM_DESC(destroy, " Destroys fcoe instance on a ethernet interface"); 13155a66d3cSVasu Dev module_param_call(enable, fcoe_enable, NULL, NULL, S_IWUSR); 13255a66d3cSVasu Dev __MODULE_PARM_TYPE(enable, "string"); 13355a66d3cSVasu Dev MODULE_PARM_DESC(enable, " Enables fcoe on a ethernet interface."); 13455a66d3cSVasu Dev module_param_call(disable, fcoe_disable, NULL, NULL, S_IWUSR); 13555a66d3cSVasu Dev __MODULE_PARM_TYPE(disable, "string"); 13655a66d3cSVasu Dev MODULE_PARM_DESC(disable, " Disables fcoe on a ethernet interface."); 1371875f27eSRobert Love 1381875f27eSRobert Love /* notification function for packets from net device */ 139a703e490SVasu Dev static struct notifier_block fcoe_notifier = { 140a703e490SVasu Dev .notifier_call = fcoe_device_notification, 141a703e490SVasu Dev }; 142a703e490SVasu Dev 1431875f27eSRobert Love /* notification function for CPU hotplug events */ 1441875f27eSRobert Love static struct notifier_block fcoe_cpu_notifier = { 1451875f27eSRobert Love .notifier_call = fcoe_cpu_callback, 1461875f27eSRobert Love }; 1471875f27eSRobert Love 148e9084bb8SChris Leech static struct scsi_transport_template *fcoe_transport_template; 149e9084bb8SChris Leech static struct scsi_transport_template *fcoe_vport_transport_template; 150a703e490SVasu Dev 1511875f27eSRobert Love static int fcoe_vport_destroy(struct fc_vport *); 1521875f27eSRobert Love static int fcoe_vport_create(struct fc_vport *, bool disabled); 1531875f27eSRobert Love static int fcoe_vport_disable(struct fc_vport *, bool disable); 1541875f27eSRobert Love static void fcoe_set_vport_symbolic_name(struct fc_vport *); 1557d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *, u32, struct fc_frame *); 1561875f27eSRobert Love 1571875f27eSRobert Love static struct libfc_function_template fcoe_libfc_fcn_templ = { 1581875f27eSRobert Love .frame_send = fcoe_xmit, 1591875f27eSRobert Love .ddp_setup = fcoe_ddp_setup, 1601875f27eSRobert Love .ddp_done = fcoe_ddp_done, 1611875f27eSRobert Love .elsct_send = fcoe_elsct_send, 162b84056bfSYi Zou .get_lesb = fcoe_get_lesb, 1637d65b0dfSJoe Eykholt .lport_set_port_id = fcoe_set_port_id, 1641875f27eSRobert Love }; 1659a05753bSChris Leech 166a703e490SVasu Dev struct fc_function_template fcoe_transport_function = { 167a703e490SVasu Dev .show_host_node_name = 1, 168a703e490SVasu Dev .show_host_port_name = 1, 169a703e490SVasu Dev .show_host_supported_classes = 1, 170a703e490SVasu Dev .show_host_supported_fc4s = 1, 171a703e490SVasu Dev .show_host_active_fc4s = 1, 172a703e490SVasu Dev .show_host_maxframe_size = 1, 173a703e490SVasu Dev 174a703e490SVasu Dev .show_host_port_id = 1, 175a703e490SVasu Dev .show_host_supported_speeds = 1, 176a703e490SVasu Dev .get_host_speed = fc_get_host_speed, 177a703e490SVasu Dev .show_host_speed = 1, 178a703e490SVasu Dev .show_host_port_type = 1, 179a703e490SVasu Dev .get_host_port_state = fc_get_host_port_state, 180a703e490SVasu Dev .show_host_port_state = 1, 181a703e490SVasu Dev .show_host_symbolic_name = 1, 182a703e490SVasu Dev 183a703e490SVasu Dev .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), 184a703e490SVasu Dev .show_rport_maxframe_size = 1, 185a703e490SVasu Dev .show_rport_supported_classes = 1, 186a703e490SVasu Dev 187a703e490SVasu Dev .show_host_fabric_name = 1, 188a703e490SVasu Dev .show_starget_node_name = 1, 189a703e490SVasu Dev .show_starget_port_name = 1, 190a703e490SVasu Dev .show_starget_port_id = 1, 191a703e490SVasu Dev .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, 192a703e490SVasu Dev .show_rport_dev_loss_tmo = 1, 193a703e490SVasu Dev .get_fc_host_stats = fc_get_host_stats, 194a703e490SVasu Dev .issue_fc_host_lip = fcoe_reset, 195a703e490SVasu Dev 196a703e490SVasu Dev .terminate_rport_io = fc_rport_terminate_io, 1979a05753bSChris Leech 1989a05753bSChris Leech .vport_create = fcoe_vport_create, 1999a05753bSChris Leech .vport_delete = fcoe_vport_destroy, 2009a05753bSChris Leech .vport_disable = fcoe_vport_disable, 201dc8596d3SChris Leech .set_vport_symbolic_name = fcoe_set_vport_symbolic_name, 202a51ab396SSteve Ma 203a51ab396SSteve Ma .bsg_request = fc_lport_bsg_request, 204a703e490SVasu Dev }; 205a703e490SVasu Dev 206e9084bb8SChris Leech struct fc_function_template fcoe_vport_transport_function = { 207e9084bb8SChris Leech .show_host_node_name = 1, 208e9084bb8SChris Leech .show_host_port_name = 1, 209e9084bb8SChris Leech .show_host_supported_classes = 1, 210e9084bb8SChris Leech .show_host_supported_fc4s = 1, 211e9084bb8SChris Leech .show_host_active_fc4s = 1, 212e9084bb8SChris Leech .show_host_maxframe_size = 1, 213e9084bb8SChris Leech 214e9084bb8SChris Leech .show_host_port_id = 1, 215e9084bb8SChris Leech .show_host_supported_speeds = 1, 216e9084bb8SChris Leech .get_host_speed = fc_get_host_speed, 217e9084bb8SChris Leech .show_host_speed = 1, 218e9084bb8SChris Leech .show_host_port_type = 1, 219e9084bb8SChris Leech .get_host_port_state = fc_get_host_port_state, 220e9084bb8SChris Leech .show_host_port_state = 1, 221e9084bb8SChris Leech .show_host_symbolic_name = 1, 222e9084bb8SChris Leech 223e9084bb8SChris Leech .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), 224e9084bb8SChris Leech .show_rport_maxframe_size = 1, 225e9084bb8SChris Leech .show_rport_supported_classes = 1, 226e9084bb8SChris Leech 227e9084bb8SChris Leech .show_host_fabric_name = 1, 228e9084bb8SChris Leech .show_starget_node_name = 1, 229e9084bb8SChris Leech .show_starget_port_name = 1, 230e9084bb8SChris Leech .show_starget_port_id = 1, 231e9084bb8SChris Leech .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, 232e9084bb8SChris Leech .show_rport_dev_loss_tmo = 1, 233e9084bb8SChris Leech .get_fc_host_stats = fc_get_host_stats, 234e9084bb8SChris Leech .issue_fc_host_lip = fcoe_reset, 235e9084bb8SChris Leech 236e9084bb8SChris Leech .terminate_rport_io = fc_rport_terminate_io, 237a51ab396SSteve Ma 238a51ab396SSteve Ma .bsg_request = fc_lport_bsg_request, 239e9084bb8SChris Leech }; 240e9084bb8SChris Leech 241a703e490SVasu Dev static struct scsi_host_template fcoe_shost_template = { 242a703e490SVasu Dev .module = THIS_MODULE, 243a703e490SVasu Dev .name = "FCoE Driver", 244a703e490SVasu Dev .proc_name = FCOE_NAME, 245a703e490SVasu Dev .queuecommand = fc_queuecommand, 246a703e490SVasu Dev .eh_abort_handler = fc_eh_abort, 247a703e490SVasu Dev .eh_device_reset_handler = fc_eh_device_reset, 248a703e490SVasu Dev .eh_host_reset_handler = fc_eh_host_reset, 249a703e490SVasu Dev .slave_alloc = fc_slave_alloc, 250a703e490SVasu Dev .change_queue_depth = fc_change_queue_depth, 251a703e490SVasu Dev .change_queue_type = fc_change_queue_type, 252a703e490SVasu Dev .this_id = -1, 25314caf44cSVasu Dev .cmd_per_lun = 3, 254a703e490SVasu Dev .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS, 255a703e490SVasu Dev .use_clustering = ENABLE_CLUSTERING, 256a703e490SVasu Dev .sg_tablesize = SG_ALL, 257a703e490SVasu Dev .max_sectors = 0xffff, 258a703e490SVasu Dev }; 259a703e490SVasu Dev 26054b649f8SChris Leech /** 2611875f27eSRobert Love * fcoe_interface_setup() - Setup a FCoE interface 2621875f27eSRobert Love * @fcoe: The new FCoE interface 2631875f27eSRobert Love * @netdev: The net device that the fcoe interface is on 26454b649f8SChris Leech * 26554b649f8SChris Leech * Returns : 0 for success 2662e70e241SChris Leech * Locking: must be called with the RTNL mutex held 26754b649f8SChris Leech */ 26854b649f8SChris Leech static int fcoe_interface_setup(struct fcoe_interface *fcoe, 26954b649f8SChris Leech struct net_device *netdev) 27054b649f8SChris Leech { 27154b649f8SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 27254b649f8SChris Leech struct netdev_hw_addr *ha; 2735bab87e6SYi Zou struct net_device *real_dev; 27454b649f8SChris Leech u8 flogi_maddr[ETH_ALEN]; 275b7a727f1SYi Zou const struct net_device_ops *ops; 27654b649f8SChris Leech 27754b649f8SChris Leech fcoe->netdev = netdev; 27854b649f8SChris Leech 279b7a727f1SYi Zou /* Let LLD initialize for FCoE */ 280b7a727f1SYi Zou ops = netdev->netdev_ops; 281b7a727f1SYi Zou if (ops->ndo_fcoe_enable) { 282b7a727f1SYi Zou if (ops->ndo_fcoe_enable(netdev)) 283b7a727f1SYi Zou FCOE_NETDEV_DBG(netdev, "Failed to enable FCoE" 284b7a727f1SYi Zou " specific feature for LLD.\n"); 285b7a727f1SYi Zou } 286b7a727f1SYi Zou 28754b649f8SChris Leech /* Do not support for bonding device */ 288cc8bdf06SJiri Pirko if (netdev->priv_flags & IFF_BONDING && netdev->flags & IFF_MASTER) { 28959d92516Sjohn fastabend FCOE_NETDEV_DBG(netdev, "Bonded interfaces not supported\n"); 29054b649f8SChris Leech return -EOPNOTSUPP; 29154b649f8SChris Leech } 29254b649f8SChris Leech 29354b649f8SChris Leech /* look for SAN MAC address, if multiple SAN MACs exist, only 29454b649f8SChris Leech * use the first one for SPMA */ 2955bab87e6SYi Zou real_dev = (netdev->priv_flags & IFF_802_1Q_VLAN) ? 2965bab87e6SYi Zou vlan_dev_real_dev(netdev) : netdev; 29754b649f8SChris Leech rcu_read_lock(); 2985bab87e6SYi Zou for_each_dev_addr(real_dev, ha) { 29954b649f8SChris Leech if ((ha->type == NETDEV_HW_ADDR_T_SAN) && 300bf361707SYi Zou (is_valid_ether_addr(ha->addr))) { 30154b649f8SChris Leech memcpy(fip->ctl_src_addr, ha->addr, ETH_ALEN); 30254b649f8SChris Leech fip->spma = 1; 30354b649f8SChris Leech break; 30454b649f8SChris Leech } 30554b649f8SChris Leech } 30654b649f8SChris Leech rcu_read_unlock(); 30754b649f8SChris Leech 30854b649f8SChris Leech /* setup Source Mac Address */ 30954b649f8SChris Leech if (!fip->spma) 31054b649f8SChris Leech memcpy(fip->ctl_src_addr, netdev->dev_addr, netdev->addr_len); 31154b649f8SChris Leech 31254b649f8SChris Leech /* 31354b649f8SChris Leech * Add FCoE MAC address as second unicast MAC address 31454b649f8SChris Leech * or enter promiscuous mode if not capable of listening 31554b649f8SChris Leech * for multiple unicast MACs. 31654b649f8SChris Leech */ 31754b649f8SChris Leech memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 318a748ee24SJiri Pirko dev_uc_add(netdev, flogi_maddr); 31954b649f8SChris Leech if (fip->spma) 320a748ee24SJiri Pirko dev_uc_add(netdev, fip->ctl_src_addr); 321e10f8c66SJoe Eykholt if (fip->mode == FIP_MODE_VN2VN) { 322e10f8c66SJoe Eykholt dev_mc_add(netdev, FIP_ALL_VN2VN_MACS); 323e10f8c66SJoe Eykholt dev_mc_add(netdev, FIP_ALL_P2P_MACS); 324e10f8c66SJoe Eykholt } else 32522bedad3SJiri Pirko dev_mc_add(netdev, FIP_ALL_ENODE_MACS); 32654b649f8SChris Leech 32754b649f8SChris Leech /* 32854b649f8SChris Leech * setup the receive function from ethernet driver 32954b649f8SChris Leech * on the ethertype for the given device 33054b649f8SChris Leech */ 33154b649f8SChris Leech fcoe->fcoe_packet_type.func = fcoe_rcv; 33254b649f8SChris Leech fcoe->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); 33354b649f8SChris Leech fcoe->fcoe_packet_type.dev = netdev; 33454b649f8SChris Leech dev_add_pack(&fcoe->fcoe_packet_type); 33554b649f8SChris Leech 33654b649f8SChris Leech fcoe->fip_packet_type.func = fcoe_fip_recv; 33754b649f8SChris Leech fcoe->fip_packet_type.type = htons(ETH_P_FIP); 33854b649f8SChris Leech fcoe->fip_packet_type.dev = netdev; 33954b649f8SChris Leech dev_add_pack(&fcoe->fip_packet_type); 34054b649f8SChris Leech 34154b649f8SChris Leech return 0; 34254b649f8SChris Leech } 34354b649f8SChris Leech 344a703e490SVasu Dev /** 3451875f27eSRobert Love * fcoe_interface_create() - Create a FCoE interface on a net device 3461875f27eSRobert Love * @netdev: The net device to create the FCoE interface on 3471dd454d9SJoe Eykholt * @fip_mode: The mode to use for FIP 348030f4e00SChris Leech * 349030f4e00SChris Leech * Returns: pointer to a struct fcoe_interface or NULL on error 350030f4e00SChris Leech */ 3511dd454d9SJoe Eykholt static struct fcoe_interface *fcoe_interface_create(struct net_device *netdev, 3521dd454d9SJoe Eykholt enum fip_state fip_mode) 353030f4e00SChris Leech { 354030f4e00SChris Leech struct fcoe_interface *fcoe; 35559d92516Sjohn fastabend int err; 356030f4e00SChris Leech 357030f4e00SChris Leech fcoe = kzalloc(sizeof(*fcoe), GFP_KERNEL); 358030f4e00SChris Leech if (!fcoe) { 359030f4e00SChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate fcoe structure\n"); 360030f4e00SChris Leech return NULL; 361030f4e00SChris Leech } 362030f4e00SChris Leech 3632e70e241SChris Leech dev_hold(netdev); 364030f4e00SChris Leech kref_init(&fcoe->kref); 36554b649f8SChris Leech 36654b649f8SChris Leech /* 36754b649f8SChris Leech * Initialize FIP. 36854b649f8SChris Leech */ 3691dd454d9SJoe Eykholt fcoe_ctlr_init(&fcoe->ctlr, fip_mode); 37054b649f8SChris Leech fcoe->ctlr.send = fcoe_fip_send; 37154b649f8SChris Leech fcoe->ctlr.update_mac = fcoe_update_src_mac; 37211b56188SChris Leech fcoe->ctlr.get_src_addr = fcoe_get_src_mac; 37354b649f8SChris Leech 37459d92516Sjohn fastabend err = fcoe_interface_setup(fcoe, netdev); 37559d92516Sjohn fastabend if (err) { 37659d92516Sjohn fastabend fcoe_ctlr_destroy(&fcoe->ctlr); 37759d92516Sjohn fastabend kfree(fcoe); 37859d92516Sjohn fastabend dev_put(netdev); 37959d92516Sjohn fastabend return NULL; 38059d92516Sjohn fastabend } 381030f4e00SChris Leech 382030f4e00SChris Leech return fcoe; 383030f4e00SChris Leech } 384030f4e00SChris Leech 385030f4e00SChris Leech /** 3861875f27eSRobert Love * fcoe_interface_cleanup() - Clean up a FCoE interface 3871875f27eSRobert Love * @fcoe: The FCoE interface to be cleaned up 3882e70e241SChris Leech * 3892e70e241SChris Leech * Caller must be holding the RTNL mutex 39054b649f8SChris Leech */ 39154b649f8SChris Leech void fcoe_interface_cleanup(struct fcoe_interface *fcoe) 39254b649f8SChris Leech { 39354b649f8SChris Leech struct net_device *netdev = fcoe->netdev; 39454b649f8SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 39554b649f8SChris Leech u8 flogi_maddr[ETH_ALEN]; 396b7a727f1SYi Zou const struct net_device_ops *ops; 39754b649f8SChris Leech 39854b649f8SChris Leech /* 39954b649f8SChris Leech * Don't listen for Ethernet packets anymore. 40054b649f8SChris Leech * synchronize_net() ensures that the packet handlers are not running 40154b649f8SChris Leech * on another CPU. dev_remove_pack() would do that, this calls the 40254b649f8SChris Leech * unsyncronized version __dev_remove_pack() to avoid multiple delays. 40354b649f8SChris Leech */ 40454b649f8SChris Leech __dev_remove_pack(&fcoe->fcoe_packet_type); 40554b649f8SChris Leech __dev_remove_pack(&fcoe->fip_packet_type); 40654b649f8SChris Leech synchronize_net(); 40754b649f8SChris Leech 40854b649f8SChris Leech /* Delete secondary MAC addresses */ 40954b649f8SChris Leech memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); 410a748ee24SJiri Pirko dev_uc_del(netdev, flogi_maddr); 41154b649f8SChris Leech if (fip->spma) 412a748ee24SJiri Pirko dev_uc_del(netdev, fip->ctl_src_addr); 413e10f8c66SJoe Eykholt if (fip->mode == FIP_MODE_VN2VN) { 414e10f8c66SJoe Eykholt dev_mc_del(netdev, FIP_ALL_VN2VN_MACS); 415e10f8c66SJoe Eykholt dev_mc_del(netdev, FIP_ALL_P2P_MACS); 416e10f8c66SJoe Eykholt } else 41722bedad3SJiri Pirko dev_mc_del(netdev, FIP_ALL_ENODE_MACS); 418b7a727f1SYi Zou 419b7a727f1SYi Zou /* Tell the LLD we are done w/ FCoE */ 420b7a727f1SYi Zou ops = netdev->netdev_ops; 421b7a727f1SYi Zou if (ops->ndo_fcoe_disable) { 422b7a727f1SYi Zou if (ops->ndo_fcoe_disable(netdev)) 423b7a727f1SYi Zou FCOE_NETDEV_DBG(netdev, "Failed to disable FCoE" 424b7a727f1SYi Zou " specific feature for LLD.\n"); 425b7a727f1SYi Zou } 42654b649f8SChris Leech } 42754b649f8SChris Leech 42854b649f8SChris Leech /** 429030f4e00SChris Leech * fcoe_interface_release() - fcoe_port kref release function 4301875f27eSRobert Love * @kref: Embedded reference count in an fcoe_interface struct 431030f4e00SChris Leech */ 432030f4e00SChris Leech static void fcoe_interface_release(struct kref *kref) 433030f4e00SChris Leech { 434030f4e00SChris Leech struct fcoe_interface *fcoe; 4352e70e241SChris Leech struct net_device *netdev; 436030f4e00SChris Leech 437030f4e00SChris Leech fcoe = container_of(kref, struct fcoe_interface, kref); 4382e70e241SChris Leech netdev = fcoe->netdev; 4392e70e241SChris Leech /* tear-down the FCoE controller */ 4402e70e241SChris Leech fcoe_ctlr_destroy(&fcoe->ctlr); 441030f4e00SChris Leech kfree(fcoe); 4422e70e241SChris Leech dev_put(netdev); 443030f4e00SChris Leech } 444030f4e00SChris Leech 445030f4e00SChris Leech /** 4461875f27eSRobert Love * fcoe_interface_get() - Get a reference to a FCoE interface 4471875f27eSRobert Love * @fcoe: The FCoE interface to be held 448030f4e00SChris Leech */ 449030f4e00SChris Leech static inline void fcoe_interface_get(struct fcoe_interface *fcoe) 450030f4e00SChris Leech { 451030f4e00SChris Leech kref_get(&fcoe->kref); 452030f4e00SChris Leech } 453030f4e00SChris Leech 454030f4e00SChris Leech /** 4551875f27eSRobert Love * fcoe_interface_put() - Put a reference to a FCoE interface 4561875f27eSRobert Love * @fcoe: The FCoE interface to be released 457030f4e00SChris Leech */ 458030f4e00SChris Leech static inline void fcoe_interface_put(struct fcoe_interface *fcoe) 459030f4e00SChris Leech { 460030f4e00SChris Leech kref_put(&fcoe->kref, fcoe_interface_release); 461030f4e00SChris Leech } 462030f4e00SChris Leech 463030f4e00SChris Leech /** 4641875f27eSRobert Love * fcoe_fip_recv() - Handler for received FIP frames 4651875f27eSRobert Love * @skb: The receive skb 4661875f27eSRobert Love * @netdev: The associated net device 4671875f27eSRobert Love * @ptype: The packet_type structure which was used to register this handler 4681875f27eSRobert Love * @orig_dev: The original net_device the the skb was received on. 4691875f27eSRobert Love * (in case dev is a bond) 470ab6b85c1SVasu Dev * 471ab6b85c1SVasu Dev * Returns: 0 for success 472ab6b85c1SVasu Dev */ 4731875f27eSRobert Love static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *netdev, 474ab6b85c1SVasu Dev struct packet_type *ptype, 475ab6b85c1SVasu Dev struct net_device *orig_dev) 476ab6b85c1SVasu Dev { 477259ad85dSChris Leech struct fcoe_interface *fcoe; 478ab6b85c1SVasu Dev 479259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fip_packet_type); 4803fe9a0baSChris Leech fcoe_ctlr_recv(&fcoe->ctlr, skb); 481ab6b85c1SVasu Dev return 0; 482ab6b85c1SVasu Dev } 483ab6b85c1SVasu Dev 484ab6b85c1SVasu Dev /** 4851875f27eSRobert Love * fcoe_fip_send() - Send an Ethernet-encapsulated FIP frame 4861875f27eSRobert Love * @fip: The FCoE controller 4871875f27eSRobert Love * @skb: The FIP packet to be sent 488ab6b85c1SVasu Dev */ 489ab6b85c1SVasu Dev static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) 490ab6b85c1SVasu Dev { 4913fe9a0baSChris Leech skb->dev = fcoe_from_ctlr(fip)->netdev; 492ab6b85c1SVasu Dev dev_queue_xmit(skb); 493ab6b85c1SVasu Dev } 494ab6b85c1SVasu Dev 495ab6b85c1SVasu Dev /** 4961875f27eSRobert Love * fcoe_update_src_mac() - Update the Ethernet MAC filters 4971875f27eSRobert Love * @lport: The local port to update the source MAC on 4981875f27eSRobert Love * @addr: Unicast MAC address to add 499ab6b85c1SVasu Dev * 500ab6b85c1SVasu Dev * Remove any previously-set unicast MAC filter. 501ab6b85c1SVasu Dev * Add secondary FCoE MAC address filter for our OUI. 502ab6b85c1SVasu Dev */ 50311b56188SChris Leech static void fcoe_update_src_mac(struct fc_lport *lport, u8 *addr) 504ab6b85c1SVasu Dev { 50511b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 50611b56188SChris Leech struct fcoe_interface *fcoe = port->fcoe; 507ab6b85c1SVasu Dev 508ab6b85c1SVasu Dev rtnl_lock(); 50911b56188SChris Leech if (!is_zero_ether_addr(port->data_src_addr)) 510a748ee24SJiri Pirko dev_uc_del(fcoe->netdev, port->data_src_addr); 51111b56188SChris Leech if (!is_zero_ether_addr(addr)) 512a748ee24SJiri Pirko dev_uc_add(fcoe->netdev, addr); 51311b56188SChris Leech memcpy(port->data_src_addr, addr, ETH_ALEN); 514ab6b85c1SVasu Dev rtnl_unlock(); 515ab6b85c1SVasu Dev } 516ab6b85c1SVasu Dev 517ab6b85c1SVasu Dev /** 51811b56188SChris Leech * fcoe_get_src_mac() - return the Ethernet source address for an lport 51911b56188SChris Leech * @lport: libfc lport 52011b56188SChris Leech */ 52111b56188SChris Leech static u8 *fcoe_get_src_mac(struct fc_lport *lport) 52211b56188SChris Leech { 52311b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 52411b56188SChris Leech 52511b56188SChris Leech return port->data_src_addr; 52611b56188SChris Leech } 52711b56188SChris Leech 52811b56188SChris Leech /** 5291875f27eSRobert Love * fcoe_lport_config() - Set up a local port 5301875f27eSRobert Love * @lport: The local port to be setup 531a703e490SVasu Dev * 532a703e490SVasu Dev * Returns: 0 for success 533a703e490SVasu Dev */ 5341875f27eSRobert Love static int fcoe_lport_config(struct fc_lport *lport) 535a703e490SVasu Dev { 5361875f27eSRobert Love lport->link_up = 0; 5371875f27eSRobert Love lport->qfull = 0; 5381875f27eSRobert Love lport->max_retry_count = 3; 5391875f27eSRobert Love lport->max_rport_retry_count = 3; 5401875f27eSRobert Love lport->e_d_tov = 2 * 1000; /* FC-FS default */ 5411875f27eSRobert Love lport->r_a_tov = 2 * 2 * 1000; 5421875f27eSRobert Love lport->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | 543a703e490SVasu Dev FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); 5441875f27eSRobert Love lport->does_npiv = 1; 545a703e490SVasu Dev 5461875f27eSRobert Love fc_lport_init_stats(lport); 547a703e490SVasu Dev 548a703e490SVasu Dev /* lport fc_lport related configuration */ 5491875f27eSRobert Love fc_lport_config(lport); 550a703e490SVasu Dev 551a703e490SVasu Dev /* offload related configuration */ 5521875f27eSRobert Love lport->crc_offload = 0; 5531875f27eSRobert Love lport->seq_offload = 0; 5541875f27eSRobert Love lport->lro_enabled = 0; 5551875f27eSRobert Love lport->lro_xid = 0; 5561875f27eSRobert Love lport->lso_max = 0; 557a703e490SVasu Dev 558a703e490SVasu Dev return 0; 559a703e490SVasu Dev } 560a703e490SVasu Dev 561a703e490SVasu Dev /** 5621875f27eSRobert Love * fcoe_queue_timer() - The fcoe queue timer 5631875f27eSRobert Love * @lport: The local port 5641047f221SVasu Dev * 5651047f221SVasu Dev * Calls fcoe_check_wait_queue on timeout 5661047f221SVasu Dev */ 5671875f27eSRobert Love static void fcoe_queue_timer(ulong lport) 5681047f221SVasu Dev { 5691875f27eSRobert Love fcoe_check_wait_queue((struct fc_lport *)lport, NULL); 5701047f221SVasu Dev } 5711047f221SVasu Dev 5721047f221SVasu Dev /** 573dcece412SYi Zou * fcoe_get_wwn() - Get the world wide name from LLD if it supports it 574dcece412SYi Zou * @netdev: the associated net device 575dcece412SYi Zou * @wwn: the output WWN 576dcece412SYi Zou * @type: the type of WWN (WWPN or WWNN) 577dcece412SYi Zou * 578dcece412SYi Zou * Returns: 0 for success 579dcece412SYi Zou */ 580dcece412SYi Zou static int fcoe_get_wwn(struct net_device *netdev, u64 *wwn, int type) 581dcece412SYi Zou { 582dcece412SYi Zou const struct net_device_ops *ops = netdev->netdev_ops; 583dcece412SYi Zou 584dcece412SYi Zou if (ops->ndo_fcoe_get_wwn) 585dcece412SYi Zou return ops->ndo_fcoe_get_wwn(netdev, wwn, type); 586dcece412SYi Zou return -EINVAL; 587dcece412SYi Zou } 588dcece412SYi Zou 589dcece412SYi Zou /** 59054a5b21dSYi Zou * fcoe_netdev_features_change - Updates the lport's offload flags based 59154a5b21dSYi Zou * on the LLD netdev's FCoE feature flags 59254a5b21dSYi Zou */ 59354a5b21dSYi Zou static void fcoe_netdev_features_change(struct fc_lport *lport, 59454a5b21dSYi Zou struct net_device *netdev) 59554a5b21dSYi Zou { 59654a5b21dSYi Zou mutex_lock(&lport->lp_mutex); 59754a5b21dSYi Zou 59854a5b21dSYi Zou if (netdev->features & NETIF_F_SG) 59954a5b21dSYi Zou lport->sg_supp = 1; 60054a5b21dSYi Zou else 60154a5b21dSYi Zou lport->sg_supp = 0; 60254a5b21dSYi Zou 60354a5b21dSYi Zou if (netdev->features & NETIF_F_FCOE_CRC) { 60454a5b21dSYi Zou lport->crc_offload = 1; 60554a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n"); 60654a5b21dSYi Zou } else { 60754a5b21dSYi Zou lport->crc_offload = 0; 60854a5b21dSYi Zou } 60954a5b21dSYi Zou 61054a5b21dSYi Zou if (netdev->features & NETIF_F_FSO) { 61154a5b21dSYi Zou lport->seq_offload = 1; 61254a5b21dSYi Zou lport->lso_max = netdev->gso_max_size; 61354a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n", 61454a5b21dSYi Zou lport->lso_max); 61554a5b21dSYi Zou } else { 61654a5b21dSYi Zou lport->seq_offload = 0; 61754a5b21dSYi Zou lport->lso_max = 0; 61854a5b21dSYi Zou } 61954a5b21dSYi Zou 62054a5b21dSYi Zou if (netdev->fcoe_ddp_xid) { 62154a5b21dSYi Zou lport->lro_enabled = 1; 62254a5b21dSYi Zou lport->lro_xid = netdev->fcoe_ddp_xid; 62354a5b21dSYi Zou FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n", 62454a5b21dSYi Zou lport->lro_xid); 62554a5b21dSYi Zou } else { 62654a5b21dSYi Zou lport->lro_enabled = 0; 62754a5b21dSYi Zou lport->lro_xid = 0; 62854a5b21dSYi Zou } 62954a5b21dSYi Zou 63054a5b21dSYi Zou mutex_unlock(&lport->lp_mutex); 63154a5b21dSYi Zou } 63254a5b21dSYi Zou 63354a5b21dSYi Zou /** 6341875f27eSRobert Love * fcoe_netdev_config() - Set up net devive for SW FCoE 6351875f27eSRobert Love * @lport: The local port that is associated with the net device 6361875f27eSRobert Love * @netdev: The associated net device 637a703e490SVasu Dev * 6381875f27eSRobert Love * Must be called after fcoe_lport_config() as it will use local port mutex 639a703e490SVasu Dev * 640a703e490SVasu Dev * Returns: 0 for success 641a703e490SVasu Dev */ 6421875f27eSRobert Love static int fcoe_netdev_config(struct fc_lport *lport, struct net_device *netdev) 643a703e490SVasu Dev { 644a703e490SVasu Dev u32 mfs; 645a703e490SVasu Dev u64 wwnn, wwpn; 64625024989SChris Leech struct fcoe_interface *fcoe; 647014f5c3fSChris Leech struct fcoe_port *port; 648a703e490SVasu Dev 649a703e490SVasu Dev /* Setup lport private data to point to fcoe softc */ 6501875f27eSRobert Love port = lport_priv(lport); 65125024989SChris Leech fcoe = port->fcoe; 652a703e490SVasu Dev 653a703e490SVasu Dev /* 654a703e490SVasu Dev * Determine max frame size based on underlying device and optional 655a703e490SVasu Dev * user-configured limit. If the MFS is too low, fcoe_link_ok() 656a703e490SVasu Dev * will return 0, so do this first. 657a703e490SVasu Dev */ 6587221d7e5SYi Zou mfs = netdev->mtu; 6597221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) { 6607221d7e5SYi Zou mfs = FCOE_MTU; 6617221d7e5SYi Zou FCOE_NETDEV_DBG(netdev, "Supports FCOE_MTU of %d bytes\n", mfs); 6627221d7e5SYi Zou } 6637221d7e5SYi Zou mfs -= (sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof)); 6641875f27eSRobert Love if (fc_set_mfs(lport, mfs)) 665a703e490SVasu Dev return -EINVAL; 666a703e490SVasu Dev 667a703e490SVasu Dev /* offload features support */ 66854a5b21dSYi Zou fcoe_netdev_features_change(lport, netdev); 669a703e490SVasu Dev 670014f5c3fSChris Leech skb_queue_head_init(&port->fcoe_pending_queue); 671014f5c3fSChris Leech port->fcoe_pending_queue_active = 0; 6721875f27eSRobert Love setup_timer(&port->timer, fcoe_queue_timer, (unsigned long)lport); 673a703e490SVasu Dev 6745e4f8fe7SRobert Love fcoe_link_speed_update(lport); 6755e4f8fe7SRobert Love 6761875f27eSRobert Love if (!lport->vport) { 677dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwnn, NETDEV_FCOE_WWNN)) 67875ea89efSYi Zou wwnn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 1, 0); 6791875f27eSRobert Love fc_set_wwnn(lport, wwnn); 680dcece412SYi Zou if (fcoe_get_wwn(netdev, &wwpn, NETDEV_FCOE_WWPN)) 681dcece412SYi Zou wwpn = fcoe_wwn_from_mac(fcoe->ctlr.ctl_src_addr, 682cf4aebcaSVasu Dev 2, 0); 6831875f27eSRobert Love fc_set_wwpn(lport, wwpn); 6849a05753bSChris Leech } 685a703e490SVasu Dev 686a703e490SVasu Dev return 0; 687a703e490SVasu Dev } 688a703e490SVasu Dev 689a703e490SVasu Dev /** 6901875f27eSRobert Love * fcoe_shost_config() - Set up the SCSI host associated with a local port 6911875f27eSRobert Love * @lport: The local port 6921875f27eSRobert Love * @dev: The device associated with the SCSI host 693a703e490SVasu Dev * 694a703e490SVasu Dev * Must be called after fcoe_lport_config() and fcoe_netdev_config() 695a703e490SVasu Dev * 696a703e490SVasu Dev * Returns: 0 for success 697a703e490SVasu Dev */ 6988ba00a4bSVasu Dev static int fcoe_shost_config(struct fc_lport *lport, struct device *dev) 699a703e490SVasu Dev { 700a703e490SVasu Dev int rc = 0; 701a703e490SVasu Dev 702a703e490SVasu Dev /* lport scsi host config */ 7031875f27eSRobert Love lport->host->max_lun = FCOE_MAX_LUN; 7041875f27eSRobert Love lport->host->max_id = FCOE_MAX_FCP_TARGET; 7051875f27eSRobert Love lport->host->max_channel = 0; 706da87bfabSVasu Dev lport->host->max_cmd_len = FCOE_MAX_CMD_LEN; 707da87bfabSVasu Dev 7081875f27eSRobert Love if (lport->vport) 7091875f27eSRobert Love lport->host->transportt = fcoe_vport_transport_template; 710e9084bb8SChris Leech else 7111875f27eSRobert Love lport->host->transportt = fcoe_transport_template; 712a703e490SVasu Dev 713a703e490SVasu Dev /* add the new host to the SCSI-ml */ 7141875f27eSRobert Love rc = scsi_add_host(lport->host, dev); 715a703e490SVasu Dev if (rc) { 7161875f27eSRobert Love FCOE_NETDEV_DBG(fcoe_netdev(lport), "fcoe_shost_config: " 717d5488eb9SRobert Love "error on scsi_add_host\n"); 718a703e490SVasu Dev return rc; 719a703e490SVasu Dev } 7209a05753bSChris Leech 7211875f27eSRobert Love if (!lport->vport) 7224be929beSAlexey Dobriyan fc_host_max_npiv_vports(lport->host) = USHRT_MAX; 7239a05753bSChris Leech 7241875f27eSRobert Love snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 7255baa17c3SChris Leech "%s v%s over %s", FCOE_NAME, FCOE_VERSION, 7261875f27eSRobert Love fcoe_netdev(lport)->name); 727a703e490SVasu Dev 728a703e490SVasu Dev return 0; 729a703e490SVasu Dev } 730a703e490SVasu Dev 7311875f27eSRobert Love /** 7321875f27eSRobert Love * fcoe_oem_match() - The match routine for the offloaded exchange manager 7331875f27eSRobert Love * @fp: The I/O frame 734d7179680SVasu Dev * 7351875f27eSRobert Love * This routine will be associated with an exchange manager (EM). When 7361875f27eSRobert Love * the libfc exchange handling code is looking for an EM to use it will 7371875f27eSRobert Love * call this routine and pass it the frame that it wishes to send. This 7381875f27eSRobert Love * routine will return True if the associated EM is to be used and False 7391875f27eSRobert Love * if the echange code should continue looking for an EM. 7401875f27eSRobert Love * 7411875f27eSRobert Love * The offload EM that this routine is associated with will handle any 7421875f27eSRobert Love * packets that are for SCSI read requests. 7431875f27eSRobert Love * 7441875f27eSRobert Love * Returns: True for read types I/O, otherwise returns false. 745d7179680SVasu Dev */ 746d7179680SVasu Dev bool fcoe_oem_match(struct fc_frame *fp) 747d7179680SVasu Dev { 74805cc7390SYi Zou return fc_fcp_is_read(fr_fsp(fp)) && 74905cc7390SYi Zou (fr_fsp(fp)->data_len > fcoe_ddp_min); 750d7179680SVasu Dev } 751d7179680SVasu Dev 752a703e490SVasu Dev /** 7531875f27eSRobert Love * fcoe_em_config() - Allocate and configure an exchange manager 7541875f27eSRobert Love * @lport: The local port that the new EM will be associated with 755a703e490SVasu Dev * 756a703e490SVasu Dev * Returns: 0 on success 757a703e490SVasu Dev */ 7581875f27eSRobert Love static inline int fcoe_em_config(struct fc_lport *lport) 759a703e490SVasu Dev { 7601875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 76125024989SChris Leech struct fcoe_interface *fcoe = port->fcoe; 76225024989SChris Leech struct fcoe_interface *oldfcoe = NULL; 7631d1b88dcSVasu Dev struct net_device *old_real_dev, *cur_real_dev; 764d7179680SVasu Dev u16 min_xid = FCOE_MIN_XID; 765d7179680SVasu Dev u16 max_xid = FCOE_MAX_XID; 766d7179680SVasu Dev 767d7179680SVasu Dev /* 768d7179680SVasu Dev * Check if need to allocate an em instance for 769d7179680SVasu Dev * offload exchange ids to be shared across all VN_PORTs/lport. 770d7179680SVasu Dev */ 7711875f27eSRobert Love if (!lport->lro_enabled || !lport->lro_xid || 7721875f27eSRobert Love (lport->lro_xid >= max_xid)) { 7731875f27eSRobert Love lport->lro_xid = 0; 774d7179680SVasu Dev goto skip_oem; 775d7179680SVasu Dev } 776d7179680SVasu Dev 777d7179680SVasu Dev /* 778d7179680SVasu Dev * Reuse existing offload em instance in case 7791d1b88dcSVasu Dev * it is already allocated on real eth device 780d7179680SVasu Dev */ 78125024989SChris Leech if (fcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 78225024989SChris Leech cur_real_dev = vlan_dev_real_dev(fcoe->netdev); 7831d1b88dcSVasu Dev else 78425024989SChris Leech cur_real_dev = fcoe->netdev; 7851d1b88dcSVasu Dev 78625024989SChris Leech list_for_each_entry(oldfcoe, &fcoe_hostlist, list) { 78725024989SChris Leech if (oldfcoe->netdev->priv_flags & IFF_802_1Q_VLAN) 78825024989SChris Leech old_real_dev = vlan_dev_real_dev(oldfcoe->netdev); 7891d1b88dcSVasu Dev else 79025024989SChris Leech old_real_dev = oldfcoe->netdev; 7911d1b88dcSVasu Dev 7921d1b88dcSVasu Dev if (cur_real_dev == old_real_dev) { 793991cbb60SChris Leech fcoe->oem = oldfcoe->oem; 794d7179680SVasu Dev break; 795d7179680SVasu Dev } 796d7179680SVasu Dev } 797d7179680SVasu Dev 798991cbb60SChris Leech if (fcoe->oem) { 7991875f27eSRobert Love if (!fc_exch_mgr_add(lport, fcoe->oem, fcoe_oem_match)) { 800d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to add " 801d7179680SVasu Dev "offload em:%p on interface:%s\n", 802991cbb60SChris Leech fcoe->oem, fcoe->netdev->name); 803a703e490SVasu Dev return -ENOMEM; 804d7179680SVasu Dev } 805d7179680SVasu Dev } else { 8061875f27eSRobert Love fcoe->oem = fc_exch_mgr_alloc(lport, FC_CLASS_3, 8071875f27eSRobert Love FCOE_MIN_XID, lport->lro_xid, 808d7179680SVasu Dev fcoe_oem_match); 809991cbb60SChris Leech if (!fcoe->oem) { 810d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to allocate " 811d7179680SVasu Dev "em for offload exches on interface:%s\n", 81225024989SChris Leech fcoe->netdev->name); 813d7179680SVasu Dev return -ENOMEM; 814d7179680SVasu Dev } 815d7179680SVasu Dev } 816d7179680SVasu Dev 817d7179680SVasu Dev /* 818d7179680SVasu Dev * Exclude offload EM xid range from next EM xid range. 819d7179680SVasu Dev */ 8201875f27eSRobert Love min_xid += lport->lro_xid + 1; 821d7179680SVasu Dev 822d7179680SVasu Dev skip_oem: 8231875f27eSRobert Love if (!fc_exch_mgr_alloc(lport, FC_CLASS_3, min_xid, max_xid, NULL)) { 824d7179680SVasu Dev printk(KERN_ERR "fcoe_em_config: failed to " 82525024989SChris Leech "allocate em on interface %s\n", fcoe->netdev->name); 826d7179680SVasu Dev return -ENOMEM; 827d7179680SVasu Dev } 828a703e490SVasu Dev 829a703e490SVasu Dev return 0; 830a703e490SVasu Dev } 831a703e490SVasu Dev 832a703e490SVasu Dev /** 8331875f27eSRobert Love * fcoe_if_destroy() - Tear down a SW FCoE instance 8341875f27eSRobert Love * @lport: The local port to be destroyed 83534ce27bcSVasu Dev * 83634ce27bcSVasu Dev * Locking: must be called with the RTNL mutex held and RTNL mutex 83734ce27bcSVasu Dev * needed to be dropped by this function since not dropping RTNL 83834ce27bcSVasu Dev * would cause circular locking warning on synchronous fip worker 83934ce27bcSVasu Dev * cancelling thru fcoe_interface_put invoked by this function. 84034ce27bcSVasu Dev * 841a703e490SVasu Dev */ 842af7f85d9SChris Leech static void fcoe_if_destroy(struct fc_lport *lport) 843a703e490SVasu Dev { 844014f5c3fSChris Leech struct fcoe_port *port = lport_priv(lport); 845014f5c3fSChris Leech struct fcoe_interface *fcoe = port->fcoe; 84625024989SChris Leech struct net_device *netdev = fcoe->netdev; 847a703e490SVasu Dev 848d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Destroying interface\n"); 849a703e490SVasu Dev 850a703e490SVasu Dev /* Logout of the fabric */ 851af7f85d9SChris Leech fc_fabric_logoff(lport); 852a703e490SVasu Dev 853a703e490SVasu Dev /* Cleanup the fc_lport */ 854af7f85d9SChris Leech fc_lport_destroy(lport); 855a703e490SVasu Dev 85654b649f8SChris Leech /* Stop the transmit retry timer */ 85754b649f8SChris Leech del_timer_sync(&port->timer); 85854b649f8SChris Leech 85954b649f8SChris Leech /* Free existing transmit skbs */ 86054b649f8SChris Leech fcoe_clean_pending_queue(lport); 86154b649f8SChris Leech 86211b56188SChris Leech if (!is_zero_ether_addr(port->data_src_addr)) 863a748ee24SJiri Pirko dev_uc_del(netdev, port->data_src_addr); 86411b56188SChris Leech rtnl_unlock(); 86511b56188SChris Leech 86654b649f8SChris Leech /* receives may not be stopped until after this */ 86754b649f8SChris Leech fcoe_interface_put(fcoe); 86854b649f8SChris Leech 86954b649f8SChris Leech /* Free queued packets for the per-CPU receive threads */ 87054b649f8SChris Leech fcoe_percpu_clean(lport); 87154b649f8SChris Leech 872a703e490SVasu Dev /* Detach from the scsi-ml */ 873af7f85d9SChris Leech fc_remove_host(lport->host); 874af7f85d9SChris Leech scsi_remove_host(lport->host); 875a703e490SVasu Dev 87680e736f8SYi Zou /* Destroy lport scsi_priv */ 87780e736f8SYi Zou fc_fcp_destroy(lport); 87880e736f8SYi Zou 879a703e490SVasu Dev /* There are no more rports or I/O, free the EM */ 880af7f85d9SChris Leech fc_exch_mgr_free(lport); 881a703e490SVasu Dev 882a703e490SVasu Dev /* Free memory used by statistical counters */ 883af7f85d9SChris Leech fc_lport_free_stats(lport); 884a703e490SVasu Dev 8852e70e241SChris Leech /* Release the Scsi_Host */ 886af7f85d9SChris Leech scsi_host_put(lport->host); 88715af974dSVasu Dev module_put(THIS_MODULE); 888a703e490SVasu Dev } 889a703e490SVasu Dev 8901875f27eSRobert Love /** 8911875f27eSRobert Love * fcoe_ddp_setup() - Call a LLD's ddp_setup through the net device 8921875f27eSRobert Love * @lport: The local port to setup DDP for 8931875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 8941875f27eSRobert Love * @sgl: The scatterlist describing this transfer 8951875f27eSRobert Love * @sgc: The number of sg items 896a703e490SVasu Dev * 8971875f27eSRobert Love * Returns: 0 if the DDP context was not configured 898a703e490SVasu Dev */ 8991875f27eSRobert Love static int fcoe_ddp_setup(struct fc_lport *lport, u16 xid, 900a703e490SVasu Dev struct scatterlist *sgl, unsigned int sgc) 901a703e490SVasu Dev { 9021875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 903a703e490SVasu Dev 9041875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_setup) 9051875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_setup(netdev, 9061875f27eSRobert Love xid, sgl, 9071875f27eSRobert Love sgc); 908a703e490SVasu Dev 909a703e490SVasu Dev return 0; 910a703e490SVasu Dev } 911a703e490SVasu Dev 912a703e490SVasu Dev /** 9131875f27eSRobert Love * fcoe_ddp_done() - Call a LLD's ddp_done through the net device 9141875f27eSRobert Love * @lport: The local port to complete DDP on 9151875f27eSRobert Love * @xid: The exchange ID for this DDP transfer 916a703e490SVasu Dev * 9171875f27eSRobert Love * Returns: the length of data that have been completed by DDP 9181875f27eSRobert Love */ 9191875f27eSRobert Love static int fcoe_ddp_done(struct fc_lport *lport, u16 xid) 9201875f27eSRobert Love { 9211875f27eSRobert Love struct net_device *netdev = fcoe_netdev(lport); 9221875f27eSRobert Love 9231875f27eSRobert Love if (netdev->netdev_ops->ndo_fcoe_ddp_done) 9241875f27eSRobert Love return netdev->netdev_ops->ndo_fcoe_ddp_done(netdev, xid); 9251875f27eSRobert Love return 0; 9261875f27eSRobert Love } 9271875f27eSRobert Love 9281875f27eSRobert Love /** 9291875f27eSRobert Love * fcoe_if_create() - Create a FCoE instance on an interface 9301875f27eSRobert Love * @fcoe: The FCoE interface to create a local port on 9311875f27eSRobert Love * @parent: The device pointer to be the parent in sysfs for the SCSI host 9321875f27eSRobert Love * @npiv: Indicates if the port is a vport or not 9331875f27eSRobert Love * 9341875f27eSRobert Love * Creates a fc_lport instance and a Scsi_Host instance and configure them. 935a703e490SVasu Dev * 936af7f85d9SChris Leech * Returns: The allocated fc_lport or an error pointer 937a703e490SVasu Dev */ 938030f4e00SChris Leech static struct fc_lport *fcoe_if_create(struct fcoe_interface *fcoe, 9399a05753bSChris Leech struct device *parent, int npiv) 940a703e490SVasu Dev { 9411875f27eSRobert Love struct net_device *netdev = fcoe->netdev; 942af7f85d9SChris Leech struct fc_lport *lport = NULL; 943014f5c3fSChris Leech struct fcoe_port *port; 9441875f27eSRobert Love int rc; 9459a05753bSChris Leech /* 9469a05753bSChris Leech * parent is only a vport if npiv is 1, 9479a05753bSChris Leech * but we'll only use vport in that case so go ahead and set it 9489a05753bSChris Leech */ 9499a05753bSChris Leech struct fc_vport *vport = dev_to_vport(parent); 950a703e490SVasu Dev 951d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Create Interface\n"); 952a703e490SVasu Dev 9539a05753bSChris Leech if (!npiv) { 95486221969SChris Leech lport = libfc_host_alloc(&fcoe_shost_template, 955014f5c3fSChris Leech sizeof(struct fcoe_port)); 9569a05753bSChris Leech } else { 9579a05753bSChris Leech lport = libfc_vport_create(vport, 9589a05753bSChris Leech sizeof(struct fcoe_port)); 9599a05753bSChris Leech } 96086221969SChris Leech if (!lport) { 961014f5c3fSChris Leech FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n"); 962014f5c3fSChris Leech rc = -ENOMEM; 963030f4e00SChris Leech goto out; 964014f5c3fSChris Leech } 965014f5c3fSChris Leech port = lport_priv(lport); 9662e70e241SChris Leech port->lport = lport; 967014f5c3fSChris Leech port->fcoe = fcoe; 9682e70e241SChris Leech INIT_WORK(&port->destroy_work, fcoe_destroy_work); 969a703e490SVasu Dev 9701875f27eSRobert Love /* configure a fc_lport including the exchange manager */ 971af7f85d9SChris Leech rc = fcoe_lport_config(lport); 972a703e490SVasu Dev if (rc) { 973d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure lport for the " 974d5488eb9SRobert Love "interface\n"); 975a703e490SVasu Dev goto out_host_put; 976a703e490SVasu Dev } 977a703e490SVasu Dev 9789a05753bSChris Leech if (npiv) { 9799f8f3aa6SChris Leech FCOE_NETDEV_DBG(netdev, "Setting vport names, " 9809f8f3aa6SChris Leech "%16.16llx %16.16llx\n", 9819a05753bSChris Leech vport->node_name, vport->port_name); 9829a05753bSChris Leech fc_set_wwnn(lport, vport->node_name); 9839a05753bSChris Leech fc_set_wwpn(lport, vport->port_name); 9849a05753bSChris Leech } 9859a05753bSChris Leech 986ab6b85c1SVasu Dev /* configure lport network properties */ 987af7f85d9SChris Leech rc = fcoe_netdev_config(lport, netdev); 988ab6b85c1SVasu Dev if (rc) { 989d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the " 990d5488eb9SRobert Love "interface\n"); 99154b649f8SChris Leech goto out_lp_destroy; 992ab6b85c1SVasu Dev } 99397c8389dSJoe Eykholt 994a703e490SVasu Dev /* configure lport scsi host properties */ 9958ba00a4bSVasu Dev rc = fcoe_shost_config(lport, parent); 996a703e490SVasu Dev if (rc) { 997d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure shost for the " 998d5488eb9SRobert Love "interface\n"); 99954b649f8SChris Leech goto out_lp_destroy; 1000a703e490SVasu Dev } 1001a703e490SVasu Dev 1002a703e490SVasu Dev /* Initialize the library */ 1003e10f8c66SJoe Eykholt rc = fcoe_libfc_config(lport, &fcoe->ctlr, &fcoe_libfc_fcn_templ, 1); 1004a703e490SVasu Dev if (rc) { 1005d5488eb9SRobert Love FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the " 1006d5488eb9SRobert Love "interface\n"); 1007a703e490SVasu Dev goto out_lp_destroy; 1008a703e490SVasu Dev } 1009a703e490SVasu Dev 10109a05753bSChris Leech if (!npiv) { 1011e8af4d43SVasu Dev /* 1012e8af4d43SVasu Dev * fcoe_em_alloc() and fcoe_hostlist_add() both 10139a05753bSChris Leech * need to be atomic with respect to other changes to the 10149a05753bSChris Leech * hostlist since fcoe_em_alloc() looks for an existing EM 1015e8af4d43SVasu Dev * instance on host list updated by fcoe_hostlist_add(). 1016c863df33SChris Leech * 10179a05753bSChris Leech * This is currently handled through the fcoe_config_mutex 10189a05753bSChris Leech * begin held. 1019e8af4d43SVasu Dev */ 1020c863df33SChris Leech 102196316099SVasu Dev /* lport exch manager allocation */ 1022af7f85d9SChris Leech rc = fcoe_em_config(lport); 102396316099SVasu Dev if (rc) { 10249a05753bSChris Leech FCOE_NETDEV_DBG(netdev, "Could not configure the EM " 10259a05753bSChris Leech "for the interface\n"); 102696316099SVasu Dev goto out_lp_destroy; 102796316099SVasu Dev } 10289a05753bSChris Leech } 102996316099SVasu Dev 1030030f4e00SChris Leech fcoe_interface_get(fcoe); 1031af7f85d9SChris Leech return lport; 1032a703e490SVasu Dev 1033a703e490SVasu Dev out_lp_destroy: 1034af7f85d9SChris Leech fc_exch_mgr_free(lport); 1035a703e490SVasu Dev out_host_put: 1036af7f85d9SChris Leech scsi_host_put(lport->host); 1037af7f85d9SChris Leech out: 1038af7f85d9SChris Leech return ERR_PTR(rc); 1039a703e490SVasu Dev } 1040a703e490SVasu Dev 1041a703e490SVasu Dev /** 10421875f27eSRobert Love * fcoe_if_init() - Initialization routine for fcoe.ko 10431875f27eSRobert Love * 10441875f27eSRobert Love * Attaches the SW FCoE transport to the FC transport 1045a703e490SVasu Dev * 1046a703e490SVasu Dev * Returns: 0 on success 1047a703e490SVasu Dev */ 1048a703e490SVasu Dev static int __init fcoe_if_init(void) 1049a703e490SVasu Dev { 1050a703e490SVasu Dev /* attach to scsi transport */ 1051e9084bb8SChris Leech fcoe_transport_template = fc_attach_transport(&fcoe_transport_function); 1052e9084bb8SChris Leech fcoe_vport_transport_template = 1053e9084bb8SChris Leech fc_attach_transport(&fcoe_vport_transport_function); 1054a703e490SVasu Dev 1055e9084bb8SChris Leech if (!fcoe_transport_template) { 1056d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); 1057a703e490SVasu Dev return -ENODEV; 1058a703e490SVasu Dev } 1059a703e490SVasu Dev 1060a703e490SVasu Dev return 0; 1061a703e490SVasu Dev } 1062a703e490SVasu Dev 1063a703e490SVasu Dev /** 10641875f27eSRobert Love * fcoe_if_exit() - Tear down fcoe.ko 10651875f27eSRobert Love * 10661875f27eSRobert Love * Detaches the SW FCoE transport from the FC transport 1067a703e490SVasu Dev * 1068a703e490SVasu Dev * Returns: 0 on success 1069a703e490SVasu Dev */ 1070a703e490SVasu Dev int __exit fcoe_if_exit(void) 1071a703e490SVasu Dev { 1072e9084bb8SChris Leech fc_release_transport(fcoe_transport_template); 1073e9084bb8SChris Leech fc_release_transport(fcoe_vport_transport_template); 1074e9084bb8SChris Leech fcoe_transport_template = NULL; 1075e9084bb8SChris Leech fcoe_vport_transport_template = NULL; 1076a703e490SVasu Dev return 0; 1077a703e490SVasu Dev } 1078a703e490SVasu Dev 1079a703e490SVasu Dev /** 10801875f27eSRobert Love * fcoe_percpu_thread_create() - Create a receive thread for an online CPU 10811875f27eSRobert Love * @cpu: The CPU index of the CPU to create a receive thread for 1082a703e490SVasu Dev */ 1083a703e490SVasu Dev static void fcoe_percpu_thread_create(unsigned int cpu) 1084a703e490SVasu Dev { 1085a703e490SVasu Dev struct fcoe_percpu_s *p; 1086a703e490SVasu Dev struct task_struct *thread; 1087a703e490SVasu Dev 1088a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1089a703e490SVasu Dev 1090a703e490SVasu Dev thread = kthread_create(fcoe_percpu_receive_thread, 1091a703e490SVasu Dev (void *)p, "fcoethread/%d", cpu); 1092a703e490SVasu Dev 1093e7a51997SJoe Eykholt if (likely(!IS_ERR(thread))) { 1094a703e490SVasu Dev kthread_bind(thread, cpu); 1095a703e490SVasu Dev wake_up_process(thread); 1096a703e490SVasu Dev 1097a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1098a703e490SVasu Dev p->thread = thread; 1099a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1100a703e490SVasu Dev } 1101a703e490SVasu Dev } 1102a703e490SVasu Dev 1103a703e490SVasu Dev /** 11041875f27eSRobert Love * fcoe_percpu_thread_destroy() - Remove the receive thread of a CPU 11051875f27eSRobert Love * @cpu: The CPU index of the CPU whose receive thread is to be destroyed 1106a703e490SVasu Dev * 1107a703e490SVasu Dev * Destroys a per-CPU Rx thread. Any pending skbs are moved to the 1108a703e490SVasu Dev * current CPU's Rx thread. If the thread being destroyed is bound to 1109a703e490SVasu Dev * the CPU processing this context the skbs will be freed. 1110a703e490SVasu Dev */ 1111a703e490SVasu Dev static void fcoe_percpu_thread_destroy(unsigned int cpu) 1112a703e490SVasu Dev { 1113a703e490SVasu Dev struct fcoe_percpu_s *p; 1114a703e490SVasu Dev struct task_struct *thread; 1115a703e490SVasu Dev struct page *crc_eof; 1116a703e490SVasu Dev struct sk_buff *skb; 1117a703e490SVasu Dev #ifdef CONFIG_SMP 1118a703e490SVasu Dev struct fcoe_percpu_s *p0; 1119f018b73aSJoe Eykholt unsigned targ_cpu = get_cpu(); 1120a703e490SVasu Dev #endif /* CONFIG_SMP */ 1121a703e490SVasu Dev 1122d5488eb9SRobert Love FCOE_DBG("Destroying receive thread for CPU %d\n", cpu); 1123a703e490SVasu Dev 1124a703e490SVasu Dev /* Prevent any new skbs from being queued for this CPU. */ 1125a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 1126a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1127a703e490SVasu Dev thread = p->thread; 1128a703e490SVasu Dev p->thread = NULL; 1129a703e490SVasu Dev crc_eof = p->crc_eof_page; 1130a703e490SVasu Dev p->crc_eof_page = NULL; 1131a703e490SVasu Dev p->crc_eof_offset = 0; 1132a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1133a703e490SVasu Dev 1134a703e490SVasu Dev #ifdef CONFIG_SMP 1135a703e490SVasu Dev /* 1136a703e490SVasu Dev * Don't bother moving the skb's if this context is running 1137a703e490SVasu Dev * on the same CPU that is having its thread destroyed. This 1138a703e490SVasu Dev * can easily happen when the module is removed. 1139a703e490SVasu Dev */ 1140a703e490SVasu Dev if (cpu != targ_cpu) { 1141a703e490SVasu Dev p0 = &per_cpu(fcoe_percpu, targ_cpu); 1142a703e490SVasu Dev spin_lock_bh(&p0->fcoe_rx_list.lock); 1143a703e490SVasu Dev if (p0->thread) { 1144d5488eb9SRobert Love FCOE_DBG("Moving frames from CPU %d to CPU %d\n", 1145a703e490SVasu Dev cpu, targ_cpu); 1146a703e490SVasu Dev 1147a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1148a703e490SVasu Dev __skb_queue_tail(&p0->fcoe_rx_list, skb); 1149a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1150a703e490SVasu Dev } else { 1151a703e490SVasu Dev /* 1152a703e490SVasu Dev * The targeted CPU is not initialized and cannot accept 1153a703e490SVasu Dev * new skbs. Unlock the targeted CPU and drop the skbs 1154a703e490SVasu Dev * on the CPU that is going offline. 1155a703e490SVasu Dev */ 1156a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1157a703e490SVasu Dev kfree_skb(skb); 1158a703e490SVasu Dev spin_unlock_bh(&p0->fcoe_rx_list.lock); 1159a703e490SVasu Dev } 1160a703e490SVasu Dev } else { 1161a703e490SVasu Dev /* 1162a703e490SVasu Dev * This scenario occurs when the module is being removed 1163a703e490SVasu Dev * and all threads are being destroyed. skbs will continue 1164a703e490SVasu Dev * to be shifted from the CPU thread that is being removed 1165a703e490SVasu Dev * to the CPU thread associated with the CPU that is processing 1166a703e490SVasu Dev * the module removal. Once there is only one CPU Rx thread it 1167a703e490SVasu Dev * will reach this case and we will drop all skbs and later 1168a703e490SVasu Dev * stop the thread. 1169a703e490SVasu Dev */ 1170a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1171a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1172a703e490SVasu Dev kfree_skb(skb); 1173a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1174a703e490SVasu Dev } 1175f018b73aSJoe Eykholt put_cpu(); 1176a703e490SVasu Dev #else 1177a703e490SVasu Dev /* 1178dd3fd72eSChris Leech * This a non-SMP scenario where the singular Rx thread is 1179a703e490SVasu Dev * being removed. Free all skbs and stop the thread. 1180a703e490SVasu Dev */ 1181a703e490SVasu Dev spin_lock_bh(&p->fcoe_rx_list.lock); 1182a703e490SVasu Dev while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) 1183a703e490SVasu Dev kfree_skb(skb); 1184a703e490SVasu Dev spin_unlock_bh(&p->fcoe_rx_list.lock); 1185a703e490SVasu Dev #endif 1186a703e490SVasu Dev 1187a703e490SVasu Dev if (thread) 1188a703e490SVasu Dev kthread_stop(thread); 1189a703e490SVasu Dev 1190a703e490SVasu Dev if (crc_eof) 1191a703e490SVasu Dev put_page(crc_eof); 1192a703e490SVasu Dev } 1193a703e490SVasu Dev 1194a703e490SVasu Dev /** 11951875f27eSRobert Love * fcoe_cpu_callback() - Handler for CPU hotplug events 11961875f27eSRobert Love * @nfb: The callback data block 11971875f27eSRobert Love * @action: The event triggering the callback 11981875f27eSRobert Love * @hcpu: The index of the CPU that the event is for 1199a703e490SVasu Dev * 12001875f27eSRobert Love * This creates or destroys per-CPU data for fcoe 1201a703e490SVasu Dev * 1202a703e490SVasu Dev * Returns NOTIFY_OK always. 1203a703e490SVasu Dev */ 1204a703e490SVasu Dev static int fcoe_cpu_callback(struct notifier_block *nfb, 1205a703e490SVasu Dev unsigned long action, void *hcpu) 1206a703e490SVasu Dev { 1207a703e490SVasu Dev unsigned cpu = (unsigned long)hcpu; 1208a703e490SVasu Dev 1209a703e490SVasu Dev switch (action) { 1210a703e490SVasu Dev case CPU_ONLINE: 1211a703e490SVasu Dev case CPU_ONLINE_FROZEN: 1212d5488eb9SRobert Love FCOE_DBG("CPU %x online: Create Rx thread\n", cpu); 1213a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 1214a703e490SVasu Dev break; 1215a703e490SVasu Dev case CPU_DEAD: 1216a703e490SVasu Dev case CPU_DEAD_FROZEN: 1217d5488eb9SRobert Love FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu); 1218a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 1219a703e490SVasu Dev break; 1220a703e490SVasu Dev default: 1221a703e490SVasu Dev break; 1222a703e490SVasu Dev } 1223a703e490SVasu Dev return NOTIFY_OK; 1224a703e490SVasu Dev } 1225a703e490SVasu Dev 1226a703e490SVasu Dev /** 12271875f27eSRobert Love * fcoe_rcv() - Receive packets from a net device 12281875f27eSRobert Love * @skb: The received packet 12291875f27eSRobert Love * @netdev: The net device that the packet was received on 12301875f27eSRobert Love * @ptype: The packet type context 12311875f27eSRobert Love * @olddev: The last device net device 1232a703e490SVasu Dev * 12331875f27eSRobert Love * This routine is called by NET_RX_SOFTIRQ. It receives a packet, builds a 12341875f27eSRobert Love * FC frame and passes the frame to libfc. 1235a703e490SVasu Dev * 1236a703e490SVasu Dev * Returns: 0 for success 1237a703e490SVasu Dev */ 12381875f27eSRobert Love int fcoe_rcv(struct sk_buff *skb, struct net_device *netdev, 1239a703e490SVasu Dev struct packet_type *ptype, struct net_device *olddev) 1240a703e490SVasu Dev { 12411875f27eSRobert Love struct fc_lport *lport; 1242a703e490SVasu Dev struct fcoe_rcv_info *fr; 1243259ad85dSChris Leech struct fcoe_interface *fcoe; 1244a703e490SVasu Dev struct fc_frame_header *fh; 1245a703e490SVasu Dev struct fcoe_percpu_s *fps; 1246519e5135SVasu Dev struct ethhdr *eh; 1247b2f0091fSVasu Dev unsigned int cpu; 1248a703e490SVasu Dev 1249259ad85dSChris Leech fcoe = container_of(ptype, struct fcoe_interface, fcoe_packet_type); 12501875f27eSRobert Love lport = fcoe->ctlr.lp; 12511875f27eSRobert Love if (unlikely(!lport)) { 12521875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "Cannot find hba structure"); 1253a703e490SVasu Dev goto err2; 1254a703e490SVasu Dev } 12551875f27eSRobert Love if (!lport->link_up) 125697c8389dSJoe Eykholt goto err2; 1257a703e490SVasu Dev 12581875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "skb_info: len:%d data_len:%d head:%p " 1259d5488eb9SRobert Love "data:%p tail:%p end:%p sum:%d dev:%s", 1260d5488eb9SRobert Love skb->len, skb->data_len, skb->head, skb->data, 1261d5488eb9SRobert Love skb_tail_pointer(skb), skb_end_pointer(skb), 1262d5488eb9SRobert Love skb->csum, skb->dev ? skb->dev->name : "<NULL>"); 1263a703e490SVasu Dev 1264519e5135SVasu Dev eh = eth_hdr(skb); 1265519e5135SVasu Dev 1266519e5135SVasu Dev if (is_fip_mode(&fcoe->ctlr) && 1267519e5135SVasu Dev compare_ether_addr(eh->h_source, fcoe->ctlr.dest_addr)) { 1268519e5135SVasu Dev FCOE_NETDEV_DBG(netdev, "wrong source mac address:%pM\n", 1269519e5135SVasu Dev eh->h_source); 1270a703e490SVasu Dev goto err; 1271a703e490SVasu Dev } 1272a703e490SVasu Dev 1273a703e490SVasu Dev /* 1274a703e490SVasu Dev * Check for minimum frame length, and make sure required FCoE 1275a703e490SVasu Dev * and FC headers are pulled into the linear data area. 1276a703e490SVasu Dev */ 1277a703e490SVasu Dev if (unlikely((skb->len < FCOE_MIN_FRAME) || 1278a703e490SVasu Dev !pskb_may_pull(skb, FCOE_HEADER_LEN))) 1279a703e490SVasu Dev goto err; 1280a703e490SVasu Dev 1281a703e490SVasu Dev skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); 1282a703e490SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 1283a703e490SVasu Dev 12840ee31cb5SRobert Love if (ntoh24(&eh->h_dest[3]) != ntoh24(fh->fh_d_id)) { 12850ee31cb5SRobert Love FCOE_NETDEV_DBG(netdev, "FC frame d_id mismatch with MAC:%pM\n", 12860ee31cb5SRobert Love eh->h_dest); 12870ee31cb5SRobert Love goto err; 12880ee31cb5SRobert Love } 12890ee31cb5SRobert Love 1290a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 12911875f27eSRobert Love fr->fr_dev = lport; 1292a703e490SVasu Dev fr->ptype = ptype; 1293a703e490SVasu Dev 1294a703e490SVasu Dev /* 1295b2f0091fSVasu Dev * In case the incoming frame's exchange is originated from 1296b2f0091fSVasu Dev * the initiator, then received frame's exchange id is ANDed 1297b2f0091fSVasu Dev * with fc_cpu_mask bits to get the same cpu on which exchange 1298b2f0091fSVasu Dev * was originated, otherwise just use the current cpu. 1299a703e490SVasu Dev */ 1300b2f0091fSVasu Dev if (ntoh24(fh->fh_f_ctl) & FC_FC_EX_CTX) 1301b2f0091fSVasu Dev cpu = ntohs(fh->fh_ox_id) & fc_cpu_mask; 1302b2f0091fSVasu Dev else 1303b2f0091fSVasu Dev cpu = smp_processor_id(); 1304a703e490SVasu Dev 1305a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1306a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1307a703e490SVasu Dev if (unlikely(!fps->thread)) { 1308a703e490SVasu Dev /* 1309a703e490SVasu Dev * The targeted CPU is not ready, let's target 1310a703e490SVasu Dev * the first CPU now. For non-SMP systems this 1311a703e490SVasu Dev * will check the same CPU twice. 1312a703e490SVasu Dev */ 13131875f27eSRobert Love FCOE_NETDEV_DBG(netdev, "CPU is online, but no receive thread " 1314d5488eb9SRobert Love "ready for incoming skb- using first online " 1315d5488eb9SRobert Love "CPU.\n"); 1316a703e490SVasu Dev 1317a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 13186957177fSRusty Russell cpu = cpumask_first(cpu_online_mask); 1319a703e490SVasu Dev fps = &per_cpu(fcoe_percpu, cpu); 1320a703e490SVasu Dev spin_lock_bh(&fps->fcoe_rx_list.lock); 1321a703e490SVasu Dev if (!fps->thread) { 1322a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1323a703e490SVasu Dev goto err; 1324a703e490SVasu Dev } 1325a703e490SVasu Dev } 1326a703e490SVasu Dev 1327a703e490SVasu Dev /* 1328a703e490SVasu Dev * We now have a valid CPU that we're targeting for 1329a703e490SVasu Dev * this skb. We also have this receive thread locked, 1330a703e490SVasu Dev * so we're free to queue skbs into it's queue. 1331a703e490SVasu Dev */ 1332859b7b64SChris Leech 1333859b7b64SChris Leech /* If this is a SCSI-FCP frame, and this is already executing on the 1334859b7b64SChris Leech * correct CPU, and the queue for this CPU is empty, then go ahead 1335859b7b64SChris Leech * and process the frame directly in the softirq context. 1336859b7b64SChris Leech * This lets us process completions without context switching from the 1337859b7b64SChris Leech * NET_RX softirq, to our receive processing thread, and then back to 1338859b7b64SChris Leech * BLOCK softirq context. 1339859b7b64SChris Leech */ 1340859b7b64SChris Leech if (fh->fh_type == FC_TYPE_FCP && 1341859b7b64SChris Leech cpu == smp_processor_id() && 1342859b7b64SChris Leech skb_queue_empty(&fps->fcoe_rx_list)) { 1343859b7b64SChris Leech spin_unlock_bh(&fps->fcoe_rx_list.lock); 1344859b7b64SChris Leech fcoe_recv_frame(skb); 1345859b7b64SChris Leech } else { 1346a703e490SVasu Dev __skb_queue_tail(&fps->fcoe_rx_list, skb); 1347a703e490SVasu Dev if (fps->fcoe_rx_list.qlen == 1) 1348a703e490SVasu Dev wake_up_process(fps->thread); 1349a703e490SVasu Dev spin_unlock_bh(&fps->fcoe_rx_list.lock); 1350859b7b64SChris Leech } 1351a703e490SVasu Dev 1352a703e490SVasu Dev return 0; 1353a703e490SVasu Dev err: 1354f018b73aSJoe Eykholt per_cpu_ptr(lport->dev_stats, get_cpu())->ErrorFrames++; 1355f018b73aSJoe Eykholt put_cpu(); 1356a703e490SVasu Dev err2: 1357a703e490SVasu Dev kfree_skb(skb); 1358a703e490SVasu Dev return -1; 1359a703e490SVasu Dev } 1360a703e490SVasu Dev 1361a703e490SVasu Dev /** 13621875f27eSRobert Love * fcoe_start_io() - Start FCoE I/O 13631875f27eSRobert Love * @skb: The packet to be transmitted 13641875f27eSRobert Love * 13651875f27eSRobert Love * This routine is called from the net device to start transmitting 13661875f27eSRobert Love * FCoE packets. 1367a703e490SVasu Dev * 1368a703e490SVasu Dev * Returns: 0 for success 1369a703e490SVasu Dev */ 1370a703e490SVasu Dev static inline int fcoe_start_io(struct sk_buff *skb) 1371a703e490SVasu Dev { 137218fa11efSChris Leech struct sk_buff *nskb; 1373a703e490SVasu Dev int rc; 1374a703e490SVasu Dev 137518fa11efSChris Leech nskb = skb_clone(skb, GFP_ATOMIC); 137618fa11efSChris Leech rc = dev_queue_xmit(nskb); 1377a703e490SVasu Dev if (rc != 0) 1378a703e490SVasu Dev return rc; 1379a703e490SVasu Dev kfree_skb(skb); 1380a703e490SVasu Dev return 0; 1381a703e490SVasu Dev } 1382a703e490SVasu Dev 1383a703e490SVasu Dev /** 13841875f27eSRobert Love * fcoe_get_paged_crc_eof() - Allocate a page to be used for the trailer CRC 13851875f27eSRobert Love * @skb: The packet to be transmitted 13861875f27eSRobert Love * @tlen: The total length of the trailer 13871875f27eSRobert Love * 13881875f27eSRobert Love * This routine allocates a page for frame trailers. The page is re-used if 13891875f27eSRobert Love * there is enough room left on it for the current trailer. If there isn't 13901875f27eSRobert Love * enough buffer left a new page is allocated for the trailer. Reference to 13911875f27eSRobert Love * the page from this function as well as the skbs using the page fragments 13921875f27eSRobert Love * ensure that the page is freed at the appropriate time. 1393a703e490SVasu Dev * 1394a703e490SVasu Dev * Returns: 0 for success 1395a703e490SVasu Dev */ 1396a703e490SVasu Dev static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen) 1397a703e490SVasu Dev { 1398a703e490SVasu Dev struct fcoe_percpu_s *fps; 1399a703e490SVasu Dev struct page *page; 1400a703e490SVasu Dev 1401a703e490SVasu Dev fps = &get_cpu_var(fcoe_percpu); 1402a703e490SVasu Dev page = fps->crc_eof_page; 1403a703e490SVasu Dev if (!page) { 1404a703e490SVasu Dev page = alloc_page(GFP_ATOMIC); 1405a703e490SVasu Dev if (!page) { 1406a703e490SVasu Dev put_cpu_var(fcoe_percpu); 1407a703e490SVasu Dev return -ENOMEM; 1408a703e490SVasu Dev } 1409a703e490SVasu Dev fps->crc_eof_page = page; 1410a703e490SVasu Dev fps->crc_eof_offset = 0; 1411a703e490SVasu Dev } 1412a703e490SVasu Dev 1413a703e490SVasu Dev get_page(page); 1414a703e490SVasu Dev skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page, 1415a703e490SVasu Dev fps->crc_eof_offset, tlen); 1416a703e490SVasu Dev skb->len += tlen; 1417a703e490SVasu Dev skb->data_len += tlen; 1418a703e490SVasu Dev skb->truesize += tlen; 1419a703e490SVasu Dev fps->crc_eof_offset += sizeof(struct fcoe_crc_eof); 1420a703e490SVasu Dev 1421a703e490SVasu Dev if (fps->crc_eof_offset >= PAGE_SIZE) { 1422a703e490SVasu Dev fps->crc_eof_page = NULL; 1423a703e490SVasu Dev fps->crc_eof_offset = 0; 1424a703e490SVasu Dev put_page(page); 1425a703e490SVasu Dev } 1426a703e490SVasu Dev put_cpu_var(fcoe_percpu); 1427a703e490SVasu Dev return 0; 1428a703e490SVasu Dev } 1429a703e490SVasu Dev 1430a703e490SVasu Dev /** 14311875f27eSRobert Love * fcoe_fc_crc() - Calculates the CRC for a given frame 14321875f27eSRobert Love * @fp: The frame to be checksumed 1433a703e490SVasu Dev * 14341875f27eSRobert Love * This uses crc32() routine to calculate the CRC for a frame 14351875f27eSRobert Love * 14361875f27eSRobert Love * Return: The 32 bit CRC value 1437a703e490SVasu Dev */ 1438a703e490SVasu Dev u32 fcoe_fc_crc(struct fc_frame *fp) 1439a703e490SVasu Dev { 1440a703e490SVasu Dev struct sk_buff *skb = fp_skb(fp); 1441a703e490SVasu Dev struct skb_frag_struct *frag; 1442a703e490SVasu Dev unsigned char *data; 1443a703e490SVasu Dev unsigned long off, len, clen; 1444a703e490SVasu Dev u32 crc; 1445a703e490SVasu Dev unsigned i; 1446a703e490SVasu Dev 1447a703e490SVasu Dev crc = crc32(~0, skb->data, skb_headlen(skb)); 1448a703e490SVasu Dev 1449a703e490SVasu Dev for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { 1450a703e490SVasu Dev frag = &skb_shinfo(skb)->frags[i]; 1451a703e490SVasu Dev off = frag->page_offset; 1452a703e490SVasu Dev len = frag->size; 1453a703e490SVasu Dev while (len > 0) { 1454a703e490SVasu Dev clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK)); 1455a703e490SVasu Dev data = kmap_atomic(frag->page + (off >> PAGE_SHIFT), 1456a703e490SVasu Dev KM_SKB_DATA_SOFTIRQ); 1457a703e490SVasu Dev crc = crc32(crc, data + (off & ~PAGE_MASK), clen); 1458a703e490SVasu Dev kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ); 1459a703e490SVasu Dev off += clen; 1460a703e490SVasu Dev len -= clen; 1461a703e490SVasu Dev } 1462a703e490SVasu Dev } 1463a703e490SVasu Dev return crc; 1464a703e490SVasu Dev } 1465a703e490SVasu Dev 1466a703e490SVasu Dev /** 14671875f27eSRobert Love * fcoe_xmit() - Transmit a FCoE frame 14681875f27eSRobert Love * @lport: The local port that the frame is to be transmitted for 14691875f27eSRobert Love * @fp: The frame to be transmitted 1470a703e490SVasu Dev * 1471a703e490SVasu Dev * Return: 0 for success 1472a703e490SVasu Dev */ 14731875f27eSRobert Love int fcoe_xmit(struct fc_lport *lport, struct fc_frame *fp) 1474a703e490SVasu Dev { 14754bb6b515SVasu Dev int wlen; 1476a703e490SVasu Dev u32 crc; 1477a703e490SVasu Dev struct ethhdr *eh; 1478a703e490SVasu Dev struct fcoe_crc_eof *cp; 1479a703e490SVasu Dev struct sk_buff *skb; 1480a703e490SVasu Dev struct fcoe_dev_stats *stats; 1481a703e490SVasu Dev struct fc_frame_header *fh; 1482a703e490SVasu Dev unsigned int hlen; /* header length implies the version */ 1483a703e490SVasu Dev unsigned int tlen; /* trailer length */ 1484a703e490SVasu Dev unsigned int elen; /* eth header, may include vlan */ 14851875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 14863fe9a0baSChris Leech struct fcoe_interface *fcoe = port->fcoe; 1487a703e490SVasu Dev u8 sof, eof; 1488a703e490SVasu Dev struct fcoe_hdr *hp; 1489a703e490SVasu Dev 1490a703e490SVasu Dev WARN_ON((fr_len(fp) % sizeof(u32)) != 0); 1491a703e490SVasu Dev 1492a703e490SVasu Dev fh = fc_frame_header_get(fp); 149397c8389dSJoe Eykholt skb = fp_skb(fp); 149497c8389dSJoe Eykholt wlen = skb->len / FCOE_WORD_TO_BYTE; 149597c8389dSJoe Eykholt 14961875f27eSRobert Love if (!lport->link_up) { 14973caf02eeSDan Carpenter kfree_skb(skb); 149897c8389dSJoe Eykholt return 0; 1499a703e490SVasu Dev } 1500a703e490SVasu Dev 15019860eeb4SJoe Eykholt if (unlikely(fh->fh_type == FC_TYPE_ELS) && 15021875f27eSRobert Love fcoe_ctlr_els_send(&fcoe->ctlr, lport, skb)) 150397c8389dSJoe Eykholt return 0; 150497c8389dSJoe Eykholt 1505a703e490SVasu Dev sof = fr_sof(fp); 1506a703e490SVasu Dev eof = fr_eof(fp); 1507a703e490SVasu Dev 15084e57e1cbSVasu Dev elen = sizeof(struct ethhdr); 1509a703e490SVasu Dev hlen = sizeof(struct fcoe_hdr); 1510a703e490SVasu Dev tlen = sizeof(struct fcoe_crc_eof); 1511a703e490SVasu Dev wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; 1512a703e490SVasu Dev 1513a703e490SVasu Dev /* crc offload */ 15141875f27eSRobert Love if (likely(lport->crc_offload)) { 1515a703e490SVasu Dev skb->ip_summed = CHECKSUM_PARTIAL; 1516a703e490SVasu Dev skb->csum_start = skb_headroom(skb); 1517a703e490SVasu Dev skb->csum_offset = skb->len; 1518a703e490SVasu Dev crc = 0; 1519a703e490SVasu Dev } else { 1520a703e490SVasu Dev skb->ip_summed = CHECKSUM_NONE; 1521a703e490SVasu Dev crc = fcoe_fc_crc(fp); 1522a703e490SVasu Dev } 1523a703e490SVasu Dev 1524014f5c3fSChris Leech /* copy port crc and eof to the skb buff */ 1525a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1526a703e490SVasu Dev skb_frag_t *frag; 1527a703e490SVasu Dev if (fcoe_get_paged_crc_eof(skb, tlen)) { 1528a703e490SVasu Dev kfree_skb(skb); 1529a703e490SVasu Dev return -ENOMEM; 1530a703e490SVasu Dev } 1531a703e490SVasu Dev frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; 1532a703e490SVasu Dev cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ) 1533a703e490SVasu Dev + frag->page_offset; 1534a703e490SVasu Dev } else { 1535a703e490SVasu Dev cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); 1536a703e490SVasu Dev } 1537a703e490SVasu Dev 1538a703e490SVasu Dev memset(cp, 0, sizeof(*cp)); 1539a703e490SVasu Dev cp->fcoe_eof = eof; 1540a703e490SVasu Dev cp->fcoe_crc32 = cpu_to_le32(~crc); 1541a703e490SVasu Dev 1542a703e490SVasu Dev if (skb_is_nonlinear(skb)) { 1543a703e490SVasu Dev kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ); 1544a703e490SVasu Dev cp = NULL; 1545a703e490SVasu Dev } 1546a703e490SVasu Dev 1547014f5c3fSChris Leech /* adjust skb network/transport offsets to match mac/fcoe/port */ 1548a703e490SVasu Dev skb_push(skb, elen + hlen); 1549a703e490SVasu Dev skb_reset_mac_header(skb); 1550a703e490SVasu Dev skb_reset_network_header(skb); 1551a703e490SVasu Dev skb->mac_len = elen; 1552a703e490SVasu Dev skb->protocol = htons(ETH_P_FCOE); 15533fe9a0baSChris Leech skb->dev = fcoe->netdev; 1554a703e490SVasu Dev 1555a703e490SVasu Dev /* fill up mac and fcoe headers */ 1556a703e490SVasu Dev eh = eth_hdr(skb); 1557a703e490SVasu Dev eh->h_proto = htons(ETH_P_FCOE); 15583fe9a0baSChris Leech memcpy(eh->h_dest, fcoe->ctlr.dest_addr, ETH_ALEN); 1559cd229e42SJoe Eykholt if (fcoe->ctlr.map_dest) 1560cd229e42SJoe Eykholt memcpy(eh->h_dest + 3, fh->fh_d_id, 3); 1561a703e490SVasu Dev 15623fe9a0baSChris Leech if (unlikely(fcoe->ctlr.flogi_oxid != FC_XID_UNKNOWN)) 15633fe9a0baSChris Leech memcpy(eh->h_source, fcoe->ctlr.ctl_src_addr, ETH_ALEN); 1564a703e490SVasu Dev else 156511b56188SChris Leech memcpy(eh->h_source, port->data_src_addr, ETH_ALEN); 1566a703e490SVasu Dev 1567a703e490SVasu Dev hp = (struct fcoe_hdr *)(eh + 1); 1568a703e490SVasu Dev memset(hp, 0, sizeof(*hp)); 1569a703e490SVasu Dev if (FC_FCOE_VER) 1570a703e490SVasu Dev FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); 1571a703e490SVasu Dev hp->fcoe_sof = sof; 1572a703e490SVasu Dev 1573a703e490SVasu Dev /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ 15741875f27eSRobert Love if (lport->seq_offload && fr_max_payload(fp)) { 1575a703e490SVasu Dev skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; 1576a703e490SVasu Dev skb_shinfo(skb)->gso_size = fr_max_payload(fp); 1577a703e490SVasu Dev } else { 1578a703e490SVasu Dev skb_shinfo(skb)->gso_type = 0; 1579a703e490SVasu Dev skb_shinfo(skb)->gso_size = 0; 1580a703e490SVasu Dev } 1581a703e490SVasu Dev /* update tx stats: regardless if LLD fails */ 1582f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1583a703e490SVasu Dev stats->TxFrames++; 1584a703e490SVasu Dev stats->TxWords += wlen; 1585f018b73aSJoe Eykholt put_cpu(); 1586a703e490SVasu Dev 1587a703e490SVasu Dev /* send down to lld */ 15881875f27eSRobert Love fr_dev(fp) = lport; 1589014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen) 15901875f27eSRobert Love fcoe_check_wait_queue(lport, skb); 15914bb6b515SVasu Dev else if (fcoe_start_io(skb)) 15921875f27eSRobert Love fcoe_check_wait_queue(lport, skb); 1593a703e490SVasu Dev 1594a703e490SVasu Dev return 0; 1595a703e490SVasu Dev } 1596a703e490SVasu Dev 1597a703e490SVasu Dev /** 15981875f27eSRobert Love * fcoe_percpu_flush_done() - Indicate per-CPU queue flush completion 15991875f27eSRobert Love * @skb: The completed skb (argument required by destructor) 1600e7a51997SJoe Eykholt */ 1601e7a51997SJoe Eykholt static void fcoe_percpu_flush_done(struct sk_buff *skb) 1602e7a51997SJoe Eykholt { 1603e7a51997SJoe Eykholt complete(&fcoe_flush_completion); 1604e7a51997SJoe Eykholt } 1605e7a51997SJoe Eykholt 1606e7a51997SJoe Eykholt /** 1607859b7b64SChris Leech * fcoe_recv_frame() - process a single received frame 1608859b7b64SChris Leech * @skb: frame to process 1609a703e490SVasu Dev */ 1610859b7b64SChris Leech static void fcoe_recv_frame(struct sk_buff *skb) 1611a703e490SVasu Dev { 1612a703e490SVasu Dev u32 fr_len; 16131875f27eSRobert Love struct fc_lport *lport; 1614a703e490SVasu Dev struct fcoe_rcv_info *fr; 1615a703e490SVasu Dev struct fcoe_dev_stats *stats; 1616a703e490SVasu Dev struct fc_frame_header *fh; 1617a703e490SVasu Dev struct fcoe_crc_eof crc_eof; 1618a703e490SVasu Dev struct fc_frame *fp; 1619014f5c3fSChris Leech struct fcoe_port *port; 1620a703e490SVasu Dev struct fcoe_hdr *hp; 1621a703e490SVasu Dev 1622a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 16231875f27eSRobert Love lport = fr->fr_dev; 16241875f27eSRobert Love if (unlikely(!lport)) { 1625e7a51997SJoe Eykholt if (skb->destructor != fcoe_percpu_flush_done) 1626e7a51997SJoe Eykholt FCOE_NETDEV_DBG(skb->dev, "NULL lport in skb"); 1627a703e490SVasu Dev kfree_skb(skb); 1628859b7b64SChris Leech return; 1629a703e490SVasu Dev } 1630a703e490SVasu Dev 1631d5488eb9SRobert Love FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d " 1632d5488eb9SRobert Love "head:%p data:%p tail:%p end:%p sum:%d dev:%s", 1633a703e490SVasu Dev skb->len, skb->data_len, 1634a703e490SVasu Dev skb->head, skb->data, skb_tail_pointer(skb), 1635a703e490SVasu Dev skb_end_pointer(skb), skb->csum, 1636a703e490SVasu Dev skb->dev ? skb->dev->name : "<NULL>"); 1637a703e490SVasu Dev 16381875f27eSRobert Love port = lport_priv(lport); 1639a703e490SVasu Dev if (skb_is_nonlinear(skb)) 1640a703e490SVasu Dev skb_linearize(skb); /* not ideal */ 1641a703e490SVasu Dev 1642a703e490SVasu Dev /* 1643a703e490SVasu Dev * Frame length checks and setting up the header pointers 1644a703e490SVasu Dev * was done in fcoe_rcv already. 1645a703e490SVasu Dev */ 1646a703e490SVasu Dev hp = (struct fcoe_hdr *) skb_network_header(skb); 1647a703e490SVasu Dev fh = (struct fc_frame_header *) skb_transport_header(skb); 1648a703e490SVasu Dev 1649f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1650a703e490SVasu Dev if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { 1651a703e490SVasu Dev if (stats->ErrorFrames < 5) 1652d5488eb9SRobert Love printk(KERN_WARNING "fcoe: FCoE version " 1653a703e490SVasu Dev "mismatch: The frame has " 1654a703e490SVasu Dev "version %x, but the " 1655a703e490SVasu Dev "initiator supports version " 1656a703e490SVasu Dev "%x\n", FC_FCOE_DECAPS_VER(hp), 1657a703e490SVasu Dev FC_FCOE_VER); 1658f018b73aSJoe Eykholt goto drop; 1659a703e490SVasu Dev } 1660a703e490SVasu Dev 1661a703e490SVasu Dev skb_pull(skb, sizeof(struct fcoe_hdr)); 1662a703e490SVasu Dev fr_len = skb->len - sizeof(struct fcoe_crc_eof); 1663a703e490SVasu Dev 1664a703e490SVasu Dev stats->RxFrames++; 1665a703e490SVasu Dev stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; 1666a703e490SVasu Dev 1667a703e490SVasu Dev fp = (struct fc_frame *)skb; 1668a703e490SVasu Dev fc_frame_init(fp); 16691875f27eSRobert Love fr_dev(fp) = lport; 1670a703e490SVasu Dev fr_sof(fp) = hp->fcoe_sof; 1671a703e490SVasu Dev 1672a703e490SVasu Dev /* Copy out the CRC and EOF trailer for access */ 1673f018b73aSJoe Eykholt if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) 1674f018b73aSJoe Eykholt goto drop; 1675a703e490SVasu Dev fr_eof(fp) = crc_eof.fcoe_eof; 1676a703e490SVasu Dev fr_crc(fp) = crc_eof.fcoe_crc32; 1677f018b73aSJoe Eykholt if (pskb_trim(skb, fr_len)) 1678f018b73aSJoe Eykholt goto drop; 1679a703e490SVasu Dev 1680a703e490SVasu Dev /* 1681a703e490SVasu Dev * We only check CRC if no offload is available and if it is 1682a703e490SVasu Dev * it's solicited data, in which case, the FCP layer would 1683a703e490SVasu Dev * check it during the copy. 1684a703e490SVasu Dev */ 16851875f27eSRobert Love if (lport->crc_offload && 16861875f27eSRobert Love skb->ip_summed == CHECKSUM_UNNECESSARY) 1687a703e490SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 1688a703e490SVasu Dev else 1689a703e490SVasu Dev fr_flags(fp) |= FCPHF_CRC_UNCHECKED; 1690a703e490SVasu Dev 1691a703e490SVasu Dev fh = fc_frame_header_get(fp); 1692f018b73aSJoe Eykholt if ((fh->fh_r_ctl != FC_RCTL_DD_SOL_DATA || 1693f018b73aSJoe Eykholt fh->fh_type != FC_TYPE_FCP) && 1694f018b73aSJoe Eykholt (fr_flags(fp) & FCPHF_CRC_UNCHECKED)) { 1695a703e490SVasu Dev if (le32_to_cpu(fr_crc(fp)) != 1696a703e490SVasu Dev ~crc32(~0, skb->data, fr_len)) { 1697d5488eb9SRobert Love if (stats->InvalidCRCCount < 5) 1698a703e490SVasu Dev printk(KERN_WARNING "fcoe: dropping " 1699a703e490SVasu Dev "frame with CRC error\n"); 1700a703e490SVasu Dev stats->InvalidCRCCount++; 1701f018b73aSJoe Eykholt goto drop; 1702a703e490SVasu Dev } 1703a703e490SVasu Dev fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; 1704a703e490SVasu Dev } 1705f018b73aSJoe Eykholt put_cpu(); 17061875f27eSRobert Love fc_exch_recv(lport, fp); 1707f018b73aSJoe Eykholt return; 1708f018b73aSJoe Eykholt 1709f018b73aSJoe Eykholt drop: 1710f018b73aSJoe Eykholt stats->ErrorFrames++; 1711f018b73aSJoe Eykholt put_cpu(); 1712f018b73aSJoe Eykholt kfree_skb(skb); 1713a703e490SVasu Dev } 1714859b7b64SChris Leech 1715859b7b64SChris Leech /** 1716859b7b64SChris Leech * fcoe_percpu_receive_thread() - The per-CPU packet receive thread 1717859b7b64SChris Leech * @arg: The per-CPU context 1718859b7b64SChris Leech * 1719859b7b64SChris Leech * Return: 0 for success 1720859b7b64SChris Leech */ 1721859b7b64SChris Leech int fcoe_percpu_receive_thread(void *arg) 1722859b7b64SChris Leech { 1723859b7b64SChris Leech struct fcoe_percpu_s *p = arg; 1724859b7b64SChris Leech struct sk_buff *skb; 1725859b7b64SChris Leech 1726859b7b64SChris Leech set_user_nice(current, -20); 1727859b7b64SChris Leech 1728859b7b64SChris Leech while (!kthread_should_stop()) { 1729859b7b64SChris Leech 1730859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1731859b7b64SChris Leech while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) { 1732859b7b64SChris Leech set_current_state(TASK_INTERRUPTIBLE); 1733859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1734859b7b64SChris Leech schedule(); 1735859b7b64SChris Leech set_current_state(TASK_RUNNING); 1736859b7b64SChris Leech if (kthread_should_stop()) 1737859b7b64SChris Leech return 0; 1738859b7b64SChris Leech spin_lock_bh(&p->fcoe_rx_list.lock); 1739859b7b64SChris Leech } 1740859b7b64SChris Leech spin_unlock_bh(&p->fcoe_rx_list.lock); 1741859b7b64SChris Leech fcoe_recv_frame(skb); 1742859b7b64SChris Leech } 1743a703e490SVasu Dev return 0; 1744a703e490SVasu Dev } 1745a703e490SVasu Dev 1746a703e490SVasu Dev /** 17471875f27eSRobert Love * fcoe_check_wait_queue() - Attempt to clear the transmit backlog 17481875f27eSRobert Love * @lport: The local port whose backlog is to be cleared 1749a703e490SVasu Dev * 17501875f27eSRobert Love * This empties the wait_queue, dequeues the head of the wait_queue queue 17511875f27eSRobert Love * and calls fcoe_start_io() for each packet. If all skb have been 17521875f27eSRobert Love * transmitted it returns the qlen. If an error occurs it restores 17531875f27eSRobert Love * wait_queue (to try again later) and returns -1. 1754a703e490SVasu Dev * 17551875f27eSRobert Love * The wait_queue is used when the skb transmit fails. The failed skb 17561875f27eSRobert Love * will go in the wait_queue which will be emptied by the timer function or 1757a703e490SVasu Dev * by the next skb transmit. 1758a703e490SVasu Dev */ 17591875f27eSRobert Love static void fcoe_check_wait_queue(struct fc_lport *lport, struct sk_buff *skb) 1760a703e490SVasu Dev { 17611875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 17624bb6b515SVasu Dev int rc; 1763a703e490SVasu Dev 1764014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 17654bb6b515SVasu Dev 17664bb6b515SVasu Dev if (skb) 1767014f5c3fSChris Leech __skb_queue_tail(&port->fcoe_pending_queue, skb); 17684bb6b515SVasu Dev 1769014f5c3fSChris Leech if (port->fcoe_pending_queue_active) 1770a703e490SVasu Dev goto out; 1771014f5c3fSChris Leech port->fcoe_pending_queue_active = 1; 1772a703e490SVasu Dev 1773014f5c3fSChris Leech while (port->fcoe_pending_queue.qlen) { 1774a703e490SVasu Dev /* keep qlen > 0 until fcoe_start_io succeeds */ 1775014f5c3fSChris Leech port->fcoe_pending_queue.qlen++; 1776014f5c3fSChris Leech skb = __skb_dequeue(&port->fcoe_pending_queue); 1777a703e490SVasu Dev 1778014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 1779a703e490SVasu Dev rc = fcoe_start_io(skb); 1780014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 1781a703e490SVasu Dev 1782a703e490SVasu Dev if (rc) { 1783014f5c3fSChris Leech __skb_queue_head(&port->fcoe_pending_queue, skb); 1784a703e490SVasu Dev /* undo temporary increment above */ 1785014f5c3fSChris Leech port->fcoe_pending_queue.qlen--; 1786a703e490SVasu Dev break; 1787a703e490SVasu Dev } 1788a703e490SVasu Dev /* undo temporary increment above */ 1789014f5c3fSChris Leech port->fcoe_pending_queue.qlen--; 1790a703e490SVasu Dev } 1791a703e490SVasu Dev 1792014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH) 17931875f27eSRobert Love lport->qfull = 0; 1794014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen && !timer_pending(&port->timer)) 1795014f5c3fSChris Leech mod_timer(&port->timer, jiffies + 2); 1796014f5c3fSChris Leech port->fcoe_pending_queue_active = 0; 1797a703e490SVasu Dev out: 1798014f5c3fSChris Leech if (port->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH) 17991875f27eSRobert Love lport->qfull = 1; 1800014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 18014bb6b515SVasu Dev return; 1802a703e490SVasu Dev } 1803a703e490SVasu Dev 1804a703e490SVasu Dev /** 18051875f27eSRobert Love * fcoe_dev_setup() - Setup the link change notification interface 1806a703e490SVasu Dev */ 1807b0d428adSRandy Dunlap static void fcoe_dev_setup(void) 1808a703e490SVasu Dev { 1809a703e490SVasu Dev register_netdevice_notifier(&fcoe_notifier); 1810a703e490SVasu Dev } 1811a703e490SVasu Dev 1812a703e490SVasu Dev /** 18131875f27eSRobert Love * fcoe_dev_cleanup() - Cleanup the link change notification interface 1814a703e490SVasu Dev */ 1815a703e490SVasu Dev static void fcoe_dev_cleanup(void) 1816a703e490SVasu Dev { 1817a703e490SVasu Dev unregister_netdevice_notifier(&fcoe_notifier); 1818a703e490SVasu Dev } 1819a703e490SVasu Dev 1820a703e490SVasu Dev /** 18211875f27eSRobert Love * fcoe_device_notification() - Handler for net device events 18221875f27eSRobert Love * @notifier: The context of the notification 18231875f27eSRobert Love * @event: The type of event 18241875f27eSRobert Love * @ptr: The net device that the event was on 1825a703e490SVasu Dev * 18261875f27eSRobert Love * This function is called by the Ethernet driver in case of link change event. 1827a703e490SVasu Dev * 1828a703e490SVasu Dev * Returns: 0 for success 1829a703e490SVasu Dev */ 1830a703e490SVasu Dev static int fcoe_device_notification(struct notifier_block *notifier, 1831a703e490SVasu Dev ulong event, void *ptr) 1832a703e490SVasu Dev { 18331875f27eSRobert Love struct fc_lport *lport = NULL; 18341d1b88dcSVasu Dev struct net_device *netdev = ptr; 1835014f5c3fSChris Leech struct fcoe_interface *fcoe; 18362e70e241SChris Leech struct fcoe_port *port; 1837a703e490SVasu Dev struct fcoe_dev_stats *stats; 183897c8389dSJoe Eykholt u32 link_possible = 1; 1839a703e490SVasu Dev u32 mfs; 1840a703e490SVasu Dev int rc = NOTIFY_OK; 1841a703e490SVasu Dev 1842014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 184325024989SChris Leech if (fcoe->netdev == netdev) { 18441875f27eSRobert Love lport = fcoe->ctlr.lp; 1845a703e490SVasu Dev break; 1846a703e490SVasu Dev } 1847a703e490SVasu Dev } 18481875f27eSRobert Love if (!lport) { 1849a703e490SVasu Dev rc = NOTIFY_DONE; 1850a703e490SVasu Dev goto out; 1851a703e490SVasu Dev } 1852a703e490SVasu Dev 1853a703e490SVasu Dev switch (event) { 1854a703e490SVasu Dev case NETDEV_DOWN: 1855a703e490SVasu Dev case NETDEV_GOING_DOWN: 185697c8389dSJoe Eykholt link_possible = 0; 1857a703e490SVasu Dev break; 1858a703e490SVasu Dev case NETDEV_UP: 1859a703e490SVasu Dev case NETDEV_CHANGE: 1860a703e490SVasu Dev break; 1861a703e490SVasu Dev case NETDEV_CHANGEMTU: 18627221d7e5SYi Zou if (netdev->features & NETIF_F_FCOE_MTU) 18637221d7e5SYi Zou break; 18641d1b88dcSVasu Dev mfs = netdev->mtu - (sizeof(struct fcoe_hdr) + 1865a703e490SVasu Dev sizeof(struct fcoe_crc_eof)); 1866a703e490SVasu Dev if (mfs >= FC_MIN_MAX_FRAME) 18671875f27eSRobert Love fc_set_mfs(lport, mfs); 1868a703e490SVasu Dev break; 1869a703e490SVasu Dev case NETDEV_REGISTER: 1870a703e490SVasu Dev break; 18712e70e241SChris Leech case NETDEV_UNREGISTER: 18722e70e241SChris Leech list_del(&fcoe->list); 18732e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 18742e70e241SChris Leech fcoe_interface_cleanup(fcoe); 18752e70e241SChris Leech schedule_work(&port->destroy_work); 18762e70e241SChris Leech goto out; 18772e70e241SChris Leech break; 187854a5b21dSYi Zou case NETDEV_FEAT_CHANGE: 187954a5b21dSYi Zou fcoe_netdev_features_change(lport, netdev); 188054a5b21dSYi Zou break; 1881a703e490SVasu Dev default: 18821d1b88dcSVasu Dev FCOE_NETDEV_DBG(netdev, "Unknown event %ld " 1883d5488eb9SRobert Love "from netdev netlink\n", event); 1884a703e490SVasu Dev } 18855e4f8fe7SRobert Love 18865e4f8fe7SRobert Love fcoe_link_speed_update(lport); 18875e4f8fe7SRobert Love 18881875f27eSRobert Love if (link_possible && !fcoe_link_ok(lport)) 18893fe9a0baSChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 18903fe9a0baSChris Leech else if (fcoe_ctlr_link_down(&fcoe->ctlr)) { 1891f018b73aSJoe Eykholt stats = per_cpu_ptr(lport->dev_stats, get_cpu()); 1892a703e490SVasu Dev stats->LinkFailureCount++; 1893f018b73aSJoe Eykholt put_cpu(); 18941875f27eSRobert Love fcoe_clean_pending_queue(lport); 1895a703e490SVasu Dev } 1896a703e490SVasu Dev out: 1897a703e490SVasu Dev return rc; 1898a703e490SVasu Dev } 1899a703e490SVasu Dev 1900a703e490SVasu Dev /** 19011875f27eSRobert Love * fcoe_if_to_netdev() - Parse a name buffer to get a net device 19021875f27eSRobert Love * @buffer: The name of the net device 1903a703e490SVasu Dev * 19041875f27eSRobert Love * Returns: NULL or a ptr to net_device 1905a703e490SVasu Dev */ 1906a703e490SVasu Dev static struct net_device *fcoe_if_to_netdev(const char *buffer) 1907a703e490SVasu Dev { 1908a703e490SVasu Dev char *cp; 1909a703e490SVasu Dev char ifname[IFNAMSIZ + 2]; 1910a703e490SVasu Dev 1911a703e490SVasu Dev if (buffer) { 1912a703e490SVasu Dev strlcpy(ifname, buffer, IFNAMSIZ); 1913a703e490SVasu Dev cp = ifname + strlen(ifname); 1914a703e490SVasu Dev while (--cp >= ifname && *cp == '\n') 1915a703e490SVasu Dev *cp = '\0'; 1916a703e490SVasu Dev return dev_get_by_name(&init_net, ifname); 1917a703e490SVasu Dev } 1918a703e490SVasu Dev return NULL; 1919a703e490SVasu Dev } 1920a703e490SVasu Dev 1921a703e490SVasu Dev /** 192255a66d3cSVasu Dev * fcoe_disable() - Disables a FCoE interface 192355a66d3cSVasu Dev * @buffer: The name of the Ethernet interface to be disabled 192455a66d3cSVasu Dev * @kp: The associated kernel parameter 192555a66d3cSVasu Dev * 192655a66d3cSVasu Dev * Called from sysfs. 192755a66d3cSVasu Dev * 192855a66d3cSVasu Dev * Returns: 0 for success 192955a66d3cSVasu Dev */ 193055a66d3cSVasu Dev static int fcoe_disable(const char *buffer, struct kernel_param *kp) 193155a66d3cSVasu Dev { 193255a66d3cSVasu Dev struct fcoe_interface *fcoe; 193355a66d3cSVasu Dev struct net_device *netdev; 193455a66d3cSVasu Dev int rc = 0; 193555a66d3cSVasu Dev 193655a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 193755a66d3cSVasu Dev #ifdef CONFIG_FCOE_MODULE 193855a66d3cSVasu Dev /* 193955a66d3cSVasu Dev * Make sure the module has been initialized, and is not about to be 194055a66d3cSVasu Dev * removed. Module paramter sysfs files are writable before the 194155a66d3cSVasu Dev * module_init function is called and after module_exit. 194255a66d3cSVasu Dev */ 194355a66d3cSVasu Dev if (THIS_MODULE->state != MODULE_STATE_LIVE) { 194455a66d3cSVasu Dev rc = -ENODEV; 194555a66d3cSVasu Dev goto out_nodev; 194655a66d3cSVasu Dev } 194755a66d3cSVasu Dev #endif 194855a66d3cSVasu Dev 194955a66d3cSVasu Dev netdev = fcoe_if_to_netdev(buffer); 195055a66d3cSVasu Dev if (!netdev) { 195155a66d3cSVasu Dev rc = -ENODEV; 195255a66d3cSVasu Dev goto out_nodev; 195355a66d3cSVasu Dev } 195455a66d3cSVasu Dev 195534ce27bcSVasu Dev if (!rtnl_trylock()) { 195634ce27bcSVasu Dev dev_put(netdev); 195734ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 195834ce27bcSVasu Dev return restart_syscall(); 195934ce27bcSVasu Dev } 196034ce27bcSVasu Dev 196155a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 196255a66d3cSVasu Dev rtnl_unlock(); 196355a66d3cSVasu Dev 19649ee50e48SChris Leech if (fcoe) { 19659ee50e48SChris Leech fcoe_ctlr_link_down(&fcoe->ctlr); 19669d4cbc05SVasu Dev fcoe_clean_pending_queue(fcoe->ctlr.lp); 19679ee50e48SChris Leech } else 196855a66d3cSVasu Dev rc = -ENODEV; 196955a66d3cSVasu Dev 197055a66d3cSVasu Dev dev_put(netdev); 197155a66d3cSVasu Dev out_nodev: 197255a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 197355a66d3cSVasu Dev return rc; 197455a66d3cSVasu Dev } 197555a66d3cSVasu Dev 197655a66d3cSVasu Dev /** 197755a66d3cSVasu Dev * fcoe_enable() - Enables a FCoE interface 197855a66d3cSVasu Dev * @buffer: The name of the Ethernet interface to be enabled 197955a66d3cSVasu Dev * @kp: The associated kernel parameter 198055a66d3cSVasu Dev * 198155a66d3cSVasu Dev * Called from sysfs. 198255a66d3cSVasu Dev * 198355a66d3cSVasu Dev * Returns: 0 for success 198455a66d3cSVasu Dev */ 198555a66d3cSVasu Dev static int fcoe_enable(const char *buffer, struct kernel_param *kp) 198655a66d3cSVasu Dev { 198755a66d3cSVasu Dev struct fcoe_interface *fcoe; 198855a66d3cSVasu Dev struct net_device *netdev; 198955a66d3cSVasu Dev int rc = 0; 199055a66d3cSVasu Dev 199155a66d3cSVasu Dev mutex_lock(&fcoe_config_mutex); 199255a66d3cSVasu Dev #ifdef CONFIG_FCOE_MODULE 199355a66d3cSVasu Dev /* 199455a66d3cSVasu Dev * Make sure the module has been initialized, and is not about to be 199555a66d3cSVasu Dev * removed. Module paramter sysfs files are writable before the 199655a66d3cSVasu Dev * module_init function is called and after module_exit. 199755a66d3cSVasu Dev */ 199855a66d3cSVasu Dev if (THIS_MODULE->state != MODULE_STATE_LIVE) { 199955a66d3cSVasu Dev rc = -ENODEV; 200055a66d3cSVasu Dev goto out_nodev; 200155a66d3cSVasu Dev } 200255a66d3cSVasu Dev #endif 200355a66d3cSVasu Dev 200455a66d3cSVasu Dev netdev = fcoe_if_to_netdev(buffer); 200555a66d3cSVasu Dev if (!netdev) { 200655a66d3cSVasu Dev rc = -ENODEV; 200755a66d3cSVasu Dev goto out_nodev; 200855a66d3cSVasu Dev } 200955a66d3cSVasu Dev 201034ce27bcSVasu Dev if (!rtnl_trylock()) { 201134ce27bcSVasu Dev dev_put(netdev); 201234ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 201334ce27bcSVasu Dev return restart_syscall(); 201434ce27bcSVasu Dev } 201534ce27bcSVasu Dev 201655a66d3cSVasu Dev fcoe = fcoe_hostlist_lookup_port(netdev); 201755a66d3cSVasu Dev rtnl_unlock(); 201855a66d3cSVasu Dev 20199d4cbc05SVasu Dev if (!fcoe) 202055a66d3cSVasu Dev rc = -ENODEV; 20219d4cbc05SVasu Dev else if (!fcoe_link_ok(fcoe->ctlr.lp)) 20229d4cbc05SVasu Dev fcoe_ctlr_link_up(&fcoe->ctlr); 202355a66d3cSVasu Dev 202455a66d3cSVasu Dev dev_put(netdev); 202555a66d3cSVasu Dev out_nodev: 202655a66d3cSVasu Dev mutex_unlock(&fcoe_config_mutex); 202755a66d3cSVasu Dev return rc; 202855a66d3cSVasu Dev } 202955a66d3cSVasu Dev 203055a66d3cSVasu Dev /** 20311875f27eSRobert Love * fcoe_destroy() - Destroy a FCoE interface 20321875f27eSRobert Love * @buffer: The name of the Ethernet interface to be destroyed 20331875f27eSRobert Love * @kp: The associated kernel parameter 20341875f27eSRobert Love * 20351875f27eSRobert Love * Called from sysfs. 2036a703e490SVasu Dev * 2037a703e490SVasu Dev * Returns: 0 for success 2038a703e490SVasu Dev */ 2039a703e490SVasu Dev static int fcoe_destroy(const char *buffer, struct kernel_param *kp) 2040a703e490SVasu Dev { 2041030f4e00SChris Leech struct fcoe_interface *fcoe; 20422e70e241SChris Leech struct net_device *netdev; 20438eca355fSMike Christie int rc = 0; 2044a703e490SVasu Dev 2045dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2046dfc1d0feSChris Leech #ifdef CONFIG_FCOE_MODULE 2047dfc1d0feSChris Leech /* 2048dfc1d0feSChris Leech * Make sure the module has been initialized, and is not about to be 2049dfc1d0feSChris Leech * removed. Module paramter sysfs files are writable before the 2050dfc1d0feSChris Leech * module_init function is called and after module_exit. 2051dfc1d0feSChris Leech */ 2052dfc1d0feSChris Leech if (THIS_MODULE->state != MODULE_STATE_LIVE) { 2053dfc1d0feSChris Leech rc = -ENODEV; 2054dfc1d0feSChris Leech goto out_nodev; 2055dfc1d0feSChris Leech } 2056dfc1d0feSChris Leech #endif 2057dfc1d0feSChris Leech 2058a703e490SVasu Dev netdev = fcoe_if_to_netdev(buffer); 2059a703e490SVasu Dev if (!netdev) { 2060a703e490SVasu Dev rc = -ENODEV; 2061a703e490SVasu Dev goto out_nodev; 2062a703e490SVasu Dev } 20632e70e241SChris Leech 206434ce27bcSVasu Dev if (!rtnl_trylock()) { 206534ce27bcSVasu Dev dev_put(netdev); 206634ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 206734ce27bcSVasu Dev return restart_syscall(); 206834ce27bcSVasu Dev } 206934ce27bcSVasu Dev 20702e70e241SChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 20712e70e241SChris Leech if (!fcoe) { 2072090eb6c4SChris Leech rtnl_unlock(); 2073a703e490SVasu Dev rc = -ENODEV; 2074a703e490SVasu Dev goto out_putdev; 2075a703e490SVasu Dev } 20762e70e241SChris Leech fcoe_interface_cleanup(fcoe); 207754a5b21dSYi Zou list_del(&fcoe->list); 207834ce27bcSVasu Dev /* RTNL mutex is dropped by fcoe_if_destroy */ 20792e70e241SChris Leech fcoe_if_destroy(fcoe->ctlr.lp); 20806409ea65SRob Love 2081a703e490SVasu Dev out_putdev: 2082a703e490SVasu Dev dev_put(netdev); 2083a703e490SVasu Dev out_nodev: 2084dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2085a703e490SVasu Dev return rc; 2086a703e490SVasu Dev } 2087a703e490SVasu Dev 20881875f27eSRobert Love /** 20891875f27eSRobert Love * fcoe_destroy_work() - Destroy a FCoE port in a deferred work context 20901875f27eSRobert Love * @work: Handle to the FCoE port to be destroyed 20911875f27eSRobert Love */ 20922e70e241SChris Leech static void fcoe_destroy_work(struct work_struct *work) 20932e70e241SChris Leech { 20942e70e241SChris Leech struct fcoe_port *port; 20952e70e241SChris Leech 20962e70e241SChris Leech port = container_of(work, struct fcoe_port, destroy_work); 20972e70e241SChris Leech mutex_lock(&fcoe_config_mutex); 209834ce27bcSVasu Dev rtnl_lock(); 209934ce27bcSVasu Dev /* RTNL mutex is dropped by fcoe_if_destroy */ 21002e70e241SChris Leech fcoe_if_destroy(port->lport); 21012e70e241SChris Leech mutex_unlock(&fcoe_config_mutex); 21022e70e241SChris Leech } 21032e70e241SChris Leech 2104a703e490SVasu Dev /** 21051875f27eSRobert Love * fcoe_create() - Create a fcoe interface 21061875f27eSRobert Love * @buffer: The name of the Ethernet interface to create on 21071875f27eSRobert Love * @kp: The associated kernel param 21081875f27eSRobert Love * 21091875f27eSRobert Love * Called from sysfs. 2110a703e490SVasu Dev * 2111a703e490SVasu Dev * Returns: 0 for success 2112a703e490SVasu Dev */ 2113a703e490SVasu Dev static int fcoe_create(const char *buffer, struct kernel_param *kp) 2114a703e490SVasu Dev { 21151dd454d9SJoe Eykholt enum fip_state fip_mode = (enum fip_state)(long)kp->arg; 2116a703e490SVasu Dev int rc; 2117030f4e00SChris Leech struct fcoe_interface *fcoe; 2118af7f85d9SChris Leech struct fc_lport *lport; 2119a703e490SVasu Dev struct net_device *netdev; 2120a703e490SVasu Dev 2121dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 212234ce27bcSVasu Dev 212334ce27bcSVasu Dev if (!rtnl_trylock()) { 212434ce27bcSVasu Dev mutex_unlock(&fcoe_config_mutex); 212534ce27bcSVasu Dev return restart_syscall(); 212634ce27bcSVasu Dev } 212734ce27bcSVasu Dev 2128dfc1d0feSChris Leech #ifdef CONFIG_FCOE_MODULE 2129dfc1d0feSChris Leech /* 2130dfc1d0feSChris Leech * Make sure the module has been initialized, and is not about to be 2131dfc1d0feSChris Leech * removed. Module paramter sysfs files are writable before the 2132dfc1d0feSChris Leech * module_init function is called and after module_exit. 2133dfc1d0feSChris Leech */ 2134dfc1d0feSChris Leech if (THIS_MODULE->state != MODULE_STATE_LIVE) { 2135dfc1d0feSChris Leech rc = -ENODEV; 2136721cafafSVasu Dev goto out_nomod; 2137dfc1d0feSChris Leech } 2138dfc1d0feSChris Leech #endif 2139dfc1d0feSChris Leech 21406409ea65SRob Love if (!try_module_get(THIS_MODULE)) { 21416409ea65SRob Love rc = -EINVAL; 21426409ea65SRob Love goto out_nomod; 21436409ea65SRob Love } 21446409ea65SRob Love 2145a703e490SVasu Dev netdev = fcoe_if_to_netdev(buffer); 2146a703e490SVasu Dev if (!netdev) { 2147a703e490SVasu Dev rc = -ENODEV; 2148a703e490SVasu Dev goto out_nodev; 2149a703e490SVasu Dev } 21502e70e241SChris Leech 2151a703e490SVasu Dev /* look for existing lport */ 2152a703e490SVasu Dev if (fcoe_hostlist_lookup(netdev)) { 2153a703e490SVasu Dev rc = -EEXIST; 2154a703e490SVasu Dev goto out_putdev; 2155a703e490SVasu Dev } 2156a703e490SVasu Dev 21571dd454d9SJoe Eykholt fcoe = fcoe_interface_create(netdev, fip_mode); 2158030f4e00SChris Leech if (!fcoe) { 2159030f4e00SChris Leech rc = -ENOMEM; 2160030f4e00SChris Leech goto out_putdev; 2161030f4e00SChris Leech } 2162030f4e00SChris Leech 21639a05753bSChris Leech lport = fcoe_if_create(fcoe, &netdev->dev, 0); 2164af7f85d9SChris Leech if (IS_ERR(lport)) { 2165d5488eb9SRobert Love printk(KERN_ERR "fcoe: Failed to create interface (%s)\n", 2166a703e490SVasu Dev netdev->name); 2167a703e490SVasu Dev rc = -EIO; 21682e70e241SChris Leech fcoe_interface_cleanup(fcoe); 2169030f4e00SChris Leech goto out_free; 2170a703e490SVasu Dev } 2171030f4e00SChris Leech 217254b649f8SChris Leech /* Make this the "master" N_Port */ 217354b649f8SChris Leech fcoe->ctlr.lp = lport; 2174030f4e00SChris Leech 2175c863df33SChris Leech /* add to lports list */ 2176c863df33SChris Leech fcoe_hostlist_add(lport); 2177c863df33SChris Leech 217854b649f8SChris Leech /* start FIP Discovery and FLOGI */ 217954b649f8SChris Leech lport->boot_time = jiffies; 218054b649f8SChris Leech fc_fabric_login(lport); 218154b649f8SChris Leech if (!fcoe_link_ok(lport)) 218254b649f8SChris Leech fcoe_ctlr_link_up(&fcoe->ctlr); 218354b649f8SChris Leech 218454b649f8SChris Leech /* 218554b649f8SChris Leech * Release from init in fcoe_interface_create(), on success lport 218654b649f8SChris Leech * should be holding a reference taken in fcoe_if_create(). 218754b649f8SChris Leech */ 2188030f4e00SChris Leech fcoe_interface_put(fcoe); 21896409ea65SRob Love dev_put(netdev); 21906409ea65SRob Love rtnl_unlock(); 21916409ea65SRob Love mutex_unlock(&fcoe_config_mutex); 21926409ea65SRob Love 21936409ea65SRob Love return 0; 21946409ea65SRob Love out_free: 21956409ea65SRob Love fcoe_interface_put(fcoe); 2196a703e490SVasu Dev out_putdev: 2197a703e490SVasu Dev dev_put(netdev); 2198a703e490SVasu Dev out_nodev: 21996409ea65SRob Love module_put(THIS_MODULE); 22006409ea65SRob Love out_nomod: 220134ce27bcSVasu Dev rtnl_unlock(); 2202dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2203a703e490SVasu Dev return rc; 2204a703e490SVasu Dev } 2205a703e490SVasu Dev 2206a703e490SVasu Dev /** 22075e4f8fe7SRobert Love * fcoe_link_speed_update() - Update the supported and actual link speeds 22085e4f8fe7SRobert Love * @lport: The local port to update speeds for 2209a703e490SVasu Dev * 22105e4f8fe7SRobert Love * Returns: 0 if the ethtool query was successful 22115e4f8fe7SRobert Love * -1 if the ethtool query failed 2212a703e490SVasu Dev */ 22135e4f8fe7SRobert Love int fcoe_link_speed_update(struct fc_lport *lport) 2214a703e490SVasu Dev { 22151875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 22161875f27eSRobert Love struct net_device *netdev = port->fcoe->netdev; 2217a703e490SVasu Dev struct ethtool_cmd ecmd = { ETHTOOL_GSET }; 2218a703e490SVasu Dev 22195e4f8fe7SRobert Love if (!dev_ethtool_get_settings(netdev, &ecmd)) { 22201875f27eSRobert Love lport->link_supported_speeds &= 2221a703e490SVasu Dev ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT); 2222a703e490SVasu Dev if (ecmd.supported & (SUPPORTED_1000baseT_Half | 2223a703e490SVasu Dev SUPPORTED_1000baseT_Full)) 22241875f27eSRobert Love lport->link_supported_speeds |= FC_PORTSPEED_1GBIT; 2225a703e490SVasu Dev if (ecmd.supported & SUPPORTED_10000baseT_Full) 22261875f27eSRobert Love lport->link_supported_speeds |= 2227a703e490SVasu Dev FC_PORTSPEED_10GBIT; 2228a703e490SVasu Dev if (ecmd.speed == SPEED_1000) 22291875f27eSRobert Love lport->link_speed = FC_PORTSPEED_1GBIT; 2230a703e490SVasu Dev if (ecmd.speed == SPEED_10000) 22311875f27eSRobert Love lport->link_speed = FC_PORTSPEED_10GBIT; 2232a703e490SVasu Dev 22332f718d64SYi Zou return 0; 22342f718d64SYi Zou } 22352f718d64SYi Zou return -1; 2236a703e490SVasu Dev } 2237a703e490SVasu Dev 2238a703e490SVasu Dev /** 22395e4f8fe7SRobert Love * fcoe_link_ok() - Check if the link is OK for a local port 22405e4f8fe7SRobert Love * @lport: The local port to check link on 22415e4f8fe7SRobert Love * 22425e4f8fe7SRobert Love * Returns: 0 if link is UP and OK, -1 if not 22435e4f8fe7SRobert Love * 22445e4f8fe7SRobert Love */ 22455e4f8fe7SRobert Love int fcoe_link_ok(struct fc_lport *lport) 22465e4f8fe7SRobert Love { 22475e4f8fe7SRobert Love struct fcoe_port *port = lport_priv(lport); 22485e4f8fe7SRobert Love struct net_device *netdev = port->fcoe->netdev; 22495e4f8fe7SRobert Love 22505e4f8fe7SRobert Love if (netif_oper_up(netdev)) 22515e4f8fe7SRobert Love return 0; 22525e4f8fe7SRobert Love return -1; 22535e4f8fe7SRobert Love } 22545e4f8fe7SRobert Love 22555e4f8fe7SRobert Love /** 22561875f27eSRobert Love * fcoe_percpu_clean() - Clear all pending skbs for an local port 22571875f27eSRobert Love * @lport: The local port whose skbs are to be cleared 2258e7a51997SJoe Eykholt * 2259e7a51997SJoe Eykholt * Must be called with fcoe_create_mutex held to single-thread completion. 2260e7a51997SJoe Eykholt * 2261e7a51997SJoe Eykholt * This flushes the pending skbs by adding a new skb to each queue and 2262e7a51997SJoe Eykholt * waiting until they are all freed. This assures us that not only are 2263e7a51997SJoe Eykholt * there no packets that will be handled by the lport, but also that any 2264e7a51997SJoe Eykholt * threads already handling packet have returned. 2265a703e490SVasu Dev */ 22661875f27eSRobert Love void fcoe_percpu_clean(struct fc_lport *lport) 2267a703e490SVasu Dev { 2268a703e490SVasu Dev struct fcoe_percpu_s *pp; 2269a703e490SVasu Dev struct fcoe_rcv_info *fr; 2270a703e490SVasu Dev struct sk_buff_head *list; 2271a703e490SVasu Dev struct sk_buff *skb, *next; 2272a703e490SVasu Dev struct sk_buff *head; 2273a703e490SVasu Dev unsigned int cpu; 2274a703e490SVasu Dev 2275a703e490SVasu Dev for_each_possible_cpu(cpu) { 2276a703e490SVasu Dev pp = &per_cpu(fcoe_percpu, cpu); 2277a703e490SVasu Dev spin_lock_bh(&pp->fcoe_rx_list.lock); 2278a703e490SVasu Dev list = &pp->fcoe_rx_list; 2279a703e490SVasu Dev head = list->next; 2280a703e490SVasu Dev for (skb = head; skb != (struct sk_buff *)list; 2281a703e490SVasu Dev skb = next) { 2282a703e490SVasu Dev next = skb->next; 2283a703e490SVasu Dev fr = fcoe_dev_from_skb(skb); 22841875f27eSRobert Love if (fr->fr_dev == lport) { 2285a703e490SVasu Dev __skb_unlink(skb, list); 2286a703e490SVasu Dev kfree_skb(skb); 2287a703e490SVasu Dev } 2288a703e490SVasu Dev } 2289e7a51997SJoe Eykholt 2290e7a51997SJoe Eykholt if (!pp->thread || !cpu_online(cpu)) { 2291a703e490SVasu Dev spin_unlock_bh(&pp->fcoe_rx_list.lock); 2292e7a51997SJoe Eykholt continue; 2293e7a51997SJoe Eykholt } 2294e7a51997SJoe Eykholt 2295e7a51997SJoe Eykholt skb = dev_alloc_skb(0); 2296e7a51997SJoe Eykholt if (!skb) { 2297e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2298e7a51997SJoe Eykholt continue; 2299e7a51997SJoe Eykholt } 2300e7a51997SJoe Eykholt skb->destructor = fcoe_percpu_flush_done; 2301e7a51997SJoe Eykholt 2302e7a51997SJoe Eykholt __skb_queue_tail(&pp->fcoe_rx_list, skb); 2303e7a51997SJoe Eykholt if (pp->fcoe_rx_list.qlen == 1) 2304e7a51997SJoe Eykholt wake_up_process(pp->thread); 2305e7a51997SJoe Eykholt spin_unlock_bh(&pp->fcoe_rx_list.lock); 2306e7a51997SJoe Eykholt 2307e7a51997SJoe Eykholt wait_for_completion(&fcoe_flush_completion); 2308a703e490SVasu Dev } 2309a703e490SVasu Dev } 2310a703e490SVasu Dev 2311a703e490SVasu Dev /** 2312a703e490SVasu Dev * fcoe_clean_pending_queue() - Dequeue a skb and free it 23131875f27eSRobert Love * @lport: The local port to dequeue a skb on 2314a703e490SVasu Dev */ 23151875f27eSRobert Love void fcoe_clean_pending_queue(struct fc_lport *lport) 2316a703e490SVasu Dev { 23171875f27eSRobert Love struct fcoe_port *port = lport_priv(lport); 2318a703e490SVasu Dev struct sk_buff *skb; 2319a703e490SVasu Dev 2320014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 2321014f5c3fSChris Leech while ((skb = __skb_dequeue(&port->fcoe_pending_queue)) != NULL) { 2322014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 2323a703e490SVasu Dev kfree_skb(skb); 2324014f5c3fSChris Leech spin_lock_bh(&port->fcoe_pending_queue.lock); 2325a703e490SVasu Dev } 2326014f5c3fSChris Leech spin_unlock_bh(&port->fcoe_pending_queue.lock); 2327a703e490SVasu Dev } 2328a703e490SVasu Dev 2329a703e490SVasu Dev /** 23301875f27eSRobert Love * fcoe_reset() - Reset a local port 23311875f27eSRobert Love * @shost: The SCSI host associated with the local port to be reset 2332a703e490SVasu Dev * 23331875f27eSRobert Love * Returns: Always 0 (return value required by FC transport template) 2334a703e490SVasu Dev */ 2335a703e490SVasu Dev int fcoe_reset(struct Scsi_Host *shost) 2336a703e490SVasu Dev { 2337a703e490SVasu Dev struct fc_lport *lport = shost_priv(shost); 2338a703e490SVasu Dev fc_lport_reset(lport); 2339a703e490SVasu Dev return 0; 2340a703e490SVasu Dev } 2341a703e490SVasu Dev 2342a703e490SVasu Dev /** 23431875f27eSRobert Love * fcoe_hostlist_lookup_port() - Find the FCoE interface associated with a net device 23441875f27eSRobert Love * @netdev: The net device used as a key 2345a703e490SVasu Dev * 23461875f27eSRobert Love * Locking: Must be called with the RNL mutex held. 23471875f27eSRobert Love * 23481875f27eSRobert Love * Returns: NULL or the FCoE interface 2349a703e490SVasu Dev */ 2350014f5c3fSChris Leech static struct fcoe_interface * 23511875f27eSRobert Love fcoe_hostlist_lookup_port(const struct net_device *netdev) 2352a703e490SVasu Dev { 2353014f5c3fSChris Leech struct fcoe_interface *fcoe; 2354a703e490SVasu Dev 2355014f5c3fSChris Leech list_for_each_entry(fcoe, &fcoe_hostlist, list) { 23561875f27eSRobert Love if (fcoe->netdev == netdev) 2357014f5c3fSChris Leech return fcoe; 2358a703e490SVasu Dev } 2359a703e490SVasu Dev return NULL; 2360a703e490SVasu Dev } 2361a703e490SVasu Dev 2362a703e490SVasu Dev /** 23631875f27eSRobert Love * fcoe_hostlist_lookup() - Find the local port associated with a 23641875f27eSRobert Love * given net device 23651875f27eSRobert Love * @netdev: The netdevice used as a key 2366a703e490SVasu Dev * 23671875f27eSRobert Love * Locking: Must be called with the RTNL mutex held 23681875f27eSRobert Love * 23691875f27eSRobert Love * Returns: NULL or the local port 2370a703e490SVasu Dev */ 2371090eb6c4SChris Leech static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev) 2372a703e490SVasu Dev { 2373014f5c3fSChris Leech struct fcoe_interface *fcoe; 2374a703e490SVasu Dev 2375014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(netdev); 23763fe9a0baSChris Leech return (fcoe) ? fcoe->ctlr.lp : NULL; 2377a703e490SVasu Dev } 2378a703e490SVasu Dev 2379a703e490SVasu Dev /** 23801875f27eSRobert Love * fcoe_hostlist_add() - Add the FCoE interface identified by a local 23811875f27eSRobert Love * port to the hostlist 23821875f27eSRobert Love * @lport: The local port that identifies the FCoE interface to be added 23831875f27eSRobert Love * 23841875f27eSRobert Love * Locking: must be called with the RTNL mutex held 2385a703e490SVasu Dev * 2386a703e490SVasu Dev * Returns: 0 for success 2387a703e490SVasu Dev */ 2388090eb6c4SChris Leech static int fcoe_hostlist_add(const struct fc_lport *lport) 2389a703e490SVasu Dev { 2390014f5c3fSChris Leech struct fcoe_interface *fcoe; 2391014f5c3fSChris Leech struct fcoe_port *port; 2392a703e490SVasu Dev 2393014f5c3fSChris Leech fcoe = fcoe_hostlist_lookup_port(fcoe_netdev(lport)); 2394014f5c3fSChris Leech if (!fcoe) { 2395014f5c3fSChris Leech port = lport_priv(lport); 2396014f5c3fSChris Leech fcoe = port->fcoe; 2397014f5c3fSChris Leech list_add_tail(&fcoe->list, &fcoe_hostlist); 2398a703e490SVasu Dev } 2399a703e490SVasu Dev return 0; 2400a703e490SVasu Dev } 2401a703e490SVasu Dev 2402a703e490SVasu Dev /** 24031875f27eSRobert Love * fcoe_init() - Initialize fcoe.ko 2404a703e490SVasu Dev * 24051875f27eSRobert Love * Returns: 0 on success, or a negative value on failure 2406a703e490SVasu Dev */ 2407a703e490SVasu Dev static int __init fcoe_init(void) 2408a703e490SVasu Dev { 24091875f27eSRobert Love struct fcoe_percpu_s *p; 2410a703e490SVasu Dev unsigned int cpu; 2411a703e490SVasu Dev int rc = 0; 2412a703e490SVasu Dev 2413dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2414dfc1d0feSChris Leech 2415a703e490SVasu Dev for_each_possible_cpu(cpu) { 2416a703e490SVasu Dev p = &per_cpu(fcoe_percpu, cpu); 2417a703e490SVasu Dev skb_queue_head_init(&p->fcoe_rx_list); 2418a703e490SVasu Dev } 2419a703e490SVasu Dev 2420a703e490SVasu Dev for_each_online_cpu(cpu) 2421a703e490SVasu Dev fcoe_percpu_thread_create(cpu); 2422a703e490SVasu Dev 2423a703e490SVasu Dev /* Initialize per CPU interrupt thread */ 2424a703e490SVasu Dev rc = register_hotcpu_notifier(&fcoe_cpu_notifier); 2425a703e490SVasu Dev if (rc) 2426a703e490SVasu Dev goto out_free; 2427a703e490SVasu Dev 2428a703e490SVasu Dev /* Setup link change notification */ 2429a703e490SVasu Dev fcoe_dev_setup(); 2430a703e490SVasu Dev 24315892c32fSChris Leech rc = fcoe_if_init(); 24325892c32fSChris Leech if (rc) 24335892c32fSChris Leech goto out_free; 2434a703e490SVasu Dev 2435dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2436a703e490SVasu Dev return 0; 2437a703e490SVasu Dev 2438a703e490SVasu Dev out_free: 2439a703e490SVasu Dev for_each_online_cpu(cpu) { 2440a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2441a703e490SVasu Dev } 2442dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 2443a703e490SVasu Dev return rc; 2444a703e490SVasu Dev } 2445a703e490SVasu Dev module_init(fcoe_init); 2446a703e490SVasu Dev 2447a703e490SVasu Dev /** 24481875f27eSRobert Love * fcoe_exit() - Clean up fcoe.ko 2449a703e490SVasu Dev * 24501875f27eSRobert Love * Returns: 0 on success or a negative value on failure 2451a703e490SVasu Dev */ 2452a703e490SVasu Dev static void __exit fcoe_exit(void) 2453a703e490SVasu Dev { 2454014f5c3fSChris Leech struct fcoe_interface *fcoe, *tmp; 24552e70e241SChris Leech struct fcoe_port *port; 24561875f27eSRobert Love unsigned int cpu; 2457a703e490SVasu Dev 2458dfc1d0feSChris Leech mutex_lock(&fcoe_config_mutex); 2459dfc1d0feSChris Leech 2460a703e490SVasu Dev fcoe_dev_cleanup(); 2461a703e490SVasu Dev 2462a703e490SVasu Dev /* releases the associated fcoe hosts */ 2463090eb6c4SChris Leech rtnl_lock(); 2464090eb6c4SChris Leech list_for_each_entry_safe(fcoe, tmp, &fcoe_hostlist, list) { 2465c863df33SChris Leech list_del(&fcoe->list); 24662e70e241SChris Leech port = lport_priv(fcoe->ctlr.lp); 24672e70e241SChris Leech fcoe_interface_cleanup(fcoe); 24682e70e241SChris Leech schedule_work(&port->destroy_work); 2469c863df33SChris Leech } 2470090eb6c4SChris Leech rtnl_unlock(); 2471a703e490SVasu Dev 2472a703e490SVasu Dev unregister_hotcpu_notifier(&fcoe_cpu_notifier); 2473a703e490SVasu Dev 2474014f5c3fSChris Leech for_each_online_cpu(cpu) 2475a703e490SVasu Dev fcoe_percpu_thread_destroy(cpu); 2476a703e490SVasu Dev 2477dfc1d0feSChris Leech mutex_unlock(&fcoe_config_mutex); 24782e70e241SChris Leech 24792e70e241SChris Leech /* flush any asyncronous interface destroys, 24802e70e241SChris Leech * this should happen after the netdev notifier is unregistered */ 24812e70e241SChris Leech flush_scheduled_work(); 24829a05753bSChris Leech /* That will flush out all the N_Ports on the hostlist, but now we 24839a05753bSChris Leech * may have NPIV VN_Ports scheduled for destruction */ 24849a05753bSChris Leech flush_scheduled_work(); 24852e70e241SChris Leech 24862e70e241SChris Leech /* detach from scsi transport 24872e70e241SChris Leech * must happen after all destroys are done, therefor after the flush */ 24882e70e241SChris Leech fcoe_if_exit(); 2489a703e490SVasu Dev } 2490a703e490SVasu Dev module_exit(fcoe_exit); 249111b56188SChris Leech 249211b56188SChris Leech /** 249311b56188SChris Leech * fcoe_flogi_resp() - FCoE specific FLOGI and FDISC response handler 249411b56188SChris Leech * @seq: active sequence in the FLOGI or FDISC exchange 249511b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 249611b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 249711b56188SChris Leech * 249865155b37SUwe Kleine-König * This handles MAC address management for FCoE, then passes control on to 249911b56188SChris Leech * the libfc FLOGI response handler. 250011b56188SChris Leech */ 250111b56188SChris Leech static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 250211b56188SChris Leech { 250311b56188SChris Leech struct fcoe_ctlr *fip = arg; 250411b56188SChris Leech struct fc_exch *exch = fc_seq_exch(seq); 250511b56188SChris Leech struct fc_lport *lport = exch->lp; 250611b56188SChris Leech u8 *mac; 250711b56188SChris Leech 250811b56188SChris Leech if (IS_ERR(fp)) 250911b56188SChris Leech goto done; 251011b56188SChris Leech 251111b56188SChris Leech mac = fr_cb(fp)->granted_mac; 251211b56188SChris Leech if (is_zero_ether_addr(mac)) { 251311b56188SChris Leech /* pre-FIP */ 2514386309ceSJoe Eykholt if (fcoe_ctlr_recv_flogi(fip, lport, fp)) { 251511b56188SChris Leech fc_frame_free(fp); 251611b56188SChris Leech return; 251711b56188SChris Leech } 251811b56188SChris Leech } 2519386309ceSJoe Eykholt fcoe_update_src_mac(lport, mac); 252011b56188SChris Leech done: 252111b56188SChris Leech fc_lport_flogi_resp(seq, fp, lport); 252211b56188SChris Leech } 252311b56188SChris Leech 252411b56188SChris Leech /** 252511b56188SChris Leech * fcoe_logo_resp() - FCoE specific LOGO response handler 252611b56188SChris Leech * @seq: active sequence in the LOGO exchange 252711b56188SChris Leech * @fp: response frame, or error encoded in a pointer (timeout) 252811b56188SChris Leech * @arg: pointer the the fcoe_ctlr structure 252911b56188SChris Leech * 253065155b37SUwe Kleine-König * This handles MAC address management for FCoE, then passes control on to 253111b56188SChris Leech * the libfc LOGO response handler. 253211b56188SChris Leech */ 253311b56188SChris Leech static void fcoe_logo_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg) 253411b56188SChris Leech { 2535386309ceSJoe Eykholt struct fc_lport *lport = arg; 253611b56188SChris Leech static u8 zero_mac[ETH_ALEN] = { 0 }; 253711b56188SChris Leech 253811b56188SChris Leech if (!IS_ERR(fp)) 2539386309ceSJoe Eykholt fcoe_update_src_mac(lport, zero_mac); 254011b56188SChris Leech fc_lport_logo_resp(seq, fp, lport); 254111b56188SChris Leech } 254211b56188SChris Leech 254311b56188SChris Leech /** 254411b56188SChris Leech * fcoe_elsct_send - FCoE specific ELS handler 254511b56188SChris Leech * 254611b56188SChris Leech * This does special case handling of FIP encapsualted ELS exchanges for FCoE, 254711b56188SChris Leech * using FCoE specific response handlers and passing the FIP controller as 254811b56188SChris Leech * the argument (the lport is still available from the exchange). 254911b56188SChris Leech * 255011b56188SChris Leech * Most of the work here is just handed off to the libfc routine. 255111b56188SChris Leech */ 25521875f27eSRobert Love static struct fc_seq *fcoe_elsct_send(struct fc_lport *lport, u32 did, 25531875f27eSRobert Love struct fc_frame *fp, unsigned int op, 25541875f27eSRobert Love void (*resp)(struct fc_seq *, 25551875f27eSRobert Love struct fc_frame *, 25561875f27eSRobert Love void *), 255711b56188SChris Leech void *arg, u32 timeout) 255811b56188SChris Leech { 255911b56188SChris Leech struct fcoe_port *port = lport_priv(lport); 256011b56188SChris Leech struct fcoe_interface *fcoe = port->fcoe; 256111b56188SChris Leech struct fcoe_ctlr *fip = &fcoe->ctlr; 256211b56188SChris Leech struct fc_frame_header *fh = fc_frame_header_get(fp); 256311b56188SChris Leech 256411b56188SChris Leech switch (op) { 256511b56188SChris Leech case ELS_FLOGI: 256611b56188SChris Leech case ELS_FDISC: 2567e10f8c66SJoe Eykholt if (lport->point_to_multipoint) 2568e10f8c66SJoe Eykholt break; 256911b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_flogi_resp, 257011b56188SChris Leech fip, timeout); 257111b56188SChris Leech case ELS_LOGO: 257211b56188SChris Leech /* only hook onto fabric logouts, not port logouts */ 257311b56188SChris Leech if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) 257411b56188SChris Leech break; 257511b56188SChris Leech return fc_elsct_send(lport, did, fp, op, fcoe_logo_resp, 2576386309ceSJoe Eykholt lport, timeout); 257711b56188SChris Leech } 257811b56188SChris Leech return fc_elsct_send(lport, did, fp, op, resp, arg, timeout); 257911b56188SChris Leech } 258011b56188SChris Leech 25819a05753bSChris Leech /** 25829a05753bSChris Leech * fcoe_vport_create() - create an fc_host/scsi_host for a vport 25839a05753bSChris Leech * @vport: fc_vport object to create a new fc_host for 25849a05753bSChris Leech * @disabled: start the new fc_host in a disabled state by default? 25859a05753bSChris Leech * 25869a05753bSChris Leech * Returns: 0 for success 25879a05753bSChris Leech */ 25889a05753bSChris Leech static int fcoe_vport_create(struct fc_vport *vport, bool disabled) 25899a05753bSChris Leech { 25909a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 25919a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 25929a05753bSChris Leech struct fcoe_port *port = lport_priv(n_port); 25939a05753bSChris Leech struct fcoe_interface *fcoe = port->fcoe; 25949a05753bSChris Leech struct net_device *netdev = fcoe->netdev; 25959a05753bSChris Leech struct fc_lport *vn_port; 25969a05753bSChris Leech 25979a05753bSChris Leech mutex_lock(&fcoe_config_mutex); 25989a05753bSChris Leech vn_port = fcoe_if_create(fcoe, &vport->dev, 1); 25999a05753bSChris Leech mutex_unlock(&fcoe_config_mutex); 26009a05753bSChris Leech 26019a05753bSChris Leech if (IS_ERR(vn_port)) { 26029a05753bSChris Leech printk(KERN_ERR "fcoe: fcoe_vport_create(%s) failed\n", 26039a05753bSChris Leech netdev->name); 26049a05753bSChris Leech return -EIO; 26059a05753bSChris Leech } 26069a05753bSChris Leech 26079a05753bSChris Leech if (disabled) { 26089a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 26099a05753bSChris Leech } else { 26109a05753bSChris Leech vn_port->boot_time = jiffies; 26119a05753bSChris Leech fc_fabric_login(vn_port); 26129a05753bSChris Leech fc_vport_setlink(vn_port); 26139a05753bSChris Leech } 26149a05753bSChris Leech return 0; 26159a05753bSChris Leech } 26169a05753bSChris Leech 26179a05753bSChris Leech /** 26189a05753bSChris Leech * fcoe_vport_destroy() - destroy the fc_host/scsi_host for a vport 26199a05753bSChris Leech * @vport: fc_vport object that is being destroyed 26209a05753bSChris Leech * 26219a05753bSChris Leech * Returns: 0 for success 26229a05753bSChris Leech */ 26239a05753bSChris Leech static int fcoe_vport_destroy(struct fc_vport *vport) 26249a05753bSChris Leech { 26259a05753bSChris Leech struct Scsi_Host *shost = vport_to_shost(vport); 26269a05753bSChris Leech struct fc_lport *n_port = shost_priv(shost); 26279a05753bSChris Leech struct fc_lport *vn_port = vport->dd_data; 26289a05753bSChris Leech struct fcoe_port *port = lport_priv(vn_port); 26299a05753bSChris Leech 26309a05753bSChris Leech mutex_lock(&n_port->lp_mutex); 26319a05753bSChris Leech list_del(&vn_port->list); 26329a05753bSChris Leech mutex_unlock(&n_port->lp_mutex); 26339a05753bSChris Leech schedule_work(&port->destroy_work); 26349a05753bSChris Leech return 0; 26359a05753bSChris Leech } 26369a05753bSChris Leech 26379a05753bSChris Leech /** 26389a05753bSChris Leech * fcoe_vport_disable() - change vport state 26399a05753bSChris Leech * @vport: vport to bring online/offline 26409a05753bSChris Leech * @disable: should the vport be disabled? 26419a05753bSChris Leech */ 26429a05753bSChris Leech static int fcoe_vport_disable(struct fc_vport *vport, bool disable) 26439a05753bSChris Leech { 26449a05753bSChris Leech struct fc_lport *lport = vport->dd_data; 26459a05753bSChris Leech 26469a05753bSChris Leech if (disable) { 26479a05753bSChris Leech fc_vport_set_state(vport, FC_VPORT_DISABLED); 26489a05753bSChris Leech fc_fabric_logoff(lport); 26499a05753bSChris Leech } else { 26509a05753bSChris Leech lport->boot_time = jiffies; 26519a05753bSChris Leech fc_fabric_login(lport); 26529a05753bSChris Leech fc_vport_setlink(lport); 26539a05753bSChris Leech } 26549a05753bSChris Leech 26559a05753bSChris Leech return 0; 26569a05753bSChris Leech } 26579a05753bSChris Leech 2658dc8596d3SChris Leech /** 2659dc8596d3SChris Leech * fcoe_vport_set_symbolic_name() - append vport string to symbolic name 2660dc8596d3SChris Leech * @vport: fc_vport with a new symbolic name string 2661dc8596d3SChris Leech * 2662dc8596d3SChris Leech * After generating a new symbolic name string, a new RSPN_ID request is 2663dc8596d3SChris Leech * sent to the name server. There is no response handler, so if it fails 2664dc8596d3SChris Leech * for some reason it will not be retried. 2665dc8596d3SChris Leech */ 2666dc8596d3SChris Leech static void fcoe_set_vport_symbolic_name(struct fc_vport *vport) 2667dc8596d3SChris Leech { 2668dc8596d3SChris Leech struct fc_lport *lport = vport->dd_data; 2669dc8596d3SChris Leech struct fc_frame *fp; 2670dc8596d3SChris Leech size_t len; 2671dc8596d3SChris Leech 2672dc8596d3SChris Leech snprintf(fc_host_symbolic_name(lport->host), FC_SYMBOLIC_NAME_SIZE, 2673dc8596d3SChris Leech "%s v%s over %s : %s", FCOE_NAME, FCOE_VERSION, 2674dc8596d3SChris Leech fcoe_netdev(lport)->name, vport->symbolic_name); 2675dc8596d3SChris Leech 2676dc8596d3SChris Leech if (lport->state != LPORT_ST_READY) 2677dc8596d3SChris Leech return; 2678dc8596d3SChris Leech 2679dc8596d3SChris Leech len = strnlen(fc_host_symbolic_name(lport->host), 255); 2680dc8596d3SChris Leech fp = fc_frame_alloc(lport, 2681dc8596d3SChris Leech sizeof(struct fc_ct_hdr) + 2682dc8596d3SChris Leech sizeof(struct fc_ns_rspn) + len); 2683dc8596d3SChris Leech if (!fp) 2684dc8596d3SChris Leech return; 2685dc8596d3SChris Leech lport->tt.elsct_send(lport, FC_FID_DIR_SERV, fp, FC_NS_RSPN_ID, 2686b94f8951SJoe Eykholt NULL, NULL, 3 * lport->r_a_tov); 2687dc8596d3SChris Leech } 2688b84056bfSYi Zou 2689b84056bfSYi Zou /** 2690b84056bfSYi Zou * fcoe_get_lesb() - Fill the FCoE Link Error Status Block 2691b84056bfSYi Zou * @lport: the local port 2692b84056bfSYi Zou * @fc_lesb: the link error status block 2693b84056bfSYi Zou */ 2694b84056bfSYi Zou static void fcoe_get_lesb(struct fc_lport *lport, 2695b84056bfSYi Zou struct fc_els_lesb *fc_lesb) 2696b84056bfSYi Zou { 2697b84056bfSYi Zou unsigned int cpu; 2698b84056bfSYi Zou u32 lfc, vlfc, mdac; 2699b84056bfSYi Zou struct fcoe_dev_stats *devst; 2700b84056bfSYi Zou struct fcoe_fc_els_lesb *lesb; 270128172739SEric Dumazet struct rtnl_link_stats64 temp; 2702b84056bfSYi Zou struct net_device *netdev = fcoe_netdev(lport); 2703b84056bfSYi Zou 2704b84056bfSYi Zou lfc = 0; 2705b84056bfSYi Zou vlfc = 0; 2706b84056bfSYi Zou mdac = 0; 2707b84056bfSYi Zou lesb = (struct fcoe_fc_els_lesb *)fc_lesb; 2708b84056bfSYi Zou memset(lesb, 0, sizeof(*lesb)); 2709b84056bfSYi Zou for_each_possible_cpu(cpu) { 2710b84056bfSYi Zou devst = per_cpu_ptr(lport->dev_stats, cpu); 2711b84056bfSYi Zou lfc += devst->LinkFailureCount; 2712b84056bfSYi Zou vlfc += devst->VLinkFailureCount; 2713b84056bfSYi Zou mdac += devst->MissDiscAdvCount; 2714b84056bfSYi Zou } 2715b84056bfSYi Zou lesb->lesb_link_fail = htonl(lfc); 2716b84056bfSYi Zou lesb->lesb_vlink_fail = htonl(vlfc); 2717b84056bfSYi Zou lesb->lesb_miss_fka = htonl(mdac); 271828172739SEric Dumazet lesb->lesb_fcs_error = htonl(dev_get_stats(netdev, &temp)->rx_crc_errors); 2719b84056bfSYi Zou } 27207d65b0dfSJoe Eykholt 27217d65b0dfSJoe Eykholt /** 27227d65b0dfSJoe Eykholt * fcoe_set_port_id() - Callback from libfc when Port_ID is set. 27237d65b0dfSJoe Eykholt * @lport: the local port 27247d65b0dfSJoe Eykholt * @port_id: the port ID 27257d65b0dfSJoe Eykholt * @fp: the received frame, if any, that caused the port_id to be set. 27267d65b0dfSJoe Eykholt * 27277d65b0dfSJoe Eykholt * This routine handles the case where we received a FLOGI and are 27287d65b0dfSJoe Eykholt * entering point-to-point mode. We need to call fcoe_ctlr_recv_flogi() 27297d65b0dfSJoe Eykholt * so it can set the non-mapped mode and gateway address. 27307d65b0dfSJoe Eykholt * 27317d65b0dfSJoe Eykholt * The FLOGI LS_ACC is handled by fcoe_flogi_resp(). 27327d65b0dfSJoe Eykholt */ 27337d65b0dfSJoe Eykholt static void fcoe_set_port_id(struct fc_lport *lport, 27347d65b0dfSJoe Eykholt u32 port_id, struct fc_frame *fp) 27357d65b0dfSJoe Eykholt { 27367d65b0dfSJoe Eykholt struct fcoe_port *port = lport_priv(lport); 27377d65b0dfSJoe Eykholt struct fcoe_interface *fcoe = port->fcoe; 27387d65b0dfSJoe Eykholt 27397d65b0dfSJoe Eykholt if (fp && fc_frame_payload_op(fp) == ELS_FLOGI) 27407d65b0dfSJoe Eykholt fcoe_ctlr_recv_flogi(&fcoe->ctlr, lport, fp); 27417d65b0dfSJoe Eykholt } 2742