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 
12 #include <ipxe/usb.h>
13 
14 /** A USB network device */
15 struct usbnet_device {
16  /** USB function */
17  struct usb_function *func;
18 
19  /** Communications interface */
20  unsigned int comms;
21  /** Data interface */
22  unsigned int data;
23  /** Alternate setting for data interface */
24  unsigned int alternate;
25 
26  /** Interrupt endpoint */
28  /** Bulk IN endpoint */
29  struct usb_endpoint in;
30  /** Bulk OUT endpoint */
31  struct usb_endpoint out;
32 };
33 
34 /**
35  * Initialise USB network device
36  *
37  * @v usbnet USB network device
38  * @v func USB function
39  * @v intr Interrupt endpoint operations, or NULL
40  * @v in Bulk IN endpoint operations
41  * @v out Bulk OUT endpoint operations
42  */
43 static inline __attribute__ (( always_inline )) void
44 usbnet_init ( struct usbnet_device *usbnet, struct usb_function *func,
48  struct usb_device *usb = func->usb;
49 
50  usbnet->func = func;
51  usb_endpoint_init ( &usbnet->intr, usb, intr );
52  usb_endpoint_init ( &usbnet->in, usb, in );
53  usb_endpoint_init ( &usbnet->out, usb, out );
54 }
55 
56 /**
57  * Check if USB network device has an interrupt endpoint
58  *
59  * @v usbnet USB network device
60  * @ret has_intr Device has an interrupt endpoint
61  */
62 static inline __attribute__ (( always_inline )) int
63 usbnet_has_intr ( struct usbnet_device *usbnet ) {
64 
65  return ( usbnet->intr.driver != NULL );
66 }
67 
68 extern int usbnet_open ( struct usbnet_device *usbnet );
69 extern void usbnet_close ( struct usbnet_device *usbnet );
70 extern int usbnet_refill ( struct usbnet_device *usbnet );
71 extern int usbnet_describe ( struct usbnet_device *usbnet,
72  struct usb_configuration_descriptor *config );
73 
74 #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:54
unsigned int comms
Communications interface.
Definition: usbnet.h:20
__be32 in[4]
Definition: CIB_PRM.h:35
unsigned int data
Data interface.
Definition: usbnet.h:22
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
A USB endpoint.
Definition: usb.h:389
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
__be32 out[4]
Definition: CIB_PRM.h:36
A USB device.
Definition: usb.h:708
A USB network device.
Definition: usbnet.h:15
unsigned int alternate
Alternate setting for data interface.
Definition: usbnet.h:24
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
struct usb_device * usb
USB device.
Definition: usb.h:663
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:525
A USB configuration descriptor.
Definition: usb.h:195
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
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:44
static int usbnet_has_intr(struct usbnet_device *usbnet)
Check if USB network device has an interrupt endpoint.
Definition: usbnet.h:63
struct usb_endpoint_driver_operations * driver
Driver operations.
Definition: usb.h:416
USB endpoint driver operations.
Definition: usb.h:474
A USB function.
Definition: usb.h:659
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:151
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
struct usb_function * func
USB function.
Definition: usbnet.h:17