USB: serial: keyspan_pda: refactor write-room handling
Add helper to retrieve the available device transfer-buffer space. Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Johan Hovold <johan@kernel.org>
This commit is contained in:
parent
320f9028c7
commit
79fe6826a5
@ -98,6 +98,42 @@ static const struct usb_device_id id_table_fake_xircom[] = {
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static int keyspan_pda_get_write_room(struct keyspan_pda_private *priv)
|
||||||
|
{
|
||||||
|
struct usb_serial_port *port = priv->port;
|
||||||
|
struct usb_serial *serial = priv->serial;
|
||||||
|
u8 *room;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
room = kmalloc(1, GFP_KERNEL);
|
||||||
|
if (!room)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
rc = usb_control_msg(serial->dev,
|
||||||
|
usb_rcvctrlpipe(serial->dev, 0),
|
||||||
|
6, /* write_room */
|
||||||
|
USB_TYPE_VENDOR | USB_RECIP_INTERFACE
|
||||||
|
| USB_DIR_IN,
|
||||||
|
0, /* value: 0 means "remaining room" */
|
||||||
|
0, /* index */
|
||||||
|
room,
|
||||||
|
1,
|
||||||
|
2000);
|
||||||
|
if (rc != 1) {
|
||||||
|
if (rc >= 0)
|
||||||
|
rc = -EIO;
|
||||||
|
dev_dbg(&port->dev, "roomquery failed: %d\n", rc);
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_dbg(&port->dev, "roomquery says %d\n", *room);
|
||||||
|
rc = *room;
|
||||||
|
out_free:
|
||||||
|
kfree(room);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
static void keyspan_pda_request_unthrottle(struct work_struct *work)
|
static void keyspan_pda_request_unthrottle(struct work_struct *work)
|
||||||
{
|
{
|
||||||
struct keyspan_pda_private *priv =
|
struct keyspan_pda_private *priv =
|
||||||
@ -436,7 +472,6 @@ static int keyspan_pda_tiocmset(struct tty_struct *tty,
|
|||||||
static int keyspan_pda_write(struct tty_struct *tty,
|
static int keyspan_pda_write(struct tty_struct *tty,
|
||||||
struct usb_serial_port *port, const unsigned char *buf, int count)
|
struct usb_serial_port *port, const unsigned char *buf, int count)
|
||||||
{
|
{
|
||||||
struct usb_serial *serial = port->serial;
|
|
||||||
int request_unthrottle = 0;
|
int request_unthrottle = 0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct keyspan_pda_private *priv;
|
struct keyspan_pda_private *priv;
|
||||||
@ -479,38 +514,11 @@ static int keyspan_pda_write(struct tty_struct *tty,
|
|||||||
device how much room it really has. This is done only on
|
device how much room it really has. This is done only on
|
||||||
scheduler time, since usb_control_msg() sleeps. */
|
scheduler time, since usb_control_msg() sleeps. */
|
||||||
if (count > priv->tx_room && !in_interrupt()) {
|
if (count > priv->tx_room && !in_interrupt()) {
|
||||||
u8 *room;
|
rc = keyspan_pda_get_write_room(priv);
|
||||||
|
if (rc < 0)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
room = kmalloc(1, GFP_KERNEL);
|
priv->tx_room = rc;
|
||||||
if (!room) {
|
|
||||||
rc = -ENOMEM;
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = usb_control_msg(serial->dev,
|
|
||||||
usb_rcvctrlpipe(serial->dev, 0),
|
|
||||||
6, /* write_room */
|
|
||||||
USB_TYPE_VENDOR | USB_RECIP_INTERFACE
|
|
||||||
| USB_DIR_IN,
|
|
||||||
0, /* value: 0 means "remaining room" */
|
|
||||||
0, /* index */
|
|
||||||
room,
|
|
||||||
1,
|
|
||||||
2000);
|
|
||||||
if (rc > 0) {
|
|
||||||
dev_dbg(&port->dev, "roomquery says %d\n", *room);
|
|
||||||
priv->tx_room = *room;
|
|
||||||
}
|
|
||||||
kfree(room);
|
|
||||||
if (rc < 0) {
|
|
||||||
dev_dbg(&port->dev, "roomquery failed\n");
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
if (rc == 0) {
|
|
||||||
dev_dbg(&port->dev, "roomquery returned 0 bytes\n");
|
|
||||||
rc = -EIO; /* device didn't return any data */
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count >= priv->tx_room) {
|
if (count >= priv->tx_room) {
|
||||||
@ -614,48 +622,27 @@ static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
|
|||||||
static int keyspan_pda_open(struct tty_struct *tty,
|
static int keyspan_pda_open(struct tty_struct *tty,
|
||||||
struct usb_serial_port *port)
|
struct usb_serial_port *port)
|
||||||
{
|
{
|
||||||
struct usb_serial *serial = port->serial;
|
struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
|
||||||
u8 *room;
|
int rc;
|
||||||
int rc = 0;
|
|
||||||
struct keyspan_pda_private *priv;
|
|
||||||
|
|
||||||
/* find out how much room is in the Tx ring */
|
/* find out how much room is in the Tx ring */
|
||||||
room = kmalloc(1, GFP_KERNEL);
|
rc = keyspan_pda_get_write_room(priv);
|
||||||
if (!room)
|
if (rc < 0)
|
||||||
return -ENOMEM;
|
return rc;
|
||||||
|
|
||||||
rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
|
priv->tx_room = rc;
|
||||||
6, /* write_room */
|
priv->tx_throttled = rc ? 0 : 1;
|
||||||
USB_TYPE_VENDOR | USB_RECIP_INTERFACE
|
|
||||||
| USB_DIR_IN,
|
|
||||||
0, /* value */
|
|
||||||
0, /* index */
|
|
||||||
room,
|
|
||||||
1,
|
|
||||||
2000);
|
|
||||||
if (rc < 0) {
|
|
||||||
dev_dbg(&port->dev, "%s - roomquery failed\n", __func__);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (rc == 0) {
|
|
||||||
dev_dbg(&port->dev, "%s - roomquery returned 0 bytes\n", __func__);
|
|
||||||
rc = -EIO;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
priv = usb_get_serial_port_data(port);
|
|
||||||
priv->tx_room = *room;
|
|
||||||
priv->tx_throttled = *room ? 0 : 1;
|
|
||||||
|
|
||||||
/*Start reading from the device*/
|
/*Start reading from the device*/
|
||||||
rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
|
rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
|
dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
|
||||||
goto error;
|
return rc;
|
||||||
}
|
}
|
||||||
error:
|
|
||||||
kfree(room);
|
return 0;
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyspan_pda_close(struct usb_serial_port *port)
|
static void keyspan_pda_close(struct usb_serial_port *port)
|
||||||
{
|
{
|
||||||
struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
|
struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
|
||||||
|
Loading…
Reference in New Issue
Block a user