56a7c4a852
ahc_pci.c: Add detach support. Make use of soft allocated on our behalf by newbus. For PCI devices, disable the mapping type we aren't using for extra protection from rogue code. aic7xxx_93cx6.c: aic7xxx_93cx6.h: Sync perforce IDs. aic7xxx_freebsd.c: Capture the eventhandle returned by EVENTHANDER_REGISTER so we can kill the handler off during detach. Use AHC_* constants instead of hard coded numbers in a few more places. Test PPR option state when deciding to "really" negotiate when the CAM_NEGOTIATE flag is passed in a CCB. Make use of core "ahc_pause_and_flushwork" routine in our timeout handler rather than re-inventing this code. Cleanup all of our resources (really!) in ahc_platform_free(). We should be all set to become a module now. Implement the core ahc_detach() routine shared by all of the FreeBSD front-ends. aic7xxx_freebsd.h: Softc storage for our event handler. Null implementation for the ahc_platform_flushwork() OSM callback. FreeBSD doesn't need this as XPT callbacks are safe from all contexts and are done directly in ahc_done(). aic7xxx_inline.h: Implement new lazy interrupt scheme. To avoid an extra PCI bus read, we first check our completion queues to see if any work has completed. If work is available, we assume that this is the source of the interrupt and skip reading INTSTAT. Any remaining interrupt status will be cleared by a second call to the interrupt handler should the interrupt line still be asserted. This drops the interrupt handler down to a single PCI bus read in the common case of I/O completion. This is the same overhead as in the not so distant past, but the extra sanity of perforning a PCI read after clearing the command complete interrupt and before running the completion queue to avoid missing command complete interrupts added a cycle. aic7xxx.c: During initialization, be sure to initialize all scratch ram locations before they are read to avoid parity errors. In this case, we use a new function, ahc_unbusy_tcl() to initialize the scratch ram busy target table. Replace instances of ahc_index_busy_tcl() used to unbusy a tcl without looking at the old value with ahc_unbusy_tcl(). Modify ahc_sent_msg so that it can find single byte messages. ahc_sent_msg is now used to determine if a transfer negotiation attempt resulted in a bus free. Be more careful in filtering out only the SCSI interrupts of interest in ahc_handle_scsiint. Rearrange interrupt clearing code to ensure that at least one PCI transaction occurrs after hitting CLRSINT1 and writting to CLRINT. CLRSINT1 writes take a bit to take effect, and the re-arrangement provides sufficient delay to ensure the write to CLRINT is effective. The old code might report a spurious interrupt on some "fast" chipsets. export ahc-update_target_msg_request for use by OSM code. If a target does not respond to our ATN request, clear it once we move to a non-message phase. This avoids sending a MSG_NOOP in some later message out phase. Use max lun and max target constants instead of hard-coded values. Use softc storage built into our device_t under FreeBSD. Fix a bug in ahc_free() that caused us to delete resources that were not allocated. Clean up any tstate/lstate info in ahc_free(). Clear the powerdown state in ahc_reset() so that registers can be accessed. Add a preliminary function for pausing the chip and processing any posted work. Add a preliminary suspend and resume functions. aic7xxx.h: Limit the number of supported luns to 64. We don't support information unit transfers, so this is the maximum that makes sense for these chips. Add a new flag AHC_ALL_INTERRUPTS that forces the processing of all interrupt state in a single invokation of ahc_intr(). When the flag is not set, we use the lazy interrupt handling scheme. Add data structures to store controller state while we are suspended. Use constants instead of hard coded values where appropriate. Correct some harmless "unsigned/signed" conflicts. aic7xxx.seq: Only perform the SCSIBUSL fix on ULTRA2 or newer controllers. Older controllers seem to be confused by this. In target mode, ignore PHASEMIS during data phases. This bit seems to be flakey on U160 controllers acting in target mode. aic7xxx_pci.c: Add support for the 29160C CPCI adapter. Add definitions for subvendor ID information available for devices with the "9005" vendor id. We currently use this information to determine if a multi-function device doesn't have the second channel hooked up on a board. Add rudimentary power mode code so we can put the controller into the D0 state. In the future this will be an OSM callback so that in FreeBSD we don't duplicate functionality provided by the PCI code. The powerstate code was added after I'd completed my regression tests on this code. Only capture "left over BIOS state" if the POWRDN setting is not set in HCNTRL. In target mode, don't bother sending incremental CRC data.
210 lines
5.4 KiB
C
210 lines
5.4 KiB
C
/*
|
|
* FreeBSD, EISA product support functions
|
|
*
|
|
*
|
|
* Copyright (c) 1994, 1995, 1996, 1997, 1998, 2000 Justin T. Gibbs.
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice immediately at the beginning of the file, without modification,
|
|
* this list of conditions, and the following disclaimer.
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* $Id$
|
|
*
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
#include <dev/aic7xxx/aic7xxx_freebsd.h>
|
|
|
|
#include <dev/eisa/eisaconf.h>
|
|
|
|
static int
|
|
aic7770_probe(device_t dev)
|
|
{
|
|
struct aic7770_identity *entry;
|
|
struct resource *regs;
|
|
uint32_t iobase;
|
|
bus_space_handle_t bsh;
|
|
bus_space_tag_t tag;
|
|
u_int irq;
|
|
u_int intdef;
|
|
u_int hcntrl;
|
|
int shared;
|
|
int rid;
|
|
int error;
|
|
|
|
entry = aic7770_find_device(eisa_get_id(dev));
|
|
if (entry == NULL)
|
|
return (ENXIO);
|
|
device_set_desc(dev, entry->name);
|
|
|
|
iobase = (eisa_get_slot(dev) * EISA_SLOT_SIZE) + AHC_EISA_SLOT_OFFSET;
|
|
|
|
eisa_add_iospace(dev, iobase, AHC_EISA_IOSIZE, RESVADDR_NONE);
|
|
|
|
regs = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
|
|
0, ~0, 1, RF_ACTIVE);
|
|
if (regs == NULL) {
|
|
device_printf(dev, "Unable to map I/O space?!\n");
|
|
return ENOMEM;
|
|
}
|
|
|
|
tag = rman_get_bustag(regs);
|
|
bsh = rman_get_bushandle(regs);
|
|
error = 0;
|
|
|
|
/* Pause the card preseving the IRQ type */
|
|
hcntrl = bus_space_read_1(tag, bsh, HCNTRL) & IRQMS;
|
|
bus_space_write_1(tag, bsh, HCNTRL, hcntrl | PAUSE);
|
|
while ((bus_space_read_1(tag, bsh, HCNTRL) & PAUSE) == 0)
|
|
;
|
|
|
|
/* Make sure we have a valid interrupt vector */
|
|
intdef = bus_space_read_1(tag, bsh, INTDEF);
|
|
shared = (intdef & EDGE_TRIG) ? EISA_TRIGGER_EDGE : EISA_TRIGGER_LEVEL;
|
|
irq = intdef & VECTOR;
|
|
switch (irq) {
|
|
case 9:
|
|
case 10:
|
|
case 11:
|
|
case 12:
|
|
case 14:
|
|
case 15:
|
|
break;
|
|
default:
|
|
printf("aic7770 at slot %d: illegal irq setting %d\n",
|
|
eisa_get_slot(dev), intdef);
|
|
error = ENXIO;
|
|
}
|
|
|
|
if (error == 0)
|
|
eisa_add_intr(dev, irq, shared);
|
|
|
|
bus_release_resource(dev, SYS_RES_IOPORT, rid, regs);
|
|
return (error);
|
|
}
|
|
|
|
static int
|
|
aic7770_attach(device_t dev)
|
|
{
|
|
struct aic7770_identity *entry;
|
|
struct ahc_softc *ahc;
|
|
char *name;
|
|
int error;
|
|
|
|
entry = aic7770_find_device(eisa_get_id(dev));
|
|
if (entry == NULL)
|
|
return (ENXIO);
|
|
|
|
/*
|
|
* Allocate a softc for this card and
|
|
* set it up for attachment by our
|
|
* common detect routine.
|
|
*/
|
|
name = malloc(strlen(device_get_nameunit(dev)) + 1, M_DEVBUF, M_NOWAIT);
|
|
if (name == NULL)
|
|
return (ENOMEM);
|
|
strcpy(name, device_get_nameunit(dev));
|
|
ahc = ahc_alloc(NULL, name);
|
|
if (ahc == NULL)
|
|
return (ENOMEM);
|
|
|
|
/* Allocate a dmatag for our SCB DMA maps */
|
|
/* XXX Should be a child of the PCI bus dma tag */
|
|
error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
|
|
/*boundary*/0,
|
|
/*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
|
|
/*highaddr*/BUS_SPACE_MAXADDR,
|
|
/*filter*/NULL, /*filterarg*/NULL,
|
|
/*maxsize*/MAXBSIZE, /*nsegments*/AHC_NSEG,
|
|
/*maxsegsz*/AHC_MAXTRANSFER_SIZE,
|
|
/*flags*/BUS_DMA_ALLOCNOW,
|
|
&ahc->parent_dmat);
|
|
|
|
if (error != 0) {
|
|
printf("ahc_eisa_attach: Could not allocate DMA tag "
|
|
"- error %d\n", error);
|
|
ahc_free(ahc);
|
|
return (ENOMEM);
|
|
}
|
|
ahc->dev_softc = dev;
|
|
error = aic7770_config(ahc, entry);
|
|
if (error != 0) {
|
|
ahc_free(ahc);
|
|
return (error);
|
|
}
|
|
|
|
ahc_attach(ahc);
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
aic7770_map_registers(struct ahc_softc *ahc)
|
|
{
|
|
struct resource *regs;
|
|
int rid;
|
|
|
|
regs = bus_alloc_resource(ahc->dev_softc, SYS_RES_IOPORT,
|
|
&rid, 0, ~0, 1, RF_ACTIVE);
|
|
if (regs == NULL) {
|
|
device_printf(ahc->dev_softc, "Unable to map I/O space?!\n");
|
|
return ENOMEM;
|
|
}
|
|
ahc->platform_data->regs_res_type = SYS_RES_IOPORT;
|
|
ahc->platform_data->regs_res_id = rid,
|
|
ahc->platform_data->regs = regs;
|
|
ahc->tag = rman_get_bustag(regs);
|
|
ahc->bsh = rman_get_bushandle(regs);
|
|
return (0);
|
|
}
|
|
|
|
int
|
|
aic7770_map_int(struct ahc_softc *ahc)
|
|
{
|
|
int zero;
|
|
|
|
zero = 0;
|
|
ahc->platform_data->irq =
|
|
bus_alloc_resource(ahc->dev_softc, SYS_RES_IRQ, &zero,
|
|
0, ~0, 1, RF_ACTIVE);
|
|
if (ahc->platform_data->irq == NULL)
|
|
return (ENOMEM);
|
|
ahc->platform_data->irq_res_type = SYS_RES_IRQ;
|
|
return (0);
|
|
}
|
|
|
|
static device_method_t ahc_eisa_methods[] = {
|
|
/* Device interface */
|
|
DEVMETHOD(device_probe, aic7770_probe),
|
|
DEVMETHOD(device_attach, aic7770_attach),
|
|
DEVMETHOD(device_detach, ahc_detach),
|
|
{ 0, 0 }
|
|
};
|
|
|
|
static driver_t ahc_eisa_driver = {
|
|
"ahc",
|
|
ahc_eisa_methods,
|
|
sizeof(struct ahc_softc)
|
|
};
|
|
|
|
static devclass_t ahc_devclass;
|
|
|
|
DRIVER_MODULE(ahc, eisa, ahc_eisa_driver, ahc_devclass, 0, 0);
|