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 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->vaddr); 22 else 23 return sprintf(buf, "none"); 24 } 25 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 int i = 0; 39 40 list_for_each_entry_safe(fq, tmp, &priv->dpaa_fq_list, list) { 41 switch (fq->fq_type) { 42 case FQ_TYPE_RX_DEFAULT: 43 str = "Rx default"; 44 break; 45 case FQ_TYPE_RX_ERROR: 46 str = "Rx error"; 47 break; 48 case FQ_TYPE_RX_PCD: 49 str = "Rx PCD"; 50 break; 51 case FQ_TYPE_TX_CONFIRM: 52 str = "Tx default confirmation"; 53 break; 54 case FQ_TYPE_TX_CONF_MQ: 55 str = "Tx confirmation (mq)"; 56 break; 57 case FQ_TYPE_TX_ERROR: 58 str = "Tx error"; 59 break; 60 case FQ_TYPE_TX: 61 str = "Tx"; 62 break; 63 default: 64 str = "Unknown"; 65 } 66 67 if (prev && (abs(fq->fqid - prev->fqid) != 1 || 68 str != prevstr)) { 69 if (last_fqid == first_fqid) 70 bytes += sprintf(buf + bytes, 71 "%s: %d\n", prevstr, prev->fqid); 72 else 73 bytes += sprintf(buf + bytes, 74 "%s: %d - %d\n", prevstr, 75 first_fqid, last_fqid); 76 } 77 78 if (prev && abs(fq->fqid - prev->fqid) == 1 && 79 str == prevstr) { 80 last_fqid = fq->fqid; 81 } else { 82 first_fqid = fq->fqid; 83 last_fqid = fq->fqid; 84 } 85 86 prev = fq; 87 prevstr = str; 88 i++; 89 } 90 91 if (prev) { 92 if (last_fqid == first_fqid) 93 bytes += sprintf(buf + bytes, "%s: %d\n", prevstr, 94 prev->fqid); 95 else 96 bytes += sprintf(buf + bytes, "%s: %d - %d\n", prevstr, 97 first_fqid, last_fqid); 98 } 99 100 return bytes; 101 } 102 103 static ssize_t dpaa_eth_show_bpids(struct device *dev, 104 struct device_attribute *attr, char *buf) 105 { 106 struct dpaa_priv *priv = netdev_priv(to_net_dev(dev)); 107 ssize_t bytes = 0; 108 109 bytes += snprintf(buf + bytes, PAGE_SIZE - bytes, "%u\n", 110 priv->dpaa_bp->bpid); 111 112 return bytes; 113 } 114 115 static struct device_attribute dpaa_eth_attrs[] = { 116 __ATTR(device_addr, 0444, dpaa_eth_show_addr, NULL), 117 __ATTR(fqids, 0444, dpaa_eth_show_fqids, NULL), 118 __ATTR(bpids, 0444, dpaa_eth_show_bpids, NULL), 119 }; 120 121 void dpaa_eth_sysfs_init(struct device *dev) 122 { 123 int i; 124 125 for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++) 126 if (device_create_file(dev, &dpaa_eth_attrs[i])) { 127 dev_err(dev, "Error creating sysfs file\n"); 128 while (i > 0) 129 device_remove_file(dev, &dpaa_eth_attrs[--i]); 130 return; 131 } 132 } 133 134 void dpaa_eth_sysfs_remove(struct device *dev) 135 { 136 int i; 137 138 for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++) 139 device_remove_file(dev, &dpaa_eth_attrs[i]); 140 } 141