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