Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2007 - 2008 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., |
| 15 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | * |
| 17 | * Maintained at www.Open-FCoE.org |
| 18 | */ |
| 19 | |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/version.h> |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 22 | #include <linux/spinlock.h> |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 23 | #include <linux/netdevice.h> |
| 24 | #include <linux/etherdevice.h> |
| 25 | #include <linux/ethtool.h> |
| 26 | #include <linux/if_ether.h> |
| 27 | #include <linux/if_vlan.h> |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 28 | #include <linux/crc32.h> |
| 29 | #include <linux/cpu.h> |
| 30 | #include <linux/fs.h> |
| 31 | #include <linux/sysfs.h> |
| 32 | #include <linux/ctype.h> |
| 33 | #include <scsi/scsi_tcq.h> |
| 34 | #include <scsi/scsicam.h> |
| 35 | #include <scsi/scsi_transport.h> |
| 36 | #include <scsi/scsi_transport_fc.h> |
| 37 | #include <net/rtnetlink.h> |
| 38 | |
| 39 | #include <scsi/fc/fc_encaps.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 40 | #include <scsi/fc/fc_fip.h> |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 41 | |
| 42 | #include <scsi/libfc.h> |
| 43 | #include <scsi/fc_frame.h> |
| 44 | #include <scsi/libfcoe.h> |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 45 | |
Vasu Dev | fdd7802 | 2009-03-17 11:42:24 -0700 | [diff] [blame] | 46 | #include "fcoe.h" |
| 47 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 48 | MODULE_AUTHOR("Open-FCoE.org"); |
| 49 | MODULE_DESCRIPTION("FCoE"); |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 50 | MODULE_LICENSE("GPL v2"); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 51 | |
| 52 | /* fcoe host list */ |
| 53 | LIST_HEAD(fcoe_hostlist); |
| 54 | DEFINE_RWLOCK(fcoe_hostlist_lock); |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 55 | DEFINE_PER_CPU(struct fcoe_percpu_s, fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 56 | |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 57 | /* Function Prototypes */ |
Vasu Dev | fdd7802 | 2009-03-17 11:42:24 -0700 | [diff] [blame] | 58 | static int fcoe_reset(struct Scsi_Host *shost); |
| 59 | static int fcoe_xmit(struct fc_lport *, struct fc_frame *); |
| 60 | static int fcoe_rcv(struct sk_buff *, struct net_device *, |
| 61 | struct packet_type *, struct net_device *); |
| 62 | static int fcoe_percpu_receive_thread(void *arg); |
| 63 | static void fcoe_clean_pending_queue(struct fc_lport *lp); |
| 64 | static void fcoe_percpu_clean(struct fc_lport *lp); |
| 65 | static int fcoe_link_ok(struct fc_lport *lp); |
| 66 | |
| 67 | static struct fc_lport *fcoe_hostlist_lookup(const struct net_device *); |
| 68 | static int fcoe_hostlist_add(const struct fc_lport *); |
| 69 | static int fcoe_hostlist_remove(const struct fc_lport *); |
| 70 | |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 71 | static void fcoe_check_wait_queue(struct fc_lport *, struct sk_buff *); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 72 | static int fcoe_device_notification(struct notifier_block *, ulong, void *); |
| 73 | static void fcoe_dev_setup(void); |
| 74 | static void fcoe_dev_cleanup(void); |
| 75 | |
| 76 | /* notification function from net device */ |
| 77 | static struct notifier_block fcoe_notifier = { |
| 78 | .notifier_call = fcoe_device_notification, |
| 79 | }; |
| 80 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 81 | static struct scsi_transport_template *scsi_transport_fcoe_sw; |
| 82 | |
| 83 | struct fc_function_template fcoe_transport_function = { |
| 84 | .show_host_node_name = 1, |
| 85 | .show_host_port_name = 1, |
| 86 | .show_host_supported_classes = 1, |
| 87 | .show_host_supported_fc4s = 1, |
| 88 | .show_host_active_fc4s = 1, |
| 89 | .show_host_maxframe_size = 1, |
| 90 | |
| 91 | .show_host_port_id = 1, |
| 92 | .show_host_supported_speeds = 1, |
| 93 | .get_host_speed = fc_get_host_speed, |
| 94 | .show_host_speed = 1, |
| 95 | .show_host_port_type = 1, |
| 96 | .get_host_port_state = fc_get_host_port_state, |
| 97 | .show_host_port_state = 1, |
| 98 | .show_host_symbolic_name = 1, |
| 99 | |
| 100 | .dd_fcrport_size = sizeof(struct fc_rport_libfc_priv), |
| 101 | .show_rport_maxframe_size = 1, |
| 102 | .show_rport_supported_classes = 1, |
| 103 | |
| 104 | .show_host_fabric_name = 1, |
| 105 | .show_starget_node_name = 1, |
| 106 | .show_starget_port_name = 1, |
| 107 | .show_starget_port_id = 1, |
| 108 | .set_rport_dev_loss_tmo = fc_set_rport_loss_tmo, |
| 109 | .show_rport_dev_loss_tmo = 1, |
| 110 | .get_fc_host_stats = fc_get_host_stats, |
| 111 | .issue_fc_host_lip = fcoe_reset, |
| 112 | |
| 113 | .terminate_rport_io = fc_rport_terminate_io, |
| 114 | }; |
| 115 | |
| 116 | static struct scsi_host_template fcoe_shost_template = { |
| 117 | .module = THIS_MODULE, |
| 118 | .name = "FCoE Driver", |
| 119 | .proc_name = FCOE_NAME, |
| 120 | .queuecommand = fc_queuecommand, |
| 121 | .eh_abort_handler = fc_eh_abort, |
| 122 | .eh_device_reset_handler = fc_eh_device_reset, |
| 123 | .eh_host_reset_handler = fc_eh_host_reset, |
| 124 | .slave_alloc = fc_slave_alloc, |
| 125 | .change_queue_depth = fc_change_queue_depth, |
| 126 | .change_queue_type = fc_change_queue_type, |
| 127 | .this_id = -1, |
| 128 | .cmd_per_lun = 32, |
| 129 | .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS, |
| 130 | .use_clustering = ENABLE_CLUSTERING, |
| 131 | .sg_tablesize = SG_ALL, |
| 132 | .max_sectors = 0xffff, |
| 133 | }; |
| 134 | |
| 135 | /** |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 136 | * fcoe_fip_recv - handle a received FIP frame. |
| 137 | * @skb: the receive skb |
| 138 | * @dev: associated &net_device |
| 139 | * @ptype: the &packet_type structure which was used to register this handler. |
| 140 | * @orig_dev: original receive &net_device, in case @dev is a bond. |
| 141 | * |
| 142 | * Returns: 0 for success |
| 143 | */ |
| 144 | static int fcoe_fip_recv(struct sk_buff *skb, struct net_device *dev, |
| 145 | struct packet_type *ptype, |
| 146 | struct net_device *orig_dev) |
| 147 | { |
| 148 | struct fcoe_softc *fc; |
| 149 | |
| 150 | fc = container_of(ptype, struct fcoe_softc, fip_packet_type); |
| 151 | fcoe_ctlr_recv(&fc->ctlr, skb); |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * fcoe_fip_send() - send an Ethernet-encapsulated FIP frame. |
| 157 | * @fip: FCoE controller. |
| 158 | * @skb: FIP Packet. |
| 159 | */ |
| 160 | static void fcoe_fip_send(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 161 | { |
| 162 | skb->dev = fcoe_from_ctlr(fip)->real_dev; |
| 163 | dev_queue_xmit(skb); |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * fcoe_update_src_mac() - Update Ethernet MAC filters. |
| 168 | * @fip: FCoE controller. |
| 169 | * @old: Unicast MAC address to delete if the MAC is non-zero. |
| 170 | * @new: Unicast MAC address to add. |
| 171 | * |
| 172 | * Remove any previously-set unicast MAC filter. |
| 173 | * Add secondary FCoE MAC address filter for our OUI. |
| 174 | */ |
| 175 | static void fcoe_update_src_mac(struct fcoe_ctlr *fip, u8 *old, u8 *new) |
| 176 | { |
| 177 | struct fcoe_softc *fc; |
| 178 | |
| 179 | fc = fcoe_from_ctlr(fip); |
| 180 | rtnl_lock(); |
| 181 | if (!is_zero_ether_addr(old)) |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 182 | dev_unicast_delete(fc->real_dev, old); |
| 183 | dev_unicast_add(fc->real_dev, new); |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 184 | rtnl_unlock(); |
| 185 | } |
| 186 | |
| 187 | /** |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 188 | * fcoe_lport_config() - sets up the fc_lport |
| 189 | * @lp: ptr to the fc_lport |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 190 | * |
| 191 | * Returns: 0 for success |
| 192 | */ |
| 193 | static int fcoe_lport_config(struct fc_lport *lp) |
| 194 | { |
| 195 | lp->link_up = 0; |
| 196 | lp->qfull = 0; |
| 197 | lp->max_retry_count = 3; |
Abhijeet Joglekar | a366695 | 2009-05-01 10:01:26 -0700 | [diff] [blame] | 198 | lp->max_rport_retry_count = 3; |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 199 | lp->e_d_tov = 2 * 1000; /* FC-FS default */ |
| 200 | lp->r_a_tov = 2 * 2 * 1000; |
| 201 | lp->service_params = (FCP_SPPF_INIT_FCN | FCP_SPPF_RD_XRDY_DIS | |
| 202 | FCP_SPPF_RETRY | FCP_SPPF_CONF_COMPL); |
| 203 | |
| 204 | fc_lport_init_stats(lp); |
| 205 | |
| 206 | /* lport fc_lport related configuration */ |
| 207 | fc_lport_config(lp); |
| 208 | |
| 209 | /* offload related configuration */ |
| 210 | lp->crc_offload = 0; |
| 211 | lp->seq_offload = 0; |
| 212 | lp->lro_enabled = 0; |
| 213 | lp->lro_xid = 0; |
| 214 | lp->lso_max = 0; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | /** |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 220 | * fcoe_netdev_cleanup() - clean up netdev configurations |
| 221 | * @fc: ptr to the fcoe_softc |
| 222 | */ |
| 223 | void fcoe_netdev_cleanup(struct fcoe_softc *fc) |
| 224 | { |
| 225 | u8 flogi_maddr[ETH_ALEN]; |
| 226 | |
| 227 | /* Don't listen for Ethernet packets anymore */ |
| 228 | dev_remove_pack(&fc->fcoe_packet_type); |
| 229 | dev_remove_pack(&fc->fip_packet_type); |
| 230 | |
| 231 | /* Delete secondary MAC addresses */ |
| 232 | rtnl_lock(); |
| 233 | memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 234 | dev_unicast_delete(fc->real_dev, flogi_maddr); |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 235 | if (!is_zero_ether_addr(fc->ctlr.data_src_addr)) |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 236 | dev_unicast_delete(fc->real_dev, fc->ctlr.data_src_addr); |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 237 | if (fc->ctlr.spma) |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 238 | dev_unicast_delete(fc->real_dev, fc->ctlr.ctl_src_addr); |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 239 | dev_mc_delete(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0); |
| 240 | rtnl_unlock(); |
| 241 | } |
| 242 | |
| 243 | /** |
Vasu Dev | 1047f22 | 2009-05-06 10:52:40 -0700 | [diff] [blame] | 244 | * fcoe_queue_timer() - fcoe queue timer |
| 245 | * @lp: the fc_lport pointer |
| 246 | * |
| 247 | * Calls fcoe_check_wait_queue on timeout |
| 248 | * |
| 249 | */ |
| 250 | static void fcoe_queue_timer(ulong lp) |
| 251 | { |
| 252 | fcoe_check_wait_queue((struct fc_lport *)lp, NULL); |
| 253 | } |
| 254 | |
| 255 | /** |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 256 | * fcoe_netdev_config() - Set up netdev for SW FCoE |
| 257 | * @lp : ptr to the fc_lport |
| 258 | * @netdev : ptr to the associated netdevice struct |
| 259 | * |
| 260 | * Must be called after fcoe_lport_config() as it will use lport mutex |
| 261 | * |
| 262 | * Returns : 0 for success |
| 263 | */ |
| 264 | static int fcoe_netdev_config(struct fc_lport *lp, struct net_device *netdev) |
| 265 | { |
| 266 | u32 mfs; |
| 267 | u64 wwnn, wwpn; |
| 268 | struct fcoe_softc *fc; |
| 269 | u8 flogi_maddr[ETH_ALEN]; |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 270 | struct netdev_hw_addr *ha; |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 271 | |
| 272 | /* Setup lport private data to point to fcoe softc */ |
| 273 | fc = lport_priv(lp); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 274 | fc->ctlr.lp = lp; |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 275 | fc->real_dev = netdev; |
| 276 | fc->phys_dev = netdev; |
| 277 | |
| 278 | /* Require support for get_pauseparam ethtool op. */ |
| 279 | if (netdev->priv_flags & IFF_802_1Q_VLAN) |
| 280 | fc->phys_dev = vlan_dev_real_dev(netdev); |
| 281 | |
| 282 | /* Do not support for bonding device */ |
| 283 | if ((fc->real_dev->priv_flags & IFF_MASTER_ALB) || |
| 284 | (fc->real_dev->priv_flags & IFF_SLAVE_INACTIVE) || |
| 285 | (fc->real_dev->priv_flags & IFF_MASTER_8023AD)) { |
| 286 | return -EOPNOTSUPP; |
| 287 | } |
| 288 | |
| 289 | /* |
| 290 | * Determine max frame size based on underlying device and optional |
| 291 | * user-configured limit. If the MFS is too low, fcoe_link_ok() |
| 292 | * will return 0, so do this first. |
| 293 | */ |
| 294 | mfs = fc->real_dev->mtu - (sizeof(struct fcoe_hdr) + |
| 295 | sizeof(struct fcoe_crc_eof)); |
| 296 | if (fc_set_mfs(lp, mfs)) |
| 297 | return -EINVAL; |
| 298 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 299 | /* offload features support */ |
| 300 | if (fc->real_dev->features & NETIF_F_SG) |
| 301 | lp->sg_supp = 1; |
| 302 | |
| 303 | #ifdef NETIF_F_FCOE_CRC |
| 304 | if (netdev->features & NETIF_F_FCOE_CRC) { |
| 305 | lp->crc_offload = 1; |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 306 | FCOE_NETDEV_DBG(netdev, "Supports FCCRC offload\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 307 | } |
| 308 | #endif |
| 309 | #ifdef NETIF_F_FSO |
| 310 | if (netdev->features & NETIF_F_FSO) { |
| 311 | lp->seq_offload = 1; |
| 312 | lp->lso_max = netdev->gso_max_size; |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 313 | FCOE_NETDEV_DBG(netdev, "Supports LSO for max len 0x%x\n", |
| 314 | lp->lso_max); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 315 | } |
| 316 | #endif |
| 317 | if (netdev->fcoe_ddp_xid) { |
| 318 | lp->lro_enabled = 1; |
| 319 | lp->lro_xid = netdev->fcoe_ddp_xid; |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 320 | FCOE_NETDEV_DBG(netdev, "Supports LRO for max xid 0x%x\n", |
| 321 | lp->lro_xid); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 322 | } |
| 323 | skb_queue_head_init(&fc->fcoe_pending_queue); |
| 324 | fc->fcoe_pending_queue_active = 0; |
Vasu Dev | 1047f22 | 2009-05-06 10:52:40 -0700 | [diff] [blame] | 325 | setup_timer(&fc->timer, fcoe_queue_timer, (unsigned long)lp); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 326 | |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 327 | /* look for SAN MAC address, if multiple SAN MACs exist, only |
| 328 | * use the first one for SPMA */ |
| 329 | rcu_read_lock(); |
| 330 | for_each_dev_addr(netdev, ha) { |
| 331 | if ((ha->type == NETDEV_HW_ADDR_T_SAN) && |
Yi Zou | 7a7f0c7 | 2009-07-29 17:03:50 -0700 | [diff] [blame] | 332 | (is_valid_ether_addr(ha->addr))) { |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 333 | memcpy(fc->ctlr.ctl_src_addr, ha->addr, ETH_ALEN); |
| 334 | fc->ctlr.spma = 1; |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | rcu_read_unlock(); |
| 339 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 340 | /* setup Source Mac Address */ |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 341 | if (!fc->ctlr.spma) |
| 342 | memcpy(fc->ctlr.ctl_src_addr, fc->real_dev->dev_addr, |
| 343 | fc->real_dev->addr_len); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 344 | |
| 345 | wwnn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 1, 0); |
| 346 | fc_set_wwnn(lp, wwnn); |
| 347 | /* XXX - 3rd arg needs to be vlan id */ |
| 348 | wwpn = fcoe_wwn_from_mac(fc->real_dev->dev_addr, 2, 0); |
| 349 | fc_set_wwpn(lp, wwpn); |
| 350 | |
| 351 | /* |
| 352 | * Add FCoE MAC address as second unicast MAC address |
| 353 | * or enter promiscuous mode if not capable of listening |
| 354 | * for multiple unicast MACs. |
| 355 | */ |
| 356 | rtnl_lock(); |
| 357 | memcpy(flogi_maddr, (u8[6]) FC_FCOE_FLOGI_MAC, ETH_ALEN); |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 358 | dev_unicast_add(fc->real_dev, flogi_maddr); |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 359 | if (fc->ctlr.spma) |
Jiri Pirko | ccffad25 | 2009-05-22 23:22:17 +0000 | [diff] [blame] | 360 | dev_unicast_add(fc->real_dev, fc->ctlr.ctl_src_addr); |
Joe Eykholt | 6401bdc | 2009-04-21 16:27:46 -0700 | [diff] [blame] | 361 | dev_mc_add(fc->real_dev, FIP_ALL_ENODE_MACS, ETH_ALEN, 0); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 362 | rtnl_unlock(); |
| 363 | |
| 364 | /* |
| 365 | * setup the receive function from ethernet driver |
| 366 | * on the ethertype for the given device |
| 367 | */ |
| 368 | fc->fcoe_packet_type.func = fcoe_rcv; |
| 369 | fc->fcoe_packet_type.type = __constant_htons(ETH_P_FCOE); |
| 370 | fc->fcoe_packet_type.dev = fc->real_dev; |
| 371 | dev_add_pack(&fc->fcoe_packet_type); |
| 372 | |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 373 | fc->fip_packet_type.func = fcoe_fip_recv; |
| 374 | fc->fip_packet_type.type = htons(ETH_P_FIP); |
| 375 | fc->fip_packet_type.dev = fc->real_dev; |
| 376 | dev_add_pack(&fc->fip_packet_type); |
| 377 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * fcoe_shost_config() - Sets up fc_lport->host |
| 383 | * @lp : ptr to the fc_lport |
| 384 | * @shost : ptr to the associated scsi host |
| 385 | * @dev : device associated to scsi host |
| 386 | * |
| 387 | * Must be called after fcoe_lport_config() and fcoe_netdev_config() |
| 388 | * |
| 389 | * Returns : 0 for success |
| 390 | */ |
| 391 | static int fcoe_shost_config(struct fc_lport *lp, struct Scsi_Host *shost, |
| 392 | struct device *dev) |
| 393 | { |
| 394 | int rc = 0; |
| 395 | |
| 396 | /* lport scsi host config */ |
| 397 | lp->host = shost; |
| 398 | |
| 399 | lp->host->max_lun = FCOE_MAX_LUN; |
| 400 | lp->host->max_id = FCOE_MAX_FCP_TARGET; |
| 401 | lp->host->max_channel = 0; |
| 402 | lp->host->transportt = scsi_transport_fcoe_sw; |
| 403 | |
| 404 | /* add the new host to the SCSI-ml */ |
| 405 | rc = scsi_add_host(lp->host, dev); |
| 406 | if (rc) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 407 | FCOE_NETDEV_DBG(fcoe_netdev(lp), "fcoe_shost_config: " |
| 408 | "error on scsi_add_host\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 409 | return rc; |
| 410 | } |
| 411 | sprintf(fc_host_symbolic_name(lp->host), "%s v%s over %s", |
| 412 | FCOE_NAME, FCOE_VERSION, |
| 413 | fcoe_netdev(lp)->name); |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * fcoe_em_config() - allocates em for this lport |
| 420 | * @lp: the port that em is to allocated for |
| 421 | * |
| 422 | * Returns : 0 on success |
| 423 | */ |
| 424 | static inline int fcoe_em_config(struct fc_lport *lp) |
| 425 | { |
Vasu Dev | 52ff878 | 2009-07-29 17:05:10 -0700 | [diff] [blame^] | 426 | if (!fc_exch_mgr_alloc(lp, FC_CLASS_3, FCOE_MIN_XID, |
| 427 | FCOE_MAX_XID, NULL)) |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 428 | return -ENOMEM; |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * fcoe_if_destroy() - FCoE software HBA tear-down function |
| 435 | * @netdev: ptr to the associated net_device |
| 436 | * |
| 437 | * Returns: 0 if link is OK for use by FCoE. |
| 438 | */ |
| 439 | static int fcoe_if_destroy(struct net_device *netdev) |
| 440 | { |
| 441 | struct fc_lport *lp = NULL; |
| 442 | struct fcoe_softc *fc; |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 443 | |
| 444 | BUG_ON(!netdev); |
| 445 | |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 446 | FCOE_NETDEV_DBG(netdev, "Destroying interface\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 447 | |
| 448 | lp = fcoe_hostlist_lookup(netdev); |
| 449 | if (!lp) |
| 450 | return -ENODEV; |
| 451 | |
| 452 | fc = lport_priv(lp); |
| 453 | |
| 454 | /* Logout of the fabric */ |
| 455 | fc_fabric_logoff(lp); |
| 456 | |
| 457 | /* Remove the instance from fcoe's list */ |
| 458 | fcoe_hostlist_remove(lp); |
| 459 | |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 460 | /* clean up netdev configurations */ |
| 461 | fcoe_netdev_cleanup(fc); |
| 462 | |
| 463 | /* tear-down the FCoE controller */ |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 464 | fcoe_ctlr_destroy(&fc->ctlr); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 465 | |
Joe Eykholt | f161fb7 | 2009-07-29 17:04:17 -0700 | [diff] [blame] | 466 | /* Free queued packets for the per-CPU receive threads */ |
| 467 | fcoe_percpu_clean(lp); |
| 468 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 469 | /* Cleanup the fc_lport */ |
| 470 | fc_lport_destroy(lp); |
| 471 | fc_fcp_destroy(lp); |
| 472 | |
| 473 | /* Detach from the scsi-ml */ |
| 474 | fc_remove_host(lp->host); |
| 475 | scsi_remove_host(lp->host); |
| 476 | |
| 477 | /* There are no more rports or I/O, free the EM */ |
Vasu Dev | 52ff878 | 2009-07-29 17:05:10 -0700 | [diff] [blame^] | 478 | fc_exch_mgr_free(lp); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 479 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 480 | /* Free existing skbs */ |
| 481 | fcoe_clean_pending_queue(lp); |
| 482 | |
Vasu Dev | 1047f22 | 2009-05-06 10:52:40 -0700 | [diff] [blame] | 483 | /* Stop the timer */ |
| 484 | del_timer_sync(&fc->timer); |
| 485 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 486 | /* Free memory used by statistical counters */ |
| 487 | fc_lport_free_stats(lp); |
| 488 | |
| 489 | /* Release the net_device and Scsi_Host */ |
| 490 | dev_put(fc->real_dev); |
| 491 | scsi_host_put(lp->host); |
| 492 | |
| 493 | return 0; |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * fcoe_ddp_setup - calls LLD's ddp_setup through net_device |
| 498 | * @lp: the corresponding fc_lport |
| 499 | * @xid: the exchange id for this ddp transfer |
| 500 | * @sgl: the scatterlist describing this transfer |
| 501 | * @sgc: number of sg items |
| 502 | * |
| 503 | * Returns : 0 no ddp |
| 504 | */ |
| 505 | static int fcoe_ddp_setup(struct fc_lport *lp, u16 xid, |
| 506 | struct scatterlist *sgl, unsigned int sgc) |
| 507 | { |
| 508 | struct net_device *n = fcoe_netdev(lp); |
| 509 | |
| 510 | if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_setup) |
| 511 | return n->netdev_ops->ndo_fcoe_ddp_setup(n, xid, sgl, sgc); |
| 512 | |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * fcoe_ddp_done - calls LLD's ddp_done through net_device |
| 518 | * @lp: the corresponding fc_lport |
| 519 | * @xid: the exchange id for this ddp transfer |
| 520 | * |
| 521 | * Returns : the length of data that have been completed by ddp |
| 522 | */ |
| 523 | static int fcoe_ddp_done(struct fc_lport *lp, u16 xid) |
| 524 | { |
| 525 | struct net_device *n = fcoe_netdev(lp); |
| 526 | |
| 527 | if (n->netdev_ops && n->netdev_ops->ndo_fcoe_ddp_done) |
| 528 | return n->netdev_ops->ndo_fcoe_ddp_done(n, xid); |
| 529 | return 0; |
| 530 | } |
| 531 | |
| 532 | static struct libfc_function_template fcoe_libfc_fcn_templ = { |
| 533 | .frame_send = fcoe_xmit, |
| 534 | .ddp_setup = fcoe_ddp_setup, |
| 535 | .ddp_done = fcoe_ddp_done, |
| 536 | }; |
| 537 | |
| 538 | /** |
| 539 | * fcoe_if_create() - this function creates the fcoe interface |
| 540 | * @netdev: pointer the associated netdevice |
| 541 | * |
| 542 | * Creates fc_lport struct and scsi_host for lport, configures lport |
| 543 | * and starts fabric login. |
| 544 | * |
| 545 | * Returns : 0 on success |
| 546 | */ |
| 547 | static int fcoe_if_create(struct net_device *netdev) |
| 548 | { |
| 549 | int rc; |
| 550 | struct fc_lport *lp = NULL; |
| 551 | struct fcoe_softc *fc; |
| 552 | struct Scsi_Host *shost; |
| 553 | |
| 554 | BUG_ON(!netdev); |
| 555 | |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 556 | FCOE_NETDEV_DBG(netdev, "Create Interface\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 557 | |
| 558 | lp = fcoe_hostlist_lookup(netdev); |
| 559 | if (lp) |
| 560 | return -EEXIST; |
| 561 | |
Vasu Dev | a0a25da | 2009-03-17 11:42:29 -0700 | [diff] [blame] | 562 | shost = libfc_host_alloc(&fcoe_shost_template, |
| 563 | sizeof(struct fcoe_softc)); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 564 | if (!shost) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 565 | FCOE_NETDEV_DBG(netdev, "Could not allocate host structure\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 566 | return -ENOMEM; |
| 567 | } |
| 568 | lp = shost_priv(shost); |
| 569 | fc = lport_priv(lp); |
| 570 | |
| 571 | /* configure fc_lport, e.g., em */ |
| 572 | rc = fcoe_lport_config(lp); |
| 573 | if (rc) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 574 | FCOE_NETDEV_DBG(netdev, "Could not configure lport for the " |
| 575 | "interface\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 576 | goto out_host_put; |
| 577 | } |
| 578 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 579 | /* |
| 580 | * Initialize FIP. |
| 581 | */ |
| 582 | fcoe_ctlr_init(&fc->ctlr); |
| 583 | fc->ctlr.send = fcoe_fip_send; |
| 584 | fc->ctlr.update_mac = fcoe_update_src_mac; |
| 585 | |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 586 | /* configure lport network properties */ |
| 587 | rc = fcoe_netdev_config(lp, netdev); |
| 588 | if (rc) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 589 | FCOE_NETDEV_DBG(netdev, "Could not configure netdev for the " |
| 590 | "interface\n"); |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 591 | goto out_netdev_cleanup; |
| 592 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 593 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 594 | /* configure lport scsi host properties */ |
| 595 | rc = fcoe_shost_config(lp, shost, &netdev->dev); |
| 596 | if (rc) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 597 | FCOE_NETDEV_DBG(netdev, "Could not configure shost for the " |
| 598 | "interface\n"); |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 599 | goto out_netdev_cleanup; |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 600 | } |
| 601 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 602 | /* Initialize the library */ |
| 603 | rc = fcoe_libfc_config(lp, &fcoe_libfc_fcn_templ); |
| 604 | if (rc) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 605 | FCOE_NETDEV_DBG(netdev, "Could not configure libfc for the " |
| 606 | "interface\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 607 | goto out_lp_destroy; |
| 608 | } |
| 609 | |
Vasu Dev | 9631609 | 2009-07-29 17:05:00 -0700 | [diff] [blame] | 610 | /* lport exch manager allocation */ |
| 611 | rc = fcoe_em_config(lp); |
| 612 | if (rc) { |
| 613 | FCOE_NETDEV_DBG(netdev, "Could not configure the EM for the " |
| 614 | "interface\n"); |
| 615 | goto out_lp_destroy; |
| 616 | } |
| 617 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 618 | /* add to lports list */ |
| 619 | fcoe_hostlist_add(lp); |
| 620 | |
| 621 | lp->boot_time = jiffies; |
| 622 | |
| 623 | fc_fabric_login(lp); |
| 624 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 625 | if (!fcoe_link_ok(lp)) |
| 626 | fcoe_ctlr_link_up(&fc->ctlr); |
| 627 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 628 | dev_hold(netdev); |
| 629 | |
| 630 | return rc; |
| 631 | |
| 632 | out_lp_destroy: |
Vasu Dev | 52ff878 | 2009-07-29 17:05:10 -0700 | [diff] [blame^] | 633 | fc_exch_mgr_free(lp); |
Vasu Dev | ab6b85c | 2009-05-17 12:33:08 +0000 | [diff] [blame] | 634 | out_netdev_cleanup: |
| 635 | fcoe_netdev_cleanup(fc); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 636 | out_host_put: |
| 637 | scsi_host_put(lp->host); |
| 638 | return rc; |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * fcoe_if_init() - attach to scsi transport |
| 643 | * |
| 644 | * Returns : 0 on success |
| 645 | */ |
| 646 | static int __init fcoe_if_init(void) |
| 647 | { |
| 648 | /* attach to scsi transport */ |
| 649 | scsi_transport_fcoe_sw = |
| 650 | fc_attach_transport(&fcoe_transport_function); |
| 651 | |
| 652 | if (!scsi_transport_fcoe_sw) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 653 | printk(KERN_ERR "fcoe: Failed to attach to the FC transport\n"); |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 654 | return -ENODEV; |
| 655 | } |
| 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * fcoe_if_exit() - detach from scsi transport |
| 662 | * |
| 663 | * Returns : 0 on success |
| 664 | */ |
| 665 | int __exit fcoe_if_exit(void) |
| 666 | { |
| 667 | fc_release_transport(scsi_transport_fcoe_sw); |
| 668 | return 0; |
| 669 | } |
| 670 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 671 | /** |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 672 | * fcoe_percpu_thread_create() - Create a receive thread for an online cpu |
| 673 | * @cpu: cpu index for the online cpu |
| 674 | */ |
| 675 | static void fcoe_percpu_thread_create(unsigned int cpu) |
| 676 | { |
| 677 | struct fcoe_percpu_s *p; |
| 678 | struct task_struct *thread; |
| 679 | |
| 680 | p = &per_cpu(fcoe_percpu, cpu); |
| 681 | |
| 682 | thread = kthread_create(fcoe_percpu_receive_thread, |
| 683 | (void *)p, "fcoethread/%d", cpu); |
| 684 | |
| 685 | if (likely(!IS_ERR(p->thread))) { |
| 686 | kthread_bind(thread, cpu); |
| 687 | wake_up_process(thread); |
| 688 | |
| 689 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 690 | p->thread = thread; |
| 691 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * fcoe_percpu_thread_destroy() - removes the rx thread for the given cpu |
| 697 | * @cpu: cpu index the rx thread is to be removed |
| 698 | * |
| 699 | * Destroys a per-CPU Rx thread. Any pending skbs are moved to the |
| 700 | * current CPU's Rx thread. If the thread being destroyed is bound to |
| 701 | * the CPU processing this context the skbs will be freed. |
| 702 | */ |
| 703 | static void fcoe_percpu_thread_destroy(unsigned int cpu) |
| 704 | { |
| 705 | struct fcoe_percpu_s *p; |
| 706 | struct task_struct *thread; |
| 707 | struct page *crc_eof; |
| 708 | struct sk_buff *skb; |
| 709 | #ifdef CONFIG_SMP |
| 710 | struct fcoe_percpu_s *p0; |
| 711 | unsigned targ_cpu = smp_processor_id(); |
| 712 | #endif /* CONFIG_SMP */ |
| 713 | |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 714 | FCOE_DBG("Destroying receive thread for CPU %d\n", cpu); |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 715 | |
| 716 | /* Prevent any new skbs from being queued for this CPU. */ |
| 717 | p = &per_cpu(fcoe_percpu, cpu); |
| 718 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 719 | thread = p->thread; |
| 720 | p->thread = NULL; |
| 721 | crc_eof = p->crc_eof_page; |
| 722 | p->crc_eof_page = NULL; |
| 723 | p->crc_eof_offset = 0; |
| 724 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 725 | |
| 726 | #ifdef CONFIG_SMP |
| 727 | /* |
| 728 | * Don't bother moving the skb's if this context is running |
| 729 | * on the same CPU that is having its thread destroyed. This |
| 730 | * can easily happen when the module is removed. |
| 731 | */ |
| 732 | if (cpu != targ_cpu) { |
| 733 | p0 = &per_cpu(fcoe_percpu, targ_cpu); |
| 734 | spin_lock_bh(&p0->fcoe_rx_list.lock); |
| 735 | if (p0->thread) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 736 | FCOE_DBG("Moving frames from CPU %d to CPU %d\n", |
| 737 | cpu, targ_cpu); |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 738 | |
| 739 | while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) |
| 740 | __skb_queue_tail(&p0->fcoe_rx_list, skb); |
| 741 | spin_unlock_bh(&p0->fcoe_rx_list.lock); |
| 742 | } else { |
| 743 | /* |
| 744 | * The targeted CPU is not initialized and cannot accept |
| 745 | * new skbs. Unlock the targeted CPU and drop the skbs |
| 746 | * on the CPU that is going offline. |
| 747 | */ |
| 748 | while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) |
| 749 | kfree_skb(skb); |
| 750 | spin_unlock_bh(&p0->fcoe_rx_list.lock); |
| 751 | } |
| 752 | } else { |
| 753 | /* |
| 754 | * This scenario occurs when the module is being removed |
| 755 | * and all threads are being destroyed. skbs will continue |
| 756 | * to be shifted from the CPU thread that is being removed |
| 757 | * to the CPU thread associated with the CPU that is processing |
| 758 | * the module removal. Once there is only one CPU Rx thread it |
| 759 | * will reach this case and we will drop all skbs and later |
| 760 | * stop the thread. |
| 761 | */ |
| 762 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 763 | while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) |
| 764 | kfree_skb(skb); |
| 765 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 766 | } |
| 767 | #else |
| 768 | /* |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 769 | * This a non-SMP scenario where the singular Rx thread is |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 770 | * being removed. Free all skbs and stop the thread. |
| 771 | */ |
| 772 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 773 | while ((skb = __skb_dequeue(&p->fcoe_rx_list)) != NULL) |
| 774 | kfree_skb(skb); |
| 775 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 776 | #endif |
| 777 | |
| 778 | if (thread) |
| 779 | kthread_stop(thread); |
| 780 | |
| 781 | if (crc_eof) |
| 782 | put_page(crc_eof); |
| 783 | } |
| 784 | |
| 785 | /** |
| 786 | * fcoe_cpu_callback() - fcoe cpu hotplug event callback |
| 787 | * @nfb: callback data block |
| 788 | * @action: event triggering the callback |
| 789 | * @hcpu: index for the cpu of this event |
| 790 | * |
| 791 | * This creates or destroys per cpu data for fcoe |
| 792 | * |
| 793 | * Returns NOTIFY_OK always. |
| 794 | */ |
| 795 | static int fcoe_cpu_callback(struct notifier_block *nfb, |
| 796 | unsigned long action, void *hcpu) |
| 797 | { |
| 798 | unsigned cpu = (unsigned long)hcpu; |
| 799 | |
| 800 | switch (action) { |
| 801 | case CPU_ONLINE: |
| 802 | case CPU_ONLINE_FROZEN: |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 803 | FCOE_DBG("CPU %x online: Create Rx thread\n", cpu); |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 804 | fcoe_percpu_thread_create(cpu); |
| 805 | break; |
| 806 | case CPU_DEAD: |
| 807 | case CPU_DEAD_FROZEN: |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 808 | FCOE_DBG("CPU %x offline: Remove Rx thread\n", cpu); |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 809 | fcoe_percpu_thread_destroy(cpu); |
| 810 | break; |
| 811 | default: |
| 812 | break; |
| 813 | } |
| 814 | return NOTIFY_OK; |
| 815 | } |
| 816 | |
| 817 | static struct notifier_block fcoe_cpu_notifier = { |
| 818 | .notifier_call = fcoe_cpu_callback, |
| 819 | }; |
| 820 | |
| 821 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 822 | * fcoe_rcv() - this is the fcoe receive function called by NET_RX_SOFTIRQ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 823 | * @skb: the receive skb |
| 824 | * @dev: associated net device |
| 825 | * @ptype: context |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 826 | * @olddev: last device |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 827 | * |
| 828 | * this function will receive the packet and build fc frame and pass it up |
| 829 | * |
| 830 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 831 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 832 | int fcoe_rcv(struct sk_buff *skb, struct net_device *dev, |
| 833 | struct packet_type *ptype, struct net_device *olddev) |
| 834 | { |
| 835 | struct fc_lport *lp; |
| 836 | struct fcoe_rcv_info *fr; |
| 837 | struct fcoe_softc *fc; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 838 | struct fc_frame_header *fh; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 839 | struct fcoe_percpu_s *fps; |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 840 | unsigned short oxid; |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 841 | unsigned int cpu = 0; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 842 | |
| 843 | fc = container_of(ptype, struct fcoe_softc, fcoe_packet_type); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 844 | lp = fc->ctlr.lp; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 845 | if (unlikely(lp == NULL)) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 846 | FCOE_NETDEV_DBG(dev, "Cannot find hba structure"); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 847 | goto err2; |
| 848 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 849 | if (!lp->link_up) |
| 850 | goto err2; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 851 | |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 852 | FCOE_NETDEV_DBG(dev, "skb_info: len:%d data_len:%d head:%p " |
| 853 | "data:%p tail:%p end:%p sum:%d dev:%s", |
| 854 | skb->len, skb->data_len, skb->head, skb->data, |
| 855 | skb_tail_pointer(skb), skb_end_pointer(skb), |
| 856 | skb->csum, skb->dev ? skb->dev->name : "<NULL>"); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 857 | |
| 858 | /* check for FCOE packet type */ |
| 859 | if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 860 | FCOE_NETDEV_DBG(dev, "Wrong FC type frame"); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 861 | goto err; |
| 862 | } |
| 863 | |
| 864 | /* |
| 865 | * Check for minimum frame length, and make sure required FCoE |
| 866 | * and FC headers are pulled into the linear data area. |
| 867 | */ |
| 868 | if (unlikely((skb->len < FCOE_MIN_FRAME) || |
| 869 | !pskb_may_pull(skb, FCOE_HEADER_LEN))) |
| 870 | goto err; |
| 871 | |
| 872 | skb_set_transport_header(skb, sizeof(struct fcoe_hdr)); |
| 873 | fh = (struct fc_frame_header *) skb_transport_header(skb); |
| 874 | |
| 875 | oxid = ntohs(fh->fh_ox_id); |
| 876 | |
| 877 | fr = fcoe_dev_from_skb(skb); |
| 878 | fr->fr_dev = lp; |
| 879 | fr->ptype = ptype; |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 880 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 881 | #ifdef CONFIG_SMP |
| 882 | /* |
| 883 | * The incoming frame exchange id(oxid) is ANDed with num of online |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 884 | * cpu bits to get cpu and then this cpu is used for selecting |
| 885 | * a per cpu kernel thread from fcoe_percpu. |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 886 | */ |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 887 | cpu = oxid & (num_online_cpus() - 1); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 888 | #endif |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 889 | |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 890 | fps = &per_cpu(fcoe_percpu, cpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 891 | spin_lock_bh(&fps->fcoe_rx_list.lock); |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 892 | if (unlikely(!fps->thread)) { |
| 893 | /* |
| 894 | * The targeted CPU is not ready, let's target |
| 895 | * the first CPU now. For non-SMP systems this |
| 896 | * will check the same CPU twice. |
| 897 | */ |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 898 | FCOE_NETDEV_DBG(dev, "CPU is online, but no receive thread " |
| 899 | "ready for incoming skb- using first online " |
| 900 | "CPU.\n"); |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 901 | |
| 902 | spin_unlock_bh(&fps->fcoe_rx_list.lock); |
| 903 | cpu = first_cpu(cpu_online_map); |
| 904 | fps = &per_cpu(fcoe_percpu, cpu); |
| 905 | spin_lock_bh(&fps->fcoe_rx_list.lock); |
| 906 | if (!fps->thread) { |
| 907 | spin_unlock_bh(&fps->fcoe_rx_list.lock); |
| 908 | goto err; |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | /* |
| 913 | * We now have a valid CPU that we're targeting for |
| 914 | * this skb. We also have this receive thread locked, |
| 915 | * so we're free to queue skbs into it's queue. |
| 916 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 917 | __skb_queue_tail(&fps->fcoe_rx_list, skb); |
| 918 | if (fps->fcoe_rx_list.qlen == 1) |
| 919 | wake_up_process(fps->thread); |
| 920 | |
| 921 | spin_unlock_bh(&fps->fcoe_rx_list.lock); |
| 922 | |
| 923 | return 0; |
| 924 | err: |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 925 | fc_lport_get_stats(lp)->ErrorFrames++; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 926 | |
| 927 | err2: |
| 928 | kfree_skb(skb); |
| 929 | return -1; |
| 930 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 931 | |
| 932 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 933 | * fcoe_start_io() - pass to netdev to start xmit for fcoe |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 934 | * @skb: the skb to be xmitted |
| 935 | * |
| 936 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 937 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 938 | static inline int fcoe_start_io(struct sk_buff *skb) |
| 939 | { |
| 940 | int rc; |
| 941 | |
| 942 | skb_get(skb); |
| 943 | rc = dev_queue_xmit(skb); |
| 944 | if (rc != 0) |
| 945 | return rc; |
| 946 | kfree_skb(skb); |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | /** |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 951 | * fcoe_get_paged_crc_eof() - in case we need to alloc a page for crc_eof |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 952 | * @skb: the skb to be xmitted |
| 953 | * @tlen: total len |
| 954 | * |
| 955 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 956 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 957 | static int fcoe_get_paged_crc_eof(struct sk_buff *skb, int tlen) |
| 958 | { |
| 959 | struct fcoe_percpu_s *fps; |
| 960 | struct page *page; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 961 | |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 962 | fps = &get_cpu_var(fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 963 | page = fps->crc_eof_page; |
| 964 | if (!page) { |
| 965 | page = alloc_page(GFP_ATOMIC); |
| 966 | if (!page) { |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 967 | put_cpu_var(fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 968 | return -ENOMEM; |
| 969 | } |
| 970 | fps->crc_eof_page = page; |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 971 | fps->crc_eof_offset = 0; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | get_page(page); |
| 975 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page, |
| 976 | fps->crc_eof_offset, tlen); |
| 977 | skb->len += tlen; |
| 978 | skb->data_len += tlen; |
| 979 | skb->truesize += tlen; |
| 980 | fps->crc_eof_offset += sizeof(struct fcoe_crc_eof); |
| 981 | |
| 982 | if (fps->crc_eof_offset >= PAGE_SIZE) { |
| 983 | fps->crc_eof_page = NULL; |
| 984 | fps->crc_eof_offset = 0; |
| 985 | put_page(page); |
| 986 | } |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 987 | put_cpu_var(fcoe_percpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 992 | * fcoe_fc_crc() - calculates FC CRC in this fcoe skb |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 993 | * @fp: the fc_frame containing data to be checksummed |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 994 | * |
| 995 | * This uses crc32() to calculate the crc for fc frame |
| 996 | * Return : 32 bit crc |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 997 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 998 | u32 fcoe_fc_crc(struct fc_frame *fp) |
| 999 | { |
| 1000 | struct sk_buff *skb = fp_skb(fp); |
| 1001 | struct skb_frag_struct *frag; |
| 1002 | unsigned char *data; |
| 1003 | unsigned long off, len, clen; |
| 1004 | u32 crc; |
| 1005 | unsigned i; |
| 1006 | |
| 1007 | crc = crc32(~0, skb->data, skb_headlen(skb)); |
| 1008 | |
| 1009 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 1010 | frag = &skb_shinfo(skb)->frags[i]; |
| 1011 | off = frag->page_offset; |
| 1012 | len = frag->size; |
| 1013 | while (len > 0) { |
| 1014 | clen = min(len, PAGE_SIZE - (off & ~PAGE_MASK)); |
| 1015 | data = kmap_atomic(frag->page + (off >> PAGE_SHIFT), |
| 1016 | KM_SKB_DATA_SOFTIRQ); |
| 1017 | crc = crc32(crc, data + (off & ~PAGE_MASK), clen); |
| 1018 | kunmap_atomic(data, KM_SKB_DATA_SOFTIRQ); |
| 1019 | off += clen; |
| 1020 | len -= clen; |
| 1021 | } |
| 1022 | } |
| 1023 | return crc; |
| 1024 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1025 | |
| 1026 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1027 | * fcoe_xmit() - FCoE frame transmit function |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1028 | * @lp: the associated local port |
| 1029 | * @fp: the fc_frame to be transmitted |
| 1030 | * |
| 1031 | * Return : 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1032 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1033 | int fcoe_xmit(struct fc_lport *lp, struct fc_frame *fp) |
| 1034 | { |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 1035 | int wlen; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1036 | u32 crc; |
| 1037 | struct ethhdr *eh; |
| 1038 | struct fcoe_crc_eof *cp; |
| 1039 | struct sk_buff *skb; |
| 1040 | struct fcoe_dev_stats *stats; |
| 1041 | struct fc_frame_header *fh; |
| 1042 | unsigned int hlen; /* header length implies the version */ |
| 1043 | unsigned int tlen; /* trailer length */ |
| 1044 | unsigned int elen; /* eth header, may include vlan */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1045 | struct fcoe_softc *fc; |
| 1046 | u8 sof, eof; |
| 1047 | struct fcoe_hdr *hp; |
| 1048 | |
| 1049 | WARN_ON((fr_len(fp) % sizeof(u32)) != 0); |
| 1050 | |
Robert Love | fc47ff6 | 2009-02-27 10:55:55 -0800 | [diff] [blame] | 1051 | fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1052 | fh = fc_frame_header_get(fp); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1053 | skb = fp_skb(fp); |
| 1054 | wlen = skb->len / FCOE_WORD_TO_BYTE; |
| 1055 | |
| 1056 | if (!lp->link_up) { |
Dan Carpenter | 3caf02e | 2009-04-21 16:27:25 -0700 | [diff] [blame] | 1057 | kfree_skb(skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1058 | return 0; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1059 | } |
| 1060 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1061 | if (unlikely(fh->fh_r_ctl == FC_RCTL_ELS_REQ) && |
| 1062 | fcoe_ctlr_els_send(&fc->ctlr, skb)) |
| 1063 | return 0; |
| 1064 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1065 | sof = fr_sof(fp); |
| 1066 | eof = fr_eof(fp); |
| 1067 | |
Vasu Dev | 4e57e1c | 2009-05-06 10:52:46 -0700 | [diff] [blame] | 1068 | elen = sizeof(struct ethhdr); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1069 | hlen = sizeof(struct fcoe_hdr); |
| 1070 | tlen = sizeof(struct fcoe_crc_eof); |
| 1071 | wlen = (skb->len - tlen + sizeof(crc)) / FCOE_WORD_TO_BYTE; |
| 1072 | |
| 1073 | /* crc offload */ |
| 1074 | if (likely(lp->crc_offload)) { |
Yi Zou | 39ca9a0 | 2009-02-27 14:07:15 -0800 | [diff] [blame] | 1075 | skb->ip_summed = CHECKSUM_PARTIAL; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1076 | skb->csum_start = skb_headroom(skb); |
| 1077 | skb->csum_offset = skb->len; |
| 1078 | crc = 0; |
| 1079 | } else { |
| 1080 | skb->ip_summed = CHECKSUM_NONE; |
| 1081 | crc = fcoe_fc_crc(fp); |
| 1082 | } |
| 1083 | |
| 1084 | /* copy fc crc and eof to the skb buff */ |
| 1085 | if (skb_is_nonlinear(skb)) { |
| 1086 | skb_frag_t *frag; |
| 1087 | if (fcoe_get_paged_crc_eof(skb, tlen)) { |
Roel Kluin | e904158 | 2009-02-27 10:56:22 -0800 | [diff] [blame] | 1088 | kfree_skb(skb); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1089 | return -ENOMEM; |
| 1090 | } |
| 1091 | frag = &skb_shinfo(skb)->frags[skb_shinfo(skb)->nr_frags - 1]; |
| 1092 | cp = kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ) |
| 1093 | + frag->page_offset; |
| 1094 | } else { |
| 1095 | cp = (struct fcoe_crc_eof *)skb_put(skb, tlen); |
| 1096 | } |
| 1097 | |
| 1098 | memset(cp, 0, sizeof(*cp)); |
| 1099 | cp->fcoe_eof = eof; |
| 1100 | cp->fcoe_crc32 = cpu_to_le32(~crc); |
| 1101 | |
| 1102 | if (skb_is_nonlinear(skb)) { |
| 1103 | kunmap_atomic(cp, KM_SKB_DATA_SOFTIRQ); |
| 1104 | cp = NULL; |
| 1105 | } |
| 1106 | |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1107 | /* adjust skb network/transport offsets to match mac/fcoe/fc */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1108 | skb_push(skb, elen + hlen); |
| 1109 | skb_reset_mac_header(skb); |
| 1110 | skb_reset_network_header(skb); |
| 1111 | skb->mac_len = elen; |
Yi Zou | 211c738 | 2009-02-27 14:06:37 -0800 | [diff] [blame] | 1112 | skb->protocol = htons(ETH_P_FCOE); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1113 | skb->dev = fc->real_dev; |
| 1114 | |
| 1115 | /* fill up mac and fcoe headers */ |
| 1116 | eh = eth_hdr(skb); |
| 1117 | eh->h_proto = htons(ETH_P_FCOE); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1118 | if (fc->ctlr.map_dest) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1119 | fc_fcoe_set_mac(eh->h_dest, fh->fh_d_id); |
| 1120 | else |
| 1121 | /* insert GW address */ |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1122 | memcpy(eh->h_dest, fc->ctlr.dest_addr, ETH_ALEN); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1123 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1124 | if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN)) |
| 1125 | memcpy(eh->h_source, fc->ctlr.ctl_src_addr, ETH_ALEN); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1126 | else |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1127 | memcpy(eh->h_source, fc->ctlr.data_src_addr, ETH_ALEN); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1128 | |
| 1129 | hp = (struct fcoe_hdr *)(eh + 1); |
| 1130 | memset(hp, 0, sizeof(*hp)); |
| 1131 | if (FC_FCOE_VER) |
| 1132 | FC_FCOE_ENCAPS_VER(hp, FC_FCOE_VER); |
| 1133 | hp->fcoe_sof = sof; |
| 1134 | |
Yi Zou | 39ca9a0 | 2009-02-27 14:07:15 -0800 | [diff] [blame] | 1135 | #ifdef NETIF_F_FSO |
| 1136 | /* fcoe lso, mss is in max_payload which is non-zero for FCP data */ |
| 1137 | if (lp->seq_offload && fr_max_payload(fp)) { |
| 1138 | skb_shinfo(skb)->gso_type = SKB_GSO_FCOE; |
| 1139 | skb_shinfo(skb)->gso_size = fr_max_payload(fp); |
| 1140 | } else { |
| 1141 | skb_shinfo(skb)->gso_type = 0; |
| 1142 | skb_shinfo(skb)->gso_size = 0; |
| 1143 | } |
| 1144 | #endif |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1145 | /* update tx stats: regardless if LLD fails */ |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 1146 | stats = fc_lport_get_stats(lp); |
| 1147 | stats->TxFrames++; |
| 1148 | stats->TxWords += wlen; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1149 | |
| 1150 | /* send down to lld */ |
| 1151 | fr_dev(fp) = lp; |
| 1152 | if (fc->fcoe_pending_queue.qlen) |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 1153 | fcoe_check_wait_queue(lp, skb); |
| 1154 | else if (fcoe_start_io(skb)) |
| 1155 | fcoe_check_wait_queue(lp, skb); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1156 | |
| 1157 | return 0; |
| 1158 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1159 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1160 | /** |
| 1161 | * fcoe_percpu_receive_thread() - recv thread per cpu |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1162 | * @arg: ptr to the fcoe per cpu struct |
| 1163 | * |
| 1164 | * Return: 0 for success |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1165 | */ |
| 1166 | int fcoe_percpu_receive_thread(void *arg) |
| 1167 | { |
| 1168 | struct fcoe_percpu_s *p = arg; |
| 1169 | u32 fr_len; |
| 1170 | struct fc_lport *lp; |
| 1171 | struct fcoe_rcv_info *fr; |
| 1172 | struct fcoe_dev_stats *stats; |
| 1173 | struct fc_frame_header *fh; |
| 1174 | struct sk_buff *skb; |
| 1175 | struct fcoe_crc_eof crc_eof; |
| 1176 | struct fc_frame *fp; |
| 1177 | u8 *mac = NULL; |
| 1178 | struct fcoe_softc *fc; |
| 1179 | struct fcoe_hdr *hp; |
| 1180 | |
Robert Love | 4469c19 | 2009-02-27 10:56:38 -0800 | [diff] [blame] | 1181 | set_user_nice(current, -20); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1182 | |
| 1183 | while (!kthread_should_stop()) { |
| 1184 | |
| 1185 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 1186 | while ((skb = __skb_dequeue(&p->fcoe_rx_list)) == NULL) { |
| 1187 | set_current_state(TASK_INTERRUPTIBLE); |
| 1188 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 1189 | schedule(); |
| 1190 | set_current_state(TASK_RUNNING); |
| 1191 | if (kthread_should_stop()) |
| 1192 | return 0; |
| 1193 | spin_lock_bh(&p->fcoe_rx_list.lock); |
| 1194 | } |
| 1195 | spin_unlock_bh(&p->fcoe_rx_list.lock); |
| 1196 | fr = fcoe_dev_from_skb(skb); |
| 1197 | lp = fr->fr_dev; |
| 1198 | if (unlikely(lp == NULL)) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1199 | FCOE_NETDEV_DBG(skb->dev, "Invalid HBA Structure"); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1200 | kfree_skb(skb); |
| 1201 | continue; |
| 1202 | } |
| 1203 | |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1204 | FCOE_NETDEV_DBG(skb->dev, "skb_info: len:%d data_len:%d " |
| 1205 | "head:%p data:%p tail:%p end:%p sum:%d dev:%s", |
| 1206 | skb->len, skb->data_len, |
| 1207 | skb->head, skb->data, skb_tail_pointer(skb), |
| 1208 | skb_end_pointer(skb), skb->csum, |
| 1209 | skb->dev ? skb->dev->name : "<NULL>"); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1210 | |
| 1211 | /* |
| 1212 | * Save source MAC address before discarding header. |
| 1213 | */ |
| 1214 | fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1215 | if (skb_is_nonlinear(skb)) |
| 1216 | skb_linearize(skb); /* not ideal */ |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1217 | mac = eth_hdr(skb)->h_source; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1218 | |
| 1219 | /* |
| 1220 | * Frame length checks and setting up the header pointers |
| 1221 | * was done in fcoe_rcv already. |
| 1222 | */ |
| 1223 | hp = (struct fcoe_hdr *) skb_network_header(skb); |
| 1224 | fh = (struct fc_frame_header *) skb_transport_header(skb); |
| 1225 | |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 1226 | stats = fc_lport_get_stats(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1227 | if (unlikely(FC_FCOE_DECAPS_VER(hp) != FC_FCOE_VER)) { |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 1228 | if (stats->ErrorFrames < 5) |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1229 | printk(KERN_WARNING "fcoe: FCoE version " |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 1230 | "mismatch: The frame has " |
| 1231 | "version %x, but the " |
| 1232 | "initiator supports version " |
| 1233 | "%x\n", FC_FCOE_DECAPS_VER(hp), |
| 1234 | FC_FCOE_VER); |
| 1235 | stats->ErrorFrames++; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1236 | kfree_skb(skb); |
| 1237 | continue; |
| 1238 | } |
| 1239 | |
| 1240 | skb_pull(skb, sizeof(struct fcoe_hdr)); |
| 1241 | fr_len = skb->len - sizeof(struct fcoe_crc_eof); |
| 1242 | |
Robert Love | 582b45b | 2009-03-31 15:51:50 -0700 | [diff] [blame] | 1243 | stats->RxFrames++; |
| 1244 | stats->RxWords += fr_len / FCOE_WORD_TO_BYTE; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1245 | |
| 1246 | fp = (struct fc_frame *)skb; |
| 1247 | fc_frame_init(fp); |
| 1248 | fr_dev(fp) = lp; |
| 1249 | fr_sof(fp) = hp->fcoe_sof; |
| 1250 | |
| 1251 | /* Copy out the CRC and EOF trailer for access */ |
| 1252 | if (skb_copy_bits(skb, fr_len, &crc_eof, sizeof(crc_eof))) { |
| 1253 | kfree_skb(skb); |
| 1254 | continue; |
| 1255 | } |
| 1256 | fr_eof(fp) = crc_eof.fcoe_eof; |
| 1257 | fr_crc(fp) = crc_eof.fcoe_crc32; |
| 1258 | if (pskb_trim(skb, fr_len)) { |
| 1259 | kfree_skb(skb); |
| 1260 | continue; |
| 1261 | } |
| 1262 | |
| 1263 | /* |
| 1264 | * We only check CRC if no offload is available and if it is |
| 1265 | * it's solicited data, in which case, the FCP layer would |
| 1266 | * check it during the copy. |
| 1267 | */ |
Yi Zou | 07c00ec | 2009-02-27 14:07:31 -0800 | [diff] [blame] | 1268 | if (lp->crc_offload && skb->ip_summed == CHECKSUM_UNNECESSARY) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1269 | fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; |
| 1270 | else |
| 1271 | fr_flags(fp) |= FCPHF_CRC_UNCHECKED; |
| 1272 | |
| 1273 | fh = fc_frame_header_get(fp); |
| 1274 | if (fh->fh_r_ctl == FC_RCTL_DD_SOL_DATA && |
| 1275 | fh->fh_type == FC_TYPE_FCP) { |
Vasu Dev | 52ff878 | 2009-07-29 17:05:10 -0700 | [diff] [blame^] | 1276 | fc_exch_recv(lp, fp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1277 | continue; |
| 1278 | } |
| 1279 | if (fr_flags(fp) & FCPHF_CRC_UNCHECKED) { |
| 1280 | if (le32_to_cpu(fr_crc(fp)) != |
| 1281 | ~crc32(~0, skb->data, fr_len)) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1282 | if (stats->InvalidCRCCount < 5) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1283 | printk(KERN_WARNING "fcoe: dropping " |
| 1284 | "frame with CRC error\n"); |
| 1285 | stats->InvalidCRCCount++; |
| 1286 | stats->ErrorFrames++; |
| 1287 | fc_frame_free(fp); |
| 1288 | continue; |
| 1289 | } |
| 1290 | fr_flags(fp) &= ~FCPHF_CRC_UNCHECKED; |
| 1291 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1292 | if (unlikely(fc->ctlr.flogi_oxid != FC_XID_UNKNOWN) && |
| 1293 | fcoe_ctlr_recv_flogi(&fc->ctlr, fp, mac)) { |
| 1294 | fc_frame_free(fp); |
| 1295 | continue; |
| 1296 | } |
Vasu Dev | 52ff878 | 2009-07-29 17:05:10 -0700 | [diff] [blame^] | 1297 | fc_exch_recv(lp, fp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1298 | } |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | /** |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1303 | * fcoe_check_wait_queue() - attempt to clear the transmit backlog |
| 1304 | * @lp: the fc_lport |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1305 | * |
| 1306 | * This empties the wait_queue, dequeue the head of the wait_queue queue |
| 1307 | * and calls fcoe_start_io() for each packet, if all skb have been |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 1308 | * transmitted, return qlen or -1 if a error occurs, then restore |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1309 | * wait_queue and try again later. |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1310 | * |
| 1311 | * The wait_queue is used when the skb transmit fails. skb will go |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1312 | * in the wait_queue which will be emptied by the timer function or |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1313 | * by the next skb transmit. |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1314 | */ |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 1315 | static void fcoe_check_wait_queue(struct fc_lport *lp, struct sk_buff *skb) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1316 | { |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 1317 | struct fcoe_softc *fc = lport_priv(lp); |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 1318 | int rc; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1319 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1320 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 1321 | |
| 1322 | if (skb) |
| 1323 | __skb_queue_tail(&fc->fcoe_pending_queue, skb); |
| 1324 | |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 1325 | if (fc->fcoe_pending_queue_active) |
| 1326 | goto out; |
| 1327 | fc->fcoe_pending_queue_active = 1; |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 1328 | |
| 1329 | while (fc->fcoe_pending_queue.qlen) { |
| 1330 | /* keep qlen > 0 until fcoe_start_io succeeds */ |
| 1331 | fc->fcoe_pending_queue.qlen++; |
| 1332 | skb = __skb_dequeue(&fc->fcoe_pending_queue); |
| 1333 | |
| 1334 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
| 1335 | rc = fcoe_start_io(skb); |
| 1336 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
| 1337 | |
| 1338 | if (rc) { |
| 1339 | __skb_queue_head(&fc->fcoe_pending_queue, skb); |
| 1340 | /* undo temporary increment above */ |
| 1341 | fc->fcoe_pending_queue.qlen--; |
| 1342 | break; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1343 | } |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 1344 | /* undo temporary increment above */ |
| 1345 | fc->fcoe_pending_queue.qlen--; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1346 | } |
Chris Leech | 55c8baf | 2009-02-27 10:56:32 -0800 | [diff] [blame] | 1347 | |
| 1348 | if (fc->fcoe_pending_queue.qlen < FCOE_LOW_QUEUE_DEPTH) |
| 1349 | lp->qfull = 0; |
Vasu Dev | 1047f22 | 2009-05-06 10:52:40 -0700 | [diff] [blame] | 1350 | if (fc->fcoe_pending_queue.qlen && !timer_pending(&fc->timer)) |
| 1351 | mod_timer(&fc->timer, jiffies + 2); |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 1352 | fc->fcoe_pending_queue_active = 0; |
Vasu Dev | c826a31 | 2009-02-27 10:56:27 -0800 | [diff] [blame] | 1353 | out: |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 1354 | if (fc->fcoe_pending_queue.qlen > FCOE_MAX_QUEUE_DEPTH) |
| 1355 | lp->qfull = 1; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1356 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
Vasu Dev | 4bb6b51 | 2009-05-06 10:52:34 -0700 | [diff] [blame] | 1357 | return; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1361 | * fcoe_dev_setup() - setup link change notification interface |
| 1362 | */ |
Randy Dunlap | b0d428a | 2009-04-27 21:49:31 -0700 | [diff] [blame] | 1363 | static void fcoe_dev_setup(void) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1364 | { |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1365 | register_netdevice_notifier(&fcoe_notifier); |
| 1366 | } |
| 1367 | |
| 1368 | /** |
Randy Dunlap | b0d428a | 2009-04-27 21:49:31 -0700 | [diff] [blame] | 1369 | * fcoe_dev_cleanup() - cleanup link change notification interface |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1370 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1371 | static void fcoe_dev_cleanup(void) |
| 1372 | { |
| 1373 | unregister_netdevice_notifier(&fcoe_notifier); |
| 1374 | } |
| 1375 | |
| 1376 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1377 | * fcoe_device_notification() - netdev event notification callback |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1378 | * @notifier: context of the notification |
| 1379 | * @event: type of event |
| 1380 | * @ptr: fixed array for output parsed ifname |
| 1381 | * |
| 1382 | * This function is called by the ethernet driver in case of link change event |
| 1383 | * |
| 1384 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1385 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1386 | static int fcoe_device_notification(struct notifier_block *notifier, |
| 1387 | ulong event, void *ptr) |
| 1388 | { |
| 1389 | struct fc_lport *lp = NULL; |
| 1390 | struct net_device *real_dev = ptr; |
| 1391 | struct fcoe_softc *fc; |
| 1392 | struct fcoe_dev_stats *stats; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1393 | u32 link_possible = 1; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1394 | u32 mfs; |
| 1395 | int rc = NOTIFY_OK; |
| 1396 | |
| 1397 | read_lock(&fcoe_hostlist_lock); |
| 1398 | list_for_each_entry(fc, &fcoe_hostlist, list) { |
| 1399 | if (fc->real_dev == real_dev) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1400 | lp = fc->ctlr.lp; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1401 | break; |
| 1402 | } |
| 1403 | } |
| 1404 | read_unlock(&fcoe_hostlist_lock); |
| 1405 | if (lp == NULL) { |
| 1406 | rc = NOTIFY_DONE; |
| 1407 | goto out; |
| 1408 | } |
| 1409 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1410 | switch (event) { |
| 1411 | case NETDEV_DOWN: |
| 1412 | case NETDEV_GOING_DOWN: |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1413 | link_possible = 0; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1414 | break; |
| 1415 | case NETDEV_UP: |
| 1416 | case NETDEV_CHANGE: |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1417 | break; |
| 1418 | case NETDEV_CHANGEMTU: |
| 1419 | mfs = fc->real_dev->mtu - |
| 1420 | (sizeof(struct fcoe_hdr) + |
| 1421 | sizeof(struct fcoe_crc_eof)); |
| 1422 | if (mfs >= FC_MIN_MAX_FRAME) |
| 1423 | fc_set_mfs(lp, mfs); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1424 | break; |
| 1425 | case NETDEV_REGISTER: |
| 1426 | break; |
| 1427 | default: |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1428 | FCOE_NETDEV_DBG(real_dev, "Unknown event %ld " |
| 1429 | "from netdev netlink\n", event); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1430 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1431 | if (link_possible && !fcoe_link_ok(lp)) |
| 1432 | fcoe_ctlr_link_up(&fc->ctlr); |
| 1433 | else if (fcoe_ctlr_link_down(&fc->ctlr)) { |
| 1434 | stats = fc_lport_get_stats(lp); |
| 1435 | stats->LinkFailureCount++; |
| 1436 | fcoe_clean_pending_queue(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1437 | } |
| 1438 | out: |
| 1439 | return rc; |
| 1440 | } |
| 1441 | |
| 1442 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1443 | * fcoe_if_to_netdev() - parse a name buffer to get netdev |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1444 | * @buffer: incoming buffer to be copied |
| 1445 | * |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1446 | * Returns: NULL or ptr to net_device |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1447 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1448 | static struct net_device *fcoe_if_to_netdev(const char *buffer) |
| 1449 | { |
| 1450 | char *cp; |
| 1451 | char ifname[IFNAMSIZ + 2]; |
| 1452 | |
| 1453 | if (buffer) { |
| 1454 | strlcpy(ifname, buffer, IFNAMSIZ); |
| 1455 | cp = ifname + strlen(ifname); |
| 1456 | while (--cp >= ifname && *cp == '\n') |
| 1457 | *cp = '\0'; |
| 1458 | return dev_get_by_name(&init_net, ifname); |
| 1459 | } |
| 1460 | return NULL; |
| 1461 | } |
| 1462 | |
| 1463 | /** |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1464 | * fcoe_netdev_to_module_owner() - finds out the driver module of the netdev |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1465 | * @netdev: the target netdev |
| 1466 | * |
| 1467 | * Returns: ptr to the struct module, NULL for failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1468 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 1469 | static struct module * |
| 1470 | fcoe_netdev_to_module_owner(const struct net_device *netdev) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1471 | { |
| 1472 | struct device *dev; |
| 1473 | |
| 1474 | if (!netdev) |
| 1475 | return NULL; |
| 1476 | |
| 1477 | dev = netdev->dev.parent; |
| 1478 | if (!dev) |
| 1479 | return NULL; |
| 1480 | |
| 1481 | if (!dev->driver) |
| 1482 | return NULL; |
| 1483 | |
| 1484 | return dev->driver->owner; |
| 1485 | } |
| 1486 | |
| 1487 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1488 | * fcoe_ethdrv_get() - Hold the Ethernet driver |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1489 | * @netdev: the target netdev |
| 1490 | * |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1491 | * Holds the Ethernet driver module by try_module_get() for |
| 1492 | * the corresponding netdev. |
| 1493 | * |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1494 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1495 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1496 | static int fcoe_ethdrv_get(const struct net_device *netdev) |
| 1497 | { |
| 1498 | struct module *owner; |
| 1499 | |
| 1500 | owner = fcoe_netdev_to_module_owner(netdev); |
| 1501 | if (owner) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1502 | FCOE_NETDEV_DBG(netdev, "Hold driver module %s\n", |
| 1503 | module_name(owner)); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1504 | return try_module_get(owner); |
| 1505 | } |
| 1506 | return -ENODEV; |
| 1507 | } |
| 1508 | |
| 1509 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1510 | * fcoe_ethdrv_put() - Release the Ethernet driver |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1511 | * @netdev: the target netdev |
| 1512 | * |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1513 | * Releases the Ethernet driver module by module_put for |
| 1514 | * the corresponding netdev. |
| 1515 | * |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1516 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1517 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1518 | static int fcoe_ethdrv_put(const struct net_device *netdev) |
| 1519 | { |
| 1520 | struct module *owner; |
| 1521 | |
| 1522 | owner = fcoe_netdev_to_module_owner(netdev); |
| 1523 | if (owner) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1524 | FCOE_NETDEV_DBG(netdev, "Release driver module %s\n", |
| 1525 | module_name(owner)); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1526 | module_put(owner); |
| 1527 | return 0; |
| 1528 | } |
| 1529 | return -ENODEV; |
| 1530 | } |
| 1531 | |
| 1532 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1533 | * fcoe_destroy() - handles the destroy from sysfs |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1534 | * @buffer: expected to be an eth if name |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1535 | * @kp: associated kernel param |
| 1536 | * |
| 1537 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1538 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1539 | static int fcoe_destroy(const char *buffer, struct kernel_param *kp) |
| 1540 | { |
| 1541 | int rc; |
| 1542 | struct net_device *netdev; |
| 1543 | |
| 1544 | netdev = fcoe_if_to_netdev(buffer); |
| 1545 | if (!netdev) { |
| 1546 | rc = -ENODEV; |
| 1547 | goto out_nodev; |
| 1548 | } |
| 1549 | /* look for existing lport */ |
| 1550 | if (!fcoe_hostlist_lookup(netdev)) { |
| 1551 | rc = -ENODEV; |
| 1552 | goto out_putdev; |
| 1553 | } |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 1554 | rc = fcoe_if_destroy(netdev); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1555 | if (rc) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1556 | printk(KERN_ERR "fcoe: Failed to destroy interface (%s)\n", |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1557 | netdev->name); |
| 1558 | rc = -EIO; |
| 1559 | goto out_putdev; |
| 1560 | } |
| 1561 | fcoe_ethdrv_put(netdev); |
| 1562 | rc = 0; |
| 1563 | out_putdev: |
| 1564 | dev_put(netdev); |
| 1565 | out_nodev: |
| 1566 | return rc; |
| 1567 | } |
| 1568 | |
| 1569 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1570 | * fcoe_create() - Handles the create call from sysfs |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1571 | * @buffer: expected to be an eth if name |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1572 | * @kp: associated kernel param |
| 1573 | * |
| 1574 | * Returns: 0 for success |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1575 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1576 | static int fcoe_create(const char *buffer, struct kernel_param *kp) |
| 1577 | { |
| 1578 | int rc; |
| 1579 | struct net_device *netdev; |
| 1580 | |
| 1581 | netdev = fcoe_if_to_netdev(buffer); |
| 1582 | if (!netdev) { |
| 1583 | rc = -ENODEV; |
| 1584 | goto out_nodev; |
| 1585 | } |
| 1586 | /* look for existing lport */ |
| 1587 | if (fcoe_hostlist_lookup(netdev)) { |
| 1588 | rc = -EEXIST; |
| 1589 | goto out_putdev; |
| 1590 | } |
| 1591 | fcoe_ethdrv_get(netdev); |
| 1592 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 1593 | rc = fcoe_if_create(netdev); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1594 | if (rc) { |
Robert Love | d5488eb | 2009-06-10 15:30:59 -0700 | [diff] [blame] | 1595 | printk(KERN_ERR "fcoe: Failed to create interface (%s)\n", |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1596 | netdev->name); |
| 1597 | fcoe_ethdrv_put(netdev); |
| 1598 | rc = -EIO; |
| 1599 | goto out_putdev; |
| 1600 | } |
| 1601 | rc = 0; |
| 1602 | out_putdev: |
| 1603 | dev_put(netdev); |
| 1604 | out_nodev: |
| 1605 | return rc; |
| 1606 | } |
| 1607 | |
| 1608 | module_param_call(create, fcoe_create, NULL, NULL, S_IWUSR); |
| 1609 | __MODULE_PARM_TYPE(create, "string"); |
| 1610 | MODULE_PARM_DESC(create, "Create fcoe port using net device passed in."); |
| 1611 | module_param_call(destroy, fcoe_destroy, NULL, NULL, S_IWUSR); |
| 1612 | __MODULE_PARM_TYPE(destroy, "string"); |
| 1613 | MODULE_PARM_DESC(destroy, "Destroy fcoe port"); |
| 1614 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1615 | /** |
| 1616 | * fcoe_link_ok() - Check if link is ok for the fc_lport |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1617 | * @lp: ptr to the fc_lport |
| 1618 | * |
| 1619 | * Any permanently-disqualifying conditions have been previously checked. |
| 1620 | * This also updates the speed setting, which may change with link for 100/1000. |
| 1621 | * |
| 1622 | * This function should probably be checking for PAUSE support at some point |
| 1623 | * in the future. Currently Per-priority-pause is not determinable using |
| 1624 | * ethtool, so we shouldn't be restrictive until that problem is resolved. |
| 1625 | * |
| 1626 | * Returns: 0 if link is OK for use by FCoE. |
| 1627 | * |
| 1628 | */ |
| 1629 | int fcoe_link_ok(struct fc_lport *lp) |
| 1630 | { |
Robert Love | fc47ff6 | 2009-02-27 10:55:55 -0800 | [diff] [blame] | 1631 | struct fcoe_softc *fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1632 | struct net_device *dev = fc->real_dev; |
| 1633 | struct ethtool_cmd ecmd = { ETHTOOL_GSET }; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1634 | |
Yi Zou | 2f718d6 | 2009-07-29 17:04:01 -0700 | [diff] [blame] | 1635 | if ((dev->flags & IFF_UP) && netif_carrier_ok(dev) && |
| 1636 | (!dev_ethtool_get_settings(dev, &ecmd))) { |
| 1637 | lp->link_supported_speeds &= |
| 1638 | ~(FC_PORTSPEED_1GBIT | FC_PORTSPEED_10GBIT); |
| 1639 | if (ecmd.supported & (SUPPORTED_1000baseT_Half | |
| 1640 | SUPPORTED_1000baseT_Full)) |
| 1641 | lp->link_supported_speeds |= FC_PORTSPEED_1GBIT; |
| 1642 | if (ecmd.supported & SUPPORTED_10000baseT_Full) |
| 1643 | lp->link_supported_speeds |= |
| 1644 | FC_PORTSPEED_10GBIT; |
| 1645 | if (ecmd.speed == SPEED_1000) |
| 1646 | lp->link_speed = FC_PORTSPEED_1GBIT; |
| 1647 | if (ecmd.speed == SPEED_10000) |
| 1648 | lp->link_speed = FC_PORTSPEED_10GBIT; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1649 | |
Yi Zou | 2f718d6 | 2009-07-29 17:04:01 -0700 | [diff] [blame] | 1650 | return 0; |
| 1651 | } |
| 1652 | return -1; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1653 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1654 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1655 | /** |
| 1656 | * fcoe_percpu_clean() - Clear the pending skbs for an lport |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1657 | * @lp: the fc_lport |
| 1658 | */ |
| 1659 | void fcoe_percpu_clean(struct fc_lport *lp) |
| 1660 | { |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1661 | struct fcoe_percpu_s *pp; |
| 1662 | struct fcoe_rcv_info *fr; |
| 1663 | struct sk_buff_head *list; |
| 1664 | struct sk_buff *skb, *next; |
| 1665 | struct sk_buff *head; |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1666 | unsigned int cpu; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1667 | |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1668 | for_each_possible_cpu(cpu) { |
| 1669 | pp = &per_cpu(fcoe_percpu, cpu); |
| 1670 | spin_lock_bh(&pp->fcoe_rx_list.lock); |
| 1671 | list = &pp->fcoe_rx_list; |
| 1672 | head = list->next; |
| 1673 | for (skb = head; skb != (struct sk_buff *)list; |
| 1674 | skb = next) { |
| 1675 | next = skb->next; |
| 1676 | fr = fcoe_dev_from_skb(skb); |
| 1677 | if (fr->fr_dev == lp) { |
| 1678 | __skb_unlink(skb, list); |
| 1679 | kfree_skb(skb); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1680 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1681 | } |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1682 | spin_unlock_bh(&pp->fcoe_rx_list.lock); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1683 | } |
| 1684 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1685 | |
| 1686 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1687 | * fcoe_clean_pending_queue() - Dequeue a skb and free it |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1688 | * @lp: the corresponding fc_lport |
| 1689 | * |
| 1690 | * Returns: none |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1691 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1692 | void fcoe_clean_pending_queue(struct fc_lport *lp) |
| 1693 | { |
| 1694 | struct fcoe_softc *fc = lport_priv(lp); |
| 1695 | struct sk_buff *skb; |
| 1696 | |
| 1697 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
| 1698 | while ((skb = __skb_dequeue(&fc->fcoe_pending_queue)) != NULL) { |
| 1699 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
| 1700 | kfree_skb(skb); |
| 1701 | spin_lock_bh(&fc->fcoe_pending_queue.lock); |
| 1702 | } |
| 1703 | spin_unlock_bh(&fc->fcoe_pending_queue.lock); |
| 1704 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1705 | |
| 1706 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1707 | * fcoe_reset() - Resets the fcoe |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1708 | * @shost: shost the reset is from |
| 1709 | * |
| 1710 | * Returns: always 0 |
| 1711 | */ |
| 1712 | int fcoe_reset(struct Scsi_Host *shost) |
| 1713 | { |
| 1714 | struct fc_lport *lport = shost_priv(shost); |
| 1715 | fc_lport_reset(lport); |
| 1716 | return 0; |
| 1717 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1718 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1719 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1720 | * fcoe_hostlist_lookup_softc() - find the corresponding lport by a given device |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1721 | * @dev: this is currently ptr to net_device |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1722 | * |
| 1723 | * Returns: NULL or the located fcoe_softc |
| 1724 | */ |
Robert Love | b2ab99c | 2009-02-27 10:55:50 -0800 | [diff] [blame] | 1725 | static struct fcoe_softc * |
| 1726 | fcoe_hostlist_lookup_softc(const struct net_device *dev) |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1727 | { |
| 1728 | struct fcoe_softc *fc; |
| 1729 | |
| 1730 | read_lock(&fcoe_hostlist_lock); |
| 1731 | list_for_each_entry(fc, &fcoe_hostlist, list) { |
| 1732 | if (fc->real_dev == dev) { |
| 1733 | read_unlock(&fcoe_hostlist_lock); |
| 1734 | return fc; |
| 1735 | } |
| 1736 | } |
| 1737 | read_unlock(&fcoe_hostlist_lock); |
| 1738 | return NULL; |
| 1739 | } |
| 1740 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1741 | /** |
| 1742 | * fcoe_hostlist_lookup() - Find the corresponding lport by netdev |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1743 | * @netdev: ptr to net_device |
| 1744 | * |
| 1745 | * Returns: 0 for success |
| 1746 | */ |
| 1747 | struct fc_lport *fcoe_hostlist_lookup(const struct net_device *netdev) |
| 1748 | { |
| 1749 | struct fcoe_softc *fc; |
| 1750 | |
| 1751 | fc = fcoe_hostlist_lookup_softc(netdev); |
| 1752 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1753 | return (fc) ? fc->ctlr.lp : NULL; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1754 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1755 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1756 | /** |
| 1757 | * fcoe_hostlist_add() - Add a lport to lports list |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1758 | * @lp: ptr to the fc_lport to be added |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1759 | * |
| 1760 | * Returns: 0 for success |
| 1761 | */ |
| 1762 | int fcoe_hostlist_add(const struct fc_lport *lp) |
| 1763 | { |
| 1764 | struct fcoe_softc *fc; |
| 1765 | |
| 1766 | fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp)); |
| 1767 | if (!fc) { |
Robert Love | fc47ff6 | 2009-02-27 10:55:55 -0800 | [diff] [blame] | 1768 | fc = lport_priv(lp); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1769 | write_lock_bh(&fcoe_hostlist_lock); |
| 1770 | list_add_tail(&fc->list, &fcoe_hostlist); |
| 1771 | write_unlock_bh(&fcoe_hostlist_lock); |
| 1772 | } |
| 1773 | return 0; |
| 1774 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1775 | |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1776 | /** |
| 1777 | * fcoe_hostlist_remove() - remove a lport from lports list |
Chris Leech | dd3fd72 | 2009-04-21 16:27:36 -0700 | [diff] [blame] | 1778 | * @lp: ptr to the fc_lport to be removed |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1779 | * |
| 1780 | * Returns: 0 for success |
| 1781 | */ |
| 1782 | int fcoe_hostlist_remove(const struct fc_lport *lp) |
| 1783 | { |
| 1784 | struct fcoe_softc *fc; |
| 1785 | |
| 1786 | fc = fcoe_hostlist_lookup_softc(fcoe_netdev(lp)); |
| 1787 | BUG_ON(!fc); |
| 1788 | write_lock_bh(&fcoe_hostlist_lock); |
| 1789 | list_del(&fc->list); |
| 1790 | write_unlock_bh(&fcoe_hostlist_lock); |
| 1791 | |
| 1792 | return 0; |
| 1793 | } |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1794 | |
| 1795 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1796 | * fcoe_init() - fcoe module loading initialization |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1797 | * |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1798 | * Returns 0 on success, negative on failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1799 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1800 | static int __init fcoe_init(void) |
| 1801 | { |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 1802 | unsigned int cpu; |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 1803 | int rc = 0; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1804 | struct fcoe_percpu_s *p; |
| 1805 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1806 | INIT_LIST_HEAD(&fcoe_hostlist); |
| 1807 | rwlock_init(&fcoe_hostlist_lock); |
| 1808 | |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 1809 | for_each_possible_cpu(cpu) { |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1810 | p = &per_cpu(fcoe_percpu, cpu); |
Robert Love | 38eccab | 2009-03-17 11:41:30 -0700 | [diff] [blame] | 1811 | skb_queue_head_init(&p->fcoe_rx_list); |
| 1812 | } |
| 1813 | |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 1814 | for_each_online_cpu(cpu) |
| 1815 | fcoe_percpu_thread_create(cpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1816 | |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 1817 | /* Initialize per CPU interrupt thread */ |
| 1818 | rc = register_hotcpu_notifier(&fcoe_cpu_notifier); |
| 1819 | if (rc) |
| 1820 | goto out_free; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1821 | |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 1822 | /* Setup link change notification */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1823 | fcoe_dev_setup(); |
| 1824 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 1825 | fcoe_if_init(); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1826 | |
| 1827 | return 0; |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 1828 | |
| 1829 | out_free: |
| 1830 | for_each_online_cpu(cpu) { |
| 1831 | fcoe_percpu_thread_destroy(cpu); |
| 1832 | } |
| 1833 | |
| 1834 | return rc; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1835 | } |
| 1836 | module_init(fcoe_init); |
| 1837 | |
| 1838 | /** |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1839 | * fcoe_exit() - fcoe module unloading cleanup |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1840 | * |
| 1841 | * Returns 0 on success, negative on failure |
Robert Love | 34f42a0 | 2009-02-27 10:55:45 -0800 | [diff] [blame] | 1842 | */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1843 | static void __exit fcoe_exit(void) |
| 1844 | { |
Robert Love | 5e5e92d | 2009-03-17 11:41:35 -0700 | [diff] [blame] | 1845 | unsigned int cpu; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1846 | struct fcoe_softc *fc, *tmp; |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1847 | |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1848 | fcoe_dev_cleanup(); |
| 1849 | |
Vasu Dev | 5919a59 | 2009-03-27 09:03:29 -0700 | [diff] [blame] | 1850 | /* releases the associated fcoe hosts */ |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1851 | list_for_each_entry_safe(fc, tmp, &fcoe_hostlist, list) |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 1852 | fcoe_if_destroy(fc->real_dev); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1853 | |
Robert Love | 8976f42 | 2009-03-17 11:41:46 -0700 | [diff] [blame] | 1854 | unregister_hotcpu_notifier(&fcoe_cpu_notifier); |
| 1855 | |
| 1856 | for_each_online_cpu(cpu) { |
| 1857 | fcoe_percpu_thread_destroy(cpu); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1858 | } |
| 1859 | |
Vasu Dev | 7f34914 | 2009-03-27 09:06:31 -0700 | [diff] [blame] | 1860 | /* detach from scsi transport */ |
| 1861 | fcoe_if_exit(); |
Robert Love | 85b4aa4 | 2008-12-09 15:10:24 -0800 | [diff] [blame] | 1862 | } |
| 1863 | module_exit(fcoe_exit); |