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