Lines Matching +full:rx +full:- +full:port +full:- +full:mapping

1 // SPDX-License-Identifier: GPL-2.0+
3 * 8250_dma.c - DMA Engine API support for 8250.c
10 #include <linux/dma-mapping.h>
17 struct uart_8250_dma *dma = p->dma; in __dma_tx_complete()
18 struct tty_port *tport = &p->port.state->port; in __dma_tx_complete()
22 dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, in __dma_tx_complete()
25 uart_port_lock_irqsave(&p->port, &flags); in __dma_tx_complete()
27 dma->tx_running = 0; in __dma_tx_complete()
29 uart_xmit_advance(&p->port, dma->tx_size); in __dma_tx_complete()
31 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in __dma_tx_complete()
32 uart_write_wakeup(&p->port); in __dma_tx_complete()
35 if (ret || !dma->tx_running) in __dma_tx_complete()
38 uart_port_unlock_irqrestore(&p->port, flags); in __dma_tx_complete()
43 struct uart_8250_dma *dma = p->dma; in __dma_rx_complete()
44 struct tty_port *tty_port = &p->port.state->port; in __dma_rx_complete()
50 * New DMA Rx can be started during the completion handler before it in __dma_rx_complete()
51 * could acquire port's lock and it might still be ongoing. Don't to in __dma_rx_complete()
54 dma_status = dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state); in __dma_rx_complete()
58 count = dma->rx_size - state.residue; in __dma_rx_complete()
60 tty_insert_flip_string(tty_port, dma->rx_buf, count); in __dma_rx_complete()
61 p->port.icount.rx += count; in __dma_rx_complete()
62 dma->rx_running = 0; in __dma_rx_complete()
70 struct uart_8250_dma *dma = p->dma; in dma_rx_complete()
73 uart_port_lock_irqsave(&p->port, &flags); in dma_rx_complete()
74 if (dma->rx_running) in dma_rx_complete()
79 * changes dma->rx_running. in dma_rx_complete()
81 if (!dma->rx_running && (serial_lsr_in(p) & UART_LSR_DR)) in dma_rx_complete()
82 p->dma->rx_dma(p); in dma_rx_complete()
83 uart_port_unlock_irqrestore(&p->port, flags); in dma_rx_complete()
88 struct uart_8250_dma *dma = p->dma; in serial8250_tx_dma()
89 struct tty_port *tport = &p->port.state->port; in serial8250_tx_dma()
91 struct uart_port *up = &p->port; in serial8250_tx_dma()
97 if (dma->tx_running) { in serial8250_tx_dma()
98 if (up->x_char) { in serial8250_tx_dma()
99 dmaengine_pause(dma->txchan); in serial8250_tx_dma()
101 dmaengine_resume(dma->txchan); in serial8250_tx_dma()
104 } else if (up->x_char) { in serial8250_tx_dma()
108 if (uart_tx_stopped(&p->port) || kfifo_is_empty(&tport->xmit_fifo)) { in serial8250_tx_dma()
117 ret = kfifo_dma_out_prepare_mapped(&tport->xmit_fifo, sgl, ARRAY_SIZE(sgl), in serial8250_tx_dma()
118 UART_XMIT_SIZE, dma->tx_addr); in serial8250_tx_dma()
120 dma->tx_size = 0; in serial8250_tx_dma()
123 dma->tx_size += sg_dma_len(sg); in serial8250_tx_dma()
125 desc = dmaengine_prep_slave_sg(dma->txchan, sgl, ret, in serial8250_tx_dma()
129 ret = -EBUSY; in serial8250_tx_dma()
133 dma->tx_running = 1; in serial8250_tx_dma()
134 desc->callback = __dma_tx_complete; in serial8250_tx_dma()
135 desc->callback_param = p; in serial8250_tx_dma()
137 dma->tx_cookie = dmaengine_submit(desc); in serial8250_tx_dma()
139 dma_sync_single_for_device(dma->txchan->device->dev, dma->tx_addr, in serial8250_tx_dma()
142 dma_async_issue_pending(dma->txchan); in serial8250_tx_dma()
144 dma->tx_err = 0; in serial8250_tx_dma()
148 dma->tx_err = 1; in serial8250_tx_dma()
154 struct uart_8250_dma *dma = p->dma; in serial8250_rx_dma()
157 if (dma->rx_running) in serial8250_rx_dma()
162 desc = dmaengine_prep_slave_single(dma->rxchan, dma->rx_addr, in serial8250_rx_dma()
163 dma->rx_size, DMA_DEV_TO_MEM, in serial8250_rx_dma()
166 return -EBUSY; in serial8250_rx_dma()
168 dma->rx_running = 1; in serial8250_rx_dma()
169 desc->callback = dma_rx_complete; in serial8250_rx_dma()
170 desc->callback_param = p; in serial8250_rx_dma()
172 dma->rx_cookie = dmaengine_submit(desc); in serial8250_rx_dma()
174 dma_async_issue_pending(dma->rxchan); in serial8250_rx_dma()
181 struct uart_8250_dma *dma = p->dma; in serial8250_rx_dma_flush()
183 if (dma->rx_running) { in serial8250_rx_dma_flush()
184 dmaengine_pause(dma->rxchan); in serial8250_rx_dma_flush()
186 dmaengine_terminate_async(dma->rxchan); in serial8250_rx_dma_flush()
193 struct uart_8250_dma *dma = p->dma; in serial8250_request_dma()
194 phys_addr_t rx_dma_addr = dma->rx_dma_addr ? in serial8250_request_dma()
195 dma->rx_dma_addr : p->port.mapbase; in serial8250_request_dma()
196 phys_addr_t tx_dma_addr = dma->tx_dma_addr ? in serial8250_request_dma()
197 dma->tx_dma_addr : p->port.mapbase; in serial8250_request_dma()
203 dma->rxconf.direction = DMA_DEV_TO_MEM; in serial8250_request_dma()
204 dma->rxconf.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; in serial8250_request_dma()
205 dma->rxconf.src_addr = rx_dma_addr + UART_RX; in serial8250_request_dma()
207 dma->txconf.direction = DMA_MEM_TO_DEV; in serial8250_request_dma()
208 dma->txconf.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; in serial8250_request_dma()
209 dma->txconf.dst_addr = tx_dma_addr + UART_TX; in serial8250_request_dma()
214 /* Get a channel for RX */ in serial8250_request_dma()
215 dma->rxchan = dma_request_slave_channel_compat(mask, in serial8250_request_dma()
216 dma->fn, dma->rx_param, in serial8250_request_dma()
217 p->port.dev, "rx"); in serial8250_request_dma()
218 if (!dma->rxchan) in serial8250_request_dma()
219 return -ENODEV; in serial8250_request_dma()
221 /* 8250 rx dma requires dmaengine driver to support pause/terminate */ in serial8250_request_dma()
222 ret = dma_get_slave_caps(dma->rxchan, &caps); in serial8250_request_dma()
227 ret = -EINVAL; in serial8250_request_dma()
231 dmaengine_slave_config(dma->rxchan, &dma->rxconf); in serial8250_request_dma()
234 dma->txchan = dma_request_slave_channel_compat(mask, in serial8250_request_dma()
235 dma->fn, dma->tx_param, in serial8250_request_dma()
236 p->port.dev, "tx"); in serial8250_request_dma()
237 if (!dma->txchan) { in serial8250_request_dma()
238 ret = -ENODEV; in serial8250_request_dma()
243 ret = dma_get_slave_caps(dma->txchan, &caps); in serial8250_request_dma()
247 ret = -EINVAL; in serial8250_request_dma()
251 dmaengine_slave_config(dma->txchan, &dma->txconf); in serial8250_request_dma()
253 /* RX buffer */ in serial8250_request_dma()
254 if (!dma->rx_size) in serial8250_request_dma()
255 dma->rx_size = PAGE_SIZE; in serial8250_request_dma()
257 dma->rx_buf = dma_alloc_coherent(dma->rxchan->device->dev, dma->rx_size, in serial8250_request_dma()
258 &dma->rx_addr, GFP_KERNEL); in serial8250_request_dma()
259 if (!dma->rx_buf) { in serial8250_request_dma()
260 ret = -ENOMEM; in serial8250_request_dma()
265 dma->tx_addr = dma_map_single(dma->txchan->device->dev, in serial8250_request_dma()
266 p->port.state->port.xmit_buf, in serial8250_request_dma()
269 if (dma_mapping_error(dma->txchan->device->dev, dma->tx_addr)) { in serial8250_request_dma()
270 dma_free_coherent(dma->rxchan->device->dev, dma->rx_size, in serial8250_request_dma()
271 dma->rx_buf, dma->rx_addr); in serial8250_request_dma()
272 ret = -ENOMEM; in serial8250_request_dma()
276 dev_dbg_ratelimited(p->port.dev, "got both dma channels\n"); in serial8250_request_dma()
280 dma_release_channel(dma->txchan); in serial8250_request_dma()
282 dma_release_channel(dma->rxchan); in serial8250_request_dma()
289 struct uart_8250_dma *dma = p->dma; in serial8250_release_dma()
294 /* Release RX resources */ in serial8250_release_dma()
295 dmaengine_terminate_sync(dma->rxchan); in serial8250_release_dma()
296 dma_free_coherent(dma->rxchan->device->dev, dma->rx_size, dma->rx_buf, in serial8250_release_dma()
297 dma->rx_addr); in serial8250_release_dma()
298 dma_release_channel(dma->rxchan); in serial8250_release_dma()
299 dma->rxchan = NULL; in serial8250_release_dma()
302 dmaengine_terminate_sync(dma->txchan); in serial8250_release_dma()
303 dma_unmap_single(dma->txchan->device->dev, dma->tx_addr, in serial8250_release_dma()
305 dma_release_channel(dma->txchan); in serial8250_release_dma()
306 dma->txchan = NULL; in serial8250_release_dma()
307 dma->tx_running = 0; in serial8250_release_dma()
309 dev_dbg_ratelimited(p->port.dev, "dma channels released\n"); in serial8250_release_dma()