Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Krishna Dhulipala <krishnad@fb.com>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Signed-off-by: Stephen Bates <stephen.bates@microsemi.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Wei Zhang <wzhang@fb.com>
Reviewed-by: Jens Axboe <axboe@fb.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Logan Gunthorpe and committed by
Bjorn Helgaas
5d8e1881 44fc691b

+210
+96
Documentation/ABI/testing/sysfs-class-switchtec
··· 1 + switchtec - Microsemi Switchtec PCI Switch Management Endpoint 2 + 3 + For details on this subsystem look at Documentation/switchtec.txt. 4 + 5 + What: /sys/class/switchtec 6 + Date: 05-Jan-2017 7 + KernelVersion: v4.11 8 + Contact: Logan Gunthorpe <logang@deltatee.com> 9 + Description: The switchtec class subsystem folder. 10 + Each registered switchtec driver is represented by a switchtecX 11 + subfolder (X being an integer >= 0). 12 + 13 + 14 + What: /sys/class/switchtec/switchtec[0-9]+/component_id 15 + Date: 05-Jan-2017 16 + KernelVersion: v4.11 17 + Contact: Logan Gunthorpe <logang@deltatee.com> 18 + Description: Component identifier as stored in the hardware (eg. PM8543) 19 + (read only) 20 + Values: arbitrary string. 21 + 22 + 23 + What: /sys/class/switchtec/switchtec[0-9]+/component_revision 24 + Date: 05-Jan-2017 25 + KernelVersion: v4.11 26 + Contact: Logan Gunthorpe <logang@deltatee.com> 27 + Description: Component revision stored in the hardware (read only) 28 + Values: integer. 29 + 30 + 31 + What: /sys/class/switchtec/switchtec[0-9]+/component_vendor 32 + Date: 05-Jan-2017 33 + KernelVersion: v4.11 34 + Contact: Logan Gunthorpe <logang@deltatee.com> 35 + Description: Component vendor as stored in the hardware (eg. MICROSEM) 36 + (read only) 37 + Values: arbitrary string. 38 + 39 + 40 + What: /sys/class/switchtec/switchtec[0-9]+/device_version 41 + Date: 05-Jan-2017 42 + KernelVersion: v4.11 43 + Contact: Logan Gunthorpe <logang@deltatee.com> 44 + Description: Device version as stored in the hardware (read only) 45 + Values: integer. 46 + 47 + 48 + What: /sys/class/switchtec/switchtec[0-9]+/fw_version 49 + Date: 05-Jan-2017 50 + KernelVersion: v4.11 51 + Contact: Logan Gunthorpe <logang@deltatee.com> 52 + Description: Currently running firmware version (read only) 53 + Values: integer (in hexadecimal). 54 + 55 + 56 + What: /sys/class/switchtec/switchtec[0-9]+/partition 57 + Date: 05-Jan-2017 58 + KernelVersion: v4.11 59 + Contact: Logan Gunthorpe <logang@deltatee.com> 60 + Description: Partition number for this device in the switch (read only) 61 + Values: integer. 62 + 63 + 64 + What: /sys/class/switchtec/switchtec[0-9]+/partition_count 65 + Date: 05-Jan-2017 66 + KernelVersion: v4.11 67 + Contact: Logan Gunthorpe <logang@deltatee.com> 68 + Description: Total number of partitions in the switch (read only) 69 + Values: integer. 70 + 71 + 72 + What: /sys/class/switchtec/switchtec[0-9]+/product_id 73 + Date: 05-Jan-2017 74 + KernelVersion: v4.11 75 + Contact: Logan Gunthorpe <logang@deltatee.com> 76 + Description: Product identifier as stored in the hardware (eg. PSX 48XG3) 77 + (read only) 78 + Values: arbitrary string. 79 + 80 + 81 + What: /sys/class/switchtec/switchtec[0-9]+/product_revision 82 + Date: 05-Jan-2017 83 + KernelVersion: v4.11 84 + Contact: Logan Gunthorpe <logang@deltatee.com> 85 + Description: Product revision stored in the hardware (eg. RevB) 86 + (read only) 87 + Values: arbitrary string. 88 + 89 + 90 + What: /sys/class/switchtec/switchtec[0-9]+/product_vendor 91 + Date: 05-Jan-2017 92 + KernelVersion: v4.11 93 + Contact: Logan Gunthorpe <logang@deltatee.com> 94 + Description: Product vendor as stored in the hardware (eg. MICROSEM) 95 + (read only) 96 + Values: arbitrary string.
+1
MAINTAINERS
··· 9662 9662 L: linux-pci@vger.kernel.org 9663 9663 S: Maintained 9664 9664 F: Documentation/switchtec.txt 9665 + F: Documentation/ABI/testing/sysfs-class-switchtec 9665 9666 F: drivers/pci/switch/switchtec* 9666 9667 9667 9668 PCI DRIVER FOR NVIDIA TEGRA
+113
drivers/pci/switch/switchtec.c
··· 486 486 mutex_unlock(&stdev->mrpc_mutex); 487 487 } 488 488 489 + static ssize_t device_version_show(struct device *dev, 490 + struct device_attribute *attr, char *buf) 491 + { 492 + struct switchtec_dev *stdev = to_stdev(dev); 493 + u32 ver; 494 + 495 + ver = ioread32(&stdev->mmio_sys_info->device_version); 496 + 497 + return sprintf(buf, "%x\n", ver); 498 + } 499 + static DEVICE_ATTR_RO(device_version); 500 + 501 + static ssize_t fw_version_show(struct device *dev, 502 + struct device_attribute *attr, char *buf) 503 + { 504 + struct switchtec_dev *stdev = to_stdev(dev); 505 + u32 ver; 506 + 507 + ver = ioread32(&stdev->mmio_sys_info->firmware_version); 508 + 509 + return sprintf(buf, "%08x\n", ver); 510 + } 511 + static DEVICE_ATTR_RO(fw_version); 512 + 513 + static ssize_t io_string_show(char *buf, void __iomem *attr, size_t len) 514 + { 515 + int i; 516 + 517 + memcpy_fromio(buf, attr, len); 518 + buf[len] = '\n'; 519 + buf[len + 1] = 0; 520 + 521 + for (i = len - 1; i > 0; i--) { 522 + if (buf[i] != ' ') 523 + break; 524 + buf[i] = '\n'; 525 + buf[i + 1] = 0; 526 + } 527 + 528 + return strlen(buf); 529 + } 530 + 531 + #define DEVICE_ATTR_SYS_INFO_STR(field) \ 532 + static ssize_t field ## _show(struct device *dev, \ 533 + struct device_attribute *attr, char *buf) \ 534 + { \ 535 + struct switchtec_dev *stdev = to_stdev(dev); \ 536 + return io_string_show(buf, &stdev->mmio_sys_info->field, \ 537 + sizeof(stdev->mmio_sys_info->field)); \ 538 + } \ 539 + \ 540 + static DEVICE_ATTR_RO(field) 541 + 542 + DEVICE_ATTR_SYS_INFO_STR(vendor_id); 543 + DEVICE_ATTR_SYS_INFO_STR(product_id); 544 + DEVICE_ATTR_SYS_INFO_STR(product_revision); 545 + DEVICE_ATTR_SYS_INFO_STR(component_vendor); 546 + 547 + static ssize_t component_id_show(struct device *dev, 548 + struct device_attribute *attr, char *buf) 549 + { 550 + struct switchtec_dev *stdev = to_stdev(dev); 551 + int id = ioread16(&stdev->mmio_sys_info->component_id); 552 + 553 + return sprintf(buf, "PM%04X\n", id); 554 + } 555 + static DEVICE_ATTR_RO(component_id); 556 + 557 + static ssize_t component_revision_show(struct device *dev, 558 + struct device_attribute *attr, char *buf) 559 + { 560 + struct switchtec_dev *stdev = to_stdev(dev); 561 + int rev = ioread8(&stdev->mmio_sys_info->component_revision); 562 + 563 + return sprintf(buf, "%d\n", rev); 564 + } 565 + static DEVICE_ATTR_RO(component_revision); 566 + 567 + static ssize_t partition_show(struct device *dev, 568 + struct device_attribute *attr, char *buf) 569 + { 570 + struct switchtec_dev *stdev = to_stdev(dev); 571 + 572 + return sprintf(buf, "%d\n", stdev->partition); 573 + } 574 + static DEVICE_ATTR_RO(partition); 575 + 576 + static ssize_t partition_count_show(struct device *dev, 577 + struct device_attribute *attr, char *buf) 578 + { 579 + struct switchtec_dev *stdev = to_stdev(dev); 580 + 581 + return sprintf(buf, "%d\n", stdev->partition_count); 582 + } 583 + static DEVICE_ATTR_RO(partition_count); 584 + 585 + static struct attribute *switchtec_device_attrs[] = { 586 + &dev_attr_device_version.attr, 587 + &dev_attr_fw_version.attr, 588 + &dev_attr_vendor_id.attr, 589 + &dev_attr_product_id.attr, 590 + &dev_attr_product_revision.attr, 591 + &dev_attr_component_vendor.attr, 592 + &dev_attr_component_id.attr, 593 + &dev_attr_component_revision.attr, 594 + &dev_attr_partition.attr, 595 + &dev_attr_partition_count.attr, 596 + NULL, 597 + }; 598 + 599 + ATTRIBUTE_GROUPS(switchtec_device); 600 + 489 601 static int switchtec_dev_open(struct inode *inode, struct file *filp) 490 602 { 491 603 struct switchtec_dev *stdev; ··· 846 734 device_initialize(dev); 847 735 dev->class = switchtec_class; 848 736 dev->parent = &pdev->dev; 737 + dev->groups = switchtec_device_groups; 849 738 dev->release = stdev_release; 850 739 851 740 minor = ida_simple_get(&switchtec_minor_ida, 0, 0,