From patchwork Fri Jan 8 20:30:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Milard X-Patchwork-Id: 59418 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp761515lbb; Fri, 8 Jan 2016 12:02:02 -0800 (PST) X-Received: by 10.140.224.138 with SMTP id u132mr29135622qhb.67.1452283322477; Fri, 08 Jan 2016 12:02:02 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f47si11777495qge.29.2016.01.08.12.02.02; Fri, 08 Jan 2016 12:02:02 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C83E961666; Fri, 8 Jan 2016 20:02:01 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=K7/G7krD; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4F54F61D9B; Fri, 8 Jan 2016 19:39:09 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 2860C6179C; Fri, 8 Jan 2016 19:36:43 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by lists.linaro.org (Postfix) with ESMTPS id E007561CB0 for ; Fri, 8 Jan 2016 19:32:13 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id m198so33839770lfm.0 for ; Fri, 08 Jan 2016 11:32:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6KVykGTOfJHW5s8N61JlXTCSAeSV0JdkFZwLexRAbd0=; b=K7/G7krDZRVBzsaeBYe6P8Eu2f0qGmjvLuk5wDC1F7ffPCVBnADjSRtRK0Fq8nrGN3 IJCHqC3ttNEFKR3ewOzY1d/PlmHfewpSqQn1gB81jgYRZ4nEVxU4SsWDc2i3aecFdYy6 e9ymd1mI/sm3QiZoCGfEG9GUlJgREvitEzDGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6KVykGTOfJHW5s8N61JlXTCSAeSV0JdkFZwLexRAbd0=; b=cQdNxxUtzxb+m3lx68b/qOtgEozf0fQGns3AHOtatKItU1TlY4igkRX1GHqL7nJNCu WEIkX+SuWB3P/QVJQLsLOGr1udCj3u76k2wbGbNytLoSDIGkLOkU+AC3/5yWkCDQP7Dm GNSuYly7WIh8ca8nG/AzwlRo8MrD981WbHWn2NFsBvt/SUXpAg07YAGN5gLpTxTvGL4u FRtC9h3SnvXQ3mHGcMx/VWAEfVrCQ2UdN2KJc6yVCc4T3k7ePlRHFsYeQUiVSq6d62vF qZKNSabuvw1Kz1YoNqBfsuFsW1MDqPb07hVU3aM8Pp2vAuPwB6BYjuNj7yI55NzVdQr8 9P9A== X-Gm-Message-State: ALoCoQmnfmOu3ksdDCpuei5dJmRI+phEFx2lvF4jdbeVNabzj578Nk52wt89dhgfVqsQ5hsMZ+8puCHq3tSWVRTz79Ornaz54Q== X-Received: by 10.25.143.143 with SMTP id r137mr37584419lfd.93.1452281532865; Fri, 08 Jan 2016 11:32:12 -0800 (PST) Received: from erachmi-ericsson.ki.sw.ericsson.se (c-83-233-90-46.cust.bredband2.com. [83.233.90.46]) by smtp.gmail.com with ESMTPSA id l204sm2085534lfg.49.2016.01.08.11.32.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 08 Jan 2016 11:32:11 -0800 (PST) From: Christophe Milard To: anders.roxell@linaro.org, mike.holmes@linaro.org, stuart.haslam@linaro.org, maxim.uvarov@linaro.org, bill.fischofer@linaro.org, petri.savolainen@linaro.org, edavis@broadcom.com Date: Fri, 8 Jan 2016 21:30:14 +0100 Message-Id: <1452285014-60320-32-git-send-email-christophe.milard@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> References: <1452285014-60320-1-git-send-email-christophe.milard@linaro.org> Cc: lng-odp@lists.linaro.org Subject: [lng-odp] [API-NEXT RFC 31/31] validation: pktio: setup for nic pktio X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Shell to setup the nic driver interfaces. This script is given a list of PCI addresses, and will unbind the current running linux driver and bind the pci-vfio driver there instead. Also enable user permission for vfio groups... Must be run as root. When sourced, also sets the ODP_PKTIO_IF environment variables. For instance, syntax is: source pktio_setup_nic 0000:23:00.0 0000:23:00.1 The usage of this script is still manual. It is meant to be called in the future pktio_run_nic script in the future. Signed-off-by: Christophe Milard --- platform/linux-generic/test/pktio/pktio_setup_nic | 105 ++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 platform/linux-generic/test/pktio/pktio_setup_nic diff --git a/platform/linux-generic/test/pktio/pktio_setup_nic b/platform/linux-generic/test/pktio/pktio_setup_nic new file mode 100755 index 0000000..640930c --- /dev/null +++ b/platform/linux-generic/test/pktio/pktio_setup_nic @@ -0,0 +1,105 @@ +#!/bin/bash +#this script must be run as root (modprobe etc...) + +setup_vfio() { + user=$1 + shift + + #iommu should be running for the following to work: + #on intel, put kernel boot option "intel_iommu=on" + + #read the PCI group it belongs to: + grp=`readlink /sys/bus/pci/devices/${target}/iommu_group ` + grp=`echo ${grp} | grep -o '[^/]*$'` + echo target ${target} is in group: ${grp} + + modprobe vfio-pci + + #collect the PCI vendor:ID of the selected device: + addr=`lspci -n -mm -s ${target} | cut -d' ' -f3-4 | sed -e's/"//g'` + + #unbind the current driver: + echo ${target} > /sys/bus/pci/devices/${target}/driver/unbind + + #and bind it to the vfio-pci driver + #Binding the device to the vfio-pci driver creates the VFIO group + #character devices for this group: + + echo ${addr} > /sys/bus/pci/drivers/vfio-pci/new_id + + #Now we need to look at what other devices are in the group to free + #it for use by VFIO: + + #check manually that no other devices are in the same group: + #If more than the PCI bridge is listed here, remove these + #devices manually from the group. + #ls -l /sys/bus/pci/devices/${target}/iommu_group/devices + + #give user access to the group: + chown $user:$user /dev/vfio/${grp} + #to ba able to map the config space??? not possible via vfio!?? + chmod a+rw /sys/bus/pci/devices/${target}/config +} + +usage() { + prog=$1 + echo -e "$prog [user=] [*]" + echo -e "\t for instance: $prog 0000:23:00.0 0000:23:00.1" + echo -e "\t or $prog user=donaldduck 0000:23:00.0 0000:23:00.1" + echo -e "\t the script will attempt to sudo if not root." + echo -e "\t Environment variables ODP_PKTIO_IF are set if sourced." + echo -e "It is assumed that the differents devices belongs to different " + echo -e "vfio groups." + echo +} + +############################### MAIN ######################### + +#collect the name of the program being run +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + prog=${BASH_SOURCE[0]} + sourced=yes +else + sourced=no + prog=$0 +fi + + +#help? +if [[ "x$1" = "x-h" || "x$1" = "x--help" || "x$1" = "x" ]]; then + usage $prog + if [[ "$sourced" = yes ]]; then + return 0 + else + exit 0 + fi +fi + +#check if first arg is user= (with no space): +#default to current user if no user given +first_arg=$1 +if [[ ${first_arg:0:5} = 'user=' ]]; then + user=$(echo $first_arg| cut -d'=' -f 2) + shift +else + user=$(whoami) +fi + +##root? : do real setup: +index=0 +if [[ "$(id -u)" = "0" ]]; then + for target in $*; do + echo "setting up ${target}" + setup_vfio $user ${target} + export ODP_PKTIO_IF${index}="pmd:${target}" + export ODP_WAIT_FOR_NETWORK=1 + ((index++)) + done +else #try to sudo + sudo $prog "user=$user" $* + for target in $*; do + export ODP_PKTIO_IF${index}="pmd:${target}" + export ODP_WAIT_FOR_NETWORK=1 + ((index++)) + done +fi