162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci#ifndef _SLIC_H
462306a36Sopenharmony_ci#define _SLIC_H
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/types.h>
762306a36Sopenharmony_ci#include <linux/netdevice.h>
862306a36Sopenharmony_ci#include <linux/spinlock_types.h>
962306a36Sopenharmony_ci#include <linux/dma-mapping.h>
1062306a36Sopenharmony_ci#include <linux/pci.h>
1162306a36Sopenharmony_ci#include <linux/list.h>
1262306a36Sopenharmony_ci#include <linux/u64_stats_sync.h>
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci#define SLIC_VGBSTAT_XPERR		0x40000000
1562306a36Sopenharmony_ci#define SLIC_VGBSTAT_XERRSHFT		25
1662306a36Sopenharmony_ci#define SLIC_VGBSTAT_XCSERR		0x23
1762306a36Sopenharmony_ci#define SLIC_VGBSTAT_XUFLOW		0x22
1862306a36Sopenharmony_ci#define SLIC_VGBSTAT_XHLEN		0x20
1962306a36Sopenharmony_ci#define SLIC_VGBSTAT_NETERR		0x01000000
2062306a36Sopenharmony_ci#define SLIC_VGBSTAT_NERRSHFT		16
2162306a36Sopenharmony_ci#define SLIC_VGBSTAT_NERRMSK		0x1ff
2262306a36Sopenharmony_ci#define SLIC_VGBSTAT_NCSERR		0x103
2362306a36Sopenharmony_ci#define SLIC_VGBSTAT_NUFLOW		0x102
2462306a36Sopenharmony_ci#define SLIC_VGBSTAT_NHLEN		0x100
2562306a36Sopenharmony_ci#define SLIC_VGBSTAT_LNKERR		0x00000080
2662306a36Sopenharmony_ci#define SLIC_VGBSTAT_LERRMSK		0xff
2762306a36Sopenharmony_ci#define SLIC_VGBSTAT_LDEARLY		0x86
2862306a36Sopenharmony_ci#define SLIC_VGBSTAT_LBOFLO		0x85
2962306a36Sopenharmony_ci#define SLIC_VGBSTAT_LCODERR		0x84
3062306a36Sopenharmony_ci#define SLIC_VGBSTAT_LDBLNBL		0x83
3162306a36Sopenharmony_ci#define SLIC_VGBSTAT_LCRCERR		0x82
3262306a36Sopenharmony_ci#define SLIC_VGBSTAT_LOFLO		0x81
3362306a36Sopenharmony_ci#define SLIC_VGBSTAT_LUFLO		0x80
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define SLIC_IRHDDR_FLEN_MSK		0x0000ffff
3662306a36Sopenharmony_ci#define SLIC_IRHDDR_SVALID		0x80000000
3762306a36Sopenharmony_ci#define SLIC_IRHDDR_ERR			0x10000000
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define SLIC_VRHSTAT_802OE		0x80000000
4062306a36Sopenharmony_ci#define SLIC_VRHSTAT_TPOFLO		0x10000000
4162306a36Sopenharmony_ci#define SLIC_VRHSTATB_802UE		0x80000000
4262306a36Sopenharmony_ci#define SLIC_VRHSTATB_RCVE		0x40000000
4362306a36Sopenharmony_ci#define SLIC_VRHSTATB_BUFF		0x20000000
4462306a36Sopenharmony_ci#define SLIC_VRHSTATB_CARRE		0x08000000
4562306a36Sopenharmony_ci#define SLIC_VRHSTATB_LONGE		0x02000000
4662306a36Sopenharmony_ci#define SLIC_VRHSTATB_PREA		0x01000000
4762306a36Sopenharmony_ci#define SLIC_VRHSTATB_CRC		0x00800000
4862306a36Sopenharmony_ci#define SLIC_VRHSTATB_DRBL		0x00400000
4962306a36Sopenharmony_ci#define SLIC_VRHSTATB_CODE		0x00200000
5062306a36Sopenharmony_ci#define SLIC_VRHSTATB_TPCSUM		0x00100000
5162306a36Sopenharmony_ci#define SLIC_VRHSTATB_TPHLEN		0x00080000
5262306a36Sopenharmony_ci#define SLIC_VRHSTATB_IPCSUM		0x00040000
5362306a36Sopenharmony_ci#define SLIC_VRHSTATB_IPLERR		0x00020000
5462306a36Sopenharmony_ci#define SLIC_VRHSTATB_IPHERR		0x00010000
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci#define SLIC_CMD_XMT_REQ		0x01
5762306a36Sopenharmony_ci#define SLIC_CMD_TYPE_DUMB		3
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci#define SLIC_RESET_MAGIC		0xDEAD
6062306a36Sopenharmony_ci#define SLIC_ICR_INT_OFF		0
6162306a36Sopenharmony_ci#define SLIC_ICR_INT_ON			1
6262306a36Sopenharmony_ci#define SLIC_ICR_INT_MASK		2
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci#define SLIC_ISR_ERR			0x80000000
6562306a36Sopenharmony_ci#define SLIC_ISR_RCV			0x40000000
6662306a36Sopenharmony_ci#define SLIC_ISR_CMD			0x20000000
6762306a36Sopenharmony_ci#define SLIC_ISR_IO			0x60000000
6862306a36Sopenharmony_ci#define SLIC_ISR_UPC			0x10000000
6962306a36Sopenharmony_ci#define SLIC_ISR_LEVENT			0x08000000
7062306a36Sopenharmony_ci#define SLIC_ISR_RMISS			0x02000000
7162306a36Sopenharmony_ci#define SLIC_ISR_UPCERR			0x01000000
7262306a36Sopenharmony_ci#define SLIC_ISR_XDROP			0x00800000
7362306a36Sopenharmony_ci#define SLIC_ISR_UPCBSY			0x00020000
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define SLIC_ISR_PING_MASK		0x00700000
7662306a36Sopenharmony_ci#define SLIC_ISR_UPCERR_MASK		(SLIC_ISR_UPCERR | SLIC_ISR_UPCBSY)
7762306a36Sopenharmony_ci#define SLIC_ISR_UPC_MASK		(SLIC_ISR_UPC | SLIC_ISR_UPCERR_MASK)
7862306a36Sopenharmony_ci#define SLIC_WCS_START			0x80000000
7962306a36Sopenharmony_ci#define SLIC_WCS_COMPARE		0x40000000
8062306a36Sopenharmony_ci#define SLIC_RCVWCS_BEGIN		0x40000000
8162306a36Sopenharmony_ci#define SLIC_RCVWCS_FINISH		0x80000000
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define SLIC_MIICR_REG_16		0x00100000
8462306a36Sopenharmony_ci#define SLIC_MRV_REG16_XOVERON		0x0068
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#define SLIC_GIG_LINKUP			0x0001
8762306a36Sopenharmony_ci#define SLIC_GIG_FULLDUPLEX		0x0002
8862306a36Sopenharmony_ci#define SLIC_GIG_SPEED_MASK		0x000C
8962306a36Sopenharmony_ci#define SLIC_GIG_SPEED_1000		0x0008
9062306a36Sopenharmony_ci#define SLIC_GIG_SPEED_100		0x0004
9162306a36Sopenharmony_ci#define SLIC_GIG_SPEED_10		0x0000
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci#define SLIC_GMCR_RESET			0x80000000
9462306a36Sopenharmony_ci#define SLIC_GMCR_GBIT			0x20000000
9562306a36Sopenharmony_ci#define SLIC_GMCR_FULLD			0x10000000
9662306a36Sopenharmony_ci#define SLIC_GMCR_GAPBB_SHIFT		14
9762306a36Sopenharmony_ci#define SLIC_GMCR_GAPR1_SHIFT		7
9862306a36Sopenharmony_ci#define SLIC_GMCR_GAPR2_SHIFT		0
9962306a36Sopenharmony_ci#define SLIC_GMCR_GAPBB_1000		0x60
10062306a36Sopenharmony_ci#define SLIC_GMCR_GAPR1_1000		0x2C
10162306a36Sopenharmony_ci#define SLIC_GMCR_GAPR2_1000		0x40
10262306a36Sopenharmony_ci#define SLIC_GMCR_GAPBB_100		0x70
10362306a36Sopenharmony_ci#define SLIC_GMCR_GAPR1_100		0x2C
10462306a36Sopenharmony_ci#define SLIC_GMCR_GAPR2_100		0x40
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci#define SLIC_XCR_RESET			0x80000000
10762306a36Sopenharmony_ci#define SLIC_XCR_XMTEN			0x40000000
10862306a36Sopenharmony_ci#define SLIC_XCR_PAUSEEN		0x20000000
10962306a36Sopenharmony_ci#define SLIC_XCR_LOADRNG		0x10000000
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#define SLIC_GXCR_RESET			0x80000000
11262306a36Sopenharmony_ci#define SLIC_GXCR_XMTEN			0x40000000
11362306a36Sopenharmony_ci#define SLIC_GXCR_PAUSEEN		0x20000000
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define SLIC_GRCR_RESET			0x80000000
11662306a36Sopenharmony_ci#define SLIC_GRCR_RCVEN			0x40000000
11762306a36Sopenharmony_ci#define SLIC_GRCR_RCVALL		0x20000000
11862306a36Sopenharmony_ci#define SLIC_GRCR_RCVBAD		0x10000000
11962306a36Sopenharmony_ci#define SLIC_GRCR_CTLEN			0x08000000
12062306a36Sopenharmony_ci#define SLIC_GRCR_ADDRAEN		0x02000000
12162306a36Sopenharmony_ci#define SLIC_GRCR_HASHSIZE_SHIFT	17
12262306a36Sopenharmony_ci#define SLIC_GRCR_HASHSIZE		14
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci/* Reset Register */
12562306a36Sopenharmony_ci#define SLIC_REG_RESET			0x0000
12662306a36Sopenharmony_ci/* Interrupt Control Register */
12762306a36Sopenharmony_ci#define SLIC_REG_ICR			0x0008
12862306a36Sopenharmony_ci/* Interrupt status pointer */
12962306a36Sopenharmony_ci#define SLIC_REG_ISP			0x0010
13062306a36Sopenharmony_ci/* Interrupt status */
13162306a36Sopenharmony_ci#define SLIC_REG_ISR			0x0018
13262306a36Sopenharmony_ci/* Header buffer address reg
13362306a36Sopenharmony_ci * 31-8 - phy addr of set of contiguous hdr buffers
13462306a36Sopenharmony_ci *  7-0 - number of buffers passed
13562306a36Sopenharmony_ci * Buffers are 256 bytes long on 256-byte boundaries.
13662306a36Sopenharmony_ci */
13762306a36Sopenharmony_ci#define SLIC_REG_HBAR			0x0020
13862306a36Sopenharmony_ci/* Data buffer handle & address reg
13962306a36Sopenharmony_ci * 4 sets of registers; Buffers are 2K bytes long 2 per 4K page.
14062306a36Sopenharmony_ci */
14162306a36Sopenharmony_ci#define SLIC_REG_DBAR			0x0028
14262306a36Sopenharmony_ci/* Xmt Cmd buf addr regs.
14362306a36Sopenharmony_ci * 1 per XMT interface
14462306a36Sopenharmony_ci * 31-5 - phy addr of host command buffer
14562306a36Sopenharmony_ci *  4-0 - length of cmd in multiples of 32 bytes
14662306a36Sopenharmony_ci * Buffers are 32 bytes up to 512 bytes long
14762306a36Sopenharmony_ci */
14862306a36Sopenharmony_ci#define SLIC_REG_CBAR			0x0030
14962306a36Sopenharmony_ci/* Write control store */
15062306a36Sopenharmony_ci#define	SLIC_REG_WCS			0x0034
15162306a36Sopenharmony_ci/*Response buffer address reg.
15262306a36Sopenharmony_ci * 31-8 - phy addr of set of contiguous response buffers
15362306a36Sopenharmony_ci * 7-0 - number of buffers passed
15462306a36Sopenharmony_ci * Buffers are 32 bytes long on 32-byte boundaries.
15562306a36Sopenharmony_ci */
15662306a36Sopenharmony_ci#define	SLIC_REG_RBAR			0x0038
15762306a36Sopenharmony_ci/* Read statistics (UPR) */
15862306a36Sopenharmony_ci#define	SLIC_REG_RSTAT			0x0040
15962306a36Sopenharmony_ci/* Read link status */
16062306a36Sopenharmony_ci#define	SLIC_REG_LSTAT			0x0048
16162306a36Sopenharmony_ci/* Write Mac Config */
16262306a36Sopenharmony_ci#define	SLIC_REG_WMCFG			0x0050
16362306a36Sopenharmony_ci/* Write phy register */
16462306a36Sopenharmony_ci#define SLIC_REG_WPHY			0x0058
16562306a36Sopenharmony_ci/* Rcv Cmd buf addr reg */
16662306a36Sopenharmony_ci#define	SLIC_REG_RCBAR			0x0060
16762306a36Sopenharmony_ci/* Read SLIC Config*/
16862306a36Sopenharmony_ci#define SLIC_REG_RCONFIG		0x0068
16962306a36Sopenharmony_ci/* Interrupt aggregation time */
17062306a36Sopenharmony_ci#define SLIC_REG_INTAGG			0x0070
17162306a36Sopenharmony_ci/* Write XMIT config reg */
17262306a36Sopenharmony_ci#define	SLIC_REG_WXCFG			0x0078
17362306a36Sopenharmony_ci/* Write RCV config reg */
17462306a36Sopenharmony_ci#define	SLIC_REG_WRCFG			0x0080
17562306a36Sopenharmony_ci/* Write rcv addr a low */
17662306a36Sopenharmony_ci#define	SLIC_REG_WRADDRAL		0x0088
17762306a36Sopenharmony_ci/* Write rcv addr a high */
17862306a36Sopenharmony_ci#define	SLIC_REG_WRADDRAH		0x0090
17962306a36Sopenharmony_ci/* Write rcv addr b low */
18062306a36Sopenharmony_ci#define	SLIC_REG_WRADDRBL		0x0098
18162306a36Sopenharmony_ci/* Write rcv addr b high */
18262306a36Sopenharmony_ci#define	SLIC_REG_WRADDRBH		0x00a0
18362306a36Sopenharmony_ci/* Low bits of mcast mask */
18462306a36Sopenharmony_ci#define	SLIC_REG_MCASTLOW		0x00a8
18562306a36Sopenharmony_ci/* High bits of mcast mask */
18662306a36Sopenharmony_ci#define	SLIC_REG_MCASTHIGH		0x00b0
18762306a36Sopenharmony_ci/* Ping the card */
18862306a36Sopenharmony_ci#define SLIC_REG_PING			0x00b8
18962306a36Sopenharmony_ci/* Dump command */
19062306a36Sopenharmony_ci#define SLIC_REG_DUMP_CMD		0x00c0
19162306a36Sopenharmony_ci/* Dump data pointer */
19262306a36Sopenharmony_ci#define SLIC_REG_DUMP_DATA		0x00c8
19362306a36Sopenharmony_ci/* Read card's pci_status register */
19462306a36Sopenharmony_ci#define	SLIC_REG_PCISTATUS		0x00d0
19562306a36Sopenharmony_ci/* Write hostid field */
19662306a36Sopenharmony_ci#define SLIC_REG_WRHOSTID		0x00d8
19762306a36Sopenharmony_ci/* Put card in a low power state */
19862306a36Sopenharmony_ci#define SLIC_REG_LOW_POWER		0x00e0
19962306a36Sopenharmony_ci/* Force slic into quiescent state  before soft reset */
20062306a36Sopenharmony_ci#define SLIC_REG_QUIESCE		0x00e8
20162306a36Sopenharmony_ci/* Reset interface queues */
20262306a36Sopenharmony_ci#define SLIC_REG_RESET_IFACE		0x00f0
20362306a36Sopenharmony_ci/* Register is only written when it has changed.
20462306a36Sopenharmony_ci * Bits 63-32 for host i/f addrs.
20562306a36Sopenharmony_ci */
20662306a36Sopenharmony_ci#define SLIC_REG_ADDR_UPPER		0x00f8
20762306a36Sopenharmony_ci/* 64 bit Header buffer address reg */
20862306a36Sopenharmony_ci#define SLIC_REG_HBAR64			0x0100
20962306a36Sopenharmony_ci/* 64 bit Data buffer handle & address reg */
21062306a36Sopenharmony_ci#define SLIC_REG_DBAR64			0x0108
21162306a36Sopenharmony_ci/* 64 bit Xmt Cmd buf addr regs. */
21262306a36Sopenharmony_ci#define SLIC_REG_CBAR64			0x0110
21362306a36Sopenharmony_ci/* 64 bit Response buffer address reg.*/
21462306a36Sopenharmony_ci#define SLIC_REG_RBAR64			0x0118
21562306a36Sopenharmony_ci/* 64 bit Rcv Cmd buf addr reg*/
21662306a36Sopenharmony_ci#define	SLIC_REG_RCBAR64		0x0120
21762306a36Sopenharmony_ci/* Read statistics (64 bit UPR) */
21862306a36Sopenharmony_ci#define	SLIC_REG_RSTAT64		0x0128
21962306a36Sopenharmony_ci/* Download Gigabit RCV sequencer ucode */
22062306a36Sopenharmony_ci#define SLIC_REG_RCV_WCS		0x0130
22162306a36Sopenharmony_ci/* Write VlanId field */
22262306a36Sopenharmony_ci#define SLIC_REG_WRVLANID		0x0138
22362306a36Sopenharmony_ci/* Read Transformer info */
22462306a36Sopenharmony_ci#define SLIC_REG_READ_XF_INFO		0x0140
22562306a36Sopenharmony_ci/* Write Transformer info */
22662306a36Sopenharmony_ci#define SLIC_REG_WRITE_XF_INFO		0x0148
22762306a36Sopenharmony_ci/* Write card ticks per second */
22862306a36Sopenharmony_ci#define SLIC_REG_TICKS_PER_SEC		0x0170
22962306a36Sopenharmony_ci#define SLIC_REG_HOSTID			0x1554
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci#define PCI_VENDOR_ID_ALACRITECH		0x139A
23262306a36Sopenharmony_ci#define PCI_DEVICE_ID_ALACRITECH_MOJAVE		0x0005
23362306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_1000X1	0x0005
23462306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_1000X1_2	0x0006
23562306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_1000X1F	0x0007
23662306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_CICADA	0x0008
23762306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SES1001T	0x2006
23862306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SES1001F	0x2007
23962306a36Sopenharmony_ci#define PCI_DEVICE_ID_ALACRITECH_OASIS		0x0007
24062306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2002XT	0x000B
24162306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2002XF	0x000C
24262306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2001XT	0x000D
24362306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2001XF	0x000E
24462306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2104EF	0x000F
24562306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2104ET	0x0010
24662306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2102EF	0x0011
24762306a36Sopenharmony_ci#define PCI_SUBDEVICE_ID_ALACRITECH_SEN2102ET	0x0012
24862306a36Sopenharmony_ci
24962306a36Sopenharmony_ci/* Note: power of two required for number descriptors  */
25062306a36Sopenharmony_ci#define SLIC_NUM_RX_LES			256
25162306a36Sopenharmony_ci#define SLIC_RX_BUFF_SIZE		2048
25262306a36Sopenharmony_ci#define SLIC_RX_BUFF_ALIGN		256
25362306a36Sopenharmony_ci#define SLIC_RX_BUFF_HDR_SIZE		34
25462306a36Sopenharmony_ci#define SLIC_MAX_REQ_RX_DESCS		1
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci#define SLIC_NUM_TX_DESCS		256
25762306a36Sopenharmony_ci#define SLIC_TX_DESC_ALIGN		32
25862306a36Sopenharmony_ci#define SLIC_MIN_TX_WAKEUP_DESCS	10
25962306a36Sopenharmony_ci#define SLIC_MAX_REQ_TX_DESCS		1
26062306a36Sopenharmony_ci#define SLIC_MAX_TX_COMPLETIONS		100
26162306a36Sopenharmony_ci
26262306a36Sopenharmony_ci#define SLIC_NUM_STAT_DESCS		128
26362306a36Sopenharmony_ci#define SLIC_STATS_DESC_ALIGN		256
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci#define SLIC_NUM_STAT_DESC_ARRAYS	4
26662306a36Sopenharmony_ci#define SLIC_INVALID_STAT_DESC_IDX	0xffffffff
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci#define SLIC_UPR_LSTAT			0
26962306a36Sopenharmony_ci#define SLIC_UPR_CONFIG			1
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci#define SLIC_EEPROM_SIZE		128
27262306a36Sopenharmony_ci#define SLIC_EEPROM_MAGIC		0xa5a5
27362306a36Sopenharmony_ci
27462306a36Sopenharmony_ci#define SLIC_FIRMWARE_MOJAVE		"slicoss/gbdownload.sys"
27562306a36Sopenharmony_ci#define SLIC_FIRMWARE_OASIS		"slicoss/oasisdownload.sys"
27662306a36Sopenharmony_ci#define SLIC_RCV_FIRMWARE_MOJAVE	"slicoss/gbrcvucode.sys"
27762306a36Sopenharmony_ci#define SLIC_RCV_FIRMWARE_OASIS		"slicoss/oasisrcvucode.sys"
27862306a36Sopenharmony_ci#define SLIC_FIRMWARE_MIN_SIZE		64
27962306a36Sopenharmony_ci#define SLIC_FIRMWARE_MAX_SECTIONS	3
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci#define SLIC_MODEL_MOJAVE		0
28262306a36Sopenharmony_ci#define SLIC_MODEL_OASIS		1
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_ci#define SLIC_INC_STATS_COUNTER(st, counter)	\
28562306a36Sopenharmony_cido {						\
28662306a36Sopenharmony_ci	u64_stats_update_begin(&(st)->syncp);	\
28762306a36Sopenharmony_ci	(st)->counter++;			\
28862306a36Sopenharmony_ci	u64_stats_update_end(&(st)->syncp);	\
28962306a36Sopenharmony_ci} while (0)
29062306a36Sopenharmony_ci
29162306a36Sopenharmony_ci#define SLIC_GET_STATS_COUNTER(newst, st, counter)		\
29262306a36Sopenharmony_ci{								\
29362306a36Sopenharmony_ci	unsigned int start;					\
29462306a36Sopenharmony_ci	do {							\
29562306a36Sopenharmony_ci		start = u64_stats_fetch_begin(&(st)->syncp);	\
29662306a36Sopenharmony_ci		newst = (st)->counter;				\
29762306a36Sopenharmony_ci	} while (u64_stats_fetch_retry(&(st)->syncp, start));	\
29862306a36Sopenharmony_ci}
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_cistruct slic_upr {
30162306a36Sopenharmony_ci	dma_addr_t paddr;
30262306a36Sopenharmony_ci	unsigned int type;
30362306a36Sopenharmony_ci	struct list_head list;
30462306a36Sopenharmony_ci};
30562306a36Sopenharmony_ci
30662306a36Sopenharmony_cistruct slic_upr_list {
30762306a36Sopenharmony_ci	bool pending;
30862306a36Sopenharmony_ci	struct list_head list;
30962306a36Sopenharmony_ci	/* upr list lock */
31062306a36Sopenharmony_ci	spinlock_t lock;
31162306a36Sopenharmony_ci};
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci/* SLIC EEPROM structure for Mojave */
31462306a36Sopenharmony_cistruct slic_mojave_eeprom {
31562306a36Sopenharmony_ci	__le16 id;		/* 00 EEPROM/FLASH Magic code 'A5A5'*/
31662306a36Sopenharmony_ci	__le16 eeprom_code_size;/* 01 Size of EEPROM Codes (bytes * 4)*/
31762306a36Sopenharmony_ci	__le16 flash_size;	/* 02 Flash size */
31862306a36Sopenharmony_ci	__le16 eeprom_size;	/* 03 EEPROM Size */
31962306a36Sopenharmony_ci	__le16 vendor_id;	/* 04 Vendor ID */
32062306a36Sopenharmony_ci	__le16 dev_id;		/* 05 Device ID */
32162306a36Sopenharmony_ci	u8 rev_id;		/* 06 Revision ID */
32262306a36Sopenharmony_ci	u8 class_code[3];	/* 07 Class Code */
32362306a36Sopenharmony_ci	u8 irqpin_dbg;		/* 08 Debug Interrupt pin */
32462306a36Sopenharmony_ci	u8 irqpin;		/*    Network Interrupt Pin */
32562306a36Sopenharmony_ci	u8 min_grant;		/* 09 Minimum grant */
32662306a36Sopenharmony_ci	u8 max_lat;		/*    Maximum Latency */
32762306a36Sopenharmony_ci	__le16 pci_stat;	/* 10 PCI Status */
32862306a36Sopenharmony_ci	__le16 sub_vendor_id;	/* 11 Subsystem Vendor Id */
32962306a36Sopenharmony_ci	__le16 sub_id;		/* 12 Subsystem ID */
33062306a36Sopenharmony_ci	__le16 dev_id_dbg;	/* 13 Debug Device Id */
33162306a36Sopenharmony_ci	__le16 ramrom;		/* 14 Dram/Rom function */
33262306a36Sopenharmony_ci	__le16 dram_size2pci;	/* 15 DRAM size to PCI (bytes * 64K) */
33362306a36Sopenharmony_ci	__le16 rom_size2pci;	/* 16 ROM extension size to PCI (bytes * 4k) */
33462306a36Sopenharmony_ci	u8 pad[2];		/* 17 Padding */
33562306a36Sopenharmony_ci	u8 freetime;		/* 18 FreeTime setting */
33662306a36Sopenharmony_ci	u8 ifctrl;		/* 10-bit interface control (Mojave only) */
33762306a36Sopenharmony_ci	__le16 dram_size;	/* 19 DRAM size (bytes * 64k) */
33862306a36Sopenharmony_ci	u8 mac[ETH_ALEN];	/* 20 MAC addresses */
33962306a36Sopenharmony_ci	u8 mac2[ETH_ALEN];
34062306a36Sopenharmony_ci	u8 pad2[6];
34162306a36Sopenharmony_ci	u16 dev_id2;		/* Device ID for 2nd PCI function */
34262306a36Sopenharmony_ci	u8 irqpin2;		/* Interrupt pin for 2nd PCI function */
34362306a36Sopenharmony_ci	u8 class_code2[3];	/* Class Code for 2nd PCI function */
34462306a36Sopenharmony_ci	u16 cfg_byte6;		/* Config Byte 6 */
34562306a36Sopenharmony_ci	u16 pme_cap;		/* Power Mgment capabilities */
34662306a36Sopenharmony_ci	u16 nwclk_ctrl;		/* NetworkClockControls */
34762306a36Sopenharmony_ci	u8 fru_format;		/* Alacritech FRU format type */
34862306a36Sopenharmony_ci	u8 fru_assembly[6];	/* Alacritech FRU information */
34962306a36Sopenharmony_ci	u8 fru_rev[2];
35062306a36Sopenharmony_ci	u8 fru_serial[14];
35162306a36Sopenharmony_ci	u8 fru_pad[3];
35262306a36Sopenharmony_ci	u8 oem_fru[28];		/* optional OEM FRU format type */
35362306a36Sopenharmony_ci	u8 pad3[4];		/* Pad to 128 bytes - includes 2 cksum bytes
35462306a36Sopenharmony_ci				 * (if OEM FRU info exists) and two unusable
35562306a36Sopenharmony_ci				 * bytes at the end
35662306a36Sopenharmony_ci				 */
35762306a36Sopenharmony_ci};
35862306a36Sopenharmony_ci
35962306a36Sopenharmony_ci/* SLIC EEPROM structure for Oasis */
36062306a36Sopenharmony_cistruct slic_oasis_eeprom {
36162306a36Sopenharmony_ci	__le16 id;		/* 00 EEPROM/FLASH Magic code 'A5A5' */
36262306a36Sopenharmony_ci	__le16 eeprom_code_size;/* 01 Size of EEPROM Codes (bytes * 4)*/
36362306a36Sopenharmony_ci	__le16 spidev0_cfg;	/* 02 Flash Config for SPI device 0 */
36462306a36Sopenharmony_ci	__le16 spidev1_cfg;	/* 03 Flash Config for SPI device 1 */
36562306a36Sopenharmony_ci	__le16 vendor_id;	/* 04 Vendor ID */
36662306a36Sopenharmony_ci	__le16 dev_id;		/* 05 Device ID (function 0) */
36762306a36Sopenharmony_ci	u8 rev_id;		/* 06 Revision ID */
36862306a36Sopenharmony_ci	u8 class_code0[3];	/* 07 Class Code for PCI function 0 */
36962306a36Sopenharmony_ci	u8 irqpin1;		/* 08 Interrupt pin for PCI function 1*/
37062306a36Sopenharmony_ci	u8 class_code1[3];	/* 09 Class Code for PCI function 1 */
37162306a36Sopenharmony_ci	u8 irqpin2;		/* 10 Interrupt pin for PCI function 2*/
37262306a36Sopenharmony_ci	u8 irqpin0;		/*    Interrupt pin for PCI function 0*/
37362306a36Sopenharmony_ci	u8 min_grant;		/* 11 Minimum grant */
37462306a36Sopenharmony_ci	u8 max_lat;		/*    Maximum Latency */
37562306a36Sopenharmony_ci	__le16 sub_vendor_id;	/* 12 Subsystem Vendor Id */
37662306a36Sopenharmony_ci	__le16 sub_id;		/* 13 Subsystem ID */
37762306a36Sopenharmony_ci	__le16 flash_size;	/* 14 Flash size (bytes / 4K) */
37862306a36Sopenharmony_ci	__le16 dram_size2pci;	/* 15 DRAM size to PCI (bytes / 64K) */
37962306a36Sopenharmony_ci	__le16 rom_size2pci;	/* 16 Flash (ROM extension) size to PCI
38062306a36Sopenharmony_ci				 *   (bytes / 4K)
38162306a36Sopenharmony_ci				 */
38262306a36Sopenharmony_ci	__le16 dev_id1;		/* 17 Device Id (function 1) */
38362306a36Sopenharmony_ci	__le16 dev_id2;		/* 18 Device Id (function 2) */
38462306a36Sopenharmony_ci	__le16 dev_stat_cfg;	/* 19 Device Status Config Bytes 6-7 */
38562306a36Sopenharmony_ci	__le16 pme_cap;		/* 20 Power Mgment capabilities */
38662306a36Sopenharmony_ci	u8 msi_cap;		/* 21 MSI capabilities */
38762306a36Sopenharmony_ci	u8 clock_div;		/*    Clock divider */
38862306a36Sopenharmony_ci	__le16 pci_stat_lo;	/* 22 PCI Status bits 15:0 */
38962306a36Sopenharmony_ci	__le16 pci_stat_hi;	/* 23 PCI Status bits 31:16 */
39062306a36Sopenharmony_ci	__le16 dram_cfg_lo;	/* 24 DRAM Configuration bits 15:0 */
39162306a36Sopenharmony_ci	__le16 dram_cfg_hi;	/* 25 DRAM Configuration bits 31:16 */
39262306a36Sopenharmony_ci	__le16 dram_size;	/* 26 DRAM size (bytes / 64K) */
39362306a36Sopenharmony_ci	__le16 gpio_tbi_ctrl;	/* 27 GPIO/TBI controls for functions 1/0 */
39462306a36Sopenharmony_ci	__le16 eeprom_size;	/* 28 EEPROM Size */
39562306a36Sopenharmony_ci	u8 mac[ETH_ALEN];	/* 29 MAC addresses (2 ports) */
39662306a36Sopenharmony_ci	u8 mac2[ETH_ALEN];
39762306a36Sopenharmony_ci	u8 fru_format;		/* 35 Alacritech FRU format type */
39862306a36Sopenharmony_ci	u8 fru_assembly[6];	/* Alacritech FRU information */
39962306a36Sopenharmony_ci	u8 fru_rev[2];
40062306a36Sopenharmony_ci	u8 fru_serial[14];
40162306a36Sopenharmony_ci	u8 fru_pad[3];
40262306a36Sopenharmony_ci	u8 oem_fru[28];		/* optional OEM FRU information */
40362306a36Sopenharmony_ci	u8 pad[4];		/* Pad to 128 bytes - includes 2 checksum bytes
40462306a36Sopenharmony_ci				 * (if OEM FRU info exists) and two unusable
40562306a36Sopenharmony_ci				 * bytes at the end
40662306a36Sopenharmony_ci				 */
40762306a36Sopenharmony_ci};
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_cistruct slic_stats {
41062306a36Sopenharmony_ci	u64 rx_packets;
41162306a36Sopenharmony_ci	u64 rx_bytes;
41262306a36Sopenharmony_ci	u64 rx_mcasts;
41362306a36Sopenharmony_ci	u64 rx_errors;
41462306a36Sopenharmony_ci	u64 tx_packets;
41562306a36Sopenharmony_ci	u64 tx_bytes;
41662306a36Sopenharmony_ci	/* HW STATS */
41762306a36Sopenharmony_ci	u64 rx_buff_miss;
41862306a36Sopenharmony_ci	u64 tx_dropped;
41962306a36Sopenharmony_ci	u64 irq_errs;
42062306a36Sopenharmony_ci	/* transport layer */
42162306a36Sopenharmony_ci	u64 rx_tpcsum;
42262306a36Sopenharmony_ci	u64 rx_tpoflow;
42362306a36Sopenharmony_ci	u64 rx_tphlen;
42462306a36Sopenharmony_ci	/* ip layer */
42562306a36Sopenharmony_ci	u64 rx_ipcsum;
42662306a36Sopenharmony_ci	u64 rx_iplen;
42762306a36Sopenharmony_ci	u64 rx_iphlen;
42862306a36Sopenharmony_ci	/* link layer */
42962306a36Sopenharmony_ci	u64 rx_early;
43062306a36Sopenharmony_ci	u64 rx_buffoflow;
43162306a36Sopenharmony_ci	u64 rx_lcode;
43262306a36Sopenharmony_ci	u64 rx_drbl;
43362306a36Sopenharmony_ci	u64 rx_crc;
43462306a36Sopenharmony_ci	u64 rx_oflow802;
43562306a36Sopenharmony_ci	u64 rx_uflow802;
43662306a36Sopenharmony_ci	/* oasis only */
43762306a36Sopenharmony_ci	u64 tx_carrier;
43862306a36Sopenharmony_ci	struct u64_stats_sync syncp;
43962306a36Sopenharmony_ci};
44062306a36Sopenharmony_ci
44162306a36Sopenharmony_cistruct slic_shmem_data {
44262306a36Sopenharmony_ci	__le32 isr;
44362306a36Sopenharmony_ci	__le32 link;
44462306a36Sopenharmony_ci};
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_cistruct slic_shmem {
44762306a36Sopenharmony_ci	dma_addr_t isr_paddr;
44862306a36Sopenharmony_ci	dma_addr_t link_paddr;
44962306a36Sopenharmony_ci	struct slic_shmem_data *shmem_data;
45062306a36Sopenharmony_ci};
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_cistruct slic_rx_info_oasis {
45362306a36Sopenharmony_ci	__le32 frame_status;
45462306a36Sopenharmony_ci	__le32 frame_status_b;
45562306a36Sopenharmony_ci	__le32 time_stamp;
45662306a36Sopenharmony_ci	__le32 checksum;
45762306a36Sopenharmony_ci};
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_cistruct slic_rx_info_mojave {
46062306a36Sopenharmony_ci	__le32 frame_status;
46162306a36Sopenharmony_ci	__le16 byte_cnt;
46262306a36Sopenharmony_ci	__le16 tp_chksum;
46362306a36Sopenharmony_ci	__le16 ctx_hash;
46462306a36Sopenharmony_ci	__le16 mac_hash;
46562306a36Sopenharmony_ci	__le16 buff_lnk;
46662306a36Sopenharmony_ci};
46762306a36Sopenharmony_ci
46862306a36Sopenharmony_cistruct slic_stat_desc {
46962306a36Sopenharmony_ci	__le32 hnd;
47062306a36Sopenharmony_ci	__u8 pad[8];
47162306a36Sopenharmony_ci	__le32 status;
47262306a36Sopenharmony_ci	__u8 pad2[16];
47362306a36Sopenharmony_ci};
47462306a36Sopenharmony_ci
47562306a36Sopenharmony_cistruct slic_stat_queue {
47662306a36Sopenharmony_ci	struct slic_stat_desc *descs[SLIC_NUM_STAT_DESC_ARRAYS];
47762306a36Sopenharmony_ci	dma_addr_t paddr[SLIC_NUM_STAT_DESC_ARRAYS];
47862306a36Sopenharmony_ci	unsigned int addr_offset[SLIC_NUM_STAT_DESC_ARRAYS];
47962306a36Sopenharmony_ci	unsigned int active_array;
48062306a36Sopenharmony_ci	unsigned int len;
48162306a36Sopenharmony_ci	unsigned int done_idx;
48262306a36Sopenharmony_ci	size_t mem_size;
48362306a36Sopenharmony_ci};
48462306a36Sopenharmony_ci
48562306a36Sopenharmony_cistruct slic_tx_desc {
48662306a36Sopenharmony_ci	__le32 hnd;
48762306a36Sopenharmony_ci	__le32 rsvd;
48862306a36Sopenharmony_ci	u8 cmd;
48962306a36Sopenharmony_ci	u8 flags;
49062306a36Sopenharmony_ci	__le16 rsvd2;
49162306a36Sopenharmony_ci	__le32 totlen;
49262306a36Sopenharmony_ci	__le32 paddrl;
49362306a36Sopenharmony_ci	__le32 paddrh;
49462306a36Sopenharmony_ci	__le32 len;
49562306a36Sopenharmony_ci	__le32 type;
49662306a36Sopenharmony_ci};
49762306a36Sopenharmony_ci
49862306a36Sopenharmony_cistruct slic_tx_buffer {
49962306a36Sopenharmony_ci	struct sk_buff *skb;
50062306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(map_addr);
50162306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(map_len);
50262306a36Sopenharmony_ci	struct slic_tx_desc *desc;
50362306a36Sopenharmony_ci	dma_addr_t desc_paddr;
50462306a36Sopenharmony_ci};
50562306a36Sopenharmony_ci
50662306a36Sopenharmony_cistruct slic_tx_queue {
50762306a36Sopenharmony_ci	struct dma_pool *dma_pool;
50862306a36Sopenharmony_ci	struct slic_tx_buffer *txbuffs;
50962306a36Sopenharmony_ci	unsigned int len;
51062306a36Sopenharmony_ci	unsigned int put_idx;
51162306a36Sopenharmony_ci	unsigned int done_idx;
51262306a36Sopenharmony_ci};
51362306a36Sopenharmony_ci
51462306a36Sopenharmony_cistruct slic_rx_desc {
51562306a36Sopenharmony_ci	u8 pad[16];
51662306a36Sopenharmony_ci	__le32 buffer;
51762306a36Sopenharmony_ci	__le32 length;
51862306a36Sopenharmony_ci	__le32 status;
51962306a36Sopenharmony_ci};
52062306a36Sopenharmony_ci
52162306a36Sopenharmony_cistruct slic_rx_buffer {
52262306a36Sopenharmony_ci	struct sk_buff *skb;
52362306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_ADDR(map_addr);
52462306a36Sopenharmony_ci	DEFINE_DMA_UNMAP_LEN(map_len);
52562306a36Sopenharmony_ci	unsigned int addr_offset;
52662306a36Sopenharmony_ci};
52762306a36Sopenharmony_ci
52862306a36Sopenharmony_cistruct slic_rx_queue {
52962306a36Sopenharmony_ci	struct slic_rx_buffer *rxbuffs;
53062306a36Sopenharmony_ci	unsigned int len;
53162306a36Sopenharmony_ci	unsigned int done_idx;
53262306a36Sopenharmony_ci	unsigned int put_idx;
53362306a36Sopenharmony_ci};
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_cistruct slic_device {
53662306a36Sopenharmony_ci	struct pci_dev *pdev;
53762306a36Sopenharmony_ci	struct net_device *netdev;
53862306a36Sopenharmony_ci	void __iomem *regs;
53962306a36Sopenharmony_ci	/* upper address setting lock */
54062306a36Sopenharmony_ci	spinlock_t upper_lock;
54162306a36Sopenharmony_ci	struct slic_shmem shmem;
54262306a36Sopenharmony_ci	struct napi_struct napi;
54362306a36Sopenharmony_ci	struct slic_rx_queue rxq;
54462306a36Sopenharmony_ci	struct slic_tx_queue txq;
54562306a36Sopenharmony_ci	struct slic_stat_queue stq;
54662306a36Sopenharmony_ci	struct slic_stats stats;
54762306a36Sopenharmony_ci	struct slic_upr_list upr_list;
54862306a36Sopenharmony_ci	/* link configuration lock */
54962306a36Sopenharmony_ci	spinlock_t link_lock;
55062306a36Sopenharmony_ci	bool promisc;
55162306a36Sopenharmony_ci	int speed;
55262306a36Sopenharmony_ci	unsigned int duplex;
55362306a36Sopenharmony_ci	bool is_fiber;
55462306a36Sopenharmony_ci	unsigned char model;
55562306a36Sopenharmony_ci};
55662306a36Sopenharmony_ci
55762306a36Sopenharmony_cistatic inline u32 slic_read(struct slic_device *sdev, unsigned int reg)
55862306a36Sopenharmony_ci{
55962306a36Sopenharmony_ci	return ioread32(sdev->regs + reg);
56062306a36Sopenharmony_ci}
56162306a36Sopenharmony_ci
56262306a36Sopenharmony_cistatic inline void slic_write(struct slic_device *sdev, unsigned int reg,
56362306a36Sopenharmony_ci			      u32 val)
56462306a36Sopenharmony_ci{
56562306a36Sopenharmony_ci	iowrite32(val, sdev->regs + reg);
56662306a36Sopenharmony_ci}
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_cistatic inline void slic_flush_write(struct slic_device *sdev)
56962306a36Sopenharmony_ci{
57062306a36Sopenharmony_ci	(void)ioread32(sdev->regs + SLIC_REG_HOSTID);
57162306a36Sopenharmony_ci}
57262306a36Sopenharmony_ci
57362306a36Sopenharmony_ci#endif /* _SLIC_H */
574