• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0
16 * Review the locking/move to refcounts more (mux now moved to an
21 * Do we need a 'which mux are you' ioctl to correlate mux and tty sets
71 * Semi-arbitrary buffer size limits. 0710 is normally run with 32-64 byte
76 /* SOF, ADDR, CTRL, LEN1, LEN2, ..., FCS, EOF */
81 * struct gsm_mux_net - network interface
99 u8 ctrl; /* Control byte + flags */ member
120 * complexity right now these are only ever freed up when the mux is
123 * At the moment we don't free DLCI objects until the mux is torn down
145 bool dead; /* Refuse re-open */
193 * Each GSM mux we have is represented by this structure. If we are
196 * to the gsm mux array. For now we don't free DLCI objects that
197 * have been instantiated until the mux itself is terminated.
199 * To consider further: tty open versus mux shutdown.
234 bool dead; /* Has the mux been shut down */
268 * Mux objects - needed so that we can translate a tty index into the
269 * relevant mux and DLCI.
374 * gsm_fcs_add - update FCS
388 * gsm_fcs_add_block - update FCS for a block
399 while (len--) in gsm_fcs_add_block()
405 * gsm_read_ea - read a byte into an EA
423 * gsm_read_ea_val - read a value until EA
435 for (; dlen > 0; dlen--) { in gsm_read_ea_val()
444 * gsm_encode_modem - encode modem data bits
455 if (dlci->throttled) in gsm_encode_modem()
457 if (dlci->modem_tx & TIOCM_DTR) in gsm_encode_modem()
459 if (dlci->modem_tx & TIOCM_RTS) in gsm_encode_modem()
461 if (dlci->modem_tx & TIOCM_RI) in gsm_encode_modem()
463 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
469 * gsm_register_devices - register all tty devices for a given mux index
472 * @index: the mux number is used to calculate the minor numbers of the
473 * ttys for this mux and may differ from the position in the
474 * mux array.
483 return -EINVAL; in gsm_register_devices()
487 /* Don't register device 0 - this is the control channel in gsm_register_devices()
495 for (i--; i >= 1; i--) in gsm_register_devices()
505 * gsm_unregister_devices - unregister all tty devices for a given mux index
508 * @index: the mux number is used to calculate the minor numbers of the
509 * ttys for this mux and may differ from the position in the
510 * mux array.
523 /* Don't unregister device 0 - this is the control in gsm_unregister_devices()
531 * gsm_print_packet - display a frame for debug
540 * style is based on amateur radio LAP-B dump display.
603 * gsm_stuff_packet - bytestuff a packet
616 while (len--) { in gsm_stuff_frame()
631 * gsm_send - send a control frame
632 * @gsm: our GSM mux
650 switch (gsm->encoding) { in gsm_send()
656 cbuf[4] = 0xFF - gsm_fcs_add_block(INIT_FCS, cbuf + 1, 3); in gsm_send()
665 ibuf[2] = 0xFF - gsm_fcs_add_block(INIT_FCS, ibuf, 2); in gsm_send()
679 gsm_print_packet("-->", addr, cr, control, NULL, 0); in gsm_send()
683 * gsm_response - send a control response
684 * @gsm: our GSM mux
697 * gsm_command - send a control command
698 * @gsm: our GSM mux
712 #define HDR_LEN 6 /* ADDR CTRL [LEN.2] DATA FCS */
715 * gsm_data_alloc - allocate data frame
716 * @gsm: GSM mux
719 * @ctrl: control byte
727 u8 ctrl) in gsm_data_alloc() argument
733 m->data = m->buffer + HDR_LEN - 1; /* Allow for FCS */ in gsm_data_alloc()
734 m->len = len; in gsm_data_alloc()
735 m->addr = addr; in gsm_data_alloc()
736 m->ctrl = ctrl; in gsm_data_alloc()
737 INIT_LIST_HEAD(&m->list); in gsm_data_alloc()
742 * gsm_is_flow_ctrl_msg - checks if flow control message
752 if (msg->addr > 0) in gsm_is_flow_ctrl_msg()
755 switch (msg->ctrl & ~PF) { in gsm_is_flow_ctrl_msg()
759 if (gsm_read_ea_val(&cmd, msg->data + 2, msg->len - 2) < 1) in gsm_is_flow_ctrl_msg()
773 * gsm_data_kick - poke the queue
774 * @gsm: GSM Mux
778 * If we have been flow-stopped by a CMD_FCOFF, then we can only
789 list_for_each_entry_safe(msg, nmsg, &gsm->tx_list, list) { in gsm_data_kick()
790 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
792 if (gsm->encoding != 0) { in gsm_data_kick()
793 gsm->txframe[0] = GSM1_SOF; in gsm_data_kick()
794 len = gsm_stuff_frame(msg->data, in gsm_data_kick()
795 gsm->txframe + 1, msg->len); in gsm_data_kick()
796 gsm->txframe[len + 1] = GSM1_SOF; in gsm_data_kick()
799 gsm->txframe[0] = GSM0_SOF; in gsm_data_kick()
800 memcpy(gsm->txframe + 1 , msg->data, msg->len); in gsm_data_kick()
801 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_data_kick()
802 len = msg->len + 2; in gsm_data_kick()
808 gsm->txframe, len); in gsm_data_kick()
809 if (gsmld_output(gsm, gsm->txframe, len) < 0) in gsm_data_kick()
812 gsm->tx_bytes -= msg->len; in gsm_data_kick()
814 list_del(&msg->list); in gsm_data_kick()
818 tty_port_tty_wakeup(&dlci->port); in gsm_data_kick()
823 if (gsm->dlci[i]) in gsm_data_kick()
824 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsm_data_kick()
830 * __gsm_data_queue - queue a UI or UIH frame
835 * out of the mux tty if not already doing so. The Caller must hold
841 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue()
842 u8 *dp = msg->data; in __gsm_data_queue()
843 u8 *fcs = dp + msg->len; in __gsm_data_queue()
846 if (gsm->encoding == 0) { in __gsm_data_queue()
847 if (msg->len < 128) in __gsm_data_queue()
848 *--dp = (msg->len << 1) | EA; in __gsm_data_queue()
850 *--dp = (msg->len >> 7); /* bits 7 - 15 */ in __gsm_data_queue()
851 *--dp = (msg->len & 127) << 1; /* bits 0 - 6 */ in __gsm_data_queue()
855 *--dp = msg->ctrl; in __gsm_data_queue()
856 if (gsm->initiator) in __gsm_data_queue()
857 *--dp = (msg->addr << 2) | 2 | EA; in __gsm_data_queue()
859 *--dp = (msg->addr << 2) | EA; in __gsm_data_queue()
860 *fcs = gsm_fcs_add_block(INIT_FCS, dp , msg->data - dp); in __gsm_data_queue()
862 if (msg->ctrl == UI || msg->ctrl == (UI|PF)) in __gsm_data_queue()
863 *fcs = gsm_fcs_add_block(*fcs, msg->data, msg->len); in __gsm_data_queue()
864 *fcs = 0xFF - *fcs; in __gsm_data_queue()
866 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
867 msg->data, msg->len); in __gsm_data_queue()
871 msg->len += (msg->data - dp) + 1; in __gsm_data_queue()
872 msg->data = dp; in __gsm_data_queue()
875 list_add_tail(&msg->list, &gsm->tx_list); in __gsm_data_queue()
876 gsm->tx_bytes += msg->len; in __gsm_data_queue()
881 * gsm_data_queue - queue a UI or UIH frame
886 * out of the mux tty if not already doing so. Take the
893 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
895 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
899 * gsm_dlci_data_output - try and push data out of a DLCI
900 * @gsm: mux
904 * is data. Keep to the MRU of the mux. This path handles the usual tty
907 * Caller must hold the tx_lock of the mux.
917 h = ((dlci->adaption == 1) ? 0 : 1); in gsm_dlci_data_output()
919 len = kfifo_len(&dlci->fifo); in gsm_dlci_data_output()
924 if ((len + h) > gsm->mtu) in gsm_dlci_data_output()
925 len = gsm->mtu - h; in gsm_dlci_data_output()
929 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_data_output()
934 return -ENOMEM; in gsm_dlci_data_output()
935 dp = msg->data; in gsm_dlci_data_output()
936 switch (dlci->adaption) { in gsm_dlci_data_output()
946 dlci->adaption); in gsm_dlci_data_output()
950 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len, in gsm_dlci_data_output()
951 &dlci->lock)); in gsm_dlci_data_output()
954 tty_port_tty_wakeup(&dlci->port); in gsm_dlci_data_output()
962 * gsm_dlci_data_output_framed - try and push data out of a DLCI
963 * @gsm: mux
967 * is data. Keep to the MRU of the mux. This path handles framed data
970 * Caller must hold the tx_lock of the mux.
983 if (dlci->adaption == 4) in gsm_dlci_data_output_framed()
986 /* dlci->skb is locked by tx_lock */ in gsm_dlci_data_output_framed()
987 if (dlci->skb == NULL) { in gsm_dlci_data_output_framed()
988 dlci->skb = skb_dequeue_tail(&dlci->skb_list); in gsm_dlci_data_output_framed()
989 if (dlci->skb == NULL) in gsm_dlci_data_output_framed()
993 len = dlci->skb->len + overhead; in gsm_dlci_data_output_framed()
996 if (len > gsm->mtu) { in gsm_dlci_data_output_framed()
997 if (dlci->adaption == 3) { in gsm_dlci_data_output_framed()
999 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1000 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1003 len = gsm->mtu; in gsm_dlci_data_output_framed()
1008 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_data_output_framed()
1013 skb_queue_tail(&dlci->skb_list, dlci->skb); in gsm_dlci_data_output_framed()
1014 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1015 return -ENOMEM; in gsm_dlci_data_output_framed()
1017 dp = msg->data; in gsm_dlci_data_output_framed()
1019 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */ in gsm_dlci_data_output_framed()
1022 len--; in gsm_dlci_data_output_framed()
1024 memcpy(dp, dlci->skb->data, len); in gsm_dlci_data_output_framed()
1025 skb_pull(dlci->skb, len); in gsm_dlci_data_output_framed()
1028 dev_kfree_skb_any(dlci->skb); in gsm_dlci_data_output_framed()
1029 dlci->skb = NULL; in gsm_dlci_data_output_framed()
1035 * gsm_dlci_data_sweep - look for data to send
1036 * @gsm: the GSM mux
1038 * Sweep the GSM mux channels in priority order looking for ones with
1056 if (gsm->tx_bytes > TX_THRESH_HI) in gsm_dlci_data_sweep()
1058 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1059 if (dlci == NULL || dlci->constipated) { in gsm_dlci_data_sweep()
1063 if (dlci->adaption < 3 && !dlci->net) in gsm_dlci_data_sweep()
1069 /* DLCI empty - try the next */ in gsm_dlci_data_sweep()
1076 * gsm_dlci_data_kick - transmit if possible
1089 if (dlci->constipated) in gsm_dlci_data_kick()
1092 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1094 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1095 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1096 if (dlci->net) in gsm_dlci_data_kick()
1097 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1099 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1102 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1103 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1112 * gsm_control_reply - send a response frame to a control
1125 msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); in gsm_control_reply()
1128 msg->data[0] = (cmd & 0xFE) << 1 | EA; /* Clear C/R */ in gsm_control_reply()
1129 msg->data[1] = (dlen << 1) | EA; in gsm_control_reply()
1130 memcpy(msg->data + 2, data, dlen); in gsm_control_reply()
1131 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_reply()
1135 * gsm_process_modem - process received modem status
1154 5.4.6.3.7 of the 27.010 mux spec. */ in gsm_process_modem()
1165 if (fc && !dlci->constipated) { in gsm_process_modem()
1167 dlci->constipated = true; in gsm_process_modem()
1168 } else if (!fc && dlci->constipated) { in gsm_process_modem()
1169 dlci->constipated = false; in gsm_process_modem()
1183 /* Carrier drop -> hangup */ in gsm_process_modem()
1185 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD)) in gsm_process_modem()
1190 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK); in gsm_process_modem()
1191 dlci->modem_rx = mlines; in gsm_process_modem()
1195 * gsm_control_modem - modem status received
1201 * the GSM mux protocol to pass virtual modem line status and optionally
1217 len--; in gsm_control_modem()
1222 len--; in gsm_control_modem()
1228 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1230 dlci = gsm->dlci[addr]; in gsm_control_modem()
1233 len--; in gsm_control_modem()
1237 len--; in gsm_control_modem()
1240 len--; in gsm_control_modem()
1247 tty = tty_port_tty_get(&dlci->port); in gsm_control_modem()
1257 * gsm_control_rls - remote line status
1276 len--; in gsm_control_rls()
1281 len--; in gsm_control_rls()
1286 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1293 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1310 * gsm_control_message - DLCI 0 control processing
1311 * @gsm: our GSM mux
1329 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1332 dlci->dead = true; in gsm_control_message()
1333 gsm->dead = true; in gsm_control_message()
1344 gsm->constipated = false; in gsm_control_message()
1347 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_control_message()
1349 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_control_message()
1353 gsm->constipated = true; in gsm_control_message()
1381 * gsm_control_response - process a response to our control
1382 * @gsm: our GSM mux
1387 * Process a response to an outstanding command. We only allow a single
1396 struct gsm_control *ctrl; in gsm_control_response() local
1399 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1401 ctrl = gsm->pending_cmd; in gsm_control_response()
1404 if (ctrl != NULL && (command == ctrl->cmd || command == CMD_NSC)) { in gsm_control_response()
1406 del_timer(&gsm->t2_timer); in gsm_control_response()
1407 gsm->pending_cmd = NULL; in gsm_control_response()
1410 ctrl->error = -EOPNOTSUPP; in gsm_control_response()
1411 ctrl->done = 1; in gsm_control_response()
1412 wake_up(&gsm->event); in gsm_control_response()
1414 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1418 * gsm_control_transmit - send control packet
1419 * @gsm: gsm mux
1420 * @ctrl: frame to send
1425 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) in gsm_control_transmit() argument
1427 struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->len + 2, gsm->ftype); in gsm_control_transmit()
1430 msg->data[0] = (ctrl->cmd << 1) | CR | EA; /* command */ in gsm_control_transmit()
1431 msg->data[1] = (ctrl->len << 1) | EA; in gsm_control_transmit()
1432 memcpy(msg->data + 2, ctrl->data, ctrl->len); in gsm_control_transmit()
1433 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_transmit()
1437 * gsm_control_retransmit - retransmit a control frame
1444 * gsm->pending_cmd will be NULL and we just let the timer expire.
1450 struct gsm_control *ctrl; in gsm_control_retransmit() local
1452 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
1453 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
1454 if (ctrl) { in gsm_control_retransmit()
1455 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
1456 gsm->pending_cmd = NULL; in gsm_control_retransmit()
1457 ctrl->error = -ETIMEDOUT; in gsm_control_retransmit()
1458 ctrl->done = 1; in gsm_control_retransmit()
1459 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
1460 wake_up(&gsm->event); in gsm_control_retransmit()
1463 gsm->cretries--; in gsm_control_retransmit()
1464 gsm_control_transmit(gsm, ctrl); in gsm_control_retransmit()
1465 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
1467 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
1471 * gsm_control_send - send a control frame on DLCI 0
1485 struct gsm_control *ctrl = kzalloc(sizeof(struct gsm_control), in gsm_control_send() local
1488 if (ctrl == NULL) in gsm_control_send()
1491 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
1492 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
1493 if (gsm->pending_cmd != NULL) { in gsm_control_send()
1494 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
1497 ctrl->cmd = command; in gsm_control_send()
1498 ctrl->data = data; in gsm_control_send()
1499 ctrl->len = clen; in gsm_control_send()
1500 gsm->pending_cmd = ctrl; in gsm_control_send()
1503 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
1504 gsm->cretries = 0; in gsm_control_send()
1506 gsm->cretries = gsm->n2; in gsm_control_send()
1508 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
1509 gsm_control_transmit(gsm, ctrl); in gsm_control_send()
1510 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
1511 return ctrl; in gsm_control_send()
1515 * gsm_control_wait - wait for a control to finish
1516 * @gsm: GSM mux
1527 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
1528 err = control->error; in gsm_control_wait()
1543 * gsm_dlci_close - a DLCI has closed
1554 del_timer(&dlci->t1); in gsm_dlci_close()
1556 pr_debug("DLCI %d goes closed.\n", dlci->addr); in gsm_dlci_close()
1557 dlci->state = DLCI_CLOSED; in gsm_dlci_close()
1559 dlci->constipated = true; in gsm_dlci_close()
1560 if (dlci->addr != 0) { in gsm_dlci_close()
1561 tty_port_tty_hangup(&dlci->port, false); in gsm_dlci_close()
1562 spin_lock_irqsave(&dlci->lock, flags); in gsm_dlci_close()
1563 kfifo_reset(&dlci->fifo); in gsm_dlci_close()
1564 spin_unlock_irqrestore(&dlci->lock, flags); in gsm_dlci_close()
1566 tty_port_set_initialized(&dlci->port, 0); in gsm_dlci_close()
1567 wake_up_interruptible(&dlci->port.open_wait); in gsm_dlci_close()
1569 dlci->gsm->dead = true; in gsm_dlci_close()
1570 wake_up(&dlci->gsm->event); in gsm_dlci_close()
1571 /* A DLCI 0 close is a MUX termination so we need to kick that in gsm_dlci_close()
1576 * gsm_dlci_open - a DLCI has opened
1585 open -> open */ in gsm_dlci_open()
1586 del_timer(&dlci->t1); in gsm_dlci_open()
1588 dlci->state = DLCI_OPEN; in gsm_dlci_open()
1589 dlci->constipated = false; in gsm_dlci_open()
1591 pr_debug("DLCI %d goes open.\n", dlci->addr); in gsm_dlci_open()
1592 wake_up(&dlci->gsm->event); in gsm_dlci_open()
1596 * gsm_dlci_t1 - T1 timer expiry
1613 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1()
1615 switch (dlci->state) { in gsm_dlci_t1()
1617 if (dlci->retries) { in gsm_dlci_t1()
1618 dlci->retries--; in gsm_dlci_t1()
1619 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
1620 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
1621 } else if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
1624 dlci->addr); in gsm_dlci_t1()
1625 dlci->mode = DLCI_MODE_ADM; in gsm_dlci_t1()
1633 if (dlci->retries) { in gsm_dlci_t1()
1634 dlci->retries--; in gsm_dlci_t1()
1635 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
1636 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
1641 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state); in gsm_dlci_t1()
1647 * gsm_dlci_begin_open - start channel open procedure
1658 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_open()
1659 if (dlci->state == DLCI_OPEN || dlci->state == DLCI_OPENING) in gsm_dlci_begin_open()
1661 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
1662 dlci->state = DLCI_OPENING; in gsm_dlci_begin_open()
1663 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
1664 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
1668 * gsm_dlci_set_opening - change state to opening
1676 switch (dlci->state) { in gsm_dlci_set_opening()
1679 dlci->state = DLCI_OPENING; in gsm_dlci_set_opening()
1687 * gsm_dlci_begin_close - start channel open procedure
1699 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close()
1700 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING) in gsm_dlci_begin_close()
1702 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
1703 dlci->state = DLCI_CLOSING; in gsm_dlci_begin_close()
1704 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
1705 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
1709 * gsm_dlci_data - data arrived
1722 struct tty_port *port = &dlci->port; in gsm_dlci_data()
1729 switch (dlci->adaption) { in gsm_dlci_data()
1737 len--; in gsm_dlci_data()
1755 * gsm_dlci_control - data arrived on control channel
1770 while (len-- > 0) { in gsm_dlci_command()
1773 len--; in gsm_dlci_command()
1780 gsm_control_message(dlci->gsm, command, in gsm_dlci_command()
1783 gsm_control_response(dlci->gsm, command, in gsm_dlci_command()
1795 * gsm_dlci_alloc - allocate a DLCI
1796 * @gsm: GSM mux
1799 * Allocate and install a new DLCI object into the GSM mux.
1809 spin_lock_init(&dlci->lock); in gsm_dlci_alloc()
1810 mutex_init(&dlci->mutex); in gsm_dlci_alloc()
1811 if (kfifo_alloc(&dlci->fifo, 4096, GFP_KERNEL) < 0) { in gsm_dlci_alloc()
1816 skb_queue_head_init(&dlci->skb_list); in gsm_dlci_alloc()
1817 timer_setup(&dlci->t1, gsm_dlci_t1, 0); in gsm_dlci_alloc()
1818 tty_port_init(&dlci->port); in gsm_dlci_alloc()
1819 dlci->port.ops = &gsm_port_ops; in gsm_dlci_alloc()
1820 dlci->gsm = gsm; in gsm_dlci_alloc()
1821 dlci->addr = addr; in gsm_dlci_alloc()
1822 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
1823 dlci->state = DLCI_CLOSED; in gsm_dlci_alloc()
1825 dlci->data = gsm_dlci_data; in gsm_dlci_alloc()
1827 dlci->constipated = true; in gsm_dlci_alloc()
1829 dlci->data = gsm_dlci_command; in gsm_dlci_alloc()
1831 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
1836 * gsm_dlci_free - free DLCI
1847 del_timer_sync(&dlci->t1); in gsm_dlci_free()
1848 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
1849 kfifo_free(&dlci->fifo); in gsm_dlci_free()
1850 while ((dlci->skb = skb_dequeue(&dlci->skb_list))) in gsm_dlci_free()
1851 dev_kfree_skb(dlci->skb); in gsm_dlci_free()
1857 tty_port_get(&dlci->port); in dlci_get()
1862 tty_port_put(&dlci->port); in dlci_put()
1868 * gsm_dlci_release - release DLCI
1872 * mux is closed or tty is closed - whichever is last.
1878 struct tty_struct *tty = tty_port_tty_get(&dlci->port); in gsm_dlci_release()
1880 mutex_lock(&dlci->mutex); in gsm_dlci_release()
1882 mutex_unlock(&dlci->mutex); in gsm_dlci_release()
1886 * queue release_one_tty() -> NULL pointer panic in in gsm_dlci_release()
1891 tty_port_tty_set(&dlci->port, NULL); in gsm_dlci_release()
1894 dlci->state = DLCI_CLOSED; in gsm_dlci_release()
1903 * gsm_queue - a GSM frame is ready to process
1904 * @gsm: pointer to our gsm mux
1920 if ((gsm->control & ~PF) == UI) in gsm_queue()
1921 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, gsm->len); in gsm_queue()
1922 if (gsm->encoding == 0) { in gsm_queue()
1923 /* WARNING: gsm->received_fcs is used for in gsm_queue()
1924 gsm->encoding = 0 only. in gsm_queue()
1927 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->received_fcs); in gsm_queue()
1929 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
1930 gsm->bad_fcs++; in gsm_queue()
1932 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
1935 address = gsm->address >> 1; in gsm_queue()
1939 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
1941 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
1943 cr ^= 1 - gsm->initiator; /* Flip so 1 always means command */ in gsm_queue()
1944 dlci = gsm->dlci[address]; in gsm_queue()
1946 switch (gsm->control) { in gsm_queue()
1954 if (dlci->dead) in gsm_queue()
1964 if (dlci == NULL || dlci->state == DLCI_CLOSED) { in gsm_queue()
1975 switch (dlci->state) { in gsm_queue()
1984 dlci->state); in gsm_queue()
2004 if (dlci == NULL || dlci->state != DLCI_OPEN) { in gsm_queue()
2008 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2015 gsm->malformed++; in gsm_queue()
2021 * gsm0_receive - perform processing for non-transparency
2032 switch (gsm->state) { in gsm0_receive()
2035 gsm->state = GSM_ADDRESS; in gsm0_receive()
2036 gsm->address = 0; in gsm0_receive()
2037 gsm->len = 0; in gsm0_receive()
2038 gsm->fcs = INIT_FCS; in gsm0_receive()
2042 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2043 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
2044 gsm->state = GSM_CONTROL; in gsm0_receive()
2047 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2048 gsm->control = c; in gsm0_receive()
2049 gsm->state = GSM_LEN0; in gsm0_receive()
2052 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2053 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
2054 if (gsm->len > gsm->mru) { in gsm0_receive()
2055 gsm->bad_size++; in gsm0_receive()
2056 gsm->state = GSM_SEARCH; in gsm0_receive()
2059 gsm->count = 0; in gsm0_receive()
2060 if (!gsm->len) in gsm0_receive()
2061 gsm->state = GSM_FCS; in gsm0_receive()
2063 gsm->state = GSM_DATA; in gsm0_receive()
2066 gsm->state = GSM_LEN1; in gsm0_receive()
2069 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2071 gsm->len |= len << 7; in gsm0_receive()
2072 if (gsm->len > gsm->mru) { in gsm0_receive()
2073 gsm->bad_size++; in gsm0_receive()
2074 gsm->state = GSM_SEARCH; in gsm0_receive()
2077 gsm->count = 0; in gsm0_receive()
2078 if (!gsm->len) in gsm0_receive()
2079 gsm->state = GSM_FCS; in gsm0_receive()
2081 gsm->state = GSM_DATA; in gsm0_receive()
2084 gsm->buf[gsm->count++] = c; in gsm0_receive()
2085 if (gsm->count == gsm->len) in gsm0_receive()
2086 gsm->state = GSM_FCS; in gsm0_receive()
2089 gsm->received_fcs = c; in gsm0_receive()
2091 gsm->state = GSM_SSOF; in gsm0_receive()
2095 gsm->state = GSM_SEARCH; in gsm0_receive()
2100 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2106 * gsm1_receive - perform processing for non-transparency
2117 gsm->constipated = true; in gsm1_receive()
2120 gsm->constipated = false; in gsm1_receive()
2128 if (gsm->state == GSM_DATA && gsm->count) { in gsm1_receive()
2130 gsm->count--; in gsm1_receive()
2131 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
2132 gsm->len = gsm->count; in gsm1_receive()
2134 gsm->state = GSM_START; in gsm1_receive()
2138 if (gsm->state != GSM_START) { in gsm1_receive()
2139 if (gsm->state != GSM_SEARCH) in gsm1_receive()
2140 gsm->malformed++; in gsm1_receive()
2141 gsm->state = GSM_START; in gsm1_receive()
2149 gsm->escape = true; in gsm1_receive()
2154 if (gsm->state == GSM_SEARCH) in gsm1_receive()
2157 if (gsm->escape) { in gsm1_receive()
2159 gsm->escape = false; in gsm1_receive()
2161 switch (gsm->state) { in gsm1_receive()
2163 gsm->address = 0; in gsm1_receive()
2164 gsm->state = GSM_ADDRESS; in gsm1_receive()
2165 gsm->fcs = INIT_FCS; in gsm1_receive()
2168 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
2169 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
2170 gsm->state = GSM_CONTROL; in gsm1_receive()
2173 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
2174 gsm->control = c; in gsm1_receive()
2175 gsm->count = 0; in gsm1_receive()
2176 gsm->state = GSM_DATA; in gsm1_receive()
2179 if (gsm->count > gsm->mru) { /* Allow one for the FCS */ in gsm1_receive()
2180 gsm->state = GSM_OVERRUN; in gsm1_receive()
2181 gsm->bad_size++; in gsm1_receive()
2183 gsm->buf[gsm->count++] = c; in gsm1_receive()
2185 case GSM_OVERRUN: /* Over-long - eg a dropped SOF */ in gsm1_receive()
2188 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
2194 * gsm_error - handle tty error
2208 gsm->state = GSM_SEARCH; in gsm_error()
2209 gsm->io_error++; in gsm_error()
2213 * gsm_cleanup_mux - generic GSM protocol cleanup
2214 * @gsm: our mux
2217 * Clean up the bits of the mux which are the same for all framing
2218 * protocols. Remove the mux from the mux table, stop all the timers
2228 gsm->dead = true; in gsm_cleanup_mux()
2229 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
2231 dlci = gsm->dlci[0]; in gsm_cleanup_mux()
2233 if (disc && dlci->state != DLCI_CLOSED) { in gsm_cleanup_mux()
2235 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
2237 dlci->dead = true; in gsm_cleanup_mux()
2241 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
2244 if (gsm->has_devices) { in gsm_cleanup_mux()
2245 gsm_unregister_devices(gsm_tty_driver, gsm->num); in gsm_cleanup_mux()
2246 gsm->has_devices = false; in gsm_cleanup_mux()
2248 for (i = NUM_DLCI - 1; i >= 0; i--) in gsm_cleanup_mux()
2249 if (gsm->dlci[i]) in gsm_cleanup_mux()
2250 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
2251 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
2253 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
2254 list_for_each_entry_safe(txq, ntxq, &gsm->tx_list, list) in gsm_cleanup_mux()
2256 INIT_LIST_HEAD(&gsm->tx_list); in gsm_cleanup_mux()
2260 * gsm_activate_mux - generic GSM setup
2261 * @gsm: our mux
2263 * Set up the bits of the mux which are the same for all framing
2264 * protocols. Add the mux to the mux table so it can be opened and
2273 if (gsm->encoding == 0) in gsm_activate_mux()
2274 gsm->receive = gsm0_receive; in gsm_activate_mux()
2276 gsm->receive = gsm1_receive; in gsm_activate_mux()
2278 ret = gsm_register_devices(gsm_tty_driver, gsm->num); in gsm_activate_mux()
2284 return -ENOMEM; in gsm_activate_mux()
2285 gsm->has_devices = true; in gsm_activate_mux()
2286 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
2291 * gsm_free_mux - free up a mux
2292 * @gsm: mux to free
2294 * Dispose of allocated resources for a dead mux
2306 mutex_destroy(&gsm->mutex); in gsm_free_mux()
2307 kfree(gsm->txframe); in gsm_free_mux()
2308 kfree(gsm->buf); in gsm_free_mux()
2313 * gsm_free_muxr - free up a mux
2314 * @ref: kreference to the mux to free
2316 * Dispose of allocated resources for a dead mux
2329 kref_get(&gsm->ref); in mux_get()
2338 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
2344 return gsm->num * NUM_DLCI; in mux_num_to_base()
2353 * gsm_alloc_mux - allocate a mux
2355 * Creates a new mux ready for activation.
2364 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
2365 if (gsm->buf == NULL) { in gsm_alloc_mux()
2369 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
2370 if (gsm->txframe == NULL) { in gsm_alloc_mux()
2371 kfree(gsm->buf); in gsm_alloc_mux()
2375 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
2376 mutex_init(&gsm->mutex); in gsm_alloc_mux()
2377 kref_init(&gsm->ref); in gsm_alloc_mux()
2378 INIT_LIST_HEAD(&gsm->tx_list); in gsm_alloc_mux()
2379 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
2380 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
2381 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
2382 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
2384 gsm->t1 = T1; in gsm_alloc_mux()
2385 gsm->t2 = T2; in gsm_alloc_mux()
2386 gsm->n2 = N2; in gsm_alloc_mux()
2387 gsm->ftype = UIH; in gsm_alloc_mux()
2388 gsm->adaption = 1; in gsm_alloc_mux()
2389 gsm->encoding = 1; in gsm_alloc_mux()
2390 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
2391 gsm->mtu = 64; in gsm_alloc_mux()
2392 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
2394 /* Store the instance to the mux array or abort if no space is in gsm_alloc_mux()
2401 gsm->num = i; in gsm_alloc_mux()
2407 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
2408 kfree(gsm->txframe); in gsm_alloc_mux()
2409 kfree(gsm->buf); in gsm_alloc_mux()
2421 c->adaption = gsm->adaption; in gsm_copy_config_values()
2422 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
2423 c->initiator = gsm->initiator; in gsm_copy_config_values()
2424 c->t1 = gsm->t1; in gsm_copy_config_values()
2425 c->t2 = gsm->t2; in gsm_copy_config_values()
2426 c->t3 = 0; /* Not supported */ in gsm_copy_config_values()
2427 c->n2 = gsm->n2; in gsm_copy_config_values()
2428 if (gsm->ftype == UIH) in gsm_copy_config_values()
2429 c->i = 1; in gsm_copy_config_values()
2431 c->i = 2; in gsm_copy_config_values()
2432 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
2433 c->mru = gsm->mru; in gsm_copy_config_values()
2434 c->mtu = gsm->mtu; in gsm_copy_config_values()
2435 c->k = 0; in gsm_copy_config_values()
2444 /* Stuff we don't support yet - UI or I frame transport, windowing */ in gsm_config()
2445 if ((c->adaption != 1 && c->adaption != 2) || c->k) in gsm_config()
2446 return -EOPNOTSUPP; in gsm_config()
2448 if (c->mru > MAX_MRU || c->mtu > MAX_MTU || c->mru < 8 || c->mtu < 8) in gsm_config()
2449 return -EINVAL; in gsm_config()
2450 if (c->n2 > 255) in gsm_config()
2451 return -EINVAL; in gsm_config()
2452 if (c->encapsulation > 1) /* Basic, advanced, no I */ in gsm_config()
2453 return -EINVAL; in gsm_config()
2454 if (c->initiator > 1) in gsm_config()
2455 return -EINVAL; in gsm_config()
2456 if (c->i == 0 || c->i > 2) /* UIH and UI only */ in gsm_config()
2457 return -EINVAL; in gsm_config()
2463 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
2465 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
2467 if (c->encapsulation != gsm->encoding) in gsm_config()
2469 if (c->adaption != gsm->adaption) in gsm_config()
2472 if (c->initiator != gsm->initiator) in gsm_config()
2474 if (c->mru != gsm->mru) in gsm_config()
2476 if (c->mtu != gsm->mtu) in gsm_config()
2487 gsm->initiator = c->initiator; in gsm_config()
2488 gsm->mru = c->mru; in gsm_config()
2489 gsm->mtu = c->mtu; in gsm_config()
2490 gsm->encoding = c->encapsulation; in gsm_config()
2491 gsm->adaption = c->adaption; in gsm_config()
2492 gsm->n2 = c->n2; in gsm_config()
2494 if (c->i == 1) in gsm_config()
2495 gsm->ftype = UIH; in gsm_config()
2496 else if (c->i == 2) in gsm_config()
2497 gsm->ftype = UI; in gsm_config()
2499 if (c->t1) in gsm_config()
2500 gsm->t1 = c->t1; in gsm_config()
2501 if (c->t2) in gsm_config()
2502 gsm->t2 = c->t2; in gsm_config()
2506 * and removing from the mux array in gsm_config()
2508 if (gsm->dead) { in gsm_config()
2512 if (gsm->initiator) in gsm_config()
2513 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
2519 * gsmld_output - write to link
2520 * @gsm: our mux
2524 * Write a block of data from the GSM mux to the data channel. This
2530 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
2531 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
2532 return -ENOSPC; in gsmld_output()
2537 gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
2542 * gsmld_attach_gsm - mode set up
2544 * @gsm: our mux
2546 * Set up the MUX for basic mode and commence connecting to the
2553 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
2555 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
2556 tty->termios.c_iflag &= (IXON | IXOFF); in gsmld_attach_gsm()
2560 * gsmld_detach_gsm - stop doing 0710 mux
2561 * @tty: tty attached to the mux
2562 * @gsm: mux
2569 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
2571 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
2572 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
2573 gsm->tty = NULL; in gsmld_detach_gsm()
2579 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf()
2586 for (; count; count--, cp++) { in gsmld_receive_buf()
2591 if (gsm->receive) in gsmld_receive_buf()
2592 gsm->receive(gsm, *cp); in gsmld_receive_buf()
2611 * gsmld_flush_buffer - clean input queue
2624 * gsmld_close - close the ldisc for this tty
2635 struct gsm_mux *gsm = tty->disc_data; in gsmld_close()
2651 * gsmld_open - open an ldisc
2665 return -EPERM; in gsmld_open()
2667 if (tty->ops->write == NULL) in gsmld_open()
2668 return -EINVAL; in gsmld_open()
2673 return -ENOMEM; in gsmld_open()
2675 tty->disc_data = gsm; in gsmld_open()
2676 tty->receive_room = 65536; in gsmld_open()
2679 gsm->encoding = 1; in gsmld_open()
2683 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsmld_open()
2689 * gsmld_write_wakeup - asynchronous I/O notifier
2699 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup()
2703 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write_wakeup()
2704 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_wakeup()
2706 if (gsm->tx_bytes < TX_THRESH_LO) { in gsmld_write_wakeup()
2709 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_wakeup()
2713 * gsmld_read - read function for tty
2731 return -EOPNOTSUPP; in gsmld_read()
2735 * gsmld_write - write function for tty
2743 * as-is and must be properly framed and checksummed as appropriate
2751 struct gsm_mux *gsm = tty->disc_data; in gsmld_write()
2757 return -ENODEV; in gsmld_write()
2759 ret = -ENOBUFS; in gsmld_write()
2760 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
2763 ret = tty->ops->write(tty, buf, nr); in gsmld_write()
2765 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in gsmld_write()
2766 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
2772 * gsmld_poll - poll method for N_GSM0710
2782 * Called without the kernel lock held - fine
2789 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll()
2791 poll_wait(file, &tty->read_wait, wait); in gsmld_poll()
2792 poll_wait(file, &tty->write_wait, wait); in gsmld_poll()
2794 if (gsm->dead) in gsmld_poll()
2798 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in gsmld_poll()
2809 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl()
2816 return -EFAULT; in gsmld_ioctl()
2820 return -EFAULT; in gsmld_ioctl()
2850 if (!dlci->net) { in dlci_net_free()
2854 dlci->adaption = dlci->prev_adaption; in dlci_net_free()
2855 dlci->data = dlci->prev_data; in dlci_net_free()
2856 free_netdev(dlci->net); in dlci_net_free()
2857 dlci->net = NULL; in dlci_net_free()
2865 dlci = mux_net->dlci; in net_free()
2867 if (dlci->net) { in net_free()
2868 unregister_netdev(dlci->net); in net_free()
2875 kref_get(&mux_net->ref); in muxnet_get()
2880 kref_put(&mux_net->ref, net_free); in muxnet_put()
2887 struct gsm_dlci *dlci = mux_net->dlci; in gsm_mux_net_start_xmit()
2890 skb_queue_head(&dlci->skb_list, skb); in gsm_mux_net_start_xmit()
2891 net->stats.tx_packets++; in gsm_mux_net_start_xmit()
2892 net->stats.tx_bytes += skb->len; in gsm_mux_net_start_xmit()
2904 dev_dbg(&net->dev, "Tx timed out.\n"); in gsm_mux_net_tx_timeout()
2907 net->stats.tx_errors++; in gsm_mux_net_tx_timeout()
2913 struct net_device *net = dlci->net; in gsm_mux_rx_netchar()
2922 net->stats.rx_dropped++; in gsm_mux_rx_netchar()
2929 skb->dev = net; in gsm_mux_rx_netchar()
2930 skb->protocol = htons(ETH_P_IP); in gsm_mux_rx_netchar()
2936 net->stats.rx_packets++; in gsm_mux_rx_netchar()
2937 net->stats.rx_bytes += size; in gsm_mux_rx_netchar()
2951 net->netdev_ops = &gsm_netdev_ops; in gsm_mux_net_init()
2954 net->watchdog_timeo = GSM_NET_TX_TIMEOUT; in gsm_mux_net_init()
2955 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in gsm_mux_net_init()
2956 net->type = ARPHRD_NONE; in gsm_mux_net_init()
2957 net->tx_queue_len = 10; in gsm_mux_net_init()
2967 if (!dlci->net) in gsm_destroy_network()
2969 mux_net = netdev_priv(dlci->net); in gsm_destroy_network()
2983 return -EPERM; in gsm_create_network()
2986 if (dlci->adaption > 2) in gsm_create_network()
2987 return -EBUSY; in gsm_create_network()
2989 if (nc->protocol != htons(ETH_P_IP)) in gsm_create_network()
2990 return -EPROTONOSUPPORT; in gsm_create_network()
2992 if (nc->adaption != 3 && nc->adaption != 4) in gsm_create_network()
2993 return -EPROTONOSUPPORT; in gsm_create_network()
2998 if (nc->if_name[0] != '\0') in gsm_create_network()
2999 netname = nc->if_name; in gsm_create_network()
3004 return -ENOMEM; in gsm_create_network()
3006 net->mtu = dlci->gsm->mtu; in gsm_create_network()
3007 net->min_mtu = 8; in gsm_create_network()
3008 net->max_mtu = dlci->gsm->mtu; in gsm_create_network()
3010 mux_net->dlci = dlci; in gsm_create_network()
3011 kref_init(&mux_net->ref); in gsm_create_network()
3012 strncpy(nc->if_name, net->name, IFNAMSIZ); /* return net name */ in gsm_create_network()
3015 dlci->prev_adaption = dlci->adaption; in gsm_create_network()
3016 dlci->prev_data = dlci->data; in gsm_create_network()
3017 dlci->adaption = nc->adaption; in gsm_create_network()
3018 dlci->data = gsm_mux_rx_netchar; in gsm_create_network()
3019 dlci->net = net; in gsm_create_network()
3028 return net->ifindex; /* return network index */ in gsm_create_network()
3056 struct gsm_control *ctrl; in gsmtty_modem_update() local
3059 modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */ in gsmtty_modem_update()
3065 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsmtty_modem_update()
3066 if (ctrl == NULL) in gsmtty_modem_update()
3067 return -ENOMEM; in gsmtty_modem_update()
3068 return gsm_control_wait(dlci->gsm, ctrl); in gsmtty_modem_update()
3074 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised()
3077 if (dlci->state != DLCI_OPEN) in gsm_carrier_raised()
3086 if (gsm->encoding == 0 && gsm->dlci[0]->mode == DLCI_MODE_ADM && in gsm_carrier_raised()
3087 !dlci->modem_rx) in gsm_carrier_raised()
3090 return dlci->modem_rx & TIOCM_CD; in gsm_carrier_raised()
3096 unsigned int modem_tx = dlci->modem_tx; in gsm_dtr_rts()
3101 if (modem_tx != dlci->modem_tx) { in gsm_dtr_rts()
3102 dlci->modem_tx = modem_tx; in gsm_dtr_rts()
3117 unsigned int line = tty->index; in gsmtty_install()
3118 unsigned int mux = mux_line_to_num(line); in gsmtty_install() local
3124 if (mux >= MAX_MUX) in gsmtty_install()
3125 return -ENXIO; in gsmtty_install()
3127 if (gsm_mux[mux] == NULL) in gsmtty_install()
3128 return -EUNATCH; in gsmtty_install()
3130 return -ECHRNG; in gsmtty_install()
3131 gsm = gsm_mux[mux]; in gsmtty_install()
3132 if (gsm->dead) in gsmtty_install()
3133 return -EL2HLT; in gsmtty_install()
3138 mutex_lock(&gsm->mutex); in gsmtty_install()
3139 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) { in gsmtty_install()
3140 mutex_unlock(&gsm->mutex); in gsmtty_install()
3141 return -EL2NSYNC; in gsmtty_install()
3143 dlci = gsm->dlci[line]; in gsmtty_install()
3149 mutex_unlock(&gsm->mutex); in gsmtty_install()
3150 return -ENOMEM; in gsmtty_install()
3152 ret = tty_port_install(&dlci->port, driver, tty); in gsmtty_install()
3156 mutex_unlock(&gsm->mutex); in gsmtty_install()
3161 dlci_get(gsm->dlci[0]); in gsmtty_install()
3163 tty->driver_data = dlci; in gsmtty_install()
3164 mutex_unlock(&gsm->mutex); in gsmtty_install()
3171 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_open()
3172 struct tty_port *port = &dlci->port; in gsmtty_open()
3173 struct gsm_mux *gsm = dlci->gsm; in gsmtty_open()
3175 port->count++; in gsmtty_open()
3178 dlci->modem_rx = 0; in gsmtty_open()
3179 /* We could in theory open and close before we wait - eg if we get in gsmtty_open()
3183 if (gsm->initiator) in gsmtty_open()
3193 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_close()
3197 if (dlci->state == DLCI_CLOSED) in gsmtty_close()
3199 mutex_lock(&dlci->mutex); in gsmtty_close()
3201 mutex_unlock(&dlci->mutex); in gsmtty_close()
3202 if (tty_port_close_start(&dlci->port, tty, filp) == 0) in gsmtty_close()
3205 if (tty_port_initialized(&dlci->port) && C_HUPCL(tty)) in gsmtty_close()
3206 tty_port_lower_dtr_rts(&dlci->port); in gsmtty_close()
3207 tty_port_close_end(&dlci->port, tty); in gsmtty_close()
3208 tty_port_tty_set(&dlci->port, NULL); in gsmtty_close()
3214 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_hangup()
3215 if (dlci->state == DLCI_CLOSED) in gsmtty_hangup()
3217 tty_port_hangup(&dlci->port); in gsmtty_hangup()
3225 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write()
3226 if (dlci->state == DLCI_CLOSED) in gsmtty_write()
3227 return -EINVAL; in gsmtty_write()
3229 sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock); in gsmtty_write()
3237 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_write_room()
3238 if (dlci->state == DLCI_CLOSED) in gsmtty_write_room()
3239 return -EINVAL; in gsmtty_write_room()
3240 return TX_SIZE - kfifo_len(&dlci->fifo); in gsmtty_write_room()
3245 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_chars_in_buffer()
3246 if (dlci->state == DLCI_CLOSED) in gsmtty_chars_in_buffer()
3247 return -EINVAL; in gsmtty_chars_in_buffer()
3248 return kfifo_len(&dlci->fifo); in gsmtty_chars_in_buffer()
3253 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_flush_buffer()
3256 if (dlci->state == DLCI_CLOSED) in gsmtty_flush_buffer()
3262 spin_lock_irqsave(&dlci->lock, flags); in gsmtty_flush_buffer()
3263 kfifo_reset(&dlci->fifo); in gsmtty_flush_buffer()
3264 spin_unlock_irqrestore(&dlci->lock, flags); in gsmtty_flush_buffer()
3277 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmget()
3278 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmget()
3279 return -EINVAL; in gsmtty_tiocmget()
3280 return dlci->modem_rx; in gsmtty_tiocmget()
3286 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_tiocmset()
3287 unsigned int modem_tx = dlci->modem_tx; in gsmtty_tiocmset()
3289 if (dlci->state == DLCI_CLOSED) in gsmtty_tiocmset()
3290 return -EINVAL; in gsmtty_tiocmset()
3294 if (modem_tx != dlci->modem_tx) { in gsmtty_tiocmset()
3295 dlci->modem_tx = modem_tx; in gsmtty_tiocmset()
3305 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_ioctl()
3309 if (dlci->state == DLCI_CLOSED) in gsmtty_ioctl()
3310 return -EINVAL; in gsmtty_ioctl()
3314 return -EFAULT; in gsmtty_ioctl()
3315 nc.if_name[IFNAMSIZ-1] = '\0'; in gsmtty_ioctl()
3317 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
3319 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
3321 return -EFAULT; in gsmtty_ioctl()
3325 return -EPERM; in gsmtty_ioctl()
3326 mutex_lock(&dlci->mutex); in gsmtty_ioctl()
3328 mutex_unlock(&dlci->mutex); in gsmtty_ioctl()
3331 return -ENOIOCTLCMD; in gsmtty_ioctl()
3337 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_set_termios()
3338 if (dlci->state == DLCI_CLOSED) in gsmtty_set_termios()
3345 tty_termios_copy_hw(&tty->termios, old); in gsmtty_set_termios()
3350 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_throttle()
3351 if (dlci->state == DLCI_CLOSED) in gsmtty_throttle()
3354 dlci->modem_tx &= ~TIOCM_RTS; in gsmtty_throttle()
3355 dlci->throttled = true; in gsmtty_throttle()
3362 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_unthrottle()
3363 if (dlci->state == DLCI_CLOSED) in gsmtty_unthrottle()
3366 dlci->modem_tx |= TIOCM_RTS; in gsmtty_unthrottle()
3367 dlci->throttled = false; in gsmtty_unthrottle()
3374 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_break_ctl()
3376 if (dlci->state == DLCI_CLOSED) in gsmtty_break_ctl()
3377 return -EINVAL; in gsmtty_break_ctl()
3379 if (state == -1) /* "On indefinitely" - we can't encode this in gsmtty_break_ctl()
3392 struct gsm_dlci *dlci = tty->driver_data; in gsmtty_cleanup()
3393 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup()
3396 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
3437 return -EINVAL; in gsm_init()
3439 gsm_tty_driver->driver_name = "gsmtty"; in gsm_init()
3440 gsm_tty_driver->name = "gsmtty"; in gsm_init()
3441 gsm_tty_driver->major = 0; /* Dynamic */ in gsm_init()
3442 gsm_tty_driver->minor_start = 0; in gsm_init()
3443 gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; in gsm_init()
3444 gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; in gsm_init()
3445 gsm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV in gsm_init()
3447 gsm_tty_driver->init_termios = tty_std_termios; in gsm_init()
3449 gsm_tty_driver->init_termios.c_lflag &= ~ECHO; in gsm_init()
3458 return -EBUSY; in gsm_init()
3461 gsm_tty_driver->major, gsm_tty_driver->minor_start); in gsm_init()