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