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