From owner-svn-src-all@freebsd.org Mon May 18 09:26:43 2020 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 7EF3E13CEE2; Mon, 18 May 2020 09:26:43 +0000 (UTC) (envelope-from hselasky@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 49QYYb2m48z4WnC; Mon, 18 May 2020 09:26:43 +0000 (UTC) (envelope-from hselasky@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 59AD11F68B; Mon, 18 May 2020 09:26:43 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04I9QhO4065023; Mon, 18 May 2020 09:26:43 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04I9QhiE065022; Mon, 18 May 2020 09:26:43 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <202005180926.04I9QhiE065022@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 18 May 2020 09:26:43 +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: r361198 - stable/12/sys/compat/linuxkpi/common/include/linux X-SVN-Group: stable-12 X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: stable/12/sys/compat/linuxkpi/common/include/linux X-SVN-Commit-Revision: 361198 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.33 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: Mon, 18 May 2020 09:26:43 -0000 Author: hselasky Date: Mon May 18 09:26:42 2020 New Revision: 361198 URL: https://svnweb.freebsd.org/changeset/base/361198 Log: MFC r360532: Implement more PCI-express bandwidth functions in the LinuxKPI. Submitted by: ashafer_badland.io (Austin Shafer) Sponsored by: Mellanox Technologies Modified: stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linuxkpi/common/include/linux/pci.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Mon May 18 09:25:55 2020 (r361197) +++ stable/12/sys/compat/linuxkpi/common/include/linux/pci.h Mon May 18 09:26:42 2020 (r361198) @@ -954,6 +954,47 @@ pcie_get_width_cap(struct pci_dev *dev) return (PCIE_LNK_WIDTH_UNKNOWN); } +static inline int +pcie_get_mps(struct pci_dev *dev) +{ + return (pci_get_max_payload(dev->dev.bsddev)); +} + +static inline uint32_t +PCIE_SPEED2MBS_ENC(enum pci_bus_speed spd) +{ + + switch(spd) { + case PCIE_SPEED_16_0GT: + return (16000 * 128 / 130); + case PCIE_SPEED_8_0GT: + return (8000 * 128 / 130); + case PCIE_SPEED_5_0GT: + return (5000 * 8 / 10); + case PCIE_SPEED_2_5GT: + return (2500 * 8 / 10); + default: + return (0); + } +} + +static inline uint32_t +pcie_bandwidth_available(struct pci_dev *pdev, + struct pci_dev **limiting, + enum pci_bus_speed *speed, + enum pcie_link_width *width) +{ + enum pci_bus_speed nspeed = pcie_get_speed_cap(pdev); + enum pcie_link_width nwidth = pcie_get_width_cap(pdev); + + if (speed) + *speed = nspeed; + if (width) + *width = nwidth; + + return (nwidth * PCIE_SPEED2MBS_ENC(nspeed)); +} + /* * The following functions can be used to attach/detach the LinuxKPI's * PCI device runtime. The pci_driver and pci_device_id pointer is