xref: /illumos-gate/usr/src/uts/common/io/hxge/hpi_rxdma.h (revision 069fd767)
13dec9fcdSqs /*
23dec9fcdSqs  * CDDL HEADER START
33dec9fcdSqs  *
43dec9fcdSqs  * The contents of this file are subject to the terms of the
53dec9fcdSqs  * Common Development and Distribution License (the "License").
63dec9fcdSqs  * You may not use this file except in compliance with the License.
73dec9fcdSqs  *
83dec9fcdSqs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93dec9fcdSqs  * or http://www.opensolaris.org/os/licensing.
103dec9fcdSqs  * See the License for the specific language governing permissions
113dec9fcdSqs  * and limitations under the License.
123dec9fcdSqs  *
133dec9fcdSqs  * When distributing Covered Code, include this CDDL HEADER in each
143dec9fcdSqs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153dec9fcdSqs  * If applicable, add the following below this CDDL HEADER, with the
163dec9fcdSqs  * fields enclosed by brackets "[]" replaced with your own identifying
173dec9fcdSqs  * information: Portions Copyright [yyyy] [name of copyright owner]
183dec9fcdSqs  *
193dec9fcdSqs  * CDDL HEADER END
203dec9fcdSqs  */
213dec9fcdSqs /*
223dec9fcdSqs  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233dec9fcdSqs  * Use is subject to license terms.
243dec9fcdSqs  */
253dec9fcdSqs 
263dec9fcdSqs #ifndef _HPI_RXDMA_H
273dec9fcdSqs #define	_HPI_RXDMA_H
283dec9fcdSqs 
293dec9fcdSqs #ifdef	__cplusplus
303dec9fcdSqs extern "C" {
313dec9fcdSqs #endif
323dec9fcdSqs 
333dec9fcdSqs #include <hpi.h>
343dec9fcdSqs #include <hxge_defs.h>
353dec9fcdSqs #include <hxge_pfc.h>
363dec9fcdSqs #include <hxge_pfc_hw.h>
373dec9fcdSqs #include <hxge_rdc_hw.h>
383dec9fcdSqs 
393dec9fcdSqs #define	RXDMA_CFIG2_MBADDR_L_SHIFT	6	/* bit 31:6 */
403dec9fcdSqs #define	RXDMA_CFIG2_MBADDR_L_MASK	0x00000000ffffffc0ULL
413dec9fcdSqs 
423dec9fcdSqs #define	RBR_CFIG_A_STDADDR_MASK		0x000000000003ffc0ULL
433dec9fcdSqs #define	RBR_CFIG_A_STDADDR_BASE_MASK    0x00000ffffffc0000ULL
443dec9fcdSqs 
453dec9fcdSqs #define	RCRCFIG_A_STADDR_SHIFT		6	/* bit 18:6 */
463dec9fcdSqs #define	RCRCFIG_A_STADDR_MASK		0x000000000007FFC0ULL
473dec9fcdSqs #define	RCRCFIG_A_STADDR_BASE_SHIF	19	/* bit 43:19 */
483dec9fcdSqs #define	RCRCFIG_A_STADDR_BASE_MASK	0x00000FFFFFF80000ULL
493dec9fcdSqs #define	RCRCFIG_A_LEN_SHIF		48	/* bit 63:48 */
503dec9fcdSqs #define	RCRCFIG_A_LEN_MASK		0xFFFF000000000000ULL
513dec9fcdSqs 
523dec9fcdSqs #define	RCR_FLSH_SHIFT			0	/* RW, bit 0:0 */
533dec9fcdSqs #define	RCR_FLSH_SET			0x0000000000000001ULL
543dec9fcdSqs #define	RCR_FLSH_MASK			0x0000000000000001ULL
553dec9fcdSqs 
563dec9fcdSqs #define	RBR_CFIG_A_LEN_SHIFT		48	/* bits 63:48 */
573dec9fcdSqs #define	RBR_CFIG_A_LEN_MASK		0xFFFF000000000000ULL
583dec9fcdSqs 
593dec9fcdSqs /*
603dec9fcdSqs  * Buffer block descriptor
613dec9fcdSqs  */
623dec9fcdSqs typedef struct _rx_desc_t {
633dec9fcdSqs 	uint32_t	block_addr;
643dec9fcdSqs } rx_desc_t, *p_rx_desc_t;
653dec9fcdSqs 
663dec9fcdSqs typedef enum _bsize {
673dec9fcdSqs 	SIZE_0B = 0x0,
683dec9fcdSqs 	SIZE_64B,
693dec9fcdSqs 	SIZE_128B,
703dec9fcdSqs 	SIZE_192B,
713dec9fcdSqs 	SIZE_256B,
723dec9fcdSqs 	SIZE_512B,
733dec9fcdSqs 	SIZE_1KB,
743dec9fcdSqs 	SIZE_2KB,
753dec9fcdSqs 	SIZE_4KB,
763dec9fcdSqs 	SIZE_8KB,
773dec9fcdSqs 	SIZE_16KB,
783dec9fcdSqs 	SIZE_32KB
793dec9fcdSqs } bsize_t;
803dec9fcdSqs 
813dec9fcdSqs typedef struct _rdc_desc_cfg_t {
823dec9fcdSqs 	uint8_t mbox_enable;		/* Enable full (18b) header */
833dec9fcdSqs 	uint8_t full_hdr;		/* Enable full (18b) header */
843dec9fcdSqs 	uint8_t offset;			/* 64 byte offsets */
853dec9fcdSqs 	uint8_t valid2;			/* size 2 is valid */
863dec9fcdSqs 	bsize_t size2;			/* Size 2 length */
873dec9fcdSqs 	uint8_t valid1;			/* size 1 is valid */
883dec9fcdSqs 	bsize_t size1;			/* Size 1 length */
893dec9fcdSqs 	uint8_t valid0;			/* size 0 is valid */
903dec9fcdSqs 	bsize_t size0;			/* Size 1 length */
913dec9fcdSqs 	bsize_t page_size;		/* Page or buffer Size */
923dec9fcdSqs 	uint8_t	rcr_timeout_enable;
933dec9fcdSqs 	uint8_t	rcr_timeout;
943dec9fcdSqs 	uint16_t rcr_threshold;
953dec9fcdSqs 	uint16_t rcr_len;		/* RBR Descriptor size (entries) */
963dec9fcdSqs 	uint16_t rbr_len;		/* RBR Descriptor size (entries) */
973dec9fcdSqs 	uint64_t mbox_addr;		/* Mailbox Address */
983dec9fcdSqs 	uint64_t rcr_addr;		/* RCR Address */
993dec9fcdSqs 	uint64_t rbr_addr;		/* RBB Address */
1003dec9fcdSqs } rdc_desc_cfg_t;
1013dec9fcdSqs 
1023dec9fcdSqs 
1033dec9fcdSqs /*
1043dec9fcdSqs  * Register offset (0x800 bytes for each channel) for receive ring registers.
1053dec9fcdSqs  */
1063dec9fcdSqs #define	HXGE_RXDMA_OFFSET(x, v, channel) (x + \
1073dec9fcdSqs 		(!v ? DMC_OFFSET(channel) : \
1083dec9fcdSqs 		    RDMC_PIOVADDR_OFFSET(channel)))
1093dec9fcdSqs 
1103dec9fcdSqs #define	RXDMA_REG_READ64(handle, reg, channel, data_p) {\
1113dec9fcdSqs 	HXGE_REG_RD64(handle, (HXGE_RXDMA_OFFSET(reg, handle.is_vraddr,\
1123dec9fcdSqs 		channel)), (data_p))\
1133dec9fcdSqs }
1143dec9fcdSqs 
115fe930412Sqs #define	RXDMA_REG_READ32(handle, reg, channel, data_p) \
116fe930412Sqs 	HXGE_REG_RD32(handle, (HXGE_RXDMA_OFFSET(reg, handle.is_vraddr,\
117fe930412Sqs 		channel)), (data_p))
1183dec9fcdSqs 
1193dec9fcdSqs #define	RXDMA_REG_WRITE64(handle, reg, channel, data) {\
1203dec9fcdSqs 	HXGE_REG_WR64(handle, (HXGE_RXDMA_OFFSET(reg, handle.is_vraddr,\
1213dec9fcdSqs 		channel)), (data))\
1223dec9fcdSqs }
1233dec9fcdSqs 
1243dec9fcdSqs /*
1253dec9fcdSqs  * RX HPI error codes
1263dec9fcdSqs  */
1273dec9fcdSqs #define	RXDMA_ER_ST			(RXDMA_BLK_ID << HPI_BLOCK_ID_SHIFT)
1283dec9fcdSqs #define	RXDMA_ID_SHIFT(n)		(n << HPI_PORT_CHAN_SHIFT)
1293dec9fcdSqs 
1303dec9fcdSqs #define	HPI_RXDMA_ERROR			RXDMA_ER_ST
1313dec9fcdSqs 
1323dec9fcdSqs #define	HPI_RXDMA_SW_PARAM_ERROR	(HPI_RXDMA_ERROR | 0x40)
1333dec9fcdSqs #define	HPI_RXDMA_HW_ERROR		(HPI_RXDMA_ERROR | 0x80)
1343dec9fcdSqs 
1353dec9fcdSqs #define	HPI_RXDMA_RDC_INVALID		(HPI_RXDMA_ERROR | CHANNEL_INVALID)
1363dec9fcdSqs #define	HPI_RXDMA_RESET_ERR		(HPI_RXDMA_HW_ERROR | RESET_FAILED)
1373dec9fcdSqs #define	HPI_RXDMA_BUFSZIE_INVALID	(HPI_RXDMA_SW_PARAM_ERROR | 0x0000b)
1383dec9fcdSqs #define	HPI_RXDMA_RBRSZIE_INVALID	(HPI_RXDMA_SW_PARAM_ERROR | 0x0000c)
1393dec9fcdSqs #define	HPI_RXDMA_RCRSZIE_INVALID	(HPI_RXDMA_SW_PARAM_ERROR | 0x0000d)
1403dec9fcdSqs 
1413dec9fcdSqs #define	HPI_RXDMA_CHANNEL_INVALID(n)	(RXDMA_ID_SHIFT(n) |	\
1423dec9fcdSqs 					HPI_RXDMA_ERROR | CHANNEL_INVALID)
1433dec9fcdSqs #define	HPI_RXDMA_OPCODE_INVALID(n)	(RXDMA_ID_SHIFT(n) |	\
1443dec9fcdSqs 					HPI_RXDMA_ERROR | OPCODE_INVALID)
1453dec9fcdSqs 
1463dec9fcdSqs #define	HPI_RXDMA_ERROR_ENCODE(err, rdc)	\
1473dec9fcdSqs 	(RXDMA_ID_SHIFT(rdc) | RXDMA_ER_ST | err)
1483dec9fcdSqs 
1493dec9fcdSqs #define	RXDMA_CHANNEL_VALID(rdc) \
1503dec9fcdSqs 	((rdc < HXGE_MAX_RDCS))
1513dec9fcdSqs 
1523dec9fcdSqs #define	RXDMA_BUFF_OFFSET_VALID(offset) \
1533dec9fcdSqs 	((offset == SW_OFFSET_NO_OFFSET) || \
1543dec9fcdSqs 	    (offset == SW_OFFSET_64) || \
1553dec9fcdSqs 	    (offset == SW_OFFSET_128))
1563dec9fcdSqs 
1573dec9fcdSqs #define	RXDMA_RCR_TO_VALID(tov) ((tov) && (tov < 64))
158fe930412Sqs #define	RXDMA_RCR_THRESH_VALID(thresh) ((thresh <= 0x8000))
1593dec9fcdSqs 
1603dec9fcdSqs #define	hpi_rxdma_rdc_rcr_flush(handle, rdc) \
1613dec9fcdSqs 	RXDMA_REG_WRITE64(handle, RDC_RCR_FLUSH, rdc, \
1623dec9fcdSqs 		    (RCR_FLSH_SET << RCR_FLSH_SHIFT))
1633dec9fcdSqs #define	hpi_rxdma_rdc_rbr_kick(handle, rdc, num_buffers) \
1643dec9fcdSqs 	RXDMA_REG_WRITE64(handle, RDC_RBR_KICK, rdc, num_buffers)
1653dec9fcdSqs 
166*069fd767SMichael Speer hpi_status_t hpi_rxdma_cfg_rdc_wait_for_qst(hpi_handle_t handle, uint8_t rdc);
1673dec9fcdSqs hpi_status_t hpi_rxdma_cfg_rdc_ring(hpi_handle_t handle, uint8_t rdc,
1683dec9fcdSqs     rdc_desc_cfg_t *rdc_desc_params);
1693dec9fcdSqs hpi_status_t hpi_rxdma_cfg_clock_div_set(hpi_handle_t handle, uint16_t count);
1703dec9fcdSqs hpi_status_t hpi_rxdma_cfg_logical_page_handle(hpi_handle_t handle, uint8_t rdc,
1713dec9fcdSqs     uint64_t pg_handle);
1723dec9fcdSqs 
1733dec9fcdSqs hpi_status_t hpi_rxdma_rdc_rbr_stat_get(hpi_handle_t handle, uint8_t rdc,
1743dec9fcdSqs     rdc_rbr_qlen_t *rbr_stat);
1753dec9fcdSqs hpi_status_t hpi_rxdma_cfg_rdc_reset(hpi_handle_t handle, uint8_t rdc);
1763dec9fcdSqs hpi_status_t hpi_rxdma_cfg_rdc_enable(hpi_handle_t handle, uint8_t rdc);
1773dec9fcdSqs hpi_status_t hpi_rxdma_cfg_rdc_disable(hpi_handle_t handle, uint8_t rdc);
1783dec9fcdSqs hpi_status_t hpi_rxdma_cfg_rdc_rcr_timeout(hpi_handle_t handle, uint8_t rdc,
1793dec9fcdSqs     uint8_t rcr_timeout);
1803dec9fcdSqs 
1813dec9fcdSqs hpi_status_t hpi_rxdma_cfg_rdc_rcr_threshold(hpi_handle_t handle, uint8_t rdc,
1823dec9fcdSqs     uint16_t rcr_threshold);
1833dec9fcdSqs hpi_status_t hpi_rxdma_rdc_rcr_qlen_get(hpi_handle_t handle,
1843dec9fcdSqs     uint8_t rdc,  uint16_t *qlen);
1853dec9fcdSqs 
1863dec9fcdSqs hpi_status_t hpi_rxdma_ring_perr_stat_get(hpi_handle_t handle,
1873dec9fcdSqs     rdc_pref_par_log_t *pre_log, rdc_pref_par_log_t *sha_log);
1883dec9fcdSqs 
1893dec9fcdSqs hpi_status_t hpi_rxdma_control_status(hpi_handle_t handle, io_op_t op_mode,
1903dec9fcdSqs     uint8_t channel, rdc_stat_t *cs_p);
1913dec9fcdSqs hpi_status_t hpi_rxdma_event_mask(hpi_handle_t handle, io_op_t op_mode,
1923dec9fcdSqs     uint8_t channel, rdc_int_mask_t *mask_p);
1933dec9fcdSqs hpi_status_t hpi_rxdma_channel_rbr_empty_clear(hpi_handle_t handle,
1943dec9fcdSqs     uint8_t channel);
1953dec9fcdSqs 
1963dec9fcdSqs #ifdef	__cplusplus
1973dec9fcdSqs }
1983dec9fcdSqs #endif
1993dec9fcdSqs 
2003dec9fcdSqs #endif	/* _HPI_RXDMA_H */
201