Lines Matching refs:gsm
144 struct gsm_mux *gsm; member
255 void (*receive)(struct gsm_mux *gsm, u8 ch);
400 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len);
402 static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,
404 static int gsm_send_packet(struct gsm_mux *gsm, struct gsm_msg *msg);
405 static void gsmld_write_trigger(struct gsm_mux *gsm);
498 if (dlci->modem_tx & TIOCM_CD || dlci->gsm->initiator) in gsm_encode_modem()
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()
710 ocr = cr ^ (gsm->initiator ? 0 : 1); in gsm_send()
717 if (gsm->encoding == GSM_BASIC_OPT) 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()
729 gsmld_write_trigger(gsm); in gsm_send()
741 static void gsm_dlci_clear_queues(struct gsm_mux *gsm, struct gsm_dlci *dlci) in gsm_dlci_clear_queues() argument
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()
757 gsm->tx_bytes -= msg->len; in gsm_dlci_clear_queues()
761 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_dlci_clear_queues()
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()
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()
808 static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len, in gsm_data_alloc() argument
831 static int gsm_send_packet(struct gsm_mux *gsm, struct gsm_msg *msg) in gsm_send_packet() argument
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()
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()
853 ret = gsmld_output(gsm, gsm->txframe, len); in gsm_send_packet()
857 gsm->tx_bytes -= msg->len; in gsm_send_packet()
903 static int gsm_data_kick(struct gsm_mux *gsm) in gsm_data_kick() argument
909 clear_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); 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()
915 ret = gsm_send_packet(gsm, msg); in gsm_data_kick()
921 gsm->tx_bytes -= msg->len; in gsm_data_kick()
934 if (gsm->constipated) 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()
944 gsm->tx_bytes -= msg->len; in gsm_data_kick()
949 ret = gsm_send_packet(gsm, msg); in gsm_data_kick()
955 gsm->tx_bytes -= msg->len; in gsm_data_kick()
983 struct gsm_mux *gsm = dlci->gsm; in __gsm_data_queue() local
988 if (gsm->encoding == GSM_BASIC_OPT) { in __gsm_data_queue()
998 if (gsm->initiator) in __gsm_data_queue()
1008 gsm_print_packet("Q> ", msg->addr, gsm->initiator, msg->ctrl, in __gsm_data_queue()
1021 list_add_tail(&msg->list, &gsm->tx_data_list); in __gsm_data_queue()
1026 list_add_tail(&msg->list, &gsm->tx_ctrl_list); in __gsm_data_queue()
1029 gsm->tx_bytes += msg->len; in __gsm_data_queue()
1031 gsmld_write_trigger(gsm); in __gsm_data_queue()
1032 mod_timer(&gsm->kick_timer, jiffies + 10 * gsm->t1 * HZ / 100); in __gsm_data_queue()
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()
1065 static int gsm_dlci_data_output(struct gsm_mux *gsm, struct gsm_dlci *dlci) in gsm_dlci_data_output() argument
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()
1125 static int gsm_dlci_data_output_framed(struct gsm_mux *gsm, in gsm_dlci_data_output_framed() argument
1148 if (len > gsm->mtu) { 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()
1195 static int gsm_dlci_modem_output(struct gsm_mux *gsm, struct gsm_dlci *dlci, in gsm_dlci_modem_output() argument
1217 msg = gsm_data_alloc(gsm, dlci->addr, size, gsm->ftype); in gsm_dlci_modem_output()
1256 static int gsm_dlci_data_sweep(struct gsm_mux *gsm) in gsm_dlci_data_sweep() argument
1263 while (gsm->tx_bytes < TX_THRESH_HI) { in gsm_dlci_data_sweep()
1265 dlci = gsm->dlci[i]; in gsm_dlci_data_sweep()
1274 len = gsm_dlci_data_output(gsm, dlci); in gsm_dlci_data_sweep()
1276 len = gsm_dlci_data_output_framed(gsm, dlci); in gsm_dlci_data_sweep()
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()
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()
1340 static int gsm_control_command(struct gsm_mux *gsm, int cmd, const u8 *data, in gsm_control_command() argument
1343 struct gsm_msg *msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); in gsm_control_command()
1351 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_command()
1366 static void gsm_control_reply(struct gsm_mux *gsm, int cmd, const u8 *data, in gsm_control_reply() argument
1370 msg = gsm_data_alloc(gsm, 0, dlen + 2, gsm->ftype); in gsm_control_reply()
1376 gsm_data_queue(gsm->dlci[0], msg); in gsm_control_reply()
1452 static void gsm_control_modem(struct gsm_mux *gsm, const u8 *data, int clen) in gsm_control_modem() argument
1468 if (addr == 0 || addr >= NUM_DLCI || gsm->dlci[addr] == NULL) in gsm_control_modem()
1470 dlci = gsm->dlci[addr]; in gsm_control_modem()
1490 gsm_control_reply(gsm, CMD_MSC, data, clen); in gsm_control_modem()
1504 static void gsm_control_rls(struct gsm_mux *gsm, const u8 *data, int clen) in gsm_control_rls() argument
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()
1541 gsm_control_reply(gsm, CMD_RLS, data, clen); in gsm_control_rls()
1558 static void gsm_control_message(struct gsm_mux *gsm, unsigned int command, in gsm_control_message() argument
1565 struct gsm_dlci *dlci = gsm->dlci[0]; in gsm_control_message()
1569 gsm->dead = true; in gsm_control_message()
1576 gsm_control_reply(gsm, CMD_TEST, data, clen); in gsm_control_message()
1580 gsm->constipated = false; in gsm_control_message()
1581 gsm_control_reply(gsm, CMD_FCON, NULL, 0); in gsm_control_message()
1583 gsmld_write_trigger(gsm); in gsm_control_message()
1587 gsm->constipated = true; in gsm_control_message()
1588 gsm_control_reply(gsm, CMD_FCOFF, NULL, 0); in gsm_control_message()
1592 gsm_control_modem(gsm, data, clen); in gsm_control_message()
1596 gsm_control_rls(gsm, data, clen); in gsm_control_message()
1600 gsm_control_reply(gsm, CMD_PSC, NULL, 0); in gsm_control_message()
1609 gsm_control_reply(gsm, CMD_NSC, buf, 1); in gsm_control_message()
1627 static void gsm_control_response(struct gsm_mux *gsm, unsigned int command, in gsm_control_response() argument
1633 spin_lock_irqsave(&gsm->control_lock, flags); in gsm_control_response()
1635 ctrl = gsm->pending_cmd; in gsm_control_response()
1640 del_timer(&gsm->t2_timer); in gsm_control_response()
1641 gsm->pending_cmd = NULL; 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()
1659 static void gsm_control_transmit(struct gsm_mux *gsm, struct gsm_control *ctrl) in gsm_control_transmit() argument
1661 gsm_control_command(gsm, ctrl->cmd, ctrl->data, ctrl->len); in gsm_control_transmit()
1677 struct gsm_mux *gsm = from_timer(gsm, t, t2_timer); in gsm_control_retransmit() local
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()
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()
1692 gsm_control_transmit(gsm, ctrl); 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()
1710 static struct gsm_control *gsm_control_send(struct gsm_mux *gsm, in gsm_control_send() argument
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()
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()
1737 gsm_control_transmit(gsm, ctrl); in gsm_control_send()
1738 spin_unlock_irqrestore(&gsm->control_lock, flags); in gsm_control_send()
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()
1788 gsm_dlci_clear_queues(dlci->gsm, dlci); in gsm_dlci_close()
1793 dlci->gsm->dead = true; in gsm_dlci_close()
1797 wake_up(&dlci->gsm->event); in gsm_dlci_close()
1821 wake_up(&dlci->gsm->event); in gsm_dlci_open()
1842 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_t1() local
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()
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()
1887 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_open() local
1890 dlci->retries = gsm->n2; 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()
1928 struct gsm_mux *gsm = dlci->gsm; in gsm_dlci_begin_close() local
1931 dlci->retries = gsm->n2; 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()
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()
2034 struct gsm_mux *gsm = from_timer(gsm, t, kick_timer); in gsm_kick_timer() local
2038 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_kick_timer()
2040 if (gsm->tx_bytes < TX_THRESH_LO) in gsm_kick_timer()
2041 sent = gsm_dlci_data_sweep(gsm); in gsm_kick_timer()
2042 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_kick_timer()
2062 static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr) in gsm_dlci_alloc() argument
2078 dlci->gsm = gsm; in gsm_dlci_alloc()
2080 dlci->adaption = gsm->adaption; in gsm_dlci_alloc()
2089 gsm->dlci[addr] = dlci; in gsm_dlci_alloc()
2106 dlci->gsm->dlci[dlci->addr] = NULL; in gsm_dlci_free()
2170 static void gsm_queue(struct gsm_mux *gsm) in gsm_queue() argument
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()
2198 dlci = gsm_dlci_alloc(gsm, address); in gsm_queue()
2202 gsm_response(gsm, address, DM|PF); in gsm_queue()
2204 gsm_response(gsm, address, UA|PF); in gsm_queue()
2212 gsm_response(gsm, address, DM|PF); in gsm_queue()
2216 gsm_response(gsm, address, UA|PF); in gsm_queue()
2248 gsm_response(gsm, address, DM|PF); in gsm_queue()
2251 dlci->data(dlci, gsm->buf, gsm->len); in gsm_queue()
2258 gsm->malformed++; in gsm_queue()
2271 static void gsm0_receive(struct gsm_mux *gsm, unsigned char c) in gsm0_receive() argument
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()
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()
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()
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()
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()
2309 gsm->state = GSM_LEN1; 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()
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()
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()
2338 gsm->fcs = gsm_fcs_add(gsm->fcs, c); in gsm0_receive()
2339 gsm->state = GSM_SSOF; in gsm0_receive()
2342 gsm->state = GSM_SEARCH; in gsm0_receive()
2344 gsm_queue(gsm); in gsm0_receive()
2346 gsm->bad_size++; in gsm0_receive()
2349 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm0_receive()
2362 static void gsm1_receive(struct gsm_mux *gsm, unsigned char c) in gsm1_receive() argument
2366 gsm->constipated = true; in gsm1_receive()
2369 gsm->constipated = false; in gsm1_receive()
2371 gsmld_write_trigger(gsm); 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()
2395 gsm_queue(gsm); 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()
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()
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()
2450 pr_debug("%s: unhandled state: %d\n", __func__, gsm->state); in gsm1_receive()
2465 static void gsm_error(struct gsm_mux *gsm) in gsm_error() argument
2467 gsm->state = GSM_SEARCH; in gsm_error()
2468 gsm->io_error++; in gsm_error()
2481 static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc) in gsm_cleanup_mux() argument
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()
2493 wait_event(gsm->event, dlci->state == DLCI_CLOSED); 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()
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()
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()
2533 static int gsm_activate_mux(struct gsm_mux *gsm) in gsm_activate_mux() argument
2538 dlci = gsm_dlci_alloc(gsm, 0); 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()
2562 static void gsm_free_mux(struct gsm_mux *gsm) in gsm_free_mux() argument
2567 if (gsm == gsm_mux[i]) { 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()
2575 kfree(gsm); in gsm_free_mux()
2586 struct gsm_mux *gsm = container_of(ref, struct gsm_mux, ref); in gsm_free_muxr() local
2587 gsm_free_mux(gsm); in gsm_free_muxr()
2590 static inline void mux_get(struct gsm_mux *gsm) in mux_get() argument
2595 kref_get(&gsm->ref); in mux_get()
2599 static inline void mux_put(struct gsm_mux *gsm) in mux_put() argument
2604 kref_put(&gsm->ref, gsm_free_muxr); in mux_put()
2608 static inline unsigned int mux_num_to_base(struct gsm_mux *gsm) in mux_num_to_base() argument
2610 return gsm->num * NUM_DLCI; in mux_num_to_base()
2627 struct gsm_mux *gsm = kzalloc(sizeof(struct gsm_mux), GFP_KERNEL); in gsm_alloc_mux() local
2628 if (gsm == NULL) in gsm_alloc_mux()
2630 gsm->buf = kmalloc(MAX_MRU + 1, GFP_KERNEL); in gsm_alloc_mux()
2631 if (gsm->buf == NULL) { in gsm_alloc_mux()
2632 kfree(gsm); 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()
2638 kfree(gsm); 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()
2669 gsm_mux[i] = gsm; in gsm_alloc_mux()
2670 gsm->num = i; 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()
2679 kfree(gsm); in gsm_alloc_mux()
2683 return gsm; in gsm_alloc_mux()
2686 static void gsm_copy_config_values(struct gsm_mux *gsm, in gsm_copy_config_values() argument
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()
2696 c->n2 = gsm->n2; in gsm_copy_config_values()
2697 if (gsm->ftype == UIH) 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()
2707 static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) in gsm_config() argument
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()
2754 gsm_cleanup_mux(gsm, true); 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()
2764 gsm->ftype = UIH; in gsm_config()
2766 gsm->ftype = UI; in gsm_config()
2769 gsm->t1 = c->t1; in gsm_config()
2771 gsm->t2 = c->t2; in gsm_config()
2777 if (gsm->dead) { in gsm_config()
2778 ret = gsm_activate_mux(gsm); in gsm_config()
2781 if (gsm->initiator) in gsm_config()
2782 gsm_dlci_begin_open(gsm->dlci[0]); in gsm_config()
2797 static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len) in gsmld_output() argument
2799 if (tty_write_room(gsm->tty) < len) { in gsmld_output()
2800 set_bit(TTY_DO_WRITE_WAKEUP, &gsm->tty->flags); in gsmld_output()
2805 return gsm->tty->ops->write(gsm->tty, data, len); in gsmld_output()
2813 static void gsmld_write_trigger(struct gsm_mux *gsm) in gsmld_write_trigger() argument
2815 if (!gsm || !gsm->dlci[0] || gsm->dlci[0]->dead) in gsmld_write_trigger()
2817 schedule_work(&gsm->tx_work); in gsmld_write_trigger()
2830 struct gsm_mux *gsm = container_of(work, struct gsm_mux, tx_work); in gsmld_write_task() local
2838 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write_task()
2839 if (gsm->tty) in gsmld_write_task()
2840 ret = gsm_data_kick(gsm); 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()
2859 static void gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) in gsmld_attach_gsm() argument
2861 gsm->tty = tty_kref_get(tty); in gsmld_attach_gsm()
2863 gsm->old_c_iflag = tty->termios.c_iflag; in gsmld_attach_gsm()
2875 static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) in gsmld_detach_gsm() argument
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() local
2898 if (gsm->receive) in gsmld_receive_buf()
2899 gsm->receive(gsm, *cp); in gsmld_receive_buf()
2905 gsm_error(gsm); in gsmld_receive_buf()
2942 struct gsm_mux *gsm = tty->disc_data; in gsmld_close() local
2948 gsm_cleanup_mux(gsm, false); in gsmld_close()
2950 gsmld_detach_gsm(tty, gsm); in gsmld_close()
2954 mux_put(gsm); in gsmld_close()
2969 struct gsm_mux *gsm; in gsmld_open() local
2975 gsm = gsm_alloc_mux(); in gsmld_open()
2976 if (gsm == NULL) in gsmld_open()
2979 tty->disc_data = gsm; in gsmld_open()
2983 gsm->encoding = GSM_ADV_OPT; in gsmld_open()
2984 gsmld_attach_gsm(tty, gsm); in gsmld_open()
3000 struct gsm_mux *gsm = tty->disc_data; in gsmld_write_wakeup() local
3003 gsmld_write_trigger(gsm); in gsmld_write_wakeup()
3047 struct gsm_mux *gsm = tty->disc_data; in gsmld_write() local
3052 if (!gsm) in gsmld_write()
3056 spin_lock_irqsave(&gsm->tx_lock, flags); in gsmld_write()
3062 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsmld_write()
3085 struct gsm_mux *gsm = tty->disc_data; in gsmld_poll() local
3090 if (gsm->dead) in gsmld_poll()
3105 struct gsm_mux *gsm = tty->disc_data; in gsmld_ioctl() local
3110 gsm_copy_config_values(gsm, &c); in gsmld_ioctl()
3117 return gsm_config(gsm, &c); in gsmld_ioctl()
3119 base = mux_num_to_base(gsm); in gsmld_ioctl()
3302 net->mtu = dlci->gsm->mtu; in gsm_create_network()
3304 net->max_mtu = dlci->gsm->mtu; in gsm_create_network()
3358 struct gsm_mux *gsm = dlci->gsm; in gsm_modem_upd_via_data() local
3364 spin_lock_irqsave(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
3365 gsm_dlci_modem_output(gsm, dlci, brk); in gsm_modem_upd_via_data()
3366 spin_unlock_irqrestore(&gsm->tx_lock, flags); in gsm_modem_upd_via_data()
3381 if (dlci->gsm->encoding != GSM_BASIC_OPT) in gsm_modem_upd_via_msc()
3392 ctrl = gsm_control_send(dlci->gsm, CMD_MSC, modembits, len); in gsm_modem_upd_via_msc()
3395 return gsm_control_wait(dlci->gsm, ctrl); in gsm_modem_upd_via_msc()
3410 } else if (dlci->gsm->encoding == GSM_BASIC_OPT) { in gsm_modem_update()
3422 struct gsm_mux *gsm = dlci->gsm; in gsm_carrier_raised() local
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()
3463 struct gsm_mux *gsm; in gsmtty_install() local
3479 gsm = gsm_mux[mux]; in gsmtty_install()
3480 if (gsm->dead) 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()
3491 dlci = gsm->dlci[line]; in gsmtty_install()
3494 dlci = gsm_dlci_alloc(gsm, line); in gsmtty_install()
3497 mutex_unlock(&gsm->mutex); in gsmtty_install()
3504 mutex_unlock(&gsm->mutex); in gsmtty_install()
3509 dlci_get(gsm->dlci[0]); in gsmtty_install()
3510 mux_get(gsm); in gsmtty_install()
3512 mutex_unlock(&gsm->mutex); in gsmtty_install()
3521 struct gsm_mux *gsm = dlci->gsm; in gsmtty_open() local
3531 if (gsm->initiator) in gsmtty_open()
3742 struct gsm_mux *gsm = dlci->gsm; in gsmtty_cleanup() local
3745 dlci_put(gsm->dlci[0]); in gsmtty_cleanup()
3746 mux_put(gsm); in gsmtty_cleanup()