Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'tty-5.18-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty

Pull tty/serial fixes from Greg KH:
"Here are some small serial driver fixes, and a larger number of GSM
line discipline fixes for 5.18-rc5.

These include:

- lots of tiny n_gsm fixes for issues to resolve a number of reported
problems. Seems that people are starting to actually use this code
again.

- 8250 driver fixes for some devices

- imx serial driver fix

- amba-pl011 driver fix

All of these have been in linux-next for a while with no reported
issues"

* tag 'tty-5.18-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (27 commits)
tty: n_gsm: fix sometimes uninitialized warning in gsm_dlci_modem_output()
serial: 8250: Correct the clock for EndRun PTP/1588 PCIe device
serial: 8250: Also set sticky MCR bits in console restoration
tty: n_gsm: fix software flow control handling
tty: n_gsm: fix invalid use of MSC in advanced option
tty: n_gsm: fix broken virtual tty handling
Revert "serial: sc16is7xx: Clear RS485 bits in the shutdown"
tty: n_gsm: fix missing update of modem controls after DLCI open
serial: 8250: Fix runtime PM for start_tx() for empty buffer
serial: imx: fix overrun interrupts in DMA mode
serial: amba-pl011: do not time out prematurely when draining tx fifo
tty: n_gsm: fix incorrect UA handling
tty: n_gsm: fix reset fifo race condition
tty: n_gsm: fix missing tty wakeup in convergence layer type 2
tty: n_gsm: fix wrong signal octets encoding in MSC
tty: n_gsm: fix wrong command frame length field encoding
tty: n_gsm: fix wrong command retry handling
tty: n_gsm: fix missing explicit ldisc flush
tty: n_gsm: fix wrong DLCI release order
tty: n_gsm: fix insufficient txframe size
...

+298 -220
+281 -206
drivers/tty/n_gsm.c
··· 73 73 */ 74 74 #define MAX_MRU 1500 75 75 #define MAX_MTU 1500 76 + /* SOF, ADDR, CTRL, LEN1, LEN2, ..., FCS, EOF */ 77 + #define PROT_OVERHEAD 7 76 78 #define GSM_NET_TX_TIMEOUT (HZ*10) 77 79 78 80 /* ··· 221 219 int encoding; 222 220 u8 control; 223 221 u8 fcs; 224 - u8 received_fcs; 225 222 u8 *txframe; /* TX framing buffer */ 226 223 227 224 /* Method for the receiver side */ ··· 232 231 int initiator; /* Did we initiate connection */ 233 232 bool dead; /* Has the mux been shut down */ 234 233 struct gsm_dlci *dlci[NUM_DLCI]; 234 + int old_c_iflag; /* termios c_iflag value before attach */ 235 235 bool constipated; /* Asked by remote to shut up */ 236 236 237 237 spinlock_t tx_lock; ··· 273 271 274 272 static struct tty_driver *gsm_tty_driver; 275 273 276 - /* Save dlci open address */ 277 - static int addr_open[256] = { 0 }; 278 - /* Save dlci open count */ 279 - static int addr_cnt; 280 274 /* 281 275 * This section of the driver logic implements the GSM encodings 282 276 * both the basic and the 'advanced'. Reliable transport is not ··· 367 369 #define GOOD_FCS 0xCF 368 370 369 371 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len); 372 + static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk); 370 373 371 374 /** 372 375 * gsm_fcs_add - update FCS ··· 831 832 break; 832 833 case 2: /* Unstructed with modem bits. 833 834 Always one byte as we never send inline break data */ 834 - *dp++ = gsm_encode_modem(dlci); 835 + *dp++ = (gsm_encode_modem(dlci) << 1) | EA; 835 836 break; 836 837 } 837 838 WARN_ON(kfifo_out_locked(&dlci->fifo, dp , len, &dlci->lock) != len); ··· 912 913 dev_kfree_skb_any(dlci->skb); 913 914 dlci->skb = NULL; 914 915 } 916 + return size; 917 + } 918 + 919 + /** 920 + * gsm_dlci_modem_output - try and push modem status out of a DLCI 921 + * @gsm: mux 922 + * @dlci: the DLCI to pull modem status from 923 + * @brk: break signal 924 + * 925 + * Push an empty frame in to the transmit queue to update the modem status 926 + * bits and to transmit an optional break. 927 + * 928 + * Caller must hold the tx_lock of the mux. 929 + */ 930 + 931 + static int gsm_dlci_modem_output(struct gsm_mux *gsm, struct gsm_dlci *dlci, 932 + u8 brk) 933 + { 934 + u8 *dp = NULL; 935 + struct gsm_msg *msg; 936 + int size = 0; 937 + 938 + /* for modem bits without break data */ 939 + switch (dlci->adaption) { 940 + case 1: /* Unstructured */ 941 + break; 942 + case 2: /* Unstructured with modem bits. */ 943 + size++; 944 + if (brk > 0) 945 + size++; 946 + break; 947 + default: 948 + pr_err("%s: unsupported adaption %d\n", __func__, 949 + dlci->adaption); 950 + return -EINVAL; 951 + } 952 + 953 + msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); 954 + if (!msg) { 955 + pr_err("%s: gsm_data_alloc error", __func__); 956 + return -ENOMEM; 957 + } 958 + dp = msg->data; 959 + switch (dlci->adaption) { 960 + case 1: /* Unstructured */ 961 + break; 962 + case 2: /* Unstructured with modem bits. */ 963 + if (brk == 0) { 964 + *dp++ = (gsm_encode_modem(dlci) << 1) | EA; 965 + } else { 966 + *dp++ = gsm_encode_modem(dlci) << 1; 967 + *dp++ = (brk << 4) | 2 | EA; /* Length, Break, EA */ 968 + } 969 + break; 970 + default: 971 + /* Handled above */ 972 + break; 973 + } 974 + 975 + __gsm_data_queue(dlci, msg); 915 976 return size; 916 977 } 917 978 ··· 1152 1093 { 1153 1094 unsigned int addr = 0; 1154 1095 unsigned int modem = 0; 1155 - unsigned int brk = 0; 1156 1096 struct gsm_dlci *dlci; 1157 1097 int len = clen; 1158 1098 int slen; ··· 1181 1123 return; 1182 1124 } 1183 1125 len--; 1184 - if (len > 0) { 1185 - while (gsm_read_ea(&brk, *dp++) == 0) { 1186 - len--; 1187 - if (len == 0) 1188 - return; 1189 - } 1190 - modem <<= 7; 1191 - modem |= (brk & 0x7f); 1192 - } 1193 1126 tty = tty_port_tty_get(&dlci->port); 1194 - gsm_process_modem(tty, dlci, modem, slen); 1127 + gsm_process_modem(tty, dlci, modem, slen - len); 1195 1128 if (tty) { 1196 1129 tty_wakeup(tty); 1197 1130 tty_kref_put(tty); ··· 1242 1193 } 1243 1194 1244 1195 static void gsm_dlci_begin_close(struct gsm_dlci *dlci); 1245 - static void gsm_dlci_close(struct gsm_dlci *dlci); 1246 1196 1247 1197 /** 1248 1198 * gsm_control_message - DLCI 0 control processing ··· 1260 1212 { 1261 1213 u8 buf[1]; 1262 1214 unsigned long flags; 1263 - struct gsm_dlci *dlci; 1264 - int i; 1265 - int address; 1266 1215 1267 1216 switch (command) { 1268 1217 case CMD_CLD: { 1269 - if (addr_cnt > 0) { 1270 - for (i = 0; i < addr_cnt; i++) { 1271 - address = addr_open[i]; 1272 - dlci = gsm->dlci[address]; 1273 - gsm_dlci_close(dlci); 1274 - addr_open[i] = 0; 1275 - } 1276 - } 1218 + struct gsm_dlci *dlci = gsm->dlci[0]; 1277 1219 /* Modem wishes to close down */ 1278 - dlci = gsm->dlci[0]; 1279 1220 if (dlci) { 1280 1221 dlci->dead = true; 1281 1222 gsm->dead = true; 1282 - gsm_dlci_close(dlci); 1283 - addr_cnt = 0; 1284 - gsm_response(gsm, 0, UA|PF); 1223 + gsm_dlci_begin_close(dlci); 1285 1224 } 1286 1225 } 1287 1226 break; ··· 1361 1326 1362 1327 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) 1363 1328 { 1364 - struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->len + 1, gsm->ftype); 1329 + struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->len + 2, gsm->ftype); 1365 1330 if (msg == NULL) 1366 1331 return; 1367 - msg->data[0] = (ctrl->cmd << 1) | 2 | EA; /* command */ 1368 - memcpy(msg->data + 1, ctrl->data, ctrl->len); 1332 + msg->data[0] = (ctrl->cmd << 1) | CR | EA; /* command */ 1333 + msg->data[1] = (ctrl->len << 1) | EA; 1334 + memcpy(msg->data + 2, ctrl->data, ctrl->len); 1369 1335 gsm_data_queue(gsm->dlci[0], msg); 1370 1336 } 1371 1337 ··· 1389 1353 spin_lock_irqsave(&gsm->control_lock, flags); 1390 1354 ctrl = gsm->pending_cmd; 1391 1355 if (ctrl) { 1392 - gsm->cretries--; 1393 1356 if (gsm->cretries == 0) { 1394 1357 gsm->pending_cmd = NULL; 1395 1358 ctrl->error = -ETIMEDOUT; ··· 1397 1362 wake_up(&gsm->event); 1398 1363 return; 1399 1364 } 1365 + gsm->cretries--; 1400 1366 gsm_control_transmit(gsm, ctrl); 1401 1367 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); 1402 1368 } ··· 1438 1402 1439 1403 /* If DLCI0 is in ADM mode skip retries, it won't respond */ 1440 1404 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) 1441 - gsm->cretries = 1; 1405 + gsm->cretries = 0; 1442 1406 else 1443 1407 gsm->cretries = gsm->n2; 1444 1408 ··· 1486 1450 1487 1451 static void gsm_dlci_close(struct gsm_dlci *dlci) 1488 1452 { 1453 + unsigned long flags; 1454 + 1489 1455 del_timer(&dlci->t1); 1490 1456 if (debug & 8) 1491 1457 pr_debug("DLCI %d goes closed.\n", dlci->addr); 1492 1458 dlci->state = DLCI_CLOSED; 1493 1459 if (dlci->addr != 0) { 1494 1460 tty_port_tty_hangup(&dlci->port, false); 1461 + spin_lock_irqsave(&dlci->lock, flags); 1495 1462 kfifo_reset(&dlci->fifo); 1463 + spin_unlock_irqrestore(&dlci->lock, flags); 1496 1464 /* Ensure that gsmtty_open() can return. */ 1497 1465 tty_port_set_initialized(&dlci->port, 0); 1498 1466 wake_up_interruptible(&dlci->port.open_wait); 1499 1467 } else 1500 1468 dlci->gsm->dead = true; 1501 - /* Unregister gsmtty driver,report gsmtty dev remove uevent for user */ 1502 - tty_unregister_device(gsm_tty_driver, dlci->addr); 1503 1469 wake_up(&dlci->gsm->event); 1504 1470 /* A DLCI 0 close is a MUX termination so we need to kick that 1505 1471 back to userspace somehow */ ··· 1523 1485 dlci->state = DLCI_OPEN; 1524 1486 if (debug & 8) 1525 1487 pr_debug("DLCI %d goes open.\n", dlci->addr); 1526 - /* Register gsmtty driver,report gsmtty dev add uevent for user */ 1527 - tty_register_device(gsm_tty_driver, dlci->addr, NULL); 1488 + /* Send current modem state */ 1489 + if (dlci->addr) 1490 + gsm_modem_update(dlci, 0); 1528 1491 wake_up(&dlci->gsm->event); 1529 1492 } 1530 1493 ··· 1662 1623 tty = tty_port_tty_get(port); 1663 1624 if (tty) { 1664 1625 gsm_process_modem(tty, dlci, modem, slen); 1626 + tty_wakeup(tty); 1665 1627 tty_kref_put(tty); 1666 1628 } 1667 1629 fallthrough; ··· 1833 1793 struct gsm_dlci *dlci; 1834 1794 u8 cr; 1835 1795 int address; 1836 - int i, j, k, address_tmp; 1837 - /* We have to sneak a look at the packet body to do the FCS. 1838 - A somewhat layering violation in the spec */ 1839 1796 1840 - if ((gsm->control & ~PF) == UI) 1841 - gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, gsm->len); 1842 - if (gsm->encoding == 0) { 1843 - /* WARNING: gsm->received_fcs is used for 1844 - gsm->encoding = 0 only. 1845 - In this case it contain the last piece of data 1846 - required to generate final CRC */ 1847 - gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->received_fcs); 1848 - } 1849 1797 if (gsm->fcs != GOOD_FCS) { 1850 1798 gsm->bad_fcs++; 1851 1799 if (debug & 4) ··· 1864 1836 else { 1865 1837 gsm_response(gsm, address, UA|PF); 1866 1838 gsm_dlci_open(dlci); 1867 - /* Save dlci open address */ 1868 - if (address) { 1869 - addr_open[addr_cnt] = address; 1870 - addr_cnt++; 1871 - } 1872 1839 } 1873 1840 break; 1874 1841 case DISC|PF: ··· 1874 1851 return; 1875 1852 } 1876 1853 /* Real close complete */ 1877 - if (!address) { 1878 - if (addr_cnt > 0) { 1879 - for (i = 0; i < addr_cnt; i++) { 1880 - address = addr_open[i]; 1881 - dlci = gsm->dlci[address]; 1882 - gsm_dlci_close(dlci); 1883 - addr_open[i] = 0; 1884 - } 1885 - } 1886 - dlci = gsm->dlci[0]; 1887 - gsm_dlci_close(dlci); 1888 - addr_cnt = 0; 1889 - gsm_response(gsm, 0, UA|PF); 1890 - } else { 1891 - gsm_response(gsm, address, UA|PF); 1892 - gsm_dlci_close(dlci); 1893 - /* clear dlci address */ 1894 - for (j = 0; j < addr_cnt; j++) { 1895 - address_tmp = addr_open[j]; 1896 - if (address_tmp == address) { 1897 - for (k = j; k < addr_cnt; k++) 1898 - addr_open[k] = addr_open[k+1]; 1899 - addr_cnt--; 1900 - break; 1901 - } 1902 - } 1903 - } 1854 + gsm_response(gsm, address, UA|PF); 1855 + gsm_dlci_close(dlci); 1904 1856 break; 1905 - case UA: 1906 1857 case UA|PF: 1907 1858 if (cr == 0 || dlci == NULL) 1908 1859 break; ··· 1990 1993 break; 1991 1994 case GSM_DATA: /* Data */ 1992 1995 gsm->buf[gsm->count++] = c; 1993 - if (gsm->count == gsm->len) 1996 + if (gsm->count == gsm->len) { 1997 + /* Calculate final FCS for UI frames over all data */ 1998 + if ((gsm->control & ~PF) != UIH) { 1999 + gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, 2000 + gsm->count); 2001 + } 1994 2002 gsm->state = GSM_FCS; 2003 + } 1995 2004 break; 1996 2005 case GSM_FCS: /* FCS follows the packet */ 1997 - gsm->received_fcs = c; 1998 - gsm_queue(gsm); 2006 + gsm->fcs = gsm_fcs_add(gsm->fcs, c); 1999 2007 gsm->state = GSM_SSOF; 2000 2008 break; 2001 2009 case GSM_SSOF: 2002 - if (c == GSM0_SOF) { 2003 - gsm->state = GSM_SEARCH; 2004 - break; 2005 - } 2010 + gsm->state = GSM_SEARCH; 2011 + if (c == GSM0_SOF) 2012 + gsm_queue(gsm); 2013 + else 2014 + gsm->bad_size++; 2006 2015 break; 2007 2016 default: 2008 2017 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); ··· 2026 2023 2027 2024 static void gsm1_receive(struct gsm_mux *gsm, unsigned char c) 2028 2025 { 2026 + /* handle XON/XOFF */ 2027 + if ((c & ISO_IEC_646_MASK) == XON) { 2028 + gsm->constipated = true; 2029 + return; 2030 + } else if ((c & ISO_IEC_646_MASK) == XOFF) { 2031 + gsm->constipated = false; 2032 + /* Kick the link in case it is idling */ 2033 + gsm_data_kick(gsm, NULL); 2034 + return; 2035 + } 2029 2036 if (c == GSM1_SOF) { 2030 - /* EOF is only valid in frame if we have got to the data state 2031 - and received at least one byte (the FCS) */ 2032 - if (gsm->state == GSM_DATA && gsm->count) { 2033 - /* Extract the FCS */ 2037 + /* EOF is only valid in frame if we have got to the data state */ 2038 + if (gsm->state == GSM_DATA) { 2039 + if (gsm->count < 1) { 2040 + /* Missing FSC */ 2041 + gsm->malformed++; 2042 + gsm->state = GSM_START; 2043 + return; 2044 + } 2045 + /* Remove the FCS from data */ 2034 2046 gsm->count--; 2047 + if ((gsm->control & ~PF) != UIH) { 2048 + /* Calculate final FCS for UI frames over all 2049 + * data but FCS 2050 + */ 2051 + gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, 2052 + gsm->count); 2053 + } 2054 + /* Add the FCS itself to test against GOOD_FCS */ 2035 2055 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); 2036 2056 gsm->len = gsm->count; 2037 2057 gsm_queue(gsm); ··· 2063 2037 } 2064 2038 /* Any partial frame was a runt so go back to start */ 2065 2039 if (gsm->state != GSM_START) { 2066 - gsm->malformed++; 2040 + if (gsm->state != GSM_SEARCH) 2041 + gsm->malformed++; 2067 2042 gsm->state = GSM_START; 2068 2043 } 2069 2044 /* A SOF in GSM_START means we are still reading idling or ··· 2133 2106 gsm->io_error++; 2134 2107 } 2135 2108 2136 - static int gsm_disconnect(struct gsm_mux *gsm) 2137 - { 2138 - struct gsm_dlci *dlci = gsm->dlci[0]; 2139 - struct gsm_control *gc; 2140 - 2141 - if (!dlci) 2142 - return 0; 2143 - 2144 - /* In theory disconnecting DLCI 0 is sufficient but for some 2145 - modems this is apparently not the case. */ 2146 - gc = gsm_control_send(gsm, CMD_CLD, NULL, 0); 2147 - if (gc) 2148 - gsm_control_wait(gsm, gc); 2149 - 2150 - del_timer_sync(&gsm->t2_timer); 2151 - /* Now we are sure T2 has stopped */ 2152 - 2153 - gsm_dlci_begin_close(dlci); 2154 - wait_event_interruptible(gsm->event, 2155 - dlci->state == DLCI_CLOSED); 2156 - 2157 - if (signal_pending(current)) 2158 - return -EINTR; 2159 - 2160 - return 0; 2161 - } 2162 - 2163 2109 /** 2164 2110 * gsm_cleanup_mux - generic GSM protocol cleanup 2165 2111 * @gsm: our mux 2112 + * @disc: disconnect link? 2166 2113 * 2167 2114 * Clean up the bits of the mux which are the same for all framing 2168 2115 * protocols. Remove the mux from the mux table, stop all the timers 2169 2116 * and then shut down each device hanging up the channels as we go. 2170 2117 */ 2171 2118 2172 - static void gsm_cleanup_mux(struct gsm_mux *gsm) 2119 + static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) 2173 2120 { 2174 2121 int i; 2175 2122 struct gsm_dlci *dlci = gsm->dlci[0]; 2176 2123 struct gsm_msg *txq, *ntxq; 2177 2124 2178 2125 gsm->dead = true; 2179 - 2180 - spin_lock(&gsm_mux_lock); 2181 - for (i = 0; i < MAX_MUX; i++) { 2182 - if (gsm_mux[i] == gsm) { 2183 - gsm_mux[i] = NULL; 2184 - break; 2185 - } 2186 - } 2187 - spin_unlock(&gsm_mux_lock); 2188 - /* open failed before registering => nothing to do */ 2189 - if (i == MAX_MUX) 2190 - return; 2191 - 2192 - del_timer_sync(&gsm->t2_timer); 2193 - /* Now we are sure T2 has stopped */ 2194 - if (dlci) 2195 - dlci->dead = true; 2196 - 2197 - /* Free up any link layer users */ 2198 2126 mutex_lock(&gsm->mutex); 2199 - for (i = 0; i < NUM_DLCI; i++) 2127 + 2128 + if (dlci) { 2129 + if (disc && dlci->state != DLCI_CLOSED) { 2130 + gsm_dlci_begin_close(dlci); 2131 + wait_event(gsm->event, dlci->state == DLCI_CLOSED); 2132 + } 2133 + dlci->dead = true; 2134 + } 2135 + 2136 + /* Finish outstanding timers, making sure they are done */ 2137 + del_timer_sync(&gsm->t2_timer); 2138 + 2139 + /* Free up any link layer users and finally the control channel */ 2140 + for (i = NUM_DLCI - 1; i >= 0; i--) 2200 2141 if (gsm->dlci[i]) 2201 2142 gsm_dlci_release(gsm->dlci[i]); 2202 2143 mutex_unlock(&gsm->mutex); 2203 2144 /* Now wipe the queues */ 2145 + tty_ldisc_flush(gsm->tty); 2204 2146 list_for_each_entry_safe(txq, ntxq, &gsm->tx_list, list) 2205 2147 kfree(txq); 2206 2148 INIT_LIST_HEAD(&gsm->tx_list); ··· 2187 2191 static int gsm_activate_mux(struct gsm_mux *gsm) 2188 2192 { 2189 2193 struct gsm_dlci *dlci; 2190 - int i = 0; 2191 2194 2192 2195 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); 2193 2196 init_waitqueue_head(&gsm->event); ··· 2197 2202 gsm->receive = gsm0_receive; 2198 2203 else 2199 2204 gsm->receive = gsm1_receive; 2200 - 2201 - spin_lock(&gsm_mux_lock); 2202 - for (i = 0; i < MAX_MUX; i++) { 2203 - if (gsm_mux[i] == NULL) { 2204 - gsm->num = i; 2205 - gsm_mux[i] = gsm; 2206 - break; 2207 - } 2208 - } 2209 - spin_unlock(&gsm_mux_lock); 2210 - if (i == MAX_MUX) 2211 - return -EBUSY; 2212 2205 2213 2206 dlci = gsm_dlci_alloc(gsm, 0); 2214 2207 if (dlci == NULL) ··· 2213 2230 */ 2214 2231 static void gsm_free_mux(struct gsm_mux *gsm) 2215 2232 { 2233 + int i; 2234 + 2235 + for (i = 0; i < MAX_MUX; i++) { 2236 + if (gsm == gsm_mux[i]) { 2237 + gsm_mux[i] = NULL; 2238 + break; 2239 + } 2240 + } 2241 + mutex_destroy(&gsm->mutex); 2216 2242 kfree(gsm->txframe); 2217 2243 kfree(gsm->buf); 2218 2244 kfree(gsm); ··· 2241 2249 2242 2250 static inline void mux_get(struct gsm_mux *gsm) 2243 2251 { 2252 + unsigned long flags; 2253 + 2254 + spin_lock_irqsave(&gsm_mux_lock, flags); 2244 2255 kref_get(&gsm->ref); 2256 + spin_unlock_irqrestore(&gsm_mux_lock, flags); 2245 2257 } 2246 2258 2247 2259 static inline void mux_put(struct gsm_mux *gsm) 2248 2260 { 2261 + unsigned long flags; 2262 + 2263 + spin_lock_irqsave(&gsm_mux_lock, flags); 2249 2264 kref_put(&gsm->ref, gsm_free_muxr); 2265 + spin_unlock_irqrestore(&gsm_mux_lock, flags); 2250 2266 } 2251 2267 2252 2268 static inline unsigned int mux_num_to_base(struct gsm_mux *gsm) ··· 2275 2275 2276 2276 static struct gsm_mux *gsm_alloc_mux(void) 2277 2277 { 2278 + int i; 2278 2279 struct gsm_mux *gsm = kzalloc(sizeof(struct gsm_mux), GFP_KERNEL); 2279 2280 if (gsm == NULL) 2280 2281 return NULL; ··· 2284 2283 kfree(gsm); 2285 2284 return NULL; 2286 2285 } 2287 - gsm->txframe = kmalloc(2 * MAX_MRU + 2, GFP_KERNEL); 2286 + gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); 2288 2287 if (gsm->txframe == NULL) { 2289 2288 kfree(gsm->buf); 2290 2289 kfree(gsm); ··· 2304 2303 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ 2305 2304 gsm->mtu = 64; 2306 2305 gsm->dead = true; /* Avoid early tty opens */ 2306 + 2307 + /* Store the instance to the mux array or abort if no space is 2308 + * available. 2309 + */ 2310 + spin_lock(&gsm_mux_lock); 2311 + for (i = 0; i < MAX_MUX; i++) { 2312 + if (!gsm_mux[i]) { 2313 + gsm_mux[i] = gsm; 2314 + gsm->num = i; 2315 + break; 2316 + } 2317 + } 2318 + spin_unlock(&gsm_mux_lock); 2319 + if (i == MAX_MUX) { 2320 + mutex_destroy(&gsm->mutex); 2321 + kfree(gsm->txframe); 2322 + kfree(gsm->buf); 2323 + kfree(gsm); 2324 + return NULL; 2325 + } 2307 2326 2308 2327 return gsm; 2309 2328 } ··· 2360 2339 /* Check the MRU/MTU range looks sane */ 2361 2340 if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8) 2362 2341 return -EINVAL; 2363 - if (c->n2 < 3) 2342 + if (c->n2 > 255) 2364 2343 return -EINVAL; 2365 2344 if (c->encapsulation > 1) /* Basic, advanced, no I */ 2366 2345 return -EINVAL; ··· 2391 2370 2392 2371 /* 2393 2372 * Close down what is needed, restart and initiate the new 2394 - * configuration 2373 + * configuration. On the first time there is no DLCI[0] 2374 + * and closing or cleaning up is not necessary. 2395 2375 */ 2396 - 2397 - if (gsm->initiator && (need_close || need_restart)) { 2398 - int ret; 2399 - 2400 - ret = gsm_disconnect(gsm); 2401 - 2402 - if (ret) 2403 - return ret; 2404 - } 2405 - if (need_restart) 2406 - gsm_cleanup_mux(gsm); 2376 + if (need_close || need_restart) 2377 + gsm_cleanup_mux(gsm, true); 2407 2378 2408 2379 gsm->initiator = c->initiator; 2409 2380 gsm->mru = c->mru; ··· 2463 2450 int ret, i; 2464 2451 2465 2452 gsm->tty = tty_kref_get(tty); 2453 + /* Turn off tty XON/XOFF handling to handle it explicitly. */ 2454 + gsm->old_c_iflag = tty->termios.c_iflag; 2455 + tty->termios.c_iflag &= (IXON | IXOFF); 2466 2456 ret = gsm_activate_mux(gsm); 2467 2457 if (ret != 0) 2468 2458 tty_kref_put(gsm->tty); 2469 2459 else { 2470 2460 /* Don't register device 0 - this is the control channel and not 2471 2461 a usable tty interface */ 2472 - if (gsm->initiator) { 2473 - base = mux_num_to_base(gsm); /* Base for this MUX */ 2474 - for (i = 1; i < NUM_DLCI; i++) { 2475 - struct device *dev; 2462 + base = mux_num_to_base(gsm); /* Base for this MUX */ 2463 + for (i = 1; i < NUM_DLCI; i++) { 2464 + struct device *dev; 2476 2465 2477 - dev = tty_register_device(gsm_tty_driver, 2466 + dev = tty_register_device(gsm_tty_driver, 2478 2467 base + i, NULL); 2479 - if (IS_ERR(dev)) { 2480 - for (i--; i >= 1; i--) 2481 - tty_unregister_device(gsm_tty_driver, 2482 - base + i); 2483 - return PTR_ERR(dev); 2484 - } 2468 + if (IS_ERR(dev)) { 2469 + for (i--; i >= 1; i--) 2470 + tty_unregister_device(gsm_tty_driver, 2471 + base + i); 2472 + return PTR_ERR(dev); 2485 2473 } 2486 2474 } 2487 2475 } ··· 2504 2490 int i; 2505 2491 2506 2492 WARN_ON(tty != gsm->tty); 2507 - if (gsm->initiator) { 2508 - for (i = 1; i < NUM_DLCI; i++) 2509 - tty_unregister_device(gsm_tty_driver, base + i); 2510 - } 2511 - gsm_cleanup_mux(gsm); 2493 + for (i = 1; i < NUM_DLCI; i++) 2494 + tty_unregister_device(gsm_tty_driver, base + i); 2495 + /* Restore tty XON/XOFF handling. */ 2496 + gsm->tty->termios.c_iflag = gsm->old_c_iflag; 2512 2497 tty_kref_put(gsm->tty); 2513 2498 gsm->tty = NULL; 2514 2499 } ··· 2572 2559 { 2573 2560 struct gsm_mux *gsm = tty->disc_data; 2574 2561 2562 + /* The ldisc locks and closes the port before calling our close. This 2563 + * means we have no way to do a proper disconnect. We will not bother 2564 + * to do one. 2565 + */ 2566 + gsm_cleanup_mux(gsm, false); 2567 + 2575 2568 gsmld_detach_gsm(tty, gsm); 2576 2569 2577 2570 gsmld_flush_buffer(tty); ··· 2616 2597 2617 2598 ret = gsmld_attach_gsm(tty, gsm); 2618 2599 if (ret != 0) { 2619 - gsm_cleanup_mux(gsm); 2600 + gsm_cleanup_mux(gsm, false); 2620 2601 mux_put(gsm); 2621 2602 } 2622 2603 return ret; ··· 2973 2954 2974 2955 #define TX_SIZE 512 2975 2956 2976 - static int gsmtty_modem_update(struct gsm_dlci *dlci, u8 brk) 2957 + /** 2958 + * gsm_modem_upd_via_data - send modem bits via convergence layer 2959 + * @dlci: channel 2960 + * @brk: break signal 2961 + * 2962 + * Send an empty frame to signal mobile state changes and to transmit the 2963 + * break signal for adaption 2. 2964 + */ 2965 + 2966 + static void gsm_modem_upd_via_data(struct gsm_dlci *dlci, u8 brk) 2977 2967 { 2978 - u8 modembits[5]; 2968 + struct gsm_mux *gsm = dlci->gsm; 2969 + unsigned long flags; 2970 + 2971 + if (dlci->state != DLCI_OPEN || dlci->adaption != 2) 2972 + return; 2973 + 2974 + spin_lock_irqsave(&gsm->tx_lock, flags); 2975 + gsm_dlci_modem_output(gsm, dlci, brk); 2976 + spin_unlock_irqrestore(&gsm->tx_lock, flags); 2977 + } 2978 + 2979 + /** 2980 + * gsm_modem_upd_via_msc - send modem bits via control frame 2981 + * @dlci: channel 2982 + * @brk: break signal 2983 + */ 2984 + 2985 + static int gsm_modem_upd_via_msc(struct gsm_dlci *dlci, u8 brk) 2986 + { 2987 + u8 modembits[3]; 2979 2988 struct gsm_control *ctrl; 2980 2989 int len = 2; 2981 2990 2982 - if (brk) 2983 - len++; 2991 + if (dlci->gsm->encoding != 0) 2992 + return 0; 2984 2993 2985 - modembits[0] = len << 1 | EA; /* Data bytes */ 2986 - modembits[1] = dlci->addr << 2 | 3; /* DLCI, EA, 1 */ 2987 - modembits[2] = gsm_encode_modem(dlci) << 1 | EA; 2988 - if (brk) 2989 - modembits[3] = brk << 4 | 2 | EA; /* Valid, EA */ 2990 - ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len + 1); 2994 + modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ 2995 + if (!brk) { 2996 + modembits[1] = (gsm_encode_modem(dlci) << 1) | EA; 2997 + } else { 2998 + modembits[1] = gsm_encode_modem(dlci) << 1; 2999 + modembits[2] = (brk << 4) | 2 | EA; /* Length, Break, EA */ 3000 + len++; 3001 + } 3002 + ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); 2991 3003 if (ctrl == NULL) 2992 3004 return -ENOMEM; 2993 3005 return gsm_control_wait(dlci->gsm, ctrl); 3006 + } 3007 + 3008 + /** 3009 + * gsm_modem_update - send modem status line state 3010 + * @dlci: channel 3011 + * @brk: break signal 3012 + */ 3013 + 3014 + static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk) 3015 + { 3016 + if (dlci->adaption == 2) { 3017 + /* Send convergence layer type 2 empty data frame. */ 3018 + gsm_modem_upd_via_data(dlci, brk); 3019 + return 0; 3020 + } else if (dlci->gsm->encoding == 0) { 3021 + /* Send as MSC control message. */ 3022 + return gsm_modem_upd_via_msc(dlci, brk); 3023 + } 3024 + 3025 + /* Modem status lines are not supported. */ 3026 + return -EPROTONOSUPPORT; 2994 3027 } 2995 3028 2996 3029 static int gsm_carrier_raised(struct tty_port *port) ··· 3077 3006 modem_tx &= ~(TIOCM_DTR | TIOCM_RTS); 3078 3007 if (modem_tx != dlci->modem_tx) { 3079 3008 dlci->modem_tx = modem_tx; 3080 - gsmtty_modem_update(dlci, 0); 3009 + gsm_modem_update(dlci, 0); 3081 3010 } 3082 3011 } 3083 3012 ··· 3226 3155 static void gsmtty_flush_buffer(struct tty_struct *tty) 3227 3156 { 3228 3157 struct gsm_dlci *dlci = tty->driver_data; 3158 + unsigned long flags; 3159 + 3229 3160 if (dlci->state == DLCI_CLOSED) 3230 3161 return; 3231 3162 /* Caution needed: If we implement reliable transport classes 3232 3163 then the data being transmitted can't simply be junked once 3233 3164 it has first hit the stack. Until then we can just blow it 3234 3165 away */ 3166 + spin_lock_irqsave(&dlci->lock, flags); 3235 3167 kfifo_reset(&dlci->fifo); 3168 + spin_unlock_irqrestore(&dlci->lock, flags); 3236 3169 /* Need to unhook this DLCI from the transmit queue logic */ 3237 3170 } 3238 3171 ··· 3268 3193 3269 3194 if (modem_tx != dlci->modem_tx) { 3270 3195 dlci->modem_tx = modem_tx; 3271 - return gsmtty_modem_update(dlci, 0); 3196 + return gsm_modem_update(dlci, 0); 3272 3197 } 3273 3198 return 0; 3274 3199 } ··· 3329 3254 dlci->modem_tx &= ~TIOCM_RTS; 3330 3255 dlci->throttled = true; 3331 3256 /* Send an MSC with RTS cleared */ 3332 - gsmtty_modem_update(dlci, 0); 3257 + gsm_modem_update(dlci, 0); 3333 3258 } 3334 3259 3335 3260 static void gsmtty_unthrottle(struct tty_struct *tty) ··· 3341 3266 dlci->modem_tx |= TIOCM_RTS; 3342 3267 dlci->throttled = false; 3343 3268 /* Send an MSC with RTS set */ 3344 - gsmtty_modem_update(dlci, 0); 3269 + gsm_modem_update(dlci, 0); 3345 3270 } 3346 3271 3347 3272 static int gsmtty_break_ctl(struct tty_struct *tty, int state) ··· 3359 3284 if (encode > 0x0F) 3360 3285 encode = 0x0F; /* Best effort */ 3361 3286 } 3362 - return gsmtty_modem_update(dlci, encode); 3287 + return gsm_modem_update(dlci, encode); 3363 3288 } 3364 3289 3365 3290 static void gsmtty_cleanup(struct tty_struct *tty)
+4 -4
drivers/tty/serial/8250/8250_pci.c
··· 2667 2667 pbn_panacom2, 2668 2668 pbn_panacom4, 2669 2669 pbn_plx_romulus, 2670 - pbn_endrun_2_4000000, 2670 + pbn_endrun_2_3906250, 2671 2671 pbn_oxsemi, 2672 2672 pbn_oxsemi_1_3906250, 2673 2673 pbn_oxsemi_2_3906250, ··· 3195 3195 * signal now many ports are available 3196 3196 * 2 port 952 Uart support 3197 3197 */ 3198 - [pbn_endrun_2_4000000] = { 3198 + [pbn_endrun_2_3906250] = { 3199 3199 .flags = FL_BASE0, 3200 3200 .num_ports = 2, 3201 - .base_baud = 4000000, 3201 + .base_baud = 3906250, 3202 3202 .uart_offset = 0x200, 3203 3203 .first_offset = 0x1000, 3204 3204 }, ··· 4115 4115 */ 4116 4116 { PCI_VENDOR_ID_ENDRUN, PCI_DEVICE_ID_ENDRUN_1588, 4117 4117 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4118 - pbn_endrun_2_4000000 }, 4118 + pbn_endrun_2_3906250 }, 4119 4119 /* 4120 4120 * Quatech cards. These actually have configurable clocks but for 4121 4121 * now we just use the default.
+3 -3
drivers/tty/serial/8250/8250_port.c
··· 1675 1675 struct uart_8250_port *up = up_to_u8250p(port); 1676 1676 struct uart_8250_em485 *em485 = up->em485; 1677 1677 1678 - serial8250_rpm_get_tx(up); 1679 - 1680 1678 if (!port->x_char && uart_circ_empty(&port->state->xmit)) 1681 1679 return; 1680 + 1681 + serial8250_rpm_get_tx(up); 1682 1682 1683 1683 if (em485 && 1684 1684 em485->active_timer == &em485->start_tx_timer) ··· 3329 3329 3330 3330 serial8250_set_divisor(port, baud, quot, frac); 3331 3331 serial_port_out(port, UART_LCR, up->lcr); 3332 - serial8250_out_MCR(up, UART_MCR_DTR | UART_MCR_RTS); 3332 + serial8250_out_MCR(up, up->mcr | UART_MCR_DTR | UART_MCR_RTS); 3333 3333 } 3334 3334 3335 3335 /*
+7 -2
drivers/tty/serial/amba-pl011.c
··· 1255 1255 1256 1256 static void pl011_rs485_tx_stop(struct uart_amba_port *uap) 1257 1257 { 1258 + /* 1259 + * To be on the safe side only time out after twice as many iterations 1260 + * as fifo size. 1261 + */ 1262 + const int MAX_TX_DRAIN_ITERS = uap->port.fifosize * 2; 1258 1263 struct uart_port *port = &uap->port; 1259 1264 int i = 0; 1260 1265 u32 cr; 1261 1266 1262 1267 /* Wait until hardware tx queue is empty */ 1263 1268 while (!pl011_tx_empty(port)) { 1264 - if (i == port->fifosize) { 1269 + if (i > MAX_TX_DRAIN_ITERS) { 1265 1270 dev_warn(port->dev, 1266 1271 "timeout while draining hardware tx queue\n"); 1267 1272 break; ··· 2057 2052 * with the given baud rate. We use this as the poll interval when we 2058 2053 * wait for the tx queue to empty. 2059 2054 */ 2060 - uap->rs485_tx_drain_interval = (bits * 1000 * 1000) / baud; 2055 + uap->rs485_tx_drain_interval = DIV_ROUND_UP(bits * 1000 * 1000, baud); 2061 2056 2062 2057 pl011_setup_status_masks(port, termios); 2063 2058
+1 -1
drivers/tty/serial/imx.c
··· 1448 1448 imx_uart_writel(sport, ucr1, UCR1); 1449 1449 1450 1450 ucr4 = imx_uart_readl(sport, UCR4) & ~(UCR4_OREN | UCR4_INVR); 1451 - if (!sport->dma_is_enabled) 1451 + if (!dma_is_inited) 1452 1452 ucr4 |= UCR4_OREN; 1453 1453 if (sport->inverted_rx) 1454 1454 ucr4 |= UCR4_INVR;
+2 -4
drivers/tty/serial/sc16is7xx.c
··· 1238 1238 1239 1239 /* Disable all interrupts */ 1240 1240 sc16is7xx_port_write(port, SC16IS7XX_IER_REG, 0); 1241 - /* Disable TX/RX, clear auto RS485 and RTS invert */ 1241 + /* Disable TX/RX */ 1242 1242 sc16is7xx_port_update(port, SC16IS7XX_EFCR_REG, 1243 1243 SC16IS7XX_EFCR_RXDISABLE_BIT | 1244 - SC16IS7XX_EFCR_TXDISABLE_BIT | 1245 - SC16IS7XX_EFCR_AUTO_RS485_BIT | 1246 - SC16IS7XX_EFCR_RTS_INVERT_BIT, 1244 + SC16IS7XX_EFCR_TXDISABLE_BIT, 1247 1245 SC16IS7XX_EFCR_RXDISABLE_BIT | 1248 1246 SC16IS7XX_EFCR_TXDISABLE_BIT); 1249 1247