blob: 51fce4e95dc5c1caa410c7202cfa75bb08329011 [file] [log] [blame]
Simon Glass1e9961d2011-02-16 11:14:33 -08001/*
2 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass1e9961d2011-02-16 11:14:33 -08003 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Simon Glass1e9961d2011-02-16 11:14:33 -08005 */
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 */
Simon Glass1e9961d2011-02-16 11:14:33 -080021
Simon Glass5b026f92015-07-06 16:47:50 -060022/* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */
Simon Glass1e9961d2011-02-16 11:14:33 -080023struct ueth_data {
24 /* eth info */
Simon Glass5b026f92015-07-06 16:47:50 -060025#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 */
Simon Glass1e9961d2011-02-16 11:14:33 -080036
37 /* usb info */
38 struct usb_device *pusb_dev; /* this usb_device */
Simon Glass5b026f92015-07-06 16:47:50 -060039 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; /* .............. */
Simon Glass1e9961d2011-02-16 11:14:33 -080045 unsigned char irqinterval; /* Intervall for IRQ Pipe */
Simon Glass1e9961d2011-02-16 11:14:33 -080046};
47
Simon Glass5b026f92015-07-06 16:47:50 -060048#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 */
59int 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 */
67int 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 */
79int 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 */
93int 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 */
105void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
106#else
Simon Glass1e9961d2011-02-16 11:14:33 -0800107/*
Gerhard Sittig3b162872014-03-08 19:46:13 +0100108 * Function definitions for each USB ethernet driver go here
109 * (declaration is unconditional, compilation is conditional)
Simon Glass1e9961d2011-02-16 11:14:33 -0800110 */
Simon Glass246d6932011-02-16 11:14:34 -0800111void asix_eth_before_probe(void);
112int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
113 struct ueth_data *ss);
114int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
115 struct eth_device *eth);
Simon Glass1e9961d2011-02-16 11:14:33 -0800116
Rene Griessl979beee2014-11-07 16:53:48 +0100117void ax88179_eth_before_probe(void);
118int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum,
119 struct ueth_data *ss);
120int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
121 struct eth_device *eth);
122
Gerhard Sittig2385df62014-03-08 19:46:14 +0100123void mcs7830_eth_before_probe(void);
124int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
125 struct ueth_data *ss);
126int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
127 struct eth_device *eth);
128
Simon Glass246c1192011-06-13 16:13:09 -0700129void smsc95xx_eth_before_probe(void);
130int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
131 struct ueth_data *ss);
132int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
133 struct eth_device *eth);
Ted Chen9b6dbd42016-01-20 14:24:52 +0800134
135void r8152_eth_before_probe(void);
136int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
137 struct ueth_data *ss);
138int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
139 struct eth_device *eth);
Simon Glass5b026f92015-07-06 16:47:50 -0600140#endif
Simon Glass246c1192011-06-13 16:13:09 -0700141
Simon Glass1e9961d2011-02-16 11:14:33 -0800142#endif /* __USB_ETHER_H__ */