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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * Split out into 3c509.c and 3c5x9.c, to make it possible to build a
  3. * 3c529 module without including ISA, ISAPnP and EISA code.
  4. *
  5. */
  6. #include "isa.h"
  7. #include "io.h"
  8. #include "timer.h"
  9. #include "string.h"
  10. #include "console.h"
  11. #include "3c509.h"
  12. /*
  13. * 3c509 cards have their own method of contention resolution; this
  14. * effectively defines another bus type.
  15. *
  16. */
  17. /*
  18. * A physical t509 device
  19. *
  20. */
  21. struct t509_device {
  22. char *magic; /* must be first */
  23. uint16_t id_port;
  24. uint16_t ioaddr;
  25. unsigned char current_tag;
  26. };
  27. /*
  28. * A t509 driver
  29. *
  30. */
  31. struct t509_driver {
  32. const char *name;
  33. };
  34. /*
  35. * Ensure that there is sufficient space in the shared dev_bus
  36. * structure for a struct pci_device.
  37. *
  38. */
  39. DEV_BUS( struct t509_device, t509_dev );
  40. static char t509_magic[0]; /* guaranteed unique symbol */
  41. /*
  42. * Find a port that can be used for contention select
  43. *
  44. * Called only once, so inlined for efficiency.
  45. *
  46. */
  47. static inline int find_id_port ( struct t509_device *t509 ) {
  48. for ( t509->id_port = EP_ID_PORT_START ;
  49. t509->id_port < EP_ID_PORT_END ;
  50. t509->id_port += EP_ID_PORT_INC ) {
  51. outb ( 0x00, t509->id_port );
  52. outb ( 0xff, t509->id_port );
  53. if ( inb ( t509->id_port ) & 0x01 ) {
  54. /* Found a suitable port */
  55. return 1;
  56. }
  57. }
  58. /* No id port available */
  59. return 0;
  60. }
  61. /*
  62. * Send ID sequence to the ID port
  63. *
  64. * Called only once, so inlined for efficiency.
  65. *
  66. */
  67. static inline void send_id_sequence ( struct t509_device *t509 ) {
  68. unsigned short lrs_state, i;
  69. outb ( 0x00, t509->id_port );
  70. outb ( 0x00, t509->id_port );
  71. lrs_state = 0xff;
  72. for ( i = 0; i < 255; i++ ) {
  73. outb ( lrs_state, t509->id_port );
  74. lrs_state <<= 1;
  75. lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
  76. }
  77. }
  78. /*
  79. * We get eeprom data from the id_port given an offset into the eeprom.
  80. * Basically; after the ID_sequence is sent to all of the cards; they enter
  81. * the ID_CMD state where they will accept command requests. 0x80-0xbf loads
  82. * the eeprom data. We then read the port 16 times and with every read; the
  83. * cards check for contention (ie: if one card writes a 0 bit and another
  84. * writes a 1 bit then the host sees a 0. At the end of the cycle; each card
  85. * compares the data on the bus; if there is a difference then that card goes
  86. * into ID_WAIT state again). In the meantime; one bit of data is returned in
  87. * the AX register which is conveniently returned to us by inb(). Hence; we
  88. * read 16 times getting one bit of data with each read.
  89. */
  90. static uint16_t id_read_eeprom ( struct t509_device *t509, int offset ) {
  91. int i, data = 0;
  92. outb ( 0x80 + offset, t509->id_port );
  93. /* Do we really need this wait? Won't be noticeable anyway */
  94. udelay(10000);
  95. for ( i = 0; i < 16; i++ ) {
  96. data = ( data << 1 ) | ( inw ( t509->id_port ) & 1 );
  97. }
  98. return data;
  99. }
  100. /*
  101. * Find the next t509 device
  102. *
  103. * Called only once, so inlined for efficiency.
  104. *
  105. */
  106. static inline int fill_t509_device ( struct t509_device *t509 ) {
  107. int i;
  108. uint16_t iobase;
  109. /*
  110. * We need an ID port, if we don't already have one.
  111. *
  112. */
  113. if ( ! t509->id_port ) {
  114. if ( ! find_id_port ( t509 ) ) {
  115. DBG ( "No ID port available for contention select\n" );
  116. return 0;
  117. }
  118. DBG ( "T509 scan using ID port at %hx\n", t509->id_port );
  119. }
  120. /*
  121. * If this is the start of the scan, clear all tag registers.
  122. * Otherwise, tell already-found NICs not to respond.
  123. *
  124. */
  125. if ( t509->current_tag == 0 ) {
  126. outb ( 0xd0, t509->id_port );
  127. } else {
  128. outb ( 0xd8, t509->id_port ) ;
  129. }
  130. /* Send the ID sequence */
  131. send_id_sequence ( t509 );
  132. /* Check the manufacturer ID */
  133. if ( id_read_eeprom ( t509, EEPROM_MFG_ID ) != MFG_ID ) {
  134. /* No more t509 devices */
  135. return 0;
  136. }
  137. /* Do contention select by reading the MAC address */
  138. for ( i = 0 ; i < 3 ; i++ ) {
  139. id_read_eeprom ( t509, i );
  140. }
  141. /* By now, only one device will be left active. Get its I/O
  142. * address, tag and activate the adaptor. Tagging will
  143. * prevent it taking part in the next scan, enabling us to see
  144. * the next device.
  145. */
  146. iobase = id_read_eeprom ( t509, EEPROM_ADDR_CFG );
  147. t509->ioaddr = 0x200 + ( ( iobase & 0x1f ) << 4 );
  148. outb ( ++t509->current_tag, t509->id_port ); /* tag */
  149. outb ( ( 0xe0 | iobase ), t509->id_port ); /* activate */
  150. DBG ( "T509 found at %hx (tagged as %hhx)\n", t509->ioaddr,
  151. t509->current_tag );
  152. return 1;
  153. }
  154. /*
  155. * Find a t509 device matching the specified driver. ("Matching the
  156. * specified driver" is, in this case, a no-op, but we want to
  157. * preserve the common bus API).
  158. *
  159. * Called only once, so inlined for efficiency.
  160. *
  161. */
  162. static inline int find_t509_device ( struct t509_device *t509,
  163. struct t509_driver *driver __unused ) {
  164. /* Initialise struct t509 if it's the first time it's been used. */
  165. if ( t509->magic != t509_magic ) {
  166. memset ( t509, 0, sizeof ( *t509 ) );
  167. t509->magic = t509_magic;
  168. }
  169. /* Find the next t509 device */
  170. if ( ! fill_t509_device ( t509 ) )
  171. return 0;
  172. return 1;
  173. }
  174. /*
  175. * Find the next T509 device that can be used to boot using the
  176. * specified driver.
  177. *
  178. */
  179. int find_t509_boot_device ( struct dev *dev, struct t509_driver *driver ) {
  180. struct t509_device *t509 = ( struct t509_device * )dev->bus;
  181. if ( ! find_t509_device ( t509, driver ) )
  182. return 0;
  183. dev->name = driver->name;
  184. dev->devid.bus_type = ISA_BUS_TYPE;
  185. dev->devid.vendor_id = MFG_ID;
  186. dev->devid.device_id = PROD_ID;
  187. return 1;
  188. }
  189. /*
  190. * The ISA probe function
  191. *
  192. */
  193. static int el3_t509_probe ( struct dev *dev, struct t509_device *t509 ) {
  194. struct nic *nic = nic_device ( dev );
  195. nic->ioaddr = t509->ioaddr;
  196. nic->irqno = 0;
  197. printf ( "3c509 board on ISA at %#hx - ", nic->ioaddr );
  198. /* Hand off to generic t5x9 probe routine */
  199. return t5x9_probe ( nic, ISA_PROD_ID ( PROD_ID ), ISA_PROD_ID_MASK );
  200. }
  201. static struct t509_driver el3_t509_driver = { "3c509 (ISA)" };
  202. BOOT_DRIVER ( "3c509", find_t509_boot_device, el3_t509_driver,
  203. el3_t509_probe );
  204. ISA_ROM ( "3c509","3c509" );