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.

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