162306a36Sopenharmony_ci/* version dependencies have been confined to a separate file */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/* Tunable parameters */
462306a36Sopenharmony_ci#define TX_RING_ENTRIES 64	/* 64-512?*/
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#define RX_RING_ENTRIES 16 /* Do not change */
762306a36Sopenharmony_ci/* Internal constants */
862306a36Sopenharmony_ci#define TX_RING_BUFFER_SIZE	(TX_RING_ENTRIES*sizeof(tx_packet))
962306a36Sopenharmony_ci#define RX_BUFFER_SIZE 1546 /* ethenet packet size */
1062306a36Sopenharmony_ci#define METH_RX_BUFF_SIZE 4096
1162306a36Sopenharmony_ci#define METH_RX_HEAD 34 /* status + 3 quad garbage-fill + 2 byte zero-pad */
1262306a36Sopenharmony_ci#define RX_BUFFER_OFFSET (sizeof(rx_status_vector)+2) /* staus vector + 2 bytes of padding */
1362306a36Sopenharmony_ci#define RX_BUCKET_SIZE 256
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/* For more detailed explanations of what each field menas,
1662306a36Sopenharmony_ci   see Nick's great comments to #defines below (or docs, if
1762306a36Sopenharmony_ci   you are lucky enough toget hold of them :)*/
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* tx status vector is written over tx command header upon
2062306a36Sopenharmony_ci   dma completion. */
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_citypedef struct tx_status_vector {
2362306a36Sopenharmony_ci	u64		sent:1; /* always set to 1...*/
2462306a36Sopenharmony_ci	u64		pad0:34;/* always set to 0 */
2562306a36Sopenharmony_ci	u64		flags:9;			/*I'm too lazy to specify each one separately at the moment*/
2662306a36Sopenharmony_ci	u64		col_retry_cnt:4;	/*collision retry count*/
2762306a36Sopenharmony_ci	u64		len:16;				/*Transmit length in bytes*/
2862306a36Sopenharmony_ci} tx_status_vector;
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_ci/*
3162306a36Sopenharmony_ci * Each packet is 128 bytes long.
3262306a36Sopenharmony_ci * It consists of header, 0-3 concatination
3362306a36Sopenharmony_ci * buffer pointers and up to 120 data bytes.
3462306a36Sopenharmony_ci */
3562306a36Sopenharmony_citypedef struct tx_packet_hdr {
3662306a36Sopenharmony_ci	u64		pad1:36; /*should be filled with 0 */
3762306a36Sopenharmony_ci	u64		cat_ptr3_valid:1,	/*Concatination pointer valid flags*/
3862306a36Sopenharmony_ci			cat_ptr2_valid:1,
3962306a36Sopenharmony_ci			cat_ptr1_valid:1;
4062306a36Sopenharmony_ci	u64		tx_int_flag:1;		/*Generate TX intrrupt when packet has been sent*/
4162306a36Sopenharmony_ci	u64		term_dma_flag:1;	/*Terminate transmit DMA on transmit abort conditions*/
4262306a36Sopenharmony_ci	u64		data_offset:7;		/*Starting byte offset in ring data block*/
4362306a36Sopenharmony_ci	u64		data_len:16;		/*Length of valid data in bytes-1*/
4462306a36Sopenharmony_ci} tx_packet_hdr;
4562306a36Sopenharmony_citypedef union tx_cat_ptr {
4662306a36Sopenharmony_ci	struct {
4762306a36Sopenharmony_ci		u64		pad2:16; /* should be 0 */
4862306a36Sopenharmony_ci		u64		len:16;				/*length of buffer data - 1*/
4962306a36Sopenharmony_ci		u64		start_addr:29;		/*Physical starting address*/
5062306a36Sopenharmony_ci		u64		pad1:3; /* should be zero */
5162306a36Sopenharmony_ci	} form;
5262306a36Sopenharmony_ci	u64 raw;
5362306a36Sopenharmony_ci} tx_cat_ptr;
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_citypedef struct tx_packet {
5662306a36Sopenharmony_ci	union {
5762306a36Sopenharmony_ci		tx_packet_hdr header;
5862306a36Sopenharmony_ci		tx_status_vector res;
5962306a36Sopenharmony_ci		u64 raw;
6062306a36Sopenharmony_ci	}header;
6162306a36Sopenharmony_ci	union {
6262306a36Sopenharmony_ci		tx_cat_ptr cat_buf[3];
6362306a36Sopenharmony_ci		char dt[120];
6462306a36Sopenharmony_ci	} data;
6562306a36Sopenharmony_ci} tx_packet;
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_citypedef union rx_status_vector {
6862306a36Sopenharmony_ci	volatile struct {
6962306a36Sopenharmony_ci		u64		pad1:1;/*fill it with ones*/
7062306a36Sopenharmony_ci		u64		pad2:15;/*fill with 0*/
7162306a36Sopenharmony_ci		u64		ip_chk_sum:16;
7262306a36Sopenharmony_ci		u64		seq_num:5;
7362306a36Sopenharmony_ci		u64		mac_addr_match:1;
7462306a36Sopenharmony_ci		u64		mcast_addr_match:1;
7562306a36Sopenharmony_ci		u64		carrier_event_seen:1;
7662306a36Sopenharmony_ci		u64		bad_packet:1;
7762306a36Sopenharmony_ci		u64		long_event_seen:1;
7862306a36Sopenharmony_ci		u64		invalid_preamble:1;
7962306a36Sopenharmony_ci		u64		broadcast:1;
8062306a36Sopenharmony_ci		u64		multicast:1;
8162306a36Sopenharmony_ci		u64		crc_error:1;
8262306a36Sopenharmony_ci		u64		huh:1;/*???*/
8362306a36Sopenharmony_ci		u64		rx_code_violation:1;
8462306a36Sopenharmony_ci		u64		rx_len:16;
8562306a36Sopenharmony_ci	} parsed;
8662306a36Sopenharmony_ci	volatile u64 raw;
8762306a36Sopenharmony_ci} rx_status_vector;
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_citypedef struct rx_packet {
9062306a36Sopenharmony_ci	rx_status_vector status;
9162306a36Sopenharmony_ci        u64 pad[3]; /* For whatever reason, there needs to be 4 double-word offset */
9262306a36Sopenharmony_ci        u16 pad2;
9362306a36Sopenharmony_ci	char buf[METH_RX_BUFF_SIZE-sizeof(rx_status_vector)-3*sizeof(u64)-sizeof(u16)];/* data */
9462306a36Sopenharmony_ci} rx_packet;
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define TX_INFO_RPTR    0x00FF0000
9762306a36Sopenharmony_ci#define TX_INFO_WPTR    0x000000FF
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	/* Bits in METH_MAC */
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define SGI_MAC_RESET		BIT(0)	/* 0: MAC110 active in run mode, 1: Global reset signal to MAC110 core is active */
10262306a36Sopenharmony_ci#define METH_PHY_FDX		BIT(1) /* 0: Disable full duplex, 1: Enable full duplex */
10362306a36Sopenharmony_ci#define METH_PHY_LOOP	BIT(2) /* 0: Normal operation, follows 10/100mbit and M10T/MII select, 1: loops internal MII bus */
10462306a36Sopenharmony_ci				       /*    selects ignored */
10562306a36Sopenharmony_ci#define METH_100MBIT		BIT(3) /* 0: 10meg mode, 1: 100meg mode */
10662306a36Sopenharmony_ci#define METH_PHY_MII		BIT(4) /* 0: MII selected, 1: SIA selected */
10762306a36Sopenharmony_ci				       /*   Note: when loopback is set this bit becomes collision control.  Setting this bit will */
10862306a36Sopenharmony_ci				       /*         cause a collision to be reported. */
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci				       /* Bits 5 and 6 are used to determine the Destination address filter mode */
11162306a36Sopenharmony_ci#define METH_ACCEPT_MY 0			/* 00: Accept PHY address only */
11262306a36Sopenharmony_ci#define METH_ACCEPT_MCAST 0x20	/* 01: Accept physical, broadcast, and multicast filter matches only */
11362306a36Sopenharmony_ci#define METH_ACCEPT_AMCAST 0x40	/* 10: Accept physical, broadcast, and all multicast packets */
11462306a36Sopenharmony_ci#define METH_PROMISC 0x60		/* 11: Promiscious mode */
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci#define METH_PHY_LINK_FAIL	BIT(7) /* 0: Link failure detection disabled, 1: Hardware scans for link failure in PHY */
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci#define METH_MAC_IPG	0x1ffff00
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define METH_DEFAULT_IPG ((17<<15) | (11<<22) | (21<<8))
12162306a36Sopenharmony_ci						/* 0x172e5c00 */ /* 23, 23, 23 */ /*0x54A9500 *//*21,21,21*/
12262306a36Sopenharmony_ci				       /* Bits 8 through 14 are used to determine Inter-Packet Gap between "Back to Back" packets */
12362306a36Sopenharmony_ci				       /* The gap depends on the clock speed of the link, 80ns per increment for 100baseT, 800ns  */
12462306a36Sopenharmony_ci				       /* per increment for 10BaseT */
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci				       /* Bits 15 through 21 are used to determine IPGR1 */
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci				       /* Bits 22 through 28 are used to determine IPGR2 */
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define METH_REV_SHIFT 29       /* Bits 29 through 31 are used to determine the revision */
13162306a36Sopenharmony_ci				       /* 000: Initial revision */
13262306a36Sopenharmony_ci				       /* 001: First revision, Improved TX concatenation */
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci/* DMA control bits */
13662306a36Sopenharmony_ci#define METH_RX_OFFSET_SHIFT 12 /* Bits 12:14 of DMA control register indicate starting offset of packet data for RX operation */
13762306a36Sopenharmony_ci#define METH_RX_DEPTH_SHIFT 4 /* Bits 8:4 define RX fifo depth -- when # of RX fifo entries != depth, interrupt is generted */
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci#define METH_DMA_TX_EN BIT(1) /* enable TX DMA */
14062306a36Sopenharmony_ci#define METH_DMA_TX_INT_EN BIT(0) /* enable TX Buffer Empty interrupt */
14162306a36Sopenharmony_ci#define METH_DMA_RX_EN BIT(15) /* Enable RX */
14262306a36Sopenharmony_ci#define METH_DMA_RX_INT_EN BIT(9) /* Enable interrupt on RX packet */
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* RX FIFO MCL Info bits */
14562306a36Sopenharmony_ci#define METH_RX_FIFO_WPTR(x)   (((x)>>16)&0xf)
14662306a36Sopenharmony_ci#define METH_RX_FIFO_RPTR(x)   (((x)>>8)&0xf)
14762306a36Sopenharmony_ci#define METH_RX_FIFO_DEPTH(x)  ((x)&0x1f)
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci/* RX status bits */
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ci#define METH_RX_ST_VALID BIT(63)
15262306a36Sopenharmony_ci#define METH_RX_ST_RCV_CODE_VIOLATION BIT(16)
15362306a36Sopenharmony_ci#define METH_RX_ST_DRBL_NBL BIT(17)
15462306a36Sopenharmony_ci#define METH_RX_ST_CRC_ERR BIT(18)
15562306a36Sopenharmony_ci#define METH_RX_ST_MCAST_PKT BIT(19)
15662306a36Sopenharmony_ci#define METH_RX_ST_BCAST_PKT BIT(20)
15762306a36Sopenharmony_ci#define METH_RX_ST_INV_PREAMBLE_CTX BIT(21)
15862306a36Sopenharmony_ci#define METH_RX_ST_LONG_EVT_SEEN BIT(22)
15962306a36Sopenharmony_ci#define METH_RX_ST_BAD_PACKET BIT(23)
16062306a36Sopenharmony_ci#define METH_RX_ST_CARRIER_EVT_SEEN BIT(24)
16162306a36Sopenharmony_ci#define METH_RX_ST_MCAST_FILTER_MATCH BIT(25)
16262306a36Sopenharmony_ci#define METH_RX_ST_PHYS_ADDR_MATCH BIT(26)
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci#define METH_RX_STATUS_ERRORS \
16562306a36Sopenharmony_ci	( \
16662306a36Sopenharmony_ci	METH_RX_ST_RCV_CODE_VIOLATION| \
16762306a36Sopenharmony_ci	METH_RX_ST_CRC_ERR| \
16862306a36Sopenharmony_ci	METH_RX_ST_INV_PREAMBLE_CTX| \
16962306a36Sopenharmony_ci	METH_RX_ST_LONG_EVT_SEEN| \
17062306a36Sopenharmony_ci	METH_RX_ST_BAD_PACKET| \
17162306a36Sopenharmony_ci	METH_RX_ST_CARRIER_EVT_SEEN \
17262306a36Sopenharmony_ci	)
17362306a36Sopenharmony_ci	/* Bits in METH_INT */
17462306a36Sopenharmony_ci	/* Write _1_ to corresponding bit to clear */
17562306a36Sopenharmony_ci#define METH_INT_TX_EMPTY	BIT(0)	/* 0: No interrupt pending, 1: The TX ring buffer is empty */
17662306a36Sopenharmony_ci#define METH_INT_TX_PKT		BIT(1)	/* 0: No interrupt pending */
17762306a36Sopenharmony_ci					      	/* 1: A TX message had the INT request bit set, the packet has been sent. */
17862306a36Sopenharmony_ci#define METH_INT_TX_LINK_FAIL	BIT(2)	/* 0: No interrupt pending, 1: PHY has reported a link failure */
17962306a36Sopenharmony_ci#define METH_INT_MEM_ERROR	BIT(3)	/* 0: No interrupt pending */
18062306a36Sopenharmony_ci						/* 1: A memory error occurred during DMA, DMA stopped, Fatal */
18162306a36Sopenharmony_ci#define METH_INT_TX_ABORT		BIT(4)	/* 0: No interrupt pending, 1: The TX aborted operation, DMA stopped, FATAL */
18262306a36Sopenharmony_ci#define METH_INT_RX_THRESHOLD	BIT(5)	/* 0: No interrupt pending, 1: Selected receive threshold condition Valid */
18362306a36Sopenharmony_ci#define METH_INT_RX_UNDERFLOW	BIT(6)	/* 0: No interrupt pending, 1: FIFO was empty, packet could not be queued */
18462306a36Sopenharmony_ci#define METH_INT_RX_OVERFLOW		BIT(7)	/* 0: No interrupt pending, 1: DMA FIFO Overflow, DMA stopped, FATAL */
18562306a36Sopenharmony_ci
18662306a36Sopenharmony_ci/*#define METH_INT_RX_RPTR_MASK 0x0001F00*/		/* Bits 8 through 12 alias of RX read-pointer */
18762306a36Sopenharmony_ci#define METH_INT_RX_RPTR_MASK 0x0000F00		/* Bits 8 through 11 alias of RX read-pointer - so, is Rx FIFO 16 or 32 entry?*/
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci						/* Bits 13 through 15 are always 0. */
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci#define METH_INT_TX_RPTR_MASK	0x1FF0000        /* Bits 16 through 24 alias of TX read-pointer */
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci#define METH_INT_RX_SEQ_MASK	0x2E000000	/* Bits 25 through 29 are the starting seq number for the message at the */
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ci						/* top of the queue */
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci#define METH_INT_ERROR	(METH_INT_TX_LINK_FAIL| \
19862306a36Sopenharmony_ci			METH_INT_MEM_ERROR| \
19962306a36Sopenharmony_ci			METH_INT_TX_ABORT| \
20062306a36Sopenharmony_ci			METH_INT_RX_OVERFLOW| \
20162306a36Sopenharmony_ci			METH_INT_RX_UNDERFLOW)
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci#define METH_INT_MCAST_HASH		BIT(30) /* If RX DMA is enabled the hash select logic output is latched here */
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci/* TX status bits */
20662306a36Sopenharmony_ci#define METH_TX_ST_DONE      BIT(63) /* TX complete */
20762306a36Sopenharmony_ci#define METH_TX_ST_SUCCESS   BIT(23) /* Packet was transmitted successfully */
20862306a36Sopenharmony_ci#define METH_TX_ST_TOOLONG   BIT(24) /* TX abort due to excessive length */
20962306a36Sopenharmony_ci#define METH_TX_ST_UNDERRUN  BIT(25) /* TX abort due to underrun (?) */
21062306a36Sopenharmony_ci#define METH_TX_ST_EXCCOLL   BIT(26) /* TX abort due to excess collisions */
21162306a36Sopenharmony_ci#define METH_TX_ST_DEFER     BIT(27) /* TX abort due to excess deferals */
21262306a36Sopenharmony_ci#define METH_TX_ST_LATECOLL  BIT(28) /* TX abort due to late collision */
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci
21562306a36Sopenharmony_ci/* Tx command header bits */
21662306a36Sopenharmony_ci#define METH_TX_CMD_INT_EN BIT(24) /* Generate TX interrupt when packet is sent */
21762306a36Sopenharmony_ci
21862306a36Sopenharmony_ci/* Phy MDIO interface busy flag */
21962306a36Sopenharmony_ci#define MDIO_BUSY    BIT(16)
22062306a36Sopenharmony_ci#define MDIO_DATA_MASK 0xFFFF
22162306a36Sopenharmony_ci/* PHY defines */
22262306a36Sopenharmony_ci#define PHY_QS6612X    0x0181441    /* Quality TX */
22362306a36Sopenharmony_ci#define PHY_ICS1889    0x0015F41    /* ICS FX */
22462306a36Sopenharmony_ci#define PHY_ICS1890    0x0015F42    /* ICS TX */
22562306a36Sopenharmony_ci#define PHY_DP83840    0x20005C0    /* National TX */
22662306a36Sopenharmony_ci
22762306a36Sopenharmony_ci#define ADVANCE_RX_PTR(x)  x=(x+1)&(RX_RING_ENTRIES-1)
228