Lines Matching refs:gsm
127 struct gsm_mux *gsm; member
227 void (*receive)(struct gsm_mux *gsm, u8 ch);
369 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len);
461 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
580 static void gsm_send(struct gsm_mux *gsm, int addr, int cr, int control) in gsm_send() argument
586 switch (gsm->encoding) { in gsm_send()
614 gsmld_output(gsm, cbuf, len); in gsm_send()
627 static inline void gsm_response(struct gsm_mux *gsm, int addr, int control) in gsm_response() argument
629 gsm_send(gsm, addr, 0, control); in gsm_response()
641 static inline void gsm_command(struct gsm_mux *gsm, int addr, int control) in gsm_command() argument
643 gsm_send(gsm, addr, 1, control); in gsm_command()
662 static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len, in gsm_data_alloc() argument
720 static void gsm_data_kick(struct gsm_mux *gsm, struct gsm_dlci *dlci) in gsm_data_kick() argument
725 list_for_each_entry_safe(msg, nmsg, &gsm->tx_list, list) { in gsm_data_kick()
726 if (gsm->constipated && !gsm_is_flow_ctrl_msg(msg)) in gsm_data_kick()
728 if (gsm->encoding != 0) { in gsm_data_kick()
729 gsm->txframe[0] = GSM1_SOF; in gsm_data_kick()
731 gsm->txframe + 1, msg->len); in gsm_data_kick()
732 gsm->txframe[len + 1] = GSM1_SOF; in gsm_data_kick()
735 gsm->txframe[0] = GSM0_SOF; in gsm_data_kick()
736 memcpy(gsm->txframe + 1 , msg->data, msg->len); in gsm_data_kick()
737 gsm->txframe[msg->len + 1] = GSM0_SOF; in gsm_data_kick()
744 gsm->txframe, len); in gsm_data_kick()
745 if (gsmld_output(gsm, gsm->txframe, len) < 0) in gsm_data_kick()
748 gsm->tx_bytes -= msg->len; in gsm_data_kick()
759 if (gsm->dlci[i]) in gsm_data_kick()
760 tty_port_tty_wakeup(&gsm->dlci[i]->port); in gsm_data_kick()
777 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue() local
782 if (gsm->encoding == 0) { in __gsm_data_queue()
792 if (gsm->initiator) in __gsm_data_queue()
802 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
811 list_add_tail(&msg->list, &gsm->tx_list); in __gsm_data_queue()
812 gsm->tx_bytes += msg->len; in __gsm_data_queue()
813 gsm_data_kick(gsm, dlci); in __gsm_data_queue()
829 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
831 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_data_queue()
846 static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci) in gsm_dlci_data_output() argument
860 if ((len + h) > gsm->mtu) in gsm_dlci_data_output()
861 len = gsm->mtu - h; in gsm_dlci_data_output()
865 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_data_output()
909 static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, in gsm_dlci_data_output_framed() argument
932 if (len > gsm->mtu) { in gsm_dlci_data_output_framed()
939 len = gsm->mtu; in gsm_dlci_data_output_framed()
944 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_data_output_framed()
983 static void gsm_dlci_data_sweep(struct gsm_mux *gsm) in gsm_dlci_data_sweep() argument
992 if (gsm->tx_bytes > TX_THRESH_HI) in gsm_dlci_data_sweep()
994 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1000 len = gsm_dlci_data_output(gsm, dlci); in gsm_dlci_data_sweep()
1002 len = gsm_dlci_data_output_framed(gsm, dlci); in gsm_dlci_data_sweep()
1028 spin_lock_irqsave(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1030 sweep = (dlci->gsm->tx_bytes < TX_THRESH_LO); in gsm_dlci_data_kick()
1031 if (dlci->gsm->tx_bytes == 0) { in gsm_dlci_data_kick()
1033 gsm_dlci_data_output_framed(dlci->gsm, dlci); in gsm_dlci_data_kick()
1035 gsm_dlci_data_output(dlci->gsm, dlci); in gsm_dlci_data_kick()
1038 gsm_dlci_data_sweep(dlci->gsm); in gsm_dlci_data_kick()
1039 spin_unlock_irqrestore(&dlci->gsm->tx_lock, flags); in gsm_dlci_data_kick()
1057 static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, in gsm_control_reply() argument
1061 msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); in gsm_control_reply()
1067 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_reply()
1142 static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) in gsm_control_modem() argument
1164 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1166 dlci = gsm->dlci[addr]; in gsm_control_modem()
1189 gsm_control_reply(gsm, CMD_MSC, data, clen); in gsm_control_modem()
1203 static void gsm_control_rls(struct gsm_mux *gsm, const u8 *data, int clen) in gsm_control_rls() argument
1222 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_rls()
1229 port = &gsm->dlci[addr]->port; in gsm_control_rls()
1240 gsm_control_reply(gsm, CMD_RLS, data, clen); in gsm_control_rls()
1257 static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, in gsm_control_message() argument
1265 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1269 gsm->dead = true; in gsm_control_message()
1276 gsm_control_reply(gsm, CMD_TEST, data, clen); in gsm_control_message()
1280 gsm->constipated = false; in gsm_control_message()
1281 gsm_control_reply(gsm, CMD_FCON, NULL, 0); in gsm_control_message()
1283 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_control_message()
1284 gsm_data_kick(gsm, NULL); in gsm_control_message()
1285 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_control_message()
1289 gsm->constipated = true; in gsm_control_message()
1290 gsm_control_reply(gsm, CMD_FCOFF, NULL, 0); in gsm_control_message()
1294 gsm_control_modem(gsm, data, clen); in gsm_control_message()
1298 gsm_control_rls(gsm, data, clen); in gsm_control_message()
1302 gsm_control_reply(gsm, CMD_PSC, NULL, 0); in gsm_control_message()
1311 gsm_control_reply(gsm, CMD_NSC, buf, 1); in gsm_control_message()
1329 static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, in gsm_control_response() argument
1335 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1337 ctrl = gsm->pending_cmd; in gsm_control_response()
1342 del_timer(&gsm->t2_timer); in gsm_control_response()
1343 gsm->pending_cmd = NULL; in gsm_control_response()
1348 wake_up(&gsm->event); in gsm_control_response()
1350 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_response()
1361 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) in gsm_control_transmit() argument
1363 struct gsm_msg *msg = gsm_data_alloc(gsm, 0, ctrl->len + 2, gsm->ftype); in gsm_control_transmit()
1369 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_transmit()
1385 struct gsm_mux *gsm = from_timer(gsm, t, t2_timer); in gsm_control_retransmit() local
1388 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_retransmit()
1389 ctrl = gsm->pending_cmd; in gsm_control_retransmit()
1391 if (gsm->cretries == 0 || !gsm->dlci[0] || gsm->dlci[0]->dead) { in gsm_control_retransmit()
1392 gsm->pending_cmd = NULL; in gsm_control_retransmit()
1395 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
1396 wake_up(&gsm->event); in gsm_control_retransmit()
1399 gsm->cretries--; in gsm_control_retransmit()
1400 gsm_control_transmit(gsm, ctrl); in gsm_control_retransmit()
1401 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_retransmit()
1403 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_retransmit()
1418 static struct gsm_control *gsm_control_send(struct gsm_mux *gsm, in gsm_control_send() argument
1427 wait_event(gsm->event, gsm->pending_cmd == NULL); in gsm_control_send()
1428 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_send()
1429 if (gsm->pending_cmd != NULL) { in gsm_control_send()
1430 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
1436 gsm->pending_cmd = ctrl; in gsm_control_send()
1439 if (gsm->dlci[0]->mode == DLCI_MODE_ADM) in gsm_control_send()
1440 gsm->cretries = 0; in gsm_control_send()
1442 gsm->cretries = gsm->n2; in gsm_control_send()
1444 mod_timer(&gsm->t2_timer, jiffies + gsm->t2 * HZ / 100); in gsm_control_send()
1445 gsm_control_transmit(gsm, ctrl); in gsm_control_send()
1446 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
1460 static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control) in gsm_control_wait() argument
1463 wait_event(gsm->event, control->done == 1); in gsm_control_wait()
1505 dlci->gsm->dead = true; in gsm_dlci_close()
1506 wake_up(&dlci->gsm->event); in gsm_dlci_close()
1528 wake_up(&dlci->gsm->event); in gsm_dlci_open()
1549 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1() local
1555 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_t1()
1556 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
1557 } else if (!dlci->addr && gsm->control == (DM | PF)) { in gsm_dlci_t1()
1571 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_t1()
1572 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_t1()
1594 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_open() local
1597 dlci->retries = gsm->n2; in gsm_dlci_begin_open()
1599 gsm_command(dlci->gsm, dlci->addr, SABM|PF); in gsm_dlci_begin_open()
1600 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_open()
1635 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close() local
1638 dlci->retries = gsm->n2; in gsm_dlci_begin_close()
1640 gsm_command(dlci->gsm, dlci->addr, DISC|PF); in gsm_dlci_begin_close()
1641 mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100); in gsm_dlci_begin_close()
1716 gsm_control_message(dlci->gsm, command, in gsm_dlci_command()
1719 gsm_control_response(dlci->gsm, command, in gsm_dlci_command()
1740 static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr) in gsm_dlci_alloc() argument
1756 dlci->gsm = gsm; in gsm_dlci_alloc()
1758 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
1767 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
1784 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
1848 static void gsm_queue(struct gsm_mux *gsm) in gsm_queue() argument
1856 if ((gsm->control & ~PF) == UI) in gsm_queue()
1857 gsm->fcs = gsm_fcs_add_block(gsm->fcs, gsm->buf, gsm->len); in gsm_queue()
1858 if (gsm->encoding == 0) { in gsm_queue()
1863 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->received_fcs); in gsm_queue()
1865 if (gsm->fcs != GOOD_FCS) { in gsm_queue()
1866 gsm->bad_fcs++; in gsm_queue()
1868 pr_debug("BAD FCS %02x\n", gsm->fcs); in gsm_queue()
1871 address = gsm->address >> 1; in gsm_queue()
1875 cr = gsm->address & 1; /* C/R bit */ in gsm_queue()
1877 gsm_print_packet("<--", address, cr, gsm->control, gsm->buf, gsm->len); in gsm_queue()
1879 cr ^= 1 - gsm->initiator; /* Flip so 1 always means command */ in gsm_queue()
1880 dlci = gsm->dlci[address]; in gsm_queue()
1882 switch (gsm->control) { in gsm_queue()
1887 dlci = gsm_dlci_alloc(gsm, address); in gsm_queue()
1891 gsm_response(gsm, address, DM); in gsm_queue()
1893 gsm_response(gsm, address, UA); in gsm_queue()
1901 gsm_response(gsm, address, DM); in gsm_queue()
1905 gsm_response(gsm, address, UA); in gsm_queue()
1941 gsm_response(gsm, address, DM|PF); in gsm_queue()
1944 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
1951 gsm->malformed++; in gsm_queue()
1964 static void gsm0_receive(struct gsm_mux *gsm, unsigned char c) in gsm0_receive() argument
1968 switch (gsm->state) { in gsm0_receive()
1971 gsm->state = GSM_ADDRESS; in gsm0_receive()
1972 gsm->address = 0; in gsm0_receive()
1973 gsm->len = 0; in gsm0_receive()
1974 gsm->fcs = INIT_FCS; in gsm0_receive()
1978 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
1979 if (gsm_read_ea(&gsm->address, c)) in gsm0_receive()
1980 gsm->state = GSM_CONTROL; in gsm0_receive()
1983 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
1984 gsm->control = c; in gsm0_receive()
1985 gsm->state = GSM_LEN0; in gsm0_receive()
1988 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
1989 if (gsm_read_ea(&gsm->len, c)) { in gsm0_receive()
1990 if (gsm->len > gsm->mru) { in gsm0_receive()
1991 gsm->bad_size++; in gsm0_receive()
1992 gsm->state = GSM_SEARCH; in gsm0_receive()
1995 gsm->count = 0; in gsm0_receive()
1996 if (!gsm->len) in gsm0_receive()
1997 gsm->state = GSM_FCS; in gsm0_receive()
1999 gsm->state = GSM_DATA; in gsm0_receive()
2002 gsm->state = GSM_LEN1; in gsm0_receive()
2005 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2007 gsm->len |= len << 7; in gsm0_receive()
2008 if (gsm->len > gsm->mru) { in gsm0_receive()
2009 gsm->bad_size++; in gsm0_receive()
2010 gsm->state = GSM_SEARCH; in gsm0_receive()
2013 gsm->count = 0; in gsm0_receive()
2014 if (!gsm->len) in gsm0_receive()
2015 gsm->state = GSM_FCS; in gsm0_receive()
2017 gsm->state = GSM_DATA; in gsm0_receive()
2020 gsm->buf[gsm->count++] = c; in gsm0_receive()
2021 if (gsm->count == gsm->len) in gsm0_receive()
2022 gsm->state = GSM_FCS; in gsm0_receive()
2025 gsm->received_fcs = c; in gsm0_receive()
2026 gsm_queue(gsm); in gsm0_receive()
2027 gsm->state = GSM_SSOF; in gsm0_receive()
2031 gsm->state = GSM_SEARCH; in gsm0_receive()
2036 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2049 static void gsm1_receive(struct gsm_mux *gsm, unsigned char c) in gsm1_receive() argument
2053 gsm->constipated = true; in gsm1_receive()
2056 gsm->constipated = false; in gsm1_receive()
2058 gsm_data_kick(gsm, NULL); in gsm1_receive()
2064 if (gsm->state == GSM_DATA && gsm->count) { in gsm1_receive()
2066 gsm->count--; in gsm1_receive()
2067 gsm->fcs = gsm_fcs_add(gsm->fcs, gsm->buf[gsm->count]); in gsm1_receive()
2068 gsm->len = gsm->count; in gsm1_receive()
2069 gsm_queue(gsm); in gsm1_receive()
2070 gsm->state = GSM_START; in gsm1_receive()
2074 if (gsm->state != GSM_START) { in gsm1_receive()
2075 if (gsm->state != GSM_SEARCH) in gsm1_receive()
2076 gsm->malformed++; in gsm1_receive()
2077 gsm->state = GSM_START; in gsm1_receive()
2085 gsm->escape = true; in gsm1_receive()
2090 if (gsm->state == GSM_SEARCH) in gsm1_receive()
2093 if (gsm->escape) { in gsm1_receive()
2095 gsm->escape = false; in gsm1_receive()
2097 switch (gsm->state) { in gsm1_receive()
2099 gsm->address = 0; in gsm1_receive()
2100 gsm->state = GSM_ADDRESS; in gsm1_receive()
2101 gsm->fcs = INIT_FCS; in gsm1_receive()
2104 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
2105 if (gsm_read_ea(&gsm->address, c)) in gsm1_receive()
2106 gsm->state = GSM_CONTROL; in gsm1_receive()
2109 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm1_receive()
2110 gsm->control = c; in gsm1_receive()
2111 gsm->count = 0; in gsm1_receive()
2112 gsm->state = GSM_DATA; in gsm1_receive()
2115 if (gsm->count > gsm->mru) { /* Allow one for the FCS */ in gsm1_receive()
2116 gsm->state = GSM_OVERRUN; in gsm1_receive()
2117 gsm->bad_size++; in gsm1_receive()
2119 gsm->buf[gsm->count++] = c; in gsm1_receive()
2124 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
2141 static void gsm_error(struct gsm_mux *gsm, in gsm_error() argument
2144 gsm->state = GSM_SEARCH; in gsm_error()
2145 gsm->io_error++; in gsm_error()
2158 static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) in gsm_cleanup_mux() argument
2161 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_cleanup_mux()
2164 gsm->dead = true; in gsm_cleanup_mux()
2165 mutex_lock(&gsm->mutex); in gsm_cleanup_mux()
2170 wait_event(gsm->event, dlci->state == DLCI_CLOSED); in gsm_cleanup_mux()
2176 del_timer_sync(&gsm->t2_timer); in gsm_cleanup_mux()
2180 if (gsm->dlci[i]) in gsm_cleanup_mux()
2181 gsm_dlci_release(gsm->dlci[i]); in gsm_cleanup_mux()
2182 mutex_unlock(&gsm->mutex); in gsm_cleanup_mux()
2184 tty_ldisc_flush(gsm->tty); in gsm_cleanup_mux()
2185 list_for_each_entry_safe(txq, ntxq, &gsm->tx_list, list) in gsm_cleanup_mux()
2187 INIT_LIST_HEAD(&gsm->tx_list); in gsm_cleanup_mux()
2199 static int gsm_activate_mux(struct gsm_mux *gsm) in gsm_activate_mux() argument
2203 if (gsm->encoding == 0) in gsm_activate_mux()
2204 gsm->receive = gsm0_receive; in gsm_activate_mux()
2206 gsm->receive = gsm1_receive; in gsm_activate_mux()
2208 dlci = gsm_dlci_alloc(gsm, 0); in gsm_activate_mux()
2211 gsm->dead = false; /* Tty opens are now permissible */ in gsm_activate_mux()
2221 static void gsm_free_mux(struct gsm_mux *gsm) in gsm_free_mux() argument
2226 if (gsm == gsm_mux[i]) { in gsm_free_mux()
2231 mutex_destroy(&gsm->mutex); in gsm_free_mux()
2232 kfree(gsm->txframe); in gsm_free_mux()
2233 kfree(gsm->buf); in gsm_free_mux()
2234 kfree(gsm); in gsm_free_mux()
2245 struct gsm_mux *gsm = container_of(ref, struct gsm_mux, ref); in gsm_free_muxr() local
2246 gsm_free_mux(gsm); in gsm_free_muxr()
2249 static inline void mux_get(struct gsm_mux *gsm) in mux_get() argument
2254 kref_get(&gsm->ref); in mux_get()
2258 static inline void mux_put(struct gsm_mux *gsm) in mux_put() argument
2263 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
2267 static inline unsigned int mux_num_to_base(struct gsm_mux *gsm) in mux_num_to_base() argument
2269 return gsm->num * NUM_DLCI; in mux_num_to_base()
2286 struct gsm_mux *gsm = kzalloc(sizeof(struct gsm_mux), GFP_KERNEL); in gsm_alloc_mux() local
2287 if (gsm == NULL) in gsm_alloc_mux()
2289 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
2290 if (gsm->buf == NULL) { in gsm_alloc_mux()
2291 kfree(gsm); in gsm_alloc_mux()
2294 gsm->txframe = kmalloc(2 * (MAX_MTU + PROT_OVERHEAD - 1), GFP_KERNEL); in gsm_alloc_mux()
2295 if (gsm->txframe == NULL) { in gsm_alloc_mux()
2296 kfree(gsm->buf); in gsm_alloc_mux()
2297 kfree(gsm); in gsm_alloc_mux()
2300 spin_lock_init(&gsm->lock); in gsm_alloc_mux()
2301 mutex_init(&gsm->mutex); in gsm_alloc_mux()
2302 kref_init(&gsm->ref); in gsm_alloc_mux()
2303 INIT_LIST_HEAD(&gsm->tx_list); in gsm_alloc_mux()
2304 timer_setup(&gsm->t2_timer, gsm_control_retransmit, 0); in gsm_alloc_mux()
2305 init_waitqueue_head(&gsm->event); in gsm_alloc_mux()
2306 spin_lock_init(&gsm->control_lock); in gsm_alloc_mux()
2307 spin_lock_init(&gsm->tx_lock); in gsm_alloc_mux()
2309 gsm->t1 = T1; in gsm_alloc_mux()
2310 gsm->t2 = T2; in gsm_alloc_mux()
2311 gsm->n2 = N2; in gsm_alloc_mux()
2312 gsm->ftype = UIH; in gsm_alloc_mux()
2313 gsm->adaption = 1; in gsm_alloc_mux()
2314 gsm->encoding = 1; in gsm_alloc_mux()
2315 gsm->mru = 64; /* Default to encoding 1 so these should be 64 */ in gsm_alloc_mux()
2316 gsm->mtu = 64; in gsm_alloc_mux()
2317 gsm->dead = true; /* Avoid early tty opens */ in gsm_alloc_mux()
2325 gsm_mux[i] = gsm; in gsm_alloc_mux()
2326 gsm->num = i; in gsm_alloc_mux()
2332 mutex_destroy(&gsm->mutex); in gsm_alloc_mux()
2333 kfree(gsm->txframe); in gsm_alloc_mux()
2334 kfree(gsm->buf); in gsm_alloc_mux()
2335 kfree(gsm); in gsm_alloc_mux()
2339 return gsm; in gsm_alloc_mux()
2342 static void gsm_copy_config_values(struct gsm_mux *gsm, in gsm_copy_config_values() argument
2346 c->adaption = gsm->adaption; in gsm_copy_config_values()
2347 c->encapsulation = gsm->encoding; in gsm_copy_config_values()
2348 c->initiator = gsm->initiator; in gsm_copy_config_values()
2349 c->t1 = gsm->t1; in gsm_copy_config_values()
2350 c->t2 = gsm->t2; in gsm_copy_config_values()
2352 c->n2 = gsm->n2; in gsm_copy_config_values()
2353 if (gsm->ftype == UIH) in gsm_copy_config_values()
2357 pr_debug("Ftype %d i %d\n", gsm->ftype, c->i); in gsm_copy_config_values()
2358 c->mru = gsm->mru; in gsm_copy_config_values()
2359 c->mtu = gsm->mtu; in gsm_copy_config_values()
2363 static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) in gsm_config() argument
2388 if (c->t1 != 0 && c->t1 != gsm->t1) in gsm_config()
2390 if (c->t2 != 0 && c->t2 != gsm->t2) in gsm_config()
2392 if (c->encapsulation != gsm->encoding) in gsm_config()
2394 if (c->adaption != gsm->adaption) in gsm_config()
2397 if (c->initiator != gsm->initiator) in gsm_config()
2399 if (c->mru != gsm->mru) in gsm_config()
2401 if (c->mtu != gsm->mtu) in gsm_config()
2410 gsm_cleanup_mux(gsm, true); in gsm_config()
2412 gsm->initiator = c->initiator; in gsm_config()
2413 gsm->mru = c->mru; in gsm_config()
2414 gsm->mtu = c->mtu; in gsm_config()
2415 gsm->encoding = c->encapsulation; in gsm_config()
2416 gsm->adaption = c->adaption; in gsm_config()
2417 gsm->n2 = c->n2; in gsm_config()
2420 gsm->ftype = UIH; in gsm_config()
2422 gsm->ftype = UI; in gsm_config()
2425 gsm->t1 = c->t1; in gsm_config()
2427 gsm->t2 = c->t2; in gsm_config()
2433 if (gsm->dead) { in gsm_config()
2434 ret = gsm_activate_mux(gsm); in gsm_config()
2437 if (gsm->initiator) in gsm_config()
2438 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
2453 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len) in gsmld_output() argument
2455 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
2456 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
2462 gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
2476 static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) in gsmld_attach_gsm() argument
2481 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
2483 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
2485 ret = gsm_activate_mux(gsm); in gsmld_attach_gsm()
2487 tty_kref_put(gsm->tty); in gsmld_attach_gsm()
2491 base = mux_num_to_base(gsm); /* Base for this MUX */ in gsmld_attach_gsm()
2517 static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) in gsmld_detach_gsm() argument
2519 unsigned int base = mux_num_to_base(gsm); /* Base for this MUX */ in gsmld_detach_gsm()
2522 WARN_ON(tty != gsm->tty); in gsmld_detach_gsm()
2526 gsm->tty->termios.c_iflag = gsm->old_c_iflag; in gsmld_detach_gsm()
2527 tty_kref_put(gsm->tty); in gsmld_detach_gsm()
2528 gsm->tty = NULL; in gsmld_detach_gsm()
2534 struct gsm_mux *gsm = tty->disc_data; in gsmld_receive_buf() local
2549 gsm->receive(gsm, *dp); in gsmld_receive_buf()
2555 gsm_error(gsm, *dp, flags); in gsmld_receive_buf()
2592 struct gsm_mux *gsm = tty->disc_data; in gsmld_close() local
2598 gsm_cleanup_mux(gsm, false); in gsmld_close()
2600 gsmld_detach_gsm(tty, gsm); in gsmld_close()
2604 mux_put(gsm); in gsmld_close()
2619 struct gsm_mux *gsm; in gsmld_open() local
2626 gsm = gsm_alloc_mux(); in gsmld_open()
2627 if (gsm == NULL) in gsmld_open()
2630 tty->disc_data = gsm; in gsmld_open()
2634 gsm->encoding = 1; in gsmld_open()
2636 ret = gsmld_attach_gsm(tty, gsm); in gsmld_open()
2638 gsm_cleanup_mux(gsm, false); in gsmld_open()
2639 mux_put(gsm); in gsmld_open()
2655 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup() local
2660 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_wakeup()
2661 gsm_data_kick(gsm, NULL); in gsmld_write_wakeup()
2662 if (gsm->tx_bytes < TX_THRESH_LO) { in gsmld_write_wakeup()
2663 gsm_dlci_data_sweep(gsm); in gsmld_write_wakeup()
2665 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write_wakeup()
2707 struct gsm_mux *gsm = tty->disc_data; in gsmld_write() local
2712 if (!gsm) in gsmld_write()
2716 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
2722 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
2745 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll() local
2750 if (gsm->dead) in gsmld_poll()
2765 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl() local
2770 gsm_copy_config_values(gsm, &c); in gsmld_ioctl()
2777 return gsm_config(gsm, &c); in gsmld_ioctl()
2779 base = mux_num_to_base(gsm); in gsmld_ioctl()
2962 net->mtu = dlci->gsm->mtu; in gsm_create_network()
2964 net->max_mtu = dlci->gsm->mtu; in gsm_create_network()
3021 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsmtty_modem_update()
3024 return gsm_control_wait(dlci->gsm, ctrl); in gsmtty_modem_update()
3030 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised() local
3042 if (gsm->encoding == 0 && gsm->dlci[0]->mode == DLCI_MODE_ADM && in gsm_carrier_raised()
3071 struct gsm_mux *gsm; in gsmtty_install() local
3087 gsm = gsm_mux[mux]; in gsmtty_install()
3088 if (gsm->dead) in gsmtty_install()
3094 mutex_lock(&gsm->mutex); in gsmtty_install()
3095 if (gsm->dlci[0] && gsm->dlci[0]->state != DLCI_OPEN) { in gsmtty_install()
3096 mutex_unlock(&gsm->mutex); in gsmtty_install()
3099 dlci = gsm->dlci[line]; in gsmtty_install()
3102 dlci = gsm_dlci_alloc(gsm, line); in gsmtty_install()
3105 mutex_unlock(&gsm->mutex); in gsmtty_install()
3112 mutex_unlock(&gsm->mutex); in gsmtty_install()
3117 dlci_get(gsm->dlci[0]); in gsmtty_install()
3118 mux_get(gsm); in gsmtty_install()
3120 mutex_unlock(&gsm->mutex); in gsmtty_install()
3129 struct gsm_mux *gsm = dlci->gsm; in gsmtty_open() local
3139 if (gsm->initiator) in gsmtty_open()
3349 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup() local
3352 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
3353 mux_put(gsm); in gsmtty_cleanup()