blob: 49f47d372ab57804ae4da3aae11fcd38d6a60678 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass89d48362011-02-16 11:14:33 -08002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass89d48362011-02-16 11:14:33 -08004 */
5
6#ifndef __USB_ETHER_H__
7#define __USB_ETHER_H__
8
9#include <net.h>
10
11/*
12 * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble
13 * and FCS/CRC (frame check sequence).
14 */
15#define ETH_ALEN 6 /* Octets in one ethernet addr */
16#define ETH_HLEN 14 /* Total octets in header. */
17#define ETH_ZLEN 60 /* Min. octets in frame sans FCS */
18#define ETH_DATA_LEN 1500 /* Max. octets in payload */
19#define ETH_FRAME_LEN PKTSIZE_ALIGN /* Max. octets in frame sans FCS */
Simon Glass89d48362011-02-16 11:14:33 -080020
Simon Glassc8c27972015-07-06 16:47:50 -060021/* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */
Simon Glass89d48362011-02-16 11:14:33 -080022struct ueth_data {
23 /* eth info */
Simon Glassc8c27972015-07-06 16:47:50 -060024#ifdef CONFIG_DM_ETH
25 uint8_t *rxbuf;
26 int rxsize;
27 int rxlen; /* Total bytes available in rxbuf */
28 int rxptr; /* Current position in rxbuf */
29#else
30 struct eth_device eth_dev; /* used with eth_register */
31 /* driver private */
32 void *dev_priv;
33#endif
34 int phy_id; /* mii phy id */
Simon Glass89d48362011-02-16 11:14:33 -080035
36 /* usb info */
37 struct usb_device *pusb_dev; /* this usb_device */
Simon Glassc8c27972015-07-06 16:47:50 -060038 unsigned char ifnum; /* interface number */
39 unsigned char ep_in; /* in endpoint */
40 unsigned char ep_out; /* out ....... */
41 unsigned char ep_int; /* interrupt . */
42 unsigned char subclass; /* as in overview */
43 unsigned char protocol; /* .............. */
Simon Glass89d48362011-02-16 11:14:33 -080044 unsigned char irqinterval; /* Intervall for IRQ Pipe */
Simon Glass89d48362011-02-16 11:14:33 -080045};
46
Simon Glassc8c27972015-07-06 16:47:50 -060047#ifdef CONFIG_DM_ETH
48/**
49 * usb_ether_register() - register a new USB ethernet device
50 *
51 * This selects the correct USB interface and figures out the endpoints to use.
52 *
53 * @dev: USB device
54 * @ss: Place to put USB ethernet data
55 * @rxsize: Maximum size to allocate for the receive buffer
56 * @return 0 if OK, -ve on error
57 */
58int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize);
59
60/**
61 * usb_ether_deregister() - deregister a USB ethernet device
62 *
63 * @ueth: USB Ethernet device
64 * @return 0
65 */
66int usb_ether_deregister(struct ueth_data *ueth);
67
68/**
69 * usb_ether_receive() - recieve a packet from the bulk in endpoint
70 *
71 * The packet is stored in the internal buffer ready for processing.
72 *
73 * @ueth: USB Ethernet device
74 * @rxsize: Maximum size to receive
75 * @return 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
76 * larger than the size passed ot usb_ether_register(), other -ve on error
77 */
78int usb_ether_receive(struct ueth_data *ueth, int rxsize);
79
80/**
81 * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer
82 *
83 * This should be called repeatedly to obtain packet data until it returns 0.
84 * After each packet is processed, call usb_ether_advance_rxbuf() to move to
85 * the next one.
86 *
87 * @ueth: USB Ethernet device
88 * @ptrp: Returns a pointer to the start of the next packet if there is
89 * one available
90 * @return number of bytes available, or 0 if none
91 */
92int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp);
93
94/**
95 * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer
96 *
97 * After processing the data returned by usb_ether_get_rx_bytes(), call this
98 * function to move to the next packet. You must specify the number of bytes
99 * you have processed in @num_bytes.
100 *
101 * @ueth: USB Ethernet device
102 * @num_bytes: Number of bytes to skip, or -1 to skip all bytes
103 */
104void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
105#else
Simon Glass89d48362011-02-16 11:14:33 -0800106/*
Gerhard Sittig440a5742014-03-08 19:46:13 +0100107 * Function definitions for each USB ethernet driver go here
108 * (declaration is unconditional, compilation is conditional)
Simon Glass89d48362011-02-16 11:14:33 -0800109 */
Simon Glass9b70e002011-02-16 11:14:34 -0800110void asix_eth_before_probe(void);
111int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
112 struct ueth_data *ss);
113int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
114 struct eth_device *eth);
Simon Glass89d48362011-02-16 11:14:33 -0800115
Rene Griessle9954b82014-11-07 16:53:48 +0100116void ax88179_eth_before_probe(void);
117int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum,
118 struct ueth_data *ss);
119int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
120 struct eth_device *eth);
121
Gerhard Sittigdf4fb1c2014-03-08 19:46:14 +0100122void mcs7830_eth_before_probe(void);
123int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
124 struct ueth_data *ss);
125int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
126 struct eth_device *eth);
127
Simon Glass291391b2011-06-13 16:13:09 -0700128void smsc95xx_eth_before_probe(void);
129int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
130 struct ueth_data *ss);
131int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
132 struct eth_device *eth);
Ted Chen9dc8ba12016-01-20 14:24:52 +0800133
134void r8152_eth_before_probe(void);
135int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
136 struct ueth_data *ss);
137int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
138 struct eth_device *eth);
Simon Glassc8c27972015-07-06 16:47:50 -0600139#endif
Simon Glass291391b2011-06-13 16:13:09 -0700140
Simon Glass89d48362011-02-16 11:14:33 -0800141#endif /* __USB_ETHER_H__ */