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