Lines Matching +full:break +full:- +full:control
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()
22 * all control traffic via it
87 * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte
97 * struct gsm_mux_net - network interface
115 u8 ctrl; /* Control byte + flags */
162 bool dead; /* Refuse re-open */
163 /* Flow control */
183 * DLCI 0 is used to pass control blocks out of band of the data
250 u8 control; member
271 struct list_head tx_ctrl_list; /* Pending control packets */
274 /* Control messages */
297 * Mux objects - needed so that we can translate a tty index into the
409 * gsm_fcs_add - update FCS
423 * gsm_fcs_add_block - update FCS for a block
434 while (len--) in gsm_fcs_add_block()
440 * gsm_read_ea - read a byte into an EA
458 * gsm_read_ea_val - read a value until EA
470 for (; dlen > 0; dlen--) { in gsm_read_ea_val()
473 break; in gsm_read_ea_val()
479 * gsm_encode_modem - encode modem data bits
489 /* FC is true flow control not modem bits */ in gsm_encode_modem()
490 if (dlci->throttled) in gsm_encode_modem()
492 if (dlci->modem_tx & TIOCM_DTR) in gsm_encode_modem()
494 if (dlci->modem_tx & TIOCM_RTS) in gsm_encode_modem()
496 if (dlci->modem_tx & TIOCM_RI) in gsm_encode_modem()
498 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
523 * gsm_register_devices - register all tty devices for a given mux index
537 return -EINVAL; in gsm_register_devices()
541 /* Don't register device 0 - this is the control channel in gsm_register_devices()
549 for (i--; i >= 1; i--) in gsm_register_devices()
559 * gsm_unregister_devices - unregister all tty devices for a given mux index
577 /* Don't unregister device 0 - this is the control in gsm_unregister_devices()
585 * gsm_print_packet - display a frame for debug
589 * @control: control including PF bit
594 * style is based on amateur radio LAP-B dump display.
598 u8 control, const u8 *data, int dlen) in gsm_print_packet() argument
604 if ((control & ~PF) == UI || (control & ~PF) == UIH) in gsm_print_packet()
609 switch (control & ~PF) { in gsm_print_packet()
612 break; in gsm_print_packet()
615 break; in gsm_print_packet()
618 break; in gsm_print_packet()
621 break; in gsm_print_packet()
624 break; in gsm_print_packet()
627 break; in gsm_print_packet()
629 if (!(control & 0x01)) { in gsm_print_packet()
631 (control & 0x0E) >> 1, (control & 0xE0) >> 5); in gsm_print_packet()
632 } else switch (control & 0x0F) { in gsm_print_packet()
634 pr_cont("RR(%d)", (control & 0xE0) >> 5); in gsm_print_packet()
635 break; in gsm_print_packet()
637 pr_cont("RNR(%d)", (control & 0xE0) >> 5); in gsm_print_packet()
638 break; in gsm_print_packet()
640 pr_cont("REJ(%d)", (control & 0xE0) >> 5); in gsm_print_packet()
641 break; in gsm_print_packet()
643 pr_cont("[%02X]", control); in gsm_print_packet()
647 if (control & PF) in gsm_print_packet()
661 * gsm_stuff_frame - bytestuff a packet
674 while (len--) { in gsm_stuff_frame()
689 * gsm_send - send a control frame
691 * @addr: address for control frame
693 * @control: control byte including PF bit
695 * Format up and transmit a control frame. These should be transmitted
698 static int gsm_send(struct gsm_mux *gsm, int addr, int cr, int control) in gsm_send() argument
705 msg = gsm_data_alloc(gsm, addr, 0, control); in gsm_send()
707 return -ENOMEM; in gsm_send()
710 ocr = cr ^ (gsm->initiator ? 0 : 1); in gsm_send()
712 msg->data -= 3; in gsm_send()
713 dp = msg->data; in gsm_send()
715 *dp++ = control; in gsm_send()
717 if (gsm->encoding == GSM_BASIC_OPT) in gsm_send()
720 *dp = 0xFF - gsm_fcs_add_block(INIT_FCS, msg->data, dp - msg->data); in gsm_send()
721 msg->len = (dp - msg->data) + 1; in gsm_send()
723 gsm_print_packet("Q->", addr, cr, control, NULL, 0); in gsm_send()
725 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_send()
726 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in gsm_send()
727 gsm->tx_bytes += msg->len; in gsm_send()
728 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_send()
735 * gsm_dlci_clear_queues - remove outstanding data for a DLCI
744 int addr = dlci->addr; in gsm_dlci_clear_queues()
748 spin_lock_irqsave(&dlci->lock, flags); in gsm_dlci_clear_queues()
749 kfifo_reset(&dlci->fifo); in gsm_dlci_clear_queues()
750 spin_unlock_irqrestore(&dlci->lock, flags); in gsm_dlci_clear_queues()
753 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
754 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_dlci_clear_queues()
755 if (msg->addr != addr) in gsm_dlci_clear_queues()
757 gsm->tx_bytes -= msg->len; in gsm_dlci_clear_queues()
758 list_del(&msg->list); in gsm_dlci_clear_queues()
761 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
765 * gsm_response - send a control response
767 * @addr: address for control frame
768 * @control: control byte including PF bit
773 static inline void gsm_response(struct gsm_mux *gsm, int addr, int control) in gsm_response() argument
775 gsm_send(gsm, addr, 0, control); in gsm_response()
779 * gsm_command - send a control command
781 * @addr: address for control frame
782 * @control: control byte including PF bit
787 static inline void gsm_command(struct gsm_mux *gsm, int addr, int control) in gsm_command() argument
789 gsm_send(gsm, addr, 1, control); in gsm_command()
797 * gsm_data_alloc - allocate data frame
801 * @ctrl: control byte
815 m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ in gsm_data_alloc()
816 m->len = len; in gsm_data_alloc()
817 m->addr = addr; in gsm_data_alloc()
818 m->ctrl = ctrl; in gsm_data_alloc()
819 INIT_LIST_HEAD(&m->list); in gsm_data_alloc()
824 * gsm_send_packet - sends a single packet
836 if (gsm->encoding == GSM_BASIC_OPT) { in gsm_send_packet()
837 gsm->txframe[0] = GSM0_SOF; in gsm_send_packet()
838 memcpy(gsm->txframe + 1, msg->data, msg->len); in gsm_send_packet()
839 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_send_packet()
840 len = msg->len + 2; in gsm_send_packet()
842 gsm->txframe[0] = GSM1_SOF; in gsm_send_packet()
843 len = gsm_stuff_frame(msg->data, gsm->txframe + 1, msg->len); in gsm_send_packet()
844 gsm->txframe[len + 1] = GSM1_SOF; in gsm_send_packet()
849 gsm_hex_dump_bytes(__func__, gsm->txframe, len); in gsm_send_packet()
850 gsm_print_packet("-->", msg->addr, gsm->initiator, msg->ctrl, msg->data, in gsm_send_packet()
851 msg->len); in gsm_send_packet()
853 ret = gsmld_output(gsm, gsm->txframe, len); in gsm_send_packet()
857 gsm->tx_bytes -= msg->len; in gsm_send_packet()
863 * gsm_is_flow_ctrl_msg - checks if flow control message
866 * Returns true if the given message is a flow control command of the
867 * control channel. False is returned in any other case.
873 if (msg->addr > 0) in gsm_is_flow_ctrl_msg()
876 switch (msg->ctrl & ~PF) { in gsm_is_flow_ctrl_msg()
880 if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) in gsm_is_flow_ctrl_msg()
881 break; in gsm_is_flow_ctrl_msg()
887 break; in gsm_is_flow_ctrl_msg()
894 * gsm_data_kick - poke the queue
899 * If we have been flow-stopped by a CMD_FCOFF, then we can only
909 clear_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsm_data_kick()
911 /* Serialize control messages and control channel messages first */ in gsm_data_kick()
912 list_for_each_entry_safe(msg, nmsg, &gsm->tx_ctrl_list, list) { in gsm_data_kick()
913 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
917 case -ENOSPC: in gsm_data_kick()
918 return -ENOSPC; in gsm_data_kick()
919 case -ENODEV: in gsm_data_kick()
921 gsm->tx_bytes -= msg->len; in gsm_data_kick()
922 list_del(&msg->list); in gsm_data_kick()
927 list_del(&msg->list); in gsm_data_kick()
930 break; in gsm_data_kick()
934 if (gsm->constipated) in gsm_data_kick()
935 return -EAGAIN; in gsm_data_kick()
938 if (list_empty(&gsm->tx_data_list)) in gsm_data_kick()
940 list_for_each_entry_safe(msg, nmsg, &gsm->tx_data_list, list) { in gsm_data_kick()
941 dlci = gsm->dlci[msg->addr]; in gsm_data_kick()
943 if (dlci->state != DLCI_OPEN) { in gsm_data_kick()
944 gsm->tx_bytes -= msg->len; in gsm_data_kick()
945 list_del(&msg->list); in gsm_data_kick()
951 case -ENOSPC: in gsm_data_kick()
952 return -ENOSPC; in gsm_data_kick()
953 case -ENODEV: in gsm_data_kick()
955 gsm->tx_bytes -= msg->len; in gsm_data_kick()
956 list_del(&msg->list); in gsm_data_kick()
961 list_del(&msg->list); in gsm_data_kick()
964 break; in gsm_data_kick()
972 * __gsm_data_queue - queue a UI or UIH frame
983 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue()
984 u8 *dp = msg->data; in __gsm_data_queue()
985 u8 *fcs = dp + msg->len; in __gsm_data_queue()
988 if (gsm->encoding == GSM_BASIC_OPT) { in __gsm_data_queue()
989 if (msg->len < 128) in __gsm_data_queue()
990 *--dp = (msg->len << 1) | EA; in __gsm_data_queue()
992 *--dp = (msg->len >> 7); /* bits 7 - 15 */ in __gsm_data_queue()
993 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ in __gsm_data_queue()
997 *--dp = msg->ctrl; in __gsm_data_queue()
998 if (gsm->initiator) in __gsm_data_queue()
999 *--dp = (msg->addr << 2) | CR | EA; in __gsm_data_queue()
1001 *--dp = (msg->addr << 2) | EA; in __gsm_data_queue()
1002 *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); in __gsm_data_queue()
1004 if (msg->ctrl == UI || msg->ctrl == (UI|PF)) in __gsm_data_queue()
1005 *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); in __gsm_data_queue()
1006 *fcs = 0xFF - *fcs; in __gsm_data_queue()
1008 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
1009 msg->data, msg->len); in __gsm_data_queue()
1013 msg->len += (msg->data - dp) + 1; in __gsm_data_queue()
1014 msg->data = dp; in __gsm_data_queue()
1017 switch (msg->ctrl & ~PF) { in __gsm_data_queue()
1020 if (msg->addr > 0) { in __gsm_data_queue()
1021 list_add_tail(&msg->list, &gsm->tx_data_list); in __gsm_data_queue()
1022 break; in __gsm_data_queue()
1026 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in __gsm_data_queue()
1027 break; in __gsm_data_queue()
1029 gsm->tx_bytes += msg->len; in __gsm_data_queue()
1032 mod_timer(&gsm->kick_timer, jiffies + 10 * gsm->t1 * HZ / 100); in __gsm_data_queue()
1036 * gsm_data_queue - queue a UI or UIH frame
1048 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1050 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
1054 * gsm_dlci_data_output - try and push data out of a DLCI
1071 /* for modem bits without break data */ in gsm_dlci_data_output()
1072 h = ((dlci->adaption == 1) ? 0 : 1); in gsm_dlci_data_output()
1074 len = kfifo_len(&dlci->fifo); in gsm_dlci_data_output()
1079 if ((len + h) > gsm->mtu) in gsm_dlci_data_output()
1080 len = gsm->mtu - h; in gsm_dlci_data_output()
1084 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_data_output()
1086 return -ENOMEM; in gsm_dlci_data_output()
1087 dp = msg->data; in gsm_dlci_data_output()
1088 switch (dlci->adaption) { in gsm_dlci_data_output()
1090 break; in gsm_dlci_data_output()
1092 * Always one byte as we never send inline break data in gsm_dlci_data_output()
1095 break; in gsm_dlci_data_output()
1098 dlci->adaption); in gsm_dlci_data_output()
1099 break; in gsm_dlci_data_output()
1102 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len, in gsm_dlci_data_output()
1103 &dlci->lock)); in gsm_dlci_data_output()
1106 tty_port_tty_wakeup(&dlci->port); in gsm_dlci_data_output()
1114 * gsm_dlci_data_output_framed - try and push data out of a DLCI
1135 if (dlci->adaption == 4) in gsm_dlci_data_output_framed()
1138 /* dlci->skb is locked by tx_lock */ in gsm_dlci_data_output_framed()
1139 if (dlci->skb == NULL) { in gsm_dlci_data_output_framed()
1140 dlci->skb = skb_dequeue_tail(&dlci->skb_list); in gsm_dlci_data_output_framed()
1141 if (dlci->skb == NULL) in gsm_dlci_data_output_framed()
1145 len = dlci->skb->len + overhead; in gsm_dlci_data_output_framed()
1148 if (len > gsm->mtu) { in gsm_dlci_data_output_framed()
1149 if (dlci->adaption == 3) { in gsm_dlci_data_output_framed()
1151 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1152 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1155 len = gsm->mtu; in gsm_dlci_data_output_framed()
1160 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_data_output_framed()
1162 skb_queue_tail(&dlci->skb_list, dlci->skb); in gsm_dlci_data_output_framed()
1163 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1164 return -ENOMEM; in gsm_dlci_data_output_framed()
1166 dp = msg->data; in gsm_dlci_data_output_framed()
1168 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ in gsm_dlci_data_output_framed()
1171 len--; in gsm_dlci_data_output_framed()
1173 memcpy(dp, dlci->skb->data, len); in gsm_dlci_data_output_framed()
1174 skb_pull(dlci->skb, len); in gsm_dlci_data_output_framed()
1177 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1178 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1184 * gsm_dlci_modem_output - try and push modem status out of a DLCI
1187 * @brk: break signal
1190 * bits and to transmit an optional break.
1202 /* for modem bits without break data */ in gsm_dlci_modem_output()
1203 switch (dlci->adaption) { in gsm_dlci_modem_output()
1205 break; in gsm_dlci_modem_output()
1210 break; in gsm_dlci_modem_output()
1213 dlci->adaption); in gsm_dlci_modem_output()
1214 return -EINVAL; in gsm_dlci_modem_output()
1217 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_modem_output()
1220 return -ENOMEM; in gsm_dlci_modem_output()
1222 dp = msg->data; in gsm_dlci_modem_output()
1223 switch (dlci->adaption) { in gsm_dlci_modem_output()
1225 break; in gsm_dlci_modem_output()
1231 *dp++ = (brk << 4) | 2 | EA; /* Length, Break, EA */ in gsm_dlci_modem_output()
1233 break; in gsm_dlci_modem_output()
1236 break; in gsm_dlci_modem_output()
1244 * gsm_dlci_data_sweep - look for data to send
1263 while (gsm->tx_bytes < TX_THRESH_HI) { in gsm_dlci_data_sweep()
1265 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1267 if (!dlci || dlci->constipated) in gsm_dlci_data_sweep()
1270 if (dlci->state != DLCI_OPEN) in gsm_dlci_data_sweep()
1273 if (dlci->adaption < 3 && !dlci->net) in gsm_dlci_data_sweep()
1284 break; in gsm_dlci_data_sweep()
1289 break; in gsm_dlci_data_sweep()
1296 * gsm_dlci_data_kick - transmit if possible
1309 if (dlci->constipated) in gsm_dlci_data_kick()
1312 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1314 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1315 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1316 if (dlci->net) in gsm_dlci_data_kick()
1317 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1319 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1322 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1323 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1327 * Control message processing
1332 * gsm_control_command - send a command frame to a control
1343 struct gsm_msg *msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); in gsm_control_command()
1346 return -ENOMEM; in gsm_control_command()
1348 msg->data[0] = (cmd << 1) | CR | EA; /* Set C/R */ in gsm_control_command()
1349 msg->data[1] = (dlen << 1) | EA; in gsm_control_command()
1350 memcpy(msg->data + 2, data, dlen); in gsm_control_command()
1351 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_command()
1357 * gsm_control_reply - send a response frame to a control
1370 msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); in gsm_control_reply()
1373 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ in gsm_control_reply()
1374 msg->data[1] = (dlen << 1) | EA; in gsm_control_reply()
1375 memcpy(msg->data + 2, data, dlen); in gsm_control_reply()
1376 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_reply()
1380 * gsm_process_modem - process received modem status
1386 * Used when a modem control message or line state inline in adaption
1398 * or two octets (V.24 signals + break signals). This is specified in in gsm_process_modem()
1409 /* Flow control/ready to communicate */ in gsm_process_modem()
1411 if (fc && !dlci->constipated) { in gsm_process_modem()
1413 dlci->constipated = true; in gsm_process_modem()
1414 } else if (!fc && dlci->constipated) { in gsm_process_modem()
1415 dlci->constipated = false; in gsm_process_modem()
1429 /* Carrier drop -> hangup */ in gsm_process_modem()
1431 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) in gsm_process_modem()
1436 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); in gsm_process_modem()
1437 dlci->modem_rx = mlines; in gsm_process_modem()
1441 * gsm_control_modem - modem status received
1446 * We have received a modem status control message. This is used by
1448 * to indicate break signals. Unpack it, convert to Linux representation
1449 * and if need be stuff a break message down the tty.
1468 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1470 dlci = gsm->dlci[addr]; in gsm_control_modem()
1473 if ((cl - len) < 1) in gsm_control_modem()
1477 cl -= len; in gsm_control_modem()
1484 tty = tty_port_tty_get(&dlci->port); in gsm_control_modem()
1494 * gsm_control_rls - remote line status
1499 * The modem sends us a two byte message on the control channel whenever
1513 len--; in gsm_control_rls()
1518 len--; in gsm_control_rls()
1523 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1530 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1547 * gsm_control_message - DLCI 0 control processing
1553 * Input processor for control messages from the other end of the link.
1565 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1568 dlci->dead = true; in gsm_control_message()
1569 gsm->dead = true; in gsm_control_message()
1573 break; in gsm_control_message()
1577 break; in gsm_control_message()
1580 gsm->constipated = false; in gsm_control_message()
1584 break; in gsm_control_message()
1587 gsm->constipated = true; in gsm_control_message()
1589 break; in gsm_control_message()
1593 break; in gsm_control_message()
1597 break; in gsm_control_message()
1601 break; in gsm_control_message()
1610 break; in gsm_control_message()
1615 * gsm_control_response - process a response to our control
1622 * control message in flight so this is fairly easy. All the clean up
1633 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1635 ctrl = gsm->pending_cmd; in gsm_control_response()
1638 if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { in gsm_control_response()
1640 del_timer(&gsm->t2_timer); in gsm_control_response()
1641 gsm->pending_cmd = NULL; in gsm_control_response()
1644 ctrl->error = -EOPNOTSUPP; in gsm_control_response()
1645 ctrl->done = 1; in gsm_control_response()
1646 wake_up(&gsm->event); in gsm_control_response()
1648 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1652 * gsm_control_transmit - send control packet
1656 * Send out a pending control command (called under control lock)
1661 gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len); in gsm_control_transmit()
1665 * gsm_control_retransmit - retransmit a control frame
1668 * Called off the T2 timer expiry in order to retransmit control frames
1672 * gsm->pending_cmd will be NULL and we just let the timer expire.
1680 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
1681 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
1683 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
1684 gsm->pending_cmd = NULL; in gsm_control_retransmit()
1685 ctrl->error = -ETIMEDOUT; in gsm_control_retransmit()
1686 ctrl->done = 1; in gsm_control_retransmit()
1687 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
1688 wake_up(&gsm->event); in gsm_control_retransmit()
1691 gsm->cretries--; in gsm_control_retransmit()
1693 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
1695 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
1699 * gsm_control_send - send a control frame on DLCI 0
1705 * Queue and dispatch a control command. Only one command can be
1719 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
1720 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
1721 if (gsm->pending_cmd != NULL) { in gsm_control_send()
1722 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
1725 ctrl->cmd = command; in gsm_control_send()
1726 ctrl->data = data; in gsm_control_send()
1727 ctrl->len = clen; in gsm_control_send()
1728 gsm->pending_cmd = ctrl; in gsm_control_send()
1731 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
1732 gsm->cretries = 0; in gsm_control_send()
1734 gsm->cretries = gsm->n2; in gsm_control_send()
1736 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
1738 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
1743 * gsm_control_wait - wait for a control to finish
1745 * @control: control we are waiting on
1747 * Waits for the control to complete or time out. Frees any used
1752 static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control) in gsm_control_wait() argument
1755 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
1756 err = control->error; in gsm_control_wait()
1757 kfree(control); in gsm_control_wait()
1771 * gsm_dlci_close - a DLCI has closed
1780 del_timer(&dlci->t1); in gsm_dlci_close()
1782 pr_debug("DLCI %d goes closed.\n", dlci->addr); in gsm_dlci_close()
1783 dlci->state = DLCI_CLOSED; in gsm_dlci_close()
1785 dlci->constipated = true; in gsm_dlci_close()
1786 if (dlci->addr != 0) { in gsm_dlci_close()
1787 tty_port_tty_hangup(&dlci->port, false); in gsm_dlci_close()
1788 gsm_dlci_clear_queues(dlci->gsm, dlci); in gsm_dlci_close()
1790 tty_port_set_initialized(&dlci->port, 0); in gsm_dlci_close()
1791 wake_up_interruptible(&dlci->port.open_wait); in gsm_dlci_close()
1793 dlci->gsm->dead = true; in gsm_dlci_close()
1797 wake_up(&dlci->gsm->event); in gsm_dlci_close()
1801 * gsm_dlci_open - a DLCI has opened
1810 open -> open */ in gsm_dlci_open()
1811 del_timer(&dlci->t1); in gsm_dlci_open()
1813 dlci->state = DLCI_OPEN; in gsm_dlci_open()
1814 dlci->constipated = false; in gsm_dlci_open()
1816 pr_debug("DLCI %d goes open.\n", dlci->addr); in gsm_dlci_open()
1818 if (dlci->addr) in gsm_dlci_open()
1821 wake_up(&dlci->gsm->event); in gsm_dlci_open()
1825 * gsm_dlci_t1 - T1 timer expiry
1828 * The T1 timer handles retransmits of control frames (essentially of
1834 * Some control dlci can stay in ADM mode with other dlci working just
1835 * fine. In that case we can just keep the control dlci open after the
1842 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1()
1844 switch (dlci->state) { in gsm_dlci_t1()
1846 if (dlci->retries) { in gsm_dlci_t1()
1847 dlci->retries--; in gsm_dlci_t1()
1848 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
1849 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
1850 } else if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
1853 dlci->addr); in gsm_dlci_t1()
1854 dlci->mode = DLCI_MODE_ADM; in gsm_dlci_t1()
1860 break; in gsm_dlci_t1()
1862 if (dlci->retries) { in gsm_dlci_t1()
1863 dlci->retries--; in gsm_dlci_t1()
1864 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
1865 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
1868 break; in gsm_dlci_t1()
1870 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state); in gsm_dlci_t1()
1871 break; in gsm_dlci_t1()
1876 * gsm_dlci_begin_open - start channel open procedure
1887 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_open()
1888 if (dlci->state == DLCI_OPEN || dlci->state == DLCI_OPENING) in gsm_dlci_begin_open()
1890 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
1891 dlci->state = DLCI_OPENING; in gsm_dlci_begin_open()
1892 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
1893 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
1897 * gsm_dlci_set_opening - change state to opening
1905 switch (dlci->state) { in gsm_dlci_set_opening()
1908 dlci->state = DLCI_OPENING; in gsm_dlci_set_opening()
1909 break; in gsm_dlci_set_opening()
1911 break; in gsm_dlci_set_opening()
1916 * gsm_dlci_begin_close - start channel open procedure
1928 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close()
1929 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) in gsm_dlci_begin_close()
1931 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
1932 dlci->state = DLCI_CLOSING; in gsm_dlci_begin_close()
1933 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
1934 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
1938 * gsm_dlci_data - data arrived
1944 * other than the control channel. If the relevant virtual tty is
1951 struct tty_port *port = &dlci->port; in gsm_dlci_data()
1958 switch (dlci->adaption) { in gsm_dlci_data()
1961 break; in gsm_dlci_data()
1963 break; in gsm_dlci_data()
1976 clen -= len; in gsm_dlci_data()
1986 * gsm_dlci_command - data arrived on control channel
1992 * control channel. This should contain a command EA followed by
1993 * control data bytes. The command EA contains a command/response bit
2006 len -= dlen; in gsm_dlci_command()
2009 /* read any control data */ in gsm_dlci_command()
2011 len -= dlen; in gsm_dlci_command()
2019 gsm_control_message(dlci->gsm, command, data, clen); in gsm_dlci_command()
2021 gsm_control_response(dlci->gsm, command, data, clen); in gsm_dlci_command()
2025 * gsm_kick_timer - transmit if possible
2038 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_kick_timer()
2040 if (gsm->tx_bytes < TX_THRESH_LO) in gsm_kick_timer()
2042 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_kick_timer()
2053 * gsm_dlci_alloc - allocate a DLCI
2067 spin_lock_init(&dlci->lock); in gsm_dlci_alloc()
2068 mutex_init(&dlci->mutex); in gsm_dlci_alloc()
2069 if (kfifo_alloc(&dlci->fifo, TX_SIZE, GFP_KERNEL) < 0) { in gsm_dlci_alloc()
2074 skb_queue_head_init(&dlci->skb_list); in gsm_dlci_alloc()
2075 timer_setup(&dlci->t1, gsm_dlci_t1, 0); in gsm_dlci_alloc()
2076 tty_port_init(&dlci->port); in gsm_dlci_alloc()
2077 dlci->port.ops = &gsm_port_ops; in gsm_dlci_alloc()
2078 dlci->gsm = gsm; in gsm_dlci_alloc()
2079 dlci->addr = addr; in gsm_dlci_alloc()
2080 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
2081 dlci->state = DLCI_CLOSED; in gsm_dlci_alloc()
2083 dlci->data = gsm_dlci_data; in gsm_dlci_alloc()
2085 dlci->constipated = true; in gsm_dlci_alloc()
2087 dlci->data = gsm_dlci_command; in gsm_dlci_alloc()
2089 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
2094 * gsm_dlci_free - free DLCI
2105 del_timer_sync(&dlci->t1); in gsm_dlci_free()
2106 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
2107 kfifo_free(&dlci->fifo); in gsm_dlci_free()
2108 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) in gsm_dlci_free()
2109 dev_kfree_skb(dlci->skb); in gsm_dlci_free()
2115 tty_port_get(&dlci->port); in dlci_get()
2120 tty_port_put(&dlci->port); in dlci_put()
2126 * gsm_dlci_release - release DLCI
2130 * mux is closed or tty is closed - whichever is last.
2136 struct tty_struct *tty = tty_port_tty_get(&dlci->port); in gsm_dlci_release()
2138 mutex_lock(&dlci->mutex); in gsm_dlci_release()
2140 mutex_unlock(&dlci->mutex); in gsm_dlci_release()
2144 * queue release_one_tty() -> NULL pointer panic in in gsm_dlci_release()
2149 tty_port_tty_set(&dlci->port, NULL); in gsm_dlci_release()
2152 dlci->state = DLCI_CLOSED; in gsm_dlci_release()
2161 * gsm_queue - a GSM frame is ready to process
2176 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
2177 gsm->bad_fcs++; in gsm_queue()
2179 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
2182 address = gsm->address >> 1; in gsm_queue()
2186 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
2187 cr ^= gsm->initiator ? 0 : 1; /* Flip so 1 always means command */ in gsm_queue()
2189 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
2191 dlci = gsm->dlci[address]; in gsm_queue()
2193 switch (gsm->control) { in gsm_queue()
2201 if (dlci->dead) in gsm_queue()
2207 break; in gsm_queue()
2211 if (dlci == NULL || dlci->state == DLCI_CLOSED) { in gsm_queue()
2218 break; in gsm_queue()
2221 break; in gsm_queue()
2222 switch (dlci->state) { in gsm_queue()
2225 break; in gsm_queue()
2228 break; in gsm_queue()
2231 dlci->state); in gsm_queue()
2232 break; in gsm_queue()
2234 break; in gsm_queue()
2242 break; in gsm_queue()
2247 if (dlci == NULL || dlci->state != DLCI_OPEN) { in gsm_queue()
2251 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2252 break; in gsm_queue()
2258 gsm->malformed++; in gsm_queue()
2264 * gsm0_receive - perform processing for non-transparency
2275 switch (gsm->state) { in gsm0_receive()
2278 gsm->state = GSM_ADDRESS; in gsm0_receive()
2279 gsm->address = 0; in gsm0_receive()
2280 gsm->len = 0; in gsm0_receive()
2281 gsm->fcs = INIT_FCS; in gsm0_receive()
2283 break; in gsm0_receive()
2285 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2286 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
2287 gsm->state = GSM_CONTROL; in gsm0_receive()
2288 break; in gsm0_receive()
2289 case GSM_CONTROL: /* Control Byte */ in gsm0_receive()
2290 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2291 gsm->control = c; in gsm0_receive()
2292 gsm->state = GSM_LEN0; in gsm0_receive()
2293 break; in gsm0_receive()
2295 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2296 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
2297 if (gsm->len > gsm->mru) { in gsm0_receive()
2298 gsm->bad_size++; in gsm0_receive()
2299 gsm->state = GSM_SEARCH; in gsm0_receive()
2300 break; in gsm0_receive()
2302 gsm->count = 0; in gsm0_receive()
2303 if (!gsm->len) in gsm0_receive()
2304 gsm->state = GSM_FCS; in gsm0_receive()
2306 gsm->state = GSM_DATA; in gsm0_receive()
2307 break; in gsm0_receive()
2309 gsm->state = GSM_LEN1; in gsm0_receive()
2310 break; in gsm0_receive()
2312 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2314 gsm->len |= len << 7; in gsm0_receive()
2315 if (gsm->len > gsm->mru) { in gsm0_receive()
2316 gsm->bad_size++; in gsm0_receive()
2317 gsm->state = GSM_SEARCH; in gsm0_receive()
2318 break; in gsm0_receive()
2320 gsm->count = 0; in gsm0_receive()
2321 if (!gsm->len) in gsm0_receive()
2322 gsm->state = GSM_FCS; in gsm0_receive()
2324 gsm->state = GSM_DATA; in gsm0_receive()
2325 break; in gsm0_receive()
2327 gsm->buf[gsm->count++] = c; in gsm0_receive()
2328 if (gsm->count == gsm->len) { in gsm0_receive()
2330 if ((gsm->control & ~PF) != UIH) { in gsm0_receive()
2331 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm0_receive()
2332 gsm->count); in gsm0_receive()
2334 gsm->state = GSM_FCS; in gsm0_receive()
2336 break; in gsm0_receive()
2338 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2339 gsm->state = GSM_SSOF; in gsm0_receive()
2340 break; in gsm0_receive()
2342 gsm->state = GSM_SEARCH; in gsm0_receive()
2346 gsm->bad_size++; in gsm0_receive()
2347 break; in gsm0_receive()
2349 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2350 break; in gsm0_receive()
2355 * gsm1_receive - perform processing for non-transparency
2366 gsm->constipated = true; in gsm1_receive()
2369 gsm->constipated = false; in gsm1_receive()
2376 if (gsm->state == GSM_DATA) { in gsm1_receive()
2377 if (gsm->count < 1) { in gsm1_receive()
2379 gsm->malformed++; in gsm1_receive()
2380 gsm->state = GSM_START; in gsm1_receive()
2384 gsm->count--; in gsm1_receive()
2385 if ((gsm->control & ~PF) != UIH) { in gsm1_receive()
2389 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, in gsm1_receive()
2390 gsm->count); in gsm1_receive()
2393 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
2394 gsm->len = gsm->count; in gsm1_receive()
2396 gsm->state = GSM_START; in gsm1_receive()
2400 if (gsm->state != GSM_START) { in gsm1_receive()
2401 if (gsm->state != GSM_SEARCH) in gsm1_receive()
2402 gsm->malformed++; in gsm1_receive()
2403 gsm->state = GSM_START; in gsm1_receive()
2411 gsm->escape = true; in gsm1_receive()
2416 if (gsm->state == GSM_SEARCH) in gsm1_receive()
2419 if (gsm->escape) { in gsm1_receive()
2421 gsm->escape = false; in gsm1_receive()
2423 switch (gsm->state) { in gsm1_receive()
2425 gsm->address = 0; in gsm1_receive()
2426 gsm->state = GSM_ADDRESS; in gsm1_receive()
2427 gsm->fcs = INIT_FCS; in gsm1_receive()
2430 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
2431 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
2432 gsm->state = GSM_CONTROL; in gsm1_receive()
2433 break; in gsm1_receive()
2434 case GSM_CONTROL: /* Control Byte */ in gsm1_receive()
2435 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
2436 gsm->control = c; in gsm1_receive()
2437 gsm->count = 0; in gsm1_receive()
2438 gsm->state = GSM_DATA; in gsm1_receive()
2439 break; in gsm1_receive()
2441 if (gsm->count > gsm->mru) { /* Allow one for the FCS */ in gsm1_receive()
2442 gsm->state = GSM_OVERRUN; in gsm1_receive()
2443 gsm->bad_size++; in gsm1_receive()
2445 gsm->buf[gsm->count++] = c; in gsm1_receive()
2446 break; in gsm1_receive()
2447 case GSM_OVERRUN: /* Over-long - eg a dropped SOF */ in gsm1_receive()
2448 break; in gsm1_receive()
2450 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
2451 break; in gsm1_receive()
2456 * gsm_error - handle tty error
2467 gsm->state = GSM_SEARCH; in gsm_error()
2468 gsm->io_error++; in gsm_error()
2472 * gsm_cleanup_mux - generic GSM protocol cleanup
2484 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_cleanup_mux()
2487 gsm->dead = true; in gsm_cleanup_mux()
2488 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
2491 if (disc && dlci->state != DLCI_CLOSED) { in gsm_cleanup_mux()
2493 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
2495 dlci->dead = true; in gsm_cleanup_mux()
2499 del_timer_sync(&gsm->kick_timer); in gsm_cleanup_mux()
2500 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
2503 flush_work(&gsm->tx_work); in gsm_cleanup_mux()
2505 /* Free up any link layer users and finally the control channel */ in gsm_cleanup_mux()
2506 if (gsm->has_devices) { in gsm_cleanup_mux()
2507 gsm_unregister_devices(gsm_tty_driver, gsm->num); in gsm_cleanup_mux()
2508 gsm->has_devices = false; in gsm_cleanup_mux()
2510 for (i = NUM_DLCI - 1; i >= 0; i--) in gsm_cleanup_mux()
2511 if (gsm->dlci[i]) in gsm_cleanup_mux()
2512 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
2513 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
2515 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
2516 list_for_each_entry_safe(txq, ntxq, &gsm->tx_ctrl_list, list) in gsm_cleanup_mux()
2518 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_cleanup_mux()
2519 list_for_each_entry_safe(txq, ntxq, &gsm->tx_data_list, list) in gsm_cleanup_mux()
2521 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_cleanup_mux()
2525 * gsm_activate_mux - generic GSM setup
2540 return -ENOMEM; in gsm_activate_mux()
2542 if (gsm->encoding == GSM_BASIC_OPT) in gsm_activate_mux()
2543 gsm->receive = gsm0_receive; in gsm_activate_mux()
2545 gsm->receive = gsm1_receive; in gsm_activate_mux()
2547 ret = gsm_register_devices(gsm_tty_driver, gsm->num); in gsm_activate_mux()
2551 gsm->has_devices = true; in gsm_activate_mux()
2552 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
2557 * gsm_free_mux - free up a mux
2569 break; in gsm_free_mux()
2572 mutex_destroy(&gsm->mutex); in gsm_free_mux()
2573 kfree(gsm->txframe); in gsm_free_mux()
2574 kfree(gsm->buf); in gsm_free_mux()
2579 * gsm_free_muxr - free up a mux
2595 kref_get(&gsm->ref); in mux_get()
2604 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
2610 return gsm->num * NUM_DLCI; in mux_num_to_base()
2619 * gsm_alloc_mux - allocate a mux
2630 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
2631 if (gsm->buf == NULL) { in gsm_alloc_mux()
2635 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
2636 if (gsm->txframe == NULL) { in gsm_alloc_mux()
2637 kfree(gsm->buf); in gsm_alloc_mux()
2641 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
2642 mutex_init(&gsm->mutex); in gsm_alloc_mux()
2643 kref_init(&gsm->ref); in gsm_alloc_mux()
2644 INIT_LIST_HEAD(&gsm->tx_ctrl_list); in gsm_alloc_mux()
2645 INIT_LIST_HEAD(&gsm->tx_data_list); in gsm_alloc_mux()
2646 timer_setup(&gsm->kick_timer, gsm_kick_timer, 0); in gsm_alloc_mux()
2647 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
2648 INIT_WORK(&gsm->tx_work, gsmld_write_task); in gsm_alloc_mux()
2649 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
2650 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
2651 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
2653 gsm->t1 = T1; in gsm_alloc_mux()
2654 gsm->t2 = T2; in gsm_alloc_mux()
2655 gsm->n2 = N2; in gsm_alloc_mux()
2656 gsm->ftype = UIH; in gsm_alloc_mux()
2657 gsm->adaption = 1; in gsm_alloc_mux()
2658 gsm->encoding = GSM_ADV_OPT; in gsm_alloc_mux()
2659 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
2660 gsm->mtu = 64; in gsm_alloc_mux()
2661 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
2670 gsm->num = i; in gsm_alloc_mux()
2671 break; in gsm_alloc_mux()
2676 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
2677 kfree(gsm->txframe); in gsm_alloc_mux()
2678 kfree(gsm->buf); in gsm_alloc_mux()
2690 c->adaption = gsm->adaption; in gsm_copy_config_values()
2691 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
2692 c->initiator = gsm->initiator; in gsm_copy_config_values()
2693 c->t1 = gsm->t1; in gsm_copy_config_values()
2694 c->t2 = gsm->t2; in gsm_copy_config_values()
2695 c->t3 = 0; /* Not supported */ in gsm_copy_config_values()
2696 c->n2 = gsm->n2; in gsm_copy_config_values()
2697 if (gsm->ftype == UIH) in gsm_copy_config_values()
2698 c->i = 1; in gsm_copy_config_values()
2700 c->i = 2; in gsm_copy_config_values()
2701 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
2702 c->mru = gsm->mru; in gsm_copy_config_values()
2703 c->mtu = gsm->mtu; in gsm_copy_config_values()
2704 c->k = 0; in gsm_copy_config_values()
2713 /* Stuff we don't support yet - UI or I frame transport, windowing */ in gsm_config()
2714 if ((c->adaption != 1 && c->adaption != 2) || c->k) in gsm_config()
2715 return -EOPNOTSUPP; in gsm_config()
2717 if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8) in gsm_config()
2718 return -EINVAL; in gsm_config()
2719 if (c->n2 > 255) in gsm_config()
2720 return -EINVAL; in gsm_config()
2721 if (c->encapsulation > 1) /* Basic, advanced, no I */ in gsm_config()
2722 return -EINVAL; in gsm_config()
2723 if (c->initiator > 1) in gsm_config()
2724 return -EINVAL; in gsm_config()
2725 if (c->i == 0 || c->i > 2) /* UIH and UI only */ in gsm_config()
2726 return -EINVAL; in gsm_config()
2732 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
2734 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
2736 if (c->encapsulation != gsm->encoding) in gsm_config()
2738 if (c->adaption != gsm->adaption) in gsm_config()
2741 if (c->initiator != gsm->initiator) in gsm_config()
2743 if (c->mru != gsm->mru) in gsm_config()
2745 if (c->mtu != gsm->mtu) in gsm_config()
2756 gsm->initiator = c->initiator; in gsm_config()
2757 gsm->mru = c->mru; in gsm_config()
2758 gsm->mtu = c->mtu; in gsm_config()
2759 gsm->encoding = c->encapsulation ? GSM_ADV_OPT : GSM_BASIC_OPT; in gsm_config()
2760 gsm->adaption = c->adaption; in gsm_config()
2761 gsm->n2 = c->n2; in gsm_config()
2763 if (c->i == 1) in gsm_config()
2764 gsm->ftype = UIH; in gsm_config()
2765 else if (c->i == 2) in gsm_config()
2766 gsm->ftype = UI; in gsm_config()
2768 if (c->t1) in gsm_config()
2769 gsm->t1 = c->t1; in gsm_config()
2770 if (c->t2) in gsm_config()
2771 gsm->t2 = c->t2; in gsm_config()
2777 if (gsm->dead) { in gsm_config()
2781 if (gsm->initiator) in gsm_config()
2782 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
2788 * gsmld_output - write to link
2799 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
2800 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
2801 return -ENOSPC; in gsmld_output()
2805 return gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
2810 * gsmld_write_trigger - schedule ldisc write task
2815 if (!gsm || !gsm->dlci[0] || gsm->dlci[0]->dead) in gsmld_write_trigger()
2817 schedule_work(&gsm->tx_work); in gsmld_write_trigger()
2822 * gsmld_write_task - ldisc write task
2826 * avoid dead-locking. This returns if no space or data is left for output.
2834 /* All outstanding control channel and control messages and one data in gsmld_write_task()
2837 ret = -ENODEV; in gsmld_write_task()
2838 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_task()
2839 if (gsm->tty) in gsmld_write_task()
2841 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_task()
2845 if (gsm->dlci[i]) in gsmld_write_task()
2846 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsmld_write_task()
2850 * gsmld_attach_gsm - mode set up
2861 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
2863 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
2864 tty->termios.c_iflag &= (IXON | IXOFF); in gsmld_attach_gsm()
2868 * gsmld_detach_gsm - stop doing 0710 mux
2877 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
2879 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
2880 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
2881 gsm->tty = NULL; in gsmld_detach_gsm()
2887 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf()
2893 for (; count; count--, cp++) { in gsmld_receive_buf()
2898 if (gsm->receive) in gsmld_receive_buf()
2899 gsm->receive(gsm, *cp); in gsmld_receive_buf()
2900 break; in gsmld_receive_buf()
2906 break; in gsmld_receive_buf()
2910 break; in gsmld_receive_buf()
2918 * gsmld_flush_buffer - clean input queue
2931 * gsmld_close - close the ldisc for this tty
2942 struct gsm_mux *gsm = tty->disc_data; in gsmld_close()
2958 * gsmld_open - open an ldisc
2971 if (tty->ops->write == NULL) in gsmld_open()
2972 return -EINVAL; in gsmld_open()
2977 return -ENOMEM; in gsmld_open()
2979 tty->disc_data = gsm; in gsmld_open()
2980 tty->receive_room = 65536; in gsmld_open()
2983 gsm->encoding = GSM_ADV_OPT; in gsmld_open()
2990 * gsmld_write_wakeup - asynchronous I/O notifier
3000 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup()
3007 * gsmld_read - read function for tty
3027 return -EOPNOTSUPP; in gsmld_read()
3031 * gsmld_write - write function for tty
3038 * itself (or some other control data). The data is transferred
3039 * as-is and must be properly framed and checksummed as appropriate
3047 struct gsm_mux *gsm = tty->disc_data; in gsmld_write()
3053 return -ENODEV; in gsmld_write()
3055 ret = -ENOBUFS; in gsmld_write()
3056 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
3059 ret = tty->ops->write(tty, buf, nr); in gsmld_write()
3061 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write()
3062 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
3068 * gsmld_poll - poll method for N_GSM0710
3078 * Called without the kernel lock held - fine
3085 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll()
3087 poll_wait(file, &tty->read_wait, wait); in gsmld_poll()
3088 poll_wait(file, &tty->write_wait, wait); in gsmld_poll()
3090 if (gsm->dead) in gsmld_poll()
3094 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in gsmld_poll()
3105 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl()
3112 return -EFAULT; in gsmld_ioctl()
3116 return -EFAULT; in gsmld_ioctl()
3146 if (!dlci->net) { in dlci_net_free()
3150 dlci->adaption = dlci->prev_adaption; in dlci_net_free()
3151 dlci->data = dlci->prev_data; in dlci_net_free()
3152 free_netdev(dlci->net); in dlci_net_free()
3153 dlci->net = NULL; in dlci_net_free()
3161 dlci = mux_net->dlci; in net_free()
3163 if (dlci->net) { in net_free()
3164 unregister_netdev(dlci->net); in net_free()
3171 kref_get(&mux_net->ref); in muxnet_get()
3176 kref_put(&mux_net->ref, net_free); in muxnet_put()
3183 struct gsm_dlci *dlci = mux_net->dlci; in gsm_mux_net_start_xmit()
3186 skb_queue_head(&dlci->skb_list, skb); in gsm_mux_net_start_xmit()
3187 net->stats.tx_packets++; in gsm_mux_net_start_xmit()
3188 net->stats.tx_bytes += skb->len; in gsm_mux_net_start_xmit()
3200 dev_dbg(&net->dev, "Tx timed out.\n"); in gsm_mux_net_tx_timeout()
3203 net->stats.tx_errors++; in gsm_mux_net_tx_timeout()
3209 struct net_device *net = dlci->net; in gsm_mux_rx_netchar()
3218 net->stats.rx_dropped++; in gsm_mux_rx_netchar()
3225 skb->dev = net; in gsm_mux_rx_netchar()
3226 skb->protocol = htons(ETH_P_IP); in gsm_mux_rx_netchar()
3232 net->stats.rx_packets++; in gsm_mux_rx_netchar()
3233 net->stats.rx_bytes += size; in gsm_mux_rx_netchar()
3247 net->netdev_ops = &gsm_netdev_ops; in gsm_mux_net_init()
3250 net->watchdog_timeo = GSM_NET_TX_TIMEOUT; in gsm_mux_net_init()
3251 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in gsm_mux_net_init()
3252 net->type = ARPHRD_NONE; in gsm_mux_net_init()
3253 net->tx_queue_len = 10; in gsm_mux_net_init()
3263 if (!dlci->net) in gsm_destroy_network()
3265 mux_net = netdev_priv(dlci->net); in gsm_destroy_network()
3279 return -EPERM; in gsm_create_network()
3282 if (dlci->adaption > 2) in gsm_create_network()
3283 return -EBUSY; in gsm_create_network()
3285 if (nc->protocol != htons(ETH_P_IP)) in gsm_create_network()
3286 return -EPROTONOSUPPORT; in gsm_create_network()
3288 if (nc->adaption != 3 && nc->adaption != 4) in gsm_create_network()
3289 return -EPROTONOSUPPORT; in gsm_create_network()
3294 if (nc->if_name[0] != '\0') in gsm_create_network()
3295 netname = nc->if_name; in gsm_create_network()
3300 return -ENOMEM; in gsm_create_network()
3302 net->mtu = dlci->gsm->mtu; in gsm_create_network()
3303 net->min_mtu = 8; in gsm_create_network()
3304 net->max_mtu = dlci->gsm->mtu; in gsm_create_network()
3306 mux_net->dlci = dlci; in gsm_create_network()
3307 kref_init(&mux_net->ref); in gsm_create_network()
3308 strncpy(nc->if_name, net->name, IFNAMSIZ); /* return net name */ in gsm_create_network()
3311 dlci->prev_adaption = dlci->adaption; in gsm_create_network()
3312 dlci->prev_data = dlci->data; in gsm_create_network()
3313 dlci->adaption = nc->adaption; in gsm_create_network()
3314 dlci->data = gsm_mux_rx_netchar; in gsm_create_network()
3315 dlci->net = net; in gsm_create_network()
3324 return net->ifindex; /* return network index */ in gsm_create_network()
3348 * gsm_modem_upd_via_data - send modem bits via convergence layer
3350 * @brk: break signal
3353 * break signal for adaption 2.
3358 struct gsm_mux *gsm = dlci->gsm; in gsm_modem_upd_via_data()
3361 if (dlci->state != DLCI_OPEN || dlci->adaption != 2) in gsm_modem_upd_via_data()
3364 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
3366 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
3370 * gsm_modem_upd_via_msc - send modem bits via control frame
3372 * @brk: break signal
3381 if (dlci->gsm->encoding != GSM_BASIC_OPT) in gsm_modem_upd_via_msc()
3384 modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ in gsm_modem_upd_via_msc()
3389 modembits[2] = (brk << 4) | 2 | EA; /* Length, Break, EA */ in gsm_modem_upd_via_msc()
3392 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsm_modem_upd_via_msc()
3394 return -ENOMEM; in gsm_modem_upd_via_msc()
3395 return gsm_control_wait(dlci->gsm, ctrl); in gsm_modem_upd_via_msc()
3399 * gsm_modem_update - send modem status line state
3401 * @brk: break signal
3406 if (dlci->adaption == 2) { in gsm_modem_update()
3410 } else if (dlci->gsm->encoding == GSM_BASIC_OPT) { in gsm_modem_update()
3411 /* Send as MSC control message. */ in gsm_modem_update()
3416 return -EPROTONOSUPPORT; in gsm_modem_update()
3422 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised()
3425 if (dlci->state != DLCI_OPEN) in gsm_carrier_raised()
3431 * Basic mode with control channel in ADM mode may not respond in gsm_carrier_raised()
3434 if (gsm->encoding == GSM_BASIC_OPT && in gsm_carrier_raised()
3435 gsm->dlci[0]->mode == DLCI_MODE_ADM && !dlci->modem_rx) in gsm_carrier_raised()
3438 return dlci->modem_rx & TIOCM_CD; in gsm_carrier_raised()
3444 unsigned int modem_tx = dlci->modem_tx; in gsm_dtr_rts()
3449 if (modem_tx != dlci->modem_tx) { in gsm_dtr_rts()
3450 dlci->modem_tx = modem_tx; in gsm_dtr_rts()
3465 unsigned int line = tty->index; in gsmtty_install()
3473 return -ENXIO; in gsmtty_install()
3476 return -EUNATCH; in gsmtty_install()
3478 return -ECHRNG; in gsmtty_install()
3480 if (gsm->dead) in gsmtty_install()
3481 return -EL2HLT; in gsmtty_install()
3486 mutex_lock(&gsm->mutex); in gsmtty_install()
3487 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) { in gsmtty_install()
3488 mutex_unlock(&gsm->mutex); in gsmtty_install()
3489 return -EL2NSYNC; in gsmtty_install()
3491 dlci = gsm->dlci[line]; in gsmtty_install()
3497 mutex_unlock(&gsm->mutex); in gsmtty_install()
3498 return -ENOMEM; in gsmtty_install()
3500 ret = tty_port_install(&dlci->port, driver, tty); in gsmtty_install()
3504 mutex_unlock(&gsm->mutex); in gsmtty_install()
3509 dlci_get(gsm->dlci[0]); in gsmtty_install()
3511 tty->driver_data = dlci; in gsmtty_install()
3512 mutex_unlock(&gsm->mutex); in gsmtty_install()
3519 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_open()
3520 struct tty_port *port = &dlci->port; in gsmtty_open()
3521 struct gsm_mux *gsm = dlci->gsm; in gsmtty_open()
3523 port->count++; in gsmtty_open()
3526 dlci->modem_rx = 0; in gsmtty_open()
3527 /* We could in theory open and close before we wait - eg if we get in gsmtty_open()
3531 if (gsm->initiator) in gsmtty_open()
3541 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_close()
3545 if (dlci->state == DLCI_CLOSED) in gsmtty_close()
3547 mutex_lock(&dlci->mutex); in gsmtty_close()
3549 mutex_unlock(&dlci->mutex); in gsmtty_close()
3550 if (tty_port_close_start(&dlci->port, tty, filp) == 0) in gsmtty_close()
3553 if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) in gsmtty_close()
3554 tty_port_lower_dtr_rts(&dlci->port); in gsmtty_close()
3555 tty_port_close_end(&dlci->port, tty); in gsmtty_close()
3556 tty_port_tty_set(&dlci->port, NULL); in gsmtty_close()
3562 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_hangup()
3563 if (dlci->state == DLCI_CLOSED) in gsmtty_hangup()
3565 tty_port_hangup(&dlci->port); in gsmtty_hangup()
3573 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write()
3574 if (dlci->state == DLCI_CLOSED) in gsmtty_write()
3575 return -EINVAL; in gsmtty_write()
3577 sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock); in gsmtty_write()
3585 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write_room()
3586 if (dlci->state == DLCI_CLOSED) in gsmtty_write_room()
3588 return kfifo_avail(&dlci->fifo); in gsmtty_write_room()
3593 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_chars_in_buffer()
3594 if (dlci->state == DLCI_CLOSED) in gsmtty_chars_in_buffer()
3596 return kfifo_len(&dlci->fifo); in gsmtty_chars_in_buffer()
3601 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_flush_buffer()
3604 if (dlci->state == DLCI_CLOSED) in gsmtty_flush_buffer()
3610 spin_lock_irqsave(&dlci->lock, flags); in gsmtty_flush_buffer()
3611 kfifo_reset(&dlci->fifo); in gsmtty_flush_buffer()
3612 spin_unlock_irqrestore(&dlci->lock, flags); in gsmtty_flush_buffer()
3625 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmget()
3626 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmget()
3627 return -EINVAL; in gsmtty_tiocmget()
3628 return dlci->modem_rx; in gsmtty_tiocmget()
3634 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmset()
3635 unsigned int modem_tx = dlci->modem_tx; in gsmtty_tiocmset()
3637 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmset()
3638 return -EINVAL; in gsmtty_tiocmset()
3642 if (modem_tx != dlci->modem_tx) { in gsmtty_tiocmset()
3643 dlci->modem_tx = modem_tx; in gsmtty_tiocmset()
3653 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_ioctl()
3657 if (dlci->state == DLCI_CLOSED) in gsmtty_ioctl()
3658 return -EINVAL; in gsmtty_ioctl()
3662 return -EFAULT; in gsmtty_ioctl()
3663 nc.if_name[IFNAMSIZ-1] = '\0'; in gsmtty_ioctl()
3665 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
3667 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
3669 return -EFAULT; in gsmtty_ioctl()
3673 return -EPERM; in gsmtty_ioctl()
3674 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
3676 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
3679 return -ENOIOCTLCMD; in gsmtty_ioctl()
3686 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_set_termios()
3687 if (dlci->state == DLCI_CLOSED) in gsmtty_set_termios()
3691 the RPN control message. This however rapidly gets nasty as we in gsmtty_set_termios()
3694 tty_termios_copy_hw(&tty->termios, old); in gsmtty_set_termios()
3699 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_throttle()
3700 if (dlci->state == DLCI_CLOSED) in gsmtty_throttle()
3703 dlci->modem_tx &= ~TIOCM_RTS; in gsmtty_throttle()
3704 dlci->throttled = true; in gsmtty_throttle()
3711 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_unthrottle()
3712 if (dlci->state == DLCI_CLOSED) in gsmtty_unthrottle()
3715 dlci->modem_tx |= TIOCM_RTS; in gsmtty_unthrottle()
3716 dlci->throttled = false; in gsmtty_unthrottle()
3723 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_break_ctl()
3725 if (dlci->state == DLCI_CLOSED) in gsmtty_break_ctl()
3726 return -EINVAL; in gsmtty_break_ctl()
3728 if (state == -1) /* "On indefinitely" - we can't encode this in gsmtty_break_ctl()
3741 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_cleanup()
3742 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup()
3745 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
3789 gsm_tty_driver->driver_name = "gsmtty"; in gsm_init()
3790 gsm_tty_driver->name = "gsmtty"; in gsm_init()
3791 gsm_tty_driver->major = 0; /* Dynamic */ in gsm_init()
3792 gsm_tty_driver->minor_start = 0; in gsm_init()
3793 gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; in gsm_init()
3794 gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; in gsm_init()
3795 gsm_tty_driver->init_termios = tty_std_termios; in gsm_init()
3797 gsm_tty_driver->init_termios.c_lflag &= ~ECHO; in gsm_init()
3802 status = -EBUSY; in gsm_init()
3806 gsm_tty_driver->major, gsm_tty_driver->minor_start); in gsm_init()