Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 89d4836 | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2011 The Chromium OS Authors. |
Simon Glass | 89d4836 | 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 | |
Tom Rini | b8daa6e | 2022-11-27 10:25:33 -0500 | [diff] [blame] | 11 | /* TODO(sjg@chromium.org): Remove @pusb_dev now that all boards use CONFIG_DM_ETH */ |
Simon Glass | 89d4836 | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 12 | struct ueth_data { |
| 13 | /* eth info */ |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 14 | uint8_t *rxbuf; |
| 15 | int rxsize; |
| 16 | int rxlen; /* Total bytes available in rxbuf */ |
| 17 | int rxptr; /* Current position in rxbuf */ |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 18 | int phy_id; /* mii phy id */ |
Simon Glass | 89d4836 | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 19 | |
| 20 | /* usb info */ |
| 21 | struct usb_device *pusb_dev; /* this usb_device */ |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 22 | unsigned char ifnum; /* interface number */ |
| 23 | unsigned char ep_in; /* in endpoint */ |
| 24 | unsigned char ep_out; /* out ....... */ |
| 25 | unsigned char ep_int; /* interrupt . */ |
| 26 | unsigned char subclass; /* as in overview */ |
| 27 | unsigned char protocol; /* .............. */ |
Simon Glass | 89d4836 | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 28 | unsigned char irqinterval; /* Intervall for IRQ Pipe */ |
Simon Glass | 89d4836 | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 29 | }; |
| 30 | |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 31 | /** |
| 32 | * usb_ether_register() - register a new USB ethernet device |
| 33 | * |
| 34 | * This selects the correct USB interface and figures out the endpoints to use. |
| 35 | * |
| 36 | * @dev: USB device |
| 37 | * @ss: Place to put USB ethernet data |
| 38 | * @rxsize: Maximum size to allocate for the receive buffer |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 39 | * Return: 0 if OK, -ve on error |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 40 | */ |
| 41 | int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize); |
| 42 | |
| 43 | /** |
| 44 | * usb_ether_deregister() - deregister a USB ethernet device |
| 45 | * |
| 46 | * @ueth: USB Ethernet device |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 47 | * Return: 0 |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 48 | */ |
| 49 | int usb_ether_deregister(struct ueth_data *ueth); |
| 50 | |
| 51 | /** |
| 52 | * usb_ether_receive() - recieve a packet from the bulk in endpoint |
| 53 | * |
| 54 | * The packet is stored in the internal buffer ready for processing. |
| 55 | * |
| 56 | * @ueth: USB Ethernet device |
| 57 | * @rxsize: Maximum size to receive |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 58 | * Return: 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 59 | * larger than the size passed ot usb_ether_register(), other -ve on error |
| 60 | */ |
| 61 | int usb_ether_receive(struct ueth_data *ueth, int rxsize); |
| 62 | |
| 63 | /** |
| 64 | * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer |
| 65 | * |
| 66 | * This should be called repeatedly to obtain packet data until it returns 0. |
| 67 | * After each packet is processed, call usb_ether_advance_rxbuf() to move to |
| 68 | * the next one. |
| 69 | * |
| 70 | * @ueth: USB Ethernet device |
| 71 | * @ptrp: Returns a pointer to the start of the next packet if there is |
| 72 | * one available |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 73 | * Return: number of bytes available, or 0 if none |
Simon Glass | c8c2797 | 2015-07-06 16:47:50 -0600 | [diff] [blame] | 74 | */ |
| 75 | int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp); |
| 76 | |
| 77 | /** |
| 78 | * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer |
| 79 | * |
| 80 | * After processing the data returned by usb_ether_get_rx_bytes(), call this |
| 81 | * function to move to the next packet. You must specify the number of bytes |
| 82 | * you have processed in @num_bytes. |
| 83 | * |
| 84 | * @ueth: USB Ethernet device |
| 85 | * @num_bytes: Number of bytes to skip, or -1 to skip all bytes |
| 86 | */ |
| 87 | void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes); |
Simon Glass | 291391b | 2011-06-13 16:13:09 -0700 | [diff] [blame] | 88 | |
Simon Glass | 89d4836 | 2011-02-16 11:14:33 -0800 | [diff] [blame] | 89 | #endif /* __USB_ETHER_H__ */ |