tty: serial: switch from circ_buf to kfifo
Subsystems (33)
Jiri Slaby (SUSE)
maintainercover tty: serial: switch from circ_buf to kfifo
This series switches tty serial layer to use kfifo instead of circ_buf. Excerpt from the switching patch:
"""
Switch from struct circ_buf to proper kfifo. kfifo provides much better API, esp. when wrap-around of the buffer needs to be taken into account. Look at pl011_dma_tx_refill() or cpm_uart_tx_pump() changes for example.
Kfifo API can also fill in scatter-gather DMA structures, so it easier for that use case too. Look at lpuart_dma_tx() for example. Note that not all drivers can be converted to that (like atmel_serial), they handle DMA specially.
Note that usb-serial uses kfifo for TX for ages.
"""
This is Request for Testing as I cannot test all the changes (obviously). So please test your HW's serial properly.
And of course comments welcome.
I will send this as PATCHes later, when -rc1 is out, at earliest.
Jiri Slaby (SUSE) (15):
kfifo: drop __kfifo_dma_out_finish_r()
kfifo: introduce and use kfifo_skip_count()
kfifo: add kfifo_out_linear{,_ptr}()
kfifo: remove support for physically non-contiguous memory
kfifo: rename l to len_to_end in setup_sgl()
kfifo: pass offset to setup_sgl_buf() instead of a pointer
kfifo: add kfifo_dma_out_prepare_mapped()
kfifo: fix typos in kernel-doc
tty: 8250_dma: use dmaengine_prep_slave_sg()
tty: 8250_omap: use dmaengine_prep_slave_sg()
tty: msm_serial: use dmaengine_prep_slave_sg()
tty: serial: switch from circ_buf to kfifo
tty: atmel_serial: use single DMA mapping for TX
tty: atmel_serial: define macro for RX size
tty: atmel_serial: use single DMA mapping for RX
drivers/tty/serial/8250/8250_bcm7271.c | 14 +-- drivers/tty/serial/8250/8250_core.c | 3 +- drivers/tty/serial/8250/8250_dma.c | 31 +++-- drivers/tty/serial/8250/8250_exar.c | 5 +- drivers/tty/serial/8250/8250_mtk.c | 2 +- drivers/tty/serial/8250/8250_omap.c | 48 +++++--- drivers/tty/serial/8250/8250_pci1xxxx.c | 50 ++++---- drivers/tty/serial/8250/8250_port.c | 22 ++-- drivers/tty/serial/amba-pl011.c | 46 +++----- drivers/tty/serial/ar933x_uart.c | 15 ++- drivers/tty/serial/arc_uart.c | 8 +- drivers/tty/serial/atmel_serial.c | 150 +++++++++++------------- drivers/tty/serial/clps711x.c | 12 +- drivers/tty/serial/cpm_uart.c | 20 ++-- drivers/tty/serial/digicolor-usart.c | 12 +- drivers/tty/serial/dz.c | 13 +- drivers/tty/serial/fsl_linflexuart.c | 17 +-- drivers/tty/serial/fsl_lpuart.c | 39 +++--- drivers/tty/serial/icom.c | 25 +--- drivers/tty/serial/imx.c | 54 ++++----- drivers/tty/serial/ip22zilog.c | 26 ++-- drivers/tty/serial/jsm/jsm_cls.c | 29 ++--- drivers/tty/serial/jsm/jsm_neo.c | 38 ++---- drivers/tty/serial/max3100.c | 14 +-- drivers/tty/serial/max310x.c | 35 +++--- drivers/tty/serial/men_z135_uart.c | 26 ++-- drivers/tty/serial/meson_uart.c | 11 +- drivers/tty/serial/milbeaut_usio.c | 15 +-- drivers/tty/serial/msm_serial.c | 114 +++++++++--------- drivers/tty/serial/mvebu-uart.c | 8 +- drivers/tty/serial/mxs-auart.c | 23 +--- drivers/tty/serial/pch_uart.c | 21 ++-- drivers/tty/serial/pic32_uart.c | 15 ++- drivers/tty/serial/pmac_zilog.c | 24 ++-- drivers/tty/serial/qcom_geni_serial.c | 36 +++--- drivers/tty/serial/rda-uart.c | 17 +-- drivers/tty/serial/samsung_tty.c | 54 +++++---- drivers/tty/serial/sb1250-duart.c | 13 +- drivers/tty/serial/sc16is7xx.c | 40 +++---- drivers/tty/serial/sccnxp.c | 16 ++- drivers/tty/serial/serial-tegra.c | 43 ++++--- drivers/tty/serial/serial_core.c | 56 ++++----- drivers/tty/serial/serial_port.c | 2 +- drivers/tty/serial/sh-sci.c | 51 ++++---- drivers/tty/serial/sprd_serial.c | 20 ++-- drivers/tty/serial/st-asc.c | 4 +- drivers/tty/serial/stm32-usart.c | 52 ++++---- drivers/tty/serial/sunhv.c | 35 +++--- drivers/tty/serial/sunplus-uart.c | 16 +-- drivers/tty/serial/sunsab.c | 30 ++--- drivers/tty/serial/sunsu.c | 15 +-- drivers/tty/serial/sunzilog.c | 27 ++--- drivers/tty/serial/tegra-tcu.c | 10 +- drivers/tty/serial/timbuart.c | 17 ++- drivers/tty/serial/uartlite.c | 13 +- drivers/tty/serial/ucc_uart.c | 20 ++-- drivers/tty/serial/xilinx_uartps.c | 20 ++-- drivers/tty/serial/zs.c | 13 +- include/linux/kfifo.h | 143 ++++++++++++++++------ include/linux/serial_core.h | 49 +++++--- lib/kfifo.c | 107 +++++++++-------- 61 files changed, 944 insertions(+), 960 deletions(-)
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 1/15 kfifo: drop __kfifo_dma_out_finish_r()
It is the same as __kfifo_skip_r(), so:
* drop __kfifo_dma_out_finish_r() completely, and
* replace its (only) use by __kfifo_skip_r().
--- include/linux/kfifo.h | 4 +--- lib/kfifo.c | 8 -------- 2 files changed, 1 insertion(+), 11 deletions(-)
include/linux/kfifo.h +1 -3
@@ -797,7 +797,7 @@ __kfifo_int_must_check_helper( \const size_t __recsize =sizeof (*__tmp->rectype); \struct __kfifo *__kfifo = &__tmp->kfifo; \if (__recsize) \ -__kfifo_dma_out_finish_r (__kfifo, __recsize); \ +__kfifo_skip_r (__kfifo, __recsize); \else \ __kfifo->out += __len /sizeof (*__tmp->type); \ })
@@ -879,8 +879,6 @@ extern void __kfifo_dma_in_finish_r(struct __kfifo *fifo,extern unsigned int __kfifo_dma_out_prepare_r (struct __kfifo *fifo,struct scatterlist *sgl,int nents,unsigned int len,size_t recsize); -extern void __kfifo_dma_out_finish_r (struct __kfifo *fifo,size_t recsize); -extern unsigned int __kfifo_len_r (struct __kfifo *fifo,size_t recsize);extern void __kfifo_skip_r (struct __kfifo *fifo,size_t recsize);
lib/kfifo.c +0 -8
@@ -582,11 +582,3 @@ unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo, }EXPORT_SYMBOL (__kfifo_dma_out_prepare_r); -void __kfifo_dma_out_finish_r (struct __kfifo *fifo,size_t recsize) -{ -unsigned int len; - - len =__kfifo_peek_n (fifo, recsize); - fifo->out += len + recsize; -} -EXPORT_SYMBOL (__kfifo_dma_out_finish_r);
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 2/15 kfifo: introduce and use kfifo_skip_count()
In reply to Jiri Slaby (SUSE)kfifo_skip_count() is an extended version of kfifo_skip(), accepting also count. This will be useful in the serial code later.
Now, it can be used to implement both kfifo_skip() and kfifo_dma_out_finish(). In the latter, 'len' only needs to be divided by 'type' size (as it was until now).
And stop using statement expressions when the return value is cast to 'void'. Use classic 'do {} while (0)' instead.
Note: perhaps we should skip 'count' records for the 'recsize' case, but the original (kfifo_dma_out_finish()) used to skip only one record. So this is kept unchanged and 'count' is still ignored in the recsize case.
---
Notes:
[v2] rename __tmp to ___tmp to fix initialization in the nested macro
include/linux/kfifo.h | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-)
include/linux/kfifo.h +15 -16
@@ -304,19 +304,25 @@ __kfifo_uint_must_check_helper( \ )/** -* kfifo_skip - skip output data +* kfifo_skip_count - skip output data * @fifo: address of the fifo to be used +* @count: count of data to skip */ -#define kfifo_skip (fifo) \ -(void)({ \ +#define kfifo_skip_count (fifo, count) do { \ typeof((fifo) + 1) __tmp = (fifo); \ const size_t __recsize = sizeof(*__tmp->rectype); \ struct __kfifo *__kfifo = &__tmp->kfifo; \ if (__recsize) \ __kfifo_skip_r(__kfifo, __recsize); \ else \ - __kfifo->out++; \ -}) + __kfifo->out += (count); \ +} while(0) + +/** +* kfifo_skip - skip output data +* @fifo: address of the fifo to be used +*/ +#define kfifo_skip (fifo) kfifo_skip_count(fifo, 1)/** * kfifo_peek_len - gets the size of the next fifo record
@@ -790,17 +796,10 @@ __kfifo_int_must_check_helper( \* Note that with only one concurrent reader and one concurrent * writer, you don't need extra locking to use these macros. */ -#define kfifo_dma_out_finish (fifo, len) \ -(void)({ \ - typeof((fifo) + 1) __tmp = (fifo); \ - unsigned int __len = (len); \ - const size_t __recsize = sizeof(*__tmp->rectype); \ - struct __kfifo *__kfifo = &__tmp->kfifo; \ - if (__recsize) \ - __kfifo_skip_r(__kfifo, __recsize); \ - else \ - __kfifo->out += __len / sizeof(*__tmp->type); \ -}) +#define kfifo_dma_out_finish (fifo, len) do { \ + typeof((fifo) + 1) ___tmp = (fifo); \ + kfifo_skip_count(___tmp, (len) / sizeof(*___tmp->type)); \ +} while (0)/** * kfifo_out_peek - gets some data from the fifo
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 3/15 kfifo: add kfifo_out_linear{,_ptr}()
In reply to Jiri Slaby (SUSE)These are helpers which are going to be used in the serial layer. We need a wrapper around kfifo which provides us with a tail (sometimes "tail" offset, sometimes a pointer) to the kfifo data. And which returns count of available data -- but not larger than to the end of the buffer (hence _linear in the names). I.e. something like CIRC_CNT_TO_END() in the legacy circ_buf.
This patch adds such two helpers.
---
Notes:
[v2]
* added Andrew's fix -- missing right parenthesis
* simplify __kfifo_out_linear() -- min3() results can be returned directly.
include/linux/kfifo.h | 63 +++++++++++++++++++++++++++++++++++++++++++ lib/kfifo.c | 26 ++++++++++++++++++ 2 files changed, 89 insertions(+)
include/linux/kfifo.h +63 -0
@@ -827,6 +827,63 @@ __kfifo_uint_must_check_helper( \ }) \ ) +/** +* kfifo_out_linear - gets a tail of/offset to available data +* @fifo: address of the fifo to be used +* @tail: pointer to an unsigned int to store the value of tail +* @n: max. number of elements to point at +* +* This macro obtains the offset (tail) to the available data in the fifo +* buffer and returns the +* numbers of elements available. It returns the available count till the end +* of data or till the end of the buffer. So that it can be used for linear +* data processing (like memcpy() of (@fifo->data + @tail) with count +* returned). +* +* Note that with only one concurrent reader and one concurrent +* writer, you don't need extra locking to use these macro. +*/ +#define kfifo_out_linear (fifo, tail, n) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + unsigned int *__tail = (tail); \ + unsigned long __n = (n); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + (__recsize) ? \ + __kfifo_out_linear_r(__kfifo, __tail, __n, __recsize) : \ + __kfifo_out_linear(__kfifo, __tail, __n); \ +}) \ +) + +/** +* kfifo_out_linear_ptr - gets a pointer to the available data +* @fifo: address of the fifo to be used +* @ptr: pointer to data to store the pointer to tail +* @n: max. number of elements to point at +* +* Similarly to kfifo_out_linear(), this macro obtains the pointer to the +* available data in the fifo buffer and returns the numbers of elements +* available. It returns the available count till the end of available data or +* till the end of the buffer. So that it can be used for linear data +* processing (like memcpy() of @ptr with count returned). +* +* Note that with only one concurrent reader and one concurrent +* writer, you don't need extra locking to use these macro. +*/ +#define kfifo_out_linear_ptr (fifo, ptr, n) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) ___tmp = (fifo); \ + unsigned int ___tail; \ + unsigned int ___n = kfifo_out_linear(___tmp, &___tail, (n)); \ + *(ptr) = ___tmp->kfifo.data + ___tail * kfifo_esize(___tmp); \ + ___n; \ +}) \ +) + +extern int __kfifo_alloc (struct __kfifo *fifo,unsigned int size,size_t esize,gfp_t gfp_mask);
@@ -856,6 +913,9 @@ extern unsigned int __kfifo_dma_out_prepare(struct __kfifo *fifo,extern unsigned int __kfifo_out_peek (struct __kfifo *fifo,void *buf,unsigned int len); +extern unsigned int __kfifo_out_linear (struct __kfifo *fifo, +unsigned int *tail,unsigned int n); +extern unsigned int __kfifo_in_r (struct __kfifo *fifo,const void *buf,unsigned int len,size_t recsize);
@@ -885,6 +945,9 @@ extern void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize);extern unsigned int __kfifo_out_peek_r (struct __kfifo *fifo,void *buf,unsigned int len,size_t recsize); +extern unsigned int __kfifo_out_linear_r (struct __kfifo *fifo, +unsigned int *tail,unsigned int n,size_t recsize); +extern unsigned int __kfifo_max_r (unsigned int len,size_t recsize);#endif
lib/kfifo.c +26 -0
@@ -163,6 +163,19 @@ unsigned int __kfifo_out_peek(struct __kfifo *fifo, }EXPORT_SYMBOL (__kfifo_out_peek); +unsigned int __kfifo_out_linear (struct __kfifo *fifo, +unsigned int *tail,unsigned int n) +{ +unsigned int size = fifo->mask +1 ; +unsigned int off = fifo->out & fifo->mask; + +if (tail) + *tail = off; + +return min3 (n, fifo->in - fifo->out, size - off); +} +EXPORT_SYMBOL (__kfifo_out_linear); +unsigned int __kfifo_out (struct __kfifo *fifo,void *buf,unsigned int len) {
@@ -473,6 +486,19 @@ unsigned int __kfifo_out_peek_r(struct __kfifo *fifo, void *buf, }EXPORT_SYMBOL (__kfifo_out_peek_r); +unsigned int __kfifo_out_linear_r (struct __kfifo *fifo, +unsigned int *tail,unsigned int n,size_t recsize) +{ +if (fifo->in == fifo->out) +return 0 ; + +if (tail) + *tail = fifo->out + recsize; + +return min (n,__kfifo_peek_n (fifo, recsize)); +} +EXPORT_SYMBOL (__kfifo_out_linear_r); +unsigned int __kfifo_out_r (struct __kfifo *fifo,void *buf,unsigned int len,size_t recsize) {
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 4/4 kfifo: fix typos in kernel-doc
In reply to Jiri Slaby (SUSE)Obviously:
"This macro finish" -> "This macro finishes"
and similar.
--- include/linux/kfifo.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
include/linux/kfifo.h +5 -5
@@ -584,7 +584,7 @@ __kfifo_uint_must_check_helper( \* @buf: pointer to the storage buffer * @n: max. number of elements to get * -* This macro get some data from the fifo and return the numbers of elements +* This macro gets some data from the fifo and returns the numbers of elements * copied. * * Note that with only one concurrent reader and one concurrent
@@ -611,7 +611,7 @@ __kfifo_uint_must_check_helper( \* @n: max. number of elements to get * @lock: pointer to the spinlock to use for locking * -* This macro get the data from the fifo and return the numbers of elements +* This macro gets the data from the fifo and returns the numbers of elements * copied. */ #define kfifo_out_spinlocked (fifo, buf, n, lock) \
@@ -739,7 +739,7 @@ __kfifo_int_must_check_helper( \* @fifo: address of the fifo to be used * @len: number of bytes to received * -* This macro finish a DMA IN operation. The in counter will be updated by +* This macro finishes a DMA IN operation. The in counter will be updated by * the len parameter. No error checking will be done. * * Note that with only one concurrent reader and one concurrent
@@ -790,7 +790,7 @@ __kfifo_int_must_check_helper( \* @fifo: address of the fifo to be used * @len: number of bytes transferred * -* This macro finish a DMA OUT operation. The out counter will be updated by +* This macro finishes a DMA OUT operation. The out counter will be updated by * the len parameter. No error checking will be done. * * Note that with only one concurrent reader and one concurrent
@@ -807,7 +807,7 @@ __kfifo_int_must_check_helper( \* @buf: pointer to the storage buffer * @n: max. number of elements to get * -* This macro get the data from the fifo and return the numbers of elements +* This macro gets the data from the fifo and returns the numbers of elements * copied. The data is not removed from the fifo. * * Note that with only one concurrent reader and one concurrent
Signature · 1 line
2.43.2
Jiri Slaby
maintainerRe: [PATCH 4/4] kfifo: fix typos in kernel-doc
Ignore this one, this is some old patch present in the output directory.
Quoted 60 lines · Jiri Slaby (SUSE)
Obviously:
"This macro finish" -> "This macro finishes"
and similar.Signed-off-by Jiri Slaby (SUSE) <[email protected]>Cc Stefani Seibold <[email protected]>Cc Andrew Morton <[email protected]>--- include/linux/kfifo.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)include/linux/kfifo.h +5
-5@@ -584,7 +584,7 @@ __kfifo_uint_must_check_helper( \* @buf: pointer to the storage buffer * @n: max. number of elements to get * -* This macro get some data from the fifo and return the numbers of elements +* This macro gets some data from the fifo and returns the numbers of elements * copied. * * Note that with only one concurrent reader and one concurrent @@ -611,7 +611,7 @@ __kfifo_uint_must_check_helper( \* @n: max. number of elements to get * @lock: pointer to the spinlock to use for locking * -* This macro get the data from the fifo and return the numbers of elements +* This macro gets the data from the fifo and returns the numbers of elements * copied. */ #define kfifo_out_spinlocked (fifo, buf, n, lock) \@@ -739,7 +739,7 @@ __kfifo_int_must_check_helper( \* @fifo: address of the fifo to be used * @len: number of bytes to received * -* This macro finish a DMA IN operation. The in counter will be updated by +* This macro finishes a DMA IN operation. The in counter will be updated by * the len parameter. No error checking will be done. * * Note that with only one concurrent reader and one concurrent @@ -790,7 +790,7 @@ __kfifo_int_must_check_helper( \* @fifo: address of the fifo to be used * @len: number of bytes transferred * -* This macro finish a DMA OUT operation. The out counter will be updated by +* This macro finishes a DMA OUT operation. The out counter will be updated by * the len parameter. No error checking will be done. * * Note that with only one concurrent reader and one concurrent @@ -807,7 +807,7 @@ __kfifo_int_must_check_helper( \* @buf: pointer to the storage buffer * @n: max. number of elements to get * -* This macro get the data from the fifo and return the numbers of elements +* This macro gets the data from the fifo and returns the numbers of elements * copied. The data is not removed from the fifo. * * Note that with only one concurrent reader and one concurrent
Signature · 2 lines
js suse labs
Jiri Slaby (SUSE)
maintainerPATCH 4/15 kfifo: remove support for physically non-contiguous memory
In reply to Jiri Slaby (SUSE)First, there is no such user. The only user of this interface is caam_rng_fill_async() and that uses kfifo_alloc() -> kmalloc().
Second, the implementation does not allow anything else than direct mapping and kmalloc() (due to virt_to_phys()), anyway.
Therefore, there is no point in having this dead (and complex) code in the kernel.
Note the setup_sgl_buf() function now boils down to simple sg_set_buf(). That is called twice from setup_sgl() to take care of kfifo buffer wrap-around.
setup_sgl_buf() will be extended shortly, so keeping it in place.
--- lib/kfifo.c | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-)
lib/kfifo.c +5 -33
@@ -305,43 +305,15 @@ int __kfifo_to_user(struct __kfifo *fifo, void __user *to, }EXPORT_SYMBOL (__kfifo_to_user); -static int setup_sgl_buf (struct scatterlist *sgl,void *buf, -int nents,unsigned int len) +static unsigned int setup_sgl_buf (struct scatterlist *sgl,void *buf, +int nents,unsigned int len) { -int n; -unsigned int l; -unsigned int off; -struct page *page; - -if (!nents) +if (!nents || !len)return 0 ; -if (!len) -return 0 ; +sg_set_buf (sgl, buf, len); - n =0 ; - page =virt_to_page (buf); - off =offset_in_page (buf); - l =0 ; - -while (len >= l +PAGE_SIZE - off) { -struct page *npage; - - l +=PAGE_SIZE ; - buf +=PAGE_SIZE ; - npage =virt_to_page (buf); -if (page_to_phys (page) !=page_to_phys (npage) - l) { -sg_set_page (sgl, page, l - off, off); - sgl =sg_next (sgl); -if (++n == nents || sgl ==NULL ) -return n; - page = npage; - len -= l - off; - l = off =0 ; - } - } -sg_set_page (sgl, page, len, off); -return n +1 ; +return 1 ; } static unsigned int setup_sgl(struct __kfifo *fifo, struct scatterlist *sgl,
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 5/15 kfifo: rename l to len_to_end in setup_sgl()
In reply to Jiri Slaby (SUSE)So that one can make any sense of the name.
--- lib/kfifo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/kfifo.c +4 -4
@@ -321,7 +321,7 @@ static unsigned int setup_sgl(struct __kfifo *fifo, struct scatterlist *sgl, {unsigned int size = fifo->mask +1 ;unsigned int esize = fifo->esize; -unsigned int l; +unsigned int len_to_end;unsigned int n; off &= fifo->mask;
@@ -330,10 +330,10 @@ static unsigned int setup_sgl(struct __kfifo *fifo, struct scatterlist *sgl, size *= esize; len *= esize; } - l =min (len, size - off); + len_to_end =min (len, size - off); - n =setup_sgl_buf (sgl, fifo->data + off, nents, l); - n +=setup_sgl_buf (sgl + n, fifo->data, nents - n, len - l); + n =setup_sgl_buf (sgl, fifo->data + off, nents, len_to_end); + n +=setup_sgl_buf (sgl + n, fifo->data, nents - n, len - len_to_end);return n; }
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 6/15 kfifo: pass offset to setup_sgl_buf() instead of a pointer
In reply to Jiri Slaby (SUSE)As a preparatory for dma addresses filling, we need the data offset instead of virtual pointer in setup_sgl_buf(). So pass the former instead the latter.
And pointer to fifo is needed in setup_sgl_buf() now too.
--- lib/kfifo.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
lib/kfifo.c +7 -4
@@ -305,9 +305,12 @@ int __kfifo_to_user(struct __kfifo *fifo, void __user *to, }EXPORT_SYMBOL (__kfifo_to_user); -static unsigned int setup_sgl_buf (struct scatterlist *sgl,void *buf, -int nents,unsigned int len) +static unsigned int setup_sgl_buf (struct __kfifo *fifo,struct scatterlist *sgl, +unsigned int data_offset,int nents, +unsigned int len) { +const void *buf = fifo->data + data_offset; +if (!nents || !len)return 0 ;
@@ -332,8 +335,8 @@ static unsigned int setup_sgl(struct __kfifo *fifo, struct scatterlist *sgl, } len_to_end =min (len, size - off); - n =setup_sgl_buf (sgl, fifo->data + off, nents, len_to_end); - n +=setup_sgl_buf (sgl + n, fifo->data, nents - n, len - len_to_end); + n =setup_sgl_buf (fifo, sgl, off, nents, len_to_end); + n +=setup_sgl_buf (fifo, sgl + n,0 , nents - n, len - len_to_end);return n; }
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 7/15 kfifo: add kfifo_dma_out_prepare_mapped()
In reply to Jiri Slaby (SUSE)When the kfifo buffer is already dma-mapped, one cannot use the kfifo API to fill in an SG list.
Add kfifo_dma_in_prepare_mapped() which allows exactly this. A mapped dma_addr_t is passed and it is filled into provided sgl too. Including the dma_len.
--- include/linux/kfifo.h | 37 +++++++++++++++++++++++++------------ lib/kfifo.c | 34 ++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 24 deletions(-)
include/linux/kfifo.h +25 -12
@@ -36,6 +36,7 @@* to lock the reader. */ +#include <linux/dma-mapping.h> #include <linux/kernel.h> #include <linux/spinlock.h> #include <linux/stddef.h>
@@ -709,11 +710,12 @@ __kfifo_int_must_check_helper( \ )/** -* kfifo_dma_in_prepare - setup a scatterlist for DMA input +* kfifo_dma_in_prepare_mapped - setup a scatterlist for DMA input * @fifo: address of the fifo to be used * @sgl: pointer to the scatterlist array * @nents: number of entries in the scatterlist array * @len: number of elements to transfer +* @dma: mapped dma address to fill into @sgl * * This macro fills a scatterlist for DMA input. * It returns the number entries in the scatterlist array.
@@ -721,7 +723,7 @@ __kfifo_int_must_check_helper( \* Note that with only one concurrent reader and one concurrent * writer, you don't need extra locking to use these macros. */ -#define kfifo_dma_in_prepare (fifo, sgl, nents, len) \ +#define kfifo_dma_in_prepare_mapped (fifo, sgl, nents, len, dma) \ ({ \ typeof((fifo) + 1) __tmp = (fifo); \ struct scatterlist *__sgl = (sgl); \
@@ -730,10 +732,14 @@ __kfifo_int_must_check_helper( \const size_t __recsize =sizeof (*__tmp->rectype); \struct __kfifo *__kfifo = &__tmp->kfifo; \ (__recsize) ? \ -__kfifo_dma_in_prepare_r (__kfifo, __sgl, __nents, __len, __recsize) : \ -__kfifo_dma_in_prepare (__kfifo, __sgl, __nents, __len); \ +__kfifo_dma_in_prepare_r (__kfifo, __sgl, __nents, __len, __recsize, \ + dma) : \ +__kfifo_dma_in_prepare (__kfifo, __sgl, __nents, __len, dma); \ }) +#define kfifo_dma_in_prepare (fifo, sgl, nents, len) \ + kfifo_dma_in_prepare_mapped(fifo, sgl, nents, len, DMA_MAPPING_ERROR) +/** * kfifo_dma_in_finish - finish a DMA IN operation * @fifo: address of the fifo to be used
@@ -758,11 +764,12 @@ __kfifo_int_must_check_helper( \ })/** -* kfifo_dma_out_prepare - setup a scatterlist for DMA output +* kfifo_dma_out_prepare_mapped - setup a scatterlist for DMA output * @fifo: address of the fifo to be used * @sgl: pointer to the scatterlist array * @nents: number of entries in the scatterlist array * @len: number of elements to transfer +* @dma: mapped dma address to fill into @sgl * * This macro fills a scatterlist for DMA output which at most @len bytes * to transfer.
@@ -772,7 +779,7 @@ __kfifo_int_must_check_helper( \* Note that with only one concurrent reader and one concurrent * writer, you don't need extra locking to use these macros. */ -#define kfifo_dma_out_prepare (fifo, sgl, nents, len) \ +#define kfifo_dma_out_prepare_mapped (fifo, sgl, nents, len, dma) \ ({ \ typeof((fifo) + 1) __tmp = (fifo); \ struct scatterlist *__sgl = (sgl); \
@@ -781,10 +788,14 @@ __kfifo_int_must_check_helper( \const size_t __recsize =sizeof (*__tmp->rectype); \struct __kfifo *__kfifo = &__tmp->kfifo; \ (__recsize) ? \ -__kfifo_dma_out_prepare_r (__kfifo, __sgl, __nents, __len, __recsize) : \ -__kfifo_dma_out_prepare (__kfifo, __sgl, __nents, __len); \ +__kfifo_dma_out_prepare_r (__kfifo, __sgl, __nents, __len, __recsize, \ + dma) : \ +__kfifo_dma_out_prepare (__kfifo, __sgl, __nents, __len, dma); \ }) +#define kfifo_dma_out_prepare (fifo, sgl, nents, len) \ + kfifo_dma_out_prepare_mapped(fifo, sgl, nents, len, DMA_MAPPING_ERROR) +/** * kfifo_dma_out_finish - finish a DMA OUT operation * @fifo: address of the fifo to be used
@@ -905,10 +916,10 @@ extern int __kfifo_to_user(struct __kfifo *fifo, void __user *to, unsigned long len, unsigned int *copied);extern unsigned int __kfifo_dma_in_prepare (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len); +struct scatterlist *sgl,int nents,unsigned int len,dma_addr_t dma);extern unsigned int __kfifo_dma_out_prepare (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len); +struct scatterlist *sgl,int nents,unsigned int len,dma_addr_t dma);extern unsigned int __kfifo_out_peek (struct __kfifo *fifo,void *buf,unsigned int len);
@@ -930,13 +941,15 @@ extern int __kfifo_to_user_r(struct __kfifo *fifo, void __user *to, unsigned long len, unsigned int *copied, size_t recsize);extern unsigned int __kfifo_dma_in_prepare_r (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len,size_t recsize); +struct scatterlist *sgl,int nents,unsigned int len,size_t recsize, +dma_addr_t dma);extern void __kfifo_dma_in_finish_r (struct __kfifo *fifo,unsigned int len,size_t recsize);extern unsigned int __kfifo_dma_out_prepare_r (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len,size_t recsize); +struct scatterlist *sgl,int nents,unsigned int len,size_t recsize, +dma_addr_t dma);extern unsigned int __kfifo_len_r (struct __kfifo *fifo,size_t recsize);
lib/kfifo.c +22 -12
@@ -6,6 +6,7 @@*/ #include <linux/kernel.h> +#include <linux/dma-mapping.h> #include <linux/export.h> #include <linux/slab.h> #include <linux/err.h>
@@ -307,7 +308,7 @@ EXPORT_SYMBOL(__kfifo_to_user);static unsigned int setup_sgl_buf (struct __kfifo *fifo,struct scatterlist *sgl,unsigned int data_offset,int nents, -unsigned int len) +unsigned int len,dma_addr_t dma) {const void *buf = fifo->data + data_offset;
@@ -316,11 +317,16 @@ static unsigned int setup_sgl_buf(struct __kfifo *fifo, struct scatterlist *sgl,sg_set_buf (sgl, buf, len); +if (dma !=DMA_MAPPING_ERROR ) { +sg_dma_address (sgl) = dma + data_offset; +sg_dma_len (sgl) = len; + } +return 1 ; }static unsigned int setup_sgl (struct __kfifo *fifo,struct scatterlist *sgl, -int nents,unsigned int len,unsigned int off) +int nents,unsigned int len,unsigned int off,dma_addr_t dma) {unsigned int size = fifo->mask +1 ;unsigned int esize = fifo->esize;
@@ -335,14 +341,15 @@ static unsigned int setup_sgl(struct __kfifo *fifo, struct scatterlist *sgl, } len_to_end =min (len, size - off); - n =setup_sgl_buf (fifo, sgl, off, nents, len_to_end); - n +=setup_sgl_buf (fifo, sgl + n,0 , nents - n, len - len_to_end); + n =setup_sgl_buf (fifo, sgl, off, nents, len_to_end, dma); + n +=setup_sgl_buf (fifo, sgl + n,0 , nents - n, len - len_to_end, dma);return n; }unsigned int __kfifo_dma_in_prepare (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len) +struct scatterlist *sgl,int nents,unsigned int len, +dma_addr_t dma) {unsigned int l;
@@ -350,12 +357,13 @@ unsigned int __kfifo_dma_in_prepare(struct __kfifo *fifo,if (len > l) len = l; -return setup_sgl (fifo, sgl, nents, len, fifo->in); +return setup_sgl (fifo, sgl, nents, len, fifo->in, dma); }EXPORT_SYMBOL (__kfifo_dma_in_prepare);unsigned int __kfifo_dma_out_prepare (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len) +struct scatterlist *sgl,int nents,unsigned int len, +dma_addr_t dma) {unsigned int l;
@@ -363,7 +371,7 @@ unsigned int __kfifo_dma_out_prepare(struct __kfifo *fifo,if (len > l) len = l; -return setup_sgl (fifo, sgl, nents, len, fifo->out); +return setup_sgl (fifo, sgl, nents, len, fifo->out, dma); }EXPORT_SYMBOL (__kfifo_dma_out_prepare);
@@ -547,7 +555,8 @@ int __kfifo_to_user_r(struct __kfifo *fifo, void __user *to,EXPORT_SYMBOL (__kfifo_to_user_r);unsigned int __kfifo_dma_in_prepare_r (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len,size_t recsize) +struct scatterlist *sgl,int nents,unsigned int len,size_t recsize, +dma_addr_t dma) {BUG_ON (!nents);
@@ -556,7 +565,7 @@ unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo,if (len + recsize >kfifo_unused (fifo))return 0 ; -return setup_sgl (fifo, sgl, nents, len, fifo->in + recsize); +return setup_sgl (fifo, sgl, nents, len, fifo->in + recsize, dma); }EXPORT_SYMBOL (__kfifo_dma_in_prepare_r);
@@ -570,7 +579,8 @@ void __kfifo_dma_in_finish_r(struct __kfifo *fifo,EXPORT_SYMBOL (__kfifo_dma_in_finish_r);unsigned int __kfifo_dma_out_prepare_r (struct __kfifo *fifo, -struct scatterlist *sgl,int nents,unsigned int len,size_t recsize) +struct scatterlist *sgl,int nents,unsigned int len,size_t recsize, +dma_addr_t dma) {BUG_ON (!nents);
@@ -579,7 +589,7 @@ unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo,if (len + recsize > fifo->in - fifo->out)return 0 ; -return setup_sgl (fifo, sgl, nents, len, fifo->out + recsize); +return setup_sgl (fifo, sgl, nents, len, fifo->out + recsize, dma); }EXPORT_SYMBOL (__kfifo_dma_out_prepare_r);
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 8/15 kfifo: fix typos in kernel-doc
In reply to Jiri Slaby (SUSE)Obviously:
"This macro finish" -> "This macro finishes"
and similar.
--- include/linux/kfifo.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
include/linux/kfifo.h +5 -5
@@ -585,7 +585,7 @@ __kfifo_uint_must_check_helper( \* @buf: pointer to the storage buffer * @n: max. number of elements to get * -* This macro get some data from the fifo and return the numbers of elements +* This macro gets some data from the fifo and returns the numbers of elements * copied. * * Note that with only one concurrent reader and one concurrent
@@ -612,7 +612,7 @@ __kfifo_uint_must_check_helper( \* @n: max. number of elements to get * @lock: pointer to the spinlock to use for locking * -* This macro get the data from the fifo and return the numbers of elements +* This macro gets the data from the fifo and returns the numbers of elements * copied. */ #define kfifo_out_spinlocked (fifo, buf, n, lock) \
@@ -745,7 +745,7 @@ __kfifo_int_must_check_helper( \* @fifo: address of the fifo to be used * @len: number of bytes to received * -* This macro finish a DMA IN operation. The in counter will be updated by +* This macro finishes a DMA IN operation. The in counter will be updated by * the len parameter. No error checking will be done. * * Note that with only one concurrent reader and one concurrent
@@ -801,7 +801,7 @@ __kfifo_int_must_check_helper( \* @fifo: address of the fifo to be used * @len: number of bytes transferred * -* This macro finish a DMA OUT operation. The out counter will be updated by +* This macro finishes a DMA OUT operation. The out counter will be updated by * the len parameter. No error checking will be done. * * Note that with only one concurrent reader and one concurrent
@@ -818,7 +818,7 @@ __kfifo_int_must_check_helper( \* @buf: pointer to the storage buffer * @n: max. number of elements to get * -* This macro get the data from the fifo and return the numbers of elements +* This macro gets the data from the fifo and returns the numbers of elements * copied. The data is not removed from the fifo. * * Note that with only one concurrent reader and one concurrent
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 9/15 tty: 8250_dma: use dmaengine_prep_slave_sg()
In reply to Jiri Slaby (SUSE)This is a preparatory for the serial-to-kfifo switch. kfifo understands only scatter-gatter approach, so switch to that.
No functional change intended, it's just dmaengine_prep_slave_single() inline expanded.
--- drivers/tty/serial/8250/8250_dma.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/tty/serial/8250/8250_dma.c +8 -4
@@ -89,6 +89,7 @@ int serial8250_tx_dma(struct uart_8250_port *p)struct circ_buf *xmit = &p->port.state->xmit;struct dma_async_tx_descriptor *desc;struct uart_port *up = &p->port; +struct scatterlist sg;int ret;if (dma->tx_running) {
@@ -111,10 +112,13 @@ int serial8250_tx_dma(struct uart_8250_port *p)serial8250_do_prepare_tx_dma (p); - desc =dmaengine_prep_slave_single (dma->txchan, - dma->tx_addr + xmit->tail, - dma->tx_size,DMA_MEM_TO_DEV , -DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); +sg_init_table (&sg,1 ); +sg_dma_address (&sg) = dma->tx_addr + xmit->tail; +sg_dma_len (&sg) = dma->tx_size; + + desc =dmaengine_prep_slave_sg (dma->txchan, &sg,1 , +DMA_MEM_TO_DEV , +DMA_PREP_INTERRUPT |DMA_CTRL_ACK );if (!desc) { ret = -EBUSY ; goto err;
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 10/15 tty: 8250_omap: use dmaengine_prep_slave_sg()
In reply to Jiri Slaby (SUSE)This is a preparatory for the serial-to-kfifo switch. kfifo understands only scatter-gatter approach, so switch to that.
No functional change intended, it's just dmaengine_prep_slave_single() inline expanded.
--- drivers/tty/serial/8250/8250_omap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_omap.c +6 -3
@@ -1140,6 +1140,7 @@ static int omap_8250_tx_dma(struct uart_8250_port *p)struct omap8250_priv *priv = p->port.private_data;struct circ_buf *xmit = &p->port.state->xmit;struct dma_async_tx_descriptor *desc; +struct scatterlist sg;unsigned int skip_byte =0 ;int ret;
@@ -1191,9 +1192,11 @@ static int omap_8250_tx_dma(struct uart_8250_port *p) skip_byte =1 ; } - desc =dmaengine_prep_slave_single (dma->txchan, - dma->tx_addr + xmit->tail + skip_byte, - dma->tx_size - skip_byte,DMA_MEM_TO_DEV , +sg_init_table (&sg,1 ); +sg_dma_address (&sg) = dma->tx_addr + xmit->tail + skip_byte; +sg_dma_len (&sg) = dma->tx_size - skip_byte; + + desc =dmaengine_prep_slave_sg (dma->txchan, &sg,1 ,DMA_MEM_TO_DEV ,DMA_PREP_INTERRUPT |DMA_CTRL_ACK );if (!desc) { ret = -EBUSY ;
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 11/15 tty: msm_serial: use dmaengine_prep_slave_sg()
In reply to Jiri Slaby (SUSE)This is a preparatory for the serial-to-kfifo switch. kfifo understands only scatter-gatter approach, so switch to that.
No functional change intended, it's just dmaengine_prep_slave_single() inline expanded.
And in this case, switch from dma_map_single() to dma_map_sg() too. This needs struct msm_dma changes. I split the rx and tx parts into an union. TX is now struct scatterlist, RX remains the old good phys-virt-count triple.
--- drivers/tty/serial/msm_serial.c | 86 +++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 37 deletions(-)
drivers/tty/serial/msm_serial.c +49 -37
@@ -161,11 +161,16 @@ enum {struct msm_dma {struct dma_chan *chan;enum dma_data_direction dir; -dma_addr_t phys; -unsigned char *virt; +union { +struct { +dma_addr_t phys; +unsigned char *virt; +unsigned int count; + } rx; +struct scatterlist tx_sg; + };dma_cookie_t cookie;u32 enable_bit; -unsigned int count;struct dma_async_tx_descriptor *desc; };
@@ -249,8 +254,12 @@ static void msm_stop_dma(struct uart_port *port, struct msm_dma *dma)unsigned int mapped;u32 val; - mapped = dma->count; - dma->count =0 ; +if (dma->dir ==DMA_TO_DEVICE ) { + mapped =sg_dma_len (&dma->tx_sg); + }else { + mapped = dma->rx.count; + dma->rx.count =0 ; + }dmaengine_terminate_all (dma->chan);
@@ -265,8 +274,13 @@ static void msm_stop_dma(struct uart_port *port, struct msm_dma *dma) val &= ~dma->enable_bit;msm_write (port, val,UARTDM_DMEN ); -if (mapped) -dma_unmap_single (dev, dma->phys, mapped, dma->dir); +if (mapped) { +if (dma->dir ==DMA_TO_DEVICE ) { +dma_unmap_sg (dev, &dma->tx_sg,1 , dma->dir); +sg_init_table (&dma->tx_sg,1 ); + }else +dma_unmap_single (dev, dma->rx.phys, mapped, dma->dir); + } }static void msm_release_dma (struct msm_port *msm_port)
@@ -285,7 +299,7 @@ static void msm_release_dma(struct msm_port *msm_port)if (dma->chan) {msm_stop_dma (&msm_port->uart, dma);dma_release_channel (dma->chan); -kfree (dma->virt); +kfree (dma->rx.virt); }memset (dma,0 ,sizeof (*dma));
@@ -357,8 +371,8 @@ static void msm_request_rx_dma(struct msm_port *msm_port, resource_size_t base)of_property_read_u32 (dev->of_node,"qcom,rx-crci" , &crci); - dma->virt =kzalloc (UARTDM_RX_SIZE ,GFP_KERNEL ); -if (!dma->virt) + dma->rx.virt =kzalloc (UARTDM_RX_SIZE ,GFP_KERNEL ); +if (!dma->rx.virt) goto rel_rx;memset (&conf,0 ,sizeof (conf));
@@ -385,7 +399,7 @@ static void msm_request_rx_dma(struct msm_port *msm_port, resource_size_t base)return ; err: -kfree (dma->virt); +kfree (dma->rx.virt); rel_rx:dma_release_channel (dma->chan); no_rx:
@@ -420,7 +434,7 @@ static void msm_start_tx(struct uart_port *port)struct msm_dma *dma = &msm_port->tx_dma;/* Already started in DMA mode */ -if (dma->count) +if (sg_dma_len (&dma->tx_sg))return ; msm_port->imr |=MSM_UART_IMR_TXLEV ;
@@ -448,12 +462,12 @@ static void msm_complete_tx_dma(void *args)uart_port_lock_irqsave (port, &flags);/* Already stopped */ -if (!dma->count) +if (!sg_dma_len (&dma->tx_sg)) goto done;dmaengine_tx_status (dma->chan, dma->cookie, &state); -dma_unmap_single (port->dev, dma->phys, dma->count, dma->dir); +dma_unmap_sg (port->dev, &dma->tx_sg,1 , dma->dir); val =msm_read (port,UARTDM_DMEN ); val &= ~dma->enable_bit;
@@ -464,9 +478,9 @@ static void msm_complete_tx_dma(void *args)msm_write (port,MSM_UART_CR_TX_ENABLE ,MSM_UART_CR ); } - count = dma->count - state.residue; + count =sg_dma_len (&dma->tx_sg) - state.residue;uart_xmit_advance (port, count); - dma->count =0 ; +sg_init_table (&dma->tx_sg,1 );/* Restore "Tx FIFO below watermark" interrupt */ msm_port->imr |=MSM_UART_IMR_TXLEV ;
@@ -485,19 +499,18 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count)struct circ_buf *xmit = &msm_port->uart.state->xmit;struct uart_port *port = &msm_port->uart;struct msm_dma *dma = &msm_port->tx_dma; -void *cpu_addr;int ret;u32 val; - cpu_addr = &xmit->buf[xmit->tail]; +sg_init_table (&dma->tx_sg,1 ); +sg_set_buf (&dma->tx_sg, &xmit->buf[xmit->tail], count); - dma->phys =dma_map_single (port->dev, cpu_addr, count, dma->dir); - ret =dma_mapping_error (port->dev, dma->phys); + ret =dma_map_sg (port->dev, &dma->tx_sg,1 , dma->dir);if (ret)return ret; - dma->desc =dmaengine_prep_slave_single (dma->chan, dma->phys, - count,DMA_MEM_TO_DEV , + dma->desc =dmaengine_prep_slave_sg (dma->chan, &dma->tx_sg,1 , +DMA_MEM_TO_DEV ,DMA_PREP_INTERRUPT |DMA_PREP_FENCE );if (!dma->desc) {
@@ -520,8 +533,6 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count) msm_port->imr &= ~MSM_UART_IMR_TXLEV ;msm_write (port, msm_port->imr,MSM_UART_IMR ); - dma->count = count; - val =msm_read (port,UARTDM_DMEN ); val |= dma->enable_bit;
@@ -536,7 +547,8 @@ static int msm_handle_tx_dma(struct msm_port *msm_port, unsigned int count)dma_async_issue_pending (dma->chan);return 0 ; unmap: -dma_unmap_single (port->dev, dma->phys, count, dma->dir); +dma_unmap_sg (port->dev, &dma->tx_sg,1 , dma->dir); +sg_init_table (&dma->tx_sg,1 );return ret; }
@@ -553,7 +565,7 @@ static void msm_complete_rx_dma(void *args)uart_port_lock_irqsave (port, &flags);/* Already stopped */ -if (!dma->count) +if (!dma->rx.count) goto done; val =msm_read (port,UARTDM_DMEN );
@@ -570,14 +582,14 @@ static void msm_complete_rx_dma(void *args) port->icount.rx += count; - dma->count =0 ; + dma->rx.count =0 ; -dma_unmap_single (port->dev, dma->phys,UARTDM_RX_SIZE , dma->dir); +dma_unmap_single (port->dev, dma->rx.phys,UARTDM_RX_SIZE , dma->dir);for (i =0 ; i < count; i++) {char flag =TTY_NORMAL ; -if (msm_port->break_detected && dma->virt[i] ==0 ) { +if (msm_port->break_detected && dma->rx.virt[i] ==0 ) { port->icount.brk++; flag =TTY_BREAK ; msm_port->break_detected = false;
@@ -588,9 +600,9 @@ static void msm_complete_rx_dma(void *args)if (!(port->read_status_mask &MSM_UART_SR_RX_BREAK )) flag =TTY_NORMAL ; - sysrq =uart_prepare_sysrq_char (port, dma->virt[i]); + sysrq =uart_prepare_sysrq_char (port, dma->rx.virt[i]);if (!sysrq) -tty_insert_flip_char (tport, dma->virt[i], flag); +tty_insert_flip_char (tport, dma->rx.virt[i], flag); }msm_start_rx_dma (msm_port);
@@ -614,13 +626,13 @@ static void msm_start_rx_dma(struct msm_port *msm_port)if (!dma->chan)return ; - dma->phys =dma_map_single (uart->dev, dma->virt, + dma->rx.phys =dma_map_single (uart->dev, dma->rx.virt,UARTDM_RX_SIZE , dma->dir); - ret =dma_mapping_error (uart->dev, dma->phys); + ret =dma_mapping_error (uart->dev, dma->rx.phys);if (ret) goto sw_mode; - dma->desc =dmaengine_prep_slave_single (dma->chan, dma->phys, + dma->desc =dmaengine_prep_slave_single (dma->chan, dma->rx.phys,UARTDM_RX_SIZE ,DMA_DEV_TO_MEM ,DMA_PREP_INTERRUPT );if (!dma->desc)
@@ -648,7 +660,7 @@ static void msm_start_rx_dma(struct msm_port *msm_port)msm_write (uart, msm_port->imr,MSM_UART_IMR ); - dma->count =UARTDM_RX_SIZE ; + dma->rx.count =UARTDM_RX_SIZE ;dma_async_issue_pending (dma->chan);
@@ -668,7 +680,7 @@ static void msm_start_rx_dma(struct msm_port *msm_port)return ; unmap: -dma_unmap_single (uart->dev, dma->phys,UARTDM_RX_SIZE , dma->dir); +dma_unmap_single (uart->dev, dma->rx.phys,UARTDM_RX_SIZE , dma->dir); sw_mode:/*
@@ -955,7 +967,7 @@ static irqreturn_t msm_uart_irq(int irq, void *dev_id) }if (misr & (MSM_UART_IMR_RXLEV |MSM_UART_IMR_RXSTALE )) { -if (dma->count) { +if (dma->rx.count) { val =MSM_UART_CR_CMD_STALE_EVENT_DISABLE ;msm_write (port, val,MSM_UART_CR ); val =MSM_UART_CR_CMD_RESET_STALE_INT ;
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 12/15 tty: serial: switch from circ_buf to kfifo
In reply to Jiri Slaby (SUSE)Switch from struct circ_buf to proper kfifo. kfifo provides much better API, esp. when wrap-around of the buffer needs to be taken into account. Look at pl011_dma_tx_refill() or cpm_uart_tx_pump() changes for example.
Kfifo API can also fill in scatter-gather DMA structures, so it easier for that use case too. Look at lpuart_dma_tx() for example. Note that not all drivers can be converted to that (like atmel_serial), they handle DMA specially.
Note that usb-serial uses kfifo for TX for ages.
omap needed a bit more care as it needs to put a char into FIFO to start the DMA transfer when OMAP_DMA_TX_KICK is set. In that case, we have to do kfifo_dma_out_prepare twice: once to find out the tx_size (to find out if it is worths to do DMA at all -- size >= 4), the second time for the actual transfer.
All traces of circ_buf are removed from serial_core.h (and its struct uart_state).
--- drivers/tty/serial/8250/8250_bcm7271.c | 14 +++--- drivers/tty/serial/8250/8250_core.c | 3 +- drivers/tty/serial/8250/8250_dma.c | 23 ++++++---- drivers/tty/serial/8250/8250_exar.c | 5 ++- drivers/tty/serial/8250/8250_mtk.c | 2 +- drivers/tty/serial/8250/8250_omap.c | 47 +++++++++++++------- drivers/tty/serial/8250/8250_pci1xxxx.c | 50 ++++++++++------------ drivers/tty/serial/8250/8250_port.c | 22 ++++++---- drivers/tty/serial/amba-pl011.c | 46 +++++++++----------- drivers/tty/serial/ar933x_uart.c | 15 +++---- drivers/tty/serial/arc_uart.c | 8 ++-- drivers/tty/serial/atmel_serial.c | 57 +++++++++++++------------ drivers/tty/serial/clps711x.c | 12 +++--- drivers/tty/serial/cpm_uart.c | 20 +++------ drivers/tty/serial/digicolor-usart.c | 12 +++--- drivers/tty/serial/dz.c | 13 +++--- drivers/tty/serial/fsl_linflexuart.c | 17 ++++---- drivers/tty/serial/fsl_lpuart.c | 39 ++++++++--------- drivers/tty/serial/icom.c | 25 +++-------- drivers/tty/serial/imx.c | 54 ++++++++++------------- drivers/tty/serial/ip22zilog.c | 26 ++++++----- drivers/tty/serial/jsm/jsm_cls.c | 29 ++++--------- drivers/tty/serial/jsm/jsm_neo.c | 38 ++++++----------- drivers/tty/serial/max3100.c | 14 +++--- drivers/tty/serial/max310x.c | 35 +++++++-------- drivers/tty/serial/men_z135_uart.c | 26 +++++------ drivers/tty/serial/meson_uart.c | 11 +++-- drivers/tty/serial/milbeaut_usio.c | 15 ++++--- drivers/tty/serial/msm_serial.c | 30 ++++++------- drivers/tty/serial/mvebu-uart.c | 8 ++-- drivers/tty/serial/mxs-auart.c | 23 +++------- drivers/tty/serial/pch_uart.c | 21 +++++---- drivers/tty/serial/pic32_uart.c | 15 +++---- drivers/tty/serial/pmac_zilog.c | 24 +++++------ drivers/tty/serial/qcom_geni_serial.c | 36 ++++++++-------- drivers/tty/serial/rda-uart.c | 17 +++----- drivers/tty/serial/samsung_tty.c | 54 ++++++++++++----------- drivers/tty/serial/sb1250-duart.c | 13 +++--- drivers/tty/serial/sc16is7xx.c | 40 +++++++---------- drivers/tty/serial/sccnxp.c | 16 ++++--- drivers/tty/serial/serial-tegra.c | 43 ++++++++++--------- drivers/tty/serial/serial_core.c | 56 +++++++++--------------- drivers/tty/serial/serial_port.c | 2 +- drivers/tty/serial/sh-sci.c | 51 +++++++++++----------- drivers/tty/serial/sprd_serial.c | 20 ++++----- drivers/tty/serial/st-asc.c | 4 +- drivers/tty/serial/stm32-usart.c | 52 +++++++++------------- drivers/tty/serial/sunhv.c | 35 ++++++++------- drivers/tty/serial/sunplus-uart.c | 16 ++++--- drivers/tty/serial/sunsab.c | 30 +++++++------ drivers/tty/serial/sunsu.c | 15 ++++--- drivers/tty/serial/sunzilog.c | 27 ++++++------ drivers/tty/serial/tegra-tcu.c | 10 +++-- drivers/tty/serial/timbuart.c | 17 +++----- drivers/tty/serial/uartlite.c | 13 +++--- drivers/tty/serial/ucc_uart.c | 20 +++------ drivers/tty/serial/xilinx_uartps.c | 20 ++++----- drivers/tty/serial/zs.c | 13 +++--- include/linux/serial_core.h | 49 +++++++++++++-------- 59 files changed, 688 insertions(+), 780 deletions(-)
drivers/tty/serial/8250/8250_bcm7271.c +6 -8
@@ -413,20 +413,18 @@ static int stop_tx_dma(struct uart_8250_port *p)static int brcmuart_tx_dma (struct uart_8250_port *p) {struct brcmuart_priv *priv = p->port.private_data; -struct circ_buf *xmit = &p->port.state->xmit; +struct tty_port *tport = &p->port.state->port;u32 tx_size;if (uart_tx_stopped (&p->port) || priv->tx_running || -uart_circ_empty (xmit)) { +kfifo_is_empty (&tport->xmit_fifo)) {return 0 ; } - tx_size =CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); priv->dma.tx_err =0 ; -memcpy (priv->tx_buf, &xmit->buf[xmit->tail], tx_size); -uart_xmit_advance (&p->port, tx_size); + tx_size =uart_fifo_out (&p->port, priv->tx_buf,UART_XMIT_SIZE ); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&p->port);udma_writel (priv,REGS_DMA_TX ,UDMA_TX_TRANSFER_LEN , tx_size);
@@ -540,7 +538,7 @@ static void brcmuart_tx_isr(struct uart_port *up, u32 isr)struct brcmuart_priv *priv = up->private_data;struct device *dev = up->dev;struct uart_8250_port *port_8250 =up_to_u8250p (up); -struct circ_buf *xmit = &port_8250->port.state->xmit; +struct tty_port *tport = &port_8250->port.state->port;if (isr &UDMA_INTR_TX_ABORT ) {if (priv->tx_running)
@@ -548,7 +546,7 @@ static void brcmuart_tx_isr(struct uart_port *up, u32 isr)return ; } priv->tx_running = false; -if (!uart_circ_empty (xmit) && !uart_tx_stopped (up)) +if (!kfifo_is_empty (&tport->xmit_fifo) && !uart_tx_stopped (up))brcmuart_tx_dma (port_8250); }
drivers/tty/serial/8250/8250_core.c +2 -1
@@ -280,7 +280,8 @@ static void serial8250_backup_timeout(struct timer_list *t)*/ lsr =serial_lsr_in (up);if ((iir &UART_IIR_NO_INT ) && (up->ier &UART_IER_THRI ) && - (!uart_circ_empty (&up->port.state->xmit) || up->port.x_char) && + (!kfifo_is_empty (&up->port.state->port.xmit_fifo) || + up->port.x_char) && (lsr &UART_LSR_THRE )) { iir &= ~(UART_IIR_ID |UART_IIR_NO_INT ); iir |=UART_IIR_THRI ;
drivers/tty/serial/8250/8250_dma.c +14 -9
@@ -15,7 +15,7 @@ static void __dma_tx_complete(void *param) {struct uart_8250_port *p = param;struct uart_8250_dma *dma = p->dma; -struct circ_buf *xmit = &p->port.state->xmit; +struct tty_port *tport = &p->port.state->port;unsigned long flags;int ret;
@@ -28,7 +28,7 @@ static void __dma_tx_complete(void *param)uart_xmit_advance (&p->port, dma->tx_size); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&p->port); ret =serial8250_tx_dma (p);
@@ -86,7 +86,7 @@ static void dma_rx_complete(void *param)int serial8250_tx_dma (struct uart_8250_port *p) {struct uart_8250_dma *dma = p->dma; -struct circ_buf *xmit = &p->port.state->xmit; +struct tty_port *tport = &p->port.state->port;struct dma_async_tx_descriptor *desc;struct uart_port *up = &p->port;struct scatterlist sg;
@@ -103,18 +103,23 @@ int serial8250_tx_dma(struct uart_8250_port *p)uart_xchar_out (up,UART_TX ); } -if (uart_tx_stopped (&p->port) ||uart_circ_empty (xmit)) { +if (uart_tx_stopped (&p->port) ||kfifo_is_empty (&tport->xmit_fifo)) {/* We have been called from __dma_tx_complete() */ return 0 ; } - dma->tx_size =CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); -serial8250_do_prepare_tx_dma (p);sg_init_table (&sg,1 ); -sg_dma_address (&sg) = dma->tx_addr + xmit->tail; -sg_dma_len (&sg) = dma->tx_size; +/* kfifo can do more than one sg, we don't (quite yet) */ + ret =kfifo_dma_out_prepare_mapped (&tport->xmit_fifo, &sg,1 , +UART_XMIT_SIZE , dma->tx_addr); + +/* we already checked empty fifo above, so there should be something */ +if (WARN_ON_ONCE (ret !=1 )) +return 0 ; + + dma->tx_size =sg_dma_len (&sg); desc = dmaengine_prep_slave_sg(dma->txchan, &sg, 1, DMA_MEM_TO_DEV,
@@ -257,7 +262,7 @@ int serial8250_request_dma(struct uart_8250_port *p)/* TX buffer */ dma->tx_addr =dma_map_single (dma->txchan->device->dev, - p->port.state->xmit.buf, + p->port.state->port.xmit_buf,UART_XMIT_SIZE ,DMA_TO_DEVICE );if (dma_mapping_error (dma->txchan->device->dev, dma->tx_addr)) {
drivers/tty/serial/8250/8250_exar.c +3 -2
@@ -214,7 +214,7 @@ static void exar_shutdown(struct uart_port *port) {bool tx_complete = false;struct uart_8250_port *up =up_to_u8250p (port); -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;int i =0 ;u16 lsr;
@@ -225,7 +225,8 @@ static void exar_shutdown(struct uart_port *port)else tx_complete = false;usleep_range (1000 ,1100 ); - }while (!uart_circ_empty (xmit) && !tx_complete && i++ <1000 ); + }while (!kfifo_is_empty (&tport->xmit_fifo) && + !tx_complete && i++ <1000 );serial8250_do_shutdown (port); }
drivers/tty/serial/8250/8250_mtk.c +1 -1
@@ -199,7 +199,7 @@ static int mtk8250_startup(struct uart_port *port)if (up->dma) { data->rx_status =DMA_RX_START ; -uart_circ_clear (&port->state->xmit); +kfifo_reset (&port->state->port.xmit_fifo); }#endif memset (&port->icount,0 ,sizeof (port->icount));
drivers/tty/serial/8250/8250_omap.c +31 -16
102 lines not on this page · raw message
drivers/tty/serial/8250/8250_pci1xxxx.c +22 -28
116 lines not on this page · raw message
drivers/tty/serial/8250/8250_port.c +13 -9
@@ -1630,7 +1630,7 @@ static void serial8250_start_tx(struct uart_port *port)/* Port locked to synchronize UART_IER access against the console. */ lockdep_assert_held_once (&port->lock); -if (!port->x_char &&uart_circ_empty (&port->state->xmit)) +if (!port->x_char &&kfifo_is_empty (&port->state->port.xmit_fifo))return ;serial8250_rpm_get_tx (up);
@@ -1778,7 +1778,7 @@ EXPORT_SYMBOL_GPL(serial8250_rx_chars);void serial8250_tx_chars (struct uart_8250_port *up) {struct uart_port *port = &up->port; -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;int count;if (port->x_char) {
@@ -1789,14 +1789,19 @@ void serial8250_tx_chars(struct uart_8250_port *up)serial8250_stop_tx (port);return ; } -if (uart_circ_empty (xmit)) { +if (kfifo_is_empty (&tport->xmit_fifo)) {__stop_tx (up);return ; } count = up->tx_loadsz; do { - serial_out(up, UART_TX, xmit->buf[xmit->tail]); + unsigned char c; + + if (!uart_fifo_get(port, &c)) + break; + + serial_out(up, UART_TX, c); if (up->bugs & UART_BUG_TXRACE) { /* * The Aspeed BMC virtual UARTs have a bug where data
@@ -1809,9 +1814,7 @@ void serial8250_tx_chars(struct uart_8250_port *up)*/ serial_in (up,UART_SCR ); } -uart_xmit_advance (port,1 ); -if (uart_circ_empty (xmit)) -break ; +if ((up->capabilities &UART_CAP_HFIFO ) && !uart_lsr_tx_empty (serial_in (up,UART_LSR )))break ;
@@ -1821,7 +1824,7 @@ void serial8250_tx_chars(struct uart_8250_port *up)break ; }while (--count >0 ); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port);/*
@@ -1829,7 +1832,8 @@ void serial8250_tx_chars(struct uart_8250_port *up)* HW can go idle. So we get here once again with empty FIFO and disable * the interrupt and RPM in __stop_tx() */ -if (uart_circ_empty (xmit) && !(up->capabilities &UART_CAP_RPM )) +if (kfifo_is_empty (&tport->xmit_fifo) && + !(up->capabilities &UART_CAP_RPM ))__stop_tx (up); }EXPORT_SYMBOL_GPL (serial8250_tx_chars);
drivers/tty/serial/amba-pl011.c +19 -27
108 lines not on this page · raw message
drivers/tty/serial/ar933x_uart.c +7 -8
@@ -390,7 +390,7 @@ static void ar933x_uart_rx_chars(struct ar933x_uart_port *up)static void ar933x_uart_tx_chars (struct ar933x_uart_port *up) { -struct circ_buf *xmit = &up->port.state->xmit; +struct tty_port *tport = &up->port.state->port;struct serial_rs485 *rs485conf = &up->port.rs485;int count;bool half_duplex_send = false;
@@ -399,7 +399,7 @@ static void ar933x_uart_tx_chars(struct ar933x_uart_port *up)return ;if ((rs485conf->flags &SER_RS485_ENABLED ) && - (up->port.x_char || !uart_circ_empty (xmit))) { + (up->port.x_char || !kfifo_is_empty (&tport->xmit_fifo))) {ar933x_uart_stop_rx_interrupt (up);gpiod_set_value (up->rts_gpiod, !!(rs485conf->flags &SER_RS485_RTS_ON_SEND )); half_duplex_send = true;
@@ -408,6 +408,7 @@ static void ar933x_uart_tx_chars(struct ar933x_uart_port *up) count = up->port.fifosize; do { unsigned int rdata; + unsigned char c; rdata = ar933x_uart_read(up, AR933X_UART_DATA_REG); if ((rdata & AR933X_UART_DATA_TX_CSR) == 0)
@@ -420,18 +421,16 @@ static void ar933x_uart_tx_chars(struct ar933x_uart_port *up)continue ; } -if (uart_circ_empty (xmit)) +if (!uart_fifo_get (&up->port, &c))break ; -ar933x_uart_putc (up, xmit->buf[xmit->tail]); - -uart_xmit_advance (&up->port,1 ); +ar933x_uart_putc (up, c); }while (--count >0 ); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&up->port); -if (!uart_circ_empty (xmit)) { +if (!kfifo_is_empty (&tport->xmit_fifo)) {ar933x_uart_start_tx_interrupt (up); }else if (half_duplex_send) {ar933x_uart_wait_tx_complete (up);
drivers/tty/serial/arc_uart.c +3 -5
@@ -155,7 +155,7 @@ static unsigned int arc_serial_tx_empty(struct uart_port *port)*/ static void arc_serial_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;int sent =0 ;unsigned char ch;
@@ -164,9 +164,7 @@ static void arc_serial_tx_chars(struct uart_port *port) port->icount.tx++; port->x_char =0 ; sent =1 ; - }else if (!uart_circ_empty (xmit)) { - ch = xmit->buf[xmit->tail]; -uart_xmit_advance (port,1 ); + }else if (uart_fifo_get (port, &ch)) {while (!(UART_GET_STATUS (port) &TXEMPTY ))cpu_relax ();UART_SET_DATA (port, ch);
@@ -177,7 +175,7 @@ static void arc_serial_tx_chars(struct uart_port *port)* If num chars in xmit buffer are too few, ask tty layer for more. * By Hard ISR to schedule processing in software interrupt part */ -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port);if (sent)
drivers/tty/serial/atmel_serial.c +29 -28
165 lines not on this page · raw message
drivers/tty/serial/clps711x.c +6 -6
@@ -146,7 +146,8 @@ static irqreturn_t uart_clps711x_int_tx(int irq, void *dev_id) {struct uart_port *port = dev_id;struct clps711x_port *s =dev_get_drvdata (port->dev); -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port; +unsigned char c;if (port->x_char) {writew (port->x_char, port->membase +UARTDR_OFFSET );
@@ -155,7 +156,7 @@ static irqreturn_t uart_clps711x_int_tx(int irq, void *dev_id)return IRQ_HANDLED ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {if (s->tx_enabled) {disable_irq_nosync (port->irq); s->tx_enabled =0 ;
@@ -163,18 +164,17 @@ static irqreturn_t uart_clps711x_int_tx(int irq, void *dev_id)return IRQ_HANDLED ; } -while (!uart_circ_empty (xmit)) { +while (uart_fifo_get (port, &c)) {u32 sysflg =0 ; -writew (xmit->buf[xmit->tail], port->membase +UARTDR_OFFSET ); -uart_xmit_advance (port,1 ); +writew (c, port->membase +UARTDR_OFFSET );regmap_read (s->syscon,SYSFLG_OFFSET , &sysflg);if (sysflg &SYSFLG_UTXFF )break ; } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port);return IRQ_HANDLED ;
drivers/tty/serial/cpm_uart.c +7 -13
@@ -648,7 +648,7 @@ static int cpm_uart_tx_pump(struct uart_port *port)int count;struct uart_cpm_port *pinfo = container_of(port, struct uart_cpm_port, port); -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;/* Handle xon/xoff */ if (port->x_char) {
@@ -673,7 +673,7 @@ static int cpm_uart_tx_pump(struct uart_port *port)return 1 ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {cpm_uart_stop_tx (port);return 0 ; }
@@ -681,16 +681,10 @@ static int cpm_uart_tx_pump(struct uart_port *port)/* Pick next descriptor and fill from buffer */ bdp = pinfo->tx_cur; -while (!(in_be16 (&bdp->cbd_sc) &BD_SC_READY ) && !uart_circ_empty (xmit)) { - count =0 ; +while (!(in_be16 (&bdp->cbd_sc) &BD_SC_READY ) && + !kfifo_is_empty (&tport->xmit_fifo)) { p =cpm2cpu_addr (in_be32 (&bdp->cbd_bufaddr), pinfo); -while (count < pinfo->tx_fifosize) { - *p++ = xmit->buf[xmit->tail]; -uart_xmit_advance (port,1 ); - count++; -if (uart_circ_empty (xmit)) -break ; - } + count =uart_fifo_out (port, p, pinfo->tx_fifosize);out_be16 (&bdp->cbd_datlen, count);setbits16 (&bdp->cbd_sc,BD_SC_READY );/* Get next BD. */
@@ -701,10 +695,10 @@ static int cpm_uart_tx_pump(struct uart_port *port) } pinfo->tx_cur = bdp; -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); -if (uart_circ_empty (xmit)) { +if (kfifo_is_empty (&tport->xmit_fifo)) {cpm_uart_stop_tx (port);return 0 ; }
drivers/tty/serial/digicolor-usart.c +6 -6
@@ -179,8 +179,9 @@ static void digicolor_uart_rx(struct uart_port *port)static void digicolor_uart_tx (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;unsigned long flags; +unsigned char c;if (digicolor_uart_tx_full (port))return ;
@@ -194,20 +195,19 @@ static void digicolor_uart_tx(struct uart_port *port) goto out; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {digicolor_uart_stop_tx (port); goto out; } -while (!uart_circ_empty (xmit)) { -writeb (xmit->buf[xmit->tail], port->membase +UA_EMI_REC ); -uart_xmit_advance (port,1 ); +while (uart_fifo_get (port, &c)) { +writeb (c, port->membase +UA_EMI_REC );if (digicolor_uart_tx_full (port))break ; } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); out:
drivers/tty/serial/dz.c +6 -7
@@ -252,13 +252,13 @@ static inline void dz_receive_chars(struct dz_mux *mux)static inline void dz_transmit_chars (struct dz_mux *mux) {struct dz_port *dport = &mux->dport[0 ]; -struct circ_buf *xmit; +struct tty_port *tport;unsigned char tmp;u16 status; status =dz_in (dport,DZ_CSR ); dport = &mux->dport[LINE (status)]; - xmit = &dport->port.state->xmit; + tport = &dport->port.state->port;if (dport->port.x_char) {/* XON/XOFF chars */ dz_out (dport,DZ_TDR , dport->port.x_char);
@@ -267,7 +267,8 @@ static inline void dz_transmit_chars(struct dz_mux *mux)return ; }/* If nothing to do or stopped or hardware stopped. */ -if (uart_circ_empty (xmit) ||uart_tx_stopped (&dport->port)) { +if (uart_tx_stopped (&dport->port) || + !uart_fifo_get (&dport->port, &tmp)) {uart_port_lock (&dport->port);dz_stop_tx (&dport->port);uart_port_unlock (&dport->port);
@@ -278,15 +279,13 @@ static inline void dz_transmit_chars(struct dz_mux *mux)* If something to do... (remember the dz has no output fifo, * so we go one char at a time) :-< */ - tmp = xmit->buf[xmit->tail];dz_out (dport,DZ_TDR , tmp); -uart_xmit_advance (&dport->port,1 ); -if (uart_circ_chars_pending (xmit) <DZ_WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <DZ_WAKEUP_CHARS )uart_write_wakeup (&dport->port);/* Are we are done. */ -if (uart_circ_empty (xmit)) { +if (kfifo_is_empty (&tport->xmit_fifo)) {uart_port_lock (&dport->port);dz_stop_tx (&dport->port);uart_port_unlock (&dport->port);
drivers/tty/serial/fsl_linflexuart.c +9 -8
@@ -174,17 +174,18 @@ static void linflex_put_char(struct uart_port *sport, unsigned char c)static inline void linflex_transmit_buffer (struct uart_port *sport) { -struct circ_buf *xmit = &sport->state->xmit; +struct tty_port *tport = &sport->state->port; +unsigned char c; -while (!uart_circ_empty (xmit)) { -linflex_put_char (sport, xmit->buf[xmit->tail]); -uart_xmit_advance (sport,1 ); +while (uart_fifo_get (sport, &c)) { +linflex_put_char (sport, c); + sport->icount.tx++; } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (sport); -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo))linflex_stop_tx (sport); }
@@ -200,7 +201,7 @@ static void linflex_start_tx(struct uart_port *port)static irqreturn_t linflex_txint (int irq,void *dev_id) {struct uart_port *sport = dev_id; -struct circ_buf *xmit = &sport->state->xmit; +struct tty_port *tport = &sport->state->port;unsigned long flags;uart_port_lock_irqsave (sport, &flags);
@@ -210,7 +211,7 @@ static irqreturn_t linflex_txint(int irq, void *dev_id) goto out; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (sport)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (sport)) {linflex_stop_tx (sport); goto out; }
drivers/tty/serial/fsl_lpuart.c +17 -22
@@ -7,6 +7,7 @@#include <linux/bitfield.h> #include <linux/bits.h> +#include <linux/circ_buf.h> #include <linux/clk.h> #include <linux/console.h> #include <linux/delay.h>
@@ -473,7 +474,7 @@ static void lpuart32_stop_rx(struct uart_port *port)static void lpuart_dma_tx (struct lpuart_port *sport) { -struct circ_buf *xmit = &sport->port.state->xmit; +struct tty_port *tport = &sport->port.state->port;struct scatterlist *sgl = sport->tx_sgl;struct device *dev = sport->port.dev;struct dma_chan *chan = sport->dma_tx_chan;
@@ -482,18 +483,10 @@ static void lpuart_dma_tx(struct lpuart_port *sport)if (sport->dma_tx_in_progress)return ; - sport->dma_tx_bytes =uart_circ_chars_pending (xmit); - -if (xmit->tail < xmit->head || xmit->head ==0 ) { - sport->dma_tx_nents =1 ; -sg_init_one (sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes); - }else { - sport->dma_tx_nents =2 ; -sg_init_table (sgl,2 ); -sg_set_buf (sgl, xmit->buf + xmit->tail, -UART_XMIT_SIZE - xmit->tail); -sg_set_buf (sgl +1 , xmit->buf, xmit->head); - } +sg_init_table (sgl,ARRAY_SIZE (sport->tx_sgl)); + sport->dma_tx_bytes =kfifo_len (&tport->xmit_fifo); + sport->dma_tx_nents =kfifo_dma_out_prepare (&tport->xmit_fifo, sgl, +ARRAY_SIZE (sport->tx_sgl), sport->dma_tx_bytes); ret =dma_map_sg (chan->device->dev, sgl, sport->dma_tx_nents,DMA_TO_DEVICE );
@@ -521,14 +514,15 @@ static void lpuart_dma_tx(struct lpuart_port *sport)static bool lpuart_stopped_or_empty (struct uart_port *port) { -return uart_circ_empty (&port->state->xmit) ||uart_tx_stopped (port); +return kfifo_is_empty (&port->state->port.xmit_fifo) || +uart_tx_stopped (port); }static void lpuart_dma_tx_complete (void *arg) {struct lpuart_port *sport = arg;struct scatterlist *sgl = &sport->tx_sgl[0 ]; -struct circ_buf *xmit = &sport->port.state->xmit; +struct tty_port *tport = &sport->port.state->port;struct dma_chan *chan = sport->dma_tx_chan;unsigned long flags;
@@ -545,7 +539,7 @@ static void lpuart_dma_tx_complete(void *arg) sport->dma_tx_in_progress = false;uart_port_unlock_irqrestore (&sport->port, flags); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&sport->port);if (waitqueue_active (&sport->dma_wait)) {
@@ -756,8 +750,9 @@ static inline void lpuart_transmit_buffer(struct lpuart_port *sport)static inline void lpuart32_transmit_buffer (struct lpuart_port *sport) { -struct circ_buf *xmit = &sport->port.state->xmit; +struct tty_port *tport = &sport->port.state->port;unsigned long txcnt; +unsigned char c;if (sport->port.x_char) {lpuart32_write (&sport->port, sport->port.x_char,UARTDATA );
@@ -774,18 +769,18 @@ static inline void lpuart32_transmit_buffer(struct lpuart_port *sport) txcnt =lpuart32_read (&sport->port,UARTWATER ); txcnt = txcnt >>UARTWATER_TXCNT_OFF ; txcnt &=UARTWATER_COUNT_MASK ; -while (!uart_circ_empty (xmit) && (txcnt < sport->txfifo_size)) { -lpuart32_write (&sport->port, xmit->buf[xmit->tail],UARTDATA ); -uart_xmit_advance (&sport->port,1 ); +while (txcnt < sport->txfifo_size && +uart_fifo_get (&sport->port, &c)) { +lpuart32_write (&sport->port, c,UARTDATA ); txcnt =lpuart32_read (&sport->port,UARTWATER ); txcnt = txcnt >>UARTWATER_TXCNT_OFF ; txcnt &=UARTWATER_COUNT_MASK ; } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&sport->port); -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo))lpuart32_stop_tx (&sport->port); }
drivers/tty/serial/icom.c +6 -19
@@ -877,10 +877,10 @@ static void shutdown(struct icom_port *icom_port)static int icom_write (struct uart_port *port) {struct icom_port *icom_port =to_icom_port (port); +struct tty_port *tport = &port->state->port;unsigned long data_count;unsigned char cmdReg;unsigned long offset; -int temp_tail = port->state->xmit.tail;trace (icom_port,"WRITE" ,0 );
@@ -890,16 +890,8 @@ static int icom_write(struct uart_port *port)return 0 ; } - data_count =0 ; -while ((port->state->xmit.head != temp_tail) && - (data_count <=XMIT_BUFF_SZ )) { - - icom_port->xmit_buf[data_count++] = - port->state->xmit.buf[temp_tail]; - - temp_tail++; - temp_tail &= (UART_XMIT_SIZE -1 ); - } + data_count =kfifo_out_peek (&tport->xmit_fifo, icom_port->xmit_buf, +XMIT_BUFF_SZ );if (data_count) { icom_port->statStg->xmit[0].flags =
@@ -956,7 +948,8 @@ static inline void check_modem_status(struct icom_port *icom_port)static void xmit_interrupt (u16 port_int_reg,struct icom_port *icom_port) { -u16 count, i; +struct tty_port *tport = &icom_port->uart_port.state->port; +u16 count;if (port_int_reg & (INT_XMIT_COMPLETED )) {trace (icom_port,"XMIT_COMPLETE" ,0 );
@@ -968,13 +961,7 @@ static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port) count =le16_to_cpu (icom_port->statStg->xmit[0 ].leLength); icom_port->uart_port.icount.tx += count; -for (i=0 ; i<count && - !uart_circ_empty (&icom_port->uart_port.state->xmit); i++) { - - icom_port->uart_port.state->xmit.tail++; - icom_port->uart_port.state->xmit.tail &= - (UART_XMIT_SIZE -1 ); - } +kfifo_skip_count (&tport->xmit_fifo, count);if (!icom_write (&icom_port->uart_port))/* activate write queue */
drivers/tty/serial/imx.c +23 -31
128 lines not on this page · raw message
drivers/tty/serial/ip22zilog.c +12 -14
@@ -355,7 +355,8 @@ static void ip22zilog_status_handle(struct uart_ip22zilog_port *up,static void ip22zilog_transmit_chars (struct uart_ip22zilog_port *up,struct zilog_channel *channel) { -struct circ_buf *xmit; +struct tty_port *tport; +unsigned char c;if (ZS_IS_CONS (up)) {unsigned char status =readb (&channel->control);
@@ -398,20 +399,18 @@ static void ip22zilog_transmit_chars(struct uart_ip22zilog_port *up,if (up->port.state ==NULL ) goto ack_tx_int; - xmit = &up->port.state->xmit; -if (uart_circ_empty (xmit)) - goto ack_tx_int; + tport = &up->port.state->port;if (uart_tx_stopped (&up->port)) goto ack_tx_int; +if (!uart_fifo_get (&up->port, &c)) + goto ack_tx_int; up->flags |=IP22ZILOG_FLAG_TX_ACTIVE ; -writeb (xmit->buf[xmit->tail], &channel->data); +writeb (c, &channel->data);ZSDELAY ();ZS_WSYNC (channel); -uart_xmit_advance (&up->port,1 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&up->port);return ;
@@ -600,17 +599,16 @@ static void ip22zilog_start_tx(struct uart_port *port) port->icount.tx++; port->x_char =0 ; }else { -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port; +unsigned char c; -if (uart_circ_empty (xmit)) +if (!uart_fifo_get (port, &c))return ; -writeb (xmit->buf[xmit->tail], &channel->data); +writeb (c, &channel->data);ZSDELAY ();ZS_WSYNC (channel); -uart_xmit_advance (port,1 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&up->port); } }
drivers/tty/serial/jsm/jsm_cls.c +8 -21
@@ -443,20 +443,14 @@ static void cls_copy_data_from_uart_to_queue(struct jsm_channel *ch)static void cls_copy_data_from_queue_to_uart (struct jsm_channel *ch) { -u16 tail; +struct tty_port *tport;int n; -int qlen;u32 len_written =0 ; -struct circ_buf *circ;if (!ch)return ; - circ = &ch->uart_port.state->xmit; - -/* No data to write to the UART */ -if (uart_circ_empty (circ)) -return ; + tport = &ch->uart_port.state->port;/* If port is "stopped", don't send any data to the UART */ if ((ch->ch_flags &CH_STOP ) || (ch->ch_flags &CH_BREAK_SENDING ))
@@ -467,29 +461,22 @@ static void cls_copy_data_from_queue_to_uart(struct jsm_channel *ch)return ; n =32 ; +while (n >0 ) { +unsigned char c; -/* cache tail of queue */ - tail = circ->tail & (UART_XMIT_SIZE -1 ); - qlen =uart_circ_chars_pending (circ); - -/* Find minimum of the FIFO space, versus queue length */ - n =min (n, qlen); +if (!kfifo_get (&tport->xmit_fifo, &c)) +break ; -while (n >0 ) { -writeb (circ->buf[tail], &ch->ch_cls_uart->txrx); - tail = (tail +1 ) & (UART_XMIT_SIZE -1 ); +writeb (c, &ch->ch_cls_uart->txrx); n--; ch->ch_txcount++; len_written++; } -/* Update the final tail */ - circ->tail = tail & (UART_XMIT_SIZE -1 ); -if (len_written > ch->ch_t_tlevel) ch->ch_flags &= ~(CH_TX_FIFO_EMPTY |CH_TX_FIFO_LWM ); -if (uart_circ_empty (circ)) +if (kfifo_is_empty (&tport->xmit_fifo))uart_write_wakeup (&ch->uart_port); }
drivers/tty/serial/jsm/jsm_neo.c +13 -25
@@ -474,21 +474,21 @@ static void neo_copy_data_from_uart_to_queue(struct jsm_channel *ch)static void neo_copy_data_from_queue_to_uart (struct jsm_channel *ch) { -u16 head; -u16 tail; +struct tty_port *tport; +unsigned char *tail; +unsigned char c;int n;int s;int qlen;u32 len_written =0 ; -struct circ_buf *circ;if (!ch)return ; - circ = &ch->uart_port.state->xmit; + tport = &ch->uart_port.state->port;/* No data to write to the UART */ -if (uart_circ_empty (circ)) +if (kfifo_is_empty (&tport->xmit_fifo))return ;/* If port is "stopped", don't send any data to the UART */
@@ -504,10 +504,9 @@ static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)if (ch->ch_cached_lsr &UART_LSR_THRE ) { ch->ch_cached_lsr &= ~(UART_LSR_THRE ); -writeb (circ->buf[circ->tail], &ch->ch_neo_uart->txrx); -jsm_dbg (WRITE , &ch->ch_bd->pci_dev, -"Tx data: %x\n" , circ->buf[circ->tail]); - circ->tail = (circ->tail +1 ) & (UART_XMIT_SIZE -1 ); +WARN_ON_ONCE (!kfifo_get (&tport->xmit_fifo, &c)); +writeb (c, &ch->ch_neo_uart->txrx); +jsm_dbg (WRITE , &ch->ch_bd->pci_dev,"Tx data: %x\n" , c); ch->ch_txcount++; }return ;
@@ -520,38 +519,27 @@ static void neo_copy_data_from_queue_to_uart(struct jsm_channel *ch)return ; n =UART_17158_TX_FIFOSIZE - ch->ch_t_tlevel; - -/* cache head and tail of queue */ - head = circ->head & (UART_XMIT_SIZE -1 ); - tail = circ->tail & (UART_XMIT_SIZE -1 ); - qlen =uart_circ_chars_pending (circ); + qlen =kfifo_len (&tport->xmit_fifo);/* Find minimum of the FIFO space, versus queue length */ n =min (n, qlen);while (n >0 ) { - - s = ((head >= tail) ? head :UART_XMIT_SIZE ) - tail; - s =min (s, n); - + s =kfifo_out_linear_ptr (&tport->xmit_fifo, &tail, n);if (s <=0 )break ; -memcpy_toio (&ch->ch_neo_uart->txrxburst, circ->buf + tail, s); -/* Add and flip queue if needed */ - tail = (tail + s) & (UART_XMIT_SIZE -1 ); +memcpy_toio (&ch->ch_neo_uart->txrxburst, tail, s); +kfifo_skip_count (&tport->xmit_fifo, s); n -= s; ch->ch_txcount += s; len_written += s; } -/* Update the final tail */ - circ->tail = tail & (UART_XMIT_SIZE -1 ); -if (len_written >= ch->ch_t_tlevel) ch->ch_flags &= ~(CH_TX_FIFO_EMPTY |CH_TX_FIFO_LWM ); -if (uart_circ_empty (circ)) +if (kfifo_is_empty (&tport->xmit_fifo))uart_write_wakeup (&ch->uart_port); }
drivers/tty/serial/max3100.c +7 -7
@@ -257,10 +257,11 @@ static int max3100_handlerx(struct max3100_port *s, u16 rx)static void max3100_work (struct work_struct *w) { struct max3100_port *s = container_of(w, struct max3100_port, work); +struct tty_port *tport = &s->port.state->port; +unsigned char ch;int rxchars;u16 tx, rx;int conf, cconf, crts; -struct circ_buf *xmit = &s->port.state->xmit;dev_dbg (&s->spi->dev,"%s\n" , __func__);
@@ -290,10 +291,9 @@ static void max3100_work(struct work_struct *w) tx = s->port.x_char; s->port.icount.tx++; s->port.x_char =0 ; - }else if (!uart_circ_empty (xmit) && - !uart_tx_stopped (&s->port)) { - tx = xmit->buf[xmit->tail]; -uart_xmit_advance (&s->port,1 ); + }else if (!uart_tx_stopped (&s->port) && +uart_fifo_get (&s->port, &ch)) { + tx = ch; }if (tx !=0xffff ) {max3100_calc_parity (s, &tx);
@@ -307,13 +307,13 @@ static void max3100_work(struct work_struct *w)tty_flip_buffer_push (&s->port.state->port); rxchars =0 ; } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&s->port); }while (!s->force_end_work && !freezing (current) && ((rx &MAX3100_R ) || - (!uart_circ_empty (xmit) && + (!kfifo_is_empty (&tport->xmit_fifo) && !uart_tx_stopped (&s->port))));if (rxchars >0 )
drivers/tty/serial/max310x.c +15 -20
@@ -747,8 +747,9 @@ static void max310x_handle_rx(struct uart_port *port, unsigned int rxlen)static void max310x_handle_tx (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; -unsigned int txlen, to_send, until_end; +struct tty_port *tport = &port->state->port; +unsigned int txlen, to_send; +unsigned char *tail;if (unlikely (port->x_char)) {max310x_port_write (port,MAX310X_THR_REG , port->x_char);
@@ -757,32 +758,26 @@ static void max310x_handle_tx(struct uart_port *port)return ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port))return ; -/* Get length of data pending in circular buffer */ - to_send =uart_circ_chars_pending (xmit); - until_end =CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); -if (likely (to_send)) { +/* +* It's a circ buffer -- wrap around. +* We could do that in one SPI transaction, but meh. +*/ +while (!kfifo_is_empty (&tport->xmit_fifo)) {/* Limit to space available in TX FIFO */ txlen =max310x_port_read (port,MAX310X_TXFIFOLVL_REG ); txlen = port->fifosize - txlen; - to_send = (to_send > txlen) ? txlen : to_send; - -if (until_end < to_send) { -/* -* It's a circ buffer -- wrap around. -* We could do that in one SPI transaction, but meh. -*/ -max310x_batch_write (port, xmit->buf + xmit->tail, until_end); -max310x_batch_write (port, xmit->buf, to_send - until_end); - }else { -max310x_batch_write (port, xmit->buf + xmit->tail, to_send); - } +if (!txlen) +break ; + + to_send =kfifo_out_linear_ptr (&tport->xmit_fifo, &tail, txlen); +max310x_batch_write (port, tail, to_send);uart_xmit_advance (port, to_send); } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); }
drivers/tty/serial/men_z135_uart.c +10 -16
@@ -293,17 +293,14 @@ static void men_z135_handle_rx(struct men_z135_port *uart)static void men_z135_handle_tx (struct men_z135_port *uart) {struct uart_port *port = &uart->port; -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port; +unsigned char *tail; +unsigned int n, txfree;u32 txc;u32 wptr;int qlen; -int n; -int txfree; -int head; -int tail; -int s; -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo)) goto out;if (uart_tx_stopped (port))
@@ -313,7 +310,7 @@ static void men_z135_handle_tx(struct men_z135_port *uart) goto out;/* calculate bytes to copy */ - qlen =uart_circ_chars_pending (xmit); + qlen =kfifo_len (&tport->xmit_fifo);if (qlen <=0 ) goto out;
@@ -345,21 +342,18 @@ static void men_z135_handle_tx(struct men_z135_port *uart)if (n <=0 ) goto irq_en; - head = xmit->head & (UART_XMIT_SIZE -1 ); - tail = xmit->tail & (UART_XMIT_SIZE -1 ); - - s = ((head >= tail) ? head :UART_XMIT_SIZE ) - tail; - n =min (n, s); + n =kfifo_out_linear_ptr (&tport->xmit_fifo, &tail, + min_t(unsigned int, UART_XMIT_SIZE, n)); +memcpy_toio (port->membase +MEN_Z135_TX_RAM , tail, n); -memcpy_toio (port->membase +MEN_Z135_TX_RAM , &xmit->buf[xmit->tail], n);iowrite32 (n &0x3ff , port->membase +MEN_Z135_TX_CTRL );uart_xmit_advance (port, n); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); irq_en: -if (!uart_circ_empty (xmit)) +if (!kfifo_is_empty (&tport->xmit_fifo))men_z135_reg_set (uart,MEN_Z135_CONF_REG ,MEN_Z135_IER_TXCIEN );else men_z135_reg_clr (uart,MEN_Z135_CONF_REG ,MEN_Z135_IER_TXCIEN );
drivers/tty/serial/meson_uart.c +5 -6
@@ -141,8 +141,8 @@ static void meson_uart_shutdown(struct uart_port *port)static void meson_uart_start_tx (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; -unsigned int ch; +struct tty_port *tport = &port->state->port; +unsigned char ch;u32 val;if (uart_tx_stopped (port)) {
@@ -158,21 +158,20 @@ static void meson_uart_start_tx(struct uart_port *port)continue ; } -if (uart_circ_empty (xmit)) +if (!uart_fifo_get (port, &ch))break ; - ch = xmit->buf[xmit->tail];writel (ch, port->membase +AML_UART_WFIFO );uart_xmit_advance (port,1 ); } -if (!uart_circ_empty (xmit)) { +if (!kfifo_is_empty (&tport->xmit_fifo)) { val =readl (port->membase +AML_UART_CONTROL ); val |=AML_UART_TX_INT_EN ;writel (val, port->membase +AML_UART_CONTROL ); } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); }
drivers/tty/serial/milbeaut_usio.c +8 -7
@@ -72,7 +72,7 @@ static void mlb_usio_stop_tx(struct uart_port *port)static void mlb_usio_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;int count; writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FTIE,
@@ -87,7 +87,7 @@ static void mlb_usio_tx_chars(struct uart_port *port) port->x_char =0 ;return ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {mlb_usio_stop_tx (port);return ; }
@@ -96,12 +96,13 @@ static void mlb_usio_tx_chars(struct uart_port *port) (readw (port->membase +MLB_USIO_REG_FBYTE ) &0xff );do { -writew (xmit->buf[xmit->tail], port->membase +MLB_USIO_REG_DR ); +unsigned char ch; -uart_xmit_advance (port,1 ); -if (uart_circ_empty (xmit)) +if (!uart_fifo_get (port, &ch))break ; +writew (ch, port->membase +MLB_USIO_REG_DR ); + port->icount.tx++; }while (--count >0 ); writew(readw(port->membase + MLB_USIO_REG_FCR) & ~MLB_USIO_FCR_FDRQ,
@@ -110,10 +111,10 @@ static void mlb_usio_tx_chars(struct uart_port *port)writeb (readb (port->membase +MLB_USIO_REG_SCR ) |MLB_USIO_SCR_TBIE , port->membase +MLB_USIO_REG_SCR ); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo))mlb_usio_stop_tx (port); }
drivers/tty/serial/msm_serial.c +13 -17
@@ -452,7 +452,7 @@ static void msm_complete_tx_dma(void *args) {struct msm_port *msm_port = args;struct uart_port *port = &msm_port->uart; -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;struct msm_dma *dma = &msm_port->tx_dma;struct dma_tx_state state;unsigned long flags;
@@ -486,7 +486,7 @@ static void msm_complete_tx_dma(void *args) msm_port->imr |=MSM_UART_IMR_TXLEV ;msm_write (port, msm_port->imr,MSM_UART_IMR ); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port);msm_handle_tx (port);
@@ -496,14 +496,14 @@ static void msm_complete_tx_dma(void *args)static int msm_handle_tx_dma (struct msm_port *msm_port,unsigned int count) { -struct circ_buf *xmit = &msm_port->uart.state->xmit;struct uart_port *port = &msm_port->uart; +struct tty_port *tport = &port->state->port;struct msm_dma *dma = &msm_port->tx_dma;int ret;u32 val;sg_init_table (&dma->tx_sg,1 ); -sg_set_buf (&dma->tx_sg, &xmit->buf[xmit->tail], count); +kfifo_dma_out_prepare (&tport->xmit_fifo, &dma->tx_sg,1 , count); ret =dma_map_sg (port->dev, &dma->tx_sg,1 , dma->dir);if (ret)
@@ -843,8 +843,8 @@ static void msm_handle_rx(struct uart_port *port)static void msm_handle_tx_pio (struct uart_port *port,unsigned int tx_count) { -struct circ_buf *xmit = &port->state->xmit;struct msm_port *msm_port =to_msm_port (port); +struct tty_port *tport = &port->state->port;unsigned int num_chars;unsigned int tf_pointer =0 ;void __iomem *tf;
@@ -858,8 +858,7 @@ static void msm_handle_tx_pio(struct uart_port *port, unsigned int tx_count)msm_reset_dm_count (port, tx_count);while (tf_pointer < tx_count) { -int i; -char buf[4 ] = {0 }; +unsigned char buf[4 ] = {0 };if (!(msm_read (port,MSM_UART_SR ) &MSM_UART_SR_TX_READY ))break ;
@@ -870,26 +869,23 @@ static void msm_handle_tx_pio(struct uart_port *port, unsigned int tx_count)else num_chars =1 ; -for (i =0 ; i < num_chars; i++) - buf[i] = xmit->buf[xmit->tail + i]; - + num_chars =uart_fifo_out (port, buf, num_chars);iowrite32_rep (tf, buf,1 ); -uart_xmit_advance (port, num_chars); tf_pointer += num_chars; }/* disable tx interrupts if nothing more to send */ -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo))msm_stop_tx (port); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); }static void msm_handle_tx (struct uart_port *port) {struct msm_port *msm_port =to_msm_port (port); -struct circ_buf *xmit = &msm_port->uart.state->xmit; +struct tty_port *tport = &port->state->port;struct msm_dma *dma = &msm_port->tx_dma;unsigned int pio_count, dma_count, dma_min;char buf[4 ] = {0 };
@@ -913,13 +909,13 @@ static void msm_handle_tx(struct uart_port *port)return ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {msm_stop_tx (port);return ; } - pio_count =CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); - dma_count =CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); + dma_count = pio_count =kfifo_out_linear (&tport->xmit_fifo,NULL , +UART_XMIT_SIZE ); dma_min =1 ;/* Always DMA */ if (msm_port->is_uartdm >UARTDM_1P3 ) {
drivers/tty/serial/mvebu-uart.c +3 -5
@@ -219,12 +219,10 @@ static void mvebu_uart_stop_tx(struct uart_port *port)static void mvebu_uart_start_tx (struct uart_port *port) {unsigned int ctl; -struct circ_buf *xmit = &port->state->xmit; +unsigned char c; -if (IS_EXTENDED (port) && !uart_circ_empty (xmit)) { -writel (xmit->buf[xmit->tail], port->membase +UART_TSH (port)); -uart_xmit_advance (port,1 ); - } +if (IS_EXTENDED (port) &&uart_fifo_get (port, &c)) +writel (c, port->membase +UART_TSH (port)); ctl =readl (port->membase +UART_INTR (port)); ctl |=CTRL_TX_RDY_INT (port);
drivers/tty/serial/mxs-auart.c +6 -17
@@ -517,7 +517,7 @@ static void mxs_auart_tx_chars(struct mxs_auart_port *s);static void dma_tx_callback (void *param) {struct mxs_auart_port *s = param; -struct circ_buf *xmit = &s->port.state->xmit; +struct tty_port *tport = &s->port.state->port;dma_unmap_sg (s->dev, &s->tx_sgl,1 ,DMA_TO_DEVICE );
@@ -526,7 +526,7 @@ static void dma_tx_callback(void *param)smp_mb__after_atomic ();/* wake up the possible processes. */ -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&s->port);mxs_auart_tx_chars (s);
@@ -568,33 +568,22 @@ static int mxs_auart_dma_tx(struct mxs_auart_port *s, int size)static void mxs_auart_tx_chars (struct mxs_auart_port *s) { -struct circ_buf *xmit = &s->port.state->xmit; +struct tty_port *tport = &s->port.state->port;bool pending;u8 ch;if (auart_dma_enabled (s)) {u32 i =0 ; -int size;void *buffer = s->tx_dma_buf;if (test_and_set_bit (MXS_AUART_DMA_TX_SYNC , &s->flags))return ; -while (!uart_circ_empty (xmit) && !uart_tx_stopped (&s->port)) { - size =min_t (u32,UART_XMIT_SIZE - i, -CIRC_CNT_TO_END (xmit->head, - xmit->tail, -UART_XMIT_SIZE )); -memcpy (buffer + i, xmit->buf + xmit->tail, size); - xmit->tail = (xmit->tail + size) & (UART_XMIT_SIZE -1 ); - - i += size; -if (i >=UART_XMIT_SIZE ) -break ; - } -if (uart_tx_stopped (&s->port))mxs_auart_stop_tx (&s->port); +else + i =kfifo_out (&tport->xmit_fifo, buffer, +UART_XMIT_SIZE );if (i) {mxs_auart_dma_tx (s, i);
drivers/tty/serial/pch_uart.c +10 -11
@@ -808,7 +808,7 @@ static int dma_handle_rx(struct eg20t_port *priv)static unsigned int handle_tx (struct eg20t_port *priv) {struct uart_port *port = &priv->port; -struct circ_buf *xmit = &port->state->xmit; +unsigned char ch;int fifo_size;int tx_empty;
@@ -830,9 +830,9 @@ static unsigned int handle_tx(struct eg20t_port *priv) fifo_size--; } -while (!uart_tx_stopped (port) && !uart_circ_empty (xmit) && fifo_size) { -iowrite8 (xmit->buf[xmit->tail], priv->membase +PCH_UART_THR ); -uart_xmit_advance (port,1 ); +while (!uart_tx_stopped (port) && fifo_size && +uart_fifo_get (port, &ch)) { +iowrite8 (ch, priv->membase +PCH_UART_THR ); fifo_size--; tx_empty =0 ; }
@@ -850,14 +850,14 @@ static unsigned int handle_tx(struct eg20t_port *priv)static unsigned int dma_handle_tx (struct eg20t_port *priv) {struct uart_port *port = &priv->port; -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;struct scatterlist *sg;int nent;int fifo_size;struct dma_async_tx_descriptor *desc; +unsigned int bytes, tail;int num;int i; -int bytes;int size;int rem;
@@ -886,7 +886,7 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv) fifo_size--; } - bytes =CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); + bytes =kfifo_out_linear (&tport->xmit_fifo, &tail,UART_XMIT_SIZE );if (!bytes) {dev_dbg (priv->port.dev,"%s 0 bytes return\n" , __func__);pch_uart_hal_disable_interrupt (priv,PCH_UART_HAL_TX_INT );
@@ -920,10 +920,10 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv)for (i =0 ; i < num; i++, sg++) {if (i == (num -1 )) -sg_set_page (sg,virt_to_page (xmit->buf), +sg_set_page (sg,virt_to_page (tport->xmit_buf), rem, fifo_size * i);else -sg_set_page (sg,virt_to_page (xmit->buf), +sg_set_page (sg,virt_to_page (tport->xmit_buf), size, fifo_size * i); }
@@ -937,8 +937,7 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv) priv->nent = nent;for (i =0 ; i < nent; i++, sg++) { - sg->offset = (xmit->tail & (UART_XMIT_SIZE -1 )) + - fifo_size * i; + sg->offset = tail + fifo_size * i;sg_dma_address (sg) = (sg_dma_address (sg) & ~(UART_XMIT_SIZE -1 )) + sg->offset;if (i == (nent -1 ))
drivers/tty/serial/pic32_uart.c +7 -8
@@ -342,7 +342,7 @@ static void pic32_uart_do_rx(struct uart_port *port)static void pic32_uart_do_tx (struct uart_port *port) {struct pic32_sport *sport =to_pic32_sport (port); -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;unsigned int max_count =PIC32_UART_TX_FIFO_DEPTH ;if (port->x_char) {
@@ -357,7 +357,7 @@ static void pic32_uart_do_tx(struct uart_port *port)return ; } -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo)) goto txq_empty;/* keep stuffing chars into uart tx buffer
@@ -371,21 +371,20 @@ static void pic32_uart_do_tx(struct uart_port *port)*/ while (!(PIC32_UART_STA_UTXBF &pic32_uart_readl (sport,PIC32_UART_STA ))) { -unsigned int c = xmit->buf[xmit->tail]; +unsigned char c; +if (!uart_fifo_get (port, &c)) +break ;pic32_uart_writel (sport,PIC32_UART_TX , c); -uart_xmit_advance (port,1 ); -if (uart_circ_empty (xmit)) -break ;if (--max_count ==0 )break ; } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo)) goto txq_empty;return ;
drivers/tty/serial/pmac_zilog.c +12 -12
@@ -347,7 +347,8 @@ static void pmz_status_handle(struct uart_pmac_port *uap)static void pmz_transmit_chars (struct uart_pmac_port *uap) { -struct circ_buf *xmit; +struct tty_port *tport; +unsigned char ch;if (ZS_IS_CONS (uap)) {unsigned char status =read_zsreg (uap,R0 );
@@ -398,8 +399,8 @@ static void pmz_transmit_chars(struct uart_pmac_port *uap)if (uap->port.state ==NULL ) goto ack_tx_int; - xmit = &uap->port.state->xmit; -if (uart_circ_empty (xmit)) { + tport = &uap->port.state->port; +if (kfifo_is_empty (&tport->xmit_fifo)) {uart_write_wakeup (&uap->port); goto ack_tx_int; }
@@ -407,12 +408,11 @@ static void pmz_transmit_chars(struct uart_pmac_port *uap) goto ack_tx_int; uap->flags |=PMACZILOG_FLAG_TX_ACTIVE ; -write_zsdata (uap, xmit->buf[xmit->tail]); +WARN_ON (!uart_fifo_get (&uap->port, &ch)); +write_zsdata (uap, ch);zssync (uap); -uart_xmit_advance (&uap->port,1 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&uap->port);return ;
@@ -620,15 +620,15 @@ static void pmz_start_tx(struct uart_port *port) port->icount.tx++; port->x_char =0 ; }else { -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port; +unsigned char ch; -if (uart_circ_empty (xmit)) +if (!uart_fifo_get (&uap->port, &ch))return ; -write_zsdata (uap, xmit->buf[xmit->tail]); +write_zsdata (uap, ch);zssync (uap); -uart_xmit_advance (port,1 ); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&uap->port); } }
drivers/tty/serial/qcom_geni_serial.c +18 -18
@@ -505,7 +505,7 @@ static void qcom_geni_serial_console_write(struct console *co, const char *s,*/ qcom_geni_serial_poll_tx_done (uport); -if (!uart_circ_empty (&uport->state->xmit)) { +if (!kfifo_is_empty (&uport->state->port.xmit_fifo)) { irq_en =readl (uport->membase +SE_GENI_M_IRQ_EN );writel (irq_en |M_TX_FIFO_WATERMARK_EN , uport->membase +SE_GENI_M_IRQ_EN );
@@ -620,22 +620,24 @@ static void qcom_geni_serial_stop_tx_dma(struct uart_port *uport)static void qcom_geni_serial_start_tx_dma (struct uart_port *uport) {struct qcom_geni_serial_port *port =to_dev_port (uport); -struct circ_buf *xmit = &uport->state->xmit; +struct tty_port *tport = &uport->state->port;unsigned int xmit_size; +u8 *tail;int ret;if (port->tx_dma_addr)return ; -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo))return ; - xmit_size =CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); + xmit_size =kfifo_out_linear_ptr (&tport->xmit_fifo, &tail, +UART_XMIT_SIZE );qcom_geni_serial_setup_tx (uport, xmit_size); - ret =geni_se_tx_dma_prep (&port->se, &xmit->buf[xmit->tail], - xmit_size, &port->tx_dma_addr); + ret =geni_se_tx_dma_prep (&port->se, tail, xmit_size, + &port->tx_dma_addr);if (ret) {dev_err (uport->dev,"unable to start TX SE DMA: %d\n" , ret);qcom_geni_serial_stop_tx_dma (uport);
@@ -853,18 +855,16 @@ static void qcom_geni_serial_send_chunk_fifo(struct uart_port *uport, unsigned int chunk) {struct qcom_geni_serial_port *port =to_dev_port (uport); -struct circ_buf *xmit = &uport->state->xmit; -unsigned int tx_bytes, c, remaining = chunk; +struct tty_port *tport = &uport->state->port; +unsigned int tx_bytes, remaining = chunk;u8 buf[BYTES_PER_FIFO_WORD ];while (remaining) {memset (buf,0 ,sizeof (buf)); tx_bytes =min (remaining,BYTES_PER_FIFO_WORD ); -for (c =0 ; c < tx_bytes ; c++) { - buf[c] = xmit->buf[xmit->tail]; -uart_xmit_advance (uport,1 ); - } + tx_bytes =kfifo_out (&tport->xmit_fifo, buf, tx_bytes); +uart_xmit_advance (uport, tx_bytes);iowrite32_rep (uport->membase + SE_GENI_TX_FIFOn, buf,1 );
@@ -877,7 +877,7 @@ static void qcom_geni_serial_handle_tx_fifo(struct uart_port *uport, bool done, bool active) {struct qcom_geni_serial_port *port =to_dev_port (uport); -struct circ_buf *xmit = &uport->state->xmit; +struct tty_port *tport = &uport->state->port;size_t avail;size_t pending;u32 status;
@@ -890,7 +890,7 @@ static void qcom_geni_serial_handle_tx_fifo(struct uart_port *uport,if (active) pending = port->tx_remaining;else - pending =uart_circ_chars_pending (xmit); + pending =kfifo_len (&tport->xmit_fifo);/* All data has been transmitted and acknowledged as received */ if (!pending && !status && done) {
@@ -933,24 +933,24 @@ static void qcom_geni_serial_handle_tx_fifo(struct uart_port *uport, uport->membase + SE_GENI_M_IRQ_EN); } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (uport); }static void qcom_geni_serial_handle_tx_dma (struct uart_port *uport) {struct qcom_geni_serial_port *port =to_dev_port (uport); -struct circ_buf *xmit = &uport->state->xmit; +struct tty_port *tport = &uport->state->port;uart_xmit_advance (uport, port->tx_remaining);geni_se_tx_dma_unprep (&port->se, port->tx_dma_addr, port->tx_remaining); port->tx_dma_addr =0 ; port->tx_remaining =0 ; -if (!uart_circ_empty (xmit)) +if (!kfifo_is_empty (&tport->xmit_fifo))qcom_geni_serial_start_tx_dma (uport); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (uport); }
drivers/tty/serial/rda-uart.c +6 -11
@@ -330,8 +330,8 @@ static void rda_uart_set_termios(struct uart_port *port,static void rda_uart_send_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; -unsigned int ch; +struct tty_port *tport = &port->state->port; +unsigned char ch;u32 val;if (uart_tx_stopped (port))
@@ -347,19 +347,14 @@ static void rda_uart_send_chars(struct uart_port *port) port->x_char =0 ; } -while (rda_uart_read (port,RDA_UART_STATUS ) &RDA_UART_TX_FIFO_MASK ) { -if (uart_circ_empty (xmit)) -break ; - - ch = xmit->buf[xmit->tail]; +while ((rda_uart_read (port,RDA_UART_STATUS ) &RDA_UART_TX_FIFO_MASK ) && +uart_fifo_get (port, &ch))rda_uart_write (port, ch,RDA_UART_RXTX_BUFFER ); -uart_xmit_advance (port,1 ); - } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); -if (!uart_circ_empty (xmit)) { +if (!kfifo_is_empty (&tport->xmit_fifo)) {/* Re-enable Tx FIFO interrupt */ val =rda_uart_read (port,RDA_UART_IRQ_MASK ); val |=RDA_UART_TX_DATA_NEEDED ;
drivers/tty/serial/samsung_tty.c +28 -26
149 lines not on this page · raw message
drivers/tty/serial/sb1250-duart.c +7 -6
@@ -382,7 +382,8 @@ static void sbd_receive_chars(struct sbd_port *sport)static void sbd_transmit_chars (struct sbd_port *sport) {struct uart_port *uport = &sport->port; -struct circ_buf *xmit = &sport->port.state->xmit; +struct tty_port *tport = &sport->port.state->port; +unsigned char ch;unsigned int mask;int stop_tx;
@@ -395,19 +396,19 @@ static void sbd_transmit_chars(struct sbd_port *sport) }/* If nothing to do or stopped or hardware stopped. */ - stop_tx = (uart_circ_empty (xmit) ||uart_tx_stopped (&sport->port)); + stop_tx =uart_tx_stopped (&sport->port) || + !uart_fifo_get (&sport->port, &ch);/* Send char. */ if (!stop_tx) { -write_sbdchn (sport,R_DUART_TX_HOLD , xmit->buf[xmit->tail]); -uart_xmit_advance (&sport->port,1 ); +write_sbdchn (sport,R_DUART_TX_HOLD , ch); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (&sport->port); }/* Are we are done? */ -if (stop_tx ||uart_circ_empty (xmit)) { +if (stop_tx ||kfifo_is_empty (&tport->xmit_fifo)) {/* Disable tx interrupts. */ mask =read_sbdshr (sport,R_DUART_IMRREG ((uport->line) %2 )); mask &= ~M_DUART_IMR_TX ;
drivers/tty/serial/sc16is7xx.c +15 -25
@@ -676,9 +676,9 @@ static void sc16is7xx_handle_rx(struct uart_port *port, unsigned int rxlen,static void sc16is7xx_handle_tx (struct uart_port *port) {struct sc16is7xx_port *s =dev_get_drvdata (port->dev); -struct circ_buf *xmit = &port->state->xmit; -unsigned int txlen, to_send, i; +struct tty_port *tport = &port->state->port;unsigned long flags; +unsigned int txlen;if (unlikely (port->x_char)) {sc16is7xx_port_write (port,SC16IS7XX_THR_REG , port->x_char);
@@ -687,40 +687,30 @@ static void sc16is7xx_handle_tx(struct uart_port *port)return ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {uart_port_lock_irqsave (port, &flags);sc16is7xx_stop_tx (port);uart_port_unlock_irqrestore (port, flags);return ; } -/* Get length of data pending in circular buffer */ - to_send =uart_circ_chars_pending (xmit); -if (likely (to_send)) { -/* Limit to space available in TX FIFO */ - txlen =sc16is7xx_port_read (port,SC16IS7XX_TXLVL_REG ); -if (txlen >SC16IS7XX_FIFO_SIZE ) { -dev_err_ratelimited (port->dev, -"chip reports %d free bytes in TX fifo, but it only has %d" , - txlen,SC16IS7XX_FIFO_SIZE ); - txlen =0 ; - } - to_send = (to_send > txlen) ? txlen : to_send; - -/* Convert to linear buffer */ -for (i =0 ; i < to_send; ++i) { - s->buf[i] = xmit->buf[xmit->tail]; -uart_xmit_advance (port,1 ); - } - -sc16is7xx_fifo_write (port, s->buf, to_send); +/* Limit to space available in TX FIFO */ + txlen =sc16is7xx_port_read (port,SC16IS7XX_TXLVL_REG ); +if (txlen >SC16IS7XX_FIFO_SIZE ) { +dev_err_ratelimited (port->dev, +"chip reports %d free bytes in TX fifo, but it only has %d" , + txlen,SC16IS7XX_FIFO_SIZE ); + txlen =0 ; } + txlen =uart_fifo_out (port, s->buf, txlen); +sc16is7xx_fifo_write (port, s->buf, txlen); +uart_port_lock_irqsave (port, &flags); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); -if (uart_circ_empty (xmit)) +if (kfifo_is_empty (&tport->xmit_fifo))sc16is7xx_stop_tx (port);else sc16is7xx_ier_set (port,SC16IS7XX_IER_THRI_BIT );
drivers/tty/serial/sccnxp.c +10 -6
@@ -439,7 +439,7 @@ static void sccnxp_handle_rx(struct uart_port *port)static void sccnxp_handle_tx (struct uart_port *port) {u8 sr; -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;struct sccnxp_port *s =dev_get_drvdata (port->dev);if (unlikely (port->x_char)) {
@@ -449,7 +449,7 @@ static void sccnxp_handle_tx(struct uart_port *port)return ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {/* Disable TX if FIFO is empty */ if (sccnxp_port_read (port,SCCNXP_SR_REG ) &SR_TXEMT ) {sccnxp_disable_irq (port,IMR_TXRDY );
@@ -461,16 +461,20 @@ static void sccnxp_handle_tx(struct uart_port *port)return ; } -while (!uart_circ_empty (xmit)) { +while (1 ) { +unsigned char ch; + sr =sccnxp_port_read (port,SCCNXP_SR_REG );if (!(sr &SR_TXRDY ))break ; -sccnxp_port_write (port,SCCNXP_THR_REG , xmit->buf[xmit->tail]); -uart_xmit_advance (port,1 ); +if (!uart_fifo_get (port, &ch)) +break ; + +sccnxp_port_write (port,SCCNXP_THR_REG , ch); } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); }
drivers/tty/serial/serial-tegra.c +24 -19
120 lines not on this page · raw message
drivers/tty/serial/serial_core.c +21 -35
129 lines not on this page · raw message
drivers/tty/serial/serial_port.c +1 -1
@@ -23,7 +23,7 @@static int __serial_port_busy (struct uart_port *port) {return !uart_tx_stopped (port) && -uart_circ_chars_pending (&port->state->xmit); + !kfifo_is_empty (&port->state->port.xmit_fifo); }static int serial_port_runtime_resume (struct device *dev)
drivers/tty/serial/sh-sci.c +25 -26
135 lines not on this page · raw message
drivers/tty/serial/sprd_serial.c +10 -10
@@ -227,13 +227,13 @@ static int sprd_tx_buf_remap(struct uart_port *port) {struct sprd_uart_port *sp = container_of(port, struct sprd_uart_port, port); -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port; +unsigned char *tail; - sp->tx_dma.trans_len = -CIRC_CNT_TO_END (xmit->head, xmit->tail,UART_XMIT_SIZE ); + sp->tx_dma.trans_len =kfifo_out_linear_ptr (&tport->xmit_fifo, &tail, +UART_XMIT_SIZE ); - sp->tx_dma.phys_addr =dma_map_single (port->dev, - (void *)&(xmit->buf[xmit->tail]), + sp->tx_dma.phys_addr =dma_map_single (port->dev, tail, sp->tx_dma.trans_len,DMA_TO_DEVICE );return dma_mapping_error (port->dev, sp->tx_dma.phys_addr);
@@ -244,7 +244,7 @@ static void sprd_complete_tx_dma(void *data)struct uart_port *port = (struct uart_port *)data;struct sprd_uart_port *sp = container_of(port, struct sprd_uart_port, port); -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;unsigned long flags;uart_port_lock_irqsave (port, &flags);
@@ -253,10 +253,10 @@ static void sprd_complete_tx_dma(void *data)uart_xmit_advance (port, sp->tx_dma.trans_len); -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) +if (kfifo_len (&tport->xmit_fifo) <WAKEUP_CHARS )uart_write_wakeup (port); -if (uart_circ_empty (xmit) ||sprd_tx_buf_remap (port) || +if (kfifo_is_empty (&tport->xmit_fifo) ||sprd_tx_buf_remap (port) ||sprd_tx_dma_config (port)) sp->tx_dma.trans_len =0 ;
@@ -319,7 +319,7 @@ static void sprd_start_tx_dma(struct uart_port *port) {struct sprd_uart_port *sp = container_of(port, struct sprd_uart_port, port); -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port;if (port->x_char) {serial_out (port,SPRD_TXD , port->x_char);
@@ -328,7 +328,7 @@ static void sprd_start_tx_dma(struct uart_port *port)return ; } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) {sprd_stop_tx_dma (port);return ; }
drivers/tty/serial/st-asc.c +2 -2
@@ -387,9 +387,9 @@ static unsigned int asc_get_mctrl(struct uart_port *port)/* There are probably characters waiting to be transmitted. */ static void asc_start_tx (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; +struct tty_port *tport = &port->state->port; -if (!uart_circ_empty (xmit)) +if (!kfifo_is_empty (&tport->xmit_fifo))asc_enable_tx_interrupts (port); }
drivers/tty/serial/stm32-usart.c +20 -32
110 lines not on this page · raw message
drivers/tty/serial/sunhv.c +20 -15
@@ -39,10 +39,13 @@ static char *con_read_page;static int hung_up =0 ; -static void transmit_chars_putchar (struct uart_port *port,struct circ_buf *xmit) +static void transmit_chars_putchar (struct uart_port *port, +struct tty_port *tport) { -while (!uart_circ_empty (xmit)) { -long status =sun4v_con_putchar (xmit->buf[xmit->tail]); +unsigned char ch; + +while (kfifo_peek (&tport->xmit_fifo, &ch)) { +long status =sun4v_con_putchar (ch);if (status !=HV_EOK )break ;
@@ -51,14 +54,16 @@ static void transmit_chars_putchar(struct uart_port *port, struct circ_buf *xmit } } -static void transmit_chars_write (struct uart_port *port,struct circ_buf *xmit) +static void transmit_chars_write (struct uart_port *port,struct tty_port *tport) { -while (!uart_circ_empty (xmit)) { -unsigned long ra =__pa (xmit->buf + xmit->tail); -unsigned long len, status, sent; +while (!kfifo_is_empty (&tport->xmit_fifo)) { +unsigned long len, ra, status, sent; +unsigned char *tail;
Lines of this file are not shown. View the raw message.
include/linux/serial_core.h +31 -18
49 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.44.0
Part of the diff is not shown here. View the raw message.
Jiri Slaby (SUSE)
maintainerPATCH 13/15 tty: atmel_serial: use single DMA mapping for TX
In reply to Jiri Slaby (SUSE)dma_map_single() provides much easier interface for simple mappings as used for TX in atmel_serial. So switch to that, removing all the s-g unnecessary handling.
Note that it is not easy (maybe impossible) to use kfifo_dma_* API for atmel's serial purposes. It handles DMA very specially.
--- drivers/tty/serial/atmel_serial.c | 35 +++++++++++++------------------ 1 file changed, 14 insertions(+), 21 deletions(-)
drivers/tty/serial/atmel_serial.c +14 -21
@@ -132,7 +132,7 @@ struct atmel_uart_port {struct dma_async_tx_descriptor *desc_rx;dma_cookie_t cookie_tx;dma_cookie_t cookie_rx; -struct scatterlist sg_tx; +dma_addr_t tx_phys;struct scatterlist sg_rx;struct tasklet_struct tasklet_rx;struct tasklet_struct tasklet_tx;
@@ -904,8 +904,8 @@ static void atmel_release_tx_dma(struct uart_port *port)if (chan) {dmaengine_terminate_all (chan);dma_release_channel (chan); -dma_unmap_sg (port->dev, &atmel_port->sg_tx,1 , -DMA_TO_DEVICE ); +dma_unmap_single (port->dev, atmel_port->tx_phys, +UART_XMIT_SIZE ,DMA_TO_DEVICE ); } atmel_port->desc_tx =NULL ;
@@ -922,7 +922,7 @@ static void atmel_tx_dma(struct uart_port *port)struct tty_port *tport = &port->state->port;struct dma_chan *chan = atmel_port->chan_tx;struct dma_async_tx_descriptor *desc; -struct scatterlist sgl[2 ], *sg, *sg_tx = &atmel_port->sg_tx; +struct scatterlist sgl[2 ], *sg;unsigned int tx_len, tail, part1_len, part2_len, sg_len;dma_addr_t phys_addr;
@@ -955,7 +955,7 @@ static void atmel_tx_dma(struct uart_port *port)sg_init_table (sgl,2 ); sg_len =0 ; - phys_addr =sg_dma_address (sg_tx) + tail; + phys_addr = atmel_port->tx_phys + tail;if (part1_len) { sg = &sgl[sg_len++];sg_dma_address (sg) = phys_addr;
@@ -987,7 +987,8 @@ static void atmel_tx_dma(struct uart_port *port)return ; } -dma_sync_sg_for_device (port->dev, sg_tx,1 ,DMA_TO_DEVICE ); +dma_sync_single_for_device (port->dev, atmel_port->tx_phys, +UART_XMIT_SIZE ,DMA_TO_DEVICE ); atmel_port->desc_tx = desc; desc->callback = atmel_complete_tx_dma;
@@ -1014,7 +1015,7 @@ static int atmel_prepare_tx_dma(struct uart_port *port)dma_cap_mask_t mask;struct dma_slave_config config;struct dma_chan *chan; -int ret, nent; +int ret;dma_cap_zero (mask);dma_cap_set (DMA_SLAVE , mask);
@@ -1029,26 +1030,18 @@ static int atmel_prepare_tx_dma(struct uart_port *port) dma_chan_name(atmel_port->chan_tx));spin_lock_init (&atmel_port->lock_tx); -sg_init_table (&atmel_port->sg_tx,1 );/* UART circular tx buffer is an aligned page. */ BUG_ON (!PAGE_ALIGNED (tport->xmit_buf)); -sg_set_page (&atmel_port->sg_tx, -virt_to_page (tport->xmit_buf), -UART_XMIT_SIZE , -offset_in_page (tport->xmit_buf)); - nent =dma_map_sg (port->dev, - &atmel_port->sg_tx, -1 , -DMA_TO_DEVICE ); + atmel_port->tx_phys =dma_map_single (port->dev, tport->xmit_buf, +UART_XMIT_SIZE ,DMA_TO_DEVICE ); -if (!nent) { +if (dma_mapping_error (port->dev, atmel_port->tx_phys)) {dev_dbg (port->dev,"need to release resource of dma\n" ); goto chan_err; }else { -dev_dbg (port->dev,"%s: mapped %d@%p to %pad\n" , __func__, -sg_dma_len (&atmel_port->sg_tx), - tport->xmit_buf, - &sg_dma_address (&atmel_port->sg_tx)); +dev_dbg (port->dev,"%s: mapped %lu@%p to %pad\n" , __func__, +UART_XMIT_SIZE , tport->xmit_buf, + &atmel_port->tx_phys); }/* Configure the slave DMA */
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 14/15 tty: atmel_serial: define macro for RX size
In reply to Jiri Slaby (SUSE)It is repeated in the code and there is also a big warning by ATMEL_SERIAL_RINGSIZE. So define ATMEL_SERIAL_RX_SIZE and use it appropriatelly.
The macro uses array_size() and kmalloc_array() is switched to kmalloc().
--- drivers/tty/serial/atmel_serial.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/tty/serial/atmel_serial.c +5 -5
@@ -96,7 +96,9 @@ struct atmel_uart_char {* can contain up to 1024 characters in PIO mode and up to 4096 characters in * DMA mode. */ -#define ATMEL_SERIAL_RINGSIZE 1024 +#define ATMEL_SERIAL_RINGSIZE 1024 +#define ATMEL_SERIAL_RX_SIZE array_size(sizeof(struct atmel_uart_char), \ + ATMEL_SERIAL_RINGSIZE)/* * at91: 6 USARTs and one DBGU port (SAM9260)
@@ -1208,7 +1210,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port)BUG_ON (!PAGE_ALIGNED (ring->buf));sg_set_page (&atmel_port->sg_rx,virt_to_page (ring->buf), -sizeof (struct atmel_uart_char ) *ATMEL_SERIAL_RINGSIZE , +ATMEL_SERIAL_RX_SIZE ,offset_in_page (ring->buf)); nent = dma_map_sg(port->dev, &atmel_port->sg_rx,
@@ -2947,9 +2949,7 @@ static int atmel_serial_probe(struct platform_device *pdev)if (!atmel_use_pdc_rx (&atmel_port->uart)) { ret = -ENOMEM ; - data =kmalloc_array (ATMEL_SERIAL_RINGSIZE , -sizeof (struct atmel_uart_char ), -GFP_KERNEL ); + data =kmalloc (ATMEL_SERIAL_RX_SIZE ,GFP_KERNEL );if (!data) goto err_clk_disable_unprepare; atmel_port->rx_ring.buf = data;
Signature · 1 line
2.44.0
Jiri Slaby (SUSE)
maintainerPATCH 15/15 tty: atmel_serial: use single DMA mapping for RX
In reply to Jiri Slaby (SUSE)dma_map_single() provides much easier interface for simple mappings as used for RX in atmel_serial. So switch to that, removing all the s-g unnecessary handling.
--- drivers/tty/serial/atmel_serial.c | 56 ++++++++++++------------------- 1 file changed, 22 insertions(+), 34 deletions(-)
drivers/tty/serial/atmel_serial.c +22 -34
@@ -135,7 +135,7 @@ struct atmel_uart_port {dma_cookie_t cookie_tx;dma_cookie_t cookie_rx;dma_addr_t tx_phys; -struct scatterlist sg_rx; +dma_addr_t rx_phys;struct tasklet_struct tasklet_rx;struct tasklet_struct tasklet_tx;atomic_t tasklet_shutdown;
@@ -1088,8 +1088,8 @@ static void atmel_release_rx_dma(struct uart_port *port)if (chan) {dmaengine_terminate_all (chan);dma_release_channel (chan); -dma_unmap_sg (port->dev, &atmel_port->sg_rx,1 , -DMA_FROM_DEVICE ); +dma_unmap_single (port->dev, atmel_port->rx_phys, +ATMEL_SERIAL_RX_SIZE ,DMA_FROM_DEVICE ); } atmel_port->desc_rx =NULL ;
@@ -1122,10 +1122,8 @@ static void atmel_rx_from_dma(struct uart_port *port) }/* CPU claims ownership of RX DMA buffer */ -dma_sync_sg_for_cpu (port->dev, - &atmel_port->sg_rx, -1 , -DMA_FROM_DEVICE ); +dma_sync_single_for_cpu (port->dev, atmel_port->rx_phys, +ATMEL_SERIAL_RX_SIZE ,DMA_FROM_DEVICE );/* * ring->head points to the end of data already written by the DMA.
@@ -1134,8 +1132,8 @@ static void atmel_rx_from_dma(struct uart_port *port)* The current transfer size should not be larger than the dma buffer * length. */ - ring->head =sg_dma_len (&atmel_port->sg_rx) - state.residue; -BUG_ON (ring->head >sg_dma_len (&atmel_port->sg_rx)); + ring->head =ATMEL_SERIAL_RX_SIZE - state.residue; +BUG_ON (ring->head >ATMEL_SERIAL_RX_SIZE );/* * At this point ring->head may point to the first byte right after the * last byte of the dma buffer:
@@ -1149,7 +1147,7 @@ static void atmel_rx_from_dma(struct uart_port *port)* tail to the end of the buffer then reset tail. */ if (ring->head < ring->tail) { - count =sg_dma_len (&atmel_port->sg_rx) - ring->tail; + count =ATMEL_SERIAL_RX_SIZE - ring->tail;tty_insert_flip_string (tport, ring->buf + ring->tail, count); ring->tail =0 ;
@@ -1162,17 +1160,15 @@ static void atmel_rx_from_dma(struct uart_port *port)tty_insert_flip_string (tport, ring->buf + ring->tail, count);/* Wrap ring->head if needed */ -if (ring->head >=sg_dma_len (&atmel_port->sg_rx)) +if (ring->head >=ATMEL_SERIAL_RX_SIZE ) ring->head =0 ; ring->tail = ring->head; port->icount.rx += count; }/* USART retreives ownership of RX DMA buffer */ -dma_sync_sg_for_device (port->dev, - &atmel_port->sg_rx, -1 , -DMA_FROM_DEVICE ); +dma_sync_single_for_device (port->dev, atmel_port->rx_phys, +ATMEL_SERIAL_RX_SIZE ,DMA_FROM_DEVICE );tty_flip_buffer_push (tport);
@@ -1188,7 +1184,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port)struct dma_slave_config config;struct circ_buf *ring;struct dma_chan *chan; -int ret, nent; +int ret; ring = &atmel_port->rx_ring;
@@ -1205,26 +1201,18 @@ static int atmel_prepare_rx_dma(struct uart_port *port) dma_chan_name(atmel_port->chan_rx));spin_lock_init (&atmel_port->lock_rx); -sg_init_table (&atmel_port->sg_rx,1 );/* UART circular rx buffer is an aligned page. */ BUG_ON (!PAGE_ALIGNED (ring->buf)); -sg_set_page (&atmel_port->sg_rx, -virt_to_page (ring->buf), -ATMEL_SERIAL_RX_SIZE , -offset_in_page (ring->buf)); - nent =dma_map_sg (port->dev, - &atmel_port->sg_rx, -1 , -DMA_FROM_DEVICE ); - -if (!nent) { + atmel_port->rx_phys =dma_map_single (port->dev, ring->buf, +ATMEL_SERIAL_RX_SIZE , +DMA_FROM_DEVICE ); + +if (dma_mapping_error (port->dev, atmel_port->rx_phys)) {dev_dbg (port->dev,"need to release resource of dma\n" ); goto chan_err; }else { -dev_dbg (port->dev,"%s: mapped %d@%p to %pad\n" , __func__, -sg_dma_len (&atmel_port->sg_rx), - ring->buf, - &sg_dma_address (&atmel_port->sg_rx)); +dev_dbg (port->dev,"%s: mapped %zu@%p to %pad\n" , __func__, +ATMEL_SERIAL_RX_SIZE , ring->buf, &atmel_port->rx_phys); }/* Configure the slave DMA */
@@ -1245,9 +1233,9 @@ static int atmel_prepare_rx_dma(struct uart_port *port)* each one is half ring buffer size */ desc =dmaengine_prep_dma_cyclic (atmel_port->chan_rx, -sg_dma_address (&atmel_port->sg_rx), -sg_dma_len (&atmel_port->sg_rx), -sg_dma_len (&atmel_port->sg_rx)/2 , + atmel_port->rx_phys, +ATMEL_SERIAL_RX_SIZE , +ATMEL_SERIAL_RX_SIZE /2 ,DMA_DEV_TO_MEM ,DMA_PREP_INTERRUPT );if (!desc) {
Signature · 1 line
2.44.0
Le 19/03/2024 à 10:52, Jiri Slaby (SUSE) a écrit :
Quoted 12 lines
This series switches tty serial layer to use kfifo instead of
circ_buf. Excerpt from the switching patch:
"""
Switch from structcirc_bufto proper kfifo. kfifo provides much better API, esp. when wrap-around of the buffer needs to be taken into account. Look atpl011_dma_tx_refill()orcpm_uart_tx_pump()changes for example.Kfifo API can also fill in scatter-gather DMA structures, so it easier for that use case too. Look at
lpuart_dma_tx()for example. Note that not all drivers can be converted to that (likeatmel_serial), they handle DMA specially.
Quoted 5 lines
Note that usb-serial uses kfifo for TX for ages.
"""This is Request for Testing as I cannot test all the changes (obviously). So please test your HW's serial properly.