Date: Mon, 24 Aug 2020 10:42:04 +0000 (UTC) From: Emmanuel Vadot <manu@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: r364653 - in stable/12/sys: compat/linuxkpi/common/include/linux compat/linuxkpi/common/src dev/qlnx/qlnxe Message-ID: <202008241042.07OAg44w059080@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: manu Date: Mon Aug 24 10:42:04 2020 New Revision: 364653 URL: https://svnweb.freebsd.org/changeset/base/364653 Log: MFC r360787, r360851, r360870-r360872 r360787: linuxkpi: Add pci_iomap and pci_iounmap Those function are use to map/unmap io region of a pci device. Different resource can be mapped depending on the bar so use a tailq to store them all. Sponsored-by: The FreeBSD Foundation Reviewed by: emaste, hselasky Differential Revision: https://reviews.freebsd.org/D24696 r360851: linuxkpi: Add bitmap_copy and bitmap_andnot bitmap_copy simply copy the bitmaps, no idea why it exists. bitmap_andnot is similar to bitmap_and but uses !src2. Sponsored-by: The FreeBSD Foundation Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D24782 r360870: linuxkpi: Add bitmap_alloc and bitmap_free This is a simple call to kmallock_array/kfree, therefore include linux/slab.h as this is where the kmalloc_array/kfree definition is. Sponsored-by: The FreeBSD Foundation Reviewed by: hselsasky Differential Revision: https://reviews.freebsd.org/D24794 r360871: linuxkpi: Really add bitmap_alloc and bitmap_zalloc This was missing in r360870 Sponsored-by: The FreeBSD Foundation r360872: qnlx: Do not redifines types. r360870 added linux/slab.h into liunx/bitmap.h and this include linux/types.h The qlnx driver is redefining some of those types so remove them and add an explicit linux/types.h include. Pointy hat: manu Reported by: Austin Shafer <ashafer@badland.io> Modified: stable/12/sys/compat/linuxkpi/common/include/linux/bitmap.h stable/12/sys/compat/linuxkpi/common/include/linux/pci.h stable/12/sys/compat/linuxkpi/common/src/linux_pci.c stable/12/sys/dev/qlnx/qlnxe/bcm_osal.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linuxkpi/common/include/linux/bitmap.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/bitmap.h Mon Aug 24 10:28:15 2020 (r364652) +++ stable/12/sys/compat/linuxkpi/common/include/linux/bitmap.h Mon Aug 24 10:42:04 2020 (r364653) @@ -30,6 +30,7 @@ #define _LINUX_BITMAP_H_ #include <linux/bitops.h> +#include <linux/slab.h> static inline void bitmap_zero(unsigned long *addr, const unsigned int size) @@ -277,6 +278,17 @@ bitmap_complement(unsigned long *dst, const unsigned l } static inline void +bitmap_copy(unsigned long *dst, const unsigned long *src, + const unsigned int size) +{ + const unsigned int end = BITS_TO_LONGS(size); + unsigned int i; + + for (i = 0; i != end; i++) + dst[i] = src[i]; +} + +static inline void bitmap_or(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, const unsigned int size) { @@ -299,6 +311,17 @@ bitmap_and(unsigned long *dst, const unsigned long *sr } static inline void +bitmap_andnot(unsigned long *dst, const unsigned long *src1, + const unsigned long *src2, const unsigned int size) +{ + const unsigned int end = BITS_TO_LONGS(size); + unsigned int i; + + for (i = 0; i != end; i++) + dst[i] = src1[i] & ~src2[i]; +} + +static inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, const unsigned int size) { @@ -307,6 +330,25 @@ bitmap_xor(unsigned long *dst, const unsigned long *sr for (i = 0; i != end; i++) dst[i] = src1[i] ^ src2[i]; +} + +static inline unsigned long * +bitmap_alloc(unsigned int size, gfp_t flags) +{ + return (kmalloc_array(BITS_TO_LONGS(size), + sizeof(unsigned long), flags)); +} + +static inline unsigned long * +bitmap_zalloc(unsigned int size, gfp_t flags) +{ + return (bitmap_alloc(size, flags | __GFP_ZERO)); +} + +static inline void +bitmap_free(const unsigned long *bitmap) +{ + kfree(bitmap); } #endif /* _LINUX_BITMAP_H_ */ Modified: stable/12/sys/compat/linuxkpi/common/include/linux/pci.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Mon Aug 24 10:28:15 2020 (r364652) +++ stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Mon Aug 24 10:42:04 2020 (r364653) @@ -222,6 +222,13 @@ extern spinlock_t pci_lock; #define __devexit_p(x) x +struct pci_mmio_region { + TAILQ_ENTRY(pci_mmio_region) next; + struct resource *res; + int rid; + int type; +}; + struct pci_dev { struct device dev; struct list_head links; @@ -236,6 +243,8 @@ struct pci_dev { uint32_t class; uint8_t revision; bool msi_enabled; + + TAILQ_HEAD(, pci_mmio_region) mmio; }; static inline struct resource_list_entry * @@ -657,6 +666,41 @@ static inline int pci_enable_sriov(struct pci_dev *dev } static inline void pci_disable_sriov(struct pci_dev *dev) { +} + +static inline void * +pci_iomap(struct pci_dev *dev, int mmio_bar, int mmio_size __unused) +{ + struct pci_mmio_region *mmio; + + mmio = malloc(sizeof(*mmio), M_DEVBUF, M_WAITOK | M_ZERO); + mmio->rid = PCIR_BAR(mmio_bar); + mmio->type = pci_resource_type(dev, mmio_bar); + mmio->res = bus_alloc_resource_any(dev->dev.bsddev, mmio->type, + &mmio->rid, RF_ACTIVE); + if (mmio->res == NULL) { + free(mmio, M_DEVBUF); + return (NULL); + } + TAILQ_INSERT_TAIL(&dev->mmio, mmio, next); + + return ((void *)rman_get_bushandle(mmio->res)); +} + +static inline void +pci_iounmap(struct pci_dev *dev, void *res) +{ + struct pci_mmio_region *mmio, *p; + + TAILQ_FOREACH_SAFE(mmio, &dev->mmio, next, p) { + if (res != (void *)rman_get_bushandle(mmio->res)) + continue; + bus_release_resource(dev->dev.bsddev, + mmio->type, mmio->rid, mmio->res); + TAILQ_REMOVE(&dev->mmio, mmio, next); + free(mmio, M_DEVBUF); + return; + } } #define DEFINE_PCI_DEVICE_TABLE(_table) \ Modified: stable/12/sys/compat/linuxkpi/common/src/linux_pci.c ============================================================================== --- stable/12/sys/compat/linuxkpi/common/src/linux_pci.c Mon Aug 24 10:28:15 2020 (r364652) +++ stable/12/sys/compat/linuxkpi/common/src/linux_pci.c Mon Aug 24 10:42:04 2020 (r364653) @@ -271,6 +271,7 @@ linux_pci_attach_device(device_t dev, struct pci_drive if (error) goto out_dma_init; + TAILQ_INIT(&pdev->mmio); pbus = malloc(sizeof(*pbus), M_DEVBUF, M_WAITOK | M_ZERO); pbus->self = pdev; pbus->number = pci_get_bus(dev); Modified: stable/12/sys/dev/qlnx/qlnxe/bcm_osal.h ============================================================================== --- stable/12/sys/dev/qlnx/qlnxe/bcm_osal.h Mon Aug 24 10:28:15 2020 (r364652) +++ stable/12/sys/dev/qlnx/qlnxe/bcm_osal.h Mon Aug 24 10:42:04 2020 (r364653) @@ -34,6 +34,8 @@ #include "ecore_status.h" #include <sys/bitstring.h> +#include <linux/types.h> + #if __FreeBSD_version >= 1200032 #include <linux/bitmap.h> #else @@ -112,11 +114,6 @@ extern void qlnx_vf_flr_update(void *p_hwfn); #define s32 uint32_t #ifndef QLNX_RDMA - -typedef uint16_t __le16; -typedef uint32_t __le32; -typedef uint16_t __be16; -typedef uint32_t __be32; static __inline unsigned long roundup_pow_of_two(unsigned long x)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008241042.07OAg44w059080>