1
0

usbh_asix.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) 2024, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USBH_ASIX_H
  7. #define USBH_ASIX_H
  8. /* ASIX AX8817X based USB 2.0 Ethernet Devices */
  9. #define AX_CMD_SET_SW_MII 0x06
  10. #define AX_CMD_READ_MII_REG 0x07
  11. #define AX_CMD_WRITE_MII_REG 0x08
  12. #define AX_CMD_STATMNGSTS_REG 0x09
  13. #define AX_CMD_SET_HW_MII 0x0a
  14. #define AX_CMD_READ_EEPROM 0x0b
  15. #define AX_CMD_WRITE_EEPROM 0x0c
  16. #define AX_CMD_WRITE_ENABLE 0x0d
  17. #define AX_CMD_WRITE_DISABLE 0x0e
  18. #define AX_CMD_READ_RX_CTL 0x0f
  19. #define AX_CMD_WRITE_RX_CTL 0x10
  20. #define AX_CMD_READ_IPG012 0x11
  21. #define AX_CMD_WRITE_IPG0 0x12
  22. #define AX_CMD_WRITE_IPG1 0x13
  23. #define AX_CMD_READ_NODE_ID 0x13
  24. #define AX_CMD_WRITE_NODE_ID 0x14
  25. #define AX_CMD_WRITE_IPG2 0x14
  26. #define AX_CMD_WRITE_MULTI_FILTER 0x16
  27. #define AX88172_CMD_READ_NODE_ID 0x17
  28. #define AX_CMD_READ_PHY_ID 0x19
  29. #define AX_CMD_READ_MEDIUM_STATUS 0x1a
  30. #define AX_CMD_WRITE_MEDIUM_MODE 0x1b
  31. #define AX_CMD_READ_MONITOR_MODE 0x1c
  32. #define AX_CMD_WRITE_MONITOR_MODE 0x1d
  33. #define AX_CMD_READ_GPIOS 0x1e
  34. #define AX_CMD_WRITE_GPIOS 0x1f
  35. #define AX_CMD_SW_RESET 0x20
  36. #define AX_CMD_SW_PHY_STATUS 0x21
  37. #define AX_CMD_SW_PHY_SELECT 0x22
  38. #define AX_QCTCTRL 0x2A
  39. #define AX_CHIPCODE_MASK 0x70
  40. #define AX_AX88772_CHIPCODE 0x00
  41. #define AX_AX88772A_CHIPCODE 0x10
  42. #define AX_AX88772B_CHIPCODE 0x20
  43. #define AX_HOST_EN 0x01
  44. #define AX_PHYSEL_PSEL 0x01
  45. #define AX_PHYSEL_SSMII 0
  46. #define AX_PHYSEL_SSEN 0x10
  47. #define AX_PHY_SELECT_MASK (BIT(3) | BIT(2))
  48. #define AX_PHY_SELECT_INTERNAL 0
  49. #define AX_PHY_SELECT_EXTERNAL BIT(2)
  50. #define AX_MONITOR_MODE 0x01
  51. #define AX_MONITOR_LINK 0x02
  52. #define AX_MONITOR_MAGIC 0x04
  53. #define AX_MONITOR_HSFS 0x10
  54. /* AX88172 Medium Status Register values */
  55. #define AX88172_MEDIUM_FD 0x02
  56. #define AX88172_MEDIUM_TX 0x04
  57. #define AX88172_MEDIUM_FC 0x10
  58. #define AX88172_MEDIUM_DEFAULT \
  59. (AX88172_MEDIUM_FD | AX88172_MEDIUM_TX | AX88172_MEDIUM_FC)
  60. #define AX_MCAST_FILTER_SIZE 8
  61. #define AX_MAX_MCAST 64
  62. #define AX_SWRESET_CLEAR 0x00
  63. #define AX_SWRESET_RR 0x01
  64. #define AX_SWRESET_RT 0x02
  65. #define AX_SWRESET_PRTE 0x04
  66. #define AX_SWRESET_PRL 0x08
  67. #define AX_SWRESET_BZ 0x10
  68. #define AX_SWRESET_IPRL 0x20
  69. #define AX_SWRESET_IPPD 0x40
  70. #define AX88772_IPG0_DEFAULT 0x15
  71. #define AX88772_IPG1_DEFAULT 0x0c
  72. #define AX88772_IPG2_DEFAULT 0x12
  73. /* AX88772 & AX88178 Medium Mode Register */
  74. #define AX_MEDIUM_PF 0x0080
  75. #define AX_MEDIUM_JFE 0x0040
  76. #define AX_MEDIUM_TFC 0x0020
  77. #define AX_MEDIUM_RFC 0x0010
  78. #define AX_MEDIUM_ENCK 0x0008
  79. #define AX_MEDIUM_AC 0x0004
  80. #define AX_MEDIUM_FD 0x0002
  81. #define AX_MEDIUM_GM 0x0001
  82. #define AX_MEDIUM_SM 0x1000
  83. #define AX_MEDIUM_SBP 0x0800
  84. #define AX_MEDIUM_PS 0x0200
  85. #define AX_MEDIUM_RE 0x0100
  86. #define AX88178_MEDIUM_DEFAULT \
  87. (AX_MEDIUM_PS | AX_MEDIUM_FD | AX_MEDIUM_AC | \
  88. AX_MEDIUM_RFC | AX_MEDIUM_TFC | AX_MEDIUM_JFE | \
  89. AX_MEDIUM_RE)
  90. #define AX88772_MEDIUM_DEFAULT \
  91. (AX_MEDIUM_FD | AX_MEDIUM_PS | \
  92. AX_MEDIUM_AC | AX_MEDIUM_RE)
  93. /* AX88772 & AX88178 RX_CTL values */
  94. #define AX_RX_CTL_SO 0x0080
  95. #define AX_RX_CTL_AP 0x0020
  96. #define AX_RX_CTL_AM 0x0010
  97. #define AX_RX_CTL_AB 0x0008
  98. #define AX_RX_CTL_SEP 0x0004
  99. #define AX_RX_CTL_AMALL 0x0002
  100. #define AX_RX_CTL_PRO 0x0001
  101. #define AX_RX_CTL_MFB_2048 0x0000
  102. #define AX_RX_CTL_MFB_4096 0x0100
  103. #define AX_RX_CTL_MFB_8192 0x0200
  104. #define AX_RX_CTL_MFB_16384 0x0300
  105. #define AX_DEFAULT_RX_CTL (AX_RX_CTL_SO | AX_RX_CTL_AB)
  106. /* GPIO 0 .. 2 toggles */
  107. #define AX_GPIO_GPO0EN 0x01 /* GPIO0 Output enable */
  108. #define AX_GPIO_GPO_0 0x02 /* GPIO0 Output value */
  109. #define AX_GPIO_GPO1EN 0x04 /* GPIO1 Output enable */
  110. #define AX_GPIO_GPO_1 0x08 /* GPIO1 Output value */
  111. #define AX_GPIO_GPO2EN 0x10 /* GPIO2 Output enable */
  112. #define AX_GPIO_GPO_2 0x20 /* GPIO2 Output value */
  113. #define AX_GPIO_RESERVED 0x40 /* Reserved */
  114. #define AX_GPIO_RSE 0x80 /* Reload serial EEPROM */
  115. #define AX_EEPROM_MAGIC 0xdeadbeef
  116. #define AX_EEPROM_LEN 0x200
  117. #define AX_EMBD_PHY_ADDR 0x10
  118. struct usbh_asix {
  119. struct usbh_hubport *hport;
  120. struct usb_endpoint_descriptor *bulkin; /* Bulk IN endpoint */
  121. struct usb_endpoint_descriptor *bulkout; /* Bulk OUT endpoint */
  122. struct usb_endpoint_descriptor *intin; /* INTR IN endpoint */
  123. struct usbh_urb bulkout_urb;
  124. struct usbh_urb bulkin_urb;
  125. struct usbh_urb intin_urb;
  126. uint8_t intf;
  127. char *name;
  128. uint8_t phy_addr;
  129. uint8_t embd_phy;
  130. uint8_t chipcode;
  131. uint16_t mac_capabilities;
  132. bool connect_status;
  133. uint8_t mac[6];
  134. void *user_data;
  135. };
  136. #ifdef __cplusplus
  137. extern "C" {
  138. #endif
  139. int usbh_asix_get_connect_status(struct usbh_asix *asix_class);
  140. void usbh_asix_run(struct usbh_asix *asix_class);
  141. void usbh_asix_stop(struct usbh_asix *asix_class);
  142. uint8_t *usbh_asix_get_eth_txbuf(void);
  143. int usbh_asix_eth_output(uint32_t buflen);
  144. void usbh_asix_eth_input(uint8_t *buf, uint32_t buflen);
  145. void usbh_asix_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* USBH_ASIX_H */