lsi64854.c (145217) | lsi64854.c (146392) |
---|---|
1/*- 2 * Copyright (c) 2004 Scott Long 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 50 unchanged lines hidden (view full) --- 59 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 63 * POSSIBILITY OF SUCH DAMAGE. 64 */ 65 66#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2004 Scott Long 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 50 unchanged lines hidden (view full) --- 59 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 63 * POSSIBILITY OF SUCH DAMAGE. 64 */ 65 66#include <sys/cdefs.h> |
67__FBSDID("$FreeBSD: head/sys/sparc64/sbus/lsi64854.c 145217 2005-04-18 02:34:22Z marius $"); | 67__FBSDID("$FreeBSD: head/sys/sparc64/sbus/lsi64854.c 146392 2005-05-19 14:51:10Z marius $"); |
68 69#include <sys/param.h> 70#include <sys/systm.h> 71#include <sys/bus.h> 72#include <sys/kernel.h> 73#include <sys/resource.h> 74#include <sys/lock.h> 75#include <sys/mutex.h> --- 32 unchanged lines hidden (view full) --- 108/* 109 * Finish attaching this DMA device. 110 * Front-end must fill in these fields: 111 * sc_regs 112 * sc_burst 113 * sc_channel (one of SCSI, ENET, PP) 114 * sc_client (one of SCSI, ENET, PP `soft_c' pointers) 115 */ | 68 69#include <sys/param.h> 70#include <sys/systm.h> 71#include <sys/bus.h> 72#include <sys/kernel.h> 73#include <sys/resource.h> 74#include <sys/lock.h> 75#include <sys/mutex.h> --- 32 unchanged lines hidden (view full) --- 108/* 109 * Finish attaching this DMA device. 110 * Front-end must fill in these fields: 111 * sc_regs 112 * sc_burst 113 * sc_channel (one of SCSI, ENET, PP) 114 * sc_client (one of SCSI, ENET, PP `soft_c' pointers) 115 */ |
116void | 116int |
117lsi64854_attach(struct lsi64854_softc *sc) 118{ 119 uint32_t csr; | 117lsi64854_attach(struct lsi64854_softc *sc) 118{ 119 uint32_t csr; |
120 int error; |
|
120 121 /* Indirect functions */ 122 switch (sc->sc_channel) { 123 case L64854_CHANNEL_SCSI: 124 sc->intr = lsi64854_scsi_intr; 125 sc->setup = lsi64854_setup; 126 break; 127 case L64854_CHANNEL_ENET: 128 sc->intr = lsi64854_enet_intr; 129 break; 130 case L64854_CHANNEL_PP: 131 sc->setup = lsi64854_setup_pp; 132 break; 133 default: 134 device_printf(sc->sc_dev, "unknown channel\n"); 135 } 136 sc->reset = lsi64854_reset; 137 138 /* Allocate a dmamap */ | 121 122 /* Indirect functions */ 123 switch (sc->sc_channel) { 124 case L64854_CHANNEL_SCSI: 125 sc->intr = lsi64854_scsi_intr; 126 sc->setup = lsi64854_setup; 127 break; 128 case L64854_CHANNEL_ENET: 129 sc->intr = lsi64854_enet_intr; 130 break; 131 case L64854_CHANNEL_PP: 132 sc->setup = lsi64854_setup_pp; 133 break; 134 default: 135 device_printf(sc->sc_dev, "unknown channel\n"); 136 } 137 sc->reset = lsi64854_reset; 138 139 /* Allocate a dmamap */ |
139 if (bus_dma_tag_create( | 140 error = bus_dma_tag_create( |
140 sc->sc_parent_dmat, /* parent */ 141 1, 0, /* alignment, boundary */ 142 BUS_SPACE_MAXADDR, /* lowaddr */ 143 BUS_SPACE_MAXADDR, /* highaddr */ 144 NULL, NULL, /* filter, filterarg */ 145 MAX_DMA_SZ, /* maxsize */ 146 1, /* nsegments */ 147 MAX_DMA_SZ, /* maxsegsize */ 148 BUS_DMA_ALLOCNOW, /* flags */ 149 NULL, NULL, /* lockfunc, lockarg */ | 141 sc->sc_parent_dmat, /* parent */ 142 1, 0, /* alignment, boundary */ 143 BUS_SPACE_MAXADDR, /* lowaddr */ 144 BUS_SPACE_MAXADDR, /* highaddr */ 145 NULL, NULL, /* filter, filterarg */ 146 MAX_DMA_SZ, /* maxsize */ 147 1, /* nsegments */ 148 MAX_DMA_SZ, /* maxsegsize */ 149 BUS_DMA_ALLOCNOW, /* flags */ 150 NULL, NULL, /* lockfunc, lockarg */ |
150 &sc->sc_buffer_dmat)) { | 151 &sc->sc_buffer_dmat); 152 if (error != 0) { |
151 device_printf(sc->sc_dev, "cannot allocate buffer DMA tag\n"); | 153 device_printf(sc->sc_dev, "cannot allocate buffer DMA tag\n"); |
152 return; | 154 return (error); |
153 } 154 | 155 } 156 |
155 if (bus_dmamap_create(sc->sc_buffer_dmat, 0, &sc->sc_dmamap) != 0) { | 157 error = bus_dmamap_create(sc->sc_buffer_dmat, 0, &sc->sc_dmamap); 158 if (error != 0) { |
156 device_printf(sc->sc_dev, "DMA map create failed\n"); | 159 device_printf(sc->sc_dev, "DMA map create failed\n"); |
157 return; | 160 bus_dma_tag_destroy(sc->sc_buffer_dmat); 161 return (error); |
158 } 159 160 csr = L64854_GCSR(sc); 161 sc->sc_rev = csr & L64854_DEVID; 162 if (sc->sc_rev == DMAREV_HME) | 162 } 163 164 csr = L64854_GCSR(sc); 165 sc->sc_rev = csr & L64854_DEVID; 166 if (sc->sc_rev == DMAREV_HME) |
163 return; | 167 return (0); |
164 device_printf(sc->sc_dev, "DMA rev. "); 165 switch (sc->sc_rev) { 166 case DMAREV_0: 167 printf("0"); 168 break; 169 case DMAREV_ESC: | 168 device_printf(sc->sc_dev, "DMA rev. "); 169 switch (sc->sc_rev) { 170 case DMAREV_0: 171 printf("0"); 172 break; 173 case DMAREV_ESC: |
170 printf("esc"); | 174 printf("ESC"); |
171 break; 172 case DMAREV_1: 173 printf("1"); 174 break; 175 case DMAREV_PLUS: 176 printf("1+"); 177 break; 178 case DMAREV_2: 179 printf("2"); 180 break; 181 default: 182 printf("unknown (0x%x)", sc->sc_rev); 183 } 184 185 DPRINTF(LDB_ANY, (", burst 0x%x, csr 0x%x", sc->sc_burst, csr)); 186 printf("\n"); | 175 break; 176 case DMAREV_1: 177 printf("1"); 178 break; 179 case DMAREV_PLUS: 180 printf("1+"); 181 break; 182 case DMAREV_2: 183 printf("2"); 184 break; 185 default: 186 printf("unknown (0x%x)", sc->sc_rev); 187 } 188 189 DPRINTF(LDB_ANY, (", burst 0x%x, csr 0x%x", sc->sc_burst, csr)); 190 printf("\n"); |
191 192 return (0); |
|
187} 188 | 193} 194 |
195int 196lsi64854_detach(struct lsi64854_softc *sc) 197{ 198 199 if (sc->setup) 200 bus_dmamap_unload(sc->sc_buffer_dmat, sc->sc_dmamap); 201 bus_dmamap_destroy(sc->sc_buffer_dmat, sc->sc_dmamap); 202 bus_dma_tag_destroy(sc->sc_buffer_dmat); 203 204 return (0); 205} 206 |
|
189/* 190 * DMAWAIT waits while condition is true 191 */ 192#define DMAWAIT(SC, COND, MSG, DONTPANIC) do if (COND) { \ 193 int count = 500000; \ 194 while ((COND) && --count > 0) DELAY(1); \ 195 if (count == 0) { \ 196 printf("%s: line %d: CSR = 0x%lx\n", __FILE__, __LINE__, \ --- 63 unchanged lines hidden (view full) --- 260 * XXX is sync needed? 261 if (sc->sc_dmamap->dm_nsegs > 0) 262 bus_dmamap_unload(sc->sc_buffer_dmat, sc->sc_dmamap); 263 */ 264 265 if (sc->sc_rev == DMAREV_HME) 266 L64854_SCSR(sc, csr | D_HW_RESET_FAS366); 267 | 207/* 208 * DMAWAIT waits while condition is true 209 */ 210#define DMAWAIT(SC, COND, MSG, DONTPANIC) do if (COND) { \ 211 int count = 500000; \ 212 while ((COND) && --count > 0) DELAY(1); \ 213 if (count == 0) { \ 214 printf("%s: line %d: CSR = 0x%lx\n", __FILE__, __LINE__, \ --- 63 unchanged lines hidden (view full) --- 278 * XXX is sync needed? 279 if (sc->sc_dmamap->dm_nsegs > 0) 280 bus_dmamap_unload(sc->sc_buffer_dmat, sc->sc_dmamap); 281 */ 282 283 if (sc->sc_rev == DMAREV_HME) 284 L64854_SCSR(sc, csr | D_HW_RESET_FAS366); 285 |
268 | |
269 csr |= L64854_RESET; /* reset DMA */ 270 L64854_SCSR(sc, csr); 271 DELAY(200); /* > 10 Sbus clocks(?) */ 272 273 /*DMAWAIT1(sc); why was this here? */ 274 csr = L64854_GCSR(sc); 275 csr &= ~L64854_RESET; /* de-assert reset line */ 276 L64854_SCSR(sc, csr); --- 208 unchanged lines hidden (view full) --- 485 486 if (resid == 0 && sc->sc_dmasize == 65536 && 487 (nsc->sc_cfg2 & NCRCFG2_FE) == 0) 488 /* A transfer of 64K is encoded as `TCL=TCM=0' */ 489 resid = 65536; 490 } 491 492 trans = sc->sc_dmasize - resid; | 286 csr |= L64854_RESET; /* reset DMA */ 287 L64854_SCSR(sc, csr); 288 DELAY(200); /* > 10 Sbus clocks(?) */ 289 290 /*DMAWAIT1(sc); why was this here? */ 291 csr = L64854_GCSR(sc); 292 csr &= ~L64854_RESET; /* de-assert reset line */ 293 L64854_SCSR(sc, csr); --- 208 unchanged lines hidden (view full) --- 502 503 if (resid == 0 && sc->sc_dmasize == 65536 && 504 (nsc->sc_cfg2 & NCRCFG2_FE) == 0) 505 /* A transfer of 64K is encoded as `TCL=TCM=0' */ 506 resid = 65536; 507 } 508 509 trans = sc->sc_dmasize - resid; |
493 if (trans < 0) { /* transferred < 0 ? */ | 510 if (trans < 0) { /* transfered < 0? */ |
494#if 0 495 /* 496 * This situation can happen in perfectly normal operation 497 * if the ESP is reselected while using DMA to select 498 * another target. As such, don't print the warning. 499 */ 500 device_printf(sc->sc_dev, "xfer (%d) > req (%d)\n", trans, 501 sc->sc_dmasize); --- 59 unchanged lines hidden (view full) --- 561 if (dodrain) { /* XXX - is this necessary with D_DSBL_WRINVAL on? */ 562 int i = 10; 563 csr |= E_DRAIN; 564 L64854_SCSR(sc, csr); 565 while (i-- > 0 && (L64854_GCSR(sc) & D_DRAINING)) 566 DELAY(1); 567 } 568 | 511#if 0 512 /* 513 * This situation can happen in perfectly normal operation 514 * if the ESP is reselected while using DMA to select 515 * another target. As such, don't print the warning. 516 */ 517 device_printf(sc->sc_dev, "xfer (%d) > req (%d)\n", trans, 518 sc->sc_dmasize); --- 59 unchanged lines hidden (view full) --- 578 if (dodrain) { /* XXX - is this necessary with D_DSBL_WRINVAL on? */ 579 int i = 10; 580 csr |= E_DRAIN; 581 L64854_SCSR(sc, csr); 582 while (i-- > 0 && (L64854_GCSR(sc) & D_DRAINING)) 583 DELAY(1); 584 } 585 |
569 return (rv | (*sc->sc_intrchain)(sc->sc_intrchainarg)); | 586 (*sc->sc_intrchain)(sc->sc_intrchainarg); 587 588 return (rv); |
570} 571 572static void 573lsi64854_map_pp(void *arg, bus_dma_segment_t *segs, int nsegs, int error) 574{ 575 struct lsi64854_softc *sc; 576 577 sc = (struct lsi64854_softc *)arg; --- 127 unchanged lines hidden --- | 589} 590 591static void 592lsi64854_map_pp(void *arg, bus_dma_segment_t *segs, int nsegs, int error) 593{ 594 struct lsi64854_softc *sc; 595 596 sc = (struct lsi64854_softc *)arg; --- 127 unchanged lines hidden --- |