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.

3c595.c 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /*
  2. * 3c595.c -- 3COM 3C595 Fast Etherlink III PCI driver for etherboot
  3. *
  4. * Copyright (C) 2000 Shusuke Nisiyama <shu@athena.qe.eng.hokudai.ac.jp>
  5. * All rights reserved.
  6. * Mar. 14, 2000
  7. *
  8. * This software may be used, modified, copied, distributed, and sold, in
  9. * both source and binary form provided that the above copyright and these
  10. * terms are retained. Under no circumstances are the authors responsible for
  11. * the proper functioning of this software, nor do the authors assume any
  12. * responsibility for damages incurred with its use.
  13. *
  14. * This code is based on Martin Renters' etherboot-4.4.3 3c509.c and
  15. * Herb Peyerl's FreeBSD 3.4-RELEASE if_vx.c driver.
  16. *
  17. * Copyright (C) 1993-1994, David Greenman, Martin Renters.
  18. * Copyright (C) 1993-1995, Andres Vega Garcia.
  19. * Copyright (C) 1995, Serge Babkin.
  20. *
  21. * Copyright (c) 1994 Herb Peyerl <hpeyerl@novatel.ca>
  22. *
  23. * timlegge 08-24-2003 Add Multicast Support
  24. */
  25. /* #define EDEBUG */
  26. #include "etherboot.h"
  27. #include "nic.h"
  28. #include "pci.h"
  29. #include "3c595.h"
  30. #include "timer.h"
  31. static unsigned short eth_nic_base;
  32. static unsigned short vx_connector, vx_connectors;
  33. static struct connector_entry {
  34. int bit;
  35. char *name;
  36. } conn_tab[VX_CONNECTORS] = {
  37. #define CONNECTOR_UTP 0
  38. { 0x08, "utp"},
  39. #define CONNECTOR_AUI 1
  40. { 0x20, "aui"},
  41. /* dummy */
  42. { 0, "???"},
  43. #define CONNECTOR_BNC 3
  44. { 0x10, "bnc"},
  45. #define CONNECTOR_TX 4
  46. { 0x02, "tx"},
  47. #define CONNECTOR_FX 5
  48. { 0x04, "fx"},
  49. #define CONNECTOR_MII 6
  50. { 0x40, "mii"},
  51. { 0, "???"}
  52. };
  53. static void vxgetlink(void);
  54. static void vxsetlink(void);
  55. /**************************************************************************
  56. ETH_RESET - Reset adapter
  57. ***************************************************************************/
  58. static void t595_reset(struct nic *nic)
  59. {
  60. int i;
  61. /***********************************************************
  62. Reset 3Com 595 card
  63. *************************************************************/
  64. /* stop card */
  65. outw(RX_DISABLE, BASE + VX_COMMAND);
  66. outw(RX_DISCARD_TOP_PACK, BASE + VX_COMMAND);
  67. VX_BUSY_WAIT;
  68. outw(TX_DISABLE, BASE + VX_COMMAND);
  69. outw(STOP_TRANSCEIVER, BASE + VX_COMMAND);
  70. udelay(8000);
  71. outw(RX_RESET, BASE + VX_COMMAND);
  72. VX_BUSY_WAIT;
  73. outw(TX_RESET, BASE + VX_COMMAND);
  74. VX_BUSY_WAIT;
  75. outw(C_INTR_LATCH, BASE + VX_COMMAND);
  76. outw(SET_RD_0_MASK, BASE + VX_COMMAND);
  77. outw(SET_INTR_MASK, BASE + VX_COMMAND);
  78. outw(SET_RX_FILTER, BASE + VX_COMMAND);
  79. /*
  80. * initialize card
  81. */
  82. VX_BUSY_WAIT;
  83. GO_WINDOW(0);
  84. /* Disable the card */
  85. /* outw(0, BASE + VX_W0_CONFIG_CTRL); */
  86. /* Configure IRQ to none */
  87. /* outw(SET_IRQ(0), BASE + VX_W0_RESOURCE_CFG); */
  88. /* Enable the card */
  89. /* outw(ENABLE_DRQ_IRQ, BASE + VX_W0_CONFIG_CTRL); */
  90. GO_WINDOW(2);
  91. /* Reload the ether_addr. */
  92. for (i = 0; i < ETH_ALEN; i++)
  93. outb(nic->node_addr[i], BASE + VX_W2_ADDR_0 + i);
  94. outw(RX_RESET, BASE + VX_COMMAND);
  95. VX_BUSY_WAIT;
  96. outw(TX_RESET, BASE + VX_COMMAND);
  97. VX_BUSY_WAIT;
  98. /* Window 1 is operating window */
  99. GO_WINDOW(1);
  100. for (i = 0; i < 31; i++)
  101. inb(BASE + VX_W1_TX_STATUS);
  102. outw(SET_RD_0_MASK | S_CARD_FAILURE | S_RX_COMPLETE |
  103. S_TX_COMPLETE | S_TX_AVAIL, BASE + VX_COMMAND);
  104. outw(SET_INTR_MASK | S_CARD_FAILURE | S_RX_COMPLETE |
  105. S_TX_COMPLETE | S_TX_AVAIL, BASE + VX_COMMAND);
  106. /*
  107. * Attempt to get rid of any stray interrupts that occured during
  108. * configuration. On the i386 this isn't possible because one may
  109. * already be queued. However, a single stray interrupt is
  110. * unimportant.
  111. */
  112. outw(ACK_INTR | 0xff, BASE + VX_COMMAND);
  113. outw(SET_RX_FILTER | FIL_INDIVIDUAL |
  114. FIL_BRDCST|FIL_MULTICAST, BASE + VX_COMMAND);
  115. vxsetlink();
  116. /*{
  117. int i,j;
  118. i = CONNECTOR_TX;
  119. GO_WINDOW(3);
  120. j = inl(BASE + VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
  121. outl(BASE + VX_W3_INTERNAL_CFG, j | (i <<INTERNAL_CONNECTOR_BITS));
  122. GO_WINDOW(4);
  123. outw(LINKBEAT_ENABLE, BASE + VX_W4_MEDIA_TYPE);
  124. GO_WINDOW(1);
  125. }*/
  126. /* start tranciever and receiver */
  127. outw(RX_ENABLE, BASE + VX_COMMAND);
  128. outw(TX_ENABLE, BASE + VX_COMMAND);
  129. }
  130. /**************************************************************************
  131. ETH_TRANSMIT - Transmit a frame
  132. ***************************************************************************/
  133. static char padmap[] = {
  134. 0, 3, 2, 1};
  135. static void t595_transmit(
  136. struct nic *nic,
  137. const char *d, /* Destination */
  138. unsigned int t, /* Type */
  139. unsigned int s, /* size */
  140. const char *p) /* Packet */
  141. {
  142. register int len;
  143. int pad;
  144. int status;
  145. #ifdef EDEBUG
  146. printf("{l=%d,t=%hX}",s+ETH_HLEN,t);
  147. #endif
  148. /* swap bytes of type */
  149. t= htons(t);
  150. len=s+ETH_HLEN; /* actual length of packet */
  151. pad = padmap[len & 3];
  152. /*
  153. * The 3c595 automatically pads short packets to minimum ethernet length,
  154. * but we drop packets that are too large. Perhaps we should truncate
  155. * them instead?
  156. */
  157. if (len + pad > ETH_FRAME_LEN) {
  158. return;
  159. }
  160. /* drop acknowledgements */
  161. while(( status=inb(BASE + VX_W1_TX_STATUS) )& TXS_COMPLETE ) {
  162. if(status & (TXS_UNDERRUN|TXS_MAX_COLLISION|TXS_STATUS_OVERFLOW)) {
  163. outw(TX_RESET, BASE + VX_COMMAND);
  164. outw(TX_ENABLE, BASE + VX_COMMAND);
  165. }
  166. outb(0x0, BASE + VX_W1_TX_STATUS);
  167. }
  168. while (inw(BASE + VX_W1_FREE_TX) < len + pad + 4) {
  169. /* no room in FIFO */
  170. }
  171. outw(len, BASE + VX_W1_TX_PIO_WR_1);
  172. outw(0x0, BASE + VX_W1_TX_PIO_WR_1); /* Second dword meaningless */
  173. /* write packet */
  174. outsw(BASE + VX_W1_TX_PIO_WR_1, d, ETH_ALEN/2);
  175. outsw(BASE + VX_W1_TX_PIO_WR_1, nic->node_addr, ETH_ALEN/2);
  176. outw(t, BASE + VX_W1_TX_PIO_WR_1);
  177. outsw(BASE + VX_W1_TX_PIO_WR_1, p, s / 2);
  178. if (s & 1)
  179. outb(*(p+s - 1), BASE + VX_W1_TX_PIO_WR_1);
  180. while (pad--)
  181. outb(0, BASE + VX_W1_TX_PIO_WR_1); /* Padding */
  182. /* wait for Tx complete */
  183. while((inw(BASE + VX_STATUS) & S_COMMAND_IN_PROGRESS) != 0)
  184. ;
  185. }
  186. /**************************************************************************
  187. ETH_POLL - Wait for a frame
  188. ***************************************************************************/
  189. static int t595_poll(struct nic *nic, int retrieve)
  190. {
  191. /* common variables */
  192. /* variables for 3C595 */
  193. short status, cst;
  194. register short rx_fifo;
  195. cst=inw(BASE + VX_STATUS);
  196. #ifdef EDEBUG
  197. if(cst & 0x1FFF)
  198. printf("-%hX-",cst);
  199. #endif
  200. if( (cst & S_RX_COMPLETE)==0 ) {
  201. /* acknowledge everything */
  202. outw(ACK_INTR | cst, BASE + VX_COMMAND);
  203. outw(C_INTR_LATCH, BASE + VX_COMMAND);
  204. return 0;
  205. }
  206. status = inw(BASE + VX_W1_RX_STATUS);
  207. #ifdef EDEBUG
  208. printf("*%hX*",status);
  209. #endif
  210. if (status & ERR_RX) {
  211. outw(RX_DISCARD_TOP_PACK, BASE + VX_COMMAND);
  212. return 0;
  213. }
  214. rx_fifo = status & RX_BYTES_MASK;
  215. if (rx_fifo==0)
  216. return 0;
  217. if ( ! retrieve ) return 1;
  218. /* read packet */
  219. #ifdef EDEBUG
  220. printf("[l=%d",rx_fifo);
  221. #endif
  222. insw(BASE + VX_W1_RX_PIO_RD_1, nic->packet, rx_fifo / 2);
  223. if(rx_fifo & 1)
  224. nic->packet[rx_fifo-1]=inb(BASE + VX_W1_RX_PIO_RD_1);
  225. nic->packetlen=rx_fifo;
  226. while(1) {
  227. status = inw(BASE + VX_W1_RX_STATUS);
  228. #ifdef EDEBUG
  229. printf("*%hX*",status);
  230. #endif
  231. rx_fifo = status & RX_BYTES_MASK;
  232. if(rx_fifo>0) {
  233. insw(BASE + VX_W1_RX_PIO_RD_1, nic->packet+nic->packetlen, rx_fifo / 2);
  234. if(rx_fifo & 1)
  235. nic->packet[nic->packetlen+rx_fifo-1]=inb(BASE + VX_W1_RX_PIO_RD_1);
  236. nic->packetlen+=rx_fifo;
  237. #ifdef EDEBUG
  238. printf("+%d",rx_fifo);
  239. #endif
  240. }
  241. if(( status & RX_INCOMPLETE )==0) {
  242. #ifdef EDEBUG
  243. printf("=%d",nic->packetlen);
  244. #endif
  245. break;
  246. }
  247. udelay(1000);
  248. }
  249. /* acknowledge reception of packet */
  250. outw(RX_DISCARD_TOP_PACK, BASE + VX_COMMAND);
  251. while (inw(BASE + VX_STATUS) & S_COMMAND_IN_PROGRESS);
  252. #ifdef EDEBUG
  253. {
  254. unsigned short type = 0; /* used by EDEBUG */
  255. type = (nic->packet[12]<<8) | nic->packet[13];
  256. if(nic->packet[0]+nic->packet[1]+nic->packet[2]+nic->packet[3]+nic->packet[4]+
  257. nic->packet[5] == 0xFF*ETH_ALEN)
  258. printf(",t=%hX,b]",type);
  259. else
  260. printf(",t=%hX]",type);
  261. }
  262. #endif
  263. return 1;
  264. }
  265. /*************************************************************************
  266. 3Com 595 - specific routines
  267. **************************************************************************/
  268. static int
  269. eeprom_rdy()
  270. {
  271. int i;
  272. for (i = 0; is_eeprom_busy(BASE) && i < MAX_EEPROMBUSY; i++)
  273. udelay(1000);
  274. if (i >= MAX_EEPROMBUSY) {
  275. /* printf("3c595: eeprom failed to come ready.\n"); */
  276. printf("3c595: eeprom is busy.\n"); /* memory in EPROM is tight */
  277. return (0);
  278. }
  279. return (1);
  280. }
  281. /*
  282. * get_e: gets a 16 bits word from the EEPROM. we must have set the window
  283. * before
  284. */
  285. static int
  286. get_e(offset)
  287. int offset;
  288. {
  289. if (!eeprom_rdy())
  290. return (0xffff);
  291. outw(EEPROM_CMD_RD | offset, BASE + VX_W0_EEPROM_COMMAND);
  292. if (!eeprom_rdy())
  293. return (0xffff);
  294. return (inw(BASE + VX_W0_EEPROM_DATA));
  295. }
  296. static void
  297. vxgetlink(void)
  298. {
  299. int n, k;
  300. GO_WINDOW(3);
  301. vx_connectors = inw(BASE + VX_W3_RESET_OPT) & 0x7f;
  302. for (n = 0, k = 0; k < VX_CONNECTORS; k++) {
  303. if (vx_connectors & conn_tab[k].bit) {
  304. if (n > 0) {
  305. printf("/");
  306. }
  307. printf(conn_tab[k].name);
  308. n++;
  309. }
  310. }
  311. if (vx_connectors == 0) {
  312. printf("no connectors!");
  313. return;
  314. }
  315. GO_WINDOW(3);
  316. vx_connector = (inl(BASE + VX_W3_INTERNAL_CFG)
  317. & INTERNAL_CONNECTOR_MASK)
  318. >> INTERNAL_CONNECTOR_BITS;
  319. if (vx_connector & 0x10) {
  320. vx_connector &= 0x0f;
  321. printf("[*%s*]", conn_tab[vx_connector].name);
  322. printf(": disable 'auto select' with DOS util!");
  323. } else {
  324. printf("[*%s*]", conn_tab[vx_connector].name);
  325. }
  326. }
  327. static void
  328. vxsetlink(void)
  329. {
  330. int i, j;
  331. char *reason, *warning;
  332. static char prev_conn = -1;
  333. if (prev_conn == -1) {
  334. prev_conn = vx_connector;
  335. }
  336. i = vx_connector; /* default in EEPROM */
  337. reason = "default";
  338. warning = 0;
  339. if ((vx_connectors & conn_tab[vx_connector].bit) == 0) {
  340. warning = "strange connector type in EEPROM.";
  341. reason = "forced";
  342. i = CONNECTOR_UTP;
  343. }
  344. if (warning != 0) {
  345. printf("warning: %s\n", warning);
  346. }
  347. printf("selected %s. (%s)\n", conn_tab[i].name, reason);
  348. /* Set the selected connector. */
  349. GO_WINDOW(3);
  350. j = inl(BASE + VX_W3_INTERNAL_CFG) & ~INTERNAL_CONNECTOR_MASK;
  351. outl(j | (i <<INTERNAL_CONNECTOR_BITS), BASE + VX_W3_INTERNAL_CFG);
  352. /* First, disable all. */
  353. outw(STOP_TRANSCEIVER, BASE + VX_COMMAND);
  354. udelay(8000);
  355. GO_WINDOW(4);
  356. outw(0, BASE + VX_W4_MEDIA_TYPE);
  357. /* Second, enable the selected one. */
  358. switch(i) {
  359. case CONNECTOR_UTP:
  360. GO_WINDOW(4);
  361. outw(ENABLE_UTP, BASE + VX_W4_MEDIA_TYPE);
  362. break;
  363. case CONNECTOR_BNC:
  364. outw(START_TRANSCEIVER,BASE + VX_COMMAND);
  365. udelay(8000);
  366. break;
  367. case CONNECTOR_TX:
  368. case CONNECTOR_FX:
  369. GO_WINDOW(4);
  370. outw(LINKBEAT_ENABLE, BASE + VX_W4_MEDIA_TYPE);
  371. break;
  372. default: /* AUI and MII fall here */
  373. break;
  374. }
  375. GO_WINDOW(1);
  376. }
  377. static void t595_disable(struct dev *dev)
  378. {
  379. struct nic *nic = (struct nic *)dev;
  380. t595_reset(nic);
  381. outw(STOP_TRANSCEIVER, BASE + VX_COMMAND);
  382. udelay(8000);
  383. GO_WINDOW(4);
  384. outw(0, BASE + VX_W4_MEDIA_TYPE);
  385. GO_WINDOW(1);
  386. }
  387. static void t595_irq(struct nic *nic __unused, irq_action_t action __unused)
  388. {
  389. switch ( action ) {
  390. case DISABLE :
  391. break;
  392. case ENABLE :
  393. break;
  394. case FORCE :
  395. break;
  396. }
  397. }
  398. /**************************************************************************
  399. ETH_PROBE - Look for an adapter
  400. ***************************************************************************/
  401. static int t595_probe ( struct dev *dev ) {
  402. struct nic *nic = nic_device ( dev );
  403. struct pci_device *pci = pci_device ( dev );
  404. int i;
  405. unsigned short *p;
  406. if (pci->ioaddr == 0)
  407. return 0;
  408. /* eth_nic_base = probeaddrs[0] & ~3; */
  409. eth_nic_base = pci->ioaddr;
  410. nic->irqno = 0;
  411. nic->ioaddr = pci->ioaddr & ~3;
  412. GO_WINDOW(0);
  413. outw(GLOBAL_RESET, BASE + VX_COMMAND);
  414. VX_BUSY_WAIT;
  415. vxgetlink();
  416. /*
  417. printf("\nEEPROM:");
  418. for (i = 0; i < (EEPROMSIZE/2); i++) {
  419. printf("%hX:", get_e(i));
  420. }
  421. printf("\n");
  422. */
  423. /*
  424. * Read the station address from the eeprom
  425. */
  426. p = (unsigned short *) nic->node_addr;
  427. for (i = 0; i < 3; i++) {
  428. GO_WINDOW(0);
  429. p[i] = htons(get_e(EEPROM_OEM_ADDR_0 + i));
  430. GO_WINDOW(2);
  431. outw(ntohs(p[i]), BASE + VX_W2_ADDR_0 + (i * 2));
  432. }
  433. printf("Ethernet address: %!\n", nic->node_addr);
  434. t595_reset(nic);
  435. dev->disable = t595_disable;
  436. nic->poll = t595_poll;
  437. nic->transmit = t595_transmit;
  438. nic->irq = t595_irq;
  439. return 1;
  440. }
  441. static struct pci_id t595_nics[] = {
  442. PCI_ROM(0x10b7, 0x5900, "3c590", "3Com590"), /* Vortex 10Mbps */
  443. PCI_ROM(0x10b7, 0x5950, "3c595", "3Com595"), /* Vortex 100baseTx */
  444. PCI_ROM(0x10b7, 0x5951, "3c595-1", "3Com595"), /* Vortex 100baseT4 */
  445. PCI_ROM(0x10b7, 0x5952, "3c595-2", "3Com595"), /* Vortex 100base-MII */
  446. PCI_ROM(0x10b7, 0x9000, "3c900-tpo", "3Com900-TPO"), /* 10 Base TPO */
  447. PCI_ROM(0x10b7, 0x9001, "3c900-t4", "3Com900-Combo"), /* 10/100 T4 */
  448. PCI_ROM(0x10b7, 0x9004, "3c900b-tpo", "3Com900B-TPO"), /* 10 Base TPO */
  449. PCI_ROM(0x10b7, 0x9005, "3c900b-combo", "3Com900B-Combo"), /* 10 Base Combo */
  450. PCI_ROM(0x10b7, 0x9006, "3c900b-tpb2", "3Com900B-2/T"), /* 10 Base TP and Base2 */
  451. PCI_ROM(0x10b7, 0x900a, "3c900b-fl", "3Com900B-FL"), /* 10 Base F */
  452. PCI_ROM(0x10b7, 0x9800, "3c980-cyclone-1", "3Com980-Cyclone"), /* Cyclone */
  453. PCI_ROM(0x10b7, 0x9805, "3c9805-1", "3Com9805"), /* Dual Port Server Cyclone */
  454. PCI_ROM(0x10b7, 0x7646, "3csoho100-tx-1", "3CSOHO100-TX"), /* Hurricane */
  455. PCI_ROM(0x10b7, 0x4500, "3c450-1", "3Com450 HomePNA Tornado"),
  456. };
  457. static struct pci_driver t595_driver =
  458. PCI_DRIVER ( "3C595", t595_nics, PCI_NO_CLASS );
  459. BOOT_DRIVER ( "3C595", t595_probe );
  460. /*
  461. * Local variables:
  462. * c-basic-offset: 8
  463. * End:
  464. */