From owner-svn-src-head@freebsd.org Tue Jul 28 11:23:38 2020 Return-Path: Delivered-To: svn-src-head@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 39B5D3A68B9; Tue, 28 Jul 2020 11:23:38 +0000 (UTC) (envelope-from alfredo@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 4BGDnk0Tqvz4H9S; Tue, 28 Jul 2020 11:23:38 +0000 (UTC) (envelope-from alfredo@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 E80D9E5A4; Tue, 28 Jul 2020 11:23:37 +0000 (UTC) (envelope-from alfredo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06SBNbcf053883; Tue, 28 Jul 2020 11:23:37 GMT (envelope-from alfredo@FreeBSD.org) Received: (from alfredo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06SBNb0E053882; Tue, 28 Jul 2020 11:23:37 GMT (envelope-from alfredo@FreeBSD.org) Message-Id: <202007281123.06SBNb0E053882@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: alfredo set sender to alfredo@FreeBSD.org using -f From: "Alfredo Dal'Ava Junior" Date: Tue, 28 Jul 2020 11:23:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363646 - head/sys/dev/virtio/pci X-SVN-Group: head X-SVN-Commit-Author: alfredo X-SVN-Commit-Paths: head/sys/dev/virtio/pci X-SVN-Commit-Revision: 363646 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2020 11:23:38 -0000 Author: alfredo Date: Tue Jul 28 11:23:37 2020 New Revision: 363646 URL: https://svnweb.freebsd.org/changeset/base/363646 Log: virtio: fix mips regression introduced by r357596 PowerPC support was fixed in r357596 by changing PCI bustag to BE as part of the solution, but this caused regression on mips. This change implements byte swapping of virtio PCI config area in the driver, leaving lower layer untouched. Submittnd by: Fernando Valle Reported by: arichardson Reviewed by: alfredo, arichardson Sponsored by: Eldorado Research Institute (eldorado.org.br) Differential Revision: https://reviews.freebsd.org/D25416 Modified: head/sys/dev/virtio/pci/virtio_pci.c Modified: head/sys/dev/virtio/pci/virtio_pci.c ============================================================================== --- head/sys/dev/virtio/pci/virtio_pci.c Tue Jul 28 11:13:37 2020 (r363645) +++ head/sys/dev/virtio/pci/virtio_pci.c Tue Jul 28 11:23:37 2020 (r363646) @@ -179,23 +179,25 @@ static void vtpci_config_intr(void *); * I/O port read/write wrappers. */ #define vtpci_read_config_1(sc, o) bus_read_1((sc)->vtpci_res, (o)) -#define vtpci_read_config_2(sc, o) bus_read_2((sc)->vtpci_res, (o)) -#define vtpci_read_config_4(sc, o) bus_read_4((sc)->vtpci_res, (o)) #define vtpci_write_config_1(sc, o, v) bus_write_1((sc)->vtpci_res, (o), (v)) -#define vtpci_write_config_2(sc, o, v) bus_write_2((sc)->vtpci_res, (o), (v)) -#define vtpci_write_config_4(sc, o, v) bus_write_4((sc)->vtpci_res, (o), (v)) /* - * Legacy VirtIO header is always PCI endianness (little), so if we - * are in a BE machine we need to swap bytes from LE to BE when reading - * and from BE to LE when writing. - * If we are in a LE machine, there will be no swaps. + * Virtio-pci specifies that PCI Configuration area is guest endian. However, + * since PCI devices are inherently little-endian, on BE systems the bus layer + * transparently converts it to BE. For virtio-legacy, this conversion is + * undesired, so an extra byte swap is required to fix it. */ -#define vtpci_read_header_2(sc, o) le16toh(vtpci_read_config_2(sc, o)) -#define vtpci_read_header_4(sc, o) le32toh(vtpci_read_config_4(sc, o)) -#define vtpci_write_header_2(sc, o, v) vtpci_write_config_2(sc, o, (htole16(v))) -#define vtpci_write_header_4(sc, o, v) vtpci_write_config_4(sc, o, (htole32(v))) +#define vtpci_read_config_2(sc, o) le16toh(bus_read_2((sc)->vtpci_res, (o))) +#define vtpci_read_config_4(sc, o) le32toh(bus_read_4((sc)->vtpci_res, (o))) +#define vtpci_write_config_2(sc, o, v) bus_write_2((sc)->vtpci_res, (o), (htole16(v))) +#define vtpci_write_config_4(sc, o, v) bus_write_4((sc)->vtpci_res, (o), (htole32(v))) +/* PCI Header LE. On BE systems the bus layer takes care of byte swapping */ +#define vtpci_read_header_2(sc, o) (bus_read_2((sc)->vtpci_res, (o))) +#define vtpci_read_header_4(sc, o) (bus_read_4((sc)->vtpci_res, (o))) +#define vtpci_write_header_2(sc, o, v) bus_write_2((sc)->vtpci_res, (o), (v)) +#define vtpci_write_header_4(sc, o, v) bus_write_4((sc)->vtpci_res, (o), (v)) + /* Tunables. */ static int vtpci_disable_msix = 0; TUNABLE_INT("hw.virtio.pci.disable_msix", &vtpci_disable_msix); @@ -289,17 +291,6 @@ vtpci_attach(device_t dev) device_printf(dev, "cannot map I/O space\n"); return (ENXIO); } - -/* - * For legacy VirtIO, the device-specific configuration is guest - * endian, while the common configuration header is always - * PCI (little) endian and will be handled specifically in - * other parts of this file via functions - * 'vtpci_[read|write]_header_[2|4]' - */ -#if _BYTE_ORDER == _BIG_ENDIAN - rman_set_bustag(sc->vtpci_res, &bs_be_tag); -#endif if (pci_find_cap(dev, PCIY_MSI, NULL) != 0) sc->vtpci_flags |= VTPCI_FLAG_NO_MSI;