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.

sis190.h 7.4KB

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