162306a36Sopenharmony_ci======================== 262306a36Sopenharmony_ciLinux Switchtec Support 362306a36Sopenharmony_ci======================== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ciMicrosemi's "Switchtec" line of PCI switch devices is already 662306a36Sopenharmony_cisupported by the kernel with standard PCI switch drivers. However, the 762306a36Sopenharmony_ciSwitchtec device advertises a special management endpoint which 862306a36Sopenharmony_cienables some additional functionality. This includes: 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci* Packet and Byte Counters 1162306a36Sopenharmony_ci* Firmware Upgrades 1262306a36Sopenharmony_ci* Event and Error logs 1362306a36Sopenharmony_ci* Querying port link status 1462306a36Sopenharmony_ci* Custom user firmware commands 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ciThe switchtec kernel module implements this functionality. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ciInterface 2062306a36Sopenharmony_ci========= 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciThe primary means of communicating with the Switchtec management firmware is 2362306a36Sopenharmony_cithrough the Memory-mapped Remote Procedure Call (MRPC) interface. 2462306a36Sopenharmony_ciCommands are submitted to the interface with a 4-byte command 2562306a36Sopenharmony_ciidentifier and up to 1KB of command specific data. The firmware will 2662306a36Sopenharmony_cirespond with a 4-byte return code and up to 1KB of command-specific 2762306a36Sopenharmony_cidata. The interface only processes a single command at a time. 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ciUserspace Interface 3162306a36Sopenharmony_ci=================== 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ciThe MRPC interface will be exposed to userspace through a simple char 3462306a36Sopenharmony_cidevice: /dev/switchtec#, one for each management endpoint in the system. 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciThe char device has the following semantics: 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci* A write must consist of at least 4 bytes and no more than 1028 bytes. 3962306a36Sopenharmony_ci The first 4 bytes will be interpreted as the Command ID and the 4062306a36Sopenharmony_ci remainder will be used as the input data. A write will send the 4162306a36Sopenharmony_ci command to the firmware to begin processing. 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci* Each write must be followed by exactly one read. Any double write will 4462306a36Sopenharmony_ci produce an error and any read that doesn't follow a write will 4562306a36Sopenharmony_ci produce an error. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci* A read will block until the firmware completes the command and return 4862306a36Sopenharmony_ci the 4-byte Command Return Value plus up to 1024 bytes of output 4962306a36Sopenharmony_ci data. (The length will be specified by the size parameter of the read 5062306a36Sopenharmony_ci call -- reading less than 4 bytes will produce an error.) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci* The poll call will also be supported for userspace applications that 5362306a36Sopenharmony_ci need to do other things while waiting for the command to complete. 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciThe following IOCTLs are also supported by the device: 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci* SWITCHTEC_IOCTL_FLASH_INFO - Retrieve firmware length and number 5862306a36Sopenharmony_ci of partitions in the device. 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci* SWITCHTEC_IOCTL_FLASH_PART_INFO - Retrieve address and lengeth for 6162306a36Sopenharmony_ci any specified partition in flash. 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci* SWITCHTEC_IOCTL_EVENT_SUMMARY - Read a structure of bitmaps 6462306a36Sopenharmony_ci indicating all uncleared events. 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci* SWITCHTEC_IOCTL_EVENT_CTL - Get the current count, clear and set flags 6762306a36Sopenharmony_ci for any event. This ioctl takes in a switchtec_ioctl_event_ctl struct 6862306a36Sopenharmony_ci with the event_id, index and flags set (index being the partition or PFF 6962306a36Sopenharmony_ci number for non-global events). It returns whether the event has 7062306a36Sopenharmony_ci occurred, the number of times and any event specific data. The flags 7162306a36Sopenharmony_ci can be used to clear the count or enable and disable actions to 7262306a36Sopenharmony_ci happen when the event occurs. 7362306a36Sopenharmony_ci By using the SWITCHTEC_IOCTL_EVENT_FLAG_EN_POLL flag, 7462306a36Sopenharmony_ci you can set an event to trigger a poll command to return with 7562306a36Sopenharmony_ci POLLPRI. In this way, userspace can wait for events to occur. 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci* SWITCHTEC_IOCTL_PFF_TO_PORT and SWITCHTEC_IOCTL_PORT_TO_PFF convert 7862306a36Sopenharmony_ci between PCI Function Framework number (used by the event system) 7962306a36Sopenharmony_ci and Switchtec Logic Port ID and Partition number (which is more 8062306a36Sopenharmony_ci user friendly). 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ciNon-Transparent Bridge (NTB) Driver 8462306a36Sopenharmony_ci=================================== 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ciAn NTB hardware driver is provided for the Switchtec hardware in 8762306a36Sopenharmony_cintb_hw_switchtec. Currently, it only supports switches configured with 8862306a36Sopenharmony_ciexactly 2 NT partitions and zero or more non-NT partitions. It also requires 8962306a36Sopenharmony_cithe following configuration settings: 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci* Both NT partitions must be able to access each other's GAS spaces. 9262306a36Sopenharmony_ci Thus, the bits in the GAS Access Vector under Management Settings 9362306a36Sopenharmony_ci must be set to support this. 9462306a36Sopenharmony_ci* Kernel configuration MUST include support for NTB (CONFIG_NTB needs 9562306a36Sopenharmony_ci to be set) 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ciNT EP BAR 2 will be dynamically configured as a Direct Window, and 9862306a36Sopenharmony_cithe configuration file does not need to configure it explicitly. 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ciPlease refer to Documentation/driver-api/ntb.rst in Linux source tree for an overall 10162306a36Sopenharmony_ciunderstanding of the Linux NTB stack. ntb_hw_switchtec works as an NTB 10262306a36Sopenharmony_ciHardware Driver in this stack. 103