1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Keystone GBE and XGBE subsystem code
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2014 Texas Instruments Incorporated
6*4882a593Smuzhiyun * Authors: Sandeep Nair <sandeep_n@ti.com>
7*4882a593Smuzhiyun * Sandeep Paulraj <s-paulraj@ti.com>
8*4882a593Smuzhiyun * Cyril Chemparathy <cyril@ti.com>
9*4882a593Smuzhiyun * Santosh Shilimkar <santosh.shilimkar@ti.com>
10*4882a593Smuzhiyun * Wingman Kwok <w-kwok2@ti.com>
11*4882a593Smuzhiyun */
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/io.h>
14*4882a593Smuzhiyun #include <linux/module.h>
15*4882a593Smuzhiyun #include <linux/of_mdio.h>
16*4882a593Smuzhiyun #include <linux/of_net.h>
17*4882a593Smuzhiyun #include <linux/of_address.h>
18*4882a593Smuzhiyun #include <linux/if_vlan.h>
19*4882a593Smuzhiyun #include <linux/ptp_classify.h>
20*4882a593Smuzhiyun #include <linux/net_tstamp.h>
21*4882a593Smuzhiyun #include <linux/ethtool.h>
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #include "cpsw.h"
24*4882a593Smuzhiyun #include "cpsw_ale.h"
25*4882a593Smuzhiyun #include "netcp.h"
26*4882a593Smuzhiyun #include "cpts.h"
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun #define NETCP_DRIVER_NAME "TI KeyStone Ethernet Driver"
29*4882a593Smuzhiyun #define NETCP_DRIVER_VERSION "v1.0"
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #define GBE_IDENT(reg) ((reg >> 16) & 0xffff)
32*4882a593Smuzhiyun #define GBE_MAJOR_VERSION(reg) (reg >> 8 & 0x7)
33*4882a593Smuzhiyun #define GBE_MINOR_VERSION(reg) (reg & 0xff)
34*4882a593Smuzhiyun #define GBE_RTL_VERSION(reg) ((reg >> 11) & 0x1f)
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun /* 1G Ethernet SS defines */
37*4882a593Smuzhiyun #define GBE_MODULE_NAME "netcp-gbe"
38*4882a593Smuzhiyun #define GBE_SS_VERSION_14 0x4ed2
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #define GBE_SS_REG_INDEX 0
41*4882a593Smuzhiyun #define GBE_SGMII34_REG_INDEX 1
42*4882a593Smuzhiyun #define GBE_SM_REG_INDEX 2
43*4882a593Smuzhiyun /* offset relative to base of GBE_SS_REG_INDEX */
44*4882a593Smuzhiyun #define GBE13_SGMII_MODULE_OFFSET 0x100
45*4882a593Smuzhiyun /* offset relative to base of GBE_SM_REG_INDEX */
46*4882a593Smuzhiyun #define GBE13_HOST_PORT_OFFSET 0x34
47*4882a593Smuzhiyun #define GBE13_SLAVE_PORT_OFFSET 0x60
48*4882a593Smuzhiyun #define GBE13_EMAC_OFFSET 0x100
49*4882a593Smuzhiyun #define GBE13_SLAVE_PORT2_OFFSET 0x200
50*4882a593Smuzhiyun #define GBE13_HW_STATS_OFFSET 0x300
51*4882a593Smuzhiyun #define GBE13_CPTS_OFFSET 0x500
52*4882a593Smuzhiyun #define GBE13_ALE_OFFSET 0x600
53*4882a593Smuzhiyun #define GBE13_HOST_PORT_NUM 0
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun /* 1G Ethernet NU SS defines */
56*4882a593Smuzhiyun #define GBENU_MODULE_NAME "netcp-gbenu"
57*4882a593Smuzhiyun #define GBE_SS_ID_NU 0x4ee6
58*4882a593Smuzhiyun #define GBE_SS_ID_2U 0x4ee8
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun #define IS_SS_ID_MU(d) \
61*4882a593Smuzhiyun ((GBE_IDENT((d)->ss_version) == GBE_SS_ID_NU) || \
62*4882a593Smuzhiyun (GBE_IDENT((d)->ss_version) == GBE_SS_ID_2U))
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun #define IS_SS_ID_NU(d) \
65*4882a593Smuzhiyun (GBE_IDENT((d)->ss_version) == GBE_SS_ID_NU)
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun #define IS_SS_ID_VER_14(d) \
68*4882a593Smuzhiyun (GBE_IDENT((d)->ss_version) == GBE_SS_VERSION_14)
69*4882a593Smuzhiyun #define IS_SS_ID_2U(d) \
70*4882a593Smuzhiyun (GBE_IDENT((d)->ss_version) == GBE_SS_ID_2U)
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun #define GBENU_SS_REG_INDEX 0
73*4882a593Smuzhiyun #define GBENU_SM_REG_INDEX 1
74*4882a593Smuzhiyun #define GBENU_SGMII_MODULE_OFFSET 0x100
75*4882a593Smuzhiyun #define GBENU_HOST_PORT_OFFSET 0x1000
76*4882a593Smuzhiyun #define GBENU_SLAVE_PORT_OFFSET 0x2000
77*4882a593Smuzhiyun #define GBENU_EMAC_OFFSET 0x2330
78*4882a593Smuzhiyun #define GBENU_HW_STATS_OFFSET 0x1a000
79*4882a593Smuzhiyun #define GBENU_CPTS_OFFSET 0x1d000
80*4882a593Smuzhiyun #define GBENU_ALE_OFFSET 0x1e000
81*4882a593Smuzhiyun #define GBENU_HOST_PORT_NUM 0
82*4882a593Smuzhiyun #define GBENU_SGMII_MODULE_SIZE 0x100
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun /* 10G Ethernet SS defines */
85*4882a593Smuzhiyun #define XGBE_MODULE_NAME "netcp-xgbe"
86*4882a593Smuzhiyun #define XGBE_SS_VERSION_10 0x4ee4
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun #define XGBE_SS_REG_INDEX 0
89*4882a593Smuzhiyun #define XGBE_SM_REG_INDEX 1
90*4882a593Smuzhiyun #define XGBE_SERDES_REG_INDEX 2
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun /* offset relative to base of XGBE_SS_REG_INDEX */
93*4882a593Smuzhiyun #define XGBE10_SGMII_MODULE_OFFSET 0x100
94*4882a593Smuzhiyun #define IS_SS_ID_XGBE(d) ((d)->ss_version == XGBE_SS_VERSION_10)
95*4882a593Smuzhiyun /* offset relative to base of XGBE_SM_REG_INDEX */
96*4882a593Smuzhiyun #define XGBE10_HOST_PORT_OFFSET 0x34
97*4882a593Smuzhiyun #define XGBE10_SLAVE_PORT_OFFSET 0x64
98*4882a593Smuzhiyun #define XGBE10_EMAC_OFFSET 0x400
99*4882a593Smuzhiyun #define XGBE10_CPTS_OFFSET 0x600
100*4882a593Smuzhiyun #define XGBE10_ALE_OFFSET 0x700
101*4882a593Smuzhiyun #define XGBE10_HW_STATS_OFFSET 0x800
102*4882a593Smuzhiyun #define XGBE10_HOST_PORT_NUM 0
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun #define GBE_TIMER_INTERVAL (HZ / 2)
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun /* Soft reset register values */
107*4882a593Smuzhiyun #define SOFT_RESET_MASK BIT(0)
108*4882a593Smuzhiyun #define SOFT_RESET BIT(0)
109*4882a593Smuzhiyun #define DEVICE_EMACSL_RESET_POLL_COUNT 100
110*4882a593Smuzhiyun #define GMACSL_RET_WARN_RESET_INCOMPLETE -2
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun #define MACSL_RX_ENABLE_CSF BIT(23)
113*4882a593Smuzhiyun #define MACSL_ENABLE_EXT_CTL BIT(18)
114*4882a593Smuzhiyun #define MACSL_XGMII_ENABLE BIT(13)
115*4882a593Smuzhiyun #define MACSL_XGIG_MODE BIT(8)
116*4882a593Smuzhiyun #define MACSL_GIG_MODE BIT(7)
117*4882a593Smuzhiyun #define MACSL_GMII_ENABLE BIT(5)
118*4882a593Smuzhiyun #define MACSL_FULLDUPLEX BIT(0)
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun #define GBE_CTL_P0_ENABLE BIT(2)
121*4882a593Smuzhiyun #define ETH_SW_CTL_P0_TX_CRC_REMOVE BIT(13)
122*4882a593Smuzhiyun #define GBE13_REG_VAL_STAT_ENABLE_ALL 0xff
123*4882a593Smuzhiyun #define XGBE_REG_VAL_STAT_ENABLE_ALL 0xf
124*4882a593Smuzhiyun #define GBE_STATS_CD_SEL BIT(28)
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun #define GBE_PORT_MASK(x) (BIT(x) - 1)
127*4882a593Smuzhiyun #define GBE_MASK_NO_PORTS 0
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun #define GBE_DEF_1G_MAC_CONTROL \
130*4882a593Smuzhiyun (MACSL_GIG_MODE | MACSL_GMII_ENABLE | \
131*4882a593Smuzhiyun MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun #define GBE_DEF_10G_MAC_CONTROL \
134*4882a593Smuzhiyun (MACSL_XGIG_MODE | MACSL_XGMII_ENABLE | \
135*4882a593Smuzhiyun MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun #define GBE_STATSA_MODULE 0
138*4882a593Smuzhiyun #define GBE_STATSB_MODULE 1
139*4882a593Smuzhiyun #define GBE_STATSC_MODULE 2
140*4882a593Smuzhiyun #define GBE_STATSD_MODULE 3
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun #define GBENU_STATS0_MODULE 0
143*4882a593Smuzhiyun #define GBENU_STATS1_MODULE 1
144*4882a593Smuzhiyun #define GBENU_STATS2_MODULE 2
145*4882a593Smuzhiyun #define GBENU_STATS3_MODULE 3
146*4882a593Smuzhiyun #define GBENU_STATS4_MODULE 4
147*4882a593Smuzhiyun #define GBENU_STATS5_MODULE 5
148*4882a593Smuzhiyun #define GBENU_STATS6_MODULE 6
149*4882a593Smuzhiyun #define GBENU_STATS7_MODULE 7
150*4882a593Smuzhiyun #define GBENU_STATS8_MODULE 8
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun #define XGBE_STATS0_MODULE 0
153*4882a593Smuzhiyun #define XGBE_STATS1_MODULE 1
154*4882a593Smuzhiyun #define XGBE_STATS2_MODULE 2
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun /* s: 0-based slave_port */
157*4882a593Smuzhiyun #define SGMII_BASE(d, s) \
158*4882a593Smuzhiyun (((s) < 2) ? (d)->sgmii_port_regs : (d)->sgmii_port34_regs)
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun #define GBE_TX_QUEUE 648
161*4882a593Smuzhiyun #define GBE_TXHOOK_ORDER 0
162*4882a593Smuzhiyun #define GBE_RXHOOK_ORDER 0
163*4882a593Smuzhiyun #define GBE_DEFAULT_ALE_AGEOUT 30
164*4882a593Smuzhiyun #define SLAVE_LINK_IS_XGMII(s) ((s)->link_interface >= XGMII_LINK_MAC_PHY)
165*4882a593Smuzhiyun #define SLAVE_LINK_IS_RGMII(s) \
166*4882a593Smuzhiyun (((s)->link_interface >= RGMII_LINK_MAC_PHY) && \
167*4882a593Smuzhiyun ((s)->link_interface <= RGMII_LINK_MAC_PHY_NO_MDIO))
168*4882a593Smuzhiyun #define SLAVE_LINK_IS_SGMII(s) \
169*4882a593Smuzhiyun ((s)->link_interface <= SGMII_LINK_MAC_PHY_NO_MDIO)
170*4882a593Smuzhiyun #define NETCP_LINK_STATE_INVALID -1
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun #define GBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
173*4882a593Smuzhiyun offsetof(struct gbe##_##rb, rn)
174*4882a593Smuzhiyun #define GBENU_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
175*4882a593Smuzhiyun offsetof(struct gbenu##_##rb, rn)
176*4882a593Smuzhiyun #define XGBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
177*4882a593Smuzhiyun offsetof(struct xgbe##_##rb, rn)
178*4882a593Smuzhiyun #define GBE_REG_ADDR(p, rb, rn) (p->rb + p->rb##_ofs.rn)
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun #define HOST_TX_PRI_MAP_DEFAULT 0x00000000
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_TI_CPTS)
183*4882a593Smuzhiyun /* Px_TS_CTL register fields */
184*4882a593Smuzhiyun #define TS_RX_ANX_F_EN BIT(0)
185*4882a593Smuzhiyun #define TS_RX_VLAN_LT1_EN BIT(1)
186*4882a593Smuzhiyun #define TS_RX_VLAN_LT2_EN BIT(2)
187*4882a593Smuzhiyun #define TS_RX_ANX_D_EN BIT(3)
188*4882a593Smuzhiyun #define TS_TX_ANX_F_EN BIT(4)
189*4882a593Smuzhiyun #define TS_TX_VLAN_LT1_EN BIT(5)
190*4882a593Smuzhiyun #define TS_TX_VLAN_LT2_EN BIT(6)
191*4882a593Smuzhiyun #define TS_TX_ANX_D_EN BIT(7)
192*4882a593Smuzhiyun #define TS_LT2_EN BIT(8)
193*4882a593Smuzhiyun #define TS_RX_ANX_E_EN BIT(9)
194*4882a593Smuzhiyun #define TS_TX_ANX_E_EN BIT(10)
195*4882a593Smuzhiyun #define TS_MSG_TYPE_EN_SHIFT 16
196*4882a593Smuzhiyun #define TS_MSG_TYPE_EN_MASK 0xffff
197*4882a593Smuzhiyun
198*4882a593Smuzhiyun /* Px_TS_SEQ_LTYPE register fields */
199*4882a593Smuzhiyun #define TS_SEQ_ID_OFS_SHIFT 16
200*4882a593Smuzhiyun #define TS_SEQ_ID_OFS_MASK 0x3f
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun /* Px_TS_CTL_LTYPE2 register fields */
203*4882a593Smuzhiyun #define TS_107 BIT(16)
204*4882a593Smuzhiyun #define TS_129 BIT(17)
205*4882a593Smuzhiyun #define TS_130 BIT(18)
206*4882a593Smuzhiyun #define TS_131 BIT(19)
207*4882a593Smuzhiyun #define TS_132 BIT(20)
208*4882a593Smuzhiyun #define TS_319 BIT(21)
209*4882a593Smuzhiyun #define TS_320 BIT(22)
210*4882a593Smuzhiyun #define TS_TTL_NONZERO BIT(23)
211*4882a593Smuzhiyun #define TS_UNI_EN BIT(24)
212*4882a593Smuzhiyun #define TS_UNI_EN_SHIFT 24
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun #define TS_TX_ANX_ALL_EN \
215*4882a593Smuzhiyun (TS_TX_ANX_D_EN | TS_TX_ANX_E_EN | TS_TX_ANX_F_EN)
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun #define TS_RX_ANX_ALL_EN \
218*4882a593Smuzhiyun (TS_RX_ANX_D_EN | TS_RX_ANX_E_EN | TS_RX_ANX_F_EN)
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun #define TS_CTL_DST_PORT TS_319
221*4882a593Smuzhiyun #define TS_CTL_DST_PORT_SHIFT 21
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun #define TS_CTL_MADDR_ALL \
224*4882a593Smuzhiyun (TS_107 | TS_129 | TS_130 | TS_131 | TS_132)
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun #define TS_CTL_MADDR_SHIFT 16
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun /* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */
229*4882a593Smuzhiyun #define EVENT_MSG_BITS (BIT(0) | BIT(1) | BIT(2) | BIT(3))
230*4882a593Smuzhiyun #endif /* CONFIG_TI_CPTS */
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun struct xgbe_ss_regs {
233*4882a593Smuzhiyun u32 id_ver;
234*4882a593Smuzhiyun u32 synce_count;
235*4882a593Smuzhiyun u32 synce_mux;
236*4882a593Smuzhiyun u32 control;
237*4882a593Smuzhiyun };
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun struct xgbe_switch_regs {
240*4882a593Smuzhiyun u32 id_ver;
241*4882a593Smuzhiyun u32 control;
242*4882a593Smuzhiyun u32 emcontrol;
243*4882a593Smuzhiyun u32 stat_port_en;
244*4882a593Smuzhiyun u32 ptype;
245*4882a593Smuzhiyun u32 soft_idle;
246*4882a593Smuzhiyun u32 thru_rate;
247*4882a593Smuzhiyun u32 gap_thresh;
248*4882a593Smuzhiyun u32 tx_start_wds;
249*4882a593Smuzhiyun u32 flow_control;
250*4882a593Smuzhiyun u32 cppi_thresh;
251*4882a593Smuzhiyun };
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun struct xgbe_port_regs {
254*4882a593Smuzhiyun u32 blk_cnt;
255*4882a593Smuzhiyun u32 port_vlan;
256*4882a593Smuzhiyun u32 tx_pri_map;
257*4882a593Smuzhiyun u32 sa_lo;
258*4882a593Smuzhiyun u32 sa_hi;
259*4882a593Smuzhiyun u32 ts_ctl;
260*4882a593Smuzhiyun u32 ts_seq_ltype;
261*4882a593Smuzhiyun u32 ts_vlan;
262*4882a593Smuzhiyun u32 ts_ctl_ltype2;
263*4882a593Smuzhiyun u32 ts_ctl2;
264*4882a593Smuzhiyun u32 control;
265*4882a593Smuzhiyun };
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun struct xgbe_host_port_regs {
268*4882a593Smuzhiyun u32 blk_cnt;
269*4882a593Smuzhiyun u32 port_vlan;
270*4882a593Smuzhiyun u32 tx_pri_map;
271*4882a593Smuzhiyun u32 src_id;
272*4882a593Smuzhiyun u32 rx_pri_map;
273*4882a593Smuzhiyun u32 rx_maxlen;
274*4882a593Smuzhiyun };
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun struct xgbe_emac_regs {
277*4882a593Smuzhiyun u32 id_ver;
278*4882a593Smuzhiyun u32 mac_control;
279*4882a593Smuzhiyun u32 mac_status;
280*4882a593Smuzhiyun u32 soft_reset;
281*4882a593Smuzhiyun u32 rx_maxlen;
282*4882a593Smuzhiyun u32 __reserved_0;
283*4882a593Smuzhiyun u32 rx_pause;
284*4882a593Smuzhiyun u32 tx_pause;
285*4882a593Smuzhiyun u32 em_control;
286*4882a593Smuzhiyun u32 __reserved_1;
287*4882a593Smuzhiyun u32 tx_gap;
288*4882a593Smuzhiyun u32 rsvd[4];
289*4882a593Smuzhiyun };
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun struct xgbe_host_hw_stats {
292*4882a593Smuzhiyun u32 rx_good_frames;
293*4882a593Smuzhiyun u32 rx_broadcast_frames;
294*4882a593Smuzhiyun u32 rx_multicast_frames;
295*4882a593Smuzhiyun u32 __rsvd_0[3];
296*4882a593Smuzhiyun u32 rx_oversized_frames;
297*4882a593Smuzhiyun u32 __rsvd_1;
298*4882a593Smuzhiyun u32 rx_undersized_frames;
299*4882a593Smuzhiyun u32 __rsvd_2;
300*4882a593Smuzhiyun u32 overrun_type4;
301*4882a593Smuzhiyun u32 overrun_type5;
302*4882a593Smuzhiyun u32 rx_bytes;
303*4882a593Smuzhiyun u32 tx_good_frames;
304*4882a593Smuzhiyun u32 tx_broadcast_frames;
305*4882a593Smuzhiyun u32 tx_multicast_frames;
306*4882a593Smuzhiyun u32 __rsvd_3[9];
307*4882a593Smuzhiyun u32 tx_bytes;
308*4882a593Smuzhiyun u32 tx_64byte_frames;
309*4882a593Smuzhiyun u32 tx_65_to_127byte_frames;
310*4882a593Smuzhiyun u32 tx_128_to_255byte_frames;
311*4882a593Smuzhiyun u32 tx_256_to_511byte_frames;
312*4882a593Smuzhiyun u32 tx_512_to_1023byte_frames;
313*4882a593Smuzhiyun u32 tx_1024byte_frames;
314*4882a593Smuzhiyun u32 net_bytes;
315*4882a593Smuzhiyun u32 rx_sof_overruns;
316*4882a593Smuzhiyun u32 rx_mof_overruns;
317*4882a593Smuzhiyun u32 rx_dma_overruns;
318*4882a593Smuzhiyun };
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun struct xgbe_hw_stats {
321*4882a593Smuzhiyun u32 rx_good_frames;
322*4882a593Smuzhiyun u32 rx_broadcast_frames;
323*4882a593Smuzhiyun u32 rx_multicast_frames;
324*4882a593Smuzhiyun u32 rx_pause_frames;
325*4882a593Smuzhiyun u32 rx_crc_errors;
326*4882a593Smuzhiyun u32 rx_align_code_errors;
327*4882a593Smuzhiyun u32 rx_oversized_frames;
328*4882a593Smuzhiyun u32 rx_jabber_frames;
329*4882a593Smuzhiyun u32 rx_undersized_frames;
330*4882a593Smuzhiyun u32 rx_fragments;
331*4882a593Smuzhiyun u32 overrun_type4;
332*4882a593Smuzhiyun u32 overrun_type5;
333*4882a593Smuzhiyun u32 rx_bytes;
334*4882a593Smuzhiyun u32 tx_good_frames;
335*4882a593Smuzhiyun u32 tx_broadcast_frames;
336*4882a593Smuzhiyun u32 tx_multicast_frames;
337*4882a593Smuzhiyun u32 tx_pause_frames;
338*4882a593Smuzhiyun u32 tx_deferred_frames;
339*4882a593Smuzhiyun u32 tx_collision_frames;
340*4882a593Smuzhiyun u32 tx_single_coll_frames;
341*4882a593Smuzhiyun u32 tx_mult_coll_frames;
342*4882a593Smuzhiyun u32 tx_excessive_collisions;
343*4882a593Smuzhiyun u32 tx_late_collisions;
344*4882a593Smuzhiyun u32 tx_underrun;
345*4882a593Smuzhiyun u32 tx_carrier_sense_errors;
346*4882a593Smuzhiyun u32 tx_bytes;
347*4882a593Smuzhiyun u32 tx_64byte_frames;
348*4882a593Smuzhiyun u32 tx_65_to_127byte_frames;
349*4882a593Smuzhiyun u32 tx_128_to_255byte_frames;
350*4882a593Smuzhiyun u32 tx_256_to_511byte_frames;
351*4882a593Smuzhiyun u32 tx_512_to_1023byte_frames;
352*4882a593Smuzhiyun u32 tx_1024byte_frames;
353*4882a593Smuzhiyun u32 net_bytes;
354*4882a593Smuzhiyun u32 rx_sof_overruns;
355*4882a593Smuzhiyun u32 rx_mof_overruns;
356*4882a593Smuzhiyun u32 rx_dma_overruns;
357*4882a593Smuzhiyun };
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun struct gbenu_ss_regs {
360*4882a593Smuzhiyun u32 id_ver;
361*4882a593Smuzhiyun u32 synce_count; /* NU */
362*4882a593Smuzhiyun u32 synce_mux; /* NU */
363*4882a593Smuzhiyun u32 control; /* 2U */
364*4882a593Smuzhiyun u32 __rsvd_0[2]; /* 2U */
365*4882a593Smuzhiyun u32 rgmii_status; /* 2U */
366*4882a593Smuzhiyun u32 ss_status; /* 2U */
367*4882a593Smuzhiyun };
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun struct gbenu_switch_regs {
370*4882a593Smuzhiyun u32 id_ver;
371*4882a593Smuzhiyun u32 control;
372*4882a593Smuzhiyun u32 __rsvd_0[2];
373*4882a593Smuzhiyun u32 emcontrol;
374*4882a593Smuzhiyun u32 stat_port_en;
375*4882a593Smuzhiyun u32 ptype; /* NU */
376*4882a593Smuzhiyun u32 soft_idle;
377*4882a593Smuzhiyun u32 thru_rate; /* NU */
378*4882a593Smuzhiyun u32 gap_thresh; /* NU */
379*4882a593Smuzhiyun u32 tx_start_wds; /* NU */
380*4882a593Smuzhiyun u32 eee_prescale; /* 2U */
381*4882a593Smuzhiyun u32 tx_g_oflow_thresh_set; /* NU */
382*4882a593Smuzhiyun u32 tx_g_oflow_thresh_clr; /* NU */
383*4882a593Smuzhiyun u32 tx_g_buf_thresh_set_l; /* NU */
384*4882a593Smuzhiyun u32 tx_g_buf_thresh_set_h; /* NU */
385*4882a593Smuzhiyun u32 tx_g_buf_thresh_clr_l; /* NU */
386*4882a593Smuzhiyun u32 tx_g_buf_thresh_clr_h; /* NU */
387*4882a593Smuzhiyun };
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun struct gbenu_port_regs {
390*4882a593Smuzhiyun u32 __rsvd_0;
391*4882a593Smuzhiyun u32 control;
392*4882a593Smuzhiyun u32 max_blks; /* 2U */
393*4882a593Smuzhiyun u32 mem_align1;
394*4882a593Smuzhiyun u32 blk_cnt;
395*4882a593Smuzhiyun u32 port_vlan;
396*4882a593Smuzhiyun u32 tx_pri_map; /* NU */
397*4882a593Smuzhiyun u32 pri_ctl; /* 2U */
398*4882a593Smuzhiyun u32 rx_pri_map;
399*4882a593Smuzhiyun u32 rx_maxlen;
400*4882a593Smuzhiyun u32 tx_blks_pri; /* NU */
401*4882a593Smuzhiyun u32 __rsvd_1;
402*4882a593Smuzhiyun u32 idle2lpi; /* 2U */
403*4882a593Smuzhiyun u32 lpi2idle; /* 2U */
404*4882a593Smuzhiyun u32 eee_status; /* 2U */
405*4882a593Smuzhiyun u32 __rsvd_2;
406*4882a593Smuzhiyun u32 __rsvd_3[176]; /* NU: more to add */
407*4882a593Smuzhiyun u32 __rsvd_4[2];
408*4882a593Smuzhiyun u32 sa_lo;
409*4882a593Smuzhiyun u32 sa_hi;
410*4882a593Smuzhiyun u32 ts_ctl;
411*4882a593Smuzhiyun u32 ts_seq_ltype;
412*4882a593Smuzhiyun u32 ts_vlan;
413*4882a593Smuzhiyun u32 ts_ctl_ltype2;
414*4882a593Smuzhiyun u32 ts_ctl2;
415*4882a593Smuzhiyun };
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun struct gbenu_host_port_regs {
418*4882a593Smuzhiyun u32 __rsvd_0;
419*4882a593Smuzhiyun u32 control;
420*4882a593Smuzhiyun u32 flow_id_offset; /* 2U */
421*4882a593Smuzhiyun u32 __rsvd_1;
422*4882a593Smuzhiyun u32 blk_cnt;
423*4882a593Smuzhiyun u32 port_vlan;
424*4882a593Smuzhiyun u32 tx_pri_map; /* NU */
425*4882a593Smuzhiyun u32 pri_ctl;
426*4882a593Smuzhiyun u32 rx_pri_map;
427*4882a593Smuzhiyun u32 rx_maxlen;
428*4882a593Smuzhiyun u32 tx_blks_pri; /* NU */
429*4882a593Smuzhiyun u32 __rsvd_2;
430*4882a593Smuzhiyun u32 idle2lpi; /* 2U */
431*4882a593Smuzhiyun u32 lpi2wake; /* 2U */
432*4882a593Smuzhiyun u32 eee_status; /* 2U */
433*4882a593Smuzhiyun u32 __rsvd_3;
434*4882a593Smuzhiyun u32 __rsvd_4[184]; /* NU */
435*4882a593Smuzhiyun u32 host_blks_pri; /* NU */
436*4882a593Smuzhiyun };
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun struct gbenu_emac_regs {
439*4882a593Smuzhiyun u32 mac_control;
440*4882a593Smuzhiyun u32 mac_status;
441*4882a593Smuzhiyun u32 soft_reset;
442*4882a593Smuzhiyun u32 boff_test;
443*4882a593Smuzhiyun u32 rx_pause;
444*4882a593Smuzhiyun u32 __rsvd_0[11]; /* NU */
445*4882a593Smuzhiyun u32 tx_pause;
446*4882a593Smuzhiyun u32 __rsvd_1[11]; /* NU */
447*4882a593Smuzhiyun u32 em_control;
448*4882a593Smuzhiyun u32 tx_gap;
449*4882a593Smuzhiyun };
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun /* Some hw stat regs are applicable to slave port only.
452*4882a593Smuzhiyun * This is handled by gbenu_et_stats struct. Also some
453*4882a593Smuzhiyun * are for SS version NU and some are for 2U.
454*4882a593Smuzhiyun */
455*4882a593Smuzhiyun struct gbenu_hw_stats {
456*4882a593Smuzhiyun u32 rx_good_frames;
457*4882a593Smuzhiyun u32 rx_broadcast_frames;
458*4882a593Smuzhiyun u32 rx_multicast_frames;
459*4882a593Smuzhiyun u32 rx_pause_frames; /* slave */
460*4882a593Smuzhiyun u32 rx_crc_errors;
461*4882a593Smuzhiyun u32 rx_align_code_errors; /* slave */
462*4882a593Smuzhiyun u32 rx_oversized_frames;
463*4882a593Smuzhiyun u32 rx_jabber_frames; /* slave */
464*4882a593Smuzhiyun u32 rx_undersized_frames;
465*4882a593Smuzhiyun u32 rx_fragments; /* slave */
466*4882a593Smuzhiyun u32 ale_drop;
467*4882a593Smuzhiyun u32 ale_overrun_drop;
468*4882a593Smuzhiyun u32 rx_bytes;
469*4882a593Smuzhiyun u32 tx_good_frames;
470*4882a593Smuzhiyun u32 tx_broadcast_frames;
471*4882a593Smuzhiyun u32 tx_multicast_frames;
472*4882a593Smuzhiyun u32 tx_pause_frames; /* slave */
473*4882a593Smuzhiyun u32 tx_deferred_frames; /* slave */
474*4882a593Smuzhiyun u32 tx_collision_frames; /* slave */
475*4882a593Smuzhiyun u32 tx_single_coll_frames; /* slave */
476*4882a593Smuzhiyun u32 tx_mult_coll_frames; /* slave */
477*4882a593Smuzhiyun u32 tx_excessive_collisions; /* slave */
478*4882a593Smuzhiyun u32 tx_late_collisions; /* slave */
479*4882a593Smuzhiyun u32 rx_ipg_error; /* slave 10G only */
480*4882a593Smuzhiyun u32 tx_carrier_sense_errors; /* slave */
481*4882a593Smuzhiyun u32 tx_bytes;
482*4882a593Smuzhiyun u32 tx_64B_frames;
483*4882a593Smuzhiyun u32 tx_65_to_127B_frames;
484*4882a593Smuzhiyun u32 tx_128_to_255B_frames;
485*4882a593Smuzhiyun u32 tx_256_to_511B_frames;
486*4882a593Smuzhiyun u32 tx_512_to_1023B_frames;
487*4882a593Smuzhiyun u32 tx_1024B_frames;
488*4882a593Smuzhiyun u32 net_bytes;
489*4882a593Smuzhiyun u32 rx_bottom_fifo_drop;
490*4882a593Smuzhiyun u32 rx_port_mask_drop;
491*4882a593Smuzhiyun u32 rx_top_fifo_drop;
492*4882a593Smuzhiyun u32 ale_rate_limit_drop;
493*4882a593Smuzhiyun u32 ale_vid_ingress_drop;
494*4882a593Smuzhiyun u32 ale_da_eq_sa_drop;
495*4882a593Smuzhiyun u32 __rsvd_0[3];
496*4882a593Smuzhiyun u32 ale_unknown_ucast;
497*4882a593Smuzhiyun u32 ale_unknown_ucast_bytes;
498*4882a593Smuzhiyun u32 ale_unknown_mcast;
499*4882a593Smuzhiyun u32 ale_unknown_mcast_bytes;
500*4882a593Smuzhiyun u32 ale_unknown_bcast;
501*4882a593Smuzhiyun u32 ale_unknown_bcast_bytes;
502*4882a593Smuzhiyun u32 ale_pol_match;
503*4882a593Smuzhiyun u32 ale_pol_match_red; /* NU */
504*4882a593Smuzhiyun u32 ale_pol_match_yellow; /* NU */
505*4882a593Smuzhiyun u32 __rsvd_1[44];
506*4882a593Smuzhiyun u32 tx_mem_protect_err;
507*4882a593Smuzhiyun /* following NU only */
508*4882a593Smuzhiyun u32 tx_pri0;
509*4882a593Smuzhiyun u32 tx_pri1;
510*4882a593Smuzhiyun u32 tx_pri2;
511*4882a593Smuzhiyun u32 tx_pri3;
512*4882a593Smuzhiyun u32 tx_pri4;
513*4882a593Smuzhiyun u32 tx_pri5;
514*4882a593Smuzhiyun u32 tx_pri6;
515*4882a593Smuzhiyun u32 tx_pri7;
516*4882a593Smuzhiyun u32 tx_pri0_bcnt;
517*4882a593Smuzhiyun u32 tx_pri1_bcnt;
518*4882a593Smuzhiyun u32 tx_pri2_bcnt;
519*4882a593Smuzhiyun u32 tx_pri3_bcnt;
520*4882a593Smuzhiyun u32 tx_pri4_bcnt;
521*4882a593Smuzhiyun u32 tx_pri5_bcnt;
522*4882a593Smuzhiyun u32 tx_pri6_bcnt;
523*4882a593Smuzhiyun u32 tx_pri7_bcnt;
524*4882a593Smuzhiyun u32 tx_pri0_drop;
525*4882a593Smuzhiyun u32 tx_pri1_drop;
526*4882a593Smuzhiyun u32 tx_pri2_drop;
527*4882a593Smuzhiyun u32 tx_pri3_drop;
528*4882a593Smuzhiyun u32 tx_pri4_drop;
529*4882a593Smuzhiyun u32 tx_pri5_drop;
530*4882a593Smuzhiyun u32 tx_pri6_drop;
531*4882a593Smuzhiyun u32 tx_pri7_drop;
532*4882a593Smuzhiyun u32 tx_pri0_drop_bcnt;
533*4882a593Smuzhiyun u32 tx_pri1_drop_bcnt;
534*4882a593Smuzhiyun u32 tx_pri2_drop_bcnt;
535*4882a593Smuzhiyun u32 tx_pri3_drop_bcnt;
536*4882a593Smuzhiyun u32 tx_pri4_drop_bcnt;
537*4882a593Smuzhiyun u32 tx_pri5_drop_bcnt;
538*4882a593Smuzhiyun u32 tx_pri6_drop_bcnt;
539*4882a593Smuzhiyun u32 tx_pri7_drop_bcnt;
540*4882a593Smuzhiyun };
541*4882a593Smuzhiyun
542*4882a593Smuzhiyun #define GBENU_HW_STATS_REG_MAP_SZ 0x200
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun struct gbe_ss_regs {
545*4882a593Smuzhiyun u32 id_ver;
546*4882a593Smuzhiyun u32 synce_count;
547*4882a593Smuzhiyun u32 synce_mux;
548*4882a593Smuzhiyun };
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun struct gbe_ss_regs_ofs {
551*4882a593Smuzhiyun u16 id_ver;
552*4882a593Smuzhiyun u16 control;
553*4882a593Smuzhiyun u16 rgmii_status; /* 2U */
554*4882a593Smuzhiyun };
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun struct gbe_switch_regs {
557*4882a593Smuzhiyun u32 id_ver;
558*4882a593Smuzhiyun u32 control;
559*4882a593Smuzhiyun u32 soft_reset;
560*4882a593Smuzhiyun u32 stat_port_en;
561*4882a593Smuzhiyun u32 ptype;
562*4882a593Smuzhiyun u32 soft_idle;
563*4882a593Smuzhiyun u32 thru_rate;
564*4882a593Smuzhiyun u32 gap_thresh;
565*4882a593Smuzhiyun u32 tx_start_wds;
566*4882a593Smuzhiyun u32 flow_control;
567*4882a593Smuzhiyun };
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun struct gbe_switch_regs_ofs {
570*4882a593Smuzhiyun u16 id_ver;
571*4882a593Smuzhiyun u16 control;
572*4882a593Smuzhiyun u16 soft_reset;
573*4882a593Smuzhiyun u16 emcontrol;
574*4882a593Smuzhiyun u16 stat_port_en;
575*4882a593Smuzhiyun u16 ptype;
576*4882a593Smuzhiyun u16 flow_control;
577*4882a593Smuzhiyun };
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun struct gbe_port_regs {
580*4882a593Smuzhiyun u32 max_blks;
581*4882a593Smuzhiyun u32 blk_cnt;
582*4882a593Smuzhiyun u32 port_vlan;
583*4882a593Smuzhiyun u32 tx_pri_map;
584*4882a593Smuzhiyun u32 sa_lo;
585*4882a593Smuzhiyun u32 sa_hi;
586*4882a593Smuzhiyun u32 ts_ctl;
587*4882a593Smuzhiyun u32 ts_seq_ltype;
588*4882a593Smuzhiyun u32 ts_vlan;
589*4882a593Smuzhiyun u32 ts_ctl_ltype2;
590*4882a593Smuzhiyun u32 ts_ctl2;
591*4882a593Smuzhiyun };
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun struct gbe_port_regs_ofs {
594*4882a593Smuzhiyun u16 port_vlan;
595*4882a593Smuzhiyun u16 tx_pri_map;
596*4882a593Smuzhiyun u16 rx_pri_map;
597*4882a593Smuzhiyun u16 sa_lo;
598*4882a593Smuzhiyun u16 sa_hi;
599*4882a593Smuzhiyun u16 ts_ctl;
600*4882a593Smuzhiyun u16 ts_seq_ltype;
601*4882a593Smuzhiyun u16 ts_vlan;
602*4882a593Smuzhiyun u16 ts_ctl_ltype2;
603*4882a593Smuzhiyun u16 ts_ctl2;
604*4882a593Smuzhiyun u16 rx_maxlen; /* 2U, NU */
605*4882a593Smuzhiyun };
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun struct gbe_host_port_regs {
608*4882a593Smuzhiyun u32 src_id;
609*4882a593Smuzhiyun u32 port_vlan;
610*4882a593Smuzhiyun u32 rx_pri_map;
611*4882a593Smuzhiyun u32 rx_maxlen;
612*4882a593Smuzhiyun };
613*4882a593Smuzhiyun
614*4882a593Smuzhiyun struct gbe_host_port_regs_ofs {
615*4882a593Smuzhiyun u16 port_vlan;
616*4882a593Smuzhiyun u16 tx_pri_map;
617*4882a593Smuzhiyun u16 rx_maxlen;
618*4882a593Smuzhiyun };
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun struct gbe_emac_regs {
621*4882a593Smuzhiyun u32 id_ver;
622*4882a593Smuzhiyun u32 mac_control;
623*4882a593Smuzhiyun u32 mac_status;
624*4882a593Smuzhiyun u32 soft_reset;
625*4882a593Smuzhiyun u32 rx_maxlen;
626*4882a593Smuzhiyun u32 __reserved_0;
627*4882a593Smuzhiyun u32 rx_pause;
628*4882a593Smuzhiyun u32 tx_pause;
629*4882a593Smuzhiyun u32 __reserved_1;
630*4882a593Smuzhiyun u32 rx_pri_map;
631*4882a593Smuzhiyun u32 rsvd[6];
632*4882a593Smuzhiyun };
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun struct gbe_emac_regs_ofs {
635*4882a593Smuzhiyun u16 mac_control;
636*4882a593Smuzhiyun u16 soft_reset;
637*4882a593Smuzhiyun u16 rx_maxlen;
638*4882a593Smuzhiyun };
639*4882a593Smuzhiyun
640*4882a593Smuzhiyun struct gbe_hw_stats {
641*4882a593Smuzhiyun u32 rx_good_frames;
642*4882a593Smuzhiyun u32 rx_broadcast_frames;
643*4882a593Smuzhiyun u32 rx_multicast_frames;
644*4882a593Smuzhiyun u32 rx_pause_frames;
645*4882a593Smuzhiyun u32 rx_crc_errors;
646*4882a593Smuzhiyun u32 rx_align_code_errors;
647*4882a593Smuzhiyun u32 rx_oversized_frames;
648*4882a593Smuzhiyun u32 rx_jabber_frames;
649*4882a593Smuzhiyun u32 rx_undersized_frames;
650*4882a593Smuzhiyun u32 rx_fragments;
651*4882a593Smuzhiyun u32 __pad_0[2];
652*4882a593Smuzhiyun u32 rx_bytes;
653*4882a593Smuzhiyun u32 tx_good_frames;
654*4882a593Smuzhiyun u32 tx_broadcast_frames;
655*4882a593Smuzhiyun u32 tx_multicast_frames;
656*4882a593Smuzhiyun u32 tx_pause_frames;
657*4882a593Smuzhiyun u32 tx_deferred_frames;
658*4882a593Smuzhiyun u32 tx_collision_frames;
659*4882a593Smuzhiyun u32 tx_single_coll_frames;
660*4882a593Smuzhiyun u32 tx_mult_coll_frames;
661*4882a593Smuzhiyun u32 tx_excessive_collisions;
662*4882a593Smuzhiyun u32 tx_late_collisions;
663*4882a593Smuzhiyun u32 tx_underrun;
664*4882a593Smuzhiyun u32 tx_carrier_sense_errors;
665*4882a593Smuzhiyun u32 tx_bytes;
666*4882a593Smuzhiyun u32 tx_64byte_frames;
667*4882a593Smuzhiyun u32 tx_65_to_127byte_frames;
668*4882a593Smuzhiyun u32 tx_128_to_255byte_frames;
669*4882a593Smuzhiyun u32 tx_256_to_511byte_frames;
670*4882a593Smuzhiyun u32 tx_512_to_1023byte_frames;
671*4882a593Smuzhiyun u32 tx_1024byte_frames;
672*4882a593Smuzhiyun u32 net_bytes;
673*4882a593Smuzhiyun u32 rx_sof_overruns;
674*4882a593Smuzhiyun u32 rx_mof_overruns;
675*4882a593Smuzhiyun u32 rx_dma_overruns;
676*4882a593Smuzhiyun };
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun #define GBE_MAX_HW_STAT_MODS 9
679*4882a593Smuzhiyun #define GBE_HW_STATS_REG_MAP_SZ 0x100
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun struct ts_ctl {
682*4882a593Smuzhiyun int uni;
683*4882a593Smuzhiyun u8 dst_port_map;
684*4882a593Smuzhiyun u8 maddr_map;
685*4882a593Smuzhiyun u8 ts_mcast_type;
686*4882a593Smuzhiyun };
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun struct gbe_slave {
689*4882a593Smuzhiyun void __iomem *port_regs;
690*4882a593Smuzhiyun void __iomem *emac_regs;
691*4882a593Smuzhiyun struct gbe_port_regs_ofs port_regs_ofs;
692*4882a593Smuzhiyun struct gbe_emac_regs_ofs emac_regs_ofs;
693*4882a593Smuzhiyun int slave_num; /* 0 based logical number */
694*4882a593Smuzhiyun int port_num; /* actual port number */
695*4882a593Smuzhiyun atomic_t link_state;
696*4882a593Smuzhiyun bool open;
697*4882a593Smuzhiyun struct phy_device *phy;
698*4882a593Smuzhiyun u32 link_interface;
699*4882a593Smuzhiyun u32 mac_control;
700*4882a593Smuzhiyun u8 phy_port_t;
701*4882a593Smuzhiyun struct device_node *node;
702*4882a593Smuzhiyun struct device_node *phy_node;
703*4882a593Smuzhiyun struct ts_ctl ts_ctl;
704*4882a593Smuzhiyun struct list_head slave_list;
705*4882a593Smuzhiyun };
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun struct gbe_priv {
708*4882a593Smuzhiyun struct device *dev;
709*4882a593Smuzhiyun struct netcp_device *netcp_device;
710*4882a593Smuzhiyun struct timer_list timer;
711*4882a593Smuzhiyun u32 num_slaves;
712*4882a593Smuzhiyun u32 ale_ports;
713*4882a593Smuzhiyun bool enable_ale;
714*4882a593Smuzhiyun u8 max_num_slaves;
715*4882a593Smuzhiyun u8 max_num_ports; /* max_num_slaves + 1 */
716*4882a593Smuzhiyun u8 num_stats_mods;
717*4882a593Smuzhiyun struct netcp_tx_pipe tx_pipe;
718*4882a593Smuzhiyun
719*4882a593Smuzhiyun int host_port;
720*4882a593Smuzhiyun u32 rx_packet_max;
721*4882a593Smuzhiyun u32 ss_version;
722*4882a593Smuzhiyun u32 stats_en_mask;
723*4882a593Smuzhiyun
724*4882a593Smuzhiyun void __iomem *ss_regs;
725*4882a593Smuzhiyun void __iomem *switch_regs;
726*4882a593Smuzhiyun void __iomem *host_port_regs;
727*4882a593Smuzhiyun void __iomem *ale_reg;
728*4882a593Smuzhiyun void __iomem *cpts_reg;
729*4882a593Smuzhiyun void __iomem *sgmii_port_regs;
730*4882a593Smuzhiyun void __iomem *sgmii_port34_regs;
731*4882a593Smuzhiyun void __iomem *xgbe_serdes_regs;
732*4882a593Smuzhiyun void __iomem *hw_stats_regs[GBE_MAX_HW_STAT_MODS];
733*4882a593Smuzhiyun
734*4882a593Smuzhiyun struct gbe_ss_regs_ofs ss_regs_ofs;
735*4882a593Smuzhiyun struct gbe_switch_regs_ofs switch_regs_ofs;
736*4882a593Smuzhiyun struct gbe_host_port_regs_ofs host_port_regs_ofs;
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun struct cpsw_ale *ale;
739*4882a593Smuzhiyun unsigned int tx_queue_id;
740*4882a593Smuzhiyun const char *dma_chan_name;
741*4882a593Smuzhiyun
742*4882a593Smuzhiyun struct list_head gbe_intf_head;
743*4882a593Smuzhiyun struct list_head secondary_slaves;
744*4882a593Smuzhiyun struct net_device *dummy_ndev;
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun u64 *hw_stats;
747*4882a593Smuzhiyun u32 *hw_stats_prev;
748*4882a593Smuzhiyun const struct netcp_ethtool_stat *et_stats;
749*4882a593Smuzhiyun int num_et_stats;
750*4882a593Smuzhiyun /* Lock for updating the hwstats */
751*4882a593Smuzhiyun spinlock_t hw_stats_lock;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun int cpts_registered;
754*4882a593Smuzhiyun struct cpts *cpts;
755*4882a593Smuzhiyun int rx_ts_enabled;
756*4882a593Smuzhiyun int tx_ts_enabled;
757*4882a593Smuzhiyun };
758*4882a593Smuzhiyun
759*4882a593Smuzhiyun struct gbe_intf {
760*4882a593Smuzhiyun struct net_device *ndev;
761*4882a593Smuzhiyun struct device *dev;
762*4882a593Smuzhiyun struct gbe_priv *gbe_dev;
763*4882a593Smuzhiyun struct netcp_tx_pipe tx_pipe;
764*4882a593Smuzhiyun struct gbe_slave *slave;
765*4882a593Smuzhiyun struct list_head gbe_intf_list;
766*4882a593Smuzhiyun unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
767*4882a593Smuzhiyun };
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun static struct netcp_module gbe_module;
770*4882a593Smuzhiyun static struct netcp_module xgbe_module;
771*4882a593Smuzhiyun
772*4882a593Smuzhiyun /* Statistic management */
773*4882a593Smuzhiyun struct netcp_ethtool_stat {
774*4882a593Smuzhiyun char desc[ETH_GSTRING_LEN];
775*4882a593Smuzhiyun int type;
776*4882a593Smuzhiyun u32 size;
777*4882a593Smuzhiyun int offset;
778*4882a593Smuzhiyun };
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun #define GBE_STATSA_INFO(field) \
781*4882a593Smuzhiyun { \
782*4882a593Smuzhiyun "GBE_A:"#field, GBE_STATSA_MODULE, \
783*4882a593Smuzhiyun sizeof_field(struct gbe_hw_stats, field), \
784*4882a593Smuzhiyun offsetof(struct gbe_hw_stats, field) \
785*4882a593Smuzhiyun }
786*4882a593Smuzhiyun
787*4882a593Smuzhiyun #define GBE_STATSB_INFO(field) \
788*4882a593Smuzhiyun { \
789*4882a593Smuzhiyun "GBE_B:"#field, GBE_STATSB_MODULE, \
790*4882a593Smuzhiyun sizeof_field(struct gbe_hw_stats, field), \
791*4882a593Smuzhiyun offsetof(struct gbe_hw_stats, field) \
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun #define GBE_STATSC_INFO(field) \
795*4882a593Smuzhiyun { \
796*4882a593Smuzhiyun "GBE_C:"#field, GBE_STATSC_MODULE, \
797*4882a593Smuzhiyun sizeof_field(struct gbe_hw_stats, field), \
798*4882a593Smuzhiyun offsetof(struct gbe_hw_stats, field) \
799*4882a593Smuzhiyun }
800*4882a593Smuzhiyun
801*4882a593Smuzhiyun #define GBE_STATSD_INFO(field) \
802*4882a593Smuzhiyun { \
803*4882a593Smuzhiyun "GBE_D:"#field, GBE_STATSD_MODULE, \
804*4882a593Smuzhiyun sizeof_field(struct gbe_hw_stats, field), \
805*4882a593Smuzhiyun offsetof(struct gbe_hw_stats, field) \
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun static const struct netcp_ethtool_stat gbe13_et_stats[] = {
809*4882a593Smuzhiyun /* GBE module A */
810*4882a593Smuzhiyun GBE_STATSA_INFO(rx_good_frames),
811*4882a593Smuzhiyun GBE_STATSA_INFO(rx_broadcast_frames),
812*4882a593Smuzhiyun GBE_STATSA_INFO(rx_multicast_frames),
813*4882a593Smuzhiyun GBE_STATSA_INFO(rx_pause_frames),
814*4882a593Smuzhiyun GBE_STATSA_INFO(rx_crc_errors),
815*4882a593Smuzhiyun GBE_STATSA_INFO(rx_align_code_errors),
816*4882a593Smuzhiyun GBE_STATSA_INFO(rx_oversized_frames),
817*4882a593Smuzhiyun GBE_STATSA_INFO(rx_jabber_frames),
818*4882a593Smuzhiyun GBE_STATSA_INFO(rx_undersized_frames),
819*4882a593Smuzhiyun GBE_STATSA_INFO(rx_fragments),
820*4882a593Smuzhiyun GBE_STATSA_INFO(rx_bytes),
821*4882a593Smuzhiyun GBE_STATSA_INFO(tx_good_frames),
822*4882a593Smuzhiyun GBE_STATSA_INFO(tx_broadcast_frames),
823*4882a593Smuzhiyun GBE_STATSA_INFO(tx_multicast_frames),
824*4882a593Smuzhiyun GBE_STATSA_INFO(tx_pause_frames),
825*4882a593Smuzhiyun GBE_STATSA_INFO(tx_deferred_frames),
826*4882a593Smuzhiyun GBE_STATSA_INFO(tx_collision_frames),
827*4882a593Smuzhiyun GBE_STATSA_INFO(tx_single_coll_frames),
828*4882a593Smuzhiyun GBE_STATSA_INFO(tx_mult_coll_frames),
829*4882a593Smuzhiyun GBE_STATSA_INFO(tx_excessive_collisions),
830*4882a593Smuzhiyun GBE_STATSA_INFO(tx_late_collisions),
831*4882a593Smuzhiyun GBE_STATSA_INFO(tx_underrun),
832*4882a593Smuzhiyun GBE_STATSA_INFO(tx_carrier_sense_errors),
833*4882a593Smuzhiyun GBE_STATSA_INFO(tx_bytes),
834*4882a593Smuzhiyun GBE_STATSA_INFO(tx_64byte_frames),
835*4882a593Smuzhiyun GBE_STATSA_INFO(tx_65_to_127byte_frames),
836*4882a593Smuzhiyun GBE_STATSA_INFO(tx_128_to_255byte_frames),
837*4882a593Smuzhiyun GBE_STATSA_INFO(tx_256_to_511byte_frames),
838*4882a593Smuzhiyun GBE_STATSA_INFO(tx_512_to_1023byte_frames),
839*4882a593Smuzhiyun GBE_STATSA_INFO(tx_1024byte_frames),
840*4882a593Smuzhiyun GBE_STATSA_INFO(net_bytes),
841*4882a593Smuzhiyun GBE_STATSA_INFO(rx_sof_overruns),
842*4882a593Smuzhiyun GBE_STATSA_INFO(rx_mof_overruns),
843*4882a593Smuzhiyun GBE_STATSA_INFO(rx_dma_overruns),
844*4882a593Smuzhiyun /* GBE module B */
845*4882a593Smuzhiyun GBE_STATSB_INFO(rx_good_frames),
846*4882a593Smuzhiyun GBE_STATSB_INFO(rx_broadcast_frames),
847*4882a593Smuzhiyun GBE_STATSB_INFO(rx_multicast_frames),
848*4882a593Smuzhiyun GBE_STATSB_INFO(rx_pause_frames),
849*4882a593Smuzhiyun GBE_STATSB_INFO(rx_crc_errors),
850*4882a593Smuzhiyun GBE_STATSB_INFO(rx_align_code_errors),
851*4882a593Smuzhiyun GBE_STATSB_INFO(rx_oversized_frames),
852*4882a593Smuzhiyun GBE_STATSB_INFO(rx_jabber_frames),
853*4882a593Smuzhiyun GBE_STATSB_INFO(rx_undersized_frames),
854*4882a593Smuzhiyun GBE_STATSB_INFO(rx_fragments),
855*4882a593Smuzhiyun GBE_STATSB_INFO(rx_bytes),
856*4882a593Smuzhiyun GBE_STATSB_INFO(tx_good_frames),
857*4882a593Smuzhiyun GBE_STATSB_INFO(tx_broadcast_frames),
858*4882a593Smuzhiyun GBE_STATSB_INFO(tx_multicast_frames),
859*4882a593Smuzhiyun GBE_STATSB_INFO(tx_pause_frames),
860*4882a593Smuzhiyun GBE_STATSB_INFO(tx_deferred_frames),
861*4882a593Smuzhiyun GBE_STATSB_INFO(tx_collision_frames),
862*4882a593Smuzhiyun GBE_STATSB_INFO(tx_single_coll_frames),
863*4882a593Smuzhiyun GBE_STATSB_INFO(tx_mult_coll_frames),
864*4882a593Smuzhiyun GBE_STATSB_INFO(tx_excessive_collisions),
865*4882a593Smuzhiyun GBE_STATSB_INFO(tx_late_collisions),
866*4882a593Smuzhiyun GBE_STATSB_INFO(tx_underrun),
867*4882a593Smuzhiyun GBE_STATSB_INFO(tx_carrier_sense_errors),
868*4882a593Smuzhiyun GBE_STATSB_INFO(tx_bytes),
869*4882a593Smuzhiyun GBE_STATSB_INFO(tx_64byte_frames),
870*4882a593Smuzhiyun GBE_STATSB_INFO(tx_65_to_127byte_frames),
871*4882a593Smuzhiyun GBE_STATSB_INFO(tx_128_to_255byte_frames),
872*4882a593Smuzhiyun GBE_STATSB_INFO(tx_256_to_511byte_frames),
873*4882a593Smuzhiyun GBE_STATSB_INFO(tx_512_to_1023byte_frames),
874*4882a593Smuzhiyun GBE_STATSB_INFO(tx_1024byte_frames),
875*4882a593Smuzhiyun GBE_STATSB_INFO(net_bytes),
876*4882a593Smuzhiyun GBE_STATSB_INFO(rx_sof_overruns),
877*4882a593Smuzhiyun GBE_STATSB_INFO(rx_mof_overruns),
878*4882a593Smuzhiyun GBE_STATSB_INFO(rx_dma_overruns),
879*4882a593Smuzhiyun /* GBE module C */
880*4882a593Smuzhiyun GBE_STATSC_INFO(rx_good_frames),
881*4882a593Smuzhiyun GBE_STATSC_INFO(rx_broadcast_frames),
882*4882a593Smuzhiyun GBE_STATSC_INFO(rx_multicast_frames),
883*4882a593Smuzhiyun GBE_STATSC_INFO(rx_pause_frames),
884*4882a593Smuzhiyun GBE_STATSC_INFO(rx_crc_errors),
885*4882a593Smuzhiyun GBE_STATSC_INFO(rx_align_code_errors),
886*4882a593Smuzhiyun GBE_STATSC_INFO(rx_oversized_frames),
887*4882a593Smuzhiyun GBE_STATSC_INFO(rx_jabber_frames),
888*4882a593Smuzhiyun GBE_STATSC_INFO(rx_undersized_frames),
889*4882a593Smuzhiyun GBE_STATSC_INFO(rx_fragments),
890*4882a593Smuzhiyun GBE_STATSC_INFO(rx_bytes),
891*4882a593Smuzhiyun GBE_STATSC_INFO(tx_good_frames),
892*4882a593Smuzhiyun GBE_STATSC_INFO(tx_broadcast_frames),
893*4882a593Smuzhiyun GBE_STATSC_INFO(tx_multicast_frames),
894*4882a593Smuzhiyun GBE_STATSC_INFO(tx_pause_frames),
895*4882a593Smuzhiyun GBE_STATSC_INFO(tx_deferred_frames),
896*4882a593Smuzhiyun GBE_STATSC_INFO(tx_collision_frames),
897*4882a593Smuzhiyun GBE_STATSC_INFO(tx_single_coll_frames),
898*4882a593Smuzhiyun GBE_STATSC_INFO(tx_mult_coll_frames),
899*4882a593Smuzhiyun GBE_STATSC_INFO(tx_excessive_collisions),
900*4882a593Smuzhiyun GBE_STATSC_INFO(tx_late_collisions),
901*4882a593Smuzhiyun GBE_STATSC_INFO(tx_underrun),
902*4882a593Smuzhiyun GBE_STATSC_INFO(tx_carrier_sense_errors),
903*4882a593Smuzhiyun GBE_STATSC_INFO(tx_bytes),
904*4882a593Smuzhiyun GBE_STATSC_INFO(tx_64byte_frames),
905*4882a593Smuzhiyun GBE_STATSC_INFO(tx_65_to_127byte_frames),
906*4882a593Smuzhiyun GBE_STATSC_INFO(tx_128_to_255byte_frames),
907*4882a593Smuzhiyun GBE_STATSC_INFO(tx_256_to_511byte_frames),
908*4882a593Smuzhiyun GBE_STATSC_INFO(tx_512_to_1023byte_frames),
909*4882a593Smuzhiyun GBE_STATSC_INFO(tx_1024byte_frames),
910*4882a593Smuzhiyun GBE_STATSC_INFO(net_bytes),
911*4882a593Smuzhiyun GBE_STATSC_INFO(rx_sof_overruns),
912*4882a593Smuzhiyun GBE_STATSC_INFO(rx_mof_overruns),
913*4882a593Smuzhiyun GBE_STATSC_INFO(rx_dma_overruns),
914*4882a593Smuzhiyun /* GBE module D */
915*4882a593Smuzhiyun GBE_STATSD_INFO(rx_good_frames),
916*4882a593Smuzhiyun GBE_STATSD_INFO(rx_broadcast_frames),
917*4882a593Smuzhiyun GBE_STATSD_INFO(rx_multicast_frames),
918*4882a593Smuzhiyun GBE_STATSD_INFO(rx_pause_frames),
919*4882a593Smuzhiyun GBE_STATSD_INFO(rx_crc_errors),
920*4882a593Smuzhiyun GBE_STATSD_INFO(rx_align_code_errors),
921*4882a593Smuzhiyun GBE_STATSD_INFO(rx_oversized_frames),
922*4882a593Smuzhiyun GBE_STATSD_INFO(rx_jabber_frames),
923*4882a593Smuzhiyun GBE_STATSD_INFO(rx_undersized_frames),
924*4882a593Smuzhiyun GBE_STATSD_INFO(rx_fragments),
925*4882a593Smuzhiyun GBE_STATSD_INFO(rx_bytes),
926*4882a593Smuzhiyun GBE_STATSD_INFO(tx_good_frames),
927*4882a593Smuzhiyun GBE_STATSD_INFO(tx_broadcast_frames),
928*4882a593Smuzhiyun GBE_STATSD_INFO(tx_multicast_frames),
929*4882a593Smuzhiyun GBE_STATSD_INFO(tx_pause_frames),
930*4882a593Smuzhiyun GBE_STATSD_INFO(tx_deferred_frames),
931*4882a593Smuzhiyun GBE_STATSD_INFO(tx_collision_frames),
932*4882a593Smuzhiyun GBE_STATSD_INFO(tx_single_coll_frames),
933*4882a593Smuzhiyun GBE_STATSD_INFO(tx_mult_coll_frames),
934*4882a593Smuzhiyun GBE_STATSD_INFO(tx_excessive_collisions),
935*4882a593Smuzhiyun GBE_STATSD_INFO(tx_late_collisions),
936*4882a593Smuzhiyun GBE_STATSD_INFO(tx_underrun),
937*4882a593Smuzhiyun GBE_STATSD_INFO(tx_carrier_sense_errors),
938*4882a593Smuzhiyun GBE_STATSD_INFO(tx_bytes),
939*4882a593Smuzhiyun GBE_STATSD_INFO(tx_64byte_frames),
940*4882a593Smuzhiyun GBE_STATSD_INFO(tx_65_to_127byte_frames),
941*4882a593Smuzhiyun GBE_STATSD_INFO(tx_128_to_255byte_frames),
942*4882a593Smuzhiyun GBE_STATSD_INFO(tx_256_to_511byte_frames),
943*4882a593Smuzhiyun GBE_STATSD_INFO(tx_512_to_1023byte_frames),
944*4882a593Smuzhiyun GBE_STATSD_INFO(tx_1024byte_frames),
945*4882a593Smuzhiyun GBE_STATSD_INFO(net_bytes),
946*4882a593Smuzhiyun GBE_STATSD_INFO(rx_sof_overruns),
947*4882a593Smuzhiyun GBE_STATSD_INFO(rx_mof_overruns),
948*4882a593Smuzhiyun GBE_STATSD_INFO(rx_dma_overruns),
949*4882a593Smuzhiyun };
950*4882a593Smuzhiyun
951*4882a593Smuzhiyun /* This is the size of entries in GBENU_STATS_HOST */
952*4882a593Smuzhiyun #define GBENU_ET_STATS_HOST_SIZE 52
953*4882a593Smuzhiyun
954*4882a593Smuzhiyun #define GBENU_STATS_HOST(field) \
955*4882a593Smuzhiyun { \
956*4882a593Smuzhiyun "GBE_HOST:"#field, GBENU_STATS0_MODULE, \
957*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
958*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
959*4882a593Smuzhiyun }
960*4882a593Smuzhiyun
961*4882a593Smuzhiyun /* This is the size of entries in GBENU_STATS_PORT */
962*4882a593Smuzhiyun #define GBENU_ET_STATS_PORT_SIZE 65
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun #define GBENU_STATS_P1(field) \
965*4882a593Smuzhiyun { \
966*4882a593Smuzhiyun "GBE_P1:"#field, GBENU_STATS1_MODULE, \
967*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
968*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
969*4882a593Smuzhiyun }
970*4882a593Smuzhiyun
971*4882a593Smuzhiyun #define GBENU_STATS_P2(field) \
972*4882a593Smuzhiyun { \
973*4882a593Smuzhiyun "GBE_P2:"#field, GBENU_STATS2_MODULE, \
974*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
975*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
976*4882a593Smuzhiyun }
977*4882a593Smuzhiyun
978*4882a593Smuzhiyun #define GBENU_STATS_P3(field) \
979*4882a593Smuzhiyun { \
980*4882a593Smuzhiyun "GBE_P3:"#field, GBENU_STATS3_MODULE, \
981*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
982*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
983*4882a593Smuzhiyun }
984*4882a593Smuzhiyun
985*4882a593Smuzhiyun #define GBENU_STATS_P4(field) \
986*4882a593Smuzhiyun { \
987*4882a593Smuzhiyun "GBE_P4:"#field, GBENU_STATS4_MODULE, \
988*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
989*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
990*4882a593Smuzhiyun }
991*4882a593Smuzhiyun
992*4882a593Smuzhiyun #define GBENU_STATS_P5(field) \
993*4882a593Smuzhiyun { \
994*4882a593Smuzhiyun "GBE_P5:"#field, GBENU_STATS5_MODULE, \
995*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
996*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
997*4882a593Smuzhiyun }
998*4882a593Smuzhiyun
999*4882a593Smuzhiyun #define GBENU_STATS_P6(field) \
1000*4882a593Smuzhiyun { \
1001*4882a593Smuzhiyun "GBE_P6:"#field, GBENU_STATS6_MODULE, \
1002*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
1003*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
1004*4882a593Smuzhiyun }
1005*4882a593Smuzhiyun
1006*4882a593Smuzhiyun #define GBENU_STATS_P7(field) \
1007*4882a593Smuzhiyun { \
1008*4882a593Smuzhiyun "GBE_P7:"#field, GBENU_STATS7_MODULE, \
1009*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
1010*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
1011*4882a593Smuzhiyun }
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun #define GBENU_STATS_P8(field) \
1014*4882a593Smuzhiyun { \
1015*4882a593Smuzhiyun "GBE_P8:"#field, GBENU_STATS8_MODULE, \
1016*4882a593Smuzhiyun sizeof_field(struct gbenu_hw_stats, field), \
1017*4882a593Smuzhiyun offsetof(struct gbenu_hw_stats, field) \
1018*4882a593Smuzhiyun }
1019*4882a593Smuzhiyun
1020*4882a593Smuzhiyun static const struct netcp_ethtool_stat gbenu_et_stats[] = {
1021*4882a593Smuzhiyun /* GBENU Host Module */
1022*4882a593Smuzhiyun GBENU_STATS_HOST(rx_good_frames),
1023*4882a593Smuzhiyun GBENU_STATS_HOST(rx_broadcast_frames),
1024*4882a593Smuzhiyun GBENU_STATS_HOST(rx_multicast_frames),
1025*4882a593Smuzhiyun GBENU_STATS_HOST(rx_crc_errors),
1026*4882a593Smuzhiyun GBENU_STATS_HOST(rx_oversized_frames),
1027*4882a593Smuzhiyun GBENU_STATS_HOST(rx_undersized_frames),
1028*4882a593Smuzhiyun GBENU_STATS_HOST(ale_drop),
1029*4882a593Smuzhiyun GBENU_STATS_HOST(ale_overrun_drop),
1030*4882a593Smuzhiyun GBENU_STATS_HOST(rx_bytes),
1031*4882a593Smuzhiyun GBENU_STATS_HOST(tx_good_frames),
1032*4882a593Smuzhiyun GBENU_STATS_HOST(tx_broadcast_frames),
1033*4882a593Smuzhiyun GBENU_STATS_HOST(tx_multicast_frames),
1034*4882a593Smuzhiyun GBENU_STATS_HOST(tx_bytes),
1035*4882a593Smuzhiyun GBENU_STATS_HOST(tx_64B_frames),
1036*4882a593Smuzhiyun GBENU_STATS_HOST(tx_65_to_127B_frames),
1037*4882a593Smuzhiyun GBENU_STATS_HOST(tx_128_to_255B_frames),
1038*4882a593Smuzhiyun GBENU_STATS_HOST(tx_256_to_511B_frames),
1039*4882a593Smuzhiyun GBENU_STATS_HOST(tx_512_to_1023B_frames),
1040*4882a593Smuzhiyun GBENU_STATS_HOST(tx_1024B_frames),
1041*4882a593Smuzhiyun GBENU_STATS_HOST(net_bytes),
1042*4882a593Smuzhiyun GBENU_STATS_HOST(rx_bottom_fifo_drop),
1043*4882a593Smuzhiyun GBENU_STATS_HOST(rx_port_mask_drop),
1044*4882a593Smuzhiyun GBENU_STATS_HOST(rx_top_fifo_drop),
1045*4882a593Smuzhiyun GBENU_STATS_HOST(ale_rate_limit_drop),
1046*4882a593Smuzhiyun GBENU_STATS_HOST(ale_vid_ingress_drop),
1047*4882a593Smuzhiyun GBENU_STATS_HOST(ale_da_eq_sa_drop),
1048*4882a593Smuzhiyun GBENU_STATS_HOST(ale_unknown_ucast),
1049*4882a593Smuzhiyun GBENU_STATS_HOST(ale_unknown_ucast_bytes),
1050*4882a593Smuzhiyun GBENU_STATS_HOST(ale_unknown_mcast),
1051*4882a593Smuzhiyun GBENU_STATS_HOST(ale_unknown_mcast_bytes),
1052*4882a593Smuzhiyun GBENU_STATS_HOST(ale_unknown_bcast),
1053*4882a593Smuzhiyun GBENU_STATS_HOST(ale_unknown_bcast_bytes),
1054*4882a593Smuzhiyun GBENU_STATS_HOST(ale_pol_match),
1055*4882a593Smuzhiyun GBENU_STATS_HOST(ale_pol_match_red),
1056*4882a593Smuzhiyun GBENU_STATS_HOST(ale_pol_match_yellow),
1057*4882a593Smuzhiyun GBENU_STATS_HOST(tx_mem_protect_err),
1058*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri0_drop),
1059*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri1_drop),
1060*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri2_drop),
1061*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri3_drop),
1062*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri4_drop),
1063*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri5_drop),
1064*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri6_drop),
1065*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri7_drop),
1066*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri0_drop_bcnt),
1067*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri1_drop_bcnt),
1068*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri2_drop_bcnt),
1069*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri3_drop_bcnt),
1070*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri4_drop_bcnt),
1071*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri5_drop_bcnt),
1072*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri6_drop_bcnt),
1073*4882a593Smuzhiyun GBENU_STATS_HOST(tx_pri7_drop_bcnt),
1074*4882a593Smuzhiyun /* GBENU Module 1 */
1075*4882a593Smuzhiyun GBENU_STATS_P1(rx_good_frames),
1076*4882a593Smuzhiyun GBENU_STATS_P1(rx_broadcast_frames),
1077*4882a593Smuzhiyun GBENU_STATS_P1(rx_multicast_frames),
1078*4882a593Smuzhiyun GBENU_STATS_P1(rx_pause_frames),
1079*4882a593Smuzhiyun GBENU_STATS_P1(rx_crc_errors),
1080*4882a593Smuzhiyun GBENU_STATS_P1(rx_align_code_errors),
1081*4882a593Smuzhiyun GBENU_STATS_P1(rx_oversized_frames),
1082*4882a593Smuzhiyun GBENU_STATS_P1(rx_jabber_frames),
1083*4882a593Smuzhiyun GBENU_STATS_P1(rx_undersized_frames),
1084*4882a593Smuzhiyun GBENU_STATS_P1(rx_fragments),
1085*4882a593Smuzhiyun GBENU_STATS_P1(ale_drop),
1086*4882a593Smuzhiyun GBENU_STATS_P1(ale_overrun_drop),
1087*4882a593Smuzhiyun GBENU_STATS_P1(rx_bytes),
1088*4882a593Smuzhiyun GBENU_STATS_P1(tx_good_frames),
1089*4882a593Smuzhiyun GBENU_STATS_P1(tx_broadcast_frames),
1090*4882a593Smuzhiyun GBENU_STATS_P1(tx_multicast_frames),
1091*4882a593Smuzhiyun GBENU_STATS_P1(tx_pause_frames),
1092*4882a593Smuzhiyun GBENU_STATS_P1(tx_deferred_frames),
1093*4882a593Smuzhiyun GBENU_STATS_P1(tx_collision_frames),
1094*4882a593Smuzhiyun GBENU_STATS_P1(tx_single_coll_frames),
1095*4882a593Smuzhiyun GBENU_STATS_P1(tx_mult_coll_frames),
1096*4882a593Smuzhiyun GBENU_STATS_P1(tx_excessive_collisions),
1097*4882a593Smuzhiyun GBENU_STATS_P1(tx_late_collisions),
1098*4882a593Smuzhiyun GBENU_STATS_P1(rx_ipg_error),
1099*4882a593Smuzhiyun GBENU_STATS_P1(tx_carrier_sense_errors),
1100*4882a593Smuzhiyun GBENU_STATS_P1(tx_bytes),
1101*4882a593Smuzhiyun GBENU_STATS_P1(tx_64B_frames),
1102*4882a593Smuzhiyun GBENU_STATS_P1(tx_65_to_127B_frames),
1103*4882a593Smuzhiyun GBENU_STATS_P1(tx_128_to_255B_frames),
1104*4882a593Smuzhiyun GBENU_STATS_P1(tx_256_to_511B_frames),
1105*4882a593Smuzhiyun GBENU_STATS_P1(tx_512_to_1023B_frames),
1106*4882a593Smuzhiyun GBENU_STATS_P1(tx_1024B_frames),
1107*4882a593Smuzhiyun GBENU_STATS_P1(net_bytes),
1108*4882a593Smuzhiyun GBENU_STATS_P1(rx_bottom_fifo_drop),
1109*4882a593Smuzhiyun GBENU_STATS_P1(rx_port_mask_drop),
1110*4882a593Smuzhiyun GBENU_STATS_P1(rx_top_fifo_drop),
1111*4882a593Smuzhiyun GBENU_STATS_P1(ale_rate_limit_drop),
1112*4882a593Smuzhiyun GBENU_STATS_P1(ale_vid_ingress_drop),
1113*4882a593Smuzhiyun GBENU_STATS_P1(ale_da_eq_sa_drop),
1114*4882a593Smuzhiyun GBENU_STATS_P1(ale_unknown_ucast),
1115*4882a593Smuzhiyun GBENU_STATS_P1(ale_unknown_ucast_bytes),
1116*4882a593Smuzhiyun GBENU_STATS_P1(ale_unknown_mcast),
1117*4882a593Smuzhiyun GBENU_STATS_P1(ale_unknown_mcast_bytes),
1118*4882a593Smuzhiyun GBENU_STATS_P1(ale_unknown_bcast),
1119*4882a593Smuzhiyun GBENU_STATS_P1(ale_unknown_bcast_bytes),
1120*4882a593Smuzhiyun GBENU_STATS_P1(ale_pol_match),
1121*4882a593Smuzhiyun GBENU_STATS_P1(ale_pol_match_red),
1122*4882a593Smuzhiyun GBENU_STATS_P1(ale_pol_match_yellow),
1123*4882a593Smuzhiyun GBENU_STATS_P1(tx_mem_protect_err),
1124*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri0_drop),
1125*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri1_drop),
1126*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri2_drop),
1127*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri3_drop),
1128*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri4_drop),
1129*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri5_drop),
1130*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri6_drop),
1131*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri7_drop),
1132*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri0_drop_bcnt),
1133*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri1_drop_bcnt),
1134*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri2_drop_bcnt),
1135*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri3_drop_bcnt),
1136*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri4_drop_bcnt),
1137*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri5_drop_bcnt),
1138*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri6_drop_bcnt),
1139*4882a593Smuzhiyun GBENU_STATS_P1(tx_pri7_drop_bcnt),
1140*4882a593Smuzhiyun /* GBENU Module 2 */
1141*4882a593Smuzhiyun GBENU_STATS_P2(rx_good_frames),
1142*4882a593Smuzhiyun GBENU_STATS_P2(rx_broadcast_frames),
1143*4882a593Smuzhiyun GBENU_STATS_P2(rx_multicast_frames),
1144*4882a593Smuzhiyun GBENU_STATS_P2(rx_pause_frames),
1145*4882a593Smuzhiyun GBENU_STATS_P2(rx_crc_errors),
1146*4882a593Smuzhiyun GBENU_STATS_P2(rx_align_code_errors),
1147*4882a593Smuzhiyun GBENU_STATS_P2(rx_oversized_frames),
1148*4882a593Smuzhiyun GBENU_STATS_P2(rx_jabber_frames),
1149*4882a593Smuzhiyun GBENU_STATS_P2(rx_undersized_frames),
1150*4882a593Smuzhiyun GBENU_STATS_P2(rx_fragments),
1151*4882a593Smuzhiyun GBENU_STATS_P2(ale_drop),
1152*4882a593Smuzhiyun GBENU_STATS_P2(ale_overrun_drop),
1153*4882a593Smuzhiyun GBENU_STATS_P2(rx_bytes),
1154*4882a593Smuzhiyun GBENU_STATS_P2(tx_good_frames),
1155*4882a593Smuzhiyun GBENU_STATS_P2(tx_broadcast_frames),
1156*4882a593Smuzhiyun GBENU_STATS_P2(tx_multicast_frames),
1157*4882a593Smuzhiyun GBENU_STATS_P2(tx_pause_frames),
1158*4882a593Smuzhiyun GBENU_STATS_P2(tx_deferred_frames),
1159*4882a593Smuzhiyun GBENU_STATS_P2(tx_collision_frames),
1160*4882a593Smuzhiyun GBENU_STATS_P2(tx_single_coll_frames),
1161*4882a593Smuzhiyun GBENU_STATS_P2(tx_mult_coll_frames),
1162*4882a593Smuzhiyun GBENU_STATS_P2(tx_excessive_collisions),
1163*4882a593Smuzhiyun GBENU_STATS_P2(tx_late_collisions),
1164*4882a593Smuzhiyun GBENU_STATS_P2(rx_ipg_error),
1165*4882a593Smuzhiyun GBENU_STATS_P2(tx_carrier_sense_errors),
1166*4882a593Smuzhiyun GBENU_STATS_P2(tx_bytes),
1167*4882a593Smuzhiyun GBENU_STATS_P2(tx_64B_frames),
1168*4882a593Smuzhiyun GBENU_STATS_P2(tx_65_to_127B_frames),
1169*4882a593Smuzhiyun GBENU_STATS_P2(tx_128_to_255B_frames),
1170*4882a593Smuzhiyun GBENU_STATS_P2(tx_256_to_511B_frames),
1171*4882a593Smuzhiyun GBENU_STATS_P2(tx_512_to_1023B_frames),
1172*4882a593Smuzhiyun GBENU_STATS_P2(tx_1024B_frames),
1173*4882a593Smuzhiyun GBENU_STATS_P2(net_bytes),
1174*4882a593Smuzhiyun GBENU_STATS_P2(rx_bottom_fifo_drop),
1175*4882a593Smuzhiyun GBENU_STATS_P2(rx_port_mask_drop),
1176*4882a593Smuzhiyun GBENU_STATS_P2(rx_top_fifo_drop),
1177*4882a593Smuzhiyun GBENU_STATS_P2(ale_rate_limit_drop),
1178*4882a593Smuzhiyun GBENU_STATS_P2(ale_vid_ingress_drop),
1179*4882a593Smuzhiyun GBENU_STATS_P2(ale_da_eq_sa_drop),
1180*4882a593Smuzhiyun GBENU_STATS_P2(ale_unknown_ucast),
1181*4882a593Smuzhiyun GBENU_STATS_P2(ale_unknown_ucast_bytes),
1182*4882a593Smuzhiyun GBENU_STATS_P2(ale_unknown_mcast),
1183*4882a593Smuzhiyun GBENU_STATS_P2(ale_unknown_mcast_bytes),
1184*4882a593Smuzhiyun GBENU_STATS_P2(ale_unknown_bcast),
1185*4882a593Smuzhiyun GBENU_STATS_P2(ale_unknown_bcast_bytes),
1186*4882a593Smuzhiyun GBENU_STATS_P2(ale_pol_match),
1187*4882a593Smuzhiyun GBENU_STATS_P2(ale_pol_match_red),
1188*4882a593Smuzhiyun GBENU_STATS_P2(ale_pol_match_yellow),
1189*4882a593Smuzhiyun GBENU_STATS_P2(tx_mem_protect_err),
1190*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri0_drop),
1191*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri1_drop),
1192*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri2_drop),
1193*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri3_drop),
1194*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri4_drop),
1195*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri5_drop),
1196*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri6_drop),
1197*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri7_drop),
1198*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri0_drop_bcnt),
1199*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri1_drop_bcnt),
1200*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri2_drop_bcnt),
1201*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri3_drop_bcnt),
1202*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri4_drop_bcnt),
1203*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri5_drop_bcnt),
1204*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri6_drop_bcnt),
1205*4882a593Smuzhiyun GBENU_STATS_P2(tx_pri7_drop_bcnt),
1206*4882a593Smuzhiyun /* GBENU Module 3 */
1207*4882a593Smuzhiyun GBENU_STATS_P3(rx_good_frames),
1208*4882a593Smuzhiyun GBENU_STATS_P3(rx_broadcast_frames),
1209*4882a593Smuzhiyun GBENU_STATS_P3(rx_multicast_frames),
1210*4882a593Smuzhiyun GBENU_STATS_P3(rx_pause_frames),
1211*4882a593Smuzhiyun GBENU_STATS_P3(rx_crc_errors),
1212*4882a593Smuzhiyun GBENU_STATS_P3(rx_align_code_errors),
1213*4882a593Smuzhiyun GBENU_STATS_P3(rx_oversized_frames),
1214*4882a593Smuzhiyun GBENU_STATS_P3(rx_jabber_frames),
1215*4882a593Smuzhiyun GBENU_STATS_P3(rx_undersized_frames),
1216*4882a593Smuzhiyun GBENU_STATS_P3(rx_fragments),
1217*4882a593Smuzhiyun GBENU_STATS_P3(ale_drop),
1218*4882a593Smuzhiyun GBENU_STATS_P3(ale_overrun_drop),
1219*4882a593Smuzhiyun GBENU_STATS_P3(rx_bytes),
1220*4882a593Smuzhiyun GBENU_STATS_P3(tx_good_frames),
1221*4882a593Smuzhiyun GBENU_STATS_P3(tx_broadcast_frames),
1222*4882a593Smuzhiyun GBENU_STATS_P3(tx_multicast_frames),
1223*4882a593Smuzhiyun GBENU_STATS_P3(tx_pause_frames),
1224*4882a593Smuzhiyun GBENU_STATS_P3(tx_deferred_frames),
1225*4882a593Smuzhiyun GBENU_STATS_P3(tx_collision_frames),
1226*4882a593Smuzhiyun GBENU_STATS_P3(tx_single_coll_frames),
1227*4882a593Smuzhiyun GBENU_STATS_P3(tx_mult_coll_frames),
1228*4882a593Smuzhiyun GBENU_STATS_P3(tx_excessive_collisions),
1229*4882a593Smuzhiyun GBENU_STATS_P3(tx_late_collisions),
1230*4882a593Smuzhiyun GBENU_STATS_P3(rx_ipg_error),
1231*4882a593Smuzhiyun GBENU_STATS_P3(tx_carrier_sense_errors),
1232*4882a593Smuzhiyun GBENU_STATS_P3(tx_bytes),
1233*4882a593Smuzhiyun GBENU_STATS_P3(tx_64B_frames),
1234*4882a593Smuzhiyun GBENU_STATS_P3(tx_65_to_127B_frames),
1235*4882a593Smuzhiyun GBENU_STATS_P3(tx_128_to_255B_frames),
1236*4882a593Smuzhiyun GBENU_STATS_P3(tx_256_to_511B_frames),
1237*4882a593Smuzhiyun GBENU_STATS_P3(tx_512_to_1023B_frames),
1238*4882a593Smuzhiyun GBENU_STATS_P3(tx_1024B_frames),
1239*4882a593Smuzhiyun GBENU_STATS_P3(net_bytes),
1240*4882a593Smuzhiyun GBENU_STATS_P3(rx_bottom_fifo_drop),
1241*4882a593Smuzhiyun GBENU_STATS_P3(rx_port_mask_drop),
1242*4882a593Smuzhiyun GBENU_STATS_P3(rx_top_fifo_drop),
1243*4882a593Smuzhiyun GBENU_STATS_P3(ale_rate_limit_drop),
1244*4882a593Smuzhiyun GBENU_STATS_P3(ale_vid_ingress_drop),
1245*4882a593Smuzhiyun GBENU_STATS_P3(ale_da_eq_sa_drop),
1246*4882a593Smuzhiyun GBENU_STATS_P3(ale_unknown_ucast),
1247*4882a593Smuzhiyun GBENU_STATS_P3(ale_unknown_ucast_bytes),
1248*4882a593Smuzhiyun GBENU_STATS_P3(ale_unknown_mcast),
1249*4882a593Smuzhiyun GBENU_STATS_P3(ale_unknown_mcast_bytes),
1250*4882a593Smuzhiyun GBENU_STATS_P3(ale_unknown_bcast),
1251*4882a593Smuzhiyun GBENU_STATS_P3(ale_unknown_bcast_bytes),
1252*4882a593Smuzhiyun GBENU_STATS_P3(ale_pol_match),
1253*4882a593Smuzhiyun GBENU_STATS_P3(ale_pol_match_red),
1254*4882a593Smuzhiyun GBENU_STATS_P3(ale_pol_match_yellow),
1255*4882a593Smuzhiyun GBENU_STATS_P3(tx_mem_protect_err),
1256*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri0_drop),
1257*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri1_drop),
1258*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri2_drop),
1259*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri3_drop),
1260*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri4_drop),
1261*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri5_drop),
1262*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri6_drop),
1263*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri7_drop),
1264*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri0_drop_bcnt),
1265*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri1_drop_bcnt),
1266*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri2_drop_bcnt),
1267*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri3_drop_bcnt),
1268*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri4_drop_bcnt),
1269*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri5_drop_bcnt),
1270*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri6_drop_bcnt),
1271*4882a593Smuzhiyun GBENU_STATS_P3(tx_pri7_drop_bcnt),
1272*4882a593Smuzhiyun /* GBENU Module 4 */
1273*4882a593Smuzhiyun GBENU_STATS_P4(rx_good_frames),
1274*4882a593Smuzhiyun GBENU_STATS_P4(rx_broadcast_frames),
1275*4882a593Smuzhiyun GBENU_STATS_P4(rx_multicast_frames),
1276*4882a593Smuzhiyun GBENU_STATS_P4(rx_pause_frames),
1277*4882a593Smuzhiyun GBENU_STATS_P4(rx_crc_errors),
1278*4882a593Smuzhiyun GBENU_STATS_P4(rx_align_code_errors),
1279*4882a593Smuzhiyun GBENU_STATS_P4(rx_oversized_frames),
1280*4882a593Smuzhiyun GBENU_STATS_P4(rx_jabber_frames),
1281*4882a593Smuzhiyun GBENU_STATS_P4(rx_undersized_frames),
1282*4882a593Smuzhiyun GBENU_STATS_P4(rx_fragments),
1283*4882a593Smuzhiyun GBENU_STATS_P4(ale_drop),
1284*4882a593Smuzhiyun GBENU_STATS_P4(ale_overrun_drop),
1285*4882a593Smuzhiyun GBENU_STATS_P4(rx_bytes),
1286*4882a593Smuzhiyun GBENU_STATS_P4(tx_good_frames),
1287*4882a593Smuzhiyun GBENU_STATS_P4(tx_broadcast_frames),
1288*4882a593Smuzhiyun GBENU_STATS_P4(tx_multicast_frames),
1289*4882a593Smuzhiyun GBENU_STATS_P4(tx_pause_frames),
1290*4882a593Smuzhiyun GBENU_STATS_P4(tx_deferred_frames),
1291*4882a593Smuzhiyun GBENU_STATS_P4(tx_collision_frames),
1292*4882a593Smuzhiyun GBENU_STATS_P4(tx_single_coll_frames),
1293*4882a593Smuzhiyun GBENU_STATS_P4(tx_mult_coll_frames),
1294*4882a593Smuzhiyun GBENU_STATS_P4(tx_excessive_collisions),
1295*4882a593Smuzhiyun GBENU_STATS_P4(tx_late_collisions),
1296*4882a593Smuzhiyun GBENU_STATS_P4(rx_ipg_error),
1297*4882a593Smuzhiyun GBENU_STATS_P4(tx_carrier_sense_errors),
1298*4882a593Smuzhiyun GBENU_STATS_P4(tx_bytes),
1299*4882a593Smuzhiyun GBENU_STATS_P4(tx_64B_frames),
1300*4882a593Smuzhiyun GBENU_STATS_P4(tx_65_to_127B_frames),
1301*4882a593Smuzhiyun GBENU_STATS_P4(tx_128_to_255B_frames),
1302*4882a593Smuzhiyun GBENU_STATS_P4(tx_256_to_511B_frames),
1303*4882a593Smuzhiyun GBENU_STATS_P4(tx_512_to_1023B_frames),
1304*4882a593Smuzhiyun GBENU_STATS_P4(tx_1024B_frames),
1305*4882a593Smuzhiyun GBENU_STATS_P4(net_bytes),
1306*4882a593Smuzhiyun GBENU_STATS_P4(rx_bottom_fifo_drop),
1307*4882a593Smuzhiyun GBENU_STATS_P4(rx_port_mask_drop),
1308*4882a593Smuzhiyun GBENU_STATS_P4(rx_top_fifo_drop),
1309*4882a593Smuzhiyun GBENU_STATS_P4(ale_rate_limit_drop),
1310*4882a593Smuzhiyun GBENU_STATS_P4(ale_vid_ingress_drop),
1311*4882a593Smuzhiyun GBENU_STATS_P4(ale_da_eq_sa_drop),
1312*4882a593Smuzhiyun GBENU_STATS_P4(ale_unknown_ucast),
1313*4882a593Smuzhiyun GBENU_STATS_P4(ale_unknown_ucast_bytes),
1314*4882a593Smuzhiyun GBENU_STATS_P4(ale_unknown_mcast),
1315*4882a593Smuzhiyun GBENU_STATS_P4(ale_unknown_mcast_bytes),
1316*4882a593Smuzhiyun GBENU_STATS_P4(ale_unknown_bcast),
1317*4882a593Smuzhiyun GBENU_STATS_P4(ale_unknown_bcast_bytes),
1318*4882a593Smuzhiyun GBENU_STATS_P4(ale_pol_match),
1319*4882a593Smuzhiyun GBENU_STATS_P4(ale_pol_match_red),
1320*4882a593Smuzhiyun GBENU_STATS_P4(ale_pol_match_yellow),
1321*4882a593Smuzhiyun GBENU_STATS_P4(tx_mem_protect_err),
1322*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri0_drop),
1323*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri1_drop),
1324*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri2_drop),
1325*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri3_drop),
1326*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri4_drop),
1327*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri5_drop),
1328*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri6_drop),
1329*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri7_drop),
1330*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri0_drop_bcnt),
1331*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri1_drop_bcnt),
1332*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri2_drop_bcnt),
1333*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri3_drop_bcnt),
1334*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri4_drop_bcnt),
1335*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri5_drop_bcnt),
1336*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri6_drop_bcnt),
1337*4882a593Smuzhiyun GBENU_STATS_P4(tx_pri7_drop_bcnt),
1338*4882a593Smuzhiyun /* GBENU Module 5 */
1339*4882a593Smuzhiyun GBENU_STATS_P5(rx_good_frames),
1340*4882a593Smuzhiyun GBENU_STATS_P5(rx_broadcast_frames),
1341*4882a593Smuzhiyun GBENU_STATS_P5(rx_multicast_frames),
1342*4882a593Smuzhiyun GBENU_STATS_P5(rx_pause_frames),
1343*4882a593Smuzhiyun GBENU_STATS_P5(rx_crc_errors),
1344*4882a593Smuzhiyun GBENU_STATS_P5(rx_align_code_errors),
1345*4882a593Smuzhiyun GBENU_STATS_P5(rx_oversized_frames),
1346*4882a593Smuzhiyun GBENU_STATS_P5(rx_jabber_frames),
1347*4882a593Smuzhiyun GBENU_STATS_P5(rx_undersized_frames),
1348*4882a593Smuzhiyun GBENU_STATS_P5(rx_fragments),
1349*4882a593Smuzhiyun GBENU_STATS_P5(ale_drop),
1350*4882a593Smuzhiyun GBENU_STATS_P5(ale_overrun_drop),
1351*4882a593Smuzhiyun GBENU_STATS_P5(rx_bytes),
1352*4882a593Smuzhiyun GBENU_STATS_P5(tx_good_frames),
1353*4882a593Smuzhiyun GBENU_STATS_P5(tx_broadcast_frames),
1354*4882a593Smuzhiyun GBENU_STATS_P5(tx_multicast_frames),
1355*4882a593Smuzhiyun GBENU_STATS_P5(tx_pause_frames),
1356*4882a593Smuzhiyun GBENU_STATS_P5(tx_deferred_frames),
1357*4882a593Smuzhiyun GBENU_STATS_P5(tx_collision_frames),
1358*4882a593Smuzhiyun GBENU_STATS_P5(tx_single_coll_frames),
1359*4882a593Smuzhiyun GBENU_STATS_P5(tx_mult_coll_frames),
1360*4882a593Smuzhiyun GBENU_STATS_P5(tx_excessive_collisions),
1361*4882a593Smuzhiyun GBENU_STATS_P5(tx_late_collisions),
1362*4882a593Smuzhiyun GBENU_STATS_P5(rx_ipg_error),
1363*4882a593Smuzhiyun GBENU_STATS_P5(tx_carrier_sense_errors),
1364*4882a593Smuzhiyun GBENU_STATS_P5(tx_bytes),
1365*4882a593Smuzhiyun GBENU_STATS_P5(tx_64B_frames),
1366*4882a593Smuzhiyun GBENU_STATS_P5(tx_65_to_127B_frames),
1367*4882a593Smuzhiyun GBENU_STATS_P5(tx_128_to_255B_frames),
1368*4882a593Smuzhiyun GBENU_STATS_P5(tx_256_to_511B_frames),
1369*4882a593Smuzhiyun GBENU_STATS_P5(tx_512_to_1023B_frames),
1370*4882a593Smuzhiyun GBENU_STATS_P5(tx_1024B_frames),
1371*4882a593Smuzhiyun GBENU_STATS_P5(net_bytes),
1372*4882a593Smuzhiyun GBENU_STATS_P5(rx_bottom_fifo_drop),
1373*4882a593Smuzhiyun GBENU_STATS_P5(rx_port_mask_drop),
1374*4882a593Smuzhiyun GBENU_STATS_P5(rx_top_fifo_drop),
1375*4882a593Smuzhiyun GBENU_STATS_P5(ale_rate_limit_drop),
1376*4882a593Smuzhiyun GBENU_STATS_P5(ale_vid_ingress_drop),
1377*4882a593Smuzhiyun GBENU_STATS_P5(ale_da_eq_sa_drop),
1378*4882a593Smuzhiyun GBENU_STATS_P5(ale_unknown_ucast),
1379*4882a593Smuzhiyun GBENU_STATS_P5(ale_unknown_ucast_bytes),
1380*4882a593Smuzhiyun GBENU_STATS_P5(ale_unknown_mcast),
1381*4882a593Smuzhiyun GBENU_STATS_P5(ale_unknown_mcast_bytes),
1382*4882a593Smuzhiyun GBENU_STATS_P5(ale_unknown_bcast),
1383*4882a593Smuzhiyun GBENU_STATS_P5(ale_unknown_bcast_bytes),
1384*4882a593Smuzhiyun GBENU_STATS_P5(ale_pol_match),
1385*4882a593Smuzhiyun GBENU_STATS_P5(ale_pol_match_red),
1386*4882a593Smuzhiyun GBENU_STATS_P5(ale_pol_match_yellow),
1387*4882a593Smuzhiyun GBENU_STATS_P5(tx_mem_protect_err),
1388*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri0_drop),
1389*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri1_drop),
1390*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri2_drop),
1391*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri3_drop),
1392*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri4_drop),
1393*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri5_drop),
1394*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri6_drop),
1395*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri7_drop),
1396*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri0_drop_bcnt),
1397*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri1_drop_bcnt),
1398*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri2_drop_bcnt),
1399*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri3_drop_bcnt),
1400*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri4_drop_bcnt),
1401*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri5_drop_bcnt),
1402*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri6_drop_bcnt),
1403*4882a593Smuzhiyun GBENU_STATS_P5(tx_pri7_drop_bcnt),
1404*4882a593Smuzhiyun /* GBENU Module 6 */
1405*4882a593Smuzhiyun GBENU_STATS_P6(rx_good_frames),
1406*4882a593Smuzhiyun GBENU_STATS_P6(rx_broadcast_frames),
1407*4882a593Smuzhiyun GBENU_STATS_P6(rx_multicast_frames),
1408*4882a593Smuzhiyun GBENU_STATS_P6(rx_pause_frames),
1409*4882a593Smuzhiyun GBENU_STATS_P6(rx_crc_errors),
1410*4882a593Smuzhiyun GBENU_STATS_P6(rx_align_code_errors),
1411*4882a593Smuzhiyun GBENU_STATS_P6(rx_oversized_frames),
1412*4882a593Smuzhiyun GBENU_STATS_P6(rx_jabber_frames),
1413*4882a593Smuzhiyun GBENU_STATS_P6(rx_undersized_frames),
1414*4882a593Smuzhiyun GBENU_STATS_P6(rx_fragments),
1415*4882a593Smuzhiyun GBENU_STATS_P6(ale_drop),
1416*4882a593Smuzhiyun GBENU_STATS_P6(ale_overrun_drop),
1417*4882a593Smuzhiyun GBENU_STATS_P6(rx_bytes),
1418*4882a593Smuzhiyun GBENU_STATS_P6(tx_good_frames),
1419*4882a593Smuzhiyun GBENU_STATS_P6(tx_broadcast_frames),
1420*4882a593Smuzhiyun GBENU_STATS_P6(tx_multicast_frames),
1421*4882a593Smuzhiyun GBENU_STATS_P6(tx_pause_frames),
1422*4882a593Smuzhiyun GBENU_STATS_P6(tx_deferred_frames),
1423*4882a593Smuzhiyun GBENU_STATS_P6(tx_collision_frames),
1424*4882a593Smuzhiyun GBENU_STATS_P6(tx_single_coll_frames),
1425*4882a593Smuzhiyun GBENU_STATS_P6(tx_mult_coll_frames),
1426*4882a593Smuzhiyun GBENU_STATS_P6(tx_excessive_collisions),
1427*4882a593Smuzhiyun GBENU_STATS_P6(tx_late_collisions),
1428*4882a593Smuzhiyun GBENU_STATS_P6(rx_ipg_error),
1429*4882a593Smuzhiyun GBENU_STATS_P6(tx_carrier_sense_errors),
1430*4882a593Smuzhiyun GBENU_STATS_P6(tx_bytes),
1431*4882a593Smuzhiyun GBENU_STATS_P6(tx_64B_frames),
1432*4882a593Smuzhiyun GBENU_STATS_P6(tx_65_to_127B_frames),
1433*4882a593Smuzhiyun GBENU_STATS_P6(tx_128_to_255B_frames),
1434*4882a593Smuzhiyun GBENU_STATS_P6(tx_256_to_511B_frames),
1435*4882a593Smuzhiyun GBENU_STATS_P6(tx_512_to_1023B_frames),
1436*4882a593Smuzhiyun GBENU_STATS_P6(tx_1024B_frames),
1437*4882a593Smuzhiyun GBENU_STATS_P6(net_bytes),
1438*4882a593Smuzhiyun GBENU_STATS_P6(rx_bottom_fifo_drop),
1439*4882a593Smuzhiyun GBENU_STATS_P6(rx_port_mask_drop),
1440*4882a593Smuzhiyun GBENU_STATS_P6(rx_top_fifo_drop),
1441*4882a593Smuzhiyun GBENU_STATS_P6(ale_rate_limit_drop),
1442*4882a593Smuzhiyun GBENU_STATS_P6(ale_vid_ingress_drop),
1443*4882a593Smuzhiyun GBENU_STATS_P6(ale_da_eq_sa_drop),
1444*4882a593Smuzhiyun GBENU_STATS_P6(ale_unknown_ucast),
1445*4882a593Smuzhiyun GBENU_STATS_P6(ale_unknown_ucast_bytes),
1446*4882a593Smuzhiyun GBENU_STATS_P6(ale_unknown_mcast),
1447*4882a593Smuzhiyun GBENU_STATS_P6(ale_unknown_mcast_bytes),
1448*4882a593Smuzhiyun GBENU_STATS_P6(ale_unknown_bcast),
1449*4882a593Smuzhiyun GBENU_STATS_P6(ale_unknown_bcast_bytes),
1450*4882a593Smuzhiyun GBENU_STATS_P6(ale_pol_match),
1451*4882a593Smuzhiyun GBENU_STATS_P6(ale_pol_match_red),
1452*4882a593Smuzhiyun GBENU_STATS_P6(ale_pol_match_yellow),
1453*4882a593Smuzhiyun GBENU_STATS_P6(tx_mem_protect_err),
1454*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri0_drop),
1455*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri1_drop),
1456*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri2_drop),
1457*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri3_drop),
1458*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri4_drop),
1459*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri5_drop),
1460*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri6_drop),
1461*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri7_drop),
1462*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri0_drop_bcnt),
1463*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri1_drop_bcnt),
1464*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri2_drop_bcnt),
1465*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri3_drop_bcnt),
1466*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri4_drop_bcnt),
1467*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri5_drop_bcnt),
1468*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri6_drop_bcnt),
1469*4882a593Smuzhiyun GBENU_STATS_P6(tx_pri7_drop_bcnt),
1470*4882a593Smuzhiyun /* GBENU Module 7 */
1471*4882a593Smuzhiyun GBENU_STATS_P7(rx_good_frames),
1472*4882a593Smuzhiyun GBENU_STATS_P7(rx_broadcast_frames),
1473*4882a593Smuzhiyun GBENU_STATS_P7(rx_multicast_frames),
1474*4882a593Smuzhiyun GBENU_STATS_P7(rx_pause_frames),
1475*4882a593Smuzhiyun GBENU_STATS_P7(rx_crc_errors),
1476*4882a593Smuzhiyun GBENU_STATS_P7(rx_align_code_errors),
1477*4882a593Smuzhiyun GBENU_STATS_P7(rx_oversized_frames),
1478*4882a593Smuzhiyun GBENU_STATS_P7(rx_jabber_frames),
1479*4882a593Smuzhiyun GBENU_STATS_P7(rx_undersized_frames),
1480*4882a593Smuzhiyun GBENU_STATS_P7(rx_fragments),
1481*4882a593Smuzhiyun GBENU_STATS_P7(ale_drop),
1482*4882a593Smuzhiyun GBENU_STATS_P7(ale_overrun_drop),
1483*4882a593Smuzhiyun GBENU_STATS_P7(rx_bytes),
1484*4882a593Smuzhiyun GBENU_STATS_P7(tx_good_frames),
1485*4882a593Smuzhiyun GBENU_STATS_P7(tx_broadcast_frames),
1486*4882a593Smuzhiyun GBENU_STATS_P7(tx_multicast_frames),
1487*4882a593Smuzhiyun GBENU_STATS_P7(tx_pause_frames),
1488*4882a593Smuzhiyun GBENU_STATS_P7(tx_deferred_frames),
1489*4882a593Smuzhiyun GBENU_STATS_P7(tx_collision_frames),
1490*4882a593Smuzhiyun GBENU_STATS_P7(tx_single_coll_frames),
1491*4882a593Smuzhiyun GBENU_STATS_P7(tx_mult_coll_frames),
1492*4882a593Smuzhiyun GBENU_STATS_P7(tx_excessive_collisions),
1493*4882a593Smuzhiyun GBENU_STATS_P7(tx_late_collisions),
1494*4882a593Smuzhiyun GBENU_STATS_P7(rx_ipg_error),
1495*4882a593Smuzhiyun GBENU_STATS_P7(tx_carrier_sense_errors),
1496*4882a593Smuzhiyun GBENU_STATS_P7(tx_bytes),
1497*4882a593Smuzhiyun GBENU_STATS_P7(tx_64B_frames),
1498*4882a593Smuzhiyun GBENU_STATS_P7(tx_65_to_127B_frames),
1499*4882a593Smuzhiyun GBENU_STATS_P7(tx_128_to_255B_frames),
1500*4882a593Smuzhiyun GBENU_STATS_P7(tx_256_to_511B_frames),
1501*4882a593Smuzhiyun GBENU_STATS_P7(tx_512_to_1023B_frames),
1502*4882a593Smuzhiyun GBENU_STATS_P7(tx_1024B_frames),
1503*4882a593Smuzhiyun GBENU_STATS_P7(net_bytes),
1504*4882a593Smuzhiyun GBENU_STATS_P7(rx_bottom_fifo_drop),
1505*4882a593Smuzhiyun GBENU_STATS_P7(rx_port_mask_drop),
1506*4882a593Smuzhiyun GBENU_STATS_P7(rx_top_fifo_drop),
1507*4882a593Smuzhiyun GBENU_STATS_P7(ale_rate_limit_drop),
1508*4882a593Smuzhiyun GBENU_STATS_P7(ale_vid_ingress_drop),
1509*4882a593Smuzhiyun GBENU_STATS_P7(ale_da_eq_sa_drop),
1510*4882a593Smuzhiyun GBENU_STATS_P7(ale_unknown_ucast),
1511*4882a593Smuzhiyun GBENU_STATS_P7(ale_unknown_ucast_bytes),
1512*4882a593Smuzhiyun GBENU_STATS_P7(ale_unknown_mcast),
1513*4882a593Smuzhiyun GBENU_STATS_P7(ale_unknown_mcast_bytes),
1514*4882a593Smuzhiyun GBENU_STATS_P7(ale_unknown_bcast),
1515*4882a593Smuzhiyun GBENU_STATS_P7(ale_unknown_bcast_bytes),
1516*4882a593Smuzhiyun GBENU_STATS_P7(ale_pol_match),
1517*4882a593Smuzhiyun GBENU_STATS_P7(ale_pol_match_red),
1518*4882a593Smuzhiyun GBENU_STATS_P7(ale_pol_match_yellow),
1519*4882a593Smuzhiyun GBENU_STATS_P7(tx_mem_protect_err),
1520*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri0_drop),
1521*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri1_drop),
1522*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri2_drop),
1523*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri3_drop),
1524*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri4_drop),
1525*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri5_drop),
1526*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri6_drop),
1527*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri7_drop),
1528*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri0_drop_bcnt),
1529*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri1_drop_bcnt),
1530*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri2_drop_bcnt),
1531*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri3_drop_bcnt),
1532*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri4_drop_bcnt),
1533*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri5_drop_bcnt),
1534*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri6_drop_bcnt),
1535*4882a593Smuzhiyun GBENU_STATS_P7(tx_pri7_drop_bcnt),
1536*4882a593Smuzhiyun /* GBENU Module 8 */
1537*4882a593Smuzhiyun GBENU_STATS_P8(rx_good_frames),
1538*4882a593Smuzhiyun GBENU_STATS_P8(rx_broadcast_frames),
1539*4882a593Smuzhiyun GBENU_STATS_P8(rx_multicast_frames),
1540*4882a593Smuzhiyun GBENU_STATS_P8(rx_pause_frames),
1541*4882a593Smuzhiyun GBENU_STATS_P8(rx_crc_errors),
1542*4882a593Smuzhiyun GBENU_STATS_P8(rx_align_code_errors),
1543*4882a593Smuzhiyun GBENU_STATS_P8(rx_oversized_frames),
1544*4882a593Smuzhiyun GBENU_STATS_P8(rx_jabber_frames),
1545*4882a593Smuzhiyun GBENU_STATS_P8(rx_undersized_frames),
1546*4882a593Smuzhiyun GBENU_STATS_P8(rx_fragments),
1547*4882a593Smuzhiyun GBENU_STATS_P8(ale_drop),
1548*4882a593Smuzhiyun GBENU_STATS_P8(ale_overrun_drop),
1549*4882a593Smuzhiyun GBENU_STATS_P8(rx_bytes),
1550*4882a593Smuzhiyun GBENU_STATS_P8(tx_good_frames),
1551*4882a593Smuzhiyun GBENU_STATS_P8(tx_broadcast_frames),
1552*4882a593Smuzhiyun GBENU_STATS_P8(tx_multicast_frames),
1553*4882a593Smuzhiyun GBENU_STATS_P8(tx_pause_frames),
1554*4882a593Smuzhiyun GBENU_STATS_P8(tx_deferred_frames),
1555*4882a593Smuzhiyun GBENU_STATS_P8(tx_collision_frames),
1556*4882a593Smuzhiyun GBENU_STATS_P8(tx_single_coll_frames),
1557*4882a593Smuzhiyun GBENU_STATS_P8(tx_mult_coll_frames),
1558*4882a593Smuzhiyun GBENU_STATS_P8(tx_excessive_collisions),
1559*4882a593Smuzhiyun GBENU_STATS_P8(tx_late_collisions),
1560*4882a593Smuzhiyun GBENU_STATS_P8(rx_ipg_error),
1561*4882a593Smuzhiyun GBENU_STATS_P8(tx_carrier_sense_errors),
1562*4882a593Smuzhiyun GBENU_STATS_P8(tx_bytes),
1563*4882a593Smuzhiyun GBENU_STATS_P8(tx_64B_frames),
1564*4882a593Smuzhiyun GBENU_STATS_P8(tx_65_to_127B_frames),
1565*4882a593Smuzhiyun GBENU_STATS_P8(tx_128_to_255B_frames),
1566*4882a593Smuzhiyun GBENU_STATS_P8(tx_256_to_511B_frames),
1567*4882a593Smuzhiyun GBENU_STATS_P8(tx_512_to_1023B_frames),
1568*4882a593Smuzhiyun GBENU_STATS_P8(tx_1024B_frames),
1569*4882a593Smuzhiyun GBENU_STATS_P8(net_bytes),
1570*4882a593Smuzhiyun GBENU_STATS_P8(rx_bottom_fifo_drop),
1571*4882a593Smuzhiyun GBENU_STATS_P8(rx_port_mask_drop),
1572*4882a593Smuzhiyun GBENU_STATS_P8(rx_top_fifo_drop),
1573*4882a593Smuzhiyun GBENU_STATS_P8(ale_rate_limit_drop),
1574*4882a593Smuzhiyun GBENU_STATS_P8(ale_vid_ingress_drop),
1575*4882a593Smuzhiyun GBENU_STATS_P8(ale_da_eq_sa_drop),
1576*4882a593Smuzhiyun GBENU_STATS_P8(ale_unknown_ucast),
1577*4882a593Smuzhiyun GBENU_STATS_P8(ale_unknown_ucast_bytes),
1578*4882a593Smuzhiyun GBENU_STATS_P8(ale_unknown_mcast),
1579*4882a593Smuzhiyun GBENU_STATS_P8(ale_unknown_mcast_bytes),
1580*4882a593Smuzhiyun GBENU_STATS_P8(ale_unknown_bcast),
1581*4882a593Smuzhiyun GBENU_STATS_P8(ale_unknown_bcast_bytes),
1582*4882a593Smuzhiyun GBENU_STATS_P8(ale_pol_match),
1583*4882a593Smuzhiyun GBENU_STATS_P8(ale_pol_match_red),
1584*4882a593Smuzhiyun GBENU_STATS_P8(ale_pol_match_yellow),
1585*4882a593Smuzhiyun GBENU_STATS_P8(tx_mem_protect_err),
1586*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri0_drop),
1587*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri1_drop),
1588*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri2_drop),
1589*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri3_drop),
1590*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri4_drop),
1591*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri5_drop),
1592*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri6_drop),
1593*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri7_drop),
1594*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri0_drop_bcnt),
1595*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri1_drop_bcnt),
1596*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri2_drop_bcnt),
1597*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri3_drop_bcnt),
1598*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri4_drop_bcnt),
1599*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri5_drop_bcnt),
1600*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri6_drop_bcnt),
1601*4882a593Smuzhiyun GBENU_STATS_P8(tx_pri7_drop_bcnt),
1602*4882a593Smuzhiyun };
1603*4882a593Smuzhiyun
1604*4882a593Smuzhiyun #define XGBE_STATS0_INFO(field) \
1605*4882a593Smuzhiyun { \
1606*4882a593Smuzhiyun "GBE_0:"#field, XGBE_STATS0_MODULE, \
1607*4882a593Smuzhiyun sizeof_field(struct xgbe_hw_stats, field), \
1608*4882a593Smuzhiyun offsetof(struct xgbe_hw_stats, field) \
1609*4882a593Smuzhiyun }
1610*4882a593Smuzhiyun
1611*4882a593Smuzhiyun #define XGBE_STATS1_INFO(field) \
1612*4882a593Smuzhiyun { \
1613*4882a593Smuzhiyun "GBE_1:"#field, XGBE_STATS1_MODULE, \
1614*4882a593Smuzhiyun sizeof_field(struct xgbe_hw_stats, field), \
1615*4882a593Smuzhiyun offsetof(struct xgbe_hw_stats, field) \
1616*4882a593Smuzhiyun }
1617*4882a593Smuzhiyun
1618*4882a593Smuzhiyun #define XGBE_STATS2_INFO(field) \
1619*4882a593Smuzhiyun { \
1620*4882a593Smuzhiyun "GBE_2:"#field, XGBE_STATS2_MODULE, \
1621*4882a593Smuzhiyun sizeof_field(struct xgbe_hw_stats, field), \
1622*4882a593Smuzhiyun offsetof(struct xgbe_hw_stats, field) \
1623*4882a593Smuzhiyun }
1624*4882a593Smuzhiyun
1625*4882a593Smuzhiyun static const struct netcp_ethtool_stat xgbe10_et_stats[] = {
1626*4882a593Smuzhiyun /* GBE module 0 */
1627*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_good_frames),
1628*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_broadcast_frames),
1629*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_multicast_frames),
1630*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_oversized_frames),
1631*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_undersized_frames),
1632*4882a593Smuzhiyun XGBE_STATS0_INFO(overrun_type4),
1633*4882a593Smuzhiyun XGBE_STATS0_INFO(overrun_type5),
1634*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_bytes),
1635*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_good_frames),
1636*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_broadcast_frames),
1637*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_multicast_frames),
1638*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_bytes),
1639*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_64byte_frames),
1640*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_65_to_127byte_frames),
1641*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_128_to_255byte_frames),
1642*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_256_to_511byte_frames),
1643*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_512_to_1023byte_frames),
1644*4882a593Smuzhiyun XGBE_STATS0_INFO(tx_1024byte_frames),
1645*4882a593Smuzhiyun XGBE_STATS0_INFO(net_bytes),
1646*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_sof_overruns),
1647*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_mof_overruns),
1648*4882a593Smuzhiyun XGBE_STATS0_INFO(rx_dma_overruns),
1649*4882a593Smuzhiyun /* XGBE module 1 */
1650*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_good_frames),
1651*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_broadcast_frames),
1652*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_multicast_frames),
1653*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_pause_frames),
1654*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_crc_errors),
1655*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_align_code_errors),
1656*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_oversized_frames),
1657*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_jabber_frames),
1658*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_undersized_frames),
1659*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_fragments),
1660*4882a593Smuzhiyun XGBE_STATS1_INFO(overrun_type4),
1661*4882a593Smuzhiyun XGBE_STATS1_INFO(overrun_type5),
1662*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_bytes),
1663*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_good_frames),
1664*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_broadcast_frames),
1665*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_multicast_frames),
1666*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_pause_frames),
1667*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_deferred_frames),
1668*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_collision_frames),
1669*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_single_coll_frames),
1670*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_mult_coll_frames),
1671*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_excessive_collisions),
1672*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_late_collisions),
1673*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_underrun),
1674*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_carrier_sense_errors),
1675*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_bytes),
1676*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_64byte_frames),
1677*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_65_to_127byte_frames),
1678*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_128_to_255byte_frames),
1679*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_256_to_511byte_frames),
1680*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_512_to_1023byte_frames),
1681*4882a593Smuzhiyun XGBE_STATS1_INFO(tx_1024byte_frames),
1682*4882a593Smuzhiyun XGBE_STATS1_INFO(net_bytes),
1683*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_sof_overruns),
1684*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_mof_overruns),
1685*4882a593Smuzhiyun XGBE_STATS1_INFO(rx_dma_overruns),
1686*4882a593Smuzhiyun /* XGBE module 2 */
1687*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_good_frames),
1688*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_broadcast_frames),
1689*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_multicast_frames),
1690*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_pause_frames),
1691*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_crc_errors),
1692*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_align_code_errors),
1693*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_oversized_frames),
1694*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_jabber_frames),
1695*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_undersized_frames),
1696*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_fragments),
1697*4882a593Smuzhiyun XGBE_STATS2_INFO(overrun_type4),
1698*4882a593Smuzhiyun XGBE_STATS2_INFO(overrun_type5),
1699*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_bytes),
1700*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_good_frames),
1701*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_broadcast_frames),
1702*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_multicast_frames),
1703*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_pause_frames),
1704*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_deferred_frames),
1705*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_collision_frames),
1706*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_single_coll_frames),
1707*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_mult_coll_frames),
1708*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_excessive_collisions),
1709*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_late_collisions),
1710*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_underrun),
1711*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_carrier_sense_errors),
1712*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_bytes),
1713*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_64byte_frames),
1714*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_65_to_127byte_frames),
1715*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_128_to_255byte_frames),
1716*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_256_to_511byte_frames),
1717*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_512_to_1023byte_frames),
1718*4882a593Smuzhiyun XGBE_STATS2_INFO(tx_1024byte_frames),
1719*4882a593Smuzhiyun XGBE_STATS2_INFO(net_bytes),
1720*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_sof_overruns),
1721*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_mof_overruns),
1722*4882a593Smuzhiyun XGBE_STATS2_INFO(rx_dma_overruns),
1723*4882a593Smuzhiyun };
1724*4882a593Smuzhiyun
1725*4882a593Smuzhiyun #define for_each_intf(i, priv) \
1726*4882a593Smuzhiyun list_for_each_entry((i), &(priv)->gbe_intf_head, gbe_intf_list)
1727*4882a593Smuzhiyun
1728*4882a593Smuzhiyun #define for_each_sec_slave(slave, priv) \
1729*4882a593Smuzhiyun list_for_each_entry((slave), &(priv)->secondary_slaves, slave_list)
1730*4882a593Smuzhiyun
1731*4882a593Smuzhiyun #define first_sec_slave(priv) \
1732*4882a593Smuzhiyun list_first_entry(&priv->secondary_slaves, \
1733*4882a593Smuzhiyun struct gbe_slave, slave_list)
1734*4882a593Smuzhiyun
keystone_get_drvinfo(struct net_device * ndev,struct ethtool_drvinfo * info)1735*4882a593Smuzhiyun static void keystone_get_drvinfo(struct net_device *ndev,
1736*4882a593Smuzhiyun struct ethtool_drvinfo *info)
1737*4882a593Smuzhiyun {
1738*4882a593Smuzhiyun strncpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver));
1739*4882a593Smuzhiyun strncpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version));
1740*4882a593Smuzhiyun }
1741*4882a593Smuzhiyun
keystone_get_msglevel(struct net_device * ndev)1742*4882a593Smuzhiyun static u32 keystone_get_msglevel(struct net_device *ndev)
1743*4882a593Smuzhiyun {
1744*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
1745*4882a593Smuzhiyun
1746*4882a593Smuzhiyun return netcp->msg_enable;
1747*4882a593Smuzhiyun }
1748*4882a593Smuzhiyun
keystone_set_msglevel(struct net_device * ndev,u32 value)1749*4882a593Smuzhiyun static void keystone_set_msglevel(struct net_device *ndev, u32 value)
1750*4882a593Smuzhiyun {
1751*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
1752*4882a593Smuzhiyun
1753*4882a593Smuzhiyun netcp->msg_enable = value;
1754*4882a593Smuzhiyun }
1755*4882a593Smuzhiyun
keystone_get_intf_data(struct netcp_intf * netcp)1756*4882a593Smuzhiyun static struct gbe_intf *keystone_get_intf_data(struct netcp_intf *netcp)
1757*4882a593Smuzhiyun {
1758*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
1759*4882a593Smuzhiyun
1760*4882a593Smuzhiyun gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
1761*4882a593Smuzhiyun if (!gbe_intf)
1762*4882a593Smuzhiyun gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp);
1763*4882a593Smuzhiyun
1764*4882a593Smuzhiyun return gbe_intf;
1765*4882a593Smuzhiyun }
1766*4882a593Smuzhiyun
keystone_get_stat_strings(struct net_device * ndev,uint32_t stringset,uint8_t * data)1767*4882a593Smuzhiyun static void keystone_get_stat_strings(struct net_device *ndev,
1768*4882a593Smuzhiyun uint32_t stringset, uint8_t *data)
1769*4882a593Smuzhiyun {
1770*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
1771*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
1772*4882a593Smuzhiyun struct gbe_priv *gbe_dev;
1773*4882a593Smuzhiyun int i;
1774*4882a593Smuzhiyun
1775*4882a593Smuzhiyun gbe_intf = keystone_get_intf_data(netcp);
1776*4882a593Smuzhiyun if (!gbe_intf)
1777*4882a593Smuzhiyun return;
1778*4882a593Smuzhiyun gbe_dev = gbe_intf->gbe_dev;
1779*4882a593Smuzhiyun
1780*4882a593Smuzhiyun switch (stringset) {
1781*4882a593Smuzhiyun case ETH_SS_STATS:
1782*4882a593Smuzhiyun for (i = 0; i < gbe_dev->num_et_stats; i++) {
1783*4882a593Smuzhiyun memcpy(data, gbe_dev->et_stats[i].desc,
1784*4882a593Smuzhiyun ETH_GSTRING_LEN);
1785*4882a593Smuzhiyun data += ETH_GSTRING_LEN;
1786*4882a593Smuzhiyun }
1787*4882a593Smuzhiyun break;
1788*4882a593Smuzhiyun case ETH_SS_TEST:
1789*4882a593Smuzhiyun break;
1790*4882a593Smuzhiyun }
1791*4882a593Smuzhiyun }
1792*4882a593Smuzhiyun
keystone_get_sset_count(struct net_device * ndev,int stringset)1793*4882a593Smuzhiyun static int keystone_get_sset_count(struct net_device *ndev, int stringset)
1794*4882a593Smuzhiyun {
1795*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
1796*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
1797*4882a593Smuzhiyun struct gbe_priv *gbe_dev;
1798*4882a593Smuzhiyun
1799*4882a593Smuzhiyun gbe_intf = keystone_get_intf_data(netcp);
1800*4882a593Smuzhiyun if (!gbe_intf)
1801*4882a593Smuzhiyun return -EINVAL;
1802*4882a593Smuzhiyun gbe_dev = gbe_intf->gbe_dev;
1803*4882a593Smuzhiyun
1804*4882a593Smuzhiyun switch (stringset) {
1805*4882a593Smuzhiyun case ETH_SS_TEST:
1806*4882a593Smuzhiyun return 0;
1807*4882a593Smuzhiyun case ETH_SS_STATS:
1808*4882a593Smuzhiyun return gbe_dev->num_et_stats;
1809*4882a593Smuzhiyun default:
1810*4882a593Smuzhiyun return -EINVAL;
1811*4882a593Smuzhiyun }
1812*4882a593Smuzhiyun }
1813*4882a593Smuzhiyun
gbe_reset_mod_stats(struct gbe_priv * gbe_dev,int stats_mod)1814*4882a593Smuzhiyun static void gbe_reset_mod_stats(struct gbe_priv *gbe_dev, int stats_mod)
1815*4882a593Smuzhiyun {
1816*4882a593Smuzhiyun void __iomem *base = gbe_dev->hw_stats_regs[stats_mod];
1817*4882a593Smuzhiyun u32 __iomem *p_stats_entry;
1818*4882a593Smuzhiyun int i;
1819*4882a593Smuzhiyun
1820*4882a593Smuzhiyun for (i = 0; i < gbe_dev->num_et_stats; i++) {
1821*4882a593Smuzhiyun if (gbe_dev->et_stats[i].type == stats_mod) {
1822*4882a593Smuzhiyun p_stats_entry = base + gbe_dev->et_stats[i].offset;
1823*4882a593Smuzhiyun gbe_dev->hw_stats[i] = 0;
1824*4882a593Smuzhiyun gbe_dev->hw_stats_prev[i] = readl(p_stats_entry);
1825*4882a593Smuzhiyun }
1826*4882a593Smuzhiyun }
1827*4882a593Smuzhiyun }
1828*4882a593Smuzhiyun
gbe_update_hw_stats_entry(struct gbe_priv * gbe_dev,int et_stats_entry)1829*4882a593Smuzhiyun static inline void gbe_update_hw_stats_entry(struct gbe_priv *gbe_dev,
1830*4882a593Smuzhiyun int et_stats_entry)
1831*4882a593Smuzhiyun {
1832*4882a593Smuzhiyun void __iomem *base = NULL;
1833*4882a593Smuzhiyun u32 __iomem *p_stats_entry;
1834*4882a593Smuzhiyun u32 curr, delta;
1835*4882a593Smuzhiyun
1836*4882a593Smuzhiyun /* The hw_stats_regs pointers are already
1837*4882a593Smuzhiyun * properly set to point to the right base:
1838*4882a593Smuzhiyun */
1839*4882a593Smuzhiyun base = gbe_dev->hw_stats_regs[gbe_dev->et_stats[et_stats_entry].type];
1840*4882a593Smuzhiyun p_stats_entry = base + gbe_dev->et_stats[et_stats_entry].offset;
1841*4882a593Smuzhiyun curr = readl(p_stats_entry);
1842*4882a593Smuzhiyun delta = curr - gbe_dev->hw_stats_prev[et_stats_entry];
1843*4882a593Smuzhiyun gbe_dev->hw_stats_prev[et_stats_entry] = curr;
1844*4882a593Smuzhiyun gbe_dev->hw_stats[et_stats_entry] += delta;
1845*4882a593Smuzhiyun }
1846*4882a593Smuzhiyun
gbe_update_stats(struct gbe_priv * gbe_dev,uint64_t * data)1847*4882a593Smuzhiyun static void gbe_update_stats(struct gbe_priv *gbe_dev, uint64_t *data)
1848*4882a593Smuzhiyun {
1849*4882a593Smuzhiyun int i;
1850*4882a593Smuzhiyun
1851*4882a593Smuzhiyun for (i = 0; i < gbe_dev->num_et_stats; i++) {
1852*4882a593Smuzhiyun gbe_update_hw_stats_entry(gbe_dev, i);
1853*4882a593Smuzhiyun
1854*4882a593Smuzhiyun if (data)
1855*4882a593Smuzhiyun data[i] = gbe_dev->hw_stats[i];
1856*4882a593Smuzhiyun }
1857*4882a593Smuzhiyun }
1858*4882a593Smuzhiyun
gbe_stats_mod_visible_ver14(struct gbe_priv * gbe_dev,int stats_mod)1859*4882a593Smuzhiyun static inline void gbe_stats_mod_visible_ver14(struct gbe_priv *gbe_dev,
1860*4882a593Smuzhiyun int stats_mod)
1861*4882a593Smuzhiyun {
1862*4882a593Smuzhiyun u32 val;
1863*4882a593Smuzhiyun
1864*4882a593Smuzhiyun val = readl(GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
1865*4882a593Smuzhiyun
1866*4882a593Smuzhiyun switch (stats_mod) {
1867*4882a593Smuzhiyun case GBE_STATSA_MODULE:
1868*4882a593Smuzhiyun case GBE_STATSB_MODULE:
1869*4882a593Smuzhiyun val &= ~GBE_STATS_CD_SEL;
1870*4882a593Smuzhiyun break;
1871*4882a593Smuzhiyun case GBE_STATSC_MODULE:
1872*4882a593Smuzhiyun case GBE_STATSD_MODULE:
1873*4882a593Smuzhiyun val |= GBE_STATS_CD_SEL;
1874*4882a593Smuzhiyun break;
1875*4882a593Smuzhiyun default:
1876*4882a593Smuzhiyun return;
1877*4882a593Smuzhiyun }
1878*4882a593Smuzhiyun
1879*4882a593Smuzhiyun /* make the stat module visible */
1880*4882a593Smuzhiyun writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
1881*4882a593Smuzhiyun }
1882*4882a593Smuzhiyun
gbe_reset_mod_stats_ver14(struct gbe_priv * gbe_dev,int stats_mod)1883*4882a593Smuzhiyun static void gbe_reset_mod_stats_ver14(struct gbe_priv *gbe_dev, int stats_mod)
1884*4882a593Smuzhiyun {
1885*4882a593Smuzhiyun gbe_stats_mod_visible_ver14(gbe_dev, stats_mod);
1886*4882a593Smuzhiyun gbe_reset_mod_stats(gbe_dev, stats_mod);
1887*4882a593Smuzhiyun }
1888*4882a593Smuzhiyun
gbe_update_stats_ver14(struct gbe_priv * gbe_dev,uint64_t * data)1889*4882a593Smuzhiyun static void gbe_update_stats_ver14(struct gbe_priv *gbe_dev, uint64_t *data)
1890*4882a593Smuzhiyun {
1891*4882a593Smuzhiyun u32 half_num_et_stats = (gbe_dev->num_et_stats / 2);
1892*4882a593Smuzhiyun int et_entry, j, pair;
1893*4882a593Smuzhiyun
1894*4882a593Smuzhiyun for (pair = 0; pair < 2; pair++) {
1895*4882a593Smuzhiyun gbe_stats_mod_visible_ver14(gbe_dev, (pair ?
1896*4882a593Smuzhiyun GBE_STATSC_MODULE :
1897*4882a593Smuzhiyun GBE_STATSA_MODULE));
1898*4882a593Smuzhiyun
1899*4882a593Smuzhiyun for (j = 0; j < half_num_et_stats; j++) {
1900*4882a593Smuzhiyun et_entry = pair * half_num_et_stats + j;
1901*4882a593Smuzhiyun gbe_update_hw_stats_entry(gbe_dev, et_entry);
1902*4882a593Smuzhiyun
1903*4882a593Smuzhiyun if (data)
1904*4882a593Smuzhiyun data[et_entry] = gbe_dev->hw_stats[et_entry];
1905*4882a593Smuzhiyun }
1906*4882a593Smuzhiyun }
1907*4882a593Smuzhiyun }
1908*4882a593Smuzhiyun
keystone_get_ethtool_stats(struct net_device * ndev,struct ethtool_stats * stats,uint64_t * data)1909*4882a593Smuzhiyun static void keystone_get_ethtool_stats(struct net_device *ndev,
1910*4882a593Smuzhiyun struct ethtool_stats *stats,
1911*4882a593Smuzhiyun uint64_t *data)
1912*4882a593Smuzhiyun {
1913*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
1914*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
1915*4882a593Smuzhiyun struct gbe_priv *gbe_dev;
1916*4882a593Smuzhiyun
1917*4882a593Smuzhiyun gbe_intf = keystone_get_intf_data(netcp);
1918*4882a593Smuzhiyun if (!gbe_intf)
1919*4882a593Smuzhiyun return;
1920*4882a593Smuzhiyun
1921*4882a593Smuzhiyun gbe_dev = gbe_intf->gbe_dev;
1922*4882a593Smuzhiyun spin_lock_bh(&gbe_dev->hw_stats_lock);
1923*4882a593Smuzhiyun if (IS_SS_ID_VER_14(gbe_dev))
1924*4882a593Smuzhiyun gbe_update_stats_ver14(gbe_dev, data);
1925*4882a593Smuzhiyun else
1926*4882a593Smuzhiyun gbe_update_stats(gbe_dev, data);
1927*4882a593Smuzhiyun spin_unlock_bh(&gbe_dev->hw_stats_lock);
1928*4882a593Smuzhiyun }
1929*4882a593Smuzhiyun
keystone_get_link_ksettings(struct net_device * ndev,struct ethtool_link_ksettings * cmd)1930*4882a593Smuzhiyun static int keystone_get_link_ksettings(struct net_device *ndev,
1931*4882a593Smuzhiyun struct ethtool_link_ksettings *cmd)
1932*4882a593Smuzhiyun {
1933*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
1934*4882a593Smuzhiyun struct phy_device *phy = ndev->phydev;
1935*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
1936*4882a593Smuzhiyun
1937*4882a593Smuzhiyun if (!phy)
1938*4882a593Smuzhiyun return -EINVAL;
1939*4882a593Smuzhiyun
1940*4882a593Smuzhiyun gbe_intf = keystone_get_intf_data(netcp);
1941*4882a593Smuzhiyun if (!gbe_intf)
1942*4882a593Smuzhiyun return -EINVAL;
1943*4882a593Smuzhiyun
1944*4882a593Smuzhiyun if (!gbe_intf->slave)
1945*4882a593Smuzhiyun return -EINVAL;
1946*4882a593Smuzhiyun
1947*4882a593Smuzhiyun phy_ethtool_ksettings_get(phy, cmd);
1948*4882a593Smuzhiyun cmd->base.port = gbe_intf->slave->phy_port_t;
1949*4882a593Smuzhiyun
1950*4882a593Smuzhiyun return 0;
1951*4882a593Smuzhiyun }
1952*4882a593Smuzhiyun
keystone_set_link_ksettings(struct net_device * ndev,const struct ethtool_link_ksettings * cmd)1953*4882a593Smuzhiyun static int keystone_set_link_ksettings(struct net_device *ndev,
1954*4882a593Smuzhiyun const struct ethtool_link_ksettings *cmd)
1955*4882a593Smuzhiyun {
1956*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
1957*4882a593Smuzhiyun struct phy_device *phy = ndev->phydev;
1958*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
1959*4882a593Smuzhiyun u8 port = cmd->base.port;
1960*4882a593Smuzhiyun u32 advertising, supported;
1961*4882a593Smuzhiyun u32 features;
1962*4882a593Smuzhiyun
1963*4882a593Smuzhiyun ethtool_convert_link_mode_to_legacy_u32(&advertising,
1964*4882a593Smuzhiyun cmd->link_modes.advertising);
1965*4882a593Smuzhiyun ethtool_convert_link_mode_to_legacy_u32(&supported,
1966*4882a593Smuzhiyun cmd->link_modes.supported);
1967*4882a593Smuzhiyun features = advertising & supported;
1968*4882a593Smuzhiyun
1969*4882a593Smuzhiyun if (!phy)
1970*4882a593Smuzhiyun return -EINVAL;
1971*4882a593Smuzhiyun
1972*4882a593Smuzhiyun gbe_intf = keystone_get_intf_data(netcp);
1973*4882a593Smuzhiyun if (!gbe_intf)
1974*4882a593Smuzhiyun return -EINVAL;
1975*4882a593Smuzhiyun
1976*4882a593Smuzhiyun if (!gbe_intf->slave)
1977*4882a593Smuzhiyun return -EINVAL;
1978*4882a593Smuzhiyun
1979*4882a593Smuzhiyun if (port != gbe_intf->slave->phy_port_t) {
1980*4882a593Smuzhiyun if ((port == PORT_TP) && !(features & ADVERTISED_TP))
1981*4882a593Smuzhiyun return -EINVAL;
1982*4882a593Smuzhiyun
1983*4882a593Smuzhiyun if ((port == PORT_AUI) && !(features & ADVERTISED_AUI))
1984*4882a593Smuzhiyun return -EINVAL;
1985*4882a593Smuzhiyun
1986*4882a593Smuzhiyun if ((port == PORT_BNC) && !(features & ADVERTISED_BNC))
1987*4882a593Smuzhiyun return -EINVAL;
1988*4882a593Smuzhiyun
1989*4882a593Smuzhiyun if ((port == PORT_MII) && !(features & ADVERTISED_MII))
1990*4882a593Smuzhiyun return -EINVAL;
1991*4882a593Smuzhiyun
1992*4882a593Smuzhiyun if ((port == PORT_FIBRE) && !(features & ADVERTISED_FIBRE))
1993*4882a593Smuzhiyun return -EINVAL;
1994*4882a593Smuzhiyun }
1995*4882a593Smuzhiyun
1996*4882a593Smuzhiyun gbe_intf->slave->phy_port_t = port;
1997*4882a593Smuzhiyun return phy_ethtool_ksettings_set(phy, cmd);
1998*4882a593Smuzhiyun }
1999*4882a593Smuzhiyun
2000*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_TI_CPTS)
keystone_get_ts_info(struct net_device * ndev,struct ethtool_ts_info * info)2001*4882a593Smuzhiyun static int keystone_get_ts_info(struct net_device *ndev,
2002*4882a593Smuzhiyun struct ethtool_ts_info *info)
2003*4882a593Smuzhiyun {
2004*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
2005*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
2006*4882a593Smuzhiyun
2007*4882a593Smuzhiyun gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
2008*4882a593Smuzhiyun if (!gbe_intf || !gbe_intf->gbe_dev->cpts)
2009*4882a593Smuzhiyun return -EINVAL;
2010*4882a593Smuzhiyun
2011*4882a593Smuzhiyun info->so_timestamping =
2012*4882a593Smuzhiyun SOF_TIMESTAMPING_TX_HARDWARE |
2013*4882a593Smuzhiyun SOF_TIMESTAMPING_TX_SOFTWARE |
2014*4882a593Smuzhiyun SOF_TIMESTAMPING_RX_HARDWARE |
2015*4882a593Smuzhiyun SOF_TIMESTAMPING_RX_SOFTWARE |
2016*4882a593Smuzhiyun SOF_TIMESTAMPING_SOFTWARE |
2017*4882a593Smuzhiyun SOF_TIMESTAMPING_RAW_HARDWARE;
2018*4882a593Smuzhiyun info->phc_index = gbe_intf->gbe_dev->cpts->phc_index;
2019*4882a593Smuzhiyun info->tx_types =
2020*4882a593Smuzhiyun (1 << HWTSTAMP_TX_OFF) |
2021*4882a593Smuzhiyun (1 << HWTSTAMP_TX_ON);
2022*4882a593Smuzhiyun info->rx_filters =
2023*4882a593Smuzhiyun (1 << HWTSTAMP_FILTER_NONE) |
2024*4882a593Smuzhiyun (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
2025*4882a593Smuzhiyun (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
2026*4882a593Smuzhiyun return 0;
2027*4882a593Smuzhiyun }
2028*4882a593Smuzhiyun #else
keystone_get_ts_info(struct net_device * ndev,struct ethtool_ts_info * info)2029*4882a593Smuzhiyun static int keystone_get_ts_info(struct net_device *ndev,
2030*4882a593Smuzhiyun struct ethtool_ts_info *info)
2031*4882a593Smuzhiyun {
2032*4882a593Smuzhiyun info->so_timestamping =
2033*4882a593Smuzhiyun SOF_TIMESTAMPING_TX_SOFTWARE |
2034*4882a593Smuzhiyun SOF_TIMESTAMPING_RX_SOFTWARE |
2035*4882a593Smuzhiyun SOF_TIMESTAMPING_SOFTWARE;
2036*4882a593Smuzhiyun info->phc_index = -1;
2037*4882a593Smuzhiyun info->tx_types = 0;
2038*4882a593Smuzhiyun info->rx_filters = 0;
2039*4882a593Smuzhiyun return 0;
2040*4882a593Smuzhiyun }
2041*4882a593Smuzhiyun #endif /* CONFIG_TI_CPTS */
2042*4882a593Smuzhiyun
2043*4882a593Smuzhiyun static const struct ethtool_ops keystone_ethtool_ops = {
2044*4882a593Smuzhiyun .get_drvinfo = keystone_get_drvinfo,
2045*4882a593Smuzhiyun .get_link = ethtool_op_get_link,
2046*4882a593Smuzhiyun .get_msglevel = keystone_get_msglevel,
2047*4882a593Smuzhiyun .set_msglevel = keystone_set_msglevel,
2048*4882a593Smuzhiyun .get_strings = keystone_get_stat_strings,
2049*4882a593Smuzhiyun .get_sset_count = keystone_get_sset_count,
2050*4882a593Smuzhiyun .get_ethtool_stats = keystone_get_ethtool_stats,
2051*4882a593Smuzhiyun .get_link_ksettings = keystone_get_link_ksettings,
2052*4882a593Smuzhiyun .set_link_ksettings = keystone_set_link_ksettings,
2053*4882a593Smuzhiyun .get_ts_info = keystone_get_ts_info,
2054*4882a593Smuzhiyun };
2055*4882a593Smuzhiyun
gbe_set_slave_mac(struct gbe_slave * slave,struct gbe_intf * gbe_intf)2056*4882a593Smuzhiyun static void gbe_set_slave_mac(struct gbe_slave *slave,
2057*4882a593Smuzhiyun struct gbe_intf *gbe_intf)
2058*4882a593Smuzhiyun {
2059*4882a593Smuzhiyun struct net_device *ndev = gbe_intf->ndev;
2060*4882a593Smuzhiyun
2061*4882a593Smuzhiyun writel(mac_hi(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_hi));
2062*4882a593Smuzhiyun writel(mac_lo(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_lo));
2063*4882a593Smuzhiyun }
2064*4882a593Smuzhiyun
gbe_get_slave_port(struct gbe_priv * priv,u32 slave_num)2065*4882a593Smuzhiyun static int gbe_get_slave_port(struct gbe_priv *priv, u32 slave_num)
2066*4882a593Smuzhiyun {
2067*4882a593Smuzhiyun if (priv->host_port == 0)
2068*4882a593Smuzhiyun return slave_num + 1;
2069*4882a593Smuzhiyun
2070*4882a593Smuzhiyun return slave_num;
2071*4882a593Smuzhiyun }
2072*4882a593Smuzhiyun
netcp_ethss_link_state_action(struct gbe_priv * gbe_dev,struct net_device * ndev,struct gbe_slave * slave,int up)2073*4882a593Smuzhiyun static void netcp_ethss_link_state_action(struct gbe_priv *gbe_dev,
2074*4882a593Smuzhiyun struct net_device *ndev,
2075*4882a593Smuzhiyun struct gbe_slave *slave,
2076*4882a593Smuzhiyun int up)
2077*4882a593Smuzhiyun {
2078*4882a593Smuzhiyun struct phy_device *phy = slave->phy;
2079*4882a593Smuzhiyun u32 mac_control = 0;
2080*4882a593Smuzhiyun
2081*4882a593Smuzhiyun if (up) {
2082*4882a593Smuzhiyun mac_control = slave->mac_control;
2083*4882a593Smuzhiyun if (phy && (phy->speed == SPEED_1000)) {
2084*4882a593Smuzhiyun mac_control |= MACSL_GIG_MODE;
2085*4882a593Smuzhiyun mac_control &= ~MACSL_XGIG_MODE;
2086*4882a593Smuzhiyun } else if (phy && (phy->speed == SPEED_10000)) {
2087*4882a593Smuzhiyun mac_control |= MACSL_XGIG_MODE;
2088*4882a593Smuzhiyun mac_control &= ~MACSL_GIG_MODE;
2089*4882a593Smuzhiyun }
2090*4882a593Smuzhiyun
2091*4882a593Smuzhiyun writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
2092*4882a593Smuzhiyun mac_control));
2093*4882a593Smuzhiyun
2094*4882a593Smuzhiyun cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
2095*4882a593Smuzhiyun ALE_PORT_STATE,
2096*4882a593Smuzhiyun ALE_PORT_STATE_FORWARD);
2097*4882a593Smuzhiyun
2098*4882a593Smuzhiyun if (ndev && slave->open &&
2099*4882a593Smuzhiyun ((slave->link_interface != SGMII_LINK_MAC_PHY) &&
2100*4882a593Smuzhiyun (slave->link_interface != RGMII_LINK_MAC_PHY) &&
2101*4882a593Smuzhiyun (slave->link_interface != XGMII_LINK_MAC_PHY)))
2102*4882a593Smuzhiyun netif_carrier_on(ndev);
2103*4882a593Smuzhiyun } else {
2104*4882a593Smuzhiyun writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
2105*4882a593Smuzhiyun mac_control));
2106*4882a593Smuzhiyun cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
2107*4882a593Smuzhiyun ALE_PORT_STATE,
2108*4882a593Smuzhiyun ALE_PORT_STATE_DISABLE);
2109*4882a593Smuzhiyun if (ndev &&
2110*4882a593Smuzhiyun ((slave->link_interface != SGMII_LINK_MAC_PHY) &&
2111*4882a593Smuzhiyun (slave->link_interface != RGMII_LINK_MAC_PHY) &&
2112*4882a593Smuzhiyun (slave->link_interface != XGMII_LINK_MAC_PHY)))
2113*4882a593Smuzhiyun netif_carrier_off(ndev);
2114*4882a593Smuzhiyun }
2115*4882a593Smuzhiyun
2116*4882a593Smuzhiyun if (phy)
2117*4882a593Smuzhiyun phy_print_status(phy);
2118*4882a593Smuzhiyun }
2119*4882a593Smuzhiyun
gbe_phy_link_status(struct gbe_slave * slave)2120*4882a593Smuzhiyun static bool gbe_phy_link_status(struct gbe_slave *slave)
2121*4882a593Smuzhiyun {
2122*4882a593Smuzhiyun return !slave->phy || slave->phy->link;
2123*4882a593Smuzhiyun }
2124*4882a593Smuzhiyun
2125*4882a593Smuzhiyun #define RGMII_REG_STATUS_LINK BIT(0)
2126*4882a593Smuzhiyun
netcp_2u_rgmii_get_port_link(struct gbe_priv * gbe_dev,bool * status)2127*4882a593Smuzhiyun static void netcp_2u_rgmii_get_port_link(struct gbe_priv *gbe_dev, bool *status)
2128*4882a593Smuzhiyun {
2129*4882a593Smuzhiyun u32 val = 0;
2130*4882a593Smuzhiyun
2131*4882a593Smuzhiyun val = readl(GBE_REG_ADDR(gbe_dev, ss_regs, rgmii_status));
2132*4882a593Smuzhiyun *status = !!(val & RGMII_REG_STATUS_LINK);
2133*4882a593Smuzhiyun }
2134*4882a593Smuzhiyun
netcp_ethss_update_link_state(struct gbe_priv * gbe_dev,struct gbe_slave * slave,struct net_device * ndev)2135*4882a593Smuzhiyun static void netcp_ethss_update_link_state(struct gbe_priv *gbe_dev,
2136*4882a593Smuzhiyun struct gbe_slave *slave,
2137*4882a593Smuzhiyun struct net_device *ndev)
2138*4882a593Smuzhiyun {
2139*4882a593Smuzhiyun bool sw_link_state = true, phy_link_state;
2140*4882a593Smuzhiyun int sp = slave->slave_num, link_state;
2141*4882a593Smuzhiyun
2142*4882a593Smuzhiyun if (!slave->open)
2143*4882a593Smuzhiyun return;
2144*4882a593Smuzhiyun
2145*4882a593Smuzhiyun if (SLAVE_LINK_IS_RGMII(slave))
2146*4882a593Smuzhiyun netcp_2u_rgmii_get_port_link(gbe_dev,
2147*4882a593Smuzhiyun &sw_link_state);
2148*4882a593Smuzhiyun if (SLAVE_LINK_IS_SGMII(slave))
2149*4882a593Smuzhiyun sw_link_state =
2150*4882a593Smuzhiyun netcp_sgmii_get_port_link(SGMII_BASE(gbe_dev, sp), sp);
2151*4882a593Smuzhiyun
2152*4882a593Smuzhiyun phy_link_state = gbe_phy_link_status(slave);
2153*4882a593Smuzhiyun link_state = phy_link_state & sw_link_state;
2154*4882a593Smuzhiyun
2155*4882a593Smuzhiyun if (atomic_xchg(&slave->link_state, link_state) != link_state)
2156*4882a593Smuzhiyun netcp_ethss_link_state_action(gbe_dev, ndev, slave,
2157*4882a593Smuzhiyun link_state);
2158*4882a593Smuzhiyun }
2159*4882a593Smuzhiyun
xgbe_adjust_link(struct net_device * ndev)2160*4882a593Smuzhiyun static void xgbe_adjust_link(struct net_device *ndev)
2161*4882a593Smuzhiyun {
2162*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
2163*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
2164*4882a593Smuzhiyun
2165*4882a593Smuzhiyun gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp);
2166*4882a593Smuzhiyun if (!gbe_intf)
2167*4882a593Smuzhiyun return;
2168*4882a593Smuzhiyun
2169*4882a593Smuzhiyun netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
2170*4882a593Smuzhiyun ndev);
2171*4882a593Smuzhiyun }
2172*4882a593Smuzhiyun
gbe_adjust_link(struct net_device * ndev)2173*4882a593Smuzhiyun static void gbe_adjust_link(struct net_device *ndev)
2174*4882a593Smuzhiyun {
2175*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
2176*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
2177*4882a593Smuzhiyun
2178*4882a593Smuzhiyun gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
2179*4882a593Smuzhiyun if (!gbe_intf)
2180*4882a593Smuzhiyun return;
2181*4882a593Smuzhiyun
2182*4882a593Smuzhiyun netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
2183*4882a593Smuzhiyun ndev);
2184*4882a593Smuzhiyun }
2185*4882a593Smuzhiyun
gbe_adjust_link_sec_slaves(struct net_device * ndev)2186*4882a593Smuzhiyun static void gbe_adjust_link_sec_slaves(struct net_device *ndev)
2187*4882a593Smuzhiyun {
2188*4882a593Smuzhiyun struct gbe_priv *gbe_dev = netdev_priv(ndev);
2189*4882a593Smuzhiyun struct gbe_slave *slave;
2190*4882a593Smuzhiyun
2191*4882a593Smuzhiyun for_each_sec_slave(slave, gbe_dev)
2192*4882a593Smuzhiyun netcp_ethss_update_link_state(gbe_dev, slave, NULL);
2193*4882a593Smuzhiyun }
2194*4882a593Smuzhiyun
2195*4882a593Smuzhiyun /* Reset EMAC
2196*4882a593Smuzhiyun * Soft reset is set and polled until clear, or until a timeout occurs
2197*4882a593Smuzhiyun */
gbe_port_reset(struct gbe_slave * slave)2198*4882a593Smuzhiyun static int gbe_port_reset(struct gbe_slave *slave)
2199*4882a593Smuzhiyun {
2200*4882a593Smuzhiyun u32 i, v;
2201*4882a593Smuzhiyun
2202*4882a593Smuzhiyun /* Set the soft reset bit */
2203*4882a593Smuzhiyun writel(SOFT_RESET, GBE_REG_ADDR(slave, emac_regs, soft_reset));
2204*4882a593Smuzhiyun
2205*4882a593Smuzhiyun /* Wait for the bit to clear */
2206*4882a593Smuzhiyun for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) {
2207*4882a593Smuzhiyun v = readl(GBE_REG_ADDR(slave, emac_regs, soft_reset));
2208*4882a593Smuzhiyun if ((v & SOFT_RESET_MASK) != SOFT_RESET)
2209*4882a593Smuzhiyun return 0;
2210*4882a593Smuzhiyun }
2211*4882a593Smuzhiyun
2212*4882a593Smuzhiyun /* Timeout on the reset */
2213*4882a593Smuzhiyun return GMACSL_RET_WARN_RESET_INCOMPLETE;
2214*4882a593Smuzhiyun }
2215*4882a593Smuzhiyun
2216*4882a593Smuzhiyun /* Configure EMAC */
gbe_port_config(struct gbe_priv * gbe_dev,struct gbe_slave * slave,int max_rx_len)2217*4882a593Smuzhiyun static void gbe_port_config(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
2218*4882a593Smuzhiyun int max_rx_len)
2219*4882a593Smuzhiyun {
2220*4882a593Smuzhiyun void __iomem *rx_maxlen_reg;
2221*4882a593Smuzhiyun u32 xgmii_mode;
2222*4882a593Smuzhiyun
2223*4882a593Smuzhiyun if (max_rx_len > NETCP_MAX_FRAME_SIZE)
2224*4882a593Smuzhiyun max_rx_len = NETCP_MAX_FRAME_SIZE;
2225*4882a593Smuzhiyun
2226*4882a593Smuzhiyun /* Enable correct MII mode at SS level */
2227*4882a593Smuzhiyun if (IS_SS_ID_XGBE(gbe_dev) &&
2228*4882a593Smuzhiyun (slave->link_interface >= XGMII_LINK_MAC_PHY)) {
2229*4882a593Smuzhiyun xgmii_mode = readl(GBE_REG_ADDR(gbe_dev, ss_regs, control));
2230*4882a593Smuzhiyun xgmii_mode |= (1 << slave->slave_num);
2231*4882a593Smuzhiyun writel(xgmii_mode, GBE_REG_ADDR(gbe_dev, ss_regs, control));
2232*4882a593Smuzhiyun }
2233*4882a593Smuzhiyun
2234*4882a593Smuzhiyun if (IS_SS_ID_MU(gbe_dev))
2235*4882a593Smuzhiyun rx_maxlen_reg = GBE_REG_ADDR(slave, port_regs, rx_maxlen);
2236*4882a593Smuzhiyun else
2237*4882a593Smuzhiyun rx_maxlen_reg = GBE_REG_ADDR(slave, emac_regs, rx_maxlen);
2238*4882a593Smuzhiyun
2239*4882a593Smuzhiyun writel(max_rx_len, rx_maxlen_reg);
2240*4882a593Smuzhiyun writel(slave->mac_control, GBE_REG_ADDR(slave, emac_regs, mac_control));
2241*4882a593Smuzhiyun }
2242*4882a593Smuzhiyun
gbe_sgmii_rtreset(struct gbe_priv * priv,struct gbe_slave * slave,bool set)2243*4882a593Smuzhiyun static void gbe_sgmii_rtreset(struct gbe_priv *priv,
2244*4882a593Smuzhiyun struct gbe_slave *slave, bool set)
2245*4882a593Smuzhiyun {
2246*4882a593Smuzhiyun if (SLAVE_LINK_IS_XGMII(slave))
2247*4882a593Smuzhiyun return;
2248*4882a593Smuzhiyun
2249*4882a593Smuzhiyun netcp_sgmii_rtreset(SGMII_BASE(priv, slave->slave_num),
2250*4882a593Smuzhiyun slave->slave_num, set);
2251*4882a593Smuzhiyun }
2252*4882a593Smuzhiyun
gbe_slave_stop(struct gbe_intf * intf)2253*4882a593Smuzhiyun static void gbe_slave_stop(struct gbe_intf *intf)
2254*4882a593Smuzhiyun {
2255*4882a593Smuzhiyun struct gbe_priv *gbe_dev = intf->gbe_dev;
2256*4882a593Smuzhiyun struct gbe_slave *slave = intf->slave;
2257*4882a593Smuzhiyun
2258*4882a593Smuzhiyun if (!IS_SS_ID_2U(gbe_dev))
2259*4882a593Smuzhiyun gbe_sgmii_rtreset(gbe_dev, slave, true);
2260*4882a593Smuzhiyun gbe_port_reset(slave);
2261*4882a593Smuzhiyun /* Disable forwarding */
2262*4882a593Smuzhiyun cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
2263*4882a593Smuzhiyun ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
2264*4882a593Smuzhiyun cpsw_ale_del_mcast(gbe_dev->ale, intf->ndev->broadcast,
2265*4882a593Smuzhiyun 1 << slave->port_num, 0, 0);
2266*4882a593Smuzhiyun
2267*4882a593Smuzhiyun if (!slave->phy)
2268*4882a593Smuzhiyun return;
2269*4882a593Smuzhiyun
2270*4882a593Smuzhiyun phy_stop(slave->phy);
2271*4882a593Smuzhiyun phy_disconnect(slave->phy);
2272*4882a593Smuzhiyun slave->phy = NULL;
2273*4882a593Smuzhiyun }
2274*4882a593Smuzhiyun
gbe_sgmii_config(struct gbe_priv * priv,struct gbe_slave * slave)2275*4882a593Smuzhiyun static void gbe_sgmii_config(struct gbe_priv *priv, struct gbe_slave *slave)
2276*4882a593Smuzhiyun {
2277*4882a593Smuzhiyun if (SLAVE_LINK_IS_XGMII(slave))
2278*4882a593Smuzhiyun return;
2279*4882a593Smuzhiyun
2280*4882a593Smuzhiyun netcp_sgmii_reset(SGMII_BASE(priv, slave->slave_num), slave->slave_num);
2281*4882a593Smuzhiyun netcp_sgmii_config(SGMII_BASE(priv, slave->slave_num), slave->slave_num,
2282*4882a593Smuzhiyun slave->link_interface);
2283*4882a593Smuzhiyun }
2284*4882a593Smuzhiyun
gbe_slave_open(struct gbe_intf * gbe_intf)2285*4882a593Smuzhiyun static int gbe_slave_open(struct gbe_intf *gbe_intf)
2286*4882a593Smuzhiyun {
2287*4882a593Smuzhiyun struct gbe_priv *priv = gbe_intf->gbe_dev;
2288*4882a593Smuzhiyun struct gbe_slave *slave = gbe_intf->slave;
2289*4882a593Smuzhiyun phy_interface_t phy_mode;
2290*4882a593Smuzhiyun bool has_phy = false;
2291*4882a593Smuzhiyun int err;
2292*4882a593Smuzhiyun
2293*4882a593Smuzhiyun void (*hndlr)(struct net_device *) = gbe_adjust_link;
2294*4882a593Smuzhiyun
2295*4882a593Smuzhiyun if (!IS_SS_ID_2U(priv))
2296*4882a593Smuzhiyun gbe_sgmii_config(priv, slave);
2297*4882a593Smuzhiyun gbe_port_reset(slave);
2298*4882a593Smuzhiyun if (!IS_SS_ID_2U(priv))
2299*4882a593Smuzhiyun gbe_sgmii_rtreset(priv, slave, false);
2300*4882a593Smuzhiyun gbe_port_config(priv, slave, priv->rx_packet_max);
2301*4882a593Smuzhiyun gbe_set_slave_mac(slave, gbe_intf);
2302*4882a593Smuzhiyun /* For NU & 2U switch, map the vlan priorities to zero
2303*4882a593Smuzhiyun * as we only configure to use priority 0
2304*4882a593Smuzhiyun */
2305*4882a593Smuzhiyun if (IS_SS_ID_MU(priv))
2306*4882a593Smuzhiyun writel(HOST_TX_PRI_MAP_DEFAULT,
2307*4882a593Smuzhiyun GBE_REG_ADDR(slave, port_regs, rx_pri_map));
2308*4882a593Smuzhiyun
2309*4882a593Smuzhiyun /* enable forwarding */
2310*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, slave->port_num,
2311*4882a593Smuzhiyun ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
2312*4882a593Smuzhiyun cpsw_ale_add_mcast(priv->ale, gbe_intf->ndev->broadcast,
2313*4882a593Smuzhiyun 1 << slave->port_num, 0, 0, ALE_MCAST_FWD_2);
2314*4882a593Smuzhiyun
2315*4882a593Smuzhiyun if (slave->link_interface == SGMII_LINK_MAC_PHY) {
2316*4882a593Smuzhiyun has_phy = true;
2317*4882a593Smuzhiyun phy_mode = PHY_INTERFACE_MODE_SGMII;
2318*4882a593Smuzhiyun slave->phy_port_t = PORT_MII;
2319*4882a593Smuzhiyun } else if (slave->link_interface == RGMII_LINK_MAC_PHY) {
2320*4882a593Smuzhiyun has_phy = true;
2321*4882a593Smuzhiyun err = of_get_phy_mode(slave->node, &phy_mode);
2322*4882a593Smuzhiyun /* if phy-mode is not present, default to
2323*4882a593Smuzhiyun * PHY_INTERFACE_MODE_RGMII
2324*4882a593Smuzhiyun */
2325*4882a593Smuzhiyun if (err)
2326*4882a593Smuzhiyun phy_mode = PHY_INTERFACE_MODE_RGMII;
2327*4882a593Smuzhiyun
2328*4882a593Smuzhiyun if (!phy_interface_mode_is_rgmii(phy_mode)) {
2329*4882a593Smuzhiyun dev_err(priv->dev,
2330*4882a593Smuzhiyun "Unsupported phy mode %d\n", phy_mode);
2331*4882a593Smuzhiyun return -EINVAL;
2332*4882a593Smuzhiyun }
2333*4882a593Smuzhiyun slave->phy_port_t = PORT_MII;
2334*4882a593Smuzhiyun } else if (slave->link_interface == XGMII_LINK_MAC_PHY) {
2335*4882a593Smuzhiyun has_phy = true;
2336*4882a593Smuzhiyun phy_mode = PHY_INTERFACE_MODE_NA;
2337*4882a593Smuzhiyun slave->phy_port_t = PORT_FIBRE;
2338*4882a593Smuzhiyun }
2339*4882a593Smuzhiyun
2340*4882a593Smuzhiyun if (has_phy) {
2341*4882a593Smuzhiyun if (IS_SS_ID_XGBE(priv))
2342*4882a593Smuzhiyun hndlr = xgbe_adjust_link;
2343*4882a593Smuzhiyun
2344*4882a593Smuzhiyun slave->phy = of_phy_connect(gbe_intf->ndev,
2345*4882a593Smuzhiyun slave->phy_node,
2346*4882a593Smuzhiyun hndlr, 0,
2347*4882a593Smuzhiyun phy_mode);
2348*4882a593Smuzhiyun if (!slave->phy) {
2349*4882a593Smuzhiyun dev_err(priv->dev, "phy not found on slave %d\n",
2350*4882a593Smuzhiyun slave->slave_num);
2351*4882a593Smuzhiyun return -ENODEV;
2352*4882a593Smuzhiyun }
2353*4882a593Smuzhiyun dev_dbg(priv->dev, "phy found: id is: 0x%s\n",
2354*4882a593Smuzhiyun phydev_name(slave->phy));
2355*4882a593Smuzhiyun phy_start(slave->phy);
2356*4882a593Smuzhiyun }
2357*4882a593Smuzhiyun return 0;
2358*4882a593Smuzhiyun }
2359*4882a593Smuzhiyun
gbe_init_host_port(struct gbe_priv * priv)2360*4882a593Smuzhiyun static void gbe_init_host_port(struct gbe_priv *priv)
2361*4882a593Smuzhiyun {
2362*4882a593Smuzhiyun int bypass_en = 1;
2363*4882a593Smuzhiyun
2364*4882a593Smuzhiyun /* Host Tx Pri */
2365*4882a593Smuzhiyun if (IS_SS_ID_NU(priv) || IS_SS_ID_XGBE(priv))
2366*4882a593Smuzhiyun writel(HOST_TX_PRI_MAP_DEFAULT,
2367*4882a593Smuzhiyun GBE_REG_ADDR(priv, host_port_regs, tx_pri_map));
2368*4882a593Smuzhiyun
2369*4882a593Smuzhiyun /* Max length register */
2370*4882a593Smuzhiyun writel(NETCP_MAX_FRAME_SIZE, GBE_REG_ADDR(priv, host_port_regs,
2371*4882a593Smuzhiyun rx_maxlen));
2372*4882a593Smuzhiyun
2373*4882a593Smuzhiyun cpsw_ale_start(priv->ale);
2374*4882a593Smuzhiyun
2375*4882a593Smuzhiyun if (priv->enable_ale)
2376*4882a593Smuzhiyun bypass_en = 0;
2377*4882a593Smuzhiyun
2378*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, 0, ALE_BYPASS, bypass_en);
2379*4882a593Smuzhiyun
2380*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, 0, ALE_NO_PORT_VLAN, 1);
2381*4882a593Smuzhiyun
2382*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, priv->host_port,
2383*4882a593Smuzhiyun ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
2384*4882a593Smuzhiyun
2385*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, 0,
2386*4882a593Smuzhiyun ALE_PORT_UNKNOWN_VLAN_MEMBER,
2387*4882a593Smuzhiyun GBE_PORT_MASK(priv->ale_ports));
2388*4882a593Smuzhiyun
2389*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, 0,
2390*4882a593Smuzhiyun ALE_PORT_UNKNOWN_MCAST_FLOOD,
2391*4882a593Smuzhiyun GBE_PORT_MASK(priv->ale_ports - 1));
2392*4882a593Smuzhiyun
2393*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, 0,
2394*4882a593Smuzhiyun ALE_PORT_UNKNOWN_REG_MCAST_FLOOD,
2395*4882a593Smuzhiyun GBE_PORT_MASK(priv->ale_ports));
2396*4882a593Smuzhiyun
2397*4882a593Smuzhiyun cpsw_ale_control_set(priv->ale, 0,
2398*4882a593Smuzhiyun ALE_PORT_UNTAGGED_EGRESS,
2399*4882a593Smuzhiyun GBE_PORT_MASK(priv->ale_ports));
2400*4882a593Smuzhiyun }
2401*4882a593Smuzhiyun
gbe_add_mcast_addr(struct gbe_intf * gbe_intf,u8 * addr)2402*4882a593Smuzhiyun static void gbe_add_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2403*4882a593Smuzhiyun {
2404*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2405*4882a593Smuzhiyun u16 vlan_id;
2406*4882a593Smuzhiyun
2407*4882a593Smuzhiyun cpsw_ale_add_mcast(gbe_dev->ale, addr,
2408*4882a593Smuzhiyun GBE_PORT_MASK(gbe_dev->ale_ports), 0, 0,
2409*4882a593Smuzhiyun ALE_MCAST_FWD_2);
2410*4882a593Smuzhiyun for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
2411*4882a593Smuzhiyun cpsw_ale_add_mcast(gbe_dev->ale, addr,
2412*4882a593Smuzhiyun GBE_PORT_MASK(gbe_dev->ale_ports),
2413*4882a593Smuzhiyun ALE_VLAN, vlan_id, ALE_MCAST_FWD_2);
2414*4882a593Smuzhiyun }
2415*4882a593Smuzhiyun }
2416*4882a593Smuzhiyun
gbe_add_ucast_addr(struct gbe_intf * gbe_intf,u8 * addr)2417*4882a593Smuzhiyun static void gbe_add_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2418*4882a593Smuzhiyun {
2419*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2420*4882a593Smuzhiyun u16 vlan_id;
2421*4882a593Smuzhiyun
2422*4882a593Smuzhiyun cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
2423*4882a593Smuzhiyun
2424*4882a593Smuzhiyun for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID)
2425*4882a593Smuzhiyun cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
2426*4882a593Smuzhiyun ALE_VLAN, vlan_id);
2427*4882a593Smuzhiyun }
2428*4882a593Smuzhiyun
gbe_del_mcast_addr(struct gbe_intf * gbe_intf,u8 * addr)2429*4882a593Smuzhiyun static void gbe_del_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2430*4882a593Smuzhiyun {
2431*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2432*4882a593Smuzhiyun u16 vlan_id;
2433*4882a593Smuzhiyun
2434*4882a593Smuzhiyun cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, 0, 0);
2435*4882a593Smuzhiyun
2436*4882a593Smuzhiyun for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
2437*4882a593Smuzhiyun cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, ALE_VLAN, vlan_id);
2438*4882a593Smuzhiyun }
2439*4882a593Smuzhiyun }
2440*4882a593Smuzhiyun
gbe_del_ucast_addr(struct gbe_intf * gbe_intf,u8 * addr)2441*4882a593Smuzhiyun static void gbe_del_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2442*4882a593Smuzhiyun {
2443*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2444*4882a593Smuzhiyun u16 vlan_id;
2445*4882a593Smuzhiyun
2446*4882a593Smuzhiyun cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
2447*4882a593Smuzhiyun
2448*4882a593Smuzhiyun for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
2449*4882a593Smuzhiyun cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
2450*4882a593Smuzhiyun ALE_VLAN, vlan_id);
2451*4882a593Smuzhiyun }
2452*4882a593Smuzhiyun }
2453*4882a593Smuzhiyun
gbe_add_addr(void * intf_priv,struct netcp_addr * naddr)2454*4882a593Smuzhiyun static int gbe_add_addr(void *intf_priv, struct netcp_addr *naddr)
2455*4882a593Smuzhiyun {
2456*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2457*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2458*4882a593Smuzhiyun
2459*4882a593Smuzhiyun dev_dbg(gbe_dev->dev, "ethss adding address %pM, type %d\n",
2460*4882a593Smuzhiyun naddr->addr, naddr->type);
2461*4882a593Smuzhiyun
2462*4882a593Smuzhiyun switch (naddr->type) {
2463*4882a593Smuzhiyun case ADDR_MCAST:
2464*4882a593Smuzhiyun case ADDR_BCAST:
2465*4882a593Smuzhiyun gbe_add_mcast_addr(gbe_intf, naddr->addr);
2466*4882a593Smuzhiyun break;
2467*4882a593Smuzhiyun case ADDR_UCAST:
2468*4882a593Smuzhiyun case ADDR_DEV:
2469*4882a593Smuzhiyun gbe_add_ucast_addr(gbe_intf, naddr->addr);
2470*4882a593Smuzhiyun break;
2471*4882a593Smuzhiyun case ADDR_ANY:
2472*4882a593Smuzhiyun /* nothing to do for promiscuous */
2473*4882a593Smuzhiyun default:
2474*4882a593Smuzhiyun break;
2475*4882a593Smuzhiyun }
2476*4882a593Smuzhiyun
2477*4882a593Smuzhiyun return 0;
2478*4882a593Smuzhiyun }
2479*4882a593Smuzhiyun
gbe_del_addr(void * intf_priv,struct netcp_addr * naddr)2480*4882a593Smuzhiyun static int gbe_del_addr(void *intf_priv, struct netcp_addr *naddr)
2481*4882a593Smuzhiyun {
2482*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2483*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2484*4882a593Smuzhiyun
2485*4882a593Smuzhiyun dev_dbg(gbe_dev->dev, "ethss deleting address %pM, type %d\n",
2486*4882a593Smuzhiyun naddr->addr, naddr->type);
2487*4882a593Smuzhiyun
2488*4882a593Smuzhiyun switch (naddr->type) {
2489*4882a593Smuzhiyun case ADDR_MCAST:
2490*4882a593Smuzhiyun case ADDR_BCAST:
2491*4882a593Smuzhiyun gbe_del_mcast_addr(gbe_intf, naddr->addr);
2492*4882a593Smuzhiyun break;
2493*4882a593Smuzhiyun case ADDR_UCAST:
2494*4882a593Smuzhiyun case ADDR_DEV:
2495*4882a593Smuzhiyun gbe_del_ucast_addr(gbe_intf, naddr->addr);
2496*4882a593Smuzhiyun break;
2497*4882a593Smuzhiyun case ADDR_ANY:
2498*4882a593Smuzhiyun /* nothing to do for promiscuous */
2499*4882a593Smuzhiyun default:
2500*4882a593Smuzhiyun break;
2501*4882a593Smuzhiyun }
2502*4882a593Smuzhiyun
2503*4882a593Smuzhiyun return 0;
2504*4882a593Smuzhiyun }
2505*4882a593Smuzhiyun
gbe_add_vid(void * intf_priv,int vid)2506*4882a593Smuzhiyun static int gbe_add_vid(void *intf_priv, int vid)
2507*4882a593Smuzhiyun {
2508*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2509*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2510*4882a593Smuzhiyun
2511*4882a593Smuzhiyun set_bit(vid, gbe_intf->active_vlans);
2512*4882a593Smuzhiyun
2513*4882a593Smuzhiyun cpsw_ale_add_vlan(gbe_dev->ale, vid,
2514*4882a593Smuzhiyun GBE_PORT_MASK(gbe_dev->ale_ports),
2515*4882a593Smuzhiyun GBE_MASK_NO_PORTS,
2516*4882a593Smuzhiyun GBE_PORT_MASK(gbe_dev->ale_ports),
2517*4882a593Smuzhiyun GBE_PORT_MASK(gbe_dev->ale_ports - 1));
2518*4882a593Smuzhiyun
2519*4882a593Smuzhiyun return 0;
2520*4882a593Smuzhiyun }
2521*4882a593Smuzhiyun
gbe_del_vid(void * intf_priv,int vid)2522*4882a593Smuzhiyun static int gbe_del_vid(void *intf_priv, int vid)
2523*4882a593Smuzhiyun {
2524*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2525*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2526*4882a593Smuzhiyun
2527*4882a593Smuzhiyun cpsw_ale_del_vlan(gbe_dev->ale, vid, 0);
2528*4882a593Smuzhiyun clear_bit(vid, gbe_intf->active_vlans);
2529*4882a593Smuzhiyun return 0;
2530*4882a593Smuzhiyun }
2531*4882a593Smuzhiyun
2532*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_TI_CPTS)
2533*4882a593Smuzhiyun
gbe_txtstamp(void * context,struct sk_buff * skb)2534*4882a593Smuzhiyun static void gbe_txtstamp(void *context, struct sk_buff *skb)
2535*4882a593Smuzhiyun {
2536*4882a593Smuzhiyun struct gbe_intf *gbe_intf = context;
2537*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2538*4882a593Smuzhiyun
2539*4882a593Smuzhiyun cpts_tx_timestamp(gbe_dev->cpts, skb);
2540*4882a593Smuzhiyun }
2541*4882a593Smuzhiyun
gbe_need_txtstamp(struct gbe_intf * gbe_intf,const struct netcp_packet * p_info)2542*4882a593Smuzhiyun static bool gbe_need_txtstamp(struct gbe_intf *gbe_intf,
2543*4882a593Smuzhiyun const struct netcp_packet *p_info)
2544*4882a593Smuzhiyun {
2545*4882a593Smuzhiyun struct sk_buff *skb = p_info->skb;
2546*4882a593Smuzhiyun
2547*4882a593Smuzhiyun return cpts_can_timestamp(gbe_intf->gbe_dev->cpts, skb);
2548*4882a593Smuzhiyun }
2549*4882a593Smuzhiyun
gbe_txtstamp_mark_pkt(struct gbe_intf * gbe_intf,struct netcp_packet * p_info)2550*4882a593Smuzhiyun static int gbe_txtstamp_mark_pkt(struct gbe_intf *gbe_intf,
2551*4882a593Smuzhiyun struct netcp_packet *p_info)
2552*4882a593Smuzhiyun {
2553*4882a593Smuzhiyun struct phy_device *phydev = p_info->skb->dev->phydev;
2554*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2555*4882a593Smuzhiyun
2556*4882a593Smuzhiyun if (!(skb_shinfo(p_info->skb)->tx_flags & SKBTX_HW_TSTAMP) ||
2557*4882a593Smuzhiyun !gbe_dev->tx_ts_enabled)
2558*4882a593Smuzhiyun return 0;
2559*4882a593Smuzhiyun
2560*4882a593Smuzhiyun /* If phy has the txtstamp api, assume it will do it.
2561*4882a593Smuzhiyun * We mark it here because skb_tx_timestamp() is called
2562*4882a593Smuzhiyun * after all the txhooks are called.
2563*4882a593Smuzhiyun */
2564*4882a593Smuzhiyun if (phy_has_txtstamp(phydev)) {
2565*4882a593Smuzhiyun skb_shinfo(p_info->skb)->tx_flags |= SKBTX_IN_PROGRESS;
2566*4882a593Smuzhiyun return 0;
2567*4882a593Smuzhiyun }
2568*4882a593Smuzhiyun
2569*4882a593Smuzhiyun if (gbe_need_txtstamp(gbe_intf, p_info)) {
2570*4882a593Smuzhiyun p_info->txtstamp = gbe_txtstamp;
2571*4882a593Smuzhiyun p_info->ts_context = (void *)gbe_intf;
2572*4882a593Smuzhiyun skb_shinfo(p_info->skb)->tx_flags |= SKBTX_IN_PROGRESS;
2573*4882a593Smuzhiyun }
2574*4882a593Smuzhiyun
2575*4882a593Smuzhiyun return 0;
2576*4882a593Smuzhiyun }
2577*4882a593Smuzhiyun
gbe_rxtstamp(struct gbe_intf * gbe_intf,struct netcp_packet * p_info)2578*4882a593Smuzhiyun static int gbe_rxtstamp(struct gbe_intf *gbe_intf, struct netcp_packet *p_info)
2579*4882a593Smuzhiyun {
2580*4882a593Smuzhiyun struct phy_device *phydev = p_info->skb->dev->phydev;
2581*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2582*4882a593Smuzhiyun
2583*4882a593Smuzhiyun if (p_info->rxtstamp_complete)
2584*4882a593Smuzhiyun return 0;
2585*4882a593Smuzhiyun
2586*4882a593Smuzhiyun if (phy_has_rxtstamp(phydev)) {
2587*4882a593Smuzhiyun p_info->rxtstamp_complete = true;
2588*4882a593Smuzhiyun return 0;
2589*4882a593Smuzhiyun }
2590*4882a593Smuzhiyun
2591*4882a593Smuzhiyun if (gbe_dev->rx_ts_enabled)
2592*4882a593Smuzhiyun cpts_rx_timestamp(gbe_dev->cpts, p_info->skb);
2593*4882a593Smuzhiyun
2594*4882a593Smuzhiyun p_info->rxtstamp_complete = true;
2595*4882a593Smuzhiyun
2596*4882a593Smuzhiyun return 0;
2597*4882a593Smuzhiyun }
2598*4882a593Smuzhiyun
gbe_hwtstamp_get(struct gbe_intf * gbe_intf,struct ifreq * ifr)2599*4882a593Smuzhiyun static int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *ifr)
2600*4882a593Smuzhiyun {
2601*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2602*4882a593Smuzhiyun struct cpts *cpts = gbe_dev->cpts;
2603*4882a593Smuzhiyun struct hwtstamp_config cfg;
2604*4882a593Smuzhiyun
2605*4882a593Smuzhiyun if (!cpts)
2606*4882a593Smuzhiyun return -EOPNOTSUPP;
2607*4882a593Smuzhiyun
2608*4882a593Smuzhiyun cfg.flags = 0;
2609*4882a593Smuzhiyun cfg.tx_type = gbe_dev->tx_ts_enabled ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
2610*4882a593Smuzhiyun cfg.rx_filter = gbe_dev->rx_ts_enabled;
2611*4882a593Smuzhiyun
2612*4882a593Smuzhiyun return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
2613*4882a593Smuzhiyun }
2614*4882a593Smuzhiyun
gbe_hwtstamp(struct gbe_intf * gbe_intf)2615*4882a593Smuzhiyun static void gbe_hwtstamp(struct gbe_intf *gbe_intf)
2616*4882a593Smuzhiyun {
2617*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2618*4882a593Smuzhiyun struct gbe_slave *slave = gbe_intf->slave;
2619*4882a593Smuzhiyun u32 ts_en, seq_id, ctl;
2620*4882a593Smuzhiyun
2621*4882a593Smuzhiyun if (!gbe_dev->rx_ts_enabled &&
2622*4882a593Smuzhiyun !gbe_dev->tx_ts_enabled) {
2623*4882a593Smuzhiyun writel(0, GBE_REG_ADDR(slave, port_regs, ts_ctl));
2624*4882a593Smuzhiyun return;
2625*4882a593Smuzhiyun }
2626*4882a593Smuzhiyun
2627*4882a593Smuzhiyun seq_id = (30 << TS_SEQ_ID_OFS_SHIFT) | ETH_P_1588;
2628*4882a593Smuzhiyun ts_en = EVENT_MSG_BITS << TS_MSG_TYPE_EN_SHIFT;
2629*4882a593Smuzhiyun ctl = ETH_P_1588 | TS_TTL_NONZERO |
2630*4882a593Smuzhiyun (slave->ts_ctl.dst_port_map << TS_CTL_DST_PORT_SHIFT) |
2631*4882a593Smuzhiyun (slave->ts_ctl.uni ? TS_UNI_EN :
2632*4882a593Smuzhiyun slave->ts_ctl.maddr_map << TS_CTL_MADDR_SHIFT);
2633*4882a593Smuzhiyun
2634*4882a593Smuzhiyun if (gbe_dev->tx_ts_enabled)
2635*4882a593Smuzhiyun ts_en |= (TS_TX_ANX_ALL_EN | TS_TX_VLAN_LT1_EN);
2636*4882a593Smuzhiyun
2637*4882a593Smuzhiyun if (gbe_dev->rx_ts_enabled)
2638*4882a593Smuzhiyun ts_en |= (TS_RX_ANX_ALL_EN | TS_RX_VLAN_LT1_EN);
2639*4882a593Smuzhiyun
2640*4882a593Smuzhiyun writel(ts_en, GBE_REG_ADDR(slave, port_regs, ts_ctl));
2641*4882a593Smuzhiyun writel(seq_id, GBE_REG_ADDR(slave, port_regs, ts_seq_ltype));
2642*4882a593Smuzhiyun writel(ctl, GBE_REG_ADDR(slave, port_regs, ts_ctl_ltype2));
2643*4882a593Smuzhiyun }
2644*4882a593Smuzhiyun
gbe_hwtstamp_set(struct gbe_intf * gbe_intf,struct ifreq * ifr)2645*4882a593Smuzhiyun static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr)
2646*4882a593Smuzhiyun {
2647*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2648*4882a593Smuzhiyun struct cpts *cpts = gbe_dev->cpts;
2649*4882a593Smuzhiyun struct hwtstamp_config cfg;
2650*4882a593Smuzhiyun
2651*4882a593Smuzhiyun if (!cpts)
2652*4882a593Smuzhiyun return -EOPNOTSUPP;
2653*4882a593Smuzhiyun
2654*4882a593Smuzhiyun if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
2655*4882a593Smuzhiyun return -EFAULT;
2656*4882a593Smuzhiyun
2657*4882a593Smuzhiyun /* reserved for future extensions */
2658*4882a593Smuzhiyun if (cfg.flags)
2659*4882a593Smuzhiyun return -EINVAL;
2660*4882a593Smuzhiyun
2661*4882a593Smuzhiyun switch (cfg.tx_type) {
2662*4882a593Smuzhiyun case HWTSTAMP_TX_OFF:
2663*4882a593Smuzhiyun gbe_dev->tx_ts_enabled = 0;
2664*4882a593Smuzhiyun break;
2665*4882a593Smuzhiyun case HWTSTAMP_TX_ON:
2666*4882a593Smuzhiyun gbe_dev->tx_ts_enabled = 1;
2667*4882a593Smuzhiyun break;
2668*4882a593Smuzhiyun default:
2669*4882a593Smuzhiyun return -ERANGE;
2670*4882a593Smuzhiyun }
2671*4882a593Smuzhiyun
2672*4882a593Smuzhiyun switch (cfg.rx_filter) {
2673*4882a593Smuzhiyun case HWTSTAMP_FILTER_NONE:
2674*4882a593Smuzhiyun gbe_dev->rx_ts_enabled = HWTSTAMP_FILTER_NONE;
2675*4882a593Smuzhiyun break;
2676*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2677*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2678*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2679*4882a593Smuzhiyun gbe_dev->rx_ts_enabled = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
2680*4882a593Smuzhiyun cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
2681*4882a593Smuzhiyun break;
2682*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2683*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2684*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2685*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2686*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2687*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2688*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_EVENT:
2689*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_SYNC:
2690*4882a593Smuzhiyun case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2691*4882a593Smuzhiyun gbe_dev->rx_ts_enabled = HWTSTAMP_FILTER_PTP_V2_EVENT;
2692*4882a593Smuzhiyun cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
2693*4882a593Smuzhiyun break;
2694*4882a593Smuzhiyun default:
2695*4882a593Smuzhiyun return -ERANGE;
2696*4882a593Smuzhiyun }
2697*4882a593Smuzhiyun
2698*4882a593Smuzhiyun gbe_hwtstamp(gbe_intf);
2699*4882a593Smuzhiyun
2700*4882a593Smuzhiyun return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
2701*4882a593Smuzhiyun }
2702*4882a593Smuzhiyun
gbe_register_cpts(struct gbe_priv * gbe_dev)2703*4882a593Smuzhiyun static void gbe_register_cpts(struct gbe_priv *gbe_dev)
2704*4882a593Smuzhiyun {
2705*4882a593Smuzhiyun if (!gbe_dev->cpts)
2706*4882a593Smuzhiyun return;
2707*4882a593Smuzhiyun
2708*4882a593Smuzhiyun if (gbe_dev->cpts_registered > 0)
2709*4882a593Smuzhiyun goto done;
2710*4882a593Smuzhiyun
2711*4882a593Smuzhiyun if (cpts_register(gbe_dev->cpts)) {
2712*4882a593Smuzhiyun dev_err(gbe_dev->dev, "error registering cpts device\n");
2713*4882a593Smuzhiyun return;
2714*4882a593Smuzhiyun }
2715*4882a593Smuzhiyun
2716*4882a593Smuzhiyun done:
2717*4882a593Smuzhiyun ++gbe_dev->cpts_registered;
2718*4882a593Smuzhiyun }
2719*4882a593Smuzhiyun
gbe_unregister_cpts(struct gbe_priv * gbe_dev)2720*4882a593Smuzhiyun static void gbe_unregister_cpts(struct gbe_priv *gbe_dev)
2721*4882a593Smuzhiyun {
2722*4882a593Smuzhiyun if (!gbe_dev->cpts || (gbe_dev->cpts_registered <= 0))
2723*4882a593Smuzhiyun return;
2724*4882a593Smuzhiyun
2725*4882a593Smuzhiyun if (--gbe_dev->cpts_registered)
2726*4882a593Smuzhiyun return;
2727*4882a593Smuzhiyun
2728*4882a593Smuzhiyun cpts_unregister(gbe_dev->cpts);
2729*4882a593Smuzhiyun }
2730*4882a593Smuzhiyun #else
gbe_txtstamp_mark_pkt(struct gbe_intf * gbe_intf,struct netcp_packet * p_info)2731*4882a593Smuzhiyun static inline int gbe_txtstamp_mark_pkt(struct gbe_intf *gbe_intf,
2732*4882a593Smuzhiyun struct netcp_packet *p_info)
2733*4882a593Smuzhiyun {
2734*4882a593Smuzhiyun return 0;
2735*4882a593Smuzhiyun }
2736*4882a593Smuzhiyun
gbe_rxtstamp(struct gbe_intf * gbe_intf,struct netcp_packet * p_info)2737*4882a593Smuzhiyun static inline int gbe_rxtstamp(struct gbe_intf *gbe_intf,
2738*4882a593Smuzhiyun struct netcp_packet *p_info)
2739*4882a593Smuzhiyun {
2740*4882a593Smuzhiyun return 0;
2741*4882a593Smuzhiyun }
2742*4882a593Smuzhiyun
gbe_hwtstamp(struct gbe_intf * gbe_intf,struct ifreq * ifr,int cmd)2743*4882a593Smuzhiyun static inline int gbe_hwtstamp(struct gbe_intf *gbe_intf,
2744*4882a593Smuzhiyun struct ifreq *ifr, int cmd)
2745*4882a593Smuzhiyun {
2746*4882a593Smuzhiyun return -EOPNOTSUPP;
2747*4882a593Smuzhiyun }
2748*4882a593Smuzhiyun
gbe_register_cpts(struct gbe_priv * gbe_dev)2749*4882a593Smuzhiyun static inline void gbe_register_cpts(struct gbe_priv *gbe_dev)
2750*4882a593Smuzhiyun {
2751*4882a593Smuzhiyun }
2752*4882a593Smuzhiyun
gbe_unregister_cpts(struct gbe_priv * gbe_dev)2753*4882a593Smuzhiyun static inline void gbe_unregister_cpts(struct gbe_priv *gbe_dev)
2754*4882a593Smuzhiyun {
2755*4882a593Smuzhiyun }
2756*4882a593Smuzhiyun
gbe_hwtstamp_get(struct gbe_intf * gbe_intf,struct ifreq * req)2757*4882a593Smuzhiyun static inline int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *req)
2758*4882a593Smuzhiyun {
2759*4882a593Smuzhiyun return -EOPNOTSUPP;
2760*4882a593Smuzhiyun }
2761*4882a593Smuzhiyun
gbe_hwtstamp_set(struct gbe_intf * gbe_intf,struct ifreq * req)2762*4882a593Smuzhiyun static inline int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *req)
2763*4882a593Smuzhiyun {
2764*4882a593Smuzhiyun return -EOPNOTSUPP;
2765*4882a593Smuzhiyun }
2766*4882a593Smuzhiyun #endif /* CONFIG_TI_CPTS */
2767*4882a593Smuzhiyun
gbe_set_rx_mode(void * intf_priv,bool promisc)2768*4882a593Smuzhiyun static int gbe_set_rx_mode(void *intf_priv, bool promisc)
2769*4882a593Smuzhiyun {
2770*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2771*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2772*4882a593Smuzhiyun struct cpsw_ale *ale = gbe_dev->ale;
2773*4882a593Smuzhiyun unsigned long timeout;
2774*4882a593Smuzhiyun int i, ret = -ETIMEDOUT;
2775*4882a593Smuzhiyun
2776*4882a593Smuzhiyun /* Disable(1)/Enable(0) Learn for all ports (host is port 0 and
2777*4882a593Smuzhiyun * slaves are port 1 and up
2778*4882a593Smuzhiyun */
2779*4882a593Smuzhiyun for (i = 0; i <= gbe_dev->num_slaves; i++) {
2780*4882a593Smuzhiyun cpsw_ale_control_set(ale, i,
2781*4882a593Smuzhiyun ALE_PORT_NOLEARN, !!promisc);
2782*4882a593Smuzhiyun cpsw_ale_control_set(ale, i,
2783*4882a593Smuzhiyun ALE_PORT_NO_SA_UPDATE, !!promisc);
2784*4882a593Smuzhiyun }
2785*4882a593Smuzhiyun
2786*4882a593Smuzhiyun if (!promisc) {
2787*4882a593Smuzhiyun /* Don't Flood All Unicast Packets to Host port */
2788*4882a593Smuzhiyun cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 0);
2789*4882a593Smuzhiyun dev_vdbg(gbe_dev->dev, "promiscuous mode disabled\n");
2790*4882a593Smuzhiyun return 0;
2791*4882a593Smuzhiyun }
2792*4882a593Smuzhiyun
2793*4882a593Smuzhiyun timeout = jiffies + HZ;
2794*4882a593Smuzhiyun
2795*4882a593Smuzhiyun /* Clear All Untouched entries */
2796*4882a593Smuzhiyun cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
2797*4882a593Smuzhiyun do {
2798*4882a593Smuzhiyun cpu_relax();
2799*4882a593Smuzhiyun if (cpsw_ale_control_get(ale, 0, ALE_AGEOUT)) {
2800*4882a593Smuzhiyun ret = 0;
2801*4882a593Smuzhiyun break;
2802*4882a593Smuzhiyun }
2803*4882a593Smuzhiyun
2804*4882a593Smuzhiyun } while (time_after(timeout, jiffies));
2805*4882a593Smuzhiyun
2806*4882a593Smuzhiyun /* Make sure it is not a false timeout */
2807*4882a593Smuzhiyun if (ret && !cpsw_ale_control_get(ale, 0, ALE_AGEOUT))
2808*4882a593Smuzhiyun return ret;
2809*4882a593Smuzhiyun
2810*4882a593Smuzhiyun cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
2811*4882a593Smuzhiyun
2812*4882a593Smuzhiyun /* Clear all mcast from ALE */
2813*4882a593Smuzhiyun cpsw_ale_flush_multicast(ale,
2814*4882a593Smuzhiyun GBE_PORT_MASK(gbe_dev->ale_ports),
2815*4882a593Smuzhiyun -1);
2816*4882a593Smuzhiyun
2817*4882a593Smuzhiyun /* Flood All Unicast Packets to Host port */
2818*4882a593Smuzhiyun cpsw_ale_control_set(ale, 0, ALE_P0_UNI_FLOOD, 1);
2819*4882a593Smuzhiyun dev_vdbg(gbe_dev->dev, "promiscuous mode enabled\n");
2820*4882a593Smuzhiyun return ret;
2821*4882a593Smuzhiyun }
2822*4882a593Smuzhiyun
gbe_ioctl(void * intf_priv,struct ifreq * req,int cmd)2823*4882a593Smuzhiyun static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)
2824*4882a593Smuzhiyun {
2825*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2826*4882a593Smuzhiyun struct phy_device *phy = gbe_intf->slave->phy;
2827*4882a593Smuzhiyun
2828*4882a593Smuzhiyun if (!phy_has_hwtstamp(phy)) {
2829*4882a593Smuzhiyun switch (cmd) {
2830*4882a593Smuzhiyun case SIOCGHWTSTAMP:
2831*4882a593Smuzhiyun return gbe_hwtstamp_get(gbe_intf, req);
2832*4882a593Smuzhiyun case SIOCSHWTSTAMP:
2833*4882a593Smuzhiyun return gbe_hwtstamp_set(gbe_intf, req);
2834*4882a593Smuzhiyun }
2835*4882a593Smuzhiyun }
2836*4882a593Smuzhiyun
2837*4882a593Smuzhiyun if (phy)
2838*4882a593Smuzhiyun return phy_mii_ioctl(phy, req, cmd);
2839*4882a593Smuzhiyun
2840*4882a593Smuzhiyun return -EOPNOTSUPP;
2841*4882a593Smuzhiyun }
2842*4882a593Smuzhiyun
netcp_ethss_timer(struct timer_list * t)2843*4882a593Smuzhiyun static void netcp_ethss_timer(struct timer_list *t)
2844*4882a593Smuzhiyun {
2845*4882a593Smuzhiyun struct gbe_priv *gbe_dev = from_timer(gbe_dev, t, timer);
2846*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
2847*4882a593Smuzhiyun struct gbe_slave *slave;
2848*4882a593Smuzhiyun
2849*4882a593Smuzhiyun /* Check & update SGMII link state of interfaces */
2850*4882a593Smuzhiyun for_each_intf(gbe_intf, gbe_dev) {
2851*4882a593Smuzhiyun if (!gbe_intf->slave->open)
2852*4882a593Smuzhiyun continue;
2853*4882a593Smuzhiyun netcp_ethss_update_link_state(gbe_dev, gbe_intf->slave,
2854*4882a593Smuzhiyun gbe_intf->ndev);
2855*4882a593Smuzhiyun }
2856*4882a593Smuzhiyun
2857*4882a593Smuzhiyun /* Check & update SGMII link state of secondary ports */
2858*4882a593Smuzhiyun for_each_sec_slave(slave, gbe_dev) {
2859*4882a593Smuzhiyun netcp_ethss_update_link_state(gbe_dev, slave, NULL);
2860*4882a593Smuzhiyun }
2861*4882a593Smuzhiyun
2862*4882a593Smuzhiyun /* A timer runs as a BH, no need to block them */
2863*4882a593Smuzhiyun spin_lock(&gbe_dev->hw_stats_lock);
2864*4882a593Smuzhiyun
2865*4882a593Smuzhiyun if (IS_SS_ID_VER_14(gbe_dev))
2866*4882a593Smuzhiyun gbe_update_stats_ver14(gbe_dev, NULL);
2867*4882a593Smuzhiyun else
2868*4882a593Smuzhiyun gbe_update_stats(gbe_dev, NULL);
2869*4882a593Smuzhiyun
2870*4882a593Smuzhiyun spin_unlock(&gbe_dev->hw_stats_lock);
2871*4882a593Smuzhiyun
2872*4882a593Smuzhiyun gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
2873*4882a593Smuzhiyun add_timer(&gbe_dev->timer);
2874*4882a593Smuzhiyun }
2875*4882a593Smuzhiyun
gbe_txhook(int order,void * data,struct netcp_packet * p_info)2876*4882a593Smuzhiyun static int gbe_txhook(int order, void *data, struct netcp_packet *p_info)
2877*4882a593Smuzhiyun {
2878*4882a593Smuzhiyun struct gbe_intf *gbe_intf = data;
2879*4882a593Smuzhiyun
2880*4882a593Smuzhiyun p_info->tx_pipe = &gbe_intf->tx_pipe;
2881*4882a593Smuzhiyun
2882*4882a593Smuzhiyun return gbe_txtstamp_mark_pkt(gbe_intf, p_info);
2883*4882a593Smuzhiyun }
2884*4882a593Smuzhiyun
gbe_rxhook(int order,void * data,struct netcp_packet * p_info)2885*4882a593Smuzhiyun static int gbe_rxhook(int order, void *data, struct netcp_packet *p_info)
2886*4882a593Smuzhiyun {
2887*4882a593Smuzhiyun struct gbe_intf *gbe_intf = data;
2888*4882a593Smuzhiyun
2889*4882a593Smuzhiyun return gbe_rxtstamp(gbe_intf, p_info);
2890*4882a593Smuzhiyun }
2891*4882a593Smuzhiyun
gbe_open(void * intf_priv,struct net_device * ndev)2892*4882a593Smuzhiyun static int gbe_open(void *intf_priv, struct net_device *ndev)
2893*4882a593Smuzhiyun {
2894*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2895*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2896*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
2897*4882a593Smuzhiyun struct gbe_slave *slave = gbe_intf->slave;
2898*4882a593Smuzhiyun int port_num = slave->port_num;
2899*4882a593Smuzhiyun u32 reg, val;
2900*4882a593Smuzhiyun int ret;
2901*4882a593Smuzhiyun
2902*4882a593Smuzhiyun reg = readl(GBE_REG_ADDR(gbe_dev, switch_regs, id_ver));
2903*4882a593Smuzhiyun dev_dbg(gbe_dev->dev, "initializing gbe version %d.%d (%d) GBE identification value 0x%x\n",
2904*4882a593Smuzhiyun GBE_MAJOR_VERSION(reg), GBE_MINOR_VERSION(reg),
2905*4882a593Smuzhiyun GBE_RTL_VERSION(reg), GBE_IDENT(reg));
2906*4882a593Smuzhiyun
2907*4882a593Smuzhiyun /* For 10G and on NetCP 1.5, use directed to port */
2908*4882a593Smuzhiyun if (IS_SS_ID_XGBE(gbe_dev) || IS_SS_ID_MU(gbe_dev))
2909*4882a593Smuzhiyun gbe_intf->tx_pipe.flags = SWITCH_TO_PORT_IN_TAGINFO;
2910*4882a593Smuzhiyun
2911*4882a593Smuzhiyun if (gbe_dev->enable_ale)
2912*4882a593Smuzhiyun gbe_intf->tx_pipe.switch_to_port = 0;
2913*4882a593Smuzhiyun else
2914*4882a593Smuzhiyun gbe_intf->tx_pipe.switch_to_port = port_num;
2915*4882a593Smuzhiyun
2916*4882a593Smuzhiyun dev_dbg(gbe_dev->dev,
2917*4882a593Smuzhiyun "opened TX channel %s: %p with to port %d, flags %d\n",
2918*4882a593Smuzhiyun gbe_intf->tx_pipe.dma_chan_name,
2919*4882a593Smuzhiyun gbe_intf->tx_pipe.dma_channel,
2920*4882a593Smuzhiyun gbe_intf->tx_pipe.switch_to_port,
2921*4882a593Smuzhiyun gbe_intf->tx_pipe.flags);
2922*4882a593Smuzhiyun
2923*4882a593Smuzhiyun gbe_slave_stop(gbe_intf);
2924*4882a593Smuzhiyun
2925*4882a593Smuzhiyun /* disable priority elevation and enable statistics on all ports */
2926*4882a593Smuzhiyun writel(0, GBE_REG_ADDR(gbe_dev, switch_regs, ptype));
2927*4882a593Smuzhiyun
2928*4882a593Smuzhiyun /* Control register */
2929*4882a593Smuzhiyun val = GBE_CTL_P0_ENABLE;
2930*4882a593Smuzhiyun if (IS_SS_ID_MU(gbe_dev)) {
2931*4882a593Smuzhiyun val |= ETH_SW_CTL_P0_TX_CRC_REMOVE;
2932*4882a593Smuzhiyun netcp->hw_cap = ETH_SW_CAN_REMOVE_ETH_FCS;
2933*4882a593Smuzhiyun }
2934*4882a593Smuzhiyun writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, control));
2935*4882a593Smuzhiyun
2936*4882a593Smuzhiyun /* All statistics enabled and STAT AB visible by default */
2937*4882a593Smuzhiyun writel(gbe_dev->stats_en_mask, GBE_REG_ADDR(gbe_dev, switch_regs,
2938*4882a593Smuzhiyun stat_port_en));
2939*4882a593Smuzhiyun
2940*4882a593Smuzhiyun ret = gbe_slave_open(gbe_intf);
2941*4882a593Smuzhiyun if (ret)
2942*4882a593Smuzhiyun goto fail;
2943*4882a593Smuzhiyun
2944*4882a593Smuzhiyun netcp_register_txhook(netcp, GBE_TXHOOK_ORDER, gbe_txhook, gbe_intf);
2945*4882a593Smuzhiyun netcp_register_rxhook(netcp, GBE_RXHOOK_ORDER, gbe_rxhook, gbe_intf);
2946*4882a593Smuzhiyun
2947*4882a593Smuzhiyun slave->open = true;
2948*4882a593Smuzhiyun netcp_ethss_update_link_state(gbe_dev, slave, ndev);
2949*4882a593Smuzhiyun
2950*4882a593Smuzhiyun gbe_register_cpts(gbe_dev);
2951*4882a593Smuzhiyun
2952*4882a593Smuzhiyun return 0;
2953*4882a593Smuzhiyun
2954*4882a593Smuzhiyun fail:
2955*4882a593Smuzhiyun gbe_slave_stop(gbe_intf);
2956*4882a593Smuzhiyun return ret;
2957*4882a593Smuzhiyun }
2958*4882a593Smuzhiyun
gbe_close(void * intf_priv,struct net_device * ndev)2959*4882a593Smuzhiyun static int gbe_close(void *intf_priv, struct net_device *ndev)
2960*4882a593Smuzhiyun {
2961*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
2962*4882a593Smuzhiyun struct netcp_intf *netcp = netdev_priv(ndev);
2963*4882a593Smuzhiyun struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2964*4882a593Smuzhiyun
2965*4882a593Smuzhiyun gbe_unregister_cpts(gbe_dev);
2966*4882a593Smuzhiyun
2967*4882a593Smuzhiyun gbe_slave_stop(gbe_intf);
2968*4882a593Smuzhiyun
2969*4882a593Smuzhiyun netcp_unregister_rxhook(netcp, GBE_RXHOOK_ORDER, gbe_rxhook, gbe_intf);
2970*4882a593Smuzhiyun netcp_unregister_txhook(netcp, GBE_TXHOOK_ORDER, gbe_txhook, gbe_intf);
2971*4882a593Smuzhiyun
2972*4882a593Smuzhiyun gbe_intf->slave->open = false;
2973*4882a593Smuzhiyun atomic_set(&gbe_intf->slave->link_state, NETCP_LINK_STATE_INVALID);
2974*4882a593Smuzhiyun return 0;
2975*4882a593Smuzhiyun }
2976*4882a593Smuzhiyun
2977*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_TI_CPTS)
init_slave_ts_ctl(struct gbe_slave * slave)2978*4882a593Smuzhiyun static void init_slave_ts_ctl(struct gbe_slave *slave)
2979*4882a593Smuzhiyun {
2980*4882a593Smuzhiyun slave->ts_ctl.uni = 1;
2981*4882a593Smuzhiyun slave->ts_ctl.dst_port_map =
2982*4882a593Smuzhiyun (TS_CTL_DST_PORT >> TS_CTL_DST_PORT_SHIFT) & 0x3;
2983*4882a593Smuzhiyun slave->ts_ctl.maddr_map =
2984*4882a593Smuzhiyun (TS_CTL_MADDR_ALL >> TS_CTL_MADDR_SHIFT) & 0x1f;
2985*4882a593Smuzhiyun }
2986*4882a593Smuzhiyun
2987*4882a593Smuzhiyun #else
init_slave_ts_ctl(struct gbe_slave * slave)2988*4882a593Smuzhiyun static void init_slave_ts_ctl(struct gbe_slave *slave)
2989*4882a593Smuzhiyun {
2990*4882a593Smuzhiyun }
2991*4882a593Smuzhiyun #endif /* CONFIG_TI_CPTS */
2992*4882a593Smuzhiyun
init_slave(struct gbe_priv * gbe_dev,struct gbe_slave * slave,struct device_node * node)2993*4882a593Smuzhiyun static int init_slave(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
2994*4882a593Smuzhiyun struct device_node *node)
2995*4882a593Smuzhiyun {
2996*4882a593Smuzhiyun int port_reg_num;
2997*4882a593Smuzhiyun u32 port_reg_ofs, emac_reg_ofs;
2998*4882a593Smuzhiyun u32 port_reg_blk_sz, emac_reg_blk_sz;
2999*4882a593Smuzhiyun
3000*4882a593Smuzhiyun if (of_property_read_u32(node, "slave-port", &slave->slave_num)) {
3001*4882a593Smuzhiyun dev_err(gbe_dev->dev, "missing slave-port parameter\n");
3002*4882a593Smuzhiyun return -EINVAL;
3003*4882a593Smuzhiyun }
3004*4882a593Smuzhiyun
3005*4882a593Smuzhiyun if (of_property_read_u32(node, "link-interface",
3006*4882a593Smuzhiyun &slave->link_interface)) {
3007*4882a593Smuzhiyun dev_warn(gbe_dev->dev,
3008*4882a593Smuzhiyun "missing link-interface value defaulting to 1G mac-phy link\n");
3009*4882a593Smuzhiyun slave->link_interface = SGMII_LINK_MAC_PHY;
3010*4882a593Smuzhiyun }
3011*4882a593Smuzhiyun
3012*4882a593Smuzhiyun slave->node = node;
3013*4882a593Smuzhiyun slave->open = false;
3014*4882a593Smuzhiyun if ((slave->link_interface == SGMII_LINK_MAC_PHY) ||
3015*4882a593Smuzhiyun (slave->link_interface == RGMII_LINK_MAC_PHY) ||
3016*4882a593Smuzhiyun (slave->link_interface == XGMII_LINK_MAC_PHY))
3017*4882a593Smuzhiyun slave->phy_node = of_parse_phandle(node, "phy-handle", 0);
3018*4882a593Smuzhiyun slave->port_num = gbe_get_slave_port(gbe_dev, slave->slave_num);
3019*4882a593Smuzhiyun
3020*4882a593Smuzhiyun if (slave->link_interface >= XGMII_LINK_MAC_PHY)
3021*4882a593Smuzhiyun slave->mac_control = GBE_DEF_10G_MAC_CONTROL;
3022*4882a593Smuzhiyun else
3023*4882a593Smuzhiyun slave->mac_control = GBE_DEF_1G_MAC_CONTROL;
3024*4882a593Smuzhiyun
3025*4882a593Smuzhiyun /* Emac regs memmap are contiguous but port regs are not */
3026*4882a593Smuzhiyun port_reg_num = slave->slave_num;
3027*4882a593Smuzhiyun if (IS_SS_ID_VER_14(gbe_dev)) {
3028*4882a593Smuzhiyun if (slave->slave_num > 1) {
3029*4882a593Smuzhiyun port_reg_ofs = GBE13_SLAVE_PORT2_OFFSET;
3030*4882a593Smuzhiyun port_reg_num -= 2;
3031*4882a593Smuzhiyun } else {
3032*4882a593Smuzhiyun port_reg_ofs = GBE13_SLAVE_PORT_OFFSET;
3033*4882a593Smuzhiyun }
3034*4882a593Smuzhiyun emac_reg_ofs = GBE13_EMAC_OFFSET;
3035*4882a593Smuzhiyun port_reg_blk_sz = 0x30;
3036*4882a593Smuzhiyun emac_reg_blk_sz = 0x40;
3037*4882a593Smuzhiyun } else if (IS_SS_ID_MU(gbe_dev)) {
3038*4882a593Smuzhiyun port_reg_ofs = GBENU_SLAVE_PORT_OFFSET;
3039*4882a593Smuzhiyun emac_reg_ofs = GBENU_EMAC_OFFSET;
3040*4882a593Smuzhiyun port_reg_blk_sz = 0x1000;
3041*4882a593Smuzhiyun emac_reg_blk_sz = 0x1000;
3042*4882a593Smuzhiyun } else if (IS_SS_ID_XGBE(gbe_dev)) {
3043*4882a593Smuzhiyun port_reg_ofs = XGBE10_SLAVE_PORT_OFFSET;
3044*4882a593Smuzhiyun emac_reg_ofs = XGBE10_EMAC_OFFSET;
3045*4882a593Smuzhiyun port_reg_blk_sz = 0x30;
3046*4882a593Smuzhiyun emac_reg_blk_sz = 0x40;
3047*4882a593Smuzhiyun } else {
3048*4882a593Smuzhiyun dev_err(gbe_dev->dev, "unknown ethss(0x%x)\n",
3049*4882a593Smuzhiyun gbe_dev->ss_version);
3050*4882a593Smuzhiyun return -EINVAL;
3051*4882a593Smuzhiyun }
3052*4882a593Smuzhiyun
3053*4882a593Smuzhiyun slave->port_regs = gbe_dev->switch_regs + port_reg_ofs +
3054*4882a593Smuzhiyun (port_reg_blk_sz * port_reg_num);
3055*4882a593Smuzhiyun slave->emac_regs = gbe_dev->switch_regs + emac_reg_ofs +
3056*4882a593Smuzhiyun (emac_reg_blk_sz * slave->slave_num);
3057*4882a593Smuzhiyun
3058*4882a593Smuzhiyun if (IS_SS_ID_VER_14(gbe_dev)) {
3059*4882a593Smuzhiyun /* Initialize slave port register offsets */
3060*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, port_vlan);
3061*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
3062*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, sa_lo);
3063*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, sa_hi);
3064*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, ts_ctl);
3065*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
3066*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, ts_vlan);
3067*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
3068*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
3069*4882a593Smuzhiyun
3070*4882a593Smuzhiyun /* Initialize EMAC register offsets */
3071*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, emac_regs, mac_control);
3072*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, emac_regs, soft_reset);
3073*4882a593Smuzhiyun GBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
3074*4882a593Smuzhiyun
3075*4882a593Smuzhiyun } else if (IS_SS_ID_MU(gbe_dev)) {
3076*4882a593Smuzhiyun /* Initialize slave port register offsets */
3077*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, port_vlan);
3078*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, tx_pri_map);
3079*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, rx_pri_map);
3080*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, sa_lo);
3081*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, sa_hi);
3082*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, ts_ctl);
3083*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
3084*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, ts_vlan);
3085*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
3086*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, ts_ctl2);
3087*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, port_regs, rx_maxlen);
3088*4882a593Smuzhiyun
3089*4882a593Smuzhiyun /* Initialize EMAC register offsets */
3090*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, emac_regs, mac_control);
3091*4882a593Smuzhiyun GBENU_SET_REG_OFS(slave, emac_regs, soft_reset);
3092*4882a593Smuzhiyun
3093*4882a593Smuzhiyun } else if (IS_SS_ID_XGBE(gbe_dev)) {
3094*4882a593Smuzhiyun /* Initialize slave port register offsets */
3095*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, port_vlan);
3096*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
3097*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, sa_lo);
3098*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, sa_hi);
3099*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, ts_ctl);
3100*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
3101*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, ts_vlan);
3102*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
3103*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
3104*4882a593Smuzhiyun
3105*4882a593Smuzhiyun /* Initialize EMAC register offsets */
3106*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, emac_regs, mac_control);
3107*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, emac_regs, soft_reset);
3108*4882a593Smuzhiyun XGBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
3109*4882a593Smuzhiyun }
3110*4882a593Smuzhiyun
3111*4882a593Smuzhiyun atomic_set(&slave->link_state, NETCP_LINK_STATE_INVALID);
3112*4882a593Smuzhiyun
3113*4882a593Smuzhiyun init_slave_ts_ctl(slave);
3114*4882a593Smuzhiyun return 0;
3115*4882a593Smuzhiyun }
3116*4882a593Smuzhiyun
init_secondary_ports(struct gbe_priv * gbe_dev,struct device_node * node)3117*4882a593Smuzhiyun static void init_secondary_ports(struct gbe_priv *gbe_dev,
3118*4882a593Smuzhiyun struct device_node *node)
3119*4882a593Smuzhiyun {
3120*4882a593Smuzhiyun struct device *dev = gbe_dev->dev;
3121*4882a593Smuzhiyun phy_interface_t phy_mode;
3122*4882a593Smuzhiyun struct gbe_priv **priv;
3123*4882a593Smuzhiyun struct device_node *port;
3124*4882a593Smuzhiyun struct gbe_slave *slave;
3125*4882a593Smuzhiyun bool mac_phy_link = false;
3126*4882a593Smuzhiyun
3127*4882a593Smuzhiyun for_each_child_of_node(node, port) {
3128*4882a593Smuzhiyun slave = devm_kzalloc(dev, sizeof(*slave), GFP_KERNEL);
3129*4882a593Smuzhiyun if (!slave) {
3130*4882a593Smuzhiyun dev_err(dev, "memory alloc failed for secondary port(%pOFn), skipping...\n",
3131*4882a593Smuzhiyun port);
3132*4882a593Smuzhiyun continue;
3133*4882a593Smuzhiyun }
3134*4882a593Smuzhiyun
3135*4882a593Smuzhiyun if (init_slave(gbe_dev, slave, port)) {
3136*4882a593Smuzhiyun dev_err(dev,
3137*4882a593Smuzhiyun "Failed to initialize secondary port(%pOFn), skipping...\n",
3138*4882a593Smuzhiyun port);
3139*4882a593Smuzhiyun devm_kfree(dev, slave);
3140*4882a593Smuzhiyun continue;
3141*4882a593Smuzhiyun }
3142*4882a593Smuzhiyun
3143*4882a593Smuzhiyun if (!IS_SS_ID_2U(gbe_dev))
3144*4882a593Smuzhiyun gbe_sgmii_config(gbe_dev, slave);
3145*4882a593Smuzhiyun gbe_port_reset(slave);
3146*4882a593Smuzhiyun gbe_port_config(gbe_dev, slave, gbe_dev->rx_packet_max);
3147*4882a593Smuzhiyun list_add_tail(&slave->slave_list, &gbe_dev->secondary_slaves);
3148*4882a593Smuzhiyun gbe_dev->num_slaves++;
3149*4882a593Smuzhiyun if ((slave->link_interface == SGMII_LINK_MAC_PHY) ||
3150*4882a593Smuzhiyun (slave->link_interface == XGMII_LINK_MAC_PHY))
3151*4882a593Smuzhiyun mac_phy_link = true;
3152*4882a593Smuzhiyun
3153*4882a593Smuzhiyun slave->open = true;
3154*4882a593Smuzhiyun if (gbe_dev->num_slaves >= gbe_dev->max_num_slaves) {
3155*4882a593Smuzhiyun of_node_put(port);
3156*4882a593Smuzhiyun break;
3157*4882a593Smuzhiyun }
3158*4882a593Smuzhiyun }
3159*4882a593Smuzhiyun
3160*4882a593Smuzhiyun /* of_phy_connect() is needed only for MAC-PHY interface */
3161*4882a593Smuzhiyun if (!mac_phy_link)
3162*4882a593Smuzhiyun return;
3163*4882a593Smuzhiyun
3164*4882a593Smuzhiyun /* Allocate dummy netdev device for attaching to phy device */
3165*4882a593Smuzhiyun gbe_dev->dummy_ndev = alloc_netdev(sizeof(gbe_dev), "dummy",
3166*4882a593Smuzhiyun NET_NAME_UNKNOWN, ether_setup);
3167*4882a593Smuzhiyun if (!gbe_dev->dummy_ndev) {
3168*4882a593Smuzhiyun dev_err(dev,
3169*4882a593Smuzhiyun "Failed to allocate dummy netdev for secondary ports, skipping phy_connect()...\n");
3170*4882a593Smuzhiyun return;
3171*4882a593Smuzhiyun }
3172*4882a593Smuzhiyun priv = netdev_priv(gbe_dev->dummy_ndev);
3173*4882a593Smuzhiyun *priv = gbe_dev;
3174*4882a593Smuzhiyun
3175*4882a593Smuzhiyun if (slave->link_interface == SGMII_LINK_MAC_PHY) {
3176*4882a593Smuzhiyun phy_mode = PHY_INTERFACE_MODE_SGMII;
3177*4882a593Smuzhiyun slave->phy_port_t = PORT_MII;
3178*4882a593Smuzhiyun } else if (slave->link_interface == RGMII_LINK_MAC_PHY) {
3179*4882a593Smuzhiyun phy_mode = PHY_INTERFACE_MODE_RGMII;
3180*4882a593Smuzhiyun slave->phy_port_t = PORT_MII;
3181*4882a593Smuzhiyun } else {
3182*4882a593Smuzhiyun phy_mode = PHY_INTERFACE_MODE_NA;
3183*4882a593Smuzhiyun slave->phy_port_t = PORT_FIBRE;
3184*4882a593Smuzhiyun }
3185*4882a593Smuzhiyun
3186*4882a593Smuzhiyun for_each_sec_slave(slave, gbe_dev) {
3187*4882a593Smuzhiyun if ((slave->link_interface != SGMII_LINK_MAC_PHY) &&
3188*4882a593Smuzhiyun (slave->link_interface != RGMII_LINK_MAC_PHY) &&
3189*4882a593Smuzhiyun (slave->link_interface != XGMII_LINK_MAC_PHY))
3190*4882a593Smuzhiyun continue;
3191*4882a593Smuzhiyun slave->phy =
3192*4882a593Smuzhiyun of_phy_connect(gbe_dev->dummy_ndev,
3193*4882a593Smuzhiyun slave->phy_node,
3194*4882a593Smuzhiyun gbe_adjust_link_sec_slaves,
3195*4882a593Smuzhiyun 0, phy_mode);
3196*4882a593Smuzhiyun if (!slave->phy) {
3197*4882a593Smuzhiyun dev_err(dev, "phy not found for slave %d\n",
3198*4882a593Smuzhiyun slave->slave_num);
3199*4882a593Smuzhiyun } else {
3200*4882a593Smuzhiyun dev_dbg(dev, "phy found: id is: 0x%s\n",
3201*4882a593Smuzhiyun phydev_name(slave->phy));
3202*4882a593Smuzhiyun phy_start(slave->phy);
3203*4882a593Smuzhiyun }
3204*4882a593Smuzhiyun }
3205*4882a593Smuzhiyun }
3206*4882a593Smuzhiyun
free_secondary_ports(struct gbe_priv * gbe_dev)3207*4882a593Smuzhiyun static void free_secondary_ports(struct gbe_priv *gbe_dev)
3208*4882a593Smuzhiyun {
3209*4882a593Smuzhiyun struct gbe_slave *slave;
3210*4882a593Smuzhiyun
3211*4882a593Smuzhiyun while (!list_empty(&gbe_dev->secondary_slaves)) {
3212*4882a593Smuzhiyun slave = first_sec_slave(gbe_dev);
3213*4882a593Smuzhiyun
3214*4882a593Smuzhiyun if (slave->phy)
3215*4882a593Smuzhiyun phy_disconnect(slave->phy);
3216*4882a593Smuzhiyun list_del(&slave->slave_list);
3217*4882a593Smuzhiyun }
3218*4882a593Smuzhiyun if (gbe_dev->dummy_ndev)
3219*4882a593Smuzhiyun free_netdev(gbe_dev->dummy_ndev);
3220*4882a593Smuzhiyun }
3221*4882a593Smuzhiyun
set_xgbe_ethss10_priv(struct gbe_priv * gbe_dev,struct device_node * node)3222*4882a593Smuzhiyun static int set_xgbe_ethss10_priv(struct gbe_priv *gbe_dev,
3223*4882a593Smuzhiyun struct device_node *node)
3224*4882a593Smuzhiyun {
3225*4882a593Smuzhiyun struct resource res;
3226*4882a593Smuzhiyun void __iomem *regs;
3227*4882a593Smuzhiyun int ret, i;
3228*4882a593Smuzhiyun
3229*4882a593Smuzhiyun ret = of_address_to_resource(node, XGBE_SS_REG_INDEX, &res);
3230*4882a593Smuzhiyun if (ret) {
3231*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3232*4882a593Smuzhiyun "Can't xlate xgbe of node(%pOFn) ss address at %d\n",
3233*4882a593Smuzhiyun node, XGBE_SS_REG_INDEX);
3234*4882a593Smuzhiyun return ret;
3235*4882a593Smuzhiyun }
3236*4882a593Smuzhiyun
3237*4882a593Smuzhiyun regs = devm_ioremap_resource(gbe_dev->dev, &res);
3238*4882a593Smuzhiyun if (IS_ERR(regs)) {
3239*4882a593Smuzhiyun dev_err(gbe_dev->dev, "Failed to map xgbe ss register base\n");
3240*4882a593Smuzhiyun return PTR_ERR(regs);
3241*4882a593Smuzhiyun }
3242*4882a593Smuzhiyun gbe_dev->ss_regs = regs;
3243*4882a593Smuzhiyun
3244*4882a593Smuzhiyun ret = of_address_to_resource(node, XGBE_SM_REG_INDEX, &res);
3245*4882a593Smuzhiyun if (ret) {
3246*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3247*4882a593Smuzhiyun "Can't xlate xgbe of node(%pOFn) sm address at %d\n",
3248*4882a593Smuzhiyun node, XGBE_SM_REG_INDEX);
3249*4882a593Smuzhiyun return ret;
3250*4882a593Smuzhiyun }
3251*4882a593Smuzhiyun
3252*4882a593Smuzhiyun regs = devm_ioremap_resource(gbe_dev->dev, &res);
3253*4882a593Smuzhiyun if (IS_ERR(regs)) {
3254*4882a593Smuzhiyun dev_err(gbe_dev->dev, "Failed to map xgbe sm register base\n");
3255*4882a593Smuzhiyun return PTR_ERR(regs);
3256*4882a593Smuzhiyun }
3257*4882a593Smuzhiyun gbe_dev->switch_regs = regs;
3258*4882a593Smuzhiyun
3259*4882a593Smuzhiyun ret = of_address_to_resource(node, XGBE_SERDES_REG_INDEX, &res);
3260*4882a593Smuzhiyun if (ret) {
3261*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3262*4882a593Smuzhiyun "Can't xlate xgbe serdes of node(%pOFn) address at %d\n",
3263*4882a593Smuzhiyun node, XGBE_SERDES_REG_INDEX);
3264*4882a593Smuzhiyun return ret;
3265*4882a593Smuzhiyun }
3266*4882a593Smuzhiyun
3267*4882a593Smuzhiyun regs = devm_ioremap_resource(gbe_dev->dev, &res);
3268*4882a593Smuzhiyun if (IS_ERR(regs)) {
3269*4882a593Smuzhiyun dev_err(gbe_dev->dev, "Failed to map xgbe serdes register base\n");
3270*4882a593Smuzhiyun return PTR_ERR(regs);
3271*4882a593Smuzhiyun }
3272*4882a593Smuzhiyun gbe_dev->xgbe_serdes_regs = regs;
3273*4882a593Smuzhiyun
3274*4882a593Smuzhiyun gbe_dev->num_stats_mods = gbe_dev->max_num_ports;
3275*4882a593Smuzhiyun gbe_dev->et_stats = xgbe10_et_stats;
3276*4882a593Smuzhiyun gbe_dev->num_et_stats = ARRAY_SIZE(xgbe10_et_stats);
3277*4882a593Smuzhiyun
3278*4882a593Smuzhiyun gbe_dev->hw_stats = devm_kcalloc(gbe_dev->dev,
3279*4882a593Smuzhiyun gbe_dev->num_et_stats, sizeof(u64),
3280*4882a593Smuzhiyun GFP_KERNEL);
3281*4882a593Smuzhiyun if (!gbe_dev->hw_stats) {
3282*4882a593Smuzhiyun dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
3283*4882a593Smuzhiyun return -ENOMEM;
3284*4882a593Smuzhiyun }
3285*4882a593Smuzhiyun
3286*4882a593Smuzhiyun gbe_dev->hw_stats_prev =
3287*4882a593Smuzhiyun devm_kcalloc(gbe_dev->dev,
3288*4882a593Smuzhiyun gbe_dev->num_et_stats, sizeof(u32),
3289*4882a593Smuzhiyun GFP_KERNEL);
3290*4882a593Smuzhiyun if (!gbe_dev->hw_stats_prev) {
3291*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3292*4882a593Smuzhiyun "hw_stats_prev memory allocation failed\n");
3293*4882a593Smuzhiyun return -ENOMEM;
3294*4882a593Smuzhiyun }
3295*4882a593Smuzhiyun
3296*4882a593Smuzhiyun gbe_dev->ss_version = XGBE_SS_VERSION_10;
3297*4882a593Smuzhiyun gbe_dev->sgmii_port_regs = gbe_dev->ss_regs +
3298*4882a593Smuzhiyun XGBE10_SGMII_MODULE_OFFSET;
3299*4882a593Smuzhiyun gbe_dev->host_port_regs = gbe_dev->ss_regs + XGBE10_HOST_PORT_OFFSET;
3300*4882a593Smuzhiyun
3301*4882a593Smuzhiyun for (i = 0; i < gbe_dev->max_num_ports; i++)
3302*4882a593Smuzhiyun gbe_dev->hw_stats_regs[i] = gbe_dev->switch_regs +
3303*4882a593Smuzhiyun XGBE10_HW_STATS_OFFSET + (GBE_HW_STATS_REG_MAP_SZ * i);
3304*4882a593Smuzhiyun
3305*4882a593Smuzhiyun gbe_dev->ale_reg = gbe_dev->switch_regs + XGBE10_ALE_OFFSET;
3306*4882a593Smuzhiyun gbe_dev->cpts_reg = gbe_dev->switch_regs + XGBE10_CPTS_OFFSET;
3307*4882a593Smuzhiyun gbe_dev->ale_ports = gbe_dev->max_num_ports;
3308*4882a593Smuzhiyun gbe_dev->host_port = XGBE10_HOST_PORT_NUM;
3309*4882a593Smuzhiyun gbe_dev->stats_en_mask = (1 << (gbe_dev->max_num_ports)) - 1;
3310*4882a593Smuzhiyun
3311*4882a593Smuzhiyun /* Subsystem registers */
3312*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
3313*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, ss_regs, control);
3314*4882a593Smuzhiyun
3315*4882a593Smuzhiyun /* Switch module registers */
3316*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
3317*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, switch_regs, control);
3318*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
3319*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
3320*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
3321*4882a593Smuzhiyun
3322*4882a593Smuzhiyun /* Host port registers */
3323*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
3324*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map);
3325*4882a593Smuzhiyun XGBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
3326*4882a593Smuzhiyun return 0;
3327*4882a593Smuzhiyun }
3328*4882a593Smuzhiyun
get_gbe_resource_version(struct gbe_priv * gbe_dev,struct device_node * node)3329*4882a593Smuzhiyun static int get_gbe_resource_version(struct gbe_priv *gbe_dev,
3330*4882a593Smuzhiyun struct device_node *node)
3331*4882a593Smuzhiyun {
3332*4882a593Smuzhiyun struct resource res;
3333*4882a593Smuzhiyun void __iomem *regs;
3334*4882a593Smuzhiyun int ret;
3335*4882a593Smuzhiyun
3336*4882a593Smuzhiyun ret = of_address_to_resource(node, GBE_SS_REG_INDEX, &res);
3337*4882a593Smuzhiyun if (ret) {
3338*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3339*4882a593Smuzhiyun "Can't translate of node(%pOFn) of gbe ss address at %d\n",
3340*4882a593Smuzhiyun node, GBE_SS_REG_INDEX);
3341*4882a593Smuzhiyun return ret;
3342*4882a593Smuzhiyun }
3343*4882a593Smuzhiyun
3344*4882a593Smuzhiyun regs = devm_ioremap_resource(gbe_dev->dev, &res);
3345*4882a593Smuzhiyun if (IS_ERR(regs)) {
3346*4882a593Smuzhiyun dev_err(gbe_dev->dev, "Failed to map gbe register base\n");
3347*4882a593Smuzhiyun return PTR_ERR(regs);
3348*4882a593Smuzhiyun }
3349*4882a593Smuzhiyun gbe_dev->ss_regs = regs;
3350*4882a593Smuzhiyun gbe_dev->ss_version = readl(gbe_dev->ss_regs);
3351*4882a593Smuzhiyun return 0;
3352*4882a593Smuzhiyun }
3353*4882a593Smuzhiyun
set_gbe_ethss14_priv(struct gbe_priv * gbe_dev,struct device_node * node)3354*4882a593Smuzhiyun static int set_gbe_ethss14_priv(struct gbe_priv *gbe_dev,
3355*4882a593Smuzhiyun struct device_node *node)
3356*4882a593Smuzhiyun {
3357*4882a593Smuzhiyun struct resource res;
3358*4882a593Smuzhiyun void __iomem *regs;
3359*4882a593Smuzhiyun int i, ret;
3360*4882a593Smuzhiyun
3361*4882a593Smuzhiyun ret = of_address_to_resource(node, GBE_SGMII34_REG_INDEX, &res);
3362*4882a593Smuzhiyun if (ret) {
3363*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3364*4882a593Smuzhiyun "Can't translate of gbe node(%pOFn) address at index %d\n",
3365*4882a593Smuzhiyun node, GBE_SGMII34_REG_INDEX);
3366*4882a593Smuzhiyun return ret;
3367*4882a593Smuzhiyun }
3368*4882a593Smuzhiyun
3369*4882a593Smuzhiyun regs = devm_ioremap_resource(gbe_dev->dev, &res);
3370*4882a593Smuzhiyun if (IS_ERR(regs)) {
3371*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3372*4882a593Smuzhiyun "Failed to map gbe sgmii port34 register base\n");
3373*4882a593Smuzhiyun return PTR_ERR(regs);
3374*4882a593Smuzhiyun }
3375*4882a593Smuzhiyun gbe_dev->sgmii_port34_regs = regs;
3376*4882a593Smuzhiyun
3377*4882a593Smuzhiyun ret = of_address_to_resource(node, GBE_SM_REG_INDEX, &res);
3378*4882a593Smuzhiyun if (ret) {
3379*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3380*4882a593Smuzhiyun "Can't translate of gbe node(%pOFn) address at index %d\n",
3381*4882a593Smuzhiyun node, GBE_SM_REG_INDEX);
3382*4882a593Smuzhiyun return ret;
3383*4882a593Smuzhiyun }
3384*4882a593Smuzhiyun
3385*4882a593Smuzhiyun regs = devm_ioremap_resource(gbe_dev->dev, &res);
3386*4882a593Smuzhiyun if (IS_ERR(regs)) {
3387*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3388*4882a593Smuzhiyun "Failed to map gbe switch module register base\n");
3389*4882a593Smuzhiyun return PTR_ERR(regs);
3390*4882a593Smuzhiyun }
3391*4882a593Smuzhiyun gbe_dev->switch_regs = regs;
3392*4882a593Smuzhiyun
3393*4882a593Smuzhiyun gbe_dev->num_stats_mods = gbe_dev->max_num_slaves;
3394*4882a593Smuzhiyun gbe_dev->et_stats = gbe13_et_stats;
3395*4882a593Smuzhiyun gbe_dev->num_et_stats = ARRAY_SIZE(gbe13_et_stats);
3396*4882a593Smuzhiyun
3397*4882a593Smuzhiyun gbe_dev->hw_stats = devm_kcalloc(gbe_dev->dev,
3398*4882a593Smuzhiyun gbe_dev->num_et_stats, sizeof(u64),
3399*4882a593Smuzhiyun GFP_KERNEL);
3400*4882a593Smuzhiyun if (!gbe_dev->hw_stats) {
3401*4882a593Smuzhiyun dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
3402*4882a593Smuzhiyun return -ENOMEM;
3403*4882a593Smuzhiyun }
3404*4882a593Smuzhiyun
3405*4882a593Smuzhiyun gbe_dev->hw_stats_prev =
3406*4882a593Smuzhiyun devm_kcalloc(gbe_dev->dev,
3407*4882a593Smuzhiyun gbe_dev->num_et_stats, sizeof(u32),
3408*4882a593Smuzhiyun GFP_KERNEL);
3409*4882a593Smuzhiyun if (!gbe_dev->hw_stats_prev) {
3410*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3411*4882a593Smuzhiyun "hw_stats_prev memory allocation failed\n");
3412*4882a593Smuzhiyun return -ENOMEM;
3413*4882a593Smuzhiyun }
3414*4882a593Smuzhiyun
3415*4882a593Smuzhiyun gbe_dev->sgmii_port_regs = gbe_dev->ss_regs + GBE13_SGMII_MODULE_OFFSET;
3416*4882a593Smuzhiyun gbe_dev->host_port_regs = gbe_dev->switch_regs + GBE13_HOST_PORT_OFFSET;
3417*4882a593Smuzhiyun
3418*4882a593Smuzhiyun /* K2HK has only 2 hw stats modules visible at a time, so
3419*4882a593Smuzhiyun * module 0 & 2 points to one base and
3420*4882a593Smuzhiyun * module 1 & 3 points to the other base
3421*4882a593Smuzhiyun */
3422*4882a593Smuzhiyun for (i = 0; i < gbe_dev->max_num_slaves; i++) {
3423*4882a593Smuzhiyun gbe_dev->hw_stats_regs[i] =
3424*4882a593Smuzhiyun gbe_dev->switch_regs + GBE13_HW_STATS_OFFSET +
3425*4882a593Smuzhiyun (GBE_HW_STATS_REG_MAP_SZ * (i & 0x1));
3426*4882a593Smuzhiyun }
3427*4882a593Smuzhiyun
3428*4882a593Smuzhiyun gbe_dev->cpts_reg = gbe_dev->switch_regs + GBE13_CPTS_OFFSET;
3429*4882a593Smuzhiyun gbe_dev->ale_reg = gbe_dev->switch_regs + GBE13_ALE_OFFSET;
3430*4882a593Smuzhiyun gbe_dev->ale_ports = gbe_dev->max_num_ports;
3431*4882a593Smuzhiyun gbe_dev->host_port = GBE13_HOST_PORT_NUM;
3432*4882a593Smuzhiyun gbe_dev->stats_en_mask = GBE13_REG_VAL_STAT_ENABLE_ALL;
3433*4882a593Smuzhiyun
3434*4882a593Smuzhiyun /* Subsystem registers */
3435*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
3436*4882a593Smuzhiyun
3437*4882a593Smuzhiyun /* Switch module registers */
3438*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
3439*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, switch_regs, control);
3440*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, switch_regs, soft_reset);
3441*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
3442*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
3443*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
3444*4882a593Smuzhiyun
3445*4882a593Smuzhiyun /* Host port registers */
3446*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
3447*4882a593Smuzhiyun GBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
3448*4882a593Smuzhiyun return 0;
3449*4882a593Smuzhiyun }
3450*4882a593Smuzhiyun
set_gbenu_ethss_priv(struct gbe_priv * gbe_dev,struct device_node * node)3451*4882a593Smuzhiyun static int set_gbenu_ethss_priv(struct gbe_priv *gbe_dev,
3452*4882a593Smuzhiyun struct device_node *node)
3453*4882a593Smuzhiyun {
3454*4882a593Smuzhiyun struct resource res;
3455*4882a593Smuzhiyun void __iomem *regs;
3456*4882a593Smuzhiyun int i, ret;
3457*4882a593Smuzhiyun
3458*4882a593Smuzhiyun gbe_dev->num_stats_mods = gbe_dev->max_num_ports;
3459*4882a593Smuzhiyun gbe_dev->et_stats = gbenu_et_stats;
3460*4882a593Smuzhiyun
3461*4882a593Smuzhiyun if (IS_SS_ID_MU(gbe_dev))
3462*4882a593Smuzhiyun gbe_dev->num_et_stats = GBENU_ET_STATS_HOST_SIZE +
3463*4882a593Smuzhiyun (gbe_dev->max_num_slaves * GBENU_ET_STATS_PORT_SIZE);
3464*4882a593Smuzhiyun else
3465*4882a593Smuzhiyun gbe_dev->num_et_stats = GBENU_ET_STATS_HOST_SIZE +
3466*4882a593Smuzhiyun GBENU_ET_STATS_PORT_SIZE;
3467*4882a593Smuzhiyun
3468*4882a593Smuzhiyun gbe_dev->hw_stats = devm_kcalloc(gbe_dev->dev,
3469*4882a593Smuzhiyun gbe_dev->num_et_stats, sizeof(u64),
3470*4882a593Smuzhiyun GFP_KERNEL);
3471*4882a593Smuzhiyun if (!gbe_dev->hw_stats) {
3472*4882a593Smuzhiyun dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
3473*4882a593Smuzhiyun return -ENOMEM;
3474*4882a593Smuzhiyun }
3475*4882a593Smuzhiyun
3476*4882a593Smuzhiyun gbe_dev->hw_stats_prev =
3477*4882a593Smuzhiyun devm_kcalloc(gbe_dev->dev,
3478*4882a593Smuzhiyun gbe_dev->num_et_stats, sizeof(u32),
3479*4882a593Smuzhiyun GFP_KERNEL);
3480*4882a593Smuzhiyun if (!gbe_dev->hw_stats_prev) {
3481*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3482*4882a593Smuzhiyun "hw_stats_prev memory allocation failed\n");
3483*4882a593Smuzhiyun return -ENOMEM;
3484*4882a593Smuzhiyun }
3485*4882a593Smuzhiyun
3486*4882a593Smuzhiyun ret = of_address_to_resource(node, GBENU_SM_REG_INDEX, &res);
3487*4882a593Smuzhiyun if (ret) {
3488*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3489*4882a593Smuzhiyun "Can't translate of gbenu node(%pOFn) addr at index %d\n",
3490*4882a593Smuzhiyun node, GBENU_SM_REG_INDEX);
3491*4882a593Smuzhiyun return ret;
3492*4882a593Smuzhiyun }
3493*4882a593Smuzhiyun
3494*4882a593Smuzhiyun regs = devm_ioremap_resource(gbe_dev->dev, &res);
3495*4882a593Smuzhiyun if (IS_ERR(regs)) {
3496*4882a593Smuzhiyun dev_err(gbe_dev->dev,
3497*4882a593Smuzhiyun "Failed to map gbenu switch module register base\n");
3498*4882a593Smuzhiyun return PTR_ERR(regs);
3499*4882a593Smuzhiyun }
3500*4882a593Smuzhiyun gbe_dev->switch_regs = regs;
3501*4882a593Smuzhiyun
3502*4882a593Smuzhiyun if (!IS_SS_ID_2U(gbe_dev))
3503*4882a593Smuzhiyun gbe_dev->sgmii_port_regs =
3504*4882a593Smuzhiyun gbe_dev->ss_regs + GBENU_SGMII_MODULE_OFFSET;
3505*4882a593Smuzhiyun
3506*4882a593Smuzhiyun /* Although sgmii modules are mem mapped to one contiguous
3507*4882a593Smuzhiyun * region on GBENU devices, setting sgmii_port34_regs allows
3508*4882a593Smuzhiyun * consistent code when accessing sgmii api
3509*4882a593Smuzhiyun */
3510*4882a593Smuzhiyun gbe_dev->sgmii_port34_regs = gbe_dev->sgmii_port_regs +
3511*4882a593Smuzhiyun (2 * GBENU_SGMII_MODULE_SIZE);
3512*4882a593Smuzhiyun
3513*4882a593Smuzhiyun gbe_dev->host_port_regs = gbe_dev->switch_regs + GBENU_HOST_PORT_OFFSET;
3514*4882a593Smuzhiyun
3515*4882a593Smuzhiyun for (i = 0; i < (gbe_dev->max_num_ports); i++)
3516*4882a593Smuzhiyun gbe_dev->hw_stats_regs[i] = gbe_dev->switch_regs +
3517*4882a593Smuzhiyun GBENU_HW_STATS_OFFSET + (GBENU_HW_STATS_REG_MAP_SZ * i);
3518*4882a593Smuzhiyun
3519*4882a593Smuzhiyun gbe_dev->cpts_reg = gbe_dev->switch_regs + GBENU_CPTS_OFFSET;
3520*4882a593Smuzhiyun gbe_dev->ale_reg = gbe_dev->switch_regs + GBENU_ALE_OFFSET;
3521*4882a593Smuzhiyun gbe_dev->ale_ports = gbe_dev->max_num_ports;
3522*4882a593Smuzhiyun gbe_dev->host_port = GBENU_HOST_PORT_NUM;
3523*4882a593Smuzhiyun gbe_dev->stats_en_mask = (1 << (gbe_dev->max_num_ports)) - 1;
3524*4882a593Smuzhiyun
3525*4882a593Smuzhiyun /* Subsystem registers */
3526*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
3527*4882a593Smuzhiyun /* ok to set for MU, but used by 2U only */
3528*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, ss_regs, rgmii_status);
3529*4882a593Smuzhiyun
3530*4882a593Smuzhiyun /* Switch module registers */
3531*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
3532*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, switch_regs, control);
3533*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
3534*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, switch_regs, ptype);
3535*4882a593Smuzhiyun
3536*4882a593Smuzhiyun /* Host port registers */
3537*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
3538*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
3539*4882a593Smuzhiyun
3540*4882a593Smuzhiyun /* For NU only. 2U does not need tx_pri_map.
3541*4882a593Smuzhiyun * NU cppi port 0 tx pkt streaming interface has (n-1)*8 egress threads
3542*4882a593Smuzhiyun * while 2U has only 1 such thread
3543*4882a593Smuzhiyun */
3544*4882a593Smuzhiyun GBENU_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map);
3545*4882a593Smuzhiyun return 0;
3546*4882a593Smuzhiyun }
3547*4882a593Smuzhiyun
gbe_probe(struct netcp_device * netcp_device,struct device * dev,struct device_node * node,void ** inst_priv)3548*4882a593Smuzhiyun static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
3549*4882a593Smuzhiyun struct device_node *node, void **inst_priv)
3550*4882a593Smuzhiyun {
3551*4882a593Smuzhiyun struct device_node *interfaces, *interface, *cpts_node;
3552*4882a593Smuzhiyun struct device_node *secondary_ports;
3553*4882a593Smuzhiyun struct cpsw_ale_params ale_params;
3554*4882a593Smuzhiyun struct gbe_priv *gbe_dev;
3555*4882a593Smuzhiyun u32 slave_num;
3556*4882a593Smuzhiyun int i, ret = 0;
3557*4882a593Smuzhiyun
3558*4882a593Smuzhiyun if (!node) {
3559*4882a593Smuzhiyun dev_err(dev, "device tree info unavailable\n");
3560*4882a593Smuzhiyun return -ENODEV;
3561*4882a593Smuzhiyun }
3562*4882a593Smuzhiyun
3563*4882a593Smuzhiyun gbe_dev = devm_kzalloc(dev, sizeof(struct gbe_priv), GFP_KERNEL);
3564*4882a593Smuzhiyun if (!gbe_dev)
3565*4882a593Smuzhiyun return -ENOMEM;
3566*4882a593Smuzhiyun
3567*4882a593Smuzhiyun if (of_device_is_compatible(node, "ti,netcp-gbe-5") ||
3568*4882a593Smuzhiyun of_device_is_compatible(node, "ti,netcp-gbe")) {
3569*4882a593Smuzhiyun gbe_dev->max_num_slaves = 4;
3570*4882a593Smuzhiyun } else if (of_device_is_compatible(node, "ti,netcp-gbe-9")) {
3571*4882a593Smuzhiyun gbe_dev->max_num_slaves = 8;
3572*4882a593Smuzhiyun } else if (of_device_is_compatible(node, "ti,netcp-gbe-2")) {
3573*4882a593Smuzhiyun gbe_dev->max_num_slaves = 1;
3574*4882a593Smuzhiyun gbe_module.set_rx_mode = gbe_set_rx_mode;
3575*4882a593Smuzhiyun } else if (of_device_is_compatible(node, "ti,netcp-xgbe")) {
3576*4882a593Smuzhiyun gbe_dev->max_num_slaves = 2;
3577*4882a593Smuzhiyun } else {
3578*4882a593Smuzhiyun dev_err(dev, "device tree node for unknown device\n");
3579*4882a593Smuzhiyun return -EINVAL;
3580*4882a593Smuzhiyun }
3581*4882a593Smuzhiyun gbe_dev->max_num_ports = gbe_dev->max_num_slaves + 1;
3582*4882a593Smuzhiyun
3583*4882a593Smuzhiyun gbe_dev->dev = dev;
3584*4882a593Smuzhiyun gbe_dev->netcp_device = netcp_device;
3585*4882a593Smuzhiyun gbe_dev->rx_packet_max = NETCP_MAX_FRAME_SIZE;
3586*4882a593Smuzhiyun
3587*4882a593Smuzhiyun /* init the hw stats lock */
3588*4882a593Smuzhiyun spin_lock_init(&gbe_dev->hw_stats_lock);
3589*4882a593Smuzhiyun
3590*4882a593Smuzhiyun if (of_find_property(node, "enable-ale", NULL)) {
3591*4882a593Smuzhiyun gbe_dev->enable_ale = true;
3592*4882a593Smuzhiyun dev_info(dev, "ALE enabled\n");
3593*4882a593Smuzhiyun } else {
3594*4882a593Smuzhiyun gbe_dev->enable_ale = false;
3595*4882a593Smuzhiyun dev_dbg(dev, "ALE bypass enabled*\n");
3596*4882a593Smuzhiyun }
3597*4882a593Smuzhiyun
3598*4882a593Smuzhiyun ret = of_property_read_u32(node, "tx-queue",
3599*4882a593Smuzhiyun &gbe_dev->tx_queue_id);
3600*4882a593Smuzhiyun if (ret < 0) {
3601*4882a593Smuzhiyun dev_err(dev, "missing tx_queue parameter\n");
3602*4882a593Smuzhiyun gbe_dev->tx_queue_id = GBE_TX_QUEUE;
3603*4882a593Smuzhiyun }
3604*4882a593Smuzhiyun
3605*4882a593Smuzhiyun ret = of_property_read_string(node, "tx-channel",
3606*4882a593Smuzhiyun &gbe_dev->dma_chan_name);
3607*4882a593Smuzhiyun if (ret < 0) {
3608*4882a593Smuzhiyun dev_err(dev, "missing \"tx-channel\" parameter\n");
3609*4882a593Smuzhiyun return -EINVAL;
3610*4882a593Smuzhiyun }
3611*4882a593Smuzhiyun
3612*4882a593Smuzhiyun if (of_node_name_eq(node, "gbe")) {
3613*4882a593Smuzhiyun ret = get_gbe_resource_version(gbe_dev, node);
3614*4882a593Smuzhiyun if (ret)
3615*4882a593Smuzhiyun return ret;
3616*4882a593Smuzhiyun
3617*4882a593Smuzhiyun dev_dbg(dev, "ss_version: 0x%08x\n", gbe_dev->ss_version);
3618*4882a593Smuzhiyun
3619*4882a593Smuzhiyun if (IS_SS_ID_VER_14(gbe_dev))
3620*4882a593Smuzhiyun ret = set_gbe_ethss14_priv(gbe_dev, node);
3621*4882a593Smuzhiyun else if (IS_SS_ID_MU(gbe_dev))
3622*4882a593Smuzhiyun ret = set_gbenu_ethss_priv(gbe_dev, node);
3623*4882a593Smuzhiyun else
3624*4882a593Smuzhiyun ret = -ENODEV;
3625*4882a593Smuzhiyun
3626*4882a593Smuzhiyun } else if (of_node_name_eq(node, "xgbe")) {
3627*4882a593Smuzhiyun ret = set_xgbe_ethss10_priv(gbe_dev, node);
3628*4882a593Smuzhiyun if (ret)
3629*4882a593Smuzhiyun return ret;
3630*4882a593Smuzhiyun ret = netcp_xgbe_serdes_init(gbe_dev->xgbe_serdes_regs,
3631*4882a593Smuzhiyun gbe_dev->ss_regs);
3632*4882a593Smuzhiyun } else {
3633*4882a593Smuzhiyun dev_err(dev, "unknown GBE node(%pOFn)\n", node);
3634*4882a593Smuzhiyun ret = -ENODEV;
3635*4882a593Smuzhiyun }
3636*4882a593Smuzhiyun
3637*4882a593Smuzhiyun if (ret)
3638*4882a593Smuzhiyun return ret;
3639*4882a593Smuzhiyun
3640*4882a593Smuzhiyun interfaces = of_get_child_by_name(node, "interfaces");
3641*4882a593Smuzhiyun if (!interfaces)
3642*4882a593Smuzhiyun dev_err(dev, "could not find interfaces\n");
3643*4882a593Smuzhiyun
3644*4882a593Smuzhiyun ret = netcp_txpipe_init(&gbe_dev->tx_pipe, netcp_device,
3645*4882a593Smuzhiyun gbe_dev->dma_chan_name, gbe_dev->tx_queue_id);
3646*4882a593Smuzhiyun if (ret) {
3647*4882a593Smuzhiyun of_node_put(interfaces);
3648*4882a593Smuzhiyun return ret;
3649*4882a593Smuzhiyun }
3650*4882a593Smuzhiyun
3651*4882a593Smuzhiyun ret = netcp_txpipe_open(&gbe_dev->tx_pipe);
3652*4882a593Smuzhiyun if (ret) {
3653*4882a593Smuzhiyun of_node_put(interfaces);
3654*4882a593Smuzhiyun return ret;
3655*4882a593Smuzhiyun }
3656*4882a593Smuzhiyun
3657*4882a593Smuzhiyun /* Create network interfaces */
3658*4882a593Smuzhiyun INIT_LIST_HEAD(&gbe_dev->gbe_intf_head);
3659*4882a593Smuzhiyun for_each_child_of_node(interfaces, interface) {
3660*4882a593Smuzhiyun ret = of_property_read_u32(interface, "slave-port", &slave_num);
3661*4882a593Smuzhiyun if (ret) {
3662*4882a593Smuzhiyun dev_err(dev, "missing slave-port parameter, skipping interface configuration for %pOFn\n",
3663*4882a593Smuzhiyun interface);
3664*4882a593Smuzhiyun continue;
3665*4882a593Smuzhiyun }
3666*4882a593Smuzhiyun gbe_dev->num_slaves++;
3667*4882a593Smuzhiyun if (gbe_dev->num_slaves >= gbe_dev->max_num_slaves) {
3668*4882a593Smuzhiyun of_node_put(interface);
3669*4882a593Smuzhiyun break;
3670*4882a593Smuzhiyun }
3671*4882a593Smuzhiyun }
3672*4882a593Smuzhiyun of_node_put(interfaces);
3673*4882a593Smuzhiyun
3674*4882a593Smuzhiyun if (!gbe_dev->num_slaves)
3675*4882a593Smuzhiyun dev_warn(dev, "No network interface configured\n");
3676*4882a593Smuzhiyun
3677*4882a593Smuzhiyun /* Initialize Secondary slave ports */
3678*4882a593Smuzhiyun secondary_ports = of_get_child_by_name(node, "secondary-slave-ports");
3679*4882a593Smuzhiyun INIT_LIST_HEAD(&gbe_dev->secondary_slaves);
3680*4882a593Smuzhiyun if (secondary_ports && (gbe_dev->num_slaves < gbe_dev->max_num_slaves))
3681*4882a593Smuzhiyun init_secondary_ports(gbe_dev, secondary_ports);
3682*4882a593Smuzhiyun of_node_put(secondary_ports);
3683*4882a593Smuzhiyun
3684*4882a593Smuzhiyun if (!gbe_dev->num_slaves) {
3685*4882a593Smuzhiyun dev_err(dev,
3686*4882a593Smuzhiyun "No network interface or secondary ports configured\n");
3687*4882a593Smuzhiyun ret = -ENODEV;
3688*4882a593Smuzhiyun goto free_sec_ports;
3689*4882a593Smuzhiyun }
3690*4882a593Smuzhiyun
3691*4882a593Smuzhiyun memset(&ale_params, 0, sizeof(ale_params));
3692*4882a593Smuzhiyun ale_params.dev = gbe_dev->dev;
3693*4882a593Smuzhiyun ale_params.ale_regs = gbe_dev->ale_reg;
3694*4882a593Smuzhiyun ale_params.ale_ageout = GBE_DEFAULT_ALE_AGEOUT;
3695*4882a593Smuzhiyun ale_params.ale_ports = gbe_dev->ale_ports;
3696*4882a593Smuzhiyun ale_params.dev_id = "cpsw";
3697*4882a593Smuzhiyun if (IS_SS_ID_NU(gbe_dev))
3698*4882a593Smuzhiyun ale_params.dev_id = "66ak2el";
3699*4882a593Smuzhiyun else if (IS_SS_ID_2U(gbe_dev))
3700*4882a593Smuzhiyun ale_params.dev_id = "66ak2g";
3701*4882a593Smuzhiyun else if (IS_SS_ID_XGBE(gbe_dev))
3702*4882a593Smuzhiyun ale_params.dev_id = "66ak2h-xgbe";
3703*4882a593Smuzhiyun
3704*4882a593Smuzhiyun gbe_dev->ale = cpsw_ale_create(&ale_params);
3705*4882a593Smuzhiyun if (IS_ERR(gbe_dev->ale)) {
3706*4882a593Smuzhiyun dev_err(gbe_dev->dev, "error initializing ale engine\n");
3707*4882a593Smuzhiyun ret = PTR_ERR(gbe_dev->ale);
3708*4882a593Smuzhiyun goto free_sec_ports;
3709*4882a593Smuzhiyun } else {
3710*4882a593Smuzhiyun dev_dbg(gbe_dev->dev, "Created a gbe ale engine\n");
3711*4882a593Smuzhiyun }
3712*4882a593Smuzhiyun
3713*4882a593Smuzhiyun cpts_node = of_get_child_by_name(node, "cpts");
3714*4882a593Smuzhiyun if (!cpts_node)
3715*4882a593Smuzhiyun cpts_node = of_node_get(node);
3716*4882a593Smuzhiyun
3717*4882a593Smuzhiyun gbe_dev->cpts = cpts_create(gbe_dev->dev, gbe_dev->cpts_reg,
3718*4882a593Smuzhiyun cpts_node, 0);
3719*4882a593Smuzhiyun of_node_put(cpts_node);
3720*4882a593Smuzhiyun if (IS_ENABLED(CONFIG_TI_CPTS) && IS_ERR(gbe_dev->cpts)) {
3721*4882a593Smuzhiyun ret = PTR_ERR(gbe_dev->cpts);
3722*4882a593Smuzhiyun goto free_sec_ports;
3723*4882a593Smuzhiyun }
3724*4882a593Smuzhiyun
3725*4882a593Smuzhiyun /* initialize host port */
3726*4882a593Smuzhiyun gbe_init_host_port(gbe_dev);
3727*4882a593Smuzhiyun
3728*4882a593Smuzhiyun spin_lock_bh(&gbe_dev->hw_stats_lock);
3729*4882a593Smuzhiyun for (i = 0; i < gbe_dev->num_stats_mods; i++) {
3730*4882a593Smuzhiyun if (IS_SS_ID_VER_14(gbe_dev))
3731*4882a593Smuzhiyun gbe_reset_mod_stats_ver14(gbe_dev, i);
3732*4882a593Smuzhiyun else
3733*4882a593Smuzhiyun gbe_reset_mod_stats(gbe_dev, i);
3734*4882a593Smuzhiyun }
3735*4882a593Smuzhiyun spin_unlock_bh(&gbe_dev->hw_stats_lock);
3736*4882a593Smuzhiyun
3737*4882a593Smuzhiyun timer_setup(&gbe_dev->timer, netcp_ethss_timer, 0);
3738*4882a593Smuzhiyun gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
3739*4882a593Smuzhiyun add_timer(&gbe_dev->timer);
3740*4882a593Smuzhiyun *inst_priv = gbe_dev;
3741*4882a593Smuzhiyun return 0;
3742*4882a593Smuzhiyun
3743*4882a593Smuzhiyun free_sec_ports:
3744*4882a593Smuzhiyun free_secondary_ports(gbe_dev);
3745*4882a593Smuzhiyun return ret;
3746*4882a593Smuzhiyun }
3747*4882a593Smuzhiyun
gbe_attach(void * inst_priv,struct net_device * ndev,struct device_node * node,void ** intf_priv)3748*4882a593Smuzhiyun static int gbe_attach(void *inst_priv, struct net_device *ndev,
3749*4882a593Smuzhiyun struct device_node *node, void **intf_priv)
3750*4882a593Smuzhiyun {
3751*4882a593Smuzhiyun struct gbe_priv *gbe_dev = inst_priv;
3752*4882a593Smuzhiyun struct gbe_intf *gbe_intf;
3753*4882a593Smuzhiyun int ret;
3754*4882a593Smuzhiyun
3755*4882a593Smuzhiyun if (!node) {
3756*4882a593Smuzhiyun dev_err(gbe_dev->dev, "interface node not available\n");
3757*4882a593Smuzhiyun return -ENODEV;
3758*4882a593Smuzhiyun }
3759*4882a593Smuzhiyun
3760*4882a593Smuzhiyun gbe_intf = devm_kzalloc(gbe_dev->dev, sizeof(*gbe_intf), GFP_KERNEL);
3761*4882a593Smuzhiyun if (!gbe_intf)
3762*4882a593Smuzhiyun return -ENOMEM;
3763*4882a593Smuzhiyun
3764*4882a593Smuzhiyun gbe_intf->ndev = ndev;
3765*4882a593Smuzhiyun gbe_intf->dev = gbe_dev->dev;
3766*4882a593Smuzhiyun gbe_intf->gbe_dev = gbe_dev;
3767*4882a593Smuzhiyun
3768*4882a593Smuzhiyun gbe_intf->slave = devm_kzalloc(gbe_dev->dev,
3769*4882a593Smuzhiyun sizeof(*gbe_intf->slave),
3770*4882a593Smuzhiyun GFP_KERNEL);
3771*4882a593Smuzhiyun if (!gbe_intf->slave) {
3772*4882a593Smuzhiyun ret = -ENOMEM;
3773*4882a593Smuzhiyun goto fail;
3774*4882a593Smuzhiyun }
3775*4882a593Smuzhiyun
3776*4882a593Smuzhiyun if (init_slave(gbe_dev, gbe_intf->slave, node)) {
3777*4882a593Smuzhiyun ret = -ENODEV;
3778*4882a593Smuzhiyun goto fail;
3779*4882a593Smuzhiyun }
3780*4882a593Smuzhiyun
3781*4882a593Smuzhiyun gbe_intf->tx_pipe = gbe_dev->tx_pipe;
3782*4882a593Smuzhiyun ndev->ethtool_ops = &keystone_ethtool_ops;
3783*4882a593Smuzhiyun list_add_tail(&gbe_intf->gbe_intf_list, &gbe_dev->gbe_intf_head);
3784*4882a593Smuzhiyun *intf_priv = gbe_intf;
3785*4882a593Smuzhiyun return 0;
3786*4882a593Smuzhiyun
3787*4882a593Smuzhiyun fail:
3788*4882a593Smuzhiyun if (gbe_intf->slave)
3789*4882a593Smuzhiyun devm_kfree(gbe_dev->dev, gbe_intf->slave);
3790*4882a593Smuzhiyun if (gbe_intf)
3791*4882a593Smuzhiyun devm_kfree(gbe_dev->dev, gbe_intf);
3792*4882a593Smuzhiyun return ret;
3793*4882a593Smuzhiyun }
3794*4882a593Smuzhiyun
gbe_release(void * intf_priv)3795*4882a593Smuzhiyun static int gbe_release(void *intf_priv)
3796*4882a593Smuzhiyun {
3797*4882a593Smuzhiyun struct gbe_intf *gbe_intf = intf_priv;
3798*4882a593Smuzhiyun
3799*4882a593Smuzhiyun gbe_intf->ndev->ethtool_ops = NULL;
3800*4882a593Smuzhiyun list_del(&gbe_intf->gbe_intf_list);
3801*4882a593Smuzhiyun devm_kfree(gbe_intf->dev, gbe_intf->slave);
3802*4882a593Smuzhiyun devm_kfree(gbe_intf->dev, gbe_intf);
3803*4882a593Smuzhiyun return 0;
3804*4882a593Smuzhiyun }
3805*4882a593Smuzhiyun
gbe_remove(struct netcp_device * netcp_device,void * inst_priv)3806*4882a593Smuzhiyun static int gbe_remove(struct netcp_device *netcp_device, void *inst_priv)
3807*4882a593Smuzhiyun {
3808*4882a593Smuzhiyun struct gbe_priv *gbe_dev = inst_priv;
3809*4882a593Smuzhiyun
3810*4882a593Smuzhiyun del_timer_sync(&gbe_dev->timer);
3811*4882a593Smuzhiyun cpts_release(gbe_dev->cpts);
3812*4882a593Smuzhiyun cpsw_ale_stop(gbe_dev->ale);
3813*4882a593Smuzhiyun netcp_txpipe_close(&gbe_dev->tx_pipe);
3814*4882a593Smuzhiyun free_secondary_ports(gbe_dev);
3815*4882a593Smuzhiyun
3816*4882a593Smuzhiyun if (!list_empty(&gbe_dev->gbe_intf_head))
3817*4882a593Smuzhiyun dev_alert(gbe_dev->dev,
3818*4882a593Smuzhiyun "unreleased ethss interfaces present\n");
3819*4882a593Smuzhiyun
3820*4882a593Smuzhiyun return 0;
3821*4882a593Smuzhiyun }
3822*4882a593Smuzhiyun
3823*4882a593Smuzhiyun static struct netcp_module gbe_module = {
3824*4882a593Smuzhiyun .name = GBE_MODULE_NAME,
3825*4882a593Smuzhiyun .owner = THIS_MODULE,
3826*4882a593Smuzhiyun .primary = true,
3827*4882a593Smuzhiyun .probe = gbe_probe,
3828*4882a593Smuzhiyun .open = gbe_open,
3829*4882a593Smuzhiyun .close = gbe_close,
3830*4882a593Smuzhiyun .remove = gbe_remove,
3831*4882a593Smuzhiyun .attach = gbe_attach,
3832*4882a593Smuzhiyun .release = gbe_release,
3833*4882a593Smuzhiyun .add_addr = gbe_add_addr,
3834*4882a593Smuzhiyun .del_addr = gbe_del_addr,
3835*4882a593Smuzhiyun .add_vid = gbe_add_vid,
3836*4882a593Smuzhiyun .del_vid = gbe_del_vid,
3837*4882a593Smuzhiyun .ioctl = gbe_ioctl,
3838*4882a593Smuzhiyun };
3839*4882a593Smuzhiyun
3840*4882a593Smuzhiyun static struct netcp_module xgbe_module = {
3841*4882a593Smuzhiyun .name = XGBE_MODULE_NAME,
3842*4882a593Smuzhiyun .owner = THIS_MODULE,
3843*4882a593Smuzhiyun .primary = true,
3844*4882a593Smuzhiyun .probe = gbe_probe,
3845*4882a593Smuzhiyun .open = gbe_open,
3846*4882a593Smuzhiyun .close = gbe_close,
3847*4882a593Smuzhiyun .remove = gbe_remove,
3848*4882a593Smuzhiyun .attach = gbe_attach,
3849*4882a593Smuzhiyun .release = gbe_release,
3850*4882a593Smuzhiyun .add_addr = gbe_add_addr,
3851*4882a593Smuzhiyun .del_addr = gbe_del_addr,
3852*4882a593Smuzhiyun .add_vid = gbe_add_vid,
3853*4882a593Smuzhiyun .del_vid = gbe_del_vid,
3854*4882a593Smuzhiyun .ioctl = gbe_ioctl,
3855*4882a593Smuzhiyun };
3856*4882a593Smuzhiyun
keystone_gbe_init(void)3857*4882a593Smuzhiyun static int __init keystone_gbe_init(void)
3858*4882a593Smuzhiyun {
3859*4882a593Smuzhiyun int ret;
3860*4882a593Smuzhiyun
3861*4882a593Smuzhiyun ret = netcp_register_module(&gbe_module);
3862*4882a593Smuzhiyun if (ret)
3863*4882a593Smuzhiyun return ret;
3864*4882a593Smuzhiyun
3865*4882a593Smuzhiyun ret = netcp_register_module(&xgbe_module);
3866*4882a593Smuzhiyun if (ret)
3867*4882a593Smuzhiyun return ret;
3868*4882a593Smuzhiyun
3869*4882a593Smuzhiyun return 0;
3870*4882a593Smuzhiyun }
3871*4882a593Smuzhiyun module_init(keystone_gbe_init);
3872*4882a593Smuzhiyun
keystone_gbe_exit(void)3873*4882a593Smuzhiyun static void __exit keystone_gbe_exit(void)
3874*4882a593Smuzhiyun {
3875*4882a593Smuzhiyun netcp_unregister_module(&gbe_module);
3876*4882a593Smuzhiyun netcp_unregister_module(&xgbe_module);
3877*4882a593Smuzhiyun }
3878*4882a593Smuzhiyun module_exit(keystone_gbe_exit);
3879*4882a593Smuzhiyun
3880*4882a593Smuzhiyun MODULE_LICENSE("GPL v2");
3881*4882a593Smuzhiyun MODULE_DESCRIPTION("TI NETCP ETHSS driver for Keystone SOCs");
3882*4882a593Smuzhiyun MODULE_AUTHOR("Sandeep Nair <sandeep_n@ti.com");
3883