b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 |
| 6 | |
| 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. |
| 10 | |
| 11 | The three basic components of TSN are: |
| 12 | |
| 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 |
| 15 | in kernel. |
| 16 | 8021AS not included in this patch. |
| 17 | |
| 18 | 2. Scheduling and traffic shaping and per-stream filter policing: |
| 19 | This patch support Qbv/Qci/Qbu/8021CB/Qav etc. |
| 20 | |
| 21 | 3. Selection of communication paths: |
| 22 | This patch not support the pure software only TSN protocols(like Qcc) |
| 23 | but hardware related configuration. |
| 24 | |
| 25 | TSN Protocols supports by this patch: Qbv/Qci/Qbu/Credit-base Shaper(Qav). |
| 26 | This patch verified on NXP ls1028ardb board. |
| 27 | |
| 28 | Signed-off-by: Po Liu <Po.Liu@nxp.com> |
| 29 | --- |
| 30 | include/net/tsn.h | 114 ++ |
| 31 | include/uapi/linux/tsn.h | 1207 +++++++++++++++ |
| 32 | net/Kconfig | 1 + |
| 33 | net/Makefile | 3 + |
| 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 |
| 43 | |
| 44 | --- /dev/null |
| 45 | +++ b/include/net/tsn.h |
| 46 | @@ -0,0 +1,114 @@ |
| 47 | +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ |
| 48 | +/* Copyright 2017-2019 NXP */ |
| 49 | + |
| 50 | +#ifndef __TSN_H__ |
| 51 | +#define __TSN_H__ |
| 52 | + |
| 53 | +#include <linux/notifier.h> |
| 54 | +#include <uapi/linux/tsn.h> |
| 55 | + |
| 56 | +enum tsn_notifier_type { |
| 57 | + TSN_QBV_CONFIGCHANGETIME_ARRIVE = 1, |
| 58 | +}; |
| 59 | + |
| 60 | +struct tsn_notifier_info { |
| 61 | + struct net_device *dev; |
| 62 | + union { |
| 63 | + struct tsn_qbv_conf qbv_notify; |
| 64 | + struct tsn_qci_psfp_sgi_conf qci_notify; |
| 65 | + } ntdata; |
| 66 | +}; |
| 67 | + |
| 68 | +static inline struct net_device * |
| 69 | +tsn_notifier_info_to_dev(const struct tsn_notifier_info *info) |
| 70 | +{ |
| 71 | + return info->dev; |
| 72 | +} |
| 73 | + |
| 74 | +struct tsn_ops { |
| 75 | + void (*device_init)(struct net_device *ndev); |
| 76 | + void (*device_deinit)(struct net_device *ndev); |
| 77 | + u32 (*get_capability)(struct net_device *ndev); |
| 78 | + /* Qbv standard */ |
| 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 |
| 95 | + * -1 error happened |
| 96 | + */ |
| 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) |
| 116 | + */ |
| 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, |
| 131 | + const u8 dscp_ix, |
| 132 | + struct tsn_qos_switch_dscp_conf *c); |
| 133 | +}; |
| 134 | + |
| 135 | +enum ethdev_type { |
| 136 | + TSN_SWITCH, |
| 137 | + TSN_ENDPOINT, |
| 138 | +}; |
| 139 | + |
| 140 | +#define GROUP_OFFSET_SWITCH 256 |
| 141 | + |
| 142 | +struct tsn_port { |
| 143 | + u16 groupid; |
| 144 | + struct tsn_ops *tsnops; |
| 145 | + struct net_device *netdev; |
| 146 | + struct list_head list; |
| 147 | + enum ethdev_type type; |
| 148 | + u8 tc_nums; |
| 149 | + struct tsn_notifier_info nd; |
| 150 | +}; |
| 151 | + |
| 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); |
| 160 | +#endif |
| 161 | --- /dev/null |
| 162 | +++ b/include/uapi/linux/tsn.h |
| 163 | @@ -0,0 +1,1207 @@ |
| 164 | +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ |
| 165 | +/* Copyright 2017-2019 NXP */ |
| 166 | + |
| 167 | +#ifndef __UAPI_GENL_TSN_H |
| 168 | +#define __UAPI_GENL_TSN_H |
| 169 | + |
| 170 | +#define TSN_GENL_NAME "TSN_GEN_CTRL" |
| 171 | +#define TSN_GENL_VERSION 0x1 |
| 172 | + |
| 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 |
| 179 | + |
| 180 | +#define TSN_MULTICAST_GROUP_QBV "qbv" |
| 181 | +#define TSN_MULTICAST_GROUP_QCI "qci" |
| 182 | + |
| 183 | +/* multicast groups */ |
| 184 | +enum tsn_multicast_groups { |
| 185 | + TSN_MCGRP_QBV, |
| 186 | + TSN_MCGRP_QCI, |
| 187 | + TSN_MCGRP_MAX |
| 188 | +}; |
| 189 | + |
| 190 | +enum tsn_capability { |
| 191 | + TSN_CAP_QBV = 0x1, |
| 192 | + TSN_CAP_QCI = 0x2, |
| 193 | + TSN_CAP_QBU = 0x4, |
| 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 */ |
| 198 | +}; |
| 199 | + |
| 200 | +/* |
| 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 |
| 204 | + */ |
| 205 | + |
| 206 | +enum { |
| 207 | + TSN_CMD_UNSPEC = 0, /* Reserved */ |
| 208 | + TSN_CMD_QBV_SET, |
| 209 | + TSN_CMD_QBV_GET, |
| 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, |
| 223 | + TSN_CMD_CBS_SET, |
| 224 | + TSN_CMD_CBS_GET, |
| 225 | + TSN_CMD_QBU_SET, |
| 226 | + TSN_CMD_QBU_GET_STATUS, |
| 227 | + TSN_CMD_QAV_SET_CBS, |
| 228 | + TSN_CMD_QAV_GET_CBS, |
| 229 | + TSN_CMD_TSD_SET, |
| 230 | + TSN_CMD_TSD_GET, |
| 231 | + TSN_CMD_CT_SET, |
| 232 | + TSN_CMD_CBGEN_SET, |
| 233 | + TSN_CMD_CBREC_SET, |
| 234 | + TSN_CMD_CBSTAT_GET, |
| 235 | + TSN_CMD_PCPMAP_SET_UNUSE, |
| 236 | + TSN_CMD_DSCP_SET, |
| 237 | + TSN_CMD_ECHO, /* user->kernel request/get-response */ |
| 238 | + TSN_CMD_REPLY, /* kernel->user event */ |
| 239 | + TSN_CMD_CAP_GET, |
| 240 | + __TSN_CMD_MAX, |
| 241 | +}; |
| 242 | +#define TSN_CMD_MAX (__TSN_CMD_MAX - 1) |
| 243 | + |
| 244 | + |
| 245 | +enum { |
| 246 | + TSN_CMD_ATTR_UNSPEC = 0, |
| 247 | + TSN_CMD_ATTR_MESG, /* demo message */ |
| 248 | + TSN_CMD_ATTR_DATA, /* demo data */ |
| 249 | + TSN_ATTR_IFNAME, |
| 250 | + TSN_ATTR_PORT_NUMBER, |
| 251 | + TSN_ATTR_QBV, |
| 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, |
| 265 | + TSN_ATTR_DSCP, |
| 266 | + TSN_ATTR_CAP, /* TSN capbility */ |
| 267 | + __TSN_CMD_ATTR_MAX, |
| 268 | +}; |
| 269 | +#define TSN_CMD_ATTR_MAX (__TSN_CMD_ATTR_MAX - 1) |
| 270 | + |
| 271 | +enum { |
| 272 | + TSN_CAP_ATTR_UNSPEC, |
| 273 | + TSN_CAP_ATTR_QBV, |
| 274 | + TSN_CAP_ATTR_QCI, |
| 275 | + TSN_CAP_ATTR_QBU, |
| 276 | + TSN_CAP_ATTR_CBS, |
| 277 | + TSN_CAP_ATTR_CB, |
| 278 | + TSN_CAP_ATTR_TBS, |
| 279 | + TSN_CAP_ATTR_CTH, |
| 280 | + __TSN_CAP_ATTR_MAX, |
| 281 | + TSN_CAP_ATTR_MAX = __TSN_CAP_ATTR_MAX - 1, |
| 282 | +}; |
| 283 | + |
| 284 | +enum { |
| 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, |
| 293 | +}; |
| 294 | + |
| 295 | +enum { |
| 296 | + TSN_CBS_ATTR_UNSPEC, |
| 297 | + TSN_CBS_ATTR_TC_INDEX, |
| 298 | + TSN_CBS_ATTR_BW, |
| 299 | + __TSN_CBS_ATTR_MAX, |
| 300 | + TSN_CBS_ATTR_MAX = __TSN_CBS_ATTR_MAX - 1, |
| 301 | +}; |
| 302 | + |
| 303 | +enum { |
| 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, |
| 314 | +}; |
| 315 | + |
| 316 | +enum { |
| 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, |
| 339 | +}; |
| 340 | + |
| 341 | +enum { |
| 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, |
| 349 | +}; |
| 350 | + |
| 351 | +enum { |
| 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, |
| 367 | +}; |
| 368 | + |
| 369 | +enum { |
| 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, |
| 379 | +}; |
| 380 | + |
| 381 | +enum { |
| 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, |
| 400 | +}; |
| 401 | + |
| 402 | +enum { |
| 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, |
| 413 | +}; |
| 414 | + |
| 415 | +enum { |
| 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, |
| 423 | +}; |
| 424 | + |
| 425 | +enum { |
| 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, |
| 442 | +}; |
| 443 | + |
| 444 | +enum { |
| 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, |
| 460 | +}; |
| 461 | + |
| 462 | +enum { |
| 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, |
| 472 | +}; |
| 473 | + |
| 474 | +enum { |
| 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, |
| 481 | +}; |
| 482 | + |
| 483 | +enum { |
| 484 | + TSN_CT_ATTR_UNSPEC, |
| 485 | + TSN_CT_ATTR_QUEUE_STATE, |
| 486 | + __TSN_CT_ATTR_MAX, |
| 487 | + TSN_CT_ATTR_MAX = __TSN_CT_ATTR_MAX - 1, |
| 488 | +}; |
| 489 | + |
| 490 | +enum { |
| 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, |
| 499 | +}; |
| 500 | + |
| 501 | +enum { |
| 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, |
| 509 | +}; |
| 510 | + |
| 511 | +enum { |
| 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, |
| 524 | +}; |
| 525 | + |
| 526 | +enum { |
| 527 | + TSN_DSCP_ATTR_UNSPEC, |
| 528 | + TSN_DSCP_ATTR_DISABLE, |
| 529 | + TSN_DSCP_ATTR_INDEX, |
| 530 | + TSN_DSCP_ATTR_COS, |
| 531 | + TSN_DSCP_ATTR_DPL, |
| 532 | + __TSN_DSCP_ATTR_MAX, |
| 533 | + TSN_DSCP_ATTR_MAX = __TSN_DSCP_ATTR_MAX - 1, |
| 534 | +}; |
| 535 | + |
| 536 | +#define ptptime_t __u64 |
| 537 | + |
| 538 | +#define MAX_QUEUE_CNT 8 |
| 539 | + |
| 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). |
| 546 | + */ |
| 547 | + __u8 admin_state; |
| 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. |
| 552 | + */ |
| 553 | + __u32 hold_advance; |
| 554 | + |
| 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. |
| 559 | + */ |
| 560 | + __u32 release_advance; |
| 561 | + |
| 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. |
| 565 | + */ |
| 566 | + __u8 preemption_active; |
| 567 | + |
| 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. |
| 574 | + */ |
| 575 | + __u8 hold_request; |
| 576 | +}; |
| 577 | + |
| 578 | +enum tsn_tx_mode { |
| 579 | + TX_MODE_STRICT, |
| 580 | + TX_MODE_CBS, |
| 581 | + TX_MODE_ETS, |
| 582 | + TX_MODE_VENDOR_DEFINE = 255, |
| 583 | +}; |
| 584 | + |
| 585 | +#define QUEUE_TX_MASK ((1 << TX_MODE_STRICT) | (1 << TX_MODE_CBS) \ |
| 586 | + | (1 << TX_MODE_ETS) | (1 << TX_MODE_VENDOR_DEFINE)) |
| 587 | + |
| 588 | +struct cbs_status { |
| 589 | + __u8 delta_bw; /* percentage, 0~100 */ |
| 590 | + __u32 idleslope; |
| 591 | + __s32 sendslope; |
| 592 | + __u32 maxframesize; |
| 593 | + __u32 hicredit; |
| 594 | + __s32 locredit; |
| 595 | + __u32 maxninference; |
| 596 | +}; |
| 597 | + |
| 598 | +struct tx_queue { |
| 599 | + /* tx_queue_capbility shows the queue's capability mask. |
| 600 | + * refer the enum tsn_tx_mode |
| 601 | + */ |
| 602 | + __u8 capability; |
| 603 | + |
| 604 | + /* tx_queue_mode is current queue working mode */ |
| 605 | + __u8 mode; |
| 606 | + |
| 607 | + /* prio is showing the queue priority */ |
| 608 | + __u8 prio; |
| 609 | + |
| 610 | + /* mstat shows the status data of cbs or priority */ |
| 611 | + union { |
| 612 | + struct cbs_status cbs; |
| 613 | + }; |
| 614 | +}; |
| 615 | + |
| 616 | +struct port_status { |
| 617 | + /* txqueue_cnt shows how many queues in this port */ |
| 618 | + __u8 queue_cnt; |
| 619 | + |
| 620 | + /* max_rate(Mbit/s) is the port transmit rate current port is setting */ |
| 621 | + __u32 max_rate; |
| 622 | + |
| 623 | + /* tsn_capability mask the tsn capability */ |
| 624 | + __u32 tsn_capability; |
| 625 | +}; |
| 626 | + |
| 627 | +enum tsn_cb_streamid_type { |
| 628 | + STREAMID_RESERVED = 0, |
| 629 | + /* Null Stream identification */ |
| 630 | + STREAMID_NULL, |
| 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 */ |
| 636 | + STREAMID_IP, |
| 637 | +}; |
| 638 | + |
| 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). |
| 643 | + */ |
| 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. |
| 648 | + */ |
| 649 | + __u64 dmac; |
| 650 | + |
| 651 | + /* tsnCpeNullDownTagged. It can take the following values: |
| 652 | + * 1 tagged: A frame must have a VLAN tag to be recognized as belonging |
| 653 | + * to the Stream. |
| 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 |
| 657 | + * tagged or not. |
| 658 | + */ |
| 659 | + __u8 tagged; |
| 660 | + |
| 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. |
| 665 | + */ |
| 666 | + __u16 vid; |
| 667 | +}; |
| 668 | + |
| 669 | +struct tsn_cb_source_streamid { |
| 670 | + __u64 smac; |
| 671 | + __u8 tagged; |
| 672 | + __u16 vid; |
| 673 | +}; |
| 674 | + |
| 675 | +struct tsn_cb_dest_streamid { |
| 676 | + __u64 down_dmac; |
| 677 | + __u8 down_tagged; |
| 678 | + __u16 down_vid; |
| 679 | + __u8 down_prio; |
| 680 | + __u64 up_dmac; |
| 681 | + __u8 up_tagged; |
| 682 | + __u16 up_vid; |
| 683 | + __u8 up_prio; |
| 684 | +}; |
| 685 | + |
| 686 | +struct tsn_cb_ip_streamid { |
| 687 | + __u64 dmac; |
| 688 | + __u8 tagged; |
| 689 | + __u16 vid; |
| 690 | + __u64 siph; |
| 691 | + __u64 sipl; |
| 692 | + __u64 diph; |
| 693 | + __u64 dipl; |
| 694 | + __u8 dscp; |
| 695 | + __u8 npt; |
| 696 | + __u16 sport; |
| 697 | + __u16 dport; |
| 698 | +}; |
| 699 | + |
| 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. |
| 705 | + */ |
| 706 | + __s32 handle; |
| 707 | + |
| 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. |
| 712 | + */ |
| 713 | + __u32 ifac_oport; |
| 714 | + |
| 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. |
| 719 | + */ |
| 720 | + __u32 ofac_oport; |
| 721 | + |
| 722 | + /* The list of ports on which an in-facing Stream identification |
| 723 | + * function in the input (coming from the system forwarding function) |
| 724 | + * direction |
| 725 | + */ |
| 726 | + __u32 ifac_iport; |
| 727 | + |
| 728 | + /* The list of ports on which an out-facing Stream identification |
| 729 | + * function in the input (coming from the physical interface) direction |
| 730 | + * . |
| 731 | + */ |
| 732 | + __u32 ofac_iport; |
| 733 | + |
| 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 |
| 743 | + */ |
| 744 | + __u8 type; |
| 745 | + |
| 746 | + /* tsnStreamIdParameters The number of controlling parameters for a |
| 747 | + * Stream identification method, their types and values, are specific |
| 748 | + * to the tsnStreamIdIdentificationType |
| 749 | + */ |
| 750 | + union { |
| 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; |
| 755 | + } para; |
| 756 | +}; |
| 757 | + |
| 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). |
| 762 | + */ |
| 763 | +struct tsn_cb_streamid_counters { |
| 764 | + struct { |
| 765 | + __u64 input; |
| 766 | + __u64 output; |
| 767 | + } per_stream; |
| 768 | + |
| 769 | + struct { |
| 770 | + __u64 input; |
| 771 | + __u64 output; |
| 772 | + } per_streamport[32]; |
| 773 | +}; |
| 774 | + |
| 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. |
| 780 | + */ |
| 781 | + __s32 max_sf_instance; |
| 782 | + |
| 783 | + /* MaxStreamGateInstances |
| 784 | + * The maximum number of Stream Gate instances supported by this Bridge |
| 785 | + * component. |
| 786 | + */ |
| 787 | + __s32 max_sg_instance; |
| 788 | + |
| 789 | + /* MaxFlowMeterInstances |
| 790 | + * The maximum number of Flow Meter instances supported by this Bridge |
| 791 | + * component. |
| 792 | + */ |
| 793 | + __s32 max_fm_instance; |
| 794 | + |
| 795 | + /* SupportedListMax |
| 796 | + * The maximum value supported by this Bridge component of the |
| 797 | + * AdminControlListLength and OperControlListLength parameters. |
| 798 | + */ |
| 799 | + __s32 supported_list_max; |
| 800 | +}; |
| 801 | + |
| 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. |
| 806 | + */ |
| 807 | + __u64 matching_frames_count; |
| 808 | + |
| 809 | + /* The PassingFramesCount counter counts received frames that pass the |
| 810 | + * gate associated with this stream filter. |
| 811 | + */ |
| 812 | + __u64 passing_frames_count; |
| 813 | + |
| 814 | + /* The NotPassingFramesCount counter counts received frames that do not |
| 815 | + * pass the gate associated with this stream filter. |
| 816 | + */ |
| 817 | + __u64 not_passing_frames_count; |
| 818 | + |
| 819 | + /* The PassingSDUCount counter counts received frames that pass the SDU |
| 820 | + * size filter specification associated with this stream filter. |
| 821 | + */ |
| 822 | + __u64 passing_sdu_count; |
| 823 | + |
| 824 | + /* The NotPassingSDUCount counter counts received frames that do not |
| 825 | + * pass the SDU size filter specification associated with this stream |
| 826 | + * filter. |
| 827 | + */ |
| 828 | + __u64 not_passing_sdu_count; |
| 829 | + |
| 830 | + /* The REDFramesCount counter counts received random early detection |
| 831 | + * (RED) frames associated with this stream filter. |
| 832 | + */ |
| 833 | + __u64 red_frames_count; |
| 834 | +}; |
| 835 | + |
| 836 | +/* 802.1Qci Stream Filter Instance Table, configuration part only. */ |
| 837 | +struct tsn_qci_psfp_sfi_conf { |
| 838 | + |
| 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. |
| 842 | + */ |
| 843 | + __s32 stream_handle_spec; |
| 844 | + |
| 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. |
| 848 | + */ |
| 849 | + __s8 priority_spec; |
| 850 | + |
| 851 | + /* The StreamGateInstanceID parameter contains the index of an entry in |
| 852 | + * the Stream Gate Table. |
| 853 | + */ |
| 854 | + __u32 stream_gate_instance_id; |
| 855 | + |
| 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. |
| 859 | + */ |
| 860 | + struct { |
| 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. |
| 865 | + */ |
| 866 | + __u16 maximum_sdu_size; |
| 867 | + |
| 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 |
| 871 | + * flow meter IDs. |
| 872 | + */ |
| 873 | + __s32 flow_meter_instance_id; |
| 874 | + } stream_filter; |
| 875 | + |
| 876 | + /* The StreamBlockedDueToOversizeFrameEnable object contains a Boolean |
| 877 | + * value that indicates whether the StreamBlockedDueToOversizeFrame |
| 878 | + * function is enabled (TRUE) or disabled (FALSE). |
| 879 | + */ |
| 880 | + __u8 block_oversize_enable; |
| 881 | + |
| 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 |
| 885 | + * (FALSE). |
| 886 | + */ |
| 887 | + __u8 block_oversize; |
| 888 | +}; |
| 889 | + |
| 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. |
| 894 | + */ |
| 895 | + __u8 gate_state; |
| 896 | + |
| 897 | + /* An IPV is encoded as a signed integer. A negative denotes the null |
| 898 | + * value; zero or positive values denote internal priority values. |
| 899 | + */ |
| 900 | + __s8 ipv; |
| 901 | + |
| 902 | + /* A TimeInterval is encoded in 4 octets as a 32-bit unsigned integer, |
| 903 | + * representing a number of nanoseconds. |
| 904 | + */ |
| 905 | + __u32 time_interval; |
| 906 | + |
| 907 | + /* The maximum number of octets that are permitted to pass the gate |
| 908 | + * during the specified TimeInterval. If zero, there is no maximum. |
| 909 | + */ |
| 910 | + __u32 octet_max; |
| 911 | + |
| 912 | +}; |
| 913 | + |
| 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. |
| 919 | + */ |
| 920 | + __u8 gate_states; |
| 921 | + |
| 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. |
| 925 | + */ |
| 926 | + __u8 control_list_length; |
| 927 | + |
| 928 | + /* The administrative/operation value of the CycleTime parameter for |
| 929 | + * the gate. The value is an unsigned integer number of nanoseconds. |
| 930 | + */ |
| 931 | + __u32 cycle_time; |
| 932 | + |
| 933 | + /* The administrative/operation value of the CycleTimeExtension |
| 934 | + * parameter for the gate. The value is an unsigned integer number |
| 935 | + * of nanoseconds. |
| 936 | + */ |
| 937 | + __u32 cycle_time_extension; |
| 938 | + |
| 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 |
| 942 | + * nanoseconds. |
| 943 | + */ |
| 944 | + ptptime_t base_time; |
| 945 | + |
| 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. |
| 949 | + */ |
| 950 | + __s8 init_ipv; |
| 951 | + |
| 952 | + /* control_list contend the gate control list of |
| 953 | + * administrative/operation |
| 954 | + */ |
| 955 | + struct tsn_qci_psfp_gcl *gcl; |
| 956 | +}; |
| 957 | + |
| 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). |
| 962 | + */ |
| 963 | + __u8 gate_enabled; |
| 964 | + |
| 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. |
| 968 | + */ |
| 969 | + __u8 config_change; |
| 970 | + |
| 971 | + /* admin control parameters with admin control list */ |
| 972 | + struct tsn_qci_sg_control admin; |
| 973 | + |
| 974 | + /* The GateClosedDueToInvalidRxEnable object contains a Boolean value |
| 975 | + * that indicates whether the GateClosedDueToInvalidRx function is |
| 976 | + * enabled (TRUE) or disabled (FALSE). |
| 977 | + */ |
| 978 | + __u8 block_invalid_rx_enable; |
| 979 | + |
| 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). |
| 983 | + */ |
| 984 | + __u8 block_invalid_rx; |
| 985 | + |
| 986 | + /* The GateClosedDueToOctetsExceededEnable object contains a Boolean |
| 987 | + * value that indicates whether the GateClosedDueToOctetsExceeded |
| 988 | + * function is enabled (TRUE) or disabled (FALSE). |
| 989 | + */ |
| 990 | + __u8 block_octets_exceeded_enable; |
| 991 | + |
| 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 |
| 995 | + * (FALSE). |
| 996 | + */ |
| 997 | + __u8 block_octets_exceeded; |
| 998 | +}; |
| 999 | + |
| 1000 | +/* 802.1Qci Stream Gate Instance Table, status part only. */ |
| 1001 | +struct tsn_psfp_sgi_status { |
| 1002 | + |
| 1003 | + /* admin control parameters with admin control list */ |
| 1004 | + struct tsn_qci_sg_control oper; |
| 1005 | + |
| 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 |
| 1009 | + * nanoseconds. |
| 1010 | + */ |
| 1011 | + ptptime_t config_change_time; |
| 1012 | + |
| 1013 | + /* The granularity of the cycle time clock, represented as an unsigned |
| 1014 | + * number of tenths of nanoseconds. |
| 1015 | + */ |
| 1016 | + __u32 tick_granularity; |
| 1017 | + |
| 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 |
| 1021 | + * nanoseconds. |
| 1022 | + */ |
| 1023 | + ptptime_t current_time; |
| 1024 | + |
| 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 |
| 1027 | + * completed. |
| 1028 | + */ |
| 1029 | + __u8 config_pending; |
| 1030 | + |
| 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. |
| 1034 | + */ |
| 1035 | + __u64 config_change_error; |
| 1036 | + |
| 1037 | +}; |
| 1038 | + |
| 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. |
| 1043 | + */ |
| 1044 | + __u32 cir; |
| 1045 | + |
| 1046 | + /* The FlowMeterCBS parameter contains an integer value that represents |
| 1047 | + * the CBS value for the flow meter, in octets. |
| 1048 | + */ |
| 1049 | + __u32 cbs; |
| 1050 | + |
| 1051 | + /* The FlowMeterEIR parameter contains an integer value that represents |
| 1052 | + * the EIR value for the flow meter, in kbit/s. |
| 1053 | + */ |
| 1054 | + __u32 eir; |
| 1055 | + |
| 1056 | + /* The FlowMeterEBS parameter contains an integer value that represents |
| 1057 | + * the EBS value for the flow meter, in octets. |
| 1058 | + */ |
| 1059 | + __u32 ebs; |
| 1060 | + |
| 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). |
| 1064 | + */ |
| 1065 | + __u8 cf; |
| 1066 | + |
| 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). |
| 1070 | + */ |
| 1071 | + __u8 cm; |
| 1072 | + |
| 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). |
| 1076 | + */ |
| 1077 | + __u8 drop_on_yellow; |
| 1078 | + |
| 1079 | + /* The FlowMeterMarkAllFramesRedEnable parameter contains a Boolean |
| 1080 | + * value that indicates whether the MarkAllFramesRed function |
| 1081 | + * is enabled (TRUE) or disabled (FALSE). |
| 1082 | + */ |
| 1083 | + __u8 mark_red_enable; |
| 1084 | + |
| 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). |
| 1088 | + */ |
| 1089 | + __u8 mark_red; |
| 1090 | +}; |
| 1091 | + |
| 1092 | +struct tsn_qci_psfp_fmi_counters { |
| 1093 | + __u64 bytecount; |
| 1094 | + __u64 drop; |
| 1095 | + __u64 dr0_green; |
| 1096 | + __u64 dr1_green; |
| 1097 | + __u64 dr2_yellow; |
| 1098 | + __u64 remark_yellow; |
| 1099 | + __u64 dr3_red; |
| 1100 | + __u64 remark_red; |
| 1101 | +}; |
| 1102 | + |
| 1103 | +/* 802.1cb */ |
| 1104 | +struct tsn_seq_gen_conf { |
| 1105 | + |
| 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. |
| 1110 | + */ |
| 1111 | + __u8 iport_mask; |
| 1112 | + |
| 1113 | + /* The SplitMask parameter contains a output port mask |
| 1114 | + * used to add redundant paths. |
| 1115 | + */ |
| 1116 | + __u8 split_mask; |
| 1117 | + |
| 1118 | + /* The SequenceSpaceLenLog parameter is a value to specifies |
| 1119 | + * number of bits to be used for sequence number. |
| 1120 | + */ |
| 1121 | + __u8 seq_len; |
| 1122 | + |
| 1123 | + /* The SequenceNumber parameter is a value to used for |
| 1124 | + * outgoing packet's sequence number generation. |
| 1125 | + */ |
| 1126 | + __u32 seq_num; |
| 1127 | +}; |
| 1128 | + |
| 1129 | +struct tsn_seq_rec_conf { |
| 1130 | + |
| 1131 | + /* The SequenceSpaceLenLog parameter is a value to specifies |
| 1132 | + * number of bits to be used for sequence number. |
| 1133 | + */ |
| 1134 | + __u8 seq_len; |
| 1135 | + |
| 1136 | + /* The HistorySpaceLenLog parameter is a value to specifies |
| 1137 | + * number of bits to be used for history register. |
| 1138 | + */ |
| 1139 | + __u8 his_len; |
| 1140 | + |
| 1141 | + /* The RTagPopEnable parameter contains a __u8 to enable removal |
| 1142 | + * of redundancy tag from the packet. |
| 1143 | + */ |
| 1144 | + __u8 rtag_pop_en; |
| 1145 | +}; |
| 1146 | + |
| 1147 | +struct tsn_cb_status { |
| 1148 | + |
| 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. |
| 1153 | + */ |
| 1154 | + __u8 gen_rec; |
| 1155 | + |
| 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. |
| 1161 | + */ |
| 1162 | + __u8 err; |
| 1163 | + |
| 1164 | + /* The SequenceNumber parameter is a value to used for |
| 1165 | + * outgoing packet's sequence number generation. |
| 1166 | + */ |
| 1167 | + __u32 seq_num; |
| 1168 | + |
| 1169 | + /* The SequenceSpaceLenLog parameter is a value to specifies |
| 1170 | + * number of bits to be used for sequence number. |
| 1171 | + */ |
| 1172 | + __u8 seq_len; |
| 1173 | + |
| 1174 | + /* The SplitMask parameter contains a output port mask |
| 1175 | + * used to add redundant paths. |
| 1176 | + */ |
| 1177 | + __u8 split_mask; |
| 1178 | + |
| 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. |
| 1183 | + */ |
| 1184 | + __u8 iport_mask; |
| 1185 | + |
| 1186 | + /* The HistorySpaceLenLog parameter is a value to specifies |
| 1187 | + * number of bits to be used for history register. |
| 1188 | + */ |
| 1189 | + __u8 his_len; |
| 1190 | + |
| 1191 | + /* The SequenceHistory parameter Maintains history of sequence |
| 1192 | + * numbers of received packets. |
| 1193 | + */ |
| 1194 | + __u32 seq_his; |
| 1195 | +}; |
| 1196 | + |
| 1197 | +/* An entry for gate control list */ |
| 1198 | +struct tsn_qbv_entry { |
| 1199 | + /* Octet represent the gate states for the corresponding traffic |
| 1200 | + * classes. |
| 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. |
| 1205 | + */ |
| 1206 | + __u8 gate_state; |
| 1207 | + |
| 1208 | + /* A TimeInterval is encoded in 4 octets as a 32-bit unsigned integer, |
| 1209 | + * representing a number of nanoseconds. |
| 1210 | + */ |
| 1211 | + __u32 time_interval; |
| 1212 | +}; |
| 1213 | + |
| 1214 | +/* The administrative/operation time and gate list */ |
| 1215 | +struct tsn_qbv_basic { |
| 1216 | + /* The administrative/operation value of the GateStates parameter for |
| 1217 | + * the Port. |
| 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. |
| 1224 | + */ |
| 1225 | + __u8 gate_states; |
| 1226 | + |
| 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. |
| 1231 | + */ |
| 1232 | + __u32 control_list_length; |
| 1233 | + |
| 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. |
| 1239 | + */ |
| 1240 | + __u32 cycle_time; |
| 1241 | + |
| 1242 | + /* The administrative/operation value of the CycleTimeExtension |
| 1243 | + * parameter for the Port. The value is an unsigned integer number of |
| 1244 | + * nanoseconds. |
| 1245 | + * The value of this object MUST be retained across reinitializations |
| 1246 | + * of the management system. |
| 1247 | + */ |
| 1248 | + |
| 1249 | + __u32 cycle_time_extension; |
| 1250 | + |
| 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 |
| 1254 | + * nanoseconds. |
| 1255 | + * The value of this object MUST be retained across reinitializations of |
| 1256 | + * the management system. |
| 1257 | + */ |
| 1258 | + ptptime_t base_time; |
| 1259 | + |
| 1260 | + /* admin_control_list represent the AdminControlList/OperControlList. |
| 1261 | + * The administrative version of the gate control list for the Port. |
| 1262 | + */ |
| 1263 | + struct tsn_qbv_entry *control_list; |
| 1264 | +}; |
| 1265 | + |
| 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. |
| 1270 | + */ |
| 1271 | + __u8 gate_enabled; |
| 1272 | + |
| 1273 | + /* The maxsdu parameter denoting the maximum SDU size supported by the |
| 1274 | + * queue. |
| 1275 | + */ |
| 1276 | + __u32 maxsdu; |
| 1277 | + |
| 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. |
| 1281 | + */ |
| 1282 | + __u8 config_change; |
| 1283 | + |
| 1284 | + /* The admin parameter signals the admin relate cycletime, basictime, |
| 1285 | + * gatelist paraters. |
| 1286 | + */ |
| 1287 | + struct tsn_qbv_basic admin; |
| 1288 | +}; |
| 1289 | + |
| 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. |
| 1297 | + */ |
| 1298 | + ptptime_t config_change_time; |
| 1299 | + |
| 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. |
| 1303 | + */ |
| 1304 | + __u32 tick_granularity; |
| 1305 | + |
| 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 |
| 1309 | + * nanoseconds. |
| 1310 | + */ |
| 1311 | + ptptime_t current_time; |
| 1312 | + |
| 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 |
| 1315 | + * completed. |
| 1316 | + */ |
| 1317 | + __u8 config_pending; |
| 1318 | + |
| 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. |
| 1322 | + */ |
| 1323 | + __u64 config_change_error; |
| 1324 | + |
| 1325 | + /* The maximum value supported by this Port of the |
| 1326 | + * AdminControlListLength and OperControlListLength parameters. |
| 1327 | + */ |
| 1328 | + __u32 supported_list_max; |
| 1329 | + |
| 1330 | + /* Operation settings parameters and Oper gate list */ |
| 1331 | + struct tsn_qbv_basic oper; |
| 1332 | +}; |
| 1333 | + |
| 1334 | +/* Time Specific Departure parameters */ |
| 1335 | +struct tsn_tsd { |
| 1336 | + __u8 enable; |
| 1337 | + |
| 1338 | + /* The cycle time, in units of microsecond(us)*/ |
| 1339 | + __u32 period; |
| 1340 | + |
| 1341 | + /* The maximum number of frames which could be transmitted on one cycle |
| 1342 | + * The exceeding frames will be transmitted on next cycle. |
| 1343 | + */ |
| 1344 | + __u32 maxFrameNum; |
| 1345 | + |
| 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. |
| 1349 | + */ |
| 1350 | + __u32 syn_flag; |
| 1351 | +}; |
| 1352 | + |
| 1353 | +struct tsn_tsd_status { |
| 1354 | + __u8 enable; |
| 1355 | + __u32 period; |
| 1356 | + __u32 maxFrameNum; |
| 1357 | + __u32 flag; |
| 1358 | + __u32 cycleNum; |
| 1359 | + __u32 loss_steps; |
| 1360 | +}; |
| 1361 | + |
| 1362 | +struct tsn_qos_switch_dscp_conf { |
| 1363 | + __u8 trust; |
| 1364 | + __u8 cos; |
| 1365 | + __u8 dpl; |
| 1366 | + __u8 remark; |
| 1367 | + __u8 dscp; /* New ingress translated DSCP value */ |
| 1368 | +}; |
| 1369 | + |
| 1370 | +#endif /* _UAPI_GENL_TSN_H */ |
| 1371 | --- a/net/Kconfig |
| 1372 | +++ b/net/Kconfig |
| 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" |
| 1381 | --- a/net/Makefile |
| 1382 | +++ b/net/Makefile |
| 1383 | @@ -59,6 +59,9 @@ obj-$(CONFIG_CAIF) += caif/ |
| 1384 | ifneq ($(CONFIG_DCB),) |
| 1385 | obj-y += dcb/ |
| 1386 | endif |
| 1387 | +ifneq ($(CONFIG_TSN),) |
| 1388 | +obj-y += tsn/ |
| 1389 | +endif |
| 1390 | obj-$(CONFIG_6LOWPAN) += 6lowpan/ |
| 1391 | obj-$(CONFIG_IEEE802154) += ieee802154/ |
| 1392 | obj-$(CONFIG_MAC802154) += mac802154/ |
| 1393 | --- /dev/null |
| 1394 | +++ b/net/tsn/Kconfig |
| 1395 | @@ -0,0 +1,15 @@ |
| 1396 | +config TSN |
| 1397 | + bool "802.1 Time-Sensitive Networking support" |
| 1398 | + default n |
| 1399 | + depends on VLAN_8021Q && PTP_1588_CLOCK |
| 1400 | + help |
| 1401 | + This enables support for TSN(time sensitive networking) |
| 1402 | + TSN features include: |
| 1403 | + 802.1Qav: |
| 1404 | + 802.1Qbv: |
| 1405 | + 802.1Qci: |
| 1406 | + 802.1Qbu: |
| 1407 | + 802.1AS: |
| 1408 | + 802.1CB: |
| 1409 | + |
| 1410 | + If unsure, say N. |
| 1411 | --- /dev/null |
| 1412 | +++ b/net/tsn/Makefile |
| 1413 | @@ -0,0 +1 @@ |
| 1414 | +obj-$(CONFIG_TSN) += genl_tsn.o |
| 1415 | --- /dev/null |
| 1416 | +++ b/net/tsn/genl_tsn.c |
| 1417 | @@ -0,0 +1,3696 @@ |
| 1418 | +// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) |
| 1419 | +/* Copyright 2017-2019 NXP */ |
| 1420 | + |
| 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> |
| 1430 | + |
| 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) |
| 1434 | + |
| 1435 | +static struct genl_family tsn_family; |
| 1436 | + |
| 1437 | +LIST_HEAD(port_list); |
| 1438 | + |
| 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 }, |
| 1459 | +}; |
| 1460 | + |
| 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 }, |
| 1469 | +}; |
| 1470 | + |
| 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 }, |
| 1476 | +}; |
| 1477 | + |
| 1478 | +static const struct nla_policy ct_policy[TSN_CT_ATTR_MAX + 1] = { |
| 1479 | + [TSN_CT_ATTR_QUEUE_STATE] = { .type = NLA_U8 } |
| 1480 | +}; |
| 1481 | + |
| 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 }, |
| 1488 | +}; |
| 1489 | + |
| 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 }, |
| 1495 | +}; |
| 1496 | + |
| 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 }, |
| 1507 | +}; |
| 1508 | + |
| 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}, |
| 1515 | +}; |
| 1516 | + |
| 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}, |
| 1520 | +}; |
| 1521 | + |
| 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}, |
| 1530 | +}; |
| 1531 | + |
| 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}, |
| 1545 | +}; |
| 1546 | + |
| 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}, |
| 1554 | +}; |
| 1555 | + |
| 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}, |
| 1560 | +}; |
| 1561 | + |
| 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}, |
| 1582 | +}; |
| 1583 | + |
| 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}, |
| 1598 | +}; |
| 1599 | + |
| 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}, |
| 1616 | +}; |
| 1617 | + |
| 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}, |
| 1626 | +}; |
| 1627 | + |
| 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}, |
| 1633 | +}; |
| 1634 | + |
| 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)}, |
| 1650 | +}; |
| 1651 | + |
| 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}, |
| 1657 | +}; |
| 1658 | + |
| 1659 | +static ATOMIC_NOTIFIER_HEAD(tsn_notif_chain); |
| 1660 | + |
| 1661 | +/** |
| 1662 | + * register_tsn_notifier - Register notifier |
| 1663 | + * @nb: notifier_block |
| 1664 | + * |
| 1665 | + * Register switch device notifier. |
| 1666 | + */ |
| 1667 | +int register_tsn_notifier(struct notifier_block *nb) |
| 1668 | +{ |
| 1669 | + return atomic_notifier_chain_register(&tsn_notif_chain, nb); |
| 1670 | +} |
| 1671 | +EXPORT_SYMBOL_GPL(register_tsn_notifier); |
| 1672 | + |
| 1673 | +/** |
| 1674 | + * unregister_tsn_notifier - Unregister notifier |
| 1675 | + * @nb: notifier_block |
| 1676 | + * |
| 1677 | + * Unregister switch device notifier. |
| 1678 | + */ |
| 1679 | +int unregister_tsn_notifier(struct notifier_block *nb) |
| 1680 | +{ |
| 1681 | + return atomic_notifier_chain_unregister(&tsn_notif_chain, nb); |
| 1682 | +} |
| 1683 | +EXPORT_SYMBOL_GPL(unregister_tsn_notifier); |
| 1684 | + |
| 1685 | +/** |
| 1686 | + * call_tsn_notifiers - Call notifiers |
| 1687 | + * @val: value passed unmodified to notifier function |
| 1688 | + * @dev: port device |
| 1689 | + * @info: notifier information data |
| 1690 | + * |
| 1691 | + * Call all network notifier blocks. |
| 1692 | + */ |
| 1693 | +int call_tsn_notifiers(unsigned long val, struct net_device *dev, |
| 1694 | + struct tsn_notifier_info *info) |
| 1695 | +{ |
| 1696 | + info->dev = dev; |
| 1697 | + return atomic_notifier_call_chain(&tsn_notif_chain, val, info); |
| 1698 | +} |
| 1699 | +EXPORT_SYMBOL_GPL(call_tsn_notifiers); |
| 1700 | + |
| 1701 | +struct tsn_port *tsn_get_port(struct net_device *ndev) |
| 1702 | +{ |
| 1703 | + struct tsn_port *port; |
| 1704 | + bool tsn_found = false; |
| 1705 | + |
| 1706 | + list_for_each_entry(port, &port_list, list) { |
| 1707 | + if (port->netdev == ndev) { |
| 1708 | + tsn_found = true; |
| 1709 | + break; |
| 1710 | + } |
| 1711 | + } |
| 1712 | + |
| 1713 | + if (!tsn_found) |
| 1714 | + return NULL; |
| 1715 | + |
| 1716 | + return port; |
| 1717 | +} |
| 1718 | +EXPORT_SYMBOL_GPL(tsn_get_port); |
| 1719 | + |
| 1720 | +static int tsn_prepare_reply(struct genl_info *info, u8 cmd, |
| 1721 | + struct sk_buff **skbp, size_t size) |
| 1722 | +{ |
| 1723 | + struct sk_buff *skb; |
| 1724 | + void *reply; |
| 1725 | + |
| 1726 | + /* If new attributes are added, please revisit this allocation |
| 1727 | + */ |
| 1728 | + skb = genlmsg_new(size, GFP_KERNEL); |
| 1729 | + if (!skb) |
| 1730 | + return -ENOMEM; |
| 1731 | + |
| 1732 | + if (!info) { |
| 1733 | + nlmsg_free(skb); |
| 1734 | + return -EINVAL; |
| 1735 | + } |
| 1736 | + |
| 1737 | + reply = genlmsg_put_reply(skb, info, &tsn_family, 0, cmd); |
| 1738 | + if (!reply) { |
| 1739 | + nlmsg_free(skb); |
| 1740 | + return -EINVAL; |
| 1741 | + } |
| 1742 | + |
| 1743 | + *skbp = skb; |
| 1744 | + return 0; |
| 1745 | +} |
| 1746 | + |
| 1747 | +static int tsn_mk_reply(struct sk_buff *skb, int aggr, void *data, int len) |
| 1748 | +{ |
| 1749 | + /* add a netlink attribute to a socket buffer */ |
| 1750 | + return nla_put(skb, aggr, len, data); |
| 1751 | +} |
| 1752 | + |
| 1753 | +static int tsn_send_reply(struct sk_buff *skb, struct genl_info *info) |
| 1754 | +{ |
| 1755 | + struct genlmsghdr *genlhdr = nlmsg_data(nlmsg_hdr(skb)); |
| 1756 | + void *reply = genlmsg_data(genlhdr); |
| 1757 | + |
| 1758 | + genlmsg_end(skb, reply); |
| 1759 | + |
| 1760 | + return genlmsg_reply(skb, info); |
| 1761 | +} |
| 1762 | + |
| 1763 | +static int cmd_attr_echo_message(struct genl_info *info) |
| 1764 | +{ |
| 1765 | + struct nlattr *na; |
| 1766 | + char *msg; |
| 1767 | + struct sk_buff *rep_skb; |
| 1768 | + size_t size; |
| 1769 | + int ret; |
| 1770 | + |
| 1771 | + na = info->attrs[TSN_CMD_ATTR_MESG]; |
| 1772 | + if (!na) |
| 1773 | + return -EINVAL; |
| 1774 | + |
| 1775 | + msg = (char *)nla_data(na); |
| 1776 | + pr_info("tsn generic netlink receive echo mesg %s\n", msg); |
| 1777 | + |
| 1778 | + size = nla_total_size(strlen(msg) + 1); |
| 1779 | + |
| 1780 | + ret = tsn_prepare_reply(info, TSN_CMD_REPLY, &rep_skb, |
| 1781 | + size + NLMSG_ALIGN(MAX_USER_SIZE)); |
| 1782 | + if (ret < 0) |
| 1783 | + return ret; |
| 1784 | + |
| 1785 | + ret = tsn_mk_reply(rep_skb, TSN_CMD_ATTR_MESG, msg, size); |
| 1786 | + if (ret < 0) |
| 1787 | + goto err; |
| 1788 | + |
| 1789 | + return tsn_send_reply(rep_skb, info); |
| 1790 | + |
| 1791 | +err: |
| 1792 | + nlmsg_free(rep_skb); |
| 1793 | + return ret; |
| 1794 | +} |
| 1795 | + |
| 1796 | +static int cmd_attr_echo_data(struct genl_info *info) |
| 1797 | +{ |
| 1798 | + struct nlattr *na; |
| 1799 | + s32 data; |
| 1800 | + struct sk_buff *rep_skb; |
| 1801 | + size_t size; |
| 1802 | + int ret; |
| 1803 | + |
| 1804 | + /*read data */ |
| 1805 | + na = info->attrs[TSN_CMD_ATTR_DATA]; |
| 1806 | + if (!na) |
| 1807 | + return -EINVAL; |
| 1808 | + |
| 1809 | + data = nla_get_s32(info->attrs[TSN_CMD_ATTR_DATA]); |
| 1810 | + pr_info("tsn generic netlink receive echo data %d\n", data); |
| 1811 | + |
| 1812 | + /* send back */ |
| 1813 | + size = nla_total_size(sizeof(s32)); |
| 1814 | + |
| 1815 | + ret = tsn_prepare_reply(info, TSN_CMD_REPLY, &rep_skb, |
| 1816 | + size + NLMSG_ALIGN(MAX_USER_SIZE)); |
| 1817 | + if (ret < 0) |
| 1818 | + return ret; |
| 1819 | + |
| 1820 | + /* netlink lib func */ |
| 1821 | + ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, data); |
| 1822 | + if (ret < 0) |
| 1823 | + goto err; |
| 1824 | + |
| 1825 | + return tsn_send_reply(rep_skb, info); |
| 1826 | + |
| 1827 | +err: |
| 1828 | + nlmsg_free(rep_skb); |
| 1829 | + return ret; |
| 1830 | +} |
| 1831 | + |
| 1832 | +static int tsn_echo_cmd(struct sk_buff *skb, struct genl_info *info) |
| 1833 | +{ |
| 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); |
| 1838 | + |
| 1839 | + return -EINVAL; |
| 1840 | +} |
| 1841 | + |
| 1842 | +static int tsn_simple_reply(struct genl_info *info, u32 cmd, |
| 1843 | + char *portname, s32 retvalue) |
| 1844 | +{ |
| 1845 | + struct sk_buff *rep_skb; |
| 1846 | + size_t size; |
| 1847 | + int ret; |
| 1848 | + |
| 1849 | + /* send back */ |
| 1850 | + size = nla_total_size(strlen(portname) + 1); |
| 1851 | + size += nla_total_size(sizeof(s32)); |
| 1852 | + |
| 1853 | + ret = tsn_prepare_reply(info, cmd, |
| 1854 | + &rep_skb, size + NLMSG_ALIGN(MAX_USER_SIZE)); |
| 1855 | + if (ret < 0) |
| 1856 | + return ret; |
| 1857 | + |
| 1858 | + /* netlink lib func */ |
| 1859 | + ret = nla_put_string(rep_skb, TSN_ATTR_IFNAME, portname); |
| 1860 | + if (ret < 0) |
| 1861 | + return ret; |
| 1862 | + |
| 1863 | + ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, retvalue); |
| 1864 | + if (ret < 0) |
| 1865 | + return ret; |
| 1866 | + |
| 1867 | + return tsn_send_reply(rep_skb, info); |
| 1868 | +} |
| 1869 | + |
| 1870 | +struct tsn_port *tsn_init_check(struct genl_info *info, |
| 1871 | + struct net_device **ndev) |
| 1872 | +{ |
| 1873 | + struct nlattr *na; |
| 1874 | + char *portname; |
| 1875 | + struct net_device *netdev; |
| 1876 | + struct tsn_port *port; |
| 1877 | + bool tsn_found = false; |
| 1878 | + |
| 1879 | + if (!info->attrs[TSN_ATTR_IFNAME]) { |
| 1880 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 1881 | + "no portname", -EINVAL); |
| 1882 | + return NULL; |
| 1883 | + } |
| 1884 | + |
| 1885 | + na = info->attrs[TSN_ATTR_IFNAME]; |
| 1886 | + |
| 1887 | + portname = (char *)nla_data(na); |
| 1888 | + |
| 1889 | + netdev = __dev_get_by_name(genl_info_net(info), portname); |
| 1890 | + if (!netdev) { |
| 1891 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 1892 | + "error device", -ENODEV); |
| 1893 | + return NULL; |
| 1894 | + } |
| 1895 | + |
| 1896 | + list_for_each_entry(port, &port_list, list) { |
| 1897 | + if (port->netdev == netdev) { |
| 1898 | + tsn_found = true; |
| 1899 | + break; |
| 1900 | + } |
| 1901 | + } |
| 1902 | + |
| 1903 | + if (!tsn_found) { |
| 1904 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 1905 | + netdev->name, -ENODEV); |
| 1906 | + return NULL; |
| 1907 | + } |
| 1908 | + |
| 1909 | + *ndev = netdev; |
| 1910 | + |
| 1911 | + return port; |
| 1912 | +} |
| 1913 | + |
| 1914 | +static int tsn_cap_get(struct sk_buff *skb, struct genl_info *info) |
| 1915 | +{ |
| 1916 | + struct sk_buff *rep_skb; |
| 1917 | + struct nlattr *tsn_cap_attr; |
| 1918 | + int ret; |
| 1919 | + u32 cap = 0; |
| 1920 | + struct net_device *netdev; |
| 1921 | + struct genlmsghdr *genlhdr; |
| 1922 | + const struct tsn_ops *tsnops; |
| 1923 | + struct tsn_port *port; |
| 1924 | + |
| 1925 | + port = tsn_init_check(info, &netdev); |
| 1926 | + if (!port) { |
| 1927 | + ret = -ENODEV; |
| 1928 | + goto out; |
| 1929 | + } |
| 1930 | + |
| 1931 | + tsnops = port->tsnops; |
| 1932 | + genlhdr = info->genlhdr; |
| 1933 | + if (!tsnops->get_capability) { |
| 1934 | + ret = -EOPNOTSUPP; |
| 1935 | + goto out; |
| 1936 | + } |
| 1937 | + |
| 1938 | + cap = tsnops->get_capability(netdev); |
| 1939 | + if (cap < 0) { |
| 1940 | + ret = cap; |
| 1941 | + goto out; |
| 1942 | + } |
| 1943 | + |
| 1944 | + /* Pad netlink reply data */ |
| 1945 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 1946 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 1947 | + if (ret < 0) |
| 1948 | + goto out; |
| 1949 | + |
| 1950 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) { |
| 1951 | + ret = -EMSGSIZE; |
| 1952 | + goto err; |
| 1953 | + } |
| 1954 | + |
| 1955 | + tsn_cap_attr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CAP); |
| 1956 | + if (!tsn_cap_attr) { |
| 1957 | + ret = -EMSGSIZE; |
| 1958 | + goto err; |
| 1959 | + } |
| 1960 | + |
| 1961 | + if (cap & TSN_CAP_QBV) { |
| 1962 | + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QBV)) |
| 1963 | + goto err; |
| 1964 | + } |
| 1965 | + |
| 1966 | + if (cap & TSN_CAP_QCI) { |
| 1967 | + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QCI)) |
| 1968 | + goto err; |
| 1969 | + } |
| 1970 | + |
| 1971 | + if (cap & TSN_CAP_QBU) { |
| 1972 | + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_QBU)) |
| 1973 | + goto err; |
| 1974 | + } |
| 1975 | + |
| 1976 | + if (cap & TSN_CAP_CBS) { |
| 1977 | + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CBS)) |
| 1978 | + goto err; |
| 1979 | + } |
| 1980 | + |
| 1981 | + if (cap & TSN_CAP_CB) { |
| 1982 | + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CB)) |
| 1983 | + goto err; |
| 1984 | + } |
| 1985 | + |
| 1986 | + if (cap & TSN_CAP_TBS) { |
| 1987 | + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_TBS)) |
| 1988 | + goto err; |
| 1989 | + } |
| 1990 | + |
| 1991 | + if (cap & TSN_CAP_CTH) { |
| 1992 | + if (nla_put_flag(rep_skb, TSN_CAP_ATTR_CTH)) |
| 1993 | + goto err; |
| 1994 | + } |
| 1995 | + |
| 1996 | + nla_nest_end(rep_skb, tsn_cap_attr); |
| 1997 | + |
| 1998 | + tsn_send_reply(rep_skb, info); |
| 1999 | + return 0; |
| 2000 | +err: |
| 2001 | + nlmsg_free(rep_skb); |
| 2002 | +out: |
| 2003 | + if (ret < 0) |
| 2004 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 2005 | + return ret; |
| 2006 | +} |
| 2007 | + |
| 2008 | +static int cmd_cb_streamid_set(struct genl_info *info) |
| 2009 | +{ |
| 2010 | + struct nlattr *na, *sid[TSN_STREAMID_ATTR_MAX + 1]; |
| 2011 | + u32 sid_index; |
| 2012 | + u8 iden_type = 1; |
| 2013 | + bool enable; |
| 2014 | + int ret; |
| 2015 | + struct net_device *netdev; |
| 2016 | + struct tsn_cb_streamid sidconf; |
| 2017 | + const struct tsn_ops *tsnops; |
| 2018 | + struct tsn_port *port; |
| 2019 | + |
| 2020 | + port = tsn_init_check(info, &netdev); |
| 2021 | + if (!port) |
| 2022 | + return -ENODEV; |
| 2023 | + |
| 2024 | + tsnops = port->tsnops; |
| 2025 | + |
| 2026 | + memset(&sidconf, 0, sizeof(struct tsn_cb_streamid)); |
| 2027 | + |
| 2028 | + if (!info->attrs[TSN_ATTR_STREAM_IDENTIFY]) |
| 2029 | + return -EINVAL; |
| 2030 | + |
| 2031 | + na = info->attrs[TSN_ATTR_STREAM_IDENTIFY]; |
| 2032 | + |
| 2033 | + ret = NLA_PARSE_NESTED(sid, TSN_STREAMID_ATTR_MAX, |
| 2034 | + na, cb_streamid_policy); |
| 2035 | + if (ret) |
| 2036 | + return -EINVAL; |
| 2037 | + |
| 2038 | + if (!sid[TSN_STREAMID_ATTR_INDEX]) |
| 2039 | + return -EINVAL; |
| 2040 | + |
| 2041 | + sid_index = nla_get_u32(sid[TSN_STREAMID_ATTR_INDEX]); |
| 2042 | + |
| 2043 | + if (sid[TSN_STREAMID_ATTR_ENABLE]) |
| 2044 | + enable = true; |
| 2045 | + else if (sid[TSN_STREAMID_ATTR_DISABLE]) |
| 2046 | + enable = false; |
| 2047 | + else |
| 2048 | + return -EINVAL; |
| 2049 | + |
| 2050 | + if (!enable) |
| 2051 | + goto loaddev; |
| 2052 | + |
| 2053 | + if (sid[TSN_STREAMID_ATTR_TYPE]) |
| 2054 | + iden_type = nla_get_u8(sid[TSN_STREAMID_ATTR_TYPE]); |
| 2055 | + else |
| 2056 | + return -EINVAL; |
| 2057 | + |
| 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]) { |
| 2064 | + return -EINVAL; |
| 2065 | + } |
| 2066 | + |
| 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]); |
| 2073 | + break; |
| 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]) { |
| 2079 | + return -EINVAL; |
| 2080 | + } |
| 2081 | + |
| 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]); |
| 2088 | + break; |
| 2089 | + case STREAMID_DMAC_VLAN: |
| 2090 | + |
| 2091 | + case STREAMID_IP: |
| 2092 | + |
| 2093 | + default: |
| 2094 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2095 | + netdev->name, -EINVAL); |
| 2096 | + return -EINVAL; |
| 2097 | + } |
| 2098 | + |
| 2099 | + if (sid[TSN_STREAMID_ATTR_STREAM_HANDLE]) |
| 2100 | + sidconf.handle = |
| 2101 | + nla_get_s32(sid[TSN_STREAMID_ATTR_STREAM_HANDLE]); |
| 2102 | + |
| 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]); |
| 2111 | + |
| 2112 | +loaddev: |
| 2113 | + if (!tsnops->cb_streamid_set) { |
| 2114 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2115 | + netdev->name, -EPERM); |
| 2116 | + return -EOPNOTSUPP; |
| 2117 | + } |
| 2118 | + |
| 2119 | + ret = tsnops->cb_streamid_set(netdev, sid_index, enable, &sidconf); |
| 2120 | + if (ret < 0) { |
| 2121 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 2122 | + return ret; |
| 2123 | + } |
| 2124 | + |
| 2125 | + /* simple reply here. To be continue */ |
| 2126 | + if (tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0)) |
| 2127 | + return -1; |
| 2128 | + |
| 2129 | + return 0; |
| 2130 | +} |
| 2131 | + |
| 2132 | +static int tsn_cb_streamid_set(struct sk_buff *skb, struct genl_info *info) |
| 2133 | +{ |
| 2134 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 2135 | + cmd_cb_streamid_set(info); |
| 2136 | + return 0; |
| 2137 | + } |
| 2138 | + |
| 2139 | + return -1; |
| 2140 | +} |
| 2141 | + |
| 2142 | +static int cmd_cb_streamid_get(struct genl_info *info) |
| 2143 | +{ |
| 2144 | + struct nlattr *na, *sidattr, *sid[TSN_STREAMID_ATTR_MAX + 1]; |
| 2145 | + u32 sid_index; |
| 2146 | + struct genlmsghdr *genlhdr; |
| 2147 | + struct sk_buff *rep_skb; |
| 2148 | + int ret, i; |
| 2149 | + int valid; |
| 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; |
| 2155 | + |
| 2156 | + port = tsn_init_check(info, &netdev); |
| 2157 | + if (!port) |
| 2158 | + return -ENODEV; |
| 2159 | + |
| 2160 | + tsnops = port->tsnops; |
| 2161 | + |
| 2162 | + memset(&sidconf, 0, sizeof(struct tsn_cb_streamid)); |
| 2163 | + memset(&sidcounts, 0, sizeof(struct tsn_cb_streamid_counters)); |
| 2164 | + |
| 2165 | + if (!info->attrs[TSN_ATTR_STREAM_IDENTIFY]) |
| 2166 | + return -EINVAL; |
| 2167 | + |
| 2168 | + na = info->attrs[TSN_ATTR_STREAM_IDENTIFY]; |
| 2169 | + |
| 2170 | + ret = NLA_PARSE_NESTED(sid, TSN_STREAMID_ATTR_MAX, |
| 2171 | + na, cb_streamid_policy); |
| 2172 | + if (ret) |
| 2173 | + return -EINVAL; |
| 2174 | + |
| 2175 | + if (!sid[TSN_STREAMID_ATTR_INDEX]) |
| 2176 | + return -EINVAL; |
| 2177 | + |
| 2178 | + sid_index = nla_get_u32(sid[TSN_STREAMID_ATTR_INDEX]); |
| 2179 | + |
| 2180 | + if (!tsnops->cb_streamid_get) { |
| 2181 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2182 | + netdev->name, -EPERM); |
| 2183 | + ret = -EINVAL; |
| 2184 | + goto exit; |
| 2185 | + } else { |
| 2186 | + valid = tsnops->cb_streamid_get(netdev, sid_index, &sidconf); |
| 2187 | + if (valid < 0) { |
| 2188 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2189 | + netdev->name, valid); |
| 2190 | + return valid; |
| 2191 | + } |
| 2192 | + } |
| 2193 | + |
| 2194 | + /* send back */ |
| 2195 | + genlhdr = info->genlhdr; |
| 2196 | + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb, |
| 2197 | + NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 2198 | + if (ret < 0) |
| 2199 | + return ret; |
| 2200 | + |
| 2201 | + /* input netlink the parameters */ |
| 2202 | + sidattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_STREAM_IDENTIFY); |
| 2203 | + if (!sidattr) { |
| 2204 | + ret = -EINVAL; |
| 2205 | + goto err; |
| 2206 | + } |
| 2207 | + |
| 2208 | + if (nla_put_u32(rep_skb, TSN_STREAMID_ATTR_INDEX, sid_index)) |
| 2209 | + return -EMSGSIZE; |
| 2210 | + |
| 2211 | + if (valid == 1) { |
| 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); |
| 2215 | + } else { |
| 2216 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2217 | + netdev->name, -EINVAL); |
| 2218 | + goto err; |
| 2219 | + } |
| 2220 | + |
| 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)) |
| 2228 | + return -EMSGSIZE; |
| 2229 | + |
| 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)) |
| 2238 | + return -EMSGSIZE; |
| 2239 | + break; |
| 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)) |
| 2247 | + return -EMSGSIZE; |
| 2248 | + break; |
| 2249 | + case STREAMID_DMAC_VLAN: |
| 2250 | + case STREAMID_IP: |
| 2251 | + default: |
| 2252 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2253 | + netdev->name, -EINVAL); |
| 2254 | + goto err; |
| 2255 | + } |
| 2256 | + |
| 2257 | + if (!tsnops->cb_streamid_counters_get) { |
| 2258 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2259 | + netdev->name, -EPERM); |
| 2260 | + goto err; |
| 2261 | + } else { |
| 2262 | + ret = tsnops->cb_streamid_counters_get(netdev, |
| 2263 | + sid_index, |
| 2264 | + &sidcounts); |
| 2265 | + if (ret < 0) { |
| 2266 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2267 | + netdev->name, ret); |
| 2268 | + goto err; |
| 2269 | + } |
| 2270 | + } |
| 2271 | + |
| 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)) |
| 2276 | + return -EMSGSIZE; |
| 2277 | + |
| 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)) |
| 2283 | + return -EMSGSIZE; |
| 2284 | + } |
| 2285 | + |
| 2286 | + nla_nest_end(rep_skb, sidattr); |
| 2287 | + /* end netlink input the parameters */ |
| 2288 | + |
| 2289 | + /* netlink lib func */ |
| 2290 | + ret = nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name); |
| 2291 | + if (ret < 0) |
| 2292 | + goto err; |
| 2293 | + |
| 2294 | + ret = nla_put_s32(rep_skb, TSN_CMD_ATTR_DATA, 0); |
| 2295 | + if (ret < 0) |
| 2296 | + goto err; |
| 2297 | + |
| 2298 | + return tsn_send_reply(rep_skb, info); |
| 2299 | + |
| 2300 | +err: |
| 2301 | + nlmsg_free(rep_skb); |
| 2302 | +exit: |
| 2303 | + return ret; |
| 2304 | +} |
| 2305 | + |
| 2306 | +static int tsn_cb_streamid_get(struct sk_buff *skb, struct genl_info *info) |
| 2307 | +{ |
| 2308 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 2309 | + cmd_cb_streamid_get(info); |
| 2310 | + return 0; |
| 2311 | + } |
| 2312 | + |
| 2313 | + return -1; |
| 2314 | +} |
| 2315 | + |
| 2316 | +static int cmb_cb_streamid_counters_get(struct genl_info *info) |
| 2317 | +{ |
| 2318 | + return 0; |
| 2319 | +} |
| 2320 | + |
| 2321 | +static int tsn_cb_streamid_counters_get(struct sk_buff *skb, |
| 2322 | + struct genl_info *info) |
| 2323 | +{ |
| 2324 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 2325 | + cmb_cb_streamid_counters_get(info); |
| 2326 | + return 0; |
| 2327 | + } |
| 2328 | + |
| 2329 | + return -1; |
| 2330 | +} |
| 2331 | + |
| 2332 | +static int tsn_qci_cap_get(struct sk_buff *skb, struct genl_info *info) |
| 2333 | +{ |
| 2334 | + struct nlattr *qci_cap; |
| 2335 | + struct sk_buff *rep_skb; |
| 2336 | + int ret; |
| 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; |
| 2342 | + |
| 2343 | + port = tsn_init_check(info, &netdev); |
| 2344 | + if (!port) { |
| 2345 | + ret = -EINVAL; |
| 2346 | + goto out; |
| 2347 | + } |
| 2348 | + |
| 2349 | + tsnops = port->tsnops; |
| 2350 | + |
| 2351 | + genlhdr = info->genlhdr; |
| 2352 | + |
| 2353 | + memset(&qci_cap_status, 0, sizeof(qci_cap_status)); |
| 2354 | + |
| 2355 | + if (!tsnops->qci_get_maxcap) { |
| 2356 | + ret = -EOPNOTSUPP; |
| 2357 | + goto out; |
| 2358 | + } |
| 2359 | + |
| 2360 | + ret = tsnops->qci_get_maxcap(netdev, &qci_cap_status); |
| 2361 | + if (ret < 0) |
| 2362 | + goto out; |
| 2363 | + |
| 2364 | + /* Pad netlink reply data */ |
| 2365 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 2366 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 2367 | + if (ret < 0) |
| 2368 | + goto out; |
| 2369 | + |
| 2370 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) { |
| 2371 | + ret = -EMSGSIZE; |
| 2372 | + goto err; |
| 2373 | + } |
| 2374 | + |
| 2375 | + qci_cap = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SP); |
| 2376 | + if (!qci_cap) { |
| 2377 | + ret = -EMSGSIZE; |
| 2378 | + goto err; |
| 2379 | + } |
| 2380 | + |
| 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)) { |
| 2389 | + ret = -EMSGSIZE; |
| 2390 | + goto err; |
| 2391 | + } |
| 2392 | + |
| 2393 | + nla_nest_end(rep_skb, qci_cap); |
| 2394 | + |
| 2395 | + tsn_send_reply(rep_skb, info); |
| 2396 | + |
| 2397 | + return 0; |
| 2398 | +err: |
| 2399 | + nlmsg_free(rep_skb); |
| 2400 | +out: |
| 2401 | + if (ret < 0) |
| 2402 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 2403 | + |
| 2404 | + return ret; |
| 2405 | +} |
| 2406 | + |
| 2407 | +static int cmd_qci_sfi_set(struct genl_info *info) |
| 2408 | +{ |
| 2409 | + struct nlattr *na, *sfi[TSN_QCI_SFI_ATTR_MAX + 1]; |
| 2410 | + u32 sfi_handle; |
| 2411 | + bool enable; |
| 2412 | + int ret; |
| 2413 | + struct net_device *netdev; |
| 2414 | + struct tsn_qci_psfp_sfi_conf sficonf; |
| 2415 | + const struct tsn_ops *tsnops; |
| 2416 | + struct tsn_port *port; |
| 2417 | + |
| 2418 | + port = tsn_init_check(info, &netdev); |
| 2419 | + if (!port) |
| 2420 | + return -ENODEV; |
| 2421 | + |
| 2422 | + tsnops = port->tsnops; |
| 2423 | + |
| 2424 | + memset(&sficonf, 0, sizeof(struct tsn_qci_psfp_sfi_conf)); |
| 2425 | + |
| 2426 | + if (!info->attrs[TSN_ATTR_QCI_SFI]) |
| 2427 | + return -EINVAL; |
| 2428 | + |
| 2429 | + na = info->attrs[TSN_ATTR_QCI_SFI]; |
| 2430 | + |
| 2431 | + ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX, na, qci_sfi_policy); |
| 2432 | + if (ret) { |
| 2433 | + pr_info("tsn: parse value TSN_QCI_SFI_ATTR_MAX error."); |
| 2434 | + return -EINVAL; |
| 2435 | + } |
| 2436 | + |
| 2437 | + if (!sfi[TSN_QCI_SFI_ATTR_INDEX]) |
| 2438 | + return -EINVAL; |
| 2439 | + |
| 2440 | + sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]); |
| 2441 | + |
| 2442 | + if (sfi[TSN_QCI_SFI_ATTR_ENABLE]) { |
| 2443 | + enable = true; |
| 2444 | + } else if (sfi[TSN_QCI_SFI_ATTR_DISABLE]) { |
| 2445 | + enable = false; |
| 2446 | + goto loaddrive; |
| 2447 | + } else { |
| 2448 | + pr_err("tsn: must provde ENABLE or DISABLE attribute.\n"); |
| 2449 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2450 | + netdev->name, -EINVAL); |
| 2451 | + return -EINVAL; |
| 2452 | + } |
| 2453 | + |
| 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); |
| 2458 | + return -EINVAL; |
| 2459 | + } |
| 2460 | + |
| 2461 | + if (!sfi[TSN_QCI_SFI_ATTR_STREAM_HANDLE]) |
| 2462 | + sficonf.stream_handle_spec = -1; |
| 2463 | + else |
| 2464 | + sficonf.stream_handle_spec = |
| 2465 | + nla_get_s32(sfi[TSN_QCI_SFI_ATTR_STREAM_HANDLE]); |
| 2466 | + |
| 2467 | + if (!sfi[TSN_QCI_SFI_ATTR_PRIO_SPEC]) |
| 2468 | + sficonf.priority_spec = -1; |
| 2469 | + else |
| 2470 | + sficonf.priority_spec = |
| 2471 | + nla_get_s8(sfi[TSN_QCI_SFI_ATTR_PRIO_SPEC]); |
| 2472 | + |
| 2473 | + sficonf.stream_gate_instance_id = |
| 2474 | + nla_get_u32(sfi[TSN_QCI_SFI_ATTR_GATE_ID]); |
| 2475 | + |
| 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]); |
| 2479 | + else |
| 2480 | + sficonf.stream_filter.maximum_sdu_size = 0; |
| 2481 | + |
| 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]); |
| 2485 | + else |
| 2486 | + sficonf.stream_filter.flow_meter_instance_id = -1; |
| 2487 | + |
| 2488 | + if (sfi[TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE]) |
| 2489 | + sficonf.block_oversize_enable = true; |
| 2490 | + |
| 2491 | + if (sfi[TSN_QCI_SFI_ATTR_OVERSIZE]) |
| 2492 | + sficonf.block_oversize = true; |
| 2493 | + |
| 2494 | +loaddrive: |
| 2495 | + if (!tsnops->qci_sfi_set) { |
| 2496 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2497 | + netdev->name, -EPERM); |
| 2498 | + return -EINVAL; |
| 2499 | + } |
| 2500 | + |
| 2501 | + ret = tsnops->qci_sfi_set(netdev, sfi_handle, enable, &sficonf); |
| 2502 | + if (ret < 0) { |
| 2503 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 2504 | + return ret; |
| 2505 | + } |
| 2506 | + |
| 2507 | + ret = tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0); |
| 2508 | + |
| 2509 | + if (ret) |
| 2510 | + return ret; |
| 2511 | + return 0; |
| 2512 | +} |
| 2513 | + |
| 2514 | +static int tsn_qci_sfi_set(struct sk_buff *skb, struct genl_info *info) |
| 2515 | +{ |
| 2516 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 2517 | + cmd_qci_sfi_set(info); |
| 2518 | + return 0; |
| 2519 | + } |
| 2520 | + |
| 2521 | + return -1; |
| 2522 | +} |
| 2523 | + |
| 2524 | +static int cmd_qci_sfi_get(struct genl_info *info) |
| 2525 | +{ |
| 2526 | + struct nlattr *na, *sfiattr; |
| 2527 | + struct nlattr *sfi[TSN_QCI_SFI_ATTR_MAX + 1]; |
| 2528 | + u32 sfi_handle; |
| 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; |
| 2537 | + |
| 2538 | + port = tsn_init_check(info, &netdev); |
| 2539 | + if (!port) |
| 2540 | + return -ENODEV; |
| 2541 | + |
| 2542 | + tsnops = port->tsnops; |
| 2543 | + |
| 2544 | + genlhdr = info->genlhdr; |
| 2545 | + |
| 2546 | + if (!info->attrs[TSN_ATTR_QCI_SFI]) |
| 2547 | + return -EINVAL; |
| 2548 | + |
| 2549 | + na = info->attrs[TSN_ATTR_QCI_SFI]; |
| 2550 | + |
| 2551 | + ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX, |
| 2552 | + na, qci_sfi_policy); |
| 2553 | + if (ret) |
| 2554 | + return -EINVAL; |
| 2555 | + |
| 2556 | + if (!sfi[TSN_QCI_SFI_ATTR_INDEX]) |
| 2557 | + return -EINVAL; |
| 2558 | + |
| 2559 | + sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]); |
| 2560 | + |
| 2561 | + memset(&sficonf, 0, sizeof(struct tsn_qci_psfp_sfi_conf)); |
| 2562 | + memset(&sficount, 0, sizeof(struct tsn_qci_psfp_sfi_counters)); |
| 2563 | + |
| 2564 | + if (!tsnops->qci_sfi_get || !tsnops->qci_sfi_counters_get) { |
| 2565 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2566 | + netdev->name, -EPERM); |
| 2567 | + ret = -EINVAL; |
| 2568 | + goto exit; |
| 2569 | + } else { |
| 2570 | + valid = tsnops->qci_sfi_get(netdev, sfi_handle, &sficonf); |
| 2571 | + if (valid < 0) { |
| 2572 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2573 | + netdev->name, valid); |
| 2574 | + return valid; |
| 2575 | + } |
| 2576 | + |
| 2577 | + valid = tsnops->qci_sfi_counters_get(netdev, sfi_handle, |
| 2578 | + &sficount); |
| 2579 | + if (valid < 0) { |
| 2580 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2581 | + netdev->name, valid); |
| 2582 | + return valid; |
| 2583 | + } |
| 2584 | + } |
| 2585 | + |
| 2586 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 2587 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 2588 | + if (ret < 0) |
| 2589 | + return ret; |
| 2590 | + |
| 2591 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 2592 | + goto err; |
| 2593 | + |
| 2594 | + sfiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SFI); |
| 2595 | + if (!sfiattr) { |
| 2596 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2597 | + netdev->name, -EINVAL); |
| 2598 | + ret = -EINVAL; |
| 2599 | + goto err; |
| 2600 | + } |
| 2601 | + |
| 2602 | + if (nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_INDEX, sfi_handle)) |
| 2603 | + return -EMSGSIZE; |
| 2604 | + |
| 2605 | + if (valid) { |
| 2606 | + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_ENABLE)) |
| 2607 | + return -EMSGSIZE; |
| 2608 | + } else { |
| 2609 | + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_DISABLE)) |
| 2610 | + return -EMSGSIZE; |
| 2611 | + } |
| 2612 | + |
| 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)) |
| 2619 | + return -EMSGSIZE; |
| 2620 | + |
| 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)) |
| 2624 | + return -EMSGSIZE; |
| 2625 | + |
| 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)) |
| 2629 | + return -EMSGSIZE; |
| 2630 | + |
| 2631 | + if (sficonf.block_oversize_enable) |
| 2632 | + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_OVERSIZE_ENABLE)) |
| 2633 | + return -EMSGSIZE; |
| 2634 | + if (sficonf.block_oversize) |
| 2635 | + if (nla_put_flag(rep_skb, TSN_QCI_SFI_ATTR_OVERSIZE)) |
| 2636 | + return -EMSGSIZE; |
| 2637 | + |
| 2638 | + if (nla_put(rep_skb, TSN_QCI_SFI_ATTR_COUNTERS, |
| 2639 | + sizeof(struct tsn_qci_psfp_sfi_counters), &sficount)) |
| 2640 | + return -EMSGSIZE; |
| 2641 | + |
| 2642 | + nla_nest_end(rep_skb, sfiattr); |
| 2643 | + |
| 2644 | + return tsn_send_reply(rep_skb, info); |
| 2645 | +err: |
| 2646 | + nlmsg_free(rep_skb); |
| 2647 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2648 | + netdev->name, -EINVAL); |
| 2649 | +exit: |
| 2650 | + return ret; |
| 2651 | +} |
| 2652 | + |
| 2653 | +static int tsn_qci_sfi_get(struct sk_buff *skb, struct genl_info *info) |
| 2654 | +{ |
| 2655 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 2656 | + cmd_qci_sfi_get(info); |
| 2657 | + return 0; |
| 2658 | + } |
| 2659 | + |
| 2660 | + return -1; |
| 2661 | +} |
| 2662 | + |
| 2663 | +static int cmd_qci_sfi_counters_get(struct genl_info *info) |
| 2664 | +{ |
| 2665 | + struct nlattr *na, *sfiattr; |
| 2666 | + struct nlattr *sfi[TSN_QCI_SFI_ATTR_MAX + 1]; |
| 2667 | + u32 sfi_handle; |
| 2668 | + struct sk_buff *rep_skb; |
| 2669 | + int ret; |
| 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; |
| 2675 | + |
| 2676 | + port = tsn_init_check(info, &netdev); |
| 2677 | + if (!port) |
| 2678 | + return -ENODEV; |
| 2679 | + |
| 2680 | + tsnops = port->tsnops; |
| 2681 | + |
| 2682 | + genlhdr = info->genlhdr; |
| 2683 | + |
| 2684 | + if (!info->attrs[TSN_ATTR_QCI_SFI]) |
| 2685 | + return -EINVAL; |
| 2686 | + |
| 2687 | + na = info->attrs[TSN_ATTR_QCI_SFI]; |
| 2688 | + |
| 2689 | + ret = NLA_PARSE_NESTED(sfi, TSN_QCI_SFI_ATTR_MAX, |
| 2690 | + na, qci_sfi_policy); |
| 2691 | + if (ret) |
| 2692 | + return -EINVAL; |
| 2693 | + |
| 2694 | + if (!sfi[TSN_QCI_SFI_ATTR_INDEX]) |
| 2695 | + return -EINVAL; |
| 2696 | + |
| 2697 | + sfi_handle = nla_get_u32(sfi[TSN_QCI_SFI_ATTR_INDEX]); |
| 2698 | + |
| 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); |
| 2703 | + return -1; |
| 2704 | + } |
| 2705 | + |
| 2706 | + ret = tsnops->qci_sfi_counters_get(netdev, sfi_handle, &sficount); |
| 2707 | + if (ret < 0) { |
| 2708 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2709 | + netdev->name, ret); |
| 2710 | + return ret; |
| 2711 | + } |
| 2712 | + |
| 2713 | + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb, |
| 2714 | + NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 2715 | + if (ret < 0) |
| 2716 | + return ret; |
| 2717 | + |
| 2718 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 2719 | + goto err; |
| 2720 | + |
| 2721 | + sfiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SFI); |
| 2722 | + if (!sfiattr) { |
| 2723 | + ret = -EINVAL; |
| 2724 | + goto err; |
| 2725 | + } |
| 2726 | + |
| 2727 | + if (nla_put_u32(rep_skb, TSN_QCI_SFI_ATTR_INDEX, sfi_handle)) |
| 2728 | + return -EMSGSIZE; |
| 2729 | + |
| 2730 | + ret = tsnops->qci_sfi_counters_get(netdev, sfi_handle, &sficount); |
| 2731 | + if (ret < 0) { |
| 2732 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 2733 | + return ret; |
| 2734 | + } |
| 2735 | + |
| 2736 | + if (nla_put(rep_skb, TSN_QCI_SFI_ATTR_COUNTERS, |
| 2737 | + sizeof(struct tsn_qci_psfp_sfi_counters), &sficount)) |
| 2738 | + return -EMSGSIZE; |
| 2739 | + |
| 2740 | + nla_nest_end(rep_skb, sfiattr); |
| 2741 | + |
| 2742 | + return tsn_send_reply(rep_skb, info); |
| 2743 | +err: |
| 2744 | + nlmsg_free(rep_skb); |
| 2745 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, -EINVAL); |
| 2746 | + return ret; |
| 2747 | +} |
| 2748 | + |
| 2749 | +static int tsn_qci_sfi_counters_get(struct sk_buff *skb, struct genl_info *info) |
| 2750 | +{ |
| 2751 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 2752 | + cmd_qci_sfi_counters_get(info); |
| 2753 | + return 0; |
| 2754 | + } |
| 2755 | + |
| 2756 | + return -1; |
| 2757 | +} |
| 2758 | + |
| 2759 | +static int cmd_qci_sgi_set(struct genl_info *info) |
| 2760 | +{ |
| 2761 | + struct nlattr *na; |
| 2762 | + struct nlattr *sgia[TSN_QCI_SGI_ATTR_MAX + 1]; |
| 2763 | + struct nlattr *admin[TSN_SGI_ATTR_CTRL_MAX + 1]; |
| 2764 | + int ret = 0; |
| 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; |
| 2772 | + |
| 2773 | + port = tsn_init_check(info, &netdev); |
| 2774 | + if (!port) |
| 2775 | + return -ENODEV; |
| 2776 | + |
| 2777 | + tsnops = port->tsnops; |
| 2778 | + |
| 2779 | + memset(&sgi, 0, sizeof(struct tsn_qci_psfp_sgi_conf)); |
| 2780 | + |
| 2781 | + if (!info->attrs[TSN_ATTR_QCI_SGI]) { |
| 2782 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2783 | + netdev->name, -EINVAL); |
| 2784 | + return -EINVAL; |
| 2785 | + } |
| 2786 | + |
| 2787 | + na = info->attrs[TSN_ATTR_QCI_SGI]; |
| 2788 | + |
| 2789 | + ret = NLA_PARSE_NESTED(sgia, TSN_QCI_SGI_ATTR_MAX, |
| 2790 | + na, qci_sgi_policy); |
| 2791 | + if (ret) { |
| 2792 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2793 | + netdev->name, -EINVAL); |
| 2794 | + return -EINVAL; |
| 2795 | + } |
| 2796 | + |
| 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); |
| 2801 | + return -1; |
| 2802 | + } |
| 2803 | + |
| 2804 | + if (sgia[TSN_QCI_SGI_ATTR_INDEX]) |
| 2805 | + sgi_handle = nla_get_u32(sgia[TSN_QCI_SGI_ATTR_INDEX]); |
| 2806 | + |
| 2807 | + if (sgia[TSN_QCI_SGI_ATTR_DISABLE]) { |
| 2808 | + sgi.gate_enabled = 0; |
| 2809 | + goto loaddev; |
| 2810 | + } else { |
| 2811 | + /* set default to be enable*/ |
| 2812 | + sgi.gate_enabled = 1; |
| 2813 | + } |
| 2814 | + |
| 2815 | + if (sgia[TSN_QCI_SGI_ATTR_CONFCHANGE]) |
| 2816 | + sgi.config_change = 1; |
| 2817 | + |
| 2818 | + if (sgia[TSN_QCI_SGI_ATTR_IRXEN]) |
| 2819 | + sgi.block_invalid_rx_enable = 1; |
| 2820 | + |
| 2821 | + if (sgia[TSN_QCI_SGI_ATTR_IRX]) |
| 2822 | + sgi.block_invalid_rx = 1; |
| 2823 | + |
| 2824 | + if (sgia[TSN_QCI_SGI_ATTR_OEXEN]) |
| 2825 | + sgi.block_octets_exceeded_enable = 1; |
| 2826 | + |
| 2827 | + if (sgia[TSN_QCI_SGI_ATTR_OEX]) |
| 2828 | + sgi.block_octets_exceeded = 1; |
| 2829 | + |
| 2830 | + if (sgia[TSN_QCI_SGI_ATTR_ADMINENTRY]) { |
| 2831 | + struct nlattr *entry; |
| 2832 | + int rem; |
| 2833 | + int count = 0; |
| 2834 | + |
| 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); |
| 2838 | + |
| 2839 | + /* Other parameters in admin control */ |
| 2840 | + if (admin[TSN_SGI_ATTR_CTRL_INITSTATE]) |
| 2841 | + sgi.admin.gate_states = 1; |
| 2842 | + |
| 2843 | + if (admin[TSN_SGI_ATTR_CTRL_CYTIME]) |
| 2844 | + sgi.admin.cycle_time = |
| 2845 | + nla_get_u32(admin[TSN_SGI_ATTR_CTRL_CYTIME]); |
| 2846 | + |
| 2847 | + if (admin[TSN_SGI_ATTR_CTRL_CYTIMEEX]) |
| 2848 | + sgi.admin.cycle_time_extension = |
| 2849 | + nla_get_u32(admin[TSN_SGI_ATTR_CTRL_CYTIMEEX]); |
| 2850 | + |
| 2851 | + if (admin[TSN_SGI_ATTR_CTRL_BTIME]) |
| 2852 | + sgi.admin.base_time = |
| 2853 | + nla_get_u64(admin[TSN_SGI_ATTR_CTRL_BTIME]); |
| 2854 | + |
| 2855 | + if (admin[TSN_SGI_ATTR_CTRL_INITIPV]) |
| 2856 | + sgi.admin.init_ipv = |
| 2857 | + nla_get_s8(admin[TSN_SGI_ATTR_CTRL_INITIPV]); |
| 2858 | + else |
| 2859 | + sgi.admin.init_ipv = -1; |
| 2860 | + |
| 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; |
| 2865 | + } |
| 2866 | + |
| 2867 | + if (!listcount) |
| 2868 | + goto loaddev; |
| 2869 | + |
| 2870 | + gcl = kmalloc_array(listcount, sizeof(*gcl), GFP_KERNEL); |
| 2871 | + |
| 2872 | + memset(gcl, 0, listcount * sizeof(struct tsn_qci_psfp_gcl)); |
| 2873 | + |
| 2874 | + /* Check the whole admin attrs, |
| 2875 | + * checkout the TSN_SGI_ATTR_CTRL_GCLENTRY attributes |
| 2876 | + */ |
| 2877 | + nla_for_each_nested(entry, na, rem) { |
| 2878 | + struct nlattr *gcl_entry[TSN_SGI_ATTR_GCL_MAX + 1]; |
| 2879 | + struct nlattr *ti, *om; |
| 2880 | + |
| 2881 | + if (nla_type(entry) != TSN_SGI_ATTR_CTRL_GCLENTRY) |
| 2882 | + continue; |
| 2883 | + |
| 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; |
| 2890 | + |
| 2891 | + if (gcl_entry[TSN_SGI_ATTR_GCL_IPV]) |
| 2892 | + (gcl + count)->ipv = |
| 2893 | + nla_get_s8(gcl_entry[TSN_SGI_ATTR_GCL_IPV]); |
| 2894 | + |
| 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); |
| 2898 | + } |
| 2899 | + |
| 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); |
| 2903 | + } |
| 2904 | + |
| 2905 | + count++; |
| 2906 | + |
| 2907 | + if (count >= listcount) |
| 2908 | + break; |
| 2909 | + } |
| 2910 | + |
| 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"); |
| 2915 | + kfree(gcl); |
| 2916 | + return -EINVAL; |
| 2917 | + } |
| 2918 | + |
| 2919 | + } else { |
| 2920 | + pr_info("tsn: no admin list parameters setting\n"); |
| 2921 | + } |
| 2922 | + |
| 2923 | +loaddev: |
| 2924 | + if (!tsnops->qci_sgi_set) { |
| 2925 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2926 | + netdev->name, -EPERM); |
| 2927 | + kfree(gcl); |
| 2928 | + return -EINVAL; |
| 2929 | + } |
| 2930 | + |
| 2931 | + sgi.admin.gcl = gcl; |
| 2932 | + |
| 2933 | + ret = tsnops->qci_sgi_set(netdev, sgi_handle, &sgi); |
| 2934 | + kfree(gcl); |
| 2935 | + if (!ret) |
| 2936 | + return tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2937 | + netdev->name, 0); |
| 2938 | + |
| 2939 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 2940 | + netdev->name, ret); |
| 2941 | + return ret; |
| 2942 | +} |
| 2943 | + |
| 2944 | +static int tsn_qci_sgi_set(struct sk_buff *skb, struct genl_info *info) |
| 2945 | +{ |
| 2946 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 2947 | + cmd_qci_sgi_set(info); |
| 2948 | + return 0; |
| 2949 | + } |
| 2950 | + |
| 2951 | + return -1; |
| 2952 | +} |
| 2953 | + |
| 2954 | +static int cmd_qci_sgi_get(struct genl_info *info) |
| 2955 | +{ |
| 2956 | + struct nlattr *na, *sgiattr, *adminattr, *sglattr; |
| 2957 | + struct nlattr *sgi[TSN_QCI_SGI_ATTR_MAX + 1]; |
| 2958 | + struct sk_buff *rep_skb; |
| 2959 | + int ret; |
| 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; |
| 2965 | + u16 sgi_handle; |
| 2966 | + u8 listcount, i; |
| 2967 | + struct tsn_port *port; |
| 2968 | + |
| 2969 | + port = tsn_init_check(info, &netdev); |
| 2970 | + if (!port) |
| 2971 | + return -ENODEV; |
| 2972 | + |
| 2973 | + tsnops = port->tsnops; |
| 2974 | + |
| 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"); |
| 2979 | + return -EINVAL; |
| 2980 | + } |
| 2981 | + |
| 2982 | + na = info->attrs[TSN_ATTR_QCI_SGI]; |
| 2983 | + |
| 2984 | + ret = NLA_PARSE_NESTED(sgi, TSN_QCI_SGI_ATTR_MAX, |
| 2985 | + na, qci_sgi_policy); |
| 2986 | + if (ret) |
| 2987 | + return -EINVAL; |
| 2988 | + |
| 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"); |
| 2993 | + return -EINVAL; |
| 2994 | + } |
| 2995 | + |
| 2996 | + sgi_handle = nla_get_u32(sgi[TSN_QCI_SGI_ATTR_INDEX]); |
| 2997 | + |
| 2998 | + /* Get config data from device */ |
| 2999 | + genlhdr = info->genlhdr; |
| 3000 | + |
| 3001 | + memset(&sgiadmin, 0, sizeof(struct tsn_qci_psfp_sgi_conf)); |
| 3002 | + |
| 3003 | + if (!tsnops->qci_sgi_get) { |
| 3004 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3005 | + netdev->name, -EPERM); |
| 3006 | + return -1; |
| 3007 | + } |
| 3008 | + |
| 3009 | + ret = tsnops->qci_sgi_get(netdev, sgi_handle, &sgiadmin); |
| 3010 | + if (ret < 0) { |
| 3011 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3012 | + netdev->name, ret); |
| 3013 | + return ret; |
| 3014 | + } |
| 3015 | + |
| 3016 | + /* Form netlink reply data */ |
| 3017 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 3018 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 3019 | + if (ret < 0) |
| 3020 | + return ret; |
| 3021 | + |
| 3022 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 3023 | + return -EMSGSIZE; |
| 3024 | + |
| 3025 | + sgiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SGI); |
| 3026 | + if (!sgiattr) |
| 3027 | + return -EMSGSIZE; |
| 3028 | + |
| 3029 | + if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_INDEX, sgi_handle)) |
| 3030 | + return -EMSGSIZE; |
| 3031 | + |
| 3032 | + /* Gate enable? sgiadmin.gate_enabled */ |
| 3033 | + if (sgiadmin.gate_enabled) { |
| 3034 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_ENABLE)) |
| 3035 | + return -EMSGSIZE; |
| 3036 | + } else { |
| 3037 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_DISABLE)) |
| 3038 | + return -EMSGSIZE; |
| 3039 | + } |
| 3040 | + |
| 3041 | + if (sgiadmin.config_change) |
| 3042 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_CONFCHANGE)) |
| 3043 | + return -EMSGSIZE; |
| 3044 | + |
| 3045 | + if (sgiadmin.block_invalid_rx_enable) |
| 3046 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_IRXEN)) |
| 3047 | + return -EMSGSIZE; |
| 3048 | + |
| 3049 | + if (sgiadmin.block_invalid_rx) |
| 3050 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_IRX)) |
| 3051 | + return -EMSGSIZE; |
| 3052 | + |
| 3053 | + if (sgiadmin.block_octets_exceeded_enable) |
| 3054 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_OEXEN)) |
| 3055 | + return -EMSGSIZE; |
| 3056 | + |
| 3057 | + if (sgiadmin.block_octets_exceeded) |
| 3058 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_OEX)) |
| 3059 | + return -EMSGSIZE; |
| 3060 | + |
| 3061 | + /* Administration */ |
| 3062 | + adminattr = nla_nest_start_noflag(rep_skb, TSN_QCI_SGI_ATTR_ADMINENTRY); |
| 3063 | + if (!adminattr) |
| 3064 | + return -EMSGSIZE; |
| 3065 | + |
| 3066 | + if (sgiadmin.admin.gate_states) |
| 3067 | + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_CTRL_INITSTATE)) |
| 3068 | + return -EMSGSIZE; |
| 3069 | + |
| 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)) |
| 3078 | + return -EMSGSIZE; |
| 3079 | + |
| 3080 | + listcount = sgiadmin.admin.control_list_length; |
| 3081 | + if (!listcount) |
| 3082 | + goto out1; |
| 3083 | + |
| 3084 | + if (!sgiadmin.admin.gcl) { |
| 3085 | + pr_err("error: no gate control list\n"); |
| 3086 | + ret = -EINVAL; |
| 3087 | + goto err; |
| 3088 | + } |
| 3089 | + |
| 3090 | + gcl = sgiadmin.admin.gcl; |
| 3091 | + |
| 3092 | + /* loop list */ |
| 3093 | + for (i = 0; i < listcount; i++) { |
| 3094 | + s8 ipv; |
| 3095 | + u32 ti, omax; |
| 3096 | + |
| 3097 | + if (!(gcl + i)) { |
| 3098 | + pr_err("error: list count too big\n"); |
| 3099 | + ret = -EINVAL; |
| 3100 | + kfree(sgiadmin.admin.gcl); |
| 3101 | + goto err; |
| 3102 | + } |
| 3103 | + |
| 3104 | + /* Adminastration entry */ |
| 3105 | + sglattr = nla_nest_start_noflag(rep_skb, |
| 3106 | + TSN_SGI_ATTR_CTRL_GCLENTRY); |
| 3107 | + if (!sglattr) |
| 3108 | + return -EMSGSIZE; |
| 3109 | + ipv = (gcl + i)->ipv; |
| 3110 | + ti = (gcl + i)->time_interval; |
| 3111 | + omax = (gcl + i)->octet_max; |
| 3112 | + |
| 3113 | + if ((gcl + i)->gate_state) |
| 3114 | + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_GCL_GATESTATE)) |
| 3115 | + return -EMSGSIZE; |
| 3116 | + |
| 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)) |
| 3120 | + return -EMSGSIZE; |
| 3121 | + |
| 3122 | + /* End administration entry */ |
| 3123 | + nla_nest_end(rep_skb, sglattr); |
| 3124 | + } |
| 3125 | + |
| 3126 | + kfree(sgiadmin.admin.gcl); |
| 3127 | + if (nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_LEN, listcount)) |
| 3128 | + return -EMSGSIZE; |
| 3129 | + |
| 3130 | +out1: |
| 3131 | + /* End adminastration */ |
| 3132 | + nla_nest_end(rep_skb, adminattr); |
| 3133 | + |
| 3134 | + nla_nest_end(rep_skb, sgiattr); |
| 3135 | + |
| 3136 | + return tsn_send_reply(rep_skb, info); |
| 3137 | +err: |
| 3138 | + nlmsg_free(rep_skb); |
| 3139 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 3140 | + return ret; |
| 3141 | +} |
| 3142 | + |
| 3143 | +static int tsn_qci_sgi_get(struct sk_buff *skb, struct genl_info *info) |
| 3144 | +{ |
| 3145 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 3146 | + cmd_qci_sgi_get(info); |
| 3147 | + return 0; |
| 3148 | + } |
| 3149 | + |
| 3150 | + return -1; |
| 3151 | +} |
| 3152 | + |
| 3153 | +static int cmd_qci_sgi_status_get(struct genl_info *info) |
| 3154 | +{ |
| 3155 | + struct nlattr *na, *sgiattr, *operattr, *sglattr; |
| 3156 | + struct nlattr *sgi[TSN_QCI_SGI_ATTR_MAX + 1]; |
| 3157 | + struct sk_buff *rep_skb; |
| 3158 | + int ret; |
| 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; |
| 3164 | + u16 sgi_handle; |
| 3165 | + u8 listcount; |
| 3166 | + int valid, i; |
| 3167 | + struct tsn_port *port; |
| 3168 | + |
| 3169 | + port = tsn_init_check(info, &netdev); |
| 3170 | + if (!port) |
| 3171 | + return -ENODEV; |
| 3172 | + |
| 3173 | + tsnops = port->tsnops; |
| 3174 | + |
| 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"); |
| 3179 | + return -EINVAL; |
| 3180 | + } |
| 3181 | + |
| 3182 | + na = info->attrs[TSN_ATTR_QCI_SGI]; |
| 3183 | + |
| 3184 | + ret = NLA_PARSE_NESTED(sgi, TSN_QCI_SGI_ATTR_MAX, |
| 3185 | + na, qci_sgi_policy); |
| 3186 | + if (ret) |
| 3187 | + return -EINVAL; |
| 3188 | + |
| 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"); |
| 3193 | + return -EINVAL; |
| 3194 | + } |
| 3195 | + |
| 3196 | + sgi_handle = nla_get_u32(sgi[TSN_QCI_SGI_ATTR_INDEX]); |
| 3197 | + |
| 3198 | + /* Get status data from device */ |
| 3199 | + genlhdr = info->genlhdr; |
| 3200 | + |
| 3201 | + memset(&sgistat, 0, sizeof(struct tsn_psfp_sgi_status)); |
| 3202 | + |
| 3203 | + if (!tsnops->qci_sgi_status_get) { |
| 3204 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3205 | + netdev->name, -EPERM); |
| 3206 | + return -1; |
| 3207 | + } |
| 3208 | + |
| 3209 | + valid = tsnops->qci_sgi_status_get(netdev, sgi_handle, &sgistat); |
| 3210 | + if (valid < 0) { |
| 3211 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3212 | + netdev->name, valid); |
| 3213 | + return valid; |
| 3214 | + } |
| 3215 | + |
| 3216 | + /* Form netlink reply data */ |
| 3217 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 3218 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 3219 | + if (ret < 0) |
| 3220 | + return ret; |
| 3221 | + |
| 3222 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 3223 | + return -EMSGSIZE; |
| 3224 | + |
| 3225 | + /* Down one netlink attribute level */ |
| 3226 | + sgiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_SGI); |
| 3227 | + if (!sgiattr) |
| 3228 | + return -EMSGSIZE; |
| 3229 | + |
| 3230 | + if (nla_put_u32(rep_skb, TSN_QCI_SGI_ATTR_INDEX, sgi_handle)) |
| 3231 | + return -EMSGSIZE; |
| 3232 | + |
| 3233 | + /* Gate enable */ |
| 3234 | + if (valid == 1) { |
| 3235 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_ENABLE)) |
| 3236 | + return -EMSGSIZE; |
| 3237 | + } else { |
| 3238 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_DISABLE)) |
| 3239 | + return -EMSGSIZE; |
| 3240 | + } |
| 3241 | + |
| 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)) |
| 3250 | + return -EMSGSIZE; |
| 3251 | + |
| 3252 | + if (sgistat.config_pending) |
| 3253 | + if (nla_put_flag(rep_skb, TSN_QCI_SGI_ATTR_CPENDING)) |
| 3254 | + return -EMSGSIZE; |
| 3255 | + |
| 3256 | + /* operation data */ |
| 3257 | + operattr = nla_nest_start_noflag(rep_skb, TSN_QCI_SGI_ATTR_OPERENTRY); |
| 3258 | + if (!operattr) |
| 3259 | + return -EMSGSIZE; |
| 3260 | + |
| 3261 | + if (sgistat.oper.gate_states) |
| 3262 | + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_CTRL_INITSTATE)) |
| 3263 | + return -EMSGSIZE; |
| 3264 | + |
| 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)) |
| 3273 | + return -EMSGSIZE; |
| 3274 | + |
| 3275 | + /* Loop list */ |
| 3276 | + listcount = sgistat.oper.control_list_length; |
| 3277 | + if (!listcount) |
| 3278 | + goto out1; |
| 3279 | + |
| 3280 | + if (!sgistat.oper.gcl) { |
| 3281 | + pr_err("error: list lenghth is not zero!\n"); |
| 3282 | + ret = -EINVAL; |
| 3283 | + goto err; |
| 3284 | + } |
| 3285 | + |
| 3286 | + gcl = sgistat.oper.gcl; |
| 3287 | + |
| 3288 | + /* loop list */ |
| 3289 | + for (i = 0; i < listcount; i++) { |
| 3290 | + s8 ipv; |
| 3291 | + u32 ti, omax; |
| 3292 | + |
| 3293 | + if (!(gcl + i)) { |
| 3294 | + pr_err("error: list count too big\n"); |
| 3295 | + ret = -EINVAL; |
| 3296 | + kfree(sgistat.oper.gcl); |
| 3297 | + goto err; |
| 3298 | + } |
| 3299 | + |
| 3300 | + /* Operation entry */ |
| 3301 | + sglattr = nla_nest_start_noflag(rep_skb, |
| 3302 | + TSN_SGI_ATTR_CTRL_GCLENTRY); |
| 3303 | + if (!sglattr) |
| 3304 | + return -EMSGSIZE; |
| 3305 | + ipv = (gcl + i)->ipv; |
| 3306 | + ti = (gcl + i)->time_interval; |
| 3307 | + omax = (gcl + i)->octet_max; |
| 3308 | + |
| 3309 | + if ((gcl + i)->gate_state) |
| 3310 | + if (nla_put_flag(rep_skb, TSN_SGI_ATTR_GCL_GATESTATE)) |
| 3311 | + return -EMSGSIZE; |
| 3312 | + |
| 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)) |
| 3316 | + return -EMSGSIZE; |
| 3317 | + |
| 3318 | + /* End operation entry */ |
| 3319 | + nla_nest_end(rep_skb, sglattr); |
| 3320 | + } |
| 3321 | + |
| 3322 | + kfree(sgistat.oper.gcl); |
| 3323 | + if (nla_put_u8(rep_skb, TSN_SGI_ATTR_CTRL_LEN, listcount)) |
| 3324 | + return -EMSGSIZE; |
| 3325 | +out1: |
| 3326 | + /* End operation */ |
| 3327 | + nla_nest_end(rep_skb, operattr); |
| 3328 | + |
| 3329 | + nla_nest_end(rep_skb, sgiattr); |
| 3330 | + |
| 3331 | + return tsn_send_reply(rep_skb, info); |
| 3332 | +err: |
| 3333 | + nlmsg_free(rep_skb); |
| 3334 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 3335 | + return ret; |
| 3336 | +} |
| 3337 | + |
| 3338 | +static int tsn_qci_sgi_status_get(struct sk_buff *skb, struct genl_info *info) |
| 3339 | +{ |
| 3340 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 3341 | + cmd_qci_sgi_status_get(info); |
| 3342 | + return 0; |
| 3343 | + } |
| 3344 | + |
| 3345 | + return -1; |
| 3346 | +} |
| 3347 | + |
| 3348 | +static int cmd_qci_fmi_set(struct genl_info *info) |
| 3349 | +{ |
| 3350 | + struct nlattr *na, *fmi[TSN_QCI_FMI_ATTR_MAX + 1]; |
| 3351 | + u32 index; |
| 3352 | + int ret; |
| 3353 | + struct net_device *netdev; |
| 3354 | + struct tsn_qci_psfp_fmi fmiconf; |
| 3355 | + const struct tsn_ops *tsnops; |
| 3356 | + bool enable = 0; |
| 3357 | + struct tsn_port *port; |
| 3358 | + |
| 3359 | + port = tsn_init_check(info, &netdev); |
| 3360 | + if (!port) |
| 3361 | + return -ENODEV; |
| 3362 | + |
| 3363 | + tsnops = port->tsnops; |
| 3364 | + |
| 3365 | + memset(&fmiconf, 0, sizeof(struct tsn_qci_psfp_fmi)); |
| 3366 | + |
| 3367 | + if (!info->attrs[TSN_ATTR_QCI_FMI]) |
| 3368 | + return -EINVAL; |
| 3369 | + |
| 3370 | + na = info->attrs[TSN_ATTR_QCI_FMI]; |
| 3371 | + |
| 3372 | + ret = NLA_PARSE_NESTED(fmi, TSN_QCI_FMI_ATTR_MAX, na, qci_fmi_policy); |
| 3373 | + if (ret) { |
| 3374 | + pr_info("tsn: parse value TSN_QCI_FMI_ATTR_MAX error."); |
| 3375 | + return -EINVAL; |
| 3376 | + } |
| 3377 | + |
| 3378 | + if (!fmi[TSN_QCI_FMI_ATTR_INDEX]) |
| 3379 | + return -EINVAL; |
| 3380 | + |
| 3381 | + index = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_INDEX]); |
| 3382 | + |
| 3383 | + if (fmi[TSN_QCI_FMI_ATTR_DISABLE]) |
| 3384 | + goto loaddev; |
| 3385 | + |
| 3386 | + enable = 1; |
| 3387 | + |
| 3388 | + if (fmi[TSN_QCI_FMI_ATTR_CIR]) |
| 3389 | + fmiconf.cir = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_CIR]); |
| 3390 | + |
| 3391 | + if (fmi[TSN_QCI_FMI_ATTR_CBS]) |
| 3392 | + fmiconf.cbs = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_CBS]); |
| 3393 | + |
| 3394 | + if (fmi[TSN_QCI_FMI_ATTR_EIR]) |
| 3395 | + fmiconf.eir = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_EIR]); |
| 3396 | + |
| 3397 | + if (fmi[TSN_QCI_FMI_ATTR_EBS]) |
| 3398 | + fmiconf.ebs = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_EBS]); |
| 3399 | + |
| 3400 | + if (fmi[TSN_QCI_FMI_ATTR_CF]) |
| 3401 | + fmiconf.cf = 1; |
| 3402 | + |
| 3403 | + if (fmi[TSN_QCI_FMI_ATTR_CM]) |
| 3404 | + fmiconf.cm = 1; |
| 3405 | + |
| 3406 | + if (fmi[TSN_QCI_FMI_ATTR_DROPYL]) |
| 3407 | + fmiconf.drop_on_yellow = 1; |
| 3408 | + |
| 3409 | + if (fmi[TSN_QCI_FMI_ATTR_MAREDEN]) |
| 3410 | + fmiconf.mark_red_enable = 1; |
| 3411 | + |
| 3412 | + if (fmi[TSN_QCI_FMI_ATTR_MARED]) |
| 3413 | + fmiconf.mark_red = 1; |
| 3414 | + |
| 3415 | +loaddev: |
| 3416 | + |
| 3417 | + if (!tsnops->qci_fmi_set) { |
| 3418 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3419 | + netdev->name, -EPERM); |
| 3420 | + return -EINVAL; |
| 3421 | + } |
| 3422 | + |
| 3423 | + ret = tsnops->qci_fmi_set(netdev, index, enable, &fmiconf); |
| 3424 | + if (ret < 0) { |
| 3425 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 3426 | + return ret; |
| 3427 | + } |
| 3428 | + |
| 3429 | + ret = tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, 0); |
| 3430 | + |
| 3431 | + if (ret) |
| 3432 | + return ret; |
| 3433 | + return 0; |
| 3434 | +} |
| 3435 | + |
| 3436 | +static int tsn_qci_fmi_set(struct sk_buff *skb, struct genl_info *info) |
| 3437 | +{ |
| 3438 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 3439 | + cmd_qci_fmi_set(info); |
| 3440 | + return 0; |
| 3441 | + } |
| 3442 | + |
| 3443 | + return -1; |
| 3444 | +} |
| 3445 | + |
| 3446 | +static int cmd_qci_fmi_get(struct genl_info *info) |
| 3447 | +{ |
| 3448 | + struct nlattr *na, *fmi[TSN_QCI_FMI_ATTR_MAX + 1], *fmiattr; |
| 3449 | + u32 index; |
| 3450 | + struct sk_buff *rep_skb; |
| 3451 | + int ret; |
| 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; |
| 3458 | + |
| 3459 | + port = tsn_init_check(info, &netdev); |
| 3460 | + if (!port) |
| 3461 | + return -ENODEV; |
| 3462 | + |
| 3463 | + tsnops = port->tsnops; |
| 3464 | + |
| 3465 | + if (!info->attrs[TSN_ATTR_QCI_FMI]) |
| 3466 | + return -EINVAL; |
| 3467 | + |
| 3468 | + na = info->attrs[TSN_ATTR_QCI_FMI]; |
| 3469 | + |
| 3470 | + ret = NLA_PARSE_NESTED(fmi, TSN_QCI_FMI_ATTR_MAX, |
| 3471 | + na, qci_fmi_policy); |
| 3472 | + if (ret) { |
| 3473 | + pr_info("tsn: parse value TSN_QCI_FMI_ATTR_MAX error."); |
| 3474 | + return -EINVAL; |
| 3475 | + } |
| 3476 | + |
| 3477 | + if (!fmi[TSN_QCI_FMI_ATTR_INDEX]) |
| 3478 | + return -EINVAL; |
| 3479 | + |
| 3480 | + index = nla_get_u32(fmi[TSN_QCI_FMI_ATTR_INDEX]); |
| 3481 | + |
| 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)); |
| 3485 | + |
| 3486 | + if (!tsnops->qci_fmi_get) { |
| 3487 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3488 | + netdev->name, -EPERM); |
| 3489 | + return -EINVAL; |
| 3490 | + } |
| 3491 | + |
| 3492 | + ret = tsnops->qci_fmi_get(netdev, index, &fmiconf, &counters); |
| 3493 | + if (ret < 0) { |
| 3494 | + tsn_simple_reply(info, TSN_CMD_REPLY, netdev->name, ret); |
| 3495 | + return ret; |
| 3496 | + } |
| 3497 | + |
| 3498 | + genlhdr = info->genlhdr; |
| 3499 | + |
| 3500 | + /* Form netlink reply data */ |
| 3501 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 3502 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 3503 | + if (ret < 0) |
| 3504 | + return ret; |
| 3505 | + |
| 3506 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 3507 | + return -EMSGSIZE; |
| 3508 | + |
| 3509 | + fmiattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QCI_FMI); |
| 3510 | + if (!fmiattr) |
| 3511 | + return -EMSGSIZE; |
| 3512 | + |
| 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)) |
| 3518 | + return -EMSGSIZE; |
| 3519 | + |
| 3520 | + if (fmiconf.cf) |
| 3521 | + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_CF)) |
| 3522 | + return -EMSGSIZE; |
| 3523 | + |
| 3524 | + if (fmiconf.cm) |
| 3525 | + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_CM)) |
| 3526 | + return -EMSGSIZE; |
| 3527 | + |
| 3528 | + if (fmiconf.drop_on_yellow) |
| 3529 | + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_DROPYL)) |
| 3530 | + return -EMSGSIZE; |
| 3531 | + |
| 3532 | + if (fmiconf.mark_red_enable) |
| 3533 | + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_MAREDEN)) |
| 3534 | + return -EMSGSIZE; |
| 3535 | + |
| 3536 | + if (fmiconf.mark_red) |
| 3537 | + if (nla_put_flag(rep_skb, TSN_QCI_FMI_ATTR_MAREDEN)) |
| 3538 | + return -EMSGSIZE; |
| 3539 | + |
| 3540 | + if (nla_put(rep_skb, TSN_QCI_FMI_ATTR_COUNTERS, |
| 3541 | + sizeof(struct tsn_qci_psfp_fmi_counters), &counters)) |
| 3542 | + return -EMSGSIZE; |
| 3543 | + |
| 3544 | + nla_nest_end(rep_skb, fmiattr); |
| 3545 | + |
| 3546 | + tsn_send_reply(rep_skb, info); |
| 3547 | + |
| 3548 | + return 0; |
| 3549 | +} |
| 3550 | + |
| 3551 | +static int tsn_qci_fmi_get(struct sk_buff *skb, struct genl_info *info) |
| 3552 | +{ |
| 3553 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 3554 | + cmd_qci_fmi_get(info); |
| 3555 | + return 0; |
| 3556 | + } |
| 3557 | + |
| 3558 | + return -1; |
| 3559 | +} |
| 3560 | + |
| 3561 | +static int cmd_qbv_set(struct genl_info *info) |
| 3562 | +{ |
| 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]; |
| 3567 | + int rem; |
| 3568 | + int ret = 0; |
| 3569 | + struct net_device *netdev; |
| 3570 | + struct tsn_qbv_conf qbvconfig; |
| 3571 | + const struct tsn_ops *tsnops; |
| 3572 | + struct tsn_qbv_entry *gatelist = NULL; |
| 3573 | + int count = 0; |
| 3574 | + struct tsn_port *port; |
| 3575 | + |
| 3576 | + port = tsn_init_check(info, &netdev); |
| 3577 | + if (!port) |
| 3578 | + return -ENODEV; |
| 3579 | + |
| 3580 | + tsnops = port->tsnops; |
| 3581 | + |
| 3582 | + memset(&qbvconfig, 0, sizeof(struct tsn_qbv_conf)); |
| 3583 | + |
| 3584 | + if (!info->attrs[TSN_ATTR_QBV]) |
| 3585 | + return -EINVAL; |
| 3586 | + |
| 3587 | + na = info->attrs[TSN_ATTR_QBV]; |
| 3588 | + |
| 3589 | + ret = NLA_PARSE_NESTED(qbv, TSN_QBV_ATTR_MAX, na, qbv_policy); |
| 3590 | + if (ret) |
| 3591 | + return -EINVAL; |
| 3592 | + |
| 3593 | + if (qbv[TSN_QBV_ATTR_ENABLE]) |
| 3594 | + qbvconfig.gate_enabled = 1; |
| 3595 | + else |
| 3596 | + goto setdrive; |
| 3597 | + |
| 3598 | + if (qbv[TSN_QBV_ATTR_CONFIGCHANGE]) |
| 3599 | + qbvconfig.config_change = 1; |
| 3600 | + |
| 3601 | + if (!qbv[TSN_QBV_ATTR_ADMINENTRY]) { |
| 3602 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3603 | + netdev->name, -EINVAL); |
| 3604 | + return -1; |
| 3605 | + } |
| 3606 | + |
| 3607 | + na1 = qbv[TSN_QBV_ATTR_ADMINENTRY]; |
| 3608 | + NLA_PARSE_NESTED(qbvctrl, TSN_QBV_ATTR_CTRL_MAX, |
| 3609 | + na1, qbv_ctrl_policy); |
| 3610 | + |
| 3611 | + if (qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIME]) { |
| 3612 | + qbvconfig.admin.cycle_time = |
| 3613 | + nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIME]); |
| 3614 | + } |
| 3615 | + |
| 3616 | + if (qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIMEEXT]) { |
| 3617 | + qbvconfig.admin.cycle_time_extension = |
| 3618 | + nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_CYCLETIMEEXT]); |
| 3619 | + } |
| 3620 | + |
| 3621 | + if (qbvctrl[TSN_QBV_ATTR_CTRL_BASETIME]) { |
| 3622 | + qbvconfig.admin.base_time = |
| 3623 | + nla_get_u64(qbvctrl[TSN_QBV_ATTR_CTRL_BASETIME]); |
| 3624 | + } |
| 3625 | + |
| 3626 | + if (qbvctrl[TSN_QBV_ATTR_CTRL_GATESTATE]) { |
| 3627 | + qbvconfig.admin.gate_states = |
| 3628 | + nla_get_u8(qbvctrl[TSN_QBV_ATTR_CTRL_GATESTATE]); |
| 3629 | + } |
| 3630 | + |
| 3631 | + if (qbvctrl[TSN_QBV_ATTR_CTRL_LISTCOUNT]) { |
| 3632 | + int listcount; |
| 3633 | + |
| 3634 | + listcount = nla_get_u32(qbvctrl[TSN_QBV_ATTR_CTRL_LISTCOUNT]); |
| 3635 | + |
| 3636 | + qbvconfig.admin.control_list_length = listcount; |
| 3637 | + |
| 3638 | + gatelist = kmalloc_array(listcount, |
| 3639 | + sizeof(*gatelist), |
| 3640 | + GFP_KERNEL); |
| 3641 | + |
| 3642 | + nla_for_each_nested(qbv_table, na1, rem) { |
| 3643 | + struct nlattr *qbv_entry[TSN_QBV_ATTR_ENTRY_MAX + 1]; |
| 3644 | + |
| 3645 | + if (nla_type(qbv_table) != TSN_QBV_ATTR_CTRL_LISTENTRY) |
| 3646 | + continue; |
| 3647 | + |
| 3648 | + ret = NLA_PARSE_NESTED(qbv_entry, |
| 3649 | + TSN_QBV_ATTR_ENTRY_MAX, |
| 3650 | + qbv_table, qbv_entry_policy); |
| 3651 | + if (ret) |
| 3652 | + return -EINVAL; |
| 3653 | + |
| 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]); |
| 3658 | + count++; |
| 3659 | + if (count > listcount) |
| 3660 | + break; |
| 3661 | + } |
| 3662 | + } |
| 3663 | + |
| 3664 | + if (gatelist) |
| 3665 | + qbvconfig.admin.control_list = gatelist; |
| 3666 | + |
| 3667 | +setdrive: |
| 3668 | + if (!tsnops->qbv_set) { |
| 3669 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3670 | + netdev->name, -EPERM); |
| 3671 | + goto err; |
| 3672 | + } |
| 3673 | + |
| 3674 | + ret = tsnops->qbv_set(netdev, &qbvconfig); |
| 3675 | + |
| 3676 | + /* send back */ |
| 3677 | + if (ret < 0) |
| 3678 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3679 | + netdev->name, ret); |
| 3680 | + else |
| 3681 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3682 | + netdev->name, 0); |
| 3683 | + |
| 3684 | +err: |
| 3685 | + kfree(gatelist); |
| 3686 | + return ret; |
| 3687 | +} |
| 3688 | + |
| 3689 | +static int tsn_qbv_set(struct sk_buff *skb, struct genl_info *info) |
| 3690 | +{ |
| 3691 | + if (info->attrs[TSN_ATTR_IFNAME]) { |
| 3692 | + cmd_qbv_set(info); |
| 3693 | + return 0; |
| 3694 | + } |
| 3695 | + |
| 3696 | + return -1; |
| 3697 | +} |
| 3698 | + |
| 3699 | +static int cmd_qbv_get(struct genl_info *info) |
| 3700 | +{ |
| 3701 | + struct nlattr *qbv, *qbvadminattr; |
| 3702 | + struct sk_buff *rep_skb; |
| 3703 | + int ret; |
| 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; |
| 3710 | + |
| 3711 | + port = tsn_init_check(info, &netdev); |
| 3712 | + if (!port) |
| 3713 | + return -ENODEV; |
| 3714 | + |
| 3715 | + tsnops = port->tsnops; |
| 3716 | + |
| 3717 | + genlhdr = info->genlhdr; |
| 3718 | + |
| 3719 | + memset(&qbvconf, 0, sizeof(struct tsn_qbv_conf)); |
| 3720 | + |
| 3721 | + if (!tsnops->qbv_get) { |
| 3722 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3723 | + netdev->name, -EPERM); |
| 3724 | + return -1; |
| 3725 | + } |
| 3726 | + |
| 3727 | + ret = tsnops->qbv_get(netdev, &qbvconf); |
| 3728 | + if (ret < 0) { |
| 3729 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3730 | + netdev->name, ret); |
| 3731 | + return ret; |
| 3732 | + } |
| 3733 | + |
| 3734 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 3735 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 3736 | + if (ret < 0) |
| 3737 | + return ret; |
| 3738 | + |
| 3739 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 3740 | + return -EMSGSIZE; |
| 3741 | + |
| 3742 | + qbv = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBV); |
| 3743 | + if (!qbv) |
| 3744 | + return -EMSGSIZE; |
| 3745 | + |
| 3746 | + qbvadminattr = nla_nest_start_noflag(rep_skb, TSN_QBV_ATTR_ADMINENTRY); |
| 3747 | + if (!qbvadminattr) |
| 3748 | + return -EMSGSIZE; |
| 3749 | + |
| 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)) |
| 3753 | + return -EMSGSIZE; |
| 3754 | + |
| 3755 | + for (i = 0; i < len; i++) { |
| 3756 | + struct nlattr *qbv_table; |
| 3757 | + u8 gs; |
| 3758 | + u32 tp; |
| 3759 | + int glisttype = TSN_QBV_ATTR_CTRL_LISTENTRY; |
| 3760 | + |
| 3761 | + gs = (qbvconf.admin.control_list + i)->gate_state; |
| 3762 | + tp = (qbvconf.admin.control_list + i)->time_interval; |
| 3763 | + |
| 3764 | + qbv_table = |
| 3765 | + nla_nest_start_noflag(rep_skb, glisttype); |
| 3766 | + if (!qbv_table) |
| 3767 | + return -EMSGSIZE; |
| 3768 | + |
| 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)) |
| 3772 | + return -EMSGSIZE; |
| 3773 | + nla_nest_end(rep_skb, qbv_table); |
| 3774 | + } |
| 3775 | + |
| 3776 | + if (qbvconf.admin.gate_states) |
| 3777 | + if (nla_put_u8(rep_skb, TSN_QBV_ATTR_CTRL_GATESTATE, |
| 3778 | + qbvconf.admin.gate_states)) |
| 3779 | + return -EMSGSIZE; |
| 3780 | + |
| 3781 | + if (qbvconf.admin.cycle_time) |
| 3782 | + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIME, |
| 3783 | + qbvconf.admin.cycle_time)) |
| 3784 | + return -EMSGSIZE; |
| 3785 | + |
| 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)) |
| 3789 | + return -EMSGSIZE; |
| 3790 | + |
| 3791 | + if (qbvconf.admin.base_time) |
| 3792 | + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CTRL_BASETIME, |
| 3793 | + qbvconf.admin.base_time)) |
| 3794 | + return -EMSGSIZE; |
| 3795 | + |
| 3796 | + kfree(qbvconf.admin.control_list); |
| 3797 | + |
| 3798 | + } else { |
| 3799 | + pr_info("tsn: error get administrator data."); |
| 3800 | + } |
| 3801 | + |
| 3802 | + nla_nest_end(rep_skb, qbvadminattr); |
| 3803 | + |
| 3804 | + if (qbvconf.gate_enabled) { |
| 3805 | + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_ENABLE)) |
| 3806 | + return -EMSGSIZE; |
| 3807 | + } else { |
| 3808 | + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_DISABLE)) |
| 3809 | + return -EMSGSIZE; |
| 3810 | + } |
| 3811 | + |
| 3812 | + if (qbvconf.maxsdu) |
| 3813 | + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_MAXSDU, qbvconf.maxsdu)) |
| 3814 | + return -EMSGSIZE; |
| 3815 | + |
| 3816 | + if (qbvconf.config_change) |
| 3817 | + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_CONFIGCHANGE)) |
| 3818 | + return -EMSGSIZE; |
| 3819 | + |
| 3820 | + nla_nest_end(rep_skb, qbv); |
| 3821 | + |
| 3822 | + tsn_send_reply(rep_skb, info); |
| 3823 | + |
| 3824 | + return ret; |
| 3825 | +} |
| 3826 | + |
| 3827 | +static int cmd_qbv_status_get(struct genl_info *info) |
| 3828 | +{ |
| 3829 | + struct nlattr *qbv, *qbvoperattr; |
| 3830 | + struct sk_buff *rep_skb; |
| 3831 | + int ret; |
| 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; |
| 3838 | + |
| 3839 | + port = tsn_init_check(info, &netdev); |
| 3840 | + if (!port) |
| 3841 | + return -ENODEV; |
| 3842 | + |
| 3843 | + tsnops = port->tsnops; |
| 3844 | + |
| 3845 | + genlhdr = info->genlhdr; |
| 3846 | + |
| 3847 | + memset(&qbvstatus, 0, sizeof(struct tsn_qbv_status)); |
| 3848 | + |
| 3849 | + if (!tsnops->qbv_get_status) { |
| 3850 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3851 | + netdev->name, -EPERM); |
| 3852 | + return -1; |
| 3853 | + } |
| 3854 | + |
| 3855 | + ret = tsnops->qbv_get_status(netdev, &qbvstatus); |
| 3856 | + if (ret < 0) { |
| 3857 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 3858 | + netdev->name, ret); |
| 3859 | + return ret; |
| 3860 | + } |
| 3861 | + |
| 3862 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 3863 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 3864 | + if (ret < 0) |
| 3865 | + return ret; |
| 3866 | + |
| 3867 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 3868 | + return -EMSGSIZE; |
| 3869 | + |
| 3870 | + qbv = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBV); |
| 3871 | + if (!qbv) |
| 3872 | + return -EMSGSIZE; |
| 3873 | + |
| 3874 | + qbvoperattr = nla_nest_start_noflag(rep_skb, TSN_QBV_ATTR_OPERENTRY); |
| 3875 | + if (!qbvoperattr) |
| 3876 | + return -EMSGSIZE; |
| 3877 | + |
| 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); |
| 3882 | + return -EMSGSIZE; |
| 3883 | + } |
| 3884 | + |
| 3885 | + for (i = 0; i < len; i++) { |
| 3886 | + struct nlattr *qbv_table; |
| 3887 | + u8 gs; |
| 3888 | + u32 tp; |
| 3889 | + int glisttype = TSN_QBV_ATTR_CTRL_LISTENTRY; |
| 3890 | + |
| 3891 | + gs = (qbvstatus.oper.control_list + i)->gate_state; |
| 3892 | + tp = (qbvstatus.oper.control_list + i)->time_interval; |
| 3893 | + |
| 3894 | + qbv_table = nla_nest_start_noflag(rep_skb, glisttype); |
| 3895 | + if (!qbv_table) |
| 3896 | + return -EMSGSIZE; |
| 3897 | + |
| 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); |
| 3902 | + return -EMSGSIZE; |
| 3903 | + } |
| 3904 | + |
| 3905 | + nla_nest_end(rep_skb, qbv_table); |
| 3906 | + } |
| 3907 | + |
| 3908 | + if (qbvstatus.oper.gate_states) { |
| 3909 | + if (nla_put_u8(rep_skb, TSN_QBV_ATTR_CTRL_GATESTATE, |
| 3910 | + qbvstatus.oper.gate_states)) |
| 3911 | + return -EMSGSIZE; |
| 3912 | + } |
| 3913 | + |
| 3914 | + if (qbvstatus.oper.cycle_time) { |
| 3915 | + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_CTRL_CYCLETIME, |
| 3916 | + qbvstatus.oper.cycle_time)) |
| 3917 | + return -EMSGSIZE; |
| 3918 | + } |
| 3919 | + |
| 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)) |
| 3923 | + return -EMSGSIZE; |
| 3924 | + } |
| 3925 | + |
| 3926 | + if (qbvstatus.oper.base_time) { |
| 3927 | + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CTRL_BASETIME, |
| 3928 | + qbvstatus.oper.base_time)) |
| 3929 | + return -EMSGSIZE; |
| 3930 | + } |
| 3931 | + |
| 3932 | + kfree(qbvstatus.oper.control_list); |
| 3933 | + } else { |
| 3934 | + pr_info("tsn: error get operation list data."); |
| 3935 | + } |
| 3936 | + |
| 3937 | + nla_nest_end(rep_skb, qbvoperattr); |
| 3938 | + |
| 3939 | + if (qbvstatus.config_change_time) { |
| 3940 | + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CONFIGCHANGETIME, |
| 3941 | + qbvstatus.config_change_time)) |
| 3942 | + return -EMSGSIZE; |
| 3943 | + } |
| 3944 | + |
| 3945 | + if (qbvstatus.tick_granularity) { |
| 3946 | + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_GRANULARITY, |
| 3947 | + qbvstatus.tick_granularity)) |
| 3948 | + return -EMSGSIZE; |
| 3949 | + } |
| 3950 | + |
| 3951 | + if (qbvstatus.current_time) { |
| 3952 | + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CURRENTTIME, |
| 3953 | + qbvstatus.current_time)) |
| 3954 | + return -EMSGSIZE; |
| 3955 | + } |
| 3956 | + |
| 3957 | + if (qbvstatus.config_pending) { |
| 3958 | + if (nla_put_flag(rep_skb, TSN_QBV_ATTR_CONFIGPENDING)) |
| 3959 | + return -EMSGSIZE; |
| 3960 | + } |
| 3961 | + |
| 3962 | + if (qbvstatus.config_change_error) { |
| 3963 | + if (NLA_PUT_U64(rep_skb, TSN_QBV_ATTR_CONFIGCHANGEERROR, |
| 3964 | + qbvstatus.config_change_error)) |
| 3965 | + return -EMSGSIZE; |
| 3966 | + } |
| 3967 | + |
| 3968 | + if (qbvstatus.supported_list_max) { |
| 3969 | + if (nla_put_u32(rep_skb, TSN_QBV_ATTR_LISTMAX, |
| 3970 | + qbvstatus.supported_list_max)) |
| 3971 | + return -EMSGSIZE; |
| 3972 | + } |
| 3973 | + |
| 3974 | + nla_nest_end(rep_skb, qbv); |
| 3975 | + |
| 3976 | + tsn_send_reply(rep_skb, info); |
| 3977 | + |
| 3978 | + return ret; |
| 3979 | +} |
| 3980 | + |
| 3981 | +static int tsn_qbv_status_get(struct sk_buff *skb, struct genl_info *info) |
| 3982 | +{ |
| 3983 | + if (info->attrs[TSN_ATTR_IFNAME]) |
| 3984 | + cmd_qbv_status_get(info); |
| 3985 | + |
| 3986 | + return 0; |
| 3987 | +} |
| 3988 | + |
| 3989 | +static int tsn_qbv_get(struct sk_buff *skb, struct genl_info *info) |
| 3990 | +{ |
| 3991 | + if (info->attrs[TSN_ATTR_IFNAME]) |
| 3992 | + cmd_qbv_get(info); |
| 3993 | + |
| 3994 | + return 0; |
| 3995 | +} |
| 3996 | + |
| 3997 | +static int tsn_cbs_set(struct sk_buff *skb, struct genl_info *info) |
| 3998 | +{ |
| 3999 | + struct nlattr *na; |
| 4000 | + struct nlattr *cbsa[TSN_CBS_ATTR_MAX + 1]; |
| 4001 | + struct net_device *netdev; |
| 4002 | + const struct tsn_ops *tsnops; |
| 4003 | + int ret; |
| 4004 | + u8 tc, bw; |
| 4005 | + struct tsn_port *port; |
| 4006 | + |
| 4007 | + port = tsn_init_check(info, &netdev); |
| 4008 | + if (!port) |
| 4009 | + return -ENODEV; |
| 4010 | + |
| 4011 | + tsnops = port->tsnops; |
| 4012 | + |
| 4013 | + if (!info->attrs[TSN_ATTR_CBS]) { |
| 4014 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4015 | + netdev->name, -EINVAL); |
| 4016 | + return -EINVAL; |
| 4017 | + } |
| 4018 | + |
| 4019 | + na = info->attrs[TSN_ATTR_CBS]; |
| 4020 | + |
| 4021 | + if (!tsnops->cbs_set) { |
| 4022 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4023 | + netdev->name, -EPERM); |
| 4024 | + return -1; |
| 4025 | + } |
| 4026 | + |
| 4027 | + ret = NLA_PARSE_NESTED(cbsa, TSN_CBS_ATTR_MAX, na, cbs_policy); |
| 4028 | + if (ret) { |
| 4029 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4030 | + netdev->name, -EINVAL); |
| 4031 | + return -EINVAL; |
| 4032 | + } |
| 4033 | + |
| 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); |
| 4038 | + return -EINVAL; |
| 4039 | + } |
| 4040 | + tc = nla_get_u8(cbsa[TSN_CBS_ATTR_TC_INDEX]); |
| 4041 | + |
| 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); |
| 4046 | + return -EINVAL; |
| 4047 | + } |
| 4048 | + |
| 4049 | + bw = nla_get_u8(cbsa[TSN_CBS_ATTR_BW]); |
| 4050 | + if (bw > 100) { |
| 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); |
| 4054 | + return -EINVAL; |
| 4055 | + } |
| 4056 | + |
| 4057 | + ret = tsnops->cbs_set(netdev, tc, bw); |
| 4058 | + if (ret < 0) { |
| 4059 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4060 | + netdev->name, ret); |
| 4061 | + return ret; |
| 4062 | + } |
| 4063 | + |
| 4064 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4065 | + netdev->name, 0); |
| 4066 | + return 0; |
| 4067 | +} |
| 4068 | + |
| 4069 | +static int tsn_cbs_get(struct sk_buff *skb, struct genl_info *info) |
| 4070 | +{ |
| 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; |
| 4076 | + int ret; |
| 4077 | + struct genlmsghdr *genlhdr; |
| 4078 | + u8 tc; |
| 4079 | + struct tsn_port *port; |
| 4080 | + |
| 4081 | + port = tsn_init_check(info, &netdev); |
| 4082 | + if (!port) |
| 4083 | + return -ENODEV; |
| 4084 | + |
| 4085 | + tsnops = port->tsnops; |
| 4086 | + |
| 4087 | + if (!info->attrs[TSN_ATTR_CBS]) { |
| 4088 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4089 | + netdev->name, -EINVAL); |
| 4090 | + return -EINVAL; |
| 4091 | + } |
| 4092 | + |
| 4093 | + if (!tsnops->cbs_get) { |
| 4094 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4095 | + netdev->name, -EPERM); |
| 4096 | + return -1; |
| 4097 | + } |
| 4098 | + |
| 4099 | + na = info->attrs[TSN_ATTR_CBS]; |
| 4100 | + ret = NLA_PARSE_NESTED(cbsa, TSN_CBS_ATTR_MAX, na, cbs_policy); |
| 4101 | + if (ret) { |
| 4102 | + pr_err("tsn: parse value TSN_CBS_ATTR_MAX error."); |
| 4103 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4104 | + netdev->name, -EINVAL); |
| 4105 | + return -EINVAL; |
| 4106 | + } |
| 4107 | + |
| 4108 | + /* Get status data from device */ |
| 4109 | + genlhdr = info->genlhdr; |
| 4110 | + |
| 4111 | + /* Form netlink reply data */ |
| 4112 | + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb, |
| 4113 | + NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 4114 | + if (ret < 0) |
| 4115 | + return ret; |
| 4116 | + |
| 4117 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 4118 | + return -EMSGSIZE; |
| 4119 | + |
| 4120 | + cbsattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CBS); |
| 4121 | + if (!cbsattr) |
| 4122 | + return -EMSGSIZE; |
| 4123 | + |
| 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); |
| 4128 | + return -EINVAL; |
| 4129 | + } |
| 4130 | + tc = nla_get_u8(cbsa[TSN_CBS_ATTR_TC_INDEX]); |
| 4131 | + |
| 4132 | + ret = tsnops->cbs_get(netdev, tc); |
| 4133 | + if (ret < 0) { |
| 4134 | + pr_err("tsn: cbs_get return error\n"); |
| 4135 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4136 | + netdev->name, ret); |
| 4137 | + return ret; |
| 4138 | + } |
| 4139 | + |
| 4140 | + if (nla_put_u8(rep_skb, TSN_CBS_ATTR_BW, ret & 0XF)) |
| 4141 | + return -EMSGSIZE; |
| 4142 | + |
| 4143 | + nla_nest_end(rep_skb, cbsattr); |
| 4144 | + return tsn_send_reply(rep_skb, info); |
| 4145 | +} |
| 4146 | + |
| 4147 | +static int cmd_qbu_set(struct genl_info *info) |
| 4148 | +{ |
| 4149 | + struct nlattr *na; |
| 4150 | + struct nlattr *qbua[TSN_QBU_ATTR_MAX + 1]; |
| 4151 | + struct net_device *netdev; |
| 4152 | + const struct tsn_ops *tsnops; |
| 4153 | + int ret; |
| 4154 | + u8 preemptible = 0; |
| 4155 | + struct tsn_port *port; |
| 4156 | + |
| 4157 | + port = tsn_init_check(info, &netdev); |
| 4158 | + if (!port) |
| 4159 | + return -ENODEV; |
| 4160 | + |
| 4161 | + tsnops = port->tsnops; |
| 4162 | + |
| 4163 | + if (!info->attrs[TSN_ATTR_QBU]) { |
| 4164 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4165 | + netdev->name, -EINVAL); |
| 4166 | + return -EINVAL; |
| 4167 | + } |
| 4168 | + |
| 4169 | + na = info->attrs[TSN_ATTR_QBU]; |
| 4170 | + |
| 4171 | + ret = NLA_PARSE_NESTED(qbua, TSN_QBU_ATTR_MAX, na, qbu_policy); |
| 4172 | + if (ret) { |
| 4173 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4174 | + netdev->name, -EINVAL); |
| 4175 | + return -EINVAL; |
| 4176 | + } |
| 4177 | + |
| 4178 | + if (qbua[TSN_QBU_ATTR_ADMIN_STATE]) |
| 4179 | + preemptible = nla_get_u8(qbua[TSN_QBU_ATTR_ADMIN_STATE]); |
| 4180 | + else |
| 4181 | + pr_info("No preemptible TSN_QBU_ATTR_ADMIN_STATE config!\n"); |
| 4182 | + |
| 4183 | + if (!tsnops->qbu_set) { |
| 4184 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4185 | + netdev->name, -EPERM); |
| 4186 | + return -EINVAL; |
| 4187 | + } |
| 4188 | + |
| 4189 | + ret = tsnops->qbu_set(netdev, preemptible); |
| 4190 | + if (ret < 0) { |
| 4191 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4192 | + netdev->name, ret); |
| 4193 | + return ret; |
| 4194 | + } |
| 4195 | + |
| 4196 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4197 | + netdev->name, 0); |
| 4198 | + return 0; |
| 4199 | +} |
| 4200 | + |
| 4201 | +static int tsn_qbu_set(struct sk_buff *skb, struct genl_info *info) |
| 4202 | +{ |
| 4203 | + if (info->attrs[TSN_ATTR_IFNAME]) |
| 4204 | + return cmd_qbu_set(info); |
| 4205 | + |
| 4206 | + return -1; |
| 4207 | +} |
| 4208 | + |
| 4209 | +static int cmd_qbu_get_status(struct genl_info *info) |
| 4210 | +{ |
| 4211 | + struct nlattr *qbuattr; |
| 4212 | + struct net_device *netdev; |
| 4213 | + const struct tsn_ops *tsnops; |
| 4214 | + struct sk_buff *rep_skb; |
| 4215 | + int ret; |
| 4216 | + struct genlmsghdr *genlhdr; |
| 4217 | + struct tsn_preempt_status pps; |
| 4218 | + struct tsn_port *port; |
| 4219 | + |
| 4220 | + port = tsn_init_check(info, &netdev); |
| 4221 | + if (!port) |
| 4222 | + return -ENODEV; |
| 4223 | + |
| 4224 | + tsnops = port->tsnops; |
| 4225 | + |
| 4226 | + /* Get status data from device */ |
| 4227 | + genlhdr = info->genlhdr; |
| 4228 | + |
| 4229 | + memset(&pps, 0, sizeof(struct tsn_preempt_status)); |
| 4230 | + |
| 4231 | + if (!tsnops->qbu_get) { |
| 4232 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4233 | + netdev->name, -EPERM); |
| 4234 | + return -1; |
| 4235 | + } |
| 4236 | + |
| 4237 | + ret = tsnops->qbu_get(netdev, &pps); |
| 4238 | + if (ret < 0) { |
| 4239 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4240 | + netdev->name, ret); |
| 4241 | + return ret; |
| 4242 | + } |
| 4243 | + |
| 4244 | + /* Form netlink reply data */ |
| 4245 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 4246 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 4247 | + if (ret < 0) |
| 4248 | + return ret; |
| 4249 | + |
| 4250 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 4251 | + return -EMSGSIZE; |
| 4252 | + |
| 4253 | + qbuattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_QBU); |
| 4254 | + if (!qbuattr) |
| 4255 | + return -EMSGSIZE; |
| 4256 | + |
| 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)) |
| 4262 | + return -EMSGSIZE; |
| 4263 | + |
| 4264 | + if (pps.preemption_active) { |
| 4265 | + if (nla_put_flag(rep_skb, TSN_QBU_ATTR_ACTIVE)) |
| 4266 | + return -EMSGSIZE; |
| 4267 | + } |
| 4268 | + |
| 4269 | + if (nla_put_u8(rep_skb, TSN_QBU_ATTR_HOLD_REQUEST, pps.hold_request)) |
| 4270 | + return -EMSGSIZE; |
| 4271 | + |
| 4272 | + nla_nest_end(rep_skb, qbuattr); |
| 4273 | + |
| 4274 | + return tsn_send_reply(rep_skb, info); |
| 4275 | +} |
| 4276 | + |
| 4277 | +static int tsn_qbu_get_status(struct sk_buff *skb, struct genl_info *info) |
| 4278 | +{ |
| 4279 | + if (info->attrs[TSN_ATTR_IFNAME]) |
| 4280 | + return cmd_qbu_get_status(info); |
| 4281 | + |
| 4282 | + return -1; |
| 4283 | +} |
| 4284 | + |
| 4285 | +static int tsn_tsd_set(struct sk_buff *skb, struct genl_info *info) |
| 4286 | +{ |
| 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; |
| 4292 | + int ret; |
| 4293 | + struct tsn_port *port; |
| 4294 | + |
| 4295 | + port = tsn_init_check(info, &netdev); |
| 4296 | + if (!port) |
| 4297 | + return -ENODEV; |
| 4298 | + |
| 4299 | + tsnops = port->tsnops; |
| 4300 | + |
| 4301 | + memset(&tsd, 0, sizeof(struct tsn_tsd)); |
| 4302 | + |
| 4303 | + if (!info->attrs[TSN_ATTR_TSD]) { |
| 4304 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4305 | + netdev->name, -EINVAL); |
| 4306 | + return -EINVAL; |
| 4307 | + } |
| 4308 | + |
| 4309 | + na = info->attrs[TSN_ATTR_TSD]; |
| 4310 | + |
| 4311 | + ret = NLA_PARSE_NESTED(ntsd, TSN_TSD_ATTR_MAX, na, tsd_policy); |
| 4312 | + if (ret) { |
| 4313 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4314 | + netdev->name, -EINVAL); |
| 4315 | + return -EINVAL; |
| 4316 | + } |
| 4317 | + |
| 4318 | + if (!tsnops->tsd_set) { |
| 4319 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4320 | + netdev->name, -EPERM); |
| 4321 | + return -EINVAL; |
| 4322 | + } |
| 4323 | + |
| 4324 | + if (nla_get_flag(ntsd[TSN_TSD_ATTR_DISABLE])) { |
| 4325 | + tsd.enable = false; |
| 4326 | + } else { |
| 4327 | + if (ntsd[TSN_TSD_ATTR_PERIOD]) |
| 4328 | + tsd.period = nla_get_u32(ntsd[TSN_TSD_ATTR_PERIOD]); |
| 4329 | + |
| 4330 | + if (!tsd.period) { |
| 4331 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4332 | + netdev->name, -EINVAL); |
| 4333 | + return -EINVAL; |
| 4334 | + } |
| 4335 | + |
| 4336 | + if (ntsd[TSN_TSD_ATTR_MAX_FRM_NUM]) |
| 4337 | + tsd.maxFrameNum = |
| 4338 | + nla_get_u32(ntsd[TSN_TSD_ATTR_MAX_FRM_NUM]); |
| 4339 | + |
| 4340 | + if (ntsd[TSN_TSD_ATTR_SYN_IMME]) |
| 4341 | + tsd.syn_flag = 2; |
| 4342 | + else |
| 4343 | + tsd.syn_flag = 1; |
| 4344 | + |
| 4345 | + tsd.enable = true; |
| 4346 | + } |
| 4347 | + |
| 4348 | + ret = tsnops->tsd_set(netdev, &tsd); |
| 4349 | + if (ret < 0) { |
| 4350 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4351 | + netdev->name, ret); |
| 4352 | + return ret; |
| 4353 | + } |
| 4354 | + |
| 4355 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4356 | + netdev->name, 0); |
| 4357 | + return 0; |
| 4358 | +} |
| 4359 | + |
| 4360 | +static int tsn_tsd_get(struct sk_buff *skb, struct genl_info *info) |
| 4361 | +{ |
| 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; |
| 4367 | + int ret; |
| 4368 | + struct genlmsghdr *genlhdr; |
| 4369 | + struct tsn_tsd_status tts; |
| 4370 | + struct tsn_port *port; |
| 4371 | + |
| 4372 | + port = tsn_init_check(info, &netdev); |
| 4373 | + if (!port) |
| 4374 | + return -ENODEV; |
| 4375 | + |
| 4376 | + tsnops = port->tsnops; |
| 4377 | + |
| 4378 | + if (!info->attrs[TSN_ATTR_TSD]) { |
| 4379 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4380 | + netdev->name, -EINVAL); |
| 4381 | + return -EINVAL; |
| 4382 | + } |
| 4383 | + |
| 4384 | + if (!tsnops->tsd_get) { |
| 4385 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4386 | + netdev->name, -EPERM); |
| 4387 | + return -1; |
| 4388 | + } |
| 4389 | + |
| 4390 | + ret = tsnops->tsd_get(netdev, &tts); |
| 4391 | + if (ret < 0) { |
| 4392 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4393 | + netdev->name, ret); |
| 4394 | + return ret; |
| 4395 | + } |
| 4396 | + |
| 4397 | + na = info->attrs[TSN_ATTR_TSD]; |
| 4398 | + |
| 4399 | + ret = NLA_PARSE_NESTED(tsda, TSN_TSD_ATTR_MAX, |
| 4400 | + na, tsd_policy); |
| 4401 | + if (ret) { |
| 4402 | + pr_err("tsn: parse value TSN_TSD_ATTR_MAX error."); |
| 4403 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4404 | + netdev->name, -EINVAL); |
| 4405 | + return -EINVAL; |
| 4406 | + } |
| 4407 | + |
| 4408 | + /* Get status data from device */ |
| 4409 | + genlhdr = info->genlhdr; |
| 4410 | + |
| 4411 | + /* Form netlink reply data */ |
| 4412 | + ret = tsn_prepare_reply(info, genlhdr->cmd, &rep_skb, |
| 4413 | + NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 4414 | + if (ret < 0) |
| 4415 | + return ret; |
| 4416 | + |
| 4417 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 4418 | + return -EMSGSIZE; |
| 4419 | + |
| 4420 | + tsdattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_TSD); |
| 4421 | + if (!tsdattr) |
| 4422 | + return -EMSGSIZE; |
| 4423 | + |
| 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)) |
| 4429 | + return -EMSGSIZE; |
| 4430 | + |
| 4431 | + if (!tts.enable) { |
| 4432 | + if (nla_put_flag(rep_skb, TSN_TSD_ATTR_DISABLE)) |
| 4433 | + return -EMSGSIZE; |
| 4434 | + } else { |
| 4435 | + if (nla_put_flag(rep_skb, TSN_TSD_ATTR_ENABLE)) |
| 4436 | + return -EMSGSIZE; |
| 4437 | + } |
| 4438 | + |
| 4439 | + if (tts.flag == 2) |
| 4440 | + if (nla_put_flag(rep_skb, TSN_TSD_ATTR_SYN_IMME)) |
| 4441 | + return -EMSGSIZE; |
| 4442 | + |
| 4443 | + nla_nest_end(rep_skb, tsdattr); |
| 4444 | + return tsn_send_reply(rep_skb, info); |
| 4445 | +} |
| 4446 | + |
| 4447 | +static int tsn_ct_set(struct sk_buff *skb, struct genl_info *info) |
| 4448 | +{ |
| 4449 | + struct nlattr *na; |
| 4450 | + struct nlattr *cta[TSN_CT_ATTR_MAX + 1]; |
| 4451 | + struct net_device *netdev; |
| 4452 | + const struct tsn_ops *tsnops; |
| 4453 | + int ret; |
| 4454 | + u8 queue_stat; |
| 4455 | + struct tsn_port *port; |
| 4456 | + |
| 4457 | + port = tsn_init_check(info, &netdev); |
| 4458 | + if (!port) |
| 4459 | + return -ENODEV; |
| 4460 | + |
| 4461 | + tsnops = port->tsnops; |
| 4462 | + |
| 4463 | + if (!info->attrs[TSN_ATTR_CT]) { |
| 4464 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4465 | + netdev->name, -EINVAL); |
| 4466 | + return -EINVAL; |
| 4467 | + } |
| 4468 | + |
| 4469 | + na = info->attrs[TSN_ATTR_CT]; |
| 4470 | + |
| 4471 | + if (!tsnops->ct_set) { |
| 4472 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4473 | + netdev->name, -EPERM); |
| 4474 | + return -1; |
| 4475 | + } |
| 4476 | + |
| 4477 | + ret = NLA_PARSE_NESTED(cta, TSN_CT_ATTR_MAX, |
| 4478 | + na, ct_policy); |
| 4479 | + if (ret) { |
| 4480 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4481 | + netdev->name, -EINVAL); |
| 4482 | + return -EINVAL; |
| 4483 | + } |
| 4484 | + |
| 4485 | + queue_stat = nla_get_u8(cta[TSN_CT_ATTR_QUEUE_STATE]); |
| 4486 | + |
| 4487 | + ret = tsnops->ct_set(netdev, queue_stat); |
| 4488 | + if (ret < 0) { |
| 4489 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4490 | + netdev->name, ret); |
| 4491 | + return ret; |
| 4492 | + } |
| 4493 | + |
| 4494 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4495 | + netdev->name, 0); |
| 4496 | + return 0; |
| 4497 | +} |
| 4498 | + |
| 4499 | +static int tsn_cbgen_set(struct sk_buff *skb, struct genl_info *info) |
| 4500 | +{ |
| 4501 | + struct nlattr *na; |
| 4502 | + struct nlattr *cbgena[TSN_CBGEN_ATTR_MAX + 1]; |
| 4503 | + struct net_device *netdev; |
| 4504 | + const struct tsn_ops *tsnops; |
| 4505 | + int ret; |
| 4506 | + u32 index; |
| 4507 | + struct tsn_seq_gen_conf sg_conf; |
| 4508 | + struct tsn_port *port; |
| 4509 | + |
| 4510 | + port = tsn_init_check(info, &netdev); |
| 4511 | + if (!port) |
| 4512 | + return -ENODEV; |
| 4513 | + |
| 4514 | + tsnops = port->tsnops; |
| 4515 | + |
| 4516 | + if (!info->attrs[TSN_ATTR_CBGEN]) { |
| 4517 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4518 | + netdev->name, -EINVAL); |
| 4519 | + return -EINVAL; |
| 4520 | + } |
| 4521 | + |
| 4522 | + na = info->attrs[TSN_ATTR_CBGEN]; |
| 4523 | + |
| 4524 | + if (!tsnops->cbgen_set) { |
| 4525 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4526 | + netdev->name, -EPERM); |
| 4527 | + return -1; |
| 4528 | + } |
| 4529 | + |
| 4530 | + ret = NLA_PARSE_NESTED(cbgena, TSN_CBGEN_ATTR_MAX, |
| 4531 | + na, cbgen_policy); |
| 4532 | + if (ret) { |
| 4533 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4534 | + netdev->name, -EINVAL); |
| 4535 | + return -EINVAL; |
| 4536 | + } |
| 4537 | + |
| 4538 | + index = nla_get_u32(cbgena[TSN_CBGEN_ATTR_INDEX]); |
| 4539 | + |
| 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]); |
| 4545 | + |
| 4546 | + ret = tsnops->cbgen_set(netdev, index, &sg_conf); |
| 4547 | + if (ret < 0) { |
| 4548 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4549 | + netdev->name, ret); |
| 4550 | + return ret; |
| 4551 | + } |
| 4552 | + |
| 4553 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4554 | + netdev->name, 0); |
| 4555 | + return 0; |
| 4556 | +} |
| 4557 | + |
| 4558 | +static int tsn_cbrec_set(struct sk_buff *skb, struct genl_info *info) |
| 4559 | +{ |
| 4560 | + struct nlattr *na; |
| 4561 | + struct nlattr *cbreca[TSN_CBREC_ATTR_MAX + 1]; |
| 4562 | + struct net_device *netdev; |
| 4563 | + const struct tsn_ops *tsnops; |
| 4564 | + int ret; |
| 4565 | + u32 index; |
| 4566 | + struct tsn_seq_rec_conf sr_conf; |
| 4567 | + struct tsn_port *port; |
| 4568 | + |
| 4569 | + port = tsn_init_check(info, &netdev); |
| 4570 | + if (!port) |
| 4571 | + return -ENODEV; |
| 4572 | + |
| 4573 | + tsnops = port->tsnops; |
| 4574 | + |
| 4575 | + if (!info->attrs[TSN_ATTR_CBREC]) { |
| 4576 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4577 | + netdev->name, -EINVAL); |
| 4578 | + return -EINVAL; |
| 4579 | + } |
| 4580 | + |
| 4581 | + na = info->attrs[TSN_ATTR_CBREC]; |
| 4582 | + |
| 4583 | + if (!tsnops->cbrec_set) { |
| 4584 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4585 | + netdev->name, -EPERM); |
| 4586 | + return -1; |
| 4587 | + } |
| 4588 | + |
| 4589 | + ret = NLA_PARSE_NESTED(cbreca, TSN_CBREC_ATTR_MAX, |
| 4590 | + na, cbrec_policy); |
| 4591 | + if (ret) { |
| 4592 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4593 | + netdev->name, -EINVAL); |
| 4594 | + return -EINVAL; |
| 4595 | + } |
| 4596 | + |
| 4597 | + index = nla_get_u32(cbreca[TSN_CBREC_ATTR_INDEX]); |
| 4598 | + |
| 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]); |
| 4603 | + |
| 4604 | + ret = tsnops->cbrec_set(netdev, index, &sr_conf); |
| 4605 | + if (ret < 0) { |
| 4606 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4607 | + netdev->name, ret); |
| 4608 | + return ret; |
| 4609 | + } |
| 4610 | + |
| 4611 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4612 | + netdev->name, 0); |
| 4613 | + return 0; |
| 4614 | +} |
| 4615 | + |
| 4616 | +static int tsn_cbstatus_get(struct sk_buff *skb, struct genl_info *info) |
| 4617 | +{ |
| 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; |
| 4624 | + int ret; |
| 4625 | + unsigned int index; |
| 4626 | + struct genlmsghdr *genlhdr; |
| 4627 | + struct tsn_cb_status cbstat; |
| 4628 | + struct tsn_port *port; |
| 4629 | + |
| 4630 | + port = tsn_init_check(info, &netdev); |
| 4631 | + if (!port) |
| 4632 | + return -ENODEV; |
| 4633 | + |
| 4634 | + tsnops = port->tsnops; |
| 4635 | + |
| 4636 | + /* Get status data from device */ |
| 4637 | + genlhdr = info->genlhdr; |
| 4638 | + |
| 4639 | + memset(&cbstat, 0, sizeof(struct tsn_cb_status)); |
| 4640 | + |
| 4641 | + if (!tsnops->cb_get) { |
| 4642 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4643 | + netdev->name, -EPERM); |
| 4644 | + return -1; |
| 4645 | + } |
| 4646 | + |
| 4647 | + na = info->attrs[TSN_ATTR_CBSTAT]; |
| 4648 | + ret = NLA_PARSE_NESTED(cba, TSN_CBSTAT_ATTR_MAX, |
| 4649 | + na, cbstat_policy); |
| 4650 | + if (ret) { |
| 4651 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4652 | + netdev->name, -EINVAL); |
| 4653 | + return -EINVAL; |
| 4654 | + } |
| 4655 | + |
| 4656 | + index = nla_get_u32(cba[TSN_CBSTAT_ATTR_INDEX]); |
| 4657 | + |
| 4658 | + ret = tsnops->cb_get(netdev, index, &cbstat); |
| 4659 | + if (ret < 0) { |
| 4660 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4661 | + netdev->name, ret); |
| 4662 | + return ret; |
| 4663 | + } |
| 4664 | + |
| 4665 | + /* Form netlink reply data */ |
| 4666 | + ret = tsn_prepare_reply(info, genlhdr->cmd, |
| 4667 | + &rep_skb, NLMSG_ALIGN(MAX_ATTR_SIZE)); |
| 4668 | + if (ret < 0) |
| 4669 | + return ret; |
| 4670 | + |
| 4671 | + if (nla_put_string(rep_skb, TSN_ATTR_IFNAME, netdev->name)) |
| 4672 | + return -EMSGSIZE; |
| 4673 | + |
| 4674 | + cbattr = nla_nest_start_noflag(rep_skb, TSN_ATTR_CBSTAT); |
| 4675 | + if (!cbattr) |
| 4676 | + return -EMSGSIZE; |
| 4677 | + |
| 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, |
| 4689 | + cbstat.seq_his)) |
| 4690 | + return -EMSGSIZE; |
| 4691 | + |
| 4692 | + nla_nest_end(rep_skb, cbattr); |
| 4693 | + |
| 4694 | + return tsn_send_reply(rep_skb, info); |
| 4695 | +} |
| 4696 | + |
| 4697 | +static int tsn_dscp_set(struct sk_buff *skb, struct genl_info *info) |
| 4698 | +{ |
| 4699 | + struct nlattr *na; |
| 4700 | + struct nlattr *dscpa[TSN_DSCP_ATTR_MAX + 1]; |
| 4701 | + struct net_device *netdev; |
| 4702 | + const struct tsn_ops *tsnops; |
| 4703 | + int ret; |
| 4704 | + bool enable = 0; |
| 4705 | + struct tsn_port *port; |
| 4706 | + int dscp_ix; |
| 4707 | + struct tsn_qos_switch_dscp_conf dscp_conf; |
| 4708 | + |
| 4709 | + port = tsn_init_check(info, &netdev); |
| 4710 | + if (!port) |
| 4711 | + return -ENODEV; |
| 4712 | + |
| 4713 | + tsnops = port->tsnops; |
| 4714 | + |
| 4715 | + if (!info->attrs[TSN_ATTR_DSCP]) { |
| 4716 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4717 | + netdev->name, -EINVAL); |
| 4718 | + return -EINVAL; |
| 4719 | + } |
| 4720 | + |
| 4721 | + na = info->attrs[TSN_ATTR_DSCP]; |
| 4722 | + |
| 4723 | + if (!tsnops->dscp_set) { |
| 4724 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4725 | + netdev->name, -EPERM); |
| 4726 | + return -1; |
| 4727 | + } |
| 4728 | + |
| 4729 | + ret = NLA_PARSE_NESTED(dscpa, TSN_DSCP_ATTR_MAX, |
| 4730 | + na, dscp_policy); |
| 4731 | + if (ret) { |
| 4732 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4733 | + netdev->name, -EINVAL); |
| 4734 | + return -EINVAL; |
| 4735 | + } |
| 4736 | + |
| 4737 | + enable = 1; |
| 4738 | + if (dscpa[TSN_DSCP_ATTR_DISABLE]) |
| 4739 | + enable = 0; |
| 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); |
| 4744 | + if (ret < 0) { |
| 4745 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4746 | + netdev->name, ret); |
| 4747 | + return ret; |
| 4748 | + } |
| 4749 | + |
| 4750 | + tsn_simple_reply(info, TSN_CMD_REPLY, |
| 4751 | + netdev->name, 0); |
| 4752 | + |
| 4753 | + return 0; |
| 4754 | +} |
| 4755 | + |
| 4756 | +static const struct genl_ops tsnnl_ops[] = { |
| 4757 | + { |
| 4758 | + .cmd = TSN_CMD_ECHO, |
| 4759 | + .doit = tsn_echo_cmd, |
| 4760 | + .flags = GENL_ADMIN_PERM, |
| 4761 | + }, |
| 4762 | + { |
| 4763 | + .cmd = TSN_CMD_CAP_GET, |
| 4764 | + .doit = tsn_cap_get, |
| 4765 | + .flags = GENL_ADMIN_PERM, |
| 4766 | + }, |
| 4767 | + { |
| 4768 | + .cmd = TSN_CMD_QBV_SET, |
| 4769 | + .doit = tsn_qbv_set, |
| 4770 | + .flags = GENL_ADMIN_PERM, |
| 4771 | + }, |
| 4772 | + { |
| 4773 | + .cmd = TSN_CMD_QBV_GET, |
| 4774 | + .doit = tsn_qbv_get, |
| 4775 | + .flags = GENL_ADMIN_PERM, |
| 4776 | + }, |
| 4777 | + { |
| 4778 | + .cmd = TSN_CMD_QBV_GET_STATUS, |
| 4779 | + .doit = tsn_qbv_status_get, |
| 4780 | + .flags = GENL_ADMIN_PERM, |
| 4781 | + }, |
| 4782 | + { |
| 4783 | + .cmd = TSN_CMD_CB_STREAMID_SET, |
| 4784 | + .doit = tsn_cb_streamid_set, |
| 4785 | + .flags = GENL_ADMIN_PERM, |
| 4786 | + }, |
| 4787 | + { |
| 4788 | + .cmd = TSN_CMD_CB_STREAMID_GET, |
| 4789 | + .doit = tsn_cb_streamid_get, |
| 4790 | + .flags = GENL_ADMIN_PERM, |
| 4791 | + }, |
| 4792 | + { |
| 4793 | + .cmd = TSN_CMD_CB_STREAMID_GET_COUNTS, |
| 4794 | + .doit = tsn_cb_streamid_counters_get, |
| 4795 | + .flags = GENL_ADMIN_PERM, |
| 4796 | + }, |
| 4797 | + { |
| 4798 | + .cmd = TSN_CMD_QCI_CAP_GET, |
| 4799 | + .doit = tsn_qci_cap_get, |
| 4800 | + .flags = GENL_ADMIN_PERM, |
| 4801 | + }, |
| 4802 | + { |
| 4803 | + .cmd = TSN_CMD_QCI_SFI_SET, |
| 4804 | + .doit = tsn_qci_sfi_set, |
| 4805 | + .flags = GENL_ADMIN_PERM, |
| 4806 | + }, |
| 4807 | + { |
| 4808 | + .cmd = TSN_CMD_QCI_SFI_GET, |
| 4809 | + .doit = tsn_qci_sfi_get, |
| 4810 | + .flags = GENL_ADMIN_PERM, |
| 4811 | + }, |
| 4812 | + { |
| 4813 | + .cmd = TSN_CMD_QCI_SFI_GET_COUNTS, |
| 4814 | + .doit = tsn_qci_sfi_counters_get, |
| 4815 | + .flags = GENL_ADMIN_PERM, |
| 4816 | + }, |
| 4817 | + { |
| 4818 | + .cmd = TSN_CMD_QCI_SGI_SET, |
| 4819 | + .doit = tsn_qci_sgi_set, |
| 4820 | + .flags = GENL_ADMIN_PERM, |
| 4821 | + }, |
| 4822 | + { |
| 4823 | + .cmd = TSN_CMD_QCI_SGI_GET, |
| 4824 | + .doit = tsn_qci_sgi_get, |
| 4825 | + .flags = GENL_ADMIN_PERM, |
| 4826 | + }, |
| 4827 | + { |
| 4828 | + .cmd = TSN_CMD_QCI_SGI_GET_STATUS, |
| 4829 | + .doit = tsn_qci_sgi_status_get, |
| 4830 | + .flags = GENL_ADMIN_PERM, |
| 4831 | + }, |
| 4832 | + { |
| 4833 | + .cmd = TSN_CMD_QCI_FMI_SET, |
| 4834 | + .doit = tsn_qci_fmi_set, |
| 4835 | + .flags = GENL_ADMIN_PERM, |
| 4836 | + }, |
| 4837 | + { |
| 4838 | + .cmd = TSN_CMD_QCI_FMI_GET, |
| 4839 | + .doit = tsn_qci_fmi_get, |
| 4840 | + .flags = GENL_ADMIN_PERM, |
| 4841 | + }, |
| 4842 | + { |
| 4843 | + .cmd = TSN_CMD_CBS_SET, |
| 4844 | + .doit = tsn_cbs_set, |
| 4845 | + .flags = GENL_ADMIN_PERM, |
| 4846 | + }, |
| 4847 | + { |
| 4848 | + .cmd = TSN_CMD_CBS_GET, |
| 4849 | + .doit = tsn_cbs_get, |
| 4850 | + .flags = GENL_ADMIN_PERM, |
| 4851 | + }, |
| 4852 | + { |
| 4853 | + .cmd = TSN_CMD_QBU_SET, |
| 4854 | + .doit = tsn_qbu_set, |
| 4855 | + .flags = GENL_ADMIN_PERM, |
| 4856 | + }, |
| 4857 | + { |
| 4858 | + .cmd = TSN_CMD_QBU_GET_STATUS, |
| 4859 | + .doit = tsn_qbu_get_status, |
| 4860 | + .flags = GENL_ADMIN_PERM, |
| 4861 | + }, |
| 4862 | + { |
| 4863 | + .cmd = TSN_CMD_TSD_SET, |
| 4864 | + .doit = tsn_tsd_set, |
| 4865 | + .flags = GENL_ADMIN_PERM, |
| 4866 | + }, |
| 4867 | + { |
| 4868 | + .cmd = TSN_CMD_TSD_GET, |
| 4869 | + .doit = tsn_tsd_get, |
| 4870 | + .flags = GENL_ADMIN_PERM, |
| 4871 | + }, |
| 4872 | + { |
| 4873 | + .cmd = TSN_CMD_CT_SET, |
| 4874 | + .doit = tsn_ct_set, |
| 4875 | + .flags = GENL_ADMIN_PERM, |
| 4876 | + }, |
| 4877 | + { |
| 4878 | + .cmd = TSN_CMD_CBGEN_SET, |
| 4879 | + .doit = tsn_cbgen_set, |
| 4880 | + .flags = GENL_ADMIN_PERM, |
| 4881 | + }, |
| 4882 | + { |
| 4883 | + .cmd = TSN_CMD_CBREC_SET, |
| 4884 | + .doit = tsn_cbrec_set, |
| 4885 | + .flags = GENL_ADMIN_PERM, |
| 4886 | + }, |
| 4887 | + { |
| 4888 | + .cmd = TSN_CMD_CBSTAT_GET, |
| 4889 | + .doit = tsn_cbstatus_get, |
| 4890 | + .flags = GENL_ADMIN_PERM, |
| 4891 | + }, |
| 4892 | + { |
| 4893 | + .cmd = TSN_CMD_DSCP_SET, |
| 4894 | + .doit = tsn_dscp_set, |
| 4895 | + .flags = GENL_ADMIN_PERM, |
| 4896 | + }, |
| 4897 | +}; |
| 4898 | + |
| 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}, |
| 4902 | +}; |
| 4903 | + |
| 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, |
| 4909 | + .netnsok = true, |
| 4910 | + .ops = tsnnl_ops, |
| 4911 | + .n_ops = ARRAY_SIZE(tsnnl_ops), |
| 4912 | + .mcgrps = tsn_mcgrps, |
| 4913 | + .n_mcgrps = ARRAY_SIZE(tsn_mcgrps), |
| 4914 | +}; |
| 4915 | + |
| 4916 | +int tsn_port_register(struct net_device *netdev, |
| 4917 | + struct tsn_ops *tsnops, u16 groupid) |
| 4918 | +{ |
| 4919 | + struct tsn_port *port; |
| 4920 | + |
| 4921 | + if (list_empty(&port_list)) { |
| 4922 | + INIT_LIST_HEAD(&port_list); |
| 4923 | + } else { |
| 4924 | + list_for_each_entry(port, &port_list, list) { |
| 4925 | + if (port->netdev == netdev) { |
| 4926 | + pr_info("TSN device already registered!\n"); |
| 4927 | + return -1; |
| 4928 | + } |
| 4929 | + } |
| 4930 | + } |
| 4931 | + |
| 4932 | + port = kzalloc(sizeof(*port), GFP_KERNEL); |
| 4933 | + if (!port) |
| 4934 | + return -1; |
| 4935 | + |
| 4936 | + port->netdev = netdev; |
| 4937 | + port->groupid = groupid; |
| 4938 | + port->tsnops = tsnops; |
| 4939 | + port->nd.dev = netdev; |
| 4940 | + |
| 4941 | + if (groupid < GROUP_OFFSET_SWITCH) |
| 4942 | + port->type = TSN_ENDPOINT; |
| 4943 | + else |
| 4944 | + port->type = TSN_SWITCH; |
| 4945 | + |
| 4946 | + list_add_tail(&port->list, &port_list); |
| 4947 | + |
| 4948 | + if (tsnops && tsnops->device_init) |
| 4949 | + port->tsnops->device_init(netdev); |
| 4950 | + |
| 4951 | + return 0; |
| 4952 | +} |
| 4953 | +EXPORT_SYMBOL(tsn_port_register); |
| 4954 | + |
| 4955 | +void tsn_port_unregister(struct net_device *netdev) |
| 4956 | +{ |
| 4957 | + struct tsn_port *p; |
| 4958 | + |
| 4959 | + list_for_each_entry(p, &port_list, list) { |
| 4960 | + if (!p || !p->netdev) |
| 4961 | + continue; |
| 4962 | + if (p->netdev == netdev) { |
| 4963 | + if (p->tsnops->device_deinit) |
| 4964 | + p->tsnops->device_deinit(netdev); |
| 4965 | + list_del(&p->list); |
| 4966 | + kfree(p); |
| 4967 | + break; |
| 4968 | + } |
| 4969 | + } |
| 4970 | +} |
| 4971 | +EXPORT_SYMBOL(tsn_port_unregister); |
| 4972 | + |
| 4973 | +static int tsn_multicast_to_user(unsigned long event, |
| 4974 | + struct tsn_notifier_info *tsn_info) |
| 4975 | +{ |
| 4976 | + struct sk_buff *skb; |
| 4977 | + struct genlmsghdr *nlh; |
| 4978 | + int res; |
| 4979 | + struct tsn_qbv_conf *qbvdata; |
| 4980 | + |
| 4981 | + /* If new attributes are added, please revisit this allocation */ |
| 4982 | + skb = genlmsg_new(sizeof(*tsn_info), GFP_KERNEL); |
| 4983 | + if (!skb) { |
| 4984 | + pr_err("Allocation failure.\n"); |
| 4985 | + return -ENOMEM; |
| 4986 | + } |
| 4987 | + |
| 4988 | + switch (event) { |
| 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); |
| 4995 | + |
| 4996 | + if (res) { |
| 4997 | + pr_err("put data failure!\n"); |
| 4998 | + goto done; |
| 4999 | + } |
| 5000 | + |
| 5001 | + res = nla_put_u32(skb, TSN_QBV_ATTR_CTRL_CYCLETIME, |
| 5002 | + qbvdata->admin.cycle_time); |
| 5003 | + if (res) { |
| 5004 | + pr_err("put data failure!\n"); |
| 5005 | + goto done; |
| 5006 | + } |
| 5007 | + |
| 5008 | + if (qbvdata->gate_enabled) |
| 5009 | + res = nla_put_flag(skb, TSN_QBV_ATTR_ENABLE + |
| 5010 | + TSN_QBV_ATTR_CTRL_MAX); |
| 5011 | + else |
| 5012 | + res = nla_put_flag(skb, TSN_QBV_ATTR_DISABLE + |
| 5013 | + TSN_QBV_ATTR_CTRL_MAX); |
| 5014 | + if (res) { |
| 5015 | + pr_err("put data failure!\n"); |
| 5016 | + goto done; |
| 5017 | + } |
| 5018 | + |
| 5019 | + res = nla_put_u32(skb, TSN_QBV_ATTR_CTRL_UNSPEC, |
| 5020 | + tsn_info->dev->ifindex); |
| 5021 | + if (res) { |
| 5022 | + pr_err("put data failure!\n"); |
| 5023 | + goto done; |
| 5024 | + } |
| 5025 | + |
| 5026 | + break; |
| 5027 | + default: |
| 5028 | + pr_info("event not supportted!\n"); |
| 5029 | + break; |
| 5030 | + } |
| 5031 | + |
| 5032 | + (void)genlmsg_end(skb, nlh); |
| 5033 | + |
| 5034 | + res = genlmsg_multicast_allns(&tsn_family, skb, 0, |
| 5035 | + TSN_MCGRP_QBV, GFP_KERNEL); |
| 5036 | + skb = NULL; |
| 5037 | + if (res && res != -ESRCH) { |
| 5038 | + pr_err("genlmsg_multicast_allns error: %d\n", res); |
| 5039 | + goto done; |
| 5040 | + } |
| 5041 | + |
| 5042 | + if (res == -ESRCH) |
| 5043 | + res = 0; |
| 5044 | + |
| 5045 | +done: |
| 5046 | + if (skb) { |
| 5047 | + nlmsg_free(skb); |
| 5048 | + skb = NULL; |
| 5049 | + } |
| 5050 | + |
| 5051 | + return res; |
| 5052 | +} |
| 5053 | + |
| 5054 | +/* called with RTNL or RCU */ |
| 5055 | +static int tsn_event(struct notifier_block *unused, |
| 5056 | + unsigned long event, void *ptr) |
| 5057 | +{ |
| 5058 | + struct tsn_notifier_info *tsn_info; |
| 5059 | + int err = NOTIFY_DONE; |
| 5060 | + |
| 5061 | + switch (event) { |
| 5062 | + case TSN_QBV_CONFIGCHANGETIME_ARRIVE: |
| 5063 | + tsn_info = ptr; |
| 5064 | + err = tsn_multicast_to_user(event, tsn_info); |
| 5065 | + if (err) { |
| 5066 | + err = notifier_from_errno(err); |
| 5067 | + break; |
| 5068 | + } |
| 5069 | + break; |
| 5070 | + default: |
| 5071 | + pr_info("event not supportted!\n"); |
| 5072 | + break; |
| 5073 | + } |
| 5074 | + |
| 5075 | + return err; |
| 5076 | +} |
| 5077 | + |
| 5078 | +static struct notifier_block tsn_notifier = { |
| 5079 | + .notifier_call = tsn_event, |
| 5080 | +}; |
| 5081 | + |
| 5082 | +static int __init tsn_genetlink_init(void) |
| 5083 | +{ |
| 5084 | + int ret; |
| 5085 | + |
| 5086 | + pr_info("tsn generic netlink module v%d init...\n", TSN_GENL_VERSION); |
| 5087 | + |
| 5088 | + ret = genl_register_family(&tsn_family); |
| 5089 | + |
| 5090 | + if (ret != 0) { |
| 5091 | + pr_info("failed to init tsn generic netlink example module\n"); |
| 5092 | + return ret; |
| 5093 | + } |
| 5094 | + |
| 5095 | + register_tsn_notifier(&tsn_notifier); |
| 5096 | + |
| 5097 | + return 0; |
| 5098 | +} |
| 5099 | + |
| 5100 | +static void __exit tsn_genetlink_exit(void) |
| 5101 | +{ |
| 5102 | + int ret; |
| 5103 | + |
| 5104 | + ret = genl_unregister_family(&tsn_family); |
| 5105 | + if (ret != 0) |
| 5106 | + pr_info("failed to unregister family:%i\n", ret); |
| 5107 | + |
| 5108 | + unregister_tsn_notifier(&tsn_notifier); |
| 5109 | +} |
| 5110 | + |
| 5111 | +module_init(tsn_genetlink_init); |
| 5112 | +module_exit(tsn_genetlink_exit); |
| 5113 | +MODULE_LICENSE("GPL"); |