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