blob: c90622c28b6cec09dc43028d4dd2aad6b1ec6ef2 [file] [log] [blame]
Vasu Dev9b34ecf2009-03-17 11:42:13 -07001/*
Joe Eykholt97c83892009-03-17 11:42:40 -07002 * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2009 Intel Corporation. All rights reserved.
Vasu Dev9b34ecf2009-03-17 11:42:13 -07004 *
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 Eykholt97c83892009-03-17 11:42:40 -070021#include <linux/types.h>
Vasu Dev9b34ecf2009-03-17 11:42:13 -070022#include <linux/module.h>
Joe Eykholt97c83892009-03-17 11:42:40 -070023#include <linux/kernel.h>
24#include <linux/list.h>
25#include <linux/spinlock.h>
26#include <linux/timer.h>
Vasu Dev5e80f7f2009-03-17 11:42:18 -070027#include <linux/netdevice.h>
Joe Eykholt97c83892009-03-17 11:42:40 -070028#include <linux/etherdevice.h>
29#include <linux/ethtool.h>
30#include <linux/if_ether.h>
31#include <linux/if_vlan.h>
Joe Eykholt97c83892009-03-17 11:42:40 -070032#include <linux/errno.h>
33#include <linux/bitops.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Joe Eykholt97c83892009-03-17 11:42:40 -070035#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 Eykholte10f8c62010-07-20 15:20:30 -070042#include <scsi/fc/fc_fcp.h>
Vasu Dev5e80f7f2009-03-17 11:42:18 -070043
44#include <scsi/libfc.h>
Joe Eykholt97c83892009-03-17 11:42:40 -070045#include <scsi/libfcoe.h>
Vasu Dev9b34ecf2009-03-17 11:42:13 -070046
47MODULE_AUTHOR("Open-FCoE.org");
Joe Eykholt97c83892009-03-17 11:42:40 -070048MODULE_DESCRIPTION("FIP discovery protocol support for FCoE HBAs");
Vasu Dev9b34ecf2009-03-17 11:42:13 -070049MODULE_LICENSE("GPL v2");
Vasu Dev5e80f7f2009-03-17 11:42:18 -070050
Joe Eykholt97c83892009-03-17 11:42:40 -070051#define FCOE_CTLR_MIN_FKA 500 /* min keep alive (mS) */
52#define FCOE_CTLR_DEF_FKA FIP_DEF_FKA /* default keep alive (mS) */
53
54static void fcoe_ctlr_timeout(unsigned long);
Joe Eykholt42913652010-03-12 16:08:23 -080055static void fcoe_ctlr_timer_work(struct work_struct *);
Joe Eykholt97c83892009-03-17 11:42:40 -070056static void fcoe_ctlr_recv_work(struct work_struct *);
Joe Eykholt794d98e2010-11-30 16:19:56 -080057static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *);
58static void fcoe_ctlr_select(struct fcoe_ctlr *);
Joe Eykholt97c83892009-03-17 11:42:40 -070059
Joe Eykholte10f8c62010-07-20 15:20:30 -070060static void fcoe_ctlr_vn_start(struct fcoe_ctlr *);
61static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *, struct sk_buff *);
62static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *);
63static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr *, u32, u8 *);
64
Joe Eykholt97c83892009-03-17 11:42:40 -070065static u8 fcoe_all_fcfs[ETH_ALEN] = FIP_ALL_FCF_MACS;
Joe Eykholte10f8c62010-07-20 15:20:30 -070066static u8 fcoe_all_enode[ETH_ALEN] = FIP_ALL_ENODE_MACS;
67static u8 fcoe_all_vn2vn[ETH_ALEN] = FIP_ALL_VN2VN_MACS;
68static u8 fcoe_all_p2p[ETH_ALEN] = FIP_ALL_P2P_MACS;
Joe Eykholt97c83892009-03-17 11:42:40 -070069
Robert Love650bd122009-06-10 15:31:05 -070070unsigned int libfcoe_debug_logging;
71module_param_named(debug_logging, libfcoe_debug_logging, int, S_IRUGO|S_IWUSR);
72MODULE_PARM_DESC(debug_logging, "a bit mask of logging levels");
Joe Eykholt97c83892009-03-17 11:42:40 -070073
Robert Love70b51aa2009-11-03 11:47:45 -080074#define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */
Robert Love650bd122009-06-10 15:31:05 -070075#define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */
76
Robert Love70b51aa2009-11-03 11:47:45 -080077#define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \
78do { \
79 if (unlikely(libfcoe_debug_logging & LEVEL)) \
80 do { \
81 CMD; \
82 } while (0); \
Joe Eykholta69b06b2009-08-25 13:58:42 -070083} while (0)
Joe Eykholt97c83892009-03-17 11:42:40 -070084
Robert Love650bd122009-06-10 15:31:05 -070085#define LIBFCOE_DBG(fmt, args...) \
86 LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \
87 printk(KERN_INFO "libfcoe: " fmt, ##args);)
88
Joe Eykholt0f51c2e2009-11-03 11:48:16 -080089#define LIBFCOE_FIP_DBG(fip, fmt, args...) \
Robert Love650bd122009-06-10 15:31:05 -070090 LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \
Joe Eykholt0f51c2e2009-11-03 11:48:16 -080091 printk(KERN_INFO "host%d: fip: " fmt, \
92 (fip)->lp->host->host_no, ##args);)
Joe Eykholt97c83892009-03-17 11:42:40 -070093
Joe Eykholt9b651da2010-07-20 15:20:24 -070094static const char *fcoe_ctlr_states[] = {
95 [FIP_ST_DISABLED] = "DISABLED",
96 [FIP_ST_LINK_WAIT] = "LINK_WAIT",
97 [FIP_ST_AUTO] = "AUTO",
98 [FIP_ST_NON_FIP] = "NON_FIP",
99 [FIP_ST_ENABLED] = "ENABLED",
Joe Eykholte10f8c62010-07-20 15:20:30 -0700100 [FIP_ST_VNMP_START] = "VNMP_START",
101 [FIP_ST_VNMP_PROBE1] = "VNMP_PROBE1",
102 [FIP_ST_VNMP_PROBE2] = "VNMP_PROBE2",
103 [FIP_ST_VNMP_CLAIM] = "VNMP_CLAIM",
104 [FIP_ST_VNMP_UP] = "VNMP_UP",
Joe Eykholt9b651da2010-07-20 15:20:24 -0700105};
106
107static const char *fcoe_ctlr_state(enum fip_state state)
108{
109 const char *cp = "unknown";
110
111 if (state < ARRAY_SIZE(fcoe_ctlr_states))
112 cp = fcoe_ctlr_states[state];
113 if (!cp)
114 cp = "unknown";
115 return cp;
116}
117
118/**
119 * fcoe_ctlr_set_state() - Set and do debug printing for the new FIP state.
120 * @fip: The FCoE controller
121 * @state: The new state
122 */
123static void fcoe_ctlr_set_state(struct fcoe_ctlr *fip, enum fip_state state)
124{
125 if (state == fip->state)
126 return;
127 if (fip->lp)
128 LIBFCOE_FIP_DBG(fip, "state %s -> %s\n",
129 fcoe_ctlr_state(fip->state), fcoe_ctlr_state(state));
130 fip->state = state;
131}
132
Robert Love70b51aa2009-11-03 11:47:45 -0800133/**
134 * fcoe_ctlr_mtu_valid() - Check if a FCF's MTU is valid
135 * @fcf: The FCF to check
136 *
Joe Eykholt97c83892009-03-17 11:42:40 -0700137 * Return non-zero if FCF fcoe_size has been validated.
138 */
139static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf *fcf)
140{
141 return (fcf->flags & FIP_FL_SOL) != 0;
142}
143
Robert Love70b51aa2009-11-03 11:47:45 -0800144/**
145 * fcoe_ctlr_fcf_usable() - Check if a FCF is usable
146 * @fcf: The FCF to check
147 *
Joe Eykholt97c83892009-03-17 11:42:40 -0700148 * Return non-zero if the FCF is usable.
149 */
150static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf *fcf)
151{
152 u16 flags = FIP_FL_SOL | FIP_FL_AVAIL;
153
154 return (fcf->flags & flags) == flags;
155}
156
157/**
Joe Eykholtcd229e42010-07-20 15:20:40 -0700158 * fcoe_ctlr_map_dest() - Set flag and OUI for mapping destination addresses
159 * @fip: The FCoE controller
160 */
161static void fcoe_ctlr_map_dest(struct fcoe_ctlr *fip)
162{
163 if (fip->mode == FIP_MODE_VN2VN)
164 hton24(fip->dest_addr, FIP_VN_FC_MAP);
165 else
166 hton24(fip->dest_addr, FIP_DEF_FC_MAP);
167 hton24(fip->dest_addr + 3, 0);
168 fip->map_dest = 1;
169}
170
171/**
Robert Love70b51aa2009-11-03 11:47:45 -0800172 * fcoe_ctlr_init() - Initialize the FCoE Controller instance
173 * @fip: The FCoE controller to initialize
Joe Eykholt97c83892009-03-17 11:42:40 -0700174 */
Joe Eykholt3d902ac2010-07-20 15:19:58 -0700175void fcoe_ctlr_init(struct fcoe_ctlr *fip, enum fip_state mode)
Joe Eykholt97c83892009-03-17 11:42:40 -0700176{
Joe Eykholt9b651da2010-07-20 15:20:24 -0700177 fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT);
Joe Eykholt3d902ac2010-07-20 15:19:58 -0700178 fip->mode = mode;
Joe Eykholt97c83892009-03-17 11:42:40 -0700179 INIT_LIST_HEAD(&fip->fcfs);
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700180 mutex_init(&fip->ctlr_mutex);
Joe Eykholt794d98e2010-11-30 16:19:56 -0800181 spin_lock_init(&fip->ctlr_lock);
Joe Eykholt97c83892009-03-17 11:42:40 -0700182 fip->flogi_oxid = FC_XID_UNKNOWN;
183 setup_timer(&fip->timer, fcoe_ctlr_timeout, (unsigned long)fip);
Joe Eykholt42913652010-03-12 16:08:23 -0800184 INIT_WORK(&fip->timer_work, fcoe_ctlr_timer_work);
Joe Eykholt97c83892009-03-17 11:42:40 -0700185 INIT_WORK(&fip->recv_work, fcoe_ctlr_recv_work);
186 skb_queue_head_init(&fip->fip_recv_list);
187}
188EXPORT_SYMBOL(fcoe_ctlr_init);
189
190/**
Robert Love70b51aa2009-11-03 11:47:45 -0800191 * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller
192 * @fip: The FCoE controller whose FCFs are to be reset
Joe Eykholt97c83892009-03-17 11:42:40 -0700193 *
194 * Called with &fcoe_ctlr lock held.
195 */
196static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr *fip)
197{
198 struct fcoe_fcf *fcf;
199 struct fcoe_fcf *next;
200
201 fip->sel_fcf = NULL;
202 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
203 list_del(&fcf->list);
204 kfree(fcf);
205 }
206 fip->fcf_count = 0;
207 fip->sel_time = 0;
208}
209
210/**
Robert Love70b51aa2009-11-03 11:47:45 -0800211 * fcoe_ctlr_destroy() - Disable and tear down a FCoE controller
212 * @fip: The FCoE controller to tear down
Joe Eykholt97c83892009-03-17 11:42:40 -0700213 *
214 * This is called by FCoE drivers before freeing the &fcoe_ctlr.
215 *
216 * The receive handler will have been deleted before this to guarantee
217 * that no more recv_work will be scheduled.
218 *
219 * The timer routine will simply return once we set FIP_ST_DISABLED.
220 * This guarantees that no further timeouts or work will be scheduled.
221 */
222void fcoe_ctlr_destroy(struct fcoe_ctlr *fip)
223{
Chris Leecha4b7cfa2009-08-25 13:59:08 -0700224 cancel_work_sync(&fip->recv_work);
Joe Eykholt1f4aed82009-11-03 11:48:22 -0800225 skb_queue_purge(&fip->fip_recv_list);
Chris Leecha4b7cfa2009-08-25 13:59:08 -0700226
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700227 mutex_lock(&fip->ctlr_mutex);
Joe Eykholt9b651da2010-07-20 15:20:24 -0700228 fcoe_ctlr_set_state(fip, FIP_ST_DISABLED);
Joe Eykholt97c83892009-03-17 11:42:40 -0700229 fcoe_ctlr_reset_fcfs(fip);
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700230 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -0700231 del_timer_sync(&fip->timer);
Joe Eykholt42913652010-03-12 16:08:23 -0800232 cancel_work_sync(&fip->timer_work);
Joe Eykholt97c83892009-03-17 11:42:40 -0700233}
234EXPORT_SYMBOL(fcoe_ctlr_destroy);
235
236/**
Joe Eykholt794d98e2010-11-30 16:19:56 -0800237 * fcoe_ctlr_announce() - announce new FCF selection
Joe Eykholt69316ee2010-11-30 16:19:40 -0800238 * @fip: The FCoE controller
239 *
240 * Also sets the destination MAC for FCoE and control packets
Joe Eykholt794d98e2010-11-30 16:19:56 -0800241 *
242 * Called with neither ctlr_mutex nor ctlr_lock held.
Joe Eykholt69316ee2010-11-30 16:19:40 -0800243 */
244static void fcoe_ctlr_announce(struct fcoe_ctlr *fip)
245{
Joe Eykholt794d98e2010-11-30 16:19:56 -0800246 struct fcoe_fcf *sel;
247 struct fcoe_fcf *fcf;
248
249 mutex_lock(&fip->ctlr_mutex);
250 spin_lock_bh(&fip->ctlr_lock);
251
252 kfree_skb(fip->flogi_req);
253 fip->flogi_req = NULL;
254 list_for_each_entry(fcf, &fip->fcfs, list)
255 fcf->flogi_sent = 0;
256
257 spin_unlock_bh(&fip->ctlr_lock);
258 sel = fip->sel_fcf;
Joe Eykholt69316ee2010-11-30 16:19:40 -0800259
260 if (sel && !compare_ether_addr(sel->fcf_mac, fip->dest_addr))
Joe Eykholt794d98e2010-11-30 16:19:56 -0800261 goto unlock;
Joe Eykholt69316ee2010-11-30 16:19:40 -0800262 if (!is_zero_ether_addr(fip->dest_addr)) {
263 printk(KERN_NOTICE "libfcoe: host%d: "
264 "FIP Fibre-Channel Forwarder MAC %pM deselected\n",
265 fip->lp->host->host_no, fip->dest_addr);
266 memset(fip->dest_addr, 0, ETH_ALEN);
267 }
268 if (sel) {
269 printk(KERN_INFO "libfcoe: host%d: FIP selected "
270 "Fibre-Channel Forwarder MAC %pM\n",
271 fip->lp->host->host_no, sel->fcf_mac);
272 memcpy(fip->dest_addr, sel->fcf_mac, ETH_ALEN);
273 fip->map_dest = 0;
274 }
Joe Eykholt794d98e2010-11-30 16:19:56 -0800275unlock:
276 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt69316ee2010-11-30 16:19:40 -0800277}
278
279/**
Robert Love70b51aa2009-11-03 11:47:45 -0800280 * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port
281 * @fip: The FCoE controller to get the maximum FCoE size from
Joe Eykholt97c83892009-03-17 11:42:40 -0700282 *
283 * Returns the maximum packet size including the FCoE header and trailer,
284 * but not including any Ethernet or VLAN headers.
285 */
286static inline u32 fcoe_ctlr_fcoe_size(struct fcoe_ctlr *fip)
287{
288 /*
289 * Determine the max FCoE frame size allowed, including
290 * FCoE header and trailer.
291 * Note: lp->mfs is currently the payload size, not the frame size.
292 */
293 return fip->lp->mfs + sizeof(struct fc_frame_header) +
294 sizeof(struct fcoe_hdr) + sizeof(struct fcoe_crc_eof);
295}
296
297/**
Robert Love70b51aa2009-11-03 11:47:45 -0800298 * fcoe_ctlr_solicit() - Send a FIP solicitation
299 * @fip: The FCoE controller to send the solicitation on
300 * @fcf: The destination FCF (if NULL, a multicast solicitation is sent)
Joe Eykholt97c83892009-03-17 11:42:40 -0700301 */
302static void fcoe_ctlr_solicit(struct fcoe_ctlr *fip, struct fcoe_fcf *fcf)
303{
304 struct sk_buff *skb;
305 struct fip_sol {
306 struct ethhdr eth;
307 struct fip_header fip;
308 struct {
309 struct fip_mac_desc mac;
310 struct fip_wwn_desc wwnn;
311 struct fip_size_desc size;
312 } __attribute__((packed)) desc;
313 } __attribute__((packed)) *sol;
314 u32 fcoe_size;
315
316 skb = dev_alloc_skb(sizeof(*sol));
317 if (!skb)
318 return;
319
320 sol = (struct fip_sol *)skb->data;
321
322 memset(sol, 0, sizeof(*sol));
323 memcpy(sol->eth.h_dest, fcf ? fcf->fcf_mac : fcoe_all_fcfs, ETH_ALEN);
324 memcpy(sol->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
325 sol->eth.h_proto = htons(ETH_P_FIP);
326
327 sol->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
328 sol->fip.fip_op = htons(FIP_OP_DISC);
329 sol->fip.fip_subcode = FIP_SC_SOL;
330 sol->fip.fip_dl_len = htons(sizeof(sol->desc) / FIP_BPW);
331 sol->fip.fip_flags = htons(FIP_FL_FPMA);
Vasu Dev184dd342009-05-17 12:33:28 +0000332 if (fip->spma)
333 sol->fip.fip_flags |= htons(FIP_FL_SPMA);
Joe Eykholt97c83892009-03-17 11:42:40 -0700334
335 sol->desc.mac.fd_desc.fip_dtype = FIP_DT_MAC;
336 sol->desc.mac.fd_desc.fip_dlen = sizeof(sol->desc.mac) / FIP_BPW;
337 memcpy(sol->desc.mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
338
339 sol->desc.wwnn.fd_desc.fip_dtype = FIP_DT_NAME;
340 sol->desc.wwnn.fd_desc.fip_dlen = sizeof(sol->desc.wwnn) / FIP_BPW;
341 put_unaligned_be64(fip->lp->wwnn, &sol->desc.wwnn.fd_wwn);
342
343 fcoe_size = fcoe_ctlr_fcoe_size(fip);
344 sol->desc.size.fd_desc.fip_dtype = FIP_DT_FCOE_SIZE;
345 sol->desc.size.fd_desc.fip_dlen = sizeof(sol->desc.size) / FIP_BPW;
346 sol->desc.size.fd_size = htons(fcoe_size);
347
348 skb_put(skb, sizeof(*sol));
Chris Leech0f491532009-05-06 10:52:18 -0700349 skb->protocol = htons(ETH_P_FIP);
Joe Eykholt97c83892009-03-17 11:42:40 -0700350 skb_reset_mac_header(skb);
351 skb_reset_network_header(skb);
352 fip->send(fip, skb);
353
354 if (!fcf)
355 fip->sol_time = jiffies;
356}
357
358/**
Robert Love70b51aa2009-11-03 11:47:45 -0800359 * fcoe_ctlr_link_up() - Start FCoE controller
360 * @fip: The FCoE controller to start
Joe Eykholt97c83892009-03-17 11:42:40 -0700361 *
362 * Called from the LLD when the network link is ready.
363 */
364void fcoe_ctlr_link_up(struct fcoe_ctlr *fip)
365{
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700366 mutex_lock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -0700367 if (fip->state == FIP_ST_NON_FIP || fip->state == FIP_ST_AUTO) {
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700368 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -0700369 fc_linkup(fip->lp);
370 } else if (fip->state == FIP_ST_LINK_WAIT) {
Joe Eykholt9b651da2010-07-20 15:20:24 -0700371 fcoe_ctlr_set_state(fip, fip->mode);
Joe Eykholte10f8c62010-07-20 15:20:30 -0700372 switch (fip->mode) {
373 default:
374 LIBFCOE_FIP_DBG(fip, "invalid mode %d\n", fip->mode);
375 /* fall-through */
376 case FIP_MODE_AUTO:
Joe Eykholt0f51c2e2009-11-03 11:48:16 -0800377 LIBFCOE_FIP_DBG(fip, "%s", "setting AUTO mode.\n");
Joe Eykholte10f8c62010-07-20 15:20:30 -0700378 /* fall-through */
379 case FIP_MODE_FABRIC:
380 case FIP_MODE_NON_FIP:
381 mutex_unlock(&fip->ctlr_mutex);
382 fc_linkup(fip->lp);
383 fcoe_ctlr_solicit(fip, NULL);
384 break;
385 case FIP_MODE_VN2VN:
386 fcoe_ctlr_vn_start(fip);
387 mutex_unlock(&fip->ctlr_mutex);
388 fc_linkup(fip->lp);
389 break;
390 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700391 } else
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700392 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -0700393}
394EXPORT_SYMBOL(fcoe_ctlr_link_up);
395
396/**
Robert Love70b51aa2009-11-03 11:47:45 -0800397 * fcoe_ctlr_reset() - Reset a FCoE controller
398 * @fip: The FCoE controller to reset
Joe Eykholt97c83892009-03-17 11:42:40 -0700399 */
Joe Eykholtdd42dac2009-11-03 11:48:27 -0800400static void fcoe_ctlr_reset(struct fcoe_ctlr *fip)
Joe Eykholt97c83892009-03-17 11:42:40 -0700401{
Joe Eykholt97c83892009-03-17 11:42:40 -0700402 fcoe_ctlr_reset_fcfs(fip);
403 del_timer(&fip->timer);
Joe Eykholt97c83892009-03-17 11:42:40 -0700404 fip->ctlr_ka_time = 0;
405 fip->port_ka_time = 0;
406 fip->sol_time = 0;
407 fip->flogi_oxid = FC_XID_UNKNOWN;
Joe Eykholtcd229e42010-07-20 15:20:40 -0700408 fcoe_ctlr_map_dest(fip);
Joe Eykholt97c83892009-03-17 11:42:40 -0700409}
410
411/**
Robert Love70b51aa2009-11-03 11:47:45 -0800412 * fcoe_ctlr_link_down() - Stop a FCoE controller
413 * @fip: The FCoE controller to be stopped
Joe Eykholt97c83892009-03-17 11:42:40 -0700414 *
415 * Returns non-zero if the link was up and now isn't.
416 *
417 * Called from the LLD when the network link is not ready.
418 * There may be multiple calls while the link is down.
419 */
420int fcoe_ctlr_link_down(struct fcoe_ctlr *fip)
421{
Joe Eykholtdd42dac2009-11-03 11:48:27 -0800422 int link_dropped;
423
424 LIBFCOE_FIP_DBG(fip, "link down.\n");
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700425 mutex_lock(&fip->ctlr_mutex);
Joe Eykholtdd42dac2009-11-03 11:48:27 -0800426 fcoe_ctlr_reset(fip);
Joe Eykholt42913652010-03-12 16:08:23 -0800427 link_dropped = fip->state != FIP_ST_LINK_WAIT;
Joe Eykholt9b651da2010-07-20 15:20:24 -0700428 fcoe_ctlr_set_state(fip, FIP_ST_LINK_WAIT);
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700429 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholtdd42dac2009-11-03 11:48:27 -0800430
431 if (link_dropped)
432 fc_linkdown(fip->lp);
433 return link_dropped;
Joe Eykholt97c83892009-03-17 11:42:40 -0700434}
435EXPORT_SYMBOL(fcoe_ctlr_link_down);
436
437/**
Robert Love70b51aa2009-11-03 11:47:45 -0800438 * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF
439 * @fip: The FCoE controller to send the FKA on
440 * @lport: libfc fc_lport to send from
441 * @ports: 0 for controller keep-alive, 1 for port keep-alive
442 * @sa: The source MAC address
Joe Eykholt97c83892009-03-17 11:42:40 -0700443 *
444 * A controller keep-alive is sent every fka_period (typically 8 seconds).
445 * The source MAC is the native MAC address.
446 *
447 * A port keep-alive is sent every 90 seconds while logged in.
448 * The source MAC is the assigned mapped source address.
449 * The destination is the FCF's F-port.
450 */
Chris Leech11b56182009-11-03 11:46:29 -0800451static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr *fip,
452 struct fc_lport *lport,
453 int ports, u8 *sa)
Joe Eykholt97c83892009-03-17 11:42:40 -0700454{
455 struct sk_buff *skb;
456 struct fip_kal {
457 struct ethhdr eth;
458 struct fip_header fip;
459 struct fip_mac_desc mac;
460 } __attribute__((packed)) *kal;
461 struct fip_vn_desc *vn;
462 u32 len;
463 struct fc_lport *lp;
464 struct fcoe_fcf *fcf;
465
466 fcf = fip->sel_fcf;
467 lp = fip->lp;
Joe Eykholt281ae642010-06-11 16:43:33 -0700468 if (!fcf || (ports && !lp->port_id))
Joe Eykholt97c83892009-03-17 11:42:40 -0700469 return;
470
Yi Zoube276cb2009-11-03 11:50:16 -0800471 len = sizeof(*kal) + ports * sizeof(*vn);
Joe Eykholt97c83892009-03-17 11:42:40 -0700472 skb = dev_alloc_skb(len);
473 if (!skb)
474 return;
475
476 kal = (struct fip_kal *)skb->data;
477 memset(kal, 0, len);
478 memcpy(kal->eth.h_dest, fcf->fcf_mac, ETH_ALEN);
479 memcpy(kal->eth.h_source, sa, ETH_ALEN);
480 kal->eth.h_proto = htons(ETH_P_FIP);
481
482 kal->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
483 kal->fip.fip_op = htons(FIP_OP_CTRL);
484 kal->fip.fip_subcode = FIP_SC_KEEP_ALIVE;
485 kal->fip.fip_dl_len = htons((sizeof(kal->mac) +
Robert Love70b51aa2009-11-03 11:47:45 -0800486 ports * sizeof(*vn)) / FIP_BPW);
Joe Eykholt97c83892009-03-17 11:42:40 -0700487 kal->fip.fip_flags = htons(FIP_FL_FPMA);
Vasu Dev184dd342009-05-17 12:33:28 +0000488 if (fip->spma)
489 kal->fip.fip_flags |= htons(FIP_FL_SPMA);
Joe Eykholt97c83892009-03-17 11:42:40 -0700490
491 kal->mac.fd_desc.fip_dtype = FIP_DT_MAC;
492 kal->mac.fd_desc.fip_dlen = sizeof(kal->mac) / FIP_BPW;
493 memcpy(kal->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
Joe Eykholt97c83892009-03-17 11:42:40 -0700494 if (ports) {
495 vn = (struct fip_vn_desc *)(kal + 1);
496 vn->fd_desc.fip_dtype = FIP_DT_VN_ID;
497 vn->fd_desc.fip_dlen = sizeof(*vn) / FIP_BPW;
Chris Leech11b56182009-11-03 11:46:29 -0800498 memcpy(vn->fd_mac, fip->get_src_addr(lport), ETH_ALEN);
Kaladhar Musunurufb831532010-05-07 15:18:57 -0700499 hton24(vn->fd_fc_id, lport->port_id);
500 put_unaligned_be64(lport->wwpn, &vn->fd_wwpn);
Joe Eykholt97c83892009-03-17 11:42:40 -0700501 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700502 skb_put(skb, len);
Chris Leech0f491532009-05-06 10:52:18 -0700503 skb->protocol = htons(ETH_P_FIP);
Joe Eykholt97c83892009-03-17 11:42:40 -0700504 skb_reset_mac_header(skb);
505 skb_reset_network_header(skb);
506 fip->send(fip, skb);
507}
508
509/**
Robert Love70b51aa2009-11-03 11:47:45 -0800510 * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it
511 * @fip: The FCoE controller for the ELS frame
512 * @dtype: The FIP descriptor type for the frame
513 * @skb: The FCoE ELS frame including FC header but no FCoE headers
Joe Eykholte10f8c62010-07-20 15:20:30 -0700514 * @d_id: The destination port ID.
Joe Eykholt97c83892009-03-17 11:42:40 -0700515 *
516 * Returns non-zero error code on failure.
517 *
518 * The caller must check that the length is a multiple of 4.
519 *
520 * The @skb must have enough headroom (28 bytes) and tailroom (8 bytes).
521 * Headroom includes the FIP encapsulation description, FIP header, and
522 * Ethernet header. The tailroom is for the FIP MAC descriptor.
523 */
Chris Leech11b56182009-11-03 11:46:29 -0800524static int fcoe_ctlr_encaps(struct fcoe_ctlr *fip, struct fc_lport *lport,
Joe Eykholte10f8c62010-07-20 15:20:30 -0700525 u8 dtype, struct sk_buff *skb, u32 d_id)
Joe Eykholt97c83892009-03-17 11:42:40 -0700526{
527 struct fip_encaps_head {
528 struct ethhdr eth;
529 struct fip_header fip;
530 struct fip_encaps encaps;
531 } __attribute__((packed)) *cap;
Joe Eykholt55543452010-07-20 15:20:35 -0700532 struct fc_frame_header *fh;
Joe Eykholt97c83892009-03-17 11:42:40 -0700533 struct fip_mac_desc *mac;
534 struct fcoe_fcf *fcf;
535 size_t dlen;
Yi Zou5a84bae2009-07-29 17:03:55 -0700536 u16 fip_flags;
Joe Eykholt55543452010-07-20 15:20:35 -0700537 u8 op;
Joe Eykholt97c83892009-03-17 11:42:40 -0700538
Joe Eykholt55543452010-07-20 15:20:35 -0700539 fh = (struct fc_frame_header *)skb->data;
540 op = *(u8 *)(fh + 1);
Joe Eykholt97c83892009-03-17 11:42:40 -0700541 dlen = sizeof(struct fip_encaps) + skb->len; /* len before push */
542 cap = (struct fip_encaps_head *)skb_push(skb, sizeof(*cap));
Joe Eykholt97c83892009-03-17 11:42:40 -0700543 memset(cap, 0, sizeof(*cap));
Joe Eykholte10f8c62010-07-20 15:20:30 -0700544
545 if (lport->point_to_multipoint) {
546 if (fcoe_ctlr_vn_lookup(fip, d_id, cap->eth.h_dest))
547 return -ENODEV;
Joe Eykholt55543452010-07-20 15:20:35 -0700548 fip_flags = 0;
Joe Eykholte10f8c62010-07-20 15:20:30 -0700549 } else {
550 fcf = fip->sel_fcf;
551 if (!fcf)
552 return -ENODEV;
553 fip_flags = fcf->flags;
554 fip_flags &= fip->spma ? FIP_FL_SPMA | FIP_FL_FPMA :
555 FIP_FL_FPMA;
556 if (!fip_flags)
557 return -ENODEV;
558 memcpy(cap->eth.h_dest, fcf->fcf_mac, ETH_ALEN);
559 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700560 memcpy(cap->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
561 cap->eth.h_proto = htons(ETH_P_FIP);
562
563 cap->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
564 cap->fip.fip_op = htons(FIP_OP_LS);
Joe Eykholt55543452010-07-20 15:20:35 -0700565 if (op == ELS_LS_ACC || op == ELS_LS_RJT)
566 cap->fip.fip_subcode = FIP_SC_REP;
567 else
568 cap->fip.fip_subcode = FIP_SC_REQ;
Yi Zou5a84bae2009-07-29 17:03:55 -0700569 cap->fip.fip_flags = htons(fip_flags);
Joe Eykholt97c83892009-03-17 11:42:40 -0700570
571 cap->encaps.fd_desc.fip_dtype = dtype;
572 cap->encaps.fd_desc.fip_dlen = dlen / FIP_BPW;
573
Joe Eykholt55543452010-07-20 15:20:35 -0700574 if (op != ELS_LS_RJT) {
575 dlen += sizeof(*mac);
576 mac = (struct fip_mac_desc *)skb_put(skb, sizeof(*mac));
577 memset(mac, 0, sizeof(*mac));
578 mac->fd_desc.fip_dtype = FIP_DT_MAC;
579 mac->fd_desc.fip_dlen = sizeof(*mac) / FIP_BPW;
580 if (dtype != FIP_DT_FLOGI && dtype != FIP_DT_FDISC) {
581 memcpy(mac->fd_mac, fip->get_src_addr(lport), ETH_ALEN);
582 } else if (fip->mode == FIP_MODE_VN2VN) {
583 hton24(mac->fd_mac, FIP_VN_FC_MAP);
584 hton24(mac->fd_mac + 3, fip->port_id);
585 } else if (fip_flags & FIP_FL_SPMA) {
586 LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with SPMA\n");
587 memcpy(mac->fd_mac, fip->ctl_src_addr, ETH_ALEN);
588 } else {
589 LIBFCOE_FIP_DBG(fip, "FLOGI/FDISC sent with FPMA\n");
590 /* FPMA only FLOGI. Must leave the MAC desc zeroed. */
591 }
Robert Love593abc02010-04-09 14:22:17 -0700592 }
Joe Eykholt55543452010-07-20 15:20:35 -0700593 cap->fip.fip_dl_len = htons(dlen / FIP_BPW);
Joe Eykholt97c83892009-03-17 11:42:40 -0700594
Chris Leech0f491532009-05-06 10:52:18 -0700595 skb->protocol = htons(ETH_P_FIP);
Joe Eykholt97c83892009-03-17 11:42:40 -0700596 skb_reset_mac_header(skb);
597 skb_reset_network_header(skb);
598 return 0;
599}
600
601/**
602 * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate.
603 * @fip: FCoE controller.
Chris Leech11b56182009-11-03 11:46:29 -0800604 * @lport: libfc fc_lport to send from
Joe Eykholt97c83892009-03-17 11:42:40 -0700605 * @skb: FCoE ELS frame including FC header but no FCoE headers.
606 *
607 * Returns a non-zero error code if the frame should not be sent.
608 * Returns zero if the caller should send the frame with FCoE encapsulation.
609 *
610 * The caller must check that the length is a multiple of 4.
611 * The SKB must have enough headroom (28 bytes) and tailroom (8 bytes).
Joe Eykholte10f8c62010-07-20 15:20:30 -0700612 * The the skb must also be an fc_frame.
Joe Eykholt794d98e2010-11-30 16:19:56 -0800613 *
614 * This is called from the lower-level driver with spinlocks held,
615 * so we must not take a mutex here.
Joe Eykholt97c83892009-03-17 11:42:40 -0700616 */
Chris Leech11b56182009-11-03 11:46:29 -0800617int fcoe_ctlr_els_send(struct fcoe_ctlr *fip, struct fc_lport *lport,
618 struct sk_buff *skb)
Joe Eykholt97c83892009-03-17 11:42:40 -0700619{
Joe Eykholte10f8c62010-07-20 15:20:30 -0700620 struct fc_frame *fp;
Joe Eykholt97c83892009-03-17 11:42:40 -0700621 struct fc_frame_header *fh;
622 u16 old_xid;
623 u8 op;
Chris Leech11b56182009-11-03 11:46:29 -0800624 u8 mac[ETH_ALEN];
Joe Eykholt97c83892009-03-17 11:42:40 -0700625
Joe Eykholte10f8c62010-07-20 15:20:30 -0700626 fp = container_of(skb, struct fc_frame, skb);
Joe Eykholt97c83892009-03-17 11:42:40 -0700627 fh = (struct fc_frame_header *)skb->data;
628 op = *(u8 *)(fh + 1);
629
Joe Eykholte10f8c62010-07-20 15:20:30 -0700630 if (op == ELS_FLOGI && fip->mode != FIP_MODE_VN2VN) {
Joe Eykholt97c83892009-03-17 11:42:40 -0700631 old_xid = fip->flogi_oxid;
632 fip->flogi_oxid = ntohs(fh->fh_ox_id);
633 if (fip->state == FIP_ST_AUTO) {
634 if (old_xid == FC_XID_UNKNOWN)
635 fip->flogi_count = 0;
636 fip->flogi_count++;
637 if (fip->flogi_count < 3)
638 goto drop;
Joe Eykholtcd229e42010-07-20 15:20:40 -0700639 fcoe_ctlr_map_dest(fip);
Joe Eykholt97c83892009-03-17 11:42:40 -0700640 return 0;
641 }
Joe Eykholt5f48f702009-05-06 10:52:12 -0700642 if (fip->state == FIP_ST_NON_FIP)
Joe Eykholtcd229e42010-07-20 15:20:40 -0700643 fcoe_ctlr_map_dest(fip);
Joe Eykholt5f48f702009-05-06 10:52:12 -0700644 }
645
646 if (fip->state == FIP_ST_NON_FIP)
647 return 0;
Joe Eykholte10f8c62010-07-20 15:20:30 -0700648 if (!fip->sel_fcf && fip->mode != FIP_MODE_VN2VN)
Joe Eykholtf31f2a12009-11-03 11:48:32 -0800649 goto drop;
Joe Eykholt5f48f702009-05-06 10:52:12 -0700650 switch (op) {
651 case ELS_FLOGI:
Joe Eykholt97c83892009-03-17 11:42:40 -0700652 op = FIP_DT_FLOGI;
Joe Eykholt794d98e2010-11-30 16:19:56 -0800653 if (fip->mode == FIP_MODE_VN2VN)
654 break;
655 spin_lock_bh(&fip->ctlr_lock);
656 kfree_skb(fip->flogi_req);
657 fip->flogi_req = skb;
658 fip->flogi_req_send = 1;
659 spin_unlock_bh(&fip->ctlr_lock);
660 schedule_work(&fip->timer_work);
661 return -EINPROGRESS;
Joe Eykholt97c83892009-03-17 11:42:40 -0700662 case ELS_FDISC:
663 if (ntoh24(fh->fh_s_id))
664 return 0;
665 op = FIP_DT_FDISC;
666 break;
667 case ELS_LOGO:
Joe Eykholte10f8c62010-07-20 15:20:30 -0700668 if (fip->mode == FIP_MODE_VN2VN) {
669 if (fip->state != FIP_ST_VNMP_UP)
670 return -EINVAL;
671 if (ntoh24(fh->fh_d_id) == FC_FID_FLOGI)
672 return -EINVAL;
673 } else {
674 if (fip->state != FIP_ST_ENABLED)
675 return 0;
676 if (ntoh24(fh->fh_d_id) != FC_FID_FLOGI)
677 return 0;
678 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700679 op = FIP_DT_LOGO;
680 break;
681 case ELS_LS_ACC:
Joe Eykholt97c83892009-03-17 11:42:40 -0700682 /*
Joe Eykholte10f8c62010-07-20 15:20:30 -0700683 * If non-FIP, we may have gotten an SID by accepting an FLOGI
Joe Eykholt97c83892009-03-17 11:42:40 -0700684 * from a point-to-point connection. Switch to using
685 * the source mac based on the SID. The destination
686 * MAC in this case would have been set by receving the
687 * FLOGI.
688 */
Joe Eykholte10f8c62010-07-20 15:20:30 -0700689 if (fip->state == FIP_ST_NON_FIP) {
690 if (fip->flogi_oxid == FC_XID_UNKNOWN)
691 return 0;
692 fip->flogi_oxid = FC_XID_UNKNOWN;
693 fc_fcoe_set_mac(mac, fh->fh_d_id);
694 fip->update_mac(lport, mac);
695 }
696 /* fall through */
697 case ELS_LS_RJT:
698 op = fr_encaps(fp);
699 if (op)
700 break;
Joe Eykholt97c83892009-03-17 11:42:40 -0700701 return 0;
702 default:
Joe Eykholte10f8c62010-07-20 15:20:30 -0700703 if (fip->state != FIP_ST_ENABLED &&
704 fip->state != FIP_ST_VNMP_UP)
Joe Eykholt97c83892009-03-17 11:42:40 -0700705 goto drop;
706 return 0;
707 }
Joe Eykholte10f8c62010-07-20 15:20:30 -0700708 LIBFCOE_FIP_DBG(fip, "els_send op %u d_id %x\n",
709 op, ntoh24(fh->fh_d_id));
710 if (fcoe_ctlr_encaps(fip, lport, op, skb, ntoh24(fh->fh_d_id)))
Joe Eykholt97c83892009-03-17 11:42:40 -0700711 goto drop;
712 fip->send(fip, skb);
713 return -EINPROGRESS;
714drop:
715 kfree_skb(skb);
716 return -EINVAL;
717}
718EXPORT_SYMBOL(fcoe_ctlr_els_send);
719
Robert Love70b51aa2009-11-03 11:47:45 -0800720/**
721 * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller
722 * @fip: The FCoE controller to free FCFs on
Joe Eykholt97c83892009-03-17 11:42:40 -0700723 *
Joe Eykholtf018b732010-03-12 16:08:55 -0800724 * Called with lock held and preemption disabled.
Joe Eykholt97c83892009-03-17 11:42:40 -0700725 *
Joe Eykholt8690cb82010-06-11 16:44:10 -0700726 * An FCF is considered old if we have missed two advertisements.
727 * That is, there have been no valid advertisement from it for 2.5
728 * times its keep-alive period.
Joe Eykholt97c83892009-03-17 11:42:40 -0700729 *
730 * In addition, determine the time when an FCF selection can occur.
Yi Zouf3da80e2009-11-20 14:55:08 -0800731 *
732 * Also, increment the MissDiscAdvCount when no advertisement is received
733 * for the corresponding FCF for 1.5 * FKA_ADV_PERIOD (FC-BB-5 LESB).
Joe Eykholt8690cb82010-06-11 16:44:10 -0700734 *
735 * Returns the time in jiffies for the next call.
Joe Eykholt97c83892009-03-17 11:42:40 -0700736 */
Joe Eykholt8690cb82010-06-11 16:44:10 -0700737static unsigned long fcoe_ctlr_age_fcfs(struct fcoe_ctlr *fip)
Joe Eykholt97c83892009-03-17 11:42:40 -0700738{
739 struct fcoe_fcf *fcf;
740 struct fcoe_fcf *next;
Joe Eykholt8690cb82010-06-11 16:44:10 -0700741 unsigned long next_timer = jiffies + msecs_to_jiffies(FIP_VN_KA_PERIOD);
742 unsigned long deadline;
Joe Eykholt97c83892009-03-17 11:42:40 -0700743 unsigned long sel_time = 0;
Joe Eykholtf018b732010-03-12 16:08:55 -0800744 struct fcoe_dev_stats *stats;
Joe Eykholt97c83892009-03-17 11:42:40 -0700745
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700746 stats = per_cpu_ptr(fip->lp->dev_stats, get_cpu());
747
Joe Eykholt97c83892009-03-17 11:42:40 -0700748 list_for_each_entry_safe(fcf, next, &fip->fcfs, list) {
Joe Eykholt8690cb82010-06-11 16:44:10 -0700749 deadline = fcf->time + fcf->fka_period + fcf->fka_period / 2;
750 if (fip->sel_fcf == fcf) {
751 if (time_after(jiffies, deadline)) {
Joe Eykholt8690cb82010-06-11 16:44:10 -0700752 stats->MissDiscAdvCount++;
753 printk(KERN_INFO "libfcoe: host%d: "
754 "Missing Discovery Advertisement "
755 "for fab %16.16llx count %lld\n",
756 fip->lp->host->host_no, fcf->fabric_name,
757 stats->MissDiscAdvCount);
758 } else if (time_after(next_timer, deadline))
759 next_timer = deadline;
Yi Zouf3da80e2009-11-20 14:55:08 -0800760 }
Joe Eykholt8690cb82010-06-11 16:44:10 -0700761
762 deadline += fcf->fka_period;
Joe Eykholtd99ee452010-06-11 16:44:15 -0700763 if (time_after_eq(jiffies, deadline)) {
Joe Eykholt97c83892009-03-17 11:42:40 -0700764 if (fip->sel_fcf == fcf)
765 fip->sel_fcf = NULL;
766 list_del(&fcf->list);
767 WARN_ON(!fip->fcf_count);
768 fip->fcf_count--;
769 kfree(fcf);
Joe Eykholtf018b732010-03-12 16:08:55 -0800770 stats->VLinkFailureCount++;
Joe Eykholt8690cb82010-06-11 16:44:10 -0700771 } else {
772 if (time_after(next_timer, deadline))
773 next_timer = deadline;
774 if (fcoe_ctlr_mtu_valid(fcf) &&
775 (!sel_time || time_before(sel_time, fcf->time)))
776 sel_time = fcf->time;
Joe Eykholt97c83892009-03-17 11:42:40 -0700777 }
778 }
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700779 put_cpu();
Joe Eykholtd99ee452010-06-11 16:44:15 -0700780 if (sel_time && !fip->sel_fcf && !fip->sel_time) {
Joe Eykholt97c83892009-03-17 11:42:40 -0700781 sel_time += msecs_to_jiffies(FCOE_CTLR_START_DELAY);
782 fip->sel_time = sel_time;
Joe Eykholt97c83892009-03-17 11:42:40 -0700783 }
Joe Eykholtd99ee452010-06-11 16:44:15 -0700784
Joe Eykholt8690cb82010-06-11 16:44:10 -0700785 return next_timer;
Joe Eykholt97c83892009-03-17 11:42:40 -0700786}
787
788/**
Robert Love70b51aa2009-11-03 11:47:45 -0800789 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry
Joe Eykholt0f51c2e2009-11-03 11:48:16 -0800790 * @fip: The FCoE controller receiving the advertisement
Robert Love70b51aa2009-11-03 11:47:45 -0800791 * @skb: The received FIP advertisement frame
792 * @fcf: The resulting FCF entry
Joe Eykholt97c83892009-03-17 11:42:40 -0700793 *
794 * Returns zero on a valid parsed advertisement,
795 * otherwise returns non zero value.
796 */
Joe Eykholt0f51c2e2009-11-03 11:48:16 -0800797static int fcoe_ctlr_parse_adv(struct fcoe_ctlr *fip,
798 struct sk_buff *skb, struct fcoe_fcf *fcf)
Joe Eykholt97c83892009-03-17 11:42:40 -0700799{
800 struct fip_header *fiph;
801 struct fip_desc *desc = NULL;
802 struct fip_wwn_desc *wwn;
803 struct fip_fab_desc *fab;
804 struct fip_fka_desc *fka;
805 unsigned long t;
806 size_t rlen;
807 size_t dlen;
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700808 u32 desc_mask;
Joe Eykholt97c83892009-03-17 11:42:40 -0700809
810 memset(fcf, 0, sizeof(*fcf));
811 fcf->fka_period = msecs_to_jiffies(FCOE_CTLR_DEF_FKA);
812
813 fiph = (struct fip_header *)skb->data;
814 fcf->flags = ntohs(fiph->fip_flags);
815
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700816 /*
817 * mask of required descriptors. validating each one clears its bit.
818 */
819 desc_mask = BIT(FIP_DT_PRI) | BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) |
820 BIT(FIP_DT_FAB) | BIT(FIP_DT_FKA);
821
Joe Eykholt97c83892009-03-17 11:42:40 -0700822 rlen = ntohs(fiph->fip_dl_len) * 4;
823 if (rlen + sizeof(*fiph) > skb->len)
824 return -EINVAL;
825
826 desc = (struct fip_desc *)(fiph + 1);
827 while (rlen > 0) {
828 dlen = desc->fip_dlen * FIP_BPW;
829 if (dlen < sizeof(*desc) || dlen > rlen)
830 return -EINVAL;
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700831 /* Drop Adv if there are duplicate critical descriptors */
832 if ((desc->fip_dtype < 32) &&
833 !(desc_mask & 1U << desc->fip_dtype)) {
834 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
835 "Descriptors in FIP adv\n");
836 return -EINVAL;
837 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700838 switch (desc->fip_dtype) {
839 case FIP_DT_PRI:
840 if (dlen != sizeof(struct fip_pri_desc))
841 goto len_err;
842 fcf->pri = ((struct fip_pri_desc *)desc)->fd_pri;
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700843 desc_mask &= ~BIT(FIP_DT_PRI);
Joe Eykholt97c83892009-03-17 11:42:40 -0700844 break;
845 case FIP_DT_MAC:
846 if (dlen != sizeof(struct fip_mac_desc))
847 goto len_err;
848 memcpy(fcf->fcf_mac,
849 ((struct fip_mac_desc *)desc)->fd_mac,
850 ETH_ALEN);
851 if (!is_valid_ether_addr(fcf->fcf_mac)) {
Joe Eykholte10f8c62010-07-20 15:20:30 -0700852 LIBFCOE_FIP_DBG(fip,
853 "Invalid MAC addr %pM in FIP adv\n",
854 fcf->fcf_mac);
Joe Eykholt97c83892009-03-17 11:42:40 -0700855 return -EINVAL;
856 }
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700857 desc_mask &= ~BIT(FIP_DT_MAC);
Joe Eykholt97c83892009-03-17 11:42:40 -0700858 break;
859 case FIP_DT_NAME:
860 if (dlen != sizeof(struct fip_wwn_desc))
861 goto len_err;
862 wwn = (struct fip_wwn_desc *)desc;
863 fcf->switch_name = get_unaligned_be64(&wwn->fd_wwn);
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700864 desc_mask &= ~BIT(FIP_DT_NAME);
Joe Eykholt97c83892009-03-17 11:42:40 -0700865 break;
866 case FIP_DT_FAB:
867 if (dlen != sizeof(struct fip_fab_desc))
868 goto len_err;
869 fab = (struct fip_fab_desc *)desc;
870 fcf->fabric_name = get_unaligned_be64(&fab->fd_wwn);
871 fcf->vfid = ntohs(fab->fd_vfid);
872 fcf->fc_map = ntoh24(fab->fd_map);
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700873 desc_mask &= ~BIT(FIP_DT_FAB);
Joe Eykholt97c83892009-03-17 11:42:40 -0700874 break;
875 case FIP_DT_FKA:
876 if (dlen != sizeof(struct fip_fka_desc))
877 goto len_err;
878 fka = (struct fip_fka_desc *)desc;
Yi Zou8cdffdc2009-11-20 14:54:57 -0800879 if (fka->fd_flags & FIP_FKA_ADV_D)
880 fcf->fd_flags = 1;
Joe Eykholt97c83892009-03-17 11:42:40 -0700881 t = ntohl(fka->fd_fka_period);
882 if (t >= FCOE_CTLR_MIN_FKA)
883 fcf->fka_period = msecs_to_jiffies(t);
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700884 desc_mask &= ~BIT(FIP_DT_FKA);
Joe Eykholt97c83892009-03-17 11:42:40 -0700885 break;
886 case FIP_DT_MAP_OUI:
887 case FIP_DT_FCOE_SIZE:
888 case FIP_DT_FLOGI:
889 case FIP_DT_FDISC:
890 case FIP_DT_LOGO:
891 case FIP_DT_ELP:
892 default:
Joe Eykholt0f51c2e2009-11-03 11:48:16 -0800893 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
Robert Love650bd122009-06-10 15:31:05 -0700894 "in FIP adv\n", desc->fip_dtype);
Joe Eykholt97c83892009-03-17 11:42:40 -0700895 /* standard says ignore unknown descriptors >= 128 */
896 if (desc->fip_dtype < FIP_DT_VENDOR_BASE)
897 return -EINVAL;
Bhanu Prakash Gollapudi1508f3e2010-06-11 16:43:38 -0700898 break;
Joe Eykholt97c83892009-03-17 11:42:40 -0700899 }
900 desc = (struct fip_desc *)((char *)desc + dlen);
901 rlen -= dlen;
902 }
903 if (!fcf->fc_map || (fcf->fc_map & 0x10000))
904 return -EINVAL;
Vasu Dev240778e2010-07-20 15:21:33 -0700905 if (!fcf->switch_name)
Joe Eykholt97c83892009-03-17 11:42:40 -0700906 return -EINVAL;
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -0700907 if (desc_mask) {
908 LIBFCOE_FIP_DBG(fip, "adv missing descriptors mask %x\n",
909 desc_mask);
910 return -EINVAL;
911 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700912 return 0;
913
914len_err:
Joe Eykholt0f51c2e2009-11-03 11:48:16 -0800915 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
Robert Love650bd122009-06-10 15:31:05 -0700916 desc->fip_dtype, dlen);
Joe Eykholt97c83892009-03-17 11:42:40 -0700917 return -EINVAL;
918}
919
920/**
Robert Love70b51aa2009-11-03 11:47:45 -0800921 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement
922 * @fip: The FCoE controller receiving the advertisement
923 * @skb: The received FIP packet
Joe Eykholt97c83892009-03-17 11:42:40 -0700924 */
925static void fcoe_ctlr_recv_adv(struct fcoe_ctlr *fip, struct sk_buff *skb)
926{
927 struct fcoe_fcf *fcf;
928 struct fcoe_fcf new;
929 struct fcoe_fcf *found;
930 unsigned long sol_tov = msecs_to_jiffies(FCOE_CTRL_SOL_TOV);
931 int first = 0;
932 int mtu_valid;
933
Joe Eykholt0f51c2e2009-11-03 11:48:16 -0800934 if (fcoe_ctlr_parse_adv(fip, skb, &new))
Joe Eykholt97c83892009-03-17 11:42:40 -0700935 return;
936
Joe Eykholtfdb068c2010-07-20 15:19:47 -0700937 mutex_lock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -0700938 first = list_empty(&fip->fcfs);
939 found = NULL;
940 list_for_each_entry(fcf, &fip->fcfs, list) {
941 if (fcf->switch_name == new.switch_name &&
942 fcf->fabric_name == new.fabric_name &&
943 fcf->fc_map == new.fc_map &&
944 compare_ether_addr(fcf->fcf_mac, new.fcf_mac) == 0) {
945 found = fcf;
946 break;
947 }
948 }
949 if (!found) {
950 if (fip->fcf_count >= FCOE_CTLR_FCF_LIMIT)
951 goto out;
952
953 fcf = kmalloc(sizeof(*fcf), GFP_ATOMIC);
954 if (!fcf)
955 goto out;
956
957 fip->fcf_count++;
958 memcpy(fcf, &new, sizeof(new));
959 list_add(&fcf->list, &fip->fcfs);
960 } else {
961 /*
Joe Eykholtc600fea2010-06-11 16:44:20 -0700962 * Update the FCF's keep-alive descriptor flags.
963 * Other flag changes from new advertisements are
964 * ignored after a solicited advertisement is
965 * received and the FCF is selectable (usable).
Joe Eykholt97c83892009-03-17 11:42:40 -0700966 */
Joe Eykholtc600fea2010-06-11 16:44:20 -0700967 fcf->fd_flags = new.fd_flags;
968 if (!fcoe_ctlr_fcf_usable(fcf))
969 fcf->flags = new.flags;
970
Joe Eykholtd99ee452010-06-11 16:44:15 -0700971 if (fcf == fip->sel_fcf && !fcf->fd_flags) {
Joe Eykholt97c83892009-03-17 11:42:40 -0700972 fip->ctlr_ka_time -= fcf->fka_period;
973 fip->ctlr_ka_time += new.fka_period;
974 if (time_before(fip->ctlr_ka_time, fip->timer.expires))
975 mod_timer(&fip->timer, fip->ctlr_ka_time);
Joe Eykholtc600fea2010-06-11 16:44:20 -0700976 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700977 fcf->fka_period = new.fka_period;
978 memcpy(fcf->fcf_mac, new.fcf_mac, ETH_ALEN);
979 }
980 mtu_valid = fcoe_ctlr_mtu_valid(fcf);
981 fcf->time = jiffies;
Robert Love650bd122009-06-10 15:31:05 -0700982 if (!found) {
Chris Leech9f8f3aa2010-04-09 14:23:16 -0700983 LIBFCOE_FIP_DBG(fip, "New FCF for fab %16.16llx "
984 "map %x val %d\n",
Robert Love650bd122009-06-10 15:31:05 -0700985 fcf->fabric_name, fcf->fc_map, mtu_valid);
986 }
Joe Eykholt97c83892009-03-17 11:42:40 -0700987
988 /*
989 * If this advertisement is not solicited and our max receive size
990 * hasn't been verified, send a solicited advertisement.
991 */
992 if (!mtu_valid)
993 fcoe_ctlr_solicit(fip, fcf);
994
995 /*
996 * If its been a while since we did a solicit, and this is
997 * the first advertisement we've received, do a multicast
998 * solicitation to gather as many advertisements as we can
999 * before selection occurs.
1000 */
1001 if (first && time_after(jiffies, fip->sol_time + sol_tov))
1002 fcoe_ctlr_solicit(fip, NULL);
1003
1004 /*
1005 * If this is the first validated FCF, note the time and
1006 * set a timer to trigger selection.
1007 */
Joe Eykholtd99ee452010-06-11 16:44:15 -07001008 if (mtu_valid && !fip->sel_fcf && fcoe_ctlr_fcf_usable(fcf)) {
Joe Eykholt97c83892009-03-17 11:42:40 -07001009 fip->sel_time = jiffies +
Robert Love70b51aa2009-11-03 11:47:45 -08001010 msecs_to_jiffies(FCOE_CTLR_START_DELAY);
Joe Eykholt97c83892009-03-17 11:42:40 -07001011 if (!timer_pending(&fip->timer) ||
1012 time_before(fip->sel_time, fip->timer.expires))
1013 mod_timer(&fip->timer, fip->sel_time);
1014 }
1015out:
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001016 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001017}
1018
1019/**
Robert Love70b51aa2009-11-03 11:47:45 -08001020 * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame
1021 * @fip: The FCoE controller which received the packet
1022 * @skb: The received FIP packet
Joe Eykholt97c83892009-03-17 11:42:40 -07001023 */
1024static void fcoe_ctlr_recv_els(struct fcoe_ctlr *fip, struct sk_buff *skb)
1025{
Robert Love70b51aa2009-11-03 11:47:45 -08001026 struct fc_lport *lport = fip->lp;
Joe Eykholt97c83892009-03-17 11:42:40 -07001027 struct fip_header *fiph;
Chris Leech11b56182009-11-03 11:46:29 -08001028 struct fc_frame *fp = (struct fc_frame *)skb;
Joe Eykholt97c83892009-03-17 11:42:40 -07001029 struct fc_frame_header *fh = NULL;
1030 struct fip_desc *desc;
1031 struct fip_encaps *els;
1032 struct fcoe_dev_stats *stats;
1033 enum fip_desc_type els_dtype = 0;
1034 u8 els_op;
1035 u8 sub;
1036 u8 granted_mac[ETH_ALEN] = { 0 };
1037 size_t els_len = 0;
1038 size_t rlen;
1039 size_t dlen;
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001040 u32 desc_mask = 0;
1041 u32 desc_cnt = 0;
Joe Eykholt97c83892009-03-17 11:42:40 -07001042
1043 fiph = (struct fip_header *)skb->data;
1044 sub = fiph->fip_subcode;
1045 if (sub != FIP_SC_REQ && sub != FIP_SC_REP)
1046 goto drop;
1047
1048 rlen = ntohs(fiph->fip_dl_len) * 4;
1049 if (rlen + sizeof(*fiph) > skb->len)
1050 goto drop;
1051
1052 desc = (struct fip_desc *)(fiph + 1);
1053 while (rlen > 0) {
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001054 desc_cnt++;
Joe Eykholt97c83892009-03-17 11:42:40 -07001055 dlen = desc->fip_dlen * FIP_BPW;
1056 if (dlen < sizeof(*desc) || dlen > rlen)
1057 goto drop;
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -07001058 /* Drop ELS if there are duplicate critical descriptors */
1059 if (desc->fip_dtype < 32) {
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001060 if (desc_mask & 1U << desc->fip_dtype) {
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -07001061 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
1062 "Descriptors in FIP ELS\n");
1063 goto drop;
1064 }
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001065 desc_mask |= (1 << desc->fip_dtype);
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -07001066 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001067 switch (desc->fip_dtype) {
1068 case FIP_DT_MAC:
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001069 if (desc_cnt == 1) {
1070 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1071 "received out of order\n");
1072 goto drop;
1073 }
1074
Joe Eykholt97c83892009-03-17 11:42:40 -07001075 if (dlen != sizeof(struct fip_mac_desc))
1076 goto len_err;
1077 memcpy(granted_mac,
1078 ((struct fip_mac_desc *)desc)->fd_mac,
1079 ETH_ALEN);
Joe Eykholt97c83892009-03-17 11:42:40 -07001080 break;
1081 case FIP_DT_FLOGI:
1082 case FIP_DT_FDISC:
1083 case FIP_DT_LOGO:
1084 case FIP_DT_ELP:
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001085 if (desc_cnt != 1) {
1086 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1087 "received out of order\n");
1088 goto drop;
1089 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001090 if (fh)
1091 goto drop;
1092 if (dlen < sizeof(*els) + sizeof(*fh) + 1)
1093 goto len_err;
1094 els_len = dlen - sizeof(*els);
1095 els = (struct fip_encaps *)desc;
1096 fh = (struct fc_frame_header *)(els + 1);
1097 els_dtype = desc->fip_dtype;
1098 break;
1099 default:
Joe Eykholt0f51c2e2009-11-03 11:48:16 -08001100 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
Robert Love650bd122009-06-10 15:31:05 -07001101 "in FIP adv\n", desc->fip_dtype);
Joe Eykholt97c83892009-03-17 11:42:40 -07001102 /* standard says ignore unknown descriptors >= 128 */
1103 if (desc->fip_dtype < FIP_DT_VENDOR_BASE)
1104 goto drop;
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001105 if (desc_cnt <= 2) {
1106 LIBFCOE_FIP_DBG(fip, "FIP descriptors "
1107 "received out of order\n");
1108 goto drop;
1109 }
Bhanu Prakash Gollapudi1508f3e2010-06-11 16:43:38 -07001110 break;
Joe Eykholt97c83892009-03-17 11:42:40 -07001111 }
1112 desc = (struct fip_desc *)((char *)desc + dlen);
1113 rlen -= dlen;
1114 }
1115
1116 if (!fh)
1117 goto drop;
1118 els_op = *(u8 *)(fh + 1);
1119
Joe Eykholte10f8c62010-07-20 15:20:30 -07001120 if ((els_dtype == FIP_DT_FLOGI || els_dtype == FIP_DT_FDISC) &&
Joe Eykholt794d98e2010-11-30 16:19:56 -08001121 sub == FIP_SC_REP && fip->mode != FIP_MODE_VN2VN) {
1122 if (els_op == ELS_LS_ACC) {
1123 if (!is_valid_ether_addr(granted_mac)) {
1124 LIBFCOE_FIP_DBG(fip,
1125 "Invalid MAC address %pM in FIP ELS\n",
1126 granted_mac);
1127 goto drop;
1128 }
1129 memcpy(fr_cb(fp)->granted_mac, granted_mac, ETH_ALEN);
Joe Eykholte10f8c62010-07-20 15:20:30 -07001130
Joe Eykholt794d98e2010-11-30 16:19:56 -08001131 if (fip->flogi_oxid == ntohs(fh->fh_ox_id)) {
1132 fip->flogi_oxid = FC_XID_UNKNOWN;
1133 if (els_dtype == FIP_DT_FLOGI)
1134 fcoe_ctlr_announce(fip);
1135 }
1136 } else if (els_dtype == FIP_DT_FLOGI &&
1137 !fcoe_ctlr_flogi_retry(fip))
1138 goto drop; /* retrying FLOGI so drop reject */
Joe Eykholte10f8c62010-07-20 15:20:30 -07001139 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001140
Bhanu Prakash Gollapudibe613312010-06-11 16:44:36 -07001141 if ((desc_cnt == 0) || ((els_op != ELS_LS_RJT) &&
1142 (!(1U << FIP_DT_MAC & desc_mask)))) {
1143 LIBFCOE_FIP_DBG(fip, "Missing critical descriptors "
1144 "in FIP ELS\n");
1145 goto drop;
1146 }
1147
Joe Eykholt97c83892009-03-17 11:42:40 -07001148 /*
1149 * Convert skb into an fc_frame containing only the ELS.
1150 */
1151 skb_pull(skb, (u8 *)fh - skb->data);
1152 skb_trim(skb, els_len);
1153 fp = (struct fc_frame *)skb;
1154 fc_frame_init(fp);
1155 fr_sof(fp) = FC_SOF_I3;
1156 fr_eof(fp) = FC_EOF_T;
Robert Love70b51aa2009-11-03 11:47:45 -08001157 fr_dev(fp) = lport;
Joe Eykholte10f8c62010-07-20 15:20:30 -07001158 fr_encaps(fp) = els_dtype;
Joe Eykholt97c83892009-03-17 11:42:40 -07001159
Joe Eykholtf018b732010-03-12 16:08:55 -08001160 stats = per_cpu_ptr(lport->dev_stats, get_cpu());
Joe Eykholt97c83892009-03-17 11:42:40 -07001161 stats->RxFrames++;
1162 stats->RxWords += skb->len / FIP_BPW;
Joe Eykholtf018b732010-03-12 16:08:55 -08001163 put_cpu();
Joe Eykholt97c83892009-03-17 11:42:40 -07001164
Robert Love70b51aa2009-11-03 11:47:45 -08001165 fc_exch_recv(lport, fp);
Joe Eykholt97c83892009-03-17 11:42:40 -07001166 return;
1167
1168len_err:
Joe Eykholt0f51c2e2009-11-03 11:48:16 -08001169 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
Robert Love650bd122009-06-10 15:31:05 -07001170 desc->fip_dtype, dlen);
Joe Eykholt97c83892009-03-17 11:42:40 -07001171drop:
1172 kfree_skb(skb);
1173}
1174
1175/**
Robert Love70b51aa2009-11-03 11:47:45 -08001176 * fcoe_ctlr_recv_els() - Handle an incoming link reset frame
1177 * @fip: The FCoE controller that received the frame
1178 * @fh: The received FIP header
Joe Eykholt97c83892009-03-17 11:42:40 -07001179 *
1180 * There may be multiple VN_Port descriptors.
1181 * The overall length has already been checked.
1182 */
1183static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr *fip,
Robert Love70b51aa2009-11-03 11:47:45 -08001184 struct fip_header *fh)
Joe Eykholt97c83892009-03-17 11:42:40 -07001185{
1186 struct fip_desc *desc;
1187 struct fip_mac_desc *mp;
1188 struct fip_wwn_desc *wp;
1189 struct fip_vn_desc *vp;
1190 size_t rlen;
1191 size_t dlen;
1192 struct fcoe_fcf *fcf = fip->sel_fcf;
Robert Love70b51aa2009-11-03 11:47:45 -08001193 struct fc_lport *lport = fip->lp;
Bhanu Prakash Gollapudi5550fda2010-06-11 16:44:31 -07001194 struct fc_lport *vn_port = NULL;
1195 u32 desc_mask;
1196 int is_vn_port = 0;
Joe Eykholt97c83892009-03-17 11:42:40 -07001197
Joe Eykholt0f51c2e2009-11-03 11:48:16 -08001198 LIBFCOE_FIP_DBG(fip, "Clear Virtual Link received\n");
Robert Loved29510a2010-05-07 15:18:30 -07001199
Robert Love7b2787e2010-05-07 15:18:41 -07001200 if (!fcf || !lport->port_id)
Joe Eykholt97c83892009-03-17 11:42:40 -07001201 return;
1202
1203 /*
1204 * mask of required descriptors. Validating each one clears its bit.
1205 */
1206 desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) | BIT(FIP_DT_VN_ID);
1207
1208 rlen = ntohs(fh->fip_dl_len) * FIP_BPW;
1209 desc = (struct fip_desc *)(fh + 1);
1210 while (rlen >= sizeof(*desc)) {
1211 dlen = desc->fip_dlen * FIP_BPW;
1212 if (dlen > rlen)
1213 return;
Bhanu Prakash Gollapudi0a9c5d32010-06-11 16:44:25 -07001214 /* Drop CVL if there are duplicate critical descriptors */
1215 if ((desc->fip_dtype < 32) &&
1216 !(desc_mask & 1U << desc->fip_dtype)) {
1217 LIBFCOE_FIP_DBG(fip, "Duplicate Critical "
1218 "Descriptors in FIP CVL\n");
1219 return;
1220 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001221 switch (desc->fip_dtype) {
1222 case FIP_DT_MAC:
1223 mp = (struct fip_mac_desc *)desc;
1224 if (dlen < sizeof(*mp))
1225 return;
1226 if (compare_ether_addr(mp->fd_mac, fcf->fcf_mac))
1227 return;
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))
1233 return;
1234 if (get_unaligned_be64(&wp->fd_wwn) != fcf->switch_name)
1235 return;
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))
1241 return;
1242 if (compare_ether_addr(vp->fd_mac,
Robert Love70b51aa2009-11-03 11:47:45 -08001243 fip->get_src_addr(lport)) == 0 &&
1244 get_unaligned_be64(&vp->fd_wwpn) == lport->wwpn &&
Bhanu Prakash Gollapudi5550fda2010-06-11 16:44:31 -07001245 ntoh24(vp->fd_fc_id) == lport->port_id) {
Joe Eykholt97c83892009-03-17 11:42:40 -07001246 desc_mask &= ~BIT(FIP_DT_VN_ID);
Bhanu Prakash Gollapudi5550fda2010-06-11 16:44:31 -07001247 break;
1248 }
1249 /* check if clr_vlink is for NPIV port */
1250 mutex_lock(&lport->lp_mutex);
1251 list_for_each_entry(vn_port, &lport->vports, list) {
1252 if (compare_ether_addr(vp->fd_mac,
1253 fip->get_src_addr(vn_port)) == 0 &&
1254 (get_unaligned_be64(&vp->fd_wwpn)
1255 == vn_port->wwpn) &&
1256 (ntoh24(vp->fd_fc_id) ==
1257 fc_host_port_id(vn_port->host))) {
1258 desc_mask &= ~BIT(FIP_DT_VN_ID);
1259 is_vn_port = 1;
1260 break;
1261 }
1262 }
1263 mutex_unlock(&lport->lp_mutex);
1264
Joe Eykholt97c83892009-03-17 11:42:40 -07001265 break;
1266 default:
1267 /* standard says ignore unknown descriptors >= 128 */
1268 if (desc->fip_dtype < FIP_DT_VENDOR_BASE)
1269 return;
1270 break;
1271 }
1272 desc = (struct fip_desc *)((char *)desc + dlen);
1273 rlen -= dlen;
1274 }
1275
1276 /*
1277 * reset only if all required descriptors were present and valid.
1278 */
1279 if (desc_mask) {
Joe Eykholt0f51c2e2009-11-03 11:48:16 -08001280 LIBFCOE_FIP_DBG(fip, "missing descriptors mask %x\n",
1281 desc_mask);
Joe Eykholt97c83892009-03-17 11:42:40 -07001282 } else {
Joe Eykholt0f51c2e2009-11-03 11:48:16 -08001283 LIBFCOE_FIP_DBG(fip, "performing Clear Virtual Link\n");
Joe Eykholtdd42dac2009-11-03 11:48:27 -08001284
Bhanu Prakash Gollapudi5550fda2010-06-11 16:44:31 -07001285 if (is_vn_port)
1286 fc_lport_reset(vn_port);
1287 else {
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001288 mutex_lock(&fip->ctlr_mutex);
Bhanu Prakash Gollapudi5550fda2010-06-11 16:44:31 -07001289 per_cpu_ptr(lport->dev_stats,
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001290 get_cpu())->VLinkFailureCount++;
1291 put_cpu();
Bhanu Prakash Gollapudi5550fda2010-06-11 16:44:31 -07001292 fcoe_ctlr_reset(fip);
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001293 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholtdd42dac2009-11-03 11:48:27 -08001294
Bhanu Prakash Gollapudi5550fda2010-06-11 16:44:31 -07001295 fc_lport_reset(fip->lp);
1296 fcoe_ctlr_solicit(fip, NULL);
1297 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001298 }
1299}
1300
1301/**
Robert Love70b51aa2009-11-03 11:47:45 -08001302 * fcoe_ctlr_recv() - Receive a FIP packet
1303 * @fip: The FCoE controller that received the packet
1304 * @skb: The received FIP packet
Joe Eykholt97c83892009-03-17 11:42:40 -07001305 *
Joe Eykholt1f4aed82009-11-03 11:48:22 -08001306 * This may be called from either NET_RX_SOFTIRQ or IRQ.
Joe Eykholt97c83892009-03-17 11:42:40 -07001307 */
1308void fcoe_ctlr_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
1309{
Joe Eykholt1f4aed82009-11-03 11:48:22 -08001310 skb_queue_tail(&fip->fip_recv_list, skb);
Joe Eykholt97c83892009-03-17 11:42:40 -07001311 schedule_work(&fip->recv_work);
1312}
1313EXPORT_SYMBOL(fcoe_ctlr_recv);
1314
1315/**
Robert Love70b51aa2009-11-03 11:47:45 -08001316 * fcoe_ctlr_recv_handler() - Receive a FIP frame
1317 * @fip: The FCoE controller that received the frame
1318 * @skb: The received FIP frame
Joe Eykholt97c83892009-03-17 11:42:40 -07001319 *
1320 * Returns non-zero if the frame is dropped.
1321 */
1322static int fcoe_ctlr_recv_handler(struct fcoe_ctlr *fip, struct sk_buff *skb)
1323{
1324 struct fip_header *fiph;
1325 struct ethhdr *eh;
1326 enum fip_state state;
1327 u16 op;
1328 u8 sub;
1329
1330 if (skb_linearize(skb))
1331 goto drop;
1332 if (skb->len < sizeof(*fiph))
1333 goto drop;
1334 eh = eth_hdr(skb);
Joe Eykholte10f8c62010-07-20 15:20:30 -07001335 if (fip->mode == FIP_MODE_VN2VN) {
1336 if (compare_ether_addr(eh->h_dest, fip->ctl_src_addr) &&
1337 compare_ether_addr(eh->h_dest, fcoe_all_vn2vn) &&
1338 compare_ether_addr(eh->h_dest, fcoe_all_p2p))
1339 goto drop;
1340 } else if (compare_ether_addr(eh->h_dest, fip->ctl_src_addr) &&
1341 compare_ether_addr(eh->h_dest, fcoe_all_enode))
Joe Eykholt97c83892009-03-17 11:42:40 -07001342 goto drop;
1343 fiph = (struct fip_header *)skb->data;
1344 op = ntohs(fiph->fip_op);
1345 sub = fiph->fip_subcode;
1346
Joe Eykholt97c83892009-03-17 11:42:40 -07001347 if (FIP_VER_DECAPS(fiph->fip_ver) != FIP_VER)
1348 goto drop;
1349 if (ntohs(fiph->fip_dl_len) * FIP_BPW + sizeof(*fiph) > skb->len)
1350 goto drop;
1351
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001352 mutex_lock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001353 state = fip->state;
1354 if (state == FIP_ST_AUTO) {
1355 fip->map_dest = 0;
Joe Eykholt9b651da2010-07-20 15:20:24 -07001356 fcoe_ctlr_set_state(fip, FIP_ST_ENABLED);
Joe Eykholt97c83892009-03-17 11:42:40 -07001357 state = FIP_ST_ENABLED;
Joe Eykholt0f51c2e2009-11-03 11:48:16 -08001358 LIBFCOE_FIP_DBG(fip, "Using FIP mode\n");
Joe Eykholt97c83892009-03-17 11:42:40 -07001359 }
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001360 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholte10f8c62010-07-20 15:20:30 -07001361
1362 if (fip->mode == FIP_MODE_VN2VN && op == FIP_OP_VN2VN)
1363 return fcoe_ctlr_vn_recv(fip, skb);
1364
1365 if (state != FIP_ST_ENABLED && state != FIP_ST_VNMP_UP &&
1366 state != FIP_ST_VNMP_CLAIM)
Joe Eykholt97c83892009-03-17 11:42:40 -07001367 goto drop;
1368
1369 if (op == FIP_OP_LS) {
1370 fcoe_ctlr_recv_els(fip, skb); /* consumes skb */
1371 return 0;
1372 }
Joe Eykholte10f8c62010-07-20 15:20:30 -07001373
1374 if (state != FIP_ST_ENABLED)
1375 goto drop;
1376
Joe Eykholt97c83892009-03-17 11:42:40 -07001377 if (op == FIP_OP_DISC && sub == FIP_SC_ADV)
1378 fcoe_ctlr_recv_adv(fip, skb);
1379 else if (op == FIP_OP_CTRL && sub == FIP_SC_CLR_VLINK)
1380 fcoe_ctlr_recv_clr_vlink(fip, fiph);
1381 kfree_skb(skb);
1382 return 0;
1383drop:
1384 kfree_skb(skb);
1385 return -1;
1386}
1387
1388/**
Robert Love70b51aa2009-11-03 11:47:45 -08001389 * fcoe_ctlr_select() - Select the best FCF (if possible)
1390 * @fip: The FCoE controller
Joe Eykholt97c83892009-03-17 11:42:40 -07001391 *
1392 * If there are conflicting advertisements, no FCF can be chosen.
1393 *
Joe Eykholt794d98e2010-11-30 16:19:56 -08001394 * If there is already a selected FCF, this will choose a better one or
1395 * an equivalent one that hasn't already been sent a FLOGI.
1396 *
Joe Eykholt97c83892009-03-17 11:42:40 -07001397 * Called with lock held.
1398 */
1399static void fcoe_ctlr_select(struct fcoe_ctlr *fip)
1400{
1401 struct fcoe_fcf *fcf;
Joe Eykholt794d98e2010-11-30 16:19:56 -08001402 struct fcoe_fcf *best = fip->sel_fcf;
Joe Eykholtb69ae0a2010-11-30 16:19:51 -08001403 struct fcoe_fcf *first;
1404
1405 first = list_first_entry(&fip->fcfs, struct fcoe_fcf, list);
Joe Eykholt97c83892009-03-17 11:42:40 -07001406
1407 list_for_each_entry(fcf, &fip->fcfs, list) {
Chris Leech9f8f3aa2010-04-09 14:23:16 -07001408 LIBFCOE_FIP_DBG(fip, "consider FCF for fab %16.16llx "
1409 "VFID %d map %x val %d\n",
1410 fcf->fabric_name, fcf->vfid,
Robert Love650bd122009-06-10 15:31:05 -07001411 fcf->fc_map, fcoe_ctlr_mtu_valid(fcf));
Joe Eykholtb69ae0a2010-11-30 16:19:51 -08001412 if (fcf->fabric_name != first->fabric_name ||
1413 fcf->vfid != first->vfid ||
1414 fcf->fc_map != first->fc_map) {
1415 LIBFCOE_FIP_DBG(fip, "Conflicting fabric, VFID, "
1416 "or FC-MAP\n");
1417 return NULL;
1418 }
Joe Eykholt794d98e2010-11-30 16:19:56 -08001419 if (fcf->flogi_sent)
1420 continue;
Joe Eykholt97c83892009-03-17 11:42:40 -07001421 if (!fcoe_ctlr_fcf_usable(fcf)) {
Chris Leech9f8f3aa2010-04-09 14:23:16 -07001422 LIBFCOE_FIP_DBG(fip, "FCF for fab %16.16llx "
1423 "map %x %svalid %savailable\n",
1424 fcf->fabric_name, fcf->fc_map,
1425 (fcf->flags & FIP_FL_SOL) ? "" : "in",
1426 (fcf->flags & FIP_FL_AVAIL) ?
1427 "" : "un");
Joe Eykholt97c83892009-03-17 11:42:40 -07001428 continue;
1429 }
Joe Eykholt794d98e2010-11-30 16:19:56 -08001430 if (!best || fcf->pri < best->pri || best->flogi_sent)
Joe Eykholt97c83892009-03-17 11:42:40 -07001431 best = fcf;
1432 }
1433 fip->sel_fcf = best;
Joe Eykholtc47036a2010-11-30 16:19:46 -08001434 if (best) {
1435 fip->port_ka_time = jiffies +
1436 msecs_to_jiffies(FIP_VN_KA_PERIOD);
1437 fip->ctlr_ka_time = jiffies + best->fka_period;
1438 if (time_before(fip->ctlr_ka_time, fip->timer.expires))
1439 mod_timer(&fip->timer, fip->ctlr_ka_time);
1440 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001441}
1442
1443/**
Joe Eykholt794d98e2010-11-30 16:19:56 -08001444 * fcoe_ctlr_flogi_send_locked() - send FIP-encapsulated FLOGI to current FCF
1445 * @fip: The FCoE controller
1446 *
1447 * Returns non-zero error if it could not be sent.
1448 *
1449 * Called with ctlr_mutex and ctlr_lock held.
1450 * Caller must verify that fip->sel_fcf is not NULL.
1451 */
1452static int fcoe_ctlr_flogi_send_locked(struct fcoe_ctlr *fip)
1453{
1454 struct sk_buff *skb;
1455 struct sk_buff *skb_orig;
1456 struct fc_frame_header *fh;
1457 int error;
1458
1459 skb_orig = fip->flogi_req;
1460 if (!skb_orig)
1461 return -EINVAL;
1462
1463 /*
1464 * Clone and send the FLOGI request. If clone fails, use original.
1465 */
1466 skb = skb_clone(skb_orig, GFP_ATOMIC);
1467 if (!skb) {
1468 skb = skb_orig;
1469 fip->flogi_req = NULL;
1470 }
1471 fh = (struct fc_frame_header *)skb->data;
1472 error = fcoe_ctlr_encaps(fip, fip->lp, FIP_DT_FLOGI, skb,
1473 ntoh24(fh->fh_d_id));
1474 if (error) {
1475 kfree_skb(skb);
1476 return error;
1477 }
1478 fip->send(fip, skb);
1479 fip->sel_fcf->flogi_sent = 1;
1480 return 0;
1481}
1482
1483/**
1484 * fcoe_ctlr_flogi_retry() - resend FLOGI request to a new FCF if possible
1485 * @fip: The FCoE controller
1486 *
1487 * Returns non-zero error code if there's no FLOGI request to retry or
1488 * no alternate FCF available.
1489 */
1490static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr *fip)
1491{
1492 struct fcoe_fcf *fcf;
1493 int error;
1494
1495 mutex_lock(&fip->ctlr_mutex);
1496 spin_lock_bh(&fip->ctlr_lock);
1497 LIBFCOE_FIP_DBG(fip, "re-sending FLOGI - reselect\n");
1498 fcoe_ctlr_select(fip);
1499 fcf = fip->sel_fcf;
1500 if (!fcf || fcf->flogi_sent) {
1501 kfree_skb(fip->flogi_req);
1502 fip->flogi_req = NULL;
1503 error = -ENOENT;
1504 } else {
1505 fcoe_ctlr_solicit(fip, NULL);
1506 error = fcoe_ctlr_flogi_send_locked(fip);
1507 }
1508 spin_unlock_bh(&fip->ctlr_lock);
1509 mutex_unlock(&fip->ctlr_mutex);
1510 return error;
1511}
1512
1513
1514/**
1515 * fcoe_ctlr_flogi_send() - Handle sending of FIP FLOGI.
1516 * @fip: The FCoE controller that timed out
1517 *
1518 * Done here because fcoe_ctlr_els_send() can't get mutex.
1519 *
1520 * Called with ctlr_mutex held. The caller must not hold ctlr_lock.
1521 */
1522static void fcoe_ctlr_flogi_send(struct fcoe_ctlr *fip)
1523{
1524 struct fcoe_fcf *fcf;
1525
1526 spin_lock_bh(&fip->ctlr_lock);
1527 fcf = fip->sel_fcf;
1528 if (!fcf || !fip->flogi_req_send)
1529 goto unlock;
1530
1531 LIBFCOE_FIP_DBG(fip, "sending FLOGI\n");
1532
1533 /*
1534 * If this FLOGI is being sent due to a timeout retry
1535 * to the same FCF as before, select a different FCF if possible.
1536 */
1537 if (fcf->flogi_sent) {
1538 LIBFCOE_FIP_DBG(fip, "sending FLOGI - reselect\n");
1539 fcoe_ctlr_select(fip);
1540 fcf = fip->sel_fcf;
1541 if (!fcf || fcf->flogi_sent) {
1542 LIBFCOE_FIP_DBG(fip, "sending FLOGI - clearing\n");
1543 list_for_each_entry(fcf, &fip->fcfs, list)
1544 fcf->flogi_sent = 0;
1545 fcoe_ctlr_select(fip);
1546 fcf = fip->sel_fcf;
1547 }
1548 }
1549 if (fcf) {
1550 fcoe_ctlr_flogi_send_locked(fip);
1551 fip->flogi_req_send = 0;
1552 } else /* XXX */
1553 LIBFCOE_FIP_DBG(fip, "No FCF selected - defer send\n");
1554unlock:
1555 spin_unlock_bh(&fip->ctlr_lock);
1556}
1557
1558/**
Robert Love70b51aa2009-11-03 11:47:45 -08001559 * fcoe_ctlr_timeout() - FIP timeout handler
1560 * @arg: The FCoE controller that timed out
Joe Eykholt97c83892009-03-17 11:42:40 -07001561 */
1562static void fcoe_ctlr_timeout(unsigned long arg)
1563{
1564 struct fcoe_ctlr *fip = (struct fcoe_ctlr *)arg;
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001565
1566 schedule_work(&fip->timer_work);
1567}
1568
1569/**
1570 * fcoe_ctlr_timer_work() - Worker thread function for timer work
1571 * @work: Handle to a FCoE controller
1572 *
1573 * Ages FCFs. Triggers FCF selection if possible.
1574 * Sends keep-alives and resets.
1575 */
1576static void fcoe_ctlr_timer_work(struct work_struct *work)
1577{
1578 struct fcoe_ctlr *fip;
1579 struct fc_lport *vport;
1580 u8 *mac;
1581 u8 reset = 0;
1582 u8 send_ctlr_ka = 0;
1583 u8 send_port_ka = 0;
Joe Eykholt97c83892009-03-17 11:42:40 -07001584 struct fcoe_fcf *sel;
1585 struct fcoe_fcf *fcf;
Joe Eykholt8690cb82010-06-11 16:44:10 -07001586 unsigned long next_timer;
Joe Eykholt97c83892009-03-17 11:42:40 -07001587
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001588 fip = container_of(work, struct fcoe_ctlr, timer_work);
Joe Eykholte10f8c62010-07-20 15:20:30 -07001589 if (fip->mode == FIP_MODE_VN2VN)
1590 return fcoe_ctlr_vn_timeout(fip);
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001591 mutex_lock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001592 if (fip->state == FIP_ST_DISABLED) {
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001593 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001594 return;
1595 }
1596
1597 fcf = fip->sel_fcf;
Joe Eykholt8690cb82010-06-11 16:44:10 -07001598 next_timer = fcoe_ctlr_age_fcfs(fip);
Joe Eykholt97c83892009-03-17 11:42:40 -07001599
1600 sel = fip->sel_fcf;
Joe Eykholt8690cb82010-06-11 16:44:10 -07001601 if (!sel && fip->sel_time) {
1602 if (time_after_eq(jiffies, fip->sel_time)) {
1603 fcoe_ctlr_select(fip);
1604 sel = fip->sel_fcf;
1605 fip->sel_time = 0;
1606 } else if (time_after(next_timer, fip->sel_time))
1607 next_timer = fip->sel_time;
Joe Eykholt97c83892009-03-17 11:42:40 -07001608 }
1609
Joe Eykholt794d98e2010-11-30 16:19:56 -08001610 if (sel && fip->flogi_req_send)
1611 fcoe_ctlr_flogi_send(fip);
1612 else if (!sel && fcf)
1613 reset = 1;
Joe Eykholt97c83892009-03-17 11:42:40 -07001614
Yi Zou8cdffdc2009-11-20 14:54:57 -08001615 if (sel && !sel->fd_flags) {
Joe Eykholt97c83892009-03-17 11:42:40 -07001616 if (time_after_eq(jiffies, fip->ctlr_ka_time)) {
1617 fip->ctlr_ka_time = jiffies + sel->fka_period;
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001618 send_ctlr_ka = 1;
Joe Eykholt97c83892009-03-17 11:42:40 -07001619 }
1620 if (time_after(next_timer, fip->ctlr_ka_time))
1621 next_timer = fip->ctlr_ka_time;
1622
1623 if (time_after_eq(jiffies, fip->port_ka_time)) {
Bhanu Prakash Gollapudif47dd852010-01-21 10:16:00 -08001624 fip->port_ka_time = jiffies +
Robert Love70b51aa2009-11-03 11:47:45 -08001625 msecs_to_jiffies(FIP_VN_KA_PERIOD);
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001626 send_port_ka = 1;
Joe Eykholt97c83892009-03-17 11:42:40 -07001627 }
1628 if (time_after(next_timer, fip->port_ka_time))
1629 next_timer = fip->port_ka_time;
Joe Eykholt97c83892009-03-17 11:42:40 -07001630 }
Joe Eykholt8690cb82010-06-11 16:44:10 -07001631 if (!list_empty(&fip->fcfs))
1632 mod_timer(&fip->timer, next_timer);
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001633 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001634
Bhanu Prakash Gollapudi516a6482010-06-11 16:43:44 -07001635 if (reset) {
Joe Eykholtdd42dac2009-11-03 11:48:27 -08001636 fc_lport_reset(fip->lp);
Bhanu Prakash Gollapudi516a6482010-06-11 16:43:44 -07001637 /* restart things with a solicitation */
1638 fcoe_ctlr_solicit(fip, NULL);
1639 }
Chris Leech11b56182009-11-03 11:46:29 -08001640
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001641 if (send_ctlr_ka)
Chris Leech11b56182009-11-03 11:46:29 -08001642 fcoe_ctlr_send_keep_alive(fip, NULL, 0, fip->ctl_src_addr);
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001643
1644 if (send_port_ka) {
Chris Leech11b56182009-11-03 11:46:29 -08001645 mutex_lock(&fip->lp->lp_mutex);
1646 mac = fip->get_src_addr(fip->lp);
1647 fcoe_ctlr_send_keep_alive(fip, fip->lp, 1, mac);
1648 list_for_each_entry(vport, &fip->lp->vports, list) {
1649 mac = fip->get_src_addr(vport);
1650 fcoe_ctlr_send_keep_alive(fip, vport, 1, mac);
1651 }
1652 mutex_unlock(&fip->lp->lp_mutex);
1653 }
Joe Eykholt97c83892009-03-17 11:42:40 -07001654}
1655
1656/**
Robert Love70b51aa2009-11-03 11:47:45 -08001657 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames
1658 * @recv_work: Handle to a FCoE controller
Joe Eykholt97c83892009-03-17 11:42:40 -07001659 */
1660static void fcoe_ctlr_recv_work(struct work_struct *recv_work)
1661{
1662 struct fcoe_ctlr *fip;
1663 struct sk_buff *skb;
1664
1665 fip = container_of(recv_work, struct fcoe_ctlr, recv_work);
Joe Eykholt1f4aed82009-11-03 11:48:22 -08001666 while ((skb = skb_dequeue(&fip->fip_recv_list)))
Joe Eykholt97c83892009-03-17 11:42:40 -07001667 fcoe_ctlr_recv_handler(fip, skb);
Joe Eykholt97c83892009-03-17 11:42:40 -07001668}
1669
1670/**
Joe Eykholt386309c2009-11-03 11:49:16 -08001671 * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response
Robert Love70b51aa2009-11-03 11:47:45 -08001672 * @fip: The FCoE controller
1673 * @fp: The FC frame to snoop
Joe Eykholt97c83892009-03-17 11:42:40 -07001674 *
1675 * Snoop potential response to FLOGI or even incoming FLOGI.
1676 *
1677 * The caller has checked that we are waiting for login as indicated
1678 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1679 *
1680 * The caller is responsible for freeing the frame.
Joe Eykholt386309c2009-11-03 11:49:16 -08001681 * Fill in the granted_mac address.
Joe Eykholt97c83892009-03-17 11:42:40 -07001682 *
1683 * Return non-zero if the frame should not be delivered to libfc.
1684 */
Chris Leech11b56182009-11-03 11:46:29 -08001685int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *fip, struct fc_lport *lport,
Joe Eykholt386309c2009-11-03 11:49:16 -08001686 struct fc_frame *fp)
Joe Eykholt97c83892009-03-17 11:42:40 -07001687{
1688 struct fc_frame_header *fh;
1689 u8 op;
Joe Eykholt386309c2009-11-03 11:49:16 -08001690 u8 *sa;
Joe Eykholt97c83892009-03-17 11:42:40 -07001691
Joe Eykholt386309c2009-11-03 11:49:16 -08001692 sa = eth_hdr(&fp->skb)->h_source;
Joe Eykholt97c83892009-03-17 11:42:40 -07001693 fh = fc_frame_header_get(fp);
1694 if (fh->fh_type != FC_TYPE_ELS)
1695 return 0;
1696
1697 op = fc_frame_payload_op(fp);
1698 if (op == ELS_LS_ACC && fh->fh_r_ctl == FC_RCTL_ELS_REP &&
1699 fip->flogi_oxid == ntohs(fh->fh_ox_id)) {
1700
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001701 mutex_lock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001702 if (fip->state != FIP_ST_AUTO && fip->state != FIP_ST_NON_FIP) {
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001703 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001704 return -EINVAL;
1705 }
Joe Eykholt9b651da2010-07-20 15:20:24 -07001706 fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP);
Joe Eykholt0f51c2e2009-11-03 11:48:16 -08001707 LIBFCOE_FIP_DBG(fip,
1708 "received FLOGI LS_ACC using non-FIP mode\n");
Joe Eykholt97c83892009-03-17 11:42:40 -07001709
1710 /*
1711 * FLOGI accepted.
1712 * If the src mac addr is FC_OUI-based, then we mark the
1713 * address_mode flag to use FC_OUI-based Ethernet DA.
1714 * Otherwise we use the FCoE gateway addr
1715 */
1716 if (!compare_ether_addr(sa, (u8[6])FC_FCOE_FLOGI_MAC)) {
Joe Eykholtcd229e42010-07-20 15:20:40 -07001717 fcoe_ctlr_map_dest(fip);
Joe Eykholt97c83892009-03-17 11:42:40 -07001718 } else {
1719 memcpy(fip->dest_addr, sa, ETH_ALEN);
1720 fip->map_dest = 0;
1721 }
1722 fip->flogi_oxid = FC_XID_UNKNOWN;
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001723 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt386309c2009-11-03 11:49:16 -08001724 fc_fcoe_set_mac(fr_cb(fp)->granted_mac, fh->fh_d_id);
Joe Eykholt97c83892009-03-17 11:42:40 -07001725 } else if (op == ELS_FLOGI && fh->fh_r_ctl == FC_RCTL_ELS_REQ && sa) {
1726 /*
1727 * Save source MAC for point-to-point responses.
1728 */
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001729 mutex_lock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001730 if (fip->state == FIP_ST_AUTO || fip->state == FIP_ST_NON_FIP) {
1731 memcpy(fip->dest_addr, sa, ETH_ALEN);
1732 fip->map_dest = 0;
Joe Eykholte49bf612010-03-12 16:07:57 -08001733 if (fip->state == FIP_ST_AUTO)
1734 LIBFCOE_FIP_DBG(fip, "received non-FIP FLOGI. "
1735 "Setting non-FIP mode\n");
Joe Eykholt9b651da2010-07-20 15:20:24 -07001736 fcoe_ctlr_set_state(fip, FIP_ST_NON_FIP);
Joe Eykholt97c83892009-03-17 11:42:40 -07001737 }
Joe Eykholtfdb068c2010-07-20 15:19:47 -07001738 mutex_unlock(&fip->ctlr_mutex);
Joe Eykholt97c83892009-03-17 11:42:40 -07001739 }
1740 return 0;
1741}
1742EXPORT_SYMBOL(fcoe_ctlr_recv_flogi);
1743
Vasu Dev5e80f7f2009-03-17 11:42:18 -07001744/**
Robert Love70b51aa2009-11-03 11:47:45 -08001745 * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN
1746 * @mac: The MAC address to convert
1747 * @scheme: The scheme to use when converting
1748 * @port: The port indicator for converting
Vasu Dev5e80f7f2009-03-17 11:42:18 -07001749 *
1750 * Returns: u64 fc world wide name
1751 */
1752u64 fcoe_wwn_from_mac(unsigned char mac[MAX_ADDR_LEN],
1753 unsigned int scheme, unsigned int port)
1754{
1755 u64 wwn;
1756 u64 host_mac;
1757
1758 /* The MAC is in NO, so flip only the low 48 bits */
1759 host_mac = ((u64) mac[0] << 40) |
1760 ((u64) mac[1] << 32) |
1761 ((u64) mac[2] << 24) |
1762 ((u64) mac[3] << 16) |
1763 ((u64) mac[4] << 8) |
1764 (u64) mac[5];
1765
1766 WARN_ON(host_mac >= (1ULL << 48));
1767 wwn = host_mac | ((u64) scheme << 60);
1768 switch (scheme) {
1769 case 1:
1770 WARN_ON(port != 0);
1771 break;
1772 case 2:
1773 WARN_ON(port >= 0xfff);
1774 wwn |= (u64) port << 48;
1775 break;
1776 default:
1777 WARN_ON(1);
1778 break;
1779 }
1780
1781 return wwn;
1782}
1783EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac);
1784
1785/**
Joe Eykholte10f8c62010-07-20 15:20:30 -07001786 * fcoe_ctlr_rport() - return the fcoe_rport for a given fc_rport_priv
1787 * @rdata: libfc remote port
1788 */
1789static inline struct fcoe_rport *fcoe_ctlr_rport(struct fc_rport_priv *rdata)
1790{
1791 return (struct fcoe_rport *)(rdata + 1);
1792}
1793
1794/**
1795 * fcoe_ctlr_vn_send() - Send a FIP VN2VN Probe Request or Reply.
1796 * @fip: The FCoE controller
1797 * @sub: sub-opcode for probe request, reply, or advertisement.
1798 * @dest: The destination Ethernet MAC address
1799 * @min_len: minimum size of the Ethernet payload to be sent
1800 */
1801static void fcoe_ctlr_vn_send(struct fcoe_ctlr *fip,
1802 enum fip_vn2vn_subcode sub,
1803 const u8 *dest, size_t min_len)
1804{
1805 struct sk_buff *skb;
1806 struct fip_frame {
1807 struct ethhdr eth;
1808 struct fip_header fip;
1809 struct fip_mac_desc mac;
1810 struct fip_wwn_desc wwnn;
1811 struct fip_vn_desc vn;
1812 } __attribute__((packed)) *frame;
1813 struct fip_fc4_feat *ff;
1814 struct fip_size_desc *size;
1815 u32 fcp_feat;
1816 size_t len;
1817 size_t dlen;
1818
1819 len = sizeof(*frame);
1820 dlen = 0;
1821 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) {
1822 dlen = sizeof(struct fip_fc4_feat) +
1823 sizeof(struct fip_size_desc);
1824 len += dlen;
1825 }
1826 dlen += sizeof(frame->mac) + sizeof(frame->wwnn) + sizeof(frame->vn);
1827 len = max(len, min_len + sizeof(struct ethhdr));
1828
1829 skb = dev_alloc_skb(len);
1830 if (!skb)
1831 return;
1832
1833 frame = (struct fip_frame *)skb->data;
1834 memset(frame, 0, len);
1835 memcpy(frame->eth.h_dest, dest, ETH_ALEN);
1836 memcpy(frame->eth.h_source, fip->ctl_src_addr, ETH_ALEN);
1837 frame->eth.h_proto = htons(ETH_P_FIP);
1838
1839 frame->fip.fip_ver = FIP_VER_ENCAPS(FIP_VER);
1840 frame->fip.fip_op = htons(FIP_OP_VN2VN);
1841 frame->fip.fip_subcode = sub;
1842 frame->fip.fip_dl_len = htons(dlen / FIP_BPW);
1843
1844 frame->mac.fd_desc.fip_dtype = FIP_DT_MAC;
1845 frame->mac.fd_desc.fip_dlen = sizeof(frame->mac) / FIP_BPW;
1846 memcpy(frame->mac.fd_mac, fip->ctl_src_addr, ETH_ALEN);
1847
1848 frame->wwnn.fd_desc.fip_dtype = FIP_DT_NAME;
1849 frame->wwnn.fd_desc.fip_dlen = sizeof(frame->wwnn) / FIP_BPW;
1850 put_unaligned_be64(fip->lp->wwnn, &frame->wwnn.fd_wwn);
1851
1852 frame->vn.fd_desc.fip_dtype = FIP_DT_VN_ID;
1853 frame->vn.fd_desc.fip_dlen = sizeof(frame->vn) / FIP_BPW;
1854 hton24(frame->vn.fd_mac, FIP_VN_FC_MAP);
1855 hton24(frame->vn.fd_mac + 3, fip->port_id);
1856 hton24(frame->vn.fd_fc_id, fip->port_id);
1857 put_unaligned_be64(fip->lp->wwpn, &frame->vn.fd_wwpn);
1858
1859 /*
1860 * For claims, add FC-4 features.
1861 * TBD: Add interface to get fc-4 types and features from libfc.
1862 */
1863 if (sub == FIP_SC_VN_CLAIM_NOTIFY || sub == FIP_SC_VN_CLAIM_REP) {
1864 ff = (struct fip_fc4_feat *)(frame + 1);
1865 ff->fd_desc.fip_dtype = FIP_DT_FC4F;
1866 ff->fd_desc.fip_dlen = sizeof(*ff) / FIP_BPW;
1867 ff->fd_fts = fip->lp->fcts;
1868
1869 fcp_feat = 0;
1870 if (fip->lp->service_params & FCP_SPPF_INIT_FCN)
1871 fcp_feat |= FCP_FEAT_INIT;
1872 if (fip->lp->service_params & FCP_SPPF_TARG_FCN)
1873 fcp_feat |= FCP_FEAT_TARG;
1874 fcp_feat <<= (FC_TYPE_FCP * 4) % 32;
1875 ff->fd_ff.fd_feat[FC_TYPE_FCP * 4 / 32] = htonl(fcp_feat);
1876
1877 size = (struct fip_size_desc *)(ff + 1);
1878 size->fd_desc.fip_dtype = FIP_DT_FCOE_SIZE;
1879 size->fd_desc.fip_dlen = sizeof(*size) / FIP_BPW;
1880 size->fd_size = htons(fcoe_ctlr_fcoe_size(fip));
1881 }
1882
1883 skb_put(skb, len);
1884 skb->protocol = htons(ETH_P_FIP);
1885 skb_reset_mac_header(skb);
1886 skb_reset_network_header(skb);
1887
1888 fip->send(fip, skb);
1889}
1890
1891/**
1892 * fcoe_ctlr_vn_rport_callback - Event handler for rport events.
1893 * @lport: The lport which is receiving the event
1894 * @rdata: remote port private data
1895 * @event: The event that occured
1896 *
1897 * Locking Note: The rport lock must not be held when calling this function.
1898 */
1899static void fcoe_ctlr_vn_rport_callback(struct fc_lport *lport,
1900 struct fc_rport_priv *rdata,
1901 enum fc_rport_event event)
1902{
1903 struct fcoe_ctlr *fip = lport->disc.priv;
1904 struct fcoe_rport *frport = fcoe_ctlr_rport(rdata);
1905
1906 LIBFCOE_FIP_DBG(fip, "vn_rport_callback %x event %d\n",
1907 rdata->ids.port_id, event);
1908
1909 mutex_lock(&fip->ctlr_mutex);
1910 switch (event) {
1911 case RPORT_EV_READY:
1912 frport->login_count = 0;
1913 break;
1914 case RPORT_EV_LOGO:
1915 case RPORT_EV_FAILED:
1916 case RPORT_EV_STOP:
1917 frport->login_count++;
1918 if (frport->login_count > FCOE_CTLR_VN2VN_LOGIN_LIMIT) {
1919 LIBFCOE_FIP_DBG(fip,
1920 "rport FLOGI limited port_id %6.6x\n",
1921 rdata->ids.port_id);
1922 lport->tt.rport_logoff(rdata);
1923 }
1924 break;
1925 default:
1926 break;
1927 }
1928 mutex_unlock(&fip->ctlr_mutex);
1929}
1930
1931static struct fc_rport_operations fcoe_ctlr_vn_rport_ops = {
1932 .event_callback = fcoe_ctlr_vn_rport_callback,
1933};
1934
1935/**
1936 * fcoe_ctlr_disc_stop_locked() - stop discovery in VN2VN mode
1937 * @fip: The FCoE controller
1938 *
1939 * Called with ctlr_mutex held.
1940 */
1941static void fcoe_ctlr_disc_stop_locked(struct fc_lport *lport)
1942{
1943 mutex_lock(&lport->disc.disc_mutex);
1944 lport->disc.disc_callback = NULL;
1945 mutex_unlock(&lport->disc.disc_mutex);
1946}
1947
1948/**
1949 * fcoe_ctlr_disc_stop() - stop discovery in VN2VN mode
1950 * @fip: The FCoE controller
1951 *
1952 * Called through the local port template for discovery.
1953 * Called without the ctlr_mutex held.
1954 */
1955static void fcoe_ctlr_disc_stop(struct fc_lport *lport)
1956{
1957 struct fcoe_ctlr *fip = lport->disc.priv;
1958
1959 mutex_lock(&fip->ctlr_mutex);
1960 fcoe_ctlr_disc_stop_locked(lport);
1961 mutex_unlock(&fip->ctlr_mutex);
1962}
1963
1964/**
1965 * fcoe_ctlr_disc_stop_final() - stop discovery for shutdown in VN2VN mode
1966 * @fip: The FCoE controller
1967 *
1968 * Called through the local port template for discovery.
1969 * Called without the ctlr_mutex held.
1970 */
1971static void fcoe_ctlr_disc_stop_final(struct fc_lport *lport)
1972{
1973 fcoe_ctlr_disc_stop(lport);
1974 lport->tt.rport_flush_queue();
1975 synchronize_rcu();
1976}
1977
1978/**
1979 * fcoe_ctlr_vn_restart() - VN2VN probe restart with new port_id
1980 * @fip: The FCoE controller
1981 *
1982 * Called with fcoe_ctlr lock held.
1983 */
1984static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip)
1985{
1986 unsigned long wait;
1987 u32 port_id;
1988
1989 fcoe_ctlr_disc_stop_locked(fip->lp);
1990
1991 /*
1992 * Get proposed port ID.
1993 * If this is the first try after link up, use any previous port_id.
1994 * If there was none, use the low bits of the port_name.
1995 * On subsequent tries, get the next random one.
1996 * Don't use reserved IDs, use another non-zero value, just as random.
1997 */
1998 port_id = fip->port_id;
1999 if (fip->probe_tries)
2000 port_id = prandom32(&fip->rnd_state) & 0xffff;
2001 else if (!port_id)
2002 port_id = fip->lp->wwpn & 0xffff;
2003 if (!port_id || port_id == 0xffff)
2004 port_id = 1;
2005 fip->port_id = port_id;
2006
2007 if (fip->probe_tries < FIP_VN_RLIM_COUNT) {
2008 fip->probe_tries++;
2009 wait = random32() % FIP_VN_PROBE_WAIT;
2010 } else
2011 wait = FIP_VN_RLIM_INT;
2012 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait));
2013 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_START);
2014}
2015
2016/**
2017 * fcoe_ctlr_vn_start() - Start in VN2VN mode
2018 * @fip: The FCoE controller
2019 *
2020 * Called with fcoe_ctlr lock held.
2021 */
2022static void fcoe_ctlr_vn_start(struct fcoe_ctlr *fip)
2023{
2024 fip->probe_tries = 0;
2025 prandom32_seed(&fip->rnd_state, fip->lp->wwpn);
2026 fcoe_ctlr_vn_restart(fip);
2027}
2028
2029/**
2030 * fcoe_ctlr_vn_parse - parse probe request or response
2031 * @fip: The FCoE controller
2032 * @skb: incoming packet
2033 * @rdata: buffer for resulting parsed VN entry plus fcoe_rport
2034 *
2035 * Returns non-zero error number on error.
2036 * Does not consume the packet.
2037 */
2038static int fcoe_ctlr_vn_parse(struct fcoe_ctlr *fip,
2039 struct sk_buff *skb,
2040 struct fc_rport_priv *rdata)
2041{
2042 struct fip_header *fiph;
2043 struct fip_desc *desc = NULL;
2044 struct fip_mac_desc *macd = NULL;
2045 struct fip_wwn_desc *wwn = NULL;
2046 struct fip_vn_desc *vn = NULL;
2047 struct fip_size_desc *size = NULL;
2048 struct fcoe_rport *frport;
2049 size_t rlen;
2050 size_t dlen;
2051 u32 desc_mask = 0;
2052 u32 dtype;
2053 u8 sub;
2054
2055 memset(rdata, 0, sizeof(*rdata) + sizeof(*frport));
2056 frport = fcoe_ctlr_rport(rdata);
2057
2058 fiph = (struct fip_header *)skb->data;
2059 frport->flags = ntohs(fiph->fip_flags);
2060
2061 sub = fiph->fip_subcode;
2062 switch (sub) {
2063 case FIP_SC_VN_PROBE_REQ:
2064 case FIP_SC_VN_PROBE_REP:
2065 case FIP_SC_VN_BEACON:
2066 desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) |
2067 BIT(FIP_DT_VN_ID);
2068 break;
2069 case FIP_SC_VN_CLAIM_NOTIFY:
2070 case FIP_SC_VN_CLAIM_REP:
2071 desc_mask = BIT(FIP_DT_MAC) | BIT(FIP_DT_NAME) |
2072 BIT(FIP_DT_VN_ID) | BIT(FIP_DT_FC4F) |
2073 BIT(FIP_DT_FCOE_SIZE);
2074 break;
2075 default:
2076 LIBFCOE_FIP_DBG(fip, "vn_parse unknown subcode %u\n", sub);
2077 return -EINVAL;
2078 }
2079
2080 rlen = ntohs(fiph->fip_dl_len) * 4;
2081 if (rlen + sizeof(*fiph) > skb->len)
2082 return -EINVAL;
2083
2084 desc = (struct fip_desc *)(fiph + 1);
2085 while (rlen > 0) {
2086 dlen = desc->fip_dlen * FIP_BPW;
2087 if (dlen < sizeof(*desc) || dlen > rlen)
2088 return -EINVAL;
2089
2090 dtype = desc->fip_dtype;
2091 if (dtype < 32) {
2092 if (!(desc_mask & BIT(dtype))) {
2093 LIBFCOE_FIP_DBG(fip,
2094 "unexpected or duplicated desc "
2095 "desc type %u in "
2096 "FIP VN2VN subtype %u\n",
2097 dtype, sub);
2098 return -EINVAL;
2099 }
2100 desc_mask &= ~BIT(dtype);
2101 }
2102
2103 switch (dtype) {
2104 case FIP_DT_MAC:
2105 if (dlen != sizeof(struct fip_mac_desc))
2106 goto len_err;
2107 macd = (struct fip_mac_desc *)desc;
2108 if (!is_valid_ether_addr(macd->fd_mac)) {
2109 LIBFCOE_FIP_DBG(fip,
2110 "Invalid MAC addr %pM in FIP VN2VN\n",
2111 macd->fd_mac);
2112 return -EINVAL;
2113 }
2114 memcpy(frport->enode_mac, macd->fd_mac, ETH_ALEN);
2115 break;
2116 case FIP_DT_NAME:
2117 if (dlen != sizeof(struct fip_wwn_desc))
2118 goto len_err;
2119 wwn = (struct fip_wwn_desc *)desc;
2120 rdata->ids.node_name = get_unaligned_be64(&wwn->fd_wwn);
2121 break;
2122 case FIP_DT_VN_ID:
2123 if (dlen != sizeof(struct fip_vn_desc))
2124 goto len_err;
2125 vn = (struct fip_vn_desc *)desc;
2126 memcpy(frport->vn_mac, vn->fd_mac, ETH_ALEN);
2127 rdata->ids.port_id = ntoh24(vn->fd_fc_id);
2128 rdata->ids.port_name = get_unaligned_be64(&vn->fd_wwpn);
2129 break;
2130 case FIP_DT_FC4F:
2131 if (dlen != sizeof(struct fip_fc4_feat))
2132 goto len_err;
2133 break;
2134 case FIP_DT_FCOE_SIZE:
2135 if (dlen != sizeof(struct fip_size_desc))
2136 goto len_err;
2137 size = (struct fip_size_desc *)desc;
2138 frport->fcoe_len = ntohs(size->fd_size);
2139 break;
2140 default:
2141 LIBFCOE_FIP_DBG(fip, "unexpected descriptor type %x "
2142 "in FIP probe\n", dtype);
2143 /* standard says ignore unknown descriptors >= 128 */
2144 if (dtype < FIP_DT_VENDOR_BASE)
2145 return -EINVAL;
2146 break;
2147 }
2148 desc = (struct fip_desc *)((char *)desc + dlen);
2149 rlen -= dlen;
2150 }
2151 return 0;
2152
2153len_err:
2154 LIBFCOE_FIP_DBG(fip, "FIP length error in descriptor type %x len %zu\n",
2155 dtype, dlen);
2156 return -EINVAL;
2157}
2158
2159/**
2160 * fcoe_ctlr_vn_send_claim() - send multicast FIP VN2VN Claim Notification.
2161 * @fip: The FCoE controller
2162 *
2163 * Called with ctlr_mutex held.
2164 */
2165static void fcoe_ctlr_vn_send_claim(struct fcoe_ctlr *fip)
2166{
2167 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_NOTIFY, fcoe_all_vn2vn, 0);
2168 fip->sol_time = jiffies;
2169}
2170
2171/**
2172 * fcoe_ctlr_vn_probe_req() - handle incoming VN2VN probe request.
2173 * @fip: The FCoE controller
2174 * @rdata: parsed remote port with frport from the probe request
2175 *
2176 * Called with ctlr_mutex held.
2177 */
2178static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr *fip,
2179 struct fc_rport_priv *rdata)
2180{
2181 struct fcoe_rport *frport = fcoe_ctlr_rport(rdata);
2182
2183 if (rdata->ids.port_id != fip->port_id)
2184 return;
2185
2186 switch (fip->state) {
2187 case FIP_ST_VNMP_CLAIM:
2188 case FIP_ST_VNMP_UP:
2189 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
2190 frport->enode_mac, 0);
2191 break;
2192 case FIP_ST_VNMP_PROBE1:
2193 case FIP_ST_VNMP_PROBE2:
2194 /*
2195 * Decide whether to reply to the Probe.
2196 * Our selected address is never a "recorded" one, so
2197 * only reply if our WWPN is greater and the
2198 * Probe's REC bit is not set.
2199 * If we don't reply, we will change our address.
2200 */
2201 if (fip->lp->wwpn > rdata->ids.port_name &&
2202 !(frport->flags & FIP_FL_REC_OR_P2P)) {
2203 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REP,
2204 frport->enode_mac, 0);
2205 break;
2206 }
2207 /* fall through */
2208 case FIP_ST_VNMP_START:
2209 fcoe_ctlr_vn_restart(fip);
2210 break;
2211 default:
2212 break;
2213 }
2214}
2215
2216/**
2217 * fcoe_ctlr_vn_probe_reply() - handle incoming VN2VN probe reply.
2218 * @fip: The FCoE controller
2219 * @rdata: parsed remote port with frport from the probe request
2220 *
2221 * Called with ctlr_mutex held.
2222 */
2223static void fcoe_ctlr_vn_probe_reply(struct fcoe_ctlr *fip,
2224 struct fc_rport_priv *rdata)
2225{
2226 if (rdata->ids.port_id != fip->port_id)
2227 return;
2228 switch (fip->state) {
2229 case FIP_ST_VNMP_START:
2230 case FIP_ST_VNMP_PROBE1:
2231 case FIP_ST_VNMP_PROBE2:
2232 case FIP_ST_VNMP_CLAIM:
2233 fcoe_ctlr_vn_restart(fip);
2234 break;
2235 case FIP_ST_VNMP_UP:
2236 fcoe_ctlr_vn_send_claim(fip);
2237 break;
2238 default:
2239 break;
2240 }
2241}
2242
2243/**
2244 * fcoe_ctlr_vn_add() - Add a VN2VN entry to the list, based on a claim reply.
2245 * @fip: The FCoE controller
2246 * @new: newly-parsed remote port with frport as a template for new rdata
2247 *
2248 * Called with ctlr_mutex held.
2249 */
2250static void fcoe_ctlr_vn_add(struct fcoe_ctlr *fip, struct fc_rport_priv *new)
2251{
2252 struct fc_lport *lport = fip->lp;
2253 struct fc_rport_priv *rdata;
2254 struct fc_rport_identifiers *ids;
2255 struct fcoe_rport *frport;
2256 u32 port_id;
2257
2258 port_id = new->ids.port_id;
2259 if (port_id == fip->port_id)
2260 return;
2261
2262 mutex_lock(&lport->disc.disc_mutex);
2263 rdata = lport->tt.rport_create(lport, port_id);
2264 if (!rdata) {
2265 mutex_unlock(&lport->disc.disc_mutex);
2266 return;
2267 }
2268
2269 rdata->ops = &fcoe_ctlr_vn_rport_ops;
2270 rdata->disc_id = lport->disc.disc_id;
2271
2272 ids = &rdata->ids;
2273 if ((ids->port_name != -1 && ids->port_name != new->ids.port_name) ||
2274 (ids->node_name != -1 && ids->node_name != new->ids.node_name))
2275 lport->tt.rport_logoff(rdata);
2276 ids->port_name = new->ids.port_name;
2277 ids->node_name = new->ids.node_name;
2278 mutex_unlock(&lport->disc.disc_mutex);
2279
2280 frport = fcoe_ctlr_rport(rdata);
2281 LIBFCOE_FIP_DBG(fip, "vn_add rport %6.6x %s\n",
2282 port_id, frport->fcoe_len ? "old" : "new");
2283 *frport = *fcoe_ctlr_rport(new);
2284 frport->time = 0;
2285}
2286
2287/**
2288 * fcoe_ctlr_vn_lookup() - Find VN remote port's MAC address
2289 * @fip: The FCoE controller
2290 * @port_id: The port_id of the remote VN_node
2291 * @mac: buffer which will hold the VN_NODE destination MAC address, if found.
2292 *
2293 * Returns non-zero error if no remote port found.
2294 */
2295static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr *fip, u32 port_id, u8 *mac)
2296{
2297 struct fc_lport *lport = fip->lp;
2298 struct fc_rport_priv *rdata;
2299 struct fcoe_rport *frport;
2300 int ret = -1;
2301
2302 rcu_read_lock();
2303 rdata = lport->tt.rport_lookup(lport, port_id);
2304 if (rdata) {
2305 frport = fcoe_ctlr_rport(rdata);
2306 memcpy(mac, frport->enode_mac, ETH_ALEN);
2307 ret = 0;
2308 }
2309 rcu_read_unlock();
2310 return ret;
2311}
2312
2313/**
2314 * fcoe_ctlr_vn_claim_notify() - handle received FIP VN2VN Claim Notification
2315 * @fip: The FCoE controller
2316 * @new: newly-parsed remote port with frport as a template for new rdata
2317 *
2318 * Called with ctlr_mutex held.
2319 */
2320static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr *fip,
2321 struct fc_rport_priv *new)
2322{
2323 struct fcoe_rport *frport = fcoe_ctlr_rport(new);
2324
2325 if (frport->flags & FIP_FL_REC_OR_P2P) {
2326 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2327 return;
2328 }
2329 switch (fip->state) {
2330 case FIP_ST_VNMP_START:
2331 case FIP_ST_VNMP_PROBE1:
2332 case FIP_ST_VNMP_PROBE2:
2333 if (new->ids.port_id == fip->port_id)
2334 fcoe_ctlr_vn_restart(fip);
2335 break;
2336 case FIP_ST_VNMP_CLAIM:
2337 case FIP_ST_VNMP_UP:
2338 if (new->ids.port_id == fip->port_id) {
2339 if (new->ids.port_name > fip->lp->wwpn) {
2340 fcoe_ctlr_vn_restart(fip);
2341 break;
2342 }
2343 fcoe_ctlr_vn_send_claim(fip);
2344 break;
2345 }
2346 fcoe_ctlr_vn_send(fip, FIP_SC_VN_CLAIM_REP, frport->enode_mac,
2347 min((u32)frport->fcoe_len,
2348 fcoe_ctlr_fcoe_size(fip)));
2349 fcoe_ctlr_vn_add(fip, new);
2350 break;
2351 default:
2352 break;
2353 }
2354}
2355
2356/**
2357 * fcoe_ctlr_vn_claim_resp() - handle received Claim Response
2358 * @fip: The FCoE controller that received the frame
2359 * @new: newly-parsed remote port with frport from the Claim Response
2360 *
2361 * Called with ctlr_mutex held.
2362 */
2363static void fcoe_ctlr_vn_claim_resp(struct fcoe_ctlr *fip,
2364 struct fc_rport_priv *new)
2365{
2366 LIBFCOE_FIP_DBG(fip, "claim resp from from rport %x - state %s\n",
2367 new->ids.port_id, fcoe_ctlr_state(fip->state));
2368 if (fip->state == FIP_ST_VNMP_UP || fip->state == FIP_ST_VNMP_CLAIM)
2369 fcoe_ctlr_vn_add(fip, new);
2370}
2371
2372/**
2373 * fcoe_ctlr_vn_beacon() - handle received beacon.
2374 * @fip: The FCoE controller that received the frame
2375 * @new: newly-parsed remote port with frport from the Beacon
2376 *
2377 * Called with ctlr_mutex held.
2378 */
2379static void fcoe_ctlr_vn_beacon(struct fcoe_ctlr *fip,
2380 struct fc_rport_priv *new)
2381{
2382 struct fc_lport *lport = fip->lp;
2383 struct fc_rport_priv *rdata;
2384 struct fcoe_rport *frport;
2385
2386 frport = fcoe_ctlr_rport(new);
2387 if (frport->flags & FIP_FL_REC_OR_P2P) {
2388 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2389 return;
2390 }
2391 mutex_lock(&lport->disc.disc_mutex);
2392 rdata = lport->tt.rport_lookup(lport, new->ids.port_id);
2393 if (rdata)
2394 kref_get(&rdata->kref);
2395 mutex_unlock(&lport->disc.disc_mutex);
2396 if (rdata) {
2397 if (rdata->ids.node_name == new->ids.node_name &&
2398 rdata->ids.port_name == new->ids.port_name) {
2399 frport = fcoe_ctlr_rport(rdata);
2400 if (!frport->time && fip->state == FIP_ST_VNMP_UP)
2401 lport->tt.rport_login(rdata);
2402 frport->time = jiffies;
2403 }
2404 kref_put(&rdata->kref, lport->tt.rport_destroy);
2405 return;
2406 }
2407 if (fip->state != FIP_ST_VNMP_UP)
2408 return;
2409
2410 /*
2411 * Beacon from a new neighbor.
2412 * Send a claim notify if one hasn't been sent recently.
2413 * Don't add the neighbor yet.
2414 */
2415 LIBFCOE_FIP_DBG(fip, "beacon from new rport %x. sending claim notify\n",
2416 new->ids.port_id);
2417 if (time_after(jiffies,
2418 fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT)))
2419 fcoe_ctlr_vn_send_claim(fip);
2420}
2421
2422/**
2423 * fcoe_ctlr_vn_age() - Check for VN_ports without recent beacons
2424 * @fip: The FCoE controller
2425 *
2426 * Called with ctlr_mutex held.
2427 * Called only in state FIP_ST_VNMP_UP.
2428 * Returns the soonest time for next age-out or a time far in the future.
2429 */
2430static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr *fip)
2431{
2432 struct fc_lport *lport = fip->lp;
2433 struct fc_rport_priv *rdata;
2434 struct fcoe_rport *frport;
2435 unsigned long next_time;
2436 unsigned long deadline;
2437
2438 next_time = jiffies + msecs_to_jiffies(FIP_VN_BEACON_INT * 10);
2439 mutex_lock(&lport->disc.disc_mutex);
2440 list_for_each_entry_rcu(rdata, &lport->disc.rports, peers) {
2441 frport = fcoe_ctlr_rport(rdata);
2442 if (!frport->time)
2443 continue;
2444 deadline = frport->time +
2445 msecs_to_jiffies(FIP_VN_BEACON_INT * 25 / 10);
2446 if (time_after_eq(jiffies, deadline)) {
2447 frport->time = 0;
2448 LIBFCOE_FIP_DBG(fip,
2449 "port %16.16llx fc_id %6.6x beacon expired\n",
2450 rdata->ids.port_name, rdata->ids.port_id);
2451 lport->tt.rport_logoff(rdata);
2452 } else if (time_before(deadline, next_time))
2453 next_time = deadline;
2454 }
2455 mutex_unlock(&lport->disc.disc_mutex);
2456 return next_time;
2457}
2458
2459/**
2460 * fcoe_ctlr_vn_recv() - Receive a FIP frame
2461 * @fip: The FCoE controller that received the frame
2462 * @skb: The received FIP frame
2463 *
2464 * Returns non-zero if the frame is dropped.
2465 * Always consumes the frame.
2466 */
2467static int fcoe_ctlr_vn_recv(struct fcoe_ctlr *fip, struct sk_buff *skb)
2468{
2469 struct fip_header *fiph;
2470 enum fip_vn2vn_subcode sub;
Kiran Patil2dc02ee2010-10-08 17:12:41 -07002471 struct {
Joe Eykholte10f8c62010-07-20 15:20:30 -07002472 struct fc_rport_priv rdata;
2473 struct fcoe_rport frport;
2474 } buf;
2475 int rc;
2476
2477 fiph = (struct fip_header *)skb->data;
2478 sub = fiph->fip_subcode;
2479
2480 rc = fcoe_ctlr_vn_parse(fip, skb, &buf.rdata);
2481 if (rc) {
2482 LIBFCOE_FIP_DBG(fip, "vn_recv vn_parse error %d\n", rc);
2483 goto drop;
2484 }
2485
2486 mutex_lock(&fip->ctlr_mutex);
2487 switch (sub) {
2488 case FIP_SC_VN_PROBE_REQ:
2489 fcoe_ctlr_vn_probe_req(fip, &buf.rdata);
2490 break;
2491 case FIP_SC_VN_PROBE_REP:
2492 fcoe_ctlr_vn_probe_reply(fip, &buf.rdata);
2493 break;
2494 case FIP_SC_VN_CLAIM_NOTIFY:
2495 fcoe_ctlr_vn_claim_notify(fip, &buf.rdata);
2496 break;
2497 case FIP_SC_VN_CLAIM_REP:
2498 fcoe_ctlr_vn_claim_resp(fip, &buf.rdata);
2499 break;
2500 case FIP_SC_VN_BEACON:
2501 fcoe_ctlr_vn_beacon(fip, &buf.rdata);
2502 break;
2503 default:
2504 LIBFCOE_FIP_DBG(fip, "vn_recv unknown subcode %d\n", sub);
2505 rc = -1;
2506 break;
2507 }
2508 mutex_unlock(&fip->ctlr_mutex);
2509drop:
2510 kfree_skb(skb);
2511 return rc;
2512}
2513
2514/**
2515 * fcoe_ctlr_disc_recv - discovery receive handler for VN2VN mode.
Joe Eykholt92261152010-07-20 15:21:12 -07002516 * @lport: The local port
2517 * @fp: The received frame
Joe Eykholte10f8c62010-07-20 15:20:30 -07002518 *
2519 * This should never be called since we don't see RSCNs or other
2520 * fabric-generated ELSes.
2521 */
Joe Eykholt92261152010-07-20 15:21:12 -07002522static void fcoe_ctlr_disc_recv(struct fc_lport *lport, struct fc_frame *fp)
Joe Eykholte10f8c62010-07-20 15:20:30 -07002523{
2524 struct fc_seq_els_data rjt_data;
2525
Joe Eykholte10f8c62010-07-20 15:20:30 -07002526 rjt_data.reason = ELS_RJT_UNSUP;
2527 rjt_data.explan = ELS_EXPL_NONE;
Joe Eykholt92261152010-07-20 15:21:12 -07002528 lport->tt.seq_els_rsp_send(fp, ELS_LS_RJT, &rjt_data);
Joe Eykholte10f8c62010-07-20 15:20:30 -07002529 fc_frame_free(fp);
2530}
2531
2532/**
2533 * fcoe_ctlr_disc_recv - start discovery for VN2VN mode.
2534 * @fip: The FCoE controller
2535 *
2536 * This sets a flag indicating that remote ports should be created
2537 * and started for the peers we discover. We use the disc_callback
2538 * pointer as that flag. Peers already discovered are created here.
2539 *
2540 * The lport lock is held during this call. The callback must be done
2541 * later, without holding either the lport or discovery locks.
2542 * The fcoe_ctlr lock may also be held during this call.
2543 */
2544static void fcoe_ctlr_disc_start(void (*callback)(struct fc_lport *,
2545 enum fc_disc_event),
2546 struct fc_lport *lport)
2547{
2548 struct fc_disc *disc = &lport->disc;
2549 struct fcoe_ctlr *fip = disc->priv;
2550
2551 mutex_lock(&disc->disc_mutex);
2552 disc->disc_callback = callback;
2553 disc->disc_id = (disc->disc_id + 2) | 1;
2554 disc->pending = 1;
2555 schedule_work(&fip->timer_work);
2556 mutex_unlock(&disc->disc_mutex);
2557}
2558
2559/**
2560 * fcoe_ctlr_vn_disc() - report FIP VN_port discovery results after claim state.
2561 * @fip: The FCoE controller
2562 *
2563 * Starts the FLOGI and PLOGI login process to each discovered rport for which
2564 * we've received at least one beacon.
2565 * Performs the discovery complete callback.
2566 */
2567static void fcoe_ctlr_vn_disc(struct fcoe_ctlr *fip)
2568{
2569 struct fc_lport *lport = fip->lp;
2570 struct fc_disc *disc = &lport->disc;
2571 struct fc_rport_priv *rdata;
2572 struct fcoe_rport *frport;
2573 void (*callback)(struct fc_lport *, enum fc_disc_event);
2574
2575 mutex_lock(&disc->disc_mutex);
2576 callback = disc->pending ? disc->disc_callback : NULL;
2577 disc->pending = 0;
2578 list_for_each_entry_rcu(rdata, &disc->rports, peers) {
2579 frport = fcoe_ctlr_rport(rdata);
2580 if (frport->time)
2581 lport->tt.rport_login(rdata);
2582 }
2583 mutex_unlock(&disc->disc_mutex);
2584 if (callback)
2585 callback(lport, DISC_EV_SUCCESS);
2586}
2587
2588/**
2589 * fcoe_ctlr_vn_timeout - timer work function for VN2VN mode.
2590 * @fip: The FCoE controller
2591 */
2592static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *fip)
2593{
2594 unsigned long next_time;
2595 u8 mac[ETH_ALEN];
2596 u32 new_port_id = 0;
2597
2598 mutex_lock(&fip->ctlr_mutex);
2599 switch (fip->state) {
2600 case FIP_ST_VNMP_START:
2601 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE1);
2602 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2603 next_time = jiffies + msecs_to_jiffies(FIP_VN_PROBE_WAIT);
2604 break;
2605 case FIP_ST_VNMP_PROBE1:
2606 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_PROBE2);
2607 fcoe_ctlr_vn_send(fip, FIP_SC_VN_PROBE_REQ, fcoe_all_vn2vn, 0);
2608 next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT);
2609 break;
2610 case FIP_ST_VNMP_PROBE2:
2611 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_CLAIM);
2612 new_port_id = fip->port_id;
2613 hton24(mac, FIP_VN_FC_MAP);
2614 hton24(mac + 3, new_port_id);
Joe Eykholtcd229e42010-07-20 15:20:40 -07002615 fcoe_ctlr_map_dest(fip);
Joe Eykholte10f8c62010-07-20 15:20:30 -07002616 fip->update_mac(fip->lp, mac);
2617 fcoe_ctlr_vn_send_claim(fip);
2618 next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT);
2619 break;
2620 case FIP_ST_VNMP_CLAIM:
2621 /*
2622 * This may be invoked either by starting discovery so don't
2623 * go to the next state unless it's been long enough.
2624 */
2625 next_time = fip->sol_time + msecs_to_jiffies(FIP_VN_ANN_WAIT);
2626 if (time_after_eq(jiffies, next_time)) {
2627 fcoe_ctlr_set_state(fip, FIP_ST_VNMP_UP);
2628 fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON,
2629 fcoe_all_vn2vn, 0);
2630 next_time = jiffies + msecs_to_jiffies(FIP_VN_ANN_WAIT);
2631 fip->port_ka_time = next_time;
2632 }
2633 fcoe_ctlr_vn_disc(fip);
2634 break;
2635 case FIP_ST_VNMP_UP:
2636 next_time = fcoe_ctlr_vn_age(fip);
2637 if (time_after_eq(jiffies, fip->port_ka_time)) {
2638 fcoe_ctlr_vn_send(fip, FIP_SC_VN_BEACON,
2639 fcoe_all_vn2vn, 0);
2640 fip->port_ka_time = jiffies +
2641 msecs_to_jiffies(FIP_VN_BEACON_INT +
2642 (random32() % FIP_VN_BEACON_FUZZ));
2643 }
2644 if (time_before(fip->port_ka_time, next_time))
2645 next_time = fip->port_ka_time;
2646 break;
2647 case FIP_ST_LINK_WAIT:
2648 goto unlock;
2649 default:
Joe Perches11aa9902010-11-30 16:19:09 -08002650 WARN(1, "unexpected state %d\n", fip->state);
Joe Eykholte10f8c62010-07-20 15:20:30 -07002651 goto unlock;
2652 }
2653 mod_timer(&fip->timer, next_time);
2654unlock:
2655 mutex_unlock(&fip->ctlr_mutex);
2656
2657 /* If port ID is new, notify local port after dropping ctlr_mutex */
2658 if (new_port_id)
2659 fc_lport_set_local_id(fip->lp, new_port_id);
2660}
2661
2662/**
Robert Love70b51aa2009-11-03 11:47:45 -08002663 * fcoe_libfc_config() - Sets up libfc related properties for local port
2664 * @lp: The local port to configure libfc for
Joe Eykholte10f8c62010-07-20 15:20:30 -07002665 * @fip: The FCoE controller in use by the local port
Robert Love70b51aa2009-11-03 11:47:45 -08002666 * @tt: The libfc function template
Joe Eykholte10f8c62010-07-20 15:20:30 -07002667 * @init_fcp: If non-zero, the FCP portion of libfc should be initialized
Vasu Dev5e80f7f2009-03-17 11:42:18 -07002668 *
2669 * Returns : 0 for success
2670 */
Joe Eykholte10f8c62010-07-20 15:20:30 -07002671int fcoe_libfc_config(struct fc_lport *lport, struct fcoe_ctlr *fip,
2672 const struct libfc_function_template *tt, int init_fcp)
Vasu Dev5e80f7f2009-03-17 11:42:18 -07002673{
2674 /* Set the function pointers set by the LLDD */
Robert Love70b51aa2009-11-03 11:47:45 -08002675 memcpy(&lport->tt, tt, sizeof(*tt));
Joe Eykholte10f8c62010-07-20 15:20:30 -07002676 if (init_fcp && fc_fcp_init(lport))
Vasu Dev5e80f7f2009-03-17 11:42:18 -07002677 return -ENOMEM;
Robert Love70b51aa2009-11-03 11:47:45 -08002678 fc_exch_init(lport);
2679 fc_elsct_init(lport);
2680 fc_lport_init(lport);
Joe Eykholte10f8c62010-07-20 15:20:30 -07002681 if (fip->mode == FIP_MODE_VN2VN)
2682 lport->rport_priv_size = sizeof(struct fcoe_rport);
Robert Love70b51aa2009-11-03 11:47:45 -08002683 fc_rport_init(lport);
Joe Eykholte10f8c62010-07-20 15:20:30 -07002684 if (fip->mode == FIP_MODE_VN2VN) {
2685 lport->point_to_multipoint = 1;
2686 lport->tt.disc_recv_req = fcoe_ctlr_disc_recv;
2687 lport->tt.disc_start = fcoe_ctlr_disc_start;
2688 lport->tt.disc_stop = fcoe_ctlr_disc_stop;
2689 lport->tt.disc_stop_final = fcoe_ctlr_disc_stop_final;
2690 mutex_init(&lport->disc.disc_mutex);
2691 INIT_LIST_HEAD(&lport->disc.rports);
2692 lport->disc.priv = fip;
2693 } else {
2694 fc_disc_init(lport);
2695 }
Vasu Dev5e80f7f2009-03-17 11:42:18 -07002696 return 0;
2697}
2698EXPORT_SYMBOL_GPL(fcoe_libfc_config);