DRAFT: New Microsemi PCI Switch Management Driver
Subsystems (4)
Logan Gunthorpe
maintainercover DRAFT: New Microsemi PCI Switch Management Driver
Hi,
This is a continuation of the RFC we posted lasted month [1] which proposes a management driver for Microsemi's Switchtec line of PCI switches. This hardware is still looking to be used in the Open Compute Platform
To make this entirely clear: the Switchtec products are compliant with the PCI specifications and are supported today with the standard in-kernel driver. However, these devices also expose a management endpoint on a separate PCI function address which can be used to perform some advanced operations. This is a driver for that function. See the patch for more information.
Since the RFC, we've made the changes requested by Greg Kroah-Hartman and Keith Busch, and we've also fleshed out a number of features. We've added a couple of IOCTLs and sysfs attributes which are documented in the patch. Significant work has also been done on the userspace tool which is available under a GPL license at [2]. We've also had testing done by some of the interested parties.
We hope to see this work included in either 4.11 or 4.12 assuming a smooth review process.
The patch is based off of the v4.9 release.
Thanks for your review,
Logan
[1] https://www.spinics.net/lists/linux-pci/msg56897.html
[2] https://github.com/sbates130272/switchtec-user
--
Changes since RFC:
* Fixed incorrect use of the drive model as pointed out by Greg Kroah-Hartman
* Used devm functions as suggested by Keith Busch
* Added a handful of sysfs attributes to the switchtec class
* Added a handful of IOCTLs to the switchtec device
* A number of miscelaneous bug fixes
--
Logan Gunthorpe (1):
MicroSemi Switchtec management interface driver
Documentation/ABI/testing/sysfs-class-switchtec | 96 ++ Documentation/ioctl/ioctl-number.txt | 1 + Documentation/switchtec.txt | 80 ++ MAINTAINERS | 11 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 1320 +++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 266 +++++ include/uapi/linux/switchtec_ioctl.h | 129 +++ 11 files changed, 1919 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-switchtec create mode 100644 Documentation/switchtec.txt create mode 100644 drivers/pci/switch/Kconfig create mode 100644 drivers/pci/switch/Makefile create mode 100644 drivers/pci/switch/switchtec.c create mode 100644 drivers/pci/switch/switchtec.h create mode 100644 include/uapi/linux/switchtec_ioctl.h
--
2.1.4
Logan Gunthorpe
maintainerPATCH 1/1 MicroSemi Switchtec management interface driver
Microsemi's "Switchtec" line of PCI switch devices is already well supported by the kernel with standard PCI switch drivers. However, the Switchtec device advertises a special management endpoint with a separate PCI function address and class code. This endpoint enables some additional functionality which includes:
* Packet and Byte Counters
* Switch Firmware Upgrades
* Event and Error logs
* Querying port link status
* Custom user firmware commands
This patch introduces the switchtec kernel module which provides PCI driver that exposes a char device. The char device provides userspace access to this interface through read, write and (optionally) poll calls. A couple of special IOCTLs are provided to:
* Inform userspace of firmware partition locations
* Pass event counts and allow userspace to wait on events
A short text file is provided which documents the switchtec driver, outlines the semantics of using the char device and describes the IOCTLs.
The device also exposes a few read-only sysfs attributes which provide some device information component names and versions which is provided by the hardware. These are documented in Documentation/ABI/testing/sysfs-class-switchtec
A userspace tool and library which utilizes this interface is available at [1]. This tool takes inspiration (and borrows some code) from nvme-cli [2]. The tool is largely complete at this time but additional features may be added in the future.
[1] https://github.com/sbates130272/switchtec-user
[2] https://github.com/linux-nvme/nvme-cli
--- Documentation/ABI/testing/sysfs-class-switchtec | 96 ++ Documentation/ioctl/ioctl-number.txt | 1 + Documentation/switchtec.txt | 80 ++ MAINTAINERS | 11 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 1320 +++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 266 +++++ include/uapi/linux/switchtec_ioctl.h | 129 +++ 11 files changed, 1919 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-switchtec create mode 100644 Documentation/switchtec.txt create mode 100644 drivers/pci/switch/Kconfig create mode 100644 drivers/pci/switch/Makefile create mode 100644 drivers/pci/switch/switchtec.c create mode 100644 drivers/pci/switch/switchtec.h create mode 100644 include/uapi/linux/switchtec_ioctl.h
Documentation/ABI/testing/sysfs-class-switchtec new file +96 -0
@@ -0,0 +1,96 @@ +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 at 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 at deltatee.com> +Description: Component identifier as stored in the hardware (eg. PM4385) + (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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at deltatee.com> +Description: Product vendor as stored in the hardware (eg. MICROSEM) + (read only) +Values: arbitrary string.
Documentation/ioctl/ioctl-number.txt +1 -0
@@ -191,6 +191,7 @@ Code Seq#(hex) Include File Comments 'W' 00-1F linux/watchdog.h conflict! 'W' 00-1F linux/wanrouter.h conflict! (pre 3.9) 'W' 00-3F sound/asound.h conflict! +'W' 40-5F drivers/pci/switch/switchtec.c 'X' all fs/xfs/xfs_fs.h conflict! and fs/xfs/linux-2.6/xfs_ioctl32.h and include/linux/falloc.h
Documentation/switchtec.txt new file +80 -0
80 lines not on this page · raw message
MAINTAINERS +11 -0
@@ -9288,6 +9288,17 @@ S: Maintained F: Documentation/devicetree/bindings/pci/aardvark-pci.txt F: drivers/pci/host/pci-aardvark.c +PCI DRIVER FOR MICROSEMI SWITCHTEC +M: Kurt Schwemmer <kurt.schwemmer at microsemi.com> +M: Stephen Bates <stephen.bates at microsemi.com> +M: Logan Gunthorpe <logang at deltatee.com> +L: linux-pci at vger.kernel.org +S: Maintained +F: Documentation/switchtec.txt +F: Documentation/ABI/testing/sysfs-class-switchtec +F: drivers/pci/switch/switchtec* +F: include/uapi/linux/switchtec_ioctl.h + PCI DRIVER FOR NVIDIA TEGRA M: Thierry Reding <thierry.reding at gmail.com> L: linux-tegra at vger.kernel.org
drivers/pci/Kconfig +1 -0
@@ -133,3 +133,4 @@ config PCI_HYPERV source "drivers/pci/hotplug/Kconfig" source "drivers/pci/host/Kconfig" +source "drivers/pci/switch/Kconfig"
drivers/pci/Makefile +1 -0
@@ -68,3 +68,4 @@ ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG # PCI host controller drivers obj-y += host/ +obj-y += switch/
drivers/pci/switch/Kconfig new file +13 -0
@@ -0,0 +1,13 @@ +menu "PCI switch controller drivers" + depends on PCI + +config PCI_SW_SWITCHTEC + tristate "MicroSemi Switchtec PCIe Switch Management Driver" + help + Enables support for the management interface for the MicroSemi + Switchtec series of PCIe switches. Supports userspace access + to submit MRPC commands to the switch via /dev/switchtecX + devices. See <file:Documentation/switchtec.txt> for more + information. + +endmenu
drivers/pci/switch/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_PCI_SW_SWITCHTEC) += switchtec.o
drivers/pci/switch/switchtec.c new file +1320 -0
1,320 lines not on this page · raw message
drivers/pci/switch/switchtec.h new file +266 -0
266 lines not on this page · raw message
include/uapi/linux/switchtec_ioctl.h new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH 1/1] MicroSemi Switchtec management interface driver
Quoted 39 lines · Logan Gunthorpe
Microsemi's "Switchtec" line of PCI switch devices is already well supported by the kernel with standard PCI switch drivers. However, the Switchtec device advertises a special management endpoint with a separate PCI function address and class code. This endpoint enables some additional functionality which includes:
* Packet and Byte Counters
* Switch Firmware Upgrades
* Event and Error logs
* Querying port link status
* Custom user firmware commandsThis patch introduces the switchtec kernel module which provides PCI driver that exposes a char device. The char device provides userspace access to this interface through read, write and (optionally) poll calls. A couple of special IOCTLs are provided to:
* Inform userspace of firmware partition locations
* Pass event counts and allow userspace to wait on eventsA short text file is provided which documents the switchtec driver, outlines the semantics of using the char device and describes the IOCTLs.
The device also exposes a few read-only sysfs attributes which provide some device information component names and versions which is provided by the hardware. These are documented in
Documentation/ABI/testing/sysfs-class-switchtecA userspace tool and library which utilizes this interface is available at [1]. This tool takes inspiration (and borrows some code) from nvme-cli [2]. The tool is largely complete at this time but additional features may be added in the future.
[1] https://github.com/sbates130272/switchtec-user
[2] https://github.com/linux-nvme/nvme-cliSigned-off-by Logan Gunthorpe <logang at deltatee.com>Signed-off-by Stephen Bates <stephen.bates at microsemi.com>
Quoted 13 lines
--- Documentation/ABI/testing/sysfs-class-switchtec | 96 ++ Documentation/ioctl/ioctl-number.txt | 1 + Documentation/switchtec.txt | 80 ++ MAINTAINERS | 11 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 1320 +++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 266 +++++ include/uapi/linux/switchtec_ioctl.h | 129 +++ 11 files changed, 1919 insertions(+)
That's one big patch to review, would you want to do that?
Can you break it up into smaller parts? At least put the documentation separately, right?
And don't dump a .txt file into Documentation/ anymore, people are working to move to the newer format.
Also, please rebase against Linus's tree at the least, we can't go back in time and apply this to the 4.9 kernel tree.
thanks,
greg k-h
Re: [PATCH 1/1] MicroSemi Switchtec management interface driver
In reply to Logan GunthorpeQuoted 39 lines · Logan Gunthorpe
Microsemi's "Switchtec" line of PCI switch devices is already well supported by the kernel with standard PCI switch drivers. However, the Switchtec device advertises a special management endpoint with a separate PCI function address and class code. This endpoint enables some additional functionality which includes:
* Packet and Byte Counters
* Switch Firmware Upgrades
* Event and Error logs
* Querying port link status
* Custom user firmware commandsThis patch introduces the switchtec kernel module which provides PCI driver that exposes a char device. The char device provides userspace access to this interface through read, write and (optionally) poll calls. A couple of special IOCTLs are provided to:
* Inform userspace of firmware partition locations
* Pass event counts and allow userspace to wait on eventsA short text file is provided which documents the switchtec driver, outlines the semantics of using the char device and describes the IOCTLs.
The device also exposes a few read-only sysfs attributes which provide some device information component names and versions which is provided by the hardware. These are documented in
Documentation/ABI/testing/sysfs-class-switchtecA userspace tool and library which utilizes this interface is available at [1]. This tool takes inspiration (and borrows some code) from nvme-cli [2]. The tool is largely complete at this time but additional features may be added in the future.
[1] https://github.com/sbates130272/switchtec-user
[2] https://github.com/linux-nvme/nvme-cliSigned-off-by Logan Gunthorpe <logang at deltatee.com>Signed-off-by Stephen Bates <stephen.bates at microsemi.com>
Quoted 11 lines
--- Documentation/ABI/testing/sysfs-class-switchtec | 96 ++ Documentation/ioctl/ioctl-number.txt | 1 + Documentation/switchtec.txt | 80 ++ MAINTAINERS | 11 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 1320 +++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 266 +++++
Why a .h file for a single .c file?
Also, why a whole new directory?
thanks,
greg k-h
Logan Gunthorpe
maintainerRe: [PATCH 1/1] MicroSemi Switchtec management interface driver
In reply to Greg Kroah-HartmanQuoted 1 line · Greg Kroah-Hartman
That's one big patch to review, would you want to do that?
Sorry, will do.
Quoted 2 lines
Can you break it up into smaller parts? At least put the documentation separately, right?
Ha, funny. Last time I sent a patch someone asked for the documentation to be in the same patch. But I can easily split this up.
Quoted 2 lines
And don't dump a .txt file into
Documentation/anymore, people are working to move to the newer format.
Fair. I wasn't sure where a good place to put it was. Any suggestions?
Quoted 2 lines
Also, please rebase against Linus's tree at the least, we can't go back in time and apply this to the 4.9 kernel tree.
Will do.
Quoted 1 line
Why a .h file for a single .c file?
I wanted to keep the hardware defining structs and macros in a separate file for future expansion. This hardware is also capable of some NTB functions which may find it's way into the kernel in the future.
Quoted 1 line
Also, why a whole new directory?
We didn't feel it fit in the pci director which was for standard pci stuff. We're more than open to other suggestions as to where this code belongs.
Thanks,
Logan
Jonathan Corbet
maintainerRe: [PATCH 1/1] MicroSemi Switchtec management interface driver
Quoted 4 lines · On Tue, 31 Jan 2017 10:35:44 -0700 Logan Gunthorpe <[email protected]> wrote:
Quoted 2 lines
And don't dump a .txt file into
Documentation/anymore, people are working to move to the newer format.Fair. I wasn't sure where a good place to put it was. Any suggestions?
We're working toward a rational document hierarchy using the sphinx system:
https://lwn.net/Articles/692704/ https://lwn.net/Articles/692704/ https://static.lwn.net/kerneldoc/doc-guide/index.html
The good news is that your switchtec.txt file is already 99% in the RST format, so there is little or nothing to do there.
The bad news is that we don't quite have a place for it yet. This is really user-space developer documentation, and we don't have a sub-book for that. I expect that to change pretty soon, and I might even toss together a bare beginning for 4.11, but that hasn't happened yet.
If you would like to learn the ropes and make one, that would be more than great :) Alternatively, I'd suggest just leaving the document as-is, and I'll put it toward the top of the list of things to move into place once I get that book started.
Thanks,
jon
kbuild test robot
build botRe: [PATCH 1/1] MicroSemi Switchtec management interface driver
In reply to Logan Gunthorpereproduce:
Hi Logan,
[auto build test ERROR on pci/next]
[also build test ERROR on v4.10-rc6 next-20170130]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Logan-Gunthorpe/MicroSemi-Switchtec-management-interface-driver/20170201-011235 base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next config: i386-allmodconfig (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=i386
All error/warnings (new ones prefixed by >>):
drivers/pci/switch/switchtec.c: In function 'stdev_is_alive':
>> drivers/pci/switch/switchtec.c:120:14: warning: return makes integer from pointer without a cast [-Wint-conversion]
return stdev->mmio;
~~~~~^~~~~~
drivers/pci/switch/switchtec.c: In function 'switchtec_init_msi_isr':
>> drivers/pci/switch/switchtec.c:1075:7: error: implicit declaration of function 'pci_enable_msi_range' [-Werror=implicit-function-declaration]
rc = pci_enable_msi_range(pdev, 1, 4);
^~~~~~~~~~~~~~~~~~~~
drivers/pci/switch/switchtec.c: In function 'switchtec_dev_ioctl':
>> drivers/pci/switch/switchtec.c:758:3: warning: 'nr_idxs' may be used uninitialized in this function [-Wmaybe-uninitialized]
for (ctl.index = 0; ctl.index < nr_idxs; ctl.index++) {
^~~
drivers/pci/switch/switchtec.c:741:6: note: 'nr_idxs' was declared here
int nr_idxs;
^~~~~~~
drivers/pci/switch/switchtec.c: In function 'switchtec_pci_probe':
>> drivers/pci/switch/switchtec.c:1174:50: warning: 'partition' may be used uninitialized in this function [-Wmaybe-uninitialized]
stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[partition];
^
drivers/pci/switch/switchtec.c:1153:6: note: 'partition' was declared here
int partition;
^~~~~~~~~cc1: some warnings being treated as errors
vim +/pci_enable_msi_range +1075 drivers/pci/switch/switchtec.c
1069 static int switchtec_init_msi_isr(struct switchtec_dev *stdev)
1070 {
1071 int rc;
1072 struct pci_dev *pdev = stdev->pdev;
1073
1074 /* Try to set up msi irq */
> 1075 rc = pci_enable_msi_range(pdev, 1, 4);
1076 if (rc < 0)
1077 return rc;
1078
1079 stdev->event_irq = ioread32(&stdev->mmio_part_cfg->vep_vector_number);
1080 if (stdev->event_irq < 0 || stdev->event_irq >= 4) {
1081 rc = -EFAULT;
1082 goto err_msi_request;
1083 }
1084
1085 stdev->event_irq = pdev->irq + stdev->event_irq;
1086 dev_dbg(&stdev->dev, "Using msi interrupts: event_irq=%d\n",
1087 stdev->event_irq);
1088
1089 return 0;
1090
1091 err_msi_request:
1092 pci_disable_msi(pdev);
1093 return rc;
1094 }
1095
1096 static int switchtec_init_isr(struct switchtec_dev *stdev)
1097 {
1098 int rc;
1099
1100 rc = switchtec_init_msix_isr(stdev);
1101 if (rc)
1102 rc = switchtec_init_msi_isr(stdev);
1103
1104 if (rc)
1105 return rc;
1106
1107 rc = devm_request_irq(&stdev->pdev->dev, stdev->event_irq,
1108 switchtec_event_isr, 0, KBUILD_MODNAME, stdev);
1109
1110 return rc;
1111 }
1112
1113 static void switchtec_deinit_isr(struct switchtec_dev *stdev)
1114 {
1115 devm_free_irq(&stdev->pdev->dev, stdev->event_irq, stdev);
1116 pci_disable_msix(stdev->pdev);
1117 pci_disable_msi(stdev->pdev);
1118 }
1119
1120 static void init_pff(struct switchtec_dev *stdev)
1121 {
1122 int i;
1123 u32 reg;
1124 struct part_cfg_regs *pcfg = stdev->mmio_part_cfg;
1125
1126 for (i = 0; i < SWITCHTEC_MAX_PFF_CSR; i++) {
1127 reg = ioread16(&stdev->mmio_pff_csr[i].vendor_id);
1128 if (reg != MICROSEMI_VENDOR_ID)
1129 break;
1130 }
1131
1132 stdev->pff_csr_count = i;
1133
1134 reg = ioread32(&pcfg->usp_pff_inst_id);
1135 if (reg < SWITCHTEC_MAX_PFF_CSR)
1136 stdev->pff_local[reg] = 1;
1137
1138 reg = ioread32(&pcfg->vep_pff_inst_id);
1139 if (reg < SWITCHTEC_MAX_PFF_CSR)
1140 stdev->pff_local[reg] = 1;
1141
1142 for (i = 0; i < ARRAY_SIZE(pcfg->dsp_pff_inst_id); i++) {
1143 reg = ioread32(&pcfg->dsp_pff_inst_id[i]);
1144 if (reg < SWITCHTEC_MAX_PFF_CSR)
1145 stdev->pff_local[reg] = 1;
1146 }
1147 }
1148
1149 static int switchtec_init_pci(struct switchtec_dev *stdev,
1150 struct pci_dev *pdev)
1151 {
1152 int rc;
1153 int partition;
1154
1155 rc = pcim_enable_device(pdev);
1156 if (rc)
1157 return rc;
1158
1159 rc = pcim_iomap_regions(pdev, 0x1, KBUILD_MODNAME);
1160 if (rc)
1161 return rc;
1162
1163 pci_set_master(pdev);
1164
1165 stdev->mmio = pcim_iomap_table(pdev)[0];
1166 stdev->mmio_mrpc = stdev->mmio + SWITCHTEC_GAS_MRPC_OFFSET;
1167 stdev->mmio_sw_event = stdev->mmio + SWITCHTEC_GAS_SW_EVENT_OFFSET;
1168 stdev->mmio_sys_info = stdev->mmio + SWITCHTEC_GAS_SYS_INFO_OFFSET;
1169 stdev->mmio_flash_info = stdev->mmio + SWITCHTEC_GAS_FLASH_INFO_OFFSET;
1170 stdev->mmio_ntb = stdev->mmio + SWITCHTEC_GAS_NTB_OFFSET;
1171 stdev->partition = ioread8(&stdev->mmio_ntb->partition_id);
1172 stdev->partition_count = ioread8(&stdev->mmio_ntb->partition_count);
1173 stdev->mmio_part_cfg_all = stdev->mmio + SWITCHTEC_GAS_PART_CFG_OFFSET;
> 1174 stdev->mmio_part_cfg = &stdev->mmio_part_cfg_all[partition]; 1175 stdev->mmio_pff_csr = stdev->mmio + SWITCHTEC_GAS_PFF_CSR_OFFSET;
1176
1177 init_pff(stdev);
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .config.gz
Type: application/gzip
Size: 57993 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-nvme/attachments/20170201/1791c455/attachment-0001.gz>
Logan Gunthorpe
maintainerRe: [PATCH 1/1] MicroSemi Switchtec management interface driver
In reply to Jonathan CorbetQuoted 8 lines · Jonathan Corbet
The good news is that your switchtec.txt file is already 99% in the RST format, so there is little or nothing to do there.
The bad news is that we don't quite have a place for it yet. This is really user-space developer documentation, and we don't have a sub-book for that. I expect that to change pretty soon, and I might even toss together a bare beginning for 4.11, but that hasn't happened yet.
Quoted 4 lines
If you would like to learn the ropes and make one, that would be more than great :) Alternatively, I'd suggest just leaving the document as-is, and I'll put it toward the top of the list of things to move into place once I get that book started.
Thanks Jon. I took a look at the documentation and it doesn't look too difficult. But I don't really feel qualified to make some of the decisions necessary to create the new book. (ie names, locations, etc.) And I don't really want that churn in this patchset. So we'll leave it where it is for now.
I have cleaned up some of the RST format for v2 though.
Logan
Re: [PATCH 1/1] MicroSemi Switchtec management interface driver
In reply to Logan GunthorpeQuoted 5 lines · Logan Gunthorpe
Quoted 1 line · Greg Kroah-Hartman
That's one big patch to review, would you want to do that?
Quoted 7 lines
Sorry, will do.
Quoted 2 lines
Can you break it up into smaller parts? At least put the documentation separately, right?
Ha, funny. Last time I sent a patch someone asked for the documentation to be in the same patch. But I can easily split this up.
Sorry, it was probably me :)
Quoted 4 lines
Quoted 2 lines
And don't dump a .txt file into
Documentation/anymore, people are working to move to the newer format.Fair. I wasn't sure where a good place to put it was. Any suggestions?
Why do you need this? Wherever you put it, it should be built as part of the online kernel documentation. Who is the audience for this documentation?
Quoted 10 lines
Quoted 2 lines
Also, please rebase against Linus's tree at the least, we can't go back in time and apply this to the 4.9 kernel tree.
Will do.
Quoted 1 line
Why a .h file for a single .c file?
I wanted to keep the hardware defining structs and macros in a separate file for future expansion. This hardware is also capable of some NTB functions which may find it's way into the kernel in the future.
Do future stuff in the future, no need for that now, right?
Simple is best.
Quoted 5 lines
Quoted 1 line
Also, why a whole new directory?
We didn't feel it fit in the pci director which was for standard pci stuff. We're more than open to other suggestions as to where this code belongs.
I'll leave that up to the PCI maintainer, but just a single .c file in a subdir seems odd to me.
thanks,
greg k-h
Logan Gunthorpe
maintainerRe: [PATCH 1/1] MicroSemi Switchtec management interface driver
Quoted 1 line · Greg Kroah-Hartman
Sorry, it was probably me :)
Nope, it was Christoph Hellwig. I don't mind changing it. It's just hard to know what's expected all the time.
Quoted 3 lines
Why do you need this? Wherever you put it, it should be built as part of the online kernel documentation. Who is the audience for this documentation?
Well usually documenting how to use the device is a good thing. Is it not? The audience would be people wanting to make use of the userspace interface. Though in fairness, the vast majority of people should use our library. I also thought it would be useful to reviewers to more quickly understand the interface we are creating. If maintainers want us to leave it out, we can, but that seems like an odd request.
Quoted 3 lines
Do future stuff in the future, no need for that now, right?
Simple is best.
Ok, I can push it all into the C file for v2.
Quoted 2 lines
I'll leave that up to the PCI maintainer, but just a single .c file in a subdir seems odd to me.
Thanks,
Logan
Re: [PATCH 1/1] MicroSemi Switchtec management interface driver
In reply to Logan GunthorpeHi Logan,
NOTE: Please take my comments with a healthy pinch of salt.
I'd imagine that core/more experienced developers have more thorough feedback, so I'll mention a few things on the less common part - robust/compat UABI.
Above all, please read through the in-tree documentation on the topic [1]
include/uapi/linux/switchtec_ioctl.h line 36
Quoted 8 lines · Logan Gunthorpe
include/uapi/linux/switchtec_ioctl.h new file +3
-0+enum switchtec_ioctl_partition { +SWITCHTEC_IOCTL_NUM_PARTITIONS , +};
I'm not sure what the overall consensus on the topic of 'enums vs defines in UABI'. Fwiw personally I'm in favour of defines since enums can lead to subtle issues if one is not extra careful. For example:
- add new enum amidst the list - ABI break
- add new enum at the end of the list [just before NUM_PARTITIONS] - ABI break.
- opt for negative value for existing/new enum - ABI break
- other
With a variable size in mind, carefully consider how you'll copy data back and forth in the case of new kernel (supports partition[X) + old userspace (partition [X-1]) and vice-versa. Feel free to look at the drm ioctl handler and/or others through the kernel.
Hint - as-is we'll end up with buffer overflows/other issues.
include/uapi/linux/switchtec_ioctl.h line 44
Quoted 8 lines
include/uapi/linux/switchtec_ioctl.h new file +8
-0+ +struct switchtec_ioctl_fw_info { +__u32 flash_length; + +struct { +__u32 address; +__u32 length; +__u32 active;
Something to keep in mind, not sure how likely it is here:
If you embed structs (partition in this case), you will not be able to extend it [the embedded one] it in the future without the risk of ABI breakage.
include/uapi/linux/switchtec_ioctl.h line 47
Quoted 3 lines
include/uapi/linux/switchtec_ioctl.h new file +3
-0+ } partition[SWITCHTEC_IOCTL_NUM_PARTITIONS ]; +}; +
Afaict this and most/all other structs [in this patch] are in violation of Prerequisites#2 and/or #3.
Personally I find pahole quite useful - reference all the UABI structs in a dummy userspace app, compile with gcc -g -O0 and observe the output across 32 and 64bit builds. Members _must_ be at the same offset, otherwise things will be broken with 64bit kernel on a 32bit userspace. Something which people will eventually end up trying/using, even if you don't plan to support it.
Please check that Basics (#2 and #5 in particular) are also covered.
A couple more generic suggestions, which I may have noticed while skimming through:
- please ensure that all the input is properly sanitised, before,
going into the actual implementation
Afaict having the separate step/separation helps clarity and reduces chances of you/others getting it wrong down the line.
- user provided storage must not be changed when the ioctl fails.
Additionally you want to provide a reference to open-source userspace [alongside acknowledgement of the maintainers/co-developers about the design] which makes use of said IOCTL(s). But please, do _not_ merge userspace code before the kernel work has landed.
Hope that provided you with sufficient good points wrt IOCTL design.
Regards,
Emil
Logan Gunthorpe
maintainerRe: [PATCH 1/1] MicroSemi Switchtec management interface driver
Hi Emil,
Thanks for the feedback.
Quoted 11 lines · Emil Velikov
include/uapi/linux/switchtec_ioctl.h line 44
Quoted 7 lines
include/uapi/linux/switchtec_ioctl.h new file +7
-0+struct switchtec_ioctl_fw_info { +__u32 flash_length; + +struct { +__u32 address; +__u32 length; +__u32 active;Something to keep in mind, not sure how likely it is here:
If you embed structs (partition in this case), you will not be able to extend it [the embedded one] it in the future without the risk of ABI breakage.
Based on this feedback, I'll rework the fw_info IOCTL so the user only requests one partition at a time. This will get rid of the embedded struct and any concerns about size changes. I was originally trying to make the ioctl RO to make it simpler but that maybe isn't the case.
Quoted 11 lines
include/uapi/linux/switchtec_ioctl.h line 47
Quoted 3 lines
include/uapi/linux/switchtec_ioctl.h new file +3
-0+ } partition[SWITCHTEC_IOCTL_NUM_PARTITIONS ]; +}; +Afaict this and most/all other structs [in this patch] are in violation of Prerequisites#2 and/or #3.
Personally I find pahole quite useful - reference all the UABI structs in a dummy userspace app, compile with gcc -g -O0 and observe the output across 32 and 64bit builds. Members _must_ be at the same offset, otherwise things will be broken with 64bit kernel on a 32bit userspace. Something which people will eventually end up trying/using, even if you don't plan to support it.
I've made some changes to the padding and sizes to accommodate this. I'll also do some testing with pahole before v2.
Quoted 3 lines
Please check that Basics (#2 and #5 in particular) are also covered.
then you need a driver feature flag or revision number somewhere.
We don't have this specifically. A new version ioctl could be added later when and if changes occur; or the userspace code could easily read the module version through sysfs and we could increment that with ioctl changes.
Quoted 6 lines
A couple more generic suggestions, which I may have noticed while skimming through:
- please ensure that all the input is properly sanitised, before,
going into the actual implementation
Afaict having the separate step/separation helps clarity and reduces chances of you/others getting it wrong down the line.
The inputs are indeed properly checked in the code. Most of the ioctls that take inputs are so simple it's hard to separate the two steps. ie. Verifying that the input is right pretty much gives you the answer you need to send back to userspace.
Quoted 1 line
- user provided storage must not be changed when the ioctl fails.
This should already be true.
Quoted 4 lines
Additionally you want to provide a reference to open-source userspace [alongside acknowledgement of the maintainers/co-developers about the design] which makes use of said IOCTL(s). But please, do _not_ merge userspace code before the kernel work has landed.
I'm having trouble understanding what you're asking here. We provided a reference to the userspace code in the commit message. Currently the userspace code is completely useless without the kernel module and it is entirely independent of other projects. I'm also the only committer so far on the userspace code. So I assume this only applies if we were merging changes to other existing code?
Quoted 1 line
Hope that provided you with sufficient good points wrt IOCTL design.
Thanks, this was very helpful.
Logan
Re: [PATCH 1/1] MicroSemi Switchtec management interface driver
Quoted 17 lines · Logan Gunthorpe
Hi Emil,
Thanks for the feedback.
Quoted 11 lines · Emil Velikov
include/uapi/linux/switchtec_ioctl.h line 44
Quoted 7 lines
include/uapi/linux/switchtec_ioctl.h new file +7
-0+struct switchtec_ioctl_fw_info { +__u32 flash_length; + +struct { +__u32 address; +__u32 length; +__u32 active;Something to keep in mind, not sure how likely it is here:
If you embed structs (partition in this case), you will not be able to extend it [the embedded one] it in the future without the risk of ABI breakage.
Quoted 5 lines
Based on this feedback, I'll rework the
fw_infoIOCTL so the user only requests one partition at a time. This will get rid of the embedded struct and any concerns about size changes. I was originally trying to make the ioctl RO to make it simpler but that maybe isn't the case.
You can keep it roughly as-is if you're ~reasonably certain one won't change it in the future.
Quoted 7 lines
Quoted 1 line
then you need a driver feature flag or revision number somewhere.
We don't have this specifically. A new version ioctl could be added later when and if changes occur; or the userspace code could easily read the module version through sysfs and we could increment that with ioctl changes.
Some teams frown upon adding new IOCTL(s) where existing ones can be made backward/forward compatible.
I'm not fully aware of the general direction/consensus on the topic, so it might be a minority.
On the other hand, reading through sysfs for module version in order to use IOCTL A or B sounds quite hacky. Do you have an example where this is used or pointed out as good approach ?
Quoted 7 lines
Quoted 6 lines
A couple more generic suggestions, which I may have noticed while skimming through:
- please ensure that all the input is properly sanitised, before,
going into the actual implementation
Afaict having the separate step/separation helps clarity and reduces chances of you/others getting it wrong down the line.
Quoted 9 lines
The inputs are indeed properly checked in the code. Most of the ioctls that take inputs are so simple it's hard to separate the two steps. ie. Verifying that the input is right pretty much gives you the answer you need to send back to userspace.
Quoted 1 line
- user provided storage must not be changed when the ioctl fails.
This should already be true.
You're spot on [for both points]. I must have imagined something.
Quoted 5 lines
Quoted 4 lines
Additionally you want to provide a reference to open-source userspace [alongside acknowledgement of the maintainers/co-developers about the design] which makes use of said IOCTL(s). But please, do _not_ merge userspace code before the kernel work has landed.
Quoted 7 lines
I'm having trouble understanding what you're asking here. We provided a reference to the userspace code in the commit message. Currently the userspace code is completely useless without the kernel module and it is entirely independent of other projects. I'm also the only committer so far on the userspace code. So I assume this only applies if we were merging changes to other existing code?
Yes, I'm blind - you have links to the userspace.
Afaict the idea is to not ship/bundle/release userspace until kernel parts are in.
The "do not commit the changes" is implied as [very rarely] distros package from "random" git checkouts. Leading to all sorts of fun when it is mismatched wrt the kernel parts. Likelihood of doing that here is virtually none here, so this is a JFYI inspired by some past experiences.
Quoted 4 lines
Quoted 1 line
Hope that provided you with sufficient good points wrt IOCTL design.
Thanks, this was very helpful.
Glad to hear. Then again you already had most of the things nicely done, imho.
-Emil
Logan Gunthorpe
maintainerRe: [PATCH 1/1] MicroSemi Switchtec management interface driver
Quoted 2 lines · Emil Velikov
You can keep it roughly as-is if you're ~reasonably certain one won't change it in the future.
I've made the change anyway. I think it's better now.
Quoted 4 lines
Some teams frown upon adding new IOCTL(s) where existing ones can be made backward/forward compatible.
I'm not fully aware of the general direction/consensus on the topic, so it might be a minority.
Sure, I just don't know what might be needed in the future so it's hard to add a version or flags ioctl now.
Quoted 3 lines
On the other hand, reading through sysfs for module version in order to use IOCTL A or B sounds quite hacky. Do you have an example where this is used or pointed out as good approach ?
I don't know of anything doing it that way now. But it sure would be easy and make a bit of sense. (We'd actually use the module version for something useful.) Either way, it would really depend on if and how things change in the future. The point is there are options to expand if needed.
Quoted 7 lines
Afaict the idea is to not ship/bundle/release userspace until kernel parts are in.
The "do not commit the changes" is implied as [very rarely] distros package from "random" git checkouts. Leading to all sorts of fun when it is mismatched wrt the kernel parts. Likelihood of doing that here is virtually none here, so this is a JFYI inspired by some past experiences.
Understood.
Quoted 1 line
Glad to hear. Then again you already had most of the things nicely done, imho.
Great, thanks.
Logan
Re: [PATCH 1/1] MicroSemi Switchtec management interface driver
Quoted 8 lines · Logan Gunthorpe
Quoted 2 lines · Emil Velikov
You can keep it roughly as-is if you're ~reasonably certain one won't change it in the future.
I've made the change anyway. I think it's better now.
Quoted 8 lines
Quoted 4 lines
Some teams frown upon adding new IOCTL(s) where existing ones can be made backward/forward compatible.
I'm not fully aware of the general direction/consensus on the topic, so it might be a minority.Sure, I just don't know what might be needed in the future so it's hard to add a version or flags ioctl now.
Yes knowing how things will need to change in the is hard. That's why the documentation suggestions adding a flag to the ioctl structs. It [the flag] might imply certain functional/implementation change, support for new/deprecation of old features and others.
Quoted 10 lines
Quoted 3 lines
On the other hand, reading through sysfs for module version in order to use IOCTL A or B sounds quite hacky. Do you have an example where this is used or pointed out as good approach ?
I don't know of anything doing it that way now. But it sure would be easy and make a bit of sense. (We'd actually use the module version for something useful.) Either way, it would really depend on if and how things change in the future. The point is there are options to expand if needed.
The part that nobody else is doing such a thing should ring a bell ;-)
It's no my call, but if it was I'd stick with the existing approach and not "reinvent the wheel" sort of speak.
Thanks
Emil