Lines Matching defs:dlci
87 struct gsm_dlci *dlci;
153 void (*data)(struct gsm_dlci *dlci, const u8 *data, int len);
154 void (*prev_data)(struct gsm_dlci *dlci, const u8 *data, int len);
235 struct gsm_dlci *dlci[NUM_DLCI];
445 * @dlci: DLCI to encode from
451 static u8 gsm_encode_modem(const struct gsm_dlci *dlci)
455 if (dlci->throttled)
457 if (dlci->modem_tx & TIOCM_DTR)
459 if (dlci->modem_tx & TIOCM_RTS)
461 if (dlci->modem_tx & TIOCM_RI)
463 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator)
784 static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci)
817 if (dlci) {
818 tty_port_tty_wakeup(&dlci->port);
823 if (gsm->dlci[i])
824 tty_port_tty_wakeup(&gsm->dlci[i]->port);
831 * @dlci: DLCI sending the data
839 static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
841 struct gsm_mux *gsm = dlci->gsm;
877 gsm_data_kick(gsm, dlci);
882 * @dlci: DLCI sending the data
887 * the gsm tx lock and dlci lock.
890 static void gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)
893 spin_lock_irqsave(&dlci->gsm->tx_lock, flags);
894 __gsm_data_queue(dlci, msg);
895 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags);
901 * @dlci: the DLCI to pull data from
910 static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci)
917 h = ((dlci->adaption == 1) ? 0 : 1);
919 len = kfifo_len(&dlci->fifo);
929 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
936 switch (dlci->adaption) {
942 *dp++ = (gsm_encode_modem(dlci) << 1) | EA;
946 dlci->adaption);
950 WARN_ON(len != kfifo_out_locked(&dlci->fifo, dp, len,
951 &dlci->lock));
954 tty_port_tty_wakeup(&dlci->port);
956 __gsm_data_queue(dlci, msg);
964 * @dlci: the DLCI to pull data from
974 struct gsm_dlci *dlci)
983 if (dlci->adaption == 4)
986 /* dlci->skb is locked by tx_lock */
987 if (dlci->skb == NULL) {
988 dlci->skb = skb_dequeue_tail(&dlci->skb_list);
989 if (dlci->skb == NULL)
993 len = dlci->skb->len + overhead;
997 if (dlci->adaption == 3) {
999 dev_kfree_skb_any(dlci->skb);
1000 dlci->skb = NULL;
1008 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype);
1013 skb_queue_tail(&dlci->skb_list, dlci->skb);
1014 dlci->skb = NULL;
1019 if (dlci->adaption == 4) { /* Interruptible framed (Packetised Data) */
1024 memcpy(dp, dlci->skb->data, len);
1025 skb_pull(dlci->skb, len);
1026 __gsm_data_queue(dlci, msg);
1028 dev_kfree_skb_any(dlci->skb);
1029 dlci->skb = NULL;
1054 struct gsm_dlci *dlci;
1058 dlci = gsm->dlci[i];
1059 if (dlci == NULL || dlci->constipated) {
1063 if (dlci->adaption < 3 && !dlci->net)
1064 len = gsm_dlci_data_output(gsm, dlci);
1066 len = gsm_dlci_data_output_framed(gsm, dlci);
1077 * @dlci: DLCI to kick
1084 static void gsm_dlci_data_kick(struct gsm_dlci *dlci)
1089 if (dlci->constipated)
1092 spin_lock_irqsave(&dlci->gsm->tx_lock, flags);
1094 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO);
1095 if (dlci->gsm->tx_bytes == 0) {
1096 if (dlci->net)
1097 gsm_dlci_data_output_framed(dlci->gsm, dlci);
1099 gsm_dlci_data_output(dlci->gsm, dlci);
1102 gsm_dlci_data_sweep(dlci->gsm);
1103 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags);
1131 gsm_data_queue(gsm->dlci[0], msg);
1137 * @dlci: DLCI to affect
1144 static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci,
1165 if (fc && !dlci->constipated) {
1167 dlci->constipated = true;
1168 } else if (!fc && dlci->constipated) {
1169 dlci->constipated = false;
1170 gsm_dlci_data_kick(dlci);
1185 if ((mlines & TIOCM_CD) == 0 && (dlci->modem_rx & TIOCM_CD))
1190 tty_insert_flip_char(&dlci->port, 0, TTY_BREAK);
1191 dlci->modem_rx = mlines;
1211 struct gsm_dlci *dlci;
1228 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL)
1230 dlci = gsm->dlci[addr];
1247 tty = tty_port_tty_get(&dlci->port);
1248 gsm_process_modem(tty, dlci, modem, clen);
1286 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL)
1293 port = &gsm->dlci[addr]->port;
1307 static void gsm_dlci_begin_close(struct gsm_dlci *dlci);
1329 struct gsm_dlci *dlci = gsm->dlci[0];
1331 if (dlci) {
1332 dlci->dead = true;
1334 gsm_dlci_begin_close(dlci);
1433 gsm_data_queue(gsm->dlci[0], msg);
1455 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) {
1503 if (gsm->dlci[0]->mode == DLCI_MODE_ADM)
1544 * @dlci: DLCI that closed
1550 static void gsm_dlci_close(struct gsm_dlci *dlci)
1554 del_timer(&dlci->t1);
1556 pr_debug("DLCI %d goes closed.\n", dlci->addr);
1557 dlci->state = DLCI_CLOSED;
1559 dlci->constipated = true;
1560 if (dlci->addr != 0) {
1561 tty_port_tty_hangup(&dlci->port, false);
1562 spin_lock_irqsave(&dlci->lock, flags);
1563 kfifo_reset(&dlci->fifo);
1564 spin_unlock_irqrestore(&dlci->lock, flags);
1566 tty_port_set_initialized(&dlci->port, 0);
1567 wake_up_interruptible(&dlci->port.open_wait);
1569 dlci->gsm->dead = true;
1570 wake_up(&dlci->gsm->event);
1577 * @dlci: DLCI that opened
1582 static void gsm_dlci_open(struct gsm_dlci *dlci)
1586 del_timer(&dlci->t1);
1588 dlci->state = DLCI_OPEN;
1589 dlci->constipated = false;
1591 pr_debug("DLCI %d goes open.\n", dlci->addr);
1592 wake_up(&dlci->gsm->event);
1605 * Some control dlci can stay in ADM mode with other dlci working just
1606 * fine. In that case we can just keep the control dlci open after the
1612 struct gsm_dlci *dlci = from_timer(dlci, t, t1);
1613 struct gsm_mux *gsm = dlci->gsm;
1615 switch (dlci->state) {
1617 if (dlci->retries) {
1618 dlci->retries--;
1619 gsm_command(dlci->gsm, dlci->addr, SABM|PF);
1620 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
1621 } else if (!dlci->addr && gsm->control == (DM | PF)) {
1624 dlci->addr);
1625 dlci->mode = DLCI_MODE_ADM;
1626 gsm_dlci_open(dlci);
1628 gsm_dlci_begin_close(dlci); /* prevent half open link */
1633 if (dlci->retries) {
1634 dlci->retries--;
1635 gsm_command(dlci->gsm, dlci->addr, DISC|PF);
1636 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
1638 gsm_dlci_close(dlci);
1641 pr_debug("%s: unhandled state: %d\n", __func__, dlci->state);
1648 * @dlci: DLCI to open
1656 static void gsm_dlci_begin_open(struct gsm_dlci *dlci)
1658 struct gsm_mux *gsm = dlci->gsm;
1659 if (dlci->state == DLCI_OPEN || dlci->state == DLCI_OPENING)
1661 dlci->retries = gsm->n2;
1662 dlci->state = DLCI_OPENING;
1663 gsm_command(dlci->gsm, dlci->addr, SABM|PF);
1664 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
1669 * @dlci: DLCI to open
1674 static void gsm_dlci_set_opening(struct gsm_dlci *dlci)
1676 switch (dlci->state) {
1679 dlci->state = DLCI_OPENING;
1688 * @dlci: DLCI to open
1697 static void gsm_dlci_begin_close(struct gsm_dlci *dlci)
1699 struct gsm_mux *gsm = dlci->gsm;
1700 if (dlci->state == DLCI_CLOSED || dlci->state == DLCI_CLOSING)
1702 dlci->retries = gsm->n2;
1703 dlci->state = DLCI_CLOSING;
1704 gsm_command(dlci->gsm, dlci->addr, DISC|PF);
1705 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
1710 * @dlci: channel
1719 static void gsm_dlci_data(struct gsm_dlci *dlci, const u8 *data, int clen)
1722 struct tty_port *port = &dlci->port;
1729 switch (dlci->adaption) {
1743 gsm_process_modem(tty, dlci, modem, clen);
1756 * @dlci: channel
1766 static void gsm_dlci_command(struct gsm_dlci *dlci, const u8 *data, int len)
1780 gsm_control_message(dlci->gsm, command,
1783 gsm_control_response(dlci->gsm, command,
1806 struct gsm_dlci *dlci = kzalloc(sizeof(struct gsm_dlci), GFP_ATOMIC);
1807 if (dlci == NULL)
1809 spin_lock_init(&dlci->lock);
1810 mutex_init(&dlci->mutex);
1811 if (kfifo_alloc(&dlci->fifo, 4096, GFP_KERNEL) < 0) {
1812 kfree(dlci);
1816 skb_queue_head_init(&dlci->skb_list);
1817 timer_setup(&dlci->t1, gsm_dlci_t1, 0);
1818 tty_port_init(&dlci->port);
1819 dlci->port.ops = &gsm_port_ops;
1820 dlci->gsm = gsm;
1821 dlci->addr = addr;
1822 dlci->adaption = gsm->adaption;
1823 dlci->state = DLCI_CLOSED;
1825 dlci->data = gsm_dlci_data;
1827 dlci->constipated = true;
1829 dlci->data = gsm_dlci_command;
1831 gsm->dlci[addr] = dlci;
1832 return dlci;
1845 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port);
1847 del_timer_sync(&dlci->t1);
1848 dlci->gsm->dlci[dlci->addr] = NULL;
1849 kfifo_free(&dlci->fifo);
1850 while ((dlci->skb = skb_dequeue(&dlci->skb_list)))
1851 dev_kfree_skb(dlci->skb);
1852 kfree(dlci);
1855 static inline void dlci_get(struct gsm_dlci *dlci)
1857 tty_port_get(&dlci->port);
1860 static inline void dlci_put(struct gsm_dlci *dlci)
1862 tty_port_put(&dlci->port);
1865 static void gsm_destroy_network(struct gsm_dlci *dlci);
1869 * @dlci: DLCI to destroy
1876 static void gsm_dlci_release(struct gsm_dlci *dlci)
1878 struct tty_struct *tty = tty_port_tty_get(&dlci->port);
1880 mutex_lock(&dlci->mutex);
1881 gsm_destroy_network(dlci);
1882 mutex_unlock(&dlci->mutex);
1891 tty_port_tty_set(&dlci->port, NULL);
1894 dlci->state = DLCI_CLOSED;
1895 dlci_put(dlci);
1914 struct gsm_dlci *dlci;
1944 dlci = gsm->dlci[address];
1950 if (dlci == NULL)
1951 dlci = gsm_dlci_alloc(gsm, address);
1952 if (dlci == NULL)
1954 if (dlci->dead)
1958 gsm_dlci_open(dlci);
1964 if (dlci == NULL || dlci->state == DLCI_CLOSED) {
1970 gsm_dlci_close(dlci);
1973 if (cr == 0 || dlci == NULL)
1975 switch (dlci->state) {
1977 gsm_dlci_close(dlci);
1980 gsm_dlci_open(dlci);
1984 dlci->state);
1992 if (dlci == NULL)
1994 gsm_dlci_close(dlci);
2004 if (dlci == NULL || dlci->state != DLCI_OPEN) {
2008 dlci->data(dlci, gsm->buf, gsm->len);
2225 struct gsm_dlci *dlci;
2231 dlci = gsm->dlci[0];
2232 if (dlci) {
2233 if (disc && dlci->state != DLCI_CLOSED) {
2234 gsm_dlci_begin_close(dlci);
2235 wait_event(gsm->event, dlci->state == DLCI_CLOSED);
2237 dlci->dead = true;
2249 if (gsm->dlci[i])
2250 gsm_dlci_release(gsm->dlci[i]);
2270 struct gsm_dlci *dlci;
2282 dlci = gsm_dlci_alloc(gsm, 0);
2283 if (dlci == NULL)
2513 gsm_dlci_begin_open(gsm->dlci[0]);
2848 static void dlci_net_free(struct gsm_dlci *dlci)
2850 if (!dlci->net) {
2854 dlci->adaption = dlci->prev_adaption;
2855 dlci->data = dlci->prev_data;
2856 free_netdev(dlci->net);
2857 dlci->net = NULL;
2862 struct gsm_dlci *dlci;
2865 dlci = mux_net->dlci;
2867 if (dlci->net) {
2868 unregister_netdev(dlci->net);
2869 dlci_net_free(dlci);
2887 struct gsm_dlci *dlci = mux_net->dlci;
2890 skb_queue_head(&dlci->skb_list, skb);
2893 gsm_dlci_data_kick(dlci);
2910 static void gsm_mux_rx_netchar(struct gsm_dlci *dlci,
2913 struct net_device *net = dlci->net;
2961 /* caller holds the dlci mutex */
2962 static void gsm_destroy_network(struct gsm_dlci *dlci)
2967 if (!dlci->net)
2969 mux_net = netdev_priv(dlci->net);
2974 /* caller holds the dlci mutex */
2975 static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc)
2986 if (dlci->adaption > 2)
3006 net->mtu = dlci->gsm->mtu;
3008 net->max_mtu = dlci->gsm->mtu;
3010 mux_net->dlci = dlci;
3014 /* reconfigure dlci for network */
3015 dlci->prev_adaption = dlci->adaption;
3016 dlci->prev_data = dlci->data;
3017 dlci->adaption = nc->adaption;
3018 dlci->data = gsm_mux_rx_netchar;
3019 dlci->net = net;
3025 dlci_net_free(dlci);
3053 static int gsmtty_modem_update(struct gsm_dlci *dlci, u8 brk)
3059 modembits[0] = (dlci->addr << 2) | 2 | EA; /* DLCI, Valid, EA */
3060 modembits[1] = (gsm_encode_modem(dlci) << 1) | EA;
3065 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len);
3068 return gsm_control_wait(dlci->gsm, ctrl);
3073 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port);
3074 struct gsm_mux *gsm = dlci->gsm;
3077 if (dlci->state != DLCI_OPEN)
3086 if (gsm->encoding == 0 && gsm->dlci[0]->mode == DLCI_MODE_ADM &&
3087 !dlci->modem_rx)
3090 return dlci->modem_rx & TIOCM_CD;
3095 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port);
3096 unsigned int modem_tx = dlci->modem_tx;
3101 if (modem_tx != dlci->modem_tx) {
3102 dlci->modem_tx = modem_tx;
3103 gsmtty_modem_update(dlci, 0);
3116 struct gsm_dlci *dlci;
3139 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) {
3143 dlci = gsm->dlci[line];
3144 if (dlci == NULL) {
3146 dlci = gsm_dlci_alloc(gsm, line);
3148 if (dlci == NULL) {
3152 ret = tty_port_install(&dlci->port, driver, tty);
3155 dlci_put(dlci);
3160 dlci_get(dlci);
3161 dlci_get(gsm->dlci[0]);
3163 tty->driver_data = dlci;
3171 struct gsm_dlci *dlci = tty->driver_data;
3172 struct tty_port *port = &dlci->port;
3173 struct gsm_mux *gsm = dlci->gsm;
3178 dlci->modem_rx = 0;
3184 gsm_dlci_begin_open(dlci);
3186 gsm_dlci_set_opening(dlci);
3193 struct gsm_dlci *dlci = tty->driver_data;
3195 if (dlci == NULL)
3197 if (dlci->state == DLCI_CLOSED)
3199 mutex_lock(&dlci->mutex);
3200 gsm_destroy_network(dlci);
3201 mutex_unlock(&dlci->mutex);
3202 if (tty_port_close_start(&dlci->port, tty, filp) == 0)
3204 gsm_dlci_begin_close(dlci);
3205 if (tty_port_initialized(&dlci->port) && C_HUPCL(tty))
3206 tty_port_lower_dtr_rts(&dlci->port);
3207 tty_port_close_end(&dlci->port, tty);
3208 tty_port_tty_set(&dlci->port, NULL);
3214 struct gsm_dlci *dlci = tty->driver_data;
3215 if (dlci->state == DLCI_CLOSED)
3217 tty_port_hangup(&dlci->port);
3218 gsm_dlci_begin_close(dlci);
3225 struct gsm_dlci *dlci = tty->driver_data;
3226 if (dlci->state == DLCI_CLOSED)
3229 sent = kfifo_in_locked(&dlci->fifo, buf, len, &dlci->lock);
3231 gsm_dlci_data_kick(dlci);
3237 struct gsm_dlci *dlci = tty->driver_data;
3238 if (dlci->state == DLCI_CLOSED)
3240 return TX_SIZE - kfifo_len(&dlci->fifo);
3245 struct gsm_dlci *dlci = tty->driver_data;
3246 if (dlci->state == DLCI_CLOSED)
3248 return kfifo_len(&dlci->fifo);
3253 struct gsm_dlci *dlci = tty->driver_data;
3256 if (dlci->state == DLCI_CLOSED)
3262 spin_lock_irqsave(&dlci->lock, flags);
3263 kfifo_reset(&dlci->fifo);
3264 spin_unlock_irqrestore(&dlci->lock, flags);
3277 struct gsm_dlci *dlci = tty->driver_data;
3278 if (dlci->state == DLCI_CLOSED)
3280 return dlci->modem_rx;
3286 struct gsm_dlci *dlci = tty->driver_data;
3287 unsigned int modem_tx = dlci->modem_tx;
3289 if (dlci->state == DLCI_CLOSED)
3294 if (modem_tx != dlci->modem_tx) {
3295 dlci->modem_tx = modem_tx;
3296 return gsmtty_modem_update(dlci, 0);
3305 struct gsm_dlci *dlci = tty->driver_data;
3309 if (dlci->state == DLCI_CLOSED)
3317 mutex_lock(&dlci->mutex);
3318 index = gsm_create_network(dlci, &nc);
3319 mutex_unlock(&dlci->mutex);
3326 mutex_lock(&dlci->mutex);
3327 gsm_destroy_network(dlci);
3328 mutex_unlock(&dlci->mutex);
3337 struct gsm_dlci *dlci = tty->driver_data;
3338 if (dlci->state == DLCI_CLOSED)
3350 struct gsm_dlci *dlci = tty->driver_data;
3351 if (dlci->state == DLCI_CLOSED)
3354 dlci->modem_tx &= ~TIOCM_RTS;
3355 dlci->throttled = true;
3357 gsmtty_modem_update(dlci, 0);
3362 struct gsm_dlci *dlci = tty->driver_data;
3363 if (dlci->state == DLCI_CLOSED)
3366 dlci->modem_tx |= TIOCM_RTS;
3367 dlci->throttled = false;
3369 gsmtty_modem_update(dlci, 0);
3374 struct gsm_dlci *dlci = tty->driver_data;
3376 if (dlci->state == DLCI_CLOSED)
3387 return gsmtty_modem_update(dlci, encode);
3392 struct gsm_dlci *dlci = tty->driver_data;
3393 struct gsm_mux *gsm = dlci->gsm;
3395 dlci_put(dlci);
3396 dlci_put(gsm->dlci[0]);