diff options
author | Jerry Zhang | 2018-05-21 16:22:43 -0500 |
---|---|---|
committer | Jerry Zhang | 2018-07-17 13:54:38 -0500 |
commit | cda7c3b27c4bbea5e2bf0ece91ce77452ccd374e (patch) | |
tree | 913595884b4164b404f0d8ca8fe68e11a1ac72be /adb | |
parent | 16b78db9454b8a42b453c815c058fb52874b3104 (diff) | |
download | platform-system-core-cda7c3b27c4bbea5e2bf0ece91ce77452ccd374e.tar.gz platform-system-core-cda7c3b27c4bbea5e2bf0ece91ce77452ccd374e.tar.xz platform-system-core-cda7c3b27c4bbea5e2bf0ece91ce77452ccd374e.zip |
adb: Add io size and zero packet to usb_handle
Fastboot protocol doesn't include zero packets,
so make it possible to configure that.
Allow fastbootd to see how many bytes the handle
can read/write at once.
Test: adb works
Bug: 78793464
Change-Id: I31e444f384d9d0cdf1ea936439b2028f8151c3b8
Diffstat (limited to 'adb')
-rw-r--r-- | adb/daemon/include/adbd/usb.h | 5 | ||||
-rw-r--r-- | adb/daemon/usb.cpp | 30 |
2 files changed, 20 insertions, 15 deletions
diff --git a/adb/daemon/include/adbd/usb.h b/adb/daemon/include/adbd/usb.h index ee81e25c9..7905d9d27 100644 --- a/adb/daemon/include/adbd/usb.h +++ b/adb/daemon/include/adbd/usb.h | |||
@@ -55,6 +55,9 @@ struct usb_handle { | |||
55 | // read and write threads. | 55 | // read and write threads. |
56 | struct aio_block read_aiob; | 56 | struct aio_block read_aiob; |
57 | struct aio_block write_aiob; | 57 | struct aio_block write_aiob; |
58 | |||
59 | bool reads_zero_packets; | ||
60 | size_t io_size; | ||
58 | }; | 61 | }; |
59 | 62 | ||
60 | usb_handle *create_usb_handle(); | 63 | usb_handle *create_usb_handle(unsigned num_bufs, unsigned io_size); |
diff --git a/adb/daemon/usb.cpp b/adb/daemon/usb.cpp index 5242718a2..4165c7b3e 100644 --- a/adb/daemon/usb.cpp +++ b/adb/daemon/usb.cpp | |||
@@ -53,7 +53,7 @@ using namespace std::chrono_literals; | |||
53 | #define USB_FFS_BULK_SIZE 16384 | 53 | #define USB_FFS_BULK_SIZE 16384 |
54 | 54 | ||
55 | // Number of buffers needed to fit MAX_PAYLOAD, with an extra for ZLPs. | 55 | // Number of buffers needed to fit MAX_PAYLOAD, with an extra for ZLPs. |
56 | #define USB_FFS_NUM_BUFS ((MAX_PAYLOAD / USB_FFS_BULK_SIZE) + 1) | 56 | #define USB_FFS_NUM_BUFS ((4 * MAX_PAYLOAD / USB_FFS_BULK_SIZE) + 1) |
57 | 57 | ||
58 | #define cpu_to_le16(x) htole16(x) | 58 | #define cpu_to_le16(x) htole16(x) |
59 | #define cpu_to_le32(x) htole32(x) | 59 | #define cpu_to_le32(x) htole32(x) |
@@ -226,16 +226,16 @@ static const struct { | |||
226 | }, | 226 | }, |
227 | }; | 227 | }; |
228 | 228 | ||
229 | static void aio_block_init(aio_block* aiob) { | 229 | static void aio_block_init(aio_block* aiob, unsigned num_bufs) { |
230 | aiob->iocb.resize(USB_FFS_NUM_BUFS); | 230 | aiob->iocb.resize(num_bufs); |
231 | aiob->iocbs.resize(USB_FFS_NUM_BUFS); | 231 | aiob->iocbs.resize(num_bufs); |
232 | aiob->events.resize(USB_FFS_NUM_BUFS); | 232 | aiob->events.resize(num_bufs); |
233 | aiob->num_submitted = 0; | 233 | aiob->num_submitted = 0; |
234 | for (unsigned i = 0; i < USB_FFS_NUM_BUFS; i++) { | 234 | for (unsigned i = 0; i < num_bufs; i++) { |
235 | aiob->iocbs[i] = &aiob->iocb[i]; | 235 | aiob->iocbs[i] = &aiob->iocb[i]; |
236 | } | 236 | } |
237 | memset(&aiob->ctx, 0, sizeof(aiob->ctx)); | 237 | memset(&aiob->ctx, 0, sizeof(aiob->ctx)); |
238 | if (io_setup(USB_FFS_NUM_BUFS, &aiob->ctx)) { | 238 | if (io_setup(num_bufs, &aiob->ctx)) { |
239 | D("[ aio: got error on io_setup (%d) ]", errno); | 239 | D("[ aio: got error on io_setup (%d) ]", errno); |
240 | } | 240 | } |
241 | } | 241 | } |
@@ -318,6 +318,7 @@ static bool init_functionfs(struct usb_handle* h) { | |||
318 | 318 | ||
319 | h->read_aiob.fd = h->bulk_out; | 319 | h->read_aiob.fd = h->bulk_out; |
320 | h->write_aiob.fd = h->bulk_in; | 320 | h->write_aiob.fd = h->bulk_in; |
321 | h->reads_zero_packets = true; | ||
321 | return true; | 322 | return true; |
322 | 323 | ||
323 | err: | 324 | err: |
@@ -408,7 +409,7 @@ static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) { | |||
408 | aio_block* aiob = read ? &h->read_aiob : &h->write_aiob; | 409 | aio_block* aiob = read ? &h->read_aiob : &h->write_aiob; |
409 | bool zero_packet = false; | 410 | bool zero_packet = false; |
410 | 411 | ||
411 | int num_bufs = len / USB_FFS_BULK_SIZE + (len % USB_FFS_BULK_SIZE == 0 ? 0 : 1); | 412 | int num_bufs = len / h->io_size + (len % h->io_size == 0 ? 0 : 1); |
412 | const char* cur_data = reinterpret_cast<const char*>(data); | 413 | const char* cur_data = reinterpret_cast<const char*>(data); |
413 | int packet_size = getMaxPacketSize(aiob->fd); | 414 | int packet_size = getMaxPacketSize(aiob->fd); |
414 | 415 | ||
@@ -418,7 +419,7 @@ static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) { | |||
418 | } | 419 | } |
419 | 420 | ||
420 | for (int i = 0; i < num_bufs; i++) { | 421 | for (int i = 0; i < num_bufs; i++) { |
421 | int buf_len = std::min(len, USB_FFS_BULK_SIZE); | 422 | int buf_len = std::min(len, static_cast<int>(h->io_size)); |
422 | io_prep(&aiob->iocb[i], aiob->fd, cur_data, buf_len, 0, read); | 423 | io_prep(&aiob->iocb[i], aiob->fd, cur_data, buf_len, 0, read); |
423 | 424 | ||
424 | len -= buf_len; | 425 | len -= buf_len; |
@@ -427,7 +428,7 @@ static int usb_ffs_do_aio(usb_handle* h, const void* data, int len, bool read) { | |||
427 | if (len == 0 && buf_len % packet_size == 0 && read) { | 428 | if (len == 0 && buf_len % packet_size == 0 && read) { |
428 | // adb does not expect the device to send a zero packet after data transfer, | 429 | // adb does not expect the device to send a zero packet after data transfer, |
429 | // but the host *does* send a zero packet for the device to read. | 430 | // but the host *does* send a zero packet for the device to read. |
430 | zero_packet = true; | 431 | zero_packet = h->reads_zero_packets; |
431 | } | 432 | } |
432 | } | 433 | } |
433 | if (zero_packet) { | 434 | if (zero_packet) { |
@@ -507,7 +508,7 @@ static void usb_ffs_close(usb_handle* h) { | |||
507 | h->notify.notify_one(); | 508 | h->notify.notify_one(); |
508 | } | 509 | } |
509 | 510 | ||
510 | usb_handle *create_usb_handle() { | 511 | usb_handle *create_usb_handle(unsigned num_bufs, unsigned io_size) { |
511 | usb_handle* h = new usb_handle(); | 512 | usb_handle* h = new usb_handle(); |
512 | 513 | ||
513 | if (android::base::GetBoolProperty("sys.usb.ffs.aio_compat", false)) { | 514 | if (android::base::GetBoolProperty("sys.usb.ffs.aio_compat", false)) { |
@@ -518,9 +519,10 @@ usb_handle *create_usb_handle() { | |||
518 | } else { | 519 | } else { |
519 | h->write = usb_ffs_aio_write; | 520 | h->write = usb_ffs_aio_write; |
520 | h->read = usb_ffs_aio_read; | 521 | h->read = usb_ffs_aio_read; |
521 | aio_block_init(&h->read_aiob); | 522 | aio_block_init(&h->read_aiob, num_bufs); |
522 | aio_block_init(&h->write_aiob); | 523 | aio_block_init(&h->write_aiob, num_bufs); |
523 | } | 524 | } |
525 | h->io_size = io_size; | ||
524 | h->kick = usb_ffs_kick; | 526 | h->kick = usb_ffs_kick; |
525 | h->close = usb_ffs_close; | 527 | h->close = usb_ffs_close; |
526 | return h; | 528 | return h; |
@@ -531,7 +533,7 @@ void usb_init() { | |||
531 | dummy_fd = adb_open("/dev/null", O_WRONLY); | 533 | dummy_fd = adb_open("/dev/null", O_WRONLY); |
532 | CHECK_NE(dummy_fd, -1); | 534 | CHECK_NE(dummy_fd, -1); |
533 | 535 | ||
534 | std::thread(usb_ffs_open_thread, create_usb_handle()).detach(); | 536 | std::thread(usb_ffs_open_thread, create_usb_handle(USB_FFS_NUM_BUFS, USB_FFS_BULK_SIZE)).detach(); |
535 | } | 537 | } |
536 | 538 | ||
537 | int usb_write(usb_handle* h, const void* data, int len) { | 539 | int usb_write(usb_handle* h, const void* data, int len) { |