From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by dpdk.org (Postfix) with ESMTP id E8FFAFE5 for ; Mon, 11 May 2015 19:31:00 +0200 (CEST) Received: by pacwv17 with SMTP id wv17so115087545pac.0 for ; Mon, 11 May 2015 10:31:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=Fn9CmIZGL7eqn8wXvK5LjqBfYfV+8dUHB6Lm86H93OI=; b=bO2Mq/9Qrj18STRS626TkuR1PVLXWnXv6hq/zIyzzGjib53NhQt/YPsWxEkvNxLK4E UD/fqPNPFvjMQkclIGLA8Ha1aMU7zqoh1RKTqyIUUgC4lkOrLTlfqYDyMoaAUpaDQ60f rRlwDlvXDEnHjHGpaxKgX5WPoy3SX1LyY3jcl5ddcXTWzZu9AKE78D2yPg/44NnoZmyF 2DOYhLh5uCY0f9rZsO/ddZoEoiG2wiBaoKWdTw7Rs5m/Ql5B1epFK2BiCFPcz8GlBart qMo3tvO65A3D3dThGGx/4Ese+CmywPqoMcBFZSrY3uJVEy6mdv29tFqW3oWLYEe4TcCb TIsg== X-Gm-Message-State: ALoCoQmoCiqoMnLBEB+gnCsDle9ZotS1IsIIhLcHXDxGnWnArDeN6y02ddIR8HOiUJxqD3MJEySF X-Received: by 10.66.66.135 with SMTP id f7mr20878264pat.22.1431365460347; Mon, 11 May 2015 10:31:00 -0700 (PDT) Received: from urahara (static-50-53-82-155.bvtn.or.frontiernet.net. [50.53.82.155]) by mx.google.com with ESMTPSA id qz3sm13735132pab.19.2015.05.11.10.30.59 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 May 2015 10:31:00 -0700 (PDT) Date: Mon, 11 May 2015 10:31:04 -0700 From: Stephen Hemminger To: Neil Horman Message-ID: <20150511103104.1c60565b@urahara> In-Reply-To: <38426478085b4e779e18967cd1b6ae4f@BRMWP-EXMB11.corp.brocade.com> References: <1431041135-6289-1-git-send-email-stephen@networkplumber.org> <1431041135-6289-2-git-send-email-stephen@networkplumber.org> <38426478085b4e779e18967cd1b6ae4f@BRMWP-EXMB11.corp.brocade.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: "dev@dpdk.org" , Stephen Hemminger Subject: Re: [dpdk-dev] [PATCH 1/4] pci: allow access to PCI config space X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 May 2015 17:31:01 -0000 On Mon, 11 May 2015 12:54:54 +0000 Neil Horman wrote: > On Thu, May 07, 2015 at 04:25:32PM -0700, Stephen Hemminger wrote: > > From: Stephen Hemminger > > > > Some drivers need ability to access PCI config (for example for power > > management). This adds an abstraction to do this; only implemented > > on Linux, but should be possible on BSD. > > Could someone who has BSD infrastructure try this, not sure if it will even build. diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c index 61e8921..8ba5b13 100644 --- a/lib/librte_eal/bsdapp/eal/eal_pci.c +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c @@ -490,6 +490,76 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d return 1; } +/* Read PCI config space. */ +int rte_eal_pci_read_config(const struct rte_pci_device *dev, + void *buf, size_t len, off_t offset) +{ + int fd = -1; + + fd = open("/dev/pci", O_RDONLY); + if (fd < 0) { + RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__); + goto error; + } + + struct pci_io pi = { + .pi_sel = { + .pc_domain = dev->addr.domain, + .bus = dev->addr.bus, + .pc_dev = dev->addr.devid, + .pc_func = dev->addr.function, + }, + .pi_reg = offset, + .pi_data = buf, + .pi_width = len, + }; + + if (ioctl(fd, PCIIOCREAD, &pi) < 0) + goto error; + close(fd); + return 0; + +error: + if (fd >= 0) + close(fd); + return -1; +} + +/* Write PCI config space. */ +int rte_eal_pci_write_config(const struct rte_pci_device *device, + const void *buf, size_t len, off_t offset) +{ + int fd = -1; + + fd = open("/dev/pci", O_RDONLY); + if (fd < 0) { + RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__); + goto error; + } + + struct pci_io pi = { + .pi_sel = { + .pc_domain = dev->addr.domain, + .bus = dev->addr.bus, + .pc_dev = dev->addr.devid, + .pc_func = dev->addr.function, + }, + .pi_reg = offset, + .pi_data = buf, + .pi_width = len, + }; + + if (ioctl(fd, PCIIOCWRITE, &pi) < 0) + goto error; + close(fd); + return 0; + +error: + if (fd >= 0) + close(fd); + return -1; +} + /* Init the PCI EAL subsystem */ int rte_eal_pci_init(void)