xref: /onnv-gate/usr/src/uts/common/sys/nxge/nxge_txdma.h (revision 6886:da8ca932add7)
13859Sml29623 /*
23859Sml29623  * CDDL HEADER START
33859Sml29623  *
43859Sml29623  * The contents of this file are subject to the terms of the
53859Sml29623  * Common Development and Distribution License (the "License").
63859Sml29623  * You may not use this file except in compliance with the License.
73859Sml29623  *
83859Sml29623  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93859Sml29623  * or http://www.opensolaris.org/os/licensing.
103859Sml29623  * See the License for the specific language governing permissions
113859Sml29623  * and limitations under the License.
123859Sml29623  *
133859Sml29623  * When distributing Covered Code, include this CDDL HEADER in each
143859Sml29623  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153859Sml29623  * If applicable, add the following below this CDDL HEADER, with the
163859Sml29623  * fields enclosed by brackets "[]" replaced with your own identifying
173859Sml29623  * information: Portions Copyright [yyyy] [name of copyright owner]
183859Sml29623  *
193859Sml29623  * CDDL HEADER END
203859Sml29623  */
213859Sml29623 /*
226495Sspeer  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233859Sml29623  * Use is subject to license terms.
243859Sml29623  */
253859Sml29623 
263859Sml29623 #ifndef	_SYS_NXGE_NXGE_TXDMA_H
273859Sml29623 #define	_SYS_NXGE_NXGE_TXDMA_H
283859Sml29623 
293859Sml29623 #pragma ident	"%Z%%M%	%I%	%E% SMI"
303859Sml29623 
313859Sml29623 #ifdef	__cplusplus
323859Sml29623 extern "C" {
333859Sml29623 #endif
343859Sml29623 
353859Sml29623 #include <sys/nxge/nxge_txdma_hw.h>
363859Sml29623 #include <npi_txdma.h>
373952Sml29623 #include <sys/nxge/nxge_serialize.h>
383859Sml29623 
393859Sml29623 #define	TXDMA_PORT_BITMAP(nxgep)		(nxgep->pt_config.tx_dma_map)
403859Sml29623 
413859Sml29623 #define	TXDMA_RECLAIM_PENDING_DEFAULT		64
423859Sml29623 #define	TX_FULL_MARK				3
433859Sml29623 
443859Sml29623 /*
453859Sml29623  * Transmit load balancing definitions.
463859Sml29623  */
473859Sml29623 #define	NXGE_TX_LB_TCPUDP			0	/* default policy */
483859Sml29623 #define	NXGE_TX_LB_HASH				1	/* from the hint data */
493859Sml29623 #define	NXGE_TX_LB_DEST_MAC			2	/* Dest. MAC */
503859Sml29623 
513859Sml29623 /*
523859Sml29623  * Descriptor ring empty:
533859Sml29623  *		(1) head index is equal to tail index.
543859Sml29623  *		(2) wrapped around bits are the same.
553859Sml29623  * Descriptor ring full:
563859Sml29623  *		(1) head index is equal to tail index.
573859Sml29623  *		(2) wrapped around bits are different.
583859Sml29623  *
593859Sml29623  */
603859Sml29623 #define	TXDMA_RING_EMPTY(head, head_wrap, tail, tail_wrap)	\
613859Sml29623 	((head == tail && head_wrap == tail_wrap) ? B_TRUE : B_FALSE)
623859Sml29623 
633859Sml29623 #define	TXDMA_RING_FULL(head, head_wrap, tail, tail_wrap)	\
643859Sml29623 	((head == tail && head_wrap != tail_wrap) ? B_TRUE : B_FALSE)
653859Sml29623 
663859Sml29623 #define	TXDMA_DESC_NEXT_INDEX(index, entries, wrap_mask) \
673859Sml29623 			((index + entries) & wrap_mask)
683859Sml29623 
693859Sml29623 #define	TXDMA_DRR_WEIGHT_DEFAULT	0x001f
703859Sml29623 
713952Sml29623 typedef enum {
723952Sml29623 	NXGE_USE_SERIAL	= 0,
733952Sml29623 	NXGE_USE_START,
743952Sml29623 } nxge_tx_mode_t;
753952Sml29623 
763859Sml29623 typedef struct _tx_msg_t {
773859Sml29623 	nxge_os_block_mv_t 	flags;		/* DMA, BCOPY, DVMA (?) */
783859Sml29623 	nxge_os_dma_common_t	buf_dma;	/* premapped buffer blocks */
793859Sml29623 	nxge_os_dma_handle_t	buf_dma_handle; /* premapped buffer handle */
803859Sml29623 	nxge_os_dma_handle_t 	dma_handle;	/* DMA handle for normal send */
813859Sml29623 	nxge_os_dma_handle_t 	dvma_handle;	/* Fast DVMA  handle */
823859Sml29623 
833859Sml29623 	p_mblk_t 		tx_message;
843859Sml29623 	uint32_t 		tx_msg_size;
853859Sml29623 	size_t			bytes_used;
863859Sml29623 	int			head;
873859Sml29623 	int			tail;
883859Sml29623 } tx_msg_t, *p_tx_msg_t;
893859Sml29623 
903859Sml29623 /*
913859Sml29623  * TX  Statistics.
923859Sml29623  */
933859Sml29623 typedef struct _nxge_tx_ring_stats_t {
943859Sml29623 	uint64_t	opackets;
953859Sml29623 	uint64_t	obytes;
963859Sml29623 	uint64_t	oerrors;
973859Sml29623 
983859Sml29623 	uint32_t	tx_inits;
993859Sml29623 	uint32_t	tx_no_buf;
1003859Sml29623 
1013859Sml29623 	uint32_t		mbox_err;
1023859Sml29623 	uint32_t		pkt_size_err;
1033859Sml29623 	uint32_t 		tx_ring_oflow;
1043859Sml29623 	uint32_t 		pre_buf_par_err;
1053859Sml29623 	uint32_t 		nack_pref;
1063859Sml29623 	uint32_t 		nack_pkt_rd;
1073859Sml29623 	uint32_t 		conf_part_err;
1083859Sml29623 	uint32_t 		pkt_part_err;
1093859Sml29623 	uint32_t		tx_starts;
1103859Sml29623 	uint32_t		tx_nocanput;
1113859Sml29623 	uint32_t		tx_msgdup_fail;
1123859Sml29623 	uint32_t		tx_allocb_fail;
1133859Sml29623 	uint32_t		tx_no_desc;
1143859Sml29623 	uint32_t		tx_dma_bind_fail;
1153859Sml29623 	uint32_t		tx_uflo;
1163859Sml29623 
1173859Sml29623 	uint32_t		tx_hdr_pkts;
1183859Sml29623 	uint32_t		tx_ddi_pkts;
1193859Sml29623 	uint32_t		tx_dvma_pkts;
1203859Sml29623 
1213859Sml29623 	uint32_t		tx_max_pend;
1223859Sml29623 	uint32_t		tx_jumbo_pkts;
1233859Sml29623 
1243859Sml29623 	txdma_ring_errlog_t	errlog;
1253859Sml29623 } nxge_tx_ring_stats_t, *p_nxge_tx_ring_stats_t;
1263859Sml29623 
1273859Sml29623 typedef struct _tx_ring_t {
1283859Sml29623 	nxge_os_dma_common_t	tdc_desc;
1293859Sml29623 	struct _nxge_t		*nxgep;
1303859Sml29623 	p_tx_msg_t 		tx_msg_ring;
1313859Sml29623 	uint32_t		tnblocks;
1323859Sml29623 	tx_rng_cfig_t		tx_ring_cfig;
1333859Sml29623 	tx_ring_hdl_t		tx_ring_hdl;
1343859Sml29623 	tx_ring_kick_t		tx_ring_kick;
1353859Sml29623 	tx_cs_t			tx_cs;
1363859Sml29623 	tx_dma_ent_msk_t	tx_evmask;
1373859Sml29623 	txdma_mbh_t		tx_mbox_mbh;
1383859Sml29623 	txdma_mbl_t		tx_mbox_mbl;
1393859Sml29623 	log_page_vld_t		page_valid;
1403859Sml29623 	log_page_mask_t		page_mask_1;
1413859Sml29623 	log_page_mask_t		page_mask_2;
1423859Sml29623 	log_page_value_t	page_value_1;
1433859Sml29623 	log_page_value_t	page_value_2;
1443859Sml29623 	log_page_relo_t		page_reloc_1;
1453859Sml29623 	log_page_relo_t		page_reloc_2;
1463859Sml29623 	log_page_hdl_t		page_hdl;
1473859Sml29623 	txc_dma_max_burst_t	max_burst;
1483859Sml29623 	boolean_t		cfg_set;
1496713Sspeer #define	NXGE_TX_RING_ONLINE	0x00
1506713Sspeer #define	NXGE_TX_RING_OFFLINING	0x01
1516713Sspeer #define	NXGE_TX_RING_OFFLINED	0x02
1526713Sspeer 	uint32_t		tx_ring_offline;
153*6886Sspeer 	boolean_t		tx_ring_busy;
1543859Sml29623 
1553859Sml29623 	nxge_os_mutex_t		lock;
1563859Sml29623 	uint16_t 		index;
1573859Sml29623 	uint16_t		tdc;
1583859Sml29623 	struct nxge_tdc_cfg	*tdc_p;
1593859Sml29623 	uint_t 			tx_ring_size;
1603859Sml29623 	uint32_t 		num_chunks;
1613859Sml29623 
1623859Sml29623 	uint_t 			tx_wrap_mask;
1633859Sml29623 	uint_t 			rd_index;
1643859Sml29623 	uint_t 			wr_index;
1653859Sml29623 	boolean_t		wr_index_wrap;
1663859Sml29623 	uint_t 			head_index;
1673859Sml29623 	boolean_t		head_wrap;
1683859Sml29623 	tx_ring_hdl_t		ring_head;
1693859Sml29623 	tx_ring_kick_t		ring_kick_tail;
1703859Sml29623 	txdma_mailbox_t		tx_mbox;
1713859Sml29623 
1723859Sml29623 	uint_t 			descs_pending;
1733859Sml29623 	boolean_t 		queueing;
1743859Sml29623 
1753859Sml29623 	nxge_os_mutex_t		sq_lock;
1763952Sml29623 	nxge_serialize_t 	*serial;
1773859Sml29623 	p_mblk_t 		head;
1783859Sml29623 	p_mblk_t 		tail;
1793859Sml29623 
1803859Sml29623 	uint16_t		ldg_group_id;
1813859Sml29623 	p_nxge_tx_ring_stats_t tdc_stats;
1823859Sml29623 
1833859Sml29623 	nxge_os_mutex_t 	dvma_lock;
1843859Sml29623 	uint_t 			dvma_wr_index;
1853859Sml29623 	uint_t 			dvma_rd_index;
1863859Sml29623 	uint_t 			dvma_pending;
1873859Sml29623 	uint_t 			dvma_available;
1883859Sml29623 	uint_t 			dvma_wrap_mask;
1893859Sml29623 
1903859Sml29623 	nxge_os_dma_handle_t 	*dvma_ring;
1913859Sml29623 
1923859Sml29623 #if	defined(sun4v) && defined(NIU_LP_WORKAROUND)
1933859Sml29623 	uint64_t		hv_tx_buf_base_ioaddr_pp;
1943859Sml29623 	uint64_t		hv_tx_buf_ioaddr_size;
1953859Sml29623 	uint64_t		hv_tx_cntl_base_ioaddr_pp;
1963859Sml29623 	uint64_t		hv_tx_cntl_ioaddr_size;
1973859Sml29623 	boolean_t		hv_set;
1983859Sml29623 #endif
1993859Sml29623 } tx_ring_t, *p_tx_ring_t;
2003859Sml29623 
2013859Sml29623 
2023859Sml29623 /* Transmit Mailbox */
2033859Sml29623 typedef struct _tx_mbox_t {
2043859Sml29623 	nxge_os_mutex_t 	lock;
2053859Sml29623 	uint16_t		index;
2063859Sml29623 	struct _nxge_t		*nxgep;
2073859Sml29623 	uint16_t		tdc;
2083859Sml29623 	nxge_os_dma_common_t	tx_mbox;
2093859Sml29623 	txdma_mbl_t		tx_mbox_l;
2103859Sml29623 	txdma_mbh_t		tx_mbox_h;
2113859Sml29623 } tx_mbox_t, *p_tx_mbox_t;
2123859Sml29623 
2133859Sml29623 typedef struct _tx_rings_t {
2143859Sml29623 	p_tx_ring_t 		*rings;
2153859Sml29623 	boolean_t		txdesc_allocated;
2163859Sml29623 	uint32_t		ndmas;
2173859Sml29623 	nxge_os_dma_common_t	tdc_dma;
2183859Sml29623 	nxge_os_dma_common_t	tdc_mbox;
2193859Sml29623 } tx_rings_t, *p_tx_rings_t;
2203859Sml29623 
2213859Sml29623 
2223859Sml29623 #if defined(_KERNEL) || (defined(COSIM) && !defined(IODIAG))
2233859Sml29623 
2243859Sml29623 typedef struct _tx_buf_rings_t {
2253859Sml29623 	struct _tx_buf_ring_t 	*txbuf_rings;
2263859Sml29623 	boolean_t		txbuf_allocated;
2273859Sml29623 } tx_buf_rings_t, *p_tx_buf_rings_t;
2283859Sml29623 
2293859Sml29623 #endif
2303859Sml29623 
2313859Sml29623 typedef struct _tx_mbox_areas_t {
2323859Sml29623 	p_tx_mbox_t 		*txmbox_areas_p;
2333859Sml29623 	boolean_t		txmbox_allocated;
2343859Sml29623 } tx_mbox_areas_t, *p_tx_mbox_areas_t;
2353859Sml29623 
2363859Sml29623 typedef struct _tx_param_t {
2373859Sml29623 	nxge_logical_page_t tx_logical_pages[NXGE_MAX_LOGICAL_PAGES];
2383859Sml29623 } tx_param_t, *p_tx_param_t;
2393859Sml29623 
2403859Sml29623 typedef struct _tx_params {
2413859Sml29623 	struct _tx_param_t 	*tx_param_p;
2423859Sml29623 } tx_params_t, *p_tx_params_t;
2433859Sml29623 
2443859Sml29623 /*
2453859Sml29623  * Global register definitions per chip and they are initialized
2463859Sml29623  * using the function zero control registers.
2473859Sml29623  * .
2483859Sml29623  */
2493859Sml29623 typedef struct _txdma_globals {
2503859Sml29623 	boolean_t		mode32;
2513859Sml29623 } txdma_globals_t, *p_txdma_globals;
2523859Sml29623 
2533859Sml29623 
2543859Sml29623 #if	defined(SOLARIS) && (defined(_KERNEL) || \
2553859Sml29623 	(defined(COSIM) && !defined(IODIAG)))
2563859Sml29623 
2573859Sml29623 /*
2583859Sml29623  * Transmit prototypes.
2593859Sml29623  */
2603859Sml29623 nxge_status_t nxge_init_txdma_channels(p_nxge_t);
2613859Sml29623 void nxge_uninit_txdma_channels(p_nxge_t);
2626495Sspeer 
2636495Sspeer nxge_status_t nxge_init_txdma_channel(p_nxge_t, int);
2646495Sspeer void nxge_uninit_txdma_channel(p_nxge_t, int);
2656495Sspeer 
2663859Sml29623 void nxge_setup_dma_common(p_nxge_dma_common_t, p_nxge_dma_common_t,
2673859Sml29623 		uint32_t, uint32_t);
2683859Sml29623 nxge_status_t nxge_reset_txdma_channel(p_nxge_t, uint16_t,
2693859Sml29623 	uint64_t);
2703859Sml29623 nxge_status_t nxge_init_txdma_channel_event_mask(p_nxge_t,
2713859Sml29623 	uint16_t, p_tx_dma_ent_msk_t);
2723859Sml29623 nxge_status_t nxge_init_txdma_channel_cntl_stat(p_nxge_t,
2733859Sml29623 	uint16_t, uint64_t);
2743859Sml29623 nxge_status_t nxge_enable_txdma_channel(p_nxge_t, uint16_t,
2753859Sml29623 	p_tx_ring_t, p_tx_mbox_t);
2763859Sml29623 
2773859Sml29623 p_mblk_t nxge_tx_pkt_header_reserve(p_mblk_t, uint8_t *);
2783859Sml29623 int nxge_tx_pkt_nmblocks(p_mblk_t, int *);
2793859Sml29623 boolean_t nxge_txdma_reclaim(p_nxge_t, p_tx_ring_t, int);
2803859Sml29623 
2813859Sml29623 void nxge_fill_tx_hdr(p_mblk_t, boolean_t, boolean_t,
2826611Sml29623 	int, uint8_t, p_tx_pkt_hdr_all_t, t_uscalar_t, t_uscalar_t);
2833859Sml29623 
2843859Sml29623 nxge_status_t nxge_txdma_hw_mode(p_nxge_t, boolean_t);
2853859Sml29623 void nxge_hw_start_tx(p_nxge_t);
2863859Sml29623 void nxge_txdma_stop(p_nxge_t);
2873859Sml29623 void nxge_txdma_stop_start(p_nxge_t);
2883859Sml29623 void nxge_fixup_txdma_rings(p_nxge_t);
2893859Sml29623 void nxge_txdma_hw_kick(p_nxge_t);
2903859Sml29623 void nxge_txdma_fix_channel(p_nxge_t, uint16_t);
2913859Sml29623 void nxge_txdma_fixup_channel(p_nxge_t, p_tx_ring_t,
2923859Sml29623 	uint16_t);
2933859Sml29623 void nxge_txdma_hw_kick_channel(p_nxge_t, p_tx_ring_t,
2943859Sml29623 	uint16_t);
2953859Sml29623 
2963859Sml29623 void nxge_txdma_regs_dump(p_nxge_t, int);
2973859Sml29623 void nxge_txdma_regs_dump_channels(p_nxge_t);
2983859Sml29623 
2993859Sml29623 void nxge_check_tx_hang(p_nxge_t);
3003859Sml29623 void nxge_fixup_hung_txdma_rings(p_nxge_t);
3013859Sml29623 
3023859Sml29623 void nxge_reclaim_rings(p_nxge_t);
3033859Sml29623 int nxge_txdma_channel_hung(p_nxge_t,
3043859Sml29623 	p_tx_ring_t tx_ring_p, uint16_t);
3053859Sml29623 int nxge_txdma_hung(p_nxge_t);
3063859Sml29623 int nxge_txdma_stop_inj_err(p_nxge_t, int);
3073859Sml29623 void nxge_txdma_inject_err(p_nxge_t, uint32_t, uint8_t);
3083859Sml29623 
3096495Sspeer extern nxge_status_t nxge_alloc_tx_mem_pool(p_nxge_t);
3106495Sspeer extern nxge_status_t nxge_alloc_txb(p_nxge_t nxgep, int channel);
3116495Sspeer extern void nxge_free_txb(p_nxge_t nxgep, int channel);
3126495Sspeer 
3133859Sml29623 #endif
3143859Sml29623 
3153859Sml29623 #ifdef	__cplusplus
3163859Sml29623 }
3173859Sml29623 #endif
3183859Sml29623 
3193859Sml29623 #endif	/* _SYS_NXGE_NXGE_TXDMA_H */
320