[usb] Add generic USB network device framework
[ipxe.git] / src / include / ipxe / usbnet.h
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 );
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 */
27 struct usb_endpoint intr;
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
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,
45 struct usb_endpoint_driver_operations *intr,
46 struct usb_endpoint_driver_operations *in,
47 struct usb_endpoint_driver_operations *out ) {
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 extern int usbnet_open ( struct usbnet_device *usbnet );
57 extern void usbnet_close ( struct usbnet_device *usbnet );
58 extern int usbnet_refill ( struct usbnet_device *usbnet );
59 extern int usbnet_describe ( struct usbnet_device *usbnet,
60 struct usb_configuration_descriptor *config );
61
62 #endif /* _IPXE_USBNET_H */