UART slave device bus
Subsystems (2)
cover UART slave device bus
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct uart_port) below the tty layer in order to use existing serial drivers.
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller for uart_ports into separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Rob
Rob Herring (3):
uart bus: Introduce new bus for UART slave devices
tty: serial_core: make tty_struct optional
tty: serial_core: add uart controller registration
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/tty/serial/serial_core.c | 11 +- drivers/tty/tty_buffer.c | 2 + drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 +++++++++++++++++++++++++++++++++++++++ drivers/uart/loopback.c | 72 ++++++ include/linux/serial_core.h | 3 +- include/linux/uart_device.h | 163 ++++++++++++++ 10 files changed, 730 insertions(+), 2 deletions(-) create mode 100644 drivers/uart/Kconfig create mode 100644 drivers/uart/Makefile create mode 100644 drivers/uart/core.c create mode 100644 drivers/uart/loopback.c create mode 100644 include/linux/uart_device.h
--
2.9.2
RFC PATCH 1/3 uart bus: Introduce new bus for UART slave devices
The UART bus is designed for slave devices such as Bluetooth, WiFi, GPS and NFC connected to UARTs on host processors. Tradionally these have been handled with tty line disciplines, rfkill, and userspace glue such as hci_attach. This approach has many drawbacks since it doesn't fit into the Linux driver model. Handling of sideband signals, power control and firmware loading are the main issues.
This creates a UART bus with controllers (i.e. host UARTs) and slave devices. Typically, these are point to point connections, but some devices have muxing protocols or a h/w mux is conceivable. Any muxing is not yet supported.
--- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 ++++++++++++++++++++++++++++++++++++++++++++ drivers/uart/loopback.c | 72 +++++++ include/linux/uart_device.h | 163 ++++++++++++++++ 7 files changed, 716 insertions(+) create mode 100644 drivers/uart/Kconfig create mode 100644 drivers/uart/Makefile create mode 100644 drivers/uart/core.c create mode 100644 drivers/uart/loopback.c create mode 100644 include/linux/uart_device.h
drivers/Kconfig +2 -0
@@ -202,4 +202,6 @@ source "drivers/hwtracing/intel_th/Kconfig" source "drivers/fpga/Kconfig" +source "drivers/uart/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -173,3 +173,4 @@ obj-$(CONFIG_STM) += hwtracing/stm/ obj-$(CONFIG_ANDROID) += android/ obj-$(CONFIG_NVMEM) += nvmem/ obj-$(CONFIG_FPGA) += fpga/ +obj-$(CONFIG_UART_DEV) += uart/
drivers/uart/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +# +# UART slave driver configuration +# +menuconfig UART_DEV + tristate "UART device support" + help + Support for devices connected via a UART + +if UART_DEV + +config UART_DEV_LOOPBACK + tristate "Loopback Test Driver" + help + This option enables a loopback test driver. Anything received from + the connected device will be echoed back. + +endif
drivers/uart/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_UART_DEV) := core.o + +obj-$(CONFIG_UART_DEV_LOOPBACK) += loopback.o
drivers/uart/core.c new file +458 -0
458 lines not on this page · raw message
drivers/uart/loopback.c new file +72 -0
72 lines not on this page · raw message
include/linux/uart_device.h new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
2.9.2
RFC PATCH 2/3 tty: serial_core: make tty_struct optional
In reply to Rob HerringIn order to allow serial drivers to work without a tty, make calls from drivers and serial_core work when tty_struct is NULL.
--- drivers/tty/serial/serial_core.c | 3 ++- drivers/tty/tty_buffer.c | 2 ++ include/linux/serial_core.h | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/tty/serial/serial_core.c +2 -1
@@ -111,7 +111,8 @@ void uart_write_wakeup(struct uart_port *port)* closed. No cookie for you. */ BUG_ON (!state); -tty_wakeup (state->port.tty); +if (state->port.tty) +tty_wakeup (state->port.tty); }static void uart_stop (struct tty_struct *tty)
drivers/tty/tty_buffer.c +2 -0
@@ -528,6 +528,8 @@ static void flush_to_ldisc(struct work_struct *work)void tty_flip_buffer_push (struct tty_port *port) { +if (!port->tty) +return ;tty_schedule_flip (port); }EXPORT_SYMBOL (tty_flip_buffer_push);
include/linux/serial_core.h +1 -1
@@ -412,7 +412,7 @@ int uart_resume_port(struct uart_driver *reg, struct uart_port *port);static inline int uart_tx_stopped (struct uart_port *port) {struct tty_struct *tty = port->state->port.tty; -if (tty->stopped || port->hw_stopped) +if ((tty && tty->stopped) || port->hw_stopped)return 1 ;return 0 ; }
Signature · 1 line
2.9.2
Re: [RFC PATCH 2/3] tty: serial_core: make tty_struct optional
Quoted 4 lines · Rob Herring
In order to allow serial drivers to work without a tty, make calls from drivers and
serial_corework whentty_structis NULL.Signed-off-by Rob Herring <[email protected]>
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
RFC PATCH 3/3 tty: serial_core: add uart controller registration
In reply to Rob HerringRegister serial ports with the uart device core as a controller and add a receive handler call.
--- drivers/tty/serial/serial_core.c | 8 ++++++++ include/linux/serial_core.h | 1 + 2 files changed, 9 insertions(+)
drivers/tty/serial/serial_core.c +8 -0
@@ -34,6 +34,7 @@#include <linux/serial_core.h> #include <linux/delay.h> #include <linux/mutex.h> +#include <linux/uart_device.h> #include <asm/irq.h> #include <asm/uaccess.h>
@@ -2800,6 +2801,10 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)uart_configure_port (drv, state, uport); + uport->ctrlr =uart_controller_alloc (uport->dev,0 ); + uport->ctrlr->port = uport; +uart_controller_add (uport->ctrlr); + num_groups =2 ;if (uport->attr_group) num_groups++;
@@ -3027,6 +3032,9 @@ void uart_insert_char(struct uart_port *port, unsigned int status, {struct tty_port *tport = &port->state->port; +if (uart_controller_rx (port->ctrlr, ch) >=0 ) +return ; +if ((status & port->ignore_status_mask & ~overrun) ==0 )if (tty_insert_flip_char (tport, ch, flag) ==0 ) ++port->icount.buf_overrun;
include/linux/serial_core.h +1 -0
@@ -155,6 +155,7 @@ struct uart_port {unsigned int read_status_mask;/* driver specific */ unsigned int ignore_status_mask;/* driver specific */ +struct uart_controller *ctrlr;struct uart_state *state;/* pointer to parent state */ struct uart_icount icount;/* statistics */
Signature · 1 line
2.9.2
Greg Kroah-Hartman
maintainerQuoted 11 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.
Quoted 7 lines
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
It should be.
Quoted 2 lines
- Split out the controller for
uart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
What do you mean by "controller" drivers here? I didn't understand them in the code.
Quoted 4 lines
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
Why? Is the code as-is slow?
Quoted 2 lines
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.
That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Yes, I like the idea (minor nit, you still have SPMI in a lot of places instead of UART), so I recommend keeping going with it.
Quoted 4 lines
drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 +++++++++++++++++++++++++++++++++++++++ drivers/uart/loopback.c | 72 ++++++
Why not just put this in drivers/tty/uart/ ?
thanks,
greg k-h
Marcel Holtmann
maintainerHi Greg,
Quoted 32 lines
Quoted 11 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.Quoted 7 lines
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.It should be.
Quoted 2 lines
- Split out the controller for
uart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?What do you mean by "controller" drivers here? I didn't understand them in the code.
Quoted 4 lines
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
Quoted 7 lines
Why? Is the code as-is slow?
Quoted 2 lines
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
maybe we can get the Intel LnP driver ported over and see how that one works out. It is one of the more complex ones when it comes to bootloader and firmware loading. Maybe Loic can take a stab at this. We would then also see how we can map the ACPI tables into a driver.
Quoted 7 lines
Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Yes, I like the idea (minor nit, you still have SPMI in a lot of places instead of UART), so I recommend keeping going with it.
Quoted 6 lines
Quoted 4 lines
drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 +++++++++++++++++++++++++++++++++++++++ drivers/uart/loopback.c | 72 ++++++Why not just put this in
drivers/tty/uart/?
Is it really then a TTY at all. Would be the UART become the basic core for a TTY? Having tty/uart/ seems a bit backward. Then again, it is just a directory name ;)
Regards
Marcel
Greg Kroah-Hartman
maintainerQuoted 39 lines · Marcel Holtmann
Hi Greg,
Quoted 37 lines
Quoted 11 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.Quoted 7 lines
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.It should be.
Quoted 2 lines
- Split out the controller for
uart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?What do you mean by "controller" drivers here? I didn't understand them in the code.
Quoted 4 lines
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?Why? Is the code as-is slow?
Quoted 2 lines
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.
Quoted 7 lines
Quoted 2 lines
That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
maybe we can get the Intel LnP driver ported over and see how that one works out. It is one of the more complex ones when it comes to bootloader and firmware loading. Maybe Loic can take a stab at this. We would then also see how we can map the ACPI tables into a driver.
Yes, I was going to complain about the OF-only bent of this patch, but I figured it would get fixed up once Rob started to use a "real" machine for his testing of this code :)
Quoted 12 lines
Quoted 12 lines
Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Yes, I like the idea (minor nit, you still have SPMI in a lot of places instead of UART), so I recommend keeping going with it.
Quoted 4 lines
drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 +++++++++++++++++++++++++++++++++++++++ drivers/uart/loopback.c | 72 ++++++
Quoted 4 lines
Quoted 1 line
Why not just put this in
drivers/tty/uart/?Is it really then a TTY at all. Would be the UART become the basic core for a TTY?
Hm, interesting idea. Not for all TTYs of course, but for those that are on UART devices, maybe? How would a usb-serial device fit into that picture?
Quoted 2 lines
Having tty/uart/ seems a bit backward. Then again, it is just a directory name ;)
And as we know, naming is hard :)
thanks,
greg k-h
Quoted 43 lines · Greg Kroah-Hartman
Quoted 42 lines · Marcel Holtmann
Hi Greg,
Quoted 39 lines
Quoted 11 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.Quoted 7 lines
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.It should be.
Quoted 2 lines
- Split out the controller for
uart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?What do you mean by "controller" drivers here? I didn't understand them in the code.
Quoted 4 lines
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?Why? Is the code as-is slow?
Quoted 2 lines
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
Quoted 8 lines
Quoted 4 lines
maybe we can get the Intel LnP driver ported over and see how that one works out. It is one of the more complex ones when it comes to bootloader and firmware loading. Maybe Loic can take a stab at this. We would then also see how we can map the ACPI tables into a driver.
Yes, I was going to complain about the OF-only bent of this patch, but I figured it would get fixed up once Rob started to use a "real" machine for his testing of this code :)
I fully expected that from you. :)
It is no different than any other bus we have. Each discovery/enumeration method needs hooks for matching and creating devices. It just happens that DT is the only one added ATM.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 4 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Yes, I like the idea (minor nit, you still have SPMI in a lot of places instead of UART), so I recommend keeping going with it.
Quoted 4 lines
drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 +++++++++++++++++++++++++++++++++++++++ drivers/uart/loopback.c | 72 ++++++
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Why not just put this in
drivers/tty/uart/?Is it really then a TTY at all. Would be the UART become the basic core for a TTY?
Hm, interesting idea. Not for all TTYs of course, but for those that are on UART devices, maybe? How would a usb-serial device fit into that picture?
DT overlay. Just like greybus serial. :)
That's a good question though as usb-serial doesn't use uart_port. Perhaps there needs to be a uart controller/host driver that's a line discipline so existing tty drivers can work. That somewhat defeats the point of getting line disciplines out of the picture, but would provide a solution for h/w hacking (and no worse than what can be supported today). Longer term, the drivers would need to be adapted to use the uart slave bus directly.
Rob
Quoted 20 lines · Greg Kroah-Hartman
Quoted 11 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.Quoted 7 lines
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
Quoted 7 lines
It should be.
Quoted 2 lines
- Split out the controller for
uart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?What do you mean by "controller" drivers here? I didn't understand them in the code.
The host uart driver. It's basically a wrapper around struct uart_port, but may need to evolve to have its own ops if we want to make using struct uart_port for driver. Maybe host would be a better name.
Quoted 6 lines
Quoted 4 lines
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?Why? Is the code as-is slow?
No, the code should be fast as it is so simple. I assume there is some reason the tty buffering is more complex than just a circular buffer. My best guess is because the tty layer has to buffer things for userspace and userspace can be slow to read? Do line disciplines make assumptions about the tty buffering? Is 4KB enough buffering?
Also, the current receive implementation has no concept of blocking or timeout. Should the uart_dev_rx() function return when there's no more data or wait (with timeout) until all requested data is received? (Probably do all of them is my guess).
Quoted 14 lines
Quoted 3 lines
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Yes, I like the idea (minor nit, you still have SPMI in a lot of places instead of UART), so I recommend keeping going with it.
Quoted 6 lines
Quoted 4 lines
drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 +++++++++++++++++++++++++++++++++++++++ drivers/uart/loopback.c | 72 ++++++Why not just put this in
drivers/tty/uart/?
Because it has nothing to do with the tty layer. If anything, I think the direction would be move drivers/tty/serial/ to drivers/uart/ (didn't they used to be in drivers/serial/? :)) i'm not proposing we do that though.
Rob
Quoted 2 lines
No, the code should be fast as it is so simple. I assume there is some reason the tty buffering is more complex than just a circular buffer.
I would suggest you read n_tty.c carefully and then it'll make a fair bit of sense. It has to interlock multiple reader/writes with discipline changes and flushes of pending data. At the same time a received character may cause output changes including bytes to be queued for transmit and the entire lot must not excessively recurse.
It's fun and it took years to make work safely but basically you need to handle a simultaneous ldisc change, config change, read of data from the buffers, receive, transmit and the receive causing the transmit status to change and maybe other transmits, that might have to be sent with priority. It's fun 8)
The good news is that nobody but n_tty and maybe n_irda cares on the rx side. Every other ldisc consumes the bytes immediately. IRDA hasn't worked for years anyway.
Quoted 3 lines
My best guess is because the tty layer has to buffer things for userspace and userspace can be slow to read? Do line disciplines make assumptions about the tty buffering? Is 4KB enough buffering?
RTFS but to save you a bit of effort
1. 4K is not enough, 64K is not always sufficient, this is why we have all the functionality you appear to want to re-invent already in the tty buffer logic of the tty_port
2. Only n_tty actually uses the tty_port layer buffering
3. The ring buffer used for dumb uarts is entirely about latency limits on low end processors and only used by some uarts anyway.
Quoted 4 lines
Also, the current receive implementation has no concept of blocking or timeout. Should the
uart_dev_rx()function return when there's no more data or wait (with timeout) until all requested data is received? (Probably do all of them is my guess).
Your rx routine needs to be able to run in IRQ context, not block and complete in very very short time scales because on some hardware you have exactly 9 bit times to recover the data byte and clear the IRQ done. Serial really stretches some of the low end embedded processors running at 56K/115200, and RS485 at 4Mbits even with 8 bytes of buffering is pretty tight. Thus you need very fast buffers for just about any use case. Dumb uarts you'll need to keep the existing ring buffer or similar (moving to a kfifo would slightly improve performance I think) and queue after.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
- Convert a real driver/line discipline over to UART bus.
That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
The locking. It's taken ten years to debug the current line discipline change locking. If you want to be able to switch stuff kernel side however it's somewhat easier.
The change should be
Add tty_port->rx(uint8_t *data,uint8_t *flags, unsigned int len)
The semantics of tty_port->rx are
- You may not assume a tty is bound to this port
- You may be called in IRQ context, but are guaranteed not to get parallel calls for the same port
- When you return the bytes you passed are history
At that point you can set tty_port->rx to point to the tty_flip_buffer_push() and everyone can use it. Slow ones will want to queue to a ring buffer then do tty_port->rx (where we do the flush_buffer now), fast ones will do the ->rx directly.
Having done that you can switch all the drivers over and test nothing breaks.
Now you can add your kernel mode support because you can do an atomic_xchg of the tty_port->rx pointer between the classic queue model and your direct interfaces. Not only that but so can n_ppp and some of the other performance sensitive interfaces.
With that done you can tweak the tty_port methods to permit a ttyless open/close and as everything else sits on top of that tty_port abstraction providing you manage the tty_port the rest works.
Some of that ripples into the drivers as there are few places the tty leaks into the tty_port methods but those are not hard to solve given the need. The port needs a copy of the termios flags, a few other helpers are needed to do non tty port opens/closes and call the relevant activation methods.
Alan
Quoted 23 lines · One Thousand Gnomes
Quoted 2 lines
No, the code should be fast as it is so simple. I assume there is some reason the tty buffering is more complex than just a circular buffer.
I would suggest you read
n_tty.ccarefully and then it'll make a fair bit of sense. It has to interlock multiple reader/writes with discipline changes and flushes of pending data. At the same time a received character may cause output changes including bytes to be queued for transmit and the entire lot must not excessively recurse.It's fun and it took years to make work safely but basically you need to handle a simultaneous ldisc change, config change, read of data from the buffers, receive, transmit and the receive causing the transmit status to change and maybe other transmits, that might have to be sent with priority. It's fun 8)
The good news is that nobody but
n_ttyand mayben_irdacares on the rx side. Every other ldisc consumes the bytes immediately. IRDA hasn't worked for years anyway.Quoted 3 lines
My best guess is because the tty layer has to buffer things for userspace and userspace can be slow to read? Do line disciplines make assumptions about the tty buffering? Is 4KB enough buffering?
Quoted 5 lines
RTFS but to save you a bit of effort
1. 4K is not enough, 64K is not always sufficient, this is why we have all the functionality you appear to want to re-invent already in the tty buffer logic of the
tty_port
I don't want to reinvent it which is why I'm asking.
Quoted 1 line
2. Only
n_ttyactually uses thetty_portlayer buffering
So the first point on 4K is not enough only applies to n_tty? If I don't need the tty_port buffer logic, then how am I re-inventing it?
Quoted 38 lines
3. The ring buffer used for dumb uarts is entirely about latency limits on low end processors and only used by some uarts anyway.
Quoted 4 lines
Also, the current receive implementation has no concept of blocking or timeout. Should the
uart_dev_rx()function return when there's no more data or wait (with timeout) until all requested data is received? (Probably do all of them is my guess).Your rx routine needs to be able to run in IRQ context, not block and complete in very very short time scales because on some hardware you have exactly 9 bit times to recover the data byte and clear the IRQ done. Serial really stretches some of the low end embedded processors running at 56K/115200, and RS485 at 4Mbits even with 8 bytes of buffering is pretty tight. Thus you need very fast buffers for just about any use case. Dumb uarts you'll need to keep the existing ring buffer or similar (moving to a kfifo would slightly improve performance I think) and queue after.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
- Convert a real driver/line discipline over to UART bus.
That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
The locking. It's taken ten years to debug the current line discipline change locking. If you want to be able to switch stuff kernel side however it's somewhat easier.
The change should be
Add
tty_port->rx(uint8_t *data,uint8_t *flags, unsigned int len)The semantics of
tty_port->rxare- You may not assume a tty is bound to this port
- You may be called in IRQ context, but are guaranteed not to get parallel calls for the same port
- When you return the bytes you passed are history
Quoted 4 lines
At that point you can set
tty_port->rxto point to thetty_flip_buffer_push()and everyone can use it. Slow ones will want to queue to a ring buffer then dotty_port->rx(where we do theflush_buffernow), fast ones will do the ->rx directly.
I think I understand this for rx, but let's back-up to the registration and transmit paths. tty_port and uart_port have nothing in common other than name, and tty_port has nothing to do with i/o. So we still need tty_operations which all take a tty_struct and implies a tty_driver. It seems to me we would need surgery all over the tty code to make chardev, ldisc and anything else I'm not aware of optional.
Rob
Quoted 4 lines
Quoted 1 line
2. Only
n_ttyactually uses thetty_portlayer bufferingSo the first point on 4K is not enough only applies to
n_tty? If I don't need thetty_portbuffer logic, then how am I re-inventing it?
There are two layers of buffering.
1. Some devices buffer bytes into an internal ring buffer in the uart layer and then kick a handler to push them into the tty layer separately to the IRQ. For dumb uarts that is pretty much unavoidable. At high speed you don't have time to do processing.
2. The majority of drivers use the tty_buffer.c buffering alone. Quite a few that use the #1 above could in fact just use this today but for historical reasons don't.
The buffering needed to meet latency needs to be sufficient for the hardware and is always needed on devices that have that problem.
The rest of the buffering functionality is in fact ultimately only used by n_tty because every other ldisc implements the receive function as
alloc something
copy the data
queue to somewhere
return
Quoted 8 lines
Quoted 4 lines
At that point you can set
tty_port->rxto point to thetty_flip_buffer_push()and everyone can use it. Slow ones will want to queue to a ring buffer then dotty_port->rx(where we do theflush_buffernow), fast ones will do the ->rx directly.I think I understand this for rx, but let's back-up to the registration and transmit paths.
tty_portanduart_porthave nothing in common other than name, andtty_porthas nothing to do with i/o. So
Yes they do - every uart has a tty_port.
Quoted 3 lines
we still need
tty_operationswhich all take atty_structand implies atty_driver. It seems to me we would need surgery all over the tty code to make chardev, ldisc and anything else I'm not aware of optional.
Very little today *needs* a tty attached. The callbacks already handle the no tty case (because they can be called asynchronously to a tty closing)
The open and close are doable directly, and it is deliberate and ready for this kind of use that we have port->ops->activate, tty_port_set_initialized() and tty_port_shutdown() so just need to add a couple of abstracted out bits of code to give us
tty_port_activate(); tty_port_shutdown();
as the pair of methods needed for non tty enabling/disabling of the port
Right now you need tty for transmission because tty manages the outbound queueing, and for termios changes. Termios is historically attached to the tty structure and the fact tty->ops->set_termio[sx] exists in tty-> is just a historical quirk. They can just move.
The writing part is slightly harder to untangle. The tty->ops->write() passes a tty and there are three ways that gets used
1. tty->driver_data to get the underlying device object. That can easily be moved to port->driver_data
2. access to flow control state tty->stopped and tty->hw_stopped.
Again these can migrate along with the termios bits that are rferenced
3. Calling back to do wakeups, throttle and unthrottle
These again could be migrated to the port, and whatever port writing method you implement will anyway have to implement this simply because you have to do flow control and in some cases flow control is pure software.
The transmit side is the hardest part by far but the infrastructure is there, and already handles the nasty cases you'll have to deal with like a transmit being triggered from a receive.
Alan
Quoted 67 lines · One Thousand Gnomes
Quoted 2 lines
No, the code should be fast as it is so simple. I assume there is some reason the tty buffering is more complex than just a circular buffer.
I would suggest you read
n_tty.ccarefully and then it'll make a fair bit of sense. It has to interlock multiple reader/writes with discipline changes and flushes of pending data. At the same time a received character may cause output changes including bytes to be queued for transmit and the entire lot must not excessively recurse.It's fun and it took years to make work safely but basically you need to handle a simultaneous ldisc change, config change, read of data from the buffers, receive, transmit and the receive causing the transmit status to change and maybe other transmits, that might have to be sent with priority. It's fun 8)
The good news is that nobody but
n_ttyand mayben_irdacares on the rx side. Every other ldisc consumes the bytes immediately. IRDA hasn't worked for years anyway.Quoted 3 lines
My best guess is because the tty layer has to buffer things for userspace and userspace can be slow to read? Do line disciplines make assumptions about the tty buffering? Is 4KB enough buffering?
RTFS but to save you a bit of effort
1. 4K is not enough, 64K is not always sufficient, this is why we have all the functionality you appear to want to re-invent already in the tty buffer logic of the
tty_port
2. Onlyn_ttyactually uses thetty_portlayer buffering
3. The ring buffer used for dumb uarts is entirely about latency limits on low end processors and only used by some uarts anyway.Quoted 4 lines
Also, the current receive implementation has no concept of blocking or timeout. Should the
uart_dev_rx()function return when there's no more data or wait (with timeout) until all requested data is received? (Probably do all of them is my guess).Your rx routine needs to be able to run in IRQ context, not block and complete in very very short time scales because on some hardware you have exactly 9 bit times to recover the data byte and clear the IRQ done. Serial really stretches some of the low end embedded processors running at 56K/115200, and RS485 at 4Mbits even with 8 bytes of buffering is pretty tight. Thus you need very fast buffers for just about any use case. Dumb uarts you'll need to keep the existing ring buffer or similar (moving to a kfifo would slightly improve performance I think) and queue after.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
- Convert a real driver/line discipline over to UART bus.
That's going to be the real test, I recommend trying that as soon as possible as it will show where the real pain points are :)
The locking. It's taken ten years to debug the current line discipline change locking. If you want to be able to switch stuff kernel side however it's somewhat easier.
The change should be
Add
tty_port->rx(uint8_t *data,uint8_t *flags, unsigned int len)The semantics of
tty_port->rxare- You may not assume a tty is bound to this port
- You may be called in IRQ context, but are guaranteed not to get parallel calls for the same port
- When you return the bytes you passed are history
Quoted 4 lines
At that point you can set
tty_port->rxto point to thetty_flip_buffer_push()and everyone can use it. Slow ones will want to queue to a ring buffer then dotty_port->rx(where we do theflush_buffernow), fast ones will do the ->rx directly.
Other than doing DMA, I did not find any examples of UARTs doing internal rx ring buffers. Most/all the non-DMA cases do tty_insert_flip_char directly in the ISR. The flow is insert a series of flags and characters as we process the receive status and then trigger a flush of the buffer at the end. That doesn't match up with what you are proposing for how tty_port->rx would work. That would change the receive ISR processing in all the drivers quite a bit. Either we'd have to call tty_port->rx a character at a time or implement some temporary buffer. I don't think we want to call things like BT receive code a byte at a time. This needs to be a layer higher. flush_to_ldisc either needs to be duplicated to handle tty_port->rx or generalized to call either tty_port->rx or ldisc receive_buf. I'm not sure what to do about ldisc ref counting in the latter case.
Rob
Quoted 7 lines
Either we'd have to call
tty_port->rxa character at a time or implement some temporary buffer. I don't think we want to call things like BT receive code a byte at a time. This needs to be a layer higher.flush_to_ldisceither needs to be duplicated to handletty_port->rxor generalized to call eithertty_port->rxor ldiscreceive_buf. I'm not sure what to do about ldisc ref counting in the latter case.
You already have the buffer
What I was trying to suggest was that instead of
chars->buffer
flush
workqueue
loop pushing data into the ldisc
You can also do
chars->buffer
flush
workqueue
->rx() [where flush_to_ldisc is just one implementation of ->rx]
For byte by byte ports it really makes no difference (except you would be able to do processing without an ldisc), but for DMA devices it would give us a faster path for processing since the DMA completion event can simply fire a buffer a characters directly at the protocol handler where there are not latency concerns (ie it starts the new DMA and directly involves ->rx())
Alan
Hi Rob,
many thanks for picking up this unsolved topic!
Quoted 4 lines
Am 18.08.2016 um 03:14 schrieb Rob Herring <[email protected]>:
=20
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line =
disciplines,
Quoted 1 line
various platform drivers to handle some sideband, and in userspace =
with
Quoted 3 lines
utilities such as hciattach.
=20
There have been several attempts to improve support, but they suffer =
from
Quoted 1 line
still being tied into the tty layer and/or abusing the platform bus. =
This
Quoted 1 line
is a prototype to show creating a proper UART bus for UART devices. It =
is
Quoted 1 line
tied into the serial core (really struct
uart_port) below the tty =
layer
Quoted 4 lines
in order to use existing serial drivers.
=20
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the =
slave
Quoted 4 lines
device). It still needs lots of work and polish.
=20
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? =
I'm
Quoted 2 lines
hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we =
see
Quoted 3 lines
a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. =
DMA)
Quoted 6 lines
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus. =20
Before I spend more time on this, I'm looking mainly for feedback on =
the
Quoted 1 line
general direction and structure (the interface with the existing =
serial
Quoted 1 line
drivers in particular).
Some quick comments (can't do any real life tests in the next weeks) = from my (biased) view:
* tieing the solution into uart_port is the same as we had done. The = difference seems to
me that you completely bypass serial_core (and tty) while we want to =
integrate it with standard tty operation.
We have tapped the tty layer only because it can not be 100% avoided =
if we use serial_core.
* one feedback I had received was that there may be uart device drivers = not using serial_core. I am not sure if your approach addresses that.
* what I don't see is how we can implement our GPS device power control = driver:
- the device should still present itself as a tty device (so that cat =/dev/ttyO1 reports NMEA records) and should
not be completely hidden from user space or represented by a new =
interface type invented just for this device
(while the majority of other GPS receivers are still simple tty =
devices).
- how we can detect that the device is sending data to the UART while =
no user space process has the uart port open
i.e. when does the driver know when to start/stop the UART.
* I like that a driver can simply call uart_dev_config(udev, 115200, = 'n', 8, 0); instead of our
uart_register_rx_notification(data->uart, rx_notification, =
&termios); where we have to partially
fill the termios structure.
* it appears to need more code than our proposal did:
Quoted 9 lines
=20
Rob
=20
=20
Rob Herring (3):
uart bus: Introduce new bus for UART slave devices
tty:serial_core: maketty_structoptional
tty:serial_core: add uart controller registration
=20
Quoted 7 lines
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/tty/serial/serial_core.c | 11 +- drivers/tty/tty_buffer.c | 2 + drivers/uart/Kconfig | 17 ++ drivers/uart/Makefile | 3 + drivers/uart/core.c | 458 =
+++++++++++++++++++++++++++++++++++++++
Quoted 9 lines
drivers/uart/loopback.c | 72 ++++++ include/linux/serial_core.h | 3 +- include/linux/uart_device.h | 163 ++++++++++++++ 10 files changed, 730 insertions(+), 2 deletions(-)create mode 100644
drivers/uart/Kconfig
create mode 100644drivers/uart/Makefile
create mode 100644drivers/uart/core.c
create mode 100644drivers/uart/loopback.c
create mode 100644include/linux/uart_device.h
thereof 9 files, ~650 changes w/o loopback demo
vs.
Quoted 5 lines · H. Nikolaus Schaller
Quoted 4 lines
H. Nikolaus Schaller (3):
tty: serial core: provide a method to search uart by phandle
tty:serial_core: add hooks for uart slave drivers
misc: Add w2sg0004 gps receiver driver
Quoted 8 lines
Quoted 8 lines
=20
.../devicetree/bindings/misc/wi2wi,w2sg0004.txt | 18 + .../devicetree/bindings/serial/slaves.txt | 16 + .../devicetree/bindings/vendor-prefixes.txt | 1 + Documentation/serial/slaves.txt | 36 ++ drivers/misc/Kconfig | 18 + drivers/misc/Makefile | 1 + drivers/misc/w2sg0004.c | 443 =
+++++++++++++++++++++
Quoted 5 lines
Quoted 5 lines
drivers/tty/serial/serial_core.c | 214 +++++++++- include/linux/serial_core.h | 25 +- include/linux/w2sg0004.h | 27 ++ 10 files changed, 793 insertions(+), 6 deletions(-)create mode 100644 =
Documentation/devicetree/bindings/misc/wi2wi,w2sg0004.txt
Quoted 1 line
Quoted 1 line
create mode 100644 =
Documentation/devicetree/bindings/serial/slaves.txt
Quoted 3 lines
Quoted 3 lines
create mode 100644
Documentation/serial/slaves.txtcreate mode 100644drivers/misc/w2sg0004.ccreate mode 100644include/linux/w2sg0004.h
Thereof 4 files, ~260 changes w/o gps demo and documentation/bindings.
BR and thanks,
Nikolaus
Quoted 3 lines
Thereof 4 files, ~260 changes w/o gps demo and documentation/bindings.
So what do you use for the serial devices? platform_device was vetoed for that purpose by Greg.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi Pavel,
Quoted 5 lines
Am 18.08.2016 um 12:47 schrieb Pavel Machek <[email protected]>:
=20
=20Quoted 2 lines
=20
Thereof 4 files, ~260 changes w/o gps demo and =
documentation/bindings.
Quoted 3 lines
=20
So what do you use for the serial devices?platform_devicewas vetoed for that purpose by Greg.
device tree?
This adds code of course - but only for the slave drivers. So you = shouldn't count
them for a fair comparison of what it means for implementing a new API.
Greg Kroah-Hartman
maintainerQuoted 6 lines · H. Nikolaus Schaller
Hi Pavel,
Quoted 4 lines
Am 18.08.2016 um 12:47 schrieb Pavel Machek <[email protected]>:
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thereof 4 files, ~260 changes w/o gps demo and documentation/bindings.
So what do you use for the serial devices?
platform_devicewas vetoed for that purpose by Greg.device tree?
No.
This patchset from Rob is the way I have been saying it should be done for years now. Yes, a "bus" takes up more boilerplate code (blame me for that), but overall, it makes the drivers simpler, and fits into the rest of the kernel driver/device model much better.
greg k-h
Hi Greg,
Quoted 1 line
Am 18.08.2016 um 12:57 schrieb Greg Kroah-Hartman =
Quoted 9 lines
=20
Quoted 7 lines · H. Nikolaus Schaller
Hi Pavel,
=20Quoted 5 lines
Am 18.08.2016 um 12:47 schrieb Pavel Machek <[email protected]>:
=20
=20Quoted 2 lines
=20
Thereof 4 files, ~260 changes w/o gps demo and =
documentation/bindings.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
=20
So what do you use for the serial devices?platform_devicewas =
vetoed
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
for that purpose by Greg.
=20
device tree?=20
No.
? Sorry, but each time Pavel jumps in, he just copies half of a = statement and
any reply gets misunderstood.
I did not even mention platform_device, still you disagree to device = tree for the
*slave driver*?
Quoted 4 lines
=20
This patchset from Rob is the way I have been saying it should be done for years now. Yes, a "bus" takes up more boilerplate code (blame me for that), but overall, it makes the drivers simpler,
Sorry, but I don't see how Rob's approach makes it simpler to write a = device driver
than our original proposal, which btw is also sort of a bus and I see = only some implementation
differences.
Except that IMHO Rob's approach lacks functions we need (which maybe can = added).
Quoted 2 lines
and fits into the
rest of the kernel driver/device model much better.
BR and thanks,
Nikolaus=
Quoted 12 lines · On Thu, 18 Aug 2016 12:57:59 +0200 Greg Kroah-Hartman…
Quoted 11 lines · H. Nikolaus Schaller
Hi Pavel,
Quoted 8 lines
Am 18.08.2016 um 12:47 schrieb Pavel Machek <[email protected]>:
Quoted 2 lines
Thereof 4 files, ~260 changes w/o gps demo and documentation/bindings.
So what do you use for the serial devices?
platform_devicewas vetoed for that purpose by Greg.
Quoted 8 lines
Quoted 1 line
device tree?
No.
This patchset from Rob is the way I have been saying it should be done for years now. Yes, a "bus" takes up more boilerplate code (blame me for that), but overall, it makes the drivers simpler, and fits into the rest of the kernel driver/device model much better.
The basic problem is that the bus should be tty_ports not uart, fix that and the rest starts to make sense.
Alan
Greg Kroah-Hartman
maintainerQuoted 19 lines · One Thousand Gnomes
Quoted 16 lines · On Thu, 18 Aug 2016 12:57:59 +0200 Greg Kroah-Hartman…
Quoted 6 lines · H. Nikolaus Schaller
Hi Pavel,
Quoted 4 lines
Am 18.08.2016 um 12:47 schrieb Pavel Machek <[email protected]>:
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Thereof 4 files, ~260 changes w/o gps demo and documentation/bindings.
So what do you use for the serial devices?
platform_devicewas vetoed for that purpose by Greg.device tree?
No.
Quoted 7 lines
Quoted 4 lines
This patchset from Rob is the way I have been saying it should be done for years now. Yes, a "bus" takes up more boilerplate code (blame me for that), but overall, it makes the drivers simpler, and fits into the rest of the kernel driver/device model much better.
The basic problem is that the bus should be
tty_portsnot uart, fix that and the rest starts to make sense.
Ok, that makes sense, I missed that in the long "discussion" that happened last time about this topic...
thanks,
greg k-h
Because it was misunderstood, here a longer answer.
Quoted 7 lines
Am 18.08.2016 um 12:47 schrieb Pavel Machek <[email protected]>:
Quoted 2 lines
Thereof 4 files, ~260 changes w/o gps demo and documentation/bindings.
So what do you use for the serial devices?
You misunderstood the w/o documentation/bindings in a way that the full patch set doesn't use it. But it means changes w/o these aspects...
Quoted 2 lines
platform_devicewas vetoed
for that purpose by Greg.
That is true but not relevant at all since nobody wants to introduce platform_device again.
I have just removed these from counting differences to make the number of lines comparable to Rob's proposal.
Rob also uses device tree but has not added bindings or documentation to his patch set so that it would be unfair to include them in the changes count in one proposal and omit it in the other.
Generally it might not even be important to compare both approaches again and then the number of files / changes is not important. But if it is, we should count them correctly.
Marcel Holtmann
maintainerHi Nikolaus,
Quoted 38 lines
Quoted 27 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Some quick comments (can't do any real life tests in the next weeks) from my (biased) view:
* tieing the solution into
uart_portis the same as we had done. The difference seems to
me that you completely bypassserial_core(and tty) while we want to integrate it with standard tty operation.We have tapped the tty layer only because it can not be 100% avoided if we use
serial_core.
Quoted 8 lines
* one feedback I had received was that there may be uart device drivers not using
serial_core. I am not sure if your approach addresses that.* what I don't see is how we can implement our GPS device power control driver:
- the device should still present itself as a tty device (so that cat/dev/ttyO1reports NMEA records) and should not be completely hidden from user space or represented by a new interface type invented just for this device (while the majority of other GPS receivers are still simple tty devices).
- how we can detect that the device is sending data to the UART while no user space process has the uart port open i.e. when does the driver know when to start/stop the UART.
I am actually not convinced that GPS should be represented as /dev/ttyS0 or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.
Such a driver then can also take care of the power control on open() and close(). As it should be done in the first place. And then we can also remove the RFKILL hacks for GPS devices as well. For example that is what Intel and Broadcom Bluetooth devices do now. The power control is hooked into hciconfig hci0 up/down.
Regards
Marcel
Greg Kroah-Hartman
maintainerQuoted 49 lines · Marcel Holtmann
Hi Nikolaus,
Quoted 38 lines
Quoted 27 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Some quick comments (can't do any real life tests in the next weeks) from my (biased) view:
* tieing the solution into
uart_portis the same as we had done. The difference seems to
me that you completely bypassserial_core(and tty) while we want to integrate it with standard tty operation.We have tapped the tty layer only because it can not be 100% avoided if we use
serial_core.Quoted 8 lines
* one feedback I had received was that there may be uart device drivers not using
serial_core. I am not sure if your approach addresses that.* what I don't see is how we can implement our GPS device power control driver:
- the device should still present itself as a tty device (so that cat/dev/ttyO1reports NMEA records) and should not be completely hidden from user space or represented by a new interface type invented just for this device (while the majority of other GPS receivers are still simple tty devices).
- how we can detect that the device is sending data to the UART while no user space process has the uart port open i.e. when does the driver know when to start/stop the UART.
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.
I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
thanks,
greg k-h
Marcel Holtmann
maintainerHi Greg,
Quoted 53 lines
Quoted 47 lines
Quoted 38 lines
Quoted 27 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Some quick comments (can't do any real life tests in the next weeks) from my (biased) view:
* tieing the solution into
uart_portis the same as we had done. The difference seems to
me that you completely bypassserial_core(and tty) while we want to integrate it with standard tty operation.We have tapped the tty layer only because it can not be 100% avoided if we use
serial_core.Quoted 8 lines
* one feedback I had received was that there may be uart device drivers not using
serial_core. I am not sure if your approach addresses that.* what I don't see is how we can implement our GPS device power control driver:
- the device should still present itself as a tty device (so that cat/dev/ttyO1reports NMEA records) and should not be completely hidden from user space or represented by a new interface type invented just for this device (while the majority of other GPS receivers are still simple tty devices).
- how we can detect that the device is sending data to the UART while no user space process has the uart port open i.e. when does the driver know when to start/stop the UART.Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.
Quoted 3 lines
I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
we have a GPS line discipline? What is that one doing? As far as I know all GPS implementations are fully userspace.
Regards
Marcel
Greg Kroah-Hartman
maintainerQuoted 55 lines · Marcel Holtmann
Hi Greg,
Quoted 53 lines
Quoted 52 lines
Quoted 38 lines
Quoted 27 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Some quick comments (can't do any real life tests in the next weeks) from my (biased) view:
* tieing the solution into
uart_portis the same as we had done. The difference seems to
me that you completely bypassserial_core(and tty) while we want to integrate it with standard tty operation.We have tapped the tty layer only because it can not be 100% avoided if we use
serial_core.Quoted 8 lines
* one feedback I had received was that there may be uart device drivers not using
serial_core. I am not sure if your approach addresses that.* what I don't see is how we can implement our GPS device power control driver:
- the device should still present itself as a tty device (so that cat/dev/ttyO1reports NMEA records) and should not be completely hidden from user space or represented by a new interface type invented just for this device (while the majority of other GPS receivers are still simple tty devices).
- how we can detect that the device is sending data to the UART while no user space process has the uart port open i.e. when does the driver know when to start/stop the UART.I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.
Quoted 6 lines
Quoted 3 lines
I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
we have a GPS line discipline? What is that one doing? As far as I know all GPS implementations are fully userspace.
Hm, for some reason I thought that was what n_gsm.c was being used for, but I could be wrong, I've never seen the hardware that uses that code...
greg k-h
Hi!
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
we have a GPS line discipline? What is that one doing? As far as I know all GPS implementations are fully userspace.
Hm, for some reason I thought that was what
n_gsm.cwas being used for, but I could be wrong, I've never seen the hardware that uses that code...
n_gsm.c seems to be multiplexing support. Splits one serial link into multiple "virtual" serial links. Nothing to do with GPS explicitely, altrough it looks NMEA data is going to go over one of the channels sometimes.
I guess we should care about that later...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Marcel Holtmann
maintainerHi Greg,
Quoted 57 lines
Quoted 57 lines
Quoted 56 lines
Quoted 47 lines
Quoted 38 lines
Quoted 27 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Some quick comments (can't do any real life tests in the next weeks) from my (biased) view:
* tieing the solution into
uart_portis the same as we had done. The difference seems to
me that you completely bypassserial_core(and tty) while we want to integrate it with standard tty operation.We have tapped the tty layer only because it can not be 100% avoided if we use
serial_core.Quoted 8 lines
* one feedback I had received was that there may be uart device drivers not using
serial_core. I am not sure if your approach addresses that.* what I don't see is how we can implement our GPS device power control driver:
- the device should still present itself as a tty device (so that cat/dev/ttyO1reports NMEA records) and should not be completely hidden from user space or represented by a new interface type invented just for this device (while the majority of other GPS receivers are still simple tty devices).
- how we can detect that the device is sending data to the UART while no user space process has the uart port open i.e. when does the driver know when to start/stop the UART.Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
Quoted 6 lines
Quoted 2 lines
we have a GPS line discipline? What is that one doing? As far as I know all GPS implementations are fully userspace.
Hm, for some reason I thought that was what
n_gsm.cwas being used for, but I could be wrong, I've never seen the hardware that uses that code...
the n_gsm.c is for 3GPP TS 07.10. Which is a TTY multiplexer. Has nothing to do with GPS.
Regards
Marcel
Quoted 5 lines
Quoted 3 lines
Hm, for some reason I thought that was what
n_gsm.cwas being used for, but I could be wrong, I've never seen the hardware that uses that code...the
n_gsm.cis for 3GPP TS 07.10. Which is a TTY multiplexer. Has nothing to do with GPS.
Except that you may get GPS over 3GPP TS 07.10 (ditto firmware upload!)
Alan
Quoted 6 lines
Quoted 2 lines
we have a GPS line discipline? What is that one doing? As far as I know all GPS implementations are fully userspace.
Hm, for some reason I thought that was what
n_gsm.cwas being used for, but I could be wrong, I've never seen the hardware that uses that code...
You probably have actually. It's the standard multiplexing protocol on lots of 3G modems. It's an AT command that switches mode.
However it illustrates the kind of problems with trying to short circuit the tty_port code. It's entirely possible for a modem to expose the GPS on a channel of the multiplex on the USB connection to the modem which is itself dynamic and can be hot unplugged.
Short circuiting the tty_port layer is not a trivial exercise.
Alan
Hi!
Quoted 9 lines
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
./drivers/usb/serial/garmin_gps.c ?
Hmm, some cleanups would be welcome there... plus it would be good to know what is its interface to userland... it is not easily apparent from the code.
Actually, having some kind of common support for GPSes in the kernel would be nice. (Chardev that spits NMEA data?) For example N900 GPS is connected over network (phonet) interface, with userland driver translating custom protocol into NMEA. Not very nice from "kernel should provide hardware abstraction" point of view.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 15 lines
Am 18.08.2016 um 13:10 schrieb Pavel Machek <[email protected]>:
Hi!
Quoted 9 lines
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
Quoted 8 lines
./drivers/usb/serial/garmin_gps.c?Hmm, some cleanups would be welcome there... plus it would be good to know what is its interface to userland... it is not easily apparent from the code.
Actually, having some kind of common support for GPSes in the kernel would be nice. (Chardev that spits NMEA data?
Yes and no. How do you apply tcsetattr to such a device? More or less by implementing another tty stack?
Quoted 4 lines
) For example N900 GPS is
connected over network (phonet) interface, with userland driver translating custom protocol into NMEA. Not very nice from "kernel should provide hardware abstraction" point of view.
Indeed. In such a case the translation should be done in the kernel. But it is not necessary for devices that already provide NEMA over UART. Still user-space should be able to tcsetattr how it wants to see the records (mainly CR/LF translations).
BR,
Nikolaus
Marcel Holtmann
maintainerHi Nikolaus,
Quoted 27 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
Quoted 8 lines
./drivers/usb/serial/garmin_gps.c?Hmm, some cleanups would be welcome there... plus it would be good to know what is its interface to userland... it is not easily apparent from the code.
Actually, having some kind of common support for GPSes in the kernel would be nice. (Chardev that spits NMEA data?
Yes and no. How do you apply tcsetattr to such a device? More or less by implementing another tty stack?
Quoted 4 lines
) For example N900 GPS is
connected over network (phonet) interface, with userland driver translating custom protocol into NMEA. Not very nice from "kernel should provide hardware abstraction" point of view.
Quoted 4 lines
Indeed. In such a case the translation should be done in the kernel. But it is not necessary for devices that already provide NEMA over UART. Still user-space should be able to tcsetattr how it wants to see the records (mainly CR/LF translations).
I disagree here. NMEA is a standard and the kernel should just enforce framing of NMEA sentences. It makes no difference what the CR/LF is. Userspace gets full sentences.
Regards
Marcel
Quoted 18 lines
Am 18.08.2016 um 13:49 schrieb Marcel Holtmann <[email protected]>:
=20
Hi Nikolaus,
=20Quoted 13 lines
Quoted 13 lines
Quoted 9 lines
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.=20
I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?=20
./drivers/usb/serial/garmin_gps.c?
=20
Hmm, some cleanups would be welcome there... plus it would be good =
to
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
know what is its interface to userland... it is not easily apparent from the code.
=20
Actually, having some kind of common support for GPSes in the kernel would be nice. (Chardev that spits NMEA data?=20
Yes and no. How do you apply tcsetattr to such a device? More or less by implementing another tty stack?
=20
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
) For example N900 GPS is
connected over network (phonet) interface, with userland driver translating custom protocol into NMEA. Not very nice from "kernel should provide hardware abstraction" point of view.=20
Indeed. In such a case the translation should be done in the kernel. But it is not necessary for devices that already provide NEMA over =
UART.
Quoted 1 line
Quoted 1 line
Still user-space should be able to tcsetattr how it wants to see the =
records
Quoted 3 lines
Quoted 1 line
(mainly CR/LF translations).
=20
I disagree here. NMEA is a standard and the kernel should just enforce =
framing of NMEA sentences.
AFAIR, NMEA was originally sort of a serial bus going through a ship. = Where masters (a gps receiver)
can send records with position and speed data and clients (e.g. an = auto-pilot) can receive them and
process their actions and send control commands to a motor / winding = engine. But I would have to do
more research about this.
Quoted 1 line
It makes no difference what the CR/LF is. Userspace gets full =
sentences.
NMEA defines that devices connected to the NMEA source receive = characters and not sentences.
For example an NMEA record defines a checksum. Should that also be = exposed to user space or hidden?
How should checksum errors be reported or handled by the kernel?
I would agree if we want to write an abstract "position in geospace" = driver/subsystem which reports
the position on surface and height and speed and direction. Then we can = hide everything in the kernel.
But this would no longer send sentences to user space but cooked = coordinates. More like iio data.
And next issue: how should we handle GPS devices with a bidirectional = interface where sending
some special command sequence over the UART switches to SIRF or some = other proprietary
mode? Then, the driver (ans Linux) can't squeeze that into NMEA = sentences any more. By
doing this in the kernel we make it more inflexible.
Puh, when digging into this topic it becomes more and more complex and = we are making it more
complex than it is currently working.
BR,
Nikolaus
Quoted 6 lines
Quoted 4 lines
Indeed. In such a case the translation should be done in the kernel. But it is not necessary for devices that already provide NEMA over UART. Still user-space should be able to tcsetattr how it wants to see the records (mainly CR/LF translations).
I disagree here. NMEA is a standard and the kernel should just enforce framing of NMEA sentences. It makes no difference what the CR/LF is. Userspace gets full sentences.
GPS drivers for anything that's dumb are binary only. They have to contain specific checks so that people can't buy them from amazon and attach them to missles.
Alan
Marcel Holtmann
maintainerHi Pavel,
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
Quoted 5 lines
./drivers/usb/serial/garmin_gps.c?Hmm, some cleanups would be welcome there... plus it would be good to know what is its interface to userland... it is not easily apparent from the code.
however that driver is not a line discipline. That is just an USB driver. But I agree if we create a GPS driver framework / subsystem, then this one should be converted into using it.
Quoted 5 lines
Actually, having some kind of common support for GPSes in the kernel would be nice. (Chardev that spits NMEA data?) For example N900 GPS is connected over network (phonet) interface, with userland driver translating custom protocol into NMEA. Not very nice from "kernel should provide hardware abstraction" point of view.
I agree that if we just had a dedicated GPS NMEA char device, then that would be great. However we might just add an additional /dev/unmea like /dev/uinput, /dev/uhid, /dev/vhci. It could be used for unit testing and also hardware where the protocol is in userspace in the first. Like the mentioned QMI or some Intel AT command based modem. We would then just convert oFono to create the /dev/unmea device for us. The advantage is that then even userspace NMEA device are part of the device tree and enumerated by udev.
Regards
Marcel
Hi!
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
Quoted 8 lines
Quoted 5 lines
./drivers/usb/serial/garmin_gps.c?Hmm, some cleanups would be welcome there... plus it would be good to know what is its interface to userland... it is not easily apparent from the code.
however that driver is not a line discipline. That is just an USB driver. But I agree if we create a GPS driver framework / subsystem, then this one should be converted into using it.
Aha.
Quoted 8 lines
Quoted 5 lines
Actually, having some kind of common support for GPSes in the kernel would be nice. (Chardev that spits NMEA data?) For example N900 GPS is connected over network (phonet) interface, with userland driver translating custom protocol into NMEA. Not very nice from "kernel should provide hardware abstraction" point of view.
I agree that if we just had a dedicated GPS NMEA char device, then that would be great. However we might just add an additional
/dev/unmealike/dev/uinput,/dev/uhid,/dev/vhci. It could be used for unit testing and also hardware where the protocol is in userspace in the first. Like the mentioned QMI or some Intel AT command based modem. We would then just convert oFono to create the/dev/unmeadevice for us. The advantage is that then even userspace NMEA device are part of the device tree and enumerated by udev.
Yep, that would make sense, one day. (Another discussion is if NMEA is
the right protocol to use for kernel<->user interface, esr has some rather good reasons to believe it is not. But that, too, can wait...)
Anyway, whatever works for bluetooth is likely to work for future gps subsystem, so we should be ok here. And having support for serial devices (not pretending they are platform) is a good step forward.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 12 lines · On Thu, 18 Aug 2016 13:47:44 +0200 Marcel Holtmann <[email protected]> wrote:
Hi Pavel,
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.I would _love_ to see that happen, but what about the GPS line discipline that we have today? How would that match up with a char device driver?
Quoted 7 lines
Quoted 5 lines
./drivers/usb/serial/garmin_gps.c?Hmm, some cleanups would be welcome there... plus it would be good to know what is its interface to userland... it is not easily apparent from the code.
however that driver is not a line discipline. That is just an USB driver. But I agree if we create a GPS driver framework / subsystem, then this one should be converted into using it.
You can't convert it - you can duplicate it or pipe the data into an additional driver, but converting it would break back compatibility for existing configurations and violate Linus no regressions rule.
Alan
Hi Marcel,
Quoted 6 lines
Am 18.08.2016 um 12:49 schrieb Marcel Holtmann <[email protected]>:
=20
Hi Nikolaus,
=20Quoted 2 lines
Quoted 2 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line =
disciplines,
Quoted 1 line
Quoted 1 line
Quoted 1 line
various platform drivers to handle some sideband, and in userspace =
with
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
utilities such as hciattach.
=20
There have been several attempts to improve support, but they suffer =
from
Quoted 1 line
Quoted 1 line
Quoted 1 line
still being tied into the tty layer and/or abusing the platform bus. =
This
Quoted 1 line
Quoted 1 line
Quoted 1 line
is a prototype to show creating a proper UART bus for UART devices. =
It is
Quoted 1 line
Quoted 1 line
Quoted 1 line
tied into the serial core (really struct
uart_port) below the tty =
layer
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
in order to use existing serial drivers.
=20
This is functional with minimal testing using the loopback driver =
and
Quoted 1 line
Quoted 1 line
Quoted 1 line
pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the =
slave
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
device). It still needs lots of work and polish.
=20
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? =
I'm
Quoted 1 line
Quoted 1 line
Quoted 1 line
hoping all that complexity is from the tty layer and not needed =
here.
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Split out the controller for
uart_portsinto separate driver. Do =
we see
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. =
DMA)
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Need better receive buffering than just a simple circular buffer =
or
Quoted 1 line
Quoted 1 line
Quoted 1 line
perhaps a different receive interface (e.g. direct to client =
buffer)?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus. =20
Before I spend more time on this, I'm looking mainly for feedback on =
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
general direction and structure (the interface with the existing =
serial
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
drivers in particular).
=20
Some quick comments (can't do any real life tests in the next weeks) =
from my (biased) view:
Quoted 2 lines
Quoted 2 lines
=20
* tieing the solution intouart_portis the same as we had done. The =
difference seems to
Quoted 1 line
Quoted 1 line
me that you completely bypass
serial_core(and tty) while we want to =
integrate it with standard tty operation.
Quoted 2 lines
Quoted 2 lines
=20
We have tapped the tty layer only because it can not be 100% avoided =
if we use serial_core.
Quoted 2 lines
Quoted 2 lines
=20
* one feedback I had received was that there may be uart device =
drivers not using serial_core. I am not sure if your approach addresses = that.
Quoted 2 lines
Quoted 2 lines
=20
* what I don't see is how we can implement our GPS device power =
control driver:
Quoted 1 line
Quoted 1 line
- the device should still present itself as a tty device (so that cat =
/dev/ttyO1 reports NMEA records) and should
Quoted 1 line
Quoted 1 line
not be completely hidden from user space or represented by a new =
interface type invented just for this device
Quoted 1 line
Quoted 1 line
(while the majority of other GPS receivers are still simple tty =
devices).
Quoted 1 line
Quoted 1 line
- how we can detect that the device is sending data to the UART while =
no user space process has the uart port open
Quoted 3 lines
Quoted 1 line
i.e. when does the driver know when to start/stop the UART.
=20
I am actually not convinced that GPS should be represented as =
/dev/ttyS0 or similar TTY. It think they deserve their own driver = exposing them as simple character devices. That way we can have a proper = DEVTYPE and userspace can find them correctly. We can also annotate them = if needed for special settings.
Yes, we can. But AFAIK no user space GPS client is expecting to have a = new DEVTYPE.
I have several different GPS devices. One is by bluetooth. So I get a = /dev/tty through hci. Another one has an USB cable. I get a /dev/tty = through some USB serial converter. A third one is integrated in a 4G = modem which provides a /dev/ttyACM port. So I always get something which = looks like a /dev/tty... Seems to be pretty standard.
Yes it would be nice to have a /dev/gps2 device.
And how do you want to control if the gps device should send records = with cr / lf (INLCR, IGNCR)? Can you use tcsetattr?
Quoted 2 lines
=20
Such a driver then can also take care of the power control onopen()=
and close(). As it should be done in the first place.
Yes it could do that as well.
Quoted 1 line
And then we can also remove the RFKILL hacks for GPS devices as well. =
For example that is what Intel and Broadcom Bluetooth devices do now. = The power control is hooked into hciconfig hci0 up/down.
Quoted 5 lines
=20
Regards
=20
Marcel
=20
BR,
Nikolaus
Marcel Holtmann
maintainerHi Nikolaus,
Quoted 47 lines
Quoted 47 lines
Quoted 46 lines
Quoted 27 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Some quick comments (can't do any real life tests in the next weeks) from my (biased) view:
* tieing the solution into
uart_portis the same as we had done. The difference seems to
me that you completely bypassserial_core(and tty) while we want to integrate it with standard tty operation.We have tapped the tty layer only because it can not be 100% avoided if we use
serial_core.* one feedback I had received was that there may be uart device drivers not using
serial_core. I am not sure if your approach addresses that.* what I don't see is how we can implement our GPS device power control driver:
- the device should still present itself as a tty device (so that cat/dev/ttyO1reports NMEA records) and should not be completely hidden from user space or represented by a new interface type invented just for this device (while the majority of other GPS receivers are still simple tty devices).
- how we can detect that the device is sending data to the UART while no user space process has the uart port open i.e. when does the driver know when to start/stop the UART.
Quoted 3 lines
Quoted 1 line
I am actually not convinced that GPS should be represented as
/dev/ttyS0or similar TTY. It think they deserve their own driver exposing them as simple character devices. That way we can have a proper DEVTYPE and userspace can find them correctly. We can also annotate them if needed for special settings.Yes, we can. But AFAIK no user space GPS client is expecting to have a new DEVTYPE.
but we can fix userspace clients to deal with DEVTYPE.
Quoted 1 line
I have several different GPS devices. One is by bluetooth. So I get a
/dev/ttythrough hci. Another one has an USB cable. I get a/dev/ttythrough some USB serial converter. A third one is integrated in a 4G modem which provides a/dev/ttyACMport. So I always get something which looks like a/dev/tty... Seems to be pretty standard.
Actually for Bluetooth RFCOMM it would be a lot better to use the RFCOMM socket instead of the TTY emulation. However that said, Bluetooth RFCOMM is already split in a way that you can have either a socket or a TTY emulation. There is nothing stopping us from adding a GPS emulation and with that natively hooking it up to a future GPS driver. I mean why not have a GPS subsystem that allows for that. I know this is future talk, but it can be done.
Same goes for the USB GPS devices that use a serial converter. If they use proper VID:PID or some sort of identification, we can have a dedicated USB driver that matches it to a GPS device. At the end of the day, the only difference for the usb-serial driver is if it registers a TTY or a future GPS device.
The 4G modem ones are a bit funky. Not all of them expose a ttyACM port btw. Some of them have the NMEA via Qualcomm QMI or some other channel. So inside oFono we have abstracted that into a file descriptor so that power control etc. is handled by oFono. Since you need to use the telephony stack to control the GPS state. But again here, there is nothing stopping us from moving parts of QMI into the kernel. We have done that for the Nokia ISI and the ST-Ericsson CAIF already.
However honestly, my main focus would be to get Bluetooth UARTs integrated natively without line discipline before I would worry about GPS.
Quoted 3 lines
Yes it would be nice to have a
/dev/gps2device.And how do you want to control if the gps device should send records with cr / lf (INLCR, IGNCR)? Can you use tcsetattr?
That needs to be seen. In general NMEA does not need it. However there is more than NMEA out there. Maybe it would need to focus on NMEA GPS anyway. As said above, oFono just hands out the NMEA sentences for QMI devices via file descriptor. So I am not sure we need to control that much.
I mean with Bluetooth we have done a bunch of extra framing enforcement so that a read() only returns a full frame. So that userspace applications have it a lot easier and don't have to worry about byte-byte reading. Something similar could be done for GPS NMEA. Anyway, I am just pointing out ideas here. We do not have the UART bus upstream yet.
Regards
Marcel
Hi Marcel,
Quoted 5 lines
Am 18.08.2016 um 13:41 schrieb Marcel Holtmann <[email protected]>:
=20
Hi Nikolaus,
=20Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Currently, devices attached via a UART are not well supported in =
the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
kernel. The problem is the device support is done in tty line =
disciplines,
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
various platform drivers to handle some sideband, and in userspace =
with
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
utilities such as hciattach.
=20
There have been several attempts to improve support, but they =
suffer from
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
still being tied into the tty layer and/or abusing the platform =
bus. This
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
is a prototype to show creating a proper UART bus for UART =
devices. It is
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
tied into the serial core (really struct
uart_port) below the tty =
layer
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
in order to use existing serial drivers.
=20
This is functional with minimal testing using the loopback driver =
and
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the =
slave
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
device). It still needs lots of work and polish. =20
TODOs:
- Figure out the port locking. mutex plus spinlock plus =
refcounting? I'm
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
hoping all that complexity is from the tty layer and not needed =
here.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Split out the controller for
uart_portsinto separate driver. Do =
we see
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
a need for controller drivers that are not standard serial =
drivers?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time =
(i.e. DMA)
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- Need better receive buffering than just a simple circular buffer =
or
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
perhaps a different receive interface (e.g. direct to client =
buffer)?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus. =20
Before I spend more time on this, I'm looking mainly for feedback =
on the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
general direction and structure (the interface with the existing =
serial
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
drivers in particular).
=20
Some quick comments (can't do any real life tests in the next =
weeks) from my (biased) view:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
=20
* tieing the solution intouart_portis the same as we had done. =
The difference seems to
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
me that you completely bypass
serial_core(and tty) while we want =
to integrate it with standard tty operation.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
=20
We have tapped the tty layer only because it can not be 100% =
avoided if we use serial_core.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
=20
* one feedback I had received was that there may be uart device =
drivers not using serial_core. I am not sure if your approach addresses = that.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
=20
* what I don't see is how we can implement our GPS device power =
control driver:
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- the device should still present itself as a tty device (so that =
cat /dev/ttyO1 reports NMEA records) and should
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
not be completely hidden from user space or represented by a new =
interface type invented just for this device
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
(while the majority of other GPS receivers are still simple tty =
devices).
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
- how we can detect that the device is sending data to the UART =
while no user space process has the uart port open
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
i.e. when does the driver know when to start/stop the UART.
=20
I am actually not convinced that GPS should be represented as =
/dev/ttyS0 or similar TTY. It think they deserve their own driver = exposing them as simple character devices. That way we can have a proper = DEVTYPE and userspace can find them correctly. We can also annotate them = if needed for special settings.
Quoted 2 lines
Quoted 2 lines
=20
Yes, we can. But AFAIK no user space GPS client is expecting to have =
a new DEVTYPE.
Quoted 4 lines
=20
but we can fix userspace clients to deal with DEVTYPE. =20Quoted 1 line
I have several different GPS devices. One is by bluetooth. So I get a =
/dev/tty through hci. Another one has an USB cable. I get a /dev/tty = through some USB serial converter. A third one is integrated in a 4G = modem which provides a /dev/ttyACM port. So I always get something which = looks like a /dev/tty... Seems to be pretty standard.
Quoted 2 lines
=20
Actually for Bluetooth RFCOMM it would be a lot better to use the =
RFCOMM socket instead of the TTY emulation. However that said, Bluetooth = RFCOMM is already split in a way that you can have either a socket or a = TTY emulation. There is nothing stopping us from adding a GPS emulation = and with that natively hooking it up to a future GPS driver. I mean why = not have a GPS subsystem that allows for that. I know this is future = talk, but it can be done.
Quoted 2 lines
=20
Same goes for the USB GPS devices that use a serial converter. If they =
use proper VID:PID or some sort of identification, we can have a = dedicated USB driver that matches it to a GPS device. At the end of the = day, the only difference for the usb-serial driver is if it registers a = TTY or a future GPS device.
Quoted 2 lines
=20
The 4G modem ones are a bit funky. Not all of them expose a ttyACM =
port btw. Some of them have the NMEA via Qualcomm QMI or some other = channel. So inside oFono we have abstracted that into a file descriptor = so that power control etc. is handled by oFono. Since you need to use = the telephony stack to control the GPS state. But again here, there is = nothing stopping us from moving parts of QMI into the kernel. We have = done that for the Nokia ISI and the ST-Ericsson CAIF already.
Yes, agreed. But here we try to optimize the kernel and a specific = variant of user space code. I am not sure if we should do that.
Quoted 1 line
However honestly, my main focus would be to get Bluetooth UARTs =
integrated natively without line discipline before I would worry about = GPS.
Well, for me it is the opposite. I have no problem with running existing = user space code like hciattach on a hci tty port. Even with older OS = versions.
But I can't control the power of this GPS device with a standard user = space mechanism. So for my GPS it either needs new kernel support to = work with old and existing user space code or needs new user space code = in projects I don't even know the name...
Quoted 4 lines
=20
Quoted 3 lines
Yes it would be nice to have a
/dev/gps2device.
=20
And how do you want to control if the gps device should send records =
with cr / lf (INLCR, IGNCR)? Can you use tcsetattr?
Quoted 2 lines
=20
That needs to be seen. In general NMEA does not need it. However there =
is more than NMEA out there. Maybe it would need to focus on NMEA GPS = anyway. As said above, oFono just hands out the NMEA sentences for QMI = devices via file descriptor. So I am not sure we need to control that = much.
Well, you must have some agreement between the device internals and the = user space read() processor if CR LF are to be treated as a single line = or two lines (one empty) or whatever. It can be controlled either by = user space (ignore the empty line) or by tcsetattr. Is that something = the kernel should enforce in this case? Or should the user space tell = the kernel by tcsetattr? I really don't know..
Quoted 2 lines
=20
I mean with Bluetooth we have done a bunch of extra framing =
enforcement so that a read() only returns a full frame. So that = userspace applications have it a lot easier and don't have to worry = about byte-byte reading.
Indeed for Bluetooth it is sort of a low level network stack driver.
Quoted 1 line
Something similar could be done for GPS NMEA.
Yes it could, but I am not sure if Linux should solve this at all.
Quoted 1 line
Anyway, I am just pointing out ideas here. We do not have the UART bus =
upstream yet.
Indeed, we need an agreeable solution for that first.
Maybe the main problem is that too many unsolved ideas are tried to be = squeezed into a single solution fits everyone.
BR,
Nikolaus
Hi!
Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Looks good to me.
Thanks,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
Freaking *awesome* Rob, this really really needs to happen. I'm very happy that you're driving this.
Quoted 3 lines
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
I have Bluetooth (HCI) over UART on the Nomadik and Ux500, both with DMA support for the PL011 too. So I hope to be able to utilize this.
(The HCI transport is then used for GPS, FM radio and whatnot but that is another issue.)
Yours,
Linus Walleij
Marcel Holtmann
maintainerHi Linus,
Quoted 12 lines
Quoted 4 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
Freaking *awesome* Rob, this really really needs to happen. I'm very happy that you're driving this.
Quoted 3 lines
This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
Quoted 6 lines
I have Bluetooth (HCI) over UART on the Nomadik and Ux500, both with DMA support for the PL011 too. So I hope to be able to utilize this.
(The HCI transport is then used for GPS, FM radio and whatnot but that is another issue.)
that is something we can already solve via regmap. We have started work on Intel LnP which also includes a FM radio chip where registers/interrupts are exposed via HCI commands/events. So fundamentally the Bluetooth HCI device would expose the GPS and FM radio nodes via regmap.
Regards
Marcel
On Wed, 17 Aug 2016 20:14:42 -0500
Rob Herring <[email protected]> wrote:
This was proposed ages ago and the point clearly made that
a) the idea doesn't work because uarts are not required to use the uart layer and even those that do sometimes only use half of it
b) that you should use the tty_port abstraction
So instead of just waiting some months and recycling the proposals it's unfortunate that no listening and reworking was done.
https://lkml.org/lkml/2016/1/18/177
So I'm giving this a large neon flashing NAK, because none of the problems have been addressed.
Quoted 4 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
For most platforms it works very nicely and out of the box. The only real issue I have actually seen is the bandwidth issue from early tty based 3G modems. That's not hard to fix with some tty buffer changes. Basically you need a tty port pointer that is atomic exchangable and points either to the usual tty queue logic or to a 'fastpath' handler which just gets thrown a block of bytes and told to use them or lose them
- which is the interface the non n_tty ldiscs want anyway. That's exactly what you would need to fix to support in kernel stuff as well. The tty queue mechanism for devices that can receive in blocks just becomes a fastpath.
There are some disgusting Android turds floating around out of tree where people use things like userspace GPIO line control but you won't fix most of those anyway because they are generally being used for user space modules including dumb GPS where the US government rules won't allow them to be open sourced anyway.
Quoted 2 lines
- Split out the controller for
uart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
As I told you over six months ago uart_port is not the correct abstraction. You need to be working at the tty_port layer. The original design of tty_port was indeed partly to push towards being able to have a serial interface that is in use but not open to user space. The rather nice rework that the maintainers have done to put the buffers in the tty_port takes it closer still.
Plenty of the classic serial port interfaces also don't use the UART layer including every USB device (which is most of them these days), SDIO and others. USB has to be covered for this to be sensible.
Your changes also don't work because serial uart drivers are not obliged to use any of the uart buffering helpers and particularly on the rx side many do not do so and the performance hit would be too high.
It's been explained how to make it work with tty_port, every tty is a dynamic file handle life time object bound to a tty_port. Every tty has a tty_port, every tty driver has a tty_port.
Alan
Hi Alan,
Quoted 1 line
Am 18.08.2016 um 16:25 schrieb One Thousand Gnomes =
Quoted 7 lines
=20
On Wed, 17 Aug 2016 20:14:42 -0500
Rob Herring <[email protected]> wrote:
=20
This was proposed ages ago and the point clearly made that =20
a) the idea doesn't work because uarts are not required to use the =
uart
Quoted 5 lines
layer and even those that do sometimes only use half of it =20
b) that you should use thetty_portabstraction
=20
So instead of just waiting some months and recycling the proposals =
it's
Quoted 9 lines
unfortunate that no listening and reworking was done. =20
https://lkml.org/lkml/2016/1/18/177
=20
So I'm giving this a large neon flashing NAK, because none of the problems have been addressed.
=20Quoted 2 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line =
disciplines,
Quoted 1 line
Quoted 1 line
various platform drivers to handle some sideband, and in userspace =
with
Quoted 8 lines
Quoted 1 line
utilities such as hciattach.
=20
For most platforms it works very nicely and out of the box. The only real issue I have actually seen is the bandwidth issue from early tty based 3G modems. That's not hard to fix with some tty buffer changes. Basically you need a tty port pointer that is atomic exchangable and points either to the usual tty queue logic or to a 'fastpath' handler which just gets thrown a block of bytes and told to use them or lose =
them
Quoted 1 line
- which is the interface the non
n_ttyldiscs want anyway. That's =
exactly
Quoted 5 lines
what you would need to fix to support in kernel stuff as well. The tty queue mechanism for devices that can receive in blocks just becomes a fastpath.
=20
There are some disgusting Android turds floating around out of tree =
where
Quoted 1 line
people use things like userspace GPIO line control but you won't fix =
most
Quoted 2 lines
of those anyway because they are generally being used for user space modules including dumb GPS where the US government rules won't =
allow
Quoted 3 lines
them to be open sourced anyway.
=20Quoted 1 line
- Split out the controller for
uart_portsinto separate driver. Do we =
see
Quoted 4 lines
Quoted 1 line
a need for controller drivers that are not standard serial drivers?
=20
As I told you over six months agouart_portis not the correct abstraction. You need to be working at thetty_portlayer. The =
original
Quoted 1 line
design of
tty_portwas indeed partly to push towards being able to =
have a
Quoted 6 lines
serial interface that is in use but not open to user space. The rather nice rework that the maintainers have done to put the buffers in the
tty_porttakes it closer still.
=20
Plenty of the classic serial port interfaces also don't use the UART layer including every USB device (which is most of them these days), =
SDIO
Quoted 1 line
and others. USB has to be covered for this to be sensible.
It looks as if you try to solve a different problem than some of us. = Maybe this is
the reason why you get the impression that nobody is listening to your = proposal
(but that seems to be common for this topic - I have the impression that nobody is listening to my proposals... so don't mind).
I can only talk for my device where I just want to be able to write a = driver that
gets access to a low level physical UART within a SoC (a little = abstracted
by uart_port) to directly talk to a device connected to such an UART for = reasons
I have explained plenty of times.
Other devices may have orthogonal needs (or suspected needs) and hence a single solution may not fit everybody.
=20
Quoted 2 lines
=20
Your changes also don't work because serial uart drivers are not =
obliged
Quoted 1 line
to use any of the uart buffering helpers and particularly on the rx =
side
Quoted 1 line
many do not do so and the performance hit would be too high.
The SoC I have, is using it.
Quoted 3 lines
=20
It's been explained how to make it work withtty_port, every tty is a dynamic file handle life time object bound to atty_port. Every tty =
has a
Quoted 4 lines
tty_port, every tty driver has atty_port.=20
Alan
BR, Nikolaus
Quoted 5 lines
Quoted 3 lines
Your changes also don't work because serial uart drivers are not obliged to use any of the uart buffering helpers and particularly on the rx side many do not do so and the performance hit would be too high.
The SoC I have, is using it.
The Linux kernel does generalised implementations. Yes it may work on your board but it doesn't work for everything. It's the difference between doing it properly and hacking your board to work.
Alan
Quoted 2 lines
Am 18.08.2016 um 17:38 schrieb One Thousand Gnomes =
Quoted 2 lines
=20
Quoted 1 line
Quoted 1 line
Your changes also don't work because serial uart drivers are not =
obliged
Quoted 1 line
Quoted 1 line
Quoted 1 line
to use any of the uart buffering helpers and particularly on the rx =
side
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
many do not do so and the performance hit would be too high. =20
=20
The SoC I have, is using it.=20
The Linux kernel does generalised implementations. Yes it may work on your board but it doesn't work for everything.
It needs to work only on boards with a SoC UART. Not with a tty over USB or something else. This is the generalisation I see. Any SoC with uart_port driver support (and as far as I see many are).
Quoted 2 lines
It's the difference
between doing it properly and hacking your board to work.
Agreed. But solving problems nobody really has is overengineering.
Especially if the generalised implementation that is being discussed (tty_port) does not even solve the problem. Or only in a very clumsy and difficult way. In such a case a generalisation seems to be the wrong approach to me.
And we should start to accept that we mix up different requirements and try a single solution for almost everyone we can imagine (which isn't bad initially, but can prohibit to find a solution at all) except = the
real use case that is on the table. That is why I always come back to the practical problem to implement my driver and want to know how it can be done.
BR,
Nikolaus
Quoted 50 lines · One Thousand Gnomes
On Wed, 17 Aug 2016 20:14:42 -0500
Rob Herring <[email protected]> wrote:This was proposed ages ago and the point clearly made that
a) the idea doesn't work because uarts are not required to use the uart layer and even those that do sometimes only use half of it
b) that you should use the
tty_portabstractionSo instead of just waiting some months and recycling the proposals it's unfortunate that no listening and reworking was done.
https://lkml.org/lkml/2016/1/18/177
So I'm giving this a large neon flashing NAK, because none of the problems have been addressed.
Quoted 4 lines
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
For most platforms it works very nicely and out of the box. The only real issue I have actually seen is the bandwidth issue from early tty based 3G modems. That's not hard to fix with some tty buffer changes. Basically you need a tty port pointer that is atomic exchangable and points either to the usual tty queue logic or to a 'fastpath' handler which just gets thrown a block of bytes and told to use them or lose them
- which is the interface the nonn_ttyldiscs want anyway. That's exactly what you would need to fix to support in kernel stuff as well. The tty queue mechanism for devices that can receive in blocks just becomes a fastpath.There are some disgusting Android turds floating around out of tree where people use things like userspace GPIO line control but you won't fix most of those anyway because they are generally being used for user space modules including dumb GPS where the US government rules won't allow them to be open sourced anyway.
Quoted 2 lines
- Split out the controller for
uart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?As I told you over six months ago
uart_portis not the correct abstraction. You need to be working at thetty_portlayer. The original design oftty_portwas indeed partly to push towards being able to have a serial interface that is in use but not open to user space. The rather nice rework that the maintainers have done to put the buffers in thetty_porttakes it closer still.
Quoted 3 lines
Plenty of the classic serial port interfaces also don't use the UART layer including every USB device (which is most of them these days), SDIO and others. USB has to be covered for this to be sensible.
Plenty? Really?. Lets break down the tty drivers in the kernel which don't use uart_port.
Consoles/Debug:arch/alpha/kernel/srmcons.carch/cris/arch-v10/kernel/debugport.carch/ia64/hp/sim/simserial.carch/m68k/emu/nfcon.carch/parisc/kernel/pdc_cons.carch/xtensa/platforms/iss/console.cdrivers/char/ttyprintk.cdrivers/tty/bfin_jtag_comm.cdrivers/tty/ehv_bytechan.cdrivers/tty/hvc/hvc_console.cdrivers/tty/hvc/hvcs.cdrivers/tty/hvc/hvsi.cdrivers/tty/serial/kgdb_nmi.cdrivers/tty/mips_ejtag_fdc.cdrivers/tty/metag_da.cdrivers/misc/pti.c
SDIO UART:drivers/mmc/card/sdio_uart.c
S390 (don't think BT dongle is a use case):drivers/s390/char/con3215.cdrivers/s390/char/sclp_tty.cdrivers/s390/char/sclp_vt220.cdrivers/s390/char/tty3270.c
Firewire serial:drivers/staging/fwserial/fwserial.c
Amiga serial:drivers/tty/amiserial.c
Android emulator:drivers/tty/goldfish.c
Multi-port serial boards (standard connectors and not embedded with sideband signals):drivers/tty/cyclades.cdrivers/tty/isicom.cdrivers/tty/moxa.cdrivers/tty/mxser.cdrivers/tty/rocket.cdrivers/tty/synclink.cdrivers/tty/synclink_gt.cdrivers/tty/synclinkmp.c drivers/char/pcmcia/synclink_cs.c drivers/ipack/devices/ipoctal.c drivers/staging/dgnc/dgnc_tty.c
Modems (already a slave device):drivers/isdn/capi/capi.cdrivers/isdn/gigaset/interface.cdrivers/isdn/i4l/isdn_tty.cdrivers/tty/nozomi.cdrivers/tty/ipwireless/tty.cdrivers/tty/serial/ifx6x60.cdrivers/net/usb/hso.cdrivers/staging/gdm724x/gdm_tty.cdrivers/usb/class/cdc-acm.c
USB:drivers/usb/gadget/function/u_serial.cdrivers/usb/serial/usb-serial.c
Virtual devices:net/bluetooth/rfcomm/tty.cnet/irda/ircomm/ircomm_tty.c
Could be updated to use uart_port:drivers/tty/serial/crisv10.c
The only ones here I see us caring about are USB and SDIO as you mentioned. SDIO suffers from the same embedded problem we are trying to solve here with UART slave devices. The devices are always soldered down with sideband GPIOs and power. If there is any device, then it's ultimately going to need its own SDIO driver, not the the generic sdio-uart. So the generic sdio-uart is pretty useless except maybe for a discreet SDIO card which I haven't seen in at least 10 years or in a product for 15 years.
That leaves usb-serial. If the current support is good enough, then that will continue to work (as you said elsewhere, can't break userspace). If someone really wants to do USB serial and wire in sideband controls, then we could provide a host driver that hooks into usb_serial_port.
Quoted 3 lines
Your changes also don't work because serial uart drivers are not obliged to use any of the uart buffering helpers and particularly on the rx side many do not do so and the performance hit would be too high.
Do you have an example?
The only uart buffering helper is for the receive side with uart_insert_char. Sure, a character at a time is not efficient, but that is easily rectified. Or do you mean something else?
Rob
Quoted 2 lines
Plenty? Really?. Lets break down the tty drivers in the kernel which don't use
uart_port.
That's the wrong list - those that use uart port but don't always use the uart_insert_char helpers will also break. So you can start by adding
8250
amba-pl011atmel_serialbcm63xx_uartbfin_sportbfin_sport_uart
crisv10
efm32-uart
etraxfs-uartfsl_lpuart
icom
ifx6060
imxioc3_serialioc4_serialkgdb_nmi
lantiqlpc32xx_hsm32r_siomen_z135_uartmeson_uartmpc52xx_uart
mps2-uart
mpscmsm_serial
mux
mvebu-uart
mxs-auartpch_uartpic32_uartpmac_zilog
samsung
serial-tegra
sh-scisirfsoc_uartsn_console
sunhv
sunsab
sunsu
sunzilog
tilegx
timbuart
uartlineucc_uartvt8500_serial
Some of those you could handle reasonably easily as they are byte oriented, however if your code takes any longer in clock terms to run on the low end devices you'll be a regression. Some of these don't use uart_insert_char because the cost of that tips them over the available clock times.
Quite a few of them however use tty_insert_flip_string or the other buffer handling functions, particularly when doing DMA so you would have to do significant work to fit them into some 'byte callback' type model.
This again is why it needs to be at the tty_port layer. The receive paths can be cleanly intercepted at the point you'd push to an ldisc - the driver level code on rx doesn't care if you have a tty attached, because bytes arrived whether the tty is open or not.
In the case of 8250 all the recent x86 class systems which have things like bluetooth attached via the LPSS are using 8250 and with DMA so your interface simply won't work.
There are also some other slight complications when you look at real world implementations. Android devices tend to keep the GPS in userspace so most of then can't use some magic extra API but just drive GPIO lines via the sysfs GPIO interface. Most Android doesn't use the kernel BT stack either.
Quite a few Android and other embedded devices also do power management by shutting off the UART, routing the rx line to an edge triggered GPIO and on the interrupt flipping the UART back on and losing the first byte, picking a protocol that can recover from it.
Your model doesn't I think cover that, although I am somewhat at a loss as to how to do that nicely!
Quoted 9 lines
Consoles/Debug:
arch/alpha/kernel/srmcons.carch/cris/arch-v10/kernel/debugport.carch/ia64/hp/sim/simserial.carch/m68k/emu/nfcon.carch/parisc/kernel/pdc_cons.carch/xtensa/platforms/iss/console.cdrivers/char/ttyprintk.cdrivers/tty/bfin_jtag_comm.c
Quoted 8 lines
drivers/tty/ehv_bytechan.cdrivers/tty/hvc/hvc_console.cdrivers/tty/hvc/hvcs.cdrivers/tty/hvc/hvsi.cdrivers/tty/serial/kgdb_nmi.cdrivers/tty/mips_ejtag_fdc.cdrivers/tty/metag_da.cdrivers/misc/pti.c
You could attach a dongle of some sort to a supposed console/debug port and people do that kind of crap on embedded devices to save a few cents. The ones above look fine though.
Quoted 2 lines
SDIO UART:
drivers/mmc/card/sdio_uart.c
This is an area that definitely needs covering, except that the way the power works may be completely opaque to the OS if it's something like an ACPI OpRegion controlling it.
Quoted 5 lines
S390 (don't think BT dongle is a use case):
drivers/s390/char/con3215.cdrivers/s390/char/sclp_tty.cdrivers/s390/char/sclp_vt220.cdrivers/s390/char/tty3270.c
I would prefer to think of the fact BT on S390 *would* work as a test of the API being right.
Quoted 34 lines
Firewire serial:
drivers/staging/fwserial/fwserial.cAmiga serial:
drivers/tty/amiserial.cAndroid emulator:
drivers/tty/goldfish.cMulti-port serial boards (standard connectors and not embedded with sideband signals):
drivers/tty/cyclades.cdrivers/tty/isicom.cdrivers/tty/moxa.cdrivers/tty/mxser.cdrivers/tty/rocket.cdrivers/tty/synclink.cdrivers/tty/synclink_gt.cdrivers/tty/synclinkmp.cdrivers/char/pcmcia/synclink_cs.cdrivers/ipack/devices/ipoctal.cdrivers/staging/dgnc/dgnc_tty.cModems (already a slave device):
drivers/isdn/capi/capi.cdrivers/isdn/gigaset/interface.cdrivers/isdn/i4l/isdn_tty.cdrivers/tty/nozomi.cdrivers/tty/ipwireless/tty.cdrivers/tty/serial/ifx6x60.cdrivers/net/usb/hso.cdrivers/staging/gdm724x/gdm_tty.cdrivers/usb/class/cdc-acm.c
Quoted 3 lines
USB:
drivers/usb/gadget/function/u_serial.cdrivers/usb/serial/usb-serial.c
Your list for USB is misleading. Just about every USB serial port uses usb-serial as a midlayer so you are basically saying "Let's make a giant weird special case". Just listing usb-serial would be like just listing serial-core and saying you only support one device.
Quoted 5 lines
That leaves usb-serial. If the current support is good enough, then that will continue to work (as you said elsewhere, can't break userspace). If someone really wants to do USB serial and wire in sideband controls, then we could provide a host driver that hooks into
usb_serial_port.
Alreay happens when people are doing strange things nailing legacy devices to HSIC/SSIC. USB is not just a pile of external cables that always have the plug upside down, it has specifications for directly routed low voltage on PCB consumers and bridges.
The fact you want two different host drivers and two APIs for the same object connected to two identical interfaces but on different busses should be raising alarm bells. We don't have different interfaces for NE2000 over PCI or NE2000 over ISA !
Quoted 9 lines
Quoted 3 lines
Your changes also don't work because serial uart drivers are not obliged to use any of the uart buffering helpers and particularly on the rx side many do not do so and the performance hit would be too high.
Do you have an example?
The only uart buffering helper is for the receive side with
uart_insert_char. Sure, a character at a time is not efficient, but that is easily rectified. Or do you mean something else?
Not all of the uart drivers even use uart_insert_char. It's a convenience helper that most of them bypass because it's completely useless if you are doing things like DMA. Even the modern x86 PC UARTs don't and can't use uart_insert_char and that basically is a killer.
Alan
Hi,
Quoted 5 lines · One Thousand Gnomes
There are also some other slight complications when you look at real world implementations. Android devices tend to keep the GPS in userspace so most of them can't use some magic extra API but just drive GPIO lines via the sysfs GPIO interface. Most Android doesn't use the kernel BT stack either.
I don't get the reasoning for this one. What has it to do with an in-kernel API? People are also using libusb or doing i2c/spi from userspace. Nevertheless we have an in-kernel API for those.
Quoted 8 lines
Quite a few Android and other embedded devices also do power management by shutting off the UART, routing the rx line to an edge triggered GPIO and on the interrupt flipping the UART back on and losing the first byte, picking a protocol that can recover from it.
Your model doesn't I think cover that, although I am somewhat at a loss as to how to do that nicely!
On OMAP this is supported by the serial driver via runtime PM and wakeirq.
Actually my usecase for the API (bluetooth on Nokia N900, N950, N9), there is an extra GPIO for the power management (high = uart should be able to receive sth., low = uart can sleep). For this I can just disable the wakeirq in the UART by not adding it to DT and instead runtime manage it from the uart_dev child device.
While we are on that topic: The omap-serial driver does not enable runtime PM by default, since it does not know if the remote side is ok with loosing the first byte(s). One is expected to enable it using the sysfs API.
But I think it should be safe to enable runtime PM for the serial device in uart_dev_connect(). Due to the child device it will still be kept disabled, except when the uart_dev also implements runtime_pm.
-- Sebastian
Hi Rob,
Thanks for going forward and implementing this. I also started, but was far from a functional state.
Quoted 27 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.
Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
I had a look at the uart_dev API:
int uart_dev_config(struct uart_device *udev, int baud, int parity, int bits, int flow); int uart_dev_connect(struct uart_device *udev);
The flow control configuration should be done separately. e.g.:
uart_dev_flow_control(struct uart_device *udev, bool enable);
int uart_dev_tx(struct uart_device *udev, u8 *buf, size_t count); int uart_dev_rx(struct uart_device *udev, u8 *buf, size_t count);
UART communication does not have to be host-initiated, so this API requires polling. Either some function similar to poll in userspace is needed, or it should be implemented as callback.
-- Sebastian
Quoted 37 lines · Sebastian Reichel
Hi Rob,
Thanks for going forward and implementing this. I also started, but was far from a functional state.
Quoted 27 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Quoted 7 lines
I had a look at the
uart_devAPI:int
uart_dev_config(struct uart_device *udev, int baud, int parity, int bits, int flow); intuart_dev_connect(struct uart_device *udev);The flow control configuration should be done separately. e.g.:
uart_dev_flow_control(struct uart_device *udev, bool enable);
No objection, but out of curiosity, why?
Quoted 6 lines
int
uart_dev_tx(struct uart_device *udev, u8 *buf, size_t count); intuart_dev_rx(struct uart_device *udev, u8 *buf, size_t count);UART communication does not have to be host-initiated, so this API requires polling. Either some function similar to poll in userspace is needed, or it should be implemented as callback.
What's the userspace need? I'm assuming the only immediate consumers are in-kernel.
Rob
Hi,
Quoted 38 lines · Rob Herring
Quoted 37 lines · Sebastian Reichel
Thanks for going forward and implementing this. I also started, but was far from a functional state.
Quoted 27 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
I had a look at the
uart_devAPI:
Quoted 7 lines
Quoted 5 lines
int
uart_dev_config(struct uart_device *udev, int baud, int parity, int bits, int flow); intuart_dev_connect(struct uart_device *udev);The flow control configuration should be done separately. e.g.:
uart_dev_flow_control(struct uart_device *udev, bool enable);No objection, but out of curiosity, why?
Nokia's bluetooth uart protocol disables flow control during speed changes.
Quoted 8 lines
Quoted 6 lines
int
uart_dev_tx(struct uart_device *udev, u8 *buf, size_t count); intuart_dev_rx(struct uart_device *udev, u8 *buf, size_t count);UART communication does not have to be host-initiated, so this API requires polling. Either some function similar to poll in userspace is needed, or it should be implemented as callback.
What's the userspace need?
I meant "Either some function similar to userspace's poll() is needed, ...". Something like uart_dev_wait_for_rx()
Alternatively the rx function could be a callback, that is called when there is new data.
Quoted 1 line
I'm assuming the only immediate consumers are in-kernel.
Yes, but the driver should be notified about incoming data.
-- Sebastian
Hi,
Quoted 66 lines
Am 19.08.2016 um 07:21 schrieb Sebastian Reichel <[email protected]>:
Hi,
Quoted 38 lines · Rob Herring
Quoted 37 lines · Sebastian Reichel
Thanks for going forward and implementing this. I also started, but was far from a functional state.
Quoted 27 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
I had a look at the
uart_devAPI:Quoted 7 lines
Quoted 5 lines
int
uart_dev_config(struct uart_device *udev, int baud, int parity, int bits, int flow); intuart_dev_connect(struct uart_device *udev);The flow control configuration should be done separately. e.g.:
uart_dev_flow_control(struct uart_device *udev, bool enable);No objection, but out of curiosity, why?
Nokia's bluetooth uart protocol disables flow control during speed changes.
Quoted 8 lines
Quoted 6 lines
int
uart_dev_tx(struct uart_device *udev, u8 *buf, size_t count); intuart_dev_rx(struct uart_device *udev, u8 *buf, size_t count);UART communication does not have to be host-initiated, so this API requires polling. Either some function similar to poll in userspace is needed, or it should be implemented as callback.
What's the userspace need?
I meant "Either some function similar to userspace's
poll()is needed, ...". Something likeuart_dev_wait_for_rx()
Quoted 6 lines
Alternatively the rx function could be a callback, that is called when there is new data.
Quoted 1 line
I'm assuming the only immediate consumers are in-kernel.
Yes, but the driver should be notified about incoming data.
Yes, this is very important.
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave driver a chance to trigger actions almost immediately after every character. This probably runs in interrupt context and can happen often.
In our proposal some months ago we have implemented such an rx_notification callback for every character. This allows to work without rx buffer and implement one in the driver if needed. This gives the driver full control over the rx buffer dimensions.
And we have made the callback to return a boolean flag which tells if the character is to be queued in the tty layer so that the driver can decide for every byte if it is to be hidden from user space or passed. Since we pass a pointer, the driver could even modify the character passed back, but we have not used this feature.
This should cover most (but certainly not all) situations of implementing protocol engines in uart slave drivers.
Our API therefore was defined as:
void uart_register_slave(struct uart_port *uport, void *slave); void uart_register_rx_notification(struct uart_port *uport,
bool (*function)(void *slave, unsigned int *c), struct ktermios *termios);
Registering a slave appears to be comparable to uart_dev_connect() and registering an rx_notification combines uart_dev_config() and setting the callback.
Unregistration is done by passing a NULL pointer for 'slave' or 'function'.
If there will be a very similar API with a callback like this, we won't have to change our driver architecture much.
If there is a uart_dev_wait_for_rx() with buffer it is much more difficult to handle.
BR,
Nikolaus
Hallo Nikolaus,
do i understand it correctly. This driver is to make kind of interchip communication and represent uart as a bus to allow use this bus from multiple kernel driver or expose it to user space?
Correct?
Am 19.08.2016 um 09:29 schrieb H. Nikolaus Schaller:
Quoted 120 lines
Hi,
Quoted 66 lines
Am 19.08.2016 um 07:21 schrieb Sebastian Reichel <[email protected]>:
Hi,
Quoted 38 lines · Rob Herring
Quoted 37 lines · Sebastian Reichel
Thanks for going forward and implementing this. I also started, but was far from a functional state.
Quoted 27 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
I had a look at the
uart_devAPI:Quoted 7 lines
Quoted 5 lines
int
uart_dev_config(struct uart_device *udev, int baud, int parity, int bits, int flow); intuart_dev_connect(struct uart_device *udev);The flow control configuration should be done separately. e.g.:
uart_dev_flow_control(struct uart_device *udev, bool enable);No objection, but out of curiosity, why?
Nokia's bluetooth uart protocol disables flow control during speed changes.
Quoted 8 lines
Quoted 6 lines
int
uart_dev_tx(struct uart_device *udev, u8 *buf, size_t count); intuart_dev_rx(struct uart_device *udev, u8 *buf, size_t count);UART communication does not have to be host-initiated, so this API requires polling. Either some function similar to poll in userspace is needed, or it should be implemented as callback.
What's the userspace need?
I meant "Either some function similar to userspace's
poll()is needed, ...". Something likeuart_dev_wait_for_rx()Quoted 6 lines
Alternatively the rx function could be a callback, that is called when there is new data.
Quoted 1 line
I'm assuming the only immediate consumers are in-kernel.
Yes, but the driver should be notified about incoming data.
Yes, this is very important.
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave driver a chance to trigger actions almost immediately after every character. This probably runs in interrupt context and can happen often.
In our proposal some months ago we have implemented such an
rx_notificationcallback for every character. This allows to work without rx buffer and implement one in the driver if needed. This gives the driver full control over the rx buffer dimensions.And we have made the callback to return a boolean flag which tells if the character is to be queued in the tty layer so that the driver can decide for every byte if it is to be hidden from user space or passed. Since we pass a pointer, the driver could even modify the character passed back, but we have not used this feature.
This should cover most (but certainly not all) situations of implementing protocol engines in uart slave drivers.
Our API therefore was defined as:
void
uart_register_slave(struct uart_port *uport, void *slave); void uart_register_rx_notification(structuart_port*uport,bool (*function)(void *slave, unsigned int *c), struct ktermios *termios);Registering a slave appears to be comparable to
uart_dev_connect()and registering anrx_notificationcombinesuart_dev_config()and setting the callback.Unregistration is done by passing a NULL pointer for 'slave' or 'function'.
If there will be a very similar API with a callback like this, we won't have to change our driver architecture much.
If there is a
uart_dev_wait_for_rx()with buffer it is much more difficult to handle.BR,
Nikolaus
Signature · 2 lines
Regards, Oleksij
Hi,
Quoted 7 lines
Am 19.08.2016 um 09:49 schrieb Oleksij Rempel <[email protected]>:
Hallo Nikolaus,
do i understand it correctly. This driver is to make kind of interchip communication and represent uart as a bus to allow use this bus from multiple kernel driver or expose it to user space?
The idea for UART slave devices is to handle devices connected on an embedded board to an UART port in kernel. Currently most such devices are just passed through to some /dev/tty and handled by user-space daemons.
So it is not necessarily about multiple kernel drivers to use the same UART, although that could also be required.
A single one is already difficult... And some scenarios need to shield the UART from user space (currently there is always one /dev/tty per UART - unless the UART is completely disabled).
Some ideas where it might be needed:
* bluetooth HCI over UART
* a weird GPS device whose power state can only reliably be detected by monitoring data activity
* other chips (microcontrollers) connected through UART - similar to I2C slave devices
* it potentially could help to better implement IrDA (although that is mostly legacy)
What it is not about are UART/RS232 converters connected through USB or virtual serial ports created for WWAN modems (e.g. /dev/ttyACM, /dev/ttyHSO). Or BT devices connected through USB (even if they also run HCI protocol).
Quoted 130 lines
Correct?
Am 19.08.2016 um 09:29 schrieb H. Nikolaus Schaller:
Quoted 110 lines
Hi,
Quoted 66 lines
Am 19.08.2016 um 07:21 schrieb Sebastian Reichel <[email protected]>:
Hi,
Quoted 38 lines · Rob Herring
Quoted 37 lines · Sebastian Reichel
Thanks for going forward and implementing this. I also started, but was far from a functional state.
Quoted 27 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
I had a look at the
uart_devAPI:Quoted 7 lines
Quoted 5 lines
int
uart_dev_config(struct uart_device *udev, int baud, int parity, int bits, int flow); intuart_dev_connect(struct uart_device *udev);The flow control configuration should be done separately. e.g.:
uart_dev_flow_control(struct uart_device *udev, bool enable);No objection, but out of curiosity, why?
Nokia's bluetooth uart protocol disables flow control during speed changes.
Quoted 8 lines
Quoted 6 lines
int
uart_dev_tx(struct uart_device *udev, u8 *buf, size_t count); intuart_dev_rx(struct uart_device *udev, u8 *buf, size_t count);UART communication does not have to be host-initiated, so this API requires polling. Either some function similar to poll in userspace is needed, or it should be implemented as callback.
What's the userspace need?
I meant "Either some function similar to userspace's
poll()is needed, ...". Something likeuart_dev_wait_for_rx()Quoted 6 lines
Alternatively the rx function could be a callback, that is called when there is new data.
Quoted 1 line
I'm assuming the only immediate consumers are in-kernel.
Yes, but the driver should be notified about incoming data.
Yes, this is very important.
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave driver a chance to trigger actions almost immediately after every character. This probably runs in interrupt context and can happen often.
In our proposal some months ago we have implemented such an
rx_notificationcallback for every character. This allows to work without rx buffer and implement one in the driver if needed. This gives the driver full control over the rx buffer dimensions.And we have made the callback to return a boolean flag which tells if the character is to be queued in the tty layer so that the driver can decide for every byte if it is to be hidden from user space or passed. Since we pass a pointer, the driver could even modify the character passed back, but we have not used this feature.
This should cover most (but certainly not all) situations of implementing protocol engines in uart slave drivers.
Our API therefore was defined as:
void
uart_register_slave(struct uart_port *uport, void *slave); void uart_register_rx_notification(structuart_port*uport,bool (*function)(void *slave, unsigned int *c), struct ktermios *termios);Registering a slave appears to be comparable to
uart_dev_connect()and registering anrx_notificationcombinesuart_dev_config()and setting the callback.Unregistration is done by passing a NULL pointer for 'slave' or 'function'.
Quoted 10 lines
If there will be a very similar API with a callback like this, we won't have to change our driver architecture much.
If there is a
uart_dev_wait_for_rx()with buffer it is much more difficult to handle.BR,
Nikolaus--
Regards,
Oleksij
Am 19.08.2016 um 19:50 schrieb H. Nikolaus Schaller:
Quoted 27 lines
Hi,
Quoted 7 lines
Am 19.08.2016 um 09:49 schrieb Oleksij Rempel <[email protected]>:
Hallo Nikolaus,
do i understand it correctly. This driver is to make kind of interchip communication and represent uart as a bus to allow use this bus from multiple kernel driver or expose it to user space?
The idea for UART slave devices is to handle devices connected on an embedded board to an UART port in kernel. Currently most such devices are just passed through to some
/dev/ttyand handled by user-space daemons.So it is not necessarily about multiple kernel drivers to use the same UART, although that could also be required.
A single one is already difficult... And some scenarios need to shield the UART from user space (currently there is always one
/dev/ttyper UART - unless the UART is completely disabled).Some ideas where it might be needed:
* bluetooth HCI over UART
* a weird GPS device whose power state can only reliably be detected by monitoring data activity
* other chips (microcontrollers) connected through UART - similar to I2C slave devices
* it potentially could help to better implement IrDA (although that is mostly legacy)
Quoted 3 lines
What it is not about are UART/RS232 converters connected through USB or virtual serial ports created for WWAN modems (e.g.
/dev/ttyACM,/dev/ttyHSO). Or BT devices connected through USB (even if they also run HCI protocol).
Ah... ok. thank you for explanation.
I was thinking it is going in similar direction with my project - use SPI for communication between two SoCs. It is based on SSI32 protocol from Bosch.
In case it is going to this direction:
Master implementation for linux side (tested on Banana Pi and iMX6):
https://github.com/olerem/linux-2.6/commits/bpi-spi-variant2-2016.07.26.2
Slave implementation for stm32f303 (tested on f3 discovery):
https://github.com/olerem/libopencm3-examples/commits/ssi32-2016.08.17.1
protocol decoder for logic analyzer (sigrok):
https://github.com/olerem/libsigrokdecode/commits/ssi32_dec-2016.08.11
Quoted 130 lines
Quoted 129 lines
Correct?
Am 19.08.2016 um 09:29 schrieb H. Nikolaus Schaller:
Quoted 110 lines
Hi,
Quoted 66 lines
Am 19.08.2016 um 07:21 schrieb Sebastian Reichel <[email protected]>:
Hi,
Quoted 38 lines · Rob Herring
Quoted 37 lines · Sebastian Reichel
Thanks for going forward and implementing this. I also started, but was far from a functional state.
Quoted 27 lines · Rob Herring
Currently, devices attached via a UART are not well supported in the kernel. The problem is the device support is done in tty line disciplines, various platform drivers to handle some sideband, and in userspace with utilities such as hciattach.
There have been several attempts to improve support, but they suffer from still being tied into the tty layer and/or abusing the platform bus. This is a prototype to show creating a proper UART bus for UART devices. It is tied into the serial core (really struct
uart_port) below the tty layer in order to use existing serial drivers.This is functional with minimal testing using the loopback driver and pl011 (w/o DMA) UART under QEMU (modified to add a DT node for the slave device). It still needs lots of work and polish.
TODOs:
- Figure out the port locking. mutex plus spinlock plus refcounting? I'm hoping all that complexity is from the tty layer and not needed here.
- Split out the controller foruart_portsinto separate driver. Do we see a need for controller drivers that are not standard serial drivers?
- Implement/test the removal paths
- Fix the receive callbacks for more than character at a time (i.e. DMA)
- Need better receive buffering than just a simple circular buffer or perhaps a different receive interface (e.g. direct to client buffer)?
- Test with other UART drivers
- Convert a real driver/line discipline over to UART bus.Quoted 3 lines
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
I had a look at the
uart_devAPI:Quoted 7 lines
Quoted 5 lines
int
uart_dev_config(struct uart_device *udev, int baud, int parity, int bits, int flow); intuart_dev_connect(struct uart_device *udev);The flow control configuration should be done separately. e.g.:
uart_dev_flow_control(struct uart_device *udev, bool enable);No objection, but out of curiosity, why?
Nokia's bluetooth uart protocol disables flow control during speed changes.
Quoted 8 lines
Quoted 6 lines
int
uart_dev_tx(struct uart_device *udev, u8 *buf, size_t count); intuart_dev_rx(struct uart_device *udev, u8 *buf, size_t count);UART communication does not have to be host-initiated, so this API requires polling. Either some function similar to poll in userspace is needed, or it should be implemented as callback.
What's the userspace need?
I meant "Either some function similar to userspace's
poll()is needed, ...". Something likeuart_dev_wait_for_rx()Quoted 6 lines
Alternatively the rx function could be a callback, that is called when there is new data.
Quoted 1 line
I'm assuming the only immediate consumers are in-kernel.
Yes, but the driver should be notified about incoming data.
Yes, this is very important.
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave driver a chance to trigger actions almost immediately after every character. This probably runs in interrupt context and can happen often.
In our proposal some months ago we have implemented such an
rx_notificationcallback for every character. This allows to work without rx buffer and implement one in the driver if needed. This gives the driver full control over the rx buffer dimensions.And we have made the callback to return a boolean flag which tells if the character is to be queued in the tty layer so that the driver can decide for every byte if it is to be hidden from user space or passed. Since we pass a pointer, the driver could even modify the character passed back, but we have not used this feature.
This should cover most (but certainly not all) situations of implementing protocol engines in uart slave drivers.
Our API therefore was defined as:
void
uart_register_slave(struct uart_port *uport, void *slave); void uart_register_rx_notification(structuart_port*uport,bool (*function)(void *slave, unsigned int *c), struct ktermios *termios);Registering a slave appears to be comparable to
uart_dev_connect()and registering anrx_notificationcombinesuart_dev_config()and setting the callback.Unregistration is done by passing a NULL pointer for 'slave' or 'function'.
Quoted 10 lines
If there will be a very similar API with a callback like this, we won't have to change our driver architecture much.
If there is a
uart_dev_wait_for_rx()with buffer it is much more difficult to handle.BR,
Nikolaus--
Regards,
Oleksij
Signature · 2 lines
Regards, Oleksij
Quoted 3 lines
A single one is already difficult... And some scenarios need to shield the UART from user space (currently there is always one
/dev/ttyper UART - unless the UART is completely disabled).
That bit is already covered and one or two devices support this because they have things like 3 serial ports but one cannot be used if some other feature is enabled.
You simply keep a private counter and return -EBUSY in the port->activate() method if needed. That is sufficient to share a UART with the tty layer when you have a contended resource, but not to borrow the UART and re-use the stack which is what is needed in this case.
(You can even steal a UART this way by doing a hangup on it and then once it drops out of use taking it over and ensuring the EBUSY behaviour)
Quoted 10 lines
Some ideas where it might be needed:
* bluetooth HCI over UART
* a weird GPS device whose power state can only reliably be detected by monitoring data activity
* other chips (microcontrollers) connected through UART - similar to I2C slave devices
* it potentially could help to better implement IrDA (although that is mostly legacy)What it is not about are UART/RS232 converters connected through USB or virtual serial ports created for WWAN modems (e.g.
/dev/ttyACM,/dev/ttyHSO). Or BT devices connected through USB (even if they also run HCI protocol).
It actually has to be about both because you will find the exact same device wired via USB SSIC/HSIC to a USB UART or via a classic UART. Not is it just about embedded boards. A current PC class device will usually have bluetooth connected via a UART where both components are on board. The same for GPS (or more accurately location services as it's usually more than just a GPS nowdays). There may also be onboard WWAN modems and other widgets wired this way.
In the PC case the power relationship and connectivity is usually described via ACPI and that often means the kernel simply doesn't know how to manage the power states besides telling the modem, GPS. etc to turn itself on and off via normal ACPI power descriptions. Those may well call OpRegion handlers so it's all abstracted nicely and generic, but rather more invisible to the OS than DT describing pmic and/or gpio setings for the device.
Todays low end Intel x86 PC has multiple DMA accelerated low power 16x50 compatible UARTS on die along with multiple channels of I2C and SPI. Things like Android and PC tablet devices with sensors have pretty much converged the old divide between a desktop/laptop/tablet PC and an 'embedded' board.
Alan
Quoted 2 lines
Am 20.08.2016 um 15:34 schrieb One Thousand Gnomes =
Quoted 1 line
Quoted 1 line
What it is not about are UART/RS232 converters connected through USB =
or virtual
Quoted 1 line
Quoted 1 line
serial ports created for WWAN modems (e.g.
/dev/ttyACM,/dev/ttyHSO). =
Or BT devices
Quoted 4 lines
Quoted 1 line
connected through USB (even if they also run HCI protocol).
=20
It actually has to be about both because you will find the exact same device wired via USB SSIC/HSIC to a USB UART or via a classic UART. =
Not is
Quoted 1 line
it just about embedded boards.=20
Not necessarily.
We often have two interface options for exactly the sam sensor chips. = They can be connected
either through SPI or I2C. Which means that there is a core driver for = the chip and two different
transport glue components (see e.g. iio/accel/bmc150).
This does not require I2C to be able to handle SPI or vice versa or = provide a common API.
And most Bluetooth devices I know have either UART or a direct USB = interface. So in the
USB case there is no need to connect it through some USB-UART bridge and = treat it as
an UART at all.
BR,
Nikolaus
Hi,
Quoted 9 lines · H. Nikolaus Schaller
Quoted 8 lines
Am 20.08.2016 um 15:34 schrieb One Thousand Gnomes <[email protected]>:
Quoted 3 lines
What it is not about are UART/RS232 converters connected through USB or virtual serial ports created for WWAN modems (e.g.
/dev/ttyACM,/dev/ttyHSO). Or BT devices connected through USB (even if they also run HCI protocol).It actually has to be about both because you will find the exact same device wired via USB SSIC/HSIC to a USB UART or via a classic UART. Not is it just about embedded boards.
Quoted 7 lines
Not necessarily.
We often have two interface options for exactly the sam sensor chips. They can be connected either through SPI or I2C. Which means that there is a core driver for the chip and two different transport glue components (see e.g. iio/accel/bmc150).
This does not require I2C to be able to handle SPI or vice versa or provide a common API.
I don't understand this comparison. I2C and SPI are different protocols, while native UART and USB-connected UART are both UART.
Quoted 3 lines
And most Bluetooth devices I know have either UART or a direct USB interface. So in the USB case there is no need to connect it through some USB-UART bridge and treat it as an UART at all.
I think having support for USB-UART dongles is useful for driver development and testing on non-embedded HW.
-- Sebastian
Hi Sebastian,
Quoted 16 lines
Am 22.08.2016 um 22:39 schrieb Sebastian Reichel <[email protected]>:
Hi,
Quoted 11 lines · H. Nikolaus Schaller
Quoted 8 lines
Am 20.08.2016 um 15:34 schrieb One Thousand Gnomes <[email protected]>:
Quoted 3 lines
What it is not about are UART/RS232 converters connected through USB or virtual serial ports created for WWAN modems (e.g.
/dev/ttyACM,/dev/ttyHSO). Or BT devices connected through USB (even if they also run HCI protocol).It actually has to be about both because you will find the exact same device wired via USB SSIC/HSIC to a USB UART or via a classic UART. Not is it just about embedded boards.
Not necessarily.
Quoted 8 lines
Quoted 5 lines
We often have two interface options for exactly the sam sensor chips. They can be connected either through SPI or I2C. Which means that there is a core driver for the chip and two different transport glue components (see e.g. iio/accel/bmc150).
This does not require I2C to be able to handle SPI or vice versa or provide a common API.
I don't understand this comparison. I2C and SPI are different protocols,
Yes, they are different on protocol level, but on both you transfer blocks of data from/to a slave device which usually can be addressed. And for some chips they are just two slightly alternative serial interfaces.
Quoted 1 line
while native UART and USB-connected UART are both UART.
I see what you mean, but kernel divides between directly connected UART and USB-connected UART.
drivers/usb/serial/ vs. drivers/tty/serial/
to implement two different groups of UARTs. Although on user space level they are harmonized again. This is why I compare with i2c and spi. But each such comparison is not perfect.
Anyways, to me it looks as if everybody wants to make the solution work for usb-uarts as well (although I still would like to see a real world use-case).
Quoted 7 lines
Quoted 4 lines
And most Bluetooth devices I know have either UART or a direct USB interface. So in the USB case there is no need to connect it through some USB-UART bridge and treat it as an UART at all.
I think having support for USB-UART dongles is useful for driver development and testing on non-embedded HW.
Hm. I assume you mean the Bluetooth situation where both, embedded UART connected chips and USB dongles are available. I am not a specialist for such things, but I think you have three options to connect bluetooth:
a) SoC-UART <-> BT-Chip-UART-port
b) USB-UART (FT232, PL2303 etc.) <-> BT-Chip-UART-port
c) USB <-> BT-Chip-USB-port (not UART involved at all)
Case c) IMHO means you anyways need a special USB driver for the BT-Chip connected through USB and plugging it into a non-embedded USB port does not automatically show it as a tty interface. So you can't use it for testing the UART drivers.
BTW: the Wi2Wi W2CBW003 chip comes in two firmware variants: one for UART and one for USB. So they are also not exchangeable.
Variant b) is IMHO of no practical relevance (but I may be wrong) because it would mean to add some costly FT232 or PL2302 chip where a different firmware variant works with direct USB connection.
So to me it looks as if you need to develop different low-level drivers anyways.
BR,
Nikolaus
Quoted 3 lines · CEST H. Nikolaus Schaller
I see what you mean, but kernel divides between directly connected UART and USB-connected UART.
drivers/usb/serial/vs.drivers/tty/serial/
That distinction purely exists for historic reasons. I'd argue that the former should actually go into drivers/tty/usb or similar. A long time ago, we commonly sorted device drivers by how they were attached to the system (as drivers/usb/serial/ and drivers/usb/storage still do), but almost everything is now sorted according to how it is used instead.
Arnd
Hi,
Quoted 45 lines · H. Nikolaus Schaller
Quoted 16 lines
Am 22.08.2016 um 22:39 schrieb Sebastian Reichel <[email protected]>:
Hi,
Quoted 11 lines · H. Nikolaus Schaller
Quoted 8 lines
Am 20.08.2016 um 15:34 schrieb One Thousand Gnomes <[email protected]>:
Quoted 3 lines
What it is not about are UART/RS232 converters connected through USB or virtual serial ports created for WWAN modems (e.g.
/dev/ttyACM,/dev/ttyHSO). Or BT devices connected through USB (even if they also run HCI protocol).It actually has to be about both because you will find the exact same device wired via USB SSIC/HSIC to a USB UART or via a classic UART. Not is it just about embedded boards.
Not necessarily.
Quoted 8 lines
Quoted 5 lines
We often have two interface options for exactly the sam sensor chips. They can be connected either through SPI or I2C. Which means that there is a core driver for the chip and two different transport glue components (see e.g. iio/accel/bmc150).
This does not require I2C to be able to handle SPI or vice versa or provide a common API.
I don't understand this comparison. I2C and SPI are different protocols,
Yes, they are different on protocol level, but on both you transfer blocks of data from/to a slave device which usually can be addressed. And for some chips they are just two slightly alternative serial interfaces.
Quoted 1 line
while native UART and USB-connected UART are both UART.
I see what you mean, but kernel divides between directly connected UART and USB-connected UART.
drivers/usb/serial/vs.drivers/tty/serial/to implement two different groups of UARTs. Although on user space level they are harmonized again. This is why I compare with i2c and spi. But each such comparison is not perfect.
Anyways, to me it looks as if everybody wants to make the solution work for usb-uarts as well (although I still would like to see a real world use-case).
Quoted 5 lines
Quoted 4 lines
And most Bluetooth devices I know have either UART or a direct USB interface. So in the USB case there is no need to connect it through some USB-UART bridge and treat it as an UART at all.
Quoted 5 lines
Quoted 2 lines
I think having support for USB-UART dongles is useful for driver development and testing on non-embedded HW.
Hm. I assume you mean the Bluetooth situation where both, embedded UART connected chips and USB dongles are available.
No. I mean I have some serial device, which is connected to the embedded UART, but I also have a standalone version. For driver development I can just use my standalone serial device, connect it to an USB-UART and develop the driver on non embedded HW. Then I can use the same driver on my embedded platform and it works, since it uses the same API.
For e.g. I2C this works perfectly fine. I already did this with the I2C interface exposed on my notebook's VGA port.
Quoted 7 lines
I am not a specialist for such things, but I think you have three options to connect bluetooth:
a) SoC-UART <-> BT-Chip-UART-port
b) USB-UART (FT232, PL2303 etc.) <-> BT-Chip-UART-port
c) USB <-> BT-Chip-USB-port (not UART involved at all)
Quoted 6 lines
Case c) IMHO means you anyways need a special USB driver for the BT-Chip connected through USB and plugging it into a non-embedded USB port does not automatically show it as a tty interface. So you can't use it for testing the UART drivers.
BTW: the Wi2Wi W2CBW003 chip comes in two firmware variants: one for UART and one for USB. So they are also not exchangeable.
Yes, let's ignore option c). I'm talking about UART only. If the chip has native USB support, then that's a different driver. Note, that for more complex drivers it may become possible to use the same high-level driver via regmap at some point. Not sure if this kind of HW exists, though.
Quoted 4 lines
Variant b) is IMHO of no practical relevance (but I may be wrong) because it would mean to add some costly FT232 or PL2302 chip where a different firmware variant works with direct USB connection.
Well for some chips there is not native USB support. But my scenario was about development. Let's say I have a serial-chip and I want to develop a driver for it. It would be nice if I can develop the driver with a USB-UART and then use it on my embedded system.
There are usb-serial devices, which could benefit from support btw. I would find it really useful, if the Dangerous Prototype's Bus Pirate would expose native /dev/i2c and /dev/spi and it's based on FT232.
Quoted 2 lines
So to me it looks as if you need to develop different low-level drivers anyways.
No. You say, that option b) is irrelevant and assume, that every serial chip also has native USB support.
-- Sebastian
Quoted 4 lines
There are usb-serial devices, which could benefit from support btw. I would find it really useful, if the Dangerous Prototype's Bus Pirate would expose native
/dev/i2cand/dev/spiand it's based on FT232.
That should just need an ldisc. I2C and SPI should at this point be sane for hotplugging as needed for an ldisc.
And having an ldisc also has another nice effect. You can plug the bus pirate into a remote machine, run an 8bit clean link over a pty/tty pair half way around the world and get a local i2c/spi to the remote machine's i2c/spi bus pirate ports and devices.
It also means that if Bus Pirate 5 changes USB uart nothing breaks.
Alan
Hi,
Quoted 6 lines · One Thousand Gnomes
Quoted 4 lines
There are usb-serial devices, which could benefit from support btw. I would find it really useful, if the Dangerous Prototype's Bus Pirate would expose native
/dev/i2cand/dev/spiand it's based on FT232.That should just need an ldisc.
Right, since it does not need any extra resources. Probably not the best example.
Quoted 2 lines
I2C and SPI should at this point be sane for hotplugging as needed for an ldisc.
I guess hotplugging support in the downstream kernel frameworks would be needed anyway with usb-serial being USB based.
Quoted 4 lines
And having an ldisc also has another nice effect. You can plug the bus pirate into a remote machine, run an 8bit clean link over a pty/tty pair half way around the world and get a local i2c/spi to the remote machine's i2c/spi bus pirate ports and devices.
Right.
Quoted 1 line
It also means that if Bus Pirate 5 changes USB uart nothing breaks.
And it means no auto-support. Which would be fine in case of Bus Pirate, since its mainly a developer device and some people may actually prefer the IMHO anoying serial interface.
Let's forget that example.
-- Sebastian
Hi,
Quoted 13 lines
Am 23.08.2016 um 00:42 schrieb Sebastian Reichel <[email protected]>:
Quoted 11 lines
I am not a specialist for such things, but I think you have three options to connect bluetooth:
a) SoC-UART <-> BT-Chip-UART-port
b) USB-UART (FT232, PL2303 etc.) <-> BT-Chip-UART-port
c) USB <-> BT-Chip-USB-port (not UART involved at all)Case c) IMHO means you anyways need a special USB driver for the BT-Chip connected through USB and plugging it into a non-embedded USB port does not automatically show it as a tty interface. So you can't use it for testing the UART drivers.
Quoted 7 lines
Quoted 2 lines
BTW: the Wi2Wi W2CBW003 chip comes in two firmware variants: one for UART and one for USB. So they are also not exchangeable.
Yes, let's ignore option c).
I'm talking about UART only. If the
chip has native USB support, then that's a different driver.
Exactly.
Quoted 10 lines
Quoted 5 lines
Variant b) is IMHO of no practical relevance (but I may be wrong) because it would mean to add some costly FT232 or PL2302 chip where a different firmware variant works with direct USB connection.
Well for some chips there is not native USB support. But my scenario was about development. Let's say I have a serial-chip and I want to develop a driver for it. It would be nice if I can develop the driver with a USB-UART
Yes it would be nice, but is this a thing with significant practical relevance?
Usually you have to write drivers for a complete device where the slave chip is already wired up to a SoC-UART.
Sometimes you can get a bare chip where you can connect to an USB-UART. But someone has to design that piece of special hardware for you. If you are really lucky there is an evaluation board.
And in that case I would use a RasPi or BeagleBone and tie up directly to some SoC-UART instead of using an intermediate USB-UART adapter. Because it is more close to timing relations to the final SoC based design.
Quoted 6 lines
and then use it on my embedded system.
There are usb-serial devices, which could benefit from support btw. I would find it really useful, if the Dangerous Prototype's Bus Pirate would expose native
/dev/i2cand/dev/spiand it's based on FT232.
Oh, that is an interesting device I didn't know yet.
Quoted 6 lines
Quoted 3 lines
So to me it looks as if you need to develop different low-level drivers anyways.
No. You say, that option b) is irrelevant and assume, that every serial chip also has native USB support.
I just assume that b) is rarely used because there are alternatives. Although it would be a nice option.
Anyways, while following the discussion this is not the most important facet of the overall topic.
BR,
Nikolaus
Quoted 34 lines · H. Nikolaus Schaller
Hi Sebastian,
Quoted 16 lines
Am 22.08.2016 um 22:39 schrieb Sebastian Reichel <[email protected]>:
Hi,
Quoted 11 lines · H. Nikolaus Schaller
Quoted 8 lines
Am 20.08.2016 um 15:34 schrieb One Thousand Gnomes <[email protected]>:
Quoted 3 lines
What it is not about are UART/RS232 converters connected through USB or virtual serial ports created for WWAN modems (e.g.
/dev/ttyACM,/dev/ttyHSO). Or BT devices connected through USB (even if they also run HCI protocol).It actually has to be about both because you will find the exact same device wired via USB SSIC/HSIC to a USB UART or via a classic UART. Not is it just about embedded boards.
Not necessarily.
Quoted 8 lines
Quoted 5 lines
We often have two interface options for exactly the sam sensor chips. They can be connected either through SPI or I2C. Which means that there is a core driver for the chip and two different transport glue components (see e.g. iio/accel/bmc150).
This does not require I2C to be able to handle SPI or vice versa or provide a common API.
I don't understand this comparison. I2C and SPI are different protocols,
Yes, they are different on protocol level, but on both you transfer blocks of data from/to a slave device which usually can be addressed. And for some chips they are just two slightly alternative serial interfaces.
Quoted 1 line
while native UART and USB-connected UART are both UART.
I see what you mean, but kernel divides between directly connected UART and USB-connected UART.
Quoted 7 lines
drivers/usb/serial/vs.drivers/tty/serial/to implement two different groups of UARTs. Although on user space level they are harmonized again. This is why I compare with i2c and spi. But each such comparison is not perfect.
Anyways, to me it looks as if everybody wants to make the solution work for usb-uarts as well (although I still would like to see a real world use-case).
I use a NFC reader attached to a PL2303 UART. It's a proof of concept solution but if I needed a finished
product all it takes is to put the two pieces of PCB into a box with the USB connector sticking out.
Or glue the PCB on the inside of a plastic part of a PC case.
Thanks
Michal
Quoted 4 lines
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave driver a chance to trigger actions almost immediately after every character. This probably runs in interrupt context and can happen often.
We don't realistically have the clock cycles to do that on a low end embedded processor handling high speed I/O. The best you can do is trigger a workqueue to switch the buffer data around and call the helper while the uart may be receiving more bytes.
What you are asking for you'd get out of the first parts of tidying up the receive paths because you'd set a different port->rx() method and get bursts of characters, flags and length data.
Alan
Quoted 2 lines
Am 19.08.2016 um 13:06 schrieb One Thousand Gnomes =
Quoted 8 lines
=20
Quoted 4 lines
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave driver a chance to trigger actions almost immediately after every character. This probably runs in interrupt context and can happen often.
=20
We don't realistically have the clock cycles to do that on a low end embedded processor handling high speed I/O.
well, if we have a low end embedded processor and high-speed I/O, then buffering the data before processing doesn't help either since = processing
still will eat up clock cycles.
Quoted 2 lines
The best you can do is
trigger a workqueue to switch the buffer data around and call the =
helper
Quoted 1 line
while the uart may be receiving more bytes.
Ok, assuming DMA double buffering might (almost) double throughput.
The question is if this is needed at all. If we have a bluetooth stack = with HCI the
fastest UART interface I am aware of is running at 3 Mbit/s. 10 bits = incl. framing
means 300kByte/s equiv. 3=C2=B5s per byte to process. Should be enough = to decide
if the byte should go to a buffer or not, check checksums, or discard = and move
the protocol engine to a different state. This is what I assume would be = done in
a callback. No processing needing some ms per frame.
Quoted 3 lines
=20
What you are asking for you'd get out of the first parts of tidying up the receive paths because you'd set a differentport->rx()method and =
get
Quoted 3 lines
bursts of characters, flags and length data.
=20
Alan
Quoted 1 line · On Fri, 19 Aug 2016 19:42:37 +0200 "H. Nikolaus Schaller" <[email protected]>…
Quoted 1 line
Am 19.08.2016 um 13:06 schrieb One Thousand Gnomes <[email protected]=
.org.uk>:
Quoted 5 lines
Quoted 5 lines
=20
Quoted 4 lines
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave driver a chance to trigger actions almost immediately after every character. This probably runs in interrupt context and can happen often. =20
Quoted 7 lines
Quoted 3 lines
=20
We don't realistically have the clock cycles to do that on a low end embedded processor handling high speed I/O. =20=20
well, if we have a low end embedded processor and high-speed I/O, then buffering the data before processing doesn't help either since processing still will eat up clock cycles.
Of course it helps. You are out of the IRQ handler within the 9 serial clocks, so you can take another interrupt and grab the next byte. You will also get benefits from processing the bytes further in blocks, and if you get too far behind you'll make the flow control limit.
You've also usually got multiple cores these days - although not on the very low end quite often.
Quoted 1 line
The question is if this is needed at all. If we have a bluetooth stack wi=
th HCI the
Quoted 1 line
fastest UART interface I am aware of is running at 3 Mbit/s. 10 bits incl=
. framing
Quoted 1 line
means 300kByte/s equiv. 3=C2=B5s per byte to process. Should be enough to=
decide
Quoted 1 line
if the byte should go to a buffer or not, check checksums, or discard and=
move
Quoted 1 line
the protocol engine to a different state. This is what I assume would be =
done in
Quoted 1 line
a callback. No processing needing some ms per frame.
That depends on the processor - remember people run Linux on low end CPUs including those embedded in an FPGA not just high end PC and ARM class devices.
The more important question is - purely for the receive side of things - is a callback which guarantees to be called "soon" after the bytes arrive sufficient.
If it is then almost no work is needed on the receive side to allow pure kernel code to manage recevied data directly because the current buffering support throughout the receive side is completely capable of providing those services without a tty structure, and to anything which can have a tty attached.
Doesn't solve transmit or configuration but it's one step that needs no additional real work and re-invention.
Alan
Quoted 2 lines
Am 20.08.2016 um 15:22 schrieb One Thousand Gnomes =
Quoted 5 lines
=20
On Fri, 19 Aug 2016 19:42:37 +0200
"H. Nikolaus Schaller" <[email protected]> wrote:
=20Quoted 1 line
Quoted 1 line
Am 19.08.2016 um 13:06 schrieb One Thousand Gnomes =
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
=20
Quoted 2 lines
If possible, please do a callback for every character that arrives. And not only if the rx buffer becomes full, to give the slave =
driver
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
a chance to trigger actions almost immediately after every =
character.
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
This probably runs in interrupt context and can happen often. =20
=20
We don't realistically have the clock cycles to do that on a low end embedded processor handling high speed I/O. =20=20
well, if we have a low end embedded processor and high-speed I/O, =
then
Quoted 1 line
Quoted 1 line
buffering the data before processing doesn't help either since =
processing
Quoted 5 lines
Quoted 1 line
still will eat up clock cycles.
=20
Of course it helps. You are out of the IRQ handler within the 9 serial clocks, so you can take another interrupt and grab the next byte. You will also get benefits from processing the bytes further in blocks,
if there are benefits from processing blocks. That depends on the = specific
protocol.
My proposal can still check and then place byte by byte in a buffer and = almost
immediately return from interrupt. Until a block is completed and then = trigger
processing outside of the interrupt context.
Quoted 3 lines
and if you get too far behind you'll make the flow control limit. =20
You've also usually got multiple cores these days - although not on =
the
Quoted 1 line
very low end quite often.
Indeed. But low-end rarely has really high-speed requirements and then = should
also run Linux. If it goes to performance limits, probably some = assembler code
will be used.
And UART is inherently slow compared to SPI or USB or Ethernet.
Quoted 2 lines
=20
Quoted 1 line
The question is if this is needed at all. If we have a bluetooth =
stack with HCI the
Quoted 1 line
Quoted 1 line
fastest UART interface I am aware of is running at 3 Mbit/s. 10 bits =
incl. framing
Quoted 1 line
Quoted 1 line
means 300kByte/s equiv. 3=C2=B5s per byte to process. Should be =
enough to decide
Quoted 1 line
Quoted 1 line
if the byte should go to a buffer or not, check checksums, or discard =
and move
Quoted 1 line
Quoted 1 line
the protocol engine to a different state. This is what I assume would =
be done in
Quoted 3 lines
Quoted 1 line
a callback. No processing needing some ms per frame.
=20
That depends on the processor - remember people run Linux on low end =
CPUs
Quoted 4 lines
including those embedded in an FPGA not just high end PC and ARM class devices.
=20
The more important question is - purely for the receive side of things =
-
Quoted 1 line
is a callback which guarantees to be called "soon" after the bytes =
arrive
Quoted 3 lines
sufficient.
=20
If it is then almost no work is needed on the receive side to allow =
pure
Quoted 3 lines
kernel code to manage recevied data directly because the current buffering support throughout the receive side is completely capable of providing those services without a tty structure, and to anything =
which
Quoted 1 line
can have a tty attached.
Let me ask a question about your centralized and pre-cooked buffering = approach.
As far as I see, even then the kernel API must notify the driver at the = right moment
that a new block has arrived. Right?
But how does the kernel API know how long such a block is?
Usually there is a start byte/character, sometimes a length indicator, = then payload data,
some checksum and finally a stop byte/character. For NMEA it is $, no = length, * and \r\n.
For other serial protocols it might be AT, no length, and \r. Or = something different.
HCI seems to use 2 byte op-code or 1 byte event code and 1 byte = parameter length.
So this means each protocol has a different block format.
How can centralized solution manage such differently formatted blocks?
IMHO it can't without help from the device specific slave device driver. = Which must
therefore be able to see every byte to decide into which category it = goes. Which brings
us back to the every-byte-interrupt-context callback.
This is different from well formatted protocols like SPI or I2C or = Ethernet etc.
where the controller decodes the frame boundaries and DMA can store the payload data and an interrupt occurs for every received block.
So I would even conclude that you usually can't even use DMA based UART = receive
processing for arbitrary and not well-defined protocols. Or have to = assume that the
protocol is 100% request-response based and a timeout can tell that no = more data
will be received - until a new request has been sent.
Quoted 2 lines
=20
Doesn't solve transmit or configuration but it's one step that needs =
no
Quoted 3 lines
additional real work and re-invention.
=20
Alan
BR,
Nikolaus
Quoted 4 lines
Let me ask a question about your centralized and pre-cooked buffering approach.
As far as I see, even then the kernel API must notify the driver at the right moment that a new block has arrived. Right?
The low level driver queues words (data byte, flag byte) The buffer processing workqueue picks those bytes from the queue and atomically empties the queue
The workqueue involves the receive handler.
Quoted 1 line
But how does the kernel API know how long such a block is?
It's as long as the data that has arrived in that time.
Quoted 4 lines
Usually there is a start byte/character, sometimes a length indicator, then payload data, some checksum and finally a stop byte/character. For NMEA it is $, no length, * and \r\n. For other serial protocols it might be AT, no length, and \r. Or something different. HCI seems to use 2 byte op-code or 1 byte event code and 1 byte parameter length.
It doesn't look for any kind of protocol block headers. The routine invoked by the work queue does any frame recovery.
Quoted 2 lines
So I would even conclude that you usually can't even use DMA based UART receive processing for arbitrary and not well-defined protocols. Or have to assume that the
We do, today for bluetooth and other protocols just fine - it's all about data flows not about framing in the protocol sense.
Alan
Quoted 2 lines
Am 21.08.2016 um 19:09 schrieb One Thousand Gnomes =
Quoted 2 lines
=20
Quoted 1 line
Let me ask a question about your centralized and pre-cooked buffering =
approach.
Quoted 2 lines
Quoted 2 lines
=20
As far as I see, even then the kernel API must notify the driver at =
the right moment
Quoted 5 lines
Quoted 1 line
that a new block has arrived. Right?
=20
The low level driver queues words (data byte, flag byte) The buffer processing workqueue picks those bytes from the queue and atomically empties the queue
When and how fast is the work queue scheduled?
And by which event?
Quoted 1 line
The workqueue involves the receive handler.
This should be faster than if a driver directly processes incoming = bytes?
Quoted 4 lines
=20
Quoted 1 line
But how does the kernel API know how long such a block is?
=20
It's as long as the data that has arrived in that time.
Which means the work queue handler have to decide if it is enough for a frame to decode and if not, wait a little until more arrives.
Or you have to assemble chunks into a frame, i.e. copy data around.
Both seems a waste of scarce cpu cycles in high-speed situations to me.
Quoted 2 lines
=20
Quoted 1 line
Usually there is a start byte/character, sometimes a length =
indicator, then payload data,
Quoted 1 line
Quoted 1 line
some checksum and finally a stop byte/character. For NMEA it is $, no =
length, * and \r\n.
Quoted 1 line
Quoted 1 line
For other serial protocols it might be AT, no length, and \r. Or =
something different.
Quoted 1 line
Quoted 1 line
HCI seems to use 2 byte op-code or 1 byte event code and 1 byte =
parameter length.
Quoted 2 lines
=20
It doesn't look for any kind of protocol block headers.
Which might become the pitfall of the design because as I have described = it is an
essential part of processing UART based protocols. You seem to focus on = efficiently
buffering only but not about efficiently processing the queued data.
Quoted 5 lines
The routine
invoked by the work queue does any frame recovery.=20
Quoted 1 line
So I would even conclude that you usually can't even use DMA based =
UART receive
Quoted 1 line
Quoted 1 line
processing for arbitrary and not well-defined protocols. Or have to =
assume that the
Quoted 2 lines
=20
We do, today for bluetooth and other protocols just fine
I think it works (even with user-space HCI daemon) because bluetooth HCI = is slow (<300kByte/s).
Quoted 2 lines
- it's all about
data flows not about framing in the protocol sense.
Yes, but you should also take framing into account for a solution that = helps to implement
UART slave devices. That is my concern.
BR,
Nikolaus=
Quoted 2 lines
When and how fast is the work queue scheduled?
And by which event?
That depends upon the platform and how busy the machine is. The dumb uarts generally schedule it as soon as they've emptied the hardware. Some controllers it may be done off a timer, others off DMA completion events
Quoted 3 lines
Quoted 1 line
The workqueue involves the receive handler.
This should be faster than if a driver directly processes incoming bytes?
It is in cases like n_tty yes and more importantly the serial port can take another interrupt while the workqueue is running, so you won't drop bytes if you have flow control.
Quoted 1 line
Or you have to assemble chunks into a frame, i.e. copy data around.
You have to do a pass over the data anyway to remove any quoting in the framing for things like SLIP and PPP.
Quoted 1 line
Both seems a waste of scarce cpu cycles in high-speed situations to me.
The only case that I am aware of where there is a clear inefficiency is where the hardware is handling characters in big chunks with good buffering (eg DMA) and we are driving a protocol like PPP which simply wants to do one pass over the data and stuff it into the network stack.
That one would be nice to fix with the port->rx suggestion I made.
Quoted 3 lines
Which might become the pitfall of the design because as I have described it is an essential part of processing UART based protocols. You seem to focus on efficiently buffering only but not about efficiently processing the queued data.
There's a good reason for that - latency and throughput are not the same thing. We need good latency on the buffering but good throughput on the processing. Also if we fail to queue all the data reliably it doesn't matter how efficient the processing side is.
Quoted 2 lines
Quoted 1 line
We do, today for bluetooth and other protocols just fine
I think it works (even with user-space HCI daemon) because bluetooth HCI is slow (<300kByte/s).
We do it for PPP over 3G modem as well. Modern 3G modems pretend to be network devices, older ones didn't - and you are correct that in that scenario we struggled (it's a lot better since Peter sorted the locking out to be efficient).
Quoted 2 lines
Yes, but you should also take framing into account for a solution that helps to implement UART slave devices. That is my concern.
I understand that I think anyway - you want to know the protocol state in order to do optimal power management. Use a GPIO edge and assume it's a '$', pick up via UART from the next byte, power the UART off the moment you see \n. Leave the power on if you seem to be out of sync so you can find a '$' and resync.
If you have driver specific code for this your driver gets told when the line discipline changes so you can actually bury such logic in your low level driver and even hide what is going on from above.
I've never had a problemw with what you are doing - just that it needs to b generic to be upstream, otherwise every serial driver would immediately develop thousands of lines of code for fifty differently wired and working phone and IoT devices.
If the tty being open and normal tty operations are acceptable for the write/configuration side then the point I've been trying to make is you can't generically handle this at the uart layer.
At the ldisc layer it would have a slightly higher latency but look something like (in an NMEA ldisc)
/* We got newline, tell the port to go into low power mode
directly or via whatever helpers it uses and to send us a '$'
when it wakes back up if it can't send us the true char */
if (port->slave) {
if (ch == '\n')
port->slave->ops.lowpower(port, '$');
/* If we get a $ then wakey wakey */
if (ch == '$')
port->slave->ops.lowpower(port, 0);
}
/* And if ops.lowpower is a no-op it all still works */That also means that the port->slave-> method would be called in a workqueue so can do sensible stuff even on things like USB
And the driver would presumably do something like
name = find_slave_name(blah); /* From DeviceTree etc */ if (name) port->slave = request_tty_slave(name);
(if you for some reason needed different behaviour knowledge at the slave level a tty ldisc change does notify the tty_port so we can do that too)
Alan
Marcel Holtmann
maintainerHi Alan,
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
We do, today for bluetooth and other protocols just fine
I think it works (even with user-space HCI daemon) because bluetooth HCI is slow (<300kByte/s).
We do it for PPP over 3G modem as well. Modern 3G modems pretend to be network devices, older ones didn't - and you are correct that in that scenario we struggled (it's a lot better since Peter sorted the locking out to be efficient).
you have this backwards. Older 3G modems pretended to by Hayes compatible and pretended to be talking PPP. However PPP is terminated in the modem itself. It is not spoken over the 3GPP networks. These are purely IP.
And yes, in theory there was a dialup in GSM, but I don't know of any users. Even early 9600 baud communication was RLP based. And for modern things like LTE it is IP all the way (including voice).
What some modems still do today is pretend they are Ethernet devices. That is faked by the modem as well and mainly for some odd Windows crap. However many modern modems give you the raw IP stream. You just have to ask nicely.
Regards
Marcel
Quoted 2 lines
I meant "Either some function similar to userspace's
poll()is needed, ...". Something likeuart_dev_wait_for_rx()
You can't really do that - it might never return and then how do you want to handle timeouts and cleanups
Quoted 2 lines
Alternatively the rx function could be a callback, that is called when there is new data.
That's what the existing API gives you as an ldisc, it can't be immediate in many cases however but must be buffered.
Quoted 3 lines
Quoted 1 line
I'm assuming the only immediate consumers are in-kernel.
Yes, but the driver should be notified about incoming data.
Alan
Hi Alan,
Quoted 5 lines · One Thousand Gnomes
Quoted 2 lines
I meant "Either some function similar to userspace's
poll()is needed, ...". Something likeuart_dev_wait_for_rx()You can't really do that - it might never return and then how do you want to handle timeouts and cleanups
Well there could be some timeout. As I said, I was thinking about an API similar to poll(), but I agree, that a callback based API is probably the better solution. It's simpler to implement and in most cases simpler to use.
Quoted 5 lines
Quoted 2 lines
Alternatively the rx function could be a callback, that is called when there is new data.
That's what the existing API gives you as an ldisc, it can't be immediate in many cases however but must be buffered.
I know and I think the ldisc API is fine in this regard. Also the buffering allows DMA, so that's obviously preferred.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I'm assuming the only immediate consumers are in-kernel.
Yes, but the driver should be notified about incoming data.
-- Sebastian
Quoted 4 lines · CEST Rob Herring
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Aside from the things that have already been mentioned in the discussion, I wonder how this should relate to the drivers/input/serio framework.
My impression is that there is some overlap in what you want to do here, and what serio does today as a line discipline on top of a tty line discipline (and on top of other non-uart serial connections), so we should look into whether the two can be unified or not. Here is what I found so far:
For all I can tell, serio is only used for drivers/input/ but could easily be extended to other subsystems. It currently uses its own binary ID matching between drivers and devices through user space interfaces, though adding a DT binding for it would appear to be a good idea regardless.
It also has a bus_type already, and with some operations defined on it. In particular, it has an "interrupt" method that is used to notify the client driver when a byte is available (and pass that byte along with it). This seems to be a useful addition to what you have. Since it is based on sending single characters both ways, transferring large amounts of data would be slower, but the interface is somewhat simpler. In principle, both character based and buffer based interfaces could coexist here as they do in some other interfaces (e.g. smbus).
While serio is typically layered on top of tty-ldisc (on top of tty_port, which is often on top of uart_port) or on top of i8042/ps2 drivers, I suppose we could add another back-end on top of uart_port directly to avoid the ldisc configuration in many cases when using devicetree based setup. This should also address the main concern that Alan raised about generality of the
subsystem: we'd always leave the option of either manual configuration of the tty-ldisc (for any tty_port) or configuring on-chip devices (using uart_port) directly through DT. Of course the same thing can be done if we hook into tty_port rather than uart_port.
Arnd
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · CEST Rob Herring
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Aside from the things that have already been mentioned in the discussion, I wonder how this should relate to the
drivers/input/serioframework.
As I mentioned, I did investigate that route.
Quoted 12 lines
My impression is that there is some overlap in what you want to do here, and what serio does today as a line discipline on top of a tty line discipline (and on top of other non-uart serial connections), so we should look into whether the two can be unified or not. Here is what I found so far:
For all I can tell, serio is only used for
drivers/input/but could easily be extended to other subsystems. It currently uses its own binary ID matching between drivers and devices through user space interfaces, though adding a DT binding for it would appear to be a good idea regardless.
Quoted 9 lines
It also has a
bus_typealready, and with some operations defined on it. In particular, it has an "interrupt" method that is used to notify the client driver when a byte is available (and pass that byte along with it). This seems to be a useful addition to what you have. Since it is based on sending single characters both ways, transferring large amounts of data would be slower, but the interface is somewhat simpler. In principle, both character based and buffer based interfaces could coexist here as they do in some other interfaces (e.g. smbus).
Given that about the only things it really provided are the bus_type and associated boilerplate without much of a client interface, it seemed to me that creating a new subsystem first made more sense. Then we can convert serio to use the new subsystem.
I agree we'll probably need a character at time interface, but for initial targets a buffer based interface is what's needed.
Quoted 10 lines
While serio is typically layered on top of tty-ldisc (on top of
tty_port, which is often on top ofuart_port) or on top of i8042/ps2 drivers, I suppose we could add another back-end on top ofuart_portdirectly to avoid the ldisc configuration in many cases when using devicetree based setup. This should also address the main concern that Alan raised about generality of the
subsystem: we'd always leave the option of either manual configuration of the tty-ldisc (for anytty_port) or configuring on-chip devices (usinguart_port) directly through DT. Of course the same thing can be done if we hook intotty_portrather thanuart_port.
There are also some uart drivers that register directly with serio.
I'm also thinking of using an ldisc backend as well as a way to move forward with the slave drivers while tty_port rework is being done. Of course that doesn't solve the fundamental problems with using an ldisc already. Going the tty_port route is going take some time to restructure things in the tty layer and require tree wide changes to tty drivers.
Rob
Quoted 11 lines · CEST Rob Herring
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · CEST Rob Herring
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Aside from the things that have already been mentioned in the discussion, I wonder how this should relate to the
drivers/input/serioframework.As I mentioned, I did investigate that route.
Ok, sorry for missing that.
Quoted 22 lines
Quoted 12 lines
My impression is that there is some overlap in what you want to do here, and what serio does today as a line discipline on top of a tty line discipline (and on top of other non-uart serial connections), so we should look into whether the two can be unified or not. Here is what I found so far:
For all I can tell, serio is only used for
drivers/input/but could easily be extended to other subsystems. It currently uses its own binary ID matching between drivers and devices through user space interfaces, though adding a DT binding for it would appear to be a good idea regardless.Quoted 9 lines
It also has a
bus_typealready, and with some operations defined on it. In particular, it has an "interrupt" method that is used to notify the client driver when a byte is available (and pass that byte along with it). This seems to be a useful addition to what you have. Since it is based on sending single characters both ways, transferring large amounts of data would be slower, but the interface is somewhat simpler. In principle, both character based and buffer based interfaces could coexist here as they do in some other interfaces (e.g. smbus).
Quoted 4 lines
Given that about the only things it really provided are the
bus_typeand associated boilerplate without much of a client interface, it seemed to me that creating a new subsystem first made more sense. Then we can convert serio to use the new subsystem.
One possible downside of merging later is that we end up having to support the existing user space ABI for serio that may not fit well within whatever we come up with independently.
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of the tty_ldisc
Quoted 2 lines
I agree we'll probably need a character at time interface, but for initial targets a buffer based interface is what's needed.
I think what's more important than the 'character-at-a-time' interface is the notification about new data. Maybe I missed how you handle that today, but it seems that you can currently only handle polling for data using a blocking read.
Quoted 11 lines
Quoted 10 lines
While serio is typically layered on top of tty-ldisc (on top of
tty_port, which is often on top ofuart_port) or on top of i8042/ps2 drivers, I suppose we could add another back-end on top ofuart_portdirectly to avoid the ldisc configuration in many cases when using devicetree based setup. This should also address the main concern that Alan raised about generality of the
subsystem: we'd always leave the option of either manual configuration of the tty-ldisc (for anytty_port) or configuring on-chip devices (usinguart_port) directly through DT. Of course the same thing can be done if we hook intotty_portrather thanuart_port.
Quoted 1 line
There are also some uart drivers that register directly with serio.
Right, I think this is done to have automatic probing for the keyboard, rather than relying on the user space interface configuration.
Quoted 6 lines
I'm also thinking of using an ldisc backend as well as a way to move forward with the slave drivers while
tty_portrework is being done. Of course that doesn't solve the fundamental problems with using an ldisc already. Going thetty_portroute is going take some time to restructure things in the tty layer and require tree wide changes to tty drivers.
Would it make sense then to define a DT binding that can cover these four cases independent of the Linux usage:
a) an existing tty line discipline matched to a tty port
b) a serio device using the N_MOUSE line discipline (which happens to cover non-mouse devices these days)
c) a uart_port slave attached directly to the uart (like in your current code)
d) the same slave drivers using a new tty line discipline
If we can handle all four, then at least we have some flexibility with moving around or merging the Linux implementation later.
Arnd
Marcel Holtmann
maintainerHi Arnd,
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
My impression is that there is some overlap in what you want to do here, and what serio does today as a line discipline on top of a tty line discipline (and on top of other non-uart serial connections), so we should look into whether the two can be unified or not. Here is what I found so far:
For all I can tell, serio is only used for
drivers/input/but could easily be extended to other subsystems. It currently uses its own binary ID matching between drivers and devices through user space interfaces, though adding a DT binding for it would appear to be a good idea regardless.It also has a
bus_typealready, and with some operations defined on it. In particular, it has an "interrupt" method that is used to notify the client driver when a byte is available (and pass that byte along with it). This seems to be a useful addition to what you have. Since it is based on sending single characters both ways, transferring large amounts of data would be slower, but the interface is somewhat simpler. In principle, both character based and buffer based interfaces could coexist here as they do in some other interfaces (e.g. smbus).
Quoted 8 lines
Quoted 4 lines
Given that about the only things it really provided are the
bus_typeand associated boilerplate without much of a client interface, it seemed to me that creating a new subsystem first made more sense. Then we can convert serio to use the new subsystem.One possible downside of merging later is that we end up having to support the existing user space ABI for serio that may not fit well within whatever we come up with independently.
if we need any kind of userspace ABI to setup of Bluetooth over UART devices, then we have failed. We want that the special UARTs are identified via ACPI or DT and become an enumeratable bus. So we can attach a driver to it.
Regards
Marcel
Quoted 27 lines · CEST Marcel Holtmann
Quoted 27 lines
Quoted 26 lines
Quoted 12 lines
My impression is that there is some overlap in what you want to do here, and what serio does today as a line discipline on top of a tty line discipline (and on top of other non-uart serial connections), so we should look into whether the two can be unified or not. Here is what I found so far:
For all I can tell, serio is only used for
drivers/input/but could easily be extended to other subsystems. It currently uses its own binary ID matching between drivers and devices through user space interfaces, though adding a DT binding for it would appear to be a good idea regardless.Quoted 9 lines
It also has a
bus_typealready, and with some operations defined on it. In particular, it has an "interrupt" method that is used to notify the client driver when a byte is available (and pass that byte along with it). This seems to be a useful addition to what you have. Since it is based on sending single characters both ways, transferring large amounts of data would be slower, but the interface is somewhat simpler. In principle, both character based and buffer based interfaces could coexist here as they do in some other interfaces (e.g. smbus).Given that about the only things it really provided are the
bus_typeand associated boilerplate without much of a client interface, it seemed to me that creating a new subsystem first made more sense. Then we can convert serio to use the new subsystem.
Quoted 8 lines
Quoted 3 lines
One possible downside of merging later is that we end up having to support the existing user space ABI for serio that may not fit well within whatever we come up with independently.
if we need any kind of userspace ABI to setup of Bluetooth over UART devices, then we have failed. We want that the special UARTs are identified via ACPI or DT and become an enumeratable bus. So we can attach a driver to it.
I was not referring to new devices here, only to the existing user space ABI that is used for serio (input) devices. If we have any tools relying on e.g. the 'serio' name for the sysfs path, using another name for the new bus_type may cause incompatibility when merging the two.
Arnd
Quoted 6 lines
Would it make sense then to define a DT binding that can cover these four cases independent of the Linux usage:
a) an existing tty line discipline matched to a tty port
b) a serio device using theN_MOUSEline discipline (which happens to cover non-mouse devices these days)
These two are the same basic thing
port x expects ldisc y {with properties ...}Quoted 2 lines
c) a
uart_portslave attached directly to the uart (like in your current code)
c) needs to be a tty_port slave attached directly to a tty_port. Important detail, but as uart_port is just a subset of tty_port it's a trivial detail to the DT.
Quoted 1 line
d) the same slave drivers using a new tty line discipline
and this is also just a/b again.
What use cases and connectivity do you need to describe. Looking at the ACPI platforms we have
- the expected serial port configuration
- the properties of the port (FIFO etc)
- the power management for the port
- the children of the port
- the power management of the children (at a very simplistic abstracted level)
So we want to be able to describe something like
ttyS0 {
baud: 1152008N1
protocol: bluetooth hci
fixed: yes
powermanagement: { ... }}
and if I look at the usermode crapfest on a lot of Android systems it looks similar but with the notion of things like being able to describe
- Use GPIO mode sleeping and assume first char is X to save power
- Power up, wait n ms, write, read, wait n ms, power down (which
has to be driven at the ldisc/user level as only the ldisc understands transactions, or via ioctls (right now Android user space tends to do hardcoded writes to /sys.. gpio to drive power
- And a few variants thereof (power up on write, off on a timer
etc)
So I can imagine wanting to describe something like
- The bluetooth HCI hardware is managed by gpio 11 (or UART DTR,
or PMIC n etc)
The uart can switch into GPIO mode and is gpio 15
or
- Raise gpio 4 when writing, drop it after 50mS with no read/write
Then the ldisc needs to make port->ops. calls for enabling/disabling low power mode and expected char, and the uarts that can do it need to implement the gpio/uart switching and any timers.
Alan
Marcel Holtmann
maintainerHi Alan,
Quoted 34 lines
Quoted 6 lines
Would it make sense then to define a DT binding that can cover these four cases independent of the Linux usage:
a) an existing tty line discipline matched to a tty port
b) a serio device using theN_MOUSEline discipline (which happens to cover non-mouse devices these days)These two are the same basic thing
port x expects ldisc y {with properties ...}Quoted 2 lines
c) a
uart_portslave attached directly to the uart (like in your current code)c) needs to be a
tty_portslave attached directly to atty_port. Important detail, but asuart_portis just a subset oftty_portit's a trivial detail to the DT.Quoted 1 line
d) the same slave drivers using a new tty line discipline
and this is also just a/b again.
What use cases and connectivity do you need to describe. Looking at the ACPI platforms we have
- the expected serial port configuration
- the properties of the port (FIFO etc)
- the power management for the port- the children of the port
- the power management of the children (at a very simplistic abstracted level)
Quoted 8 lines
So we want to be able to describe something like
ttyS0 { baud: 1152008N1 protocol: bluetooth hci fixed: yes powermanagement: { ... }}
we also need to know what Bluetooth vendor is there. Since we need to match the vendor to the firmware loading and configuration.
Additionally there might be PCM audio configurations that need to be considered. Since we have to configure direct PCM interconnect with the audio codec.
Review
Quoted 12 lines
and if I look at the usermode crapfest on a lot of Android systems it looks similar but with the notion of things like being able to describe
(quoted diff) +0
-2- Use GPIO mode sleeping and assume first char is X to save power - Power up, wait n ms, write, read, wait n ms, power down (whichhas to be driven at the ldisc/user level as only the ldisc understands transactions, or via ioctls (right now Android user space tends to do hardcoded writes to /sys.. gpio to drive power
(quoted diff) +0
-1- And a few variants thereof (power up on write, off on a timer etc)
Actually the sad part about the Android mess is that we can fix it for Bluetooth. We have HCI User Channel that allows to grab a HCI device and assign it to Bluedroid stack on Android. So it would work with whatever bus or whatever vendor is underneath. All this hacking would go away. And we have used this successfully for Intel based Android platforms. We know this works.
Quoted 10 lines
So I can imagine wanting to describe something like
(quoted diff) +0
-1- The bluetooth HCI hardware is managed by gpio 11 (or UART DTR,or PMIC n etc)
The uart can switch into GPIO mode and is gpio 15or
(quoted diff) +0
-1- Raise gpio 4 when writing, drop it after 50mS with no read/write
Quoted 3 lines
Then the ldisc needs to make
port->ops. calls for enabling/disabling low power mode and expected char, and the uarts that can do it need to implement the gpio/uart switching and any timers.
I now wonder if we can not just turn the ldisc into a bus. So we have a ldisc bus that exposes devices that have no business of having a userspace /dev/ttyX exposed. And our Bluetooth UART support just turns into a ldisc driver on the ldisc bus.
One of the problems is that attaching the ldisc from userspace you still need to figure out what /dev/ttyX you get assigned in the end. And figure out which one is the Bluetooth UART. If we want single images where things just work out of the box, we need to get extra information for doing auto-detection. So some sort of bus enumeration is key to make this work smoothly.
Regards
Marcel
Quoted 1 line
I now wonder if we can not just turn the ldisc into a bus. So we have a ldisc bus that exposes devices that have no business of having a userspace
/dev/ttyXexposed. And our Bluetooth UART support just turns into a ldisc driver on the ldisc bus.
The ldisc and tty have the wrong object lifetime for a bus, but you can put the tty_port objects onto the bus, and it is those you need to instantiate the stack.
The port exists for hardware lifetime, the tty and ldisc exist only while the port is "up".
Alan
Hi,
Quoted 43 lines · Marcel Holtmann
Quoted 34 lines
Quoted 6 lines
Would it make sense then to define a DT binding that can cover these four cases independent of the Linux usage:
a) an existing tty line discipline matched to a tty port
b) a serio device using theN_MOUSEline discipline (which happens to cover non-mouse devices these days)These two are the same basic thing
port x expects ldisc y {with properties ...}Quoted 2 lines
c) a
uart_portslave attached directly to the uart (like in your current code)c) needs to be a
tty_portslave attached directly to atty_port. Important detail, but asuart_portis just a subset oftty_portit's a trivial detail to the DT.Quoted 1 line
d) the same slave drivers using a new tty line discipline
and this is also just a/b again.
What use cases and connectivity do you need to describe. Looking at the ACPI platforms we have
- the expected serial port configuration
- the properties of the port (FIFO etc)
- the power management for the port- the children of the port
- the power management of the children (at a very simplistic abstracted level)Quoted 8 lines
So we want to be able to describe something like
ttyS0 { baud: 1152008N1 protocol: bluetooth hci fixed: yes powermanagement: { ... }}
Quoted 6 lines
we also need to know what Bluetooth vendor is there. Since we need to match the vendor to the firmware loading and configuration.
Additionally there might be PCM audio configurations that need to be considered. Since we have to configure direct PCM interconnect with the audio codec.
It's not enough to automatically set a ldisc. There is also need for additional resouces. For example the Nokia bluetooth driver needs some extra GPIOs. The same is true for the in-tree hci_bcm, which misuses the platform_device exactly like Greg doesn't want it.
Quoted 39 lines
Review
Quoted 12 lines
and if I look at the usermode crapfest on a lot of Android systems it looks similar but with the notion of things like being able to describe
(quoted diff) +0
-2- Use GPIO mode sleeping and assume first char is X to save power - Power up, wait n ms, write, read, wait n ms, power down (whichhas to be driven at the ldisc/user level as only the ldisc understands transactions, or via ioctls (right now Android user space tends to do hardcoded writes to /sys.. gpio to drive power
(quoted diff) +0
-1- And a few variants thereof (power up on write, off on a timer etc)Actually the sad part about the Android mess is that we can fix it for Bluetooth. We have HCI User Channel that allows to grab a HCI device and assign it to Bluedroid stack on Android. So it would work with whatever bus or whatever vendor is underneath. All this hacking would go away. And we have used this successfully for Intel based Android platforms. We know this works.
Quoted 10 lines
So I can imagine wanting to describe something like
(quoted diff) +0
-1- The bluetooth HCI hardware is managed by gpio 11 (or UART DTR,or PMIC n etc)
The uart can switch into GPIO mode and is gpio 15or
(quoted diff) +0
-1- Raise gpio 4 when writing, drop it after 50mS with no read/writeQuoted 3 lines
Then the ldisc needs to make
port->ops. calls for enabling/disabling low power mode and expected char, and the uarts that can do it need to implement the gpio/uart switching and any timers.I now wonder if we can not just turn the ldisc into a bus. So we have a ldisc bus that exposes devices that have no business of having a userspace
/dev/ttyXexposed. And our Bluetooth UART support just turns into a ldisc driver on the ldisc bus.
Quoted 6 lines
One of the problems is that attaching the ldisc from userspace you still need to figure out what
/dev/ttyXyou get assigned in the end. And figure out which one is the Bluetooth UART. If we want single images where things just work out of the box, we need to get extra information for doing auto-detection. So some sort of bus enumeration is key to make this work smoothly.
I don't understand your propsoal. First you write, that no ttyX needs to be exported at all, then you need to figure out what ttyX got assigned in the end.
I think the problem with line disciplines is, that they do not follow the Linux device model. UART slaves may have extra resources like gpios or regulators. The current workaround from the drivers is an additional platform device, which only is used as resource storage and accessed by the line discipline.
I think having a proper slave devices would be better in the long run than adding more hacks to work around the problem of line discplines not being devices. It probably makes sense to make the API similar to the line discipline API, though. That way old code can be reused.
-- Sebastian
Quoted 4 lines
It's not enough to automatically set a ldisc. There is also need for additional resouces. For example the Nokia bluetooth driver needs some extra GPIOs. The same is true for the in-tree
hci_bcm, which misuses theplatform_deviceexactly like Greg doesn't want it.
This is one of those cases where ACPI gets it right. For the device tree case you will also need to describe the GPIO lines as part of your power management for that slave device.
Quoted 2 lines
I think the problem with line disciplines is, that they do not follow the Linux device model. UART slaves may have extra
They follow it exactly.
You have a tty_port which wraps a device, and has the lifetime of the hardware and lives on busses and can support enumeration.
You have a tty which is a file system object with a lifetime determined by the use of the file handle, it's like any other file->private_data but quite complex because we must comply with POSIX and historic Unix tty behaviour.
You have an ldisc, which is simply a modularisation of the current protocol handler and is carefully engineered not to include any device specific knowledge. That's how you make it scale and actually work sanely.
Quoted 1 line
resources like gpios or regulators.
Any resources belong to the tty_port or a child of the tty_port because only it has the correct lifetime. And yes it's perfectly reasonable for us to attach other resources to a tty_port or give it a child that is the device the other end of the fixed link. Everything the DT describes belongs hanging off the tty_port or a child thereof.
We don't get this problem in ACPI space in general because as far as ACPI is concerned the tty has a child device and the child device describes its own power management so you just power the child on or off through ACPI and ACPI describes power sanely.
Eveything you have that is device specific belongs in the tty_port driver for that hardware, or maybe shared library helpers if common.
Everything you have which involves invoking device defined policy according to protocol defined behaviour belongs in the ldisc.
Unix has worked like this for well over 30 years and it works very well as a model.
Alan
Hi,
Quoted 17 lines · One Thousand Gnomes
Quoted 4 lines
It's not enough to automatically set a ldisc. There is also need for additional resouces. For example the Nokia bluetooth driver needs some extra GPIOs. The same is true for the in-tree
hci_bcm, which misuses theplatform_deviceexactly like Greg doesn't want it.This is one of those cases where ACPI gets it right. For the device tree case you will also need to describe the GPIO lines as part of your power management for that slave device.
Quoted 2 lines
I think the problem with line disciplines is, that they do not follow the Linux device model. UART slaves may have extra
They follow it exactly.
You have a
tty_portwhich wraps a device, and has the lifetime of the hardware and lives on busses and can support enumeration.
Quoted 8 lines
You have a tty which is a file system object with a lifetime determined by the use of the file handle, it's like any other
file->private_databut quite complex because we must comply with POSIX and historic Unix tty behaviour.You have an ldisc, which is simply a modularisation of the current protocol handler and is carefully engineered not to include any device specific knowledge. That's how you make it scale and actually work sanely.
I think the current support is far from sane for hardwired serial-based bluetooth devices. I open the serial device, set the line disector, set the vendor and maybe some other extra information and then do nothing, since the kernel handles everything for me. All of the information given to the kernel could be done automatically using the firmware information. Why should I care how my bluetooth device is connected?
Quoted 7 lines
Quoted 1 line
resources like gpios or regulators.
Any resources belong to the
tty_portor a child of thetty_portbecause only it has the correct lifetime. And yes it's perfectly reasonable for us to attach other resources to atty_portor give it a child that is the device the other end of the fixed link. Everything the DT describes belongs hanging off thetty_portor a child thereof.
Right we need a _child_, since we describe the other end of the fixed link. Adding random remote end resources to the tty_port looks like a huge hack.
Quoted 10 lines
We don't get this problem in ACPI space in general because as far as ACPI is concerned the tty has a child device and the child device describes its own power management so you just power the child on or off through ACPI and ACPI describes power sanely.
Eveything you have that is device specific belongs in the
tty_portdriver for that hardware, or maybe shared library helpers if common.Everything you have which involves invoking device defined policy according to protocol defined behaviour belongs in the ldisc.
ACPI is not better in this regard. Have a look at drivers/bluetooth/hci_bcm.c and you will see a platform device providing the GPIOs, which is then accessed by the line discipline.
Quoted 2 lines
Unix has worked like this for well over 30 years and it works very well as a model.
TBH I don't think it does.
Why should I need to tell the kernel something, that it could know automatically. Let's think about hci_bcm. The firmware tells the kernel, that some bluetooth device is connected to the uart port. The kernel ignores that information until the user also tells it, that the bluetooth chip is connected to some tty. If the kernel had done the right job, the user wouldn't even know, that bluetooth is connected via UART.
-- Sebastian
Quoted 4 lines · One Thousand Gnomes
and if I look at the usermode crapfest on a lot of Android systems it looks similar but with the notion of things like being able to describe
- Use GPIO mode sleeping and assume first char is X to save power
It's really nasty hardware design, or a software hack to solve a hardware problem: what should have been done is
of course create a UART with an asynchronous low-power mode that can recieve a character and wake up the system at any time, handing over the wakeup character(s) to the driver. That is obviously the usecase they were designing for.
But yeah, I guess we have to contain hacks like that.
Quoted 4 lines
- Power up, wait n ms, write, read, wait n ms, power down (which
has to be driven at the ldisc/user level as only the ldisc understands transactions, or via ioctls (right now Android user space tends to do hardcoded writes to /sys.. gpio to drive power
This kind of abominational abuse of the GPIO sysfs ABI is partly why I've obsoleted it. The right abstraction is the fixed regulator with a GPIO line obviously, then some sequencing along the lines of what you can find in drivers/mmc/core/pwrseq*
Unfortunately that sysfs ABI crept in during a window of time when GPIO was unmaintained and I am trying my best to contain and improve the situation.
Yours,
Linus Walleij
Quoted 42 lines · Arnd Bergmann
Quoted 11 lines · CEST Rob Herring
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · CEST Rob Herring
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Aside from the things that have already been mentioned in the discussion, I wonder how this should relate to the
drivers/input/serioframework.As I mentioned, I did investigate that route.
Ok, sorry for missing that.
Quoted 22 lines
Quoted 12 lines
My impression is that there is some overlap in what you want to do here, and what serio does today as a line discipline on top of a tty line discipline (and on top of other non-uart serial connections), so we should look into whether the two can be unified or not. Here is what I found so far:
For all I can tell, serio is only used for
drivers/input/but could easily be extended to other subsystems. It currently uses its own binary ID matching between drivers and devices through user space interfaces, though adding a DT binding for it would appear to be a good idea regardless.Quoted 9 lines
It also has a
bus_typealready, and with some operations defined on it. In particular, it has an "interrupt" method that is used to notify the client driver when a byte is available (and pass that byte along with it). This seems to be a useful addition to what you have. Since it is based on sending single characters both ways, transferring large amounts of data would be slower, but the interface is somewhat simpler. In principle, both character based and buffer based interfaces could coexist here as they do in some other interfaces (e.g. smbus).Quoted 4 lines
Given that about the only things it really provided are the
bus_typeand associated boilerplate without much of a client interface, it seemed to me that creating a new subsystem first made more sense. Then we can convert serio to use the new subsystem.
Quoted 8 lines
One possible downside of merging later is that we end up having to support the existing user space ABI for serio that may not fit well within whatever we come up with independently.
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of thetty_ldisc
True, though I'd expect little of the data flow part of it to be reused.
Quoted 7 lines
Quoted 2 lines
I agree we'll probably need a character at time interface, but for initial targets a buffer based interface is what's needed.
I think what's more important than the 'character-at-a-time' interface is the notification about new data. Maybe I missed how you handle that today, but it seems that you can currently only handle polling for data using a blocking read.
What's there now I expect to change anyway. Probably will mirror the ldisc interface based on the discussion.
Quoted 23 lines
Quoted 11 lines
Quoted 10 lines
While serio is typically layered on top of tty-ldisc (on top of
tty_port, which is often on top ofuart_port) or on top of i8042/ps2 drivers, I suppose we could add another back-end on top ofuart_portdirectly to avoid the ldisc configuration in many cases when using devicetree based setup. This should also address the main concern that Alan raised about generality of the
subsystem: we'd always leave the option of either manual configuration of the tty-ldisc (for anytty_port) or configuring on-chip devices (usinguart_port) directly through DT. Of course the same thing can be done if we hook intotty_portrather thanuart_port.Quoted 1 line
There are also some uart drivers that register directly with serio.
Right, I think this is done to have automatic probing for the keyboard, rather than relying on the user space interface configuration.
Quoted 6 lines
I'm also thinking of using an ldisc backend as well as a way to move forward with the slave drivers while
tty_portrework is being done. Of course that doesn't solve the fundamental problems with using an ldisc already. Going thetty_portroute is going take some time to restructure things in the tty layer and require tree wide changes to tty drivers.
Quoted 6 lines
Would it make sense then to define a DT binding that can cover these four cases independent of the Linux usage:
a) an existing tty line discipline matched to a tty port
b) a serio device using theN_MOUSEline discipline (which happens to cover non-mouse devices these days)
I agree with Alan these are the same. tty ldisc and tty ports are Linux concepts which shouldn't leak into DT. I've rejected bindings with "ttyBLAH" in them several times. Even if we did allow it, that sounds a half solution to me. Now if the binding is the same as (c) and there is some mapping of slave compatible string to ldisc, then perhaps that is fine.
Quoted 4 lines
c) a
uart_portslave attached directly to the uart (like in your current code)From a binding standpoint, I think it is pretty simple. It's been
discussed several times, but does need to get written down in a common binding doc. IMO it is:
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).
- baudrate and other line configuration (though I would expect the slave driver to know all this and set it w/o DT. Also, we already have a way to set baudrate in the parent node at least.)
- other standard device properties for interrupt, gpios, regulators.
Also to consider is whether muxing of multiple slaves is needed. It's not anything I've seen come up, but it's not hard to imagine. I think that can be considered later and shouldn't impact the initial binding or infrastructure.
Quoted 1 line
d) the same slave drivers using a new tty line discipline
As with (a) and (b), this should be an internal kernel detail or manual config.
Rob
Quoted 6 lines
Quoted 4 lines
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of thetty_ldiscTrue, though I'd expect little of the data flow part of it to be reused.
Then your design is broken.
Quoted 3 lines
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).
That surprises me as for current x86 platforms it would be the norm, except that we use ACPI.
Quoted 9 lines
- baudrate and other line configuration (though I would expect the slave driver to know all this and set it w/o DT. Also, we already have a way to set baudrate in the parent node at least.)
- other standard device properties for interrupt, gpios, regulators.Also to consider is whether muxing of multiple slaves is needed. It's not anything I've seen come up, but it's not hard to imagine. I think that can be considered later and shouldn't impact the initial binding or infrastructure.
You can describe the child of the serial device as a mux and the children of the mux as whatever so it comes out fine when you get to that point.
Alan
Quoted 8 lines · One Thousand Gnomes
Quoted 6 lines
Quoted 4 lines
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of thetty_ldiscTrue, though I'd expect little of the data flow part of it to be reused.
Then your design is broken.
I'm talking about serio, not my design which I already said the receive side at least needs work.
The serio API for rx and tx is a single character at a time. I thought we agreed that's not sufficient for things like BT.
Quoted 6 lines
Quoted 3 lines
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).That surprises me as for current x86 platforms it would be the norm, except that we use ACPI.
Exactly, we're talking DT bindings here. Each port will be a separate node otherwise things like serial aliases and stdout-path won't work correctly. Compatible strings for 8250 uarts are for a single port. But if you had h/w such that it has common and per port registers then it may be a single node. I'm not aware of any example offhand (maybe PPC CPM). But it doesn't matter as reg can handle this case just fine if we need to.
Quoted 5 lines
Quoted 5 lines
- baudrate and other line configuration (though I would expect the slave driver to know all this and set it w/o DT. Also, we already have a way to set baudrate in the parent node at least.)
- other standard device properties for interrupt, gpios, regulators.
Quoted 7 lines
Quoted 4 lines
Also to consider is whether muxing of multiple slaves is needed. It's not anything I've seen come up, but it's not hard to imagine. I think that can be considered later and shouldn't impact the initial binding or infrastructure.
You can describe the child of the serial device as a mux and the children of the mux as whatever so it comes out fine when you get to that point.
Yes, that's what I had in mind.
Rob
Quoted 5 lines
I'm talking about serio, not my design which I already said the receive side at least needs work.
The serio API for rx and tx is a single character at a time. I thought we agreed that's not sufficient for things like BT.
Yes.
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).That surprises me as for current x86 platforms it would be the norm, except that we use ACPI.
Quoted 7 lines
Exactly, we're talking DT bindings here. Each port will be a separate node otherwise things like serial aliases and stdout-path won't work correctly. Compatible strings for 8250 uarts are for a single port. But if you had h/w such that it has common and per port registers then it may be a single node. I'm not aware of any example offhand (maybe PPC CPM). But it doesn't matter as reg can handle this case just fine if we need to.
For the tty side by the way here's a first RFC of one approach we could take. This should (unless I missed anything) allow the core tty framework to be used directly from a kernel created tty object rather than one backed by a file.
commit fcd072e755594f9c9c0533d45223f56f76e3d104
Author: Alan <[email protected]> Date: Mon Aug 22 18:05:56 2016 +0100
[RFC] tty_port: allow a port to be opened with a tty that has no file handle
Let us create tty objects entirely in kernel space. Untested proposal to show why all the ideas around rewriting half the uart stack are not needed.
With this a kernel created non file backed tty object could be used to handle data, and set terminal modes. Not all ldiscs can cope with this as N_TTY in particular has to work back to the fs/tty layer.
The tty_port code is however otherwise clean of file handles as far as I can tell as is the low level tty port write path used by the ldisc, the configuration low level interfaces and most of the ldiscs.
Currently you don't have any exposure to see tty hangups because those are built around the file layer. However a) it's a fixed port so you probably don't care about that b) if you do we can add a callback and c) you almost certainly don't want the userspace tear down/rebuild behaviour anyway.
This should however be sufficient if we wanted for example to enumerate all the bluetooth bound fixed ports via ACPI and make them directly available.
It doesn't deal with the case of a user opening a port that's also kernel opened and that would need some locking out (so it returned EBUSY if bound to a kernel device of some kind). That needs resolving along with how you "up" or "down" your new bluetooth device, or enumerate it while providing the existing tty API to avoid regressions (and to debug).
Alan
drivers/tty/tty_io.c +1 -1
@@ -855,7 +855,7 @@ static void tty_vhangup_session(struct tty_struct *tty)int tty_hung_up_p (struct file *filp) { -return (filp->f_op == &hung_up_tty_fops); +return (filp && filp->f_op == &hung_up_tty_fops); }EXPORT_SYMBOL (tty_hung_up_p);
drivers/tty/tty_port.c +2 -2
@@ -335,7 +335,7 @@ EXPORT_SYMBOL(tty_port_lower_dtr_rts);* tty_port_block_til_ready - Waiting logic for tty open * @port: the tty port being opened * @tty: the tty device being bound -* @filp: the file pointer of the opener +* @filp: the file pointer of the opener or NULL * * Implement the core POSIX/SuS tty behaviour when opening a tty device. * Handles:
@@ -369,7 +369,7 @@ int tty_port_block_til_ready(struct tty_port *port,tty_port_set_active (port,1 );return 0 ; } -if (filp->f_flags &O_NONBLOCK ) { +if (filp ==NULL || (filp->f_flags &O_NONBLOCK )) {/* Indicate we are open */ if (C_BAUD (tty))tty_port_raise_dtr_rts (port);
Marcel Holtmann
maintainerHi Alan,
Quoted 42 lines
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).That surprises me as for current x86 platforms it would be the norm, except that we use ACPI.
Quoted 7 lines
Exactly, we're talking DT bindings here. Each port will be a separate node otherwise things like serial aliases and stdout-path won't work correctly. Compatible strings for 8250 uarts are for a single port. But if you had h/w such that it has common and per port registers then it may be a single node. I'm not aware of any example offhand (maybe PPC CPM). But it doesn't matter as reg can handle this case just fine if we need to.
For the tty side by the way here's a first RFC of one approach we could take. This should (unless I missed anything) allow the core tty framework to be used directly from a kernel created tty object rather than one backed by a file.
commit
fcd072e755594f9c9c0533d45223f56f76e3d104Author: Alan <[email protected]> Date: Mon Aug 22 18:05:56 2016 +0100[RFC]
tty_port: allow a port to be opened with a tty that has no file handleLet us create tty objects entirely in kernel space. Untested proposal to show why all the ideas around rewriting half the uart stack are not needed.
With this a kernel created non file backed tty object could be used to handle data, and set terminal modes. Not all ldiscs can cope with this as
N_TTYin particular has to work back to the fs/tty layer.The
tty_portcode is however otherwise clean of file handles as far as I can tell as is the low level tty port write path used by the ldisc, the configuration low level interfaces and most of the ldiscs.Currently you don't have any exposure to see tty hangups because those are built around the file layer. However a) it's a fixed port so you probably don't care about that b) if you do we can add a callback and c) you almost certainly don't want the userspace tear down/rebuild behaviour anyway.
Quoted 8 lines
This should however be sufficient if we wanted for example to enumerate all the bluetooth bound fixed ports via ACPI and make them directly available.
It doesn't deal with the case of a user opening a port that's also kernel opened and that would need some locking out (so it returned EBUSY if bound to a kernel device of some kind). That needs resolving along with how you "up" or "down" your new bluetooth device, or enumerate it while providing the existing tty API to avoid regressions (and to debug).
why would we even have it create a /dev/ttyX for these devices in the first place. Lets just not create an uevent for it and lets not create a dev_t for it.
The Bluetooth power on (aka hciconfig hci0 up/down) is already solved with modern Intel and Broadcom UART drivers. Essentially we attach the ldisc and tell it which vendor it is. That is it. Everything else is done inside the kernel from that point on.
So attaching the ldisc (via btattach tool) is similar to plugging in a dongle via USB. It runs that basic setup like firmware loading and configuration and then goes back into sleep mode. Only when powering the Bluetooth hciX device up (via bluetoothd or manually) it gets out of sleep mode. And the details for that are left up to the driver.
Internally the setup stage does a hciconfig hci0 up and it is already abstracted out that way. So there has been a lot of work in the Bluetooth subsystem to allow for this. That part is really solved.
Regards
Marcel
Quoted 1 line
why would we even have it create a
/dev/ttyXfor these devices in the first place. Lets just not create an uevent for it and lets not create adev_tfor it.
Because if you don't it's a regression. It's not permissible to break existing userspace.
Quoted 1 line
Internally the setup stage does a hciconfig hci0 up and it is already abstracted out that way. So there has been a lot of work in the Bluetooth subsystem to allow for this. That part is really solved.
So you'd create a kernel side tty struct and bind it to the tty_port on hci0 up and drop it on hci0 down ?
Alan
Quoted 4 lines · One Thousand Gnomes
Quoted 1 line
why would we even have it create a
/dev/ttyXfor these devices in the first place. Lets just not create an uevent for it and lets not create adev_tfor it.Because if you don't it's a regression. It's not permissible to break existing userspace.
Well... it would be good to do the right thing, at least in the places where we can.
Yes, renumbering people's serials is bad, OTOH for new platforms it would be nice not to expose ttyS15 which can only return -EBUSY.
And we may want to do incompatible change at some point. People should not have to use hciattach on n900 from now on until end of time, just because we exposed USB port as ttyO1 in past.
...actually. I guess we should disable that ttyO1 in the device tree for now, so nobody can start using it. As we currently have 2-3 people in world who got that bluetooth to work with out-of-tree patches, breakage should be quite acceptable :-).
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 11 lines · On Tue, 23 Aug 2016 00:00:17 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · One Thousand Gnomes
Quoted 1 line
why would we even have it create a
/dev/ttyXfor these devices in the first place. Lets just not create an uevent for it and lets not create adev_tfor it.Because if you don't it's a regression. It's not permissible to break existing userspace.
Well... it would be good to do the right thing, at least in the places where we can.
Yes, renumbering people's serials is bad, OTOH for new platforms it would be nice not to expose ttyS15 which can only return
-EBUSY.
That would still be a regression. Not everyone even uses the kernel bluetooth stack. It would only return EBUSY if you had done an "up" on it via the direct bluetooth stack.
Alan
Hi,
Quoted 12 lines · One Thousand Gnomes
Quoted 9 lines · On Tue, 23 Aug 2016 00:00:17 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines · One Thousand Gnomes
Quoted 1 line
why would we even have it create a
/dev/ttyXfor these devices in the first place. Lets just not create an uevent for it and lets not create adev_tfor it.Because if you don't it's a regression. It's not permissible to break existing userspace.
Well... it would be good to do the right thing, at least in the places where we can.
Quoted 6 lines
Quoted 2 lines
Yes, renumbering people's serials is bad, OTOH for new platforms it would be nice not to expose ttyS15 which can only return
-EBUSY.That would still be a regression. Not everyone even uses the kernel bluetooth stack. It would only return EBUSY if you had done an "up" on it via the direct bluetooth stack.
So it returns EBUSY when uart-bus is used. Since uart-bus is about hardwired devices that's basically always.
Also I wonder how relevant your "I want to handle all UART stuff out of kernel" scenario is for uart-bus, which is about in-kernel UART drivers.
-- Sebastian
Quoted 6 lines
Quoted 3 lines
That would still be a regression. Not everyone even uses the kernel bluetooth stack. It would only return EBUSY if you had done an "up" on it via the direct bluetooth stack.
So it returns EBUSY when uart-bus is used. Since uart-bus is about hardwired devices that's basically always.
That would only be when the bluetooth port in question was active via the hardwired interface - which is not always. You choose to turn on/off bluetooth interfaces. If you boot with an older user space you'd use hciattach instead.
In many cases you'll also still need the tty interface to do things like firmware upgrades.
Alan
Hi,
Quoted 11 lines · One Thousand Gnomes
Quoted 6 lines
Quoted 3 lines
That would still be a regression. Not everyone even uses the kernel bluetooth stack. It would only return EBUSY if you had done an "up" on it via the direct bluetooth stack.
So it returns EBUSY when uart-bus is used. Since uart-bus is about hardwired devices that's basically always.
That would only be when the bluetooth port in question was active via the hardwired interface - which is not always. You choose to turn on/off bluetooth interfaces. If you boot with an older user space you'd use hciattach instead.
So you mean if I do "hciconfig hci0 down", then the uart-bus should "down" the tty and only on "hciconfig hci0 up" it should "up" the tty? I would expect a uart-bus slave-device takes control of the device ("up" it) on probe. It's hardwired anyway.
Also what should happen if old userspace use hciattach while uart-bus slave-device doesn't have control over it? Do you suggest to implement some dummy code, that detects uart-bus already registered a hci device and returns success without doing anything? Then "hciconfig hci0 up" will fail, since the tty is already taken by hciattach.
Or do you suggest to register hci1 and one cannot use hci0? I guess this breaks even more devices, as the device number changes.
Also note, that there is a chance, that hci0 will go up by some script before hciattach has been called in your legacy userspace. Then it will also fail.
So yes, from your point of view there is a regression, just because it's working automatically. So let's just not convert existing boards with working hciattach based bluetooth devices. New devices can use the uart-bus, as it's not a regression for them and Nokia N series can also do it, since they have no working bluetooth at all at the moment.
Quoted 2 lines
In many cases you'll also still need the tty interface to do things like firmware upgrades.
I would expect the uart-slave driver to know how to do firmware updates. Actually most bluetooth chips are initialized by uploading a firmware to them.
And there are definitely uart drivers not caring about having a tty device. Nokia's vendor driver for their bluetooth protocol contains a custom omap-serial driver combined with the actual bluetooth driver. There is nothing related to the tty framework. I think the same would work for the other hardwired bluetooth chips perfectly fine.
Note: I'm not in favour of merging uart and bluetooth drivers. This is really bad design. But it shows, that /dev/tty interface is not needed by in-kernel drivers.
Of course tty is needed by userland drivers, but I expect, that those do not use the uart-bus. They already require all kind of hardware knowledge and don't work out-of-the-box anyway, so they do not gain from this framework.
-- Sebastian
Quoted 4 lines
So you mean if I do "hciconfig hci0 down", then the uart-bus should "down" the tty and only on "hciconfig hci0 up" it should "up" the tty? I would expect a uart-bus slave-device takes control of the device ("up" it) on probe. It's hardwired anyway.
Today you can switch stacks at runtime, you can switch between the kernel stack and debug tools at runtime. Breaking that is a regression.
Quoted 2 lines
Also what should happen if old userspace use hciattach while uart-bus slave-device doesn't have control over it? Do you
You would either use the old hciattach in which case you wouldn't be able to manage it via a new API while attached, or the new API in which case you wouldn't be able to manage it via the old interface while it was being used directly.
Quoted 2 lines
Or do you suggest to register hci1 and one cannot use hci0? I guess this breaks even more devices, as the device number changes.
Device numbers are dynamic anyway. Plug a USB adapter in and if it beats your onboard adapter to registration then the order changes.
Quoted 3 lines
So yes, from your point of view there is a regression, just because it's working automatically. So let's just not convert existing boards with working hciattach based bluetooth devices. New devices can use
=46rom a distribution point of view that would be a nightmare.
Quoted 3 lines
the uart-bus, as it's not a regression for them and Nokia N series can also do it, since they have no working bluetooth at all at the moment.
The Nokia N series is a weird corner case.
Quoted 6 lines
Quoted 2 lines
In many cases you'll also still need the tty interface to do things like firmware upgrades. =20
=20
I would expect the uart-slave driver to know how to do firmware updates. Actually most bluetooth chips are initialized by uploading a firmware to them.
Usually no - you don't want a ton of kernel code for flashing adapters when they have built in firmware (similar issue for 3G modems)
Quoted 6 lines
And there are definitely uart drivers not caring about having a tty device. Nokia's vendor driver for their bluetooth protocol contains a custom omap-serial driver combined with the actual bluetooth driver. There is nothing related to the tty framework. I think the same would work for the other hardwired bluetooth chips perfectly fine.
That means having two different omap serial drivers to maintain which is not ideal.
To me there are four different things
1. bluetooth devices "just work". That can be user space (eg it seems to just work on my Fedora boxes and bluetooth enumeration is being done via user space, or may be via kernel enumeration, or a mix. PPP is an existing example of this - serial port PPP is an ldisc but ports that are not UART like speak directly to the PPP layer as network adapters.
2. Sideband controls and power management, where we need to give the tty_port a child device and power it up/down properly and have the tty_port hooks to do so based upon the ldisc protocol state machine when talking stuff like NMEA or HCI.
3. The special case UART power saving features/hacks like GPIO snooping, again with the right hooks
4. Whether it's useful to be able to create a tty device in kernel and attach that to stuff with no userspace involved.
All are independent.
Alan
Marcel Holtmann
maintainerHi Alan,
Quoted 7 lines
Quoted 4 lines
So you mean if I do "hciconfig hci0 down", then the uart-bus should "down" the tty and only on "hciconfig hci0 up" it should "up" the tty? I would expect a uart-bus slave-device takes control of the device ("up" it) on probe. It's hardwired anyway.
Today you can switch stacks at runtime, you can switch between the kernel stack and debug tools at runtime. Breaking that is a regression.
actually that is not true. We have HCI User Channel since a long time that gives you raw access to the devices. And also kernel interfaces to do all vendor / debug tasks.
Regards
Marcel
Marcel Holtmann
maintainerHi Alan,
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
That would still be a regression. Not everyone even uses the kernel bluetooth stack. It would only return EBUSY if you had done an "up" on it via the direct bluetooth stack.
So it returns EBUSY when uart-bus is used. Since uart-bus is about hardwired devices that's basically always.
Quoted 7 lines
That would only be when the bluetooth port in question was active via the hardwired interface - which is not always. You choose to turn on/off bluetooth interfaces. If you boot with an older user space you'd use hciattach instead.
In many cases you'll also still need the tty interface to do things like firmware upgrades.
actually for Bluetooth you don't. We dealt with all of this crazy vendor stuff and provided proper hooks in the Bluetooth subsystem to support.
hciattach / btattach are just the hotplug trigger to attach the hardware. It is like plugging in an USB dongle into your USB port. That is how you have to see this. Killing the hciattach / btattach process is the unplug event. It is that simple.
And if you can skip the hciattach / btattach step and use kernel serial bus with proper enumeration and driver binding, then the end result is that you get a hci0 Bluetooth interface. The same way as you would have gotten when calling hciattach / btattach. Meaning you then call hciconfig hci0 up (or let bluetoothd do it for you) and you have Bluetooth working. It worked this way since 2.4.6 kernel.
The real power on is done via hciconfig hci0 up and not hciattach. The only difference is that since a long time now, kernel drivers can provide extra vendor hooks. And the kernel can internally and temporally power on the hardware if it has to do certain tasks. For example configuring the BD_ADDR, loading some patches or doing some audio configuration.
Regards
Marcel
Hi,
Quoted 7 lines · Pavel Machek
Quoted 6 lines · One Thousand Gnomes
Quoted 3 lines
why would we even have it create a
/dev/ttyXfor these devices in the first place. Lets just not create an uevent for it and lets not create adev_tfor it.Because if you don't it's a regression. It's not permissible to break existing userspace.
I guess there are three classes
1.) support for uart-slaves on new devices -> tty can be safely
disabled, as it was never exposed
2.) support for uart-slaves on devices, which exported a useless
tty (-> port could not be used from userspace without kernel modifications) [this is what N900 falls under]
3.) support for uart-slaves on devices, which could use hciattach
or similar tools previously. I think these devices can't switch to the new API without a regression anyways. If the kernel already registered the bluetooth stuff hciattach will fail due to the -EBUSY (or whatever is returned).
So from my point of view there is no real regression when we avoid exporting the tty at all.
Quoted 2 lines
Yes, renumbering people's serials is bad, OTOH for new platforms it would be nice not to expose ttyS15 which can only return
-EBUSY.
No need to renumber, there is the serial mapping in DT. We can just export ttyS0, ttyS2 and ttyS3 (and skip ttyS1, which is used for hardwired serial device).
Quoted 2 lines
And we may want to do incompatible change at some point. People should not have to use hciattach on n900 from now
Don't worry, since platform_driver approach has been NAK'd by Greg, the N900 bluetooth driver can only proceed once this patchset has gone into the kernel. So N900 will never use hciattach.
Quoted 2 lines
on until end of time, just because we exposed USB port as ttyO1 in past.
USB port as ttyO1?
Quoted 4 lines
...actually. I guess we should disable that ttyO1 in the device tree for now, so nobody can start using it. As we currently have 2-3 people in world who got that bluetooth to work with out-of-tree patches, breakage should be quite acceptable :-).
If you just disable ttyO1 in the N900's DT, you break runtime PM, since the kernel does not access disabled devices. We could add some kernel quirk, but who should use ttyO1 (which is btw named ttyS1 with 8251 based omap driver)? It's basically unusable from userspace.
-- Sebastian
Hi,
Quoted 24 lines · Rob Herring
Quoted 8 lines · One Thousand Gnomes
Quoted 6 lines
Quoted 4 lines
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of thetty_ldiscTrue, though I'd expect little of the data flow part of it to be reused.
Then your design is broken.
I'm talking about serio, not my design which I already said the receive side at least needs work.
The serio API for rx and tx is a single character at a time. I thought we agreed that's not sufficient for things like BT.
Quoted 6 lines
Quoted 3 lines
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).That surprises me as for current x86 platforms it would be the norm, except that we use ACPI.
Quoted 7 lines
Exactly, we're talking DT bindings here. Each port will be a separate node otherwise things like serial aliases and stdout-path won't work correctly. Compatible strings for 8250 uarts are for a single port. But if you had h/w such that it has common and per port registers then it may be a single node. I'm not aware of any example offhand (maybe PPC CPM). But it doesn't matter as reg can handle this case just fine if we need to.
I would expect, that your imaginary example h/w also has one node per port using a mfd style h/w description:
multi-uart-device {
uart1 {
child { };
};
uart2 {
child { };
};
};Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- baudrate and other line configuration (though I would expect the slave driver to know all this and set it w/o DT. Also, we already have a way to set baudrate in the parent node at least.)
I'm not sure if every slave driver knows this. Maybe some generic slave drivers will come up, once we have the infrastructure. So it could be useful to have the settings as optional properties. OTOH it can also be done once it is needed.
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
- other standard device properties for interrupt, gpios, regulators.
Also to consider is whether muxing of multiple slaves is needed. It's not anything I've seen come up, but it's not hard to imagine. I think that can be considered later and shouldn't impact the initial binding or infrastructure.
You can describe the child of the serial device as a mux and the children of the mux as whatever so it comes out fine when you get to that point.
Yes, that's what I had in mind.
I guess it can be discussed, when it becomes relevant. Until then let's not open another topic.
-- Sebastian
Quoted 38 lines · Sebastian Reichel
Hi,
Quoted 24 lines · Rob Herring
Quoted 8 lines · One Thousand Gnomes
Quoted 6 lines
Quoted 4 lines
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of thetty_ldiscTrue, though I'd expect little of the data flow part of it to be reused.
Then your design is broken.
I'm talking about serio, not my design which I already said the receive side at least needs work.
The serio API for rx and tx is a single character at a time. I thought we agreed that's not sufficient for things like BT.
Quoted 6 lines
Quoted 3 lines
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).That surprises me as for current x86 platforms it would be the norm, except that we use ACPI.
Quoted 7 lines
Exactly, we're talking DT bindings here. Each port will be a separate node otherwise things like serial aliases and stdout-path won't work correctly. Compatible strings for 8250 uarts are for a single port. But if you had h/w such that it has common and per port registers then it may be a single node. I'm not aware of any example offhand (maybe PPC CPM). But it doesn't matter as reg can handle this case just fine if we need to.
I would expect, that your imaginary example h/w also has one node per port using a mfd style h/w description:
Quoted 8 lines
multi-uart-device {
uart1 {
child { };
};
uart2 {
child { };
};
};Yes, that is certainly possible too.
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- baudrate and other line configuration (though I would expect the slave driver to know all this and set it w/o DT. Also, we already have a way to set baudrate in the parent node at least.)
I'm not sure if every slave driver knows this. Maybe some generic slave drivers will come up, once we have the infrastructure. So it could be useful to have the settings as optional properties. OTOH it can also be done once it is needed.
Yes, you could have devices that do autobaud detect and don't care other than some max baudrate which could be limited by either the host or device. Then you have others that are fixed or start at a fixed baud and then switch.
As for generic slaves, no doubt they will come up and I will be nak'ing the generic slave bindings. The "generic slave" is already supported via tty devices in userspace IMO.
Rob
Hi,
Quoted 48 lines · Rob Herring
Quoted 38 lines · Sebastian Reichel
Hi,
Quoted 24 lines · Rob Herring
Quoted 8 lines · One Thousand Gnomes
Quoted 6 lines
Quoted 4 lines
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of thetty_ldiscTrue, though I'd expect little of the data flow part of it to be reused.
Then your design is broken.
I'm talking about serio, not my design which I already said the receive side at least needs work.
The serio API for rx and tx is a single character at a time. I thought we agreed that's not sufficient for things like BT.
Quoted 6 lines
Quoted 3 lines
- a child of the uart node
- a reg property containing the line number if the parent has multiple uarts (I'd expect this to rarely be used).That surprises me as for current x86 platforms it would be the norm, except that we use ACPI.
Quoted 7 lines
Exactly, we're talking DT bindings here. Each port will be a separate node otherwise things like serial aliases and stdout-path won't work correctly. Compatible strings for 8250 uarts are for a single port. But if you had h/w such that it has common and per port registers then it may be a single node. I'm not aware of any example offhand (maybe PPC CPM). But it doesn't matter as reg can handle this case just fine if we need to.
I would expect, that your imaginary example h/w also has one node per port using a mfd style h/w description:
Quoted 8 lines
multi-uart-device { uart1 { child { }; }; uart2 { child { }; }; };
Quoted 1 line
Yes, that is certainly possible too.
That way aliases and stdout-path also works. I think I would just make one-node-per-uart-port mandatory and skip the reg part.
Let's assume your imaginary example h/w would be and i2c master with two ports and some shared registers. Then it immidiatly becomes clear, that one wants to somehow expose two ports in the DT instead of using some port selection property (and reg would already be taken).
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- baudrate and other line configuration (though I would expect the slave driver to know all this and set it w/o DT. Also, we already have a way to set baudrate in the parent node at least.)
I'm not sure if every slave driver knows this. Maybe some generic slave drivers will come up, once we have the infrastructure. So it could be useful to have the settings as optional properties. OTOH it can also be done once it is needed.
Quoted 8 lines
Yes, you could have devices that do autobaud detect and don't care other than some max baudrate which could be limited by either the host or device. Then you have others that are fixed or start at a fixed baud and then switch.
As for generic slaves, no doubt they will come up and I will be nak'ing the generic slave bindings. The "generic slave" is already supported via tty devices in userspace IMO.
Ok I didn't meant that generic. I meant something like "I have a remote controller with specific protocol, baudrate is board specific". Anyways it can be discussed once needed
-- Sebastian
+Dmitry to get his opinion on using serio.
Quoted 42 lines · Arnd Bergmann
Quoted 11 lines · CEST Rob Herring
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · CEST Rob Herring
Before I spend more time on this, I'm looking mainly for feedback on the general direction and structure (the interface with the existing serial drivers in particular).
Aside from the things that have already been mentioned in the discussion, I wonder how this should relate to the
drivers/input/serioframework.As I mentioned, I did investigate that route.
Ok, sorry for missing that.
Quoted 22 lines
Quoted 12 lines
My impression is that there is some overlap in what you want to do here, and what serio does today as a line discipline on top of a tty line discipline (and on top of other non-uart serial connections), so we should look into whether the two can be unified or not. Here is what I found so far:
For all I can tell, serio is only used for
drivers/input/but could easily be extended to other subsystems. It currently uses its own binary ID matching between drivers and devices through user space interfaces, though adding a DT binding for it would appear to be a good idea regardless.Quoted 9 lines
It also has a
bus_typealready, and with some operations defined on it. In particular, it has an "interrupt" method that is used to notify the client driver when a byte is available (and pass that byte along with it). This seems to be a useful addition to what you have. Since it is based on sending single characters both ways, transferring large amounts of data would be slower, but the interface is somewhat simpler. In principle, both character based and buffer based interfaces could coexist here as they do in some other interfaces (e.g. smbus).Quoted 4 lines
Given that about the only things it really provided are the
bus_typeand associated boilerplate without much of a client interface, it seemed to me that creating a new subsystem first made more sense. Then we can convert serio to use the new subsystem.
Quoted 8 lines
One possible downside of merging later is that we end up having to support the existing user space ABI for serio that may not fit well within whatever we come up with independently.
I think there are two other valuable features provided by serio:
- an existing set of drivers written to the API
- the implementation of thetty_ldisc
I've looked at serio a bit more and was able to add in DT matching to it. It's a bit hacky to make it work with the ldisc as it gets the DT node from serio->dev.parent->parent (the parent is the tty and grandparent is the uart dev) and still requires inputattach to open the tty and set the ldisc. Otherwise, the mode for inputattach doesn't matter. So I plan to continue down this path.
One thing I'm left wondering is serio essentially implements it's own async probing with connect()/disconnect(). Seems like it was because PS/2 port probing and resuming are slow. Is this still necessary or could be converted to use driver core async probing? That would make serio drivers look a bit more "normal".
Rob