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)
 
 FILE_SECBOOT (PERMITTED)
 
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. More...
 
static int usbnet_has_intr (struct usbnet_device *usbnet)
 Check if USB network device has an interrupt endpoint. More...
 
int usbnet_open (struct usbnet_device *usbnet)
 Open USB network device. More...
 
void usbnet_close (struct usbnet_device *usbnet)
 Close USB network device. More...
 
int usbnet_refill (struct usbnet_device *usbnet)
 Refill USB network device bulk IN and interrupt endpoints. More...
 
int usbnet_describe (struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
 Describe USB network device interfaces. More...
 

Detailed Description

USB network devices.

Definition in file usbnet.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ usbnet_init()

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 
)
inlinestatic

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 45 of file usbnet.h.

48  {
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 }
__be32 in[4]
Definition: CIB_PRM.h:35
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
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
A USB device.
Definition: usb.h:723
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
struct usb_function * func
USB function.
Definition: usbnet.h:18

References usbnet_device::func, usbnet_device::in, in, intr, usbnet_device::intr, usbnet_device::out, out, usb_function::usb, and usb_endpoint_init().

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

◆ usbnet_has_intr()

static int usbnet_has_intr ( struct usbnet_device usbnet)
inlinestatic

Check if USB network device has an interrupt endpoint.

Parameters
usbnetUSB network device
Return values
has_intrDevice has an interrupt endpoint

Definition at line 64 of file usbnet.h.

64  {
65 
66  return ( usbnet->intr.driver != NULL );
67 }
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:28
struct usb_endpoint_driver_operations * driver
Driver operations.
Definition: usb.h:431
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References usb_endpoint::driver, usbnet_device::intr, and NULL.

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

◆ usbnet_open()

int usbnet_open ( struct usbnet_device usbnet)

Open USB network device.

Parameters
usbnetUSB network device
Return values
rcReturn status code

Definition at line 55 of file usbnet.c.

55  {
56  struct usb_device *usb = usbnet->func->usb;
57  int rc;
58 
59  /* Open interrupt endpoint, if applicable */
60  if ( usbnet_has_intr ( usbnet ) &&
61  ( rc = usb_endpoint_open ( &usbnet->intr ) ) != 0 ) {
62  DBGC ( usbnet, "USBNET %s could not open interrupt: %s\n",
63  usbnet->func->name, strerror ( rc ) );
64  goto err_open_intr;
65  }
66 
67  /* Refill interrupt endpoint, if applicable */
68  if ( usbnet_has_intr ( usbnet ) &&
69  ( rc = usb_refill ( &usbnet->intr ) ) != 0 ) {
70  DBGC ( usbnet, "USBNET %s could not refill interrupt: %s\n",
71  usbnet->func->name, strerror ( rc ) );
72  goto err_refill_intr;
73  }
74 
75  /* Select alternate setting for data interface, if applicable */
76  if ( usbnet->alternate &&
77  ( ( rc = usb_set_interface ( usb, usbnet->data,
78  usbnet->alternate ) ) != 0 ) ) {
79  DBGC ( usbnet, "USBNET %s could not set alternate interface "
80  "%d: %s\n", usbnet->func->name, usbnet->alternate,
81  strerror ( rc ) );
82  goto err_set_interface;
83  }
84 
85  /* Open bulk IN endpoint */
86  if ( ( rc = usb_endpoint_open ( &usbnet->in ) ) != 0 ) {
87  DBGC ( usbnet, "USBNET %s could not open bulk IN: %s\n",
88  usbnet->func->name, strerror ( rc ) );
89  goto err_open_in;
90  }
91 
92  /* Open bulk OUT endpoint */
93  if ( ( rc = usb_endpoint_open ( &usbnet->out ) ) != 0 ) {
94  DBGC ( usbnet, "USBNET %s could not open bulk OUT: %s\n",
95  usbnet->func->name, strerror ( rc ) );
96  goto err_open_out;
97  }
98 
99  /* Refill bulk IN endpoint */
100  if ( ( rc = usb_refill ( &usbnet->in ) ) != 0 ) {
101  DBGC ( usbnet, "USBNET %s could not refill bulk IN: %s\n",
102  usbnet->func->name, strerror ( rc ) );
103  goto err_refill_in;
104  }
105 
106  return 0;
107 
108  err_refill_in:
109  usb_endpoint_close ( &usbnet->out );
110  err_open_out:
111  usb_endpoint_close ( &usbnet->in );
112  err_open_in:
113  if ( usbnet->alternate )
114  usb_set_interface ( usb, usbnet->data, 0 );
115  err_set_interface:
116  err_refill_intr:
117  if ( usbnet_has_intr ( usbnet ) )
118  usb_endpoint_close ( &usbnet->intr );
119  err_open_intr:
120  return rc;
121 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: usb.h:676
#define DBGC(...)
Definition: compiler.h:505
unsigned int data
Data interface.
Definition: usbnet.h:23
int usb_endpoint_open(struct usb_endpoint *ep)
Open USB endpoint.
Definition: usb.c:294
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:400
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:28
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition: usb.c:711
static int usb_set_interface(struct usb_device *usb, unsigned int interface, unsigned int alternate)
Set USB interface alternate setting.
Definition: usb.h:1256
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:32
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
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 int usbnet_has_intr(struct usbnet_device *usbnet)
Check if USB network device has an interrupt endpoint.
Definition: usbnet.h:64
struct usb_function * func
USB function.
Definition: usbnet.h:18

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(), imux_probe(), iphone_open(), lan78xx_open(), ncm_open(), smsc75xx_open(), and smsc95xx_open().

◆ usbnet_close()

void usbnet_close ( struct usbnet_device usbnet)

Close USB network device.

Parameters
usbnetUSB network device

Definition at line 128 of file usbnet.c.

128  {
129  struct usb_device *usb = usbnet->func->usb;
130 
131  /* Close bulk OUT endpoint */
132  usb_endpoint_close ( &usbnet->out );
133 
134  /* Close bulk IN endpoint */
135  usb_endpoint_close ( &usbnet->in );
136 
137  /* Reset alternate setting for data interface, if applicable */
138  if ( usbnet->alternate )
139  usb_set_interface ( usb, usbnet->data, 0 );
140 
141  /* Close interrupt endpoint, if applicable */
142  if ( usbnet_has_intr ( usbnet ) )
143  usb_endpoint_close ( &usbnet->intr );
144 }
unsigned int data
Data interface.
Definition: usbnet.h:23
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:400
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:28
static int usb_set_interface(struct usb_device *usb, unsigned int interface, unsigned int alternate)
Set USB interface alternate setting.
Definition: usb.h:1256
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:32
A USB device.
Definition: usb.h:723
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 int usbnet_has_intr(struct usbnet_device *usbnet)
Check if USB network device has an interrupt endpoint.
Definition: usbnet.h:64
struct usb_function * func
USB function.
Definition: usbnet.h:18

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(), imux_shutdown(), iphone_close(), iphone_open(), lan78xx_close(), lan78xx_open(), ncm_close(), ncm_open(), smsc75xx_close(), smsc75xx_open(), smsc95xx_close(), and smsc95xx_open().

◆ usbnet_refill()

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 152 of file usbnet.c.

152  {
153  int rc;
154 
155  /* Refill bulk IN endpoint */
156  if ( ( rc = usb_refill ( &usbnet->in ) ) != 0 )
157  return rc;
158 
159  /* Refill interrupt endpoint, if applicable */
160  if ( usbnet_has_intr ( usbnet ) &&
161  ( rc = usb_refill ( &usbnet->intr ) ) != 0 ) {
162  return rc;
163  }
164 
165  return 0;
166 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:28
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition: usb.c:711
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:30
static int usbnet_has_intr(struct usbnet_device *usbnet)
Check if USB network device has an interrupt endpoint.
Definition: usbnet.h:64

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

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

◆ usbnet_describe()

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 278 of file usbnet.c.

279  {
280  int rc;
281 
282  /* Describe communications interface, if applicable */
283  if ( usbnet_has_intr ( usbnet ) &&
284  ( rc = usbnet_comms_describe ( usbnet, config ) ) != 0 ) {
285  return rc;
286  }
287 
288  /* Describe data interface */
289  if ( ( rc = usbnet_data_describe ( usbnet, config ) ) != 0 )
290  return rc;
291 
292  return 0;
293 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int usbnet_comms_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe communications interface and interrupt endpoint.
Definition: usbnet.c:175
static int usbnet_data_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe data interface and bulk endpoints.
Definition: usbnet.c:218
static int usbnet_has_intr(struct usbnet_device *usbnet)
Check if USB network device has an interrupt endpoint.
Definition: usbnet.h:64

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

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