usb_ether.h 4.6 KB

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