Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

3c595.c 14KB

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