blob: 18d7184711b2f4caadf776d47cf6298c922a20c3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass1e9961d2011-02-16 11:14:33 -08002/*
3 * Copyright (c) 2011 The Chromium OS Authors.
Simon Glass1e9961d2011-02-16 11:14:33 -08004 */
5
6#ifndef __USB_ETHER_H__
7#define __USB_ETHER_H__
8
9#include <net.h>
10
Tom Rinif0c60512022-11-27 10:25:33 -050011/* TODO(sjg@chromium.org): Remove @pusb_dev now that all boards use CONFIG_DM_ETH */
Simon Glass1e9961d2011-02-16 11:14:33 -080012struct ueth_data {
13 /* eth info */
Simon Glass5b026f92015-07-06 16:47:50 -060014 uint8_t *rxbuf;
15 int rxsize;
16 int rxlen; /* Total bytes available in rxbuf */
17 int rxptr; /* Current position in rxbuf */
Simon Glass5b026f92015-07-06 16:47:50 -060018 int phy_id; /* mii phy id */
Simon Glass1e9961d2011-02-16 11:14:33 -080019
20 /* usb info */
21 struct usb_device *pusb_dev; /* this usb_device */
Simon Glass5b026f92015-07-06 16:47:50 -060022 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 Glass1e9961d2011-02-16 11:14:33 -080028 unsigned char irqinterval; /* Intervall for IRQ Pipe */
Simon Glass1e9961d2011-02-16 11:14:33 -080029};
30
Simon Glass5b026f92015-07-06 16:47:50 -060031/**
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 Schuchardt47b4c022022-01-19 18:05:50 +010039 * Return: 0 if OK, -ve on error
Simon Glass5b026f92015-07-06 16:47:50 -060040 */
41int 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 Schuchardt47b4c022022-01-19 18:05:50 +010047 * Return: 0
Simon Glass5b026f92015-07-06 16:47:50 -060048 */
49int 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 Schuchardt47b4c022022-01-19 18:05:50 +010058 * Return: 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
Simon Glass5b026f92015-07-06 16:47:50 -060059 * larger than the size passed ot usb_ether_register(), other -ve on error
60 */
61int 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 Schuchardt47b4c022022-01-19 18:05:50 +010073 * Return: number of bytes available, or 0 if none
Simon Glass5b026f92015-07-06 16:47:50 -060074 */
75int 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 */
87void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
Simon Glass246c1192011-06-13 16:13:09 -070088
Simon Glass1e9961d2011-02-16 11:14:33 -080089#endif /* __USB_ETHER_H__ */