From owner-svn-src-all@freebsd.org Wed Nov 20 23:49:48 2019 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 DAD851C5BFC; Wed, 20 Nov 2019 23:49:48 +0000 (UTC) (envelope-from mav@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) server-signature RSA-PSS (4096 bits) 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 47JKDX5Bssz4XG9; Wed, 20 Nov 2019 23:49:48 +0000 (UTC) (envelope-from mav@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 912A42695; Wed, 20 Nov 2019 23:49:48 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xAKNnmXk039061; Wed, 20 Nov 2019 23:49:48 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xAKNnmu3039059; Wed, 20 Nov 2019 23:49:48 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201911202349.xAKNnmu3039059@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Wed, 20 Nov 2019 23:49:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r354923 - stable/12/sys/dev/ahci X-SVN-Group: stable-12 X-SVN-Commit-Author: mav X-SVN-Commit-Paths: stable/12/sys/dev/ahci X-SVN-Commit-Revision: 354923 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.29 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: Wed, 20 Nov 2019 23:49:48 -0000 Author: mav Date: Wed Nov 20 23:49:47 2019 New Revision: 354923 URL: https://svnweb.freebsd.org/changeset/base/354923 Log: MFC r351589: Fix AHCI Enclosure Management, broken by r351356. ivars value of -1 was used to distinguish EM device, and r351356 left some wrong checks for it. Give EM device separate flag there instead. Modified: stable/12/sys/dev/ahci/ahci.c stable/12/sys/dev/ahci/ahci.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/ahci/ahci.c ============================================================================== --- stable/12/sys/dev/ahci/ahci.c Wed Nov 20 23:45:31 2019 (r354922) +++ stable/12/sys/dev/ahci/ahci.c Wed Nov 20 23:49:47 2019 (r354923) @@ -362,7 +362,7 @@ ahci_attach(device_t dev) if (child == NULL) device_printf(dev, "failed to add enclosure device\n"); else - device_set_ivars(child, (void *)(intptr_t)-1); + device_set_ivars(child, (void *)(intptr_t)AHCI_EM_UNIT); } bus_generic_attach(dev); return (0); @@ -562,23 +562,25 @@ ahci_alloc_resource(device_t dev, device_t child, int struct resource *res; rman_res_t st; int offset, size, unit; - bool is_remapped; + bool is_em, is_remapped; unit = (intptr_t)device_get_ivars(child); + is_em = is_remapped = false; if (unit & AHCI_REMAPPED_UNIT) { - unit &= ~AHCI_REMAPPED_UNIT; + unit &= AHCI_UNIT; unit -= ctlr->channels; is_remapped = true; - } else - is_remapped = false; + } else if (unit & AHCI_EM_UNIT) { + unit &= AHCI_UNIT; + is_em = true; + } res = NULL; switch (type) { case SYS_RES_MEMORY: if (is_remapped) { offset = ctlr->remap_offset + unit * ctlr->remap_size; size = ctlr->remap_size; - } - else if (unit >= 0) { + } else if (!is_em) { offset = AHCI_OFFSET + (unit << 7); size = 128; } else if (*rid == 0) { @@ -639,7 +641,7 @@ ahci_setup_intr(device_t dev, device_t child, struct r void *argument, void **cookiep) { struct ahci_controller *ctlr = device_get_softc(dev); - int unit = (intptr_t)device_get_ivars(child) & ~AHCI_REMAPPED_UNIT; + int unit = (intptr_t)device_get_ivars(child) & AHCI_UNIT; if (filter != NULL) { printf("ahci.c: we cannot use a filter here\n"); @@ -655,7 +657,7 @@ ahci_teardown_intr(device_t dev, device_t child, struc void *cookie) { struct ahci_controller *ctlr = device_get_softc(dev); - int unit = (intptr_t)device_get_ivars(child) & ~AHCI_REMAPPED_UNIT; + int unit = (intptr_t)device_get_ivars(child) & AHCI_UNIT; ctlr->interrupt[unit].function = NULL; ctlr->interrupt[unit].argument = NULL; @@ -665,12 +667,13 @@ ahci_teardown_intr(device_t dev, device_t child, struc int ahci_print_child(device_t dev, device_t child) { - int retval, channel; + intptr_t ivars; + int retval; retval = bus_print_child_header(dev, child); - channel = (int)(intptr_t)device_get_ivars(child) & ~AHCI_REMAPPED_UNIT; - if (channel >= 0) - retval += printf(" at channel %d", channel); + ivars = (intptr_t)device_get_ivars(child); + if ((ivars & AHCI_EM_UNIT) == 0) + retval += printf(" at channel %d", (int)ivars & AHCI_UNIT); retval += bus_print_child_footer(dev, child); return (retval); } @@ -679,11 +682,11 @@ int ahci_child_location_str(device_t dev, device_t child, char *buf, size_t buflen) { - int channel; + intptr_t ivars; - channel = (int)(intptr_t)device_get_ivars(child) & ~AHCI_REMAPPED_UNIT; - if (channel >= 0) - snprintf(buf, buflen, "channel=%d", channel); + ivars = (intptr_t)device_get_ivars(child); + if ((ivars & AHCI_EM_UNIT) == 0) + snprintf(buf, buflen, "channel=%d", (int)ivars & AHCI_UNIT); return (0); } Modified: stable/12/sys/dev/ahci/ahci.h ============================================================================== --- stable/12/sys/dev/ahci/ahci.h Wed Nov 20 23:45:31 2019 (r354922) +++ stable/12/sys/dev/ahci/ahci.h Wed Nov 20 23:49:47 2019 (r354923) @@ -319,9 +319,10 @@ /* Total main work area. */ #define AHCI_WORK_SIZE (AHCI_CT_OFFSET + AHCI_CT_SIZE * ch->numslots) - -/* NVMe remapped device */ -#define AHCI_REMAPPED_UNIT (1 << 31) +/* ivars value fields */ +#define AHCI_REMAPPED_UNIT (1 << 31) /* NVMe remapped device. */ +#define AHCI_EM_UNIT (1 << 30) /* Enclosure Mgmt device. */ +#define AHCI_UNIT 0xff /* Channel number. */ struct ahci_dma_prd { u_int64_t dba;