From d3de56d87fddfd34e06ff6982c350d9341cd5d50 Mon Sep 17 00:00:00 2001 From: Peter Avalos Date: Sat, 5 Jan 2008 07:27:09 +0000 Subject: [PATCH] Sync with FreeBSD: Eliminate support for oldcard by removing the compat shims. Convert callers to the new bus_alloc_resource_any(9) API. Initialize variable to fix possible warning. Use cam_calc_geometry(). Be consistent about "static" functions. Support for LG GM82C700, an AIC6360 clone. Add PnP IDs for AHA-1530 and AHA-1520 cards. Enable 10MHz (fast SCSI) operation on boards that support it. Bounds check sync periods and offsets passed in from the transport layer. Tell the user which resource allocation failed (for the ISA probe) if we weren't able to allocate an IRQ, DRQ or I/O port. Remove unneeded includes. Obtained-from: FreeBSD --- sys/dev/disk/aic/aic.c | 79 +++++++++++++++++++++++++++---------------- sys/dev/disk/aic/aic6360reg.h | 10 ++++-- sys/dev/disk/aic/aic_isa.c | 26 +++++++++----- sys/dev/disk/aic/aic_pccard.c | 38 +++++---------------- sys/dev/disk/aic/aicvar.h | 11 +++++- 5 files changed, 92 insertions(+), 72 deletions(-) diff --git a/sys/dev/disk/aic/aic.c b/sys/dev/disk/aic/aic.c index 336ee81a10..2b91e04bed 100644 --- a/sys/dev/disk/aic/aic.c +++ b/sys/dev/disk/aic/aic.c @@ -24,20 +24,15 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aic/aic.c,v 1.8 2000/01/14 23:42:35 imp Exp $ - * $DragonFly: src/sys/dev/disk/aic/aic.c,v 1.11 2008/01/02 11:41:52 hasso Exp $ + * $DragonFly: src/sys/dev/disk/aic/aic.c,v 1.12 2008/01/05 07:27:09 pavalos Exp $ */ #include #include -#include -#include #include -#include #include #include -#include - #include #include #include @@ -326,25 +321,7 @@ aic_action(struct cam_sim *sim, union ccb *ccb) } case XPT_CALC_GEOMETRY: { - struct ccb_calc_geometry *ccg; - u_int32_t size_mb; - u_int32_t secs_per_cylinder; - int extended = 0; - - ccg = &ccb->ccg; - size_mb = ccg->volume_size - / ((1024L * 1024L) / ccg->block_size); - - if (size_mb >= 1024 && extended) { - ccg->heads = 255; - ccg->secs_per_track = 63; - } else { - ccg->heads = 64; - ccg->secs_per_track = 32; - } - secs_per_cylinder = ccg->heads * ccg->secs_per_track; - ccg->cylinders = ccg->volume_size / secs_per_cylinder; - ccb->ccb_h.status = CAM_REQ_CMP; + cam_calc_geometry(&ccb->ccg, /*extended*/1); xpt_done(ccb); break; } @@ -576,7 +553,7 @@ aic_spiordy(struct aic_softc *aic) /* * Reestablish a disconnected nexus. */ -void +static void aic_reconnect(struct aic_softc *aic, int tag) { struct aic_scb *scb; @@ -585,6 +562,7 @@ aic_reconnect(struct aic_softc *aic, int tag) CAM_DEBUG_PRINT(CAM_DEBUG_TRACE, ("aic_reconnect\n")); /* Find the nexus */ + scb = NULL; TAILQ_FOREACH(ccb_h, &aic->nexus_ccbs, sim_links.tqe) { scb = (struct aic_scb *)ccb_h->ccb_scb_ptr; if (scb->target == aic->target && scb->lun == aic->lun && @@ -1501,12 +1479,26 @@ aic_reset(struct aic_softc *aic, int initiate_reset) aic_outb(aic, DMACNTRL0, INTEN); } +static char *aic_chip_names[] = { + "AIC6260", "AIC6360", "AIC6370", "GM82C700", +}; + +static struct { + int type; + char *idstring; +} aic_chip_ids[] = { + { AIC6360, IDSTRING_AIC6360 }, + { AIC6370, IDSTRING_AIC6370 }, + { GM82C700, IDSTRING_GM82C700 }, +}; + static void aic_init(struct aic_softc *aic) { struct aic_scb *scb; struct aic_tinfo *ti; u_int8_t porta, portb; + char chip_id[33]; int i; TAILQ_INIT(&aic->pending_ccbs); @@ -1519,6 +1511,17 @@ aic_init(struct aic_softc *aic) aic_chip_reset(aic); aic_scsi_reset(aic); + /* determine the chip type from its ID string */ + aic->chip_type = AIC6260; + aic_insb(aic, ID, chip_id, sizeof(chip_id) - 1); + chip_id[sizeof(chip_id) - 1] = '\0'; + for (i = 0; i < sizeof(aic_chip_ids) / sizeof(aic_chip_ids[0]); i++) { + if (!strcmp(chip_id, aic_chip_ids[i].idstring)) { + aic->chip_type = aic_chip_ids[i].type; + break; + } + } + porta = aic_inb(aic, PORTA); portb = aic_inb(aic, PORTB); @@ -1529,8 +1532,23 @@ aic_init(struct aic_softc *aic) aic->flags |= AIC_DISC_ENABLE; if (PORTB_DMA(portb)) aic->flags |= AIC_DMA_ENABLE; - if (aic_inb(aic, REV)) + + /* + * We can do fast SCSI (10MHz clock rate) if bit 4 of portb + * is set and we've got a 6360. The 6260 can only do standard + * 5MHz SCSI. + */ + if (aic->chip_type > AIC6260 || aic_inb(aic, REV)) { + if (PORTB_FSYNC(portb)) + aic->flags |= AIC_FAST_ENABLE; aic->flags |= AIC_DWIO_ENABLE; + } + + if (aic->flags & AIC_FAST_ENABLE) + aic->max_period = AIC_FAST_SYNC_PERIOD; + else + aic->max_period = AIC_SYNC_PERIOD; + aic->min_period = AIC_MIN_SYNC_PERIOD; free_scbs = NULL; for (i = 255; i >= 0; i--) { @@ -1547,7 +1565,7 @@ aic_init(struct aic_softc *aic) ti->flags = TINFO_TAG_ENB; if (aic->flags & AIC_DISC_ENABLE) ti->flags |= TINFO_DISC_ENB; - ti->user.period = AIC_SYNC_PERIOD; + ti->user.period = aic->max_period; ti->user.offset = AIC_SYNC_OFFSET; ti->scsirate = 0; } @@ -1604,14 +1622,15 @@ aic_attach(struct aic_softc *aic) aic_init(aic); - kprintf("aic%d: %s", aic->unit, - aic_inb(aic, REV) > 0 ? "aic6360" : "aic6260"); + kprintf("aic%d: %s", aic->unit, aic_chip_names[aic->chip_type]); if (aic->flags & AIC_DMA_ENABLE) kprintf(", dma"); if (aic->flags & AIC_DISC_ENABLE) kprintf(", disconnection"); if (aic->flags & AIC_PARITY_ENABLE) kprintf(", parity check"); + if (aic->flags & AIC_FAST_ENABLE) + kprintf(", fast SCSI"); kprintf("\n"); return (0); } diff --git a/sys/dev/disk/aic/aic6360reg.h b/sys/dev/disk/aic/aic6360reg.h index 9563971465..6a8a55314f 100644 --- a/sys/dev/disk/aic/aic6360reg.h +++ b/sys/dev/disk/aic/aic6360reg.h @@ -1,4 +1,4 @@ -/* +/*- * Copyright (c) 1994 Charles Hannum. * Copyright (c) 1994 Jarle Greipsland. * All rights reserved. @@ -30,7 +30,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aic/aic6360reg.h,v 1.1 1999/10/21 08:56:52 luoqi Exp $ - * $DragonFly: src/sys/dev/disk/aic/aic6360reg.h,v 1.2 2003/06/17 04:28:21 dillon Exp $ + * $DragonFly: src/sys/dev/disk/aic/aic6360reg.h,v 1.3 2008/01/05 07:27:09 pavalos Exp $ */ #define SCSISEQ 0x00 /* SCSI sequence control */ @@ -73,7 +73,9 @@ #define TEST 0x1e /* Test register */ #define ID 0x1f /* ID register */ -#define IDSTRING "(C)1991ADAPTECAIC6360 " +#define IDSTRING_AIC6360 "(C)1991ADAPTECAIC6360 " +#define IDSTRING_AIC6370 "(C)1994ADAPTECAIC6370" +#define IDSTRING_GM82C700 "(C)1993 GoldStarGM82C700 " /* What all the bits do */ @@ -321,8 +323,10 @@ #define PORTA_PARITY(a) ((a) & 0x80) /* PORTB */ +#define PORTB_EXTTRAN(b)((b) & 1) #define PORTB_DISC(b) ((b) & 4) #define PORTB_SYNC(b) ((b) & 8) +#define PORTB_FSYNC(b) ((b) & 0x10) #define PORTB_BOOT(b) ((b) & 0x40) #define PORTB_DMA(b) ((b) & 0x80) diff --git a/sys/dev/disk/aic/aic_isa.c b/sys/dev/disk/aic/aic_isa.c index 8fd1bfd794..b8f8f94a4b 100644 --- a/sys/dev/disk/aic/aic_isa.c +++ b/sys/dev/disk/aic/aic_isa.c @@ -24,11 +24,10 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aic/aic_isa.c,v 1.3 2000/01/14 23:42:35 imp Exp $ - * $DragonFly: src/sys/dev/disk/aic/aic_isa.c,v 1.7 2006/10/25 20:55:53 dillon Exp $ + * $DragonFly: src/sys/dev/disk/aic/aic_isa.c,v 1.8 2008/01/05 07:27:09 pavalos Exp $ */ #include -#include #include #include #include @@ -55,6 +54,12 @@ static u_int aic_isa_ports[] = { 0x340, 0x140 }; #define AIC_ISA_NUMPORTS (sizeof(aic_isa_ports) / sizeof(aic_isa_ports[0])) #define AIC_ISA_PORTSIZE 0x20 +static struct isa_pnp_id aic_ids[] = { + { 0x15309004, "Adaptec AHA-1530P" }, + { 0x15209004, "Adaptec AHA-1520P" }, + { 0 } +}; + static int aic_isa_alloc_resources(device_t dev) { @@ -66,14 +71,17 @@ aic_isa_alloc_resources(device_t dev) rid = 0; sc->sc_port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0ul, ~0ul, AIC_ISA_PORTSIZE, RF_ACTIVE); - if (!sc->sc_port) + if (!sc->sc_port) { + device_printf(dev, "I/O port allocation failed\n"); return (ENOMEM); + } if (isa_get_irq(dev) != -1) { rid = 0; - sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, - 0ul, ~0ul, 1, RF_ACTIVE); + sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, + RF_ACTIVE); if (!sc->sc_irq) { + device_printf(dev, "IRQ allocation failed\n"); aic_isa_release_resources(dev); return (ENOMEM); } @@ -81,9 +89,10 @@ aic_isa_alloc_resources(device_t dev) if (isa_get_drq(dev) != -1) { rid = 0; - sc->sc_drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid, - 0ul, ~0ul, 1, RF_ACTIVE); + sc->sc_drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &rid, + RF_ACTIVE); if (!sc->sc_drq) { + device_printf(dev, "DRQ allocation failed\n"); aic_isa_release_resources(dev); return (ENOMEM); } @@ -118,7 +127,7 @@ aic_isa_probe(device_t dev) u_int port, *ports; u_int8_t porta; - if (isa_get_vendorid(dev)) + if (ISA_PNP_PROBE(device_get_parent(dev), dev, aic_ids) == ENXIO) return (ENXIO); port = isa_get_port(dev); @@ -222,4 +231,5 @@ static driver_t aic_isa_driver = { extern devclass_t aic_devclass; +MODULE_DEPEND(aic, cam, 1,1,1); DRIVER_MODULE(aic, isa, aic_isa_driver, aic_devclass, 0, 0); diff --git a/sys/dev/disk/aic/aic_pccard.c b/sys/dev/disk/aic/aic_pccard.c index 268978adb8..6fc5d61210 100644 --- a/sys/dev/disk/aic/aic_pccard.c +++ b/sys/dev/disk/aic/aic_pccard.c @@ -24,17 +24,15 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aic/aic_pccard.c,v 1.1 2000/01/14 23:42:36 imp Exp $ - * $DragonFly: src/sys/dev/disk/aic/aic_pccard.c,v 1.8 2006/10/25 20:55:53 dillon Exp $ + * $DragonFly: src/sys/dev/disk/aic/aic_pccard.c,v 1.9 2008/01/05 07:27:09 pavalos Exp $ */ #include -#include #include #include #include #include -#include "aic6360reg.h" #include "aicvar.h" #include @@ -51,7 +49,6 @@ struct aic_pccard_softc { static int aic_pccard_alloc_resources (device_t); static void aic_pccard_release_resources (device_t); -static int aic_pccard_match(device_t); static int aic_pccard_probe (device_t); static int aic_pccard_attach (device_t); @@ -81,8 +78,7 @@ aic_pccard_alloc_resources(device_t dev) return (ENOMEM); rid = 0; - sc->sc_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, - 0ul, ~0ul, 1, RF_ACTIVE); + sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE); if (!sc->sc_irq) { aic_pccard_release_resources(dev); return (ENOMEM); @@ -107,7 +103,7 @@ aic_pccard_release_resources(device_t dev) } static int -aic_pccard_match(device_t dev) +aic_pccard_probe(device_t dev) { const struct pccard_product *pp; @@ -121,10 +117,11 @@ aic_pccard_match(device_t dev) } static int -aic_pccard_probe(device_t dev) +aic_pccard_attach(device_t dev) { struct aic_pccard_softc *sc = device_get_softc(dev); struct aic_softc *aic = &sc->sc_aic; + int error; if (aic_pccard_alloc_resources(dev)) return (ENXIO); @@ -132,24 +129,8 @@ aic_pccard_probe(device_t dev) aic_pccard_release_resources(dev); return (ENXIO); } - aic_pccard_release_resources(dev); device_set_desc(dev, "Adaptec 6260/6360 SCSI controller"); - return (0); -} - -static int -aic_pccard_attach(device_t dev) -{ - struct aic_pccard_softc *sc = device_get_softc(dev); - struct aic_softc *aic = &sc->sc_aic; - int error; - - error = aic_pccard_alloc_resources(dev); - if (error) { - device_printf(dev, "resource allocation failed\n"); - return (error); - } error = aic_attach(aic); if (error) { @@ -192,14 +173,10 @@ aic_pccard_detach(device_t dev) static device_method_t aic_pccard_methods[] = { /* Device interface */ - DEVMETHOD(device_probe, pccard_compat_probe), - DEVMETHOD(device_attach, pccard_compat_attach), + DEVMETHOD(device_probe, aic_pccard_probe), + DEVMETHOD(device_attach, aic_pccard_attach), DEVMETHOD(device_detach, aic_pccard_detach), - /* Card interface */ - DEVMETHOD(card_compat_match, aic_pccard_match), - DEVMETHOD(card_compat_probe, aic_pccard_probe), - DEVMETHOD(card_compat_attach, aic_pccard_attach), { 0, 0 } }; @@ -210,4 +187,5 @@ static driver_t aic_pccard_driver = { extern devclass_t aic_devclass; +MODULE_DEPEND(aic, cam, 1,1,1); DRIVER_MODULE(aic, pccard, aic_pccard_driver, aic_devclass, 0, 0); diff --git a/sys/dev/disk/aic/aicvar.h b/sys/dev/disk/aic/aicvar.h index 2998a57b61..5e045ab314 100644 --- a/sys/dev/disk/aic/aicvar.h +++ b/sys/dev/disk/aic/aicvar.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/aic/aicvar.h,v 1.2.2.1 2000/08/08 23:51:23 peter Exp $ - * $DragonFly: src/sys/dev/disk/aic/aicvar.h,v 1.3 2003/08/27 10:35:16 rob Exp $ + * $DragonFly: src/sys/dev/disk/aic/aicvar.h,v 1.4 2008/01/05 07:27:09 pavalos Exp $ */ struct aic_transinfo { @@ -67,6 +67,8 @@ struct aic_scb { #define SCB_DEVICE_RESET 0x04 #define SCB_SENSE 0x08 +enum { AIC6260, AIC6360, AIC6370, GM82C700 }; + struct aic_softc { int unit; bus_space_tag_t tag; @@ -92,6 +94,10 @@ struct aic_softc { struct aic_tinfo tinfo[8]; struct aic_scb scbs[256]; + + int min_period; + int max_period; + int chip_type; }; #define AIC_DISC_ENABLE 0x01 @@ -101,6 +107,7 @@ struct aic_softc { #define AIC_RESOURCE_SHORTAGE 0x10 #define AIC_DROP_MSGIN 0x20 #define AIC_BUSFREE_OK 0x40 +#define AIC_FAST_ENABLE 0x80 #define AIC_IDLE 0x00 #define AIC_SELECTING 0x01 @@ -115,6 +122,8 @@ struct aic_softc { #define AIC_MSG_MSGBUF 0x80 #define AIC_SYNC_PERIOD (200 / 4) +#define AIC_FAST_SYNC_PERIOD (100 / 4) +#define AIC_MIN_SYNC_PERIOD 112 #define AIC_SYNC_OFFSET 8 #define aic_inb(aic, port) \ -- 2.11.4.GIT