lance.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. /**************************************************************************
  2. Etherboot - BOOTP/TFTP Bootstrap Program
  3. LANCE NIC driver for Etherboot
  4. Large portions borrowed from the Linux LANCE driver by Donald Becker
  5. Ken Yap, July 1997
  6. ***************************************************************************/
  7. /*
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2, or (at
  11. * your option) any later version.
  12. */
  13. /* to get some global routines like printf */
  14. #include "etherboot.h"
  15. /* to get the interface to the body of the program */
  16. #include "nic.h"
  17. #ifdef INCLUDE_LANCE
  18. #include "pci.h"
  19. #endif
  20. #include "cards.h"
  21. /* Offsets from base I/O address */
  22. #if defined(INCLUDE_NE2100) || defined(INCLUDE_LANCE)
  23. #define LANCE_ETH_ADDR 0x0
  24. #define LANCE_DATA 0x10
  25. #define LANCE_ADDR 0x12
  26. #define LANCE_RESET 0x14
  27. #define LANCE_BUS_IF 0x16
  28. #define LANCE_TOTAL_SIZE 0x18
  29. #endif
  30. #ifdef INCLUDE_NI6510
  31. #define LANCE_ETH_ADDR 0x8
  32. #define LANCE_DATA 0x0
  33. #define LANCE_ADDR 0x2
  34. #define LANCE_RESET 0x4
  35. #define LANCE_BUS_IF 0x6
  36. #define LANCE_TOTAL_SIZE 0x10
  37. #endif
  38. /* lance_poll() now can use multiple Rx buffers to prevent packet loss. Set
  39. * Set LANCE_LOG_RX_BUFFERS to 0..7 for 1, 2, 4, 8, 16, 32, 64 or 128 Rx
  40. * buffers. Usually 4 (=16 Rx buffers) is a good value. (Andreas Neuhaus)
  41. * Decreased to 2 (=4 Rx buffers) (Ken Yap, 20010305) */
  42. #define LANCE_LOG_RX_BUFFERS 2 /* Use 2^2=4 Rx buffers */
  43. #define RX_RING_SIZE (1 << (LANCE_LOG_RX_BUFFERS))
  44. #define RX_RING_MOD_MASK (RX_RING_SIZE - 1)
  45. #define RX_RING_LEN_BITS ((LANCE_LOG_RX_BUFFERS) << 29)
  46. struct lance_init_block
  47. {
  48. unsigned short mode;
  49. unsigned char phys_addr[ETH_ALEN];
  50. unsigned long filter[2];
  51. Address rx_ring;
  52. Address tx_ring;
  53. };
  54. struct lance_rx_head
  55. {
  56. union {
  57. Address base;
  58. unsigned char addr[4];
  59. } u;
  60. short buf_length; /* 2s complement */
  61. short msg_length;
  62. };
  63. struct lance_tx_head
  64. {
  65. union {
  66. Address base;
  67. unsigned char addr[4];
  68. } u;
  69. short buf_length; /* 2s complement */
  70. short misc;
  71. };
  72. struct lance_interface
  73. {
  74. struct lance_init_block init_block;
  75. struct lance_rx_head rx_ring[RX_RING_SIZE];
  76. struct lance_tx_head tx_ring;
  77. unsigned char rbuf[RX_RING_SIZE][ETH_FRAME_LEN+4];
  78. unsigned char tbuf[ETH_FRAME_LEN];
  79. /*
  80. * Do not alter the order of the struct members above;
  81. * the hardware depends on the correct alignment.
  82. */
  83. int rx_idx;
  84. };
  85. #define LANCE_MUST_PAD 0x00000001
  86. #define LANCE_ENABLE_AUTOSELECT 0x00000002
  87. #define LANCE_SELECT_PHONELINE 0x00000004
  88. #define LANCE_MUST_UNRESET 0x00000008
  89. /* A mapping from the chip ID number to the part number and features.
  90. These are from the datasheets -- in real life the '970 version
  91. reportedly has the same ID as the '965. */
  92. static const struct lance_chip_type
  93. {
  94. int id_number;
  95. const char *name;
  96. int flags;
  97. } chip_table[] = {
  98. {0x0000, "LANCE 7990", /* Ancient lance chip. */
  99. LANCE_MUST_PAD + LANCE_MUST_UNRESET},
  100. {0x0003, "PCnet/ISA 79C960", /* 79C960 PCnet/ISA. */
  101. LANCE_ENABLE_AUTOSELECT},
  102. {0x2260, "PCnet/ISA+ 79C961", /* 79C961 PCnet/ISA+, Plug-n-Play. */
  103. LANCE_ENABLE_AUTOSELECT},
  104. {0x2420, "PCnet/PCI 79C970", /* 79C970 or 79C974 PCnet-SCSI, PCI. */
  105. LANCE_ENABLE_AUTOSELECT},
  106. /* Bug: the PCnet/PCI actually uses the PCnet/VLB ID number, so just call
  107. it the PCnet32. */
  108. {0x2430, "PCnet32", /* 79C965 PCnet for VL bus. */
  109. LANCE_ENABLE_AUTOSELECT},
  110. {0x2621, "PCnet/PCI-II 79C970A", /* 79C970A PCInetPCI II. */
  111. LANCE_ENABLE_AUTOSELECT},
  112. {0x2625, "PCnet-FAST III 79C973", /* 79C973 PCInet-FAST III. */
  113. LANCE_ENABLE_AUTOSELECT},
  114. {0x2626, "PCnet/HomePNA 79C978",
  115. LANCE_ENABLE_AUTOSELECT|LANCE_SELECT_PHONELINE},
  116. {0x0, "PCnet (unknown)",
  117. LANCE_ENABLE_AUTOSELECT},
  118. };
  119. /* Define a macro for converting program addresses to real addresses */
  120. #undef virt_to_bus
  121. #define virt_to_bus(x) ((unsigned long)x)
  122. static int chip_version;
  123. static int lance_version;
  124. static unsigned short ioaddr;
  125. #ifndef INCLUDE_LANCE
  126. static int dma;
  127. #endif
  128. static struct lance_interface *lp;
  129. /* additional 8 bytes for 8-byte alignment space */
  130. #ifdef USE_LOWMEM_BUFFER
  131. #define lance ((char *)0x10000 - (sizeof(struct lance_interface)+8))
  132. #else
  133. static char lance[sizeof(struct lance_interface)+8];
  134. #endif
  135. #ifndef INCLUDE_LANCE
  136. /* DMA defines and helper routines */
  137. /* DMA controller registers */
  138. #define DMA1_CMD_REG 0x08 /* command register (w) */
  139. #define DMA1_STAT_REG 0x08 /* status register (r) */
  140. #define DMA1_REQ_REG 0x09 /* request register (w) */
  141. #define DMA1_MASK_REG 0x0A /* single-channel mask (w) */
  142. #define DMA1_MODE_REG 0x0B /* mode register (w) */
  143. #define DMA1_CLEAR_FF_REG 0x0C /* clear pointer flip-flop (w) */
  144. #define DMA1_TEMP_REG 0x0D /* Temporary Register (r) */
  145. #define DMA1_RESET_REG 0x0D /* Master Clear (w) */
  146. #define DMA1_CLR_MASK_REG 0x0E /* Clear Mask */
  147. #define DMA1_MASK_ALL_REG 0x0F /* all-channels mask (w) */
  148. #define DMA2_CMD_REG 0xD0 /* command register (w) */
  149. #define DMA2_STAT_REG 0xD0 /* status register (r) */
  150. #define DMA2_REQ_REG 0xD2 /* request register (w) */
  151. #define DMA2_MASK_REG 0xD4 /* single-channel mask (w) */
  152. #define DMA2_MODE_REG 0xD6 /* mode register (w) */
  153. #define DMA2_CLEAR_FF_REG 0xD8 /* clear pointer flip-flop (w) */
  154. #define DMA2_TEMP_REG 0xDA /* Temporary Register (r) */
  155. #define DMA2_RESET_REG 0xDA /* Master Clear (w) */
  156. #define DMA2_CLR_MASK_REG 0xDC /* Clear Mask */
  157. #define DMA2_MASK_ALL_REG 0xDE /* all-channels mask (w) */
  158. #define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */
  159. #define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */
  160. #define DMA_MODE_CASCADE 0xC0 /* pass thru DREQ->HRQ, DACK<-HLDA only */
  161. /* enable/disable a specific DMA channel */
  162. static void enable_dma(unsigned int dmanr)
  163. {
  164. if (dmanr <= 3)
  165. outb_p(dmanr, DMA1_MASK_REG);
  166. else
  167. outb_p(dmanr & 3, DMA2_MASK_REG);
  168. }
  169. static void disable_dma(unsigned int dmanr)
  170. {
  171. if (dmanr <= 3)
  172. outb_p(dmanr | 4, DMA1_MASK_REG);
  173. else
  174. outb_p((dmanr & 3) | 4, DMA2_MASK_REG);
  175. }
  176. /* set mode (above) for a specific DMA channel */
  177. static void set_dma_mode(unsigned int dmanr, char mode)
  178. {
  179. if (dmanr <= 3)
  180. outb_p(mode | dmanr, DMA1_MODE_REG);
  181. else
  182. outb_p(mode | (dmanr&3), DMA2_MODE_REG);
  183. }
  184. #endif /* !INCLUDE_LANCE */
  185. /**************************************************************************
  186. RESET - Reset adapter
  187. ***************************************************************************/
  188. static void lance_reset(struct nic *nic)
  189. {
  190. int i;
  191. Address l;
  192. /* Reset the LANCE */
  193. (void)inw(ioaddr+LANCE_RESET);
  194. /* Un-Reset the LANCE, needed only for the NE2100 */
  195. if (chip_table[lance_version].flags & LANCE_MUST_UNRESET)
  196. outw(0, ioaddr+LANCE_RESET);
  197. if (chip_table[lance_version].flags & LANCE_ENABLE_AUTOSELECT)
  198. {
  199. /* This is 79C960 specific; Turn on auto-select of media
  200. (AUI, BNC). */
  201. outw(0x2, ioaddr+LANCE_ADDR);
  202. /* Don't touch 10base2 power bit. */
  203. outw(inw(ioaddr+LANCE_BUS_IF) | 0x2, ioaddr+LANCE_BUS_IF);
  204. }
  205. /* HomePNA cards need to explicitly pick the phoneline interface.
  206. * Some of these cards have ethernet interfaces as well, this
  207. * code might require some modification for those.
  208. */
  209. if (chip_table[lance_version].flags & LANCE_SELECT_PHONELINE) {
  210. short media, check ;
  211. /* this is specific to HomePNA cards... */
  212. outw(49, ioaddr+0x12) ;
  213. media = inw(ioaddr+0x16) ;
  214. #ifdef DEBUG
  215. printf("media was %d\n", media) ;
  216. #endif
  217. media &= ~3 ;
  218. media |= 1 ;
  219. #ifdef DEBUG
  220. printf("media changed to %d\n", media) ;
  221. #endif
  222. media &= ~3 ;
  223. media |= 1 ;
  224. outw(49, ioaddr+0x12) ;
  225. outw(media, ioaddr+0x16) ;
  226. outw(49, ioaddr+0x12) ;
  227. check = inw(ioaddr+0x16) ;
  228. #ifdef DEBUG
  229. printf("check %s, media was set properly\n",
  230. check == media ? "passed" : "FAILED" ) ;
  231. #endif
  232. }
  233. /* Re-initialise the LANCE, and start it when done. */
  234. /* Set station address */
  235. for (i = 0; i < ETH_ALEN; ++i)
  236. lp->init_block.phys_addr[i] = nic->node_addr[i];
  237. /* Preset the receive ring headers */
  238. for (i=0; i<RX_RING_SIZE; i++) {
  239. lp->rx_ring[i].buf_length = -ETH_FRAME_LEN-4;
  240. /* OWN */
  241. lp->rx_ring[i].u.base = virt_to_bus(lp->rbuf[i]) & 0xffffff;
  242. /* we set the top byte as the very last thing */
  243. lp->rx_ring[i].u.addr[3] = 0x80;
  244. }
  245. lp->rx_idx = 0;
  246. lp->init_block.mode = 0x0; /* enable Rx and Tx */
  247. l = (Address)virt_to_bus(&lp->init_block);
  248. outw(0x1, ioaddr+LANCE_ADDR);
  249. (void)inw(ioaddr+LANCE_ADDR);
  250. outw((short)l, ioaddr+LANCE_DATA);
  251. outw(0x2, ioaddr+LANCE_ADDR);
  252. (void)inw(ioaddr+LANCE_ADDR);
  253. outw((short)(l >> 16), ioaddr+LANCE_DATA);
  254. outw(0x4, ioaddr+LANCE_ADDR);
  255. (void)inw(ioaddr+LANCE_ADDR);
  256. outw(0x915, ioaddr+LANCE_DATA);
  257. outw(0x0, ioaddr+LANCE_ADDR);
  258. (void)inw(ioaddr+LANCE_ADDR);
  259. outw(0x4, ioaddr+LANCE_DATA); /* stop */
  260. outw(0x1, ioaddr+LANCE_DATA); /* init */
  261. for (i = 10000; i > 0; --i)
  262. if (inw(ioaddr+LANCE_DATA) & 0x100)
  263. break;
  264. #ifdef DEBUG
  265. if (i <= 0)
  266. printf("Init timed out\n");
  267. #endif
  268. /* Apparently clearing the InitDone bit here triggers a bug
  269. in the '974. (Mark Stockton) */
  270. outw(0x2, ioaddr+LANCE_DATA); /* start */
  271. }
  272. /**************************************************************************
  273. POLL - Wait for a frame
  274. ***************************************************************************/
  275. static int lance_poll(struct nic *nic)
  276. {
  277. int status;
  278. status = lp->rx_ring[lp->rx_idx].u.base >> 24;
  279. if (status & 0x80)
  280. return (0);
  281. #ifdef DEBUG
  282. printf("LANCE packet received rx_ring.u.base %X mcnt %hX csr0 %hX\n",
  283. lp->rx_ring[lp->rx_idx].u.base, lp->rx_ring[lp->rx_idx].msg_length,
  284. inw(ioaddr+LANCE_DATA));
  285. #endif
  286. if (status == 0x3)
  287. memcpy(nic->packet, lp->rbuf[lp->rx_idx], nic->packetlen = lp->rx_ring[lp->rx_idx].msg_length);
  288. /* Andrew Boyd of QNX reports that some revs of the 79C765
  289. clear the buffer length */
  290. lp->rx_ring[lp->rx_idx].buf_length = -ETH_FRAME_LEN-4;
  291. lp->rx_ring[lp->rx_idx].u.addr[3] |= 0x80; /* prime for next receive */
  292. /* I'm not sure if the following is still ok with multiple Rx buffers, but it works */
  293. outw(0x0, ioaddr+LANCE_ADDR);
  294. (void)inw(ioaddr+LANCE_ADDR);
  295. outw(0x500, ioaddr+LANCE_DATA); /* clear receive + InitDone */
  296. /* Switch to the next Rx ring buffer */
  297. lp->rx_idx = (lp->rx_idx + 1) & RX_RING_MOD_MASK;
  298. return (status == 0x3);
  299. }
  300. /**************************************************************************
  301. TRANSMIT - Transmit a frame
  302. ***************************************************************************/
  303. static void lance_transmit(
  304. struct nic *nic,
  305. const char *d, /* Destination */
  306. unsigned int t, /* Type */
  307. unsigned int s, /* size */
  308. const char *p) /* Packet */
  309. {
  310. unsigned long time;
  311. /* copy the packet to ring buffer */
  312. memcpy(lp->tbuf, d, ETH_ALEN); /* dst */
  313. memcpy(&lp->tbuf[ETH_ALEN], nic->node_addr, ETH_ALEN); /* src */
  314. lp->tbuf[ETH_ALEN+ETH_ALEN] = t >> 8; /* type */
  315. lp->tbuf[ETH_ALEN+ETH_ALEN+1] = t; /* type */
  316. memcpy(&lp->tbuf[ETH_HLEN], p, s);
  317. s += ETH_HLEN;
  318. if (chip_table[chip_version].flags & LANCE_MUST_PAD)
  319. while (s < ETH_ZLEN) /* pad to min length */
  320. lp->tbuf[s++] = 0;
  321. lp->tx_ring.buf_length = -s;
  322. lp->tx_ring.misc = 0x0;
  323. /* OWN, STP, ENP */
  324. lp->tx_ring.u.base = virt_to_bus(lp->tbuf) & 0xffffff;
  325. /* we set the top byte as the very last thing */
  326. lp->tx_ring.u.addr[3] = 0x83;
  327. /* Trigger an immediate send poll */
  328. outw(0x0, ioaddr+LANCE_ADDR);
  329. (void)inw(ioaddr+LANCE_ADDR); /* as in the datasheets... */
  330. /* Klaus Espenlaub: the value below was 0x48, but that enabled the
  331. * interrupt line, causing a hang if for some reasone the interrupt
  332. * controller had the LANCE interrupt enabled. I have no idea why
  333. * nobody ran into this before... */
  334. outw(0x08, ioaddr+LANCE_DATA);
  335. /* wait for transmit complete */
  336. time = currticks() + TICKS_PER_SEC; /* wait one second */
  337. while (currticks() < time && (lp->tx_ring.u.base & 0x80000000) != 0)
  338. ;
  339. if ((lp->tx_ring.u.base & 0x80000000) != 0)
  340. printf("LANCE timed out on transmit\n");
  341. (void)inw(ioaddr+LANCE_ADDR);
  342. outw(0x200, ioaddr+LANCE_DATA); /* clear transmit + InitDone */
  343. #ifdef DEBUG
  344. printf("tx_ring.u.base %X tx_ring.buf_length %hX tx_ring.misc %hX csr0 %hX\n",
  345. lp->tx_ring.u.base, lp->tx_ring.buf_length, lp->tx_ring.misc,
  346. inw(ioaddr+LANCE_DATA));
  347. #endif
  348. }
  349. static void lance_disable(struct nic *nic)
  350. {
  351. (void)inw(ioaddr+LANCE_RESET);
  352. if (chip_table[lance_version].flags & LANCE_MUST_UNRESET)
  353. outw(0, ioaddr+LANCE_RESET);
  354. outw(0, ioaddr+LANCE_ADDR);
  355. outw(0x0004, ioaddr+LANCE_DATA); /* stop the LANCE */
  356. #ifndef INCLUDE_LANCE
  357. disable_dma(dma);
  358. #endif
  359. }
  360. #ifdef INCLUDE_LANCE
  361. static int lance_probe1(struct nic *nic, struct pci_device *pci)
  362. #else
  363. static int lance_probe1(struct nic *nic)
  364. #endif
  365. {
  366. int reset_val ;
  367. unsigned int i;
  368. Address l;
  369. short dma_channels;
  370. #ifndef INCLUDE_LANCE
  371. static const char dmas[] = { 5, 6, 7, 3 };
  372. #endif
  373. reset_val = inw(ioaddr+LANCE_RESET);
  374. outw(reset_val, ioaddr+LANCE_RESET);
  375. #if 1 /* Klaus Espenlaub -- was #ifdef INCLUDE_NE2100*/
  376. outw(0x0, ioaddr+LANCE_ADDR); /* Switch to window 0 */
  377. if (inw(ioaddr+LANCE_DATA) != 0x4)
  378. return (-1);
  379. #endif
  380. outw(88, ioaddr+LANCE_ADDR); /* Get the version of the chip */
  381. if (inw(ioaddr+LANCE_ADDR) != 88)
  382. lance_version = 0;
  383. else
  384. {
  385. chip_version = inw(ioaddr+LANCE_DATA);
  386. outw(89, ioaddr+LANCE_ADDR);
  387. chip_version |= inw(ioaddr+LANCE_DATA) << 16;
  388. if ((chip_version & 0xfff) != 0x3)
  389. return (-1);
  390. chip_version = (chip_version >> 12) & 0xffff;
  391. for (lance_version = 1; chip_table[lance_version].id_number != 0; ++lance_version)
  392. if (chip_table[lance_version].id_number == chip_version)
  393. break;
  394. }
  395. /* make sure data structure is 8-byte aligned */
  396. l = ((Address)lance + 7) & ~7;
  397. lp = (struct lance_interface *)l;
  398. lp->init_block.mode = 0x3; /* disable Rx and Tx */
  399. lp->init_block.filter[0] = lp->init_block.filter[1] = 0x0;
  400. /* using multiple Rx buffer and a single Tx buffer */
  401. lp->init_block.rx_ring = (virt_to_bus(&lp->rx_ring) & 0xffffff) | RX_RING_LEN_BITS;
  402. lp->init_block.tx_ring = virt_to_bus(&lp->tx_ring) & 0xffffff;
  403. l = virt_to_bus(&lp->init_block);
  404. outw(0x1, ioaddr+LANCE_ADDR);
  405. (void)inw(ioaddr+LANCE_ADDR);
  406. outw((unsigned short)l, ioaddr+LANCE_DATA);
  407. outw(0x2, ioaddr+LANCE_ADDR);
  408. (void)inw(ioaddr+LANCE_ADDR);
  409. outw((unsigned short)(l >> 16), ioaddr+LANCE_DATA);
  410. outw(0x4, ioaddr+LANCE_ADDR);
  411. (void)inw(ioaddr+LANCE_ADDR);
  412. outw(0x915, ioaddr+LANCE_DATA);
  413. outw(0x0, ioaddr+LANCE_ADDR);
  414. (void)inw(ioaddr+LANCE_ADDR);
  415. /* Get station address */
  416. for (i = 0; i < ETH_ALEN; ++i) {
  417. nic->node_addr[i] = inb(ioaddr+LANCE_ETH_ADDR+i);
  418. }
  419. #ifndef INCLUDE_LANCE
  420. /* now probe for DMA channel */
  421. dma_channels = ((inb(DMA1_STAT_REG) >> 4) & 0xf) |
  422. (inb(DMA2_STAT_REG) & 0xf0);
  423. /* need to fix when PCI provides DMA info */
  424. for (i = 0; i < (sizeof(dmas)/sizeof(dmas[0])); ++i)
  425. {
  426. int j;
  427. dma = dmas[i];
  428. /* Don't enable a permanently busy DMA channel,
  429. or the machine will hang */
  430. if (dma_channels & (1 << dma))
  431. continue;
  432. outw(0x7f04, ioaddr+LANCE_DATA); /* clear memory error bits */
  433. set_dma_mode(dma, DMA_MODE_CASCADE);
  434. enable_dma(dma);
  435. outw(0x1, ioaddr+LANCE_DATA); /* init */
  436. for (j = 100; j > 0; --j)
  437. if (inw(ioaddr+LANCE_DATA) & 0x900)
  438. break;
  439. if (inw(ioaddr+LANCE_DATA) & 0x100)
  440. break;
  441. else
  442. disable_dma(dma);
  443. }
  444. if (i >= (sizeof(dmas)/sizeof(dmas[0])))
  445. dma = 0;
  446. printf("\n%s base %#X, DMA %d, addr %!\n",
  447. chip_table[lance_version].name, ioaddr, dma, nic->node_addr);
  448. #else
  449. printf(" %s base %#hX, addr %!\n", chip_table[lance_version].name, ioaddr, nic->node_addr);
  450. #endif
  451. if (chip_table[chip_version].flags & LANCE_ENABLE_AUTOSELECT) {
  452. /* Turn on auto-select of media (10baseT or BNC) so that the
  453. * user watch the LEDs. */
  454. outw(0x0002, ioaddr+LANCE_ADDR);
  455. /* Don't touch 10base2 power bit. */
  456. outw(inw(ioaddr+LANCE_BUS_IF) | 0x0002, ioaddr+LANCE_BUS_IF);
  457. }
  458. return (lance_version);
  459. }
  460. /**************************************************************************
  461. PROBE - Look for an adapter, this routine's visible to the outside
  462. ***************************************************************************/
  463. #ifdef INCLUDE_LANCE
  464. struct nic *lancepci_probe(struct nic *nic, unsigned short *probe_addrs, struct pci_device *pci)
  465. #endif
  466. #ifdef INCLUDE_NE2100
  467. struct nic *ne2100_probe(struct nic *nic, unsigned short *probe_addrs)
  468. #endif
  469. #ifdef INCLUDE_NI6510
  470. struct nic *ni6510_probe(struct nic *nic, unsigned short *probe_addrs)
  471. #endif
  472. {
  473. unsigned short *p;
  474. #ifndef INCLUDE_LANCE
  475. static unsigned short io_addrs[] = { 0x300, 0x320, 0x340, 0x360, 0 };
  476. #endif
  477. /* if probe_addrs is 0, then routine can use a hardwired default */
  478. if (probe_addrs == 0) {
  479. #ifdef INCLUDE_LANCE
  480. return 0;
  481. #else
  482. probe_addrs = io_addrs;
  483. #endif
  484. }
  485. for (p = probe_addrs; (ioaddr = *p) != 0; ++p)
  486. {
  487. char offset15, offset14 = inb(ioaddr + 14);
  488. unsigned short pci_cmd;
  489. #ifdef INCLUDE_NE2100
  490. if ((offset14 == 0x52 || offset14 == 0x57) &&
  491. ((offset15 = inb(ioaddr + 15)) == 0x57 || offset15 == 0x44))
  492. if (lance_probe1(nic) >= 0)
  493. break;
  494. #endif
  495. #ifdef INCLUDE_NI6510
  496. if ((offset14 == 0x00 || offset14 == 0x52) &&
  497. ((offset15 = inb(ioaddr + 15)) == 0x55 || offset15 == 0x44))
  498. if (lance_probe1(nic) >= 0)
  499. break;
  500. #endif
  501. #ifdef INCLUDE_LANCE
  502. adjust_pci_device(pci);
  503. if (lance_probe1(nic, pci) >= 0)
  504. break;
  505. #endif
  506. }
  507. /* if board found */
  508. if (ioaddr != 0)
  509. {
  510. /* point to NIC specific routines */
  511. lance_reset(nic);
  512. nic->reset = lance_reset;
  513. nic->poll = lance_poll;
  514. nic->transmit = lance_transmit;
  515. nic->disable = lance_disable;
  516. return nic;
  517. }
  518. /* no board found */
  519. return 0;
  520. }