xref: /openbmc/u-boot/include/usb_ether.h (revision a740ee91)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2011 The Chromium OS Authors.
4  */
5 
6 #ifndef __USB_ETHER_H__
7 #define __USB_ETHER_H__
8 
9 #include <net.h>
10 
11 /* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */
12 struct ueth_data {
13 	/* eth info */
14 #ifdef CONFIG_DM_ETH
15 	uint8_t *rxbuf;
16 	int rxsize;
17 	int rxlen;			/* Total bytes available in rxbuf */
18 	int rxptr;			/* Current position in rxbuf */
19 #else
20 	struct eth_device eth_dev;	/* used with eth_register */
21 	/* driver private */
22 	void *dev_priv;
23 #endif
24 	int phy_id;			/* mii phy id */
25 
26 	/* usb info */
27 	struct usb_device *pusb_dev;	/* this usb_device */
28 	unsigned char	ifnum;		/* interface number */
29 	unsigned char	ep_in;		/* in endpoint */
30 	unsigned char	ep_out;		/* out ....... */
31 	unsigned char	ep_int;		/* interrupt . */
32 	unsigned char	subclass;	/* as in overview */
33 	unsigned char	protocol;	/* .............. */
34 	unsigned char	irqinterval;	/* Intervall for IRQ Pipe */
35 };
36 
37 #ifdef CONFIG_DM_ETH
38 /**
39  * usb_ether_register() - register a new USB ethernet device
40  *
41  * This selects the correct USB interface and figures out the endpoints to use.
42  *
43  * @dev:	USB device
44  * @ss:		Place to put USB ethernet data
45  * @rxsize:	Maximum size to allocate for the receive buffer
46  * @return 0 if OK, -ve on error
47  */
48 int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize);
49 
50 /**
51  * usb_ether_deregister() - deregister a USB ethernet device
52  *
53  * @ueth:	USB Ethernet device
54  * @return 0
55  */
56 int usb_ether_deregister(struct ueth_data *ueth);
57 
58 /**
59  * usb_ether_receive() - recieve a packet from the bulk in endpoint
60  *
61  * The packet is stored in the internal buffer ready for processing.
62  *
63  * @ueth:	USB Ethernet device
64  * @rxsize:	Maximum size to receive
65  * @return 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
66  * larger than the size passed ot usb_ether_register(), other -ve on error
67  */
68 int usb_ether_receive(struct ueth_data *ueth, int rxsize);
69 
70 /**
71  * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer
72  *
73  * This should be called repeatedly to obtain packet data until it returns 0.
74  * After each packet is processed, call usb_ether_advance_rxbuf() to move to
75  * the next one.
76  *
77  * @ueth:	USB Ethernet device
78  * @ptrp:	Returns a pointer to the start of the next packet if there is
79  *		one available
80  * @return number of bytes available, or 0 if none
81  */
82 int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp);
83 
84 /**
85  * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer
86  *
87  * After processing the data returned by usb_ether_get_rx_bytes(), call this
88  * function to move to the next packet. You must specify the number of bytes
89  * you have processed in @num_bytes.
90  *
91  * @ueth:	USB Ethernet device
92  * @num_bytes:	Number of bytes to skip, or -1 to skip all bytes
93  */
94 void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
95 #else
96 /*
97  * Function definitions for each USB ethernet driver go here
98  * (declaration is unconditional, compilation is conditional)
99  */
100 void asix_eth_before_probe(void);
101 int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
102 		      struct ueth_data *ss);
103 int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
104 		      struct eth_device *eth);
105 
106 void ax88179_eth_before_probe(void);
107 int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum,
108 		      struct ueth_data *ss);
109 int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
110 		      struct eth_device *eth);
111 
112 void mcs7830_eth_before_probe(void);
113 int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
114 		      struct ueth_data *ss);
115 int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
116 			 struct eth_device *eth);
117 
118 void smsc95xx_eth_before_probe(void);
119 int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
120 			struct ueth_data *ss);
121 int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
122 			struct eth_device *eth);
123 
124 void r8152_eth_before_probe(void);
125 int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
126 		    struct ueth_data *ss);
127 int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
128 		       struct eth_device *eth);
129 #endif
130 
131 #endif /* __USB_ETHER_H__ */
132