usb_ether.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 when all boards use CONFIG_DM_ETH */
  9. struct ueth_data {
  10. /* eth info */
  11. #ifdef CONFIG_DM_ETH
  12. uint8_t *rxbuf;
  13. int rxsize;
  14. int rxlen; /* Total bytes available in rxbuf */
  15. int rxptr; /* Current position in rxbuf */
  16. #else
  17. struct eth_device eth_dev; /* used with eth_register */
  18. /* driver private */
  19. void *dev_priv;
  20. #endif
  21. int phy_id; /* mii phy id */
  22. /* usb info */
  23. struct usb_device *pusb_dev; /* this usb_device */
  24. unsigned char ifnum; /* interface number */
  25. unsigned char ep_in; /* in endpoint */
  26. unsigned char ep_out; /* out ....... */
  27. unsigned char ep_int; /* interrupt . */
  28. unsigned char subclass; /* as in overview */
  29. unsigned char protocol; /* .............. */
  30. unsigned char irqinterval; /* Intervall for IRQ Pipe */
  31. };
  32. #ifdef CONFIG_DM_ETH
  33. /**
  34. * usb_ether_register() - register a new USB ethernet device
  35. *
  36. * This selects the correct USB interface and figures out the endpoints to use.
  37. *
  38. * @dev: USB device
  39. * @ss: Place to put USB ethernet data
  40. * @rxsize: Maximum size to allocate for the receive buffer
  41. * @return 0 if OK, -ve on error
  42. */
  43. int usb_ether_register(struct udevice *dev, struct ueth_data *ueth, int rxsize);
  44. /**
  45. * usb_ether_deregister() - deregister a USB ethernet device
  46. *
  47. * @ueth: USB Ethernet device
  48. * @return 0
  49. */
  50. int usb_ether_deregister(struct ueth_data *ueth);
  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
  58. * @return 0 if a packet was received, -EAGAIN if not, -ENOSPC if @rxsize is
  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. * usb_ether_get_rx_bytes() - obtain bytes from the internal packet buffer
  64. *
  65. * This should be called repeatedly to obtain packet data until it returns 0.
  66. * After each packet is processed, call usb_ether_advance_rxbuf() to move to
  67. * the next one.
  68. *
  69. * @ueth: USB Ethernet device
  70. * @ptrp: Returns a pointer to the start of the next packet if there is
  71. * one available
  72. * @return number of bytes available, or 0 if none
  73. */
  74. int usb_ether_get_rx_bytes(struct ueth_data *ueth, uint8_t **ptrp);
  75. /**
  76. * usb_ether_advance_rxbuf() - Advance to the next packet in the internal buffer
  77. *
  78. * After processing the data returned by usb_ether_get_rx_bytes(), call this
  79. * function to move to the next packet. You must specify the number of bytes
  80. * you have processed in @num_bytes.
  81. *
  82. * @ueth: USB Ethernet device
  83. * @num_bytes: Number of bytes to skip, or -1 to skip all bytes
  84. */
  85. void usb_ether_advance_rxbuf(struct ueth_data *ueth, int num_bytes);
  86. #else
  87. /*
  88. * Function definitions for each USB ethernet driver go here
  89. * (declaration is unconditional, compilation is conditional)
  90. */
  91. void asix_eth_before_probe(void);
  92. int asix_eth_probe(struct usb_device *dev, unsigned int ifnum,
  93. struct ueth_data *ss);
  94. int asix_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
  95. struct eth_device *eth);
  96. void ax88179_eth_before_probe(void);
  97. int ax88179_eth_probe(struct usb_device *dev, unsigned int ifnum,
  98. struct ueth_data *ss);
  99. int ax88179_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
  100. struct eth_device *eth);
  101. void mcs7830_eth_before_probe(void);
  102. int mcs7830_eth_probe(struct usb_device *dev, unsigned int ifnum,
  103. struct ueth_data *ss);
  104. int mcs7830_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
  105. struct eth_device *eth);
  106. void smsc95xx_eth_before_probe(void);
  107. int smsc95xx_eth_probe(struct usb_device *dev, unsigned int ifnum,
  108. struct ueth_data *ss);
  109. int smsc95xx_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
  110. struct eth_device *eth);
  111. void r8152_eth_before_probe(void);
  112. int r8152_eth_probe(struct usb_device *dev, unsigned int ifnum,
  113. struct ueth_data *ss);
  114. int r8152_eth_get_info(struct usb_device *dev, struct ueth_data *ss,
  115. struct eth_device *eth);
  116. #endif
  117. #endif /* __USB_ETHER_H__ */