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