Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 5 | */ |
| 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 Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 21 | |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 22 | /* 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] | 23 | struct ueth_data { |
| 24 | /* eth info */ |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 25 | #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 Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 36 | |
| 37 | /* usb info */ |
| 38 | struct usb_device *pusb_dev; /* this usb_device */ |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 39 | 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 Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 45 | unsigned char irqinterval; /* Intervall for IRQ Pipe */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 46 | }; |
| 47 | |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 48 | #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 | */ |
| 59 | int 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 | */ |
| 67 | int 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 | */ |
| 79 | int 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 | */ |
| 93 | int 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 | */ |
| 105 | void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes); |
| 106 | #else |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 107 | /* |
Gerhard Sittig | 3b16287 | 2014-03-08 19:46:13 +0100 | [diff] [blame] | 108 | * Function definitions for each USB ethernet driver go here |
| 109 | * (declaration is unconditional, compilation is conditional) |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 110 | */ |
Simon Glass | 246d693 | 2011-02-16 11:14:34 -0800 | [diff] [blame] | 111 | void asix_eth_before_probe(void); |
| 112 | int asix_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 113 | struct ueth_data *ss); |
| 114 | int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 115 | struct eth_device *eth); |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 116 | |
Rene Griessl | 979beee | 2014-11-07 16:53:48 +0100 | [diff] [blame] | 117 | void ax88179_eth_before_probe(void); |
| 118 | int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 119 | struct ueth_data *ss); |
| 120 | int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 121 | struct eth_device *eth); |
| 122 | |
Gerhard Sittig | 2385df6 | 2014-03-08 19:46:14 +0100 | [diff] [blame] | 123 | void mcs7830_eth_before_probe(void); |
| 124 | int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 125 | struct ueth_data *ss); |
| 126 | int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 127 | struct eth_device *eth); |
| 128 | |
Simon Glass | 246c119 | 2011-06-13 16:13:09 -0700 | [diff] [blame] | 129 | void smsc95xx_eth_before_probe(void); |
| 130 | int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 131 | struct ueth_data *ss); |
| 132 | int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 133 | struct eth_device *eth); |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 134 | #endif |
Simon Glass | 246c119 | 2011-06-13 16:13:09 -0700 | [diff] [blame] | 135 | |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 136 | #endif /* __USB_ETHER_H__ */ |