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