Lines Matching +full:usb +full:- +full:to +full:- +full:serial
1 // SPDX-License-Identifier: GPL-2.0-only
12 * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
22 * The multiplexed serial ports are using the interrupt and
31 * Interface 2: Standard modem interface - circuit switched interface, this
32 * can be used to make a standard ppp connection however it
34 * enabled for USB performance reasons i.e. if using this set
48 #include <linux/usb.h>
56 #include <linux/usb/cdc.h>
60 #include <linux/serial.h>
64 #define MOD_DESCRIPTION "USB High Speed Option driver"
83 /* - use *_bit operations on it. (bit indices not values.) */
90 /* Number of ttys to handle */
122 struct usb_device *usb; member
203 on which serial port it is used on. */
230 int (*write_data) (struct hso_serial *serial);
232 /* Hacks required to get flow control
233 * working on the serial receive buffers
234 * so as not to drop characters on the floor.
254 struct usb_device *usb; member
290 /* Serial driver functions */
294 static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial);
295 static void hso_kick_transmit(struct hso_serial *serial);
298 struct usb_device *usb, gfp_t gfp);
312 static int hso_mux_serial_read(struct hso_serial *serial);
326 return hso_dev->port_data.dev_net; in dev2net()
331 return hso_dev->port_data.dev_serial; in dev2ser()
367 /* the usb driver itself (registered in hso_init) */
369 /* serial structures */
418 {default_port_device(0x0af0, 0xc031)}, /* Icon-Edge */
420 {icon321_port_device(0x0af0, 0xd031)}, /* Icon-321 */
421 {icon321_port_device(0x0af0, 0xd033)}, /* Icon-322 */
457 MODULE_DEVICE_TABLE(usb, hso_ids);
469 switch (hso_dev->port_spec & HSO_PORT_MASK) { in hsotype_show()
516 static int hso_urb_to_index(struct hso_serial *serial, struct urb *urb) in hso_urb_to_index() argument
520 for (idx = 0; idx < serial->num_rx_urbs; idx++) in hso_urb_to_index()
521 if (serial->rx_urb[idx] == urb) in hso_urb_to_index()
523 dev_err(serial->parent->dev, "hso_urb_to_index failed\n"); in hso_urb_to_index()
524 return -1; in hso_urb_to_index()
527 /* converts mux value to a port spec value */
554 /* converts port spec value to a mux value */
591 (dev2ser(serial_table[i])->shared_int == shared_int) && in get_serial_by_shared_int_and_type()
592 ((serial_table[i]->port_spec & HSO_PORT_MASK) == port)) { in get_serial_by_shared_int_and_type()
602 struct hso_serial *serial = NULL; in get_serial_by_index() local
607 serial = dev2ser(serial_table[index]); in get_serial_by_index()
610 return serial; in get_serial_by_index()
613 static int obtain_minor(struct hso_serial *serial) in obtain_minor() argument
621 serial_table[index] = serial->parent; in obtain_minor()
622 serial->minor = index; in obtain_minor()
629 pr_err("%s: no free serial devices in table\n", __func__); in obtain_minor()
630 return -1; in obtain_minor()
633 static void release_minor(struct hso_serial *serial) in release_minor() argument
638 serial_table[serial->minor] = NULL; in release_minor()
648 case -ENODEV: in handle_usb_error()
651 case -ENOENT: in handle_usb_error()
654 case -EPIPE: in handle_usb_error()
657 case -ENOSPC: in handle_usb_error()
660 case -ESHUTDOWN: in handle_usb_error()
663 case -EHOSTUNREACH: in handle_usb_error()
666 case -EINVAL: in handle_usb_error()
667 case -EAGAIN: in handle_usb_error()
668 case -EFBIG: in handle_usb_error()
669 case -EMSGSIZE: in handle_usb_error()
672 case -EILSEQ: in handle_usb_error()
673 case -EPROTO: in handle_usb_error()
674 case -ETIME: in handle_usb_error()
675 case -ETIMEDOUT: in handle_usb_error()
678 usb_queue_reset_device(hso_dev->interface); in handle_usb_error()
685 /* log a meaningful explanation of an USB status */ in handle_usb_error()
686 hso_dbg(0x1, "%s: received USB status - %s (%d)\n", in handle_usb_error()
699 dev_err(&net->dev, "No net device !\n"); in hso_net_open()
700 return -ENODEV; in hso_net_open()
703 odev->skb_tx_buf = NULL; in hso_net_open()
706 spin_lock_irqsave(&odev->net_lock, flags); in hso_net_open()
707 odev->rx_parse_state = WAIT_IP; in hso_net_open()
708 odev->rx_buf_size = 0; in hso_net_open()
709 odev->rx_buf_missing = sizeof(struct iphdr); in hso_net_open()
710 spin_unlock_irqrestore(&odev->net_lock, flags); in hso_net_open()
713 set_bit(HSO_NET_RUNNING, &odev->flags); in hso_net_open()
714 hso_start_net_device(odev->parent); in hso_net_open()
716 /* Tell the kernel we are ready to start receiving from it */ in hso_net_open()
730 clear_bit(HSO_NET_RUNNING, &odev->flags); in hso_net_close()
732 hso_stop_net_device(odev->parent); in hso_net_close()
738 /* USB tells is xmit done, we should start the netqueue again */
741 struct hso_net *odev = urb->context; in write_bulk_callback()
742 int status = urb->status; in write_bulk_callback()
745 if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) { in write_bulk_callback()
746 dev_err(&urb->dev->dev, "%s: device not running\n", __func__); in write_bulk_callback()
751 if (!netif_device_present(odev->net)) { in write_bulk_callback()
752 dev_err(&urb->dev->dev, "%s: net device not present\n", in write_bulk_callback()
757 /* log status, but don't act on it, we don't need to resubmit anything in write_bulk_callback()
760 handle_usb_error(status, __func__, odev->parent); in write_bulk_callback()
762 hso_put_activity(odev->parent); in write_bulk_callback()
765 netif_wake_queue(odev->net); in write_bulk_callback()
768 /* called by kernel when we need to transmit a packet */
777 if (hso_get_activity(odev->parent) == -EAGAIN) { in hso_net_start_xmit()
778 odev->skb_tx_buf = skb; in hso_net_start_xmit()
783 DUMP1(skb->data, skb->len); in hso_net_start_xmit()
784 /* Copy it from kernel memory to OUR memory */ in hso_net_start_xmit()
785 memcpy(odev->mux_bulk_tx_buf, skb->data, skb->len); in hso_net_start_xmit()
786 hso_dbg(0x1, "len: %d/%d\n", skb->len, MUX_BULK_TX_BUF_SIZE); in hso_net_start_xmit()
789 usb_fill_bulk_urb(odev->mux_bulk_tx_urb, in hso_net_start_xmit()
790 odev->parent->usb, in hso_net_start_xmit()
791 usb_sndbulkpipe(odev->parent->usb, in hso_net_start_xmit()
792 odev->out_endp-> in hso_net_start_xmit()
794 odev->mux_bulk_tx_buf, skb->len, write_bulk_callback, in hso_net_start_xmit()
798 odev->mux_bulk_tx_urb->transfer_flags |= URB_ZERO_PACKET; in hso_net_start_xmit()
801 result = usb_submit_urb(odev->mux_bulk_tx_urb, GFP_ATOMIC); in hso_net_start_xmit()
803 dev_warn(&odev->parent->interface->dev, in hso_net_start_xmit()
805 net->stats.tx_errors++; in hso_net_start_xmit()
808 net->stats.tx_packets++; in hso_net_start_xmit()
809 net->stats.tx_bytes += skb->len; in hso_net_start_xmit()
829 dev_warn(&net->dev, "Tx timed out.\n"); in hso_net_tx_timeout()
832 if (odev->mux_bulk_tx_urb) in hso_net_tx_timeout()
833 usb_unlink_urb(odev->mux_bulk_tx_urb); in hso_net_tx_timeout()
836 net->stats.tx_errors++; in hso_net_tx_timeout()
839 /* make a real packet from the received USB buffer */
852 switch (odev->rx_parse_state) { in packetizeRx()
855 /* wanted bytes - size of ip header */ in packetizeRx()
858 odev->rx_buf_missing) ? count : odev-> in packetizeRx()
861 memcpy(((unsigned char *)(&odev->rx_ip_hdr)) + in packetizeRx()
862 odev->rx_buf_size, ip_pkt + buffer_offset, in packetizeRx()
865 odev->rx_buf_size += temp_bytes; in packetizeRx()
867 odev->rx_buf_missing -= temp_bytes; in packetizeRx()
868 count -= temp_bytes; in packetizeRx()
870 if (!odev->rx_buf_missing) { in packetizeRx()
872 * continue to WAIT_DATA */ in packetizeRx()
873 frame_len = ntohs(odev->rx_ip_hdr.tot_len); in packetizeRx()
877 dev_err(&odev->net->dev, in packetizeRx()
880 odev->rx_parse_state = WAIT_SYNC; in packetizeRx()
884 odev->skb_rx_buf = netdev_alloc_skb(odev->net, in packetizeRx()
886 if (!odev->skb_rx_buf) { in packetizeRx()
889 odev->rx_parse_state = WAIT_SYNC; in packetizeRx()
895 skb_put_data(odev->skb_rx_buf, in packetizeRx()
896 (char *)&(odev->rx_ip_hdr), in packetizeRx()
900 odev->rx_buf_size = sizeof(struct iphdr); in packetizeRx()
903 odev->rx_buf_missing = in packetizeRx()
904 frame_len - sizeof(struct iphdr); in packetizeRx()
905 odev->rx_parse_state = WAIT_DATA; in packetizeRx()
910 temp_bytes = (count < odev->rx_buf_missing) in packetizeRx()
911 ? count : odev->rx_buf_missing; in packetizeRx()
916 skb_put_data(odev->skb_rx_buf, in packetizeRx()
920 odev->rx_buf_missing -= temp_bytes; in packetizeRx()
921 count -= temp_bytes; in packetizeRx()
923 odev->rx_buf_size += temp_bytes; in packetizeRx()
924 if (!odev->rx_buf_missing) { in packetizeRx()
927 odev->skb_rx_buf->protocol = cpu_to_be16(ETH_P_IP); in packetizeRx()
928 skb_reset_mac_header(odev->skb_rx_buf); in packetizeRx()
930 /* Ship it off to the kernel */ in packetizeRx()
931 netif_rx(odev->skb_rx_buf); in packetizeRx()
933 odev->skb_rx_buf = NULL; in packetizeRx()
936 odev->net->stats.rx_packets++; in packetizeRx()
938 odev->net->stats.rx_bytes += odev->rx_buf_size; in packetizeRx()
940 odev->rx_buf_size = 0; in packetizeRx()
941 odev->rx_buf_missing = sizeof(struct iphdr); in packetizeRx()
942 odev->rx_parse_state = WAIT_IP; in packetizeRx()
952 count--; in packetizeRx()
959 if (odev->rx_parse_state == WAIT_SYNC) { in packetizeRx()
960 odev->rx_parse_state = WAIT_IP; in packetizeRx()
961 odev->rx_buf_size = 0; in packetizeRx()
962 odev->rx_buf_missing = sizeof(struct iphdr); in packetizeRx()
970 u32 rest = urb->actual_length % le16_to_cpu(max_packet_size); in fix_crc_bug()
973 !memcmp(((u8 *)urb->transfer_buffer) + urb->actual_length - 4, in fix_crc_bug()
975 urb->actual_length -= 4; in fix_crc_bug()
979 /* Moving data from usb to kernel (in interrupt state) */
982 struct hso_net *odev = urb->context; in read_bulk_callback()
986 int status = urb->status; in read_bulk_callback()
990 handle_usb_error(status, __func__, odev->parent); in read_bulk_callback()
995 if (!odev || !test_bit(HSO_NET_RUNNING, &odev->flags)) { in read_bulk_callback()
999 usb_mark_last_busy(urb->dev); in read_bulk_callback()
1001 net = odev->net; in read_bulk_callback()
1008 if (odev->parent->port_spec & HSO_INFO_CRC_BUG) in read_bulk_callback()
1009 fix_crc_bug(urb, odev->in_endp->wMaxPacketSize); in read_bulk_callback()
1012 if (urb->actual_length) { in read_bulk_callback()
1015 spin_lock_irqsave(&odev->net_lock, flags); in read_bulk_callback()
1016 packetizeRx(odev, urb->transfer_buffer, urb->actual_length, in read_bulk_callback()
1017 (urb->transfer_buffer_length > in read_bulk_callback()
1018 urb->actual_length) ? 1 : 0); in read_bulk_callback()
1019 spin_unlock_irqrestore(&odev->net_lock, flags); in read_bulk_callback()
1022 /* We are done with this URB, resubmit it. Prep the USB to wait for in read_bulk_callback()
1025 odev->parent->usb, in read_bulk_callback()
1026 usb_rcvbulkpipe(odev->parent->usb, in read_bulk_callback()
1027 odev->in_endp-> in read_bulk_callback()
1029 urb->transfer_buffer, MUX_BULK_RX_BUF_SIZE, in read_bulk_callback()
1032 /* Give this to the USB subsystem so it can tell us when more data in read_bulk_callback()
1036 dev_warn(&odev->parent->interface->dev, in read_bulk_callback()
1041 /* Serial driver functions */
1048 termios->c_iflag &= in hso_init_termios()
1053 | INLCR /* disable translate NL to CR */ in hso_init_termios()
1055 | ICRNL /* disable translate CR to NL */ in hso_init_termios()
1059 termios->c_oflag &= ~OPOST; in hso_init_termios()
1061 termios->c_lflag &= in hso_init_termios()
1068 | IEXTEN); /* disable non-POSIX special characters */ in hso_init_termios()
1070 termios->c_cflag &= in hso_init_termios()
1076 termios->c_cflag |= CS8; /* character size 8 bits */ in hso_init_termios()
1084 struct hso_serial *serial = tty->driver_data; in _hso_serial_set_termios() local
1086 if (!serial) { in _hso_serial_set_termios()
1091 hso_dbg(0x8, "port %d\n", serial->minor); in _hso_serial_set_termios()
1096 tty->termios.c_iflag &= ~IXON; /* disable enable XON/XOFF flow control */ in _hso_serial_set_termios()
1098 tty->termios.c_cflag &= in _hso_serial_set_termios()
1104 tty->termios.c_cflag |= CS8; /* character size 8 bits */ in _hso_serial_set_termios()
1110 static void hso_resubmit_rx_bulk_urb(struct hso_serial *serial, struct urb *urb) in hso_resubmit_rx_bulk_urb() argument
1113 /* We are done with this URB, resubmit it. Prep the USB to wait for in hso_resubmit_rx_bulk_urb()
1115 usb_fill_bulk_urb(urb, serial->parent->usb, in hso_resubmit_rx_bulk_urb()
1116 usb_rcvbulkpipe(serial->parent->usb, in hso_resubmit_rx_bulk_urb()
1117 serial->in_endp-> in hso_resubmit_rx_bulk_urb()
1119 urb->transfer_buffer, serial->rx_data_length, in hso_resubmit_rx_bulk_urb()
1120 hso_std_serial_read_bulk_callback, serial); in hso_resubmit_rx_bulk_urb()
1121 /* Give this to the USB subsystem so it can tell us when more data in hso_resubmit_rx_bulk_urb()
1125 dev_err(&urb->dev->dev, "%s failed submit serial rx_urb %d\n", in hso_resubmit_rx_bulk_urb()
1133 static void put_rxbuf_data_and_resubmit_bulk_urb(struct hso_serial *serial) in put_rxbuf_data_and_resubmit_bulk_urb() argument
1138 while (serial->rx_urb_filled[serial->curr_rx_urb_idx]) { in put_rxbuf_data_and_resubmit_bulk_urb()
1139 curr_urb = serial->rx_urb[serial->curr_rx_urb_idx]; in put_rxbuf_data_and_resubmit_bulk_urb()
1140 count = put_rxbuf_data(curr_urb, serial); in put_rxbuf_data_and_resubmit_bulk_urb()
1141 if (count == -1) in put_rxbuf_data_and_resubmit_bulk_urb()
1144 serial->curr_rx_urb_idx++; in put_rxbuf_data_and_resubmit_bulk_urb()
1145 if (serial->curr_rx_urb_idx >= serial->num_rx_urbs) in put_rxbuf_data_and_resubmit_bulk_urb()
1146 serial->curr_rx_urb_idx = 0; in put_rxbuf_data_and_resubmit_bulk_urb()
1147 hso_resubmit_rx_bulk_urb(serial, curr_urb); in put_rxbuf_data_and_resubmit_bulk_urb()
1152 static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial) in put_rxbuf_data_and_resubmit_ctrl_urb() argument
1157 urb = serial->rx_urb[0]; in put_rxbuf_data_and_resubmit_ctrl_urb()
1158 if (serial->port.count > 0) { in put_rxbuf_data_and_resubmit_ctrl_urb()
1159 count = put_rxbuf_data(urb, serial); in put_rxbuf_data_and_resubmit_ctrl_urb()
1160 if (count == -1) in put_rxbuf_data_and_resubmit_ctrl_urb()
1165 if (count == 0 && ((urb->actual_length != 0) || in put_rxbuf_data_and_resubmit_ctrl_urb()
1166 (serial->rx_state == RX_PENDING))) { in put_rxbuf_data_and_resubmit_ctrl_urb()
1167 serial->rx_state = RX_SENT; in put_rxbuf_data_and_resubmit_ctrl_urb()
1168 hso_mux_serial_read(serial); in put_rxbuf_data_and_resubmit_ctrl_urb()
1170 serial->rx_state = RX_IDLE; in put_rxbuf_data_and_resubmit_ctrl_urb()
1177 struct hso_serial *serial = urb->context; in hso_std_serial_read_bulk_callback() local
1178 int status = urb->status; in hso_std_serial_read_bulk_callback()
1181 hso_dbg(0x8, "--- Got serial_read_bulk callback %02x ---\n", status); in hso_std_serial_read_bulk_callback()
1184 if (!serial) { in hso_std_serial_read_bulk_callback()
1185 hso_dbg(0x1, "serial == NULL\n"); in hso_std_serial_read_bulk_callback()
1189 handle_usb_error(status, __func__, serial->parent); in hso_std_serial_read_bulk_callback()
1193 hso_dbg(0x1, "Actual length = %d\n", urb->actual_length); in hso_std_serial_read_bulk_callback()
1194 DUMP1(urb->transfer_buffer, urb->actual_length); in hso_std_serial_read_bulk_callback()
1197 if (serial->port.count == 0) in hso_std_serial_read_bulk_callback()
1200 if (serial->parent->port_spec & HSO_INFO_CRC_BUG) in hso_std_serial_read_bulk_callback()
1201 fix_crc_bug(urb, serial->in_endp->wMaxPacketSize); in hso_std_serial_read_bulk_callback()
1203 spin_lock_irqsave(&serial->serial_lock, flags); in hso_std_serial_read_bulk_callback()
1204 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 1; in hso_std_serial_read_bulk_callback()
1205 put_rxbuf_data_and_resubmit_bulk_urb(serial); in hso_std_serial_read_bulk_callback()
1206 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_std_serial_read_bulk_callback()
1210 * This needs to be a tasklet otherwise we will
1215 struct hso_serial *serial = from_tasklet(serial, t, in hso_unthrottle_tasklet() local
1219 spin_lock_irqsave(&serial->serial_lock, flags); in hso_unthrottle_tasklet()
1220 if ((serial->parent->port_spec & HSO_INTF_MUX)) in hso_unthrottle_tasklet()
1221 put_rxbuf_data_and_resubmit_ctrl_urb(serial); in hso_unthrottle_tasklet()
1223 put_rxbuf_data_and_resubmit_bulk_urb(serial); in hso_unthrottle_tasklet()
1224 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_unthrottle_tasklet()
1229 struct hso_serial *serial = tty->driver_data; in hso_unthrottle() local
1231 tasklet_hi_schedule(&serial->unthrottle_tasklet); in hso_unthrottle()
1234 /* open the requested serial port */
1237 struct hso_serial *serial = get_serial_by_index(tty->index); in hso_serial_open() local
1241 if (serial == NULL || serial->magic != HSO_SERIAL_MAGIC) { in hso_serial_open()
1243 tty->driver_data = NULL; in hso_serial_open()
1244 hso_dbg(0x1, "Failed to open port\n"); in hso_serial_open()
1245 return -ENODEV; in hso_serial_open()
1248 mutex_lock(&serial->parent->mutex); in hso_serial_open()
1249 result = usb_autopm_get_interface(serial->parent->interface); in hso_serial_open()
1253 hso_dbg(0x1, "Opening %d\n", serial->minor); in hso_serial_open()
1256 tty->driver_data = serial; in hso_serial_open()
1257 tty_port_tty_set(&serial->port, tty); in hso_serial_open()
1260 serial->port.count++; in hso_serial_open()
1261 if (serial->port.count == 1) { in hso_serial_open()
1262 serial->rx_state = RX_IDLE; in hso_serial_open()
1265 tasklet_setup(&serial->unthrottle_tasklet, in hso_serial_open()
1267 result = hso_start_serial_device(serial->parent, GFP_KERNEL); in hso_serial_open()
1269 hso_stop_serial_device(serial->parent); in hso_serial_open()
1270 serial->port.count--; in hso_serial_open()
1272 kref_get(&serial->parent->ref); in hso_serial_open()
1278 usb_autopm_put_interface(serial->parent->interface); in hso_serial_open()
1284 mutex_unlock(&serial->parent->mutex); in hso_serial_open()
1288 /* close the requested serial port */
1291 struct hso_serial *serial = tty->driver_data; in hso_serial_close() local
1294 hso_dbg(0x1, "Closing serial port\n"); in hso_serial_close()
1297 if (serial == NULL) in hso_serial_close()
1300 mutex_lock(&serial->parent->mutex); in hso_serial_close()
1301 usb_gone = serial->parent->usb_gone; in hso_serial_close()
1304 usb_autopm_get_interface(serial->parent->interface); in hso_serial_close()
1308 serial->port.count--; in hso_serial_close()
1310 if (serial->port.count <= 0) { in hso_serial_close()
1311 serial->port.count = 0; in hso_serial_close()
1312 tty_port_tty_set(&serial->port, NULL); in hso_serial_close()
1314 hso_stop_serial_device(serial->parent); in hso_serial_close()
1315 tasklet_kill(&serial->unthrottle_tasklet); in hso_serial_close()
1319 usb_autopm_put_interface(serial->parent->interface); in hso_serial_close()
1321 mutex_unlock(&serial->parent->mutex); in hso_serial_close()
1324 /* close the requested serial port */
1328 struct hso_serial *serial = tty->driver_data; in hso_serial_write() local
1332 if (serial == NULL) { in hso_serial_write()
1333 pr_err("%s: serial is NULL\n", __func__); in hso_serial_write()
1334 return -ENODEV; in hso_serial_write()
1337 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_write()
1339 count = min_t(size_t, serial->tx_data_length - serial->tx_buffer_count, in hso_serial_write()
1341 memcpy(serial->tx_buffer + serial->tx_buffer_count, buf, count); in hso_serial_write()
1342 serial->tx_buffer_count += count; in hso_serial_write()
1344 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_write()
1346 hso_kick_transmit(serial); in hso_serial_write()
1354 struct hso_serial *serial = tty->driver_data; in hso_serial_write_room() local
1358 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_write_room()
1359 room = serial->tx_data_length - serial->tx_buffer_count; in hso_serial_write_room()
1360 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_write_room()
1368 struct hso_serial *serial = tty->driver_data; in hso_serial_cleanup() local
1370 if (!serial) in hso_serial_cleanup()
1373 kref_put(&serial->parent->ref, hso_serial_ref_free); in hso_serial_cleanup()
1380 struct hso_serial *serial = tty->driver_data; in hso_serial_set_termios() local
1384 hso_dbg(0x16, "Termios called with: cflags new[%u] - old[%u]\n", in hso_serial_set_termios()
1385 (unsigned int)tty->termios.c_cflag, in hso_serial_set_termios()
1386 (unsigned int)old->c_cflag); in hso_serial_set_termios()
1389 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_set_termios()
1390 if (serial->port.count) in hso_serial_set_termios()
1393 tty->termios = *old; in hso_serial_set_termios()
1394 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_set_termios()
1402 struct hso_serial *serial = tty->driver_data; in hso_serial_chars_in_buffer() local
1407 if (serial == NULL) in hso_serial_chars_in_buffer()
1410 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_chars_in_buffer()
1411 chars = serial->tx_buffer_count; in hso_serial_chars_in_buffer()
1412 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_chars_in_buffer()
1416 static int tiocmget_submit_urb(struct hso_serial *serial, in tiocmget_submit_urb() argument
1418 struct usb_device *usb) in tiocmget_submit_urb() argument
1422 if (serial->parent->usb_gone) in tiocmget_submit_urb()
1423 return -ENODEV; in tiocmget_submit_urb()
1424 usb_fill_int_urb(tiocmget->urb, usb, in tiocmget_submit_urb()
1425 usb_rcvintpipe(usb, in tiocmget_submit_urb()
1426 tiocmget->endp-> in tiocmget_submit_urb()
1428 tiocmget->serial_state_notification, in tiocmget_submit_urb()
1430 tiocmget_intr_callback, serial, in tiocmget_submit_urb()
1431 tiocmget->endp->bInterval); in tiocmget_submit_urb()
1432 result = usb_submit_urb(tiocmget->urb, GFP_ATOMIC); in tiocmget_submit_urb()
1434 dev_warn(&usb->dev, "%s usb_submit_urb failed %d\n", __func__, in tiocmget_submit_urb()
1443 struct hso_serial *serial = urb->context; in tiocmget_intr_callback() local
1445 int status = urb->status; in tiocmget_intr_callback()
1449 struct usb_device *usb; in tiocmget_intr_callback() local
1454 if (!serial) in tiocmget_intr_callback()
1457 handle_usb_error(status, __func__, serial->parent); in tiocmget_intr_callback()
1462 tiocmget = serial->tiocmget; in tiocmget_intr_callback()
1465 BUG_ON((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM); in tiocmget_intr_callback()
1467 usb = serial->parent->usb; in tiocmget_intr_callback()
1468 interface = serial->parent->interface; in tiocmget_intr_callback()
1470 if_num = interface->cur_altsetting->desc.bInterfaceNumber; in tiocmget_intr_callback()
1472 /* wIndex should be the USB interface number of the port to which the in tiocmget_intr_callback()
1475 serial_state_notification = tiocmget->serial_state_notification; in tiocmget_intr_callback()
1476 if (serial_state_notification->bmRequestType != BM_REQUEST_TYPE || in tiocmget_intr_callback()
1477 serial_state_notification->bNotification != B_NOTIFICATION || in tiocmget_intr_callback()
1478 le16_to_cpu(serial_state_notification->wValue) != W_VALUE || in tiocmget_intr_callback()
1479 le16_to_cpu(serial_state_notification->wIndex) != if_num || in tiocmget_intr_callback()
1480 le16_to_cpu(serial_state_notification->wLength) != W_LENGTH) { in tiocmget_intr_callback()
1481 dev_warn(&usb->dev, in tiocmget_intr_callback()
1482 "hso received invalid serial state notification\n"); in tiocmget_intr_callback()
1488 UART_state_bitmap = le16_to_cpu(serial_state_notification-> in tiocmget_intr_callback()
1490 prev_UART_state_bitmap = tiocmget->prev_UART_state_bitmap; in tiocmget_intr_callback()
1491 icount = &tiocmget->icount; in tiocmget_intr_callback()
1492 spin_lock_irqsave(&serial->serial_lock, flags); in tiocmget_intr_callback()
1495 icount->parity++; in tiocmget_intr_callback()
1498 icount->parity++; in tiocmget_intr_callback()
1501 icount->frame++; in tiocmget_intr_callback()
1504 icount->rng++; in tiocmget_intr_callback()
1507 icount->brk++; in tiocmget_intr_callback()
1510 icount->dsr++; in tiocmget_intr_callback()
1513 icount->dcd++; in tiocmget_intr_callback()
1514 tiocmget->prev_UART_state_bitmap = UART_state_bitmap; in tiocmget_intr_callback()
1515 spin_unlock_irqrestore(&serial->serial_lock, flags); in tiocmget_intr_callback()
1516 tiocmget->intr_completed = 1; in tiocmget_intr_callback()
1517 wake_up_interruptible(&tiocmget->waitq); in tiocmget_intr_callback()
1521 tiocmget_submit_urb(serial, in tiocmget_intr_callback()
1523 serial->parent->usb); in tiocmget_intr_callback()
1527 * next few functions largely stolen from drivers/serial/serial_core.c
1529 /* Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1530 * - mask passed in arg for lines of interest
1532 * Caller should use TIOCGICOUNT to see which one it was
1535 hso_wait_modem_status(struct hso_serial *serial, unsigned long arg) in hso_wait_modem_status() argument
1542 tiocmget = serial->tiocmget; in hso_wait_modem_status()
1544 return -ENOENT; in hso_wait_modem_status()
1548 spin_lock_irq(&serial->serial_lock); in hso_wait_modem_status()
1549 memcpy(&cprev, &tiocmget->icount, sizeof(struct uart_icount)); in hso_wait_modem_status()
1550 spin_unlock_irq(&serial->serial_lock); in hso_wait_modem_status()
1551 add_wait_queue(&tiocmget->waitq, &wait); in hso_wait_modem_status()
1553 spin_lock_irq(&serial->serial_lock); in hso_wait_modem_status()
1554 memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount)); in hso_wait_modem_status()
1555 spin_unlock_irq(&serial->serial_lock); in hso_wait_modem_status()
1566 ret = -ERESTARTSYS; in hso_wait_modem_status()
1572 remove_wait_queue(&tiocmget->waitq, &wait); in hso_wait_modem_status()
1578 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1579 * Return: write counters to the user passed counter struct
1580 * NB: both 1->0 and 0->1 transitions are counted except for
1581 * RI where only 0->1 is counted.
1587 struct hso_serial *serial = tty->driver_data; in hso_get_count() local
1588 struct hso_tiocmget *tiocmget = serial->tiocmget; in hso_get_count()
1593 return -ENOENT; in hso_get_count()
1594 spin_lock_irq(&serial->serial_lock); in hso_get_count()
1595 memcpy(&cnow, &tiocmget->icount, sizeof(struct uart_icount)); in hso_get_count()
1596 spin_unlock_irq(&serial->serial_lock); in hso_get_count()
1598 icount->cts = cnow.cts; in hso_get_count()
1599 icount->dsr = cnow.dsr; in hso_get_count()
1600 icount->rng = cnow.rng; in hso_get_count()
1601 icount->dcd = cnow.dcd; in hso_get_count()
1602 icount->rx = cnow.rx; in hso_get_count()
1603 icount->tx = cnow.tx; in hso_get_count()
1604 icount->frame = cnow.frame; in hso_get_count()
1605 icount->overrun = cnow.overrun; in hso_get_count()
1606 icount->parity = cnow.parity; in hso_get_count()
1607 icount->brk = cnow.brk; in hso_get_count()
1608 icount->buf_overrun = cnow.buf_overrun; in hso_get_count()
1617 struct hso_serial *serial = tty->driver_data; in hso_serial_tiocmget() local
1622 if (!serial) { in hso_serial_tiocmget()
1624 return -EINVAL; in hso_serial_tiocmget()
1626 spin_lock_irq(&serial->serial_lock); in hso_serial_tiocmget()
1627 retval = ((serial->rts_state) ? TIOCM_RTS : 0) | in hso_serial_tiocmget()
1628 ((serial->dtr_state) ? TIOCM_DTR : 0); in hso_serial_tiocmget()
1629 tiocmget = serial->tiocmget; in hso_serial_tiocmget()
1633 tiocmget->prev_UART_state_bitmap); in hso_serial_tiocmget()
1641 spin_unlock_irq(&serial->serial_lock); in hso_serial_tiocmget()
1651 struct hso_serial *serial = tty->driver_data; in hso_serial_tiocmset() local
1655 if (!serial) { in hso_serial_tiocmset()
1657 return -EINVAL; in hso_serial_tiocmset()
1660 if ((serial->parent->port_spec & HSO_PORT_MASK) != HSO_PORT_MODEM) in hso_serial_tiocmset()
1661 return -EINVAL; in hso_serial_tiocmset()
1663 interface = serial->parent->interface; in hso_serial_tiocmset()
1664 if_num = interface->cur_altsetting->desc.bInterfaceNumber; in hso_serial_tiocmset()
1666 spin_lock_irqsave(&serial->serial_lock, flags); in hso_serial_tiocmset()
1668 serial->rts_state = 1; in hso_serial_tiocmset()
1670 serial->dtr_state = 1; in hso_serial_tiocmset()
1673 serial->rts_state = 0; in hso_serial_tiocmset()
1675 serial->dtr_state = 0; in hso_serial_tiocmset()
1677 if (serial->dtr_state) in hso_serial_tiocmset()
1679 if (serial->rts_state) in hso_serial_tiocmset()
1682 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_serial_tiocmset()
1684 return usb_control_msg(serial->parent->usb, in hso_serial_tiocmset()
1685 usb_sndctrlpipe(serial->parent->usb, 0), 0x22, in hso_serial_tiocmset()
1693 struct hso_serial *serial = tty->driver_data; in hso_serial_ioctl() local
1697 if (!serial) in hso_serial_ioctl()
1698 return -ENODEV; in hso_serial_ioctl()
1701 ret = hso_wait_modem_status(serial, arg); in hso_serial_ioctl()
1704 ret = -ENOIOCTLCMD; in hso_serial_ioctl()
1712 static void hso_kick_transmit(struct hso_serial *serial) in hso_kick_transmit() argument
1717 spin_lock_irqsave(&serial->serial_lock, flags); in hso_kick_transmit()
1718 if (!serial->tx_buffer_count) in hso_kick_transmit()
1721 if (serial->tx_urb_used) in hso_kick_transmit()
1724 /* Wakeup USB interface if necessary */ in hso_kick_transmit()
1725 if (hso_get_activity(serial->parent) == -EAGAIN) in hso_kick_transmit()
1728 /* Switch pointers around to avoid memcpy */ in hso_kick_transmit()
1729 swap(serial->tx_buffer, serial->tx_data); in hso_kick_transmit()
1730 serial->tx_data_count = serial->tx_buffer_count; in hso_kick_transmit()
1731 serial->tx_buffer_count = 0; in hso_kick_transmit()
1733 /* If serial->tx_data is set, it means we switched buffers */ in hso_kick_transmit()
1734 if (serial->tx_data && serial->write_data) { in hso_kick_transmit()
1735 res = serial->write_data(serial); in hso_kick_transmit()
1737 serial->tx_urb_used = 1; in hso_kick_transmit()
1740 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_kick_transmit()
1743 /* make a request (for reading and writing data to muxed serial port) */
1744 static int mux_device_request(struct hso_serial *serial, u8 type, u16 port, in mux_device_request() argument
1753 if (!serial || !ctrl_urb || !ctrl_req) { in mux_device_request()
1755 return -EINVAL; in mux_device_request()
1759 ctrl_req->wValue = 0; in mux_device_request()
1760 ctrl_req->wIndex = cpu_to_le16(hso_port_to_mux(port)); in mux_device_request()
1761 ctrl_req->wLength = cpu_to_le16(size); in mux_device_request()
1765 ctrl_req->bRequestType = USB_DIR_IN | in mux_device_request()
1768 ctrl_req->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE; in mux_device_request()
1769 pipe = usb_rcvctrlpipe(serial->parent->usb, 0); in mux_device_request()
1772 ctrl_req->bRequestType = USB_DIR_OUT | in mux_device_request()
1775 ctrl_req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND; in mux_device_request()
1776 pipe = usb_sndctrlpipe(serial->parent->usb, 0); in mux_device_request()
1781 ctrl_req->bRequestType, ctrl_req->wLength, port); in mux_device_request()
1784 ctrl_urb->transfer_flags = 0; in mux_device_request()
1786 serial->parent->usb, in mux_device_request()
1789 ctrl_urb_data, size, ctrl_callback, serial); in mux_device_request()
1793 dev_err(&ctrl_urb->dev->dev, in mux_device_request()
1804 static int hso_mux_serial_read(struct hso_serial *serial) in hso_mux_serial_read() argument
1806 if (!serial) in hso_mux_serial_read()
1807 return -EINVAL; in hso_mux_serial_read()
1810 memset(serial->rx_data[0], 0, CTRL_URB_RX_SIZE); in hso_mux_serial_read()
1813 if (serial->num_rx_urbs != 1) { in hso_mux_serial_read()
1814 dev_err(&serial->parent->interface->dev, in hso_mux_serial_read()
1819 return mux_device_request(serial, in hso_mux_serial_read()
1821 serial->parent->port_spec & HSO_PORT_MASK, in hso_mux_serial_read()
1822 serial->rx_urb[0], in hso_mux_serial_read()
1823 &serial->ctrl_req_rx, in hso_mux_serial_read()
1824 serial->rx_data[0], serial->rx_data_length); in hso_mux_serial_read()
1827 /* used for muxed serial port callback (muxed serial read) */
1830 struct hso_shared_int *shared_int = urb->context; in intr_callback()
1831 struct hso_serial *serial; in intr_callback() local
1833 int status = urb->status; in intr_callback()
1837 usb_mark_last_busy(urb->dev); in intr_callback()
1848 hso_dbg(0x8, "--- Got intr callback 0x%02X ---\n", status); in intr_callback()
1851 port_req = urb->transfer_buffer; in intr_callback()
1853 /* loop over all muxed ports to find the one sending this */ in intr_callback()
1857 serial = get_serial_by_shared_int_and_type(shared_int, in intr_callback()
1859 if (serial != NULL) { in intr_callback()
1862 spin_lock_irqsave(&serial->serial_lock, flags); in intr_callback()
1863 if (serial->rx_state == RX_IDLE && in intr_callback()
1864 serial->port.count > 0) { in intr_callback()
1867 if (!serial->rx_urb_filled[0]) { in intr_callback()
1868 serial->rx_state = RX_SENT; in intr_callback()
1869 hso_mux_serial_read(serial); in intr_callback()
1871 serial->rx_state = RX_PENDING; in intr_callback()
1876 spin_unlock_irqrestore(&serial->serial_lock, in intr_callback()
1882 hso_mux_submit_intr_urb(shared_int, urb->dev, GFP_ATOMIC); in intr_callback()
1885 /* called for writing to muxed serial port */
1886 static int hso_mux_serial_write_data(struct hso_serial *serial) in hso_mux_serial_write_data() argument
1888 if (NULL == serial) in hso_mux_serial_write_data()
1889 return -EINVAL; in hso_mux_serial_write_data()
1891 return mux_device_request(serial, in hso_mux_serial_write_data()
1893 serial->parent->port_spec & HSO_PORT_MASK, in hso_mux_serial_write_data()
1894 serial->tx_urb, in hso_mux_serial_write_data()
1895 &serial->ctrl_req_tx, in hso_mux_serial_write_data()
1896 serial->tx_data, serial->tx_data_count); in hso_mux_serial_write_data()
1902 struct hso_serial *serial = urb->context; in hso_std_serial_write_bulk_callback() local
1903 int status = urb->status; in hso_std_serial_write_bulk_callback()
1907 if (!serial) { in hso_std_serial_write_bulk_callback()
1908 hso_dbg(0x1, "serial == NULL\n"); in hso_std_serial_write_bulk_callback()
1912 spin_lock_irqsave(&serial->serial_lock, flags); in hso_std_serial_write_bulk_callback()
1913 serial->tx_urb_used = 0; in hso_std_serial_write_bulk_callback()
1914 spin_unlock_irqrestore(&serial->serial_lock, flags); in hso_std_serial_write_bulk_callback()
1916 handle_usb_error(status, __func__, serial->parent); in hso_std_serial_write_bulk_callback()
1919 hso_put_activity(serial->parent); in hso_std_serial_write_bulk_callback()
1920 tty_port_tty_wakeup(&serial->port); in hso_std_serial_write_bulk_callback()
1921 hso_kick_transmit(serial); in hso_std_serial_write_bulk_callback()
1926 /* called for writing diag or CS serial port */
1927 static int hso_std_serial_write_data(struct hso_serial *serial) in hso_std_serial_write_data() argument
1929 int count = serial->tx_data_count; in hso_std_serial_write_data()
1932 usb_fill_bulk_urb(serial->tx_urb, in hso_std_serial_write_data()
1933 serial->parent->usb, in hso_std_serial_write_data()
1934 usb_sndbulkpipe(serial->parent->usb, in hso_std_serial_write_data()
1935 serial->out_endp-> in hso_std_serial_write_data()
1937 serial->tx_data, serial->tx_data_count, in hso_std_serial_write_data()
1938 hso_std_serial_write_bulk_callback, serial); in hso_std_serial_write_data()
1940 result = usb_submit_urb(serial->tx_urb, GFP_ATOMIC); in hso_std_serial_write_data()
1942 dev_warn(&serial->parent->usb->dev, in hso_std_serial_write_data()
1943 "Failed to submit urb - res %d\n", result); in hso_std_serial_write_data()
1950 /* callback after read or write on muxed serial port */
1953 struct hso_serial *serial = urb->context; in ctrl_callback() local
1955 int status = urb->status; in ctrl_callback()
1959 if (!serial) in ctrl_callback()
1962 spin_lock_irqsave(&serial->serial_lock, flags); in ctrl_callback()
1963 serial->tx_urb_used = 0; in ctrl_callback()
1964 spin_unlock_irqrestore(&serial->serial_lock, flags); in ctrl_callback()
1966 handle_usb_error(status, __func__, serial->parent); in ctrl_callback()
1971 req = (struct usb_ctrlrequest *)(urb->setup_packet); in ctrl_callback()
1972 hso_dbg(0x8, "--- Got muxed ctrl callback 0x%02X ---\n", status); in ctrl_callback()
1973 hso_dbg(0x8, "Actual length of urb = %d\n", urb->actual_length); in ctrl_callback()
1974 DUMP1(urb->transfer_buffer, urb->actual_length); in ctrl_callback()
1976 if (req->bRequestType == in ctrl_callback()
1978 /* response to a read command */ in ctrl_callback()
1979 serial->rx_urb_filled[0] = 1; in ctrl_callback()
1980 spin_lock_irqsave(&serial->serial_lock, flags); in ctrl_callback()
1981 put_rxbuf_data_and_resubmit_ctrl_urb(serial); in ctrl_callback()
1982 spin_unlock_irqrestore(&serial->serial_lock, flags); in ctrl_callback()
1984 hso_put_activity(serial->parent); in ctrl_callback()
1985 tty_port_tty_wakeup(&serial->port); in ctrl_callback()
1986 /* response to a write command */ in ctrl_callback()
1987 hso_kick_transmit(serial); in ctrl_callback()
1991 /* handle RX data for serial port */
1992 static int put_rxbuf_data(struct urb *urb, struct hso_serial *serial) in put_rxbuf_data() argument
1998 if (urb == NULL || serial == NULL) { in put_rxbuf_data()
1999 hso_dbg(0x1, "serial = NULL\n"); in put_rxbuf_data()
2000 return -2; in put_rxbuf_data()
2003 tty = tty_port_tty_get(&serial->port); in put_rxbuf_data()
2007 return -1; in put_rxbuf_data()
2010 /* Push data to tty */ in put_rxbuf_data()
2011 hso_dbg(0x1, "data to push to tty\n"); in put_rxbuf_data()
2012 count = tty_buffer_request_room(&serial->port, urb->actual_length); in put_rxbuf_data()
2013 if (count >= urb->actual_length) { in put_rxbuf_data()
2014 tty_insert_flip_string(&serial->port, urb->transfer_buffer, in put_rxbuf_data()
2015 urb->actual_length); in put_rxbuf_data()
2016 tty_flip_buffer_push(&serial->port); in put_rxbuf_data()
2018 dev_warn(&serial->parent->usb->dev, in put_rxbuf_data()
2019 "dropping data, %d bytes lost\n", urb->actual_length); in put_rxbuf_data()
2024 serial->rx_urb_filled[hso_urb_to_index(serial, urb)] = 0; in put_rxbuf_data()
2037 switch (hso_dev->port_spec & HSO_PORT_MASK) { in hso_log_port()
2072 if ((hso_dev->port_spec & HSO_PORT_MASK) == HSO_PORT_NETWORK) { in hso_log_port()
2073 sprintf(port_dev, "%s", dev2net(hso_dev)->net->name); in hso_log_port()
2076 dev2ser(hso_dev)->minor); in hso_log_port()
2078 dev_dbg(&hso_dev->interface->dev, "HSO: Found %s port %s\n", in hso_log_port()
2088 return -ENODEV; in hso_start_net_device()
2094 usb_fill_bulk_urb(hso_net->mux_bulk_rx_urb_pool[i], in hso_start_net_device()
2095 hso_dev->usb, in hso_start_net_device()
2096 usb_rcvbulkpipe(hso_dev->usb, in hso_start_net_device()
2097 hso_net->in_endp-> in hso_start_net_device()
2099 hso_net->mux_bulk_rx_buf_pool[i], in hso_start_net_device()
2104 result = usb_submit_urb(hso_net->mux_bulk_rx_urb_pool[i], in hso_start_net_device()
2107 dev_warn(&hso_dev->usb->dev, in hso_start_net_device()
2121 return -ENODEV; in hso_stop_net_device()
2124 if (hso_net->mux_bulk_rx_urb_pool[i]) in hso_stop_net_device()
2125 usb_kill_urb(hso_net->mux_bulk_rx_urb_pool[i]); in hso_stop_net_device()
2128 if (hso_net->mux_bulk_tx_urb) in hso_stop_net_device()
2129 usb_kill_urb(hso_net->mux_bulk_tx_urb); in hso_stop_net_device()
2137 struct hso_serial *serial = dev2ser(hso_dev); in hso_start_serial_device() local
2139 if (!serial) in hso_start_serial_device()
2140 return -ENODEV; in hso_start_serial_device()
2144 if (!(serial->parent->port_spec & HSO_INTF_MUX)) { in hso_start_serial_device()
2145 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_start_serial_device()
2146 usb_fill_bulk_urb(serial->rx_urb[i], in hso_start_serial_device()
2147 serial->parent->usb, in hso_start_serial_device()
2148 usb_rcvbulkpipe(serial->parent->usb, in hso_start_serial_device()
2149 serial->in_endp-> in hso_start_serial_device()
2152 serial->rx_data[i], in hso_start_serial_device()
2153 serial->rx_data_length, in hso_start_serial_device()
2155 serial); in hso_start_serial_device()
2156 result = usb_submit_urb(serial->rx_urb[i], flags); in hso_start_serial_device()
2158 dev_warn(&serial->parent->usb->dev, in hso_start_serial_device()
2159 "Failed to submit urb - res %d\n", in hso_start_serial_device()
2165 mutex_lock(&serial->shared_int->shared_int_lock); in hso_start_serial_device()
2166 if (!serial->shared_int->use_count) { in hso_start_serial_device()
2168 hso_mux_submit_intr_urb(serial->shared_int, in hso_start_serial_device()
2169 hso_dev->usb, flags); in hso_start_serial_device()
2171 serial->shared_int->use_count++; in hso_start_serial_device()
2172 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_start_serial_device()
2174 if (serial->tiocmget) in hso_start_serial_device()
2175 tiocmget_submit_urb(serial, in hso_start_serial_device()
2176 serial->tiocmget, in hso_start_serial_device()
2177 serial->parent->usb); in hso_start_serial_device()
2184 struct hso_serial *serial = dev2ser(hso_dev); in hso_stop_serial_device() local
2187 if (!serial) in hso_stop_serial_device()
2188 return -ENODEV; in hso_stop_serial_device()
2190 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_stop_serial_device()
2191 if (serial->rx_urb[i]) { in hso_stop_serial_device()
2192 usb_kill_urb(serial->rx_urb[i]); in hso_stop_serial_device()
2193 serial->rx_urb_filled[i] = 0; in hso_stop_serial_device()
2196 serial->curr_rx_urb_idx = 0; in hso_stop_serial_device()
2198 if (serial->tx_urb) in hso_stop_serial_device()
2199 usb_kill_urb(serial->tx_urb); in hso_stop_serial_device()
2201 if (serial->shared_int) { in hso_stop_serial_device()
2202 mutex_lock(&serial->shared_int->shared_int_lock); in hso_stop_serial_device()
2203 if (serial->shared_int->use_count && in hso_stop_serial_device()
2204 (--serial->shared_int->use_count == 0)) { in hso_stop_serial_device()
2207 urb = serial->shared_int->shared_intr_urb; in hso_stop_serial_device()
2211 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_stop_serial_device()
2213 tiocmget = serial->tiocmget; in hso_stop_serial_device()
2215 wake_up_interruptible(&tiocmget->waitq); in hso_stop_serial_device()
2216 usb_kill_urb(tiocmget->urb); in hso_stop_serial_device()
2222 static void hso_serial_tty_unregister(struct hso_serial *serial) in hso_serial_tty_unregister() argument
2224 tty_unregister_device(tty_drv, serial->minor); in hso_serial_tty_unregister()
2225 release_minor(serial); in hso_serial_tty_unregister()
2228 static void hso_serial_common_free(struct hso_serial *serial) in hso_serial_common_free() argument
2232 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_serial_common_free()
2234 usb_free_urb(serial->rx_urb[i]); in hso_serial_common_free()
2236 kfree(serial->rx_data[i]); in hso_serial_common_free()
2240 usb_free_urb(serial->tx_urb); in hso_serial_common_free()
2241 kfree(serial->tx_buffer); in hso_serial_common_free()
2242 kfree(serial->tx_data); in hso_serial_common_free()
2243 tty_port_destroy(&serial->port); in hso_serial_common_free()
2246 static int hso_serial_common_create(struct hso_serial *serial, int num_urbs, in hso_serial_common_create() argument
2251 tty_port_init(&serial->port); in hso_serial_common_create()
2253 if (obtain_minor(serial)) in hso_serial_common_create()
2257 serial->parent->dev = tty_port_register_device_attr(&serial->port, in hso_serial_common_create()
2258 tty_drv, serial->minor, &serial->parent->interface->dev, in hso_serial_common_create()
2259 serial->parent, hso_serial_dev_groups); in hso_serial_common_create()
2260 if (IS_ERR(serial->parent->dev)) { in hso_serial_common_create()
2261 release_minor(serial); in hso_serial_common_create()
2265 serial->magic = HSO_SERIAL_MAGIC; in hso_serial_common_create()
2266 spin_lock_init(&serial->serial_lock); in hso_serial_common_create()
2267 serial->num_rx_urbs = num_urbs; in hso_serial_common_create()
2272 serial->rx_data_length = rx_size; in hso_serial_common_create()
2273 for (i = 0; i < serial->num_rx_urbs; i++) { in hso_serial_common_create()
2274 serial->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL); in hso_serial_common_create()
2275 if (!serial->rx_urb[i]) in hso_serial_common_create()
2277 serial->rx_urb[i]->transfer_buffer = NULL; in hso_serial_common_create()
2278 serial->rx_urb[i]->transfer_buffer_length = 0; in hso_serial_common_create()
2279 serial->rx_data[i] = kzalloc(serial->rx_data_length, in hso_serial_common_create()
2281 if (!serial->rx_data[i]) in hso_serial_common_create()
2286 serial->tx_urb = usb_alloc_urb(0, GFP_KERNEL); in hso_serial_common_create()
2287 if (!serial->tx_urb) in hso_serial_common_create()
2289 serial->tx_urb->transfer_buffer = NULL; in hso_serial_common_create()
2290 serial->tx_urb->transfer_buffer_length = 0; in hso_serial_common_create()
2292 serial->tx_data_count = 0; in hso_serial_common_create()
2293 serial->tx_buffer_count = 0; in hso_serial_common_create()
2294 serial->tx_data_length = tx_size; in hso_serial_common_create()
2295 serial->tx_data = kzalloc(serial->tx_data_length, GFP_KERNEL); in hso_serial_common_create()
2296 if (!serial->tx_data) in hso_serial_common_create()
2299 serial->tx_buffer = kzalloc(serial->tx_data_length, GFP_KERNEL); in hso_serial_common_create()
2300 if (!serial->tx_buffer) in hso_serial_common_create()
2305 hso_serial_tty_unregister(serial); in hso_serial_common_create()
2307 hso_serial_common_free(serial); in hso_serial_common_create()
2308 return -1; in hso_serial_common_create()
2321 hso_dev->port_spec = port_spec; in hso_create_device()
2322 hso_dev->usb = interface_to_usbdev(intf); in hso_create_device()
2323 hso_dev->interface = intf; in hso_create_device()
2324 kref_init(&hso_dev->ref); in hso_create_device()
2325 mutex_init(&hso_dev->mutex); in hso_create_device()
2327 INIT_WORK(&hso_dev->async_get_intf, async_get_intf); in hso_create_device()
2328 INIT_WORK(&hso_dev->async_put_intf, async_put_intf); in hso_create_device()
2345 return -1; in remove_net_device()
2358 remove_net_device(hso_net->parent); in hso_free_net_device()
2360 if (hso_net->net) in hso_free_net_device()
2361 unregister_netdev(hso_net->net); in hso_free_net_device()
2365 usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]); in hso_free_net_device()
2366 kfree(hso_net->mux_bulk_rx_buf_pool[i]); in hso_free_net_device()
2367 hso_net->mux_bulk_rx_buf_pool[i] = NULL; in hso_free_net_device()
2369 usb_free_urb(hso_net->mux_bulk_tx_urb); in hso_free_net_device()
2370 kfree(hso_net->mux_bulk_tx_buf); in hso_free_net_device()
2371 hso_net->mux_bulk_tx_buf = NULL; in hso_free_net_device()
2373 if (hso_net->net) in hso_free_net_device()
2374 free_netdev(hso_net->net); in hso_free_net_device()
2394 net->netdev_ops = &hso_netdev_ops; in hso_net_init()
2395 net->watchdog_timeo = HSO_NET_TX_TIMEOUT; in hso_net_init()
2396 net->flags = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST; in hso_net_init()
2397 net->type = ARPHRD_NONE; in hso_net_init()
2398 net->mtu = DEFAULT_MTU - 14; in hso_net_init()
2399 net->tx_queue_len = 10; in hso_net_init()
2400 net->ethtool_ops = &ops; in hso_net_init()
2403 spin_lock_init(&hso_net->net_lock); in hso_net_init()
2418 return -1; in add_net_device()
2428 mutex_lock(&hso_dev->mutex); in hso_rfkill_set_block()
2429 if (hso_dev->usb_gone) in hso_rfkill_set_block()
2432 rv = usb_control_msg(hso_dev->usb, usb_sndctrlpipe(hso_dev->usb, 0), in hso_rfkill_set_block()
2435 mutex_unlock(&hso_dev->mutex); in hso_rfkill_set_block()
2448 struct device *dev = &hso_net->net->dev; in hso_create_rfkill()
2451 snprintf(hso_net->name, sizeof(hso_net->name), "hso-%d", in hso_create_rfkill()
2454 hso_net->rfkill = rfkill_alloc(hso_net->name, in hso_create_rfkill()
2455 &interface_to_usbdev(interface)->dev, in hso_create_rfkill()
2458 if (!hso_net->rfkill) in hso_create_rfkill()
2461 if (rfkill_register(hso_net->rfkill) < 0) { in hso_create_rfkill()
2462 rfkill_destroy(hso_net->rfkill); in hso_create_rfkill()
2463 hso_net->rfkill = NULL; in hso_create_rfkill()
2464 dev_err(dev, "%s - Failed to register rfkill\n", __func__); in hso_create_rfkill()
2487 /* call hso_net_init to do the basic initialization */ in hso_create_net_device()
2491 dev_err(&interface->dev, "Unable to create ethernet device\n"); in hso_create_net_device()
2497 hso_dev->port_data.dev_net = hso_net; in hso_create_net_device()
2498 hso_net->net = net; in hso_create_net_device()
2499 hso_net->parent = hso_dev; in hso_create_net_device()
2501 hso_net->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, in hso_create_net_device()
2503 if (!hso_net->in_endp) { in hso_create_net_device()
2504 dev_err(&interface->dev, "Can't find BULK IN endpoint\n"); in hso_create_net_device()
2507 hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, in hso_create_net_device()
2509 if (!hso_net->out_endp) { in hso_create_net_device()
2510 dev_err(&interface->dev, "Can't find BULK OUT endpoint\n"); in hso_create_net_device()
2513 SET_NETDEV_DEV(net, &interface->dev); in hso_create_net_device()
2518 hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL); in hso_create_net_device()
2519 if (!hso_net->mux_bulk_rx_urb_pool[i]) in hso_create_net_device()
2521 hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE, in hso_create_net_device()
2523 if (!hso_net->mux_bulk_rx_buf_pool[i]) in hso_create_net_device()
2526 hso_net->mux_bulk_tx_urb = usb_alloc_urb(0, GFP_KERNEL); in hso_create_net_device()
2527 if (!hso_net->mux_bulk_tx_urb) in hso_create_net_device()
2529 hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL); in hso_create_net_device()
2530 if (!hso_net->mux_bulk_tx_buf) in hso_create_net_device()
2535 dev_err(&interface->dev, "Failed to add net device\n"); in hso_create_net_device()
2542 dev_err(&interface->dev, "Failed to register device\n"); in hso_create_net_device()
2555 kfree(hso_net->mux_bulk_tx_buf); in hso_create_net_device()
2557 usb_free_urb(hso_net->mux_bulk_tx_urb); in hso_create_net_device()
2560 usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]); in hso_create_net_device()
2561 kfree(hso_net->mux_bulk_rx_buf_pool[i]); in hso_create_net_device()
2570 static void hso_free_tiomget(struct hso_serial *serial) in hso_free_tiomget() argument
2573 if (!serial) in hso_free_tiomget()
2575 tiocmget = serial->tiocmget; in hso_free_tiomget()
2577 usb_free_urb(tiocmget->urb); in hso_free_tiomget()
2578 tiocmget->urb = NULL; in hso_free_tiomget()
2579 serial->tiocmget = NULL; in hso_free_tiomget()
2580 kfree(tiocmget->serial_state_notification); in hso_free_tiomget()
2581 tiocmget->serial_state_notification = NULL; in hso_free_tiomget()
2586 /* Frees an AT channel ( goes for both mux and non-mux ) */
2589 struct hso_serial *serial = dev2ser(hso_dev); in hso_free_serial_device() local
2591 if (!serial) in hso_free_serial_device()
2594 hso_serial_common_free(serial); in hso_free_serial_device()
2596 if (serial->shared_int) { in hso_free_serial_device()
2597 mutex_lock(&serial->shared_int->shared_int_lock); in hso_free_serial_device()
2598 if (--serial->shared_int->ref_count == 0) in hso_free_serial_device()
2599 hso_free_shared_int(serial->shared_int); in hso_free_serial_device()
2601 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_free_serial_device()
2603 hso_free_tiomget(serial); in hso_free_serial_device()
2604 kfree(serial); in hso_free_serial_device()
2613 struct hso_serial *serial; in hso_create_bulk_serial_device() local
2621 serial = kzalloc(sizeof(*serial), GFP_KERNEL); in hso_create_bulk_serial_device()
2622 if (!serial) in hso_create_bulk_serial_device()
2625 serial->parent = hso_dev; in hso_create_bulk_serial_device()
2626 hso_dev->port_data.dev_serial = serial; in hso_create_bulk_serial_device()
2630 serial->tiocmget = kzalloc(sizeof(struct hso_tiocmget), in hso_create_bulk_serial_device()
2632 if (!serial->tiocmget) in hso_create_bulk_serial_device()
2634 serial->tiocmget->serial_state_notification in hso_create_bulk_serial_device()
2637 if (!serial->tiocmget->serial_state_notification) in hso_create_bulk_serial_device()
2639 tiocmget = serial->tiocmget; in hso_create_bulk_serial_device()
2640 tiocmget->endp = hso_get_ep(interface, in hso_create_bulk_serial_device()
2643 if (!tiocmget->endp) { in hso_create_bulk_serial_device()
2644 dev_err(&interface->dev, "Failed to find INT IN ep\n"); in hso_create_bulk_serial_device()
2648 tiocmget->urb = usb_alloc_urb(0, GFP_KERNEL); in hso_create_bulk_serial_device()
2649 if (!tiocmget->urb) in hso_create_bulk_serial_device()
2652 mutex_init(&tiocmget->mutex); in hso_create_bulk_serial_device()
2653 init_waitqueue_head(&tiocmget->waitq); in hso_create_bulk_serial_device()
2658 if (hso_serial_common_create(serial, num_urbs, BULK_URB_RX_SIZE, in hso_create_bulk_serial_device()
2662 serial->in_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, in hso_create_bulk_serial_device()
2664 if (!serial->in_endp) { in hso_create_bulk_serial_device()
2665 dev_err(&interface->dev, "Failed to find BULK IN ep\n"); in hso_create_bulk_serial_device()
2670 (serial->out_endp = in hso_create_bulk_serial_device()
2672 dev_err(&interface->dev, "Failed to find BULK OUT ep\n"); in hso_create_bulk_serial_device()
2676 serial->write_data = hso_std_serial_write_data; in hso_create_bulk_serial_device()
2685 hso_serial_tty_unregister(serial); in hso_create_bulk_serial_device()
2686 hso_serial_common_free(serial); in hso_create_bulk_serial_device()
2688 hso_free_tiomget(serial); in hso_create_bulk_serial_device()
2689 kfree(serial); in hso_create_bulk_serial_device()
2701 struct hso_serial *serial; in hso_create_mux_serial_device() local
2715 serial = kzalloc(sizeof(*serial), GFP_KERNEL); in hso_create_mux_serial_device()
2716 if (!serial) in hso_create_mux_serial_device()
2719 hso_dev->port_data.dev_serial = serial; in hso_create_mux_serial_device()
2720 serial->parent = hso_dev; in hso_create_mux_serial_device()
2723 (serial, 1, CTRL_URB_RX_SIZE, CTRL_URB_TX_SIZE)) in hso_create_mux_serial_device()
2726 serial->tx_data_length--; in hso_create_mux_serial_device()
2727 serial->write_data = hso_mux_serial_write_data; in hso_create_mux_serial_device()
2729 serial->shared_int = mux; in hso_create_mux_serial_device()
2730 mutex_lock(&serial->shared_int->shared_int_lock); in hso_create_mux_serial_device()
2731 serial->shared_int->ref_count++; in hso_create_mux_serial_device()
2732 mutex_unlock(&serial->shared_int->shared_int_lock); in hso_create_mux_serial_device()
2741 kfree(serial); in hso_create_mux_serial_device()
2750 usb_free_urb(mux->shared_intr_urb); in hso_free_shared_int()
2751 kfree(mux->shared_intr_buf); in hso_free_shared_int()
2752 mutex_unlock(&mux->shared_int_lock); in hso_free_shared_int()
2764 mux->intr_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_INT, in hso_create_shared_int()
2766 if (!mux->intr_endp) { in hso_create_shared_int()
2767 dev_err(&interface->dev, "Can't find INT IN endpoint\n"); in hso_create_shared_int()
2771 mux->shared_intr_urb = usb_alloc_urb(0, GFP_KERNEL); in hso_create_shared_int()
2772 if (!mux->shared_intr_urb) in hso_create_shared_int()
2774 mux->shared_intr_buf = in hso_create_shared_int()
2775 kzalloc(le16_to_cpu(mux->intr_endp->wMaxPacketSize), in hso_create_shared_int()
2777 if (!mux->shared_intr_buf) in hso_create_shared_int()
2780 mutex_init(&mux->shared_int_lock); in hso_create_shared_int()
2785 kfree(mux->shared_intr_buf); in hso_create_shared_int()
2786 usb_free_urb(mux->shared_intr_urb); in hso_create_shared_int()
2796 u32 if_num = interface->cur_altsetting->desc.bInterfaceNumber; in hso_get_config_data()
2800 return -ENOMEM; in hso_get_config_data()
2805 return -EIO; in hso_get_config_data()
2811 return -EINVAL; in hso_get_config_data()
2875 if (interface->cur_altsetting->desc.bInterfaceClass != 0xFF) { in hso_probe()
2876 dev_err(&interface->dev, "Not our interface\n"); in hso_probe()
2877 return -ENODEV; in hso_probe()
2880 if_num = interface->cur_altsetting->desc.bInterfaceNumber; in hso_probe()
2884 if (id->driver_info) { in hso_probe()
2888 if (((u32 *)(id->driver_info))[i] == 0) in hso_probe()
2890 port_spec = ((u32 *)(id->driver_info))[if_num]; in hso_probe()
2897 /* Check if we need to switch to alt interfaces prior to port in hso_probe()
2899 if (interface->num_altsetting > 1) in hso_probe()
2901 interface->needs_remote_wakeup = 1; in hso_probe()
2918 /* TODO: de-allocate everything */ in hso_probe()
2962 return -ENODEV; in hso_probe()
2978 usb_autopm_get_interface(hso_dev->interface); in async_get_intf()
2985 usb_autopm_put_interface(hso_dev->interface); in async_put_intf()
2990 if (hso_dev->usb->state == USB_STATE_SUSPENDED) { in hso_get_activity()
2991 if (!hso_dev->is_active) { in hso_get_activity()
2992 hso_dev->is_active = 1; in hso_get_activity()
2993 schedule_work(&hso_dev->async_get_intf); in hso_get_activity()
2997 if (hso_dev->usb->state != USB_STATE_CONFIGURED) in hso_get_activity()
2998 return -EAGAIN; in hso_get_activity()
3000 usb_mark_last_busy(hso_dev->usb); in hso_get_activity()
3007 if (hso_dev->usb->state != USB_STATE_SUSPENDED) { in hso_put_activity()
3008 if (hso_dev->is_active) { in hso_put_activity()
3009 hso_dev->is_active = 0; in hso_put_activity()
3010 schedule_work(&hso_dev->async_put_intf); in hso_put_activity()
3011 return -EAGAIN; in hso_put_activity()
3014 hso_dev->is_active = 0; in hso_put_activity()
3018 /* called by kernel when we need to suspend device */
3023 /* Stop all serial ports */ in hso_suspend()
3025 if (serial_table[i] && (serial_table[i]->interface == iface)) { in hso_suspend()
3035 (network_table[i]->interface == iface)) { in hso_suspend()
3046 /* called by kernel when we need to resume device */
3052 /* Start all serial ports */ in hso_resume()
3054 if (serial_table[i] && (serial_table[i]->interface == iface)) { in hso_resume()
3055 if (dev2ser(serial_table[i])->port.count) { in hso_resume()
3068 (network_table[i]->interface == iface)) { in hso_resume()
3070 if (hso_net->flags & IFF_UP) { in hso_resume()
3073 if (hso_net->skb_tx_buf) { in hso_resume()
3074 dev_dbg(&iface->dev, in hso_resume()
3077 hso_net_start_xmit(hso_net->skb_tx_buf, in hso_resume()
3078 hso_net->net); in hso_resume()
3079 hso_net->skb_tx_buf = NULL; in hso_resume()
3101 struct hso_serial *serial; in hso_free_interface() local
3106 (serial_table[i]->interface == interface)) { in hso_free_interface()
3107 serial = dev2ser(serial_table[i]); in hso_free_interface()
3108 tty_port_tty_hangup(&serial->port, false); in hso_free_interface()
3109 mutex_lock(&serial->parent->mutex); in hso_free_interface()
3110 serial->parent->usb_gone = 1; in hso_free_interface()
3111 mutex_unlock(&serial->parent->mutex); in hso_free_interface()
3112 cancel_work_sync(&serial_table[i]->async_put_intf); in hso_free_interface()
3113 cancel_work_sync(&serial_table[i]->async_get_intf); in hso_free_interface()
3114 hso_serial_tty_unregister(serial); in hso_free_interface()
3115 kref_put(&serial->parent->ref, hso_serial_ref_free); in hso_free_interface()
3121 (network_table[i]->interface == interface)) { in hso_free_interface()
3122 struct rfkill *rfk = dev2net(network_table[i])->rfkill; in hso_free_interface()
3124 * traffic needs to start it again when suspended */ in hso_free_interface()
3125 netif_stop_queue(dev2net(network_table[i])->net); in hso_free_interface()
3127 cancel_work_sync(&network_table[i]->async_put_intf); in hso_free_interface()
3128 cancel_work_sync(&network_table[i]->async_get_intf); in hso_free_interface()
3145 struct usb_host_interface *iface = intf->cur_altsetting; in hso_get_ep()
3148 for (i = 0; i < iface->desc.bNumEndpoints; i++) { in hso_get_ep()
3149 endp = &iface->endpoint[i].desc; in hso_get_ep()
3150 if (((endp->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == dir) && in hso_get_ep()
3162 struct usb_host_interface *iface = intf->cur_altsetting; in hso_get_mux_ports()
3164 if (iface->extralen == 3) { in hso_get_mux_ports()
3165 *ports = iface->extra[2]; in hso_get_mux_ports()
3169 for (i = 0; i < iface->desc.bNumEndpoints; i++) { in hso_get_mux_ports()
3170 if (iface->endpoint[i].extralen == 3) { in hso_get_mux_ports()
3171 *ports = iface->endpoint[i].extra[2]; in hso_get_mux_ports()
3176 return -1; in hso_get_mux_ports()
3179 /* interrupt urb needs to be submitted, used for serial read of muxed port */
3181 struct usb_device *usb, gfp_t gfp) in hso_mux_submit_intr_urb() argument
3185 usb_fill_int_urb(shared_int->shared_intr_urb, usb, in hso_mux_submit_intr_urb()
3186 usb_rcvintpipe(usb, in hso_mux_submit_intr_urb()
3187 shared_int->intr_endp->bEndpointAddress & 0x7F), in hso_mux_submit_intr_urb()
3188 shared_int->shared_intr_buf, in hso_mux_submit_intr_urb()
3191 shared_int->intr_endp->bInterval); in hso_mux_submit_intr_urb()
3193 result = usb_submit_urb(shared_int->shared_intr_urb, gfp); in hso_mux_submit_intr_urb()
3195 dev_warn(&usb->dev, "%s failed mux_intr_urb %d\n", __func__, in hso_mux_submit_intr_urb()
3201 /* operations setup of the serial interface */
3237 /* Initialise the serial table semaphore and table */ in hso_init()
3248 tty_drv->driver_name = driver_name; in hso_init()
3249 tty_drv->name = tty_filename; in hso_init()
3253 tty_drv->major = tty_major; in hso_init()
3255 tty_drv->minor_start = 0; in hso_init()
3256 tty_drv->type = TTY_DRIVER_TYPE_SERIAL; in hso_init()
3257 tty_drv->subtype = SERIAL_TYPE_NORMAL; in hso_init()
3258 tty_drv->init_termios = tty_std_termios; in hso_init()
3259 hso_init_termios(&tty_drv->init_termios); in hso_init()
3265 pr_err("%s - tty_register_driver failed(%d)\n", in hso_init()
3270 /* register this module as an usb driver */ in hso_init()
3273 pr_err("Could not register hso driver - error: %d\n", result); in hso_init()
3291 /* deregister the usb driver */ in hso_exit()