Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d8e1881 authored by Logan Gunthorpe's avatar Logan Gunthorpe Committed by Bjorn Helgaas
Browse files

switchtec: Add sysfs attributes to the Switchtec driver



Add a few read-only sysfs attributes which provide some device information
that is exposed from the devices, primarily component and device names and
versions.

These are documented in Documentation/ABI/testing/sysfs-class-switchtec.

Tested-by: default avatarKrishna Dhulipala <krishnad@fb.com>
Signed-off-by: default avatarLogan Gunthorpe <logang@deltatee.com>
Signed-off-by: default avatarStephen Bates <stephen.bates@microsemi.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Reviewed-by: default avatarWei Zhang <wzhang@fb.com>
Reviewed-by: default avatarJens Axboe <axboe@fb.com>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 44fc691b
Loading
Loading
Loading
Loading
+96 −0
Original line number Diff line number Diff line
switchtec - Microsemi Switchtec PCI Switch Management Endpoint

For details on this subsystem look at Documentation/switchtec.txt.

What: 		/sys/class/switchtec
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	The switchtec class subsystem folder.
		Each registered switchtec driver is represented by a switchtecX
		subfolder (X being an integer >= 0).


What:		/sys/class/switchtec/switchtec[0-9]+/component_id
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Component identifier as stored in the hardware (eg. PM8543)
		(read only)
Values: 	arbitrary string.


What:		/sys/class/switchtec/switchtec[0-9]+/component_revision
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Component revision stored in the hardware (read only)
Values: 	integer.


What:		/sys/class/switchtec/switchtec[0-9]+/component_vendor
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Component vendor as stored in the hardware (eg. MICROSEM)
		(read only)
Values: 	arbitrary string.


What:		/sys/class/switchtec/switchtec[0-9]+/device_version
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Device version as stored in the hardware (read only)
Values: 	integer.


What:		/sys/class/switchtec/switchtec[0-9]+/fw_version
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Currently running firmware version (read only)
Values: 	integer (in hexadecimal).


What:		/sys/class/switchtec/switchtec[0-9]+/partition
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Partition number for this device in the switch (read only)
Values: 	integer.


What:		/sys/class/switchtec/switchtec[0-9]+/partition_count
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Total number of partitions in the switch (read only)
Values: 	integer.


What:		/sys/class/switchtec/switchtec[0-9]+/product_id
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Product identifier as stored in the hardware (eg. PSX 48XG3)
		(read only)
Values: 	arbitrary string.


What:		/sys/class/switchtec/switchtec[0-9]+/product_revision
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Product revision stored in the hardware (eg. RevB)
		(read only)
Values: 	arbitrary string.


What:		/sys/class/switchtec/switchtec[0-9]+/product_vendor
Date:		05-Jan-2017
KernelVersion:	v4.11
Contact:	Logan Gunthorpe <logang@deltatee.com>
Description:	Product vendor as stored in the hardware (eg. MICROSEM)
		(read only)
Values: 	arbitrary string.
+1 −0
Original line number Diff line number Diff line
@@ -9662,6 +9662,7 @@ M: Logan Gunthorpe <logang@deltatee.com>
L:	linux-pci@vger.kernel.org
S:	Maintained
F:	Documentation/switchtec.txt
F:	Documentation/ABI/testing/sysfs-class-switchtec
F:	drivers/pci/switch/switchtec*

PCI DRIVER FOR NVIDIA TEGRA
+113 −0
Original line number Diff line number Diff line
@@ -486,6 +486,118 @@ static void mrpc_timeout_work(struct work_struct *work)
	mutex_unlock(&stdev->mrpc_mutex);
}

static ssize_t device_version_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct switchtec_dev *stdev = to_stdev(dev);
	u32 ver;

	ver = ioread32(&stdev->mmio_sys_info->device_version);

	return sprintf(buf, "%x\n", ver);
}
static DEVICE_ATTR_RO(device_version);

static ssize_t fw_version_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct switchtec_dev *stdev = to_stdev(dev);
	u32 ver;

	ver = ioread32(&stdev->mmio_sys_info->firmware_version);

	return sprintf(buf, "%08x\n", ver);
}
static DEVICE_ATTR_RO(fw_version);

static ssize_t io_string_show(char *buf, void __iomem *attr, size_t len)
{
	int i;

	memcpy_fromio(buf, attr, len);
	buf[len] = '\n';
	buf[len + 1] = 0;

	for (i = len - 1; i > 0; i--) {
		if (buf[i] != ' ')
			break;
		buf[i] = '\n';
		buf[i + 1] = 0;
	}

	return strlen(buf);
}

#define DEVICE_ATTR_SYS_INFO_STR(field) \
static ssize_t field ## _show(struct device *dev, \
	struct device_attribute *attr, char *buf) \
{ \
	struct switchtec_dev *stdev = to_stdev(dev); \
	return io_string_show(buf, &stdev->mmio_sys_info->field, \
			    sizeof(stdev->mmio_sys_info->field)); \
} \
\
static DEVICE_ATTR_RO(field)

DEVICE_ATTR_SYS_INFO_STR(vendor_id);
DEVICE_ATTR_SYS_INFO_STR(product_id);
DEVICE_ATTR_SYS_INFO_STR(product_revision);
DEVICE_ATTR_SYS_INFO_STR(component_vendor);

static ssize_t component_id_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct switchtec_dev *stdev = to_stdev(dev);
	int id = ioread16(&stdev->mmio_sys_info->component_id);

	return sprintf(buf, "PM%04X\n", id);
}
static DEVICE_ATTR_RO(component_id);

static ssize_t component_revision_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct switchtec_dev *stdev = to_stdev(dev);
	int rev = ioread8(&stdev->mmio_sys_info->component_revision);

	return sprintf(buf, "%d\n", rev);
}
static DEVICE_ATTR_RO(component_revision);

static ssize_t partition_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct switchtec_dev *stdev = to_stdev(dev);

	return sprintf(buf, "%d\n", stdev->partition);
}
static DEVICE_ATTR_RO(partition);

static ssize_t partition_count_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct switchtec_dev *stdev = to_stdev(dev);

	return sprintf(buf, "%d\n", stdev->partition_count);
}
static DEVICE_ATTR_RO(partition_count);

static struct attribute *switchtec_device_attrs[] = {
	&dev_attr_device_version.attr,
	&dev_attr_fw_version.attr,
	&dev_attr_vendor_id.attr,
	&dev_attr_product_id.attr,
	&dev_attr_product_revision.attr,
	&dev_attr_component_vendor.attr,
	&dev_attr_component_id.attr,
	&dev_attr_component_revision.attr,
	&dev_attr_partition.attr,
	&dev_attr_partition_count.attr,
	NULL,
};

ATTRIBUTE_GROUPS(switchtec_device);

static int switchtec_dev_open(struct inode *inode, struct file *filp)
{
	struct switchtec_dev *stdev;
@@ -734,6 +846,7 @@ static struct switchtec_dev *stdev_create(struct pci_dev *pdev)
	device_initialize(dev);
	dev->class = switchtec_class;
	dev->parent = &pdev->dev;
	dev->groups = switchtec_device_groups;
	dev->release = stdev_release;

	minor = ida_simple_get(&switchtec_minor_ida, 0, 0,