Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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