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