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