├── .gitignore ├── Documentation ├── COPYING ├── accfg │ ├── Makefile.am │ ├── accel-config-config-device.txt │ ├── accel-config-config-engine.txt │ ├── accel-config-config-group.txt │ ├── accel-config-config-user-default.txt │ ├── accel-config-config-wq.txt │ ├── accel-config-disable-device.txt │ ├── accel-config-disable-wq.txt │ ├── accel-config-enable-device.txt │ ├── accel-config-enable-wq.txt │ ├── accel-config-info.txt │ ├── accel-config-list.txt │ ├── accel-config-load-config.txt │ ├── accel-config-save-config.txt │ ├── accel-config.txt │ └── attrs.adoc ├── asciidoc.conf.in ├── asciidoctor-extensions.rb.in ├── copyright.txt ├── manpage-base.xsl └── manpage-normal.xsl ├── LICENSE_GPL_2_0 ├── Makefile.am ├── Makefile.am.in ├── README.md ├── SECURITY.md ├── TODO ├── accfg-test.spec.in ├── accfg.spec.in ├── accfg ├── Makefile.am ├── accel-config.c ├── accfg.h ├── config.c ├── config_attr.c ├── enable.c ├── idxd.h ├── lib │ ├── LICENSE_LGPL_2_1 │ ├── Makefile.am │ ├── libaccel-config.pc.in │ ├── libaccel-config.sym │ ├── libaccfg.c │ └── private.h ├── libaccel_config.h ├── list.c └── test.c ├── autogen.sh ├── builtin.h ├── ccan ├── array_size │ ├── LICENSE │ └── array_size.h ├── build_assert │ ├── LICENSE │ └── build_assert.h ├── check_type │ ├── LICENSE │ └── check_type.h ├── container_of │ ├── LICENSE │ └── container_of.h ├── endian │ ├── LICENSE │ └── endian.h ├── list │ ├── LICENSE │ ├── list.c │ └── list.h ├── minmax │ ├── LICENSE │ └── minmax.h ├── short_types │ ├── LICENSE │ └── short_types.h └── str │ ├── LICENSE │ ├── debug.c │ ├── str.c │ ├── str.h │ └── str_debug.h ├── configure.ac ├── contrib ├── accel-config.conf.sample └── configs │ ├── app_profile.conf │ ├── net_profile.conf │ ├── os_profile.conf │ ├── profilenote.txt │ ├── storage_profile.conf │ └── user_default_profile.conf ├── debbuild.sh ├── debdch.sh ├── debian ├── accel-config-test.install ├── accel-config.install ├── changelog ├── control ├── copyright ├── libaccel-config-dev.install ├── libaccel-config1.install ├── rules ├── source │ └── format └── watch ├── git-version ├── git-version-gen ├── licenses ├── BSD-MIT ├── CC0 ├── accel-config-licenses └── libaccel-config-licenses ├── make-git-snapshot.sh ├── rpmbuild-test.sh ├── rpmbuild.sh ├── sles └── header ├── test.h ├── test ├── Makefile.am ├── README.md ├── accel_test.c ├── accel_test.h ├── accfg_test.h ├── algorithms │ ├── iaa_compress.c │ ├── iaa_compress.h │ ├── iaa_crc64.c │ ├── iaa_crc64.h │ ├── iaa_crypto.c │ ├── iaa_crypto.h │ ├── iaa_filter.c │ ├── iaa_filter.h │ ├── iaa_zcompress.c │ └── iaa_zcompress.h ├── common ├── configs │ ├── 2g2q_user_1.conf │ └── 2g2q_user_2.conf ├── core.c ├── crc16_t10_lookup.h ├── dsa.c ├── dsa.h ├── dsa_config_test_runner.sh ├── dsa_crc32.h ├── dsa_memmove.sh ├── dsa_prep.c ├── dsa_test.c ├── dsa_user_test_runner.sh ├── iaa.c ├── iaa.h ├── iaa_prep.c ├── iaa_test.c ├── iaa_user_test_runner.sh └── libaccfg.c ├── test_all.sh └── util ├── abspath.c ├── bitmap.c ├── bitmap.h ├── filter.c ├── filter.h ├── help.c ├── json.c ├── json.h ├── list.h ├── log.c ├── log.h ├── main.c ├── main.h ├── parse-options.c ├── parse-options.h ├── size.c ├── size.h ├── strbuf.c ├── strbuf.h ├── sysfs.c ├── sysfs.h ├── usage.c ├── util.h └── wrapper.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.xml 3 | .deps/ 4 | .libs/ 5 | Makefile 6 | !contrib/Makefile 7 | Makefile.in 8 | /aclocal.m4 9 | /autom4te.cache 10 | /build-aux 11 | /config.* 12 | /configure 13 | /libtool 14 | /stamp-h1 15 | *.1 16 | Documentation/accfg/asciidoc.conf 17 | Documentation/accfg/asciidoctor-extensions.rb 18 | .dirstamp 19 | *.a 20 | accfg/lib/libaccfg.pc 21 | accfg/accfg 22 | accfg/accel-config 23 | rhel/ 24 | sles/accfg.spec 25 | test/dsa_test 26 | test/iaa_test 27 | test/libaccfg 28 | util/log.lo 29 | util/sysfs.lo 30 | version.m4 31 | *.swp 32 | cscope.files 33 | cscope*.out 34 | tags 35 | *.swk 36 | *.swl 37 | *.swm 38 | *.swn 39 | *.swo 40 | *.?~ 41 | m4 42 | log 43 | *.log 44 | *.trs 45 | *.la 46 | *.lo 47 | *.pc 48 | config.h 49 | -------------------------------------------------------------------------------- /Documentation/accfg/Makefile.am: -------------------------------------------------------------------------------- 1 | #SPDX-License-Identifier: GPL-2.0 2 | #Copyright(c) 2023-2026 Intel Corporation. All rights reserved 3 | 4 | if USE_ASCIIDOCTOR 5 | 6 | do_subst = sed -e 's,@Utility@,Dsactl,g' -e's,@utility@,accfg,g' 7 | CONFFILE = asciidoctor-extensions.rb 8 | asciidoctor-extensions.rb: ../asciidoctor-extensions.rb.in 9 | $(AM_V_GEN) $(do_subst) < $< > $@ 10 | 11 | else 12 | 13 | do_subst = sed -e 's,UTILITY,accfg,g' 14 | CONFFILE = asciidoc.conf 15 | asciidoc.conf: ../asciidoc.conf.in 16 | $(AM_V_GEN) $(do_subst) < $< > $@ 17 | 18 | endif 19 | 20 | man1_MANS = \ 21 | accel-config.1 \ 22 | accel-config-list.1 \ 23 | accel-config-load-config.1 \ 24 | accel-config-save-config.1 \ 25 | accel-config-config-device.1 \ 26 | accel-config-config-engine.1 \ 27 | accel-config-config-group.1 \ 28 | accel-config-config-wq.1 \ 29 | accel-config-disable-device.1 \ 30 | accel-config-disable-wq.1 \ 31 | accel-config-enable-wq.1 \ 32 | accel-config-enable-device.1 \ 33 | accel-config-config-user-default.1 \ 34 | accel-config-info.1 35 | 36 | EXTRA_DIST = \ 37 | $(man1_MANS) \ 38 | accel-config.txt \ 39 | accel-config-list.txt \ 40 | accel-config-load-config.txt \ 41 | accel-config-save-config.txt \ 42 | accel-config-config-device.txt \ 43 | accel-config-config-engine.txt \ 44 | accel-config-config-group.txt \ 45 | accel-config-config-wq.txt \ 46 | accel-config-disable-device.txt \ 47 | accel-config-disable-wq.txt \ 48 | accel-config-enable-wq.txt \ 49 | accel-config-enable-device.txt \ 50 | accel-config-config-user-default.txt \ 51 | accel-config-info.txt 52 | 53 | CLEANFILES = $(man1_MANS) 54 | 55 | XML_DEPS = \ 56 | ../../version.m4 \ 57 | Makefile \ 58 | $(CONFFILE) \ 59 | ../copyright.txt 60 | 61 | RM ?= rm -f 62 | 63 | if USE_ASCIIDOCTOR 64 | 65 | %.1: %.txt $(XML_DEPS) 66 | $(AM_V_GEN)$(RM) $@+ $@ && \ 67 | $(ASCIIDOC) -b manpage -d manpage -acompat-mode \ 68 | -I. -rasciidoctor-extensions \ 69 | -amansource=accfg -amanmanual="accfg Manual" \ 70 | -aaccfg_version=$(VERSION) -o $@+ $< && \ 71 | mv $@+ $@ 72 | 73 | else 74 | 75 | %.xml: %.txt $(XML_DEPS) 76 | $(AM_V_GEN)$(RM) $@+ $@ && \ 77 | $(ASCIIDOC) -b docbook -d manpage -f asciidoc.conf \ 78 | --unsafe -aaccfg_version=$(VERSION) -o $@+ $< && \ 79 | mv $@+ $@ 80 | 81 | %.1: %.xml $(XML_DEPS) 82 | $(AM_V_GEN)$(RM) $@ && \ 83 | $(XMLTO) -o . -m ../manpage-normal.xsl man $< 84 | 85 | endif 86 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-config-device.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config config-device(1) 4 | ============================= 5 | 6 | NAME 7 | ---- 8 | accel-config-config-device - configure the individual attributes of the device 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config config-device []' 14 | 15 | EXAMPLE 16 | ------- 17 | accel-config config-device dsa0 --read-buffer-limit=1 18 | 19 | OPTIONS 20 | ------- 21 | -l:: 22 | --read-buffer-limit=:: 23 | This specifies the maximum number of read buffers that may be 24 | in use at one time by operations that access low bandwidth memory. 25 | This number of read buffers is shared by all descriptors accessing 26 | low bandwidth memory across the entire device. read-buffer-limit should be 27 | more than 0. 28 | 29 | -e:: 30 | --event-log-size=:: 31 | Indicates the number of entries in the event log. The valid range is 32 | 64-65535. 33 | 34 | include::../copyright.txt[] 35 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-config-engine.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config config-engine(1) 4 | ============================= 5 | 6 | NAME 7 | ---- 8 | accel-config-config-engine - configure individual attributes of an engine 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config config-engine / []' 14 | 15 | EXAMPLE 16 | ------- 17 | accel-config config-engine dsa0/engine1.2 --group-id=0 18 | 19 | OPTIONS 20 | ------- 21 | -g:: 22 | --group-id=:: 23 | specify the group-id for this engine, group-id should be between 0 24 | and the maximum number of groups per device shown in max_groups 25 | attribute under a device. A value of -1 disassociates the engine 26 | from any group. 27 | 28 | include::../copyright.txt[] 29 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-config-group.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config config-group(1) 4 | ============================ 5 | 6 | NAME 7 | ---- 8 | accel-config-config-group - configure individual attributes of a group 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config config-group / []' 14 | 15 | EXAMPLE 16 | ------- 17 | accel-config config-group dsa0/group0.0 --read-buffers-reserved=1 18 | 19 | OPTIONS 20 | ------- 21 | -r:: 22 | --read-buffers-reserved=:: 23 | specify the number of read buffers reserved for the use of engines 24 | in the group. The limit of this value must be: 25 | - The sum of all read-buffers-reserved for all groups must be less than or 26 | equal to total read buffers from group capability field of the 27 | device. 28 | 29 | -t:: 30 | --read-buffers-allowed=:: 31 | specify the maximum number of read buffers that may be in use at 32 | one time by all engines in the group. This value can be used to 33 | limit the maximum bandwidth used by engines in the group. The limit 34 | of this value must be: 35 | - greater than 0 36 | - greater than or equal to the read-buffers-reserved value for this group. 37 | - less than or equal to the sum of read-buffers reserved-field and the 38 | non-reserved read buffers (total read buffers - total read buffers 39 | reserved for all groups). 40 | 41 | -l:: 42 | --use-read-buffer-limit=:: 43 | toggle the enabling of read-buffer limit usage. use-read-buffer-limit should be 44 | either 0 or 1. 45 | 46 | -a:: 47 | --traffic-class-a=:: 48 | specify traffic class A for this group, it should be larger 49 | than 0 and less than 8. 50 | 51 | -b:: 52 | --traffic-class-b=:: 53 | specify traffic class B for this group, it should be larger 54 | than 0 and less than 8. 55 | 56 | -d:: 57 | --desc-progress-limit=:: 58 | Controls the number of work descriptors that can be concurrently 59 | processed by an engine in the group. Range of valid values are 0, 1, 2 60 | and 3 for max, 1/2, 1/4 and 1/8 respectively that the engine is capable 61 | of. 62 | 63 | -p:: 64 | --batch-progress-limit=:: 65 | Controls the number of batch descriptors that can be concurrently 66 | processed by an engine in the group. Range of valid values are 0, 1, 2 67 | and 3 for max, 1/2, 1/4 and 1/8 respectively that the engine is capable 68 | of. 69 | 70 | include::../copyright.txt[] 71 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-config-user-default.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config config-user-default(1) 4 | =================================== 5 | 6 | NAME 7 | ---- 8 | accel-config-config-user-default - load a pre-defined user default configuration 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config config-user-default' [] 14 | 15 | Without an option, config-user-default loads a pre-defined user default 16 | configuration. 17 | 18 | There is a config file template at contrib/configs/user_default_profile.conf. 19 | Run "accel-config config-user-default -c user_default_profile.conf" to 20 | configure all available devices with the template values. Any modifications to 21 | the template file should retain the json format. 22 | 23 | EXAMPLE 24 | ------- 25 | # accel-config config-user-default 26 | 27 | The command will load the pre-defined user default config to all available 28 | WQs and engines on all available DSA and IAX devices with the following 29 | attributes: 30 | All WQs and all engines are in group 0 31 | 32 | WQ attributes: 33 | priority: 1 34 | group_id: 0 35 | block_on_fault: 1 36 | ats_disable: 0 37 | prs_disable: 1 38 | mode: "shared" 39 | type: "user" 40 | name: "user_default_wq" 41 | driver_name: "user" 42 | size: max WQ size / max WQs 43 | threshold: size 44 | max_transfer_size: default value 45 | max_batch_size: default value on DSA. N/A on IAX 46 | op_config: default value 47 | 48 | Attributes of all devices and groups are default values. 49 | 50 | # accel-config config-user-default -c /etc/accel-config/contrib/configs/user_default_profile.conf 51 | 52 | The command will load the specified user default config file. The config 53 | file is a template that specifies attributes and devices. User can edit 54 | the config file per requirements. 55 | 56 | # accel-config config-user-default -d -n 57 | The command will disable all WQs named (default name is 58 | "user_default_wq"). 59 | 60 | OPTIONS 61 | ------- 62 | -c:: 63 | --config-file:: 64 | to specify the location of the customized user default config file 65 | 66 | -n:: 67 | --name:: 68 | to specify WQ name which will be used to disable enabled WQs 69 | -d:: 70 | --disable:: 71 | to disable the configured devices and wqs 72 | 73 | -v:: 74 | --verbose:: 75 | verbose 76 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-config-wq.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config config-wq(1) 4 | ========================= 5 | 6 | NAME 7 | ---- 8 | accel-config-config-wq - configure individual attributes of a work queue 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config config-wq / []' 14 | 15 | EXAMPLE 16 | ------- 17 | accel-config config-wq dsa0/wq0.0 --wq-size=16 18 | 19 | OPTIONS 20 | -------- 21 | -g:: 22 | --group-id=:: 23 | specify the group id used by work queue, group id should be between 0 24 | and the maximum number of groups per device. A group id of -1 25 | disassociates the work queue from a group. 26 | 27 | -s:: 28 | --wq-size=:: 29 | specify work queue size used by a work queue. The wq-size should be 30 | between 0 and the maximum workqueue size exposed by the device in 31 | the max_work_queue_size attribute under device. 32 | 33 | -p:: 34 | --priority:: 35 | specify the priority of this work queue relative to other work queues 36 | in the same group. This field ranges from 1 to 15 where the larger 37 | value means higher priority. For example, if wq1 has a priority of 38 | 6 and wq2 has priority of 2, wq1 will issue 3 times as many 39 | descriptors to the engine compare to wq2. 40 | 41 | -b:: 42 | --block-on-fault:: 43 | toggle block on fault enable for the work queue. block-on-fault 44 | should be either 0 or 1. If block on fault is disabled, if a 45 | page fault occurs on a source or destination memory access, 46 | the operation stops and the page fault is reported to the software. 47 | 48 | -t:: 49 | --threshold:: 50 | configure the threshold for the wq. The set up threshold value should be 51 | larger than 0 and only for "shared" wq, and note that the configured 52 | threshold value should be at least 1 less than the configured wq-size 53 | value. The reason is threshold is set for unprivileged users, and need 54 | to reserve at least 1 space for the privileged user for commands. 55 | 56 | -y:: 57 | --type:: 58 | configure the type for the wq. The wq type can be "kernel" for kernel 59 | user case to request wq or "user" for regular character device driver 60 | use case to wq. 61 | 62 | -n:: 63 | --name:: 64 | configure the name for the wq. This can be any string defined by the user. 65 | Typically it is used for identifying the wq in some unique way. A possible 66 | suggestion would be using a uuid string. 67 | 68 | -d:: 69 | --driver-name:: 70 | specify the name of the driver to bind. This should be one of the valid 71 | wq drivers found in /sys/bus/dsa/drivers 72 | 73 | -o:: 74 | --op-config:: 75 | specify the op config bitmask. The bitmask is of size 256 bits and entered 76 | as 32 bit hex words separated by comma or space. 77 | e.g. 00000000,00000000,00000000,00000000,00000000,00000000,00fc00ff,003f03ff 78 | 79 | -m:: 80 | --mode:: 81 | configure the mode for the wq. The wq mode can be set as "dedicated" or 82 | "shared". 83 | 84 | -c:: 85 | --max-batch-size:: 86 | specify the max batch size used by a work queue. The value should be 87 | between 1 and the device maximum batch size found in the 88 | max_batch_size attribute under device. If the value is not a power 89 | of 2, it will be rounded up to the next power of 2. 90 | 91 | -x:: 92 | --max-transfer-size:: 93 | specify the max transfer size used by a work queue. The value should be 94 | between 1 and the device maximum transfer size found in the 95 | max_transfer_size attribute under device. If the value is not a power 96 | of 2, it will be rounded up to the next power of 2. 97 | 98 | -a:: 99 | --ats-disable:: 100 | toggle whether ATS disable is turned on for the work queue. The value 101 | should be either 0 or 1. 0 indicates ATS is on, and 1 indicates ATS is 102 | off for the work queue. 103 | 104 | -r:: 105 | --prs-disable:: 106 | toggle whether PRS disable is turned on for the work queue. The value 107 | should be either 0 or 1. 0 indicates PRS is on, and 1 indicates PRS is 108 | off for the work queue. 109 | 110 | include::../copyright.txt[] 111 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-disable-device.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config disable-device(1) 4 | ============================== 5 | 6 | NAME 7 | ---- 8 | accel-config-disable-device - disables an accfg device 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config disable-device' 14 | 'accel-config disable-device' 15 | dsa: disable all DSA devices 16 | iax: disable all IAX devices 17 | all: disable all devices 18 | 19 | EXAMPLE 20 | ------- 21 | accel-config disable-device dsa0 22 | accel-config disable-device all 23 | 24 | OPTIONS 25 | ------- 26 | -f:: 27 | --force:: 28 | Force the disable of device even when there are clients using the 29 | device. 30 | 31 | include::../copyright.txt[] 32 | 33 | SEE ALSO 34 | -------- 35 | accel-config enable-device(1) 36 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-disable-wq.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config disable-wq(1) 4 | ========================== 5 | 6 | NAME 7 | ---- 8 | accel-config-disable-wq - disables an accelerator device work queue 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config disable-wq' / 14 | 15 | EXAMPLE 16 | ------- 17 | accel-config disable-wq dsa0/wq0.0 18 | 19 | include::../copyright.txt[] 20 | 21 | OPTIONS 22 | ------- 23 | -f:: 24 | --force:: 25 | Force the disabling of the wq even if there are clients using the wq. 26 | 27 | SEE ALSO 28 | -------- 29 | accel-config enable-wq(1) 30 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-enable-device.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config enable-device(1) 4 | ============================= 5 | 6 | NAME 7 | ---- 8 | accel-config-enable-device - enable an accfg device 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config enable-device' 14 | 'accel-config enable-device' 15 | dsa: enable all configured DSA devices 16 | iax: enable all configured IAX devices 17 | all: enable all configured devices 18 | 19 | EXAMPLE 20 | ------- 21 | accel-config enable-device dsa0 22 | accel-config enable-device all 23 | 24 | include::../copyright.txt[] 25 | 26 | SEE ALSO 27 | -------- 28 | accel-config disable-device(1) 29 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-enable-wq.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config enable-wq(1) 4 | ========================= 5 | 6 | NAME 7 | ---- 8 | accel-config-enable-wq - enables an accelerator device work queue 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config enable-wq' / 14 | 15 | EXAMPLE 16 | ------- 17 | accel-config enable-wq dsa0/wq0.0 18 | 19 | include::../copyright.txt[] 20 | 21 | SEE ALSO 22 | -------- 23 | accel-config disable-wq(1) 24 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-info.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config info(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | accel-config-info - dump more idxd device information. 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config info [-v]' 14 | 15 | EXAMPLE 16 | ------- 17 | accel-config info -v 18 | 19 | dsa0 [active] 20 | 21 | 00000000,00000000,00000000,00000000,00000000,00000000,0000007b,00bf07fd 22 | 23 | Batch[-] Drain[+] Memory Move[+] Fill[+] Compare[+] Compare Pattern[+] Create Delta Record[+] Apply Delta Record[+] Memory Copy with Dualcast[+] Translation Fetch[+] CRC Generation[+] Copy with CRC Generation[+] DIF Check[+] DIF Insert[+] DIF Strip[+] DIF Update[+] DIX Generate[+] Cache Flush[+] Update Window[+] Inter-Domain Memory Copy[+] Inter-Domain Fill[+] Inter-Domain Compare[+] Inter-Domain Compare Pattern[+] Inter-Domain Cache Flush[-] 24 | 25 | iax1 26 | 27 | 00000000,00000000,00000000,00000000,00000000,004d001c,00000000,00000405 28 | 29 | Drain[+] Translation Fetch[+] Decrypt[-] Encrypt[-] Decompress[+] Compress[+] CRC64[+] Zdecompress32[-] Zdecompress16[-] Zdecompress8 [-] Zcompress32[-] Zcompress16[-] Zcompress8[-] Scan[+] Set Membership[-] Extract[+] Select[+] BLE Burst[-] Find Unique[-] Expand[+] 30 | 31 | OPTIONS 32 | ------- 33 | -v: 34 | Verbose mode. Print more information about the device. 35 | 36 | include::../copyright.txt[] 37 | 38 | SEE ALSO 39 | -------- 40 | accel-config info(1) 41 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-list.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config list(1) 4 | ==================== 5 | 6 | NAME 7 | ---- 8 | accel-config-list - display the platform accfg device(s) topology and attributes in 9 | json format 10 | 11 | SYNOPSIS 12 | -------- 13 | [verse] 14 | 'accel-config list' [] 15 | 16 | List all the active DSA devices discovered by the driver and the driver exported 17 | attributes. 18 | 19 | Options can be specified to limit the output to devices of a certain 20 | grouping where the grouping are devices, groups, work queues and engines. By 21 | default, 'accel-config list' with no options is equivalent to: 22 | [verse] 23 | accel-config list --devices --engines --groups --workqueues 24 | 25 | EXAMPLE 26 | ------- 27 | ---- 28 | # accel-config list 29 | [ 30 | { 31 | "dev":"dsa0", 32 | "read_buffer_limit":0, 33 | "max_groups":4, 34 | "max_work_queues":8, 35 | "max_engines":4, 36 | "work_queue_size":64, 37 | "numa_node":-1, 38 | "op_cap":"00000000,00000000,00000000,00000000,00000000,00000000,00fc00ff,003f03ff", 39 | "gen_cap":"0x1833f215f", 40 | "version":"0x100", 41 | "state":"enabled", 42 | "max_read_buffers":64, 43 | "max_batch_size":512, 44 | "max_transfer_size":2147483648, 45 | "configurable":1, 46 | "pasid_enabled":1, 47 | "cdev_major":511, 48 | "clients":0, 49 | "groups":[ 50 | { 51 | "dev":"group0.0", 52 | "read_buffers_reserved":0, 53 | "use_read_buffer_limit":0, 54 | "read_buffers_allowed":8, 55 | "traffic_class_a":0, 56 | "traffic_class_b":1, 57 | "grouped_workqueues":[ 58 | { 59 | "dev":"wq0.0", 60 | "mode":"dedicated", 61 | "size":16, 62 | "group_id":0, 63 | "priority":10, 64 | "block_on_fault":1, 65 | "max_batch_size":32, 66 | "max_transfer_size":2097152, 67 | "cdev_minor":1, 68 | "type":"user", 69 | "name":"app1", 70 | "threshold":0, 71 | "ats_disable":0, 72 | "op_config":"00000000,00000000,00000000,00000000,00000000,00000000,00fc00ff,003f03ff", 73 | "state":"enabled", 74 | "clients":0 75 | } 76 | ], 77 | "grouped_engines":[ 78 | { 79 | "dev":"engine0.0", 80 | "group_id":0 81 | }, 82 | { 83 | "dev":"engine0.1", 84 | "group_id":0 85 | } 86 | ] 87 | }, 88 | { 89 | "dev":"group0.1", 90 | "read_buffers_reserved":0, 91 | "use_read_buffer_limit":0, 92 | "read_buffers_allowed":8, 93 | "traffic_class_a":0, 94 | "traffic_class_b":1, 95 | "grouped_workqueues":[ 96 | { 97 | "dev":"wq0.1", 98 | "mode":"dedicated", 99 | "size":16, 100 | "group_id":1, 101 | "priority":10, 102 | "block_on_fault":1, 103 | "max_batch_size":16, 104 | "max_transfer_size":65536, 105 | "cdev_minor":0, 106 | "type":"user", 107 | "name":"app2", 108 | "threshold":0, 109 | "ats_disable":0, 110 | "op_config":"00000000,00000000,00000000,00000000,00000000,00000000,00fc00ff,003f03ff", 111 | "state":"enabled", 112 | "clients":0 113 | } 114 | ], 115 | "grouped_engines":[ 116 | { 117 | "dev":"engine0.2", 118 | "group_id":1 119 | }, 120 | { 121 | "dev":"engine0.3", 122 | "group_id":1 123 | } 124 | ] 125 | }, 126 | { 127 | "dev":"group0.2", 128 | "read_buffers_reserved":0, 129 | "use_read_buffer_limit":0, 130 | "read_buffers_allowed":8, 131 | "traffic_class_a":0, 132 | "traffic_class_b":1 133 | }, 134 | { 135 | "dev":"group0.3", 136 | "read_buffers_reserved":0, 137 | "use_read_buffer_limit":0, 138 | "read_buffers_allowed":8, 139 | "traffic_class_a":0, 140 | "traffic_class_b":1 141 | } 142 | ] 143 | } 144 | ] 145 | ---- 146 | 147 | OPTIONS 148 | ------- 149 | -d:: 150 | --device=:: 151 | A accfg device name like dsa{number}. Filter 152 | listing by devices that reference the given device. 153 | 154 | -g:: 155 | --group=:: 156 | An 'groupX.Y' group name, or device id plus group id tuple 157 | 'X.Y'. Limit the group list to the single identified device 158 | if present. 159 | 160 | -q:: 161 | --workqueue=:: 162 | An 'wqX.Y' workqueue name, or device id plus workqueue id tuple 163 | 'X.Y'. Limit the workqueue list to the single identified device 164 | if present. 165 | 166 | -e:: 167 | --engine=:: 168 | An 'engineX.Y' engine name, or device id plus engine id tuple 169 | 'X.Y'. Limit the engine list to the single identified device 170 | if present. 171 | 172 | -D:: 173 | --devices:: 174 | Include device info in the listing 175 | 176 | -G:: 177 | --regions:: 178 | Include group info in the listing 179 | 180 | -Q:: 181 | --workqueues:: 182 | Include active workqueue info in the listing 183 | 184 | -E:: 185 | --engines:: 186 | Include active engine info in the listing 187 | 188 | -i:: 189 | --idle:: 190 | Include both idle (not enabled) and active devices in the listing 191 | 192 | include::../copyright.txt[] 193 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-load-config.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config load-config(1) 4 | =========================== 5 | 6 | NAME 7 | ---- 8 | accel-config-load-config - load pre-defined the configuration in json format 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config load-config' [] 14 | 15 | Load and scan through the pre-defined configuration file in json format, 16 | and set the configured attribute into corresponding component. 17 | 18 | There is a sample config file at /etc/accel-config/accel-config.conf.sample, and 19 | it can be used as a reference for user about how the loadable config file looks 20 | like, but it should not be used directly given the variance of each system. The 21 | user should create a proper config file according to the format of sample file 22 | and use "-c" option to point to the config file. 23 | 24 | The "dev" property is used as the key for each json object and must be the 25 | first entry in each object block. 26 | 27 | Note: This feature is intended to be used with a configuration that was 28 | previously saved using the save-config command. Manual editing of the 29 | configuration file can produce unexpected results. 30 | 31 | EXAMPLE 32 | ------- 33 | ---- 34 | # accel-config load-config 35 | The command will load the default config file at 36 | /etc/accel-config/accel-config.conf 37 | 38 | # accel-config load-config -c 39 | The command will load the specified config file 40 | ---- 41 | 42 | OPTIONS 43 | ------- 44 | -l:: 45 | --log=:: 46 | to set where to output the config's notification 47 | 48 | 49 | -c:: 50 | --config-file:: 51 | to specify the location of the customized config file 52 | 53 | -e:: 54 | --enable:: 55 | to enable the configured devices and wqs 56 | 57 | -f:: 58 | --forced:: 59 | to disable enabled devices before configuring 60 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config-save-config.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config save-config(1) 4 | =========================== 5 | 6 | NAME 7 | ---- 8 | accel-config-save-config - save the configuration in json format into a file. 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config save-config' [] 14 | 15 | Save the current configuration displayed in json format into a specified path 16 | with specified file name. 17 | 18 | EXAMPLE 19 | ------- 20 | ---- 21 | # accel-config save-config -s /usr/accfg/save_config.conf 22 | ---- 23 | 24 | OPTIONS 25 | ------- 26 | -s:: 27 | --saved-file=:: 28 | to specify saved file name and path 29 | -------------------------------------------------------------------------------- /Documentation/accfg/accel-config.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | accel-config(1) 4 | =============== 5 | 6 | NAME 7 | ---- 8 | accel-config - configure and control DSA(data streaminng accelerator) subsystem devices 9 | 10 | SYNOPSIS 11 | -------- 12 | [verse] 13 | 'accel-config' [--list-cmds] [--version] [--help] [OPTIONS] COMMAND [ARGS] 14 | 15 | OPTIONS 16 | ------- 17 | -v:: 18 | --version:: 19 | Display accel-config version. 20 | 21 | -h:: 22 | --help:: 23 | Displays help information on commands. 24 | 25 | --list-cmds:: 26 | List available accel-config commands. 27 | 28 | DESCRIPTION 29 | ----------- 30 | accel-config provides ability to display the accelerator's state presented by 31 | the Linux driver via sysfs, configure the device via sysfs, and saving and 32 | loading the configuration. 33 | 34 | include::../copyright.txt[] 35 | 36 | SEE ALSO 37 | -------- 38 | accel-config enable-wq(1), 39 | accel-config disable-wq(1), 40 | accel-config enable-device(1), 41 | accel-config disable-device(1), 42 | accel-config load-config(1), 43 | accel-config save-config(1), 44 | accel-config list(1), 45 | accel-config config-device(1), 46 | accel-config config-group(1), 47 | accel-config config-wq(1), 48 | accel-config config-engine(1), 49 | accel-config config-user-default(1), 50 | -------------------------------------------------------------------------------- /Documentation/accfg/attrs.adoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/idxd-config/c590717c85a34c2b85f9463bb38a67cdf2493501/Documentation/accfg/attrs.adoc -------------------------------------------------------------------------------- /Documentation/asciidoc.conf.in: -------------------------------------------------------------------------------- 1 | ## linkUTILITY: macro 2 | # 3 | # Copyright (c) 2005, Sergey Vlasov 4 | # Copyright (c) 2005, Jonas Fonseca 5 | # 6 | # Originally copied from GIT source (commit d1c2e113c5b6 "[PATCH] 7 | # Documentation: Add asciidoc.conf file and gitlink: macro") 8 | # 9 | # Usage: linkUTILITY:command[manpage-section] 10 | # 11 | # Note, {0} is the manpage section, while {target} is the command. 12 | # 13 | # Show PERF link as: (
); if section is defined, else just show 14 | # the command. 15 | 16 | [macros] 17 | (?su)[\\]?(?PlinkUTILITY):(?P\S*?)\[(?P.*?)\]= 18 | 19 | [attributes] 20 | asterisk=* 21 | plus=+ 22 | caret=^ 23 | startsb=[ 24 | endsb=] 25 | tilde=~ 26 | 27 | ifdef::backend-docbook[] 28 | [linkUTILITY-inlinemacro] 29 | {0%{target}} 30 | {0#} 31 | {0#{target}{0}} 32 | {0#} 33 | endif::backend-docbook[] 34 | 35 | ifdef::backend-docbook[] 36 | ifndef::UTILITY-asciidoc-no-roff[] 37 | # "unbreak" docbook-xsl v1.68 for manpages. v1.69 works with or without this. 38 | # v1.72 breaks with this because it replaces dots not in roff requests. 39 | [listingblock] 40 | {title} 41 | 42 | ifdef::doctype-manpage[] 43 | .ft C 44 | endif::doctype-manpage[] 45 | | 46 | ifdef::doctype-manpage[] 47 | .ft 48 | endif::doctype-manpage[] 49 | 50 | {title#} 51 | endif::UTILITY-asciidoc-no-roff[] 52 | 53 | ifdef::UTILITY-asciidoc-no-roff[] 54 | ifdef::doctype-manpage[] 55 | # The following two small workarounds insert a simple paragraph after screen 56 | [listingblock] 57 | {title} 58 | 59 | | 60 | 61 | {title#} 62 | 63 | [verseblock] 64 | {title} 65 | {title%} 66 | {title#} 67 | | 68 | 69 | {title#} 70 | {title%} 71 | endif::doctype-manpage[] 72 | endif::UTILITY-asciidoc-no-roff[] 73 | endif::backend-docbook[] 74 | 75 | ifdef::doctype-manpage[] 76 | ifdef::backend-docbook[] 77 | [header] 78 | template::[header-declarations] 79 | 80 | 81 | {mantitle} 82 | {manvolnum} 83 | UTILITY 84 | {UTILITY_version} 85 | UTILITY Manual 86 | 87 | 88 | {manname} 89 | {manpurpose} 90 | 91 | endif::backend-docbook[] 92 | endif::doctype-manpage[] 93 | 94 | ifdef::backend-xhtml11[] 95 | [linkUTILITY-inlinemacro] 96 | {target}{0?({0})} 97 | endif::backend-xhtml11[] 98 | -------------------------------------------------------------------------------- /Documentation/asciidoctor-extensions.rb.in: -------------------------------------------------------------------------------- 1 | require 'asciidoctor' 2 | require 'asciidoctor/extensions' 3 | 4 | module @Utility@ 5 | module Documentation 6 | class Link@Utility@Processor < Asciidoctor::Extensions::InlineMacroProcessor 7 | use_dsl 8 | 9 | named :chrome 10 | 11 | def process(parent, target, attrs) 12 | if parent.document.basebackend? 'html' 13 | prefix = parent.document.attr('@utility@-relative-html-prefix') 14 | %(#{target}(#{attrs[1]})\n) 15 | elsif parent.document.basebackend? 'manpage' 16 | "#{target}(#{attrs[1]})" 17 | elsif parent.document.basebackend? 'docbook' 18 | "\n" \ 19 | "#{target}" \ 20 | "#{attrs[1]}\n" \ 21 | "\n" 22 | end 23 | end 24 | end 25 | end 26 | end 27 | 28 | Asciidoctor::Extensions.register do 29 | inline_macro @Utility@::Documentation::Link@Utility@Processor, :link@utility@ 30 | end 31 | -------------------------------------------------------------------------------- /Documentation/copyright.txt: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | 3 | COPYRIGHT 4 | --------- 5 | Copyright (c) 2023 - 2026, Intel Corporation. License GPLv2: GNU GPL 6 | version 2 . This is free software: 7 | you are free to change and redistribute it. There is NO WARRANTY, to 8 | the extent permitted by law. 9 | -------------------------------------------------------------------------------- /Documentation/manpage-base.xsl: -------------------------------------------------------------------------------- 1 | 9 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 21 | 22 | 26 | 27 | 28 | 29 | sp 30 | 31 | 32 | 33 | 34 | 38 | 39 | 40 | br 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Documentation/manpage-normal.xsl: -------------------------------------------------------------------------------- 1 | 9 | 12 | 14 | 15 | 16 | 17 | 18 | \ 19 | . 20 | 21 | 22 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | include Makefile.am.in 2 | 3 | ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} 4 | SUBDIRS = . accfg/lib accfg 5 | if ENABLE_DOCS 6 | SUBDIRS += Documentation/accfg 7 | endif 8 | if ENABLE_TEST 9 | SUBDIRS += test 10 | endif 11 | 12 | BUILT_SOURCES = version.m4 13 | version.m4: FORCE 14 | $(AM_V_GEN)$(top_srcdir)/git-version-gen 15 | 16 | FORCE: 17 | 18 | noinst_SCRIPTS = rhel/accfg.spec rhel/accfg-test.spec 19 | CLEANFILES += $(noinst_SCRIPTS) 20 | 21 | do_rhel_subst = sed -e 's,VERSION,$(VERSION),g' \ 22 | -e 's,DNAME,accel-config-devel,g' \ 23 | -e '/^%defattr.*/d' \ 24 | -e 's,LNAME,accel-config-libs,g' 25 | 26 | rhel/accfg.spec: accfg.spec.in Makefile.am version.m4 27 | $(AM_V_GEN)$(MKDIR_P) rhel; $(do_rhel_subst) < $< > $@ 28 | 29 | rhel/accfg-test.spec: accfg-test.spec.in Makefile.am version.m4 30 | $(AM_V_GEN)$(MKDIR_P) rhel; $(do_rhel_subst) < $< > $@ 31 | 32 | if ENABLE_BASH_COMPLETION 33 | bashcompletiondir = $(BASH_COMPLETION_DIR) 34 | endif 35 | 36 | contrib_configs = contrib/configs/* 37 | contribdir = $(sysconfdir)/accel-config/contrib/configs 38 | contrib_DATA = $(contrib_configs) 39 | 40 | EXTRA_DIST += $(contrib_configs) accfg.spec.in accfg-test.spec.in 41 | 42 | noinst_LIBRARIES = libccan.a 43 | libccan_a_SOURCES = \ 44 | ccan/str/str.h \ 45 | ccan/str/str_debug.h \ 46 | ccan/str/str.c \ 47 | ccan/str/debug.c \ 48 | ccan/list/list.h \ 49 | ccan/list/list.c \ 50 | ccan/container_of/container_of.h \ 51 | ccan/check_type/check_type.h \ 52 | ccan/build_assert/build_assert.h \ 53 | ccan/array_size/array_size.h \ 54 | ccan/minmax/minmax.h \ 55 | ccan/short_types/short_types.h \ 56 | ccan/endian/endian.h 57 | 58 | 59 | noinst_LIBRARIES += libutil.a 60 | libutil_a_SOURCES = \ 61 | util/abspath.c \ 62 | util/bitmap.c \ 63 | util/bitmap.h \ 64 | util/filter.c \ 65 | util/filter.h \ 66 | util/help.c \ 67 | util/json.h \ 68 | util/list.h \ 69 | util/log.h \ 70 | util/main.c \ 71 | util/main.h \ 72 | util/parse-options.c \ 73 | util/parse-options.h \ 74 | util/size.c \ 75 | util/size.h \ 76 | util/strbuf.c \ 77 | util/strbuf.h \ 78 | util/sysfs.h \ 79 | util/usage.c \ 80 | util/util.h \ 81 | util/wrapper.c \ 82 | builtin.h \ 83 | test.h 84 | -------------------------------------------------------------------------------- /Makefile.am.in: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = 2 | CLEANFILES = 3 | 4 | AM_MAKEFLAGS = --no-print-directory 5 | 6 | AM_CPPFLAGS = \ 7 | -include $(top_builddir)/config.h \ 8 | -DSYSCONFDIR=\""$(sysconfdir)"\" \ 9 | -DLIBEXECDIR=\""$(libexecdir)"\" \ 10 | -DPREFIX=\""$(prefix)"\" \ 11 | -DACCFG_MAN_PATH=\""$(mandir)"\" \ 12 | -I${top_srcdir}/accfg/lib \ 13 | -I${top_srcdir}/accfg \ 14 | -I${top_srcdir}/ \ 15 | $(UUID_CFLAGS) \ 16 | $(JSON_CFLAGS) 17 | 18 | AM_CFLAGS = ${my_CFLAGS} \ 19 | -fvisibility=hidden \ 20 | -ffunction-sections \ 21 | -fdata-sections 22 | 23 | AM_LDFLAGS = \ 24 | -Wl,--gc-sections \ 25 | -Wl,--as-needed 26 | 27 | SED_PROCESS = \ 28 | $(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \ 29 | -e 's,@VERSION\@,$(VERSION),g' \ 30 | -e 's,@prefix\@,$(prefix),g' \ 31 | -e 's,@exec_prefix\@,$(exec_prefix),g' \ 32 | -e 's,@libdir\@,$(libdir),g' \ 33 | -e 's,@includedir\@,$(includedir),g' \ 34 | < $< > $@ || rm $@ 35 | 36 | LIBACCFG_CURRENT=1 37 | LIBACCFG_REVISION=0 38 | LIBACCFG_AGE=0 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # accel-config 2 | 3 | Utility library for controlling and configuring DSA (Intel® Data Streaming 4 | Accelerator Architecture) and IAA (Intel® Analytics Accelerator Architecture) 5 | sub-systems in the Linux kernel 6 | 7 | ## Resolve dependencies 8 | 9 | ### Fedora, RHEL, CentOS 10 | ```bash 11 | yum groupinstall "Development Tools" 12 | yum install autoconf automake libtool pkgconf rpm-build rpmdevtools 13 | yum install asciidoc xmlto libuuid-devel json-c-devel zlib-devel openssl-devel 14 | ``` 15 | ### Debian 16 | ```bash 17 | apt install build-essential 18 | apt install autoconf automake autotools-dev libtool pkgconf asciidoc xmlto 19 | apt install uuid-dev libjson-c-dev libkeyutils-dev libz-dev libssl-dev 20 | apt install debhelper devscripts debmake quilt fakeroot lintian asciidoctor 21 | apt install file gnupg patch patchutils 22 | ``` 23 | 24 | ## Build 25 | 26 | ```bash 27 | ./autogen.sh 28 | ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 29 | make 30 | make check 31 | sudo make install 32 | ``` 33 | 34 | Build with test 35 | 36 | ```bash 37 | ./autogen.sh 38 | ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc \ 39 | --libdir=/usr/lib64 --enable-test=yes 40 | make 41 | make check 42 | sudo make install 43 | ``` 44 | 45 | ## Build RPM 46 | 47 | ```bash 48 | mkdir -p ${HOME}/rpmbuild/SOURCES 49 | ./autogen.sh 50 | ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 51 | make rhel/accfg.spec 52 | ./rpmbuild.sh 53 | ``` 54 | 55 | Build as RPM package with test 56 | 57 | ```bash 58 | mkdir -p ${HOME}/rpmbuild/SOURCES 59 | ./autogen.sh 60 | ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc \ 61 | --libdir=/usr/lib64 --enable-test=yes 62 | make rhel/accfg-test.spec 63 | ./rpmbuild-test.sh 64 | ``` 65 | 66 | There are a number of packages required for the build steps that may not 67 | be installed by default. For information about the required packages, 68 | see the "BuildRequires:" lines in accfg.spec.in and accfg-test.spec.in. 69 | 70 | ## Build Debian Package 71 | ```bash 72 | export DEBEMAIL="your.email@example.org" 73 | export DEBFULLNAME="Firstname Lastname" 74 | ./autogen.sh 75 | ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc \ 76 | --libdir=/usr/lib64 --enable-test=yes 77 | 78 | ./debdch.sh 79 | (Run dch -r and edit debian/changelog as necessary) 80 | 81 | ./debbuild.sh 82 | 83 | Debian package components would be created in ./debpkg 84 | 85 | debian/changelog changes should be committed 86 | ``` 87 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 3 | 4 | ## Reporting a Vulnerability 5 | Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 6 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Do something 2 | - Do something else 3 | -------------------------------------------------------------------------------- /accfg-test.spec.in: -------------------------------------------------------------------------------- 1 | Name: accel-config 2 | Version: VERSION 3 | Release: 2%{?dist} 4 | Summary: Configure accelerator subsystem devices 5 | License: GPL-2.0 6 | Group: System Environment/Base 7 | Source0: %{name}-%{version}.tar.gz 8 | 9 | Requires: LNAME%{?_isa} = %{version}-%{release} 10 | BuildRequires: autoconf 11 | BuildRequires: asciidoc 12 | BuildRequires: xmlto 13 | BuildRequires: automake 14 | BuildRequires: libtool 15 | BuildRequires: pkgconfig 16 | BuildRequires: pkgconfig(uuid) 17 | BuildRequires: pkgconfig(json-c) 18 | BuildRequires: systemd 19 | 20 | %description 21 | Utility library for configuring the accelerator subsystem. 22 | 23 | %package -n DNAME 24 | Summary: Development files for libaccfg 25 | License: LGPL-2.1-only 26 | Group: Development/Libraries 27 | Requires: LNAME%{?_isa} = %{version}-%{release} 28 | 29 | %description -n DNAME 30 | The %{name}-devel package contains libraries and header files for 31 | developing applications that use %{name}. 32 | 33 | 34 | %package -n LNAME 35 | Summary: Configuration library for accelerator subsystem devices 36 | License: LGPL-2.1-only 37 | Group: System Environment/Libraries 38 | 39 | %description -n LNAME 40 | Libraries for %{name}. 41 | 42 | %package -n %{name}-test 43 | Summary: Unit tests for %{name}. 44 | License: GPL-2.0 45 | Group: Unspecified 46 | 47 | %description -n %{name}-test 48 | Unit tests for %{name} 49 | 50 | %prep 51 | %setup -q accel-config-%{version} 52 | 53 | %build 54 | echo %{version} > version 55 | ./autogen.sh 56 | %configure --disable-static --disable-silent-rules --enable-test 57 | make %{?_smp_mflags} 58 | 59 | %install 60 | %make_install 61 | find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';' 62 | 63 | %post -n LNAME -p /sbin/ldconfig 64 | 65 | %postun -n LNAME -p /sbin/ldconfig 66 | 67 | %files 68 | %defattr(-,root,root) 69 | %license Documentation/COPYING licenses/BSD-MIT licenses/CC0 70 | %license licenses/accel-config-licenses LICENSE_GPL_2_0 71 | %{_bindir}/accel-config 72 | %{_mandir}/man1/accel-config* 73 | %{_sysconfdir}/accel-config/contrib/configs/* 74 | 75 | %files -n LNAME 76 | %defattr(-,root,root) 77 | %doc README.md 78 | %license Documentation/COPYING licenses/BSD-MIT licenses/CC0 79 | %license licenses/libaccel-config-licenses accfg/lib/LICENSE_LGPL_2_1 80 | %{_libdir}/libaccel-config.so.* 81 | 82 | %files -n DNAME 83 | %defattr(-,root,root) 84 | %license Documentation/COPYING 85 | %{_includedir}/accel-config/ 86 | %{_libdir}/libaccel-config.so 87 | %{_libdir}/pkgconfig/libaccel-config.pc 88 | 89 | %files -n %{name}-test 90 | %defattr(-,root,root) 91 | %license Documentation/COPYING LICENSE_GPL_2_0 92 | %{_prefix}/libexec/accel-config/test/* 93 | 94 | %changelog 95 | -------------------------------------------------------------------------------- /accfg.spec.in: -------------------------------------------------------------------------------- 1 | Name: accel-config 2 | Version: VERSION 3 | Release: 2%{?dist} 4 | Summary: Configure accelerator subsystem devices 5 | License: GPL-2.0 6 | Group: System Environment/Base 7 | Source0: %{name}-%{version}.tar.gz 8 | 9 | Requires: LNAME%{?_isa} = %{version}-%{release} 10 | BuildRequires: autoconf 11 | BuildRequires: asciidoc 12 | BuildRequires: xmlto 13 | BuildRequires: automake 14 | BuildRequires: libtool 15 | BuildRequires: pkgconfig 16 | BuildRequires: pkgconfig(uuid) 17 | BuildRequires: pkgconfig(json-c) 18 | BuildRequires: systemd 19 | 20 | %description 21 | Utility library for configuring the accelerator subsystem. 22 | 23 | %package -n DNAME 24 | Summary: Development files for libaccfg 25 | License: LGPL-2.1-only 26 | Group: Development/Libraries 27 | Requires: LNAME%{?_isa} = %{version}-%{release} 28 | 29 | %description -n DNAME 30 | The %{name}-devel package contains libraries and header files for 31 | developing applications that use %{name}. 32 | 33 | 34 | %package -n LNAME 35 | Summary: Configuration library for accelerator subsystem devices 36 | License: LGPL-2.1-only 37 | Group: System Environment/Libraries 38 | 39 | %description -n LNAME 40 | Libraries for %{name}. 41 | 42 | %prep 43 | %setup -q accel-config-%{version} 44 | 45 | %build 46 | echo %{version} > version 47 | ./autogen.sh 48 | %configure --disable-static --disable-silent-rules 49 | make %{?_smp_mflags} 50 | 51 | %install 52 | %make_install 53 | find $RPM_BUILD_ROOT -name '*.la' -exec rm -f {} ';' 54 | 55 | %post -n LNAME -p /sbin/ldconfig 56 | 57 | %postun -n LNAME -p /sbin/ldconfig 58 | 59 | %files 60 | %defattr(-,root,root) 61 | %license Documentation/COPYING licenses/BSD-MIT licenses/CC0 62 | %license licenses/accel-config-licenses LICENSE_GPL_2_0 63 | %{_bindir}/accel-config 64 | %{_mandir}/man1/accel-config* 65 | %{_sysconfdir}/accel-config/contrib/configs/* 66 | 67 | %files -n LNAME 68 | %defattr(-,root,root) 69 | %doc README.md 70 | %license Documentation/COPYING licenses/BSD-MIT licenses/CC0 71 | %license licenses/libaccel-config-licenses accfg/lib/LICENSE_LGPL_2_1 72 | %{_libdir}/libaccel-config.so.* 73 | 74 | %files -n DNAME 75 | %defattr(-,root,root) 76 | %license Documentation/COPYING 77 | %{_includedir}/accel-config/ 78 | %{_libdir}/libaccel-config.so 79 | %{_libdir}/pkgconfig/libaccel-config.pc 80 | 81 | %changelog 82 | -------------------------------------------------------------------------------- /accfg/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Makefile.am.in 2 | 3 | bin_PROGRAMS = accel-config 4 | 5 | DISTCLEANFILES = config.h 6 | BUILT_SOURCES = config.h 7 | config.h: $(srcdir)/Makefile.am 8 | $(AM_V_GEN) echo "/* Autogenerated by accfg/Makefile.am */" >$@ && \ 9 | echo '#define ACCFG_CONF_FILE "$(accfg_confdir)/$(accfg_conf)"' >>$@ && \ 10 | echo '#define ACCFG_CONF_DIR "$(accfg_confdir)"' >>$@ 11 | 12 | accel_config_SOURCES = accel-config.c \ 13 | ../util/log.c \ 14 | list.c \ 15 | ../util/json.c \ 16 | ../util/json.h \ 17 | enable.c \ 18 | config_attr.c \ 19 | config.c 20 | 21 | accel_config_LDADD =\ 22 | lib/libaccel-config.la \ 23 | ../libutil.a \ 24 | $(JSON_LIBS) \ 25 | $(UUID_LIBS) 26 | 27 | if ENABLE_TEST 28 | accel_config_SOURCES += ../test/libaccfg.c \ 29 | ../test/core.c \ 30 | test.c 31 | endif 32 | 33 | accfg_configdir = $(accfg_confdir) 34 | -------------------------------------------------------------------------------- /accfg/accel-config.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | const char accfg_usage_string[] = 19 | "accel-config [--list-cmds] [-h | --help] [-v | --version] COMMAND [ARGS]\n\n" 20 | " 'accel-config --help COMMAND' for information on a specific command\n" 21 | " 'accel-config --list-cmds' for a list of available commands\n" 22 | " 'accel-config --version' for version info"; 23 | 24 | static struct cmd_struct commands[] = { 25 | {"list", cmd_list}, 26 | {"info", cmd_info}, 27 | {"load-config", cmd_config}, 28 | {"save-config", cmd_save}, 29 | {"disable-device", cmd_disable_device}, 30 | {"enable-device", cmd_enable_device}, 31 | {"disable-wq", cmd_disable_wq}, 32 | {"enable-wq", cmd_enable_wq}, 33 | {"config-device", cmd_config_device}, 34 | {"config-group", cmd_config_group}, 35 | {"config-wq", cmd_config_wq}, 36 | {"config-engine", cmd_config_engine}, 37 | {"config-user-default", cmd_config_default}, 38 | #ifdef ENABLE_TEST 39 | {"test", cmd_test}, 40 | #endif 41 | }; 42 | 43 | int main(int argc, const char **argv) 44 | { 45 | struct accfg_ctx *ctx; 46 | unsigned int last_error; 47 | int rc; 48 | 49 | /* Look for flags.. */ 50 | main_handle_options(argv, argc, accfg_usage_string, commands, 51 | ARRAY_SIZE(commands)); 52 | 53 | if (access("/sys/module/idxd", F_OK)) { 54 | fprintf(stderr, "idxd kernel module not loaded\n"); 55 | return EXIT_FAILURE; 56 | } 57 | 58 | rc = accfg_new(&ctx); 59 | if (rc) 60 | goto error_exit; 61 | 62 | argv++; 63 | argc--; 64 | rc = main_handle_internal_command(argc, argv, ctx, commands, 65 | ARRAY_SIZE(commands)); 66 | 67 | last_error = accfg_ctx_get_last_error(ctx); 68 | if (rc && last_error) { 69 | struct accfg_device *d; 70 | struct accfg_group *g; 71 | struct accfg_wq *w; 72 | struct accfg_engine *e; 73 | 74 | printf("Error[%#10x] ", last_error); 75 | d = accfg_ctx_get_last_error_device(ctx); 76 | g = accfg_ctx_get_last_error_group(ctx); 77 | w = accfg_ctx_get_last_error_wq(ctx); 78 | e = accfg_ctx_get_last_error_engine(ctx); 79 | if (d) 80 | printf("%s", accfg_device_get_devname(d)); 81 | if (g) 82 | printf("/%s", accfg_group_get_devname(g)); 83 | if (w) 84 | printf("/%s", accfg_wq_get_devname(w)); 85 | if (e) 86 | printf("/%s", accfg_engine_get_devname(e)); 87 | printf(": %s\n", accfg_ctx_get_last_error_str(ctx)); 88 | } 89 | accfg_unref(ctx); 90 | 91 | if (!rc) 92 | return EXIT_SUCCESS; 93 | error_exit: 94 | errno = abs(rc); 95 | 96 | return EXIT_FAILURE; 97 | } 98 | -------------------------------------------------------------------------------- /accfg/accfg.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef __ACCFG_H__ 5 | #define __ACCFG_H__ 6 | 7 | #ifndef ARRAY_SIZE 8 | #include 9 | #endif 10 | #include 11 | #include 12 | #include 13 | 14 | #endif /* __ACCFG_H__ */ 15 | -------------------------------------------------------------------------------- /accfg/lib/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Makefile.am.in 2 | 3 | %.pc: %.pc.in Makefile 4 | $(SED_PROCESS) 5 | 6 | pkginclude_HEADERS = ../libaccel_config.h 7 | lib_LTLIBRARIES = libaccel-config.la 8 | 9 | libaccel_config_la_SOURCES =\ 10 | private.h \ 11 | ../../util/list.h \ 12 | ../../util/log.c \ 13 | ../../util/log.h \ 14 | ../../util/sysfs.c \ 15 | ../../util/sysfs.h \ 16 | libaccfg.c 17 | 18 | libaccel_config_la_LIBADD =\ 19 | $(UUID_LIBS) 20 | 21 | EXTRA_DIST += libaccel-config.sym 22 | 23 | libaccel_config_la_LDFLAGS = $(AM_LDFLAGS) \ 24 | -version-info $(LIBACCFG_CURRENT):$(LIBACCFG_REVISION):$(LIBACCFG_AGE) \ 25 | -Wl,--version-script=$(top_srcdir)/accfg/lib/libaccel-config.sym 26 | libaccel_config_la_DEPENDENCIES = libaccel-config.sym 27 | 28 | pkgconfigdir = $(libdir)/pkgconfig 29 | pkgconfig_DATA = libaccel-config.pc 30 | EXTRA_DIST += libaccel-config.pc.in 31 | CLEANFILES += libaccel-config.pc 32 | -------------------------------------------------------------------------------- /accfg/lib/libaccel-config.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: libaccfg 7 | Description: Configure accfg subsystem devices 8 | Version: @VERSION@ 9 | Libs: -L${libdir} -laccel-config 10 | Libs.private: 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /accfg/lib/libaccel-config.sym: -------------------------------------------------------------------------------- 1 | LIBACCFG_1 { 2 | global: accfg_ref; 3 | accfg_get_log_priority; 4 | accfg_set_log_priority; 5 | accfg_set_log_fn; 6 | accfg_enable; 7 | accfg_unref; 8 | accfg_new; 9 | accfg_basenames; 10 | accfg_device_get_first; 11 | accfg_device_get_next; 12 | accfg_device_get_ctx; 13 | accfg_device_get_devname; 14 | accfg_device_get_id; 15 | accfg_ctx_device_get_by_id; 16 | accfg_ctx_device_get_by_name; 17 | accfg_device_get_max_groups; 18 | accfg_device_get_max_work_queues; 19 | accfg_device_get_max_engines; 20 | accfg_device_get_max_work_queues_size; 21 | accfg_device_get_numa_node; 22 | accfg_device_get_ims_size; 23 | accfg_device_get_max_batch_size; 24 | accfg_device_get_max_transfer_size; 25 | accfg_device_get_configurable; 26 | accfg_device_get_pasid_enabled; 27 | accfg_device_get_errors; 28 | accfg_device_get_state; 29 | accfg_device_get_max_tokens; 30 | accfg_device_get_max_batch_size; 31 | accfg_device_get_cdev_major; 32 | accfg_device_is_active; 33 | accfg_device_get_token_limit; 34 | accfg_device_set_token_limit; 35 | accfg_device_enable; 36 | accfg_device_disable; 37 | accfg_device_type_validate; 38 | accfg_group_get_first; 39 | accfg_group_get_next; 40 | accfg_group_get_id; 41 | accfg_device_group_get_by_id; 42 | accfg_group_get_device; 43 | accfg_group_get_device_id; 44 | accfg_group_get_ctx; 45 | accfg_group_get_devname; 46 | accfg_group_get_tokens_reserved; 47 | accfg_group_get_tokens_allowed; 48 | accfg_group_get_use_token_limit; 49 | accfg_group_get_traffic_class_a; 50 | accfg_group_get_traffic_class_b; 51 | accfg_group_set_tokens_reserved; 52 | accfg_group_set_tokens_allowed; 53 | accfg_group_set_use_token_limit; 54 | accfg_group_set_traffic_class_a; 55 | accfg_group_set_traffic_class_b; 56 | accfg_wq_get_id; 57 | accfg_device_wq_get_by_id; 58 | accfg_wq_get_first; 59 | accfg_wq_get_next; 60 | accfg_wq_get_ctx; 61 | accfg_wq_get_device; 62 | accfg_wq_get_group; 63 | accfg_wq_get_group_id; 64 | accfg_wq_get_priority; 65 | accfg_wq_get_priv; 66 | accfg_wq_get_devname; 67 | accfg_wq_get_mode; 68 | accfg_wq_is_enabled; 69 | accfg_wq_get_size; 70 | accfg_wq_get_block_on_fault; 71 | accfg_wq_get_state; 72 | accfg_wq_get_cdev_minor; 73 | accfg_wq_get_type; 74 | accfg_wq_get_threshold; 75 | accfg_wq_set_size; 76 | accfg_wq_set_priority; 77 | accfg_wq_set_group_id; 78 | accfg_wq_set_block_on_fault; 79 | accfg_wq_set_threshold; 80 | accfg_wq_set_str_mode; 81 | accfg_wq_set_str_type; 82 | accfg_wq_set_str_name; 83 | accfg_wq_enable; 84 | accfg_wq_disable; 85 | accfg_wq_priority_boundary; 86 | accfg_wq_size_boundary; 87 | accfg_engine_get_first; 88 | accfg_engine_get_next; 89 | accfg_engine_get_ctx; 90 | accfg_engine_get_device; 91 | accfg_engine_get_group; 92 | accfg_engine_get_id; 93 | accfg_device_engine_get_by_id; 94 | accfg_engine_get_group_id; 95 | accfg_engine_get_devname; 96 | accfg_engine_set_group_id; 97 | local: 98 | *; 99 | }; 100 | 101 | LIBACCFG_3 { 102 | global: 103 | accfg_wq_set_mode; 104 | accfg_wq_get_type_name; 105 | accfg_device_get_clients; 106 | accfg_wq_get_clients; 107 | } LIBACCFG_1; 108 | 109 | LIBACCFG_4 { 110 | global: 111 | accfg_device_get_version; 112 | accfg_device_get_gen_cap; 113 | } LIBACCFG_3; 114 | 115 | LIBACCFG_5 { 116 | global: 117 | accfg_device_get_type; 118 | accfg_device_get_type_str; 119 | } LIBACCFG_4; 120 | 121 | LIBACCFG_6 { 122 | global: 123 | accfg_device_get_cmd_status; 124 | accfg_device_get_cmd_status_str; 125 | } LIBACCFG_5; 126 | 127 | LIBACCFG_7 { 128 | global: 129 | accfg_wq_get_max_batch_size; 130 | accfg_wq_get_max_transfer_size; 131 | accfg_wq_set_max_batch_size; 132 | accfg_wq_set_max_transfer_size; 133 | } LIBACCFG_6; 134 | 135 | LIBACCFG_8 { 136 | global: 137 | accfg_wq_get_user_dev_path; 138 | } LIBACCFG_7; 139 | 140 | LIBACCFG_9 { 141 | global: 142 | accfg_device_get_op_cap; 143 | } LIBACCFG_8; 144 | 145 | LIBACCFG_10 { 146 | global: 147 | accfg_wq_get_ats_disable; 148 | accfg_wq_set_ats_disable; 149 | accfg_ctx_get_last_error; 150 | accfg_ctx_get_last_error_str; 151 | accfg_ctx_get_last_error_device; 152 | accfg_ctx_get_last_error_wq; 153 | accfg_ctx_get_last_error_group; 154 | accfg_ctx_get_last_error_engine; 155 | } LIBACCFG_9; 156 | 157 | LIBACCFG_11 { 158 | global: 159 | accfg_wq_get_occupancy; 160 | } LIBACCFG_10; 161 | 162 | LIBACCFG_12 { 163 | global: 164 | accfg_device_get_max_read_buffers; 165 | accfg_device_get_read_buffer_limit; 166 | accfg_device_set_read_buffer_limit; 167 | accfg_group_get_read_buffers_reserved; 168 | accfg_group_get_read_buffers_allowed; 169 | accfg_group_get_use_read_buffer_limit; 170 | accfg_group_set_read_buffers_reserved; 171 | accfg_group_set_read_buffers_allowed; 172 | accfg_group_set_use_read_buffer_limit; 173 | } LIBACCFG_11; 174 | 175 | LIBACCFG_13 { 176 | global: 177 | accfg_wq_set_str_driver_name; 178 | accfg_wq_get_driver_name; 179 | accfg_wq_driver_name_validate; 180 | accfg_wq_get_op_config; 181 | accfg_wq_set_op_config; 182 | accfg_wq_set_op_config_str; 183 | } LIBACCFG_12; 184 | 185 | LIBACCFG_14 { 186 | global: 187 | accfg_device_get_compl_size; 188 | accfg_device_get_iaa_cap; 189 | accfg_group_get_desc_progress_limit; 190 | accfg_group_set_desc_progress_limit; 191 | accfg_group_get_batch_progress_limit; 192 | accfg_group_set_batch_progress_limit; 193 | accfg_wq_get_prs_disable; 194 | accfg_wq_set_prs_disable; 195 | accfg_device_get_event_log_size; 196 | accfg_device_set_event_log_size; 197 | } LIBACCFG_13; 198 | -------------------------------------------------------------------------------- /accfg/lib/private.h: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: LGPL-2.1 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef _LIBACCFG_PRIVATE_H_ 5 | #define _LIBACCFG_PRIVATE_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | struct accfg_device { 21 | struct accfg_ctx *ctx; 22 | unsigned int id; 23 | struct accfg_group *group; 24 | struct accfg_wq *wq; 25 | struct accfg_engine *engine; 26 | struct list_head groups; 27 | struct list_head wqs; 28 | struct list_head engines; 29 | struct list_node list; 30 | int group_init; 31 | char *device_path; 32 | char *device_buf; 33 | char *bus_type_str; 34 | char *device_type_str; 35 | enum accfg_device_type type; 36 | size_t buf_len; 37 | 38 | /* Device Attributes */ 39 | struct accfg_error errors; 40 | int max_groups; 41 | int max_work_queues; 42 | int max_engines; 43 | int max_work_queues_size; 44 | int numa_node; 45 | int ims_size; 46 | int max_batch_size; 47 | int compl_size; 48 | int configurable; 49 | int max_read_buffers; 50 | unsigned int read_buffer_limit; 51 | int event_log_size; 52 | unsigned int cdev_major; 53 | unsigned int version; 54 | uint64_t max_transfer_size; 55 | uint64_t opcap; 56 | uint64_t gencap; 57 | int pasid_enabled; 58 | }; 59 | 60 | struct accfg_group { 61 | struct accfg_device *device; 62 | int id; 63 | int buf_len; 64 | int size; 65 | char *group_path; 66 | char *group_buf; 67 | char *group_engines; 68 | char *group_wqs; 69 | struct list_head wqs; 70 | struct list_head engines; 71 | struct list_node list; 72 | int numa_node; 73 | int group_id; 74 | int wqs_init; 75 | int engines_init; 76 | 77 | /* Group Attributes */ 78 | unsigned int read_buffers_reserved; 79 | unsigned int read_buffers_allowed; 80 | unsigned int use_read_buffer_limit; 81 | int traffic_class_a; 82 | int traffic_class_b; 83 | unsigned int desc_progress_limit; 84 | unsigned int batch_progress_limit; 85 | }; 86 | 87 | struct accfg_engine { 88 | struct accfg_device *device; 89 | struct accfg_group *group; 90 | struct list_node list; 91 | char *engine_path; 92 | char *engine_buf; 93 | int type, id, buf_len; 94 | int numa_node; 95 | 96 | /* Engine Attributes */ 97 | int group_id; 98 | }; 99 | 100 | struct accfg_wq { 101 | struct accfg_device *device; 102 | struct accfg_group *group; 103 | struct list_node list; 104 | char *wq_path; 105 | char *wq_buf; 106 | int id, buf_len; 107 | int numa_node; 108 | 109 | /* Workqueue Attributes */ 110 | int group_id; 111 | int size; 112 | int priv; 113 | int priority; 114 | int block_on_fault; 115 | int cdev_minor; 116 | unsigned int threshold; 117 | char *mode; 118 | char *name; 119 | char *driver_name; 120 | enum accfg_wq_type type; 121 | char *state; 122 | unsigned int max_batch_size; 123 | uint64_t max_transfer_size; 124 | int ats_disable; 125 | int prs_disable; 126 | }; 127 | 128 | #define ACCFG_EXPORT __attribute__ ((visibility("default"))) 129 | 130 | struct accfg_error_ctx { 131 | unsigned int cmd_status; 132 | struct accfg_device *device; 133 | struct accfg_group *group; 134 | struct accfg_wq *wq; 135 | struct accfg_engine *engine; 136 | }; 137 | 138 | /** 139 | * struct accfg_ctx - library user context to find device instances 140 | * 141 | * Instantiate with accfg_new(), which takes an initial reference. Free 142 | * the context by dropping the reference count to zero with 143 | * accfg_unref(), or take additional references with accfg_ref() 144 | * @timeout: default library timeout in milliseconds 145 | */ 146 | struct accfg_ctx { 147 | /* log_ctx must be first member for accfg_set_log_fn compat */ 148 | struct log_ctx ctx; 149 | int refcount; 150 | int devices_init; 151 | int groups_init; 152 | struct list_head devices; 153 | uint64_t timeout; 154 | void *private_data; 155 | bool compat; 156 | struct accfg_error_ctx *error_ctx; 157 | }; 158 | 159 | #endif /* _LIBACCFG_PRIVATE_H_ */ 160 | -------------------------------------------------------------------------------- /accfg/test.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static char *result(int rc) 11 | { 12 | if (rc == EXIT_SKIP) 13 | return "SKIP"; 14 | else if (rc) 15 | return "FAIL"; 16 | else 17 | return "PASS"; 18 | } 19 | 20 | int cmd_test(int argc, const char **argv, struct accfg_ctx *ctx) 21 | { 22 | struct accfg_test *test; 23 | int loglevel = LOG_DEBUG, i, rc; 24 | const char * const u[] = { 25 | "accel-config test []", 26 | NULL 27 | }; 28 | const struct option options[] = { 29 | OPT_INTEGER('l', "loglevel", &loglevel, 30 | "set the log level (default LOG_DEBUG)"), 31 | OPT_END(), 32 | }; 33 | 34 | argc = parse_options(argc, argv, options, u, 0); 35 | 36 | for (i = 0; i < argc; i++) 37 | error("unknown parameter \"%s\"\n", argv[i]); 38 | 39 | if (argc) 40 | usage_with_options(u, options); 41 | else 42 | test = accfg_test_new(0); 43 | if (!test) 44 | return EXIT_FAILURE; 45 | 46 | printf("run test_libaccfg\n"); 47 | rc = test_libaccfg(loglevel, test, ctx); 48 | fprintf(stderr, "test-libaccfg: %s\n", result(rc)); 49 | free(test); 50 | if (rc) 51 | return rc; 52 | printf("SUCCESS!\n"); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then 4 | cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \ 5 | chmod +x .git/hooks/pre-commit && \ 6 | echo "Activated pre-commit hook." 7 | fi 8 | 9 | $(dirname $0)/git-version-gen 10 | reconf_args='' 11 | [ -n "$*" ] && reconf_args="$*" 12 | autoreconf --install --symlink $reconf_args 13 | 14 | libdir() { 15 | echo $(cd $1/$(gcc -print-multi-os-directory); pwd) 16 | } 17 | 18 | args="--prefix=/usr \ 19 | --sysconfdir=/etc \ 20 | --libdir=$(libdir /usr/lib)" 21 | 22 | echo 23 | echo "----------------------------------------------------------------" 24 | echo "Initialized build system. For a common configuration please run:" 25 | echo "----------------------------------------------------------------" 26 | echo 27 | echo "./configure CFLAGS='-g -O2' $args" 28 | echo 29 | -------------------------------------------------------------------------------- /builtin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2015-2017 Intel Corporation. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of version 2 of the GNU General Public License as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | */ 13 | #ifndef _ACCFG_BUILTIN_H_ 14 | #define _ACCFG_BUILTIN_H_ 15 | extern const char accfg_usage_string[]; 16 | 17 | struct cmd_struct { 18 | const char *cmd; 19 | int (*fn) (int, const char **, void *ctx); 20 | }; 21 | int cmd_list(int argc, const char **argv, void *ctx); 22 | int cmd_info(int argc, const char **argv, void *ctx); 23 | int cmd_config(int argc, const char **argv, void *ctx); 24 | int cmd_save(int argc, const char **argv, void *ctx); 25 | int cmd_disable_device(int argc, const char **argv, void *ctx); 26 | int cmd_enable_device(int argc, const char **argv, void *ctx); 27 | int cmd_disable_wq(int argc, const char **argv, void *ctx); 28 | int cmd_enable_wq(int argc, const char **argv, void *ctx); 29 | int cmd_config_device(int argc, const char **argv, void *ctx); 30 | int cmd_config_group(int argc, const char **argv, void *ctx); 31 | int cmd_config_wq(int argc, const char **argv, void *ctx); 32 | int cmd_config_engine(int argc, const char **argv, void *ctx); 33 | int cmd_config_default(int argc, const char **argv, void *ctx); 34 | #ifdef ENABLE_TEST 35 | int cmd_test(int argc, const char **argv, void *ctx); 36 | #endif 37 | #endif /* _ACCFG_BUILTIN_H_ */ 38 | -------------------------------------------------------------------------------- /ccan/array_size/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/array_size/array_size.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_ARRAY_SIZE_H 3 | #define CCAN_ARRAY_SIZE_H 4 | #include "config.h" 5 | #include 6 | 7 | /** 8 | * ARRAY_SIZE - get the number of elements in a visible array 9 | * @arr: the array whose size you want. 10 | * 11 | * This does not work on pointers, or arrays declared as [], or 12 | * function parameters. With correct compiler support, such usage 13 | * will cause a build error (see build_assert). 14 | */ 15 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + _array_size_chk(arr)) 16 | 17 | #if HAVE_BUILTIN_TYPES_COMPATIBLE_P && HAVE_TYPEOF 18 | /* Two gcc extensions. 19 | * &a[0] degrades to a pointer: a different type from an array */ 20 | #define _array_size_chk(arr) \ 21 | BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(typeof(arr), \ 22 | typeof(&(arr)[0]))) 23 | #else 24 | #define _array_size_chk(arr) 0 25 | #endif 26 | #endif /* CCAN_ALIGNOF_H */ 27 | -------------------------------------------------------------------------------- /ccan/build_assert/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/build_assert/build_assert.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_BUILD_ASSERT_H 3 | #define CCAN_BUILD_ASSERT_H 4 | 5 | /** 6 | * BUILD_ASSERT - assert a build-time dependency. 7 | * @cond: the compile-time condition which must be true. 8 | * 9 | * Your compile will fail if the condition isn't true, or can't be evaluated 10 | * by the compiler. This can only be used within a function. 11 | * 12 | * Example: 13 | * #include 14 | * ... 15 | * static char *foo_to_char(struct foo *foo) 16 | * { 17 | * // This code needs string to be at start of foo. 18 | * BUILD_ASSERT(offsetof(struct foo, string) == 0); 19 | * return (char *)foo; 20 | * } 21 | */ 22 | #define BUILD_ASSERT(cond) \ 23 | do { (void) sizeof(char [1 - 2*!(cond)]); } while(0) 24 | 25 | /** 26 | * BUILD_ASSERT_OR_ZERO - assert a build-time dependency, as an expression. 27 | * @cond: the compile-time condition which must be true. 28 | * 29 | * Your compile will fail if the condition isn't true, or can't be evaluated 30 | * by the compiler. This can be used in an expression: its value is "0". 31 | * 32 | * Example: 33 | * #define foo_to_char(foo) \ 34 | * ((char *)(foo) \ 35 | * + BUILD_ASSERT_OR_ZERO(offsetof(struct foo, string) == 0)) 36 | */ 37 | #define BUILD_ASSERT_OR_ZERO(cond) \ 38 | (sizeof(char [1 - 2*!(cond)]) - 1) 39 | 40 | #endif /* CCAN_BUILD_ASSERT_H */ 41 | -------------------------------------------------------------------------------- /ccan/check_type/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/check_type/check_type.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_CHECK_TYPE_H 3 | #define CCAN_CHECK_TYPE_H 4 | #include "config.h" 5 | 6 | /** 7 | * check_type - issue a warning or build failure if type is not correct. 8 | * @expr: the expression whose type we should check (not evaluated). 9 | * @type: the exact type we expect the expression to be. 10 | * 11 | * This macro is usually used within other macros to try to ensure that a macro 12 | * argument is of the expected type. No type promotion of the expression is 13 | * done: an unsigned int is not the same as an int! 14 | * 15 | * check_type() always evaluates to 0. 16 | * 17 | * If your compiler does not support typeof, then the best we can do is fail 18 | * to compile if the sizes of the types are unequal (a less complete check). 19 | * 20 | * Example: 21 | * // They should always pass a 64-bit value to _set_some_value! 22 | * #define set_some_value(expr) \ 23 | * _set_some_value((check_type((expr), uint64_t), (expr))) 24 | */ 25 | 26 | /** 27 | * check_types_match - issue a warning or build failure if types are not same. 28 | * @expr1: the first expression (not evaluated). 29 | * @expr2: the second expression (not evaluated). 30 | * 31 | * This macro is usually used within other macros to try to ensure that 32 | * arguments are of identical types. No type promotion of the expressions is 33 | * done: an unsigned int is not the same as an int! 34 | * 35 | * check_types_match() always evaluates to 0. 36 | * 37 | * If your compiler does not support typeof, then the best we can do is fail 38 | * to compile if the sizes of the types are unequal (a less complete check). 39 | * 40 | * Example: 41 | * // Do subtraction to get to enclosing type, but make sure that 42 | * // pointer is of correct type for that member. 43 | * #define container_of(mbr_ptr, encl_type, mbr) \ 44 | * (check_types_match((mbr_ptr), &((encl_type *)0)->mbr), \ 45 | * ((encl_type *) \ 46 | * ((char *)(mbr_ptr) - offsetof(enclosing_type, mbr)))) 47 | */ 48 | #if HAVE_TYPEOF 49 | #define check_type(expr, type) \ 50 | ((typeof(expr) *)0 != (type *)0) 51 | 52 | #define check_types_match(expr1, expr2) \ 53 | ((typeof(expr1) *)0 != (typeof(expr2) *)0) 54 | #else 55 | #include 56 | /* Without typeof, we can only test the sizes. */ 57 | #define check_type(expr, type) \ 58 | BUILD_ASSERT_OR_ZERO(sizeof(expr) == sizeof(type)) 59 | 60 | #define check_types_match(expr1, expr2) \ 61 | BUILD_ASSERT_OR_ZERO(sizeof(expr1) == sizeof(expr2)) 62 | #endif /* HAVE_TYPEOF */ 63 | 64 | #endif /* CCAN_CHECK_TYPE_H */ 65 | -------------------------------------------------------------------------------- /ccan/container_of/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/container_of/container_of.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_CONTAINER_OF_H 3 | #define CCAN_CONTAINER_OF_H 4 | #include 5 | 6 | #include "config.h" 7 | #include 8 | 9 | /** 10 | * container_of - get pointer to enclosing structure 11 | * @member_ptr: pointer to the structure member 12 | * @containing_type: the type this member is within 13 | * @member: the name of this member within the structure. 14 | * 15 | * Given a pointer to a member of a structure, this macro does pointer 16 | * subtraction to return the pointer to the enclosing type. 17 | * 18 | * Example: 19 | * struct foo { 20 | * int fielda, fieldb; 21 | * // ... 22 | * }; 23 | * struct info { 24 | * int some_other_field; 25 | * struct foo my_foo; 26 | * }; 27 | * 28 | * static struct info *foo_to_info(struct foo *foo) 29 | * { 30 | * return container_of(foo, struct info, my_foo); 31 | * } 32 | */ 33 | #define container_of(member_ptr, containing_type, member) \ 34 | ((containing_type *) \ 35 | ((char *)(member_ptr) \ 36 | - container_off(containing_type, member)) \ 37 | + check_types_match(*(member_ptr), ((containing_type *)0)->member)) 38 | 39 | /** 40 | * container_off - get offset to enclosing structure 41 | * @containing_type: the type this member is within 42 | * @member: the name of this member within the structure. 43 | * 44 | * Given a pointer to a member of a structure, this macro does 45 | * typechecking and figures out the offset to the enclosing type. 46 | * 47 | * Example: 48 | * struct foo { 49 | * int fielda, fieldb; 50 | * // ... 51 | * }; 52 | * struct info { 53 | * int some_other_field; 54 | * struct foo my_foo; 55 | * }; 56 | * 57 | * static struct info *foo_to_info(struct foo *foo) 58 | * { 59 | * size_t off = container_off(struct info, my_foo); 60 | * return (void *)((char *)foo - off); 61 | * } 62 | */ 63 | #define container_off(containing_type, member) \ 64 | offsetof(containing_type, member) 65 | 66 | /** 67 | * container_of_var - get pointer to enclosing structure using a variable 68 | * @member_ptr: pointer to the structure member 69 | * @container_var: a pointer of same type as this member's container 70 | * @member: the name of this member within the structure. 71 | * 72 | * Given a pointer to a member of a structure, this macro does pointer 73 | * subtraction to return the pointer to the enclosing type. 74 | * 75 | * Example: 76 | * static struct info *foo_to_i(struct foo *foo) 77 | * { 78 | * struct info *i = container_of_var(foo, i, my_foo); 79 | * return i; 80 | * } 81 | */ 82 | #if HAVE_TYPEOF 83 | #define container_of_var(member_ptr, container_var, member) \ 84 | container_of(member_ptr, typeof(*container_var), member) 85 | #else 86 | #define container_of_var(member_ptr, container_var, member) \ 87 | ((void *)((char *)(member_ptr) - \ 88 | container_off_var(container_var, member))) 89 | #endif 90 | 91 | /** 92 | * container_off_var - get offset of a field in enclosing structure 93 | * @container_var: a pointer to a container structure 94 | * @member: the name of a member within the structure. 95 | * 96 | * Given (any) pointer to a structure and a its member name, this 97 | * macro does pointer subtraction to return offset of member in a 98 | * structure memory layout. 99 | * 100 | */ 101 | #if HAVE_TYPEOF 102 | #define container_off_var(var, member) \ 103 | container_off(typeof(*var), member) 104 | #else 105 | #define container_off_var(var, member) \ 106 | ((const char *)&(var)->member - (const char *)(var)) 107 | #endif 108 | 109 | #endif /* CCAN_CONTAINER_OF_H */ 110 | -------------------------------------------------------------------------------- /ccan/endian/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/list/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/BSD-MIT -------------------------------------------------------------------------------- /ccan/list/list.c: -------------------------------------------------------------------------------- 1 | /* Licensed under BSD-MIT - see LICENSE file for details */ 2 | #include 3 | #include 4 | #include "list.h" 5 | 6 | static void *corrupt(const char *abortstr, 7 | const struct list_node *head, 8 | const struct list_node *node, 9 | unsigned int count) 10 | { 11 | if (abortstr) { 12 | fprintf(stderr, 13 | "%s: prev corrupt in node %p (%u) of %p\n", 14 | abortstr, node, count, head); 15 | abort(); 16 | } 17 | return NULL; 18 | } 19 | 20 | struct list_node *list_check_node(const struct list_node *node, 21 | const char *abortstr) 22 | { 23 | const struct list_node *p, *n; 24 | int count = 0; 25 | 26 | for (p = node, n = node->next; n != node; p = n, n = n->next) { 27 | count++; 28 | if (n->prev != p) 29 | return corrupt(abortstr, node, n, count); 30 | } 31 | /* Check prev on head node. */ 32 | if (node->prev != p) 33 | return corrupt(abortstr, node, node, 0); 34 | 35 | return (struct list_node *)node; 36 | } 37 | 38 | struct list_head *list_check(const struct list_head *h, const char *abortstr) 39 | { 40 | if (!list_check_node(&h->n, abortstr)) 41 | return NULL; 42 | return (struct list_head *)h; 43 | } 44 | -------------------------------------------------------------------------------- /ccan/minmax/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/minmax/minmax.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_MINMAX_H 3 | #define CCAN_MINMAX_H 4 | 5 | #include "config.h" 6 | 7 | #pragma GCC diagnostic ignored "-Wpedantic" 8 | 9 | #include 10 | 11 | #if !HAVE_STATEMENT_EXPR || !HAVE_TYPEOF 12 | /* 13 | * Without these, there's no way to avoid unsafe double evaluation of 14 | * the arguments 15 | */ 16 | #error Sorry, minmax module requires statement expressions and typeof 17 | #endif 18 | 19 | #if HAVE_BUILTIN_TYPES_COMPATIBLE_P 20 | #define MINMAX_ASSERT_COMPATIBLE(a, b) \ 21 | BUILD_ASSERT(__builtin_types_compatible_p(a, b)) 22 | #else 23 | #define MINMAX_ASSERT_COMPATIBLE(a, b) \ 24 | do { } while (0) 25 | #endif 26 | 27 | #define min(a, b) \ 28 | ({ \ 29 | typeof(a) _a = (a); \ 30 | typeof(b) _b = (b); \ 31 | MINMAX_ASSERT_COMPATIBLE(typeof(_a), typeof(_b)); \ 32 | _a < _b ? _a : _b; \ 33 | }) 34 | 35 | #define max(a, b) \ 36 | ({ \ 37 | typeof(a) __a = (a); \ 38 | typeof(b) __b = (b); \ 39 | MINMAX_ASSERT_COMPATIBLE(typeof(__a), typeof(__b)); \ 40 | __a > __b ? __a : __b; \ 41 | }) 42 | 43 | #define clamp(v, f, c) (max(min((v), (c)), (f))) 44 | 45 | 46 | #define min_t(t, a, b) \ 47 | ({ \ 48 | t _ta = (a); \ 49 | t _tb = (b); \ 50 | min(_ta, _tb); \ 51 | }) 52 | #define max_t(t, a, b) \ 53 | ({ \ 54 | t _ta = (a); \ 55 | t _tb = (b); \ 56 | max(_ta, _tb); \ 57 | }) 58 | 59 | #define clamp_t(t, v, f, c) \ 60 | ({ \ 61 | t _tv = (v); \ 62 | t _tf = (f); \ 63 | t _tc = (c); \ 64 | clamp(_tv, _tf, _tc); \ 65 | }) 66 | 67 | #endif /* CCAN_MINMAX_H */ 68 | -------------------------------------------------------------------------------- /ccan/short_types/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/short_types/short_types.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_SHORT_TYPES_H 3 | #define CCAN_SHORT_TYPES_H 4 | #include 5 | 6 | /** 7 | * u64/s64/u32/s32/u16/s16/u8/s8 - short names for explicitly-sized types. 8 | */ 9 | typedef uint64_t u64; 10 | typedef int64_t s64; 11 | typedef uint32_t u32; 12 | typedef int32_t s32; 13 | typedef uint16_t u16; 14 | typedef int16_t s16; 15 | typedef uint8_t u8; 16 | typedef int8_t s8; 17 | 18 | /* Whichever they include first, they get these definitions. */ 19 | #ifdef CCAN_ENDIAN_H 20 | /** 21 | * be64/be32/be16 - 64/32/16 bit big-endian representation. 22 | */ 23 | typedef beint64_t be64; 24 | typedef beint32_t be32; 25 | typedef beint16_t be16; 26 | 27 | /** 28 | * le64/le32/le16 - 64/32/16 bit little-endian representation. 29 | */ 30 | typedef leint64_t le64; 31 | typedef leint32_t le32; 32 | typedef leint16_t le16; 33 | #endif 34 | 35 | #endif /* CCAN_SHORT_TYPES_H */ 36 | -------------------------------------------------------------------------------- /ccan/str/LICENSE: -------------------------------------------------------------------------------- 1 | ../../licenses/CC0 -------------------------------------------------------------------------------- /ccan/str/debug.c: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #include "config.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef CCAN_STR_DEBUG 9 | /* Because we mug the real ones with macros, we need our own wrappers. */ 10 | int str_isalnum(int i) 11 | { 12 | assert(i >= -1 && i < 256); 13 | return isalnum(i); 14 | } 15 | 16 | int str_isalpha(int i) 17 | { 18 | assert(i >= -1 && i < 256); 19 | return isalpha(i); 20 | } 21 | 22 | int str_isascii(int i) 23 | { 24 | assert(i >= -1 && i < 256); 25 | return isascii(i); 26 | } 27 | 28 | #if HAVE_ISBLANK 29 | int str_isblank(int i) 30 | { 31 | assert(i >= -1 && i < 256); 32 | return isblank(i); 33 | } 34 | #endif 35 | 36 | int str_iscntrl(int i) 37 | { 38 | assert(i >= -1 && i < 256); 39 | return iscntrl(i); 40 | } 41 | 42 | int str_isdigit(int i) 43 | { 44 | assert(i >= -1 && i < 256); 45 | return isdigit(i); 46 | } 47 | 48 | int str_isgraph(int i) 49 | { 50 | assert(i >= -1 && i < 256); 51 | return isgraph(i); 52 | } 53 | 54 | int str_islower(int i) 55 | { 56 | assert(i >= -1 && i < 256); 57 | return islower(i); 58 | } 59 | 60 | int str_isprint(int i) 61 | { 62 | assert(i >= -1 && i < 256); 63 | return isprint(i); 64 | } 65 | 66 | int str_ispunct(int i) 67 | { 68 | assert(i >= -1 && i < 256); 69 | return ispunct(i); 70 | } 71 | 72 | int str_isspace(int i) 73 | { 74 | assert(i >= -1 && i < 256); 75 | return isspace(i); 76 | } 77 | 78 | int str_isupper(int i) 79 | { 80 | assert(i >= -1 && i < 256); 81 | return isupper(i); 82 | } 83 | 84 | int str_isxdigit(int i) 85 | { 86 | assert(i >= -1 && i < 256); 87 | return isxdigit(i); 88 | } 89 | 90 | #undef strstr 91 | #undef strchr 92 | #undef strrchr 93 | 94 | char *str_strstr(const char *haystack, const char *needle) 95 | { 96 | return strstr(haystack, needle); 97 | } 98 | 99 | char *str_strchr(const char *haystack, int c) 100 | { 101 | return strchr(haystack, c); 102 | } 103 | 104 | char *str_strrchr(const char *haystack, int c) 105 | { 106 | return strrchr(haystack, c); 107 | } 108 | #endif 109 | -------------------------------------------------------------------------------- /ccan/str/str.c: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #include 3 | 4 | size_t strcount(const char *haystack, const char *needle) 5 | { 6 | size_t i = 0, nlen = strlen(needle); 7 | 8 | while ((haystack = strstr(haystack, needle)) != NULL) { 9 | i++; 10 | haystack += nlen; 11 | } 12 | return i; 13 | } 14 | -------------------------------------------------------------------------------- /ccan/str/str_debug.h: -------------------------------------------------------------------------------- 1 | /* CC0 (Public domain) - see LICENSE file for details */ 2 | #ifndef CCAN_STR_DEBUG_H 3 | #define CCAN_STR_DEBUG_H 4 | 5 | /* #define CCAN_STR_DEBUG 1 */ 6 | 7 | #ifdef CCAN_STR_DEBUG 8 | /* Because we mug the real ones with macros, we need our own wrappers. */ 9 | int str_isalnum(int i); 10 | int str_isalpha(int i); 11 | int str_isascii(int i); 12 | #if HAVE_ISBLANK 13 | int str_isblank(int i); 14 | #endif 15 | int str_iscntrl(int i); 16 | int str_isdigit(int i); 17 | int str_isgraph(int i); 18 | int str_islower(int i); 19 | int str_isprint(int i); 20 | int str_ispunct(int i); 21 | int str_isspace(int i); 22 | int str_isupper(int i); 23 | int str_isxdigit(int i); 24 | 25 | char *str_strstr(const char *haystack, const char *needle); 26 | char *str_strchr(const char *s, int c); 27 | char *str_strrchr(const char *s, int c); 28 | #endif /* CCAN_STR_DEBUG */ 29 | 30 | #endif /* CCAN_STR_DEBUG_H */ 31 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.60) 2 | m4_include([version.m4]) 3 | AC_INIT([accel-config], 4 | GIT_VERSION, 5 | [linux-dsa@lists.01.org], 6 | [accel-config], 7 | [https://github.com/xxx/accel-config]) 8 | AC_CONFIG_SRCDIR([accfg/lib/libaccfg.c]) 9 | AC_CONFIG_AUX_DIR([build-aux]) 10 | AM_INIT_AUTOMAKE([ 11 | foreign 12 | 1.11 13 | -Wall 14 | -Wno-portability 15 | silent-rules 16 | tar-pax 17 | no-dist-gzip 18 | dist-xz 19 | subdir-objects 20 | ]) 21 | AC_PROG_CC_STDC 22 | AC_USE_SYSTEM_EXTENSIONS 23 | AC_SYS_LARGEFILE 24 | AC_CONFIG_MACRO_DIR([m4]) 25 | AM_SILENT_RULES([yes]) 26 | LT_INIT([ 27 | disable-static 28 | pic-only 29 | ]) 30 | AC_PREFIX_DEFAULT([/usr]) 31 | 32 | AC_PROG_SED 33 | AC_PROG_MKDIR_P 34 | 35 | AC_ARG_ENABLE([docs], 36 | AS_HELP_STRING([--disable-docs], 37 | [disable documentation build @<:@default=enabled@:>@]), 38 | [], enable_docs=yes) 39 | AS_IF([test "x$enable_docs" = "xyes"], [ 40 | AC_DEFINE(ENABLE_DOCS, [1], [Documentation / man pages.]) 41 | ]) 42 | AM_CONDITIONAL([ENABLE_DOCS], [test "x$enable_docs" = "xyes"]) 43 | 44 | AC_ARG_ENABLE([asciidoctor], 45 | AS_HELP_STRING([--enable-asciidoctor], 46 | [use asciidoctor for documentation build]), 47 | [], enable_asciidoctor=no) 48 | AM_CONDITIONAL([USE_ASCIIDOCTOR], [test "x$enable_asciidoctor" = "xyes"]) 49 | if test "x$enable_asciidoctor" = "xyes"; then 50 | asciidoc="asciidoctor" 51 | else 52 | asciidoc="asciidoc" 53 | fi 54 | AC_CHECK_PROG(ASCIIDOC, [$asciidoc], [$(which $asciidoc)], [missing]) 55 | if test "x$ASCIIDOC" = xmissing -a "x$enable_docs" = "xyes"; then 56 | AC_MSG_ERROR([$asciidoc needed to build documentation]) 57 | fi 58 | AC_SUBST([ASCIIDOC]) 59 | 60 | if test x"$asciidoc" = x"asciidoc"; then 61 | AC_CHECK_PROG(XMLTO, [xmlto], [$(which xmlto)], [missing]) 62 | if test "x$XMLTO" = xmissing -a "x$enable_docs" = "xyes"; then 63 | AC_MSG_ERROR([xmlto needed to build documentation]) 64 | fi 65 | AC_SUBST([XMLTO]) 66 | fi 67 | 68 | AC_C_TYPEOF 69 | AC_DEFINE([HAVE_STATEMENT_EXPR], 1, [Define to 1 if you have statement expressions.]) 70 | 71 | AC_C_BIGENDIAN( 72 | AC_DEFINE(HAVE_BIG_ENDIAN, 1, [Define to 1 if big-endian-arch]), 73 | AC_DEFINE(HAVE_LITTLE_ENDIAN, 1, [Define to 1 if little-endian-arch]), 74 | [], []) 75 | 76 | AC_ARG_ENABLE([logging], 77 | AS_HELP_STRING([--disable-logging], [disable system logging @<:@default=enabled@:>@]), 78 | [], enable_logging=yes) 79 | AS_IF([test "x$enable_logging" = "xyes"], [ 80 | AC_DEFINE(ENABLE_LOGGING, [1], [System logging.]) 81 | ]) 82 | 83 | AC_ARG_ENABLE([debug], 84 | AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]), 85 | [], [enable_debug=no]) 86 | AS_IF([test "x$enable_debug" = "xyes"], [ 87 | AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.]) 88 | ]) 89 | 90 | AC_ARG_ENABLE([test], 91 | AS_HELP_STRING([--enable-test], [enable accfg test command @<:@default=disabled@:>@]), 92 | [], [enable_test=$enable_destructive]) 93 | AS_IF([test "x$enable_test" = "xyes"], 94 | [AC_DEFINE([ENABLE_TEST], [1], [accfg test support])]) 95 | AM_CONDITIONAL([ENABLE_TEST], [test "x$enable_test" = "xyes"]) 96 | 97 | PKG_CHECK_MODULES([UUID], [uuid], 98 | [AC_DEFINE([HAVE_UUID], [1], [Define to 1 if using libuuid])]) 99 | PKG_CHECK_MODULES([JSON], [json-c]) 100 | 101 | AC_ARG_WITH([bash-completion-dir], 102 | AS_HELP_STRING([--with-bash-completion-dir[=PATH]], 103 | [Install the bash auto-completion script in this directory. @<:@default=yes@:>@]), 104 | [], 105 | [with_bash_completion_dir=yes]) 106 | 107 | if test "x$with_bash_completion_dir" = "xyes"; then 108 | PKG_CHECK_MODULES([BASH_COMPLETION], [bash-completion >= 2.0], 109 | [BASH_COMPLETION_DIR="`pkg-config --variable=completionsdir bash-completion`"], 110 | [BASH_COMPLETION_DIR="$datadir/bash-completion/completions"]) 111 | else 112 | BASH_COMPLETION_DIR="$with_bash_completion_dir" 113 | fi 114 | 115 | AC_SUBST([BASH_COMPLETION_DIR]) 116 | AM_CONDITIONAL([ENABLE_BASH_COMPLETION],[test "x$with_bash_completion_dir" != "xno"]) 117 | 118 | AC_ARG_ENABLE([local], 119 | AS_HELP_STRING([--disable-local], @<:@default=system@:>@]), 120 | [], [enable_local=yes]) 121 | 122 | AC_CHECK_HEADERS_ONCE([linux/version.h]) 123 | 124 | AC_CHECK_FUNCS([ \ 125 | __secure_getenv \ 126 | secure_getenv\ 127 | ]) 128 | 129 | AC_ARG_WITH([tmpfilesdir], 130 | [AS_HELP_STRING([--with-tmpfilesdir=DIR], [Directory for temporary runtime files])], 131 | [tmpfilesdir=$withval], 132 | [tmpfilesdir="/run"]) 133 | 134 | accfg_confdir=${sysconfdir}/accel-config 135 | accfg_conf=accel-config.conf 136 | 137 | AC_SUBST([accfg_confdir]) 138 | AC_SUBST([accfg_conf]) 139 | 140 | my_CFLAGS="\ 141 | -Wall \ 142 | -Wchar-subscripts \ 143 | -Wformat-security \ 144 | -Wmissing-declarations \ 145 | -Wmissing-prototypes \ 146 | -Wnested-externs \ 147 | -Wpointer-arith \ 148 | -Wshadow \ 149 | -Wsign-compare \ 150 | -Wstrict-prototypes \ 151 | -Wtype-limits \ 152 | -Wmaybe-uninitialized \ 153 | -Wdeclaration-after-statement \ 154 | -Wunused-result \ 155 | -D_FORTIFY_SOURCE=2 \ 156 | -O2 157 | " 158 | AC_SUBST([my_CFLAGS]) 159 | 160 | AC_CONFIG_HEADERS(config.h) 161 | AC_CONFIG_FILES([ 162 | Makefile 163 | accfg/lib/Makefile 164 | accfg/Makefile 165 | test/Makefile 166 | Documentation/accfg/Makefile 167 | ]) 168 | 169 | AC_OUTPUT 170 | AC_MSG_RESULT([ 171 | $PACKAGE $VERSION 172 | ===== 173 | 174 | prefix: ${prefix} 175 | sysconfdir: ${sysconfdir} 176 | libdir: ${libdir} 177 | includedir: ${includedir} 178 | tmpfilesdir: ${tmpfilesdir} 179 | 180 | compiler: ${CC} 181 | cflags: ${CFLAGS} 182 | ldflags: ${LDFLAGS} 183 | 184 | logging: ${enable_logging} 185 | debug: ${enable_debug} 186 | ]) 187 | -------------------------------------------------------------------------------- /contrib/accel-config.conf.sample: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"dsa0", 4 | "read_buffer_limit":0, 5 | "groups":[ 6 | { 7 | "dev":"group0.0", 8 | "traffic_class_a":-1, 9 | "traffic_class_b":-1, 10 | "grouped_workqueues":[ 11 | { 12 | "dev":"wq0.0", 13 | "mode":"shared", 14 | "size":16, 15 | "group_id":0, 16 | "priority":10, 17 | "block_on_fault":1, 18 | "type":"user", 19 | "driver_name":"user", 20 | "name":"app1", 21 | "threshold":15 22 | } 23 | ], 24 | "grouped_engines":[ 25 | { 26 | "dev":"engine0.0", 27 | "group_id":0 28 | }, 29 | { 30 | "dev":"engine0.1", 31 | "group_id":0 32 | } 33 | ] 34 | }, 35 | { 36 | "dev":"group0.1", 37 | "traffic_class_a":-1, 38 | "traffic_class_b":-1, 39 | "grouped_workqueues":[ 40 | { 41 | "dev":"wq0.1", 42 | "mode":"dedicated", 43 | "size":16, 44 | "group_id":1, 45 | "priority":10, 46 | "block_on_fault":1, 47 | "type":"user", 48 | "driver_name":"user", 49 | "name":"app2", 50 | "threshold":0 51 | } 52 | ], 53 | "grouped_engines":[ 54 | { 55 | "dev":"engine0.2", 56 | "group_id":1 57 | }, 58 | { 59 | "dev":"engine0.3", 60 | "group_id":1 61 | } 62 | ] 63 | }, 64 | { 65 | "dev":"group0.2", 66 | "traffic_class_a":-1, 67 | "traffic_class_b":-1 68 | }, 69 | { 70 | "dev":"group0.3", 71 | "traffic_class_a":-1, 72 | "traffic_class_b":-1 73 | } 74 | ] 75 | } 76 | ] 77 | -------------------------------------------------------------------------------- /contrib/configs/app_profile.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"dsa0", 4 | "read_buffer_limit":0, 5 | "groups":[ 6 | { 7 | "dev":"group0.0", 8 | "grouped_workqueues":[ 9 | { 10 | "dev":"wq0.0", 11 | "mode":"shared", 12 | "size":8, 13 | "group_id":0, 14 | "priority":10, 15 | "block_on_fault":0, 16 | "max_batch_size":32, 17 | "max_transfer_size":16384, 18 | "type":"user", 19 | "driver_name":"user", 20 | "name":"app1", 21 | "threshold":6 22 | } 23 | ], 24 | "grouped_engines":[ 25 | { 26 | "dev":"engine0.0", 27 | "group_id":0 28 | } 29 | ] 30 | }, 31 | { 32 | "dev":"group0.1", 33 | "grouped_workqueues":[ 34 | { 35 | "dev":"wq0.1", 36 | "mode":"shared", 37 | "size":32, 38 | "group_id":1, 39 | "priority":10, 40 | "block_on_fault":0, 41 | "max_batch_size":32, 42 | "max_transfer_size":2097152, 43 | "type":"user", 44 | "driver_name":"user", 45 | "name":"app2", 46 | "threshold":28 47 | } 48 | ], 49 | "grouped_engines":[ 50 | { 51 | "dev":"engine0.1", 52 | "group_id":1 53 | } 54 | ] 55 | } 56 | ] 57 | } 58 | ] 59 | -------------------------------------------------------------------------------- /contrib/configs/net_profile.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"dsa0", 4 | "read_buffer_limit":0, 5 | "groups":[ 6 | { 7 | "dev":"group0.0", 8 | "grouped_workqueues":[ 9 | { 10 | "dev":"wq0.0", 11 | "mode":"dedicated", 12 | "size":32, 13 | "group_id":0, 14 | "priority":10, 15 | "block_on_fault":0, 16 | "max_batch_size":1024, 17 | "max_transfer_size":16384, 18 | "type":"user", 19 | "driver_name":"user", 20 | "name":"app1", 21 | "threshold":0 22 | } 23 | ], 24 | "grouped_engines":[ 25 | { 26 | "dev":"engine0.0", 27 | "group_id":0 28 | } 29 | ] 30 | }, 31 | { 32 | "dev":"group0.1", 33 | "grouped_workqueues":[ 34 | { 35 | "dev":"wq0.1", 36 | "mode":"dedicated", 37 | "size":32, 38 | "group_id":1, 39 | "priority":10, 40 | "block_on_fault":0, 41 | "max_batch_size":1024, 42 | "max_transfer_size":16384, 43 | "type":"user", 44 | "driver_name":"user", 45 | "name":"app2", 46 | "threshold":0 47 | } 48 | ], 49 | "grouped_engines":[ 50 | { 51 | "dev":"engine0.1", 52 | "group_id":1 53 | }, 54 | ] 55 | }, 56 | { 57 | "dev":"group0.2", 58 | "grouped_workqueues":[ 59 | { 60 | "dev":"wq0.2", 61 | "mode":"dedicated", 62 | "size":32, 63 | "group_id":2, 64 | "priority":10, 65 | "block_on_fault":0, 66 | "max_batch_size":1024, 67 | "max_transfer_size":16384, 68 | "type":"user", 69 | "driver_name":"user", 70 | "name":"app3", 71 | "threshold":0 72 | } 73 | ], 74 | "grouped_engines":[ 75 | { 76 | "dev":"engine0.2", 77 | "group_id":2 78 | } 79 | ] 80 | }, 81 | { 82 | "dev":"group0.3", 83 | "grouped_workqueues":[ 84 | { 85 | "dev":"wq0.3", 86 | "mode":"dedicated", 87 | "size":32, 88 | "group_id":3, 89 | "priority":10, 90 | "block_on_fault":0, 91 | "max_batch_size":1024, 92 | "max_transfer_size":16384, 93 | "type":"user", 94 | "driver_name":"user", 95 | "name":"app4", 96 | "threshold":0 97 | } 98 | ], 99 | "grouped_engines":[ 100 | { 101 | "dev":"engine0.3", 102 | "group_id":3 103 | }, 104 | ] 105 | } 106 | ] 107 | } 108 | ] 109 | -------------------------------------------------------------------------------- /contrib/configs/os_profile.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"dsa0", 4 | "read_buffer_limit":0, 5 | "groups":[ 6 | { 7 | "dev":"group0.0", 8 | "grouped_workqueues":[ 9 | { 10 | "dev":"wq0.0", 11 | "mode":"shared", 12 | "size":16, 13 | "group_id":0, 14 | "priority":10, 15 | "block_on_fault":0, 16 | "max_batch_size":32, 17 | "max_transfer_size":2097152, 18 | "type":"kernel", 19 | "driver_name":"dmaengine", 20 | "name":"dmaengine", 21 | "threshold":15 22 | } 23 | ], 24 | "grouped_engines":[ 25 | { 26 | "dev":"engine0.0", 27 | "group_id":0 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /contrib/configs/profilenote.txt: -------------------------------------------------------------------------------- 1 | The purpose of this doc is about the config profile statements. Json 2 | doesn't support comments. List all the example config files along with 3 | profile descriptions. 4 | 5 | 1. os_profile.conf 6 | Recommended dsa config for OS usage such as page zeroing,compaction etc. 7 | - 1 group 8 | - 1 SWQ@16qd/1eng 9 | - max xfer size=2MB, max batch sz=32, bof=0 10 | - priority 10 11 | - threshold 15 12 | 13 | 2. app_profile.conf 14 | Recommended dsa default application profile. 15 | - 2 groups 16 | - Grp1 - SWQ1@8qd, 1eng 17 | max xfer size=16KB, max batch sz=32, bof=0, threshold=6 18 | - Grp2 - SWQ2@32qd, 1eng 19 | max xfer size=2MB, max batch sz=32, bof=0, threshold=28 20 | - Use group1 for smaller size ops with better latency characteristics 21 | 22 | 3. net_profile.conf 23 | Recommended dsa network accel profile 24 | - 4 groups, each with 1 DWQ@32qd/1 eng per group 25 | - Each DWQ has max xfer size=16KB 26 | - DWQ threshold default 0 27 | 28 | 4. storage_profile.conf 29 | Recommended dsa storage accel profile 30 | - 2 groups each with 1 DWQ@32qd/1 eng per group 31 | - DWQ1 - max xfer size=16KB, max batch sz=32, bof=0 32 | for lower latency or synchronous ops 33 | - DWQ2 - max xfer size=2MB, max batch sz=32, bof=0 34 | for throughput ops 35 | - targeting SPDK-like uses 36 | - DWQ threshold default 0 37 | 38 | 5. user_default_profile.conf 39 | Recommended dsa and iax accel profile template 40 | - The template specifies one DSA device and one IAX device 41 | - The attributes are applied to all WQs and engines on DSA and IAX 42 | - Run "accel-config config-user-default -c user_default_profile.conf" 43 | to load the config to all WQs and engines on all available DSA and 44 | IAX devices 45 | - The attributes can be edited. Two devices can be tailored to one device. 46 | - 1 group with all available WQs/all engs per group 47 | - Attributes that can be changed: 48 | "group_id":0 49 | "priority":10 50 | "block_on_fault":1 51 | "ats_disable":0 52 | "prs_disable":1 53 | "name":"user_default_wq" 54 | - Calcuated attributes: 55 | "size": max WQ size / max WQs 56 | "threshold": WQ size 57 | - Fixed attributes: 58 | "type": "user" 59 | "mode":"shared" 60 | "driver_name":"user", 61 | - Attributes with default values set by driver: 62 | "max_batch_size": default value 63 | "max_transfer_size": default value 64 | "op_config": default value 65 | -------------------------------------------------------------------------------- /contrib/configs/storage_profile.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"dsa0", 4 | "read_buffer_limit":0, 5 | "groups":[ 6 | { 7 | "dev":"group0.0", 8 | "grouped_workqueues":[ 9 | { 10 | "dev":"wq0.0", 11 | "mode":"dedicated", 12 | "size":32, 13 | "group_id":0, 14 | "priority":10, 15 | "block_on_fault":0, 16 | "max_batch_size":32, 17 | "max_transfer_size":16384, 18 | "type":"user", 19 | "driver_name":"user", 20 | "name":"app1", 21 | "threshold":0 22 | } 23 | ], 24 | "grouped_engines":[ 25 | { 26 | "dev":"engine0.0", 27 | "group_id":0 28 | } 29 | ] 30 | }, 31 | { 32 | "dev":"group0.1", 33 | "grouped_workqueues":[ 34 | { 35 | "dev":"wq0.1", 36 | "mode":"dedicated", 37 | "size":32, 38 | "group_id":1, 39 | "priority":10, 40 | "block_on_fault":0, 41 | "max_batch_size":32, 42 | "max_transfer_size":2097152, 43 | "type":"user", 44 | "driver_name":"user", 45 | "name":"app2", 46 | "threshold":0 47 | } 48 | ], 49 | "grouped_engines":[ 50 | { 51 | "dev":"engine0.1", 52 | "group_id":1 53 | } 54 | ] 55 | } 56 | ] 57 | } 58 | ] 59 | -------------------------------------------------------------------------------- /contrib/configs/user_default_profile.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"dsa0", 4 | "groups":[ 5 | { 6 | "dev":"group0.0", 7 | "grouped_workqueues":[ 8 | { 9 | "dev":"wq0.0", 10 | "mode":"shared", 11 | "group_id":0, 12 | "priority":10, 13 | "block_on_fault":1, 14 | "name":"user_default_wq", 15 | "ats_disable":0, 16 | "prs_disable":1 17 | } 18 | ] 19 | } 20 | ] 21 | }, 22 | { 23 | "dev":"iax1", 24 | "groups":[ 25 | { 26 | "dev":"group1.0", 27 | "grouped_workqueues":[ 28 | { 29 | "dev":"wq1.0", 30 | "mode":"shared", 31 | "group_id":0, 32 | "priority":10, 33 | "block_on_fault":1, 34 | "name":"user_default_wq", 35 | "ats_disable":0, 36 | "prs_disable":1 37 | } 38 | ] 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /debbuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright(c) 2021 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | [ -z "${DEBEMAIL}" ] || [ -z "${DEBFULLNAME}" ] && { 8 | echo 9 | echo "Please set following environment variables" 10 | echo 11 | echo 'DEBEMAIL="your.email.address@example.org"' 12 | echo 'DEBFULLNAME="Firstname Lastname"' 13 | echo 14 | exit 15 | } 16 | 17 | NAME=accel-config 18 | REPODIR=idxd-config 19 | REFDIR=$(pwd) 20 | UPSTREAM=$REFDIR #TODO update once we have a public upstream 21 | PKGDIR=debpkg 22 | 23 | WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")" 24 | trap 'rm -rf $WORKDIR' exit 25 | 26 | [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR" 27 | 28 | echo 29 | ch_entry=$(grep accel-config debian/changelog | head -n1) 30 | echo Last entry in debian/changelog = \"$ch_entry\" 31 | 32 | read -r -p 'Build package for this version? [y/N)] ' res 33 | if [[ ! "$res" =~ [yY](es)* ]] 34 | then 35 | echo 36 | echo "Please run ./debdch.sh or dch -r to update debian/changelog" 37 | echo 38 | exit 39 | fi 40 | 41 | dch -r "" 42 | 43 | pushd $WORKDIR 44 | 45 | git clone $REFERENCE "$UPSTREAM" $REPODIR 46 | 47 | cp -r $REFDIR/deb* $REPODIR #temporary till initial commit 48 | 49 | cd $REPODIR 50 | 51 | debmake -t 52 | DEB_BUILD_OPTIONS=nocheck debuild -us -uc 53 | 54 | popd 55 | 56 | rm -rf $PKGDIR 57 | mkdir $PKGDIR 58 | rm -rf $WORKDIR/*/ 59 | cp -r $WORKDIR/* $PKGDIR 60 | 61 | echo 62 | echo "!!!Debian package created in ./$PKGDIR and is ready for upload!!!" 63 | echo "***debian/changelog was updated - please commit the changes***" 64 | echo 65 | -------------------------------------------------------------------------------- /debdch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright(c) 2021 Intel Corporation. All rights reserved. 4 | 5 | set -e 6 | 7 | [ -z "${DEBEMAIL}" ] || [ -z "${DEBFULLNAME}" ] && { 8 | echo 9 | echo "Please set following environment variables" 10 | echo 11 | echo 'DEBEMAIL="your.email.address@example.org"' 12 | echo 'DEBFULLNAME="Firstname Lastname"' 13 | echo 14 | exit 15 | } 16 | 17 | [ -n "$1" ] && REVISION=$1 || REVISION=1 18 | 19 | VERSION=$(echo $(./git-version) | sed 's/\.git.*//') 20 | DEB_VERSION=$VERSION-$REVISION 21 | 22 | echo 23 | echo "Updating debian/changelog.." 24 | echo "accel-config version = $VERSION" 25 | echo "Debian revision = $REVISION" 26 | echo "New version = $DEB_VERSION" 27 | echo 28 | echo "Adding changes..." 29 | echo 30 | 31 | dch -v $DEB_VERSION --package accel-config -D unstable "" 32 | cur_release=HEAD 33 | prev_release=$(git describe --tags --abbrev=0 $cur_release^) 34 | git shortlog $prev_release..$cur_release --invert-grep \ 35 | --grep=release 2>/dev/null | 36 | while IFS= read -r line || [ -n "$line" ]; 37 | do 38 | if [[ "$line" == *"):" ]]; then 39 | line=$(echo $line | sed -e "s/ ([0-9]*):$//") 40 | line="[ "$line" ]" 41 | else 42 | line=$(echo $line | sed -e "s/^.*: //") 43 | fi 44 | dch -a "$line" 2>/dev/null 45 | echo "* $line" 46 | done 47 | 48 | echo 49 | echo Please run "dch -r" to review and update debian/changelog before building package 50 | echo 51 | -------------------------------------------------------------------------------- /debian/accel-config-test.install: -------------------------------------------------------------------------------- 1 | usr/libexec/accel-config/test/* usr/libexec/accel-config/test 2 | -------------------------------------------------------------------------------- /debian/accel-config.install: -------------------------------------------------------------------------------- 1 | usr/bin/accel-config 2 | usr/share/man/man1/accel-config* 3 | etc/accel-config/contrib/configs/* 4 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: accel-config 2 | Maintainer: Ramesh Thomas 3 | Section: libs 4 | Priority: optional 5 | Standards-Version: 4.6.2 6 | Homepage: https://github.com/intel/idxd-config 7 | Vcs-Browser: https://salsa.debian.org/debian/idxd-config 8 | Vcs-Git: https://salsa.debian.org/debian/idxd-config.git 9 | Rules-Requires-Root: no 10 | Build-Depends: asciidoc, 11 | debhelper-compat (= 13), 12 | libjson-c-dev, 13 | libkeyutils-dev, 14 | pkg-config, 15 | uuid-dev, 16 | xmlto, 17 | zlib1g-dev, 18 | libssl-dev 19 | 20 | Package: accel-config 21 | Section: misc 22 | Architecture: i386 amd64 23 | Depends: ${misc:Depends}, ${shlibs:Depends} 24 | Pre-Depends: ${misc:Pre-Depends} 25 | Description: utility for configuring the DSA subsystem 26 | Intel Accelerator Utilities (accel-config) provides a user interface to the 27 | Intel Data Streaming Accelerator (DSA). DSA is a high-performance data copy 28 | and transformation accelerator integrated into Intel Xeon processors. 29 | . 30 | This package contains a utility for configuring the DSA (Data Stream 31 | Accelerator) subsystem in the Linux kernel. 32 | 33 | Package: libaccel-config1 34 | Architecture: i386 amd64 35 | Multi-Arch: same 36 | Depends: ${misc:Depends}, ${shlibs:Depends} 37 | Description: utility library wrapping the Intel DSA sysfs ABI 38 | This provides access to work queues by using the mmap portal from the 39 | character device and send work to the accelerator. It also provides 40 | interfaces to manage virtual DSA devices exposed by the driver to the 41 | guest via VFIO mediated device framework. 42 | . 43 | This package contains a utility library for managing the DSA (Data 44 | Stream Accelerator) subsystem in the Linux kernel. 45 | 46 | Package: libaccel-config-dev 47 | Section: libdevel 48 | Architecture: i386 amd64 49 | Multi-Arch: same 50 | Depends: libaccel-config1 (= ${binary:Version}), ${misc:Depends} 51 | Description: development files for libaccel-config 52 | Header files and development library for compiling C programs to link with the 53 | libaccel-config library and manage the DSA subsystem in the Linux kernel. 54 | 55 | Package: accel-config-test 56 | Section: misc 57 | Architecture: i386 amd64 58 | Depends: ${misc:Depends}, ${shlibs:Depends} 59 | Pre-Depends: ${misc:Pre-Depends} 60 | Description: utility to test the DSA subsystem 61 | This utility has test cases that exercise the DSA subsysem. It uses 62 | libaccel-config API to configure workqueues and issues ENQCMD and MOVDIR64 63 | instructions to move memory. 64 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: idxd-config 3 | Source: https://github.com/intel/idxd-config 4 | 5 | Files: * 6 | Copyright: 2021-2023 Intel Corporation 7 | License: LGPL-2.1 8 | On Debian systems, the complete text of the GNU General Public 9 | License can be found in `/usr/share/common-licenses/LGPL-2.1'. 10 | 11 | Files: accfg/* 12 | Documentation/* 13 | util/* 14 | test/* 15 | Copyright: 2021-2023 Intel Corporation 16 | License: GPL-2 17 | On Debian systems, the complete text of the GNU General Public 18 | License can be found in `/usr/share/common-licenses/GPL-2'. 19 | 20 | Files: accfg/lib/* 21 | Copyright: 2021-2023 Intel Corporation 22 | License: LGPL-2.1 23 | On Debian systems, the complete text of the GNU General Public 24 | License can be found in `/usr/share/common-licenses/LGPL-2.1'. 25 | 26 | Files: debian/* 27 | Copyright: 2021-2023 Intel Corporation 28 | License: GPL-2+ 29 | This package is free software; you can redistribute it and/or modify 30 | it under the terms of the GNU General Public License as published by 31 | the Free Software Foundation; either version 2 of the License, or 32 | (at your option) any later version. 33 | . 34 | This package is distributed in the hope that it will be useful, 35 | but WITHOUT ANY WARRANTY; without even the implied warranty of 36 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 37 | GNU General Public License for more details. 38 | . 39 | You should have received a copy of the GNU General Public License 40 | along with this program. If not, see 41 | . 42 | On Debian systems, the complete text of the GNU General 43 | Public License version 2 can be found in `/usr/share/common-licenses/GPL-2'. 44 | -------------------------------------------------------------------------------- /debian/libaccel-config-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/accel-config/ 2 | usr/lib/${DEB_HOST_MULTIARCH}/libaccel-config.so 3 | usr/lib/${DEB_HOST_MULTIARCH}/pkgconfig/ 4 | -------------------------------------------------------------------------------- /debian/libaccel-config1.install: -------------------------------------------------------------------------------- 1 | usr/lib/${DEB_HOST_MULTIARCH}/libaccel-config.so.1* 2 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | export DH_VERBOSE = 1 4 | export DEB_BUILD_MAINT_OPTIONS = hardening=+all 5 | export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic 6 | export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed 7 | 8 | DPKG_EXPORT_BUILDFLAGS = 1 9 | include /usr/share/dpkg/buildflags.mk 10 | 11 | %: 12 | dh $@ 13 | 14 | override_dh_autoreconf: 15 | dh_autoreconf ./autogen.sh 16 | 17 | override_dh_auto_configure: 18 | dh_auto_configure -- --prefix=/usr --sysconfdir=/etc --enable-test=yes 19 | 20 | override_dh_clean: 21 | #removing files generated by autogen.sh 22 | rm -fr build-aux/ 23 | rm -fr m4/* 24 | rm -fr Documentation/Makefile.in 25 | rm -fr Makefile.in 26 | rm -fr aclocal.m4 27 | rm -fr autom4te.cache 28 | rm -fr config.h.in 29 | rm -fr configure 30 | rm -fr accfg/lib/Makefile.in 31 | rm -fr accfg/Makefile.in 32 | rm -fr test/Makefile.in 33 | # created by tests and not cleaned up after 34 | rm -fr version.m4 35 | rm -fr Documentation/accfg/asciidoc.conf 36 | rm -fr Documentation/accfg/Makefile.in 37 | rm -fr config.log 38 | dh_clean 39 | 40 | override_dh_install: 41 | find debian/tmp -name '*.la' -print -delete 42 | dh_install 43 | 44 | override_dh_fixperms: 45 | dh_fixperms -X2g2q_user_1.conf -X2g2q_user_2.conf 46 | 47 | override_dh_makeshlibs: 48 | dh_makeshlibs -- -c4 49 | 50 | #override_dh_missing: 51 | dh_missing --fail-missing 52 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /debian/watch: -------------------------------------------------------------------------------- 1 | version=4 2 | opts="filenamemangle=s%(?:.*?)?v?(\d[\d.]*)\.tar\.gz%@PACKAGE@-$1.tar.gz%" \ 3 | https://github.com/intel/idxd-config/tags \ 4 | (?:.*?/)?v?(\d[\d.]*)\.tar\.gz debian uupdate 5 | 6 | -------------------------------------------------------------------------------- /git-version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | to_ver() { 4 | VN=$1 5 | #drop leading 'v' out of the version so its a pure number 6 | if [ ${VN:0:1} = "v" ]; then 7 | VN=${VN:1} 8 | fi 9 | echo $VN 10 | } 11 | 12 | dirty() { 13 | VN=$(to_ver $1) 14 | git update-index -q --refresh 15 | if test -z "$(git diff-index --name-only HEAD --)"; then 16 | echo "$VN" 17 | else 18 | echo "${VN}.dirty" 19 | fi 20 | } 21 | 22 | DEF_VER=4.1.8 23 | 24 | LF=' 25 | ' 26 | 27 | # First see if there is a version file (included in release tarballs), 28 | # then try git-describe, then default. 29 | if test -f version; then 30 | VN=$(cat version) || VN="$DEF_VER" 31 | elif test -d ${GIT_DIR:-.git} -o -f .git && 32 | VN=$(git describe --match "v[0-9]*" --abbrev=7 HEAD 2>/dev/null) && 33 | case "$VN" in 34 | *$LF*) (exit 1) ;; 35 | v[0-9]*) 36 | VN="$(dirty $VN)" 37 | esac; then 38 | VN=$(echo "$VN" | sed -e 's/-/./g'); 39 | else 40 | read COMMIT COMMIT_SUBJECT </dev/null) 42 | EOF 43 | if [ -z $COMMIT ]; then 44 | VN="${DEF_VER}+" 45 | else 46 | VN="$(dirty ${DEF_VER}.git$COMMIT)" 47 | fi 48 | fi 49 | 50 | echo $VN 51 | -------------------------------------------------------------------------------- /git-version-gen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | GVF=version.m4 4 | 5 | if test -r $GVF; then 6 | VC=$(sed -e 's/m4_define(\[GIT_VERSION], \[//' <$GVF) 7 | VC=$(echo $VC | sed -e 's/\])//') 8 | else 9 | VC=unset 10 | fi 11 | 12 | VN=$(./git-version) 13 | 14 | test "$VN" = "$VC" || { 15 | echo >&2 "GIT_VERSION = $VN" 16 | echo "m4_define([GIT_VERSION], [$VN])" >$GVF 17 | exit 0 18 | } 19 | -------------------------------------------------------------------------------- /licenses/BSD-MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a copy 2 | of this software and associated documentation files (the "Software"), to deal 3 | in the Software without restriction, including without limitation the rights 4 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 5 | copies of the Software, and to permit persons to whom the Software is 6 | furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in 9 | all copies or substantial portions of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 12 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 14 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 15 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 16 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 17 | THE SOFTWARE. 18 | -------------------------------------------------------------------------------- /licenses/CC0: -------------------------------------------------------------------------------- 1 | Statement of Purpose 2 | 3 | The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). 4 | 5 | Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. 6 | 7 | For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 8 | 9 | 1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: 10 | 11 | the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; 12 | moral rights retained by the original author(s) and/or performer(s); 13 | publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; 14 | rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; 15 | rights protecting the extraction, dissemination, use and reuse of data in a Work; 16 | database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and 17 | other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 18 | 19 | 2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 20 | 21 | 3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 22 | 23 | 4. Limitations and Disclaimers. 24 | 25 | No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. 26 | Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. 27 | Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. 28 | Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. 29 | -------------------------------------------------------------------------------- /make-git-snapshot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | NAME=accel-config 5 | REFDIR=$(pwd) 6 | UPSTREAM=$REFDIR #TODO update once we have a public upstream 7 | OUTDIR=$HOME/rpmbuild/SOURCES 8 | 9 | [ -n "$1" ] && HEAD="$1" || HEAD="HEAD" 10 | 11 | WORKDIR="$(mktemp -d --tmpdir "$NAME.XXXXXXXXXX")" 12 | trap 'rm -rf $WORKDIR' exit 13 | 14 | [ -d "$REFDIR" ] && REFERENCE="--reference $REFDIR" 15 | git clone $REFERENCE "$UPSTREAM" "$WORKDIR" 16 | 17 | VERSION=$(./git-version) 18 | DIRNAME="accel-config-${VERSION}" 19 | git archive --remote="$WORKDIR" --format=tar --prefix="$DIRNAME/" HEAD | gzip > $OUTDIR/"accel-config-${VERSION}.tar.gz" 20 | 21 | echo "Written $OUTDIR/accel-config-${VERSION}.tar.gz" 22 | -------------------------------------------------------------------------------- /rpmbuild-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd $(dirname $0) >/dev/null 3 | [ ! -d ~/rpmbuild/SOURCES ] && echo "rpmdev tree not found" && exit 1 4 | ./make-git-snapshot.sh 5 | popd > /dev/null 6 | rpmbuild -ba $(dirname $0)/rhel/accfg-test.spec 7 | -------------------------------------------------------------------------------- /rpmbuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | pushd $(dirname $0) >/dev/null 3 | [ ! -d ~/rpmbuild/SOURCES ] && echo "rpmdev tree not found" && exit 1 4 | ./make-git-snapshot.sh 5 | popd > /dev/null 6 | rpmbuild -ba $(dirname $0)/rhel/accfg.spec 7 | -------------------------------------------------------------------------------- /sles/header: -------------------------------------------------------------------------------- 1 | # 2 | # spec file for package accel-config 3 | # 4 | # Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. 5 | # Copyright (c) 2015 Intel Corporation 6 | # 7 | # All modifications and additions to the file contributed by third parties 8 | # remain the property of their copyright owners, unless otherwise agreed 9 | # upon. The license for this file, and modifications and additions to the 10 | # file, is the same license as for the pristine package itself (unless the 11 | # license for the pristine package is not an Open Source License, in which 12 | # case the license is the MIT License). An "Open Source License" is a 13 | # license that conforms to the Open Source Definition (Version 1.9) 14 | # published by the Open Source Initiative. 15 | 16 | # Please submit bugfixes or comments via http://bugs.opensuse.org/ 17 | # 18 | -------------------------------------------------------------------------------- /test.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2015-2019 Intel Corporation. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of version 2 of the GNU General Public License as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | */ 13 | #ifndef __TEST_H__ 14 | #define __TEST_H__ 15 | #include 16 | 17 | #define EXIT_SKIP 77 18 | struct accfg_test; 19 | struct accfg_ctx; 20 | struct util_filter_ctx; 21 | struct accfg_test *accfg_test_new(unsigned int kver); 22 | int accfg_test_result(struct accfg_test *test, int rc); 23 | int accfg_test_get_skipped(struct accfg_test *test); 24 | int accfg_test_get_attempted(struct accfg_test *test); 25 | int __accfg_test_attempt(struct accfg_test *test, unsigned int kver, 26 | const char *caller, int line); 27 | #define accfg_test_attempt(t, v) __accfg_test_attempt(t, v, __func__, __LINE__) 28 | void __accfg_test_skip(struct accfg_test *test, const char *caller, int line); 29 | #define accfg_test_skip(t) __accfg_test_skip(t, __func__, __LINE__) 30 | int test_libaccfg(int loglevel, struct accfg_test *test, struct accfg_ctx *ctx); 31 | int device_enum(struct accfg_ctx *ctx, struct util_filter_ctx *fctx); 32 | #endif /* __TEST_H__ */ 33 | -------------------------------------------------------------------------------- /test/Makefile.am: -------------------------------------------------------------------------------- 1 | include $(top_srcdir)/Makefile.am.in 2 | 3 | TESTS =\ 4 | libaccfg \ 5 | dsa_user_test_runner.sh \ 6 | iaa_user_test_runner.sh \ 7 | dsa_config_test_runner.sh 8 | 9 | EXTRA_DIST += $(TESTS) 10 | 11 | check_PROGRAMS =\ 12 | libaccfg \ 13 | dsa_test \ 14 | iaa_test 15 | 16 | if ENABLE_TEST 17 | testprogdir = $(prefix)/libexec/accel-config/test/ 18 | testprog_DATA = common 19 | testprog_SCRIPTS = dsa_user_test_runner.sh iaa_user_test_runner.sh dsa_config_test_runner.sh 20 | testprog_PROGRAMS = dsa_test iaa_test 21 | 22 | testconfdir = $(testprogdir)/configs/ 23 | testconf_DATA = configs/2g2q_user_1.conf configs/2g2q_user_2.conf 24 | endif 25 | 26 | LIBACCFG_LIB =\ 27 | ../accfg/lib/libaccel-config.la 28 | 29 | testcore =\ 30 | core.c \ 31 | ../util/log.c \ 32 | ../util/sysfs.c \ 33 | dsa.h \ 34 | accfg_test.h 35 | 36 | iaa_test_LDFLAGS = -lz -lcrypto 37 | 38 | libaccfg_SOURCES = libaccfg.c $(testcore) 39 | libaccfg_LDADD = $(LIBACCFG_LIB) $(UUID_LIBS) 40 | 41 | dsa_test_SOURCES = dsa_test.c dsa.c dsa_prep.c accel_test.c 42 | dsa_test_LDADD = $(LIBACCFG_LIB) $(UUID_LIBS) 43 | 44 | iaa_test_SOURCES = iaa_test.c iaa.c iaa_prep.c accel_test.c \ 45 | algorithms/iaa_crc64.c algorithms/iaa_zcompress.c algorithms/iaa_compress.c \ 46 | algorithms/iaa_filter.c algorithms/iaa_crypto.c 47 | iaa_test_LDADD = $(LIBACCFG_LIB) $(UUID_LIBS) 48 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | #accel-config test 2 | 3 | The test command is an option to test all the library code of accel-config, 4 | including set and get libaccfg functions for all components in dsa device, set 5 | large wq to exceed max total size in dsa. 6 | 7 | Build 8 | ===== 9 | To enable test in the accel-config utility, building steps are following: 10 | 11 | ``` 12 | ./autogen.sh 13 | ./configure CFLAGS='-g -O2' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib64 14 | --enable-test=yes 15 | make 16 | sudo make install 17 | ``` 18 | 19 | Option 20 | ====== 21 | 'accel-config test' [] 22 | 23 | Options can be specified to set the log level (default is LOG DEBUG). 24 | 25 | -l:: 26 | --log-level=:: 27 | set the log level, by default it is LOG_DEBUG. 28 | 29 | Examples 30 | ======== 31 | The following shows an example of using "accel-config test". 32 | 33 | ``` 34 | # accel-config test 35 | run test libaccfg 36 | configure device 0 37 | configure group0.0 38 | configure wq0.0 39 | configure engine0.0 40 | configure engine0.1 41 | configure group0.1 42 | configure wq0.1 43 | configure wq0.2 44 | configure wq0.3 45 | configure engine0.2 46 | configure engine0.3 47 | check device0 48 | check group0.0 49 | check group0.1 50 | check wq0.0 51 | check wq0.1 52 | check wq0.2 53 | check wq0.3 54 | check engine0.0 55 | check engine0.1 56 | check engine0.2 57 | check engine0.3 58 | test 0: test the set and get libaccfg functions for components passed successfully 59 | configure device 1 60 | configure group1.3 61 | configure wq1.2 62 | configure wq1.3 63 | configure wq1.4 64 | test 1: set large wq to exceed max total size in dsa passed successfully 65 | test-libaccfg: PASS 66 | SUCCESS! 67 | ``` 68 | -------------------------------------------------------------------------------- /test/accfg_test.h: -------------------------------------------------------------------------------- 1 | #ifndef _DSA_TEST_H_ 2 | #define _DSA_TEST_H_ 3 | 4 | static inline void movdir64b(volatile void *portal, void *desc) 5 | { 6 | asm volatile("sfence\t\n" 7 | ".byte 0x66, 0x0f, 0x38, 0xf8, 0x02\t\n" : 8 | : "a" (portal), "d" (desc)); 9 | } 10 | 11 | static inline unsigned char enqcmd(volatile void *portal, void *desc) 12 | { 13 | unsigned char retry; 14 | asm volatile("sfence\t\n" 15 | ".byte 0xf2, 0x0f, 0x38, 0xf8, 0x02\t\n" 16 | "setz %0\t\n" 17 | : "=r"(retry): "a" (portal), "d" (desc)); 18 | return retry; 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /test/algorithms/iaa_compress.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "iaa_compress.h" 8 | 9 | static void dump_stream(z_stream *stream) 10 | { 11 | printf("inflate: avail_in=%d, total_in=%ld, avail_out=%d, total_out=%ld, next_out=0x%p\n", 12 | stream->avail_in, 13 | stream->total_in, 14 | stream->avail_out, 15 | stream->total_out, 16 | stream->next_out); 17 | } 18 | 19 | int iaa_do_decompress(void *dst, void *src, int src_len, int *out_len) 20 | { 21 | int ret = 0; 22 | z_stream stream; 23 | 24 | memset(&stream, 0, sizeof(z_stream)); 25 | 26 | /* allocate inflate state */ 27 | ret = inflateInit2(&stream, -MAX_WBITS); 28 | if (ret) { 29 | printf("Error inflateInit2 status %d\n", ret); 30 | return ret; 31 | } 32 | 33 | stream.avail_in = src_len; 34 | stream.next_in = src; 35 | stream.avail_out = IAA_COMPRESS_MAX_DEST_SIZE; 36 | stream.next_out = dst; 37 | dump_stream(&stream); 38 | 39 | do { 40 | ret = inflate(&stream, Z_NO_FLUSH); 41 | dump_stream(&stream); 42 | 43 | if (ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) { 44 | inflateEnd(&stream); 45 | printf("Error inflate status %d\n", ret); 46 | return ret; 47 | } 48 | } while (ret != Z_STREAM_END); 49 | 50 | ret = inflateEnd(&stream); 51 | if (ret) { 52 | printf("Error inflateEnd status %d\n", ret); 53 | return ret; 54 | } 55 | 56 | *out_len = stream.total_out; 57 | return ret; 58 | } 59 | -------------------------------------------------------------------------------- /test/algorithms/iaa_crc64.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #include 4 | #include 5 | #include "iaa_crc64.h" 6 | 7 | static const uint8_t bitrev8[0x100] = { 8 | 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 9 | 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 10 | 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, 11 | 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, 12 | 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 13 | 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, 14 | 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, 15 | 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 16 | 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, 17 | 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, 18 | 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 19 | 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, 20 | 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 21 | 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 22 | 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 23 | 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF, 24 | }; 25 | 26 | static uint64_t bit_byte_swap64(uint64_t x) 27 | { 28 | uint64_t y; 29 | 30 | y = bitrev8[x >> 56]; 31 | y |= ((uint64_t)bitrev8[(x >> 48) & 0xff]) << 8; 32 | y |= ((uint64_t)bitrev8[(x >> 40) & 0xff]) << 16; 33 | y |= ((uint64_t)bitrev8[(x >> 32) & 0xff]) << 24; 34 | y |= ((uint64_t)bitrev8[(x >> 24) & 0xff]) << 32; 35 | y |= ((uint64_t)bitrev8[(x >> 16) & 0xff]) << 40; 36 | y |= ((uint64_t)bitrev8[(x >> 8) & 0xff]) << 48; 37 | y |= ((uint64_t)bitrev8[(x >> 0) & 0xff]) << 56; 38 | return y; 39 | } 40 | 41 | static void crc64_init_tbl(uint64_t *tbl, uint64_t poly, uint8_t msb) 42 | { 43 | uint64_t crc, i; 44 | uint32_t j; 45 | 46 | tbl[0] = 0; 47 | 48 | if (msb) { 49 | poly = bit_byte_swap64(poly); 50 | for (i = 1; i < 256; i++) { 51 | crc = i; 52 | for (j = 0; j < 8; j++) 53 | if (crc & 0x0000000000000001ULL) 54 | crc = (crc >> 1) ^ poly; 55 | else 56 | crc = (crc >> 1); 57 | tbl[i] = crc; 58 | } 59 | } else { 60 | for (i = 1; i < 256; i++) { 61 | crc = i << 56; 62 | for (j = 0; j < 8; j++) 63 | if (crc & 0x8000000000000000ULL) 64 | crc = (crc << 1) ^ poly; 65 | else 66 | crc = (crc << 1); 67 | tbl[i] = crc; 68 | } 69 | } 70 | } 71 | 72 | static uint64_t crc64_init_crc(uint64_t poly, uint8_t msb, uint8_t invcrc) 73 | { 74 | if (!invcrc) 75 | return 0; 76 | poly |= (poly << 1); 77 | poly |= (poly << 2); 78 | poly |= (poly << 4); 79 | poly |= (poly << 8); 80 | poly |= (poly << 16); 81 | poly |= (poly << 32); 82 | if (!msb) 83 | return poly; 84 | return bit_byte_swap64(poly); 85 | } 86 | 87 | static uint64_t crc64_update(uint8_t data, uint64_t *tbl, uint64_t crc, uint8_t msb) 88 | { 89 | if (msb) 90 | return tbl[data ^ (crc & 0xff)] ^ (crc >> 8); 91 | else 92 | return tbl[data ^ (crc >> 56)] ^ (crc << 8); 93 | } 94 | 95 | static uint64_t crc64_finalize(uint64_t crc, uint64_t poly, uint8_t msb, uint8_t invcrc) 96 | { 97 | if (!invcrc) 98 | return crc; 99 | poly |= (poly << 1); 100 | poly |= (poly << 2); 101 | poly |= (poly << 4); 102 | poly |= (poly << 8); 103 | poly |= (poly << 16); 104 | poly |= (poly << 32); 105 | if (!msb) 106 | return crc ^ poly; 107 | return crc ^ bit_byte_swap64(poly); 108 | } 109 | 110 | /* convert 8 bytes array to uint64_t, if not aligned, fill up with 0*/ 111 | static uint64_t read_qword(uint8_t *in, uint32_t len) 112 | { 113 | uint32_t i; 114 | uint64_t qword = 0; 115 | 116 | for (i = 0; i < len; i++) 117 | qword |= ((((uint64_t)in[i]) & 0xFF) << (8 * i)); 118 | 119 | return qword; 120 | } 121 | 122 | uint64_t iaa_calculate_crc64(uint64_t poly, uint8_t *buf, uint32_t len, 123 | uint8_t msb, uint8_t invcrc) 124 | { 125 | uint64_t data; 126 | uint32_t data_size, i = 0, j = 0; 127 | uint64_t tbl[256], crc; 128 | uint8_t *ptr; 129 | uint32_t aligned_len = len & 0xfffffff8; 130 | uint32_t remain_len = len - aligned_len; 131 | 132 | crc64_init_tbl(tbl, poly, msb); 133 | crc = crc64_init_crc(poly, msb, invcrc); 134 | 135 | for (i = 0; i < aligned_len; i += sizeof(uint64_t)) { 136 | ptr = &buf[i]; 137 | data = read_qword(ptr, sizeof(uint64_t)); 138 | data_size = sizeof(uint64_t) * 8; 139 | for (j = 0; j < data_size; j += 8) 140 | crc = crc64_update((uint8_t)(data >> j), tbl, crc, msb); 141 | } 142 | 143 | if (remain_len) { 144 | ptr = &buf[i]; 145 | data = read_qword(ptr, remain_len); 146 | data_size = remain_len * 8; 147 | for (j = 0; j < data_size; j += 8) 148 | crc = crc64_update((uint8_t)(data >> j), tbl, crc, msb); 149 | } 150 | crc = crc64_finalize(crc, poly, msb, invcrc); 151 | return crc; 152 | } 153 | -------------------------------------------------------------------------------- /test/algorithms/iaa_crc64.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #ifndef _USR_CRC64_H_ 4 | #define _USR_CRC64_H_ 5 | 6 | #include 7 | #include 8 | 9 | #define IAA_CRC64_EXTRA_FLAGS_BIT_ORDER 0x8000 10 | #define IAA_CRC64_EXTRA_FLAGS_INVERT_CRC 0x4000 11 | 12 | /* crc64-ecma-182 */ 13 | #define IAA_CRC64_POLYNOMIAL 0x42F0E1EBA9EA3693 14 | 15 | uint64_t iaa_calculate_crc64(uint64_t poly, uint8_t *buf, uint32_t len, 16 | uint8_t msb, uint8_t invcrc); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /test/algorithms/iaa_crypto.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #include 4 | #include 5 | #include "accel_test.h" 6 | #include "iaa_crypto.h" 7 | 8 | /* Dump aes_key to log */ 9 | static void dump_aes_key(uint8_t *aes_key) 10 | { 11 | int i; 12 | uint32_t *raw = (uint32_t *)aes_key; 13 | 14 | dbg("aes_key addr: %p\n", aes_key); 15 | 16 | for (i = 0; i < (32 / 4); i++) 17 | dbg("aes_key[0x%X]: 0x%08x\n", i * 4, raw[i]); 18 | } 19 | 20 | /* Dump aes_iv to log */ 21 | static void dump_aes_iv(uint8_t *aes_iv) 22 | { 23 | int i; 24 | uint32_t *raw = (uint32_t *)aes_iv; 25 | 26 | dbg("aes_iv addr: %p\n", aes_iv); 27 | 28 | for (i = 0; i < (16 / 4); i++) 29 | dbg("aes_iv[0x%X]: 0x%08x\n", i * 4, raw[i]); 30 | } 31 | 32 | int iaa_do_crypto(uint8_t *out, uint8_t *in, int in_len, uint8_t *aes_key, uint8_t *aes_iv, 33 | int key_size, enum _crypto_type_t crypto_type, int do_encrypt) 34 | { 35 | int out_len = 0, out_final_len = 0; 36 | uint8_t *out_ptr = out; 37 | EVP_CIPHER_CTX *ctx; 38 | 39 | dbg("%s: in_len=%d, key_size=%d, crypto_type=%d, do_encrypt=%d\n", 40 | __func__, in_len, key_size, crypto_type, do_encrypt); 41 | dump_aes_key(aes_key); 42 | dump_aes_iv(aes_iv); 43 | 44 | /* Don't set key or IV right away; we want to check lengths */ 45 | ctx = EVP_CIPHER_CTX_new(); 46 | 47 | switch (crypto_type) { 48 | case IAA_AES_GCM: 49 | if (key_size == 128) { 50 | EVP_CipherInit_ex(ctx, EVP_aes_128_gcm(), 51 | NULL, NULL, NULL, do_encrypt); 52 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) == 12); 53 | OPENSSL_assert(EVP_CIPHER_CTX_key_length(ctx) == 16); 54 | } else { 55 | EVP_CipherInit_ex(ctx, EVP_aes_256_gcm(), 56 | NULL, NULL, NULL, do_encrypt); 57 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) == 12); 58 | OPENSSL_assert(EVP_CIPHER_CTX_key_length(ctx) == 32); 59 | } 60 | break; 61 | case IAA_AES_CFB: 62 | if (key_size == 128) { 63 | EVP_CipherInit_ex(ctx, EVP_aes_128_cfb(), 64 | NULL, NULL, NULL, do_encrypt); 65 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) == 16); 66 | OPENSSL_assert(EVP_CIPHER_CTX_key_length(ctx) == 16); 67 | } else { 68 | EVP_CipherInit_ex(ctx, EVP_aes_256_cfb(), 69 | NULL, NULL, NULL, do_encrypt); 70 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) == 16); 71 | OPENSSL_assert(EVP_CIPHER_CTX_key_length(ctx) == 32); 72 | } 73 | break; 74 | case IAA_AES_XTS: 75 | if (key_size == 128) { 76 | EVP_CipherInit_ex(ctx, EVP_aes_128_xts(), 77 | NULL, NULL, NULL, do_encrypt); 78 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) == 16); 79 | OPENSSL_assert(EVP_CIPHER_CTX_key_length(ctx) == 32); 80 | } else { 81 | EVP_CipherInit_ex(ctx, EVP_aes_256_xts(), 82 | NULL, NULL, NULL, do_encrypt); 83 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) == 16); 84 | OPENSSL_assert(EVP_CIPHER_CTX_key_length(ctx) == 64); 85 | } 86 | break; 87 | default: 88 | printf("Unknown crypto type\n"); 89 | EVP_CIPHER_CTX_free(ctx); 90 | return -1; 91 | } 92 | 93 | /* Now we can set key and IV */ 94 | EVP_CipherInit_ex(ctx, NULL, NULL, aes_key, aes_iv, do_encrypt); 95 | 96 | if (!EVP_CipherUpdate(ctx, out_ptr, &out_len, in, in_len)) { 97 | EVP_CIPHER_CTX_free(ctx); 98 | return -1; 99 | } 100 | 101 | out_ptr += out_len; 102 | 103 | if (!EVP_CipherFinal_ex(ctx, out_ptr, &out_final_len)) { 104 | EVP_CIPHER_CTX_free(ctx); 105 | return -1; 106 | } 107 | 108 | EVP_CIPHER_CTX_free(ctx); 109 | 110 | return (out_len + out_final_len); 111 | } 112 | -------------------------------------------------------------------------------- /test/algorithms/iaa_crypto.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #ifndef _IAA_CRYPT_H_ 4 | #define _IAA_CRYPT_H_ 5 | 6 | #define IAA_CRYPTO_MASK_KEY_SIZE (0x02) 7 | #define IAA_CRYPTO_MASK_FLUSH_CRYPTO_IN_ACCUM (0x08) 8 | #define IAA_CRYPTO_AECS_SIZE (192) 9 | #define IAA_CRYPTO_SRC2_SIZE (IAA_CRYPTO_AECS_SIZE * 2) 10 | 11 | enum _crypto_type_t { 12 | IAA_AES_GCM = 0, 13 | IAA_AES_CFB, 14 | IAA_AES_XTS 15 | }; 16 | 17 | struct iaa_crypto_aecs_t { 18 | uint32_t filter_rsvd[6]; 19 | uint8_t crypto_algorithm; 20 | uint8_t crypto_flags; 21 | uint16_t crypto_accum_sizes; 22 | uint32_t crypto_rsvd; 23 | uint32_t crypto_input_accum[6]; 24 | uint32_t crypto_output_accum[4]; 25 | uint32_t aes_key_low[4]; 26 | uint32_t aes_key_high[4]; 27 | uint32_t crypto_rsvd2[4]; 28 | uint32_t counter_iv[4]; 29 | uint32_t gcm_h[4]; 30 | uint32_t hash[4]; 31 | uint8_t complement[24]; 32 | }; 33 | 34 | int iaa_do_crypto(uint8_t *out, uint8_t *in, int in_len, uint8_t *aes_key, uint8_t *aes_iv, 35 | int key_size, enum _crypto_type_t crypto_type, int do_encrypt); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /test/algorithms/iaa_filter.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #ifndef _IAA_FILTER_H_ 4 | #define _IAA_FILTER_H_ 5 | 6 | #include 7 | 8 | #define IAA_FILTER_MAX_DEST_SIZE (2097152 * 2) 9 | #define IAA_FILTER_MAX_SRC2_SIZE (2097152) 10 | 11 | #define IAA_FILTER_AECS_SIZE (32) 12 | 13 | struct iaa_filter_flags_t { 14 | uint32_t src1_parse:2; 15 | uint32_t src1_width:5; 16 | uint32_t src2_width:5; 17 | uint32_t src2_bit_order:1; 18 | uint32_t output_width:2; 19 | uint32_t output_bit_order:1; 20 | uint32_t invert_output:1; 21 | uint32_t drop_low_bits:5; 22 | uint32_t drop_high_bits:5; 23 | uint32_t rsvd:5; 24 | }; 25 | 26 | struct iaa_filter_aecs_t { 27 | uint32_t rsvd; 28 | uint32_t rsvd2; 29 | uint32_t low_filter_param; 30 | uint32_t high_filter_param; 31 | uint32_t rsvd3; 32 | uint32_t rsvd4; 33 | uint32_t rsvd5; 34 | uint32_t rsvd6; 35 | }; 36 | 37 | uint32_t iaa_do_scan(void *dst, void *src1, void *src2, 38 | uint32_t num_inputs, uint32_t filter_flags); 39 | uint32_t iaa_do_set_membership(void *dst, void *src1, void *src2, 40 | uint32_t num_inputs, uint32_t filter_flags); 41 | uint32_t iaa_do_extract(void *dst, void *src1, void *src2, 42 | uint32_t num_inputs, uint32_t filter_flags); 43 | uint32_t iaa_do_select(void *dst, void *src1, void *src2, 44 | uint32_t num_inputs, uint32_t filter_flags); 45 | uint32_t iaa_do_rle_burst(void *dst, void *src1, void *src2, 46 | uint32_t num_inputs, uint32_t filter_flags); 47 | uint32_t iaa_do_find_unique(void *dst, void *src1, void *src2, 48 | uint32_t num_inputs, uint32_t filter_flags); 49 | uint32_t iaa_do_expand(void *dst, void *src1, void *src2, 50 | uint32_t num_inputs, uint32_t filter_flags); 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /test/algorithms/iaa_zcompress.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #ifndef _IAA_ZCOMPRESS_H_ 4 | #define _IAA_ZCOMPRESS_H_ 5 | 6 | #include 7 | 8 | #define IAA_ZCOMPRESS_MAX_DEST_SIZE (2097152 * 2) 9 | #define IAA_ZDECOMPRESS_MAX_DEST_SIZE (2097152 * 2) 10 | 11 | void iaa_zcompress16_randomize_input(void *dst, uint64_t pattern, int len); 12 | int iaa_do_zcompress8(void *dst, void *src, int src_len); 13 | int iaa_do_zdecompress8(void *dst, void *src, int src_len); 14 | int iaa_do_zcompress16(void *dst, void *src, int src_len); 15 | int iaa_do_zdecompress16(void *dst, void *src, int src_len); 16 | int iaa_do_zcompress32(void *dst, void *src, int src_len); 17 | int iaa_do_zdecompress32(void *dst, void *src, int src_len); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /test/configs/2g2q_user_1.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"dsa0", 4 | "read_buffer_limit":0, 5 | "groups":[ 6 | { 7 | "dev":"group0.0", 8 | "read_buffers_reserved":0, 9 | "use_read_buffer_limit":0, 10 | "read_buffers_allowed":8, 11 | "grouped_workqueues":[ 12 | { 13 | "dev":"wq0.0", 14 | "mode":"shared", 15 | "size":16, 16 | "group_id":0, 17 | "priority":10, 18 | "block_on_fault":1, 19 | "type":"user", 20 | "driver_name":"user", 21 | "name":"app1", 22 | "threshold":15 23 | } 24 | ], 25 | "grouped_engines":[ 26 | { 27 | "dev":"engine0.0", 28 | "group_id":0 29 | }, 30 | { 31 | "dev":"engine0.1", 32 | "group_id":0 33 | } 34 | ] 35 | }, 36 | { 37 | "dev":"group0.1", 38 | "read_buffers_reserved":0, 39 | "use_read_buffer_limit":0, 40 | "read_buffers_allowed":8, 41 | "grouped_workqueues":[ 42 | { 43 | "dev":"wq0.1", 44 | "mode":"dedicated", 45 | "size":16, 46 | "group_id":1, 47 | "priority":10, 48 | "block_on_fault":1, 49 | "type":"user", 50 | "driver_name":"user", 51 | "name":"app2", 52 | "threshold":0 53 | } 54 | ], 55 | "grouped_engines":[ 56 | { 57 | "dev":"engine0.2", 58 | "group_id":1 59 | }, 60 | { 61 | "dev":"engine0.3", 62 | "group_id":1 63 | } 64 | ] 65 | }, 66 | { 67 | "dev":"group0.2", 68 | "read_buffers_reserved":0, 69 | "use_read_buffer_limit":0, 70 | "read_buffers_allowed":8, 71 | }, 72 | { 73 | "dev":"group0.3", 74 | "read_buffers_reserved":0, 75 | "use_read_buffer_limit":0, 76 | "read_buffers_allowed":8, 77 | } 78 | ] 79 | } 80 | ] 81 | -------------------------------------------------------------------------------- /test/configs/2g2q_user_2.conf: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "dev":"iax1", 4 | "groups":[ 5 | { 6 | "dev":"group1.0", 7 | }, 8 | { 9 | "dev":"group1.1", 10 | "grouped_workqueues":[ 11 | { 12 | "dev":"wq1.1", 13 | "mode":"dedicated", 14 | "size":16, 15 | "group_id":1, 16 | "priority":10, 17 | "block_on_fault":1, 18 | "max_transfer_size":4194304, 19 | "type":"user", 20 | "name":"wq1.1", 21 | "driver_name":"user", 22 | "threshold":0, 23 | } 24 | ], 25 | "grouped_engines":[ 26 | { 27 | "dev":"engine1.1", 28 | "group_id":1 29 | } 30 | ] 31 | }, 32 | { 33 | "dev":"group1.2", 34 | "grouped_workqueues":[ 35 | { 36 | "dev":"wq1.4", 37 | "mode":"shared", 38 | "size":40, 39 | "group_id":2, 40 | "priority":10, 41 | "block_on_fault":1, 42 | "max_transfer_size":4194304, 43 | "type":"user", 44 | "name":"wq1.4", 45 | "driver_name":"user", 46 | "threshold":40, 47 | } 48 | ], 49 | "grouped_engines":[ 50 | { 51 | "dev":"engine1.3", 52 | "group_id":2 53 | } 54 | ] 55 | }, 56 | { 57 | "dev":"group1.3", 58 | } 59 | ], 60 | "ungrouped_engines":[ 61 | { 62 | "dev":"engine1.0" 63 | }, 64 | { 65 | "dev":"engine1.2" 66 | }, 67 | { 68 | "dev":"engine1.4" 69 | }, 70 | { 71 | "dev":"engine1.5" 72 | }, 73 | { 74 | "dev":"engine1.6" 75 | }, 76 | { 77 | "dev":"engine1.7" 78 | } 79 | ] 80 | } 81 | ] 82 | -------------------------------------------------------------------------------- /test/core.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define KVER_STRLEN 20 17 | 18 | struct accfg_test { 19 | unsigned int kver; 20 | int attempt; 21 | int skip; 22 | }; 23 | 24 | static unsigned int get_system_kver(void) 25 | { 26 | const char *kver = getenv("KVER"); 27 | struct utsname utsname; 28 | int a, b, c; 29 | 30 | if (!kver) { 31 | uname(&utsname); 32 | kver = utsname.release; 33 | } 34 | 35 | if (sscanf(kver, "%d.%d.%d", &a, &b, &c) != 3) 36 | return LINUX_VERSION_CODE; 37 | 38 | return KERNEL_VERSION(a,b,c); 39 | } 40 | 41 | struct accfg_test *accfg_test_new(unsigned int kver) 42 | { 43 | struct accfg_test *test = calloc(1, sizeof(*test)); 44 | 45 | if (!test) 46 | return NULL; 47 | 48 | if (!kver) 49 | test->kver = get_system_kver(); 50 | else 51 | test->kver = kver; 52 | 53 | return test; 54 | } 55 | 56 | int accfg_test_result(struct accfg_test *test, int rc) 57 | { 58 | if (accfg_test_get_skipped(test)) 59 | fprintf(stderr, "attempted: %d skipped: %d\n", 60 | accfg_test_get_attempted(test), 61 | accfg_test_get_skipped(test)); 62 | if (rc && rc != EXIT_SKIP) 63 | return rc; 64 | if (accfg_test_get_skipped(test) >= accfg_test_get_attempted(test)) 65 | return EXIT_SKIP; 66 | /* return success if no failures and at least one test not skipped */ 67 | return 0; 68 | } 69 | 70 | static char *kver_str(char *buf, unsigned int kver) 71 | { 72 | snprintf(buf, KVER_STRLEN, "%d.%d.%d", (kver >> 16) & 0xffff, 73 | (kver >> 8) & 0xff, kver & 0xff); 74 | return buf; 75 | } 76 | 77 | int __accfg_test_attempt(struct accfg_test *test, unsigned int kver, 78 | const char *caller, int line) 79 | { 80 | char requires[KVER_STRLEN], current[KVER_STRLEN]; 81 | 82 | test->attempt++; 83 | if (kver <= test->kver) 84 | return 1; 85 | fprintf(stderr, "%s: skip %s:%d requires: %s current: %s\n", 86 | __func__, caller, line, kver_str(requires, kver), 87 | kver_str(current, test->kver)); 88 | test->skip++; 89 | return 0; 90 | } 91 | 92 | void __accfg_test_skip(struct accfg_test *test, const char *caller, int line) 93 | { 94 | test->skip++; 95 | test->attempt = test->skip; 96 | fprintf(stderr, "%s: explicit skip %s:%d\n", __func__, caller, line); 97 | } 98 | 99 | int accfg_test_get_attempted(struct accfg_test *test) 100 | { 101 | return test->attempt; 102 | } 103 | 104 | int accfg_test_get_skipped(struct accfg_test *test) 105 | { 106 | return test->skip; 107 | } 108 | -------------------------------------------------------------------------------- /test/crc16_t10_lookup.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ 3 | static const unsigned short t10_dif_crc_table[256] = { 4 | 0x0000, 0x8BB7, 0x9CD9, 0x176E, 0xB205, 0x39B2, 0x2EDC, 0xA56B, 5 | 0xEFBD, 0x640A, 0x7364, 0xF8D3, 0x5DB8, 0xD60F, 0xC161, 0x4AD6, 6 | 0x54CD, 0xDF7A, 0xC814, 0x43A3, 0xE6C8, 0x6D7F, 0x7A11, 0xF1A6, 7 | 0xBB70, 0x30C7, 0x27A9, 0xAC1E, 0x0975, 0x82C2, 0x95AC, 0x1E1B, 8 | 0xA99A, 0x222D, 0x3543, 0xBEF4, 0x1B9F, 0x9028, 0x8746, 0x0CF1, 9 | 0x4627, 0xCD90, 0xDAFE, 0x5149, 0xF422, 0x7F95, 0x68FB, 0xE34C, 10 | 0xFD57, 0x76E0, 0x618E, 0xEA39, 0x4F52, 0xC4E5, 0xD38B, 0x583C, 11 | 0x12EA, 0x995D, 0x8E33, 0x0584, 0xA0EF, 0x2B58, 0x3C36, 0xB781, 12 | 0xD883, 0x5334, 0x445A, 0xCFED, 0x6A86, 0xE131, 0xF65F, 0x7DE8, 13 | 0x373E, 0xBC89, 0xABE7, 0x2050, 0x853B, 0x0E8C, 0x19E2, 0x9255, 14 | 0x8C4E, 0x07F9, 0x1097, 0x9B20, 0x3E4B, 0xB5FC, 0xA292, 0x2925, 15 | 0x63F3, 0xE844, 0xFF2A, 0x749D, 0xD1F6, 0x5A41, 0x4D2F, 0xC698, 16 | 0x7119, 0xFAAE, 0xEDC0, 0x6677, 0xC31C, 0x48AB, 0x5FC5, 0xD472, 17 | 0x9EA4, 0x1513, 0x027D, 0x89CA, 0x2CA1, 0xA716, 0xB078, 0x3BCF, 18 | 0x25D4, 0xAE63, 0xB90D, 0x32BA, 0x97D1, 0x1C66, 0x0B08, 0x80BF, 19 | 0xCA69, 0x41DE, 0x56B0, 0xDD07, 0x786C, 0xF3DB, 0xE4B5, 0x6F02, 20 | 0x3AB1, 0xB106, 0xA668, 0x2DDF, 0x88B4, 0x0303, 0x146D, 0x9FDA, 21 | 0xD50C, 0x5EBB, 0x49D5, 0xC262, 0x6709, 0xECBE, 0xFBD0, 0x7067, 22 | 0x6E7C, 0xE5CB, 0xF2A5, 0x7912, 0xDC79, 0x57CE, 0x40A0, 0xCB17, 23 | 0x81C1, 0x0A76, 0x1D18, 0x96AF, 0x33C4, 0xB873, 0xAF1D, 0x24AA, 24 | 0x932B, 0x189C, 0x0FF2, 0x8445, 0x212E, 0xAA99, 0xBDF7, 0x3640, 25 | 0x7C96, 0xF721, 0xE04F, 0x6BF8, 0xCE93, 0x4524, 0x524A, 0xD9FD, 26 | 0xC7E6, 0x4C51, 0x5B3F, 0xD088, 0x75E3, 0xFE54, 0xE93A, 0x628D, 27 | 0x285B, 0xA3EC, 0xB482, 0x3F35, 0x9A5E, 0x11E9, 0x0687, 0x8D30, 28 | 0xE232, 0x6985, 0x7EEB, 0xF55C, 0x5037, 0xDB80, 0xCCEE, 0x4759, 29 | 0x0D8F, 0x8638, 0x9156, 0x1AE1, 0xBF8A, 0x343D, 0x2353, 0xA8E4, 30 | 0xB6FF, 0x3D48, 0x2A26, 0xA191, 0x04FA, 0x8F4D, 0x9823, 0x1394, 31 | 0x5942, 0xD2F5, 0xC59B, 0x4E2C, 0xEB47, 0x60F0, 0x779E, 0xFC29, 32 | 0x4BA8, 0xC01F, 0xD771, 0x5CC6, 0xF9AD, 0x721A, 0x6574, 0xEEC3, 33 | 0xA415, 0x2FA2, 0x38CC, 0xB37B, 0x1610, 0x9DA7, 0x8AC9, 0x017E, 34 | 0x1F65, 0x94D2, 0x83BC, 0x080B, 0xAD60, 0x26D7, 0x31B9, 0xBA0E, 35 | 0xF0D8, 0x7B6F, 0x6C01, 0xE7B6, 0x42DD, 0xC96A, 0xDE04, 0x55B3 36 | }; 37 | -------------------------------------------------------------------------------- /test/dsa_memmove.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -Ex 2 | # SPDX-License-Identifier: GPL-2.0 3 | # Copyright(c) 2019 Intel Corporation. All rights reserved. 4 | 5 | rc=77 6 | 7 | . ./common 8 | 9 | DSATEST=./dsa_test 10 | CONFIG=./configs/2g2q_user_1.conf 11 | DSA=dsa0 12 | WQ0=wq0.0 13 | WQ1=wq0.1 14 | 15 | trap 'err $LINENO' ERR 16 | 17 | [ ! -f "$DSATEST" ] && echo "fail: $LINENO" && exit 1 18 | 19 | check_min_kver "5.6" || do_skip "kernel does not support idxd" 20 | 21 | start_dsa() 22 | { 23 | configurable=$(cat /sys/bus/dsa/devices/$DSA/configurable) 24 | if [ "$configurable" ]; then 25 | "$ACCFG" load-config -c "$CONFIG" 26 | fi 27 | "$ACCFG" enable-device "$DSA" 28 | } 29 | 30 | stop_dsa() 31 | { 32 | "$ACCFG" disable-device "$DSA" 33 | } 34 | 35 | enable_wqs() 36 | { 37 | "$ACCFG" enable-wq "$DSA"/"$WQ0" 38 | "$ACCFG" enable-wq "$DSA"/"$WQ1" 39 | } 40 | 41 | disable_wqs() 42 | { 43 | "$ACCFG" disable-wq "$DSA"/"$WQ0" 44 | "$ACCFG" disable-wq "$DSA"/"$WQ1" 45 | } 46 | 47 | test_memmove() 48 | { 49 | echo "Performing shared WQ MEMMOVE testing" 50 | echo "Testing $SIZE_4K bytes" 51 | "$DSATEST" -w 1 -l "$SIZE_4K" -o0x3 -t200 52 | echo "Testing $SIZE_64K bytes" 53 | "$DSATEST" -w 1 -l "$SIZE_64K" -o0x3 -t200 54 | echo "Testing $SIZE_1M bytes" 55 | "$DSATEST" -w 1 -l "$SIZE_1M" -o0x3 -t200 56 | echo "Testing $SIZE_2M bytes" 57 | "$DSATEST" -w 1 -l "$SIZE_2M" -o0x3 -t200 58 | 59 | echo "Performing dedicated WQ MEMMOVE testing" 60 | echo "Testing $SIZE_4K bytes" 61 | "$DSATEST" -w 0 -l "$SIZE_4K" -o0x3 -t200 62 | echo "Testing $SIZE_64K bytes" 63 | "$DSATEST" -w 0 -l "$SIZE_64K" -o0x3 -t200 64 | echo "Testing $SIZE_1M bytes" 65 | "$DSATEST" -w 0 -l "$SIZE_1M" -o0x3 -t200 66 | echo "Testing $SIZE_2M bytes" 67 | "$DSATEST" -w 0 -l "$SIZE_2M" -o0x3 -t200 68 | } 69 | 70 | test_memmove_batch() 71 | { 72 | echo "Performing shared WQ batched MEMMOVE testing" 73 | echo "Testing $SIZE_4K bytes" 74 | "$DSATEST" -w 1 -l "$SIZE_4K" -o0x1 -b0x3 -c16 -t2000 75 | 76 | echo "Performing dedicated WQ batched MEMMOVE testing" 77 | echo "Testing $SIZE_4K bytes" 78 | "$DSATEST" -w 0 -l "$SIZE_4K" -o0x1 -b0x3 -c16 -t2000 79 | } 80 | 81 | _cleanup 82 | start_dsa 83 | enable_wqs 84 | rc=1 85 | 86 | test_memmove 87 | test_memmove_batch 88 | 89 | disable_wqs 90 | stop_dsa 91 | _cleanup 92 | exit 0 93 | -------------------------------------------------------------------------------- /test/iaa.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2019 Intel Corporation. All rights reserved. */ 3 | #ifndef __TEST_IAA_H__ 4 | #define __TEST_IAA_H__ 5 | #include 6 | #include 7 | #include "accel_test.h" 8 | #include "accfg_test.h" 9 | 10 | int init_task(struct task *tsk, int tflags, int opcode, unsigned long src1_xfer_size); 11 | 12 | int iaa_noop_multi_task_nodes(struct acctest_context *ctx); 13 | int iaa_crc64_multi_task_nodes(struct acctest_context *ctx); 14 | int iaa_zcompress8_multi_task_nodes(struct acctest_context *ctx); 15 | int iaa_zdecompress8_multi_task_nodes(struct acctest_context *ctx); 16 | int iaa_zcompress16_multi_task_nodes(struct acctest_context *ctx); 17 | int iaa_zdecompress16_multi_task_nodes(struct acctest_context *ctx); 18 | int iaa_zcompress32_multi_task_nodes(struct acctest_context *ctx); 19 | int iaa_zdecompress32_multi_task_nodes(struct acctest_context *ctx); 20 | int iaa_compress_multi_task_nodes(struct acctest_context *ctx); 21 | int iaa_decompress_multi_task_nodes(struct acctest_context *ctx); 22 | int iaa_scan_multi_task_nodes(struct acctest_context *ctx); 23 | int iaa_set_membership_multi_task_nodes(struct acctest_context *ctx); 24 | int iaa_extract_multi_task_nodes(struct acctest_context *ctx); 25 | int iaa_select_multi_task_nodes(struct acctest_context *ctx); 26 | int iaa_rle_burst_multi_task_nodes(struct acctest_context *ctx); 27 | int iaa_find_unique_multi_task_nodes(struct acctest_context *ctx); 28 | int iaa_expand_multi_task_nodes(struct acctest_context *ctx); 29 | int iaa_transl_fetch_multi_task_nodes(struct acctest_context *ctx); 30 | int iaa_encrypto_multi_task_nodes(struct acctest_context *ctx); 31 | int iaa_decrypto_multi_task_nodes(struct acctest_context *ctx); 32 | 33 | void iaa_prep_noop(struct task *tsk); 34 | void iaa_prep_crc64(struct task *tsk); 35 | void iaa_prep_zcompress8(struct task *tsk); 36 | void iaa_prep_zdecompress8(struct task *tsk); 37 | void iaa_prep_zcompress16(struct task *tsk); 38 | void iaa_prep_zdecompress16(struct task *tsk); 39 | void iaa_prep_zcompress32(struct task *tsk); 40 | void iaa_prep_zdecompress32(struct task *tsk); 41 | void iaa_prep_compress(struct task *tsk); 42 | void iaa_prep_decompress(struct task *tsk); 43 | void iaa_prep_scan(struct task *tsk); 44 | void iaa_prep_set_membership(struct task *tsk); 45 | void iaa_prep_extract(struct task *tsk); 46 | void iaa_prep_select(struct task *tsk); 47 | void iaa_prep_rle_burst(struct task *tsk); 48 | void iaa_prep_find_unique(struct task *tsk); 49 | void iaa_prep_expand(struct task *tsk); 50 | void iaa_prep_transl_fetch(struct task *tsk); 51 | void iaa_prep_encrypto(struct task *tsk); 52 | void iaa_prep_decrypto(struct task *tsk); 53 | 54 | int iaa_task_result_verify(struct task *tsk, int mismatch_expected); 55 | int iaa_task_result_verify_task_nodes(struct acctest_context *ctx, int mismatch_expected); 56 | int task_result_verify_crc64(struct task *tsk, int mismatch_expected); 57 | int task_result_verify_zcompress8(struct task *tsk, int mismatch_expected); 58 | int task_result_verify_zdecompress8(struct task *tsk, int mismatch_expected); 59 | int task_result_verify_zcompress16(struct task *tsk, int mismatch_expected); 60 | int task_result_verify_zdecompress16(struct task *tsk, int mismatch_expected); 61 | int task_result_verify_zcompress32(struct task *tsk, int mismatch_expected); 62 | int task_result_verify_zdecompress32(struct task *tsk, int mismatch_expected); 63 | int task_result_verify_compress(struct task *tsk, int mismatch_expected); 64 | int task_result_verify_decompress(struct task *tsk, int mismatch_expected); 65 | int task_result_verify_scan(struct task *tsk, int mismatch_expected); 66 | int task_result_verify_set_membership(struct task *tsk, int mismatch_expected); 67 | int task_result_verify_extract(struct task *tsk, int mismatch_expected); 68 | int task_result_verify_select(struct task *tsk, int mismatch_expected); 69 | int task_result_verify_rle_burst(struct task *tsk, int mismatch_expected); 70 | int task_result_verify_find_unique(struct task *tsk, int mismatch_expected); 71 | int task_result_verify_expand(struct task *tsk, int mismatch_expected); 72 | int task_result_verify_transl_fetch(struct task *tsk, int mismatch_expected); 73 | int task_result_verify_encrypto(struct task *tsk, int mismatch_expected); 74 | int task_result_verify_decrypto(struct task *tsk, int mismatch_expected); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /test_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | batch=0,0,0,0 4 | batch_cpf=1,0,0,0 5 | success=0,0,0,0 6 | page_fault=1,0,0,0 7 | cp_error_log=0,1,0,0 8 | cp_wr_fail=0,1,1,0 9 | fence=0,0,0,1 10 | page_fault_cp_error_log=1,1,0,0 11 | page_fault_cp_write_fail=1,1,1,0 12 | da_page_fault=0,0,1,2 13 | da_page_bc_fault=1,0,1,2 14 | 15 | run_dsa_test() { 16 | 17 | echo $1 18 | echo $2 19 | ./test/.libs/dsa_test -o1 -b3 -w0 -f0x8 -c$1 -e$2 20 | } 21 | 22 | #1a-1.0 23 | #eval declare -a param=('"'$batch':'$success':'$cp_error_log'"'\ #1a 24 | # '"'$batch':'$success':'$cp_wr_fail'"'\ #1a 25 | # '"'$batch':'$cp_error_log':'$fence'"'\ #1b 26 | # '"'$batch':'$page_fault':'$cp_error_log'"'\ #2a 27 | # '"'$batch':'$page_fault':'$cp_error_log':'$fence'"'\ #2b 28 | # '"'$batch':'$success':'$page_fault_cp_error_log':'$fence'"'\ #3.0 29 | # '"'$batch':'$success':'$page_fault_cp_write_fail':'$fence'"'\ #3.1 30 | # '"'$batch_cpf':'$success':'$cp_error_log'"'\ #4a.0 31 | # '"'$batch_cpf':'$success':'$cp_wr_fail'"') #4a.1 32 | # '"'$batch_cpf':'$success':'$success'"') 33 | # '"'$da_page_fault':'$success':'$success':'$success'"'\ #6a 34 | # '"'$da_page_bc_fault':'$success':'$success':'$success'"'\ #6b 35 | # '"'$da_page_fault':'$success':'$cp_error_log':'$success'"'\ #6c 36 | # '"'$da_page_fault':'$page_fault':'$cp_error_log':'$success'"'\ #6d.0 37 | # '"'$da_page_fault':'$page_fault':'$cp_wr_fail':'$success'"') #6d.1 38 | 39 | eval declare -a param=('"'$batch':'$success':'$cp_error_log'"' #1a.0 40 | '"'$batch':'$success':'$cp_wr_fail'"' #1a.1 41 | '"'$batch':'$success':'$cp_error_log':'$fence'"' #1b 42 | '"'$batch':'$page_fault':'$cp_error_log'"' #2a 43 | '"'$batch':'$page_fault':'$cp_error_log':'$fence'"' #2b 44 | '"'$batch':'$success':'$page_fault_cp_error_log':'$fence'"' #3.0 45 | '"'$batch':'$success':'$page_fault_cp_write_fail':'$fence'"' #3.1 46 | '"'$batch_cpf':'$success':'$cp_error_log'"' #4a.0 47 | '"'$batch_cpf':'$success':'$cp_wr_fail'"' #4a.1 48 | '"'$batch_cpf':'$success':'$success'"' #4b 49 | '"'$da_page_fault':'$success':'$success':'$success'"' #6a 50 | '"'$da_page_bc_fault':'$success':'$success':'$success'"' #6b 51 | '"'$da_page_fault':'$success':'$cp_error_log':'$success'"' #6c.0 52 | '"'$da_page_fault':'$success':'$cp_wr_fail':'$success'"' #6c.1 53 | '"'$da_page_fault':'$page_fault':'$cp_error_log':'$success'"' #6d.0 54 | '"'$da_page_fault':'$page_fault':'$cp_wr_fail':'$success'"') #6d.1 55 | 56 | eval declare -a casename=(1a.0 57 | 1a.1 58 | 1b 59 | 2a 60 | 2b 61 | 3.0 62 | 3.1 63 | 4a.0 64 | 4a.1 65 | 4b 66 | 6a 67 | 6b 68 | 6c.0 69 | 6c.1 70 | 6d.0 71 | 6d.1) 72 | 73 | run_all() { 74 | l=${#param[@]} 75 | for ((i=0;i 5 | #include 6 | 7 | char *prefix_filename(const char *pfx, const char *arg) 8 | { 9 | struct strbuf path = STRBUF_INIT; 10 | 11 | if (pfx && !is_absolute_path(arg)) 12 | strbuf_add(&path, pfx, strlen(pfx)); 13 | 14 | strbuf_addstr(&path, arg); 15 | return strbuf_detach(&path, NULL); 16 | } 17 | 18 | void fix_filename(const char *prefix, const char **file) 19 | { 20 | if (!file || !*file || !prefix || is_absolute_path(*file) 21 | || !strcmp("-", *file)) 22 | return; 23 | *file = prefix_filename(prefix, *file); 24 | } 25 | -------------------------------------------------------------------------------- /util/bitmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2019 Intel Corporation. All rights reserved. 3 | * Copyright(c) 2009 Akinobu Mita. All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | */ 14 | 15 | /* originally copied from the Linux kernel bitmap implementation */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | uint64_t *bitmap_alloc(uint64_t nbits) 26 | { 27 | return calloc(BITS_TO_LONGS(nbits), sizeof(uint64_t)); 28 | } 29 | 30 | void bitmap_set(uint64_t *map, unsigned int start, int len) 31 | { 32 | uint64_t *p = map + BIT_WORD(start); 33 | const unsigned int size = start + len; 34 | int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); 35 | uint64_t mask_to_set = BITMAP_FIRST_WORD_MASK(start); 36 | 37 | while (len - bits_to_set >= 0) { 38 | *p |= mask_to_set; 39 | len -= bits_to_set; 40 | bits_to_set = BITS_PER_LONG; 41 | mask_to_set = ~0UL; 42 | p++; 43 | } 44 | if (len) { 45 | mask_to_set &= BITMAP_LAST_WORD_MASK(size); 46 | *p |= mask_to_set; 47 | } 48 | } 49 | 50 | void bitmap_clear(uint64_t *map, unsigned int start, int len) 51 | { 52 | uint64_t *p = map + BIT_WORD(start); 53 | const unsigned int size = start + len; 54 | int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); 55 | uint64_t mask_to_clear = BITMAP_FIRST_WORD_MASK(start); 56 | 57 | while (len - bits_to_clear >= 0) { 58 | *p &= ~mask_to_clear; 59 | len -= bits_to_clear; 60 | bits_to_clear = BITS_PER_LONG; 61 | mask_to_clear = ~0UL; 62 | p++; 63 | } 64 | if (len) { 65 | mask_to_clear &= BITMAP_LAST_WORD_MASK(size); 66 | *p &= ~mask_to_clear; 67 | } 68 | } 69 | 70 | /** 71 | * test_bit - Determine whether a bit is set 72 | * @nr: bit number to test 73 | * @addr: Address to start counting from 74 | */ 75 | int test_bit(unsigned int nr, const volatile uint64_t *addr) 76 | { 77 | return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); 78 | } 79 | 80 | /* 81 | * This is a common helper function for find_next_bit and 82 | * find_next_zero_bit. The difference is the "invert" argument, which 83 | * is XORed with each fetched word before searching it for one bits. 84 | */ 85 | static uint64_t _find_next_bit(const uint64_t *addr, 86 | uint64_t nbits, uint64_t start, uint64_t invert) 87 | { 88 | uint64_t tmp; 89 | 90 | if (!nbits || start >= nbits) 91 | return nbits; 92 | 93 | tmp = addr[start / BITS_PER_LONG] ^ invert; 94 | 95 | /* Handle 1st word. */ 96 | tmp &= BITMAP_FIRST_WORD_MASK(start); 97 | start = round_down(start, BITS_PER_LONG); 98 | 99 | while (!tmp) { 100 | start += BITS_PER_LONG; 101 | if (start >= nbits) 102 | return nbits; 103 | 104 | tmp = addr[start / BITS_PER_LONG] ^ invert; 105 | } 106 | 107 | return min(start + __builtin_ffsl(tmp), nbits); 108 | } 109 | 110 | /* 111 | * Find the next set bit in a memory region. 112 | */ 113 | uint64_t find_next_bit(const uint64_t *addr, uint64_t size, 114 | uint64_t offset) 115 | { 116 | return _find_next_bit(addr, size, offset, 0UL); 117 | } 118 | 119 | uint64_t find_next_zero_bit(const uint64_t *addr, uint64_t size, 120 | uint64_t offset) 121 | { 122 | return _find_next_bit(addr, size, offset, ~0UL); 123 | } 124 | 125 | int bitmap_full(const uint64_t *src, unsigned int nbits) 126 | { 127 | if (small_const_nbits(nbits)) 128 | return ! (~(*src) & BITMAP_LAST_WORD_MASK(nbits)); 129 | 130 | return find_next_zero_bit(src, nbits, 0UL) == nbits; 131 | } 132 | -------------------------------------------------------------------------------- /util/bitmap.h: -------------------------------------------------------------------------------- 1 | 2 | /* SPDX-License-Identifier: GPL-2.0 */ 3 | /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ 4 | #ifndef _ACCFG_BITMAP_H_ 5 | #define _ACCFG_BITMAP_H_ 6 | 7 | #include 8 | #include 9 | 10 | #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) 11 | 12 | #define BIT(nr) (1UL << (nr)) 13 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) 14 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) 15 | #define BITS_PER_BYTE 8 16 | #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) 17 | 18 | #define BITMAP_FIRST_WORD_MASK(start) (~0UL << ((start) & (BITS_PER_LONG - 1))) 19 | #define BITMAP_LAST_WORD_MASK(nbits) (~0UL >> (-(nbits) & (BITS_PER_LONG - 1))) 20 | 21 | #define small_const_nbits(nbits) \ 22 | (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) 23 | 24 | uint64_t *bitmap_alloc(uint64_t nbits); 25 | void bitmap_set(uint64_t *map, unsigned int start, int len); 26 | void bitmap_clear(uint64_t *map, unsigned int start, int len); 27 | int test_bit(unsigned int nr, const volatile uint64_t *addr); 28 | uint64_t find_next_bit(const uint64_t *addr, uint64_t size, 29 | uint64_t offset); 30 | uint64_t find_next_zero_bit(const uint64_t *addr, uint64_t size, 31 | uint64_t offset); 32 | int bitmap_full(const uint64_t *src, unsigned int nbits); 33 | 34 | 35 | #endif /* _ACCFG_BITMAP_H_ */ 36 | -------------------------------------------------------------------------------- /util/filter.c: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: GPL-2.0 2 | // Copyright(c) 2015-2019 Intel Corporation. All rights reserved. 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int match_device(struct accfg_device *dev, struct accfg_json_container *jc) 17 | { 18 | return !strcmp(accfg_device_get_devname(dev), jc->device_name); 19 | } 20 | 21 | int scan_device_type_id(const char *name, char *dev_type, 22 | unsigned int *dev_id) 23 | { 24 | char type[MAX_DEV_LEN]; 25 | unsigned int id; 26 | 27 | if (sscanf(name, "%[a-z]%u", type, &id) != 2) 28 | return -EINVAL; 29 | 30 | if (dev_type) 31 | strcpy(dev_type, type); 32 | 33 | if (dev_id) 34 | *dev_id = id; 35 | 36 | return 0; 37 | } 38 | 39 | int scan_parent_child_names(const char *name, char *parent_name, 40 | char *child_name) 41 | { 42 | char p_name[MAX_DEV_LEN], c_name[MAX_DEV_LEN]; 43 | 44 | if (sscanf(name, "%[^/]/%s", p_name, c_name) != 2) 45 | return -EINVAL; 46 | 47 | if (parent_name) 48 | strcpy(parent_name, p_name); 49 | 50 | if (child_name) 51 | strcpy(child_name, c_name); 52 | 53 | return 0; 54 | } 55 | 56 | int scan_parent_child_ids(const char *name, unsigned int *parent_id, 57 | unsigned int *child_id) 58 | { 59 | unsigned int p_id, c_id; 60 | 61 | if (sscanf(name, "%*[a-z]%u.%u", &p_id, &c_id) != 2) 62 | return -EINVAL; 63 | 64 | if (parent_id) 65 | *parent_id = p_id; 66 | 67 | if (child_id) 68 | *child_id = c_id; 69 | 70 | return 0; 71 | } 72 | 73 | int parse_device_name(struct accfg_ctx *ctx, const char *name, 74 | struct accfg_device **device) 75 | { 76 | struct accfg_device *dev; 77 | char dev_type[MAX_DEV_LEN]; 78 | int rc; 79 | 80 | rc = scan_device_type_id(name, dev_type, NULL); 81 | if (rc || !accfg_device_type_validate(dev_type)) 82 | return -EINVAL; 83 | 84 | accfg_device_foreach(ctx, dev) 85 | if (!strcmp(name, accfg_device_get_devname(dev))) 86 | break; 87 | 88 | if (!dev) { 89 | fprintf(stderr, "%s device not found\n", name); 90 | return -EINVAL; 91 | } 92 | 93 | if (device) 94 | *device = dev; 95 | 96 | return 0; 97 | } 98 | 99 | int parse_wq_name(struct accfg_ctx *ctx, const char *name, 100 | struct accfg_device **device, struct accfg_wq **wq) 101 | { 102 | struct accfg_device *dev; 103 | struct accfg_wq *q; 104 | char dev_name[MAX_DEV_LEN], wq_name[MAX_DEV_LEN]; 105 | int rc; 106 | 107 | rc = scan_parent_child_names(name, dev_name, wq_name); 108 | if (rc) 109 | return rc; 110 | 111 | rc = parse_device_name(ctx, dev_name, &dev); 112 | if (rc) 113 | return rc; 114 | 115 | accfg_wq_foreach(dev, q) 116 | if (!strcmp(wq_name, accfg_wq_get_devname(q))) 117 | break; 118 | 119 | if (!q) { 120 | fprintf(stderr, "%s workqueue not found\n", name); 121 | return -EINVAL; 122 | } 123 | 124 | if (device) 125 | *device = dev; 126 | 127 | if (wq) 128 | *wq = q; 129 | 130 | return 0; 131 | } 132 | 133 | int parse_group_name(struct accfg_ctx *ctx, const char *name, 134 | struct accfg_device **device, struct accfg_group **group) 135 | { 136 | struct accfg_device *dev; 137 | struct accfg_group *g; 138 | char dev_name[MAX_DEV_LEN], group_name[MAX_DEV_LEN]; 139 | int rc; 140 | 141 | rc = scan_parent_child_names(name, dev_name, group_name); 142 | if (rc) 143 | return rc; 144 | 145 | rc = parse_device_name(ctx, dev_name, &dev); 146 | if (rc) 147 | return rc; 148 | 149 | accfg_group_foreach(dev, g) 150 | if (!strcmp(group_name, accfg_group_get_devname(g))) 151 | break; 152 | 153 | if (!g) { 154 | fprintf(stderr, "%s group not found\n", name); 155 | return -EINVAL; 156 | } 157 | 158 | if (device) 159 | *device = dev; 160 | 161 | if (group) 162 | *group = g; 163 | 164 | return 0; 165 | } 166 | 167 | int parse_engine_name(struct accfg_ctx *ctx, const char *name, 168 | struct accfg_device **device, struct accfg_engine **engine) 169 | { 170 | struct accfg_device *dev; 171 | struct accfg_engine *e; 172 | char dev_name[MAX_DEV_LEN], engine_name[MAX_DEV_LEN]; 173 | int rc; 174 | 175 | rc = scan_parent_child_names(name, dev_name, engine_name); 176 | if (rc) 177 | return rc; 178 | 179 | rc = parse_device_name(ctx, dev_name, &dev); 180 | if (rc) 181 | return rc; 182 | 183 | accfg_engine_foreach(dev, e) 184 | if (!strcmp(engine_name, accfg_engine_get_devname(e))) 185 | break; 186 | 187 | if (!e) { 188 | fprintf(stderr, "%s engine not found\n", name); 189 | return -EINVAL; 190 | } 191 | 192 | if (device) 193 | *device = dev; 194 | 195 | if (engine) 196 | *engine = e; 197 | 198 | return 0; 199 | } 200 | 201 | int util_filter_walk(struct accfg_ctx *ctx, struct util_filter_ctx *fctx, 202 | struct util_filter_params *param) 203 | { 204 | struct accfg_device *device, *dev = NULL; 205 | struct accfg_wq *wq, *q = NULL; 206 | struct accfg_engine *engine, *e = NULL; 207 | struct accfg_group *group, *g = NULL; 208 | bool b, found = false; 209 | int rc = 0; 210 | 211 | if (param->device) 212 | rc = parse_device_name(ctx, param->device, &dev); 213 | else if (param->group) 214 | rc = parse_group_name(ctx, param->group, &dev, &g); 215 | else if (param->wq) 216 | rc = parse_wq_name(ctx, param->wq, &dev, &q); 217 | else if (param->engine) 218 | rc = parse_engine_name(ctx, param->engine, &dev, &e); 219 | else 220 | found = true; 221 | 222 | if (rc) 223 | return rc; 224 | 225 | accfg_device_foreach(ctx, device) { 226 | if (dev && dev != device) 227 | continue; 228 | 229 | if (!fctx->filter_device(device, fctx)) 230 | continue; 231 | 232 | if (param->device) 233 | found = true; 234 | 235 | accfg_group_foreach(device, group) { 236 | if (g && g != group) 237 | continue; 238 | b = fctx->filter_group(group, fctx); 239 | if (g) { 240 | found = b; 241 | break; 242 | } 243 | } 244 | 245 | accfg_wq_foreach(device, wq) { 246 | if (q && q != wq) 247 | continue; 248 | b = fctx->filter_wq(wq, fctx); 249 | if (q) { 250 | found = b; 251 | break; 252 | } 253 | } 254 | 255 | accfg_engine_foreach(device, engine) { 256 | if (e && e != engine) 257 | continue; 258 | b = fctx->filter_engine(engine, fctx); 259 | if (e) { 260 | found = b; 261 | break; 262 | } 263 | } 264 | 265 | if (dev) 266 | break; 267 | } 268 | 269 | if (!found) { 270 | fprintf(stderr, "No matching device found\n"); 271 | return -EINVAL; 272 | } 273 | 274 | return 0; 275 | } 276 | -------------------------------------------------------------------------------- /util/filter.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ 3 | #ifndef _UTIL_FILTER_H_ 4 | #define _UTIL_FILTER_H_ 5 | #include 6 | #include 7 | #include 8 | 9 | struct accfg_device; 10 | struct accfg_group; 11 | struct accfg_wq; 12 | struct accfg_engine; 13 | struct json_object; 14 | 15 | /* json object hierarchy for device */ 16 | struct accfg_json_container { 17 | /* array of json group */ 18 | struct json_object *jgroups; 19 | /* each json group */ 20 | struct json_object *jgroup; 21 | /* array to track group with assigned wq/engine */ 22 | struct json_object **jgroup_assigned; 23 | /* array for assigned wqs in group */ 24 | struct json_object **jwq_group; 25 | /* array for unassigend wqs in group */ 26 | struct json_object *jwq_ungroup; 27 | /* array for assigned engines in group */ 28 | struct json_object **jengine_group; 29 | /* array for unassigned engines in group */ 30 | struct json_object *jengine_ungroup; 31 | /* store group_id when a jgroup is created */ 32 | int *jgroup_id; 33 | /* device_id bonded with this container */ 34 | int device_id; 35 | /* device name bonded with this container */ 36 | const char *device_name; 37 | /* list node to represent each container on linked list */ 38 | struct list_node list; 39 | }; 40 | 41 | /* json object device for the util_filter_walk() by cmd_list() and cmd_config() */ 42 | struct list_filter_arg { 43 | /* json object for device array */ 44 | struct json_object *jdevices; 45 | /* json object for each device */ 46 | struct json_object *jdevice; 47 | /* linked list to add accfg_json_container for each device */ 48 | struct list_head jdev_list; 49 | /* linked list node for each list_filter_arg */ 50 | struct list_node list; 51 | /* flags to indicate command options */ 52 | uint64_t flags; 53 | /* track device number during walk-through */ 54 | int dev_num; 55 | /* track group_num during walk-through */ 56 | int group_num; 57 | 58 | 59 | }; 60 | 61 | /* 62 | * struct util_filter_ctx - control and callbacks for util_filter_walk() 63 | * ->filter_device() and ->filter_group() return bool because the 64 | * child-object filter routines can not be called if the parent context 65 | * is not established. ->filter_wq() and ->filter_engine() are leaf 66 | * objects, so no child dependencies to check. 67 | */ 68 | struct util_filter_ctx { 69 | bool (*filter_device)(struct accfg_device *device, struct util_filter_ctx *ctx); 70 | bool (*filter_group)(struct accfg_group *group, struct util_filter_ctx *ctx); 71 | bool (*filter_wq)(struct accfg_wq *wq, 72 | struct util_filter_ctx *ctx); 73 | bool (*filter_engine)(struct accfg_engine *engine, 74 | struct util_filter_ctx *ctx); 75 | union { 76 | void *arg; 77 | struct list_filter_arg *list; 78 | }; 79 | }; 80 | 81 | struct util_filter_params { 82 | const char *device; 83 | const char *group; 84 | const char *wq; 85 | const char *engine; 86 | }; 87 | 88 | struct accfg_ctx; 89 | 90 | int scan_device_type_id(const char *name, char *dev_type, 91 | unsigned int *dev_id); 92 | int scan_parent_child_names(const char *name, char *parent_name, 93 | char *child_name); 94 | int scan_parent_child_ids(const char *name, unsigned int *parent_id, 95 | unsigned int *child_id); 96 | int parse_device_name(struct accfg_ctx *ctx, const char *name, 97 | struct accfg_device **device); 98 | int parse_wq_name(struct accfg_ctx *ctx, const char *name, 99 | struct accfg_device **device, struct accfg_wq **wq); 100 | int parse_group_name(struct accfg_ctx *ctx, const char *name, 101 | struct accfg_device **device, struct accfg_group **group); 102 | int parse_engine_name(struct accfg_ctx *ctx, const char *name, 103 | struct accfg_device **device, struct accfg_engine **engine); 104 | int util_filter_walk(struct accfg_ctx *ctx, struct util_filter_ctx *fctx, 105 | struct util_filter_params *param); 106 | int match_device(struct accfg_device *device, struct accfg_json_container *jc); 107 | #endif 108 | -------------------------------------------------------------------------------- /util/help.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2015-2019 Intel Corporation. All rights reserved. 3 | * Copyright(c) 2008 Miklos Vajna. All rights reserved. 4 | * Copyright(c) 2006 Linus Torvalds. All rights reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of version 2 of the GNU General Public License as 8 | * published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | */ 15 | 16 | /* originally copied from perf and git */ 17 | 18 | /* 19 | * builtin-help.c 20 | * 21 | * Builtin help command 22 | */ 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define pr_err(x, ...) fprintf(stderr, x, ##__VA_ARGS__) 32 | #define STRERR_BUFSIZE 128 /* For the buffer size of strerror_r */ 33 | 34 | static void exec_man_konqueror(const char *path, const char *page) 35 | { 36 | const char *display = getenv("DISPLAY"); 37 | 38 | if (display && *display) { 39 | struct strbuf man_page = STRBUF_INIT; 40 | const char *filename = "kfmclient"; 41 | char sbuf[STRERR_BUFSIZE]; 42 | char *new = NULL; 43 | 44 | /* It's simpler to launch konqueror using kfmclient. */ 45 | if (path) { 46 | const char *file = strrchr(path, '/'); 47 | 48 | if (file && !strcmp(file + 1, "konqueror")) { 49 | char *dest; 50 | 51 | new = strdup(path); 52 | dest = strrchr(new, '/'); 53 | 54 | /* strlen("konqueror") == strlen("kfmclient") */ 55 | strcpy(dest + 1, "kfmclient"); 56 | path = new; 57 | } 58 | if (file) 59 | filename = file; 60 | } else 61 | path = "kfmclient"; 62 | strbuf_addf(&man_page, "man:%s(1)", page); 63 | execlp(path, filename, "newTab", man_page.buf, NULL); 64 | warning("failed to exec '%s': %s", path, 65 | strerror_r(errno, sbuf, sizeof(sbuf))); 66 | free(new); 67 | } 68 | } 69 | 70 | static void exec_man_man(const char *path, const char *page) 71 | { 72 | char sbuf[STRERR_BUFSIZE]; 73 | 74 | if (!path) 75 | path = "man"; 76 | execlp(path, "man", page, NULL); 77 | warning("failed to exec '%s': %s", path, 78 | strerror_r(errno, sbuf, sizeof(sbuf))); 79 | } 80 | 81 | static char *cmd_to_page(const char *cmd, char **page, const char *util_name) 82 | { 83 | int rc; 84 | 85 | if (!cmd) 86 | rc = asprintf(page, "%s", util_name); 87 | else if (!prefixcmp(cmd, util_name)) 88 | rc = asprintf(page, "%s", cmd); 89 | else 90 | rc = asprintf(page, "%s-%s", util_name, cmd); 91 | 92 | if (rc < 0) 93 | return NULL; 94 | return *page; 95 | } 96 | 97 | static const char *system_path(const char *path) 98 | { 99 | static const char *prefix = PREFIX; 100 | struct strbuf d = STRBUF_INIT; 101 | 102 | if (is_absolute_path(path)) 103 | return path; 104 | 105 | strbuf_addf(&d, "%s/%s", prefix, path); 106 | path = strbuf_detach(&d, NULL); 107 | return path; 108 | } 109 | 110 | static void setup_man_path(void) 111 | { 112 | struct strbuf new_path = STRBUF_INIT; 113 | const char *old_path = getenv("MANPATH"); 114 | 115 | /* We should always put ':' after our path. If there is no 116 | * old_path, the ':' at the end will let 'man' to try 117 | * system-wide paths after ours to find the manual page. If 118 | * there is old_path, we need ':' as delimiter. */ 119 | strbuf_addstr(&new_path, system_path(ACCFG_MAN_PATH)); 120 | strbuf_addch(&new_path, ':'); 121 | if (old_path) 122 | strbuf_addstr(&new_path, old_path); 123 | 124 | setenv("MANPATH", new_path.buf, 1); 125 | 126 | strbuf_release(&new_path); 127 | } 128 | 129 | static void exec_viewer(const char *name, const char *page) 130 | { 131 | if (!strcasecmp(name, "man")) 132 | exec_man_man(NULL, page); 133 | else if (!strcasecmp(name, "konqueror")) 134 | exec_man_konqueror(NULL, page); 135 | else 136 | warning("'%s': unknown man viewer.", name); 137 | } 138 | 139 | int help_show_man_page(const char *cmd, const char *util_name, 140 | const char *viewer) 141 | { 142 | const char *fallback = getenv(viewer); 143 | char *page; 144 | 145 | page = cmd_to_page(cmd, &page, util_name); 146 | if (!page) 147 | return -1; 148 | setup_man_path(); 149 | if (fallback) 150 | exec_viewer(fallback, page); 151 | exec_viewer("man", page); 152 | 153 | pr_err("no man viewer handled the request"); 154 | free(page); 155 | return -1; 156 | } 157 | -------------------------------------------------------------------------------- /util/json.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ 3 | #ifndef __ACCFG_JSON_H__ 4 | #define __ACCFG_JSON_H__ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | enum util_json_flags { 11 | UTIL_JSON_IDLE = (1 << 0), 12 | UTIL_JSON_HUMAN = (1 << 1), 13 | UTIL_JSON_VERBOSE = (1 << 2), 14 | UTIL_JSON_SAVE = (1 << 3), 15 | }; 16 | 17 | struct json_object; 18 | void util_display_json_array(FILE *f_out, struct json_object *jarray, 19 | uint64_t flags); 20 | struct json_object *util_device_to_json(struct accfg_device *device, 21 | uint64_t flags); 22 | struct json_object *util_wq_to_json(struct accfg_wq *accfg_wq, 23 | uint64_t flags); 24 | struct json_object *util_engine_to_json(struct accfg_engine *accfg_engine, 25 | uint64_t flags); 26 | struct json_object *util_json_object_size(uint64_t size, 27 | uint64_t flags); 28 | struct json_object *util_json_object_hex(uint64_t val, 29 | uint64_t flags); 30 | #endif /* __ACCFG_JSON_H__ */ 31 | -------------------------------------------------------------------------------- /util/list.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef _ACCFG_LIST_H_ 5 | #define _ACCFG_LIST_H_ 6 | 7 | #include 8 | 9 | /** 10 | * list_add_after - add an entry after the given node in the linked list. 11 | * @h: the list_head to add the node to 12 | * @l: the list_node after which to add to 13 | * @n: the list_node to add to the list. 14 | * 15 | * The list_node does not need to be initialized; it will be overwritten. 16 | * Example: 17 | * struct child *child = malloc(sizeof(*child)); 18 | * 19 | * child->name = "geoffrey"; 20 | * list_add_after(&parent->children, &child1->list, &child->list); 21 | * parent->num_children++; 22 | */ 23 | #define list_add_after(h, l, n) list_add_after_(h, l, n, LIST_LOC) 24 | static inline void list_add_after_(struct list_head *h, 25 | struct list_node *l, 26 | struct list_node *n, 27 | const char *abortstr) 28 | { 29 | if (l->next == &h->n) { 30 | /* l is the last element, this becomes a list_add_tail */ 31 | list_add_tail(h, n); 32 | return; 33 | } 34 | n->next = l->next; 35 | n->prev = l; 36 | l->next->prev = n; 37 | l->next = n; 38 | (void)list_debug(h, abortstr); 39 | } 40 | 41 | #endif /* _ACCFG_LIST_H_ */ 42 | -------------------------------------------------------------------------------- /util/log.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | /* Copyright(c) 2016-2025 Intel Corporation. All rights reserved. */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void do_log(struct log_ctx *ctx, int priority, const char *file, 12 | int line, const char *fn, const char *format, ...) 13 | { 14 | va_list args; 15 | int errno_save = errno; 16 | 17 | va_start(args, format); 18 | ctx->log_fn(ctx, priority, file, line, fn, format, args); 19 | va_end(args); 20 | errno = errno_save; 21 | } 22 | 23 | static void log_stderr(struct log_ctx *ctx, int priority, const char *file, 24 | int line, const char *fn, const char *format, va_list args) 25 | { 26 | fprintf(stderr, "%s: %s: ", ctx->owner, fn); 27 | vfprintf(stderr, format, args); 28 | } 29 | 30 | static int log_priority(const char *priority) 31 | { 32 | char *endptr; 33 | int prio; 34 | 35 | prio = strtol(priority, &endptr, 10); 36 | if (endptr[0] == '\0' || isspace(endptr[0])) 37 | return prio; 38 | if (strncmp(priority, "err", 3) == 0) 39 | return LOG_ERR; 40 | if (strncmp(priority, "info", 4) == 0) 41 | return LOG_INFO; 42 | if (strncmp(priority, "debug", 5) == 0) 43 | return LOG_DEBUG; 44 | if (strncmp(priority, "notice", 6) == 0) 45 | return LOG_NOTICE; 46 | return 0; 47 | } 48 | 49 | void log_init(struct log_ctx *ctx, const char *owner, const char *log_env) 50 | { 51 | const char *env; 52 | 53 | ctx->owner = owner; 54 | ctx->log_fn = log_stderr; 55 | ctx->log_priority = LOG_ERR; 56 | 57 | /* environment overwrites config */ 58 | env = secure_getenv(log_env); 59 | if (env != NULL) 60 | ctx->log_priority = log_priority(env); 61 | } 62 | -------------------------------------------------------------------------------- /util/log.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | /* Copyright(c) 2016-2025 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef __UTIL_LOG_H__ 5 | #define __UTIL_LOG_H__ 6 | #include 7 | #include 8 | #include 9 | 10 | struct log_ctx; 11 | typedef void (*log_fn)(struct log_ctx *ctx, int priority, const char *file, 12 | int line, const char *fn, const char *format, va_list args); 13 | 14 | struct log_ctx { 15 | log_fn log_fn; 16 | const char *owner; 17 | int log_priority; 18 | }; 19 | 20 | 21 | void do_log(struct log_ctx *ctx, int priority, const char *file, int line, 22 | const char *fn, const char *format, ...) 23 | __attribute__((format(printf, 6, 7))); 24 | void log_init(struct log_ctx *ctx, const char *owner, const char *log_env); 25 | static inline void __attribute__((always_inline, format(printf, 2, 3))) 26 | log_null(struct log_ctx *ctx, const char *format, ...) {} 27 | 28 | #define log_cond(ctx, prio, ...) \ 29 | do { \ 30 | if ((ctx)->log_priority >= prio) \ 31 | do_log(ctx, prio, __FILE__, __LINE__, __func__, __VA_ARGS__); \ 32 | } while (0) 33 | 34 | #ifdef ENABLE_LOGGING 35 | # ifdef ENABLE_DEBUG 36 | # define log_dbg(ctx, ...) log_cond(ctx, LOG_DEBUG, __VA_ARGS__) 37 | # else 38 | # define log_dbg(ctx, ...) log_null(ctx, __VA_ARGS__) 39 | # endif 40 | # define log_info(ctx, ...) log_cond(ctx, LOG_INFO, __VA_ARGS__) 41 | # define log_err(ctx, ...) log_cond(ctx, LOG_ERR, __VA_ARGS__) 42 | # define log_notice(ctx, ...) log_cond(ctx, LOG_NOTICE, __VA_ARGS__) 43 | #else 44 | # define log_dbg(ctx, ...) log_null(ctx, __VA_ARGS__) 45 | # define log_info(ctx, ...) log_null(ctx, __VA_ARGS__) 46 | # define log_err(ctx, ...) log_null(ctx, __VA_ARGS__) 47 | # define log_notice(ctx, ...) log_null(ctx, __VA_ARGS__) 48 | #endif 49 | 50 | #define dbg(x, ...) log_dbg(&(x)->ctx, __VA_ARGS__) 51 | #define info(x, ...) log_info(&(x)->ctx, __VA_ARGS__) 52 | #define err(x, ...) log_err(&(x)->ctx, __VA_ARGS__) 53 | #define notice(x, ...) log_notice(&(x)->ctx, __VA_ARGS__) 54 | 55 | #ifndef HAVE_SECURE_GETENV 56 | # ifdef HAVE___SECURE_GETENV 57 | # define secure_getenv __secure_getenv 58 | # else 59 | # warning neither secure_getenv nor __secure_getenv is available. 60 | # define secure_getenv getenv 61 | # endif 62 | #endif 63 | 64 | #endif /* __UTIL_LOG_H__ */ 65 | -------------------------------------------------------------------------------- /util/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2015-2019 Intel Corporation. All rights reserved. 3 | * Copyright(c) 2006 Linus Torvalds. All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | */ 14 | 15 | /* originally copied from perf and git */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | void main_handle_options(const char **argv, int argc, const char *usage_msg, 31 | struct cmd_struct *cmds, int num_cmds) 32 | { 33 | int i; 34 | 35 | if (argc < 2) { 36 | help_show_man_page(NULL, argv[0], "ACCFG_MAN_VIEWER"); 37 | goto exit_app; 38 | } 39 | 40 | if (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-v")) { 41 | printf("%s\n", VERSION); 42 | exit(0); 43 | } 44 | 45 | if (argv[1][0] != '-') { 46 | for (i = 0; i < num_cmds; i++) 47 | if (!strcmp(argv[1], cmds[i].cmd)) { 48 | if (argc > 2 && 49 | (!strcmp(argv[2], "--help") || 50 | !strcmp(argv[2], "-h"))) { 51 | help_show_man_page(argv[1], argv[0], 52 | "ACCFG_MAN_VIEWER"); 53 | goto exit_app; 54 | } else 55 | return; 56 | } 57 | fprintf(stderr, "Unknown command: '%s'\n", argv[1]); 58 | goto exit_app; 59 | } 60 | 61 | if (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")) { 62 | if (argc > 2) 63 | help_show_man_page(argv[2], argv[0], "ACCFG_MAN_VIEWER"); 64 | else 65 | help_show_man_page(NULL, argv[0], "ACCFG_MAN_VIEWER"); 66 | } 67 | 68 | if (!strcmp(argv[1], "--list-cmds")) { 69 | for (i = 0; i < num_cmds; i++) 70 | printf("%s %s\n", argv[0], cmds[i].cmd); 71 | exit(0); 72 | } 73 | 74 | exit_app: 75 | /* Exits app if not already */ 76 | usage(usage_msg); 77 | } 78 | 79 | int main_handle_internal_command(int argc, const char **argv, void *ctx, 80 | struct cmd_struct *cmds, int num_cmds) 81 | { 82 | int i; 83 | 84 | for (i = 0; i < num_cmds; i++) { 85 | struct cmd_struct *p = cmds+i; 86 | if (strcmp(p->cmd, argv[0])) 87 | continue; 88 | return p->fn(argc, argv, ctx); 89 | } 90 | 91 | fprintf(stderr, "Unknown command: '%s'\n", argv[0]); 92 | 93 | return -EINVAL; 94 | } 95 | -------------------------------------------------------------------------------- /util/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2015-2017 Intel Corporation. All rights reserved. 3 | * Copyright(c) 2006 Linus Torvalds. All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | */ 14 | 15 | /* originally copied from perf and git */ 16 | 17 | #ifndef __MAIN_H__ 18 | #define __MAIN_H__ 19 | struct cmd_struct; 20 | void main_handle_options(const char **argv, int argc, const char *usage_msg, 21 | struct cmd_struct *cmds, int num_cmds); 22 | int main_handle_internal_command(int argc, const char **argv, void *ctx, 23 | struct cmd_struct *cmds, int num_cmds); 24 | int help_show_man_page(const char *cmd, const char *util_name, 25 | const char *viewer); 26 | #endif /* __MAIN_H__ */ 27 | -------------------------------------------------------------------------------- /util/size.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | uint64_t __parse_size64(const char *str, uint64_t *units) 9 | { 10 | uint64_t val, check; 11 | char *end; 12 | 13 | val = strtoull(str, &end, 0); 14 | if (val == ULLONG_MAX) 15 | return val; 16 | check = val; 17 | switch (*end) { 18 | case 'k': 19 | case 'K': 20 | if (units) 21 | *units = SZ_1K; 22 | val *= SZ_1K; 23 | end++; 24 | break; 25 | case 'm': 26 | case 'M': 27 | if (units) 28 | *units = SZ_1M; 29 | val *= SZ_1M; 30 | end++; 31 | break; 32 | case 'g': 33 | case 'G': 34 | if (units) 35 | *units = SZ_1G; 36 | val *= SZ_1G; 37 | end++; 38 | break; 39 | case 't': 40 | case 'T': 41 | if (units) 42 | *units = SZ_1T; 43 | val *= SZ_1T; 44 | end++; 45 | break; 46 | default: 47 | if (units) 48 | *units = 1; 49 | break; 50 | } 51 | 52 | if (val < check || *end != '\0') 53 | val = ULLONG_MAX; 54 | return val; 55 | } 56 | 57 | uint64_t parse_size64(const char *str) 58 | { 59 | return __parse_size64(str, NULL); 60 | } 61 | -------------------------------------------------------------------------------- /util/size.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: GPL-2.0 */ 2 | /* Copyright(c) 2015-2019 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef _ACCFG_SIZE_H_ 5 | #define _ACCFG_SIZE_H_ 6 | 7 | #include 8 | 9 | #define SZ_1K 0x00000400 10 | #define SZ_4K 0x00001000 11 | #define SZ_1M 0x00100000 12 | #define SZ_2M 0x00200000 13 | #define SZ_4M 0x00400000 14 | #define SZ_16M 0x01000000 15 | #define SZ_64M 0x04000000 16 | #define SZ_1G 0x40000000 17 | #define SZ_1T 0x10000000000ULL 18 | 19 | uint64_t parse_size64(const char *str); 20 | uint64_t __parse_size64(const char *str, uint64_t *units); 21 | 22 | #define ALIGN(x, a) ((((uint64_t) x) + (a - 1)) & ~(a - 1)) 23 | #define ALIGN_DOWN(x, a) (((((uint64_t) x) + a) & ~(a - 1)) - a) 24 | #define BITS_PER_LONG (sizeof(uint64_t) * 8) 25 | #define HPAGE_SIZE (2 << 20) 26 | 27 | #endif /* _ACCFG_SIZE_H_ */ 28 | -------------------------------------------------------------------------------- /util/strbuf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2005 Junio C Hamano. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of version 2 of the GNU General Public License as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | */ 13 | 14 | /* originally copied from perf and git */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | int prefixcmp(const char *str, const char *prefix) 24 | { 25 | for (; ; str++, prefix++) 26 | if (!*prefix) 27 | return 0; 28 | else if (*str != *prefix) 29 | return (unsigned char)*prefix - (unsigned char)*str; 30 | } 31 | 32 | /* 33 | * Used as the default ->buf value, so that people can always assume 34 | * buf is non NULL and ->buf is NUL terminated even for a freshly 35 | * initialized strbuf. 36 | */ 37 | char strbuf_slopbuf[1]; 38 | 39 | void strbuf_init(struct strbuf *sb, ssize_t hint) 40 | { 41 | sb->alloc = sb->len = 0; 42 | sb->buf = strbuf_slopbuf; 43 | if (hint) 44 | strbuf_grow(sb, hint); 45 | } 46 | 47 | void strbuf_release(struct strbuf *sb) 48 | { 49 | if (sb->alloc) { 50 | zfree(&sb->buf); 51 | strbuf_init(sb, 0); 52 | } 53 | } 54 | 55 | char *strbuf_detach(struct strbuf *sb, size_t *sz) 56 | { 57 | char *res = sb->alloc ? sb->buf : NULL; 58 | if (sz) 59 | *sz = sb->len; 60 | strbuf_init(sb, 0); 61 | return res; 62 | } 63 | 64 | void strbuf_grow(struct strbuf *sb, size_t extra) 65 | { 66 | if (sb->len + extra + 1 <= sb->len) 67 | die("you want to use way too much memory"); 68 | if (!sb->alloc) 69 | sb->buf = NULL; 70 | ALLOC_GROW(sb->buf, sb->len + extra + 1, sb->alloc); 71 | } 72 | 73 | static void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, 74 | const void *data, size_t dlen) 75 | { 76 | if (pos + len < pos) 77 | die("you want to use way too much memory"); 78 | if (pos > sb->len) 79 | die("`pos' is too far after the end of the buffer"); 80 | if (pos + len > sb->len) 81 | die("`pos + len' is too far after the end of the buffer"); 82 | 83 | if (dlen >= len) 84 | strbuf_grow(sb, dlen - len); 85 | memmove(sb->buf + pos + dlen, 86 | sb->buf + pos + len, 87 | sb->len - pos - len); 88 | if (data) 89 | memcpy(sb->buf + pos, data, dlen); 90 | strbuf_setlen(sb, sb->len + dlen - len); 91 | } 92 | 93 | void strbuf_remove(struct strbuf *sb, size_t pos, size_t len) 94 | { 95 | strbuf_splice(sb, pos, len, NULL, 0); 96 | } 97 | 98 | void strbuf_add(struct strbuf *sb, const void *data, size_t len) 99 | { 100 | strbuf_grow(sb, len); 101 | memcpy(sb->buf + sb->len, data, len); 102 | strbuf_setlen(sb, sb->len + len); 103 | } 104 | 105 | void strbuf_addf(struct strbuf *sb, const char *fmt, ...) 106 | { 107 | int len; 108 | va_list ap; 109 | 110 | if (!strbuf_avail(sb)) 111 | strbuf_grow(sb, 64); 112 | va_start(ap, fmt); 113 | len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 114 | va_end(ap); 115 | if (len < 0) 116 | die("your vsnprintf is broken"); 117 | if (len > strbuf_avail(sb)) { 118 | strbuf_grow(sb, len); 119 | va_start(ap, fmt); 120 | len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); 121 | va_end(ap); 122 | if (len > strbuf_avail(sb)) { 123 | die("this should not happen, your vsnprintf is broken"); 124 | } 125 | } 126 | strbuf_setlen(sb, sb->len + len); 127 | } 128 | 129 | ssize_t strbuf_read(struct strbuf *sb, int fd, ssize_t hint) 130 | { 131 | size_t oldlen = sb->len; 132 | size_t oldalloc = sb->alloc; 133 | 134 | strbuf_grow(sb, hint ? hint : 8192); 135 | for (;;) { 136 | ssize_t cnt; 137 | 138 | cnt = read(fd, sb->buf + sb->len, sb->alloc - sb->len - 1); 139 | if (cnt < 0) { 140 | if (oldalloc == 0) 141 | strbuf_release(sb); 142 | else 143 | strbuf_setlen(sb, oldlen); 144 | return -1; 145 | } 146 | if (!cnt) 147 | break; 148 | sb->len += cnt; 149 | strbuf_grow(sb, 8192); 150 | } 151 | 152 | sb->buf[sb->len] = '\0'; 153 | return sb->len - oldlen; 154 | } 155 | -------------------------------------------------------------------------------- /util/strbuf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2005 Junio C Hamano. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of version 2 of the GNU General Public License as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | */ 13 | 14 | /* originally copied from perf and git */ 15 | 16 | #ifndef __ACCFG_STRBUF_H 17 | #define __ACCFG_STRBUF_H 18 | #include 19 | #include 20 | #include /* for ssize_t */ 21 | 22 | /* 23 | * Strbuf's can be use in many ways: as a byte array, or to store arbitrary 24 | * long, overflow safe strings. 25 | * 26 | * Strbufs has some invariants that are very important to keep in mind: 27 | * 28 | * 1. the ->buf member is always malloc-ed, hence strbuf's can be used to 29 | * build complex strings/buffers whose final size isn't easily known. 30 | * 31 | * It is NOT legal to copy the ->buf pointer away. 32 | * `strbuf_detach' is the operation that detaches a buffer from its shell 33 | * while keeping the shell valid wrt its invariants. 34 | * 35 | * 2. the ->buf member is a byte array that has at least ->len + 1 bytes 36 | * allocated. The extra byte is used to store a '\0', allowing the ->buf 37 | * member to be a valid C-string. Every strbuf function ensure this 38 | * invariant is preserved. 39 | * 40 | * Note that it is OK to "play" with the buffer directly if you work it 41 | * that way: 42 | * 43 | * strbuf_grow(sb, SOME_SIZE); 44 | * ... Here, the memory array starting at sb->buf, and of length 45 | * ... strbuf_avail(sb) is all yours, and you are sure that 46 | * ... strbuf_avail(sb) is at least SOME_SIZE. 47 | * strbuf_setlen(sb, sb->len + SOME_OTHER_SIZE); 48 | * 49 | * Of course, SOME_OTHER_SIZE must be smaller or equal to strbuf_avail(sb). 50 | * 51 | * Doing so is safe, though if it has to be done in many places, adding the 52 | * missing API to the strbuf module is the way to go. 53 | * 54 | * XXX: do _not_ assume that the area that is yours is of size ->alloc - 1 55 | * even if it's true in the current implementation. Alloc is somehow a 56 | * "private" member that should not be messed with. 57 | */ 58 | 59 | extern char strbuf_slopbuf[]; 60 | struct strbuf { 61 | size_t alloc; 62 | size_t len; 63 | char *buf; 64 | }; 65 | 66 | #define STRBUF_INIT { 0, 0, strbuf_slopbuf } 67 | 68 | /*----- strbuf life cycle -----*/ 69 | extern void strbuf_init(struct strbuf *buf, ssize_t hint); 70 | extern void strbuf_release(struct strbuf *); 71 | extern char *strbuf_detach(struct strbuf *, size_t *); 72 | 73 | /*----- strbuf size related -----*/ 74 | static inline ssize_t strbuf_avail(const struct strbuf *sb) { 75 | return sb->alloc ? sb->alloc - sb->len - 1 : 0; 76 | } 77 | 78 | extern void strbuf_grow(struct strbuf *, size_t); 79 | 80 | static inline void strbuf_setlen(struct strbuf *sb, size_t len) { 81 | if (!sb->alloc) 82 | strbuf_grow(sb, 0); 83 | assert(len < sb->alloc); 84 | sb->len = len; 85 | sb->buf[len] = '\0'; 86 | } 87 | 88 | /*----- add data in your buffer -----*/ 89 | static inline void strbuf_addch(struct strbuf *sb, int c) { 90 | strbuf_grow(sb, 1); 91 | sb->buf[sb->len++] = c; 92 | sb->buf[sb->len] = '\0'; 93 | } 94 | 95 | extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); 96 | 97 | extern void strbuf_add(struct strbuf *, const void *, size_t); 98 | static inline void strbuf_addstr(struct strbuf *sb, const char *s) { 99 | strbuf_add(sb, s, strlen(s)); 100 | } 101 | 102 | __attribute__((format(printf,2,3))) 103 | extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); 104 | 105 | /* XXX: if read fails, any partial read is undone */ 106 | extern ssize_t strbuf_read(struct strbuf *, int fd, ssize_t hint); 107 | 108 | #endif /* __ACCFG_STRBUF_H */ 109 | -------------------------------------------------------------------------------- /util/sysfs.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | /* Copyright(c) 2014-2025 Intel Corporation. All rights reserved. */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf) 22 | { 23 | int fd = open(path, O_RDONLY|O_CLOEXEC); 24 | int n; 25 | 26 | if (fd < 0) { 27 | return -errno; 28 | } 29 | n = read(fd, buf, SYSFS_ATTR_SIZE); 30 | close(fd); 31 | if (n < 0 || n >= SYSFS_ATTR_SIZE) { 32 | buf[0] = 0; 33 | log_dbg(ctx, "failed to read %s: %s\n", path, strerror(errno)); 34 | return -errno; 35 | } 36 | buf[n] = 0; 37 | if (n && buf[n-1] == '\n'){ 38 | buf[n-1] = 0; 39 | } 40 | return 0; 41 | } 42 | 43 | static int write_attr(struct log_ctx *ctx, const char *path, 44 | const char *buf, int quiet) 45 | { 46 | int fd = open(path, O_WRONLY|O_CLOEXEC); 47 | int n, len = strlen(buf), rc; 48 | 49 | if (fd < 0) { 50 | rc = -errno; 51 | log_dbg(ctx, "failed to open %s: %s\n", path, strerror(errno)); 52 | return rc; 53 | } 54 | n = write(fd, buf, len); 55 | rc = -errno; 56 | close(fd); 57 | if (n < len) { 58 | if (!quiet) 59 | log_dbg(ctx, "failed to write %s to %s: %s\n", buf, path, 60 | strerror(errno)); 61 | return rc; 62 | } 63 | return 0; 64 | } 65 | 66 | int __sysfs_write_attr(struct log_ctx *ctx, const char *path, 67 | const char *buf) 68 | { 69 | return write_attr(ctx, path, buf, 0); 70 | } 71 | 72 | int __sysfs_write_attr_quiet(struct log_ctx *ctx, const char *path, 73 | const char *buf) 74 | { 75 | return write_attr(ctx, path, buf, 1); 76 | } 77 | 78 | int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path, 79 | char *dev_prefix, char *bus_type, 80 | int (*filter)(const struct dirent *), 81 | void *parent, add_dev_fn add_dev) 82 | { 83 | int add_errors = 0; 84 | struct dirent **d, *de; 85 | int i, n; 86 | 87 | n = scandir(base_path, &d, filter, alphasort); 88 | if (n == -1) 89 | return -ENODEV; 90 | 91 | for (i = 0; i < n; i++) { 92 | char *dev_path; 93 | void *dev; 94 | int id; 95 | 96 | de = d[i]; 97 | if (sscanf(de->d_name, "%*[a-z]%d", &id) < 0) { 98 | while (n--) 99 | free(d[n]); 100 | free(d); 101 | return -EINVAL; 102 | } 103 | if (strchr(de->d_name, '!')) 104 | continue; 105 | if (asprintf(&dev_path, "%s/%s", base_path, de->d_name) < 0) { 106 | log_err(ctx, "%s%d: path allocation failure\n", 107 | de->d_name, id); 108 | continue; 109 | } 110 | dev = add_dev(parent, id, dev_path, dev_prefix, bus_type); 111 | free(dev_path); 112 | if (!dev) { 113 | add_errors++; 114 | log_err(ctx, "%d: add_dev() failed\n", id); 115 | } else 116 | log_dbg(ctx, "%d: processed\n", id); 117 | } 118 | while (n--) 119 | free(d[n]); 120 | free(d); 121 | 122 | return add_errors; 123 | } 124 | -------------------------------------------------------------------------------- /util/sysfs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: LGPL-2.1 */ 2 | /* Copyright(c) 2014-2025 Intel Corporation. All rights reserved. */ 3 | 4 | #ifndef __UTIL_SYSFS_H__ 5 | #define __UTIL_SYSFS_H__ 6 | 7 | #include 8 | #include 9 | 10 | typedef void *(*add_dev_fn)(void *parent, int id, const char *dev_path, 11 | char *dev_prefix, char *bus_type); 12 | 13 | #define SYSFS_ATTR_SIZE 1024 14 | 15 | struct log_ctx; 16 | int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf); 17 | int __sysfs_write_attr(struct log_ctx *ctx, const char *path, const char *buf); 18 | int __sysfs_write_attr_quiet(struct log_ctx *ctx, const char *path, 19 | const char *buf); 20 | int __sysfs_device_parse(struct log_ctx *ctx, const char *base_path, 21 | char *dev_prefix, char *bus_type, 22 | int (*filter)(const struct dirent *), 23 | void *parent, add_dev_fn add_dev); 24 | 25 | #define sysfs_read_attr(c, p, b) __sysfs_read_attr(&(c)->ctx, (p), (b)) 26 | #define sysfs_write_attr(c, p, b) __sysfs_write_attr(&(c)->ctx, (p), (b)) 27 | #define sysfs_write_attr_quiet(c, p, b) __sysfs_write_attr_quiet(&(c)->ctx, (p), (b)) 28 | #define sysfs_device_parse(c, b, d, bt, m, p, fn) __sysfs_device_parse(&(c)->ctx, \ 29 | (b), (d), (bt), (m), (p), (fn)) 30 | 31 | static inline const char *devpath_to_devname(const char *devpath) 32 | { 33 | return strrchr(devpath, '/') + 1; 34 | } 35 | #endif /* __UTIL_SYSFS_H__ */ 36 | -------------------------------------------------------------------------------- /util/usage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2005 Linus Torvalds. All rights reserved. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of version 2 of the GNU General Public License as 6 | * published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope that it will be useful, but 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | * General Public License for more details. 12 | */ 13 | 14 | /* originally copied from perf and git */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | static void report(const char *prefix, const char *err, va_list params) 22 | { 23 | char msg[1024]; 24 | vsnprintf(msg, sizeof(msg), err, params); 25 | fprintf(stderr, " %s%s\n", prefix, msg); 26 | } 27 | 28 | static NORETURN void usage_builtin(const char *err) 29 | { 30 | fprintf(stderr, "\n Usage: %s\n", err); 31 | exit(129); 32 | } 33 | 34 | static NORETURN void die_builtin(const char *err, va_list params) 35 | { 36 | report(" Fatal: ", err, params); 37 | exit(128); 38 | } 39 | 40 | static void error_builtin(const char *err, va_list params) 41 | { 42 | report(" Error: ", err, params); 43 | } 44 | 45 | static void warn_builtin(const char *warn, va_list params) 46 | { 47 | report(" Warning: ", warn, params); 48 | } 49 | 50 | /* If we are in a dlopen()ed .so write to a global variable would segfault 51 | * (ugh), so keep things static. */ 52 | static void (*usage_routine)(const char *err) NORETURN = usage_builtin; 53 | static void (*die_routine)(const char *err, va_list params) NORETURN = die_builtin; 54 | static void (*error_routine)(const char *err, va_list params) = error_builtin; 55 | static void (*warn_routine)(const char *err, va_list params) = warn_builtin; 56 | 57 | void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN) 58 | { 59 | die_routine = routine; 60 | } 61 | 62 | void usage(const char *err) 63 | { 64 | usage_routine(err); 65 | } 66 | 67 | void die(const char *err, ...) 68 | { 69 | va_list params; 70 | 71 | va_start(params, err); 72 | die_routine(err, params); 73 | va_end(params); 74 | } 75 | 76 | int error(const char *err, ...) 77 | { 78 | va_list params; 79 | 80 | va_start(params, err); 81 | error_routine(err, params); 82 | va_end(params); 83 | return -1; 84 | } 85 | 86 | void warning(const char *warn, ...) 87 | { 88 | va_list params; 89 | 90 | va_start(params, warn); 91 | warn_routine(warn, params); 92 | va_end(params); 93 | } 94 | -------------------------------------------------------------------------------- /util/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2005 Junio C Hamano. All rights reserved. 3 | * Copyright(c) 2005 Linus Torvalds. All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | */ 14 | 15 | /* originally copied from perf and git */ 16 | 17 | #ifndef __UTIL_H__ 18 | #define __UTIL_H__ 19 | #include 20 | #include 21 | #include 22 | 23 | #pragma GCC diagnostic ignored "-Wmissing-prototypes" 24 | #pragma GCC diagnostic ignored "-Wpedantic" 25 | 26 | #ifdef __GNUC__ 27 | #define NORETURN __attribute__((__noreturn__)) 28 | #else 29 | #define NORETURN 30 | #ifndef __attribute__ 31 | #define __attribute__(x) 32 | #endif 33 | #endif 34 | 35 | #ifndef __maybe_unused 36 | # define __maybe_unused /* unimplemented */ 37 | #endif 38 | 39 | #define is_dir_sep(c) ((c) == '/') 40 | 41 | #define alloc_nr(x) (((x)+16)*3/2) 42 | 43 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) 44 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) 45 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) 46 | 47 | #define rounddown(x, y) ( \ 48 | { \ 49 | typeof(x) __x = (x); \ 50 | __x - (__x % (y)); \ 51 | } \ 52 | ) 53 | 54 | /* 55 | * Realloc the buffer pointed at by variable 'x' so that it can hold 56 | * at least 'nr' entries; the number of entries currently allocated 57 | * is 'alloc', using the standard growing factor alloc_nr() macro. 58 | * 59 | * DO NOT USE any expression with side-effect for 'x' or 'alloc'. 60 | */ 61 | #define ALLOC_GROW(x, nr, alloc) \ 62 | do { \ 63 | if ((nr) > alloc) { \ 64 | if (alloc_nr(alloc) < (nr)) \ 65 | alloc = (nr); \ 66 | else \ 67 | alloc = alloc_nr(alloc); \ 68 | x = xrealloc((x), alloc * sizeof(*(x))); \ 69 | } \ 70 | } while(0) 71 | 72 | #define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) 73 | 74 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 75 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) 76 | 77 | static inline const char *skip_prefix(const char *str, const char *prefix) 78 | { 79 | size_t len = strlen(prefix); 80 | return strncmp(str, prefix, len) ? NULL : str + len; 81 | } 82 | 83 | static inline int is_absolute_path(const char *path) 84 | { 85 | return path[0] == '/'; 86 | } 87 | 88 | void usage(const char *err) NORETURN; 89 | void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); 90 | int error(const char *err, ...) __attribute__((format (printf, 1, 2))); 91 | void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); 92 | void set_die_routine(void (*routine)(const char *err, va_list params) NORETURN); 93 | char *xstrdup(const char *str); 94 | void *xrealloc(void *ptr, size_t size); 95 | int prefixcmp(const char *str, const char *prefix); 96 | char *prefix_filename(const char *pfx, const char *arg); 97 | void fix_filename(const char *prefix, const char **file); 98 | 99 | #endif /* __UTIL_H__ */ 100 | -------------------------------------------------------------------------------- /util/wrapper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright(c) 2005 Junio C Hamano. All rights reserved. 3 | * Copyright(c) 2005 Linus Torvalds. All rights reserved. 4 | * 5 | * This program is free software; you can redistribute it and/or modify it 6 | * under the terms of version 2 of the GNU General Public License as 7 | * published by the Free Software Foundation. 8 | * 9 | * This program is distributed in the hope that it will be useful, but 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * General Public License for more details. 13 | */ 14 | 15 | /* originally copied from perf and git */ 16 | 17 | /* 18 | * Various trivial helper wrappers around standard functions 19 | */ 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | char *xstrdup(const char *str) 26 | { 27 | char *ret = strdup(str); 28 | if (!ret) { 29 | ret = strdup(str); 30 | if (!ret) 31 | die("Out of memory, strdup failed"); 32 | } 33 | return ret; 34 | } 35 | 36 | void *xrealloc(void *ptr, size_t size) 37 | { 38 | void *ret = realloc(ptr, size); 39 | 40 | if (!ret) { 41 | /* realloc() would free ptr if size == 0 */ 42 | if (size) 43 | free(ptr); 44 | 45 | die("Out of memory, realloc failed"); 46 | } 47 | return ret; 48 | } 49 | --------------------------------------------------------------------------------