esp_sbus.c (180692) | esp_sbus.c (182876) |
---|---|
1/*- 2 * Copyright (c) 2004 Scott Long | 1/*- 2 * Copyright (c) 2004 Scott Long |
3 * Copyright (c) 2005 Marius Strobl <marius@FreeBSD.org> |
|
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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 49 unchanged lines hidden (view full) --- 60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 64 * POSSIBILITY OF SUCH DAMAGE. 65 */ 66 67#include <sys/cdefs.h> | 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright --- 49 unchanged lines hidden (view full) --- 61 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 62 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 63 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 65 * POSSIBILITY OF SUCH DAMAGE. 66 */ 67 68#include <sys/cdefs.h> |
68__FBSDID("$FreeBSD: head/sys/dev/esp/esp_sbus.c 180692 2008-07-22 13:51:21Z marius $"); | 69__FBSDID("$FreeBSD: head/sys/dev/esp/esp_sbus.c 182876 2008-09-08 20:20:44Z marius $"); |
69 70#include <sys/param.h> 71#include <sys/systm.h> 72#include <sys/bus.h> 73#include <sys/kernel.h> | 70 71#include <sys/param.h> 72#include <sys/systm.h> 73#include <sys/bus.h> 74#include <sys/kernel.h> |
75#include <sys/lock.h> |
|
74#include <sys/module.h> | 76#include <sys/module.h> |
75#include <sys/resource.h> | 77#include <sys/mutex.h> |
76 77#include <dev/ofw/ofw_bus.h> 78#include <dev/ofw/openfirm.h> 79#include <machine/bus.h> 80#include <machine/resource.h> 81#include <sys/rman.h> 82 83#include <cam/cam.h> 84#include <cam/cam_ccb.h> 85#include <cam/scsi/scsi_all.h> | 78 79#include <dev/ofw/ofw_bus.h> 80#include <dev/ofw/openfirm.h> 81#include <machine/bus.h> 82#include <machine/resource.h> 83#include <sys/rman.h> 84 85#include <cam/cam.h> 86#include <cam/cam_ccb.h> 87#include <cam/scsi/scsi_all.h> |
88#include <cam/scsi/scsi_message.h> |
|
86 87#include <sparc64/sbus/lsi64854reg.h> 88#include <sparc64/sbus/lsi64854var.h> 89#include <sparc64/sbus/sbusvar.h> 90 91#include <dev/esp/ncr53c9xreg.h> 92#include <dev/esp/ncr53c9xvar.h> 93 94/* #define ESP_SBUS_DEBUG */ 95 96struct esp_softc { 97 struct ncr53c9x_softc sc_ncr53c9x; /* glue to MI code */ 98 struct device *sc_dev; 99 | 89 90#include <sparc64/sbus/lsi64854reg.h> 91#include <sparc64/sbus/lsi64854var.h> 92#include <sparc64/sbus/sbusvar.h> 93 94#include <dev/esp/ncr53c9xreg.h> 95#include <dev/esp/ncr53c9xvar.h> 96 97/* #define ESP_SBUS_DEBUG */ 98 99struct esp_softc { 100 struct ncr53c9x_softc sc_ncr53c9x; /* glue to MI code */ 101 struct device *sc_dev; 102 |
100 int sc_rid; | |
101 struct resource *sc_res; | 103 struct resource *sc_res; |
102 bus_space_handle_t sc_regh; 103 bus_space_tag_t sc_regt; | |
104 | 104 |
105 int sc_irqrid; | |
106 struct resource *sc_irqres; 107 void *sc_irq; 108 109 struct lsi64854_softc *sc_dma; /* pointer to my DMA */ 110}; 111 112static devclass_t esp_devclass; 113 --- 36 unchanged lines hidden (view full) --- 150 "esp", 151 esp_sbus_methods, 152 sizeof(struct esp_softc) 153}; 154 155DRIVER_MODULE(esp, sbus, esp_sbus_driver, esp_devclass, 0, 0); 156MODULE_DEPEND(esp, sbus, 1, 1, 1); 157 | 105 struct resource *sc_irqres; 106 void *sc_irq; 107 108 struct lsi64854_softc *sc_dma; /* pointer to my DMA */ 109}; 110 111static devclass_t esp_devclass; 112 --- 36 unchanged lines hidden (view full) --- 149 "esp", 150 esp_sbus_methods, 151 sizeof(struct esp_softc) 152}; 153 154DRIVER_MODULE(esp, sbus, esp_sbus_driver, esp_devclass, 0, 0); 155MODULE_DEPEND(esp, sbus, 1, 1, 1); 156 |
158MODULE_DEPEND(esp, cam, 1, 1, 1); 159 | |
160/* 161 * Functions and the switch for the MI code 162 */ 163static u_char esp_read_reg(struct ncr53c9x_softc *sc, int reg); 164static void esp_write_reg(struct ncr53c9x_softc *sc, int reg, u_char v); 165static int esp_dma_isintr(struct ncr53c9x_softc *sc); 166static void esp_dma_reset(struct ncr53c9x_softc *sc); 167static int esp_dma_intr(struct ncr53c9x_softc *sc); 168static int esp_dma_setup(struct ncr53c9x_softc *sc, caddr_t *addr, 169 size_t *len, int datain, size_t *dmasize); 170static void esp_dma_go(struct ncr53c9x_softc *sc); 171static void esp_dma_stop(struct ncr53c9x_softc *sc); 172static int esp_dma_isactive(struct ncr53c9x_softc *sc); | 157/* 158 * Functions and the switch for the MI code 159 */ 160static u_char esp_read_reg(struct ncr53c9x_softc *sc, int reg); 161static void esp_write_reg(struct ncr53c9x_softc *sc, int reg, u_char v); 162static int esp_dma_isintr(struct ncr53c9x_softc *sc); 163static void esp_dma_reset(struct ncr53c9x_softc *sc); 164static int esp_dma_intr(struct ncr53c9x_softc *sc); 165static int esp_dma_setup(struct ncr53c9x_softc *sc, caddr_t *addr, 166 size_t *len, int datain, size_t *dmasize); 167static void esp_dma_go(struct ncr53c9x_softc *sc); 168static void esp_dma_stop(struct ncr53c9x_softc *sc); 169static int esp_dma_isactive(struct ncr53c9x_softc *sc); |
173static int espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep); | 170static int espattach(struct esp_softc *esc, 171 const struct ncr53c9x_glue *gluep); 172static int espdetach(struct esp_softc *esc); |
174 | 173 |
175static struct ncr53c9x_glue esp_sbus_glue = { | 174static const struct ncr53c9x_glue esp_sbus_glue = { |
176 esp_read_reg, 177 esp_write_reg, 178 esp_dma_isintr, 179 esp_dma_reset, 180 esp_dma_intr, 181 esp_dma_setup, 182 esp_dma_go, 183 esp_dma_stop, --- 20 unchanged lines hidden (view full) --- 204 205static int 206esp_sbus_attach(device_t dev) 207{ 208 struct esp_softc *esc; 209 struct ncr53c9x_softc *sc; 210 struct lsi64854_softc *lsc; 211 device_t *children; | 175 esp_read_reg, 176 esp_write_reg, 177 esp_dma_isintr, 178 esp_dma_reset, 179 esp_dma_intr, 180 esp_dma_setup, 181 esp_dma_go, 182 esp_dma_stop, --- 20 unchanged lines hidden (view full) --- 203 204static int 205esp_sbus_attach(device_t dev) 206{ 207 struct esp_softc *esc; 208 struct ncr53c9x_softc *sc; 209 struct lsi64854_softc *lsc; 210 device_t *children; |
212 const char *name; 213 phandle_t node; 214 int burst, error, i, nchildren, slot; | 211 int error, i, nchildren; |
215 216 esc = device_get_softc(dev); | 212 213 esc = device_get_softc(dev); |
217 bzero(esc, sizeof(struct esp_softc)); | |
218 sc = &esc->sc_ncr53c9x; 219 220 lsc = NULL; 221 esc->sc_dev = dev; | 214 sc = &esc->sc_ncr53c9x; 215 216 lsc = NULL; 217 esc->sc_dev = dev; |
222 name = ofw_bus_get_name(dev); 223 node = ofw_bus_get_node(dev); 224 if (OF_getprop(node, "initiator-id", &sc->sc_id, 225 sizeof(sc->sc_id)) == -1) 226 sc->sc_id = 7; | |
227 sc->sc_freq = sbus_get_clockfreq(dev); 228 | 218 sc->sc_freq = sbus_get_clockfreq(dev); 219 |
229#ifdef ESP_SBUS_DEBUG 230 device_printf(dev, "%s: sc_id %d, freq %d\n", __func__, sc->sc_id, 231 sc->sc_freq); 232#endif 233 234 if (strcmp(name, "SUNW,fas") == 0) { | 220 if (strcmp(ofw_bus_get_name(dev), "SUNW,fas") == 0) { |
235 /* 236 * Allocate space for DMA, in SUNW,fas there are no 237 * separate DMA devices. 238 */ 239 lsc = malloc(sizeof (struct lsi64854_softc), M_DEVBUF, 240 M_NOWAIT | M_ZERO); 241 if (lsc == NULL) { 242 device_printf(dev, "out of memory (lsi64854_softc)\n"); 243 return (ENOMEM); 244 } 245 esc->sc_dma = lsc; 246 247 /* 248 * SUNW,fas have 2 register spaces: DMA (lsi64854) and 249 * SCSI core (ncr53c9x). 250 */ 251 252 /* Allocate DMA registers. */ | 221 /* 222 * Allocate space for DMA, in SUNW,fas there are no 223 * separate DMA devices. 224 */ 225 lsc = malloc(sizeof (struct lsi64854_softc), M_DEVBUF, 226 M_NOWAIT | M_ZERO); 227 if (lsc == NULL) { 228 device_printf(dev, "out of memory (lsi64854_softc)\n"); 229 return (ENOMEM); 230 } 231 esc->sc_dma = lsc; 232 233 /* 234 * SUNW,fas have 2 register spaces: DMA (lsi64854) and 235 * SCSI core (ncr53c9x). 236 */ 237 238 /* Allocate DMA registers. */ |
253 lsc->sc_rid = 0; | 239 i = 0; |
254 if ((lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | 240 if ((lsc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, |
255 &lsc->sc_rid, RF_ACTIVE)) == NULL) { | 241 &i, RF_ACTIVE)) == NULL) { |
256 device_printf(dev, "cannot allocate DMA registers\n"); 257 error = ENXIO; 258 goto fail_sbus_lsc; 259 } | 242 device_printf(dev, "cannot allocate DMA registers\n"); 243 error = ENXIO; 244 goto fail_sbus_lsc; 245 } |
260 lsc->sc_regt = rman_get_bustag(lsc->sc_res); 261 lsc->sc_regh = rman_get_bushandle(lsc->sc_res); | |
262 263 /* Create a parent DMA tag based on this bus. */ 264 error = bus_dma_tag_create( 265 bus_get_dma_tag(dev), /* parent */ | 246 247 /* Create a parent DMA tag based on this bus. */ 248 error = bus_dma_tag_create( 249 bus_get_dma_tag(dev), /* parent */ |
266 PAGE_SIZE, 0, /* alignment, boundary */ | 250 1, 0, /* alignment, boundary */ |
267 BUS_SPACE_MAXADDR, /* lowaddr */ 268 BUS_SPACE_MAXADDR, /* highaddr */ 269 NULL, NULL, /* filter, filterarg */ 270 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 271 0, /* nsegments */ 272 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 273 0, /* flags */ 274 NULL, NULL, /* no locking */ 275 &lsc->sc_parent_dmat); 276 if (error != 0) { 277 device_printf(dev, "cannot allocate parent DMA tag\n"); 278 goto fail_sbus_lres; 279 } | 251 BUS_SPACE_MAXADDR, /* lowaddr */ 252 BUS_SPACE_MAXADDR, /* highaddr */ 253 NULL, NULL, /* filter, filterarg */ 254 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */ 255 0, /* nsegments */ 256 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */ 257 0, /* flags */ 258 NULL, NULL, /* no locking */ 259 &lsc->sc_parent_dmat); 260 if (error != 0) { 261 device_printf(dev, "cannot allocate parent DMA tag\n"); 262 goto fail_sbus_lres; 263 } |
280 burst = sbus_get_burstsz(dev); | |
281 | 264 |
265 i = sbus_get_burstsz(dev); 266 |
|
282#ifdef ESP_SBUS_DEBUG | 267#ifdef ESP_SBUS_DEBUG |
283 printf("%s: burst 0x%x\n", __func__, burst); | 268 printf("%s: burst 0x%x\n", __func__, i); |
284#endif 285 | 269#endif 270 |
286 lsc->sc_burst = (burst & SBUS_BURST_32) ? 32 : 287 (burst & SBUS_BURST_16) ? 16 : 0; | 271 lsc->sc_burst = (i & SBUS_BURST_32) ? 32 : 272 (i & SBUS_BURST_16) ? 16 : 0; |
288 289 lsc->sc_channel = L64854_CHANNEL_SCSI; 290 lsc->sc_client = sc; 291 lsc->sc_dev = dev; 292 | 273 274 lsc->sc_channel = L64854_CHANNEL_SCSI; 275 lsc->sc_client = sc; 276 lsc->sc_dev = dev; 277 |
293 error = lsi64854_attach(lsc); 294 if (error != 0) { 295 device_printf(dev, "lsi64854_attach failed\n"); 296 goto fail_sbus_lpdma; 297 } 298 | |
299 /* 300 * Allocate SCSI core registers. 301 */ | 278 /* 279 * Allocate SCSI core registers. 280 */ |
302 esc->sc_rid = 1; | 281 i = 1; |
303 if ((esc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | 282 if ((esc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, |
304 &esc->sc_rid, RF_ACTIVE)) == NULL) { | 283 &i, RF_ACTIVE)) == NULL) { |
305 device_printf(dev, 306 "cannot allocate SCSI core registers\n"); 307 error = ENXIO; | 284 device_printf(dev, 285 "cannot allocate SCSI core registers\n"); 286 error = ENXIO; |
308 goto fail_sbus_lsi; | 287 goto fail_sbus_lpdma; |
309 } | 288 } |
310 esc->sc_regt = rman_get_bustag(esc->sc_res); 311 esc->sc_regh = rman_get_bushandle(esc->sc_res); | |
312 } else { 313 /* 314 * Search accompanying DMA engine. It should have been 315 * already attached otherwise there isn't much we can do. 316 */ 317 if (device_get_children(device_get_parent(dev), &children, 318 &nchildren) != 0) { 319 device_printf(dev, "cannot determine siblings\n"); 320 return (ENXIO); 321 } | 289 } else { 290 /* 291 * Search accompanying DMA engine. It should have been 292 * already attached otherwise there isn't much we can do. 293 */ 294 if (device_get_children(device_get_parent(dev), &children, 295 &nchildren) != 0) { 296 device_printf(dev, "cannot determine siblings\n"); 297 return (ENXIO); 298 } |
322 slot = sbus_get_slot(dev); | |
323 for (i = 0; i < nchildren; i++) { 324 if (device_is_attached(children[i]) && | 299 for (i = 0; i < nchildren; i++) { 300 if (device_is_attached(children[i]) && |
325 sbus_get_slot(children[i]) == slot && | 301 sbus_get_slot(children[i]) == sbus_get_slot(dev) && |
326 strcmp(ofw_bus_get_name(children[i]), "dma") == 0) { 327 /* XXX hackery */ 328 esc->sc_dma = (struct lsi64854_softc *) 329 device_get_softc(children[i]); 330 break; 331 } 332 } 333 free(children, M_TEMP); 334 if (esc->sc_dma == NULL) { 335 device_printf(dev, "cannot find DMA engine\n"); 336 return (ENXIO); 337 } 338 esc->sc_dma->sc_client = sc; 339 340 /* 341 * Allocate SCSI core registers. 342 */ | 302 strcmp(ofw_bus_get_name(children[i]), "dma") == 0) { 303 /* XXX hackery */ 304 esc->sc_dma = (struct lsi64854_softc *) 305 device_get_softc(children[i]); 306 break; 307 } 308 } 309 free(children, M_TEMP); 310 if (esc->sc_dma == NULL) { 311 device_printf(dev, "cannot find DMA engine\n"); 312 return (ENXIO); 313 } 314 esc->sc_dma->sc_client = sc; 315 316 /* 317 * Allocate SCSI core registers. 318 */ |
343 esc->sc_rid = 0; | 319 i = 0; |
344 if ((esc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | 320 if ((esc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, |
345 &esc->sc_rid, RF_ACTIVE)) == NULL) { | 321 &i, RF_ACTIVE)) == NULL) { |
346 device_printf(dev, 347 "cannot allocate SCSI core registers\n"); 348 return (ENXIO); 349 } | 322 device_printf(dev, 323 "cannot allocate SCSI core registers\n"); 324 return (ENXIO); 325 } |
350 esc->sc_regt = rman_get_bustag(esc->sc_res); 351 esc->sc_regh = rman_get_bushandle(esc->sc_res); | |
352 } 353 354 error = espattach(esc, &esp_sbus_glue); 355 if (error != 0) { 356 device_printf(dev, "espattach failed\n"); 357 goto fail_sbus_eres; 358 } 359 360 return (0); 361 362 fail_sbus_eres: | 326 } 327 328 error = espattach(esc, &esp_sbus_glue); 329 if (error != 0) { 330 device_printf(dev, "espattach failed\n"); 331 goto fail_sbus_eres; 332 } 333 334 return (0); 335 336 fail_sbus_eres: |
363 bus_release_resource(dev, SYS_RES_MEMORY, esc->sc_rid, esc->sc_res); 364 if (strcmp(name, "SUNW,fas") != 0) | 337 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(esc->sc_res), 338 esc->sc_res); 339 if (strcmp(ofw_bus_get_name(dev), "SUNW,fas") != 0) |
365 return (error); | 340 return (error); |
366 fail_sbus_lsi: 367 lsi64854_detach(lsc); | |
368 fail_sbus_lpdma: 369 bus_dma_tag_destroy(lsc->sc_parent_dmat); 370 fail_sbus_lres: | 341 fail_sbus_lpdma: 342 bus_dma_tag_destroy(lsc->sc_parent_dmat); 343 fail_sbus_lres: |
371 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, lsc->sc_res); | 344 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(lsc->sc_res), 345 lsc->sc_res); |
372 fail_sbus_lsc: 373 free(lsc, M_DEVBUF); 374 return (error); 375} 376 377static int 378esp_sbus_detach(device_t dev) 379{ 380 struct esp_softc *esc; | 346 fail_sbus_lsc: 347 free(lsc, M_DEVBUF); 348 return (error); 349} 350 351static int 352esp_sbus_detach(device_t dev) 353{ 354 struct esp_softc *esc; |
381 struct ncr53c9x_softc *sc; | |
382 struct lsi64854_softc *lsc; 383 int error; 384 385 esc = device_get_softc(dev); | 355 struct lsi64854_softc *lsc; 356 int error; 357 358 esc = device_get_softc(dev); |
386 sc = &esc->sc_ncr53c9x; | |
387 lsc = esc->sc_dma; 388 | 359 lsc = esc->sc_dma; 360 |
389 bus_teardown_intr(esc->sc_dev, esc->sc_irqres, esc->sc_irq); 390 error = ncr53c9x_detach(sc); | 361 error = espdetach(esc); |
391 if (error != 0) 392 return (error); | 362 if (error != 0) 363 return (error); |
393 bus_release_resource(esc->sc_dev, SYS_RES_IRQ, esc->sc_irqrid, 394 esc->sc_irqres); 395 bus_release_resource(dev, SYS_RES_MEMORY, esc->sc_rid, esc->sc_res); | 364 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(esc->sc_res), 365 esc->sc_res); |
396 if (strcmp(ofw_bus_get_name(dev), "SUNW,fas") != 0) 397 return (0); | 366 if (strcmp(ofw_bus_get_name(dev), "SUNW,fas") != 0) 367 return (0); |
398 error = lsi64854_detach(lsc); 399 if (error != 0) 400 return (error); | |
401 bus_dma_tag_destroy(lsc->sc_parent_dmat); | 368 bus_dma_tag_destroy(lsc->sc_parent_dmat); |
402 bus_release_resource(dev, SYS_RES_MEMORY, lsc->sc_rid, lsc->sc_res); | 369 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(lsc->sc_res), 370 lsc->sc_res); |
403 free(lsc, M_DEVBUF); 404 405 return (0); 406} 407 408static int 409esp_dma_attach(device_t dev) 410{ 411 struct esp_softc *esc; 412 struct ncr53c9x_softc *sc; | 371 free(lsc, M_DEVBUF); 372 373 return (0); 374} 375 376static int 377esp_dma_attach(device_t dev) 378{ 379 struct esp_softc *esc; 380 struct ncr53c9x_softc *sc; |
413 phandle_t node; 414 int error; | 381 int error, i; |
415 416 esc = device_get_softc(dev); | 382 383 esc = device_get_softc(dev); |
417 bzero(esc, sizeof(struct esp_softc)); | |
418 sc = &esc->sc_ncr53c9x; 419 420 esc->sc_dev = dev; | 384 sc = &esc->sc_ncr53c9x; 385 386 esc->sc_dev = dev; |
421 node = ofw_bus_get_node(dev); 422 if (OF_getprop(node, "initiator-id", &sc->sc_id, 423 sizeof(sc->sc_id)) == -1) 424 sc->sc_id = 7; 425 if (OF_getprop(node, "clock-frequency", &sc->sc_freq, 426 sizeof(sc->sc_freq)) == -1) { | 387 if (OF_getprop(ofw_bus_get_node(dev), "clock-frequency", 388 &sc->sc_freq, sizeof(sc->sc_freq)) == -1) { |
427 printf("failed to query OFW for clock-frequency\n"); 428 return (ENXIO); 429 } 430 | 389 printf("failed to query OFW for clock-frequency\n"); 390 return (ENXIO); 391 } 392 |
431#ifdef ESP_SBUS_DEBUG 432 device_printf(dev, "%s: sc_id %d, freq %d\n", __func__, sc->sc_id, 433 sc->sc_freq); 434#endif 435 | |
436 /* XXX hackery */ 437 esc->sc_dma = (struct lsi64854_softc *) 438 device_get_softc(device_get_parent(dev)); 439 esc->sc_dma->sc_client = sc; 440 441 /* 442 * Allocate SCSI core registers. 443 */ | 393 /* XXX hackery */ 394 esc->sc_dma = (struct lsi64854_softc *) 395 device_get_softc(device_get_parent(dev)); 396 esc->sc_dma->sc_client = sc; 397 398 /* 399 * Allocate SCSI core registers. 400 */ |
444 esc->sc_rid = 0; | 401 i = 0; |
445 if ((esc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | 402 if ((esc->sc_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, |
446 &esc->sc_rid, RF_ACTIVE)) == NULL) { | 403 &i, RF_ACTIVE)) == NULL) { |
447 device_printf(dev, "cannot allocate SCSI core registers\n"); 448 return (ENXIO); 449 } | 404 device_printf(dev, "cannot allocate SCSI core registers\n"); 405 return (ENXIO); 406 } |
450 esc->sc_regt = rman_get_bustag(esc->sc_res); 451 esc->sc_regh = rman_get_bushandle(esc->sc_res); | |
452 453 error = espattach(esc, &esp_sbus_glue); 454 if (error != 0) { 455 device_printf(dev, "espattach failed\n"); 456 goto fail_dma_eres; 457 } 458 459 return (0); 460 461 fail_dma_eres: | 407 408 error = espattach(esc, &esp_sbus_glue); 409 if (error != 0) { 410 device_printf(dev, "espattach failed\n"); 411 goto fail_dma_eres; 412 } 413 414 return (0); 415 416 fail_dma_eres: |
462 bus_release_resource(dev, SYS_RES_MEMORY, esc->sc_rid, esc->sc_res); | 417 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(esc->sc_res), 418 esc->sc_res); |
463 return (error); 464} 465 466static int 467esp_dma_detach(device_t dev) 468{ 469 struct esp_softc *esc; | 419 return (error); 420} 421 422static int 423esp_dma_detach(device_t dev) 424{ 425 struct esp_softc *esc; |
470 struct ncr53c9x_softc *sc; | |
471 int error; 472 473 esc = device_get_softc(dev); | 426 int error; 427 428 esc = device_get_softc(dev); |
474 sc = &esc->sc_ncr53c9x; | |
475 | 429 |
476 bus_teardown_intr(esc->sc_dev, esc->sc_irqres, esc->sc_irq); 477 error = ncr53c9x_detach(sc); | 430 error = espdetach(esc); |
478 if (error != 0) 479 return (error); | 431 if (error != 0) 432 return (error); |
480 bus_release_resource(esc->sc_dev, SYS_RES_IRQ, esc->sc_irqrid, 481 esc->sc_irqres); 482 bus_release_resource(dev, SYS_RES_MEMORY, esc->sc_rid, esc->sc_res); | 433 bus_release_resource(dev, SYS_RES_MEMORY, rman_get_rid(esc->sc_res), 434 esc->sc_res); |
483 484 return (0); 485} 486 487static int 488esp_suspend(device_t dev) 489{ 490 491 return (ENXIO); 492} 493 494static int 495esp_resume(device_t dev) 496{ 497 498 return (ENXIO); 499} 500 501static int | 435 436 return (0); 437} 438 439static int 440esp_suspend(device_t dev) 441{ 442 443 return (ENXIO); 444} 445 446static int 447esp_resume(device_t dev) 448{ 449 450 return (ENXIO); 451} 452 453static int |
502espattach(struct esp_softc *esc, struct ncr53c9x_glue *gluep) | 454espattach(struct esp_softc *esc, const struct ncr53c9x_glue *gluep) |
503{ 504 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x; 505 unsigned int uid = 0; | 455{ 456 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x; 457 unsigned int uid = 0; |
506 int error; | 458 int error, i; |
507 | 459 |
460 NCR_LOCK_INIT(sc); 461 462 /* Attach the DMA engine. */ 463 error = lsi64854_attach(esc->sc_dma); 464 if (error != 0) { 465 device_printf(esc->sc_dev, "lsi64854_attach failed\n"); 466 goto fail_lock; 467 } 468 469 if (OF_getprop(ofw_bus_get_node(esc->sc_dev), "scsi-initiator-id", 470 &sc->sc_id, sizeof(sc->sc_id)) == -1) 471 sc->sc_id = 7; 472 473#ifdef ESP_SBUS_DEBUG 474 device_printf(esc->sc_dev, "%s: sc_id %d, freq %d\n", 475 __func__, sc->sc_id, sc->sc_freq); 476#endif 477 |
|
508 /* 509 * The `ESC' DMA chip must be reset before we can access 510 * the ESP registers. 511 */ 512 if (esc->sc_dma->sc_rev == DMAREV_ESC) 513 DMA_RESET(esc->sc_dma); 514 515 /* --- 77 unchanged lines hidden (view full) --- 593 default: 594 /* 595 * We could just treat unknown chips 596 * as ESP200 but then we would most 597 * likely drive them out of specs. 598 */ 599 device_printf(esc->sc_dev, 600 "Unknown chip\n"); | 478 /* 479 * The `ESC' DMA chip must be reset before we can access 480 * the ESP registers. 481 */ 482 if (esc->sc_dma->sc_rev == DMAREV_ESC) 483 DMA_RESET(esc->sc_dma); 484 485 /* --- 77 unchanged lines hidden (view full) --- 563 default: 564 /* 565 * We could just treat unknown chips 566 * as ESP200 but then we would most 567 * likely drive them out of specs. 568 */ 569 device_printf(esc->sc_dev, 570 "Unknown chip\n"); |
601 return (ENXIO); | 571 goto fail_lsi; |
602 } 603 } 604 } 605 } 606 607#ifdef ESP_SBUS_DEBUG 608 printf("%s: revision %d, uid 0x%x\n", __func__, sc->sc_rev, uid); 609#endif --- 20 unchanged lines hidden (view full) --- 630 631 /* 632 * Alas, we must now modify the value a bit, because it's 633 * only valid when can switch on FASTCLK and FASTSCSI bits 634 * in config register 3... 635 */ 636 switch (sc->sc_rev) { 637 case NCR_VARIANT_ESP100: | 572 } 573 } 574 } 575 } 576 577#ifdef ESP_SBUS_DEBUG 578 printf("%s: revision %d, uid 0x%x\n", __func__, sc->sc_rev, uid); 579#endif --- 20 unchanged lines hidden (view full) --- 600 601 /* 602 * Alas, we must now modify the value a bit, because it's 603 * only valid when can switch on FASTCLK and FASTSCSI bits 604 * in config register 3... 605 */ 606 switch (sc->sc_rev) { 607 case NCR_VARIANT_ESP100: |
638 sc->sc_maxwidth = 0; | 608 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_8_BIT; |
639 sc->sc_maxxfer = 64 * 1024; 640 sc->sc_minsync = 0; /* No synch on old chip? */ 641 break; 642 643 case NCR_VARIANT_ESP100A: | 609 sc->sc_maxxfer = 64 * 1024; 610 sc->sc_minsync = 0; /* No synch on old chip? */ 611 break; 612 613 case NCR_VARIANT_ESP100A: |
644 sc->sc_maxwidth = 0; | 614 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_8_BIT; |
645 sc->sc_maxxfer = 64 * 1024; 646 /* Min clocks/byte is 5 */ 647 sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5); 648 break; 649 650 case NCR_VARIANT_ESP200: | 615 sc->sc_maxxfer = 64 * 1024; 616 /* Min clocks/byte is 5 */ 617 sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5); 618 break; 619 620 case NCR_VARIANT_ESP200: |
651 sc->sc_maxwidth = 0; | 621 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_8_BIT; |
652 sc->sc_maxxfer = 16 * 1024 * 1024; 653 /* Min clocks/byte is 5 */ 654 sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5); 655 break; 656 657 case NCR_VARIANT_FAS100A: 658 case NCR_VARIANT_FAS216: 659 case NCR_VARIANT_FAS236: --- 5 unchanged lines hidden (view full) --- 665 * instead which seems to be correct as otherwise sync 666 * negotiation just doesn't work. Using NCRF9XCFG3_FCLK 667 * and NCRF9XCFG3_FSCSI with these chips in fact also 668 * yields Fast-SCSI speed. 669 */ 670 sc->sc_features = NCR_F_FASTSCSI; 671 sc->sc_cfg3 = NCRF9XCFG3_FCLK; 672 sc->sc_cfg3_fscsi = NCRF9XCFG3_FSCSI; | 622 sc->sc_maxxfer = 16 * 1024 * 1024; 623 /* Min clocks/byte is 5 */ 624 sc->sc_minsync = ncr53c9x_cpb2stp(sc, 5); 625 break; 626 627 case NCR_VARIANT_FAS100A: 628 case NCR_VARIANT_FAS216: 629 case NCR_VARIANT_FAS236: --- 5 unchanged lines hidden (view full) --- 635 * instead which seems to be correct as otherwise sync 636 * negotiation just doesn't work. Using NCRF9XCFG3_FCLK 637 * and NCRF9XCFG3_FSCSI with these chips in fact also 638 * yields Fast-SCSI speed. 639 */ 640 sc->sc_features = NCR_F_FASTSCSI; 641 sc->sc_cfg3 = NCRF9XCFG3_FCLK; 642 sc->sc_cfg3_fscsi = NCRF9XCFG3_FSCSI; |
673 sc->sc_maxwidth = 0; | 643 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_8_BIT; |
674 sc->sc_maxxfer = 16 * 1024 * 1024; 675 break; 676 677 case NCR_VARIANT_FAS366: | 644 sc->sc_maxxfer = 16 * 1024 * 1024; 645 break; 646 647 case NCR_VARIANT_FAS366: |
678 sc->sc_maxwidth = 1; | 648 sc->sc_maxwidth = MSG_EXT_WDTR_BUS_16_BIT; |
679 sc->sc_maxxfer = 16 * 1024 * 1024; 680 break; 681 } 682 | 649 sc->sc_maxxfer = 16 * 1024 * 1024; 650 break; 651 } 652 |
683 /* Limit minsync due to unsolved performance issues. */ 684 sc->sc_maxsync = sc->sc_minsync; 685 | |
686 /* Establish interrupt channel. */ | 653 /* Establish interrupt channel. */ |
687 esc->sc_irqrid = 0; | 654 i = 0; |
688 if ((esc->sc_irqres = bus_alloc_resource_any(esc->sc_dev, SYS_RES_IRQ, | 655 if ((esc->sc_irqres = bus_alloc_resource_any(esc->sc_dev, SYS_RES_IRQ, |
689 &esc->sc_irqrid, RF_SHAREABLE|RF_ACTIVE)) == NULL) { | 656 &i, RF_SHAREABLE|RF_ACTIVE)) == NULL) { |
690 device_printf(esc->sc_dev, "cannot allocate interrupt\n"); | 657 device_printf(esc->sc_dev, "cannot allocate interrupt\n"); |
691 return (ENXIO); | 658 goto fail_lsi; |
692 } 693 if (bus_setup_intr(esc->sc_dev, esc->sc_irqres, | 659 } 660 if (bus_setup_intr(esc->sc_dev, esc->sc_irqres, |
694 INTR_TYPE_BIO, NULL, ncr53c9x_intr, sc, &esc->sc_irq)) { | 661 INTR_MPSAFE | INTR_TYPE_CAM, NULL, ncr53c9x_intr, sc, 662 &esc->sc_irq)) { |
695 device_printf(esc->sc_dev, "cannot set up interrupt\n"); 696 error = ENXIO; 697 goto fail_ires; 698 } 699 700 /* Turn on target selection using the `DMA' method. */ 701 if (sc->sc_rev != NCR_VARIANT_FAS366) 702 sc->sc_features |= NCR_F_DMASELECT; --- 6 unchanged lines hidden (view full) --- 709 goto fail_intr; 710 } 711 712 return (0); 713 714 fail_intr: 715 bus_teardown_intr(esc->sc_dev, esc->sc_irqres, esc->sc_irq); 716 fail_ires: | 663 device_printf(esc->sc_dev, "cannot set up interrupt\n"); 664 error = ENXIO; 665 goto fail_ires; 666 } 667 668 /* Turn on target selection using the `DMA' method. */ 669 if (sc->sc_rev != NCR_VARIANT_FAS366) 670 sc->sc_features |= NCR_F_DMASELECT; --- 6 unchanged lines hidden (view full) --- 677 goto fail_intr; 678 } 679 680 return (0); 681 682 fail_intr: 683 bus_teardown_intr(esc->sc_dev, esc->sc_irqres, esc->sc_irq); 684 fail_ires: |
717 bus_release_resource(esc->sc_dev, SYS_RES_IRQ, esc->sc_irqrid, 718 esc->sc_irqres); | 685 bus_release_resource(esc->sc_dev, SYS_RES_IRQ, 686 rman_get_rid(esc->sc_irqres), esc->sc_irqres); 687 fail_lsi: 688 lsi64854_detach(esc->sc_dma); 689 fail_lock: 690 NCR_LOCK_DESTROY(sc); |
719 return (error); 720} 721 | 691 return (error); 692} 693 |
694static int 695espdetach(struct esp_softc *esc) 696{ 697 struct ncr53c9x_softc *sc = &esc->sc_ncr53c9x; 698 int error; 699 700 bus_teardown_intr(esc->sc_dev, esc->sc_irqres, esc->sc_irq); 701 error = ncr53c9x_detach(sc); 702 if (error != 0) 703 return (error); 704 error = lsi64854_detach(esc->sc_dma); 705 if (error != 0) 706 return (error); 707 NCR_LOCK_DESTROY(sc); 708 bus_release_resource(esc->sc_dev, SYS_RES_IRQ, 709 rman_get_rid(esc->sc_irqres), esc->sc_irqres); 710 711 return (0); 712} 713 |
|
722/* 723 * Glue functions 724 */ 725 726#ifdef ESP_SBUS_DEBUG | 714/* 715 * Glue functions 716 */ 717 718#ifdef ESP_SBUS_DEBUG |
727int esp_sbus_debug = 0; | 719static int esp_sbus_debug = 0; |
728 | 720 |
729static struct { | 721static const struct { |
730 char *r_name; 731 int r_flag; 732} esp__read_regnames [] = { 733 { "TCL", 0}, /* 0/00 */ 734 { "TCM", 0}, /* 1/04 */ 735 { "FIFO", 0}, /* 2/08 */ 736 { "CMD", 0}, /* 3/0c */ 737 { "STAT", 0}, /* 4/10 */ --- 5 unchanged lines hidden (view full) --- 743 { "CFG4", 1}, /* a/28 */ 744 { "CFG2", 1}, /* b/2c */ 745 { "CFG3", 1}, /* c/30 */ 746 { "-none", 1}, /* d/34 */ 747 { "TCH", 1}, /* e/38 */ 748 { "TCX", 1}, /* f/3c */ 749}; 750 | 722 char *r_name; 723 int r_flag; 724} esp__read_regnames [] = { 725 { "TCL", 0}, /* 0/00 */ 726 { "TCM", 0}, /* 1/04 */ 727 { "FIFO", 0}, /* 2/08 */ 728 { "CMD", 0}, /* 3/0c */ 729 { "STAT", 0}, /* 4/10 */ --- 5 unchanged lines hidden (view full) --- 735 { "CFG4", 1}, /* a/28 */ 736 { "CFG2", 1}, /* b/2c */ 737 { "CFG3", 1}, /* c/30 */ 738 { "-none", 1}, /* d/34 */ 739 { "TCH", 1}, /* e/38 */ 740 { "TCX", 1}, /* f/3c */ 741}; 742 |
751static struct { | 743static const struct { |
752 char *r_name; 753 int r_flag; 754} esp__write_regnames[] = { 755 { "TCL", 1}, /* 0/00 */ 756 { "TCM", 1}, /* 1/04 */ 757 { "FIFO", 0}, /* 2/08 */ 758 { "CMD", 0}, /* 3/0c */ 759 { "SELID", 1}, /* 4/10 */ --- 12 unchanged lines hidden (view full) --- 772#endif 773 774static u_char 775esp_read_reg(struct ncr53c9x_softc *sc, int reg) 776{ 777 struct esp_softc *esc = (struct esp_softc *)sc; 778 u_char v; 779 | 744 char *r_name; 745 int r_flag; 746} esp__write_regnames[] = { 747 { "TCL", 1}, /* 0/00 */ 748 { "TCM", 1}, /* 1/04 */ 749 { "FIFO", 0}, /* 2/08 */ 750 { "CMD", 0}, /* 3/0c */ 751 { "SELID", 1}, /* 4/10 */ --- 12 unchanged lines hidden (view full) --- 764#endif 765 766static u_char 767esp_read_reg(struct ncr53c9x_softc *sc, int reg) 768{ 769 struct esp_softc *esc = (struct esp_softc *)sc; 770 u_char v; 771 |
780 v = bus_space_read_1(esc->sc_regt, esc->sc_regh, reg * 4); | 772 v = bus_read_1(esc->sc_res, reg * 4); 773 |
781#ifdef ESP_SBUS_DEBUG 782 if (esp_sbus_debug && (reg < 0x10) && esp__read_regnames[reg].r_flag) | 774#ifdef ESP_SBUS_DEBUG 775 if (esp_sbus_debug && (reg < 0x10) && esp__read_regnames[reg].r_flag) |
783 printf("RD:%x <%s> %x\n", reg * 4, 784 ((unsigned)reg < 0x10) ? esp__read_regnames[reg].r_name : "<***>", v); | 776 printf("RD:%x <%s> %x\n", reg * 4, ((unsigned)reg < 0x10) ? 777 esp__read_regnames[reg].r_name : "<***>", v); |
785#endif | 778#endif |
786 return v; | 779 780 return (v); |
787} 788 789static void 790esp_write_reg(struct ncr53c9x_softc *sc, int reg, u_char v) 791{ 792 struct esp_softc *esc = (struct esp_softc *)sc; 793 794#ifdef ESP_SBUS_DEBUG 795 if (esp_sbus_debug && (reg < 0x10) && esp__write_regnames[reg].r_flag) | 781} 782 783static void 784esp_write_reg(struct ncr53c9x_softc *sc, int reg, u_char v) 785{ 786 struct esp_softc *esc = (struct esp_softc *)sc; 787 788#ifdef ESP_SBUS_DEBUG 789 if (esp_sbus_debug && (reg < 0x10) && esp__write_regnames[reg].r_flag) |
796 printf("WR:%x <%s> %x\n", reg * 4, 797 ((unsigned)reg < 0x10) ? esp__write_regnames[reg].r_name : "<***>", v); | 790 printf("WR:%x <%s> %x\n", reg * 4, ((unsigned)reg < 0x10) ? 791 esp__write_regnames[reg].r_name : "<***>", v); |
798#endif | 792#endif |
799 bus_space_write_1(esc->sc_regt, esc->sc_regh, reg * 4, v); | 793 794 bus_write_1(esc->sc_res, reg * 4, v); |
800} 801 802static int 803esp_dma_isintr(struct ncr53c9x_softc *sc) 804{ 805 struct esp_softc *esc = (struct esp_softc *)sc; 806 807 return (DMA_ISINTR(esc->sc_dma)); --- 50 unchanged lines hidden --- | 795} 796 797static int 798esp_dma_isintr(struct ncr53c9x_softc *sc) 799{ 800 struct esp_softc *esc = (struct esp_softc *)sc; 801 802 return (DMA_ISINTR(esc->sc_dma)); --- 50 unchanged lines hidden --- |