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