blob: 0847a8f48cfe1d11d5001c1da2e0a33200a05116 [file] [log] [blame]
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001/*
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002 * Keystone GBE and XGBE subsystem code
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003 *
4 * Copyright (C) 2014 Texas Instruments Incorporated
5 * Authors: Sandeep Nair <sandeep_n@ti.com>
6 * Sandeep Paulraj <s-paulraj@ti.com>
7 * Cyril Chemparathy <cyril@ti.com>
8 * Santosh Shilimkar <santosh.shilimkar@ti.com>
9 * Wingman Kwok <w-kwok2@ti.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation version 2.
14 *
15 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
16 * kind, whether express or implied; without even the implied warranty
17 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/io.h>
Karicheri, Muralidharan58c11b52015-01-29 18:15:51 -050022#include <linux/module.h>
Wingman Kwok6f8d3f32015-01-15 19:12:51 -050023#include <linux/of_mdio.h>
24#include <linux/of_address.h>
25#include <linux/if_vlan.h>
WingMan Kwok62461682016-12-08 16:21:56 -060026#include <linux/ptp_classify.h>
27#include <linux/net_tstamp.h>
Wingman Kwok6f8d3f32015-01-15 19:12:51 -050028#include <linux/ethtool.h>
29
30#include "cpsw_ale.h"
31#include "netcp.h"
WingMan Kwok62461682016-12-08 16:21:56 -060032#include "cpts.h"
Wingman Kwok6f8d3f32015-01-15 19:12:51 -050033
34#define NETCP_DRIVER_NAME "TI KeyStone Ethernet Driver"
35#define NETCP_DRIVER_VERSION "v1.0"
36
37#define GBE_IDENT(reg) ((reg >> 16) & 0xffff)
38#define GBE_MAJOR_VERSION(reg) (reg >> 8 & 0x7)
39#define GBE_MINOR_VERSION(reg) (reg & 0xff)
40#define GBE_RTL_VERSION(reg) ((reg >> 11) & 0x1f)
41
42/* 1G Ethernet SS defines */
43#define GBE_MODULE_NAME "netcp-gbe"
44#define GBE_SS_VERSION_14 0x4ed21104
45
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -040046#define GBE_SS_REG_INDEX 0
47#define GBE_SGMII34_REG_INDEX 1
48#define GBE_SM_REG_INDEX 2
49/* offset relative to base of GBE_SS_REG_INDEX */
Wingman Kwok6f8d3f32015-01-15 19:12:51 -050050#define GBE13_SGMII_MODULE_OFFSET 0x100
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -040051/* offset relative to base of GBE_SM_REG_INDEX */
52#define GBE13_HOST_PORT_OFFSET 0x34
53#define GBE13_SLAVE_PORT_OFFSET 0x60
54#define GBE13_EMAC_OFFSET 0x100
55#define GBE13_SLAVE_PORT2_OFFSET 0x200
56#define GBE13_HW_STATS_OFFSET 0x300
WingMan Kwok62461682016-12-08 16:21:56 -060057#define GBE13_CPTS_OFFSET 0x500
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -040058#define GBE13_ALE_OFFSET 0x600
Wingman Kwok6f8d3f32015-01-15 19:12:51 -050059#define GBE13_HOST_PORT_NUM 0
Wingman Kwok6f8d3f32015-01-15 19:12:51 -050060#define GBE13_NUM_ALE_ENTRIES 1024
61
WingMan Kwok9a391c72015-03-20 16:11:25 -040062/* 1G Ethernet NU SS defines */
63#define GBENU_MODULE_NAME "netcp-gbenu"
64#define GBE_SS_ID_NU 0x4ee6
65#define GBE_SS_ID_2U 0x4ee8
66
67#define IS_SS_ID_MU(d) \
68 ((GBE_IDENT((d)->ss_version) == GBE_SS_ID_NU) || \
69 (GBE_IDENT((d)->ss_version) == GBE_SS_ID_2U))
70
71#define IS_SS_ID_NU(d) \
72 (GBE_IDENT((d)->ss_version) == GBE_SS_ID_NU)
73
74#define GBENU_SS_REG_INDEX 0
75#define GBENU_SM_REG_INDEX 1
76#define GBENU_SGMII_MODULE_OFFSET 0x100
77#define GBENU_HOST_PORT_OFFSET 0x1000
78#define GBENU_SLAVE_PORT_OFFSET 0x2000
79#define GBENU_EMAC_OFFSET 0x2330
80#define GBENU_HW_STATS_OFFSET 0x1a000
WingMan Kwok62461682016-12-08 16:21:56 -060081#define GBENU_CPTS_OFFSET 0x1d000
WingMan Kwok9a391c72015-03-20 16:11:25 -040082#define GBENU_ALE_OFFSET 0x1e000
83#define GBENU_HOST_PORT_NUM 0
WingMan Kwok8c851512015-09-23 13:37:05 -040084#define GBENU_SGMII_MODULE_SIZE 0x100
WingMan Kwok9a391c72015-03-20 16:11:25 -040085
Wingman Kwok90cff9e2015-01-15 19:12:52 -050086/* 10G Ethernet SS defines */
87#define XGBE_MODULE_NAME "netcp-xgbe"
88#define XGBE_SS_VERSION_10 0x4ee42100
89
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -040090#define XGBE_SS_REG_INDEX 0
91#define XGBE_SM_REG_INDEX 1
92#define XGBE_SERDES_REG_INDEX 2
93
94/* offset relative to base of XGBE_SS_REG_INDEX */
Wingman Kwok90cff9e2015-01-15 19:12:52 -050095#define XGBE10_SGMII_MODULE_OFFSET 0x100
WingMan Kwok4c0ef232016-12-19 17:55:57 -050096#define IS_SS_ID_XGBE(d) ((d)->ss_version == XGBE_SS_VERSION_10)
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -040097/* offset relative to base of XGBE_SM_REG_INDEX */
98#define XGBE10_HOST_PORT_OFFSET 0x34
99#define XGBE10_SLAVE_PORT_OFFSET 0x64
100#define XGBE10_EMAC_OFFSET 0x400
WingMan Kwok62461682016-12-08 16:21:56 -0600101#define XGBE10_CPTS_OFFSET 0x600
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -0400102#define XGBE10_ALE_OFFSET 0x700
103#define XGBE10_HW_STATS_OFFSET 0x800
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500104#define XGBE10_HOST_PORT_NUM 0
Karicheri, Muralidharan7938a0d2017-01-06 15:37:45 -0500105#define XGBE10_NUM_ALE_ENTRIES 2048
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500106
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500107#define GBE_TIMER_INTERVAL (HZ / 2)
108
109/* Soft reset register values */
110#define SOFT_RESET_MASK BIT(0)
111#define SOFT_RESET BIT(0)
112#define DEVICE_EMACSL_RESET_POLL_COUNT 100
113#define GMACSL_RET_WARN_RESET_INCOMPLETE -2
114
115#define MACSL_RX_ENABLE_CSF BIT(23)
116#define MACSL_ENABLE_EXT_CTL BIT(18)
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500117#define MACSL_XGMII_ENABLE BIT(13)
118#define MACSL_XGIG_MODE BIT(8)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500119#define MACSL_GIG_MODE BIT(7)
120#define MACSL_GMII_ENABLE BIT(5)
121#define MACSL_FULLDUPLEX BIT(0)
122
123#define GBE_CTL_P0_ENABLE BIT(2)
Karicheri, Muralidharan4cd85a62017-01-06 15:37:43 -0500124#define ETH_SW_CTL_P0_TX_CRC_REMOVE BIT(13)
WingMan Kwok9a391c72015-03-20 16:11:25 -0400125#define GBE13_REG_VAL_STAT_ENABLE_ALL 0xff
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500126#define XGBE_REG_VAL_STAT_ENABLE_ALL 0xf
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500127#define GBE_STATS_CD_SEL BIT(28)
128
129#define GBE_PORT_MASK(x) (BIT(x) - 1)
130#define GBE_MASK_NO_PORTS 0
131
132#define GBE_DEF_1G_MAC_CONTROL \
133 (MACSL_GIG_MODE | MACSL_GMII_ENABLE | \
134 MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
135
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500136#define GBE_DEF_10G_MAC_CONTROL \
137 (MACSL_XGIG_MODE | MACSL_XGMII_ENABLE | \
138 MACSL_ENABLE_EXT_CTL | MACSL_RX_ENABLE_CSF)
139
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500140#define GBE_STATSA_MODULE 0
141#define GBE_STATSB_MODULE 1
142#define GBE_STATSC_MODULE 2
143#define GBE_STATSD_MODULE 3
144
WingMan Kwok9a391c72015-03-20 16:11:25 -0400145#define GBENU_STATS0_MODULE 0
146#define GBENU_STATS1_MODULE 1
147#define GBENU_STATS2_MODULE 2
148#define GBENU_STATS3_MODULE 3
149#define GBENU_STATS4_MODULE 4
150#define GBENU_STATS5_MODULE 5
151#define GBENU_STATS6_MODULE 6
152#define GBENU_STATS7_MODULE 7
153#define GBENU_STATS8_MODULE 8
154
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500155#define XGBE_STATS0_MODULE 0
156#define XGBE_STATS1_MODULE 1
157#define XGBE_STATS2_MODULE 2
158
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500159/* s: 0-based slave_port */
WingMan Kwok8c851512015-09-23 13:37:05 -0400160#define SGMII_BASE(d, s) \
161 (((s) < 2) ? (d)->sgmii_port_regs : (d)->sgmii_port34_regs)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500162
163#define GBE_TX_QUEUE 648
164#define GBE_TXHOOK_ORDER 0
WingMan Kwok62461682016-12-08 16:21:56 -0600165#define GBE_RXHOOK_ORDER 0
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500166#define GBE_DEFAULT_ALE_AGEOUT 30
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500167#define SLAVE_LINK_IS_XGMII(s) ((s)->link_interface >= XGMII_LINK_MAC_PHY)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500168#define NETCP_LINK_STATE_INVALID -1
169
170#define GBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
171 offsetof(struct gbe##_##rb, rn)
WingMan Kwok9a391c72015-03-20 16:11:25 -0400172#define GBENU_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
173 offsetof(struct gbenu##_##rb, rn)
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500174#define XGBE_SET_REG_OFS(p, rb, rn) p->rb##_ofs.rn = \
175 offsetof(struct xgbe##_##rb, rn)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500176#define GBE_REG_ADDR(p, rb, rn) (p->rb + p->rb##_ofs.rn)
177
WingMan Kwok9a391c72015-03-20 16:11:25 -0400178#define HOST_TX_PRI_MAP_DEFAULT 0x00000000
179
WingMan Kwok62461682016-12-08 16:21:56 -0600180#if IS_ENABLED(CONFIG_TI_CPTS)
181/* Px_TS_CTL register fields */
182#define TS_RX_ANX_F_EN BIT(0)
183#define TS_RX_VLAN_LT1_EN BIT(1)
184#define TS_RX_VLAN_LT2_EN BIT(2)
185#define TS_RX_ANX_D_EN BIT(3)
186#define TS_TX_ANX_F_EN BIT(4)
187#define TS_TX_VLAN_LT1_EN BIT(5)
188#define TS_TX_VLAN_LT2_EN BIT(6)
189#define TS_TX_ANX_D_EN BIT(7)
190#define TS_LT2_EN BIT(8)
191#define TS_RX_ANX_E_EN BIT(9)
192#define TS_TX_ANX_E_EN BIT(10)
193#define TS_MSG_TYPE_EN_SHIFT 16
194#define TS_MSG_TYPE_EN_MASK 0xffff
195
196/* Px_TS_SEQ_LTYPE register fields */
197#define TS_SEQ_ID_OFS_SHIFT 16
198#define TS_SEQ_ID_OFS_MASK 0x3f
199
200/* Px_TS_CTL_LTYPE2 register fields */
201#define TS_107 BIT(16)
202#define TS_129 BIT(17)
203#define TS_130 BIT(18)
204#define TS_131 BIT(19)
205#define TS_132 BIT(20)
206#define TS_319 BIT(21)
207#define TS_320 BIT(22)
208#define TS_TTL_NONZERO BIT(23)
209#define TS_UNI_EN BIT(24)
210#define TS_UNI_EN_SHIFT 24
211
212#define TS_TX_ANX_ALL_EN \
213 (TS_TX_ANX_D_EN | TS_TX_ANX_E_EN | TS_TX_ANX_F_EN)
214
215#define TS_RX_ANX_ALL_EN \
216 (TS_RX_ANX_D_EN | TS_RX_ANX_E_EN | TS_RX_ANX_F_EN)
217
218#define TS_CTL_DST_PORT TS_319
219#define TS_CTL_DST_PORT_SHIFT 21
220
221#define TS_CTL_MADDR_ALL \
222 (TS_107 | TS_129 | TS_130 | TS_131 | TS_132)
223
224#define TS_CTL_MADDR_SHIFT 16
225
226/* The PTP event messages - Sync, Delay_Req, Pdelay_Req, and Pdelay_Resp. */
227#define EVENT_MSG_BITS (BIT(0) | BIT(1) | BIT(2) | BIT(3))
228#endif /* CONFIG_TI_CPTS */
229
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500230struct xgbe_ss_regs {
231 u32 id_ver;
232 u32 synce_count;
233 u32 synce_mux;
234 u32 control;
235};
236
237struct xgbe_switch_regs {
238 u32 id_ver;
239 u32 control;
240 u32 emcontrol;
241 u32 stat_port_en;
242 u32 ptype;
243 u32 soft_idle;
244 u32 thru_rate;
245 u32 gap_thresh;
246 u32 tx_start_wds;
247 u32 flow_control;
248 u32 cppi_thresh;
249};
250
251struct xgbe_port_regs {
252 u32 blk_cnt;
253 u32 port_vlan;
254 u32 tx_pri_map;
255 u32 sa_lo;
256 u32 sa_hi;
257 u32 ts_ctl;
258 u32 ts_seq_ltype;
259 u32 ts_vlan;
260 u32 ts_ctl_ltype2;
261 u32 ts_ctl2;
262 u32 control;
263};
264
265struct xgbe_host_port_regs {
266 u32 blk_cnt;
267 u32 port_vlan;
268 u32 tx_pri_map;
269 u32 src_id;
270 u32 rx_pri_map;
271 u32 rx_maxlen;
272};
273
274struct xgbe_emac_regs {
275 u32 id_ver;
276 u32 mac_control;
277 u32 mac_status;
278 u32 soft_reset;
279 u32 rx_maxlen;
280 u32 __reserved_0;
281 u32 rx_pause;
282 u32 tx_pause;
283 u32 em_control;
284 u32 __reserved_1;
285 u32 tx_gap;
286 u32 rsvd[4];
287};
288
289struct xgbe_host_hw_stats {
290 u32 rx_good_frames;
291 u32 rx_broadcast_frames;
292 u32 rx_multicast_frames;
293 u32 __rsvd_0[3];
294 u32 rx_oversized_frames;
295 u32 __rsvd_1;
296 u32 rx_undersized_frames;
297 u32 __rsvd_2;
298 u32 overrun_type4;
299 u32 overrun_type5;
300 u32 rx_bytes;
301 u32 tx_good_frames;
302 u32 tx_broadcast_frames;
303 u32 tx_multicast_frames;
304 u32 __rsvd_3[9];
305 u32 tx_bytes;
306 u32 tx_64byte_frames;
307 u32 tx_65_to_127byte_frames;
308 u32 tx_128_to_255byte_frames;
309 u32 tx_256_to_511byte_frames;
310 u32 tx_512_to_1023byte_frames;
311 u32 tx_1024byte_frames;
312 u32 net_bytes;
313 u32 rx_sof_overruns;
314 u32 rx_mof_overruns;
315 u32 rx_dma_overruns;
316};
317
318struct xgbe_hw_stats {
319 u32 rx_good_frames;
320 u32 rx_broadcast_frames;
321 u32 rx_multicast_frames;
322 u32 rx_pause_frames;
323 u32 rx_crc_errors;
324 u32 rx_align_code_errors;
325 u32 rx_oversized_frames;
326 u32 rx_jabber_frames;
327 u32 rx_undersized_frames;
328 u32 rx_fragments;
329 u32 overrun_type4;
330 u32 overrun_type5;
331 u32 rx_bytes;
332 u32 tx_good_frames;
333 u32 tx_broadcast_frames;
334 u32 tx_multicast_frames;
335 u32 tx_pause_frames;
336 u32 tx_deferred_frames;
337 u32 tx_collision_frames;
338 u32 tx_single_coll_frames;
339 u32 tx_mult_coll_frames;
340 u32 tx_excessive_collisions;
341 u32 tx_late_collisions;
342 u32 tx_underrun;
343 u32 tx_carrier_sense_errors;
344 u32 tx_bytes;
345 u32 tx_64byte_frames;
346 u32 tx_65_to_127byte_frames;
347 u32 tx_128_to_255byte_frames;
348 u32 tx_256_to_511byte_frames;
349 u32 tx_512_to_1023byte_frames;
350 u32 tx_1024byte_frames;
351 u32 net_bytes;
352 u32 rx_sof_overruns;
353 u32 rx_mof_overruns;
354 u32 rx_dma_overruns;
355};
356
WingMan Kwok9a391c72015-03-20 16:11:25 -0400357struct gbenu_ss_regs {
358 u32 id_ver;
359 u32 synce_count; /* NU */
360 u32 synce_mux; /* NU */
361 u32 control; /* 2U */
362 u32 __rsvd_0[2]; /* 2U */
363 u32 rgmii_status; /* 2U */
364 u32 ss_status; /* 2U */
365};
366
367struct gbenu_switch_regs {
368 u32 id_ver;
369 u32 control;
370 u32 __rsvd_0[2];
371 u32 emcontrol;
372 u32 stat_port_en;
373 u32 ptype; /* NU */
374 u32 soft_idle;
375 u32 thru_rate; /* NU */
376 u32 gap_thresh; /* NU */
377 u32 tx_start_wds; /* NU */
378 u32 eee_prescale; /* 2U */
379 u32 tx_g_oflow_thresh_set; /* NU */
380 u32 tx_g_oflow_thresh_clr; /* NU */
381 u32 tx_g_buf_thresh_set_l; /* NU */
382 u32 tx_g_buf_thresh_set_h; /* NU */
383 u32 tx_g_buf_thresh_clr_l; /* NU */
384 u32 tx_g_buf_thresh_clr_h; /* NU */
385};
386
387struct gbenu_port_regs {
388 u32 __rsvd_0;
389 u32 control;
390 u32 max_blks; /* 2U */
391 u32 mem_align1;
392 u32 blk_cnt;
393 u32 port_vlan;
394 u32 tx_pri_map; /* NU */
395 u32 pri_ctl; /* 2U */
396 u32 rx_pri_map;
397 u32 rx_maxlen;
398 u32 tx_blks_pri; /* NU */
399 u32 __rsvd_1;
400 u32 idle2lpi; /* 2U */
401 u32 lpi2idle; /* 2U */
402 u32 eee_status; /* 2U */
403 u32 __rsvd_2;
404 u32 __rsvd_3[176]; /* NU: more to add */
405 u32 __rsvd_4[2];
406 u32 sa_lo;
407 u32 sa_hi;
408 u32 ts_ctl;
409 u32 ts_seq_ltype;
410 u32 ts_vlan;
411 u32 ts_ctl_ltype2;
412 u32 ts_ctl2;
413};
414
415struct gbenu_host_port_regs {
416 u32 __rsvd_0;
417 u32 control;
418 u32 flow_id_offset; /* 2U */
419 u32 __rsvd_1;
420 u32 blk_cnt;
421 u32 port_vlan;
422 u32 tx_pri_map; /* NU */
423 u32 pri_ctl;
424 u32 rx_pri_map;
425 u32 rx_maxlen;
426 u32 tx_blks_pri; /* NU */
427 u32 __rsvd_2;
428 u32 idle2lpi; /* 2U */
429 u32 lpi2wake; /* 2U */
430 u32 eee_status; /* 2U */
431 u32 __rsvd_3;
432 u32 __rsvd_4[184]; /* NU */
433 u32 host_blks_pri; /* NU */
434};
435
436struct gbenu_emac_regs {
437 u32 mac_control;
438 u32 mac_status;
439 u32 soft_reset;
440 u32 boff_test;
441 u32 rx_pause;
442 u32 __rsvd_0[11]; /* NU */
443 u32 tx_pause;
444 u32 __rsvd_1[11]; /* NU */
445 u32 em_control;
446 u32 tx_gap;
447};
448
449/* Some hw stat regs are applicable to slave port only.
450 * This is handled by gbenu_et_stats struct. Also some
451 * are for SS version NU and some are for 2U.
452 */
453struct gbenu_hw_stats {
454 u32 rx_good_frames;
455 u32 rx_broadcast_frames;
456 u32 rx_multicast_frames;
457 u32 rx_pause_frames; /* slave */
458 u32 rx_crc_errors;
459 u32 rx_align_code_errors; /* slave */
460 u32 rx_oversized_frames;
461 u32 rx_jabber_frames; /* slave */
462 u32 rx_undersized_frames;
463 u32 rx_fragments; /* slave */
464 u32 ale_drop;
465 u32 ale_overrun_drop;
466 u32 rx_bytes;
467 u32 tx_good_frames;
468 u32 tx_broadcast_frames;
469 u32 tx_multicast_frames;
470 u32 tx_pause_frames; /* slave */
471 u32 tx_deferred_frames; /* slave */
472 u32 tx_collision_frames; /* slave */
473 u32 tx_single_coll_frames; /* slave */
474 u32 tx_mult_coll_frames; /* slave */
475 u32 tx_excessive_collisions; /* slave */
476 u32 tx_late_collisions; /* slave */
477 u32 rx_ipg_error; /* slave 10G only */
478 u32 tx_carrier_sense_errors; /* slave */
479 u32 tx_bytes;
480 u32 tx_64B_frames;
481 u32 tx_65_to_127B_frames;
482 u32 tx_128_to_255B_frames;
483 u32 tx_256_to_511B_frames;
484 u32 tx_512_to_1023B_frames;
485 u32 tx_1024B_frames;
486 u32 net_bytes;
487 u32 rx_bottom_fifo_drop;
488 u32 rx_port_mask_drop;
489 u32 rx_top_fifo_drop;
490 u32 ale_rate_limit_drop;
491 u32 ale_vid_ingress_drop;
492 u32 ale_da_eq_sa_drop;
493 u32 __rsvd_0[3];
494 u32 ale_unknown_ucast;
495 u32 ale_unknown_ucast_bytes;
496 u32 ale_unknown_mcast;
497 u32 ale_unknown_mcast_bytes;
498 u32 ale_unknown_bcast;
499 u32 ale_unknown_bcast_bytes;
500 u32 ale_pol_match;
501 u32 ale_pol_match_red; /* NU */
502 u32 ale_pol_match_yellow; /* NU */
503 u32 __rsvd_1[44];
504 u32 tx_mem_protect_err;
505 /* following NU only */
506 u32 tx_pri0;
507 u32 tx_pri1;
508 u32 tx_pri2;
509 u32 tx_pri3;
510 u32 tx_pri4;
511 u32 tx_pri5;
512 u32 tx_pri6;
513 u32 tx_pri7;
514 u32 tx_pri0_bcnt;
515 u32 tx_pri1_bcnt;
516 u32 tx_pri2_bcnt;
517 u32 tx_pri3_bcnt;
518 u32 tx_pri4_bcnt;
519 u32 tx_pri5_bcnt;
520 u32 tx_pri6_bcnt;
521 u32 tx_pri7_bcnt;
522 u32 tx_pri0_drop;
523 u32 tx_pri1_drop;
524 u32 tx_pri2_drop;
525 u32 tx_pri3_drop;
526 u32 tx_pri4_drop;
527 u32 tx_pri5_drop;
528 u32 tx_pri6_drop;
529 u32 tx_pri7_drop;
530 u32 tx_pri0_drop_bcnt;
531 u32 tx_pri1_drop_bcnt;
532 u32 tx_pri2_drop_bcnt;
533 u32 tx_pri3_drop_bcnt;
534 u32 tx_pri4_drop_bcnt;
535 u32 tx_pri5_drop_bcnt;
536 u32 tx_pri6_drop_bcnt;
537 u32 tx_pri7_drop_bcnt;
538};
539
WingMan Kwok9a391c72015-03-20 16:11:25 -0400540#define GBENU_HW_STATS_REG_MAP_SZ 0x200
541
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500542struct gbe_ss_regs {
543 u32 id_ver;
544 u32 synce_count;
545 u32 synce_mux;
546};
547
548struct gbe_ss_regs_ofs {
549 u16 id_ver;
550 u16 control;
551};
552
553struct gbe_switch_regs {
554 u32 id_ver;
555 u32 control;
556 u32 soft_reset;
557 u32 stat_port_en;
558 u32 ptype;
559 u32 soft_idle;
560 u32 thru_rate;
561 u32 gap_thresh;
562 u32 tx_start_wds;
563 u32 flow_control;
564};
565
566struct gbe_switch_regs_ofs {
567 u16 id_ver;
568 u16 control;
569 u16 soft_reset;
570 u16 emcontrol;
571 u16 stat_port_en;
572 u16 ptype;
573 u16 flow_control;
574};
575
576struct gbe_port_regs {
577 u32 max_blks;
578 u32 blk_cnt;
579 u32 port_vlan;
580 u32 tx_pri_map;
581 u32 sa_lo;
582 u32 sa_hi;
583 u32 ts_ctl;
584 u32 ts_seq_ltype;
585 u32 ts_vlan;
586 u32 ts_ctl_ltype2;
587 u32 ts_ctl2;
588};
589
590struct gbe_port_regs_ofs {
591 u16 port_vlan;
592 u16 tx_pri_map;
593 u16 sa_lo;
594 u16 sa_hi;
595 u16 ts_ctl;
596 u16 ts_seq_ltype;
597 u16 ts_vlan;
598 u16 ts_ctl_ltype2;
599 u16 ts_ctl2;
WingMan Kwok9a391c72015-03-20 16:11:25 -0400600 u16 rx_maxlen; /* 2U, NU */
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500601};
602
603struct gbe_host_port_regs {
604 u32 src_id;
605 u32 port_vlan;
606 u32 rx_pri_map;
607 u32 rx_maxlen;
608};
609
610struct gbe_host_port_regs_ofs {
611 u16 port_vlan;
612 u16 tx_pri_map;
613 u16 rx_maxlen;
614};
615
616struct gbe_emac_regs {
617 u32 id_ver;
618 u32 mac_control;
619 u32 mac_status;
620 u32 soft_reset;
621 u32 rx_maxlen;
622 u32 __reserved_0;
623 u32 rx_pause;
624 u32 tx_pause;
625 u32 __reserved_1;
626 u32 rx_pri_map;
627 u32 rsvd[6];
628};
629
630struct gbe_emac_regs_ofs {
631 u16 mac_control;
632 u16 soft_reset;
633 u16 rx_maxlen;
634};
635
636struct gbe_hw_stats {
637 u32 rx_good_frames;
638 u32 rx_broadcast_frames;
639 u32 rx_multicast_frames;
640 u32 rx_pause_frames;
641 u32 rx_crc_errors;
642 u32 rx_align_code_errors;
643 u32 rx_oversized_frames;
644 u32 rx_jabber_frames;
645 u32 rx_undersized_frames;
646 u32 rx_fragments;
647 u32 __pad_0[2];
648 u32 rx_bytes;
649 u32 tx_good_frames;
650 u32 tx_broadcast_frames;
651 u32 tx_multicast_frames;
652 u32 tx_pause_frames;
653 u32 tx_deferred_frames;
654 u32 tx_collision_frames;
655 u32 tx_single_coll_frames;
656 u32 tx_mult_coll_frames;
657 u32 tx_excessive_collisions;
658 u32 tx_late_collisions;
659 u32 tx_underrun;
660 u32 tx_carrier_sense_errors;
661 u32 tx_bytes;
662 u32 tx_64byte_frames;
663 u32 tx_65_to_127byte_frames;
664 u32 tx_128_to_255byte_frames;
665 u32 tx_256_to_511byte_frames;
666 u32 tx_512_to_1023byte_frames;
667 u32 tx_1024byte_frames;
668 u32 net_bytes;
669 u32 rx_sof_overruns;
670 u32 rx_mof_overruns;
671 u32 rx_dma_overruns;
672};
673
WingMan Kwok9a391c72015-03-20 16:11:25 -0400674#define GBE_MAX_HW_STAT_MODS 9
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500675#define GBE_HW_STATS_REG_MAP_SZ 0x100
676
WingMan Kwok62461682016-12-08 16:21:56 -0600677struct ts_ctl {
678 int uni;
679 u8 dst_port_map;
680 u8 maddr_map;
681 u8 ts_mcast_type;
682};
683
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500684struct gbe_slave {
685 void __iomem *port_regs;
686 void __iomem *emac_regs;
687 struct gbe_port_regs_ofs port_regs_ofs;
688 struct gbe_emac_regs_ofs emac_regs_ofs;
689 int slave_num; /* 0 based logical number */
690 int port_num; /* actual port number */
691 atomic_t link_state;
692 bool open;
693 struct phy_device *phy;
694 u32 link_interface;
695 u32 mac_control;
696 u8 phy_port_t;
697 struct device_node *phy_node;
WingMan Kwok62461682016-12-08 16:21:56 -0600698 struct ts_ctl ts_ctl;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500699 struct list_head slave_list;
700};
701
702struct gbe_priv {
703 struct device *dev;
704 struct netcp_device *netcp_device;
705 struct timer_list timer;
706 u32 num_slaves;
707 u32 ale_entries;
708 u32 ale_ports;
709 bool enable_ale;
WingMan Kwok9a391c72015-03-20 16:11:25 -0400710 u8 max_num_slaves;
711 u8 max_num_ports; /* max_num_slaves + 1 */
WingMan Kwok489e8a22015-07-23 15:57:23 -0400712 u8 num_stats_mods;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500713 struct netcp_tx_pipe tx_pipe;
714
715 int host_port;
716 u32 rx_packet_max;
717 u32 ss_version;
WingMan Kwok9a391c72015-03-20 16:11:25 -0400718 u32 stats_en_mask;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500719
720 void __iomem *ss_regs;
721 void __iomem *switch_regs;
722 void __iomem *host_port_regs;
723 void __iomem *ale_reg;
WingMan Kwok62461682016-12-08 16:21:56 -0600724 void __iomem *cpts_reg;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500725 void __iomem *sgmii_port_regs;
726 void __iomem *sgmii_port34_regs;
727 void __iomem *xgbe_serdes_regs;
728 void __iomem *hw_stats_regs[GBE_MAX_HW_STAT_MODS];
729
730 struct gbe_ss_regs_ofs ss_regs_ofs;
731 struct gbe_switch_regs_ofs switch_regs_ofs;
732 struct gbe_host_port_regs_ofs host_port_regs_ofs;
733
734 struct cpsw_ale *ale;
735 unsigned int tx_queue_id;
736 const char *dma_chan_name;
737
738 struct list_head gbe_intf_head;
739 struct list_head secondary_slaves;
740 struct net_device *dummy_ndev;
741
742 u64 *hw_stats;
WingMan Kwok489e8a22015-07-23 15:57:23 -0400743 u32 *hw_stats_prev;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500744 const struct netcp_ethtool_stat *et_stats;
745 int num_et_stats;
746 /* Lock for updating the hwstats */
747 spinlock_t hw_stats_lock;
WingMan Kwok62461682016-12-08 16:21:56 -0600748
749 int cpts_registered;
750 struct cpts *cpts;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500751};
752
753struct gbe_intf {
754 struct net_device *ndev;
755 struct device *dev;
756 struct gbe_priv *gbe_dev;
757 struct netcp_tx_pipe tx_pipe;
758 struct gbe_slave *slave;
759 struct list_head gbe_intf_list;
760 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
761};
762
763static struct netcp_module gbe_module;
Wingman Kwok90cff9e2015-01-15 19:12:52 -0500764static struct netcp_module xgbe_module;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500765
766/* Statistic management */
767struct netcp_ethtool_stat {
768 char desc[ETH_GSTRING_LEN];
769 int type;
770 u32 size;
771 int offset;
772};
773
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400774#define GBE_STATSA_INFO(field) \
775{ \
776 "GBE_A:"#field, GBE_STATSA_MODULE, \
777 FIELD_SIZEOF(struct gbe_hw_stats, field), \
778 offsetof(struct gbe_hw_stats, field) \
779}
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500780
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400781#define GBE_STATSB_INFO(field) \
782{ \
783 "GBE_B:"#field, GBE_STATSB_MODULE, \
784 FIELD_SIZEOF(struct gbe_hw_stats, field), \
785 offsetof(struct gbe_hw_stats, field) \
786}
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500787
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400788#define GBE_STATSC_INFO(field) \
789{ \
790 "GBE_C:"#field, GBE_STATSC_MODULE, \
791 FIELD_SIZEOF(struct gbe_hw_stats, field), \
792 offsetof(struct gbe_hw_stats, field) \
793}
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500794
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400795#define GBE_STATSD_INFO(field) \
796{ \
797 "GBE_D:"#field, GBE_STATSD_MODULE, \
798 FIELD_SIZEOF(struct gbe_hw_stats, field), \
799 offsetof(struct gbe_hw_stats, field) \
800}
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500801
802static const struct netcp_ethtool_stat gbe13_et_stats[] = {
803 /* GBE module A */
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400804 GBE_STATSA_INFO(rx_good_frames),
805 GBE_STATSA_INFO(rx_broadcast_frames),
806 GBE_STATSA_INFO(rx_multicast_frames),
807 GBE_STATSA_INFO(rx_pause_frames),
808 GBE_STATSA_INFO(rx_crc_errors),
809 GBE_STATSA_INFO(rx_align_code_errors),
810 GBE_STATSA_INFO(rx_oversized_frames),
811 GBE_STATSA_INFO(rx_jabber_frames),
812 GBE_STATSA_INFO(rx_undersized_frames),
813 GBE_STATSA_INFO(rx_fragments),
814 GBE_STATSA_INFO(rx_bytes),
815 GBE_STATSA_INFO(tx_good_frames),
816 GBE_STATSA_INFO(tx_broadcast_frames),
817 GBE_STATSA_INFO(tx_multicast_frames),
818 GBE_STATSA_INFO(tx_pause_frames),
819 GBE_STATSA_INFO(tx_deferred_frames),
820 GBE_STATSA_INFO(tx_collision_frames),
821 GBE_STATSA_INFO(tx_single_coll_frames),
822 GBE_STATSA_INFO(tx_mult_coll_frames),
823 GBE_STATSA_INFO(tx_excessive_collisions),
824 GBE_STATSA_INFO(tx_late_collisions),
825 GBE_STATSA_INFO(tx_underrun),
826 GBE_STATSA_INFO(tx_carrier_sense_errors),
827 GBE_STATSA_INFO(tx_bytes),
828 GBE_STATSA_INFO(tx_64byte_frames),
829 GBE_STATSA_INFO(tx_65_to_127byte_frames),
830 GBE_STATSA_INFO(tx_128_to_255byte_frames),
831 GBE_STATSA_INFO(tx_256_to_511byte_frames),
832 GBE_STATSA_INFO(tx_512_to_1023byte_frames),
833 GBE_STATSA_INFO(tx_1024byte_frames),
834 GBE_STATSA_INFO(net_bytes),
835 GBE_STATSA_INFO(rx_sof_overruns),
836 GBE_STATSA_INFO(rx_mof_overruns),
837 GBE_STATSA_INFO(rx_dma_overruns),
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500838 /* GBE module B */
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400839 GBE_STATSB_INFO(rx_good_frames),
840 GBE_STATSB_INFO(rx_broadcast_frames),
841 GBE_STATSB_INFO(rx_multicast_frames),
842 GBE_STATSB_INFO(rx_pause_frames),
843 GBE_STATSB_INFO(rx_crc_errors),
844 GBE_STATSB_INFO(rx_align_code_errors),
845 GBE_STATSB_INFO(rx_oversized_frames),
846 GBE_STATSB_INFO(rx_jabber_frames),
847 GBE_STATSB_INFO(rx_undersized_frames),
848 GBE_STATSB_INFO(rx_fragments),
849 GBE_STATSB_INFO(rx_bytes),
850 GBE_STATSB_INFO(tx_good_frames),
851 GBE_STATSB_INFO(tx_broadcast_frames),
852 GBE_STATSB_INFO(tx_multicast_frames),
853 GBE_STATSB_INFO(tx_pause_frames),
854 GBE_STATSB_INFO(tx_deferred_frames),
855 GBE_STATSB_INFO(tx_collision_frames),
856 GBE_STATSB_INFO(tx_single_coll_frames),
857 GBE_STATSB_INFO(tx_mult_coll_frames),
858 GBE_STATSB_INFO(tx_excessive_collisions),
859 GBE_STATSB_INFO(tx_late_collisions),
860 GBE_STATSB_INFO(tx_underrun),
861 GBE_STATSB_INFO(tx_carrier_sense_errors),
862 GBE_STATSB_INFO(tx_bytes),
863 GBE_STATSB_INFO(tx_64byte_frames),
864 GBE_STATSB_INFO(tx_65_to_127byte_frames),
865 GBE_STATSB_INFO(tx_128_to_255byte_frames),
866 GBE_STATSB_INFO(tx_256_to_511byte_frames),
867 GBE_STATSB_INFO(tx_512_to_1023byte_frames),
868 GBE_STATSB_INFO(tx_1024byte_frames),
869 GBE_STATSB_INFO(net_bytes),
870 GBE_STATSB_INFO(rx_sof_overruns),
871 GBE_STATSB_INFO(rx_mof_overruns),
872 GBE_STATSB_INFO(rx_dma_overruns),
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500873 /* GBE module C */
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400874 GBE_STATSC_INFO(rx_good_frames),
875 GBE_STATSC_INFO(rx_broadcast_frames),
876 GBE_STATSC_INFO(rx_multicast_frames),
877 GBE_STATSC_INFO(rx_pause_frames),
878 GBE_STATSC_INFO(rx_crc_errors),
879 GBE_STATSC_INFO(rx_align_code_errors),
880 GBE_STATSC_INFO(rx_oversized_frames),
881 GBE_STATSC_INFO(rx_jabber_frames),
882 GBE_STATSC_INFO(rx_undersized_frames),
883 GBE_STATSC_INFO(rx_fragments),
884 GBE_STATSC_INFO(rx_bytes),
885 GBE_STATSC_INFO(tx_good_frames),
886 GBE_STATSC_INFO(tx_broadcast_frames),
887 GBE_STATSC_INFO(tx_multicast_frames),
888 GBE_STATSC_INFO(tx_pause_frames),
889 GBE_STATSC_INFO(tx_deferred_frames),
890 GBE_STATSC_INFO(tx_collision_frames),
891 GBE_STATSC_INFO(tx_single_coll_frames),
892 GBE_STATSC_INFO(tx_mult_coll_frames),
893 GBE_STATSC_INFO(tx_excessive_collisions),
894 GBE_STATSC_INFO(tx_late_collisions),
895 GBE_STATSC_INFO(tx_underrun),
896 GBE_STATSC_INFO(tx_carrier_sense_errors),
897 GBE_STATSC_INFO(tx_bytes),
898 GBE_STATSC_INFO(tx_64byte_frames),
899 GBE_STATSC_INFO(tx_65_to_127byte_frames),
900 GBE_STATSC_INFO(tx_128_to_255byte_frames),
901 GBE_STATSC_INFO(tx_256_to_511byte_frames),
902 GBE_STATSC_INFO(tx_512_to_1023byte_frames),
903 GBE_STATSC_INFO(tx_1024byte_frames),
904 GBE_STATSC_INFO(net_bytes),
905 GBE_STATSC_INFO(rx_sof_overruns),
906 GBE_STATSC_INFO(rx_mof_overruns),
907 GBE_STATSC_INFO(rx_dma_overruns),
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500908 /* GBE module D */
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -0400909 GBE_STATSD_INFO(rx_good_frames),
910 GBE_STATSD_INFO(rx_broadcast_frames),
911 GBE_STATSD_INFO(rx_multicast_frames),
912 GBE_STATSD_INFO(rx_pause_frames),
913 GBE_STATSD_INFO(rx_crc_errors),
914 GBE_STATSD_INFO(rx_align_code_errors),
915 GBE_STATSD_INFO(rx_oversized_frames),
916 GBE_STATSD_INFO(rx_jabber_frames),
917 GBE_STATSD_INFO(rx_undersized_frames),
918 GBE_STATSD_INFO(rx_fragments),
919 GBE_STATSD_INFO(rx_bytes),
920 GBE_STATSD_INFO(tx_good_frames),
921 GBE_STATSD_INFO(tx_broadcast_frames),
922 GBE_STATSD_INFO(tx_multicast_frames),
923 GBE_STATSD_INFO(tx_pause_frames),
924 GBE_STATSD_INFO(tx_deferred_frames),
925 GBE_STATSD_INFO(tx_collision_frames),
926 GBE_STATSD_INFO(tx_single_coll_frames),
927 GBE_STATSD_INFO(tx_mult_coll_frames),
928 GBE_STATSD_INFO(tx_excessive_collisions),
929 GBE_STATSD_INFO(tx_late_collisions),
930 GBE_STATSD_INFO(tx_underrun),
931 GBE_STATSD_INFO(tx_carrier_sense_errors),
932 GBE_STATSD_INFO(tx_bytes),
933 GBE_STATSD_INFO(tx_64byte_frames),
934 GBE_STATSD_INFO(tx_65_to_127byte_frames),
935 GBE_STATSD_INFO(tx_128_to_255byte_frames),
936 GBE_STATSD_INFO(tx_256_to_511byte_frames),
937 GBE_STATSD_INFO(tx_512_to_1023byte_frames),
938 GBE_STATSD_INFO(tx_1024byte_frames),
939 GBE_STATSD_INFO(net_bytes),
940 GBE_STATSD_INFO(rx_sof_overruns),
941 GBE_STATSD_INFO(rx_mof_overruns),
942 GBE_STATSD_INFO(rx_dma_overruns),
Wingman Kwok6f8d3f32015-01-15 19:12:51 -0500943};
944
WingMan Kwok9a391c72015-03-20 16:11:25 -0400945/* This is the size of entries in GBENU_STATS_HOST */
WingMan Kwok5be4001e2015-07-23 15:57:24 -0400946#define GBENU_ET_STATS_HOST_SIZE 52
WingMan Kwok9a391c72015-03-20 16:11:25 -0400947
948#define GBENU_STATS_HOST(field) \
949{ \
950 "GBE_HOST:"#field, GBENU_STATS0_MODULE, \
951 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
952 offsetof(struct gbenu_hw_stats, field) \
953}
954
WingMan Kwok5be4001e2015-07-23 15:57:24 -0400955/* This is the size of entries in GBENU_STATS_PORT */
956#define GBENU_ET_STATS_PORT_SIZE 65
WingMan Kwok9a391c72015-03-20 16:11:25 -0400957
958#define GBENU_STATS_P1(field) \
959{ \
960 "GBE_P1:"#field, GBENU_STATS1_MODULE, \
961 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
962 offsetof(struct gbenu_hw_stats, field) \
963}
964
965#define GBENU_STATS_P2(field) \
966{ \
967 "GBE_P2:"#field, GBENU_STATS2_MODULE, \
968 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
969 offsetof(struct gbenu_hw_stats, field) \
970}
971
972#define GBENU_STATS_P3(field) \
973{ \
974 "GBE_P3:"#field, GBENU_STATS3_MODULE, \
975 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
976 offsetof(struct gbenu_hw_stats, field) \
977}
978
979#define GBENU_STATS_P4(field) \
980{ \
981 "GBE_P4:"#field, GBENU_STATS4_MODULE, \
982 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
983 offsetof(struct gbenu_hw_stats, field) \
984}
985
986#define GBENU_STATS_P5(field) \
987{ \
988 "GBE_P5:"#field, GBENU_STATS5_MODULE, \
989 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
990 offsetof(struct gbenu_hw_stats, field) \
991}
992
993#define GBENU_STATS_P6(field) \
994{ \
995 "GBE_P6:"#field, GBENU_STATS6_MODULE, \
996 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
997 offsetof(struct gbenu_hw_stats, field) \
998}
999
1000#define GBENU_STATS_P7(field) \
1001{ \
1002 "GBE_P7:"#field, GBENU_STATS7_MODULE, \
1003 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
1004 offsetof(struct gbenu_hw_stats, field) \
1005}
1006
1007#define GBENU_STATS_P8(field) \
1008{ \
1009 "GBE_P8:"#field, GBENU_STATS8_MODULE, \
1010 FIELD_SIZEOF(struct gbenu_hw_stats, field), \
1011 offsetof(struct gbenu_hw_stats, field) \
1012}
1013
1014static const struct netcp_ethtool_stat gbenu_et_stats[] = {
1015 /* GBENU Host Module */
1016 GBENU_STATS_HOST(rx_good_frames),
1017 GBENU_STATS_HOST(rx_broadcast_frames),
1018 GBENU_STATS_HOST(rx_multicast_frames),
1019 GBENU_STATS_HOST(rx_crc_errors),
1020 GBENU_STATS_HOST(rx_oversized_frames),
1021 GBENU_STATS_HOST(rx_undersized_frames),
1022 GBENU_STATS_HOST(ale_drop),
1023 GBENU_STATS_HOST(ale_overrun_drop),
1024 GBENU_STATS_HOST(rx_bytes),
1025 GBENU_STATS_HOST(tx_good_frames),
1026 GBENU_STATS_HOST(tx_broadcast_frames),
1027 GBENU_STATS_HOST(tx_multicast_frames),
1028 GBENU_STATS_HOST(tx_bytes),
1029 GBENU_STATS_HOST(tx_64B_frames),
1030 GBENU_STATS_HOST(tx_65_to_127B_frames),
1031 GBENU_STATS_HOST(tx_128_to_255B_frames),
1032 GBENU_STATS_HOST(tx_256_to_511B_frames),
1033 GBENU_STATS_HOST(tx_512_to_1023B_frames),
1034 GBENU_STATS_HOST(tx_1024B_frames),
1035 GBENU_STATS_HOST(net_bytes),
1036 GBENU_STATS_HOST(rx_bottom_fifo_drop),
1037 GBENU_STATS_HOST(rx_port_mask_drop),
1038 GBENU_STATS_HOST(rx_top_fifo_drop),
1039 GBENU_STATS_HOST(ale_rate_limit_drop),
1040 GBENU_STATS_HOST(ale_vid_ingress_drop),
1041 GBENU_STATS_HOST(ale_da_eq_sa_drop),
1042 GBENU_STATS_HOST(ale_unknown_ucast),
1043 GBENU_STATS_HOST(ale_unknown_ucast_bytes),
1044 GBENU_STATS_HOST(ale_unknown_mcast),
1045 GBENU_STATS_HOST(ale_unknown_mcast_bytes),
1046 GBENU_STATS_HOST(ale_unknown_bcast),
1047 GBENU_STATS_HOST(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001048 GBENU_STATS_HOST(ale_pol_match),
1049 GBENU_STATS_HOST(ale_pol_match_red),
1050 GBENU_STATS_HOST(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001051 GBENU_STATS_HOST(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001052 GBENU_STATS_HOST(tx_pri0_drop),
1053 GBENU_STATS_HOST(tx_pri1_drop),
1054 GBENU_STATS_HOST(tx_pri2_drop),
1055 GBENU_STATS_HOST(tx_pri3_drop),
1056 GBENU_STATS_HOST(tx_pri4_drop),
1057 GBENU_STATS_HOST(tx_pri5_drop),
1058 GBENU_STATS_HOST(tx_pri6_drop),
1059 GBENU_STATS_HOST(tx_pri7_drop),
1060 GBENU_STATS_HOST(tx_pri0_drop_bcnt),
1061 GBENU_STATS_HOST(tx_pri1_drop_bcnt),
1062 GBENU_STATS_HOST(tx_pri2_drop_bcnt),
1063 GBENU_STATS_HOST(tx_pri3_drop_bcnt),
1064 GBENU_STATS_HOST(tx_pri4_drop_bcnt),
1065 GBENU_STATS_HOST(tx_pri5_drop_bcnt),
1066 GBENU_STATS_HOST(tx_pri6_drop_bcnt),
1067 GBENU_STATS_HOST(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001068 /* GBENU Module 1 */
1069 GBENU_STATS_P1(rx_good_frames),
1070 GBENU_STATS_P1(rx_broadcast_frames),
1071 GBENU_STATS_P1(rx_multicast_frames),
1072 GBENU_STATS_P1(rx_pause_frames),
1073 GBENU_STATS_P1(rx_crc_errors),
1074 GBENU_STATS_P1(rx_align_code_errors),
1075 GBENU_STATS_P1(rx_oversized_frames),
1076 GBENU_STATS_P1(rx_jabber_frames),
1077 GBENU_STATS_P1(rx_undersized_frames),
1078 GBENU_STATS_P1(rx_fragments),
1079 GBENU_STATS_P1(ale_drop),
1080 GBENU_STATS_P1(ale_overrun_drop),
1081 GBENU_STATS_P1(rx_bytes),
1082 GBENU_STATS_P1(tx_good_frames),
1083 GBENU_STATS_P1(tx_broadcast_frames),
1084 GBENU_STATS_P1(tx_multicast_frames),
1085 GBENU_STATS_P1(tx_pause_frames),
1086 GBENU_STATS_P1(tx_deferred_frames),
1087 GBENU_STATS_P1(tx_collision_frames),
1088 GBENU_STATS_P1(tx_single_coll_frames),
1089 GBENU_STATS_P1(tx_mult_coll_frames),
1090 GBENU_STATS_P1(tx_excessive_collisions),
1091 GBENU_STATS_P1(tx_late_collisions),
1092 GBENU_STATS_P1(rx_ipg_error),
1093 GBENU_STATS_P1(tx_carrier_sense_errors),
1094 GBENU_STATS_P1(tx_bytes),
1095 GBENU_STATS_P1(tx_64B_frames),
1096 GBENU_STATS_P1(tx_65_to_127B_frames),
1097 GBENU_STATS_P1(tx_128_to_255B_frames),
1098 GBENU_STATS_P1(tx_256_to_511B_frames),
1099 GBENU_STATS_P1(tx_512_to_1023B_frames),
1100 GBENU_STATS_P1(tx_1024B_frames),
1101 GBENU_STATS_P1(net_bytes),
1102 GBENU_STATS_P1(rx_bottom_fifo_drop),
1103 GBENU_STATS_P1(rx_port_mask_drop),
1104 GBENU_STATS_P1(rx_top_fifo_drop),
1105 GBENU_STATS_P1(ale_rate_limit_drop),
1106 GBENU_STATS_P1(ale_vid_ingress_drop),
1107 GBENU_STATS_P1(ale_da_eq_sa_drop),
1108 GBENU_STATS_P1(ale_unknown_ucast),
1109 GBENU_STATS_P1(ale_unknown_ucast_bytes),
1110 GBENU_STATS_P1(ale_unknown_mcast),
1111 GBENU_STATS_P1(ale_unknown_mcast_bytes),
1112 GBENU_STATS_P1(ale_unknown_bcast),
1113 GBENU_STATS_P1(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001114 GBENU_STATS_P1(ale_pol_match),
1115 GBENU_STATS_P1(ale_pol_match_red),
1116 GBENU_STATS_P1(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001117 GBENU_STATS_P1(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001118 GBENU_STATS_P1(tx_pri0_drop),
1119 GBENU_STATS_P1(tx_pri1_drop),
1120 GBENU_STATS_P1(tx_pri2_drop),
1121 GBENU_STATS_P1(tx_pri3_drop),
1122 GBENU_STATS_P1(tx_pri4_drop),
1123 GBENU_STATS_P1(tx_pri5_drop),
1124 GBENU_STATS_P1(tx_pri6_drop),
1125 GBENU_STATS_P1(tx_pri7_drop),
1126 GBENU_STATS_P1(tx_pri0_drop_bcnt),
1127 GBENU_STATS_P1(tx_pri1_drop_bcnt),
1128 GBENU_STATS_P1(tx_pri2_drop_bcnt),
1129 GBENU_STATS_P1(tx_pri3_drop_bcnt),
1130 GBENU_STATS_P1(tx_pri4_drop_bcnt),
1131 GBENU_STATS_P1(tx_pri5_drop_bcnt),
1132 GBENU_STATS_P1(tx_pri6_drop_bcnt),
1133 GBENU_STATS_P1(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001134 /* GBENU Module 2 */
1135 GBENU_STATS_P2(rx_good_frames),
1136 GBENU_STATS_P2(rx_broadcast_frames),
1137 GBENU_STATS_P2(rx_multicast_frames),
1138 GBENU_STATS_P2(rx_pause_frames),
1139 GBENU_STATS_P2(rx_crc_errors),
1140 GBENU_STATS_P2(rx_align_code_errors),
1141 GBENU_STATS_P2(rx_oversized_frames),
1142 GBENU_STATS_P2(rx_jabber_frames),
1143 GBENU_STATS_P2(rx_undersized_frames),
1144 GBENU_STATS_P2(rx_fragments),
1145 GBENU_STATS_P2(ale_drop),
1146 GBENU_STATS_P2(ale_overrun_drop),
1147 GBENU_STATS_P2(rx_bytes),
1148 GBENU_STATS_P2(tx_good_frames),
1149 GBENU_STATS_P2(tx_broadcast_frames),
1150 GBENU_STATS_P2(tx_multicast_frames),
1151 GBENU_STATS_P2(tx_pause_frames),
1152 GBENU_STATS_P2(tx_deferred_frames),
1153 GBENU_STATS_P2(tx_collision_frames),
1154 GBENU_STATS_P2(tx_single_coll_frames),
1155 GBENU_STATS_P2(tx_mult_coll_frames),
1156 GBENU_STATS_P2(tx_excessive_collisions),
1157 GBENU_STATS_P2(tx_late_collisions),
1158 GBENU_STATS_P2(rx_ipg_error),
1159 GBENU_STATS_P2(tx_carrier_sense_errors),
1160 GBENU_STATS_P2(tx_bytes),
1161 GBENU_STATS_P2(tx_64B_frames),
1162 GBENU_STATS_P2(tx_65_to_127B_frames),
1163 GBENU_STATS_P2(tx_128_to_255B_frames),
1164 GBENU_STATS_P2(tx_256_to_511B_frames),
1165 GBENU_STATS_P2(tx_512_to_1023B_frames),
1166 GBENU_STATS_P2(tx_1024B_frames),
1167 GBENU_STATS_P2(net_bytes),
1168 GBENU_STATS_P2(rx_bottom_fifo_drop),
1169 GBENU_STATS_P2(rx_port_mask_drop),
1170 GBENU_STATS_P2(rx_top_fifo_drop),
1171 GBENU_STATS_P2(ale_rate_limit_drop),
1172 GBENU_STATS_P2(ale_vid_ingress_drop),
1173 GBENU_STATS_P2(ale_da_eq_sa_drop),
1174 GBENU_STATS_P2(ale_unknown_ucast),
1175 GBENU_STATS_P2(ale_unknown_ucast_bytes),
1176 GBENU_STATS_P2(ale_unknown_mcast),
1177 GBENU_STATS_P2(ale_unknown_mcast_bytes),
1178 GBENU_STATS_P2(ale_unknown_bcast),
1179 GBENU_STATS_P2(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001180 GBENU_STATS_P2(ale_pol_match),
1181 GBENU_STATS_P2(ale_pol_match_red),
1182 GBENU_STATS_P2(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001183 GBENU_STATS_P2(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001184 GBENU_STATS_P2(tx_pri0_drop),
1185 GBENU_STATS_P2(tx_pri1_drop),
1186 GBENU_STATS_P2(tx_pri2_drop),
1187 GBENU_STATS_P2(tx_pri3_drop),
1188 GBENU_STATS_P2(tx_pri4_drop),
1189 GBENU_STATS_P2(tx_pri5_drop),
1190 GBENU_STATS_P2(tx_pri6_drop),
1191 GBENU_STATS_P2(tx_pri7_drop),
1192 GBENU_STATS_P2(tx_pri0_drop_bcnt),
1193 GBENU_STATS_P2(tx_pri1_drop_bcnt),
1194 GBENU_STATS_P2(tx_pri2_drop_bcnt),
1195 GBENU_STATS_P2(tx_pri3_drop_bcnt),
1196 GBENU_STATS_P2(tx_pri4_drop_bcnt),
1197 GBENU_STATS_P2(tx_pri5_drop_bcnt),
1198 GBENU_STATS_P2(tx_pri6_drop_bcnt),
1199 GBENU_STATS_P2(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001200 /* GBENU Module 3 */
1201 GBENU_STATS_P3(rx_good_frames),
1202 GBENU_STATS_P3(rx_broadcast_frames),
1203 GBENU_STATS_P3(rx_multicast_frames),
1204 GBENU_STATS_P3(rx_pause_frames),
1205 GBENU_STATS_P3(rx_crc_errors),
1206 GBENU_STATS_P3(rx_align_code_errors),
1207 GBENU_STATS_P3(rx_oversized_frames),
1208 GBENU_STATS_P3(rx_jabber_frames),
1209 GBENU_STATS_P3(rx_undersized_frames),
1210 GBENU_STATS_P3(rx_fragments),
1211 GBENU_STATS_P3(ale_drop),
1212 GBENU_STATS_P3(ale_overrun_drop),
1213 GBENU_STATS_P3(rx_bytes),
1214 GBENU_STATS_P3(tx_good_frames),
1215 GBENU_STATS_P3(tx_broadcast_frames),
1216 GBENU_STATS_P3(tx_multicast_frames),
1217 GBENU_STATS_P3(tx_pause_frames),
1218 GBENU_STATS_P3(tx_deferred_frames),
1219 GBENU_STATS_P3(tx_collision_frames),
1220 GBENU_STATS_P3(tx_single_coll_frames),
1221 GBENU_STATS_P3(tx_mult_coll_frames),
1222 GBENU_STATS_P3(tx_excessive_collisions),
1223 GBENU_STATS_P3(tx_late_collisions),
1224 GBENU_STATS_P3(rx_ipg_error),
1225 GBENU_STATS_P3(tx_carrier_sense_errors),
1226 GBENU_STATS_P3(tx_bytes),
1227 GBENU_STATS_P3(tx_64B_frames),
1228 GBENU_STATS_P3(tx_65_to_127B_frames),
1229 GBENU_STATS_P3(tx_128_to_255B_frames),
1230 GBENU_STATS_P3(tx_256_to_511B_frames),
1231 GBENU_STATS_P3(tx_512_to_1023B_frames),
1232 GBENU_STATS_P3(tx_1024B_frames),
1233 GBENU_STATS_P3(net_bytes),
1234 GBENU_STATS_P3(rx_bottom_fifo_drop),
1235 GBENU_STATS_P3(rx_port_mask_drop),
1236 GBENU_STATS_P3(rx_top_fifo_drop),
1237 GBENU_STATS_P3(ale_rate_limit_drop),
1238 GBENU_STATS_P3(ale_vid_ingress_drop),
1239 GBENU_STATS_P3(ale_da_eq_sa_drop),
1240 GBENU_STATS_P3(ale_unknown_ucast),
1241 GBENU_STATS_P3(ale_unknown_ucast_bytes),
1242 GBENU_STATS_P3(ale_unknown_mcast),
1243 GBENU_STATS_P3(ale_unknown_mcast_bytes),
1244 GBENU_STATS_P3(ale_unknown_bcast),
1245 GBENU_STATS_P3(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001246 GBENU_STATS_P3(ale_pol_match),
1247 GBENU_STATS_P3(ale_pol_match_red),
1248 GBENU_STATS_P3(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001249 GBENU_STATS_P3(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001250 GBENU_STATS_P3(tx_pri0_drop),
1251 GBENU_STATS_P3(tx_pri1_drop),
1252 GBENU_STATS_P3(tx_pri2_drop),
1253 GBENU_STATS_P3(tx_pri3_drop),
1254 GBENU_STATS_P3(tx_pri4_drop),
1255 GBENU_STATS_P3(tx_pri5_drop),
1256 GBENU_STATS_P3(tx_pri6_drop),
1257 GBENU_STATS_P3(tx_pri7_drop),
1258 GBENU_STATS_P3(tx_pri0_drop_bcnt),
1259 GBENU_STATS_P3(tx_pri1_drop_bcnt),
1260 GBENU_STATS_P3(tx_pri2_drop_bcnt),
1261 GBENU_STATS_P3(tx_pri3_drop_bcnt),
1262 GBENU_STATS_P3(tx_pri4_drop_bcnt),
1263 GBENU_STATS_P3(tx_pri5_drop_bcnt),
1264 GBENU_STATS_P3(tx_pri6_drop_bcnt),
1265 GBENU_STATS_P3(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001266 /* GBENU Module 4 */
1267 GBENU_STATS_P4(rx_good_frames),
1268 GBENU_STATS_P4(rx_broadcast_frames),
1269 GBENU_STATS_P4(rx_multicast_frames),
1270 GBENU_STATS_P4(rx_pause_frames),
1271 GBENU_STATS_P4(rx_crc_errors),
1272 GBENU_STATS_P4(rx_align_code_errors),
1273 GBENU_STATS_P4(rx_oversized_frames),
1274 GBENU_STATS_P4(rx_jabber_frames),
1275 GBENU_STATS_P4(rx_undersized_frames),
1276 GBENU_STATS_P4(rx_fragments),
1277 GBENU_STATS_P4(ale_drop),
1278 GBENU_STATS_P4(ale_overrun_drop),
1279 GBENU_STATS_P4(rx_bytes),
1280 GBENU_STATS_P4(tx_good_frames),
1281 GBENU_STATS_P4(tx_broadcast_frames),
1282 GBENU_STATS_P4(tx_multicast_frames),
1283 GBENU_STATS_P4(tx_pause_frames),
1284 GBENU_STATS_P4(tx_deferred_frames),
1285 GBENU_STATS_P4(tx_collision_frames),
1286 GBENU_STATS_P4(tx_single_coll_frames),
1287 GBENU_STATS_P4(tx_mult_coll_frames),
1288 GBENU_STATS_P4(tx_excessive_collisions),
1289 GBENU_STATS_P4(tx_late_collisions),
1290 GBENU_STATS_P4(rx_ipg_error),
1291 GBENU_STATS_P4(tx_carrier_sense_errors),
1292 GBENU_STATS_P4(tx_bytes),
1293 GBENU_STATS_P4(tx_64B_frames),
1294 GBENU_STATS_P4(tx_65_to_127B_frames),
1295 GBENU_STATS_P4(tx_128_to_255B_frames),
1296 GBENU_STATS_P4(tx_256_to_511B_frames),
1297 GBENU_STATS_P4(tx_512_to_1023B_frames),
1298 GBENU_STATS_P4(tx_1024B_frames),
1299 GBENU_STATS_P4(net_bytes),
1300 GBENU_STATS_P4(rx_bottom_fifo_drop),
1301 GBENU_STATS_P4(rx_port_mask_drop),
1302 GBENU_STATS_P4(rx_top_fifo_drop),
1303 GBENU_STATS_P4(ale_rate_limit_drop),
1304 GBENU_STATS_P4(ale_vid_ingress_drop),
1305 GBENU_STATS_P4(ale_da_eq_sa_drop),
1306 GBENU_STATS_P4(ale_unknown_ucast),
1307 GBENU_STATS_P4(ale_unknown_ucast_bytes),
1308 GBENU_STATS_P4(ale_unknown_mcast),
1309 GBENU_STATS_P4(ale_unknown_mcast_bytes),
1310 GBENU_STATS_P4(ale_unknown_bcast),
1311 GBENU_STATS_P4(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001312 GBENU_STATS_P4(ale_pol_match),
1313 GBENU_STATS_P4(ale_pol_match_red),
1314 GBENU_STATS_P4(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001315 GBENU_STATS_P4(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001316 GBENU_STATS_P4(tx_pri0_drop),
1317 GBENU_STATS_P4(tx_pri1_drop),
1318 GBENU_STATS_P4(tx_pri2_drop),
1319 GBENU_STATS_P4(tx_pri3_drop),
1320 GBENU_STATS_P4(tx_pri4_drop),
1321 GBENU_STATS_P4(tx_pri5_drop),
1322 GBENU_STATS_P4(tx_pri6_drop),
1323 GBENU_STATS_P4(tx_pri7_drop),
1324 GBENU_STATS_P4(tx_pri0_drop_bcnt),
1325 GBENU_STATS_P4(tx_pri1_drop_bcnt),
1326 GBENU_STATS_P4(tx_pri2_drop_bcnt),
1327 GBENU_STATS_P4(tx_pri3_drop_bcnt),
1328 GBENU_STATS_P4(tx_pri4_drop_bcnt),
1329 GBENU_STATS_P4(tx_pri5_drop_bcnt),
1330 GBENU_STATS_P4(tx_pri6_drop_bcnt),
1331 GBENU_STATS_P4(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001332 /* GBENU Module 5 */
1333 GBENU_STATS_P5(rx_good_frames),
1334 GBENU_STATS_P5(rx_broadcast_frames),
1335 GBENU_STATS_P5(rx_multicast_frames),
1336 GBENU_STATS_P5(rx_pause_frames),
1337 GBENU_STATS_P5(rx_crc_errors),
1338 GBENU_STATS_P5(rx_align_code_errors),
1339 GBENU_STATS_P5(rx_oversized_frames),
1340 GBENU_STATS_P5(rx_jabber_frames),
1341 GBENU_STATS_P5(rx_undersized_frames),
1342 GBENU_STATS_P5(rx_fragments),
1343 GBENU_STATS_P5(ale_drop),
1344 GBENU_STATS_P5(ale_overrun_drop),
1345 GBENU_STATS_P5(rx_bytes),
1346 GBENU_STATS_P5(tx_good_frames),
1347 GBENU_STATS_P5(tx_broadcast_frames),
1348 GBENU_STATS_P5(tx_multicast_frames),
1349 GBENU_STATS_P5(tx_pause_frames),
1350 GBENU_STATS_P5(tx_deferred_frames),
1351 GBENU_STATS_P5(tx_collision_frames),
1352 GBENU_STATS_P5(tx_single_coll_frames),
1353 GBENU_STATS_P5(tx_mult_coll_frames),
1354 GBENU_STATS_P5(tx_excessive_collisions),
1355 GBENU_STATS_P5(tx_late_collisions),
1356 GBENU_STATS_P5(rx_ipg_error),
1357 GBENU_STATS_P5(tx_carrier_sense_errors),
1358 GBENU_STATS_P5(tx_bytes),
1359 GBENU_STATS_P5(tx_64B_frames),
1360 GBENU_STATS_P5(tx_65_to_127B_frames),
1361 GBENU_STATS_P5(tx_128_to_255B_frames),
1362 GBENU_STATS_P5(tx_256_to_511B_frames),
1363 GBENU_STATS_P5(tx_512_to_1023B_frames),
1364 GBENU_STATS_P5(tx_1024B_frames),
1365 GBENU_STATS_P5(net_bytes),
1366 GBENU_STATS_P5(rx_bottom_fifo_drop),
1367 GBENU_STATS_P5(rx_port_mask_drop),
1368 GBENU_STATS_P5(rx_top_fifo_drop),
1369 GBENU_STATS_P5(ale_rate_limit_drop),
1370 GBENU_STATS_P5(ale_vid_ingress_drop),
1371 GBENU_STATS_P5(ale_da_eq_sa_drop),
1372 GBENU_STATS_P5(ale_unknown_ucast),
1373 GBENU_STATS_P5(ale_unknown_ucast_bytes),
1374 GBENU_STATS_P5(ale_unknown_mcast),
1375 GBENU_STATS_P5(ale_unknown_mcast_bytes),
1376 GBENU_STATS_P5(ale_unknown_bcast),
1377 GBENU_STATS_P5(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001378 GBENU_STATS_P5(ale_pol_match),
1379 GBENU_STATS_P5(ale_pol_match_red),
1380 GBENU_STATS_P5(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001381 GBENU_STATS_P5(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001382 GBENU_STATS_P5(tx_pri0_drop),
1383 GBENU_STATS_P5(tx_pri1_drop),
1384 GBENU_STATS_P5(tx_pri2_drop),
1385 GBENU_STATS_P5(tx_pri3_drop),
1386 GBENU_STATS_P5(tx_pri4_drop),
1387 GBENU_STATS_P5(tx_pri5_drop),
1388 GBENU_STATS_P5(tx_pri6_drop),
1389 GBENU_STATS_P5(tx_pri7_drop),
1390 GBENU_STATS_P5(tx_pri0_drop_bcnt),
1391 GBENU_STATS_P5(tx_pri1_drop_bcnt),
1392 GBENU_STATS_P5(tx_pri2_drop_bcnt),
1393 GBENU_STATS_P5(tx_pri3_drop_bcnt),
1394 GBENU_STATS_P5(tx_pri4_drop_bcnt),
1395 GBENU_STATS_P5(tx_pri5_drop_bcnt),
1396 GBENU_STATS_P5(tx_pri6_drop_bcnt),
1397 GBENU_STATS_P5(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001398 /* GBENU Module 6 */
1399 GBENU_STATS_P6(rx_good_frames),
1400 GBENU_STATS_P6(rx_broadcast_frames),
1401 GBENU_STATS_P6(rx_multicast_frames),
1402 GBENU_STATS_P6(rx_pause_frames),
1403 GBENU_STATS_P6(rx_crc_errors),
1404 GBENU_STATS_P6(rx_align_code_errors),
1405 GBENU_STATS_P6(rx_oversized_frames),
1406 GBENU_STATS_P6(rx_jabber_frames),
1407 GBENU_STATS_P6(rx_undersized_frames),
1408 GBENU_STATS_P6(rx_fragments),
1409 GBENU_STATS_P6(ale_drop),
1410 GBENU_STATS_P6(ale_overrun_drop),
1411 GBENU_STATS_P6(rx_bytes),
1412 GBENU_STATS_P6(tx_good_frames),
1413 GBENU_STATS_P6(tx_broadcast_frames),
1414 GBENU_STATS_P6(tx_multicast_frames),
1415 GBENU_STATS_P6(tx_pause_frames),
1416 GBENU_STATS_P6(tx_deferred_frames),
1417 GBENU_STATS_P6(tx_collision_frames),
1418 GBENU_STATS_P6(tx_single_coll_frames),
1419 GBENU_STATS_P6(tx_mult_coll_frames),
1420 GBENU_STATS_P6(tx_excessive_collisions),
1421 GBENU_STATS_P6(tx_late_collisions),
1422 GBENU_STATS_P6(rx_ipg_error),
1423 GBENU_STATS_P6(tx_carrier_sense_errors),
1424 GBENU_STATS_P6(tx_bytes),
1425 GBENU_STATS_P6(tx_64B_frames),
1426 GBENU_STATS_P6(tx_65_to_127B_frames),
1427 GBENU_STATS_P6(tx_128_to_255B_frames),
1428 GBENU_STATS_P6(tx_256_to_511B_frames),
1429 GBENU_STATS_P6(tx_512_to_1023B_frames),
1430 GBENU_STATS_P6(tx_1024B_frames),
1431 GBENU_STATS_P6(net_bytes),
1432 GBENU_STATS_P6(rx_bottom_fifo_drop),
1433 GBENU_STATS_P6(rx_port_mask_drop),
1434 GBENU_STATS_P6(rx_top_fifo_drop),
1435 GBENU_STATS_P6(ale_rate_limit_drop),
1436 GBENU_STATS_P6(ale_vid_ingress_drop),
1437 GBENU_STATS_P6(ale_da_eq_sa_drop),
1438 GBENU_STATS_P6(ale_unknown_ucast),
1439 GBENU_STATS_P6(ale_unknown_ucast_bytes),
1440 GBENU_STATS_P6(ale_unknown_mcast),
1441 GBENU_STATS_P6(ale_unknown_mcast_bytes),
1442 GBENU_STATS_P6(ale_unknown_bcast),
1443 GBENU_STATS_P6(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001444 GBENU_STATS_P6(ale_pol_match),
1445 GBENU_STATS_P6(ale_pol_match_red),
1446 GBENU_STATS_P6(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001447 GBENU_STATS_P6(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001448 GBENU_STATS_P6(tx_pri0_drop),
1449 GBENU_STATS_P6(tx_pri1_drop),
1450 GBENU_STATS_P6(tx_pri2_drop),
1451 GBENU_STATS_P6(tx_pri3_drop),
1452 GBENU_STATS_P6(tx_pri4_drop),
1453 GBENU_STATS_P6(tx_pri5_drop),
1454 GBENU_STATS_P6(tx_pri6_drop),
1455 GBENU_STATS_P6(tx_pri7_drop),
1456 GBENU_STATS_P6(tx_pri0_drop_bcnt),
1457 GBENU_STATS_P6(tx_pri1_drop_bcnt),
1458 GBENU_STATS_P6(tx_pri2_drop_bcnt),
1459 GBENU_STATS_P6(tx_pri3_drop_bcnt),
1460 GBENU_STATS_P6(tx_pri4_drop_bcnt),
1461 GBENU_STATS_P6(tx_pri5_drop_bcnt),
1462 GBENU_STATS_P6(tx_pri6_drop_bcnt),
1463 GBENU_STATS_P6(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001464 /* GBENU Module 7 */
1465 GBENU_STATS_P7(rx_good_frames),
1466 GBENU_STATS_P7(rx_broadcast_frames),
1467 GBENU_STATS_P7(rx_multicast_frames),
1468 GBENU_STATS_P7(rx_pause_frames),
1469 GBENU_STATS_P7(rx_crc_errors),
1470 GBENU_STATS_P7(rx_align_code_errors),
1471 GBENU_STATS_P7(rx_oversized_frames),
1472 GBENU_STATS_P7(rx_jabber_frames),
1473 GBENU_STATS_P7(rx_undersized_frames),
1474 GBENU_STATS_P7(rx_fragments),
1475 GBENU_STATS_P7(ale_drop),
1476 GBENU_STATS_P7(ale_overrun_drop),
1477 GBENU_STATS_P7(rx_bytes),
1478 GBENU_STATS_P7(tx_good_frames),
1479 GBENU_STATS_P7(tx_broadcast_frames),
1480 GBENU_STATS_P7(tx_multicast_frames),
1481 GBENU_STATS_P7(tx_pause_frames),
1482 GBENU_STATS_P7(tx_deferred_frames),
1483 GBENU_STATS_P7(tx_collision_frames),
1484 GBENU_STATS_P7(tx_single_coll_frames),
1485 GBENU_STATS_P7(tx_mult_coll_frames),
1486 GBENU_STATS_P7(tx_excessive_collisions),
1487 GBENU_STATS_P7(tx_late_collisions),
1488 GBENU_STATS_P7(rx_ipg_error),
1489 GBENU_STATS_P7(tx_carrier_sense_errors),
1490 GBENU_STATS_P7(tx_bytes),
1491 GBENU_STATS_P7(tx_64B_frames),
1492 GBENU_STATS_P7(tx_65_to_127B_frames),
1493 GBENU_STATS_P7(tx_128_to_255B_frames),
1494 GBENU_STATS_P7(tx_256_to_511B_frames),
1495 GBENU_STATS_P7(tx_512_to_1023B_frames),
1496 GBENU_STATS_P7(tx_1024B_frames),
1497 GBENU_STATS_P7(net_bytes),
1498 GBENU_STATS_P7(rx_bottom_fifo_drop),
1499 GBENU_STATS_P7(rx_port_mask_drop),
1500 GBENU_STATS_P7(rx_top_fifo_drop),
1501 GBENU_STATS_P7(ale_rate_limit_drop),
1502 GBENU_STATS_P7(ale_vid_ingress_drop),
1503 GBENU_STATS_P7(ale_da_eq_sa_drop),
1504 GBENU_STATS_P7(ale_unknown_ucast),
1505 GBENU_STATS_P7(ale_unknown_ucast_bytes),
1506 GBENU_STATS_P7(ale_unknown_mcast),
1507 GBENU_STATS_P7(ale_unknown_mcast_bytes),
1508 GBENU_STATS_P7(ale_unknown_bcast),
1509 GBENU_STATS_P7(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001510 GBENU_STATS_P7(ale_pol_match),
1511 GBENU_STATS_P7(ale_pol_match_red),
1512 GBENU_STATS_P7(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001513 GBENU_STATS_P7(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001514 GBENU_STATS_P7(tx_pri0_drop),
1515 GBENU_STATS_P7(tx_pri1_drop),
1516 GBENU_STATS_P7(tx_pri2_drop),
1517 GBENU_STATS_P7(tx_pri3_drop),
1518 GBENU_STATS_P7(tx_pri4_drop),
1519 GBENU_STATS_P7(tx_pri5_drop),
1520 GBENU_STATS_P7(tx_pri6_drop),
1521 GBENU_STATS_P7(tx_pri7_drop),
1522 GBENU_STATS_P7(tx_pri0_drop_bcnt),
1523 GBENU_STATS_P7(tx_pri1_drop_bcnt),
1524 GBENU_STATS_P7(tx_pri2_drop_bcnt),
1525 GBENU_STATS_P7(tx_pri3_drop_bcnt),
1526 GBENU_STATS_P7(tx_pri4_drop_bcnt),
1527 GBENU_STATS_P7(tx_pri5_drop_bcnt),
1528 GBENU_STATS_P7(tx_pri6_drop_bcnt),
1529 GBENU_STATS_P7(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001530 /* GBENU Module 8 */
1531 GBENU_STATS_P8(rx_good_frames),
1532 GBENU_STATS_P8(rx_broadcast_frames),
1533 GBENU_STATS_P8(rx_multicast_frames),
1534 GBENU_STATS_P8(rx_pause_frames),
1535 GBENU_STATS_P8(rx_crc_errors),
1536 GBENU_STATS_P8(rx_align_code_errors),
1537 GBENU_STATS_P8(rx_oversized_frames),
1538 GBENU_STATS_P8(rx_jabber_frames),
1539 GBENU_STATS_P8(rx_undersized_frames),
1540 GBENU_STATS_P8(rx_fragments),
1541 GBENU_STATS_P8(ale_drop),
1542 GBENU_STATS_P8(ale_overrun_drop),
1543 GBENU_STATS_P8(rx_bytes),
1544 GBENU_STATS_P8(tx_good_frames),
1545 GBENU_STATS_P8(tx_broadcast_frames),
1546 GBENU_STATS_P8(tx_multicast_frames),
1547 GBENU_STATS_P8(tx_pause_frames),
1548 GBENU_STATS_P8(tx_deferred_frames),
1549 GBENU_STATS_P8(tx_collision_frames),
1550 GBENU_STATS_P8(tx_single_coll_frames),
1551 GBENU_STATS_P8(tx_mult_coll_frames),
1552 GBENU_STATS_P8(tx_excessive_collisions),
1553 GBENU_STATS_P8(tx_late_collisions),
1554 GBENU_STATS_P8(rx_ipg_error),
1555 GBENU_STATS_P8(tx_carrier_sense_errors),
1556 GBENU_STATS_P8(tx_bytes),
1557 GBENU_STATS_P8(tx_64B_frames),
1558 GBENU_STATS_P8(tx_65_to_127B_frames),
1559 GBENU_STATS_P8(tx_128_to_255B_frames),
1560 GBENU_STATS_P8(tx_256_to_511B_frames),
1561 GBENU_STATS_P8(tx_512_to_1023B_frames),
1562 GBENU_STATS_P8(tx_1024B_frames),
1563 GBENU_STATS_P8(net_bytes),
1564 GBENU_STATS_P8(rx_bottom_fifo_drop),
1565 GBENU_STATS_P8(rx_port_mask_drop),
1566 GBENU_STATS_P8(rx_top_fifo_drop),
1567 GBENU_STATS_P8(ale_rate_limit_drop),
1568 GBENU_STATS_P8(ale_vid_ingress_drop),
1569 GBENU_STATS_P8(ale_da_eq_sa_drop),
1570 GBENU_STATS_P8(ale_unknown_ucast),
1571 GBENU_STATS_P8(ale_unknown_ucast_bytes),
1572 GBENU_STATS_P8(ale_unknown_mcast),
1573 GBENU_STATS_P8(ale_unknown_mcast_bytes),
1574 GBENU_STATS_P8(ale_unknown_bcast),
1575 GBENU_STATS_P8(ale_unknown_bcast_bytes),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001576 GBENU_STATS_P8(ale_pol_match),
1577 GBENU_STATS_P8(ale_pol_match_red),
1578 GBENU_STATS_P8(ale_pol_match_yellow),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001579 GBENU_STATS_P8(tx_mem_protect_err),
WingMan Kwok5be4001e2015-07-23 15:57:24 -04001580 GBENU_STATS_P8(tx_pri0_drop),
1581 GBENU_STATS_P8(tx_pri1_drop),
1582 GBENU_STATS_P8(tx_pri2_drop),
1583 GBENU_STATS_P8(tx_pri3_drop),
1584 GBENU_STATS_P8(tx_pri4_drop),
1585 GBENU_STATS_P8(tx_pri5_drop),
1586 GBENU_STATS_P8(tx_pri6_drop),
1587 GBENU_STATS_P8(tx_pri7_drop),
1588 GBENU_STATS_P8(tx_pri0_drop_bcnt),
1589 GBENU_STATS_P8(tx_pri1_drop_bcnt),
1590 GBENU_STATS_P8(tx_pri2_drop_bcnt),
1591 GBENU_STATS_P8(tx_pri3_drop_bcnt),
1592 GBENU_STATS_P8(tx_pri4_drop_bcnt),
1593 GBENU_STATS_P8(tx_pri5_drop_bcnt),
1594 GBENU_STATS_P8(tx_pri6_drop_bcnt),
1595 GBENU_STATS_P8(tx_pri7_drop_bcnt),
WingMan Kwok9a391c72015-03-20 16:11:25 -04001596};
1597
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -04001598#define XGBE_STATS0_INFO(field) \
1599{ \
1600 "GBE_0:"#field, XGBE_STATS0_MODULE, \
1601 FIELD_SIZEOF(struct xgbe_hw_stats, field), \
1602 offsetof(struct xgbe_hw_stats, field) \
1603}
Wingman Kwok90cff9e2015-01-15 19:12:52 -05001604
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -04001605#define XGBE_STATS1_INFO(field) \
1606{ \
1607 "GBE_1:"#field, XGBE_STATS1_MODULE, \
1608 FIELD_SIZEOF(struct xgbe_hw_stats, field), \
1609 offsetof(struct xgbe_hw_stats, field) \
1610}
Wingman Kwok90cff9e2015-01-15 19:12:52 -05001611
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -04001612#define XGBE_STATS2_INFO(field) \
1613{ \
1614 "GBE_2:"#field, XGBE_STATS2_MODULE, \
1615 FIELD_SIZEOF(struct xgbe_hw_stats, field), \
1616 offsetof(struct xgbe_hw_stats, field) \
1617}
Wingman Kwok90cff9e2015-01-15 19:12:52 -05001618
1619static const struct netcp_ethtool_stat xgbe10_et_stats[] = {
1620 /* GBE module 0 */
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -04001621 XGBE_STATS0_INFO(rx_good_frames),
1622 XGBE_STATS0_INFO(rx_broadcast_frames),
1623 XGBE_STATS0_INFO(rx_multicast_frames),
1624 XGBE_STATS0_INFO(rx_oversized_frames),
1625 XGBE_STATS0_INFO(rx_undersized_frames),
1626 XGBE_STATS0_INFO(overrun_type4),
1627 XGBE_STATS0_INFO(overrun_type5),
1628 XGBE_STATS0_INFO(rx_bytes),
1629 XGBE_STATS0_INFO(tx_good_frames),
1630 XGBE_STATS0_INFO(tx_broadcast_frames),
1631 XGBE_STATS0_INFO(tx_multicast_frames),
1632 XGBE_STATS0_INFO(tx_bytes),
1633 XGBE_STATS0_INFO(tx_64byte_frames),
1634 XGBE_STATS0_INFO(tx_65_to_127byte_frames),
1635 XGBE_STATS0_INFO(tx_128_to_255byte_frames),
1636 XGBE_STATS0_INFO(tx_256_to_511byte_frames),
1637 XGBE_STATS0_INFO(tx_512_to_1023byte_frames),
1638 XGBE_STATS0_INFO(tx_1024byte_frames),
1639 XGBE_STATS0_INFO(net_bytes),
1640 XGBE_STATS0_INFO(rx_sof_overruns),
1641 XGBE_STATS0_INFO(rx_mof_overruns),
1642 XGBE_STATS0_INFO(rx_dma_overruns),
Wingman Kwok90cff9e2015-01-15 19:12:52 -05001643 /* XGBE module 1 */
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -04001644 XGBE_STATS1_INFO(rx_good_frames),
1645 XGBE_STATS1_INFO(rx_broadcast_frames),
1646 XGBE_STATS1_INFO(rx_multicast_frames),
1647 XGBE_STATS1_INFO(rx_pause_frames),
1648 XGBE_STATS1_INFO(rx_crc_errors),
1649 XGBE_STATS1_INFO(rx_align_code_errors),
1650 XGBE_STATS1_INFO(rx_oversized_frames),
1651 XGBE_STATS1_INFO(rx_jabber_frames),
1652 XGBE_STATS1_INFO(rx_undersized_frames),
1653 XGBE_STATS1_INFO(rx_fragments),
1654 XGBE_STATS1_INFO(overrun_type4),
1655 XGBE_STATS1_INFO(overrun_type5),
1656 XGBE_STATS1_INFO(rx_bytes),
1657 XGBE_STATS1_INFO(tx_good_frames),
1658 XGBE_STATS1_INFO(tx_broadcast_frames),
1659 XGBE_STATS1_INFO(tx_multicast_frames),
1660 XGBE_STATS1_INFO(tx_pause_frames),
1661 XGBE_STATS1_INFO(tx_deferred_frames),
1662 XGBE_STATS1_INFO(tx_collision_frames),
1663 XGBE_STATS1_INFO(tx_single_coll_frames),
1664 XGBE_STATS1_INFO(tx_mult_coll_frames),
1665 XGBE_STATS1_INFO(tx_excessive_collisions),
1666 XGBE_STATS1_INFO(tx_late_collisions),
1667 XGBE_STATS1_INFO(tx_underrun),
1668 XGBE_STATS1_INFO(tx_carrier_sense_errors),
1669 XGBE_STATS1_INFO(tx_bytes),
1670 XGBE_STATS1_INFO(tx_64byte_frames),
1671 XGBE_STATS1_INFO(tx_65_to_127byte_frames),
1672 XGBE_STATS1_INFO(tx_128_to_255byte_frames),
1673 XGBE_STATS1_INFO(tx_256_to_511byte_frames),
1674 XGBE_STATS1_INFO(tx_512_to_1023byte_frames),
1675 XGBE_STATS1_INFO(tx_1024byte_frames),
1676 XGBE_STATS1_INFO(net_bytes),
1677 XGBE_STATS1_INFO(rx_sof_overruns),
1678 XGBE_STATS1_INFO(rx_mof_overruns),
1679 XGBE_STATS1_INFO(rx_dma_overruns),
Wingman Kwok90cff9e2015-01-15 19:12:52 -05001680 /* XGBE module 2 */
Karicheri, Muralidharanda866ba2015-03-20 16:11:24 -04001681 XGBE_STATS2_INFO(rx_good_frames),
1682 XGBE_STATS2_INFO(rx_broadcast_frames),
1683 XGBE_STATS2_INFO(rx_multicast_frames),
1684 XGBE_STATS2_INFO(rx_pause_frames),
1685 XGBE_STATS2_INFO(rx_crc_errors),
1686 XGBE_STATS2_INFO(rx_align_code_errors),
1687 XGBE_STATS2_INFO(rx_oversized_frames),
1688 XGBE_STATS2_INFO(rx_jabber_frames),
1689 XGBE_STATS2_INFO(rx_undersized_frames),
1690 XGBE_STATS2_INFO(rx_fragments),
1691 XGBE_STATS2_INFO(overrun_type4),
1692 XGBE_STATS2_INFO(overrun_type5),
1693 XGBE_STATS2_INFO(rx_bytes),
1694 XGBE_STATS2_INFO(tx_good_frames),
1695 XGBE_STATS2_INFO(tx_broadcast_frames),
1696 XGBE_STATS2_INFO(tx_multicast_frames),
1697 XGBE_STATS2_INFO(tx_pause_frames),
1698 XGBE_STATS2_INFO(tx_deferred_frames),
1699 XGBE_STATS2_INFO(tx_collision_frames),
1700 XGBE_STATS2_INFO(tx_single_coll_frames),
1701 XGBE_STATS2_INFO(tx_mult_coll_frames),
1702 XGBE_STATS2_INFO(tx_excessive_collisions),
1703 XGBE_STATS2_INFO(tx_late_collisions),
1704 XGBE_STATS2_INFO(tx_underrun),
1705 XGBE_STATS2_INFO(tx_carrier_sense_errors),
1706 XGBE_STATS2_INFO(tx_bytes),
1707 XGBE_STATS2_INFO(tx_64byte_frames),
1708 XGBE_STATS2_INFO(tx_65_to_127byte_frames),
1709 XGBE_STATS2_INFO(tx_128_to_255byte_frames),
1710 XGBE_STATS2_INFO(tx_256_to_511byte_frames),
1711 XGBE_STATS2_INFO(tx_512_to_1023byte_frames),
1712 XGBE_STATS2_INFO(tx_1024byte_frames),
1713 XGBE_STATS2_INFO(net_bytes),
1714 XGBE_STATS2_INFO(rx_sof_overruns),
1715 XGBE_STATS2_INFO(rx_mof_overruns),
1716 XGBE_STATS2_INFO(rx_dma_overruns),
Wingman Kwok90cff9e2015-01-15 19:12:52 -05001717};
1718
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001719#define for_each_intf(i, priv) \
1720 list_for_each_entry((i), &(priv)->gbe_intf_head, gbe_intf_list)
1721
1722#define for_each_sec_slave(slave, priv) \
1723 list_for_each_entry((slave), &(priv)->secondary_slaves, slave_list)
1724
1725#define first_sec_slave(priv) \
1726 list_first_entry(&priv->secondary_slaves, \
1727 struct gbe_slave, slave_list)
1728
1729static void keystone_get_drvinfo(struct net_device *ndev,
1730 struct ethtool_drvinfo *info)
1731{
1732 strncpy(info->driver, NETCP_DRIVER_NAME, sizeof(info->driver));
1733 strncpy(info->version, NETCP_DRIVER_VERSION, sizeof(info->version));
1734}
1735
1736static u32 keystone_get_msglevel(struct net_device *ndev)
1737{
1738 struct netcp_intf *netcp = netdev_priv(ndev);
1739
1740 return netcp->msg_enable;
1741}
1742
1743static void keystone_set_msglevel(struct net_device *ndev, u32 value)
1744{
1745 struct netcp_intf *netcp = netdev_priv(ndev);
1746
1747 netcp->msg_enable = value;
1748}
1749
WingMan Kwoke9838ef2016-12-19 17:55:56 -05001750static struct gbe_intf *keystone_get_intf_data(struct netcp_intf *netcp)
1751{
1752 struct gbe_intf *gbe_intf;
1753
1754 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
1755 if (!gbe_intf)
1756 gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp);
1757
1758 return gbe_intf;
1759}
1760
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001761static void keystone_get_stat_strings(struct net_device *ndev,
1762 uint32_t stringset, uint8_t *data)
1763{
1764 struct netcp_intf *netcp = netdev_priv(ndev);
1765 struct gbe_intf *gbe_intf;
1766 struct gbe_priv *gbe_dev;
1767 int i;
1768
WingMan Kwoke9838ef2016-12-19 17:55:56 -05001769 gbe_intf = keystone_get_intf_data(netcp);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001770 if (!gbe_intf)
1771 return;
1772 gbe_dev = gbe_intf->gbe_dev;
1773
1774 switch (stringset) {
1775 case ETH_SS_STATS:
1776 for (i = 0; i < gbe_dev->num_et_stats; i++) {
1777 memcpy(data, gbe_dev->et_stats[i].desc,
1778 ETH_GSTRING_LEN);
1779 data += ETH_GSTRING_LEN;
1780 }
1781 break;
1782 case ETH_SS_TEST:
1783 break;
1784 }
1785}
1786
1787static int keystone_get_sset_count(struct net_device *ndev, int stringset)
1788{
1789 struct netcp_intf *netcp = netdev_priv(ndev);
1790 struct gbe_intf *gbe_intf;
1791 struct gbe_priv *gbe_dev;
1792
WingMan Kwoke9838ef2016-12-19 17:55:56 -05001793 gbe_intf = keystone_get_intf_data(netcp);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001794 if (!gbe_intf)
1795 return -EINVAL;
1796 gbe_dev = gbe_intf->gbe_dev;
1797
1798 switch (stringset) {
1799 case ETH_SS_TEST:
1800 return 0;
1801 case ETH_SS_STATS:
1802 return gbe_dev->num_et_stats;
1803 default:
1804 return -EINVAL;
1805 }
1806}
1807
WingMan Kwok489e8a22015-07-23 15:57:23 -04001808static void gbe_reset_mod_stats(struct gbe_priv *gbe_dev, int stats_mod)
1809{
1810 void __iomem *base = gbe_dev->hw_stats_regs[stats_mod];
1811 u32 __iomem *p_stats_entry;
1812 int i;
1813
1814 for (i = 0; i < gbe_dev->num_et_stats; i++) {
1815 if (gbe_dev->et_stats[i].type == stats_mod) {
1816 p_stats_entry = base + gbe_dev->et_stats[i].offset;
1817 gbe_dev->hw_stats[i] = 0;
1818 gbe_dev->hw_stats_prev[i] = readl(p_stats_entry);
1819 }
1820 }
1821}
1822
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001823static inline void gbe_update_hw_stats_entry(struct gbe_priv *gbe_dev,
1824 int et_stats_entry)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001825{
1826 void __iomem *base = NULL;
WingMan Kwok489e8a22015-07-23 15:57:23 -04001827 u32 __iomem *p_stats_entry;
1828 u32 curr, delta;
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001829
1830 /* The hw_stats_regs pointers are already
1831 * properly set to point to the right base:
1832 */
1833 base = gbe_dev->hw_stats_regs[gbe_dev->et_stats[et_stats_entry].type];
WingMan Kwok489e8a22015-07-23 15:57:23 -04001834 p_stats_entry = base + gbe_dev->et_stats[et_stats_entry].offset;
1835 curr = readl(p_stats_entry);
1836 delta = curr - gbe_dev->hw_stats_prev[et_stats_entry];
1837 gbe_dev->hw_stats_prev[et_stats_entry] = curr;
1838 gbe_dev->hw_stats[et_stats_entry] += delta;
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001839}
1840
1841static void gbe_update_stats(struct gbe_priv *gbe_dev, uint64_t *data)
1842{
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001843 int i;
1844
1845 for (i = 0; i < gbe_dev->num_et_stats; i++) {
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001846 gbe_update_hw_stats_entry(gbe_dev, i);
1847
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001848 if (data)
1849 data[i] = gbe_dev->hw_stats[i];
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001850 }
1851}
1852
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001853static inline void gbe_stats_mod_visible_ver14(struct gbe_priv *gbe_dev,
1854 int stats_mod)
1855{
1856 u32 val;
1857
1858 val = readl(GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
1859
1860 switch (stats_mod) {
1861 case GBE_STATSA_MODULE:
1862 case GBE_STATSB_MODULE:
1863 val &= ~GBE_STATS_CD_SEL;
1864 break;
1865 case GBE_STATSC_MODULE:
1866 case GBE_STATSD_MODULE:
1867 val |= GBE_STATS_CD_SEL;
1868 break;
1869 default:
1870 return;
1871 }
1872
1873 /* make the stat module visible */
1874 writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
1875}
1876
WingMan Kwok489e8a22015-07-23 15:57:23 -04001877static void gbe_reset_mod_stats_ver14(struct gbe_priv *gbe_dev, int stats_mod)
1878{
1879 gbe_stats_mod_visible_ver14(gbe_dev, stats_mod);
1880 gbe_reset_mod_stats(gbe_dev, stats_mod);
1881}
1882
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001883static void gbe_update_stats_ver14(struct gbe_priv *gbe_dev, uint64_t *data)
1884{
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001885 u32 half_num_et_stats = (gbe_dev->num_et_stats / 2);
1886 int et_entry, j, pair;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001887
1888 for (pair = 0; pair < 2; pair++) {
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001889 gbe_stats_mod_visible_ver14(gbe_dev, (pair ?
1890 GBE_STATSC_MODULE :
1891 GBE_STATSA_MODULE));
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001892
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001893 for (j = 0; j < half_num_et_stats; j++) {
1894 et_entry = pair * half_num_et_stats + j;
1895 gbe_update_hw_stats_entry(gbe_dev, et_entry);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001896
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001897 if (data)
WingMan Kwokfbf64c12015-07-23 15:57:22 -04001898 data[et_entry] = gbe_dev->hw_stats[et_entry];
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001899 }
1900 }
1901}
1902
1903static void keystone_get_ethtool_stats(struct net_device *ndev,
1904 struct ethtool_stats *stats,
1905 uint64_t *data)
1906{
1907 struct netcp_intf *netcp = netdev_priv(ndev);
1908 struct gbe_intf *gbe_intf;
1909 struct gbe_priv *gbe_dev;
1910
WingMan Kwoke9838ef2016-12-19 17:55:56 -05001911 gbe_intf = keystone_get_intf_data(netcp);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001912 if (!gbe_intf)
1913 return;
1914
1915 gbe_dev = gbe_intf->gbe_dev;
1916 spin_lock_bh(&gbe_dev->hw_stats_lock);
Wingman Kwok90cff9e2015-01-15 19:12:52 -05001917 if (gbe_dev->ss_version == GBE_SS_VERSION_14)
1918 gbe_update_stats_ver14(gbe_dev, data);
1919 else
1920 gbe_update_stats(gbe_dev, data);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001921 spin_unlock_bh(&gbe_dev->hw_stats_lock);
1922}
1923
Philippe Reynes86e3a042016-10-08 19:48:15 +02001924static int keystone_get_link_ksettings(struct net_device *ndev,
1925 struct ethtool_link_ksettings *cmd)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001926{
1927 struct netcp_intf *netcp = netdev_priv(ndev);
1928 struct phy_device *phy = ndev->phydev;
1929 struct gbe_intf *gbe_intf;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001930
1931 if (!phy)
1932 return -EINVAL;
1933
WingMan Kwoke9838ef2016-12-19 17:55:56 -05001934 gbe_intf = keystone_get_intf_data(netcp);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001935 if (!gbe_intf)
1936 return -EINVAL;
1937
1938 if (!gbe_intf->slave)
1939 return -EINVAL;
1940
yuval.shaia@oracle.com55141742017-06-13 10:09:46 +03001941 phy_ethtool_ksettings_get(phy, cmd);
1942 cmd->base.port = gbe_intf->slave->phy_port_t;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001943
yuval.shaia@oracle.com55141742017-06-13 10:09:46 +03001944 return 0;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001945}
1946
Philippe Reynes86e3a042016-10-08 19:48:15 +02001947static int keystone_set_link_ksettings(struct net_device *ndev,
1948 const struct ethtool_link_ksettings *cmd)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001949{
1950 struct netcp_intf *netcp = netdev_priv(ndev);
1951 struct phy_device *phy = ndev->phydev;
1952 struct gbe_intf *gbe_intf;
Philippe Reynes86e3a042016-10-08 19:48:15 +02001953 u8 port = cmd->base.port;
1954 u32 advertising, supported;
1955 u32 features;
1956
1957 ethtool_convert_link_mode_to_legacy_u32(&advertising,
1958 cmd->link_modes.advertising);
1959 ethtool_convert_link_mode_to_legacy_u32(&supported,
1960 cmd->link_modes.supported);
1961 features = advertising & supported;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001962
1963 if (!phy)
1964 return -EINVAL;
1965
WingMan Kwoke9838ef2016-12-19 17:55:56 -05001966 gbe_intf = keystone_get_intf_data(netcp);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001967 if (!gbe_intf)
1968 return -EINVAL;
1969
1970 if (!gbe_intf->slave)
1971 return -EINVAL;
1972
Philippe Reynes86e3a042016-10-08 19:48:15 +02001973 if (port != gbe_intf->slave->phy_port_t) {
1974 if ((port == PORT_TP) && !(features & ADVERTISED_TP))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001975 return -EINVAL;
1976
Philippe Reynes86e3a042016-10-08 19:48:15 +02001977 if ((port == PORT_AUI) && !(features & ADVERTISED_AUI))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001978 return -EINVAL;
1979
Philippe Reynes86e3a042016-10-08 19:48:15 +02001980 if ((port == PORT_BNC) && !(features & ADVERTISED_BNC))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001981 return -EINVAL;
1982
Philippe Reynes86e3a042016-10-08 19:48:15 +02001983 if ((port == PORT_MII) && !(features & ADVERTISED_MII))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001984 return -EINVAL;
1985
Philippe Reynes86e3a042016-10-08 19:48:15 +02001986 if ((port == PORT_FIBRE) && !(features & ADVERTISED_FIBRE))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001987 return -EINVAL;
1988 }
1989
Philippe Reynes86e3a042016-10-08 19:48:15 +02001990 gbe_intf->slave->phy_port_t = port;
1991 return phy_ethtool_ksettings_set(phy, cmd);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05001992}
1993
WingMan Kwok62461682016-12-08 16:21:56 -06001994#if IS_ENABLED(CONFIG_TI_CPTS)
1995static int keystone_get_ts_info(struct net_device *ndev,
1996 struct ethtool_ts_info *info)
1997{
1998 struct netcp_intf *netcp = netdev_priv(ndev);
1999 struct gbe_intf *gbe_intf;
2000
2001 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
2002 if (!gbe_intf || !gbe_intf->gbe_dev->cpts)
2003 return -EINVAL;
2004
2005 info->so_timestamping =
2006 SOF_TIMESTAMPING_TX_HARDWARE |
2007 SOF_TIMESTAMPING_TX_SOFTWARE |
2008 SOF_TIMESTAMPING_RX_HARDWARE |
2009 SOF_TIMESTAMPING_RX_SOFTWARE |
2010 SOF_TIMESTAMPING_SOFTWARE |
2011 SOF_TIMESTAMPING_RAW_HARDWARE;
2012 info->phc_index = gbe_intf->gbe_dev->cpts->phc_index;
2013 info->tx_types =
2014 (1 << HWTSTAMP_TX_OFF) |
2015 (1 << HWTSTAMP_TX_ON);
2016 info->rx_filters =
2017 (1 << HWTSTAMP_FILTER_NONE) |
2018 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
2019 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT);
2020 return 0;
2021}
2022#else
2023static int keystone_get_ts_info(struct net_device *ndev,
2024 struct ethtool_ts_info *info)
2025{
2026 info->so_timestamping =
2027 SOF_TIMESTAMPING_TX_SOFTWARE |
2028 SOF_TIMESTAMPING_RX_SOFTWARE |
2029 SOF_TIMESTAMPING_SOFTWARE;
2030 info->phc_index = -1;
2031 info->tx_types = 0;
2032 info->rx_filters = 0;
2033 return 0;
2034}
2035#endif /* CONFIG_TI_CPTS */
2036
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002037static const struct ethtool_ops keystone_ethtool_ops = {
2038 .get_drvinfo = keystone_get_drvinfo,
2039 .get_link = ethtool_op_get_link,
2040 .get_msglevel = keystone_get_msglevel,
2041 .set_msglevel = keystone_set_msglevel,
2042 .get_strings = keystone_get_stat_strings,
2043 .get_sset_count = keystone_get_sset_count,
2044 .get_ethtool_stats = keystone_get_ethtool_stats,
Philippe Reynes86e3a042016-10-08 19:48:15 +02002045 .get_link_ksettings = keystone_get_link_ksettings,
2046 .set_link_ksettings = keystone_set_link_ksettings,
WingMan Kwok62461682016-12-08 16:21:56 -06002047 .get_ts_info = keystone_get_ts_info,
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002048};
2049
2050#define mac_hi(mac) (((mac)[0] << 0) | ((mac)[1] << 8) | \
2051 ((mac)[2] << 16) | ((mac)[3] << 24))
2052#define mac_lo(mac) (((mac)[4] << 0) | ((mac)[5] << 8))
2053
2054static void gbe_set_slave_mac(struct gbe_slave *slave,
2055 struct gbe_intf *gbe_intf)
2056{
2057 struct net_device *ndev = gbe_intf->ndev;
2058
2059 writel(mac_hi(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_hi));
2060 writel(mac_lo(ndev->dev_addr), GBE_REG_ADDR(slave, port_regs, sa_lo));
2061}
2062
2063static int gbe_get_slave_port(struct gbe_priv *priv, u32 slave_num)
2064{
2065 if (priv->host_port == 0)
2066 return slave_num + 1;
2067
2068 return slave_num;
2069}
2070
2071static void netcp_ethss_link_state_action(struct gbe_priv *gbe_dev,
2072 struct net_device *ndev,
2073 struct gbe_slave *slave,
2074 int up)
2075{
2076 struct phy_device *phy = slave->phy;
2077 u32 mac_control = 0;
2078
2079 if (up) {
2080 mac_control = slave->mac_control;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002081 if (phy && (phy->speed == SPEED_1000)) {
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002082 mac_control |= MACSL_GIG_MODE;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002083 mac_control &= ~MACSL_XGIG_MODE;
2084 } else if (phy && (phy->speed == SPEED_10000)) {
2085 mac_control |= MACSL_XGIG_MODE;
2086 mac_control &= ~MACSL_GIG_MODE;
2087 }
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002088
2089 writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
2090 mac_control));
2091
2092 cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
2093 ALE_PORT_STATE,
2094 ALE_PORT_STATE_FORWARD);
2095
Karicheri, Muralidharan8e046d62015-04-27 14:12:43 -04002096 if (ndev && slave->open &&
2097 slave->link_interface != SGMII_LINK_MAC_PHY &&
2098 slave->link_interface != XGMII_LINK_MAC_PHY)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002099 netif_carrier_on(ndev);
2100 } else {
2101 writel(mac_control, GBE_REG_ADDR(slave, emac_regs,
2102 mac_control));
2103 cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
2104 ALE_PORT_STATE,
2105 ALE_PORT_STATE_DISABLE);
Karicheri, Muralidharan8e046d62015-04-27 14:12:43 -04002106 if (ndev &&
2107 slave->link_interface != SGMII_LINK_MAC_PHY &&
2108 slave->link_interface != XGMII_LINK_MAC_PHY)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002109 netif_carrier_off(ndev);
2110 }
2111
2112 if (phy)
2113 phy_print_status(phy);
2114}
2115
2116static bool gbe_phy_link_status(struct gbe_slave *slave)
2117{
2118 return !slave->phy || slave->phy->link;
2119}
2120
2121static void netcp_ethss_update_link_state(struct gbe_priv *gbe_dev,
2122 struct gbe_slave *slave,
2123 struct net_device *ndev)
2124{
2125 int sp = slave->slave_num;
2126 int phy_link_state, sgmii_link_state = 1, link_state;
2127
2128 if (!slave->open)
2129 return;
2130
WingMan Kwok9a391c72015-03-20 16:11:25 -04002131 if (!SLAVE_LINK_IS_XGMII(slave)) {
WingMan Kwok8c851512015-09-23 13:37:05 -04002132 sgmii_link_state =
2133 netcp_sgmii_get_port_link(SGMII_BASE(gbe_dev, sp), sp);
WingMan Kwok9a391c72015-03-20 16:11:25 -04002134 }
2135
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002136 phy_link_state = gbe_phy_link_status(slave);
2137 link_state = phy_link_state & sgmii_link_state;
2138
2139 if (atomic_xchg(&slave->link_state, link_state) != link_state)
2140 netcp_ethss_link_state_action(gbe_dev, ndev, slave,
2141 link_state);
2142}
2143
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002144static void xgbe_adjust_link(struct net_device *ndev)
2145{
2146 struct netcp_intf *netcp = netdev_priv(ndev);
2147 struct gbe_intf *gbe_intf;
2148
2149 gbe_intf = netcp_module_get_intf_data(&xgbe_module, netcp);
2150 if (!gbe_intf)
2151 return;
2152
2153 netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
2154 ndev);
2155}
2156
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002157static void gbe_adjust_link(struct net_device *ndev)
2158{
2159 struct netcp_intf *netcp = netdev_priv(ndev);
2160 struct gbe_intf *gbe_intf;
2161
2162 gbe_intf = netcp_module_get_intf_data(&gbe_module, netcp);
2163 if (!gbe_intf)
2164 return;
2165
2166 netcp_ethss_update_link_state(gbe_intf->gbe_dev, gbe_intf->slave,
2167 ndev);
2168}
2169
2170static void gbe_adjust_link_sec_slaves(struct net_device *ndev)
2171{
2172 struct gbe_priv *gbe_dev = netdev_priv(ndev);
2173 struct gbe_slave *slave;
2174
2175 for_each_sec_slave(slave, gbe_dev)
2176 netcp_ethss_update_link_state(gbe_dev, slave, NULL);
2177}
2178
2179/* Reset EMAC
2180 * Soft reset is set and polled until clear, or until a timeout occurs
2181 */
2182static int gbe_port_reset(struct gbe_slave *slave)
2183{
2184 u32 i, v;
2185
2186 /* Set the soft reset bit */
2187 writel(SOFT_RESET, GBE_REG_ADDR(slave, emac_regs, soft_reset));
2188
2189 /* Wait for the bit to clear */
2190 for (i = 0; i < DEVICE_EMACSL_RESET_POLL_COUNT; i++) {
2191 v = readl(GBE_REG_ADDR(slave, emac_regs, soft_reset));
2192 if ((v & SOFT_RESET_MASK) != SOFT_RESET)
2193 return 0;
2194 }
2195
2196 /* Timeout on the reset */
2197 return GMACSL_RET_WARN_RESET_INCOMPLETE;
2198}
2199
2200/* Configure EMAC */
2201static void gbe_port_config(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
2202 int max_rx_len)
2203{
WingMan Kwok9a391c72015-03-20 16:11:25 -04002204 void __iomem *rx_maxlen_reg;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002205 u32 xgmii_mode;
2206
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002207 if (max_rx_len > NETCP_MAX_FRAME_SIZE)
2208 max_rx_len = NETCP_MAX_FRAME_SIZE;
2209
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002210 /* Enable correct MII mode at SS level */
2211 if ((gbe_dev->ss_version == XGBE_SS_VERSION_10) &&
2212 (slave->link_interface >= XGMII_LINK_MAC_PHY)) {
2213 xgmii_mode = readl(GBE_REG_ADDR(gbe_dev, ss_regs, control));
2214 xgmii_mode |= (1 << slave->slave_num);
2215 writel(xgmii_mode, GBE_REG_ADDR(gbe_dev, ss_regs, control));
2216 }
2217
WingMan Kwok9a391c72015-03-20 16:11:25 -04002218 if (IS_SS_ID_MU(gbe_dev))
2219 rx_maxlen_reg = GBE_REG_ADDR(slave, port_regs, rx_maxlen);
2220 else
2221 rx_maxlen_reg = GBE_REG_ADDR(slave, emac_regs, rx_maxlen);
2222
2223 writel(max_rx_len, rx_maxlen_reg);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002224 writel(slave->mac_control, GBE_REG_ADDR(slave, emac_regs, mac_control));
2225}
2226
WingMan Kwok7025e882015-07-24 15:02:29 -04002227static void gbe_sgmii_rtreset(struct gbe_priv *priv,
2228 struct gbe_slave *slave, bool set)
2229{
WingMan Kwok7025e882015-07-24 15:02:29 -04002230 if (SLAVE_LINK_IS_XGMII(slave))
2231 return;
2232
WingMan Kwok8c851512015-09-23 13:37:05 -04002233 netcp_sgmii_rtreset(SGMII_BASE(priv, slave->slave_num),
2234 slave->slave_num, set);
WingMan Kwok7025e882015-07-24 15:02:29 -04002235}
2236
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002237static void gbe_slave_stop(struct gbe_intf *intf)
2238{
2239 struct gbe_priv *gbe_dev = intf->gbe_dev;
2240 struct gbe_slave *slave = intf->slave;
2241
WingMan Kwok7025e882015-07-24 15:02:29 -04002242 gbe_sgmii_rtreset(gbe_dev, slave, true);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002243 gbe_port_reset(slave);
2244 /* Disable forwarding */
2245 cpsw_ale_control_set(gbe_dev->ale, slave->port_num,
2246 ALE_PORT_STATE, ALE_PORT_STATE_DISABLE);
2247 cpsw_ale_del_mcast(gbe_dev->ale, intf->ndev->broadcast,
2248 1 << slave->port_num, 0, 0);
2249
2250 if (!slave->phy)
2251 return;
2252
2253 phy_stop(slave->phy);
2254 phy_disconnect(slave->phy);
2255 slave->phy = NULL;
2256}
2257
2258static void gbe_sgmii_config(struct gbe_priv *priv, struct gbe_slave *slave)
2259{
WingMan Kwok8c851512015-09-23 13:37:05 -04002260 if (SLAVE_LINK_IS_XGMII(slave))
2261 return;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002262
WingMan Kwok8c851512015-09-23 13:37:05 -04002263 netcp_sgmii_reset(SGMII_BASE(priv, slave->slave_num), slave->slave_num);
2264 netcp_sgmii_config(SGMII_BASE(priv, slave->slave_num), slave->slave_num,
2265 slave->link_interface);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002266}
2267
2268static int gbe_slave_open(struct gbe_intf *gbe_intf)
2269{
2270 struct gbe_priv *priv = gbe_intf->gbe_dev;
2271 struct gbe_slave *slave = gbe_intf->slave;
2272 phy_interface_t phy_mode;
2273 bool has_phy = false;
2274
2275 void (*hndlr)(struct net_device *) = gbe_adjust_link;
2276
2277 gbe_sgmii_config(priv, slave);
2278 gbe_port_reset(slave);
WingMan Kwok7025e882015-07-24 15:02:29 -04002279 gbe_sgmii_rtreset(priv, slave, false);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002280 gbe_port_config(priv, slave, priv->rx_packet_max);
2281 gbe_set_slave_mac(slave, gbe_intf);
2282 /* enable forwarding */
2283 cpsw_ale_control_set(priv->ale, slave->port_num,
2284 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
2285 cpsw_ale_add_mcast(priv->ale, gbe_intf->ndev->broadcast,
2286 1 << slave->port_num, 0, 0, ALE_MCAST_FWD_2);
2287
2288 if (slave->link_interface == SGMII_LINK_MAC_PHY) {
2289 has_phy = true;
2290 phy_mode = PHY_INTERFACE_MODE_SGMII;
2291 slave->phy_port_t = PORT_MII;
2292 } else if (slave->link_interface == XGMII_LINK_MAC_PHY) {
2293 has_phy = true;
2294 phy_mode = PHY_INTERFACE_MODE_NA;
2295 slave->phy_port_t = PORT_FIBRE;
2296 }
2297
2298 if (has_phy) {
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002299 if (priv->ss_version == XGBE_SS_VERSION_10)
2300 hndlr = xgbe_adjust_link;
2301
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002302 slave->phy = of_phy_connect(gbe_intf->ndev,
2303 slave->phy_node,
2304 hndlr, 0,
2305 phy_mode);
2306 if (!slave->phy) {
2307 dev_err(priv->dev, "phy not found on slave %d\n",
2308 slave->slave_num);
2309 return -ENODEV;
2310 }
2311 dev_dbg(priv->dev, "phy found: id is: 0x%s\n",
Andrew Lunn84eff6d2016-01-06 20:11:10 +01002312 phydev_name(slave->phy));
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002313 phy_start(slave->phy);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002314 }
2315 return 0;
2316}
2317
2318static void gbe_init_host_port(struct gbe_priv *priv)
2319{
2320 int bypass_en = 1;
WingMan Kwok9a391c72015-03-20 16:11:25 -04002321
2322 /* Host Tx Pri */
WingMan Kwok4c0ef232016-12-19 17:55:57 -05002323 if (IS_SS_ID_NU(priv) || IS_SS_ID_XGBE(priv))
WingMan Kwok9a391c72015-03-20 16:11:25 -04002324 writel(HOST_TX_PRI_MAP_DEFAULT,
2325 GBE_REG_ADDR(priv, host_port_regs, tx_pri_map));
2326
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002327 /* Max length register */
2328 writel(NETCP_MAX_FRAME_SIZE, GBE_REG_ADDR(priv, host_port_regs,
2329 rx_maxlen));
2330
2331 cpsw_ale_start(priv->ale);
2332
2333 if (priv->enable_ale)
2334 bypass_en = 0;
2335
2336 cpsw_ale_control_set(priv->ale, 0, ALE_BYPASS, bypass_en);
2337
2338 cpsw_ale_control_set(priv->ale, 0, ALE_NO_PORT_VLAN, 1);
2339
2340 cpsw_ale_control_set(priv->ale, priv->host_port,
2341 ALE_PORT_STATE, ALE_PORT_STATE_FORWARD);
2342
2343 cpsw_ale_control_set(priv->ale, 0,
2344 ALE_PORT_UNKNOWN_VLAN_MEMBER,
2345 GBE_PORT_MASK(priv->ale_ports));
2346
2347 cpsw_ale_control_set(priv->ale, 0,
2348 ALE_PORT_UNKNOWN_MCAST_FLOOD,
2349 GBE_PORT_MASK(priv->ale_ports - 1));
2350
2351 cpsw_ale_control_set(priv->ale, 0,
2352 ALE_PORT_UNKNOWN_REG_MCAST_FLOOD,
2353 GBE_PORT_MASK(priv->ale_ports));
2354
2355 cpsw_ale_control_set(priv->ale, 0,
2356 ALE_PORT_UNTAGGED_EGRESS,
2357 GBE_PORT_MASK(priv->ale_ports));
2358}
2359
2360static void gbe_add_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2361{
2362 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2363 u16 vlan_id;
2364
2365 cpsw_ale_add_mcast(gbe_dev->ale, addr,
2366 GBE_PORT_MASK(gbe_dev->ale_ports), 0, 0,
2367 ALE_MCAST_FWD_2);
2368 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
2369 cpsw_ale_add_mcast(gbe_dev->ale, addr,
2370 GBE_PORT_MASK(gbe_dev->ale_ports),
2371 ALE_VLAN, vlan_id, ALE_MCAST_FWD_2);
2372 }
2373}
2374
2375static void gbe_add_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2376{
2377 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2378 u16 vlan_id;
2379
2380 cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
2381
2382 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID)
2383 cpsw_ale_add_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
2384 ALE_VLAN, vlan_id);
2385}
2386
2387static void gbe_del_mcast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2388{
2389 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2390 u16 vlan_id;
2391
2392 cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, 0, 0);
2393
2394 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
2395 cpsw_ale_del_mcast(gbe_dev->ale, addr, 0, ALE_VLAN, vlan_id);
2396 }
2397}
2398
2399static void gbe_del_ucast_addr(struct gbe_intf *gbe_intf, u8 *addr)
2400{
2401 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2402 u16 vlan_id;
2403
2404 cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port, 0, 0);
2405
2406 for_each_set_bit(vlan_id, gbe_intf->active_vlans, VLAN_N_VID) {
2407 cpsw_ale_del_ucast(gbe_dev->ale, addr, gbe_dev->host_port,
2408 ALE_VLAN, vlan_id);
2409 }
2410}
2411
2412static int gbe_add_addr(void *intf_priv, struct netcp_addr *naddr)
2413{
2414 struct gbe_intf *gbe_intf = intf_priv;
2415 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2416
2417 dev_dbg(gbe_dev->dev, "ethss adding address %pM, type %d\n",
2418 naddr->addr, naddr->type);
2419
2420 switch (naddr->type) {
2421 case ADDR_MCAST:
2422 case ADDR_BCAST:
2423 gbe_add_mcast_addr(gbe_intf, naddr->addr);
2424 break;
2425 case ADDR_UCAST:
2426 case ADDR_DEV:
2427 gbe_add_ucast_addr(gbe_intf, naddr->addr);
2428 break;
2429 case ADDR_ANY:
2430 /* nothing to do for promiscuous */
2431 default:
2432 break;
2433 }
2434
2435 return 0;
2436}
2437
2438static int gbe_del_addr(void *intf_priv, struct netcp_addr *naddr)
2439{
2440 struct gbe_intf *gbe_intf = intf_priv;
2441 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2442
2443 dev_dbg(gbe_dev->dev, "ethss deleting address %pM, type %d\n",
2444 naddr->addr, naddr->type);
2445
2446 switch (naddr->type) {
2447 case ADDR_MCAST:
2448 case ADDR_BCAST:
2449 gbe_del_mcast_addr(gbe_intf, naddr->addr);
2450 break;
2451 case ADDR_UCAST:
2452 case ADDR_DEV:
2453 gbe_del_ucast_addr(gbe_intf, naddr->addr);
2454 break;
2455 case ADDR_ANY:
2456 /* nothing to do for promiscuous */
2457 default:
2458 break;
2459 }
2460
2461 return 0;
2462}
2463
2464static int gbe_add_vid(void *intf_priv, int vid)
2465{
2466 struct gbe_intf *gbe_intf = intf_priv;
2467 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2468
2469 set_bit(vid, gbe_intf->active_vlans);
2470
2471 cpsw_ale_add_vlan(gbe_dev->ale, vid,
2472 GBE_PORT_MASK(gbe_dev->ale_ports),
2473 GBE_MASK_NO_PORTS,
2474 GBE_PORT_MASK(gbe_dev->ale_ports),
2475 GBE_PORT_MASK(gbe_dev->ale_ports - 1));
2476
2477 return 0;
2478}
2479
2480static int gbe_del_vid(void *intf_priv, int vid)
2481{
2482 struct gbe_intf *gbe_intf = intf_priv;
2483 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2484
2485 cpsw_ale_del_vlan(gbe_dev->ale, vid, 0);
2486 clear_bit(vid, gbe_intf->active_vlans);
2487 return 0;
2488}
2489
WingMan Kwok62461682016-12-08 16:21:56 -06002490#if IS_ENABLED(CONFIG_TI_CPTS)
2491#define HAS_PHY_TXTSTAMP(p) ((p)->drv && (p)->drv->txtstamp)
2492#define HAS_PHY_RXTSTAMP(p) ((p)->drv && (p)->drv->rxtstamp)
2493
2494static void gbe_txtstamp(void *context, struct sk_buff *skb)
2495{
2496 struct gbe_intf *gbe_intf = context;
2497 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2498
2499 cpts_tx_timestamp(gbe_dev->cpts, skb);
2500}
2501
2502static bool gbe_need_txtstamp(struct gbe_intf *gbe_intf,
2503 const struct netcp_packet *p_info)
2504{
2505 struct sk_buff *skb = p_info->skb;
2506 unsigned int class = ptp_classify_raw(skb);
2507
2508 if (class == PTP_CLASS_NONE)
2509 return false;
2510
2511 switch (class) {
2512 case PTP_CLASS_V1_IPV4:
2513 case PTP_CLASS_V1_IPV6:
2514 case PTP_CLASS_V2_IPV4:
2515 case PTP_CLASS_V2_IPV6:
2516 case PTP_CLASS_V2_L2:
2517 case (PTP_CLASS_V2_VLAN | PTP_CLASS_L2):
2518 case (PTP_CLASS_V2_VLAN | PTP_CLASS_IPV4):
2519 case (PTP_CLASS_V2_VLAN | PTP_CLASS_IPV6):
2520 return true;
2521 }
2522
2523 return false;
2524}
2525
2526static int gbe_txtstamp_mark_pkt(struct gbe_intf *gbe_intf,
2527 struct netcp_packet *p_info)
2528{
2529 struct phy_device *phydev = p_info->skb->dev->phydev;
2530 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2531
2532 if (!(skb_shinfo(p_info->skb)->tx_flags & SKBTX_HW_TSTAMP) ||
2533 !cpts_is_tx_enabled(gbe_dev->cpts))
2534 return 0;
2535
2536 /* If phy has the txtstamp api, assume it will do it.
2537 * We mark it here because skb_tx_timestamp() is called
2538 * after all the txhooks are called.
2539 */
2540 if (phydev && HAS_PHY_TXTSTAMP(phydev)) {
2541 skb_shinfo(p_info->skb)->tx_flags |= SKBTX_IN_PROGRESS;
2542 return 0;
2543 }
2544
2545 if (gbe_need_txtstamp(gbe_intf, p_info)) {
2546 p_info->txtstamp = gbe_txtstamp;
2547 p_info->ts_context = (void *)gbe_intf;
2548 skb_shinfo(p_info->skb)->tx_flags |= SKBTX_IN_PROGRESS;
2549 }
2550
2551 return 0;
2552}
2553
2554static int gbe_rxtstamp(struct gbe_intf *gbe_intf, struct netcp_packet *p_info)
2555{
2556 struct phy_device *phydev = p_info->skb->dev->phydev;
2557 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2558
2559 if (p_info->rxtstamp_complete)
2560 return 0;
2561
2562 if (phydev && HAS_PHY_RXTSTAMP(phydev)) {
2563 p_info->rxtstamp_complete = true;
2564 return 0;
2565 }
2566
2567 cpts_rx_timestamp(gbe_dev->cpts, p_info->skb);
2568 p_info->rxtstamp_complete = true;
2569
2570 return 0;
2571}
2572
2573static int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *ifr)
2574{
2575 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2576 struct cpts *cpts = gbe_dev->cpts;
2577 struct hwtstamp_config cfg;
2578
2579 if (!cpts)
2580 return -EOPNOTSUPP;
2581
2582 cfg.flags = 0;
2583 cfg.tx_type = cpts_is_tx_enabled(cpts) ?
2584 HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
2585 cfg.rx_filter = (cpts_is_rx_enabled(cpts) ?
2586 cpts->rx_enable : HWTSTAMP_FILTER_NONE);
2587
2588 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
2589}
2590
2591static void gbe_hwtstamp(struct gbe_intf *gbe_intf)
2592{
2593 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2594 struct gbe_slave *slave = gbe_intf->slave;
2595 u32 ts_en, seq_id, ctl;
2596
2597 if (!cpts_is_rx_enabled(gbe_dev->cpts) &&
2598 !cpts_is_tx_enabled(gbe_dev->cpts)) {
2599 writel(0, GBE_REG_ADDR(slave, port_regs, ts_ctl));
2600 return;
2601 }
2602
2603 seq_id = (30 << TS_SEQ_ID_OFS_SHIFT) | ETH_P_1588;
2604 ts_en = EVENT_MSG_BITS << TS_MSG_TYPE_EN_SHIFT;
2605 ctl = ETH_P_1588 | TS_TTL_NONZERO |
2606 (slave->ts_ctl.dst_port_map << TS_CTL_DST_PORT_SHIFT) |
2607 (slave->ts_ctl.uni ? TS_UNI_EN :
2608 slave->ts_ctl.maddr_map << TS_CTL_MADDR_SHIFT);
2609
2610 if (cpts_is_tx_enabled(gbe_dev->cpts))
2611 ts_en |= (TS_TX_ANX_ALL_EN | TS_TX_VLAN_LT1_EN);
2612
2613 if (cpts_is_rx_enabled(gbe_dev->cpts))
2614 ts_en |= (TS_RX_ANX_ALL_EN | TS_RX_VLAN_LT1_EN);
2615
2616 writel(ts_en, GBE_REG_ADDR(slave, port_regs, ts_ctl));
2617 writel(seq_id, GBE_REG_ADDR(slave, port_regs, ts_seq_ltype));
2618 writel(ctl, GBE_REG_ADDR(slave, port_regs, ts_ctl_ltype2));
2619}
2620
2621static int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *ifr)
2622{
2623 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2624 struct cpts *cpts = gbe_dev->cpts;
2625 struct hwtstamp_config cfg;
2626
2627 if (!cpts)
2628 return -EOPNOTSUPP;
2629
2630 if (copy_from_user(&cfg, ifr->ifr_data, sizeof(cfg)))
2631 return -EFAULT;
2632
2633 /* reserved for future extensions */
2634 if (cfg.flags)
2635 return -EINVAL;
2636
2637 switch (cfg.tx_type) {
2638 case HWTSTAMP_TX_OFF:
2639 cpts_tx_enable(cpts, 0);
2640 break;
2641 case HWTSTAMP_TX_ON:
2642 cpts_tx_enable(cpts, 1);
2643 break;
2644 default:
2645 return -ERANGE;
2646 }
2647
2648 switch (cfg.rx_filter) {
2649 case HWTSTAMP_FILTER_NONE:
2650 cpts_rx_enable(cpts, 0);
2651 break;
WingMan Kwok62461682016-12-08 16:21:56 -06002652 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2653 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2654 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2655 cpts_rx_enable(cpts, HWTSTAMP_FILTER_PTP_V1_L4_EVENT);
2656 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V1_L4_EVENT;
2657 break;
2658 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2659 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2660 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2661 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2662 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2663 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2664 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2665 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2666 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
2667 cpts_rx_enable(cpts, HWTSTAMP_FILTER_PTP_V2_EVENT);
2668 cfg.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
2669 break;
2670 default:
2671 return -ERANGE;
2672 }
2673
2674 gbe_hwtstamp(gbe_intf);
2675
2676 return copy_to_user(ifr->ifr_data, &cfg, sizeof(cfg)) ? -EFAULT : 0;
2677}
2678
2679static void gbe_register_cpts(struct gbe_priv *gbe_dev)
2680{
2681 if (!gbe_dev->cpts)
2682 return;
2683
2684 if (gbe_dev->cpts_registered > 0)
2685 goto done;
2686
2687 if (cpts_register(gbe_dev->cpts)) {
2688 dev_err(gbe_dev->dev, "error registering cpts device\n");
2689 return;
2690 }
2691
2692done:
2693 ++gbe_dev->cpts_registered;
2694}
2695
2696static void gbe_unregister_cpts(struct gbe_priv *gbe_dev)
2697{
2698 if (!gbe_dev->cpts || (gbe_dev->cpts_registered <= 0))
2699 return;
2700
2701 if (--gbe_dev->cpts_registered)
2702 return;
2703
2704 cpts_unregister(gbe_dev->cpts);
2705}
2706#else
2707static inline int gbe_txtstamp_mark_pkt(struct gbe_intf *gbe_intf,
2708 struct netcp_packet *p_info)
2709{
2710 return 0;
2711}
2712
2713static inline int gbe_rxtstamp(struct gbe_intf *gbe_intf,
2714 struct netcp_packet *p_info)
2715{
2716 return 0;
2717}
2718
2719static inline int gbe_hwtstamp(struct gbe_intf *gbe_intf,
2720 struct ifreq *ifr, int cmd)
2721{
2722 return -EOPNOTSUPP;
2723}
2724
2725static inline void gbe_register_cpts(struct gbe_priv *gbe_dev)
2726{
2727}
2728
2729static inline void gbe_unregister_cpts(struct gbe_priv *gbe_dev)
2730{
2731}
2732
2733static inline int gbe_hwtstamp_get(struct gbe_intf *gbe_intf, struct ifreq *req)
2734{
2735 return -EOPNOTSUPP;
2736}
2737
2738static inline int gbe_hwtstamp_set(struct gbe_intf *gbe_intf, struct ifreq *req)
2739{
2740 return -EOPNOTSUPP;
2741}
2742#endif /* CONFIG_TI_CPTS */
2743
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002744static int gbe_ioctl(void *intf_priv, struct ifreq *req, int cmd)
2745{
2746 struct gbe_intf *gbe_intf = intf_priv;
2747 struct phy_device *phy = gbe_intf->slave->phy;
WingMan Kwok62461682016-12-08 16:21:56 -06002748
2749 if (!phy || !phy->drv->hwtstamp) {
2750 switch (cmd) {
2751 case SIOCGHWTSTAMP:
2752 return gbe_hwtstamp_get(gbe_intf, req);
2753 case SIOCSHWTSTAMP:
2754 return gbe_hwtstamp_set(gbe_intf, req);
2755 }
2756 }
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002757
2758 if (phy)
WingMan Kwok62461682016-12-08 16:21:56 -06002759 return phy_mii_ioctl(phy, req, cmd);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002760
WingMan Kwok62461682016-12-08 16:21:56 -06002761 return -EOPNOTSUPP;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002762}
2763
2764static void netcp_ethss_timer(unsigned long arg)
2765{
2766 struct gbe_priv *gbe_dev = (struct gbe_priv *)arg;
2767 struct gbe_intf *gbe_intf;
2768 struct gbe_slave *slave;
2769
2770 /* Check & update SGMII link state of interfaces */
2771 for_each_intf(gbe_intf, gbe_dev) {
2772 if (!gbe_intf->slave->open)
2773 continue;
2774 netcp_ethss_update_link_state(gbe_dev, gbe_intf->slave,
2775 gbe_intf->ndev);
2776 }
2777
2778 /* Check & update SGMII link state of secondary ports */
2779 for_each_sec_slave(slave, gbe_dev) {
2780 netcp_ethss_update_link_state(gbe_dev, slave, NULL);
2781 }
2782
WingMan Kwokc0f54ed2015-07-23 15:57:19 -04002783 /* A timer runs as a BH, no need to block them */
2784 spin_lock(&gbe_dev->hw_stats_lock);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002785
2786 if (gbe_dev->ss_version == GBE_SS_VERSION_14)
2787 gbe_update_stats_ver14(gbe_dev, NULL);
2788 else
2789 gbe_update_stats(gbe_dev, NULL);
2790
WingMan Kwokc0f54ed2015-07-23 15:57:19 -04002791 spin_unlock(&gbe_dev->hw_stats_lock);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002792
2793 gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
2794 add_timer(&gbe_dev->timer);
2795}
2796
WingMan Kwok62461682016-12-08 16:21:56 -06002797static int gbe_txhook(int order, void *data, struct netcp_packet *p_info)
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002798{
2799 struct gbe_intf *gbe_intf = data;
2800
2801 p_info->tx_pipe = &gbe_intf->tx_pipe;
WingMan Kwok62461682016-12-08 16:21:56 -06002802
2803 return gbe_txtstamp_mark_pkt(gbe_intf, p_info);
2804}
2805
2806static int gbe_rxhook(int order, void *data, struct netcp_packet *p_info)
2807{
2808 struct gbe_intf *gbe_intf = data;
2809
2810 return gbe_rxtstamp(gbe_intf, p_info);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002811}
2812
2813static int gbe_open(void *intf_priv, struct net_device *ndev)
2814{
2815 struct gbe_intf *gbe_intf = intf_priv;
2816 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2817 struct netcp_intf *netcp = netdev_priv(ndev);
2818 struct gbe_slave *slave = gbe_intf->slave;
2819 int port_num = slave->port_num;
Karicheri, Muralidharan4cd85a62017-01-06 15:37:43 -05002820 u32 reg, val;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002821 int ret;
2822
2823 reg = readl(GBE_REG_ADDR(gbe_dev, switch_regs, id_ver));
2824 dev_dbg(gbe_dev->dev, "initializing gbe version %d.%d (%d) GBE identification value 0x%x\n",
2825 GBE_MAJOR_VERSION(reg), GBE_MINOR_VERSION(reg),
2826 GBE_RTL_VERSION(reg), GBE_IDENT(reg));
2827
WingMan Kwok9a391c72015-03-20 16:11:25 -04002828 /* For 10G and on NetCP 1.5, use directed to port */
2829 if ((gbe_dev->ss_version == XGBE_SS_VERSION_10) || IS_SS_ID_MU(gbe_dev))
Karicheri, Muralidharane170f402015-03-20 16:11:21 -04002830 gbe_intf->tx_pipe.flags = SWITCH_TO_PORT_IN_TAGINFO;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002831
Karicheri, Muralidharane170f402015-03-20 16:11:21 -04002832 if (gbe_dev->enable_ale)
2833 gbe_intf->tx_pipe.switch_to_port = 0;
2834 else
2835 gbe_intf->tx_pipe.switch_to_port = port_num;
2836
2837 dev_dbg(gbe_dev->dev,
2838 "opened TX channel %s: %p with to port %d, flags %d\n",
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002839 gbe_intf->tx_pipe.dma_chan_name,
2840 gbe_intf->tx_pipe.dma_channel,
Karicheri, Muralidharane170f402015-03-20 16:11:21 -04002841 gbe_intf->tx_pipe.switch_to_port,
2842 gbe_intf->tx_pipe.flags);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002843
2844 gbe_slave_stop(gbe_intf);
2845
2846 /* disable priority elevation and enable statistics on all ports */
2847 writel(0, GBE_REG_ADDR(gbe_dev, switch_regs, ptype));
2848
2849 /* Control register */
Karicheri, Muralidharan4cd85a62017-01-06 15:37:43 -05002850 val = GBE_CTL_P0_ENABLE;
2851 if (IS_SS_ID_MU(gbe_dev)) {
2852 val |= ETH_SW_CTL_P0_TX_CRC_REMOVE;
2853 netcp->hw_cap = ETH_SW_CAN_REMOVE_ETH_FCS;
2854 }
2855 writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, control));
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002856
2857 /* All statistics enabled and STAT AB visible by default */
WingMan Kwok9a391c72015-03-20 16:11:25 -04002858 writel(gbe_dev->stats_en_mask, GBE_REG_ADDR(gbe_dev, switch_regs,
2859 stat_port_en));
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002860
2861 ret = gbe_slave_open(gbe_intf);
2862 if (ret)
2863 goto fail;
2864
WingMan Kwok62461682016-12-08 16:21:56 -06002865 netcp_register_txhook(netcp, GBE_TXHOOK_ORDER, gbe_txhook, gbe_intf);
2866 netcp_register_rxhook(netcp, GBE_RXHOOK_ORDER, gbe_rxhook, gbe_intf);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002867
2868 slave->open = true;
2869 netcp_ethss_update_link_state(gbe_dev, slave, ndev);
WingMan Kwok62461682016-12-08 16:21:56 -06002870
2871 gbe_register_cpts(gbe_dev);
2872
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002873 return 0;
2874
2875fail:
2876 gbe_slave_stop(gbe_intf);
2877 return ret;
2878}
2879
2880static int gbe_close(void *intf_priv, struct net_device *ndev)
2881{
2882 struct gbe_intf *gbe_intf = intf_priv;
2883 struct netcp_intf *netcp = netdev_priv(ndev);
WingMan Kwok62461682016-12-08 16:21:56 -06002884 struct gbe_priv *gbe_dev = gbe_intf->gbe_dev;
2885
2886 gbe_unregister_cpts(gbe_dev);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002887
2888 gbe_slave_stop(gbe_intf);
WingMan Kwok62461682016-12-08 16:21:56 -06002889
2890 netcp_unregister_rxhook(netcp, GBE_RXHOOK_ORDER, gbe_rxhook, gbe_intf);
2891 netcp_unregister_txhook(netcp, GBE_TXHOOK_ORDER, gbe_txhook, gbe_intf);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002892
2893 gbe_intf->slave->open = false;
2894 atomic_set(&gbe_intf->slave->link_state, NETCP_LINK_STATE_INVALID);
2895 return 0;
2896}
2897
WingMan Kwok62461682016-12-08 16:21:56 -06002898#if IS_ENABLED(CONFIG_TI_CPTS)
2899static void init_slave_ts_ctl(struct gbe_slave *slave)
2900{
2901 slave->ts_ctl.uni = 1;
2902 slave->ts_ctl.dst_port_map =
2903 (TS_CTL_DST_PORT >> TS_CTL_DST_PORT_SHIFT) & 0x3;
2904 slave->ts_ctl.maddr_map =
2905 (TS_CTL_MADDR_ALL >> TS_CTL_MADDR_SHIFT) & 0x1f;
2906}
2907
2908#else
2909static void init_slave_ts_ctl(struct gbe_slave *slave)
2910{
2911}
2912#endif /* CONFIG_TI_CPTS */
2913
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002914static int init_slave(struct gbe_priv *gbe_dev, struct gbe_slave *slave,
2915 struct device_node *node)
2916{
2917 int port_reg_num;
2918 u32 port_reg_ofs, emac_reg_ofs;
WingMan Kwok9a391c72015-03-20 16:11:25 -04002919 u32 port_reg_blk_sz, emac_reg_blk_sz;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002920
2921 if (of_property_read_u32(node, "slave-port", &slave->slave_num)) {
2922 dev_err(gbe_dev->dev, "missing slave-port parameter\n");
2923 return -EINVAL;
2924 }
2925
2926 if (of_property_read_u32(node, "link-interface",
2927 &slave->link_interface)) {
2928 dev_warn(gbe_dev->dev,
2929 "missing link-interface value defaulting to 1G mac-phy link\n");
2930 slave->link_interface = SGMII_LINK_MAC_PHY;
2931 }
2932
2933 slave->open = false;
Karicheri, Muralidharan0cead3a2017-01-06 15:37:42 -05002934 if ((slave->link_interface == SGMII_LINK_MAC_PHY) ||
2935 (slave->link_interface == XGMII_LINK_MAC_PHY))
2936 slave->phy_node = of_parse_phandle(node, "phy-handle", 0);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002937 slave->port_num = gbe_get_slave_port(gbe_dev, slave->slave_num);
2938
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002939 if (slave->link_interface >= XGMII_LINK_MAC_PHY)
2940 slave->mac_control = GBE_DEF_10G_MAC_CONTROL;
2941 else
2942 slave->mac_control = GBE_DEF_1G_MAC_CONTROL;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002943
2944 /* Emac regs memmap are contiguous but port regs are not */
2945 port_reg_num = slave->slave_num;
2946 if (gbe_dev->ss_version == GBE_SS_VERSION_14) {
2947 if (slave->slave_num > 1) {
2948 port_reg_ofs = GBE13_SLAVE_PORT2_OFFSET;
2949 port_reg_num -= 2;
2950 } else {
2951 port_reg_ofs = GBE13_SLAVE_PORT_OFFSET;
2952 }
WingMan Kwok9a391c72015-03-20 16:11:25 -04002953 emac_reg_ofs = GBE13_EMAC_OFFSET;
2954 port_reg_blk_sz = 0x30;
2955 emac_reg_blk_sz = 0x40;
2956 } else if (IS_SS_ID_MU(gbe_dev)) {
2957 port_reg_ofs = GBENU_SLAVE_PORT_OFFSET;
2958 emac_reg_ofs = GBENU_EMAC_OFFSET;
2959 port_reg_blk_sz = 0x1000;
2960 emac_reg_blk_sz = 0x1000;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05002961 } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) {
2962 port_reg_ofs = XGBE10_SLAVE_PORT_OFFSET;
WingMan Kwok9a391c72015-03-20 16:11:25 -04002963 emac_reg_ofs = XGBE10_EMAC_OFFSET;
2964 port_reg_blk_sz = 0x30;
2965 emac_reg_blk_sz = 0x40;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002966 } else {
2967 dev_err(gbe_dev->dev, "unknown ethss(0x%x)\n",
2968 gbe_dev->ss_version);
2969 return -EINVAL;
2970 }
2971
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04002972 slave->port_regs = gbe_dev->switch_regs + port_reg_ofs +
WingMan Kwok9a391c72015-03-20 16:11:25 -04002973 (port_reg_blk_sz * port_reg_num);
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04002974 slave->emac_regs = gbe_dev->switch_regs + emac_reg_ofs +
WingMan Kwok9a391c72015-03-20 16:11:25 -04002975 (emac_reg_blk_sz * slave->slave_num);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05002976
2977 if (gbe_dev->ss_version == GBE_SS_VERSION_14) {
2978 /* Initialize slave port register offsets */
2979 GBE_SET_REG_OFS(slave, port_regs, port_vlan);
2980 GBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
2981 GBE_SET_REG_OFS(slave, port_regs, sa_lo);
2982 GBE_SET_REG_OFS(slave, port_regs, sa_hi);
2983 GBE_SET_REG_OFS(slave, port_regs, ts_ctl);
2984 GBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
2985 GBE_SET_REG_OFS(slave, port_regs, ts_vlan);
2986 GBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
2987 GBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
2988
2989 /* Initialize EMAC register offsets */
2990 GBE_SET_REG_OFS(slave, emac_regs, mac_control);
2991 GBE_SET_REG_OFS(slave, emac_regs, soft_reset);
2992 GBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
2993
WingMan Kwok9a391c72015-03-20 16:11:25 -04002994 } else if (IS_SS_ID_MU(gbe_dev)) {
2995 /* Initialize slave port register offsets */
2996 GBENU_SET_REG_OFS(slave, port_regs, port_vlan);
2997 GBENU_SET_REG_OFS(slave, port_regs, tx_pri_map);
2998 GBENU_SET_REG_OFS(slave, port_regs, sa_lo);
2999 GBENU_SET_REG_OFS(slave, port_regs, sa_hi);
3000 GBENU_SET_REG_OFS(slave, port_regs, ts_ctl);
3001 GBENU_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
3002 GBENU_SET_REG_OFS(slave, port_regs, ts_vlan);
3003 GBENU_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
3004 GBENU_SET_REG_OFS(slave, port_regs, ts_ctl2);
3005 GBENU_SET_REG_OFS(slave, port_regs, rx_maxlen);
3006
3007 /* Initialize EMAC register offsets */
3008 GBENU_SET_REG_OFS(slave, emac_regs, mac_control);
3009 GBENU_SET_REG_OFS(slave, emac_regs, soft_reset);
3010
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003011 } else if (gbe_dev->ss_version == XGBE_SS_VERSION_10) {
3012 /* Initialize slave port register offsets */
3013 XGBE_SET_REG_OFS(slave, port_regs, port_vlan);
3014 XGBE_SET_REG_OFS(slave, port_regs, tx_pri_map);
3015 XGBE_SET_REG_OFS(slave, port_regs, sa_lo);
3016 XGBE_SET_REG_OFS(slave, port_regs, sa_hi);
3017 XGBE_SET_REG_OFS(slave, port_regs, ts_ctl);
3018 XGBE_SET_REG_OFS(slave, port_regs, ts_seq_ltype);
3019 XGBE_SET_REG_OFS(slave, port_regs, ts_vlan);
3020 XGBE_SET_REG_OFS(slave, port_regs, ts_ctl_ltype2);
3021 XGBE_SET_REG_OFS(slave, port_regs, ts_ctl2);
3022
3023 /* Initialize EMAC register offsets */
3024 XGBE_SET_REG_OFS(slave, emac_regs, mac_control);
3025 XGBE_SET_REG_OFS(slave, emac_regs, soft_reset);
3026 XGBE_SET_REG_OFS(slave, emac_regs, rx_maxlen);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003027 }
3028
3029 atomic_set(&slave->link_state, NETCP_LINK_STATE_INVALID);
WingMan Kwok62461682016-12-08 16:21:56 -06003030
3031 init_slave_ts_ctl(slave);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003032 return 0;
3033}
3034
3035static void init_secondary_ports(struct gbe_priv *gbe_dev,
3036 struct device_node *node)
3037{
3038 struct device *dev = gbe_dev->dev;
3039 phy_interface_t phy_mode;
3040 struct gbe_priv **priv;
3041 struct device_node *port;
3042 struct gbe_slave *slave;
3043 bool mac_phy_link = false;
3044
3045 for_each_child_of_node(node, port) {
3046 slave = devm_kzalloc(dev, sizeof(*slave), GFP_KERNEL);
3047 if (!slave) {
Colin Ian King11a9ec42017-04-22 13:22:01 +01003048 dev_err(dev, "memory alloc failed for secondary port(%s), skipping...\n",
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003049 port->name);
3050 continue;
3051 }
3052
3053 if (init_slave(gbe_dev, slave, port)) {
3054 dev_err(dev,
3055 "Failed to initialize secondary port(%s), skipping...\n",
3056 port->name);
3057 devm_kfree(dev, slave);
3058 continue;
3059 }
3060
3061 gbe_sgmii_config(gbe_dev, slave);
3062 gbe_port_reset(slave);
3063 gbe_port_config(gbe_dev, slave, gbe_dev->rx_packet_max);
3064 list_add_tail(&slave->slave_list, &gbe_dev->secondary_slaves);
3065 gbe_dev->num_slaves++;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003066 if ((slave->link_interface == SGMII_LINK_MAC_PHY) ||
3067 (slave->link_interface == XGMII_LINK_MAC_PHY))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003068 mac_phy_link = true;
3069
3070 slave->open = true;
Julia Lawallbd252792015-10-25 14:57:01 +01003071 if (gbe_dev->num_slaves >= gbe_dev->max_num_slaves) {
3072 of_node_put(port);
WingMan Kwok9a391c72015-03-20 16:11:25 -04003073 break;
Julia Lawallbd252792015-10-25 14:57:01 +01003074 }
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003075 }
3076
3077 /* of_phy_connect() is needed only for MAC-PHY interface */
3078 if (!mac_phy_link)
3079 return;
3080
3081 /* Allocate dummy netdev device for attaching to phy device */
3082 gbe_dev->dummy_ndev = alloc_netdev(sizeof(gbe_dev), "dummy",
3083 NET_NAME_UNKNOWN, ether_setup);
3084 if (!gbe_dev->dummy_ndev) {
3085 dev_err(dev,
3086 "Failed to allocate dummy netdev for secondary ports, skipping phy_connect()...\n");
3087 return;
3088 }
3089 priv = netdev_priv(gbe_dev->dummy_ndev);
3090 *priv = gbe_dev;
3091
3092 if (slave->link_interface == SGMII_LINK_MAC_PHY) {
3093 phy_mode = PHY_INTERFACE_MODE_SGMII;
3094 slave->phy_port_t = PORT_MII;
3095 } else {
3096 phy_mode = PHY_INTERFACE_MODE_NA;
3097 slave->phy_port_t = PORT_FIBRE;
3098 }
3099
3100 for_each_sec_slave(slave, gbe_dev) {
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003101 if ((slave->link_interface != SGMII_LINK_MAC_PHY) &&
3102 (slave->link_interface != XGMII_LINK_MAC_PHY))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003103 continue;
3104 slave->phy =
3105 of_phy_connect(gbe_dev->dummy_ndev,
3106 slave->phy_node,
3107 gbe_adjust_link_sec_slaves,
3108 0, phy_mode);
3109 if (!slave->phy) {
3110 dev_err(dev, "phy not found for slave %d\n",
3111 slave->slave_num);
3112 slave->phy = NULL;
3113 } else {
3114 dev_dbg(dev, "phy found: id is: 0x%s\n",
Andrew Lunn84eff6d2016-01-06 20:11:10 +01003115 phydev_name(slave->phy));
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003116 phy_start(slave->phy);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003117 }
3118 }
3119}
3120
3121static void free_secondary_ports(struct gbe_priv *gbe_dev)
3122{
3123 struct gbe_slave *slave;
3124
Karicheri, Muralidharanc20afae2015-07-28 18:20:13 -04003125 while (!list_empty(&gbe_dev->secondary_slaves)) {
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003126 slave = first_sec_slave(gbe_dev);
Karicheri, Muralidharanc20afae2015-07-28 18:20:13 -04003127
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003128 if (slave->phy)
3129 phy_disconnect(slave->phy);
3130 list_del(&slave->slave_list);
3131 }
3132 if (gbe_dev->dummy_ndev)
3133 free_netdev(gbe_dev->dummy_ndev);
3134}
3135
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003136static int set_xgbe_ethss10_priv(struct gbe_priv *gbe_dev,
3137 struct device_node *node)
3138{
3139 struct resource res;
3140 void __iomem *regs;
3141 int ret, i;
3142
WingMan Kwok9a391c72015-03-20 16:11:25 -04003143 ret = of_address_to_resource(node, XGBE_SS_REG_INDEX, &res);
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003144 if (ret) {
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003145 dev_err(gbe_dev->dev,
3146 "Can't xlate xgbe of node(%s) ss address at %d\n",
3147 node->name, XGBE_SS_REG_INDEX);
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003148 return ret;
3149 }
3150
3151 regs = devm_ioremap_resource(gbe_dev->dev, &res);
3152 if (IS_ERR(regs)) {
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003153 dev_err(gbe_dev->dev, "Failed to map xgbe ss register base\n");
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003154 return PTR_ERR(regs);
3155 }
3156 gbe_dev->ss_regs = regs;
3157
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003158 ret = of_address_to_resource(node, XGBE_SM_REG_INDEX, &res);
3159 if (ret) {
3160 dev_err(gbe_dev->dev,
3161 "Can't xlate xgbe of node(%s) sm address at %d\n",
3162 node->name, XGBE_SM_REG_INDEX);
3163 return ret;
3164 }
3165
3166 regs = devm_ioremap_resource(gbe_dev->dev, &res);
3167 if (IS_ERR(regs)) {
3168 dev_err(gbe_dev->dev, "Failed to map xgbe sm register base\n");
3169 return PTR_ERR(regs);
3170 }
3171 gbe_dev->switch_regs = regs;
3172
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003173 ret = of_address_to_resource(node, XGBE_SERDES_REG_INDEX, &res);
3174 if (ret) {
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003175 dev_err(gbe_dev->dev,
3176 "Can't xlate xgbe serdes of node(%s) address at %d\n",
3177 node->name, XGBE_SERDES_REG_INDEX);
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003178 return ret;
3179 }
3180
3181 regs = devm_ioremap_resource(gbe_dev->dev, &res);
3182 if (IS_ERR(regs)) {
3183 dev_err(gbe_dev->dev, "Failed to map xgbe serdes register base\n");
3184 return PTR_ERR(regs);
3185 }
3186 gbe_dev->xgbe_serdes_regs = regs;
3187
WingMan Kwok489e8a22015-07-23 15:57:23 -04003188 gbe_dev->num_stats_mods = gbe_dev->max_num_ports;
WingMan Kwok208c6b92015-07-23 15:57:21 -04003189 gbe_dev->et_stats = xgbe10_et_stats;
3190 gbe_dev->num_et_stats = ARRAY_SIZE(xgbe10_et_stats);
3191
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003192 gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
WingMan Kwok208c6b92015-07-23 15:57:21 -04003193 gbe_dev->num_et_stats * sizeof(u64),
3194 GFP_KERNEL);
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003195 if (!gbe_dev->hw_stats) {
3196 dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
3197 return -ENOMEM;
3198 }
3199
WingMan Kwok489e8a22015-07-23 15:57:23 -04003200 gbe_dev->hw_stats_prev =
3201 devm_kzalloc(gbe_dev->dev,
3202 gbe_dev->num_et_stats * sizeof(u32),
3203 GFP_KERNEL);
3204 if (!gbe_dev->hw_stats_prev) {
3205 dev_err(gbe_dev->dev,
3206 "hw_stats_prev memory allocation failed\n");
3207 return -ENOMEM;
3208 }
3209
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003210 gbe_dev->ss_version = XGBE_SS_VERSION_10;
3211 gbe_dev->sgmii_port_regs = gbe_dev->ss_regs +
3212 XGBE10_SGMII_MODULE_OFFSET;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003213 gbe_dev->host_port_regs = gbe_dev->ss_regs + XGBE10_HOST_PORT_OFFSET;
3214
WingMan Kwok9a391c72015-03-20 16:11:25 -04003215 for (i = 0; i < gbe_dev->max_num_ports; i++)
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003216 gbe_dev->hw_stats_regs[i] = gbe_dev->switch_regs +
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003217 XGBE10_HW_STATS_OFFSET + (GBE_HW_STATS_REG_MAP_SZ * i);
3218
WingMan Kwok9a391c72015-03-20 16:11:25 -04003219 gbe_dev->ale_reg = gbe_dev->switch_regs + XGBE10_ALE_OFFSET;
WingMan Kwok62461682016-12-08 16:21:56 -06003220 gbe_dev->cpts_reg = gbe_dev->switch_regs + XGBE10_CPTS_OFFSET;
WingMan Kwok9a391c72015-03-20 16:11:25 -04003221 gbe_dev->ale_ports = gbe_dev->max_num_ports;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003222 gbe_dev->host_port = XGBE10_HOST_PORT_NUM;
3223 gbe_dev->ale_entries = XGBE10_NUM_ALE_ENTRIES;
WingMan Kwok9a391c72015-03-20 16:11:25 -04003224 gbe_dev->stats_en_mask = (1 << (gbe_dev->max_num_ports)) - 1;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003225
3226 /* Subsystem registers */
3227 XGBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
3228 XGBE_SET_REG_OFS(gbe_dev, ss_regs, control);
3229
3230 /* Switch module registers */
3231 XGBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
3232 XGBE_SET_REG_OFS(gbe_dev, switch_regs, control);
3233 XGBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
3234 XGBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
3235 XGBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
3236
3237 /* Host port registers */
3238 XGBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
3239 XGBE_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map);
3240 XGBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
3241 return 0;
3242}
3243
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003244static int get_gbe_resource_version(struct gbe_priv *gbe_dev,
3245 struct device_node *node)
3246{
3247 struct resource res;
3248 void __iomem *regs;
3249 int ret;
3250
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003251 ret = of_address_to_resource(node, GBE_SS_REG_INDEX, &res);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003252 if (ret) {
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003253 dev_err(gbe_dev->dev,
3254 "Can't translate of node(%s) of gbe ss address at %d\n",
3255 node->name, GBE_SS_REG_INDEX);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003256 return ret;
3257 }
3258
3259 regs = devm_ioremap_resource(gbe_dev->dev, &res);
3260 if (IS_ERR(regs)) {
3261 dev_err(gbe_dev->dev, "Failed to map gbe register base\n");
3262 return PTR_ERR(regs);
3263 }
3264 gbe_dev->ss_regs = regs;
3265 gbe_dev->ss_version = readl(gbe_dev->ss_regs);
3266 return 0;
3267}
3268
3269static int set_gbe_ethss14_priv(struct gbe_priv *gbe_dev,
3270 struct device_node *node)
3271{
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003272 struct resource res;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003273 void __iomem *regs;
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003274 int i, ret;
3275
3276 ret = of_address_to_resource(node, GBE_SGMII34_REG_INDEX, &res);
3277 if (ret) {
3278 dev_err(gbe_dev->dev,
3279 "Can't translate of gbe node(%s) address at index %d\n",
3280 node->name, GBE_SGMII34_REG_INDEX);
3281 return ret;
3282 }
3283
3284 regs = devm_ioremap_resource(gbe_dev->dev, &res);
3285 if (IS_ERR(regs)) {
3286 dev_err(gbe_dev->dev,
3287 "Failed to map gbe sgmii port34 register base\n");
3288 return PTR_ERR(regs);
3289 }
3290 gbe_dev->sgmii_port34_regs = regs;
3291
3292 ret = of_address_to_resource(node, GBE_SM_REG_INDEX, &res);
3293 if (ret) {
3294 dev_err(gbe_dev->dev,
3295 "Can't translate of gbe node(%s) address at index %d\n",
3296 node->name, GBE_SM_REG_INDEX);
3297 return ret;
3298 }
3299
3300 regs = devm_ioremap_resource(gbe_dev->dev, &res);
3301 if (IS_ERR(regs)) {
3302 dev_err(gbe_dev->dev,
3303 "Failed to map gbe switch module register base\n");
3304 return PTR_ERR(regs);
3305 }
3306 gbe_dev->switch_regs = regs;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003307
WingMan Kwok489e8a22015-07-23 15:57:23 -04003308 gbe_dev->num_stats_mods = gbe_dev->max_num_slaves;
WingMan Kwok208c6b92015-07-23 15:57:21 -04003309 gbe_dev->et_stats = gbe13_et_stats;
3310 gbe_dev->num_et_stats = ARRAY_SIZE(gbe13_et_stats);
3311
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003312 gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
WingMan Kwok208c6b92015-07-23 15:57:21 -04003313 gbe_dev->num_et_stats * sizeof(u64),
3314 GFP_KERNEL);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003315 if (!gbe_dev->hw_stats) {
3316 dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
3317 return -ENOMEM;
3318 }
3319
WingMan Kwok489e8a22015-07-23 15:57:23 -04003320 gbe_dev->hw_stats_prev =
3321 devm_kzalloc(gbe_dev->dev,
3322 gbe_dev->num_et_stats * sizeof(u32),
3323 GFP_KERNEL);
3324 if (!gbe_dev->hw_stats_prev) {
3325 dev_err(gbe_dev->dev,
3326 "hw_stats_prev memory allocation failed\n");
3327 return -ENOMEM;
3328 }
3329
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003330 gbe_dev->sgmii_port_regs = gbe_dev->ss_regs + GBE13_SGMII_MODULE_OFFSET;
3331 gbe_dev->host_port_regs = gbe_dev->switch_regs + GBE13_HOST_PORT_OFFSET;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003332
WingMan Kwoka94bcd092015-07-23 15:57:20 -04003333 /* K2HK has only 2 hw stats modules visible at a time, so
3334 * module 0 & 2 points to one base and
3335 * module 1 & 3 points to the other base
3336 */
WingMan Kwok9a391c72015-03-20 16:11:25 -04003337 for (i = 0; i < gbe_dev->max_num_slaves; i++) {
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003338 gbe_dev->hw_stats_regs[i] =
3339 gbe_dev->switch_regs + GBE13_HW_STATS_OFFSET +
WingMan Kwoka94bcd092015-07-23 15:57:20 -04003340 (GBE_HW_STATS_REG_MAP_SZ * (i & 0x1));
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003341 }
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003342
WingMan Kwok62461682016-12-08 16:21:56 -06003343 gbe_dev->cpts_reg = gbe_dev->switch_regs + GBE13_CPTS_OFFSET;
Karicheri, Muralidharan21e0e0d2015-03-20 16:11:22 -04003344 gbe_dev->ale_reg = gbe_dev->switch_regs + GBE13_ALE_OFFSET;
WingMan Kwok9a391c72015-03-20 16:11:25 -04003345 gbe_dev->ale_ports = gbe_dev->max_num_ports;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003346 gbe_dev->host_port = GBE13_HOST_PORT_NUM;
3347 gbe_dev->ale_entries = GBE13_NUM_ALE_ENTRIES;
WingMan Kwok9a391c72015-03-20 16:11:25 -04003348 gbe_dev->stats_en_mask = GBE13_REG_VAL_STAT_ENABLE_ALL;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003349
3350 /* Subsystem registers */
3351 GBE_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
3352
3353 /* Switch module registers */
3354 GBE_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
3355 GBE_SET_REG_OFS(gbe_dev, switch_regs, control);
3356 GBE_SET_REG_OFS(gbe_dev, switch_regs, soft_reset);
3357 GBE_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
3358 GBE_SET_REG_OFS(gbe_dev, switch_regs, ptype);
3359 GBE_SET_REG_OFS(gbe_dev, switch_regs, flow_control);
3360
3361 /* Host port registers */
3362 GBE_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
3363 GBE_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
3364 return 0;
3365}
3366
WingMan Kwok9a391c72015-03-20 16:11:25 -04003367static int set_gbenu_ethss_priv(struct gbe_priv *gbe_dev,
3368 struct device_node *node)
3369{
3370 struct resource res;
3371 void __iomem *regs;
3372 int i, ret;
3373
WingMan Kwok489e8a22015-07-23 15:57:23 -04003374 gbe_dev->num_stats_mods = gbe_dev->max_num_ports;
WingMan Kwok208c6b92015-07-23 15:57:21 -04003375 gbe_dev->et_stats = gbenu_et_stats;
3376
3377 if (IS_SS_ID_NU(gbe_dev))
3378 gbe_dev->num_et_stats = GBENU_ET_STATS_HOST_SIZE +
3379 (gbe_dev->max_num_slaves * GBENU_ET_STATS_PORT_SIZE);
3380 else
3381 gbe_dev->num_et_stats = GBENU_ET_STATS_HOST_SIZE +
3382 GBENU_ET_STATS_PORT_SIZE;
3383
WingMan Kwok9a391c72015-03-20 16:11:25 -04003384 gbe_dev->hw_stats = devm_kzalloc(gbe_dev->dev,
WingMan Kwok208c6b92015-07-23 15:57:21 -04003385 gbe_dev->num_et_stats * sizeof(u64),
3386 GFP_KERNEL);
WingMan Kwok9a391c72015-03-20 16:11:25 -04003387 if (!gbe_dev->hw_stats) {
3388 dev_err(gbe_dev->dev, "hw_stats memory allocation failed\n");
3389 return -ENOMEM;
3390 }
3391
WingMan Kwok489e8a22015-07-23 15:57:23 -04003392 gbe_dev->hw_stats_prev =
3393 devm_kzalloc(gbe_dev->dev,
3394 gbe_dev->num_et_stats * sizeof(u32),
3395 GFP_KERNEL);
3396 if (!gbe_dev->hw_stats_prev) {
3397 dev_err(gbe_dev->dev,
3398 "hw_stats_prev memory allocation failed\n");
3399 return -ENOMEM;
3400 }
3401
WingMan Kwok9a391c72015-03-20 16:11:25 -04003402 ret = of_address_to_resource(node, GBENU_SM_REG_INDEX, &res);
3403 if (ret) {
3404 dev_err(gbe_dev->dev,
3405 "Can't translate of gbenu node(%s) addr at index %d\n",
3406 node->name, GBENU_SM_REG_INDEX);
3407 return ret;
3408 }
3409
3410 regs = devm_ioremap_resource(gbe_dev->dev, &res);
3411 if (IS_ERR(regs)) {
3412 dev_err(gbe_dev->dev,
3413 "Failed to map gbenu switch module register base\n");
3414 return PTR_ERR(regs);
3415 }
3416 gbe_dev->switch_regs = regs;
3417
3418 gbe_dev->sgmii_port_regs = gbe_dev->ss_regs + GBENU_SGMII_MODULE_OFFSET;
WingMan Kwok8c851512015-09-23 13:37:05 -04003419
3420 /* Although sgmii modules are mem mapped to one contiguous
3421 * region on GBENU devices, setting sgmii_port34_regs allows
3422 * consistent code when accessing sgmii api
3423 */
3424 gbe_dev->sgmii_port34_regs = gbe_dev->sgmii_port_regs +
3425 (2 * GBENU_SGMII_MODULE_SIZE);
3426
WingMan Kwok9a391c72015-03-20 16:11:25 -04003427 gbe_dev->host_port_regs = gbe_dev->switch_regs + GBENU_HOST_PORT_OFFSET;
3428
3429 for (i = 0; i < (gbe_dev->max_num_ports); i++)
3430 gbe_dev->hw_stats_regs[i] = gbe_dev->switch_regs +
3431 GBENU_HW_STATS_OFFSET + (GBENU_HW_STATS_REG_MAP_SZ * i);
3432
WingMan Kwok62461682016-12-08 16:21:56 -06003433 gbe_dev->cpts_reg = gbe_dev->switch_regs + GBENU_CPTS_OFFSET;
WingMan Kwok9a391c72015-03-20 16:11:25 -04003434 gbe_dev->ale_reg = gbe_dev->switch_regs + GBENU_ALE_OFFSET;
3435 gbe_dev->ale_ports = gbe_dev->max_num_ports;
3436 gbe_dev->host_port = GBENU_HOST_PORT_NUM;
WingMan Kwok9a391c72015-03-20 16:11:25 -04003437 gbe_dev->stats_en_mask = (1 << (gbe_dev->max_num_ports)) - 1;
3438
WingMan Kwok9a391c72015-03-20 16:11:25 -04003439 /* Subsystem registers */
3440 GBENU_SET_REG_OFS(gbe_dev, ss_regs, id_ver);
3441
3442 /* Switch module registers */
3443 GBENU_SET_REG_OFS(gbe_dev, switch_regs, id_ver);
3444 GBENU_SET_REG_OFS(gbe_dev, switch_regs, control);
3445 GBENU_SET_REG_OFS(gbe_dev, switch_regs, stat_port_en);
3446 GBENU_SET_REG_OFS(gbe_dev, switch_regs, ptype);
3447
3448 /* Host port registers */
3449 GBENU_SET_REG_OFS(gbe_dev, host_port_regs, port_vlan);
3450 GBENU_SET_REG_OFS(gbe_dev, host_port_regs, rx_maxlen);
3451
3452 /* For NU only. 2U does not need tx_pri_map.
3453 * NU cppi port 0 tx pkt streaming interface has (n-1)*8 egress threads
3454 * while 2U has only 1 such thread
3455 */
3456 GBENU_SET_REG_OFS(gbe_dev, host_port_regs, tx_pri_map);
3457 return 0;
3458}
3459
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003460static int gbe_probe(struct netcp_device *netcp_device, struct device *dev,
3461 struct device_node *node, void **inst_priv)
3462{
3463 struct device_node *interfaces, *interface;
3464 struct device_node *secondary_ports;
3465 struct cpsw_ale_params ale_params;
3466 struct gbe_priv *gbe_dev;
3467 u32 slave_num;
WingMan Kwok489e8a22015-07-23 15:57:23 -04003468 int i, ret = 0;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003469
3470 if (!node) {
3471 dev_err(dev, "device tree info unavailable\n");
3472 return -ENODEV;
3473 }
3474
3475 gbe_dev = devm_kzalloc(dev, sizeof(struct gbe_priv), GFP_KERNEL);
3476 if (!gbe_dev)
3477 return -ENOMEM;
3478
WingMan Kwok9a391c72015-03-20 16:11:25 -04003479 if (of_device_is_compatible(node, "ti,netcp-gbe-5") ||
3480 of_device_is_compatible(node, "ti,netcp-gbe")) {
3481 gbe_dev->max_num_slaves = 4;
3482 } else if (of_device_is_compatible(node, "ti,netcp-gbe-9")) {
3483 gbe_dev->max_num_slaves = 8;
3484 } else if (of_device_is_compatible(node, "ti,netcp-gbe-2")) {
3485 gbe_dev->max_num_slaves = 1;
3486 } else if (of_device_is_compatible(node, "ti,netcp-xgbe")) {
3487 gbe_dev->max_num_slaves = 2;
3488 } else {
3489 dev_err(dev, "device tree node for unknown device\n");
3490 return -EINVAL;
3491 }
3492 gbe_dev->max_num_ports = gbe_dev->max_num_slaves + 1;
3493
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003494 gbe_dev->dev = dev;
3495 gbe_dev->netcp_device = netcp_device;
3496 gbe_dev->rx_packet_max = NETCP_MAX_FRAME_SIZE;
3497
3498 /* init the hw stats lock */
3499 spin_lock_init(&gbe_dev->hw_stats_lock);
3500
3501 if (of_find_property(node, "enable-ale", NULL)) {
3502 gbe_dev->enable_ale = true;
3503 dev_info(dev, "ALE enabled\n");
3504 } else {
3505 gbe_dev->enable_ale = false;
3506 dev_dbg(dev, "ALE bypass enabled*\n");
3507 }
3508
3509 ret = of_property_read_u32(node, "tx-queue",
3510 &gbe_dev->tx_queue_id);
3511 if (ret < 0) {
3512 dev_err(dev, "missing tx_queue parameter\n");
3513 gbe_dev->tx_queue_id = GBE_TX_QUEUE;
3514 }
3515
3516 ret = of_property_read_string(node, "tx-channel",
3517 &gbe_dev->dma_chan_name);
3518 if (ret < 0) {
3519 dev_err(dev, "missing \"tx-channel\" parameter\n");
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003520 return -EINVAL;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003521 }
3522
3523 if (!strcmp(node->name, "gbe")) {
3524 ret = get_gbe_resource_version(gbe_dev, node);
3525 if (ret)
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003526 return ret;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003527
WingMan Kwok9a391c72015-03-20 16:11:25 -04003528 dev_dbg(dev, "ss_version: 0x%08x\n", gbe_dev->ss_version);
3529
3530 if (gbe_dev->ss_version == GBE_SS_VERSION_14)
3531 ret = set_gbe_ethss14_priv(gbe_dev, node);
3532 else if (IS_SS_ID_MU(gbe_dev))
3533 ret = set_gbenu_ethss_priv(gbe_dev, node);
3534 else
3535 ret = -ENODEV;
3536
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003537 } else if (!strcmp(node->name, "xgbe")) {
3538 ret = set_xgbe_ethss10_priv(gbe_dev, node);
3539 if (ret)
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003540 return ret;
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003541 ret = netcp_xgbe_serdes_init(gbe_dev->xgbe_serdes_regs,
3542 gbe_dev->ss_regs);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003543 } else {
3544 dev_err(dev, "unknown GBE node(%s)\n", node->name);
3545 ret = -ENODEV;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003546 }
3547
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003548 if (ret)
3549 return ret;
3550
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003551 interfaces = of_get_child_by_name(node, "interfaces");
3552 if (!interfaces)
3553 dev_err(dev, "could not find interfaces\n");
3554
3555 ret = netcp_txpipe_init(&gbe_dev->tx_pipe, netcp_device,
3556 gbe_dev->dma_chan_name, gbe_dev->tx_queue_id);
3557 if (ret)
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003558 return ret;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003559
3560 ret = netcp_txpipe_open(&gbe_dev->tx_pipe);
3561 if (ret)
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003562 return ret;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003563
3564 /* Create network interfaces */
3565 INIT_LIST_HEAD(&gbe_dev->gbe_intf_head);
3566 for_each_child_of_node(interfaces, interface) {
3567 ret = of_property_read_u32(interface, "slave-port", &slave_num);
3568 if (ret) {
3569 dev_err(dev, "missing slave-port parameter, skipping interface configuration for %s\n",
3570 interface->name);
3571 continue;
3572 }
3573 gbe_dev->num_slaves++;
Julia Lawallbd252792015-10-25 14:57:01 +01003574 if (gbe_dev->num_slaves >= gbe_dev->max_num_slaves) {
3575 of_node_put(interface);
WingMan Kwok9a391c72015-03-20 16:11:25 -04003576 break;
Julia Lawallbd252792015-10-25 14:57:01 +01003577 }
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003578 }
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003579 of_node_put(interfaces);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003580
3581 if (!gbe_dev->num_slaves)
3582 dev_warn(dev, "No network interface configured\n");
3583
3584 /* Initialize Secondary slave ports */
3585 secondary_ports = of_get_child_by_name(node, "secondary-slave-ports");
3586 INIT_LIST_HEAD(&gbe_dev->secondary_slaves);
WingMan Kwok9a391c72015-03-20 16:11:25 -04003587 if (secondary_ports && (gbe_dev->num_slaves < gbe_dev->max_num_slaves))
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003588 init_secondary_ports(gbe_dev, secondary_ports);
3589 of_node_put(secondary_ports);
3590
3591 if (!gbe_dev->num_slaves) {
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003592 dev_err(dev,
3593 "No network interface or secondary ports configured\n");
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003594 ret = -ENODEV;
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003595 goto free_sec_ports;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003596 }
3597
3598 memset(&ale_params, 0, sizeof(ale_params));
3599 ale_params.dev = gbe_dev->dev;
3600 ale_params.ale_regs = gbe_dev->ale_reg;
3601 ale_params.ale_ageout = GBE_DEFAULT_ALE_AGEOUT;
3602 ale_params.ale_entries = gbe_dev->ale_entries;
3603 ale_params.ale_ports = gbe_dev->ale_ports;
Karicheri, Muralidharanca471302017-01-06 15:37:44 -05003604 if (IS_SS_ID_MU(gbe_dev)) {
3605 ale_params.major_ver_mask = 0x7;
3606 ale_params.nu_switch_ale = true;
3607 }
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003608 gbe_dev->ale = cpsw_ale_create(&ale_params);
3609 if (!gbe_dev->ale) {
3610 dev_err(gbe_dev->dev, "error initializing ale engine\n");
3611 ret = -ENODEV;
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003612 goto free_sec_ports;
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003613 } else {
3614 dev_dbg(gbe_dev->dev, "Created a gbe ale engine\n");
3615 }
3616
WingMan Kwok62461682016-12-08 16:21:56 -06003617 gbe_dev->cpts = cpts_create(gbe_dev->dev, gbe_dev->cpts_reg, node);
3618 if (IS_ENABLED(CONFIG_TI_CPTS) && IS_ERR(gbe_dev->cpts)) {
3619 ret = PTR_ERR(gbe_dev->cpts);
3620 goto free_sec_ports;
3621 }
3622
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003623 /* initialize host port */
3624 gbe_init_host_port(gbe_dev);
3625
WingMan Kwok489e8a22015-07-23 15:57:23 -04003626 spin_lock_bh(&gbe_dev->hw_stats_lock);
3627 for (i = 0; i < gbe_dev->num_stats_mods; i++) {
3628 if (gbe_dev->ss_version == GBE_SS_VERSION_14)
3629 gbe_reset_mod_stats_ver14(gbe_dev, i);
3630 else
3631 gbe_reset_mod_stats(gbe_dev, i);
3632 }
3633 spin_unlock_bh(&gbe_dev->hw_stats_lock);
3634
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003635 init_timer(&gbe_dev->timer);
3636 gbe_dev->timer.data = (unsigned long)gbe_dev;
3637 gbe_dev->timer.function = netcp_ethss_timer;
3638 gbe_dev->timer.expires = jiffies + GBE_TIMER_INTERVAL;
3639 add_timer(&gbe_dev->timer);
3640 *inst_priv = gbe_dev;
3641 return 0;
3642
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003643free_sec_ports:
3644 free_secondary_ports(gbe_dev);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003645 return ret;
3646}
3647
3648static int gbe_attach(void *inst_priv, struct net_device *ndev,
3649 struct device_node *node, void **intf_priv)
3650{
3651 struct gbe_priv *gbe_dev = inst_priv;
3652 struct gbe_intf *gbe_intf;
3653 int ret;
3654
3655 if (!node) {
3656 dev_err(gbe_dev->dev, "interface node not available\n");
3657 return -ENODEV;
3658 }
3659
3660 gbe_intf = devm_kzalloc(gbe_dev->dev, sizeof(*gbe_intf), GFP_KERNEL);
3661 if (!gbe_intf)
3662 return -ENOMEM;
3663
3664 gbe_intf->ndev = ndev;
3665 gbe_intf->dev = gbe_dev->dev;
3666 gbe_intf->gbe_dev = gbe_dev;
3667
3668 gbe_intf->slave = devm_kzalloc(gbe_dev->dev,
3669 sizeof(*gbe_intf->slave),
3670 GFP_KERNEL);
3671 if (!gbe_intf->slave) {
3672 ret = -ENOMEM;
3673 goto fail;
3674 }
3675
3676 if (init_slave(gbe_dev, gbe_intf->slave, node)) {
3677 ret = -ENODEV;
3678 goto fail;
3679 }
3680
3681 gbe_intf->tx_pipe = gbe_dev->tx_pipe;
3682 ndev->ethtool_ops = &keystone_ethtool_ops;
3683 list_add_tail(&gbe_intf->gbe_intf_list, &gbe_dev->gbe_intf_head);
3684 *intf_priv = gbe_intf;
3685 return 0;
3686
3687fail:
3688 if (gbe_intf->slave)
3689 devm_kfree(gbe_dev->dev, gbe_intf->slave);
3690 if (gbe_intf)
3691 devm_kfree(gbe_dev->dev, gbe_intf);
3692 return ret;
3693}
3694
3695static int gbe_release(void *intf_priv)
3696{
3697 struct gbe_intf *gbe_intf = intf_priv;
3698
3699 gbe_intf->ndev->ethtool_ops = NULL;
3700 list_del(&gbe_intf->gbe_intf_list);
3701 devm_kfree(gbe_intf->dev, gbe_intf->slave);
3702 devm_kfree(gbe_intf->dev, gbe_intf);
3703 return 0;
3704}
3705
3706static int gbe_remove(struct netcp_device *netcp_device, void *inst_priv)
3707{
3708 struct gbe_priv *gbe_dev = inst_priv;
3709
3710 del_timer_sync(&gbe_dev->timer);
WingMan Kwok62461682016-12-08 16:21:56 -06003711 cpts_release(gbe_dev->cpts);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003712 cpsw_ale_stop(gbe_dev->ale);
3713 cpsw_ale_destroy(gbe_dev->ale);
3714 netcp_txpipe_close(&gbe_dev->tx_pipe);
3715 free_secondary_ports(gbe_dev);
3716
3717 if (!list_empty(&gbe_dev->gbe_intf_head))
Karicheri, Muralidharan31a184b2015-07-28 18:20:14 -04003718 dev_alert(gbe_dev->dev,
3719 "unreleased ethss interfaces present\n");
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003720
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003721 return 0;
3722}
3723
3724static struct netcp_module gbe_module = {
3725 .name = GBE_MODULE_NAME,
3726 .owner = THIS_MODULE,
3727 .primary = true,
3728 .probe = gbe_probe,
3729 .open = gbe_open,
3730 .close = gbe_close,
3731 .remove = gbe_remove,
3732 .attach = gbe_attach,
3733 .release = gbe_release,
3734 .add_addr = gbe_add_addr,
3735 .del_addr = gbe_del_addr,
3736 .add_vid = gbe_add_vid,
3737 .del_vid = gbe_del_vid,
3738 .ioctl = gbe_ioctl,
3739};
3740
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003741static struct netcp_module xgbe_module = {
3742 .name = XGBE_MODULE_NAME,
3743 .owner = THIS_MODULE,
3744 .primary = true,
3745 .probe = gbe_probe,
3746 .open = gbe_open,
3747 .close = gbe_close,
3748 .remove = gbe_remove,
3749 .attach = gbe_attach,
3750 .release = gbe_release,
3751 .add_addr = gbe_add_addr,
3752 .del_addr = gbe_del_addr,
3753 .add_vid = gbe_add_vid,
3754 .del_vid = gbe_del_vid,
3755 .ioctl = gbe_ioctl,
3756};
3757
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003758static int __init keystone_gbe_init(void)
3759{
3760 int ret;
3761
3762 ret = netcp_register_module(&gbe_module);
3763 if (ret)
3764 return ret;
3765
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003766 ret = netcp_register_module(&xgbe_module);
3767 if (ret)
3768 return ret;
3769
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003770 return 0;
3771}
3772module_init(keystone_gbe_init);
3773
3774static void __exit keystone_gbe_exit(void)
3775{
3776 netcp_unregister_module(&gbe_module);
Wingman Kwok90cff9e2015-01-15 19:12:52 -05003777 netcp_unregister_module(&xgbe_module);
Wingman Kwok6f8d3f32015-01-15 19:12:51 -05003778}
3779module_exit(keystone_gbe_exit);
Karicheri, Muralidharan58c11b52015-01-29 18:15:51 -05003780
3781MODULE_LICENSE("GPL v2");
3782MODULE_DESCRIPTION("TI NETCP ETHSS driver for Keystone SOCs");
3783MODULE_AUTHOR("Sandeep Nair <sandeep_n@ti.com");