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