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