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.

w89c840.c 30KB

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