1 /* 2 ** File: ne.c Jun. 08, 2000 3 ** 4 ** Driver for the NE*000 ethernet cards and derivates. 5 ** This file contains only the ne specific code, 6 ** the rest is in 8390.c Code specific for ISA bus only 7 ** 8 ** Created: March 15, 1994 by Philip Homburg <philip@cs.vu.nl> 9 ** PchId: ne2000.c,v 1.4 1996/01/19 23:30:34 philip Exp 10 ** 11 ** Modified: Jun. 08, 2000 by Giovanni Falzoni <gfalzoni@inwind.it> 12 ** Adapted to interface new main network task. 13 */ 14 15 #include <minix/drivers.h> 16 #include <net/gen/ether.h> 17 #include <net/gen/eth_io.h> 18 #include "dp.h" 19 20 #if (ENABLE_NE2000 == 1) 21 22 #include "8390.h" 23 #include "ne.h" 24 25 /* 26 ** Name: void ne_reset(dpeth_t * dep); 27 ** Function: Resets the board and checks if reset cycle completes 28 */ 29 static int ne_reset(dpeth_t * dep) 30 { 31 int count = 0; 32 33 /* Reset the ethernet card */ 34 outb_ne(dep, NE_RESET, inb_ne(dep, NE_RESET)); 35 do { 36 if (++count > 10) return FALSE; /* 20 mSecs. timeout */ 37 milli_delay(2); 38 } while ((inb_ne(dep, DP_ISR) & ISR_RST) == 0); 39 return TRUE; 40 } 41 42 /* 43 ** Name: void ne_close(dpeth_t * dep); 44 ** Function: Stops the board by resetting it and masking interrupts. 45 */ 46 static void ne_close(dpeth_t * dep) 47 { 48 49 (void)ne_reset(dep); 50 outb_ne(dep, DP_ISR, 0xFF); 51 sys_irqdisable(&dep->de_hook); 52 return; 53 } 54 55 /* 56 ** Name: void ne_init(dpeth_t * dep); 57 ** Function: Initialize the board making it ready to work. 58 */ 59 static void ne_init(dpeth_t * dep) 60 { 61 int ix; 62 63 dep->de_data_port = dep->de_base_port + NE_DATA; 64 if (dep->de_16bit) { 65 dep->de_ramsize = NE2000_SIZE; 66 dep->de_offset_page = NE2000_START / DP_PAGESIZE; 67 } else { 68 dep->de_ramsize = NE1000_SIZE; 69 dep->de_offset_page = NE1000_START / DP_PAGESIZE; 70 } 71 72 /* Allocates two send buffers from onboard RAM */ 73 dep->de_sendq_nr = SENDQ_NR; 74 for (ix = 0; ix < SENDQ_NR; ix += 1) { 75 dep->de_sendq[ix].sq_sendpage = dep->de_offset_page + ix * SENDQ_PAGES; 76 } 77 78 /* Remaining onboard RAM allocated for receiving */ 79 dep->de_startpage = dep->de_offset_page + ix * SENDQ_PAGES; 80 dep->de_stoppage = dep->de_offset_page + dep->de_ramsize / DP_PAGESIZE; 81 82 /* Can't override the default IRQ. */ 83 dep->de_irq &= NOT(DEI_DEFAULT); 84 85 ns_init(dep); /* Initialize DP controller */ 86 87 printf("%s: NE%d000 (%dkB RAM) at %X:%d - ", 88 dep->de_name, 89 dep->de_16bit ? 2 : 1, 90 dep->de_ramsize / 1024, 91 dep->de_base_port, dep->de_irq); 92 for (ix = 0; ix < SA_ADDR_LEN; ix += 1) 93 printf("%02X%c", dep->de_address.ea_addr[ix], ix < SA_ADDR_LEN - 1 ? ':' : '\n'); 94 return; 95 } 96 97 /* 98 ** Name: int ne_probe(dpeth_t * dep); 99 ** Function: Probe for the presence of a NE*000 card by testing 100 ** whether the board is reachable through the dp8390. 101 ** Note that the NE1000 is an 8bit card and has a memory 102 ** region distict from the 16bit NE2000. 103 */ 104 int ne_probe(dpeth_t * dep) 105 { 106 int ix, wd, loc1, loc2; 107 char EPROM[32]; 108 static const struct { 109 unsigned char offset; 110 unsigned char value; 111 } InitSeq[] = 112 { 113 { /* Selects page 0. */ 114 DP_CR, (CR_NO_DMA | CR_PS_P0 | CR_STP), 115 }, 116 { /* Set byte-wide access and 8 bytes burst mode. */ 117 DP_DCR, (DCR_8BYTES | DCR_BMS), 118 }, 119 { /* Clears the count registers. */ 120 DP_RBCR0, 0x00, }, { DP_RBCR1, 0x00, 121 }, 122 { /* Mask completion irq. */ 123 DP_IMR, 0x00, }, { DP_ISR, 0xFF, 124 }, 125 { /* Set receiver to monitor */ 126 DP_RCR, RCR_MON, 127 }, 128 { /* and transmitter to loopback mode. */ 129 DP_TCR, TCR_INTERNAL, 130 }, 131 { /* Transmit 32 bytes */ 132 DP_RBCR0, 32, }, { DP_RBCR1, 0, 133 }, 134 { /* DMA starting at 0x0000. */ 135 DP_RSAR0, 0x00, }, { DP_RSAR1, 0x00, 136 }, 137 { /* Start board (reads) */ 138 DP_CR, (CR_PS_P0 | CR_DM_RR | CR_STA), 139 }, 140 }; 141 142 dep->de_dp8390_port = dep->de_base_port + NE_DP8390; 143 144 if ((loc1 = inb_ne(dep, NE_DP8390)) == 0xFF) return FALSE; 145 146 /* Check if the dp8390 is really there */ 147 outb_ne(dep, DP_CR, CR_STP | CR_NO_DMA | CR_PS_P1); 148 loc2 = inb_ne(dep, DP_MAR5); /* Saves one byte of the address */ 149 outb_ne(dep, DP_MAR5, 0xFF); /* Write 0xFF to it (same offset as DP_CNTR0) */ 150 outb_ne(dep, DP_CR, CR_NO_DMA | CR_PS_P0); /* Back to page 0 */ 151 inb_ne(dep, DP_CNTR0); /* Reading counter resets it */ 152 if (inb_ne(dep, DP_CNTR0) != 0) { 153 outb_ne(dep, NE_DP8390, loc1); /* Try to restore modified bytes */ 154 outb_ne(dep, DP_TCR, loc2); 155 return FALSE; 156 } 157 158 /* Try to reset the board */ 159 if (ne_reset(dep) == FALSE) return FALSE; 160 161 /* Checks whether the board is 8/16bits and a real NE*000 or clone */ 162 for (ix = 0; ix < sizeof(InitSeq)/sizeof(InitSeq[0]); ix += 1) { 163 outb_ne(dep, InitSeq[ix].offset, InitSeq[ix].value); 164 } 165 for (ix = 0, wd = 1; ix < 32; ix += 2) { 166 EPROM[ix + 0] = inb_ne(dep, NE_DATA); 167 EPROM[ix + 1] = inb_ne(dep, NE_DATA); 168 /* NE2000s and clones read same value for even and odd addresses */ 169 if (EPROM[ix + 0] != EPROM[ix + 1]) wd = 0; 170 } 171 if (wd == 1) { /* Normalize EPROM contents for NE2000 */ 172 for (ix = 0; ix < 16; ix += 1) EPROM[ix] = EPROM[ix * 2]; 173 } 174 /* Real NE*000 and good clones have '0x57' at locations 14 and 15 */ 175 if (EPROM[14] != 0x57 || EPROM[15] != 0x57) return FALSE; 176 177 /* Setup the ethernet address. */ 178 for (ix = 0; ix < SA_ADDR_LEN; ix += 1) { 179 dep->de_address.ea_addr[ix] = EPROM[ix]; 180 } 181 dep->de_16bit = wd; 182 dep->de_linmem = 0; /* Uses Programmed I/O only */ 183 dep->de_prog_IO = 1; 184 dep->de_initf = ne_init; 185 dep->de_stopf = ne_close; 186 return TRUE; 187 } 188 189 #endif /* ENABLE_NE2000 */ 190 191 /** ne.c **/ 192