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 | /* |
| 1003 | * If this is the first validated FCF, note the time and |
| 1004 | * set a timer to trigger selection. |
| 1005 | */ |
Joe Eykholt | d99ee45 | 2010-06-11 16:44:15 -0700 | [diff] [blame] | 1006 | if (mtu_valid && !fip->sel_fcf && fcoe_ctlr_fcf_usable(fcf)) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1007 | fip->sel_time = jiffies + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1008 | msecs_to_jiffies(FCOE_CTLR_START_DELAY); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1009 | if (!timer_pending(&fip->timer) || |
| 1010 | time_before(fip->sel_time, fip->timer.expires)) |
| 1011 | mod_timer(&fip->timer, fip->sel_time); |
| 1012 | } |
| 1013 | out: |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1014 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1018 | * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame |
| 1019 | * @fip: The FCoE controller which received the packet |
| 1020 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1021 | */ |
| 1022 | static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1023 | { |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1024 | struct fc_lport *lport = fip->lp; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1025 | struct fip_header *fiph; |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1026 | struct fc_frame *fp = (struct fc_frame *)skb; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1027 | struct fc_frame_header *fh = NULL; |
| 1028 | struct fip_desc *desc; |
| 1029 | struct fip_encaps *els; |
| 1030 | struct fcoe_dev_stats *stats; |
| 1031 | enum fip_desc_type els_dtype = 0; |
| 1032 | u8 els_op; |
| 1033 | u8 sub; |
| 1034 | u8 granted_mac[ETH_ALEN] = { 0 }; |
| 1035 | size_t els_len = 0; |
| 1036 | size_t rlen; |
| 1037 | size_t dlen; |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1038 | u32 desc_mask = 0; |
| 1039 | u32 desc_cnt = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1040 | |
| 1041 | fiph = (struct fip_header *)skb->data; |
| 1042 | sub = fiph->fip_subcode; |
| 1043 | if (sub != FIP_SC_REQ && sub != FIP_SC_REP) |
| 1044 | goto drop; |
| 1045 | |
| 1046 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 1047 | if (rlen + sizeof(*fiph) > skb->len) |
| 1048 | goto drop; |
| 1049 | |
| 1050 | desc = (struct fip_desc *)(fiph + 1); |
| 1051 | while (rlen > 0) { |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1052 | desc_cnt++; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1053 | dlen = desc->fip_dlen * FIP_BPW; |
| 1054 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 1055 | goto drop; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1056 | /* Drop ELS if there are duplicate critical descriptors */ |
| 1057 | if (desc->fip_dtype < 32) { |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1058 | if (desc_mask & 1U << desc->fip_dtype) { |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1059 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 1060 | "Descriptors in FIP ELS\n"); |
| 1061 | goto drop; |
| 1062 | } |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1063 | desc_mask |= (1 << desc->fip_dtype); |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1064 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1065 | switch (desc->fip_dtype) { |
| 1066 | case FIP_DT_MAC: |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1067 | if (desc_cnt == 1) { |
| 1068 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 1069 | "received out of order\n"); |
| 1070 | goto drop; |
| 1071 | } |
| 1072 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1073 | if (dlen != sizeof(struct fip_mac_desc)) |
| 1074 | goto len_err; |
| 1075 | memcpy(granted_mac, |
| 1076 | ((struct fip_mac_desc *)desc)->fd_mac, |
| 1077 | ETH_ALEN); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1078 | break; |
| 1079 | case FIP_DT_FLOGI: |
| 1080 | case FIP_DT_FDISC: |
| 1081 | case FIP_DT_LOGO: |
| 1082 | case FIP_DT_ELP: |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1083 | if (desc_cnt != 1) { |
| 1084 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 1085 | "received out of order\n"); |
| 1086 | goto drop; |
| 1087 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1088 | if (fh) |
| 1089 | goto drop; |
| 1090 | if (dlen < sizeof(*els) + sizeof(*fh) + 1) |
| 1091 | goto len_err; |
| 1092 | els_len = dlen - sizeof(*els); |
| 1093 | els = (struct fip_encaps *)desc; |
| 1094 | fh = (struct fc_frame_header *)(els + 1); |
| 1095 | els_dtype = desc->fip_dtype; |
| 1096 | break; |
| 1097 | default: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1098 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
Robert Love | 650bd12 | 2009-06-10 15:31:05 -0700 | [diff] [blame] | 1099 | "in FIP adv\n", desc->fip_dtype); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1100 | /* standard says ignore unknown descriptors >= 128 */ |
| 1101 | if (desc->fip_dtype < FIP_DT_VENDOR_BASE) |
| 1102 | goto drop; |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1103 | if (desc_cnt <= 2) { |
| 1104 | LIBFCOE_FIP_DBG(fip, "FIP descriptors " |
| 1105 | "received out of order\n"); |
| 1106 | goto drop; |
| 1107 | } |
Bhanu Prakash Gollapudi | 1508f3ec | 2010-06-11 16:43:38 -0700 | [diff] [blame] | 1108 | break; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1109 | } |
| 1110 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 1111 | rlen -= dlen; |
| 1112 | } |
| 1113 | |
| 1114 | if (!fh) |
| 1115 | goto drop; |
| 1116 | els_op = *(u8 *)(fh + 1); |
| 1117 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1118 | if ((els_dtype == FIP_DT_FLOGI || els_dtype == FIP_DT_FDISC) && |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1119 | sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) { |
| 1120 | if (els_op == ELS_LS_ACC) { |
| 1121 | if (!is_valid_ether_addr(granted_mac)) { |
| 1122 | LIBFCOE_FIP_DBG(fip, |
| 1123 | "Invalid MAC address %pM in FIP ELS\n", |
| 1124 | granted_mac); |
| 1125 | goto drop; |
| 1126 | } |
| 1127 | memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1128 | |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1129 | if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) { |
| 1130 | fip->flogi_oxid = FC_XID_UNKNOWN; |
| 1131 | if (els_dtype == FIP_DT_FLOGI) |
| 1132 | fcoe_ctlr_announce(fip); |
| 1133 | } |
| 1134 | } else if (els_dtype == FIP_DT_FLOGI && |
| 1135 | !fcoe_ctlr_flogi_retry(fip)) |
| 1136 | goto drop; /* retrying FLOGI so drop reject */ |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1137 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1138 | |
Bhanu Prakash Gollapudi | be61331 | 2010-06-11 16:44:36 -0700 | [diff] [blame] | 1139 | if ((desc_cnt == 0) || ((els_op != ELS_LS_RJT) && |
| 1140 | (!(1U << FIP_DT_MAC & desc_mask)))) { |
| 1141 | LIBFCOE_FIP_DBG(fip, "Missing critical descriptors " |
| 1142 | "in FIP ELS\n"); |
| 1143 | goto drop; |
| 1144 | } |
| 1145 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1146 | /* |
| 1147 | * Convert skb into an fc_frame containing only the ELS. |
| 1148 | */ |
| 1149 | skb_pull(skb, (u8 *)fh - skb->data); |
| 1150 | skb_trim(skb, els_len); |
| 1151 | fp = (struct fc_frame *)skb; |
| 1152 | fc_frame_init(fp); |
| 1153 | fr_sof(fp) = FC_SOF_I3; |
| 1154 | fr_eof(fp) = FC_EOF_T; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1155 | fr_dev(fp) = lport; |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1156 | fr_encaps(fp) = els_dtype; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1157 | |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 1158 | stats = per_cpu_ptr(lport->dev_stats, get_cpu()); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1159 | stats->RxFrames++; |
| 1160 | stats->RxWords += skb->len / FIP_BPW; |
Joe Eykholt | f018b73 | 2010-03-12 16:08:55 -0800 | [diff] [blame] | 1161 | put_cpu(); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1162 | |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1163 | fc_exch_recv(lport, fp); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1164 | return; |
| 1165 | |
| 1166 | len_err: |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1167 | 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] | 1168 | desc->fip_dtype, dlen); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1169 | drop: |
| 1170 | kfree_skb(skb); |
| 1171 | } |
| 1172 | |
| 1173 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1174 | * fcoe_ctlr_recv_els() - Handle an incoming link reset frame |
| 1175 | * @fip: The FCoE controller that received the frame |
| 1176 | * @fh: The received FIP header |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1177 | * |
| 1178 | * There may be multiple VN_Port descriptors. |
| 1179 | * The overall length has already been checked. |
| 1180 | */ |
| 1181 | static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip, |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1182 | struct fip_header *fh) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1183 | { |
| 1184 | struct fip_desc *desc; |
| 1185 | struct fip_mac_desc *mp; |
| 1186 | struct fip_wwn_desc *wp; |
| 1187 | struct fip_vn_desc *vp; |
| 1188 | size_t rlen; |
| 1189 | size_t dlen; |
| 1190 | struct fcoe_fcf *fcf = fip->sel_fcf; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1191 | struct fc_lport *lport = fip->lp; |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1192 | struct fc_lport *vn_port = NULL; |
| 1193 | u32 desc_mask; |
| 1194 | int is_vn_port = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1195 | |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1196 | LIBFCOE_FIP_DBG(fip, "Clear Virtual Link received\n"); |
Robert Love | d29510a | 2010-05-07 15:18:30 -0700 | [diff] [blame] | 1197 | |
Robert Love | 7b2787e | 2010-05-07 15:18:41 -0700 | [diff] [blame] | 1198 | if (!fcf || !lport->port_id) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1199 | return; |
| 1200 | |
| 1201 | /* |
| 1202 | * mask of required descriptors. Validating each one clears its bit. |
| 1203 | */ |
| 1204 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | BIT(FIP_DT_VN_ID); |
| 1205 | |
| 1206 | rlen = ntohs(fh->fip_dl_len) * FIP_BPW; |
| 1207 | desc = (struct fip_desc *)(fh + 1); |
| 1208 | while (rlen >= sizeof(*desc)) { |
| 1209 | dlen = desc->fip_dlen * FIP_BPW; |
| 1210 | if (dlen > rlen) |
| 1211 | return; |
Bhanu Prakash Gollapudi | 0a9c5d3 | 2010-06-11 16:44:25 -0700 | [diff] [blame] | 1212 | /* Drop CVL if there are duplicate critical descriptors */ |
| 1213 | if ((desc->fip_dtype < 32) && |
| 1214 | !(desc_mask & 1U << desc->fip_dtype)) { |
| 1215 | LIBFCOE_FIP_DBG(fip, "Duplicate Critical " |
| 1216 | "Descriptors in FIP CVL\n"); |
| 1217 | return; |
| 1218 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1219 | switch (desc->fip_dtype) { |
| 1220 | case FIP_DT_MAC: |
| 1221 | mp = (struct fip_mac_desc *)desc; |
| 1222 | if (dlen < sizeof(*mp)) |
| 1223 | return; |
| 1224 | if (compare_ether_addr(mp->fd_mac, fcf->fcf_mac)) |
| 1225 | return; |
| 1226 | desc_mask &= ~BIT(FIP_DT_MAC); |
| 1227 | break; |
| 1228 | case FIP_DT_NAME: |
| 1229 | wp = (struct fip_wwn_desc *)desc; |
| 1230 | if (dlen < sizeof(*wp)) |
| 1231 | return; |
| 1232 | if (get_unaligned_be64(&wp->fd_wwn) != fcf->switch_name) |
| 1233 | return; |
| 1234 | desc_mask &= ~BIT(FIP_DT_NAME); |
| 1235 | break; |
| 1236 | case FIP_DT_VN_ID: |
| 1237 | vp = (struct fip_vn_desc *)desc; |
| 1238 | if (dlen < sizeof(*vp)) |
| 1239 | return; |
| 1240 | if (compare_ether_addr(vp->fd_mac, |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1241 | fip->get_src_addr(lport)) == 0 && |
| 1242 | get_unaligned_be64(&vp->fd_wwpn) == lport->wwpn && |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1243 | ntoh24(vp->fd_fc_id) == lport->port_id) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1244 | desc_mask &= ~BIT(FIP_DT_VN_ID); |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1245 | break; |
| 1246 | } |
| 1247 | /* check if clr_vlink is for NPIV port */ |
| 1248 | mutex_lock(&lport->lp_mutex); |
| 1249 | list_for_each_entry(vn_port, &lport->vports, list) { |
| 1250 | if (compare_ether_addr(vp->fd_mac, |
| 1251 | fip->get_src_addr(vn_port)) == 0 && |
| 1252 | (get_unaligned_be64(&vp->fd_wwpn) |
| 1253 | == vn_port->wwpn) && |
| 1254 | (ntoh24(vp->fd_fc_id) == |
| 1255 | fc_host_port_id(vn_port->host))) { |
| 1256 | desc_mask &= ~BIT(FIP_DT_VN_ID); |
| 1257 | is_vn_port = 1; |
| 1258 | break; |
| 1259 | } |
| 1260 | } |
| 1261 | mutex_unlock(&lport->lp_mutex); |
| 1262 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1263 | break; |
| 1264 | default: |
| 1265 | /* standard says ignore unknown descriptors >= 128 */ |
| 1266 | if (desc->fip_dtype < FIP_DT_VENDOR_BASE) |
| 1267 | return; |
| 1268 | break; |
| 1269 | } |
| 1270 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 1271 | rlen -= dlen; |
| 1272 | } |
| 1273 | |
| 1274 | /* |
| 1275 | * reset only if all required descriptors were present and valid. |
| 1276 | */ |
| 1277 | if (desc_mask) { |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1278 | LIBFCOE_FIP_DBG(fip, "missing descriptors mask %x\n", |
| 1279 | desc_mask); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1280 | } else { |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1281 | LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n"); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 1282 | |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1283 | if (is_vn_port) |
| 1284 | fc_lport_reset(vn_port); |
| 1285 | else { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1286 | mutex_lock(&fip->ctlr_mutex); |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1287 | per_cpu_ptr(lport->dev_stats, |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1288 | get_cpu())->VLinkFailureCount++; |
| 1289 | put_cpu(); |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1290 | fcoe_ctlr_reset(fip); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1291 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 1292 | |
Bhanu Prakash Gollapudi | 5550fda | 2010-06-11 16:44:31 -0700 | [diff] [blame] | 1293 | fc_lport_reset(fip->lp); |
| 1294 | fcoe_ctlr_solicit(fip, NULL); |
| 1295 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1300 | * fcoe_ctlr_recv() - Receive a FIP packet |
| 1301 | * @fip: The FCoE controller that received the packet |
| 1302 | * @skb: The received FIP packet |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1303 | * |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1304 | * This may be called from either NET_RX_SOFTIRQ or IRQ. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1305 | */ |
| 1306 | void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1307 | { |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1308 | skb_queue_tail(&fip->fip_recv_list, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1309 | schedule_work(&fip->recv_work); |
| 1310 | } |
| 1311 | EXPORT_SYMBOL(fcoe_ctlr_recv); |
| 1312 | |
| 1313 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1314 | * fcoe_ctlr_recv_handler() - Receive a FIP frame |
| 1315 | * @fip: The FCoE controller that received the frame |
| 1316 | * @skb: The received FIP frame |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1317 | * |
| 1318 | * Returns non-zero if the frame is dropped. |
| 1319 | */ |
| 1320 | static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 1321 | { |
| 1322 | struct fip_header *fiph; |
| 1323 | struct ethhdr *eh; |
| 1324 | enum fip_state state; |
| 1325 | u16 op; |
| 1326 | u8 sub; |
| 1327 | |
| 1328 | if (skb_linearize(skb)) |
| 1329 | goto drop; |
| 1330 | if (skb->len < sizeof(*fiph)) |
| 1331 | goto drop; |
| 1332 | eh = eth_hdr(skb); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1333 | if (fip->mode == FIP_MODE_VN2VN) { |
| 1334 | if (compare_ether_addr(eh->h_dest, fip->ctl_src_addr) && |
| 1335 | compare_ether_addr(eh->h_dest, fcoe_all_vn2vn) && |
| 1336 | compare_ether_addr(eh->h_dest, fcoe_all_p2p)) |
| 1337 | goto drop; |
| 1338 | } else if (compare_ether_addr(eh->h_dest, fip->ctl_src_addr) && |
| 1339 | compare_ether_addr(eh->h_dest, fcoe_all_enode)) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1340 | goto drop; |
| 1341 | fiph = (struct fip_header *)skb->data; |
| 1342 | op = ntohs(fiph->fip_op); |
| 1343 | sub = fiph->fip_subcode; |
| 1344 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1345 | if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER) |
| 1346 | goto drop; |
| 1347 | if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len) |
| 1348 | goto drop; |
| 1349 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1350 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1351 | state = fip->state; |
| 1352 | if (state == FIP_ST_AUTO) { |
| 1353 | fip->map_dest = 0; |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 1354 | fcoe_ctlr_set_state(fip, FIP_ST_ENABLED); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1355 | state = FIP_ST_ENABLED; |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1356 | LIBFCOE_FIP_DBG(fip, "Using FIP mode\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1357 | } |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1358 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1359 | |
| 1360 | if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN) |
| 1361 | return fcoe_ctlr_vn_recv(fip, skb); |
| 1362 | |
| 1363 | if (state != FIP_ST_ENABLED && state != FIP_ST_VNMP_UP && |
| 1364 | state != FIP_ST_VNMP_CLAIM) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1365 | goto drop; |
| 1366 | |
| 1367 | if (op == FIP_OP_LS) { |
| 1368 | fcoe_ctlr_recv_els(fip, skb); /* consumes skb */ |
| 1369 | return 0; |
| 1370 | } |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1371 | |
| 1372 | if (state != FIP_ST_ENABLED) |
| 1373 | goto drop; |
| 1374 | |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1375 | if (op == FIP_OP_DISC && sub == FIP_SC_ADV) |
| 1376 | fcoe_ctlr_recv_adv(fip, skb); |
| 1377 | else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK) |
| 1378 | fcoe_ctlr_recv_clr_vlink(fip, fiph); |
| 1379 | kfree_skb(skb); |
| 1380 | return 0; |
| 1381 | drop: |
| 1382 | kfree_skb(skb); |
| 1383 | return -1; |
| 1384 | } |
| 1385 | |
| 1386 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1387 | * fcoe_ctlr_select() - Select the best FCF (if possible) |
| 1388 | * @fip: The FCoE controller |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1389 | * |
| 1390 | * If there are conflicting advertisements, no FCF can be chosen. |
| 1391 | * |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1392 | * If there is already a selected FCF, this will choose a better one or |
| 1393 | * an equivalent one that hasn't already been sent a FLOGI. |
| 1394 | * |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1395 | * Called with lock held. |
| 1396 | */ |
| 1397 | static void fcoe_ctlr_select(struct fcoe_ctlr *fip) |
| 1398 | { |
| 1399 | struct fcoe_fcf *fcf; |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1400 | struct fcoe_fcf *best = fip->sel_fcf; |
Joe Eykholt | b69ae0a | 2010-11-30 16:19:51 -0800 | [diff] [blame] | 1401 | struct fcoe_fcf *first; |
| 1402 | |
| 1403 | first = list_first_entry(&fip->fcfs, struct fcoe_fcf, list); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1404 | |
| 1405 | list_for_each_entry(fcf, &fip->fcfs, list) { |
Joe Eykholt | 9069f5c | 2010-11-30 16:20:02 -0800 | [diff] [blame^] | 1406 | LIBFCOE_FIP_DBG(fip, "consider FCF fab %16.16llx " |
| 1407 | "VFID %d mac %pM map %x val %d " |
| 1408 | "sent %u pri %u\n", |
| 1409 | fcf->fabric_name, fcf->vfid, fcf->fcf_mac, |
| 1410 | fcf->fc_map, fcoe_ctlr_mtu_valid(fcf), |
| 1411 | fcf->flogi_sent, fcf->pri); |
Joe Eykholt | b69ae0a | 2010-11-30 16:19:51 -0800 | [diff] [blame] | 1412 | if (fcf->fabric_name != first->fabric_name || |
| 1413 | fcf->vfid != first->vfid || |
| 1414 | fcf->fc_map != first->fc_map) { |
| 1415 | LIBFCOE_FIP_DBG(fip, "Conflicting fabric, VFID, " |
| 1416 | "or FC-MAP\n"); |
| 1417 | return NULL; |
| 1418 | } |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1419 | if (fcf->flogi_sent) |
| 1420 | continue; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1421 | if (!fcoe_ctlr_fcf_usable(fcf)) { |
Chris Leech | 9f8f3aa | 2010-04-09 14:23:16 -0700 | [diff] [blame] | 1422 | LIBFCOE_FIP_DBG(fip, "FCF for fab %16.16llx " |
| 1423 | "map %x %svalid %savailable\n", |
| 1424 | fcf->fabric_name, fcf->fc_map, |
| 1425 | (fcf->flags & FIP_FL_SOL) ? "" : "in", |
| 1426 | (fcf->flags & FIP_FL_AVAIL) ? |
| 1427 | "" : "un"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1428 | continue; |
| 1429 | } |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1430 | if (!best || fcf->pri < best->pri || best->flogi_sent) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1431 | best = fcf; |
| 1432 | } |
| 1433 | fip->sel_fcf = best; |
Joe Eykholt | c47036a | 2010-11-30 16:19:46 -0800 | [diff] [blame] | 1434 | if (best) { |
Joe Eykholt | 9069f5c | 2010-11-30 16:20:02 -0800 | [diff] [blame^] | 1435 | LIBFCOE_FIP_DBG(fip, "using FCF mac %pM\n", best->fcf_mac); |
Joe Eykholt | c47036a | 2010-11-30 16:19:46 -0800 | [diff] [blame] | 1436 | fip->port_ka_time = jiffies + |
| 1437 | msecs_to_jiffies(FIP_VN_KA_PERIOD); |
| 1438 | fip->ctlr_ka_time = jiffies + best->fka_period; |
| 1439 | if (time_before(fip->ctlr_ka_time, fip->timer.expires)) |
| 1440 | mod_timer(&fip->timer, fip->ctlr_ka_time); |
| 1441 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | /** |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1445 | * fcoe_ctlr_flogi_send_locked() - send FIP-encapsulated FLOGI to current FCF |
| 1446 | * @fip: The FCoE controller |
| 1447 | * |
| 1448 | * Returns non-zero error if it could not be sent. |
| 1449 | * |
| 1450 | * Called with ctlr_mutex and ctlr_lock held. |
| 1451 | * Caller must verify that fip->sel_fcf is not NULL. |
| 1452 | */ |
| 1453 | static int fcoe_ctlr_flogi_send_locked(struct fcoe_ctlr *fip) |
| 1454 | { |
| 1455 | struct sk_buff *skb; |
| 1456 | struct sk_buff *skb_orig; |
| 1457 | struct fc_frame_header *fh; |
| 1458 | int error; |
| 1459 | |
| 1460 | skb_orig = fip->flogi_req; |
| 1461 | if (!skb_orig) |
| 1462 | return -EINVAL; |
| 1463 | |
| 1464 | /* |
| 1465 | * Clone and send the FLOGI request. If clone fails, use original. |
| 1466 | */ |
| 1467 | skb = skb_clone(skb_orig, GFP_ATOMIC); |
| 1468 | if (!skb) { |
| 1469 | skb = skb_orig; |
| 1470 | fip->flogi_req = NULL; |
| 1471 | } |
| 1472 | fh = (struct fc_frame_header *)skb->data; |
| 1473 | error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb, |
| 1474 | ntoh24(fh->fh_d_id)); |
| 1475 | if (error) { |
| 1476 | kfree_skb(skb); |
| 1477 | return error; |
| 1478 | } |
| 1479 | fip->send(fip, skb); |
| 1480 | fip->sel_fcf->flogi_sent = 1; |
| 1481 | return 0; |
| 1482 | } |
| 1483 | |
| 1484 | /** |
| 1485 | * fcoe_ctlr_flogi_retry() - resend FLOGI request to a new FCF if possible |
| 1486 | * @fip: The FCoE controller |
| 1487 | * |
| 1488 | * Returns non-zero error code if there's no FLOGI request to retry or |
| 1489 | * no alternate FCF available. |
| 1490 | */ |
| 1491 | static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *fip) |
| 1492 | { |
| 1493 | struct fcoe_fcf *fcf; |
| 1494 | int error; |
| 1495 | |
| 1496 | mutex_lock(&fip->ctlr_mutex); |
| 1497 | spin_lock_bh(&fip->ctlr_lock); |
| 1498 | LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n"); |
| 1499 | fcoe_ctlr_select(fip); |
| 1500 | fcf = fip->sel_fcf; |
| 1501 | if (!fcf || fcf->flogi_sent) { |
| 1502 | kfree_skb(fip->flogi_req); |
| 1503 | fip->flogi_req = NULL; |
| 1504 | error = -ENOENT; |
| 1505 | } else { |
| 1506 | fcoe_ctlr_solicit(fip, NULL); |
| 1507 | error = fcoe_ctlr_flogi_send_locked(fip); |
| 1508 | } |
| 1509 | spin_unlock_bh(&fip->ctlr_lock); |
| 1510 | mutex_unlock(&fip->ctlr_mutex); |
| 1511 | return error; |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | /** |
| 1516 | * fcoe_ctlr_flogi_send() - Handle sending of FIP FLOGI. |
| 1517 | * @fip: The FCoE controller that timed out |
| 1518 | * |
| 1519 | * Done here because fcoe_ctlr_els_send() can't get mutex. |
| 1520 | * |
| 1521 | * Called with ctlr_mutex held. The caller must not hold ctlr_lock. |
| 1522 | */ |
| 1523 | static void fcoe_ctlr_flogi_send(struct fcoe_ctlr *fip) |
| 1524 | { |
| 1525 | struct fcoe_fcf *fcf; |
| 1526 | |
| 1527 | spin_lock_bh(&fip->ctlr_lock); |
| 1528 | fcf = fip->sel_fcf; |
| 1529 | if (!fcf || !fip->flogi_req_send) |
| 1530 | goto unlock; |
| 1531 | |
| 1532 | LIBFCOE_FIP_DBG(fip, "sending FLOGI\n"); |
| 1533 | |
| 1534 | /* |
| 1535 | * If this FLOGI is being sent due to a timeout retry |
| 1536 | * to the same FCF as before, select a different FCF if possible. |
| 1537 | */ |
| 1538 | if (fcf->flogi_sent) { |
| 1539 | LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n"); |
| 1540 | fcoe_ctlr_select(fip); |
| 1541 | fcf = fip->sel_fcf; |
| 1542 | if (!fcf || fcf->flogi_sent) { |
| 1543 | LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n"); |
| 1544 | list_for_each_entry(fcf, &fip->fcfs, list) |
| 1545 | fcf->flogi_sent = 0; |
| 1546 | fcoe_ctlr_select(fip); |
| 1547 | fcf = fip->sel_fcf; |
| 1548 | } |
| 1549 | } |
| 1550 | if (fcf) { |
| 1551 | fcoe_ctlr_flogi_send_locked(fip); |
| 1552 | fip->flogi_req_send = 0; |
| 1553 | } else /* XXX */ |
| 1554 | LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n"); |
| 1555 | unlock: |
| 1556 | spin_unlock_bh(&fip->ctlr_lock); |
| 1557 | } |
| 1558 | |
| 1559 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1560 | * fcoe_ctlr_timeout() - FIP timeout handler |
| 1561 | * @arg: The FCoE controller that timed out |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1562 | */ |
| 1563 | static void fcoe_ctlr_timeout(unsigned long arg) |
| 1564 | { |
| 1565 | struct fcoe_ctlr *fip = (struct fcoe_ctlr *)arg; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1566 | |
| 1567 | schedule_work(&fip->timer_work); |
| 1568 | } |
| 1569 | |
| 1570 | /** |
| 1571 | * fcoe_ctlr_timer_work() - Worker thread function for timer work |
| 1572 | * @work: Handle to a FCoE controller |
| 1573 | * |
| 1574 | * Ages FCFs. Triggers FCF selection if possible. |
| 1575 | * Sends keep-alives and resets. |
| 1576 | */ |
| 1577 | static void fcoe_ctlr_timer_work(struct work_struct *work) |
| 1578 | { |
| 1579 | struct fcoe_ctlr *fip; |
| 1580 | struct fc_lport *vport; |
| 1581 | u8 *mac; |
| 1582 | u8 reset = 0; |
| 1583 | u8 send_ctlr_ka = 0; |
| 1584 | u8 send_port_ka = 0; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1585 | struct fcoe_fcf *sel; |
| 1586 | struct fcoe_fcf *fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1587 | unsigned long next_timer; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1588 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1589 | fip = container_of(work, struct fcoe_ctlr, timer_work); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1590 | if (fip->mode == FIP_MODE_VN2VN) |
| 1591 | return fcoe_ctlr_vn_timeout(fip); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1592 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1593 | if (fip->state == FIP_ST_DISABLED) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1594 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1595 | return; |
| 1596 | } |
| 1597 | |
| 1598 | fcf = fip->sel_fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1599 | next_timer = fcoe_ctlr_age_fcfs(fip); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1600 | |
| 1601 | sel = fip->sel_fcf; |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1602 | if (!sel && fip->sel_time) { |
| 1603 | if (time_after_eq(jiffies, fip->sel_time)) { |
| 1604 | fcoe_ctlr_select(fip); |
| 1605 | sel = fip->sel_fcf; |
| 1606 | fip->sel_time = 0; |
| 1607 | } else if (time_after(next_timer, fip->sel_time)) |
| 1608 | next_timer = fip->sel_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1609 | } |
| 1610 | |
Joe Eykholt | 794d98e | 2010-11-30 16:19:56 -0800 | [diff] [blame] | 1611 | if (sel && fip->flogi_req_send) |
| 1612 | fcoe_ctlr_flogi_send(fip); |
| 1613 | else if (!sel && fcf) |
| 1614 | reset = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1615 | |
Yi Zou | 8cdffdc | 2009-11-20 14:54:57 -0800 | [diff] [blame] | 1616 | if (sel && !sel->fd_flags) { |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1617 | if (time_after_eq(jiffies, fip->ctlr_ka_time)) { |
| 1618 | fip->ctlr_ka_time = jiffies + sel->fka_period; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1619 | send_ctlr_ka = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1620 | } |
| 1621 | if (time_after(next_timer, fip->ctlr_ka_time)) |
| 1622 | next_timer = fip->ctlr_ka_time; |
| 1623 | |
| 1624 | if (time_after_eq(jiffies, fip->port_ka_time)) { |
Bhanu Prakash Gollapudi | f47dd85 | 2010-01-21 10:16:00 -0800 | [diff] [blame] | 1625 | fip->port_ka_time = jiffies + |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1626 | msecs_to_jiffies(FIP_VN_KA_PERIOD); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1627 | send_port_ka = 1; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1628 | } |
| 1629 | if (time_after(next_timer, fip->port_ka_time)) |
| 1630 | next_timer = fip->port_ka_time; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1631 | } |
Joe Eykholt | 8690cb8 | 2010-06-11 16:44:10 -0700 | [diff] [blame] | 1632 | if (!list_empty(&fip->fcfs)) |
| 1633 | mod_timer(&fip->timer, next_timer); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1634 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1635 | |
Bhanu Prakash Gollapudi | 516a648 | 2010-06-11 16:43:44 -0700 | [diff] [blame] | 1636 | if (reset) { |
Joe Eykholt | dd42dac | 2009-11-03 11:48:27 -0800 | [diff] [blame] | 1637 | fc_lport_reset(fip->lp); |
Bhanu Prakash Gollapudi | 516a648 | 2010-06-11 16:43:44 -0700 | [diff] [blame] | 1638 | /* restart things with a solicitation */ |
| 1639 | fcoe_ctlr_solicit(fip, NULL); |
| 1640 | } |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1641 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1642 | if (send_ctlr_ka) |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1643 | fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr); |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1644 | |
| 1645 | if (send_port_ka) { |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1646 | mutex_lock(&fip->lp->lp_mutex); |
| 1647 | mac = fip->get_src_addr(fip->lp); |
| 1648 | fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac); |
| 1649 | list_for_each_entry(vport, &fip->lp->vports, list) { |
| 1650 | mac = fip->get_src_addr(vport); |
| 1651 | fcoe_ctlr_send_keep_alive(fip, vport, 1, mac); |
| 1652 | } |
| 1653 | mutex_unlock(&fip->lp->lp_mutex); |
| 1654 | } |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1658 | * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames |
| 1659 | * @recv_work: Handle to a FCoE controller |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1660 | */ |
| 1661 | static void fcoe_ctlr_recv_work(struct work_struct *recv_work) |
| 1662 | { |
| 1663 | struct fcoe_ctlr *fip; |
| 1664 | struct sk_buff *skb; |
| 1665 | |
| 1666 | fip = container_of(recv_work, struct fcoe_ctlr, recv_work); |
Joe Eykholt | 1f4aed8 | 2009-11-03 11:48:22 -0800 | [diff] [blame] | 1667 | while ((skb = skb_dequeue(&fip->fip_recv_list))) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1668 | fcoe_ctlr_recv_handler(fip, skb); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
| 1671 | /** |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1672 | * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1673 | * @fip: The FCoE controller |
| 1674 | * @fp: The FC frame to snoop |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1675 | * |
| 1676 | * Snoop potential response to FLOGI or even incoming FLOGI. |
| 1677 | * |
| 1678 | * The caller has checked that we are waiting for login as indicated |
| 1679 | * by fip->flogi_oxid != FC_XID_UNKNOWN. |
| 1680 | * |
| 1681 | * The caller is responsible for freeing the frame. |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1682 | * Fill in the granted_mac address. |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1683 | * |
| 1684 | * Return non-zero if the frame should not be delivered to libfc. |
| 1685 | */ |
Chris Leech | 11b5618 | 2009-11-03 11:46:29 -0800 | [diff] [blame] | 1686 | int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport, |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1687 | struct fc_frame *fp) |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1688 | { |
| 1689 | struct fc_frame_header *fh; |
| 1690 | u8 op; |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1691 | u8 *sa; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1692 | |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1693 | sa = eth_hdr(&fp->skb)->h_source; |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1694 | fh = fc_frame_header_get(fp); |
| 1695 | if (fh->fh_type != FC_TYPE_ELS) |
| 1696 | return 0; |
| 1697 | |
| 1698 | op = fc_frame_payload_op(fp); |
| 1699 | if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP && |
| 1700 | fip->flogi_oxid == ntohs(fh->fh_ox_id)) { |
| 1701 | |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1702 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1703 | if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) { |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1704 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1705 | return -EINVAL; |
| 1706 | } |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 1707 | fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP); |
Joe Eykholt | 0f51c2e | 2009-11-03 11:48:16 -0800 | [diff] [blame] | 1708 | LIBFCOE_FIP_DBG(fip, |
| 1709 | "received FLOGI LS_ACC using non-FIP mode\n"); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1710 | |
| 1711 | /* |
| 1712 | * FLOGI accepted. |
| 1713 | * If the src mac addr is FC_OUI-based, then we mark the |
| 1714 | * address_mode flag to use FC_OUI-based Ethernet DA. |
| 1715 | * Otherwise we use the FCoE gateway addr |
| 1716 | */ |
| 1717 | if (!compare_ether_addr(sa, (u8[6])FC_FCOE_FLOGI_MAC)) { |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 1718 | fcoe_ctlr_map_dest(fip); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1719 | } else { |
| 1720 | memcpy(fip->dest_addr, sa, ETH_ALEN); |
| 1721 | fip->map_dest = 0; |
| 1722 | } |
| 1723 | fip->flogi_oxid = FC_XID_UNKNOWN; |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1724 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 386309c | 2009-11-03 11:49:16 -0800 | [diff] [blame] | 1725 | 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] | 1726 | } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) { |
| 1727 | /* |
| 1728 | * Save source MAC for point-to-point responses. |
| 1729 | */ |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1730 | mutex_lock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1731 | if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) { |
| 1732 | memcpy(fip->dest_addr, sa, ETH_ALEN); |
| 1733 | fip->map_dest = 0; |
Joe Eykholt | e49bf61 | 2010-03-12 16:07:57 -0800 | [diff] [blame] | 1734 | if (fip->state == FIP_ST_AUTO) |
| 1735 | LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. " |
| 1736 | "Setting non-FIP mode\n"); |
Joe Eykholt | 9b651da | 2010-07-20 15:20:24 -0700 | [diff] [blame] | 1737 | fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1738 | } |
Joe Eykholt | fdb068c | 2010-07-20 15:19:47 -0700 | [diff] [blame] | 1739 | mutex_unlock(&fip->ctlr_mutex); |
Joe Eykholt | 97c8389 | 2009-03-17 11:42:40 -0700 | [diff] [blame] | 1740 | } |
| 1741 | return 0; |
| 1742 | } |
| 1743 | EXPORT_SYMBOL(fcoe_ctlr_recv_flogi); |
| 1744 | |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1745 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 1746 | * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN |
| 1747 | * @mac: The MAC address to convert |
| 1748 | * @scheme: The scheme to use when converting |
| 1749 | * @port: The port indicator for converting |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 1750 | * |
| 1751 | * Returns: u64 fc world wide name |
| 1752 | */ |
| 1753 | u64 fcoe_wwn_from_mac(unsigned char mac[MAX_ADDR_LEN], |
| 1754 | unsigned int scheme, unsigned int port) |
| 1755 | { |
| 1756 | u64 wwn; |
| 1757 | u64 host_mac; |
| 1758 | |
| 1759 | /* The MAC is in NO, so flip only the low 48 bits */ |
| 1760 | host_mac = ((u64) mac[0] << 40) | |
| 1761 | ((u64) mac[1] << 32) | |
| 1762 | ((u64) mac[2] << 24) | |
| 1763 | ((u64) mac[3] << 16) | |
| 1764 | ((u64) mac[4] << 8) | |
| 1765 | (u64) mac[5]; |
| 1766 | |
| 1767 | WARN_ON(host_mac >= (1ULL << 48)); |
| 1768 | wwn = host_mac | ((u64) scheme << 60); |
| 1769 | switch (scheme) { |
| 1770 | case 1: |
| 1771 | WARN_ON(port != 0); |
| 1772 | break; |
| 1773 | case 2: |
| 1774 | WARN_ON(port >= 0xfff); |
| 1775 | wwn |= (u64) port << 48; |
| 1776 | break; |
| 1777 | default: |
| 1778 | WARN_ON(1); |
| 1779 | break; |
| 1780 | } |
| 1781 | |
| 1782 | return wwn; |
| 1783 | } |
| 1784 | EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac); |
| 1785 | |
| 1786 | /** |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 1787 | * fcoe_ctlr_rport() - return the fcoe_rport for a given fc_rport_priv |
| 1788 | * @rdata: libfc remote port |
| 1789 | */ |
| 1790 | static inline struct fcoe_rport *fcoe_ctlr_rport(struct fc_rport_priv *rdata) |
| 1791 | { |
| 1792 | return (struct fcoe_rport *)(rdata + 1); |
| 1793 | } |
| 1794 | |
| 1795 | /** |
| 1796 | * fcoe_ctlr_vn_send() - Send a FIP VN2VN Probe Request or Reply. |
| 1797 | * @fip: The FCoE controller |
| 1798 | * @sub: sub-opcode for probe request, reply, or advertisement. |
| 1799 | * @dest: The destination Ethernet MAC address |
| 1800 | * @min_len: minimum size of the Ethernet payload to be sent |
| 1801 | */ |
| 1802 | static void fcoe_ctlr_vn_send(struct fcoe_ctlr *fip, |
| 1803 | enum fip_vn2vn_subcode sub, |
| 1804 | const u8 *dest, size_t min_len) |
| 1805 | { |
| 1806 | struct sk_buff *skb; |
| 1807 | struct fip_frame { |
| 1808 | struct ethhdr eth; |
| 1809 | struct fip_header fip; |
| 1810 | struct fip_mac_desc mac; |
| 1811 | struct fip_wwn_desc wwnn; |
| 1812 | struct fip_vn_desc vn; |
| 1813 | } __attribute__((packed)) *frame; |
| 1814 | struct fip_fc4_feat *ff; |
| 1815 | struct fip_size_desc *size; |
| 1816 | u32 fcp_feat; |
| 1817 | size_t len; |
| 1818 | size_t dlen; |
| 1819 | |
| 1820 | len = sizeof(*frame); |
| 1821 | dlen = 0; |
| 1822 | if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { |
| 1823 | dlen = sizeof(struct fip_fc4_feat) + |
| 1824 | sizeof(struct fip_size_desc); |
| 1825 | len += dlen; |
| 1826 | } |
| 1827 | dlen += sizeof(frame->mac) + sizeof(frame->wwnn) + sizeof(frame->vn); |
| 1828 | len = max(len, min_len + sizeof(struct ethhdr)); |
| 1829 | |
| 1830 | skb = dev_alloc_skb(len); |
| 1831 | if (!skb) |
| 1832 | return; |
| 1833 | |
| 1834 | frame = (struct fip_frame *)skb->data; |
| 1835 | memset(frame, 0, len); |
| 1836 | memcpy(frame->eth.h_dest, dest, ETH_ALEN); |
| 1837 | memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN); |
| 1838 | frame->eth.h_proto = htons(ETH_P_FIP); |
| 1839 | |
| 1840 | frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER); |
| 1841 | frame->fip.fip_op = htons(FIP_OP_VN2VN); |
| 1842 | frame->fip.fip_subcode = sub; |
| 1843 | frame->fip.fip_dl_len = htons(dlen / FIP_BPW); |
| 1844 | |
| 1845 | frame->mac.fd_desc.fip_dtype = FIP_DT_MAC; |
| 1846 | frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW; |
| 1847 | memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN); |
| 1848 | |
| 1849 | frame->wwnn.fd_desc.fip_dtype = FIP_DT_NAME; |
| 1850 | frame->wwnn.fd_desc.fip_dlen = sizeof(frame->wwnn) / FIP_BPW; |
| 1851 | put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn); |
| 1852 | |
| 1853 | frame->vn.fd_desc.fip_dtype = FIP_DT_VN_ID; |
| 1854 | frame->vn.fd_desc.fip_dlen = sizeof(frame->vn) / FIP_BPW; |
| 1855 | hton24(frame->vn.fd_mac, FIP_VN_FC_MAP); |
| 1856 | hton24(frame->vn.fd_mac + 3, fip->port_id); |
| 1857 | hton24(frame->vn.fd_fc_id, fip->port_id); |
| 1858 | put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn); |
| 1859 | |
| 1860 | /* |
| 1861 | * For claims, add FC-4 features. |
| 1862 | * TBD: Add interface to get fc-4 types and features from libfc. |
| 1863 | */ |
| 1864 | if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) { |
| 1865 | ff = (struct fip_fc4_feat *)(frame + 1); |
| 1866 | ff->fd_desc.fip_dtype = FIP_DT_FC4F; |
| 1867 | ff->fd_desc.fip_dlen = sizeof(*ff) / FIP_BPW; |
| 1868 | ff->fd_fts = fip->lp->fcts; |
| 1869 | |
| 1870 | fcp_feat = 0; |
| 1871 | if (fip->lp->service_params & FCP_SPPF_INIT_FCN) |
| 1872 | fcp_feat |= FCP_FEAT_INIT; |
| 1873 | if (fip->lp->service_params & FCP_SPPF_TARG_FCN) |
| 1874 | fcp_feat |= FCP_FEAT_TARG; |
| 1875 | fcp_feat <<= (FC_TYPE_FCP * 4) % 32; |
| 1876 | ff->fd_ff.fd_feat[FC_TYPE_FCP * 4 / 32] = htonl(fcp_feat); |
| 1877 | |
| 1878 | size = (struct fip_size_desc *)(ff + 1); |
| 1879 | size->fd_desc.fip_dtype = FIP_DT_FCOE_SIZE; |
| 1880 | size->fd_desc.fip_dlen = sizeof(*size) / FIP_BPW; |
| 1881 | size->fd_size = htons(fcoe_ctlr_fcoe_size(fip)); |
| 1882 | } |
| 1883 | |
| 1884 | skb_put(skb, len); |
| 1885 | skb->protocol = htons(ETH_P_FIP); |
| 1886 | skb_reset_mac_header(skb); |
| 1887 | skb_reset_network_header(skb); |
| 1888 | |
| 1889 | fip->send(fip, skb); |
| 1890 | } |
| 1891 | |
| 1892 | /** |
| 1893 | * fcoe_ctlr_vn_rport_callback - Event handler for rport events. |
| 1894 | * @lport: The lport which is receiving the event |
| 1895 | * @rdata: remote port private data |
| 1896 | * @event: The event that occured |
| 1897 | * |
| 1898 | * Locking Note: The rport lock must not be held when calling this function. |
| 1899 | */ |
| 1900 | static void fcoe_ctlr_vn_rport_callback(struct fc_lport *lport, |
| 1901 | struct fc_rport_priv *rdata, |
| 1902 | enum fc_rport_event event) |
| 1903 | { |
| 1904 | struct fcoe_ctlr *fip = lport->disc.priv; |
| 1905 | struct fcoe_rport *frport = fcoe_ctlr_rport(rdata); |
| 1906 | |
| 1907 | LIBFCOE_FIP_DBG(fip, "vn_rport_callback %x event %d\n", |
| 1908 | rdata->ids.port_id, event); |
| 1909 | |
| 1910 | mutex_lock(&fip->ctlr_mutex); |
| 1911 | switch (event) { |
| 1912 | case RPORT_EV_READY: |
| 1913 | frport->login_count = 0; |
| 1914 | break; |
| 1915 | case RPORT_EV_LOGO: |
| 1916 | case RPORT_EV_FAILED: |
| 1917 | case RPORT_EV_STOP: |
| 1918 | frport->login_count++; |
| 1919 | if (frport->login_count > FCOE_CTLR_VN2VN_LOGIN_LIMIT) { |
| 1920 | LIBFCOE_FIP_DBG(fip, |
| 1921 | "rport FLOGI limited port_id %6.6x\n", |
| 1922 | rdata->ids.port_id); |
| 1923 | lport->tt.rport_logoff(rdata); |
| 1924 | } |
| 1925 | break; |
| 1926 | default: |
| 1927 | break; |
| 1928 | } |
| 1929 | mutex_unlock(&fip->ctlr_mutex); |
| 1930 | } |
| 1931 | |
| 1932 | static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = { |
| 1933 | .event_callback = fcoe_ctlr_vn_rport_callback, |
| 1934 | }; |
| 1935 | |
| 1936 | /** |
| 1937 | * fcoe_ctlr_disc_stop_locked() - stop discovery in VN2VN mode |
| 1938 | * @fip: The FCoE controller |
| 1939 | * |
| 1940 | * Called with ctlr_mutex held. |
| 1941 | */ |
| 1942 | static void fcoe_ctlr_disc_stop_locked(struct fc_lport *lport) |
| 1943 | { |
| 1944 | mutex_lock(&lport->disc.disc_mutex); |
| 1945 | lport->disc.disc_callback = NULL; |
| 1946 | mutex_unlock(&lport->disc.disc_mutex); |
| 1947 | } |
| 1948 | |
| 1949 | /** |
| 1950 | * fcoe_ctlr_disc_stop() - stop discovery in VN2VN mode |
| 1951 | * @fip: The FCoE controller |
| 1952 | * |
| 1953 | * Called through the local port template for discovery. |
| 1954 | * Called without the ctlr_mutex held. |
| 1955 | */ |
| 1956 | static void fcoe_ctlr_disc_stop(struct fc_lport *lport) |
| 1957 | { |
| 1958 | struct fcoe_ctlr *fip = lport->disc.priv; |
| 1959 | |
| 1960 | mutex_lock(&fip->ctlr_mutex); |
| 1961 | fcoe_ctlr_disc_stop_locked(lport); |
| 1962 | mutex_unlock(&fip->ctlr_mutex); |
| 1963 | } |
| 1964 | |
| 1965 | /** |
| 1966 | * fcoe_ctlr_disc_stop_final() - stop discovery for shutdown in VN2VN mode |
| 1967 | * @fip: The FCoE controller |
| 1968 | * |
| 1969 | * Called through the local port template for discovery. |
| 1970 | * Called without the ctlr_mutex held. |
| 1971 | */ |
| 1972 | static void fcoe_ctlr_disc_stop_final(struct fc_lport *lport) |
| 1973 | { |
| 1974 | fcoe_ctlr_disc_stop(lport); |
| 1975 | lport->tt.rport_flush_queue(); |
| 1976 | synchronize_rcu(); |
| 1977 | } |
| 1978 | |
| 1979 | /** |
| 1980 | * fcoe_ctlr_vn_restart() - VN2VN probe restart with new port_id |
| 1981 | * @fip: The FCoE controller |
| 1982 | * |
| 1983 | * Called with fcoe_ctlr lock held. |
| 1984 | */ |
| 1985 | static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip) |
| 1986 | { |
| 1987 | unsigned long wait; |
| 1988 | u32 port_id; |
| 1989 | |
| 1990 | fcoe_ctlr_disc_stop_locked(fip->lp); |
| 1991 | |
| 1992 | /* |
| 1993 | * Get proposed port ID. |
| 1994 | * If this is the first try after link up, use any previous port_id. |
| 1995 | * If there was none, use the low bits of the port_name. |
| 1996 | * On subsequent tries, get the next random one. |
| 1997 | * Don't use reserved IDs, use another non-zero value, just as random. |
| 1998 | */ |
| 1999 | port_id = fip->port_id; |
| 2000 | if (fip->probe_tries) |
| 2001 | port_id = prandom32(&fip->rnd_state) & 0xffff; |
| 2002 | else if (!port_id) |
| 2003 | port_id = fip->lp->wwpn & 0xffff; |
| 2004 | if (!port_id || port_id == 0xffff) |
| 2005 | port_id = 1; |
| 2006 | fip->port_id = port_id; |
| 2007 | |
| 2008 | if (fip->probe_tries < FIP_VN_RLIM_COUNT) { |
| 2009 | fip->probe_tries++; |
| 2010 | wait = random32() % FIP_VN_PROBE_WAIT; |
| 2011 | } else |
| 2012 | wait = FIP_VN_RLIM_INT; |
| 2013 | mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait)); |
| 2014 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_START); |
| 2015 | } |
| 2016 | |
| 2017 | /** |
| 2018 | * fcoe_ctlr_vn_start() - Start in VN2VN mode |
| 2019 | * @fip: The FCoE controller |
| 2020 | * |
| 2021 | * Called with fcoe_ctlr lock held. |
| 2022 | */ |
| 2023 | static void fcoe_ctlr_vn_start(struct fcoe_ctlr *fip) |
| 2024 | { |
| 2025 | fip->probe_tries = 0; |
| 2026 | prandom32_seed(&fip->rnd_state, fip->lp->wwpn); |
| 2027 | fcoe_ctlr_vn_restart(fip); |
| 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * fcoe_ctlr_vn_parse - parse probe request or response |
| 2032 | * @fip: The FCoE controller |
| 2033 | * @skb: incoming packet |
| 2034 | * @rdata: buffer for resulting parsed VN entry plus fcoe_rport |
| 2035 | * |
| 2036 | * Returns non-zero error number on error. |
| 2037 | * Does not consume the packet. |
| 2038 | */ |
| 2039 | static int fcoe_ctlr_vn_parse(struct fcoe_ctlr *fip, |
| 2040 | struct sk_buff *skb, |
| 2041 | struct fc_rport_priv *rdata) |
| 2042 | { |
| 2043 | struct fip_header *fiph; |
| 2044 | struct fip_desc *desc = NULL; |
| 2045 | struct fip_mac_desc *macd = NULL; |
| 2046 | struct fip_wwn_desc *wwn = NULL; |
| 2047 | struct fip_vn_desc *vn = NULL; |
| 2048 | struct fip_size_desc *size = NULL; |
| 2049 | struct fcoe_rport *frport; |
| 2050 | size_t rlen; |
| 2051 | size_t dlen; |
| 2052 | u32 desc_mask = 0; |
| 2053 | u32 dtype; |
| 2054 | u8 sub; |
| 2055 | |
| 2056 | memset(rdata, 0, sizeof(*rdata) + sizeof(*frport)); |
| 2057 | frport = fcoe_ctlr_rport(rdata); |
| 2058 | |
| 2059 | fiph = (struct fip_header *)skb->data; |
| 2060 | frport->flags = ntohs(fiph->fip_flags); |
| 2061 | |
| 2062 | sub = fiph->fip_subcode; |
| 2063 | switch (sub) { |
| 2064 | case FIP_SC_VN_PROBE_REQ: |
| 2065 | case FIP_SC_VN_PROBE_REP: |
| 2066 | case FIP_SC_VN_BEACON: |
| 2067 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | |
| 2068 | BIT(FIP_DT_VN_ID); |
| 2069 | break; |
| 2070 | case FIP_SC_VN_CLAIM_NOTIFY: |
| 2071 | case FIP_SC_VN_CLAIM_REP: |
| 2072 | desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | |
| 2073 | BIT(FIP_DT_VN_ID) | BIT(FIP_DT_FC4F) | |
| 2074 | BIT(FIP_DT_FCOE_SIZE); |
| 2075 | break; |
| 2076 | default: |
| 2077 | LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub); |
| 2078 | return -EINVAL; |
| 2079 | } |
| 2080 | |
| 2081 | rlen = ntohs(fiph->fip_dl_len) * 4; |
| 2082 | if (rlen + sizeof(*fiph) > skb->len) |
| 2083 | return -EINVAL; |
| 2084 | |
| 2085 | desc = (struct fip_desc *)(fiph + 1); |
| 2086 | while (rlen > 0) { |
| 2087 | dlen = desc->fip_dlen * FIP_BPW; |
| 2088 | if (dlen < sizeof(*desc) || dlen > rlen) |
| 2089 | return -EINVAL; |
| 2090 | |
| 2091 | dtype = desc->fip_dtype; |
| 2092 | if (dtype < 32) { |
| 2093 | if (!(desc_mask & BIT(dtype))) { |
| 2094 | LIBFCOE_FIP_DBG(fip, |
| 2095 | "unexpected or duplicated desc " |
| 2096 | "desc type %u in " |
| 2097 | "FIP VN2VN subtype %u\n", |
| 2098 | dtype, sub); |
| 2099 | return -EINVAL; |
| 2100 | } |
| 2101 | desc_mask &= ~BIT(dtype); |
| 2102 | } |
| 2103 | |
| 2104 | switch (dtype) { |
| 2105 | case FIP_DT_MAC: |
| 2106 | if (dlen != sizeof(struct fip_mac_desc)) |
| 2107 | goto len_err; |
| 2108 | macd = (struct fip_mac_desc *)desc; |
| 2109 | if (!is_valid_ether_addr(macd->fd_mac)) { |
| 2110 | LIBFCOE_FIP_DBG(fip, |
| 2111 | "Invalid MAC addr %pM in FIP VN2VN\n", |
| 2112 | macd->fd_mac); |
| 2113 | return -EINVAL; |
| 2114 | } |
| 2115 | memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN); |
| 2116 | break; |
| 2117 | case FIP_DT_NAME: |
| 2118 | if (dlen != sizeof(struct fip_wwn_desc)) |
| 2119 | goto len_err; |
| 2120 | wwn = (struct fip_wwn_desc *)desc; |
| 2121 | rdata->ids.node_name = get_unaligned_be64(&wwn->fd_wwn); |
| 2122 | break; |
| 2123 | case FIP_DT_VN_ID: |
| 2124 | if (dlen != sizeof(struct fip_vn_desc)) |
| 2125 | goto len_err; |
| 2126 | vn = (struct fip_vn_desc *)desc; |
| 2127 | memcpy(frport->vn_mac, vn->fd_mac, ETH_ALEN); |
| 2128 | rdata->ids.port_id = ntoh24(vn->fd_fc_id); |
| 2129 | rdata->ids.port_name = get_unaligned_be64(&vn->fd_wwpn); |
| 2130 | break; |
| 2131 | case FIP_DT_FC4F: |
| 2132 | if (dlen != sizeof(struct fip_fc4_feat)) |
| 2133 | goto len_err; |
| 2134 | break; |
| 2135 | case FIP_DT_FCOE_SIZE: |
| 2136 | if (dlen != sizeof(struct fip_size_desc)) |
| 2137 | goto len_err; |
| 2138 | size = (struct fip_size_desc *)desc; |
| 2139 | frport->fcoe_len = ntohs(size->fd_size); |
| 2140 | break; |
| 2141 | default: |
| 2142 | LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x " |
| 2143 | "in FIP probe\n", dtype); |
| 2144 | /* standard says ignore unknown descriptors >= 128 */ |
| 2145 | if (dtype < FIP_DT_VENDOR_BASE) |
| 2146 | return -EINVAL; |
| 2147 | break; |
| 2148 | } |
| 2149 | desc = (struct fip_desc *)((char *)desc + dlen); |
| 2150 | rlen -= dlen; |
| 2151 | } |
| 2152 | return 0; |
| 2153 | |
| 2154 | len_err: |
| 2155 | LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n", |
| 2156 | dtype, dlen); |
| 2157 | return -EINVAL; |
| 2158 | } |
| 2159 | |
| 2160 | /** |
| 2161 | * fcoe_ctlr_vn_send_claim() - send multicast FIP VN2VN Claim Notification. |
| 2162 | * @fip: The FCoE controller |
| 2163 | * |
| 2164 | * Called with ctlr_mutex held. |
| 2165 | */ |
| 2166 | static void fcoe_ctlr_vn_send_claim(struct fcoe_ctlr *fip) |
| 2167 | { |
| 2168 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_NOTIFY, fcoe_all_vn2vn, 0); |
| 2169 | fip->sol_time = jiffies; |
| 2170 | } |
| 2171 | |
| 2172 | /** |
| 2173 | * fcoe_ctlr_vn_probe_req() - handle incoming VN2VN probe request. |
| 2174 | * @fip: The FCoE controller |
| 2175 | * @rdata: parsed remote port with frport from the probe request |
| 2176 | * |
| 2177 | * Called with ctlr_mutex held. |
| 2178 | */ |
| 2179 | static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr *fip, |
| 2180 | struct fc_rport_priv *rdata) |
| 2181 | { |
| 2182 | struct fcoe_rport *frport = fcoe_ctlr_rport(rdata); |
| 2183 | |
| 2184 | if (rdata->ids.port_id != fip->port_id) |
| 2185 | return; |
| 2186 | |
| 2187 | switch (fip->state) { |
| 2188 | case FIP_ST_VNMP_CLAIM: |
| 2189 | case FIP_ST_VNMP_UP: |
| 2190 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP, |
| 2191 | frport->enode_mac, 0); |
| 2192 | break; |
| 2193 | case FIP_ST_VNMP_PROBE1: |
| 2194 | case FIP_ST_VNMP_PROBE2: |
| 2195 | /* |
| 2196 | * Decide whether to reply to the Probe. |
| 2197 | * Our selected address is never a "recorded" one, so |
| 2198 | * only reply if our WWPN is greater and the |
| 2199 | * Probe's REC bit is not set. |
| 2200 | * If we don't reply, we will change our address. |
| 2201 | */ |
| 2202 | if (fip->lp->wwpn > rdata->ids.port_name && |
| 2203 | !(frport->flags & FIP_FL_REC_OR_P2P)) { |
| 2204 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP, |
| 2205 | frport->enode_mac, 0); |
| 2206 | break; |
| 2207 | } |
| 2208 | /* fall through */ |
| 2209 | case FIP_ST_VNMP_START: |
| 2210 | fcoe_ctlr_vn_restart(fip); |
| 2211 | break; |
| 2212 | default: |
| 2213 | break; |
| 2214 | } |
| 2215 | } |
| 2216 | |
| 2217 | /** |
| 2218 | * fcoe_ctlr_vn_probe_reply() - handle incoming VN2VN probe reply. |
| 2219 | * @fip: The FCoE controller |
| 2220 | * @rdata: parsed remote port with frport from the probe request |
| 2221 | * |
| 2222 | * Called with ctlr_mutex held. |
| 2223 | */ |
| 2224 | static void fcoe_ctlr_vn_probe_reply(struct fcoe_ctlr *fip, |
| 2225 | struct fc_rport_priv *rdata) |
| 2226 | { |
| 2227 | if (rdata->ids.port_id != fip->port_id) |
| 2228 | return; |
| 2229 | switch (fip->state) { |
| 2230 | case FIP_ST_VNMP_START: |
| 2231 | case FIP_ST_VNMP_PROBE1: |
| 2232 | case FIP_ST_VNMP_PROBE2: |
| 2233 | case FIP_ST_VNMP_CLAIM: |
| 2234 | fcoe_ctlr_vn_restart(fip); |
| 2235 | break; |
| 2236 | case FIP_ST_VNMP_UP: |
| 2237 | fcoe_ctlr_vn_send_claim(fip); |
| 2238 | break; |
| 2239 | default: |
| 2240 | break; |
| 2241 | } |
| 2242 | } |
| 2243 | |
| 2244 | /** |
| 2245 | * fcoe_ctlr_vn_add() - Add a VN2VN entry to the list, based on a claim reply. |
| 2246 | * @fip: The FCoE controller |
| 2247 | * @new: newly-parsed remote port with frport as a template for new rdata |
| 2248 | * |
| 2249 | * Called with ctlr_mutex held. |
| 2250 | */ |
| 2251 | static void fcoe_ctlr_vn_add(struct fcoe_ctlr *fip, struct fc_rport_priv *new) |
| 2252 | { |
| 2253 | struct fc_lport *lport = fip->lp; |
| 2254 | struct fc_rport_priv *rdata; |
| 2255 | struct fc_rport_identifiers *ids; |
| 2256 | struct fcoe_rport *frport; |
| 2257 | u32 port_id; |
| 2258 | |
| 2259 | port_id = new->ids.port_id; |
| 2260 | if (port_id == fip->port_id) |
| 2261 | return; |
| 2262 | |
| 2263 | mutex_lock(&lport->disc.disc_mutex); |
| 2264 | rdata = lport->tt.rport_create(lport, port_id); |
| 2265 | if (!rdata) { |
| 2266 | mutex_unlock(&lport->disc.disc_mutex); |
| 2267 | return; |
| 2268 | } |
| 2269 | |
| 2270 | rdata->ops = &fcoe_ctlr_vn_rport_ops; |
| 2271 | rdata->disc_id = lport->disc.disc_id; |
| 2272 | |
| 2273 | ids = &rdata->ids; |
| 2274 | if ((ids->port_name != -1 && ids->port_name != new->ids.port_name) || |
| 2275 | (ids->node_name != -1 && ids->node_name != new->ids.node_name)) |
| 2276 | lport->tt.rport_logoff(rdata); |
| 2277 | ids->port_name = new->ids.port_name; |
| 2278 | ids->node_name = new->ids.node_name; |
| 2279 | mutex_unlock(&lport->disc.disc_mutex); |
| 2280 | |
| 2281 | frport = fcoe_ctlr_rport(rdata); |
| 2282 | LIBFCOE_FIP_DBG(fip, "vn_add rport %6.6x %s\n", |
| 2283 | port_id, frport->fcoe_len ? "old" : "new"); |
| 2284 | *frport = *fcoe_ctlr_rport(new); |
| 2285 | frport->time = 0; |
| 2286 | } |
| 2287 | |
| 2288 | /** |
| 2289 | * fcoe_ctlr_vn_lookup() - Find VN remote port's MAC address |
| 2290 | * @fip: The FCoE controller |
| 2291 | * @port_id: The port_id of the remote VN_node |
| 2292 | * @mac: buffer which will hold the VN_NODE destination MAC address, if found. |
| 2293 | * |
| 2294 | * Returns non-zero error if no remote port found. |
| 2295 | */ |
| 2296 | static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr *fip, u32 port_id, u8 *mac) |
| 2297 | { |
| 2298 | struct fc_lport *lport = fip->lp; |
| 2299 | struct fc_rport_priv *rdata; |
| 2300 | struct fcoe_rport *frport; |
| 2301 | int ret = -1; |
| 2302 | |
| 2303 | rcu_read_lock(); |
| 2304 | rdata = lport->tt.rport_lookup(lport, port_id); |
| 2305 | if (rdata) { |
| 2306 | frport = fcoe_ctlr_rport(rdata); |
| 2307 | memcpy(mac, frport->enode_mac, ETH_ALEN); |
| 2308 | ret = 0; |
| 2309 | } |
| 2310 | rcu_read_unlock(); |
| 2311 | return ret; |
| 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * fcoe_ctlr_vn_claim_notify() - handle received FIP VN2VN Claim Notification |
| 2316 | * @fip: The FCoE controller |
| 2317 | * @new: newly-parsed remote port with frport as a template for new rdata |
| 2318 | * |
| 2319 | * Called with ctlr_mutex held. |
| 2320 | */ |
| 2321 | static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr *fip, |
| 2322 | struct fc_rport_priv *new) |
| 2323 | { |
| 2324 | struct fcoe_rport *frport = fcoe_ctlr_rport(new); |
| 2325 | |
| 2326 | if (frport->flags & FIP_FL_REC_OR_P2P) { |
| 2327 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 2328 | return; |
| 2329 | } |
| 2330 | switch (fip->state) { |
| 2331 | case FIP_ST_VNMP_START: |
| 2332 | case FIP_ST_VNMP_PROBE1: |
| 2333 | case FIP_ST_VNMP_PROBE2: |
| 2334 | if (new->ids.port_id == fip->port_id) |
| 2335 | fcoe_ctlr_vn_restart(fip); |
| 2336 | break; |
| 2337 | case FIP_ST_VNMP_CLAIM: |
| 2338 | case FIP_ST_VNMP_UP: |
| 2339 | if (new->ids.port_id == fip->port_id) { |
| 2340 | if (new->ids.port_name > fip->lp->wwpn) { |
| 2341 | fcoe_ctlr_vn_restart(fip); |
| 2342 | break; |
| 2343 | } |
| 2344 | fcoe_ctlr_vn_send_claim(fip); |
| 2345 | break; |
| 2346 | } |
| 2347 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, frport->enode_mac, |
| 2348 | min((u32)frport->fcoe_len, |
| 2349 | fcoe_ctlr_fcoe_size(fip))); |
| 2350 | fcoe_ctlr_vn_add(fip, new); |
| 2351 | break; |
| 2352 | default: |
| 2353 | break; |
| 2354 | } |
| 2355 | } |
| 2356 | |
| 2357 | /** |
| 2358 | * fcoe_ctlr_vn_claim_resp() - handle received Claim Response |
| 2359 | * @fip: The FCoE controller that received the frame |
| 2360 | * @new: newly-parsed remote port with frport from the Claim Response |
| 2361 | * |
| 2362 | * Called with ctlr_mutex held. |
| 2363 | */ |
| 2364 | static void fcoe_ctlr_vn_claim_resp(struct fcoe_ctlr *fip, |
| 2365 | struct fc_rport_priv *new) |
| 2366 | { |
| 2367 | LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n", |
| 2368 | new->ids.port_id, fcoe_ctlr_state(fip->state)); |
| 2369 | if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM) |
| 2370 | fcoe_ctlr_vn_add(fip, new); |
| 2371 | } |
| 2372 | |
| 2373 | /** |
| 2374 | * fcoe_ctlr_vn_beacon() - handle received beacon. |
| 2375 | * @fip: The FCoE controller that received the frame |
| 2376 | * @new: newly-parsed remote port with frport from the Beacon |
| 2377 | * |
| 2378 | * Called with ctlr_mutex held. |
| 2379 | */ |
| 2380 | static void fcoe_ctlr_vn_beacon(struct fcoe_ctlr *fip, |
| 2381 | struct fc_rport_priv *new) |
| 2382 | { |
| 2383 | struct fc_lport *lport = fip->lp; |
| 2384 | struct fc_rport_priv *rdata; |
| 2385 | struct fcoe_rport *frport; |
| 2386 | |
| 2387 | frport = fcoe_ctlr_rport(new); |
| 2388 | if (frport->flags & FIP_FL_REC_OR_P2P) { |
| 2389 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 2390 | return; |
| 2391 | } |
| 2392 | mutex_lock(&lport->disc.disc_mutex); |
| 2393 | rdata = lport->tt.rport_lookup(lport, new->ids.port_id); |
| 2394 | if (rdata) |
| 2395 | kref_get(&rdata->kref); |
| 2396 | mutex_unlock(&lport->disc.disc_mutex); |
| 2397 | if (rdata) { |
| 2398 | if (rdata->ids.node_name == new->ids.node_name && |
| 2399 | rdata->ids.port_name == new->ids.port_name) { |
| 2400 | frport = fcoe_ctlr_rport(rdata); |
| 2401 | if (!frport->time && fip->state == FIP_ST_VNMP_UP) |
| 2402 | lport->tt.rport_login(rdata); |
| 2403 | frport->time = jiffies; |
| 2404 | } |
| 2405 | kref_put(&rdata->kref, lport->tt.rport_destroy); |
| 2406 | return; |
| 2407 | } |
| 2408 | if (fip->state != FIP_ST_VNMP_UP) |
| 2409 | return; |
| 2410 | |
| 2411 | /* |
| 2412 | * Beacon from a new neighbor. |
| 2413 | * Send a claim notify if one hasn't been sent recently. |
| 2414 | * Don't add the neighbor yet. |
| 2415 | */ |
| 2416 | LIBFCOE_FIP_DBG(fip, "beacon from new rport %x. sending claim notify\n", |
| 2417 | new->ids.port_id); |
| 2418 | if (time_after(jiffies, |
| 2419 | fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT))) |
| 2420 | fcoe_ctlr_vn_send_claim(fip); |
| 2421 | } |
| 2422 | |
| 2423 | /** |
| 2424 | * fcoe_ctlr_vn_age() - Check for VN_ports without recent beacons |
| 2425 | * @fip: The FCoE controller |
| 2426 | * |
| 2427 | * Called with ctlr_mutex held. |
| 2428 | * Called only in state FIP_ST_VNMP_UP. |
| 2429 | * Returns the soonest time for next age-out or a time far in the future. |
| 2430 | */ |
| 2431 | static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr *fip) |
| 2432 | { |
| 2433 | struct fc_lport *lport = fip->lp; |
| 2434 | struct fc_rport_priv *rdata; |
| 2435 | struct fcoe_rport *frport; |
| 2436 | unsigned long next_time; |
| 2437 | unsigned long deadline; |
| 2438 | |
| 2439 | next_time = jiffies + msecs_to_jiffies(FIP_VN_BEACON_INT * 10); |
| 2440 | mutex_lock(&lport->disc.disc_mutex); |
| 2441 | list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) { |
| 2442 | frport = fcoe_ctlr_rport(rdata); |
| 2443 | if (!frport->time) |
| 2444 | continue; |
| 2445 | deadline = frport->time + |
| 2446 | msecs_to_jiffies(FIP_VN_BEACON_INT * 25 / 10); |
| 2447 | if (time_after_eq(jiffies, deadline)) { |
| 2448 | frport->time = 0; |
| 2449 | LIBFCOE_FIP_DBG(fip, |
| 2450 | "port %16.16llx fc_id %6.6x beacon expired\n", |
| 2451 | rdata->ids.port_name, rdata->ids.port_id); |
| 2452 | lport->tt.rport_logoff(rdata); |
| 2453 | } else if (time_before(deadline, next_time)) |
| 2454 | next_time = deadline; |
| 2455 | } |
| 2456 | mutex_unlock(&lport->disc.disc_mutex); |
| 2457 | return next_time; |
| 2458 | } |
| 2459 | |
| 2460 | /** |
| 2461 | * fcoe_ctlr_vn_recv() - Receive a FIP frame |
| 2462 | * @fip: The FCoE controller that received the frame |
| 2463 | * @skb: The received FIP frame |
| 2464 | * |
| 2465 | * Returns non-zero if the frame is dropped. |
| 2466 | * Always consumes the frame. |
| 2467 | */ |
| 2468 | static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb) |
| 2469 | { |
| 2470 | struct fip_header *fiph; |
| 2471 | enum fip_vn2vn_subcode sub; |
Kiran Patil | 2dc02ee | 2010-10-08 17:12:41 -0700 | [diff] [blame] | 2472 | struct { |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2473 | struct fc_rport_priv rdata; |
| 2474 | struct fcoe_rport frport; |
| 2475 | } buf; |
| 2476 | int rc; |
| 2477 | |
| 2478 | fiph = (struct fip_header *)skb->data; |
| 2479 | sub = fiph->fip_subcode; |
| 2480 | |
| 2481 | rc = fcoe_ctlr_vn_parse(fip, skb, &buf.rdata); |
| 2482 | if (rc) { |
| 2483 | LIBFCOE_FIP_DBG(fip, "vn_recv vn_parse error %d\n", rc); |
| 2484 | goto drop; |
| 2485 | } |
| 2486 | |
| 2487 | mutex_lock(&fip->ctlr_mutex); |
| 2488 | switch (sub) { |
| 2489 | case FIP_SC_VN_PROBE_REQ: |
| 2490 | fcoe_ctlr_vn_probe_req(fip, &buf.rdata); |
| 2491 | break; |
| 2492 | case FIP_SC_VN_PROBE_REP: |
| 2493 | fcoe_ctlr_vn_probe_reply(fip, &buf.rdata); |
| 2494 | break; |
| 2495 | case FIP_SC_VN_CLAIM_NOTIFY: |
| 2496 | fcoe_ctlr_vn_claim_notify(fip, &buf.rdata); |
| 2497 | break; |
| 2498 | case FIP_SC_VN_CLAIM_REP: |
| 2499 | fcoe_ctlr_vn_claim_resp(fip, &buf.rdata); |
| 2500 | break; |
| 2501 | case FIP_SC_VN_BEACON: |
| 2502 | fcoe_ctlr_vn_beacon(fip, &buf.rdata); |
| 2503 | break; |
| 2504 | default: |
| 2505 | LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub); |
| 2506 | rc = -1; |
| 2507 | break; |
| 2508 | } |
| 2509 | mutex_unlock(&fip->ctlr_mutex); |
| 2510 | drop: |
| 2511 | kfree_skb(skb); |
| 2512 | return rc; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
| 2516 | * fcoe_ctlr_disc_recv - discovery receive handler for VN2VN mode. |
Joe Eykholt | 92261156 | 2010-07-20 15:21:12 -0700 | [diff] [blame] | 2517 | * @lport: The local port |
| 2518 | * @fp: The received frame |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2519 | * |
| 2520 | * This should never be called since we don't see RSCNs or other |
| 2521 | * fabric-generated ELSes. |
| 2522 | */ |
Joe Eykholt | 92261156 | 2010-07-20 15:21:12 -0700 | [diff] [blame] | 2523 | 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] | 2524 | { |
| 2525 | struct fc_seq_els_data rjt_data; |
| 2526 | |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2527 | rjt_data.reason = ELS_RJT_UNSUP; |
| 2528 | rjt_data.explan = ELS_EXPL_NONE; |
Joe Eykholt | 92261156 | 2010-07-20 15:21:12 -0700 | [diff] [blame] | 2529 | lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2530 | fc_frame_free(fp); |
| 2531 | } |
| 2532 | |
| 2533 | /** |
| 2534 | * fcoe_ctlr_disc_recv - start discovery for VN2VN mode. |
| 2535 | * @fip: The FCoE controller |
| 2536 | * |
| 2537 | * This sets a flag indicating that remote ports should be created |
| 2538 | * and started for the peers we discover. We use the disc_callback |
| 2539 | * pointer as that flag. Peers already discovered are created here. |
| 2540 | * |
| 2541 | * The lport lock is held during this call. The callback must be done |
| 2542 | * later, without holding either the lport or discovery locks. |
| 2543 | * The fcoe_ctlr lock may also be held during this call. |
| 2544 | */ |
| 2545 | static void fcoe_ctlr_disc_start(void (*callback)(struct fc_lport *, |
| 2546 | enum fc_disc_event), |
| 2547 | struct fc_lport *lport) |
| 2548 | { |
| 2549 | struct fc_disc *disc = &lport->disc; |
| 2550 | struct fcoe_ctlr *fip = disc->priv; |
| 2551 | |
| 2552 | mutex_lock(&disc->disc_mutex); |
| 2553 | disc->disc_callback = callback; |
| 2554 | disc->disc_id = (disc->disc_id + 2) | 1; |
| 2555 | disc->pending = 1; |
| 2556 | schedule_work(&fip->timer_work); |
| 2557 | mutex_unlock(&disc->disc_mutex); |
| 2558 | } |
| 2559 | |
| 2560 | /** |
| 2561 | * fcoe_ctlr_vn_disc() - report FIP VN_port discovery results after claim state. |
| 2562 | * @fip: The FCoE controller |
| 2563 | * |
| 2564 | * Starts the FLOGI and PLOGI login process to each discovered rport for which |
| 2565 | * we've received at least one beacon. |
| 2566 | * Performs the discovery complete callback. |
| 2567 | */ |
| 2568 | static void fcoe_ctlr_vn_disc(struct fcoe_ctlr *fip) |
| 2569 | { |
| 2570 | struct fc_lport *lport = fip->lp; |
| 2571 | struct fc_disc *disc = &lport->disc; |
| 2572 | struct fc_rport_priv *rdata; |
| 2573 | struct fcoe_rport *frport; |
| 2574 | void (*callback)(struct fc_lport *, enum fc_disc_event); |
| 2575 | |
| 2576 | mutex_lock(&disc->disc_mutex); |
| 2577 | callback = disc->pending ? disc->disc_callback : NULL; |
| 2578 | disc->pending = 0; |
| 2579 | list_for_each_entry_rcu(rdata, &disc->rports, peers) { |
| 2580 | frport = fcoe_ctlr_rport(rdata); |
| 2581 | if (frport->time) |
| 2582 | lport->tt.rport_login(rdata); |
| 2583 | } |
| 2584 | mutex_unlock(&disc->disc_mutex); |
| 2585 | if (callback) |
| 2586 | callback(lport, DISC_EV_SUCCESS); |
| 2587 | } |
| 2588 | |
| 2589 | /** |
| 2590 | * fcoe_ctlr_vn_timeout - timer work function for VN2VN mode. |
| 2591 | * @fip: The FCoE controller |
| 2592 | */ |
| 2593 | static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *fip) |
| 2594 | { |
| 2595 | unsigned long next_time; |
| 2596 | u8 mac[ETH_ALEN]; |
| 2597 | u32 new_port_id = 0; |
| 2598 | |
| 2599 | mutex_lock(&fip->ctlr_mutex); |
| 2600 | switch (fip->state) { |
| 2601 | case FIP_ST_VNMP_START: |
| 2602 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE1); |
| 2603 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 2604 | next_time = jiffies + msecs_to_jiffies(FIP_VN_PROBE_WAIT); |
| 2605 | break; |
| 2606 | case FIP_ST_VNMP_PROBE1: |
| 2607 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE2); |
| 2608 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0); |
| 2609 | next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 2610 | break; |
| 2611 | case FIP_ST_VNMP_PROBE2: |
| 2612 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_CLAIM); |
| 2613 | new_port_id = fip->port_id; |
| 2614 | hton24(mac, FIP_VN_FC_MAP); |
| 2615 | hton24(mac + 3, new_port_id); |
Joe Eykholt | cd229e4 | 2010-07-20 15:20:40 -0700 | [diff] [blame] | 2616 | fcoe_ctlr_map_dest(fip); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2617 | fip->update_mac(fip->lp, mac); |
| 2618 | fcoe_ctlr_vn_send_claim(fip); |
| 2619 | next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 2620 | break; |
| 2621 | case FIP_ST_VNMP_CLAIM: |
| 2622 | /* |
| 2623 | * This may be invoked either by starting discovery so don't |
| 2624 | * go to the next state unless it's been long enough. |
| 2625 | */ |
| 2626 | next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 2627 | if (time_after_eq(jiffies, next_time)) { |
| 2628 | fcoe_ctlr_set_state(fip, FIP_ST_VNMP_UP); |
| 2629 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON, |
| 2630 | fcoe_all_vn2vn, 0); |
| 2631 | next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT); |
| 2632 | fip->port_ka_time = next_time; |
| 2633 | } |
| 2634 | fcoe_ctlr_vn_disc(fip); |
| 2635 | break; |
| 2636 | case FIP_ST_VNMP_UP: |
| 2637 | next_time = fcoe_ctlr_vn_age(fip); |
| 2638 | if (time_after_eq(jiffies, fip->port_ka_time)) { |
| 2639 | fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON, |
| 2640 | fcoe_all_vn2vn, 0); |
| 2641 | fip->port_ka_time = jiffies + |
| 2642 | msecs_to_jiffies(FIP_VN_BEACON_INT + |
| 2643 | (random32() % FIP_VN_BEACON_FUZZ)); |
| 2644 | } |
| 2645 | if (time_before(fip->port_ka_time, next_time)) |
| 2646 | next_time = fip->port_ka_time; |
| 2647 | break; |
| 2648 | case FIP_ST_LINK_WAIT: |
| 2649 | goto unlock; |
| 2650 | default: |
Joe Perches | 11aa990 | 2010-11-30 16:19:09 -0800 | [diff] [blame] | 2651 | WARN(1, "unexpected state %d\n", fip->state); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2652 | goto unlock; |
| 2653 | } |
| 2654 | mod_timer(&fip->timer, next_time); |
| 2655 | unlock: |
| 2656 | mutex_unlock(&fip->ctlr_mutex); |
| 2657 | |
| 2658 | /* If port ID is new, notify local port after dropping ctlr_mutex */ |
| 2659 | if (new_port_id) |
| 2660 | fc_lport_set_local_id(fip->lp, new_port_id); |
| 2661 | } |
| 2662 | |
| 2663 | /** |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 2664 | * fcoe_libfc_config() - Sets up libfc related properties for local port |
| 2665 | * @lp: The local port to configure libfc for |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2666 | * @fip: The FCoE controller in use by the local port |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 2667 | * @tt: The libfc function template |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2668 | * @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] | 2669 | * |
| 2670 | * Returns : 0 for success |
| 2671 | */ |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2672 | int fcoe_libfc_config(struct fc_lport *lport, struct fcoe_ctlr *fip, |
| 2673 | const struct libfc_function_template *tt, int init_fcp) |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 2674 | { |
| 2675 | /* Set the function pointers set by the LLDD */ |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 2676 | memcpy(&lport->tt, tt, sizeof(*tt)); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2677 | if (init_fcp && fc_fcp_init(lport)) |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 2678 | return -ENOMEM; |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 2679 | fc_exch_init(lport); |
| 2680 | fc_elsct_init(lport); |
| 2681 | fc_lport_init(lport); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2682 | if (fip->mode == FIP_MODE_VN2VN) |
| 2683 | lport->rport_priv_size = sizeof(struct fcoe_rport); |
Robert Love | 70b51aa | 2009-11-03 11:47:45 -0800 | [diff] [blame] | 2684 | fc_rport_init(lport); |
Joe Eykholt | e10f8c6 | 2010-07-20 15:20:30 -0700 | [diff] [blame] | 2685 | if (fip->mode == FIP_MODE_VN2VN) { |
| 2686 | lport->point_to_multipoint = 1; |
| 2687 | lport->tt.disc_recv_req = fcoe_ctlr_disc_recv; |
| 2688 | lport->tt.disc_start = fcoe_ctlr_disc_start; |
| 2689 | lport->tt.disc_stop = fcoe_ctlr_disc_stop; |
| 2690 | lport->tt.disc_stop_final = fcoe_ctlr_disc_stop_final; |
| 2691 | mutex_init(&lport->disc.disc_mutex); |
| 2692 | INIT_LIST_HEAD(&lport->disc.rports); |
| 2693 | lport->disc.priv = fip; |
| 2694 | } else { |
| 2695 | fc_disc_init(lport); |
| 2696 | } |
Vasu Dev | 5e80f7f | 2009-03-17 11:42:18 -0700 | [diff] [blame] | 2697 | return 0; |
| 2698 | } |
| 2699 | EXPORT_SYMBOL_GPL(fcoe_libfc_config); |