From b609b18fca93d4559c6f063f11eea57365a58e66 Mon Sep 17 00:00:00 2001 From: zitingguo Date: Wed, 25 Jun 2025 05:29:15 +0000 Subject: [PATCH 1/4] Move xgs SAI to SAI_13.2.1_EA branch Signed-off-by: zitingguo-ms --- platform/broadcom/sai.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/broadcom/sai.mk b/platform/broadcom/sai.mk index df5b62ffc82..e37be35520b 100644 --- a/platform/broadcom/sai.mk +++ b/platform/broadcom/sai.mk @@ -1,6 +1,6 @@ -LIBSAIBCM_XGS_VERSION = 13.2.0.4 +LIBSAIBCM_XGS_VERSION = 13.2.1.0 LIBSAIBCM_DNX_VERSION = 12.3.3.2 -LIBSAIBCM_XGS_BRANCH_NAME = SAI_13.2.0_GA +LIBSAIBCM_XGS_BRANCH_NAME = SAI_13.2.1_EA LIBSAIBCM_DNX_BRANCH_NAME = SAI_12.3.0_master LIBSAIBCM_XGS_URL_PREFIX = "https://sonicstorage.blob.core.windows.net/public/sai/sai-broadcom/$(LIBSAIBCM_XGS_BRANCH_NAME)/$(LIBSAIBCM_XGS_VERSION)/xgs" LIBSAIBCM_DNX_URL_PREFIX = "https://sonicstorage.blob.core.windows.net/public/sai/sai-broadcom/$(LIBSAIBCM_DNX_BRANCH_NAME)/$(LIBSAIBCM_DNX_VERSION)/dnx" From 4c0291f8f1b8271366224f227c591d997a0c59c4 Mon Sep 17 00:00:00 2001 From: zitingguo Date: Wed, 25 Jun 2025 05:33:50 +0000 Subject: [PATCH 2/4] Update changes under sdklt/ folder Signed-off-by: zitingguo-ms --- .../broadcom/saibcm-modules/sdklt/Makefile | 9 +- .../sdklt/linux/include/lkm/ngst_ioctl.h | 75 ++++ .../sdklt/linux/include/lkm/ngst_netlink.h | 44 +++ .../saibcm-modules/sdklt/linux/st/Kbuild | 27 ++ .../saibcm-modules/sdklt/linux/st/Makefile | 32 ++ .../saibcm-modules/sdklt/linux/st/ngst_main.c | 320 ++++++++++++++++++ 6 files changed, 506 insertions(+), 1 deletion(-) create mode 100644 platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_ioctl.h create mode 100644 platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_netlink.h create mode 100644 platform/broadcom/saibcm-modules/sdklt/linux/st/Kbuild create mode 100644 platform/broadcom/saibcm-modules/sdklt/linux/st/Makefile create mode 100644 platform/broadcom/saibcm-modules/sdklt/linux/st/ngst_main.c diff --git a/platform/broadcom/saibcm-modules/sdklt/Makefile b/platform/broadcom/saibcm-modules/sdklt/Makefile index 1c7882f2871..45442dcfbf5 100644 --- a/platform/broadcom/saibcm-modules/sdklt/Makefile +++ b/platform/broadcom/saibcm-modules/sdklt/Makefile @@ -58,11 +58,12 @@ BCMGENL_BLDDIR := $(OUTPUT_DIR)/bcmgenl GENL_PACKET_BLDDIR := $(OUTPUT_DIR)/genl-packet EDK_BLDDIR := $(OUTPUT_DIR)/edk PTPCLOCK_BLDDIR := $(OUTPUT_DIR)/ptpclock +ST_BLDDIR := $(OUTPUT_DIR)/st LKM_CFLAGS += -UNGKNET_NETIF_MAX -DNGKNET_NETIF_MAX=1056 -UNGKNET_FILTER_MAX -DNGKNET_FILTER_MAX=1025 export LKM_CFLAGS -KMODS := bde knet knetcb genl-packet bcmgenl edk ptpclock +KMODS := bde knet knetcb genl-packet bcmgenl edk ptpclock st kmod: $(KMODS) @@ -108,6 +109,12 @@ ptpclock: bde knet edk LKM_BLDDIR=$(PTPCLOCK_BLDDIR) $(TARGET) ln -sf $(PTPCLOCK_BLDDIR)/*.ko $(OUTPUT_DIR) +st: bde + $(MAKE) -C $(SDK)/linux/st SDK=$(SDK) \ + KBUILD_EXTRA_SYMBOLS=$(BDE_BLDDIR)/Module.symvers \ + LKM_BLDDIR=$(ST_BLDDIR) $(TARGET) + ln -sf $(ST_BLDDIR)/*.ko $(OUTPUT_DIR) + clean: $(MAKE) kmod TARGET=$@ rm -f $(OUTPUT_DIR)/*.ko diff --git a/platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_ioctl.h b/platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_ioctl.h new file mode 100644 index 00000000000..c98abbfbef1 --- /dev/null +++ b/platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_ioctl.h @@ -0,0 +1,75 @@ +/*! \file ngst_ioctl.h + * + * NGST device I/O control definitions. + * + * This file is intended for use in both kernel mode and user mode. + * + * IMPORTANT! + * All shared structures must be properly 64-bit aligned. + * + */ +/* + * Copyright 2018-2025 Broadcom. All rights reserved. + * The term 'Broadcom' refers to Broadcom Inc. and/or its subsidiaries. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * A copy of the GNU General Public License version 2 (GPLv2) can + * be found in the LICENSES folder. + */ + +#ifndef NGST_IOCTL_H +#define NGST_IOCTL_H + +#include +#include + +/*! Module information */ +#define NGST_MODULE_NAME "linux_ngst" +#define NGST_MODULE_MAJOR 61 + +/*! LUST IOCTL command magic. */ +#define NGST_IOC_MAGIC 'x' + +/*! + * \name IOCTL commands for the NGST kernel module. + * \anchor NGST_IOC_xxx + */ + +/*! \{ */ + +/*! Set/Get ST DMA memory information. */ +#define NGST_IOC_DMA_INFO _IOWR(NGST_IOC_MAGIC, 0, struct ngst_ioc_dma_info_s) + +/*! \} */ + +/*! IOCTL command return code for success. */ +#define NGST_IOC_SUCCESS 0 + +/*! Get ST DMA information */ +struct ngst_ioc_dma_info_s { + + /*! Unit */ + __u32 unit; + + /*! Virtual address */ + __u64 vaddr; + + /*! Physical address */ + __u64 paddr; + + /*! Number of DMA chunks */ + __u32 chunk_cnt; + + /*! DMA pool size */ + __u32 size; +}; + +#endif /* NGST_IOCTL_H */ diff --git a/platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_netlink.h b/platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_netlink.h new file mode 100644 index 00000000000..e7ec416fe6d --- /dev/null +++ b/platform/broadcom/saibcm-modules/sdklt/linux/include/lkm/ngst_netlink.h @@ -0,0 +1,44 @@ +/*! \file ngst_netlink.h + * + * NGST device Netlink message definitions. + * + * This file is intended for use in both kernel mode and user mode. + * + * IMPORTANT! + * All shared structures must be properly 64-bit aligned. + * + */ +/* + * Copyright 2018-2025 Broadcom. All rights reserved. + * The term 'Broadcom' refers to Broadcom Inc. and/or its subsidiaries. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * A copy of the GNU General Public License version 2 (GPLv2) can + * be found in the LICENSES folder. + */ + +#ifndef NGST_NETLINK_H +#define NGST_NETLINK_H + +#include + +#define NGST_NETLINK_PROTOCOL 17 + +#define NGST_NL_MSG_TYPE_ST_DATA_REQ 1 +#define NGST_NL_MSG_TYPE_ST_DATA_NOT_READY 2 +#define NGST_NL_MSG_TYPE_ST_DATA_RSP 3 + +struct ngst_nl_msg_hdr_s { + __u32 unit; + __u32 msg_type; +}; + +#endif /* NGST_NETLINK_H */ diff --git a/platform/broadcom/saibcm-modules/sdklt/linux/st/Kbuild b/platform/broadcom/saibcm-modules/sdklt/linux/st/Kbuild new file mode 100644 index 00000000000..345481dd4b7 --- /dev/null +++ b/platform/broadcom/saibcm-modules/sdklt/linux/st/Kbuild @@ -0,0 +1,27 @@ +# -*- Kbuild -*- +# +# Linux Streaming Telemetry kernel module. +# +# Copyright 2018-2025 Broadcom. All rights reserved. +# The term 'Broadcom' refers to Broadcom Inc. and/or its subsidiaries. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# A copy of the GNU General Public License version 2 (GPLv2) can +# be found in the LICENSES folder. +# + +obj-m := linux_ngst.o + +ccflags-y := $(LKM_CFLAGS) $(LKM_CPPFLAGS) \ + -I$(SDK)/shr/include \ + -I$(SDK)/linux/include \ + +linux_ngst-y := ngst_main.o diff --git a/platform/broadcom/saibcm-modules/sdklt/linux/st/Makefile b/platform/broadcom/saibcm-modules/sdklt/linux/st/Makefile new file mode 100644 index 00000000000..181fc7117fc --- /dev/null +++ b/platform/broadcom/saibcm-modules/sdklt/linux/st/Makefile @@ -0,0 +1,32 @@ +# +# Copyright 2018-2025 Broadcom. All rights reserved. +# The term 'Broadcom' refers to Broadcom Inc. and/or its subsidiaries. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# A copy of the GNU General Public License version 2 (GPLv2) can +# be found in the LICENSES folder. +# +# Linux Streaming Telemetry kernel module. +# + +include Kbuild + +ifeq ($(KERNELRELEASE),) + +MOD_NAME = linux_ngst + +include $(SDK)/make/lkm.mk + +endif + +.PHONY: distclean + +distclean:: diff --git a/platform/broadcom/saibcm-modules/sdklt/linux/st/ngst_main.c b/platform/broadcom/saibcm-modules/sdklt/linux/st/ngst_main.c new file mode 100644 index 00000000000..c908b53d354 --- /dev/null +++ b/platform/broadcom/saibcm-modules/sdklt/linux/st/ngst_main.c @@ -0,0 +1,320 @@ +/*! \file ngst_main.c + * + * Streaming Telemetry support module entry. + * + */ +/* + * Copyright 2018-2025 Broadcom. All rights reserved. + * The term 'Broadcom' refers to Broadcom Inc. and/or its subsidiaries. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * A copy of the GNU General Public License version 2 (GPLv2) can + * be found in the LICENSES folder. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*! \cond */ +MODULE_AUTHOR("Broadcom"); +MODULE_DESCRIPTION("Streaming Telemetry Support Module"); +MODULE_LICENSE("GPL"); +/*! \endcond */ + +/*! Maximum number of switch devices supported. */ +#ifndef NGST_NUM_SWDEV_MAX +#define NGST_NUM_SWDEV_MAX NGBDE_NUM_SWDEV_MAX +#endif + +/*! Switch device descriptor. */ +typedef struct st_dev_s { + + /*! Logical address of DMA pool. */ + void *dma_vaddr; + + /*! Logical address of buffer pool. */ + void *dma_buff_addr_va; + + /*! Physical address of DMA pool. */ + dma_addr_t dma_handle; + + /*! Size of DMA memory (in bytes). */ + size_t dma_size; + + /*! Buffer chunk size (in bytes). */ + uint32_t buff_chunk_size; + + /*! Buffer chunk count. */ + uint32_t buff_chunk_cnt; + + /*! Buffer read pointer. */ + uint32_t buff_rd_ptr; + + /*! Buffer write pointer. */ + uint32_t buff_wr_ptr; + + /*! Linux DMA device associated with DMA pool. */ + struct device *dma_dev; + +} st_dev_t; + +static st_dev_t stdevs[NGST_NUM_SWDEV_MAX]; + +/*! Netlink socket. */ +static struct sock *nl_sk; + +/*! Send netlink message to user-space. */ +static void +ngst_nl_msg_send(int unit, int pid, int msg_type, const char *payload) +{ + struct nlmsghdr *nlh; + struct sk_buff *skb_out; + int res; + int msg_size; + uint32_t payload_size; + st_dev_t *stdev; + + struct ngst_nl_msg_hdr_s rsp = { + .unit = unit, + .msg_type = msg_type, + }; + + stdev = &stdevs[unit]; + switch (msg_type) { + case NGST_NL_MSG_TYPE_ST_DATA_NOT_READY: + msg_size = sizeof(struct ngst_nl_msg_hdr_s); + skb_out = nlmsg_new(msg_size, 0); + if (!skb_out) { + printk(KERN_ERR "Failed to allocate new skb for reply\n"); + return; + } + + nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0); + NETLINK_CB(skb_out).dst_group = 0; + memcpy(nlmsg_data(nlh), &rsp, msg_size); + + break; + case NGST_NL_MSG_TYPE_ST_DATA_RSP: + payload_size = stdev->buff_chunk_size; + msg_size = sizeof(struct ngst_nl_msg_hdr_s) + payload_size; + skb_out = nlmsg_new(msg_size, 0); + if (!skb_out) { + printk(KERN_ERR "Failed to allocate new skb for reply\n"); + return; + } + + nlh = nlmsg_put(skb_out, 0, 0, NLMSG_DONE, msg_size, 0); + NETLINK_CB(skb_out).dst_group = 0; + memcpy(nlmsg_data(nlh), &rsp, sizeof(struct ngst_nl_msg_hdr_s)); + memcpy(nlmsg_data(nlh) + sizeof(struct ngst_nl_msg_hdr_s), + payload, payload_size); + break; + default: + return; + } + + res = nlmsg_unicast(nl_sk, skb_out, pid); + if (res < 0) { + printk(KERN_INFO "Error while sending back to user: %d\n", res); + } + + return; +} + + +/*! Receive netlink message from user-space. */ +static void +ngst_nl_msg_recv(struct sk_buff *skb) +{ + struct nlmsghdr *nlh; + struct ngst_nl_msg_hdr_s *rcv_nlmsg; + struct ngst_nl_msg_hdr_s *st_data_req_msg; + void *cur_dma_vaddr = NULL; + int user_pid, unit; + st_dev_t *stdev; + + nlh = (struct nlmsghdr *)skb->data; + user_pid = nlh->nlmsg_pid; + rcv_nlmsg = (struct ngst_nl_msg_hdr_s *)nlmsg_data(nlh); + + unit = rcv_nlmsg->unit; + if (unit < 0 || unit > NGST_NUM_SWDEV_MAX) { + return; + } + stdev = &stdevs[rcv_nlmsg->unit]; + + if (rcv_nlmsg->msg_type == NGST_NL_MSG_TYPE_ST_DATA_REQ) { + if (!stdev->dma_vaddr) { + ngst_nl_msg_send(unit, user_pid, + NGST_NL_MSG_TYPE_ST_DATA_NOT_READY, NULL); + return; + } + stdev->buff_wr_ptr = *((uint32_t *)(stdev->dma_vaddr)); + st_data_req_msg = (struct ngst_nl_msg_hdr_s *)nlmsg_data(nlh); + + stdev->buff_rd_ptr = + stdev->buff_rd_ptr == stdev->buff_chunk_cnt ? 0 : stdev->buff_rd_ptr; + if (stdev->buff_wr_ptr != stdev->buff_rd_ptr) { + cur_dma_vaddr = stdev->dma_buff_addr_va + + (stdev->buff_rd_ptr * stdev->buff_chunk_size); + ngst_nl_msg_send(unit, user_pid, + NGST_NL_MSG_TYPE_ST_DATA_RSP, cur_dma_vaddr); + stdev->buff_rd_ptr = stdev->buff_wr_ptr; + } else { + ngst_nl_msg_send(unit, user_pid, + NGST_NL_MSG_TYPE_ST_DATA_NOT_READY, NULL); + } + } + + return; +} + +/*! + * Generic module functions + */ + +static int +ngst_open(struct inode *inode, struct file *filp) +{ + return 0; +} + +static int +ngst_release(struct inode *inode, struct file *filp) +{ + return 0; +} + +static long +ngst_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct ngst_ioc_dma_info_s ioc; + st_dev_t *stdev; + + switch (cmd) { + case NGST_IOC_DMA_INFO: + if (copy_from_user(&ioc, + (struct ngst_ioc_dma_info_s __user *)arg, + sizeof(ioc))) + return ~EFAULT; + + if (ioc.chunk_cnt == 0 || ioc.size == 0) { + return 0; + } + stdev = &stdevs[ioc.unit]; + stdev->dma_dev = ngbde_kapi_dma_dev_get(ioc.unit); + if (!stdev->dma_dev) { + printk(KERN_INFO "Not Found ST dev %d\n", ioc.unit); + return ~EFAULT; + } + + if (!stdev->dma_vaddr) { + /* Including write pointer size */ + stdev->dma_size = ioc.size + sizeof(uint32_t); + stdev->dma_vaddr = dma_alloc_coherent(stdev->dma_dev, + stdev->dma_size, + &stdev->dma_handle, + GFP_KERNEL); + if (!stdev->dma_vaddr) { + printk(KERN_ERR "Error allocating DMA buffer\n"); + return ~ENOMEM; + } else { + printk(KERN_INFO "DMA buffer allocated successfully\n"); + } + memset((void *)stdev->dma_vaddr, 0, stdev->dma_size); + stdev->dma_buff_addr_va = stdev->dma_vaddr + sizeof(uint32_t); + + stdev->buff_chunk_cnt = ioc.chunk_cnt; + stdev->buff_chunk_size = ioc.size / ioc.chunk_cnt; + } else { + if ((stdev->buff_chunk_cnt != ioc.chunk_cnt) || + (stdev->buff_chunk_size != ioc.size / ioc.chunk_cnt)) { + printk(KERN_ERR "DMA buffer is already allocated.n"); + return ~EFAULT; + } + } + + ioc.paddr = (uint64_t)stdev->dma_handle; + if (copy_to_user((struct ngst_ioc_dma_info_s __user *)arg, + &ioc, sizeof(ioc))) + return ~EFAULT; + break; + + default: + return -EINVAL; + } + return 0; +} + +static struct file_operations ngst_fops = { + .open = ngst_open, + .release = ngst_release, + .unlocked_ioctl = ngst_ioctl, + .compat_ioctl = ngst_ioctl, +}; + +static void __exit +ngst_exit_module(void) +{ + int unit; + st_dev_t *stdev; + + unregister_chrdev(NGST_MODULE_MAJOR, NGST_MODULE_NAME); + + if (nl_sk) { + netlink_kernel_release(nl_sk); + } + + for (unit = 0; unit < NGST_NUM_SWDEV_MAX; unit++) { + stdev = &stdevs[unit]; + + if (stdev->dma_vaddr) { + dma_free_coherent(stdev->dma_dev, stdev->dma_size, + stdev->dma_vaddr, stdev->dma_handle); + } + } + printk(KERN_INFO "Broadcom NGST unloaded successfully.\n"); +} + +static int __init +ngst_init_module(void) +{ + int rv; + struct netlink_kernel_cfg cfg = { + .input = ngst_nl_msg_recv, + }; + + rv = register_chrdev(NGST_MODULE_MAJOR, NGST_MODULE_NAME, &ngst_fops); + if (rv < 0) { + printk(KERN_WARNING "%s: can't get major %d\n", + NGST_MODULE_NAME, NGST_MODULE_MAJOR); + return rv; + } + + nl_sk = netlink_kernel_create(&init_net, NGST_NETLINK_PROTOCOL, &cfg); + if (!nl_sk) { + printk(KERN_WARNING "%s: Unable to create netlink socket\n", + NGST_MODULE_NAME); + return -EFAULT; + } + printk(KERN_INFO "Broadcom NGST loaded successfully\n"); + return 0; +} + +module_exit(ngst_exit_module); +module_init(ngst_init_module); From 9da6a8b641e0f155d162a3659ceae2eef09ce725 Mon Sep 17 00:00:00 2001 From: zitingguo Date: Wed, 25 Jun 2025 05:46:10 +0000 Subject: [PATCH 3/4] Update opennsl kernel version to 13.2.1.0 Signed-off-by: zitingguo-ms --- platform/broadcom/sai-modules.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/broadcom/sai-modules.mk b/platform/broadcom/sai-modules.mk index e587443c0f1..d0ae5bad941 100644 --- a/platform/broadcom/sai-modules.mk +++ b/platform/broadcom/sai-modules.mk @@ -1,6 +1,6 @@ # Broadcom SAI modules -BRCM_OPENNSL_KERNEL_VERSION = 13.2.0.0 +BRCM_OPENNSL_KERNEL_VERSION = 13.2.1.0 BRCM_OPENNSL_KERNEL = opennsl-modules_$(BRCM_OPENNSL_KERNEL_VERSION)_amd64.deb $(BRCM_OPENNSL_KERNEL)_SRC_PATH = $(PLATFORM_PATH)/saibcm-modules From b3d35f78f3a08064667678e13be9e700386eb332 Mon Sep 17 00:00:00 2001 From: zitingguo Date: Wed, 25 Jun 2025 05:47:38 +0000 Subject: [PATCH 4/4] Update changelog Signed-off-by: zitingguo-ms --- platform/broadcom/saibcm-modules/debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platform/broadcom/saibcm-modules/debian/changelog b/platform/broadcom/saibcm-modules/debian/changelog index 8e6aded9637..9550e853560 100644 --- a/platform/broadcom/saibcm-modules/debian/changelog +++ b/platform/broadcom/saibcm-modules/debian/changelog @@ -1,3 +1,9 @@ +opennsl (13.2.1.0) unstable; urgency=medium + + * Update to Broadcom SAI 13.2.1.0 + + -- Ziting Guo Wed, 25 Jun 2025 05:46:10 +0000 + opennsl (13.2.0.0) unstable; urgency=medium * Update to Broadcom SAI 13.2.0.0