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