Lines Matching +full:single +full:- +full:mux +full:- +full:ctrl

1 // SPDX-License-Identifier: GPL-2.0
10 * tty -> DLCI fifo -> scheduler -> GSM MUX data queue ---o-> ldisc
11 * control message -> GSM MUX control queue --´
14 * ldisc -> gsm_queue() -o--> tty
15 * `-> gsm_control_response()
25 * Review the locking/move to refcounts more (mux now moved to an
30 * Do we need a 'which mux are you' ioctl to correlate mux and tty sets
96 * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte
102 /* SOF, ADDR, CTRL, LEN1, LEN2, ..., FCS, EOF */
107 * struct gsm_mux_net - network interface
125 u8 ctrl; /* Control byte + flags */ member
148 * complexity right now these are only ever freed up when the mux is
151 * At the moment we don't free DLCI objects until the mux is torn down
175 bool dead; /* Refuse re-open */
263 * Each GSM mux we have is represented by this structure. If we are
266 * to the gsm mux array. For now we don't free DLCI objects that
267 * have been instantiated until the mux itself is terminated.
269 * To consider further: tty open versus mux shutdown.
306 bool dead; /* Has the mux been shut down */
326 /* Keep-alive */
327 struct timer_list ka_timer; /* Keep-alive response timer */
328 u8 ka_num; /* Keep-alive match pattern */
329 signed int ka_retries; /* Keep-alive retry counter, -1 if not yet initialized */
335 unsigned int t3; /* Power wake-up timer in seconds. */
339 u32 keep_alive; /* Control channel keep-alive in 10ms */
352 * Mux objects - needed so that we can translate a tty index into the
353 * relevant mux and DLCI.
459 u8 ctrl);
466 * gsm_fcs_add - update FCS
480 * gsm_fcs_add_block - update FCS for a block
491 while (len--) in gsm_fcs_add_block()
497 * gsm_read_ea - read a byte into an EA
515 * gsm_read_ea_val - read a value until EA
527 for (; dlen > 0; dlen--) { in gsm_read_ea_val()
536 * gsm_encode_modem - encode modem data bits
547 if (dlci->throttled) in gsm_encode_modem()
549 if (dlci->modem_tx & TIOCM_DTR) in gsm_encode_modem()
551 if (dlci->modem_tx & TIOCM_RTS) in gsm_encode_modem()
553 if (dlci->modem_tx & TIOCM_RI) in gsm_encode_modem()
555 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
558 if (dlci->modem_tx & TIOCM_OUT1) in gsm_encode_modem()
560 if (dlci->modem_tx & TIOCM_OUT2) in gsm_encode_modem()
585 * gsm_encode_params - encode DLCI parameters
595 const struct gsm_mux *gsm = dlci->gsm; in gsm_encode_params()
598 switch (dlci->ftype) { in gsm_encode_params()
606 pr_debug("unsupported frame type %d\n", dlci->ftype); in gsm_encode_params()
607 return -EINVAL; in gsm_encode_params()
610 switch (dlci->adaption) { in gsm_encode_params()
618 pr_debug("unsupported adaption %d\n", dlci->adaption); in gsm_encode_params()
619 return -EINVAL; in gsm_encode_params()
622 params->d_bits = FIELD_PREP(PN_D_FIELD_DLCI, dlci->addr); in gsm_encode_params()
624 params->i_cl_bits = FIELD_PREP(PN_I_CL_FIELD_FTYPE, i) | in gsm_encode_params()
626 params->p_bits = FIELD_PREP(PN_P_FIELD_PRIO, dlci->prio); in gsm_encode_params()
627 params->t_bits = FIELD_PREP(PN_T_FIELD_T1, gsm->t1); in gsm_encode_params()
628 params->n_bits = cpu_to_le16(FIELD_PREP(PN_N_FIELD_N1, dlci->mtu)); in gsm_encode_params()
629 params->na_bits = FIELD_PREP(PN_NA_FIELD_N2, gsm->n2); in gsm_encode_params()
630 params->k_bits = FIELD_PREP(PN_K_FIELD_K, dlci->k); in gsm_encode_params()
636 * gsm_register_devices - register all tty devices for a given mux index
639 * @index: the mux number is used to calculate the minor numbers of the
640 * ttys for this mux and may differ from the position in the
641 * mux array.
650 return -EINVAL; in gsm_register_devices()
654 /* Don't register device 0 - this is the control channel in gsm_register_devices()
662 for (i--; i >= 1; i--) in gsm_register_devices()
672 * gsm_unregister_devices - unregister all tty devices for a given mux index
675 * @index: the mux number is used to calculate the minor numbers of the
676 * ttys for this mux and may differ from the position in the
677 * mux array.
690 /* Don't unregister device 0 - this is the control in gsm_unregister_devices()
698 * gsm_print_packet - display a frame for debug
707 * style is based on amateur radio LAP-B dump display.
774 * gsm_stuff_frame - bytestuff a packet
787 while (len--) { in gsm_stuff_frame()
802 * gsm_send - send a control frame
803 * @gsm: our GSM mux
820 return -ENOMEM; in gsm_send()
823 ocr = cr ^ (gsm->initiator ? 0 : 1); in gsm_send()
825 msg->data -= 3; in gsm_send()
826 dp = msg->data; in gsm_send()
830 if (gsm->encoding == GSM_BASIC_OPT) in gsm_send()
833 *dp = 0xFF - gsm_fcs_add_block(INIT_FCS, msg->data, dp - msg->data); in gsm_send()
834 msg->len = (dp - msg->data) + 1; in gsm_send()
836 gsm_print_packet("Q->", addr, cr, control, NULL, 0); in gsm_send()
838 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_send()
839 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in gsm_send()
840 gsm->tx_bytes += msg->len; in gsm_send()
841 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_send()
848 * gsm_dlci_clear_queues - remove outstanding data for a DLCI
849 * @gsm: mux
857 int addr = dlci->addr; in gsm_dlci_clear_queues()
861 spin_lock_irqsave(&dlci->lock, flags); in gsm_dlci_clear_queues()
862 kfifo_reset(&dlci->fifo); in gsm_dlci_clear_queues()
863 spin_unlock_irqrestore(&dlci->lock, flags); in gsm_dlci_clear_queues()
865 /* Clear data packets in MUX write queue */ in gsm_dlci_clear_queues()
866 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
867 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_dlci_clear_queues()
868 if (msg->addr != addr) in gsm_dlci_clear_queues()
870 gsm->tx_bytes -= msg->len; in gsm_dlci_clear_queues()
871 list_del(&msg->list); in gsm_dlci_clear_queues()
874 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
878 * gsm_response - send a control response
879 * @gsm: our GSM mux
892 * gsm_command - send a control command
893 * @gsm: our GSM mux
907 #define HDR_LEN 6 /* ADDR CTRL [LEN.2] DATA FCS */
910 * gsm_data_alloc - allocate data frame
911 * @gsm: GSM mux
914 * @ctrl: control byte
922 u8 ctrl) in gsm_data_alloc() argument
928 m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ in gsm_data_alloc()
929 m->len = len; in gsm_data_alloc()
930 m->addr = addr; in gsm_data_alloc()
931 m->ctrl = ctrl; in gsm_data_alloc()
932 INIT_LIST_HEAD(&m->list); in gsm_data_alloc()
937 * gsm_send_packet - sends a single packet
938 * @gsm: GSM Mux
949 if (gsm->encoding == GSM_BASIC_OPT) { in gsm_send_packet()
950 gsm->txframe[0] = GSM0_SOF; in gsm_send_packet()
951 memcpy(gsm->txframe + 1, msg->data, msg->len); in gsm_send_packet()
952 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_send_packet()
953 len = msg->len + 2; in gsm_send_packet()
955 gsm->txframe[0] = GSM1_SOF; in gsm_send_packet()
956 len = gsm_stuff_frame(msg->data, gsm->txframe + 1, msg->len); in gsm_send_packet()
957 gsm->txframe[len + 1] = GSM1_SOF; in gsm_send_packet()
962 gsm_hex_dump_bytes(__func__, gsm->txframe, len); in gsm_send_packet()
963 gsm_print_packet("-->", msg->addr, gsm->initiator, msg->ctrl, msg->data, in gsm_send_packet()
964 msg->len); in gsm_send_packet()
966 ret = gsmld_output(gsm, gsm->txframe, len); in gsm_send_packet()
970 gsm->tx_bytes -= msg->len; in gsm_send_packet()
976 * gsm_is_flow_ctrl_msg - checks if flow control message
986 if (msg->addr > 0) in gsm_is_flow_ctrl_msg()
989 switch (msg->ctrl & ~PF) { in gsm_is_flow_ctrl_msg()
993 if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) in gsm_is_flow_ctrl_msg()
1007 * gsm_data_kick - poke the queue
1008 * @gsm: GSM Mux
1012 * If we have been flow-stopped by a CMD_FCOFF, then we can only
1022 clear_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsm_data_kick()
1025 list_for_each_entry_safe(msg, nmsg, &gsm->tx_ctrl_list, list) { in gsm_data_kick()
1026 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
1030 case -ENOSPC: in gsm_data_kick()
1031 return -ENOSPC; in gsm_data_kick()
1032 case -ENODEV: in gsm_data_kick()
1034 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1035 list_del(&msg->list); in gsm_data_kick()
1040 list_del(&msg->list); in gsm_data_kick()
1047 if (gsm->constipated) in gsm_data_kick()
1048 return -EAGAIN; in gsm_data_kick()
1051 if (list_empty(&gsm->tx_data_list)) in gsm_data_kick()
1053 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_data_kick()
1054 dlci = gsm->dlci[msg->addr]; in gsm_data_kick()
1056 if (dlci->state != DLCI_OPEN) { in gsm_data_kick()
1057 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1058 list_del(&msg->list); in gsm_data_kick()
1064 case -ENOSPC: in gsm_data_kick()
1065 return -ENOSPC; in gsm_data_kick()
1066 case -ENODEV: in gsm_data_kick()
1068 gsm->tx_bytes -= msg->len; in gsm_data_kick()
1069 list_del(&msg->list); in gsm_data_kick()
1074 list_del(&msg->list); in gsm_data_kick()
1085 * __gsm_data_queue - queue a UI or UIH frame
1090 * out of the mux tty if not already doing so. The Caller must hold
1096 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue()
1097 u8 *dp = msg->data; in __gsm_data_queue()
1098 u8 *fcs = dp + msg->len; in __gsm_data_queue()
1101 if (gsm->encoding == GSM_BASIC_OPT) { in __gsm_data_queue()
1102 if (msg->len < 128) in __gsm_data_queue()
1103 *--dp = (msg->len << 1) | EA; in __gsm_data_queue()
1105 *--dp = (msg->len >> 7); /* bits 7 - 15 */ in __gsm_data_queue()
1106 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ in __gsm_data_queue()
1110 *--dp = msg->ctrl; in __gsm_data_queue()
1111 if (gsm->initiator) in __gsm_data_queue()
1112 *--dp = (msg->addr << 2) | CR | EA; in __gsm_data_queue()
1114 *--dp = (msg->addr << 2) | EA; in __gsm_data_queue()
1115 *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); in __gsm_data_queue()
1117 if (msg->ctrl == UI || msg->ctrl == (UI|PF)) in __gsm_data_queue()
1118 *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); in __gsm_data_queue()
1119 *fcs = 0xFF - *fcs; in __gsm_data_queue()
1121 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
1122 msg->data, msg->len); in __gsm_data_queue()
1126 msg->len += (msg->data - dp) + 1; in __gsm_data_queue()
1127 msg->data = dp; in __gsm_data_queue()
1130 switch (msg->ctrl & ~PF) { in __gsm_data_queue()
1133 if (msg->addr > 0) { in __gsm_data_queue()
1134 list_add_tail(&msg->list, &gsm->tx_data_list); in __gsm_data_queue()
1139 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in __gsm_data_queue()
1142 gsm->tx_bytes += msg->len; in __gsm_data_queue()
1145 mod_timer(&gsm->kick_timer, jiffies + 10 * gsm->t1 * HZ / 100); in __gsm_data_queue()
1149 * gsm_data_queue - queue a UI or UIH frame
1154 * out of the mux tty if not already doing so. Take the
1161 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1163 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1167 * gsm_dlci_data_output - try and push data out of a DLCI
1168 * @gsm: mux
1172 * is data. Keep to the MRU of the mux. This path handles the usual tty
1175 * Caller must hold the tx_lock of the mux.
1185 h = ((dlci->adaption == 1) ? 0 : 1); in gsm_dlci_data_output()
1187 len = kfifo_len(&dlci->fifo); in gsm_dlci_data_output()
1192 if ((len + h) > dlci->mtu) in gsm_dlci_data_output()
1193 len = dlci->mtu - h; in gsm_dlci_data_output()
1197 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output()
1199 return -ENOMEM; in gsm_dlci_data_output()
1200 dp = msg->data; in gsm_dlci_data_output()
1201 switch (dlci->adaption) { in gsm_dlci_data_output()
1211 dlci->adaption); in gsm_dlci_data_output()
1215 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len, in gsm_dlci_data_output()
1216 &dlci->lock)); in gsm_dlci_data_output()
1219 tty_port_tty_wakeup(&dlci->port); in gsm_dlci_data_output()
1227 * gsm_dlci_data_output_framed - try and push data out of a DLCI
1228 * @gsm: mux
1232 * is data. Keep to the MRU of the mux. This path handles framed data
1235 * Caller must hold the tx_lock of the mux.
1248 if (dlci->adaption == 4) in gsm_dlci_data_output_framed()
1251 /* dlci->skb is locked by tx_lock */ in gsm_dlci_data_output_framed()
1252 if (dlci->skb == NULL) { in gsm_dlci_data_output_framed()
1253 dlci->skb = skb_dequeue_tail(&dlci->skb_list); in gsm_dlci_data_output_framed()
1254 if (dlci->skb == NULL) in gsm_dlci_data_output_framed()
1258 len = dlci->skb->len + overhead; in gsm_dlci_data_output_framed()
1261 if (len > dlci->mtu) { in gsm_dlci_data_output_framed()
1262 if (dlci->adaption == 3) { in gsm_dlci_data_output_framed()
1264 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1265 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1268 len = dlci->mtu; in gsm_dlci_data_output_framed()
1273 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_data_output_framed()
1275 skb_queue_tail(&dlci->skb_list, dlci->skb); in gsm_dlci_data_output_framed()
1276 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1277 return -ENOMEM; in gsm_dlci_data_output_framed()
1279 dp = msg->data; in gsm_dlci_data_output_framed()
1281 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ in gsm_dlci_data_output_framed()
1284 len--; in gsm_dlci_data_output_framed()
1286 memcpy(dp, dlci->skb->data, len); in gsm_dlci_data_output_framed()
1287 skb_pull(dlci->skb, len); in gsm_dlci_data_output_framed()
1290 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1291 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1297 * gsm_dlci_modem_output - try and push modem status out of a DLCI
1298 * @gsm: mux
1305 * Caller must hold the tx_lock of the mux.
1316 switch (dlci->adaption) { in gsm_dlci_modem_output()
1326 dlci->adaption); in gsm_dlci_modem_output()
1327 return -EINVAL; in gsm_dlci_modem_output()
1330 msg = gsm_data_alloc(gsm, dlci->addr, size, dlci->ftype); in gsm_dlci_modem_output()
1333 return -ENOMEM; in gsm_dlci_modem_output()
1335 dp = msg->data; in gsm_dlci_modem_output()
1336 switch (dlci->adaption) { in gsm_dlci_modem_output()
1357 * gsm_dlci_data_sweep - look for data to send
1358 * @gsm: the GSM mux
1360 * Sweep the GSM mux channels in priority order looking for ones with
1376 while (gsm->tx_bytes < TX_THRESH_HI) { in gsm_dlci_data_sweep()
1378 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1380 if (!dlci || dlci->constipated) in gsm_dlci_data_sweep()
1383 if (dlci->state != DLCI_OPEN) in gsm_dlci_data_sweep()
1386 if (dlci->adaption < 3 && !dlci->net) in gsm_dlci_data_sweep()
1409 * gsm_dlci_data_kick - transmit if possible
1422 if (dlci->constipated) in gsm_dlci_data_kick()
1425 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1427 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1428 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1429 if (dlci->net) in gsm_dlci_data_kick()
1430 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1432 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1435 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1436 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1445 * gsm_control_command - send a command frame to a control
1457 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_command()
1459 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_command()
1461 return -ENOMEM; in gsm_control_command()
1463 msg->data[0] = (cmd << 1) | CR | EA; /* Set C/R */ in gsm_control_command()
1464 msg->data[1] = (dlen << 1) | EA; in gsm_control_command()
1465 memcpy(msg->data + 2, data, dlen); in gsm_control_command()
1472 * gsm_control_reply - send a response frame to a control
1485 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_reply()
1487 msg = gsm_data_alloc(gsm, 0, dlen + 2, dlci->ftype); in gsm_control_reply()
1490 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ in gsm_control_reply()
1491 msg->data[1] = (dlen << 1) | EA; in gsm_control_reply()
1492 memcpy(msg->data + 2, data, dlen); in gsm_control_reply()
1497 * gsm_process_modem - process received modem status
1516 * section 5.4.6.3.7 of the 07.10 mux spec. in gsm_process_modem()
1528 if (fc && !dlci->constipated) { in gsm_process_modem()
1530 dlci->constipated = true; in gsm_process_modem()
1531 } else if (!fc && dlci->constipated) { in gsm_process_modem()
1532 dlci->constipated = false; in gsm_process_modem()
1546 /* Carrier drop -> hangup */ in gsm_process_modem()
1548 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) in gsm_process_modem()
1553 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); in gsm_process_modem()
1554 dlci->modem_rx = mlines; in gsm_process_modem()
1555 wake_up_interruptible(&dlci->gsm->event); in gsm_process_modem()
1559 * gsm_process_negotiation - process received parameters
1572 struct gsm_dlci *dlci = gsm->dlci[addr]; in gsm_process_negotiation()
1575 i = FIELD_GET(PN_I_CL_FIELD_FTYPE, params->i_cl_bits); in gsm_process_negotiation()
1576 adaption = FIELD_GET(PN_I_CL_FIELD_ADAPTION, params->i_cl_bits) + 1; in gsm_process_negotiation()
1577 prio = FIELD_GET(PN_P_FIELD_PRIO, params->p_bits); in gsm_process_negotiation()
1578 n1 = FIELD_GET(PN_N_FIELD_N1, get_unaligned_le16(&params->n_bits)); in gsm_process_negotiation()
1579 k = FIELD_GET(PN_K_FIELD_K, params->k_bits); in gsm_process_negotiation()
1584 return -EINVAL; in gsm_process_negotiation()
1598 gsm->unsupported++; in gsm_process_negotiation()
1599 return -EINVAL; in gsm_process_negotiation()
1603 return -EINVAL; in gsm_process_negotiation()
1606 if (!cr && gsm->initiator) { in gsm_process_negotiation()
1607 if (adaption != dlci->adaption) { in gsm_process_negotiation()
1611 return -EINVAL; in gsm_process_negotiation()
1613 if (prio != dlci->prio) { in gsm_process_negotiation()
1617 return -EINVAL; in gsm_process_negotiation()
1619 if (n1 > gsm->mru || n1 > dlci->mtu) { in gsm_process_negotiation()
1627 return -EINVAL; in gsm_process_negotiation()
1629 dlci->mtu = n1; in gsm_process_negotiation()
1630 if (ftype != dlci->ftype) { in gsm_process_negotiation()
1633 return -EINVAL; in gsm_process_negotiation()
1635 if (ftype != UI && ftype != UIH && k > dlci->k) { in gsm_process_negotiation()
1638 return -EINVAL; in gsm_process_negotiation()
1640 dlci->k = k; in gsm_process_negotiation()
1641 } else if (cr && !gsm->initiator) { in gsm_process_negotiation()
1647 return -EINVAL; in gsm_process_negotiation()
1649 dlci->adaption = adaption; in gsm_process_negotiation()
1650 if (n1 > gsm->mru) { in gsm_process_negotiation()
1652 dlci->mtu = gsm->mru; in gsm_process_negotiation()
1655 dlci->mtu = MAX_MTU; in gsm_process_negotiation()
1657 dlci->mtu = n1; in gsm_process_negotiation()
1659 dlci->prio = prio; in gsm_process_negotiation()
1660 dlci->ftype = ftype; in gsm_process_negotiation()
1661 dlci->k = k; in gsm_process_negotiation()
1663 return -EINVAL; in gsm_process_negotiation()
1670 * gsm_control_modem - modem status received
1676 * the GSM mux protocol to pass virtual modem line status and optionally
1697 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1699 dlci = gsm->dlci[addr]; in gsm_control_modem()
1702 if ((cl - len) < 1) in gsm_control_modem()
1706 cl -= len; in gsm_control_modem()
1713 tty = tty_port_tty_get(&dlci->port); in gsm_control_modem()
1723 * gsm_control_negotiation - parameter negotiation received
1730 * the GSM mux protocol to configure protocol parameters for a new DLCI.
1741 gsm->open_error++; in gsm_control_negotiation()
1747 addr = FIELD_GET(PN_D_FIELD_DLCI, params->d_bits); in gsm_control_negotiation()
1748 if (addr == 0 || addr >= NUM_DLCI || !gsm->dlci[addr]) { in gsm_control_negotiation()
1749 gsm->open_error++; in gsm_control_negotiation()
1752 dlci = gsm->dlci[addr]; in gsm_control_negotiation()
1755 if ((!cr && dlci->state == DLCI_OPENING) || dlci->state == DLCI_OPEN) { in gsm_control_negotiation()
1756 gsm->open_error++; in gsm_control_negotiation()
1765 gsm->open_error++; in gsm_control_negotiation()
1777 } else if (dlci->state == DLCI_CONFIGURE) { in gsm_control_negotiation()
1779 dlci->state = DLCI_OPENING; in gsm_control_negotiation()
1780 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_control_negotiation()
1781 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_control_negotiation()
1785 gsm->open_error++; in gsm_control_negotiation()
1790 * gsm_control_rls - remote line status
1809 len--; in gsm_control_rls()
1814 len--; in gsm_control_rls()
1819 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1826 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1843 * gsm_control_message - DLCI 0 control processing
1844 * @gsm: our GSM mux
1861 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1864 dlci->dead = true; in gsm_control_message()
1865 gsm->dead = true; in gsm_control_message()
1876 gsm->constipated = false; in gsm_control_message()
1883 gsm->constipated = true; in gsm_control_message()
1906 gsm->unsupported++; in gsm_control_message()
1917 * gsm_control_response - process a response to our control
1918 * @gsm: our GSM mux
1923 * Process a response to an outstanding command. We only allow a single
1932 struct gsm_control *ctrl; in gsm_control_response() local
1936 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1938 ctrl = gsm->pending_cmd; in gsm_control_response()
1939 dlci = gsm->dlci[0]; in gsm_control_response()
1942 if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { in gsm_control_response()
1944 del_timer(&gsm->t2_timer); in gsm_control_response()
1945 gsm->pending_cmd = NULL; in gsm_control_response()
1948 ctrl->error = -EOPNOTSUPP; in gsm_control_response()
1949 ctrl->done = 1; in gsm_control_response()
1950 wake_up(&gsm->event); in gsm_control_response()
1955 } else if (command == CMD_TEST && clen == 1 && *data == gsm->ka_num) { in gsm_control_response()
1956 gsm->ka_retries = -1; /* trigger new keep-alive message */ in gsm_control_response()
1957 if (dlci && !dlci->dead) in gsm_control_response()
1958 mod_timer(&gsm->ka_timer, jiffies + gsm->keep_alive * HZ / 100); in gsm_control_response()
1960 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1964 * gsm_control_keep_alive - check timeout or start keep-alive
1967 * Called off the keep-alive timer expiry signaling that our link
1977 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_keep_alive()
1978 if (gsm->ka_num && gsm->ka_retries == 0) { in gsm_control_keep_alive()
1979 /* Keep-alive expired -> close the link */ in gsm_control_keep_alive()
1981 pr_debug("%s keep-alive timed out\n", __func__); in gsm_control_keep_alive()
1982 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
1983 if (gsm->dlci[0]) in gsm_control_keep_alive()
1984 gsm_dlci_begin_close(gsm->dlci[0]); in gsm_control_keep_alive()
1986 } else if (gsm->keep_alive && gsm->dlci[0] && !gsm->dlci[0]->dead) { in gsm_control_keep_alive()
1987 if (gsm->ka_retries > 0) { in gsm_control_keep_alive()
1988 /* T2 expired for keep-alive -> resend */ in gsm_control_keep_alive()
1989 gsm->ka_retries--; in gsm_control_keep_alive()
1991 /* Start keep-alive timer */ in gsm_control_keep_alive()
1992 gsm->ka_num++; in gsm_control_keep_alive()
1993 if (!gsm->ka_num) in gsm_control_keep_alive()
1994 gsm->ka_num++; in gsm_control_keep_alive()
1995 gsm->ka_retries = (signed int)gsm->n2; in gsm_control_keep_alive()
1997 gsm_control_command(gsm, CMD_TEST, &gsm->ka_num, in gsm_control_keep_alive()
1998 sizeof(gsm->ka_num)); in gsm_control_keep_alive()
1999 mod_timer(&gsm->ka_timer, in gsm_control_keep_alive()
2000 jiffies + gsm->t2 * HZ / 100); in gsm_control_keep_alive()
2002 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_keep_alive()
2006 * gsm_control_transmit - send control packet
2007 * @gsm: gsm mux
2008 * @ctrl: frame to send
2013 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) in gsm_control_transmit() argument
2015 gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len); in gsm_control_transmit()
2019 * gsm_control_retransmit - retransmit a control frame
2026 * gsm->pending_cmd will be NULL and we just let the timer expire.
2032 struct gsm_control *ctrl; in gsm_control_retransmit() local
2034 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
2035 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
2036 if (ctrl) { in gsm_control_retransmit()
2037 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
2038 gsm->pending_cmd = NULL; in gsm_control_retransmit()
2039 ctrl->error = -ETIMEDOUT; in gsm_control_retransmit()
2040 ctrl->done = 1; in gsm_control_retransmit()
2041 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2042 wake_up(&gsm->event); in gsm_control_retransmit()
2045 gsm->cretries--; in gsm_control_retransmit()
2046 gsm_control_transmit(gsm, ctrl); in gsm_control_retransmit()
2047 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
2049 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
2053 * gsm_control_send - send a control frame on DLCI 0
2067 struct gsm_control *ctrl = kzalloc(sizeof(struct gsm_control), in gsm_control_send() local
2070 if (ctrl == NULL) in gsm_control_send()
2073 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
2074 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
2075 if (gsm->pending_cmd != NULL) { in gsm_control_send()
2076 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2079 ctrl->cmd = command; in gsm_control_send()
2080 ctrl->data = data; in gsm_control_send()
2081 ctrl->len = clen; in gsm_control_send()
2082 gsm->pending_cmd = ctrl; in gsm_control_send()
2085 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
2086 gsm->cretries = 0; in gsm_control_send()
2088 gsm->cretries = gsm->n2; in gsm_control_send()
2090 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
2091 gsm_control_transmit(gsm, ctrl); in gsm_control_send()
2092 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
2093 return ctrl; in gsm_control_send()
2097 * gsm_control_wait - wait for a control to finish
2098 * @gsm: GSM mux
2109 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
2110 err = control->error; in gsm_control_wait()
2125 * gsm_dlci_close - a DLCI has closed
2134 del_timer(&dlci->t1); in gsm_dlci_close()
2136 pr_debug("DLCI %d goes closed.\n", dlci->addr); in gsm_dlci_close()
2137 dlci->state = DLCI_CLOSED; in gsm_dlci_close()
2139 dlci->constipated = true; in gsm_dlci_close()
2140 if (dlci->addr != 0) { in gsm_dlci_close()
2141 tty_port_tty_hangup(&dlci->port, false); in gsm_dlci_close()
2142 gsm_dlci_clear_queues(dlci->gsm, dlci); in gsm_dlci_close()
2144 tty_port_set_initialized(&dlci->port, false); in gsm_dlci_close()
2145 wake_up_interruptible(&dlci->port.open_wait); in gsm_dlci_close()
2147 del_timer(&dlci->gsm->ka_timer); in gsm_dlci_close()
2148 dlci->gsm->dead = true; in gsm_dlci_close()
2150 /* A DLCI 0 close is a MUX termination so we need to kick that in gsm_dlci_close()
2153 wake_up_all(&dlci->gsm->event); in gsm_dlci_close()
2157 * gsm_dlci_open - a DLCI has opened
2165 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_open()
2168 open -> open */ in gsm_dlci_open()
2169 del_timer(&dlci->t1); in gsm_dlci_open()
2171 dlci->state = DLCI_OPEN; in gsm_dlci_open()
2172 dlci->constipated = false; in gsm_dlci_open()
2174 pr_debug("DLCI %d goes open.\n", dlci->addr); in gsm_dlci_open()
2176 if (dlci->addr) { in gsm_dlci_open()
2179 /* Start keep-alive control */ in gsm_dlci_open()
2180 gsm->ka_num = 0; in gsm_dlci_open()
2181 gsm->ka_retries = -1; in gsm_dlci_open()
2182 mod_timer(&gsm->ka_timer, in gsm_dlci_open()
2183 jiffies + gsm->keep_alive * HZ / 100); in gsm_dlci_open()
2186 wake_up(&dlci->gsm->event); in gsm_dlci_open()
2190 * gsm_dlci_negotiate - start parameter negotiation
2198 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_negotiate()
2216 * gsm_dlci_t1 - T1 timer expiry
2233 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1()
2235 switch (dlci->state) { in gsm_dlci_t1()
2237 if (dlci->retries && gsm_dlci_negotiate(dlci) == 0) { in gsm_dlci_t1()
2238 dlci->retries--; in gsm_dlci_t1()
2239 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2241 gsm->open_error++; in gsm_dlci_t1()
2246 if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
2249 dlci->mode = DLCI_MODE_ADM; in gsm_dlci_t1()
2251 } else if (dlci->retries) { in gsm_dlci_t1()
2252 if (!dlci->addr || !gsm->dlci[0] || in gsm_dlci_t1()
2253 gsm->dlci[0]->state != DLCI_OPENING) { in gsm_dlci_t1()
2254 dlci->retries--; in gsm_dlci_t1()
2255 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
2258 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2260 gsm->open_error++; in gsm_dlci_t1()
2266 if (dlci->retries) { in gsm_dlci_t1()
2267 dlci->retries--; in gsm_dlci_t1()
2268 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
2269 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
2274 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state); in gsm_dlci_t1()
2280 * gsm_dlci_begin_open - start channel open procedure
2292 struct gsm_mux *gsm = dlci ? dlci->gsm : NULL; in gsm_dlci_begin_open()
2298 if (dlci->addr != 0) { in gsm_dlci_begin_open()
2299 if (gsm->adaption != 1 || gsm->adaption != dlci->adaption) in gsm_dlci_begin_open()
2301 if (dlci->prio != (roundup(dlci->addr + 1, 8) - 1)) in gsm_dlci_begin_open()
2303 if (gsm->ftype != dlci->ftype) in gsm_dlci_begin_open()
2307 switch (dlci->state) { in gsm_dlci_begin_open()
2311 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
2313 dlci->state = DLCI_OPENING; in gsm_dlci_begin_open()
2314 if (!dlci->addr || !gsm->dlci[0] || in gsm_dlci_begin_open()
2315 gsm->dlci[0]->state != DLCI_OPENING) in gsm_dlci_begin_open()
2316 gsm_command(gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
2319 dlci->state = DLCI_CONFIGURE; in gsm_dlci_begin_open()
2325 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
2333 * gsm_dlci_set_opening - change state to opening
2341 switch (dlci->state) { in gsm_dlci_set_opening()
2345 dlci->state = DLCI_OPENING; in gsm_dlci_set_opening()
2353 * gsm_dlci_set_wait_config - wait for channel configuration
2360 switch (dlci->state) { in gsm_dlci_set_wait_config()
2363 dlci->state = DLCI_WAITING_CONFIG; in gsm_dlci_set_wait_config()
2371 * gsm_dlci_begin_close - start channel open procedure
2383 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close()
2384 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) in gsm_dlci_begin_close()
2386 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
2387 dlci->state = DLCI_CLOSING; in gsm_dlci_begin_close()
2388 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
2389 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
2390 wake_up_interruptible(&gsm->event); in gsm_dlci_begin_close()
2394 * gsm_dlci_data - data arrived
2407 struct tty_port *port = &dlci->port; in gsm_dlci_data()
2414 switch (dlci->adaption) { in gsm_dlci_data()
2432 clen -= len; in gsm_dlci_data()
2442 * gsm_dlci_command - data arrived on control channel
2462 len -= dlen; in gsm_dlci_command()
2467 len -= dlen; in gsm_dlci_command()
2472 dlci->gsm->malformed++; in gsm_dlci_command()
2477 gsm_control_message(dlci->gsm, command, data, clen); in gsm_dlci_command()
2479 gsm_control_response(dlci->gsm, command, data, clen); in gsm_dlci_command()
2483 * gsm_kick_timer - transmit if possible
2496 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_kick_timer()
2498 if (gsm->tx_bytes < TX_THRESH_LO) in gsm_kick_timer()
2500 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_kick_timer()
2507 * gsm_dlci_copy_config_values - copy DLCI configuration
2514 dc->channel = (u32)dlci->addr; in gsm_dlci_copy_config_values()
2515 dc->adaption = (u32)dlci->adaption; in gsm_dlci_copy_config_values()
2516 dc->mtu = (u32)dlci->mtu; in gsm_dlci_copy_config_values()
2517 dc->priority = (u32)dlci->prio; in gsm_dlci_copy_config_values()
2518 if (dlci->ftype == UIH) in gsm_dlci_copy_config_values()
2519 dc->i = 1; in gsm_dlci_copy_config_values()
2521 dc->i = 2; in gsm_dlci_copy_config_values()
2522 dc->k = (u32)dlci->k; in gsm_dlci_copy_config_values()
2526 * gsm_dlci_config - configure DLCI from configuration
2542 for (i = 0; i < ARRAY_SIZE(dc->reserved); i++) in gsm_dlci_config()
2543 if (dc->reserved[i]) in gsm_dlci_config()
2544 return -EINVAL; in gsm_dlci_config()
2547 return -EINVAL; in gsm_dlci_config()
2548 gsm = dlci->gsm; in gsm_dlci_config()
2550 /* Stuff we don't support yet - I frame transport */ in gsm_dlci_config()
2551 if (dc->adaption != 1 && dc->adaption != 2) in gsm_dlci_config()
2552 return -EOPNOTSUPP; in gsm_dlci_config()
2553 if (dc->mtu > MAX_MTU || dc->mtu < MIN_MTU || dc->mtu > gsm->mru) in gsm_dlci_config()
2554 return -EINVAL; in gsm_dlci_config()
2555 if (dc->priority >= 64) in gsm_dlci_config()
2556 return -EINVAL; in gsm_dlci_config()
2557 if (dc->i == 0 || dc->i > 2) /* UIH and UI only */ in gsm_dlci_config()
2558 return -EINVAL; in gsm_dlci_config()
2559 if (dc->k > 7) in gsm_dlci_config()
2560 return -EINVAL; in gsm_dlci_config()
2561 if (dc->flags & ~GSM_FL_RESTART) /* allow future extensions */ in gsm_dlci_config()
2562 return -EINVAL; in gsm_dlci_config()
2568 if (dc->adaption != dlci->adaption) in gsm_dlci_config()
2570 if (dc->mtu != dlci->mtu) in gsm_dlci_config()
2572 if (dc->i != dlci->ftype) in gsm_dlci_config()
2575 if (dc->priority != dlci->prio) in gsm_dlci_config()
2577 if (dc->flags & GSM_FL_RESTART) in gsm_dlci_config()
2580 if ((open && gsm->wait_config) || need_restart) in gsm_dlci_config()
2582 if (dlci->state == DLCI_WAITING_CONFIG) { in gsm_dlci_config()
2593 wait_event_interruptible(gsm->event, dlci->state == DLCI_CLOSED); in gsm_dlci_config()
2595 return -EINTR; in gsm_dlci_config()
2600 dlci->adaption = (int)dc->adaption; in gsm_dlci_config()
2602 if (dc->mtu) in gsm_dlci_config()
2603 dlci->mtu = (unsigned int)dc->mtu; in gsm_dlci_config()
2605 dlci->mtu = gsm->mtu; in gsm_dlci_config()
2607 if (dc->priority) in gsm_dlci_config()
2608 dlci->prio = (u8)dc->priority; in gsm_dlci_config()
2610 dlci->prio = roundup(dlci->addr + 1, 8) - 1; in gsm_dlci_config()
2612 if (dc->i == 1) in gsm_dlci_config()
2613 dlci->ftype = UIH; in gsm_dlci_config()
2614 else if (dc->i == 2) in gsm_dlci_config()
2615 dlci->ftype = UI; in gsm_dlci_config()
2617 if (dc->k) in gsm_dlci_config()
2618 dlci->k = (u8)dc->k; in gsm_dlci_config()
2620 dlci->k = gsm->k; in gsm_dlci_config()
2623 if (gsm->initiator) in gsm_dlci_config()
2637 * gsm_dlci_alloc - allocate a DLCI
2638 * @gsm: GSM mux
2641 * Allocate and install a new DLCI object into the GSM mux.
2651 spin_lock_init(&dlci->lock); in gsm_dlci_alloc()
2652 mutex_init(&dlci->mutex); in gsm_dlci_alloc()
2653 if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) { in gsm_dlci_alloc()
2658 skb_queue_head_init(&dlci->skb_list); in gsm_dlci_alloc()
2659 timer_setup(&dlci->t1, gsm_dlci_t1, 0); in gsm_dlci_alloc()
2660 tty_port_init(&dlci->port); in gsm_dlci_alloc()
2661 dlci->port.ops = &gsm_port_ops; in gsm_dlci_alloc()
2662 dlci->gsm = gsm; in gsm_dlci_alloc()
2663 dlci->addr = addr; in gsm_dlci_alloc()
2664 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
2665 dlci->mtu = gsm->mtu; in gsm_dlci_alloc()
2667 dlci->prio = 0; in gsm_dlci_alloc()
2669 dlci->prio = roundup(addr + 1, 8) - 1; in gsm_dlci_alloc()
2670 dlci->ftype = gsm->ftype; in gsm_dlci_alloc()
2671 dlci->k = gsm->k; in gsm_dlci_alloc()
2672 dlci->state = DLCI_CLOSED; in gsm_dlci_alloc()
2674 dlci->data = gsm_dlci_data; in gsm_dlci_alloc()
2676 dlci->constipated = true; in gsm_dlci_alloc()
2678 dlci->data = gsm_dlci_command; in gsm_dlci_alloc()
2680 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
2685 * gsm_dlci_free - free DLCI
2696 timer_shutdown_sync(&dlci->t1); in gsm_dlci_free()
2697 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
2698 kfifo_free(&dlci->fifo); in gsm_dlci_free()
2699 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) in gsm_dlci_free()
2700 dev_kfree_skb(dlci->skb); in gsm_dlci_free()
2706 tty_port_get(&dlci->port); in dlci_get()
2711 tty_port_put(&dlci->port); in dlci_put()
2717 * gsm_dlci_release - release DLCI
2721 * mux is closed or tty is closed - whichever is last.
2727 struct tty_struct *tty = tty_port_tty_get(&dlci->port); in gsm_dlci_release()
2729 mutex_lock(&dlci->mutex); in gsm_dlci_release()
2731 mutex_unlock(&dlci->mutex); in gsm_dlci_release()
2735 * queue release_one_tty() -> NULL pointer panic in in gsm_dlci_release()
2740 tty_port_tty_set(&dlci->port, NULL); in gsm_dlci_release()
2743 dlci->state = DLCI_CLOSED; in gsm_dlci_release()
2752 * gsm_queue - a GSM frame is ready to process
2753 * @gsm: pointer to our gsm mux
2767 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
2768 gsm->bad_fcs++; in gsm_queue()
2770 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
2773 address = gsm->address >> 1; in gsm_queue()
2777 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
2778 cr ^= gsm->initiator ? 0 : 1; /* Flip so 1 always means command */ in gsm_queue()
2780 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
2782 dlci = gsm->dlci[address]; in gsm_queue()
2784 switch (gsm->control) { in gsm_queue()
2787 gsm->open_error++; in gsm_queue()
2793 gsm->open_error++; in gsm_queue()
2796 if (dlci->dead) in gsm_queue()
2806 if (dlci == NULL || dlci->state == DLCI_CLOSED) { in gsm_queue()
2817 switch (dlci->state) { in gsm_queue()
2826 dlci->state); in gsm_queue()
2842 if (dlci == NULL || dlci->state != DLCI_OPEN) { in gsm_queue()
2846 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2853 gsm->malformed++; in gsm_queue()
2858 * gsm0_receive_state_check_and_fix - check and correct receive state
2866 switch (gsm->state) { in gsm0_receive_state_check_and_fix()
2877 gsm->state = GSM_SEARCH; in gsm0_receive_state_check_and_fix()
2883 * gsm0_receive - perform processing for non-transparency
2895 switch (gsm->state) { in gsm0_receive()
2898 gsm->state = GSM0_ADDRESS; in gsm0_receive()
2899 gsm->address = 0; in gsm0_receive()
2900 gsm->len = 0; in gsm0_receive()
2901 gsm->fcs = INIT_FCS; in gsm0_receive()
2905 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2906 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
2907 gsm->state = GSM0_CONTROL; in gsm0_receive()
2910 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2911 gsm->control = c; in gsm0_receive()
2912 gsm->state = GSM0_LEN0; in gsm0_receive()
2915 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2916 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
2917 if (gsm->len > gsm->mru) { in gsm0_receive()
2918 gsm->bad_size++; in gsm0_receive()
2919 gsm->state = GSM_SEARCH; in gsm0_receive()
2922 gsm->count = 0; in gsm0_receive()
2923 if (!gsm->len) in gsm0_receive()
2924 gsm->state = GSM0_FCS; in gsm0_receive()
2926 gsm->state = GSM0_DATA; in gsm0_receive()
2929 gsm->state = GSM0_LEN1; in gsm0_receive()
2932 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2934 gsm->len |= len << 7; in gsm0_receive()
2935 if (gsm->len > gsm->mru) { in gsm0_receive()
2936 gsm->bad_size++; in gsm0_receive()
2937 gsm->state = GSM_SEARCH; in gsm0_receive()
2940 gsm->count = 0; in gsm0_receive()
2941 if (!gsm->len) in gsm0_receive()
2942 gsm->state = GSM0_FCS; in gsm0_receive()
2944 gsm->state = GSM0_DATA; in gsm0_receive()
2947 gsm->buf[gsm->count++] = c; in gsm0_receive()
2948 if (gsm->count >= MAX_MRU) { in gsm0_receive()
2949 gsm->bad_size++; in gsm0_receive()
2950 gsm->state = GSM_SEARCH; in gsm0_receive()
2951 } else if (gsm->count >= gsm->len) { in gsm0_receive()
2953 if ((gsm->control & ~PF) != UIH) { in gsm0_receive()
2954 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm0_receive()
2955 gsm->count); in gsm0_receive()
2957 gsm->state = GSM0_FCS; in gsm0_receive()
2961 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2962 gsm->state = GSM0_SSOF; in gsm0_receive()
2965 gsm->state = GSM_SEARCH; in gsm0_receive()
2969 gsm->bad_size++; in gsm0_receive()
2972 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2978 * gsm1_receive_state_check_and_fix - check and correct receive state
2986 switch (gsm->state) { in gsm1_receive_state_check_and_fix()
2995 gsm->state = GSM_SEARCH; in gsm1_receive_state_check_and_fix()
3001 * gsm1_receive - perform processing for non-transparency
3013 gsm->constipated = true; in gsm1_receive()
3016 gsm->constipated = false; in gsm1_receive()
3023 if (gsm->state == GSM1_DATA) { in gsm1_receive()
3024 if (gsm->count < 1) { in gsm1_receive()
3026 gsm->malformed++; in gsm1_receive()
3027 gsm->state = GSM1_START; in gsm1_receive()
3031 gsm->count--; in gsm1_receive()
3032 if ((gsm->control & ~PF) != UIH) { in gsm1_receive()
3036 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm1_receive()
3037 gsm->count); in gsm1_receive()
3040 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
3041 gsm->len = gsm->count; in gsm1_receive()
3043 gsm->state = GSM1_START; in gsm1_receive()
3047 if (gsm->state != GSM1_START) { in gsm1_receive()
3048 if (gsm->state != GSM_SEARCH) in gsm1_receive()
3049 gsm->malformed++; in gsm1_receive()
3050 gsm->state = GSM1_START; in gsm1_receive()
3058 gsm->escape = true; in gsm1_receive()
3063 if (gsm->state == GSM_SEARCH) in gsm1_receive()
3066 if (gsm->escape) { in gsm1_receive()
3068 gsm->escape = false; in gsm1_receive()
3070 switch (gsm->state) { in gsm1_receive()
3072 gsm->address = 0; in gsm1_receive()
3073 gsm->state = GSM1_ADDRESS; in gsm1_receive()
3074 gsm->fcs = INIT_FCS; in gsm1_receive()
3077 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3078 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
3079 gsm->state = GSM1_CONTROL; in gsm1_receive()
3082 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
3083 gsm->control = c; in gsm1_receive()
3084 gsm->count = 0; in gsm1_receive()
3085 gsm->state = GSM1_DATA; in gsm1_receive()
3088 if (gsm->count > gsm->mru || gsm->count > MAX_MRU) { /* Allow one for the FCS */ in gsm1_receive()
3089 gsm->state = GSM1_OVERRUN; in gsm1_receive()
3090 gsm->bad_size++; in gsm1_receive()
3092 gsm->buf[gsm->count++] = c; in gsm1_receive()
3094 case GSM1_OVERRUN: /* Over-long - eg a dropped SOF */ in gsm1_receive()
3097 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
3103 * gsm_error - handle tty error
3114 gsm->state = GSM_SEARCH; in gsm_error()
3115 gsm->io_error++; in gsm_error()
3119 * gsm_cleanup_mux - generic GSM protocol cleanup
3120 * @gsm: our mux
3123 * Clean up the bits of the mux which are the same for all framing
3124 * protocols. Remove the mux from the mux table, stop all the timers
3134 gsm->dead = true; in gsm_cleanup_mux()
3135 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
3137 dlci = gsm->dlci[0]; in gsm_cleanup_mux()
3139 if (disc && dlci->state != DLCI_CLOSED) { in gsm_cleanup_mux()
3141 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
3143 dlci->dead = true; in gsm_cleanup_mux()
3147 del_timer_sync(&gsm->kick_timer); in gsm_cleanup_mux()
3148 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
3149 del_timer_sync(&gsm->ka_timer); in gsm_cleanup_mux()
3152 flush_work(&gsm->tx_work); in gsm_cleanup_mux()
3155 if (gsm->has_devices) { in gsm_cleanup_mux()
3156 gsm_unregister_devices(gsm_tty_driver, gsm->num); in gsm_cleanup_mux()
3157 gsm->has_devices = false; in gsm_cleanup_mux()
3159 for (i = NUM_DLCI - 1; i >= 0; i--) in gsm_cleanup_mux()
3160 if (gsm->dlci[i]) in gsm_cleanup_mux()
3161 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
3162 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
3164 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
3166 guard(spinlock_irqsave)(&gsm->tx_lock); in gsm_cleanup_mux()
3167 list_for_each_entry_safe(txq, ntxq, &gsm->tx_ctrl_list, list) in gsm_cleanup_mux()
3169 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_cleanup_mux()
3170 list_for_each_entry_safe(txq, ntxq, &gsm->tx_data_list, list) in gsm_cleanup_mux()
3172 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_cleanup_mux()
3176 * gsm_activate_mux - generic GSM setup
3177 * @gsm: our mux
3179 * Set up the bits of the mux which are the same for all framing
3180 * protocols. Add the mux to the mux table so it can be opened and
3191 return -ENOMEM; in gsm_activate_mux()
3193 if (gsm->encoding == GSM_BASIC_OPT) in gsm_activate_mux()
3194 gsm->receive = gsm0_receive; in gsm_activate_mux()
3196 gsm->receive = gsm1_receive; in gsm_activate_mux()
3198 ret = gsm_register_devices(gsm_tty_driver, gsm->num); in gsm_activate_mux()
3202 gsm->has_devices = true; in gsm_activate_mux()
3203 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
3208 * gsm_free_mux - free up a mux
3209 * @gsm: mux to free
3211 * Dispose of allocated resources for a dead mux
3223 mutex_destroy(&gsm->mutex); in gsm_free_mux()
3224 kfree(gsm->txframe); in gsm_free_mux()
3225 kfree(gsm->buf); in gsm_free_mux()
3230 * gsm_free_muxr - free up a mux
3231 * @ref: kreference to the mux to free
3233 * Dispose of allocated resources for a dead mux
3246 kref_get(&gsm->ref); in mux_get()
3255 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
3261 return gsm->num * NUM_DLCI; in mux_num_to_base()
3270 * gsm_alloc_mux - allocate a mux
3272 * Creates a new mux ready for activation.
3281 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
3282 if (gsm->buf == NULL) { in gsm_alloc_mux()
3286 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
3287 if (gsm->txframe == NULL) { in gsm_alloc_mux()
3288 kfree(gsm->buf); in gsm_alloc_mux()
3292 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
3293 mutex_init(&gsm->mutex); in gsm_alloc_mux()
3294 kref_init(&gsm->ref); in gsm_alloc_mux()
3295 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_alloc_mux()
3296 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_alloc_mux()
3297 timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); in gsm_alloc_mux()
3298 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
3299 timer_setup(&gsm->ka_timer, gsm_control_keep_alive, 0); in gsm_alloc_mux()
3300 INIT_WORK(&gsm->tx_work, gsmld_write_task); in gsm_alloc_mux()
3301 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
3302 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
3303 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
3305 gsm->t1 = T1; in gsm_alloc_mux()
3306 gsm->t2 = T2; in gsm_alloc_mux()
3307 gsm->t3 = T3; in gsm_alloc_mux()
3308 gsm->n2 = N2; in gsm_alloc_mux()
3309 gsm->k = K; in gsm_alloc_mux()
3310 gsm->ftype = UIH; in gsm_alloc_mux()
3311 gsm->adaption = 1; in gsm_alloc_mux()
3312 gsm->encoding = GSM_ADV_OPT; in gsm_alloc_mux()
3313 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
3314 gsm->mtu = 64; in gsm_alloc_mux()
3315 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
3316 gsm->wait_config = false; /* Disabled */ in gsm_alloc_mux()
3317 gsm->keep_alive = 0; /* Disabled */ in gsm_alloc_mux()
3319 /* Store the instance to the mux array or abort if no space is in gsm_alloc_mux()
3326 gsm->num = i; in gsm_alloc_mux()
3332 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
3333 kfree(gsm->txframe); in gsm_alloc_mux()
3334 kfree(gsm->buf); in gsm_alloc_mux()
3346 c->adaption = gsm->adaption; in gsm_copy_config_values()
3347 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
3348 c->initiator = gsm->initiator; in gsm_copy_config_values()
3349 c->t1 = gsm->t1; in gsm_copy_config_values()
3350 c->t2 = gsm->t2; in gsm_copy_config_values()
3351 c->t3 = gsm->t3; in gsm_copy_config_values()
3352 c->n2 = gsm->n2; in gsm_copy_config_values()
3353 if (gsm->ftype == UIH) in gsm_copy_config_values()
3354 c->i = 1; in gsm_copy_config_values()
3356 c->i = 2; in gsm_copy_config_values()
3357 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
3358 c->mru = gsm->mru; in gsm_copy_config_values()
3359 c->mtu = gsm->mtu; in gsm_copy_config_values()
3360 c->k = gsm->k; in gsm_copy_config_values()
3368 /* Stuff we don't support yet - UI or I frame transport */ in gsm_config()
3369 if (c->adaption != 1 && c->adaption != 2) in gsm_config()
3370 return -EOPNOTSUPP; in gsm_config()
3372 if (c->mru < MIN_MTU || c->mtu < MIN_MTU) in gsm_config()
3373 return -EINVAL; in gsm_config()
3374 if (c->mru > MAX_MRU || c->mtu > MAX_MTU) in gsm_config()
3375 return -EINVAL; in gsm_config()
3376 if (c->t3 > MAX_T3) in gsm_config()
3377 return -EINVAL; in gsm_config()
3378 if (c->n2 > 255) in gsm_config()
3379 return -EINVAL; in gsm_config()
3380 if (c->encapsulation > 1) /* Basic, advanced, no I */ in gsm_config()
3381 return -EINVAL; in gsm_config()
3382 if (c->initiator > 1) in gsm_config()
3383 return -EINVAL; in gsm_config()
3384 if (c->k > MAX_WINDOW_SIZE) in gsm_config()
3385 return -EINVAL; in gsm_config()
3386 if (c->i == 0 || c->i > 2) /* UIH and UI only */ in gsm_config()
3387 return -EINVAL; in gsm_config()
3393 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
3395 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
3397 if (c->encapsulation != gsm->encoding) in gsm_config()
3399 if (c->adaption != gsm->adaption) in gsm_config()
3402 if (c->initiator != gsm->initiator) in gsm_config()
3404 if (c->mru != gsm->mru) in gsm_config()
3406 if (c->mtu != gsm->mtu) in gsm_config()
3417 gsm->initiator = c->initiator; in gsm_config()
3418 gsm->mru = c->mru; in gsm_config()
3419 gsm->mtu = c->mtu; in gsm_config()
3420 gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT; in gsm_config()
3421 gsm->adaption = c->adaption; in gsm_config()
3422 gsm->n2 = c->n2; in gsm_config()
3424 if (c->i == 1) in gsm_config()
3425 gsm->ftype = UIH; in gsm_config()
3426 else if (c->i == 2) in gsm_config()
3427 gsm->ftype = UI; in gsm_config()
3429 if (c->t1) in gsm_config()
3430 gsm->t1 = c->t1; in gsm_config()
3431 if (c->t2) in gsm_config()
3432 gsm->t2 = c->t2; in gsm_config()
3433 if (c->t3) in gsm_config()
3434 gsm->t3 = c->t3; in gsm_config()
3435 if (c->k) in gsm_config()
3436 gsm->k = c->k; in gsm_config()
3440 * and removing from the mux array in gsm_config()
3442 if (gsm->dead) { in gsm_config()
3446 if (gsm->initiator) in gsm_config()
3447 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
3456 ce->wait_config = gsm->wait_config ? 1 : 0; in gsm_copy_config_ext_values()
3457 ce->keep_alive = gsm->keep_alive; in gsm_copy_config_ext_values()
3469 for (i = 0; i < ARRAY_SIZE(ce->reserved); i++) in gsm_config_ext()
3470 if (ce->reserved[i]) in gsm_config_ext()
3471 return -EINVAL; in gsm_config_ext()
3472 if (ce->flags & ~GSM_FL_RESTART) in gsm_config_ext()
3473 return -EINVAL; in gsm_config_ext()
3476 if (ce->flags & GSM_FL_RESTART) in gsm_config_ext()
3490 gsm->wait_config = ce->wait_config ? true : false; in gsm_config_ext()
3491 gsm->keep_alive = ce->keep_alive; in gsm_config_ext()
3493 if (gsm->dead) { in gsm_config_ext()
3497 if (gsm->initiator) in gsm_config_ext()
3498 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config_ext()
3505 * gsmld_output - write to link
3506 * @gsm: our mux
3510 * Write a block of data from the GSM mux to the data channel. This
3516 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
3517 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
3518 return -ENOSPC; in gsmld_output()
3522 return gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
3527 * gsmld_write_trigger - schedule ldisc write task
3528 * @gsm: our mux
3532 if (!gsm || !gsm->dlci[0] || gsm->dlci[0]->dead) in gsmld_write_trigger()
3534 schedule_work(&gsm->tx_work); in gsmld_write_trigger()
3539 * gsmld_write_task - ldisc write task
3543 * avoid dead-locking. This returns if no space or data is left for output.
3554 ret = -ENODEV; in gsmld_write_task()
3555 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_task()
3556 if (gsm->tty) in gsmld_write_task()
3558 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_task()
3562 if (gsm->dlci[i]) in gsmld_write_task()
3563 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsmld_write_task()
3567 * gsmld_attach_gsm - mode set up
3569 * @gsm: our mux
3571 * Set up the MUX for basic mode and commence connecting to the
3578 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
3580 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
3581 tty->termios.c_iflag &= (IXON | IXOFF); in gsmld_attach_gsm()
3585 * gsmld_detach_gsm - stop doing 0710 mux
3586 * @tty: tty attached to the mux
3587 * @gsm: mux
3594 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
3596 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
3597 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
3598 gsm->tty = NULL; in gsmld_detach_gsm()
3604 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf()
3610 for (; count; count--, cp++) { in gsmld_receive_buf()
3615 if (gsm->receive) in gsmld_receive_buf()
3616 gsm->receive(gsm, *cp); in gsmld_receive_buf()
3635 * gsmld_flush_buffer - clean input queue
3648 * gsmld_close - close the ldisc for this tty
3659 struct gsm_mux *gsm = tty->disc_data; in gsmld_close()
3675 * gsmld_open - open an ldisc
3689 return -EPERM; in gsmld_open()
3691 if (tty->ops->write == NULL) in gsmld_open()
3692 return -EINVAL; in gsmld_open()
3697 return -ENOMEM; in gsmld_open()
3699 tty->disc_data = gsm; in gsmld_open()
3700 tty->receive_room = 65536; in gsmld_open()
3705 /* The mux will not be activated yet, we wait for correct in gsmld_open()
3708 if (gsm->encoding == GSM_BASIC_OPT) in gsmld_open()
3709 gsm->receive = gsm0_receive; in gsmld_open()
3711 gsm->receive = gsm1_receive; in gsmld_open()
3717 * gsmld_write_wakeup - asynchronous I/O notifier
3727 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup()
3734 * gsmld_read - read function for tty
3753 return -EOPNOTSUPP; in gsmld_read()
3757 * gsmld_write - write function for tty
3765 * as-is and must be properly framed and checksummed as appropriate
3773 struct gsm_mux *gsm = tty->disc_data; in gsmld_write()
3779 return -ENODEV; in gsmld_write()
3781 ret = -ENOBUFS; in gsmld_write()
3782 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
3785 ret = tty->ops->write(tty, buf, nr); in gsmld_write()
3787 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write()
3788 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
3794 * gsmld_poll - poll method for N_GSM0710
3804 * Called without the kernel lock held - fine
3811 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll()
3813 poll_wait(file, &tty->read_wait, wait); in gsmld_poll()
3814 poll_wait(file, &tty->write_wait, wait); in gsmld_poll()
3816 if (gsm->dead) in gsmld_poll()
3820 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in gsmld_poll()
3833 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl()
3841 return -EFAULT; in gsmld_ioctl()
3845 return -EFAULT; in gsmld_ioctl()
3853 return -EFAULT; in gsmld_ioctl()
3857 return -EFAULT; in gsmld_ioctl()
3861 return -EFAULT; in gsmld_ioctl()
3863 return -EINVAL; in gsmld_ioctl()
3865 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3869 return -ENOMEM; in gsmld_ioctl()
3873 return -EFAULT; in gsmld_ioctl()
3877 return -EFAULT; in gsmld_ioctl()
3879 return -EINVAL; in gsmld_ioctl()
3881 dlci = gsm->dlci[addr]; in gsmld_ioctl()
3885 return -ENOMEM; in gsmld_ioctl()
3913 if (!dlci->net) { in dlci_net_free()
3917 dlci->adaption = dlci->prev_adaption; in dlci_net_free()
3918 dlci->data = dlci->prev_data; in dlci_net_free()
3919 free_netdev(dlci->net); in dlci_net_free()
3920 dlci->net = NULL; in dlci_net_free()
3928 dlci = mux_net->dlci; in net_free()
3930 if (dlci->net) { in net_free()
3931 unregister_netdev(dlci->net); in net_free()
3938 kref_get(&mux_net->ref); in muxnet_get()
3943 kref_put(&mux_net->ref, net_free); in muxnet_put()
3950 struct gsm_dlci *dlci = mux_net->dlci; in gsm_mux_net_start_xmit()
3953 skb_queue_head(&dlci->skb_list, skb); in gsm_mux_net_start_xmit()
3954 net->stats.tx_packets++; in gsm_mux_net_start_xmit()
3955 net->stats.tx_bytes += skb->len; in gsm_mux_net_start_xmit()
3967 dev_dbg(&net->dev, "Tx timed out.\n"); in gsm_mux_net_tx_timeout()
3970 net->stats.tx_errors++; in gsm_mux_net_tx_timeout()
3975 struct net_device *net = dlci->net; in gsm_mux_rx_netchar()
3984 net->stats.rx_dropped++; in gsm_mux_rx_netchar()
3991 skb->dev = net; in gsm_mux_rx_netchar()
3992 skb->protocol = htons(ETH_P_IP); in gsm_mux_rx_netchar()
3998 net->stats.rx_packets++; in gsm_mux_rx_netchar()
3999 net->stats.rx_bytes += size; in gsm_mux_rx_netchar()
4013 net->netdev_ops = &gsm_netdev_ops; in gsm_mux_net_init()
4016 net->watchdog_timeo = GSM_NET_TX_TIMEOUT; in gsm_mux_net_init()
4017 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in gsm_mux_net_init()
4018 net->type = ARPHRD_NONE; in gsm_mux_net_init()
4019 net->tx_queue_len = 10; in gsm_mux_net_init()
4029 if (!dlci->net) in gsm_destroy_network()
4031 mux_net = netdev_priv(dlci->net); in gsm_destroy_network()
4045 return -EPERM; in gsm_create_network()
4048 if (dlci->adaption > 2) in gsm_create_network()
4049 return -EBUSY; in gsm_create_network()
4051 if (nc->protocol != htons(ETH_P_IP)) in gsm_create_network()
4052 return -EPROTONOSUPPORT; in gsm_create_network()
4054 if (nc->adaption != 3 && nc->adaption != 4) in gsm_create_network()
4055 return -EPROTONOSUPPORT; in gsm_create_network()
4060 if (nc->if_name[0] != '\0') in gsm_create_network()
4061 netname = nc->if_name; in gsm_create_network()
4066 return -ENOMEM; in gsm_create_network()
4068 net->mtu = dlci->mtu; in gsm_create_network()
4069 net->min_mtu = MIN_MTU; in gsm_create_network()
4070 net->max_mtu = dlci->mtu; in gsm_create_network()
4072 mux_net->dlci = dlci; in gsm_create_network()
4073 kref_init(&mux_net->ref); in gsm_create_network()
4074 strscpy(nc->if_name, net->name); /* return net name */ in gsm_create_network()
4077 dlci->prev_adaption = dlci->adaption; in gsm_create_network()
4078 dlci->prev_data = dlci->data; in gsm_create_network()
4079 dlci->adaption = nc->adaption; in gsm_create_network()
4080 dlci->data = gsm_mux_rx_netchar; in gsm_create_network()
4081 dlci->net = net; in gsm_create_network()
4090 return net->ifindex; /* return network index */ in gsm_create_network()
4114 * gsm_modem_upd_via_data - send modem bits via convergence layer
4124 struct gsm_mux *gsm = dlci->gsm; in gsm_modem_upd_via_data()
4127 if (dlci->state != DLCI_OPEN || dlci->adaption != 2) in gsm_modem_upd_via_data()
4130 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4132 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
4136 * gsm_modem_upd_via_msc - send modem bits via control frame
4144 struct gsm_control *ctrl; in gsm_modem_upd_via_msc() local
4147 if (dlci->gsm->encoding != GSM_BASIC_OPT) in gsm_modem_upd_via_msc()
4150 modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ in gsm_modem_upd_via_msc()
4158 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsm_modem_upd_via_msc()
4159 if (ctrl == NULL) in gsm_modem_upd_via_msc()
4160 return -ENOMEM; in gsm_modem_upd_via_msc()
4161 return gsm_control_wait(dlci->gsm, ctrl); in gsm_modem_upd_via_msc()
4165 * gsm_modem_update - send modem status line state
4172 if (dlci->gsm->dead) in gsm_modem_update()
4173 return -EL2HLT; in gsm_modem_update()
4174 if (dlci->adaption == 2) { in gsm_modem_update()
4178 } else if (dlci->gsm->encoding == GSM_BASIC_OPT) { in gsm_modem_update()
4184 return -EPROTONOSUPPORT; in gsm_modem_update()
4188 * gsm_wait_modem_change - wait for modem status line change
4193 * - any given modem status line bit changed
4194 * - the wait event function got interrupted (e.g. by a signal)
4195 * - the underlying DLCI was closed
4196 * - the underlying ldisc device was removed
4200 struct gsm_mux *gsm = dlci->gsm; in gsm_wait_modem_change()
4201 u32 old = dlci->modem_rx; in gsm_wait_modem_change()
4204 ret = wait_event_interruptible(gsm->event, gsm->dead || in gsm_wait_modem_change()
4205 dlci->state != DLCI_OPEN || in gsm_wait_modem_change()
4206 (old ^ dlci->modem_rx) & mask); in gsm_wait_modem_change()
4207 if (gsm->dead) in gsm_wait_modem_change()
4208 return -ENODEV; in gsm_wait_modem_change()
4209 if (dlci->state != DLCI_OPEN) in gsm_wait_modem_change()
4210 return -EL2NSYNC; in gsm_wait_modem_change()
4217 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised()
4220 if (dlci->state != DLCI_OPEN) in gsm_carrier_raised()
4229 if (gsm->encoding == GSM_BASIC_OPT && in gsm_carrier_raised()
4230 gsm->dlci[0]->mode == DLCI_MODE_ADM && !dlci->modem_rx) in gsm_carrier_raised()
4233 return dlci->modem_rx & TIOCM_CD; in gsm_carrier_raised()
4239 unsigned int modem_tx = dlci->modem_tx; in gsm_dtr_rts()
4244 if (modem_tx != dlci->modem_tx) { in gsm_dtr_rts()
4245 dlci->modem_tx = modem_tx; in gsm_dtr_rts()
4260 unsigned int line = tty->index; in gsmtty_install()
4261 unsigned int mux = mux_line_to_num(line); in gsmtty_install() local
4267 if (mux >= MAX_MUX) in gsmtty_install()
4268 return -ENXIO; in gsmtty_install()
4270 if (gsm_mux[mux] == NULL) in gsmtty_install()
4271 return -EUNATCH; in gsmtty_install()
4273 return -ECHRNG; in gsmtty_install()
4274 gsm = gsm_mux[mux]; in gsmtty_install()
4275 if (gsm->dead) in gsmtty_install()
4276 return -EL2HLT; in gsmtty_install()
4281 mutex_lock(&gsm->mutex); in gsmtty_install()
4283 dlci0 = gsm->dlci[0]; in gsmtty_install()
4284 if (dlci0 && dlci0->state != DLCI_OPEN) { in gsmtty_install()
4285 mutex_unlock(&gsm->mutex); in gsmtty_install()
4287 if (dlci0->state == DLCI_OPENING) in gsmtty_install()
4288 wait_event(gsm->event, dlci0->state != DLCI_OPENING); in gsmtty_install()
4290 if (dlci0->state != DLCI_OPEN) in gsmtty_install()
4291 return -EL2NSYNC; in gsmtty_install()
4293 mutex_lock(&gsm->mutex); in gsmtty_install()
4296 dlci = gsm->dlci[line]; in gsmtty_install()
4302 mutex_unlock(&gsm->mutex); in gsmtty_install()
4303 return -ENOMEM; in gsmtty_install()
4305 ret = tty_port_install(&dlci->port, driver, tty); in gsmtty_install()
4309 mutex_unlock(&gsm->mutex); in gsmtty_install()
4314 dlci_get(gsm->dlci[0]); in gsmtty_install()
4316 tty->driver_data = dlci; in gsmtty_install()
4317 mutex_unlock(&gsm->mutex); in gsmtty_install()
4324 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_open()
4325 struct tty_port *port = &dlci->port; in gsmtty_open()
4327 port->count++; in gsmtty_open()
4330 dlci->modem_rx = 0; in gsmtty_open()
4331 /* We could in theory open and close before we wait - eg if we get in gsmtty_open()
4335 if (!dlci->gsm->wait_config) { in gsmtty_open()
4337 if (dlci->gsm->initiator) in gsmtty_open()
4350 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_close()
4354 if (dlci->state == DLCI_CLOSED) in gsmtty_close()
4356 mutex_lock(&dlci->mutex); in gsmtty_close()
4358 mutex_unlock(&dlci->mutex); in gsmtty_close()
4359 if (tty_port_close_start(&dlci->port, tty, filp) == 0) in gsmtty_close()
4362 if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) in gsmtty_close()
4363 tty_port_lower_dtr_rts(&dlci->port); in gsmtty_close()
4364 tty_port_close_end(&dlci->port, tty); in gsmtty_close()
4365 tty_port_tty_set(&dlci->port, NULL); in gsmtty_close()
4371 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_hangup()
4372 if (dlci->state == DLCI_CLOSED) in gsmtty_hangup()
4374 tty_port_hangup(&dlci->port); in gsmtty_hangup()
4381 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write()
4382 if (dlci->state == DLCI_CLOSED) in gsmtty_write()
4383 return -EINVAL; in gsmtty_write()
4385 sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock); in gsmtty_write()
4393 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write_room()
4394 if (dlci->state == DLCI_CLOSED) in gsmtty_write_room()
4396 return kfifo_avail(&dlci->fifo); in gsmtty_write_room()
4401 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_chars_in_buffer()
4402 if (dlci->state == DLCI_CLOSED) in gsmtty_chars_in_buffer()
4404 return kfifo_len(&dlci->fifo); in gsmtty_chars_in_buffer()
4409 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_flush_buffer()
4412 if (dlci->state == DLCI_CLOSED) in gsmtty_flush_buffer()
4418 spin_lock_irqsave(&dlci->lock, flags); in gsmtty_flush_buffer()
4419 kfifo_reset(&dlci->fifo); in gsmtty_flush_buffer()
4420 spin_unlock_irqrestore(&dlci->lock, flags); in gsmtty_flush_buffer()
4433 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmget()
4434 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmget()
4435 return -EINVAL; in gsmtty_tiocmget()
4436 return dlci->modem_rx; in gsmtty_tiocmget()
4442 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmset()
4443 unsigned int modem_tx = dlci->modem_tx; in gsmtty_tiocmset()
4445 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmset()
4446 return -EINVAL; in gsmtty_tiocmset()
4450 if (modem_tx != dlci->modem_tx) { in gsmtty_tiocmset()
4451 dlci->modem_tx = modem_tx; in gsmtty_tiocmset()
4461 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_ioctl()
4466 if (dlci->state == DLCI_CLOSED) in gsmtty_ioctl()
4467 return -EINVAL; in gsmtty_ioctl()
4471 return -EFAULT; in gsmtty_ioctl()
4472 nc.if_name[IFNAMSIZ-1] = '\0'; in gsmtty_ioctl()
4474 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4476 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4478 return -EFAULT; in gsmtty_ioctl()
4482 return -EPERM; in gsmtty_ioctl()
4483 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
4485 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
4489 return -EFAULT; in gsmtty_ioctl()
4490 if (dc.channel != dlci->addr) in gsmtty_ioctl()
4491 return -EPERM; in gsmtty_ioctl()
4494 return -EFAULT; in gsmtty_ioctl()
4498 return -EFAULT; in gsmtty_ioctl()
4500 return -EINVAL; in gsmtty_ioctl()
4501 if (dc.channel != 0 && dc.channel != dlci->addr) in gsmtty_ioctl()
4502 return -EPERM; in gsmtty_ioctl()
4507 return -ENOIOCTLCMD; in gsmtty_ioctl()
4514 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_set_termios()
4515 if (dlci->state == DLCI_CLOSED) in gsmtty_set_termios()
4522 tty_termios_copy_hw(&tty->termios, old); in gsmtty_set_termios()
4527 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_throttle()
4528 if (dlci->state == DLCI_CLOSED) in gsmtty_throttle()
4531 dlci->modem_tx &= ~TIOCM_RTS; in gsmtty_throttle()
4532 dlci->throttled = true; in gsmtty_throttle()
4539 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_unthrottle()
4540 if (dlci->state == DLCI_CLOSED) in gsmtty_unthrottle()
4543 dlci->modem_tx |= TIOCM_RTS; in gsmtty_unthrottle()
4544 dlci->throttled = false; in gsmtty_unthrottle()
4551 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_break_ctl()
4553 if (dlci->state == DLCI_CLOSED) in gsmtty_break_ctl()
4554 return -EINVAL; in gsmtty_break_ctl()
4556 if (state == -1) /* "On indefinitely" - we can't encode this in gsmtty_break_ctl()
4569 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_cleanup()
4570 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup()
4573 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
4617 gsm_tty_driver->driver_name = "gsmtty"; in gsm_init()
4618 gsm_tty_driver->name = "gsmtty"; in gsm_init()
4619 gsm_tty_driver->major = 0; /* Dynamic */ in gsm_init()
4620 gsm_tty_driver->minor_start = 0; in gsm_init()
4621 gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; in gsm_init()
4622 gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; in gsm_init()
4623 gsm_tty_driver->init_termios = tty_std_termios; in gsm_init()
4625 gsm_tty_driver->init_termios.c_lflag &= ~ECHO; in gsm_init()
4630 status = -EBUSY; in gsm_init()
4634 gsm_tty_driver->major, gsm_tty_driver->minor_start); in gsm_init()