Skip to content

Commit f54a373

Browse files
committed
Merge: CNB97: devlink: add support for clock_id generic parameter
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/7157 JIRA: https://issues.redhat.com/browse/RHEL-105064 This adds support for new devlink generic paramter clock_id. Signed-off-by: Ivan Vecera <ivecera@redhat.com> Approved-by: Murphy Zhou <xzhou@redhat.com> Approved-by: Petr Oros <poros@redhat.com> Approved-by: mheib <mheib@redhat.com> Approved-by: Sabrina Dubroca <sdubroca@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: Augusto Caringi <acaringi@redhat.com>
2 parents 32f0857 + 2efd9b8 commit f54a373

File tree

9 files changed

+145
-84
lines changed

9 files changed

+145
-84
lines changed

Documentation/netlink/specs/devlink.yaml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ definitions:
3838
-
3939
name: dsa
4040
-
41-
name: pci_pf
41+
name: pci-pf
4242
-
43-
name: pci_vf
43+
name: pci-vf
4444
-
4545
name: virtual
4646
-
4747
name: unused
4848
-
49-
name: pci_sf
49+
name: pci-sf
5050
-
5151
type: enum
5252
name: port-fn-state
@@ -202,6 +202,28 @@ definitions:
202202
name: exception
203203
-
204204
name: control
205+
-
206+
type: enum
207+
name: var-attr-type
208+
entries:
209+
-
210+
name: u8
211+
value: 1
212+
-
213+
name: u16
214+
-
215+
name: u32
216+
-
217+
name: u64
218+
-
219+
name: string
220+
-
221+
name: flag
222+
-
223+
name: nul-string
224+
value: 10
225+
-
226+
name: binary
205227

206228
attribute-sets:
207229
-
@@ -498,6 +520,7 @@ attribute-sets:
498520
-
499521
name: param-type
500522
type: u8
523+
enum: var-attr-type
501524

502525
# TODO: fill in the attributes in between
503526

@@ -592,6 +615,7 @@ attribute-sets:
592615
-
593616
name: fmsg-obj-value-type
594617
type: u8
618+
enum: var-attr-type
595619

596620
# TODO: fill in the attributes in between
597621

Documentation/networking/devlink/devlink-params.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ own name.
137137
* - ``event_eq_size``
138138
- u32
139139
- Control the size of asynchronous control events EQ.
140+
* - ``enable_phc``
141+
- Boolean
142+
- Enable PHC (PTP Hardware Clock) functionality in the device.
143+
* - ``clock_id``
144+
- u64
145+
- Clock ID used by the device for registering DPLL devices and pins.

include/net/devlink.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,17 +439,19 @@ typedef u64 devlink_resource_occ_get_t(void *priv);
439439

440440
#define __DEVLINK_PARAM_MAX_STRING_VALUE 32
441441
enum devlink_param_type {
442-
DEVLINK_PARAM_TYPE_U8,
443-
DEVLINK_PARAM_TYPE_U16,
444-
DEVLINK_PARAM_TYPE_U32,
445-
DEVLINK_PARAM_TYPE_STRING,
446-
DEVLINK_PARAM_TYPE_BOOL,
442+
DEVLINK_PARAM_TYPE_U8 = DEVLINK_VAR_ATTR_TYPE_U8,
443+
DEVLINK_PARAM_TYPE_U16 = DEVLINK_VAR_ATTR_TYPE_U16,
444+
DEVLINK_PARAM_TYPE_U32 = DEVLINK_VAR_ATTR_TYPE_U32,
445+
DEVLINK_PARAM_TYPE_U64 = DEVLINK_VAR_ATTR_TYPE_U64,
446+
DEVLINK_PARAM_TYPE_STRING = DEVLINK_VAR_ATTR_TYPE_STRING,
447+
DEVLINK_PARAM_TYPE_BOOL = DEVLINK_VAR_ATTR_TYPE_FLAG,
447448
};
448449

449450
union devlink_param_value {
450451
u8 vu8;
451452
u16 vu16;
452453
u32 vu32;
454+
u64 vu64;
453455
char vstr[__DEVLINK_PARAM_MAX_STRING_VALUE];
454456
bool vbool;
455457
};
@@ -539,6 +541,8 @@ enum devlink_param_generic_id {
539541
DEVLINK_PARAM_GENERIC_ID_ENABLE_IWARP,
540542
DEVLINK_PARAM_GENERIC_ID_IO_EQ_SIZE,
541543
DEVLINK_PARAM_GENERIC_ID_EVENT_EQ_SIZE,
544+
DEVLINK_PARAM_GENERIC_ID_ENABLE_PHC,
545+
DEVLINK_PARAM_GENERIC_ID_CLOCK_ID,
542546

543547
/* add new param generic ids above here*/
544548
__DEVLINK_PARAM_GENERIC_ID_MAX,
@@ -597,6 +601,12 @@ enum devlink_param_generic_id {
597601
#define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_NAME "event_eq_size"
598602
#define DEVLINK_PARAM_GENERIC_EVENT_EQ_SIZE_TYPE DEVLINK_PARAM_TYPE_U32
599603

604+
#define DEVLINK_PARAM_GENERIC_ENABLE_PHC_NAME "enable_phc"
605+
#define DEVLINK_PARAM_GENERIC_ENABLE_PHC_TYPE DEVLINK_PARAM_TYPE_BOOL
606+
607+
#define DEVLINK_PARAM_GENERIC_CLOCK_ID_NAME "clock_id"
608+
#define DEVLINK_PARAM_GENERIC_CLOCK_ID_TYPE DEVLINK_PARAM_TYPE_U64
609+
600610
#define DEVLINK_PARAM_GENERIC(_id, _cmodes, _get, _set, _validate) \
601611
{ \
602612
.id = DEVLINK_PARAM_GENERIC_ID_##_id, \

include/net/netlink.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,13 @@ enum nla_policy_validation {
320320
* All other Unused - but note that it's a union
321321
*
322322
* Meaning of `validate' field, use via NLA_POLICY_VALIDATE_FN:
323+
* NLA_U8, NLA_U16,
324+
* NLA_U32, NLA_U64,
325+
* NLA_S8, NLA_S16,
326+
* NLA_S32, NLA_S64,
327+
* NLA_MSECS,
323328
* NLA_BINARY Validation function called for the attribute.
329+
*
324330
* All other Unused - but note that it's a union
325331
*
326332
* Example:

include/uapi/linux/devlink.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,21 @@ enum devlink_linecard_state {
385385
DEVLINK_LINECARD_STATE_MAX = __DEVLINK_LINECARD_STATE_MAX - 1
386386
};
387387

388+
/* Variable attribute type. */
389+
enum devlink_var_attr_type {
390+
/* Following values relate to the internal NLA_* values */
391+
DEVLINK_VAR_ATTR_TYPE_U8 = 1,
392+
DEVLINK_VAR_ATTR_TYPE_U16,
393+
DEVLINK_VAR_ATTR_TYPE_U32,
394+
DEVLINK_VAR_ATTR_TYPE_U64,
395+
DEVLINK_VAR_ATTR_TYPE_STRING,
396+
DEVLINK_VAR_ATTR_TYPE_FLAG,
397+
DEVLINK_VAR_ATTR_TYPE_NUL_STRING = 10,
398+
DEVLINK_VAR_ATTR_TYPE_BINARY,
399+
__DEVLINK_VAR_ATTR_TYPE_CUSTOM_BASE = 0x80,
400+
/* Any possible custom types, unrelated to NLA_* values go below */
401+
};
402+
388403
enum devlink_attr {
389404
/* don't change the order or add anything between, this is ABI! */
390405
DEVLINK_ATTR_UNSPEC,

net/devlink/health.c

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ static void devlink_fmsg_put_name(struct devlink_fmsg *fmsg, const char *name)
735735
return;
736736
}
737737

738-
item->nla_type = NLA_NUL_STRING;
738+
item->nla_type = DEVLINK_VAR_ATTR_TYPE_NUL_STRING;
739739
item->len = strlen(name) + 1;
740740
item->attrtype = DEVLINK_ATTR_FMSG_OBJ_NAME;
741741
memcpy(&item->value, name, item->len);
@@ -822,32 +822,37 @@ static void devlink_fmsg_put_value(struct devlink_fmsg *fmsg,
822822
static void devlink_fmsg_bool_put(struct devlink_fmsg *fmsg, bool value)
823823
{
824824
devlink_fmsg_err_if_binary(fmsg);
825-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_FLAG);
825+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
826+
DEVLINK_VAR_ATTR_TYPE_FLAG);
826827
}
827828

828829
static void devlink_fmsg_u8_put(struct devlink_fmsg *fmsg, u8 value)
829830
{
830831
devlink_fmsg_err_if_binary(fmsg);
831-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U8);
832+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
833+
DEVLINK_VAR_ATTR_TYPE_U8);
832834
}
833835

834836
void devlink_fmsg_u32_put(struct devlink_fmsg *fmsg, u32 value)
835837
{
836838
devlink_fmsg_err_if_binary(fmsg);
837-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U32);
839+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
840+
DEVLINK_VAR_ATTR_TYPE_U32);
838841
}
839842
EXPORT_SYMBOL_GPL(devlink_fmsg_u32_put);
840843

841844
static void devlink_fmsg_u64_put(struct devlink_fmsg *fmsg, u64 value)
842845
{
843846
devlink_fmsg_err_if_binary(fmsg);
844-
devlink_fmsg_put_value(fmsg, &value, sizeof(value), NLA_U64);
847+
devlink_fmsg_put_value(fmsg, &value, sizeof(value),
848+
DEVLINK_VAR_ATTR_TYPE_U64);
845849
}
846850

847851
void devlink_fmsg_string_put(struct devlink_fmsg *fmsg, const char *value)
848852
{
849853
devlink_fmsg_err_if_binary(fmsg);
850-
devlink_fmsg_put_value(fmsg, value, strlen(value) + 1, NLA_NUL_STRING);
854+
devlink_fmsg_put_value(fmsg, value, strlen(value) + 1,
855+
DEVLINK_VAR_ATTR_TYPE_NUL_STRING);
851856
}
852857
EXPORT_SYMBOL_GPL(devlink_fmsg_string_put);
853858

@@ -857,7 +862,8 @@ void devlink_fmsg_binary_put(struct devlink_fmsg *fmsg, const void *value,
857862
if (!fmsg->err && !fmsg->putting_binary)
858863
fmsg->err = -EINVAL;
859864

860-
devlink_fmsg_put_value(fmsg, value, value_len, NLA_BINARY);
865+
devlink_fmsg_put_value(fmsg, value, value_len,
866+
DEVLINK_VAR_ATTR_TYPE_BINARY);
861867
}
862868
EXPORT_SYMBOL_GPL(devlink_fmsg_binary_put);
863869

@@ -927,44 +933,27 @@ void devlink_fmsg_binary_pair_put(struct devlink_fmsg *fmsg, const char *name,
927933
}
928934
EXPORT_SYMBOL_GPL(devlink_fmsg_binary_pair_put);
929935

930-
static int
931-
devlink_fmsg_item_fill_type(struct devlink_fmsg_item *msg, struct sk_buff *skb)
932-
{
933-
switch (msg->nla_type) {
934-
case NLA_FLAG:
935-
case NLA_U8:
936-
case NLA_U32:
937-
case NLA_U64:
938-
case NLA_NUL_STRING:
939-
case NLA_BINARY:
940-
return nla_put_u8(skb, DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE,
941-
msg->nla_type);
942-
default:
943-
return -EINVAL;
944-
}
945-
}
946-
947936
static int
948937
devlink_fmsg_item_fill_data(struct devlink_fmsg_item *msg, struct sk_buff *skb)
949938
{
950939
int attrtype = DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA;
951940
u8 tmp;
952941

953942
switch (msg->nla_type) {
954-
case NLA_FLAG:
943+
case DEVLINK_VAR_ATTR_TYPE_FLAG:
955944
/* Always provide flag data, regardless of its value */
956945
tmp = *(bool *)msg->value;
957946

958947
return nla_put_u8(skb, attrtype, tmp);
959-
case NLA_U8:
948+
case DEVLINK_VAR_ATTR_TYPE_U8:
960949
return nla_put_u8(skb, attrtype, *(u8 *)msg->value);
961-
case NLA_U32:
950+
case DEVLINK_VAR_ATTR_TYPE_U32:
962951
return nla_put_u32(skb, attrtype, *(u32 *)msg->value);
963-
case NLA_U64:
952+
case DEVLINK_VAR_ATTR_TYPE_U64:
964953
return devlink_nl_put_u64(skb, attrtype, *(u64 *)msg->value);
965-
case NLA_NUL_STRING:
954+
case DEVLINK_VAR_ATTR_TYPE_NUL_STRING:
966955
return nla_put_string(skb, attrtype, (char *)&msg->value);
967-
case NLA_BINARY:
956+
case DEVLINK_VAR_ATTR_TYPE_BINARY:
968957
return nla_put(skb, attrtype, msg->len, (void *)&msg->value);
969958
default:
970959
return -EINVAL;
@@ -998,7 +987,8 @@ devlink_fmsg_prepare_skb(struct devlink_fmsg *fmsg, struct sk_buff *skb,
998987
err = nla_put_flag(skb, item->attrtype);
999988
break;
1000989
case DEVLINK_ATTR_FMSG_OBJ_VALUE_DATA:
1001-
err = devlink_fmsg_item_fill_type(item, skb);
990+
err = nla_put_u8(skb, DEVLINK_ATTR_FMSG_OBJ_VALUE_TYPE,
991+
item->nla_type);
1002992
if (err)
1003993
break;
1004994
err = devlink_fmsg_item_fill_data(item, skb);

net/devlink/netlink_gen.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,33 @@
1010

1111
#include <uapi/linux/devlink.h>
1212

13+
/* Sparse enums validation callbacks */
14+
static int
15+
devlink_attr_param_type_validate(const struct nlattr *attr,
16+
struct netlink_ext_ack *extack)
17+
{
18+
switch (nla_get_u8(attr)) {
19+
case DEVLINK_VAR_ATTR_TYPE_U8:
20+
fallthrough;
21+
case DEVLINK_VAR_ATTR_TYPE_U16:
22+
fallthrough;
23+
case DEVLINK_VAR_ATTR_TYPE_U32:
24+
fallthrough;
25+
case DEVLINK_VAR_ATTR_TYPE_U64:
26+
fallthrough;
27+
case DEVLINK_VAR_ATTR_TYPE_STRING:
28+
fallthrough;
29+
case DEVLINK_VAR_ATTR_TYPE_FLAG:
30+
fallthrough;
31+
case DEVLINK_VAR_ATTR_TYPE_NUL_STRING:
32+
fallthrough;
33+
case DEVLINK_VAR_ATTR_TYPE_BINARY:
34+
return 0;
35+
}
36+
NL_SET_ERR_MSG_ATTR(extack, attr, "invalid enum value");
37+
return -EINVAL;
38+
}
39+
1340
/* Common nested types */
1441
const struct nla_policy devlink_dl_port_function_nl_policy[DEVLINK_PORT_FN_ATTR_CAPS + 1] = {
1542
[DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR] = { .type = NLA_BINARY, },
@@ -273,7 +300,7 @@ static const struct nla_policy devlink_param_set_nl_policy[DEVLINK_ATTR_PARAM_VA
273300
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
274301
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
275302
[DEVLINK_ATTR_PARAM_NAME] = { .type = NLA_NUL_STRING, },
276-
[DEVLINK_ATTR_PARAM_TYPE] = { .type = NLA_U8, },
303+
[DEVLINK_ATTR_PARAM_TYPE] = NLA_POLICY_VALIDATE_FN(NLA_U8, &devlink_attr_param_type_validate),
277304
[DEVLINK_ATTR_PARAM_VALUE_CMODE] = NLA_POLICY_MAX(NLA_U8, 2),
278305
};
279306

0 commit comments

Comments
 (0)