1 1.13 andvar /* $NetBSD: if_cs.c,v 1.13 2022/05/29 10:47:39 andvar Exp $ */ 2 1.1 chris 3 1.1 chris /* 4 1.2 chris * Copyright (c) 2004 Christopher Gilbert 5 1.2 chris * All rights reserved. 6 1.2 chris * 7 1.2 chris * 1. Redistributions of source code must retain the above copyright 8 1.2 chris * notice, this list of conditions and the following disclaimer. 9 1.2 chris * 2. Redistributions in binary form must reproduce the above copyright 10 1.2 chris * notice, this list of conditions and the following disclaimer in the 11 1.2 chris * documentation and/or other materials provided with the distribution. 12 1.2 chris * 3. The name of the author may be used to endorse or promote products 13 1.2 chris * derived from this software without specific prior written permission. 14 1.2 chris * 15 1.2 chris * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 16 1.2 chris * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 17 1.2 chris * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 1.2 chris * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 1.2 chris * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 1.2 chris * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 1.2 chris * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 1.2 chris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 1.2 chris * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 1.2 chris * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 1.2 chris * SUCH DAMAGE. 26 1.2 chris */ 27 1.2 chris /* 28 1.1 chris * Copyright 1997 29 1.1 chris * Digital Equipment Corporation. All rights reserved. 30 1.1 chris * 31 1.1 chris * This software is furnished under license and may be used and 32 1.1 chris * copied only in accordance with the following terms and conditions. 33 1.1 chris * Subject to these conditions, you may download, copy, install, 34 1.1 chris * use, modify and distribute this software in source and/or binary 35 1.1 chris * form. No title or ownership is transferred hereby. 36 1.1 chris * 37 1.1 chris * 1) Any source code used, modified or distributed must reproduce 38 1.1 chris * and retain this copyright notice and list of conditions as 39 1.1 chris * they appear in the source file. 40 1.1 chris * 41 1.1 chris * 2) No right is granted to use any trade name, trademark, or logo of 42 1.1 chris * Digital Equipment Corporation. Neither the "Digital Equipment 43 1.1 chris * Corporation" name nor any trademark or logo of Digital Equipment 44 1.1 chris * Corporation may be used to endorse or promote products derived 45 1.1 chris * from this software without the prior written permission of 46 1.1 chris * Digital Equipment Corporation. 47 1.1 chris * 48 1.1 chris * 3) This software is provided "AS-IS" and any express or implied 49 1.1 chris * warranties, including but not limited to, any implied warranties 50 1.1 chris * of merchantability, fitness for a particular purpose, or 51 1.1 chris * non-infringement are disclaimed. In no event shall DIGITAL be 52 1.1 chris * liable for any damages whatsoever, and in particular, DIGITAL 53 1.1 chris * shall not be liable for special, indirect, consequential, or 54 1.1 chris * incidental damages or damages for lost profits, loss of 55 1.1 chris * revenue or loss of use, whether such damages arise in contract, 56 1.1 chris * negligence, tort, under statute, in equity, at law or otherwise, 57 1.1 chris * even if advised of the possibility of such damage. 58 1.1 chris */ 59 1.1 chris 60 1.1 chris #include <sys/cdefs.h> 61 1.13 andvar __KERNEL_RCSID(0, "$NetBSD: if_cs.c,v 1.13 2022/05/29 10:47:39 andvar Exp $"); 62 1.1 chris 63 1.1 chris #include <sys/param.h> 64 1.1 chris #include <sys/systm.h> 65 1.1 chris #include <sys/socket.h> 66 1.1 chris #include <sys/device.h> 67 1.7 dyoung #include <sys/bus.h> 68 1.1 chris 69 1.1 chris #include <net/if.h> 70 1.1 chris #include <net/if_ether.h> 71 1.1 chris #include <net/if_media.h> 72 1.1 chris 73 1.1 chris #include <machine/intr.h> 74 1.1 chris 75 1.1 chris #include <acorn32/eb7500atx/rsbus.h> 76 1.1 chris 77 1.1 chris #include <dev/ic/cs89x0reg.h> 78 1.1 chris #include <dev/ic/cs89x0var.h> 79 1.1 chris 80 1.1 chris /* 81 1.1 chris * the CS network interface is accessed at the following address locations: 82 1.1 chris * 030104f1 CS8920 PNP Low 83 1.1 chris * 03010600 03010640 CS8920 Default I/O registers 84 1.1 chris * 030114f1 CS8920 PNP High 85 1.1 chris * 03014000 03016000 CS8920 Default Memory 86 1.1 chris * 87 1.1 chris * IRQ is mapped as: 88 1.1 chris * CS8920 IRQ 3 INT5 89 1.11 msaitoh * 90 1.1 chris * It must be configured as the following: 91 1.1 chris * The CS8920 PNP address should be configured for ISA base at 0x300 92 1.11 msaitoh * to achieve the default register mapping as specified. 93 1.1 chris * Note memory addresses are all have bit 23 tied high in hardware. 94 1.1 chris * This only effects the value programmed into the CS8920 memory offset 95 1.11 msaitoh * registers. 96 1.11 msaitoh * 97 1.13 andvar * Just to add to the fun the I/O registers are laid out as: 98 1.1 chris * xxxxR1R0 99 1.1 chris * xxxxR3R2 100 1.1 chris * xxxxR5R4 101 1.1 chris * 102 1.2 chris * This works fine for 16bit accesses, but it makes access to single 103 1.2 chris * register hard (which does happen on a reset, as we've got to toggle 104 1.2 chris * the chip into 16bit mode) 105 1.11 msaitoh * 106 1.11 msaitoh * Network DRQ is connected to DRQ5 107 1.1 chris */ 108 1.1 chris 109 1.1 chris /* 110 1.2 chris * make a private tag so that we can use rsbus's map/unmap 111 1.1 chris */ 112 1.1 chris static struct bus_space cs_rsbus_bs_tag; 113 1.1 chris 114 1.6 tsutsui int cs_rsbus_probe(device_t, cfdata_t, void *); 115 1.6 tsutsui void cs_rsbus_attach(device_t, device_t, void *); 116 1.1 chris 117 1.9 skrll static uint8_t cs_rbus_read_1(struct cs_softc *, bus_size_t); 118 1.1 chris 119 1.6 tsutsui CFATTACH_DECL_NEW(cs_rsbus, sizeof(struct cs_softc), 120 1.2 chris cs_rsbus_probe, cs_rsbus_attach, NULL, NULL); 121 1.1 chris 122 1.1 chris /* Available media */ 123 1.1 chris int cs_rbus_media [] = { 124 1.11 msaitoh IFM_ETHER | IFM_10_T | IFM_FDX, 125 1.11 msaitoh IFM_ETHER | IFM_10_T 126 1.1 chris }; 127 1.1 chris 128 1.11 msaitoh int 129 1.6 tsutsui cs_rsbus_probe(device_t parent, cfdata_t cf, void *aux) 130 1.1 chris { 131 1.11 msaitoh /* For now it'll always attach */ 132 1.1 chris return 1; 133 1.1 chris } 134 1.1 chris 135 1.11 msaitoh void 136 1.6 tsutsui cs_rsbus_attach(device_t parent, device_t self, void *aux) 137 1.1 chris { 138 1.6 tsutsui struct cs_softc *sc = device_private(self); 139 1.6 tsutsui struct rsbus_attach_args *rs = aux; 140 1.1 chris u_int iobase; 141 1.1 chris 142 1.6 tsutsui sc->sc_dev = self; 143 1.6 tsutsui 144 1.11 msaitoh /* Member copy */ 145 1.1 chris cs_rsbus_bs_tag = *rs->sa_iot; 146 1.11 msaitoh 147 1.11 msaitoh /* Registers are normally accessed in pairs, on a 4 byte aligned */ 148 1.12 msaitoh cs_rsbus_bs_tag.bs_cookie = (void *)1; 149 1.11 msaitoh 150 1.1 chris sc->sc_iot = sc->sc_memt = &cs_rsbus_bs_tag; 151 1.1 chris 152 1.6 tsutsui #if 0 /* Do DMA later */ 153 1.1 chris if (ia->ia_ndrq > 0) 154 1.1 chris isc->sc_drq = ia->ia_drq[0].ir_drq; 155 1.1 chris else 156 1.1 chris isc->sc_drq = -1; 157 1.6 tsutsui #endif 158 1.1 chris 159 1.11 msaitoh /* Device always interrupts on 3 but that routes to IRQ 5 */ 160 1.1 chris sc->sc_irq = 3; 161 1.1 chris 162 1.1 chris printf("\n"); 163 1.1 chris 164 1.11 msaitoh /* Map the device. */ 165 1.1 chris iobase = 0x03010600; 166 1.1 chris if (bus_space_map(sc->sc_iot, iobase, CS8900_IOSIZE * 4, 167 1.1 chris 0, &sc->sc_ioh)) { 168 1.6 tsutsui printf("%s: unable to map i/o space\n", device_xname(self)); 169 1.1 chris return; 170 1.1 chris } 171 1.1 chris 172 1.1 chris #if 0 173 1.2 chris if (bus_space_map(sc->sc_memt, iobase + 0x3A00, 174 1.2 chris CS8900_MEMSIZE * 4, 0, &sc->sc_memh)) { 175 1.6 tsutsui printf("%s: unable to map memory space\n", device_xname(self)); 176 1.2 chris } else { 177 1.2 chris sc->sc_cfgflags |= CFGFLG_MEM_MODE | CFGFLG_USE_SA; 178 1.2 chris sc->sc_pktpgaddr = 1<<23; 179 1.11 msaitoh //(0x4000 >> 1) | (1<<23); 180 1.1 chris } 181 1.1 chris #endif 182 1.3 chris sc->sc_ih = intr_claim(IRQ_INT5, IPL_NET, "cs", cs_intr, sc); 183 1.1 chris if (sc->sc_ih == NULL) { 184 1.1 chris printf("%s: unable to establish interrupt\n", 185 1.6 tsutsui device_xname(sc->sc_dev)); 186 1.1 chris return; 187 1.1 chris } 188 1.1 chris 189 1.1 chris /* DMA is for later */ 190 1.1 chris sc->sc_dma_chipinit = NULL; 191 1.1 chris sc->sc_dma_attach = NULL; 192 1.1 chris sc->sc_dma_process_rx = NULL; 193 1.1 chris 194 1.3 chris sc->sc_cfgflags |= CFGFLG_PARSE_EEPROM; 195 1.1 chris sc->sc_io_read_1 = cs_rbus_read_1; 196 1.2 chris 197 1.11 msaitoh /* 198 1.12 msaitoh * Also provide media, otherwise it attempts to read the media from 199 1.2 chris * the EEPROM, which again fails 200 1.2 chris */ 201 1.11 msaitoh cs_attach(sc, NULL, cs_rbus_media, __arraycount(cs_rbus_media), 202 1.12 msaitoh IFM_ETHER | IFM_10_T | IFM_FDX); 203 1.1 chris } 204 1.1 chris 205 1.2 chris /* 206 1.2 chris * Provide a function to correctly do reading from oddly numbered registers 207 1.2 chris * as you can't simply shift the register number 208 1.2 chris */ 209 1.9 skrll static uint8_t 210 1.1 chris cs_rbus_read_1(struct cs_softc *sc, bus_size_t a) 211 1.1 chris { 212 1.1 chris bus_size_t offset; 213 1.12 msaitoh 214 1.12 msaitoh /* If it's an even address then just use the bus_space_read_1 */ 215 1.1 chris if ((a & 1) == 0) 216 1.1 chris return bus_space_read_1(sc->sc_iot, sc->sc_ioh, a); 217 1.12 msaitoh 218 1.11 msaitoh /* 219 1.12 msaitoh * Otherwise we've get to work out the aligned address and then add 220 1.2 chris * one 221 1.2 chris */ 222 1.1 chris offset = (a & ~1) << 1; 223 1.1 chris offset++; 224 1.1 chris 225 1.12 msaitoh /* And read it, with no shift (cookie is 0) */ 226 1.1 chris return sc->sc_iot->bs_r_1(0, (sc)->sc_ioh, offset); 227 1.1 chris } 228