iPXE
Functions
usbnet.c File Reference

USB network devices. More...

#include <string.h>
#include <errno.h>
#include <ipxe/usb.h>
#include <ipxe/usbnet.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int usbnet_open (struct usbnet_device *usbnet)
 Open USB network device.
void usbnet_close (struct usbnet_device *usbnet)
 Close USB network device.
int usbnet_refill (struct usbnet_device *usbnet)
 Refill USB network device bulk IN and interrupt endpoints.
static int usbnet_comms_describe (struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
 Describe communications interface and interrupt endpoint.
static int usbnet_data_describe (struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
 Describe data interface and bulk endpoints.
int usbnet_describe (struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
 Describe USB network device interfaces.

Detailed Description

USB network devices.

USB network devices use a variety of packet formats and interface descriptors, but tend to have several features in common:

Definition in file usbnet.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int usbnet_open ( struct usbnet_device usbnet)

Open USB network device.

Parameters:
usbnetUSB network device
Return values:
rcReturn status code

Definition at line 54 of file usbnet.c.

References usbnet_device::alternate, usbnet_device::data, DBGC, usbnet_device::func, usbnet_device::in, usbnet_device::intr, usb_function::name, usbnet_device::out, rc, strerror(), usb_function::usb, usb_endpoint_close(), usb_endpoint_open(), usb_refill(), usb_set_interface(), and usbnet_has_intr().

Referenced by acm_open(), axge_open(), dm96xx_open(), ecm_open(), lan78xx_open(), ncm_open(), smsc75xx_open(), and smsc95xx_open().

                                                 {
        struct usb_device *usb = usbnet->func->usb;
        int rc;

        /* Open interrupt endpoint, if applicable */
        if ( usbnet_has_intr ( usbnet ) &&
             ( rc = usb_endpoint_open ( &usbnet->intr ) ) != 0 ) {
                DBGC ( usbnet, "USBNET %s could not open interrupt: %s\n",
                       usbnet->func->name, strerror ( rc ) );
                goto err_open_intr;
        }

        /* Refill interrupt endpoint, if applicable */
        if ( usbnet_has_intr ( usbnet ) &&
             ( rc = usb_refill ( &usbnet->intr ) ) != 0 ) {
                DBGC ( usbnet, "USBNET %s could not refill interrupt: %s\n",
                       usbnet->func->name, strerror ( rc ) );
                goto err_refill_intr;
        }

        /* Select alternate setting for data interface, if applicable */
        if ( usbnet->alternate &&
             ( ( rc = usb_set_interface ( usb, usbnet->data,
                                          usbnet->alternate ) ) != 0 ) ) {
                DBGC ( usbnet, "USBNET %s could not set alternate interface "
                       "%d: %s\n", usbnet->func->name, usbnet->alternate,
                       strerror ( rc ) );
                goto err_set_interface;
        }

        /* Open bulk IN endpoint */
        if ( ( rc = usb_endpoint_open ( &usbnet->in ) ) != 0 ) {
                DBGC ( usbnet, "USBNET %s could not open bulk IN: %s\n",
                       usbnet->func->name, strerror ( rc ) );
                goto err_open_in;
        }

        /* Open bulk OUT endpoint */
        if ( ( rc = usb_endpoint_open ( &usbnet->out ) ) != 0 ) {
                DBGC ( usbnet, "USBNET %s could not open bulk OUT: %s\n",
                       usbnet->func->name, strerror ( rc ) );
                goto err_open_out;
        }

        /* Refill bulk IN endpoint */
        if ( ( rc = usb_refill ( &usbnet->in ) ) != 0 ) {
                DBGC ( usbnet, "USBNET %s could not refill bulk IN: %s\n",
                       usbnet->func->name, strerror ( rc ) );
                goto err_refill_in;
        }

        return 0;

 err_refill_in:
        usb_endpoint_close ( &usbnet->out );
 err_open_out:
        usb_endpoint_close ( &usbnet->in );
 err_open_in:
        if ( usbnet->alternate )
                usb_set_interface ( usb, usbnet->data, 0 );
 err_set_interface:
 err_refill_intr:
        if ( usbnet_has_intr ( usbnet ) )
                usb_endpoint_close ( &usbnet->intr );
 err_open_intr:
        return rc;
}
void usbnet_close ( struct usbnet_device usbnet)

Close USB network device.

Parameters:
usbnetUSB network device

Definition at line 127 of file usbnet.c.

References usbnet_device::alternate, usbnet_device::data, usbnet_device::func, usbnet_device::in, usbnet_device::intr, usbnet_device::out, usb_function::usb, usb_endpoint_close(), usb_set_interface(), and usbnet_has_intr().

Referenced by acm_close(), acm_open(), axge_close(), axge_open(), dm96xx_close(), dm96xx_open(), ecm_close(), ecm_open(), lan78xx_close(), lan78xx_open(), ncm_close(), ncm_open(), smsc75xx_close(), smsc75xx_open(), smsc95xx_close(), and smsc95xx_open().

                                                   {
        struct usb_device *usb = usbnet->func->usb;

        /* Close bulk OUT endpoint */
        usb_endpoint_close ( &usbnet->out );

        /* Close bulk IN endpoint */
        usb_endpoint_close ( &usbnet->in );

        /* Reset alternate setting for data interface, if applicable */
        if ( usbnet->alternate )
                usb_set_interface ( usb, usbnet->data, 0 );

        /* Close interrupt endpoint, if applicable */
        if ( usbnet_has_intr ( usbnet ) )
                usb_endpoint_close ( &usbnet->intr );
}
int usbnet_refill ( struct usbnet_device usbnet)

Refill USB network device bulk IN and interrupt endpoints.

Parameters:
usbnetUSB network device
Return values:
rcReturn status code

Definition at line 151 of file usbnet.c.

References usbnet_device::in, usbnet_device::intr, rc, usb_refill(), and usbnet_has_intr().

Referenced by acm_poll(), axge_poll(), dm96xx_poll(), ecm_poll(), ncm_poll(), smsc75xx_poll(), and smsc95xx_poll().

                                                   {
        int rc;

        /* Refill bulk IN endpoint */
        if ( ( rc = usb_refill ( &usbnet->in ) ) != 0 )
                return rc;

        /* Refill interrupt endpoint, if applicable */
        if ( usbnet_has_intr ( usbnet ) &&
             ( rc = usb_refill ( &usbnet->intr ) ) != 0 ) {
                return rc;
        }

        return 0;
}
static int usbnet_comms_describe ( struct usbnet_device usbnet,
struct usb_configuration_descriptor config 
) [static]

Describe communications interface and interrupt endpoint.

Parameters:
usbnetUSB network device
configConfiguration descriptor
Return values:
rcReturn status code

Definition at line 174 of file usbnet.c.

References usbnet_device::comms, usb_function_descriptor::count, DBGC, usb_function::desc, ENOENT, usbnet_device::func, usb_function::interface, usbnet_device::intr, usb_function::name, rc, usb_endpoint_described(), usb_interface_descriptor(), and USB_INTERRUPT_IN.

Referenced by usbnet_describe().

                                                                               {
        struct usb_interface_descriptor *desc;
        unsigned int comms;
        unsigned int i;
        int rc;

        /* Iterate over all available interfaces */
        for ( i = 0 ; i < usbnet->func->desc.count ; i++ ) {

                /* Get interface number */
                comms = usbnet->func->interface[i];

                /* Locate interface descriptor */
                desc = usb_interface_descriptor ( config, comms, 0 );
                if ( ! desc )
                        continue;

                /* Describe interrupt endpoint */
                if ( ( rc = usb_endpoint_described ( &usbnet->intr, config,
                                                     desc, USB_INTERRUPT_IN,
                                                     0 ) ) != 0 )
                        continue;

                /* Record communications interface */
                usbnet->comms = comms;
                DBGC ( usbnet, "USBNET %s found communications interface %d\n",
                       usbnet->func->name, comms );
                return 0;
        }

        DBGC ( usbnet, "USBNET %s found no communications interface\n",
               usbnet->func->name );
        return -ENOENT;
}
static int usbnet_data_describe ( struct usbnet_device usbnet,
struct usb_configuration_descriptor config 
) [static]

Describe data interface and bulk endpoints.

Parameters:
usbnetUSB network device
configConfiguration descriptor
Return values:
rcReturn status code

Definition at line 217 of file usbnet.c.

References usbnet_device::alternate, usb_function_descriptor::count, usbnet_device::data, data, DBGC, usb_function::desc, ENOENT, usbnet_device::func, usbnet_device::in, usb_function::interface, usb_function::name, usbnet_device::out, rc, USB_BULK_IN, USB_BULK_OUT, usb_endpoint_described(), and usb_interface_descriptor().

Referenced by usbnet_describe().

                                                                               {
        struct usb_interface_descriptor *desc;
        unsigned int data;
        unsigned int alt;
        unsigned int i;
        int rc;

        /* Iterate over all available interfaces */
        for ( i = 0 ; i < usbnet->func->desc.count ; i++ ) {

                /* Get interface number */
                data = usbnet->func->interface[i];

                /* Iterate over all existent alternate settings */
                for ( alt = 0 ; ; alt++ ) {

                        /* Locate interface descriptor */
                        desc = usb_interface_descriptor ( config, data, alt );
                        if ( ! desc )
                                break;

                        /* Describe bulk IN endpoint */
                        if ( ( rc = usb_endpoint_described ( &usbnet->in,
                                                             config, desc,
                                                             USB_BULK_IN,
                                                             0 ) ) != 0 )
                                continue;

                        /* Describe bulk OUT endpoint */
                        if ( ( rc = usb_endpoint_described ( &usbnet->out,
                                                             config, desc,
                                                             USB_BULK_OUT,
                                                             0 ) ) != 0 )
                                continue;

                        /* Record data interface and alternate setting */
                        usbnet->data = data;
                        usbnet->alternate = alt;
                        DBGC ( usbnet, "USBNET %s found data interface %d",
                               usbnet->func->name, data );
                        if ( alt )
                                DBGC ( usbnet, " using alternate %d", alt );
                        DBGC ( usbnet, "\n" );
                        return 0;
                }
        }

        DBGC ( usbnet, "USBNET %s found no data interface\n",
               usbnet->func->name );
        return -ENOENT;
}
int usbnet_describe ( struct usbnet_device usbnet,
struct usb_configuration_descriptor config 
)

Describe USB network device interfaces.

Parameters:
usbnetUSB network device
configConfiguration descriptor
Return values:
rcReturn status code

Definition at line 277 of file usbnet.c.

References rc, usbnet_comms_describe(), usbnet_data_describe(), and usbnet_has_intr().

Referenced by acm_probe(), axge_probe(), dm96xx_probe(), ecm_probe(), lan78xx_probe(), ncm_probe(), smsc75xx_probe(), and smsc95xx_probe().

                                                                    {
        int rc;

        /* Describe communications interface, if applicable */
        if ( usbnet_has_intr ( usbnet ) &&
             ( rc = usbnet_comms_describe ( usbnet, config ) ) != 0 ) {
                return rc;
        }

        /* Describe data interface */
        if ( ( rc = usbnet_data_describe ( usbnet, config ) ) != 0 )
                return rc;

        return 0;
}