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