xref: /rk3399_rockchip-uboot/include/usb_ether.h (revision c8c2797c381054beaf3de89027af92a0b84b36cc)
189d48367SSimon Glass /*
289d48367SSimon Glass  * Copyright (c) 2011 The Chromium OS Authors.
389d48367SSimon Glass  *
41a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
589d48367SSimon Glass  */
689d48367SSimon Glass 
789d48367SSimon Glass #ifndef __USB_ETHER_H__
889d48367SSimon Glass #define __USB_ETHER_H__
989d48367SSimon Glass 
1089d48367SSimon Glass #include <net.h>
1189d48367SSimon Glass 
1289d48367SSimon Glass /*
1389d48367SSimon Glass  *	IEEE 802.3 Ethernet magic constants.  The frame sizes omit the preamble
1489d48367SSimon Glass  *	and FCS/CRC (frame check sequence).
1589d48367SSimon Glass  */
1689d48367SSimon Glass #define ETH_ALEN	6		/* Octets in one ethernet addr	 */
1789d48367SSimon Glass #define ETH_HLEN	14		/* Total octets in header.	 */
1889d48367SSimon Glass #define ETH_ZLEN	60		/* Min. octets in frame sans FCS */
1989d48367SSimon Glass #define ETH_DATA_LEN	1500		/* Max. octets in payload	 */
2089d48367SSimon Glass #define ETH_FRAME_LEN	PKTSIZE_ALIGN	/* Max. octets in frame sans FCS */
2189d48367SSimon Glass 
22*c8c2797cSSimon Glass /* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */
2389d48367SSimon Glass struct ueth_data {
2489d48367SSimon Glass 	/* eth info */
25*c8c2797cSSimon Glass #ifdef CONFIG_DM_ETH
26*c8c2797cSSimon Glass 	uint8_t *rxbuf;
27*c8c2797cSSimon Glass 	int rxsize;
28*c8c2797cSSimon Glass 	int rxlen;			/* Total bytes available in rxbuf */
29*c8c2797cSSimon Glass 	int rxptr;			/* Current position in rxbuf */
30*c8c2797cSSimon Glass #else
3189d48367SSimon Glass 	struct eth_device eth_dev;	/* used with eth_register */
32*c8c2797cSSimon Glass 	/* driver private */
33*c8c2797cSSimon Glass 	void *dev_priv;
34*c8c2797cSSimon Glass #endif
3589d48367SSimon Glass 	int phy_id;			/* mii phy id */
3689d48367SSimon Glass 
3789d48367SSimon Glass 	/* usb info */
3889d48367SSimon Glass 	struct usb_device *pusb_dev;	/* this usb_device */
3989d48367SSimon Glass 	unsigned char	ifnum;		/* interface number */
4089d48367SSimon Glass 	unsigned char	ep_in;		/* in endpoint */
4189d48367SSimon Glass 	unsigned char	ep_out;		/* out ....... */
4289d48367SSimon Glass 	unsigned char	ep_int;		/* interrupt . */
4389d48367SSimon Glass 	unsigned char	subclass;	/* as in overview */
4489d48367SSimon Glass 	unsigned char	protocol;	/* .............. */
4589d48367SSimon Glass 	unsigned char	irqinterval;	/* Intervall for IRQ Pipe */
4689d48367SSimon Glass };
4789d48367SSimon Glass 
48*c8c2797cSSimon Glass #ifdef CONFIG_DM_ETH
49*c8c2797cSSimon Glass /**
50*c8c2797cSSimon Glass  * usb_ether_register() - register a new USB ethernet device
51*c8c2797cSSimon Glass  *
52*c8c2797cSSimon Glass  * This selects the correct USB interface and figures out the endpoints to use.
53*c8c2797cSSimon Glass  *
54*c8c2797cSSimon Glass  * @dev:	USB device
55*c8c2797cSSimon Glass  * @ss:		Place to put USB ethernet data
56*c8c2797cSSimon Glass  * @rxsize:	Maximum size to allocate for the receive buffer
57*c8c2797cSSimon Glass  * @return 0 if OK, -ve on error
58*c8c2797cSSimon Glass  */
59*c8c2797cSSimon Glass int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize);
60*c8c2797cSSimon Glass 
61*c8c2797cSSimon Glass /**
62*c8c2797cSSimon Glass  * usb_ether_deregister() - deregister a USB ethernet device
63*c8c2797cSSimon Glass  *
64*c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
65*c8c2797cSSimon Glass  * @return 0
66*c8c2797cSSimon Glass  */
67*c8c2797cSSimon Glass int usb_ether_deregister(struct ueth_data *ueth);
68*c8c2797cSSimon Glass 
69*c8c2797cSSimon Glass /**
70*c8c2797cSSimon Glass  * usb_ether_receive() - recieve a packet from the bulk in endpoint
71*c8c2797cSSimon Glass  *
72*c8c2797cSSimon Glass  * The packet is stored in the internal buffer ready for processing.
73*c8c2797cSSimon Glass  *
74*c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
75*c8c2797cSSimon Glass  * @rxsize:	Maximum size to receive
76*c8c2797cSSimon Glass  * @return 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
77*c8c2797cSSimon Glass  * larger than the size passed ot usb_ether_register(), other -ve on error
78*c8c2797cSSimon Glass  */
79*c8c2797cSSimon Glass int usb_ether_receive(struct ueth_data *ueth, int rxsize);
80*c8c2797cSSimon Glass 
81*c8c2797cSSimon Glass /**
82*c8c2797cSSimon Glass  * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer
83*c8c2797cSSimon Glass  *
84*c8c2797cSSimon Glass  * This should be called repeatedly to obtain packet data until it returns 0.
85*c8c2797cSSimon Glass  * After each packet is processed, call usb_ether_advance_rxbuf() to move to
86*c8c2797cSSimon Glass  * the next one.
87*c8c2797cSSimon Glass  *
88*c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
89*c8c2797cSSimon Glass  * @ptrp:	Returns a pointer to the start of the next packet if there is
90*c8c2797cSSimon Glass  *		one available
91*c8c2797cSSimon Glass  * @return number of bytes available, or 0 if none
92*c8c2797cSSimon Glass  */
93*c8c2797cSSimon Glass int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp);
94*c8c2797cSSimon Glass 
95*c8c2797cSSimon Glass /**
96*c8c2797cSSimon Glass  * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer
97*c8c2797cSSimon Glass  *
98*c8c2797cSSimon Glass  * After processing the data returned by usb_ether_get_rx_bytes(), call this
99*c8c2797cSSimon Glass  * function to move to the next packet. You must specify the number of bytes
100*c8c2797cSSimon Glass  * you have processed in @num_bytes.
101*c8c2797cSSimon Glass  *
102*c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
103*c8c2797cSSimon Glass  * @num_bytes:	Number of bytes to skip, or -1 to skip all bytes
104*c8c2797cSSimon Glass  */
105*c8c2797cSSimon Glass void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
106*c8c2797cSSimon Glass #else
10789d48367SSimon Glass /*
108440a5742SGerhard Sittig  * Function definitions for each USB ethernet driver go here
109440a5742SGerhard Sittig  * (declaration is unconditional, compilation is conditional)
11089d48367SSimon Glass  */
1119b70e007SSimon Glass void asix_eth_before_probe(void);
1129b70e007SSimon Glass int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
1139b70e007SSimon Glass 		      struct ueth_data *ss);
1149b70e007SSimon Glass int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
1159b70e007SSimon Glass 		      struct eth_device *eth);
11689d48367SSimon Glass 
117e9954b86SRene Griessl void ax88179_eth_before_probe(void);
118e9954b86SRene Griessl int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum,
119e9954b86SRene Griessl 		      struct ueth_data *ss);
120e9954b86SRene Griessl int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
121e9954b86SRene Griessl 		      struct eth_device *eth);
122e9954b86SRene Griessl 
123df4fb1c3SGerhard Sittig void mcs7830_eth_before_probe(void);
124df4fb1c3SGerhard Sittig int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
125df4fb1c3SGerhard Sittig 		      struct ueth_data *ss);
126df4fb1c3SGerhard Sittig int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
127df4fb1c3SGerhard Sittig 			 struct eth_device *eth);
128df4fb1c3SGerhard Sittig 
129291391beSSimon Glass void smsc95xx_eth_before_probe(void);
130291391beSSimon Glass int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
131291391beSSimon Glass 			struct ueth_data *ss);
132291391beSSimon Glass int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
133291391beSSimon Glass 			struct eth_device *eth);
134*c8c2797cSSimon Glass #endif
135291391beSSimon Glass 
13689d48367SSimon Glass #endif /* __USB_ETHER_H__ */
137