]> git.ipfire.org Git - thirdparty/u-boot.git/blame - include/usb_ether.h
Merge tag 'u-boot-stm32-20240614' of https://source.denx.de/u-boot/custodians/u-boot-stm
[thirdparty/u-boot.git] / include / usb_ether.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
89d48367
SG
2/*
3 * Copyright (c) 2011 The Chromium OS Authors.
89d48367
SG
4 */
5
6#ifndef __USB_ETHER_H__
7#define __USB_ETHER_H__
8
9#include <net.h>
89d48367 10
b8daa6e9 11/* TODO(sjg@chromium.org): Remove @pusb_dev now that all boards use CONFIG_DM_ETH */
89d48367
SG
12struct ueth_data {
13 /* eth info */
c8c2797c
SG
14 uint8_t *rxbuf;
15 int rxsize;
16 int rxlen; /* Total bytes available in rxbuf */
17 int rxptr; /* Current position in rxbuf */
c8c2797c 18 int phy_id; /* mii phy id */
89d48367
SG
19
20 /* usb info */
21 struct usb_device *pusb_dev; /* this usb_device */
c8c2797c
SG
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; /* .............. */
89d48367 28 unsigned char irqinterval; /* Intervall for IRQ Pipe */
89d48367
SG
29};
30
c8c2797c
SG
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
185f812c 39 * Return: 0 if OK, -ve on error
c8c2797c
SG
40 */
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
185f812c 47 * Return: 0
c8c2797c
SG
48 */
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
185f812c 58 * Return: 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
c8c2797c
SG
59 * 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
185f812c 73 * Return: number of bytes available, or 0 if none
c8c2797c
SG
74 */
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);
291391be 88
89d48367 89#endif /* __USB_ETHER_H__ */