usb: bugfixes for usb-serial @ xhci.
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQIcBAABCgAGBQJecJ1MAAoJEEy22O7T6HE4+QgP/iYyRjO/tR+eO9pxoCJs1KRi HALrVizRYl73//PgTp/Gy+ZVLGXipzKHsITBZPUREBtSmrWOzBJDTxc5ouVsL8FS D0xGSTVQNQjFGLOPFNpP1ei7AQny9lEy849wBFV1YaWOcnCc0Ckw/oneJ4e4j0Lp TEVV5vdurhadz+6fO/++oS/Ms156G8IDfzpHzmpWOmEQ5Wwknk3ko0OSHS1D8T8h eLVzOVc974vXAHLdLXOMs9zu/BwYfoZkRxawoNNlBQyFidKfvAdUktJchp+6h4Yu NhhQQc6Pt1+MuUhlrH8Z0BPbaSZHzPpQWPbza2cOnF8OA8Asogi6ruiwxGhsqrtA 9H8r2DWDJE6j1pyu5QRT4aC62A8AKe+E3hjurj0n2HkL+X6DMmhJ4YEiMjedIqQq BN4szl2LgUeF9PKI0JRl9ZZj/VAewViPFJPnx0uZ7gDYBIvpetIvQaIeyQK+RgIC wZolY0ryeyNEUcPlWRkArbK9rcbA/+cAJRwSY9nG4J3/TR4riQGw3uNFYPwdU888 UfSJKv0uYNF9roivtHqu6jX49G5bDwMn7W2Gf5Aj6D7g6Q53dSwwHum93JuR42iY weotkKERWlJ52LAlJ/Jdr6rYFDSTyND16bfBbkFgYKtppvMSfK7xXQLFbtmHsYmR HVWq7lGntemGlO7D1JSD =Le6M -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/kraxel/tags/usb-20200317-pull-request' into staging usb: bugfixes for usb-serial @ xhci. # gpg: Signature made Tue 17 Mar 2020 09:50:04 GMT # gpg: using RSA key 4CB6D8EED3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>" [full] # gpg: aka "Gerd Hoffmann <gerd@kraxel.org>" [full] # gpg: aka "Gerd Hoffmann (private) <kraxel@gmail.com>" [full] # Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138 * remotes/kraxel/tags/usb-20200317-pull-request: usb-serial: Fix timeout closing the device usb-serial: Increase receive buffer to 496 usb-serial: chunk data to wMaxPacketSize usb-serial: Move USB_TOKEN_IN into a helper function Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
40c67636f6
@ -29,7 +29,7 @@ do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0)
|
||||
#define DPRINTF(fmt, ...) do {} while(0)
|
||||
#endif
|
||||
|
||||
#define RECV_BUF 384
|
||||
#define RECV_BUF (512 - (2 * 8))
|
||||
|
||||
/* Commands */
|
||||
#define FTDI_RESET 0
|
||||
@ -332,7 +332,7 @@ static void usb_serial_handle_control(USBDevice *dev, USBPacket *p,
|
||||
break;
|
||||
case DeviceInVendor | FTDI_GET_MDM_ST:
|
||||
data[0] = usb_get_modem_lines(s) | 1;
|
||||
data[1] = 0;
|
||||
data[1] = FTDI_THRE | FTDI_TEMT;
|
||||
p->actual_length = 2;
|
||||
break;
|
||||
case DeviceOutVendor | FTDI_SET_EVENT_CHR:
|
||||
@ -358,13 +358,67 @@ static void usb_serial_handle_control(USBDevice *dev, USBPacket *p,
|
||||
}
|
||||
}
|
||||
|
||||
static void usb_serial_token_in(USBSerialState *s, USBPacket *p)
|
||||
{
|
||||
const int max_packet_size = desc_iface0.eps[0].wMaxPacketSize;
|
||||
int packet_len;
|
||||
uint8_t header[2];
|
||||
|
||||
packet_len = p->iov.size;
|
||||
if (packet_len <= 2) {
|
||||
p->status = USB_RET_NAK;
|
||||
return;
|
||||
}
|
||||
|
||||
header[0] = usb_get_modem_lines(s) | 1;
|
||||
/* We do not have the uart details */
|
||||
/* handle serial break */
|
||||
if (s->event_trigger && s->event_trigger & FTDI_BI) {
|
||||
s->event_trigger &= ~FTDI_BI;
|
||||
header[1] = FTDI_BI;
|
||||
usb_packet_copy(p, header, 2);
|
||||
return;
|
||||
} else {
|
||||
header[1] = 0;
|
||||
}
|
||||
|
||||
if (!s->recv_used) {
|
||||
p->status = USB_RET_NAK;
|
||||
return;
|
||||
}
|
||||
|
||||
while (s->recv_used && packet_len > 2) {
|
||||
int first_len, len;
|
||||
|
||||
len = MIN(packet_len, max_packet_size);
|
||||
len -= 2;
|
||||
if (len > s->recv_used) {
|
||||
len = s->recv_used;
|
||||
}
|
||||
|
||||
first_len = RECV_BUF - s->recv_ptr;
|
||||
if (first_len > len) {
|
||||
first_len = len;
|
||||
}
|
||||
usb_packet_copy(p, header, 2);
|
||||
usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len);
|
||||
if (len > first_len) {
|
||||
usb_packet_copy(p, s->recv_buf, len - first_len);
|
||||
}
|
||||
s->recv_used -= len;
|
||||
s->recv_ptr = (s->recv_ptr + len) % RECV_BUF;
|
||||
packet_len -= len + 2;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void usb_serial_handle_data(USBDevice *dev, USBPacket *p)
|
||||
{
|
||||
USBSerialState *s = (USBSerialState *)dev;
|
||||
uint8_t devep = p->ep->nr;
|
||||
struct iovec *iov;
|
||||
uint8_t header[2];
|
||||
int i, first_len, len;
|
||||
int i;
|
||||
|
||||
switch (p->pid) {
|
||||
case USB_TOKEN_OUT:
|
||||
@ -382,38 +436,7 @@ static void usb_serial_handle_data(USBDevice *dev, USBPacket *p)
|
||||
case USB_TOKEN_IN:
|
||||
if (devep != 1)
|
||||
goto fail;
|
||||
first_len = RECV_BUF - s->recv_ptr;
|
||||
len = p->iov.size;
|
||||
if (len <= 2) {
|
||||
p->status = USB_RET_NAK;
|
||||
break;
|
||||
}
|
||||
header[0] = usb_get_modem_lines(s) | 1;
|
||||
/* We do not have the uart details */
|
||||
/* handle serial break */
|
||||
if (s->event_trigger && s->event_trigger & FTDI_BI) {
|
||||
s->event_trigger &= ~FTDI_BI;
|
||||
header[1] = FTDI_BI;
|
||||
usb_packet_copy(p, header, 2);
|
||||
break;
|
||||
} else {
|
||||
header[1] = 0;
|
||||
}
|
||||
len -= 2;
|
||||
if (len > s->recv_used)
|
||||
len = s->recv_used;
|
||||
if (!len) {
|
||||
p->status = USB_RET_NAK;
|
||||
break;
|
||||
}
|
||||
if (first_len > len)
|
||||
first_len = len;
|
||||
usb_packet_copy(p, header, 2);
|
||||
usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len);
|
||||
if (len > first_len)
|
||||
usb_packet_copy(p, s->recv_buf, len - first_len);
|
||||
s->recv_used -= len;
|
||||
s->recv_ptr = (s->recv_ptr + len) % RECV_BUF;
|
||||
usb_serial_token_in(s, p);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user