Skip to content

Commit bb37101

Browse files
committed
Merge tag 'tty-5.17-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty/serial driver fixes from Greg KH: "Here are some small bug fixes and reverts for reported problems with the tty core and drivers. They include: - revert the fifo use for the 8250 console mode. It caused too many regressions and problems, and had a bug in it as well. This is being reworked and should show up in a later -rc1 release, but it's not ready for 5.17 - rpmsg tty race fix - restore the cyclades.h uapi header file. Turns out a compiler test suite used it for some unknown reason. Bring it back just for the parts that are used by the builder test so they continue to build. No functionality is restored as no one actually has this hardware anymore, nor is it really tested. - stm32 driver fixes - n_gsm flow control fixes - pl011 driver fix - rs485 initialization fix All of these have been in linux-next this week with no reported problems" * tag 'tty-5.17-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: kbuild: remove include/linux/cyclades.h from header file check serial: core: Initialize rs485 RTS polarity already on probe serial: pl011: Fix incorrect rs485 RTS polarity on set_mctrl serial: stm32: fix software flow control transfer serial: stm32: prevent TDR register overwrite when sending x_char tty: n_gsm: fix SW flow control encoding/handling serial: 8250: of: Fix mapped region size when using reg-offset property tty: rpmsg: Fix race condition releasing tty port tty: Partially revert the removal of the Cyclades public API tty: Add support for Brainboxes UC cards. Revert "tty: serial: Use fifo in 8250 console driver"
2 parents 44aa31a + d1ad272 commit bb37101

File tree

10 files changed

+205
-106
lines changed

10 files changed

+205
-106
lines changed

drivers/tty/n_gsm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ static int addr_cnt;
322322
#define GSM1_ESCAPE_BITS 0x20
323323
#define XON 0x11
324324
#define XOFF 0x13
325+
#define ISO_IEC_646_MASK 0x7F
325326

326327
static const struct tty_port_operations gsm_port_ops;
327328

@@ -531,7 +532,8 @@ static int gsm_stuff_frame(const u8 *input, u8 *output, int len)
531532
int olen = 0;
532533
while (len--) {
533534
if (*input == GSM1_SOF || *input == GSM1_ESCAPE
534-
|| *input == XON || *input == XOFF) {
535+
|| (*input & ISO_IEC_646_MASK) == XON
536+
|| (*input & ISO_IEC_646_MASK) == XOFF) {
535537
*output++ = GSM1_ESCAPE;
536538
*output++ = *input++ ^ GSM1_ESCAPE_BITS;
537539
olen++;

drivers/tty/rpmsg_tty.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,17 @@ static int rpmsg_tty_cb(struct rpmsg_device *rpdev, void *data, int len, void *p
5050
static int rpmsg_tty_install(struct tty_driver *driver, struct tty_struct *tty)
5151
{
5252
struct rpmsg_tty_port *cport = idr_find(&tty_idr, tty->index);
53+
struct tty_port *port;
5354

5455
tty->driver_data = cport;
5556

56-
return tty_port_install(&cport->port, driver, tty);
57+
port = tty_port_get(&cport->port);
58+
return tty_port_install(port, driver, tty);
59+
}
60+
61+
static void rpmsg_tty_cleanup(struct tty_struct *tty)
62+
{
63+
tty_port_put(tty->port);
5764
}
5865

5966
static int rpmsg_tty_open(struct tty_struct *tty, struct file *filp)
@@ -106,12 +113,19 @@ static unsigned int rpmsg_tty_write_room(struct tty_struct *tty)
106113
return size;
107114
}
108115

116+
static void rpmsg_tty_hangup(struct tty_struct *tty)
117+
{
118+
tty_port_hangup(tty->port);
119+
}
120+
109121
static const struct tty_operations rpmsg_tty_ops = {
110122
.install = rpmsg_tty_install,
111123
.open = rpmsg_tty_open,
112124
.close = rpmsg_tty_close,
113125
.write = rpmsg_tty_write,
114126
.write_room = rpmsg_tty_write_room,
127+
.hangup = rpmsg_tty_hangup,
128+
.cleanup = rpmsg_tty_cleanup,
115129
};
116130

117131
static struct rpmsg_tty_port *rpmsg_tty_alloc_cport(void)
@@ -137,16 +151,21 @@ static struct rpmsg_tty_port *rpmsg_tty_alloc_cport(void)
137151
return cport;
138152
}
139153

140-
static void rpmsg_tty_release_cport(struct rpmsg_tty_port *cport)
154+
static void rpmsg_tty_destruct_port(struct tty_port *port)
141155
{
156+
struct rpmsg_tty_port *cport = container_of(port, struct rpmsg_tty_port, port);
157+
142158
mutex_lock(&idr_lock);
143159
idr_remove(&tty_idr, cport->id);
144160
mutex_unlock(&idr_lock);
145161

146162
kfree(cport);
147163
}
148164

149-
static const struct tty_port_operations rpmsg_tty_port_ops = { };
165+
static const struct tty_port_operations rpmsg_tty_port_ops = {
166+
.destruct = rpmsg_tty_destruct_port,
167+
};
168+
150169

151170
static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
152171
{
@@ -166,7 +185,8 @@ static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
166185
cport->id, dev);
167186
if (IS_ERR(tty_dev)) {
168187
ret = dev_err_probe(dev, PTR_ERR(tty_dev), "Failed to register tty port\n");
169-
goto err_destroy;
188+
tty_port_put(&cport->port);
189+
return ret;
170190
}
171191

172192
cport->rpdev = rpdev;
@@ -177,12 +197,6 @@ static int rpmsg_tty_probe(struct rpmsg_device *rpdev)
177197
rpdev->src, rpdev->dst, cport->id);
178198

179199
return 0;
180-
181-
err_destroy:
182-
tty_port_destroy(&cport->port);
183-
rpmsg_tty_release_cport(cport);
184-
185-
return ret;
186200
}
187201

188202
static void rpmsg_tty_remove(struct rpmsg_device *rpdev)
@@ -192,13 +206,11 @@ static void rpmsg_tty_remove(struct rpmsg_device *rpdev)
192206
dev_dbg(&rpdev->dev, "Removing rpmsg tty device %d\n", cport->id);
193207

194208
/* User hang up to release the tty */
195-
if (tty_port_initialized(&cport->port))
196-
tty_port_tty_hangup(&cport->port, false);
209+
tty_port_tty_hangup(&cport->port, false);
197210

198211
tty_unregister_device(rpmsg_tty_driver, cport->id);
199212

200-
tty_port_destroy(&cport->port);
201-
rpmsg_tty_release_cport(cport);
213+
tty_port_put(&cport->port);
202214
}
203215

204216
static struct rpmsg_device_id rpmsg_driver_tty_id_table[] = {

drivers/tty/serial/8250/8250_of.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,17 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
8383
port->mapsize = resource_size(&resource);
8484

8585
/* Check for shifted address mapping */
86-
if (of_property_read_u32(np, "reg-offset", &prop) == 0)
86+
if (of_property_read_u32(np, "reg-offset", &prop) == 0) {
87+
if (prop >= port->mapsize) {
88+
dev_warn(&ofdev->dev, "reg-offset %u exceeds region size %pa\n",
89+
prop, &port->mapsize);
90+
ret = -EINVAL;
91+
goto err_unprepare;
92+
}
93+
8794
port->mapbase += prop;
95+
port->mapsize -= prop;
96+
}
8897

8998
port->iotype = UPIO_MEM;
9099
if (of_property_read_u32(np, "reg-io-width", &prop) == 0) {

drivers/tty/serial/8250/8250_pci.c

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4779,16 +4779,112 @@ static const struct pci_device_id serial_pci_tbl[] = {
47794779
{ PCI_VENDOR_ID_INTASHIELD, PCI_DEVICE_ID_INTASHIELD_IS400,
47804780
PCI_ANY_ID, PCI_ANY_ID, 0, 0, /* 135a.0dc0 */
47814781
pbn_b2_4_115200 },
4782+
/* Brainboxes Devices */
47824783
/*
4783-
* BrainBoxes UC-260
4784+
* Brainboxes UC-101
4785+
*/
4786+
{ PCI_VENDOR_ID_INTASHIELD, 0x0BA1,
4787+
PCI_ANY_ID, PCI_ANY_ID,
4788+
0, 0,
4789+
pbn_b2_2_115200 },
4790+
/*
4791+
* Brainboxes UC-235/246
4792+
*/
4793+
{ PCI_VENDOR_ID_INTASHIELD, 0x0AA1,
4794+
PCI_ANY_ID, PCI_ANY_ID,
4795+
0, 0,
4796+
pbn_b2_1_115200 },
4797+
/*
4798+
* Brainboxes UC-257
4799+
*/
4800+
{ PCI_VENDOR_ID_INTASHIELD, 0x0861,
4801+
PCI_ANY_ID, PCI_ANY_ID,
4802+
0, 0,
4803+
pbn_b2_2_115200 },
4804+
/*
4805+
* Brainboxes UC-260/271/701/756
47844806
*/
47854807
{ PCI_VENDOR_ID_INTASHIELD, 0x0D21,
47864808
PCI_ANY_ID, PCI_ANY_ID,
47874809
PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, 0xffff00,
47884810
pbn_b2_4_115200 },
47894811
{ PCI_VENDOR_ID_INTASHIELD, 0x0E34,
47904812
PCI_ANY_ID, PCI_ANY_ID,
4791-
PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, 0xffff00,
4813+
PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, 0xffff00,
4814+
pbn_b2_4_115200 },
4815+
/*
4816+
* Brainboxes UC-268
4817+
*/
4818+
{ PCI_VENDOR_ID_INTASHIELD, 0x0841,
4819+
PCI_ANY_ID, PCI_ANY_ID,
4820+
0, 0,
4821+
pbn_b2_4_115200 },
4822+
/*
4823+
* Brainboxes UC-275/279
4824+
*/
4825+
{ PCI_VENDOR_ID_INTASHIELD, 0x0881,
4826+
PCI_ANY_ID, PCI_ANY_ID,
4827+
0, 0,
4828+
pbn_b2_8_115200 },
4829+
/*
4830+
* Brainboxes UC-302
4831+
*/
4832+
{ PCI_VENDOR_ID_INTASHIELD, 0x08E1,
4833+
PCI_ANY_ID, PCI_ANY_ID,
4834+
0, 0,
4835+
pbn_b2_2_115200 },
4836+
/*
4837+
* Brainboxes UC-310
4838+
*/
4839+
{ PCI_VENDOR_ID_INTASHIELD, 0x08C1,
4840+
PCI_ANY_ID, PCI_ANY_ID,
4841+
0, 0,
4842+
pbn_b2_2_115200 },
4843+
/*
4844+
* Brainboxes UC-313
4845+
*/
4846+
{ PCI_VENDOR_ID_INTASHIELD, 0x08A3,
4847+
PCI_ANY_ID, PCI_ANY_ID,
4848+
0, 0,
4849+
pbn_b2_2_115200 },
4850+
/*
4851+
* Brainboxes UC-320/324
4852+
*/
4853+
{ PCI_VENDOR_ID_INTASHIELD, 0x0A61,
4854+
PCI_ANY_ID, PCI_ANY_ID,
4855+
0, 0,
4856+
pbn_b2_1_115200 },
4857+
/*
4858+
* Brainboxes UC-346
4859+
*/
4860+
{ PCI_VENDOR_ID_INTASHIELD, 0x0B02,
4861+
PCI_ANY_ID, PCI_ANY_ID,
4862+
0, 0,
4863+
pbn_b2_4_115200 },
4864+
/*
4865+
* Brainboxes UC-357
4866+
*/
4867+
{ PCI_VENDOR_ID_INTASHIELD, 0x0A81,
4868+
PCI_ANY_ID, PCI_ANY_ID,
4869+
0, 0,
4870+
pbn_b2_2_115200 },
4871+
{ PCI_VENDOR_ID_INTASHIELD, 0x0A83,
4872+
PCI_ANY_ID, PCI_ANY_ID,
4873+
0, 0,
4874+
pbn_b2_2_115200 },
4875+
/*
4876+
* Brainboxes UC-368
4877+
*/
4878+
{ PCI_VENDOR_ID_INTASHIELD, 0x0C41,
4879+
PCI_ANY_ID, PCI_ANY_ID,
4880+
0, 0,
4881+
pbn_b2_4_115200 },
4882+
/*
4883+
* Brainboxes UC-420/431
4884+
*/
4885+
{ PCI_VENDOR_ID_INTASHIELD, 0x0921,
4886+
PCI_ANY_ID, PCI_ANY_ID,
4887+
0, 0,
47924888
pbn_b2_4_115200 },
47934889
/*
47944890
* Perle PCI-RAS cards

drivers/tty/serial/8250/8250_port.c

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,10 @@ static void serial8250_break_ctl(struct uart_port *port, int break_state)
20562056
serial8250_rpm_put(up);
20572057
}
20582058

2059-
static void wait_for_lsr(struct uart_8250_port *up, int bits)
2059+
/*
2060+
* Wait for transmitter & holding register to empty
2061+
*/
2062+
static void wait_for_xmitr(struct uart_8250_port *up, int bits)
20602063
{
20612064
unsigned int status, tmout = 10000;
20622065

@@ -2073,16 +2076,6 @@ static void wait_for_lsr(struct uart_8250_port *up, int bits)
20732076
udelay(1);
20742077
touch_nmi_watchdog();
20752078
}
2076-
}
2077-
2078-
/*
2079-
* Wait for transmitter & holding register to empty
2080-
*/
2081-
static void wait_for_xmitr(struct uart_8250_port *up, int bits)
2082-
{
2083-
unsigned int tmout;
2084-
2085-
wait_for_lsr(up, bits);
20862079

20872080
/* Wait up to 1s for flow control if necessary */
20882081
if (up->port.flags & UPF_CONS_FLOW) {
@@ -3332,35 +3325,6 @@ static void serial8250_console_restore(struct uart_8250_port *up)
33323325
serial8250_out_MCR(up, UART_MCR_DTR | UART_MCR_RTS);
33333326
}
33343327

3335-
/*
3336-
* Print a string to the serial port using the device FIFO
3337-
*
3338-
* It sends fifosize bytes and then waits for the fifo
3339-
* to get empty.
3340-
*/
3341-
static void serial8250_console_fifo_write(struct uart_8250_port *up,
3342-
const char *s, unsigned int count)
3343-
{
3344-
int i;
3345-
const char *end = s + count;
3346-
unsigned int fifosize = up->port.fifosize;
3347-
bool cr_sent = false;
3348-
3349-
while (s != end) {
3350-
wait_for_lsr(up, UART_LSR_THRE);
3351-
3352-
for (i = 0; i < fifosize && s != end; ++i) {
3353-
if (*s == '\n' && !cr_sent) {
3354-
serial_out(up, UART_TX, '\r');
3355-
cr_sent = true;
3356-
} else {
3357-
serial_out(up, UART_TX, *s++);
3358-
cr_sent = false;
3359-
}
3360-
}
3361-
}
3362-
}
3363-
33643328
/*
33653329
* Print a string to the serial port trying not to disturb
33663330
* any possible real use of the port...
@@ -3376,7 +3340,7 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s,
33763340
struct uart_8250_em485 *em485 = up->em485;
33773341
struct uart_port *port = &up->port;
33783342
unsigned long flags;
3379-
unsigned int ier, use_fifo;
3343+
unsigned int ier;
33803344
int locked = 1;
33813345

33823346
touch_nmi_watchdog();
@@ -3408,20 +3372,7 @@ void serial8250_console_write(struct uart_8250_port *up, const char *s,
34083372
mdelay(port->rs485.delay_rts_before_send);
34093373
}
34103374

3411-
use_fifo = (up->capabilities & UART_CAP_FIFO) &&
3412-
port->fifosize > 1 &&
3413-
(serial_port_in(port, UART_FCR) & UART_FCR_ENABLE_FIFO) &&
3414-
/*
3415-
* After we put a data in the fifo, the controller will send
3416-
* it regardless of the CTS state. Therefore, only use fifo
3417-
* if we don't use control flow.
3418-
*/
3419-
!(up->port.flags & UPF_CONS_FLOW);
3420-
3421-
if (likely(use_fifo))
3422-
serial8250_console_fifo_write(up, s, count);
3423-
else
3424-
uart_console_write(port, s, count, serial8250_console_putchar);
3375+
uart_console_write(port, s, count, serial8250_console_putchar);
34253376

34263377
/*
34273378
* Finally, wait for transmitter to become empty

drivers/tty/serial/amba-pl011.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,9 +1582,6 @@ static void pl011_set_mctrl(struct uart_port *port, unsigned int mctrl)
15821582
container_of(port, struct uart_amba_port, port);
15831583
unsigned int cr;
15841584

1585-
if (port->rs485.flags & SER_RS485_ENABLED)
1586-
mctrl &= ~TIOCM_RTS;
1587-
15881585
cr = pl011_read(uap, REG_CR);
15891586

15901587
#define TIOCMBIT(tiocmbit, uartbit) \
@@ -1808,14 +1805,8 @@ static int pl011_startup(struct uart_port *port)
18081805
cr &= UART011_CR_RTS | UART011_CR_DTR;
18091806
cr |= UART01x_CR_UARTEN | UART011_CR_RXE;
18101807

1811-
if (port->rs485.flags & SER_RS485_ENABLED) {
1812-
if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
1813-
cr &= ~UART011_CR_RTS;
1814-
else
1815-
cr |= UART011_CR_RTS;
1816-
} else {
1808+
if (!(port->rs485.flags & SER_RS485_ENABLED))
18171809
cr |= UART011_CR_TXE;
1818-
}
18191810

18201811
pl011_write(cr, uap, REG_CR);
18211812

0 commit comments

Comments
 (0)