Lines Matching +full:mux +full:- +full:ctrl +full:- +full:list
1 // SPDX-License-Identifier: GPL-2.0
9 * tty -> DLCI fifo -> scheduler -> GSM MUX data queue ---o-> ldisc
10 * control message -> GSM MUX control queue --´
13 * ldisc -> gsm_queue() -o--> tty
14 * `-> gsm_control_response()
24 * Review the locking/move to refcounts more (mux now moved to an
29 * Do we need a 'which mux are you' ioctl to correlate mux and tty sets
95 * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte
101 /* SOF, ADDR, CTRL, LEN1, LEN2, ..., FCS, EOF */
106 * struct gsm_mux_net - network interface
122 struct list_head list; member
124 u8 ctrl; /* Control byte + flags */ member
147 * complexity right now these are only ever freed up when the mux is
150 * At the moment we don't free DLCI objects until the mux is torn down
174 bool dead; /* Refuse re-open */
262 * Each GSM mux we have is represented by this structure. If we are
265 * to the gsm mux array. For now we don't free DLCI objects that
266 * have been instantiated until the mux itself is terminated.
268 * To consider further: tty open versus mux shutdown.
305 bool dead; /* Has the mux been shut down */
325 /* Keep-alive */
326 struct timer_list ka_timer; /* Keep-alive response timer */
327 u8 ka_num; /* Keep-alive match pattern */
328 signed int ka_retries; /* Keep-alive retry counter, -1 if not yet initialized */
334 unsigned int t3; /* Power wake-up timer in seconds. */
338 u32 keep_alive; /* Control channel keep-alive in 10ms */
351 * Mux objects - needed so that we can translate a tty index into the
352 * relevant mux and DLCI.
458 u8 ctrl);
465 * gsm_fcs_add - update FCS
479 * gsm_fcs_add_block - update FCS for a block
490 while (len--) in gsm_fcs_add_block()
496 * gsm_read_ea - read a byte into an EA
514 * gsm_read_ea_val - read a value until EA
526 for (; dlen > 0; dlen--) { in gsm_read_ea_val()
535 * gsm_encode_modem - encode modem data bits
546 if (dlci->throttled) in gsm_encode_modem()
548 if (dlci->modem_tx & TIOCM_DTR) in gsm_encode_modem()
550 if (dlci->modem_tx & TIOCM_RTS) in gsm_encode_modem()
552 if (dlci->modem_tx & TIOCM_RI) in gsm_encode_modem()
554 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
557 if (dlci->modem_tx & TIOCM_OUT1) in gsm_encode_modem()
559 if (dlci->modem_tx & TIOCM_OUT2) in gsm_encode_modem()
584 * gsm_encode_params - encode DLCI parameters
594 const struct gsm_mux *gsm = dlci->gsm; in gsm_encode_params()
597 switch (dlci->ftype) { in gsm_encode_params()
605 pr_debug("unsupported frame type %d\n", dlci->ftype); in gsm_encode_params()
606 return -EINVAL; in gsm_encode_params()
609 switch (dlci->adaption) { in gsm_encode_params()
617 pr_debug("unsupported adaption %d\n", dlci->adaption); in gsm_encode_params()
618 return -EINVAL; in gsm_encode_params()
621 params->d_bits = FIELD_PREP(PN_D_FIELD_DLCI, dlci->addr); in gsm_encode_params()
623 params->i_cl_bits = FIELD_PREP(PN_I_CL_FIELD_FTYPE, i) | in gsm_encode_params()
625 params->p_bits = FIELD_PREP(PN_P_FIELD_PRIO, dlci->prio); in gsm_encode_params()
626 params->t_bits = FIELD_PREP(PN_T_FIELD_T1, gsm->t1); in gsm_encode_params()
627 params->n_bits = cpu_to_le16(FIELD_PREP(PN_N_FIELD_N1, dlci->mtu)); in gsm_encode_params()
628 params->na_bits = FIELD_PREP(PN_NA_FIELD_N2, gsm->n2); in gsm_encode_params()
629 params->k_bits = FIELD_PREP(PN_K_FIELD_K, dlci->k); in gsm_encode_params()
635 * gsm_register_devices - register all tty devices for a given mux index
638 * @index: the mux number is used to calculate the minor numbers of the
639 * ttys for this mux and may differ from the position in the
640 * mux array.
649 return -EINVAL; in gsm_register_devices()
653 /* Don't register device 0 - this is the control channel in gsm_register_devices()
661 for (i--; i >= 1; i--) in gsm_register_devices()
671 * gsm_unregister_devices - unregister all tty devices for a given mux index
674 * @index: the mux number is used to calculate the minor numbers of the
675 * ttys for this mux and may differ from the position in the
676 * mux array.
689 /* Don't unregister device 0 - this is the control in gsm_unregister_devices()
697 * gsm_print_packet - display a frame for debug
706 * style is based on amateur radio LAP-B dump display.
773 * gsm_stuff_frame - bytestuff a packet
786 while (len--) { in gsm_stuff_frame()
801 * gsm_send - send a control frame
802 * @gsm: our GSM mux
819 return -ENOMEM; in gsm_send()
822 ocr = cr ^ (gsm->initiator ? 0 : 1); in gsm_send()
824 msg->data -= 3; in gsm_send()
825 dp = msg->data; in gsm_send()
829 if (gsm->encoding == GSM_BASIC_OPT) in gsm_send()
832 *dp = 0xFF - gsm_fcs_add_block(INIT_FCS, msg->data, dp - msg->data); in gsm_send()
833 msg->len = (dp - msg->data) + 1; in gsm_send()
835 gsm_print_packet("Q->", addr, cr, control, NULL, 0); in gsm_send()
837 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_send()
838 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in gsm_send()
839 gsm->tx_bytes += msg->len; in gsm_send()
840 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_send()
847 * gsm_dlci_clear_queues - remove outstanding data for a DLCI
848 * @gsm: mux
856 int addr = dlci->addr; in gsm_dlci_clear_queues()
860 spin_lock_irqsave(&dlci->lock, flags); in gsm_dlci_clear_queues()
861 kfifo_reset(&dlci->fifo); in gsm_dlci_clear_queues()
862 spin_unlock_irqrestore(&dlci->lock, flags); in gsm_dlci_clear_queues()
864 /* Clear data packets in MUX write queue */ in gsm_dlci_clear_queues()
865 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
866 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_dlci_clear_queues()
867 if (msg->addr != addr) in gsm_dlci_clear_queues()
869 gsm->tx_bytes -= msg->len; in gsm_dlci_clear_queues()
870 list_del(&msg->list); in gsm_dlci_clear_queues()
873 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
877 * gsm_response - send a control response
878 * @gsm: our GSM mux
891 * gsm_command - send a control command
892 * @gsm: our GSM mux
906 #define HDR_LEN 6 /* ADDR CTRL [LEN.2] DATA FCS */
909 * gsm_data_alloc - allocate data frame
910 * @gsm: GSM mux
913 * @ctrl: control byte
921 u8 ctrl) in gsm_data_alloc() argument
927 m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ in gsm_data_alloc()
928 m->len = len; in gsm_data_alloc()
929 m->addr = addr; in gsm_data_alloc()
930 m->ctrl = ctrl; in gsm_data_alloc()
931 INIT_LIST_HEAD(&m->list); in gsm_data_alloc()
936 * gsm_send_packet - sends a single packet
937 * @gsm: GSM Mux
948 if (gsm->encoding == GSM_BASIC_OPT) { in gsm_send_packet()
949 gsm->txframe[0] = GSM0_SOF; in gsm_send_packet()
950 memcpy(gsm->txframe + 1, msg->data, msg->len); in gsm_send_packet()
951 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_send_packet()
952 len = msg->len + 2; in gsm_send_packet()
954 gsm->txframe[0] = GSM1_SOF; in gsm_send_packet()
955 len = gsm_stuff_frame(msg->data, gsm->txframe + 1, msg->len); in gsm_send_packet()
956 gsm->txframe[len + 1] = GSM1_SOF; in gsm_send_packet()
961 gsm_hex_dump_bytes(__func__, gsm->txframe, len); in gsm_send_packet()
962 gsm_print_packet("-->", msg->addr, gsm->initiator, msg->ctrl, msg->data, in gsm_send_packet()
963 msg->len); in gsm_send_packet()
965 ret = gsmld_output(gsm, gsm->txframe, len); in gsm_send_packet()
969 gsm->tx_bytes -= msg->len; in gsm_send_packet()
975 * gsm_is_flow_ctrl_msg - checks if flow control message
985 if (msg->addr > 0) in gsm_is_flow_ctrl_msg()
988 switch (msg->ctrl & ~PF) { in gsm_is_flow_ctrl_msg()
992 if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) in gsm_is_flow_ctrl_msg()
1006 * gsm_data_kick - poke the queue
1007 * @gsm: GSM Mux
1011 * If we have been flow-stopped by a CMD_FCOFF, then we can only
1021 clear_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsm_data_kick()
1024 list_for_each_entry_safe(msg, nmsg, &gsm->tx_ctrl_list, list) { in gsm_data_kick()
1025 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
1029 case -ENOSPC: in gsm_data_kick()
1030 return -ENOSPC; in gsm_data_kick()
1031 case -ENODEV: in gsm_data_kick()
1033 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1034 list_del(&msg->list); in gsm_data_kick()
1039 list_del(&msg->list); in gsm_data_kick()
1046 if (gsm->constipated) in gsm_data_kick()
1047 return -EAGAIN; in gsm_data_kick()
1050 if (list_empty(&gsm->tx_data_list)) in gsm_data_kick()
1052 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_data_kick()
1053 dlci = gsm->dlci[msg->addr]; in gsm_data_kick()
1055 if (dlci->state != DLCI_OPEN) { in gsm_data_kick()
1056 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1057 list_del(&msg->list); in gsm_data_kick()
1063 case -ENOSPC: in gsm_data_kick()
1064 return -ENOSPC; in gsm_data_kick()
1065 case -ENODEV: in gsm_data_kick()
1067 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1068 list_del(&msg->list); in gsm_data_kick()
1073 list_del(&msg->list); in gsm_data_kick()
1084 * __gsm_data_queue - queue a UI or UIH frame
1089 * out of the mux tty if not already doing so. The Caller must hold
1095 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue()
1096 u8 *dp = msg->data; in __gsm_data_queue()
1097 u8 *fcs = dp + msg->len; in __gsm_data_queue()
1100 if (gsm->encoding == GSM_BASIC_OPT) { in __gsm_data_queue()
1101 if (msg->len < 128) in __gsm_data_queue()
1102 *--dp = (msg->len << 1) | EA; in __gsm_data_queue()
1104 *--dp = (msg->len >> 7); /* bits 7 - 15 */ in __gsm_data_queue()
1105 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ in __gsm_data_queue()
1109 *--dp = msg->ctrl; in __gsm_data_queue()
1110 if (gsm->initiator) in __gsm_data_queue()
1111 *--dp = (msg->addr << 2) | CR | EA; in __gsm_data_queue()
1113 *--dp = (msg->addr << 2) | EA; in __gsm_data_queue()
1114 *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); in __gsm_data_queue()
1116 if (msg->ctrl == UI || msg->ctrl == (UI|PF)) in __gsm_data_queue()
1117 *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); in __gsm_data_queue()
1118 *fcs = 0xFF - *fcs; in __gsm_data_queue()
1120 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
1121 msg->data, msg->len); in __gsm_data_queue()
1125 msg->len += (msg->data - dp) + 1; in __gsm_data_queue()
1126 msg->data = dp; in __gsm_data_queue()
1129 switch (msg->ctrl & ~PF) { in __gsm_data_queue()
1132 if (msg->addr > 0) { in __gsm_data_queue()
1133 list_add_tail(&msg->list, &gsm->tx_data_list); in __gsm_data_queue()
1138 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in __gsm_data_queue()
1141 gsm->tx_bytes += msg->len; in __gsm_data_queue()
1144 mod_timer(&gsm->kick_timer, jiffies + 10 * gsm->t1 * HZ / 100); in __gsm_data_queue()
1148 * gsm_data_queue - queue a UI or UIH frame
1153 * out of the mux tty if not already doing so. Take the
1160 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1162 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1166 * gsm_dlci_data_output - try and push data out of a DLCI
1167 * @gsm: mux
1171 * is data. Keep to the MRU of the mux. This path handles the usual tty
1174 * Caller must hold the tx_lock of the mux.
1184 h = ((dlci->adaption == 1) ? 0 : 1); in gsm_dlci_data_output()
1186 len = kfifo_len(&dlci->fifo); in gsm_dlci_data_output()
1191 if ((len + h) > dlci->mtu) in gsm_dlci_data_output()
1192 len = dlci->mtu - h; in gsm_dlci_data_output()
1196 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output()
1198 return -ENOMEM; in gsm_dlci_data_output()
1199 dp = msg->data; in gsm_dlci_data_output()
1200 switch (dlci->adaption) { in gsm_dlci_data_output()
1210 dlci->adaption); in gsm_dlci_data_output()
1214 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len, in gsm_dlci_data_output()
1215 &dlci->lock)); in gsm_dlci_data_output()
1218 tty_port_tty_wakeup(&dlci->port); in gsm_dlci_data_output()
1226 * gsm_dlci_data_output_framed - try and push data out of a DLCI
1227 * @gsm: mux
1231 * is data. Keep to the MRU of the mux. This path handles framed data
1234 * Caller must hold the tx_lock of the mux.
1247 if (dlci->adaption == 4) in gsm_dlci_data_output_framed()
1250 /* dlci->skb is locked by tx_lock */ in gsm_dlci_data_output_framed()
1251 if (dlci->skb == NULL) { in gsm_dlci_data_output_framed()
1252 dlci->skb = skb_dequeue_tail(&dlci->skb_list); in gsm_dlci_data_output_framed()
1253 if (dlci->skb == NULL) in gsm_dlci_data_output_framed()
1257 len = dlci->skb->len + overhead; in gsm_dlci_data_output_framed()
1260 if (len > dlci->mtu) { in gsm_dlci_data_output_framed()
1261 if (dlci->adaption == 3) { in gsm_dlci_data_output_framed()
1263 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1264 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1267 len = dlci->mtu; in gsm_dlci_data_output_framed()
1272 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output_framed()
1274 skb_queue_tail(&dlci->skb_list, dlci->skb); in gsm_dlci_data_output_framed()
1275 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1276 return -ENOMEM; in gsm_dlci_data_output_framed()
1278 dp = msg->data; in gsm_dlci_data_output_framed()
1280 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ in gsm_dlci_data_output_framed()
1283 len--; in gsm_dlci_data_output_framed()
1285 memcpy(dp, dlci->skb->data, len); in gsm_dlci_data_output_framed()
1286 skb_pull(dlci->skb, len); in gsm_dlci_data_output_framed()
1289 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1290 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1296 * gsm_dlci_modem_output - try and push modem status out of a DLCI
1297 * @gsm: mux
1304 * Caller must hold the tx_lock of the mux.
1315 switch (dlci->adaption) { in gsm_dlci_modem_output()
1325 dlci->adaption); in gsm_dlci_modem_output()
1326 return -EINVAL; in gsm_dlci_modem_output()
1329 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_modem_output()
1332 return -ENOMEM; in gsm_dlci_modem_output()
1334 dp = msg->data; in gsm_dlci_modem_output()
1335 switch (dlci->adaption) { in gsm_dlci_modem_output()
1356 * gsm_dlci_data_sweep - look for data to send
1357 * @gsm: the GSM mux
1359 * Sweep the GSM mux channels in priority order looking for ones with
1375 while (gsm->tx_bytes < TX_THRESH_HI) { in gsm_dlci_data_sweep()
1377 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1379 if (!dlci || dlci->constipated) in gsm_dlci_data_sweep()
1382 if (dlci->state != DLCI_OPEN) in gsm_dlci_data_sweep()
1385 if (dlci->adaption < 3 && !dlci->net) in gsm_dlci_data_sweep()
1408 * gsm_dlci_data_kick - transmit if possible
1421 if (dlci->constipated) in gsm_dlci_data_kick()
1424 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1426 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1427 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1428 if (dlci->net) in gsm_dlci_data_kick()
1429 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1431 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1434 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1435 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1444 * gsm_control_command - send a command frame to a control
1456 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_command()
1458 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_command()
1460 return -ENOMEM; in gsm_control_command()
1462 msg->data[0] = (cmd << 1) | CR | EA; /* Set C/R */ in gsm_control_command()
1463 msg->data[1] = (dlen << 1) | EA; in gsm_control_command()
1464 memcpy(msg->data + 2, data, dlen); in gsm_control_command()
1471 * gsm_control_reply - send a response frame to a control
1484 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_reply()
1486 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_reply()
1489 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ in gsm_control_reply()
1490 msg->data[1] = (dlen << 1) | EA; in gsm_control_reply()
1491 memcpy(msg->data + 2, data, dlen); in gsm_control_reply()
1496 * gsm_process_modem - process received modem status
1515 * section 5.4.6.3.7 of the 07.10 mux spec. in gsm_process_modem()
1527 if (fc && !dlci->constipated) { in gsm_process_modem()
1529 dlci->constipated = true; in gsm_process_modem()
1530 } else if (!fc && dlci->constipated) { in gsm_process_modem()
1531 dlci->constipated = false; in gsm_process_modem()
1545 /* Carrier drop -> hangup */ in gsm_process_modem()
1547 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) in gsm_process_modem()
1552 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); in gsm_process_modem()
1553 dlci->modem_rx = mlines; in gsm_process_modem()
1554 wake_up_interruptible(&dlci->gsm->event); in gsm_process_modem()
1558 * gsm_process_negotiation - process received parameters
1571 struct gsm_dlci *dlci = gsm->dlci[addr]; in gsm_process_negotiation()
1574 i = FIELD_GET(PN_I_CL_FIELD_FTYPE, params->i_cl_bits); in gsm_process_negotiation()
1575 adaption = FIELD_GET(PN_I_CL_FIELD_ADAPTION, params->i_cl_bits) + 1; in gsm_process_negotiation()
1576 prio = FIELD_GET(PN_P_FIELD_PRIO, params->p_bits); in gsm_process_negotiation()
1577 n1 = FIELD_GET(PN_N_FIELD_N1, get_unaligned_le16(¶ms->n_bits)); in gsm_process_negotiation()
1578 k = FIELD_GET(PN_K_FIELD_K, params->k_bits); in gsm_process_negotiation()
1583 return -EINVAL; in gsm_process_negotiation()
1597 gsm->unsupported++; in gsm_process_negotiation()
1598 return -EINVAL; in gsm_process_negotiation()
1602 return -EINVAL; in gsm_process_negotiation()
1605 if (!cr && gsm->initiator) { in gsm_process_negotiation()
1606 if (adaption != dlci->adaption) { in gsm_process_negotiation()
1610 return -EINVAL; in gsm_process_negotiation()
1612 if (prio != dlci->prio) { in gsm_process_negotiation()
1616 return -EINVAL; in gsm_process_negotiation()
1618 if (n1 > gsm->mru || n1 > dlci->mtu) { in gsm_process_negotiation()
1626 return -EINVAL; in gsm_process_negotiation()
1628 dlci->mtu = n1; in gsm_process_negotiation()
1629 if (ftype != dlci->ftype) { in gsm_process_negotiation()
1632 return -EINVAL; in gsm_process_negotiation()
1634 if (ftype != UI && ftype != UIH && k > dlci->k) { in gsm_process_negotiation()
1637 return -EINVAL; in gsm_process_negotiation()
1639 dlci->k = k; in gsm_process_negotiation()
1640 } else if (cr && !gsm->initiator) { in gsm_process_negotiation()
1646 return -EINVAL; in gsm_process_negotiation()
1648 dlci->adaption = adaption; in gsm_process_negotiation()
1649 if (n1 > gsm->mru) { in gsm_process_negotiation()
1651 dlci->mtu = gsm->mru; in gsm_process_negotiation()
1654 dlci->mtu = MAX_MTU; in gsm_process_negotiation()
1656 dlci->mtu = n1; in gsm_process_negotiation()
1658 dlci->prio = prio; in gsm_process_negotiation()
1659 dlci->ftype = ftype; in gsm_process_negotiation()
1660 dlci->k = k; in gsm_process_negotiation()
1662 return -EINVAL; in gsm_process_negotiation()
1669 * gsm_control_modem - modem status received
1675 * the GSM mux protocol to pass virtual modem line status and optionally
1696 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1698 dlci = gsm->dlci[addr]; in gsm_control_modem()
1701 if ((cl - len) < 1) in gsm_control_modem()
1705 cl -= len; in gsm_control_modem()
1712 tty = tty_port_tty_get(&dlci->port); in gsm_control_modem()
1722 * gsm_control_negotiation - parameter negotiation received
1729 * the GSM mux protocol to configure protocol parameters for a new DLCI.
1740 gsm->open_error++; in gsm_control_negotiation()
1746 addr = FIELD_GET(PN_D_FIELD_DLCI, params->d_bits); in gsm_control_negotiation()
1747 if (addr == 0 || addr >= NUM_DLCI || !gsm->dlci[addr]) { in gsm_control_negotiation()
1748 gsm->open_error++; in gsm_control_negotiation()
1751 dlci = gsm->dlci[addr]; in gsm_control_negotiation()
1754 if ((!cr && dlci->state == DLCI_OPENING) || dlci->state == DLCI_OPEN) { in gsm_control_negotiation()
1755 gsm->open_error++; in gsm_control_negotiation()
1764 gsm->open_error++; in gsm_control_negotiation()
1776 } else if (dlci->state == DLCI_CONFIGURE) { in gsm_control_negotiation()
1778 dlci->state = DLCI_OPENING; in gsm_control_negotiation()
1779 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_control_negotiation()
1780 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_control_negotiation()
1784 gsm->open_error++; in gsm_control_negotiation()
1789 * gsm_control_rls - remote line status
1808 len--; in gsm_control_rls()
1813 len--; in gsm_control_rls()
1818 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1825 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1842 * gsm_control_message - DLCI 0 control processing
1843 * @gsm: our GSM mux
1860 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1863 dlci->dead = true; in gsm_control_message()
1864 gsm->dead = true; in gsm_control_message()
1875 gsm->constipated = false; in gsm_control_message()
1882 gsm->constipated = true; in gsm_control_message()
1905 gsm->unsupported++; in gsm_control_message()
1916 * gsm_control_response - process a response to our control
1917 * @gsm: our GSM mux
1931 struct gsm_control *ctrl; in gsm_control_response() local
1935 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1937 ctrl = gsm->pending_cmd; in gsm_control_response()
1938 dlci = gsm->dlci[0]; in gsm_control_response()
1941 if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { in gsm_control_response()
1943 del_timer(&gsm->t2_timer); in gsm_control_response()
1944 gsm->pending_cmd = NULL; in gsm_control_response()
1947 ctrl->error = -EOPNOTSUPP; in gsm_control_response()
1948 ctrl->done = 1; in gsm_control_response()
1949 wake_up(&gsm->event); in gsm_control_response()
1954 } else if (command == CMD_TEST && clen == 1 && *data == gsm->ka_num) { in gsm_control_response()
1955 gsm->ka_retries = -1; /* trigger new keep-alive message */ in gsm_control_response()
1956 if (dlci && !dlci->dead) in gsm_control_response()
1957 mod_timer(&gsm->ka_timer, jiffies + gsm->keep_alive * HZ / 100); in gsm_control_response()
1959 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1963 * gsm_control_keep_alive - check timeout or start keep-alive
1966 * Called off the keep-alive timer expiry signaling that our link
1976 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_keep_alive()
1977 if (gsm->ka_num && gsm->ka_retries == 0) { in gsm_control_keep_alive()
1978 /* Keep-alive expired -> close the link */ in gsm_control_keep_alive()
1980 pr_debug("%s keep-alive timed out\n", __func__); in gsm_control_keep_alive()
1981 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
1982 if (gsm->dlci[0]) in gsm_control_keep_alive()
1983 gsm_dlci_begin_close(gsm->dlci[0]); in gsm_control_keep_alive()
1985 } else if (gsm->keep_alive && gsm->dlci[0] && !gsm->dlci[0]->dead) { in gsm_control_keep_alive()
1986 if (gsm->ka_retries > 0) { in gsm_control_keep_alive()
1987 /* T2 expired for keep-alive -> resend */ in gsm_control_keep_alive()
1988 gsm->ka_retries--; in gsm_control_keep_alive()
1990 /* Start keep-alive timer */ in gsm_control_keep_alive()
1991 gsm->ka_num++; in gsm_control_keep_alive()
1992 if (!gsm->ka_num) in gsm_control_keep_alive()
1993 gsm->ka_num++; in gsm_control_keep_alive()
1994 gsm->ka_retries = (signed int)gsm->n2; in gsm_control_keep_alive()
1996 gsm_control_command(gsm, CMD_TEST, &gsm->ka_num, in gsm_control_keep_alive()
1997 sizeof(gsm->ka_num)); in gsm_control_keep_alive()
1998 mod_timer(&gsm->ka_timer, in gsm_control_keep_alive()
1999 jiffies + gsm->t2 * HZ / 100); in gsm_control_keep_alive()
2001 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
2005 * gsm_control_transmit - send control packet
2006 * @gsm: gsm mux
2007 * @ctrl: frame to send
2012 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) in gsm_control_transmit() argument
2014 gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len); in gsm_control_transmit()
2018 * gsm_control_retransmit - retransmit a control frame
2025 * gsm->pending_cmd will be NULL and we just let the timer expire.
2031 struct gsm_control *ctrl; in gsm_control_retransmit() local
2033 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
2034 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
2035 if (ctrl) { in gsm_control_retransmit()
2036 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
2037 gsm->pending_cmd = NULL; in gsm_control_retransmit()
2038 ctrl->error = -ETIMEDOUT; in gsm_control_retransmit()
2039 ctrl->done = 1; in gsm_control_retransmit()
2040 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2041 wake_up(&gsm->event); in gsm_control_retransmit()
2044 gsm->cretries--; in gsm_control_retransmit()
2045 gsm_control_transmit(gsm, ctrl); in gsm_control_retransmit()
2046 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
2048 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2052 * gsm_control_send - send a control frame on DLCI 0
2066 struct gsm_control *ctrl = kzalloc(sizeof(struct gsm_control), in gsm_control_send() local
2069 if (ctrl == NULL) in gsm_control_send()
2072 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
2073 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
2074 if (gsm->pending_cmd != NULL) { in gsm_control_send()
2075 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2078 ctrl->cmd = command; in gsm_control_send()
2079 ctrl->data = data; in gsm_control_send()
2080 ctrl->len = clen; in gsm_control_send()
2081 gsm->pending_cmd = ctrl; in gsm_control_send()
2084 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
2085 gsm->cretries = 0; in gsm_control_send()
2087 gsm->cretries = gsm->n2; in gsm_control_send()
2089 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
2090 gsm_control_transmit(gsm, ctrl); in gsm_control_send()
2091 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2092 return ctrl; in gsm_control_send()
2096 * gsm_control_wait - wait for a control to finish
2097 * @gsm: GSM mux
2108 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
2109 err = control->error; in gsm_control_wait()
2124 * gsm_dlci_close - a DLCI has closed
2133 del_timer(&dlci->t1); in gsm_dlci_close()
2135 pr_debug("DLCI %d goes closed.\n", dlci->addr); in gsm_dlci_close()
2136 dlci->state = DLCI_CLOSED; in gsm_dlci_close()
2138 dlci->constipated = true; in gsm_dlci_close()
2139 if (dlci->addr != 0) { in gsm_dlci_close()
2140 tty_port_tty_hangup(&dlci->port, false); in gsm_dlci_close()
2141 gsm_dlci_clear_queues(dlci->gsm, dlci); in gsm_dlci_close()
2143 tty_port_set_initialized(&dlci->port, false); in gsm_dlci_close()
2144 wake_up_interruptible(&dlci->port.open_wait); in gsm_dlci_close()
2146 del_timer(&dlci->gsm->ka_timer); in gsm_dlci_close()
2147 dlci->gsm->dead = true; in gsm_dlci_close()
2149 /* A DLCI 0 close is a MUX termination so we need to kick that in gsm_dlci_close()
2152 wake_up_all(&dlci->gsm->event); in gsm_dlci_close()
2156 * gsm_dlci_open - a DLCI has opened
2164 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_open()
2167 open -> open */ in gsm_dlci_open()
2168 del_timer(&dlci->t1); in gsm_dlci_open()
2170 dlci->state = DLCI_OPEN; in gsm_dlci_open()
2171 dlci->constipated = false; in gsm_dlci_open()
2173 pr_debug("DLCI %d goes open.\n", dlci->addr); in gsm_dlci_open()
2175 if (dlci->addr) { in gsm_dlci_open()
2178 /* Start keep-alive control */ in gsm_dlci_open()
2179 gsm->ka_num = 0; in gsm_dlci_open()
2180 gsm->ka_retries = -1; in gsm_dlci_open()
2181 mod_timer(&gsm->ka_timer, in gsm_dlci_open()
2182 jiffies + gsm->keep_alive * HZ / 100); in gsm_dlci_open()
2185 wake_up(&dlci->gsm->event); in gsm_dlci_open()
2189 * gsm_dlci_negotiate - start parameter negotiation
2197 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_negotiate()
2215 * gsm_dlci_t1 - T1 timer expiry
2232 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1()
2234 switch (dlci->state) { in gsm_dlci_t1()
2236 if (dlci->retries && gsm_dlci_negotiate(dlci) == 0) { in gsm_dlci_t1()
2237 dlci->retries--; in gsm_dlci_t1()
2238 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2240 gsm->open_error++; in gsm_dlci_t1()
2245 if (dlci->retries) { in gsm_dlci_t1()
2246 dlci->retries--; in gsm_dlci_t1()
2247 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
2248 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2249 } else if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
2252 dlci->addr); in gsm_dlci_t1()
2253 dlci->mode = DLCI_MODE_ADM; in gsm_dlci_t1()
2256 gsm->open_error++; in gsm_dlci_t1()
2262 if (dlci->retries) { in gsm_dlci_t1()
2263 dlci->retries--; in gsm_dlci_t1()
2264 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
2265 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2270 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state); in gsm_dlci_t1()
2276 * gsm_dlci_begin_open - start channel open procedure
2288 struct gsm_mux *gsm = dlci ? dlci->gsm : NULL; in gsm_dlci_begin_open()
2294 if (dlci->addr != 0) { in gsm_dlci_begin_open()
2295 if (gsm->adaption != 1 || gsm->adaption != dlci->adaption) in gsm_dlci_begin_open()
2297 if (dlci->prio != (roundup(dlci->addr + 1, 8) - 1)) in gsm_dlci_begin_open()
2299 if (gsm->ftype != dlci->ftype) in gsm_dlci_begin_open()
2303 switch (dlci->state) { in gsm_dlci_begin_open()
2307 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
2309 dlci->state = DLCI_OPENING; in gsm_dlci_begin_open()
2310 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
2313 dlci->state = DLCI_CONFIGURE; in gsm_dlci_begin_open()
2319 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
2327 * gsm_dlci_set_opening - change state to opening
2335 switch (dlci->state) { in gsm_dlci_set_opening()
2339 dlci->state = DLCI_OPENING; in gsm_dlci_set_opening()
2347 * gsm_dlci_set_wait_config - wait for channel configuration
2354 switch (dlci->state) { in gsm_dlci_set_wait_config()
2357 dlci->state = DLCI_WAITING_CONFIG; in gsm_dlci_set_wait_config()
2365 * gsm_dlci_begin_close - start channel open procedure
2377 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close()
2378 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) in gsm_dlci_begin_close()
2380 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
2381 dlci->state = DLCI_CLOSING; in gsm_dlci_begin_close()
2382 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
2383 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
2384 wake_up_interruptible(&gsm->event); in gsm_dlci_begin_close()
2388 * gsm_dlci_data - data arrived
2401 struct tty_port *port = &dlci->port; in gsm_dlci_data()
2408 switch (dlci->adaption) { in gsm_dlci_data()
2426 clen -= len; in gsm_dlci_data()
2436 * gsm_dlci_command - data arrived on control channel
2456 len -= dlen; in gsm_dlci_command()
2461 len -= dlen; in gsm_dlci_command()
2466 dlci->gsm->malformed++; in gsm_dlci_command()
2471 gsm_control_message(dlci->gsm, command, data, clen); in gsm_dlci_command()
2473 gsm_control_response(dlci->gsm, command, data, clen); in gsm_dlci_command()
2477 * gsm_kick_timer - transmit if possible
2490 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_kick_timer()
2492 if (gsm->tx_bytes < TX_THRESH_LO) in gsm_kick_timer()
2494 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_kick_timer()
2501 * gsm_dlci_copy_config_values - copy DLCI configuration
2508 dc->channel = (u32)dlci->addr; in gsm_dlci_copy_config_values()
2509 dc->adaption = (u32)dlci->adaption; in gsm_dlci_copy_config_values()
2510 dc->mtu = (u32)dlci->mtu; in gsm_dlci_copy_config_values()
2511 dc->priority = (u32)dlci->prio; in gsm_dlci_copy_config_values()
2512 if (dlci->ftype == UIH) in gsm_dlci_copy_config_values()
2513 dc->i = 1; in gsm_dlci_copy_config_values()
2515 dc->i = 2; in gsm_dlci_copy_config_values()
2516 dc->k = (u32)dlci->k; in gsm_dlci_copy_config_values()
2520 * gsm_dlci_config - configure DLCI from configuration
2536 for (i = 0; i < ARRAY_SIZE(dc->reserved); i++) in gsm_dlci_config()
2537 if (dc->reserved[i]) in gsm_dlci_config()
2538 return -EINVAL; in gsm_dlci_config()
2541 return -EINVAL; in gsm_dlci_config()
2542 gsm = dlci->gsm; in gsm_dlci_config()
2544 /* Stuff we don't support yet - I frame transport */ in gsm_dlci_config()
2545 if (dc->adaption != 1 && dc->adaption != 2) in gsm_dlci_config()
2546 return -EOPNOTSUPP; in gsm_dlci_config()
2547 if (dc->mtu > MAX_MTU || dc->mtu < MIN_MTU || dc->mtu > gsm->mru) in gsm_dlci_config()
2548 return -EINVAL; in gsm_dlci_config()
2549 if (dc->priority >= 64) in gsm_dlci_config()
2550 return -EINVAL; in gsm_dlci_config()
2551 if (dc->i == 0 || dc->i > 2) /* UIH and UI only */ in gsm_dlci_config()
2552 return -EINVAL; in gsm_dlci_config()
2553 if (dc->k > 7) in gsm_dlci_config()
2554 return -EINVAL; in gsm_dlci_config()
2555 if (dc->flags & ~GSM_FL_RESTART) /* allow future extensions */ in gsm_dlci_config()
2556 return -EINVAL; in gsm_dlci_config()
2562 if (dc->adaption != dlci->adaption) in gsm_dlci_config()
2564 if (dc->mtu != dlci->mtu) in gsm_dlci_config()
2566 if (dc->i != dlci->ftype) in gsm_dlci_config()
2569 if (dc->priority != dlci->prio) in gsm_dlci_config()
2571 if (dc->flags & GSM_FL_RESTART) in gsm_dlci_config()
2574 if ((open && gsm->wait_config) || need_restart) in gsm_dlci_config()
2576 if (dlci->state == DLCI_WAITING_CONFIG) { in gsm_dlci_config()
2587 wait_event_interruptible(gsm->event, dlci->state == DLCI_CLOSED); in gsm_dlci_config()
2589 return -EINTR; in gsm_dlci_config()
2594 dlci->adaption = (int)dc->adaption; in gsm_dlci_config()
2596 if (dc->mtu) in gsm_dlci_config()
2597 dlci->mtu = (unsigned int)dc->mtu; in gsm_dlci_config()
2599 dlci->mtu = gsm->mtu; in gsm_dlci_config()
2601 if (dc->priority) in gsm_dlci_config()
2602 dlci->prio = (u8)dc->priority; in gsm_dlci_config()
2604 dlci->prio = roundup(dlci->addr + 1, 8) - 1; in gsm_dlci_config()
2606 if (dc->i == 1) in gsm_dlci_config()
2607 dlci->ftype = UIH; in gsm_dlci_config()
2608 else if (dc->i == 2) in gsm_dlci_config()
2609 dlci->ftype = UI; in gsm_dlci_config()
2611 if (dc->k) in gsm_dlci_config()
2612 dlci->k = (u8)dc->k; in gsm_dlci_config()
2614 dlci->k = gsm->k; in gsm_dlci_config()
2617 if (gsm->initiator) in gsm_dlci_config()
2631 * gsm_dlci_alloc - allocate a DLCI
2632 * @gsm: GSM mux
2635 * Allocate and install a new DLCI object into the GSM mux.
2645 spin_lock_init(&dlci->lock); in gsm_dlci_alloc()
2646 mutex_init(&dlci->mutex); in gsm_dlci_alloc()
2647 if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) { in gsm_dlci_alloc()
2652 skb_queue_head_init(&dlci->skb_list); in gsm_dlci_alloc()
2653 timer_setup(&dlci->t1, gsm_dlci_t1, 0); in gsm_dlci_alloc()
2654 tty_port_init(&dlci->port); in gsm_dlci_alloc()
2655 dlci->port.ops = &gsm_port_ops; in gsm_dlci_alloc()
2656 dlci->gsm = gsm; in gsm_dlci_alloc()
2657 dlci->addr = addr; in gsm_dlci_alloc()
2658 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
2659 dlci->mtu = gsm->mtu; in gsm_dlci_alloc()
2661 dlci->prio = 0; in gsm_dlci_alloc()
2663 dlci->prio = roundup(addr + 1, 8) - 1; in gsm_dlci_alloc()
2664 dlci->ftype = gsm->ftype; in gsm_dlci_alloc()
2665 dlci->k = gsm->k; in gsm_dlci_alloc()
2666 dlci->state = DLCI_CLOSED; in gsm_dlci_alloc()
2668 dlci->data = gsm_dlci_data; in gsm_dlci_alloc()
2670 dlci->constipated = true; in gsm_dlci_alloc()
2672 dlci->data = gsm_dlci_command; in gsm_dlci_alloc()
2674 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
2679 * gsm_dlci_free - free DLCI
2690 timer_shutdown_sync(&dlci->t1); in gsm_dlci_free()
2691 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
2692 kfifo_free(&dlci->fifo); in gsm_dlci_free()
2693 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) in gsm_dlci_free()
2694 dev_kfree_skb(dlci->skb); in gsm_dlci_free()
2700 tty_port_get(&dlci->port); in dlci_get()
2705 tty_port_put(&dlci->port); in dlci_put()
2711 * gsm_dlci_release - release DLCI
2715 * mux is closed or tty is closed - whichever is last.
2721 struct tty_struct *tty = tty_port_tty_get(&dlci->port); in gsm_dlci_release()
2723 mutex_lock(&dlci->mutex); in gsm_dlci_release()
2725 mutex_unlock(&dlci->mutex); in gsm_dlci_release()
2729 * queue release_one_tty() -> NULL pointer panic in in gsm_dlci_release()
2734 tty_port_tty_set(&dlci->port, NULL); in gsm_dlci_release()
2737 dlci->state = DLCI_CLOSED; in gsm_dlci_release()
2746 * gsm_queue - a GSM frame is ready to process
2747 * @gsm: pointer to our gsm mux
2761 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
2762 gsm->bad_fcs++; in gsm_queue()
2764 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
2767 address = gsm->address >> 1; in gsm_queue()
2771 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
2772 cr ^= gsm->initiator ? 0 : 1; /* Flip so 1 always means command */ in gsm_queue()
2774 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
2776 dlci = gsm->dlci[address]; in gsm_queue()
2778 switch (gsm->control) { in gsm_queue()
2781 gsm->open_error++; in gsm_queue()
2787 gsm->open_error++; in gsm_queue()
2790 if (dlci->dead) in gsm_queue()
2800 if (dlci == NULL || dlci->state == DLCI_CLOSED) { in gsm_queue()
2811 switch (dlci->state) { in gsm_queue()
2820 dlci->state); in gsm_queue()
2836 if (dlci == NULL || dlci->state != DLCI_OPEN) { in gsm_queue()
2840 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2847 gsm->malformed++; in gsm_queue()
2852 * gsm0_receive_state_check_and_fix - check and correct receive state
2860 switch (gsm->state) { in gsm0_receive_state_check_and_fix()
2871 gsm->state = GSM_SEARCH; in gsm0_receive_state_check_and_fix()
2877 * gsm0_receive - perform processing for non-transparency
2889 switch (gsm->state) { in gsm0_receive()
2892 gsm->state = GSM0_ADDRESS; in gsm0_receive()
2893 gsm->address = 0; in gsm0_receive()
2894 gsm->len = 0; in gsm0_receive()
2895 gsm->fcs = INIT_FCS; in gsm0_receive()
2899 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2900 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
2901 gsm->state = GSM0_CONTROL; in gsm0_receive()
2904 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2905 gsm->control = c; in gsm0_receive()
2906 gsm->state = GSM0_LEN0; in gsm0_receive()
2909 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2910 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
2911 if (gsm->len > gsm->mru) { in gsm0_receive()
2912 gsm->bad_size++; in gsm0_receive()
2913 gsm->state = GSM_SEARCH; in gsm0_receive()
2916 gsm->count = 0; in gsm0_receive()
2917 if (!gsm->len) in gsm0_receive()
2918 gsm->state = GSM0_FCS; in gsm0_receive()
2920 gsm->state = GSM0_DATA; in gsm0_receive()
2923 gsm->state = GSM0_LEN1; in gsm0_receive()
2926 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2928 gsm->len |= len << 7; in gsm0_receive()
2929 if (gsm->len > gsm->mru) { in gsm0_receive()
2930 gsm->bad_size++; in gsm0_receive()
2931 gsm->state = GSM_SEARCH; in gsm0_receive()
2934 gsm->count = 0; in gsm0_receive()
2935 if (!gsm->len) in gsm0_receive()
2936 gsm->state = GSM0_FCS; in gsm0_receive()
2938 gsm->state = GSM0_DATA; in gsm0_receive()
2941 gsm->buf[gsm->count++] = c; in gsm0_receive()
2942 if (gsm->count >= MAX_MRU) { in gsm0_receive()
2943 gsm->bad_size++; in gsm0_receive()
2944 gsm->state = GSM_SEARCH; in gsm0_receive()
2945 } else if (gsm->count >= gsm->len) { in gsm0_receive()
2947 if ((gsm->control & ~PF) != UIH) { in gsm0_receive()
2948 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm0_receive()
2949 gsm->count); in gsm0_receive()
2951 gsm->state = GSM0_FCS; in gsm0_receive()
2955 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2956 gsm->state = GSM0_SSOF; in gsm0_receive()
2959 gsm->state = GSM_SEARCH; in gsm0_receive()
2963 gsm->bad_size++; in gsm0_receive()
2966 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2972 * gsm1_receive_state_check_and_fix - check and correct receive state
2980 switch (gsm->state) { in gsm1_receive_state_check_and_fix()
2989 gsm->state = GSM_SEARCH; in gsm1_receive_state_check_and_fix()
2995 * gsm1_receive - perform processing for non-transparency
3007 gsm->constipated = true; in gsm1_receive()
3010 gsm->constipated = false; in gsm1_receive()
3017 if (gsm->state == GSM1_DATA) { in gsm1_receive()
3018 if (gsm->count < 1) { in gsm1_receive()
3020 gsm->malformed++; in gsm1_receive()
3021 gsm->state = GSM1_START; in gsm1_receive()
3025 gsm->count--; in gsm1_receive()
3026 if ((gsm->control & ~PF) != UIH) { in gsm1_receive()
3030 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm1_receive()
3031 gsm->count); in gsm1_receive()
3034 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
3035 gsm->len = gsm->count; in gsm1_receive()
3037 gsm->state = GSM1_START; in gsm1_receive()
3041 if (gsm->state != GSM1_START) { in gsm1_receive()
3042 if (gsm->state != GSM_SEARCH) in gsm1_receive()
3043 gsm->malformed++; in gsm1_receive()
3044 gsm->state = GSM1_START; in gsm1_receive()
3052 gsm->escape = true; in gsm1_receive()
3057 if (gsm->state == GSM_SEARCH) in gsm1_receive()
3060 if (gsm->escape) { in gsm1_receive()
3062 gsm->escape = false; in gsm1_receive()
3064 switch (gsm->state) { in gsm1_receive()
3066 gsm->address = 0; in gsm1_receive()
3067 gsm->state = GSM1_ADDRESS; in gsm1_receive()
3068 gsm->fcs = INIT_FCS; in gsm1_receive()
3071 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3072 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
3073 gsm->state = GSM1_CONTROL; in gsm1_receive()
3076 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3077 gsm->control = c; in gsm1_receive()
3078 gsm->count = 0; in gsm1_receive()
3079 gsm->state = GSM1_DATA; in gsm1_receive()
3082 if (gsm->count > gsm->mru || gsm->count > MAX_MRU) { /* Allow one for the FCS */ in gsm1_receive()
3083 gsm->state = GSM1_OVERRUN; in gsm1_receive()
3084 gsm->bad_size++; in gsm1_receive()
3086 gsm->buf[gsm->count++] = c; in gsm1_receive()
3088 case GSM1_OVERRUN: /* Over-long - eg a dropped SOF */ in gsm1_receive()
3091 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
3097 * gsm_error - handle tty error
3108 gsm->state = GSM_SEARCH; in gsm_error()
3109 gsm->io_error++; in gsm_error()
3113 * gsm_cleanup_mux - generic GSM protocol cleanup
3114 * @gsm: our mux
3117 * Clean up the bits of the mux which are the same for all framing
3118 * protocols. Remove the mux from the mux table, stop all the timers
3128 gsm->dead = true; in gsm_cleanup_mux()
3129 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
3131 dlci = gsm->dlci[0]; in gsm_cleanup_mux()
3133 if (disc && dlci->state != DLCI_CLOSED) { in gsm_cleanup_mux()
3135 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
3137 dlci->dead = true; in gsm_cleanup_mux()
3141 del_timer_sync(&gsm->kick_timer); in gsm_cleanup_mux()
3142 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
3143 del_timer_sync(&gsm->ka_timer); in gsm_cleanup_mux()
3146 flush_work(&gsm->tx_work); in gsm_cleanup_mux()
3149 if (gsm->has_devices) { in gsm_cleanup_mux()
3150 gsm_unregister_devices(gsm_tty_driver, gsm->num); in gsm_cleanup_mux()
3151 gsm->has_devices = false; in gsm_cleanup_mux()
3153 for (i = NUM_DLCI - 1; i >= 0; i--) in gsm_cleanup_mux()
3154 if (gsm->dlci[i]) in gsm_cleanup_mux()
3155 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
3156 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
3158 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
3160 guard(spinlock_irqsave)(&gsm->tx_lock); in gsm_cleanup_mux()
3161 list_for_each_entry_safe(txq, ntxq, &gsm->tx_ctrl_list, list) in gsm_cleanup_mux()
3163 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_cleanup_mux()
3164 list_for_each_entry_safe(txq, ntxq, &gsm->tx_data_list, list) in gsm_cleanup_mux()
3166 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_cleanup_mux()
3170 * gsm_activate_mux - generic GSM setup
3171 * @gsm: our mux
3173 * Set up the bits of the mux which are the same for all framing
3174 * protocols. Add the mux to the mux table so it can be opened and
3185 return -ENOMEM; in gsm_activate_mux()
3187 if (gsm->encoding == GSM_BASIC_OPT) in gsm_activate_mux()
3188 gsm->receive = gsm0_receive; in gsm_activate_mux()
3190 gsm->receive = gsm1_receive; in gsm_activate_mux()
3192 ret = gsm_register_devices(gsm_tty_driver, gsm->num); in gsm_activate_mux()
3196 gsm->has_devices = true; in gsm_activate_mux()
3197 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
3202 * gsm_free_mux - free up a mux
3203 * @gsm: mux to free
3205 * Dispose of allocated resources for a dead mux
3217 mutex_destroy(&gsm->mutex); in gsm_free_mux()
3218 kfree(gsm->txframe); in gsm_free_mux()
3219 kfree(gsm->buf); in gsm_free_mux()
3224 * gsm_free_muxr - free up a mux
3225 * @ref: kreference to the mux to free
3227 * Dispose of allocated resources for a dead mux
3240 kref_get(&gsm->ref); in mux_get()
3249 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
3255 return gsm->num * NUM_DLCI; in mux_num_to_base()
3264 * gsm_alloc_mux - allocate a mux
3266 * Creates a new mux ready for activation.
3275 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
3276 if (gsm->buf == NULL) { in gsm_alloc_mux()
3280 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
3281 if (gsm->txframe == NULL) { in gsm_alloc_mux()
3282 kfree(gsm->buf); in gsm_alloc_mux()
3286 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
3287 mutex_init(&gsm->mutex); in gsm_alloc_mux()
3288 kref_init(&gsm->ref); in gsm_alloc_mux()
3289 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_alloc_mux()
3290 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_alloc_mux()
3291 timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); in gsm_alloc_mux()
3292 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
3293 timer_setup(&gsm->ka_timer, gsm_control_keep_alive, 0); in gsm_alloc_mux()
3294 INIT_WORK(&gsm->tx_work, gsmld_write_task); in gsm_alloc_mux()
3295 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
3296 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
3297 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
3299 gsm->t1 = T1; in gsm_alloc_mux()
3300 gsm->t2 = T2; in gsm_alloc_mux()
3301 gsm->t3 = T3; in gsm_alloc_mux()
3302 gsm->n2 = N2; in gsm_alloc_mux()
3303 gsm->k = K; in gsm_alloc_mux()
3304 gsm->ftype = UIH; in gsm_alloc_mux()
3305 gsm->adaption = 1; in gsm_alloc_mux()
3306 gsm->encoding = GSM_ADV_OPT; in gsm_alloc_mux()
3307 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
3308 gsm->mtu = 64; in gsm_alloc_mux()
3309 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
3310 gsm->wait_config = false; /* Disabled */ in gsm_alloc_mux()
3311 gsm->keep_alive = 0; /* Disabled */ in gsm_alloc_mux()
3313 /* Store the instance to the mux array or abort if no space is in gsm_alloc_mux()
3320 gsm->num = i; in gsm_alloc_mux()
3326 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
3327 kfree(gsm->txframe); in gsm_alloc_mux()
3328 kfree(gsm->buf); in gsm_alloc_mux()
3340 c->adaption = gsm->adaption; in gsm_copy_config_values()
3341 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
3342 c->initiator = gsm->initiator; in gsm_copy_config_values()
3343 c->t1 = gsm->t1; in gsm_copy_config_values()
3344 c->t2 = gsm->t2; in gsm_copy_config_values()
3345 c->t3 = gsm->t3; in gsm_copy_config_values()
3346 c->n2 = gsm->n2; in gsm_copy_config_values()
3347 if (gsm->ftype == UIH) in gsm_copy_config_values()
3348 c->i = 1; in gsm_copy_config_values()
3350 c->i = 2; in gsm_copy_config_values()
3351 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
3352 c->mru = gsm->mru; in gsm_copy_config_values()
3353 c->mtu = gsm->mtu; in gsm_copy_config_values()
3354 c->k = gsm->k; in gsm_copy_config_values()
3362 /* Stuff we don't support yet - UI or I frame transport */ in gsm_config()
3363 if (c->adaption != 1 && c->adaption != 2) in gsm_config()
3364 return -EOPNOTSUPP; in gsm_config()
3366 if (c->mru < MIN_MTU || c->mtu < MIN_MTU) in gsm_config()
3367 return -EINVAL; in gsm_config()
3368 if (c->mru > MAX_MRU || c->mtu > MAX_MTU) in gsm_config()
3369 return -EINVAL; in gsm_config()
3370 if (c->t3 > MAX_T3) in gsm_config()
3371 return -EINVAL; in gsm_config()
3372 if (c->n2 > 255) in gsm_config()
3373 return -EINVAL; in gsm_config()
3374 if (c->encapsulation > 1) /* Basic, advanced, no I */ in gsm_config()
3375 return -EINVAL; in gsm_config()
3376 if (c->initiator > 1) in gsm_config()
3377 return -EINVAL; in gsm_config()
3378 if (c->k > MAX_WINDOW_SIZE) in gsm_config()
3379 return -EINVAL; in gsm_config()
3380 if (c->i == 0 || c->i > 2) /* UIH and UI only */ in gsm_config()
3381 return -EINVAL; in gsm_config()
3387 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
3389 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
3391 if (c->encapsulation != gsm->encoding) in gsm_config()
3393 if (c->adaption != gsm->adaption) in gsm_config()
3396 if (c->initiator != gsm->initiator) in gsm_config()
3398 if (c->mru != gsm->mru) in gsm_config()
3400 if (c->mtu != gsm->mtu) in gsm_config()
3411 gsm->initiator = c->initiator; in gsm_config()
3412 gsm->mru = c->mru; in gsm_config()
3413 gsm->mtu = c->mtu; in gsm_config()
3414 gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT; in gsm_config()
3415 gsm->adaption = c->adaption; in gsm_config()
3416 gsm->n2 = c->n2; in gsm_config()
3418 if (c->i == 1) in gsm_config()
3419 gsm->ftype = UIH; in gsm_config()
3420 else if (c->i == 2) in gsm_config()
3421 gsm->ftype = UI; in gsm_config()
3423 if (c->t1) in gsm_config()
3424 gsm->t1 = c->t1; in gsm_config()
3425 if (c->t2) in gsm_config()
3426 gsm->t2 = c->t2; in gsm_config()
3427 if (c->t3) in gsm_config()
3428 gsm->t3 = c->t3; in gsm_config()
3429 if (c->k) in gsm_config()
3430 gsm->k = c->k; in gsm_config()
3434 * and removing from the mux array in gsm_config()
3436 if (gsm->dead) { in gsm_config()
3440 if (gsm->initiator) in gsm_config()
3441 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
3450 ce->wait_config = gsm->wait_config ? 1 : 0; in gsm_copy_config_ext_values()
3451 ce->keep_alive = gsm->keep_alive; in gsm_copy_config_ext_values()
3463 for (i = 0; i < ARRAY_SIZE(ce->reserved); i++) in gsm_config_ext()
3464 if (ce->reserved[i]) in gsm_config_ext()
3465 return -EINVAL; in gsm_config_ext()
3466 if (ce->flags & ~GSM_FL_RESTART) in gsm_config_ext()
3467 return -EINVAL; in gsm_config_ext()
3470 if (ce->flags & GSM_FL_RESTART) in gsm_config_ext()
3484 gsm->wait_config = ce->wait_config ? true : false; in gsm_config_ext()
3485 gsm->keep_alive = ce->keep_alive; in gsm_config_ext()
3487 if (gsm->dead) { in gsm_config_ext()
3491 if (gsm->initiator) in gsm_config_ext()
3492 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config_ext()
3499 * gsmld_output - write to link
3500 * @gsm: our mux
3504 * Write a block of data from the GSM mux to the data channel. This
3510 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
3511 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
3512 return -ENOSPC; in gsmld_output()
3516 return gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
3521 * gsmld_write_trigger - schedule ldisc write task
3522 * @gsm: our mux
3526 if (!gsm || !gsm->dlci[0] || gsm->dlci[0]->dead) in gsmld_write_trigger()
3528 schedule_work(&gsm->tx_work); in gsmld_write_trigger()
3533 * gsmld_write_task - ldisc write task
3537 * avoid dead-locking. This returns if no space or data is left for output.
3548 ret = -ENODEV; in gsmld_write_task()
3549 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_task()
3550 if (gsm->tty) in gsmld_write_task()
3552 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_task()
3556 if (gsm->dlci[i]) in gsmld_write_task()
3557 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsmld_write_task()
3561 * gsmld_attach_gsm - mode set up
3563 * @gsm: our mux
3565 * Set up the MUX for basic mode and commence connecting to the
3572 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
3574 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
3575 tty->termios.c_iflag &= (IXON | IXOFF); in gsmld_attach_gsm()
3579 * gsmld_detach_gsm - stop doing 0710 mux
3580 * @tty: tty attached to the mux
3581 * @gsm: mux
3588 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
3590 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
3591 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
3592 gsm->tty = NULL; in gsmld_detach_gsm()
3598 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf()
3604 for (; count; count--, cp++) { in gsmld_receive_buf()
3609 if (gsm->receive) in gsmld_receive_buf()
3610 gsm->receive(gsm, *cp); in gsmld_receive_buf()
3629 * gsmld_flush_buffer - clean input queue
3642 * gsmld_close - close the ldisc for this tty
3653 struct gsm_mux *gsm = tty->disc_data; in gsmld_close()
3669 * gsmld_open - open an ldisc
3683 return -EPERM; in gsmld_open()
3685 if (tty->ops->write == NULL) in gsmld_open()
3686 return -EINVAL; in gsmld_open()
3691 return -ENOMEM; in gsmld_open()
3693 tty->disc_data = gsm; in gsmld_open()
3694 tty->receive_room = 65536; in gsmld_open()
3699 /* The mux will not be activated yet, we wait for correct in gsmld_open()
3702 if (gsm->encoding == GSM_BASIC_OPT) in gsmld_open()
3703 gsm->receive = gsm0_receive; in gsmld_open()
3705 gsm->receive = gsm1_receive; in gsmld_open()
3711 * gsmld_write_wakeup - asynchronous I/O notifier
3721 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup()
3728 * gsmld_read - read function for tty
3747 return -EOPNOTSUPP; in gsmld_read()
3751 * gsmld_write - write function for tty
3759 * as-is and must be properly framed and checksummed as appropriate
3767 struct gsm_mux *gsm = tty->disc_data; in gsmld_write()
3773 return -ENODEV; in gsmld_write()
3775 ret = -ENOBUFS; in gsmld_write()
3776 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
3779 ret = tty->ops->write(tty, buf, nr); in gsmld_write()
3781 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write()
3782 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
3788 * gsmld_poll - poll method for N_GSM0710
3798 * Called without the kernel lock held - fine
3805 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll()
3807 poll_wait(file, &tty->read_wait, wait); in gsmld_poll()
3808 poll_wait(file, &tty->write_wait, wait); in gsmld_poll()
3810 if (gsm->dead) in gsmld_poll()
3814 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in gsmld_poll()
3827 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl()
3835 return -EFAULT; in gsmld_ioctl()
3839 return -EFAULT; in gsmld_ioctl()
3847 return -EFAULT; in gsmld_ioctl()
3851 return -EFAULT; in gsmld_ioctl()
3855 return -EFAULT; in gsmld_ioctl()
3857 return -EINVAL; in gsmld_ioctl()
3859 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3863 return -ENOMEM; in gsmld_ioctl()
3867 return -EFAULT; in gsmld_ioctl()
3871 return -EFAULT; in gsmld_ioctl()
3873 return -EINVAL; in gsmld_ioctl()
3875 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3879 return -ENOMEM; in gsmld_ioctl()
3907 if (!dlci->net) { in dlci_net_free()
3911 dlci->adaption = dlci->prev_adaption; in dlci_net_free()
3912 dlci->data = dlci->prev_data; in dlci_net_free()
3913 free_netdev(dlci->net); in dlci_net_free()
3914 dlci->net = NULL; in dlci_net_free()
3922 dlci = mux_net->dlci; in net_free()
3924 if (dlci->net) { in net_free()
3925 unregister_netdev(dlci->net); in net_free()
3932 kref_get(&mux_net->ref); in muxnet_get()
3937 kref_put(&mux_net->ref, net_free); in muxnet_put()
3944 struct gsm_dlci *dlci = mux_net->dlci; in gsm_mux_net_start_xmit()
3947 skb_queue_head(&dlci->skb_list, skb); in gsm_mux_net_start_xmit()
3948 net->stats.tx_packets++; in gsm_mux_net_start_xmit()
3949 net->stats.tx_bytes += skb->len; in gsm_mux_net_start_xmit()
3961 dev_dbg(&net->dev, "Tx timed out.\n"); in gsm_mux_net_tx_timeout()
3964 net->stats.tx_errors++; in gsm_mux_net_tx_timeout()
3970 struct net_device *net = dlci->net; in gsm_mux_rx_netchar()
3979 net->stats.rx_dropped++; in gsm_mux_rx_netchar()
3986 skb->dev = net; in gsm_mux_rx_netchar()
3987 skb->protocol = htons(ETH_P_IP); in gsm_mux_rx_netchar()
3993 net->stats.rx_packets++; in gsm_mux_rx_netchar()
3994 net->stats.rx_bytes += size; in gsm_mux_rx_netchar()
4008 net->netdev_ops = &gsm_netdev_ops; in gsm_mux_net_init()
4011 net->watchdog_timeo = GSM_NET_TX_TIMEOUT; in gsm_mux_net_init()
4012 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in gsm_mux_net_init()
4013 net->type = ARPHRD_NONE; in gsm_mux_net_init()
4014 net->tx_queue_len = 10; in gsm_mux_net_init()
4024 if (!dlci->net) in gsm_destroy_network()
4026 mux_net = netdev_priv(dlci->net); in gsm_destroy_network()
4040 return -EPERM; in gsm_create_network()
4043 if (dlci->adaption > 2) in gsm_create_network()
4044 return -EBUSY; in gsm_create_network()
4046 if (nc->protocol != htons(ETH_P_IP)) in gsm_create_network()
4047 return -EPROTONOSUPPORT; in gsm_create_network()
4049 if (nc->adaption != 3 && nc->adaption != 4) in gsm_create_network()
4050 return -EPROTONOSUPPORT; in gsm_create_network()
4055 if (nc->if_name[0] != '\0') in gsm_create_network()
4056 netname = nc->if_name; in gsm_create_network()
4061 return -ENOMEM; in gsm_create_network()
4063 net->mtu = dlci->mtu; in gsm_create_network()
4064 net->min_mtu = MIN_MTU; in gsm_create_network()
4065 net->max_mtu = dlci->mtu; in gsm_create_network()
4067 mux_net->dlci = dlci; in gsm_create_network()
4068 kref_init(&mux_net->ref); in gsm_create_network()
4069 strncpy(nc->if_name, net->name, IFNAMSIZ); /* return net name */ in gsm_create_network()
4072 dlci->prev_adaption = dlci->adaption; in gsm_create_network()
4073 dlci->prev_data = dlci->data; in gsm_create_network()
4074 dlci->adaption = nc->adaption; in gsm_create_network()
4075 dlci->data = gsm_mux_rx_netchar; in gsm_create_network()
4076 dlci->net = net; in gsm_create_network()
4085 return net->ifindex; /* return network index */ in gsm_create_network()
4109 * gsm_modem_upd_via_data - send modem bits via convergence layer
4119 struct gsm_mux *gsm = dlci->gsm; in gsm_modem_upd_via_data()
4122 if (dlci->state != DLCI_OPEN || dlci->adaption != 2) in gsm_modem_upd_via_data()
4125 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4127 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4131 * gsm_modem_upd_via_msc - send modem bits via control frame
4139 struct gsm_control *ctrl; in gsm_modem_upd_via_msc() local
4142 if (dlci->gsm->encoding != GSM_BASIC_OPT) in gsm_modem_upd_via_msc()
4145 modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ in gsm_modem_upd_via_msc()
4153 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsm_modem_upd_via_msc()
4154 if (ctrl == NULL) in gsm_modem_upd_via_msc()
4155 return -ENOMEM; in gsm_modem_upd_via_msc()
4156 return gsm_control_wait(dlci->gsm, ctrl); in gsm_modem_upd_via_msc()
4160 * gsm_modem_update - send modem status line state
4167 if (dlci->gsm->dead) in gsm_modem_update()
4168 return -EL2HLT; in gsm_modem_update()
4169 if (dlci->adaption == 2) { in gsm_modem_update()
4173 } else if (dlci->gsm->encoding == GSM_BASIC_OPT) { in gsm_modem_update()
4179 return -EPROTONOSUPPORT; in gsm_modem_update()
4183 * gsm_wait_modem_change - wait for modem status line change
4188 * - any given modem status line bit changed
4189 * - the wait event function got interrupted (e.g. by a signal)
4190 * - the underlying DLCI was closed
4191 * - the underlying ldisc device was removed
4195 struct gsm_mux *gsm = dlci->gsm; in gsm_wait_modem_change()
4196 u32 old = dlci->modem_rx; in gsm_wait_modem_change()
4199 ret = wait_event_interruptible(gsm->event, gsm->dead || in gsm_wait_modem_change()
4200 dlci->state != DLCI_OPEN || in gsm_wait_modem_change()
4201 (old ^ dlci->modem_rx) & mask); in gsm_wait_modem_change()
4202 if (gsm->dead) in gsm_wait_modem_change()
4203 return -ENODEV; in gsm_wait_modem_change()
4204 if (dlci->state != DLCI_OPEN) in gsm_wait_modem_change()
4205 return -EL2NSYNC; in gsm_wait_modem_change()
4212 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised()
4215 if (dlci->state != DLCI_OPEN) in gsm_carrier_raised()
4224 if (gsm->encoding == GSM_BASIC_OPT && in gsm_carrier_raised()
4225 gsm->dlci[0]->mode == DLCI_MODE_ADM && !dlci->modem_rx) in gsm_carrier_raised()
4228 return dlci->modem_rx & TIOCM_CD; in gsm_carrier_raised()
4234 unsigned int modem_tx = dlci->modem_tx; in gsm_dtr_rts()
4239 if (modem_tx != dlci->modem_tx) { in gsm_dtr_rts()
4240 dlci->modem_tx = modem_tx; in gsm_dtr_rts()
4255 unsigned int line = tty->index; in gsmtty_install()
4256 unsigned int mux = mux_line_to_num(line); in gsmtty_install() local
4262 if (mux >= MAX_MUX) in gsmtty_install()
4263 return -ENXIO; in gsmtty_install()
4265 if (gsm_mux[mux] == NULL) in gsmtty_install()
4266 return -EUNATCH; in gsmtty_install()
4268 return -ECHRNG; in gsmtty_install()
4269 gsm = gsm_mux[mux]; in gsmtty_install()
4270 if (gsm->dead) in gsmtty_install()
4271 return -EL2HLT; in gsmtty_install()
4276 mutex_lock(&gsm->mutex); in gsmtty_install()
4277 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) { in gsmtty_install()
4278 mutex_unlock(&gsm->mutex); in gsmtty_install()
4279 return -EL2NSYNC; in gsmtty_install()
4281 dlci = gsm->dlci[line]; in gsmtty_install()
4287 mutex_unlock(&gsm->mutex); in gsmtty_install()
4288 return -ENOMEM; in gsmtty_install()
4290 ret = tty_port_install(&dlci->port, driver, tty); in gsmtty_install()
4294 mutex_unlock(&gsm->mutex); in gsmtty_install()
4299 dlci_get(gsm->dlci[0]); in gsmtty_install()
4301 tty->driver_data = dlci; in gsmtty_install()
4302 mutex_unlock(&gsm->mutex); in gsmtty_install()
4309 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_open()
4310 struct tty_port *port = &dlci->port; in gsmtty_open()
4312 port->count++; in gsmtty_open()
4315 dlci->modem_rx = 0; in gsmtty_open()
4316 /* We could in theory open and close before we wait - eg if we get in gsmtty_open()
4320 if (!dlci->gsm->wait_config) { in gsmtty_open()
4322 if (dlci->gsm->initiator) in gsmtty_open()
4335 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_close()
4339 if (dlci->state == DLCI_CLOSED) in gsmtty_close()
4341 mutex_lock(&dlci->mutex); in gsmtty_close()
4343 mutex_unlock(&dlci->mutex); in gsmtty_close()
4344 if (tty_port_close_start(&dlci->port, tty, filp) == 0) in gsmtty_close()
4347 if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) in gsmtty_close()
4348 tty_port_lower_dtr_rts(&dlci->port); in gsmtty_close()
4349 tty_port_close_end(&dlci->port, tty); in gsmtty_close()
4350 tty_port_tty_set(&dlci->port, NULL); in gsmtty_close()
4356 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_hangup()
4357 if (dlci->state == DLCI_CLOSED) in gsmtty_hangup()
4359 tty_port_hangup(&dlci->port); in gsmtty_hangup()
4366 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write()
4367 if (dlci->state == DLCI_CLOSED) in gsmtty_write()
4368 return -EINVAL; in gsmtty_write()
4370 sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock); in gsmtty_write()
4378 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write_room()
4379 if (dlci->state == DLCI_CLOSED) in gsmtty_write_room()
4381 return kfifo_avail(&dlci->fifo); in gsmtty_write_room()
4386 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_chars_in_buffer()
4387 if (dlci->state == DLCI_CLOSED) in gsmtty_chars_in_buffer()
4389 return kfifo_len(&dlci->fifo); in gsmtty_chars_in_buffer()
4394 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_flush_buffer()
4397 if (dlci->state == DLCI_CLOSED) in gsmtty_flush_buffer()
4403 spin_lock_irqsave(&dlci->lock, flags); in gsmtty_flush_buffer()
4404 kfifo_reset(&dlci->fifo); in gsmtty_flush_buffer()
4405 spin_unlock_irqrestore(&dlci->lock, flags); in gsmtty_flush_buffer()
4418 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmget()
4419 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmget()
4420 return -EINVAL; in gsmtty_tiocmget()
4421 return dlci->modem_rx; in gsmtty_tiocmget()
4427 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmset()
4428 unsigned int modem_tx = dlci->modem_tx; in gsmtty_tiocmset()
4430 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmset()
4431 return -EINVAL; in gsmtty_tiocmset()
4435 if (modem_tx != dlci->modem_tx) { in gsmtty_tiocmset()
4436 dlci->modem_tx = modem_tx; in gsmtty_tiocmset()
4446 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_ioctl()
4451 if (dlci->state == DLCI_CLOSED) in gsmtty_ioctl()
4452 return -EINVAL; in gsmtty_ioctl()
4456 return -EFAULT; in gsmtty_ioctl()
4457 nc.if_name[IFNAMSIZ-1] = '\0'; in gsmtty_ioctl()
4459 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4461 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4463 return -EFAULT; in gsmtty_ioctl()
4467 return -EPERM; in gsmtty_ioctl()
4468 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4470 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4474 return -EFAULT; in gsmtty_ioctl()
4475 if (dc.channel != dlci->addr) in gsmtty_ioctl()
4476 return -EPERM; in gsmtty_ioctl()
4479 return -EFAULT; in gsmtty_ioctl()
4483 return -EFAULT; in gsmtty_ioctl()
4485 return -EINVAL; in gsmtty_ioctl()
4486 if (dc.channel != 0 && dc.channel != dlci->addr) in gsmtty_ioctl()
4487 return -EPERM; in gsmtty_ioctl()
4492 return -ENOIOCTLCMD; in gsmtty_ioctl()
4499 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_set_termios()
4500 if (dlci->state == DLCI_CLOSED) in gsmtty_set_termios()
4507 tty_termios_copy_hw(&tty->termios, old); in gsmtty_set_termios()
4512 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_throttle()
4513 if (dlci->state == DLCI_CLOSED) in gsmtty_throttle()
4516 dlci->modem_tx &= ~TIOCM_RTS; in gsmtty_throttle()
4517 dlci->throttled = true; in gsmtty_throttle()
4524 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_unthrottle()
4525 if (dlci->state == DLCI_CLOSED) in gsmtty_unthrottle()
4528 dlci->modem_tx |= TIOCM_RTS; in gsmtty_unthrottle()
4529 dlci->throttled = false; in gsmtty_unthrottle()
4536 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_break_ctl()
4538 if (dlci->state == DLCI_CLOSED) in gsmtty_break_ctl()
4539 return -EINVAL; in gsmtty_break_ctl()
4541 if (state == -1) /* "On indefinitely" - we can't encode this in gsmtty_break_ctl()
4554 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_cleanup()
4555 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup()
4558 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
4602 gsm_tty_driver->driver_name = "gsmtty"; in gsm_init()
4603 gsm_tty_driver->name = "gsmtty"; in gsm_init()
4604 gsm_tty_driver->major = 0; /* Dynamic */ in gsm_init()
4605 gsm_tty_driver->minor_start = 0; in gsm_init()
4606 gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; in gsm_init()
4607 gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; in gsm_init()
4608 gsm_tty_driver->init_termios = tty_std_termios; in gsm_init()
4610 gsm_tty_driver->init_termios.c_lflag &= ~ECHO; in gsm_init()
4615 status = -EBUSY; in gsm_init()
4619 gsm_tty_driver->major, gsm_tty_driver->minor_start); in gsm_init()