From 0c5fed7eec072264216d902ed0694bb4ffdf644f Mon Sep 17 00:00:00 2001 From: christos Date: Fri, 24 May 2002 15:58:06 +0000 Subject: [PATCH] Deal with the NBPG problem in a better way. --- sys/dev/pci/twe.c | 15 +++++++++++---- sys/dev/pci/twevar.h | 9 +-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sys/dev/pci/twe.c b/sys/dev/pci/twe.c index c95523ecead5..b4184ec4ad82 100644 --- a/sys/dev/pci/twe.c +++ b/sys/dev/pci/twe.c @@ -1,4 +1,4 @@ -/* $NetBSD: twe.c,v 1.22 2002/05/18 20:59:20 ad Exp $ */ +/* $NetBSD: twe.c,v 1.23 2002/05/24 15:58:06 christos Exp $ */ /*- * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc. @@ -70,7 +70,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: twe.c,v 1.22 2002/05/18 20:59:20 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: twe.c,v 1.23 2002/05/24 15:58:06 christos Exp $"); #include #include @@ -186,6 +186,7 @@ twe_attach(struct device *parent, struct device *self, void *aux) pcireg_t csr; const char *intrstr; int size, i, rv, rseg; + size_t max_segs, max_xfer; struct twe_param *dtp, *ctp; bus_dma_segment_t seg; struct twe_cmd *tc; @@ -269,13 +270,19 @@ twe_attach(struct device *parent, struct device *self, void *aux) ccb = malloc(sizeof(*ccb) * TWE_MAX_QUEUECNT, M_DEVBUF, M_NOWAIT); sc->sc_ccbs = ccb; tc = (struct twe_cmd *)sc->sc_cmds; + max_segs = ((MAXPHYS + PAGE_SIZE - 1) / PAGE_SIZE) + 1; +#ifdef TWE_SG_SIZE + if (TWE_SG_SIZE < max_segs) + max_segs = TWE_SG_SIZE; +#endif + max_xfer = (max_segs - 1) * PAGE_SIZE; for (i = 0; i < TWE_MAX_QUEUECNT; i++, tc++, ccb++) { ccb->ccb_cmd = tc; ccb->ccb_cmdid = i; ccb->ccb_flags = 0; - rv = bus_dmamap_create(sc->sc_dmat, TWE_MAX_XFER, - TWE_MAX_SEGS, PAGE_SIZE, 0, + rv = bus_dmamap_create(sc->sc_dmat, max_xfer, + max_segs, PAGE_SIZE, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &ccb->ccb_dmamap_xfer); if (rv != 0) { diff --git a/sys/dev/pci/twevar.h b/sys/dev/pci/twevar.h index aa9c2a404715..d79b9fffc41b 100644 --- a/sys/dev/pci/twevar.h +++ b/sys/dev/pci/twevar.h @@ -1,4 +1,4 @@ -/* $NetBSD: twevar.h,v 1.10 2002/05/18 20:59:20 ad Exp $ */ +/* $NetBSD: twevar.h,v 1.11 2002/05/24 15:58:06 christos Exp $ */ /*- * Copyright (c) 2000, 2001, 2002 The NetBSD Foundation, Inc. @@ -43,13 +43,6 @@ #define TWE_MAX_QUEUECNT 129 -#if TWE_SG_SIZE > (((MAXPHYS + PAGE_SIZE - 1) / PAGE_SIZE) + 1) -#define TWE_MAX_SEGS (((MAXPHYS + PAGE_SIZE - 1) / PAGE_SIZE) + 1) -#else -#define TWE_MAX_SEGS TWE_SG_SIZE -#endif -#define TWE_MAX_XFER ((TWE_MAX_SEGS - 1) * PAGE_SIZE) - /* Per-controller state. */ struct twe_softc { struct device sc_dv;