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