xref: /rk3399_rockchip-uboot/include/usb_ether.h (revision 9c3193f8d03d4074fa6ca6b783246b97d8dc2ff5)
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 
22c8c2797cSSimon Glass /* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */
2389d48367SSimon Glass struct ueth_data {
2489d48367SSimon Glass 	/* eth info */
25c8c2797cSSimon Glass #ifdef CONFIG_DM_ETH
26c8c2797cSSimon Glass 	uint8_t *rxbuf;
27c8c2797cSSimon Glass 	int rxsize;
28c8c2797cSSimon Glass 	int rxlen;			/* Total bytes available in rxbuf */
29c8c2797cSSimon Glass 	int rxptr;			/* Current position in rxbuf */
30c8c2797cSSimon Glass #else
3189d48367SSimon Glass 	struct eth_device eth_dev;	/* used with eth_register */
32c8c2797cSSimon Glass 	/* driver private */
33c8c2797cSSimon Glass 	void *dev_priv;
34c8c2797cSSimon 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 
48c8c2797cSSimon Glass #ifdef CONFIG_DM_ETH
49c8c2797cSSimon Glass /**
50c8c2797cSSimon Glass  * usb_ether_register() - register a new USB ethernet device
51c8c2797cSSimon Glass  *
52c8c2797cSSimon Glass  * This selects the correct USB interface and figures out the endpoints to use.
53c8c2797cSSimon Glass  *
54c8c2797cSSimon Glass  * @dev:	USB device
55c8c2797cSSimon Glass  * @ss:		Place to put USB ethernet data
56c8c2797cSSimon Glass  * @rxsize:	Maximum size to allocate for the receive buffer
57c8c2797cSSimon Glass  * @return 0 if OK, -ve on error
58c8c2797cSSimon Glass  */
59c8c2797cSSimon Glass int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize);
60c8c2797cSSimon Glass 
61c8c2797cSSimon Glass /**
62c8c2797cSSimon Glass  * usb_ether_deregister() - deregister a USB ethernet device
63c8c2797cSSimon Glass  *
64c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
65c8c2797cSSimon Glass  * @return 0
66c8c2797cSSimon Glass  */
67c8c2797cSSimon Glass int usb_ether_deregister(struct ueth_data *ueth);
68c8c2797cSSimon Glass 
69c8c2797cSSimon Glass /**
70c8c2797cSSimon Glass  * usb_ether_receive() - recieve a packet from the bulk in endpoint
71c8c2797cSSimon Glass  *
72c8c2797cSSimon Glass  * The packet is stored in the internal buffer ready for processing.
73c8c2797cSSimon Glass  *
74c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
75c8c2797cSSimon Glass  * @rxsize:	Maximum size to receive
76c8c2797cSSimon Glass  * @return 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
77c8c2797cSSimon Glass  * larger than the size passed ot usb_ether_register(), other -ve on error
78c8c2797cSSimon Glass  */
79c8c2797cSSimon Glass int usb_ether_receive(struct ueth_data *ueth, int rxsize);
80c8c2797cSSimon Glass 
81c8c2797cSSimon Glass /**
82c8c2797cSSimon Glass  * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer
83c8c2797cSSimon Glass  *
84c8c2797cSSimon Glass  * This should be called repeatedly to obtain packet data until it returns 0.
85c8c2797cSSimon Glass  * After each packet is processed, call usb_ether_advance_rxbuf() to move to
86c8c2797cSSimon Glass  * the next one.
87c8c2797cSSimon Glass  *
88c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
89c8c2797cSSimon Glass  * @ptrp:	Returns a pointer to the start of the next packet if there is
90c8c2797cSSimon Glass  *		one available
91c8c2797cSSimon Glass  * @return number of bytes available, or 0 if none
92c8c2797cSSimon Glass  */
93c8c2797cSSimon Glass int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp);
94c8c2797cSSimon Glass 
95c8c2797cSSimon Glass /**
96c8c2797cSSimon Glass  * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer
97c8c2797cSSimon Glass  *
98c8c2797cSSimon Glass  * After processing the data returned by usb_ether_get_rx_bytes(), call this
99c8c2797cSSimon Glass  * function to move to the next packet. You must specify the number of bytes
100c8c2797cSSimon Glass  * you have processed in @num_bytes.
101c8c2797cSSimon Glass  *
102c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
103c8c2797cSSimon Glass  * @num_bytes:	Number of bytes to skip, or -1 to skip all bytes
104c8c2797cSSimon Glass  */
105c8c2797cSSimon Glass void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
106c8c2797cSSimon 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*9dc8ba19STed Chen 
135*9dc8ba19STed Chen void r8152_eth_before_probe(void);
136*9dc8ba19STed Chen int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
137*9dc8ba19STed Chen 		    struct ueth_data *ss);
138*9dc8ba19STed Chen int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
139*9dc8ba19STed Chen 		       struct eth_device *eth);
140c8c2797cSSimon Glass #endif
141291391beSSimon Glass 
14289d48367SSimon Glass #endif /* __USB_ETHER_H__ */
143