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