Date: Tue, 17 Nov 2020 16:34:58 +0000 (UTC) From: Alexander Motin <mav@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367768 - in head/sbin/nvmecontrol: . modules/wdc Message-ID: <202011171634.0AHGYwKR092497@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mav Date: Tue Nov 17 16:34:58 2020 New Revision: 367768 URL: https://svnweb.freebsd.org/changeset/base/367768 Log: 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. MFC after: 1 month Modified: head/sbin/nvmecontrol/firmware.c head/sbin/nvmecontrol/modules/wdc/wdc.c Modified: head/sbin/nvmecontrol/firmware.c ============================================================================== --- head/sbin/nvmecontrol/firmware.c Tue Nov 17 14:59:58 2020 (r367767) +++ head/sbin/nvmecontrol/firmware.c Tue Nov 17 16:34:58 2020 (r367768) @@ -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: head/sbin/nvmecontrol/modules/wdc/wdc.c ============================================================================== --- head/sbin/nvmecontrol/modules/wdc/wdc.c Tue Nov 17 14:59:58 2020 (r367767) +++ head/sbin/nvmecontrol/modules/wdc/wdc.c Tue Nov 17 16:34:58 2020 (r367768) @@ -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?202011171634.0AHGYwKR092497>