]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/scsi/fcoe/libfcoe.c
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 <net/rtnetlink.h>
36 #include <scsi/fc/fc_els.h>
37 #include <scsi/fc/fc_fs.h>
38 #include <scsi/fc/fc_fip.h>
39 #include <scsi/fc/fc_encaps.h>
40 #include <scsi/fc/fc_fcoe.h>
42 #include <scsi/libfc.h>
43 #include <scsi/libfcoe.h>
45 MODULE_AUTHOR("Open-FCoE.org");
46 MODULE_DESCRIPTION("FIP discovery protocol support for FCoE HBAs");
47 MODULE_LICENSE("GPL v2");
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_link_work(struct work_struct
*);
54 static void fcoe_ctlr_recv_work(struct work_struct
*);
56 static u8 fcoe_all_fcfs
[ETH_ALEN
] = FIP_ALL_FCF_MACS
;
58 unsigned int libfcoe_debug_logging
;
59 module_param_named(debug_logging
, libfcoe_debug_logging
, int, S_IRUGO
|S_IWUSR
);
60 MODULE_PARM_DESC(debug_logging
, "a bit mask of logging levels");
62 #define LIBFCOE_LOGGING 0x01 /* General logging, not categorized */
63 #define LIBFCOE_FIP_LOGGING 0x02 /* FIP logging */
65 #define LIBFCOE_CHECK_LOGGING(LEVEL, CMD) \
67 if (unlikely(libfcoe_debug_logging & LEVEL)) \
73 #define LIBFCOE_DBG(fmt, args...) \
74 LIBFCOE_CHECK_LOGGING(LIBFCOE_LOGGING, \
75 printk(KERN_INFO "libfcoe: " fmt, ##args);)
77 #define LIBFCOE_FIP_DBG(fip, fmt, args...) \
78 LIBFCOE_CHECK_LOGGING(LIBFCOE_FIP_LOGGING, \
79 printk(KERN_INFO "host%d: fip: " fmt, \
80 (fip)->lp->host->host_no, ##args);)
83 * fcoe_ctlr_mtu_valid() - Check if a FCF's MTU is valid
84 * @fcf: The FCF to check
86 * Return non-zero if FCF fcoe_size has been validated.
88 static inline int fcoe_ctlr_mtu_valid(const struct fcoe_fcf
*fcf
)
90 return (fcf
->flags
& FIP_FL_SOL
) != 0;
94 * fcoe_ctlr_fcf_usable() - Check if a FCF is usable
95 * @fcf: The FCF to check
97 * Return non-zero if the FCF is usable.
99 static inline int fcoe_ctlr_fcf_usable(struct fcoe_fcf
*fcf
)
101 u16 flags
= FIP_FL_SOL
| FIP_FL_AVAIL
;
103 return (fcf
->flags
& flags
) == flags
;
107 * fcoe_ctlr_init() - Initialize the FCoE Controller instance
108 * @fip: The FCoE controller to initialize
110 void fcoe_ctlr_init(struct fcoe_ctlr
*fip
)
112 fip
->state
= FIP_ST_LINK_WAIT
;
113 fip
->mode
= FIP_ST_AUTO
;
114 INIT_LIST_HEAD(&fip
->fcfs
);
115 spin_lock_init(&fip
->lock
);
116 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
117 setup_timer(&fip
->timer
, fcoe_ctlr_timeout
, (unsigned long)fip
);
118 INIT_WORK(&fip
->link_work
, fcoe_ctlr_link_work
);
119 INIT_WORK(&fip
->recv_work
, fcoe_ctlr_recv_work
);
120 skb_queue_head_init(&fip
->fip_recv_list
);
122 EXPORT_SYMBOL(fcoe_ctlr_init
);
125 * fcoe_ctlr_reset_fcfs() - Reset and free all FCFs for a controller
126 * @fip: The FCoE controller whose FCFs are to be reset
128 * Called with &fcoe_ctlr lock held.
130 static void fcoe_ctlr_reset_fcfs(struct fcoe_ctlr
*fip
)
132 struct fcoe_fcf
*fcf
;
133 struct fcoe_fcf
*next
;
136 list_for_each_entry_safe(fcf
, next
, &fip
->fcfs
, list
) {
137 list_del(&fcf
->list
);
145 * fcoe_ctlr_destroy() - Disable and tear down a FCoE controller
146 * @fip: The FCoE controller to tear down
148 * This is called by FCoE drivers before freeing the &fcoe_ctlr.
150 * The receive handler will have been deleted before this to guarantee
151 * that no more recv_work will be scheduled.
153 * The timer routine will simply return once we set FIP_ST_DISABLED.
154 * This guarantees that no further timeouts or work will be scheduled.
156 void fcoe_ctlr_destroy(struct fcoe_ctlr
*fip
)
158 cancel_work_sync(&fip
->recv_work
);
159 spin_lock_bh(&fip
->fip_recv_list
.lock
);
160 __skb_queue_purge(&fip
->fip_recv_list
);
161 spin_unlock_bh(&fip
->fip_recv_list
.lock
);
163 spin_lock_bh(&fip
->lock
);
164 fip
->state
= FIP_ST_DISABLED
;
165 fcoe_ctlr_reset_fcfs(fip
);
166 spin_unlock_bh(&fip
->lock
);
167 del_timer_sync(&fip
->timer
);
168 cancel_work_sync(&fip
->link_work
);
170 EXPORT_SYMBOL(fcoe_ctlr_destroy
);
173 * fcoe_ctlr_fcoe_size() - Return the maximum FCoE size required for VN_Port
174 * @fip: The FCoE controller to get the maximum FCoE size from
176 * Returns the maximum packet size including the FCoE header and trailer,
177 * but not including any Ethernet or VLAN headers.
179 static inline u32
fcoe_ctlr_fcoe_size(struct fcoe_ctlr
*fip
)
182 * Determine the max FCoE frame size allowed, including
183 * FCoE header and trailer.
184 * Note: lp->mfs is currently the payload size, not the frame size.
186 return fip
->lp
->mfs
+ sizeof(struct fc_frame_header
) +
187 sizeof(struct fcoe_hdr
) + sizeof(struct fcoe_crc_eof
);
191 * fcoe_ctlr_solicit() - Send a FIP solicitation
192 * @fip: The FCoE controller to send the solicitation on
193 * @fcf: The destination FCF (if NULL, a multicast solicitation is sent)
195 static void fcoe_ctlr_solicit(struct fcoe_ctlr
*fip
, struct fcoe_fcf
*fcf
)
200 struct fip_header fip
;
202 struct fip_mac_desc mac
;
203 struct fip_wwn_desc wwnn
;
204 struct fip_size_desc size
;
205 } __attribute__((packed
)) desc
;
206 } __attribute__((packed
)) *sol
;
209 skb
= dev_alloc_skb(sizeof(*sol
));
213 sol
= (struct fip_sol
*)skb
->data
;
215 memset(sol
, 0, sizeof(*sol
));
216 memcpy(sol
->eth
.h_dest
, fcf
? fcf
->fcf_mac
: fcoe_all_fcfs
, ETH_ALEN
);
217 memcpy(sol
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
218 sol
->eth
.h_proto
= htons(ETH_P_FIP
);
220 sol
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
221 sol
->fip
.fip_op
= htons(FIP_OP_DISC
);
222 sol
->fip
.fip_subcode
= FIP_SC_SOL
;
223 sol
->fip
.fip_dl_len
= htons(sizeof(sol
->desc
) / FIP_BPW
);
224 sol
->fip
.fip_flags
= htons(FIP_FL_FPMA
);
226 sol
->fip
.fip_flags
|= htons(FIP_FL_SPMA
);
228 sol
->desc
.mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
229 sol
->desc
.mac
.fd_desc
.fip_dlen
= sizeof(sol
->desc
.mac
) / FIP_BPW
;
230 memcpy(sol
->desc
.mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
232 sol
->desc
.wwnn
.fd_desc
.fip_dtype
= FIP_DT_NAME
;
233 sol
->desc
.wwnn
.fd_desc
.fip_dlen
= sizeof(sol
->desc
.wwnn
) / FIP_BPW
;
234 put_unaligned_be64(fip
->lp
->wwnn
, &sol
->desc
.wwnn
.fd_wwn
);
236 fcoe_size
= fcoe_ctlr_fcoe_size(fip
);
237 sol
->desc
.size
.fd_desc
.fip_dtype
= FIP_DT_FCOE_SIZE
;
238 sol
->desc
.size
.fd_desc
.fip_dlen
= sizeof(sol
->desc
.size
) / FIP_BPW
;
239 sol
->desc
.size
.fd_size
= htons(fcoe_size
);
241 skb_put(skb
, sizeof(*sol
));
242 skb
->protocol
= htons(ETH_P_FIP
);
243 skb_reset_mac_header(skb
);
244 skb_reset_network_header(skb
);
248 fip
->sol_time
= jiffies
;
252 * fcoe_ctlr_link_up() - Start FCoE controller
253 * @fip: The FCoE controller to start
255 * Called from the LLD when the network link is ready.
257 void fcoe_ctlr_link_up(struct fcoe_ctlr
*fip
)
259 spin_lock_bh(&fip
->lock
);
260 if (fip
->state
== FIP_ST_NON_FIP
|| fip
->state
== FIP_ST_AUTO
) {
263 spin_unlock_bh(&fip
->lock
);
265 } else if (fip
->state
== FIP_ST_LINK_WAIT
) {
266 fip
->state
= fip
->mode
;
269 spin_unlock_bh(&fip
->lock
);
270 if (fip
->state
== FIP_ST_AUTO
)
271 LIBFCOE_FIP_DBG(fip
, "%s", "setting AUTO mode.\n");
273 fcoe_ctlr_solicit(fip
, NULL
);
275 spin_unlock_bh(&fip
->lock
);
277 EXPORT_SYMBOL(fcoe_ctlr_link_up
);
280 * fcoe_ctlr_reset() - Reset a FCoE controller
281 * @fip: The FCoE controller to reset
282 * @new_state: The FIP state to be entered
284 * Returns non-zero if the link was up and now isn't.
286 static int fcoe_ctlr_reset(struct fcoe_ctlr
*fip
, enum fip_state new_state
)
288 struct fc_lport
*lport
= fip
->lp
;
291 spin_lock_bh(&fip
->lock
);
292 fcoe_ctlr_reset_fcfs(fip
);
293 del_timer(&fip
->timer
);
294 fip
->state
= new_state
;
295 fip
->ctlr_ka_time
= 0;
296 fip
->port_ka_time
= 0;
298 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
301 link_dropped
= fip
->link
;
303 spin_unlock_bh(&fip
->lock
);
308 if (new_state
== FIP_ST_ENABLED
) {
309 fcoe_ctlr_solicit(fip
, NULL
);
317 * fcoe_ctlr_link_down() - Stop a FCoE controller
318 * @fip: The FCoE controller to be stopped
320 * Returns non-zero if the link was up and now isn't.
322 * Called from the LLD when the network link is not ready.
323 * There may be multiple calls while the link is down.
325 int fcoe_ctlr_link_down(struct fcoe_ctlr
*fip
)
327 return fcoe_ctlr_reset(fip
, FIP_ST_LINK_WAIT
);
329 EXPORT_SYMBOL(fcoe_ctlr_link_down
);
332 * fcoe_ctlr_send_keep_alive() - Send a keep-alive to the selected FCF
333 * @fip: The FCoE controller to send the FKA on
334 * @lport: libfc fc_lport to send from
335 * @ports: 0 for controller keep-alive, 1 for port keep-alive
336 * @sa: The source MAC address
338 * A controller keep-alive is sent every fka_period (typically 8 seconds).
339 * The source MAC is the native MAC address.
341 * A port keep-alive is sent every 90 seconds while logged in.
342 * The source MAC is the assigned mapped source address.
343 * The destination is the FCF's F-port.
345 static void fcoe_ctlr_send_keep_alive(struct fcoe_ctlr
*fip
,
346 struct fc_lport
*lport
,
352 struct fip_header fip
;
353 struct fip_mac_desc mac
;
354 } __attribute__((packed
)) *kal
;
355 struct fip_vn_desc
*vn
;
358 struct fcoe_fcf
*fcf
;
362 if (!fcf
|| !fc_host_port_id(lp
->host
))
365 len
= fcoe_ctlr_fcoe_size(fip
) + sizeof(struct ethhdr
);
366 BUG_ON(len
< sizeof(*kal
) + sizeof(*vn
));
367 skb
= dev_alloc_skb(len
);
371 kal
= (struct fip_kal
*)skb
->data
;
373 memcpy(kal
->eth
.h_dest
, fcf
->fcf_mac
, ETH_ALEN
);
374 memcpy(kal
->eth
.h_source
, sa
, ETH_ALEN
);
375 kal
->eth
.h_proto
= htons(ETH_P_FIP
);
377 kal
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
378 kal
->fip
.fip_op
= htons(FIP_OP_CTRL
);
379 kal
->fip
.fip_subcode
= FIP_SC_KEEP_ALIVE
;
380 kal
->fip
.fip_dl_len
= htons((sizeof(kal
->mac
) +
381 ports
* sizeof(*vn
)) / FIP_BPW
);
382 kal
->fip
.fip_flags
= htons(FIP_FL_FPMA
);
384 kal
->fip
.fip_flags
|= htons(FIP_FL_SPMA
);
386 kal
->mac
.fd_desc
.fip_dtype
= FIP_DT_MAC
;
387 kal
->mac
.fd_desc
.fip_dlen
= sizeof(kal
->mac
) / FIP_BPW
;
388 memcpy(kal
->mac
.fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
390 vn
= (struct fip_vn_desc
*)(kal
+ 1);
391 vn
->fd_desc
.fip_dtype
= FIP_DT_VN_ID
;
392 vn
->fd_desc
.fip_dlen
= sizeof(*vn
) / FIP_BPW
;
393 memcpy(vn
->fd_mac
, fip
->get_src_addr(lport
), ETH_ALEN
);
394 hton24(vn
->fd_fc_id
, fc_host_port_id(lp
->host
));
395 put_unaligned_be64(lp
->wwpn
, &vn
->fd_wwpn
);
398 skb
->protocol
= htons(ETH_P_FIP
);
399 skb_reset_mac_header(skb
);
400 skb_reset_network_header(skb
);
405 * fcoe_ctlr_encaps() - Encapsulate an ELS frame for FIP, without sending it
406 * @fip: The FCoE controller for the ELS frame
407 * @dtype: The FIP descriptor type for the frame
408 * @skb: The FCoE ELS frame including FC header but no FCoE headers
410 * Returns non-zero error code on failure.
412 * The caller must check that the length is a multiple of 4.
414 * The @skb must have enough headroom (28 bytes) and tailroom (8 bytes).
415 * Headroom includes the FIP encapsulation description, FIP header, and
416 * Ethernet header. The tailroom is for the FIP MAC descriptor.
418 static int fcoe_ctlr_encaps(struct fcoe_ctlr
*fip
, struct fc_lport
*lport
,
419 u8 dtype
, struct sk_buff
*skb
)
421 struct fip_encaps_head
{
423 struct fip_header fip
;
424 struct fip_encaps encaps
;
425 } __attribute__((packed
)) *cap
;
426 struct fip_mac_desc
*mac
;
427 struct fcoe_fcf
*fcf
;
435 /* set flags according to both FCF and lport's capability on SPMA */
436 fip_flags
= fcf
->flags
;
437 fip_flags
&= fip
->spma
? FIP_FL_SPMA
| FIP_FL_FPMA
: FIP_FL_FPMA
;
441 dlen
= sizeof(struct fip_encaps
) + skb
->len
; /* len before push */
442 cap
= (struct fip_encaps_head
*)skb_push(skb
, sizeof(*cap
));
444 memset(cap
, 0, sizeof(*cap
));
445 memcpy(cap
->eth
.h_dest
, fcf
->fcf_mac
, ETH_ALEN
);
446 memcpy(cap
->eth
.h_source
, fip
->ctl_src_addr
, ETH_ALEN
);
447 cap
->eth
.h_proto
= htons(ETH_P_FIP
);
449 cap
->fip
.fip_ver
= FIP_VER_ENCAPS(FIP_VER
);
450 cap
->fip
.fip_op
= htons(FIP_OP_LS
);
451 cap
->fip
.fip_subcode
= FIP_SC_REQ
;
452 cap
->fip
.fip_dl_len
= htons((dlen
+ sizeof(*mac
)) / FIP_BPW
);
453 cap
->fip
.fip_flags
= htons(fip_flags
);
455 cap
->encaps
.fd_desc
.fip_dtype
= dtype
;
456 cap
->encaps
.fd_desc
.fip_dlen
= dlen
/ FIP_BPW
;
458 mac
= (struct fip_mac_desc
*)skb_put(skb
, sizeof(*mac
));
459 memset(mac
, 0, sizeof(mac
));
460 mac
->fd_desc
.fip_dtype
= FIP_DT_MAC
;
461 mac
->fd_desc
.fip_dlen
= sizeof(*mac
) / FIP_BPW
;
462 if (dtype
!= FIP_DT_FLOGI
&& dtype
!= FIP_DT_FDISC
)
463 memcpy(mac
->fd_mac
, fip
->get_src_addr(lport
), ETH_ALEN
);
465 memcpy(mac
->fd_mac
, fip
->ctl_src_addr
, ETH_ALEN
);
467 skb
->protocol
= htons(ETH_P_FIP
);
468 skb_reset_mac_header(skb
);
469 skb_reset_network_header(skb
);
474 * fcoe_ctlr_els_send() - Send an ELS frame encapsulated by FIP if appropriate.
475 * @fip: FCoE controller.
476 * @lport: libfc fc_lport to send from
477 * @skb: FCoE ELS frame including FC header but no FCoE headers.
479 * Returns a non-zero error code if the frame should not be sent.
480 * Returns zero if the caller should send the frame with FCoE encapsulation.
482 * The caller must check that the length is a multiple of 4.
483 * The SKB must have enough headroom (28 bytes) and tailroom (8 bytes).
485 int fcoe_ctlr_els_send(struct fcoe_ctlr
*fip
, struct fc_lport
*lport
,
488 struct fc_frame_header
*fh
;
493 fh
= (struct fc_frame_header
*)skb
->data
;
494 op
= *(u8
*)(fh
+ 1);
496 if (op
== ELS_FLOGI
) {
497 old_xid
= fip
->flogi_oxid
;
498 fip
->flogi_oxid
= ntohs(fh
->fh_ox_id
);
499 if (fip
->state
== FIP_ST_AUTO
) {
500 if (old_xid
== FC_XID_UNKNOWN
)
501 fip
->flogi_count
= 0;
503 if (fip
->flogi_count
< 3)
508 if (fip
->state
== FIP_ST_NON_FIP
)
512 if (fip
->state
== FIP_ST_NON_FIP
)
520 if (ntoh24(fh
->fh_s_id
))
525 if (fip
->state
!= FIP_ST_ENABLED
)
527 if (ntoh24(fh
->fh_d_id
) != FC_FID_FLOGI
)
532 if (fip
->flogi_oxid
== FC_XID_UNKNOWN
)
534 if (!ntoh24(fh
->fh_s_id
))
536 if (fip
->state
== FIP_ST_AUTO
)
539 * Here we must've gotten an SID by accepting an FLOGI
540 * from a point-to-point connection. Switch to using
541 * the source mac based on the SID. The destination
542 * MAC in this case would have been set by receving the
545 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
546 fc_fcoe_set_mac(mac
, fh
->fh_d_id
);
547 fip
->update_mac(lport
, mac
);
550 if (fip
->state
!= FIP_ST_ENABLED
)
554 if (fcoe_ctlr_encaps(fip
, lport
, op
, skb
))
562 EXPORT_SYMBOL(fcoe_ctlr_els_send
);
565 * fcoe_ctlr_age_fcfs() - Reset and free all old FCFs for a controller
566 * @fip: The FCoE controller to free FCFs on
568 * Called with lock held.
570 * An FCF is considered old if we have missed three advertisements.
571 * That is, there have been no valid advertisement from it for three
572 * times its keep-alive period including fuzz.
574 * In addition, determine the time when an FCF selection can occur.
576 static void fcoe_ctlr_age_fcfs(struct fcoe_ctlr
*fip
)
578 struct fcoe_fcf
*fcf
;
579 struct fcoe_fcf
*next
;
580 unsigned long sel_time
= 0;
582 list_for_each_entry_safe(fcf
, next
, &fip
->fcfs
, list
) {
583 if (time_after(jiffies
, fcf
->time
+ fcf
->fka_period
* 3 +
584 msecs_to_jiffies(FIP_FCF_FUZZ
* 3))) {
585 if (fip
->sel_fcf
== fcf
)
587 list_del(&fcf
->list
);
588 WARN_ON(!fip
->fcf_count
);
591 } else if (fcoe_ctlr_mtu_valid(fcf
) &&
592 (!sel_time
|| time_before(sel_time
, fcf
->time
))) {
593 sel_time
= fcf
->time
;
597 sel_time
+= msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
598 fip
->sel_time
= sel_time
;
599 if (time_before(sel_time
, fip
->timer
.expires
))
600 mod_timer(&fip
->timer
, sel_time
);
607 * fcoe_ctlr_parse_adv() - Decode a FIP advertisement into a new FCF entry
608 * @fip: The FCoE controller receiving the advertisement
609 * @skb: The received FIP advertisement frame
610 * @fcf: The resulting FCF entry
612 * Returns zero on a valid parsed advertisement,
613 * otherwise returns non zero value.
615 static int fcoe_ctlr_parse_adv(struct fcoe_ctlr
*fip
,
616 struct sk_buff
*skb
, struct fcoe_fcf
*fcf
)
618 struct fip_header
*fiph
;
619 struct fip_desc
*desc
= NULL
;
620 struct fip_wwn_desc
*wwn
;
621 struct fip_fab_desc
*fab
;
622 struct fip_fka_desc
*fka
;
627 memset(fcf
, 0, sizeof(*fcf
));
628 fcf
->fka_period
= msecs_to_jiffies(FCOE_CTLR_DEF_FKA
);
630 fiph
= (struct fip_header
*)skb
->data
;
631 fcf
->flags
= ntohs(fiph
->fip_flags
);
633 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
634 if (rlen
+ sizeof(*fiph
) > skb
->len
)
637 desc
= (struct fip_desc
*)(fiph
+ 1);
639 dlen
= desc
->fip_dlen
* FIP_BPW
;
640 if (dlen
< sizeof(*desc
) || dlen
> rlen
)
642 switch (desc
->fip_dtype
) {
644 if (dlen
!= sizeof(struct fip_pri_desc
))
646 fcf
->pri
= ((struct fip_pri_desc
*)desc
)->fd_pri
;
649 if (dlen
!= sizeof(struct fip_mac_desc
))
652 ((struct fip_mac_desc
*)desc
)->fd_mac
,
654 if (!is_valid_ether_addr(fcf
->fcf_mac
)) {
655 LIBFCOE_FIP_DBG(fip
, "Invalid MAC address "
661 if (dlen
!= sizeof(struct fip_wwn_desc
))
663 wwn
= (struct fip_wwn_desc
*)desc
;
664 fcf
->switch_name
= get_unaligned_be64(&wwn
->fd_wwn
);
667 if (dlen
!= sizeof(struct fip_fab_desc
))
669 fab
= (struct fip_fab_desc
*)desc
;
670 fcf
->fabric_name
= get_unaligned_be64(&fab
->fd_wwn
);
671 fcf
->vfid
= ntohs(fab
->fd_vfid
);
672 fcf
->fc_map
= ntoh24(fab
->fd_map
);
675 if (dlen
!= sizeof(struct fip_fka_desc
))
677 fka
= (struct fip_fka_desc
*)desc
;
678 t
= ntohl(fka
->fd_fka_period
);
679 if (t
>= FCOE_CTLR_MIN_FKA
)
680 fcf
->fka_period
= msecs_to_jiffies(t
);
683 case FIP_DT_FCOE_SIZE
:
689 LIBFCOE_FIP_DBG(fip
, "unexpected descriptor type %x "
690 "in FIP adv\n", desc
->fip_dtype
);
691 /* standard says ignore unknown descriptors >= 128 */
692 if (desc
->fip_dtype
< FIP_DT_VENDOR_BASE
)
696 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
699 if (!fcf
->fc_map
|| (fcf
->fc_map
& 0x10000))
701 if (!fcf
->switch_name
|| !fcf
->fabric_name
)
706 LIBFCOE_FIP_DBG(fip
, "FIP length error in descriptor type %x len %zu\n",
707 desc
->fip_dtype
, dlen
);
712 * fcoe_ctlr_recv_adv() - Handle an incoming advertisement
713 * @fip: The FCoE controller receiving the advertisement
714 * @skb: The received FIP packet
716 static void fcoe_ctlr_recv_adv(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
718 struct fcoe_fcf
*fcf
;
720 struct fcoe_fcf
*found
;
721 unsigned long sol_tov
= msecs_to_jiffies(FCOE_CTRL_SOL_TOV
);
725 if (fcoe_ctlr_parse_adv(fip
, skb
, &new))
728 spin_lock_bh(&fip
->lock
);
729 first
= list_empty(&fip
->fcfs
);
731 list_for_each_entry(fcf
, &fip
->fcfs
, list
) {
732 if (fcf
->switch_name
== new.switch_name
&&
733 fcf
->fabric_name
== new.fabric_name
&&
734 fcf
->fc_map
== new.fc_map
&&
735 compare_ether_addr(fcf
->fcf_mac
, new.fcf_mac
) == 0) {
741 if (fip
->fcf_count
>= FCOE_CTLR_FCF_LIMIT
)
744 fcf
= kmalloc(sizeof(*fcf
), GFP_ATOMIC
);
749 memcpy(fcf
, &new, sizeof(new));
750 list_add(&fcf
->list
, &fip
->fcfs
);
753 * Flags in advertisements are ignored once the FCF is
754 * selected. Flags in unsolicited advertisements are
755 * ignored after a usable solicited advertisement
758 if (fcf
== fip
->sel_fcf
) {
759 fip
->ctlr_ka_time
-= fcf
->fka_period
;
760 fip
->ctlr_ka_time
+= new.fka_period
;
761 if (time_before(fip
->ctlr_ka_time
, fip
->timer
.expires
))
762 mod_timer(&fip
->timer
, fip
->ctlr_ka_time
);
763 } else if (!fcoe_ctlr_fcf_usable(fcf
))
764 fcf
->flags
= new.flags
;
765 fcf
->fka_period
= new.fka_period
;
766 memcpy(fcf
->fcf_mac
, new.fcf_mac
, ETH_ALEN
);
768 mtu_valid
= fcoe_ctlr_mtu_valid(fcf
);
771 LIBFCOE_FIP_DBG(fip
, "New FCF for fab %llx map %x val %d\n",
772 fcf
->fabric_name
, fcf
->fc_map
, mtu_valid
);
776 * If this advertisement is not solicited and our max receive size
777 * hasn't been verified, send a solicited advertisement.
780 fcoe_ctlr_solicit(fip
, fcf
);
783 * If its been a while since we did a solicit, and this is
784 * the first advertisement we've received, do a multicast
785 * solicitation to gather as many advertisements as we can
786 * before selection occurs.
788 if (first
&& time_after(jiffies
, fip
->sol_time
+ sol_tov
))
789 fcoe_ctlr_solicit(fip
, NULL
);
792 * If this is the first validated FCF, note the time and
793 * set a timer to trigger selection.
795 if (mtu_valid
&& !fip
->sel_time
&& fcoe_ctlr_fcf_usable(fcf
)) {
796 fip
->sel_time
= jiffies
+
797 msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
798 if (!timer_pending(&fip
->timer
) ||
799 time_before(fip
->sel_time
, fip
->timer
.expires
))
800 mod_timer(&fip
->timer
, fip
->sel_time
);
803 spin_unlock_bh(&fip
->lock
);
807 * fcoe_ctlr_recv_els() - Handle an incoming FIP encapsulated ELS frame
808 * @fip: The FCoE controller which received the packet
809 * @skb: The received FIP packet
811 static void fcoe_ctlr_recv_els(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
813 struct fc_lport
*lport
= fip
->lp
;
814 struct fip_header
*fiph
;
815 struct fc_frame
*fp
= (struct fc_frame
*)skb
;
816 struct fc_frame_header
*fh
= NULL
;
817 struct fip_desc
*desc
;
818 struct fip_encaps
*els
;
819 struct fcoe_dev_stats
*stats
;
820 enum fip_desc_type els_dtype
= 0;
823 u8 granted_mac
[ETH_ALEN
] = { 0 };
828 fiph
= (struct fip_header
*)skb
->data
;
829 sub
= fiph
->fip_subcode
;
830 if (sub
!= FIP_SC_REQ
&& sub
!= FIP_SC_REP
)
833 rlen
= ntohs(fiph
->fip_dl_len
) * 4;
834 if (rlen
+ sizeof(*fiph
) > skb
->len
)
837 desc
= (struct fip_desc
*)(fiph
+ 1);
839 dlen
= desc
->fip_dlen
* FIP_BPW
;
840 if (dlen
< sizeof(*desc
) || dlen
> rlen
)
842 switch (desc
->fip_dtype
) {
844 if (dlen
!= sizeof(struct fip_mac_desc
))
847 ((struct fip_mac_desc
*)desc
)->fd_mac
,
849 if (!is_valid_ether_addr(granted_mac
)) {
850 LIBFCOE_FIP_DBG(fip
, "Invalid MAC address "
854 memcpy(fr_cb(fp
)->granted_mac
, granted_mac
, ETH_ALEN
);
862 if (dlen
< sizeof(*els
) + sizeof(*fh
) + 1)
864 els_len
= dlen
- sizeof(*els
);
865 els
= (struct fip_encaps
*)desc
;
866 fh
= (struct fc_frame_header
*)(els
+ 1);
867 els_dtype
= desc
->fip_dtype
;
870 LIBFCOE_FIP_DBG(fip
, "unexpected descriptor type %x "
871 "in FIP adv\n", desc
->fip_dtype
);
872 /* standard says ignore unknown descriptors >= 128 */
873 if (desc
->fip_dtype
< FIP_DT_VENDOR_BASE
)
877 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
883 els_op
= *(u8
*)(fh
+ 1);
885 if (els_dtype
== FIP_DT_FLOGI
&& sub
== FIP_SC_REP
&&
886 fip
->flogi_oxid
== ntohs(fh
->fh_ox_id
) &&
887 els_op
== ELS_LS_ACC
&& is_valid_ether_addr(granted_mac
))
888 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
891 * Convert skb into an fc_frame containing only the ELS.
893 skb_pull(skb
, (u8
*)fh
- skb
->data
);
894 skb_trim(skb
, els_len
);
895 fp
= (struct fc_frame
*)skb
;
897 fr_sof(fp
) = FC_SOF_I3
;
898 fr_eof(fp
) = FC_EOF_T
;
901 stats
= fc_lport_get_stats(lport
);
903 stats
->RxWords
+= skb
->len
/ FIP_BPW
;
905 fc_exch_recv(lport
, fp
);
909 LIBFCOE_FIP_DBG(fip
, "FIP length error in descriptor type %x len %zu\n",
910 desc
->fip_dtype
, dlen
);
916 * fcoe_ctlr_recv_els() - Handle an incoming link reset frame
917 * @fip: The FCoE controller that received the frame
918 * @fh: The received FIP header
920 * There may be multiple VN_Port descriptors.
921 * The overall length has already been checked.
923 static void fcoe_ctlr_recv_clr_vlink(struct fcoe_ctlr
*fip
,
924 struct fip_header
*fh
)
926 struct fip_desc
*desc
;
927 struct fip_mac_desc
*mp
;
928 struct fip_wwn_desc
*wp
;
929 struct fip_vn_desc
*vp
;
932 struct fcoe_fcf
*fcf
= fip
->sel_fcf
;
933 struct fc_lport
*lport
= fip
->lp
;
936 LIBFCOE_FIP_DBG(fip
, "Clear Virtual Link received\n");
939 if (!fcf
|| !fc_host_port_id(lport
->host
))
943 * mask of required descriptors. Validating each one clears its bit.
945 desc_mask
= BIT(FIP_DT_MAC
) | BIT(FIP_DT_NAME
) | BIT(FIP_DT_VN_ID
);
947 rlen
= ntohs(fh
->fip_dl_len
) * FIP_BPW
;
948 desc
= (struct fip_desc
*)(fh
+ 1);
949 while (rlen
>= sizeof(*desc
)) {
950 dlen
= desc
->fip_dlen
* FIP_BPW
;
953 switch (desc
->fip_dtype
) {
955 mp
= (struct fip_mac_desc
*)desc
;
956 if (dlen
< sizeof(*mp
))
958 if (compare_ether_addr(mp
->fd_mac
, fcf
->fcf_mac
))
960 desc_mask
&= ~BIT(FIP_DT_MAC
);
963 wp
= (struct fip_wwn_desc
*)desc
;
964 if (dlen
< sizeof(*wp
))
966 if (get_unaligned_be64(&wp
->fd_wwn
) != fcf
->switch_name
)
968 desc_mask
&= ~BIT(FIP_DT_NAME
);
971 vp
= (struct fip_vn_desc
*)desc
;
972 if (dlen
< sizeof(*vp
))
974 if (compare_ether_addr(vp
->fd_mac
,
975 fip
->get_src_addr(lport
)) == 0 &&
976 get_unaligned_be64(&vp
->fd_wwpn
) == lport
->wwpn
&&
977 ntoh24(vp
->fd_fc_id
) ==
978 fc_host_port_id(lport
->host
))
979 desc_mask
&= ~BIT(FIP_DT_VN_ID
);
982 /* standard says ignore unknown descriptors >= 128 */
983 if (desc
->fip_dtype
< FIP_DT_VENDOR_BASE
)
987 desc
= (struct fip_desc
*)((char *)desc
+ dlen
);
992 * reset only if all required descriptors were present and valid.
995 LIBFCOE_FIP_DBG(fip
, "missing descriptors mask %x\n",
998 LIBFCOE_FIP_DBG(fip
, "performing Clear Virtual Link\n");
999 fcoe_ctlr_reset(fip
, FIP_ST_ENABLED
);
1004 * fcoe_ctlr_recv() - Receive a FIP packet
1005 * @fip: The FCoE controller that received the packet
1006 * @skb: The received FIP packet
1008 * This is called from NET_RX_SOFTIRQ.
1010 void fcoe_ctlr_recv(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1012 spin_lock_bh(&fip
->fip_recv_list
.lock
);
1013 __skb_queue_tail(&fip
->fip_recv_list
, skb
);
1014 spin_unlock_bh(&fip
->fip_recv_list
.lock
);
1015 schedule_work(&fip
->recv_work
);
1017 EXPORT_SYMBOL(fcoe_ctlr_recv
);
1020 * fcoe_ctlr_recv_handler() - Receive a FIP frame
1021 * @fip: The FCoE controller that received the frame
1022 * @skb: The received FIP frame
1024 * Returns non-zero if the frame is dropped.
1026 static int fcoe_ctlr_recv_handler(struct fcoe_ctlr
*fip
, struct sk_buff
*skb
)
1028 struct fip_header
*fiph
;
1030 enum fip_state state
;
1034 if (skb_linearize(skb
))
1036 if (skb
->len
< sizeof(*fiph
))
1039 if (compare_ether_addr(eh
->h_dest
, fip
->ctl_src_addr
) &&
1040 compare_ether_addr(eh
->h_dest
, FIP_ALL_ENODE_MACS
))
1042 fiph
= (struct fip_header
*)skb
->data
;
1043 op
= ntohs(fiph
->fip_op
);
1044 sub
= fiph
->fip_subcode
;
1046 if (FIP_VER_DECAPS(fiph
->fip_ver
) != FIP_VER
)
1048 if (ntohs(fiph
->fip_dl_len
) * FIP_BPW
+ sizeof(*fiph
) > skb
->len
)
1051 spin_lock_bh(&fip
->lock
);
1053 if (state
== FIP_ST_AUTO
) {
1055 fip
->state
= FIP_ST_ENABLED
;
1056 state
= FIP_ST_ENABLED
;
1057 LIBFCOE_FIP_DBG(fip
, "Using FIP mode\n");
1059 spin_unlock_bh(&fip
->lock
);
1060 if (state
!= FIP_ST_ENABLED
)
1063 if (op
== FIP_OP_LS
) {
1064 fcoe_ctlr_recv_els(fip
, skb
); /* consumes skb */
1067 if (op
== FIP_OP_DISC
&& sub
== FIP_SC_ADV
)
1068 fcoe_ctlr_recv_adv(fip
, skb
);
1069 else if (op
== FIP_OP_CTRL
&& sub
== FIP_SC_CLR_VLINK
)
1070 fcoe_ctlr_recv_clr_vlink(fip
, fiph
);
1079 * fcoe_ctlr_select() - Select the best FCF (if possible)
1080 * @fip: The FCoE controller
1082 * If there are conflicting advertisements, no FCF can be chosen.
1084 * Called with lock held.
1086 static void fcoe_ctlr_select(struct fcoe_ctlr
*fip
)
1088 struct fcoe_fcf
*fcf
;
1089 struct fcoe_fcf
*best
= NULL
;
1091 list_for_each_entry(fcf
, &fip
->fcfs
, list
) {
1092 LIBFCOE_FIP_DBG(fip
, "consider FCF for fab %llx VFID %d map %x "
1093 "val %d\n", fcf
->fabric_name
, fcf
->vfid
,
1094 fcf
->fc_map
, fcoe_ctlr_mtu_valid(fcf
));
1095 if (!fcoe_ctlr_fcf_usable(fcf
)) {
1096 LIBFCOE_FIP_DBG(fip
, "FCF for fab %llx map %x %svalid "
1097 "%savailable\n", fcf
->fabric_name
,
1098 fcf
->fc_map
, (fcf
->flags
& FIP_FL_SOL
)
1099 ? "" : "in", (fcf
->flags
& FIP_FL_AVAIL
)
1107 if (fcf
->fabric_name
!= best
->fabric_name
||
1108 fcf
->vfid
!= best
->vfid
||
1109 fcf
->fc_map
!= best
->fc_map
) {
1110 LIBFCOE_FIP_DBG(fip
, "Conflicting fabric, VFID, "
1114 if (fcf
->pri
< best
->pri
)
1117 fip
->sel_fcf
= best
;
1121 * fcoe_ctlr_timeout() - FIP timeout handler
1122 * @arg: The FCoE controller that timed out
1124 * Ages FCFs. Triggers FCF selection if possible. Sends keep-alives.
1126 static void fcoe_ctlr_timeout(unsigned long arg
)
1128 struct fcoe_ctlr
*fip
= (struct fcoe_ctlr
*)arg
;
1129 struct fcoe_fcf
*sel
;
1130 struct fcoe_fcf
*fcf
;
1131 unsigned long next_timer
= jiffies
+ msecs_to_jiffies(FIP_VN_KA_PERIOD
);
1133 spin_lock_bh(&fip
->lock
);
1134 if (fip
->state
== FIP_ST_DISABLED
) {
1135 spin_unlock_bh(&fip
->lock
);
1140 fcoe_ctlr_age_fcfs(fip
);
1143 if (!sel
&& fip
->sel_time
&& time_after_eq(jiffies
, fip
->sel_time
)) {
1144 fcoe_ctlr_select(fip
);
1150 fcf
= sel
; /* the old FCF may have been freed */
1152 printk(KERN_INFO
"libfcoe: host%d: FIP selected "
1153 "Fibre-Channel Forwarder MAC %pM\n",
1154 fip
->lp
->host
->host_no
, sel
->fcf_mac
);
1155 memcpy(fip
->dest_addr
, sel
->fcf_mac
, ETH_ALEN
);
1156 fip
->port_ka_time
= jiffies
+
1157 msecs_to_jiffies(FIP_VN_KA_PERIOD
);
1158 fip
->ctlr_ka_time
= jiffies
+ sel
->fka_period
;
1161 printk(KERN_NOTICE
"libfcoe: host%d: "
1162 "FIP Fibre-Channel Forwarder timed out. "
1163 "Starting FCF discovery.\n",
1164 fip
->lp
->host
->host_no
);
1167 schedule_work(&fip
->link_work
);
1171 if (time_after_eq(jiffies
, fip
->ctlr_ka_time
)) {
1172 fip
->ctlr_ka_time
= jiffies
+ sel
->fka_period
;
1173 fip
->send_ctlr_ka
= 1;
1175 if (time_after(next_timer
, fip
->ctlr_ka_time
))
1176 next_timer
= fip
->ctlr_ka_time
;
1178 if (time_after_eq(jiffies
, fip
->port_ka_time
)) {
1179 fip
->port_ka_time
+= jiffies
+
1180 msecs_to_jiffies(FIP_VN_KA_PERIOD
);
1181 fip
->send_port_ka
= 1;
1183 if (time_after(next_timer
, fip
->port_ka_time
))
1184 next_timer
= fip
->port_ka_time
;
1185 mod_timer(&fip
->timer
, next_timer
);
1186 } else if (fip
->sel_time
) {
1187 next_timer
= fip
->sel_time
+
1188 msecs_to_jiffies(FCOE_CTLR_START_DELAY
);
1189 mod_timer(&fip
->timer
, next_timer
);
1191 if (fip
->send_ctlr_ka
|| fip
->send_port_ka
)
1192 schedule_work(&fip
->link_work
);
1193 spin_unlock_bh(&fip
->lock
);
1197 * fcoe_ctlr_link_work() - Worker thread function for link changes
1198 * @work: Handle to a FCoE controller
1200 * See if the link status has changed and if so, report it.
1202 * This is here because fc_linkup() and fc_linkdown() must not
1203 * be called from the timer directly, since they use a mutex.
1205 static void fcoe_ctlr_link_work(struct work_struct
*work
)
1207 struct fcoe_ctlr
*fip
;
1208 struct fc_lport
*vport
;
1213 fip
= container_of(work
, struct fcoe_ctlr
, link_work
);
1214 spin_lock_bh(&fip
->lock
);
1215 last_link
= fip
->last_link
;
1217 fip
->last_link
= link
;
1218 spin_unlock_bh(&fip
->lock
);
1220 if (last_link
!= link
) {
1224 fcoe_ctlr_reset(fip
, FIP_ST_LINK_WAIT
);
1227 if (fip
->send_ctlr_ka
) {
1228 fip
->send_ctlr_ka
= 0;
1229 fcoe_ctlr_send_keep_alive(fip
, NULL
, 0, fip
->ctl_src_addr
);
1231 if (fip
->send_port_ka
) {
1232 fip
->send_port_ka
= 0;
1233 mutex_lock(&fip
->lp
->lp_mutex
);
1234 mac
= fip
->get_src_addr(fip
->lp
);
1235 fcoe_ctlr_send_keep_alive(fip
, fip
->lp
, 1, mac
);
1236 list_for_each_entry(vport
, &fip
->lp
->vports
, list
) {
1237 mac
= fip
->get_src_addr(vport
);
1238 fcoe_ctlr_send_keep_alive(fip
, vport
, 1, mac
);
1240 mutex_unlock(&fip
->lp
->lp_mutex
);
1245 * fcoe_ctlr_recv_work() - Worker thread function for receiving FIP frames
1246 * @recv_work: Handle to a FCoE controller
1248 static void fcoe_ctlr_recv_work(struct work_struct
*recv_work
)
1250 struct fcoe_ctlr
*fip
;
1251 struct sk_buff
*skb
;
1253 fip
= container_of(recv_work
, struct fcoe_ctlr
, recv_work
);
1254 spin_lock_bh(&fip
->fip_recv_list
.lock
);
1255 while ((skb
= __skb_dequeue(&fip
->fip_recv_list
))) {
1256 spin_unlock_bh(&fip
->fip_recv_list
.lock
);
1257 fcoe_ctlr_recv_handler(fip
, skb
);
1258 spin_lock_bh(&fip
->fip_recv_list
.lock
);
1260 spin_unlock_bh(&fip
->fip_recv_list
.lock
);
1264 * fcoe_ctlr_recv_flogi() - Snoop pre-FIP receipt of FLOGI response or request
1265 * @fip: The FCoE controller
1266 * @fp: The FC frame to snoop
1267 * @sa: Ethernet source MAC address from received FCoE frame
1269 * Snoop potential response to FLOGI or even incoming FLOGI.
1271 * The caller has checked that we are waiting for login as indicated
1272 * by fip->flogi_oxid != FC_XID_UNKNOWN.
1274 * The caller is responsible for freeing the frame.
1276 * Return non-zero if the frame should not be delivered to libfc.
1278 int fcoe_ctlr_recv_flogi(struct fcoe_ctlr
*fip
, struct fc_lport
*lport
,
1279 struct fc_frame
*fp
, u8
*sa
)
1281 struct fc_frame_header
*fh
;
1285 fh
= fc_frame_header_get(fp
);
1286 if (fh
->fh_type
!= FC_TYPE_ELS
)
1289 op
= fc_frame_payload_op(fp
);
1290 if (op
== ELS_LS_ACC
&& fh
->fh_r_ctl
== FC_RCTL_ELS_REP
&&
1291 fip
->flogi_oxid
== ntohs(fh
->fh_ox_id
)) {
1293 spin_lock_bh(&fip
->lock
);
1294 if (fip
->state
!= FIP_ST_AUTO
&& fip
->state
!= FIP_ST_NON_FIP
) {
1295 spin_unlock_bh(&fip
->lock
);
1298 fip
->state
= FIP_ST_NON_FIP
;
1299 LIBFCOE_FIP_DBG(fip
,
1300 "received FLOGI LS_ACC using non-FIP mode\n");
1304 * If the src mac addr is FC_OUI-based, then we mark the
1305 * address_mode flag to use FC_OUI-based Ethernet DA.
1306 * Otherwise we use the FCoE gateway addr
1308 if (!compare_ether_addr(sa
, (u8
[6])FC_FCOE_FLOGI_MAC
)) {
1311 memcpy(fip
->dest_addr
, sa
, ETH_ALEN
);
1314 fip
->flogi_oxid
= FC_XID_UNKNOWN
;
1315 fc_fcoe_set_mac(mac
, fh
->fh_d_id
);
1316 fip
->update_mac(lport
, mac
);
1317 spin_unlock_bh(&fip
->lock
);
1318 } else if (op
== ELS_FLOGI
&& fh
->fh_r_ctl
== FC_RCTL_ELS_REQ
&& sa
) {
1320 * Save source MAC for point-to-point responses.
1322 spin_lock_bh(&fip
->lock
);
1323 if (fip
->state
== FIP_ST_AUTO
|| fip
->state
== FIP_ST_NON_FIP
) {
1324 memcpy(fip
->dest_addr
, sa
, ETH_ALEN
);
1326 if (fip
->state
== FIP_ST_NON_FIP
)
1327 LIBFCOE_FIP_DBG(fip
, "received FLOGI REQ, "
1328 "using non-FIP mode\n");
1329 fip
->state
= FIP_ST_NON_FIP
;
1331 spin_unlock_bh(&fip
->lock
);
1335 EXPORT_SYMBOL(fcoe_ctlr_recv_flogi
);
1338 * fcoe_wwn_from_mac() - Converts a 48-bit IEEE MAC address to a 64-bit FC WWN
1339 * @mac: The MAC address to convert
1340 * @scheme: The scheme to use when converting
1341 * @port: The port indicator for converting
1343 * Returns: u64 fc world wide name
1345 u64
fcoe_wwn_from_mac(unsigned char mac
[MAX_ADDR_LEN
],
1346 unsigned int scheme
, unsigned int port
)
1351 /* The MAC is in NO, so flip only the low 48 bits */
1352 host_mac
= ((u64
) mac
[0] << 40) |
1353 ((u64
) mac
[1] << 32) |
1354 ((u64
) mac
[2] << 24) |
1355 ((u64
) mac
[3] << 16) |
1356 ((u64
) mac
[4] << 8) |
1359 WARN_ON(host_mac
>= (1ULL << 48));
1360 wwn
= host_mac
| ((u64
) scheme
<< 60);
1366 WARN_ON(port
>= 0xfff);
1367 wwn
|= (u64
) port
<< 48;
1376 EXPORT_SYMBOL_GPL(fcoe_wwn_from_mac
);
1379 * fcoe_libfc_config() - Sets up libfc related properties for local port
1380 * @lp: The local port to configure libfc for
1381 * @tt: The libfc function template
1383 * Returns : 0 for success
1385 int fcoe_libfc_config(struct fc_lport
*lport
,
1386 struct libfc_function_template
*tt
)
1388 /* Set the function pointers set by the LLDD */
1389 memcpy(&lport
->tt
, tt
, sizeof(*tt
));
1390 if (fc_fcp_init(lport
))
1392 fc_exch_init(lport
);
1393 fc_elsct_init(lport
);
1394 fc_lport_init(lport
);
1395 fc_rport_init(lport
);
1396 fc_disc_init(lport
);
1400 EXPORT_SYMBOL_GPL(fcoe_libfc_config
);