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