aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/quatech_usb2/quatech_usb2.c
diff options
context:
space:
mode:
authorRichard Ash <richard@audacityteam.org>2009-08-17 05:32:53 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2009-09-15 15:01:35 -0400
commit713e5f69d07ce6ff4ac9c2637ece4829a8127606 (patch)
tree15aa643a19da42b083b7cb63f464d6dd48674466 /drivers/staging/quatech_usb2/quatech_usb2.c
parent72ba94ec61d1ceb9b80e317f72548b1e88e539f4 (diff)
Staging: quatech_usb2: close, read, and some ioctl support
This patch implements close(), read(), write() and some ioctls, and fixes some implementation issues in open(). Compared to the previous patch it doesn't suffer an oops in the module code, however if you try to open any of the serial devices a second time then an oops occurs in tty_open(), presumably because my code isn't playing nicely on the previous close(): Aug 13 11:44:01 [kernel] WARNING: at drivers/char/tty_io.c:1268 tty_open+0x3e5/0x46d() Aug 13 11:44:01 [kernel] Hardware name: HP Compaq dc5100 MT(PW097ET) Aug 13 11:44:01 [kernel] Modules linked in: quatech_usb2(C) usbserial snd_seq snd_seq_device snd_pcm_oss snd_mixer_oss nls_iso8859_1 cifs xt_limit xt_NFLOG nfnetlink_log nfnetlink xt_tcpudp nf_conntrack_ipv4 nf_defrag_ipv4 xt_state nf_conntrack iptable_filter ip_tables x_tables i915 fb drm i2c_algo_bit cfbcopyarea i2c_core video backlight output cfbimgblt cfbfillrect snd_intel8x0 snd_ac97_codec ehci_hcd ac97_bus uhci_hcd snd_pcm snd_timer usbcore snd ohci1394 psmouse ide_cd_mod cdrom tg3 soundcore snd_page_alloc ieee1394 libphy intel_agp agpgart floppy evdev [last unloaded: usbserial] Aug 13 11:44:01 [kernel] Pid: 26765, comm: stty Tainted: G C 2.6.31-rc5-git3-gkh #7 Aug 13 11:44:01 [kernel] Call Trace: Aug 13 11:44:01 [kernel] [<c11dbef8>] ? tty_open+0x3e5/0x46d Aug 13 11:44:01 [kernel] [<c10264e2>] warn_slowpath_common+0x88/0xb0 Aug 13 11:44:01 [kernel] [<c11dbef8>] ? tty_open+0x3e5/0x46d Aug 13 11:44:01 [kernel] [<c102652b>] warn_slowpath_null+0x21/0x3b Aug 13 11:44:01 [kernel] [<c11dbef8>] tty_open+0x3e5/0x46d Aug 13 11:44:01 [kernel] [<c10883d1>] chrdev_open+0x77/0x113 Aug 13 11:44:01 [kernel] [<c1083a5d>] __dentry_open+0xb8/0x230 Aug 13 11:44:01 [kernel] [<c108835a>] ? chrdev_open+0x0/0x113 Aug 13 11:44:01 [kernel] [<c1084993>] nameidata_to_filp+0x61/0x6a Aug 13 11:44:01 [kernel] [<c1091144>] do_filp_open+0x248/0x7cd Aug 13 11:44:01 [kernel] [<c106f14f>] ? __do_fault+0x2ba/0x3b2 Aug 13 11:44:01 [kernel] [<c109a337>] ? alloc_fd+0x6a/0xf1 Aug 13 11:44:01 [kernel] [<c1083804>] do_sys_open+0x5f/0x12b Aug 13 11:44:01 [kernel] [<c1083947>] sys_open+0x2e/0x47 Aug 13 11:44:01 [kernel] [<c1002e4f>] sysenter_do_call+0x12/0x26 Aug 13 11:44:01 [kernel] ---[ end trace 1d6b9e2cd7636394 ]--- Aug 13 11:44:01 [kernel] BUG: unable to handle kernel NULL pointer dereference at 00000004 Aug 13 11:44:01 [kernel] IP: [<c1086538>] file_move+0x26/0x47 Aug 13 11:44:01 [kernel] *pde = 00000000 Aug 13 11:44:01 [kernel] Modules linked in: quatech_usb2(C) usbserial snd_seq snd_seq_device snd_pcm_oss snd_mixer_oss nls_iso8859_1 cifs xt_limit xt_NFLOG nfnetlink_log nfnetlink xt_tcpudp nf_conntrack_ipv4 nf_defrag_ipv4 xt_state nf_conntrack iptable_filter ip_tables x_tables i915 fb drm i2c_algo_bit cfbcopyarea i2c_core video backlight output cfbimgblt cfbfillrect snd_intel8x0 snd_ac97_codec ehci_hcd ac97_bus uhci_hcd snd_pcm snd_timer usbcore snd ohci1394 psmouse ide_cd_mod cdrom tg3 soundcore snd_page_alloc ieee1394 libphy intel_agp agpgart floppy evdev [last unloaded: usbserial] Aug 13 11:44:01 [kernel] Pid: 26765, comm: stty Tainted: G WC (2.6.31-rc5-git3-gkh #7) HP Compaq dc5100 MT(PW097ET) Aug 13 11:44:01 [kernel] EIP: 0060:[<c1086538>] EFLAGS: 00010282 CPU: 0 Aug 13 11:44:01 [kernel] EIP is at file_move+0x26/0x47 Aug 13 11:44:01 [kernel] EAX: 00000000 EBX: e593b508 ECX: ea7e9900 EDX: f734a888 Aug 13 11:44:01 [kernel] ESI: 00000000 EDI: 0bc00004 EBP: d8923e10 ESP: d8923e08 Aug 13 11:44:01 [kernel] DS: 007b ES: 007b FS: 0000 GS: 00e0 SS: 0068 Aug 13 11:44:01 [kernel] 2ba6efc8 c8c93180 d8923e48 c11dbca7 ea7e9900 eed37e6c 00000000 00008800 Aug 13 11:44:01 [kernel] <0> 00000000 e593b400 e593b400 00000004 2ba6efc8 c8c93188 00000000 eed37e6c Aug 13 11:44:01 [kernel] <0> d8923e68 c10883d1 ea7e9900 2ba6efc8 2ba6efc8 ea7e9900 eed37e6c ffffffe9 Aug 13 11:44:01 [kernel] [<c11dbca7>] ? tty_open+0x194/0x46d Aug 13 11:44:01 [kernel] [<c10883d1>] ? chrdev_open+0x77/0x113 Aug 13 11:44:01 [kernel] [<c1083a5d>] ? __dentry_open+0xb8/0x230 Aug 13 11:44:01 [kernel] [<c108835a>] ? chrdev_open+0x0/0x113 Aug 13 11:44:01 [kernel] [<c1084993>] ? nameidata_to_filp+0x61/0x6a Aug 13 11:44:01 [kernel] [<c1091144>] ? do_filp_open+0x248/0x7cd Aug 13 11:44:01 [kernel] [<c106f14f>] ? __do_fault+0x2ba/0x3b2 Aug 13 11:44:01 [kernel] [<c109a337>] ? alloc_fd+0x6a/0xf1 Aug 13 11:44:01 [kernel] [<c1083804>] ? do_sys_open+0x5f/0x12b Aug 13 11:44:01 [kernel] [<c1083947>] ? sys_open+0x2e/0x47 Aug 13 11:44:01 [kernel] [<c1002e4f>] ? sysenter_do_call+0x12/0x26 Aug 13 11:44:01 [kernel] ---[ end trace 1d6b9e2cd7636395 ]--- Read and Write also do not work at the moment, and I'm fairly sure that the URB completion callbacks are not running. Why this is I don't know, and haven't tried to investigate. Signed-off-by: Richard Ash <richard@audacityteam.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/quatech_usb2/quatech_usb2.c')
-rw-r--r--drivers/staging/quatech_usb2/quatech_usb2.c694
1 files changed, 646 insertions, 48 deletions
diff --git a/drivers/staging/quatech_usb2/quatech_usb2.c b/drivers/staging/quatech_usb2/quatech_usb2.c
index 0eaea2e7ce8..bbbf9b88fac 100644
--- a/drivers/staging/quatech_usb2/quatech_usb2.c
+++ b/drivers/staging/quatech_usb2/quatech_usb2.c
@@ -39,23 +39,33 @@ static int debug;
39#define QU2BOX232 0x40 /* RS232 mode on MEI devices */ 39#define QU2BOX232 0x40 /* RS232 mode on MEI devices */
40#define QU2BOXSPD9600 0x60 /* set speed to 9600 baud */ 40#define QU2BOXSPD9600 0x60 /* set speed to 9600 baud */
41#define FIFO_DEPTH 1024 /* size of hardware fifos */ 41#define FIFO_DEPTH 1024 /* size of hardware fifos */
42#define QT2_TX_HEADER_LENGTH 5
43/* length of the header sent to the box with each write URB */
44
42/* directions for USB transfers */ 45/* directions for USB transfers */
43#define USBD_TRANSFER_DIRECTION_IN 0xc0 46#define USBD_TRANSFER_DIRECTION_IN 0xc0
44#define USBD_TRANSFER_DIRECTION_OUT 0x40 47#define USBD_TRANSFER_DIRECTION_OUT 0x40
45/* special Quatech command IDs */ 48
49/* special Quatech command IDs. These are pushed down the
50 USB control pipe to get the box on the end to do things */
46#define QT_SET_GET_DEVICE 0xc2 51#define QT_SET_GET_DEVICE 0xc2
47#define QT_OPEN_CLOSE_CHANNEL 0xca 52#define QT_OPEN_CLOSE_CHANNEL 0xca
48/*#define QT_GET_SET_PREBUF_TRIG_LVL 0xcc 53/*#define QT_GET_SET_PREBUF_TRIG_LVL 0xcc
49#define QT_SET_ATF 0xcd 54#define QT_SET_ATF 0xcd*/
50#define QT_GET_SET_REGISTER 0xc0*/ 55#define QT2_GET_SET_REGISTER 0xc0
51#define QT_GET_SET_UART 0xc1 56#define QT_GET_SET_UART 0xc1
52/*#define QT_HW_FLOW_CONTROL_MASK 0xc5 57/*#define QT_HW_FLOW_CONTROL_MASK 0xc5
53#define QT_SW_FLOW_CONTROL_MASK 0xc6 58#define QT_SW_FLOW_CONTROL_MASK 0xc6
54#define QT_SW_FLOW_CONTROL_DISABLE 0xc7 59#define QT_SW_FLOW_CONTROL_DISABLE 0xc7
55#define QT_BREAK_CONTROL 0xc8 60#define QT_BREAK_CONTROL 0xc8
56#define QT_STOP_RECEIVE 0xe0 61#define QT_STOP_RECEIVE 0xe0*/
57#define QT_FLUSH_DEVICE 0xc4*/ 62#define QT2_FLUSH_DEVICE 0xc4
58#define QT_GET_SET_QMCR 0xe1 63#define QT_GET_SET_QMCR 0xe1
64
65/* sorts of flush we can do on */
66#define QT2_FLUSH_RX 0x00
67#define QT2_FLUSH_TX 0x01
68
59/* port setting constants */ 69/* port setting constants */
60#define SERIAL_MCR_DTR 0x01 70#define SERIAL_MCR_DTR 0x01
61#define SERIAL_MCR_RTS 0x02 71#define SERIAL_MCR_RTS 0x02
@@ -85,6 +95,19 @@ static int debug;
85#define SERIAL_LSR_FE 0x08 95#define SERIAL_LSR_FE 0x08
86#define SERIAL_LSR_BI 0x10 96#define SERIAL_LSR_BI 0x10
87 97
98/* value of Line Status Register when UART has completed
99 * emptying data out on the line */
100#define QT2_LSR_TEMT 0x40
101
102/* register numbers on each UART, for use with qt2_box_[get|set]_register*/
103#define QT2_XMT_HOLD_REGISTER 0x00
104#define QT2_XVR_BUFFER_REGISTER 0x00
105#define QT2_FIFO_CONTROL_REGISTER 0x02
106#define QT2_LINE_CONTROL_REGISTER 0x03
107#define QT2_MODEM_CONTROL_REGISTER 0x04
108#define QT2_LINE_STATUS_REGISTER 0x05
109#define QT2_MODEM_STATUS_REGISTER 0x06
110
88/* handy macros for doing escape sequence parsing on data reads */ 111/* handy macros for doing escape sequence parsing on data reads */
89#define THISCHAR ((unsigned char *)(urb->transfer_buffer))[i] 112#define THISCHAR ((unsigned char *)(urb->transfer_buffer))[i]
90#define NEXTCHAR ((unsigned char *)(urb->transfer_buffer))[i + 1] 113#define NEXTCHAR ((unsigned char *)(urb->transfer_buffer))[i + 1]
@@ -118,7 +141,7 @@ static struct usb_driver quausb2_usb_driver = {
118 * alongside the usb_serial_port structure 141 * alongside the usb_serial_port structure
119 * @param read_urb_busy Flag indicating that port->read_urb is in use 142 * @param read_urb_busy Flag indicating that port->read_urb is in use
120 * @param close_pending flag indicating that this port is in the process of 143 * @param close_pending flag indicating that this port is in the process of
121 * being closed. 144 * being closed (and so no new reads / writes should be started).
122 * @param shadowLSR Last received state of the line status register, holds the 145 * @param shadowLSR Last received state of the line status register, holds the
123 * value of the line status flags from the port 146 * value of the line status flags from the port
124 * @param shadowMSR Last received state of the modem status register, holds 147 * @param shadowMSR Last received state of the modem status register, holds
@@ -127,10 +150,14 @@ static struct usb_driver quausb2_usb_driver = {
127 * the serial port 150 * the serial port
128 * @param xmit_fifo_room_bytes free space available in the transmit fifo 151 * @param xmit_fifo_room_bytes free space available in the transmit fifo
129 * for this port on the box 152 * for this port on the box
130 * @param rcv_flush Flag indicating that a receive flush has been requested by 153 * @param rcv_flush Flag indicating that a receive flush has occured on
131 * the hardware. 154 * the hardware.
132 * @param xmit_flush Flag indicating that a transmit flush has been requested by 155 * @param xmit_flush Flag indicating that a transmit flush has been processed by
133 * the hardware. 156 * the hardware.
157 * @param fifo_empty_flag Flag indicating that the (per-port) buffer on the
158 * device is empty.
159 * @param tx_fifo_room Number of bytes room left in the buffer
160 * @param tx_pending_bytes Number of bytes waiting to be sent
134 */ 161 */
135struct quatech2_port { 162struct quatech2_port {
136 int magic; 163 int magic;
@@ -140,8 +167,11 @@ struct quatech2_port {
140 __u8 shadowMSR; 167 __u8 shadowMSR;
141 int xmit_pending_bytes; 168 int xmit_pending_bytes;
142 int xmit_fifo_room_bytes; 169 int xmit_fifo_room_bytes;
143 char rcv_flush; 170 bool rcv_flush;
144 char xmit_flush; 171 bool xmit_flush;
172/* bool fifo_empty_flag;
173 int tx_fifo_room;*/
174 int tx_pending_bytes;
145 175
146 char active; /* someone has this device open */ 176 char active; /* someone has this device open */
147 unsigned char *xfer_to_tty_buffer; 177 unsigned char *xfer_to_tty_buffer;
@@ -151,7 +181,6 @@ struct quatech2_port {
151 __u8 shadowLCR; /* last LCR value received */ 181 __u8 shadowLCR; /* last LCR value received */
152 __u8 shadowMCR; /* last MCR value received */ 182 __u8 shadowMCR; /* last MCR value received */
153 char RxHolding; 183 char RxHolding;
154 char fifo_empty_flag;
155 struct semaphore pend_xmit_sem; /* locks this structure */ 184 struct semaphore pend_xmit_sem; /* locks this structure */
156 spinlock_t lock; 185 spinlock_t lock;
157}; 186};
@@ -164,11 +193,16 @@ struct quatech2_port {
164 * the read stream is currently directed to. Escape sequences in the read 193 * the read stream is currently directed to. Escape sequences in the read
165 * stream will change this around as data arrives from different ports on the 194 * stream will change this around as data arrives from different ports on the
166 * box 195 * box
196 * @buffer_size: The max size buffer each URB can take, used to set the size of
197 * the buffers allocated for writing to each port on the device (we need to
198 * store this because it is known only to the endpoint, but used each time a
199 * port is opened and a new buffer is allocated.
167 */ 200 */
168struct quatech2_dev { 201struct quatech2_dev {
169 bool ReadBulkStopped; 202 bool ReadBulkStopped;
170 char open_ports; 203 char open_ports;
171 struct usb_serial_port *current_port; 204 struct usb_serial_port *current_port;
205 int buffer_size;
172}; 206};
173 207
174/* structure which holds line and modem status flags */ 208/* structure which holds line and modem status flags */
@@ -200,6 +234,7 @@ static int qt2_closeboxchannel(struct usb_serial *serial, __u16
200static int qt2_conf_uart(struct usb_serial *serial, unsigned short Uart_Number, 234static int qt2_conf_uart(struct usb_serial *serial, unsigned short Uart_Number,
201 unsigned short divisor, unsigned char LCR); 235 unsigned short divisor, unsigned char LCR);
202static void qt2_read_bulk_callback(struct urb *urb); 236static void qt2_read_bulk_callback(struct urb *urb);
237static void qt2_write_bulk_callback(struct urb *urb);
203static void qt2_process_line_status(struct usb_serial_port *port, 238static void qt2_process_line_status(struct usb_serial_port *port,
204 unsigned char LineStatus); 239 unsigned char LineStatus);
205static void qt2_process_modem_status(struct usb_serial_port *port, 240static void qt2_process_modem_status(struct usb_serial_port *port,
@@ -212,6 +247,19 @@ static void qt2_process_rcv_flush(struct usb_serial_port *port);
212static void qt2_process_xmit_flush(struct usb_serial_port *port); 247static void qt2_process_xmit_flush(struct usb_serial_port *port);
213static void qt2_process_rx_char(struct usb_serial_port *port, 248static void qt2_process_rx_char(struct usb_serial_port *port,
214 unsigned char data); 249 unsigned char data);
250static int qt2_box_get_register(struct usb_serial *serial,
251 unsigned char uart_number, unsigned short register_num,
252 __u8 *pValue);
253static int qt2_box_set_register(struct usb_serial *serial,
254 unsigned short Uart_Number, unsigned short Register_Num,
255 unsigned short Value);
256static int qt2_box_flush(struct usb_serial *serial, unsigned char uart_number,
257 unsigned short rcv_or_xmit);
258static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port,
259 const unsigned char *buf, int count);
260static int qt2_tiocmget(struct tty_struct *tty, struct file *file);
261static int qt2_tiocmset(struct tty_struct *tty, struct file *file,
262 unsigned int set, unsigned int clear);
215 263
216/* implementation functions, roughly in order of use, are here */ 264/* implementation functions, roughly in order of use, are here */
217static int qt2_calc_num_ports(struct usb_serial *serial) 265static int qt2_calc_num_ports(struct usb_serial *serial)
@@ -291,7 +339,7 @@ static int qt2_attach(struct usb_serial *serial)
291 return -ENOMEM; 339 return -ENOMEM;
292 } 340 }
293 spin_lock_init(&qt2_port->lock); 341 spin_lock_init(&qt2_port->lock);
294 usb_set_serial_port_data(port, qt2_port); 342 qt2_set_port_private(port, qt2_port);
295 } 343 }
296 344
297 /* gain access to port[0]'s structure because we want to store 345 /* gain access to port[0]'s structure because we want to store
@@ -307,15 +355,17 @@ static int qt2_attach(struct usb_serial *serial)
307 if ((endpoint->bEndpointAddress & 0x80) && 355 if ((endpoint->bEndpointAddress & 0x80) &&
308 ((endpoint->bmAttributes & 3) == 0x02)) { 356 ((endpoint->bmAttributes & 3) == 0x02)) {
309 /* we found a bulk in endpoint */ 357 /* we found a bulk in endpoint */
310 dbg("found bulk in at 0x%x", 358 dbg("found bulk in at %#.2x",
311 endpoint->bEndpointAddress); 359 endpoint->bEndpointAddress);
312 } 360 }
313 361
314 if (((endpoint->bEndpointAddress & 0x80) == 0x00) && 362 if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
315 ((endpoint->bmAttributes & 3) == 0x02)) { 363 ((endpoint->bmAttributes & 3) == 0x02)) {
316 /* we found a bulk out endpoint */ 364 /* we found a bulk out endpoint */
317 dbg("found bulk out at 0x%x", 365 dbg("found bulk out at %#.2x",
318 endpoint->bEndpointAddress); 366 endpoint->bEndpointAddress);
367 qt2_dev->buffer_size = endpoint->wMaxPacketSize;
368 /* max size of URB needs recording for the device */
319 } 369 }
320 } /* end printing endpoint addresses */ 370 } /* end printing endpoint addresses */
321 371
@@ -368,7 +418,8 @@ static void qt2_release(struct usb_serial *serial)
368 usb_set_serial_port_data(port, NULL); 418 usb_set_serial_port_data(port, NULL);
369 } 419 }
370} 420}
371/* This function is called once per serial port on the device. 421/* This function is called once per serial port on the device, when
422 * that port is opened by a userspace application.
372 * The tty_struct and the usb_serial_port belong to this port, 423 * The tty_struct and the usb_serial_port belong to this port,
373 * i.e. there are multiple ones for a multi-port device. 424 * i.e. there are multiple ones for a multi-port device.
374 * However the usb_serial_port structure has a back-pointer 425 * However the usb_serial_port structure has a back-pointer
@@ -379,12 +430,11 @@ static void qt2_release(struct usb_serial *serial)
379 * This is most helpful if the device shares resources (e.g. end 430 * This is most helpful if the device shares resources (e.g. end
380 * points) between different ports 431 * points) between different ports
381 */ 432 */
382int qt2_open(struct tty_struct *tty, 433int qt2_open(struct tty_struct *tty, struct usb_serial_port *port)
383 struct usb_serial_port *port, struct file *filp)
384{ 434{
385 struct usb_serial *serial; /* device structure */ 435 struct usb_serial *serial; /* device structure */
386 struct usb_serial_port *port0; /* first port structure on device */ 436 struct usb_serial_port *port0; /* first port structure on device */
387 struct quatech2_port *port_extra; /* extra data for this port */ 437 struct quatech2_port *port_extra; /* extra data for this port */
388 struct quatech2_port *port0_extra; /* extra data for first port */ 438 struct quatech2_port *port0_extra; /* extra data for first port */
389 struct quatech2_dev *dev_extra; /* extra data for the device */ 439 struct quatech2_dev *dev_extra; /* extra data for the device */
390 struct qt2_status_data ChannelData; 440 struct qt2_status_data ChannelData;
@@ -405,22 +455,23 @@ int qt2_open(struct tty_struct *tty,
405 } 455 }
406 dev_extra = qt2_get_dev_private(serial); 456 dev_extra = qt2_get_dev_private(serial);
407 /* get the device private data */ 457 /* get the device private data */
458 if (dev_extra == NULL) {
459 dbg("device extra data pointer is null");
460 return -ENODEV;
461 }
408 port0 = serial->port[0]; /* get the first port's device structure */ 462 port0 = serial->port[0]; /* get the first port's device structure */
409 if (port_paranoia_check(port, __func__)) { 463 if (port_paranoia_check(port0, __func__)) {
410 dbg("port0 usb_serial_port struct failed sanity check"); 464 dbg("port0 usb_serial_port struct failed sanity check");
411 return -ENODEV; 465 return -ENODEV;
412 } 466 }
467
413 port_extra = qt2_get_port_private(port); 468 port_extra = qt2_get_port_private(port);
414 port0_extra = qt2_get_port_private(port0); 469 port0_extra = qt2_get_port_private(port0);
415
416 if (port_extra == NULL || port0_extra == NULL) { 470 if (port_extra == NULL || port0_extra == NULL) {
417 dbg("failed to get private data for port and port0"); 471 dbg("failed to get private data for port or port0");
418 return -ENODEV; 472 return -ENODEV;
419 } 473 }
420 474
421 usb_clear_halt(serial->dev, port->write_urb->pipe);
422 usb_clear_halt(serial->dev, port->read_urb->pipe);
423
424 /* FIXME: are these needed? Does it even do anything useful? */ 475 /* FIXME: are these needed? Does it even do anything useful? */
425 /* get the modem and line status values from the UART */ 476 /* get the modem and line status values from the UART */
426 status = qt2_openboxchannel(serial, port->number, 477 status = qt2_openboxchannel(serial, port->number,
@@ -433,12 +484,11 @@ int qt2_open(struct tty_struct *tty,
433 port_extra->shadowLSR = ChannelData.line_status & 484 port_extra->shadowLSR = ChannelData.line_status &
434 (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE | 485 (SERIAL_LSR_OE | SERIAL_LSR_PE | SERIAL_LSR_FE |
435 SERIAL_LSR_BI); 486 SERIAL_LSR_BI);
436
437 port_extra->shadowMSR = ChannelData.modem_status & 487 port_extra->shadowMSR = ChannelData.modem_status &
438 (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI | 488 (SERIAL_MSR_CTS | SERIAL_MSR_DSR | SERIAL_MSR_RI |
439 SERIAL_MSR_CD); 489 SERIAL_MSR_CD);
440 490
441 port_extra->fifo_empty_flag = true; 491/* port_extra->fifo_empty_flag = true;*/
442 dbg("qt2_openboxchannel on channel %d completed.", 492 dbg("qt2_openboxchannel on channel %d completed.",
443 port->number); 493 port->number);
444 494
@@ -463,19 +513,57 @@ int qt2_open(struct tty_struct *tty,
463 * when we do a write to a port, we will use the same endpoint 513 * when we do a write to a port, we will use the same endpoint
464 * regardless of the port, with a 5-byte header added on to 514 * regardless of the port, with a 5-byte header added on to
465 * tell the box which port it should eventually come out of, so we only 515 * tell the box which port it should eventually come out of, so we only
466 * need the one set of endpoints. 516 * need the one set of endpoints. We will have one URB per port for
517 * writing, so that multiple ports can be writing at once.
467 * Finally we need a bulk in URB to use for background reads from the 518 * Finally we need a bulk in URB to use for background reads from the
468 * device, which will deal with uplink data from the box to host. 519 * device, which will deal with uplink data from the box to host.
469 */ 520 */
470 dbg("port number is %d", port->number);
471 dbg("serial number is %d", port->serial->minor); 521 dbg("serial number is %d", port->serial->minor);
472 dbg("port0 bulk in endpoint is %#.2x", port0->bulk_in_endpointAddress); 522 dbg("port0 bulk in endpoint is %#.2x", port0->bulk_in_endpointAddress);
473 dbg("port0 bulk out endpoint is %#.2x", 523 dbg("port0 bulk out endpoint is %#.2x",
474 port0->bulk_out_endpointAddress); 524 port0->bulk_out_endpointAddress);
475 525
526 /* set up write_urb for bulk out transfers on this port. The USB
527 * serial framework will have allocated a blank URB, buffer etc for
528 * port0 when it put the endpoints there, but not for any of the other
529 * ports on the device because there are no more endpoints. Thus we
530 * have to allocate our own URBs for ports 1-7
531 */
532 if (port->write_urb == NULL) {
533 dbg("port->write_urb == NULL, allocating one");
534 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
535 if (!port->write_urb) {
536 err("Allocating write URB failed");
537 return -ENOMEM;
538 }
539 /* buffer same size as port0 */
540 port->bulk_out_size = dev_extra->buffer_size;
541 port->bulk_out_buffer = kmalloc(port->bulk_out_size,
542 GFP_KERNEL);
543 if (!port->bulk_out_buffer) {
544 err("Couldn't allocate bulk_out_buffer");
545 return -ENOMEM;
546 }
547 }
548 if (serial->dev == NULL)
549 dbg("serial->dev == NULL");
550 dbg("port->bulk_out_size is %d", port->bulk_out_size);
551
552 usb_fill_bulk_urb(port->write_urb, serial->dev,
553 usb_sndbulkpipe(serial->dev,
554 port0->bulk_out_endpointAddress),
555 port->bulk_out_buffer,
556 port->bulk_out_size,
557 qt2_write_bulk_callback,
558 port);
559 /*port_extra->fifo_empty_flag = true;
560 port_extra->tx_fifo_room = FIFO_DEPTH;*/
561 port_extra->tx_pending_bytes = 0;
562
476 if (dev_extra->open_ports == 0) { 563 if (dev_extra->open_ports == 0) {
477 /* this is first port to be opened, so need some URBs */ 564 /* this is first port to be opened, so need the read URB
478 /* initialise read_urb for bulk in transfers */ 565 * initialised for bulk in transfers (this is shared amongst
566 * all the ports on the device) */
479 usb_fill_bulk_urb(port0->read_urb, serial->dev, 567 usb_fill_bulk_urb(port0->read_urb, serial->dev,
480 usb_rcvbulkpipe(serial->dev, 568 usb_rcvbulkpipe(serial->dev,
481 port0->bulk_in_endpointAddress), 569 port0->bulk_in_endpointAddress),
@@ -490,25 +578,444 @@ int qt2_open(struct tty_struct *tty,
490 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 578 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
491 if (result) { 579 if (result) {
492 dev_err(&port->dev, 580 dev_err(&port->dev,
493 "%s - Error %d submitting bulk in urb\n", 581 "%s(): Error %d submitting bulk in urb",
494 __func__, result); 582 __func__, result);
495 port_extra->read_urb_busy = false; 583 port_extra->read_urb_busy = false;
584 dev_extra->ReadBulkStopped = true;
496 } 585 }
586
587 /* When the first port is opened, initialise the value of
588 * current_port in dev_extra to this port, so it is set
589 * to something. Once the box sends data it will send the
590 * relevant escape sequences to get it to the right port anyway
591 */
592 dev_extra->current_port = port;
497 } 593 }
498 594
499 /* initialize our wait queues */ 595 /* initialize our wait queues */
500 init_waitqueue_head(&port_extra->wait); 596 init_waitqueue_head(&port_extra->wait);
501 597
502 /* remember to store port_extra and port0 back again at end !*/ 598 /* remember to store dev_extra, port_extra and port0_extra back again at
599 * end !*/
503 qt2_set_port_private(port, port_extra); 600 qt2_set_port_private(port, port_extra);
504 qt2_set_port_private(serial->port[0], port0_extra); 601 qt2_set_port_private(serial->port[0], port0_extra);
505 qt2_set_dev_private(serial, dev_extra); 602 qt2_set_dev_private(serial, dev_extra);
506 603
507 dev_extra->open_ports++; /* one more port opened */ 604 dev_extra->open_ports++; /* one more port opened */
508 605
509 return 0; 606 return 0;
510} 607}
511 608
609/* called when a port is closed by userspace */
610/* Setting close_pending should keep new data from being written out,
611 * once all the data in the enpoint buffers is moved out we won't get
612 * any more. */
613/* BoxStopReceive would keep any more data from coming from a given
614 * port, but isn't called by the vendor driver, although their comments
615 * mention it. Should it be used here to stop the inbound data
616 * flow?
617 */
618static void qt2_close(struct usb_serial_port *port)
619{
620 /* time out value for flush loops */
621 unsigned long jift;
622 struct quatech2_port *port_extra; /* extra data for this port */
623 struct usb_serial *serial; /* device structure */
624 struct quatech2_dev *dev_extra; /* extra data for the device */
625 __u8 lsr_value = 0; /* value of Line Status Register */
626 int status; /* result of last USB comms function */
627
628 dbg("%s(): port %d", __func__, port->number);
629 serial = port->serial; /* get the parent device structure */
630 dev_extra = qt2_get_dev_private(serial);
631 /* get the device private data */
632 port_extra = qt2_get_port_private(port); /* port private data */
633
634 /* to check we have successfully flushed the buffers on the hardware,
635 * we set the flags indicating flushes have occured to false, then ask
636 * for flushes to occur, then sit in a timed loop until either we
637 * get notified back that the flushes have happened (good) or we get
638 * tired of waiting for the flush to happen and give up (bad).
639 */
640 port_extra->rcv_flush = false;
641 port_extra->xmit_flush = false;
642 qt2_box_flush(serial, port->number, QT2_FLUSH_TX); /* flush tx buffer */
643 qt2_box_flush(serial, port->number, QT2_FLUSH_RX); /* flush rx buffer */
644 /* now wait for the flags to magically go back to being true */
645 jift = jiffies + (10 * HZ);
646 do {
647 if ((port_extra->rcv_flush == true) &&
648 (port_extra->xmit_flush == true)) {
649 dbg("Flush completed");
650 break;
651 }
652 schedule();
653 } while (jiffies <= jift);
654
655 /* we can now (and only now) stop reading data */
656 port_extra->close_pending = true;
657 dbg("%s(): port_extra->close_pending = true", __func__);
658 /* although the USB side is now empty, the UART itself may
659 * still be pushing characters out over the line, so we have to
660 * wait testing the actual line status until the lines change
661 * indicating that the data is done transfering. */
662 jift = jiffies + (10 * HZ); /* 10 sec timeout */
663 do {
664 status = qt2_box_get_register(serial, port->number,
665 QT2_LINE_STATUS_REGISTER, &lsr_value);
666 if (status < 0) {
667 dbg("%s(): qt2_box_get_register failed", __func__);
668 break;
669 }
670 if ((lsr_value & QT2_LSR_TEMT)) {
671 dbg("UART done sending");
672 break;
673 }
674 schedule();
675 } while (jiffies <= jift);
676
677 status = qt2_closeboxchannel(serial, port->number);
678 if (status < 0)
679 dbg("%s(): port %d qt2_box_open_close_channel failed",
680 __func__, port->number);
681 /* to avoid leaking URBs, we should now free the write_urb for this
682 * port and set the pointer to null so that next time the port is opened
683 * a new URB is allocated. This avoids leaking URBs when the device is
684 * removed */
685 usb_free_urb(port->write_urb);
686 kfree(port->bulk_out_buffer);
687 port->bulk_out_buffer = NULL;
688 port->bulk_out_size = 0;
689
690 dev_extra->open_ports--;
691 dbg("%s(): Exit, dev_extra->open_ports = %d", __func__,
692 dev_extra->open_ports);
693}
694
695/* called to deliver writes from the next layer up to the device */
696static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port,
697 const unsigned char *buf, int count)
698{
699 struct usb_serial *serial; /* parent device struct */
700 __u8 header_array[5]; /* header used to direct writes to the correct
701 port on the device */
702 struct quatech2_port *port_extra; /* extra data for this port */
703
704 int result;
705
706 /* get the parent device of the port */
707 serial = port->serial;
708 if (serial == NULL)
709 return -ENODEV;
710 dbg("%s(): port %d", __func__, port->number);
711
712 if (count <= 0) {
713 dbg("%s(): write request of <= 0 bytes", __func__);
714 return 0; /* no bytes written */
715 }
716 port_extra = qt2_get_port_private(port);
717
718 /* check if the write urb is already in use, i.e. data already being
719 * sent to this port */
720 if ((port->write_urb->status == -EINPROGRESS)) {
721 /* Fifo hasn't been emptied since last write to this port */
722 dbg("%s(): already writing, port->write_urb->status == "
723 "-EINPROGRESS", __func__);
724 /* schedule_work(&port->work); commented in vendor driver */
725 return 0;
726 } else if (port_extra->tx_pending_bytes >= FIFO_DEPTH) {
727 /* such a lot queued up that we will fill the buffer again as
728 * soon as it does empty? Overflowed buffer? */
729 dbg("%s(): already writing, port_extra->tx_pending_bytes >="
730 " FIFO_DEPTH", __func__);
731 /* schedule_work(&port->work); commented in vendor driver */
732 return 0;
733 }
734
735 /* We must fill the first 5 bytes of anything we sent with a transmit
736 * header which directes the data to the correct port. The maximum
737 * size we can send out in one URB is port->bulk_out_size, which caps
738 * the number of bytes of real data we can send in each write. As the
739 * semantics of write allow us to write less than we were give, we cap
740 * the maximum we will ever write to the device as 5 bytes less than
741 * one URB's worth, by reducing the value of the count argument
742 * appropriately*/
743 if (count > port->bulk_out_size - QT2_TX_HEADER_LENGTH)
744 count = port->bulk_out_size - QT2_TX_HEADER_LENGTH;
745 /* we must also ensure that the FIFO at the other end can cope with the
746 * URB we send it, otherwise it will have problems. As above, we can
747 * restrict the write size by just shrinking count.*/
748 if (count > (FIFO_DEPTH - port_extra->tx_pending_bytes))
749 count = FIFO_DEPTH - port_extra->tx_pending_bytes;
750 /* now build the header for transmission */
751 header_array[0] = 0x1b;
752 header_array[1] = 0x1b;
753 header_array[2] = (__u8)port->number;
754 header_array[3] = (__u8)count;
755 header_array[4] = (__u8)count >> 8;
756 /* copy header into URB */
757 memcpy(port->write_urb->transfer_buffer, header_array,
758 QT2_TX_HEADER_LENGTH);
759 /* and actual data to write */
760 memcpy(port->write_urb->transfer_buffer + 5, buf, count);
761
762 dbg("%s(): first data byte to send = %#.2x", __func__, *buf);
763
764 /* set up our urb */
765 usb_fill_bulk_urb(port->write_urb, serial->dev,
766 usb_sndbulkpipe(serial->dev,
767 port->bulk_out_endpointAddress),
768 port->write_urb->transfer_buffer, count + 5,
769 (qt2_write_bulk_callback), port);
770 /* send the data out the bulk port */
771 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
772 if (result) {
773 /* error couldn't submit urb */
774 result = 0;
775 dbg("%s(): failed submitting write urb, error %d",
776 __func__, result);
777 } else {
778 port_extra->tx_pending_bytes += (count - QT2_TX_HEADER_LENGTH);
779 /*port->fifo_empty_flag = false;
780 port->xmit_fifo_room_bytes = FIFO_DEPTH -
781 port->xmit_pending_bytes;*/
782 result = count;
783 dbg("%s(): submitted write urb, returning %d", __func__,
784result);
785 }
786 return result;
787}
788
789static int qt2_write_room(struct tty_struct *tty)
790{
791 struct usb_serial_port *port = tty->driver_data;
792 /* parent usb_serial_port pointer */
793 struct quatech2_port *port_extra; /* extra data for this port */
794 int room = 0;
795 port_extra = qt2_get_port_private(port);
796
797 if (port_extra->close_pending == true) {
798 dbg("%s(): port_extra->close_pending == true", __func__);
799 return -ENODEV;
800 }
801
802 dbg("%s(): port %d", __func__, port->number);
803 if ((port->write_urb->status != -EINPROGRESS) &&
804 (port_extra->tx_pending_bytes == 0))
805 room = port->bulk_out_size - QT2_TX_HEADER_LENGTH;
806 return room;
807}
808
809static int qt2_chars_in_buffer(struct tty_struct *tty)
810{
811 struct usb_serial_port *port = tty->driver_data;
812 /* parent usb_serial_port pointer */
813 int chars = 0;
814 struct quatech2_port *port_extra; /* extra data for this port */
815 port_extra = qt2_get_port_private(port);
816
817 dbg("%s(): port %d", __func__, port->number);
818 if ((port->write_urb->status == -EINPROGRESS) &&
819 (port_extra->tx_pending_bytes != 0))
820 chars = port->write_urb->transfer_buffer_length;
821 dbg("%s(): returns %d", __func__, chars);
822 return chars;
823}
824
825
826static int qt2_ioctl(struct tty_struct *tty, struct file *file,
827 unsigned int cmd, unsigned long arg)
828{
829 struct usb_serial_port *port = tty->driver_data;
830 struct usb_serial *serial = port->serial;
831 __u8 mcr_value; /* Modem Control Register value */
832 __u8 msr_value; /* Modem Status Register value */
833 unsigned short prev_msr_value; /* Previous value of Modem Status
834 * Register used to implement waiting for a line status change to
835 * occur */
836 struct quatech2_port *port_extra; /* extra data for this port */
837 DECLARE_WAITQUEUE(wait, current);
838 /* Declare a wait queue named "wait" */
839
840 unsigned int value;
841 int status;
842 unsigned int UartNumber;
843
844 if (serial == NULL)
845 return -ENODEV;
846 UartNumber = tty->index - serial->minor;
847 port_extra = qt2_get_port_private(port);
848
849 dbg("%s(): port %d, UartNumber %d, tty =0x%p", __func__,
850 port->number, UartNumber, tty);
851
852 if (cmd == TIOCMGET) {
853 return qt2_tiocmget(tty, file);
854 /* same as tiocmget function */
855 } else if (cmd == TIOCMSET) {
856 if (copy_from_user(&value, (unsigned int *)arg,
857 sizeof(unsigned int)))
858 return -EFAULT;
859 return qt2_tiocmset(tty, file, value, 0);
860 /* same as tiocmset function */
861 } else if (cmd == TIOCMBIS || cmd == TIOCMBIC) {
862 status = qt2_box_get_register(port->serial, UartNumber,
863 QT2_MODEM_CONTROL_REGISTER, &mcr_value);
864 if (status < 0)
865 return -ESPIPE;
866 if (copy_from_user(&value, (unsigned int *)arg,
867 sizeof(unsigned int)))
868 return -EFAULT;
869
870 switch (cmd) {
871 case TIOCMBIS:
872 if (value & TIOCM_RTS)
873 mcr_value |= SERIAL_MCR_RTS;
874 if (value & TIOCM_DTR)
875 mcr_value |= SERIAL_MCR_DTR;
876 if (value & TIOCM_LOOP)
877 mcr_value |= SERIAL_MCR_LOOP;
878 break;
879 case TIOCMBIC:
880 if (value & TIOCM_RTS)
881 mcr_value &= ~SERIAL_MCR_RTS;
882 if (value & TIOCM_DTR)
883 mcr_value &= ~SERIAL_MCR_DTR;
884 if (value & TIOCM_LOOP)
885 mcr_value &= ~SERIAL_MCR_LOOP;
886 break;
887 default:
888 break;
889 } /* end of local switch on cmd */
890 status = qt2_box_set_register(port->serial, UartNumber,
891 QT2_MODEM_CONTROL_REGISTER, mcr_value);
892 if (status < 0) {
893 return -ESPIPE;
894 } else {
895 port_extra->shadowMCR = mcr_value;
896 return 0;
897 }
898 } else if (cmd == TIOCMIWAIT) {
899 dbg("%s() port %d, cmd == TIOCMIWAIT enter",
900 __func__, port->number);
901 prev_msr_value = port_extra->shadowMSR & SERIAL_MSR_MASK;
902 while (1) {
903 add_wait_queue(&port_extra->wait, &wait);
904 set_current_state(TASK_INTERRUPTIBLE);
905 schedule();
906 dbg("%s(): port %d, cmd == TIOCMIWAIT here\n",
907 __func__, port->number);
908 remove_wait_queue(&port_extra->wait, &wait);
909 /* see if a signal woke us up */
910 if (signal_pending(current))
911 return -ERESTARTSYS;
912 msr_value = port_extra->shadowMSR & SERIAL_MSR_MASK;
913 if (msr_value == prev_msr_value)
914 return -EIO; /* no change - error */
915 if ((arg & TIOCM_RNG &&
916 ((prev_msr_value & SERIAL_MSR_RI) ==
917 (msr_value & SERIAL_MSR_RI))) ||
918 (arg & TIOCM_DSR &&
919 ((prev_msr_value & SERIAL_MSR_DSR) ==
920 (msr_value & SERIAL_MSR_DSR))) ||
921 (arg & TIOCM_CD &&
922 ((prev_msr_value & SERIAL_MSR_CD) ==
923 (msr_value & SERIAL_MSR_CD))) ||
924 (arg & TIOCM_CTS &&
925 ((prev_msr_value & SERIAL_MSR_CTS) ==
926 (msr_value & SERIAL_MSR_CTS)))) {
927 return 0;
928 }
929 } /* end inifinite while */
930 } else {
931 /* any other ioctls we don't know about come here */
932 dbg("%s(): No ioctl for that one. port = %d", __func__,
933 port->number);
934 return -ENOIOCTLCMD;
935 }
936}
937
938static int qt2_tiocmget(struct tty_struct *tty, struct file *file)
939{
940 struct usb_serial_port *port = tty->driver_data;
941 struct usb_serial *serial = port->serial;
942
943 __u8 mcr_value; /* Modem Control Register value */
944 __u8 msr_value; /* Modem Status Register value */
945 unsigned int result = 0;
946 int status;
947 unsigned int UartNumber;
948
949 if (serial == NULL)
950 return -ENODEV;
951
952 dbg("%s(): port %d, tty =0x%p", __func__, port->number, tty);
953 UartNumber = tty->index - serial->minor;
954 dbg("UartNumber is %d", UartNumber);
955
956 status = qt2_box_get_register(port->serial, UartNumber,
957 QT2_MODEM_CONTROL_REGISTER, &mcr_value);
958 if (status >= 0) {
959 status = qt2_box_get_register(port->serial, UartNumber,
960 QT2_MODEM_STATUS_REGISTER, &msr_value);
961 }
962 if (status >= 0) {
963 result = ((mcr_value & SERIAL_MCR_DTR) ? TIOCM_DTR : 0)
964 /*DTR set */
965 | ((mcr_value & SERIAL_MCR_RTS) ? TIOCM_RTS : 0)
966 /*RTS set */
967 | ((msr_value & SERIAL_MSR_CTS) ? TIOCM_CTS : 0)
968 /* CTS set */
969 | ((msr_value & SERIAL_MSR_CD) ? TIOCM_CAR : 0)
970 /*Carrier detect set */
971 | ((msr_value & SERIAL_MSR_RI) ? TIOCM_RI : 0)
972 /* Ring indicator set */
973 | ((msr_value & SERIAL_MSR_DSR) ? TIOCM_DSR : 0);
974 /* DSR set */
975 return result;
976 } else {
977 return -ESPIPE;
978 }
979}
980
981static int qt2_tiocmset(struct tty_struct *tty, struct file *file,
982 unsigned int set, unsigned int clear)
983{
984 struct usb_serial_port *port = tty->driver_data;
985 struct usb_serial *serial = port->serial;
986 __u8 mcr_value; /* Modem Control Register value */
987 int status;
988 unsigned int UartNumber;
989
990 if (serial == NULL)
991 return -ENODEV;
992
993 UartNumber = tty->index - serial->minor;
994 dbg("%s(): port %d, UartNumber %d", __func__, port->number, UartNumber);
995
996 status = qt2_box_get_register(port->serial, UartNumber,
997 QT2_MODEM_CONTROL_REGISTER, &mcr_value);
998 if (status < 0)
999 return -ESPIPE;
1000
1001 /* Turn off RTS, DTR and loopback, then only turn on what was asked
1002 * for */
1003 mcr_value &= ~(SERIAL_MCR_RTS | SERIAL_MCR_DTR | SERIAL_MCR_LOOP);
1004 if (set & TIOCM_RTS)
1005 mcr_value |= SERIAL_MCR_RTS;
1006 if (set & TIOCM_DTR)
1007 mcr_value |= SERIAL_MCR_DTR;
1008 if (set & TIOCM_LOOP)
1009 mcr_value |= SERIAL_MCR_LOOP;
1010
1011 status = qt2_box_set_register(port->serial, UartNumber,
1012 QT2_MODEM_CONTROL_REGISTER, mcr_value);
1013 if (status < 0)
1014 return -ESPIPE;
1015 else
1016 return 0;
1017}
1018
512/* internal, private helper functions for the driver */ 1019/* internal, private helper functions for the driver */
513 1020
514/* Power up the FPGA in the box to get it working */ 1021/* Power up the FPGA in the box to get it working */
@@ -643,7 +1150,7 @@ static int qt2_conf_uart(struct usb_serial *serial, unsigned short Uart_Number,
643 return result; 1150 return result;
644} 1151}
645 1152
646/** @brief Callback for asynchronous submission of URBs on bulk in 1153/** @brief Callback for asynchronous submission of read URBs on bulk in
647 * endpoints 1154 * endpoints
648 * 1155 *
649 * Registered in qt2_open_port(), used to deal with incomming data 1156 * Registered in qt2_open_port(), used to deal with incomming data
@@ -678,7 +1185,7 @@ static void qt2_read_bulk_callback(struct urb *urb)
678 if (urb->status) { 1185 if (urb->status) {
679 /* read didn't go well */ 1186 /* read didn't go well */
680 dev_extra->ReadBulkStopped = true; 1187 dev_extra->ReadBulkStopped = true;
681 dbg("%s(): nonzero write bulk status received: %d", 1188 dbg("%s(): nonzero bulk read status received: %d",
682 __func__, urb->status); 1189 __func__, urb->status);
683 return; 1190 return;
684 } 1191 }
@@ -908,6 +1415,34 @@ __func__);
908 1415
909 return; 1416 return;
910} 1417}
1418
1419/** @brief Callback for asynchronous submission of write URBs on bulk in
1420 * endpoints
1421 *
1422 * Registered in qt2_write(), used to deal with outgoing data
1423 * to the box.
1424 */
1425static void qt2_write_bulk_callback(struct urb *urb)
1426{
1427 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1428 struct usb_serial *serial = port->serial;
1429 dbg("%s(): port %d", __func__, port->number);
1430 if (!serial) {
1431 dbg("%s(): bad serial pointer, exiting", __func__);
1432 return;
1433 }
1434 if (urb->status) {
1435 dbg("%s(): nonzero write bulk status received: %d",
1436 __func__, urb->status);
1437 return;
1438 }
1439
1440 /*port_softint((void *) serial); commented in vendor driver */
1441 schedule_work(&port->work);
1442 dbg("%s(): port %d exit", __func__, port->number);
1443 return;
1444}
1445
911static void qt2_process_line_status(struct usb_serial_port *port, 1446static void qt2_process_line_status(struct usb_serial_port *port,
912 unsigned char LineStatus) 1447 unsigned char LineStatus)
913{ 1448{
@@ -922,8 +1457,11 @@ static void qt2_process_modem_status(struct usb_serial_port *port,
922 /* obtain the private structure for the port */ 1457 /* obtain the private structure for the port */
923 struct quatech2_port *port_extra = qt2_get_port_private(port); 1458 struct quatech2_port *port_extra = qt2_get_port_private(port);
924 port_extra->shadowMSR = ModemStatus; 1459 port_extra->shadowMSR = ModemStatus;
925 /* ?? */
926 wake_up_interruptible(&port_extra->wait); 1460 wake_up_interruptible(&port_extra->wait);
1461 /* this wakes up the otherwise indefinitely waiting code for
1462 * the TIOCMIWAIT ioctl, so that it can notice that
1463 * port_extra->shadowMSR has changed and the ioctl needs to return.
1464 */
927} 1465}
928 1466
929static void qt2_process_xmit_empty(struct usb_serial_port *port, 1467static void qt2_process_xmit_empty(struct usb_serial_port *port,
@@ -980,6 +1518,66 @@ static void qt2_process_rx_char(struct usb_serial_port *port,
980 /*tty_flip_buffer_push(tty);*/ 1518 /*tty_flip_buffer_push(tty);*/
981 } 1519 }
982} 1520}
1521
1522/** @brief Retreive the value of a register from the device
1523 *
1524 * Issues a GET_REGISTER vendor-spcific request over the USB control
1525 * pipe to obtain a value back from a specific register on a specific
1526 * UART
1527 * @param serial Serial device handle to access the device through
1528 * @param uart_number Which UART the value is wanted from
1529 * @param register_num Which register to read the value from
1530 * @param pValue Pointer to somewhere to put the retrieved value
1531 */
1532static int qt2_box_get_register(struct usb_serial *serial,
1533 unsigned char uart_number, unsigned short register_num,
1534 __u8 *pValue)
1535{
1536 int result;
1537 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
1538 QT2_GET_SET_REGISTER, 0xC0, register_num,
1539 uart_number, (void *)pValue, sizeof(*pValue), 300);
1540 return result;
1541}
1542
1543/** qt2_box_set_register
1544 * Issue a SET_REGISTER vendor-specific request on the default control pipe
1545 */
1546static int qt2_box_set_register(struct usb_serial *serial,
1547 unsigned short Uart_Number, unsigned short Register_Num,
1548 unsigned short Value)
1549{
1550 int result;
1551 unsigned short reg_and_byte;
1552
1553 reg_and_byte = Value;
1554 reg_and_byte = reg_and_byte << 8;
1555 reg_and_byte = reg_and_byte + Register_Num;
1556
1557 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1558 QT2_GET_SET_REGISTER, 0x40, reg_and_byte,
1559 Uart_Number, NULL, 0, 300);
1560 return result;
1561}
1562
1563
1564/** @brief Request the Tx or Rx buffers on the USB side be flushed
1565 *
1566 * Tx flush: When all the currently buffered data has been sent, send an escape
1567 * sequence back up the data stream to us
1568 * Rx flush: add a flag in the data stream now so we know when it's made it's
1569 * way up to us.
1570 */
1571static int qt2_box_flush(struct usb_serial *serial, unsigned char uart_number,
1572 unsigned short rcv_or_xmit)
1573{
1574 int result;
1575 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
1576 QT2_FLUSH_DEVICE, 0x40, rcv_or_xmit, uart_number, NULL, 0,
1577 300);
1578 return result;
1579}
1580
983/* 1581/*
984 * last things in file: stuff to register this driver into the generic 1582 * last things in file: stuff to register this driver into the generic
985 * USB serial framework. 1583 * USB serial framework.
@@ -995,20 +1593,22 @@ static struct usb_serial_driver quatech2_device = {
995 .id_table = quausb2_id_table, 1593 .id_table = quausb2_id_table,
996 .num_ports = 8, 1594 .num_ports = 8,
997 .open = qt2_open, 1595 .open = qt2_open,
998 /*.close = qt_close, 1596 .close = qt2_close,
999 .write = qt_write, 1597 .write = qt2_write,
1000 .write_room = qt_write_room, 1598 .write_room = qt2_write_room,
1001 .chars_in_buffer = qt_chars_in_buffer, 1599 .chars_in_buffer = qt2_chars_in_buffer,
1002 .throttle = qt_throttle, 1600 /*.throttle = qt_throttle,
1003 .unthrottle = qt_unthrottle,*/ 1601 .unthrottle = qt_unthrottle,*/
1004 .calc_num_ports = qt2_calc_num_ports, 1602 .calc_num_ports = qt2_calc_num_ports,
1005 /*.ioctl = qt_ioctl, 1603 .ioctl = qt2_ioctl,
1006 .set_termios = qt_set_termios, 1604 /*.set_termios = qt_set_termios,
1007 .break_ctl = qt_break, 1605 .break_ctl = qt_break,*/
1008 .tiocmget = qt_tiocmget, 1606 .tiocmget = qt2_tiocmget,
1009 .tiocmset = qt_tiocmset,*/ 1607 .tiocmset = qt2_tiocmset,
1010 .attach = qt2_attach, 1608 .attach = qt2_attach,
1011 .release = qt2_release, 1609 .release = qt2_release,
1610 .read_bulk_callback = qt2_read_bulk_callback,
1611 .write_bulk_callback = qt2_write_bulk_callback,
1012}; 1612};
1013 1613
1014static int __init quausb2_usb_init(void) 1614static int __init quausb2_usb_init(void)
@@ -1038,8 +1638,6 @@ failed_usb_serial_register:
1038 return retval; 1638 return retval;
1039} 1639}
1040 1640
1041
1042
1043static void __exit quausb2_usb_exit(void) 1641static void __exit quausb2_usb_exit(void)
1044{ 1642{
1045 usb_deregister(&quausb2_usb_driver); 1643 usb_deregister(&quausb2_usb_driver);