2 * Copyright (c) 2008-2009 Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2009 Intel Corporation. All rights reserved.
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.
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
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.
18 * Maintained at www.Open-FCoE.org
21 #include <linux/types.h>
22 #include <linux/module.h>
23 #include <linux/kernel.h>
24 #include <linux/list.h>
25 #include <linux/spinlock.h>
26 #include <linux/timer.h>
27 #include <linux/netdevice.h>
28 #include <linux/etherdevice.h>
29 #include <linux/ethtool.h>
30 #include <linux/if_ether.h>
31 #include <linux/if_vlan.h>
32 #include <linux/errno.h>
33 #include <linux/bitops.h>
34 #include <linux/slab.h>
35 #include <net/rtnetlink.h>
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>
42 #include <scsi/fc/fc_fcp.h>
44 #include <scsi/libfc.h>
45 #include <scsi/libfcoe.h>
49 #define FCOE_CTLR_MIN_FKA 500 /* min keep alive (mS) */
50 #define FCOE_CTLR_DEF_FKA FIP_DEF_FKA /* default keep alive (mS) */
52 static void fcoe_ctlr_timeout(unsigned long);
53 static void fcoe_ctlr_timer_work(struct work_struct
*);
54 static void fcoe_ctlr_recv_work(struct work_struct
*);
55 static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr
*);
57 static void fcoe_ctlr_vn_start(struct fcoe_ctlr
*);
58 static int fcoe_ctlr_vn_recv(struct fcoe_ctlr
*, struct sk_buff
*);
59 static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr
*);
60 static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr
*, u32
, u8
*);
62 static u8 fcoe_all_fcfs
[ETH_ALEN
] = FIP_ALL_FCF_MACS
;
63 static u8 fcoe_all_enode
[ETH_ALEN
] = FIP_ALL_ENODE_MACS
;
64 static u8 fcoe_all_vn2vn
[ETH_ALEN
] = FIP_ALL_VN2VN_MACS
;
65 static u8 fcoe_all_p2p
[ETH_ALEN
] = FIP_ALL_P2P_MACS
;
67 static const char * const fcoe_ctlr_states
[] = {
68 [FIP_ST_DISABLED
] = "DISABLED",
69 [FIP_ST_LINK_WAIT
] = "LINK_WAIT",
70 [FIP_ST_AUTO
] = "AUTO",
71 [FIP_ST_NON_FIP
] = "NON_FIP",
72 [FIP_ST_ENABLED
] = "ENABLED",
73 [FIP_ST_VNMP_START
] = "VNMP_START",
74 [FIP_ST_VNMP_PROBE1
] = "VNMP_PROBE1",
75 [FIP_ST_VNMP_PROBE2
] = "VNMP_PROBE2",
76 [FIP_ST_VNMP_CLAIM
] = "VNMP_CLAIM",
77 [FIP_ST_VNMP_UP
] = "VNMP_UP",
80 static const char *fcoe_ctlr_state(enum fip_state state
)
82 const char *cp
= "unknown";
84 if (state
< ARRAY_SIZE(fcoe_ctlr_states
))
85 cp
= fcoe_ctlr_states
[state
];
92 * fcoe_ctlr_set_state() - Set and do debug printing for the new FIP state.
93 * @fip: The FCoE controller
94 * @state: The new state
96 static void fcoe_ctlr_set_state(struct fcoe_ctlr
*fip
, enum fip_state state
)
98 if (state
== fip
->state
)
101 LIBFCOE_FIP_DBG(fip
, "state %s -> %s\n",
102 fcoe_ctlr_state(fip
->state
), fcoe_ctlr_state(state
));
107 * fcoe_ctlr_mtu_valid() - Check if a FCF's MTU is valid
108 * @fcf: The FCF to check
110 * Return non-zero if FCF fcoe_size has been validated.
112 static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf
*fcf
)
114 return (fcf
->flags
& FIP_FL_SOL
) != 0;
118 * fcoe_ctlr_fcf_usable() - Check if a FCF is usable
119 * @fcf: The FCF to check
121 * Return non-zero if the FCF is usable.
123 static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf
*fcf
)
125 u16 flags
= FIP_FL_SOL
| FIP_FL_AVAIL
;
127 return (fcf
->flags
& flags
) == flags
;
131 * fcoe_ctlr_map_dest() - Set flag and OUI for mapping destination addresses
132 * @fip: The FCoE controller
134 static void fcoe_ctlr_map_dest(struct fcoe_ctlr
*fip
)
136 if (fip
->mode
== FIP_MODE_VN2VN
)
137 hton24(fip
->dest_addr
, FIP_VN_FC_MAP
);
139 hton24(fip
->dest_addr
, FIP_DEF_FC_MAP
);
140 hton24(fip
->dest_addr
+ 3, 0);
145 * fcoe_ctlr_init() - Initialize the FCoE Controller instance
146 * @fip: The FCoE controller to initialize
148 void fcoe_ctlr_init(struct fcoe_ctlr
*fip
, enum fip_state mode
)
150 fcoe_ctlr_set_state(fip
, FIP_ST_LINK_WAIT
);
152 INIT_LIST_HEAD(&fip
->fcfs
);
153 mutex_init(&fip
->ctlr_mutex
);
154 spin_lock_init(&fip
->ctlr_lock
);
155 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
156 setup_timer(&fip
->timer
, fcoe_ctlr_timeout
, (unsigned long)fip
);
157 INIT_WORK(&fip
->timer_work
, fcoe_ctlr_timer_work
);
158 INIT_WORK(&fip
->recv_work
, fcoe_ctlr_recv_work
);
159 skb_queue_head_init(&fip
->fip_recv_list
);
161 EXPORT_SYMBOL(fcoe_ctlr_init
);
164 * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller
165 * @fip: The FCoE controller whose FCFs are to be reset
167 * Called with &fcoe_ctlr lock held.
169 static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr
*fip
)
171 struct fcoe_fcf
*fcf
;
172 struct fcoe_fcf
*next
;
175 list_for_each_entry_safe(fcf
, next
, &fip
->fcfs
, list
) {
176 list_del(&fcf
->list
);
184 * fcoe_ctlr_destroy() - Disable and tear down a FCoE controller
185 * @fip: The FCoE controller to tear down
187 * This is called by FCoE drivers before freeing the &fcoe_ctlr.
189 * The receive handler will have been deleted before this to guarantee
190 * that no more recv_work will be scheduled.
192 * The timer routine will simply return once we set FIP_ST_DISABLED.
193 * This guarantees that no further timeouts or work will be scheduled.
195 void fcoe_ctlr_destroy(struct fcoe_ctlr
*fip
)
197 cancel_work_sync(&fip
->recv_work
);
198 skb_queue_purge(&fip
->fip_recv_list
);
200 mutex_lock(&fip
->ctlr_mutex
);
201 fcoe_ctlr_set_state(fip
, FIP_ST_DISABLED
);
202 fcoe_ctlr_reset_fcfs(fip
);
203 mutex_unlock(&fip
->ctlr_mutex
);
204 del_timer_sync(&fip
->timer
);
205 cancel_work_sync(&fip
->timer_work
);
207 EXPORT_SYMBOL(fcoe_ctlr_destroy
);
210 * fcoe_ctlr_announce() - announce new FCF selection
211 * @fip: The FCoE controller
213 * Also sets the destination MAC for FCoE and control packets
215 * Called with neither ctlr_mutex nor ctlr_lock held.
217 static void fcoe_ctlr_announce(struct fcoe_ctlr
*fip
)
219 struct fcoe_fcf
*sel
;
220 struct fcoe_fcf
*fcf
;
222 mutex_lock(&fip
->ctlr_mutex
);
223 spin_lock_bh(&fip
->ctlr_lock
);
225 kfree_skb(fip
->flogi_req
);
226 fip
->flogi_req
= NULL
;
227 list_for_each_entry(fcf
, &fip
->fcfs
, list
)
230 spin_unlock_bh(&fip
->ctlr_lock
);
233 if (sel
&& !compare_ether_addr(sel
->fcf_mac
, fip
->dest_addr
))
235 if (!is_zero_ether_addr(fip
->dest_addr
)) {
236 printk(KERN_NOTICE
"libfcoe: host%d: "
237 "FIP Fibre-Channel Forwarder MAC %pM deselected\n",
238 fip
->lp
->host
->host_no
, fip
->dest_addr
);
239 memset(fip
->dest_addr
, 0, ETH_ALEN
);
242 printk(KERN_INFO
"libfcoe: host%d: FIP selected "
243 "Fibre-Channel Forwarder MAC %pM\n",
244 fip
->lp
->host
->host_no
, sel
->fcf_mac
);
245 memcpy(fip
->dest_addr
, sel
->fcf_mac
, ETH_ALEN
);
249 mutex_unlock(&fip
->ctlr_mutex
);
253 * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port
254 * @fip: The FCoE controller to get the maximum FCoE size from
256 * Returns the maximum packet size including the FCoE header and trailer,
257 * but not including any Ethernet or VLAN headers.
259 static inline u32
fcoe_ctlr_fcoe_size(struct fcoe_ctlr
*fip
)
262 * Determine the max FCoE frame size allowed, including
263 * FCoE header and trailer.
264 * Note: lp->mfs is currently the payload size, not the frame size.
266 return fip
->lp
->mfs
+ sizeof(struct fc_frame_header
) +
267 sizeof(struct fcoe_hdr
) + sizeof(struct fcoe_crc_eof
);
271 * fcoe_ctlr_solicit() - Send a FIP solicitation
272 * @fip: The FCoE controller to send the solicitation on
273 * @fcf: The destination FCF (if NULL, a multicast solicitation is sent)
275 static void fcoe_ctlr_solicit(struct fcoe_ctlr
*fip
, struct fcoe_fcf
*fcf
)
280 struct fip_header fip
;
282 struct fip_mac_desc mac
;
283 struct fip_wwn_desc wwnn
;
284 struct fip_size_desc size
;
289 skb
= dev_alloc_skb(sizeof(*sol
));
293 sol
= (struct fip_sol
*)skb
->data
;
295 memset(sol
, 0, sizeof(*sol
));
296 memcpy(sol
->eth
.h_dest
, fcf
? fcf
->fcf_mac
: fcoe_all_fcfs
, ETH_ALEN
);
297 memcpy(sol
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
298 sol
->eth
.h_proto
= htons(ETH_P_FIP
);
300 sol
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
301 sol
->fip
.fip_op
= htons(FIP_OP_DISC
);
302 sol
->fip
.fip_subcode
= FIP_SC_SOL
;
303 sol
->fip
.fip_dl_len
= htons(sizeof(sol
->desc
) / FIP_BPW
);
304 sol
->fip
.fip_flags
= htons(FIP_FL_FPMA
);
306 sol
->fip
.fip_flags
|= htons(FIP_FL_SPMA
);
308 sol
->desc
.mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
309 sol
->desc
.mac
.fd_desc
.fip_dlen
= sizeof(sol
->desc
.mac
) / FIP_BPW
;
310 memcpy(sol
->desc
.mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
312 sol
->desc
.wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
313 sol
->desc
.wwnn
.fd_desc
.fip_dlen
= sizeof(sol
->desc
.wwnn
) / FIP_BPW
;
314 put_unaligned_be64(fip
->lp
->wwnn
, &sol
->desc
.wwnn
.fd_wwn
);
316 fcoe_size
= fcoe_ctlr_fcoe_size(fip
);
317 sol
->desc
.size
.fd_desc
.fip_dtype
= FIP_DT_FCOE_SIZE
;
318 sol
->desc
.size
.fd_desc
.fip_dlen
= sizeof(sol
->desc
.size
) / FIP_BPW
;
319 sol
->desc
.size
.fd_size
= htons(fcoe_size
);
321 skb_put(skb
, sizeof(*sol
));
322 skb
->protocol
= htons(ETH_P_FIP
);
323 skb_reset_mac_header(skb
);
324 skb_reset_network_header(skb
);
328 fip
->sol_time
= jiffies
;
332 * fcoe_ctlr_link_up() - Start FCoE controller
333 * @fip: The FCoE controller to start
335 * Called from the LLD when the network link is ready.
337 void fcoe_ctlr_link_up(struct fcoe_ctlr
*fip
)
339 mutex_lock(&fip
->ctlr_mutex
);
340 if (fip
->state
== FIP_ST_NON_FIP
|| fip
->state
== FIP_ST_AUTO
) {
341 mutex_unlock(&fip
->ctlr_mutex
);
343 } else if (fip
->state
== FIP_ST_LINK_WAIT
) {
344 fcoe_ctlr_set_state(fip
, fip
->mode
);
347 LIBFCOE_FIP_DBG(fip
, "invalid mode %d\n", fip
->mode
);
350 LIBFCOE_FIP_DBG(fip
, "%s", "setting AUTO mode.\n");
352 case FIP_MODE_FABRIC
:
353 case FIP_MODE_NON_FIP
:
354 mutex_unlock(&fip
->ctlr_mutex
);
356 fcoe_ctlr_solicit(fip
, NULL
);
359 fcoe_ctlr_vn_start(fip
);
360 mutex_unlock(&fip
->ctlr_mutex
);
365 mutex_unlock(&fip
->ctlr_mutex
);
367 EXPORT_SYMBOL(fcoe_ctlr_link_up
);
370 * fcoe_ctlr_reset() - Reset a FCoE controller
371 * @fip: The FCoE controller to reset
373 static void fcoe_ctlr_reset(struct fcoe_ctlr
*fip
)
375 fcoe_ctlr_reset_fcfs(fip
);
376 del_timer(&fip
->timer
);
377 fip
->ctlr_ka_time
= 0;
378 fip
->port_ka_time
= 0;
380 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
381 fcoe_ctlr_map_dest(fip
);
385 * fcoe_ctlr_link_down() - Stop a FCoE controller
386 * @fip: The FCoE controller to be stopped
388 * Returns non-zero if the link was up and now isn't.
390 * Called from the LLD when the network link is not ready.
391 * There may be multiple calls while the link is down.
393 int fcoe_ctlr_link_down(struct fcoe_ctlr
*fip
)
397 LIBFCOE_FIP_DBG(fip
, "link down.\n");
398 mutex_lock(&fip
->ctlr_mutex
);
399 fcoe_ctlr_reset(fip
);
400 link_dropped
= fip
->state
!= FIP_ST_LINK_WAIT
;
401 fcoe_ctlr_set_state(fip
, FIP_ST_LINK_WAIT
);
402 mutex_unlock(&fip
->ctlr_mutex
);
405 fc_linkdown(fip
->lp
);
408 EXPORT_SYMBOL(fcoe_ctlr_link_down
);
411 * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF
412 * @fip: The FCoE controller to send the FKA on
413 * @lport: libfc fc_lport to send from
414 * @ports: 0 for controller keep-alive, 1 for port keep-alive
415 * @sa: The source MAC address
417 * A controller keep-alive is sent every fka_period (typically 8 seconds).
418 * The source MAC is the native MAC address.
420 * A port keep-alive is sent every 90 seconds while logged in.
421 * The source MAC is the assigned mapped source address.
422 * The destination is the FCF's F-port.
424 static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr
*fip
,
425 struct fc_lport
*lport
,
431 struct fip_header fip
;
432 struct fip_mac_desc mac
;
434 struct fip_vn_desc
*vn
;
437 struct fcoe_fcf
*fcf
;
441 if (!fcf
|| (ports
&& !lp
->port_id
))
444 len
= sizeof(*kal
) + ports
* sizeof(*vn
);
445 skb
= dev_alloc_skb(len
);
449 kal
= (struct fip_kal
*)skb
->data
;
451 memcpy(kal
->eth
.h_dest
, fcf
->fcf_mac
, ETH_ALEN
);
452 memcpy(kal
->eth
.h_source
, sa
, ETH_ALEN
);
453 kal
->eth
.h_proto
= htons(ETH_P_FIP
);
455 kal
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
456 kal
->fip
.fip_op
= htons(FIP_OP_CTRL
);
457 kal
->fip
.fip_subcode
= FIP_SC_KEEP_ALIVE
;
458 kal
->fip
.fip_dl_len
= htons((sizeof(kal
->mac
) +
459 ports
* sizeof(*vn
)) / FIP_BPW
);
460 kal
->fip
.fip_flags
= htons(FIP_FL_FPMA
);
462 kal
->fip
.fip_flags
|= htons(FIP_FL_SPMA
);
464 kal
->mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
465 kal
->mac
.fd_desc
.fip_dlen
= sizeof(kal
->mac
) / FIP_BPW
;
466 memcpy(kal
->mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
468 vn
= (struct fip_vn_desc
*)(kal
+ 1);
469 vn
->fd_desc
.fip_dtype
= FIP_DT_VN_ID
;
470 vn
->fd_desc
.fip_dlen
= sizeof(*vn
) / FIP_BPW
;
471 memcpy(vn
->fd_mac
, fip
->get_src_addr(lport
), ETH_ALEN
);
472 hton24(vn
->fd_fc_id
, lport
->port_id
);
473 put_unaligned_be64(lport
->wwpn
, &vn
->fd_wwpn
);
476 skb
->protocol
= htons(ETH_P_FIP
);
477 skb_reset_mac_header(skb
);
478 skb_reset_network_header(skb
);
483 * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it
484 * @fip: The FCoE controller for the ELS frame
485 * @dtype: The FIP descriptor type for the frame
486 * @skb: The FCoE ELS frame including FC header but no FCoE headers
487 * @d_id: The destination port ID.
489 * Returns non-zero error code on failure.
491 * The caller must check that the length is a multiple of 4.
493 * The @skb must have enough headroom (28 bytes) and tailroom (8 bytes).
494 * Headroom includes the FIP encapsulation description, FIP header, and
495 * Ethernet header. The tailroom is for the FIP MAC descriptor.
497 static int fcoe_ctlr_encaps(struct fcoe_ctlr
*fip
, struct fc_lport
*lport
,
498 u8 dtype
, struct sk_buff
*skb
, u32 d_id
)
500 struct fip_encaps_head
{
502 struct fip_header fip
;
503 struct fip_encaps encaps
;
505 struct fc_frame_header
*fh
;
506 struct fip_mac_desc
*mac
;
507 struct fcoe_fcf
*fcf
;
512 fh
= (struct fc_frame_header
*)skb
->data
;
513 op
= *(u8
*)(fh
+ 1);
514 dlen
= sizeof(struct fip_encaps
) + skb
->len
; /* len before push */
515 cap
= (struct fip_encaps_head
*)skb_push(skb
, sizeof(*cap
));
516 memset(cap
, 0, sizeof(*cap
));
518 if (lport
->point_to_multipoint
) {
519 if (fcoe_ctlr_vn_lookup(fip
, d_id
, cap
->eth
.h_dest
))
526 fip_flags
= fcf
->flags
;
527 fip_flags
&= fip
->spma
? FIP_FL_SPMA
| FIP_FL_FPMA
:
531 memcpy(cap
->eth
.h_dest
, fcf
->fcf_mac
, ETH_ALEN
);
533 memcpy(cap
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
534 cap
->eth
.h_proto
= htons(ETH_P_FIP
);
536 cap
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
537 cap
->fip
.fip_op
= htons(FIP_OP_LS
);
538 if (op
== ELS_LS_ACC
|| op
== ELS_LS_RJT
)
539 cap
->fip
.fip_subcode
= FIP_SC_REP
;
541 cap
->fip
.fip_subcode
= FIP_SC_REQ
;
542 cap
->fip
.fip_flags
= htons(fip_flags
);
544 cap
->encaps
.fd_desc
.fip_dtype
= dtype
;
545 cap
->encaps
.fd_desc
.fip_dlen
= dlen
/ FIP_BPW
;
547 if (op
!= ELS_LS_RJT
) {
548 dlen
+= sizeof(*mac
);
549 mac
= (struct fip_mac_desc
*)skb_put(skb
, sizeof(*mac
));
550 memset(mac
, 0, sizeof(*mac
));
551 mac
->fd_desc
.fip_dtype
= FIP_DT_MAC
;
552 mac
->fd_desc
.fip_dlen
= sizeof(*mac
) / FIP_BPW
;
553 if (dtype
!= FIP_DT_FLOGI
&& dtype
!= FIP_DT_FDISC
) {
554 memcpy(mac
->fd_mac
, fip
->get_src_addr(lport
), ETH_ALEN
);
555 } else if (fip
->mode
== FIP_MODE_VN2VN
) {
556 hton24(mac
->fd_mac
, FIP_VN_FC_MAP
);
557 hton24(mac
->fd_mac
+ 3, fip
->port_id
);
558 } else if (fip_flags
& FIP_FL_SPMA
) {
559 LIBFCOE_FIP_DBG(fip
, "FLOGI/FDISC sent with SPMA\n");
560 memcpy(mac
->fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
562 LIBFCOE_FIP_DBG(fip
, "FLOGI/FDISC sent with FPMA\n");
563 /* FPMA only FLOGI. Must leave the MAC desc zeroed. */
566 cap
->fip
.fip_dl_len
= htons(dlen
/ FIP_BPW
);
568 skb
->protocol
= htons(ETH_P_FIP
);
569 skb_reset_mac_header(skb
);
570 skb_reset_network_header(skb
);
575 * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate.
576 * @fip: FCoE controller.
577 * @lport: libfc fc_lport to send from
578 * @skb: FCoE ELS frame including FC header but no FCoE headers.
580 * Returns a non-zero error code if the frame should not be sent.
581 * Returns zero if the caller should send the frame with FCoE encapsulation.
583 * The caller must check that the length is a multiple of 4.
584 * The SKB must have enough headroom (28 bytes) and tailroom (8 bytes).
585 * The the skb must also be an fc_frame.
587 * This is called from the lower-level driver with spinlocks held,
588 * so we must not take a mutex here.
590 int fcoe_ctlr_els_send(struct fcoe_ctlr
*fip
, struct fc_lport
*lport
,
594 struct fc_frame_header
*fh
;
599 fp
= container_of(skb
, struct fc_frame
, skb
);
600 fh
= (struct fc_frame_header
*)skb
->data
;
601 op
= *(u8
*)(fh
+ 1);
603 if (op
== ELS_FLOGI
&& fip
->mode
!= FIP_MODE_VN2VN
) {
604 old_xid
= fip
->flogi_oxid
;
605 fip
->flogi_oxid
= ntohs(fh
->fh_ox_id
);
606 if (fip
->state
== FIP_ST_AUTO
) {
607 if (old_xid
== FC_XID_UNKNOWN
)
608 fip
->flogi_count
= 0;
610 if (fip
->flogi_count
< 3)
612 fcoe_ctlr_map_dest(fip
);
615 if (fip
->state
== FIP_ST_NON_FIP
)
616 fcoe_ctlr_map_dest(fip
);
619 if (fip
->state
== FIP_ST_NON_FIP
)
621 if (!fip
->sel_fcf
&& fip
->mode
!= FIP_MODE_VN2VN
)
626 if (fip
->mode
== FIP_MODE_VN2VN
)
628 spin_lock_bh(&fip
->ctlr_lock
);
629 kfree_skb(fip
->flogi_req
);
630 fip
->flogi_req
= skb
;
631 fip
->flogi_req_send
= 1;
632 spin_unlock_bh(&fip
->ctlr_lock
);
633 schedule_work(&fip
->timer_work
);
636 if (ntoh24(fh
->fh_s_id
))
641 if (fip
->mode
== FIP_MODE_VN2VN
) {
642 if (fip
->state
!= FIP_ST_VNMP_UP
)
644 if (ntoh24(fh
->fh_d_id
) == FC_FID_FLOGI
)
647 if (fip
->state
!= FIP_ST_ENABLED
)
649 if (ntoh24(fh
->fh_d_id
) != FC_FID_FLOGI
)
656 * If non-FIP, we may have gotten an SID by accepting an FLOGI
657 * from a point-to-point connection. Switch to using
658 * the source mac based on the SID. The destination
659 * MAC in this case would have been set by receiving the
662 if (fip
->state
== FIP_ST_NON_FIP
) {
663 if (fip
->flogi_oxid
== FC_XID_UNKNOWN
)
665 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
666 fc_fcoe_set_mac(mac
, fh
->fh_d_id
);
667 fip
->update_mac(lport
, mac
);
676 if (fip
->state
!= FIP_ST_ENABLED
&&
677 fip
->state
!= FIP_ST_VNMP_UP
)
681 LIBFCOE_FIP_DBG(fip
, "els_send op %u d_id %x\n",
682 op
, ntoh24(fh
->fh_d_id
));
683 if (fcoe_ctlr_encaps(fip
, lport
, op
, skb
, ntoh24(fh
->fh_d_id
)))
691 EXPORT_SYMBOL(fcoe_ctlr_els_send
);
694 * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller
695 * @fip: The FCoE controller to free FCFs on
697 * Called with lock held and preemption disabled.
699 * An FCF is considered old if we have missed two advertisements.
700 * That is, there have been no valid advertisement from it for 2.5
701 * times its keep-alive period.
703 * In addition, determine the time when an FCF selection can occur.
705 * Also, increment the MissDiscAdvCount when no advertisement is received
706 * for the corresponding FCF for 1.5 * FKA_ADV_PERIOD (FC-BB-5 LESB).
708 * Returns the time in jiffies for the next call.
710 static unsigned long fcoe_ctlr_age_fcfs(struct fcoe_ctlr
*fip
)
712 struct fcoe_fcf
*fcf
;
713 struct fcoe_fcf
*next
;
714 unsigned long next_timer
= jiffies
+ msecs_to_jiffies(FIP_VN_KA_PERIOD
);
715 unsigned long deadline
;
716 unsigned long sel_time
= 0;
717 struct fcoe_dev_stats
*stats
;
719 stats
= per_cpu_ptr(fip
->lp
->dev_stats
, get_cpu());
721 list_for_each_entry_safe(fcf
, next
, &fip
->fcfs
, list
) {
722 deadline
= fcf
->time
+ fcf
->fka_period
+ fcf
->fka_period
/ 2;
723 if (fip
->sel_fcf
== fcf
) {
724 if (time_after(jiffies
, deadline
)) {
725 stats
->MissDiscAdvCount
++;
726 printk(KERN_INFO
"libfcoe: host%d: "
727 "Missing Discovery Advertisement "
728 "for fab %16.16llx count %lld\n",
729 fip
->lp
->host
->host_no
, fcf
->fabric_name
,
730 stats
->MissDiscAdvCount
);
731 } else if (time_after(next_timer
, deadline
))
732 next_timer
= deadline
;
735 deadline
+= fcf
->fka_period
;
736 if (time_after_eq(jiffies
, deadline
)) {
737 if (fip
->sel_fcf
== fcf
)
739 list_del(&fcf
->list
);
740 WARN_ON(!fip
->fcf_count
);
743 stats
->VLinkFailureCount
++;
745 if (time_after(next_timer
, deadline
))
746 next_timer
= deadline
;
747 if (fcoe_ctlr_mtu_valid(fcf
) &&
748 (!sel_time
|| time_before(sel_time
, fcf
->time
)))
749 sel_time
= fcf
->time
;
753 if (sel_time
&& !fip
->sel_fcf
&& !fip
->sel_time
) {
754 sel_time
+= msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
755 fip
->sel_time
= sel_time
;
762 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry
763 * @fip: The FCoE controller receiving the advertisement
764 * @skb: The received FIP advertisement frame
765 * @fcf: The resulting FCF entry
767 * Returns zero on a valid parsed advertisement,
768 * otherwise returns non zero value.
770 static int fcoe_ctlr_parse_adv(struct fcoe_ctlr
*fip
,
771 struct sk_buff
*skb
, struct fcoe_fcf
*fcf
)
773 struct fip_header
*fiph
;
774 struct fip_desc
*desc
= NULL
;
775 struct fip_wwn_desc
*wwn
;
776 struct fip_fab_desc
*fab
;
777 struct fip_fka_desc
*fka
;
783 memset(fcf
, 0, sizeof(*fcf
));
784 fcf
->fka_period
= msecs_to_jiffies(FCOE_CTLR_DEF_FKA
);
786 fiph
= (struct fip_header
*)skb
->data
;
787 fcf
->flags
= ntohs(fiph
->fip_flags
);
790 * mask of required descriptors. validating each one clears its bit.
792 desc_mask
= BIT(FIP_DT_PRI
) | BIT(FIP_DT_MAC
) | BIT(FIP_DT_NAME
) |
793 BIT(FIP_DT_FAB
) | BIT(FIP_DT_FKA
);
795 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
796 if (rlen
+ sizeof(*fiph
) > skb
->len
)
799 desc
= (struct fip_desc
*)(fiph
+ 1);
801 dlen
= desc
->fip_dlen
* FIP_BPW
;
802 if (dlen
< sizeof(*desc
) || dlen
> rlen
)
804 /* Drop Adv if there are duplicate critical descriptors */
805 if ((desc
->fip_dtype
< 32) &&
806 !(desc_mask
& 1U << desc
->fip_dtype
)) {
807 LIBFCOE_FIP_DBG(fip
, "Duplicate Critical "
808 "Descriptors in FIP adv\n");
811 switch (desc
->fip_dtype
) {
813 if (dlen
!= sizeof(struct fip_pri_desc
))
815 fcf
->pri
= ((struct fip_pri_desc
*)desc
)->fd_pri
;
816 desc_mask
&= ~BIT(FIP_DT_PRI
);
819 if (dlen
!= sizeof(struct fip_mac_desc
))
822 ((struct fip_mac_desc
*)desc
)->fd_mac
,
824 if (!is_valid_ether_addr(fcf
->fcf_mac
)) {
826 "Invalid MAC addr %pM in FIP adv\n",
830 desc_mask
&= ~BIT(FIP_DT_MAC
);
833 if (dlen
!= sizeof(struct fip_wwn_desc
))
835 wwn
= (struct fip_wwn_desc
*)desc
;
836 fcf
->switch_name
= get_unaligned_be64(&wwn
->fd_wwn
);
837 desc_mask
&= ~BIT(FIP_DT_NAME
);
840 if (dlen
!= sizeof(struct fip_fab_desc
))
842 fab
= (struct fip_fab_desc
*)desc
;
843 fcf
->fabric_name
= get_unaligned_be64(&fab
->fd_wwn
);
844 fcf
->vfid
= ntohs(fab
->fd_vfid
);
845 fcf
->fc_map
= ntoh24(fab
->fd_map
);
846 desc_mask
&= ~BIT(FIP_DT_FAB
);
849 if (dlen
!= sizeof(struct fip_fka_desc
))
851 fka
= (struct fip_fka_desc
*)desc
;
852 if (fka
->fd_flags
& FIP_FKA_ADV_D
)
854 t
= ntohl(fka
->fd_fka_period
);
855 if (t
>= FCOE_CTLR_MIN_FKA
)
856 fcf
->fka_period
= msecs_to_jiffies(t
);
857 desc_mask
&= ~BIT(FIP_DT_FKA
);
860 case FIP_DT_FCOE_SIZE
:
866 LIBFCOE_FIP_DBG(fip
, "unexpected descriptor type %x "
867 "in FIP adv\n", desc
->fip_dtype
);
868 /* standard says ignore unknown descriptors >= 128 */
869 if (desc
->fip_dtype
< FIP_DT_VENDOR_BASE
)
873 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
876 if (!fcf
->fc_map
|| (fcf
->fc_map
& 0x10000))
878 if (!fcf
->switch_name
)
881 LIBFCOE_FIP_DBG(fip
, "adv missing descriptors mask %x\n",
888 LIBFCOE_FIP_DBG(fip
, "FIP length error in descriptor type %x len %zu\n",
889 desc
->fip_dtype
, dlen
);
894 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement
895 * @fip: The FCoE controller receiving the advertisement
896 * @skb: The received FIP packet
898 static void fcoe_ctlr_recv_adv(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
900 struct fcoe_fcf
*fcf
;
902 struct fcoe_fcf
*found
;
903 unsigned long sol_tov
= msecs_to_jiffies(FCOE_CTRL_SOL_TOV
);
907 if (fcoe_ctlr_parse_adv(fip
, skb
, &new))
910 mutex_lock(&fip
->ctlr_mutex
);
911 first
= list_empty(&fip
->fcfs
);
913 list_for_each_entry(fcf
, &fip
->fcfs
, list
) {
914 if (fcf
->switch_name
== new.switch_name
&&
915 fcf
->fabric_name
== new.fabric_name
&&
916 fcf
->fc_map
== new.fc_map
&&
917 compare_ether_addr(fcf
->fcf_mac
, new.fcf_mac
) == 0) {
923 if (fip
->fcf_count
>= FCOE_CTLR_FCF_LIMIT
)
926 fcf
= kmalloc(sizeof(*fcf
), GFP_ATOMIC
);
931 memcpy(fcf
, &new, sizeof(new));
932 list_add(&fcf
->list
, &fip
->fcfs
);
935 * Update the FCF's keep-alive descriptor flags.
936 * Other flag changes from new advertisements are
937 * ignored after a solicited advertisement is
938 * received and the FCF is selectable (usable).
940 fcf
->fd_flags
= new.fd_flags
;
941 if (!fcoe_ctlr_fcf_usable(fcf
))
942 fcf
->flags
= new.flags
;
944 if (fcf
== fip
->sel_fcf
&& !fcf
->fd_flags
) {
945 fip
->ctlr_ka_time
-= fcf
->fka_period
;
946 fip
->ctlr_ka_time
+= new.fka_period
;
947 if (time_before(fip
->ctlr_ka_time
, fip
->timer
.expires
))
948 mod_timer(&fip
->timer
, fip
->ctlr_ka_time
);
950 fcf
->fka_period
= new.fka_period
;
951 memcpy(fcf
->fcf_mac
, new.fcf_mac
, ETH_ALEN
);
953 mtu_valid
= fcoe_ctlr_mtu_valid(fcf
);
956 LIBFCOE_FIP_DBG(fip
, "New FCF fab %16.16llx mac %pM\n",
957 fcf
->fabric_name
, fcf
->fcf_mac
);
960 * If this advertisement is not solicited and our max receive size
961 * hasn't been verified, send a solicited advertisement.
964 fcoe_ctlr_solicit(fip
, fcf
);
967 * If its been a while since we did a solicit, and this is
968 * the first advertisement we've received, do a multicast
969 * solicitation to gather as many advertisements as we can
970 * before selection occurs.
972 if (first
&& time_after(jiffies
, fip
->sol_time
+ sol_tov
))
973 fcoe_ctlr_solicit(fip
, NULL
);
976 * Put this FCF at the head of the list for priority among equals.
977 * This helps in the case of an NPV switch which insists we use
978 * the FCF that answers multicast solicitations, not the others that
979 * are sending periodic multicast advertisements.
982 list_move(&fcf
->list
, &fip
->fcfs
);
985 * If this is the first validated FCF, note the time and
986 * set a timer to trigger selection.
988 if (mtu_valid
&& !fip
->sel_fcf
&& fcoe_ctlr_fcf_usable(fcf
)) {
989 fip
->sel_time
= jiffies
+
990 msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
991 if (!timer_pending(&fip
->timer
) ||
992 time_before(fip
->sel_time
, fip
->timer
.expires
))
993 mod_timer(&fip
->timer
, fip
->sel_time
);
996 mutex_unlock(&fip
->ctlr_mutex
);
1000 * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame
1001 * @fip: The FCoE controller which received the packet
1002 * @skb: The received FIP packet
1004 static void fcoe_ctlr_recv_els(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1006 struct fc_lport
*lport
= fip
->lp
;
1007 struct fip_header
*fiph
;
1008 struct fc_frame
*fp
= (struct fc_frame
*)skb
;
1009 struct fc_frame_header
*fh
= NULL
;
1010 struct fip_desc
*desc
;
1011 struct fip_encaps
*els
;
1012 struct fcoe_dev_stats
*stats
;
1013 enum fip_desc_type els_dtype
= 0;
1016 u8 granted_mac
[ETH_ALEN
] = { 0 };
1023 fiph
= (struct fip_header
*)skb
->data
;
1024 sub
= fiph
->fip_subcode
;
1025 if (sub
!= FIP_SC_REQ
&& sub
!= FIP_SC_REP
)
1028 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
1029 if (rlen
+ sizeof(*fiph
) > skb
->len
)
1032 desc
= (struct fip_desc
*)(fiph
+ 1);
1035 dlen
= desc
->fip_dlen
* FIP_BPW
;
1036 if (dlen
< sizeof(*desc
) || dlen
> rlen
)
1038 /* Drop ELS if there are duplicate critical descriptors */
1039 if (desc
->fip_dtype
< 32) {
1040 if (desc_mask
& 1U << desc
->fip_dtype
) {
1041 LIBFCOE_FIP_DBG(fip
, "Duplicate Critical "
1042 "Descriptors in FIP ELS\n");
1045 desc_mask
|= (1 << desc
->fip_dtype
);
1047 switch (desc
->fip_dtype
) {
1049 if (desc_cnt
== 1) {
1050 LIBFCOE_FIP_DBG(fip
, "FIP descriptors "
1051 "received out of order\n");
1055 if (dlen
!= sizeof(struct fip_mac_desc
))
1058 ((struct fip_mac_desc
*)desc
)->fd_mac
,
1065 if (desc_cnt
!= 1) {
1066 LIBFCOE_FIP_DBG(fip
, "FIP descriptors "
1067 "received out of order\n");
1072 if (dlen
< sizeof(*els
) + sizeof(*fh
) + 1)
1074 els_len
= dlen
- sizeof(*els
);
1075 els
= (struct fip_encaps
*)desc
;
1076 fh
= (struct fc_frame_header
*)(els
+ 1);
1077 els_dtype
= desc
->fip_dtype
;
1080 LIBFCOE_FIP_DBG(fip
, "unexpected descriptor type %x "
1081 "in FIP adv\n", desc
->fip_dtype
);
1082 /* standard says ignore unknown descriptors >= 128 */
1083 if (desc
->fip_dtype
< FIP_DT_VENDOR_BASE
)
1085 if (desc_cnt
<= 2) {
1086 LIBFCOE_FIP_DBG(fip
, "FIP descriptors "
1087 "received out of order\n");
1092 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
1098 els_op
= *(u8
*)(fh
+ 1);
1100 if ((els_dtype
== FIP_DT_FLOGI
|| els_dtype
== FIP_DT_FDISC
) &&
1101 sub
== FIP_SC_REP
&& fip
->mode
!= FIP_MODE_VN2VN
) {
1102 if (els_op
== ELS_LS_ACC
) {
1103 if (!is_valid_ether_addr(granted_mac
)) {
1104 LIBFCOE_FIP_DBG(fip
,
1105 "Invalid MAC address %pM in FIP ELS\n",
1109 memcpy(fr_cb(fp
)->granted_mac
, granted_mac
, ETH_ALEN
);
1111 if (fip
->flogi_oxid
== ntohs(fh
->fh_ox_id
)) {
1112 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
1113 if (els_dtype
== FIP_DT_FLOGI
)
1114 fcoe_ctlr_announce(fip
);
1116 } else if (els_dtype
== FIP_DT_FLOGI
&&
1117 !fcoe_ctlr_flogi_retry(fip
))
1118 goto drop
; /* retrying FLOGI so drop reject */
1121 if ((desc_cnt
== 0) || ((els_op
!= ELS_LS_RJT
) &&
1122 (!(1U << FIP_DT_MAC
& desc_mask
)))) {
1123 LIBFCOE_FIP_DBG(fip
, "Missing critical descriptors "
1129 * Convert skb into an fc_frame containing only the ELS.
1131 skb_pull(skb
, (u8
*)fh
- skb
->data
);
1132 skb_trim(skb
, els_len
);
1133 fp
= (struct fc_frame
*)skb
;
1135 fr_sof(fp
) = FC_SOF_I3
;
1136 fr_eof(fp
) = FC_EOF_T
;
1138 fr_encaps(fp
) = els_dtype
;
1140 stats
= per_cpu_ptr(lport
->dev_stats
, get_cpu());
1142 stats
->RxWords
+= skb
->len
/ FIP_BPW
;
1145 fc_exch_recv(lport
, fp
);
1149 LIBFCOE_FIP_DBG(fip
, "FIP length error in descriptor type %x len %zu\n",
1150 desc
->fip_dtype
, dlen
);
1156 * fcoe_ctlr_recv_els() - Handle an incoming link reset frame
1157 * @fip: The FCoE controller that received the frame
1158 * @fh: The received FIP header
1160 * There may be multiple VN_Port descriptors.
1161 * The overall length has already been checked.
1163 static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr
*fip
,
1164 struct fip_header
*fh
)
1166 struct fip_desc
*desc
;
1167 struct fip_mac_desc
*mp
;
1168 struct fip_wwn_desc
*wp
;
1169 struct fip_vn_desc
*vp
;
1172 struct fcoe_fcf
*fcf
= fip
->sel_fcf
;
1173 struct fc_lport
*lport
= fip
->lp
;
1174 struct fc_lport
*vn_port
= NULL
;
1177 int reset_phys_port
= 0;
1178 struct fip_vn_desc
**vlink_desc_arr
= NULL
;
1180 LIBFCOE_FIP_DBG(fip
, "Clear Virtual Link received\n");
1182 if (!fcf
|| !lport
->port_id
)
1186 * mask of required descriptors. Validating each one clears its bit.
1188 desc_mask
= BIT(FIP_DT_MAC
) | BIT(FIP_DT_NAME
);
1190 rlen
= ntohs(fh
->fip_dl_len
) * FIP_BPW
;
1191 desc
= (struct fip_desc
*)(fh
+ 1);
1194 * Actually need to subtract 'sizeof(*mp) - sizeof(*wp)' from 'rlen'
1195 * before determining max Vx_Port descriptor but a buggy FCF could have
1196 * omited either or both MAC Address and Name Identifier descriptors
1198 num_vlink_desc
= rlen
/ sizeof(*vp
);
1200 vlink_desc_arr
= kmalloc(sizeof(vp
) * num_vlink_desc
,
1202 if (!vlink_desc_arr
)
1206 while (rlen
>= sizeof(*desc
)) {
1207 dlen
= desc
->fip_dlen
* FIP_BPW
;
1210 /* Drop CVL if there are duplicate critical descriptors */
1211 if ((desc
->fip_dtype
< 32) &&
1212 (desc
->fip_dtype
!= FIP_DT_VN_ID
) &&
1213 !(desc_mask
& 1U << desc
->fip_dtype
)) {
1214 LIBFCOE_FIP_DBG(fip
, "Duplicate Critical "
1215 "Descriptors in FIP CVL\n");
1218 switch (desc
->fip_dtype
) {
1220 mp
= (struct fip_mac_desc
*)desc
;
1221 if (dlen
< sizeof(*mp
))
1223 if (compare_ether_addr(mp
->fd_mac
, fcf
->fcf_mac
))
1225 desc_mask
&= ~BIT(FIP_DT_MAC
);
1228 wp
= (struct fip_wwn_desc
*)desc
;
1229 if (dlen
< sizeof(*wp
))
1231 if (get_unaligned_be64(&wp
->fd_wwn
) != fcf
->switch_name
)
1233 desc_mask
&= ~BIT(FIP_DT_NAME
);
1236 vp
= (struct fip_vn_desc
*)desc
;
1237 if (dlen
< sizeof(*vp
))
1239 vlink_desc_arr
[num_vlink_desc
++] = vp
;
1240 vn_port
= fc_vport_id_lookup(lport
,
1241 ntoh24(vp
->fd_fc_id
));
1242 if (vn_port
&& (vn_port
== lport
)) {
1243 mutex_lock(&fip
->ctlr_mutex
);
1244 per_cpu_ptr(lport
->dev_stats
,
1245 get_cpu())->VLinkFailureCount
++;
1247 fcoe_ctlr_reset(fip
);
1248 mutex_unlock(&fip
->ctlr_mutex
);
1252 /* standard says ignore unknown descriptors >= 128 */
1253 if (desc
->fip_dtype
< FIP_DT_VENDOR_BASE
)
1257 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
1262 * reset only if all required descriptors were present and valid.
1265 LIBFCOE_FIP_DBG(fip
, "missing descriptors mask %x\n",
1267 else if (!num_vlink_desc
) {
1268 LIBFCOE_FIP_DBG(fip
, "CVL: no Vx_Port descriptor found\n");
1270 * No Vx_Port description. Clear all NPIV ports,
1271 * followed by physical port
1273 mutex_lock(&lport
->lp_mutex
);
1274 list_for_each_entry(vn_port
, &lport
->vports
, list
)
1275 fc_lport_reset(vn_port
);
1276 mutex_unlock(&lport
->lp_mutex
);
1278 mutex_lock(&fip
->ctlr_mutex
);
1279 per_cpu_ptr(lport
->dev_stats
,
1280 get_cpu())->VLinkFailureCount
++;
1282 fcoe_ctlr_reset(fip
);
1283 mutex_unlock(&fip
->ctlr_mutex
);
1285 fc_lport_reset(fip
->lp
);
1286 fcoe_ctlr_solicit(fip
, NULL
);
1290 LIBFCOE_FIP_DBG(fip
, "performing Clear Virtual Link\n");
1291 for (i
= 0; i
< num_vlink_desc
; i
++) {
1292 vp
= vlink_desc_arr
[i
];
1293 vn_port
= fc_vport_id_lookup(lport
,
1294 ntoh24(vp
->fd_fc_id
));
1299 * 'port_id' is already validated, check MAC address and
1302 if (compare_ether_addr(fip
->get_src_addr(vn_port
),
1304 get_unaligned_be64(&vp
->fd_wwpn
) !=
1308 if (vn_port
== lport
)
1310 * Physical port, defer processing till all
1311 * listed NPIV ports are cleared
1313 reset_phys_port
= 1;
1314 else /* NPIV port */
1315 fc_lport_reset(vn_port
);
1318 if (reset_phys_port
) {
1319 fc_lport_reset(fip
->lp
);
1320 fcoe_ctlr_solicit(fip
, NULL
);
1325 kfree(vlink_desc_arr
);
1329 * fcoe_ctlr_recv() - Receive a FIP packet
1330 * @fip: The FCoE controller that received the packet
1331 * @skb: The received FIP packet
1333 * This may be called from either NET_RX_SOFTIRQ or IRQ.
1335 void fcoe_ctlr_recv(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1337 skb_queue_tail(&fip
->fip_recv_list
, skb
);
1338 schedule_work(&fip
->recv_work
);
1340 EXPORT_SYMBOL(fcoe_ctlr_recv
);
1343 * fcoe_ctlr_recv_handler() - Receive a FIP frame
1344 * @fip: The FCoE controller that received the frame
1345 * @skb: The received FIP frame
1347 * Returns non-zero if the frame is dropped.
1349 static int fcoe_ctlr_recv_handler(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1351 struct fip_header
*fiph
;
1353 enum fip_state state
;
1357 if (skb_linearize(skb
))
1359 if (skb
->len
< sizeof(*fiph
))
1362 if (fip
->mode
== FIP_MODE_VN2VN
) {
1363 if (compare_ether_addr(eh
->h_dest
, fip
->ctl_src_addr
) &&
1364 compare_ether_addr(eh
->h_dest
, fcoe_all_vn2vn
) &&
1365 compare_ether_addr(eh
->h_dest
, fcoe_all_p2p
))
1367 } else if (compare_ether_addr(eh
->h_dest
, fip
->ctl_src_addr
) &&
1368 compare_ether_addr(eh
->h_dest
, fcoe_all_enode
))
1370 fiph
= (struct fip_header
*)skb
->data
;
1371 op
= ntohs(fiph
->fip_op
);
1372 sub
= fiph
->fip_subcode
;
1374 if (FIP_VER_DECAPS(fiph
->fip_ver
) != FIP_VER
)
1376 if (ntohs(fiph
->fip_dl_len
) * FIP_BPW
+ sizeof(*fiph
) > skb
->len
)
1379 mutex_lock(&fip
->ctlr_mutex
);
1381 if (state
== FIP_ST_AUTO
) {
1383 fcoe_ctlr_set_state(fip
, FIP_ST_ENABLED
);
1384 state
= FIP_ST_ENABLED
;
1385 LIBFCOE_FIP_DBG(fip
, "Using FIP mode\n");
1387 mutex_unlock(&fip
->ctlr_mutex
);
1389 if (fip
->mode
== FIP_MODE_VN2VN
&& op
== FIP_OP_VN2VN
)
1390 return fcoe_ctlr_vn_recv(fip
, skb
);
1392 if (state
!= FIP_ST_ENABLED
&& state
!= FIP_ST_VNMP_UP
&&
1393 state
!= FIP_ST_VNMP_CLAIM
)
1396 if (op
== FIP_OP_LS
) {
1397 fcoe_ctlr_recv_els(fip
, skb
); /* consumes skb */
1401 if (state
!= FIP_ST_ENABLED
)
1404 if (op
== FIP_OP_DISC
&& sub
== FIP_SC_ADV
)
1405 fcoe_ctlr_recv_adv(fip
, skb
);
1406 else if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_CLR_VLINK
)
1407 fcoe_ctlr_recv_clr_vlink(fip
, fiph
);
1416 * fcoe_ctlr_select() - Select the best FCF (if possible)
1417 * @fip: The FCoE controller
1419 * Returns the selected FCF, or NULL if none are usable.
1421 * If there are conflicting advertisements, no FCF can be chosen.
1423 * If there is already a selected FCF, this will choose a better one or
1424 * an equivalent one that hasn't already been sent a FLOGI.
1426 * Called with lock held.
1428 static struct fcoe_fcf
*fcoe_ctlr_select(struct fcoe_ctlr
*fip
)
1430 struct fcoe_fcf
*fcf
;
1431 struct fcoe_fcf
*best
= fip
->sel_fcf
;
1432 struct fcoe_fcf
*first
;
1434 first
= list_first_entry(&fip
->fcfs
, struct fcoe_fcf
, list
);
1436 list_for_each_entry(fcf
, &fip
->fcfs
, list
) {
1437 LIBFCOE_FIP_DBG(fip
, "consider FCF fab %16.16llx "
1438 "VFID %d mac %pM map %x val %d "
1440 fcf
->fabric_name
, fcf
->vfid
, fcf
->fcf_mac
,
1441 fcf
->fc_map
, fcoe_ctlr_mtu_valid(fcf
),
1442 fcf
->flogi_sent
, fcf
->pri
);
1443 if (fcf
->fabric_name
!= first
->fabric_name
||
1444 fcf
->vfid
!= first
->vfid
||
1445 fcf
->fc_map
!= first
->fc_map
) {
1446 LIBFCOE_FIP_DBG(fip
, "Conflicting fabric, VFID, "
1450 if (fcf
->flogi_sent
)
1452 if (!fcoe_ctlr_fcf_usable(fcf
)) {
1453 LIBFCOE_FIP_DBG(fip
, "FCF for fab %16.16llx "
1454 "map %x %svalid %savailable\n",
1455 fcf
->fabric_name
, fcf
->fc_map
,
1456 (fcf
->flags
& FIP_FL_SOL
) ? "" : "in",
1457 (fcf
->flags
& FIP_FL_AVAIL
) ?
1461 if (!best
|| fcf
->pri
< best
->pri
|| best
->flogi_sent
)
1464 fip
->sel_fcf
= best
;
1466 LIBFCOE_FIP_DBG(fip
, "using FCF mac %pM\n", best
->fcf_mac
);
1467 fip
->port_ka_time
= jiffies
+
1468 msecs_to_jiffies(FIP_VN_KA_PERIOD
);
1469 fip
->ctlr_ka_time
= jiffies
+ best
->fka_period
;
1470 if (time_before(fip
->ctlr_ka_time
, fip
->timer
.expires
))
1471 mod_timer(&fip
->timer
, fip
->ctlr_ka_time
);
1477 * fcoe_ctlr_flogi_send_locked() - send FIP-encapsulated FLOGI to current FCF
1478 * @fip: The FCoE controller
1480 * Returns non-zero error if it could not be sent.
1482 * Called with ctlr_mutex and ctlr_lock held.
1483 * Caller must verify that fip->sel_fcf is not NULL.
1485 static int fcoe_ctlr_flogi_send_locked(struct fcoe_ctlr
*fip
)
1487 struct sk_buff
*skb
;
1488 struct sk_buff
*skb_orig
;
1489 struct fc_frame_header
*fh
;
1492 skb_orig
= fip
->flogi_req
;
1497 * Clone and send the FLOGI request. If clone fails, use original.
1499 skb
= skb_clone(skb_orig
, GFP_ATOMIC
);
1502 fip
->flogi_req
= NULL
;
1504 fh
= (struct fc_frame_header
*)skb
->data
;
1505 error
= fcoe_ctlr_encaps(fip
, fip
->lp
, FIP_DT_FLOGI
, skb
,
1506 ntoh24(fh
->fh_d_id
));
1511 fip
->send(fip
, skb
);
1512 fip
->sel_fcf
->flogi_sent
= 1;
1517 * fcoe_ctlr_flogi_retry() - resend FLOGI request to a new FCF if possible
1518 * @fip: The FCoE controller
1520 * Returns non-zero error code if there's no FLOGI request to retry or
1521 * no alternate FCF available.
1523 static int fcoe_ctlr_flogi_retry(struct fcoe_ctlr
*fip
)
1525 struct fcoe_fcf
*fcf
;
1528 mutex_lock(&fip
->ctlr_mutex
);
1529 spin_lock_bh(&fip
->ctlr_lock
);
1530 LIBFCOE_FIP_DBG(fip
, "re-sending FLOGI - reselect\n");
1531 fcf
= fcoe_ctlr_select(fip
);
1532 if (!fcf
|| fcf
->flogi_sent
) {
1533 kfree_skb(fip
->flogi_req
);
1534 fip
->flogi_req
= NULL
;
1537 fcoe_ctlr_solicit(fip
, NULL
);
1538 error
= fcoe_ctlr_flogi_send_locked(fip
);
1540 spin_unlock_bh(&fip
->ctlr_lock
);
1541 mutex_unlock(&fip
->ctlr_mutex
);
1547 * fcoe_ctlr_flogi_send() - Handle sending of FIP FLOGI.
1548 * @fip: The FCoE controller that timed out
1550 * Done here because fcoe_ctlr_els_send() can't get mutex.
1552 * Called with ctlr_mutex held. The caller must not hold ctlr_lock.
1554 static void fcoe_ctlr_flogi_send(struct fcoe_ctlr
*fip
)
1556 struct fcoe_fcf
*fcf
;
1558 spin_lock_bh(&fip
->ctlr_lock
);
1560 if (!fcf
|| !fip
->flogi_req_send
)
1563 LIBFCOE_FIP_DBG(fip
, "sending FLOGI\n");
1566 * If this FLOGI is being sent due to a timeout retry
1567 * to the same FCF as before, select a different FCF if possible.
1569 if (fcf
->flogi_sent
) {
1570 LIBFCOE_FIP_DBG(fip
, "sending FLOGI - reselect\n");
1571 fcf
= fcoe_ctlr_select(fip
);
1572 if (!fcf
|| fcf
->flogi_sent
) {
1573 LIBFCOE_FIP_DBG(fip
, "sending FLOGI - clearing\n");
1574 list_for_each_entry(fcf
, &fip
->fcfs
, list
)
1575 fcf
->flogi_sent
= 0;
1576 fcf
= fcoe_ctlr_select(fip
);
1580 fcoe_ctlr_flogi_send_locked(fip
);
1581 fip
->flogi_req_send
= 0;
1583 LIBFCOE_FIP_DBG(fip
, "No FCF selected - defer send\n");
1585 spin_unlock_bh(&fip
->ctlr_lock
);
1589 * fcoe_ctlr_timeout() - FIP timeout handler
1590 * @arg: The FCoE controller that timed out
1592 static void fcoe_ctlr_timeout(unsigned long arg
)
1594 struct fcoe_ctlr
*fip
= (struct fcoe_ctlr
*)arg
;
1596 schedule_work(&fip
->timer_work
);
1600 * fcoe_ctlr_timer_work() - Worker thread function for timer work
1601 * @work: Handle to a FCoE controller
1603 * Ages FCFs. Triggers FCF selection if possible.
1604 * Sends keep-alives and resets.
1606 static void fcoe_ctlr_timer_work(struct work_struct
*work
)
1608 struct fcoe_ctlr
*fip
;
1609 struct fc_lport
*vport
;
1612 u8 send_ctlr_ka
= 0;
1613 u8 send_port_ka
= 0;
1614 struct fcoe_fcf
*sel
;
1615 struct fcoe_fcf
*fcf
;
1616 unsigned long next_timer
;
1618 fip
= container_of(work
, struct fcoe_ctlr
, timer_work
);
1619 if (fip
->mode
== FIP_MODE_VN2VN
)
1620 return fcoe_ctlr_vn_timeout(fip
);
1621 mutex_lock(&fip
->ctlr_mutex
);
1622 if (fip
->state
== FIP_ST_DISABLED
) {
1623 mutex_unlock(&fip
->ctlr_mutex
);
1628 next_timer
= fcoe_ctlr_age_fcfs(fip
);
1631 if (!sel
&& fip
->sel_time
) {
1632 if (time_after_eq(jiffies
, fip
->sel_time
)) {
1633 sel
= fcoe_ctlr_select(fip
);
1635 } else if (time_after(next_timer
, fip
->sel_time
))
1636 next_timer
= fip
->sel_time
;
1639 if (sel
&& fip
->flogi_req_send
)
1640 fcoe_ctlr_flogi_send(fip
);
1641 else if (!sel
&& fcf
)
1644 if (sel
&& !sel
->fd_flags
) {
1645 if (time_after_eq(jiffies
, fip
->ctlr_ka_time
)) {
1646 fip
->ctlr_ka_time
= jiffies
+ sel
->fka_period
;
1649 if (time_after(next_timer
, fip
->ctlr_ka_time
))
1650 next_timer
= fip
->ctlr_ka_time
;
1652 if (time_after_eq(jiffies
, fip
->port_ka_time
)) {
1653 fip
->port_ka_time
= jiffies
+
1654 msecs_to_jiffies(FIP_VN_KA_PERIOD
);
1657 if (time_after(next_timer
, fip
->port_ka_time
))
1658 next_timer
= fip
->port_ka_time
;
1660 if (!list_empty(&fip
->fcfs
))
1661 mod_timer(&fip
->timer
, next_timer
);
1662 mutex_unlock(&fip
->ctlr_mutex
);
1665 fc_lport_reset(fip
->lp
);
1666 /* restart things with a solicitation */
1667 fcoe_ctlr_solicit(fip
, NULL
);
1671 fcoe_ctlr_send_keep_alive(fip
, NULL
, 0, fip
->ctl_src_addr
);
1674 mutex_lock(&fip
->lp
->lp_mutex
);
1675 mac
= fip
->get_src_addr(fip
->lp
);
1676 fcoe_ctlr_send_keep_alive(fip
, fip
->lp
, 1, mac
);
1677 list_for_each_entry(vport
, &fip
->lp
->vports
, list
) {
1678 mac
= fip
->get_src_addr(vport
);
1679 fcoe_ctlr_send_keep_alive(fip
, vport
, 1, mac
);
1681 mutex_unlock(&fip
->lp
->lp_mutex
);
1686 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames
1687 * @recv_work: Handle to a FCoE controller
1689 static void fcoe_ctlr_recv_work(struct work_struct
*recv_work
)
1691 struct fcoe_ctlr
*fip
;
1692 struct sk_buff
*skb
;
1694 fip
= container_of(recv_work
, struct fcoe_ctlr
, recv_work
);
1695 while ((skb
= skb_dequeue(&fip
->fip_recv_list
)))
1696 fcoe_ctlr_recv_handler(fip
, skb
);
1700 * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response
1701 * @fip: The FCoE controller
1702 * @fp: The FC frame to snoop
1704 * Snoop potential response to FLOGI or even incoming FLOGI.
1706 * The caller has checked that we are waiting for login as indicated
1707 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1709 * The caller is responsible for freeing the frame.
1710 * Fill in the granted_mac address.
1712 * Return non-zero if the frame should not be delivered to libfc.
1714 int fcoe_ctlr_recv_flogi(struct fcoe_ctlr
*fip
, struct fc_lport
*lport
,
1715 struct fc_frame
*fp
)
1717 struct fc_frame_header
*fh
;
1721 sa
= eth_hdr(&fp
->skb
)->h_source
;
1722 fh
= fc_frame_header_get(fp
);
1723 if (fh
->fh_type
!= FC_TYPE_ELS
)
1726 op
= fc_frame_payload_op(fp
);
1727 if (op
== ELS_LS_ACC
&& fh
->fh_r_ctl
== FC_RCTL_ELS_REP
&&
1728 fip
->flogi_oxid
== ntohs(fh
->fh_ox_id
)) {
1730 mutex_lock(&fip
->ctlr_mutex
);
1731 if (fip
->state
!= FIP_ST_AUTO
&& fip
->state
!= FIP_ST_NON_FIP
) {
1732 mutex_unlock(&fip
->ctlr_mutex
);
1735 fcoe_ctlr_set_state(fip
, FIP_ST_NON_FIP
);
1736 LIBFCOE_FIP_DBG(fip
,
1737 "received FLOGI LS_ACC using non-FIP mode\n");
1741 * If the src mac addr is FC_OUI-based, then we mark the
1742 * address_mode flag to use FC_OUI-based Ethernet DA.
1743 * Otherwise we use the FCoE gateway addr
1745 if (!compare_ether_addr(sa
, (u8
[6])FC_FCOE_FLOGI_MAC
)) {
1746 fcoe_ctlr_map_dest(fip
);
1748 memcpy(fip
->dest_addr
, sa
, ETH_ALEN
);
1751 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
1752 mutex_unlock(&fip
->ctlr_mutex
);
1753 fc_fcoe_set_mac(fr_cb(fp
)->granted_mac
, fh
->fh_d_id
);
1754 } else if (op
== ELS_FLOGI
&& fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&& sa
) {
1756 * Save source MAC for point-to-point responses.
1758 mutex_lock(&fip
->ctlr_mutex
);
1759 if (fip
->state
== FIP_ST_AUTO
|| fip
->state
== FIP_ST_NON_FIP
) {
1760 memcpy(fip
->dest_addr
, sa
, ETH_ALEN
);
1762 if (fip
->state
== FIP_ST_AUTO
)
1763 LIBFCOE_FIP_DBG(fip
, "received non-FIP FLOGI. "
1764 "Setting non-FIP mode\n");
1765 fcoe_ctlr_set_state(fip
, FIP_ST_NON_FIP
);
1767 mutex_unlock(&fip
->ctlr_mutex
);
1771 EXPORT_SYMBOL(fcoe_ctlr_recv_flogi
);
1774 * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN
1775 * @mac: The MAC address to convert
1776 * @scheme: The scheme to use when converting
1777 * @port: The port indicator for converting
1779 * Returns: u64 fc world wide name
1781 u64
fcoe_wwn_from_mac(unsigned char mac
[MAX_ADDR_LEN
],
1782 unsigned int scheme
, unsigned int port
)
1787 /* The MAC is in NO, so flip only the low 48 bits */
1788 host_mac
= ((u64
) mac
[0] << 40) |
1789 ((u64
) mac
[1] << 32) |
1790 ((u64
) mac
[2] << 24) |
1791 ((u64
) mac
[3] << 16) |
1792 ((u64
) mac
[4] << 8) |
1795 WARN_ON(host_mac
>= (1ULL << 48));
1796 wwn
= host_mac
| ((u64
) scheme
<< 60);
1802 WARN_ON(port
>= 0xfff);
1803 wwn
|= (u64
) port
<< 48;
1812 EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac
);
1815 * fcoe_ctlr_rport() - return the fcoe_rport for a given fc_rport_priv
1816 * @rdata: libfc remote port
1818 static inline struct fcoe_rport
*fcoe_ctlr_rport(struct fc_rport_priv
*rdata
)
1820 return (struct fcoe_rport
*)(rdata
+ 1);
1824 * fcoe_ctlr_vn_send() - Send a FIP VN2VN Probe Request or Reply.
1825 * @fip: The FCoE controller
1826 * @sub: sub-opcode for probe request, reply, or advertisement.
1827 * @dest: The destination Ethernet MAC address
1828 * @min_len: minimum size of the Ethernet payload to be sent
1830 static void fcoe_ctlr_vn_send(struct fcoe_ctlr
*fip
,
1831 enum fip_vn2vn_subcode sub
,
1832 const u8
*dest
, size_t min_len
)
1834 struct sk_buff
*skb
;
1837 struct fip_header fip
;
1838 struct fip_mac_desc mac
;
1839 struct fip_wwn_desc wwnn
;
1840 struct fip_vn_desc vn
;
1842 struct fip_fc4_feat
*ff
;
1843 struct fip_size_desc
*size
;
1848 len
= sizeof(*frame
);
1850 if (sub
== FIP_SC_VN_CLAIM_NOTIFY
|| sub
== FIP_SC_VN_CLAIM_REP
) {
1851 dlen
= sizeof(struct fip_fc4_feat
) +
1852 sizeof(struct fip_size_desc
);
1855 dlen
+= sizeof(frame
->mac
) + sizeof(frame
->wwnn
) + sizeof(frame
->vn
);
1856 len
= max(len
, min_len
+ sizeof(struct ethhdr
));
1858 skb
= dev_alloc_skb(len
);
1862 frame
= (struct fip_frame
*)skb
->data
;
1863 memset(frame
, 0, len
);
1864 memcpy(frame
->eth
.h_dest
, dest
, ETH_ALEN
);
1865 memcpy(frame
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
1866 frame
->eth
.h_proto
= htons(ETH_P_FIP
);
1868 frame
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
1869 frame
->fip
.fip_op
= htons(FIP_OP_VN2VN
);
1870 frame
->fip
.fip_subcode
= sub
;
1871 frame
->fip
.fip_dl_len
= htons(dlen
/ FIP_BPW
);
1873 frame
->mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
1874 frame
->mac
.fd_desc
.fip_dlen
= sizeof(frame
->mac
) / FIP_BPW
;
1875 memcpy(frame
->mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
1877 frame
->wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
1878 frame
->wwnn
.fd_desc
.fip_dlen
= sizeof(frame
->wwnn
) / FIP_BPW
;
1879 put_unaligned_be64(fip
->lp
->wwnn
, &frame
->wwnn
.fd_wwn
);
1881 frame
->vn
.fd_desc
.fip_dtype
= FIP_DT_VN_ID
;
1882 frame
->vn
.fd_desc
.fip_dlen
= sizeof(frame
->vn
) / FIP_BPW
;
1883 hton24(frame
->vn
.fd_mac
, FIP_VN_FC_MAP
);
1884 hton24(frame
->vn
.fd_mac
+ 3, fip
->port_id
);
1885 hton24(frame
->vn
.fd_fc_id
, fip
->port_id
);
1886 put_unaligned_be64(fip
->lp
->wwpn
, &frame
->vn
.fd_wwpn
);
1889 * For claims, add FC-4 features.
1890 * TBD: Add interface to get fc-4 types and features from libfc.
1892 if (sub
== FIP_SC_VN_CLAIM_NOTIFY
|| sub
== FIP_SC_VN_CLAIM_REP
) {
1893 ff
= (struct fip_fc4_feat
*)(frame
+ 1);
1894 ff
->fd_desc
.fip_dtype
= FIP_DT_FC4F
;
1895 ff
->fd_desc
.fip_dlen
= sizeof(*ff
) / FIP_BPW
;
1896 ff
->fd_fts
= fip
->lp
->fcts
;
1899 if (fip
->lp
->service_params
& FCP_SPPF_INIT_FCN
)
1900 fcp_feat
|= FCP_FEAT_INIT
;
1901 if (fip
->lp
->service_params
& FCP_SPPF_TARG_FCN
)
1902 fcp_feat
|= FCP_FEAT_TARG
;
1903 fcp_feat
<<= (FC_TYPE_FCP
* 4) % 32;
1904 ff
->fd_ff
.fd_feat
[FC_TYPE_FCP
* 4 / 32] = htonl(fcp_feat
);
1906 size
= (struct fip_size_desc
*)(ff
+ 1);
1907 size
->fd_desc
.fip_dtype
= FIP_DT_FCOE_SIZE
;
1908 size
->fd_desc
.fip_dlen
= sizeof(*size
) / FIP_BPW
;
1909 size
->fd_size
= htons(fcoe_ctlr_fcoe_size(fip
));
1913 skb
->protocol
= htons(ETH_P_FIP
);
1914 skb_reset_mac_header(skb
);
1915 skb_reset_network_header(skb
);
1917 fip
->send(fip
, skb
);
1921 * fcoe_ctlr_vn_rport_callback - Event handler for rport events.
1922 * @lport: The lport which is receiving the event
1923 * @rdata: remote port private data
1924 * @event: The event that occurred
1926 * Locking Note: The rport lock must not be held when calling this function.
1928 static void fcoe_ctlr_vn_rport_callback(struct fc_lport
*lport
,
1929 struct fc_rport_priv
*rdata
,
1930 enum fc_rport_event event
)
1932 struct fcoe_ctlr
*fip
= lport
->disc
.priv
;
1933 struct fcoe_rport
*frport
= fcoe_ctlr_rport(rdata
);
1935 LIBFCOE_FIP_DBG(fip
, "vn_rport_callback %x event %d\n",
1936 rdata
->ids
.port_id
, event
);
1938 mutex_lock(&fip
->ctlr_mutex
);
1940 case RPORT_EV_READY
:
1941 frport
->login_count
= 0;
1944 case RPORT_EV_FAILED
:
1946 frport
->login_count
++;
1947 if (frport
->login_count
> FCOE_CTLR_VN2VN_LOGIN_LIMIT
) {
1948 LIBFCOE_FIP_DBG(fip
,
1949 "rport FLOGI limited port_id %6.6x\n",
1950 rdata
->ids
.port_id
);
1951 lport
->tt
.rport_logoff(rdata
);
1957 mutex_unlock(&fip
->ctlr_mutex
);
1960 static struct fc_rport_operations fcoe_ctlr_vn_rport_ops
= {
1961 .event_callback
= fcoe_ctlr_vn_rport_callback
,
1965 * fcoe_ctlr_disc_stop_locked() - stop discovery in VN2VN mode
1966 * @fip: The FCoE controller
1968 * Called with ctlr_mutex held.
1970 static void fcoe_ctlr_disc_stop_locked(struct fc_lport
*lport
)
1972 mutex_lock(&lport
->disc
.disc_mutex
);
1973 lport
->disc
.disc_callback
= NULL
;
1974 mutex_unlock(&lport
->disc
.disc_mutex
);
1978 * fcoe_ctlr_disc_stop() - stop discovery in VN2VN mode
1979 * @fip: The FCoE controller
1981 * Called through the local port template for discovery.
1982 * Called without the ctlr_mutex held.
1984 static void fcoe_ctlr_disc_stop(struct fc_lport
*lport
)
1986 struct fcoe_ctlr
*fip
= lport
->disc
.priv
;
1988 mutex_lock(&fip
->ctlr_mutex
);
1989 fcoe_ctlr_disc_stop_locked(lport
);
1990 mutex_unlock(&fip
->ctlr_mutex
);
1994 * fcoe_ctlr_disc_stop_final() - stop discovery for shutdown in VN2VN mode
1995 * @fip: The FCoE controller
1997 * Called through the local port template for discovery.
1998 * Called without the ctlr_mutex held.
2000 static void fcoe_ctlr_disc_stop_final(struct fc_lport
*lport
)
2002 fcoe_ctlr_disc_stop(lport
);
2003 lport
->tt
.rport_flush_queue();
2008 * fcoe_ctlr_vn_restart() - VN2VN probe restart with new port_id
2009 * @fip: The FCoE controller
2011 * Called with fcoe_ctlr lock held.
2013 static void fcoe_ctlr_vn_restart(struct fcoe_ctlr
*fip
)
2018 fcoe_ctlr_disc_stop_locked(fip
->lp
);
2021 * Get proposed port ID.
2022 * If this is the first try after link up, use any previous port_id.
2023 * If there was none, use the low bits of the port_name.
2024 * On subsequent tries, get the next random one.
2025 * Don't use reserved IDs, use another non-zero value, just as random.
2027 port_id
= fip
->port_id
;
2028 if (fip
->probe_tries
)
2029 port_id
= prandom32(&fip
->rnd_state
) & 0xffff;
2031 port_id
= fip
->lp
->wwpn
& 0xffff;
2032 if (!port_id
|| port_id
== 0xffff)
2034 fip
->port_id
= port_id
;
2036 if (fip
->probe_tries
< FIP_VN_RLIM_COUNT
) {
2038 wait
= random32() % FIP_VN_PROBE_WAIT
;
2040 wait
= FIP_VN_RLIM_INT
;
2041 mod_timer(&fip
->timer
, jiffies
+ msecs_to_jiffies(wait
));
2042 fcoe_ctlr_set_state(fip
, FIP_ST_VNMP_START
);
2046 * fcoe_ctlr_vn_start() - Start in VN2VN mode
2047 * @fip: The FCoE controller
2049 * Called with fcoe_ctlr lock held.
2051 static void fcoe_ctlr_vn_start(struct fcoe_ctlr
*fip
)
2053 fip
->probe_tries
= 0;
2054 prandom32_seed(&fip
->rnd_state
, fip
->lp
->wwpn
);
2055 fcoe_ctlr_vn_restart(fip
);
2059 * fcoe_ctlr_vn_parse - parse probe request or response
2060 * @fip: The FCoE controller
2061 * @skb: incoming packet
2062 * @rdata: buffer for resulting parsed VN entry plus fcoe_rport
2064 * Returns non-zero error number on error.
2065 * Does not consume the packet.
2067 static int fcoe_ctlr_vn_parse(struct fcoe_ctlr
*fip
,
2068 struct sk_buff
*skb
,
2069 struct fc_rport_priv
*rdata
)
2071 struct fip_header
*fiph
;
2072 struct fip_desc
*desc
= NULL
;
2073 struct fip_mac_desc
*macd
= NULL
;
2074 struct fip_wwn_desc
*wwn
= NULL
;
2075 struct fip_vn_desc
*vn
= NULL
;
2076 struct fip_size_desc
*size
= NULL
;
2077 struct fcoe_rport
*frport
;
2084 memset(rdata
, 0, sizeof(*rdata
) + sizeof(*frport
));
2085 frport
= fcoe_ctlr_rport(rdata
);
2087 fiph
= (struct fip_header
*)skb
->data
;
2088 frport
->flags
= ntohs(fiph
->fip_flags
);
2090 sub
= fiph
->fip_subcode
;
2092 case FIP_SC_VN_PROBE_REQ
:
2093 case FIP_SC_VN_PROBE_REP
:
2094 case FIP_SC_VN_BEACON
:
2095 desc_mask
= BIT(FIP_DT_MAC
) | BIT(FIP_DT_NAME
) |
2098 case FIP_SC_VN_CLAIM_NOTIFY
:
2099 case FIP_SC_VN_CLAIM_REP
:
2100 desc_mask
= BIT(FIP_DT_MAC
) | BIT(FIP_DT_NAME
) |
2101 BIT(FIP_DT_VN_ID
) | BIT(FIP_DT_FC4F
) |
2102 BIT(FIP_DT_FCOE_SIZE
);
2105 LIBFCOE_FIP_DBG(fip
, "vn_parse unknown subcode %u\n", sub
);
2109 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
2110 if (rlen
+ sizeof(*fiph
) > skb
->len
)
2113 desc
= (struct fip_desc
*)(fiph
+ 1);
2115 dlen
= desc
->fip_dlen
* FIP_BPW
;
2116 if (dlen
< sizeof(*desc
) || dlen
> rlen
)
2119 dtype
= desc
->fip_dtype
;
2121 if (!(desc_mask
& BIT(dtype
))) {
2122 LIBFCOE_FIP_DBG(fip
,
2123 "unexpected or duplicated desc "
2125 "FIP VN2VN subtype %u\n",
2129 desc_mask
&= ~BIT(dtype
);
2134 if (dlen
!= sizeof(struct fip_mac_desc
))
2136 macd
= (struct fip_mac_desc
*)desc
;
2137 if (!is_valid_ether_addr(macd
->fd_mac
)) {
2138 LIBFCOE_FIP_DBG(fip
,
2139 "Invalid MAC addr %pM in FIP VN2VN\n",
2143 memcpy(frport
->enode_mac
, macd
->fd_mac
, ETH_ALEN
);
2146 if (dlen
!= sizeof(struct fip_wwn_desc
))
2148 wwn
= (struct fip_wwn_desc
*)desc
;
2149 rdata
->ids
.node_name
= get_unaligned_be64(&wwn
->fd_wwn
);
2152 if (dlen
!= sizeof(struct fip_vn_desc
))
2154 vn
= (struct fip_vn_desc
*)desc
;
2155 memcpy(frport
->vn_mac
, vn
->fd_mac
, ETH_ALEN
);
2156 rdata
->ids
.port_id
= ntoh24(vn
->fd_fc_id
);
2157 rdata
->ids
.port_name
= get_unaligned_be64(&vn
->fd_wwpn
);
2160 if (dlen
!= sizeof(struct fip_fc4_feat
))
2163 case FIP_DT_FCOE_SIZE
:
2164 if (dlen
!= sizeof(struct fip_size_desc
))
2166 size
= (struct fip_size_desc
*)desc
;
2167 frport
->fcoe_len
= ntohs(size
->fd_size
);
2170 LIBFCOE_FIP_DBG(fip
, "unexpected descriptor type %x "
2171 "in FIP probe\n", dtype
);
2172 /* standard says ignore unknown descriptors >= 128 */
2173 if (dtype
< FIP_DT_VENDOR_BASE
)
2177 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
2183 LIBFCOE_FIP_DBG(fip
, "FIP length error in descriptor type %x len %zu\n",
2189 * fcoe_ctlr_vn_send_claim() - send multicast FIP VN2VN Claim Notification.
2190 * @fip: The FCoE controller
2192 * Called with ctlr_mutex held.
2194 static void fcoe_ctlr_vn_send_claim(struct fcoe_ctlr
*fip
)
2196 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_CLAIM_NOTIFY
, fcoe_all_vn2vn
, 0);
2197 fip
->sol_time
= jiffies
;
2201 * fcoe_ctlr_vn_probe_req() - handle incoming VN2VN probe request.
2202 * @fip: The FCoE controller
2203 * @rdata: parsed remote port with frport from the probe request
2205 * Called with ctlr_mutex held.
2207 static void fcoe_ctlr_vn_probe_req(struct fcoe_ctlr
*fip
,
2208 struct fc_rport_priv
*rdata
)
2210 struct fcoe_rport
*frport
= fcoe_ctlr_rport(rdata
);
2212 if (rdata
->ids
.port_id
!= fip
->port_id
)
2215 switch (fip
->state
) {
2216 case FIP_ST_VNMP_CLAIM
:
2217 case FIP_ST_VNMP_UP
:
2218 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_PROBE_REP
,
2219 frport
->enode_mac
, 0);
2221 case FIP_ST_VNMP_PROBE1
:
2222 case FIP_ST_VNMP_PROBE2
:
2224 * Decide whether to reply to the Probe.
2225 * Our selected address is never a "recorded" one, so
2226 * only reply if our WWPN is greater and the
2227 * Probe's REC bit is not set.
2228 * If we don't reply, we will change our address.
2230 if (fip
->lp
->wwpn
> rdata
->ids
.port_name
&&
2231 !(frport
->flags
& FIP_FL_REC_OR_P2P
)) {
2232 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_PROBE_REP
,
2233 frport
->enode_mac
, 0);
2237 case FIP_ST_VNMP_START
:
2238 fcoe_ctlr_vn_restart(fip
);
2246 * fcoe_ctlr_vn_probe_reply() - handle incoming VN2VN probe reply.
2247 * @fip: The FCoE controller
2248 * @rdata: parsed remote port with frport from the probe request
2250 * Called with ctlr_mutex held.
2252 static void fcoe_ctlr_vn_probe_reply(struct fcoe_ctlr
*fip
,
2253 struct fc_rport_priv
*rdata
)
2255 if (rdata
->ids
.port_id
!= fip
->port_id
)
2257 switch (fip
->state
) {
2258 case FIP_ST_VNMP_START
:
2259 case FIP_ST_VNMP_PROBE1
:
2260 case FIP_ST_VNMP_PROBE2
:
2261 case FIP_ST_VNMP_CLAIM
:
2262 fcoe_ctlr_vn_restart(fip
);
2264 case FIP_ST_VNMP_UP
:
2265 fcoe_ctlr_vn_send_claim(fip
);
2273 * fcoe_ctlr_vn_add() - Add a VN2VN entry to the list, based on a claim reply.
2274 * @fip: The FCoE controller
2275 * @new: newly-parsed remote port with frport as a template for new rdata
2277 * Called with ctlr_mutex held.
2279 static void fcoe_ctlr_vn_add(struct fcoe_ctlr
*fip
, struct fc_rport_priv
*new)
2281 struct fc_lport
*lport
= fip
->lp
;
2282 struct fc_rport_priv
*rdata
;
2283 struct fc_rport_identifiers
*ids
;
2284 struct fcoe_rport
*frport
;
2287 port_id
= new->ids
.port_id
;
2288 if (port_id
== fip
->port_id
)
2291 mutex_lock(&lport
->disc
.disc_mutex
);
2292 rdata
= lport
->tt
.rport_create(lport
, port_id
);
2294 mutex_unlock(&lport
->disc
.disc_mutex
);
2298 rdata
->ops
= &fcoe_ctlr_vn_rport_ops
;
2299 rdata
->disc_id
= lport
->disc
.disc_id
;
2302 if ((ids
->port_name
!= -1 && ids
->port_name
!= new->ids
.port_name
) ||
2303 (ids
->node_name
!= -1 && ids
->node_name
!= new->ids
.node_name
))
2304 lport
->tt
.rport_logoff(rdata
);
2305 ids
->port_name
= new->ids
.port_name
;
2306 ids
->node_name
= new->ids
.node_name
;
2307 mutex_unlock(&lport
->disc
.disc_mutex
);
2309 frport
= fcoe_ctlr_rport(rdata
);
2310 LIBFCOE_FIP_DBG(fip
, "vn_add rport %6.6x %s\n",
2311 port_id
, frport
->fcoe_len
? "old" : "new");
2312 *frport
= *fcoe_ctlr_rport(new);
2317 * fcoe_ctlr_vn_lookup() - Find VN remote port's MAC address
2318 * @fip: The FCoE controller
2319 * @port_id: The port_id of the remote VN_node
2320 * @mac: buffer which will hold the VN_NODE destination MAC address, if found.
2322 * Returns non-zero error if no remote port found.
2324 static int fcoe_ctlr_vn_lookup(struct fcoe_ctlr
*fip
, u32 port_id
, u8
*mac
)
2326 struct fc_lport
*lport
= fip
->lp
;
2327 struct fc_rport_priv
*rdata
;
2328 struct fcoe_rport
*frport
;
2332 rdata
= lport
->tt
.rport_lookup(lport
, port_id
);
2334 frport
= fcoe_ctlr_rport(rdata
);
2335 memcpy(mac
, frport
->enode_mac
, ETH_ALEN
);
2343 * fcoe_ctlr_vn_claim_notify() - handle received FIP VN2VN Claim Notification
2344 * @fip: The FCoE controller
2345 * @new: newly-parsed remote port with frport as a template for new rdata
2347 * Called with ctlr_mutex held.
2349 static void fcoe_ctlr_vn_claim_notify(struct fcoe_ctlr
*fip
,
2350 struct fc_rport_priv
*new)
2352 struct fcoe_rport
*frport
= fcoe_ctlr_rport(new);
2354 if (frport
->flags
& FIP_FL_REC_OR_P2P
) {
2355 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_PROBE_REQ
, fcoe_all_vn2vn
, 0);
2358 switch (fip
->state
) {
2359 case FIP_ST_VNMP_START
:
2360 case FIP_ST_VNMP_PROBE1
:
2361 case FIP_ST_VNMP_PROBE2
:
2362 if (new->ids
.port_id
== fip
->port_id
)
2363 fcoe_ctlr_vn_restart(fip
);
2365 case FIP_ST_VNMP_CLAIM
:
2366 case FIP_ST_VNMP_UP
:
2367 if (new->ids
.port_id
== fip
->port_id
) {
2368 if (new->ids
.port_name
> fip
->lp
->wwpn
) {
2369 fcoe_ctlr_vn_restart(fip
);
2372 fcoe_ctlr_vn_send_claim(fip
);
2375 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_CLAIM_REP
, frport
->enode_mac
,
2376 min((u32
)frport
->fcoe_len
,
2377 fcoe_ctlr_fcoe_size(fip
)));
2378 fcoe_ctlr_vn_add(fip
, new);
2386 * fcoe_ctlr_vn_claim_resp() - handle received Claim Response
2387 * @fip: The FCoE controller that received the frame
2388 * @new: newly-parsed remote port with frport from the Claim Response
2390 * Called with ctlr_mutex held.
2392 static void fcoe_ctlr_vn_claim_resp(struct fcoe_ctlr
*fip
,
2393 struct fc_rport_priv
*new)
2395 LIBFCOE_FIP_DBG(fip
, "claim resp from from rport %x - state %s\n",
2396 new->ids
.port_id
, fcoe_ctlr_state(fip
->state
));
2397 if (fip
->state
== FIP_ST_VNMP_UP
|| fip
->state
== FIP_ST_VNMP_CLAIM
)
2398 fcoe_ctlr_vn_add(fip
, new);
2402 * fcoe_ctlr_vn_beacon() - handle received beacon.
2403 * @fip: The FCoE controller that received the frame
2404 * @new: newly-parsed remote port with frport from the Beacon
2406 * Called with ctlr_mutex held.
2408 static void fcoe_ctlr_vn_beacon(struct fcoe_ctlr
*fip
,
2409 struct fc_rport_priv
*new)
2411 struct fc_lport
*lport
= fip
->lp
;
2412 struct fc_rport_priv
*rdata
;
2413 struct fcoe_rport
*frport
;
2415 frport
= fcoe_ctlr_rport(new);
2416 if (frport
->flags
& FIP_FL_REC_OR_P2P
) {
2417 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_PROBE_REQ
, fcoe_all_vn2vn
, 0);
2420 mutex_lock(&lport
->disc
.disc_mutex
);
2421 rdata
= lport
->tt
.rport_lookup(lport
, new->ids
.port_id
);
2423 kref_get(&rdata
->kref
);
2424 mutex_unlock(&lport
->disc
.disc_mutex
);
2426 if (rdata
->ids
.node_name
== new->ids
.node_name
&&
2427 rdata
->ids
.port_name
== new->ids
.port_name
) {
2428 frport
= fcoe_ctlr_rport(rdata
);
2429 if (!frport
->time
&& fip
->state
== FIP_ST_VNMP_UP
)
2430 lport
->tt
.rport_login(rdata
);
2431 frport
->time
= jiffies
;
2433 kref_put(&rdata
->kref
, lport
->tt
.rport_destroy
);
2436 if (fip
->state
!= FIP_ST_VNMP_UP
)
2440 * Beacon from a new neighbor.
2441 * Send a claim notify if one hasn't been sent recently.
2442 * Don't add the neighbor yet.
2444 LIBFCOE_FIP_DBG(fip
, "beacon from new rport %x. sending claim notify\n",
2446 if (time_after(jiffies
,
2447 fip
->sol_time
+ msecs_to_jiffies(FIP_VN_ANN_WAIT
)))
2448 fcoe_ctlr_vn_send_claim(fip
);
2452 * fcoe_ctlr_vn_age() - Check for VN_ports without recent beacons
2453 * @fip: The FCoE controller
2455 * Called with ctlr_mutex held.
2456 * Called only in state FIP_ST_VNMP_UP.
2457 * Returns the soonest time for next age-out or a time far in the future.
2459 static unsigned long fcoe_ctlr_vn_age(struct fcoe_ctlr
*fip
)
2461 struct fc_lport
*lport
= fip
->lp
;
2462 struct fc_rport_priv
*rdata
;
2463 struct fcoe_rport
*frport
;
2464 unsigned long next_time
;
2465 unsigned long deadline
;
2467 next_time
= jiffies
+ msecs_to_jiffies(FIP_VN_BEACON_INT
* 10);
2468 mutex_lock(&lport
->disc
.disc_mutex
);
2469 list_for_each_entry_rcu(rdata
, &lport
->disc
.rports
, peers
) {
2470 frport
= fcoe_ctlr_rport(rdata
);
2473 deadline
= frport
->time
+
2474 msecs_to_jiffies(FIP_VN_BEACON_INT
* 25 / 10);
2475 if (time_after_eq(jiffies
, deadline
)) {
2477 LIBFCOE_FIP_DBG(fip
,
2478 "port %16.16llx fc_id %6.6x beacon expired\n",
2479 rdata
->ids
.port_name
, rdata
->ids
.port_id
);
2480 lport
->tt
.rport_logoff(rdata
);
2481 } else if (time_before(deadline
, next_time
))
2482 next_time
= deadline
;
2484 mutex_unlock(&lport
->disc
.disc_mutex
);
2489 * fcoe_ctlr_vn_recv() - Receive a FIP frame
2490 * @fip: The FCoE controller that received the frame
2491 * @skb: The received FIP frame
2493 * Returns non-zero if the frame is dropped.
2494 * Always consumes the frame.
2496 static int fcoe_ctlr_vn_recv(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
2498 struct fip_header
*fiph
;
2499 enum fip_vn2vn_subcode sub
;
2501 struct fc_rport_priv rdata
;
2502 struct fcoe_rport frport
;
2506 fiph
= (struct fip_header
*)skb
->data
;
2507 sub
= fiph
->fip_subcode
;
2509 rc
= fcoe_ctlr_vn_parse(fip
, skb
, &buf
.rdata
);
2511 LIBFCOE_FIP_DBG(fip
, "vn_recv vn_parse error %d\n", rc
);
2515 mutex_lock(&fip
->ctlr_mutex
);
2517 case FIP_SC_VN_PROBE_REQ
:
2518 fcoe_ctlr_vn_probe_req(fip
, &buf
.rdata
);
2520 case FIP_SC_VN_PROBE_REP
:
2521 fcoe_ctlr_vn_probe_reply(fip
, &buf
.rdata
);
2523 case FIP_SC_VN_CLAIM_NOTIFY
:
2524 fcoe_ctlr_vn_claim_notify(fip
, &buf
.rdata
);
2526 case FIP_SC_VN_CLAIM_REP
:
2527 fcoe_ctlr_vn_claim_resp(fip
, &buf
.rdata
);
2529 case FIP_SC_VN_BEACON
:
2530 fcoe_ctlr_vn_beacon(fip
, &buf
.rdata
);
2533 LIBFCOE_FIP_DBG(fip
, "vn_recv unknown subcode %d\n", sub
);
2537 mutex_unlock(&fip
->ctlr_mutex
);
2544 * fcoe_ctlr_disc_recv - discovery receive handler for VN2VN mode.
2545 * @lport: The local port
2546 * @fp: The received frame
2548 * This should never be called since we don't see RSCNs or other
2549 * fabric-generated ELSes.
2551 static void fcoe_ctlr_disc_recv(struct fc_lport
*lport
, struct fc_frame
*fp
)
2553 struct fc_seq_els_data rjt_data
;
2555 rjt_data
.reason
= ELS_RJT_UNSUP
;
2556 rjt_data
.explan
= ELS_EXPL_NONE
;
2557 lport
->tt
.seq_els_rsp_send(fp
, ELS_LS_RJT
, &rjt_data
);
2562 * fcoe_ctlr_disc_recv - start discovery for VN2VN mode.
2563 * @fip: The FCoE controller
2565 * This sets a flag indicating that remote ports should be created
2566 * and started for the peers we discover. We use the disc_callback
2567 * pointer as that flag. Peers already discovered are created here.
2569 * The lport lock is held during this call. The callback must be done
2570 * later, without holding either the lport or discovery locks.
2571 * The fcoe_ctlr lock may also be held during this call.
2573 static void fcoe_ctlr_disc_start(void (*callback
)(struct fc_lport
*,
2574 enum fc_disc_event
),
2575 struct fc_lport
*lport
)
2577 struct fc_disc
*disc
= &lport
->disc
;
2578 struct fcoe_ctlr
*fip
= disc
->priv
;
2580 mutex_lock(&disc
->disc_mutex
);
2581 disc
->disc_callback
= callback
;
2582 disc
->disc_id
= (disc
->disc_id
+ 2) | 1;
2584 schedule_work(&fip
->timer_work
);
2585 mutex_unlock(&disc
->disc_mutex
);
2589 * fcoe_ctlr_vn_disc() - report FIP VN_port discovery results after claim state.
2590 * @fip: The FCoE controller
2592 * Starts the FLOGI and PLOGI login process to each discovered rport for which
2593 * we've received at least one beacon.
2594 * Performs the discovery complete callback.
2596 static void fcoe_ctlr_vn_disc(struct fcoe_ctlr
*fip
)
2598 struct fc_lport
*lport
= fip
->lp
;
2599 struct fc_disc
*disc
= &lport
->disc
;
2600 struct fc_rport_priv
*rdata
;
2601 struct fcoe_rport
*frport
;
2602 void (*callback
)(struct fc_lport
*, enum fc_disc_event
);
2604 mutex_lock(&disc
->disc_mutex
);
2605 callback
= disc
->pending
? disc
->disc_callback
: NULL
;
2607 list_for_each_entry_rcu(rdata
, &disc
->rports
, peers
) {
2608 frport
= fcoe_ctlr_rport(rdata
);
2610 lport
->tt
.rport_login(rdata
);
2612 mutex_unlock(&disc
->disc_mutex
);
2614 callback(lport
, DISC_EV_SUCCESS
);
2618 * fcoe_ctlr_vn_timeout - timer work function for VN2VN mode.
2619 * @fip: The FCoE controller
2621 static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr
*fip
)
2623 unsigned long next_time
;
2625 u32 new_port_id
= 0;
2627 mutex_lock(&fip
->ctlr_mutex
);
2628 switch (fip
->state
) {
2629 case FIP_ST_VNMP_START
:
2630 fcoe_ctlr_set_state(fip
, FIP_ST_VNMP_PROBE1
);
2631 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_PROBE_REQ
, fcoe_all_vn2vn
, 0);
2632 next_time
= jiffies
+ msecs_to_jiffies(FIP_VN_PROBE_WAIT
);
2634 case FIP_ST_VNMP_PROBE1
:
2635 fcoe_ctlr_set_state(fip
, FIP_ST_VNMP_PROBE2
);
2636 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_PROBE_REQ
, fcoe_all_vn2vn
, 0);
2637 next_time
= jiffies
+ msecs_to_jiffies(FIP_VN_ANN_WAIT
);
2639 case FIP_ST_VNMP_PROBE2
:
2640 fcoe_ctlr_set_state(fip
, FIP_ST_VNMP_CLAIM
);
2641 new_port_id
= fip
->port_id
;
2642 hton24(mac
, FIP_VN_FC_MAP
);
2643 hton24(mac
+ 3, new_port_id
);
2644 fcoe_ctlr_map_dest(fip
);
2645 fip
->update_mac(fip
->lp
, mac
);
2646 fcoe_ctlr_vn_send_claim(fip
);
2647 next_time
= jiffies
+ msecs_to_jiffies(FIP_VN_ANN_WAIT
);
2649 case FIP_ST_VNMP_CLAIM
:
2651 * This may be invoked either by starting discovery so don't
2652 * go to the next state unless it's been long enough.
2654 next_time
= fip
->sol_time
+ msecs_to_jiffies(FIP_VN_ANN_WAIT
);
2655 if (time_after_eq(jiffies
, next_time
)) {
2656 fcoe_ctlr_set_state(fip
, FIP_ST_VNMP_UP
);
2657 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_BEACON
,
2659 next_time
= jiffies
+ msecs_to_jiffies(FIP_VN_ANN_WAIT
);
2660 fip
->port_ka_time
= next_time
;
2662 fcoe_ctlr_vn_disc(fip
);
2664 case FIP_ST_VNMP_UP
:
2665 next_time
= fcoe_ctlr_vn_age(fip
);
2666 if (time_after_eq(jiffies
, fip
->port_ka_time
)) {
2667 fcoe_ctlr_vn_send(fip
, FIP_SC_VN_BEACON
,
2669 fip
->port_ka_time
= jiffies
+
2670 msecs_to_jiffies(FIP_VN_BEACON_INT
+
2671 (random32() % FIP_VN_BEACON_FUZZ
));
2673 if (time_before(fip
->port_ka_time
, next_time
))
2674 next_time
= fip
->port_ka_time
;
2676 case FIP_ST_LINK_WAIT
:
2679 WARN(1, "unexpected state %d\n", fip
->state
);
2682 mod_timer(&fip
->timer
, next_time
);
2684 mutex_unlock(&fip
->ctlr_mutex
);
2686 /* If port ID is new, notify local port after dropping ctlr_mutex */
2688 fc_lport_set_local_id(fip
->lp
, new_port_id
);
2692 * fcoe_libfc_config() - Sets up libfc related properties for local port
2693 * @lp: The local port to configure libfc for
2694 * @fip: The FCoE controller in use by the local port
2695 * @tt: The libfc function template
2696 * @init_fcp: If non-zero, the FCP portion of libfc should be initialized
2698 * Returns : 0 for success
2700 int fcoe_libfc_config(struct fc_lport
*lport
, struct fcoe_ctlr
*fip
,
2701 const struct libfc_function_template
*tt
, int init_fcp
)
2703 /* Set the function pointers set by the LLDD */
2704 memcpy(&lport
->tt
, tt
, sizeof(*tt
));
2705 if (init_fcp
&& fc_fcp_init(lport
))
2707 fc_exch_init(lport
);
2708 fc_elsct_init(lport
);
2709 fc_lport_init(lport
);
2710 if (fip
->mode
== FIP_MODE_VN2VN
)
2711 lport
->rport_priv_size
= sizeof(struct fcoe_rport
);
2712 fc_rport_init(lport
);
2713 if (fip
->mode
== FIP_MODE_VN2VN
) {
2714 lport
->point_to_multipoint
= 1;
2715 lport
->tt
.disc_recv_req
= fcoe_ctlr_disc_recv
;
2716 lport
->tt
.disc_start
= fcoe_ctlr_disc_start
;
2717 lport
->tt
.disc_stop
= fcoe_ctlr_disc_stop
;
2718 lport
->tt
.disc_stop_final
= fcoe_ctlr_disc_stop_final
;
2719 mutex_init(&lport
->disc
.disc_mutex
);
2720 INIT_LIST_HEAD(&lport
->disc
.rports
);
2721 lport
->disc
.priv
= fip
;
2723 fc_disc_init(lport
);
2727 EXPORT_SYMBOL_GPL(fcoe_libfc_config
);