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