Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 1 | /* |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 2 | * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved. |
| 3 | * Copyright (c) 2009 Intel Corporation. All rights reserved. |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms and conditions of the GNU General Public License, |
| 7 | * version 2, as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | * Maintained at www.Open-FCoE.org |
| 19 | */ |
| 20 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 21 | #include <linux/types.h> |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 23 | #include <linux/kernel.h> |
| 24 | #include <linux/list.h> |
| 25 | #include <linux/spinlock.h> |
| 26 | #include <linux/timer.h> |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 27 | #include <linux/netdevice.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 28 | #include <linux/etherdevice.h> |
| 29 | #include <linux/ethtool.h> |
| 30 | #include <linux/if_ether.h> |
| 31 | #include <linux/if_vlan.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 32 | #include <linux/errno.h> |
| 33 | #include <linux/bitops.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 35 | #include <net/rtnetlink.h> |
| 36 | |
| 37 | #include <scsi/fc/fc_els.h> |
| 38 | #include <scsi/fc/fc_fs.h> |
| 39 | #include <scsi/fc/fc_fip.h> |
| 40 | #include <scsi/fc/fc_encaps.h> |
| 41 | #include <scsi/fc/fc_fcoe.h> |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 42 | #include <scsi/fc/fc_fcp.h> |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 43 | |
| 44 | #include <scsi/libfc.h> |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 45 | #include <scsi/libfcoe.h> |
Vasu Dev | 9b34ecf | 2009-03-17 11:42:13 -0700 | [diff] [blame] | 46 | |
Yi Zou | 21b7b2f | 2011-01-28 16:04:45 -0800 | [diff] [blame] | 47 | #include "libfcoe.h" |
| 48 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 49 | #define FCOE_CTLR_MIN_FKA 500 /* min keep alive (mS) */ |
| 50 | #define FCOE_CTLR_DEF_FKA FIP_DEF_FKA /* default keep alive (mS) */ |
| 51 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 52 | static void fcoe_ctlr_timeout(struct timer_list *); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 53 | static void fcoe_ctlr_timer_work(struct work_struct *); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 54 | static void fcoe_ctlr_recv_work(struct work_struct *); |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 55 | static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 56 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 57 | static void fcoe_ctlr_vn_start(struct fcoe_ctlr *); |
| 58 | static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *, struct sk_buff *); |
| 59 | static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *); |
| 60 | static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr *, u32, u8 *); |
| 61 | |
Hannes Reinecke | 9a6cf88 | 2016-07-19 13:49:40 +0200 | [diff] [blame] | 62 | static int fcoe_ctlr_vlan_recv(struct fcoe_ctlr *, struct sk_buff *); |
| 63 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 64 | static u8 fcoe_all_fcfs[ETH_ALEN] = FIP_ALL_FCF_MACS; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 65 | static u8 fcoe_all_enode[ETH_ALEN] = FIP_ALL_ENODE_MACS; |
| 66 | static u8 fcoe_all_vn2vn[ETH_ALEN] = FIP_ALL_VN2VN_MACS; |
| 67 | static u8 fcoe_all_p2p[ETH_ALEN] = FIP_ALL_P2P_MACS; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 68 | |
Yi Zou | 0095a92 | 2011-01-28 16:05:00 -0800 | [diff] [blame] | 69 | static const char * const fcoe_ctlr_states[] = { |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 70 | [FIP_ST_DISABLED] = "DISABLED", |
| 71 | [FIP_ST_LINK_WAIT] = "LINK_WAIT", |
| 72 | [FIP_ST_AUTO] = "AUTO", |
| 73 | [FIP_ST_NON_FIP] = "NON_FIP", |
| 74 | [FIP_ST_ENABLED] = "ENABLED", |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 75 | [FIP_ST_VNMP_START] = "VNMP_START", |
| 76 | [FIP_ST_VNMP_PROBE1] = "VNMP_PROBE1", |
| 77 | [FIP_ST_VNMP_PROBE2] = "VNMP_PROBE2", |
| 78 | [FIP_ST_VNMP_CLAIM] = "VNMP_CLAIM", |
| 79 | [FIP_ST_VNMP_UP] = "VNMP_UP", |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static const char *fcoe_ctlr_state(enum fip_state state) |
| 83 | { |
| 84 | const char *cp = "unknown"; |
| 85 | |
| 86 | if (state < ARRAY_SIZE(fcoe_ctlr_states)) |
| 87 | cp = fcoe_ctlr_states[state]; |
| 88 | if (!cp) |
| 89 | cp = "unknown"; |
| 90 | return cp; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * fcoe_ctlr_set_state() - Set and do debug printing for the new FIP state. |
| 95 | * @fip: The FCoE controller |
| 96 | * @state: The new state |
| 97 | */ |
| 98 | static void fcoe_ctlr_set_state(struct fcoe_ctlr *fip, enum fip_state state) |
| 99 | { |
| 100 | if (state == fip->state) |
| 101 | return; |
| 102 | if (fip->lp) |
| 103 | LIBFCOE_FIP_DBG(fip, "state %s -> %s\n", |
| 104 | fcoe_ctlr_state(fip->state), fcoe_ctlr_state(state)); |
| 105 | fip->state = state; |
| 106 | } |
| 107 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 108 | /** |
| 109 | * fcoe_ctlr_mtu_valid() - Check if a FCF's MTU is valid |
| 110 | * @fcf: The FCF to check |
| 111 | * |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 112 | * Return non-zero if FCF fcoe_size has been validated. |
| 113 | */ |
| 114 | static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf *fcf) |
| 115 | { |
| 116 | return (fcf->flags & FIP_FL_SOL) != 0; |
| 117 | } |
| 118 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 119 | /** |
| 120 | * fcoe_ctlr_fcf_usable() - Check if a FCF is usable |
| 121 | * @fcf: The FCF to check |
| 122 | * |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 123 | * Return non-zero if the FCF is usable. |
| 124 | */ |
| 125 | static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf *fcf) |
| 126 | { |
| 127 | u16 flags = FIP_FL_SOL | FIP_FL_AVAIL; |
| 128 | |
| 129 | return (fcf->flags & flags) == flags; |
| 130 | } |
| 131 | |
| 132 | /** |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 133 | * fcoe_ctlr_map_dest() - Set flag and OUI for mapping destination addresses |
| 134 | * @fip: The FCoE controller |
| 135 | */ |
| 136 | static void fcoe_ctlr_map_dest(struct fcoe_ctlr *fip) |
| 137 | { |
| 138 | if (fip->mode == FIP_MODE_VN2VN) |
| 139 | hton24(fip->dest_addr, FIP_VN_FC_MAP); |
| 140 | else |
| 141 | hton24(fip->dest_addr, FIP_DEF_FC_MAP); |
| 142 | hton24(fip->dest_addr + 3, 0); |
| 143 | fip->map_dest = 1; |
| 144 | } |
| 145 | |
| 146 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 147 | * fcoe_ctlr_init() - Initialize the FCoE Controller instance |
| 148 | * @fip: The FCoE controller to initialize |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 149 | */ |
Sedat Dilek | 8beb90a | 2019-02-15 13:19:20 +0100 | [diff] [blame] | 150 | void fcoe_ctlr_init(struct fcoe_ctlr *fip, enum fip_mode mode) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 151 | { |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 152 | fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT); |
Joe Eykholt | 3d902ac | 2010-07-20 15:19:58 -0700 | [diff] [blame] | 153 | fip->mode = mode; |
Hannes Reinecke | 9a6cf88 | 2016-07-19 13:49:40 +0200 | [diff] [blame] | 154 | fip->fip_resp = false; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 155 | INIT_LIST_HEAD(&fip->fcfs); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 156 | mutex_init(&fip->ctlr_mutex); |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 157 | spin_lock_init(&fip->ctlr_lock); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 158 | fip->flogi_oxid = FC_XID_UNKNOWN; |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 159 | timer_setup(&fip->timer, fcoe_ctlr_timeout, 0); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 160 | INIT_WORK(&fip->timer_work, fcoe_ctlr_timer_work); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 161 | INIT_WORK(&fip->recv_work, fcoe_ctlr_recv_work); |
| 162 | skb_queue_head_init(&fip->fip_recv_list); |
| 163 | } |
| 164 | EXPORT_SYMBOL(fcoe_ctlr_init); |
| 165 | |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 166 | /** |
| 167 | * fcoe_sysfs_fcf_add() - Add a fcoe_fcf{,_device} to a fcoe_ctlr{,_device} |
| 168 | * @new: The newly discovered FCF |
| 169 | * |
| 170 | * Called with fip->ctlr_mutex held |
| 171 | */ |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 172 | static int fcoe_sysfs_fcf_add(struct fcoe_fcf *new) |
| 173 | { |
| 174 | struct fcoe_ctlr *fip = new->fip; |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 175 | struct fcoe_ctlr_device *ctlr_dev; |
Bart Van Assche | 1c2c1b4 | 2013-08-14 15:42:46 +0000 | [diff] [blame] | 176 | struct fcoe_fcf_device *temp, *fcf_dev; |
| 177 | int rc = -ENOMEM; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 178 | |
| 179 | LIBFCOE_FIP_DBG(fip, "New FCF fab %16.16llx mac %pM\n", |
| 180 | new->fabric_name, new->fcf_mac); |
| 181 | |
Bart Van Assche | 1c2c1b4 | 2013-08-14 15:42:46 +0000 | [diff] [blame] | 182 | temp = kzalloc(sizeof(*temp), GFP_KERNEL); |
| 183 | if (!temp) |
| 184 | goto out; |
| 185 | |
Bart Van Assche | 1c2c1b4 | 2013-08-14 15:42:46 +0000 | [diff] [blame] | 186 | temp->fabric_name = new->fabric_name; |
| 187 | temp->switch_name = new->switch_name; |
| 188 | temp->fc_map = new->fc_map; |
| 189 | temp->vfid = new->vfid; |
| 190 | memcpy(temp->mac, new->fcf_mac, ETH_ALEN); |
| 191 | temp->priority = new->pri; |
| 192 | temp->fka_period = new->fka_period; |
| 193 | temp->selected = 0; /* default to unselected */ |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 194 | |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 195 | /* |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 196 | * If ctlr_dev doesn't exist then it means we're a libfcoe user |
| 197 | * who doesn't use fcoe_syfs and didn't allocate a fcoe_ctlr_device. |
| 198 | * fnic would be an example of a driver with this behavior. In this |
| 199 | * case we want to add the fcoe_fcf to the fcoe_ctlr list, but we |
| 200 | * don't want to make sysfs changes. |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 201 | */ |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 202 | |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 203 | ctlr_dev = fcoe_ctlr_to_ctlr_dev(fip); |
| 204 | if (ctlr_dev) { |
| 205 | mutex_lock(&ctlr_dev->lock); |
| 206 | fcf_dev = fcoe_fcf_device_add(ctlr_dev, temp); |
| 207 | if (unlikely(!fcf_dev)) { |
| 208 | rc = -ENOMEM; |
Neil Horman | 55d0ac5 | 2013-10-08 23:43:58 +0000 | [diff] [blame] | 209 | mutex_unlock(&ctlr_dev->lock); |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 210 | goto out; |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * The fcoe_sysfs layer can return a CONNECTED fcf that |
| 215 | * has a priv (fcf was never deleted) or a CONNECTED fcf |
| 216 | * that doesn't have a priv (fcf was deleted). However, |
| 217 | * libfcoe will always delete FCFs before trying to add |
| 218 | * them. This is ensured because both recv_adv and |
| 219 | * age_fcfs are protected by the the fcoe_ctlr's mutex. |
| 220 | * This means that we should never get a FCF with a |
| 221 | * non-NULL priv pointer. |
| 222 | */ |
| 223 | BUG_ON(fcf_dev->priv); |
| 224 | |
| 225 | fcf_dev->priv = new; |
| 226 | new->fcf_dev = fcf_dev; |
| 227 | mutex_unlock(&ctlr_dev->lock); |
| 228 | } |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 229 | |
| 230 | list_add(&new->list, &fip->fcfs); |
| 231 | fip->fcf_count++; |
Bart Van Assche | 1c2c1b4 | 2013-08-14 15:42:46 +0000 | [diff] [blame] | 232 | rc = 0; |
| 233 | |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 234 | out: |
Bart Van Assche | 1c2c1b4 | 2013-08-14 15:42:46 +0000 | [diff] [blame] | 235 | kfree(temp); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 236 | return rc; |
| 237 | } |
| 238 | |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 239 | /** |
| 240 | * fcoe_sysfs_fcf_del() - Remove a fcoe_fcf{,_device} to a fcoe_ctlr{,_device} |
| 241 | * @new: The FCF to be removed |
| 242 | * |
| 243 | * Called with fip->ctlr_mutex held |
| 244 | */ |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 245 | static void fcoe_sysfs_fcf_del(struct fcoe_fcf *new) |
| 246 | { |
| 247 | struct fcoe_ctlr *fip = new->fip; |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 248 | struct fcoe_ctlr_device *cdev; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 249 | struct fcoe_fcf_device *fcf_dev; |
| 250 | |
| 251 | list_del(&new->list); |
| 252 | fip->fcf_count--; |
| 253 | |
Robert Love | 9d34876 | 2013-09-05 07:47:27 +0000 | [diff] [blame] | 254 | /* |
| 255 | * If ctlr_dev doesn't exist then it means we're a libfcoe user |
| 256 | * who doesn't use fcoe_syfs and didn't allocate a fcoe_ctlr_device |
| 257 | * or a fcoe_fcf_device. |
| 258 | * |
| 259 | * fnic would be an example of a driver with this behavior. In this |
| 260 | * case we want to remove the fcoe_fcf from the fcoe_ctlr list (above), |
| 261 | * but we don't want to make sysfs changes. |
| 262 | */ |
| 263 | cdev = fcoe_ctlr_to_ctlr_dev(fip); |
| 264 | if (cdev) { |
| 265 | mutex_lock(&cdev->lock); |
| 266 | fcf_dev = fcoe_fcf_to_fcf_dev(new); |
| 267 | WARN_ON(!fcf_dev); |
| 268 | new->fcf_dev = NULL; |
| 269 | fcoe_fcf_device_delete(fcf_dev); |
| 270 | kfree(new); |
| 271 | mutex_unlock(&cdev->lock); |
| 272 | } |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 275 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 276 | * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller |
| 277 | * @fip: The FCoE controller whose FCFs are to be reset |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 278 | * |
| 279 | * Called with &fcoe_ctlr lock held. |
| 280 | */ |
| 281 | static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr *fip) |
| 282 | { |
| 283 | struct fcoe_fcf *fcf; |
| 284 | struct fcoe_fcf *next; |
| 285 | |
| 286 | fip->sel_fcf = NULL; |
| 287 | list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 288 | fcoe_sysfs_fcf_del(fcf); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 289 | } |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 290 | WARN_ON(fip->fcf_count); |
| 291 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 292 | fip->sel_time = 0; |
| 293 | } |
| 294 | |
| 295 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 296 | * fcoe_ctlr_destroy() - Disable and tear down a FCoE controller |
| 297 | * @fip: The FCoE controller to tear down |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 298 | * |
| 299 | * This is called by FCoE drivers before freeing the &fcoe_ctlr. |
| 300 | * |
| 301 | * The receive handler will have been deleted before this to guarantee |
| 302 | * that no more recv_work will be scheduled. |
| 303 | * |
| 304 | * The timer routine will simply return once we set FIP_ST_DISABLED. |
| 305 | * This guarantees that no further timeouts or work will be scheduled. |
| 306 | */ |
| 307 | void fcoe_ctlr_destroy(struct fcoe_ctlr *fip) |
| 308 | { |
Chris Leech | a4b7cfa | 2009-08-25 13:59:08 -0700 | [diff] [blame] | 309 | cancel_work_sync(&fip->recv_work); |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 310 | skb_queue_purge(&fip->fip_recv_list); |
Chris Leech | a4b7cfa | 2009-08-25 13:59:08 -0700 | [diff] [blame] | 311 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 312 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 313 | fcoe_ctlr_set_state(fip, FIP_ST_DISABLED); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 314 | fcoe_ctlr_reset_fcfs(fip); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 315 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 316 | del_timer_sync(&fip->timer); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 317 | cancel_work_sync(&fip->timer_work); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 318 | } |
| 319 | EXPORT_SYMBOL(fcoe_ctlr_destroy); |
| 320 | |
| 321 | /** |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 322 | * fcoe_ctlr_announce() - announce new FCF selection |
Joe Eykholt | 69316ee | 2010-11-30 16:19:40 -0800 | [diff] [blame] | 323 | * @fip: The FCoE controller |
| 324 | * |
| 325 | * Also sets the destination MAC for FCoE and control packets |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 326 | * |
| 327 | * Called with neither ctlr_mutex nor ctlr_lock held. |
Joe Eykholt | 69316ee | 2010-11-30 16:19:40 -0800 | [diff] [blame] | 328 | */ |
| 329 | static void fcoe_ctlr_announce(struct fcoe_ctlr *fip) |
| 330 | { |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 331 | struct fcoe_fcf *sel; |
| 332 | struct fcoe_fcf *fcf; |
| 333 | |
| 334 | mutex_lock(&fip->ctlr_mutex); |
| 335 | spin_lock_bh(&fip->ctlr_lock); |
| 336 | |
| 337 | kfree_skb(fip->flogi_req); |
| 338 | fip->flogi_req = NULL; |
| 339 | list_for_each_entry(fcf, &fip->fcfs, list) |
| 340 | fcf->flogi_sent = 0; |
| 341 | |
| 342 | spin_unlock_bh(&fip->ctlr_lock); |
| 343 | sel = fip->sel_fcf; |
Joe Eykholt | 69316ee | 2010-11-30 16:19:40 -0800 | [diff] [blame] | 344 | |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 345 | if (sel && ether_addr_equal(sel->fcf_mac, fip->dest_addr)) |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 346 | goto unlock; |
Joe Eykholt | 69316ee | 2010-11-30 16:19:40 -0800 | [diff] [blame] | 347 | if (!is_zero_ether_addr(fip->dest_addr)) { |
| 348 | printk(KERN_NOTICE "libfcoe: host%d: " |
| 349 | "FIP Fibre-Channel Forwarder MAC %pM deselected\n", |
| 350 | fip->lp->host->host_no, fip->dest_addr); |
| 351 | memset(fip->dest_addr, 0, ETH_ALEN); |
| 352 | } |
| 353 | if (sel) { |
| 354 | printk(KERN_INFO "libfcoe: host%d: FIP selected " |
| 355 | "Fibre-Channel Forwarder MAC %pM\n", |
| 356 | fip->lp->host->host_no, sel->fcf_mac); |
Bhanu Prakash Gollapudi | 81c11dd | 2012-03-09 14:50:03 -0800 | [diff] [blame] | 357 | memcpy(fip->dest_addr, sel->fcoe_mac, ETH_ALEN); |
Joe Eykholt | 69316ee | 2010-11-30 16:19:40 -0800 | [diff] [blame] | 358 | fip->map_dest = 0; |
| 359 | } |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 360 | unlock: |
| 361 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 69316ee | 2010-11-30 16:19:40 -0800 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 365 | * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port |
| 366 | * @fip: The FCoE controller to get the maximum FCoE size from |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 367 | * |
| 368 | * Returns the maximum packet size including the FCoE header and trailer, |
| 369 | * but not including any Ethernet or VLAN headers. |
| 370 | */ |
| 371 | static inline u32 fcoe_ctlr_fcoe_size(struct fcoe_ctlr *fip) |
| 372 | { |
| 373 | /* |
| 374 | * Determine the max FCoE frame size allowed, including |
| 375 | * FCoE header and trailer. |
| 376 | * Note: lp->mfs is currently the payload size, not the frame size. |
| 377 | */ |
| 378 | return fip->lp->mfs + sizeof(struct fc_frame_header) + |
| 379 | sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof); |
| 380 | } |
| 381 | |
| 382 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 383 | * fcoe_ctlr_solicit() - Send a FIP solicitation |
| 384 | * @fip: The FCoE controller to send the solicitation on |
| 385 | * @fcf: The destination FCF (if NULL, a multicast solicitation is sent) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 386 | */ |
| 387 | static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf) |
| 388 | { |
| 389 | struct sk_buff *skb; |
| 390 | struct fip_sol { |
| 391 | struct ethhdr eth; |
| 392 | struct fip_header fip; |
| 393 | struct { |
| 394 | struct fip_mac_desc mac; |
| 395 | struct fip_wwn_desc wwnn; |
| 396 | struct fip_size_desc size; |
Yi Zou | 0095a92 | 2011-01-28 16:05:00 -0800 | [diff] [blame] | 397 | } __packed desc; |
| 398 | } __packed * sol; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 399 | u32 fcoe_size; |
| 400 | |
| 401 | skb = dev_alloc_skb(sizeof(*sol)); |
| 402 | if (!skb) |
| 403 | return; |
| 404 | |
| 405 | sol = (struct fip_sol *)skb->data; |
| 406 | |
| 407 | memset(sol, 0, sizeof(*sol)); |
| 408 | memcpy(sol->eth.h_dest, fcf ? fcf->fcf_mac : fcoe_all_fcfs, ETH_ALEN); |
| 409 | memcpy(sol->eth.h_source, fip->ctl_src_addr, ETH_ALEN); |
| 410 | sol->eth.h_proto = htons(ETH_P_FIP); |
| 411 | |
| 412 | sol->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 413 | sol->fip.fip_op = htons(FIP_OP_DISC); |
| 414 | sol->fip.fip_subcode = FIP_SC_SOL; |
| 415 | sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW); |
| 416 | sol->fip.fip_flags = htons(FIP_FL_FPMA); |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 417 | if (fip->spma) |
| 418 | sol->fip.fip_flags |= htons(FIP_FL_SPMA); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 419 | |
| 420 | sol->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC; |
| 421 | sol->desc.mac.fd_desc.fip_dlen = sizeof(sol->desc.mac) / FIP_BPW; |
| 422 | memcpy(sol->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); |
| 423 | |
| 424 | sol->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME; |
| 425 | sol->desc.wwnn.fd_desc.fip_dlen = sizeof(sol->desc.wwnn) / FIP_BPW; |
| 426 | put_unaligned_be64(fip->lp->wwnn, &sol->desc.wwnn.fd_wwn); |
| 427 | |
| 428 | fcoe_size = fcoe_ctlr_fcoe_size(fip); |
| 429 | sol->desc.size.fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; |
| 430 | sol->desc.size.fd_desc.fip_dlen = sizeof(sol->desc.size) / FIP_BPW; |
| 431 | sol->desc.size.fd_size = htons(fcoe_size); |
| 432 | |
| 433 | skb_put(skb, sizeof(*sol)); |
Chris Leech | 0f49153 | 2009-05-06 10:52:18 -0700 | [diff] [blame] | 434 | skb->protocol = htons(ETH_P_FIP); |
john fastabend | 6f6c2aa | 2011-11-18 13:35:56 -0800 | [diff] [blame] | 435 | skb->priority = fip->priority; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 436 | skb_reset_mac_header(skb); |
| 437 | skb_reset_network_header(skb); |
| 438 | fip->send(fip, skb); |
| 439 | |
| 440 | if (!fcf) |
| 441 | fip->sol_time = jiffies; |
| 442 | } |
| 443 | |
| 444 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 445 | * fcoe_ctlr_link_up() - Start FCoE controller |
| 446 | * @fip: The FCoE controller to start |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 447 | * |
| 448 | * Called from the LLD when the network link is ready. |
| 449 | */ |
| 450 | void fcoe_ctlr_link_up(struct fcoe_ctlr *fip) |
| 451 | { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 452 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 453 | if (fip->state == FIP_ST_NON_FIP || fip->state == FIP_ST_AUTO) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 454 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 455 | fc_linkup(fip->lp); |
| 456 | } else if (fip->state == FIP_ST_LINK_WAIT) { |
Sedat Dilek | 8beb90a | 2019-02-15 13:19:20 +0100 | [diff] [blame] | 457 | if (fip->mode == FIP_MODE_NON_FIP) |
| 458 | fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP); |
| 459 | else |
| 460 | fcoe_ctlr_set_state(fip, FIP_ST_AUTO); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 461 | switch (fip->mode) { |
| 462 | default: |
| 463 | LIBFCOE_FIP_DBG(fip, "invalid mode %d\n", fip->mode); |
| 464 | /* fall-through */ |
| 465 | case FIP_MODE_AUTO: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 466 | LIBFCOE_FIP_DBG(fip, "%s", "setting AUTO mode.\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 467 | /* fall-through */ |
| 468 | case FIP_MODE_FABRIC: |
| 469 | case FIP_MODE_NON_FIP: |
| 470 | mutex_unlock(&fip->ctlr_mutex); |
| 471 | fc_linkup(fip->lp); |
| 472 | fcoe_ctlr_solicit(fip, NULL); |
| 473 | break; |
| 474 | case FIP_MODE_VN2VN: |
| 475 | fcoe_ctlr_vn_start(fip); |
| 476 | mutex_unlock(&fip->ctlr_mutex); |
| 477 | fc_linkup(fip->lp); |
| 478 | break; |
| 479 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 480 | } else |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 481 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 482 | } |
| 483 | EXPORT_SYMBOL(fcoe_ctlr_link_up); |
| 484 | |
| 485 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 486 | * fcoe_ctlr_reset() - Reset a FCoE controller |
| 487 | * @fip: The FCoE controller to reset |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 488 | */ |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 489 | static void fcoe_ctlr_reset(struct fcoe_ctlr *fip) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 490 | { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 491 | fcoe_ctlr_reset_fcfs(fip); |
| 492 | del_timer(&fip->timer); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 493 | fip->ctlr_ka_time = 0; |
| 494 | fip->port_ka_time = 0; |
| 495 | fip->sol_time = 0; |
| 496 | fip->flogi_oxid = FC_XID_UNKNOWN; |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 497 | fcoe_ctlr_map_dest(fip); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 501 | * fcoe_ctlr_link_down() - Stop a FCoE controller |
| 502 | * @fip: The FCoE controller to be stopped |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 503 | * |
| 504 | * Returns non-zero if the link was up and now isn't. |
| 505 | * |
| 506 | * Called from the LLD when the network link is not ready. |
| 507 | * There may be multiple calls while the link is down. |
| 508 | */ |
| 509 | int fcoe_ctlr_link_down(struct fcoe_ctlr *fip) |
| 510 | { |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 511 | int link_dropped; |
| 512 | |
| 513 | LIBFCOE_FIP_DBG(fip, "link down.\n"); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 514 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 515 | fcoe_ctlr_reset(fip); |
Joe Eykholt | 4291365 | 2010-03-12 16:08:23 -0800 | [diff] [blame] | 516 | link_dropped = fip->state != FIP_ST_LINK_WAIT; |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 517 | fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 518 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 519 | |
| 520 | if (link_dropped) |
| 521 | fc_linkdown(fip->lp); |
| 522 | return link_dropped; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 523 | } |
| 524 | EXPORT_SYMBOL(fcoe_ctlr_link_down); |
| 525 | |
| 526 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 527 | * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF |
| 528 | * @fip: The FCoE controller to send the FKA on |
| 529 | * @lport: libfc fc_lport to send from |
| 530 | * @ports: 0 for controller keep-alive, 1 for port keep-alive |
| 531 | * @sa: The source MAC address |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 532 | * |
| 533 | * A controller keep-alive is sent every fka_period (typically 8 seconds). |
| 534 | * The source MAC is the native MAC address. |
| 535 | * |
| 536 | * A port keep-alive is sent every 90 seconds while logged in. |
| 537 | * The source MAC is the assigned mapped source address. |
| 538 | * The destination is the FCF's F-port. |
| 539 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 540 | static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip, |
| 541 | struct fc_lport *lport, |
| 542 | int ports, u8 *sa) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 543 | { |
| 544 | struct sk_buff *skb; |
| 545 | struct fip_kal { |
| 546 | struct ethhdr eth; |
| 547 | struct fip_header fip; |
| 548 | struct fip_mac_desc mac; |
Yi Zou | 0095a92 | 2011-01-28 16:05:00 -0800 | [diff] [blame] | 549 | } __packed * kal; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 550 | struct fip_vn_desc *vn; |
| 551 | u32 len; |
| 552 | struct fc_lport *lp; |
| 553 | struct fcoe_fcf *fcf; |
| 554 | |
| 555 | fcf = fip->sel_fcf; |
| 556 | lp = fip->lp; |
Joe Eykholt | 281ae64 | 2010-06-11 16:43:33 -0700 | [diff] [blame] | 557 | if (!fcf || (ports && !lp->port_id)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 558 | return; |
| 559 | |
Yi Zou | be276cb | 2009-11-03 11:50:16 -0800 | [diff] [blame] | 560 | len = sizeof(*kal) + ports * sizeof(*vn); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 561 | skb = dev_alloc_skb(len); |
| 562 | if (!skb) |
| 563 | return; |
| 564 | |
| 565 | kal = (struct fip_kal *)skb->data; |
| 566 | memset(kal, 0, len); |
| 567 | memcpy(kal->eth.h_dest, fcf->fcf_mac, ETH_ALEN); |
| 568 | memcpy(kal->eth.h_source, sa, ETH_ALEN); |
| 569 | kal->eth.h_proto = htons(ETH_P_FIP); |
| 570 | |
| 571 | kal->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 572 | kal->fip.fip_op = htons(FIP_OP_CTRL); |
| 573 | kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE; |
| 574 | kal->fip.fip_dl_len = htons((sizeof(kal->mac) + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 575 | ports * sizeof(*vn)) / FIP_BPW); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 576 | kal->fip.fip_flags = htons(FIP_FL_FPMA); |
Vasu Dev | 184dd34 | 2009-05-17 12:33:28 +0000 | [diff] [blame] | 577 | if (fip->spma) |
| 578 | kal->fip.fip_flags |= htons(FIP_FL_SPMA); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 579 | |
| 580 | kal->mac.fd_desc.fip_dtype = FIP_DT_MAC; |
| 581 | kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW; |
| 582 | memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 583 | if (ports) { |
| 584 | vn = (struct fip_vn_desc *)(kal + 1); |
| 585 | vn->fd_desc.fip_dtype = FIP_DT_VN_ID; |
| 586 | vn->fd_desc.fip_dlen = sizeof(*vn) / FIP_BPW; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 587 | memcpy(vn->fd_mac, fip->get_src_addr(lport), ETH_ALEN); |
Kaladhar Musunuru | fb83153 | 2010-05-07 15:18:57 -0700 | [diff] [blame] | 588 | hton24(vn->fd_fc_id, lport->port_id); |
| 589 | put_unaligned_be64(lport->wwpn, &vn->fd_wwpn); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 590 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 591 | skb_put(skb, len); |
Chris Leech | 0f49153 | 2009-05-06 10:52:18 -0700 | [diff] [blame] | 592 | skb->protocol = htons(ETH_P_FIP); |
john fastabend | 6f6c2aa | 2011-11-18 13:35:56 -0800 | [diff] [blame] | 593 | skb->priority = fip->priority; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 594 | skb_reset_mac_header(skb); |
| 595 | skb_reset_network_header(skb); |
| 596 | fip->send(fip, skb); |
| 597 | } |
| 598 | |
| 599 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 600 | * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it |
| 601 | * @fip: The FCoE controller for the ELS frame |
| 602 | * @dtype: The FIP descriptor type for the frame |
| 603 | * @skb: The FCoE ELS frame including FC header but no FCoE headers |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 604 | * @d_id: The destination port ID. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 605 | * |
| 606 | * Returns non-zero error code on failure. |
| 607 | * |
| 608 | * The caller must check that the length is a multiple of 4. |
| 609 | * |
| 610 | * The @skb must have enough headroom (28 bytes) and tailroom (8 bytes). |
| 611 | * Headroom includes the FIP encapsulation description, FIP header, and |
| 612 | * Ethernet header. The tailroom is for the FIP MAC descriptor. |
| 613 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 614 | static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip, struct fc_lport *lport, |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 615 | u8 dtype, struct sk_buff *skb, u32 d_id) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 616 | { |
| 617 | struct fip_encaps_head { |
| 618 | struct ethhdr eth; |
| 619 | struct fip_header fip; |
| 620 | struct fip_encaps encaps; |
Yi Zou | 0095a92 | 2011-01-28 16:05:00 -0800 | [diff] [blame] | 621 | } __packed * cap; |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 622 | struct fc_frame_header *fh; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 623 | struct fip_mac_desc *mac; |
| 624 | struct fcoe_fcf *fcf; |
| 625 | size_t dlen; |
Yi Zou | 5a84bae | 2009-07-29 17:03:55 -0700 | [diff] [blame] | 626 | u16 fip_flags; |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 627 | u8 op; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 628 | |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 629 | fh = (struct fc_frame_header *)skb->data; |
| 630 | op = *(u8 *)(fh + 1); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 631 | dlen = sizeof(struct fip_encaps) + skb->len; /* len before push */ |
Johannes Berg | d58ff35 | 2017-06-16 14:29:23 +0200 | [diff] [blame] | 632 | cap = skb_push(skb, sizeof(*cap)); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 633 | memset(cap, 0, sizeof(*cap)); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 634 | |
| 635 | if (lport->point_to_multipoint) { |
| 636 | if (fcoe_ctlr_vn_lookup(fip, d_id, cap->eth.h_dest)) |
| 637 | return -ENODEV; |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 638 | fip_flags = 0; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 639 | } else { |
| 640 | fcf = fip->sel_fcf; |
| 641 | if (!fcf) |
| 642 | return -ENODEV; |
| 643 | fip_flags = fcf->flags; |
| 644 | fip_flags &= fip->spma ? FIP_FL_SPMA | FIP_FL_FPMA : |
| 645 | FIP_FL_FPMA; |
| 646 | if (!fip_flags) |
| 647 | return -ENODEV; |
| 648 | memcpy(cap->eth.h_dest, fcf->fcf_mac, ETH_ALEN); |
| 649 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 650 | memcpy(cap->eth.h_source, fip->ctl_src_addr, ETH_ALEN); |
| 651 | cap->eth.h_proto = htons(ETH_P_FIP); |
| 652 | |
| 653 | cap->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 654 | cap->fip.fip_op = htons(FIP_OP_LS); |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 655 | if (op == ELS_LS_ACC || op == ELS_LS_RJT) |
| 656 | cap->fip.fip_subcode = FIP_SC_REP; |
| 657 | else |
| 658 | cap->fip.fip_subcode = FIP_SC_REQ; |
Yi Zou | 5a84bae | 2009-07-29 17:03:55 -0700 | [diff] [blame] | 659 | cap->fip.fip_flags = htons(fip_flags); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 660 | |
| 661 | cap->encaps.fd_desc.fip_dtype = dtype; |
| 662 | cap->encaps.fd_desc.fip_dlen = dlen / FIP_BPW; |
| 663 | |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 664 | if (op != ELS_LS_RJT) { |
| 665 | dlen += sizeof(*mac); |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 666 | mac = skb_put_zero(skb, sizeof(*mac)); |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 667 | mac->fd_desc.fip_dtype = FIP_DT_MAC; |
| 668 | mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW; |
| 669 | if (dtype != FIP_DT_FLOGI && dtype != FIP_DT_FDISC) { |
| 670 | memcpy(mac->fd_mac, fip->get_src_addr(lport), ETH_ALEN); |
| 671 | } else if (fip->mode == FIP_MODE_VN2VN) { |
| 672 | hton24(mac->fd_mac, FIP_VN_FC_MAP); |
| 673 | hton24(mac->fd_mac + 3, fip->port_id); |
| 674 | } else if (fip_flags & FIP_FL_SPMA) { |
| 675 | LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with SPMA\n"); |
| 676 | memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN); |
| 677 | } else { |
| 678 | LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with FPMA\n"); |
| 679 | /* FPMA only FLOGI. Must leave the MAC desc zeroed. */ |
| 680 | } |
Robert Love | 593abc0 | 2010-04-09 14:22:17 -0700 | [diff] [blame] | 681 | } |
Joe Eykholt | 5554345 | 2010-07-20 15:20:35 -0700 | [diff] [blame] | 682 | cap->fip.fip_dl_len = htons(dlen / FIP_BPW); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 683 | |
Chris Leech | 0f49153 | 2009-05-06 10:52:18 -0700 | [diff] [blame] | 684 | skb->protocol = htons(ETH_P_FIP); |
john fastabend | 6f6c2aa | 2011-11-18 13:35:56 -0800 | [diff] [blame] | 685 | skb->priority = fip->priority; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 686 | skb_reset_mac_header(skb); |
| 687 | skb_reset_network_header(skb); |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | /** |
| 692 | * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate. |
| 693 | * @fip: FCoE controller. |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 694 | * @lport: libfc fc_lport to send from |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 695 | * @skb: FCoE ELS frame including FC header but no FCoE headers. |
| 696 | * |
| 697 | * Returns a non-zero error code if the frame should not be sent. |
| 698 | * Returns zero if the caller should send the frame with FCoE encapsulation. |
| 699 | * |
| 700 | * The caller must check that the length is a multiple of 4. |
| 701 | * The SKB must have enough headroom (28 bytes) and tailroom (8 bytes). |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 702 | * The the skb must also be an fc_frame. |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 703 | * |
| 704 | * This is called from the lower-level driver with spinlocks held, |
| 705 | * so we must not take a mutex here. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 706 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 707 | int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct fc_lport *lport, |
| 708 | struct sk_buff *skb) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 709 | { |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 710 | struct fc_frame *fp; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 711 | struct fc_frame_header *fh; |
| 712 | u16 old_xid; |
| 713 | u8 op; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 714 | u8 mac[ETH_ALEN]; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 715 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 716 | fp = container_of(skb, struct fc_frame, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 717 | fh = (struct fc_frame_header *)skb->data; |
| 718 | op = *(u8 *)(fh + 1); |
| 719 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 720 | if (op == ELS_FLOGI && fip->mode != FIP_MODE_VN2VN) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 721 | old_xid = fip->flogi_oxid; |
| 722 | fip->flogi_oxid = ntohs(fh->fh_ox_id); |
| 723 | if (fip->state == FIP_ST_AUTO) { |
| 724 | if (old_xid == FC_XID_UNKNOWN) |
| 725 | fip->flogi_count = 0; |
| 726 | fip->flogi_count++; |
| 727 | if (fip->flogi_count < 3) |
| 728 | goto drop; |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 729 | fcoe_ctlr_map_dest(fip); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 730 | return 0; |
| 731 | } |
Joe Eykholt | 5f48f70 | 2009-05-06 10:52:12 -0700 | [diff] [blame] | 732 | if (fip->state == FIP_ST_NON_FIP) |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 733 | fcoe_ctlr_map_dest(fip); |
Joe Eykholt | 5f48f70 | 2009-05-06 10:52:12 -0700 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | if (fip->state == FIP_ST_NON_FIP) |
| 737 | return 0; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 738 | if (!fip->sel_fcf && fip->mode != FIP_MODE_VN2VN) |
Joe Eykholt | f31f2a1 | 2009-11-03 11:48:32 -0800 | [diff] [blame] | 739 | goto drop; |
Joe Eykholt | 5f48f70 | 2009-05-06 10:52:12 -0700 | [diff] [blame] | 740 | switch (op) { |
| 741 | case ELS_FLOGI: |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 742 | op = FIP_DT_FLOGI; |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 743 | if (fip->mode == FIP_MODE_VN2VN) |
| 744 | break; |
| 745 | spin_lock_bh(&fip->ctlr_lock); |
| 746 | kfree_skb(fip->flogi_req); |
| 747 | fip->flogi_req = skb; |
| 748 | fip->flogi_req_send = 1; |
| 749 | spin_unlock_bh(&fip->ctlr_lock); |
| 750 | schedule_work(&fip->timer_work); |
| 751 | return -EINPROGRESS; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 752 | case ELS_FDISC: |
| 753 | if (ntoh24(fh->fh_s_id)) |
| 754 | return 0; |
| 755 | op = FIP_DT_FDISC; |
| 756 | break; |
| 757 | case ELS_LOGO: |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 758 | if (fip->mode == FIP_MODE_VN2VN) { |
| 759 | if (fip->state != FIP_ST_VNMP_UP) |
Johannes Thumshirn | 63d0e3d | 2018-07-31 15:46:02 +0200 | [diff] [blame] | 760 | goto drop; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 761 | if (ntoh24(fh->fh_d_id) == FC_FID_FLOGI) |
Johannes Thumshirn | 63d0e3d | 2018-07-31 15:46:02 +0200 | [diff] [blame] | 762 | goto drop; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 763 | } else { |
| 764 | if (fip->state != FIP_ST_ENABLED) |
| 765 | return 0; |
| 766 | if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI) |
| 767 | return 0; |
| 768 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 769 | op = FIP_DT_LOGO; |
| 770 | break; |
| 771 | case ELS_LS_ACC: |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 772 | /* |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 773 | * If non-FIP, we may have gotten an SID by accepting an FLOGI |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 774 | * from a point-to-point connection. Switch to using |
| 775 | * the source mac based on the SID. The destination |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 776 | * MAC in this case would have been set by receiving the |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 777 | * FLOGI. |
| 778 | */ |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 779 | if (fip->state == FIP_ST_NON_FIP) { |
| 780 | if (fip->flogi_oxid == FC_XID_UNKNOWN) |
| 781 | return 0; |
| 782 | fip->flogi_oxid = FC_XID_UNKNOWN; |
| 783 | fc_fcoe_set_mac(mac, fh->fh_d_id); |
| 784 | fip->update_mac(lport, mac); |
| 785 | } |
| 786 | /* fall through */ |
| 787 | case ELS_LS_RJT: |
| 788 | op = fr_encaps(fp); |
| 789 | if (op) |
| 790 | break; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 791 | return 0; |
| 792 | default: |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 793 | if (fip->state != FIP_ST_ENABLED && |
| 794 | fip->state != FIP_ST_VNMP_UP) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 795 | goto drop; |
| 796 | return 0; |
| 797 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 798 | LIBFCOE_FIP_DBG(fip, "els_send op %u d_id %x\n", |
| 799 | op, ntoh24(fh->fh_d_id)); |
| 800 | if (fcoe_ctlr_encaps(fip, lport, op, skb, ntoh24(fh->fh_d_id))) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 801 | goto drop; |
| 802 | fip->send(fip, skb); |
| 803 | return -EINPROGRESS; |
| 804 | drop: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 805 | LIBFCOE_FIP_DBG(fip, "drop els_send op %u d_id %x\n", |
| 806 | op, ntoh24(fh->fh_d_id)); |
Johannes Thumshirn | 2d7d4fd | 2018-07-31 15:46:01 +0200 | [diff] [blame] | 807 | kfree_skb(skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 808 | return -EINVAL; |
| 809 | } |
| 810 | EXPORT_SYMBOL(fcoe_ctlr_els_send); |
| 811 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 812 | /** |
| 813 | * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller |
| 814 | * @fip: The FCoE controller to free FCFs on |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 815 | * |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 816 | * Called with lock held and preemption disabled. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 817 | * |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 818 | * An FCF is considered old if we have missed two advertisements. |
| 819 | * That is, there have been no valid advertisement from it for 2.5 |
| 820 | * times its keep-alive period. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 821 | * |
| 822 | * In addition, determine the time when an FCF selection can occur. |
Yi Zou | f3da80e7 | 2009-11-20 14:55:08 -0800 | [diff] [blame] | 823 | * |
| 824 | * Also, increment the MissDiscAdvCount when no advertisement is received |
| 825 | * for the corresponding FCF for 1.5 * FKA_ADV_PERIOD (FC-BB-5 LESB). |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 826 | * |
| 827 | * Returns the time in jiffies for the next call. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 828 | */ |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 829 | static unsigned long fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 830 | { |
| 831 | struct fcoe_fcf *fcf; |
| 832 | struct fcoe_fcf *next; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 833 | unsigned long next_timer = jiffies + msecs_to_jiffies(FIP_VN_KA_PERIOD); |
| 834 | unsigned long deadline; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 835 | unsigned long sel_time = 0; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 836 | struct list_head del_list; |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 837 | struct fc_stats *stats; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 838 | |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 839 | INIT_LIST_HEAD(&del_list); |
| 840 | |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 841 | stats = per_cpu_ptr(fip->lp->stats, get_cpu()); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 842 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 843 | list_for_each_entry_safe(fcf, next, &fip->fcfs, list) { |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 844 | deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2; |
| 845 | if (fip->sel_fcf == fcf) { |
| 846 | if (time_after(jiffies, deadline)) { |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 847 | stats->MissDiscAdvCount++; |
| 848 | printk(KERN_INFO "libfcoe: host%d: " |
| 849 | "Missing Discovery Advertisement " |
| 850 | "for fab %16.16llx count %lld\n", |
| 851 | fip->lp->host->host_no, fcf->fabric_name, |
| 852 | stats->MissDiscAdvCount); |
| 853 | } else if (time_after(next_timer, deadline)) |
| 854 | next_timer = deadline; |
Yi Zou | f3da80e7 | 2009-11-20 14:55:08 -0800 | [diff] [blame] | 855 | } |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 856 | |
| 857 | deadline += fcf->fka_period; |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 858 | if (time_after_eq(jiffies, deadline)) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 859 | if (fip->sel_fcf == fcf) |
| 860 | fip->sel_fcf = NULL; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 861 | /* |
| 862 | * Move to delete list so we can call |
| 863 | * fcoe_sysfs_fcf_del (which can sleep) |
| 864 | * after the put_cpu(). |
| 865 | */ |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 866 | list_del(&fcf->list); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 867 | list_add(&fcf->list, &del_list); |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 868 | stats->VLinkFailureCount++; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 869 | } else { |
| 870 | if (time_after(next_timer, deadline)) |
| 871 | next_timer = deadline; |
| 872 | if (fcoe_ctlr_mtu_valid(fcf) && |
| 873 | (!sel_time || time_before(sel_time, fcf->time))) |
| 874 | sel_time = fcf->time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 875 | } |
| 876 | } |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 877 | put_cpu(); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 878 | |
| 879 | list_for_each_entry_safe(fcf, next, &del_list, list) { |
| 880 | /* Removes fcf from current list */ |
| 881 | fcoe_sysfs_fcf_del(fcf); |
| 882 | } |
| 883 | |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 884 | if (sel_time && !fip->sel_fcf && !fip->sel_time) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 885 | sel_time += msecs_to_jiffies(FCOE_CTLR_START_DELAY); |
| 886 | fip->sel_time = sel_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 887 | } |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 888 | |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 889 | return next_timer; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 893 | * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 894 | * @fip: The FCoE controller receiving the advertisement |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 895 | * @skb: The received FIP advertisement frame |
| 896 | * @fcf: The resulting FCF entry |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 897 | * |
| 898 | * Returns zero on a valid parsed advertisement, |
| 899 | * otherwise returns non zero value. |
| 900 | */ |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 901 | static int fcoe_ctlr_parse_adv(struct fcoe_ctlr *fip, |
| 902 | struct sk_buff *skb, struct fcoe_fcf *fcf) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 903 | { |
| 904 | struct fip_header *fiph; |
| 905 | struct fip_desc *desc = NULL; |
| 906 | struct fip_wwn_desc *wwn; |
| 907 | struct fip_fab_desc *fab; |
| 908 | struct fip_fka_desc *fka; |
| 909 | unsigned long t; |
| 910 | size_t rlen; |
| 911 | size_t dlen; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 912 | u32 desc_mask; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 913 | |
| 914 | memset(fcf, 0, sizeof(*fcf)); |
| 915 | fcf->fka_period = msecs_to_jiffies(FCOE_CTLR_DEF_FKA); |
| 916 | |
| 917 | fiph = (struct fip_header *)skb->data; |
| 918 | fcf->flags = ntohs(fiph->fip_flags); |
| 919 | |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 920 | /* |
| 921 | * mask of required descriptors. validating each one clears its bit. |
| 922 | */ |
| 923 | desc_mask = BIT(FIP_DT_PRI) | BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | |
| 924 | BIT(FIP_DT_FAB) | BIT(FIP_DT_FKA); |
| 925 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 926 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 927 | if (rlen + sizeof(*fiph) > skb->len) |
| 928 | return -EINVAL; |
| 929 | |
| 930 | desc = (struct fip_desc *)(fiph + 1); |
| 931 | while (rlen > 0) { |
| 932 | dlen = desc->fip_dlen * FIP_BPW; |
| 933 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 934 | return -EINVAL; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 935 | /* Drop Adv if there are duplicate critical descriptors */ |
| 936 | if ((desc->fip_dtype < 32) && |
| 937 | !(desc_mask & 1U << desc->fip_dtype)) { |
| 938 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 939 | "Descriptors in FIP adv\n"); |
| 940 | return -EINVAL; |
| 941 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 942 | switch (desc->fip_dtype) { |
| 943 | case FIP_DT_PRI: |
| 944 | if (dlen != sizeof(struct fip_pri_desc)) |
| 945 | goto len_err; |
| 946 | fcf->pri = ((struct fip_pri_desc *)desc)->fd_pri; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 947 | desc_mask &= ~BIT(FIP_DT_PRI); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 948 | break; |
| 949 | case FIP_DT_MAC: |
| 950 | if (dlen != sizeof(struct fip_mac_desc)) |
| 951 | goto len_err; |
| 952 | memcpy(fcf->fcf_mac, |
| 953 | ((struct fip_mac_desc *)desc)->fd_mac, |
| 954 | ETH_ALEN); |
Bhanu Prakash Gollapudi | 81c11dd | 2012-03-09 14:50:03 -0800 | [diff] [blame] | 955 | memcpy(fcf->fcoe_mac, fcf->fcf_mac, ETH_ALEN); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 956 | if (!is_valid_ether_addr(fcf->fcf_mac)) { |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 957 | LIBFCOE_FIP_DBG(fip, |
| 958 | "Invalid MAC addr %pM in FIP adv\n", |
| 959 | fcf->fcf_mac); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 960 | return -EINVAL; |
| 961 | } |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 962 | desc_mask &= ~BIT(FIP_DT_MAC); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 963 | break; |
| 964 | case FIP_DT_NAME: |
| 965 | if (dlen != sizeof(struct fip_wwn_desc)) |
| 966 | goto len_err; |
| 967 | wwn = (struct fip_wwn_desc *)desc; |
| 968 | fcf->switch_name = get_unaligned_be64(&wwn->fd_wwn); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 969 | desc_mask &= ~BIT(FIP_DT_NAME); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 970 | break; |
| 971 | case FIP_DT_FAB: |
| 972 | if (dlen != sizeof(struct fip_fab_desc)) |
| 973 | goto len_err; |
| 974 | fab = (struct fip_fab_desc *)desc; |
| 975 | fcf->fabric_name = get_unaligned_be64(&fab->fd_wwn); |
| 976 | fcf->vfid = ntohs(fab->fd_vfid); |
| 977 | fcf->fc_map = ntoh24(fab->fd_map); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 978 | desc_mask &= ~BIT(FIP_DT_FAB); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 979 | break; |
| 980 | case FIP_DT_FKA: |
| 981 | if (dlen != sizeof(struct fip_fka_desc)) |
| 982 | goto len_err; |
| 983 | fka = (struct fip_fka_desc *)desc; |
Yi Zou | 8cdffdc | 2009-11-20 14:54:57 -0800 | [diff] [blame] | 984 | if (fka->fd_flags & FIP_FKA_ADV_D) |
| 985 | fcf->fd_flags = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 986 | t = ntohl(fka->fd_fka_period); |
| 987 | if (t >= FCOE_CTLR_MIN_FKA) |
| 988 | fcf->fka_period = msecs_to_jiffies(t); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 989 | desc_mask &= ~BIT(FIP_DT_FKA); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 990 | break; |
| 991 | case FIP_DT_MAP_OUI: |
| 992 | case FIP_DT_FCOE_SIZE: |
| 993 | case FIP_DT_FLOGI: |
| 994 | case FIP_DT_FDISC: |
| 995 | case FIP_DT_LOGO: |
| 996 | case FIP_DT_ELP: |
| 997 | default: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 998 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 999 | "in FIP adv\n", desc->fip_dtype); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1000 | /* standard says ignore unknown descriptors >= 128 */ |
Hannes Reinecke | 6a551c1 | 2016-07-04 10:29:18 +0200 | [diff] [blame] | 1001 | if (desc->fip_dtype < FIP_DT_NON_CRITICAL) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1002 | return -EINVAL; |
Bhanu Prakash Gollapudi | 1508f3ec | 2010-06-11 16:43:38 -0700 | [diff] [blame] | 1003 | break; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1004 | } |
| 1005 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 1006 | rlen -= dlen; |
| 1007 | } |
| 1008 | if (!fcf->fc_map || (fcf->fc_map & 0x10000)) |
| 1009 | return -EINVAL; |
Vasu Dev | 240778e | 2010-07-20 15:21:33 -0700 | [diff] [blame] | 1010 | if (!fcf->switch_name) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1011 | return -EINVAL; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1012 | if (desc_mask) { |
| 1013 | LIBFCOE_FIP_DBG(fip, "adv missing descriptors mask %x\n", |
| 1014 | desc_mask); |
| 1015 | return -EINVAL; |
| 1016 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1017 | return 0; |
| 1018 | |
| 1019 | len_err: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1020 | LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n", |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1021 | desc->fip_dtype, dlen); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1022 | return -EINVAL; |
| 1023 | } |
| 1024 | |
| 1025 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1026 | * fcoe_ctlr_recv_adv() - Handle an incoming advertisement |
| 1027 | * @fip: The FCoE controller receiving the advertisement |
| 1028 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1029 | */ |
| 1030 | static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1031 | { |
| 1032 | struct fcoe_fcf *fcf; |
| 1033 | struct fcoe_fcf new; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1034 | unsigned long sol_tov = msecs_to_jiffies(FCOE_CTRL_SOL_TOV); |
| 1035 | int first = 0; |
| 1036 | int mtu_valid; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1037 | int found = 0; |
| 1038 | int rc = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1039 | |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1040 | if (fcoe_ctlr_parse_adv(fip, skb, &new)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1041 | return; |
| 1042 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1043 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1044 | first = list_empty(&fip->fcfs); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1045 | list_for_each_entry(fcf, &fip->fcfs, list) { |
| 1046 | if (fcf->switch_name == new.switch_name && |
| 1047 | fcf->fabric_name == new.fabric_name && |
| 1048 | fcf->fc_map == new.fc_map && |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 1049 | ether_addr_equal(fcf->fcf_mac, new.fcf_mac)) { |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1050 | found = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1051 | break; |
| 1052 | } |
| 1053 | } |
| 1054 | if (!found) { |
| 1055 | if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT) |
| 1056 | goto out; |
| 1057 | |
| 1058 | fcf = kmalloc(sizeof(*fcf), GFP_ATOMIC); |
| 1059 | if (!fcf) |
| 1060 | goto out; |
| 1061 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1062 | memcpy(fcf, &new, sizeof(new)); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1063 | fcf->fip = fip; |
| 1064 | rc = fcoe_sysfs_fcf_add(fcf); |
| 1065 | if (rc) { |
| 1066 | printk(KERN_ERR "Failed to allocate sysfs instance " |
| 1067 | "for FCF, fab %16.16llx mac %pM\n", |
| 1068 | new.fabric_name, new.fcf_mac); |
| 1069 | kfree(fcf); |
| 1070 | goto out; |
| 1071 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1072 | } else { |
| 1073 | /* |
Joe Eykholt | c600fea | 2010-06-11 16:44:20 -0700 | [diff] [blame] | 1074 | * Update the FCF's keep-alive descriptor flags. |
| 1075 | * Other flag changes from new advertisements are |
| 1076 | * ignored after a solicited advertisement is |
| 1077 | * received and the FCF is selectable (usable). |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1078 | */ |
Joe Eykholt | c600fea | 2010-06-11 16:44:20 -0700 | [diff] [blame] | 1079 | fcf->fd_flags = new.fd_flags; |
| 1080 | if (!fcoe_ctlr_fcf_usable(fcf)) |
| 1081 | fcf->flags = new.flags; |
| 1082 | |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 1083 | if (fcf == fip->sel_fcf && !fcf->fd_flags) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1084 | fip->ctlr_ka_time -= fcf->fka_period; |
| 1085 | fip->ctlr_ka_time += new.fka_period; |
| 1086 | if (time_before(fip->ctlr_ka_time, fip->timer.expires)) |
| 1087 | mod_timer(&fip->timer, fip->ctlr_ka_time); |
Joe Eykholt | c600fea | 2010-06-11 16:44:20 -0700 | [diff] [blame] | 1088 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1089 | fcf->fka_period = new.fka_period; |
| 1090 | memcpy(fcf->fcf_mac, new.fcf_mac, ETH_ALEN); |
| 1091 | } |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1092 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1093 | mtu_valid = fcoe_ctlr_mtu_valid(fcf); |
| 1094 | fcf->time = jiffies; |
Joe Eykholt | 9069f5c | 2010-11-30 16:20:02 -0800 | [diff] [blame] | 1095 | if (!found) |
| 1096 | LIBFCOE_FIP_DBG(fip, "New FCF fab %16.16llx mac %pM\n", |
| 1097 | fcf->fabric_name, fcf->fcf_mac); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1098 | |
| 1099 | /* |
| 1100 | * If this advertisement is not solicited and our max receive size |
| 1101 | * hasn't been verified, send a solicited advertisement. |
| 1102 | */ |
| 1103 | if (!mtu_valid) |
| 1104 | fcoe_ctlr_solicit(fip, fcf); |
| 1105 | |
| 1106 | /* |
| 1107 | * If its been a while since we did a solicit, and this is |
| 1108 | * the first advertisement we've received, do a multicast |
| 1109 | * solicitation to gather as many advertisements as we can |
| 1110 | * before selection occurs. |
| 1111 | */ |
| 1112 | if (first && time_after(jiffies, fip->sol_time + sol_tov)) |
| 1113 | fcoe_ctlr_solicit(fip, NULL); |
| 1114 | |
| 1115 | /* |
Joe Eykholt | 981c115 | 2010-11-30 16:20:07 -0800 | [diff] [blame] | 1116 | * Put this FCF at the head of the list for priority among equals. |
| 1117 | * This helps in the case of an NPV switch which insists we use |
| 1118 | * the FCF that answers multicast solicitations, not the others that |
| 1119 | * are sending periodic multicast advertisements. |
| 1120 | */ |
Kirill A. Shutemov | 63ce249 | 2011-04-01 16:06:09 -0700 | [diff] [blame] | 1121 | if (mtu_valid) |
| 1122 | list_move(&fcf->list, &fip->fcfs); |
Joe Eykholt | 981c115 | 2010-11-30 16:20:07 -0800 | [diff] [blame] | 1123 | |
| 1124 | /* |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1125 | * If this is the first validated FCF, note the time and |
| 1126 | * set a timer to trigger selection. |
| 1127 | */ |
Usha Ketineni | eac00c8 | 2016-02-29 03:36:52 -0800 | [diff] [blame] | 1128 | if (mtu_valid && !fip->sel_fcf && !fip->sel_time && |
| 1129 | fcoe_ctlr_fcf_usable(fcf)) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1130 | fip->sel_time = jiffies + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1131 | msecs_to_jiffies(FCOE_CTLR_START_DELAY); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1132 | if (!timer_pending(&fip->timer) || |
| 1133 | time_before(fip->sel_time, fip->timer.expires)) |
| 1134 | mod_timer(&fip->timer, fip->sel_time); |
| 1135 | } |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 1136 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1137 | out: |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1138 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1142 | * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame |
| 1143 | * @fip: The FCoE controller which received the packet |
| 1144 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1145 | */ |
| 1146 | static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1147 | { |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1148 | struct fc_lport *lport = fip->lp; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1149 | struct fip_header *fiph; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1150 | struct fc_frame *fp = (struct fc_frame *)skb; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1151 | struct fc_frame_header *fh = NULL; |
| 1152 | struct fip_desc *desc; |
| 1153 | struct fip_encaps *els; |
Bhanu Prakash Gollapudi | 81c11dd | 2012-03-09 14:50:03 -0800 | [diff] [blame] | 1154 | struct fcoe_fcf *sel; |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 1155 | struct fc_stats *stats; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1156 | enum fip_desc_type els_dtype = 0; |
| 1157 | u8 els_op; |
| 1158 | u8 sub; |
| 1159 | u8 granted_mac[ETH_ALEN] = { 0 }; |
| 1160 | size_t els_len = 0; |
| 1161 | size_t rlen; |
| 1162 | size_t dlen; |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1163 | u32 desc_mask = 0; |
| 1164 | u32 desc_cnt = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1165 | |
| 1166 | fiph = (struct fip_header *)skb->data; |
| 1167 | sub = fiph->fip_subcode; |
| 1168 | if (sub != FIP_SC_REQ && sub != FIP_SC_REP) |
| 1169 | goto drop; |
| 1170 | |
| 1171 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 1172 | if (rlen + sizeof(*fiph) > skb->len) |
| 1173 | goto drop; |
| 1174 | |
| 1175 | desc = (struct fip_desc *)(fiph + 1); |
| 1176 | while (rlen > 0) { |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1177 | desc_cnt++; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1178 | dlen = desc->fip_dlen * FIP_BPW; |
| 1179 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 1180 | goto drop; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1181 | /* Drop ELS if there are duplicate critical descriptors */ |
| 1182 | if (desc->fip_dtype < 32) { |
Bhanu Prakash Gollapudi | 81c11dd | 2012-03-09 14:50:03 -0800 | [diff] [blame] | 1183 | if ((desc->fip_dtype != FIP_DT_MAC) && |
| 1184 | (desc_mask & 1U << desc->fip_dtype)) { |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1185 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 1186 | "Descriptors in FIP ELS\n"); |
| 1187 | goto drop; |
| 1188 | } |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1189 | desc_mask |= (1 << desc->fip_dtype); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1190 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1191 | switch (desc->fip_dtype) { |
| 1192 | case FIP_DT_MAC: |
Bhanu Prakash Gollapudi | 81c11dd | 2012-03-09 14:50:03 -0800 | [diff] [blame] | 1193 | sel = fip->sel_fcf; |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1194 | if (desc_cnt == 1) { |
| 1195 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 1196 | "received out of order\n"); |
| 1197 | goto drop; |
| 1198 | } |
Bhanu Prakash Gollapudi | 81c11dd | 2012-03-09 14:50:03 -0800 | [diff] [blame] | 1199 | /* |
| 1200 | * Some switch implementations send two MAC descriptors, |
| 1201 | * with first MAC(granted_mac) being the FPMA, and the |
| 1202 | * second one(fcoe_mac) is used as destination address |
| 1203 | * for sending/receiving FCoE packets. FIP traffic is |
| 1204 | * sent using fip_mac. For regular switches, both |
| 1205 | * fip_mac and fcoe_mac would be the same. |
| 1206 | */ |
| 1207 | if (desc_cnt == 2) |
| 1208 | memcpy(granted_mac, |
| 1209 | ((struct fip_mac_desc *)desc)->fd_mac, |
| 1210 | ETH_ALEN); |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1211 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1212 | if (dlen != sizeof(struct fip_mac_desc)) |
| 1213 | goto len_err; |
Bhanu Prakash Gollapudi | 81c11dd | 2012-03-09 14:50:03 -0800 | [diff] [blame] | 1214 | |
| 1215 | if ((desc_cnt == 3) && (sel)) |
| 1216 | memcpy(sel->fcoe_mac, |
| 1217 | ((struct fip_mac_desc *)desc)->fd_mac, |
| 1218 | ETH_ALEN); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1219 | break; |
| 1220 | case FIP_DT_FLOGI: |
| 1221 | case FIP_DT_FDISC: |
| 1222 | case FIP_DT_LOGO: |
| 1223 | case FIP_DT_ELP: |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1224 | if (desc_cnt != 1) { |
| 1225 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 1226 | "received out of order\n"); |
| 1227 | goto drop; |
| 1228 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1229 | if (fh) |
| 1230 | goto drop; |
| 1231 | if (dlen < sizeof(*els) + sizeof(*fh) + 1) |
| 1232 | goto len_err; |
| 1233 | els_len = dlen - sizeof(*els); |
| 1234 | els = (struct fip_encaps *)desc; |
| 1235 | fh = (struct fc_frame_header *)(els + 1); |
| 1236 | els_dtype = desc->fip_dtype; |
| 1237 | break; |
| 1238 | default: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1239 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1240 | "in FIP adv\n", desc->fip_dtype); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1241 | /* standard says ignore unknown descriptors >= 128 */ |
Hannes Reinecke | 6a551c1 | 2016-07-04 10:29:18 +0200 | [diff] [blame] | 1242 | if (desc->fip_dtype < FIP_DT_NON_CRITICAL) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1243 | goto drop; |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1244 | if (desc_cnt <= 2) { |
| 1245 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 1246 | "received out of order\n"); |
| 1247 | goto drop; |
| 1248 | } |
Bhanu Prakash Gollapudi | 1508f3ec | 2010-06-11 16:43:38 -0700 | [diff] [blame] | 1249 | break; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1250 | } |
| 1251 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 1252 | rlen -= dlen; |
| 1253 | } |
| 1254 | |
| 1255 | if (!fh) |
| 1256 | goto drop; |
| 1257 | els_op = *(u8 *)(fh + 1); |
| 1258 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1259 | if ((els_dtype == FIP_DT_FLOGI || els_dtype == FIP_DT_FDISC) && |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1260 | sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) { |
| 1261 | if (els_op == ELS_LS_ACC) { |
| 1262 | if (!is_valid_ether_addr(granted_mac)) { |
| 1263 | LIBFCOE_FIP_DBG(fip, |
| 1264 | "Invalid MAC address %pM in FIP ELS\n", |
| 1265 | granted_mac); |
| 1266 | goto drop; |
| 1267 | } |
| 1268 | memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1269 | |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1270 | if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) { |
| 1271 | fip->flogi_oxid = FC_XID_UNKNOWN; |
| 1272 | if (els_dtype == FIP_DT_FLOGI) |
| 1273 | fcoe_ctlr_announce(fip); |
| 1274 | } |
| 1275 | } else if (els_dtype == FIP_DT_FLOGI && |
| 1276 | !fcoe_ctlr_flogi_retry(fip)) |
| 1277 | goto drop; /* retrying FLOGI so drop reject */ |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1278 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1279 | |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1280 | if ((desc_cnt == 0) || ((els_op != ELS_LS_RJT) && |
| 1281 | (!(1U << FIP_DT_MAC & desc_mask)))) { |
| 1282 | LIBFCOE_FIP_DBG(fip, "Missing critical descriptors " |
| 1283 | "in FIP ELS\n"); |
| 1284 | goto drop; |
| 1285 | } |
| 1286 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1287 | /* |
| 1288 | * Convert skb into an fc_frame containing only the ELS. |
| 1289 | */ |
| 1290 | skb_pull(skb, (u8 *)fh - skb->data); |
| 1291 | skb_trim(skb, els_len); |
| 1292 | fp = (struct fc_frame *)skb; |
| 1293 | fc_frame_init(fp); |
| 1294 | fr_sof(fp) = FC_SOF_I3; |
| 1295 | fr_eof(fp) = FC_EOF_T; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1296 | fr_dev(fp) = lport; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1297 | fr_encaps(fp) = els_dtype; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1298 | |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 1299 | stats = per_cpu_ptr(lport->stats, get_cpu()); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1300 | stats->RxFrames++; |
| 1301 | stats->RxWords += skb->len / FIP_BPW; |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 1302 | put_cpu(); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1303 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1304 | fc_exch_recv(lport, fp); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1305 | return; |
| 1306 | |
| 1307 | len_err: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1308 | LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n", |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1309 | desc->fip_dtype, dlen); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1310 | drop: |
| 1311 | kfree_skb(skb); |
| 1312 | } |
| 1313 | |
| 1314 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1315 | * fcoe_ctlr_recv_els() - Handle an incoming link reset frame |
| 1316 | * @fip: The FCoE controller that received the frame |
| 1317 | * @fh: The received FIP header |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1318 | * |
| 1319 | * There may be multiple VN_Port descriptors. |
| 1320 | * The overall length has already been checked. |
| 1321 | */ |
| 1322 | static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip, |
Chad Dupuis | fd37f66 | 2016-09-30 11:01:20 +0200 | [diff] [blame] | 1323 | struct sk_buff *skb) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1324 | { |
| 1325 | struct fip_desc *desc; |
| 1326 | struct fip_mac_desc *mp; |
| 1327 | struct fip_wwn_desc *wp; |
| 1328 | struct fip_vn_desc *vp; |
| 1329 | size_t rlen; |
| 1330 | size_t dlen; |
| 1331 | struct fcoe_fcf *fcf = fip->sel_fcf; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1332 | struct fc_lport *lport = fip->lp; |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1333 | struct fc_lport *vn_port = NULL; |
| 1334 | u32 desc_mask; |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1335 | int num_vlink_desc; |
| 1336 | int reset_phys_port = 0; |
| 1337 | struct fip_vn_desc **vlink_desc_arr = NULL; |
Chad Dupuis | fd37f66 | 2016-09-30 11:01:20 +0200 | [diff] [blame] | 1338 | struct fip_header *fh = (struct fip_header *)skb->data; |
| 1339 | struct ethhdr *eh = eth_hdr(skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1340 | |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1341 | LIBFCOE_FIP_DBG(fip, "Clear Virtual Link received\n"); |
Robert Love | d29510a | 2010-05-07 15:18:30 -0700 | [diff] [blame] | 1342 | |
Chad Dupuis | fd37f66 | 2016-09-30 11:01:20 +0200 | [diff] [blame] | 1343 | if (!fcf) { |
Bhanu Prakash Gollapudi | b2593cb | 2013-02-04 23:00:20 -0800 | [diff] [blame] | 1344 | /* |
| 1345 | * We are yet to select best FCF, but we got CVL in the |
| 1346 | * meantime. reset the ctlr and let it rediscover the FCF |
| 1347 | */ |
Chad Dupuis | fd37f66 | 2016-09-30 11:01:20 +0200 | [diff] [blame] | 1348 | LIBFCOE_FIP_DBG(fip, "Resetting fcoe_ctlr as FCF has not been " |
| 1349 | "selected yet\n"); |
Bhanu Prakash Gollapudi | b2593cb | 2013-02-04 23:00:20 -0800 | [diff] [blame] | 1350 | mutex_lock(&fip->ctlr_mutex); |
| 1351 | fcoe_ctlr_reset(fip); |
| 1352 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1353 | return; |
Bhanu Prakash Gollapudi | b2593cb | 2013-02-04 23:00:20 -0800 | [diff] [blame] | 1354 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1355 | |
| 1356 | /* |
Chad Dupuis | fd37f66 | 2016-09-30 11:01:20 +0200 | [diff] [blame] | 1357 | * If we've selected an FCF check that the CVL is from there to avoid |
| 1358 | * processing CVLs from an unexpected source. If it is from an |
| 1359 | * unexpected source drop it on the floor. |
| 1360 | */ |
| 1361 | if (!ether_addr_equal(eh->h_source, fcf->fcf_mac)) { |
| 1362 | LIBFCOE_FIP_DBG(fip, "Dropping CVL due to source address " |
| 1363 | "mismatch with FCF src=%pM\n", eh->h_source); |
| 1364 | return; |
| 1365 | } |
| 1366 | |
| 1367 | /* |
| 1368 | * If we haven't logged into the fabric but receive a CVL we should |
| 1369 | * reset everything and go back to solicitation. |
| 1370 | */ |
| 1371 | if (!lport->port_id) { |
| 1372 | LIBFCOE_FIP_DBG(fip, "lport not logged in, resoliciting\n"); |
| 1373 | mutex_lock(&fip->ctlr_mutex); |
| 1374 | fcoe_ctlr_reset(fip); |
| 1375 | mutex_unlock(&fip->ctlr_mutex); |
| 1376 | fc_lport_reset(fip->lp); |
| 1377 | fcoe_ctlr_solicit(fip, NULL); |
| 1378 | return; |
| 1379 | } |
| 1380 | |
| 1381 | /* |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1382 | * mask of required descriptors. Validating each one clears its bit. |
| 1383 | */ |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1384 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1385 | |
| 1386 | rlen = ntohs(fh->fip_dl_len) * FIP_BPW; |
| 1387 | desc = (struct fip_desc *)(fh + 1); |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1388 | |
| 1389 | /* |
| 1390 | * Actually need to subtract 'sizeof(*mp) - sizeof(*wp)' from 'rlen' |
| 1391 | * before determining max Vx_Port descriptor but a buggy FCF could have |
Masahiro Yamada | 0cf2a84 | 2017-02-27 14:29:39 -0800 | [diff] [blame] | 1392 | * omitted either or both MAC Address and Name Identifier descriptors |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1393 | */ |
| 1394 | num_vlink_desc = rlen / sizeof(*vp); |
| 1395 | if (num_vlink_desc) |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 1396 | vlink_desc_arr = kmalloc_array(num_vlink_desc, sizeof(vp), |
| 1397 | GFP_ATOMIC); |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1398 | if (!vlink_desc_arr) |
| 1399 | return; |
| 1400 | num_vlink_desc = 0; |
| 1401 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1402 | while (rlen >= sizeof(*desc)) { |
| 1403 | dlen = desc->fip_dlen * FIP_BPW; |
| 1404 | if (dlen > rlen) |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1405 | goto err; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1406 | /* Drop CVL if there are duplicate critical descriptors */ |
| 1407 | if ((desc->fip_dtype < 32) && |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1408 | (desc->fip_dtype != FIP_DT_VN_ID) && |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1409 | !(desc_mask & 1U << desc->fip_dtype)) { |
| 1410 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 1411 | "Descriptors in FIP CVL\n"); |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1412 | goto err; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1413 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1414 | switch (desc->fip_dtype) { |
| 1415 | case FIP_DT_MAC: |
| 1416 | mp = (struct fip_mac_desc *)desc; |
| 1417 | if (dlen < sizeof(*mp)) |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1418 | goto err; |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 1419 | if (!ether_addr_equal(mp->fd_mac, fcf->fcf_mac)) |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1420 | goto err; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1421 | desc_mask &= ~BIT(FIP_DT_MAC); |
| 1422 | break; |
| 1423 | case FIP_DT_NAME: |
| 1424 | wp = (struct fip_wwn_desc *)desc; |
| 1425 | if (dlen < sizeof(*wp)) |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1426 | goto err; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1427 | if (get_unaligned_be64(&wp->fd_wwn) != fcf->switch_name) |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1428 | goto err; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1429 | desc_mask &= ~BIT(FIP_DT_NAME); |
| 1430 | break; |
| 1431 | case FIP_DT_VN_ID: |
| 1432 | vp = (struct fip_vn_desc *)desc; |
| 1433 | if (dlen < sizeof(*vp)) |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1434 | goto err; |
| 1435 | vlink_desc_arr[num_vlink_desc++] = vp; |
| 1436 | vn_port = fc_vport_id_lookup(lport, |
| 1437 | ntoh24(vp->fd_fc_id)); |
| 1438 | if (vn_port && (vn_port == lport)) { |
| 1439 | mutex_lock(&fip->ctlr_mutex); |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 1440 | per_cpu_ptr(lport->stats, |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1441 | get_cpu())->VLinkFailureCount++; |
| 1442 | put_cpu(); |
| 1443 | fcoe_ctlr_reset(fip); |
| 1444 | mutex_unlock(&fip->ctlr_mutex); |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1445 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1446 | break; |
| 1447 | default: |
| 1448 | /* standard says ignore unknown descriptors >= 128 */ |
Hannes Reinecke | 6a551c1 | 2016-07-04 10:29:18 +0200 | [diff] [blame] | 1449 | if (desc->fip_dtype < FIP_DT_NON_CRITICAL) |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1450 | goto err; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1451 | break; |
| 1452 | } |
| 1453 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 1454 | rlen -= dlen; |
| 1455 | } |
| 1456 | |
| 1457 | /* |
| 1458 | * reset only if all required descriptors were present and valid. |
| 1459 | */ |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1460 | if (desc_mask) |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1461 | LIBFCOE_FIP_DBG(fip, "missing descriptors mask %x\n", |
| 1462 | desc_mask); |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1463 | else if (!num_vlink_desc) { |
| 1464 | LIBFCOE_FIP_DBG(fip, "CVL: no Vx_Port descriptor found\n"); |
| 1465 | /* |
| 1466 | * No Vx_Port description. Clear all NPIV ports, |
| 1467 | * followed by physical port |
| 1468 | */ |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1469 | mutex_lock(&fip->ctlr_mutex); |
Vasu Dev | 1bd49b4 | 2012-05-25 10:26:43 -0700 | [diff] [blame] | 1470 | per_cpu_ptr(lport->stats, get_cpu())->VLinkFailureCount++; |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1471 | put_cpu(); |
| 1472 | fcoe_ctlr_reset(fip); |
| 1473 | mutex_unlock(&fip->ctlr_mutex); |
| 1474 | |
Bhanu Prakash Gollapudi | 14619ea | 2012-03-09 14:49:53 -0800 | [diff] [blame] | 1475 | mutex_lock(&lport->lp_mutex); |
| 1476 | list_for_each_entry(vn_port, &lport->vports, list) |
| 1477 | fc_lport_reset(vn_port); |
| 1478 | mutex_unlock(&lport->lp_mutex); |
| 1479 | |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1480 | fc_lport_reset(fip->lp); |
| 1481 | fcoe_ctlr_solicit(fip, NULL); |
| 1482 | } else { |
| 1483 | int i; |
| 1484 | |
| 1485 | LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n"); |
| 1486 | for (i = 0; i < num_vlink_desc; i++) { |
| 1487 | vp = vlink_desc_arr[i]; |
| 1488 | vn_port = fc_vport_id_lookup(lport, |
| 1489 | ntoh24(vp->fd_fc_id)); |
| 1490 | if (!vn_port) |
| 1491 | continue; |
| 1492 | |
| 1493 | /* |
| 1494 | * 'port_id' is already validated, check MAC address and |
| 1495 | * wwpn |
| 1496 | */ |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 1497 | if (!ether_addr_equal(fip->get_src_addr(vn_port), |
| 1498 | vp->fd_mac) || |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1499 | get_unaligned_be64(&vp->fd_wwpn) != |
| 1500 | vn_port->wwpn) |
| 1501 | continue; |
| 1502 | |
| 1503 | if (vn_port == lport) |
| 1504 | /* |
| 1505 | * Physical port, defer processing till all |
| 1506 | * listed NPIV ports are cleared |
| 1507 | */ |
| 1508 | reset_phys_port = 1; |
| 1509 | else /* NPIV port */ |
| 1510 | fc_lport_reset(vn_port); |
| 1511 | } |
| 1512 | |
| 1513 | if (reset_phys_port) { |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1514 | fc_lport_reset(fip->lp); |
| 1515 | fcoe_ctlr_solicit(fip, NULL); |
| 1516 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1517 | } |
Bhanu Prakash Gollapudi | c051ad2 | 2011-05-16 16:45:24 -0700 | [diff] [blame] | 1518 | |
| 1519 | err: |
| 1520 | kfree(vlink_desc_arr); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1524 | * fcoe_ctlr_recv() - Receive a FIP packet |
| 1525 | * @fip: The FCoE controller that received the packet |
| 1526 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1527 | * |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1528 | * This may be called from either NET_RX_SOFTIRQ or IRQ. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1529 | */ |
| 1530 | void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1531 | { |
Neil Horman | c086628 | 2013-08-03 10:45:53 +0000 | [diff] [blame] | 1532 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 1533 | if (!skb) |
| 1534 | return; |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1535 | skb_queue_tail(&fip->fip_recv_list, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1536 | schedule_work(&fip->recv_work); |
| 1537 | } |
| 1538 | EXPORT_SYMBOL(fcoe_ctlr_recv); |
| 1539 | |
| 1540 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1541 | * fcoe_ctlr_recv_handler() - Receive a FIP frame |
| 1542 | * @fip: The FCoE controller that received the frame |
| 1543 | * @skb: The received FIP frame |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1544 | * |
| 1545 | * Returns non-zero if the frame is dropped. |
| 1546 | */ |
| 1547 | static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1548 | { |
| 1549 | struct fip_header *fiph; |
| 1550 | struct ethhdr *eh; |
| 1551 | enum fip_state state; |
Hannes Reinecke | 9a6cf88 | 2016-07-19 13:49:40 +0200 | [diff] [blame] | 1552 | bool fip_vlan_resp = false; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1553 | u16 op; |
| 1554 | u8 sub; |
| 1555 | |
| 1556 | if (skb_linearize(skb)) |
| 1557 | goto drop; |
| 1558 | if (skb->len < sizeof(*fiph)) |
| 1559 | goto drop; |
| 1560 | eh = eth_hdr(skb); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1561 | if (fip->mode == FIP_MODE_VN2VN) { |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 1562 | if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && |
| 1563 | !ether_addr_equal(eh->h_dest, fcoe_all_vn2vn) && |
| 1564 | !ether_addr_equal(eh->h_dest, fcoe_all_p2p)) |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1565 | goto drop; |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 1566 | } else if (!ether_addr_equal(eh->h_dest, fip->ctl_src_addr) && |
| 1567 | !ether_addr_equal(eh->h_dest, fcoe_all_enode)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1568 | goto drop; |
| 1569 | fiph = (struct fip_header *)skb->data; |
| 1570 | op = ntohs(fiph->fip_op); |
| 1571 | sub = fiph->fip_subcode; |
| 1572 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1573 | if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) |
| 1574 | goto drop; |
| 1575 | if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) |
| 1576 | goto drop; |
| 1577 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1578 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1579 | state = fip->state; |
| 1580 | if (state == FIP_ST_AUTO) { |
| 1581 | fip->map_dest = 0; |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 1582 | fcoe_ctlr_set_state(fip, FIP_ST_ENABLED); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1583 | state = FIP_ST_ENABLED; |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1584 | LIBFCOE_FIP_DBG(fip, "Using FIP mode\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1585 | } |
Hannes Reinecke | 9a6cf88 | 2016-07-19 13:49:40 +0200 | [diff] [blame] | 1586 | fip_vlan_resp = fip->fip_resp; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1587 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1588 | |
| 1589 | if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN) |
| 1590 | return fcoe_ctlr_vn_recv(fip, skb); |
| 1591 | |
Hannes Reinecke | 9a6cf88 | 2016-07-19 13:49:40 +0200 | [diff] [blame] | 1592 | if (fip_vlan_resp && op == FIP_OP_VLAN) { |
| 1593 | LIBFCOE_FIP_DBG(fip, "fip vlan discovery\n"); |
| 1594 | return fcoe_ctlr_vlan_recv(fip, skb); |
| 1595 | } |
| 1596 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1597 | if (state != FIP_ST_ENABLED && state != FIP_ST_VNMP_UP && |
| 1598 | state != FIP_ST_VNMP_CLAIM) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1599 | goto drop; |
| 1600 | |
| 1601 | if (op == FIP_OP_LS) { |
| 1602 | fcoe_ctlr_recv_els(fip, skb); /* consumes skb */ |
| 1603 | return 0; |
| 1604 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1605 | |
| 1606 | if (state != FIP_ST_ENABLED) |
| 1607 | goto drop; |
| 1608 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1609 | if (op == FIP_OP_DISC && sub == FIP_SC_ADV) |
| 1610 | fcoe_ctlr_recv_adv(fip, skb); |
| 1611 | else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) |
Chad Dupuis | fd37f66 | 2016-09-30 11:01:20 +0200 | [diff] [blame] | 1612 | fcoe_ctlr_recv_clr_vlink(fip, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1613 | kfree_skb(skb); |
| 1614 | return 0; |
| 1615 | drop: |
| 1616 | kfree_skb(skb); |
| 1617 | return -1; |
| 1618 | } |
| 1619 | |
| 1620 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1621 | * fcoe_ctlr_select() - Select the best FCF (if possible) |
| 1622 | * @fip: The FCoE controller |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1623 | * |
Joe Eykholt | ba9cd5d | 2010-11-30 16:20:12 -0800 | [diff] [blame] | 1624 | * Returns the selected FCF, or NULL if none are usable. |
| 1625 | * |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1626 | * If there are conflicting advertisements, no FCF can be chosen. |
| 1627 | * |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1628 | * If there is already a selected FCF, this will choose a better one or |
| 1629 | * an equivalent one that hasn't already been sent a FLOGI. |
| 1630 | * |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1631 | * Called with lock held. |
| 1632 | */ |
Joe Eykholt | ba9cd5d | 2010-11-30 16:20:12 -0800 | [diff] [blame] | 1633 | static struct fcoe_fcf *fcoe_ctlr_select(struct fcoe_ctlr *fip) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1634 | { |
| 1635 | struct fcoe_fcf *fcf; |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1636 | struct fcoe_fcf *best = fip->sel_fcf; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1637 | |
| 1638 | list_for_each_entry(fcf, &fip->fcfs, list) { |
Joe Eykholt | 9069f5c | 2010-11-30 16:20:02 -0800 | [diff] [blame] | 1639 | LIBFCOE_FIP_DBG(fip, "consider FCF fab %16.16llx " |
| 1640 | "VFID %d mac %pM map %x val %d " |
| 1641 | "sent %u pri %u\n", |
| 1642 | fcf->fabric_name, fcf->vfid, fcf->fcf_mac, |
| 1643 | fcf->fc_map, fcoe_ctlr_mtu_valid(fcf), |
| 1644 | fcf->flogi_sent, fcf->pri); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1645 | if (!fcoe_ctlr_fcf_usable(fcf)) { |
Chris Leech | 9f8f3aa | 2010-04-09 14:23:16 -0700 | [diff] [blame] | 1646 | LIBFCOE_FIP_DBG(fip, "FCF for fab %16.16llx " |
| 1647 | "map %x %svalid %savailable\n", |
| 1648 | fcf->fabric_name, fcf->fc_map, |
| 1649 | (fcf->flags & FIP_FL_SOL) ? "" : "in", |
| 1650 | (fcf->flags & FIP_FL_AVAIL) ? |
| 1651 | "" : "un"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1652 | continue; |
| 1653 | } |
Krishna Mohan | e6c10b7 | 2013-03-01 11:35:31 +0000 | [diff] [blame] | 1654 | if (!best || fcf->pri < best->pri || best->flogi_sent) |
| 1655 | best = fcf; |
| 1656 | if (fcf->fabric_name != best->fabric_name || |
| 1657 | fcf->vfid != best->vfid || |
| 1658 | fcf->fc_map != best->fc_map) { |
Bhanu Prakash Gollapudi | 1f953b0 | 2013-01-28 11:43:03 -0800 | [diff] [blame] | 1659 | LIBFCOE_FIP_DBG(fip, "Conflicting fabric, VFID, " |
| 1660 | "or FC-MAP\n"); |
| 1661 | return NULL; |
| 1662 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1663 | } |
| 1664 | fip->sel_fcf = best; |
Joe Eykholt | c47036a | 2010-11-30 16:19:46 -0800 | [diff] [blame] | 1665 | if (best) { |
Joe Eykholt | 9069f5c | 2010-11-30 16:20:02 -0800 | [diff] [blame] | 1666 | LIBFCOE_FIP_DBG(fip, "using FCF mac %pM\n", best->fcf_mac); |
Joe Eykholt | c47036a | 2010-11-30 16:19:46 -0800 | [diff] [blame] | 1667 | fip->port_ka_time = jiffies + |
| 1668 | msecs_to_jiffies(FIP_VN_KA_PERIOD); |
| 1669 | fip->ctlr_ka_time = jiffies + best->fka_period; |
| 1670 | if (time_before(fip->ctlr_ka_time, fip->timer.expires)) |
| 1671 | mod_timer(&fip->timer, fip->ctlr_ka_time); |
| 1672 | } |
Joe Eykholt | ba9cd5d | 2010-11-30 16:20:12 -0800 | [diff] [blame] | 1673 | return best; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | /** |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1677 | * fcoe_ctlr_flogi_send_locked() - send FIP-encapsulated FLOGI to current FCF |
| 1678 | * @fip: The FCoE controller |
| 1679 | * |
| 1680 | * Returns non-zero error if it could not be sent. |
| 1681 | * |
| 1682 | * Called with ctlr_mutex and ctlr_lock held. |
| 1683 | * Caller must verify that fip->sel_fcf is not NULL. |
| 1684 | */ |
| 1685 | static int fcoe_ctlr_flogi_send_locked(struct fcoe_ctlr *fip) |
| 1686 | { |
| 1687 | struct sk_buff *skb; |
| 1688 | struct sk_buff *skb_orig; |
| 1689 | struct fc_frame_header *fh; |
| 1690 | int error; |
| 1691 | |
| 1692 | skb_orig = fip->flogi_req; |
| 1693 | if (!skb_orig) |
| 1694 | return -EINVAL; |
| 1695 | |
| 1696 | /* |
| 1697 | * Clone and send the FLOGI request. If clone fails, use original. |
| 1698 | */ |
| 1699 | skb = skb_clone(skb_orig, GFP_ATOMIC); |
| 1700 | if (!skb) { |
| 1701 | skb = skb_orig; |
| 1702 | fip->flogi_req = NULL; |
| 1703 | } |
| 1704 | fh = (struct fc_frame_header *)skb->data; |
| 1705 | error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb, |
| 1706 | ntoh24(fh->fh_d_id)); |
| 1707 | if (error) { |
| 1708 | kfree_skb(skb); |
| 1709 | return error; |
| 1710 | } |
| 1711 | fip->send(fip, skb); |
| 1712 | fip->sel_fcf->flogi_sent = 1; |
| 1713 | return 0; |
| 1714 | } |
| 1715 | |
| 1716 | /** |
| 1717 | * fcoe_ctlr_flogi_retry() - resend FLOGI request to a new FCF if possible |
| 1718 | * @fip: The FCoE controller |
| 1719 | * |
| 1720 | * Returns non-zero error code if there's no FLOGI request to retry or |
| 1721 | * no alternate FCF available. |
| 1722 | */ |
| 1723 | static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *fip) |
| 1724 | { |
| 1725 | struct fcoe_fcf *fcf; |
| 1726 | int error; |
| 1727 | |
| 1728 | mutex_lock(&fip->ctlr_mutex); |
| 1729 | spin_lock_bh(&fip->ctlr_lock); |
| 1730 | LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n"); |
Joe Eykholt | ba9cd5d | 2010-11-30 16:20:12 -0800 | [diff] [blame] | 1731 | fcf = fcoe_ctlr_select(fip); |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1732 | if (!fcf || fcf->flogi_sent) { |
| 1733 | kfree_skb(fip->flogi_req); |
| 1734 | fip->flogi_req = NULL; |
| 1735 | error = -ENOENT; |
| 1736 | } else { |
| 1737 | fcoe_ctlr_solicit(fip, NULL); |
| 1738 | error = fcoe_ctlr_flogi_send_locked(fip); |
| 1739 | } |
| 1740 | spin_unlock_bh(&fip->ctlr_lock); |
| 1741 | mutex_unlock(&fip->ctlr_mutex); |
| 1742 | return error; |
| 1743 | } |
| 1744 | |
| 1745 | |
| 1746 | /** |
| 1747 | * fcoe_ctlr_flogi_send() - Handle sending of FIP FLOGI. |
| 1748 | * @fip: The FCoE controller that timed out |
| 1749 | * |
| 1750 | * Done here because fcoe_ctlr_els_send() can't get mutex. |
| 1751 | * |
| 1752 | * Called with ctlr_mutex held. The caller must not hold ctlr_lock. |
| 1753 | */ |
| 1754 | static void fcoe_ctlr_flogi_send(struct fcoe_ctlr *fip) |
| 1755 | { |
| 1756 | struct fcoe_fcf *fcf; |
| 1757 | |
| 1758 | spin_lock_bh(&fip->ctlr_lock); |
| 1759 | fcf = fip->sel_fcf; |
| 1760 | if (!fcf || !fip->flogi_req_send) |
| 1761 | goto unlock; |
| 1762 | |
| 1763 | LIBFCOE_FIP_DBG(fip, "sending FLOGI\n"); |
| 1764 | |
| 1765 | /* |
| 1766 | * If this FLOGI is being sent due to a timeout retry |
| 1767 | * to the same FCF as before, select a different FCF if possible. |
| 1768 | */ |
| 1769 | if (fcf->flogi_sent) { |
| 1770 | LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n"); |
Joe Eykholt | ba9cd5d | 2010-11-30 16:20:12 -0800 | [diff] [blame] | 1771 | fcf = fcoe_ctlr_select(fip); |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1772 | if (!fcf || fcf->flogi_sent) { |
| 1773 | LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n"); |
| 1774 | list_for_each_entry(fcf, &fip->fcfs, list) |
| 1775 | fcf->flogi_sent = 0; |
Joe Eykholt | ba9cd5d | 2010-11-30 16:20:12 -0800 | [diff] [blame] | 1776 | fcf = fcoe_ctlr_select(fip); |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1777 | } |
| 1778 | } |
| 1779 | if (fcf) { |
| 1780 | fcoe_ctlr_flogi_send_locked(fip); |
| 1781 | fip->flogi_req_send = 0; |
| 1782 | } else /* XXX */ |
| 1783 | LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n"); |
| 1784 | unlock: |
| 1785 | spin_unlock_bh(&fip->ctlr_lock); |
| 1786 | } |
| 1787 | |
| 1788 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1789 | * fcoe_ctlr_timeout() - FIP timeout handler |
| 1790 | * @arg: The FCoE controller that timed out |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1791 | */ |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 1792 | static void fcoe_ctlr_timeout(struct timer_list *t) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1793 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 1794 | struct fcoe_ctlr *fip = from_timer(fip, t, timer); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1795 | |
| 1796 | schedule_work(&fip->timer_work); |
| 1797 | } |
| 1798 | |
| 1799 | /** |
| 1800 | * fcoe_ctlr_timer_work() - Worker thread function for timer work |
| 1801 | * @work: Handle to a FCoE controller |
| 1802 | * |
| 1803 | * Ages FCFs. Triggers FCF selection if possible. |
| 1804 | * Sends keep-alives and resets. |
| 1805 | */ |
| 1806 | static void fcoe_ctlr_timer_work(struct work_struct *work) |
| 1807 | { |
| 1808 | struct fcoe_ctlr *fip; |
| 1809 | struct fc_lport *vport; |
| 1810 | u8 *mac; |
| 1811 | u8 reset = 0; |
| 1812 | u8 send_ctlr_ka = 0; |
| 1813 | u8 send_port_ka = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1814 | struct fcoe_fcf *sel; |
| 1815 | struct fcoe_fcf *fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1816 | unsigned long next_timer; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1817 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1818 | fip = container_of(work, struct fcoe_ctlr, timer_work); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1819 | if (fip->mode == FIP_MODE_VN2VN) |
| 1820 | return fcoe_ctlr_vn_timeout(fip); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1821 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1822 | if (fip->state == FIP_ST_DISABLED) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1823 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1824 | return; |
| 1825 | } |
| 1826 | |
| 1827 | fcf = fip->sel_fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1828 | next_timer = fcoe_ctlr_age_fcfs(fip); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1829 | |
| 1830 | sel = fip->sel_fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1831 | if (!sel && fip->sel_time) { |
| 1832 | if (time_after_eq(jiffies, fip->sel_time)) { |
Joe Eykholt | ba9cd5d | 2010-11-30 16:20:12 -0800 | [diff] [blame] | 1833 | sel = fcoe_ctlr_select(fip); |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1834 | fip->sel_time = 0; |
| 1835 | } else if (time_after(next_timer, fip->sel_time)) |
| 1836 | next_timer = fip->sel_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1839 | if (sel && fip->flogi_req_send) |
| 1840 | fcoe_ctlr_flogi_send(fip); |
| 1841 | else if (!sel && fcf) |
| 1842 | reset = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1843 | |
Yi Zou | 8cdffdc | 2009-11-20 14:54:57 -0800 | [diff] [blame] | 1844 | if (sel && !sel->fd_flags) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1845 | if (time_after_eq(jiffies, fip->ctlr_ka_time)) { |
| 1846 | fip->ctlr_ka_time = jiffies + sel->fka_period; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1847 | send_ctlr_ka = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1848 | } |
| 1849 | if (time_after(next_timer, fip->ctlr_ka_time)) |
| 1850 | next_timer = fip->ctlr_ka_time; |
| 1851 | |
| 1852 | if (time_after_eq(jiffies, fip->port_ka_time)) { |
Bhanu Prakash Gollapudi | f47dd85 | 2010-01-21 10:16:00 -0800 | [diff] [blame] | 1853 | fip->port_ka_time = jiffies + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1854 | msecs_to_jiffies(FIP_VN_KA_PERIOD); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1855 | send_port_ka = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1856 | } |
| 1857 | if (time_after(next_timer, fip->port_ka_time)) |
| 1858 | next_timer = fip->port_ka_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1859 | } |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1860 | if (!list_empty(&fip->fcfs)) |
| 1861 | mod_timer(&fip->timer, next_timer); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1862 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1863 | |
Bhanu Prakash Gollapudi | 516a648 | 2010-06-11 16:43:44 -0700 | [diff] [blame] | 1864 | if (reset) { |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 1865 | fc_lport_reset(fip->lp); |
Bhanu Prakash Gollapudi | 516a648 | 2010-06-11 16:43:44 -0700 | [diff] [blame] | 1866 | /* restart things with a solicitation */ |
| 1867 | fcoe_ctlr_solicit(fip, NULL); |
| 1868 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1869 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1870 | if (send_ctlr_ka) |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1871 | fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1872 | |
| 1873 | if (send_port_ka) { |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1874 | mutex_lock(&fip->lp->lp_mutex); |
| 1875 | mac = fip->get_src_addr(fip->lp); |
| 1876 | fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac); |
| 1877 | list_for_each_entry(vport, &fip->lp->vports, list) { |
| 1878 | mac = fip->get_src_addr(vport); |
| 1879 | fcoe_ctlr_send_keep_alive(fip, vport, 1, mac); |
| 1880 | } |
| 1881 | mutex_unlock(&fip->lp->lp_mutex); |
| 1882 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1886 | * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames |
| 1887 | * @recv_work: Handle to a FCoE controller |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1888 | */ |
| 1889 | static void fcoe_ctlr_recv_work(struct work_struct *recv_work) |
| 1890 | { |
| 1891 | struct fcoe_ctlr *fip; |
| 1892 | struct sk_buff *skb; |
| 1893 | |
| 1894 | fip = container_of(recv_work, struct fcoe_ctlr, recv_work); |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1895 | while ((skb = skb_dequeue(&fip->fip_recv_list))) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1896 | fcoe_ctlr_recv_handler(fip, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | /** |
Joe Eykholt | 386309ce | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1900 | * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1901 | * @fip: The FCoE controller |
| 1902 | * @fp: The FC frame to snoop |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1903 | * |
| 1904 | * Snoop potential response to FLOGI or even incoming FLOGI. |
| 1905 | * |
| 1906 | * The caller has checked that we are waiting for login as indicated |
| 1907 | * by fip->flogi_oxid != FC_XID_UNKNOWN. |
| 1908 | * |
| 1909 | * The caller is responsible for freeing the frame. |
Joe Eykholt | 386309ce | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1910 | * Fill in the granted_mac address. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1911 | * |
| 1912 | * Return non-zero if the frame should not be delivered to libfc. |
| 1913 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1914 | int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport, |
Joe Eykholt | 386309ce | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1915 | struct fc_frame *fp) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1916 | { |
| 1917 | struct fc_frame_header *fh; |
| 1918 | u8 op; |
Joe Eykholt | 386309ce | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1919 | u8 *sa; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1920 | |
Joe Eykholt | 386309ce | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1921 | sa = eth_hdr(&fp->skb)->h_source; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1922 | fh = fc_frame_header_get(fp); |
| 1923 | if (fh->fh_type != FC_TYPE_ELS) |
| 1924 | return 0; |
| 1925 | |
| 1926 | op = fc_frame_payload_op(fp); |
| 1927 | if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP && |
| 1928 | fip->flogi_oxid == ntohs(fh->fh_ox_id)) { |
| 1929 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1930 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1931 | if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1932 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1933 | return -EINVAL; |
| 1934 | } |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 1935 | fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP); |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1936 | LIBFCOE_FIP_DBG(fip, |
| 1937 | "received FLOGI LS_ACC using non-FIP mode\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1938 | |
| 1939 | /* |
| 1940 | * FLOGI accepted. |
| 1941 | * If the src mac addr is FC_OUI-based, then we mark the |
| 1942 | * address_mode flag to use FC_OUI-based Ethernet DA. |
| 1943 | * Otherwise we use the FCoE gateway addr |
| 1944 | */ |
Joe Perches | 6942df7 | 2013-09-02 03:32:33 +0000 | [diff] [blame] | 1945 | if (ether_addr_equal(sa, (u8[6])FC_FCOE_FLOGI_MAC)) { |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 1946 | fcoe_ctlr_map_dest(fip); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1947 | } else { |
| 1948 | memcpy(fip->dest_addr, sa, ETH_ALEN); |
| 1949 | fip->map_dest = 0; |
| 1950 | } |
| 1951 | fip->flogi_oxid = FC_XID_UNKNOWN; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1952 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 386309ce | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1953 | fc_fcoe_set_mac(fr_cb(fp)->granted_mac, fh->fh_d_id); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1954 | } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { |
| 1955 | /* |
| 1956 | * Save source MAC for point-to-point responses. |
| 1957 | */ |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1958 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1959 | if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) { |
| 1960 | memcpy(fip->dest_addr, sa, ETH_ALEN); |
| 1961 | fip->map_dest = 0; |
Joe Eykholt | e49bf61 | 2010-03-12 16:07:57 -0800 | [diff] [blame] | 1962 | if (fip->state == FIP_ST_AUTO) |
| 1963 | LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. " |
| 1964 | "Setting non-FIP mode\n"); |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 1965 | fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1966 | } |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1967 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1968 | } |
| 1969 | return 0; |
| 1970 | } |
| 1971 | EXPORT_SYMBOL(fcoe_ctlr_recv_flogi); |
| 1972 | |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1973 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1974 | * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN |
| 1975 | * @mac: The MAC address to convert |
| 1976 | * @scheme: The scheme to use when converting |
| 1977 | * @port: The port indicator for converting |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1978 | * |
| 1979 | * Returns: u64 fc world wide name |
| 1980 | */ |
| 1981 | u64 fcoe_wwn_from_mac(unsigned char mac[MAX_ADDR_LEN], |
| 1982 | unsigned int scheme, unsigned int port) |
| 1983 | { |
| 1984 | u64 wwn; |
| 1985 | u64 host_mac; |
| 1986 | |
| 1987 | /* The MAC is in NO, so flip only the low 48 bits */ |
| 1988 | host_mac = ((u64) mac[0] << 40) | |
| 1989 | ((u64) mac[1] << 32) | |
| 1990 | ((u64) mac[2] << 24) | |
| 1991 | ((u64) mac[3] << 16) | |
| 1992 | ((u64) mac[4] << 8) | |
| 1993 | (u64) mac[5]; |
| 1994 | |
| 1995 | WARN_ON(host_mac >= (1ULL << 48)); |
| 1996 | wwn = host_mac | ((u64) scheme << 60); |
| 1997 | switch (scheme) { |
| 1998 | case 1: |
| 1999 | WARN_ON(port != 0); |
| 2000 | break; |
| 2001 | case 2: |
| 2002 | WARN_ON(port >= 0xfff); |
| 2003 | wwn |= (u64) port << 48; |
| 2004 | break; |
| 2005 | default: |
| 2006 | WARN_ON(1); |
| 2007 | break; |
| 2008 | } |
| 2009 | |
| 2010 | return wwn; |
| 2011 | } |
| 2012 | EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac); |
| 2013 | |
| 2014 | /** |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2015 | * fcoe_ctlr_rport() - return the fcoe_rport for a given fc_rport_priv |
| 2016 | * @rdata: libfc remote port |
| 2017 | */ |
| 2018 | static inline struct fcoe_rport *fcoe_ctlr_rport(struct fc_rport_priv *rdata) |
| 2019 | { |
| 2020 | return (struct fcoe_rport *)(rdata + 1); |
| 2021 | } |
| 2022 | |
| 2023 | /** |
| 2024 | * fcoe_ctlr_vn_send() - Send a FIP VN2VN Probe Request or Reply. |
| 2025 | * @fip: The FCoE controller |
| 2026 | * @sub: sub-opcode for probe request, reply, or advertisement. |
| 2027 | * @dest: The destination Ethernet MAC address |
| 2028 | * @min_len: minimum size of the Ethernet payload to be sent |
| 2029 | */ |
| 2030 | static void fcoe_ctlr_vn_send(struct fcoe_ctlr *fip, |
| 2031 | enum fip_vn2vn_subcode sub, |
| 2032 | const u8 *dest, size_t min_len) |
| 2033 | { |
| 2034 | struct sk_buff *skb; |
Hannes Reinecke | b3d30f4 | 2016-07-19 13:49:39 +0200 | [diff] [blame] | 2035 | struct fip_vn2vn_probe_frame { |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2036 | struct ethhdr eth; |
| 2037 | struct fip_header fip; |
| 2038 | struct fip_mac_desc mac; |
| 2039 | struct fip_wwn_desc wwnn; |
| 2040 | struct fip_vn_desc vn; |
Yi Zou | 0095a92 | 2011-01-28 16:05:00 -0800 | [diff] [blame] | 2041 | } __packed * frame; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2042 | struct fip_fc4_feat *ff; |
| 2043 | struct fip_size_desc *size; |
| 2044 | u32 fcp_feat; |
| 2045 | size_t len; |
| 2046 | size_t dlen; |
| 2047 | |
| 2048 | len = sizeof(*frame); |
| 2049 | dlen = 0; |
| 2050 | if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { |
| 2051 | dlen = sizeof(struct fip_fc4_feat) + |
| 2052 | sizeof(struct fip_size_desc); |
| 2053 | len += dlen; |
| 2054 | } |
| 2055 | dlen += sizeof(frame->mac) + sizeof(frame->wwnn) + sizeof(frame->vn); |
| 2056 | len = max(len, min_len + sizeof(struct ethhdr)); |
| 2057 | |
| 2058 | skb = dev_alloc_skb(len); |
| 2059 | if (!skb) |
| 2060 | return; |
| 2061 | |
Hannes Reinecke | b3d30f4 | 2016-07-19 13:49:39 +0200 | [diff] [blame] | 2062 | frame = (struct fip_vn2vn_probe_frame *)skb->data; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2063 | memset(frame, 0, len); |
| 2064 | memcpy(frame->eth.h_dest, dest, ETH_ALEN); |
Yi Zou | d227f02 | 2012-04-20 12:16:49 -0700 | [diff] [blame] | 2065 | |
| 2066 | if (sub == FIP_SC_VN_BEACON) { |
| 2067 | hton24(frame->eth.h_source, FIP_VN_FC_MAP); |
| 2068 | hton24(frame->eth.h_source + 3, fip->port_id); |
| 2069 | } else { |
| 2070 | memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); |
| 2071 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2072 | frame->eth.h_proto = htons(ETH_P_FIP); |
| 2073 | |
| 2074 | frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 2075 | frame->fip.fip_op = htons(FIP_OP_VN2VN); |
| 2076 | frame->fip.fip_subcode = sub; |
| 2077 | frame->fip.fip_dl_len = htons(dlen / FIP_BPW); |
| 2078 | |
| 2079 | frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; |
| 2080 | frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; |
| 2081 | memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); |
| 2082 | |
| 2083 | frame->wwnn.fd_desc.fip_dtype = FIP_DT_NAME; |
| 2084 | frame->wwnn.fd_desc.fip_dlen = sizeof(frame->wwnn) / FIP_BPW; |
| 2085 | put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn); |
| 2086 | |
| 2087 | frame->vn.fd_desc.fip_dtype = FIP_DT_VN_ID; |
| 2088 | frame->vn.fd_desc.fip_dlen = sizeof(frame->vn) / FIP_BPW; |
| 2089 | hton24(frame->vn.fd_mac, FIP_VN_FC_MAP); |
| 2090 | hton24(frame->vn.fd_mac + 3, fip->port_id); |
| 2091 | hton24(frame->vn.fd_fc_id, fip->port_id); |
| 2092 | put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn); |
| 2093 | |
| 2094 | /* |
| 2095 | * For claims, add FC-4 features. |
| 2096 | * TBD: Add interface to get fc-4 types and features from libfc. |
| 2097 | */ |
| 2098 | if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { |
| 2099 | ff = (struct fip_fc4_feat *)(frame + 1); |
| 2100 | ff->fd_desc.fip_dtype = FIP_DT_FC4F; |
| 2101 | ff->fd_desc.fip_dlen = sizeof(*ff) / FIP_BPW; |
| 2102 | ff->fd_fts = fip->lp->fcts; |
| 2103 | |
| 2104 | fcp_feat = 0; |
| 2105 | if (fip->lp->service_params & FCP_SPPF_INIT_FCN) |
| 2106 | fcp_feat |= FCP_FEAT_INIT; |
| 2107 | if (fip->lp->service_params & FCP_SPPF_TARG_FCN) |
| 2108 | fcp_feat |= FCP_FEAT_TARG; |
| 2109 | fcp_feat <<= (FC_TYPE_FCP * 4) % 32; |
| 2110 | ff->fd_ff.fd_feat[FC_TYPE_FCP * 4 / 32] = htonl(fcp_feat); |
| 2111 | |
| 2112 | size = (struct fip_size_desc *)(ff + 1); |
| 2113 | size->fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; |
| 2114 | size->fd_desc.fip_dlen = sizeof(*size) / FIP_BPW; |
| 2115 | size->fd_size = htons(fcoe_ctlr_fcoe_size(fip)); |
| 2116 | } |
| 2117 | |
| 2118 | skb_put(skb, len); |
| 2119 | skb->protocol = htons(ETH_P_FIP); |
john fastabend | 6f6c2aa | 2011-11-18 13:35:56 -0800 | [diff] [blame] | 2120 | skb->priority = fip->priority; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2121 | skb_reset_mac_header(skb); |
| 2122 | skb_reset_network_header(skb); |
| 2123 | |
| 2124 | fip->send(fip, skb); |
| 2125 | } |
| 2126 | |
| 2127 | /** |
| 2128 | * fcoe_ctlr_vn_rport_callback - Event handler for rport events. |
| 2129 | * @lport: The lport which is receiving the event |
| 2130 | * @rdata: remote port private data |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2131 | * @event: The event that occurred |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2132 | * |
| 2133 | * Locking Note: The rport lock must not be held when calling this function. |
| 2134 | */ |
| 2135 | static void fcoe_ctlr_vn_rport_callback(struct fc_lport *lport, |
| 2136 | struct fc_rport_priv *rdata, |
| 2137 | enum fc_rport_event event) |
| 2138 | { |
| 2139 | struct fcoe_ctlr *fip = lport->disc.priv; |
| 2140 | struct fcoe_rport *frport = fcoe_ctlr_rport(rdata); |
| 2141 | |
| 2142 | LIBFCOE_FIP_DBG(fip, "vn_rport_callback %x event %d\n", |
| 2143 | rdata->ids.port_id, event); |
| 2144 | |
| 2145 | mutex_lock(&fip->ctlr_mutex); |
| 2146 | switch (event) { |
| 2147 | case RPORT_EV_READY: |
| 2148 | frport->login_count = 0; |
| 2149 | break; |
| 2150 | case RPORT_EV_LOGO: |
| 2151 | case RPORT_EV_FAILED: |
| 2152 | case RPORT_EV_STOP: |
| 2153 | frport->login_count++; |
| 2154 | if (frport->login_count > FCOE_CTLR_VN2VN_LOGIN_LIMIT) { |
| 2155 | LIBFCOE_FIP_DBG(fip, |
| 2156 | "rport FLOGI limited port_id %6.6x\n", |
| 2157 | rdata->ids.port_id); |
Hannes Reinecke | c96c792 | 2016-10-18 10:01:44 +0200 | [diff] [blame] | 2158 | fc_rport_logoff(rdata); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2159 | } |
| 2160 | break; |
| 2161 | default: |
| 2162 | break; |
| 2163 | } |
| 2164 | mutex_unlock(&fip->ctlr_mutex); |
| 2165 | } |
| 2166 | |
| 2167 | static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = { |
| 2168 | .event_callback = fcoe_ctlr_vn_rport_callback, |
| 2169 | }; |
| 2170 | |
| 2171 | /** |
| 2172 | * fcoe_ctlr_disc_stop_locked() - stop discovery in VN2VN mode |
| 2173 | * @fip: The FCoE controller |
| 2174 | * |
| 2175 | * Called with ctlr_mutex held. |
| 2176 | */ |
| 2177 | static void fcoe_ctlr_disc_stop_locked(struct fc_lport *lport) |
| 2178 | { |
Mark Rustad | d17efa0 | 2013-05-18 04:10:07 +0000 | [diff] [blame] | 2179 | struct fc_rport_priv *rdata; |
| 2180 | |
Hannes Reinecke | 0993ed9 | 2018-07-11 10:09:30 +0200 | [diff] [blame] | 2181 | mutex_lock(&lport->disc.disc_mutex); |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2182 | list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { |
| 2183 | if (kref_get_unless_zero(&rdata->kref)) { |
Hannes Reinecke | c96c792 | 2016-10-18 10:01:44 +0200 | [diff] [blame] | 2184 | fc_rport_logoff(rdata); |
Hannes Reinecke | 944ef96 | 2016-10-18 10:01:39 +0200 | [diff] [blame] | 2185 | kref_put(&rdata->kref, fc_rport_destroy); |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2186 | } |
| 2187 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2188 | lport->disc.disc_callback = NULL; |
| 2189 | mutex_unlock(&lport->disc.disc_mutex); |
| 2190 | } |
| 2191 | |
| 2192 | /** |
| 2193 | * fcoe_ctlr_disc_stop() - stop discovery in VN2VN mode |
| 2194 | * @fip: The FCoE controller |
| 2195 | * |
| 2196 | * Called through the local port template for discovery. |
| 2197 | * Called without the ctlr_mutex held. |
| 2198 | */ |
| 2199 | static void fcoe_ctlr_disc_stop(struct fc_lport *lport) |
| 2200 | { |
| 2201 | struct fcoe_ctlr *fip = lport->disc.priv; |
| 2202 | |
| 2203 | mutex_lock(&fip->ctlr_mutex); |
| 2204 | fcoe_ctlr_disc_stop_locked(lport); |
| 2205 | mutex_unlock(&fip->ctlr_mutex); |
| 2206 | } |
| 2207 | |
| 2208 | /** |
| 2209 | * fcoe_ctlr_disc_stop_final() - stop discovery for shutdown in VN2VN mode |
| 2210 | * @fip: The FCoE controller |
| 2211 | * |
| 2212 | * Called through the local port template for discovery. |
| 2213 | * Called without the ctlr_mutex held. |
| 2214 | */ |
| 2215 | static void fcoe_ctlr_disc_stop_final(struct fc_lport *lport) |
| 2216 | { |
| 2217 | fcoe_ctlr_disc_stop(lport); |
Hannes Reinecke | 5922a95 | 2016-10-18 10:01:46 +0200 | [diff] [blame] | 2218 | fc_rport_flush_queue(); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2219 | synchronize_rcu(); |
| 2220 | } |
| 2221 | |
| 2222 | /** |
| 2223 | * fcoe_ctlr_vn_restart() - VN2VN probe restart with new port_id |
| 2224 | * @fip: The FCoE controller |
| 2225 | * |
| 2226 | * Called with fcoe_ctlr lock held. |
| 2227 | */ |
| 2228 | static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip) |
| 2229 | { |
| 2230 | unsigned long wait; |
| 2231 | u32 port_id; |
| 2232 | |
| 2233 | fcoe_ctlr_disc_stop_locked(fip->lp); |
| 2234 | |
| 2235 | /* |
| 2236 | * Get proposed port ID. |
| 2237 | * If this is the first try after link up, use any previous port_id. |
| 2238 | * If there was none, use the low bits of the port_name. |
| 2239 | * On subsequent tries, get the next random one. |
| 2240 | * Don't use reserved IDs, use another non-zero value, just as random. |
| 2241 | */ |
| 2242 | port_id = fip->port_id; |
| 2243 | if (fip->probe_tries) |
Akinobu Mita | 496f2f9 | 2012-12-17 16:04:23 -0800 | [diff] [blame] | 2244 | port_id = prandom_u32_state(&fip->rnd_state) & 0xffff; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2245 | else if (!port_id) |
| 2246 | port_id = fip->lp->wwpn & 0xffff; |
| 2247 | if (!port_id || port_id == 0xffff) |
| 2248 | port_id = 1; |
| 2249 | fip->port_id = port_id; |
| 2250 | |
| 2251 | if (fip->probe_tries < FIP_VN_RLIM_COUNT) { |
| 2252 | fip->probe_tries++; |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 2253 | wait = prandom_u32() % FIP_VN_PROBE_WAIT; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2254 | } else |
| 2255 | wait = FIP_VN_RLIM_INT; |
| 2256 | mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait)); |
| 2257 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_START); |
| 2258 | } |
| 2259 | |
| 2260 | /** |
| 2261 | * fcoe_ctlr_vn_start() - Start in VN2VN mode |
| 2262 | * @fip: The FCoE controller |
| 2263 | * |
| 2264 | * Called with fcoe_ctlr lock held. |
| 2265 | */ |
| 2266 | static void fcoe_ctlr_vn_start(struct fcoe_ctlr *fip) |
| 2267 | { |
| 2268 | fip->probe_tries = 0; |
Akinobu Mita | 496f2f9 | 2012-12-17 16:04:23 -0800 | [diff] [blame] | 2269 | prandom_seed_state(&fip->rnd_state, fip->lp->wwpn); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2270 | fcoe_ctlr_vn_restart(fip); |
| 2271 | } |
| 2272 | |
| 2273 | /** |
| 2274 | * fcoe_ctlr_vn_parse - parse probe request or response |
| 2275 | * @fip: The FCoE controller |
| 2276 | * @skb: incoming packet |
| 2277 | * @rdata: buffer for resulting parsed VN entry plus fcoe_rport |
| 2278 | * |
| 2279 | * Returns non-zero error number on error. |
| 2280 | * Does not consume the packet. |
| 2281 | */ |
| 2282 | static int fcoe_ctlr_vn_parse(struct fcoe_ctlr *fip, |
| 2283 | struct sk_buff *skb, |
| 2284 | struct fc_rport_priv *rdata) |
| 2285 | { |
| 2286 | struct fip_header *fiph; |
| 2287 | struct fip_desc *desc = NULL; |
| 2288 | struct fip_mac_desc *macd = NULL; |
| 2289 | struct fip_wwn_desc *wwn = NULL; |
| 2290 | struct fip_vn_desc *vn = NULL; |
| 2291 | struct fip_size_desc *size = NULL; |
| 2292 | struct fcoe_rport *frport; |
| 2293 | size_t rlen; |
| 2294 | size_t dlen; |
| 2295 | u32 desc_mask = 0; |
| 2296 | u32 dtype; |
| 2297 | u8 sub; |
| 2298 | |
| 2299 | memset(rdata, 0, sizeof(*rdata) + sizeof(*frport)); |
| 2300 | frport = fcoe_ctlr_rport(rdata); |
| 2301 | |
| 2302 | fiph = (struct fip_header *)skb->data; |
| 2303 | frport->flags = ntohs(fiph->fip_flags); |
| 2304 | |
| 2305 | sub = fiph->fip_subcode; |
| 2306 | switch (sub) { |
| 2307 | case FIP_SC_VN_PROBE_REQ: |
| 2308 | case FIP_SC_VN_PROBE_REP: |
| 2309 | case FIP_SC_VN_BEACON: |
| 2310 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | |
| 2311 | BIT(FIP_DT_VN_ID); |
| 2312 | break; |
| 2313 | case FIP_SC_VN_CLAIM_NOTIFY: |
| 2314 | case FIP_SC_VN_CLAIM_REP: |
| 2315 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | |
| 2316 | BIT(FIP_DT_VN_ID) | BIT(FIP_DT_FC4F) | |
| 2317 | BIT(FIP_DT_FCOE_SIZE); |
| 2318 | break; |
| 2319 | default: |
| 2320 | LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); |
| 2321 | return -EINVAL; |
| 2322 | } |
| 2323 | |
| 2324 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 2325 | if (rlen + sizeof(*fiph) > skb->len) |
| 2326 | return -EINVAL; |
| 2327 | |
| 2328 | desc = (struct fip_desc *)(fiph + 1); |
| 2329 | while (rlen > 0) { |
| 2330 | dlen = desc->fip_dlen * FIP_BPW; |
| 2331 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 2332 | return -EINVAL; |
| 2333 | |
| 2334 | dtype = desc->fip_dtype; |
| 2335 | if (dtype < 32) { |
| 2336 | if (!(desc_mask & BIT(dtype))) { |
| 2337 | LIBFCOE_FIP_DBG(fip, |
| 2338 | "unexpected or duplicated desc " |
| 2339 | "desc type %u in " |
| 2340 | "FIP VN2VN subtype %u\n", |
| 2341 | dtype, sub); |
| 2342 | return -EINVAL; |
| 2343 | } |
| 2344 | desc_mask &= ~BIT(dtype); |
| 2345 | } |
| 2346 | |
| 2347 | switch (dtype) { |
| 2348 | case FIP_DT_MAC: |
| 2349 | if (dlen != sizeof(struct fip_mac_desc)) |
| 2350 | goto len_err; |
| 2351 | macd = (struct fip_mac_desc *)desc; |
| 2352 | if (!is_valid_ether_addr(macd->fd_mac)) { |
| 2353 | LIBFCOE_FIP_DBG(fip, |
| 2354 | "Invalid MAC addr %pM in FIP VN2VN\n", |
| 2355 | macd->fd_mac); |
| 2356 | return -EINVAL; |
| 2357 | } |
| 2358 | memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); |
| 2359 | break; |
| 2360 | case FIP_DT_NAME: |
| 2361 | if (dlen != sizeof(struct fip_wwn_desc)) |
| 2362 | goto len_err; |
| 2363 | wwn = (struct fip_wwn_desc *)desc; |
| 2364 | rdata->ids.node_name = get_unaligned_be64(&wwn->fd_wwn); |
| 2365 | break; |
| 2366 | case FIP_DT_VN_ID: |
| 2367 | if (dlen != sizeof(struct fip_vn_desc)) |
| 2368 | goto len_err; |
| 2369 | vn = (struct fip_vn_desc *)desc; |
| 2370 | memcpy(frport->vn_mac, vn->fd_mac, ETH_ALEN); |
| 2371 | rdata->ids.port_id = ntoh24(vn->fd_fc_id); |
| 2372 | rdata->ids.port_name = get_unaligned_be64(&vn->fd_wwpn); |
| 2373 | break; |
| 2374 | case FIP_DT_FC4F: |
| 2375 | if (dlen != sizeof(struct fip_fc4_feat)) |
| 2376 | goto len_err; |
| 2377 | break; |
| 2378 | case FIP_DT_FCOE_SIZE: |
| 2379 | if (dlen != sizeof(struct fip_size_desc)) |
| 2380 | goto len_err; |
| 2381 | size = (struct fip_size_desc *)desc; |
| 2382 | frport->fcoe_len = ntohs(size->fd_size); |
| 2383 | break; |
| 2384 | default: |
| 2385 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
| 2386 | "in FIP probe\n", dtype); |
| 2387 | /* standard says ignore unknown descriptors >= 128 */ |
Hannes Reinecke | 6a551c1 | 2016-07-04 10:29:18 +0200 | [diff] [blame] | 2388 | if (dtype < FIP_DT_NON_CRITICAL) |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2389 | return -EINVAL; |
| 2390 | break; |
| 2391 | } |
| 2392 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 2393 | rlen -= dlen; |
| 2394 | } |
| 2395 | return 0; |
| 2396 | |
| 2397 | len_err: |
| 2398 | LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n", |
| 2399 | dtype, dlen); |
| 2400 | return -EINVAL; |
| 2401 | } |
| 2402 | |
| 2403 | /** |
| 2404 | * fcoe_ctlr_vn_send_claim() - send multicast FIP VN2VN Claim Notification. |
| 2405 | * @fip: The FCoE controller |
| 2406 | * |
| 2407 | * Called with ctlr_mutex held. |
| 2408 | */ |
| 2409 | static void fcoe_ctlr_vn_send_claim(struct fcoe_ctlr *fip) |
| 2410 | { |
| 2411 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_NOTIFY, fcoe_all_vn2vn, 0); |
| 2412 | fip->sol_time = jiffies; |
| 2413 | } |
| 2414 | |
| 2415 | /** |
| 2416 | * fcoe_ctlr_vn_probe_req() - handle incoming VN2VN probe request. |
| 2417 | * @fip: The FCoE controller |
| 2418 | * @rdata: parsed remote port with frport from the probe request |
| 2419 | * |
| 2420 | * Called with ctlr_mutex held. |
| 2421 | */ |
| 2422 | static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr *fip, |
| 2423 | struct fc_rport_priv *rdata) |
| 2424 | { |
| 2425 | struct fcoe_rport *frport = fcoe_ctlr_rport(rdata); |
| 2426 | |
| 2427 | if (rdata->ids.port_id != fip->port_id) |
| 2428 | return; |
| 2429 | |
| 2430 | switch (fip->state) { |
| 2431 | case FIP_ST_VNMP_CLAIM: |
| 2432 | case FIP_ST_VNMP_UP: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2433 | LIBFCOE_FIP_DBG(fip, "vn_probe_req: send reply, state %x\n", |
| 2434 | fip->state); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2435 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP, |
| 2436 | frport->enode_mac, 0); |
| 2437 | break; |
| 2438 | case FIP_ST_VNMP_PROBE1: |
| 2439 | case FIP_ST_VNMP_PROBE2: |
| 2440 | /* |
| 2441 | * Decide whether to reply to the Probe. |
| 2442 | * Our selected address is never a "recorded" one, so |
| 2443 | * only reply if our WWPN is greater and the |
| 2444 | * Probe's REC bit is not set. |
| 2445 | * If we don't reply, we will change our address. |
| 2446 | */ |
| 2447 | if (fip->lp->wwpn > rdata->ids.port_name && |
| 2448 | !(frport->flags & FIP_FL_REC_OR_P2P)) { |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2449 | LIBFCOE_FIP_DBG(fip, "vn_probe_req: " |
| 2450 | "port_id collision\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2451 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP, |
| 2452 | frport->enode_mac, 0); |
| 2453 | break; |
| 2454 | } |
| 2455 | /* fall through */ |
| 2456 | case FIP_ST_VNMP_START: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2457 | LIBFCOE_FIP_DBG(fip, "vn_probe_req: " |
| 2458 | "restart VN2VN negotiation\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2459 | fcoe_ctlr_vn_restart(fip); |
| 2460 | break; |
| 2461 | default: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2462 | LIBFCOE_FIP_DBG(fip, "vn_probe_req: ignore state %x\n", |
| 2463 | fip->state); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2464 | break; |
| 2465 | } |
| 2466 | } |
| 2467 | |
| 2468 | /** |
| 2469 | * fcoe_ctlr_vn_probe_reply() - handle incoming VN2VN probe reply. |
| 2470 | * @fip: The FCoE controller |
| 2471 | * @rdata: parsed remote port with frport from the probe request |
| 2472 | * |
| 2473 | * Called with ctlr_mutex held. |
| 2474 | */ |
| 2475 | static void fcoe_ctlr_vn_probe_reply(struct fcoe_ctlr *fip, |
| 2476 | struct fc_rport_priv *rdata) |
| 2477 | { |
| 2478 | if (rdata->ids.port_id != fip->port_id) |
| 2479 | return; |
| 2480 | switch (fip->state) { |
| 2481 | case FIP_ST_VNMP_START: |
| 2482 | case FIP_ST_VNMP_PROBE1: |
| 2483 | case FIP_ST_VNMP_PROBE2: |
| 2484 | case FIP_ST_VNMP_CLAIM: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2485 | LIBFCOE_FIP_DBG(fip, "vn_probe_reply: restart state %x\n", |
| 2486 | fip->state); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2487 | fcoe_ctlr_vn_restart(fip); |
| 2488 | break; |
| 2489 | case FIP_ST_VNMP_UP: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2490 | LIBFCOE_FIP_DBG(fip, "vn_probe_reply: send claim notify\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2491 | fcoe_ctlr_vn_send_claim(fip); |
| 2492 | break; |
| 2493 | default: |
| 2494 | break; |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | /** |
| 2499 | * fcoe_ctlr_vn_add() - Add a VN2VN entry to the list, based on a claim reply. |
| 2500 | * @fip: The FCoE controller |
| 2501 | * @new: newly-parsed remote port with frport as a template for new rdata |
| 2502 | * |
| 2503 | * Called with ctlr_mutex held. |
| 2504 | */ |
| 2505 | static void fcoe_ctlr_vn_add(struct fcoe_ctlr *fip, struct fc_rport_priv *new) |
| 2506 | { |
| 2507 | struct fc_lport *lport = fip->lp; |
| 2508 | struct fc_rport_priv *rdata; |
| 2509 | struct fc_rport_identifiers *ids; |
| 2510 | struct fcoe_rport *frport; |
| 2511 | u32 port_id; |
| 2512 | |
| 2513 | port_id = new->ids.port_id; |
| 2514 | if (port_id == fip->port_id) |
| 2515 | return; |
| 2516 | |
| 2517 | mutex_lock(&lport->disc.disc_mutex); |
Hannes Reinecke | 2580064 | 2016-10-18 10:01:42 +0200 | [diff] [blame] | 2518 | rdata = fc_rport_create(lport, port_id); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2519 | if (!rdata) { |
| 2520 | mutex_unlock(&lport->disc.disc_mutex); |
| 2521 | return; |
| 2522 | } |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2523 | mutex_lock(&rdata->rp_mutex); |
| 2524 | mutex_unlock(&lport->disc.disc_mutex); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2525 | |
| 2526 | rdata->ops = &fcoe_ctlr_vn_rport_ops; |
| 2527 | rdata->disc_id = lport->disc.disc_id; |
| 2528 | |
| 2529 | ids = &rdata->ids; |
| 2530 | if ((ids->port_name != -1 && ids->port_name != new->ids.port_name) || |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2531 | (ids->node_name != -1 && ids->node_name != new->ids.node_name)) { |
| 2532 | mutex_unlock(&rdata->rp_mutex); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2533 | LIBFCOE_FIP_DBG(fip, "vn_add rport logoff %6.6x\n", port_id); |
Hannes Reinecke | c96c792 | 2016-10-18 10:01:44 +0200 | [diff] [blame] | 2534 | fc_rport_logoff(rdata); |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2535 | mutex_lock(&rdata->rp_mutex); |
| 2536 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2537 | ids->port_name = new->ids.port_name; |
| 2538 | ids->node_name = new->ids.node_name; |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2539 | mutex_unlock(&rdata->rp_mutex); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2540 | |
| 2541 | frport = fcoe_ctlr_rport(rdata); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2542 | LIBFCOE_FIP_DBG(fip, "vn_add rport %6.6x %s state %d\n", |
| 2543 | port_id, frport->fcoe_len ? "old" : "new", |
| 2544 | rdata->rp_state); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2545 | *frport = *fcoe_ctlr_rport(new); |
| 2546 | frport->time = 0; |
| 2547 | } |
| 2548 | |
| 2549 | /** |
| 2550 | * fcoe_ctlr_vn_lookup() - Find VN remote port's MAC address |
| 2551 | * @fip: The FCoE controller |
| 2552 | * @port_id: The port_id of the remote VN_node |
| 2553 | * @mac: buffer which will hold the VN_NODE destination MAC address, if found. |
| 2554 | * |
| 2555 | * Returns non-zero error if no remote port found. |
| 2556 | */ |
| 2557 | static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr *fip, u32 port_id, u8 *mac) |
| 2558 | { |
| 2559 | struct fc_lport *lport = fip->lp; |
| 2560 | struct fc_rport_priv *rdata; |
| 2561 | struct fcoe_rport *frport; |
| 2562 | int ret = -1; |
| 2563 | |
Hannes Reinecke | e87b777 | 2016-10-18 10:01:40 +0200 | [diff] [blame] | 2564 | rdata = fc_rport_lookup(lport, port_id); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2565 | if (rdata) { |
| 2566 | frport = fcoe_ctlr_rport(rdata); |
| 2567 | memcpy(mac, frport->enode_mac, ETH_ALEN); |
| 2568 | ret = 0; |
Hannes Reinecke | 944ef96 | 2016-10-18 10:01:39 +0200 | [diff] [blame] | 2569 | kref_put(&rdata->kref, fc_rport_destroy); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2570 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2571 | return ret; |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * fcoe_ctlr_vn_claim_notify() - handle received FIP VN2VN Claim Notification |
| 2576 | * @fip: The FCoE controller |
| 2577 | * @new: newly-parsed remote port with frport as a template for new rdata |
| 2578 | * |
| 2579 | * Called with ctlr_mutex held. |
| 2580 | */ |
| 2581 | static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr *fip, |
| 2582 | struct fc_rport_priv *new) |
| 2583 | { |
| 2584 | struct fcoe_rport *frport = fcoe_ctlr_rport(new); |
| 2585 | |
| 2586 | if (frport->flags & FIP_FL_REC_OR_P2P) { |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2587 | LIBFCOE_FIP_DBG(fip, "send probe req for P2P/REC\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2588 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 2589 | return; |
| 2590 | } |
| 2591 | switch (fip->state) { |
| 2592 | case FIP_ST_VNMP_START: |
| 2593 | case FIP_ST_VNMP_PROBE1: |
| 2594 | case FIP_ST_VNMP_PROBE2: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2595 | if (new->ids.port_id == fip->port_id) { |
| 2596 | LIBFCOE_FIP_DBG(fip, "vn_claim_notify: " |
| 2597 | "restart, state %d\n", |
| 2598 | fip->state); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2599 | fcoe_ctlr_vn_restart(fip); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2600 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2601 | break; |
| 2602 | case FIP_ST_VNMP_CLAIM: |
| 2603 | case FIP_ST_VNMP_UP: |
| 2604 | if (new->ids.port_id == fip->port_id) { |
| 2605 | if (new->ids.port_name > fip->lp->wwpn) { |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2606 | LIBFCOE_FIP_DBG(fip, "vn_claim_notify: " |
| 2607 | "restart, port_id collision\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2608 | fcoe_ctlr_vn_restart(fip); |
| 2609 | break; |
| 2610 | } |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2611 | LIBFCOE_FIP_DBG(fip, "vn_claim_notify: " |
| 2612 | "send claim notify\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2613 | fcoe_ctlr_vn_send_claim(fip); |
| 2614 | break; |
| 2615 | } |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2616 | LIBFCOE_FIP_DBG(fip, "vn_claim_notify: send reply to %x\n", |
| 2617 | new->ids.port_id); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2618 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, frport->enode_mac, |
| 2619 | min((u32)frport->fcoe_len, |
| 2620 | fcoe_ctlr_fcoe_size(fip))); |
| 2621 | fcoe_ctlr_vn_add(fip, new); |
| 2622 | break; |
| 2623 | default: |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2624 | LIBFCOE_FIP_DBG(fip, "vn_claim_notify: " |
| 2625 | "ignoring claim from %x\n", new->ids.port_id); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2626 | break; |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | /** |
| 2631 | * fcoe_ctlr_vn_claim_resp() - handle received Claim Response |
| 2632 | * @fip: The FCoE controller that received the frame |
| 2633 | * @new: newly-parsed remote port with frport from the Claim Response |
| 2634 | * |
| 2635 | * Called with ctlr_mutex held. |
| 2636 | */ |
| 2637 | static void fcoe_ctlr_vn_claim_resp(struct fcoe_ctlr *fip, |
| 2638 | struct fc_rport_priv *new) |
| 2639 | { |
| 2640 | LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n", |
| 2641 | new->ids.port_id, fcoe_ctlr_state(fip->state)); |
| 2642 | if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM) |
| 2643 | fcoe_ctlr_vn_add(fip, new); |
| 2644 | } |
| 2645 | |
| 2646 | /** |
| 2647 | * fcoe_ctlr_vn_beacon() - handle received beacon. |
| 2648 | * @fip: The FCoE controller that received the frame |
| 2649 | * @new: newly-parsed remote port with frport from the Beacon |
| 2650 | * |
| 2651 | * Called with ctlr_mutex held. |
| 2652 | */ |
| 2653 | static void fcoe_ctlr_vn_beacon(struct fcoe_ctlr *fip, |
| 2654 | struct fc_rport_priv *new) |
| 2655 | { |
| 2656 | struct fc_lport *lport = fip->lp; |
| 2657 | struct fc_rport_priv *rdata; |
| 2658 | struct fcoe_rport *frport; |
| 2659 | |
| 2660 | frport = fcoe_ctlr_rport(new); |
| 2661 | if (frport->flags & FIP_FL_REC_OR_P2P) { |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2662 | LIBFCOE_FIP_DBG(fip, "p2p beacon while in vn2vn mode\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2663 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 2664 | return; |
| 2665 | } |
Hannes Reinecke | e87b777 | 2016-10-18 10:01:40 +0200 | [diff] [blame] | 2666 | rdata = fc_rport_lookup(lport, new->ids.port_id); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2667 | if (rdata) { |
| 2668 | if (rdata->ids.node_name == new->ids.node_name && |
| 2669 | rdata->ids.port_name == new->ids.port_name) { |
| 2670 | frport = fcoe_ctlr_rport(rdata); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2671 | LIBFCOE_FIP_DBG(fip, "beacon from rport %x\n", |
| 2672 | rdata->ids.port_id); |
| 2673 | if (!frport->time && fip->state == FIP_ST_VNMP_UP) { |
| 2674 | LIBFCOE_FIP_DBG(fip, "beacon expired " |
| 2675 | "for rport %x\n", |
| 2676 | rdata->ids.port_id); |
Hannes Reinecke | 05d7d3b | 2016-10-18 10:01:43 +0200 | [diff] [blame] | 2677 | fc_rport_login(rdata); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 2678 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2679 | frport->time = jiffies; |
| 2680 | } |
Hannes Reinecke | 944ef96 | 2016-10-18 10:01:39 +0200 | [diff] [blame] | 2681 | kref_put(&rdata->kref, fc_rport_destroy); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2682 | return; |
| 2683 | } |
| 2684 | if (fip->state != FIP_ST_VNMP_UP) |
| 2685 | return; |
| 2686 | |
| 2687 | /* |
| 2688 | * Beacon from a new neighbor. |
| 2689 | * Send a claim notify if one hasn't been sent recently. |
| 2690 | * Don't add the neighbor yet. |
| 2691 | */ |
| 2692 | LIBFCOE_FIP_DBG(fip, "beacon from new rport %x. sending claim notify\n", |
| 2693 | new->ids.port_id); |
| 2694 | if (time_after(jiffies, |
| 2695 | fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT))) |
| 2696 | fcoe_ctlr_vn_send_claim(fip); |
| 2697 | } |
| 2698 | |
| 2699 | /** |
| 2700 | * fcoe_ctlr_vn_age() - Check for VN_ports without recent beacons |
| 2701 | * @fip: The FCoE controller |
| 2702 | * |
| 2703 | * Called with ctlr_mutex held. |
| 2704 | * Called only in state FIP_ST_VNMP_UP. |
| 2705 | * Returns the soonest time for next age-out or a time far in the future. |
| 2706 | */ |
| 2707 | static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr *fip) |
| 2708 | { |
| 2709 | struct fc_lport *lport = fip->lp; |
| 2710 | struct fc_rport_priv *rdata; |
| 2711 | struct fcoe_rport *frport; |
| 2712 | unsigned long next_time; |
| 2713 | unsigned long deadline; |
| 2714 | |
| 2715 | next_time = jiffies + msecs_to_jiffies(FIP_VN_BEACON_INT * 10); |
Hannes Reinecke | 0993ed9 | 2018-07-11 10:09:30 +0200 | [diff] [blame] | 2716 | mutex_lock(&lport->disc.disc_mutex); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2717 | list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2718 | if (!kref_get_unless_zero(&rdata->kref)) |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2719 | continue; |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2720 | frport = fcoe_ctlr_rport(rdata); |
| 2721 | if (!frport->time) { |
Hannes Reinecke | 944ef96 | 2016-10-18 10:01:39 +0200 | [diff] [blame] | 2722 | kref_put(&rdata->kref, fc_rport_destroy); |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 2723 | continue; |
| 2724 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2725 | deadline = frport->time + |
| 2726 | msecs_to_jiffies(FIP_VN_BEACON_INT * 25 / 10); |
| 2727 | if (time_after_eq(jiffies, deadline)) { |
| 2728 | frport->time = 0; |
| 2729 | LIBFCOE_FIP_DBG(fip, |
| 2730 | "port %16.16llx fc_id %6.6x beacon expired\n", |
| 2731 | rdata->ids.port_name, rdata->ids.port_id); |
Hannes Reinecke | c96c792 | 2016-10-18 10:01:44 +0200 | [diff] [blame] | 2732 | fc_rport_logoff(rdata); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2733 | } else if (time_before(deadline, next_time)) |
| 2734 | next_time = deadline; |
Hannes Reinecke | 944ef96 | 2016-10-18 10:01:39 +0200 | [diff] [blame] | 2735 | kref_put(&rdata->kref, fc_rport_destroy); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2736 | } |
Hannes Reinecke | 0993ed9 | 2018-07-11 10:09:30 +0200 | [diff] [blame] | 2737 | mutex_unlock(&lport->disc.disc_mutex); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2738 | return next_time; |
| 2739 | } |
| 2740 | |
| 2741 | /** |
| 2742 | * fcoe_ctlr_vn_recv() - Receive a FIP frame |
| 2743 | * @fip: The FCoE controller that received the frame |
| 2744 | * @skb: The received FIP frame |
| 2745 | * |
| 2746 | * Returns non-zero if the frame is dropped. |
| 2747 | * Always consumes the frame. |
| 2748 | */ |
| 2749 | static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 2750 | { |
| 2751 | struct fip_header *fiph; |
| 2752 | enum fip_vn2vn_subcode sub; |
Kiran Patil | 2dc02ee | 2010-10-08 17:12:41 -0700 | [diff] [blame] | 2753 | struct { |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2754 | struct fc_rport_priv rdata; |
| 2755 | struct fcoe_rport frport; |
| 2756 | } buf; |
Hannes Reinecke | 5d5a51d | 2016-10-13 15:11:00 +0200 | [diff] [blame] | 2757 | int rc, vlan_id = 0; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2758 | |
| 2759 | fiph = (struct fip_header *)skb->data; |
| 2760 | sub = fiph->fip_subcode; |
| 2761 | |
Hannes Reinecke | 5d5a51d | 2016-10-13 15:11:00 +0200 | [diff] [blame] | 2762 | if (fip->lp->vlan) |
| 2763 | vlan_id = skb_vlan_tag_get_id(skb); |
| 2764 | |
| 2765 | if (vlan_id && vlan_id != fip->lp->vlan) { |
| 2766 | LIBFCOE_FIP_DBG(fip, "vn_recv drop frame sub %x vlan %d\n", |
| 2767 | sub, vlan_id); |
| 2768 | rc = -EAGAIN; |
| 2769 | goto drop; |
| 2770 | } |
| 2771 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2772 | rc = fcoe_ctlr_vn_parse(fip, skb, &buf.rdata); |
| 2773 | if (rc) { |
| 2774 | LIBFCOE_FIP_DBG(fip, "vn_recv vn_parse error %d\n", rc); |
| 2775 | goto drop; |
| 2776 | } |
| 2777 | |
| 2778 | mutex_lock(&fip->ctlr_mutex); |
| 2779 | switch (sub) { |
| 2780 | case FIP_SC_VN_PROBE_REQ: |
| 2781 | fcoe_ctlr_vn_probe_req(fip, &buf.rdata); |
| 2782 | break; |
| 2783 | case FIP_SC_VN_PROBE_REP: |
| 2784 | fcoe_ctlr_vn_probe_reply(fip, &buf.rdata); |
| 2785 | break; |
| 2786 | case FIP_SC_VN_CLAIM_NOTIFY: |
| 2787 | fcoe_ctlr_vn_claim_notify(fip, &buf.rdata); |
| 2788 | break; |
| 2789 | case FIP_SC_VN_CLAIM_REP: |
| 2790 | fcoe_ctlr_vn_claim_resp(fip, &buf.rdata); |
| 2791 | break; |
| 2792 | case FIP_SC_VN_BEACON: |
| 2793 | fcoe_ctlr_vn_beacon(fip, &buf.rdata); |
| 2794 | break; |
| 2795 | default: |
| 2796 | LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub); |
| 2797 | rc = -1; |
| 2798 | break; |
| 2799 | } |
| 2800 | mutex_unlock(&fip->ctlr_mutex); |
| 2801 | drop: |
| 2802 | kfree_skb(skb); |
| 2803 | return rc; |
| 2804 | } |
| 2805 | |
| 2806 | /** |
Hannes Reinecke | 9a6cf88 | 2016-07-19 13:49:40 +0200 | [diff] [blame] | 2807 | * fcoe_ctlr_vlan_parse - parse vlan discovery request or response |
| 2808 | * @fip: The FCoE controller |
| 2809 | * @skb: incoming packet |
| 2810 | * @rdata: buffer for resulting parsed VLAN entry plus fcoe_rport |
| 2811 | * |
| 2812 | * Returns non-zero error number on error. |
| 2813 | * Does not consume the packet. |
| 2814 | */ |
| 2815 | static int fcoe_ctlr_vlan_parse(struct fcoe_ctlr *fip, |
| 2816 | struct sk_buff *skb, |
| 2817 | struct fc_rport_priv *rdata) |
| 2818 | { |
| 2819 | struct fip_header *fiph; |
| 2820 | struct fip_desc *desc = NULL; |
| 2821 | struct fip_mac_desc *macd = NULL; |
| 2822 | struct fip_wwn_desc *wwn = NULL; |
| 2823 | struct fcoe_rport *frport; |
| 2824 | size_t rlen; |
| 2825 | size_t dlen; |
| 2826 | u32 desc_mask = 0; |
| 2827 | u32 dtype; |
| 2828 | u8 sub; |
| 2829 | |
| 2830 | memset(rdata, 0, sizeof(*rdata) + sizeof(*frport)); |
| 2831 | frport = fcoe_ctlr_rport(rdata); |
| 2832 | |
| 2833 | fiph = (struct fip_header *)skb->data; |
| 2834 | frport->flags = ntohs(fiph->fip_flags); |
| 2835 | |
| 2836 | sub = fiph->fip_subcode; |
| 2837 | switch (sub) { |
| 2838 | case FIP_SC_VL_REQ: |
| 2839 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME); |
| 2840 | break; |
| 2841 | default: |
| 2842 | LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); |
| 2843 | return -EINVAL; |
| 2844 | } |
| 2845 | |
| 2846 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 2847 | if (rlen + sizeof(*fiph) > skb->len) |
| 2848 | return -EINVAL; |
| 2849 | |
| 2850 | desc = (struct fip_desc *)(fiph + 1); |
| 2851 | while (rlen > 0) { |
| 2852 | dlen = desc->fip_dlen * FIP_BPW; |
| 2853 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 2854 | return -EINVAL; |
| 2855 | |
| 2856 | dtype = desc->fip_dtype; |
| 2857 | if (dtype < 32) { |
| 2858 | if (!(desc_mask & BIT(dtype))) { |
| 2859 | LIBFCOE_FIP_DBG(fip, |
| 2860 | "unexpected or duplicated desc " |
| 2861 | "desc type %u in " |
| 2862 | "FIP VN2VN subtype %u\n", |
| 2863 | dtype, sub); |
| 2864 | return -EINVAL; |
| 2865 | } |
| 2866 | desc_mask &= ~BIT(dtype); |
| 2867 | } |
| 2868 | |
| 2869 | switch (dtype) { |
| 2870 | case FIP_DT_MAC: |
| 2871 | if (dlen != sizeof(struct fip_mac_desc)) |
| 2872 | goto len_err; |
| 2873 | macd = (struct fip_mac_desc *)desc; |
| 2874 | if (!is_valid_ether_addr(macd->fd_mac)) { |
| 2875 | LIBFCOE_FIP_DBG(fip, |
| 2876 | "Invalid MAC addr %pM in FIP VN2VN\n", |
| 2877 | macd->fd_mac); |
| 2878 | return -EINVAL; |
| 2879 | } |
| 2880 | memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); |
| 2881 | break; |
| 2882 | case FIP_DT_NAME: |
| 2883 | if (dlen != sizeof(struct fip_wwn_desc)) |
| 2884 | goto len_err; |
| 2885 | wwn = (struct fip_wwn_desc *)desc; |
| 2886 | rdata->ids.node_name = get_unaligned_be64(&wwn->fd_wwn); |
| 2887 | break; |
| 2888 | default: |
| 2889 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
| 2890 | "in FIP probe\n", dtype); |
| 2891 | /* standard says ignore unknown descriptors >= 128 */ |
| 2892 | if (dtype < FIP_DT_NON_CRITICAL) |
| 2893 | return -EINVAL; |
| 2894 | break; |
| 2895 | } |
| 2896 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 2897 | rlen -= dlen; |
| 2898 | } |
| 2899 | return 0; |
| 2900 | |
| 2901 | len_err: |
| 2902 | LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n", |
| 2903 | dtype, dlen); |
| 2904 | return -EINVAL; |
| 2905 | } |
| 2906 | |
| 2907 | /** |
| 2908 | * fcoe_ctlr_vlan_send() - Send a FIP VLAN Notification |
| 2909 | * @fip: The FCoE controller |
| 2910 | * @sub: sub-opcode for vlan notification or vn2vn vlan notification |
| 2911 | * @dest: The destination Ethernet MAC address |
| 2912 | * @min_len: minimum size of the Ethernet payload to be sent |
| 2913 | */ |
| 2914 | static void fcoe_ctlr_vlan_send(struct fcoe_ctlr *fip, |
| 2915 | enum fip_vlan_subcode sub, |
| 2916 | const u8 *dest) |
| 2917 | { |
| 2918 | struct sk_buff *skb; |
| 2919 | struct fip_vlan_notify_frame { |
| 2920 | struct ethhdr eth; |
| 2921 | struct fip_header fip; |
| 2922 | struct fip_mac_desc mac; |
| 2923 | struct fip_vlan_desc vlan; |
| 2924 | } __packed * frame; |
| 2925 | size_t len; |
| 2926 | size_t dlen; |
| 2927 | |
| 2928 | len = sizeof(*frame); |
| 2929 | dlen = sizeof(frame->mac) + sizeof(frame->vlan); |
| 2930 | len = max(len, sizeof(struct ethhdr)); |
| 2931 | |
| 2932 | skb = dev_alloc_skb(len); |
| 2933 | if (!skb) |
| 2934 | return; |
| 2935 | |
| 2936 | LIBFCOE_FIP_DBG(fip, "fip %s vlan notification, vlan %d\n", |
| 2937 | fip->mode == FIP_MODE_VN2VN ? "vn2vn" : "fcf", |
| 2938 | fip->lp->vlan); |
| 2939 | |
| 2940 | frame = (struct fip_vlan_notify_frame *)skb->data; |
| 2941 | memset(frame, 0, len); |
| 2942 | memcpy(frame->eth.h_dest, dest, ETH_ALEN); |
| 2943 | |
| 2944 | memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); |
| 2945 | frame->eth.h_proto = htons(ETH_P_FIP); |
| 2946 | |
| 2947 | frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 2948 | frame->fip.fip_op = htons(FIP_OP_VLAN); |
| 2949 | frame->fip.fip_subcode = sub; |
| 2950 | frame->fip.fip_dl_len = htons(dlen / FIP_BPW); |
| 2951 | |
| 2952 | frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; |
| 2953 | frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; |
| 2954 | memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); |
| 2955 | |
| 2956 | frame->vlan.fd_desc.fip_dtype = FIP_DT_VLAN; |
| 2957 | frame->vlan.fd_desc.fip_dlen = sizeof(frame->vlan) / FIP_BPW; |
| 2958 | put_unaligned_be16(fip->lp->vlan, &frame->vlan.fd_vlan); |
| 2959 | |
| 2960 | skb_put(skb, len); |
| 2961 | skb->protocol = htons(ETH_P_FIP); |
| 2962 | skb->priority = fip->priority; |
| 2963 | skb_reset_mac_header(skb); |
| 2964 | skb_reset_network_header(skb); |
| 2965 | |
| 2966 | fip->send(fip, skb); |
| 2967 | } |
| 2968 | |
| 2969 | /** |
| 2970 | * fcoe_ctlr_vlan_disk_reply() - send FIP VLAN Discovery Notification. |
| 2971 | * @fip: The FCoE controller |
| 2972 | * |
| 2973 | * Called with ctlr_mutex held. |
| 2974 | */ |
| 2975 | static void fcoe_ctlr_vlan_disc_reply(struct fcoe_ctlr *fip, |
| 2976 | struct fc_rport_priv *rdata) |
| 2977 | { |
| 2978 | struct fcoe_rport *frport = fcoe_ctlr_rport(rdata); |
| 2979 | enum fip_vlan_subcode sub = FIP_SC_VL_NOTE; |
| 2980 | |
| 2981 | if (fip->mode == FIP_MODE_VN2VN) |
| 2982 | sub = FIP_SC_VL_VN2VN_NOTE; |
| 2983 | |
| 2984 | fcoe_ctlr_vlan_send(fip, sub, frport->enode_mac); |
| 2985 | } |
| 2986 | |
| 2987 | /** |
| 2988 | * fcoe_ctlr_vlan_recv - vlan request receive handler for VN2VN mode. |
| 2989 | * @lport: The local port |
| 2990 | * @fp: The received frame |
| 2991 | * |
| 2992 | */ |
| 2993 | static int fcoe_ctlr_vlan_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 2994 | { |
| 2995 | struct fip_header *fiph; |
| 2996 | enum fip_vlan_subcode sub; |
| 2997 | struct { |
| 2998 | struct fc_rport_priv rdata; |
| 2999 | struct fcoe_rport frport; |
| 3000 | } buf; |
| 3001 | int rc; |
| 3002 | |
| 3003 | fiph = (struct fip_header *)skb->data; |
| 3004 | sub = fiph->fip_subcode; |
| 3005 | rc = fcoe_ctlr_vlan_parse(fip, skb, &buf.rdata); |
| 3006 | if (rc) { |
| 3007 | LIBFCOE_FIP_DBG(fip, "vlan_recv vlan_parse error %d\n", rc); |
| 3008 | goto drop; |
| 3009 | } |
| 3010 | mutex_lock(&fip->ctlr_mutex); |
| 3011 | if (sub == FIP_SC_VL_REQ) |
| 3012 | fcoe_ctlr_vlan_disc_reply(fip, &buf.rdata); |
| 3013 | mutex_unlock(&fip->ctlr_mutex); |
| 3014 | |
| 3015 | drop: |
Wei Yongjun | ea0a95d | 2016-07-25 07:00:33 +0000 | [diff] [blame] | 3016 | kfree_skb(skb); |
Hannes Reinecke | 9a6cf88 | 2016-07-19 13:49:40 +0200 | [diff] [blame] | 3017 | return rc; |
| 3018 | } |
| 3019 | |
| 3020 | /** |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3021 | * fcoe_ctlr_disc_recv - discovery receive handler for VN2VN mode. |
Joe Eykholt | 92261156 | 2010-07-20 15:21:12 -0700 | [diff] [blame] | 3022 | * @lport: The local port |
| 3023 | * @fp: The received frame |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3024 | * |
| 3025 | * This should never be called since we don't see RSCNs or other |
| 3026 | * fabric-generated ELSes. |
| 3027 | */ |
Joe Eykholt | 92261156 | 2010-07-20 15:21:12 -0700 | [diff] [blame] | 3028 | static void fcoe_ctlr_disc_recv(struct fc_lport *lport, struct fc_frame *fp) |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3029 | { |
| 3030 | struct fc_seq_els_data rjt_data; |
| 3031 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3032 | rjt_data.reason = ELS_RJT_UNSUP; |
| 3033 | rjt_data.explan = ELS_EXPL_NONE; |
Hannes Reinecke | 7ab24dd | 2016-10-18 10:01:35 +0200 | [diff] [blame] | 3034 | fc_seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3035 | fc_frame_free(fp); |
| 3036 | } |
| 3037 | |
| 3038 | /** |
| 3039 | * fcoe_ctlr_disc_recv - start discovery for VN2VN mode. |
| 3040 | * @fip: The FCoE controller |
| 3041 | * |
| 3042 | * This sets a flag indicating that remote ports should be created |
| 3043 | * and started for the peers we discover. We use the disc_callback |
| 3044 | * pointer as that flag. Peers already discovered are created here. |
| 3045 | * |
| 3046 | * The lport lock is held during this call. The callback must be done |
| 3047 | * later, without holding either the lport or discovery locks. |
| 3048 | * The fcoe_ctlr lock may also be held during this call. |
| 3049 | */ |
| 3050 | static void fcoe_ctlr_disc_start(void (*callback)(struct fc_lport *, |
| 3051 | enum fc_disc_event), |
| 3052 | struct fc_lport *lport) |
| 3053 | { |
| 3054 | struct fc_disc *disc = &lport->disc; |
| 3055 | struct fcoe_ctlr *fip = disc->priv; |
| 3056 | |
| 3057 | mutex_lock(&disc->disc_mutex); |
| 3058 | disc->disc_callback = callback; |
| 3059 | disc->disc_id = (disc->disc_id + 2) | 1; |
| 3060 | disc->pending = 1; |
| 3061 | schedule_work(&fip->timer_work); |
| 3062 | mutex_unlock(&disc->disc_mutex); |
| 3063 | } |
| 3064 | |
| 3065 | /** |
| 3066 | * fcoe_ctlr_vn_disc() - report FIP VN_port discovery results after claim state. |
| 3067 | * @fip: The FCoE controller |
| 3068 | * |
| 3069 | * Starts the FLOGI and PLOGI login process to each discovered rport for which |
| 3070 | * we've received at least one beacon. |
| 3071 | * Performs the discovery complete callback. |
| 3072 | */ |
| 3073 | static void fcoe_ctlr_vn_disc(struct fcoe_ctlr *fip) |
| 3074 | { |
| 3075 | struct fc_lport *lport = fip->lp; |
| 3076 | struct fc_disc *disc = &lport->disc; |
| 3077 | struct fc_rport_priv *rdata; |
| 3078 | struct fcoe_rport *frport; |
| 3079 | void (*callback)(struct fc_lport *, enum fc_disc_event); |
| 3080 | |
| 3081 | mutex_lock(&disc->disc_mutex); |
| 3082 | callback = disc->pending ? disc->disc_callback : NULL; |
| 3083 | disc->pending = 0; |
| 3084 | list_for_each_entry_rcu(rdata, &disc->rports, peers) { |
Hannes Reinecke | a407c59 | 2016-09-30 11:01:15 +0200 | [diff] [blame] | 3085 | if (!kref_get_unless_zero(&rdata->kref)) |
| 3086 | continue; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3087 | frport = fcoe_ctlr_rport(rdata); |
| 3088 | if (frport->time) |
Hannes Reinecke | 05d7d3b | 2016-10-18 10:01:43 +0200 | [diff] [blame] | 3089 | fc_rport_login(rdata); |
Hannes Reinecke | 944ef96 | 2016-10-18 10:01:39 +0200 | [diff] [blame] | 3090 | kref_put(&rdata->kref, fc_rport_destroy); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3091 | } |
Hannes Reinecke | 0993ed9 | 2018-07-11 10:09:30 +0200 | [diff] [blame] | 3092 | mutex_unlock(&disc->disc_mutex); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3093 | if (callback) |
| 3094 | callback(lport, DISC_EV_SUCCESS); |
| 3095 | } |
| 3096 | |
| 3097 | /** |
| 3098 | * fcoe_ctlr_vn_timeout - timer work function for VN2VN mode. |
| 3099 | * @fip: The FCoE controller |
| 3100 | */ |
| 3101 | static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *fip) |
| 3102 | { |
| 3103 | unsigned long next_time; |
| 3104 | u8 mac[ETH_ALEN]; |
| 3105 | u32 new_port_id = 0; |
| 3106 | |
| 3107 | mutex_lock(&fip->ctlr_mutex); |
| 3108 | switch (fip->state) { |
| 3109 | case FIP_ST_VNMP_START: |
| 3110 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE1); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 3111 | LIBFCOE_FIP_DBG(fip, "vn_timeout: send 1st probe request\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3112 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 3113 | next_time = jiffies + msecs_to_jiffies(FIP_VN_PROBE_WAIT); |
| 3114 | break; |
| 3115 | case FIP_ST_VNMP_PROBE1: |
| 3116 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE2); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 3117 | LIBFCOE_FIP_DBG(fip, "vn_timeout: send 2nd probe request\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3118 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 3119 | next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 3120 | break; |
| 3121 | case FIP_ST_VNMP_PROBE2: |
| 3122 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_CLAIM); |
| 3123 | new_port_id = fip->port_id; |
| 3124 | hton24(mac, FIP_VN_FC_MAP); |
| 3125 | hton24(mac + 3, new_port_id); |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 3126 | fcoe_ctlr_map_dest(fip); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3127 | fip->update_mac(fip->lp, mac); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 3128 | LIBFCOE_FIP_DBG(fip, "vn_timeout: send claim notify\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3129 | fcoe_ctlr_vn_send_claim(fip); |
| 3130 | next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 3131 | break; |
| 3132 | case FIP_ST_VNMP_CLAIM: |
| 3133 | /* |
| 3134 | * This may be invoked either by starting discovery so don't |
| 3135 | * go to the next state unless it's been long enough. |
| 3136 | */ |
| 3137 | next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 3138 | if (time_after_eq(jiffies, next_time)) { |
| 3139 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_UP); |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 3140 | LIBFCOE_FIP_DBG(fip, "vn_timeout: send vn2vn beacon\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3141 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON, |
| 3142 | fcoe_all_vn2vn, 0); |
| 3143 | next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 3144 | fip->port_ka_time = next_time; |
| 3145 | } |
| 3146 | fcoe_ctlr_vn_disc(fip); |
| 3147 | break; |
| 3148 | case FIP_ST_VNMP_UP: |
| 3149 | next_time = fcoe_ctlr_vn_age(fip); |
| 3150 | if (time_after_eq(jiffies, fip->port_ka_time)) { |
Hannes Reinecke | c959655 | 2016-10-13 15:10:58 +0200 | [diff] [blame] | 3151 | LIBFCOE_FIP_DBG(fip, "vn_timeout: send vn2vn beacon\n"); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3152 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON, |
| 3153 | fcoe_all_vn2vn, 0); |
| 3154 | fip->port_ka_time = jiffies + |
| 3155 | msecs_to_jiffies(FIP_VN_BEACON_INT + |
Akinobu Mita | 3b60a64 | 2013-04-29 16:21:35 -0700 | [diff] [blame] | 3156 | (prandom_u32() % FIP_VN_BEACON_FUZZ)); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3157 | } |
| 3158 | if (time_before(fip->port_ka_time, next_time)) |
| 3159 | next_time = fip->port_ka_time; |
| 3160 | break; |
| 3161 | case FIP_ST_LINK_WAIT: |
| 3162 | goto unlock; |
| 3163 | default: |
Joe Perches | 11aa990 | 2010-11-30 16:19:09 -0800 | [diff] [blame] | 3164 | WARN(1, "unexpected state %d\n", fip->state); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3165 | goto unlock; |
| 3166 | } |
| 3167 | mod_timer(&fip->timer, next_time); |
| 3168 | unlock: |
| 3169 | mutex_unlock(&fip->ctlr_mutex); |
| 3170 | |
| 3171 | /* If port ID is new, notify local port after dropping ctlr_mutex */ |
| 3172 | if (new_port_id) |
| 3173 | fc_lport_set_local_id(fip->lp, new_port_id); |
| 3174 | } |
| 3175 | |
| 3176 | /** |
Robert Love | 0db0e37 | 2013-03-25 11:00:28 -0700 | [diff] [blame] | 3177 | * fcoe_ctlr_mode_set() - Set or reset the ctlr's mode |
| 3178 | * @lport: The local port to be (re)configured |
| 3179 | * @fip: The FCoE controller whose mode is changing |
| 3180 | * @fip_mode: The new fip mode |
| 3181 | * |
| 3182 | * Note that the we shouldn't be changing the libfc discovery settings |
| 3183 | * (fc_disc_config) while an lport is going through the libfc state |
| 3184 | * machine. The mode can only be changed when a fcoe_ctlr device is |
| 3185 | * disabled, so that should ensure that this routine is only called |
| 3186 | * when nothing is happening. |
| 3187 | */ |
Bart Van Assche | 41463a8 | 2013-08-14 15:41:22 +0000 | [diff] [blame] | 3188 | static void fcoe_ctlr_mode_set(struct fc_lport *lport, struct fcoe_ctlr *fip, |
Hannes Reinecke | 1917d42 | 2016-07-04 10:29:19 +0200 | [diff] [blame] | 3189 | enum fip_mode fip_mode) |
Robert Love | 0db0e37 | 2013-03-25 11:00:28 -0700 | [diff] [blame] | 3190 | { |
| 3191 | void *priv; |
| 3192 | |
| 3193 | WARN_ON(lport->state != LPORT_ST_RESET && |
| 3194 | lport->state != LPORT_ST_DISABLED); |
| 3195 | |
| 3196 | if (fip_mode == FIP_MODE_VN2VN) { |
| 3197 | lport->rport_priv_size = sizeof(struct fcoe_rport); |
| 3198 | lport->point_to_multipoint = 1; |
| 3199 | lport->tt.disc_recv_req = fcoe_ctlr_disc_recv; |
| 3200 | lport->tt.disc_start = fcoe_ctlr_disc_start; |
| 3201 | lport->tt.disc_stop = fcoe_ctlr_disc_stop; |
| 3202 | lport->tt.disc_stop_final = fcoe_ctlr_disc_stop_final; |
| 3203 | priv = fip; |
| 3204 | } else { |
| 3205 | lport->rport_priv_size = 0; |
| 3206 | lport->point_to_multipoint = 0; |
| 3207 | lport->tt.disc_recv_req = NULL; |
| 3208 | lport->tt.disc_start = NULL; |
| 3209 | lport->tt.disc_stop = NULL; |
| 3210 | lport->tt.disc_stop_final = NULL; |
| 3211 | priv = lport; |
| 3212 | } |
| 3213 | |
| 3214 | fc_disc_config(lport, priv); |
| 3215 | } |
| 3216 | |
| 3217 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 3218 | * fcoe_libfc_config() - Sets up libfc related properties for local port |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3219 | * @lport: The local port to configure libfc for |
| 3220 | * @fip: The FCoE controller in use by the local port |
| 3221 | * @tt: The libfc function template |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3222 | * @init_fcp: If non-zero, the FCP portion of libfc should be initialized |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 3223 | * |
| 3224 | * Returns : 0 for success |
| 3225 | */ |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3226 | int fcoe_libfc_config(struct fc_lport *lport, struct fcoe_ctlr *fip, |
| 3227 | const struct libfc_function_template *tt, int init_fcp) |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 3228 | { |
| 3229 | /* Set the function pointers set by the LLDD */ |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 3230 | memcpy(&lport->tt, tt, sizeof(*tt)); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 3231 | if (init_fcp && fc_fcp_init(lport)) |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 3232 | return -ENOMEM; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 3233 | fc_exch_init(lport); |
| 3234 | fc_elsct_init(lport); |
| 3235 | fc_lport_init(lport); |
Robert Love | 0807619 | 2013-03-25 11:00:28 -0700 | [diff] [blame] | 3236 | fc_disc_init(lport); |
Robert Love | 0db0e37 | 2013-03-25 11:00:28 -0700 | [diff] [blame] | 3237 | fcoe_ctlr_mode_set(lport, fip, fip->mode); |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 3238 | return 0; |
| 3239 | } |
| 3240 | EXPORT_SYMBOL_GPL(fcoe_libfc_config); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3241 | |
| 3242 | void fcoe_fcf_get_selected(struct fcoe_fcf_device *fcf_dev) |
| 3243 | { |
| 3244 | struct fcoe_ctlr_device *ctlr_dev = fcoe_fcf_dev_to_ctlr_dev(fcf_dev); |
| 3245 | struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr_dev); |
| 3246 | struct fcoe_fcf *fcf; |
| 3247 | |
| 3248 | mutex_lock(&fip->ctlr_mutex); |
| 3249 | mutex_lock(&ctlr_dev->lock); |
| 3250 | |
| 3251 | fcf = fcoe_fcf_device_priv(fcf_dev); |
| 3252 | if (fcf) |
| 3253 | fcf_dev->selected = (fcf == fip->sel_fcf) ? 1 : 0; |
| 3254 | else |
| 3255 | fcf_dev->selected = 0; |
| 3256 | |
| 3257 | mutex_unlock(&ctlr_dev->lock); |
| 3258 | mutex_unlock(&fip->ctlr_mutex); |
| 3259 | } |
| 3260 | EXPORT_SYMBOL(fcoe_fcf_get_selected); |
| 3261 | |
Robert Love | 435c866 | 2012-11-27 06:53:35 +0000 | [diff] [blame] | 3262 | void fcoe_ctlr_set_fip_mode(struct fcoe_ctlr_device *ctlr_dev) |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3263 | { |
| 3264 | struct fcoe_ctlr *ctlr = fcoe_ctlr_device_priv(ctlr_dev); |
Robert Love | 0db0e37 | 2013-03-25 11:00:28 -0700 | [diff] [blame] | 3265 | struct fc_lport *lport = ctlr->lp; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3266 | |
| 3267 | mutex_lock(&ctlr->ctlr_mutex); |
Robert Love | 435c866 | 2012-11-27 06:53:35 +0000 | [diff] [blame] | 3268 | switch (ctlr_dev->mode) { |
| 3269 | case FIP_CONN_TYPE_VN2VN: |
| 3270 | ctlr->mode = FIP_MODE_VN2VN; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3271 | break; |
Robert Love | 435c866 | 2012-11-27 06:53:35 +0000 | [diff] [blame] | 3272 | case FIP_CONN_TYPE_FABRIC: |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3273 | default: |
Robert Love | 435c866 | 2012-11-27 06:53:35 +0000 | [diff] [blame] | 3274 | ctlr->mode = FIP_MODE_FABRIC; |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3275 | break; |
| 3276 | } |
Robert Love | 435c866 | 2012-11-27 06:53:35 +0000 | [diff] [blame] | 3277 | |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3278 | mutex_unlock(&ctlr->ctlr_mutex); |
Robert Love | 0db0e37 | 2013-03-25 11:00:28 -0700 | [diff] [blame] | 3279 | |
| 3280 | fcoe_ctlr_mode_set(lport, ctlr, ctlr->mode); |
Robert Love | 8d55e50 | 2012-05-22 19:06:26 -0700 | [diff] [blame] | 3281 | } |
Robert Love | 435c866 | 2012-11-27 06:53:35 +0000 | [diff] [blame] | 3282 | EXPORT_SYMBOL(fcoe_ctlr_set_fip_mode); |