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