]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[usb] Allow endpoints to be refilled to a specified upper limit
authorMichael Brown <mcb30@ipxe.org>
Mon, 12 Oct 2020 14:28:26 +0000 (15:28 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 12 Oct 2020 14:28:26 +0000 (15:28 +0100)
For USB mass storage devices, we do not want to submit more bulk IN
packets than are required for the inbound data, since this will waste
memory.

Allow an upper limit to be specified on each refill attempt.  The
endpoint will be refilled to the lower of this limit or the limit
specified by usb_refill_init().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/drivers/bus/usb.c
src/include/ipxe/usb.h

index 88df9c64ae974b9a0449c279239a3e0970c4c927..70a86c913fcd06e1b66e6353e177f88c501ad393 100644 (file)
@@ -651,12 +651,13 @@ int usb_prefill ( struct usb_endpoint *ep ) {
 }
 
 /**
- * Refill endpoint
+ * Refill endpoint up to specified limit
  *
  * @v ep               USB endpoint
+ * @v max              Fill limit
  * @ret rc             Return status code
  */
-int usb_refill ( struct usb_endpoint *ep ) {
+int usb_refill_limit ( struct usb_endpoint *ep, unsigned int max ) {
        struct io_buffer *iobuf;
        size_t reserve = ep->reserve;
        size_t len = ( ep->len ? ep->len : ep->mtu );
@@ -667,7 +668,9 @@ int usb_refill ( struct usb_endpoint *ep ) {
        assert ( ep->max > 0 );
 
        /* Refill endpoint */
-       while ( ep->fill < ep->max ) {
+       if ( max > ep->max )
+               max = ep->max;
+       while ( ep->fill < max ) {
 
                /* Get or allocate buffer */
                if ( list_empty ( &ep->recycled ) ) {
@@ -698,6 +701,16 @@ int usb_refill ( struct usb_endpoint *ep ) {
        return 0;
 }
 
+/**
+ * Refill endpoint
+ *
+ * @v ep               USB endpoint
+ * @ret rc             Return status code
+ */
+int usb_refill ( struct usb_endpoint *ep ) {
+       return usb_refill_limit ( ep, ep->max );
+}
+
 /**
  * Discard endpoint recycled buffer list
  *
index a05ac613c7ed8b871a30699b96e6a28774bfe82c..70d6daf333b80e0e23184ab478252a27fe89c627 100644 (file)
@@ -621,6 +621,7 @@ usb_recycle ( struct usb_endpoint *ep, struct io_buffer *iobuf ) {
 }
 
 extern int usb_prefill ( struct usb_endpoint *ep );
+extern int usb_refill_limit ( struct usb_endpoint *ep, unsigned int max );
 extern int usb_refill ( struct usb_endpoint *ep );
 extern void usb_flush ( struct usb_endpoint *ep );