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