mfd: intel-m10-bmc: Expose MAC address and count
authorRuss Weight <russell.h.weight@intel.com>
Thu, 14 Jan 2021 23:16:48 +0000 (15:16 -0800)
committerLee Jones <lee.jones@linaro.org>
Mon, 8 Feb 2021 13:54:25 +0000 (13:54 +0000)
Create two sysfs entries for exposing the MAC address and count
from the MAX10 BMC register space. The MAC address is the first
in a sequential block of MAC addresses reserved for the FPGA card.
The MAC count is the number of MAC addresses in the reserved block.

Signed-off-by: Russ Weight <russell.h.weight@intel.com>
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Documentation/ABI/testing/sysfs-driver-intel-m10-bmc
drivers/mfd/intel-m10-bmc.c
include/linux/mfd/intel-m10-bmc.h

index 979a2d62513ff5c9c25307c980b48a682078209e..9773925138af1a73d5f21d980ddf495f38db844f 100644 (file)
@@ -13,3 +13,24 @@ Contact:     Xu Yilun <yilun.xu@intel.com>
 Description:   Read only. Returns the firmware version of Intel MAX10
                BMC chip.
                Format: "0x%x".
+
+What:          /sys/bus/spi/devices/.../mac_address
+Date:          January 2021
+KernelVersion:  5.12
+Contact:       Russ Weight <russell.h.weight@intel.com>
+Description:   Read only. Returns the first MAC address in a block
+               of sequential MAC addresses assigned to the board
+               that is managed by the Intel MAX10 BMC. It is stored in
+               FLASH storage and is mirrored in the MAX10 BMC register
+               space.
+               Format: "%02x:%02x:%02x:%02x:%02x:%02x".
+
+What:          /sys/bus/spi/devices/.../mac_count
+Date:          January 2021
+KernelVersion:  5.12
+Contact:       Russ Weight <russell.h.weight@intel.com>
+Description:   Read only. Returns the number of sequential MAC
+               addresses assigned to the board managed by the Intel
+               MAX10 BMC. This value is stored in FLASH and is mirrored
+               in the MAX10 BMC register space.
+               Format: "%u".
index b84579b7b4f0cc3fae17c2caa85e71dea67a56e1..06c977519479ac3b1bb941f873e81c30d9cb4445 100644 (file)
@@ -60,9 +60,52 @@ static ssize_t bmcfw_version_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(bmcfw_version);
 
+static ssize_t mac_address_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       struct intel_m10bmc *max10 = dev_get_drvdata(dev);
+       unsigned int macaddr_low, macaddr_high;
+       int ret;
+
+       ret = m10bmc_sys_read(max10, M10BMC_MAC_LOW, &macaddr_low);
+       if (ret)
+               return ret;
+
+       ret = m10bmc_sys_read(max10, M10BMC_MAC_HIGH, &macaddr_high);
+       if (ret)
+               return ret;
+
+       return sysfs_emit(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
+                         (u8)FIELD_GET(M10BMC_MAC_BYTE1, macaddr_low),
+                         (u8)FIELD_GET(M10BMC_MAC_BYTE2, macaddr_low),
+                         (u8)FIELD_GET(M10BMC_MAC_BYTE3, macaddr_low),
+                         (u8)FIELD_GET(M10BMC_MAC_BYTE4, macaddr_low),
+                         (u8)FIELD_GET(M10BMC_MAC_BYTE5, macaddr_high),
+                         (u8)FIELD_GET(M10BMC_MAC_BYTE6, macaddr_high));
+}
+static DEVICE_ATTR_RO(mac_address);
+
+static ssize_t mac_count_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       struct intel_m10bmc *max10 = dev_get_drvdata(dev);
+       unsigned int macaddr_high;
+       int ret;
+
+       ret = m10bmc_sys_read(max10, M10BMC_MAC_HIGH, &macaddr_high);
+       if (ret)
+               return ret;
+
+       return sysfs_emit(buf, "%u\n",
+                         (u8)FIELD_GET(M10BMC_MAC_COUNT, macaddr_high));
+}
+static DEVICE_ATTR_RO(mac_count);
+
 static struct attribute *m10bmc_attrs[] = {
        &dev_attr_bmc_version.attr,
        &dev_attr_bmcfw_version.attr,
+       &dev_attr_mac_address.attr,
+       &dev_attr_mac_count.attr,
        NULL,
 };
 ATTRIBUTE_GROUPS(m10bmc);
index c8ef2f1654a4460f34c1ae5856ee78fa29f07830..74d4e193966a9a846d22e9de62fb1dc4db3c1632 100644 (file)
 
 /* Register offset of system registers */
 #define NIOS2_FW_VERSION               0x0
+#define M10BMC_MAC_LOW                 0x10
+#define M10BMC_MAC_BYTE4               GENMASK(7, 0)
+#define M10BMC_MAC_BYTE3               GENMASK(15, 8)
+#define M10BMC_MAC_BYTE2               GENMASK(23, 16)
+#define M10BMC_MAC_BYTE1               GENMASK(31, 24)
+#define M10BMC_MAC_HIGH                        0x14
+#define M10BMC_MAC_BYTE6               GENMASK(7, 0)
+#define M10BMC_MAC_BYTE5               GENMASK(15, 8)
+#define M10BMC_MAC_COUNT               GENMASK(23, 16)
 #define M10BMC_TEST_REG                        0x3c
 #define M10BMC_BUILD_VER               0x68
 #define M10BMC_VER_MAJOR_MSK           GENMASK(23, 16)