Index: sys/cam/ata/ata_da.c =================================================================== --- sys/cam/ata/ata_da.c (revision 367665) +++ sys/cam/ata/ata_da.c (working copy) @@ -3447,8 +3447,8 @@ adasetgeom(struct ada_softc *softc, struct ccb_get maxio = softc->cpi.maxio; /* Honor max I/O size of SIM */ if (maxio == 0) maxio = DFLTPHYS; /* traditional default */ - else if (maxio > MAXPHYS) - maxio = MAXPHYS; /* for safety */ + else if (maxio > maxphys) + maxio = maxphys; /* for safety */ if (softc->flags & ADA_FLAG_CAN_48BIT) maxio = min(maxio, 65536 * softc->params.secsize); else /* 28bit ATA command limit */ Index: sys/cam/cam_compat.c =================================================================== --- sys/cam/cam_compat.c (revision 367665) +++ sys/cam/cam_compat.c (working copy) @@ -368,7 +368,7 @@ cam_compat_translate_dev_match_0x18(union ccb *ccb /* Remap the CCB into kernel address space */ bzero(&mapinfo, sizeof(mapinfo)); - cam_periph_mapmem(ccb, &mapinfo, MAXPHYS); + cam_periph_mapmem(ccb, &mapinfo, maxphys); dm = ccb->cdm.matches; /* Translate in-place: old fields are smaller */ Index: sys/cam/cam_periph.c =================================================================== --- sys/cam/cam_periph.c (revision 367665) +++ sys/cam/cam_periph.c (working copy) @@ -772,7 +772,7 @@ camperiphfree(struct cam_periph *periph) * Map user virtual pointers into kernel virtual address space, so we can * access the memory. This is now a generic function that centralizes most * of the sanity checks on the data flags, if any. - * This also only works for up to MAXPHYS memory. Since we use + * This also only works for up to maxphys memory. Since we use * buffers to map stuff in and out, we're limited to the buffer size. */ int @@ -788,8 +788,8 @@ cam_periph_mapmem(union ccb *ccb, struct cam_perip bzero(mapinfo, sizeof(*mapinfo)); if (maxmap == 0) maxmap = DFLTPHYS; /* traditional default */ - else if (maxmap > MAXPHYS) - maxmap = MAXPHYS; /* for safety */ + else if (maxmap > maxphys) + maxmap = maxphys; /* for safety */ switch(ccb->ccb_h.func_code) { case XPT_DEV_MATCH: if (ccb->cdm.match_buf_len == 0) { @@ -813,9 +813,9 @@ cam_periph_mapmem(union ccb *ccb, struct cam_perip } /* * This request will not go to the hardware, no reason - * to be so strict. vmapbuf() is able to map up to MAXPHYS. + * to be so strict. vmapbuf() is able to map up to maxphys. */ - maxmap = MAXPHYS; + maxmap = maxphys; break; case XPT_SCSI_IO: case XPT_CONT_TARGET_IO: @@ -881,9 +881,9 @@ cam_periph_mapmem(union ccb *ccb, struct cam_perip /* * This request will not go to the hardware, no reason - * to be so strict. vmapbuf() is able to map up to MAXPHYS. + * to be so strict. vmapbuf() is able to map up to maxphys. */ - maxmap = MAXPHYS; + maxmap = maxphys; break; default: return(EINVAL); @@ -911,7 +911,7 @@ cam_periph_mapmem(union ccb *ccb, struct cam_perip * boundary. */ misaligned[i] = (lengths[i] + - (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK) > MAXPHYS); + (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK) > maxphys); } /* Index: sys/cam/cam_xpt.c =================================================================== --- sys/cam/cam_xpt.c (revision 367665) +++ sys/cam/cam_xpt.c (working copy) @@ -553,7 +553,7 @@ xptdoioctl(struct cdev *dev, u_long cmd, caddr_t a * Map the pattern and match buffers into kernel * virtual address space. */ - error = cam_periph_mapmem(inccb, &mapinfo, MAXPHYS); + error = cam_periph_mapmem(inccb, &mapinfo, maxphys); if (error) { inccb->ccb_h.path = old_path; Index: sys/cam/ctl/ctl_backend_block.c =================================================================== --- sys/cam/ctl/ctl_backend_block.c (revision 367665) +++ sys/cam/ctl/ctl_backend_block.c (working copy) @@ -102,9 +102,11 @@ __FBSDID("$FreeBSD$"); */ #define CTLBLK_HALF_IO_SIZE (512 * 1024) #define CTLBLK_MAX_IO_SIZE (CTLBLK_HALF_IO_SIZE * 2) -#define CTLBLK_MAX_SEG MIN(CTLBLK_HALF_IO_SIZE, MAXPHYS) -#define CTLBLK_HALF_SEGS MAX(CTLBLK_HALF_IO_SIZE / CTLBLK_MAX_SEG, 1) +#define CTLBLK_MIN_SEG (128 * 1024) +#define CTLBLK_MAX_SEG MIN(CTLBLK_HALF_IO_SIZE, maxphys) +#define CTLBLK_HALF_SEGS MAX(CTLBLK_HALF_IO_SIZE / CTLBLK_MIN_SEG, 1) #define CTLBLK_MAX_SEGS (CTLBLK_HALF_SEGS * 2) +#define CTLBLK_NUM_SEGS (CTLBLK_MAX_IO_SIZE / CTLBLK_MAX_SEG) #ifdef CTLBLK_DEBUG #define DPRINTF(fmt, args...) \ @@ -189,10 +191,8 @@ struct ctl_be_block_softc { int num_luns; SLIST_HEAD(, ctl_be_block_lun) lun_list; uma_zone_t beio_zone; - uma_zone_t buf_zone; -#if (CTLBLK_MAX_SEG > 131072) - uma_zone_t buf128_zone; -#endif + uma_zone_t bufmin_zone; + uma_zone_t bufmax_zone; }; static struct ctl_be_block_softc backend_block_softc; @@ -307,12 +307,13 @@ ctl_alloc_seg(struct ctl_be_block_softc *softc, st size_t len) { -#if (CTLBLK_MAX_SEG > 131072) - if (len <= 131072) - sg->addr = uma_zalloc(softc->buf128_zone, M_WAITOK); - else -#endif - sg->addr = uma_zalloc(softc->buf_zone, M_WAITOK); + if (len <= CTLBLK_MIN_SEG) { + sg->addr = uma_zalloc(softc->bufmin_zone, M_WAITOK); + } else { + KASSERT(len <= CTLBLK_MAX_SEG, + ("Too large alloc %lu > %lu", len, CTLBLK_MAX_SEG)); + sg->addr = uma_zalloc(softc->bufmax_zone, M_WAITOK); + } sg->len = len; } @@ -320,12 +321,13 @@ static void ctl_free_seg(struct ctl_be_block_softc *softc, struct ctl_sg_entry *sg) { -#if (CTLBLK_MAX_SEG > 131072) - if (sg->len <= 131072) - uma_zfree(softc->buf128_zone, sg->addr); - else -#endif - uma_zfree(softc->buf_zone, sg->addr); + if (sg->len <= CTLBLK_MIN_SEG) { + uma_zfree(softc->bufmin_zone, sg->addr); + } else { + KASSERT(sg->len <= CTLBLK_MAX_SEG, + ("Too large free %lu > %lu", sg->len, CTLBLK_MAX_SEG)); + uma_zfree(softc->bufmax_zone, sg->addr); + } } static struct ctl_be_block_io * @@ -1344,7 +1346,7 @@ ctl_be_block_cw_dispatch_ws(struct ctl_be_block_lu else pbo = 0; len_left = (uint64_t)lbalen->len * cbe_lun->blocksize; - for (i = 0, lba = 0; i < CTLBLK_MAX_SEGS && len_left > 0; i++) { + for (i = 0, lba = 0; i < CTLBLK_NUM_SEGS && len_left > 0; i++) { /* * Setup the S/G entry for this chunk. */ @@ -1631,7 +1633,7 @@ ctl_be_block_dispatch(struct ctl_be_block_lun *be_ * Setup the S/G entry for this chunk. */ ctl_alloc_seg(softc, &beio->sg_segs[i], - min(CTLBLK_MAX_SEG, len_left)); + MIN(CTLBLK_MAX_SEG, len_left)); DPRINTF("segment %d addr %p len %zd\n", i, beio->sg_segs[i].addr, beio->sg_segs[i].len); @@ -2802,12 +2804,11 @@ ctl_be_block_init(void) mtx_init(&softc->lock, "ctlblock", NULL, MTX_DEF); softc->beio_zone = uma_zcreate("beio", sizeof(struct ctl_be_block_io), NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0); - softc->buf_zone = uma_zcreate("ctlblock", CTLBLK_MAX_SEG, + softc->bufmin_zone = uma_zcreate("ctlblockmin", CTLBLK_MIN_SEG, NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); -#if (CTLBLK_MAX_SEG > 131072) - softc->buf128_zone = uma_zcreate("ctlblock128", 131072, - NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); -#endif + if (CTLBLK_MIN_SEG < CTLBLK_MAX_SEG) + softc->bufmax_zone = uma_zcreate("ctlblockmax", CTLBLK_MAX_SEG, + NULL, NULL, NULL, NULL, /*align*/ 0, /*flags*/0); SLIST_INIT(&softc->lun_list); return (0); } @@ -2832,10 +2833,9 @@ ctl_be_block_shutdown(void) mtx_lock(&softc->lock); } mtx_unlock(&softc->lock); - uma_zdestroy(softc->buf_zone); -#if (CTLBLK_MAX_SEG > 131072) - uma_zdestroy(softc->buf128_zone); -#endif + uma_zdestroy(softc->bufmin_zone); + if (CTLBLK_MIN_SEG < CTLBLK_MAX_SEG) + uma_zdestroy(softc->bufmax_zone); uma_zdestroy(softc->beio_zone); mtx_destroy(&softc->lock); sx_destroy(&softc->modify_lock); Index: sys/cam/mmc/mmc_da.c =================================================================== --- sys/cam/mmc/mmc_da.c (revision 367665) +++ sys/cam/mmc/mmc_da.c (working copy) @@ -1587,7 +1587,7 @@ sdda_add_part(struct cam_periph *periph, u_int typ part->disk->d_name = part->name; part->disk->d_drv1 = part; part->disk->d_maxsize = - MIN(MAXPHYS, sdda_get_max_data(periph, + MIN(maxphys, sdda_get_max_data(periph, (union ccb *)&cpi) * mmc_get_sector_size(periph)); part->disk->d_unit = cnt; part->disk->d_flags = 0; Index: sys/cam/nvme/nvme_da.c =================================================================== --- sys/cam/nvme/nvme_da.c (revision 367665) +++ sys/cam/nvme/nvme_da.c (working copy) @@ -906,8 +906,8 @@ ndaregister(struct cam_periph *periph, void *arg) maxio = cpi.maxio; /* Honor max I/O size of SIM */ if (maxio == 0) maxio = DFLTPHYS; /* traditional default */ - else if (maxio > MAXPHYS) - maxio = MAXPHYS; /* for safety */ + else if (maxio > maxphys) + maxio = maxphys; /* for safety */ disk->d_maxsize = maxio; flbas_fmt = (nsd->flbas >> NVME_NS_DATA_FLBAS_FORMAT_SHIFT) & NVME_NS_DATA_FLBAS_FORMAT_MASK; Index: sys/cam/scsi/scsi_cd.c =================================================================== --- sys/cam/scsi/scsi_cd.c (revision 367665) +++ sys/cam/scsi/scsi_cd.c (working copy) @@ -696,8 +696,8 @@ cdregister(struct cam_periph *periph, void *arg) softc->disk->d_drv1 = periph; if (cpi.maxio == 0) softc->disk->d_maxsize = DFLTPHYS; /* traditional default */ - else if (cpi.maxio > MAXPHYS) - softc->disk->d_maxsize = MAXPHYS; /* for safety */ + else if (cpi.maxio > maxphys) + softc->disk->d_maxsize = maxphys; /* for safety */ else softc->disk->d_maxsize = cpi.maxio; softc->disk->d_flags = 0; Index: sys/cam/scsi/scsi_da.c =================================================================== --- sys/cam/scsi/scsi_da.c (revision 367665) +++ sys/cam/scsi/scsi_da.c (working copy) @@ -2921,8 +2921,8 @@ daregister(struct cam_periph *periph, void *arg) softc->disk->d_drv1 = periph; if (cpi.maxio == 0) softc->maxio = DFLTPHYS; /* traditional default */ - else if (cpi.maxio > MAXPHYS) - softc->maxio = MAXPHYS; /* for safety */ + else if (cpi.maxio > maxphys) + softc->maxio = maxphys; /* for safety */ else softc->maxio = cpi.maxio; if (softc->quirks & DA_Q_128KB) @@ -4819,7 +4819,7 @@ dadone_proberc(struct cam_periph *periph, union cc if (maxsector == 0) maxsector = -1; } - if (block_size >= MAXPHYS) { + if (block_size >= maxphys) { xpt_print(periph->path, "unsupportable block size %ju\n", (uintmax_t) block_size); Index: sys/cam/scsi/scsi_pass.c =================================================================== --- sys/cam/scsi/scsi_pass.c (revision 367665) +++ sys/cam/scsi/scsi_pass.c (working copy) @@ -583,7 +583,7 @@ passregister(struct cam_periph *periph, void *arg) periph->periph_name, periph->unit_number); snprintf(softc->io_zone_name, sizeof(softc->io_zone_name), "%s%dIO", periph->periph_name, periph->unit_number); - softc->io_zone_size = MAXPHYS; + softc->io_zone_size = maxphys; knlist_init_mtx(&softc->read_select.si_note, cam_periph_mtx(periph)); xpt_path_inq(&cpi, periph->path); @@ -590,8 +590,8 @@ passregister(struct cam_periph *periph, void *arg) if (cpi.maxio == 0) softc->maxio = DFLTPHYS; /* traditional default */ - else if (cpi.maxio > MAXPHYS) - softc->maxio = MAXPHYS; /* for safety */ + else if (cpi.maxio > maxphys) + softc->maxio = maxphys; /* for safety */ else softc->maxio = cpi.maxio; /* real value */ @@ -1507,7 +1507,7 @@ passmemsetup(struct cam_periph *periph, struct pas /* * We allocate buffers in io_zone_size increments for an - * S/G list. This will generally be MAXPHYS. + * S/G list. This will generally be maxphys. */ if (lengths[0] <= softc->io_zone_size) num_segs_needed = 1; Index: sys/cam/scsi/scsi_sa.c =================================================================== --- sys/cam/scsi/scsi_sa.c (revision 367665) +++ sys/cam/scsi/scsi_sa.c (working copy) @@ -2447,12 +2447,12 @@ saregister(struct cam_periph *periph, void *arg) /* * If maxio isn't set, we fall back to DFLTPHYS. Otherwise we take - * the smaller of cpi.maxio or MAXPHYS. + * the smaller of cpi.maxio or maxphys. */ if (cpi.maxio == 0) softc->maxio = DFLTPHYS; - else if (cpi.maxio > MAXPHYS) - softc->maxio = MAXPHYS; + else if (cpi.maxio > maxphys) + softc->maxio = maxphys; else softc->maxio = cpi.maxio; Index: sys/cam/scsi/scsi_sg.c =================================================================== --- sys/cam/scsi/scsi_sg.c (revision 367665) +++ sys/cam/scsi/scsi_sg.c (working copy) @@ -327,8 +327,8 @@ sgregister(struct cam_periph *periph, void *arg) if (cpi.maxio == 0) softc->maxio = DFLTPHYS; /* traditional default */ - else if (cpi.maxio > MAXPHYS) - softc->maxio = MAXPHYS; /* for safety */ + else if (cpi.maxio > maxphys) + softc->maxio = maxphys; /* for safety */ else softc->maxio = cpi.maxio; /* real value */ Index: sys/cam/scsi/scsi_target.c =================================================================== --- sys/cam/scsi/scsi_target.c (revision 367665) +++ sys/cam/scsi/scsi_target.c (working copy) @@ -404,8 +404,8 @@ targenable(struct targ_softc *softc, struct cam_pa } if (cpi.maxio == 0) softc->maxio = DFLTPHYS; /* traditional default */ - else if (cpi.maxio > MAXPHYS) - softc->maxio = MAXPHYS; /* for safety */ + else if (cpi.maxio > maxphys) + softc->maxio = maxphys; /* for safety */ else softc->maxio = cpi.maxio; /* real value */ Index: sys/dev/ahci/ahci.c =================================================================== --- sys/dev/ahci/ahci.c (revision 367665) +++ sys/dev/ahci/ahci.c (working copy) @@ -1124,8 +1124,7 @@ ahci_dmainit(device_t dev) error = bus_dma_tag_create(bus_get_dma_tag(dev), 2, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, - AHCI_SG_ENTRIES * PAGE_SIZE * ch->numslots, - AHCI_SG_ENTRIES, AHCI_PRD_MAX, + AHCI_SG_ENTRIES * PAGE_SIZE, AHCI_SG_ENTRIES, AHCI_PRD_MAX, 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag); if (error != 0) goto error; @@ -1187,6 +1186,7 @@ ahci_slotsalloc(device_t dev) slot->ch = ch; slot->slot = i; slot->state = AHCI_SLOT_EMPTY; + slot->ct_offset = AHCI_CT_OFFSET + AHCI_CT_SIZE * i; slot->ccb = NULL; callout_init_mtx(&slot->timeout, &ch->mtx, 0); @@ -1642,8 +1642,7 @@ ahci_dmasetprd(void *arg, bus_dma_segment_t *segs, } KASSERT(nsegs <= AHCI_SG_ENTRIES, ("too many DMA segment entries\n")); /* Get a piece of the workspace for this request */ - ctp = (struct ahci_cmd_tab *) - (ch->dma.work + AHCI_CT_OFFSET + (AHCI_CT_SIZE * slot->slot)); + ctp = (struct ahci_cmd_tab *)(ch->dma.work + slot->ct_offset); /* Fill S/G table */ prd = &ctp->prd_tab[0]; for (i = 0; i < nsegs; i++) { @@ -1672,8 +1671,7 @@ ahci_execute_transaction(struct ahci_slot *slot) uint16_t cmd_flags; /* Get a piece of the workspace for this request */ - ctp = (struct ahci_cmd_tab *) - (ch->dma.work + AHCI_CT_OFFSET + (AHCI_CT_SIZE * slot->slot)); + ctp = (struct ahci_cmd_tab *)(ch->dma.work + slot->ct_offset); /* Setup the FIS for this request */ if (!(fis_size = ahci_setup_fis(ch, ctp, ccb, slot->slot))) { device_printf(ch->dev, "Setting up SATA FIS failed\n"); @@ -1710,8 +1708,7 @@ ahci_execute_transaction(struct ahci_slot *slot) softreset = 0; clp->bytecount = 0; clp->cmd_flags = htole16(cmd_flags); - clp->cmd_table_phys = htole64(ch->dma.work_bus + AHCI_CT_OFFSET + - (AHCI_CT_SIZE * slot->slot)); + clp->cmd_table_phys = htole64(ch->dma.work_bus + slot->ct_offset); bus_dmamap_sync(ch->dma.work_tag, ch->dma.work_map, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); bus_dmamap_sync(ch->dma.rfis_tag, ch->dma.rfis_map, @@ -2868,7 +2865,7 @@ ahciaction(struct cam_sim *sim, union ccb *ccb) cpi->transport_version = XPORT_VERSION_UNSPECIFIED; cpi->protocol = PROTO_ATA; cpi->protocol_version = PROTO_VERSION_UNSPECIFIED; - cpi->maxio = MAXPHYS; + cpi->maxio = ctob(AHCI_SG_ENTRIES - 1); /* ATI SB600 can't handle 256 sectors with FPDMA (NCQ). */ if (ch->quirks & AHCI_Q_MAXIO_64K) cpi->maxio = min(cpi->maxio, 128 * 512); Index: sys/dev/ahci/ahci.h =================================================================== --- sys/dev/ahci/ahci.h (revision 367665) +++ sys/dev/ahci/ahci.h (working copy) @@ -310,13 +310,8 @@ #define AHCI_P_DEVSLP_DM 0x0e000000 #define AHCI_P_DEVSLP_DM_SHIFT 25 -/* Just to be sure, if building as module. */ -#if MAXPHYS < 512 * 1024 -#undef MAXPHYS -#define MAXPHYS 512 * 1024 -#endif /* Pessimistic prognosis on number of required S/G entries */ -#define AHCI_SG_ENTRIES (roundup(btoc(MAXPHYS) + 1, 8)) +#define AHCI_SG_ENTRIES MIN(roundup(btoc(maxphys) + 1, 8), 65528) /* Command list. 32 commands. First, 1Kbyte aligned. */ #define AHCI_CL_OFFSET 0 #define AHCI_CL_SIZE 32 @@ -344,7 +339,7 @@ struct ahci_cmd_tab { u_int8_t cfis[64]; u_int8_t acmd[32]; u_int8_t reserved[32]; - struct ahci_dma_prd prd_tab[AHCI_SG_ENTRIES]; + struct ahci_dma_prd prd_tab[]; } __packed; struct ahci_cmd_list { @@ -394,6 +389,7 @@ struct ahci_slot { struct ahci_channel *ch; /* Channel */ u_int8_t slot; /* Number of this slot */ enum ahci_slot_states state; /* Slot state */ + u_int ct_offset; /* cmd_tab offset */ union ccb *ccb; /* CCB occupying slot */ struct ata_dmaslot dma; /* DMA data of this slot */ struct callout timeout; /* Execution timeout */ Index: sys/dev/ahci/ahciem.c =================================================================== --- sys/dev/ahci/ahciem.c (revision 367665) +++ sys/dev/ahci/ahciem.c (working copy) @@ -641,7 +641,7 @@ ahciemaction(struct cam_sim *sim, union ccb *ccb) cpi->transport_version = XPORT_VERSION_UNSPECIFIED; cpi->protocol = PROTO_ATA; cpi->protocol_version = PROTO_VERSION_UNSPECIFIED; - cpi->maxio = MAXPHYS; + cpi->maxio = maxphys; cpi->hba_vendor = pci_get_vendor(parent); cpi->hba_device = pci_get_device(parent); cpi->hba_subvendor = pci_get_subvendor(parent); Index: sys/dev/ata/ata-all.c =================================================================== --- sys/dev/ata/ata-all.c (revision 367665) +++ sys/dev/ata/ata-all.c (working copy) @@ -139,7 +139,7 @@ ata_attach(device_t dev) if (ch->flags & ATA_SATA) ch->user[i].bytecount = 8192; else - ch->user[i].bytecount = MAXPHYS; + ch->user[i].bytecount = 65536; ch->user[i].caps = 0; ch->curr[i] = ch->user[i]; if (ch->flags & ATA_SATA) { Index: sys/dev/ata/ata-all.h =================================================================== --- sys/dev/ata/ata-all.h (revision 367665) +++ sys/dev/ata/ata-all.h (working copy) @@ -152,7 +152,7 @@ #define ATA_SACTIVE 16 /* DMA register defines */ -#define ATA_DMA_ENTRIES 256 +#define ATA_DMA_ENTRIES MAX(17, btoc(maxphys) + 1) #define ATA_DMA_EOT 0x80000000 #define ATA_BMCMD_PORT 17 Index: sys/dev/ata/ata-dma.c =================================================================== --- sys/dev/ata/ata-dma.c (revision 367665) +++ sys/dev/ata/ata-dma.c (working copy) @@ -87,7 +87,7 @@ ata_dmainit(device_t dev) if (ch->dma.segsize == 0) ch->dma.segsize = 65536; if (ch->dma.max_iosize == 0) - ch->dma.max_iosize = MIN((ATA_DMA_ENTRIES - 1) * PAGE_SIZE, MAXPHYS); + ch->dma.max_iosize = (ATA_DMA_ENTRIES - 1) * PAGE_SIZE; if (ch->dma.max_address == 0) ch->dma.max_address = BUS_SPACE_MAXADDR_32BIT; if (ch->dma.dma_slots == 0) Index: sys/dev/mpr/mpr.c =================================================================== --- sys/dev/mpr/mpr.c (revision 367665) +++ sys/dev/mpr/mpr.c (working copy) @@ -436,7 +436,7 @@ mpr_resize_queues(struct mpr_softc *sc) /* * If I/O size limitation requested then use it and pass up to CAM. - * If not, use MAXPHYS as an optimization hint, but report HW limit. + * If not, use maxphys as an optimization hint, but report HW limit. */ if (sc->max_io_pages > 0) { maxio = min(maxio, sc->max_io_pages * PAGE_SIZE); @@ -443,7 +443,7 @@ mpr_resize_queues(struct mpr_softc *sc) sc->maxio = maxio; } else { sc->maxio = maxio; - maxio = min(maxio, MAXPHYS); + maxio = min(maxio, maxphys); } sc->num_chains = (maxio / PAGE_SIZE + sges_per_frame - 2) / Index: sys/dev/mps/mps.c =================================================================== --- sys/dev/mps/mps.c (revision 367665) +++ sys/dev/mps/mps.c (working copy) @@ -418,7 +418,7 @@ mps_resize_queues(struct mps_softc *sc) /* * If I/O size limitation requested, then use it and pass up to CAM. - * If not, use MAXPHYS as an optimization hint, but report HW limit. + * If not, use maxphys as an optimization hint, but report HW limit. */ if (sc->max_io_pages > 0) { maxio = min(maxio, sc->max_io_pages * PAGE_SIZE); @@ -425,7 +425,7 @@ mps_resize_queues(struct mps_softc *sc) sc->maxio = maxio; } else { sc->maxio = maxio; - maxio = min(maxio, MAXPHYS); + maxio = min(maxio, maxphys); } sc->num_chains = (maxio / PAGE_SIZE + sges_per_frame - 2) / Index: sys/dev/mpt/mpt.c =================================================================== --- sys/dev/mpt/mpt.c (revision 367665) +++ sys/dev/mpt/mpt.c (working copy) @@ -2691,7 +2691,7 @@ mpt_configure_ioc(struct mpt_softc *mpt, int tn, i /* * Use this as the basis for reporting the maximum I/O size to CAM. */ - mpt->max_cam_seg_cnt = min(mpt->max_seg_cnt, (MAXPHYS / PAGE_SIZE) + 1); + mpt->max_cam_seg_cnt = min(mpt->max_seg_cnt, btoc(maxphys) + 1); /* XXX Lame Locking! */ MPT_UNLOCK(mpt); Index: sys/dev/mpt/mpt.h =================================================================== --- sys/dev/mpt/mpt.h (revision 367665) +++ sys/dev/mpt/mpt.h (working copy) @@ -668,7 +668,7 @@ struct mpt_softc { bus_addr_t request_phys; /* BusAddr of request memory */ uint32_t max_seg_cnt; /* calculated after IOC facts */ - uint32_t max_cam_seg_cnt;/* calculated from MAXPHYS*/ + uint32_t max_cam_seg_cnt;/* calculated from maxphys */ /* * Hardware management Index: sys/dev/mvs/mvs.c =================================================================== --- sys/dev/mvs/mvs.c (revision 367665) +++ sys/dev/mvs/mvs.c (working copy) @@ -370,8 +370,7 @@ mvs_dmainit(device_t dev) if (bus_dma_tag_create(bus_get_dma_tag(dev), 2, MVS_EPRD_MAX, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, - MVS_SG_ENTRIES * PAGE_SIZE * MVS_MAX_SLOTS, - MVS_SG_ENTRIES, MVS_EPRD_MAX, + MVS_SG_ENTRIES * PAGE_SIZE, MVS_SG_ENTRIES, MVS_EPRD_MAX, 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag)) { goto error; } @@ -438,6 +437,7 @@ mvs_slotsalloc(device_t dev) slot->dev = dev; slot->slot = i; slot->state = MVS_SLOT_EMPTY; + slot->eprd_offset = MVS_EPRD_OFFSET + MVS_EPRD_SIZE * i; slot->ccb = NULL; callout_init_mtx(&slot->timeout, &ch->mtx, 0); @@ -1286,8 +1286,7 @@ mvs_dmasetprd(void *arg, bus_dma_segment_t *segs, } else { slot->dma.addr = 0; /* Get a piece of the workspace for this EPRD */ - eprd = (struct mvs_eprd *) - (ch->dma.workrq + MVS_EPRD_OFFSET + (MVS_EPRD_SIZE * slot->slot)); + eprd = (struct mvs_eprd *)(ch->dma.workrq + slot->eprd_offset); /* Fill S/G table */ for (i = 0; i < nsegs; i++) { eprd[i].prdbal = htole32(segs[i].ds_addr); @@ -1405,8 +1404,7 @@ mvs_legacy_execute_transaction(struct mvs_slot *sl DELAY(10); if (ch->basic_dma) { /* Start basic DMA. */ - eprd = ch->dma.workrq_bus + MVS_EPRD_OFFSET + - (MVS_EPRD_SIZE * slot->slot); + eprd = ch->dma.workrq_bus + slot->eprd_offset; ATA_OUTL(ch->r_mem, DMA_DTLBA, eprd); ATA_OUTL(ch->r_mem, DMA_DTHBA, (eprd >> 16) >> 16); ATA_OUTL(ch->r_mem, DMA_C, DMA_C_START | @@ -1433,7 +1431,7 @@ mvs_execute_transaction(struct mvs_slot *slot) int i; /* Get address of the prepared EPRD */ - eprd = ch->dma.workrq_bus + MVS_EPRD_OFFSET + (MVS_EPRD_SIZE * slot->slot); + eprd = ch->dma.workrq_bus + slot->eprd_offset; /* Prepare CRQB. Gen IIe uses different CRQB format. */ if (ch->quirks & MVS_Q_GENIIE) { crqb2e = (struct mvs_crqb_gen2e *) @@ -2423,7 +2421,7 @@ mvsaction(struct cam_sim *sim, union ccb *ccb) cpi->transport_version = XPORT_VERSION_UNSPECIFIED; cpi->protocol = PROTO_ATA; cpi->protocol_version = PROTO_VERSION_UNSPECIFIED; - cpi->maxio = MAXPHYS; + cpi->maxio = maxphys; if ((ch->quirks & MVS_Q_SOC) == 0) { cpi->hba_vendor = pci_get_vendor(parent); cpi->hba_device = pci_get_device(parent); Index: sys/dev/mvs/mvs.h =================================================================== --- sys/dev/mvs/mvs.h (revision 367665) +++ sys/dev/mvs/mvs.h (working copy) @@ -392,7 +392,7 @@ #define MVS_MAX_SLOTS 32 /* Pessimistic prognosis on number of required S/G entries */ -#define MVS_SG_ENTRIES (btoc(MAXPHYS) + 1) +#define MVS_SG_ENTRIES (btoc(maxphys) + 1) /* EDMA Command Request Block (CRQB) Data */ struct mvs_crqb { @@ -505,6 +505,7 @@ struct mvs_slot { int slot; /* Number of this slot */ int tag; /* Used command tag */ enum mvs_slot_states state; /* Slot state */ + u_int eprd_offset; /* EPRD offset */ union ccb *ccb; /* CCB occupying slot */ struct ata_dmaslot dma; /* DMA data of this slot */ struct callout timeout; /* Execution timeout */ Index: sys/dev/siis/siis.c =================================================================== --- sys/dev/siis/siis.c (revision 367665) +++ sys/dev/siis/siis.c (working copy) @@ -688,8 +688,7 @@ siis_dmainit(device_t dev) if (bus_dma_tag_create(bus_get_dma_tag(dev), 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, - SIIS_SG_ENTRIES * PAGE_SIZE * SIIS_MAX_SLOTS, - SIIS_SG_ENTRIES, 0xFFFFFFFF, + SIIS_SG_ENTRIES * PAGE_SIZE, SIIS_SG_ENTRIES, 0xFFFFFFFF, 0, busdma_lock_mutex, &ch->mtx, &ch->dma.data_tag)) { goto error; } @@ -745,6 +744,7 @@ siis_slotsalloc(device_t dev) slot->dev = dev; slot->slot = i; slot->state = SIIS_SLOT_EMPTY; + slot->prb_offset = SIIS_PRB_SIZE * i; slot->ccb = NULL; callout_init_mtx(&slot->timeout, &ch->mtx, 0); @@ -1034,8 +1034,7 @@ siis_dmasetprd(void *arg, bus_dma_segment_t *segs, slot->dma.nsegs = nsegs; if (nsegs != 0) { /* Get a piece of the workspace for this request */ - ctp = (struct siis_cmd *)(ch->dma.work + SIIS_CT_OFFSET + - (SIIS_CT_SIZE * slot->slot)); + ctp = (struct siis_cmd *)(ch->dma.work + slot->prb_offset); /* Fill S/G table */ if (slot->ccb->ccb_h.func_code == XPT_ATA_IO) prd = &ctp->u.ata.prd[0]; @@ -1066,8 +1065,7 @@ siis_execute_transaction(struct siis_slot *slot) mtx_assert(&ch->mtx, MA_OWNED); /* Get a piece of the workspace for this request */ - ctp = (struct siis_cmd *) - (ch->dma.work + SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot)); + ctp = (struct siis_cmd *)(ch->dma.work + slot->prb_offset); ctp->control = 0; ctp->protocol_override = 0; ctp->transfer_count = 0; @@ -1117,8 +1115,7 @@ siis_execute_transaction(struct siis_slot *slot) /* Issue command to the controller. */ slot->state = SIIS_SLOT_RUNNING; ch->rslots |= (1 << slot->slot); - prb_bus = ch->dma.work_bus + - SIIS_CT_OFFSET + (SIIS_CT_SIZE * slot->slot); + prb_bus = ch->dma.work_bus + slot->prb_offset; ATA_OUTL(ch->r_mem, SIIS_P_CACTL(slot->slot), prb_bus); ATA_OUTL(ch->r_mem, SIIS_P_CACTH(slot->slot), prb_bus >> 32); /* Start command execution timeout */ @@ -1967,7 +1964,7 @@ siisaction(struct cam_sim *sim, union ccb *ccb) cpi->transport_version = XPORT_VERSION_UNSPECIFIED; cpi->protocol = PROTO_ATA; cpi->protocol_version = PROTO_VERSION_UNSPECIFIED; - cpi->maxio = MAXPHYS; + cpi->maxio = maxphys; cpi->hba_vendor = pci_get_vendor(parent); cpi->hba_device = pci_get_device(parent); cpi->hba_subvendor = pci_get_subvendor(parent); Index: sys/dev/siis/siis.h =================================================================== --- sys/dev/siis/siis.h (revision 367665) +++ sys/dev/siis/siis.h (working copy) @@ -263,18 +263,12 @@ #define SIIS_OFFSET 0x100 #define SIIS_STEP 0x80 -/* Just to be sure, if building as module. */ -#if MAXPHYS < 512 * 1024 -#undef MAXPHYS -#define MAXPHYS 512 * 1024 -#endif /* Pessimistic prognosis on number of required S/G entries */ -#define SIIS_SG_ENTRIES (roundup(btoc(MAXPHYS), 4) + 1) -/* Command tables. Up to 32 commands, Each, 128byte aligned. */ -#define SIIS_CT_OFFSET 0 -#define SIIS_CT_SIZE (32 + 16 + SIIS_SG_ENTRIES * 16) +#define SIIS_SG_ENTRIES (roundup(btoc(maxphys), 4) + 1) +/* Port Request Block + S/G entries. 128byte aligned. */ +#define SIIS_PRB_SIZE (32 + 16 + SIIS_SG_ENTRIES * 16) /* Total main work area. */ -#define SIIS_WORK_SIZE (SIIS_CT_OFFSET + SIIS_CT_SIZE * SIIS_MAX_SLOTS) +#define SIIS_WORK_SIZE (SIIS_PRB_SIZE * SIIS_MAX_SLOTS) struct siis_dma_prd { u_int64_t dba; @@ -287,12 +281,12 @@ struct siis_dma_prd { } __packed; struct siis_cmd_ata { - struct siis_dma_prd prd[1 + SIIS_SG_ENTRIES]; + struct siis_dma_prd prd[2]; } __packed; struct siis_cmd_atapi { u_int8_t ccb[16]; - struct siis_dma_prd prd[SIIS_SG_ENTRIES]; + struct siis_dma_prd prd[1]; } __packed; struct siis_cmd { @@ -349,6 +343,7 @@ struct siis_slot { device_t dev; /* Device handle */ u_int8_t slot; /* Number of this slot */ enum siis_slot_states state; /* Slot state */ + u_int prb_offset; /* PRB offset */ union ccb *ccb; /* CCB occupying slot */ struct ata_dmaslot dma; /* DMA data of this slot */ struct callout timeout; /* Execution timeout */