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