xref: /onnv-gate/usr/src/uts/common/io/hxge/hxge_txdma.h (revision 8718:3ebdab15f891)
16349Sqs148142 /*
26349Sqs148142  * CDDL HEADER START
36349Sqs148142  *
46349Sqs148142  * The contents of this file are subject to the terms of the
56349Sqs148142  * Common Development and Distribution License (the "License").
66349Sqs148142  * You may not use this file except in compliance with the License.
76349Sqs148142  *
86349Sqs148142  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96349Sqs148142  * or http://www.opensolaris.org/os/licensing.
106349Sqs148142  * See the License for the specific language governing permissions
116349Sqs148142  * and limitations under the License.
126349Sqs148142  *
136349Sqs148142  * When distributing Covered Code, include this CDDL HEADER in each
146349Sqs148142  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156349Sqs148142  * If applicable, add the following below this CDDL HEADER, with the
166349Sqs148142  * fields enclosed by brackets "[]" replaced with your own identifying
176349Sqs148142  * information: Portions Copyright [yyyy] [name of copyright owner]
186349Sqs148142  *
196349Sqs148142  * CDDL HEADER END
206349Sqs148142  */
216349Sqs148142 /*
228476SMichael.Speer@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
236349Sqs148142  * Use is subject to license terms.
246349Sqs148142  */
256349Sqs148142 
266349Sqs148142 #ifndef	_SYS_HXGE_HXGE_TXDMA_H
276349Sqs148142 #define	_SYS_HXGE_HXGE_TXDMA_H
286349Sqs148142 
296349Sqs148142 #ifdef	__cplusplus
306349Sqs148142 extern "C" {
316349Sqs148142 #endif
326349Sqs148142 
33*8718SMichael.Speer@Sun.COM #include <sys/taskq.h>
346349Sqs148142 #include <hxge_txdma_hw.h>
356349Sqs148142 #include <hpi_txdma.h>
366349Sqs148142 
376349Sqs148142 #define	TXDMA_RECLAIM_PENDING_DEFAULT		64
386349Sqs148142 #define	TX_FULL_MARK				3
396349Sqs148142 
406349Sqs148142 /*
416349Sqs148142  * Transmit load balancing definitions.
426349Sqs148142  */
436349Sqs148142 #define	HXGE_TX_LB_TCPUDP	0	/* default policy */
446349Sqs148142 #define	HXGE_TX_LB_HASH		1	/* from the hint data */
456349Sqs148142 #define	HXGE_TX_LB_DEST_MAC	2	/* Dest. MAC */
466349Sqs148142 
476349Sqs148142 /*
486349Sqs148142  * Descriptor ring empty:
496349Sqs148142  *		(1) head index is equal to tail index.
506349Sqs148142  *		(2) wrapped around bits are the same.
516349Sqs148142  * Descriptor ring full:
526349Sqs148142  *		(1) head index is equal to tail index.
536349Sqs148142  *		(2) wrapped around bits are different.
546349Sqs148142  *
556349Sqs148142  */
566349Sqs148142 #define	TXDMA_RING_EMPTY(head, head_wrap, tail, tail_wrap)	\
576349Sqs148142 	((head == tail && head_wrap == tail_wrap) ? B_TRUE : B_FALSE)
586349Sqs148142 
596349Sqs148142 #define	TXDMA_RING_FULL(head, head_wrap, tail, tail_wrap)	\
606349Sqs148142 	((head == tail && head_wrap != tail_wrap) ? B_TRUE : B_FALSE)
616349Sqs148142 
626349Sqs148142 #define	TXDMA_DESC_NEXT_INDEX(index, entries, wrap_mask) \
636349Sqs148142 			((index + entries) & wrap_mask)
646349Sqs148142 
656349Sqs148142 typedef struct _tx_msg_t {
666349Sqs148142 	hxge_os_block_mv_t	flags;		/* DMA, BCOPY, DVMA (?) */
676349Sqs148142 	hxge_os_dma_common_t	buf_dma;	/* premapped buffer blocks */
686349Sqs148142 	hxge_os_dma_handle_t	buf_dma_handle;	/* premapped buffer handle */
696349Sqs148142 	hxge_os_dma_handle_t	dma_handle;	/* DMA handle for normal send */
706349Sqs148142 	hxge_os_dma_handle_t	dvma_handle;	/* Fast DVMA  handle */
716349Sqs148142 
726349Sqs148142 	p_mblk_t		tx_message;
736349Sqs148142 	uint32_t		tx_msg_size;
746349Sqs148142 	size_t			bytes_used;
756349Sqs148142 	int			head;
766349Sqs148142 	int			tail;
778476SMichael.Speer@Sun.COM 	int			offset_index;
786349Sqs148142 } tx_msg_t, *p_tx_msg_t;
796349Sqs148142 
806349Sqs148142 /*
816349Sqs148142  * TX  Statistics.
826349Sqs148142  */
836349Sqs148142 typedef struct _hxge_tx_ring_stats_t {
846349Sqs148142 	uint64_t		opackets;
856349Sqs148142 	uint64_t		obytes;
866349Sqs148142 	uint64_t		obytes_with_pad;
876349Sqs148142 	uint64_t		oerrors;
886349Sqs148142 
896349Sqs148142 	uint32_t		tx_inits;
906349Sqs148142 	uint32_t		tx_no_buf;
916349Sqs148142 
926349Sqs148142 	uint32_t		peu_resp_err;
936349Sqs148142 	uint32_t		pkt_size_hdr_err;
946349Sqs148142 	uint32_t		runt_pkt_drop_err;
956349Sqs148142 	uint32_t		pkt_size_err;
966349Sqs148142 	uint32_t		tx_rng_oflow;
976349Sqs148142 	uint32_t		pref_par_err;
986349Sqs148142 	uint32_t		tdr_pref_cpl_to;
996349Sqs148142 	uint32_t		pkt_cpl_to;
1006349Sqs148142 	uint32_t		invalid_sop;
1016349Sqs148142 	uint32_t		unexpected_sop;
1026349Sqs148142 
1036349Sqs148142 	uint64_t		count_hdr_size_err;
1046349Sqs148142 	uint64_t		count_runt;
1056349Sqs148142 	uint64_t		count_abort;
1066349Sqs148142 
1076349Sqs148142 	uint32_t		tx_starts;
1086349Sqs148142 	uint32_t		tx_no_desc;
1096349Sqs148142 	uint32_t		tx_dma_bind_fail;
1106349Sqs148142 	uint32_t		tx_hdr_pkts;
1116349Sqs148142 	uint32_t		tx_ddi_pkts;
1126349Sqs148142 	uint32_t		tx_jumbo_pkts;
1136349Sqs148142 	uint32_t		tx_max_pend;
1146349Sqs148142 	uint32_t		tx_marks;
1156349Sqs148142 	tdc_pref_par_log_t	errlog;
1166349Sqs148142 } hxge_tx_ring_stats_t, *p_hxge_tx_ring_stats_t;
1176349Sqs148142 
1186349Sqs148142 typedef struct _hxge_tdc_sys_stats {
1196349Sqs148142 	uint32_t	reord_tbl_par_err;
1206349Sqs148142 	uint32_t	reord_buf_ded_err;
1216349Sqs148142 	uint32_t	reord_buf_sec_err;
1226349Sqs148142 } hxge_tdc_sys_stats_t, *p_hxge_tdc_sys_stats_t;
1236349Sqs148142 
1246349Sqs148142 typedef struct _tx_ring_t {
1256349Sqs148142 	hxge_os_dma_common_t	tdc_desc;
1266349Sqs148142 	struct _hxge_t		*hxgep;
127*8718SMichael.Speer@Sun.COM 	mac_ring_handle_t	ring_handle;
128*8718SMichael.Speer@Sun.COM 	ddi_taskq_t		*taskq;
1296349Sqs148142 	p_tx_msg_t		tx_msg_ring;
1306349Sqs148142 	uint32_t		tnblocks;
1316349Sqs148142 	tdc_tdr_cfg_t		tx_ring_cfig;
1326349Sqs148142 	tdc_tdr_kick_t		tx_ring_kick;
1336349Sqs148142 	tdc_tdr_cfg_t		tx_cs;
1346349Sqs148142 	tdc_int_mask_t		tx_evmask;
1356349Sqs148142 	tdc_mbh_t		tx_mbox_mbh;
1366349Sqs148142 	tdc_mbl_t		tx_mbox_mbl;
1376349Sqs148142 
1386349Sqs148142 	tdc_page_handle_t	page_hdl;
1396349Sqs148142 
1406349Sqs148142 	hxge_os_mutex_t		lock;
1416349Sqs148142 	uint16_t		index;
1426349Sqs148142 	uint16_t		tdc;
1436349Sqs148142 	struct hxge_tdc_cfg	*tdc_p;
1446349Sqs148142 	uint_t			tx_ring_size;
1456349Sqs148142 	uint32_t		num_chunks;
1466349Sqs148142 
1476349Sqs148142 	uint_t			tx_wrap_mask;
1486349Sqs148142 	uint_t			rd_index;
1496349Sqs148142 	uint_t			wr_index;
1506349Sqs148142 	boolean_t		wr_index_wrap;
1516349Sqs148142 	uint_t			head_index;
1526349Sqs148142 	boolean_t		head_wrap;
1536349Sqs148142 	tdc_tdr_head_t		ring_head;
1546349Sqs148142 	tdc_tdr_kick_t		ring_kick_tail;
1556349Sqs148142 	txdma_mailbox_t		tx_mbox;
1566349Sqs148142 
1576349Sqs148142 	uint_t			descs_pending;
1586349Sqs148142 	boolean_t		queueing;
1596349Sqs148142 
1606349Sqs148142 	p_mblk_t		head;
1616349Sqs148142 	p_mblk_t		tail;
1626349Sqs148142 
1636349Sqs148142 	p_hxge_tx_ring_stats_t	tdc_stats;
1646349Sqs148142 
1656349Sqs148142 	uint_t			dvma_wr_index;
1666349Sqs148142 	uint_t			dvma_rd_index;
1676349Sqs148142 	uint_t			dvma_pending;
1686349Sqs148142 	uint_t			dvma_available;
1696349Sqs148142 	uint_t			dvma_wrap_mask;
1706349Sqs148142 
1716349Sqs148142 	hxge_os_dma_handle_t	*dvma_ring;
1726349Sqs148142 
1736349Sqs148142 	mac_resource_handle_t	tx_mac_resource_handle;
1746349Sqs148142 } tx_ring_t, *p_tx_ring_t;
1756349Sqs148142 
1766349Sqs148142 
1776349Sqs148142 /* Transmit Mailbox */
1786349Sqs148142 typedef struct _tx_mbox_t {
1796349Sqs148142 	hxge_os_mutex_t		lock;
1806349Sqs148142 	uint16_t		index;
1816349Sqs148142 	struct _hxge_t		*hxgep;
1826349Sqs148142 	uint16_t		tdc;
1836349Sqs148142 	hxge_os_dma_common_t	tx_mbox;
1846349Sqs148142 	tdc_mbl_t		tx_mbox_l;
1856349Sqs148142 	tdc_mbh_t		tx_mbox_h;
1866349Sqs148142 } tx_mbox_t, *p_tx_mbox_t;
1876349Sqs148142 
1886349Sqs148142 typedef struct _tx_rings_t {
1896349Sqs148142 	p_tx_ring_t		*rings;
1906349Sqs148142 	boolean_t		txdesc_allocated;
1916349Sqs148142 	uint32_t		ndmas;
1926349Sqs148142 	hxge_os_dma_common_t	tdc_dma;
1936349Sqs148142 	hxge_os_dma_common_t	tdc_mbox;
1946349Sqs148142 } tx_rings_t, *p_tx_rings_t;
1956349Sqs148142 
1966349Sqs148142 typedef struct _tx_mbox_areas_t {
1976349Sqs148142 	p_tx_mbox_t		*txmbox_areas_p;
1986349Sqs148142 	boolean_t		txmbox_allocated;
1996349Sqs148142 } tx_mbox_areas_t, *p_tx_mbox_areas_t;
2006349Sqs148142 
2016349Sqs148142 /*
2026349Sqs148142  * Transmit prototypes.
2036349Sqs148142  */
2046349Sqs148142 hxge_status_t hxge_init_txdma_channels(p_hxge_t hxgep);
2056349Sqs148142 void hxge_uninit_txdma_channels(p_hxge_t hxgep);
2066349Sqs148142 void hxge_setup_dma_common(p_hxge_dma_common_t, p_hxge_dma_common_t,
2076349Sqs148142 	uint32_t, uint32_t);
2086349Sqs148142 hxge_status_t hxge_reset_txdma_channel(p_hxge_t hxgep, uint16_t channel,
2096349Sqs148142 	uint64_t reg_data);
2106349Sqs148142 hxge_status_t hxge_init_txdma_channel_event_mask(p_hxge_t hxgep,
2116349Sqs148142 	uint16_t channel, tdc_int_mask_t *mask_p);
2126349Sqs148142 hxge_status_t hxge_enable_txdma_channel(p_hxge_t hxgep, uint16_t channel,
2136349Sqs148142 	p_tx_ring_t tx_desc_p, p_tx_mbox_t mbox_p);
2146349Sqs148142 
2156349Sqs148142 p_mblk_t hxge_tx_pkt_header_reserve(p_mblk_t mp, uint8_t *npads);
2166349Sqs148142 	int hxge_tx_pkt_nmblocks(p_mblk_t mp, int *tot_xfer_len_p);
2176349Sqs148142 boolean_t hxge_txdma_reclaim(p_hxge_t hxgep,
2186349Sqs148142 	p_tx_ring_t tx_ring_p, int nmblks);
2196349Sqs148142 
2206349Sqs148142 void hxge_fill_tx_hdr(p_mblk_t mp, boolean_t fill_len, boolean_t l4_cksum,
2216349Sqs148142 	int pkt_len, uint8_t npads, p_tx_pkt_hdr_all_t pkthdrp);
2226349Sqs148142 
2236349Sqs148142 hxge_status_t hxge_txdma_hw_mode(p_hxge_t hxgep, boolean_t enable);
2246349Sqs148142 void hxge_txdma_stop(p_hxge_t hxgep);
2256349Sqs148142 void hxge_fixup_txdma_rings(p_hxge_t hxgep);
2266349Sqs148142 void hxge_txdma_hw_kick(p_hxge_t hxgep);
2276349Sqs148142 void hxge_txdma_fix_channel(p_hxge_t hxgep, uint16_t channel);
2286349Sqs148142 void hxge_txdma_fixup_channel(p_hxge_t hxgep, p_tx_ring_t ring_p,
2296349Sqs148142 	uint16_t channel);
2306349Sqs148142 void hxge_txdma_hw_kick_channel(p_hxge_t hxgep, p_tx_ring_t ring_p,
2316349Sqs148142 	uint16_t channel);
2326349Sqs148142 
2336349Sqs148142 void hxge_check_tx_hang(p_hxge_t hxgep);
2346349Sqs148142 void hxge_fixup_hung_txdma_rings(p_hxge_t hxgep);
2356349Sqs148142 void hxge_txdma_fix_hung_channel(p_hxge_t hxgep, uint16_t channel);
2366349Sqs148142 void hxge_txdma_fixup_hung_channel(p_hxge_t hxgep, p_tx_ring_t ring_p,
2376349Sqs148142 	uint16_t channel);
2386349Sqs148142 
239*8718SMichael.Speer@Sun.COM mblk_t *hxge_tx_ring_send(void *arg, mblk_t *mp);
2406349Sqs148142 void hxge_reclaim_rings(p_hxge_t hxgep);
2416349Sqs148142 int hxge_txdma_channel_hung(p_hxge_t hxgep,
2426349Sqs148142 	p_tx_ring_t tx_ring_p, uint16_t channel);
2436349Sqs148142 int hxge_txdma_hung(p_hxge_t hxgep);
2446349Sqs148142 int hxge_txdma_stop_inj_err(p_hxge_t hxgep, int channel);
2456349Sqs148142 hxge_status_t hxge_txdma_handle_sys_errors(p_hxge_t hxgep);
2466349Sqs148142 
2476349Sqs148142 #ifdef	__cplusplus
2486349Sqs148142 }
2496349Sqs148142 #endif
2506349Sqs148142 
2516349Sqs148142 #endif /* _SYS_HXGE_HXGE_TXDMA_H */
252