1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
3 * Copyright 2008 - 2016 Freescale Semiconductor Inc.
6 #include <linux/init.h>
7 #include <linux/module.h>
9 #include <linux/of_net.h>
13 static ssize_t dpaa_eth_show_addr(struct device *dev,
14 struct device_attribute *attr, char *buf)
16 struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
17 struct mac_device *mac_dev = priv->mac_dev;
20 return sprintf(buf, "%llx",
21 (unsigned long long)mac_dev->res->start);
23 return sprintf(buf, "none");
26 static ssize_t dpaa_eth_show_fqids(struct device *dev,
27 struct device_attribute *attr, char *buf)
29 struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
30 struct dpaa_fq *prev = NULL;
39 list_for_each_entry_safe(fq, tmp, &priv->dpaa_fq_list, list) {
40 switch (fq->fq_type) {
41 case FQ_TYPE_RX_DEFAULT:
44 case FQ_TYPE_RX_ERROR:
50 case FQ_TYPE_TX_CONFIRM:
51 str = "Tx default confirmation";
53 case FQ_TYPE_TX_CONF_MQ:
54 str = "Tx confirmation (mq)";
56 case FQ_TYPE_TX_ERROR:
66 if (prev && (abs(fq->fqid - prev->fqid) != 1 ||
68 if (last_fqid == first_fqid)
69 bytes += sprintf(buf + bytes,
70 "%s: %d\n", prevstr, prev->fqid);
72 bytes += sprintf(buf + bytes,
73 "%s: %d - %d\n", prevstr,
74 first_fqid, last_fqid);
77 if (prev && abs(fq->fqid - prev->fqid) == 1 &&
81 first_fqid = fq->fqid;
90 if (last_fqid == first_fqid)
91 bytes += sprintf(buf + bytes, "%s: %d\n", prevstr,
94 bytes += sprintf(buf + bytes, "%s: %d - %d\n", prevstr,
95 first_fqid, last_fqid);
101 static ssize_t dpaa_eth_show_bpids(struct device *dev,
102 struct device_attribute *attr, char *buf)
104 struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
107 bytes += snprintf(buf + bytes, PAGE_SIZE - bytes, "%u\n",
108 priv->dpaa_bp->bpid);
113 static struct device_attribute dpaa_eth_attrs[] = {
114 __ATTR(device_addr, 0444, dpaa_eth_show_addr, NULL),
115 __ATTR(fqids, 0444, dpaa_eth_show_fqids, NULL),
116 __ATTR(bpids, 0444, dpaa_eth_show_bpids, NULL),
119 void dpaa_eth_sysfs_init(struct device *dev)
123 for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
124 if (device_create_file(dev, &dpaa_eth_attrs[i])) {
125 dev_err(dev, "Error creating sysfs file\n");
127 device_remove_file(dev, &dpaa_eth_attrs[--i]);
132 void dpaa_eth_sysfs_remove(struct device *dev)
136 for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
137 device_remove_file(dev, &dpaa_eth_attrs[i]);