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