]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
89d48367 SG |
2 | /* |
3 | * Copyright (c) 2011 The Chromium OS Authors. | |
89d48367 SG |
4 | */ |
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 */ | |
89d48367 | 20 | |
c8c2797c | 21 | /* TODO([email protected]): Remove @pusb_dev when all boards use CONFIG_DM_ETH */ |
89d48367 SG |
22 | struct ueth_data { |
23 | /* eth info */ | |
c8c2797c SG |
24 | #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 */ | |
89d48367 SG |
35 | |
36 | /* usb info */ | |
37 | struct usb_device *pusb_dev; /* this usb_device */ | |
c8c2797c SG |
38 | 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; /* .............. */ | |
89d48367 | 44 | unsigned char irqinterval; /* Intervall for IRQ Pipe */ |
89d48367 SG |
45 | }; |
46 | ||
c8c2797c SG |
47 | #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 | */ | |
58 | int 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 | */ | |
66 | int 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 | */ | |
78 | int 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 | */ | |
92 | int 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 | */ | |
104 | void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes); | |
105 | #else | |
89d48367 | 106 | /* |
440a5742 GS |
107 | * Function definitions for each USB ethernet driver go here |
108 | * (declaration is unconditional, compilation is conditional) | |
89d48367 | 109 | */ |
9b70e007 SG |
110 | void asix_eth_before_probe(void); |
111 | int asix_eth_probe(struct usb_device *dev, unsigned int ifnum, | |
112 | struct ueth_data *ss); | |
113 | int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss, | |
114 | struct eth_device *eth); | |
89d48367 | 115 | |
e9954b86 RG |
116 | void ax88179_eth_before_probe(void); |
117 | int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum, | |
118 | struct ueth_data *ss); | |
119 | int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss, | |
120 | struct eth_device *eth); | |
121 | ||
df4fb1c3 GS |
122 | void mcs7830_eth_before_probe(void); |
123 | int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum, | |
124 | struct ueth_data *ss); | |
125 | int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss, | |
126 | struct eth_device *eth); | |
127 | ||
291391be SG |
128 | void smsc95xx_eth_before_probe(void); |
129 | int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum, | |
130 | struct ueth_data *ss); | |
131 | int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss, | |
132 | struct eth_device *eth); | |
9dc8ba19 TC |
133 | |
134 | void r8152_eth_before_probe(void); | |
135 | int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum, | |
136 | struct ueth_data *ss); | |
137 | int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss, | |
138 | struct eth_device *eth); | |
c8c2797c | 139 | #endif |
291391be | 140 | |
89d48367 | 141 | #endif /* __USB_ETHER_H__ */ |