New PCI Switch Management Driver
Subsystems (4)
Logan Gunthorpe
maintainercover New PCI Switch Management Driver
Hi,
[Appologies: this is a resend for some people. Due to a configuration error the original email was rejected by the mailing lists. I hope this one makes it!]
We're looking to get some initial feedback on a new driver for a line of PCIe switches produced and produced and sold by Microsemi. The goal is to get the process moving to get this code included in upstream hopefully for 4.11. Facebook is currently gearing up to use this hardware in its Open Compute Platform and is pushing to have this driver in the upstream kernel.
The following patch briefly describes the hardware and provides the first draft of driver code. Currently, the driver works and has been tested but is not feature complete. Thus, we are not looking to get it merged immediately. However we would like some early review, specifically on the interfaces and core concepts so that we don't do a lot of work down a path the community would reject. Barring any objections to this RFC, we will flesh out all the features and provide a completed patch for inclusion in the coming weeks.
Work on a userspace tool, that utilizes this driver, is also being done at [1]. The tool is currently also a bit of a skeleton and will be fleshed out assuming there are no serious objections to our userspace interface. In the end, the tool will be released with a GPL license.
The patch is based off of the v4.9 release.
Thanks for your review,
Logan
[1] https://github.com/sbates130272/switchtec-user
Logan Gunthorpe (1):
MicroSemi Switchtec management interface driver
Documentation/switchtec.txt | 54 +++ MAINTAINERS | 9 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 824 +++++++++++++++++++++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 119 ++++++ 8 files changed, 1022 insertions(+) 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
--
2.1.4
Logan Gunthorpe
maintainerRFC 1/1 MicroSemi Switchtec management interface driver
Microsemi's "Switchtec" line of PCI switch devices is already supported by the kernel with standard PCI switch drivers. However, the Switchtec device advertises a special management endpoint which enables some additional functionality. This includes:
* Packet and Byte Counters
* 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. Currently no ioctls have been implemented but a couple may be added in a later revision.
A short text file is provided which documents the switchtec driver and outlines the semantics of using the char device.
A WIP userspace tool which utilizes this interface is available at [1]. This tool takes
inspiration (and borrows some code) from nvme-cli [2].
[1] https://github.com/sbates130272/switchtec-user
[2] https://github.com/linux-nvme/nvme-cli
--- Documentation/switchtec.txt | 54 +++ MAINTAINERS | 9 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 824 +++++++++++++++++++++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 119 ++++++ 8 files changed, 1022 insertions(+) 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
Documentation/switchtec.txt new file +54 -0
@@ -0,0 +1,54 @@ + +Linux Switchtec Support +======================== + +Microsemi's "Switchtec" line of PCI switch devices is already +supported by the kernel with standard PCI switch drivers. However, the +Switchtec device advertises a special management endpoint which +enables some additional functionality. This includes: + + * Packet and Byte Counters + * Firmware Upgrades + * Event and Error logs + * Querying port link status + * Custom user firmware commands + +The switchtec kernel module implements this functionality. + + + +Interface +========= + +The primary means of communicating with the Switchtec management firmware is +through the Memory-mapped Remote Procedure Call (MRPC) interface. +Commands are submitted to the interface with a 4-byte command +identifier and up to 1KB of command specific data. The firmware will +respond with a 4 bytes return code and up to 1KB of command specific +data. The interface only processes a single command at a time. + + +Userspace Interface +=================== + +The MRPC interface will be exposed to userspace through a simple char +device: /dev/switchtec#, one for each management endpoint in the system. + +The char device has the following semantics: + + * A write must consist of at least 4 bytes and no more than 1028 bytes. + The first four bytes will be interpreted as the command to run and + the remainder will be used as the input data. A write will send the + command to the firmware to begin processing. + + * Each write must be followed by exactly one read. Any double write will + produce an error and any read that doesn't follow a write will + produce an error. + + * A read will block until the firmware completes the command and return + the four bytes of status plus up to 1024 bytes of output data. (The + length will be specified by the size parameter of the read call -- + reading less than 4 bytes will produce an error. + + * The poll call will also be supported for userspace applications that + need to do other things while waiting for the command to complete.
MAINTAINERS +9 -0
@@ -9288,6 +9288,15 @@ 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: drivers/pci/switch/switchtec* + 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 +824 -0
824 lines not on this page · raw message
drivers/pci/switch/switchtec.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [RFC 1/1] MicroSemi Switchtec management interface driver
drivers/pci/switch/switchtec.h line 94
Quoted 5 lines · Logan Gunthorpe
drivers/pci/switch/switchtec.h new file +5
-0+struct switchtec_dev { +struct pci_dev *pdev; +struct msix_entry *msix; +struct device *dev; +struct kref kref;
Why do you have a pointer to a device, yet a kref as well? Just have this structure embed a 'struct device' in itself, like you did for a kref, and you will be fine. Otherwise you are dealing with two different sets of reference counting here, for no good reason.
Quoted 13 lines
drivers/pci/switch/switchtec.h new file +13
-0+ +unsigned int event_irq; + +void __iomem *mmio; +struct mrpc_regs __iomem *mmio_mrpc; +struct ntb_info_regs __iomem *mmio_ntb; +struct part_cfg_regs __iomem *mmio_part_cfg; + +/* +* The mrpc mutex must be held when accessing the other +* mrpc fields +*/ +struct mutex mrpc_mutex;
drivers/pci/switch/switchtec.h line 117
Quoted 10 lines
drivers/pci/switch/switchtec.h new file +10
-0+struct list_head mrpc_queue; +int mrpc_busy; +struct work_struct mrpc_work; +struct delayed_work mrpc_timeout; +}; + +#define stdev_pdev (stdev) ((stdev)->pdev) +#define stdev_pdev_dev (stdev) (&stdev_pdev(stdev)->dev) +#define stdev_name (stdev) pci_name(stdev_pdev(stdev)) +#define stdev_dev (stdev) ((stdev)->dev)
Ick, just open code these please. That's a huge hint your use of the driver model is not correct :)
thanks,
greg k-h
Logan Gunthorpe
maintainerRe: [RFC 1/1] MicroSemi Switchtec management interface driver
Hi Greg,
Thanks for the quick review!
Quoted 11 lines · Greg Kroah-Hartman
drivers/pci/switch/switchtec.h line 94
Quoted 5 lines · Logan Gunthorpe
drivers/pci/switch/switchtec.h new file +5
-0+struct switchtec_dev { +struct pci_dev *pdev; +struct msix_entry *msix; +struct device *dev; +struct kref kref;Why do you have a pointer to a device, yet a kref as well? Just have this structure embed a 'struct device' in itself, like you did for a kref, and you will be fine. Otherwise you are dealing with two different sets of reference counting here, for no good reason.
Ok, understood. I had referenced the device dax driver which did it this way in 4.8 but looks like it was changed to the way you suggest in 4.9.
Quoted 7 lines
drivers/pci/switch/switchtec.h line 117
Quoted 4 lines
drivers/pci/switch/switchtec.h new file +4
-0+#define stdev_pdev (stdev) ((stdev)->pdev) +#define stdev_pdev_dev (stdev) (&stdev_pdev(stdev)->dev) +#define stdev_name (stdev) pci_name(stdev_pdev(stdev)) +#define stdev_dev (stdev) ((stdev)->dev)Ick, just open code these please. That's a huge hint your use of the driver model is not correct :)
Ok, will do. For reference, I was copying
drivers/ntb/hw/intel/ntb_hw_intel.h
which does a similar thing.
Logan
Re: [RFC 1/1] MicroSemi Switchtec management interface driver
Quoted 28 lines · Logan Gunthorpe
Hi Greg,
Thanks for the quick review!
Quoted 11 lines · Greg Kroah-Hartman
drivers/pci/switch/switchtec.h line 94
Quoted 5 lines · Logan Gunthorpe
drivers/pci/switch/switchtec.h new file +5
-0+struct switchtec_dev { +struct pci_dev *pdev; +struct msix_entry *msix; +struct device *dev; +struct kref kref;Why do you have a pointer to a device, yet a kref as well? Just have this structure embed a 'struct device' in itself, like you did for a kref, and you will be fine. Otherwise you are dealing with two different sets of reference counting here, for no good reason.
Ok, understood. I had referenced the device dax driver which did it this way in 4.8 but looks like it was changed to the way you suggest in 4.9.
Quoted 7 lines
drivers/pci/switch/switchtec.h line 117
Quoted 4 lines
drivers/pci/switch/switchtec.h new file +4
-0+#define stdev_pdev (stdev) ((stdev)->pdev) +#define stdev_pdev_dev (stdev) (&stdev_pdev(stdev)->dev) +#define stdev_name (stdev) pci_name(stdev_pdev(stdev)) +#define stdev_dev (stdev) ((stdev)->dev)Ick, just open code these please. That's a huge hint your use of the driver model is not correct :)
Quoted 5 lines
Ok, will do. For reference, I was copying
drivers/ntb/hw/intel/ntb_hw_intel.hwhich does a similar thing.
No need to copy bad code, I suggest fixing that up as well :)
thanks,
greg k-h
Re: [RFC 1/1] MicroSemi Switchtec management interface driver
In reply to Logan GunthorpeQuoted 11 lines · Logan Gunthorpe
Microsemi's "Switchtec" line of PCI switch devices is already supported by the kernel with standard PCI switch drivers. However, the Switchtec device advertises a special management endpoint which enables some additional functionality. This includes:
* Packet and Byte Counters
* Firmware Upgrades
* Event and Error logs
* Querying port link status
* Custom user firmware commands
Quoted 8 lines
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. Currently no ioctls have been implemented but a couple may be added in a later revision.
A short text file is provided which documents the switchtec driver and outlines the semantics of using the char device.
Some of this would be simplified if you use the managed device API's:devm_request_irq, pcim_enable_device, pcim_iomap, etc...
Logan Gunthorpe
maintainerRe: [RFC 1/1] MicroSemi Switchtec management interface driver
Quoted 2 lines · Keith Busch
Some of this would be simplified if you use the managed device API's:
devm_request_irq,pcim_enable_device,pcim_iomap, etc...
Thanks Keith, I'll look into using those.
Logan
I guess the obvious questions is: why is a driver for a PCI switch necessary? The core works with all compliant switches today and there are no specifics for a particular design or such.
So I guess I'd like to hear the reasoning and justifications for why a driver for a common device that should conform to the specifications and not seem to need any special considerations is required or desired here.
Quoted 60 lines · Logan Gunthorpe
Hi,
[Appologies: this is a resend for some people. Due to a configuration error the original email was rejected by the mailing lists. I hope this one makes it!]
We're looking to get some initial feedback on a new driver for a line of PCIe switches produced and produced and sold by Microsemi. The goal is to get the process moving to get this code included in upstream hopefully for 4.11. Facebook is currently gearing up to use this hardware in its Open Compute Platform and is pushing to have this driver in the upstream kernel.
The following patch briefly describes the hardware and provides the first draft of driver code. Currently, the driver works and has been tested but is not feature complete. Thus, we are not looking to get it merged immediately. However we would like some early review, specifically on the interfaces and core concepts so that we don't do a lot of work down a path the community would reject. Barring any objections to this RFC, we will flesh out all the features and provide a completed patch for inclusion in the coming weeks.
Work on a userspace tool, that utilizes this driver, is also being done at [1]. The tool is currently also a bit of a skeleton and will be fleshed out assuming there are no serious objections to our userspace interface. In the end, the tool will be released with a GPL license.
The patch is based off of the v4.9 release.
Thanks for your review,
Logan
[1] https://github.com/sbates130272/switchtec-user
Logan Gunthorpe (1):
MicroSemi Switchtec management interface driverDocumentation/switchtec.txt | 54 +++ MAINTAINERS | 9 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 824 +++++++++++++++++++++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 119 ++++++ 8 files changed, 1022 insertions(+) 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--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Logan Gunthorpe
maintainerHey,
Quoted 8 lines · Myron Stowe
I guess the obvious questions is: why is a driver for a PCI switch necessary? The core works with all compliant switches today and there are no specifics for a particular design or such.
So I guess I'd like to hear the reasoning and justifications for why a driver for a common device that should conform to the specifications and not seem to need any special considerations is required or desired here.
As I noted, the hardware is compliant and works perfectly fine with the in-kernel driver. However, the hardware has many additional custom features that are not covered by the PCI specs. For example, it has an interface to count packets that match a specific criteria. It also has firmware that can be expanded to do completely custom things by the user. Additionally, the switch is _very_ configurable and has a configuration file that can be uploaded and downloaded.
All these features and more are exposed through a special management endpoint that is completely separate from the standard PCI switch interface. This work is a driver for that endpoint and is not required to use the switch. It only makes the advanced features available to the user.
Does that make sense?
Thanks,
Logan
Quoted 61 lines · Logan Gunthorpe
Quoted 60 lines
Hi,
[Appologies: this is a resend for some people. Due to a configuration error the original email was rejected by the mailing lists. I hope this one makes it!]
We're looking to get some initial feedback on a new driver for a line of PCIe switches produced and produced and sold by Microsemi. The goal is to get the process moving to get this code included in upstream hopefully for 4.11. Facebook is currently gearing up to use this hardware in its Open Compute Platform and is pushing to have this driver in the upstream kernel.
The following patch briefly describes the hardware and provides the first draft of driver code. Currently, the driver works and has been tested but is not feature complete. Thus, we are not looking to get it merged immediately. However we would like some early review, specifically on the interfaces and core concepts so that we don't do a lot of work down a path the community would reject. Barring any objections to this RFC, we will flesh out all the features and provide a completed patch for inclusion in the coming weeks.
Work on a userspace tool, that utilizes this driver, is also being done at [1]. The tool is currently also a bit of a skeleton and will be fleshed out assuming there are no serious objections to our userspace interface. In the end, the tool will be released with a GPL license.
The patch is based off of the v4.9 release.
Thanks for your review,
Logan
[1] https://github.com/sbates130272/switchtec-user
Logan Gunthorpe (1):
MicroSemi Switchtec management interface driverDocumentation/switchtec.txt | 54 +++ MAINTAINERS | 9 + drivers/pci/Kconfig | 1 + drivers/pci/Makefile | 1 + drivers/pci/switch/Kconfig | 13 + drivers/pci/switch/Makefile | 1 + drivers/pci/switch/switchtec.c | 824 +++++++++++++++++++++++++++++++++++++++++ drivers/pci/switch/switchtec.h | 119 ++++++ 8 files changed, 1022 insertions(+) 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--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Logan Gunthorpe
As I noted, the hardware is compliant and works perfectly fine with the in-kernel driver. However, the hardware has many additional custom features that are not covered by the PCI specs. For example, it has an interface to count packets that match a specific criteria. It also has firmware that can be expanded to do completely custom things by the user. Additionally, the switch is _very_ configurable and has a configuration file that can be uploaded and downloaded.
Quoted 5 lines
All these features and more are exposed through a special management endpoint that is completely separate from the standard PCI switch interface. This work is a driver for that endpoint and is not required to use the switch. It only makes the advanced features available to the user.
Since the in-kernel driver binds to the device, won't this driver conflict with the initialization the in-kernel one already does? Bus master, MSI setup, etc?
Could you also provide the reasoning against making the functionality this driver provides in user space?
Logan Gunthorpe
maintainerQuoted 3 lines · Keith Busch
Since the in-kernel driver binds to the device, won't this driver conflict with the initialization the in-kernel one already does? Bus master, MSI setup, etc?
No. The management interface is on a completely separate PCI endpoint. So from the kernels perspective, the management interface is just another PCI device. It has the same vendor and device ID as the switch but uses separate class codes so it can be bound by an independent driver.
Quoted 2 lines
Could you also provide the reasoning against making the functionality this driver provides in user space?
I'm not sure how you mean. I suppose we could write a UIO driver but that seemed like an ugly solution to me and doesn't seem like an approach the community prefers. We do have to make use of interrupts so simply using /sys/bus/pci/.../resourceN wouldn't work either.
Logan