Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 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 */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 20 | |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 21 | /* TODO(sjg@chromium.org): Remove @pusb_dev when all boards use CONFIG_DM_ETH */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 22 | struct ueth_data { |
| 23 | /* eth info */ |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 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 */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 35 | |
| 36 | /* usb info */ |
| 37 | struct usb_device *pusb_dev; /* this usb_device */ |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 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; /* .............. */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 44 | unsigned char irqinterval; /* Intervall for IRQ Pipe */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 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 |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 106 | /* |
Gerhard Sittig | 3b16287 | 2014-03-08 19:46:13 +0100 | [diff] [blame] | 107 | * Function definitions for each USB ethernet driver go here |
| 108 | * (declaration is unconditional, compilation is conditional) |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 109 | */ |
Simon Glass | 246d693 | 2011-02-16 11:14:34 -0800 | [diff] [blame] | 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); |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 115 | |
Rene Griessl | 979beee | 2014-11-07 16:53:48 +0100 | [diff] [blame] | 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 | |
Gerhard Sittig | 2385df6 | 2014-03-08 19:46:14 +0100 | [diff] [blame] | 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 | |
Simon Glass | 246c119 | 2011-06-13 16:13:09 -0700 | [diff] [blame] | 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); |
Ted Chen | 9b6dbd4 | 2016-01-20 14:24:52 +0800 | [diff] [blame] | 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); |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 139 | #endif |
Simon Glass | 246c119 | 2011-06-13 16:13:09 -0700 | [diff] [blame] | 140 | |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 141 | #endif /* __USB_ETHER_H__ */ |