blob: 8c7bd06906433e79446949d319947633e44477ab [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass1e9961d2011-02-16 11:14:33 -08002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass1e9961d2011-02-16 11:14:33 -08004 */
5
6#ifndef __USB_ETHER_H__
7#define __USB_ETHER_H__
8
9#include <net.h>
10
Simon Glass5b026f92015-07-06 16:47:50 -060011/* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */
Simon Glass1e9961d2011-02-16 11:14:33 -080012struct ueth_data {
13 /* eth info */
Simon Glass5b026f92015-07-06 16:47:50 -060014#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 */
Simon Glass1e9961d2011-02-16 11:14:33 -080025
26 /* usb info */
27 struct usb_device *pusb_dev; /* this usb_device */
Simon Glass5b026f92015-07-06 16:47:50 -060028 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; /* .............. */
Simon Glass1e9961d2011-02-16 11:14:33 -080034 unsigned char irqinterval; /* Intervall for IRQ Pipe */
Simon Glass1e9961d2011-02-16 11:14:33 -080035};
36
Simon Glass5b026f92015-07-06 16:47:50 -060037#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
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010046 * Return: 0 if OK, -ve on error
Simon Glass5b026f92015-07-06 16:47:50 -060047 */
48int 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
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010054 * Return: 0
Simon Glass5b026f92015-07-06 16:47:50 -060055 */
56int 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
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010065 * Return: 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
Simon Glass5b026f92015-07-06 16:47:50 -060066 * larger than the size passed ot usb_ether_register(), other -ve on error
67 */
68int 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
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010080 * Return: number of bytes available, or 0 if none
Simon Glass5b026f92015-07-06 16:47:50 -060081 */
82int 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 */
94void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
95#else
Simon Glass1e9961d2011-02-16 11:14:33 -080096/*
Gerhard Sittig3b162872014-03-08 19:46:13 +010097 * Function definitions for each USB ethernet driver go here
98 * (declaration is unconditional, compilation is conditional)
Simon Glass1e9961d2011-02-16 11:14:33 -080099 */
Simon Glass246d6932011-02-16 11:14:34 -0800100void asix_eth_before_probe(void);
101int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
102 struct ueth_data *ss);
103int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
104 struct eth_device *eth);
Simon Glass1e9961d2011-02-16 11:14:33 -0800105
Rene Griessl979beee2014-11-07 16:53:48 +0100106void ax88179_eth_before_probe(void);
107int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum,
108 struct ueth_data *ss);
109int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
110 struct eth_device *eth);
111
Gerhard Sittig2385df62014-03-08 19:46:14 +0100112void mcs7830_eth_before_probe(void);
113int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
114 struct ueth_data *ss);
115int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
116 struct eth_device *eth);
117
Simon Glass246c1192011-06-13 16:13:09 -0700118void smsc95xx_eth_before_probe(void);
119int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
120 struct ueth_data *ss);
121int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
122 struct eth_device *eth);
Ted Chen9b6dbd42016-01-20 14:24:52 +0800123
124void r8152_eth_before_probe(void);
125int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
126 struct ueth_data *ss);
127int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
128 struct eth_device *eth);
Simon Glass5b026f92015-07-06 16:47:50 -0600129#endif
Simon Glass246c1192011-06-13 16:13:09 -0700130
Simon Glass1e9961d2011-02-16 11:14:33 -0800131#endif /* __USB_ETHER_H__ */