xref: /illumos-gate/usr/src/uts/common/io/fcoe/fcoe.h (revision 7ff83669)
12a8164dfSZhong Wang /*
22a8164dfSZhong Wang  * CDDL HEADER START
32a8164dfSZhong Wang  *
42a8164dfSZhong Wang  * The contents of this file are subject to the terms of the
52a8164dfSZhong Wang  * Common Development and Distribution License (the "License").
62a8164dfSZhong Wang  * You may not use this file except in compliance with the License.
72a8164dfSZhong Wang  *
82a8164dfSZhong Wang  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92a8164dfSZhong Wang  * or http://www.opensolaris.org/os/licensing.
102a8164dfSZhong Wang  * See the License for the specific language governing permissions
112a8164dfSZhong Wang  * and limitations under the License.
122a8164dfSZhong Wang  *
132a8164dfSZhong Wang  * When distributing Covered Code, include this CDDL HEADER in each
142a8164dfSZhong Wang  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152a8164dfSZhong Wang  * If applicable, add the following below this CDDL HEADER, with the
162a8164dfSZhong Wang  * fields enclosed by brackets "[]" replaced with your own identifying
172a8164dfSZhong Wang  * information: Portions Copyright [yyyy] [name of copyright owner]
182a8164dfSZhong Wang  *
192a8164dfSZhong Wang  * CDDL HEADER END
202a8164dfSZhong Wang  */
212a8164dfSZhong Wang /*
222a8164dfSZhong Wang  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
232a8164dfSZhong Wang  * Use is subject to license terms.
242a8164dfSZhong Wang  */
252a8164dfSZhong Wang 
262a8164dfSZhong Wang /*
272a8164dfSZhong Wang  * The following notice accompanied the original version of this file:
282a8164dfSZhong Wang  *
292a8164dfSZhong Wang  * BSD LICENSE
302a8164dfSZhong Wang  *
312a8164dfSZhong Wang  * Copyright(c) 2007 Intel Corporation. All rights reserved.
322a8164dfSZhong Wang  * All rights reserved.
332a8164dfSZhong Wang  *
342a8164dfSZhong Wang  * Redistribution and use in source and binary forms, with or without
352a8164dfSZhong Wang  * modification, are permitted provided that the following conditions
362a8164dfSZhong Wang  * are met:
372a8164dfSZhong Wang  *
382a8164dfSZhong Wang  *   * Redistributions of source code must retain the above copyright
392a8164dfSZhong Wang  *     notice, this list of conditions and the following disclaimer.
402a8164dfSZhong Wang  *   * Redistributions in binary form must reproduce the above copyright
412a8164dfSZhong Wang  *     notice, this list of conditions and the following disclaimer in
422a8164dfSZhong Wang  *     the documentation and/or other materials provided with the
432a8164dfSZhong Wang  *     distribution.
442a8164dfSZhong Wang  *   * Neither the name of Intel Corporation nor the names of its
452a8164dfSZhong Wang  *     contributors may be used to endorse or promote products derived
462a8164dfSZhong Wang  *     from this software without specific prior written permission.
472a8164dfSZhong Wang  *
482a8164dfSZhong Wang  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
492a8164dfSZhong Wang  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
502a8164dfSZhong Wang  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
512a8164dfSZhong Wang  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
522a8164dfSZhong Wang  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
532a8164dfSZhong Wang  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
542a8164dfSZhong Wang  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
552a8164dfSZhong Wang  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
562a8164dfSZhong Wang  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
572a8164dfSZhong Wang  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
582a8164dfSZhong Wang  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
592a8164dfSZhong Wang  */
602a8164dfSZhong Wang #ifndef	_FCOE_H_
612a8164dfSZhong Wang #define	_FCOE_H_
622a8164dfSZhong Wang 
632a8164dfSZhong Wang #ifdef	__cplusplus
642a8164dfSZhong Wang extern "C" {
652a8164dfSZhong Wang #endif
662a8164dfSZhong Wang 
672a8164dfSZhong Wang #ifdef	_KERNEL
682a8164dfSZhong Wang 
692a8164dfSZhong Wang extern int			 fcoe_use_ext_log;
702a8164dfSZhong Wang extern struct fcoe_soft_state	*fcoe_global_ss;
712a8164dfSZhong Wang 
722a8164dfSZhong Wang /*
732a8164dfSZhong Wang  * Caution: 1) LOG will be available in debug/non-debug mode
742a8164dfSZhong Wang  *	    2) Anything which can potentially flood the log should be under
752a8164dfSZhong Wang  *	       extended logging, and use FCOE_EXT_LOG.
762a8164dfSZhong Wang  *	    3) Don't use FCOE_EXT_LOG in performance-critical code path, such
772a8164dfSZhong Wang  *	       as normal SCSI I/O code path. It could hurt system performance.
782a8164dfSZhong Wang  *	    4) Use kmdb to change foce_use_ext_log in the fly to adjust
792a8164dfSZhong Wang  *	       tracing
802a8164dfSZhong Wang  */
812a8164dfSZhong Wang #define	FCOE_EXT_LOG(log_ident, ...)	\
822a8164dfSZhong Wang 	do {	\
832a8164dfSZhong Wang 		if (fcoe_use_ext_log) {	\
842a8164dfSZhong Wang 			fcoe_trace(log_ident, __VA_ARGS__);	\
852a8164dfSZhong Wang 		}	\
862a8164dfSZhong Wang 	} while (0)
872a8164dfSZhong Wang 
882a8164dfSZhong Wang #define	FCOE_LOG(log_ident, ...)	\
892a8164dfSZhong Wang 	fcoe_trace(log_ident, __VA_ARGS__)
902a8164dfSZhong Wang 
912a8164dfSZhong Wang /*
922a8164dfSZhong Wang  * There will be only one fcoe instance
932a8164dfSZhong Wang  */
942a8164dfSZhong Wang typedef struct fcoe_soft_state {
952a8164dfSZhong Wang 	dev_info_t	*ss_dip;
962a8164dfSZhong Wang 	uint32_t	 ss_flags;
972a8164dfSZhong Wang 	list_t		 ss_mac_list;
982a8164dfSZhong Wang 	uint32_t	 ss_ioctl_flags;
992a8164dfSZhong Wang 	kmutex_t	 ss_ioctl_mutex;
1002a8164dfSZhong Wang 
1012a8164dfSZhong Wang 	/*
1022a8164dfSZhong Wang 	 * watchdog stuff
1032a8164dfSZhong Wang 	 */
1042a8164dfSZhong Wang 	ddi_taskq_t	*ss_watchdog_taskq;
1052a8164dfSZhong Wang 	kcondvar_t	 ss_watch_cv;
1062a8164dfSZhong Wang 	kmutex_t	 ss_watch_mutex;
1072a8164dfSZhong Wang 	list_t		 ss_pfrm_list;	/* Pending frame */
1082a8164dfSZhong Wang } fcoe_soft_state_t;
1092a8164dfSZhong Wang 
1102a8164dfSZhong Wang #define	SS_FLAG_TERMINATE_WATCHDOG	0x0020
1112a8164dfSZhong Wang #define	SS_FLAG_WATCHDOG_RUNNING	0x0040
1122a8164dfSZhong Wang #define	SS_FLAG_DOG_WAITING		0x0080
1132a8164dfSZhong Wang 
1142a8164dfSZhong Wang /*
1152a8164dfSZhong Wang  *  Driver name
1162a8164dfSZhong Wang  */
1172a8164dfSZhong Wang #define	FCOEI_DRIVER_NAME	"fcoei"
1182a8164dfSZhong Wang #define	FCOET_DRIVER_NAME	"fcoet"
1192a8164dfSZhong Wang 
1202a8164dfSZhong Wang /*
1212a8164dfSZhong Wang  * One for each ethernet port
1222a8164dfSZhong Wang  */
1232a8164dfSZhong Wang typedef struct fcoe_mac
1242a8164dfSZhong Wang {
1252a8164dfSZhong Wang 	list_node_t		fm_ss_node;
126d4401b99SKelly Hu 	datalink_id_t		fm_linkid;
1272a8164dfSZhong Wang 	uint32_t		fm_flags;
1282a8164dfSZhong Wang 
1292a8164dfSZhong Wang 	fcoe_soft_state_t	*fm_ss;
1302a8164dfSZhong Wang 	fcoe_port_t		fm_eport;
1312a8164dfSZhong Wang 	fcoe_client_t		fm_client;
1322a8164dfSZhong Wang 	dev_info_t		*fm_client_dev;
1332a8164dfSZhong Wang 
1342a8164dfSZhong Wang 	mac_handle_t		fm_handle;
1352a8164dfSZhong Wang 	mac_client_handle_t	fm_cli_handle;
1362a8164dfSZhong Wang 	mac_promisc_handle_t	fm_promisc_handle;
1372a8164dfSZhong Wang 	mac_notify_handle_t	fm_notify_handle;
1382a8164dfSZhong Wang 	mac_unicast_handle_t	fm_unicst_handle;
1392a8164dfSZhong Wang 	uint8_t			fm_primary_addr[ETHERADDRL];
1402a8164dfSZhong Wang 	uint8_t			fm_current_addr[ETHERADDRL];
1412a8164dfSZhong Wang 	uint32_t		fm_running:1,
1422a8164dfSZhong Wang 				fm_force_promisc:1,
1432a8164dfSZhong Wang 				fm_rsvd:18,
1442a8164dfSZhong Wang 				fm_state:4,
1452a8164dfSZhong Wang 				fm_link_state:8;
1462a8164dfSZhong Wang 	uint32_t		fm_frm_cnt;
1472a8164dfSZhong Wang 	kcondvar_t		fm_tx_cv;
1482a8164dfSZhong Wang 	kmutex_t		fm_mutex;
1492a8164dfSZhong Wang } fcoe_mac_t;
1502a8164dfSZhong Wang 
1512a8164dfSZhong Wang #define	FCOE_MAC_STATE_OFFLINE		0x0
1522a8164dfSZhong Wang #define	FCOE_MAC_STATE_ONLINE		0x1
1532a8164dfSZhong Wang 
1542a8164dfSZhong Wang #define	FCOE_MAC_LINK_STATE_DOWN	0x00
1552a8164dfSZhong Wang #define	FCOE_MAC_LINK_STATE_UP		0x01
1562a8164dfSZhong Wang 
1572a8164dfSZhong Wang #define	FCOE_MAC_FLAG_ENABLED		0x01
1582a8164dfSZhong Wang #define	FCOE_MAC_FLAG_BOUND		0x02
159*7ff83669SZhong Wang #define	FCOE_MAC_FLAG_USER_DEL		0x04
1602a8164dfSZhong Wang 
1612a8164dfSZhong Wang typedef struct fcoe_frame_header {
1622a8164dfSZhong Wang 	uint8_t		 ffh_ver[1];	/* version field - upper 4 bits */
1632a8164dfSZhong Wang 	uint8_t		 ffh_resvd[12];
1642a8164dfSZhong Wang 	uint8_t		 ffh_sof[1];	/* start of frame per RFC 3643 */
1652a8164dfSZhong Wang } fcoe_frame_header_t;
1662a8164dfSZhong Wang 
1672a8164dfSZhong Wang typedef struct fcoe_frame_tailer {
1682a8164dfSZhong Wang 	uint8_t		 fft_crc[4];	/* FC packet CRC */
1692a8164dfSZhong Wang 	uint8_t		 fft_eof[1];
1702a8164dfSZhong Wang 	uint8_t		 fft_resvd[3];
1712a8164dfSZhong Wang } fcoe_frame_tailer_t;
1722a8164dfSZhong Wang 
1732a8164dfSZhong Wang /*
1742a8164dfSZhong Wang  * RAW frame structure
1752a8164dfSZhong Wang  * It is used to describe the content of every mblk
1762a8164dfSZhong Wang  */
1772a8164dfSZhong Wang typedef struct fcoe_i_frame {
1782a8164dfSZhong Wang 	list_node_t		 fmi_pending_node;
1792a8164dfSZhong Wang 
1802a8164dfSZhong Wang 	fcoe_frame_t		*fmi_frame;	/* to common struct */
1812a8164dfSZhong Wang 	fcoe_mac_t		*fmi_mac;	/* to/from where */
1822a8164dfSZhong Wang 
1832a8164dfSZhong Wang 	/*
1842a8164dfSZhong Wang 	 * FRAME structure
1852a8164dfSZhong Wang 	 */
1862a8164dfSZhong Wang 	struct ether_header	*fmi_efh;	/* 14 bytes eth header */
1872a8164dfSZhong Wang 	fcoe_frame_header_t	*fmi_ffh;	/* 14 bytes FCOE hader */
1882a8164dfSZhong Wang 	uint8_t			*fmi_fc_frame;
1892a8164dfSZhong Wang 	fcoe_frame_tailer_t	*fmi_fft;	/* 8 bytes FCOE tailer */
1902a8164dfSZhong Wang } fcoe_i_frame_t;
1912a8164dfSZhong Wang 
1922a8164dfSZhong Wang typedef struct fcoe_worker {
1932a8164dfSZhong Wang 	list_t		worker_frm_list;
1942a8164dfSZhong Wang 	kmutex_t	worker_lock;
1952a8164dfSZhong Wang 	kcondvar_t	worker_cv;
1962a8164dfSZhong Wang 	uint32_t	worker_flags;
1972a8164dfSZhong Wang 	uint32_t	worker_ntasks;
1982a8164dfSZhong Wang } fcoe_worker_t;
1992a8164dfSZhong Wang 
2002a8164dfSZhong Wang #define	FCOE_WORKER_TERMINATE	0x01
2012a8164dfSZhong Wang #define	FCOE_WORKER_STARTED	0x02
2022a8164dfSZhong Wang #define	FCOE_WORKER_ACTIVE	0x04
2032a8164dfSZhong Wang 
2042a8164dfSZhong Wang /*
2052a8164dfSZhong Wang  * IOCTL supporting stuff
2062a8164dfSZhong Wang  */
2072a8164dfSZhong Wang #define	FCOE_IOCTL_FLAG_MASK		0xFF
2082a8164dfSZhong Wang #define	FCOE_IOCTL_FLAG_IDLE		0x00
2092a8164dfSZhong Wang #define	FCOE_IOCTL_FLAG_OPEN		0x01
2102a8164dfSZhong Wang #define	FCOE_IOCTL_FLAG_EXCL		0x02
2112a8164dfSZhong Wang #define	FCOE_IOCTL_FLAG_EXCL_BUSY	0x04
2122a8164dfSZhong Wang 
2132a8164dfSZhong Wang /*
2142a8164dfSZhong Wang  * define common-used macros to simplify coding
2152a8164dfSZhong Wang  */
2162a8164dfSZhong Wang #define	FCOE_FIP_TYPE		0x8914
2172a8164dfSZhong Wang #define	FCOE_802_1Q_TAG		0x8100
2182a8164dfSZhong Wang 
2192a8164dfSZhong Wang #define	PADDING_HEADER_SIZE	(sizeof (struct ether_header) + \
2202a8164dfSZhong Wang 	sizeof (fcoe_frame_header_t))
2212a8164dfSZhong Wang #define	PADDING_SIZE	(PADDING_HEADER_SIZE + sizeof (fcoe_frame_tailer_t))
2222a8164dfSZhong Wang 
2232a8164dfSZhong Wang #define	EPORT2MAC(x_eport)	((fcoe_mac_t *)(x_eport)->eport_fcoe_private)
2242a8164dfSZhong Wang 
2252a8164dfSZhong Wang #define	FRM2MAC(x_frm)		(EPORT2MAC((x_frm)->frm_eport))
2262a8164dfSZhong Wang #define	FRM2FMI(x_frm)		((fcoe_i_frame_t *)(x_frm)->frm_fcoe_private)
2272a8164dfSZhong Wang #define	FRM2MBLK(x_frm)		((mblk_t *)(x_frm)->frm_netb)
2282a8164dfSZhong Wang 
2292a8164dfSZhong Wang #define	FCOE_VER			0
2302a8164dfSZhong Wang #define	FCOE_DECAPS_VER(x_ffh)		((x_ffh)->ffh_ver[0] >> 4)
2312a8164dfSZhong Wang #define	FCOE_ENCAPS_VER(x_ffh, x_v)			\
2322a8164dfSZhong Wang 	{						\
2332a8164dfSZhong Wang 		(x_ffh)->ffh_ver[0] = ((x_v) << 4);	\
2342a8164dfSZhong Wang 	}
2352a8164dfSZhong Wang 
2362a8164dfSZhong Wang /*
2372a8164dfSZhong Wang  * fcoe driver common functions
2382a8164dfSZhong Wang  */
239d4401b99SKelly Hu extern fcoe_mac_t *fcoe_lookup_mac_by_id(datalink_id_t);
2402a8164dfSZhong Wang extern void fcoe_destroy_mac(fcoe_mac_t *);
2412a8164dfSZhong Wang extern mblk_t *fcoe_get_mblk(fcoe_mac_t *, uint32_t);
2422a8164dfSZhong Wang extern void fcoe_post_frame(fcoe_frame_t *);
2432a8164dfSZhong Wang 
2442a8164dfSZhong Wang #endif	/* _KERNEL */
2452a8164dfSZhong Wang 
2462a8164dfSZhong Wang #ifdef	__cplusplus
2472a8164dfSZhong Wang }
2482a8164dfSZhong Wang #endif
2492a8164dfSZhong Wang 
2502a8164dfSZhong Wang #endif	/* _FCOE_H_ */
251