iPXE
usbnet.h
Go to the documentation of this file.
1 #ifndef _IPXE_USBNET_H
2 #define _IPXE_USBNET_H
3 
4 /** @file
5  *
6  * USB network devices
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_SECBOOT ( PERMITTED );
12 
13 #include <ipxe/usb.h>
14 
15 /** A USB network device */
16 struct usbnet_device {
17  /** USB function */
18  struct usb_function *func;
19 
20  /** Communications interface */
21  unsigned int comms;
22  /** Data interface */
23  unsigned int data;
24  /** Alternate setting for data interface */
25  unsigned int alternate;
26 
27  /** Interrupt endpoint */
29  /** Bulk IN endpoint */
30  struct usb_endpoint in;
31  /** Bulk OUT endpoint */
32  struct usb_endpoint out;
33 };
34 
35 /**
36  * Initialise USB network device
37  *
38  * @v usbnet USB network device
39  * @v func USB function
40  * @v intr Interrupt endpoint operations, or NULL
41  * @v in Bulk IN endpoint operations
42  * @v out Bulk OUT endpoint operations
43  */
44 static inline __attribute__ (( always_inline )) void
45 usbnet_init ( struct usbnet_device *usbnet, struct usb_function *func,
49  struct usb_device *usb = func->usb;
50 
51  usbnet->func = func;
52  usb_endpoint_init ( &usbnet->intr, usb, intr );
53  usb_endpoint_init ( &usbnet->in, usb, in );
54  usb_endpoint_init ( &usbnet->out, usb, out );
55 }
56 
57 /**
58  * Check if USB network device has an interrupt endpoint
59  *
60  * @v usbnet USB network device
61  * @ret has_intr Device has an interrupt endpoint
62  */
63 static inline __attribute__ (( always_inline )) int
64 usbnet_has_intr ( struct usbnet_device *usbnet ) {
65 
66  return ( usbnet->intr.driver != NULL );
67 }
68 
69 extern int usbnet_open ( struct usbnet_device *usbnet );
70 extern void usbnet_close ( struct usbnet_device *usbnet );
71 extern int usbnet_refill ( struct usbnet_device *usbnet );
72 extern int usbnet_describe ( struct usbnet_device *usbnet,
73  struct usb_configuration_descriptor *config );
74 
75 #endif /* _IPXE_USBNET_H */
#define __attribute__(x)
Definition: compiler.h:10
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:55
unsigned int comms
Communications interface.
Definition: usbnet.h:21
__be32 in[4]
Definition: CIB_PRM.h:35
FILE_SECBOOT(PERMITTED)
unsigned int data
Data interface.
Definition: usbnet.h:23
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:28
__be32 out[4]
Definition: CIB_PRM.h:36
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:32
A USB endpoint.
Definition: usb.h:404
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
A USB device.
Definition: usb.h:723
A USB network device.
Definition: usbnet.h:16
unsigned int alternate
Alternate setting for data interface.
Definition: usbnet.h:25
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:30
struct usb_device * usb
USB device.
Definition: usb.h:678
static void usb_endpoint_init(struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
Initialise USB endpoint.
Definition: usb.h:540
A USB configuration descriptor.
Definition: usb.h:210
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:278
Universal Serial Bus (USB)
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.
Definition: usbnet.h:45
static int usbnet_has_intr(struct usbnet_device *usbnet)
Check if USB network device has an interrupt endpoint.
Definition: usbnet.h:64
struct usb_endpoint_driver_operations * driver
Driver operations.
Definition: usb.h:431
USB endpoint driver operations.
Definition: usb.h:489
A USB function.
Definition: usb.h:674
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:152
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:128
struct usb_function * func
USB function.
Definition: usbnet.h:18