All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Monjalon <thomas.monjalon-pdR9zngts4EAvxtiuMwx3w@public.gmane.org>
To: zhida zang <zhida.zang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: dev-VfR2kkLFssw@public.gmane.org
Subject: Re: [PATCH] scripts: enable extended tag of PCIe
Date: Mon, 23 Mar 2015 12:52:31 +0100	[thread overview]
Message-ID: <3200414.B2YSnFKgSE@xps13> (raw)
In-Reply-To: <1422593822-15531-1-git-send-email-zhida.zang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

Hi,

This patch needs review and documentation.
It's going to be dropped if nobody cares.

There were some previous discussions about it:
	http://dpdk.org/ml/archives/dev/2015-February/012708.html


2015-01-30 12:57, zhida zang:
> As 'extended tag' of PCIe needs to be enabled for i40e high performance,
> Linux command of 'setpci' can be used to check and set the corresponding 
> bit of 'extended tag' of PCIe configuration space. The script is to check
> and set the right bit in PCIe configuration space to enable 'extended tag'.
> 
> Signed-off-by: Zhida Zang <zhida.zang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
>  tools/set_pci.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 124 insertions(+)
>  create mode 100755 tools/set_pci.py
> 
> diff --git a/tools/set_pci.py b/tools/set_pci.py
> new file mode 100755
> index 0000000..e242efb
> --- /dev/null
> +++ b/tools/set_pci.py
> @@ -0,0 +1,124 @@
> +#! /usr/bin/python
> +import sys
> +import os
> +import subprocess
> +import getopt
> +from os.path import basename
> +
> +# The register to check if extended tag is supported or not.
> +PCI_DEV_CAP_REG = 0xA4
> +# The control register which contains the bit to enable/disable 'extended tag'.
> +PCI_DEV_CTRL_REG = 0xA8
> +# The mask of 'extended tag' in capability register.
> +PCI_DEV_CAP_EXT_TAG_MASK = 0x20
> +# The mask of 'extended tag' in control register.
> +PCI_DEV_CTRL_EXT_TAG_MASK = 0x100
> +
> +dev_ids = {}
> +flag = "Set"
> +
> +
> +def usage():
> +    '''Print usage information for the program'''
> +    argv0 = basename(sys.argv[0])
> +    print """
> +Usage:
> +------
> +
> +    %(argv0)s [options] DEVICE1 DEVICE2 ....
> +
> +where DEVICE1, DEVICE2 etc, are specified via PCI "domain:bus:slot.func" syntax
> +or "bus:slot.func" syntax. For devices bound to Linux kernel drivers, they may
> +also be referred to by Linux interface name e.g. eth0, eth1, em0, em1, etc.
> +
> +Options:
> +    --help, --usage:
> +        Display usage information and quit
> +
> +    -s --set:
> +        Set the following pci device
> +
> +    -u --Unset:
> +        Unset the following pci device
> +
> +Examples:
> +---------
> +To set pci 0a:00.0
> +        %(argv0)s -s 0a:00.0
> +        %(argv0)s --set 0a:00.0
> +
> +To unset 0000:01:00.0
> +        %(argv0)s -u 0000:01:00.0
> +        %(argv0)s --unset 0000:01:00.0
> +
> +To set 0000:02:00.0 and 0000:02:00.1
> +        %(argv0)s -s 02:00.0 02:00.1
> +
> +    """ % locals()  # replace items from local variables
> +
> +
> +def parse_args():
> +    global flag
> +    global dev_ids
> +    if len(sys.argv) <= 1:
> +        usage()
> +        sys.exit(0)
> +    try:
> +        opts, dev_ids = getopt.getopt(
> +            sys.argv[1:],
> +            "su",
> +            ["help", "usage", "set", "unset"]
> +            )
> +    except getopt.GetoptError, error:
> +        print str(error)
> +        print "Run '%s --usage' for further information" % sys.argv[0]
> +        sys.exit(1)
> +
> +    for opt, arg in opts:
> +        if opt == "--help" or opt == "--usage":
> +            usage()
> +            sys.exit(0)
> +        if opt == "-s" or opt == "--set":
> +            flag = "Set"
> +        if opt == "-u" or opt == "--unset":
> +            flag = "Unset"
> +
> +
> +def check_output(args, stderr=None):
> +    '''Run a command and capture its output'''
> +    return subprocess.Popen(
> +        args,
> +        stdout=subprocess.PIPE,
> +        stderr=stderr
> +        ).communicate()[0]
> +
> +
> +def set_pci():
> +    if len(dev_ids) == 0:
> +        print "Error: No devices specified."
> +        print "Run '%s --usage' for further information" % sys.argv[0]
> +        sys.exit(1)
> +    param_cap = "%x.W" % PCI_DEV_CAP_REG
> +    for k in range(len(dev_ids)):
> +        val = check_output(["setpci", "-s", dev_ids[k], param_cap])
> +        if (not (int(val, 16) & PCI_DEV_CAP_EXT_TAG_MASK)):
> +            print dev_ids[k], "Not supported"
> +            continue
> +        if (int(val, 16) & PCI_DEV_CTRL_EXT_TAG_MASK):
> +            continue
> +        param_ctrl = "%x.W" % PCI_DEV_CTRL_REG
> +        val = check_output(["setpci", "-s", dev_ids[k], param_ctrl])
> +        if flag == "Set":
> +            val = int(val, 16) | PCI_DEV_CTRL_EXT_TAG_MASK
> +        else:
> +            val = int(val, 16) & ~PCI_DEV_CTRL_EXT_TAG_MASK
> +        param_ctrl = "%x.W=%x" % (PCI_DEV_CTRL_REG, val)
> +        check_output(["setpci", "-s", dev_ids[k], param_ctrl])
> +
> +
> +def main():
> +    parse_args()
> +    set_pci()
> +
> +if __name__ == "__main__":
> +    main()
> 

  parent reply	other threads:[~2015-03-23 11:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <setpciv1>
2015-01-30  4:57 ` [PATCH] scripts: enable extended tag of PCIe zhida zang
     [not found]   ` <1422593822-15531-1-git-send-email-zhida.zang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2015-03-23 11:52     ` Thomas Monjalon [this message]
2015-03-24  1:07       ` Zhang, Helin
     [not found]         ` <F35DEAC7BCE34641BA9FAC6BCA4A12E70A830360-0J0gbvR4kTg/UvCtAeCM4rfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-25  3:32           ` Liu, Yong
     [not found]             ` <86228AFD5BCD8E4EBFD2B90117B5E81E10DA9B8A-0J0gbvR4kTggGBtAFL8yw7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-30  5:30               ` Lu, Patrick
     [not found]                 ` <EFC7DD9FAC418F4683FA895DBD8B35A30F00D165-96pTJSsuoYSkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2015-03-30  6:11                   ` Zhang, Helin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3200414.B2YSnFKgSE@xps13 \
    --to=thomas.monjalon-pdr9zngts4eavxtiumwx3w@public.gmane.org \
    --cc=dev-VfR2kkLFssw@public.gmane.org \
    --cc=zhida.zang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.