xref: /titanic_41/usr/src/uts/common/io/fcoe/fcoe.h (revision 56b2bdd1f04d465cfe4a95b88ae5cba5884154e4)
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 #define	FCOE_MAC_FLAG_USER_DEL		0x04
160 
161 typedef struct fcoe_frame_header {
162 	uint8_t		 ffh_ver[1];	/* version field - upper 4 bits */
163 	uint8_t		 ffh_resvd[12];
164 	uint8_t		 ffh_sof[1];	/* start of frame per RFC 3643 */
165 } fcoe_frame_header_t;
166 
167 typedef struct fcoe_frame_tailer {
168 	uint8_t		 fft_crc[4];	/* FC packet CRC */
169 	uint8_t		 fft_eof[1];
170 	uint8_t		 fft_resvd[3];
171 } fcoe_frame_tailer_t;
172 
173 /*
174  * RAW frame structure
175  * It is used to describe the content of every mblk
176  */
177 typedef struct fcoe_i_frame {
178 	list_node_t		 fmi_pending_node;
179 
180 	fcoe_frame_t		*fmi_frame;	/* to common struct */
181 	fcoe_mac_t		*fmi_mac;	/* to/from where */
182 
183 	/*
184 	 * FRAME structure
185 	 */
186 	struct ether_header	*fmi_efh;	/* 14 bytes eth header */
187 	fcoe_frame_header_t	*fmi_ffh;	/* 14 bytes FCOE hader */
188 	uint8_t			*fmi_fc_frame;
189 	fcoe_frame_tailer_t	*fmi_fft;	/* 8 bytes FCOE tailer */
190 } fcoe_i_frame_t;
191 
192 typedef struct fcoe_worker {
193 	list_t		worker_frm_list;
194 	kmutex_t	worker_lock;
195 	kcondvar_t	worker_cv;
196 	uint32_t	worker_flags;
197 	uint32_t	worker_ntasks;
198 } fcoe_worker_t;
199 
200 #define	FCOE_WORKER_TERMINATE	0x01
201 #define	FCOE_WORKER_STARTED	0x02
202 #define	FCOE_WORKER_ACTIVE	0x04
203 
204 /*
205  * IOCTL supporting stuff
206  */
207 #define	FCOE_IOCTL_FLAG_MASK		0xFF
208 #define	FCOE_IOCTL_FLAG_IDLE		0x00
209 #define	FCOE_IOCTL_FLAG_OPEN		0x01
210 #define	FCOE_IOCTL_FLAG_EXCL		0x02
211 #define	FCOE_IOCTL_FLAG_EXCL_BUSY	0x04
212 
213 /*
214  * define common-used macros to simplify coding
215  */
216 #define	FCOE_FIP_TYPE		0x8914
217 #define	FCOE_802_1Q_TAG		0x8100
218 
219 #define	PADDING_HEADER_SIZE	(sizeof (struct ether_header) + \
220 	sizeof (fcoe_frame_header_t))
221 #define	PADDING_SIZE	(PADDING_HEADER_SIZE + sizeof (fcoe_frame_tailer_t))
222 
223 #define	EPORT2MAC(x_eport)	((fcoe_mac_t *)(x_eport)->eport_fcoe_private)
224 
225 #define	FRM2MAC(x_frm)		(EPORT2MAC((x_frm)->frm_eport))
226 #define	FRM2FMI(x_frm)		((fcoe_i_frame_t *)(x_frm)->frm_fcoe_private)
227 #define	FRM2MBLK(x_frm)		((mblk_t *)(x_frm)->frm_netb)
228 
229 #define	FCOE_VER			0
230 #define	FCOE_DECAPS_VER(x_ffh)		((x_ffh)->ffh_ver[0] >> 4)
231 #define	FCOE_ENCAPS_VER(x_ffh, x_v)			\
232 	{						\
233 		(x_ffh)->ffh_ver[0] = ((x_v) << 4);	\
234 	}
235 
236 /*
237  * fcoe driver common functions
238  */
239 extern fcoe_mac_t *fcoe_lookup_mac_by_id(datalink_id_t);
240 extern void fcoe_destroy_mac(fcoe_mac_t *);
241 extern mblk_t *fcoe_get_mblk(fcoe_mac_t *, uint32_t);
242 extern void fcoe_post_frame(fcoe_frame_t *);
243 
244 #endif	/* _KERNEL */
245 
246 #ifdef	__cplusplus
247 }
248 #endif
249 
250 #endif	/* _FCOE_H_ */
251