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 | |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 11 | /* 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] | 12 | struct ueth_data { |
| 13 | /* eth info */ |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 14 | #ifdef CONFIG_DM_ETH |
| 15 | uint8_t *rxbuf; |
| 16 | int rxsize; |
| 17 | int rxlen; /* Total bytes available in rxbuf */ |
| 18 | int rxptr; /* Current position in rxbuf */ |
| 19 | #else |
| 20 | struct eth_device eth_dev; /* used with eth_register */ |
| 21 | /* driver private */ |
| 22 | void *dev_priv; |
| 23 | #endif |
| 24 | int phy_id; /* mii phy id */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 25 | |
| 26 | /* usb info */ |
| 27 | struct usb_device *pusb_dev; /* this usb_device */ |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 28 | unsigned char ifnum; /* interface number */ |
| 29 | unsigned char ep_in; /* in endpoint */ |
| 30 | unsigned char ep_out; /* out ....... */ |
| 31 | unsigned char ep_int; /* interrupt . */ |
| 32 | unsigned char subclass; /* as in overview */ |
| 33 | unsigned char protocol; /* .............. */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 34 | unsigned char irqinterval; /* Intervall for IRQ Pipe */ |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 35 | }; |
| 36 | |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 37 | #ifdef CONFIG_DM_ETH |
| 38 | /** |
| 39 | * usb_ether_register() - register a new USB ethernet device |
| 40 | * |
| 41 | * This selects the correct USB interface and figures out the endpoints to use. |
| 42 | * |
| 43 | * @dev: USB device |
| 44 | * @ss: Place to put USB ethernet data |
| 45 | * @rxsize: Maximum size to allocate for the receive buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 46 | * Return: 0 if OK, -ve on error |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 47 | */ |
| 48 | int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize); |
| 49 | |
| 50 | /** |
| 51 | * usb_ether_deregister() - deregister a USB ethernet device |
| 52 | * |
| 53 | * @ueth: USB Ethernet device |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 54 | * Return: 0 |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 55 | */ |
| 56 | int usb_ether_deregister(struct ueth_data *ueth); |
| 57 | |
| 58 | /** |
| 59 | * usb_ether_receive() - recieve a packet from the bulk in endpoint |
| 60 | * |
| 61 | * The packet is stored in the internal buffer ready for processing. |
| 62 | * |
| 63 | * @ueth: USB Ethernet device |
| 64 | * @rxsize: Maximum size to receive |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 65 | * Return: 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 66 | * larger than the size passed ot usb_ether_register(), other -ve on error |
| 67 | */ |
| 68 | int usb_ether_receive(struct ueth_data *ueth, int rxsize); |
| 69 | |
| 70 | /** |
| 71 | * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer |
| 72 | * |
| 73 | * This should be called repeatedly to obtain packet data until it returns 0. |
| 74 | * After each packet is processed, call usb_ether_advance_rxbuf() to move to |
| 75 | * the next one. |
| 76 | * |
| 77 | * @ueth: USB Ethernet device |
| 78 | * @ptrp: Returns a pointer to the start of the next packet if there is |
| 79 | * one available |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 80 | * Return: number of bytes available, or 0 if none |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 81 | */ |
| 82 | int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp); |
| 83 | |
| 84 | /** |
| 85 | * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer |
| 86 | * |
| 87 | * After processing the data returned by usb_ether_get_rx_bytes(), call this |
| 88 | * function to move to the next packet. You must specify the number of bytes |
| 89 | * you have processed in @num_bytes. |
| 90 | * |
| 91 | * @ueth: USB Ethernet device |
| 92 | * @num_bytes: Number of bytes to skip, or -1 to skip all bytes |
| 93 | */ |
| 94 | void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes); |
| 95 | #else |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 96 | /* |
Gerhard Sittig | 3b16287 | 2014-03-08 19:46:13 +0100 | [diff] [blame] | 97 | * Function definitions for each USB ethernet driver go here |
| 98 | * (declaration is unconditional, compilation is conditional) |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 99 | */ |
Simon Glass | 246d693 | 2011-02-16 11:14:34 -0800 | [diff] [blame] | 100 | void asix_eth_before_probe(void); |
| 101 | int asix_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 102 | struct ueth_data *ss); |
| 103 | int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 104 | struct eth_device *eth); |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 105 | |
Rene Griessl | 979beee | 2014-11-07 16:53:48 +0100 | [diff] [blame] | 106 | void ax88179_eth_before_probe(void); |
| 107 | int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 108 | struct ueth_data *ss); |
| 109 | int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 110 | struct eth_device *eth); |
| 111 | |
Gerhard Sittig | 2385df6 | 2014-03-08 19:46:14 +0100 | [diff] [blame] | 112 | void mcs7830_eth_before_probe(void); |
| 113 | int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 114 | struct ueth_data *ss); |
| 115 | int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 116 | struct eth_device *eth); |
| 117 | |
Simon Glass | 246c119 | 2011-06-13 16:13:09 -0700 | [diff] [blame] | 118 | void smsc95xx_eth_before_probe(void); |
| 119 | int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 120 | struct ueth_data *ss); |
| 121 | int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 122 | struct eth_device *eth); |
Ted Chen | 9b6dbd4 | 2016-01-20 14:24:52 +0800 | [diff] [blame] | 123 | |
| 124 | void r8152_eth_before_probe(void); |
| 125 | int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum, |
| 126 | struct ueth_data *ss); |
| 127 | int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss, |
| 128 | struct eth_device *eth); |
Simon Glass | 5b026f9 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 129 | #endif |
Simon Glass | 246c119 | 2011-06-13 16:13:09 -0700 | [diff] [blame] | 130 | |
Simon Glass | 1e9961d | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 131 | #endif /* __USB_ETHER_H__ */ |