xref: /illumos-gate/usr/src/uts/common/io/fcoe/fcoe.h (revision ef2504f26d1ea5859db9838255bb63f488f1b050)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * The following notice accompanied the original version of this file:
28  *
29  * BSD LICENSE
30  *
31  * Copyright(c) 2007 Intel Corporation. All rights reserved.
32  * All rights reserved.
33  *
34  * Redistribution and use in source and binary forms, with or without
35  * modification, are permitted provided that the following conditions
36  * are met:
37  *
38  *   * Redistributions of source code must retain the above copyright
39  *     notice, this list of conditions and the following disclaimer.
40  *   * Redistributions in binary form must reproduce the above copyright
41  *     notice, this list of conditions and the following disclaimer in
42  *     the documentation and/or other materials provided with the
43  *     distribution.
44  *   * Neither the name of Intel Corporation nor the names of its
45  *     contributors may be used to endorse or promote products derived
46  *     from this software without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
52  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59  */
60 #ifndef	_FCOE_H_
61 #define	_FCOE_H_
62 
63 #ifdef	__cplusplus
64 extern "C" {
65 #endif
66 
67 #ifdef	_KERNEL
68 
69 extern int			 fcoe_use_ext_log;
70 extern struct fcoe_soft_state	*fcoe_global_ss;
71 
72 /*
73  * Caution: 1) LOG will be available in debug/non-debug mode
74  *	    2) Anything which can potentially flood the log should be under
75  *	       extended logging, and use FCOE_EXT_LOG.
76  *	    3) Don't use FCOE_EXT_LOG in performance-critical code path, such
77  *	       as normal SCSI I/O code path. It could hurt system performance.
78  *	    4) Use kmdb to change foce_use_ext_log in the fly to adjust
79  *	       tracing
80  */
81 #define	FCOE_EXT_LOG(log_ident, ...)	\
82 	do {	\
83 		if (fcoe_use_ext_log) {	\
84 			fcoe_trace(log_ident, __VA_ARGS__);	\
85 		}	\
86 	} while (0)
87 
88 #define	FCOE_LOG(log_ident, ...)	\
89 	fcoe_trace(log_ident, __VA_ARGS__)
90 
91 /*
92  * There will be only one fcoe instance
93  */
94 typedef struct fcoe_soft_state {
95 	dev_info_t	*ss_dip;
96 	uint32_t	 ss_flags;
97 	list_t		 ss_mac_list;
98 	uint32_t	 ss_ioctl_flags;
99 	kmutex_t	 ss_ioctl_mutex;
100 
101 	/*
102 	 * watchdog stuff
103 	 */
104 	ddi_taskq_t	*ss_watchdog_taskq;
105 	kcondvar_t	 ss_watch_cv;
106 	kmutex_t	 ss_watch_mutex;
107 	list_t		 ss_pfrm_list;	/* Pending frame */
108 } fcoe_soft_state_t;
109 
110 #define	SS_FLAG_TERMINATE_WATCHDOG	0x0020
111 #define	SS_FLAG_WATCHDOG_RUNNING	0x0040
112 #define	SS_FLAG_DOG_WAITING		0x0080
113 
114 /*
115  *  Driver name
116  */
117 #define	FCOEI_DRIVER_NAME	"fcoei"
118 #define	FCOET_DRIVER_NAME	"fcoet"
119 
120 /*
121  * One for each ethernet port
122  */
123 typedef struct fcoe_mac
124 {
125 	list_node_t		fm_ss_node;
126 	datalink_id_t		fm_linkid;
127 	uint32_t		fm_flags;
128 
129 	fcoe_soft_state_t	*fm_ss;
130 	fcoe_port_t		fm_eport;
131 	fcoe_client_t		fm_client;
132 	dev_info_t		*fm_client_dev;
133 
134 	mac_handle_t		fm_handle;
135 	mac_client_handle_t	fm_cli_handle;
136 	mac_promisc_handle_t	fm_promisc_handle;
137 	mac_notify_handle_t	fm_notify_handle;
138 	mac_unicast_handle_t	fm_unicst_handle;
139 	uint8_t			fm_primary_addr[ETHERADDRL];
140 	uint8_t			fm_current_addr[ETHERADDRL];
141 	uint32_t		fm_running:1,
142 				fm_force_promisc:1,
143 				fm_rsvd:18,
144 				fm_state:4,
145 				fm_link_state:8;
146 	uint32_t		fm_frm_cnt;
147 	kcondvar_t		fm_tx_cv;
148 	kmutex_t		fm_mutex;
149 } fcoe_mac_t;
150 
151 #define	FCOE_MAC_STATE_OFFLINE		0x0
152 #define	FCOE_MAC_STATE_ONLINE		0x1
153 
154 #define	FCOE_MAC_LINK_STATE_DOWN	0x00
155 #define	FCOE_MAC_LINK_STATE_UP		0x01
156 
157 #define	FCOE_MAC_FLAG_ENABLED		0x01
158 #define	FCOE_MAC_FLAG_BOUND		0x02
159 
160 typedef struct fcoe_frame_header {
161 	uint8_t		 ffh_ver[1];	/* version field - upper 4 bits */
162 	uint8_t		 ffh_resvd[12];
163 	uint8_t		 ffh_sof[1];	/* start of frame per RFC 3643 */
164 } fcoe_frame_header_t;
165 
166 typedef struct fcoe_frame_tailer {
167 	uint8_t		 fft_crc[4];	/* FC packet CRC */
168 	uint8_t		 fft_eof[1];
169 	uint8_t		 fft_resvd[3];
170 } fcoe_frame_tailer_t;
171 
172 /*
173  * RAW frame structure
174  * It is used to describe the content of every mblk
175  */
176 typedef struct fcoe_i_frame {
177 	list_node_t		 fmi_pending_node;
178 
179 	fcoe_frame_t		*fmi_frame;	/* to common struct */
180 	fcoe_mac_t		*fmi_mac;	/* to/from where */
181 
182 	/*
183 	 * FRAME structure
184 	 */
185 	struct ether_header	*fmi_efh;	/* 14 bytes eth header */
186 	fcoe_frame_header_t	*fmi_ffh;	/* 14 bytes FCOE hader */
187 	uint8_t			*fmi_fc_frame;
188 	fcoe_frame_tailer_t	*fmi_fft;	/* 8 bytes FCOE tailer */
189 } fcoe_i_frame_t;
190 
191 typedef struct fcoe_worker {
192 	list_t		worker_frm_list;
193 	kmutex_t	worker_lock;
194 	kcondvar_t	worker_cv;
195 	uint32_t	worker_flags;
196 	uint32_t	worker_ntasks;
197 } fcoe_worker_t;
198 
199 #define	FCOE_WORKER_TERMINATE	0x01
200 #define	FCOE_WORKER_STARTED	0x02
201 #define	FCOE_WORKER_ACTIVE	0x04
202 
203 /*
204  * IOCTL supporting stuff
205  */
206 #define	FCOE_IOCTL_FLAG_MASK		0xFF
207 #define	FCOE_IOCTL_FLAG_IDLE		0x00
208 #define	FCOE_IOCTL_FLAG_OPEN		0x01
209 #define	FCOE_IOCTL_FLAG_EXCL		0x02
210 #define	FCOE_IOCTL_FLAG_EXCL_BUSY	0x04
211 
212 /*
213  * define common-used macros to simplify coding
214  */
215 #define	FCOE_FIP_TYPE		0x8914
216 #define	FCOE_802_1Q_TAG		0x8100
217 
218 #define	PADDING_HEADER_SIZE	(sizeof (struct ether_header) + \
219 	sizeof (fcoe_frame_header_t))
220 #define	PADDING_SIZE	(PADDING_HEADER_SIZE + sizeof (fcoe_frame_tailer_t))
221 
222 #define	EPORT2MAC(x_eport)	((fcoe_mac_t *)(x_eport)->eport_fcoe_private)
223 
224 #define	FRM2MAC(x_frm)		(EPORT2MAC((x_frm)->frm_eport))
225 #define	FRM2FMI(x_frm)		((fcoe_i_frame_t *)(x_frm)->frm_fcoe_private)
226 #define	FRM2MBLK(x_frm)		((mblk_t *)(x_frm)->frm_netb)
227 
228 #define	FCOE_VER			0
229 #define	FCOE_DECAPS_VER(x_ffh)		((x_ffh)->ffh_ver[0] >> 4)
230 #define	FCOE_ENCAPS_VER(x_ffh, x_v)			\
231 	{						\
232 		(x_ffh)->ffh_ver[0] = ((x_v) << 4);	\
233 	}
234 
235 /*
236  * fcoe driver common functions
237  */
238 extern fcoe_mac_t *fcoe_lookup_mac_by_id(datalink_id_t);
239 extern void fcoe_destroy_mac(fcoe_mac_t *);
240 extern mblk_t *fcoe_get_mblk(fcoe_mac_t *, uint32_t);
241 extern void fcoe_post_frame(fcoe_frame_t *);
242 
243 #endif	/* _KERNEL */
244 
245 #ifdef	__cplusplus
246 }
247 #endif
248 
249 #endif	/* _FCOE_H_ */
250