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