usb_ether.h 2.7 KB

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