xref: /openbmc/u-boot/include/usb_ether.h (revision 0223462b373b975d970fa86e5e1a7eadd1d41820)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
289d48367SSimon Glass /*
389d48367SSimon Glass  * Copyright (c) 2011 The Chromium OS Authors.
489d48367SSimon Glass  */
589d48367SSimon Glass 
689d48367SSimon Glass #ifndef __USB_ETHER_H__
789d48367SSimon Glass #define __USB_ETHER_H__
889d48367SSimon Glass 
989d48367SSimon Glass #include <net.h>
1089d48367SSimon Glass 
11c8c2797cSSimon Glass /* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */
1289d48367SSimon Glass struct ueth_data {
1389d48367SSimon Glass 	/* eth info */
14c8c2797cSSimon Glass #ifdef CONFIG_DM_ETH
15c8c2797cSSimon Glass 	uint8_t *rxbuf;
16c8c2797cSSimon Glass 	int rxsize;
17c8c2797cSSimon Glass 	int rxlen;			/* Total bytes available in rxbuf */
18c8c2797cSSimon Glass 	int rxptr;			/* Current position in rxbuf */
19c8c2797cSSimon Glass #else
2089d48367SSimon Glass 	struct eth_device eth_dev;	/* used with eth_register */
21c8c2797cSSimon Glass 	/* driver private */
22c8c2797cSSimon Glass 	void *dev_priv;
23c8c2797cSSimon Glass #endif
2489d48367SSimon Glass 	int phy_id;			/* mii phy id */
2589d48367SSimon Glass 
2689d48367SSimon Glass 	/* usb info */
2789d48367SSimon Glass 	struct usb_device *pusb_dev;	/* this usb_device */
2889d48367SSimon Glass 	unsigned char	ifnum;		/* interface number */
2989d48367SSimon Glass 	unsigned char	ep_in;		/* in endpoint */
3089d48367SSimon Glass 	unsigned char	ep_out;		/* out ....... */
3189d48367SSimon Glass 	unsigned char	ep_int;		/* interrupt . */
3289d48367SSimon Glass 	unsigned char	subclass;	/* as in overview */
3389d48367SSimon Glass 	unsigned char	protocol;	/* .............. */
3489d48367SSimon Glass 	unsigned char	irqinterval;	/* Intervall for IRQ Pipe */
3589d48367SSimon Glass };
3689d48367SSimon Glass 
37c8c2797cSSimon Glass #ifdef CONFIG_DM_ETH
38c8c2797cSSimon Glass /**
39c8c2797cSSimon Glass  * usb_ether_register() - register a new USB ethernet device
40c8c2797cSSimon Glass  *
41c8c2797cSSimon Glass  * This selects the correct USB interface and figures out the endpoints to use.
42c8c2797cSSimon Glass  *
43c8c2797cSSimon Glass  * @dev:	USB device
44c8c2797cSSimon Glass  * @ss:		Place to put USB ethernet data
45c8c2797cSSimon Glass  * @rxsize:	Maximum size to allocate for the receive buffer
46c8c2797cSSimon Glass  * @return 0 if OK, -ve on error
47c8c2797cSSimon Glass  */
48c8c2797cSSimon Glass int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize);
49c8c2797cSSimon Glass 
50c8c2797cSSimon Glass /**
51c8c2797cSSimon Glass  * usb_ether_deregister() - deregister a USB ethernet device
52c8c2797cSSimon Glass  *
53c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
54c8c2797cSSimon Glass  * @return 0
55c8c2797cSSimon Glass  */
56c8c2797cSSimon Glass int usb_ether_deregister(struct ueth_data *ueth);
57c8c2797cSSimon Glass 
58c8c2797cSSimon Glass /**
59c8c2797cSSimon Glass  * usb_ether_receive() - recieve a packet from the bulk in endpoint
60c8c2797cSSimon Glass  *
61c8c2797cSSimon Glass  * The packet is stored in the internal buffer ready for processing.
62c8c2797cSSimon Glass  *
63c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
64c8c2797cSSimon Glass  * @rxsize:	Maximum size to receive
65c8c2797cSSimon Glass  * @return 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
66c8c2797cSSimon Glass  * larger than the size passed ot usb_ether_register(), other -ve on error
67c8c2797cSSimon Glass  */
68c8c2797cSSimon Glass int usb_ether_receive(struct ueth_data *ueth, int rxsize);
69c8c2797cSSimon Glass 
70c8c2797cSSimon Glass /**
71c8c2797cSSimon Glass  * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer
72c8c2797cSSimon Glass  *
73c8c2797cSSimon Glass  * This should be called repeatedly to obtain packet data until it returns 0.
74c8c2797cSSimon Glass  * After each packet is processed, call usb_ether_advance_rxbuf() to move to
75c8c2797cSSimon Glass  * the next one.
76c8c2797cSSimon Glass  *
77c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
78c8c2797cSSimon Glass  * @ptrp:	Returns a pointer to the start of the next packet if there is
79c8c2797cSSimon Glass  *		one available
80c8c2797cSSimon Glass  * @return number of bytes available, or 0 if none
81c8c2797cSSimon Glass  */
82c8c2797cSSimon Glass int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp);
83c8c2797cSSimon Glass 
84c8c2797cSSimon Glass /**
85c8c2797cSSimon Glass  * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer
86c8c2797cSSimon Glass  *
87c8c2797cSSimon Glass  * After processing the data returned by usb_ether_get_rx_bytes(), call this
88c8c2797cSSimon Glass  * function to move to the next packet. You must specify the number of bytes
89c8c2797cSSimon Glass  * you have processed in @num_bytes.
90c8c2797cSSimon Glass  *
91c8c2797cSSimon Glass  * @ueth:	USB Ethernet device
92c8c2797cSSimon Glass  * @num_bytes:	Number of bytes to skip, or -1 to skip all bytes
93c8c2797cSSimon Glass  */
94c8c2797cSSimon Glass void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
95c8c2797cSSimon Glass #else
9689d48367SSimon Glass /*
97440a5742SGerhard Sittig  * Function definitions for each USB ethernet driver go here
98440a5742SGerhard Sittig  * (declaration is unconditional, compilation is conditional)
9989d48367SSimon Glass  */
1009b70e007SSimon Glass void asix_eth_before_probe(void);
1019b70e007SSimon Glass int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
1029b70e007SSimon Glass 		      struct ueth_data *ss);
1039b70e007SSimon Glass int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
1049b70e007SSimon Glass 		      struct eth_device *eth);
10589d48367SSimon Glass 
106e9954b86SRene Griessl void ax88179_eth_before_probe(void);
107e9954b86SRene Griessl int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum,
108e9954b86SRene Griessl 		      struct ueth_data *ss);
109e9954b86SRene Griessl int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
110e9954b86SRene Griessl 		      struct eth_device *eth);
111e9954b86SRene Griessl 
112df4fb1c3SGerhard Sittig void mcs7830_eth_before_probe(void);
113df4fb1c3SGerhard Sittig int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
114df4fb1c3SGerhard Sittig 		      struct ueth_data *ss);
115df4fb1c3SGerhard Sittig int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
116df4fb1c3SGerhard Sittig 			 struct eth_device *eth);
117df4fb1c3SGerhard Sittig 
118291391beSSimon Glass void smsc95xx_eth_before_probe(void);
119291391beSSimon Glass int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
120291391beSSimon Glass 			struct ueth_data *ss);
121291391beSSimon Glass int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
122291391beSSimon Glass 			struct eth_device *eth);
1239dc8ba19STed Chen 
1249dc8ba19STed Chen void r8152_eth_before_probe(void);
1259dc8ba19STed Chen int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
1269dc8ba19STed Chen 		    struct ueth_data *ss);
1279dc8ba19STed Chen int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
1289dc8ba19STed Chen 		       struct eth_device *eth);
129c8c2797cSSimon Glass #endif
130291391beSSimon Glass 
13189d48367SSimon Glass #endif /* __USB_ETHER_H__ */
132