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.

cs89x0.c 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. #ifdef ALLMULTI
  2. #error multicast support is not yet implemented
  3. #endif
  4. /**
  5. Per an email message from Russ Nelson <nelson@crynwr.com> on
  6. 18 March 2008 this file is now licensed under GPL Version 2.
  7. From: Russ Nelson <nelson@crynwr.com>
  8. Date: Tue, 18 Mar 2008 12:42:00 -0400
  9. Subject: Re: [Etherboot-developers] cs89x0 driver in etherboot
  10. -- quote from email
  11. As copyright holder, if I say it doesn't conflict with the GPL,
  12. then it doesn't conflict with the GPL.
  13. However, there's no point in causing people's brains to overheat,
  14. so yes, I grant permission for the code to be relicensed under the
  15. GPLv2. Please make sure that this change in licensing makes its
  16. way upstream. -russ
  17. -- quote from email
  18. **/
  19. FILE_LICENCE ( GPL2_ONLY );
  20. /* cs89x0.c: A Crystal Semiconductor CS89[02]0 driver for etherboot. */
  21. /*
  22. Permission is granted to distribute the enclosed cs89x0.[ch] driver
  23. only in conjunction with the Etherboot package. The code is
  24. ordinarily distributed under the GPL.
  25. Russ Nelson, January 2000
  26. ChangeLog:
  27. Thu Dec 6 22:40:00 1996 Markus Gutschke <gutschk@math.uni-muenster.de>
  28. * disabled all "advanced" features; this should make the code more reliable
  29. * reorganized the reset function
  30. * always reset the address port, so that autoprobing will continue working
  31. * some cosmetic changes
  32. * 2.5
  33. Thu Dec 5 21:00:00 1996 Markus Gutschke <gutschk@math.uni-muenster.de>
  34. * tested the code against a CS8900 card
  35. * lots of minor bug fixes and adjustments
  36. * this is the first release, that actually works! it still requires some
  37. changes in order to be more tolerant to different environments
  38. * 4
  39. Fri Nov 22 23:00:00 1996 Markus Gutschke <gutschk@math.uni-muenster.de>
  40. * read the manuals for the CS89x0 chipsets and took note of all the
  41. changes that will be necessary in order to adapt Russel Nelson's code
  42. to the requirements of a BOOT-Prom
  43. * 6
  44. Thu Nov 19 22:00:00 1996 Markus Gutschke <gutschk@math.uni-muenster.de>
  45. * Synched with Russel Nelson's current code (v1.00)
  46. * 2
  47. Thu Nov 12 18:00:00 1996 Markus Gutschke <gutschk@math.uni-muenster.de>
  48. * Cleaned up some of the code and tried to optimize the code size.
  49. * 1.5
  50. Sun Nov 10 16:30:00 1996 Markus Gutschke <gutschk@math.uni-muenster.de>
  51. * First experimental release. This code compiles fine, but I
  52. have no way of testing whether it actually works.
  53. * I did not (yet) bother to make the code 16bit aware, so for
  54. the time being, it will only work for Etherboot/32.
  55. * 12
  56. */
  57. #include <errno.h>
  58. #include <ipxe/ethernet.h>
  59. #include "etherboot.h"
  60. #include "nic.h"
  61. #include <ipxe/isa.h>
  62. #include "cs89x0.h"
  63. static unsigned short eth_nic_base;
  64. static unsigned long eth_mem_start;
  65. static unsigned short eth_irqno;
  66. static unsigned short eth_cs_type; /* one of: CS8900, CS8920, CS8920M */
  67. static unsigned short eth_auto_neg_cnf;
  68. static unsigned short eth_adapter_cnf;
  69. static unsigned short eth_linectl;
  70. /*************************************************************************
  71. CS89x0 - specific routines
  72. **************************************************************************/
  73. static inline int readreg(int portno)
  74. {
  75. outw(portno, eth_nic_base + ADD_PORT);
  76. return inw(eth_nic_base + DATA_PORT);
  77. }
  78. static inline void writereg(int portno, int value)
  79. {
  80. outw(portno, eth_nic_base + ADD_PORT);
  81. outw(value, eth_nic_base + DATA_PORT);
  82. return;
  83. }
  84. /*************************************************************************
  85. EEPROM access
  86. **************************************************************************/
  87. static int wait_eeprom_ready(void)
  88. {
  89. unsigned long tmo = currticks() + 4*TICKS_PER_SEC;
  90. /* check to see if the EEPROM is ready, a timeout is used -
  91. just in case EEPROM is ready when SI_BUSY in the
  92. PP_SelfST is clear */
  93. while(readreg(PP_SelfST) & SI_BUSY) {
  94. if (currticks() >= tmo)
  95. return -1; }
  96. return 0;
  97. }
  98. static int get_eeprom_data(int off, int len, unsigned short *buffer)
  99. {
  100. int i;
  101. #ifdef EDEBUG
  102. printf("\ncs: EEPROM data from %hX for %hX:",off,len);
  103. #endif
  104. for (i = 0; i < len; i++) {
  105. if (wait_eeprom_ready() < 0)
  106. return -1;
  107. /* Now send the EEPROM read command and EEPROM location
  108. to read */
  109. writereg(PP_EECMD, (off + i) | EEPROM_READ_CMD);
  110. if (wait_eeprom_ready() < 0)
  111. return -1;
  112. buffer[i] = readreg(PP_EEData);
  113. #ifdef EDEBUG
  114. if (!(i%10))
  115. printf("\ncs: ");
  116. printf("%hX ", buffer[i]);
  117. #endif
  118. }
  119. #ifdef EDEBUG
  120. putchar('\n');
  121. #endif
  122. return(0);
  123. }
  124. static int get_eeprom_chksum(int off __unused, int len, unsigned short *buffer)
  125. {
  126. int i, cksum;
  127. cksum = 0;
  128. for (i = 0; i < len; i++)
  129. cksum += buffer[i];
  130. cksum &= 0xffff;
  131. if (cksum == 0)
  132. return 0;
  133. return -1;
  134. }
  135. /*************************************************************************
  136. Activate all of the available media and probe for network
  137. **************************************************************************/
  138. static void clrline(void)
  139. {
  140. int i;
  141. putchar('\r');
  142. for (i = 79; i--; ) putchar(' ');
  143. printf("\rcs: ");
  144. return;
  145. }
  146. static void control_dc_dc(int on_not_off)
  147. {
  148. unsigned int selfcontrol;
  149. unsigned long tmo = currticks() + TICKS_PER_SEC;
  150. /* control the DC to DC convertor in the SelfControl register. */
  151. selfcontrol = HCB1_ENBL; /* Enable the HCB1 bit as an output */
  152. if (((eth_adapter_cnf & A_CNF_DC_DC_POLARITY) != 0) ^ on_not_off)
  153. selfcontrol |= HCB1;
  154. else
  155. selfcontrol &= ~HCB1;
  156. writereg(PP_SelfCTL, selfcontrol);
  157. /* Wait for the DC/DC converter to power up - 1000ms */
  158. while (currticks() < tmo);
  159. return;
  160. }
  161. static int detect_tp(void)
  162. {
  163. unsigned long tmo;
  164. /* Turn on the chip auto detection of 10BT/ AUI */
  165. clrline(); printf("attempting %s:","TP");
  166. /* If connected to another full duplex capable 10-Base-T card
  167. the link pulses seem to be lost when the auto detect bit in
  168. the LineCTL is set. To overcome this the auto detect bit
  169. will be cleared whilst testing the 10-Base-T interface.
  170. This would not be necessary for the sparrow chip but is
  171. simpler to do it anyway. */
  172. writereg(PP_LineCTL, eth_linectl &~ AUI_ONLY);
  173. control_dc_dc(0);
  174. /* Delay for the hardware to work out if the TP cable is
  175. present - 150ms */
  176. for (tmo = currticks() + 4; currticks() < tmo; );
  177. if ((readreg(PP_LineST) & LINK_OK) == 0)
  178. return 0;
  179. if (eth_cs_type != CS8900) {
  180. writereg(PP_AutoNegCTL, eth_auto_neg_cnf & AUTO_NEG_MASK);
  181. if ((eth_auto_neg_cnf & AUTO_NEG_BITS) == AUTO_NEG_ENABLE) {
  182. printf(" negotiating duplex... ");
  183. while (readreg(PP_AutoNegST) & AUTO_NEG_BUSY) {
  184. if (currticks() - tmo > 40*TICKS_PER_SEC) {
  185. printf("time out ");
  186. break;
  187. }
  188. }
  189. }
  190. if (readreg(PP_AutoNegST) & FDX_ACTIVE)
  191. printf("using full duplex");
  192. else
  193. printf("using half duplex");
  194. }
  195. return A_CNF_MEDIA_10B_T;
  196. }
  197. /* send a test packet - return true if carrier bits are ok */
  198. static int send_test_pkt(struct nic *nic)
  199. {
  200. static unsigned char testpacket[] = { 0,0,0,0,0,0, 0,0,0,0,0,0,
  201. 0, 46, /*A 46 in network order */
  202. 0, 0, /*DSAP=0 & SSAP=0 fields */
  203. 0xf3,0 /*Control (Test Req+P bit set)*/ };
  204. unsigned long tmo;
  205. writereg(PP_LineCTL, readreg(PP_LineCTL) | SERIAL_TX_ON);
  206. memcpy(testpacket, nic->node_addr, ETH_ALEN);
  207. memcpy(testpacket+ETH_ALEN, nic->node_addr, ETH_ALEN);
  208. outw(TX_AFTER_ALL, eth_nic_base + TX_CMD_PORT);
  209. outw(ETH_ZLEN, eth_nic_base + TX_LEN_PORT);
  210. /* Test to see if the chip has allocated memory for the packet */
  211. for (tmo = currticks() + 2;
  212. (readreg(PP_BusST) & READY_FOR_TX_NOW) == 0; )
  213. if (currticks() >= tmo)
  214. return(0);
  215. /* Write the contents of the packet */
  216. outsw(eth_nic_base + TX_FRAME_PORT, testpacket,
  217. (ETH_ZLEN+1)>>1);
  218. printf(" sending test packet ");
  219. /* wait a couple of timer ticks for packet to be received */
  220. for (tmo = currticks() + 2; currticks() < tmo; );
  221. if ((readreg(PP_TxEvent) & TX_SEND_OK_BITS) == TX_OK) {
  222. printf("succeeded");
  223. return 1;
  224. }
  225. printf("failed");
  226. return 0;
  227. }
  228. static int detect_aui(struct nic *nic)
  229. {
  230. clrline(); printf("attempting %s:","AUI");
  231. control_dc_dc(0);
  232. writereg(PP_LineCTL, (eth_linectl & ~AUTO_AUI_10BASET) | AUI_ONLY);
  233. if (send_test_pkt(nic)) {
  234. return A_CNF_MEDIA_AUI; }
  235. else
  236. return 0;
  237. }
  238. static int detect_bnc(struct nic *nic)
  239. {
  240. clrline(); printf("attempting %s:","BNC");
  241. control_dc_dc(1);
  242. writereg(PP_LineCTL, (eth_linectl & ~AUTO_AUI_10BASET) | AUI_ONLY);
  243. if (send_test_pkt(nic)) {
  244. return A_CNF_MEDIA_10B_2; }
  245. else
  246. return 0;
  247. }
  248. /**************************************************************************
  249. ETH_RESET - Reset adapter
  250. ***************************************************************************/
  251. static void cs89x0_reset(struct nic *nic)
  252. {
  253. int i;
  254. unsigned long reset_tmo;
  255. writereg(PP_SelfCTL, readreg(PP_SelfCTL) | POWER_ON_RESET);
  256. /* wait for two ticks; that is 2*55ms */
  257. for (reset_tmo = currticks() + 2; currticks() < reset_tmo; );
  258. if (eth_cs_type != CS8900) {
  259. /* Hardware problem requires PNP registers to be reconfigured
  260. after a reset */
  261. if (eth_irqno != 0xFFFF) {
  262. outw(PP_CS8920_ISAINT, eth_nic_base + ADD_PORT);
  263. outb(eth_irqno, eth_nic_base + DATA_PORT);
  264. outb(0, eth_nic_base + DATA_PORT + 1); }
  265. if (eth_mem_start) {
  266. outw(PP_CS8920_ISAMemB, eth_nic_base + ADD_PORT);
  267. outb((eth_mem_start >> 8) & 0xff, eth_nic_base + DATA_PORT);
  268. outb((eth_mem_start >> 24) & 0xff, eth_nic_base + DATA_PORT + 1); } }
  269. /* Wait until the chip is reset */
  270. for (reset_tmo = currticks() + 2;
  271. (readreg(PP_SelfST) & INIT_DONE) == 0 &&
  272. currticks() < reset_tmo; );
  273. /* disable interrupts and memory accesses */
  274. writereg(PP_BusCTL, 0);
  275. /* set the ethernet address */
  276. for (i=0; i < ETH_ALEN/2; i++)
  277. writereg(PP_IA+i*2,
  278. nic->node_addr[i*2] |
  279. (nic->node_addr[i*2+1] << 8));
  280. /* receive only error free packets addressed to this card */
  281. writereg(PP_RxCTL, DEF_RX_ACCEPT);
  282. /* do not generate any interrupts on receive operations */
  283. writereg(PP_RxCFG, 0);
  284. /* do not generate any interrupts on transmit operations */
  285. writereg(PP_TxCFG, 0);
  286. /* do not generate any interrupts on buffer operations */
  287. writereg(PP_BufCFG, 0);
  288. /* reset address port, so that autoprobing will keep working */
  289. outw(PP_ChipID, eth_nic_base + ADD_PORT);
  290. return;
  291. }
  292. /**************************************************************************
  293. ETH_TRANSMIT - Transmit a frame
  294. ***************************************************************************/
  295. static void cs89x0_transmit(
  296. struct nic *nic,
  297. const char *d, /* Destination */
  298. unsigned int t, /* Type */
  299. unsigned int s, /* size */
  300. const char *p) /* Packet */
  301. {
  302. unsigned long tmo;
  303. int sr;
  304. /* does this size have to be rounded??? please,
  305. somebody have a look in the specs */
  306. if ((sr = ((s + ETH_HLEN + 1)&~1)) < ETH_ZLEN)
  307. sr = ETH_ZLEN;
  308. retry:
  309. /* initiate a transmit sequence */
  310. outw(TX_AFTER_ALL, eth_nic_base + TX_CMD_PORT);
  311. outw(sr, eth_nic_base + TX_LEN_PORT);
  312. /* Test to see if the chip has allocated memory for the packet */
  313. if ((readreg(PP_BusST) & READY_FOR_TX_NOW) == 0) {
  314. /* Oops... this should not happen! */
  315. printf("cs: unable to send packet; retrying...\n");
  316. for (tmo = currticks() + 5*TICKS_PER_SEC; currticks() < tmo; );
  317. cs89x0_reset(nic);
  318. goto retry; }
  319. /* Write the contents of the packet */
  320. outsw(eth_nic_base + TX_FRAME_PORT, d, ETH_ALEN/2);
  321. outsw(eth_nic_base + TX_FRAME_PORT, nic->node_addr,
  322. ETH_ALEN/2);
  323. outw(((t >> 8)&0xFF)|(t << 8), eth_nic_base + TX_FRAME_PORT);
  324. outsw(eth_nic_base + TX_FRAME_PORT, p, (s+1)/2);
  325. for (sr = sr/2 - (s+1)/2 - ETH_ALEN - 1; sr > 0; sr--)
  326. outw(0, eth_nic_base + TX_FRAME_PORT);
  327. /* wait for transfer to succeed */
  328. for (tmo = currticks()+5*TICKS_PER_SEC;
  329. (s = readreg(PP_TxEvent)&~0x1F) == 0 && currticks() < tmo;)
  330. /* nothing */ ;
  331. if ((s & TX_SEND_OK_BITS) != TX_OK) {
  332. printf("\ntransmission error %#hX\n", s);
  333. }
  334. return;
  335. }
  336. /**************************************************************************
  337. ETH_POLL - Wait for a frame
  338. ***************************************************************************/
  339. static int cs89x0_poll(struct nic *nic, int retrieve)
  340. {
  341. int status;
  342. status = readreg(PP_RxEvent);
  343. if ((status & RX_OK) == 0)
  344. return(0);
  345. if ( ! retrieve ) return 1;
  346. status = inw(eth_nic_base + RX_FRAME_PORT);
  347. nic->packetlen = inw(eth_nic_base + RX_FRAME_PORT);
  348. insw(eth_nic_base + RX_FRAME_PORT, nic->packet, nic->packetlen >> 1);
  349. if (nic->packetlen & 1)
  350. nic->packet[nic->packetlen-1] = inw(eth_nic_base + RX_FRAME_PORT);
  351. return 1;
  352. }
  353. static void cs89x0_irq(struct nic *nic __unused, irq_action_t action __unused)
  354. {
  355. switch ( action ) {
  356. case DISABLE :
  357. break;
  358. case ENABLE :
  359. break;
  360. case FORCE :
  361. break;
  362. }
  363. }
  364. static struct nic_operations cs89x0_operations = {
  365. .connect = dummy_connect,
  366. .poll = cs89x0_poll,
  367. .transmit = cs89x0_transmit,
  368. .irq = cs89x0_irq,
  369. };
  370. /**************************************************************************
  371. ETH_PROBE - Look for an adapter
  372. ***************************************************************************/
  373. static int cs89x0_probe_addr ( isa_probe_addr_t ioaddr ) {
  374. /* if they give us an odd I/O address, then do ONE write to
  375. the address port, to get it back to address zero, where we
  376. expect to find the EISA signature word. */
  377. if (ioaddr & 1) {
  378. ioaddr &= ~1;
  379. if ((inw(ioaddr + ADD_PORT) & ADD_MASK) != ADD_SIG)
  380. return 0;
  381. outw(PP_ChipID, ioaddr + ADD_PORT);
  382. }
  383. if (inw(ioaddr + DATA_PORT) != CHIP_EISA_ID_SIG)
  384. return 0;
  385. return 1;
  386. }
  387. static int cs89x0_probe ( struct nic *nic, struct isa_device *isa __unused ) {
  388. int i, result = -1;
  389. unsigned rev_type = 0, isa_cnf, cs_revision;
  390. unsigned short eeprom_buff[CHKSUM_LEN];
  391. nic->ioaddr &= ~1; /* LSB = 1 indicates a more aggressive probe */
  392. eth_nic_base = nic->ioaddr;
  393. /* get the chip type */
  394. rev_type = readreg(PRODUCT_ID_ADD);
  395. eth_cs_type = rev_type &~ REVISON_BITS;
  396. cs_revision = ((rev_type & REVISON_BITS) >> 8) + 'A';
  397. printf("\ncs: cs89%c0%s rev %c, base %#hX",
  398. eth_cs_type==CS8900?'0':'2',
  399. eth_cs_type==CS8920M?"M":"",
  400. cs_revision,
  401. eth_nic_base);
  402. #ifndef EMBEDDED
  403. /* First check to see if an EEPROM is attached*/
  404. if ((readreg(PP_SelfST) & EEPROM_PRESENT) == 0) {
  405. printf("\ncs: no EEPROM...\n");
  406. outw(PP_ChipID, eth_nic_base + ADD_PORT);
  407. return 0;
  408. } else if (get_eeprom_data(START_EEPROM_DATA,CHKSUM_LEN,
  409. eeprom_buff) < 0) {
  410. printf("\ncs: EEPROM read failed...\n");
  411. outw(PP_ChipID, eth_nic_base + ADD_PORT);
  412. return 0;
  413. } else if (get_eeprom_chksum(START_EEPROM_DATA,CHKSUM_LEN,
  414. eeprom_buff) < 0) {
  415. printf("\ncs: EEPROM checksum bad...\n");
  416. outw(PP_ChipID, eth_nic_base + ADD_PORT);
  417. return 0;
  418. }
  419. /* get transmission control word but keep the
  420. autonegotiation bits */
  421. eth_auto_neg_cnf = eeprom_buff[AUTO_NEG_CNF_OFFSET/2];
  422. /* Store adapter configuration */
  423. eth_adapter_cnf = eeprom_buff[ADAPTER_CNF_OFFSET/2];
  424. /* Store ISA configuration */
  425. isa_cnf = eeprom_buff[ISA_CNF_OFFSET/2];
  426. /* store the initial memory base address */
  427. eth_mem_start = eeprom_buff[PACKET_PAGE_OFFSET/2] << 8;
  428. printf("%s%s%s, addr ",
  429. (eth_adapter_cnf & A_CNF_10B_T)?", RJ-45":"",
  430. (eth_adapter_cnf & A_CNF_AUI)?", AUI":"",
  431. (eth_adapter_cnf & A_CNF_10B_2)?", BNC":"");
  432. /* If this is a CS8900 then no pnp soft */
  433. if (eth_cs_type != CS8900 &&
  434. /* Check if the ISA IRQ has been set */
  435. (i = readreg(PP_CS8920_ISAINT) & 0xff,
  436. (i != 0 && i < CS8920_NO_INTS)))
  437. eth_irqno = i;
  438. else {
  439. i = isa_cnf & INT_NO_MASK;
  440. if (eth_cs_type == CS8900) {
  441. /* the table that follows is dependent
  442. upon how you wired up your cs8900
  443. in your system. The table is the
  444. same as the cs8900 engineering demo
  445. board. irq_map also depends on the
  446. contents of the table. Also see
  447. write_irq, which is the reverse
  448. mapping of the table below. */
  449. if (i < 4) i = "\012\013\014\005"[i];
  450. else printf("\ncs: BUG: isa_config is %d\n", i); }
  451. eth_irqno = i; }
  452. nic->irqno = eth_irqno;
  453. /* Retrieve and print the ethernet address. */
  454. for (i=0; i<ETH_ALEN; i++) {
  455. nic->node_addr[i] = ((unsigned char *)eeprom_buff)[i];
  456. }
  457. DBG ( "%s\n", eth_ntoa ( nic->node_addr ) );
  458. #endif
  459. #ifdef EMBEDDED
  460. /* Retrieve and print the ethernet address. */
  461. {
  462. unsigned char MAC_HW_ADDR[6]={MAC_HW_ADDR_DRV};
  463. memcpy(nic->node_addr, MAC_HW_ADDR, 6);
  464. }
  465. DBG ( "%s\n", eth_ntoa ( nic->node_addr ) );
  466. eth_adapter_cnf = A_CNF_10B_T | A_CNF_MEDIA_10B_T;
  467. eth_auto_neg_cnf = EE_AUTO_NEG_ENABLE | IMM_BIT;
  468. #endif
  469. #ifndef EMBEDDED
  470. /* Set the LineCTL quintuplet based on adapter
  471. configuration read from EEPROM */
  472. if ((eth_adapter_cnf & A_CNF_EXTND_10B_2) &&
  473. (eth_adapter_cnf & A_CNF_LOW_RX_SQUELCH))
  474. eth_linectl = LOW_RX_SQUELCH;
  475. else
  476. eth_linectl = 0;
  477. /* check to make sure that they have the "right"
  478. hardware available */
  479. switch(eth_adapter_cnf & A_CNF_MEDIA_TYPE) {
  480. case A_CNF_MEDIA_10B_T: result = eth_adapter_cnf & A_CNF_10B_T;
  481. break;
  482. case A_CNF_MEDIA_AUI: result = eth_adapter_cnf & A_CNF_AUI;
  483. break;
  484. case A_CNF_MEDIA_10B_2: result = eth_adapter_cnf & A_CNF_10B_2;
  485. break;
  486. default: result = eth_adapter_cnf & (A_CNF_10B_T | A_CNF_AUI |
  487. A_CNF_10B_2);
  488. }
  489. if (!result) {
  490. printf("cs: EEPROM is configured for unavailable media\n");
  491. error:
  492. writereg(PP_LineCTL, readreg(PP_LineCTL) &
  493. ~(SERIAL_TX_ON | SERIAL_RX_ON));
  494. outw(PP_ChipID, eth_nic_base + ADD_PORT);
  495. return 0;
  496. }
  497. #endif
  498. /* Initialize the card for probing of the attached media */
  499. cs89x0_reset(nic);
  500. /* set the hardware to the configured choice */
  501. switch(eth_adapter_cnf & A_CNF_MEDIA_TYPE) {
  502. case A_CNF_MEDIA_10B_T:
  503. result = detect_tp();
  504. if (!result) {
  505. clrline();
  506. printf("10Base-T (RJ-45%s",
  507. ") has no cable\n"); }
  508. /* check "ignore missing media" bit */
  509. if (eth_auto_neg_cnf & IMM_BIT)
  510. /* Yes! I don't care if I see a link pulse */
  511. result = A_CNF_MEDIA_10B_T;
  512. break;
  513. case A_CNF_MEDIA_AUI:
  514. result = detect_aui(nic);
  515. if (!result) {
  516. clrline();
  517. printf("10Base-5 (AUI%s",
  518. ") has no cable\n"); }
  519. /* check "ignore missing media" bit */
  520. if (eth_auto_neg_cnf & IMM_BIT)
  521. /* Yes! I don't care if I see a carrrier */
  522. result = A_CNF_MEDIA_AUI;
  523. break;
  524. case A_CNF_MEDIA_10B_2:
  525. result = detect_bnc(nic);
  526. if (!result) {
  527. clrline();
  528. printf("10Base-2 (BNC%s",
  529. ") has no cable\n"); }
  530. /* check "ignore missing media" bit */
  531. if (eth_auto_neg_cnf & IMM_BIT)
  532. /* Yes! I don't care if I can xmit a packet */
  533. result = A_CNF_MEDIA_10B_2;
  534. break;
  535. case A_CNF_MEDIA_AUTO:
  536. writereg(PP_LineCTL, eth_linectl | AUTO_AUI_10BASET);
  537. if (eth_adapter_cnf & A_CNF_10B_T)
  538. if ((result = detect_tp()) != 0)
  539. break;
  540. if (eth_adapter_cnf & A_CNF_AUI)
  541. if ((result = detect_aui(nic)) != 0)
  542. break;
  543. if (eth_adapter_cnf & A_CNF_10B_2)
  544. if ((result = detect_bnc(nic)) != 0)
  545. break;
  546. clrline(); printf("no media detected\n");
  547. goto error;
  548. }
  549. clrline();
  550. switch(result) {
  551. case 0: printf("no network cable attached to configured media\n");
  552. goto error;
  553. case A_CNF_MEDIA_10B_T: printf("using 10Base-T (RJ-45)\n");
  554. break;
  555. case A_CNF_MEDIA_AUI: printf("using 10Base-5 (AUI)\n");
  556. break;
  557. case A_CNF_MEDIA_10B_2: printf("using 10Base-2 (BNC)\n");
  558. break;
  559. }
  560. /* Turn on both receive and transmit operations */
  561. writereg(PP_LineCTL, readreg(PP_LineCTL) | SERIAL_RX_ON |
  562. SERIAL_TX_ON);
  563. return 0;
  564. #ifdef EMBEDDED
  565. error:
  566. writereg(PP_LineCTL, readreg(PP_LineCTL) &
  567. ~(SERIAL_TX_ON | SERIAL_RX_ON));
  568. outw(PP_ChipID, eth_nic_base + ADD_PORT);
  569. return 0;
  570. #endif
  571. nic->nic_op = &cs89x0_operations;
  572. return 1;
  573. }
  574. static void cs89x0_disable ( struct nic *nic,
  575. struct isa_device *isa __unused ) {
  576. cs89x0_reset(nic);
  577. }
  578. static isa_probe_addr_t cs89x0_probe_addrs[] = {
  579. #ifndef EMBEDDED
  580. /* use "conservative" default values for autoprobing */
  581. 0x300, 0x320, 0x340, 0x200, 0x220, 0x240,
  582. 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0,
  583. /* if that did not work, then be more aggressive */
  584. 0x301, 0x321, 0x341, 0x201, 0x221, 0x241,
  585. 0x261, 0x281, 0x2a1, 0x2c1, 0x2e1,
  586. #else
  587. 0x01000300,
  588. #endif
  589. };
  590. ISA_DRIVER ( cs89x0_driver, cs89x0_probe_addrs, cs89x0_probe_addr,
  591. ISAPNP_VENDOR('C','S','C'), 0x0007 );
  592. DRIVER ( "cs89x0", nic_driver, isa_driver, cs89x0_driver,
  593. cs89x0_probe, cs89x0_disable );
  594. ISA_ROM ( "cs89x0", "Crystal Semiconductor CS89x0" );
  595. /*
  596. * Local variables:
  597. * c-basic-offset: 8
  598. * c-indent-level: 8
  599. * tab-width: 8
  600. * End:
  601. */