blob: 623d113b6581dadf91352532940a62262c73e1ed [file] [log] [blame]
Ioana Ciornei71947922019-10-31 01:18:31 +02001// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2/* Copyright 2019 NXP */
3
Calvin Johnson3264f592021-06-11 13:54:01 +03004#include <linux/acpi.h>
Colin Fostere7026f12021-12-28 21:03:06 -08005#include <linux/pcs-lynx.h>
Calvin Johnson3264f592021-06-11 13:54:01 +03006#include <linux/property.h>
7
Ioana Ciornei71947922019-10-31 01:18:31 +02008#include "dpaa2-eth.h"
9#include "dpaa2-mac.h"
10
11#define phylink_to_dpaa2_mac(config) \
12 container_of((config), struct dpaa2_mac, phylink_config)
13
Ioana Ciornei226df3e2019-11-06 19:06:50 +020014static int phy_mode(enum dpmac_eth_if eth_if, phy_interface_t *if_mode)
Ioana Ciornei71947922019-10-31 01:18:31 +020015{
Ioana Ciornei226df3e2019-11-06 19:06:50 +020016 *if_mode = PHY_INTERFACE_MODE_NA;
17
Ioana Ciornei71947922019-10-31 01:18:31 +020018 switch (eth_if) {
19 case DPMAC_ETH_IF_RGMII:
Ioana Ciornei226df3e2019-11-06 19:06:50 +020020 *if_mode = PHY_INTERFACE_MODE_RGMII;
21 break;
Ioana Ciornei94ae8992020-09-23 18:41:23 +030022 case DPMAC_ETH_IF_USXGMII:
23 *if_mode = PHY_INTERFACE_MODE_USXGMII;
24 break;
25 case DPMAC_ETH_IF_QSGMII:
26 *if_mode = PHY_INTERFACE_MODE_QSGMII;
27 break;
28 case DPMAC_ETH_IF_SGMII:
29 *if_mode = PHY_INTERFACE_MODE_SGMII;
30 break;
31 case DPMAC_ETH_IF_XFI:
32 *if_mode = PHY_INTERFACE_MODE_10GBASER;
33 break;
Ioana Ciornei71947922019-10-31 01:18:31 +020034 default:
35 return -EINVAL;
36 }
Ioana Ciornei226df3e2019-11-06 19:06:50 +020037
38 return 0;
Ioana Ciornei71947922019-10-31 01:18:31 +020039}
40
Calvin Johnson3264f592021-06-11 13:54:01 +030041static struct fwnode_handle *dpaa2_mac_get_node(struct device *dev,
42 u16 dpmac_id)
Ioana Ciornei71947922019-10-31 01:18:31 +020043{
Robert-Ionut Alexa5b1e38c2022-01-06 15:59:03 +020044 struct fwnode_handle *fwnode, *parent = NULL, *child = NULL;
Calvin Johnson3264f592021-06-11 13:54:01 +030045 struct device_node *dpmacs = NULL;
Ioana Ciornei71947922019-10-31 01:18:31 +020046 int err;
Calvin Johnson3264f592021-06-11 13:54:01 +030047 u32 id;
Ioana Ciornei71947922019-10-31 01:18:31 +020048
Calvin Johnson3264f592021-06-11 13:54:01 +030049 fwnode = dev_fwnode(dev->parent);
50 if (is_of_node(fwnode)) {
51 dpmacs = of_find_node_by_name(NULL, "dpmacs");
52 if (!dpmacs)
53 return NULL;
54 parent = of_fwnode_handle(dpmacs);
55 } else if (is_acpi_node(fwnode)) {
56 parent = fwnode;
Ioana Ciornei4e30e982022-01-06 15:59:04 +020057 } else {
58 /* The root dprc device didn't yet get to finalize it's probe,
59 * thus the fwnode field is not yet set. Defer probe if we are
60 * facing this situation.
61 */
62 return ERR_PTR(-EPROBE_DEFER);
Ioana Ciornei71947922019-10-31 01:18:31 +020063 }
64
Robert-Ionut Alexa5b1e38c2022-01-06 15:59:03 +020065 if (!parent)
66 return NULL;
67
Calvin Johnson3264f592021-06-11 13:54:01 +030068 fwnode_for_each_child_node(parent, child) {
69 err = -EINVAL;
70 if (is_acpi_device_node(child))
71 err = acpi_get_local_address(ACPI_HANDLE_FWNODE(child), &id);
72 else if (is_of_node(child))
73 err = of_property_read_u32(to_of_node(child), "reg", &id);
74 if (err)
75 continue;
Ioana Ciornei71947922019-10-31 01:18:31 +020076
Calvin Johnson3264f592021-06-11 13:54:01 +030077 if (id == dpmac_id) {
78 of_node_put(dpmacs);
79 return child;
80 }
81 }
82 of_node_put(dpmacs);
83 return NULL;
Ioana Ciornei71947922019-10-31 01:18:31 +020084}
85
Calvin Johnson3264f592021-06-11 13:54:01 +030086static int dpaa2_mac_get_if_mode(struct fwnode_handle *dpmac_node,
Ioana Ciornei71947922019-10-31 01:18:31 +020087 struct dpmac_attr attr)
88{
Andrew Lunn0c65b2b2019-11-04 02:40:33 +010089 phy_interface_t if_mode;
90 int err;
Ioana Ciornei71947922019-10-31 01:18:31 +020091
Calvin Johnson3264f592021-06-11 13:54:01 +030092 err = fwnode_get_phy_mode(dpmac_node);
93 if (err > 0)
94 return err;
Ioana Ciornei71947922019-10-31 01:18:31 +020095
Ioana Ciornei226df3e2019-11-06 19:06:50 +020096 err = phy_mode(attr.eth_if, &if_mode);
97 if (!err)
Ioana Ciornei71947922019-10-31 01:18:31 +020098 return if_mode;
99
Ioana Ciornei226df3e2019-11-06 19:06:50 +0200100 return err;
Ioana Ciornei71947922019-10-31 01:18:31 +0200101}
102
Ioana Ciornei71947922019-10-31 01:18:31 +0200103static void dpaa2_mac_config(struct phylink_config *config, unsigned int mode,
104 const struct phylink_link_state *state)
105{
106 struct dpaa2_mac *mac = phylink_to_dpaa2_mac(config);
107 struct dpmac_link_state *dpmac_state = &mac->state;
108 int err;
109
Ioana Ciornei71947922019-10-31 01:18:31 +0200110 if (state->an_enabled)
111 dpmac_state->options |= DPMAC_LINK_OPT_AUTONEG;
112 else
113 dpmac_state->options &= ~DPMAC_LINK_OPT_AUTONEG;
114
Ioana Ciornei71947922019-10-31 01:18:31 +0200115 err = dpmac_set_link_state(mac->mc_io, 0,
116 mac->mc_dev->mc_handle, dpmac_state);
117 if (err)
Russell King37556a42020-02-26 10:24:01 +0000118 netdev_err(mac->net_dev, "%s: dpmac_set_link_state() = %d\n",
119 __func__, err);
Ioana Ciornei71947922019-10-31 01:18:31 +0200120}
121
Russell King91a208f2020-02-26 10:23:41 +0000122static void dpaa2_mac_link_up(struct phylink_config *config,
123 struct phy_device *phy,
124 unsigned int mode, phy_interface_t interface,
125 int speed, int duplex,
126 bool tx_pause, bool rx_pause)
Ioana Ciornei71947922019-10-31 01:18:31 +0200127{
128 struct dpaa2_mac *mac = phylink_to_dpaa2_mac(config);
129 struct dpmac_link_state *dpmac_state = &mac->state;
130 int err;
131
132 dpmac_state->up = 1;
Russell King37556a42020-02-26 10:24:01 +0000133
Ioana Ciorneica763342021-01-08 11:07:26 +0200134 dpmac_state->rate = speed;
Russell King37556a42020-02-26 10:24:01 +0000135
Ioana Ciorneica763342021-01-08 11:07:26 +0200136 if (duplex == DUPLEX_HALF)
137 dpmac_state->options |= DPMAC_LINK_OPT_HALF_DUPLEX;
138 else if (duplex == DUPLEX_FULL)
139 dpmac_state->options &= ~DPMAC_LINK_OPT_HALF_DUPLEX;
Russell King37556a42020-02-26 10:24:01 +0000140
Ioana Ciorneica763342021-01-08 11:07:26 +0200141 if (rx_pause)
142 dpmac_state->options |= DPMAC_LINK_OPT_PAUSE;
143 else
144 dpmac_state->options &= ~DPMAC_LINK_OPT_PAUSE;
Russell King37556a42020-02-26 10:24:01 +0000145
Ioana Ciorneica763342021-01-08 11:07:26 +0200146 if (rx_pause ^ tx_pause)
147 dpmac_state->options |= DPMAC_LINK_OPT_ASYM_PAUSE;
148 else
149 dpmac_state->options &= ~DPMAC_LINK_OPT_ASYM_PAUSE;
Russell King37556a42020-02-26 10:24:01 +0000150
Ioana Ciornei71947922019-10-31 01:18:31 +0200151 err = dpmac_set_link_state(mac->mc_io, 0,
152 mac->mc_dev->mc_handle, dpmac_state);
153 if (err)
Russell King37556a42020-02-26 10:24:01 +0000154 netdev_err(mac->net_dev, "%s: dpmac_set_link_state() = %d\n",
155 __func__, err);
Ioana Ciornei71947922019-10-31 01:18:31 +0200156}
157
158static void dpaa2_mac_link_down(struct phylink_config *config,
159 unsigned int mode,
160 phy_interface_t interface)
161{
162 struct dpaa2_mac *mac = phylink_to_dpaa2_mac(config);
163 struct dpmac_link_state *dpmac_state = &mac->state;
164 int err;
165
166 dpmac_state->up = 0;
167 err = dpmac_set_link_state(mac->mc_io, 0,
168 mac->mc_dev->mc_handle, dpmac_state);
169 if (err)
170 netdev_err(mac->net_dev, "dpmac_set_link_state() = %d\n", err);
171}
172
173static const struct phylink_mac_ops dpaa2_mac_phylink_ops = {
Russell King (Oracle)6d386f62021-11-17 17:24:13 +0000174 .validate = phylink_generic_validate,
Ioana Ciornei71947922019-10-31 01:18:31 +0200175 .mac_config = dpaa2_mac_config,
176 .mac_link_up = dpaa2_mac_link_up,
177 .mac_link_down = dpaa2_mac_link_down,
178};
179
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300180static int dpaa2_pcs_create(struct dpaa2_mac *mac,
Calvin Johnson3264f592021-06-11 13:54:01 +0300181 struct fwnode_handle *dpmac_node,
182 int id)
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300183{
184 struct mdio_device *mdiodev;
Calvin Johnson3264f592021-06-11 13:54:01 +0300185 struct fwnode_handle *node;
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300186
Calvin Johnson3264f592021-06-11 13:54:01 +0300187 node = fwnode_find_reference(dpmac_node, "pcs-handle", 0);
188 if (IS_ERR(node)) {
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300189 /* do not error out on old DTS files */
190 netdev_warn(mac->net_dev, "pcs-handle node not found\n");
191 return 0;
192 }
193
Calvin Johnson3264f592021-06-11 13:54:01 +0300194 if (!fwnode_device_is_available(node)) {
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300195 netdev_err(mac->net_dev, "pcs-handle node not available\n");
Calvin Johnson3264f592021-06-11 13:54:01 +0300196 fwnode_handle_put(node);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300197 return -ENODEV;
198 }
199
Calvin Johnson3264f592021-06-11 13:54:01 +0300200 mdiodev = fwnode_mdio_find_device(node);
201 fwnode_handle_put(node);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300202 if (!mdiodev)
203 return -EPROBE_DEFER;
204
205 mac->pcs = lynx_pcs_create(mdiodev);
206 if (!mac->pcs) {
207 netdev_err(mac->net_dev, "lynx_pcs_create() failed\n");
208 put_device(&mdiodev->dev);
209 return -ENOMEM;
210 }
211
212 return 0;
213}
214
215static void dpaa2_pcs_destroy(struct dpaa2_mac *mac)
216{
Colin Fostere7026f12021-12-28 21:03:06 -0800217 struct phylink_pcs *phylink_pcs = mac->pcs;
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300218
Colin Fostere7026f12021-12-28 21:03:06 -0800219 if (phylink_pcs) {
220 struct mdio_device *mdio = lynx_get_mdio_device(phylink_pcs);
221 struct device *dev = &mdio->dev;
222
223 lynx_pcs_destroy(phylink_pcs);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300224 put_device(dev);
225 mac->pcs = NULL;
226 }
227}
228
Ioana Ciornei71947922019-10-31 01:18:31 +0200229int dpaa2_mac_connect(struct dpaa2_mac *mac)
230{
Ioana Ciornei71947922019-10-31 01:18:31 +0200231 struct net_device *net_dev = mac->net_dev;
Calvin Johnson3264f592021-06-11 13:54:01 +0300232 struct fwnode_handle *dpmac_node;
Ioana Ciornei71947922019-10-31 01:18:31 +0200233 struct phylink *phylink;
Ioana Ciornei71947922019-10-31 01:18:31 +0200234 int err;
235
Ioana Ciornei095dca12021-01-08 11:07:22 +0200236 mac->if_link_type = mac->attr.link_type;
237
Calvin Johnson3264f592021-06-11 13:54:01 +0300238 dpmac_node = mac->fw_node;
Ioana Ciornei095dca12021-01-08 11:07:22 +0200239 if (!dpmac_node) {
240 netdev_err(net_dev, "No dpmac@%d node found.\n", mac->attr.id);
Ioana Ciornei71947922019-10-31 01:18:31 +0200241 return -ENODEV;
242 }
243
Ioana Ciornei095dca12021-01-08 11:07:22 +0200244 err = dpaa2_mac_get_if_mode(dpmac_node, mac->attr);
Ioana Ciorneib193f2e2021-05-21 16:25:29 +0300245 if (err < 0)
246 return -EINVAL;
Ioana Ciornei71947922019-10-31 01:18:31 +0200247 mac->if_mode = err;
248
249 /* The MAC does not have the capability to add RGMII delays so
250 * error out if the interface mode requests them and there is no PHY
251 * to act upon them
252 */
Calvin Johnson3264f592021-06-11 13:54:01 +0300253 if (of_phy_is_fixed_link(to_of_node(dpmac_node)) &&
Ioana Ciornei71947922019-10-31 01:18:31 +0200254 (mac->if_mode == PHY_INTERFACE_MODE_RGMII_ID ||
255 mac->if_mode == PHY_INTERFACE_MODE_RGMII_RXID ||
256 mac->if_mode == PHY_INTERFACE_MODE_RGMII_TXID)) {
257 netdev_err(net_dev, "RGMII delay not supported\n");
Ioana Ciorneib193f2e2021-05-21 16:25:29 +0300258 return -EINVAL;
Ioana Ciornei71947922019-10-31 01:18:31 +0200259 }
260
Russell King085f1772021-02-05 10:40:09 +0000261 if ((mac->attr.link_type == DPMAC_LINK_TYPE_PHY &&
262 mac->attr.eth_if != DPMAC_ETH_IF_RGMII) ||
263 mac->attr.link_type == DPMAC_LINK_TYPE_BACKPLANE) {
Ioana Ciornei095dca12021-01-08 11:07:22 +0200264 err = dpaa2_pcs_create(mac, dpmac_node, mac->attr.id);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300265 if (err)
Ioana Ciorneib193f2e2021-05-21 16:25:29 +0300266 return err;
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300267 }
268
Russell King15d0b142021-11-17 17:24:02 +0000269 memset(&mac->phylink_config, 0, sizeof(mac->phylink_config));
Ioana Ciornei71947922019-10-31 01:18:31 +0200270 mac->phylink_config.dev = &net_dev->dev;
271 mac->phylink_config.type = PHYLINK_NETDEV;
272
Russell King (Oracle)6d386f62021-11-17 17:24:13 +0000273 mac->phylink_config.mac_capabilities = MAC_SYM_PAUSE | MAC_ASYM_PAUSE |
274 MAC_10FD | MAC_100FD | MAC_1000FD | MAC_2500FD | MAC_5000FD |
275 MAC_10000FD;
276
Russell King15d0b142021-11-17 17:24:02 +0000277 /* We support the current interface mode, and if we have a PCS
278 * similar interface modes that do not require the PLLs to be
279 * reconfigured.
280 */
281 __set_bit(mac->if_mode, mac->phylink_config.supported_interfaces);
282 if (mac->pcs) {
283 switch (mac->if_mode) {
284 case PHY_INTERFACE_MODE_1000BASEX:
285 case PHY_INTERFACE_MODE_SGMII:
286 __set_bit(PHY_INTERFACE_MODE_1000BASEX,
287 mac->phylink_config.supported_interfaces);
288 __set_bit(PHY_INTERFACE_MODE_SGMII,
289 mac->phylink_config.supported_interfaces);
290 break;
291
292 default:
293 break;
294 }
295 }
296
Ioana Ciornei71947922019-10-31 01:18:31 +0200297 phylink = phylink_create(&mac->phylink_config,
Calvin Johnson3264f592021-06-11 13:54:01 +0300298 dpmac_node, mac->if_mode,
Ioana Ciornei71947922019-10-31 01:18:31 +0200299 &dpaa2_mac_phylink_ops);
300 if (IS_ERR(phylink)) {
301 err = PTR_ERR(phylink);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300302 goto err_pcs_destroy;
Ioana Ciornei71947922019-10-31 01:18:31 +0200303 }
304 mac->phylink = phylink;
305
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300306 if (mac->pcs)
Colin Fostere7026f12021-12-28 21:03:06 -0800307 phylink_set_pcs(mac->phylink, mac->pcs);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300308
Calvin Johnson3264f592021-06-11 13:54:01 +0300309 err = phylink_fwnode_phy_connect(mac->phylink, dpmac_node, 0);
Ioana Ciornei71947922019-10-31 01:18:31 +0200310 if (err) {
Calvin Johnson3264f592021-06-11 13:54:01 +0300311 netdev_err(net_dev, "phylink_fwnode_phy_connect() = %d\n", err);
Ioana Ciornei71947922019-10-31 01:18:31 +0200312 goto err_phylink_destroy;
313 }
314
Ioana Ciornei71947922019-10-31 01:18:31 +0200315 return 0;
316
317err_phylink_destroy:
318 phylink_destroy(mac->phylink);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300319err_pcs_destroy:
320 dpaa2_pcs_destroy(mac);
Ioana Ciornei095dca12021-01-08 11:07:22 +0200321
Ioana Ciornei71947922019-10-31 01:18:31 +0200322 return err;
323}
324
325void dpaa2_mac_disconnect(struct dpaa2_mac *mac)
326{
327 if (!mac->phylink)
328 return;
329
330 phylink_disconnect_phy(mac->phylink);
331 phylink_destroy(mac->phylink);
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300332 dpaa2_pcs_destroy(mac);
Ioana Ciornei095dca12021-01-08 11:07:22 +0200333}
Ioana Ciornei94ae8992020-09-23 18:41:23 +0300334
Ioana Ciornei095dca12021-01-08 11:07:22 +0200335int dpaa2_mac_open(struct dpaa2_mac *mac)
336{
337 struct fsl_mc_device *dpmac_dev = mac->mc_dev;
338 struct net_device *net_dev = mac->net_dev;
Ioana Ciornei4e30e982022-01-06 15:59:04 +0200339 struct fwnode_handle *fw_node;
Ioana Ciornei095dca12021-01-08 11:07:22 +0200340 int err;
341
342 err = dpmac_open(mac->mc_io, 0, dpmac_dev->obj_desc.id,
343 &dpmac_dev->mc_handle);
344 if (err || !dpmac_dev->mc_handle) {
345 netdev_err(net_dev, "dpmac_open() = %d\n", err);
346 return -ENODEV;
347 }
348
349 err = dpmac_get_attributes(mac->mc_io, 0, dpmac_dev->mc_handle,
350 &mac->attr);
351 if (err) {
352 netdev_err(net_dev, "dpmac_get_attributes() = %d\n", err);
353 goto err_close_dpmac;
354 }
355
Ioana Ciorneib193f2e2021-05-21 16:25:29 +0300356 /* Find the device node representing the MAC device and link the device
357 * behind the associated netdev to it.
358 */
Ioana Ciornei4e30e982022-01-06 15:59:04 +0200359 fw_node = dpaa2_mac_get_node(&mac->mc_dev->dev, mac->attr.id);
360 if (IS_ERR(fw_node)) {
361 err = PTR_ERR(fw_node);
362 goto err_close_dpmac;
363 }
364
365 mac->fw_node = fw_node;
Calvin Johnson3264f592021-06-11 13:54:01 +0300366 net_dev->dev.of_node = to_of_node(mac->fw_node);
Ioana Ciorneib193f2e2021-05-21 16:25:29 +0300367
Ioana Ciornei095dca12021-01-08 11:07:22 +0200368 return 0;
369
370err_close_dpmac:
371 dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle);
372 return err;
373}
374
375void dpaa2_mac_close(struct dpaa2_mac *mac)
376{
377 struct fsl_mc_device *dpmac_dev = mac->mc_dev;
378
379 dpmac_close(mac->mc_io, 0, dpmac_dev->mc_handle);
Calvin Johnson3264f592021-06-11 13:54:01 +0300380 if (mac->fw_node)
381 fwnode_handle_put(mac->fw_node);
Ioana Ciornei71947922019-10-31 01:18:31 +0200382}
Ioana Ciornei991df1f2019-11-07 12:44:48 +0200383
384static char dpaa2_mac_ethtool_stats[][ETH_GSTRING_LEN] = {
385 [DPMAC_CNT_ING_ALL_FRAME] = "[mac] rx all frames",
386 [DPMAC_CNT_ING_GOOD_FRAME] = "[mac] rx frames ok",
387 [DPMAC_CNT_ING_ERR_FRAME] = "[mac] rx frame errors",
388 [DPMAC_CNT_ING_FRAME_DISCARD] = "[mac] rx frame discards",
389 [DPMAC_CNT_ING_UCAST_FRAME] = "[mac] rx u-cast",
390 [DPMAC_CNT_ING_BCAST_FRAME] = "[mac] rx b-cast",
391 [DPMAC_CNT_ING_MCAST_FRAME] = "[mac] rx m-cast",
392 [DPMAC_CNT_ING_FRAME_64] = "[mac] rx 64 bytes",
393 [DPMAC_CNT_ING_FRAME_127] = "[mac] rx 65-127 bytes",
394 [DPMAC_CNT_ING_FRAME_255] = "[mac] rx 128-255 bytes",
395 [DPMAC_CNT_ING_FRAME_511] = "[mac] rx 256-511 bytes",
396 [DPMAC_CNT_ING_FRAME_1023] = "[mac] rx 512-1023 bytes",
397 [DPMAC_CNT_ING_FRAME_1518] = "[mac] rx 1024-1518 bytes",
398 [DPMAC_CNT_ING_FRAME_1519_MAX] = "[mac] rx 1519-max bytes",
399 [DPMAC_CNT_ING_FRAG] = "[mac] rx frags",
400 [DPMAC_CNT_ING_JABBER] = "[mac] rx jabber",
401 [DPMAC_CNT_ING_ALIGN_ERR] = "[mac] rx align errors",
402 [DPMAC_CNT_ING_OVERSIZED] = "[mac] rx oversized",
403 [DPMAC_CNT_ING_VALID_PAUSE_FRAME] = "[mac] rx pause",
404 [DPMAC_CNT_ING_BYTE] = "[mac] rx bytes",
405 [DPMAC_CNT_EGR_GOOD_FRAME] = "[mac] tx frames ok",
406 [DPMAC_CNT_EGR_UCAST_FRAME] = "[mac] tx u-cast",
407 [DPMAC_CNT_EGR_MCAST_FRAME] = "[mac] tx m-cast",
408 [DPMAC_CNT_EGR_BCAST_FRAME] = "[mac] tx b-cast",
409 [DPMAC_CNT_EGR_ERR_FRAME] = "[mac] tx frame errors",
410 [DPMAC_CNT_EGR_UNDERSIZED] = "[mac] tx undersized",
411 [DPMAC_CNT_EGR_VALID_PAUSE_FRAME] = "[mac] tx b-pause",
412 [DPMAC_CNT_EGR_BYTE] = "[mac] tx bytes",
413};
414
415#define DPAA2_MAC_NUM_STATS ARRAY_SIZE(dpaa2_mac_ethtool_stats)
416
417int dpaa2_mac_get_sset_count(void)
418{
419 return DPAA2_MAC_NUM_STATS;
420}
421
422void dpaa2_mac_get_strings(u8 *data)
423{
424 u8 *p = data;
425 int i;
426
427 for (i = 0; i < DPAA2_MAC_NUM_STATS; i++) {
428 strlcpy(p, dpaa2_mac_ethtool_stats[i], ETH_GSTRING_LEN);
429 p += ETH_GSTRING_LEN;
430 }
431}
432
433void dpaa2_mac_get_ethtool_stats(struct dpaa2_mac *mac, u64 *data)
434{
435 struct fsl_mc_device *dpmac_dev = mac->mc_dev;
436 int i, err;
437 u64 value;
438
439 for (i = 0; i < DPAA2_MAC_NUM_STATS; i++) {
440 err = dpmac_get_counter(mac->mc_io, 0, dpmac_dev->mc_handle,
441 i, &value);
442 if (err) {
443 netdev_err_once(mac->net_dev,
444 "dpmac_get_counter error %d\n", err);
445 *(data + i) = U64_MAX;
446 continue;
447 }
448 *(data + i) = value;
449 }
450}