1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/drivers/net/ethernet/netronome/nfp/bpf/fw.h
Gustavo A. R. Silva 3f6e963305 netronome: Replace zero-length array with flexible-array member
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to declare
variable-length types such as these ones is a flexible array member[1][2],
introduced in C99:

struct foo {
        int stuff;
        struct boo array[];
};

By making use of the mechanism above, we will get a compiler warning
in case the flexible array does not occur last in the structure, which
will help us prevent some kind of undefined behavior bugs from being
inadvertently introduced[3] to the codebase from now on.

Also, notice that, dynamic memory allocations won't be affected by
this change:

"Flexible array members have incomplete type, and so the sizeof operator
may not be applied. As a quirk of the original implementation of
zero-length arrays, sizeof evaluates to zero."[1]

This issue was found with the help of Coccinelle.

[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://github.com/KSPP/linux/issues/21
[3] commit 7649773293 ("cxgb3/l2t: Fix undefined behaviour")

Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2020-02-24 15:26:17 -08:00

125 lines
2.5 KiB
C

/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
/* Copyright (C) 2017-2018 Netronome Systems, Inc. */
#ifndef NFP_BPF_FW_H
#define NFP_BPF_FW_H 1
#include <linux/bitops.h>
#include <linux/types.h>
#include "../ccm.h"
/* Kernel's enum bpf_reg_type is not uABI so people may change it breaking
* our FW ABI. In that case we will do translation in the driver.
*/
#define NFP_BPF_SCALAR_VALUE 1
#define NFP_BPF_MAP_VALUE 4
#define NFP_BPF_STACK 6
#define NFP_BPF_PACKET_DATA 8
enum bpf_cap_tlv_type {
NFP_BPF_CAP_TYPE_FUNC = 1,
NFP_BPF_CAP_TYPE_ADJUST_HEAD = 2,
NFP_BPF_CAP_TYPE_MAPS = 3,
NFP_BPF_CAP_TYPE_RANDOM = 4,
NFP_BPF_CAP_TYPE_QUEUE_SELECT = 5,
NFP_BPF_CAP_TYPE_ADJUST_TAIL = 6,
NFP_BPF_CAP_TYPE_ABI_VERSION = 7,
NFP_BPF_CAP_TYPE_CMSG_MULTI_ENT = 8,
};
struct nfp_bpf_cap_tlv_func {
__le32 func_id;
__le32 func_addr;
};
struct nfp_bpf_cap_tlv_adjust_head {
__le32 flags;
__le32 off_min;
__le32 off_max;
__le32 guaranteed_sub;
__le32 guaranteed_add;
};
#define NFP_BPF_ADJUST_HEAD_NO_META BIT(0)
struct nfp_bpf_cap_tlv_maps {
__le32 types;
__le32 max_maps;
__le32 max_elems;
__le32 max_key_sz;
__le32 max_val_sz;
__le32 max_elem_sz;
};
/*
* Types defined for map related control messages
*/
/* BPF ABIv2 fixed-length control message fields */
#define CMSG_MAP_KEY_LW 16
#define CMSG_MAP_VALUE_LW 16
enum nfp_bpf_cmsg_status {
CMSG_RC_SUCCESS = 0,
CMSG_RC_ERR_MAP_FD = 1,
CMSG_RC_ERR_MAP_NOENT = 2,
CMSG_RC_ERR_MAP_ERR = 3,
CMSG_RC_ERR_MAP_PARSE = 4,
CMSG_RC_ERR_MAP_EXIST = 5,
CMSG_RC_ERR_MAP_NOMEM = 6,
CMSG_RC_ERR_MAP_E2BIG = 7,
};
struct cmsg_reply_map_simple {
struct nfp_ccm_hdr hdr;
__be32 rc;
};
struct cmsg_req_map_alloc_tbl {
struct nfp_ccm_hdr hdr;
__be32 key_size; /* in bytes */
__be32 value_size; /* in bytes */
__be32 max_entries;
__be32 map_type;
__be32 map_flags; /* reserved */
};
struct cmsg_reply_map_alloc_tbl {
struct cmsg_reply_map_simple reply_hdr;
__be32 tid;
};
struct cmsg_req_map_free_tbl {
struct nfp_ccm_hdr hdr;
__be32 tid;
};
struct cmsg_reply_map_free_tbl {
struct cmsg_reply_map_simple reply_hdr;
__be32 count;
};
struct cmsg_req_map_op {
struct nfp_ccm_hdr hdr;
__be32 tid;
__be32 count;
__be32 flags;
u8 data[];
};
struct cmsg_reply_map_op {
struct cmsg_reply_map_simple reply_hdr;
__be32 count;
__be32 resv;
u8 data[];
};
struct cmsg_bpf_event {
struct nfp_ccm_hdr hdr;
__be32 cpu_id;
__be64 map_ptr;
__be32 data_size;
__be32 pkt_size;
u8 data[];
};
#endif