xref: /linux/drivers/net/ethernet/ezchip/nps_enet.h (revision b54b8c2d6e3cd1db17405a402ba42da5a9c8bf1d)
10dd07709SNoam Camus /*
20dd07709SNoam Camus  * Copyright(c) 2015 EZchip Technologies.
30dd07709SNoam Camus  *
40dd07709SNoam Camus  * This program is free software; you can redistribute it and/or modify it
50dd07709SNoam Camus  * under the terms and conditions of the GNU General Public License,
60dd07709SNoam Camus  * version 2, as published by the Free Software Foundation.
70dd07709SNoam Camus  *
80dd07709SNoam Camus  * This program is distributed in the hope it will be useful, but WITHOUT
90dd07709SNoam Camus  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
100dd07709SNoam Camus  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
110dd07709SNoam Camus  * more details.
120dd07709SNoam Camus  *
130dd07709SNoam Camus  * The full GNU General Public License is included in this distribution in
140dd07709SNoam Camus  * the file called "COPYING".
150dd07709SNoam Camus  */
160dd07709SNoam Camus 
170dd07709SNoam Camus #ifndef _NPS_ENET_H
180dd07709SNoam Camus #define _NPS_ENET_H
190dd07709SNoam Camus 
200dd07709SNoam Camus /* default values */
210dd07709SNoam Camus #define NPS_ENET_NAPI_POLL_WEIGHT		0x2
220dd07709SNoam Camus #define NPS_ENET_MAX_FRAME_LENGTH		0x3FFF
230dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_TX_FC_RETR	0x7
240dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_RX_IFG		0x5
250dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_TX_IFG		0xC
260dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_0_TX_PR_LEN		0x7
270dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_2_STAT_EN		0x3
280dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_3_RX_IFG_TH		0x14
290dd07709SNoam Camus #define NPS_ENET_GE_MAC_CFG_3_MAX_LEN		0x3FFC
300dd07709SNoam Camus #define NPS_ENET_ENABLE				1
310dd07709SNoam Camus #define NPS_ENET_DISABLE			0
320dd07709SNoam Camus 
330dd07709SNoam Camus /* register definitions  */
340dd07709SNoam Camus #define NPS_ENET_REG_TX_CTL		0x800
350dd07709SNoam Camus #define NPS_ENET_REG_TX_BUF		0x808
360dd07709SNoam Camus #define NPS_ENET_REG_RX_CTL		0x810
370dd07709SNoam Camus #define NPS_ENET_REG_RX_BUF		0x818
380dd07709SNoam Camus #define NPS_ENET_REG_BUF_INT_ENABLE	0x8C0
390dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_0	0x1000
400dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_1	0x1004
410dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_2	0x1008
420dd07709SNoam Camus #define NPS_ENET_REG_GE_MAC_CFG_3	0x100C
430dd07709SNoam Camus #define NPS_ENET_REG_GE_RST		0x1400
440dd07709SNoam Camus #define NPS_ENET_REG_PHASE_FIFO_CTL	0x1404
450dd07709SNoam Camus 
46*b54b8c2dSLada Trimasova /* Tx control register masks and shifts */
47*b54b8c2dSLada Trimasova #define TX_CTL_NT_MASK 0x7FF
48*b54b8c2dSLada Trimasova #define TX_CTL_NT_SHIFT 0
49*b54b8c2dSLada Trimasova #define TX_CTL_ET_MASK 0x4000
50*b54b8c2dSLada Trimasova #define TX_CTL_ET_SHIFT 14
51*b54b8c2dSLada Trimasova #define TX_CTL_CT_MASK 0x8000
52*b54b8c2dSLada Trimasova #define TX_CTL_CT_SHIFT 15
530dd07709SNoam Camus 
54*b54b8c2dSLada Trimasova /* Rx control register masks and shifts */
55*b54b8c2dSLada Trimasova #define RX_CTL_NR_MASK 0x7FF
56*b54b8c2dSLada Trimasova #define RX_CTL_NR_SHIFT 0
57*b54b8c2dSLada Trimasova #define RX_CTL_CRC_MASK 0x2000
58*b54b8c2dSLada Trimasova #define RX_CTL_CRC_SHIFT 13
59*b54b8c2dSLada Trimasova #define RX_CTL_ER_MASK 0x4000
60*b54b8c2dSLada Trimasova #define RX_CTL_ER_SHIFT 14
61*b54b8c2dSLada Trimasova #define RX_CTL_CR_MASK 0x8000
62*b54b8c2dSLada Trimasova #define RX_CTL_CR_SHIFT 15
630dd07709SNoam Camus 
64*b54b8c2dSLada Trimasova /* Interrupt enable for data buffer events register masks and shifts */
65*b54b8c2dSLada Trimasova #define RX_RDY_MASK 0x1
66*b54b8c2dSLada Trimasova #define RX_RDY_SHIFT 0
67*b54b8c2dSLada Trimasova #define TX_DONE_MASK 0x2
68*b54b8c2dSLada Trimasova #define TX_DONE_SHIFT 1
690dd07709SNoam Camus 
70*b54b8c2dSLada Trimasova /* Gbps Eth MAC Configuration 0 register masks and shifts */
71*b54b8c2dSLada Trimasova #define CFG_0_RX_EN_MASK 0x1
72*b54b8c2dSLada Trimasova #define CFG_0_RX_EN_SHIFT 0
73*b54b8c2dSLada Trimasova #define CFG_0_TX_EN_MASK 0x2
74*b54b8c2dSLada Trimasova #define CFG_0_TX_EN_SHIFT 1
75*b54b8c2dSLada Trimasova #define CFG_0_TX_FC_EN_MASK 0x4
76*b54b8c2dSLada Trimasova #define CFG_0_TX_FC_EN_SHIFT 2
77*b54b8c2dSLada Trimasova #define CFG_0_TX_PAD_EN_MASK 0x8
78*b54b8c2dSLada Trimasova #define CFG_0_TX_PAD_EN_SHIFT 3
79*b54b8c2dSLada Trimasova #define CFG_0_TX_CRC_EN_MASK 0x10
80*b54b8c2dSLada Trimasova #define CFG_0_TX_CRC_EN_SHIFT 4
81*b54b8c2dSLada Trimasova #define CFG_0_RX_FC_EN_MASK 0x20
82*b54b8c2dSLada Trimasova #define CFG_0_RX_FC_EN_SHIFT 5
83*b54b8c2dSLada Trimasova #define CFG_0_RX_CRC_STRIP_MASK 0x40
84*b54b8c2dSLada Trimasova #define CFG_0_RX_CRC_STRIP_SHIFT 6
85*b54b8c2dSLada Trimasova #define CFG_0_RX_CRC_IGNORE_MASK 0x80
86*b54b8c2dSLada Trimasova #define CFG_0_RX_CRC_IGNORE_SHIFT 7
87*b54b8c2dSLada Trimasova #define CFG_0_RX_LENGTH_CHECK_EN_MASK 0x100
88*b54b8c2dSLada Trimasova #define CFG_0_RX_LENGTH_CHECK_EN_SHIFT 8
89*b54b8c2dSLada Trimasova #define CFG_0_TX_FC_RETR_MASK 0xE00
90*b54b8c2dSLada Trimasova #define CFG_0_TX_FC_RETR_SHIFT 9
91*b54b8c2dSLada Trimasova #define CFG_0_RX_IFG_MASK 0xF000
92*b54b8c2dSLada Trimasova #define CFG_0_RX_IFG_SHIFT 12
93*b54b8c2dSLada Trimasova #define CFG_0_TX_IFG_MASK 0x3F0000
94*b54b8c2dSLada Trimasova #define CFG_0_TX_IFG_SHIFT 16
95*b54b8c2dSLada Trimasova #define CFG_0_RX_PR_CHECK_EN_MASK 0x400000
96*b54b8c2dSLada Trimasova #define CFG_0_RX_PR_CHECK_EN_SHIFT 22
97*b54b8c2dSLada Trimasova #define CFG_0_NIB_MODE_MASK 0x800000
98*b54b8c2dSLada Trimasova #define CFG_0_NIB_MODE_SHIFT 23
99*b54b8c2dSLada Trimasova #define CFG_0_TX_IFG_NIB_MASK 0xF000000
100*b54b8c2dSLada Trimasova #define CFG_0_TX_IFG_NIB_SHIFT 24
101*b54b8c2dSLada Trimasova #define CFG_0_TX_PR_LEN_MASK 0xF0000000
102*b54b8c2dSLada Trimasova #define CFG_0_TX_PR_LEN_SHIFT 28
1030dd07709SNoam Camus 
104*b54b8c2dSLada Trimasova /* Gbps Eth MAC Configuration 1 register masks and shifts */
105*b54b8c2dSLada Trimasova #define CFG_1_OCTET_0_MASK 0x000000FF
106*b54b8c2dSLada Trimasova #define CFG_1_OCTET_0_SHIFT 0
107*b54b8c2dSLada Trimasova #define CFG_1_OCTET_1_MASK 0x0000FF00
108*b54b8c2dSLada Trimasova #define CFG_1_OCTET_1_SHIFT 8
109*b54b8c2dSLada Trimasova #define CFG_1_OCTET_2_MASK 0x00FF0000
110*b54b8c2dSLada Trimasova #define CFG_1_OCTET_2_SHIFT 16
111*b54b8c2dSLada Trimasova #define CFG_1_OCTET_3_MASK 0xFF000000
112*b54b8c2dSLada Trimasova #define CFG_1_OCTET_3_SHIFT 24
1130dd07709SNoam Camus 
114*b54b8c2dSLada Trimasova /* Gbps Eth MAC Configuration 2 register masks and shifts */
115*b54b8c2dSLada Trimasova #define CFG_2_OCTET_4_MASK 0x000000FF
116*b54b8c2dSLada Trimasova #define CFG_2_OCTET_4_SHIFT 0
117*b54b8c2dSLada Trimasova #define CFG_2_OCTET_5_MASK 0x0000FF00
118*b54b8c2dSLada Trimasova #define CFG_2_OCTET_5_SHIFT 8
119*b54b8c2dSLada Trimasova #define CFG_2_DISK_MC_MASK 0x00100000
120*b54b8c2dSLada Trimasova #define CFG_2_DISK_MC_SHIFT 20
121*b54b8c2dSLada Trimasova #define CFG_2_DISK_BC_MASK 0x00200000
122*b54b8c2dSLada Trimasova #define CFG_2_DISK_BC_SHIFT 21
123*b54b8c2dSLada Trimasova #define CFG_2_DISK_DA_MASK 0x00400000
124*b54b8c2dSLada Trimasova #define CFG_2_DISK_DA_SHIFT 22
125*b54b8c2dSLada Trimasova #define CFG_2_STAT_EN_MASK 0x3000000
126*b54b8c2dSLada Trimasova #define CFG_2_STAT_EN_SHIFT 24
127*b54b8c2dSLada Trimasova #define CFG_2_TRANSMIT_FLUSH_EN_MASK 0x80000000
128*b54b8c2dSLada Trimasova #define CFG_2_TRANSMIT_FLUSH_EN_SHIFT 31
1290dd07709SNoam Camus 
130*b54b8c2dSLada Trimasova /* Gbps Eth MAC Configuration 3 register masks and shifts */
131*b54b8c2dSLada Trimasova #define CFG_3_TM_HD_MODE_MASK 0x1
132*b54b8c2dSLada Trimasova #define CFG_3_TM_HD_MODE_SHIFT 0
133*b54b8c2dSLada Trimasova #define CFG_3_RX_CBFC_EN_MASK 0x2
134*b54b8c2dSLada Trimasova #define CFG_3_RX_CBFC_EN_SHIFT 1
135*b54b8c2dSLada Trimasova #define CFG_3_RX_CBFC_REDIR_EN_MASK 0x4
136*b54b8c2dSLada Trimasova #define CFG_3_RX_CBFC_REDIR_EN_SHIFT 2
137*b54b8c2dSLada Trimasova #define CFG_3_REDIRECT_CBFC_SEL_MASK 0x18
138*b54b8c2dSLada Trimasova #define CFG_3_REDIRECT_CBFC_SEL_SHIFT 3
139*b54b8c2dSLada Trimasova #define CFG_3_CF_DROP_MASK 0x20
140*b54b8c2dSLada Trimasova #define CFG_3_CF_DROP_SHIFT 5
141*b54b8c2dSLada Trimasova #define CFG_3_CF_TIMEOUT_MASK 0x3C0
142*b54b8c2dSLada Trimasova #define CFG_3_CF_TIMEOUT_SHIFT 6
143*b54b8c2dSLada Trimasova #define CFG_3_RX_IFG_TH_MASK 0x7C00
144*b54b8c2dSLada Trimasova #define CFG_3_RX_IFG_TH_SHIFT 10
145*b54b8c2dSLada Trimasova #define CFG_3_TX_CBFC_EN_MASK 0x8000
146*b54b8c2dSLada Trimasova #define CFG_3_TX_CBFC_EN_SHIFT 15
147*b54b8c2dSLada Trimasova #define CFG_3_MAX_LEN_MASK 0x3FFF0000
148*b54b8c2dSLada Trimasova #define CFG_3_MAX_LEN_SHIFT 16
149*b54b8c2dSLada Trimasova #define CFG_3_EXT_OOB_CBFC_SEL_MASK 0xC0000000
150*b54b8c2dSLada Trimasova #define CFG_3_EXT_OOB_CBFC_SEL_SHIFT 30
1510dd07709SNoam Camus 
152*b54b8c2dSLada Trimasova /* GE MAC, PCS reset control register masks and shifts */
153*b54b8c2dSLada Trimasova #define RST_SPCS_MASK 0x1
154*b54b8c2dSLada Trimasova #define RST_SPCS_SHIFT 0
155*b54b8c2dSLada Trimasova #define RST_GMAC_0_MASK 0x100
156*b54b8c2dSLada Trimasova #define RST_GMAC_0_SHIFT 8
1570dd07709SNoam Camus 
158*b54b8c2dSLada Trimasova /* Tx phase sync FIFO control register masks and shifts */
159*b54b8c2dSLada Trimasova #define PHASE_FIFO_CTL_RST_MASK 0x1
160*b54b8c2dSLada Trimasova #define PHASE_FIFO_CTL_RST_SHIFT 0
161*b54b8c2dSLada Trimasova #define PHASE_FIFO_CTL_INIT_MASK 0x2
162*b54b8c2dSLada Trimasova #define PHASE_FIFO_CTL_INIT_SHIFT 1
1630dd07709SNoam Camus 
1640dd07709SNoam Camus /**
1650dd07709SNoam Camus  * struct nps_enet_priv - Storage of ENET's private information.
1660dd07709SNoam Camus  * @regs_base:      Base address of ENET memory-mapped control registers.
1670dd07709SNoam Camus  * @irq:            For RX/TX IRQ number.
1680dd07709SNoam Camus  * @tx_packet_sent: SW indication if frame is being sent.
1690dd07709SNoam Camus  * @tx_skb:         socket buffer of sent frame.
1700dd07709SNoam Camus  * @napi:           Structure for NAPI.
1710dd07709SNoam Camus  */
1720dd07709SNoam Camus struct nps_enet_priv {
1730dd07709SNoam Camus 	void __iomem *regs_base;
1740dd07709SNoam Camus 	s32 irq;
1750dd07709SNoam Camus 	bool tx_packet_sent;
1760dd07709SNoam Camus 	struct sk_buff *tx_skb;
1770dd07709SNoam Camus 	struct napi_struct napi;
178*b54b8c2dSLada Trimasova 	u32 ge_mac_cfg_2_value;
179*b54b8c2dSLada Trimasova 	u32 ge_mac_cfg_3_value;
1800dd07709SNoam Camus };
1810dd07709SNoam Camus 
1820dd07709SNoam Camus /**
1830dd07709SNoam Camus  * nps_reg_set - Sets ENET register with provided value.
1840dd07709SNoam Camus  * @priv:       Pointer to EZchip ENET private data structure.
1850dd07709SNoam Camus  * @reg:        Register offset from base address.
1860dd07709SNoam Camus  * @value:      Value to set in register.
1870dd07709SNoam Camus  */
1880dd07709SNoam Camus static inline void nps_enet_reg_set(struct nps_enet_priv *priv,
1890dd07709SNoam Camus 				    s32 reg, s32 value)
1900dd07709SNoam Camus {
1910dd07709SNoam Camus 	iowrite32be(value, priv->regs_base + reg);
1920dd07709SNoam Camus }
1930dd07709SNoam Camus 
1940dd07709SNoam Camus /**
1950dd07709SNoam Camus  * nps_reg_get - Gets value of specified ENET register.
1960dd07709SNoam Camus  * @priv:       Pointer to EZchip ENET private data structure.
1970dd07709SNoam Camus  * @reg:        Register offset from base address.
1980dd07709SNoam Camus  *
1990dd07709SNoam Camus  * returns:     Value of requested register.
2000dd07709SNoam Camus  */
2010dd07709SNoam Camus static inline u32 nps_enet_reg_get(struct nps_enet_priv *priv, s32 reg)
2020dd07709SNoam Camus {
2030dd07709SNoam Camus 	return ioread32be(priv->regs_base + reg);
2040dd07709SNoam Camus }
2050dd07709SNoam Camus 
2060dd07709SNoam Camus #endif /* _NPS_ENET_H */
207