1 /**************************************************************************
2 * ns83820.c: Etherboot device driver for the National Semiconductor 83820
3 * Written 2004 by Timothy Legge <tlegge@rogers.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Portions of this code based on:
20 * ns83820.c by Benjamin LaHaise with contributions
21 * for Linux kernel 2.4.x.
23 * Linux Driver Version 0.20, 20020610
25 * This development of this Etherboot driver was funded by:
27 * NXTV: http://www.nxtv.com/
32 * v1.0 02-16-2004 timlegge Initial port of Linux driver
33 * v1.1 02-19-2004 timlegge More rohbust transmit and poll
35 * Indent Options: indent -kr -i8
36 ***************************************************************************/
38 /* to get some global routines like printf */
39 #include "etherboot.h"
40 /* to get the interface to the body of the program */
42 /* to get the PCI support functions, if this is a PCI NIC */
45 #if ARCH == ia64 /* Support 64-bit addressing */
46 #define USE_64BIT_ADDR
51 #define dprintf(x) printf x
58 /* Condensed operations for readability. */
59 #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr))
60 #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr))
62 /* NIC specific static variables go here */
64 /* Global parameters. See MODULE_PARM near the bottom. */
65 // static int ihr = 2;
66 static int reset_phy = 0;
67 static int lnksts = 0; /* CFG_LNKSTS bit polarity */
69 #if defined(CONFIG_HIGHMEM64G) || defined(__ia64__)
70 #define USE_64BIT_ADDR "+"
73 #if defined(USE_64BIT_ADDR)
80 #define RX_BUF_SIZE 1500 /* 8192 */
82 /* Must not exceed ~65000. */
86 /* not tunable *//* Extra 6 bytes for 64 bit alignment (divisable by 8) */
87 #define REAL_RX_BUF_SIZE (RX_BUF_SIZE + 14 + 6) /* rx/tx mac addr + type */
89 #define MIN_TX_DESC_FREE 8
91 /* register defines */
94 #define CR_TXE 0x00000001
95 #define CR_TXD 0x00000002
96 /* Ramit : Here's a tip, don't do a RXD immediately followed by an RXE
97 * The Receive engine skips one descriptor and moves
98 * onto the next one!! */
99 #define CR_RXE 0x00000004
100 #define CR_RXD 0x00000008
101 #define CR_TXR 0x00000010
102 #define CR_RXR 0x00000020
103 #define CR_SWI 0x00000080
104 #define CR_RST 0x00000100
106 #define PTSCR_EEBIST_FAIL 0x00000001
107 #define PTSCR_EEBIST_EN 0x00000002
108 #define PTSCR_EELOAD_EN 0x00000004
109 #define PTSCR_RBIST_FAIL 0x000001b8
110 #define PTSCR_RBIST_DONE 0x00000200
111 #define PTSCR_RBIST_EN 0x00000400
112 #define PTSCR_RBIST_RST 0x00002000
114 #define MEAR_EEDI 0x00000001
115 #define MEAR_EEDO 0x00000002
116 #define MEAR_EECLK 0x00000004
117 #define MEAR_EESEL 0x00000008
118 #define MEAR_MDIO 0x00000010
119 #define MEAR_MDDIR 0x00000020
120 #define MEAR_MDC 0x00000040
122 #define ISR_TXDESC3 0x40000000
123 #define ISR_TXDESC2 0x20000000
124 #define ISR_TXDESC1 0x10000000
125 #define ISR_TXDESC0 0x08000000
126 #define ISR_RXDESC3 0x04000000
127 #define ISR_RXDESC2 0x02000000
128 #define ISR_RXDESC1 0x01000000
129 #define ISR_RXDESC0 0x00800000
130 #define ISR_TXRCMP 0x00400000
131 #define ISR_RXRCMP 0x00200000
132 #define ISR_DPERR 0x00100000
133 #define ISR_SSERR 0x00080000
134 #define ISR_RMABT 0x00040000
135 #define ISR_RTABT 0x00020000
136 #define ISR_RXSOVR 0x00010000
137 #define ISR_HIBINT 0x00008000
138 #define ISR_PHY 0x00004000
139 #define ISR_PME 0x00002000
140 #define ISR_SWI 0x00001000
141 #define ISR_MIB 0x00000800
142 #define ISR_TXURN 0x00000400
143 #define ISR_TXIDLE 0x00000200
144 #define ISR_TXERR 0x00000100
145 #define ISR_TXDESC 0x00000080
146 #define ISR_TXOK 0x00000040
147 #define ISR_RXORN 0x00000020
148 #define ISR_RXIDLE 0x00000010
149 #define ISR_RXEARLY 0x00000008
150 #define ISR_RXERR 0x00000004
151 #define ISR_RXDESC 0x00000002
152 #define ISR_RXOK 0x00000001
154 #define TXCFG_CSI 0x80000000
155 #define TXCFG_HBI 0x40000000
156 #define TXCFG_MLB 0x20000000
157 #define TXCFG_ATP 0x10000000
158 #define TXCFG_ECRETRY 0x00800000
159 #define TXCFG_BRST_DIS 0x00080000
160 #define TXCFG_MXDMA1024 0x00000000
161 #define TXCFG_MXDMA512 0x00700000
162 #define TXCFG_MXDMA256 0x00600000
163 #define TXCFG_MXDMA128 0x00500000
164 #define TXCFG_MXDMA64 0x00400000
165 #define TXCFG_MXDMA32 0x00300000
166 #define TXCFG_MXDMA16 0x00200000
167 #define TXCFG_MXDMA8 0x00100000
169 #define CFG_LNKSTS 0x80000000
170 #define CFG_SPDSTS 0x60000000
171 #define CFG_SPDSTS1 0x40000000
172 #define CFG_SPDSTS0 0x20000000
173 #define CFG_DUPSTS 0x10000000
174 #define CFG_TBI_EN 0x01000000
175 #define CFG_MODE_1000 0x00400000
176 /* Ramit : Dont' ever use AUTO_1000, it never works and is buggy.
177 * Read the Phy response and then configure the MAC accordingly */
178 #define CFG_AUTO_1000 0x00200000
179 #define CFG_PINT_CTL 0x001c0000
180 #define CFG_PINT_DUPSTS 0x00100000
181 #define CFG_PINT_LNKSTS 0x00080000
182 #define CFG_PINT_SPDSTS 0x00040000
183 #define CFG_TMRTEST 0x00020000
184 #define CFG_MRM_DIS 0x00010000
185 #define CFG_MWI_DIS 0x00008000
186 #define CFG_T64ADDR 0x00004000
187 #define CFG_PCI64_DET 0x00002000
188 #define CFG_DATA64_EN 0x00001000
189 #define CFG_M64ADDR 0x00000800
190 #define CFG_PHY_RST 0x00000400
191 #define CFG_PHY_DIS 0x00000200
192 #define CFG_EXTSTS_EN 0x00000100
193 #define CFG_REQALG 0x00000080
194 #define CFG_SB 0x00000040
195 #define CFG_POW 0x00000020
196 #define CFG_EXD 0x00000010
197 #define CFG_PESEL 0x00000008
198 #define CFG_BROM_DIS 0x00000004
199 #define CFG_EXT_125 0x00000002
200 #define CFG_BEM 0x00000001
202 #define EXTSTS_UDPPKT 0x00200000
203 #define EXTSTS_TCPPKT 0x00080000
204 #define EXTSTS_IPPKT 0x00020000
206 #define SPDSTS_POLARITY (CFG_SPDSTS1 | CFG_SPDSTS0 | CFG_DUPSTS | (lnksts ? CFG_LNKSTS : 0))
208 #define MIBC_MIBS 0x00000008
209 #define MIBC_ACLR 0x00000004
210 #define MIBC_FRZ 0x00000002
211 #define MIBC_WRN 0x00000001
213 #define PCR_PSEN (1 << 31)
214 #define PCR_PS_MCAST (1 << 30)
215 #define PCR_PS_DA (1 << 29)
216 #define PCR_STHI_8 (3 << 23)
217 #define PCR_STLO_4 (1 << 23)
218 #define PCR_FFHI_8K (3 << 21)
219 #define PCR_FFLO_4K (1 << 21)
220 #define PCR_PAUSE_CNT 0xFFFE
222 #define RXCFG_AEP 0x80000000
223 #define RXCFG_ARP 0x40000000
224 #define RXCFG_STRIPCRC 0x20000000
225 #define RXCFG_RX_FD 0x10000000
226 #define RXCFG_ALP 0x08000000
227 #define RXCFG_AIRL 0x04000000
228 #define RXCFG_MXDMA512 0x00700000
229 #define RXCFG_DRTH 0x0000003e
230 #define RXCFG_DRTH0 0x00000002
232 #define RFCR_RFEN 0x80000000
233 #define RFCR_AAB 0x40000000
234 #define RFCR_AAM 0x20000000
235 #define RFCR_AAU 0x10000000
236 #define RFCR_APM 0x08000000
237 #define RFCR_APAT 0x07800000
238 #define RFCR_APAT3 0x04000000
239 #define RFCR_APAT2 0x02000000
240 #define RFCR_APAT1 0x01000000
241 #define RFCR_APAT0 0x00800000
242 #define RFCR_AARP 0x00400000
243 #define RFCR_MHEN 0x00200000
244 #define RFCR_UHEN 0x00100000
245 #define RFCR_ULM 0x00080000
247 #define VRCR_RUDPE 0x00000080
248 #define VRCR_RTCPE 0x00000040
249 #define VRCR_RIPE 0x00000020
250 #define VRCR_IPEN 0x00000010
251 #define VRCR_DUTF 0x00000008
252 #define VRCR_DVTF 0x00000004
253 #define VRCR_VTREN 0x00000002
254 #define VRCR_VTDEN 0x00000001
256 #define VTCR_PPCHK 0x00000008
257 #define VTCR_GCHK 0x00000004
258 #define VTCR_VPPTI 0x00000002
259 #define VTCR_VGTI 0x00000001
296 #define TBICR_MR_AN_ENABLE 0x00001000
297 #define TBICR_MR_RESTART_AN 0x00000200
299 #define TBISR_MR_LINK_STATUS 0x00000020
300 #define TBISR_MR_AN_COMPLETE 0x00000004
302 #define TANAR_PS2 0x00000100
303 #define TANAR_PS1 0x00000080
304 #define TANAR_HALF_DUP 0x00000040
305 #define TANAR_FULL_DUP 0x00000020
307 #define GPIOR_GP5_OE 0x00000200
308 #define GPIOR_GP4_OE 0x00000100
309 #define GPIOR_GP3_OE 0x00000080
310 #define GPIOR_GP2_OE 0x00000040
311 #define GPIOR_GP1_OE 0x00000020
312 #define GPIOR_GP3_OUT 0x00000004
313 #define GPIOR_GP1_OUT 0x00000001
315 #define LINK_AUTONEGOTIATE 0x01
316 #define LINK_DOWN 0x02
320 #define __kick_rx() writel(CR_RXE, ns->base + CR)
322 #define kick_rx() do { \
323 dprintf(("kick_rx: maybe kicking\n")); \
324 writel(virt_to_le32desc(&rx_ring[ns->cur_rx]), ns->base + RXDP); \
325 if (ns->next_rx == ns->next_empty) \
326 printf("uh-oh: next_rx == next_empty???\n"); \
331 #ifdef USE_64BIT_ADDR
332 #define HW_ADDR_LEN 8
334 #define HW_ADDR_LEN 4
337 #define CMDSTS_OWN 0x80000000
338 #define CMDSTS_MORE 0x40000000
339 #define CMDSTS_INTR 0x20000000
340 #define CMDSTS_ERR 0x10000000
341 #define CMDSTS_OK 0x08000000
342 #define CMDSTS_LEN_MASK 0x0000ffff
344 #define CMDSTS_DEST_MASK 0x01800000
345 #define CMDSTS_DEST_SELF 0x00800000
346 #define CMDSTS_DEST_MULTI 0x01000000
348 #define DESC_SIZE 8 /* Should be cache line sized */
350 #ifdef USE_64BIT_ADDR
355 u32 extsts; /* Extended status field */
362 u32 extsts; /* Extended status field */
366 /* Private Storage for the NIC */
367 struct ns83820_private {
372 u16 next_rx, next_empty;
387 static struct ns83820_private *ns;
389 /* Define the TX and RX Descriptor and Buffers */
391 struct ring_desc tx_ring[NR_TX_DESC] __attribute__ ((aligned(8)));
392 unsigned char txb[NR_TX_DESC * REAL_RX_BUF_SIZE];
393 struct ring_desc rx_ring[NR_RX_DESC] __attribute__ ((aligned(8)));
394 unsigned char rxb[NR_RX_DESC * REAL_RX_BUF_SIZE]
395 __attribute__ ((aligned(8)));
396 } ns83820_bufs __shared;
397 #define tx_ring ns83820_bufs.tx_ring
398 #define rx_ring ns83820_bufs.rx_ring
399 #define txb ns83820_bufs.txb
400 #define rxb ns83820_bufs.rxb
402 static void phy_intr(struct nic *nic __unused)
404 static char *speeds[] =
405 { "10", "100", "1000", "1000(?)", "1000F" };
407 u32 tbisr, tanar, tanlpar;
408 int speed, fullduplex, newlinkstate;
410 cfg = readl(ns->base + CFG) ^ SPDSTS_POLARITY;
411 if (ns->CFG_cache & CFG_TBI_EN) {
412 /* we have an optical transceiver */
413 tbisr = readl(ns->base + TBISR);
414 tanar = readl(ns->base + TANAR);
415 tanlpar = readl(ns->base + TANLPAR);
416 dprintf(("phy_intr: tbisr=%hX, tanar=%hX, tanlpar=%hX\n",
417 tbisr, tanar, tanlpar));
419 if ((fullduplex = (tanlpar & TANAR_FULL_DUP)
420 && (tanar & TANAR_FULL_DUP))) {
422 /* both of us are full duplex */
423 writel(readl(ns->base + TXCFG)
424 | TXCFG_CSI | TXCFG_HBI | TXCFG_ATP,
426 writel(readl(ns->base + RXCFG) | RXCFG_RX_FD,
428 /* Light up full duplex LED */
429 writel(readl(ns->base + GPIOR) | GPIOR_GP1_OUT,
432 } else if (((tanlpar & TANAR_HALF_DUP)
433 && (tanar & TANAR_HALF_DUP))
434 || ((tanlpar & TANAR_FULL_DUP)
435 && (tanar & TANAR_HALF_DUP))
436 || ((tanlpar & TANAR_HALF_DUP)
437 && (tanar & TANAR_FULL_DUP))) {
439 /* one or both of us are half duplex */
440 writel((readl(ns->base + TXCFG)
441 & ~(TXCFG_CSI | TXCFG_HBI)) | TXCFG_ATP,
443 writel(readl(ns->base + RXCFG) & ~RXCFG_RX_FD,
445 /* Turn off full duplex LED */
446 writel(readl(ns->base + GPIOR) & ~GPIOR_GP1_OUT,
450 speed = 4; /* 1000F */
453 /* we have a copper transceiver */
455 ns->CFG_cache & ~(CFG_SB | CFG_MODE_1000 | CFG_SPDSTS);
457 if (cfg & CFG_SPDSTS1)
458 new_cfg |= CFG_MODE_1000;
460 new_cfg &= ~CFG_MODE_1000;
462 speed = ((cfg / CFG_SPDSTS0) & 3);
463 fullduplex = (cfg & CFG_DUPSTS);
468 if ((cfg & CFG_LNKSTS) &&
469 ((new_cfg ^ ns->CFG_cache) & CFG_MODE_1000)) {
470 writel(new_cfg, ns->base + CFG);
471 ns->CFG_cache = new_cfg;
474 ns->CFG_cache &= ~CFG_SPDSTS;
475 ns->CFG_cache |= cfg & CFG_SPDSTS;
478 newlinkstate = (cfg & CFG_LNKSTS) ? LINK_UP : LINK_DOWN;
480 if (newlinkstate & LINK_UP && ns->linkstate != newlinkstate) {
481 printf("link now %s mbps, %s duplex and up.\n",
482 speeds[speed], fullduplex ? "full" : "half");
483 } else if (newlinkstate & LINK_DOWN
484 && ns->linkstate != newlinkstate) {
485 printf("link now down.\n");
487 ns->linkstate = newlinkstate;
489 static void ns83820_set_multicast(struct nic *nic __unused);
490 static void ns83820_setup_rx(struct nic *nic)
495 ns->next_rx_desc = ns->descs;
500 for (i = 0; i < NR_RX_DESC; i++) {
501 rx_ring[i].link = virt_to_le32desc(&rx_ring[i + 1]);
503 virt_to_le32desc(&rxb[i * REAL_RX_BUF_SIZE]);
504 rx_ring[i].cmdsts = cpu_to_le32(REAL_RX_BUF_SIZE);
505 rx_ring[i].extsts = cpu_to_le32(0);
507 // No need to wrap the ring
508 // rx_ring[i].link = virt_to_le32desc(&rx_ring[0]);
509 writel(0, ns->base + RXDP_HI);
510 writel(virt_to_le32desc(&rx_ring[0]), ns->base + RXDP);
512 dprintf(("starting receiver\n"));
514 writel(0x0001, ns->base + CCSR);
515 writel(0, ns->base + RFCR);
516 writel(0x7fc00000, ns->base + RFCR);
517 writel(0xffc00000, ns->base + RFCR);
523 /* Okay, let it rip */
524 ns->IMR_cache |= ISR_PHY;
525 ns->IMR_cache |= ISR_RXRCMP;
526 //dev->IMR_cache |= ISR_RXERR;
527 //dev->IMR_cache |= ISR_RXOK;
528 ns->IMR_cache |= ISR_RXORN;
529 ns->IMR_cache |= ISR_RXSOVR;
530 ns->IMR_cache |= ISR_RXDESC;
531 ns->IMR_cache |= ISR_RXIDLE;
532 ns->IMR_cache |= ISR_TXDESC;
533 ns->IMR_cache |= ISR_TXIDLE;
535 // No reason to enable interupts...
536 // writel(ns->IMR_cache, ns->base + IMR);
537 // writel(1, ns->base + IER);
538 ns83820_set_multicast(nic);
543 static void ns83820_do_reset(struct nic *nic __unused, u32 which)
545 dprintf(("resetting chip...\n"));
546 writel(which, ns->base + CR);
549 } while (readl(ns->base + CR) & which);
550 dprintf(("okay!\n"));
553 static void ns83820_reset(struct nic *nic)
556 dprintf(("ns83820_reset\n"));
558 writel(0, ns->base + PQCR);
560 ns83820_setup_rx(nic);
562 for (i = 0; i < NR_TX_DESC; i++) {
564 tx_ring[i].bufptr = 0;
565 tx_ring[i].cmdsts = cpu_to_le32(0);
566 tx_ring[i].extsts = cpu_to_le32(0);
571 writel(0, ns->base + TXDP_HI);
574 static void ns83820_getmac(struct nic *nic __unused, u8 * mac)
577 for (i = 0; i < 3; i++) {
579 /* Read from the perfect match memory: this is loaded by
580 * the chip from the EEPROM via the EELOAD self test.
582 writel(i * 2, ns->base + RFCR);
583 data = readl(ns->base + RFDR);
589 static void ns83820_set_multicast(struct nic *nic __unused)
591 u8 *rfcr = ns->base + RFCR;
592 u32 and_mask = 0xffffffff;
596 /* Support Multicast */
597 and_mask &= ~(RFCR_AAU | RFCR_AAM);
599 val = (readl(rfcr) & and_mask) | or_mask;
600 /* Ramit : RFCR Write Fix doc says RFEN must be 0 modify other bits */
601 writel(val & ~RFCR_RFEN, rfcr);
605 static void ns83820_run_bist(struct nic *nic __unused, const char *name,
606 u32 enable, u32 done, u32 fail)
613 dprintf(("start %s\n", name))
617 writel(enable, ns->base + PTSCR);
620 status = readl(ns->base + PTSCR);
621 if (!(status & enable))
627 if ((currticks() - start) >= HZ) {
634 printf("%s failed! (0x%hX & 0x%hX)\n", name, status, fail);
636 printf("run_bist %s timed out! (%hX)\n", name, status);
637 dprintf(("done %s in %d loops\n", name, loops));
640 /*************************************
642 *************************************/
643 static void ns83820_check_intr(struct nic *nic) {
645 u32 isr = readl(ns->base + ISR);
648 if(( ISR_RXIDLE | ISR_RXDESC | ISR_RXERR) & isr)
650 for (i = 0; i < NR_RX_DESC; i++) {
651 if (rx_ring[i].cmdsts == CMDSTS_OWN) {
652 // rx_ring[i].link = virt_to_le32desc(&rx_ring[i + 1]);
653 rx_ring[i].cmdsts = cpu_to_le32(REAL_RX_BUF_SIZE);
657 /**************************************************************************
658 POLL - Wait for a frame
659 ***************************************************************************/
660 static int ns83820_poll(struct nic *nic, int retrieve)
662 /* return true if there's an ethernet packet ready to read */
663 /* nic->packet should contain data on return */
664 /* nic->packetlen should contain length of data */
666 int entry = ns->cur_rx;
668 ns83820_check_intr(nic);
670 cmdsts = le32_to_cpu(rx_ring[entry].cmdsts);
672 if ( ! ( (CMDSTS_OWN & (cmdsts)) && (cmdsts != (CMDSTS_OWN)) ) )
675 if ( ! retrieve ) return 1;
677 if (! (CMDSTS_OK & cmdsts) )
680 nic->packetlen = cmdsts & 0xffff;
682 rxb + (entry * REAL_RX_BUF_SIZE),
684 // rx_ring[entry].link = 0;
685 rx_ring[entry].cmdsts = cpu_to_le32(CMDSTS_OWN);
687 ns->cur_rx = ++ns->cur_rx % NR_RX_DESC;
689 if (ns->cur_rx == 0) /* We have wrapped the ring */
695 static inline void kick_tx(struct nic *nic __unused)
697 dprintf(("kick_tx\n"));
698 writel(CR_TXE, ns->base + CR);
701 /**************************************************************************
702 TRANSMIT - Transmit a frame
703 ***************************************************************************/
704 static void ns83820_transmit(struct nic *nic, const char *d, /* Destination */
705 unsigned int t, /* Type */
706 unsigned int s, /* size */
709 /* send the packet to destination */
714 u32 isr = readl(ns->base + ISR);
715 if (ISR_TXIDLE & isr)
717 /* point to the current txb incase multiple tx_rings are used */
718 memcpy(txb, d, ETH_ALEN);
719 memcpy(txb + ETH_ALEN, nic->node_addr, ETH_ALEN);
720 nstype = htons((u16) t);
721 memcpy(txb + 2 * ETH_ALEN, (u8 *) & nstype, 2);
722 memcpy(txb + ETH_HLEN, p, s);
728 /* Setup the transmit descriptor */
730 extsts |= EXTSTS_UDPPKT;
732 tx_ring[cur_tx].bufptr = virt_to_le32desc(&txb);
733 tx_ring[cur_tx].extsts = cpu_to_le32(extsts);
735 cmdsts = cpu_to_le32(0);
736 cmdsts |= cpu_to_le32(CMDSTS_OWN | s);
737 tx_ring[cur_tx].cmdsts = cpu_to_le32(cmdsts);
739 writel(virt_to_le32desc(&tx_ring[0]), ns->base + TXDP);
743 /**************************************************************************
744 DISABLE - Turn off ethernet interface
745 ***************************************************************************/
746 static void ns83820_disable ( struct nic *nic ) {
748 /* put the card in its initial state */
749 /* This function serves 3 purposes.
750 * This disables DMA and interrupts so we don't receive
751 * unexpected packets or interrupts from the card after
752 * etherboot has finished.
753 * This frees resources so etherboot may use
754 * this driver on another interface
755 * This allows etherboot to reinitialize the interface
756 * if something is something goes wrong.
758 /* disable interrupts */
759 writel(0, ns->base + IMR);
760 writel(0, ns->base + IER);
761 readl(ns->base + IER);
765 ns83820_do_reset(nic, CR_RST);
768 ~(ISR_RXOK | ISR_RXDESC | ISR_RXERR | ISR_RXEARLY |
770 writel(ns->IMR_cache, ns->base + IMR);
772 /* touch the pci bus... */
773 readl(ns->base + IMR);
775 /* assumes the transmitter is already disabled and reset */
776 writel(0, ns->base + RXDP_HI);
777 writel(0, ns->base + RXDP);
780 /**************************************************************************
781 IRQ - Enable, Disable, or Force interrupts
782 ***************************************************************************/
783 static void ns83820_irq(struct nic *nic __unused, irq_action_t action __unused)
795 static struct nic_operations ns83820_operations = {
796 .connect = dummy_connect,
797 .poll = ns83820_poll,
798 .transmit = ns83820_transmit,
803 static struct pci_device_id ns83820_nics[] = {
804 PCI_ROM(0x100b, 0x0022, "ns83820", "National Semiconductor 83820"),
807 PCI_DRIVER ( ns83820_driver, ns83820_nics, PCI_NO_CLASS );
809 /**************************************************************************
810 PROBE - Look for an adapter, this routine's visible to the outside
811 ***************************************************************************/
813 #define board_found 1
815 static int ns83820_probe ( struct nic *nic, struct pci_device *pci ) {
820 if (pci->ioaddr == 0)
823 printf("ns83820.c: Found %s, vendor=0x%hX, device=0x%hX\n",
824 pci->name, pci->vendor, pci->device);
826 /* point to private storage */
829 adjust_pci_device(pci);
831 addr = pci_bar_start(pci, PCI_BASE_ADDRESS_1);
833 ns->base = ioremap(addr, (1UL << 12));
839 pci_fill_nic ( nic, pci );
840 nic->ioaddr = pci->ioaddr & ~3;
842 /* disable interrupts */
843 writel(0, ns->base + IMR);
844 writel(0, ns->base + IER);
845 readl(ns->base + IER);
849 ns83820_do_reset(nic, CR_RST);
851 /* Must reset the ram bist before running it */
852 writel(PTSCR_RBIST_RST, ns->base + PTSCR);
853 ns83820_run_bist(nic, "sram bist", PTSCR_RBIST_EN,
854 PTSCR_RBIST_DONE, PTSCR_RBIST_FAIL);
855 ns83820_run_bist(nic, "eeprom bist", PTSCR_EEBIST_EN, 0,
857 ns83820_run_bist(nic, "eeprom load", PTSCR_EELOAD_EN, 0, 0);
859 /* I love config registers */
860 ns->CFG_cache = readl(ns->base + CFG);
862 if ((ns->CFG_cache & CFG_PCI64_DET)) {
863 printf("%s: detected 64 bit PCI data bus.\n", pci->name);
864 /*dev->CFG_cache |= CFG_DATA64_EN; */
865 if (!(ns->CFG_cache & CFG_DATA64_EN))
867 ("%s: EEPROM did not enable 64 bit bus. Disabled.\n",
870 ns->CFG_cache &= ~(CFG_DATA64_EN);
872 ns->CFG_cache &= (CFG_TBI_EN | CFG_MRM_DIS | CFG_MWI_DIS |
873 CFG_T64ADDR | CFG_DATA64_EN | CFG_EXT_125 |
876 CFG_PINT_DUPSTS | CFG_PINT_LNKSTS | CFG_PINT_SPDSTS |
877 CFG_EXTSTS_EN | CFG_EXD | CFG_PESEL;
878 ns->CFG_cache |= CFG_REQALG;
879 ns->CFG_cache |= CFG_POW;
880 ns->CFG_cache |= CFG_TMRTEST;
882 /* When compiled with 64 bit addressing, we must always enable
883 * the 64 bit descriptor format.
885 #ifdef USE_64BIT_ADDR
886 ns->CFG_cache |= CFG_M64ADDR;
889 //FIXME: Enable section on dac or remove this
891 ns->CFG_cache |= CFG_T64ADDR;
893 /* Big endian mode does not seem to do what the docs suggest */
894 ns->CFG_cache &= ~CFG_BEM;
896 /* setup optical transceiver if we have one */
897 if (ns->CFG_cache & CFG_TBI_EN) {
898 dprintf(("%s: enabling optical transceiver\n", pci->name));
899 writel(readl(ns->base + GPIOR) | 0x3e8, ns->base + GPIOR);
901 /* setup auto negotiation feature advertisement */
902 writel(readl(ns->base + TANAR)
903 | TANAR_HALF_DUP | TANAR_FULL_DUP,
906 /* start auto negotiation */
907 writel(TBICR_MR_AN_ENABLE | TBICR_MR_RESTART_AN,
909 writel(TBICR_MR_AN_ENABLE, ns->base + TBICR);
910 ns->linkstate = LINK_AUTONEGOTIATE;
912 ns->CFG_cache |= CFG_MODE_1000;
914 writel(ns->CFG_cache, ns->base + CFG);
915 dprintf(("CFG: %hX\n", ns->CFG_cache));
917 /* FIXME: reset_phy is defaulted to 0, should we reset anyway? */
919 dprintf(("%s: resetting phy\n", pci->name));
920 writel(ns->CFG_cache | CFG_PHY_RST, ns->base + CFG);
921 writel(ns->CFG_cache, ns->base + CFG);
923 #if 0 /* Huh? This sets the PCI latency register. Should be done via
924 * the PCI layer. FIXME.
926 if (readl(dev->base + SRR))
927 writel(readl(dev->base + 0x20c) | 0xfe00,
931 /* Note! The DMA burst size interacts with packet
932 * transmission, such that the largest packet that
933 * can be transmitted is 8192 - FLTH - burst size.
934 * If only the transmit fifo was larger...
936 /* Ramit : 1024 DMA is not a good idea, it ends up banging
937 * some DELL and COMPAQ SMP systems */
938 writel(TXCFG_CSI | TXCFG_HBI | TXCFG_ATP | TXCFG_MXDMA512
939 | ((1600 / 32) * 0x100), ns->base + TXCFG);
941 /* Set Rx to full duplex, don't accept runt, errored, long or length
942 * range errored packets. Use 512 byte DMA.
944 /* Ramit : 1024 DMA is not a good idea, it ends up banging
945 * some DELL and COMPAQ SMP systems
946 * Turn on ALP, only we are accpeting Jumbo Packets */
947 writel(RXCFG_AEP | RXCFG_ARP | RXCFG_AIRL | RXCFG_RX_FD
950 | (RXCFG_MXDMA512) | 0, ns->base + RXCFG);
952 /* Disable priority queueing */
953 writel(0, ns->base + PQCR);
955 /* Enable IP checksum validation and detetion of VLAN headers.
956 * Note: do not set the reject options as at least the 0x102
957 * revision of the chip does not properly accept IP fragments
960 /* Ramit : Be sure to turn on RXCFG_ARP if VLAN's are enabled, since
961 * the MAC it calculates the packetsize AFTER stripping the VLAN
962 * header, and if a VLAN Tagged packet of 64 bytes is received (like
963 * a ping with a VLAN header) then the card, strips the 4 byte VLAN
964 * tag and then checks the packet size, so if RXCFG_ARP is not enabled,
965 * it discrards it!. These guys......
967 writel(VRCR_IPEN | VRCR_VTDEN, ns->base + VRCR);
969 /* Enable per-packet TCP/UDP/IP checksumming */
970 writel(VTCR_PPCHK, ns->base + VTCR);
972 /* Ramit : Enable async and sync pause frames */
973 // writel(0, ns->base + PCR);
974 writel((PCR_PS_MCAST | PCR_PS_DA | PCR_PSEN | PCR_FFLO_4K |
975 PCR_FFHI_8K | PCR_STLO_4 | PCR_STHI_8 | PCR_PAUSE_CNT),
978 /* Disable Wake On Lan */
979 writel(0, ns->base + WCSR);
981 ns83820_getmac(nic, nic->node_addr);
984 dprintf(("%s: using 64 bit addressing.\n", pci->name));
987 dprintf(("%s: DP83820 %d.%d: %! io=0x%hX\n",
989 (unsigned) readl(ns->base + SRR) >> 8,
990 (unsigned) readl(ns->base + SRR) & 0xff,
991 nic->node_addr, pci->ioaddr));
993 #ifdef PHY_CODE_IS_FINISHED
994 ns83820_probe_phy(dev);
998 /* point to NIC specific routines */
999 nic->nic_op = &ns83820_operations;
1003 DRIVER ( "NS83820/PCI", nic_driver, pci_driver, ns83820_driver,
1004 ns83820_probe, ns83820_disable );