usb_ether.h 4.6 KB

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