From owner-svn-src-all@freebsd.org Sat Nov 28 12:13:01 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5B44047F0A5; Sat, 28 Nov 2020 12:13:01 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Cjr3x1xZtz3mXb; Sat, 28 Nov 2020 12:13:01 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 34E832721B; Sat, 28 Nov 2020 12:13:01 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0ASCD0fW007052; Sat, 28 Nov 2020 12:13:00 GMT (envelope-from kib@FreeBSD.org) Received: (from kib@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0ASCCpjQ006999; Sat, 28 Nov 2020 12:12:51 GMT (envelope-from kib@FreeBSD.org) Message-Id: <202011281212.0ASCCpjQ006999@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kib set sender to kib@FreeBSD.org using -f From: Konstantin Belousov Date: Sat, 28 Nov 2020 12:12:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r368124 - in head/sys: cam cam/ata cam/ctl cam/mmc cam/nvme cam/scsi compat/linprocfs compat/linux conf contrib/openzfs/module/os/freebsd/zfs dev/ahci dev/ata dev/firewire dev/flash dev... X-SVN-Group: head X-SVN-Commit-Author: kib X-SVN-Commit-Paths: in head/sys: cam cam/ata cam/ctl cam/mmc cam/nvme cam/scsi compat/linprocfs compat/linux conf contrib/openzfs/module/os/freebsd/zfs dev/ahci dev/ata dev/firewire dev/flash dev/isci/scil dev/iscsi dev/... X-SVN-Commit-Revision: 368124 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Nov 2020 12:13:01 -0000 Author: kib Date: Sat Nov 28 12:12:51 2020 New Revision: 368124 URL: https://svnweb.freebsd.org/changeset/base/368124 Log: Make MAXPHYS tunable. Bump MAXPHYS to 1M. Replace MAXPHYS by runtime variable maxphys. It is initialized from MAXPHYS by default, but can be also adjusted with the tunable kern.maxphys. Make b_pages[] array in struct buf flexible. Size b_pages[] for buffer cache buffers exactly to atop(maxbcachebuf) (currently it is sized to atop(MAXPHYS)), and b_pages[] for pbufs is sized to atop(maxphys) + 1. The +1 for pbufs allow several pbuf consumers, among them vmapbuf(), to use unaligned buffers still sized to maxphys, esp. when such buffers come from userspace (*). Overall, we save significant amount of otherwise wasted memory in b_pages[] for buffer cache buffers, while bumping MAXPHYS to desired high value. Eliminate all direct uses of the MAXPHYS constant in kernel and driver sources, except a place which initialize maxphys. Some random (and arguably weird) uses of MAXPHYS, e.g. in linuxolator, are converted straight. Some drivers, which use MAXPHYS to size embeded structures, get private MAXPHYS-like constant; their convertion is out of scope for this work. Changes to cam/, dev/ahci, dev/ata, dev/mpr, dev/mpt, dev/mvs, dev/siis, where either submitted by, or based on changes by mav. Suggested by: mav (*) Reviewed by: imp, mav, imp, mckusick, scottl (intermediate versions) Tested by: pho Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D27225 Modified: head/sys/cam/ata/ata_da.c head/sys/cam/cam_compat.c head/sys/cam/cam_periph.c head/sys/cam/cam_xpt.c head/sys/cam/ctl/ctl_backend_block.c head/sys/cam/mmc/mmc_da.c head/sys/cam/nvme/nvme_da.c head/sys/cam/scsi/scsi_cd.c head/sys/cam/scsi/scsi_da.c head/sys/cam/scsi/scsi_pass.c head/sys/cam/scsi/scsi_sa.c head/sys/cam/scsi/scsi_sg.c head/sys/cam/scsi/scsi_target.c head/sys/compat/linprocfs/linprocfs.c head/sys/compat/linux/linux_ioctl.c head/sys/conf/options head/sys/contrib/openzfs/module/os/freebsd/zfs/vdev_geom.c head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.c head/sys/dev/ahci/ahci.c head/sys/dev/ahci/ahci.h head/sys/dev/ahci/ahciem.c head/sys/dev/ata/ata-all.c head/sys/dev/ata/ata-all.h head/sys/dev/ata/ata-dma.c head/sys/dev/firewire/sbp.c head/sys/dev/flash/cqspi.c head/sys/dev/isci/scil/sci_controller_constants.h head/sys/dev/iscsi/iscsi.c head/sys/dev/md/md.c head/sys/dev/mfi/mfi.c head/sys/dev/mpr/mpr.c head/sys/dev/mps/mps.c head/sys/dev/mpt/mpt.c head/sys/dev/mpt/mpt.h head/sys/dev/mrsas/mrsas.c head/sys/dev/mvs/mvs.c head/sys/dev/mvs/mvs.h head/sys/dev/nvme/nvme.h head/sys/dev/nvme/nvme_ctrlr.c head/sys/dev/pms/freebsd/driver/ini/src/agdef.h head/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c head/sys/dev/sdhci/sdhci.c head/sys/dev/siis/siis.c head/sys/dev/siis/siis.h head/sys/dev/sym/sym_conf.h head/sys/dev/usb/storage/umass.c head/sys/dev/virtio/block/virtio_blk.c head/sys/dev/virtio/scsi/virtio_scsi.c head/sys/dev/xen/blkback/blkback.c head/sys/dev/xen/blkfront/blkfront.c head/sys/fs/cd9660/cd9660_vfsops.c head/sys/fs/ext2fs/ext2_vfsops.c head/sys/fs/fuse/fuse_vfsops.c head/sys/fs/msdosfs/msdosfs_vfsops.c head/sys/fs/udf/udf_vfsops.c head/sys/geom/cache/g_cache.c head/sys/geom/eli/g_eli_integrity.c head/sys/geom/geom_dev.c head/sys/geom/geom_io.c head/sys/geom/journal/g_journal.c head/sys/geom/journal/g_journal.h head/sys/geom/mirror/g_mirror.c head/sys/geom/nop/g_nop.c head/sys/geom/part/g_part_apm.c head/sys/geom/part/g_part_gpt.c head/sys/geom/part/g_part_ldm.c head/sys/geom/raid/md_ddf.c head/sys/geom/raid/md_promise.c head/sys/geom/raid3/g_raid3.c head/sys/geom/shsec/g_shsec.c head/sys/geom/stripe/g_stripe.c head/sys/geom/uzip/g_uzip.c head/sys/geom/vinum/geom_vinum_var.h head/sys/geom/virstor/g_virstor.c head/sys/geom/virstor/g_virstor.h head/sys/kern/kern_mib.c head/sys/kern/kern_physio.c head/sys/kern/kern_sendfile.c head/sys/kern/subr_param.c head/sys/kern/vfs_aio.c head/sys/kern/vfs_bio.c head/sys/kern/vfs_cluster.c head/sys/kern/vfs_default.c head/sys/mips/ingenic/jz4780_mmc.c head/sys/net/if.c head/sys/powerpc/mambo/mambo_disk.c head/sys/powerpc/mpc85xx/fsl_sata.c head/sys/sys/aio.h head/sys/sys/buf.h head/sys/sys/param.h head/sys/sys/systm.h head/sys/ufs/ffs/ffs_vfsops.c head/sys/vm/swap_pager.c head/sys/vm/vm_fault.c head/sys/vm/vm_init.c head/sys/vm/vm_map.h head/sys/vm/vm_pager.c head/sys/vm/vm_pager.h head/sys/vm/vnode_pager.c Modified: head/sys/cam/ata/ata_da.c ============================================================================== --- head/sys/cam/ata/ata_da.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/ata/ata_da.c Sat Nov 28 12:12:51 2020 (r368124) @@ -3447,8 +3447,8 @@ adasetgeom(struct ada_softc *softc, struct ccb_getdev 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 */ Modified: head/sys/cam/cam_compat.c ============================================================================== --- head/sys/cam/cam_compat.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/cam_compat.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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 */ Modified: head/sys/cam/cam_periph.c ============================================================================== --- head/sys/cam/cam_periph.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/cam_periph.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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_periph_ma 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_periph_ma } /* * 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_periph_ma /* * 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_periph_ma * boundary. */ misaligned[i] = (lengths[i] + - (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK) > MAXPHYS); + (((vm_offset_t)(*data_ptrs[i])) & PAGE_MASK) > maxphys); } /* Modified: head/sys/cam/cam_xpt.c ============================================================================== --- head/sys/cam/cam_xpt.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/cam_xpt.c Sat Nov 28 12:12:51 2020 (r368124) @@ -553,7 +553,7 @@ xptdoioctl(struct cdev *dev, u_long cmd, caddr_t addr, * 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; Modified: head/sys/cam/ctl/ctl_backend_block.c ============================================================================== --- head/sys/cam/ctl/ctl_backend_block.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/ctl/ctl_backend_block.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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, struct 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 %zu > %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 %zu > %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_lun *b 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_lun, * 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); Modified: head/sys/cam/mmc/mmc_da.c ============================================================================== --- head/sys/cam/mmc/mmc_da.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/mmc/mmc_da.c Sat Nov 28 12:12:51 2020 (r368124) @@ -1592,7 +1592,7 @@ sdda_add_part(struct cam_periph *periph, u_int type, c 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; Modified: head/sys/cam/nvme/nvme_da.c ============================================================================== --- head/sys/cam/nvme/nvme_da.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/nvme/nvme_da.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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; Modified: head/sys/cam/scsi/scsi_cd.c ============================================================================== --- head/sys/cam/scsi/scsi_cd.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/scsi/scsi_cd.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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; Modified: head/sys/cam/scsi/scsi_da.c ============================================================================== --- head/sys/cam/scsi/scsi_da.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/scsi/scsi_da.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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 ccb *d 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); Modified: head/sys/cam/scsi/scsi_pass.c ============================================================================== --- head/sys/cam/scsi/scsi_pass.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/scsi/scsi_pass.c Sat Nov 28 12:12:51 2020 (r368124) @@ -583,15 +583,15 @@ 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); 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 pass_io /* * 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; Modified: head/sys/cam/scsi/scsi_sa.c ============================================================================== --- head/sys/cam/scsi/scsi_sa.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/scsi/scsi_sa.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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; Modified: head/sys/cam/scsi/scsi_sg.c ============================================================================== --- head/sys/cam/scsi/scsi_sg.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/scsi/scsi_sg.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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 */ Modified: head/sys/cam/scsi/scsi_target.c ============================================================================== --- head/sys/cam/scsi/scsi_target.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/cam/scsi/scsi_target.c Sat Nov 28 12:12:51 2020 (r368124) @@ -404,8 +404,8 @@ targenable(struct targ_softc *softc, struct cam_path * } 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 */ Modified: head/sys/compat/linprocfs/linprocfs.c ============================================================================== --- head/sys/compat/linprocfs/linprocfs.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/compat/linprocfs/linprocfs.c Sat Nov 28 12:12:51 2020 (r368124) @@ -1928,8 +1928,8 @@ linprocfs_doauxv(PFS_FILL_ARGS) buflen = resid; if (buflen > IOSIZE_MAX) return (EINVAL); - if (buflen > MAXPHYS) - buflen = MAXPHYS; + if (buflen > maxphys) + buflen = maxphys; if (resid <= 0) return (0); Modified: head/sys/compat/linux/linux_ioctl.c ============================================================================== --- head/sys/compat/linux/linux_ioctl.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/compat/linux/linux_ioctl.c Sat Nov 28 12:12:51 2020 (r368124) @@ -2152,7 +2152,7 @@ linux_ifconf(struct thread *td, struct ifconf *uifc) if (error != 0) return (error); - max_len = MAXPHYS - 1; + max_len = maxphys - 1; CURVNET_SET(TD_TO_VNET(td)); /* handle the 'request buffer size' case */ Modified: head/sys/conf/options ============================================================================== --- head/sys/conf/options Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/conf/options Sat Nov 28 12:12:51 2020 (r368124) @@ -602,7 +602,7 @@ INVARIANTS opt_global.h KASSERT_PANIC_OPTIONAL opt_global.h MAXCPU opt_global.h MAXMEMDOM opt_global.h -MAXPHYS opt_global.h +MAXPHYS opt_maxphys.h MCLSHIFT opt_global.h MUTEX_NOINLINE opt_global.h LOCK_PROFILING opt_global.h Modified: head/sys/contrib/openzfs/module/os/freebsd/zfs/vdev_geom.c ============================================================================== --- head/sys/contrib/openzfs/module/os/freebsd/zfs/vdev_geom.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/contrib/openzfs/module/os/freebsd/zfs/vdev_geom.c Sat Nov 28 12:12:51 2020 (r368124) @@ -379,7 +379,7 @@ vdev_geom_io(struct g_consumer *cp, int *cmds, void ** int i, n_bios, j; size_t bios_size; - maxio = MAXPHYS - (MAXPHYS % cp->provider->sectorsize); + maxio = maxphys - (maxphys % cp->provider->sectorsize); n_bios = 0; /* How many bios are required for all commands ? */ Modified: head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.c ============================================================================== --- head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/contrib/openzfs/module/os/freebsd/zfs/zvol_os.c Sat Nov 28 12:12:51 2020 (r368124) @@ -1191,7 +1191,7 @@ zvol_rename_minor(zvol_state_t *zv, const char *newnam args.mda_si_drv2 = zv; if (make_dev_s(&args, &dev, "%s/%s", ZVOL_DRIVER, newname) == 0) { - dev->si_iosize_max = MAXPHYS; + dev->si_iosize_max = maxphys; zsd->zsd_cdev = dev; } } @@ -1327,7 +1327,7 @@ zvol_create_minor_impl(const char *name) dmu_objset_disown(os, B_TRUE, FTAG); goto out_giant; } - dev->si_iosize_max = MAXPHYS; + dev->si_iosize_max = maxphys; zsd->zsd_cdev = dev; } (void) strlcpy(zv->zv_name, name, MAXPATHLEN); Modified: head/sys/dev/ahci/ahci.c ============================================================================== --- head/sys/dev/ahci/ahci.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/ahci/ahci.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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, int } 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); Modified: head/sys/dev/ahci/ahci.h ============================================================================== --- head/sys/dev/ahci/ahci.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/ahci/ahci.h Sat Nov 28 12:12:51 2020 (r368124) @@ -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 */ Modified: head/sys/dev/ahci/ahciem.c ============================================================================== --- head/sys/dev/ahci/ahciem.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/ahci/ahciem.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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); Modified: head/sys/dev/ata/ata-all.c ============================================================================== --- head/sys/dev/ata/ata-all.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/ata/ata-all.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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) { Modified: head/sys/dev/ata/ata-all.h ============================================================================== --- head/sys/dev/ata/ata-all.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/ata/ata-all.h Sat Nov 28 12:12:51 2020 (r368124) @@ -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 Modified: head/sys/dev/ata/ata-dma.c ============================================================================== --- head/sys/dev/ata/ata-dma.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/ata/ata-dma.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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) Modified: head/sys/dev/firewire/sbp.c ============================================================================== --- head/sys/dev/firewire/sbp.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/firewire/sbp.c Sat Nov 28 12:12:51 2020 (r368124) @@ -71,7 +71,7 @@ * because of CAM_SCSI2_MAXLUN in cam_xpt.c */ #define SBP_NUM_LUNS 64 -#define SBP_MAXPHYS MIN(MAXPHYS, (512*1024) /* 512KB */) +#define SBP_MAXPHYS (128 * 1024) #define SBP_DMA_SIZE PAGE_SIZE #define SBP_LOGIN_SIZE sizeof(struct sbp_login_res) #define SBP_QUEUE_LEN ((SBP_DMA_SIZE - SBP_LOGIN_SIZE) / sizeof(struct sbp_ocb)) Modified: head/sys/dev/flash/cqspi.c ============================================================================== --- head/sys/dev/flash/cqspi.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/flash/cqspi.c Sat Nov 28 12:12:51 2020 (r368124) @@ -721,9 +721,9 @@ cqspi_attach(device_t dev) return (ENXIO); } - xdma_prep_sg(sc->xchan_tx, TX_QUEUE_SIZE, MAXPHYS, 8, 16, 0, + xdma_prep_sg(sc->xchan_tx, TX_QUEUE_SIZE, maxphys, 8, 16, 0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR); - xdma_prep_sg(sc->xchan_rx, TX_QUEUE_SIZE, MAXPHYS, 8, 16, 0, + xdma_prep_sg(sc->xchan_rx, TX_QUEUE_SIZE, maxphys, 8, 16, 0, BUS_SPACE_MAXADDR_32BIT, BUS_SPACE_MAXADDR); cqspi_init(sc); Modified: head/sys/dev/isci/scil/sci_controller_constants.h ============================================================================== --- head/sys/dev/isci/scil/sci_controller_constants.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/isci/scil/sci_controller_constants.h Sat Nov 28 12:12:51 2020 (r368124) @@ -157,7 +157,7 @@ extern "C" { * posted to hardware always contain pairs of elements (with second * element set to zeroes if not needed). */ -#define __MAXPHYS_ELEMENTS ((MAXPHYS / PAGE_SIZE) + 1) +#define __MAXPHYS_ELEMENTS ((128 * 1024 / PAGE_SIZE) + 1) #define SCI_MAX_SCATTER_GATHER_ELEMENTS ((__MAXPHYS_ELEMENTS + 1) & ~0x1) #endif Modified: head/sys/dev/iscsi/iscsi.c ============================================================================== --- head/sys/dev/iscsi/iscsi.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/iscsi/iscsi.c Sat Nov 28 12:12:51 2020 (r368124) @@ -2407,7 +2407,7 @@ iscsi_action(struct cam_sim *sim, union ccb *ccb) cpi->transport_version = 0; cpi->protocol = PROTO_SCSI; cpi->protocol_version = SCSI_REV_SPC3; - cpi->maxio = MAXPHYS; + cpi->maxio = maxphys; cpi->ccb_h.status = CAM_REQ_CMP; break; } Modified: head/sys/dev/md/md.c ============================================================================== --- head/sys/dev/md/md.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/md/md.c Sat Nov 28 12:12:51 2020 (r368124) @@ -960,9 +960,10 @@ mdstart_vnode(struct md_s *sc, struct bio *bp) piov = auio.uio_iov; } else if ((bp->bio_flags & BIO_UNMAPPED) != 0) { pb = uma_zalloc(md_pbuf_zone, M_WAITOK); + MPASS((pb->b_flags & B_MAXPHYS) != 0); bp->bio_resid = len; unmapped_step: - npages = atop(min(MAXPHYS, round_page(len + (ma_offs & + npages = atop(min(maxphys, round_page(len + (ma_offs & PAGE_MASK)))); iolen = min(ptoa(npages) - (ma_offs & PAGE_MASK), len); KASSERT(iolen > 0, ("zero iolen")); @@ -1684,7 +1685,7 @@ kern_mdattach_locked(struct thread *td, struct md_req sectsize = DEV_BSIZE; else sectsize = mdr->md_sectorsize; - if (sectsize > MAXPHYS || mdr->md_mediasize < sectsize) + if (sectsize > maxphys || mdr->md_mediasize < sectsize) return (EINVAL); if (mdr->md_options & MD_AUTOUNIT) sc = mdnew(-1, &error, mdr->md_type); Modified: head/sys/dev/mfi/mfi.c ============================================================================== --- head/sys/dev/mfi/mfi.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mfi/mfi.c Sat Nov 28 12:12:51 2020 (r368124) @@ -457,7 +457,7 @@ mfi_attach(struct mfi_softc *sc) /* * Get information needed for sizing the contiguous memory for the * frame pool. Size down the sgl parameter since we know that - * we will never need more than what's required for MAXPHYS. + * we will never need more than what's required for MFI_MAXPHYS. * It would be nice if these constants were available at runtime * instead of compile time. */ Modified: head/sys/dev/mpr/mpr.c ============================================================================== --- head/sys/dev/mpr/mpr.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mpr/mpr.c Sat Nov 28 12:12:51 2020 (r368124) @@ -436,14 +436,14 @@ 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); 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) / Modified: head/sys/dev/mps/mps.c ============================================================================== --- head/sys/dev/mps/mps.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mps/mps.c Sat Nov 28 12:12:51 2020 (r368124) @@ -418,14 +418,14 @@ 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); 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) / Modified: head/sys/dev/mpt/mpt.c ============================================================================== --- head/sys/dev/mpt/mpt.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mpt/mpt.c Sat Nov 28 12:12:51 2020 (r368124) @@ -2691,7 +2691,7 @@ mpt_configure_ioc(struct mpt_softc *mpt, int tn, int n /* * 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); Modified: head/sys/dev/mpt/mpt.h ============================================================================== --- head/sys/dev/mpt/mpt.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mpt/mpt.h Sat Nov 28 12:12:51 2020 (r368124) @@ -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 Modified: head/sys/dev/mrsas/mrsas.c ============================================================================== --- head/sys/dev/mrsas/mrsas.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mrsas/mrsas.c Sat Nov 28 12:12:51 2020 (r368124) @@ -1922,9 +1922,9 @@ mrsas_alloc_mem(struct mrsas_softc *sc) BUS_SPACE_MAXADDR, /* lowaddr */ BUS_SPACE_MAXADDR, /* highaddr */ NULL, NULL, /* filter, filterarg */ - MAXPHYS, /* maxsize */ + maxphys, /* maxsize */ sc->max_num_sge, /* nsegments */ - MAXPHYS, /* maxsegsize */ + maxphys, /* maxsegsize */ 0, /* flags */ NULL, NULL, /* lockfunc, lockarg */ &sc->mrsas_parent_tag /* tag */ @@ -2154,9 +2154,9 @@ mrsas_alloc_mem(struct mrsas_softc *sc) BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL, NULL, - MAXPHYS, + maxphys, sc->max_num_sge, /* nsegments */ - MAXPHYS, + maxphys, BUS_DMA_ALLOCNOW, busdma_lock_mutex, &sc->io_lock, Modified: head/sys/dev/mvs/mvs.c ============================================================================== --- head/sys/dev/mvs/mvs.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mvs/mvs.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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, int } 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 *slot) 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); Modified: head/sys/dev/mvs/mvs.h ============================================================================== --- head/sys/dev/mvs/mvs.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/mvs/mvs.h Sat Nov 28 12:12:51 2020 (r368124) @@ -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 */ Modified: head/sys/dev/nvme/nvme.h ============================================================================== --- head/sys/dev/nvme/nvme.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/nvme/nvme.h Sat Nov 28 12:12:51 2020 (r368124) @@ -60,7 +60,7 @@ #define NVME_GLOBAL_NAMESPACE_TAG ((uint32_t)0xFFFFFFFF) /* Cap nvme to 1MB transfers driver explodes with larger sizes */ -#define NVME_MAX_XFER_SIZE (MAXPHYS < (1<<20) ? MAXPHYS : (1<<20)) +#define NVME_MAX_XFER_SIZE (maxphys < (1<<20) ? maxphys : (1<<20)) /* Register field definitions */ #define NVME_CAP_LO_REG_MQES_SHIFT (0) Modified: head/sys/dev/nvme/nvme_ctrlr.c ============================================================================== --- head/sys/dev/nvme/nvme_ctrlr.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/nvme/nvme_ctrlr.c Sat Nov 28 12:12:51 2020 (r368124) @@ -1248,13 +1248,13 @@ nvme_ctrlr_passthrough_cmd(struct nvme_controller *ctr if (pt->len > 0) { /* * vmapbuf calls vm_fault_quick_hold_pages which only maps full - * pages. Ensure this request has fewer than MAXPHYS bytes when + * pages. Ensure this request has fewer than maxphys bytes when * extended to full pages. */ addr = (vm_offset_t)pt->buf; end = round_page(addr + pt->len); addr = trunc_page(addr); - if (end - addr > MAXPHYS) + if (end - addr > maxphys) return EIO; if (pt->len > ctrlr->max_xfer_size) { Modified: head/sys/dev/pms/freebsd/driver/ini/src/agdef.h ============================================================================== --- head/sys/dev/pms/freebsd/driver/ini/src/agdef.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/pms/freebsd/driver/ini/src/agdef.h Sat Nov 28 12:12:51 2020 (r368124) @@ -62,7 +62,7 @@ EW 09-17-2004 1.0.0 Constant definitions #define AGTIAPI_MAX_DEVICE_7H 256 /*Max devices per channel in 7H */ #define AGTIAPI_MAX_DEVICE_8H 512 /*Max devices per channel in 8H*/ #define AGTIAPI_MAX_CAM_Q_DEPTH 1024 -#define AGTIAPI_NSEGS (MAXPHYS / PAGE_SIZE) +#define AGTIAPI_NSEGS (maxphys / PAGE_SIZE) /* ** Adapter specific defines */ Modified: head/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c ============================================================================== --- head/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/pms/freebsd/driver/ini/src/agtiapi.c Sat Nov 28 12:12:51 2020 (r368124) @@ -1623,8 +1623,8 @@ int agtiapi_alloc_requests( struct agtiapi_softc *pmcs nsegs = AGTIAPI_NSEGS; rsize = AGTIAPI_MAX_DMA_SEGS; // 128 - AGTIAPI_PRINTK( "agtiapi_alloc_requests: MAXPHYS 0x%x PAGE_SIZE 0x%x \n", - MAXPHYS, PAGE_SIZE ); + AGTIAPI_PRINTK( "agtiapi_alloc_requests: maxphys 0x%lx PAGE_SIZE 0x%x \n", + maxphys, PAGE_SIZE ); AGTIAPI_PRINTK( "agtiapi_alloc_requests: nsegs %d rsize %d \n", nsegs, rsize ); // 32, 128 // This is for csio->data_ptr Modified: head/sys/dev/sdhci/sdhci.c ============================================================================== --- head/sys/dev/sdhci/sdhci.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/sdhci/sdhci.c Sat Nov 28 12:12:51 2020 (r368124) @@ -722,19 +722,19 @@ sdhci_dma_alloc(struct sdhci_slot *slot) int err; if (!(slot->quirks & SDHCI_QUIRK_BROKEN_SDMA_BOUNDARY)) { - if (MAXPHYS <= 1024 * 4) + if (maxphys <= 1024 * 4) slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_4K; - else if (MAXPHYS <= 1024 * 8) + else if (maxphys <= 1024 * 8) slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_8K; - else if (MAXPHYS <= 1024 * 16) + else if (maxphys <= 1024 * 16) slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_16K; - else if (MAXPHYS <= 1024 * 32) + else if (maxphys <= 1024 * 32) slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_32K; - else if (MAXPHYS <= 1024 * 64) + else if (maxphys <= 1024 * 64) slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_64K; - else if (MAXPHYS <= 1024 * 128) + else if (maxphys <= 1024 * 128) slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_128K; - else if (MAXPHYS <= 1024 * 256) + else if (maxphys <= 1024 * 256) slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_256K; else slot->sdma_boundary = SDHCI_BLKSZ_SDMA_BNDRY_512K; @@ -2534,7 +2534,7 @@ sdhci_cam_action(struct cam_sim *sim, union ccb *ccb) switch (ccb->ccb_h.func_code) { case XPT_PATH_INQ: - mmc_path_inq(&ccb->cpi, "Deglitch Networks", sim, MAXPHYS); + mmc_path_inq(&ccb->cpi, "Deglitch Networks", sim, maxphys); break; case XPT_GET_TRAN_SETTINGS: Modified: head/sys/dev/siis/siis.c ============================================================================== --- head/sys/dev/siis/siis.c Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/siis/siis.c Sat Nov 28 12:12:51 2020 (r368124) @@ -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, int 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); Modified: head/sys/dev/siis/siis.h ============================================================================== --- head/sys/dev/siis/siis.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/siis/siis.h Sat Nov 28 12:12:51 2020 (r368124) @@ -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 */ Modified: head/sys/dev/sym/sym_conf.h ============================================================================== --- head/sys/dev/sym/sym_conf.h Sat Nov 28 10:38:00 2020 (r368123) +++ head/sys/dev/sym/sym_conf.h Sat Nov 28 12:12:51 2020 (r368124) @@ -95,9 +95,9 @@ * Max number of scatter/gather entries for an I/O. * Each entry costs 8 bytes in the internal CCB data structure. * We use at most 33 segments but also no more than required for handling - * MAXPHYS. + * legacy MAXPHYS == 128 * 1024. */ -#define SYM_CONF_MAX_SG (MIN(33, (MAXPHYS / PAGE_SIZE) + 1)) +#define SYM_CONF_MAX_SG (MIN(33, (128 * 1024 / PAGE_SIZE) + 1)) /* * Max number of targets. *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***