Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #ifndef __SIS190_H__
  2. #define __SIS190_H__
  3. FILE_LICENCE ( GPL_ANY );
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stddef.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include <assert.h>
  11. #include <byteswap.h>
  12. #include <errno.h>
  13. #include <mii.h>
  14. #include <ipxe/ethernet.h>
  15. #include <ipxe/if_ether.h>
  16. #include <ipxe/io.h>
  17. #include <ipxe/iobuf.h>
  18. #include <ipxe/malloc.h>
  19. #include <ipxe/netdevice.h>
  20. #include <ipxe/pci.h>
  21. #include <ipxe/timer.h>
  22. #define PCI_VENDOR_ID_SI 0x1039
  23. #define PHY_MAX_ADDR 32
  24. #define PHY_ID_ANY 0x1f
  25. #define MII_REG_ANY 0x1f
  26. #define DRV_VERSION "1.3"
  27. #define DRV_NAME "sis190"
  28. #define SIS190_DRIVER_NAME DRV_NAME " Gigabit Ethernet driver " DRV_VERSION
  29. #define PFX DRV_NAME ": "
  30. #define sis190_rx_quota(count, quota) count
  31. #define NUM_TX_DESC 8 /* [8..1024] */
  32. #define NUM_RX_DESC 8 /* [8..8192] */
  33. #define TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc))
  34. #define RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc))
  35. #define RX_BUF_SIZE 1536
  36. #define RX_BUF_MASK 0xfff8
  37. #define RING_ALIGNMENT 256
  38. #define SIS190_REGS_SIZE 0x80
  39. /* Enhanced PHY access register bit definitions */
  40. #define EhnMIIread 0x0000
  41. #define EhnMIIwrite 0x0020
  42. #define EhnMIIdataShift 16
  43. #define EhnMIIpmdShift 6 /* 7016 only */
  44. #define EhnMIIregShift 11
  45. #define EhnMIIreq 0x0010
  46. #define EhnMIInotDone 0x0010
  47. /* Write/read MMIO register */
  48. #define SIS_W8(reg, val) writeb ((val), ioaddr + (reg))
  49. #define SIS_W16(reg, val) writew ((val), ioaddr + (reg))
  50. #define SIS_W32(reg, val) writel ((val), ioaddr + (reg))
  51. #define SIS_R8(reg) readb (ioaddr + (reg))
  52. #define SIS_R16(reg) readw (ioaddr + (reg))
  53. #define SIS_R32(reg) readl (ioaddr + (reg))
  54. #define SIS_PCI_COMMIT() SIS_R32(IntrControl)
  55. enum sis190_registers {
  56. TxControl = 0x00,
  57. TxDescStartAddr = 0x04,
  58. rsv0 = 0x08, // reserved
  59. TxSts = 0x0c, // unused (Control/Status)
  60. RxControl = 0x10,
  61. RxDescStartAddr = 0x14,
  62. rsv1 = 0x18, // reserved
  63. RxSts = 0x1c, // unused
  64. IntrStatus = 0x20,
  65. IntrMask = 0x24,
  66. IntrControl = 0x28,
  67. IntrTimer = 0x2c, // unused (Interrupt Timer)
  68. PMControl = 0x30, // unused (Power Mgmt Control/Status)
  69. rsv2 = 0x34, // reserved
  70. ROMControl = 0x38,
  71. ROMInterface = 0x3c,
  72. StationControl = 0x40,
  73. GMIIControl = 0x44,
  74. GIoCR = 0x48, // unused (GMAC IO Compensation)
  75. GIoCtrl = 0x4c, // unused (GMAC IO Control)
  76. TxMacControl = 0x50,
  77. TxLimit = 0x54, // unused (Tx MAC Timer/TryLimit)
  78. RGDelay = 0x58, // unused (RGMII Tx Internal Delay)
  79. rsv3 = 0x5c, // reserved
  80. RxMacControl = 0x60,
  81. RxMacAddr = 0x62,
  82. RxHashTable = 0x68,
  83. // Undocumented = 0x6c,
  84. RxWolCtrl = 0x70,
  85. RxWolData = 0x74, // unused (Rx WOL Data Access)
  86. RxMPSControl = 0x78, // unused (Rx MPS Control)
  87. rsv4 = 0x7c, // reserved
  88. };
  89. enum sis190_register_content {
  90. /* IntrStatus */
  91. SoftInt = 0x40000000, // unused
  92. Timeup = 0x20000000, // unused
  93. PauseFrame = 0x00080000, // unused
  94. MagicPacket = 0x00040000, // unused
  95. WakeupFrame = 0x00020000, // unused
  96. LinkChange = 0x00010000,
  97. RxQEmpty = 0x00000080,
  98. RxQInt = 0x00000040,
  99. TxQ1Empty = 0x00000020, // unused
  100. TxQ1Int = 0x00000010,
  101. TxQ0Empty = 0x00000008, // unused
  102. TxQ0Int = 0x00000004,
  103. RxHalt = 0x00000002,
  104. TxHalt = 0x00000001,
  105. /* {Rx/Tx}CmdBits */
  106. CmdReset = 0x10,
  107. CmdRxEnb = 0x08, // unused
  108. CmdTxEnb = 0x01,
  109. RxBufEmpty = 0x01, // unused
  110. /* Cfg9346Bits */
  111. Cfg9346_Lock = 0x00, // unused
  112. Cfg9346_Unlock = 0xc0, // unused
  113. /* RxMacControl */
  114. AcceptErr = 0x20, // unused
  115. AcceptRunt = 0x10, // unused
  116. AcceptBroadcast = 0x0800,
  117. AcceptMulticast = 0x0400,
  118. AcceptMyPhys = 0x0200,
  119. AcceptAllPhys = 0x0100,
  120. /* RxConfigBits */
  121. RxCfgFIFOShift = 13,
  122. RxCfgDMAShift = 8, // 0x1a in RxControl ?
  123. /* TxConfigBits */
  124. TxInterFrameGapShift = 24,
  125. TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */
  126. LinkStatus = 0x02, // unused
  127. FullDup = 0x01, // unused
  128. /* TBICSRBit */
  129. TBILinkOK = 0x02000000, // unused
  130. };
  131. struct TxDesc {
  132. volatile u32 PSize;
  133. volatile u32 status;
  134. volatile u32 addr;
  135. volatile u32 size;
  136. };
  137. struct RxDesc {
  138. volatile u32 PSize;
  139. volatile u32 status;
  140. volatile u32 addr;
  141. volatile u32 size;
  142. };
  143. enum _DescStatusBit {
  144. /* _Desc.status */
  145. OWNbit = 0x80000000, // RXOWN/TXOWN
  146. INTbit = 0x40000000, // RXINT/TXINT
  147. CRCbit = 0x00020000, // CRCOFF/CRCEN
  148. PADbit = 0x00010000, // PREADD/PADEN
  149. /* _Desc.size */
  150. RingEnd = 0x80000000,
  151. /* TxDesc.status */
  152. LSEN = 0x08000000, // TSO ? -- FR
  153. IPCS = 0x04000000,
  154. TCPCS = 0x02000000,
  155. UDPCS = 0x01000000,
  156. BSTEN = 0x00800000,
  157. EXTEN = 0x00400000,
  158. DEFEN = 0x00200000,
  159. BKFEN = 0x00100000,
  160. CRSEN = 0x00080000,
  161. COLEN = 0x00040000,
  162. THOL3 = 0x30000000,
  163. THOL2 = 0x20000000,
  164. THOL1 = 0x10000000,
  165. THOL0 = 0x00000000,
  166. WND = 0x00080000,
  167. TABRT = 0x00040000,
  168. FIFO = 0x00020000,
  169. LINK = 0x00010000,
  170. ColCountMask = 0x0000ffff,
  171. /* RxDesc.status */
  172. IPON = 0x20000000,
  173. TCPON = 0x10000000,
  174. UDPON = 0x08000000,
  175. Wakup = 0x00400000,
  176. Magic = 0x00200000,
  177. Pause = 0x00100000,
  178. DEFbit = 0x00200000,
  179. BCAST = 0x000c0000,
  180. MCAST = 0x00080000,
  181. UCAST = 0x00040000,
  182. /* RxDesc.PSize */
  183. TAGON = 0x80000000,
  184. RxDescCountMask = 0x7f000000, // multi-desc pkt when > 1 ? -- FR
  185. ABORT = 0x00800000,
  186. SHORT = 0x00400000,
  187. LIMIT = 0x00200000,
  188. MIIER = 0x00100000,
  189. OVRUN = 0x00080000,
  190. NIBON = 0x00040000,
  191. COLON = 0x00020000,
  192. CRCOK = 0x00010000,
  193. RxSizeMask = 0x0000ffff
  194. /*
  195. * The asic could apparently do vlan, TSO, jumbo (sis191 only) and
  196. * provide two (unused with Linux) Tx queues. No publicly
  197. * available documentation alas.
  198. */
  199. };
  200. enum sis190_eeprom_access_register_bits {
  201. EECS = 0x00000001, // unused
  202. EECLK = 0x00000002, // unused
  203. EEDO = 0x00000008, // unused
  204. EEDI = 0x00000004, // unused
  205. EEREQ = 0x00000080,
  206. EEROP = 0x00000200,
  207. EEWOP = 0x00000100 // unused
  208. };
  209. /* EEPROM Addresses */
  210. enum sis190_eeprom_address {
  211. EEPROMSignature = 0x00,
  212. EEPROMCLK = 0x01, // unused
  213. EEPROMInfo = 0x02,
  214. EEPROMMACAddr = 0x03
  215. };
  216. enum sis190_feature {
  217. F_HAS_RGMII = 1,
  218. F_PHY_88E1111 = 2,
  219. F_PHY_BCM5461 = 4
  220. };
  221. struct sis190_private {
  222. void *mmio_addr;
  223. struct pci_device *pci_device;
  224. struct net_device *dev;
  225. u32 cur_rx;
  226. u32 cur_tx;
  227. u32 dirty_rx;
  228. u32 dirty_tx;
  229. u32 rx_dma;
  230. u32 tx_dma;
  231. struct RxDesc *RxDescRing;
  232. struct TxDesc *TxDescRing;
  233. struct io_buffer *Rx_iobuf[NUM_RX_DESC];
  234. struct io_buffer *Tx_iobuf[NUM_TX_DESC];
  235. struct mii_if_info mii_if;
  236. struct list_head first_phy;
  237. u32 features;
  238. };
  239. struct sis190_phy {
  240. struct list_head list;
  241. int phy_id;
  242. u16 id[2];
  243. u16 status;
  244. u8 type;
  245. };
  246. enum sis190_phy_type {
  247. UNKNOWN = 0x00,
  248. HOME = 0x01,
  249. LAN = 0x02,
  250. MIX = 0x03
  251. };
  252. static struct mii_chip_info {
  253. const char *name;
  254. u16 id[2];
  255. unsigned int type;
  256. u32 feature;
  257. } mii_chip_table[] = {
  258. { "Atheros PHY", { 0x004d, 0xd010 }, LAN, 0 },
  259. { "Atheros PHY AR8012", { 0x004d, 0xd020 }, LAN, 0 },
  260. { "Broadcom PHY BCM5461", { 0x0020, 0x60c0 }, LAN, F_PHY_BCM5461 },
  261. { "Broadcom PHY AC131", { 0x0143, 0xbc70 }, LAN, 0 },
  262. { "Agere PHY ET1101B", { 0x0282, 0xf010 }, LAN, 0 },
  263. { "Marvell PHY 88E1111", { 0x0141, 0x0cc0 }, LAN, F_PHY_88E1111 },
  264. { "Realtek PHY RTL8201", { 0x0000, 0x8200 }, LAN, 0 },
  265. { NULL, { 0x00, 0x00 }, 0, 0 }
  266. };
  267. static void sis190_phy_task(struct sis190_private *tp);
  268. static void sis190_free(struct net_device *dev);
  269. static inline void sis190_init_rxfilter(struct net_device *dev);
  270. #endif