Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
7.0 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /**
  2. * @file
  3. * Netman common definitions
  4. */
  5. #ifndef __NETMAN_H__
  6. #define __NETMAN_H__
  7. #include <tamtypes.h>
  8. //Common structures
  9. #define NETMAN_NETIF_NAME_MAX_LEN 4
  10. #define NETMAN_NETIF_FRAME_SIZE 1514
  11. #define NETMAN_FRAME_GROUP_SIZE 8 //The actual number of DMA transfer tags is twice this. The total number presented to sceSifSetDma must never exceed 32.
  12. struct NetManNetProtStack{
  13. void (*LinkStateUp)(void);
  14. void (*LinkStateDown)(void);
  15. void *(*AllocRxPacket)(unsigned int size, void **payload);
  16. void (*FreeRxPacket)(void *packet);
  17. void (*EnQRxPacket)(void *packet);
  18. int (*NextTxPacket)(void **payload);
  19. void (*DeQTxPacket)(void);
  20. int (*AfterTxPacket)(void **payload); //For EE only, peek at the packet after the current packet.
  21. void (*ReallocRxPacket)(void *packet, unsigned int size); //For EE only, update the size of the Rx packet (size will be always smaller than NETMAN_NETIF_FRAME_SIZE).
  22. };
  23. struct NetManEthRuntimeStats{
  24. u32 RxDroppedFrameCount;
  25. u32 RxErrorCount;
  26. u16 RxFrameOverrunCount;
  27. u16 RxFrameBadLengthCount;
  28. u16 RxFrameBadFCSCount;
  29. u16 RxFrameBadAlignmentCount;
  30. u32 TxDroppedFrameCount;
  31. u32 TxErrorCount;
  32. u16 TxFrameLOSSCRCount;
  33. u16 TxFrameEDEFERCount;
  34. u16 TxFrameCollisionCount;
  35. u16 TxFrameUnderrunCount;
  36. u16 RxAllocFail;
  37. };
  38. struct NetManEthStatus{
  39. u8 LinkStatus, LinkMode;
  40. struct NetManEthRuntimeStats stats;
  41. };
  42. /** Flow-control */
  43. #define NETMAN_NETIF_ETH_LINK_DISABLE_PAUSE 0x40
  44. enum NETMAN_NETIF_ETH_LINK_MODE{
  45. /** Auto negotiation cannot be reflected by NETMAN_NETIF_IOCTL_ETH_GET_LINK_MODE. */
  46. NETMAN_NETIF_ETH_LINK_MODE_AUTO = 0,
  47. /** 10Mbit Half-DupleX */
  48. NETMAN_NETIF_ETH_LINK_MODE_10M_HDX,
  49. /** 10Mbit Full-DupleX */
  50. NETMAN_NETIF_ETH_LINK_MODE_10M_FDX,
  51. /** 100Mbit Half-DupleX */
  52. NETMAN_NETIF_ETH_LINK_MODE_100M_HDX,
  53. /** 100Mbit Full-DupleX */
  54. NETMAN_NETIF_ETH_LINK_MODE_100M_FDX,
  55. NETMAN_NETIF_ETH_LINK_MODE_COUNT
  56. };
  57. enum NETMAN_NETIF_ETH_LINK_STATE{
  58. NETMAN_NETIF_ETH_LINK_STATE_DOWN = 0,
  59. NETMAN_NETIF_ETH_LINK_STATE_UP
  60. };
  61. enum NETMAN_NETIF_IOCTL_CODES{
  62. // Ethernet I/F-only IOCTL codes
  63. /** Output = 6 bytes of MAC address. */
  64. NETMAN_NETIF_IOCTL_ETH_GET_MAC = 0x1000,
  65. //Function codes with no input and no output; the result is in the return value.
  66. NETMAN_NETIF_IOCTL_ETH_GET_LINK_MODE,
  67. NETMAN_NETIF_IOCTL_ETH_GET_RX_EOVERRUN_CNT,
  68. NETMAN_NETIF_IOCTL_ETH_GET_RX_EBADLEN_CNT,
  69. NETMAN_NETIF_IOCTL_ETH_GET_RX_EBADFCS_CNT,
  70. NETMAN_NETIF_IOCTL_ETH_GET_RX_EBADALIGN_CNT,
  71. NETMAN_NETIF_IOCTL_ETH_GET_TX_ELOSSCR_CNT,
  72. NETMAN_NETIF_IOCTL_ETH_GET_TX_EEDEFER_CNT,
  73. NETMAN_NETIF_IOCTL_ETH_GET_TX_ECOLL_CNT,
  74. NETMAN_NETIF_IOCTL_ETH_GET_TX_EUNDERRUN_CNT,
  75. //Returns struct NetManEthStatus
  76. NETMAN_NETIF_IOCTL_ETH_GET_STATUS,
  77. /** Input = struct NetManIFLinkModeParams. Note: does not wait for the IF to finish. Use NetManSetLinkMode() instead. */
  78. NETMAN_NETIF_IOCTL_ETH_SET_LINK_MODE,
  79. // Dial-up I/F-only IOCTL codes
  80. // 0x2000
  81. // Common IOCTL codes
  82. NETMAN_NETIF_IOCTL_GET_LINK_STATUS = 0x3000,
  83. NETMAN_NETIF_IOCTL_GET_TX_DROPPED_COUNT,
  84. NETMAN_NETIF_IOCTL_GET_RX_DROPPED_COUNT,
  85. };
  86. //*** Higher-level services, for the running user program ***
  87. //Initialization and deinitialization functions, for the EE side.
  88. #ifdef _EE
  89. int NetManInit(void);
  90. void NetManDeinit(void);
  91. #endif
  92. //Network Interface (IF) control.
  93. int NetManGetGlobalNetIFLinkState(void);
  94. int NetManSetMainIF(const char *name);
  95. int NetManQueryMainIF(char *name);
  96. //*** System functions for either the Network IF driver or the network protocol stack ***
  97. //For the network protocol stack to initialize/deinitialize NETMAN.
  98. int NetManRegisterNetworkStack(const struct NetManNetProtStack *stack);
  99. void NetManUnregisterNetworkStack(void);
  100. /* Common network Interface (IF) management functions. Used by the user program and the protocol stack. */
  101. int NetManIoctl(unsigned int command, void *args, unsigned int args_len, void *output, unsigned int length);
  102. int NetManSetLinkMode(int mode);
  103. /* Network Interface (IF) management functions. Used by the protocol stack. */
  104. void NetManNetIFXmit(void); //Notify the interface of available packets. May be called from the interrupt context.
  105. /* Network protocol stack management functions. Used by the Network InterFace (IF) driver. */
  106. void *NetManNetProtStackAllocRxPacket(unsigned int length, void **payload);
  107. void NetManNetProtStackFreeRxPacket(void *packet);
  108. void NetManNetProtStackEnQRxPacket(void *packet);
  109. int NetManTxPacketNext(void **payload);
  110. void NetManTxPacketDeQ(void);
  111. int NetManTxPacketAfter(void **payload); //For EE only, for NETMAN's internal use.
  112. void NetManNetProtStackReallocRxPacket(void *packet, unsigned int length); //For EE only, for NETMAN's internal use.
  113. /* NETIF flags. */
  114. /** Set internally by NETMAN. Do not set externally. */
  115. #define NETMAN_NETIF_IN_USE 0x80
  116. /** Set = network IF is an Ethernet IF. */
  117. #define NETMAN_NETIF_ETHERNET 1
  118. /** Set = network IF is a dailup modem. */
  119. #define NETMAN_NETIF_DIALUP 2
  120. /** Set = network IF has a link up status. */
  121. #define NETMAN_NETIF_LINK_UP 4
  122. struct NetManNetIF{
  123. char name[NETMAN_NETIF_NAME_MAX_LEN];
  124. unsigned short int flags;
  125. /** Used internally by NETMAN. Do not use. */
  126. short int id;
  127. int (*init)(void);
  128. void (*deinit)(void);
  129. void (*xmit)(void);
  130. int (*ioctl)(unsigned int command, void *args, unsigned int args_len, void *output, unsigned int length);
  131. int EventFlagID;
  132. };
  133. //IF event flag bits, set by NETMAN
  134. #define NETMAN_NETIF_EVF_UP 0x01
  135. #define NETMAN_NETIF_EVF_DOWN 0x02
  136. #define NETMAN_MAX_NETIF_COUNT 2
  137. /* Network InterFace (IF) management functions. Used by the network InterFace (IF). */
  138. int NetManRegisterNetIF(struct NetManNetIF *NetIF);
  139. void NetManUnregisterNetIF(const char *name);
  140. void NetManToggleNetIFLinkState(int NetIFID, unsigned char state); //Also toggles NETMAN_NETIF_EVF_UP and NETMAN_NETIF_EVF_DOWN
  141. #ifdef _IOP
  142. #define netman_IMPORTS_start DECLARE_IMPORT_TABLE(netman, 3, 1)
  143. #define netman_IMPORTS_end END_IMPORT_TABLE
  144. #define I_NetManRegisterNetworkStack DECLARE_IMPORT(4, NetManRegisterNetworkStack)
  145. #define I_NetManUnregisterNetworkStack DECLARE_IMPORT(5, NetManUnregisterNetworkStack)
  146. #define I_NetManNetIFXmit DECLARE_IMPORT(6, NetManNetIFXmit)
  147. #define I_NetManIoctl DECLARE_IMPORT(7, NetManIoctl)
  148. #define I_NetManNetProtStackAllocPacket DECLARE_IMPORT(8, NetManNetProtStackAllocRxPacket)
  149. #define I_NetManNetProtStackFreePacket DECLARE_IMPORT(9, NetManNetProtStackFreeRxPacket)
  150. #define I_NetManNetProtStackEnQPacket DECLARE_IMPORT(10, NetManNetProtStackEnQRxPacket)
  151. #define I_NetManRegisterNetIF DECLARE_IMPORT(11, NetManRegisterNetIF)
  152. #define I_NetManUnregisterNetIF DECLARE_IMPORT(12, NetManUnregisterNetIF)
  153. #define I_NetManToggleNetIFLinkState DECLARE_IMPORT(13, NetManToggleNetIFLinkState)
  154. #define I_NetManGetGlobalNetIFLinkState DECLARE_IMPORT(14, NetManGetGlobalNetIFLinkState)
  155. #define I_NetManSetMainIF DECLARE_IMPORT(15, NetManSetMainIF)
  156. #define I_NetManQueryMainIF DECLARE_IMPORT(16, NetManQueryMainIF)
  157. #define I_NetManSetLinkMode DECLARE_IMPORT(17, NetManSetLinkMode)
  158. #define I_NetManTxPacketNext DECLARE_IMPORT(18, NetManTxPacketNext)
  159. #define I_NetManTxPacketDeQ DECLARE_IMPORT(19, NetManTxPacketDeQ)
  160. #endif
  161. #endif /* __NETMAN_H__ */