Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

w89c840.c 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. /*
  2. * Etherboot - BOOTP/TFTP Bootstrap Program
  3. *
  4. * w89c840.c -- This file implements the winbond-840 driver for etherboot.
  5. *
  6. */
  7. /*
  8. * Adapted by Igor V. Kovalenko
  9. * -- <garrison@mail.ru>
  10. * OR
  11. * -- <iko@crec.mipt.ru>
  12. * Initial adaptaion stage, including testing, completed 23 August 2000.
  13. */
  14. /*
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2, or (at
  18. * your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful, but
  21. * WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. * General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28. */
  29. FILE_LICENCE ( GPL2_OR_LATER );
  30. /*
  31. * date version by what
  32. * Written: Aug 20 2000 V0.10 iko Initial revision.
  33. * changes: Aug 22 2000 V0.90 iko Works!
  34. * Aug 23 2000 V0.91 iko Cleanup, posted to etherboot
  35. * maintainer.
  36. * Aug 26 2000 V0.92 iko Fixed Rx ring handling.
  37. * First Linux Kernel (TM)
  38. * successfully loaded using
  39. * this driver.
  40. * Jan 07 2001 V0.93 iko Transmitter timeouts are handled
  41. * using timer2 routines. Proposed
  42. * by Ken Yap to eliminate CPU speed
  43. * dependency.
  44. * Dec 12 2003 V0.94 timlegge Fixed issues in 5.2, removed
  45. * interrupt usage, enabled
  46. * multicast support
  47. *
  48. * This is the etherboot driver for cards based on Winbond W89c840F chip.
  49. *
  50. * It was written from skeleton source, with Donald Becker's winbond-840.c
  51. * kernel driver as a guideline. Mostly the w89c840 related definitions
  52. * and the lower level routines have been cut-and-pasted into this source.
  53. *
  54. * Frankly speaking, about 90% of the code was obtained using cut'n'paste
  55. * sequence :) while the remainder appeared while brainstorming
  56. * Linux Kernel 2.4.0-testX source code. Thanks, Donald and Linus!
  57. *
  58. * There was a demand for using this card in a rather large
  59. * remote boot environment at MSKP OVTI Lab of
  60. * Moscow Institute for Physics and Technology (MIPT) -- http://www.mipt.ru/
  61. * so you may count that for motivation.
  62. *
  63. */
  64. /*
  65. * If you want to see debugging output then define W89C840_DEBUG
  66. */
  67. /*
  68. #define W89C840_DEBUG
  69. */
  70. /*
  71. * Keep using IO_OPS for Etherboot driver!
  72. */
  73. #define USE_IO_OPS
  74. #include "etherboot.h"
  75. #include "nic.h"
  76. #include <gpxe/pci.h>
  77. #include <gpxe/ethernet.h>
  78. static const char *w89c840_version = "driver Version 0.94 - December 12, 2003";
  79. /* Linux support functions */
  80. #define virt_to_le32desc(addr) virt_to_bus(addr)
  81. #define le32desc_to_virt(addr) bus_to_virt(addr)
  82. /*
  83. #define cpu_to_le32(val) (val)
  84. #define le32_to_cpu(val) (val)
  85. */
  86. /* Operational parameters that are set at compile time. */
  87. /* Keep the ring sizes a power of two for compile efficiency.
  88. The compiler will convert <unsigned>'%'<2^N> into a bit mask.
  89. Making the Tx ring too large decreases the effectiveness of channel
  90. bonding and packet priority.
  91. There are no ill effects from too-large receive rings. */
  92. #define TX_RING_SIZE 2
  93. #define RX_RING_SIZE 2
  94. /* The presumed FIFO size for working around the Tx-FIFO-overflow bug.
  95. To avoid overflowing we don't queue again until we have room for a
  96. full-size packet.
  97. */
  98. #define TX_FIFO_SIZE (2048)
  99. #define TX_BUG_FIFO_LIMIT (TX_FIFO_SIZE-1514-16)
  100. /* Operational parameters that usually are not changed. */
  101. /* Time in jiffies before concluding the transmitter is hung. */
  102. #define TX_TIMEOUT (10*1000)
  103. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
  104. /*
  105. * Used to be this much CPU loops on Celeron@400 (?),
  106. * now using real timer and TX_TIMEOUT!
  107. * #define TX_LOOP_COUNT 10000000
  108. */
  109. #if !defined(__OPTIMIZE__)
  110. #warning You must compile this file with the correct options!
  111. #warning See the last lines of the source file.
  112. #error You must compile this driver with "-O".
  113. #endif
  114. enum chip_capability_flags {CanHaveMII=1, HasBrokenTx=2};
  115. #ifdef USE_IO_OPS
  116. #define W840_FLAGS (PCI_USES_IO | PCI_ADDR0 | PCI_USES_MASTER)
  117. #else
  118. #define W840_FLAGS (PCI_USES_MEM | PCI_ADDR1 | PCI_USES_MASTER)
  119. #endif
  120. static u32 driver_flags = CanHaveMII | HasBrokenTx;
  121. /* This driver was written to use PCI memory space, however some x86 systems
  122. work only with I/O space accesses. Pass -DUSE_IO_OPS to use PCI I/O space
  123. accesses instead of memory space. */
  124. #ifdef USE_IO_OPS
  125. #undef readb
  126. #undef readw
  127. #undef readl
  128. #undef writeb
  129. #undef writew
  130. #undef writel
  131. #define readb inb
  132. #define readw inw
  133. #define readl inl
  134. #define writeb outb
  135. #define writew outw
  136. #define writel outl
  137. #endif
  138. /* Offsets to the Command and Status Registers, "CSRs".
  139. While similar to the Tulip, these registers are longword aligned.
  140. Note: It's not useful to define symbolic names for every register bit in
  141. the device. The name can only partially document the semantics and make
  142. the driver longer and more difficult to read.
  143. */
  144. enum w840_offsets {
  145. PCIBusCfg=0x00, TxStartDemand=0x04, RxStartDemand=0x08,
  146. RxRingPtr=0x0C, TxRingPtr=0x10,
  147. IntrStatus=0x14, NetworkConfig=0x18, IntrEnable=0x1C,
  148. RxMissed=0x20, EECtrl=0x24, MIICtrl=0x24, BootRom=0x28, GPTimer=0x2C,
  149. CurRxDescAddr=0x30, CurRxBufAddr=0x34, /* Debug use */
  150. MulticastFilter0=0x38, MulticastFilter1=0x3C, StationAddr=0x40,
  151. CurTxDescAddr=0x4C, CurTxBufAddr=0x50,
  152. };
  153. /* Bits in the interrupt status/enable registers. */
  154. /* The bits in the Intr Status/Enable registers, mostly interrupt sources. */
  155. enum intr_status_bits {
  156. NormalIntr=0x10000, AbnormalIntr=0x8000,
  157. IntrPCIErr=0x2000, TimerInt=0x800,
  158. IntrRxDied=0x100, RxNoBuf=0x80, IntrRxDone=0x40,
  159. TxFIFOUnderflow=0x20, RxErrIntr=0x10,
  160. TxIdle=0x04, IntrTxStopped=0x02, IntrTxDone=0x01,
  161. };
  162. /* Bits in the NetworkConfig register. */
  163. enum rx_mode_bits {
  164. AcceptErr=0x80, AcceptRunt=0x40,
  165. AcceptBroadcast=0x20, AcceptMulticast=0x10,
  166. AcceptAllPhys=0x08, AcceptMyPhys=0x02,
  167. };
  168. enum mii_reg_bits {
  169. MDIO_ShiftClk=0x10000, MDIO_DataIn=0x80000, MDIO_DataOut=0x20000,
  170. MDIO_EnbOutput=0x40000, MDIO_EnbIn = 0x00000,
  171. };
  172. /* The Tulip Rx and Tx buffer descriptors. */
  173. struct w840_rx_desc {
  174. s32 status;
  175. s32 length;
  176. u32 buffer1;
  177. u32 next_desc;
  178. };
  179. struct w840_tx_desc {
  180. s32 status;
  181. s32 length;
  182. u32 buffer1, buffer2; /* We use only buffer 1. */
  183. };
  184. /* Bits in network_desc.status */
  185. enum desc_status_bits {
  186. DescOwn=0x80000000, DescEndRing=0x02000000, DescUseLink=0x01000000,
  187. DescWholePkt=0x60000000, DescStartPkt=0x20000000, DescEndPkt=0x40000000,
  188. DescIntr=0x80000000,
  189. };
  190. #define PRIV_ALIGN 15 /* Required alignment mask */
  191. #define PRIV_ALIGN_BYTES 32
  192. static struct winbond_private
  193. {
  194. /* Descriptor rings first for alignment. */
  195. struct w840_rx_desc rx_ring[RX_RING_SIZE];
  196. struct w840_tx_desc tx_ring[TX_RING_SIZE];
  197. struct net_device *next_module; /* Link for devices of this type. */
  198. void *priv_addr; /* Unaligned address for kfree */
  199. const char *product_name;
  200. /* Frequently used values: keep some adjacent for cache effect. */
  201. int chip_id, drv_flags;
  202. struct pci_dev *pci_dev;
  203. int csr6;
  204. struct w840_rx_desc *rx_head_desc;
  205. unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */
  206. unsigned int rx_buf_sz; /* Based on MTU+slack. */
  207. unsigned int cur_tx, dirty_tx;
  208. int tx_q_bytes;
  209. unsigned int tx_full:1; /* The Tx queue is full. */
  210. /* These values are keep track of the transceiver/media in use. */
  211. unsigned int full_duplex:1; /* Full-duplex operation requested. */
  212. unsigned int duplex_lock:1;
  213. unsigned int medialock:1; /* Do not sense media. */
  214. unsigned int default_port:4; /* Last dev->if_port value. */
  215. /* MII transceiver section. */
  216. int mii_cnt; /* MII device addresses. */
  217. u16 advertising; /* NWay media advertisement */
  218. unsigned char phys[2]; /* MII device addresses. */
  219. } w840private __attribute__ ((aligned (PRIV_ALIGN_BYTES)));
  220. /* NIC specific static variables go here */
  221. static int ioaddr;
  222. static unsigned short eeprom [0x40];
  223. struct {
  224. char rx_packet[PKT_BUF_SZ * RX_RING_SIZE];
  225. char tx_packet[PKT_BUF_SZ * TX_RING_SIZE];
  226. } w89c840_buf __shared;
  227. static int eeprom_read(long ioaddr, int location);
  228. static int mdio_read(int base_address, int phy_id, int location);
  229. #if 0
  230. static void mdio_write(int base_address, int phy_id, int location, int value);
  231. #endif
  232. static void check_duplex(void);
  233. static void set_rx_mode(void);
  234. static void init_ring(void);
  235. #if defined(W89C840_DEBUG)
  236. static void decode_interrupt(u32 intr_status)
  237. {
  238. printf("Interrupt status: ");
  239. #define TRACE_INTR(_intr_) \
  240. if (intr_status & (_intr_)) { printf (" " #_intr_); }
  241. TRACE_INTR(NormalIntr);
  242. TRACE_INTR(AbnormalIntr);
  243. TRACE_INTR(IntrPCIErr);
  244. TRACE_INTR(TimerInt);
  245. TRACE_INTR(IntrRxDied);
  246. TRACE_INTR(RxNoBuf);
  247. TRACE_INTR(IntrRxDone);
  248. TRACE_INTR(TxFIFOUnderflow);
  249. TRACE_INTR(RxErrIntr);
  250. TRACE_INTR(TxIdle);
  251. TRACE_INTR(IntrTxStopped);
  252. TRACE_INTR(IntrTxDone);
  253. printf("\n");
  254. /*sleep(1);*/
  255. }
  256. #endif
  257. /**************************************************************************
  258. w89c840_reset - Reset adapter
  259. ***************************************************************************/
  260. static void w89c840_reset(struct nic *nic)
  261. {
  262. int i;
  263. /* Reset the chip to erase previous misconfiguration.
  264. No hold time required! */
  265. writel(0x00000001, ioaddr + PCIBusCfg);
  266. init_ring();
  267. writel(virt_to_bus(w840private.rx_ring), ioaddr + RxRingPtr);
  268. writel(virt_to_bus(w840private.tx_ring), ioaddr + TxRingPtr);
  269. for (i = 0; i < ETH_ALEN; i++)
  270. writeb(nic->node_addr[i], ioaddr + StationAddr + i);
  271. /* Initialize other registers. */
  272. /* Configure the PCI bus bursts and FIFO thresholds.
  273. 486: Set 8 longword cache alignment, 8 longword burst.
  274. 586: Set 16 longword cache alignment, no burst limit.
  275. Cache alignment bits 15:14 Burst length 13:8
  276. 0000 <not allowed> 0000 align to cache 0800 8 longwords
  277. 4000 8 longwords 0100 1 longword 1000 16 longwords
  278. 8000 16 longwords 0200 2 longwords 2000 32 longwords
  279. C000 32 longwords 0400 4 longwords
  280. Wait the specified 50 PCI cycles after a reset by initializing
  281. Tx and Rx queues and the address filter list. */
  282. writel(0xE010, ioaddr + PCIBusCfg);
  283. writel(0, ioaddr + RxStartDemand);
  284. w840private.csr6 = 0x20022002;
  285. check_duplex();
  286. set_rx_mode();
  287. /* Do not enable the interrupts Etherboot doesn't need them */
  288. /*
  289. writel(0x1A0F5, ioaddr + IntrStatus);
  290. writel(0x1A0F5, ioaddr + IntrEnable);
  291. */
  292. #if defined(W89C840_DEBUG)
  293. printf("winbond-840 : Done reset.\n");
  294. #endif
  295. }
  296. #if 0
  297. static void handle_intr(u32 intr_stat)
  298. {
  299. if ((intr_stat & (NormalIntr|AbnormalIntr)) == 0) {
  300. /* we are polling, do not return now */
  301. /*return 0;*/
  302. } else {
  303. /* Acknowledge all of the current interrupt sources ASAP. */
  304. writel(intr_stat & 0x001ffff, ioaddr + IntrStatus);
  305. }
  306. if (intr_stat & AbnormalIntr) {
  307. /* There was an abnormal interrupt */
  308. printf("\n-=- Abnormal interrupt.\n");
  309. #if defined(W89C840_DEBUG)
  310. decode_interrupt(intr_stat);
  311. #endif
  312. if (intr_stat & RxNoBuf) {
  313. /* There was an interrupt */
  314. printf("-=- <=> No receive buffers available.\n");
  315. writel(0, ioaddr + RxStartDemand);
  316. }
  317. }
  318. }
  319. #endif
  320. /**************************************************************************
  321. w89c840_poll - Wait for a frame
  322. ***************************************************************************/
  323. static int w89c840_poll(struct nic *nic, int retrieve)
  324. {
  325. /* return true if there's an ethernet packet ready to read */
  326. /* nic->packet should contain data on return */
  327. /* nic->packetlen should contain length of data */
  328. int packet_received = 0;
  329. #if defined(W89C840_DEBUG)
  330. u32 intr_status = readl(ioaddr + IntrStatus);
  331. #endif
  332. do {
  333. /* Code from netdev_rx(dev) */
  334. int entry = w840private.cur_rx % RX_RING_SIZE;
  335. struct w840_rx_desc *desc = w840private.rx_head_desc;
  336. s32 status = desc->status;
  337. if (status & DescOwn) {
  338. /* DescOwn bit is still set, we should wait for RX to complete */
  339. packet_received = 0;
  340. break;
  341. }
  342. if ( !retrieve ) {
  343. packet_received = 1;
  344. break;
  345. }
  346. if ((status & 0x38008300) != 0x0300) {
  347. if ((status & 0x38000300) != 0x0300) {
  348. /* Ingore earlier buffers. */
  349. if ((status & 0xffff) != 0x7fff) {
  350. printf("winbond-840 : Oversized Ethernet frame spanned "
  351. "multiple buffers, entry %d status %X !\n",
  352. w840private.cur_rx, (unsigned int) status);
  353. }
  354. } else if (status & 0x8000) {
  355. /* There was a fatal error. */
  356. #if defined(W89C840_DEBUG)
  357. printf("winbond-840 : Receive error, Rx status %X :", status);
  358. if (status & 0x0890) {
  359. printf(" RXLEN_ERROR");
  360. }
  361. if (status & 0x004C) {
  362. printf(", FRAME_ERROR");
  363. }
  364. if (status & 0x0002) {
  365. printf(", CRC_ERROR");
  366. }
  367. printf("\n");
  368. #endif
  369. /* Simpy do a reset now... */
  370. w89c840_reset(nic);
  371. packet_received = 0;
  372. break;
  373. }
  374. } else {
  375. /* Omit the four octet CRC from the length. */
  376. int pkt_len = ((status >> 16) & 0x7ff) - 4;
  377. #if defined(W89C840_DEBUG)
  378. printf(" netdev_rx() normal Rx pkt ring %d length %d status %X\n", entry, pkt_len, status);
  379. #endif
  380. nic->packetlen = pkt_len;
  381. /* Check if the packet is long enough to accept without copying
  382. to a minimally-sized skbuff. */
  383. memcpy(nic->packet, le32desc_to_virt(w840private.rx_ring[entry].buffer1), pkt_len);
  384. packet_received = 1;
  385. /* Release buffer to NIC */
  386. w840private.rx_ring[entry].status = DescOwn;
  387. #if defined(W89C840_DEBUG)
  388. /* You will want this info for the initial debug. */
  389. printf(" Rx data %hhX:%hhX:%hhX:%hhX:%hhX:"
  390. "%hhX %hhX:%hhX:%hhX:%hhX:%hhX:%hhX %hhX%hhX "
  391. "%hhX.%hhX.%hhX.%hhX.\n",
  392. nic->packet[0], nic->packet[1], nic->packet[2], nic->packet[3],
  393. nic->packet[4], nic->packet[5], nic->packet[6], nic->packet[7],
  394. nic->packet[8], nic->packet[9], nic->packet[10],
  395. nic->packet[11], nic->packet[12], nic->packet[13],
  396. nic->packet[14], nic->packet[15], nic->packet[16],
  397. nic->packet[17]);
  398. #endif
  399. }
  400. entry = (++w840private.cur_rx) % RX_RING_SIZE;
  401. w840private.rx_head_desc = &w840private.rx_ring[entry];
  402. } while (0);
  403. return packet_received;
  404. }
  405. /**************************************************************************
  406. w89c840_transmit - Transmit a frame
  407. ***************************************************************************/
  408. static void w89c840_transmit(
  409. struct nic *nic,
  410. const char *d, /* Destination */
  411. unsigned int t, /* Type */
  412. unsigned int s, /* size */
  413. const char *p) /* Packet */
  414. {
  415. /* send the packet to destination */
  416. unsigned entry;
  417. int transmit_status;
  418. unsigned long ct;
  419. /* Caution: the write order is important here, set the field
  420. with the "ownership" bits last. */
  421. /* Fill in our transmit buffer */
  422. entry = w840private.cur_tx % TX_RING_SIZE;
  423. memcpy (w89c840_buf.tx_packet, d, ETH_ALEN); /* dst */
  424. memcpy (w89c840_buf.tx_packet + ETH_ALEN, nic->node_addr, ETH_ALEN);/*src*/
  425. *((char *) w89c840_buf.tx_packet + 12) = t >> 8; /* type */
  426. *((char *) w89c840_buf.tx_packet + 13) = t;
  427. memcpy (w89c840_buf.tx_packet + ETH_HLEN, p, s);
  428. s += ETH_HLEN;
  429. while (s < ETH_ZLEN)
  430. *((char *) w89c840_buf.tx_packet + ETH_HLEN + (s++)) = 0;
  431. w840private.tx_ring[entry].buffer1
  432. = virt_to_le32desc(w89c840_buf.tx_packet);
  433. w840private.tx_ring[entry].length = (DescWholePkt | (u32) s);
  434. if (entry >= TX_RING_SIZE-1) /* Wrap ring */
  435. w840private.tx_ring[entry].length |= (DescIntr | DescEndRing);
  436. w840private.tx_ring[entry].status = (DescOwn);
  437. w840private.cur_tx++;
  438. w840private.tx_q_bytes = (u16) s;
  439. writel(0, ioaddr + TxStartDemand);
  440. /* Work around horrible bug in the chip by marking the queue as full
  441. when we do not have FIFO room for a maximum sized packet. */
  442. if ((w840private.drv_flags & HasBrokenTx) && w840private.tx_q_bytes > TX_BUG_FIFO_LIMIT) {
  443. /* Actually this is left to help finding error tails later in debugging...
  444. * See Linux kernel driver in winbond-840.c for details.
  445. */
  446. w840private.tx_full = 1;
  447. }
  448. #if defined(W89C840_DEBUG)
  449. printf("winbond-840 : Transmit frame # %d size %d queued in slot %d.\n", w840private.cur_tx, s, entry);
  450. #endif
  451. /* Now wait for TX to complete. */
  452. transmit_status = w840private.tx_ring[entry].status;
  453. ct = currticks();
  454. {
  455. #if defined W89C840_DEBUG
  456. u32 intr_stat = 0;
  457. #endif
  458. while (1) {
  459. #if defined(W89C840_DEBUG)
  460. decode_interrupt(intr_stat);
  461. #endif
  462. while ( (transmit_status & DescOwn) && ct + TX_TIMEOUT < currticks()) {
  463. transmit_status = w840private.tx_ring[entry].status;
  464. }
  465. break;
  466. }
  467. }
  468. if ((transmit_status & DescOwn) == 0) {
  469. #if defined(W89C840_DEBUG)
  470. printf("winbond-840 : transmission complete after wait loop iterations, status %X\n",
  471. w840private.tx_ring[entry].status);
  472. #endif
  473. return;
  474. }
  475. /* Transmit timed out... */
  476. printf("winbond-840 : transmission TIMEOUT : status %X\n",
  477. (unsigned int) w840private.tx_ring[entry].status);
  478. return;
  479. }
  480. /**************************************************************************
  481. w89c840_disable - Turn off ethernet interface
  482. ***************************************************************************/
  483. static void w89c840_disable ( struct nic *nic ) {
  484. w89c840_reset(nic);
  485. /* Don't know what to do to disable the board. Is this needed at all? */
  486. /* Yes, a live NIC can corrupt the loaded memory later [Ken] */
  487. /* Stop the chip's Tx and Rx processes. */
  488. writel(w840private.csr6 &= ~0x20FA, ioaddr + NetworkConfig);
  489. }
  490. /**************************************************************************
  491. w89c840_irq - Enable, Disable, or Force interrupts
  492. ***************************************************************************/
  493. static void w89c840_irq(struct nic *nic __unused, irq_action_t action __unused)
  494. {
  495. switch ( action ) {
  496. case DISABLE :
  497. break;
  498. case ENABLE :
  499. break;
  500. case FORCE :
  501. break;
  502. }
  503. }
  504. static struct nic_operations w89c840_operations = {
  505. .connect = dummy_connect,
  506. .poll = w89c840_poll,
  507. .transmit = w89c840_transmit,
  508. .irq = w89c840_irq,
  509. };
  510. static struct pci_device_id w89c840_nics[] = {
  511. PCI_ROM(0x1050, 0x0840, "winbond840", "Winbond W89C840F", 0),
  512. PCI_ROM(0x11f6, 0x2011, "compexrl100atx", "Compex RL100ATX", 0),
  513. };
  514. PCI_DRIVER ( w89c840_driver, w89c840_nics, PCI_NO_CLASS );
  515. /**************************************************************************
  516. w89c840_probe - Look for an adapter, this routine's visible to the outside
  517. ***************************************************************************/
  518. static int w89c840_probe ( struct nic *nic, struct pci_device *p ) {
  519. u16 sum = 0;
  520. int i, j;
  521. unsigned short value;
  522. if (p->ioaddr == 0)
  523. return 0;
  524. nic->ioaddr = p->ioaddr;
  525. nic->irqno = 0;
  526. #if defined(W89C840_DEBUG)
  527. printf("winbond-840: PCI bus %hhX device function %hhX: I/O address: %hX\n", p->bus, p->devfn, ioaddr);
  528. #endif
  529. ioaddr = ioaddr & ~3; /* Mask the bit that says "this is an io addr" */
  530. #define PCI_DEVICE_ID_WINBOND2_89C840 0x0840
  531. #define PCI_DEVICE_ID_COMPEX_RL100ATX 0x2011
  532. /* From Matt Hortman <mbhortman@acpthinclient.com> */
  533. if (p->vendor == PCI_VENDOR_ID_WINBOND2
  534. && p->device == PCI_DEVICE_ID_WINBOND2_89C840) {
  535. /* detected "Winbond W89c840 Fast Ethernet PCI NIC" */
  536. } else if ( p->vendor == PCI_VENDOR_ID_COMPEX
  537. && p->device == PCI_DEVICE_ID_COMPEX_RL100ATX) {
  538. /* detected "Compex RL100ATX Fast Ethernet PCI NIC" */
  539. } else {
  540. /* Gee, guess what? They missed again. */
  541. printf("device ID : %X - is not a Compex RL100ATX NIC.\n",
  542. p->device);
  543. return 0;
  544. }
  545. printf(" %s\n", w89c840_version);
  546. adjust_pci_device(p);
  547. /* Ok. Got one. Read the eeprom. */
  548. for (j = 0, i = 0; i < 0x40; i++) {
  549. value = eeprom_read(ioaddr, i);
  550. eeprom[i] = value;
  551. sum += value;
  552. }
  553. for (i=0;i<ETH_ALEN;i++) {
  554. nic->node_addr[i] = (eeprom[i/2] >> (8*(i&1))) & 0xff;
  555. }
  556. DBG ( "Ethernet addr: %s\n", eth_ntoa ( nic->node_addr ) );
  557. #if defined(W89C840_DEBUG)
  558. printf("winbond-840: EEPROM checksum %hX, got eeprom", sum);
  559. #endif
  560. /* Reset the chip to erase previous misconfiguration.
  561. No hold time required! */
  562. writel(0x00000001, ioaddr + PCIBusCfg);
  563. if (driver_flags & CanHaveMII) {
  564. int phy, phy_idx = 0;
  565. for (phy = 1; phy < 32 && phy_idx < 4; phy++) {
  566. int mii_status = mdio_read(ioaddr, phy, 1);
  567. if (mii_status != 0xffff && mii_status != 0x0000) {
  568. w840private.phys[phy_idx++] = phy;
  569. w840private.advertising = mdio_read(ioaddr, phy, 4);
  570. #if defined(W89C840_DEBUG)
  571. printf("winbond-840 : MII PHY found at address %d, status "
  572. "%X advertising %hX.\n", phy, mii_status, w840private.advertising);
  573. #endif
  574. }
  575. }
  576. w840private.mii_cnt = phy_idx;
  577. if (phy_idx == 0) {
  578. printf("winbond-840 : MII PHY not found -- this device may not operate correctly.\n");
  579. }
  580. }
  581. /* point to NIC specific routines */
  582. nic->nic_op = &w89c840_operations;
  583. w89c840_reset(nic);
  584. return 1;
  585. }
  586. /* Read the EEPROM and MII Management Data I/O (MDIO) interfaces. These are
  587. often serial bit streams generated by the host processor.
  588. The example below is for the common 93c46 EEPROM, 64 16 bit words. */
  589. /* Delay between EEPROM clock transitions.
  590. No extra delay is needed with 33Mhz PCI, but future 66Mhz access may need
  591. a delay. Note that pre-2.0.34 kernels had a cache-alignment bug that
  592. made udelay() unreliable.
  593. The old method of using an ISA access as a delay, __SLOW_DOWN_IO__, is
  594. depricated.
  595. */
  596. #define eeprom_delay(ee_addr) readl(ee_addr)
  597. enum EEPROM_Ctrl_Bits {
  598. EE_ShiftClk=0x02, EE_Write0=0x801, EE_Write1=0x805,
  599. EE_ChipSelect=0x801, EE_DataIn=0x08,
  600. };
  601. /* The EEPROM commands include the alway-set leading bit. */
  602. enum EEPROM_Cmds {
  603. EE_WriteCmd=(5 << 6), EE_ReadCmd=(6 << 6), EE_EraseCmd=(7 << 6),
  604. };
  605. static int eeprom_read(long addr, int location)
  606. {
  607. int i;
  608. int retval = 0;
  609. int ee_addr = addr + EECtrl;
  610. int read_cmd = location | EE_ReadCmd;
  611. writel(EE_ChipSelect, ee_addr);
  612. /* Shift the read command bits out. */
  613. for (i = 10; i >= 0; i--) {
  614. short dataval = (read_cmd & (1 << i)) ? EE_Write1 : EE_Write0;
  615. writel(dataval, ee_addr);
  616. eeprom_delay(ee_addr);
  617. writel(dataval | EE_ShiftClk, ee_addr);
  618. eeprom_delay(ee_addr);
  619. }
  620. writel(EE_ChipSelect, ee_addr);
  621. for (i = 16; i > 0; i--) {
  622. writel(EE_ChipSelect | EE_ShiftClk, ee_addr);
  623. eeprom_delay(ee_addr);
  624. retval = (retval << 1) | ((readl(ee_addr) & EE_DataIn) ? 1 : 0);
  625. writel(EE_ChipSelect, ee_addr);
  626. eeprom_delay(ee_addr);
  627. }
  628. /* Terminate the EEPROM access. */
  629. writel(0, ee_addr);
  630. return retval;
  631. }
  632. /* MII transceiver control section.
  633. Read and write the MII registers using software-generated serial
  634. MDIO protocol. See the MII specifications or DP83840A data sheet
  635. for details.
  636. The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
  637. met by back-to-back 33Mhz PCI cycles. */
  638. #define mdio_delay(mdio_addr) readl(mdio_addr)
  639. /* Set iff a MII transceiver on any interface requires mdio preamble.
  640. This only set with older tranceivers, so the extra
  641. code size of a per-interface flag is not worthwhile. */
  642. static char mii_preamble_required = 1;
  643. #define MDIO_WRITE0 (MDIO_EnbOutput)
  644. #define MDIO_WRITE1 (MDIO_DataOut | MDIO_EnbOutput)
  645. /* Generate the preamble required for initial synchronization and
  646. a few older transceivers. */
  647. static void mdio_sync(long mdio_addr)
  648. {
  649. int bits = 32;
  650. /* Establish sync by sending at least 32 logic ones. */
  651. while (--bits >= 0) {
  652. writel(MDIO_WRITE1, mdio_addr);
  653. mdio_delay(mdio_addr);
  654. writel(MDIO_WRITE1 | MDIO_ShiftClk, mdio_addr);
  655. mdio_delay(mdio_addr);
  656. }
  657. }
  658. static int mdio_read(int base_address, int phy_id, int location)
  659. {
  660. long mdio_addr = base_address + MIICtrl;
  661. int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location;
  662. int i, retval = 0;
  663. if (mii_preamble_required)
  664. mdio_sync(mdio_addr);
  665. /* Shift the read command bits out. */
  666. for (i = 15; i >= 0; i--) {
  667. int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
  668. writel(dataval, mdio_addr);
  669. mdio_delay(mdio_addr);
  670. writel(dataval | MDIO_ShiftClk, mdio_addr);
  671. mdio_delay(mdio_addr);
  672. }
  673. /* Read the two transition, 16 data, and wire-idle bits. */
  674. for (i = 20; i > 0; i--) {
  675. writel(MDIO_EnbIn, mdio_addr);
  676. mdio_delay(mdio_addr);
  677. retval = (retval << 1) | ((readl(mdio_addr) & MDIO_DataIn) ? 1 : 0);
  678. writel(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
  679. mdio_delay(mdio_addr);
  680. }
  681. return (retval>>1) & 0xffff;
  682. }
  683. #if 0
  684. static void mdio_write(int base_address, int phy_id, int location, int value)
  685. {
  686. long mdio_addr = base_address + MIICtrl;
  687. int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location<<18) | value;
  688. int i;
  689. if (location == 4 && phy_id == w840private.phys[0])
  690. w840private.advertising = value;
  691. if (mii_preamble_required)
  692. mdio_sync(mdio_addr);
  693. /* Shift the command bits out. */
  694. for (i = 31; i >= 0; i--) {
  695. int dataval = (mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0;
  696. writel(dataval, mdio_addr);
  697. mdio_delay(mdio_addr);
  698. writel(dataval | MDIO_ShiftClk, mdio_addr);
  699. mdio_delay(mdio_addr);
  700. }
  701. /* Clear out extra bits. */
  702. for (i = 2; i > 0; i--) {
  703. writel(MDIO_EnbIn, mdio_addr);
  704. mdio_delay(mdio_addr);
  705. writel(MDIO_EnbIn | MDIO_ShiftClk, mdio_addr);
  706. mdio_delay(mdio_addr);
  707. }
  708. return;
  709. }
  710. #endif
  711. static void check_duplex(void)
  712. {
  713. int mii_reg5 = mdio_read(ioaddr, w840private.phys[0], 5);
  714. int negotiated = mii_reg5 & w840private.advertising;
  715. int duplex;
  716. if (w840private.duplex_lock || mii_reg5 == 0xffff)
  717. return;
  718. duplex = (negotiated & 0x0100) || (negotiated & 0x01C0) == 0x0040;
  719. if (w840private.full_duplex != duplex) {
  720. w840private.full_duplex = duplex;
  721. #if defined(W89C840_DEBUG)
  722. printf("winbond-840 : Setting %s-duplex based on MII # %d negotiated capability %X\n",
  723. duplex ? "full" : "half", w840private.phys[0], negotiated);
  724. #endif
  725. w840private.csr6 &= ~0x200;
  726. w840private.csr6 |= duplex ? 0x200 : 0;
  727. }
  728. }
  729. static void set_rx_mode(void)
  730. {
  731. u32 mc_filter[2]; /* Multicast hash filter */
  732. u32 rx_mode;
  733. /* Accept all multicasts from now on. */
  734. memset(mc_filter, 0xff, sizeof(mc_filter));
  735. /*
  736. * works OK with multicast enabled.
  737. */
  738. rx_mode = AcceptBroadcast | AcceptMyPhys | AcceptMulticast;
  739. writel(mc_filter[0], ioaddr + MulticastFilter0);
  740. writel(mc_filter[1], ioaddr + MulticastFilter1);
  741. w840private.csr6 &= ~0x00F8;
  742. w840private.csr6 |= rx_mode;
  743. writel(w840private.csr6, ioaddr + NetworkConfig);
  744. #if defined(W89C840_DEBUG)
  745. printf("winbond-840 : Done setting RX mode.\n");
  746. #endif
  747. }
  748. /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
  749. static void init_ring(void)
  750. {
  751. int i;
  752. char * p;
  753. w840private.tx_full = 0;
  754. w840private.tx_q_bytes = w840private.cur_rx = w840private.cur_tx = 0;
  755. w840private.dirty_rx = w840private.dirty_tx = 0;
  756. w840private.rx_buf_sz = PKT_BUF_SZ;
  757. w840private.rx_head_desc = &w840private.rx_ring[0];
  758. /* Initial all Rx descriptors. Fill in the Rx buffers. */
  759. p = &w89c840_buf.rx_packet[0];
  760. for (i = 0; i < RX_RING_SIZE; i++) {
  761. w840private.rx_ring[i].length = w840private.rx_buf_sz;
  762. w840private.rx_ring[i].status = 0;
  763. w840private.rx_ring[i].next_desc = virt_to_le32desc(&w840private.rx_ring[i+1]);
  764. w840private.rx_ring[i].buffer1 = virt_to_le32desc(p + (PKT_BUF_SZ * i));
  765. w840private.rx_ring[i].status = DescOwn | DescIntr;
  766. }
  767. /* Mark the last entry as wrapping the ring. */
  768. w840private.rx_ring[i-1].length |= DescEndRing;
  769. w840private.rx_ring[i-1].next_desc = virt_to_le32desc(&w840private.rx_ring[0]);
  770. w840private.dirty_rx = (unsigned int)(i - RX_RING_SIZE);
  771. for (i = 0; i < TX_RING_SIZE; i++) {
  772. w840private.tx_ring[i].status = 0;
  773. }
  774. return;
  775. }
  776. DRIVER ( "W89C840F", nic_driver, pci_driver, w89c840_driver,
  777. w89c840_probe, w89c840_disable );
  778. /*
  779. * Local variables:
  780. * c-basic-offset: 8
  781. * c-indent-level: 8
  782. * tab-width: 8
  783. * End:
  784. */