Date: Sun, 13 Dec 2020 02:21:55 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r368603 - in stable/12/sbin/nvmecontrol: . modules/wdc Message-ID: <202012130221.0BD2LtXk070912@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Sun Dec 13 02:21:54 2020 New Revision: 368603 URL: https://svnweb.freebsd.org/changeset/base/368603 Log: MFC r367768: Stop using NVME_MAX_XFER_SIZE constant. This constant depends on MAXPHYS and does not respect device capabilities. Use proper dynamic ioctl(NVME_GET_MAX_XFER_SIZE) instead. Modified: stable/12/sbin/nvmecontrol/firmware.c stable/12/sbin/nvmecontrol/modules/wdc/wdc.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sbin/nvmecontrol/firmware.c ============================================================================== --- stable/12/sbin/nvmecontrol/firmware.c Sun Dec 13 02:19:18 2020 (r368602) +++ stable/12/sbin/nvmecontrol/firmware.c Sun Dec 13 02:21:54 2020 (r368603) @@ -166,12 +166,10 @@ update_firmware(int fd, uint8_t *payload, int32_t payl off = 0; resid = payload_size; - if (fwug != 0 && fwug != 0xFF) - max_xfer_size = ((uint64_t)fwug << 12); - else if (ioctl(fd, NVME_GET_MAX_XFER_SIZE, &max_xfer_size) < 0) + if (ioctl(fd, NVME_GET_MAX_XFER_SIZE, &max_xfer_size) < 0) err(EX_IOERR, "query max transfer size failed"); - if (max_xfer_size > NVME_MAX_XFER_SIZE) - max_xfer_size = NVME_MAX_XFER_SIZE; + if (fwug != 0 && fwug != 0xFF) + max_xfer_size = MIN(max_xfer_size, (uint64_t)fwug << 12); if ((chunk = aligned_alloc(PAGE_SIZE, max_xfer_size)) == NULL) errx(EX_OSERR, "unable to malloc %zd bytes", (size_t)max_xfer_size); Modified: stable/12/sbin/nvmecontrol/modules/wdc/wdc.c ============================================================================== --- stable/12/sbin/nvmecontrol/modules/wdc/wdc.c Sun Dec 13 02:19:18 2020 (r368602) +++ stable/12/sbin/nvmecontrol/modules/wdc/wdc.c Sun Dec 13 02:21:54 2020 (r368603) @@ -165,6 +165,7 @@ wdc_do_dump_e6(int fd, char *tmpl, const char *suffix, int first; int fd2; uint8_t *buf, *hdr; + uint64_t max_xfer_size; uint32_t len, offset; size_t resid; bool e6lg_flag = false; @@ -186,15 +187,17 @@ wdc_do_dump_e6(int fd, char *tmpl, const char *suffix, fd2 = open(tmpl, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd2 < 0) err(EX_CANTCREAT, "open %s", tmpl); - buf = aligned_alloc(PAGE_SIZE, NVME_MAX_XFER_SIZE); + if (ioctl(fd, NVME_GET_MAX_XFER_SIZE, &max_xfer_size) < 0) + err(EX_IOERR, "query max transfer size failed"); + buf = aligned_alloc(PAGE_SIZE, max_xfer_size); if (buf == NULL) errx(EX_OSERR, "Can't get buffer to read dump"); offset = 0; - len = NVME_MAX_XFER_SIZE; + len = max_xfer_size; first = 1; do { - resid = len > NVME_MAX_XFER_SIZE ? NVME_MAX_XFER_SIZE : len; + resid = MIN(len, max_xfer_size); wdc_get_data(fd, opcode, resid, offset, cmd, buf, resid, e6lg_flag); if (first) { @@ -321,6 +324,7 @@ wdc_do_dump_dui(int fd, char *tmpl, uint8_t data_area, { int fd2, first; uint8_t *buf; + uint64_t max_xfer_size; uint16_t hdr_ver; uint64_t log_len, offset; size_t resid; @@ -332,14 +336,16 @@ wdc_do_dump_dui(int fd, char *tmpl, uint8_t data_area, fd2 = open(tmpl, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (fd2 < 0) err(EX_CANTCREAT, "open %s", tmpl); - buf = aligned_alloc(PAGE_SIZE, NVME_MAX_XFER_SIZE); + if (ioctl(fd, NVME_GET_MAX_XFER_SIZE, &max_xfer_size) < 0) + err(EX_IOERR, "query max transfer size failed"); + buf = aligned_alloc(PAGE_SIZE, max_xfer_size); if (buf == NULL) errx(EX_OSERR, "Can't get buffer to read dump"); offset = 0; first = 1; while (log_len > 0) { - resid = log_len > NVME_MAX_XFER_SIZE ? NVME_MAX_XFER_SIZE : log_len; + resid = MIN(log_len, max_xfer_size); wdc_get_data_dui(fd, opcode, resid, offset, buf, resid); if (first) { hdr_ver = ((buf[len_off] & 0xF) != 0) ?
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012130221.0BD2LtXk070912>