1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Copyright (C) 2018 Netronome Systems, Inc. */
4 #include <linux/bitfield.h>
5 #include <linux/device.h>
6 #include <linux/kernel.h>
7 #include <linux/types.h>
9 #include "nfp_net_ctrl.h"
12 static void nfp_net_tlv_caps_reset(struct nfp_net_tlv_caps
*caps
)
14 memset(caps
, 0, sizeof(*caps
));
15 caps
->me_freq_mhz
= 1200;
16 caps
->mbox_off
= NFP_NET_CFG_MBOX_BASE
;
17 caps
->mbox_len
= NFP_NET_CFG_MBOX_VAL_MAX_SZ
;
21 nfp_net_tls_parse_crypto_ops(struct device
*dev
, struct nfp_net_tlv_caps
*caps
,
22 u8 __iomem
*ctrl_mem
, u8 __iomem
*data
,
23 unsigned int length
, unsigned int offset
,
26 /* Ignore the legacy TLV if new one was already parsed */
27 if (caps
->tls_resync_ss
&& !rx_stream_scan
)
32 "CRYPTO OPS TLV should be at least 32B, is %dB offset:%u\n",
37 caps
->crypto_ops
= readl(data
);
38 caps
->crypto_enable_off
= data
- ctrl_mem
+ 16;
39 caps
->tls_resync_ss
= rx_stream_scan
;
44 int nfp_net_tlv_caps_parse(struct device
*dev
, u8 __iomem
*ctrl_mem
,
45 struct nfp_net_tlv_caps
*caps
)
47 u8 __iomem
*data
= ctrl_mem
+ NFP_NET_CFG_TLV_BASE
;
48 u8 __iomem
*end
= ctrl_mem
+ NFP_NET_CFG_BAR_SZ
;
51 nfp_net_tlv_caps_reset(caps
);
58 unsigned int length
, offset
;
59 u32 hdr
= readl(data
);
61 length
= FIELD_GET(NFP_NET_CFG_TLV_HEADER_LENGTH
, hdr
);
62 offset
= data
- ctrl_mem
;
64 /* Advance past the header */
67 if (length
% NFP_NET_CFG_TLV_LENGTH_INC
) {
68 dev_err(dev
, "TLV size not multiple of %u offset:%u len:%u\n",
69 NFP_NET_CFG_TLV_LENGTH_INC
, offset
, length
);
72 if (data
+ length
> end
) {
73 dev_err(dev
, "oversized TLV offset:%u len:%u\n",
78 switch (FIELD_GET(NFP_NET_CFG_TLV_HEADER_TYPE
, hdr
)) {
79 case NFP_NET_CFG_TLV_TYPE_UNKNOWN
:
80 dev_err(dev
, "NULL TLV at offset:%u\n", offset
);
82 case NFP_NET_CFG_TLV_TYPE_RESERVED
:
84 case NFP_NET_CFG_TLV_TYPE_END
:
88 dev_err(dev
, "END TLV should be empty, has offset:%u len:%d\n",
91 case NFP_NET_CFG_TLV_TYPE_ME_FREQ
:
94 "ME FREQ TLV should be 4B, is %dB offset:%u\n",
99 caps
->me_freq_mhz
= readl(data
);
101 case NFP_NET_CFG_TLV_TYPE_MBOX
:
106 caps
->mbox_off
= data
- ctrl_mem
;
107 caps
->mbox_len
= length
;
110 case NFP_NET_CFG_TLV_TYPE_EXPERIMENTAL0
:
111 case NFP_NET_CFG_TLV_TYPE_EXPERIMENTAL1
:
113 "experimental TLV type:%u offset:%u len:%u\n",
114 FIELD_GET(NFP_NET_CFG_TLV_HEADER_TYPE
, hdr
),
117 case NFP_NET_CFG_TLV_TYPE_REPR_CAP
:
119 dev_err(dev
, "REPR CAP TLV short %dB < 4B offset:%u\n",
124 caps
->repr_cap
= readl(data
);
126 case NFP_NET_CFG_TLV_TYPE_MBOX_CMSG_TYPES
:
128 caps
->mbox_cmsg_types
= readl(data
);
130 case NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS
:
131 if (!nfp_net_tls_parse_crypto_ops(dev
, caps
, ctrl_mem
,
132 data
, length
, offset
,
136 case NFP_NET_CFG_TLV_TYPE_VNIC_STATS
:
137 if ((data
- ctrl_mem
) % 8) {
138 dev_warn(dev
, "VNIC STATS TLV misaligned, ignoring offset:%u len:%u\n",
142 caps
->vnic_stats_off
= data
- ctrl_mem
;
143 caps
->vnic_stats_cnt
= length
/ 10;
145 case NFP_NET_CFG_TLV_TYPE_CRYPTO_OPS_RX_SCAN
:
146 if (!nfp_net_tls_parse_crypto_ops(dev
, caps
, ctrl_mem
,
147 data
, length
, offset
,
152 if (!FIELD_GET(NFP_NET_CFG_TLV_HEADER_REQUIRED
, hdr
))
155 dev_err(dev
, "unknown TLV type:%u offset:%u len:%u\n",
156 FIELD_GET(NFP_NET_CFG_TLV_HEADER_TYPE
, hdr
),
162 if (data
+ 4 > end
) {
163 dev_err(dev
, "reached end of BAR without END TLV\n");