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