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