xref: /freebsd-src/sys/sys/iov.h (revision c57c26179033f64c2011a2d2a904ee3fa62e826a)
19bfb1e36SRyan Stone /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
39b10f59aSPedro F. Giffuni  *
4faf139ccSRyan Stone  * Copyright (c) 2013-2015 Sandvine Inc.
59bfb1e36SRyan Stone  * All rights reserved.
69bfb1e36SRyan Stone  *
79bfb1e36SRyan Stone  * Redistribution and use in source and binary forms, with or without
89bfb1e36SRyan Stone  * modification, are permitted provided that the following conditions
99bfb1e36SRyan Stone  * are met:
109bfb1e36SRyan Stone  * 1. Redistributions of source code must retain the above copyright
119bfb1e36SRyan Stone  *    notice, this list of conditions and the following disclaimer.
129bfb1e36SRyan Stone  * 2. Redistributions in binary form must reproduce the above copyright
139bfb1e36SRyan Stone  *    notice, this list of conditions and the following disclaimer in the
149bfb1e36SRyan Stone  *    documentation and/or other materials provided with the distribution.
159bfb1e36SRyan Stone  *
169bfb1e36SRyan Stone  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
179bfb1e36SRyan Stone  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
189bfb1e36SRyan Stone  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199bfb1e36SRyan Stone  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
209bfb1e36SRyan Stone  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
219bfb1e36SRyan Stone  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
229bfb1e36SRyan Stone  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
239bfb1e36SRyan Stone  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
249bfb1e36SRyan Stone  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
259bfb1e36SRyan Stone  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
269bfb1e36SRyan Stone  * SUCH DAMAGE.
279bfb1e36SRyan Stone  */
289bfb1e36SRyan Stone 
299bfb1e36SRyan Stone #ifndef _SYS_IOV_H_
309bfb1e36SRyan Stone #define _SYS_IOV_H_
319bfb1e36SRyan Stone 
329bfb1e36SRyan Stone #include <sys/ioccom.h>
339bfb1e36SRyan Stone 
341191f715SRyan Stone #define	PF_CONFIG_NAME		"PF"
351191f715SRyan Stone #define	VF_SCHEMA_NAME		"VF"
361191f715SRyan Stone 
373c22f215SRyan Stone #define	VF_PREFIX		"VF-"
383c22f215SRyan Stone #define	VF_PREFIX_LEN		3
393c22f215SRyan Stone #define	VF_NUM_LEN		5	/* The maximum VF num is 65535. */
403c22f215SRyan Stone #define	VF_MAX_NAME		(VF_PREFIX_LEN + VF_NUM_LEN + 1)
413c22f215SRyan Stone 
421191f715SRyan Stone #define	DRIVER_CONFIG_NAME	"DRIVER"
431191f715SRyan Stone #define	IOV_CONFIG_NAME		"IOV"
441191f715SRyan Stone 
451191f715SRyan Stone #define	TYPE_SCHEMA_NAME	"TYPE"
461191f715SRyan Stone #define	DEFAULT_SCHEMA_NAME	"DEFAULT"
471191f715SRyan Stone #define	REQUIRED_SCHEMA_NAME	"REQUIRED"
481191f715SRyan Stone 
49*c57c2617SKristof Provost #define	VF_VLAN_TRUNK		4096
50*c57c2617SKristof Provost 
511191f715SRyan Stone /*
521191f715SRyan Stone  * Because each PF device is expected to expose a unique set of possible
531191f715SRyan Stone  * configurations, the SR-IOV infrastructure dynamically queries the PF
541191f715SRyan Stone  * driver for its capabilities.  These capabilities are exposed to userland
551191f715SRyan Stone  * with a configuration schema.  The schema is exported from the kernel as a
561191f715SRyan Stone  * packed nvlist.  See nv(3) for the details of the nvlist API.  The expected
571191f715SRyan Stone  * format of the nvlist is:
581191f715SRyan Stone  *
591191f715SRyan Stone  * BASIC RULES
601191f715SRyan Stone  *   1) All keys are case-insensitive.
611191f715SRyan Stone  *   2) No keys that are not specified below may exist at any level of the
621191f715SRyan Stone  *      schema.
631191f715SRyan Stone  *   3) All keys are mandatory unless explicitly documented as optional.  If a
641191f715SRyan Stone  *      key is mandatory then the associated value is also mandatory.
651191f715SRyan Stone  *   4) Order of keys is irrelevant.
661191f715SRyan Stone  *
671191f715SRyan Stone  * TOP LEVEL
681191f715SRyan Stone  *   1) There must be a top-level key with the name PF_CONFIG_NAME.  The value
691191f715SRyan Stone  *      associated with this key is a nvlist that follows the device schema
701191f715SRyan Stone  *      node format.  The parameters in this node specify the configuration
711191f715SRyan Stone  *      parameters that may be applied to a PF.
721191f715SRyan Stone  *   2) There must be a top-level key with the name VF_SCHEMA_NAME.  The value
731191f715SRyan Stone  *      associated with this key is a nvlist that follows the device schema
741191f715SRyan Stone  *      node format.  The parameters in this node specify the configuration
751191f715SRyan Stone  *      parameters that may be applied to a VF.
761191f715SRyan Stone  *
771191f715SRyan Stone  * DEVICE SCHEMA NODE
781191f715SRyan Stone  *   1) There must be a key with the name DRIVER_CONFIG_NAME.  The value
791191f715SRyan Stone  *      associated with this key is a nvlist that follows the device/subsystem
801191f715SRyan Stone  *      schema node format.  The parameters in this node specify the
811191f715SRyan Stone  *      configuration parameters that are specific to a particular device
821191f715SRyan Stone  *      driver.
831191f715SRyan Stone  *   2) There must be a key with the name IOV_CONFIG_NAME.  The value associated
841191f715SRyan Stone  *      with this key is an nvlist that follows the device/subsystem schema node
851191f715SRyan Stone  *      format.  The parameters in this node specify the configuration
861191f715SRyan Stone  *      parameters that are applied by the SR-IOV infrastructure.
871191f715SRyan Stone  *
881191f715SRyan Stone  * DEVICE/SUBSYSTEM SCHEMA NODE
891191f715SRyan Stone  *   1) All keys in the device/subsystem schema node are optional.
901191f715SRyan Stone  *   2) Each key specifies the name of a valid configuration parameter that may
911191f715SRyan Stone  *      be applied to the device/subsystem combination specified by this node.
921191f715SRyan Stone  *      The value associated with the key specifies the format of valid
931191f715SRyan Stone  *      configuration values, and must be a nvlist in parameter schema node
941191f715SRyan Stone  *      format.
951191f715SRyan Stone  *
961191f715SRyan Stone  * PARAMETER SCHEMA NODE
971191f715SRyan Stone  *   1) The parameter schema node must contain a key with the name
981191f715SRyan Stone  *      TYPE_SCHEMA_NAME.  The value associated with this key must be a string.
991191f715SRyan Stone  *      This string specifies the type of value that the parameter specified by
1001191f715SRyan Stone  *      this node must take.  The string must have one of the following values:
1011191f715SRyan Stone  *         - "bool"     - The configuration value must be a boolean.
1021191f715SRyan Stone  *         - "mac-addr" - The configuration value must be a binary value.  In
1031191f715SRyan Stone  *                         addition, the value must be exactly 6 bytes long and
1041191f715SRyan Stone  *                         the value must not be a multicast or broadcast mac.
1051191f715SRyan Stone  *         - "uint8_t"  - The configuration value must be a integer value in
1061191f715SRyan Stone  *                         the range [0, UINT8_MAX].
1071191f715SRyan Stone  *         - "uint16_t" - The configuration value must be a integer value in
1081191f715SRyan Stone  *                         the range [0, UINT16_MAX].
1091191f715SRyan Stone  *         - "uint32_t" - The configuration value must be a integer value in
1101191f715SRyan Stone  *                         the range [0, UINT32_MAX].
1111191f715SRyan Stone  *         - "uint64_t" - The configuration value must be a integer value in
1121191f715SRyan Stone  *                         the range [0, UINT64_MAX].
1131191f715SRyan Stone  *  2) The parameter schema may contain a key with the name
1141191f715SRyan Stone  *     REQUIRED_SCHEMA_NAME.  This key is optional.  If this key is present, the
1151191f715SRyan Stone  *     value associated with it must have a boolean type.  If the value is true,
1161191f715SRyan Stone  *     then the parameter specified by this schema is a required parameter.  All
1171191f715SRyan Stone  *     valid configurations must include all required parameters.
1181191f715SRyan Stone  *  3) The parameter schema may contain a key with the name DEFAULT_SCHEMA_NAME.
1191191f715SRyan Stone  *     This key is optional.  This key must not be present if the parameter
1201191f715SRyan Stone  *     specified by this schema is required.  If this key is present, the value
1211191f715SRyan Stone  *     associated with the parent key must follow all restrictions specified by
1221191f715SRyan Stone  *     the type specified by this schema.  If a configuration does not supply a
1231191f715SRyan Stone  *     value for the parameter specified by this schema, then the kernel will
1241191f715SRyan Stone  *     apply the value associated with this key in its place.
1251191f715SRyan Stone  *
1261191f715SRyan Stone  * The following is an example of a valid schema, as printed by nvlist_dump.
1271191f715SRyan Stone  * Keys are printed followed by the type of the value in parantheses.  The
1281191f715SRyan Stone  * value is displayed following a colon.  The indentation level reflects the
1291191f715SRyan Stone  * level of nesting of nvlists.  String values are displayed between []
1301191f715SRyan Stone  * brackets.  Binary values are shown with the length of the binary value (in
1311191f715SRyan Stone  * bytes) followed by the actual binary values.
1321191f715SRyan Stone  *
1331191f715SRyan Stone  *  PF (NVLIST):
1341191f715SRyan Stone  *      IOV (NVLIST):
1351191f715SRyan Stone  *          num_vfs (NVLIST):
1361191f715SRyan Stone  *              type (STRING): [uint16_t]
1371191f715SRyan Stone  *              required (BOOL): TRUE
1381191f715SRyan Stone  *          device (NVLIST):
1391191f715SRyan Stone  *              type (STRING): [string]
1401191f715SRyan Stone  *              required (BOOL): TRUE
1411191f715SRyan Stone  *      DRIVER (NVLIST):
1421191f715SRyan Stone  *  VF (NVLIST):
1431191f715SRyan Stone  *      IOV (NVLIST):
1441191f715SRyan Stone  *          passthrough (NVLIST):
1451191f715SRyan Stone  *              type (STRING): [bool]
1461191f715SRyan Stone  *              default (BOOL): FALSE
1471191f715SRyan Stone  *      DRIVER (NVLIST):
1481191f715SRyan Stone  *          mac-addr (NVLIST):
1491191f715SRyan Stone  *              type (STRING): [mac-addr]
1501191f715SRyan Stone  *              default (BINARY): 6 000000000000
1511191f715SRyan Stone  *          vlan (NVLIST):
1521191f715SRyan Stone  *               type (STRING): [uint16_t]
1531191f715SRyan Stone  *          spoof-check (NVLIST):
1541191f715SRyan Stone  *              type (STRING): [bool]
1551191f715SRyan Stone  *              default (BOOL): TRUE
1561191f715SRyan Stone  *          allow-set-mac (NVLIST):
1571191f715SRyan Stone  *              type (STRING): [bool]
1581191f715SRyan Stone  *              default (BOOL): FALSE
1591191f715SRyan Stone  */
1601191f715SRyan Stone struct pci_iov_schema
1611191f715SRyan Stone {
1621191f715SRyan Stone 	void *schema;
1631191f715SRyan Stone 	size_t len;
1641191f715SRyan Stone 	int error;
1651191f715SRyan Stone };
1661191f715SRyan Stone 
1675cc26e63SRyan Stone /*
1685cc26e63SRyan Stone  * SR-IOV configuration is passed to the kernel as a packed nvlist.  See nv(3)
1695cc26e63SRyan Stone  * for the details of the nvlist API.  The expected format of the nvlist is:
1705cc26e63SRyan Stone  *
1715cc26e63SRyan Stone  * BASIC RULES
1725cc26e63SRyan Stone  *   1) All keys are case-insensitive.
1735cc26e63SRyan Stone  *   2) No keys that are not specified below may exist at any level of the
1745cc26e63SRyan Stone  *      config nvlist.
1755cc26e63SRyan Stone  *   3) Unless otherwise specified, all keys are optional.  It should go without
1765cc26e63SRyan Stone  *      saying a key being mandatory is transitive: that is, if a key is
1775cc26e63SRyan Stone  *      specified to contain a sub-nodes that contains a mandatory key, then
1785cc26e63SRyan Stone  *      the outer key is implicitly mandatory.  If a key is mandatory then the
1795cc26e63SRyan Stone  *      associated value is also mandatory.
1805cc26e63SRyan Stone  *   4) Order of keys is irrelevant.
1815cc26e63SRyan Stone  *
1825cc26e63SRyan Stone  * TOP LEVEL OF CONFIG NVLIST
1835cc26e63SRyan Stone  * 1) All keys specified in this section are mandatory.
1845cc26e63SRyan Stone  * 2) There must be a top-level key with the name PF_CONFIG_NAME.  The value
1855cc26e63SRyan Stone  *    associated is an nvlist that follows the "device node" format.  The
1865cc26e63SRyan Stone  *    parameters in this node specify parameters that apply to the PF.
1875cc26e63SRyan Stone  * 3) For every VF being configured (this is set via the "num_vfs" parameter
1885cc26e63SRyan Stone  *    in the PF section), there must be a top-level key whose name is VF_PREFIX
1895cc26e63SRyan Stone  *    immediately followed by the index of the VF as a decimal integer.  For
1905cc26e63SRyan Stone  *    example, this would be VF-0 for the first VF.  VFs are numbered starting
1915cc26e63SRyan Stone  *    from 0.  The value associated with this key follows the "device node"
1925cc26e63SRyan Stone  *    format.  The parameters in this node specify configuration that applies
1935cc26e63SRyan Stone  *    to the VF specified in the key.  Leading zeros are not permitted in VF
1945cc26e63SRyan Stone  *    index.  Configuration for the second VF must be specified in a node with
1955cc26e63SRyan Stone  *    the key VF-1.  VF-01 is not a valid key.
1965cc26e63SRyan Stone  *
1975cc26e63SRyan Stone  * DEVICE NODES
1985cc26e63SRyan Stone  * 1) All keys specified in this section are mandatory.
1995cc26e63SRyan Stone  * 2) The device node must contain a key with the name DRIVER_CONFIG_NAME.  The
2005cc26e63SRyan Stone  *    value associated with this key is an nvlist following the subsystem node
2015cc26e63SRyan Stone  *    format.  The parameters in this key specify configuration that is specific
2025cc26e63SRyan Stone  *    to a particular device driver.
2035cc26e63SRyan Stone  * 3) The device node must contain a key with the name IOV_CONFIG_NAME.  The
2045cc26e63SRyan Stone  *    value associated with this key is an nvlist following the subsystem node
2055cc26e63SRyan Stone  *    format.  The parameters in this key specify configuration that is consumed
2065cc26e63SRyan Stone  *    by the SR-IOV infrastructure.
2075cc26e63SRyan Stone  *
2085cc26e63SRyan Stone  * SUBSYSTEM NODES
2095cc26e63SRyan Stone  * 1) A subsystem node specifies configuration parameters that apply to a
2105cc26e63SRyan Stone  *    particular subsystem (driver or infrastructure) of a particular device
2115cc26e63SRyan Stone  *    (PF or individual VF).
2125cc26e63SRyan Stone  *         Note: We will refer to the section of the configuration schema that
2135cc26e63SRyan Stone  *               specifies the parameters for this subsystem and device
214f24c816dSGordon Bergling  *               configuration as the device/subsystem schema.
2155cc26e63SRyan Stone  * 2) The subsystem node must contain only keys that correspond to parameters
2165cc26e63SRyan Stone  *    that are specified in the device/subsystem schema.
2175cc26e63SRyan Stone  * 3) Every parameter specified as required in the device/subsystem schema is
2185cc26e63SRyan Stone  *    a mandatory key in the subsystem node.
2195cc26e63SRyan Stone  *    Note:  All parameters that are not required in device/subsystem schema are
2205cc26e63SRyan Stone  *           optional keys.  In particular, any parameter specified to have a
2215cc26e63SRyan Stone  *           default value in the device/subsystem schema is optional.  The
2225cc26e63SRyan Stone  *           kernel is responsible for applying default values.
2235cc26e63SRyan Stone  * 4) The value of every parameter in the device node must conform to the
2245cc26e63SRyan Stone  *    restrictions of the type specified for that parameter in the device/
2255cc26e63SRyan Stone  *    subsystem schema.
2265cc26e63SRyan Stone  *
2275cc26e63SRyan Stone  * The following is an example of a valid configuration, when validated against
2285cc26e63SRyan Stone  * the schema example given above.
2295cc26e63SRyan Stone  *
2305cc26e63SRyan Stone  * PF (NVLIST):
2315cc26e63SRyan Stone  *     driver (NVLIST):
2325cc26e63SRyan Stone  *     iov (NVLIST):
2335cc26e63SRyan Stone  *         num_vfs (NUMBER): 3 (3) (0x3)
2345cc26e63SRyan Stone  *         device (STRING): [ix0]
2355cc26e63SRyan Stone  * VF-0 (NVLIST):
2365cc26e63SRyan Stone  *     driver (NVLIST):
2375cc26e63SRyan Stone  *         vlan (NUMBER): 1000 (1000) (0x3e8)
2385cc26e63SRyan Stone  *     iov (NVLIST):
2395cc26e63SRyan Stone  *         passthrough (BOOL): TRUE
2405cc26e63SRyan Stone  * VF-1 (NVLIST):
2415cc26e63SRyan Stone  *     driver (NVLIST):
2425cc26e63SRyan Stone  *     iov (NVLIST):
2435cc26e63SRyan Stone  * VF-2 (NVLIST):
2445cc26e63SRyan Stone  *     driver (NVLIST):
2455cc26e63SRyan Stone  *         mac-addr (BINARY): 6 020102030405
2465cc26e63SRyan Stone  *     iov (NVLIST):
2475cc26e63SRyan Stone  */
2485cc26e63SRyan Stone struct pci_iov_arg
2495cc26e63SRyan Stone {
2505cc26e63SRyan Stone 	void *config;
2515cc26e63SRyan Stone 	size_t len;
2525cc26e63SRyan Stone };
2535cc26e63SRyan Stone 
2545cc26e63SRyan Stone #define	IOV_CONFIG	_IOW('p', 10, struct pci_iov_arg)
2556c3162c4SRyan Stone #define	IOV_DELETE	_IO('p', 11)
2561191f715SRyan Stone #define	IOV_GET_SCHEMA	_IOWR('p', 12, struct pci_iov_schema)
2579bfb1e36SRyan Stone 
2589bfb1e36SRyan Stone #endif
259