iPXE
Data Structures | Functions
usbnet.h File Reference

USB network devices. More...

#include <ipxe/usb.h>

Go to the source code of this file.

Data Structures

struct  usbnet_device
 A USB network device. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void usbnet_init (struct usbnet_device *usbnet, struct usb_function *func, struct usb_endpoint_driver_operations *intr, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
 Initialise USB network device.
static int usbnet_has_intr (struct usbnet_device *usbnet)
 Check if USB network device has an interrupt endpoint.
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.
int usbnet_describe (struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
 Describe USB network device interfaces.

Detailed Description

USB network devices.

Definition in file usbnet.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void usbnet_init ( struct usbnet_device usbnet,
struct usb_function func,
struct usb_endpoint_driver_operations intr,
struct usb_endpoint_driver_operations in,
struct usb_endpoint_driver_operations out 
) [inline, static]

Initialise USB network device.

Parameters:
usbnetUSB network device
funcUSB function
intrInterrupt endpoint operations, or NULL
inBulk IN endpoint operations
outBulk OUT endpoint operations

Definition at line 44 of file usbnet.h.

References usb_endpoint_init().

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

                                                           {
        struct usb_device *usb = func->usb;

        usbnet->func = func;
        usb_endpoint_init ( &usbnet->intr, usb, intr );
        usb_endpoint_init ( &usbnet->in, usb, in );
        usb_endpoint_init ( &usbnet->out, usb, out );
}
static int usbnet_has_intr ( struct usbnet_device usbnet) [inline, static]

Check if USB network device has an interrupt endpoint.

Parameters:
usbnetUSB network device
Return values:
has_intrDevice has an interrupt endpoint

Definition at line 63 of file usbnet.h.

References NULL.

Referenced by usbnet_close(), usbnet_describe(), usbnet_open(), and usbnet_refill().

                                                 {

        return ( usbnet->intr.driver != NULL );
}
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;
}
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;
}