diff options
-rw-r--r-- | drivers/staging/quatech_usb2/quatech_usb2.c | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/drivers/staging/quatech_usb2/quatech_usb2.c b/drivers/staging/quatech_usb2/quatech_usb2.c index b06e90d3cef..deb222c7186 100644 --- a/drivers/staging/quatech_usb2/quatech_usb2.c +++ b/drivers/staging/quatech_usb2/quatech_usb2.c | |||
@@ -163,7 +163,7 @@ static struct usb_driver quausb2_usb_driver = { | |||
163 | * each time a write urb is dispatched. | 163 | * each time a write urb is dispatched. |
164 | * - is decremented each time a "transmit empty" message is received | 164 | * - is decremented each time a "transmit empty" message is received |
165 | * by the driver in the data stream. | 165 | * by the driver in the data stream. |
166 | * @sem: Semaphore to lock access to this structure when we need to ensure that | 166 | * @lock: Mutex to lock access to this structure when we need to ensure that |
167 | * races don't occur to access bits of it. | 167 | * races don't occur to access bits of it. |
168 | * @open_count: The number of uses of the port currently having | 168 | * @open_count: The number of uses of the port currently having |
169 | * it open, i.e. the reference count. | 169 | * it open, i.e. the reference count. |
@@ -177,13 +177,12 @@ struct quatech2_port { | |||
177 | bool rcv_flush; | 177 | bool rcv_flush; |
178 | bool xmit_flush; | 178 | bool xmit_flush; |
179 | int tx_pending_bytes; | 179 | int tx_pending_bytes; |
180 | struct semaphore sem; | 180 | struct mutex modelock; |
181 | int open_count; | 181 | int open_count; |
182 | 182 | ||
183 | char active; /* someone has this device open */ | 183 | char active; /* someone has this device open */ |
184 | unsigned char *xfer_to_tty_buffer; | 184 | unsigned char *xfer_to_tty_buffer; |
185 | wait_queue_head_t wait; | 185 | wait_queue_head_t wait; |
186 | |||
187 | __u8 shadowLCR; /* last LCR value received */ | 186 | __u8 shadowLCR; /* last LCR value received */ |
188 | __u8 shadowMCR; /* last MCR value received */ | 187 | __u8 shadowMCR; /* last MCR value received */ |
189 | char RxHolding; | 188 | char RxHolding; |
@@ -263,11 +262,6 @@ static int qt2_box_flush(struct usb_serial *serial, unsigned char uart_number, | |||
263 | unsigned short rcv_or_xmit); | 262 | unsigned short rcv_or_xmit); |
264 | static int qt2_boxsetuart(struct usb_serial *serial, unsigned short Uart_Number, | 263 | static int qt2_boxsetuart(struct usb_serial *serial, unsigned short Uart_Number, |
265 | unsigned short default_divisor, unsigned char default_LCR); | 264 | unsigned short default_divisor, unsigned char default_LCR); |
266 | /*static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port, | ||
267 | const unsigned char *buf, int count); | ||
268 | static int qt2_tiocmget(struct tty_struct *tty, struct file *file); | ||
269 | static int qt2_tiocmset(struct tty_struct *tty, struct file *file, | ||
270 | unsigned int set, unsigned int clear);*/ | ||
271 | static int qt2_boxsethw_flowctl(struct usb_serial *serial, | 265 | static int qt2_boxsethw_flowctl(struct usb_serial *serial, |
272 | unsigned int UartNumber, bool bSet); | 266 | unsigned int UartNumber, bool bSet); |
273 | static int qt2_boxsetsw_flowctl(struct usb_serial *serial, __u16 UartNumber, | 267 | static int qt2_boxsetsw_flowctl(struct usb_serial *serial, __u16 UartNumber, |
@@ -356,6 +350,7 @@ static int qt2_attach(struct usb_serial *serial) | |||
356 | /* initialise stuff in the structure */ | 350 | /* initialise stuff in the structure */ |
357 | qt2_port->open_count = 0; /* port is not open */ | 351 | qt2_port->open_count = 0; /* port is not open */ |
358 | spin_lock_init(&qt2_port->lock); | 352 | spin_lock_init(&qt2_port->lock); |
353 | mutex_init(&qt2_port->modelock); | ||
359 | qt2_set_port_private(port, qt2_port); | 354 | qt2_set_port_private(port, qt2_port); |
360 | } | 355 | } |
361 | 356 | ||
@@ -535,7 +530,6 @@ int qt2_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
535 | * Finally we need a bulk in URB to use for background reads from the | 530 | * Finally we need a bulk in URB to use for background reads from the |
536 | * device, which will deal with uplink data from the box to host. | 531 | * device, which will deal with uplink data from the box to host. |
537 | */ | 532 | */ |
538 | dbg("serial number is %d", port->serial->minor); | ||
539 | dbg("port0 bulk in endpoint is %#.2x", port0->bulk_in_endpointAddress); | 533 | dbg("port0 bulk in endpoint is %#.2x", port0->bulk_in_endpointAddress); |
540 | dbg("port0 bulk out endpoint is %#.2x", | 534 | dbg("port0 bulk out endpoint is %#.2x", |
541 | port0->bulk_out_endpointAddress); | 535 | port0->bulk_out_endpointAddress); |
@@ -700,7 +694,12 @@ static void qt2_close(struct usb_serial_port *port) | |||
700 | dev_extra->open_ports); | 694 | dev_extra->open_ports); |
701 | } | 695 | } |
702 | 696 | ||
703 | /* called to deliver writes from the next layer up to the device */ | 697 | /** |
698 | * qt2_write - write bytes from the tty layer out to the USB device. | ||
699 | * @buf: The data to be written, size at least count. | ||
700 | * @count: The number of bytes requested for transmission. | ||
701 | * @return The number of bytes actually accepted for transmission to the device. | ||
702 | */ | ||
704 | static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port, | 703 | static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port, |
705 | const unsigned char *buf, int count) | 704 | const unsigned char *buf, int count) |
706 | { | 705 | { |
@@ -708,20 +707,19 @@ static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
708 | __u8 header_array[5]; /* header used to direct writes to the correct | 707 | __u8 header_array[5]; /* header used to direct writes to the correct |
709 | port on the device */ | 708 | port on the device */ |
710 | struct quatech2_port *port_extra; /* extra data for this port */ | 709 | struct quatech2_port *port_extra; /* extra data for this port */ |
711 | |||
712 | int result; | 710 | int result; |
713 | 711 | ||
714 | /* get the parent device of the port */ | 712 | serial = port->serial; /* get the parent device of the port */ |
715 | serial = port->serial; | 713 | port_extra = qt2_get_port_private(port); /* port extra info */ |
716 | if (serial == NULL) | 714 | if (serial == NULL) |
717 | return -ENODEV; | 715 | return -ENODEV; |
718 | dbg("%s(): port %d", __func__, port->number); | 716 | dbg("%s(): port %d, requested to write %d bytes, %d already pending", |
717 | __func__, port->number, count, port_extra->tx_pending_bytes); | ||
719 | 718 | ||
720 | if (count <= 0) { | 719 | if (count <= 0) { |
721 | dbg("%s(): write request of <= 0 bytes", __func__); | 720 | dbg("%s(): write request of <= 0 bytes", __func__); |
722 | return 0; /* no bytes written */ | 721 | return 0; /* no bytes written */ |
723 | } | 722 | } |
724 | port_extra = qt2_get_port_private(port); | ||
725 | 723 | ||
726 | /* check if the write urb is already in use, i.e. data already being | 724 | /* check if the write urb is already in use, i.e. data already being |
727 | * sent to this port */ | 725 | * sent to this port */ |
@@ -747,13 +745,19 @@ static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
747 | * the maximum we will ever write to the device as 5 bytes less than | 745 | * the maximum we will ever write to the device as 5 bytes less than |
748 | * one URB's worth, by reducing the value of the count argument | 746 | * one URB's worth, by reducing the value of the count argument |
749 | * appropriately*/ | 747 | * appropriately*/ |
750 | if (count > port->bulk_out_size - QT2_TX_HEADER_LENGTH) | 748 | if (count > port->bulk_out_size - QT2_TX_HEADER_LENGTH) { |
751 | count = port->bulk_out_size - QT2_TX_HEADER_LENGTH; | 749 | count = port->bulk_out_size - QT2_TX_HEADER_LENGTH; |
750 | dbg("%s(): write request bigger than urb, only accepting " | ||
751 | "%d bytes", __func__, count); | ||
752 | } | ||
752 | /* we must also ensure that the FIFO at the other end can cope with the | 753 | /* we must also ensure that the FIFO at the other end can cope with the |
753 | * URB we send it, otherwise it will have problems. As above, we can | 754 | * URB we send it, otherwise it will have problems. As above, we can |
754 | * restrict the write size by just shrinking count.*/ | 755 | * restrict the write size by just shrinking count.*/ |
755 | if (count > (QT2_FIFO_DEPTH - port_extra->tx_pending_bytes)) | 756 | if (count > (QT2_FIFO_DEPTH - port_extra->tx_pending_bytes)) { |
756 | count = QT2_FIFO_DEPTH - port_extra->tx_pending_bytes; | 757 | count = QT2_FIFO_DEPTH - port_extra->tx_pending_bytes; |
758 | dbg("%s(): not enough room in buffer, only accepting %d bytes", | ||
759 | __func__, count); | ||
760 | } | ||
757 | /* now build the header for transmission */ | 761 | /* now build the header for transmission */ |
758 | header_array[0] = 0x1b; | 762 | header_array[0] = 0x1b; |
759 | header_array[1] = 0x1b; | 763 | header_array[1] = 0x1b; |
@@ -778,17 +782,15 @@ static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
778 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | 782 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
779 | if (result) { | 783 | if (result) { |
780 | /* error couldn't submit urb */ | 784 | /* error couldn't submit urb */ |
781 | result = 0; | 785 | result = 0; /* return 0 as nothing got written */ |
782 | dbg("%s(): failed submitting write urb, error %d", | 786 | dbg("%s(): failed submitting write urb, error %d", |
783 | __func__, result); | 787 | __func__, result); |
784 | } else { | 788 | } else { |
785 | port_extra->tx_pending_bytes += (count - QT2_TX_HEADER_LENGTH); | 789 | port_extra->tx_pending_bytes += count; |
786 | /*port->fifo_empty_flag = false; | 790 | result = count; /* return number of bytes written, i.e. count */ |
787 | port->xmit_fifo_room_bytes = FIFO_DEPTH - | 791 | dbg("%s(): submitted write urb, wrote %d bytes, " |
788 | port->xmit_pending_bytes;*/ | 792 | "total pending bytes %d", |
789 | result = count; | 793 | __func__, result, port_extra->tx_pending_bytes); |
790 | dbg("%s(): submitted write urb, returning %d", | ||
791 | __func__, result); | ||
792 | } | 794 | } |
793 | return result; | 795 | return result; |
794 | } | 796 | } |
@@ -1178,7 +1180,7 @@ static void qt2_break(struct tty_struct *tty, int break_state) | |||
1178 | dbg("%s(): port %d, break_value %d", __func__, port->number, | 1180 | dbg("%s(): port %d, break_value %d", __func__, port->number, |
1179 | break_value); | 1181 | break_value); |
1180 | 1182 | ||
1181 | down(&port_extra->sem); | 1183 | mutex_lock(&port_extra->modelock); |
1182 | if (!port_extra->open_count) { | 1184 | if (!port_extra->open_count) { |
1183 | dbg("%s(): port not open", __func__); | 1185 | dbg("%s(): port not open", __func__); |
1184 | goto exit; | 1186 | goto exit; |
@@ -1188,7 +1190,7 @@ static void qt2_break(struct tty_struct *tty, int break_state) | |||
1188 | QT2_BREAK_CONTROL, 0x40, break_value, | 1190 | QT2_BREAK_CONTROL, 0x40, break_value, |
1189 | port->number, NULL, 0, 300); | 1191 | port->number, NULL, 0, 300); |
1190 | exit: | 1192 | exit: |
1191 | up(&port_extra->sem); | 1193 | mutex_unlock(&port_extra->modelock); |
1192 | dbg("%s(): exit port %d", __func__, port->number); | 1194 | dbg("%s(): exit port %d", __func__, port->number); |
1193 | 1195 | ||
1194 | } | 1196 | } |
@@ -1209,7 +1211,7 @@ static void qt2_throttle(struct tty_struct *tty) | |||
1209 | return; | 1211 | return; |
1210 | } | 1212 | } |
1211 | 1213 | ||
1212 | down(&port_extra->sem); /* lock structure */ | 1214 | mutex_lock(&port_extra->modelock); /* lock structure */ |
1213 | if (!port_extra->open_count) { | 1215 | if (!port_extra->open_count) { |
1214 | dbg("%s(): port not open", __func__); | 1216 | dbg("%s(): port not open", __func__); |
1215 | goto exit; | 1217 | goto exit; |
@@ -1224,7 +1226,7 @@ static void qt2_throttle(struct tty_struct *tty) | |||
1224 | 1226 | ||
1225 | port->throttled = 1; | 1227 | port->throttled = 1; |
1226 | exit: | 1228 | exit: |
1227 | up(&port_extra->sem); | 1229 | mutex_unlock(&port_extra->modelock); |
1228 | dbg("%s(): port %d: setting port->throttled", __func__, port->number); | 1230 | dbg("%s(): port %d: setting port->throttled", __func__, port->number); |
1229 | return; | 1231 | return; |
1230 | } | 1232 | } |
@@ -1251,7 +1253,7 @@ static void qt2_unthrottle(struct tty_struct *tty) | |||
1251 | port_extra = qt2_get_port_private(port); | 1253 | port_extra = qt2_get_port_private(port); |
1252 | port0 = serial->port[0]; /* get the first port's device structure */ | 1254 | port0 = serial->port[0]; /* get the first port's device structure */ |
1253 | 1255 | ||
1254 | down(&port_extra->sem); | 1256 | mutex_lock(&port_extra->modelock); |
1255 | if (!port_extra->open_count) { | 1257 | if (!port_extra->open_count) { |
1256 | dbg("%s(): port %d not open", __func__, port->number); | 1258 | dbg("%s(): port %d not open", __func__, port->number); |
1257 | goto exit; | 1259 | goto exit; |
@@ -1275,7 +1277,7 @@ static void qt2_unthrottle(struct tty_struct *tty) | |||
1275 | } | 1277 | } |
1276 | } | 1278 | } |
1277 | exit: | 1279 | exit: |
1278 | up(&port_extra->sem); | 1280 | mutex_unlock(&port_extra->modelock); |
1279 | dbg("%s(): exit port %d", __func__, port->number); | 1281 | dbg("%s(): exit port %d", __func__, port->number); |
1280 | return; | 1282 | return; |
1281 | } | 1283 | } |
@@ -1442,9 +1444,8 @@ static void qt2_read_bulk_callback(struct urb *urb) | |||
1442 | bool escapeflag; /* flag set to true if this loop iteration is | 1444 | bool escapeflag; /* flag set to true if this loop iteration is |
1443 | * parsing an escape sequence, rather than | 1445 | * parsing an escape sequence, rather than |
1444 | * ordinary data */ | 1446 | * ordinary data */ |
1445 | 1447 | dbg("%s(): callback running, active port is %d", __func__, | |
1446 | 1448 | active->number); | |
1447 | dbg("%s(): callback running", __func__); | ||
1448 | 1449 | ||
1449 | if (urb->status) { | 1450 | if (urb->status) { |
1450 | /* read didn't go well */ | 1451 | /* read didn't go well */ |
@@ -1502,7 +1503,7 @@ __func__); | |||
1502 | /* single port device, input is already stopped, so we don't | 1503 | /* single port device, input is already stopped, so we don't |
1503 | * need any more input data */ | 1504 | * need any more input data */ |
1504 | dev_extra->ReadBulkStopped = true; | 1505 | dev_extra->ReadBulkStopped = true; |
1505 | return; | 1506 | return; |
1506 | } | 1507 | } |
1507 | /* finally, we are in a situation where we might consider the data | 1508 | /* finally, we are in a situation where we might consider the data |
1508 | * that is contained within the URB, and what to do about it. | 1509 | * that is contained within the URB, and what to do about it. |
@@ -1512,14 +1513,12 @@ __func__); | |||
1512 | 1513 | ||
1513 | /* active is a usb_serial_port. It has a member port which is a | 1514 | /* active is a usb_serial_port. It has a member port which is a |
1514 | * tty_port. From this we get a tty_struct pointer which is what we | 1515 | * tty_port. From this we get a tty_struct pointer which is what we |
1515 | * actually wanted, and keep it on tty_st */ | 1516 | * actually wanted, and keep it on tty_st */ |
1516 | tty_st = tty_port_tty_get(&active->port); | 1517 | tty_st = tty_port_tty_get(&active->port); |
1517 | if (!tty_st) { | 1518 | if (!tty_st) { |
1518 | dbg("%s - bad tty pointer - exiting", __func__); | 1519 | dbg("%s - bad tty pointer - exiting", __func__); |
1519 | return; | 1520 | return; |
1520 | } | 1521 | } |
1521 | dbg("%s(): active port %d, tty_st =0x%p\n", __func__, active->number, | ||
1522 | tty_st); | ||
1523 | RxCount = urb->actual_length; /* grab length of data handy */ | 1522 | RxCount = urb->actual_length; /* grab length of data handy */ |
1524 | 1523 | ||
1525 | if (RxCount) { | 1524 | if (RxCount) { |
@@ -1663,6 +1662,7 @@ __func__); | |||
1663 | dbg("%s(): failed resubmitting read urb, error %d", | 1662 | dbg("%s(): failed resubmitting read urb, error %d", |
1664 | __func__, result); | 1663 | __func__, result); |
1665 | } else { | 1664 | } else { |
1665 | dbg("%s() sucessfully resumitted read urb", __func__); | ||
1666 | if (tty_st && RxCount) { | 1666 | if (tty_st && RxCount) { |
1667 | /* if some inbound data was processed, then | 1667 | /* if some inbound data was processed, then |
1668 | * we need to push that through the tty layer | 1668 | * we need to push that through the tty layer |
@@ -1675,7 +1675,7 @@ __func__); | |||
1675 | /* cribbed from serqt_usb2 driver, but not sure which work needs | 1675 | /* cribbed from serqt_usb2 driver, but not sure which work needs |
1676 | * scheduling - port0 or currently active port? */ | 1676 | * scheduling - port0 or currently active port? */ |
1677 | /* schedule_work(&port->work); */ | 1677 | /* schedule_work(&port->work); */ |
1678 | 1678 | dbg("%s() completed", __func__); | |
1679 | return; | 1679 | return; |
1680 | } | 1680 | } |
1681 | 1681 | ||
@@ -1699,7 +1699,9 @@ static void qt2_write_bulk_callback(struct urb *urb) | |||
1699 | __func__, urb->status); | 1699 | __func__, urb->status); |
1700 | return; | 1700 | return; |
1701 | } | 1701 | } |
1702 | 1702 | /* FIXME What is supposed to be going on here? | |
1703 | * does this actually do anything useful, and should it? | ||
1704 | */ | ||
1703 | /*port_softint((void *) serial); commented in vendor driver */ | 1705 | /*port_softint((void *) serial); commented in vendor driver */ |
1704 | schedule_work(&port->work); | 1706 | schedule_work(&port->work); |
1705 | dbg("%s(): port %d exit", __func__, port->number); | 1707 | dbg("%s(): port %d exit", __func__, port->number); |