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

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

47  {
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 }
__be32 in[4]
Definition: CIB_PRM.h:35
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
uint8_t intr
Interrupts enabled.
Definition: ena.h:14
__be32 out[4]
Definition: CIB_PRM.h:36
A USB device.
Definition: usb.h:706
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
struct usb_device * usb
USB device.
Definition: usb.h:661
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
struct usb_function * func
USB function.
Definition: usbnet.h:17

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(), 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 63 of file usbnet.h.

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

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

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

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().

◆ usbnet_close()

void usbnet_close ( struct usbnet_device usbnet)

Close USB network device.

Parameters
usbnetUSB network device

Definition at line 127 of file usbnet.c.

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

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().

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

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

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().

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

278  {
279  int rc;
280 
281  /* Describe communications interface, if applicable */
282  if ( usbnet_has_intr ( usbnet ) &&
283  ( rc = usbnet_comms_describe ( usbnet, config ) ) != 0 ) {
284  return rc;
285  }
286 
287  /* Describe data interface */
288  if ( ( rc = usbnet_data_describe ( usbnet, config ) ) != 0 )
289  return rc;
290 
291  return 0;
292 }
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:174
static int usbnet_data_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe data interface and bulk endpoints.
Definition: usbnet.c:217
static int usbnet_has_intr(struct usbnet_device *usbnet)
Check if USB network device has an interrupt endpoint.
Definition: usbnet.h:63

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().