1 From e478ab518612f1a821968e1bb5b08b01b10085b0 Mon Sep 17 00:00:00 2001
2 From: Po Liu <Po.Liu@nxp.com>
3 Date: Tue, 15 Oct 2019 16:11:40 +0800
4 Subject: [PATCH] net:tsn: netlink interface for APP layer to config TSN
5 capability hardware ports
7 This patch provids netlink method to configure the TSN protocols hardwares.
8 TSN guaranteed packet transport with bounded low latency, low packet delay
9 variation, and low packet loss by hardware and software methods.
11 The three basic components of TSN are:
13 1. Time synchronization: This was implement by 8021AS which base on the
14 IEEE1588 precision Time Protocol. This is configured by the other way
16 8021AS not included in this patch.
18 2. Scheduling and traffic shaping and per-stream filter policing:
19 This patch support Qbv/Qci/Qbu/8021CB/Qav etc.
21 3. Selection of communication paths:
22 This patch not support the pure software only TSN protocols(like Qcc)
23 but hardware related configuration.
25 TSN Protocols supports by this patch: Qbv/Qci/Qbu/Credit-base Shaper(Qav).
26 This patch verified on NXP ls1028ardb board.
28 Signed-off-by: Po Liu <Po.Liu@nxp.com>
30 include/net/tsn.h | 114 ++
31 include/uapi/linux/tsn.h | 1207 +++++++++++++++
34 net/tsn/Kconfig | 15 +
35 net/tsn/Makefile | 1 +
36 net/tsn/genl_tsn.c | 3696 ++++++++++++++++++++++++++++++++++++++++++++++
37 7 files changed, 5037 insertions(+)
38 create mode 100644 include/net/tsn.h
39 create mode 100644 include/uapi/linux/tsn.h
40 create mode 100644 net/tsn/Kconfig
41 create mode 100644 net/tsn/Makefile
42 create mode 100644 net/tsn/genl_tsn.c
45 +++ b/include/net/tsn.h
47 +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
48 +/* Copyright 2017-2019 NXP */
53 +#include <linux/notifier.h>
54 +#include <uapi/linux/tsn.h>
56 +enum tsn_notifier_type {
57 + TSN_QBV_CONFIGCHANGETIME_ARRIVE = 1,
60 +struct tsn_notifier_info {
61 + struct net_device *dev;
63 + struct tsn_qbv_conf qbv_notify;
64 + struct tsn_qci_psfp_sgi_conf qci_notify;
68 +static inline struct net_device *
69 +tsn_notifier_info_to_dev(const struct tsn_notifier_info *info)
75 + void (*device_init)(struct net_device *ndev);
76 + void (*device_deinit)(struct net_device *ndev);
77 + u32 (*get_capability)(struct net_device *ndev);
79 + int (*qbv_set)(struct net_device *ndev, struct tsn_qbv_conf *qbvconf);
80 + int (*qbv_get)(struct net_device *ndev, struct tsn_qbv_conf *qbvconf);
81 + int (*qbv_get_status)(struct net_device *ndev,
82 + struct tsn_qbv_status *qbvstat);
83 + int (*cb_streamid_set)(struct net_device *ndev, u32 index,
84 + bool enable, struct tsn_cb_streamid *sid);
85 + int (*cb_streamid_get)(struct net_device *ndev, u32 index,
86 + struct tsn_cb_streamid *sid);
87 + int (*cb_streamid_counters_get)(struct net_device *ndev, u32 index,
88 + struct tsn_cb_streamid_counters *sidcounter);
89 + int (*qci_get_maxcap)(struct net_device *ndev,
90 + struct tsn_qci_psfp_stream_param *qcicapa);
91 + int (*qci_sfi_set)(struct net_device *ndev, u32 index, bool enable,
92 + struct tsn_qci_psfp_sfi_conf *sficonf);
93 + /* return: 0 stream filter instance not valid
94 + * 1 stream filter instance valid
97 + int (*qci_sfi_get)(struct net_device *ndev, u32 index,
98 + struct tsn_qci_psfp_sfi_conf *sficonf);
99 + int (*qci_sfi_counters_get)(struct net_device *ndev, u32 index,
100 + struct tsn_qci_psfp_sfi_counters *sficounter);
101 + int (*qci_sgi_set)(struct net_device *ndev, u32 index,
102 + struct tsn_qci_psfp_sgi_conf *sgiconf);
103 + int (*qci_sgi_get)(struct net_device *ndev, u32 index,
104 + struct tsn_qci_psfp_sgi_conf *sgiconf);
105 + int (*qci_sgi_status_get)(struct net_device *ndev, u16 index,
106 + struct tsn_psfp_sgi_status *sgistat);
107 + int (*qci_fmi_set)(struct net_device *ndev, u32 index, bool enable,
108 + struct tsn_qci_psfp_fmi *fmi);
109 + int (*qci_fmi_get)(struct net_device *ndev, u32 index,
110 + struct tsn_qci_psfp_fmi *fmi,
111 + struct tsn_qci_psfp_fmi_counters *counters);
112 + int (*cbs_set)(struct net_device *ndev, u8 tc, u8 bw);
113 + int (*cbs_get)(struct net_device *ndev, u8 tc);
114 + /* To set a 8 bits vector shows 8 traffic classes
115 + * preemtable(1) or express(0)
117 + int (*qbu_set)(struct net_device *ndev, u8 ptvector);
118 + /* To get port preemtion status */
119 + int (*qbu_get)(struct net_device *ndev,
120 + struct tsn_preempt_status *preemptstat);
121 + int (*tsd_set)(struct net_device *ndev, struct tsn_tsd *tsd);
122 + int (*tsd_get)(struct net_device *ndev, struct tsn_tsd_status *stats);
123 + int (*ct_set)(struct net_device *ndev, u8 cut_thru);
124 + int (*cbgen_set)(struct net_device *ndev, u32 index,
125 + struct tsn_seq_gen_conf *seqgen);
126 + int (*cbrec_set)(struct net_device *ndev, u32 index,
127 + struct tsn_seq_rec_conf *seqrec);
128 + int (*cb_get)(struct net_device *ndev, u32 index,
129 + struct tsn_cb_status *c);
130 + int (*dscp_set)(struct net_device *ndev, bool enable,
132 + struct tsn_qos_switch_dscp_conf *c);
140 +#define GROUP_OFFSET_SWITCH 256
144 + struct tsn_ops *tsnops;
145 + struct net_device *netdev;
146 + struct list_head list;
147 + enum ethdev_type type;
149 + struct tsn_notifier_info nd;
152 +struct tsn_port *tsn_get_port(struct net_device *ndev);
153 +int register_tsn_notifier(struct notifier_block *nb);
154 +int unregister_tsn_notifier(struct notifier_block *nb);
155 +int call_tsn_notifiers(unsigned long val, struct net_device *dev,
156 + struct tsn_notifier_info *info);
157 +int tsn_port_register(struct net_device *netdev,
158 + struct tsn_ops *tsnops, u16 groupid);
159 +void tsn_port_unregister(struct net_device *netdev);
162 +++ b/include/uapi/linux/tsn.h
164 +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */
165 +/* Copyright 2017-2019 NXP */
167 +#ifndef __UAPI_GENL_TSN_H
168 +#define __UAPI_GENL_TSN_H
170 +#define TSN_GENL_NAME "TSN_GEN_CTRL"
171 +#define TSN_GENL_VERSION 0x1
173 +#define MAX_USER_SIZE 0
174 +#define MAX_ATTR_SIZE 3072
175 +#define MAX_TOTAL_MSG_SIZE (MAX_USER_SIZE + MAX_ATTR_SIZE)
176 +#define MAX_ENTRY_SIZE 2048
177 +#define MAX_ENTRY_NUMBER 128
178 +#define MAX_IFNAME_COUNT 64
180 +#define TSN_MULTICAST_GROUP_QBV "qbv"
181 +#define TSN_MULTICAST_GROUP_QCI "qci"
183 +/* multicast groups */
184 +enum tsn_multicast_groups {
190 +enum tsn_capability {
194 + TSN_CAP_CBS = 0x8, /* Credit-based Shapter Qav */
195 + TSN_CAP_CB = 0x10, /* 8021CB redundancy and replication */
196 + TSN_CAP_TBS = 0x20, /* Time Based schedule */
197 + TSN_CAP_CTH = 0x40, /* cut through */
201 + * Commands sent from userspace
202 + * Not versioned. New commands should only be inserted at the enum's end
203 + * prior to __TSN_CMD_MAX
207 + TSN_CMD_UNSPEC = 0, /* Reserved */
210 + TSN_CMD_QBV_GET_STATUS,
211 + TSN_CMD_CB_STREAMID_SET,
212 + TSN_CMD_CB_STREAMID_GET,
213 + TSN_CMD_CB_STREAMID_GET_COUNTS,
214 + TSN_CMD_QCI_CAP_GET, /* Qci capability get length capability get */
215 + TSN_CMD_QCI_SFI_SET,
216 + TSN_CMD_QCI_SFI_GET,
217 + TSN_CMD_QCI_SFI_GET_COUNTS,
218 + TSN_CMD_QCI_SGI_SET,
219 + TSN_CMD_QCI_SGI_GET,
220 + TSN_CMD_QCI_SGI_GET_STATUS,
221 + TSN_CMD_QCI_FMI_SET,
222 + TSN_CMD_QCI_FMI_GET,
226 + TSN_CMD_QBU_GET_STATUS,
227 + TSN_CMD_QAV_SET_CBS,
228 + TSN_CMD_QAV_GET_CBS,
234 + TSN_CMD_CBSTAT_GET,
235 + TSN_CMD_PCPMAP_SET_UNUSE,
237 + TSN_CMD_ECHO, /* user->kernel request/get-response */
238 + TSN_CMD_REPLY, /* kernel->user event */
242 +#define TSN_CMD_MAX (__TSN_CMD_MAX - 1)
246 + TSN_CMD_ATTR_UNSPEC = 0,
247 + TSN_CMD_ATTR_MESG, /* demo message */
248 + TSN_CMD_ATTR_DATA, /* demo data */
250 + TSN_ATTR_PORT_NUMBER,
252 + TSN_ATTR_STREAM_IDENTIFY, /* stream identify */
253 + TSN_ATTR_QCI_SP, /* psfp port capbility parameters */
254 + TSN_ATTR_QCI_SFI, /* psfp stream filter instance */
255 + TSN_ATTR_QCI_SGI, /* psfp stream gate instance */
256 + TSN_ATTR_QCI_FMI, /* psfp flow meter instance */
257 + TSN_ATTR_CBS, /* credit-based shaper */
258 + TSN_ATTR_TSD, /* Time Specific Departure */
259 + TSN_ATTR_QBU, /* preemption */
260 + TSN_ATTR_CT, /* cut through */
261 + TSN_ATTR_CBGEN, /* 802.1CB sequence generate */
262 + TSN_ATTR_CBREC, /* 802.1CB sequence recover */
263 + TSN_ATTR_CBSTAT, /* 802.1CB status */
264 + TSN_ATTR_PCPMAP_UNUSE,
266 + TSN_ATTR_CAP, /* TSN capbility */
267 + __TSN_CMD_ATTR_MAX,
269 +#define TSN_CMD_ATTR_MAX (__TSN_CMD_ATTR_MAX - 1)
272 + TSN_CAP_ATTR_UNSPEC,
280 + __TSN_CAP_ATTR_MAX,
281 + TSN_CAP_ATTR_MAX = __TSN_CAP_ATTR_MAX - 1,
285 + TSN_QBU_ATTR_UNSPEC,
286 + TSN_QBU_ATTR_ADMIN_STATE,
287 + TSN_QBU_ATTR_HOLD_ADVANCE,
288 + TSN_QBU_ATTR_RELEASE_ADVANCE,
289 + TSN_QBU_ATTR_ACTIVE,
290 + TSN_QBU_ATTR_HOLD_REQUEST,
291 + __TSN_QBU_ATTR_MAX,
292 + TSN_QBU_ATTR_MAX = __TSN_QBU_ATTR_MAX - 1,
296 + TSN_CBS_ATTR_UNSPEC,
297 + TSN_CBS_ATTR_TC_INDEX,
299 + __TSN_CBS_ATTR_MAX,
300 + TSN_CBS_ATTR_MAX = __TSN_CBS_ATTR_MAX - 1,
304 + TSN_TSD_ATTR_UNSPEC,
305 + TSN_TSD_ATTR_DISABLE,
306 + TSN_TSD_ATTR_ENABLE,
307 + TSN_TSD_ATTR_PERIOD,
308 + TSN_TSD_ATTR_MAX_FRM_NUM,
309 + TSN_TSD_ATTR_CYCLE_NUM,
310 + TSN_TSD_ATTR_LOSS_STEPS,
311 + TSN_TSD_ATTR_SYN_IMME,
312 + __TSN_TSD_ATTR_MAX,
313 + TSN_TSD_ATTR_MAX = __TSN_TSD_ATTR_MAX - 1,
317 + TSN_STREAMID_ATTR_UNSPEC,
318 + TSN_STREAMID_ATTR_INDEX,
319 + TSN_STREAMID_ATTR_ENABLE,
320 + TSN_STREAMID_ATTR_DISABLE,
321 + TSN_STREAMID_ATTR_STREAM_HANDLE,
322 + TSN_STREAMID_ATTR_IFOP,
323 + TSN_STREAMID_ATTR_OFOP,
324 + TSN_STREAMID_ATTR_IFIP,
325 + TSN_STREAMID_ATTR_OFIP,
326 + TSN_STREAMID_ATTR_TYPE,
327 + TSN_STREAMID_ATTR_NDMAC,
328 + TSN_STREAMID_ATTR_NTAGGED,
329 + TSN_STREAMID_ATTR_NVID,
330 + TSN_STREAMID_ATTR_SMAC,
331 + TSN_STREAMID_ATTR_STAGGED,
332 + TSN_STREAMID_ATTR_SVID,
333 + TSN_STREAMID_ATTR_COUNTERS_PSI,
334 + TSN_STREAMID_ATTR_COUNTERS_PSO,
335 + TSN_STREAMID_ATTR_COUNTERS_PSPPI,
336 + TSN_STREAMID_ATTR_COUNTERS_PSPPO,
337 + __TSN_STREAMID_ATTR_MAX,
338 + TSN_STREAMID_ATTR_MAX = __TSN_STREAMID_ATTR_MAX - 1,
342 + TSN_QCI_STREAM_ATTR_UNSPEC = 0,
343 + TSN_QCI_STREAM_ATTR_MAX_SFI,
344 + TSN_QCI_STREAM_ATTR_MAX_SGI,
345 + TSN_QCI_STREAM_ATTR_MAX_FMI,
346 + TSN_QCI_STREAM_ATTR_SLM,
347 + __TSN_QCI_STREAM_ATTR_MAX,
348 + TSN_QCI_STREAM_ATTR_MAX = __TSN_QCI_STREAM_ATTR_MAX - 1,
352 + TSN_QCI_SFI_ATTR_UNSPEC = 0,
353 + TSN_QCI_SFI_ATTR_INDEX,
354 + TSN_QCI_SFI_ATTR_ENABLE,
355 + TSN_QCI_SFI_ATTR_DISABLE,
356 + TSN_QCI_SFI_ATTR_STREAM_HANDLE,
357 + TSN_QCI_SFI_ATTR_PRIO_SPEC,
358 + TSN_QCI_SFI_ATTR_GATE_ID,
359 + TSN_QCI_SFI_ATTR_FILTER_TYPE,
360 + TSN_QCI_SFI_ATTR_FLOW_ID,
361 + TSN_QCI_SFI_ATTR_MAXSDU,
362 + TSN_QCI_SFI_ATTR_COUNTERS,
363 + TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE,
364 + TSN_QCI_SFI_ATTR_OVERSIZE,
365 + __TSN_QCI_SFI_ATTR_MAX,
366 + TSN_QCI_SFI_ATTR_MAX = __TSN_QCI_SFI_ATTR_MAX - 1,
370 + TSN_QCI_SFI_ATTR_COUNTERS_UNSPEC = 0,
371 + TSN_QCI_SFI_ATTR_MATCH,
372 + TSN_QCI_SFI_ATTR_PASS,
373 + TSN_QCI_SFI_ATTR_DROP,
374 + TSN_QCI_SFI_ATTR_SDU_DROP,
375 + TSN_QCI_SFI_ATTR_SDU_PASS,
376 + TSN_QCI_SFI_ATTR_RED,
377 + __TSN_QCI_SFI_ATTR_COUNT_MAX,
378 + TSN_QCI_SFI_ATTR_COUNT_MAX = __TSN_QCI_SFI_ATTR_COUNT_MAX - 1,
382 + TSN_QCI_SGI_ATTR_UNSPEC = 0,
383 + TSN_QCI_SGI_ATTR_INDEX,
384 + TSN_QCI_SGI_ATTR_ENABLE,
385 + TSN_QCI_SGI_ATTR_DISABLE,
386 + TSN_QCI_SGI_ATTR_CONFCHANGE,
387 + TSN_QCI_SGI_ATTR_IRXEN, /* Invalid rx enable*/
388 + TSN_QCI_SGI_ATTR_IRX,
389 + TSN_QCI_SGI_ATTR_OEXEN, /* Octet exceed enable */
390 + TSN_QCI_SGI_ATTR_OEX,
391 + TSN_QCI_SGI_ATTR_ADMINENTRY,
392 + TSN_QCI_SGI_ATTR_OPERENTRY,
393 + TSN_QCI_SGI_ATTR_CCTIME, /* config change time */
394 + TSN_QCI_SGI_ATTR_TICKG,
395 + TSN_QCI_SGI_ATTR_CUTIME,
396 + TSN_QCI_SGI_ATTR_CPENDING,
397 + TSN_QCI_SGI_ATTR_CCERROR,
398 + __TSN_QCI_SGI_ATTR_MAX,
399 + TSN_QCI_SGI_ATTR_MAX = __TSN_QCI_SGI_ATTR_MAX - 1,
403 + TSN_SGI_ATTR_CTRL_UNSPEC = 0,
404 + TSN_SGI_ATTR_CTRL_INITSTATE,
405 + TSN_SGI_ATTR_CTRL_LEN,
406 + TSN_SGI_ATTR_CTRL_CYTIME,
407 + TSN_SGI_ATTR_CTRL_CYTIMEEX,
408 + TSN_SGI_ATTR_CTRL_BTIME,
409 + TSN_SGI_ATTR_CTRL_INITIPV,
410 + TSN_SGI_ATTR_CTRL_GCLENTRY,
411 + __TSN_SGI_ATTR_CTRL_MAX,
412 + TSN_SGI_ATTR_CTRL_MAX = __TSN_SGI_ATTR_CTRL_MAX - 1,
416 + TSN_SGI_ATTR_GCL_UNSPEC = 0,
417 + TSN_SGI_ATTR_GCL_GATESTATE,
418 + TSN_SGI_ATTR_GCL_IPV,
419 + TSN_SGI_ATTR_GCL_INTERVAL,
420 + TSN_SGI_ATTR_GCL_OCTMAX,
421 + __TSN_SGI_ATTR_GCL_MAX,
422 + TSN_SGI_ATTR_GCL_MAX = __TSN_SGI_ATTR_GCL_MAX - 1,
426 + TSN_QCI_FMI_ATTR_UNSPEC = 0,
427 + TSN_QCI_FMI_ATTR_INDEX,
428 + TSN_QCI_FMI_ATTR_ENABLE,
429 + TSN_QCI_FMI_ATTR_DISABLE,
430 + TSN_QCI_FMI_ATTR_CIR,
431 + TSN_QCI_FMI_ATTR_CBS,
432 + TSN_QCI_FMI_ATTR_EIR,
433 + TSN_QCI_FMI_ATTR_EBS,
434 + TSN_QCI_FMI_ATTR_CF,
435 + TSN_QCI_FMI_ATTR_CM,
436 + TSN_QCI_FMI_ATTR_DROPYL,
437 + TSN_QCI_FMI_ATTR_MAREDEN,
438 + TSN_QCI_FMI_ATTR_MARED,
439 + TSN_QCI_FMI_ATTR_COUNTERS,
440 + __TSN_QCI_FMI_ATTR_MAX,
441 + TSN_QCI_FMI_ATTR_MAX = __TSN_QCI_FMI_ATTR_MAX - 1,
445 + TSN_QBV_ATTR_UNSPEC,
446 + TSN_QBV_ATTR_ENABLE,
447 + TSN_QBV_ATTR_DISABLE,
448 + TSN_QBV_ATTR_CONFIGCHANGE,
449 + TSN_QBV_ATTR_CONFIGCHANGETIME,
450 + TSN_QBV_ATTR_MAXSDU,
451 + TSN_QBV_ATTR_GRANULARITY,
452 + TSN_QBV_ATTR_CURRENTTIME,
453 + TSN_QBV_ATTR_CONFIGPENDING,
454 + TSN_QBV_ATTR_CONFIGCHANGEERROR,
455 + TSN_QBV_ATTR_ADMINENTRY,
456 + TSN_QBV_ATTR_OPERENTRY,
457 + TSN_QBV_ATTR_LISTMAX,
458 + __TSN_QBV_ATTR_MAX,
459 + TSN_QBV_ATTR_MAX = __TSN_QBV_ATTR_MAX - 1,
463 + TSN_QBV_ATTR_CTRL_UNSPEC,
464 + TSN_QBV_ATTR_CTRL_LISTCOUNT,
465 + TSN_QBV_ATTR_CTRL_GATESTATE,
466 + TSN_QBV_ATTR_CTRL_CYCLETIME,
467 + TSN_QBV_ATTR_CTRL_CYCLETIMEEXT,
468 + TSN_QBV_ATTR_CTRL_BASETIME,
469 + TSN_QBV_ATTR_CTRL_LISTENTRY,
470 + __TSN_QBV_ATTR_CTRL_MAX,
471 + TSN_QBV_ATTR_CTRL_MAX = __TSN_QBV_ATTR_CTRL_MAX - 1,
475 + TSN_QBV_ATTR_ENTRY_UNSPEC,
476 + TSN_QBV_ATTR_ENTRY_ID,
477 + TSN_QBV_ATTR_ENTRY_GC,
478 + TSN_QBV_ATTR_ENTRY_TM,
479 + __TSN_QBV_ATTR_ENTRY_MAX,
480 + TSN_QBV_ATTR_ENTRY_MAX = __TSN_QBV_ATTR_ENTRY_MAX - 1,
484 + TSN_CT_ATTR_UNSPEC,
485 + TSN_CT_ATTR_QUEUE_STATE,
487 + TSN_CT_ATTR_MAX = __TSN_CT_ATTR_MAX - 1,
491 + TSN_CBGEN_ATTR_UNSPEC,
492 + TSN_CBGEN_ATTR_INDEX,
493 + TSN_CBGEN_ATTR_PORT_MASK,
494 + TSN_CBGEN_ATTR_SPLIT_MASK,
495 + TSN_CBGEN_ATTR_SEQ_LEN,
496 + TSN_CBGEN_ATTR_SEQ_NUM,
497 + __TSN_CBGEN_ATTR_MAX,
498 + TSN_CBGEN_ATTR_MAX = __TSN_CBGEN_ATTR_MAX - 1,
502 + TSN_CBREC_ATTR_UNSPEC,
503 + TSN_CBREC_ATTR_INDEX,
504 + TSN_CBREC_ATTR_SEQ_LEN,
505 + TSN_CBREC_ATTR_HIS_LEN,
506 + TSN_CBREC_ATTR_TAG_POP_EN,
507 + __TSN_CBREC_ATTR_MAX,
508 + TSN_CBREC_ATTR_MAX = __TSN_CBREC_ATTR_MAX - 1,
512 + TSN_CBSTAT_ATTR_UNSPEC,
513 + TSN_CBSTAT_ATTR_INDEX,
514 + TSN_CBSTAT_ATTR_GEN_REC,
515 + TSN_CBSTAT_ATTR_ERR,
516 + TSN_CBSTAT_ATTR_SEQ_NUM,
517 + TSN_CBSTAT_ATTR_SEQ_LEN,
518 + TSN_CBSTAT_ATTR_SPLIT_MASK,
519 + TSN_CBSTAT_ATTR_PORT_MASK,
520 + TSN_CBSTAT_ATTR_HIS_LEN,
521 + TSN_CBSTAT_ATTR_SEQ_HIS,
522 + __TSN_CBSTAT_ATTR_MAX,
523 + TSN_CBSTAT_ATTR_MAX = __TSN_CBSTAT_ATTR_MAX - 1,
527 + TSN_DSCP_ATTR_UNSPEC,
528 + TSN_DSCP_ATTR_DISABLE,
529 + TSN_DSCP_ATTR_INDEX,
532 + __TSN_DSCP_ATTR_MAX,
533 + TSN_DSCP_ATTR_MAX = __TSN_DSCP_ATTR_MAX - 1,
536 +#define ptptime_t __u64
538 +#define MAX_QUEUE_CNT 8
540 +struct tsn_preempt_status {
541 + /* The value of admin_state shows a 8-bits vector value for showing
542 + * the framePreemptionAdminStatus parameter and PreemptionPriority
543 + * for the traffic class. Bit-7 is the highest priority traffic class
544 + * and the bit-0 is the lowest priority traffic class.
545 + * The bit is express (0) and is preemptible (1).
548 + /* The value of the holdAdvance parameter for the port in nanoseconds.
549 + * There is no default value; the holdAdvance is a property of the
550 + * underlying MAC." This parameter corresponds to the holdAdvance
551 + * parameter in 802.1Qbu.
553 + __u32 hold_advance;
555 + /* The value of the releaseAdvance parameter for the port in
556 + * nanoseconds. There is no default value; the releaseAdvance is a
557 + * property of the underlying MAC." This parameter corresponds to the
558 + * releaseAdvance parameter in 802.1Qbu.
560 + __u32 release_advance;
562 + /* The value is active (TRUE) when preemption is operationally active
563 + * for the port, and idle (FALSE) otherwise. This parameter corresponds
564 + * to the preemptionActive parameter in 802.1Qbu.
566 + __u8 preemption_active;
568 + /* The value is hold (1) when the sequence of gate operations for
569 + * the port has executed a Set-And-Hold-MAC operation, and release
570 + * (2) when the sequence of gate operations has executed a
571 + * Set-And-Release-MAC operation. The value of this object is release
572 + * (FALSE) on system initialization. This parameter corresponds to the
573 + * holdRequest parameter in 802.1Qbu.
582 + TX_MODE_VENDOR_DEFINE = 255,
585 +#define QUEUE_TX_MASK ((1 << TX_MODE_STRICT) | (1 << TX_MODE_CBS) \
586 + | (1 << TX_MODE_ETS) | (1 << TX_MODE_VENDOR_DEFINE))
589 + __u8 delta_bw; /* percentage, 0~100 */
592 + __u32 maxframesize;
595 + __u32 maxninference;
599 + /* tx_queue_capbility shows the queue's capability mask.
600 + * refer the enum tsn_tx_mode
604 + /* tx_queue_mode is current queue working mode */
607 + /* prio is showing the queue priority */
610 + /* mstat shows the status data of cbs or priority */
612 + struct cbs_status cbs;
616 +struct port_status {
617 + /* txqueue_cnt shows how many queues in this port */
620 + /* max_rate(Mbit/s) is the port transmit rate current port is setting */
623 + /* tsn_capability mask the tsn capability */
624 + __u32 tsn_capability;
627 +enum tsn_cb_streamid_type {
628 + STREAMID_RESERVED = 0,
629 + /* Null Stream identification */
631 + /* Source MAC and VLAN Stream identification */
632 + STREAMID_SMAC_VLAN,
633 + /* Active Destination MAC and VLAN stream identification */
634 + STREAMID_DMAC_VLAN,
635 + /* IP stream identification */
639 +/* When instantiating an instance of the Null Stream identification function
640 + * 8021CB(6.4) for a particular input Stream, the managed objects in the
641 + * following subsections serve as the tsnStreamIdParameters managed object
642 + * 8021CB claus(9.1.1.7).
644 +struct tsn_cb_null_streamid {
645 + /* tsnCpeNullDownDestMac. Specifies the destination_address that
646 + * identifies a packet in an Enhanced Internal Sublayer Service (EISS)
647 + * indication primitive, to the Null Stream identification function.
651 + /* tsnCpeNullDownTagged. It can take the following values:
652 + * 1 tagged: A frame must have a VLAN tag to be recognized as belonging
654 + * 2 priority: A frame must be untagged, or have a VLAN tag with a VLAN
655 + * ID = 0 to be recognized as belonging to the Stream.
656 + * 3 all: A frame is recognized as belonging to the Stream whether
661 + /* tsnCpeNullDownVlan. Specifies the vlan_identifier parameter that
662 + * identifies a packet in an EISS indication primitive to the Null
663 + * Stream identification function. A value of 0 indicates that the vlan
664 + * _identifier parameter is ignored on EISS indication primitives.
669 +struct tsn_cb_source_streamid {
675 +struct tsn_cb_dest_streamid {
686 +struct tsn_cb_ip_streamid {
700 +/* 802.1CB stream identify table clause 9.1 */
701 +struct tsn_cb_streamid {
702 + /* The objects in a given entry of the Stream identity table are used
703 + * to control packets whose stream_handle subparameter is equal to the
704 + * entry tsnStreamIdHandle object.
708 + /* The list of ports on which an in-facing Stream identification
709 + * function in the output (towards the system forwarding function)
710 + * direction Only Active Destination MAC and VLAN Stream identification
711 + * (or nothing) can be configured.
715 + /* The list of ports on which an out-facing Stream identification
716 + * function in the output (towards the physical interface) direction.
717 + * Only Active Destination MAC and VLAN Stream identification
718 + * (or nothing) can be configured.
722 + /* The list of ports on which an in-facing Stream identification
723 + * function in the input (coming from the system forwarding function)
728 + /* The list of ports on which an out-facing Stream identification
729 + * function in the input (coming from the physical interface) direction
734 + /* An enumerated value indicating the method used to identify packets
735 + * belonging to the Stream.
736 + * The Organizationally Unique Identifier (OUI) or Company Identifier
737 + * (CID) to identify the organization defining the enumerated type
738 + * should be: 00-80-C2
739 + * 1: null stream identification
740 + * 2: source mac and vlan stream identification
741 + * 3: activ destination mac and vlan stream identification
742 + * 4: ip stream identifaciton
746 + /* tsnStreamIdParameters The number of controlling parameters for a
747 + * Stream identification method, their types and values, are specific
748 + * to the tsnStreamIdIdentificationType
751 + struct tsn_cb_null_streamid nid;
752 + struct tsn_cb_source_streamid sid;
753 + struct tsn_cb_dest_streamid did;
754 + struct tsn_cb_ip_streamid iid;
758 +/* Following counters are instantiated for each port on which the Stream
759 + * identification function (6.2) is configured. The counters are indexed by
760 + * port number, facing (in-facing or out-facing), and stream_handle value
761 + * (tsnStreamIdHandle, 9.1.1.1).
763 +struct tsn_cb_streamid_counters {
772 + } per_streamport[32];
775 +/* 802.1Qci Stream Parameter Table, read from port */
776 +struct tsn_qci_psfp_stream_param {
777 + /* MaxStreamFilterInstances.
778 + * The maximum number of Stream Filter instances supported by this
779 + * Bridge component.
781 + __s32 max_sf_instance;
783 + /* MaxStreamGateInstances
784 + * The maximum number of Stream Gate instances supported by this Bridge
787 + __s32 max_sg_instance;
789 + /* MaxFlowMeterInstances
790 + * The maximum number of Flow Meter instances supported by this Bridge
793 + __s32 max_fm_instance;
795 + /* SupportedListMax
796 + * The maximum value supported by this Bridge component of the
797 + * AdminControlListLength and OperControlListLength parameters.
799 + __s32 supported_list_max;
802 +/* 802.1Qci Stream Filter Instance Table, counters part only. */
803 +struct tsn_qci_psfp_sfi_counters {
804 + /* The MatchingFramesCount counter counts received frames that match
805 + * this stream filter.
807 + __u64 matching_frames_count;
809 + /* The PassingFramesCount counter counts received frames that pass the
810 + * gate associated with this stream filter.
812 + __u64 passing_frames_count;
814 + /* The NotPassingFramesCount counter counts received frames that do not
815 + * pass the gate associated with this stream filter.
817 + __u64 not_passing_frames_count;
819 + /* The PassingSDUCount counter counts received frames that pass the SDU
820 + * size filter specification associated with this stream filter.
822 + __u64 passing_sdu_count;
824 + /* The NotPassingSDUCount counter counts received frames that do not
825 + * pass the SDU size filter specification associated with this stream
828 + __u64 not_passing_sdu_count;
830 + /* The REDFramesCount counter counts received random early detection
831 + * (RED) frames associated with this stream filter.
833 + __u64 red_frames_count;
836 +/* 802.1Qci Stream Filter Instance Table, configuration part only. */
837 +struct tsn_qci_psfp_sfi_conf {
839 + /* The StreamHandleSpec parameter contains a stream identifier
840 + * specification value. A value of -1 denotes the wild card value; zero
841 + * or positive values denote stream identifier values.
843 + __s32 stream_handle_spec;
845 + /* The PrioritySpec parameter contains a priority specification value.
846 + * A value of -1 denotes the wild card value; zero or positive values
847 + * denote priority values.
849 + __s8 priority_spec;
851 + /* The StreamGateInstanceID parameter contains the index of an entry in
852 + * the Stream Gate Table.
854 + __u32 stream_gate_instance_id;
856 + /* The filter specifications. The actions specified in a filter
857 + * specification can result in a frame passing or failing the specified
858 + * filter. Frames that fail a filter are discarded.
861 + /* The MaximumSDUSize parameter specifies the maximum allowed
862 + * frame size for the stream. Any frame exceeding this value
863 + * will be dropped. A value of 0 denote that the MaximumSDUSize
864 + * filter is disabled for this stream.
866 + __u16 maximum_sdu_size;
868 + /* The FlowMeterInstanceID parameter contains the index of an
869 + * entry in the Flow Meter Table. A value of -1 denotes that
870 + * no flow meter is assigned; zero or positive values denote
873 + __s32 flow_meter_instance_id;
876 + /* The StreamBlockedDueToOversizeFrameEnable object contains a Boolean
877 + * value that indicates whether the StreamBlockedDueToOversizeFrame
878 + * function is enabled (TRUE) or disabled (FALSE).
880 + __u8 block_oversize_enable;
882 + /* The StreamBlockedDueToOversizeFrame object contains a Boolean value
883 + * that indicates whether, if the StreamBlockedDueToOversizeFrame
884 + * function is enabled, all frames are to be discarded (TRUE) or not
887 + __u8 block_oversize;
890 +/* 802.1Qci Stream Gate Control List Entry. */
891 +struct tsn_qci_psfp_gcl {
892 + /* The GateState parameter specifies a desired state, open (true) or
893 + * closed (false), for the stream gate.
897 + /* An IPV is encoded as a signed integer. A negative denotes the null
898 + * value; zero or positive values denote internal priority values.
902 + /* A TimeInterval is encoded in 4 octets as a 32-bit unsigned integer,
903 + * representing a number of nanoseconds.
905 + __u32 time_interval;
907 + /* The maximum number of octets that are permitted to pass the gate
908 + * during the specified TimeInterval. If zero, there is no maximum.
914 +/* 802.1Qci Stream Gate Admin/Operation common list control parameters */
915 +struct tsn_qci_sg_control {
916 + /* The administrative/operation value of the GateStates parameter
917 + * for the stream gate. A value of false indicates closed;
918 + * a value of true indicates open.
922 + /* The administrative/operation value of the ListMax parameter for the
923 + * gate. The integer value indicates the number of entries (TLVs) in
924 + * the AdminControlList/OperControlList.
926 + __u8 control_list_length;
928 + /* The administrative/operation value of the CycleTime parameter for
929 + * the gate. The value is an unsigned integer number of nanoseconds.
933 + /* The administrative/operation value of the CycleTimeExtension
934 + * parameter for the gate. The value is an unsigned integer number
937 + __u32 cycle_time_extension;
939 + /* The administrative/operation value of the BaseTime parameter for the
940 + * gate. The value is a representation of a PTPtime value, consisting
941 + * of a 48-bit integer number of seconds and a 32-bit integer number of
944 + ptptime_t base_time;
946 + /* The administrative/operation value of the IPV parameter for the gate.
947 + * A value of -1 denotes the null value; zero or positive values denote
948 + * internal priority values.
952 + /* control_list contend the gate control list of
953 + * administrative/operation
955 + struct tsn_qci_psfp_gcl *gcl;
958 +/* 802.1Qci Stream Gate Instance Table, configuration part only. */
959 +struct tsn_qci_psfp_sgi_conf {
960 + /* The GateEnabled parameter determines whether the stream gate is
961 + * active (true) or inactive (false).
965 + /* The ConfigChange parameter signals the start of a configuration
966 + * change when it is set to TRUE. This should only be done when the
967 + * various administrative parameters are all set to appropriate values.
969 + __u8 config_change;
971 + /* admin control parameters with admin control list */
972 + struct tsn_qci_sg_control admin;
974 + /* The GateClosedDueToInvalidRxEnable object contains a Boolean value
975 + * that indicates whether the GateClosedDueToInvalidRx function is
976 + * enabled (TRUE) or disabled (FALSE).
978 + __u8 block_invalid_rx_enable;
980 + /* The GateClosedDueToInvalidRx object contains a Boolean value that
981 + * indicates whether, if the GateClosedDueToInvalidRx function is
982 + * enabled, all frames are to be discarded (TRUE) or not (FALSE).
984 + __u8 block_invalid_rx;
986 + /* The GateClosedDueToOctetsExceededEnable object contains a Boolean
987 + * value that indicates whether the GateClosedDueToOctetsExceeded
988 + * function is enabled (TRUE) or disabled (FALSE).
990 + __u8 block_octets_exceeded_enable;
992 + /* The GateClosedDueToOctetsExceeded object contains a Boolean value
993 + * that indicates whether, if the GateClosedDueToOctetsExceeded
994 + * function is enabled, all frames are to be discarded (TRUE) or not
997 + __u8 block_octets_exceeded;
1000 +/* 802.1Qci Stream Gate Instance Table, status part only. */
1001 +struct tsn_psfp_sgi_status {
1003 + /* admin control parameters with admin control list */
1004 + struct tsn_qci_sg_control oper;
1006 + /* The PTPtime at which the next config change is scheduled to occur.
1007 + * The value is a representation of a PTPtime value, consisting of a
1008 + * 48-bit integer number of seconds and a 32-bit integer number of
1011 + ptptime_t config_change_time;
1013 + /* The granularity of the cycle time clock, represented as an unsigned
1014 + * number of tenths of nanoseconds.
1016 + __u32 tick_granularity;
1018 + /* The current time, in PTPtime, as maintained by the local system.
1019 + * The value is a representation of a PTPtime value, consisting of a
1020 + * 48-bit integer number of seconds and a 32-bit integer number of
1023 + ptptime_t current_time;
1025 + /* The value of the ConfigPending state machine variable. The value is
1026 + * TRUE if a configuration change is in progress but has not yet
1029 + __u8 config_pending;
1031 + /* A counter of the number of times that a re-configuration of the
1032 + * traffic schedule has been requested with the old schedule still
1033 + * running and the requested base time was in the past.
1035 + __u64 config_change_error;
1039 +/* 802.1Qci Flow Meter Instance Table. */
1040 +struct tsn_qci_psfp_fmi {
1041 + /* The FlowMeterCIR parameter contains an integer value that represents
1042 + * the CIR value for the flow meter, in kbit/s.
1046 + /* The FlowMeterCBS parameter contains an integer value that represents
1047 + * the CBS value for the flow meter, in octets.
1051 + /* The FlowMeterEIR parameter contains an integer value that represents
1052 + * the EIR value for the flow meter, in kbit/s.
1056 + /* The FlowMeterEBS parameter contains an integer value that represents
1057 + * the EBS value for the flow meter, in octets.
1061 + /* The FlowMeterCF parameter contains a Boolean value that represents
1062 + * the CF value for the flow meter, as a Boolean value indicating no
1063 + * coupling (FALSE) or coupling (TRUE).
1067 + /* The FlowMeterCM parameter contains a Boolean value that represents
1068 + * the CM value for the flow meter, as a Boolean value indicating
1069 + * colorBlind (FALSE) or colorAware (TRUE).
1073 + /* The FlowMeterDropOnYellow parameter contains a Boolean value that
1074 + * indicates whether yellow frames are dropped (TRUE) or have
1075 + * drop_eligible set to TRUE (FALSE).
1077 + __u8 drop_on_yellow;
1079 + /* The FlowMeterMarkAllFramesRedEnable parameter contains a Boolean
1080 + * value that indicates whether the MarkAllFramesRed function
1081 + * is enabled (TRUE) or disabled (FALSE).
1083 + __u8 mark_red_enable;
1085 + /* The FlowMeterMarkAllFramesRed parameter contains a Boolean value
1086 + * that indicates whether, if the MarkAllFramesRed function is enabled,
1087 + * all frames are to be discarded (TRUE) or not (FALSE).
1092 +struct tsn_qci_psfp_fmi_counters {
1098 + __u64 remark_yellow;
1104 +struct tsn_seq_gen_conf {
1106 + /* The InputPortMask parameter contains a port mask.
1107 + * If the packet is from input port belonging to this
1108 + * port mask then it's on known stream and sequence
1109 + * generation parameters can be applied.
1113 + /* The SplitMask parameter contains a output port mask
1114 + * used to add redundant paths.
1118 + /* The SequenceSpaceLenLog parameter is a value to specifies
1119 + * number of bits to be used for sequence number.
1123 + /* The SequenceNumber parameter is a value to used for
1124 + * outgoing packet's sequence number generation.
1129 +struct tsn_seq_rec_conf {
1131 + /* The SequenceSpaceLenLog parameter is a value to specifies
1132 + * number of bits to be used for sequence number.
1136 + /* The HistorySpaceLenLog parameter is a value to specifies
1137 + * number of bits to be used for history register.
1141 + /* The RTagPopEnable parameter contains a __u8 to enable removal
1142 + * of redundancy tag from the packet.
1147 +struct tsn_cb_status {
1149 + /* The GenRecover parameter contains a value specifies type
1150 + * of stream sequence parameters:
1151 + * 0: Stream sequence parameters are for generation.
1152 + * 1: Stream sequence parameters are for recovery.
1156 + /* The ErrStatus parameter indicates stream's error status
1157 + * 1: This switch is expected to sequence the stream,
1158 + * but the incoming packet has sequence number.
1159 + * 2: This switch is expected to recover the stream,
1160 + * but the incoming packet is NONSEQ.
1164 + /* The SequenceNumber parameter is a value to used for
1165 + * outgoing packet's sequence number generation.
1169 + /* The SequenceSpaceLenLog parameter is a value to specifies
1170 + * number of bits to be used for sequence number.
1174 + /* The SplitMask parameter contains a output port mask
1175 + * used to add redundant paths.
1179 + /* The InputPortMask parameter contains a port mask.
1180 + * If the packet is from input port belonging to this
1181 + * port mask then it's on known stream and sequence
1182 + * generation parameters can be applied.
1186 + /* The HistorySpaceLenLog parameter is a value to specifies
1187 + * number of bits to be used for history register.
1191 + /* The SequenceHistory parameter Maintains history of sequence
1192 + * numbers of received packets.
1197 +/* An entry for gate control list */
1198 +struct tsn_qbv_entry {
1199 + /* Octet represent the gate states for the corresponding traffic
1201 + * The MS bit corresponds to traffic class 7.
1202 + * The LS bit to traffic class 0.
1203 + * A bit value of 0 indicates closed;
1204 + * A bit value of 1 indicates open.
1208 + /* A TimeInterval is encoded in 4 octets as a 32-bit unsigned integer,
1209 + * representing a number of nanoseconds.
1211 + __u32 time_interval;
1214 +/* The administrative/operation time and gate list */
1215 +struct tsn_qbv_basic {
1216 + /* The administrative/operation value of the GateStates parameter for
1218 + * The bits of the octet represent the gate states for the
1219 + * corresponding traffic classes; the MS bit corresponds to traffic
1220 + * class 7, the LS bit to traffic class 0. A bit value of 0 indicates
1221 + * closed; a bit value of 1 indicates open.
1222 + * The value of this object MUST be retained
1223 + * across reinitializations of the management system.
1227 + /* The administrative/operation value of the ListMax parameter for the
1228 + * port. The integer value indicates the number of entries (TLVs) in
1229 + * the AdminControlList. The value of this object MUST be retained
1230 + * across reinitializations of the management system.
1232 + __u32 control_list_length;
1234 + /* The administrative/operation value of the AdminCycleTime
1235 + * parameter for the Port. The numerator and denominator together
1236 + * represent the cycle time as a rational number of seconds. The value
1237 + * of this object MUST be retained across reinitializations of the
1238 + * management system.
1242 + /* The administrative/operation value of the CycleTimeExtension
1243 + * parameter for the Port. The value is an unsigned integer number of
1245 + * The value of this object MUST be retained across reinitializations
1246 + * of the management system.
1249 + __u32 cycle_time_extension;
1251 + /* The administrative/operation value of the BaseTime parameter for the
1252 + * Port. The value is a representation of a PTPtime value, consisting
1253 + * of a 48-bit integer number of seconds and a 32-bit integer number of
1255 + * The value of this object MUST be retained across reinitializations of
1256 + * the management system.
1258 + ptptime_t base_time;
1260 + /* admin_control_list represent the AdminControlList/OperControlList.
1261 + * The administrative version of the gate control list for the Port.
1263 + struct tsn_qbv_entry *control_list;
1266 +struct tsn_qbv_conf {
1267 + /* The GateEnabled parameter determines whether traffic scheduling is
1268 + * active (true) or inactive (false). The value of this object MUST be
1269 + * retained across reinitializations of the management system.
1271 + __u8 gate_enabled;
1273 + /* The maxsdu parameter denoting the maximum SDU size supported by the
1278 + /* The ConfigChange parameter signals the start of a configuration
1279 + * change when it is set to TRUE. This should only be done when the
1280 + * various administrative parameters are all set to appropriate values.
1282 + __u8 config_change;
1284 + /* The admin parameter signals the admin relate cycletime, basictime,
1285 + * gatelist paraters.
1287 + struct tsn_qbv_basic admin;
1290 +/* 802.1Qbv (Time Aware Shaper) port status */
1291 +struct tsn_qbv_status {
1292 + /* The PTPtime at which the next config change is scheduled to occur.
1293 + * The value is a representation of a PTPtime value, consisting of a
1294 + * 48-bit integer number of seconds and a 32-bit integer number of
1295 + * nanoseconds. The value of this object MUST be retained across
1296 + * reinitializations of the management system.
1298 + ptptime_t config_change_time;
1300 + /* The granularity of the cycle time clock, represented as an unsigned
1301 + * number of tenths of nanoseconds. The value of this object MUST be
1302 + * retained across reinitializations of the management system.
1304 + __u32 tick_granularity;
1306 + /* The current time, in PTPtime, as maintained by the local system.
1307 + * The value is a representation of a PTPtime value, consisting of a
1308 + * 48-bit integer number of seconds and a 32-bit integer number of
1311 + ptptime_t current_time;
1313 + /* The value of the ConfigPending state machine variable. The value is
1314 + * TRUE if a configuration change is in progress but has not yet
1317 + __u8 config_pending;
1319 + /* A counter of the number of times that a re-configuration of the
1320 + * traffic schedule has been requested with the old schedule still
1321 + * running and the requested base time was in the past.
1323 + __u64 config_change_error;
1325 + /* The maximum value supported by this Port of the
1326 + * AdminControlListLength and OperControlListLength parameters.
1328 + __u32 supported_list_max;
1330 + /* Operation settings parameters and Oper gate list */
1331 + struct tsn_qbv_basic oper;
1334 +/* Time Specific Departure parameters */
1338 + /* The cycle time, in units of microsecond(us)*/
1341 + /* The maximum number of frames which could be transmitted on one cycle
1342 + * The exceeding frames will be transmitted on next cycle.
1344 + __u32 maxFrameNum;
1346 + /* Specify the time of the first cycle begins.
1347 + * 1: begin when the queue get the first frame to transmit.
1348 + * 2: begin immediately at the end of setting function.
1353 +struct tsn_tsd_status {
1356 + __u32 maxFrameNum;
1362 +struct tsn_qos_switch_dscp_conf {
1367 + __u8 dscp; /* New ingress translated DSCP value */
1370 +#endif /* _UAPI_GENL_TSN_H */
1373 @@ -240,6 +240,7 @@ source "net/ieee802154/Kconfig"
1374 source "net/mac802154/Kconfig"
1375 source "net/sched/Kconfig"
1376 source "net/dcb/Kconfig"
1377 +source "net/tsn/Kconfig"
1378 source "net/dns_resolver/Kconfig"
1379 source "net/batman-adv/Kconfig"
1380 source "net/openvswitch/Kconfig"
1383 @@ -59,6 +59,9 @@ obj-$(CONFIG_CAIF) += caif/
1384 ifneq ($(CONFIG_DCB),)
1387 +ifneq ($(CONFIG_TSN),)
1390 obj-$(CONFIG_6LOWPAN) += 6lowpan/
1391 obj-$(CONFIG_IEEE802154) += ieee802154/
1392 obj-$(CONFIG_MAC802154) += mac802154/
1394 +++ b/net/tsn/Kconfig
1397 + bool "802.1 Time-Sensitive Networking support"
1399 + depends on VLAN_8021Q && PTP_1588_CLOCK
1401 + This enables support for TSN(time sensitive networking)
1402 + TSN features include:
1412 +++ b/net/tsn/Makefile
1414 +obj-$(CONFIG_TSN) += genl_tsn.o
1416 +++ b/net/tsn/genl_tsn.c
1418 +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
1419 +/* Copyright 2017-2019 NXP */
1421 +#include <linux/module.h>
1422 +#include <linux/kernel.h>
1423 +#include <linux/init.h>
1424 +#include <linux/netdevice.h>
1425 +#include <linux/if_vlan.h>
1426 +#include <net/genetlink.h>
1427 +#include <net/netlink.h>
1428 +#include <linux/version.h>
1429 +#include <net/tsn.h>
1431 +#define NLA_PARSE_NESTED(a, b, c, d) \
1432 + nla_parse_nested_deprecated(a, b, c, d, NULL)
1433 +#define NLA_PUT_U64(a, b, c) nla_put_u64_64bit(a, b, c, NLA_U64)
1435 +static struct genl_family tsn_family;
1437 +LIST_HEAD(port_list);
1439 +static const struct nla_policy tsn_cmd_policy[TSN_CMD_ATTR_MAX + 1] = {
1440 + [TSN_CMD_ATTR_MESG] = { .type = NLA_STRING },
1441 + [TSN_CMD_ATTR_DATA] = { .type = NLA_S32 },
1442 + [TSN_ATTR_IFNAME] = { .type = NLA_STRING },
1443 + [TSN_ATTR_PORT_NUMBER] = { .type = NLA_U8 },
1444 + [TSN_ATTR_CAP] = { .type = NLA_NESTED },
1445 + [TSN_ATTR_QBV] = { .type = NLA_NESTED },
1446 + [TSN_ATTR_STREAM_IDENTIFY] = { .type = NLA_NESTED },
1447 + [TSN_ATTR_QCI_SP] = { .type = NLA_NESTED },
1448 + [TSN_ATTR_QCI_SFI] = { .type = NLA_NESTED },
1449 + [TSN_ATTR_QCI_SGI] = { .type = NLA_NESTED },
1450 + [TSN_ATTR_QCI_FMI] = { .type = NLA_NESTED },
1451 + [TSN_ATTR_CBS] = { .type = NLA_NESTED },
1452 + [TSN_ATTR_TSD] = { .type = NLA_NESTED },
1453 + [TSN_ATTR_QBU] = { .type = NLA_NESTED },
1454 + [TSN_ATTR_CT] = { .type = NLA_NESTED },
1455 + [TSN_ATTR_CBGEN] = { .type = NLA_NESTED },
1456 + [TSN_ATTR_CBREC] = { .type = NLA_NESTED },
1457 + [TSN_ATTR_CBSTAT] = { .type = NLA_NESTED },
1458 + [TSN_ATTR_DSCP] = { .type = NLA_NESTED },
1461 +static const struct nla_policy tsn_cap_policy[TSN_CAP_ATTR_MAX + 1] = {
1462 + [TSN_CAP_ATTR_QBV] = { .type = NLA_FLAG },
1463 + [TSN_CAP_ATTR_QCI] = { .type = NLA_FLAG },
1464 + [TSN_CAP_ATTR_QBU] = { .type = NLA_FLAG },
1465 + [TSN_CAP_ATTR_CBS] = { .type = NLA_FLAG },
1466 + [TSN_CAP_ATTR_CB] = { .type = NLA_FLAG },
1467 + [TSN_CAP_ATTR_TBS] = { .type = NLA_FLAG },
1468 + [TSN_CAP_ATTR_CTH] = { .type = NLA_FLAG },
1471 +static const struct nla_policy qci_cap_policy[TSN_QCI_STREAM_ATTR_MAX + 1] = {
1472 + [TSN_QCI_STREAM_ATTR_MAX_SFI] = { .type = NLA_U32 },
1473 + [TSN_QCI_STREAM_ATTR_MAX_SGI] = { .type = NLA_U32 },
1474 + [TSN_QCI_STREAM_ATTR_MAX_FMI] = { .type = NLA_U32 },
1475 + [TSN_QCI_STREAM_ATTR_SLM] = { .type = NLA_U32 },
1478 +static const struct nla_policy ct_policy[TSN_CT_ATTR_MAX + 1] = {
1479 + [TSN_CT_ATTR_QUEUE_STATE] = { .type = NLA_U8 }
1482 +static const struct nla_policy cbgen_policy[TSN_CBGEN_ATTR_MAX + 1] = {
1483 + [TSN_CBGEN_ATTR_INDEX] = { .type = NLA_U32 },
1484 + [TSN_CBGEN_ATTR_PORT_MASK] = { .type = NLA_U8 },
1485 + [TSN_CBGEN_ATTR_SPLIT_MASK] = { .type = NLA_U8 },
1486 + [TSN_CBGEN_ATTR_SEQ_LEN] = { .type = NLA_U8 },
1487 + [TSN_CBGEN_ATTR_SEQ_NUM] = { .type = NLA_U32 },
1490 +static const struct nla_policy cbrec_policy[TSN_CBREC_ATTR_MAX + 1] = {
1491 + [TSN_CBREC_ATTR_INDEX] = { .type = NLA_U32 },
1492 + [TSN_CBREC_ATTR_SEQ_LEN] = { .type = NLA_U8 },
1493 + [TSN_CBREC_ATTR_HIS_LEN] = { .type = NLA_U8 },
1494 + [TSN_CBREC_ATTR_TAG_POP_EN] = { .type = NLA_FLAG },
1497 +static const struct nla_policy cbstat_policy[TSN_CBSTAT_ATTR_MAX + 1] = {
1498 + [TSN_CBSTAT_ATTR_INDEX] = { .type = NLA_U32 },
1499 + [TSN_CBSTAT_ATTR_GEN_REC] = { .type = NLA_U8 },
1500 + [TSN_CBSTAT_ATTR_ERR] = { .type = NLA_U8 },
1501 + [TSN_CBSTAT_ATTR_SEQ_NUM] = { .type = NLA_U32 },
1502 + [TSN_CBSTAT_ATTR_SEQ_LEN] = { .type = NLA_U8 },
1503 + [TSN_CBSTAT_ATTR_SPLIT_MASK] = { .type = NLA_U8 },
1504 + [TSN_CBSTAT_ATTR_PORT_MASK] = { .type = NLA_U8 },
1505 + [TSN_CBSTAT_ATTR_HIS_LEN] = { .type = NLA_U8 },
1506 + [TSN_CBSTAT_ATTR_SEQ_HIS] = { .type = NLA_U32 },
1509 +static const struct nla_policy qbu_policy[TSN_QBU_ATTR_MAX + 1] = {
1510 + [TSN_QBU_ATTR_ADMIN_STATE] = { .type = NLA_U8 },
1511 + [TSN_QBU_ATTR_HOLD_ADVANCE] = { .type = NLA_U32},
1512 + [TSN_QBU_ATTR_RELEASE_ADVANCE] = { .type = NLA_U32},
1513 + [TSN_QBU_ATTR_ACTIVE] = { .type = NLA_FLAG},
1514 + [TSN_QBU_ATTR_HOLD_REQUEST] = { .type = NLA_U8},
1517 +static const struct nla_policy cbs_policy[TSN_CBS_ATTR_MAX + 1] = {
1518 + [TSN_CBS_ATTR_TC_INDEX] = { .type = NLA_U8},
1519 + [TSN_CBS_ATTR_BW] = { .type = NLA_U8},
1522 +static const struct nla_policy tsd_policy[TSN_TSD_ATTR_MAX + 1] = {
1523 + [TSN_TSD_ATTR_ENABLE] = { .type = NLA_FLAG},
1524 + [TSN_TSD_ATTR_DISABLE] = { .type = NLA_FLAG},
1525 + [TSN_TSD_ATTR_PERIOD] = { .type = NLA_U32},
1526 + [TSN_TSD_ATTR_MAX_FRM_NUM] = { .type = NLA_U32},
1527 + [TSN_TSD_ATTR_CYCLE_NUM] = { .type = NLA_U32},
1528 + [TSN_TSD_ATTR_LOSS_STEPS] = { .type = NLA_U32},
1529 + [TSN_TSD_ATTR_SYN_IMME] = { .type = NLA_FLAG},
1532 +static const struct nla_policy qbv_policy[TSN_QBV_ATTR_MAX + 1] = {
1533 + [TSN_QBV_ATTR_ADMINENTRY] = { .type = NLA_NESTED},
1534 + [TSN_QBV_ATTR_OPERENTRY] = { .type = NLA_NESTED},
1535 + [TSN_QBV_ATTR_ENABLE] = { .type = NLA_FLAG},
1536 + [TSN_QBV_ATTR_DISABLE] = { .type = NLA_FLAG},
1537 + [TSN_QBV_ATTR_CONFIGCHANGE] = { .type = NLA_FLAG},
1538 + [TSN_QBV_ATTR_CONFIGCHANGETIME] = { .type = NLA_U64},
1539 + [TSN_QBV_ATTR_MAXSDU] = { .type = NLA_U32},
1540 + [TSN_QBV_ATTR_GRANULARITY] = { .type = NLA_U32},
1541 + [TSN_QBV_ATTR_CURRENTTIME] = { .type = NLA_U64},
1542 + [TSN_QBV_ATTR_CONFIGPENDING] = {.type = NLA_FLAG},
1543 + [TSN_QBV_ATTR_CONFIGCHANGEERROR] = { .type = NLA_U64},
1544 + [TSN_QBV_ATTR_LISTMAX] = { .type = NLA_U32},
1547 +static const struct nla_policy qbv_ctrl_policy[TSN_QBV_ATTR_CTRL_MAX + 1] = {
1548 + [TSN_QBV_ATTR_CTRL_LISTCOUNT] = { .type = NLA_U32},
1549 + [TSN_QBV_ATTR_CTRL_GATESTATE] = { .type = NLA_U8},
1550 + [TSN_QBV_ATTR_CTRL_CYCLETIME] = { .type = NLA_U32},
1551 + [TSN_QBV_ATTR_CTRL_CYCLETIMEEXT] = { .type = NLA_U32},
1552 + [TSN_QBV_ATTR_CTRL_BASETIME] = { .type = NLA_U64},
1553 + [TSN_QBV_ATTR_CTRL_LISTENTRY] = { .type = NLA_NESTED},
1556 +static const struct nla_policy qbv_entry_policy[TSN_QBV_ATTR_ENTRY_MAX + 1] = {
1557 + [TSN_QBV_ATTR_ENTRY_ID] = { .type = NLA_U32},
1558 + [TSN_QBV_ATTR_ENTRY_GC] = { .type = NLA_U8},
1559 + [TSN_QBV_ATTR_ENTRY_TM] = { .type = NLA_U32},
1562 +static const struct nla_policy cb_streamid_policy[TSN_STREAMID_ATTR_MAX + 1] = {
1563 + [TSN_STREAMID_ATTR_INDEX] = { .type = NLA_U32},
1564 + [TSN_STREAMID_ATTR_ENABLE] = { .type = NLA_FLAG},
1565 + [TSN_STREAMID_ATTR_DISABLE] = { .type = NLA_FLAG},
1566 + [TSN_STREAMID_ATTR_STREAM_HANDLE] = { .type = NLA_S32},
1567 + [TSN_STREAMID_ATTR_IFOP] = { .type = NLA_U32},
1568 + [TSN_STREAMID_ATTR_OFOP] = { .type = NLA_U32},
1569 + [TSN_STREAMID_ATTR_IFIP] = { .type = NLA_U32},
1570 + [TSN_STREAMID_ATTR_OFIP] = { .type = NLA_U32},
1571 + [TSN_STREAMID_ATTR_TYPE] = { .type = NLA_U8},
1572 + [TSN_STREAMID_ATTR_NDMAC] = { .type = NLA_U64},
1573 + [TSN_STREAMID_ATTR_NTAGGED] = { .type = NLA_U8},
1574 + [TSN_STREAMID_ATTR_NVID] = { .type = NLA_U16},
1575 + [TSN_STREAMID_ATTR_SMAC] = { .type = NLA_U64},
1576 + [TSN_STREAMID_ATTR_STAGGED] = { .type = NLA_U8},
1577 + [TSN_STREAMID_ATTR_SVID] = { .type = NLA_U16},
1578 + [TSN_STREAMID_ATTR_COUNTERS_PSI] = { .type = NLA_U64},
1579 + [TSN_STREAMID_ATTR_COUNTERS_PSO] = { .type = NLA_U64},
1580 + [TSN_STREAMID_ATTR_COUNTERS_PSPPI] = { .type = NLA_U64},
1581 + [TSN_STREAMID_ATTR_COUNTERS_PSPPO] = { .type = NLA_U64},
1584 +static const struct nla_policy qci_sfi_policy[TSN_QCI_SFI_ATTR_MAX + 1] = {
1585 + [TSN_QCI_SFI_ATTR_INDEX] = { .type = NLA_U32},
1586 + [TSN_QCI_SFI_ATTR_ENABLE] = { .type = NLA_FLAG},
1587 + [TSN_QCI_SFI_ATTR_DISABLE] = { .type = NLA_FLAG},
1588 + [TSN_QCI_SFI_ATTR_STREAM_HANDLE] = { .type = NLA_S32},
1589 + [TSN_QCI_SFI_ATTR_PRIO_SPEC] = { .type = NLA_S8},
1590 + [TSN_QCI_SFI_ATTR_GATE_ID] = { .type = NLA_U32},
1591 + [TSN_QCI_SFI_ATTR_FILTER_TYPE] = { .type = NLA_U8},
1592 + [TSN_QCI_SFI_ATTR_FLOW_ID] = { .type = NLA_S32},
1593 + [TSN_QCI_SFI_ATTR_MAXSDU] = { .type = NLA_U16},
1594 + [TSN_QCI_SFI_ATTR_COUNTERS] = {
1595 + .len = sizeof(struct tsn_qci_psfp_sfi_counters)},
1596 + [TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE] = { .type = NLA_FLAG},
1597 + [TSN_QCI_SFI_ATTR_OVERSIZE] = { .type = NLA_FLAG},
1600 +static const struct nla_policy qci_sgi_policy[] = {
1601 + [TSN_QCI_SGI_ATTR_INDEX] = { .type = NLA_U32},
1602 + [TSN_QCI_SGI_ATTR_ENABLE] = { .type = NLA_FLAG},
1603 + [TSN_QCI_SGI_ATTR_DISABLE] = { .type = NLA_FLAG},
1604 + [TSN_QCI_SGI_ATTR_CONFCHANGE] = { .type = NLA_FLAG},
1605 + [TSN_QCI_SGI_ATTR_IRXEN] = { .type = NLA_FLAG},
1606 + [TSN_QCI_SGI_ATTR_IRX] = { .type = NLA_FLAG},
1607 + [TSN_QCI_SGI_ATTR_OEXEN] = { .type = NLA_FLAG},
1608 + [TSN_QCI_SGI_ATTR_OEX] = { .type = NLA_FLAG},
1609 + [TSN_QCI_SGI_ATTR_ADMINENTRY] = { .type = NLA_NESTED},
1610 + [TSN_QCI_SGI_ATTR_OPERENTRY] = { .type = NLA_NESTED},
1611 + [TSN_QCI_SGI_ATTR_CCTIME] = { .type = NLA_U64},
1612 + [TSN_QCI_SGI_ATTR_TICKG] = { .type = NLA_U32},
1613 + [TSN_QCI_SGI_ATTR_CUTIME] = { .type = NLA_U64},
1614 + [TSN_QCI_SGI_ATTR_CPENDING] = { .type = NLA_FLAG},
1615 + [TSN_QCI_SGI_ATTR_CCERROR] = { .type = NLA_U64},
1618 +static const struct nla_policy qci_sgi_ctrl_policy[] = {
1619 + [TSN_SGI_ATTR_CTRL_INITSTATE] = { .type = NLA_FLAG},
1620 + [TSN_SGI_ATTR_CTRL_LEN] = { .type = NLA_U8},
1621 + [TSN_SGI_ATTR_CTRL_CYTIME] = { .type = NLA_U32},
1622 + [TSN_SGI_ATTR_CTRL_CYTIMEEX] = { .type = NLA_U32},
1623 + [TSN_SGI_ATTR_CTRL_BTIME] = { .type = NLA_U64},
1624 + [TSN_SGI_ATTR_CTRL_INITIPV] = { .type = NLA_S8},
1625 + [TSN_SGI_ATTR_CTRL_GCLENTRY] = { .type = NLA_NESTED},
1628 +static const struct nla_policy qci_sgi_gcl_policy[] = {
1629 + [TSN_SGI_ATTR_GCL_GATESTATE] = { .type = NLA_FLAG},
1630 + [TSN_SGI_ATTR_GCL_IPV] = { .type = NLA_S8},
1631 + [TSN_SGI_ATTR_GCL_INTERVAL] = { .type = NLA_U32},
1632 + [TSN_SGI_ATTR_GCL_OCTMAX] = { .type = NLA_U32},
1635 +static const struct nla_policy qci_fmi_policy[] = {
1636 + [TSN_QCI_FMI_ATTR_INDEX] = { .type = NLA_U32},
1637 + [TSN_QCI_FMI_ATTR_ENABLE] = { .type = NLA_FLAG},
1638 + [TSN_QCI_FMI_ATTR_DISABLE] = { .type = NLA_FLAG},
1639 + [TSN_QCI_FMI_ATTR_CIR] = { .type = NLA_U32},
1640 + [TSN_QCI_FMI_ATTR_CBS] = { .type = NLA_U32},
1641 + [TSN_QCI_FMI_ATTR_EIR] = { .type = NLA_U32},
1642 + [TSN_QCI_FMI_ATTR_EBS] = { .type = NLA_U32},
1643 + [TSN_QCI_FMI_ATTR_CF] = { .type = NLA_FLAG},
1644 + [TSN_QCI_FMI_ATTR_CM] = { .type = NLA_FLAG},
1645 + [TSN_QCI_FMI_ATTR_DROPYL] = { .type = NLA_FLAG},
1646 + [TSN_QCI_FMI_ATTR_MAREDEN] = { .type = NLA_FLAG},
1647 + [TSN_QCI_FMI_ATTR_MARED] = { .type = NLA_FLAG},
1648 + [TSN_QCI_FMI_ATTR_COUNTERS] = {
1649 + .len = sizeof(struct tsn_qci_psfp_fmi_counters)},
1652 +static const struct nla_policy dscp_policy[] = {
1653 + [TSN_DSCP_ATTR_INDEX] = { .type = NLA_U32},
1654 + [TSN_DSCP_ATTR_DISABLE] = { .type = NLA_FLAG},
1655 + [TSN_DSCP_ATTR_COS] = { .type = NLA_U8},
1656 + [TSN_DSCP_ATTR_DPL] = { .type = NLA_U8},
1659 +static ATOMIC_NOTIFIER_HEAD(tsn_notif_chain);
1662 + * register_tsn_notifier - Register notifier
1663 + * @nb: notifier_block
1665 + * Register switch device notifier.
1667 +int register_tsn_notifier(struct notifier_block *nb)
1669 + return atomic_notifier_chain_register(&tsn_notif_chain, nb);
1671 +EXPORT_SYMBOL_GPL(register_tsn_notifier);
1674 + * unregister_tsn_notifier - Unregister notifier
1675 + * @nb: notifier_block
1677 + * Unregister switch device notifier.
1679 +int unregister_tsn_notifier(struct notifier_block *nb)
1681 + return atomic_notifier_chain_unregister(&tsn_notif_chain, nb);
1683 +EXPORT_SYMBOL_GPL(unregister_tsn_notifier);
1686 + * call_tsn_notifiers - Call notifiers
1687 + * @val: value passed unmodified to notifier function
1688 + * @dev: port device
1689 + * @info: notifier information data
1691 + * Call all network notifier blocks.
1693 +int call_tsn_notifiers(unsigned long val, struct net_device *dev,
1694 + struct tsn_notifier_info *info)
1697 + return atomic_notifier_call_chain(&tsn_notif_chain, val, info);
1699 +EXPORT_SYMBOL_GPL(call_tsn_notifiers);
1701 +struct tsn_port *tsn_get_port(struct net_device *ndev)
1703 + struct tsn_port *port;
1704 + bool tsn_found = false;
1706 + list_for_each_entry(port, &port_list, list) {
1707 + if (port->netdev == ndev) {
1718 +EXPORT_SYMBOL_GPL(tsn_get_port);
1720 +static int tsn_prepare_reply(struct genl_info *info, u8 cmd,
1721 + struct sk_buff **skbp, size_t size)
1723 + struct sk_buff *skb;
1726 + /* If new attributes are added, please revisit this allocation
1728 + skb = genlmsg_new(size, GFP_KERNEL);
1737 + reply = genlmsg_put_reply(skb, info, &tsn_family, 0, cmd);
1747 +static int tsn_mk_reply(struct sk_buff *skb, int aggr, void *data, int len)
1749 + /* add a netlink attribute to a socket buffer */
1750 + return nla_put(skb, aggr, len, data);
1753 +static int tsn_send_reply(struct sk_buff *skb, struct genl_info *info)
1755 + struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb));
1756 + void *reply = genlmsg_data(genlhdr);
1758 + genlmsg_end(skb, reply);
1760 + return genlmsg_reply(skb, info);
1763 +static int cmd_attr_echo_message(struct genl_info *info)
1765 + struct nlattr *na;
1767 + struct sk_buff *rep_skb;
1771 + na = info->attrs[TSN_CMD_ATTR_MESG];
1775 + msg = (char *)nla_data(na);
1776 + pr_info("tsn generic netlink receive echo mesg %s\n", msg);
1778 + size = nla_total_size(strlen(msg) + 1);
1780 + ret = tsn_prepare_reply(info, TSN_CMD_REPLY, &rep_skb,
1781 + size + NLMSG_ALIGN(MAX_USER_SIZE));
1785 + ret = tsn_mk_reply(rep_skb, TSN_CMD_ATTR_MESG, msg, size);
1789 + return tsn_send_reply(rep_skb, info);
1792 + nlmsg_free(rep_skb);
1796 +static int cmd_attr_echo_data(struct genl_info *info)
1798 + struct nlattr *na;
1800 + struct sk_buff *rep_skb;
1805 + na = info->attrs[TSN_CMD_ATTR_DATA];
1809 + data = nla_get_s32(info->attrs[TSN_CMD_ATTR_DATA]);
1810 + pr_info("tsn generic netlink receive echo data %d\n", data);
1813 + size = nla_total_size(sizeof(s32));
1815 + ret = tsn_prepare_reply(info, TSN_CMD_REPLY, &rep_skb,
1816 + size + NLMSG_ALIGN(MAX_USER_SIZE));
1820 + /* netlink lib func */
1821 + ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, data);
1825 + return tsn_send_reply(rep_skb, info);
1828 + nlmsg_free(rep_skb);
1832 +static int tsn_echo_cmd(struct sk_buff *skb, struct genl_info *info)
1834 + if (info->attrs[TSN_CMD_ATTR_MESG])
1835 + return cmd_attr_echo_message(info);
1836 + else if (info->attrs[TSN_CMD_ATTR_DATA])
1837 + return cmd_attr_echo_data(info);
1842 +static int tsn_simple_reply(struct genl_info *info, u32 cmd,
1843 + char *portname, s32 retvalue)
1845 + struct sk_buff *rep_skb;
1850 + size = nla_total_size(strlen(portname) + 1);
1851 + size += nla_total_size(sizeof(s32));
1853 + ret = tsn_prepare_reply(info, cmd,
1854 + &rep_skb, size + NLMSG_ALIGN(MAX_USER_SIZE));
1858 + /* netlink lib func */
1859 + ret = nla_put_string(rep_skb, TSN_ATTR_IFNAME, portname);
1863 + ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, retvalue);
1867 + return tsn_send_reply(rep_skb, info);
1870 +struct tsn_port *tsn_init_check(struct genl_info *info,
1871 + struct net_device **ndev)
1873 + struct nlattr *na;
1875 + struct net_device *netdev;
1876 + struct tsn_port *port;
1877 + bool tsn_found = false;
1879 + if (!info->attrs[TSN_ATTR_IFNAME]) {
1880 + tsn_simple_reply(info, TSN_CMD_REPLY,
1881 + "no portname", -EINVAL);
1885 + na = info->attrs[TSN_ATTR_IFNAME];
1887 + portname = (char *)nla_data(na);
1889 + netdev = __dev_get_by_name(genl_info_net(info), portname);
1891 + tsn_simple_reply(info, TSN_CMD_REPLY,
1892 + "error device", -ENODEV);
1896 + list_for_each_entry(port, &port_list, list) {
1897 + if (port->netdev == netdev) {
1904 + tsn_simple_reply(info, TSN_CMD_REPLY,
1905 + netdev->name, -ENODEV);
1914 +static int tsn_cap_get(struct sk_buff *skb, struct genl_info *info)
1916 + struct sk_buff *rep_skb;
1917 + struct nlattr *tsn_cap_attr;
1920 + struct net_device *netdev;
1921 + struct genlmsghdr *genlhdr;
1922 + const struct tsn_ops *tsnops;
1923 + struct tsn_port *port;
1925 + port = tsn_init_check(info, &netdev);
1931 + tsnops = port->tsnops;
1932 + genlhdr = info->genlhdr;
1933 + if (!tsnops->get_capability) {
1934 + ret = -EOPNOTSUPP;
1938 + cap = tsnops->get_capability(netdev);
1944 + /* Pad netlink reply data */
1945 + ret = tsn_prepare_reply(info, genlhdr->cmd,
1946 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
1950 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) {
1955 + tsn_cap_attr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CAP);
1956 + if (!tsn_cap_attr) {
1961 + if (cap & TSN_CAP_QBV) {
1962 + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QBV))
1966 + if (cap & TSN_CAP_QCI) {
1967 + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QCI))
1971 + if (cap & TSN_CAP_QBU) {
1972 + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QBU))
1976 + if (cap & TSN_CAP_CBS) {
1977 + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CBS))
1981 + if (cap & TSN_CAP_CB) {
1982 + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CB))
1986 + if (cap & TSN_CAP_TBS) {
1987 + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_TBS))
1991 + if (cap & TSN_CAP_CTH) {
1992 + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CTH))
1996 + nla_nest_end(rep_skb, tsn_cap_attr);
1998 + tsn_send_reply(rep_skb, info);
2001 + nlmsg_free(rep_skb);
2004 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
2008 +static int cmd_cb_streamid_set(struct genl_info *info)
2010 + struct nlattr *na, *sid[TSN_STREAMID_ATTR_MAX + 1];
2015 + struct net_device *netdev;
2016 + struct tsn_cb_streamid sidconf;
2017 + const struct tsn_ops *tsnops;
2018 + struct tsn_port *port;
2020 + port = tsn_init_check(info, &netdev);
2024 + tsnops = port->tsnops;
2026 + memset(&sidconf, 0, sizeof(struct tsn_cb_streamid));
2028 + if (!info->attrs[TSN_ATTR_STREAM_IDENTIFY])
2031 + na = info->attrs[TSN_ATTR_STREAM_IDENTIFY];
2033 + ret = NLA_PARSE_NESTED(sid, TSN_STREAMID_ATTR_MAX,
2034 + na, cb_streamid_policy);
2038 + if (!sid[TSN_STREAMID_ATTR_INDEX])
2041 + sid_index = nla_get_u32(sid[TSN_STREAMID_ATTR_INDEX]);
2043 + if (sid[TSN_STREAMID_ATTR_ENABLE])
2045 + else if (sid[TSN_STREAMID_ATTR_DISABLE])
2053 + if (sid[TSN_STREAMID_ATTR_TYPE])
2054 + iden_type = nla_get_u8(sid[TSN_STREAMID_ATTR_TYPE]);
2058 + sidconf.type = iden_type;
2059 + switch (iden_type) {
2060 + case STREAMID_NULL:
2061 + if (!sid[TSN_STREAMID_ATTR_NDMAC] ||
2062 + !sid[TSN_STREAMID_ATTR_NTAGGED] ||
2063 + !sid[TSN_STREAMID_ATTR_NVID]) {
2067 + sidconf.para.nid.dmac =
2068 + nla_get_u64(sid[TSN_STREAMID_ATTR_NDMAC]);
2069 + sidconf.para.nid.tagged =
2070 + nla_get_u8(sid[TSN_STREAMID_ATTR_NTAGGED]);
2071 + sidconf.para.nid.vid =
2072 + nla_get_u16(sid[TSN_STREAMID_ATTR_NVID]);
2074 + case STREAMID_SMAC_VLAN:
2075 + /* TODO: not supportted yet */
2076 + if (!sid[TSN_STREAMID_ATTR_SMAC] ||
2077 + !sid[TSN_STREAMID_ATTR_STAGGED] ||
2078 + !sid[TSN_STREAMID_ATTR_SVID]) {
2082 + sidconf.para.sid.smac =
2083 + nla_get_u64(sid[TSN_STREAMID_ATTR_SMAC]);
2084 + sidconf.para.sid.tagged =
2085 + nla_get_u8(sid[TSN_STREAMID_ATTR_STAGGED]);
2086 + sidconf.para.sid.vid =
2087 + nla_get_u16(sid[TSN_STREAMID_ATTR_SVID]);
2089 + case STREAMID_DMAC_VLAN:
2094 + tsn_simple_reply(info, TSN_CMD_REPLY,
2095 + netdev->name, -EINVAL);
2099 + if (sid[TSN_STREAMID_ATTR_STREAM_HANDLE])
2101 + nla_get_s32(sid[TSN_STREAMID_ATTR_STREAM_HANDLE]);
2103 + if (sid[TSN_STREAMID_ATTR_IFOP])
2104 + sidconf.ifac_oport = nla_get_u32(sid[TSN_STREAMID_ATTR_IFOP]);
2105 + if (sid[TSN_STREAMID_ATTR_OFOP])
2106 + sidconf.ofac_oport = nla_get_u32(sid[TSN_STREAMID_ATTR_OFOP]);
2107 + if (sid[TSN_STREAMID_ATTR_IFIP])
2108 + sidconf.ifac_iport = nla_get_u32(sid[TSN_STREAMID_ATTR_IFIP]);
2109 + if (sid[TSN_STREAMID_ATTR_OFIP])
2110 + sidconf.ofac_iport = nla_get_u32(sid[TSN_STREAMID_ATTR_OFIP]);
2113 + if (!tsnops->cb_streamid_set) {
2114 + tsn_simple_reply(info, TSN_CMD_REPLY,
2115 + netdev->name, -EPERM);
2116 + return -EOPNOTSUPP;
2119 + ret = tsnops->cb_streamid_set(netdev, sid_index, enable, &sidconf);
2121 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
2125 + /* simple reply here. To be continue */
2126 + if (tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0))
2132 +static int tsn_cb_streamid_set(struct sk_buff *skb, struct genl_info *info)
2134 + if (info->attrs[TSN_ATTR_IFNAME]) {
2135 + cmd_cb_streamid_set(info);
2142 +static int cmd_cb_streamid_get(struct genl_info *info)
2144 + struct nlattr *na, *sidattr, *sid[TSN_STREAMID_ATTR_MAX + 1];
2146 + struct genlmsghdr *genlhdr;
2147 + struct sk_buff *rep_skb;
2150 + struct net_device *netdev;
2151 + struct tsn_cb_streamid sidconf;
2152 + struct tsn_cb_streamid_counters sidcounts;
2153 + const struct tsn_ops *tsnops;
2154 + struct tsn_port *port;
2156 + port = tsn_init_check(info, &netdev);
2160 + tsnops = port->tsnops;
2162 + memset(&sidconf, 0, sizeof(struct tsn_cb_streamid));
2163 + memset(&sidcounts, 0, sizeof(struct tsn_cb_streamid_counters));
2165 + if (!info->attrs[TSN_ATTR_STREAM_IDENTIFY])
2168 + na = info->attrs[TSN_ATTR_STREAM_IDENTIFY];
2170 + ret = NLA_PARSE_NESTED(sid, TSN_STREAMID_ATTR_MAX,
2171 + na, cb_streamid_policy);
2175 + if (!sid[TSN_STREAMID_ATTR_INDEX])
2178 + sid_index = nla_get_u32(sid[TSN_STREAMID_ATTR_INDEX]);
2180 + if (!tsnops->cb_streamid_get) {
2181 + tsn_simple_reply(info, TSN_CMD_REPLY,
2182 + netdev->name, -EPERM);
2186 + valid = tsnops->cb_streamid_get(netdev, sid_index, &sidconf);
2188 + tsn_simple_reply(info, TSN_CMD_REPLY,
2189 + netdev->name, valid);
2195 + genlhdr = info->genlhdr;
2196 + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
2197 + NLMSG_ALIGN(MAX_ATTR_SIZE));
2201 + /* input netlink the parameters */
2202 + sidattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_STREAM_IDENTIFY);
2208 + if (nla_put_u32(rep_skb, TSN_STREAMID_ATTR_INDEX, sid_index))
2212 + nla_put_flag(rep_skb, TSN_STREAMID_ATTR_ENABLE);
2213 + } else if (valid == 0) {
2214 + nla_put_flag(rep_skb, TSN_STREAMID_ATTR_DISABLE);
2216 + tsn_simple_reply(info, TSN_CMD_REPLY,
2217 + netdev->name, -EINVAL);
2221 + if (nla_put_s32(rep_skb,
2222 + TSN_STREAMID_ATTR_STREAM_HANDLE, sidconf.handle) ||
2223 + nla_put_u32(rep_skb, TSN_STREAMID_ATTR_IFOP, sidconf.ifac_oport) ||
2224 + nla_put_u32(rep_skb, TSN_STREAMID_ATTR_OFOP, sidconf.ofac_oport) ||
2225 + nla_put_u32(rep_skb, TSN_STREAMID_ATTR_IFIP, sidconf.ifac_iport) ||
2226 + nla_put_u32(rep_skb, TSN_STREAMID_ATTR_OFIP, sidconf.ofac_iport) ||
2227 + nla_put_u8(rep_skb, TSN_STREAMID_ATTR_TYPE, sidconf.type))
2230 + switch (sidconf.type) {
2231 + case STREAMID_NULL:
2232 + if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_NDMAC,
2233 + sidconf.para.nid.dmac) ||
2234 + nla_put_u16(rep_skb, TSN_STREAMID_ATTR_NVID,
2235 + sidconf.para.nid.vid) ||
2236 + nla_put_u8(rep_skb, TSN_STREAMID_ATTR_NTAGGED,
2237 + sidconf.para.nid.tagged))
2240 + case STREAMID_SMAC_VLAN:
2241 + if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_SMAC,
2242 + sidconf.para.sid.smac) ||
2243 + nla_put_u16(rep_skb, TSN_STREAMID_ATTR_SVID,
2244 + sidconf.para.sid.vid) ||
2245 + nla_put_u8(rep_skb, TSN_STREAMID_ATTR_STAGGED,
2246 + sidconf.para.sid.tagged))
2249 + case STREAMID_DMAC_VLAN:
2252 + tsn_simple_reply(info, TSN_CMD_REPLY,
2253 + netdev->name, -EINVAL);
2257 + if (!tsnops->cb_streamid_counters_get) {
2258 + tsn_simple_reply(info, TSN_CMD_REPLY,
2259 + netdev->name, -EPERM);
2262 + ret = tsnops->cb_streamid_counters_get(netdev,
2266 + tsn_simple_reply(info, TSN_CMD_REPLY,
2267 + netdev->name, ret);
2272 + if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSI,
2273 + sidcounts.per_stream.input) ||
2274 + NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSO,
2275 + sidcounts.per_stream.output))
2278 + for (i = 0; i < 32; i++) {
2279 + if (NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSPPI,
2280 + sidcounts.per_streamport[i].input) ||
2281 + NLA_PUT_U64(rep_skb, TSN_STREAMID_ATTR_COUNTERS_PSPPO,
2282 + sidcounts.per_streamport[i].output))
2286 + nla_nest_end(rep_skb, sidattr);
2287 + /* end netlink input the parameters */
2289 + /* netlink lib func */
2290 + ret = nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name);
2294 + ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, 0);
2298 + return tsn_send_reply(rep_skb, info);
2301 + nlmsg_free(rep_skb);
2306 +static int tsn_cb_streamid_get(struct sk_buff *skb, struct genl_info *info)
2308 + if (info->attrs[TSN_ATTR_IFNAME]) {
2309 + cmd_cb_streamid_get(info);
2316 +static int cmb_cb_streamid_counters_get(struct genl_info *info)
2321 +static int tsn_cb_streamid_counters_get(struct sk_buff *skb,
2322 + struct genl_info *info)
2324 + if (info->attrs[TSN_ATTR_IFNAME]) {
2325 + cmb_cb_streamid_counters_get(info);
2332 +static int tsn_qci_cap_get(struct sk_buff *skb, struct genl_info *info)
2334 + struct nlattr *qci_cap;
2335 + struct sk_buff *rep_skb;
2337 + struct net_device *netdev;
2338 + struct genlmsghdr *genlhdr;
2339 + struct tsn_qci_psfp_stream_param qci_cap_status;
2340 + const struct tsn_ops *tsnops;
2341 + struct tsn_port *port;
2343 + port = tsn_init_check(info, &netdev);
2349 + tsnops = port->tsnops;
2351 + genlhdr = info->genlhdr;
2353 + memset(&qci_cap_status, 0, sizeof(qci_cap_status));
2355 + if (!tsnops->qci_get_maxcap) {
2356 + ret = -EOPNOTSUPP;
2360 + ret = tsnops->qci_get_maxcap(netdev, &qci_cap_status);
2364 + /* Pad netlink reply data */
2365 + ret = tsn_prepare_reply(info, genlhdr->cmd,
2366 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
2370 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) {
2375 + qci_cap = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SP);
2381 + if (nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_MAX_SFI,
2382 + qci_cap_status.max_sf_instance) ||
2383 + nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_MAX_SGI,
2384 + qci_cap_status.max_sg_instance) ||
2385 + nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_MAX_FMI,
2386 + qci_cap_status.max_fm_instance) ||
2387 + nla_put_u32(rep_skb, TSN_QCI_STREAM_ATTR_SLM,
2388 + qci_cap_status.supported_list_max)) {
2393 + nla_nest_end(rep_skb, qci_cap);
2395 + tsn_send_reply(rep_skb, info);
2399 + nlmsg_free(rep_skb);
2402 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
2407 +static int cmd_qci_sfi_set(struct genl_info *info)
2409 + struct nlattr *na, *sfi[TSN_QCI_SFI_ATTR_MAX + 1];
2413 + struct net_device *netdev;
2414 + struct tsn_qci_psfp_sfi_conf sficonf;
2415 + const struct tsn_ops *tsnops;
2416 + struct tsn_port *port;
2418 + port = tsn_init_check(info, &netdev);
2422 + tsnops = port->tsnops;
2424 + memset(&sficonf, 0, sizeof(struct tsn_qci_psfp_sfi_conf));
2426 + if (!info->attrs[TSN_ATTR_QCI_SFI])
2429 + na = info->attrs[TSN_ATTR_QCI_SFI];
2431 + ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX, na, qci_sfi_policy);
2433 + pr_info("tsn: parse value TSN_QCI_SFI_ATTR_MAX error.");
2437 + if (!sfi[TSN_QCI_SFI_ATTR_INDEX])
2440 + sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]);
2442 + if (sfi[TSN_QCI_SFI_ATTR_ENABLE]) {
2444 + } else if (sfi[TSN_QCI_SFI_ATTR_DISABLE]) {
2448 + pr_err("tsn: must provde ENABLE or DISABLE attribute.\n");
2449 + tsn_simple_reply(info, TSN_CMD_REPLY,
2450 + netdev->name, -EINVAL);
2454 + if (!sfi[TSN_QCI_SFI_ATTR_GATE_ID]) {
2455 + pr_err("tsn: must provide stream gate index\n");
2456 + tsn_simple_reply(info, TSN_CMD_REPLY,
2457 + netdev->name, -EINVAL);
2461 + if (!sfi[TSN_QCI_SFI_ATTR_STREAM_HANDLE])
2462 + sficonf.stream_handle_spec = -1;
2464 + sficonf.stream_handle_spec =
2465 + nla_get_s32(sfi[TSN_QCI_SFI_ATTR_STREAM_HANDLE]);
2467 + if (!sfi[TSN_QCI_SFI_ATTR_PRIO_SPEC])
2468 + sficonf.priority_spec = -1;
2470 + sficonf.priority_spec =
2471 + nla_get_s8(sfi[TSN_QCI_SFI_ATTR_PRIO_SPEC]);
2473 + sficonf.stream_gate_instance_id =
2474 + nla_get_u32(sfi[TSN_QCI_SFI_ATTR_GATE_ID]);
2476 + if (sfi[TSN_QCI_SFI_ATTR_MAXSDU])
2477 + sficonf.stream_filter.maximum_sdu_size =
2478 + nla_get_u16(sfi[TSN_QCI_SFI_ATTR_MAXSDU]);
2480 + sficonf.stream_filter.maximum_sdu_size = 0;
2482 + if (sfi[TSN_QCI_SFI_ATTR_FLOW_ID])
2483 + sficonf.stream_filter.flow_meter_instance_id =
2484 + nla_get_s32(sfi[TSN_QCI_SFI_ATTR_FLOW_ID]);
2486 + sficonf.stream_filter.flow_meter_instance_id = -1;
2488 + if (sfi[TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE])
2489 + sficonf.block_oversize_enable = true;
2491 + if (sfi[TSN_QCI_SFI_ATTR_OVERSIZE])
2492 + sficonf.block_oversize = true;
2495 + if (!tsnops->qci_sfi_set) {
2496 + tsn_simple_reply(info, TSN_CMD_REPLY,
2497 + netdev->name, -EPERM);
2501 + ret = tsnops->qci_sfi_set(netdev, sfi_handle, enable, &sficonf);
2503 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
2507 + ret = tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0);
2514 +static int tsn_qci_sfi_set(struct sk_buff *skb, struct genl_info *info)
2516 + if (info->attrs[TSN_ATTR_IFNAME]) {
2517 + cmd_qci_sfi_set(info);
2524 +static int cmd_qci_sfi_get(struct genl_info *info)
2526 + struct nlattr *na, *sfiattr;
2527 + struct nlattr *sfi[TSN_QCI_SFI_ATTR_MAX + 1];
2529 + struct sk_buff *rep_skb;
2530 + int ret, valid = 0;
2531 + struct net_device *netdev;
2532 + struct genlmsghdr *genlhdr;
2533 + struct tsn_qci_psfp_sfi_conf sficonf;
2534 + struct tsn_qci_psfp_sfi_counters sficount;
2535 + const struct tsn_ops *tsnops;
2536 + struct tsn_port *port;
2538 + port = tsn_init_check(info, &netdev);
2542 + tsnops = port->tsnops;
2544 + genlhdr = info->genlhdr;
2546 + if (!info->attrs[TSN_ATTR_QCI_SFI])
2549 + na = info->attrs[TSN_ATTR_QCI_SFI];
2551 + ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX,
2552 + na, qci_sfi_policy);
2556 + if (!sfi[TSN_QCI_SFI_ATTR_INDEX])
2559 + sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]);
2561 + memset(&sficonf, 0, sizeof(struct tsn_qci_psfp_sfi_conf));
2562 + memset(&sficount, 0, sizeof(struct tsn_qci_psfp_sfi_counters));
2564 + if (!tsnops->qci_sfi_get || !tsnops->qci_sfi_counters_get) {
2565 + tsn_simple_reply(info, TSN_CMD_REPLY,
2566 + netdev->name, -EPERM);
2570 + valid = tsnops->qci_sfi_get(netdev, sfi_handle, &sficonf);
2572 + tsn_simple_reply(info, TSN_CMD_REPLY,
2573 + netdev->name, valid);
2577 + valid = tsnops->qci_sfi_counters_get(netdev, sfi_handle,
2580 + tsn_simple_reply(info, TSN_CMD_REPLY,
2581 + netdev->name, valid);
2586 + ret = tsn_prepare_reply(info, genlhdr->cmd,
2587 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
2591 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
2594 + sfiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SFI);
2596 + tsn_simple_reply(info, TSN_CMD_REPLY,
2597 + netdev->name, -EINVAL);
2602 + if (nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_INDEX, sfi_handle))
2606 + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_ENABLE))
2609 + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_DISABLE))
2613 + if (nla_put_s32(rep_skb, TSN_QCI_SFI_ATTR_STREAM_HANDLE,
2614 + sficonf.stream_handle_spec) ||
2615 + nla_put_s8(rep_skb, TSN_QCI_SFI_ATTR_PRIO_SPEC,
2616 + sficonf.priority_spec) ||
2617 + nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_GATE_ID,
2618 + sficonf.stream_gate_instance_id))
2621 + if (sficonf.stream_filter.maximum_sdu_size)
2622 + if (nla_put_u16(rep_skb, TSN_QCI_SFI_ATTR_MAXSDU,
2623 + sficonf.stream_filter.maximum_sdu_size))
2626 + if (sficonf.stream_filter.flow_meter_instance_id >= 0)
2627 + if (nla_put_s32(rep_skb, TSN_QCI_SFI_ATTR_FLOW_ID,
2628 + sficonf.stream_filter.flow_meter_instance_id))
2631 + if (sficonf.block_oversize_enable)
2632 + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE))
2634 + if (sficonf.block_oversize)
2635 + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_OVERSIZE))
2638 + if (nla_put(rep_skb, TSN_QCI_SFI_ATTR_COUNTERS,
2639 + sizeof(struct tsn_qci_psfp_sfi_counters), &sficount))
2642 + nla_nest_end(rep_skb, sfiattr);
2644 + return tsn_send_reply(rep_skb, info);
2646 + nlmsg_free(rep_skb);
2647 + tsn_simple_reply(info, TSN_CMD_REPLY,
2648 + netdev->name, -EINVAL);
2653 +static int tsn_qci_sfi_get(struct sk_buff *skb, struct genl_info *info)
2655 + if (info->attrs[TSN_ATTR_IFNAME]) {
2656 + cmd_qci_sfi_get(info);
2663 +static int cmd_qci_sfi_counters_get(struct genl_info *info)
2665 + struct nlattr *na, *sfiattr;
2666 + struct nlattr *sfi[TSN_QCI_SFI_ATTR_MAX + 1];
2668 + struct sk_buff *rep_skb;
2670 + struct net_device *netdev;
2671 + struct genlmsghdr *genlhdr;
2672 + struct tsn_qci_psfp_sfi_counters sficount;
2673 + const struct tsn_ops *tsnops;
2674 + struct tsn_port *port;
2676 + port = tsn_init_check(info, &netdev);
2680 + tsnops = port->tsnops;
2682 + genlhdr = info->genlhdr;
2684 + if (!info->attrs[TSN_ATTR_QCI_SFI])
2687 + na = info->attrs[TSN_ATTR_QCI_SFI];
2689 + ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX,
2690 + na, qci_sfi_policy);
2694 + if (!sfi[TSN_QCI_SFI_ATTR_INDEX])
2697 + sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]);
2699 + memset(&sficount, 0, sizeof(struct tsn_qci_psfp_sfi_counters));
2700 + if (!tsnops->qci_sfi_counters_get) {
2701 + tsn_simple_reply(info, TSN_CMD_REPLY,
2702 + netdev->name, -EPERM);
2706 + ret = tsnops->qci_sfi_counters_get(netdev, sfi_handle, &sficount);
2708 + tsn_simple_reply(info, TSN_CMD_REPLY,
2709 + netdev->name, ret);
2713 + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
2714 + NLMSG_ALIGN(MAX_ATTR_SIZE));
2718 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
2721 + sfiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SFI);
2727 + if (nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_INDEX, sfi_handle))
2730 + ret = tsnops->qci_sfi_counters_get(netdev, sfi_handle, &sficount);
2732 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
2736 + if (nla_put(rep_skb, TSN_QCI_SFI_ATTR_COUNTERS,
2737 + sizeof(struct tsn_qci_psfp_sfi_counters), &sficount))
2740 + nla_nest_end(rep_skb, sfiattr);
2742 + return tsn_send_reply(rep_skb, info);
2744 + nlmsg_free(rep_skb);
2745 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, -EINVAL);
2749 +static int tsn_qci_sfi_counters_get(struct sk_buff *skb, struct genl_info *info)
2751 + if (info->attrs[TSN_ATTR_IFNAME]) {
2752 + cmd_qci_sfi_counters_get(info);
2759 +static int cmd_qci_sgi_set(struct genl_info *info)
2761 + struct nlattr *na;
2762 + struct nlattr *sgia[TSN_QCI_SGI_ATTR_MAX + 1];
2763 + struct nlattr *admin[TSN_SGI_ATTR_CTRL_MAX + 1];
2765 + struct net_device *netdev;
2766 + const struct tsn_ops *tsnops;
2767 + struct tsn_qci_psfp_sgi_conf sgi;
2768 + struct tsn_qci_psfp_gcl *gcl = NULL;
2769 + u16 sgi_handle = 0;
2770 + u16 listcount = 0;
2771 + struct tsn_port *port;
2773 + port = tsn_init_check(info, &netdev);
2777 + tsnops = port->tsnops;
2779 + memset(&sgi, 0, sizeof(struct tsn_qci_psfp_sgi_conf));
2781 + if (!info->attrs[TSN_ATTR_QCI_SGI]) {
2782 + tsn_simple_reply(info, TSN_CMD_REPLY,
2783 + netdev->name, -EINVAL);
2787 + na = info->attrs[TSN_ATTR_QCI_SGI];
2789 + ret = NLA_PARSE_NESTED(sgia, TSN_QCI_SGI_ATTR_MAX,
2790 + na, qci_sgi_policy);
2792 + tsn_simple_reply(info, TSN_CMD_REPLY,
2793 + netdev->name, -EINVAL);
2797 + if (sgia[TSN_QCI_SGI_ATTR_ENABLE] && sgia[TSN_QCI_SGI_ATTR_DISABLE]) {
2798 + pr_err("tsn: enable or disable?\n");
2799 + tsn_simple_reply(info, TSN_CMD_REPLY,
2800 + netdev->name, -EINVAL);
2804 + if (sgia[TSN_QCI_SGI_ATTR_INDEX])
2805 + sgi_handle = nla_get_u32(sgia[TSN_QCI_SGI_ATTR_INDEX]);
2807 + if (sgia[TSN_QCI_SGI_ATTR_DISABLE]) {
2808 + sgi.gate_enabled = 0;
2811 + /* set default to be enable*/
2812 + sgi.gate_enabled = 1;
2815 + if (sgia[TSN_QCI_SGI_ATTR_CONFCHANGE])
2816 + sgi.config_change = 1;
2818 + if (sgia[TSN_QCI_SGI_ATTR_IRXEN])
2819 + sgi.block_invalid_rx_enable = 1;
2821 + if (sgia[TSN_QCI_SGI_ATTR_IRX])
2822 + sgi.block_invalid_rx = 1;
2824 + if (sgia[TSN_QCI_SGI_ATTR_OEXEN])
2825 + sgi.block_octets_exceeded_enable = 1;
2827 + if (sgia[TSN_QCI_SGI_ATTR_OEX])
2828 + sgi.block_octets_exceeded = 1;
2830 + if (sgia[TSN_QCI_SGI_ATTR_ADMINENTRY]) {
2831 + struct nlattr *entry;
2835 + na = sgia[TSN_QCI_SGI_ATTR_ADMINENTRY];
2836 + ret = NLA_PARSE_NESTED(admin, TSN_SGI_ATTR_CTRL_MAX,
2837 + na, qci_sgi_ctrl_policy);
2839 + /* Other parameters in admin control */
2840 + if (admin[TSN_SGI_ATTR_CTRL_INITSTATE])
2841 + sgi.admin.gate_states = 1;
2843 + if (admin[TSN_SGI_ATTR_CTRL_CYTIME])
2844 + sgi.admin.cycle_time =
2845 + nla_get_u32(admin[TSN_SGI_ATTR_CTRL_CYTIME]);
2847 + if (admin[TSN_SGI_ATTR_CTRL_CYTIMEEX])
2848 + sgi.admin.cycle_time_extension =
2849 + nla_get_u32(admin[TSN_SGI_ATTR_CTRL_CYTIMEEX]);
2851 + if (admin[TSN_SGI_ATTR_CTRL_BTIME])
2852 + sgi.admin.base_time =
2853 + nla_get_u64(admin[TSN_SGI_ATTR_CTRL_BTIME]);
2855 + if (admin[TSN_SGI_ATTR_CTRL_INITIPV])
2856 + sgi.admin.init_ipv =
2857 + nla_get_s8(admin[TSN_SGI_ATTR_CTRL_INITIPV]);
2859 + sgi.admin.init_ipv = -1;
2861 + if (admin[TSN_SGI_ATTR_CTRL_LEN]) {
2862 + sgi.admin.control_list_length =
2863 + nla_get_u8(admin[TSN_SGI_ATTR_CTRL_LEN]);
2864 + listcount = sgi.admin.control_list_length;
2870 + gcl = kmalloc_array(listcount, sizeof(*gcl), GFP_KERNEL);
2872 + memset(gcl, 0, listcount * sizeof(struct tsn_qci_psfp_gcl));
2874 + /* Check the whole admin attrs,
2875 + * checkout the TSN_SGI_ATTR_CTRL_GCLENTRY attributes
2877 + nla_for_each_nested(entry, na, rem) {
2878 + struct nlattr *gcl_entry[TSN_SGI_ATTR_GCL_MAX + 1];
2879 + struct nlattr *ti, *om;
2881 + if (nla_type(entry) != TSN_SGI_ATTR_CTRL_GCLENTRY)
2884 + /* parse each TSN_SGI_ATTR_CTRL_GCLENTRY */
2885 + ret = NLA_PARSE_NESTED(gcl_entry, TSN_SGI_ATTR_GCL_MAX,
2886 + entry, qci_sgi_gcl_policy);
2887 + /* Parse gate control list */
2888 + if (gcl_entry[TSN_SGI_ATTR_GCL_GATESTATE])
2889 + (gcl + count)->gate_state = 1;
2891 + if (gcl_entry[TSN_SGI_ATTR_GCL_IPV])
2892 + (gcl + count)->ipv =
2893 + nla_get_s8(gcl_entry[TSN_SGI_ATTR_GCL_IPV]);
2895 + if (gcl_entry[TSN_SGI_ATTR_GCL_INTERVAL]) {
2896 + ti = gcl_entry[TSN_SGI_ATTR_GCL_INTERVAL];
2897 + (gcl + count)->time_interval = nla_get_u32(ti);
2900 + if (gcl_entry[TSN_SGI_ATTR_GCL_OCTMAX]) {
2901 + om = gcl_entry[TSN_SGI_ATTR_GCL_OCTMAX];
2902 + (gcl + count)->octet_max = nla_get_u32(om);
2907 + if (count >= listcount)
2911 + if (count < listcount) {
2912 + tsn_simple_reply(info, TSN_CMD_REPLY,
2913 + netdev->name, -EINVAL);
2914 + pr_err("tsn: count less than TSN_SGI_ATTR_CTRL_LEN\n");
2920 + pr_info("tsn: no admin list parameters setting\n");
2924 + if (!tsnops->qci_sgi_set) {
2925 + tsn_simple_reply(info, TSN_CMD_REPLY,
2926 + netdev->name, -EPERM);
2931 + sgi.admin.gcl = gcl;
2933 + ret = tsnops->qci_sgi_set(netdev, sgi_handle, &sgi);
2936 + return tsn_simple_reply(info, TSN_CMD_REPLY,
2939 + tsn_simple_reply(info, TSN_CMD_REPLY,
2940 + netdev->name, ret);
2944 +static int tsn_qci_sgi_set(struct sk_buff *skb, struct genl_info *info)
2946 + if (info->attrs[TSN_ATTR_IFNAME]) {
2947 + cmd_qci_sgi_set(info);
2954 +static int cmd_qci_sgi_get(struct genl_info *info)
2956 + struct nlattr *na, *sgiattr, *adminattr, *sglattr;
2957 + struct nlattr *sgi[TSN_QCI_SGI_ATTR_MAX + 1];
2958 + struct sk_buff *rep_skb;
2960 + struct net_device *netdev;
2961 + struct genlmsghdr *genlhdr;
2962 + struct tsn_qci_psfp_sgi_conf sgiadmin;
2963 + struct tsn_qci_psfp_gcl *gcl = NULL;
2964 + const struct tsn_ops *tsnops;
2967 + struct tsn_port *port;
2969 + port = tsn_init_check(info, &netdev);
2973 + tsnops = port->tsnops;
2975 + if (!info->attrs[TSN_ATTR_QCI_SGI]) {
2976 + tsn_simple_reply(info, TSN_CMD_REPLY,
2977 + netdev->name, -EINVAL);
2978 + pr_err("tsn: no sgi handle input\n");
2982 + na = info->attrs[TSN_ATTR_QCI_SGI];
2984 + ret = NLA_PARSE_NESTED(sgi, TSN_QCI_SGI_ATTR_MAX,
2985 + na, qci_sgi_policy);
2989 + if (!sgi[TSN_QCI_SGI_ATTR_INDEX]) {
2990 + tsn_simple_reply(info, TSN_CMD_REPLY,
2991 + netdev->name, -EINVAL);
2992 + pr_err("tsn: no sgi handle input\n");
2996 + sgi_handle = nla_get_u32(sgi[TSN_QCI_SGI_ATTR_INDEX]);
2998 + /* Get config data from device */
2999 + genlhdr = info->genlhdr;
3001 + memset(&sgiadmin, 0, sizeof(struct tsn_qci_psfp_sgi_conf));
3003 + if (!tsnops->qci_sgi_get) {
3004 + tsn_simple_reply(info, TSN_CMD_REPLY,
3005 + netdev->name, -EPERM);
3009 + ret = tsnops->qci_sgi_get(netdev, sgi_handle, &sgiadmin);
3011 + tsn_simple_reply(info, TSN_CMD_REPLY,
3012 + netdev->name, ret);
3016 + /* Form netlink reply data */
3017 + ret = tsn_prepare_reply(info, genlhdr->cmd,
3018 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
3022 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
3025 + sgiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SGI);
3029 + if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_INDEX, sgi_handle))
3032 + /* Gate enable? sgiadmin.gate_enabled */
3033 + if (sgiadmin.gate_enabled) {
3034 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_ENABLE))
3037 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_DISABLE))
3041 + if (sgiadmin.config_change)
3042 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_CONFCHANGE))
3045 + if (sgiadmin.block_invalid_rx_enable)
3046 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_IRXEN))
3049 + if (sgiadmin.block_invalid_rx)
3050 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_IRX))
3053 + if (sgiadmin.block_octets_exceeded_enable)
3054 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_OEXEN))
3057 + if (sgiadmin.block_octets_exceeded)
3058 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_OEX))
3061 + /* Administration */
3062 + adminattr = nla_nest_start_noflag(rep_skb, TSN_QCI_SGI_ATTR_ADMINENTRY);
3066 + if (sgiadmin.admin.gate_states)
3067 + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_CTRL_INITSTATE))
3070 + if (nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIME,
3071 + sgiadmin.admin.cycle_time) ||
3072 + nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIMEEX,
3073 + sgiadmin.admin.cycle_time_extension) ||
3074 + NLA_PUT_U64(rep_skb, TSN_SGI_ATTR_CTRL_BTIME,
3075 + sgiadmin.admin.base_time) ||
3076 + nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_INITIPV,
3077 + sgiadmin.admin.init_ipv))
3080 + listcount = sgiadmin.admin.control_list_length;
3084 + if (!sgiadmin.admin.gcl) {
3085 + pr_err("error: no gate control list\n");
3090 + gcl = sgiadmin.admin.gcl;
3093 + for (i = 0; i < listcount; i++) {
3098 + pr_err("error: list count too big\n");
3100 + kfree(sgiadmin.admin.gcl);
3104 + /* Adminastration entry */
3105 + sglattr = nla_nest_start_noflag(rep_skb,
3106 + TSN_SGI_ATTR_CTRL_GCLENTRY);
3109 + ipv = (gcl + i)->ipv;
3110 + ti = (gcl + i)->time_interval;
3111 + omax = (gcl + i)->octet_max;
3113 + if ((gcl + i)->gate_state)
3114 + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_GCL_GATESTATE))
3117 + if (nla_put_s8(rep_skb, TSN_SGI_ATTR_GCL_IPV, ipv) ||
3118 + nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_INTERVAL, ti) ||
3119 + nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_OCTMAX, omax))
3122 + /* End administration entry */
3123 + nla_nest_end(rep_skb, sglattr);
3126 + kfree(sgiadmin.admin.gcl);
3127 + if (nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_LEN, listcount))
3131 + /* End adminastration */
3132 + nla_nest_end(rep_skb, adminattr);
3134 + nla_nest_end(rep_skb, sgiattr);
3136 + return tsn_send_reply(rep_skb, info);
3138 + nlmsg_free(rep_skb);
3139 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
3143 +static int tsn_qci_sgi_get(struct sk_buff *skb, struct genl_info *info)
3145 + if (info->attrs[TSN_ATTR_IFNAME]) {
3146 + cmd_qci_sgi_get(info);
3153 +static int cmd_qci_sgi_status_get(struct genl_info *info)
3155 + struct nlattr *na, *sgiattr, *operattr, *sglattr;
3156 + struct nlattr *sgi[TSN_QCI_SGI_ATTR_MAX + 1];
3157 + struct sk_buff *rep_skb;
3159 + struct net_device *netdev;
3160 + struct genlmsghdr *genlhdr;
3161 + struct tsn_psfp_sgi_status sgistat;
3162 + struct tsn_qci_psfp_gcl *gcl = NULL;
3163 + const struct tsn_ops *tsnops;
3167 + struct tsn_port *port;
3169 + port = tsn_init_check(info, &netdev);
3173 + tsnops = port->tsnops;
3175 + if (!info->attrs[TSN_ATTR_QCI_SGI]) {
3176 + tsn_simple_reply(info, TSN_CMD_REPLY,
3177 + netdev->name, -EINVAL);
3178 + pr_err("tsn: no sgi handle input\n");
3182 + na = info->attrs[TSN_ATTR_QCI_SGI];
3184 + ret = NLA_PARSE_NESTED(sgi, TSN_QCI_SGI_ATTR_MAX,
3185 + na, qci_sgi_policy);
3189 + if (!sgi[TSN_QCI_SGI_ATTR_INDEX]) {
3190 + tsn_simple_reply(info, TSN_CMD_REPLY,
3191 + netdev->name, -EINVAL);
3192 + pr_err("tsn: no sgi handle input\n");
3196 + sgi_handle = nla_get_u32(sgi[TSN_QCI_SGI_ATTR_INDEX]);
3198 + /* Get status data from device */
3199 + genlhdr = info->genlhdr;
3201 + memset(&sgistat, 0, sizeof(struct tsn_psfp_sgi_status));
3203 + if (!tsnops->qci_sgi_status_get) {
3204 + tsn_simple_reply(info, TSN_CMD_REPLY,
3205 + netdev->name, -EPERM);
3209 + valid = tsnops->qci_sgi_status_get(netdev, sgi_handle, &sgistat);
3211 + tsn_simple_reply(info, TSN_CMD_REPLY,
3212 + netdev->name, valid);
3216 + /* Form netlink reply data */
3217 + ret = tsn_prepare_reply(info, genlhdr->cmd,
3218 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
3222 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
3225 + /* Down one netlink attribute level */
3226 + sgiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SGI);
3230 + if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_INDEX, sgi_handle))
3235 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_ENABLE))
3238 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_DISABLE))
3242 + if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_TICKG,
3243 + sgistat.tick_granularity) ||
3244 + NLA_PUT_U64(rep_skb, TSN_QCI_SGI_ATTR_CCTIME,
3245 + sgistat.config_change_time) ||
3246 + NLA_PUT_U64(rep_skb, TSN_QCI_SGI_ATTR_CUTIME,
3247 + sgistat.current_time) ||
3248 + NLA_PUT_U64(rep_skb, TSN_QCI_SGI_ATTR_CCERROR,
3249 + sgistat.config_change_error))
3252 + if (sgistat.config_pending)
3253 + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_CPENDING))
3256 + /* operation data */
3257 + operattr = nla_nest_start_noflag(rep_skb, TSN_QCI_SGI_ATTR_OPERENTRY);
3261 + if (sgistat.oper.gate_states)
3262 + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_CTRL_INITSTATE))
3265 + if (nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIME,
3266 + sgistat.oper.cycle_time) ||
3267 + nla_put_u32(rep_skb, TSN_SGI_ATTR_CTRL_CYTIMEEX,
3268 + sgistat.oper.cycle_time_extension) ||
3269 + NLA_PUT_U64(rep_skb, TSN_SGI_ATTR_CTRL_BTIME,
3270 + sgistat.oper.base_time) ||
3271 + nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_INITIPV,
3272 + sgistat.oper.init_ipv))
3276 + listcount = sgistat.oper.control_list_length;
3280 + if (!sgistat.oper.gcl) {
3281 + pr_err("error: list lenghth is not zero!\n");
3286 + gcl = sgistat.oper.gcl;
3289 + for (i = 0; i < listcount; i++) {
3294 + pr_err("error: list count too big\n");
3296 + kfree(sgistat.oper.gcl);
3300 + /* Operation entry */
3301 + sglattr = nla_nest_start_noflag(rep_skb,
3302 + TSN_SGI_ATTR_CTRL_GCLENTRY);
3305 + ipv = (gcl + i)->ipv;
3306 + ti = (gcl + i)->time_interval;
3307 + omax = (gcl + i)->octet_max;
3309 + if ((gcl + i)->gate_state)
3310 + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_GCL_GATESTATE))
3313 + if (nla_put_s8(rep_skb, TSN_SGI_ATTR_GCL_IPV, ipv) ||
3314 + nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_INTERVAL, ti) ||
3315 + nla_put_u32(rep_skb, TSN_SGI_ATTR_GCL_OCTMAX, omax))
3318 + /* End operation entry */
3319 + nla_nest_end(rep_skb, sglattr);
3322 + kfree(sgistat.oper.gcl);
3323 + if (nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_LEN, listcount))
3326 + /* End operation */
3327 + nla_nest_end(rep_skb, operattr);
3329 + nla_nest_end(rep_skb, sgiattr);
3331 + return tsn_send_reply(rep_skb, info);
3333 + nlmsg_free(rep_skb);
3334 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
3338 +static int tsn_qci_sgi_status_get(struct sk_buff *skb, struct genl_info *info)
3340 + if (info->attrs[TSN_ATTR_IFNAME]) {
3341 + cmd_qci_sgi_status_get(info);
3348 +static int cmd_qci_fmi_set(struct genl_info *info)
3350 + struct nlattr *na, *fmi[TSN_QCI_FMI_ATTR_MAX + 1];
3353 + struct net_device *netdev;
3354 + struct tsn_qci_psfp_fmi fmiconf;
3355 + const struct tsn_ops *tsnops;
3357 + struct tsn_port *port;
3359 + port = tsn_init_check(info, &netdev);
3363 + tsnops = port->tsnops;
3365 + memset(&fmiconf, 0, sizeof(struct tsn_qci_psfp_fmi));
3367 + if (!info->attrs[TSN_ATTR_QCI_FMI])
3370 + na = info->attrs[TSN_ATTR_QCI_FMI];
3372 + ret = NLA_PARSE_NESTED(fmi, TSN_QCI_FMI_ATTR_MAX, na, qci_fmi_policy);
3374 + pr_info("tsn: parse value TSN_QCI_FMI_ATTR_MAX error.");
3378 + if (!fmi[TSN_QCI_FMI_ATTR_INDEX])
3381 + index = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_INDEX]);
3383 + if (fmi[TSN_QCI_FMI_ATTR_DISABLE])
3388 + if (fmi[TSN_QCI_FMI_ATTR_CIR])
3389 + fmiconf.cir = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_CIR]);
3391 + if (fmi[TSN_QCI_FMI_ATTR_CBS])
3392 + fmiconf.cbs = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_CBS]);
3394 + if (fmi[TSN_QCI_FMI_ATTR_EIR])
3395 + fmiconf.eir = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_EIR]);
3397 + if (fmi[TSN_QCI_FMI_ATTR_EBS])
3398 + fmiconf.ebs = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_EBS]);
3400 + if (fmi[TSN_QCI_FMI_ATTR_CF])
3403 + if (fmi[TSN_QCI_FMI_ATTR_CM])
3406 + if (fmi[TSN_QCI_FMI_ATTR_DROPYL])
3407 + fmiconf.drop_on_yellow = 1;
3409 + if (fmi[TSN_QCI_FMI_ATTR_MAREDEN])
3410 + fmiconf.mark_red_enable = 1;
3412 + if (fmi[TSN_QCI_FMI_ATTR_MARED])
3413 + fmiconf.mark_red = 1;
3417 + if (!tsnops->qci_fmi_set) {
3418 + tsn_simple_reply(info, TSN_CMD_REPLY,
3419 + netdev->name, -EPERM);
3423 + ret = tsnops->qci_fmi_set(netdev, index, enable, &fmiconf);
3425 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
3429 + ret = tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0);
3436 +static int tsn_qci_fmi_set(struct sk_buff *skb, struct genl_info *info)
3438 + if (info->attrs[TSN_ATTR_IFNAME]) {
3439 + cmd_qci_fmi_set(info);
3446 +static int cmd_qci_fmi_get(struct genl_info *info)
3448 + struct nlattr *na, *fmi[TSN_QCI_FMI_ATTR_MAX + 1], *fmiattr;
3450 + struct sk_buff *rep_skb;
3452 + struct net_device *netdev;
3453 + struct tsn_qci_psfp_fmi fmiconf;
3454 + struct tsn_qci_psfp_fmi_counters counters;
3455 + const struct tsn_ops *tsnops;
3456 + struct genlmsghdr *genlhdr;
3457 + struct tsn_port *port;
3459 + port = tsn_init_check(info, &netdev);
3463 + tsnops = port->tsnops;
3465 + if (!info->attrs[TSN_ATTR_QCI_FMI])
3468 + na = info->attrs[TSN_ATTR_QCI_FMI];
3470 + ret = NLA_PARSE_NESTED(fmi, TSN_QCI_FMI_ATTR_MAX,
3471 + na, qci_fmi_policy);
3473 + pr_info("tsn: parse value TSN_QCI_FMI_ATTR_MAX error.");
3477 + if (!fmi[TSN_QCI_FMI_ATTR_INDEX])
3480 + index = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_INDEX]);
3482 + /* Get data from device */
3483 + memset(&fmiconf, 0, sizeof(struct tsn_qci_psfp_fmi));
3484 + memset(&counters, 0, sizeof(struct tsn_qci_psfp_fmi_counters));
3486 + if (!tsnops->qci_fmi_get) {
3487 + tsn_simple_reply(info, TSN_CMD_REPLY,
3488 + netdev->name, -EPERM);
3492 + ret = tsnops->qci_fmi_get(netdev, index, &fmiconf, &counters);
3494 + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret);
3498 + genlhdr = info->genlhdr;
3500 + /* Form netlink reply data */
3501 + ret = tsn_prepare_reply(info, genlhdr->cmd,
3502 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
3506 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
3509 + fmiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_FMI);
3513 + if (nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_INDEX, index) ||
3514 + nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_CIR, fmiconf.cir) ||
3515 + nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_CBS, fmiconf.cbs) ||
3516 + nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_EIR, fmiconf.eir) ||
3517 + nla_put_u32(rep_skb, TSN_QCI_FMI_ATTR_EBS, fmiconf.ebs))
3521 + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_CF))
3525 + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_CM))
3528 + if (fmiconf.drop_on_yellow)
3529 + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_DROPYL))
3532 + if (fmiconf.mark_red_enable)
3533 + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_MAREDEN))
3536 + if (fmiconf.mark_red)
3537 + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_MAREDEN))
3540 + if (nla_put(rep_skb, TSN_QCI_FMI_ATTR_COUNTERS,
3541 + sizeof(struct tsn_qci_psfp_fmi_counters), &counters))
3544 + nla_nest_end(rep_skb, fmiattr);
3546 + tsn_send_reply(rep_skb, info);
3551 +static int tsn_qci_fmi_get(struct sk_buff *skb, struct genl_info *info)
3553 + if (info->attrs[TSN_ATTR_IFNAME]) {
3554 + cmd_qci_fmi_get(info);
3561 +static int cmd_qbv_set(struct genl_info *info)
3563 + struct nlattr *na, *na1;
3564 + struct nlattr *qbv_table;
3565 + struct nlattr *qbv[TSN_QBV_ATTR_MAX + 1];
3566 + struct nlattr *qbvctrl[TSN_QBV_ATTR_CTRL_MAX + 1];
3569 + struct net_device *netdev;
3570 + struct tsn_qbv_conf qbvconfig;
3571 + const struct tsn_ops *tsnops;
3572 + struct tsn_qbv_entry *gatelist = NULL;
3574 + struct tsn_port *port;
3576 + port = tsn_init_check(info, &netdev);
3580 + tsnops = port->tsnops;
3582 + memset(&qbvconfig, 0, sizeof(struct tsn_qbv_conf));
3584 + if (!info->attrs[TSN_ATTR_QBV])
3587 + na = info->attrs[TSN_ATTR_QBV];
3589 + ret = NLA_PARSE_NESTED(qbv, TSN_QBV_ATTR_MAX, na, qbv_policy);
3593 + if (qbv[TSN_QBV_ATTR_ENABLE])
3594 + qbvconfig.gate_enabled = 1;
3598 + if (qbv[TSN_QBV_ATTR_CONFIGCHANGE])
3599 + qbvconfig.config_change = 1;
3601 + if (!qbv[TSN_QBV_ATTR_ADMINENTRY]) {
3602 + tsn_simple_reply(info, TSN_CMD_REPLY,
3603 + netdev->name, -EINVAL);
3607 + na1 = qbv[TSN_QBV_ATTR_ADMINENTRY];
3608 + NLA_PARSE_NESTED(qbvctrl, TSN_QBV_ATTR_CTRL_MAX,
3609 + na1, qbv_ctrl_policy);
3611 + if (qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIME]) {
3612 + qbvconfig.admin.cycle_time =
3613 + nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIME]);
3616 + if (qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIMEEXT]) {
3617 + qbvconfig.admin.cycle_time_extension =
3618 + nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIMEEXT]);
3621 + if (qbvctrl[TSN_QBV_ATTR_CTRL_BASETIME]) {
3622 + qbvconfig.admin.base_time =
3623 + nla_get_u64(qbvctrl[TSN_QBV_ATTR_CTRL_BASETIME]);
3626 + if (qbvctrl[TSN_QBV_ATTR_CTRL_GATESTATE]) {
3627 + qbvconfig.admin.gate_states =
3628 + nla_get_u8(qbvctrl[TSN_QBV_ATTR_CTRL_GATESTATE]);
3631 + if (qbvctrl[TSN_QBV_ATTR_CTRL_LISTCOUNT]) {
3634 + listcount = nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_LISTCOUNT]);
3636 + qbvconfig.admin.control_list_length = listcount;
3638 + gatelist = kmalloc_array(listcount,
3639 + sizeof(*gatelist),
3642 + nla_for_each_nested(qbv_table, na1, rem) {
3643 + struct nlattr *qbv_entry[TSN_QBV_ATTR_ENTRY_MAX + 1];
3645 + if (nla_type(qbv_table) != TSN_QBV_ATTR_CTRL_LISTENTRY)
3648 + ret = NLA_PARSE_NESTED(qbv_entry,
3649 + TSN_QBV_ATTR_ENTRY_MAX,
3650 + qbv_table, qbv_entry_policy);
3654 + (gatelist + count)->gate_state =
3655 + nla_get_u8(qbv_entry[TSN_QBV_ATTR_ENTRY_GC]);
3656 + (gatelist + count)->time_interval =
3657 + nla_get_u32(qbv_entry[TSN_QBV_ATTR_ENTRY_TM]);
3659 + if (count > listcount)
3665 + qbvconfig.admin.control_list = gatelist;
3668 + if (!tsnops->qbv_set) {
3669 + tsn_simple_reply(info, TSN_CMD_REPLY,
3670 + netdev->name, -EPERM);
3674 + ret = tsnops->qbv_set(netdev, &qbvconfig);
3678 + tsn_simple_reply(info, TSN_CMD_REPLY,
3679 + netdev->name, ret);
3681 + tsn_simple_reply(info, TSN_CMD_REPLY,
3689 +static int tsn_qbv_set(struct sk_buff *skb, struct genl_info *info)
3691 + if (info->attrs[TSN_ATTR_IFNAME]) {
3692 + cmd_qbv_set(info);
3699 +static int cmd_qbv_get(struct genl_info *info)
3701 + struct nlattr *qbv, *qbvadminattr;
3702 + struct sk_buff *rep_skb;
3704 + int len = 0, i = 0;
3705 + struct net_device *netdev;
3706 + struct genlmsghdr *genlhdr;
3707 + struct tsn_qbv_conf qbvconf;
3708 + const struct tsn_ops *tsnops;
3709 + struct tsn_port *port;
3711 + port = tsn_init_check(info, &netdev);
3715 + tsnops = port->tsnops;
3717 + genlhdr = info->genlhdr;
3719 + memset(&qbvconf, 0, sizeof(struct tsn_qbv_conf));
3721 + if (!tsnops->qbv_get) {
3722 + tsn_simple_reply(info, TSN_CMD_REPLY,
3723 + netdev->name, -EPERM);
3727 + ret = tsnops->qbv_get(netdev, &qbvconf);
3729 + tsn_simple_reply(info, TSN_CMD_REPLY,
3730 + netdev->name, ret);
3734 + ret = tsn_prepare_reply(info, genlhdr->cmd,
3735 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
3739 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
3742 + qbv = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBV);
3746 + qbvadminattr = nla_nest_start_noflag(rep_skb, TSN_QBV_ATTR_ADMINENTRY);
3747 + if (!qbvadminattr)
3750 + if (qbvconf.admin.control_list) {
3751 + len = qbvconf.admin.control_list_length;
3752 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_LISTCOUNT, len))
3755 + for (i = 0; i < len; i++) {
3756 + struct nlattr *qbv_table;
3759 + int glisttype = TSN_QBV_ATTR_CTRL_LISTENTRY;
3761 + gs = (qbvconf.admin.control_list + i)->gate_state;
3762 + tp = (qbvconf.admin.control_list + i)->time_interval;
3765 + nla_nest_start_noflag(rep_skb, glisttype);
3769 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_ID, i) ||
3770 + nla_put_u8(rep_skb, TSN_QBV_ATTR_ENTRY_GC, gs) ||
3771 + nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_TM, tp))
3773 + nla_nest_end(rep_skb, qbv_table);
3776 + if (qbvconf.admin.gate_states)
3777 + if (nla_put_u8(rep_skb, TSN_QBV_ATTR_CTRL_GATESTATE,
3778 + qbvconf.admin.gate_states))
3781 + if (qbvconf.admin.cycle_time)
3782 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIME,
3783 + qbvconf.admin.cycle_time))
3786 + if (qbvconf.admin.cycle_time_extension)
3787 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIMEEXT,
3788 + qbvconf.admin.cycle_time_extension))
3791 + if (qbvconf.admin.base_time)
3792 + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CTRL_BASETIME,
3793 + qbvconf.admin.base_time))
3796 + kfree(qbvconf.admin.control_list);
3799 + pr_info("tsn: error get administrator data.");
3802 + nla_nest_end(rep_skb, qbvadminattr);
3804 + if (qbvconf.gate_enabled) {
3805 + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_ENABLE))
3808 + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_DISABLE))
3812 + if (qbvconf.maxsdu)
3813 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_MAXSDU, qbvconf.maxsdu))
3816 + if (qbvconf.config_change)
3817 + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_CONFIGCHANGE))
3820 + nla_nest_end(rep_skb, qbv);
3822 + tsn_send_reply(rep_skb, info);
3827 +static int cmd_qbv_status_get(struct genl_info *info)
3829 + struct nlattr *qbv, *qbvoperattr;
3830 + struct sk_buff *rep_skb;
3832 + int len = 0, i = 0;
3833 + struct net_device *netdev;
3834 + struct genlmsghdr *genlhdr;
3835 + struct tsn_qbv_status qbvstatus;
3836 + const struct tsn_ops *tsnops;
3837 + struct tsn_port *port;
3839 + port = tsn_init_check(info, &netdev);
3843 + tsnops = port->tsnops;
3845 + genlhdr = info->genlhdr;
3847 + memset(&qbvstatus, 0, sizeof(struct tsn_qbv_status));
3849 + if (!tsnops->qbv_get_status) {
3850 + tsn_simple_reply(info, TSN_CMD_REPLY,
3851 + netdev->name, -EPERM);
3855 + ret = tsnops->qbv_get_status(netdev, &qbvstatus);
3857 + tsn_simple_reply(info, TSN_CMD_REPLY,
3858 + netdev->name, ret);
3862 + ret = tsn_prepare_reply(info, genlhdr->cmd,
3863 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
3867 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
3870 + qbv = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBV);
3874 + qbvoperattr = nla_nest_start_noflag(rep_skb, TSN_QBV_ATTR_OPERENTRY);
3878 + if (qbvstatus.oper.control_list) {
3879 + len = qbvstatus.oper.control_list_length;
3880 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_LISTCOUNT, len)) {
3881 + nla_nest_cancel(rep_skb, qbvoperattr);
3885 + for (i = 0; i < len; i++) {
3886 + struct nlattr *qbv_table;
3889 + int glisttype = TSN_QBV_ATTR_CTRL_LISTENTRY;
3891 + gs = (qbvstatus.oper.control_list + i)->gate_state;
3892 + tp = (qbvstatus.oper.control_list + i)->time_interval;
3894 + qbv_table = nla_nest_start_noflag(rep_skb, glisttype);
3898 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_ID, i) ||
3899 + nla_put_u8(rep_skb, TSN_QBV_ATTR_ENTRY_GC, gs) ||
3900 + nla_put_u32(rep_skb, TSN_QBV_ATTR_ENTRY_TM, tp)) {
3901 + nla_nest_cancel(rep_skb, qbv_table);
3905 + nla_nest_end(rep_skb, qbv_table);
3908 + if (qbvstatus.oper.gate_states) {
3909 + if (nla_put_u8(rep_skb, TSN_QBV_ATTR_CTRL_GATESTATE,
3910 + qbvstatus.oper.gate_states))
3914 + if (qbvstatus.oper.cycle_time) {
3915 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIME,
3916 + qbvstatus.oper.cycle_time))
3920 + if (qbvstatus.oper.cycle_time_extension) {
3921 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIMEEXT,
3922 + qbvstatus.oper.cycle_time_extension))
3926 + if (qbvstatus.oper.base_time) {
3927 + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CTRL_BASETIME,
3928 + qbvstatus.oper.base_time))
3932 + kfree(qbvstatus.oper.control_list);
3934 + pr_info("tsn: error get operation list data.");
3937 + nla_nest_end(rep_skb, qbvoperattr);
3939 + if (qbvstatus.config_change_time) {
3940 + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CONFIGCHANGETIME,
3941 + qbvstatus.config_change_time))
3945 + if (qbvstatus.tick_granularity) {
3946 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_GRANULARITY,
3947 + qbvstatus.tick_granularity))
3951 + if (qbvstatus.current_time) {
3952 + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CURRENTTIME,
3953 + qbvstatus.current_time))
3957 + if (qbvstatus.config_pending) {
3958 + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_CONFIGPENDING))
3962 + if (qbvstatus.config_change_error) {
3963 + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CONFIGCHANGEERROR,
3964 + qbvstatus.config_change_error))
3968 + if (qbvstatus.supported_list_max) {
3969 + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_LISTMAX,
3970 + qbvstatus.supported_list_max))
3974 + nla_nest_end(rep_skb, qbv);
3976 + tsn_send_reply(rep_skb, info);
3981 +static int tsn_qbv_status_get(struct sk_buff *skb, struct genl_info *info)
3983 + if (info->attrs[TSN_ATTR_IFNAME])
3984 + cmd_qbv_status_get(info);
3989 +static int tsn_qbv_get(struct sk_buff *skb, struct genl_info *info)
3991 + if (info->attrs[TSN_ATTR_IFNAME])
3992 + cmd_qbv_get(info);
3997 +static int tsn_cbs_set(struct sk_buff *skb, struct genl_info *info)
3999 + struct nlattr *na;
4000 + struct nlattr *cbsa[TSN_CBS_ATTR_MAX + 1];
4001 + struct net_device *netdev;
4002 + const struct tsn_ops *tsnops;
4005 + struct tsn_port *port;
4007 + port = tsn_init_check(info, &netdev);
4011 + tsnops = port->tsnops;
4013 + if (!info->attrs[TSN_ATTR_CBS]) {
4014 + tsn_simple_reply(info, TSN_CMD_REPLY,
4015 + netdev->name, -EINVAL);
4019 + na = info->attrs[TSN_ATTR_CBS];
4021 + if (!tsnops->cbs_set) {
4022 + tsn_simple_reply(info, TSN_CMD_REPLY,
4023 + netdev->name, -EPERM);
4027 + ret = NLA_PARSE_NESTED(cbsa, TSN_CBS_ATTR_MAX, na, cbs_policy);
4029 + tsn_simple_reply(info, TSN_CMD_REPLY,
4030 + netdev->name, -EINVAL);
4034 + if (!cbsa[TSN_CBS_ATTR_TC_INDEX]) {
4035 + pr_err("tsn: no TSN_CBS_ATTR_TC_INDEX input\n");
4036 + tsn_simple_reply(info, TSN_CMD_REPLY,
4037 + netdev->name, -EINVAL);
4040 + tc = nla_get_u8(cbsa[TSN_CBS_ATTR_TC_INDEX]);
4042 + if (!cbsa[TSN_CBS_ATTR_BW]) {
4043 + pr_err("tsn: no TSN_CBS_ATTR_BW input\n");
4044 + tsn_simple_reply(info, TSN_CMD_REPLY,
4045 + netdev->name, -EINVAL);
4049 + bw = nla_get_u8(cbsa[TSN_CBS_ATTR_BW]);
4051 + pr_err("tsn: TSN_CBS_ATTR_BW isn't in the range of 0~100\n");
4052 + tsn_simple_reply(info, TSN_CMD_REPLY,
4053 + netdev->name, -EINVAL);
4057 + ret = tsnops->cbs_set(netdev, tc, bw);
4059 + tsn_simple_reply(info, TSN_CMD_REPLY,
4060 + netdev->name, ret);
4064 + tsn_simple_reply(info, TSN_CMD_REPLY,
4069 +static int tsn_cbs_get(struct sk_buff *skb, struct genl_info *info)
4071 + struct nlattr *na, *cbsattr;
4072 + struct nlattr *cbsa[TSN_CBS_ATTR_MAX + 1];
4073 + struct net_device *netdev;
4074 + const struct tsn_ops *tsnops;
4075 + struct sk_buff *rep_skb;
4077 + struct genlmsghdr *genlhdr;
4079 + struct tsn_port *port;
4081 + port = tsn_init_check(info, &netdev);
4085 + tsnops = port->tsnops;
4087 + if (!info->attrs[TSN_ATTR_CBS]) {
4088 + tsn_simple_reply(info, TSN_CMD_REPLY,
4089 + netdev->name, -EINVAL);
4093 + if (!tsnops->cbs_get) {
4094 + tsn_simple_reply(info, TSN_CMD_REPLY,
4095 + netdev->name, -EPERM);
4099 + na = info->attrs[TSN_ATTR_CBS];
4100 + ret = NLA_PARSE_NESTED(cbsa, TSN_CBS_ATTR_MAX, na, cbs_policy);
4102 + pr_err("tsn: parse value TSN_CBS_ATTR_MAX error.");
4103 + tsn_simple_reply(info, TSN_CMD_REPLY,
4104 + netdev->name, -EINVAL);
4108 + /* Get status data from device */
4109 + genlhdr = info->genlhdr;
4111 + /* Form netlink reply data */
4112 + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
4113 + NLMSG_ALIGN(MAX_ATTR_SIZE));
4117 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
4120 + cbsattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CBS);
4124 + if (!cbsa[TSN_CBS_ATTR_TC_INDEX]) {
4125 + pr_err("tsn: must to specify the TSN_CBS_ATTR_TC_INDEX\n");
4126 + tsn_simple_reply(info, TSN_CMD_REPLY,
4127 + netdev->name, -EINVAL);
4130 + tc = nla_get_u8(cbsa[TSN_CBS_ATTR_TC_INDEX]);
4132 + ret = tsnops->cbs_get(netdev, tc);
4134 + pr_err("tsn: cbs_get return error\n");
4135 + tsn_simple_reply(info, TSN_CMD_REPLY,
4136 + netdev->name, ret);
4140 + if (nla_put_u8(rep_skb, TSN_CBS_ATTR_BW, ret & 0XF))
4143 + nla_nest_end(rep_skb, cbsattr);
4144 + return tsn_send_reply(rep_skb, info);
4147 +static int cmd_qbu_set(struct genl_info *info)
4149 + struct nlattr *na;
4150 + struct nlattr *qbua[TSN_QBU_ATTR_MAX + 1];
4151 + struct net_device *netdev;
4152 + const struct tsn_ops *tsnops;
4154 + u8 preemptible = 0;
4155 + struct tsn_port *port;
4157 + port = tsn_init_check(info, &netdev);
4161 + tsnops = port->tsnops;
4163 + if (!info->attrs[TSN_ATTR_QBU]) {
4164 + tsn_simple_reply(info, TSN_CMD_REPLY,
4165 + netdev->name, -EINVAL);
4169 + na = info->attrs[TSN_ATTR_QBU];
4171 + ret = NLA_PARSE_NESTED(qbua, TSN_QBU_ATTR_MAX, na, qbu_policy);
4173 + tsn_simple_reply(info, TSN_CMD_REPLY,
4174 + netdev->name, -EINVAL);
4178 + if (qbua[TSN_QBU_ATTR_ADMIN_STATE])
4179 + preemptible = nla_get_u8(qbua[TSN_QBU_ATTR_ADMIN_STATE]);
4181 + pr_info("No preemptible TSN_QBU_ATTR_ADMIN_STATE config!\n");
4183 + if (!tsnops->qbu_set) {
4184 + tsn_simple_reply(info, TSN_CMD_REPLY,
4185 + netdev->name, -EPERM);
4189 + ret = tsnops->qbu_set(netdev, preemptible);
4191 + tsn_simple_reply(info, TSN_CMD_REPLY,
4192 + netdev->name, ret);
4196 + tsn_simple_reply(info, TSN_CMD_REPLY,
4201 +static int tsn_qbu_set(struct sk_buff *skb, struct genl_info *info)
4203 + if (info->attrs[TSN_ATTR_IFNAME])
4204 + return cmd_qbu_set(info);
4209 +static int cmd_qbu_get_status(struct genl_info *info)
4211 + struct nlattr *qbuattr;
4212 + struct net_device *netdev;
4213 + const struct tsn_ops *tsnops;
4214 + struct sk_buff *rep_skb;
4216 + struct genlmsghdr *genlhdr;
4217 + struct tsn_preempt_status pps;
4218 + struct tsn_port *port;
4220 + port = tsn_init_check(info, &netdev);
4224 + tsnops = port->tsnops;
4226 + /* Get status data from device */
4227 + genlhdr = info->genlhdr;
4229 + memset(&pps, 0, sizeof(struct tsn_preempt_status));
4231 + if (!tsnops->qbu_get) {
4232 + tsn_simple_reply(info, TSN_CMD_REPLY,
4233 + netdev->name, -EPERM);
4237 + ret = tsnops->qbu_get(netdev, &pps);
4239 + tsn_simple_reply(info, TSN_CMD_REPLY,
4240 + netdev->name, ret);
4244 + /* Form netlink reply data */
4245 + ret = tsn_prepare_reply(info, genlhdr->cmd,
4246 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
4250 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
4253 + qbuattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBU);
4257 + if (nla_put_u8(rep_skb, TSN_QBU_ATTR_ADMIN_STATE, pps.admin_state) ||
4258 + nla_put_u32(rep_skb,
4259 + TSN_QBU_ATTR_HOLD_ADVANCE, pps.hold_advance) ||
4260 + nla_put_u32(rep_skb,
4261 + TSN_QBU_ATTR_RELEASE_ADVANCE, pps.release_advance))
4264 + if (pps.preemption_active) {
4265 + if (nla_put_flag(rep_skb, TSN_QBU_ATTR_ACTIVE))
4269 + if (nla_put_u8(rep_skb, TSN_QBU_ATTR_HOLD_REQUEST, pps.hold_request))
4272 + nla_nest_end(rep_skb, qbuattr);
4274 + return tsn_send_reply(rep_skb, info);
4277 +static int tsn_qbu_get_status(struct sk_buff *skb, struct genl_info *info)
4279 + if (info->attrs[TSN_ATTR_IFNAME])
4280 + return cmd_qbu_get_status(info);
4285 +static int tsn_tsd_set(struct sk_buff *skb, struct genl_info *info)
4287 + struct nlattr *na;
4288 + struct nlattr *ntsd[TSN_TSD_ATTR_MAX + 1];
4289 + struct net_device *netdev;
4290 + const struct tsn_ops *tsnops;
4291 + struct tsn_tsd tsd;
4293 + struct tsn_port *port;
4295 + port = tsn_init_check(info, &netdev);
4299 + tsnops = port->tsnops;
4301 + memset(&tsd, 0, sizeof(struct tsn_tsd));
4303 + if (!info->attrs[TSN_ATTR_TSD]) {
4304 + tsn_simple_reply(info, TSN_CMD_REPLY,
4305 + netdev->name, -EINVAL);
4309 + na = info->attrs[TSN_ATTR_TSD];
4311 + ret = NLA_PARSE_NESTED(ntsd, TSN_TSD_ATTR_MAX, na, tsd_policy);
4313 + tsn_simple_reply(info, TSN_CMD_REPLY,
4314 + netdev->name, -EINVAL);
4318 + if (!tsnops->tsd_set) {
4319 + tsn_simple_reply(info, TSN_CMD_REPLY,
4320 + netdev->name, -EPERM);
4324 + if (nla_get_flag(ntsd[TSN_TSD_ATTR_DISABLE])) {
4325 + tsd.enable = false;
4327 + if (ntsd[TSN_TSD_ATTR_PERIOD])
4328 + tsd.period = nla_get_u32(ntsd[TSN_TSD_ATTR_PERIOD]);
4330 + if (!tsd.period) {
4331 + tsn_simple_reply(info, TSN_CMD_REPLY,
4332 + netdev->name, -EINVAL);
4336 + if (ntsd[TSN_TSD_ATTR_MAX_FRM_NUM])
4338 + nla_get_u32(ntsd[TSN_TSD_ATTR_MAX_FRM_NUM]);
4340 + if (ntsd[TSN_TSD_ATTR_SYN_IMME])
4345 + tsd.enable = true;
4348 + ret = tsnops->tsd_set(netdev, &tsd);
4350 + tsn_simple_reply(info, TSN_CMD_REPLY,
4351 + netdev->name, ret);
4355 + tsn_simple_reply(info, TSN_CMD_REPLY,
4360 +static int tsn_tsd_get(struct sk_buff *skb, struct genl_info *info)
4362 + struct nlattr *na, *tsdattr;
4363 + struct nlattr *tsda[TSN_TSD_ATTR_MAX + 1];
4364 + struct net_device *netdev;
4365 + const struct tsn_ops *tsnops;
4366 + struct sk_buff *rep_skb;
4368 + struct genlmsghdr *genlhdr;
4369 + struct tsn_tsd_status tts;
4370 + struct tsn_port *port;
4372 + port = tsn_init_check(info, &netdev);
4376 + tsnops = port->tsnops;
4378 + if (!info->attrs[TSN_ATTR_TSD]) {
4379 + tsn_simple_reply(info, TSN_CMD_REPLY,
4380 + netdev->name, -EINVAL);
4384 + if (!tsnops->tsd_get) {
4385 + tsn_simple_reply(info, TSN_CMD_REPLY,
4386 + netdev->name, -EPERM);
4390 + ret = tsnops->tsd_get(netdev, &tts);
4392 + tsn_simple_reply(info, TSN_CMD_REPLY,
4393 + netdev->name, ret);
4397 + na = info->attrs[TSN_ATTR_TSD];
4399 + ret = NLA_PARSE_NESTED(tsda, TSN_TSD_ATTR_MAX,
4402 + pr_err("tsn: parse value TSN_TSD_ATTR_MAX error.");
4403 + tsn_simple_reply(info, TSN_CMD_REPLY,
4404 + netdev->name, -EINVAL);
4408 + /* Get status data from device */
4409 + genlhdr = info->genlhdr;
4411 + /* Form netlink reply data */
4412 + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb,
4413 + NLMSG_ALIGN(MAX_ATTR_SIZE));
4417 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
4420 + tsdattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_TSD);
4424 + if (nla_put_u32(rep_skb, TSN_TSD_ATTR_PERIOD, tts.period) ||
4425 + nla_put_u32(rep_skb, TSN_TSD_ATTR_MAX_FRM_NUM, tts.maxFrameNum) ||
4426 + nla_put_u32(rep_skb, TSN_TSD_ATTR_CYCLE_NUM, tts.cycleNum) ||
4427 + nla_put_u32(rep_skb, TSN_TSD_ATTR_LOSS_STEPS, tts.loss_steps) ||
4428 + nla_put_u32(rep_skb, TSN_TSD_ATTR_MAX_FRM_NUM, tts.maxFrameNum))
4431 + if (!tts.enable) {
4432 + if (nla_put_flag(rep_skb, TSN_TSD_ATTR_DISABLE))
4435 + if (nla_put_flag(rep_skb, TSN_TSD_ATTR_ENABLE))
4439 + if (tts.flag == 2)
4440 + if (nla_put_flag(rep_skb, TSN_TSD_ATTR_SYN_IMME))
4443 + nla_nest_end(rep_skb, tsdattr);
4444 + return tsn_send_reply(rep_skb, info);
4447 +static int tsn_ct_set(struct sk_buff *skb, struct genl_info *info)
4449 + struct nlattr *na;
4450 + struct nlattr *cta[TSN_CT_ATTR_MAX + 1];
4451 + struct net_device *netdev;
4452 + const struct tsn_ops *tsnops;
4455 + struct tsn_port *port;
4457 + port = tsn_init_check(info, &netdev);
4461 + tsnops = port->tsnops;
4463 + if (!info->attrs[TSN_ATTR_CT]) {
4464 + tsn_simple_reply(info, TSN_CMD_REPLY,
4465 + netdev->name, -EINVAL);
4469 + na = info->attrs[TSN_ATTR_CT];
4471 + if (!tsnops->ct_set) {
4472 + tsn_simple_reply(info, TSN_CMD_REPLY,
4473 + netdev->name, -EPERM);
4477 + ret = NLA_PARSE_NESTED(cta, TSN_CT_ATTR_MAX,
4480 + tsn_simple_reply(info, TSN_CMD_REPLY,
4481 + netdev->name, -EINVAL);
4485 + queue_stat = nla_get_u8(cta[TSN_CT_ATTR_QUEUE_STATE]);
4487 + ret = tsnops->ct_set(netdev, queue_stat);
4489 + tsn_simple_reply(info, TSN_CMD_REPLY,
4490 + netdev->name, ret);
4494 + tsn_simple_reply(info, TSN_CMD_REPLY,
4499 +static int tsn_cbgen_set(struct sk_buff *skb, struct genl_info *info)
4501 + struct nlattr *na;
4502 + struct nlattr *cbgena[TSN_CBGEN_ATTR_MAX + 1];
4503 + struct net_device *netdev;
4504 + const struct tsn_ops *tsnops;
4507 + struct tsn_seq_gen_conf sg_conf;
4508 + struct tsn_port *port;
4510 + port = tsn_init_check(info, &netdev);
4514 + tsnops = port->tsnops;
4516 + if (!info->attrs[TSN_ATTR_CBGEN]) {
4517 + tsn_simple_reply(info, TSN_CMD_REPLY,
4518 + netdev->name, -EINVAL);
4522 + na = info->attrs[TSN_ATTR_CBGEN];
4524 + if (!tsnops->cbgen_set) {
4525 + tsn_simple_reply(info, TSN_CMD_REPLY,
4526 + netdev->name, -EPERM);
4530 + ret = NLA_PARSE_NESTED(cbgena, TSN_CBGEN_ATTR_MAX,
4531 + na, cbgen_policy);
4533 + tsn_simple_reply(info, TSN_CMD_REPLY,
4534 + netdev->name, -EINVAL);
4538 + index = nla_get_u32(cbgena[TSN_CBGEN_ATTR_INDEX]);
4540 + memset(&sg_conf, 0, sizeof(struct tsn_seq_gen_conf));
4541 + sg_conf.iport_mask = nla_get_u8(cbgena[TSN_CBGEN_ATTR_PORT_MASK]);
4542 + sg_conf.split_mask = nla_get_u8(cbgena[TSN_CBGEN_ATTR_SPLIT_MASK]);
4543 + sg_conf.seq_len = nla_get_u8(cbgena[TSN_CBGEN_ATTR_SEQ_LEN]);
4544 + sg_conf.seq_num = nla_get_u32(cbgena[TSN_CBGEN_ATTR_SEQ_NUM]);
4546 + ret = tsnops->cbgen_set(netdev, index, &sg_conf);
4548 + tsn_simple_reply(info, TSN_CMD_REPLY,
4549 + netdev->name, ret);
4553 + tsn_simple_reply(info, TSN_CMD_REPLY,
4558 +static int tsn_cbrec_set(struct sk_buff *skb, struct genl_info *info)
4560 + struct nlattr *na;
4561 + struct nlattr *cbreca[TSN_CBREC_ATTR_MAX + 1];
4562 + struct net_device *netdev;
4563 + const struct tsn_ops *tsnops;
4566 + struct tsn_seq_rec_conf sr_conf;
4567 + struct tsn_port *port;
4569 + port = tsn_init_check(info, &netdev);
4573 + tsnops = port->tsnops;
4575 + if (!info->attrs[TSN_ATTR_CBREC]) {
4576 + tsn_simple_reply(info, TSN_CMD_REPLY,
4577 + netdev->name, -EINVAL);
4581 + na = info->attrs[TSN_ATTR_CBREC];
4583 + if (!tsnops->cbrec_set) {
4584 + tsn_simple_reply(info, TSN_CMD_REPLY,
4585 + netdev->name, -EPERM);
4589 + ret = NLA_PARSE_NESTED(cbreca, TSN_CBREC_ATTR_MAX,
4590 + na, cbrec_policy);
4592 + tsn_simple_reply(info, TSN_CMD_REPLY,
4593 + netdev->name, -EINVAL);
4597 + index = nla_get_u32(cbreca[TSN_CBREC_ATTR_INDEX]);
4599 + memset(&sr_conf, 0, sizeof(struct tsn_seq_rec_conf));
4600 + sr_conf.seq_len = nla_get_u8(cbreca[TSN_CBREC_ATTR_SEQ_LEN]);
4601 + sr_conf.his_len = nla_get_u8(cbreca[TSN_CBREC_ATTR_HIS_LEN]);
4602 + sr_conf.rtag_pop_en = nla_get_flag(cbreca[TSN_CBREC_ATTR_TAG_POP_EN]);
4604 + ret = tsnops->cbrec_set(netdev, index, &sr_conf);
4606 + tsn_simple_reply(info, TSN_CMD_REPLY,
4607 + netdev->name, ret);
4611 + tsn_simple_reply(info, TSN_CMD_REPLY,
4616 +static int tsn_cbstatus_get(struct sk_buff *skb, struct genl_info *info)
4618 + struct nlattr *na;
4619 + struct nlattr *cba[TSN_CBSTAT_ATTR_MAX + 1];
4620 + struct nlattr *cbattr;
4621 + struct net_device *netdev;
4622 + const struct tsn_ops *tsnops;
4623 + struct sk_buff *rep_skb;
4625 + unsigned int index;
4626 + struct genlmsghdr *genlhdr;
4627 + struct tsn_cb_status cbstat;
4628 + struct tsn_port *port;
4630 + port = tsn_init_check(info, &netdev);
4634 + tsnops = port->tsnops;
4636 + /* Get status data from device */
4637 + genlhdr = info->genlhdr;
4639 + memset(&cbstat, 0, sizeof(struct tsn_cb_status));
4641 + if (!tsnops->cb_get) {
4642 + tsn_simple_reply(info, TSN_CMD_REPLY,
4643 + netdev->name, -EPERM);
4647 + na = info->attrs[TSN_ATTR_CBSTAT];
4648 + ret = NLA_PARSE_NESTED(cba, TSN_CBSTAT_ATTR_MAX,
4649 + na, cbstat_policy);
4651 + tsn_simple_reply(info, TSN_CMD_REPLY,
4652 + netdev->name, -EINVAL);
4656 + index = nla_get_u32(cba[TSN_CBSTAT_ATTR_INDEX]);
4658 + ret = tsnops->cb_get(netdev, index, &cbstat);
4660 + tsn_simple_reply(info, TSN_CMD_REPLY,
4661 + netdev->name, ret);
4665 + /* Form netlink reply data */
4666 + ret = tsn_prepare_reply(info, genlhdr->cmd,
4667 + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE));
4671 + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name))
4674 + cbattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CBSTAT);
4678 + if (nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_GEN_REC, cbstat.gen_rec) ||
4679 + nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_ERR, cbstat.err) ||
4680 + nla_put_u32(rep_skb, TSN_CBSTAT_ATTR_SEQ_NUM,
4681 + cbstat.seq_num) ||
4682 + nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_SEQ_LEN, cbstat.seq_len) ||
4683 + nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_SPLIT_MASK,
4684 + cbstat.split_mask) ||
4685 + nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_PORT_MASK,
4686 + cbstat.iport_mask) ||
4687 + nla_put_u8(rep_skb, TSN_CBSTAT_ATTR_HIS_LEN, cbstat.his_len) ||
4688 + nla_put_u32(rep_skb, TSN_CBSTAT_ATTR_SEQ_HIS,
4692 + nla_nest_end(rep_skb, cbattr);
4694 + return tsn_send_reply(rep_skb, info);
4697 +static int tsn_dscp_set(struct sk_buff *skb, struct genl_info *info)
4699 + struct nlattr *na;
4700 + struct nlattr *dscpa[TSN_DSCP_ATTR_MAX + 1];
4701 + struct net_device *netdev;
4702 + const struct tsn_ops *tsnops;
4705 + struct tsn_port *port;
4707 + struct tsn_qos_switch_dscp_conf dscp_conf;
4709 + port = tsn_init_check(info, &netdev);
4713 + tsnops = port->tsnops;
4715 + if (!info->attrs[TSN_ATTR_DSCP]) {
4716 + tsn_simple_reply(info, TSN_CMD_REPLY,
4717 + netdev->name, -EINVAL);
4721 + na = info->attrs[TSN_ATTR_DSCP];
4723 + if (!tsnops->dscp_set) {
4724 + tsn_simple_reply(info, TSN_CMD_REPLY,
4725 + netdev->name, -EPERM);
4729 + ret = NLA_PARSE_NESTED(dscpa, TSN_DSCP_ATTR_MAX,
4732 + tsn_simple_reply(info, TSN_CMD_REPLY,
4733 + netdev->name, -EINVAL);
4738 + if (dscpa[TSN_DSCP_ATTR_DISABLE])
4740 + dscp_ix = nla_get_u32(dscpa[TSN_DSCP_ATTR_INDEX]);
4741 + dscp_conf.cos = nla_get_u32(dscpa[TSN_DSCP_ATTR_COS]);
4742 + dscp_conf.dpl = nla_get_u32(dscpa[TSN_DSCP_ATTR_DPL]);
4743 + ret = tsnops->dscp_set(netdev, enable, dscp_ix, &dscp_conf);
4745 + tsn_simple_reply(info, TSN_CMD_REPLY,
4746 + netdev->name, ret);
4750 + tsn_simple_reply(info, TSN_CMD_REPLY,
4756 +static const struct genl_ops tsnnl_ops[] = {
4758 + .cmd = TSN_CMD_ECHO,
4759 + .doit = tsn_echo_cmd,
4760 + .flags = GENL_ADMIN_PERM,
4763 + .cmd = TSN_CMD_CAP_GET,
4764 + .doit = tsn_cap_get,
4765 + .flags = GENL_ADMIN_PERM,
4768 + .cmd = TSN_CMD_QBV_SET,
4769 + .doit = tsn_qbv_set,
4770 + .flags = GENL_ADMIN_PERM,
4773 + .cmd = TSN_CMD_QBV_GET,
4774 + .doit = tsn_qbv_get,
4775 + .flags = GENL_ADMIN_PERM,
4778 + .cmd = TSN_CMD_QBV_GET_STATUS,
4779 + .doit = tsn_qbv_status_get,
4780 + .flags = GENL_ADMIN_PERM,
4783 + .cmd = TSN_CMD_CB_STREAMID_SET,
4784 + .doit = tsn_cb_streamid_set,
4785 + .flags = GENL_ADMIN_PERM,
4788 + .cmd = TSN_CMD_CB_STREAMID_GET,
4789 + .doit = tsn_cb_streamid_get,
4790 + .flags = GENL_ADMIN_PERM,
4793 + .cmd = TSN_CMD_CB_STREAMID_GET_COUNTS,
4794 + .doit = tsn_cb_streamid_counters_get,
4795 + .flags = GENL_ADMIN_PERM,
4798 + .cmd = TSN_CMD_QCI_CAP_GET,
4799 + .doit = tsn_qci_cap_get,
4800 + .flags = GENL_ADMIN_PERM,
4803 + .cmd = TSN_CMD_QCI_SFI_SET,
4804 + .doit = tsn_qci_sfi_set,
4805 + .flags = GENL_ADMIN_PERM,
4808 + .cmd = TSN_CMD_QCI_SFI_GET,
4809 + .doit = tsn_qci_sfi_get,
4810 + .flags = GENL_ADMIN_PERM,
4813 + .cmd = TSN_CMD_QCI_SFI_GET_COUNTS,
4814 + .doit = tsn_qci_sfi_counters_get,
4815 + .flags = GENL_ADMIN_PERM,
4818 + .cmd = TSN_CMD_QCI_SGI_SET,
4819 + .doit = tsn_qci_sgi_set,
4820 + .flags = GENL_ADMIN_PERM,
4823 + .cmd = TSN_CMD_QCI_SGI_GET,
4824 + .doit = tsn_qci_sgi_get,
4825 + .flags = GENL_ADMIN_PERM,
4828 + .cmd = TSN_CMD_QCI_SGI_GET_STATUS,
4829 + .doit = tsn_qci_sgi_status_get,
4830 + .flags = GENL_ADMIN_PERM,
4833 + .cmd = TSN_CMD_QCI_FMI_SET,
4834 + .doit = tsn_qci_fmi_set,
4835 + .flags = GENL_ADMIN_PERM,
4838 + .cmd = TSN_CMD_QCI_FMI_GET,
4839 + .doit = tsn_qci_fmi_get,
4840 + .flags = GENL_ADMIN_PERM,
4843 + .cmd = TSN_CMD_CBS_SET,
4844 + .doit = tsn_cbs_set,
4845 + .flags = GENL_ADMIN_PERM,
4848 + .cmd = TSN_CMD_CBS_GET,
4849 + .doit = tsn_cbs_get,
4850 + .flags = GENL_ADMIN_PERM,
4853 + .cmd = TSN_CMD_QBU_SET,
4854 + .doit = tsn_qbu_set,
4855 + .flags = GENL_ADMIN_PERM,
4858 + .cmd = TSN_CMD_QBU_GET_STATUS,
4859 + .doit = tsn_qbu_get_status,
4860 + .flags = GENL_ADMIN_PERM,
4863 + .cmd = TSN_CMD_TSD_SET,
4864 + .doit = tsn_tsd_set,
4865 + .flags = GENL_ADMIN_PERM,
4868 + .cmd = TSN_CMD_TSD_GET,
4869 + .doit = tsn_tsd_get,
4870 + .flags = GENL_ADMIN_PERM,
4873 + .cmd = TSN_CMD_CT_SET,
4874 + .doit = tsn_ct_set,
4875 + .flags = GENL_ADMIN_PERM,
4878 + .cmd = TSN_CMD_CBGEN_SET,
4879 + .doit = tsn_cbgen_set,
4880 + .flags = GENL_ADMIN_PERM,
4883 + .cmd = TSN_CMD_CBREC_SET,
4884 + .doit = tsn_cbrec_set,
4885 + .flags = GENL_ADMIN_PERM,
4888 + .cmd = TSN_CMD_CBSTAT_GET,
4889 + .doit = tsn_cbstatus_get,
4890 + .flags = GENL_ADMIN_PERM,
4893 + .cmd = TSN_CMD_DSCP_SET,
4894 + .doit = tsn_dscp_set,
4895 + .flags = GENL_ADMIN_PERM,
4899 +static const struct genl_multicast_group tsn_mcgrps[] = {
4900 + [TSN_MCGRP_QBV] = { .name = TSN_MULTICAST_GROUP_QBV},
4901 + [TSN_MCGRP_QCI] = { .name = TSN_MULTICAST_GROUP_QCI},
4904 +static struct genl_family tsn_family = {
4905 + .name = TSN_GENL_NAME,
4906 + .version = TSN_GENL_VERSION,
4907 + .maxattr = TSN_CMD_ATTR_MAX,
4908 + .module = THIS_MODULE,
4911 + .n_ops = ARRAY_SIZE(tsnnl_ops),
4912 + .mcgrps = tsn_mcgrps,
4913 + .n_mcgrps = ARRAY_SIZE(tsn_mcgrps),
4916 +int tsn_port_register(struct net_device *netdev,
4917 + struct tsn_ops *tsnops, u16 groupid)
4919 + struct tsn_port *port;
4921 + if (list_empty(&port_list)) {
4922 + INIT_LIST_HEAD(&port_list);
4924 + list_for_each_entry(port, &port_list, list) {
4925 + if (port->netdev == netdev) {
4926 + pr_info("TSN device already registered!\n");
4932 + port = kzalloc(sizeof(*port), GFP_KERNEL);
4936 + port->netdev = netdev;
4937 + port->groupid = groupid;
4938 + port->tsnops = tsnops;
4939 + port->nd.dev = netdev;
4941 + if (groupid < GROUP_OFFSET_SWITCH)
4942 + port->type = TSN_ENDPOINT;
4944 + port->type = TSN_SWITCH;
4946 + list_add_tail(&port->list, &port_list);
4948 + if (tsnops && tsnops->device_init)
4949 + port->tsnops->device_init(netdev);
4953 +EXPORT_SYMBOL(tsn_port_register);
4955 +void tsn_port_unregister(struct net_device *netdev)
4957 + struct tsn_port *p;
4959 + list_for_each_entry(p, &port_list, list) {
4960 + if (!p || !p->netdev)
4962 + if (p->netdev == netdev) {
4963 + if (p->tsnops->device_deinit)
4964 + p->tsnops->device_deinit(netdev);
4965 + list_del(&p->list);
4971 +EXPORT_SYMBOL(tsn_port_unregister);
4973 +static int tsn_multicast_to_user(unsigned long event,
4974 + struct tsn_notifier_info *tsn_info)
4976 + struct sk_buff *skb;
4977 + struct genlmsghdr *nlh;
4979 + struct tsn_qbv_conf *qbvdata;
4981 + /* If new attributes are added, please revisit this allocation */
4982 + skb = genlmsg_new(sizeof(*tsn_info), GFP_KERNEL);
4984 + pr_err("Allocation failure.\n");
4989 + case TSN_QBV_CONFIGCHANGETIME_ARRIVE:
4990 + nlh = genlmsg_put(skb, 0, 1, &tsn_family,
4991 + GFP_KERNEL, TSN_CMD_QBV_SET);
4992 + qbvdata = &tsn_info->ntdata.qbv_notify;
4993 + res = NLA_PUT_U64(skb, TSN_QBV_ATTR_CTRL_BASETIME,
4994 + qbvdata->admin.base_time);
4997 + pr_err("put data failure!\n");
5001 + res = nla_put_u32(skb, TSN_QBV_ATTR_CTRL_CYCLETIME,
5002 + qbvdata->admin.cycle_time);
5004 + pr_err("put data failure!\n");
5008 + if (qbvdata->gate_enabled)
5009 + res = nla_put_flag(skb, TSN_QBV_ATTR_ENABLE +
5010 + TSN_QBV_ATTR_CTRL_MAX);
5012 + res = nla_put_flag(skb, TSN_QBV_ATTR_DISABLE +
5013 + TSN_QBV_ATTR_CTRL_MAX);
5015 + pr_err("put data failure!\n");
5019 + res = nla_put_u32(skb, TSN_QBV_ATTR_CTRL_UNSPEC,
5020 + tsn_info->dev->ifindex);
5022 + pr_err("put data failure!\n");
5028 + pr_info("event not supportted!\n");
5032 + (void)genlmsg_end(skb, nlh);
5034 + res = genlmsg_multicast_allns(&tsn_family, skb, 0,
5035 + TSN_MCGRP_QBV, GFP_KERNEL);
5037 + if (res && res != -ESRCH) {
5038 + pr_err("genlmsg_multicast_allns error: %d\n", res);
5042 + if (res == -ESRCH)
5054 +/* called with RTNL or RCU */
5055 +static int tsn_event(struct notifier_block *unused,
5056 + unsigned long event, void *ptr)
5058 + struct tsn_notifier_info *tsn_info;
5059 + int err = NOTIFY_DONE;
5062 + case TSN_QBV_CONFIGCHANGETIME_ARRIVE:
5064 + err = tsn_multicast_to_user(event, tsn_info);
5066 + err = notifier_from_errno(err);
5071 + pr_info("event not supportted!\n");
5078 +static struct notifier_block tsn_notifier = {
5079 + .notifier_call = tsn_event,
5082 +static int __init tsn_genetlink_init(void)
5086 + pr_info("tsn generic netlink module v%d init...\n", TSN_GENL_VERSION);
5088 + ret = genl_register_family(&tsn_family);
5091 + pr_info("failed to init tsn generic netlink example module\n");
5095 + register_tsn_notifier(&tsn_notifier);
5100 +static void __exit tsn_genetlink_exit(void)
5104 + ret = genl_unregister_family(&tsn_family);
5106 + pr_info("failed to unregister family:%i\n", ret);
5108 + unregister_tsn_notifier(&tsn_notifier);
5111 +module_init(tsn_genetlink_init);
5112 +module_exit(tsn_genetlink_exit);
5113 +MODULE_LICENSE("GPL");