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