選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

3c509.c 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 similar to ISAPnP. Even the
  15. * original ISA cards can be programatically mapped to any I/O address
  16. * in the range 0x200-0x3e0.
  17. *
  18. * However, there is a small problem: once you've activated a card,
  19. * the only ways to deactivate it will also wipe its tag, meaning that
  20. * you won't be able to subsequently reactivate it without going
  21. * through the whole ID sequence again. The solution we adopt is to
  22. * isolate and tag all cards at the start, and to immediately
  23. * re-isolate and re-tag a card after disabling it.
  24. *
  25. */
  26. static uint16_t t509_id_port = 0;
  27. static uint8_t t509_max_tag = 0;
  28. /*
  29. * A location on a t509 bus
  30. *
  31. */
  32. struct t509_loc {
  33. uint8_t tag;
  34. };
  35. /*
  36. * A physical t509 device
  37. *
  38. */
  39. struct t509_device {
  40. uint16_t ioaddr;
  41. uint8_t tag;
  42. };
  43. /*
  44. * t509 utility functions
  45. *
  46. */
  47. static inline void t509_set_id_port ( void ) {
  48. outb ( 0x00, t509_id_port );
  49. }
  50. static inline void t509_wait_for_id_sequence ( void ) {
  51. outb ( 0x00, t509_id_port );
  52. }
  53. static inline void t509_global_reset ( void ) {
  54. outb ( 0xc0, t509_id_port );
  55. }
  56. static inline void t509_reset_tag ( void ) {
  57. outb ( 0xd0, t509_id_port );
  58. }
  59. static inline void t509_set_tag ( uint8_t tag ) {
  60. outb ( 0xd0 | tag, t509_id_port );
  61. }
  62. static inline void t509_select_tag ( uint8_t tag ) {
  63. outb ( 0xd8 | tag, t509_id_port );
  64. }
  65. static inline void t509_activate ( uint16_t ioaddr ) {
  66. outb ( 0xe0 | ( ioaddr >> 4 ), t509_id_port );
  67. }
  68. static inline void t509_deactivate_and_reset_tag ( uint16_t ioaddr ) {
  69. outb ( GLOBAL_RESET, ioaddr + EP_COMMAND );
  70. }
  71. static inline void t509_load_eeprom_word ( uint8_t offset ) {
  72. outb ( 0x80 | offset, t509_id_port );
  73. }
  74. /*
  75. * Find a suitable ID port
  76. *
  77. */
  78. static inline int t509_find_id_port ( void ) {
  79. for ( t509_id_port = EP_ID_PORT_START ;
  80. t509_id_port < EP_ID_PORT_END ;
  81. t509_id_port += EP_ID_PORT_INC ) {
  82. t509_set_id_port ();
  83. /* See if anything's listening */
  84. outb ( 0xff, t509_id_port );
  85. if ( inb ( t509_id_port ) & 0x01 ) {
  86. /* Found a suitable port */
  87. DBG ( "T509 using ID port at %hx\n", t509_id_port );
  88. return 1;
  89. }
  90. }
  91. /* No id port available */
  92. DBG ( "T509 found no available ID port\n" );
  93. return 0;
  94. }
  95. /*
  96. * Send ID sequence to the ID port
  97. *
  98. */
  99. static void t509_send_id_sequence ( void ) {
  100. unsigned short lrs_state, i;
  101. t509_set_id_port ();
  102. /* Reset IDS on cards */
  103. t509_wait_for_id_sequence ();
  104. lrs_state = 0xff;
  105. for ( i = 0; i < 255; i++ ) {
  106. outb ( lrs_state, t509_id_port );
  107. lrs_state <<= 1;
  108. lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
  109. }
  110. }
  111. /*
  112. * We get eeprom data from the id_port given an offset into the eeprom.
  113. * Basically; after the ID_sequence is sent to all of the cards; they enter
  114. * the ID_CMD state where they will accept command requests. 0x80-0xbf loads
  115. * the eeprom data. We then read the port 16 times and with every read; the
  116. * cards check for contention (ie: if one card writes a 0 bit and another
  117. * writes a 1 bit then the host sees a 0. At the end of the cycle; each card
  118. * compares the data on the bus; if there is a difference then that card goes
  119. * into ID_WAIT state again). In the meantime; one bit of data is returned in
  120. * the AX register which is conveniently returned to us by inb(). Hence; we
  121. * read 16 times getting one bit of data with each read.
  122. */
  123. static uint16_t t509_id_read_eeprom ( int offset ) {
  124. int i, data = 0;
  125. t509_load_eeprom_word ( offset );
  126. /* Do we really need this wait? Won't be noticeable anyway */
  127. udelay(10000);
  128. for ( i = 0; i < 16; i++ ) {
  129. data = ( data << 1 ) | ( inw ( t509_id_port ) & 1 );
  130. }
  131. return data;
  132. }
  133. /*
  134. * Isolate and tag all t509 cards
  135. *
  136. */
  137. static void t509_isolate ( void ) {
  138. unsigned int i;
  139. uint16_t contend[3];
  140. /* Find a suitable ID port */
  141. if ( ! t509_find_id_port () )
  142. return;
  143. while ( 1 ) {
  144. /* All cards are in ID_WAIT state each time we go
  145. * through this loop.
  146. */
  147. /* Send the ID sequence */
  148. t509_send_id_sequence ();
  149. /* First time through, reset all tags. On subsequent
  150. * iterations, kill off any already-tagged cards
  151. */
  152. if ( t509_max_tag == 0 ) {
  153. t509_reset_tag();
  154. } else {
  155. t509_select_tag(0);
  156. }
  157. /* Read the manufacturer ID, to see if there are any
  158. * more cards
  159. */
  160. if ( t509_id_read_eeprom ( EEPROM_MFG_ID ) != MFG_ID ) {
  161. DBG ( "T509 saw %s signs of life\n",
  162. t509_max_tag ? "no further" : "no" );
  163. break;
  164. }
  165. /* Perform contention selection on the MAC address */
  166. for ( i = 0 ; i < 3 ; i++ ) {
  167. contend[i] = t509_id_read_eeprom ( i );
  168. }
  169. /* Only one device will still be left alive. Tag it. */
  170. ++t509_max_tag;
  171. DBG ( "T509 found card %hx%hx%hx, assigning tag %hhx\n",
  172. contend[0], contend[1], contend[2], t509_max_tag );
  173. t509_set_tag ( t509_max_tag );
  174. /* Return all cards back to ID_WAIT state */
  175. t509_wait_for_id_sequence();
  176. }
  177. DBG ( "T509 found %d cards using ID port %hx\n",
  178. t509_max_tag, t509_id_port );
  179. return;
  180. }
  181. /*
  182. * Increment a bus_loc structure to the next possible T509 location.
  183. * Leave the structure zeroed and return 0 if there are no more valid
  184. * locations.
  185. *
  186. */
  187. static int t509_next_location ( struct bus_loc *bus_loc ) {
  188. struct t509_loc *t509_loc = ( struct t509_loc * ) bus_loc;
  189. /*
  190. * Ensure that there is sufficient space in the shared bus
  191. * structures for a struct t509_loc and a struct t509_dev,
  192. * as mandated by bus.h.
  193. *
  194. */
  195. BUS_LOC_CHECK ( struct t509_loc );
  196. BUS_DEV_CHECK ( struct t509_device );
  197. return ( t509_loc->tag = ( ++t509_loc->tag & EP_TAG_MAX ) );
  198. }
  199. /*
  200. * Fill in parameters for a T509 device based on tag
  201. *
  202. * Return 1 if device present, 0 otherwise
  203. *
  204. */
  205. static int t509_fill_device ( struct bus_dev *bus_dev,
  206. struct bus_loc *bus_loc ) {
  207. struct t509_device *t509 = ( struct t509_device * ) bus_dev;
  208. struct t509_loc *t509_loc = ( struct t509_loc * ) bus_loc;
  209. uint16_t iobase;
  210. /* Copy tag to struct t509 */
  211. t509->tag = t509_loc->tag;
  212. /* Tag 0 is never valid, but may be passed in */
  213. if ( ! t509->tag )
  214. return 0;
  215. /* Perform isolation if it hasn't yet been done */
  216. if ( ! t509_id_port )
  217. t509_isolate();
  218. /* Check tag is in range */
  219. if ( t509->tag > t509_max_tag )
  220. return 0;
  221. /* Send the ID sequence */
  222. t509_send_id_sequence ();
  223. /* Select the specified tag */
  224. t509_select_tag ( t509->tag );
  225. /* Read the default I/O address */
  226. iobase = t509_id_read_eeprom ( EEPROM_ADDR_CFG );
  227. t509->ioaddr = 0x200 + ( ( iobase & 0x1f ) << 4 );
  228. /* Send card back to ID_WAIT */
  229. t509_wait_for_id_sequence();
  230. DBG ( "T509 found device %hhx, base %hx\n", t509->tag, t509->ioaddr );
  231. return 1;
  232. }
  233. /*
  234. * Test whether or not a driver is capable of driving the device.
  235. * This is a no-op for T509.
  236. *
  237. */
  238. static int t509_check_driver ( struct bus_dev *bus_dev __unused,
  239. struct device_driver *device_driver __unused ) {
  240. return 1;
  241. }
  242. /*
  243. * Describe a T509 device
  244. *
  245. */
  246. static char * t509_describe_device ( struct bus_dev *bus_dev ) {
  247. struct t509_device *t509 = ( struct t509_device * ) bus_dev;
  248. static char t509_description[] = "T509 00";
  249. sprintf ( t509_description + 4, "%hhx", t509->tag );
  250. return t509_description;
  251. }
  252. /*
  253. * Name a T509 device
  254. *
  255. */
  256. static const char * t509_name_device ( struct bus_dev *bus_dev __unused ) {
  257. return "T509";
  258. }
  259. /*
  260. * T509 bus operations table
  261. *
  262. */
  263. static struct bus_driver t509_driver __bus_driver = {
  264. .name = "T509",
  265. .next_location = t509_next_location,
  266. .fill_device = t509_fill_device,
  267. .check_driver = t509_check_driver,
  268. .describe_device = t509_describe_device,
  269. .name_device = t509_name_device,
  270. };
  271. /*
  272. * Activate a T509 device
  273. *
  274. * The device will be enabled at whatever ioaddr is specified in the
  275. * struct t509_device; there is no need to stick with the default
  276. * ioaddr read from the EEPROM.
  277. *
  278. */
  279. static inline void activate_t509_device ( struct t509_device *t509 ) {
  280. t509_send_id_sequence ();
  281. t509_select_tag ( t509->tag );
  282. t509_activate ( t509->ioaddr );
  283. DBG ( "T509 activated device %hhx at ioaddr %hx\n",
  284. t509->tag, t509->ioaddr );
  285. }
  286. /*
  287. * Deactivate a T509 device
  288. *
  289. * Disabling also clears the tag, so we immediately isolate and re-tag
  290. * this card.
  291. *
  292. */
  293. static inline void deactivate_t509_device ( struct t509_device *t509 ) {
  294. t509_deactivate_and_reset_tag ( t509->ioaddr );
  295. udelay ( 1000 );
  296. t509_send_id_sequence ();
  297. t509_select_tag ( 0 );
  298. t509_set_tag ( t509->tag );
  299. t509_wait_for_id_sequence ();
  300. DBG ( "T509 deactivated device at %hx and re-tagged as %hhx\n",
  301. t509->ioaddr, t509->tag );
  302. }
  303. /*
  304. * Fill in a nic structure
  305. *
  306. * Called only once, so inlined for efficiency
  307. *
  308. */
  309. static inline void t509_fill_nic ( struct nic *nic,
  310. struct t509_device *t509 ) {
  311. /* Fill in ioaddr and irqno */
  312. nic->ioaddr = t509->ioaddr;
  313. nic->irqno = 0;
  314. /* Fill in DHCP device ID structure */
  315. nic->dhcp_dev_id.bus_type = ISA_BUS_TYPE;
  316. nic->dhcp_dev_id.vendor_id = htons ( MFG_ID );
  317. nic->dhcp_dev_id.device_id = htons ( PROD_ID );
  318. }
  319. /*
  320. * The ISA probe function
  321. *
  322. */
  323. static int el3_t509_probe ( struct nic *nic, struct t509_device *t509 ) {
  324. /* We could change t509->ioaddr if we wanted to */
  325. activate_t509_device ( t509 );
  326. t509_fill_nic ( nic, t509 );
  327. /* Hand off to generic t5x9 probe routine */
  328. return t5x9_probe ( nic, ISA_PROD_ID ( PROD_ID ), ISA_PROD_ID_MASK );
  329. }
  330. static void el3_t509_disable ( struct nic *nic, struct t509_device *t509 ) {
  331. t5x9_disable ( nic );
  332. deactivate_t509_device ( t509 );
  333. }
  334. static struct {} el3_t509_driver;
  335. DRIVER ( "3c509", nic_driver, t509_driver, el3_t509_driver,
  336. el3_t509_probe, el3_t509_disable );
  337. ISA_ROM ( "3c509", "3c509" );