xref: /linux/include/scsi/libfcoe.h (revision a7b12a279faaad26837276065104a1f9cf60e962)
1 /*
2  * Copyright (c) 2008-2009 Cisco Systems, Inc.  All rights reserved.
3  * Copyright (c) 2007-2008 Intel Corporation.  All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Maintained at www.Open-FCoE.org
19  */
20 
21 #ifndef _LIBFCOE_H
22 #define _LIBFCOE_H
23 
24 #include <linux/etherdevice.h>
25 #include <linux/if_ether.h>
26 #include <linux/netdevice.h>
27 #include <linux/skbuff.h>
28 #include <linux/workqueue.h>
29 #include <scsi/fc/fc_fcoe.h>
30 #include <scsi/libfc.h>
31 
32 #define FCOE_MAX_CMD_LEN	16	/* Supported CDB length */
33 
34 /*
35  * FIP tunable parameters.
36  */
37 #define FCOE_CTLR_START_DELAY	2000	/* mS after first adv. to choose FCF */
38 #define FCOE_CTRL_SOL_TOV	2000	/* min. solicitation interval (mS) */
39 #define FCOE_CTLR_FCF_LIMIT	20	/* max. number of FCF entries */
40 
41 /**
42  * enum fip_state - internal state of FCoE controller.
43  * @FIP_ST_DISABLED: 	controller has been disabled or not yet enabled.
44  * @FIP_ST_LINK_WAIT:	the physical link is down or unusable.
45  * @FIP_ST_AUTO:	determining whether to use FIP or non-FIP mode.
46  * @FIP_ST_NON_FIP:	non-FIP mode selected.
47  * @FIP_ST_ENABLED:	FIP mode selected.
48  */
49 enum fip_state {
50 	FIP_ST_DISABLED,
51 	FIP_ST_LINK_WAIT,
52 	FIP_ST_AUTO,
53 	FIP_ST_NON_FIP,
54 	FIP_ST_ENABLED,
55 };
56 
57 /*
58  * Modes:
59  * The mode is the state that is to be entered after link up.
60  * It must not change after fcoe_ctlr_init() sets it.
61  */
62 #define FIP_MODE_AUTO		FIP_ST_AUTO
63 #define FIP_MODE_NON_FIP	FIP_ST_NON_FIP
64 #define FIP_MODE_FABRIC		FIP_ST_ENABLED
65 
66 /**
67  * struct fcoe_ctlr - FCoE Controller and FIP state
68  * @state:	   internal FIP state for network link and FIP or non-FIP mode.
69  * @mode:	   LLD-selected mode.
70  * @lp:		   &fc_lport: libfc local port.
71  * @sel_fcf:	   currently selected FCF, or NULL.
72  * @fcfs:	   list of discovered FCFs.
73  * @fcf_count:	   number of discovered FCF entries.
74  * @sol_time:	   time when a multicast solicitation was last sent.
75  * @sel_time:	   time after which to select an FCF.
76  * @port_ka_time:  time of next port keep-alive.
77  * @ctlr_ka_time:  time of next controller keep-alive.
78  * @timer:	   timer struct used for all delayed events.
79  * @timer_work:	   &work_struct for doing keep-alives and resets.
80  * @recv_work:	   &work_struct for receiving FIP frames.
81  * @fip_recv_list: list of received FIP frames.
82  * @user_mfs:	   configured maximum FC frame size, including FC header.
83  * @flogi_oxid:    exchange ID of most recent fabric login.
84  * @flogi_count:   number of FLOGI attempts in AUTO mode.
85  * @map_dest:	   use the FC_MAP mode for destination MAC addresses.
86  * @spma:	   supports SPMA server-provided MACs mode
87  * @dest_addr:	   MAC address of the selected FC forwarder.
88  * @ctl_src_addr:  the native MAC address of our local port.
89  * @send:	   LLD-supplied function to handle sending FIP Ethernet frames
90  * @update_mac:    LLD-supplied function to handle changes to MAC addresses.
91  * @get_src_addr:  LLD-supplied function to supply a source MAC address.
92  * @ctlr_mutex:	   lock protecting this structure.
93  *
94  * This structure is used by all FCoE drivers.  It contains information
95  * needed by all FCoE low-level drivers (LLDs) as well as internal state
96  * for FIP, and fields shared with the LLDS.
97  */
98 struct fcoe_ctlr {
99 	enum fip_state state;
100 	enum fip_state mode;
101 	struct fc_lport *lp;
102 	struct fcoe_fcf *sel_fcf;
103 	struct list_head fcfs;
104 	u16 fcf_count;
105 	unsigned long sol_time;
106 	unsigned long sel_time;
107 	unsigned long port_ka_time;
108 	unsigned long ctlr_ka_time;
109 	struct timer_list timer;
110 	struct work_struct timer_work;
111 	struct work_struct recv_work;
112 	struct sk_buff_head fip_recv_list;
113 	u16 user_mfs;
114 	u16 flogi_oxid;
115 	u8 flogi_count;
116 	u8 map_dest;
117 	u8 spma;
118 	u8 dest_addr[ETH_ALEN];
119 	u8 ctl_src_addr[ETH_ALEN];
120 
121 	void (*send)(struct fcoe_ctlr *, struct sk_buff *);
122 	void (*update_mac)(struct fc_lport *, u8 *addr);
123 	u8 * (*get_src_addr)(struct fc_lport *);
124 	struct mutex ctlr_mutex;
125 };
126 
127 /**
128  * struct fcoe_fcf - Fibre-Channel Forwarder
129  * @list:	 list linkage
130  * @time:	 system time (jiffies) when an advertisement was last received
131  * @switch_name: WWN of switch from advertisement
132  * @fabric_name: WWN of fabric from advertisement
133  * @fc_map:	 FC_MAP value from advertisement
134  * @fcf_mac:	 Ethernet address of the FCF
135  * @vfid:	 virtual fabric ID
136  * @pri:	 selection priority, smaller values are better
137  * @flags:	 flags received from advertisement
138  * @fka_period:	 keep-alive period, in jiffies
139  *
140  * A Fibre-Channel Forwarder (FCF) is the entity on the Ethernet that
141  * passes FCoE frames on to an FC fabric.  This structure represents
142  * one FCF from which advertisements have been received.
143  *
144  * When looking up an FCF, @switch_name, @fabric_name, @fc_map, @vfid, and
145  * @fcf_mac together form the lookup key.
146  */
147 struct fcoe_fcf {
148 	struct list_head list;
149 	unsigned long time;
150 
151 	u64 switch_name;
152 	u64 fabric_name;
153 	u32 fc_map;
154 	u16 vfid;
155 	u8 fcf_mac[ETH_ALEN];
156 
157 	u8 pri;
158 	u16 flags;
159 	u32 fka_period;
160 	u8 fd_flags:1;
161 };
162 
163 /* FIP API functions */
164 void fcoe_ctlr_init(struct fcoe_ctlr *, enum fip_state);
165 void fcoe_ctlr_destroy(struct fcoe_ctlr *);
166 void fcoe_ctlr_link_up(struct fcoe_ctlr *);
167 int fcoe_ctlr_link_down(struct fcoe_ctlr *);
168 int fcoe_ctlr_els_send(struct fcoe_ctlr *, struct fc_lport *, struct sk_buff *);
169 void fcoe_ctlr_recv(struct fcoe_ctlr *, struct sk_buff *);
170 int fcoe_ctlr_recv_flogi(struct fcoe_ctlr *, struct fc_lport *,
171 			 struct fc_frame *);
172 
173 /* libfcoe funcs */
174 u64 fcoe_wwn_from_mac(unsigned char mac[], unsigned int, unsigned int);
175 int fcoe_libfc_config(struct fc_lport *, struct libfc_function_template *);
176 
177 /**
178  * is_fip_mode() - returns true if FIP mode selected.
179  * @fip:	FCoE controller.
180  */
181 static inline bool is_fip_mode(struct fcoe_ctlr *fip)
182 {
183 	return fip->state == FIP_ST_ENABLED;
184 }
185 
186 
187 #endif /* _LIBFCOE_H */
188