113d3aa75SGeorge Liu# Mux Support 28fee4242SAlexander Hansen 38fee4242SAlexander HansenIn some hardware designs, multiple UARTS may be available behind a Mux, which 48fee4242SAlexander Hansenrequires obmc-console to select one at a time. 58fee4242SAlexander Hansen 68fee4242SAlexander HansenFor example, let's say behind `/dev/ttyS0` there are `UART1` and `UART2`, behind 78fee4242SAlexander Hansena mux. GPIO `UART-MUX-CTL` can be used to select one. This scenario is shown in 88fee4242SAlexander Hansenthe [Example Diagram](#example-diagram) 98fee4242SAlexander Hansen 108fee4242SAlexander HansenThen there will be one obmc-console-server process, and 2 consoles will be 118fee4242SAlexander Hansencreated in this server process. 128fee4242SAlexander Hansen 138fee4242SAlexander HansenThe obmc-console-server will receive configuration for both consoles detailing 148fee4242SAlexander Hansenthe gpios to be used to control the mux and the values they should have when 158fee4242SAlexander Hansenthey are active. 168fee4242SAlexander Hansen 178fee4242SAlexander HansenThe implementation documented here has been made based on the 188fee4242SAlexander Hansen[design document](https://github.com/openbmc/docs/blob/master/designs/uart-mux-support.md) 198fee4242SAlexander Hansen 208fee4242SAlexander Hansen## Userspace Implementation 218fee4242SAlexander Hansen 228fee4242SAlexander HansenThe kernel will not be aware of this mux and the support can be implemented in 238fee4242SAlexander Hansenuserspace. 248fee4242SAlexander Hansen 258fee4242SAlexander HansenReasons for this are that the hardware this is for is not static (blade server) 268fee4242SAlexander Hansenand thus cannot be represented by devicetree. Also, it is unclear how the 278fee4242SAlexander Hansenvirtual uart should notify a process that the mux state has changed. 288fee4242SAlexander Hansen 298fee4242SAlexander HansenWhen a userspace implementation is available for reference, this may later pave 308fee4242SAlexander Hansenthe way for a kernel implementation if someone wants to do that. 318fee4242SAlexander Hansen 328fee4242SAlexander Hansen## Configuration Example 338fee4242SAlexander Hansen 348fee4242SAlexander HansenThe configuration is similar to i2c-mux-gpio in the linux kernel. 358fee4242SAlexander Hansen 368fee4242SAlexander HansenThe order of GPIOs listed in 'mux-gpios' forms the LSB-first bit representation 378fee4242SAlexander Hansenof an N-bit number that is taken from 'mux-index'. 388fee4242SAlexander Hansen 398fee4242SAlexander HansenFor declaring the different consoles, the section name, e.g. `[host1]` must be 408fee4242SAlexander Hansenthe same as the console-id. All of the section names need to be unique. 418fee4242SAlexander Hansen 42ce3688c9SGeorge Liu```sh 438fee4242SAlexander Hansen$ cat server.conf 448fee4242SAlexander Hansenmux-gpios = MUX_CTL 458fee4242SAlexander Hansen 468fee4242SAlexander Hansen[host1] 478fee4242SAlexander Hansenmux-index = 0 488fee4242SAlexander Hansenlogfile = /var/log/console-host1.log 498fee4242SAlexander Hansen 508fee4242SAlexander Hansen[host2] 518fee4242SAlexander Hansenmux-index = 1 528fee4242SAlexander Hansenlogfile = /var/log/console-host2.log 538fee4242SAlexander Hansen``` 548fee4242SAlexander Hansen 558fee4242SAlexander HansenNow the server can be started. See the [Dbus Interface](#dbus-interface-example) 568fee4242SAlexander Hansenand [Example Diagram](#example-diagram) 578fee4242SAlexander Hansen 58ce3688c9SGeorge Liu```sh 59*85055f99SGeorge Liuobmc-console-server --config server.conf /dev/ttyS0 608fee4242SAlexander Hansen``` 618fee4242SAlexander Hansen 628fee4242SAlexander Hansen## Mux Control 638fee4242SAlexander Hansen 648fee4242SAlexander HansenMux Control happens implicitly via connections. When a client connects to a 658fee4242SAlexander Hansenconsole, the new connection is accepted and the console-server switches the mux 668fee4242SAlexander Hansento this console. Any clients connected to other consoles are disconnected. 678fee4242SAlexander Hansen 688fee4242SAlexander Hansen### Mux Control - Example 698fee4242SAlexander Hansen 70ce3688c9SGeorge Liu```sh 718fee4242SAlexander Hansen$ obmc-console-client -i host2 & 728fee4242SAlexander Hansen[1] 3422 738fee4242SAlexander Hansen$ obmc-console-client -i host1 748fee4242SAlexander Hansen``` 758fee4242SAlexander Hansen 768fee4242SAlexander HansenConnecting to console 'host1' will cause console 'host2' to: 778fee4242SAlexander Hansen 788fee4242SAlexander Hansen1. stop forwarding bytes 798fee4242SAlexander Hansen2. print a log message to its clients, if the server was connected before, see 808fee4242SAlexander Hansen [Mux Control Log](#mux-control-log) 818fee4242SAlexander Hansen 828fee4242SAlexander HansenThen the following happens for console 'host1': 838fee4242SAlexander Hansen 848fee4242SAlexander Hansen1. switch the mux using the gpios 858fee4242SAlexander Hansen2. print a log message to its clients, if the server was disconnected before, 868fee4242SAlexander Hansen see [Mux Control Log](#mux-control-log) 878fee4242SAlexander Hansen3. start forwarding bytes. 888fee4242SAlexander Hansen 898fee4242SAlexander Hansen## Mux Control Log 908fee4242SAlexander Hansen 918fee4242SAlexander HansenWhenever the mux is switched, there should be a way for people reading the log 928fee4242SAlexander Hansento know that that console was (dis)connected, and at which time. Otherwise there 938fee4242SAlexander Hansenmay be confusion as to why there is a gap in the logs. 948fee4242SAlexander Hansen 958fee4242SAlexander HansenSo obmc-console-server will print one of these messages to all clients: 968fee4242SAlexander Hansen 97ce3688c9SGeorge Liu```sh 988fee4242SAlexander Hansen[obmc-console] %Y-%m-%d %H:%M:%S UTC CONNECTED 998fee4242SAlexander Hansen``` 1008fee4242SAlexander Hansen 101ce3688c9SGeorge Liu```sh 1028fee4242SAlexander Hansen[obmc-console] %Y-%m-%d %H:%M:%S UTC DISCONNECTED 1038fee4242SAlexander Hansen``` 1048fee4242SAlexander Hansen 1058fee4242SAlexander Hansen### Mux Control Log Disclaimer 1068fee4242SAlexander Hansen 1078fee4242SAlexander HansenNote that this log message is not a reliable source of information, and is only 1088fee4242SAlexander Hansenprovided as a convenience feature. This same log message could be printed by 1098fee4242SAlexander Hansenanything that's connected to the uart on the other side. 1108fee4242SAlexander Hansen 1118fee4242SAlexander HansenThe exact format of this log message is not fixed and could change. 1128fee4242SAlexander Hansen 1138fee4242SAlexander Hansen## Dbus Interface Example 1148fee4242SAlexander Hansen 115ce3688c9SGeorge Liu```sh 1168fee4242SAlexander Hansen$ busctl list 1178fee4242SAlexander Hansen... 1188fee4242SAlexander Hansenxyz.openbmc_project.Console.host1 926 obmc-console-server root ... 1198fee4242SAlexander Hansenxyz.openbmc_project.Console.host2 926 obmc-console-server root ... 1208fee4242SAlexander Hansen... 1218fee4242SAlexander Hansen``` 1228fee4242SAlexander Hansen 123ce3688c9SGeorge Liu```sh 1248fee4242SAlexander Hansen$ busctl tree xyz.openbmc_project.Console.host2 1258fee4242SAlexander Hansen└─ /xyz 1268fee4242SAlexander Hansen └─ /xyz/openbmc_project 1278fee4242SAlexander Hansen └─ /xyz/openbmc_project/console 1288fee4242SAlexander Hansen └─ /xyz/openbmc_project/console/host1 1298fee4242SAlexander Hansen └─ /xyz/openbmc_project/console/host2 1308fee4242SAlexander Hansen 1318fee4242SAlexander Hansen$ busctl tree xyz.openbmc_project.Console.host1 1328fee4242SAlexander Hansen└─ /xyz 1338fee4242SAlexander Hansen └─ /xyz/openbmc_project 1348fee4242SAlexander Hansen └─ /xyz/openbmc_project/console 1358fee4242SAlexander Hansen └─ /xyz/openbmc_project/console/host1 1368fee4242SAlexander Hansen └─ /xyz/openbmc_project/console/host2 1378fee4242SAlexander Hansen``` 1388fee4242SAlexander Hansen 139ce3688c9SGeorge Liu```sh 1408fee4242SAlexander Hansen$ busctl introspect xyz.openbmc_project.Console.host1 /xyz/openbmc_project/console/host1 1418fee4242SAlexander HansenNAME TYPE SIGNATURE RESULT/VALUE FLAGS 1428fee4242SAlexander Hansenorg.freedesktop.DBus.Introspectable interface - - - 1438fee4242SAlexander Hansen.Introspect method - s - 1448fee4242SAlexander Hansenorg.freedesktop.DBus.Peer interface - - - 1458fee4242SAlexander Hansen.GetMachineId method - s - 1468fee4242SAlexander Hansen.Ping method - - - 1478fee4242SAlexander Hansenorg.freedesktop.DBus.Properties interface - - - 1488fee4242SAlexander Hansen.Get method ss v - 1498fee4242SAlexander Hansen.GetAll method s a{sv} - 1508fee4242SAlexander Hansen.Set method ssv - - 1518fee4242SAlexander Hansen.PropertiesChanged signal sa{sv}as - - 1528fee4242SAlexander Hansenxyz.openbmc_project.Console.Access interface - - - 1538fee4242SAlexander Hansen.Connect method - h - 1548fee4242SAlexander Hansen``` 1558fee4242SAlexander Hansen 1568fee4242SAlexander Hansen## Example Diagram 1578fee4242SAlexander Hansen 158ce3688c9SGeorge Liu```text 1598fee4242SAlexander Hansen +--------------------+ 1608fee4242SAlexander Hansen | server.conf | 1618fee4242SAlexander Hansen +--------------------+ 1628fee4242SAlexander Hansen | 1638fee4242SAlexander Hansen | 1648fee4242SAlexander Hansen | 1658fee4242SAlexander Hansen | 1668fee4242SAlexander Hansen +----+----+ +-----+ +-------+ 1678fee4242SAlexander Hansen | | | | | | 1688fee4242SAlexander Hansen | | +-------+ +-------+ | +-----+ UART1 | 1698fee4242SAlexander Hansen+-----------------------------------+ | | | | | | | | | | 1708fee4242SAlexander Hansen| xyz.openbmc_project.Console.host1 +-----+ +-----+ ttyS0 +-----+ UART0 +-----+ | +-------+ 1718fee4242SAlexander Hansen+-----------------------------------+ | | | | | | | | 1728fee4242SAlexander Hansen | obmc | +-------+ +-------+ | | 1738fee4242SAlexander Hansen | console | | MUX | 1748fee4242SAlexander Hansen | server | +-------+ | | 1758fee4242SAlexander Hansen+-----------------------------------+ | | | | | | 1768fee4242SAlexander Hansen| xyz.openbmc_project.Console.host2 +-----+ +-------------------+ GPIO +-----+ | +-------+ 1778fee4242SAlexander Hansen+-----------------------------------+ | | | | | | | | 1788fee4242SAlexander Hansen | | +-------+ | +-----+ UART2 | 1798fee4242SAlexander Hansen | | | | | | 1808fee4242SAlexander Hansen +----+----+ +-----+ +-------+ 1818fee4242SAlexander Hansen 1828fee4242SAlexander Hansen``` 183