xref: /linux/drivers/net/ethernet/freescale/dpaa/dpaa_eth_sysfs.c (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later
2 /*
3  * Copyright 2008 - 2016 Freescale Semiconductor Inc.
4  */
5 
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/io.h>
9 #include <linux/of_net.h>
10 #include "dpaa_eth.h"
11 #include "mac.h"
12 
dpaa_eth_show_addr(struct device * dev,struct device_attribute * attr,char * buf)13 static ssize_t dpaa_eth_show_addr(struct device *dev,
14 				  struct device_attribute *attr, char *buf)
15 {
16 	struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
17 	struct mac_device *mac_dev = priv->mac_dev;
18 
19 	if (mac_dev)
20 		return sprintf(buf, "%llx",
21 				(unsigned long long)mac_dev->res->start);
22 	else
23 		return sprintf(buf, "none");
24 }
25 
dpaa_eth_show_fqids(struct device * dev,struct device_attribute * attr,char * buf)26 static ssize_t dpaa_eth_show_fqids(struct device *dev,
27 				   struct device_attribute *attr, char *buf)
28 {
29 	struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
30 	struct dpaa_fq *prev = NULL;
31 	char *prevstr = NULL;
32 	struct dpaa_fq *tmp;
33 	struct dpaa_fq *fq;
34 	u32 first_fqid = 0;
35 	u32 last_fqid = 0;
36 	ssize_t bytes = 0;
37 	char *str;
38 
39 	list_for_each_entry_safe(fq, tmp, &priv->dpaa_fq_list, list) {
40 		switch (fq->fq_type) {
41 		case FQ_TYPE_RX_DEFAULT:
42 			str = "Rx default";
43 			break;
44 		case FQ_TYPE_RX_ERROR:
45 			str = "Rx error";
46 			break;
47 		case FQ_TYPE_RX_PCD:
48 			str = "Rx PCD";
49 			break;
50 		case FQ_TYPE_TX_CONFIRM:
51 			str = "Tx default confirmation";
52 			break;
53 		case FQ_TYPE_TX_CONF_MQ:
54 			str = "Tx confirmation (mq)";
55 			break;
56 		case FQ_TYPE_TX_ERROR:
57 			str = "Tx error";
58 			break;
59 		case FQ_TYPE_TX:
60 			str = "Tx";
61 			break;
62 		default:
63 			str = "Unknown";
64 		}
65 
66 		if (prev && (abs(fq->fqid - prev->fqid) != 1 ||
67 			     str != prevstr)) {
68 			if (last_fqid == first_fqid)
69 				bytes += sprintf(buf + bytes,
70 					"%s: %d\n", prevstr, prev->fqid);
71 			else
72 				bytes += sprintf(buf + bytes,
73 					"%s: %d - %d\n", prevstr,
74 					first_fqid, last_fqid);
75 		}
76 
77 		if (prev && abs(fq->fqid - prev->fqid) == 1 &&
78 		    str == prevstr) {
79 			last_fqid = fq->fqid;
80 		} else {
81 			first_fqid = fq->fqid;
82 			last_fqid = fq->fqid;
83 		}
84 
85 		prev = fq;
86 		prevstr = str;
87 	}
88 
89 	if (prev) {
90 		if (last_fqid == first_fqid)
91 			bytes += sprintf(buf + bytes, "%s: %d\n", prevstr,
92 					prev->fqid);
93 		else
94 			bytes += sprintf(buf + bytes, "%s: %d - %d\n", prevstr,
95 					first_fqid, last_fqid);
96 	}
97 
98 	return bytes;
99 }
100 
dpaa_eth_show_bpids(struct device * dev,struct device_attribute * attr,char * buf)101 static ssize_t dpaa_eth_show_bpids(struct device *dev,
102 				   struct device_attribute *attr, char *buf)
103 {
104 	struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
105 	ssize_t bytes = 0;
106 
107 	bytes += snprintf(buf + bytes, PAGE_SIZE - bytes, "%u\n",
108 				  priv->dpaa_bp->bpid);
109 
110 	return bytes;
111 }
112 
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),
117 };
118 
dpaa_eth_sysfs_init(struct device * dev)119 void dpaa_eth_sysfs_init(struct device *dev)
120 {
121 	int i;
122 
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");
126 			while (i > 0)
127 				device_remove_file(dev, &dpaa_eth_attrs[--i]);
128 			return;
129 		}
130 }
131 
dpaa_eth_sysfs_remove(struct device * dev)132 void dpaa_eth_sysfs_remove(struct device *dev)
133 {
134 	int i;
135 
136 	for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
137 		device_remove_file(dev, &dpaa_eth_attrs[i]);
138 }
139