^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) ========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) Linux Switchtec Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) ========================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) Microsemi's "Switchtec" line of PCI switch devices is already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) supported by the kernel with standard PCI switch drivers. However, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Switchtec device advertises a special management endpoint which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) enables some additional functionality. This includes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Packet and Byte Counters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Firmware Upgrades
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Event and Error logs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Querying port link status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Custom user firmware commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) The switchtec kernel module implements this functionality.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) The primary means of communicating with the Switchtec management firmware is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) through the Memory-mapped Remote Procedure Call (MRPC) interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Commands are submitted to the interface with a 4-byte command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) identifier and up to 1KB of command specific data. The firmware will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) respond with a 4-byte return code and up to 1KB of command-specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) data. The interface only processes a single command at a time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) Userspace Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) ===================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) The MRPC interface will be exposed to userspace through a simple char
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) device: /dev/switchtec#, one for each management endpoint in the system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) The char device has the following semantics:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * A write must consist of at least 4 bytes and no more than 1028 bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) The first 4 bytes will be interpreted as the Command ID and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) remainder will be used as the input data. A write will send the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) command to the firmware to begin processing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Each write must be followed by exactly one read. Any double write will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) produce an error and any read that doesn't follow a write will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) produce an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * A read will block until the firmware completes the command and return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) the 4-byte Command Return Value plus up to 1024 bytes of output
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) data. (The length will be specified by the size parameter of the read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) call -- reading less than 4 bytes will produce an error.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * The poll call will also be supported for userspace applications that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) need to do other things while waiting for the command to complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) The following IOCTLs are also supported by the device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * SWITCHTEC_IOCTL_FLASH_INFO - Retrieve firmware length and number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) of partitions in the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * SWITCHTEC_IOCTL_FLASH_PART_INFO - Retrieve address and lengeth for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) any specified partition in flash.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * SWITCHTEC_IOCTL_EVENT_SUMMARY - Read a structure of bitmaps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) indicating all uncleared events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * SWITCHTEC_IOCTL_EVENT_CTL - Get the current count, clear and set flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) for any event. This ioctl takes in a switchtec_ioctl_event_ctl struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) with the event_id, index and flags set (index being the partition or PFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) number for non-global events). It returns whether the event has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) occurred, the number of times and any event specific data. The flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) can be used to clear the count or enable and disable actions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) happen when the event occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) By using the SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) you can set an event to trigger a poll command to return with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) POLLPRI. In this way, userspace can wait for events to occur.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * SWITCHTEC_IOCTL_PFF_TO_PORT and SWITCHTEC_IOCTL_PORT_TO_PFF convert
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) between PCI Function Framework number (used by the event system)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) and Switchtec Logic Port ID and Partition number (which is more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) user friendly).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) Non-Transparent Bridge (NTB) Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ===================================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) An NTB hardware driver is provided for the Switchtec hardware in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ntb_hw_switchtec. Currently, it only supports switches configured with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) exactly 2 NT partitions and zero or more non-NT partitions. It also requires
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) the following configuration settings:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * Both NT partitions must be able to access each other's GAS spaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) Thus, the bits in the GAS Access Vector under Management Settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) must be set to support this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * Kernel configuration MUST include support for NTB (CONFIG_NTB needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) to be set)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) NT EP BAR 2 will be dynamically configured as a Direct Window, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) the configuration file does not need to configure it explicitly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) Please refer to Documentation/driver-api/ntb.rst in Linux source tree for an overall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) understanding of the Linux NTB stack. ntb_hw_switchtec works as an NTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) Hardware Driver in this stack.