Merge branch 'pci/switchtec' into next

* pci/switchtec:
  switchtec: Add IOCTLs to the Switchtec driver
  switchtec: Add sysfs attributes to the Switchtec driver
  switchtec: Add user interface documentation
  MicroSemi Switchtec management interface driver

Conflicts:
	drivers/pci/Kconfig
This commit is contained in:
Bjorn Helgaas 2017-04-28 10:33:41 -05:00
commit d060c6fcef
10 changed files with 1936 additions and 0 deletions

View File

@ -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@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.

View File

@ -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

View File

@ -0,0 +1,80 @@
========================
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.
The following IOCTLs are also supported by the device:
* SWITCHTEC_IOCTL_FLASH_INFO - Retrieve firmware length and number
of partitions in the device.
* SWITCHTEC_IOCTL_FLASH_PART_INFO - Retrieve address and lengeth for
any specified partition in flash.
* SWITCHTEC_IOCTL_EVENT_SUMMARY - Read a structure of bitmaps
indicating all uncleared events.
* SWITCHTEC_IOCTL_EVENT_CTL - Get the current count, clear and set flags
for any event. This ioctl takes in a switchtec_ioctl_event_ctl struct
with the event_id, index and flags set (index being the partition or PFF
number for non-global events). It returns whether the event has
occurred, the number of times and any event specific data. The flags
can be used to clear the count or enable and disable actions to
happen when the event occurs.
By using the SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL flag,
you can set an event to trigger a poll command to return with
POLLPRI. In this way, userspace can wait for events to occur.
* SWITCHTEC_IOCTL_PFF_TO_PORT and SWITCHTEC_IOCTL_PORT_TO_PFF convert
between PCI Function Framework number (used by the event system)
and Switchtec Logic Port ID and Partition number (which is more
user friendly).

View File

@ -9664,6 +9664,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@microsemi.com>
M: Stephen Bates <stephen.bates@microsemi.com>
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*
F: include/uapi/linux/switchtec_ioctl.h
PCI DRIVER FOR NVIDIA TEGRA
M: Thierry Reding <thierry.reding@gmail.com>
L: linux-tegra@vger.kernel.org

View File

@ -135,3 +135,4 @@ source "drivers/pci/hotplug/Kconfig"
source "drivers/pci/dwc/Kconfig"
source "drivers/pci/host/Kconfig"
source "drivers/pci/endpoint/Kconfig"
source "drivers/pci/switch/Kconfig"

View File

@ -68,3 +68,4 @@ ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG
# PCI host controller drivers
obj-y += host/
obj-y += switch/

View File

@ -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

View File

@ -0,0 +1 @@
obj-$(CONFIG_PCI_SW_SWITCHTEC) += switchtec.o

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
/*
* Microsemi Switchtec PCIe Driver
* Copyright (c) 2017, Microsemi Corporation
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*/
#ifndef _UAPI_LINUX_SWITCHTEC_IOCTL_H
#define _UAPI_LINUX_SWITCHTEC_IOCTL_H
#include <linux/types.h>
#define SWITCHTEC_IOCTL_PART_CFG0 0
#define SWITCHTEC_IOCTL_PART_CFG1 1
#define SWITCHTEC_IOCTL_PART_IMG0 2
#define SWITCHTEC_IOCTL_PART_IMG1 3
#define SWITCHTEC_IOCTL_PART_NVLOG 4
#define SWITCHTEC_IOCTL_PART_VENDOR0 5
#define SWITCHTEC_IOCTL_PART_VENDOR1 6
#define SWITCHTEC_IOCTL_PART_VENDOR2 7
#define SWITCHTEC_IOCTL_PART_VENDOR3 8
#define SWITCHTEC_IOCTL_PART_VENDOR4 9
#define SWITCHTEC_IOCTL_PART_VENDOR5 10
#define SWITCHTEC_IOCTL_PART_VENDOR6 11
#define SWITCHTEC_IOCTL_PART_VENDOR7 12
#define SWITCHTEC_IOCTL_NUM_PARTITIONS 13
struct switchtec_ioctl_flash_info {
__u64 flash_length;
__u32 num_partitions;
__u32 padding;
};
struct switchtec_ioctl_flash_part_info {
__u32 flash_partition;
__u32 address;
__u32 length;
__u32 active;
};
struct switchtec_ioctl_event_summary {
__u64 global;
__u64 part_bitmap;
__u32 local_part;
__u32 padding;
__u32 part[48];
__u32 pff[48];
};
#define SWITCHTEC_IOCTL_EVENT_STACK_ERROR 0
#define SWITCHTEC_IOCTL_EVENT_PPU_ERROR 1
#define SWITCHTEC_IOCTL_EVENT_ISP_ERROR 2
#define SWITCHTEC_IOCTL_EVENT_SYS_RESET 3
#define SWITCHTEC_IOCTL_EVENT_FW_EXC 4
#define SWITCHTEC_IOCTL_EVENT_FW_NMI 5
#define SWITCHTEC_IOCTL_EVENT_FW_NON_FATAL 6
#define SWITCHTEC_IOCTL_EVENT_FW_FATAL 7
#define SWITCHTEC_IOCTL_EVENT_TWI_MRPC_COMP 8
#define SWITCHTEC_IOCTL_EVENT_TWI_MRPC_COMP_ASYNC 9
#define SWITCHTEC_IOCTL_EVENT_CLI_MRPC_COMP 10
#define SWITCHTEC_IOCTL_EVENT_CLI_MRPC_COMP_ASYNC 11
#define SWITCHTEC_IOCTL_EVENT_GPIO_INT 12
#define SWITCHTEC_IOCTL_EVENT_PART_RESET 13
#define SWITCHTEC_IOCTL_EVENT_MRPC_COMP 14
#define SWITCHTEC_IOCTL_EVENT_MRPC_COMP_ASYNC 15
#define SWITCHTEC_IOCTL_EVENT_DYN_PART_BIND_COMP 16
#define SWITCHTEC_IOCTL_EVENT_AER_IN_P2P 17
#define SWITCHTEC_IOCTL_EVENT_AER_IN_VEP 18
#define SWITCHTEC_IOCTL_EVENT_DPC 19
#define SWITCHTEC_IOCTL_EVENT_CTS 20
#define SWITCHTEC_IOCTL_EVENT_HOTPLUG 21
#define SWITCHTEC_IOCTL_EVENT_IER 22
#define SWITCHTEC_IOCTL_EVENT_THRESH 23
#define SWITCHTEC_IOCTL_EVENT_POWER_MGMT 24
#define SWITCHTEC_IOCTL_EVENT_TLP_THROTTLING 25
#define SWITCHTEC_IOCTL_EVENT_FORCE_SPEED 26
#define SWITCHTEC_IOCTL_EVENT_CREDIT_TIMEOUT 27
#define SWITCHTEC_IOCTL_EVENT_LINK_STATE 28
#define SWITCHTEC_IOCTL_MAX_EVENTS 29
#define SWITCHTEC_IOCTL_EVENT_LOCAL_PART_IDX -1
#define SWITCHTEC_IOCTL_EVENT_IDX_ALL -2
#define SWITCHTEC_IOCTL_EVENT_FLAG_CLEAR (1 << 0)
#define SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL (1 << 1)
#define SWITCHTEC_IOCTL_EVENT_FLAG_EN_LOG (1 << 2)
#define SWITCHTEC_IOCTL_EVENT_FLAG_EN_CLI (1 << 3)
#define SWITCHTEC_IOCTL_EVENT_FLAG_EN_FATAL (1 << 4)
#define SWITCHTEC_IOCTL_EVENT_FLAG_DIS_POLL (1 << 5)
#define SWITCHTEC_IOCTL_EVENT_FLAG_DIS_LOG (1 << 6)
#define SWITCHTEC_IOCTL_EVENT_FLAG_DIS_CLI (1 << 7)
#define SWITCHTEC_IOCTL_EVENT_FLAG_DIS_FATAL (1 << 8)
#define SWITCHTEC_IOCTL_EVENT_FLAG_UNUSED (~0x1ff)
struct switchtec_ioctl_event_ctl {
__u32 event_id;
__s32 index;
__u32 flags;
__u32 occurred;
__u32 count;
__u32 data[5];
};
#define SWITCHTEC_IOCTL_PFF_VEP 100
struct switchtec_ioctl_pff_port {
__u32 pff;
__u32 partition;
__u32 port;
};
#define SWITCHTEC_IOCTL_FLASH_INFO \
_IOR('W', 0x40, struct switchtec_ioctl_flash_info)
#define SWITCHTEC_IOCTL_FLASH_PART_INFO \
_IOWR('W', 0x41, struct switchtec_ioctl_flash_part_info)
#define SWITCHTEC_IOCTL_EVENT_SUMMARY \
_IOR('W', 0x42, struct switchtec_ioctl_event_summary)
#define SWITCHTEC_IOCTL_EVENT_CTL \
_IOWR('W', 0x43, struct switchtec_ioctl_event_ctl)
#define SWITCHTEC_IOCTL_PFF_TO_PORT \
_IOWR('W', 0x44, struct switchtec_ioctl_pff_port)
#define SWITCHTEC_IOCTL_PORT_TO_PFF \
_IOWR('W', 0x45, struct switchtec_ioctl_pff_port)
#endif