atp.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Linux header file for the ATP pocket ethernet adapter. */
  3. /* v1.09 8/9/2000 becker@scyld.com. */
  4. #include <linux/if_ether.h>
  5. #include <linux/types.h>
  6. /* The header prepended to received packets. */
  7. struct rx_header {
  8. ushort pad; /* Pad. */
  9. ushort rx_count;
  10. ushort rx_status; /* Unknown bit assignments :-<. */
  11. ushort cur_addr; /* Apparently the current buffer address(?) */
  12. };
  13. #define PAR_DATA 0
  14. #define PAR_STATUS 1
  15. #define PAR_CONTROL 2
  16. #define Ctrl_LNibRead 0x08 /* LP_PSELECP */
  17. #define Ctrl_HNibRead 0
  18. #define Ctrl_LNibWrite 0x08 /* LP_PSELECP */
  19. #define Ctrl_HNibWrite 0
  20. #define Ctrl_SelData 0x04 /* LP_PINITP */
  21. #define Ctrl_IRQEN 0x10 /* LP_PINTEN */
  22. #define EOW 0xE0
  23. #define EOC 0xE0
  24. #define WrAddr 0x40 /* Set address of EPLC read, write register. */
  25. #define RdAddr 0xC0
  26. #define HNib 0x10
  27. enum page0_regs {
  28. /* The first six registers hold
  29. * the ethernet physical station address.
  30. */
  31. PAR0 = 0, PAR1 = 1, PAR2 = 2, PAR3 = 3, PAR4 = 4, PAR5 = 5,
  32. TxCNT0 = 6, TxCNT1 = 7, /* The transmit byte count. */
  33. TxSTAT = 8, RxSTAT = 9, /* Tx and Rx status. */
  34. ISR = 10, IMR = 11, /* Interrupt status and mask. */
  35. CMR1 = 12, /* Command register 1. */
  36. CMR2 = 13, /* Command register 2. */
  37. MODSEL = 14, /* Mode select register. */
  38. MAR = 14, /* Memory address register (?). */
  39. CMR2_h = 0x1d,
  40. };
  41. enum eepage_regs {
  42. PROM_CMD = 6,
  43. PROM_DATA = 7 /* Note that PROM_CMD is in the "high" bits. */
  44. };
  45. #define ISR_TxOK 0x01
  46. #define ISR_RxOK 0x04
  47. #define ISR_TxErr 0x02
  48. #define ISRh_RxErr 0x11 /* ISR, high nibble */
  49. #define CMR1h_MUX 0x08 /* Select printer multiplexor on 8012. */
  50. #define CMR1h_RESET 0x04 /* Reset. */
  51. #define CMR1h_RxENABLE 0x02 /* Rx unit enable. */
  52. #define CMR1h_TxENABLE 0x01 /* Tx unit enable. */
  53. #define CMR1h_TxRxOFF 0x00
  54. #define CMR1_ReXmit 0x08 /* Trigger a retransmit. */
  55. #define CMR1_Xmit 0x04 /* Trigger a transmit. */
  56. #define CMR1_IRQ 0x02 /* Interrupt active. */
  57. #define CMR1_BufEnb 0x01 /* Enable the buffer(?). */
  58. #define CMR1_NextPkt 0x01 /* Enable the buffer(?). */
  59. #define CMR2_NULL 8
  60. #define CMR2_IRQOUT 9
  61. #define CMR2_RAMTEST 10
  62. #define CMR2_EEPROM 12 /* Set to page 1, for reading the EEPROM. */
  63. #define CMR2h_OFF 0 /* No accept mode. */
  64. #define CMR2h_Physical 1 /* Accept a physical address match only. */
  65. #define CMR2h_Normal 2 /* Accept physical and broadcast address. */
  66. #define CMR2h_PROMISC 3 /* Promiscuous mode. */
  67. /* An inline function used below: it differs from inb() by explicitly
  68. * return an unsigned char, saving a truncation.
  69. */
  70. static inline unsigned char inbyte(unsigned short port)
  71. {
  72. unsigned char _v;
  73. __asm__ __volatile__ ("inb %w1,%b0" : "=a" (_v) : "d" (port));
  74. return _v;
  75. }
  76. /* Read register OFFSET.
  77. * This command should always be terminated with read_end().
  78. */
  79. static inline unsigned char read_nibble(short port, unsigned char offset)
  80. {
  81. unsigned char retval;
  82. outb(EOC+offset, port + PAR_DATA);
  83. outb(RdAddr+offset, port + PAR_DATA);
  84. inbyte(port + PAR_STATUS); /* Settling time delay */
  85. retval = inbyte(port + PAR_STATUS);
  86. outb(EOC+offset, port + PAR_DATA);
  87. return retval;
  88. }
  89. /* Functions for bulk data read. The interrupt line is always disabled. */
  90. /* Get a byte using read mode 0, reading data from the control lines. */
  91. static inline unsigned char read_byte_mode0(short ioaddr)
  92. {
  93. unsigned char low_nib;
  94. outb(Ctrl_LNibRead, ioaddr + PAR_CONTROL);
  95. inbyte(ioaddr + PAR_STATUS);
  96. low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
  97. outb(Ctrl_HNibRead, ioaddr + PAR_CONTROL);
  98. inbyte(ioaddr + PAR_STATUS); /* Settling time delay -- needed! */
  99. inbyte(ioaddr + PAR_STATUS); /* Settling time delay -- needed! */
  100. return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
  101. }
  102. /* The same as read_byte_mode0(), but does multiple inb()s for stability. */
  103. static inline unsigned char read_byte_mode2(short ioaddr)
  104. {
  105. unsigned char low_nib;
  106. outb(Ctrl_LNibRead, ioaddr + PAR_CONTROL);
  107. inbyte(ioaddr + PAR_STATUS);
  108. low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
  109. outb(Ctrl_HNibRead, ioaddr + PAR_CONTROL);
  110. inbyte(ioaddr + PAR_STATUS); /* Settling time delay -- needed! */
  111. return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
  112. }
  113. /* Read a byte through the data register. */
  114. static inline unsigned char read_byte_mode4(short ioaddr)
  115. {
  116. unsigned char low_nib;
  117. outb(RdAddr | MAR, ioaddr + PAR_DATA);
  118. low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
  119. outb(RdAddr | HNib | MAR, ioaddr + PAR_DATA);
  120. return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
  121. }
  122. /* Read a byte through the data register, double reading to allow settling. */
  123. static inline unsigned char read_byte_mode6(short ioaddr)
  124. {
  125. unsigned char low_nib;
  126. outb(RdAddr | MAR, ioaddr + PAR_DATA);
  127. inbyte(ioaddr + PAR_STATUS);
  128. low_nib = (inbyte(ioaddr + PAR_STATUS) >> 3) & 0x0f;
  129. outb(RdAddr | HNib | MAR, ioaddr + PAR_DATA);
  130. inbyte(ioaddr + PAR_STATUS);
  131. return low_nib | ((inbyte(ioaddr + PAR_STATUS) << 1) & 0xf0);
  132. }
  133. static inline void
  134. write_reg(short port, unsigned char reg, unsigned char value)
  135. {
  136. unsigned char outval;
  137. outb(EOC | reg, port + PAR_DATA);
  138. outval = WrAddr | reg;
  139. outb(outval, port + PAR_DATA);
  140. outb(outval, port + PAR_DATA); /* Double write for PS/2. */
  141. outval &= 0xf0;
  142. outval |= value;
  143. outb(outval, port + PAR_DATA);
  144. outval &= 0x1f;
  145. outb(outval, port + PAR_DATA);
  146. outb(outval, port + PAR_DATA);
  147. outb(EOC | outval, port + PAR_DATA);
  148. }
  149. static inline void
  150. write_reg_high(short port, unsigned char reg, unsigned char value)
  151. {
  152. unsigned char outval = EOC | HNib | reg;
  153. outb(outval, port + PAR_DATA);
  154. outval &= WrAddr | HNib | 0x0f;
  155. outb(outval, port + PAR_DATA);
  156. outb(outval, port + PAR_DATA); /* Double write for PS/2. */
  157. outval = WrAddr | HNib | value;
  158. outb(outval, port + PAR_DATA);
  159. outval &= HNib | 0x0f; /* HNib | value */
  160. outb(outval, port + PAR_DATA);
  161. outb(outval, port + PAR_DATA);
  162. outb(EOC | HNib | outval, port + PAR_DATA);
  163. }
  164. /* Write a byte out using nibble mode. The low nibble is written first. */
  165. static inline void
  166. write_reg_byte(short port, unsigned char reg, unsigned char value)
  167. {
  168. unsigned char outval;
  169. outb(EOC | reg, port + PAR_DATA); /* Reset the address register. */
  170. outval = WrAddr | reg;
  171. outb(outval, port + PAR_DATA);
  172. outb(outval, port + PAR_DATA); /* Double write for PS/2. */
  173. outb((outval & 0xf0) | (value & 0x0f), port + PAR_DATA);
  174. outb(value & 0x0f, port + PAR_DATA);
  175. value >>= 4;
  176. outb(value, port + PAR_DATA);
  177. outb(0x10 | value, port + PAR_DATA);
  178. outb(0x10 | value, port + PAR_DATA);
  179. outb(EOC | value, port + PAR_DATA); /* Reset the address register. */
  180. }
  181. /* Bulk data writes to the packet buffer. The interrupt line remains enabled.
  182. * The first, faster method uses only the dataport (data modes 0, 2 & 4).
  183. * The second (backup) method uses data and control regs (modes 1, 3 & 5).
  184. * It should only be needed when there is skew between the individual data
  185. * lines.
  186. */
  187. static inline void write_byte_mode0(short ioaddr, unsigned char value)
  188. {
  189. outb(value & 0x0f, ioaddr + PAR_DATA);
  190. outb((value>>4) | 0x10, ioaddr + PAR_DATA);
  191. }
  192. static inline void write_byte_mode1(short ioaddr, unsigned char value)
  193. {
  194. outb(value & 0x0f, ioaddr + PAR_DATA);
  195. outb(Ctrl_IRQEN | Ctrl_LNibWrite, ioaddr + PAR_CONTROL);
  196. outb((value>>4) | 0x10, ioaddr + PAR_DATA);
  197. outb(Ctrl_IRQEN | Ctrl_HNibWrite, ioaddr + PAR_CONTROL);
  198. }
  199. /* Write 16bit VALUE to the packet buffer: the same as above just doubled. */
  200. static inline void write_word_mode0(short ioaddr, unsigned short value)
  201. {
  202. outb(value & 0x0f, ioaddr + PAR_DATA);
  203. value >>= 4;
  204. outb((value & 0x0f) | 0x10, ioaddr + PAR_DATA);
  205. value >>= 4;
  206. outb(value & 0x0f, ioaddr + PAR_DATA);
  207. value >>= 4;
  208. outb((value & 0x0f) | 0x10, ioaddr + PAR_DATA);
  209. }
  210. /* EEPROM_Ctrl bits. */
  211. #define EE_SHIFT_CLK 0x04 /* EEPROM shift clock. */
  212. #define EE_CS 0x02 /* EEPROM chip select. */
  213. #define EE_CLK_HIGH 0x12
  214. #define EE_CLK_LOW 0x16
  215. #define EE_DATA_WRITE 0x01 /* EEPROM chip data in. */
  216. #define EE_DATA_READ 0x08 /* EEPROM chip data out. */
  217. /* Delay between EEPROM clock transitions. */
  218. #define eeprom_delay(ticks) \
  219. do { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; } } while (0)
  220. /* The EEPROM commands include the alway-set leading bit. */
  221. #define EE_WRITE_CMD(offset) (((5 << 6) + (offset)) << 17)
  222. #define EE_READ(offset) (((6 << 6) + (offset)) << 17)
  223. #define EE_ERASE(offset) (((7 << 6) + (offset)) << 17)
  224. #define EE_CMD_SIZE 27 /* The command+address+data size. */