diff --git a/platform/broadcom/sai-modules.mk b/platform/broadcom/sai-modules.mk index 5f48efefa19a..84d97c09ac88 100644 --- a/platform/broadcom/sai-modules.mk +++ b/platform/broadcom/sai-modules.mk @@ -1,9 +1,8 @@ # Broadcom SAI modules -BRCM_OPENNSL_KERNEL_VERSION = 3.7.3.3-1 +BRCM_OPENNSL_KERNEL_VERSION = 4.2.1.3-1 BRCM_OPENNSL_KERNEL = opennsl-modules_$(BRCM_OPENNSL_KERNEL_VERSION)_amd64.deb $(BRCM_OPENNSL_KERNEL)_SRC_PATH = $(PLATFORM_PATH)/saibcm-modules $(BRCM_OPENNSL_KERNEL)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) SONIC_DPKG_DEBS += $(BRCM_OPENNSL_KERNEL) - diff --git a/platform/broadcom/sai.mk b/platform/broadcom/sai.mk index 00aaae57b4fa..98c61b798bd7 100644 --- a/platform/broadcom/sai.mk +++ b/platform/broadcom/sai.mk @@ -1,8 +1,8 @@ -BRCM_SAI = libsaibcm_3.7.5.1-3_amd64.deb -$(BRCM_SAI)_URL = "https://sonicstorage.blob.core.windows.net/packages/bcmsai/3.7/master/libsaibcm_3.7.5.1-3_amd64.deb?sv=2015-04-05&sr=b&sig=hwGt%2Fw1fWhauEsCXBTBmC3vC8G90iJT4DEp%2Bznwh4WY%3D&se=2034-04-16T01%3A02%3A17Z&sp=r" -BRCM_SAI_DEV = libsaibcm-dev_3.7.5.1-3_amd64.deb +BRCM_SAI = libsaibcm_4.2.1.3_amd64.deb +$(BRCM_SAI)_URL = "https://sonicstorage.blob.core.windows.net/packages/bcmsai/4.2/master/libsaibcm_4.2.1.3_amd64.deb?sv=2015-04-05&sr=b&sig=aA0Ltk2jteFuJZdr1ldj%2F5e6o7R0U5S%2FqVWvutPC7k0%3D&se=2021-08-31T04%3A08%3A35Z&sp=r" +BRCM_SAI_DEV = libsaibcm-dev_4.2.1.3_amd64.deb $(eval $(call add_derived_package,$(BRCM_SAI),$(BRCM_SAI_DEV))) -$(BRCM_SAI_DEV)_URL = "https://sonicstorage.blob.core.windows.net/packages/bcmsai/3.7/master/libsaibcm-dev_3.7.5.1-3_amd64.deb?sv=2015-04-05&sr=b&sig=nuyZOMB%2BnmDIROP60UAiDl9eG0YHAEj6u8ViTlEqjf0%3D&se=2034-04-16T01%3A01%3A51Z&sp=r" +$(BRCM_SAI_DEV)_URL = "https://sonicstorage.blob.core.windows.net/packages/bcmsai/4.2/master/libsaibcm-dev_4.2.1.3_amd64.deb?sv=2015-04-05&sr=b&sig=r%2FWgs1VEFo07sbfYK%2FDZmk83QKTzwSSe%2F3%2BN3k3uAcY%3D&se=2022-01-30T22%3A55%3A04Z&sp=r" SONIC_ONLINE_DEBS += $(BRCM_SAI) $(BRCM_SAI_DEV)_DEPENDS += $(BRCM_SAI) diff --git a/platform/broadcom/saibcm-modules/debian/changelog b/platform/broadcom/saibcm-modules/debian/changelog index 2be513ed0435..f2b0db31e662 100644 --- a/platform/broadcom/saibcm-modules/debian/changelog +++ b/platform/broadcom/saibcm-modules/debian/changelog @@ -1,19 +1,25 @@ +opennsl (4.2.1.3-1) unstable; urgency=medium + + * Update to Broadcom SAI 4.2.1.3 + + -- Mahesh Maddikayala Fri, 18 Sep 2029 10:57:47 +0000 + opennsl (3.7.3.3-1) unstable; urgency=medium - + * Port Broadcom SAI 3.7.3.3 * Cherry-pick change from master branch, 3.7.3.3-1 -- Judy Joseph Fri, 2 Dec 2019 15:32:47 +0000 opennsl (3.7.3.2-1) unstable; urgency=medium - + * Port Broadcom SAI 3.7.3.2 * Cherry-pick change from master branch, 3.7.3.2-1 -- Judy Joseph Fri, 12 Nov 2019 15:22:47 +0000 opennsl (3.7.3.1-1) unstable; urgency=medium - + * Port Broadcom SAI 3.7.3.1 * Cherry-pick change from master branch, 3.7.3.1-1 diff --git a/platform/broadcom/saibcm-modules/debian/rules b/platform/broadcom/saibcm-modules/debian/rules index 5fee0cbf8f65..64cc9b6c07e0 100755 --- a/platform/broadcom/saibcm-modules/debian/rules +++ b/platform/broadcom/saibcm-modules/debian/rules @@ -35,6 +35,8 @@ PACKAGE=opennsl-modules # modifieable for experiments or debugging m-a MA_DIR ?= /usr/share/modass KVERSION ?= 4.19.0-9-2-amd64 +KERNVERSION ?= 4.19.0-9-2 + # load generic variable handling -include $(MA_DIR)/include/generic.make # load default rules, including kdist, kdist_image, ... @@ -62,8 +64,8 @@ kdist_clean: clean dh_testdir dh_clean SDK=$(realpath .) LINUX_UAPI_SPLIT=1 DEBIAN_LINUX_HEADER=1 BUILD_KNET_CB=1 BUILD_PSAMPLE=1 \ - KERNDIR=/usr/src/linux-headers-$(KVERSION) \ - KERNEL_SRC=/usr/src/linux-headers-$(KVERSION) \ + KERNDIR=/usr/src/linux-headers-$(KERNVERSION)-common \ + KERNEL_SRC=/usr/src/linux-headers-$(KERNVERSION)-amd64 \ $(MAKE) -C systems/linux/user/x86-smp_generic_64-2_6 clean # rm -f driver/*.o driver/*.ko # @@ -78,13 +80,24 @@ configure-stamp: build-arch: configure-stamp build-arch-stamp -build-arch-stamp: +build-arch-stamp: dh_testdir + # create links + cd /; sudo mkdir -p /lib/modules/$(KERNVERSION)-amd64 + cd /; sudo rm /lib/modules/$(KERNVERSION)-amd64/build + cd /; sudo rm /lib/modules/$(KERNVERSION)-amd64/source + cd /; sudo ln -s /usr/src/linux-headers-$(KERNVERSION)-common/ /lib/modules/$(KERNVERSION)-amd64/source + cd /; sudo ln -s /usr/src/linux-headers-$(KERNVERSION)-amd64/ /lib/modules/$(KERNVERSION)-amd64/build + cd /; sudo ln -s /usr/src/linux-headers-$(KERNVERSION)-amd64/include/generated/ /usr/src/linux-headers-$(KERNVERSION)-common/include/generated + cd /; sudo ln -s /usr/src/linux-headers-$(KERNVERSION)-amd64/arch/x86/include/generated/ /usr/src/linux-headers-$(KERNVERSION)-common/arch/x86/include/generated + cd /; sudo ln -s /usr/src/linux-headers-$(KERNVERSION)-amd64/include/config/ /usr/src/linux-headers-$(KERNVERSION)-common/include/config + cd /; sudo cp /usr/src/linux-headers-$(KERNVERSION)-amd64/Module.symvers /usr/src/linux-headers-$(KERNVERSION)-common/Module.symvers + # Add here command to compile/build the package. SDK=$(realpath .) LINUX_UAPI_SPLIT=1 DEBIAN_LINUX_HEADER=1 BUILD_KNET_CB=1 BUILD_PSAMPLE=1 \ - KERNDIR=/usr/src/linux-headers-$(KVERSION) \ - KERNEL_SRC=/usr/src/linux-headers-$(KVERSION) \ + KERNDIR=/usr/src/linux-headers-$(KERNVERSION)-common \ + KERNEL_SRC=/usr/src/linux-headers-$(KERNVERSION)-amd64 \ $(MAKE) -C systems/linux/user/x86-smp_generic_64-2_6 touch $@ @@ -92,7 +105,7 @@ build-arch-stamp: #k = $(shell echo $(KVERS) | grep -q ^2.6 && echo k) build-indep: configure-stamp build-indep-stamp -build-indep-stamp: +build-indep-stamp: dh_testdir # Add here command to compile/build the arch indep package. @@ -104,15 +117,15 @@ build-indep-stamp: build: build-arch -clean: +clean: dh_testdir #dh_testroot rm -f build-arch-stamp build-indep-stamp configure-stamp # Add here commands to clean up after the build process. SDK=$(realpath .) LINUX_UAPI_SPLIT=1 DEBIAN_LINUX_HEADER=1 BUILD_KNET_CB=1 BUILD_PSAMPLE=1 \ - KERNDIR=/usr/src/linux-headers-$(KVERSION) \ - KERNEL_SRC=/usr/src/linux-headers-$(KVERSION) \ + KERNDIR=/usr/src/linux-headers-$(KERNVERSION)-common \ + KERNEL_SRC=/usr/src/linux-headers-$(KERNVERSION)-amd64 \ $(MAKE) -C systems/linux/user/x86-smp_generic_64-2_6 clean dh_clean diff --git a/platform/broadcom/saibcm-modules/include/ibde.h b/platform/broadcom/saibcm-modules/include/ibde.h index 45112eadcb4b..5f371b2667c3 100644 --- a/platform/broadcom/saibcm-modules/include/ibde.h +++ b/platform/broadcom/saibcm-modules/include/ibde.h @@ -34,6 +34,12 @@ typedef struct ibde_dev_s { sal_vaddr_t base_address; sal_vaddr_t base_address1; sal_vaddr_t base_address2; + /* a unique number representing the specific device. + * Must be different for different devices. + * May be used to identify specific devices in the system. + * May be implemented as a full PCIe address, a persistent configurable user value, ... + * Possible implementation value stores in QSPI flash memory of the device. */ + uint32 dev_unique_id; } ibde_dev_t; diff --git a/platform/broadcom/saibcm-modules/include/kcom.h b/platform/broadcom/saibcm-modules/include/kcom.h index 1e3cad0753bc..eb41e1a5aaf2 100644 --- a/platform/broadcom/saibcm-modules/include/kcom.h +++ b/platform/broadcom/saibcm-modules/include/kcom.h @@ -59,8 +59,9 @@ #define KCOM_M_DBGPKT_SET 41 /* Enbale debug packet function */ #define KCOM_M_DBGPKT_GET 42 /* Get debug packet function info */ #define KCOM_M_WB_CLEANUP 51 /* Clean up for warmbooting */ +#define KCOM_M_CLOCK_CMD 52 /* Clock Commands */ -#define KCOM_VERSION 10 /* Protocol version */ +#define KCOM_VERSION 12 /* Protocol version */ /* * Message status codes @@ -138,11 +139,10 @@ typedef struct kcom_netif_s { uint16 vlan; uint16 qnum; uint8 macaddr[6]; - uint8 ptch[2]; - uint8 itmh[4]; uint8 system_headers[KCOM_NETIF_SYSTEM_HEADERS_SIZE_MAX]; uint8 system_headers_size; char name[KCOM_NETIF_NAME_MAX]; + uint8 phys_port; } kcom_netif_t; /* @@ -225,13 +225,9 @@ typedef struct kcom_filter_s { uint8 b[KCOM_FILTER_BYTES_MAX]; uint32 w[KCOM_FILTER_WORDS_MAX]; } mask; - /** Information to parse Dune system headers */ - uint32 ftmh_lb_key_ext_size; - uint32 ftmh_stacking_ext_size; - uint32 pph_base_size; - uint32 pph_lif_ext_size[8]; - uint8 udh_enable; - uint32 udh_length_type[4]; + /** Mark to match source modid and modport */ + uint8 is_src_modport; + uint8 spa_unit; } kcom_filter_t; /* @@ -338,6 +334,19 @@ typedef struct kcom_msg_version_s { uint32 filter_max; } kcom_msg_version_t; +/* + * Request KCOM interface clock info. + */ +#define KSYNC_M_HW_INIT 0 +#define KSYNC_M_HW_DEINIT 1 +#define KSYNC_M_VERSION 2 +#define KSYNC_M_HW_TS_DISABLE 3 + +typedef struct kcom_clock_info_s { + uint8 cmd; + int32 data[8]; +} kcom_clock_info_t; + /* * Send literal string to/from kernel module. * Mainly for debugging purposes. @@ -386,6 +395,19 @@ typedef struct kcom_msg_hw_init_s { uint8 pkt_hdr_size; uint32 dma_hi; uint32 cdma_channels; + /* + * Information to parse Dune system headers + */ + uint32 ftmh_lb_key_ext_size; + uint32 ftmh_stacking_ext_size; + uint32 pph_base_size; + uint32 pph_lif_ext_size[8]; + uint32 udh_length_type[4]; + uint32 udh_size; + uint32 oamp_punted; + uint8 no_skip_udh_check; + uint8 system_headers_mode; + uint8 udh_enable; } kcom_msg_hw_init_t; /* @@ -445,6 +467,14 @@ typedef struct kcom_msg_netif_destroy_s { kcom_msg_hdr_t hdr; } kcom_msg_netif_destroy_t; +/* + * Destroy system network interface. + */ +typedef struct kcom_msg_clock_s{ + kcom_msg_hdr_t hdr; + kcom_clock_info_t clock_info; +} kcom_msg_clock_cmd_t; + /* * Get list of currently defined system network interfaces. */ @@ -486,7 +516,7 @@ typedef struct kcom_msg_filter_destroy_s { * Get list of currently defined packet filters. */ #ifndef KCOM_FILTER_MAX -#define KCOM_FILTER_MAX 128 +#define KCOM_FILTER_MAX 128 #endif typedef struct kcom_msg_filter_list_s { @@ -535,6 +565,7 @@ typedef union kcom_msg_s { kcom_msg_dbg_pkt_set_t dbg_pkt_set; kcom_msg_dbg_pkt_get_t dbg_pkt_get; kcom_msg_wb_cleanup_t wb_cleanup; + kcom_msg_clock_cmd_t clock_cmd; } kcom_msg_t; /* diff --git a/platform/broadcom/saibcm-modules/include/sal/types.h b/platform/broadcom/saibcm-modules/include/sal/types.h index b6b40f762939..7ed68f43e5e5 100644 --- a/platform/broadcom/saibcm-modules/include/sal/types.h +++ b/platform/broadcom/saibcm-modules/include/sal/types.h @@ -92,17 +92,25 @@ typedef signed int int32; /* 32-bit quantity */ #define COUNTOF(ary) ((int) (sizeof (ary) / sizeof ((ary)[0]))) -typedef uint32 sal_paddr_t; /* Physical address (PCI address) */ - #ifdef PTRS_ARE_64BITS -typedef uint64 sal_vaddr_t; /* Virtual address (Host address) */ -#define PTR_TO_INT(x) ((uint32)(((sal_vaddr_t)(x))&0xFFFFFFFF)) +typedef uint64 sal_vaddr_t; /* Virtual address (Host address) */ +typedef uint64 sal_paddr_t; /* Physical address (PCI address) */ +#define PTR_TO_INT(x) ((uint32)(((sal_vaddr_t)(x))&0xFFFFFFFF)) +#define PTR_HI_TO_INT(x) ((uint32)((((sal_vaddr_t)(x))>>32)&0xFFFFFFFF)) +#else +typedef uint32 sal_vaddr_t; /* Virtual address (Host address) */ +/* Physical address (PCI address) */ +#ifdef PHYS_ADDRS_ARE_64BITS +typedef uint64 sal_paddr_t; +#define PTR_HI_TO_INT(x) ((uint32)((((uint64)(x))>>32)&0xFFFFFFFF)) #else -typedef uint32 sal_vaddr_t; /* Virtual address (Host address) */ -#define PTR_TO_INT(x) ((uint32)(x)) +typedef uint32 sal_paddr_t; +#define PTR_HI_TO_INT(x) (0) +#endif +#define PTR_TO_INT(x) ((uint32)(x)) #endif -#define INT_TO_PTR(x) ((void *)((sal_vaddr_t)(x))) +#define INT_TO_PTR(x) ((void *)((sal_vaddr_t)(x))) #define PTR_TO_UINTPTR(x) ((sal_vaddr_t)(x)) #define UINTPTR_TO_PTR(x) ((void *)(x)) @@ -128,6 +136,7 @@ typedef union #define SAL_I2C_DEV_TYPE 0x00040 /* I2C device */ #define SAL_AXI_DEV_TYPE 0x00080 /* AXI device */ #define SAL_EMMI_DEV_TYPE 0x10000 /* EMMI device */ +#define SAL_COMPOSITE_DEV_TYPE 0x20000 /* Composite device, composed of sub-devices with buses */ #define SAL_DEV_BUS_TYPE_MASK 0xf00ff /* Odd for historical reasons */ /* Device types */ @@ -152,4 +161,4 @@ typedef union /* Special access addresses */ #define SAL_DEV_OP_EMMI_INIT 0x0fff1000 -#endif /* !_SAL_TYPES_H */ +#endif /* !_SAL_TYPES_H */ diff --git a/platform/broadcom/saibcm-modules/include/sdk_custom_config.h b/platform/broadcom/saibcm-modules/include/sdk_custom_config.h new file mode 100644 index 000000000000..74f1a4dd7490 --- /dev/null +++ b/platform/broadcom/saibcm-modules/include/sdk_custom_config.h @@ -0,0 +1,26 @@ +/* + * $Id: bitop.h,v 1.16 Broadcom SDK $ + * $Copyright: (c) 2017 Broadcom. + * Broadcom Proprietary and Confidential. All rights reserved.$ + * + * SDK custom configuration + */ + +#ifndef _SDK_CUSTOM_CONFIG_H +#define _SDK_CUSTOM_CONFIG_H + +#ifdef BCM_RPC_SUPPORT + +#define ATP_RETRY_TIMEOUT_DEFAULT 1000000 +#define ATP_RETRY_COUNT_DEFAULT 20 +/* + ** The RPC timeout interval is chosen to be twice the overall ATP + ** timeout. Since transaction requires two ATP transfers plus some work on + ** remote unit, the timeout should theoretically be twice the ATP + ** timeout plus some processing time, but since we use a very long ATP + ** timeout we ignore the processing time delay. + */ +#define RPC_REPLY_TIMEOUT (2 * ATP_RETRY_TIMEOUT_DEFAULT * ATP_RETRY_COUNT_DEFAULT) +#endif + +#endif /* _SDK_CUSTOM_CONFIG_H */ diff --git a/platform/broadcom/saibcm-modules/include/soc/devids.h b/platform/broadcom/saibcm-modules/include/soc/devids.h index 7546ef392298..bb91d90be03f 100644 --- a/platform/broadcom/saibcm-modules/include/soc/devids.h +++ b/platform/broadcom/saibcm-modules/include/soc/devids.h @@ -14,7 +14,7 @@ * version 2 (GPLv2) along with this source code. */ /* - * Copyright: (c) 2019 Broadcom. + * Copyright: (c) 2020 Broadcom. * All Rights Reserved. */ @@ -1211,11 +1211,13 @@ #define BCM56169_B0_REV_ID 0x11 #define BCM56169_B1_REV_ID 0x12 +#define BCM56980_DEVICE_ID_MASK 0xFFF0 #define BCM56980_DEVICE_ID 0xb980 #define BCM56980_A0_REV_ID 1 #define BCM56980_B0_REV_ID 0x11 #define BCM56981_DEVICE_ID 0xb981 #define BCM56981_A0_REV_ID 1 +#define BCM56981_B0_REV_ID 0x11 #define BCM56982_DEVICE_ID 0xb982 #define BCM56982_A0_REV_ID 1 #define BCM56982_B0_REV_ID 0x11 @@ -1248,6 +1250,30 @@ #define BCM56166_A0_REV_ID 1 #define BCM56166_B0_REV_ID 0x11 +#define BCM56273_DEVICE_ID 0xb273 +#define BCM56273_A0_REV_ID 1 +#define BCM56273_A1_REV_ID 2 + +#define BCM56274_DEVICE_ID 0xb274 +#define BCM56274_A0_REV_ID 1 +#define BCM56274_A1_REV_ID 2 + +#define BCM56275_DEVICE_ID 0xb275 +#define BCM56275_A0_REV_ID 1 +#define BCM56275_A1_REV_ID 2 + +#define BCM56276_DEVICE_ID 0xb276 +#define BCM56276_A0_REV_ID 1 +#define BCM56276_A1_REV_ID 2 + +#define BCM56277_DEVICE_ID 0xb277 +#define BCM56277_A0_REV_ID 1 +#define BCM56277_A1_REV_ID 2 + +#define BCM56278_DEVICE_ID 0xb278 +#define BCM56278_A0_REV_ID 1 +#define BCM56278_A1_REV_ID 2 + #define BCM53440_DEVICE_ID 0x8440 #define BCM53440_A0_REV_ID 1 #define BCM53440_B0_REV_ID 0x11 @@ -1277,18 +1303,23 @@ #define BCM56670_DEVICE_ID 0xb670 #define BCM56670_A0_REV_ID 1 #define BCM56670_B0_REV_ID 0x11 +#define BCM56670_C0_REV_ID 0x21 + #define BCM56671_DEVICE_ID 0xb671 #define BCM56671_A0_REV_ID 1 #define BCM56671_B0_REV_ID 0x11 +#define BCM56671_C0_REV_ID 0x21 #define BCM56672_DEVICE_ID 0xb672 #define BCM56672_A0_REV_ID 1 #define BCM56672_B0_REV_ID 0x11 +#define BCM56672_C0_REV_ID 0x21 #define BCM56675_DEVICE_ID 0xb675 #define BCM56675_A0_REV_ID 1 #define BCM56675_B0_REV_ID 0x11 +#define BCM56675_C0_REV_ID 0x21 #define BCM56565_DEVICE_ID 0xb565 @@ -1312,9 +1343,6 @@ #define BCM56760_A1_REV_ID 2 #define BCM56760_B0_REV_ID 0x11 -#define BCM56761_DEVICE_ID 0xb761 -#define BCM56761_A0_REV_ID 1 -#define BCM56761_B0_REV_ID 0x11 #define BCM56761_DEVICE_ID 0xb761 #define BCM56761_A0_REV_ID 1 @@ -1372,6 +1400,11 @@ #define BCM53575_A0_REV_ID 1 #define BCM53575_B0_REV_ID 0x11 +#define BCM56070_DEVICE_ID 0xb070 +#define BCM56070_A0_REV_ID 1 +#define BCM56071_DEVICE_ID 0xb071 +#define BCM56071_A0_REV_ID 1 + #define BCM56965_DEVICE_ID 0xb965 #define BCM56965_A0_REV_ID 1 @@ -1407,42 +1440,52 @@ #define BCM56370_DEVICE_ID 0xb370 #define BCM56370_A0_REV_ID 1 #define BCM56370_A1_REV_ID 0x02 +#define BCM56370_A2_REV_ID 0x03 #define BCM56371_DEVICE_ID 0xb371 #define BCM56371_A0_REV_ID 1 #define BCM56371_A1_REV_ID 0x02 +#define BCM56371_A2_REV_ID 0x03 #define BCM56372_DEVICE_ID 0xb372 #define BCM56372_A0_REV_ID 1 #define BCM56372_A1_REV_ID 0x02 +#define BCM56372_A2_REV_ID 0x03 #define BCM56374_DEVICE_ID 0xb374 #define BCM56374_A0_REV_ID 1 #define BCM56374_A1_REV_ID 0x02 +#define BCM56374_A2_REV_ID 0x03 #define BCM56375_DEVICE_ID 0xb375 #define BCM56375_A0_REV_ID 1 #define BCM56375_A1_REV_ID 0x02 +#define BCM56375_A2_REV_ID 0x03 #define BCM56376_DEVICE_ID 0xb376 #define BCM56376_A0_REV_ID 1 #define BCM56376_A1_REV_ID 0x02 +#define BCM56376_A2_REV_ID 0x03 #define BCM56377_DEVICE_ID 0xb377 #define BCM56377_A0_REV_ID 1 #define BCM56377_A1_REV_ID 0x02 +#define BCM56377_A2_REV_ID 0x03 #define BCM56577_DEVICE_ID 0xb577 #define BCM56577_A0_REV_ID 1 #define BCM56577_A1_REV_ID 0x02 +#define BCM56577_A2_REV_ID 0x03 #define BCM56578_DEVICE_ID 0xb578 #define BCM56578_A0_REV_ID 1 #define BCM56578_A1_REV_ID 0x02 +#define BCM56578_A2_REV_ID 0x03 #define BCM56579_DEVICE_ID 0xb579 #define BCM56579_A0_REV_ID 1 #define BCM56579_A1_REV_ID 0x02 +#define BCM56579_A2_REV_ID 0x03 #define BCM56770_DEVICE_ID 0xb770 #define BCM56770_A0_REV_ID 1 @@ -1450,6 +1493,14 @@ #define BCM56771_DEVICE_ID 0xb771 #define BCM56771_A0_REV_ID 1 +#define BCM56470_DEVICE_ID 0xb470 +#define BCM56470_A0_REV_ID 1 +#define BCM56471_DEVICE_ID 0xb471 +#define BCM56471_A0_REV_ID 1 +#define BCM56472_DEVICE_ID 0xb472 +#define BCM56472_A0_REV_ID 1 + + #define BCM53540_DEVICE_ID 0x8540 #define BCM53540_A0_REV_ID 1 #define BCM53547_DEVICE_ID 0x8547 @@ -1526,6 +1577,7 @@ #define DNXC_A1_REV_ID 0x0002 #define DNXC_B0_REV_ID 0x0011 #define DNXC_B1_REV_ID 0x0012 +#define DNXC_DEVID_FAMILY_MASK 0xfff0 #define BCM88790_DEVICE_ID 0x8790 #define BCM88790_A0_REV_ID DNXC_A0_REV_ID #define BCM88790_B0_REV_ID DNXC_B0_REV_ID @@ -1544,7 +1596,6 @@ #define BCM8879D_DEVICE_ID 0x879D #define BCM8879E_DEVICE_ID 0x879E #define BCM8879F_DEVICE_ID 0x879F -#define BCM_DNXF_DEVID_MASK 0xFFF0 #define ARADPLUS_DEVICE_ID 0x8660 #define ARADPLUS_A0_REV_ID 0x0001 #define BCM88660_DEVICE_ID ARADPLUS_DEVICE_ID @@ -1675,19 +1726,22 @@ #define BCM88685_DEVICE_ID 0x8685 #define BCM88685_A0_REV_ID JERICHO_PLUS_A0_REV_ID +#define BCM88687_DEVICE_ID 0x8687 +#define BCM88687_A0_REV_ID JERICHO_PLUS_A0_REV_ID + #define BCM88380_DEVICE_ID 0x8380 #define BCM88380_A0_REV_ID JERICHO_PLUS_A0_REV_ID #define BCM88381_DEVICE_ID 0x8381 #define BCM88381_A0_REV_ID JERICHO_PLUS_A0_REV_ID -#define JERICHO_2_DEVICE_ID 0x8690 -#define JERICHO_2_A0_REV_ID DNXC_A0_REV_ID -#define JERICHO_2_B0_REV_ID DNXC_B0_REV_ID -#define JERICHO_2_B1_REV_ID DNXC_B1_REV_ID -#define BCM88690_DEVICE_ID JERICHO_2_DEVICE_ID -#define BCM88690_A0_REV_ID JERICHO_2_A0_REV_ID -#define BCM88690_B0_REV_ID JERICHO_2_B0_REV_ID -#define BCM88690_B1_REV_ID JERICHO_2_B1_REV_ID +#define JERICHO2_DEVICE_ID 0x8690 +#define JERICHO2_A0_REV_ID DNXC_A0_REV_ID +#define JERICHO2_B0_REV_ID DNXC_B0_REV_ID +#define JERICHO2_B1_REV_ID DNXC_B1_REV_ID +#define BCM88690_DEVICE_ID JERICHO2_DEVICE_ID +#define BCM88690_A0_REV_ID JERICHO2_A0_REV_ID +#define BCM88690_B0_REV_ID JERICHO2_B0_REV_ID +#define BCM88690_B1_REV_ID JERICHO2_B1_REV_ID #define BCM88691_DEVICE_ID 0x8691 #define BCM88692_DEVICE_ID 0x8692 #define BCM88693_DEVICE_ID 0x8693 @@ -1703,12 +1757,56 @@ #define BCM8869D_DEVICE_ID 0x869D #define BCM8869E_DEVICE_ID 0x869E #define BCM8869F_DEVICE_ID 0x869F -#define BCM_JR2_DEVID_MASK 0xFFF0 -#define J2C_DEVICE_ID 0x8800 +#define J2C_DEVICE_ID 0x8800 +#define J2C_2ND_DEVICE_ID 0x8820 +#define J2C_DEVID_FAMILY_MASK 0xffd0 #define J2C_A0_REV_ID DNXC_A0_REV_ID +#define J2C_A1_REV_ID DNXC_A1_REV_ID #define BCM88800_DEVICE_ID J2C_DEVICE_ID +#define BCM88820_DEVICE_ID J2C_2ND_DEVICE_ID #define BCM88800_A0_REV_ID J2C_A0_REV_ID +#define BCM88800_A1_REV_ID J2C_A1_REV_ID +#define BCM88821_DEVICE_ID 0x8821 +#define BCM88826_DEVICE_ID 0x8826 +#define BCM88802_DEVICE_ID 0x8802 +#define BCM88803_DEVICE_ID 0x8803 +#define BCM88804_DEVICE_ID 0x8804 +#define BCM88805_DEVICE_ID 0x8805 +#define BCM88806_DEVICE_ID 0x8806 +#define BCM88822_DEVICE_ID 0x8822 +#define BCM88823_DEVICE_ID 0x8823 +#define BCM88824_DEVICE_ID 0x8824 +#define BCM88825_DEVICE_ID 0x8825 + +#define J2P_DEVICE_ID 0x8850 +#define J2P_A0_REV_ID DNXC_A0_REV_ID +#define BCM88850_DEVICE_ID J2P_DEVICE_ID +#define BCM88850_A0_REV_ID J2P_A0_REV_ID + +#define Q2A_DEVICE_ID 0x8480 +#define Q2A_A0_REV_ID DNXC_A0_REV_ID +#define Q2A_B0_REV_ID DNXC_B0_REV_ID +#define Q2A_B1_REV_ID DNXC_B1_REV_ID +#define BCM88480_DEVICE_ID Q2A_DEVICE_ID +#define BCM88480_A0_REV_ID Q2A_A0_REV_ID +#define BCM88480_B0_REV_ID Q2A_B0_REV_ID +#define BCM88480_B1_REV_ID Q2A_B1_REV_ID +#define BCM88481_DEVICE_ID 0x8481 +#define BCM88482_DEVICE_ID 0x8482 +#define BCM88483_DEVICE_ID 0x8483 +#define BCM88484_DEVICE_ID 0x8484 +#define BCM88485_DEVICE_ID 0x8485 +#define BCM88486_DEVICE_ID 0x8486 +#define BCM88487_DEVICE_ID 0x8487 +#define BCM88488_DEVICE_ID 0x8488 +#define BCM88489_DEVICE_ID 0x8489 +#define BCM8848A_DEVICE_ID 0x848A +#define BCM8848B_DEVICE_ID 0x848B +#define BCM8848C_DEVICE_ID 0x848C +#define BCM8848D_DEVICE_ID 0x848D +#define BCM8848E_DEVICE_ID 0x848E +#define BCM8848F_DEVICE_ID 0x848F #define QAX_DEVICE_ID 0x8470 #define QAX_A0_REV_ID 0x0001 @@ -1822,5 +1920,17 @@ #define PLX9056_DEVICE_ID 0x9056 +#ifdef BCM_LTSW_SUPPORT +#define BCM56880_DEVICE_ID 0xb880 +#define BCM56880_A0_REV_ID 0x0001 +#define BCM56880_B0_REV_ID 0x0011 +#define BCM56881_DEVICE_ID 0xb881 +#define BCM56881_A0_REV_ID 0x0001 +#define BCM56881_B0_REV_ID 0x0011 +#define BCM56883_DEVICE_ID 0xb883 +#define BCM56883_A0_REV_ID 0x0001 +#define BCM56883_B0_REV_ID 0x0011 + +#endif #endif diff --git a/platform/broadcom/saibcm-modules/make/Make.linux b/platform/broadcom/saibcm-modules/make/Make.linux index bd86ca351b6e..81e88daf16bc 100644 --- a/platform/broadcom/saibcm-modules/make/Make.linux +++ b/platform/broadcom/saibcm-modules/make/Make.linux @@ -85,7 +85,7 @@ endif build: $(MAKE) $(CMD) -DELIVER clean C_COMPILER CXX_COMPILER variable mod bcm user: +DELIVER clean C_COMPILER CXX_COMPILER variable mod bcm user issu: $(MAKE) $(CMD) $@ clean_d: clean @@ -93,5 +93,5 @@ clean_d: clean distclean: $(MAKE) $(CMD) $@ -.PHONY: build clean distclean clean_d DELIVER variable mod bcm user +.PHONY: build clean distclean clean_d DELIVER variable mod bcm user issu diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-gto b/platform/broadcom/saibcm-modules/make/Makefile.linux-gto index 786b4cc26bc3..4a20a99dac69 100644 --- a/platform/broadcom/saibcm-modules/make/Makefile.linux-gto +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-gto @@ -97,6 +97,21 @@ ifdef SHADOW_PLX CFLAGS += -DBCM_PLX9656_LOCAL_BUS -DBDE_LINUX_NON_INTERRUPTIBLE -DSHADOW_SVK endif +ifdef LTSW_CHIPS +# Default open source target build +OPENSRC_BUILD ?= uclibc_201402_ppc + +# Hardware interface (see $SDKLT/bcma/sys/probe directory) +SYSTEM_INTERFACE ?= ngbde + +# Turn on direct register access if running on real hardware. +ifeq (ngbde,$(SYSTEM_INTERFACE)) +LTSW_ADD_CPPFLAGS += -DBCMDRD_CONFIG_MEMMAP_DIRECT=1 +endif + +export SYSTEM_INTERFACE +endif + ifeq (,$(KFLAGS)) KFLAGS := -D__KERNEL__ -m32 -nostdinc -isystem $(KFLAG_INCLD) -I$(LINUX_INCLUDE) -include $(LINUX_INCLUDE)/generated/uapi/linux/version.h -include $(LINUX_INCLUDE)/generated/autoconf.h -I$(KERNDIR)/arch/powerpc -I$(KERNDIR)/arch/powerpc/include -I$(KERNDIR)/include/asm-powerpc -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -msoft-float -pipe -ffixed-r2 -mmultiple -mno-altivec -funit-at-a-time -Wa,-me500 -fomit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign endif diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-gts b/platform/broadcom/saibcm-modules/make/Makefile.linux-gts new file mode 100644 index 000000000000..ddc94afa13fe --- /dev/null +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-gts @@ -0,0 +1,142 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# $Id: Makefile.linux-xlr-4_19,v 0.1 Broadcom SDK $ +# $Copyright: (c) 2015 Broadcom Corp. +# All Rights Reserved.$ + +# +# XLR system make file. +# +# Most of this was taken from target x86-smp_generic_64-2_6. +# + + +############################################################################# +# this segment is custom and not sourced from any existing makefile # +# (base thanks to http:confluence.broadcom.com/display/NTSWSW/X86+System) # +############################################################################# + +# set up a basic feature list. tcl, etc. # +#ifeq (,$(FEATURE_LIST)) +#FEATURE_LIST = TCL BFD PTP CINT L3 I2C MEM_SCAN EDITLINE BCM_SAL_PROFILE CUSTOMER TEST CHASSIS MSTP RCPU +#endif + +# some basic path variables for tools and kernel source, etc # +export XLR_TOOLS_BASE = /projects/ntsw-tools/linux/xlr-419 +TOOLCHAIN_DIR = $(XLR_TOOLS_BASE)/buildroot/host/usr +KERNDIR = $(XLR_TOOLS_BASE)/kernel/linux + +# set up cross compile prefix, tools dir variables. # +export CROSS_COMPILE := x86_64-broadcom-linux-gnu- +export TOOLS_DIR := $(TOOLCHAIN_DIR)/bin + +# architecture. # +ARCH = x86_64 +TARGET_ARCHITECTURE = x86_64-broadcom-linux-gnu + +# Noisy kernel build +KBUILD_VERBOSE = 1 + +export ARCH KBUILD_VERBOSE + +# set up paths. # +export LIBRARY_PATH := $(TOOLCHAIN_DIR)/lib:$(TOOLCHAIN_DIR)/lib64:$(LIBRARY_PATH) +export PATH := $(TOOLCHAIN_DIR)/bin:$(KERNDIR):$(PATH) + +# set up SYSINC path # +export SYSINC := $(XLR_TOOLS_BASE)/buildroot/host/usr/lib/gcc/$(TARGET_ARCHITECTURE)/5.4.0/include + + +# CFLAGS/CFGFLAGS # +CFLAGS += -DUSE_LINUX_BDE_MMAP=1 +#CFLAGS += -DBDE_LINUX_USE_MSI_INTERRUPT +CFLAGS += -Wno-error=unused-value +CFLAGS += -Wno-error=unused-but-set-variable +CFLAGS += -Wno-error=maybe-uninitialized +CFLAGS += -Wno-error=cpp +CFLAGS += -Wno-error=aggressive-loop-optimizations +CFLAGS += -Wno-error=array-bounds +CFLAGS += -Wno-error=strict-overflow +CFLAGS += -L$(TOOLCHAIN_DIR)/lib +CFLAGS += -L$(TOOLCHAIN_DIR)/lib64 +#CFLAGS += -Wl,--rpath=/lib64 # may need to set rpath and dynamic-linker path here (and possibly in KLFAGS below) in the future, # +#CFLAGS += -Wl,--dynamic-linker=/lib64/ld-linux-x86-64.so.2 # if we want to build the target executable to be used with shared libs # + +#XLDK-568 fix inline references +CFGFLAGS += -fgnu89-inline + + +# set up KFLAGS appropriately. # +ifeq (,$(KFLAGS)) +KFLAGS := -L$(TOOLCHAIN_DIR)/lib -L$(TOOLCHAIN_DIR)/lib64 -I$(KERNDIR) -lc -nostdinc -isystem $(SYSINC) -Iinclude -I$(KERNDIR)/arch/x86/include -I$(KERNDIR)/arch/x86/include/generated -I$(KERNDIR)/arch/x86/include/generated/uapi -I$(KERNDIR)/arch/x86/include/uapi -I$(KERNDIR)/include -I$(KERNDIR)/include/generated -I$(KERNDIR)/include/generated/uapi -I$(KERNDIR)/include/uapi -include $(KERNDIR)/include/generated/autoconf.h -D__KERNEL__ -DNDEBUG -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Wno-format-security -fno-delete-null-pointer-checks -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -fstack-protector -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -Wframe-larger-than=1024 -fno-omit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-dwarf2-cfi-asm -fconserve-stack +endif + + +###################################################################### +# this segment comes from make/Makefile.linux-x86-smp_generic_64-2_6 # +###################################################################### +CFGFLAGS += -DLONGS_ARE_64BITS +CFGFLAGS += -DPTRS_ARE_64BITS +CFGFLAGS += -DSAL_SPL_LOCK_ON_IRQ + + +############################################################## +# This segment comes from make/Makefile.linux-x86-common-2_6 # +############################################################## +CFGFLAGS += -DSYS_BE_PIO=0 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=0 +ENDIAN = LE_HOST=1 +CFGFLAGS += -D$(ENDIAN) +CFGFLAGS += -DBCM_PLATFORM_STRING=\"X86\" +CFGFLAGS += -DSAL_BDE_DMA_MEM_DEFAULT=32 + +# Extra variables. +EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) + +comma = , +basetarget = $(basename $(notdir $@)) +modname = $(basetarget) + +name-fix = $(subst $(comma),_,$(subst -,_,$1)) +basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" +modname_flags = $(if $(filter 1,$(words $(modname))),\ +-D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") + +ifdef LTSW_CHIPS +# Ensure we do not use an out-of-date libelf.so +ELFUTILS_MIN = 158 +ELFUTILS_DIR ?= /projects/ntsw-tools/lib + +# Default open source target build +OPENSRC_BUILD ?= fed21-x86_64 + +# Hardware interface (see $SDKLT/bcma/sys/probe directory) +SYSTEM_INTERFACE ?= ngbde + +# Turn on direct register access if running on real hardware. +ifeq (ngbde,$(SYSTEM_INTERFACE)) +LTSW_ADD_CPPFLAGS += -DBCMDRD_CONFIG_MEMMAP_DIRECT=1 +endif + +export SYSTEM_INTERFACE +endif + +ifneq ($(targetplat),user) +# By default we exclude -Werror from x86 kernel builds +BCM_CFLAGS = -Wall +include ${SDK}/make/Makefile.linux-kernel-2_6 +endif + + diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc b/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc index 092e474e2563..7d8adb98de38 100644 --- a/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc @@ -27,11 +27,14 @@ endif # TARGET_ARCHITECTURE Compiler for target architecture # KERNDIR Kernel directory for iPROC-CMICd devices ifeq (BE,$(ENDIAN_MODE)) +#While BE mode is supported, it's use is very limited. We had a specific customer +#request for BE support but don't currently mainstream it. So a 5.1.0 version +#has not been built. Continue using 5.0.3 for any BE support TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/linux/iproc_ldks/xldk50-be/XLDK32 TARGET_ARCHITECTURE:=armeb-broadcom-linux-uclibcgnueabi KERNDIR ?= $(TOOLCHAIN_BASE_DIR)/kernel/linux else -TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/linux/iproc_ldks/xldk50/XLDK32 +TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/linux/iproc_ldks/xldk51/XLDK32 TARGET_ARCHITECTURE:= arm-broadcom-linux-uclibcgnueabi KERNDIR ?= $(TOOLCHAIN_BASE_DIR)/kernel/linux endif @@ -44,9 +47,10 @@ endif TOOLCHAIN_BIN_DIR=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/bin override PATH:=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/$(TARGET_ARCHITECTURE)/bin:$(TOOLCHAIN_BIN_DIR):$(PATH) LD_LIBRARY_PATH=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/lib - export TOOLCHAIN_BIN_DIR LD_LIBRARY_PATH +CROSS_GCC_VER ?= $(shell $(TOOLCHAIN_BIN_DIR)/$(CROSS_COMPILE)gcc -dumpversion) + # Default Linux include directory ifeq (,$(LINUX_INCLUDE)) LINUX_INCLUDE := $(KERNDIR)/include @@ -61,6 +65,12 @@ ENDIAN = LE_HOST=1 endif CFLAGS += -fno-aggressive-loop-optimizations +CFLAGS += -Wno-error=maybe-uninitialized +CFLAGS += -Wno-error=array-bounds +CFLAGS += -fgnu89-inline +ifeq "$(shell expr `echo $(CROSS_GCC_VER) | cut -f1 -d.` \>= 7)" "1" + CFLAGS += -Wno-error=bool-operation +endif CFGFLAGS += -D$(ENDIAN) -DIPROC_CMICD CFGFLAGS += -DBCM_PLATFORM_STRING=\"IPROC_CMICD\" @@ -82,7 +92,7 @@ basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" modname_flags = $(if $(filter 1,$(words $(modname))),\ -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") -KFLAG_INCLD ?= $(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/lib/gcc/$(TARGET_ARCHITECTURE)/4.9.4/include +KFLAG_INCLD ?= $(LD_LIBRARY_PATH)/gcc/$(TARGET_ARCHITECTURE)/$(CROSS_GCC_VER)/include ifeq (,$(KFLAGS)) KFLAGS := -D__LINUX_ARM_ARCH__=7 -D__KERNEL__ -nostdinc -isystem $(KFLAG_INCLD) -I$(LINUX_INCLUDE) -include $(LINUX_INCLUDE)/generated/autoconf.h -I$(KERNDIR)/arch/arm/include -I$(KERNDIR)/arch/arm/include/generated -I$(KERNDIR)/arch/arm/mach-iproc/include -Wall -Wstrict-prototypes -Wno-trigraphs -Os -fno-strict-aliasing -fno-common -marm -mabi=aapcs-linux -fno-pic -pipe -msoft-float -ffreestanding -march=armv7-a -mfpu=vfp -mfloat-abi=softfp -fomit-frame-pointer -g -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -mlong-calls diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc-4_4 b/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc-4_4 new file mode 100644 index 000000000000..df31f84e9d8f --- /dev/null +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc-4_4 @@ -0,0 +1,92 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# $Id: Makefile.linux-iproc Exp $ +# $Copyright: (c) 2007 Broadcom Corp. +# All Rights Reserved.$ +# Makefile for iproc-CMICd + +# User must select one platform from below.By default ARM_LINUX is selected. . +ifeq (,$(BUILD_PLATFORM)) +BUILD_PLATFORM=ARM_LINUX +endif + +# TOOLCHAIN_BASE_DIR Toolchain base directory for iPROC-CMICd devices +# TARGET_ARCHITECTURE Compiler for target architecture +# KERNDIR Kernel directory for iPROC-CMICd devices +ifeq (BE,$(ENDIAN_MODE)) +TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/linux/iproc_ldks/xldk40-be/XLDK +TARGET_ARCHITECTURE:=armeb-broadcom-linux-uclibcgnueabi +KERNDIR ?= $(TOOLCHAIN_BASE_DIR)/kernel/linux +else +TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/linux/iproc_ldks/xldk40/XLDK +TARGET_ARCHITECTURE:= arm-broadcom-linux-uclibcgnueabi +KERNDIR ?= $(TOOLCHAIN_BASE_DIR)/kernel/linux +endif + +ifeq (,$(CROSS_COMPILE)) +CROSS_COMPILE:= $(TARGET_ARCHITECTURE)- +endif + +# arm9tools +TOOLCHAIN_BIN_DIR=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/bin +override PATH:=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/$(TARGET_ARCHITECTURE)/bin:$(TOOLCHAIN_BIN_DIR):$(PATH) +LD_LIBRARY_PATH=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/lib + +export TOOLCHAIN_BIN_DIR LD_LIBRARY_PATH + +# Default Linux include directory +ifeq (,$(LINUX_INCLUDE)) +LINUX_INCLUDE := $(KERNDIR)/include +endif + +ifeq (BE,$(ENDIAN_MODE)) +CFGFLAGS += -DSYS_BE_PIO=1 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=1 +ENDIAN = BE_HOST=1 +else +CFGFLAGS += -DSYS_BE_PIO=0 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=0 +ENDIAN = LE_HOST=1 +endif + +CFGFLAGS += -D$(ENDIAN) -DIPROC_CMICD +CFGFLAGS += -DBCM_PLATFORM_STRING=\"IPROC_CMICD\" + +ARCH = arm +KBUILD_VERBOSE = 1 + +export ARCH KBUILD_VERBOSE + +comma = , +basetarget = $(basename $(notdir $@)) +modname = $(basetarget) + +# Extra variables. +EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) + +name-fix = $(subst $(comma),_,$(subst -,_,$1)) +basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" +modname_flags = $(if $(filter 1,$(words $(modname))),\ + -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") + +KFLAG_INCLD ?= $(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/lib/gcc/$(TARGET_ARCHITECTURE)/4.9.3/include + +ifeq (,$(KFLAGS)) +KFLAGS := -D__LINUX_ARM_ARCH__=7 -D__KERNEL__ -nostdinc -isystem $(KFLAG_INCLD) -I$(LINUX_INCLUDE) -include $(LINUX_INCLUDE)/generated/autoconf.h -I$(KERNDIR)/arch/arm/include -I$(KERNDIR)/arch/arm/include/generated -I$(KERNDIR)/arch/arm/mach-iproc/include -Wall -Wstrict-prototypes -Wno-trigraphs -Os -fno-strict-aliasing -fno-common -marm -mabi=aapcs-linux -fno-pic -pipe -msoft-float -ffreestanding -march=armv7-a -mfpu=vfp -mfloat-abi=softfp -fomit-frame-pointer -g -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -mlong-calls +KFLAGS += -I$(LINUX_INCLUDE)/uapi -I$(LINUX_INCLUDE)/generated/uapi -I$(KERNDIR)/arch/arm/include/uapi -I$(KERNDIR)/arch/arm/include/generated/uapi +endif + +ifneq ($(targetplat),user) +include ${SDK}/make/Makefile.linux-kernel-3_6 +endif diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc_64 b/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc_64 new file mode 100644 index 000000000000..dbccd7e25734 --- /dev/null +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-iproc_64 @@ -0,0 +1,106 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# $Id: Makefile.linux-iproc Exp $ +# $Copyright: (c) 2007 Broadcom Corp. +# All Rights Reserved.$ +# Makefile for iproc-CMICd + +# User must select one platform from below.By default ARM_LINUX is selected. . +ifeq (,$(BUILD_PLATFORM)) +BUILD_PLATFORM=ARM_LINUX +endif + +# TOOLCHAIN_BASE_DIR Toolchain base directory for iPROC-CMICd devices +# TARGET_ARCHITECTURE Compiler for target architecture +# KERNDIR Kernel directory for iPROC-CMICd devices +ifeq (BE,$(ENDIAN_MODE)) +#We've never actually built a 64 BE executable. Just here for any future +#customer requirements. +TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/linux/iproc_ldks/xldk51-be/XLDK64 +TARGET_ARCHITECTURE ?= aarch64_be-broadcom-linux-uclibc +KERNDIR ?= $(TOOLCHAIN_BASE_DIR)/kernel/linux +else +TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/linux/iproc_ldks/xldk51/XLDK64 +TARGET_ARCHITECTURE ?= aarch64-broadcom-linux-uclibc +KERNDIR ?= $(TOOLCHAIN_BASE_DIR)/kernel/linux +endif + +ifeq (,$(CROSS_COMPILE)) +CROSS_COMPILE:= $(TARGET_ARCHITECTURE)- +endif + +# A72 tools +TOOLCHAIN_BIN_DIR=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/bin +override PATH:=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/$(TARGET_ARCHITECTURE)/bin:$(TOOLCHAIN_BIN_DIR):$(PATH) +LD_LIBRARY_PATH=$(TOOLCHAIN_BASE_DIR)/buildroot/host/usr/lib +export TOOLCHAIN_BIN_DIR LD_LIBRARY_PATH + +CROSS_GCC_VER ?= $(shell $(TOOLCHAIN_BIN_DIR)/$(CROSS_COMPILE)gcc -dumpversion) + +# Default Linux include directory +ifeq (,$(LINUX_INCLUDE)) +LINUX_INCLUDE := $(KERNDIR)/include +endif + +ifeq (BE,$(ENDIAN_MODE)) +CFGFLAGS += -DSYS_BE_PIO=1 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=1 +ENDIAN = BE_HOST=1 +else +CFGFLAGS += -DSYS_BE_PIO=0 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=0 +ENDIAN = LE_HOST=1 +endif + +CFLAGS += -DPTRS_ARE_64BITS -DLONGS_ARE_64BITS +CFLAGS += -DPHYS_ADDRS_ARE_64BITS +CFLAGS += -fno-aggressive-loop-optimizations -fno-strict-overflow +CFLAGS += -Wno-error=maybe-uninitialized +CFLAGS += -Wno-error=array-bounds +CFLAGS += -fgnu89-inline +ifeq "$(shell expr `echo $(CROSS_GCC_VER) | cut -f1 -d.` \>= 7)" "1" + CFLAGS += -Wno-error=bool-operation +endif + + +CFGFLAGS += -D$(ENDIAN) -DIPROC_CMICD +CFGFLAGS += -DBCM_PLATFORM_STRING=\"IPROC_CMICD\" +CFGFLAGS += -DSAL_BDE_DMA_MEM_DEFAULT=16 + +ARCH = arm64 +KBUILD_VERBOSE = 1 + +export ARCH KBUILD_VERBOSE + +comma = , +basetarget = $(basename $(notdir $@)) +modname = $(basetarget) + +# Extra variables. +EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) + +name-fix = $(subst $(comma),_,$(subst -,_,$1)) +basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" +modname_flags = $(if $(filter 1,$(words $(modname))),\ + -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") + +KFLAG_INCLD ?= $(LD_LIBRARY_PATH)/gcc/$(TARGET_ARCHITECTURE)/$(CROSS_GCC_VER)/include + +ifeq (,$(KFLAGS)) +KFLAGS := -D__LINUX_ARM_ARCH__=8 -D__KERNEL__ -DPTRS_ARE_64BITS -DLONGS_ARE_64BITS -nostdinc -isystem $(KFLAG_INCLD) -I$(LINUX_INCLUDE) -include $(LINUX_INCLUDE)/generated/autoconf.h -I$(KERNDIR)/arch/arm64/include -I$(KERNDIR)/arch/arm64/include/generated -I$(KERNDIR)/arch/arm64/include/generated/uapi -I$(KERNDIR)/arch/arm64/include/generated/asm -I$(KERNDIR)/include/uapi -I$(KERNDIR)/include/generated/uapi -I$(KERNDIR)/arch/arm64/include/uapi -Wall -Wstrict-prototypes -Wno-trigraphs -Os -fno-strict-aliasing -fno-common -fno-pic -pipe -ffreestanding -fomit-frame-pointer -g -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign -mcmodel=large +endif + +ifneq ($(targetplat),user) +include ${SDK}/make/Makefile.linux-kernel-3_6 +endif diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-slk b/platform/broadcom/saibcm-modules/make/Makefile.linux-slk new file mode 100644 index 000000000000..00131c2f2af9 --- /dev/null +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-slk @@ -0,0 +1,146 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# $Id: Makefile.linux-slk-3_14,v 1.2 Broadcom SDK $ +# $Copyright: (c) 2013 Broadcom Corp. +# All Rights Reserved.$ +# Makefile for SLK(BCM957812) + +# User must select one platform from below.By default ARM_LINUX is selected. . +ifeq (,$(BUILD_PLATFORM)) +BUILD_PLATFORM=ARM_LINUX +endif + +# Toolchain base directory for NS2 XMC card +ifeq (BE,$(ENDIAN_MODE)) +TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/toolchains/slk/linaro-be +TARGET_ARCHITECTURE:=aarch64_be-linux-gnu +KERNDIR ?= /projects/ntsw-tools/linux/iproc_ldks/slk-be/poky/brcm-released-source/git +else +TOOLCHAIN_BASE_DIR ?= /projects/ntsw-tools/toolchains/slk/linaro-le +# Compiler for target architecture +TARGET_ARCHITECTURE:= aarch64-linux-gnu +# Kernel directory +KERNDIR ?= /projects/ntsw-tools/linux/iproc_ldks/slk/poky/brcm-released-source/git +endif + +ifeq (,$(CROSS_COMPILE)) +CROSS_COMPILE:= $(TARGET_ARCHITECTURE)- +endif + +# armtools +TOOLCHAIN_BIN_DIR=$(TOOLCHAIN_BASE_DIR)/bin +override PATH:=$(TOOLCHAIN_BIN_DIR):$(PATH) +LD_LIBRARY_PATH=$(TOOLCHAIN_BASE_DIR)/lib + +export TOOLCHAIN_BIN_DIR LD_LIBRARY_PATH + +# Default Linux include directory +ifeq (,$(LINUX_INCLUDE)) +LINUX_INCLUDE := $(KERNDIR)/include +endif + +ifeq (BE,$(ENDIAN_MODE)) +CFGFLAGS += -DSYS_BE_PIO=1 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=1 +ENDIAN = BE_HOST=1 +else +CFGFLAGS += -DSYS_BE_PIO=0 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=0 +ENDIAN = LE_HOST=1 +endif + +CFGFLAGS += -D$(ENDIAN) -DBCM958525 +CFGFLAGS += -DBCM_PLATFORM_STRING=\"SLK_BCM957812\" +CFGFLAGS += -DSAL_BDE_DMA_MEM_DEFAULT=32 +ifeq (1,$(SLK_32BIT)) +CFGFLAGS += -DSAL_BDE_32BIT_USER_64BIT_KERNEL +else +CFGFLAGS += -DPTRS_ARE_64BITS -DLONGS_ARE_64BITS +endif +CFGFLAGS += -DPHYS_ADDRS_ARE_64BITS + +CFLAGS += -Wno-unused-value -Wno-unused-but-set-variable -Wno-sizeof-pointer-memaccess -fno-aggressive-loop-optimizations + +ifdef DPP_CHIPS +CFLAGS += -DDUNE_BCM -D__DUNE_LINUX_BCM_CPU_PCP_DMA__ +CFGFLAGS += -DSOC_CM_FUNCTION +endif + +ifdef DFE_CHIPS +CFLAGS += -DDUNE_BCM +CFGFLAGS += -DSOC_CM_FUNCTION +endif + +ifdef SAND_CHIPS +CFLAGS += -D__DUNE_SLK_BCM_CPU__ -D__DUNE_LINUX_BCM_CPU_PCIE__ +endif + +# Enable cached DMA memory by default +ifeq (,$(SAL_BDE_USE_CACHED_DMA_MEM)) +SAL_BDE_USE_CACHED_DMA_MEM = 1 +endif +ifeq ($(SAL_BDE_USE_CACHED_DMA_MEM),1) +CFGFLAGS += -DSAL_BDE_CACHE_DMA_MEM +endif + +ifeq (1,$(SLK_32BIT)) +ARCH = arm +else +ARCH = arm64 +endif + +KBUILD_VERBOSE = 1 + +export ARCH KBUILD_VERBOSE + +comma = , +basetarget = $(basename $(notdir $@)) +modname = $(basetarget) + +# Extra variables. +EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) + +name-fix = $(subst $(comma),_,$(subst -,_,$1)) +basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" +modname_flags = $(if $(filter 1,$(words $(modname))),\ + -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") + +KFLAG_INCLD = $(TOOLCHAIN_BASE_DIR)/lib/gcc/$(TARGET_ARCHITECTURE)/4.9.2/include + +ifeq (,$(KFLAGS)) +KFLAGS := -D__LINUX_ARM_ARCH__=8 -D__KERNEL__ -DPTRS_ARE_64BITS -DLONGS_ARE_64BITS -nostdinc -isystem $(KFLAG_INCLD) -I$(LINUX_INCLUDE) -include $(LINUX_INCLUDE)/generated/autoconf.h -I$(KERNDIR)/arch/arm64/include -I$(KERNDIR)/arch/arm64/include/generated -I$(KERNDIR)/arch/arm64/include/generated/asm -I$(KERNDIR)/include/uapi -I$(KERNDIR)/include/generated/uapi -I$(KERNDIR)/arch/arm64/include/uapi -Wall -Wstrict-prototypes -Wno-trigraphs -Os -fno-strict-aliasing -fno-common -fno-pic -pipe -ffreestanding -fomit-frame-pointer -g -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign +endif + +ifdef LTSW_CHIPS +# Default open source target build +ifeq (BE,$(ENDIAN_MODE)) +OPENSRC_BUILD ?= linaro_arm64_be +else +OPENSRC_BUILD ?= linaro_arm64_le +endif + +# Hardware interface (see $SDKLT/bcma/sys/probe directory) +SYSTEM_INTERFACE ?= ngbde + +# Turn on direct register access if running on real hardware. +ifeq (ngbde,$(SYSTEM_INTERFACE)) +LTSW_ADD_CPPFLAGS += -DBCMDRD_CONFIG_MEMMAP_DIRECT=1 +endif + +export SYSTEM_INTERFACE +endif + +ifneq ($(targetplat),user) +include ${SDK}/make/Makefile.linux-kernel-3_6 +endif diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-generic-common-2_6 b/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-generic-common-2_6 index bf0ea85d578e..397d2f332ff7 100644 --- a/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-generic-common-2_6 +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-generic-common-2_6 @@ -1,15 +1,15 @@ # # Copyright 2017 Broadcom -# +# # 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 (the "GPL"). -# +# # 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 version 2 (GPLv2) for more details. -# +# # You should have received a copy of the GNU General Public License # version 2 (GPLv2) along with this source code. # diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-smp_generic_64-2_6 b/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-smp_generic_64-2_6 index bc0230ec8226..27edc6017ece 100644 --- a/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-smp_generic_64-2_6 +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-x86-smp_generic_64-2_6 @@ -1,15 +1,15 @@ # # Copyright 2017 Broadcom -# +# # 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 (the "GPL"). -# +# # 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 version 2 (GPLv2) for more details. -# +# # You should have received a copy of the GNU General Public License # version 2 (GPLv2) along with this source code. # @@ -35,11 +35,27 @@ KFLAGS += -fno-pie -mcmodel=kernel endif LINUX_UAPI = $(LINUX_INCLUDE)/uapi +ifneq (,$(shell ls $(LINUX_UAPI) 2>/dev/null)) KFLAGS += -I$(LINUX_INCLUDE)/uapi -I$(LINUX_INCLUDE)/generated/uapi -I$(KERNDIR)/arch/x86/include/generated -I$(KERNDIR)/arch/x86/include/uapi -I$(KERNDIR)/arch/x86/include/generated/uapi +endif + +ifdef LTSW_CHIPS +# Ensure we do not use an out-of-date libelf.so +ELFUTILS_MIN = 158 +ELFUTILS_DIR ?= /projects/ntsw-tools/lib + +# Default open source target build +OPENSRC_BUILD ?= x86_64 + +# Hardware interface (see $SDKLT/bcma/sys/probe directory) +SYSTEM_INTERFACE ?= ngbde + +# Turn on direct register access if running on real hardware. +ifeq (ngbde,$(SYSTEM_INTERFACE)) +LTSW_ADD_CPPFLAGS += -DBCMDRD_CONFIG_MEMMAP_DIRECT=1 +endif -ifeq (1,$(DEBIAN_LINUX_HEADER)) -KERNDIR_COMMON := $(subst amd64,common,$(KERNDIR)) -KFLAGS += -I$(KERNDIR_COMMON)/include -I$(KERNDIR_COMMON)/include/uapi -I$(KERNDIR_COMMON)/arch/x86/include -I$(KERNDIR_COMMON)/arch/x86/include/uapi +export SYSTEM_INTERFACE endif include ${SDK}/make/Makefile.linux-x86-common-2_6 diff --git a/platform/broadcom/saibcm-modules/make/Makefile.linux-xlr b/platform/broadcom/saibcm-modules/make/Makefile.linux-xlr new file mode 100644 index 000000000000..ddc94afa13fe --- /dev/null +++ b/platform/broadcom/saibcm-modules/make/Makefile.linux-xlr @@ -0,0 +1,142 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# $Id: Makefile.linux-xlr-4_19,v 0.1 Broadcom SDK $ +# $Copyright: (c) 2015 Broadcom Corp. +# All Rights Reserved.$ + +# +# XLR system make file. +# +# Most of this was taken from target x86-smp_generic_64-2_6. +# + + +############################################################################# +# this segment is custom and not sourced from any existing makefile # +# (base thanks to http:confluence.broadcom.com/display/NTSWSW/X86+System) # +############################################################################# + +# set up a basic feature list. tcl, etc. # +#ifeq (,$(FEATURE_LIST)) +#FEATURE_LIST = TCL BFD PTP CINT L3 I2C MEM_SCAN EDITLINE BCM_SAL_PROFILE CUSTOMER TEST CHASSIS MSTP RCPU +#endif + +# some basic path variables for tools and kernel source, etc # +export XLR_TOOLS_BASE = /projects/ntsw-tools/linux/xlr-419 +TOOLCHAIN_DIR = $(XLR_TOOLS_BASE)/buildroot/host/usr +KERNDIR = $(XLR_TOOLS_BASE)/kernel/linux + +# set up cross compile prefix, tools dir variables. # +export CROSS_COMPILE := x86_64-broadcom-linux-gnu- +export TOOLS_DIR := $(TOOLCHAIN_DIR)/bin + +# architecture. # +ARCH = x86_64 +TARGET_ARCHITECTURE = x86_64-broadcom-linux-gnu + +# Noisy kernel build +KBUILD_VERBOSE = 1 + +export ARCH KBUILD_VERBOSE + +# set up paths. # +export LIBRARY_PATH := $(TOOLCHAIN_DIR)/lib:$(TOOLCHAIN_DIR)/lib64:$(LIBRARY_PATH) +export PATH := $(TOOLCHAIN_DIR)/bin:$(KERNDIR):$(PATH) + +# set up SYSINC path # +export SYSINC := $(XLR_TOOLS_BASE)/buildroot/host/usr/lib/gcc/$(TARGET_ARCHITECTURE)/5.4.0/include + + +# CFLAGS/CFGFLAGS # +CFLAGS += -DUSE_LINUX_BDE_MMAP=1 +#CFLAGS += -DBDE_LINUX_USE_MSI_INTERRUPT +CFLAGS += -Wno-error=unused-value +CFLAGS += -Wno-error=unused-but-set-variable +CFLAGS += -Wno-error=maybe-uninitialized +CFLAGS += -Wno-error=cpp +CFLAGS += -Wno-error=aggressive-loop-optimizations +CFLAGS += -Wno-error=array-bounds +CFLAGS += -Wno-error=strict-overflow +CFLAGS += -L$(TOOLCHAIN_DIR)/lib +CFLAGS += -L$(TOOLCHAIN_DIR)/lib64 +#CFLAGS += -Wl,--rpath=/lib64 # may need to set rpath and dynamic-linker path here (and possibly in KLFAGS below) in the future, # +#CFLAGS += -Wl,--dynamic-linker=/lib64/ld-linux-x86-64.so.2 # if we want to build the target executable to be used with shared libs # + +#XLDK-568 fix inline references +CFGFLAGS += -fgnu89-inline + + +# set up KFLAGS appropriately. # +ifeq (,$(KFLAGS)) +KFLAGS := -L$(TOOLCHAIN_DIR)/lib -L$(TOOLCHAIN_DIR)/lib64 -I$(KERNDIR) -lc -nostdinc -isystem $(SYSINC) -Iinclude -I$(KERNDIR)/arch/x86/include -I$(KERNDIR)/arch/x86/include/generated -I$(KERNDIR)/arch/x86/include/generated/uapi -I$(KERNDIR)/arch/x86/include/uapi -I$(KERNDIR)/include -I$(KERNDIR)/include/generated -I$(KERNDIR)/include/generated/uapi -I$(KERNDIR)/include/uapi -include $(KERNDIR)/include/generated/autoconf.h -D__KERNEL__ -DNDEBUG -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Wno-format-security -fno-delete-null-pointer-checks -O2 -m64 -mtune=generic -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -fstack-protector -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -Wframe-larger-than=1024 -fno-omit-frame-pointer -Wdeclaration-after-statement -Wno-pointer-sign -fno-dwarf2-cfi-asm -fconserve-stack +endif + + +###################################################################### +# this segment comes from make/Makefile.linux-x86-smp_generic_64-2_6 # +###################################################################### +CFGFLAGS += -DLONGS_ARE_64BITS +CFGFLAGS += -DPTRS_ARE_64BITS +CFGFLAGS += -DSAL_SPL_LOCK_ON_IRQ + + +############################################################## +# This segment comes from make/Makefile.linux-x86-common-2_6 # +############################################################## +CFGFLAGS += -DSYS_BE_PIO=0 -DSYS_BE_PACKET=0 -DSYS_BE_OTHER=0 +ENDIAN = LE_HOST=1 +CFGFLAGS += -D$(ENDIAN) +CFGFLAGS += -DBCM_PLATFORM_STRING=\"X86\" +CFGFLAGS += -DSAL_BDE_DMA_MEM_DEFAULT=32 + +# Extra variables. +EXTRA_CFLAGS = -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) + +comma = , +basetarget = $(basename $(notdir $@)) +modname = $(basetarget) + +name-fix = $(subst $(comma),_,$(subst -,_,$1)) +basename_flags = -D"KBUILD_BASENAME=KBUILD_STR($(call name-fix,$(basetarget)))" +modname_flags = $(if $(filter 1,$(words $(modname))),\ +-D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") + +ifdef LTSW_CHIPS +# Ensure we do not use an out-of-date libelf.so +ELFUTILS_MIN = 158 +ELFUTILS_DIR ?= /projects/ntsw-tools/lib + +# Default open source target build +OPENSRC_BUILD ?= fed21-x86_64 + +# Hardware interface (see $SDKLT/bcma/sys/probe directory) +SYSTEM_INTERFACE ?= ngbde + +# Turn on direct register access if running on real hardware. +ifeq (ngbde,$(SYSTEM_INTERFACE)) +LTSW_ADD_CPPFLAGS += -DBCMDRD_CONFIG_MEMMAP_DIRECT=1 +endif + +export SYSTEM_INTERFACE +endif + +ifneq ($(targetplat),user) +# By default we exclude -Werror from x86 kernel builds +BCM_CFLAGS = -Wall +include ${SDK}/make/Makefile.linux-kernel-2_6 +endif + + diff --git a/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/Makefile b/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/Makefile index aedd487b1f11..cfd72d3a9216 100644 --- a/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/Makefile +++ b/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/Makefile @@ -55,14 +55,16 @@ THIS_MOD_NAME := linux-kernel-bde MODULE = $(LIBDIR)/$(THIS_MOD_NAME).o KMODULE = $(LIBDIR)/$(THIS_MOD_NAME).ko -build: kernel_libs $(MODULE) $(KMODULE) +build: kernel_libs module $(KMODULE) else MODULE = $(LIBDIR)/linux-kernel-bde.o -build: kernel_libs $(MODULE) +build: kernel_libs module endif -$(MODULE): $(BLDDIR)/.tree kernel_libs $(BOBJS) +module: kernel_libs $(MODULE) + +$(MODULE): $(BLDDIR)/.tree $(BOBJS) mkdir -p $(@D) $(LD) $(MODULE_LDFLAGS) -r -d $(BOBJS) $(LIBS) -o $@ ifneq ($(kernel_version),2_4) diff --git a/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux-kernel-bde.c b/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux-kernel-bde.c index 464a72bd3e41..3a60ac4dd54e 100644 --- a/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux-kernel-bde.c +++ b/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux-kernel-bde.c @@ -1,25 +1,21 @@ /* * Copyright 2017 Broadcom - * + * * 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 (the "GPL"). - * + * * 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 version 2 (GPLv2) for more details. - * + * * You should have received a copy of the GNU General Public License * version 2 (GPLv2) along with this source code. */ + /* - * $Id: linux-kernel-bde.c,v 1.414 Broadcom SDK $ - * $Copyright: (c) 2005 Broadcom Corp. - * All Rights Reserved.$ - * * Linux Kernel BDE - * */ #include @@ -30,27 +26,32 @@ #include #include #include -#include #include #include "linux_shbde.h" +#define MEMCPY memcpy -#ifdef __GNUC__ -#if __GNUC__ == 8 +#ifdef CONFIG_X86_64 +#if (defined(__GNUC__) && (__GNUC__ == 8)) /* * Prevent gcc 8.1.10 using a compiler inline memcpy even if using -fno-builtin or * -fno-builtin-memcpy . * __inline_memcpy and __memcpy are kernel functions that may be used instead, * for either an inline or non-inline implementations of the function */ -#define MEMCPY __inline_memcpy -#else -#define MEMCPY memcpy -#endif /* __GNUC__ == 8 */ -#else /* ifdef __GNUC__ */ -#define MEMCPY memcpy -#endif /* ifdef __GNUC__ */ +#undef MEMCPY +#define MEMCPY __memcpy +#endif /* (defined(__GNUC__) && (__GNUC__ == 8)) */ +#endif /* CONFIG_X86_64 */ + + +#if defined(CMIC_SOFT_BYTE_SWAP) +#define CMIC_SWAP32(_x) ((((_x) & 0xff000000) >> 24) \ + | (((_x) & 0x00ff0000) >> 8) \ + | (((_x) & 0x0000ff00) << 8) \ + | (((_x) & 0x000000ff) << 24)) +#endif /* defined(CMIC_SOFT_BYTE_SWAP) */ #define PCI_USE_INT_NONE (-1) #define PCI_USE_INT_INTX (0) @@ -68,8 +69,15 @@ MODULE_AUTHOR("Broadcom Corporation"); MODULE_DESCRIPTION("Kernel BDE"); MODULE_LICENSE("GPL"); -/* PCIe max payload */ -int maxpayload = 256; +/* + * PCIe max payload size in bytes. + * The default value if not specified to the kernel module by maxpayload is historically 256. + * The default value may be changed using the BDE_PCIE_MAXPAYLOAD_DEFAULT macro. + */ +#ifndef BDE_PCIE_MAXPAYLOAD_DEFAULT +#define BDE_PCIE_MAXPAYLOAD_DEFAULT 256 +#endif +int maxpayload = BDE_PCIE_MAXPAYLOAD_DEFAULT; LKM_MOD_PARAM(maxpayload, "i", int, 0); MODULE_PARM_DESC(maxpayload, "Limit maximum payload size and request size on PCIe devices"); @@ -256,6 +264,19 @@ struct bde_spi_device_id { uint32 spifreq; }; +/* Maximum number of I/O windows supported per device. */ +#define BDE_NUM_IOWIN_MAX 3 + +/* I/O memory window definition. */ +struct memwin_s { + + /* Physical address of I/O window. */ + resource_size_t addr; + + /* Size of I/O window (in bytes). */ + resource_size_t size; +}; + /* Control Data */ typedef struct bde_ctrl_s { struct list_head list; @@ -285,10 +306,7 @@ typedef struct bde_ctrl_s { struct device *dma_dev; #endif - /* Physical addresses */ - resource_size_t phys_address; - resource_size_t phys_address1; - resource_size_t phys_address2; + struct memwin_s iowin[BDE_NUM_IOWIN_MAX]; /* Secondary mapped base address */ sal_vaddr_t alt_base_addr; @@ -334,7 +352,7 @@ static int _cpu_ndevices = 0; #if defined(IPROC_CMICD) && defined(CONFIG_OF) #define ICFG_CHIP_ID_REG 0x10236000 -#define IHOST_CMICX_MAX_INTRS 128 +#define IHOST_CMICX_MAX_INTRS 129 static uint32 iproc_cmicx_irqs[IHOST_CMICX_MAX_INTRS]; #endif @@ -415,7 +433,7 @@ static void *cpu_address = NULL; /* PLX PCI-E Switch */ #define PLX_PEX8608_DEV_ID 0x8608 #define PLX_PEX8617_DEV_ID 0x8617 -#define PLX_PEX86XX_DEV_CTRL_REG 0x70 +#define PLX_PEX86XX_DEV_CTRL_REG 0x70 /* Broadcom BCM58525 */ #define BCM58525_PCI_VENDOR_ID 0x14E4 @@ -432,10 +450,11 @@ static void *cpu_address = NULL; #define IHOST_GICD_REG_ADDR_VALID(d, addr) \ (_devices[d].bde_dev.base_address1 && \ - (addr & 0xFFFFFF00) == _devices[d].phys_address1) + (addr & 0xFFFFFF00) == _devices[d].iowin[1].addr) #define IHOST_GICD_REG_ADDR_REMAP(d, addr) \ - (void *)(_devices[d].bde_dev.base_address1 + (addr - _devices[d].phys_address1)) + (void *)(_devices[d].bde_dev.base_address1 + \ + (addr - ((sal_vaddr_t)_devices[d].iowin[1].addr))) static uint32_t _read(int d, uint32_t addr); @@ -554,7 +573,8 @@ _eb_device_create(resource_size_t paddr, int irq, int rd_hw, int wr_hw) /* Map in the device */ ctrl->bde_dev.base_address = (sal_vaddr_t)IOREMAP(paddr, 0x10000); - ctrl->phys_address = paddr; + ctrl->iowin[0].addr = paddr; + ctrl->iowin[0].size = 0x10000; dev_rev_id = _read(dev_id, 0x178); /* CMIC_DEV_REV_ID */ @@ -590,7 +610,8 @@ sand_device_create(void) /* Map in the device */ /* FIX_ME: not realy map anything */ ctrl->bde_dev.base_address = (sal_vaddr_t)IOREMAP(0x40000000, 0x100000); - ctrl->phys_address = 0x40000000; + ctrl->iowin[0].addr = 0x40000000; + ctrl->iowin[0].size = 0x100000; ctrl->iLine = 0; ctrl->isr = NULL; @@ -695,7 +716,8 @@ iproc_cmicd_probe(struct platform_device *pldev) gprintk("Error mapping iProc CMIC registers"); return -1; } - ctrl->phys_address = memres->start; + ctrl->iowin[0].addr = memres->start; + ctrl->iowin[0].size = size; #ifdef CONFIG_OF if (of_find_compatible_node(NULL, NULL, IPROC_CMICX_COMPATIBLE)) { @@ -712,16 +734,18 @@ iproc_cmicd_probe(struct platform_device *pldev) memres = iproc_platform_get_resource(pldev, IORESOURCE_MEM, 1); if (memres) { ctrl->bde_dev.base_address1 = (sal_vaddr_t)IOREMAP(memres->start, memres->end - memres->start + 1); - ctrl->phys_address1 = memres->start; + ctrl->iowin[1].addr = memres->start; + ctrl->iowin[1].size = memres->end - memres->start + 1; } else { /* Use default address if not available in DTB */ ctrl->bde_dev.base_address1 = (sal_vaddr_t)IOREMAP(IHOST_GICD_REG_ADDR, IHOST_GICD_REG_REMAP_LEN); - ctrl->phys_address1 = IHOST_GICD_REG_ADDR; + ctrl->iowin[1].addr = IHOST_GICD_REG_ADDR; + ctrl->iowin[1].size = IHOST_GICD_REG_REMAP_LEN; } if (ctrl->bde_dev.base_address1) { if (debug >= 1) { gprintk("base_address1:0x%lx phys_address1:0x%lx\n", - (unsigned long)ctrl->bde_dev.base_address1, (unsigned long)ctrl->phys_address1); + (unsigned long)ctrl->bde_dev.base_address1, (unsigned long)ctrl->iowin[1].addr); } } else { gprintk("Error mapping ihost GICD registers\n"); @@ -753,9 +777,12 @@ iproc_cmicd_probe(struct platform_device *pldev) #ifdef CONFIG_OF if (of_find_compatible_node(NULL, NULL, IPROC_CMICX_COMPATIBLE)) { int i; + memset(iproc_cmicx_irqs, 0, IHOST_CMICX_MAX_INTRS*sizeof(uint32_t)); for (i = 0; i < IHOST_CMICX_MAX_INTRS; i++) { irqres = iproc_platform_get_resource(pldev, IORESOURCE_IRQ, i); - iproc_cmicx_irqs[i] = irqres->start; + if (irqres) { + iproc_cmicx_irqs[i] = irqres->start; + } if (debug >= 1) { gprintk("iproc_cmicx_irqs[%d] = %d\n", i, iproc_cmicx_irqs[i]); } @@ -1019,7 +1046,8 @@ _ics_bde_create(void) /* Map in the device */ paddr = BCM_ICS_CMIC_BASE; ctrl->bde_dev.base_address = (sal_vaddr_t)IOREMAP(paddr, 0x10000); - ctrl->phys_address = paddr; + ctrl->iowin[0].addr = paddr; + ctrl->iowin[0].size = 0x10000; dev_rev_id = *((unsigned int *)(KSEG1ADDR(paddr + 0x178))); @@ -1399,6 +1427,8 @@ static const struct pci_device_id _id_table[] = { { BROADCOM_VENDOR_ID, BCM56174_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM53570_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM53575_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56070_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56071_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9656, PCI_ANY_ID, PCI_ANY_ID }, { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9056, PCI_ANY_ID, PCI_ANY_ID }, { BCM53000_VENDOR_ID, BCM53000PCIE_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, @@ -1463,6 +1493,7 @@ static const struct pci_device_id _id_table[] = { { BROADCOM_VENDOR_ID, BCM88683_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM88684_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM88685_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88687_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM88380_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM88381_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM88202_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, @@ -1493,8 +1524,38 @@ static const struct pci_device_id _id_table[] = { { BROADCOM_VENDOR_ID, BCM8869B_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM8869C_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM8869D_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM8869E_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM8869F_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM88800_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88821_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88826_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88802_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88803_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88804_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88805_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88806_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88820_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88822_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88823_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88824_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88825_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88480_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88481_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88482_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88483_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88484_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88485_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88486_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88487_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88488_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88489_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM8848A_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM8848B_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM8848C_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM8848D_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM8848E_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM8848F_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM88850_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, #endif /* BCM_DNX_SUPPORT */ #ifdef BCM_DFE_SUPPORT { BROADCOM_VENDOR_ID, BCM88750_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, @@ -1546,6 +1607,12 @@ static const struct pci_device_id _id_table[] = { { BROADCOM_VENDOR_ID, BCM56832_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM56836_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM56870_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56273_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56274_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56275_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56276_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56277_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56278_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM56370_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM56371_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM56372_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, @@ -1568,6 +1635,9 @@ static const struct pci_device_id _id_table[] = { { BROADCOM_VENDOR_ID, BCM53547_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM53548_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { BROADCOM_VENDOR_ID, BCM53549_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56470_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56471_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, + { BROADCOM_VENDOR_ID, BCM56472_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID }, { 0, 0, 0, 0 } };; @@ -2180,7 +2250,7 @@ _pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) resource_size_t paddr; uint16 cmd = 0; uint32 bar_len; - int cmic_bar; + int i, cmic_bar; int baroff = 0; int iproc = 0; int plx_dev = 0; @@ -2219,7 +2289,7 @@ _pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) } } #endif /* IPROC_CMICD */ - + /* * Note that a few supported devices have a non-Broadcom PCI vendor ID, * but since none of their associated PCI device IDs collide with the @@ -2441,7 +2511,7 @@ _pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) ((PCI_FIND_DEV(BCM58525_PCI_VENDOR_ID, BCM58522_PCI_DEVICE_ID, NULL)) != NULL) || ((PCI_FIND_DEV(BCM58712_PCI_VENDOR_ID, BCM58712_PCI_DEVICE_ID, NULL)) != NULL) ) { /* BCM58525/BCM58712 CPU boards support 128 Max payload size */ - if (maxpayload) { + if (maxpayload && maxpayload != 128) { maxpayload = 128; if (debug >= 1) gprintk("force max payload size to 128\n"); } @@ -2500,19 +2570,6 @@ _pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) } #endif /* BCM_DFE_SUPPORT */ -#if defined(BCM_DNXF_SUPPORT) - /*All Ramon devices from 0x8790 to 0x879F*/ - if ((dev->device & BCM_DNXF_DEVID_MASK) == BCM88790_DEVICE_ID) { - /* - * For DMA transactions - set Max_Payload_Size and - * Max_Read_Request_Size to 128 bytes. - */ - pci_write_config_byte(dev, 0xb5, 0x0c); - pci_write_config_byte(dev, 0xb4, 0x0); - - } -#endif - /* Prevent compiler warning */ if (ctrl == NULL) { return 0; @@ -2523,6 +2580,15 @@ _pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) ctrl->pci_device = dev; pci_set_drvdata(dev, ctrl); + /* + * Sample setting of unique ID, used the PCIe address of the device: + * domain, bus, slot, function in hex digits: DDDDBBSS (SS includes the slot/device and function. + * Tested with old kernels from 2.6 . + * Do not use the PCI_DEVID macro which old kernel versions don't have. */ + ctrl->bde_dev.dev_unique_id = dev->bus ? + (((uint32)pci_domain_nr(dev->bus)) << 16) ^ (((uint32)dev->bus->number) << 8) ^ dev->devfn : + dev->devfn; + /* Check for iProc device */ if (shbde_pci_is_iproc(shbde, dev, &cmic_bar)) { iproc = 1; @@ -2557,13 +2623,21 @@ _pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) } ctrl->bde_dev.base_address = (sal_vaddr_t)IOREMAP(paddr, bar_len); - ctrl->phys_address = paddr; + ctrl->iowin[0].addr = paddr; + ctrl->iowin[0].size = bar_len; + if (debug >= 3) { gprintk("BAR %d: kernel addr:0x%lx phys addr:0x%lx length:%lx\n", baroff, (unsigned long)ctrl->bde_dev.base_address, (unsigned long)paddr, (unsigned long)bar_len); } /* Map secondary address spaces */ + for (i = 1; i < BDE_NUM_IOWIN_MAX; i++) { + ctrl->iowin[i].addr = 0; + ctrl->iowin[i].size = 0; + } + ctrl->bde_dev.base_address1 = 0; + if (iproc #ifdef DNX_TEST_BOARD || (dev->device == PLX9056_DEVICE_ID && baroff == 2) @@ -2572,7 +2646,8 @@ _pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) paddr = pci_resource_start(dev, 0); bar_len = pci_resource_len(dev, 0); ctrl->bde_dev.base_address1 = (sal_vaddr_t)IOREMAP(paddr, bar_len); - ctrl->phys_address1 = paddr; + ctrl->iowin[1].addr = paddr; + ctrl->iowin[1].size = bar_len; if (debug >= 3) { gprintk("BAR 0: kernel addr:0x%lx phys addr:0x%lx length:%lx\n", (unsigned long)ctrl->bde_dev.base_address1, (unsigned long)paddr, (unsigned long)bar_len); @@ -2773,7 +2848,8 @@ map_local_bus(uint64_t addr, uint32_t size) /* Map in the device */ ctrl->bde_dev.base_address = (sal_vaddr_t)IOREMAP(addr, size); - ctrl->phys_address = addr; + ctrl->iowin[0].addr = addr; + ctrl->iowin[0].size = size; _bde_add_device(); return(ctrl); @@ -2817,7 +2893,8 @@ map_local_bus2(bde_ctrl_t *plx_ctrl, uint32_t dev_base, uint32_t size) /* Map in the device */ ctrl->bde_dev.base_address = plx_ctrl->bde_dev.base_address + dev_base; - ctrl->phys_address = plx_ctrl->phys_address + (resource_size_t)dev_base; + ctrl->iowin[0].addr = plx_ctrl->iowin[0].addr + (resource_size_t)dev_base; + ctrl->iowin[0].size = size; #if 1 addr = (uint8_t *)ctrl->bde_dev.base_address + PL0_REVISION_REG; @@ -2850,12 +2927,12 @@ probe_plx_local_bus(void) } addr_hi_str[0] = 0; #ifdef PHYS_ADDR_IS_64BIT - sprintf(addr_hi_str, "%08x", (uint32_t)(plx_ctrl.phys_address >> 32)); + sprintf(addr_hi_str, "%08x", (uint32_t)(plx_ctrl.iowin[0].addr >> 32)); #endif printk(KERN_ERR "Found PLX %04x:%04x vir: 0x%08x phy: 0x%s%08x\n", plx_ctrl.bde_dev.device, plx_ctrl.bde_dev.rev, plx_ctrl.bde_dev.base_address, addr_hi_str, - (uint32_t)(plx_ctrl.phys_address)); + (uint32_t)(plx_ctrl.iowin[0].addr)); addr = (uint8_t *)plx_ctrl.bde_dev.base_address + CPLD_OFFSET + CPLD_REVISION_REG; val = readl(addr); @@ -2947,9 +3024,9 @@ _init(void) } #else if (use_msi > PCI_USE_INT_INTX) { - /* Warn if invalid configuration */ - gprintk("MSI interrupts not supported by kernel\n"); - } + /* Warn if invalid configuration */ + gprintk("MSI interrupts not supported by kernel\n"); + } use_msi = PCI_USE_INT_INTX; #endif /* CONFIG_PCI_MSI */ @@ -3079,6 +3156,10 @@ _pprint(void) pprintf("Broadcom Device Enumerator (%s)\n", LINUX_KERNEL_BDE_NAME); + pprintf("Module parameters:\n"); + pprintf("\tmaxpayload=%d\n", maxpayload); + pprintf("\tusemsi=%d\n", usemsi); + _dma_pprint(); if (_ndevices == 0) { @@ -3134,7 +3215,7 @@ _pprint(void) pprintf("AXI Device 0x%x:0x%x:0x%.8lx:%d\n", ctrl->bde_dev.device, ctrl->bde_dev.rev, - (unsigned long)ctrl->phys_address, + (unsigned long)ctrl->iowin[0].addr, ctrl->iLine); } else if (ctrl->dev_type & BDE_EB_DEV_TYPE) { pprintf("EB Bus Device 0x%x:0x%x\n", @@ -3150,6 +3231,54 @@ _pprint(void) } return 0; } +/* + * Some kernels are configured to prevent mapping of kernel RAM memory + * into user space via the /dev/mem device. + * + * The function below provides a backdoor to map IO and DMA memory to + * user space via the BDE device file. + */ +static int +_bde_mmap(struct file *filp, struct vm_area_struct *vma) +{ + unsigned long paddr = vma->vm_pgoff << PAGE_SHIFT; + unsigned long size = vma->vm_end - vma->vm_start; + int i, j, pio_range_valid = 0; + + for(i = 0; i < _ndevices; i++) { + bde_ctrl_t *ctrl = _devices + i; + if (ctrl->dev_type & BDE_SWITCH_DEV_TYPE) { + for (j = 0; j < BDE_NUM_IOWIN_MAX; j++) { + if (paddr >= (unsigned long)ctrl->iowin[j].addr && + (paddr + size) <= (unsigned long)(ctrl->iowin[j].addr + ctrl->iowin[j].size)) { + pio_range_valid = 1; + break; + } + if ((ctrl->dev_type & BDE_AXI_DEV_TYPE) && (paddr == ctrl->iowin[j].addr)) { + pio_range_valid = 1; + break; + } + } + } + } + + if (pio_range_valid) { + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); + + if (remap_pfn_range(vma, + vma->vm_start, + vma->vm_pgoff, + size, + vma->vm_page_prot)) { + gprintk("Failed to mmap phys range 0x%lx-0x%lx to 0x%lx-0x%lx\n", + paddr, paddr + size, vma->vm_start,vma->vm_end); + return -EAGAIN; + } + return 0; + } + + return _dma_mmap(filp, vma); +} /* Workaround for broken Busybox/PPC insmod */ static char _modname[] = LINUX_KERNEL_BDE_NAME; @@ -3160,7 +3289,7 @@ static gmodule_t _gmodule = { init: _init, cleanup: _cleanup, pprint: _pprint, - mmap: _dma_mmap, + mmap: _bde_mmap, }; gmodule_t * @@ -3479,6 +3608,9 @@ _interrupt_connect(int d, if (of_find_compatible_node(NULL, NULL, IPROC_CMICX_COMPATIBLE)) { int i, j; for (i = 0; i < IHOST_CMICX_MAX_INTRS; i++) { + if (!iproc_cmicx_irqs[i]) { + continue; + } if (unlikely(debug >= 1)) gprintk("%s(%d):device# = %d, request_irq(%d)\n", __func__, __LINE__, d, iproc_cmicx_irqs[i]); @@ -3491,6 +3623,9 @@ _interrupt_connect(int d, } if (ret < 0) { for (j = 0; j < i; j++) { + if (!iproc_cmicx_irqs[j]) { + continue; + } free_irq(iproc_cmicx_irqs[j], ctrl); } goto err_disable_msi; @@ -3519,10 +3654,10 @@ _interrupt_connect(int d, msi_exit: #endif gprintk("could not request IRQ\n"); - ctrl->isr = NULL; - ctrl->isr_data = NULL; - ctrl->isr2 = NULL; - ctrl->isr2_data = NULL; + ctrl->isr = NULL; + ctrl->isr_data = NULL; + ctrl->isr2 = NULL; + ctrl->isr2_data = NULL; return -1; } @@ -3600,6 +3735,9 @@ _interrupt_disconnect(int d) if (of_find_compatible_node(NULL, NULL, IPROC_CMICX_COMPATIBLE)) { int i; for (i = 0; i < IHOST_CMICX_MAX_INTRS; i++) { + if (!iproc_cmicx_irqs[i]) { + continue; + } if (unlikely(debug > 1)) { gprintk("%s(%d):device# = %d, free_irq(%d)\n", __func__, __LINE__, d, iproc_cmicx_irqs[i]); @@ -3862,10 +4000,10 @@ lkbde_cpu_pci_register(int d) case BCM88683_DEVICE_ID: case BCM88684_DEVICE_ID: case BCM88685_DEVICE_ID: + case BCM88687_DEVICE_ID: case BCM88380_DEVICE_ID: case BCM88381_DEVICE_ID: case BCM88680_DEVICE_ID: - case BCM88800_DEVICE_ID: case BCM88470_DEVICE_ID: case BCM88470P_DEVICE_ID: case BCM88471_DEVICE_ID: @@ -3915,34 +4053,41 @@ lkbde_cpu_pci_register(int d) break; } + /* configure iproc >=14 devices by device family */ +#if defined(BCM_DNXF_SUPPORT) || defined(BCM_DNX_SUPPORT) + switch (ctrl->bde_dev.device & DNXC_DEVID_FAMILY_MASK) { #ifdef BCM_DNX_SUPPORT - /*All Jericho 2 devices from 0x8690 to 0x869F*/ - if (SOC_IS_JERICHO_2_TYPE(ctrl->bde_dev.device)) { - /* Fix bar 0 address */ /* FIXME: write full phy address */ - pci_write_config_byte(ctrl->pci_device, 0x12, 0x10); - pci_write_config_byte(ctrl->pci_device, 0x13, 0x60); - + case JERICHO2_DEVICE_ID: + case J2C_DEVICE_ID: + case J2C_2ND_DEVICE_ID: + case Q2A_DEVICE_ID: + case J2P_DEVICE_ID: +#endif +#ifdef BCM_DNXF_SUPPORT + case BCM88790_DEVICE_ID: +#endif /* * For DMA transactions - set Max_Payload_Size and * Max_Read_Request_Size to 128 bytes. */ pci_write_config_byte(ctrl->pci_device, 0xb5, 0x0c); pci_write_config_byte(ctrl->pci_device, 0xb4, 0x0); + break; } -#endif +#endif /* defined(BCM_DNXF_SUPPORT) || defined(BCM_DNX_SUPPORT) */ /* Redo ioremap */ if (ctrl->bde_dev.base_address) { iounmap((void *)ctrl->bde_dev.base_address); } - ctrl->bde_dev.base_address = (sal_vaddr_t)IOREMAP(ctrl->phys_address, 0x1000000); + ctrl->bde_dev.base_address = (sal_vaddr_t)IOREMAP(ctrl->iowin[0].addr, 0x1000000); if (debug >= 1) { gprintk("%s, %s(): info:\n", __FILE__, __FUNCTION__); gprintk("_ndevices=%d, _switch_ndevices=%d\n", _ndevices, _switch_ndevices); gprintk("ctrl->dev_type=0x%x, ctrl->phys_address=0x%lx\n", - ctrl->dev_type, (unsigned long)ctrl->phys_address); + ctrl->dev_type, (unsigned long)ctrl->iowin[0].addr); gprintk("ctrl->bde_dev.device=0x%x, ctrl->bde_dev.rev=0x%x, " "ctrl->bde_dev.base_address=0x%lx\n", ctrl->bde_dev.device, ctrl->bde_dev.rev, @@ -4089,7 +4234,7 @@ lkbde_get_dev_phys(int d) d, _devices[d].dev_type); return 0; } - return _devices[d].phys_address; + return _devices[d].iowin[0].addr; } uint32_t @@ -4105,7 +4250,7 @@ lkbde_get_dev_phys_hi(int d) return 0; } #ifdef PHYS_ADDR_IS_64BIT - return (uint32_t)(_devices[d].phys_address >> 32); + return (uint32_t)(_devices[d].iowin[0].addr >> 32); #else return 0; #endif @@ -4151,15 +4296,15 @@ lkbde_get_dev_resource(int d, int rsrc, uint32_t *flags, switch (rsrc) { case 0: - *phys_lo = (uint32_t)(_devices[d].phys_address); + *phys_lo = (uint32_t)(_devices[d].iowin[0].addr); #ifdef PHYS_ADDR_IS_64BIT - *phys_hi = (uint32_t)(_devices[d].phys_address >> 32); + *phys_hi = (uint32_t)(_devices[d].iowin[0].addr >> 32); #endif break; case 1: - *phys_lo = (uint32_t)(_devices[d].phys_address1); + *phys_lo = (uint32_t)(_devices[d].iowin[1].addr); #ifdef PHYS_ADDR_IS_64BIT - *phys_hi = (uint32_t)(_devices[d].phys_address1 >> 32); + *phys_hi = (uint32_t)(_devices[d].iowin[1].addr >> 32); #endif break; default: @@ -4286,7 +4431,7 @@ lkbde_irq_mask_set(int d, uint32_t addr, uint32_t mask, uint32_t fmask) if (iproc_reg) { _iproc_write(d, addr, ctrl->imask | ctrl->imask2); } else { - _write(d, addr, ctrl->imask | ctrl->imask2); + _write(d, addr, ctrl->imask | ctrl->imask2); } spin_unlock_irqrestore(&ctrl->lock, flags); @@ -4326,7 +4471,7 @@ lkbde_irq_mask_get(int d, uint32_t *mask, uint32_t *fmask) *fmask = ctrl->fmask; *mask = ctrl->imask | ctrl->imask2; - + return 0; } diff --git a/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux_dma.c b/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux_dma.c index eb3dc0495195..012cac21a7ae 100644 --- a/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux_dma.c +++ b/platform/broadcom/saibcm-modules/systems/bde/linux/kernel/linux_dma.c @@ -67,6 +67,10 @@ #include #include +#if defined(IPROC_CMICD) && defined(CONFIG_OF) +#include +#endif + #ifdef BCM_PLX9656_LOCAL_BUS #include #endif @@ -117,9 +121,9 @@ #endif #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)) -#define DMA_MAPPING_ERROR(d, p) dma_mapping_error((d),(p)) +#define BDE_DMA_MAPPING_ERROR(d, p) dma_mapping_error((d),(p)) #else -#define DMA_MAPPING_ERROR(d, p) dma_mapping_error((p)) +#define BDE_DMA_MAPPING_ERROR(d, p) dma_mapping_error((p)) #endif #ifndef KMALLOC_MAX_SIZE @@ -612,6 +616,15 @@ static void _alloc_mpool(size_t size) { unsigned long pbase = 0; + struct device *dev = DMA_DEV(DMA_DEV_INDEX); + int dma64_support = 0; + +#if defined(IPROC_CMICD) && defined(CONFIG_OF) + if (of_find_compatible_node(NULL, NULL, "brcm,iproc-cmicx")) { + dma64_support = 1; + } +#endif + #if defined(__arm__) && !defined(CONFIG_HIGHMEM) if (_use_himem) { gprintk("DMA in high memory requires CONFIG_HIGHMEM on ARM CPUs.\n"); @@ -647,8 +660,8 @@ _alloc_mpool(size_t size) /* get a memory allocation from the kernel */ { dma_addr_t dma_handle; - if (!(_dma_vbase = dma_alloc_coherent(DMA_DEV(DMA_DEV_INDEX), - alloc_size, &dma_handle, GFP_KERNEL)) || !dma_handle) { + _dma_vbase = dma_alloc_coherent(dev, alloc_size, &dma_handle, GFP_KERNEL); + if (!_dma_vbase || !dma_handle) { gprintk("Failed to allocate coherent memory pool of size 0x%lx\n", (unsigned long)alloc_size); return; } @@ -672,13 +685,12 @@ _alloc_mpool(size_t size) } _cpu_pbase = virt_to_bus(_dma_vbase); /* Use dma_map_single to obtain DMA bus address or IOVA if iommu is present. */ - if (DMA_DEV(DMA_DEV_INDEX)) { - pbase = dma_map_single(DMA_DEV(DMA_DEV_INDEX), _dma_vbase, size, DMA_BIDIRECTIONAL); - if (DMA_MAPPING_ERROR(DMA_DEV(DMA_DEV_INDEX), pbase)) { + if (dev) { + pbase = dma_map_single(dev, _dma_vbase, size, DMA_BIDIRECTIONAL); + if (BDE_DMA_MAPPING_ERROR(dev, pbase)) { gprintk("Failed to map memory at %p\n", _dma_vbase); _pgcleanup(); _dma_vbase = NULL; - _cpu_pbase = 0; return; } _use_dma_mapping = 1; @@ -692,7 +704,9 @@ _alloc_mpool(size_t size) return; } - if (((pbase + (size - 1)) >> 16) > DMA_BIT_MASK(16)) { + _dma_pbase = pbase; + + if (!dma64_support && ((pbase + (size - 1)) >> 16) > DMA_BIT_MASK(16)) { gprintk("DMA memory allocated at 0x%lx size 0x%lx is beyond the 4GB limit and not supported.\n", pbase, (unsigned long)size); _pgcleanup(); _dma_vbase = NULL; @@ -700,14 +714,13 @@ _alloc_mpool(size_t size) return; } - _dma_pbase = pbase; #ifdef REMAP_DMA_NONCACHED _dma_vbase = IOREMAP(_dma_pbase, size); #endif if (dma_debug >= 1) { - gprintk("_use_dma_mapping:%d _dma_vbase:%p _dma_pbase:%lx _cpu_pbase:%lx allocated:%lx dmaalloc:%d\n", + gprintk("_use_dma_mapping:%d _dma_vbase:%p _dma_pbase:%lx _cpu_pbase:%lx allocated:%lx dmaalloc:%d, dma64_support:%d\n", _use_dma_mapping, _dma_vbase, (unsigned long)_dma_pbase, - (unsigned long)_cpu_pbase, (unsigned long)size, dmaalloc); + (unsigned long)_cpu_pbase, (unsigned long)size, dmaalloc, dma64_support); } } } @@ -749,7 +762,7 @@ void _dma_init(int dev_index) if (dev_index > DMA_DEV_INDEX) { if (_use_dma_mapping && DMA_DEV(dev_index) && _dma_vbase) { pbase = dma_map_single(DMA_DEV(dev_index), _dma_vbase, _dma_mem_size, DMA_BIDIRECTIONAL); - if (DMA_MAPPING_ERROR(DMA_DEV(dev_index), pbase)) { + if (BDE_DMA_MAPPING_ERROR(DMA_DEV(dev_index), pbase)) { gprintk("Failed to map memory for device %d at %p\n", dev_index, _dma_vbase); return; } @@ -992,6 +1005,9 @@ lkbde_get_dma_info(phys_addr_t* cpu_pbase, phys_addr_t* dma_pbase, ssize_t* size void _dma_pprint(void) { + pprintf("\tdmasize=%s\n", dmasize); + pprintf("\thimem=%s\n", himem); + pprintf("\thimemaddr=%s\n", himemaddr); pprintf("DMA Memory (%s): %d bytes, %d used, %d free%s\n", (_use_himem) ? "high" : "kernel", (_dma_vbase) ? _dma_mem_size : 0, diff --git a/platform/broadcom/saibcm-modules/systems/bde/linux/user/kernel/linux-user-bde.c b/platform/broadcom/saibcm-modules/systems/bde/linux/user/kernel/linux-user-bde.c index 370f89e022c4..471ff423cea5 100644 --- a/platform/broadcom/saibcm-modules/systems/bde/linux/user/kernel/linux-user-bde.c +++ b/platform/broadcom/saibcm-modules/systems/bde/linux/user/kernel/linux-user-bde.c @@ -1,23 +1,20 @@ /* * Copyright 2017 Broadcom - * + * * 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 (the "GPL"). - * + * * 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 version 2 (GPLv2) for more details. - * + * * You should have received a copy of the GNU General Public License * version 2 (GPLv2) along with this source code. */ + /* - * $Id: linux-user-bde.c,v 1.80 Broadcom SDK $ - * $Copyright: (c) 2005 Broadcom Corp. - * All Rights Reserved.$ - * * Linux User BDE Helper Module */ #include @@ -81,6 +78,17 @@ The INTR base address values are changed for HX5, hence making new #defines so runtime decisions can be made. */ +#define PAXB_0_PAXB_IC_INTRCLR_0 (0x180123a0) +#define PAXB_0_PAXB_IC_INTRCLR_1 (0x180123a4) + +#define PAXB_0_PAXB_IC_INTRCLR_MODE_0 (0x180123a8) +#define PAXB_0_PAXB_IC_INTRCLR_MODE_1 (0x180123ac) + +#define HX5_PAXB_0_PAXB_IC_INTRCLR_0 (0x102303a0) +#define HX5_PAXB_0_PAXB_IC_INTRCLR_1 (0x102303a4) + +#define HX5_PAXB_0_PAXB_IC_INTRCLR_MODE_0 (0x102303a8) +#define HX5_PAXB_0_PAXB_IC_INTRCLR_MODE_1 (0x102303ac) #define INTC_INTR_ENABLE_REG0 (0x180130f0) #define INTC_INTR_STATUS_REG0 (0x18013190) @@ -104,12 +112,18 @@ be made. #define HX5_IHOST_GICD_ISENABLERN_1 (0x10781104) #define HX5_IHOST_GICD_ICENABLERN_1 (0x10781184) #define HX5_IHOST_GICD_ICENABLERN_8 (0x107811a0) +#define HX5_IHOST_GICD_ISPENDRN_8 (0x10781220) /* Offset between ISENABLERN_1 and ICENABLERN_1 in 4-bytes */ #define HX5_IHOST_IRQ_MASK_OFFSET 0x20 -#define HX5_IHOST_INTR_MAP_NUM (HX5_IHOST_GICD_ICENABLERN_8 - HX5_IHOST_GICD_ISENABLERN_0) +/* Offset between ISENABLERN_1 and ISPENDRN_1 in 4-bytes */ +#define HX5_IHOST_IRQ_PEND_OFFSET 0x40 +#define HX5_IHOST_INTR_MAP_NUM (HX5_IHOST_GICD_ISPENDRN_8 - HX5_IHOST_GICD_ISENABLERN_0) #define HX5_IHOST_INTR_STATUS_MAP_NUM (INTC_INTR_REG_NUM * (sizeof(uint32))) #define IRQ_BIT(intr) (intr % (sizeof(uint32)*8)) #define IRQ_MASK_INDEX(intr) (intr / (sizeof(uint32)*8)) +#define HX5_SW_PROG_INTR_PRIORITY 73 +#define INTR_SW_PROG_INTR_BITPOS (1 << IRQ_BIT(HX5_SW_PROG_INTR_PRIORITY)) +#define INTC_SW_PROG_INTR_REG_IND IRQ_MASK_INDEX(HX5_SW_PROG_INTR_PRIORITY) #define HX5_CHIP_INTR_LOW_PRIORITY 119 #define INTR_LOW_PRIORITY_BITPOS (1 << IRQ_BIT(HX5_CHIP_INTR_LOW_PRIORITY)) #define INTC_LOW_PRIORITY_INTR_REG_IND IRQ_MASK_INDEX(HX5_CHIP_INTR_LOW_PRIORITY) @@ -145,6 +159,15 @@ static ibde_t *user_bde = NULL; typedef void (*isr_f)(void *); +typedef struct _intr_regs_s { + uint32 intc_intr_status_base; + uint32 intc_intr_enable_base; + uint32 intc_intr_clear_0; + uint32 intc_intr_clear_1; + uint32 intc_intr_clear_mode_0; + uint32 intc_intr_clear_mode_1; +} _intr_regs_t; + typedef struct bde_ctrl_s { uint32 dev_type; int irq; @@ -153,6 +176,7 @@ typedef struct bde_ctrl_s { isr_f isr; uint32 *ba; int inst; /* associate to _bde_inst_resource[] */ + _intr_regs_t intr_regs; } bde_ctrl_t; #define VALID_DEVICE(_n) (_n < LINUX_BDE_MAX_DEVICES) @@ -263,44 +287,33 @@ _cmicx_interrupt(bde_ctrl_t *ctrl) int d, ind; uint32 stat, iena, mask, fmask; bde_inst_resource_t *res; - uint32 intc_intr_status_base = 0, intc_intr_enable_base = 0; d = (((uint8 *)ctrl - (uint8 *)_devices) / sizeof (bde_ctrl_t)); + + if (ctrl->dev_type & BDE_PCI_DEV_TYPE) { + /* Clear MSI interrupts immediately to prevent spurious interrupts */ + WRITE_INTC_INTR(d, ctrl->intr_regs.intc_intr_clear_0, 0xFFFFFFFF); + WRITE_INTC_INTR(d, ctrl->intr_regs.intc_intr_clear_1, 0xFFFFFFFF); + } + res = &_bde_inst_resource[ctrl->inst]; lkbde_irq_mask_get(d, &mask, &fmask); - if ((ctrl->dev_type & BDE_SWITCH_DEV_TYPE) && - ((user_bde->get_dev(d)->device == BCM56370_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56371_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56372_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56374_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56375_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56376_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56377_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56577_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56578_DEVICE_ID) || - (user_bde->get_dev(d)->device == BCM56579_DEVICE_ID))) { - intc_intr_status_base = HX5_INTC_INTR_STATUS_BASE; - intc_intr_enable_base = HX5_INTC_INTR_ENABLE_BASE; - } else { - intc_intr_status_base = INTC_INTR_STATUS_BASE; - intc_intr_enable_base = INTC_INTR_ENABLE_BASE; - } if (fmask) { if (ctrl->dev_type & BDE_AXI_DEV_TYPE) { IHOST_READ_INTR(d, ihost_intr_status_base + INTC_PDMA_INTR_REG_IND, stat); IHOST_READ_INTR(d, ihost_intr_enable_base + INTC_PDMA_INTR_REG_IND, iena); } else { - READ_INTC_INTR(d, intc_intr_status_base + 4 * INTC_PDMA_INTR_REG_IND, stat); - READ_INTC_INTR(d, intc_intr_enable_base + 4 * INTC_PDMA_INTR_REG_IND, iena); + READ_INTC_INTR(d, ctrl->intr_regs.intc_intr_status_base + 4 * INTC_PDMA_INTR_REG_IND, stat); + READ_INTC_INTR(d, ctrl->intr_regs.intc_intr_enable_base + 4 * INTC_PDMA_INTR_REG_IND, iena); } if (stat & iena) { if (ctrl->dev_type & BDE_AXI_DEV_TYPE) { IHOST_WRITE_INTR(d, ihost_intr_enable_base + INTC_PDMA_INTR_REG_IND + HX5_IHOST_IRQ_MASK_OFFSET, ~0); } else { - WRITE_INTC_INTR(d, intc_intr_enable_base + 4 * INTC_PDMA_INTR_REG_IND, 0); + WRITE_INTC_INTR(d, ctrl->intr_regs.intc_intr_enable_base + 4 * INTC_PDMA_INTR_REG_IND, 0); } for (ind = 0; ind < INTC_INTR_REG_NUM; ind++) { @@ -308,17 +321,21 @@ _cmicx_interrupt(bde_ctrl_t *ctrl) continue; } if (ctrl->dev_type & BDE_AXI_DEV_TYPE) { - if (ind < INTC_LOW_PRIORITY_INTR_REG_IND) { + if (ind < INTC_SW_PROG_INTR_REG_IND) { continue; } - IHOST_READ_INTR(d, ihost_intr_status_base + ind, stat); - IHOST_READ_INTR(d, ihost_intr_enable_base + ind, iena); - if (ind == INTC_LOW_PRIORITY_INTR_REG_IND) { - stat &= INTR_LOW_PRIORITY_BITPOS; + if (ind == INTC_SW_PROG_INTR_REG_IND) { + IHOST_READ_INTR(d, ihost_intr_enable_base + ind + HX5_IHOST_IRQ_PEND_OFFSET, stat); + stat &= INTR_SW_PROG_INTR_BITPOS; + } else { + IHOST_READ_INTR(d, ihost_intr_status_base + ind, stat); + if (ind == INTC_LOW_PRIORITY_INTR_REG_IND) { + stat &= INTR_LOW_PRIORITY_BITPOS; + } } } else { - READ_INTC_INTR(d, intc_intr_status_base + 4 * ind, stat); - READ_INTC_INTR(d, intc_intr_enable_base + 4 * ind, iena); + READ_INTC_INTR(d, ctrl->intr_regs.intc_intr_status_base + 4 * ind, stat); + READ_INTC_INTR(d, ctrl->intr_regs.intc_intr_enable_base + 4 * ind, iena); } if (stat & iena) { break; @@ -340,10 +357,13 @@ _cmicx_interrupt(bde_ctrl_t *ctrl) continue; } if (ctrl->dev_type & BDE_AXI_DEV_TYPE) { - if (ind < INTC_LOW_PRIORITY_INTR_REG_IND) { + if (ind < INTC_SW_PROG_INTR_REG_IND) { continue; } - if (ind == INTC_LOW_PRIORITY_INTR_REG_IND) { + if (ind == INTC_SW_PROG_INTR_REG_IND) { + IHOST_WRITE_INTR(d, ihost_intr_enable_base + INTC_SW_PROG_INTR_REG_IND + + HX5_IHOST_IRQ_MASK_OFFSET, INTR_SW_PROG_INTR_BITPOS); + } else if (ind == INTC_LOW_PRIORITY_INTR_REG_IND) { IHOST_WRITE_INTR(d, ihost_intr_enable_base + INTC_LOW_PRIORITY_INTR_REG_IND + HX5_IHOST_IRQ_MASK_OFFSET, INTR_LOW_PRIORITY_BITPOS); } else { @@ -351,7 +371,7 @@ _cmicx_interrupt(bde_ctrl_t *ctrl) HX5_IHOST_IRQ_MASK_OFFSET, ~0); } } else { - WRITE_INTC_INTR(d, intc_intr_enable_base + 4*ind, 0); + WRITE_INTC_INTR(d, ctrl->intr_regs.intc_intr_enable_base + 4*ind, 0); } } @@ -567,6 +587,18 @@ _cmicd_interrupt(bde_ctrl_t *ctrl) if (stat & imask) { break; } + /** Check if there are interrupts other than PacketIO interrupts on CMC1 */ + stat = user_bde->read(d, CMIC_CMCx_IRQ_STAT0_OFFSET(1)); + imask = mask & ~fmask; + if (stat & imask) { + break; + } + /** Check if there are interrupts other than PacketIO interrupts on CMC2 */ + stat = user_bde->read(d, CMIC_CMCx_IRQ_STAT0_OFFSET(2)); + imask = mask & ~fmask; + if (stat & imask) { + break; + } stat = user_bde->read(d, CMIC_CMCx_IRQ_STAT1_OFFSET(cmc)); if (ctrl->dev_type & BDE_AXI_DEV_TYPE) { mask = user_bde->read(d, CMIC_CMCx_UC0_IRQ_MASK1_OFFSET(cmc)); @@ -716,6 +748,26 @@ _intr_mode_str(void *isr) return NULL; } +static void +_intr_regs_init(bde_ctrl_t *ctrl, int hx5_intr) +{ + if (hx5_intr) { + ctrl->intr_regs.intc_intr_status_base = HX5_INTC_INTR_STATUS_BASE; + ctrl->intr_regs.intc_intr_enable_base = HX5_INTC_INTR_ENABLE_BASE; + ctrl->intr_regs.intc_intr_clear_0 = HX5_PAXB_0_PAXB_IC_INTRCLR_0; + ctrl->intr_regs.intc_intr_clear_1 = HX5_PAXB_0_PAXB_IC_INTRCLR_1; + ctrl->intr_regs.intc_intr_clear_mode_0 = HX5_PAXB_0_PAXB_IC_INTRCLR_MODE_0; + ctrl->intr_regs.intc_intr_clear_mode_1 = HX5_PAXB_0_PAXB_IC_INTRCLR_MODE_1; + } else { + ctrl->intr_regs.intc_intr_status_base = INTC_INTR_STATUS_BASE; + ctrl->intr_regs.intc_intr_enable_base = INTC_INTR_ENABLE_BASE; + ctrl->intr_regs.intc_intr_clear_0 = PAXB_0_PAXB_IC_INTRCLR_0; + ctrl->intr_regs.intc_intr_clear_1 = PAXB_0_PAXB_IC_INTRCLR_1; + ctrl->intr_regs.intc_intr_clear_mode_0 = PAXB_0_PAXB_IC_INTRCLR_MODE_0; + ctrl->intr_regs.intc_intr_clear_mode_1 = PAXB_0_PAXB_IC_INTRCLR_MODE_1; + } +} + static void _devices_init(int d) { @@ -753,6 +805,8 @@ _devices_init(int d) case BCM53547_DEVICE_ID: case BCM53548_DEVICE_ID: case BCM53549_DEVICE_ID: + ctrl->isr = (isr_f)_cmicd_cmc0_interrupt; + break; case BCM88670_DEVICE_ID: case BCM88671_DEVICE_ID: case BCM88671M_DEVICE_ID: @@ -780,10 +834,10 @@ _devices_init(int d) case BCM88683_DEVICE_ID: case BCM88684_DEVICE_ID: case BCM88685_DEVICE_ID: + case BCM88687_DEVICE_ID: case BCM88380_DEVICE_ID: case BCM88381_DEVICE_ID: case BCM88680_DEVICE_ID: - case BCM88800_DEVICE_ID: case BCM88770_DEVICE_ID: case BCM88773_DEVICE_ID: case BCM88774_DEVICE_ID: @@ -812,10 +866,7 @@ _devices_init(int d) case BCM88956_DEVICE_ID: case BCM88772_DEVICE_ID: case BCM88952_DEVICE_ID: - ctrl->isr = (isr_f)_cmicd_cmc0_interrupt; - break; - case BCM88790_DEVICE_ID: - ctrl->isr = (isr_f)_cmicx_interrupt; + ctrl->isr = (isr_f)_cmicd_interrupt; break; case BCM56370_DEVICE_ID: case BCM56371_DEVICE_ID: @@ -827,6 +878,12 @@ _devices_init(int d) case BCM56577_DEVICE_ID: case BCM56578_DEVICE_ID: case BCM56579_DEVICE_ID: + case BCM56273_DEVICE_ID: + case BCM56274_DEVICE_ID: + case BCM56275_DEVICE_ID: + case BCM56276_DEVICE_ID: + case BCM56277_DEVICE_ID: + case BCM56278_DEVICE_ID: ctrl->isr = (isr_f)_cmicx_interrupt; if (ctrl->dev_type & BDE_AXI_DEV_TYPE) { if (!ihost_intr_enable_base) { @@ -838,6 +895,7 @@ _devices_init(int d) HX5_IHOST_INTR_STATUS_MAP_NUM); } } + _intr_regs_init(ctrl, 1); break; default: /* Get CMIC version */ @@ -853,7 +911,8 @@ _devices_init(int d) } /* check if version is CMICX */ else if (ver == 0x04) { - ctrl->isr = (isr_f)_cmicx_interrupt; + ctrl->isr = (isr_f)_cmicx_interrupt; + _intr_regs_init(ctrl, 0); } else { ctrl->isr = (isr_f)_cmic_interrupt; if ((ctrl->dev_type & BDE_256K_REG_SPACE) && @@ -867,17 +926,25 @@ _devices_init(int d) break; } + /* configure interrupts for DNX devices using iproc >=14 */ +#if defined(BCM_DNXF_SUPPORT) || defined(BCM_DNX_SUPPORT) + switch (user_bde->get_dev(d)->device & DNXC_DEVID_FAMILY_MASK) { #ifdef BCM_DNX_SUPPORT - /*All Jericho 2 devices from 0x8690 to 0x869F*/ - if (SOC_IS_JERICHO_2_TYPE(user_bde->get_dev(d)->device)) { - ctrl->isr = (isr_f)_cmicx_interrupt; - } + case JERICHO2_DEVICE_ID: + case J2C_DEVICE_ID: + case J2C_2ND_DEVICE_ID: + case Q2A_DEVICE_ID: + case J2P_DEVICE_ID: +#endif +#ifdef BCM_DNXF_SUPPORT + case BCM88790_DEVICE_ID: #endif - - /*All Ramon devices from 0x8790 to 0x879F*/ - if ((user_bde->get_dev(d)->device & BCM88790_DEVICE_ID) == BCM88790_DEVICE_ID) { ctrl->isr = (isr_f)_cmicx_interrupt; + _intr_regs_init(ctrl, 0); + break; } +#endif /* defined(BCM_DNXF_SUPPORT) || defined(BCM_DNX_SUPPORT) */ + if (_intr_mode_str(ctrl->isr) == NULL) { gprintk("Warning: Unknown interrupt mode\n"); } @@ -1204,6 +1271,7 @@ _ioctl(unsigned int cmd, unsigned long arg) if (bde_dev) { io.d0 = bde_dev->device; io.d1 = bde_dev->rev; + io.dx.dw[0] = bde_dev->dev_unique_id; if (BDE_DEV_MEM_MAPPED(_devices[io.dev].dev_type)) { /* Get physical address to map */ io.d2 = lkbde_get_dev_phys(io.dev); @@ -1258,8 +1326,10 @@ _ioctl(unsigned int cmd, unsigned long arg) io.dx.dw[0] = cpu_pbase; #ifdef PHYS_ADDRS_ARE_64BITS io.dx.dw[1] = cpu_pbase >> 32; + io.d3 = dma_pbase >> 32; #else io.dx.dw[1] = 0; + io.d3 = 0; #endif break; case LUBDE_ENABLE_INTERRUPTS: @@ -1268,6 +1338,14 @@ _ioctl(unsigned int cmd, unsigned long arg) } if (_devices[io.dev].dev_type & BDE_SWITCH_DEV_TYPE) { if (_devices[io.dev].isr && !_devices[io.dev].enabled) { + bde_ctrl_t *ctrl; + ctrl = &_devices[io.dev]; + if ((ctrl->isr == (isr_f)_cmicx_interrupt) && + (ctrl->dev_type & BDE_PCI_DEV_TYPE)) { + /* Set MSI mode to SW clear vs auto clear */ + WRITE_INTC_INTR(io.dev, ctrl->intr_regs.intc_intr_clear_mode_0, 0x0); + WRITE_INTC_INTR(io.dev, ctrl->intr_regs.intc_intr_clear_mode_1, 0x0); + } user_bde->interrupt_connect(io.dev, _devices[io.dev].isr, _devices+io.dev); diff --git a/platform/broadcom/saibcm-modules/systems/bde/shared/shbde_iproc.c b/platform/broadcom/saibcm-modules/systems/bde/shared/shbde_iproc.c index 05253141b2ff..087720a20a8b 100644 --- a/platform/broadcom/saibcm-modules/systems/bde/shared/shbde_iproc.c +++ b/platform/broadcom/saibcm-modules/systems/bde/shared/shbde_iproc.c @@ -290,8 +290,9 @@ shbde_iproc_paxb_init(shbde_hal_t *shbde, void *iproc_regs, } } - /* Configure MSIX interrupt page, only need for iproc ver == 0x10 */ - if ((icfg->use_msi == 2) && (icfg->iproc_ver == 0x10)) { + /* Configure MSIX interrupt page, need for iproc ver 0x10 and 0x12 */ + if ((icfg->use_msi == 2) && + ((icfg->iproc_ver == 0x10) || (icfg->iproc_ver == 0x12))){ unsigned int mask = (0x1 << PAXB_0_FUNC0_IMAP1_3_ADDR_SHIFT) - 1; reg = ROFFS(iproc_regs, PAXB_0_FUNC0_IMAP1_3); data = iproc32_read(shbde, reg); @@ -341,19 +342,23 @@ shbde_iproc_pci_read(shbde_hal_t *shbde, void *iproc_regs, subwin_base = (addr & ~0xfff); if((icfg->cmic_ver >= 4) && + ((subwin_base == 0x10230000) || (subwin_base == 0x18012000))) { + /* Route the PAXB register through IMAP0_2 */ + reg = ROFFS(iproc_regs, 0x2000 + (addr & 0xfff)); + } else if((icfg->cmic_ver >= 4) && ((subwin_base == 0x10231000) || (subwin_base == 0x18013000))) { /* Route the INTC block access through IMAP0_6 */ reg = ROFFS(iproc_regs, 0x6000 + (addr & 0xfff)); } else { /* Update base address for sub-window 7 */ subwin_base |= 1; /* Valid bit */ - reg = ROFFS(iproc_regs, BAR0_PAXB_IMAP0_7); - iproc32_write(shbde, reg, subwin_base); + reg = ROFFS(iproc_regs, BAR0_PAXB_IMAP0_7); + iproc32_write(shbde, reg, subwin_base); /* Read it to make sure the write actually goes through */ subwin_base = iproc32_read(shbde, reg); - /* Read register through sub-window 7 */ - reg = ROFFS(iproc_regs, 0x7000 + (addr & 0xfff)); + /* Read register through sub-window 7 */ + reg = ROFFS(iproc_regs, 0x7000 + (addr & 0xfff)); } return iproc32_read(shbde, reg); @@ -388,19 +393,23 @@ shbde_iproc_pci_write(shbde_hal_t *shbde, void *iproc_regs, subwin_base = (addr & ~0xfff); if((icfg->cmic_ver >= 4) && + ((subwin_base == 0x10230000) || (subwin_base == 0x18012000))) { + /* Route the PAXB register through IMAP0_2 */ + reg = ROFFS(iproc_regs, 0x2000 + (addr & 0xfff)); + } else if((icfg->cmic_ver >= 4) && ((subwin_base == 0x10231000) || (subwin_base == 0x18013000))) { /* Route the INTC block access through IMAP0_6 */ reg = ROFFS(iproc_regs, 0x6000 + (addr & 0xfff)); } else { /* Update base address for sub-window 7 */ subwin_base |= 1; /* Valid bit */ - reg = ROFFS(iproc_regs, BAR0_PAXB_IMAP0_7); - iproc32_write(shbde, reg, subwin_base); + reg = ROFFS(iproc_regs, BAR0_PAXB_IMAP0_7); + iproc32_write(shbde, reg, subwin_base); /* Read it to make sure the write actually goes through */ subwin_base = iproc32_read(shbde, reg); /* Read register through sub-window 7 */ - reg = ROFFS(iproc_regs, 0x7000 + (addr & 0xfff)); + reg = ROFFS(iproc_regs, 0x7000 + (addr & 0xfff)); } iproc32_write(shbde, reg, data); diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/Makefile b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/Makefile index 84c677758cac..448b4b9a9310 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/Makefile +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/Makefile @@ -24,7 +24,7 @@ LOCALDIR = systems/linux/kernel/modules include ${SDK}/make/Make.config -subdirs=shared uk-proxy bcm-diag-full bcm-core bcm-net bcm-diag +subdirs= include ${SDK}/make/Make.subdirs diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/Makefile b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/Makefile index ed1a5000e3ca..a3f430a6a903 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/Makefile +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/Makefile @@ -37,9 +37,6 @@ build: $(MODULE) $(KMODULE) endif KBUILD_EXTRA_SYMBOLS := ${BLDDIR}/../../../../bde/linux/kernel/kernel_module/Module.symvers -ifeq (,$(findstring -DPROXY_SUPPORT=0,$(CFLAGS))) -KBUILD_EXTRA_SYMBOLS += ${BLDDIR}/../uk-proxy/kernel_module/Module.symvers -endif # BCM Network Device diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/bcm-knet.c b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/bcm-knet.c index 077386e6dcbc..768ff490dc27 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/bcm-knet.c +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/bcm-knet/bcm-knet.c @@ -1,23 +1,18 @@ /* * Copyright 2017 Broadcom - * + * * 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 (the "GPL"). - * + * * 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 version 2 (GPLv2) for more details. - * + * * You should have received a copy of the GNU General Public License * version 2 (GPLv2) along with this source code. */ -/* - * $Id: bcm-knet.c,v 1.90 Broadcom SDK $ - * $Copyright: (c) 2005 Broadcom Corp. - * All Rights Reserved.$ - */ /* * This module implements a Linux network driver for Broadcom @@ -54,7 +49,7 @@ * * To support pci hot-plug in this module, the resource update * should be handled when the PCI device is re-plugged. - * NOTE: the KNET detach should be invoked befere removing the + * NOTE: the KNET detach should be invoked before removing the * device. * * For a list of supported module parameters, please see below. @@ -71,6 +66,7 @@ #include #include #include +#include MODULE_AUTHOR("Broadcom Corporation"); @@ -167,6 +163,39 @@ LKM_MOD_PARAM(basedev_suspend, "i", int, 0); MODULE_PARM_DESC(basedev_suspend, "Pause traffic till base device is up (enabled by default in NAPI mode)"); +/* + * Force to add one layer of VLAN tag to untagged packets on Dune devices + */ +#if defined(SAI_FIXUP) && defined(BCM_DNX_SUPPORT) /* SONIC-16195 CS9129167 - Change the default to NOT add tag */ +static int force_tagged = 0; +#else +static int force_tagged = 1; +#endif +LKM_MOD_PARAM(force_tagged, "i", int, 0); +MODULE_PARM_DESC(force_tagged, +"Always tagged with VLAN tag with spceified VID or VSI(default 1)"); + +static int ft_tpid=0x8100; +LKM_MOD_PARAM(ft_tpid, "i", int, 0); +MODULE_PARM_DESC(ft_tpid, +"Tag Protocol Identifier (TPID) indicates the frame type (default 0x8100)"); + +static int ft_pri=0; +LKM_MOD_PARAM(ft_pri, "i", int, 0); +MODULE_PARM_DESC(ft_cfi, +"Priority (PRI) indicates the frame priority (default 0)"); + +static int ft_cfi=0; +LKM_MOD_PARAM(ft_cfi, "i", int, 0); +MODULE_PARM_DESC(ft_cfi, +"Canonical Format Indicator (CFI) indicates whether a MAC address is encapsulated in canonical format over different transmission media (default 0)"); + +static int ft_vid=0; +LKM_MOD_PARAM(ft_vid, "i", int, 0); +MODULE_PARM_DESC(ft_vid, +"VLAN ID (VID) indicates the VLAN to which a frame belongs (default 0)"); + + /* Debug levels */ #define DBG_LVL_VERB 0x1 #define DBG_LVL_DCB 0x2 @@ -267,40 +296,6 @@ static int napi_weight = 0; #endif -/* - * If proxy support is compiled in the module will attempt to use - * the user/kernel message service provided by the linux-uk-proxy - * kernel module, otherwise device IOCTL will be used. - */ -#ifndef PROXY_SUPPORT -#define PROXY_SUPPORT 0 -#endif - -#if PROXY_SUPPORT - -#include - -static int use_proxy = 1; -LKM_MOD_PARAM(use_proxy, "i", int, 0); -MODULE_PARM_DESC(use_proxy, -"Use Linux User/Kernel proxy (default 1)"); - -#define PROXY_SERVICE_CREATE(_s,_q,_f) linux_uk_proxy_service_create(_s,_q,_f) -#define PROXY_SERVICE_DESTROY(_s) linux_uk_proxy_service_destroy(_s); -#define PROXY_SEND(_s,_m,_l) linux_uk_proxy_send(_s,_m,_l) -#define PROXY_RECV(_s,_m,_l) linux_uk_proxy_recv(_s,_m,_l) - -#else - -static int use_proxy = 0; - -#define PROXY_SERVICE_CREATE(_s,_q,_f) -#define PROXY_SERVICE_DESTROY(_s) -#define PROXY_SEND(_s,_m,_l) -#define PROXY_RECV(_s,_m,_l) (-1) - -#endif - /* Compatibility */ #if (LINUX_VERSION_CODE < KERNEL_VERSION(4,7,0)) @@ -394,6 +389,10 @@ static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len) __vlan_hwaccel_put_tag(_skb, htons(_proto), _tci) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +#define ETH_P_8021AD 0x88A8 /* 802.1ad Service VLAN */ +#endif + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) #define bkn_dma_mapping_error(d, a) \ dma_mapping_error(a) @@ -407,6 +406,11 @@ static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len) #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) +enum hwtstamp_tx_types { + HWTSTAMP_TX_OFF, + HWTSTAMP_TX_ON, + HWTSTAMP_TX_ONESTEP_SYNC +}; enum { SKBTX_HW_TSTAMP = 1 << 0, SKBTX_SW_TSTAMP = 1 << 1, @@ -441,6 +445,7 @@ static inline ktime_t ns_to_ktime(u64 ns) #endif #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) #include +#define HWTSTAMP_TX_ONESTEP_SYNC 2 enum { SKBTX_HW_TSTAMP = 1 << 0, SKBTX_SW_TSTAMP = 1 << 1, @@ -452,6 +457,11 @@ static inline void bkn_skb_tx_timestamp(struct sk_buff *skb) } #else #include + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) +#define HWTSTAMP_TX_ONESTEP_SYNC 2 +#endif + #define bkn_skb_tx_flags(_skb) skb_shinfo(_skb)->tx_flags static inline void bkn_skb_tx_timestamp(struct sk_buff *skb) { @@ -459,26 +469,41 @@ static inline void bkn_skb_tx_timestamp(struct sk_buff *skb) } #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +#define bkn_dev_net_set(dev, net) +#else +#define bkn_dev_net_set(dev, net) dev_net_set(dev, net) +#endif + #ifdef LINUX_BDE_DMA_DEVICE_SUPPORT -#define DMA_DEV device -#define DMA_FROMDEV DMA_FROM_DEVICE -#define DMA_TODEV DMA_TO_DEVICE -#define DMA_MAP_SINGLE(d,p,s,r) dma_map_single(d,p,s,r) -#define DMA_UNMAP_SINGLE(d,a,s,r) dma_unmap_single(d,a,s,r) -#define DMA_ALLOC_COHERENT(d,s,h) dma_alloc_coherent(d,s,h,GFP_ATOMIC|GFP_DMA32) -#define DMA_FREE_COHERENT(d,s,a,h) dma_free_coherent(d,s,a,h) -#define DMA_MAPPING_ERROR(d,a) bkn_dma_mapping_error(d,a) +#define BKN_DMA_DEV device +#define BKN_DMA_FROMDEV DMA_FROM_DEVICE +#define BKN_DMA_TODEV DMA_TO_DEVICE +#define BKN_DMA_MAP_SINGLE(d,p,s,r) dma_map_single(d,p,s,r) +#define BKN_DMA_UNMAP_SINGLE(d,a,s,r) dma_unmap_single(d,a,s,r) +#define BKN_DMA_ALLOC_COHERENT(d,s,h) dma_alloc_coherent(d,s,h,GFP_ATOMIC|GFP_DMA32) +#define BKN_DMA_FREE_COHERENT(d,s,a,h) dma_free_coherent(d,s,a,h) +#define BKN_DMA_MAPPING_ERROR(d,a) bkn_dma_mapping_error(d,a) #else -#define DMA_DEV pci_dev -#define DMA_FROMDEV PCI_DMA_FROMDEVICE -#define DMA_TODEV PCI_DMA_TODEVICE -#define DMA_MAP_SINGLE(d,p,s,r) pci_map_single(d,p,s,r) -#define DMA_UNMAP_SINGLE(d,a,s,r) pci_unmap_single(d,a,s,r) -#define DMA_ALLOC_COHERENT(d,s,h) pci_alloc_consistent(d,s,h) -#define DMA_FREE_COHERENT(d,s,a,h) pci_free_consistent(d,s,a,h) -#define DMA_MAPPING_ERROR(d,a) bkn_pci_dma_mapping_error(d,a) +#define BKN_DMA_DEV pci_dev +#define BKN_DMA_FROMDEV PCI_DMA_FROMDEVICE +#define BKN_DMA_TODEV PCI_DMA_TODEVICE +#define BKN_DMA_MAP_SINGLE(d,p,s,r) pci_map_single(d,p,s,r) +#define BKN_DMA_UNMAP_SINGLE(d,a,s,r) pci_unmap_single(d,a,s,r) +#define BKN_DMA_ALLOC_COHERENT(d,s,h) pci_alloc_consistent(d,s,h) +#define BKN_DMA_FREE_COHERENT(d,s,a,h) pci_free_consistent(d,s,a,h) +#define BKN_DMA_MAPPING_ERROR(d,a) bkn_pci_dma_mapping_error(d,a) #endif +/* + * Get a 16-bit value from packet offset + * _data Pointer to packet + * _offset Offset + */ +#define PKT_U16_GET(_data, _offset) \ + (uint16_t)(_data[_offset] << 8 | _data[_offset + 1]) + + /* RCPU operations */ #define RCPU_OPCODE_RX 0x10 #define RCPU_OPCODE_TX 0x20 @@ -536,7 +561,7 @@ typedef struct bkn_switch_info_s { int ndev_max; /* Size of indexed array */ struct list_head rxpf_list; /* Associated Rx packet filters */ volatile void *base_addr; /* Base address for PCI register access */ - struct DMA_DEV *dma_dev; /* Required for DMA memory control */ + struct BKN_DMA_DEV *dma_dev; /* Required for DMA memory control */ struct pci_dev *pdev; /* Required for DMA memory control */ struct net_device *dev; /* Base network device */ struct napi_struct napi; /* New NAPI */ @@ -558,8 +583,12 @@ typedef struct bkn_switch_info_s { uint32_t ftmh_stacking_ext_size; /* FTMH Stacking extension existence/size */ uint32_t pph_base_size; /* Size of PPH base */ uint32_t pph_lif_ext_size[8]; /* Size of PPH Lif extension header */ - uint8_t udh_enable; /* Indicates UDH existence */ uint32_t udh_length_type[4]; /* Size of UDH header per type */ + uint32_t udh_size; /* Size of UDH header on legacy devices */ + uint32_t oamp_punt; /* OAMP port if nonzero */ + uint8_t no_skip_udh_check; /* Indicates UDH won't be skipped */ + uint8_t system_headers_mode; /* Indicates system header mode */ + uint8_t udh_enable; /* Indicates UDH existence */ int rx_chans; /* Number of Rx channels */ uint32_t dma_hi; /* DMA higher address */ uint32_t cmic_type; /* CMIC type (CMICe or CMICm) */ @@ -579,8 +608,6 @@ typedef struct bkn_switch_info_s { uint32_t inst_id; /* Instance id of this device */ int evt_idx; /* Event queue index for this device*/ int basedev_suspended; /* Base device suspended */ - int tx_hwts; /* HW timestamp for Tx */ - int rx_hwts; /* HW timestamp for Rx */ struct sk_buff_head tx_ptp_queue; /* Tx PTP skb queue */ struct work_struct tx_ptp_work; /* Tx PTP work */ struct { @@ -641,6 +668,8 @@ typedef struct bkn_switch_info_s { } rx[NUM_RX_CHAN]; } bkn_switch_info_t; +/* 0x1 - Jericho 2 mode */ +#define BKN_DNX_JR2_MODE 1 /* PTCH_2 */ #define BKN_DNX_PTCH_2_SIZE 2 /* ITMH */ @@ -675,49 +704,49 @@ typedef struct bkn_switch_info_s { /* TSH */ #define BKN_DNX_TSH_SIZE 4 /* PPH */ -#define BKN_DNX_PPH_BASE_TYPE_9 9 -#define BKN_DNX_PPH_BASE_TYPE_10 10 -#define BKN_DNX_PPH_BASE_TYPE_12 12 -#define BKN_DNX_PPH_9_FORWARD_DOMAIN_MSB 5 -#define BKN_DNX_PPH_9_FORWARD_DOMAIN_NOF_BITS 16 -#define BKN_DNX_PPH_9_LEARN_EXT_PRESENT_MSB 53 -#define BKN_DNX_PPH_9_LEARN_EXT_PRESENT_NOF_BITS 1 -#define BKN_DNX_PPH_9_FHEI_SIZE_MSB 54 -#define BKN_DNX_PPH_9_FHEI_SIZE_NOF_BITS 2 -#define BKN_DNX_PPH_9_LIF_EXT_TYPE_MSB 56 -#define BKN_DNX_PPH_9_LIF_EXT_TYPE_NOF_BITS 3 -#define BKN_DNX_PPH_10_FORWARD_DOMAIN_MSB 9 -#define BKN_DNX_PPH_10_FORWARD_DOMAIN_NOF_BITS 16 -#define BKN_DNX_PPH_10_LEARN_EXT_PRESENT_MSB 61 -#define BKN_DNX_PPH_10_LEARN_EXT_PRESENT_NOF_BITS 1 -#define BKN_DNX_PPH_10_FHEI_SIZE_MSB 62 -#define BKN_DNX_PPH_10_FHEI_SIZE_NOF_BITS 2 -#define BKN_DNX_PPH_10_LIF_EXT_TYPE_MSB 64 -#define BKN_DNX_PPH_10_LIF_EXT_TYPE_NOF_BITS 3 -#define BKN_DNX_PPH_12_FORWARD_DOMAIN_MSB 21 -#define BKN_DNX_PPH_12_FORWARD_DOMAIN_NOF_BITS 18 -#define BKN_DNX_PPH_12_LEARN_EXT_PRESENT_MSB 77 -#define BKN_DNX_PPH_12_LEARN_EXT_PRESENT_NOF_BITS 1 -#define BKN_DNX_PPH_12_FHEI_SIZE_MSB 78 -#define BKN_DNX_PPH_12_FHEI_SIZE_NOF_BITS 2 -#define BKN_DNX_PPH_12_LIF_EXT_TYPE_MSB 80 -#define BKN_DNX_PPH_12_LIF_EXT_TYPE_NOF_BITS 3 +#define BKN_DNX_INTERNAL_BASE_TYPE_9 9 +#define BKN_DNX_INTERNAL_BASE_TYPE_10 10 +#define BKN_DNX_INTERNAL_BASE_TYPE_12 12 +#define BKN_DNX_INTERNAL_9_FORWARD_DOMAIN_MSB 5 +#define BKN_DNX_INTERNAL_9_FORWARD_DOMAIN_NOF_BITS 16 +#define BKN_DNX_INTERNAL_9_LEARN_EXT_PRESENT_MSB 53 +#define BKN_DNX_INTERNAL_9_LEARN_EXT_PRESENT_NOF_BITS 1 +#define BKN_DNX_INTERNAL_9_FHEI_SIZE_MSB 54 +#define BKN_DNX_INTERNAL_9_FHEI_SIZE_NOF_BITS 2 +#define BKN_DNX_INTERNAL_9_LIF_EXT_TYPE_MSB 56 +#define BKN_DNX_INTERNAL_9_LIF_EXT_TYPE_NOF_BITS 3 +#define BKN_DNX_INTERNAL_10_FORWARD_DOMAIN_MSB 9 +#define BKN_DNX_INTERNAL_10_FORWARD_DOMAIN_NOF_BITS 16 +#define BKN_DNX_INTERNAL_10_LEARN_EXT_PRESENT_MSB 61 +#define BKN_DNX_INTERNAL_10_LEARN_EXT_PRESENT_NOF_BITS 1 +#define BKN_DNX_INTERNAL_10_FHEI_SIZE_MSB 62 +#define BKN_DNX_INTERNAL_10_FHEI_SIZE_NOF_BITS 2 +#define BKN_DNX_INTERNAL_10_LIF_EXT_TYPE_MSB 64 +#define BKN_DNX_INTERNAL_10_LIF_EXT_TYPE_NOF_BITS 3 +#define BKN_DNX_INTERNAL_12_FORWARD_DOMAIN_MSB 21 +#define BKN_DNX_INTERNAL_12_FORWARD_DOMAIN_NOF_BITS 18 +#define BKN_DNX_INTERNAL_12_LEARN_EXT_PRESENT_MSB 77 +#define BKN_DNX_INTERNAL_12_LEARN_EXT_PRESENT_NOF_BITS 1 +#define BKN_DNX_INTERNAL_12_FHEI_SIZE_MSB 78 +#define BKN_DNX_INTERNAL_12_FHEI_SIZE_NOF_BITS 2 +#define BKN_DNX_INTERNAL_12_LIF_EXT_TYPE_MSB 80 +#define BKN_DNX_INTERNAL_12_LIF_EXT_TYPE_NOF_BITS 3 /* PPH.FHEI_TYPE */ -#define BKN_DNX_PPH_FHEI_TYPE_SZ0 1 -#define BKN_DNX_PPH_FHEI_TYPE_SZ1 2 -#define BKN_DNX_PPH_FHEI_TYPE_SZ2 3 +#define BKN_DNX_INTERNAL_FHEI_TYPE_SZ0 1 +#define BKN_DNX_INTERNAL_FHEI_TYPE_SZ1 2 +#define BKN_DNX_INTERNAL_FHEI_TYPE_SZ2 3 /* FHEI */ -#define BKN_DNX_PPH_FHEI_SZ0_SIZE 3 -#define BKN_DNX_PPH_FHEI_SZ1_SIZE 5 -#define BKN_DNX_PPH_FHEI_SZ2_SIZE 8 -#define BKN_DNX_PPH_FHEI_TRAP_5B_QUALIFIER_MSB 0 -#define BKN_DNX_PPH_FHEI_TRAP_5B_QUALIFIER_NOF_BITS 27 -#define BKN_DNX_PPH_FHEI_TRAP_5B_CODE_MSB 27 -#define BKN_DNX_PPH_FHEI_TRAP_5B_CODE_NOF_BITS 9 -#define BKN_DNX_PPH_FHEI_TRAP_5B_TYPE_MSB 36 -#define BKN_DNX_PPH_FHEI_TRAP_5B_TYPE_NOF_BITS 4 +#define BKN_DNX_INTERNAL_FHEI_SZ0_SIZE 3 +#define BKN_DNX_INTERNAL_FHEI_SZ1_SIZE 5 +#define BKN_DNX_INTERNAL_FHEI_SZ2_SIZE 8 +#define BKN_DNX_INTERNAL_FHEI_TRAP_5B_QUALIFIER_MSB 0 +#define BKN_DNX_INTERNAL_FHEI_TRAP_5B_QUALIFIER_NOF_BITS 27 +#define BKN_DNX_INTERNAL_FHEI_TRAP_5B_CODE_MSB 27 +#define BKN_DNX_INTERNAL_FHEI_TRAP_5B_CODE_NOF_BITS 9 +#define BKN_DNX_INTERNAL_FHEI_TRAP_5B_TYPE_MSB 36 +#define BKN_DNX_INTERNAL_FHEI_TRAP_5B_TYPE_NOF_BITS 4 /* PPH Extension */ -#define BKN_DNX_PPH_LEARN_EXT_SIZE 19 +#define BKN_DNX_INTERNAL_LEARN_EXT_SIZE 19 /* UDH */ #define BKN_DNX_UDH_DATA_TYPE_0_MSB 0 #define BKN_DNX_UDH_DATA_TYPE_0_NOF_BITS 2 @@ -758,29 +787,48 @@ typedef struct bkn_switch_info_s { #define BKN_DPP_FTMH_PPH_TYPE_MSB 45 #define BKN_DPP_FTMH_PPH_TYPE_NOF_BITS 2 +/* OTSH */ +#define BKN_DPP_OTSH_SIZE_BYTE 6 +#define BKN_DPP_OTSH_TYPE_MSB 0 +#define BKN_DPP_OTSH_TYPE_NOF_BITS 2 +#define BKN_DPP_OTSH_OAM_SUB_TYPE_MSB 2 +#define BKN_DPP_OTSH_OAM_SUB_TYPE_NOF_BITS 3 + +#define BKN_DPP_OTSH_TYPE_OAM 0 +#define BKN_DPP_OTSH_OAM_SUB_TYPE_DM_1588 2 +#define BKN_DPP_OTSH_OAM_SUB_TYPE_DM_NTP 3 + +#define BKN_DPP_OAM_DM_TOD_SIZE_BYTE 4 + /* PPH */ -#define BKN_DPP_PPH_SIZE_BYTE 7 -#define BKN_DPP_PPH_EEI_EXTENSION_PRESENT_MSB 0 -#define BKN_DPP_PPH_EEI_EXTENSION_PRESENT_NOF_BITS 1 -#define BKN_DPP_PPH_LEARN_EXENSION_PRESENT_MSB 1 -#define BKN_DPP_PPH_LEARN_EXENSION_PRESENT_NOF_BITS 1 -#define BKN_DPP_PPH_FHEI_SIZE_MSB 2 -#define BKN_DPP_PPH_FHEI_SIZE_NOF_BITS 2 -#define BKN_DPP_PPH_FORWARD_CODE_MSB 4 -#define BKN_DPP_PPH_FORWARD_CODE_NOF_BITS 4 -#define BKN_DPP_PPH_VSI_MSB 22 -#define BKN_DPP_PPH_VSI_NOF_BITS 16 +#define BKN_DPP_INTERNAL_SIZE_BYTE 7 +#define BKN_DPP_INTERNAL_EEI_EXTENSION_PRESENT_MSB 0 +#define BKN_DPP_INTERNAL_EEI_EXTENSION_PRESENT_NOF_BITS 1 +#define BKN_DPP_INTERNAL_LEARN_EXENSION_PRESENT_MSB 1 +#define BKN_DPP_INTERNAL_LEARN_EXENSION_PRESENT_NOF_BITS 1 +#define BKN_DPP_INTERNAL_FHEI_SIZE_MSB 2 +#define BKN_DPP_INTERNAL_FHEI_SIZE_NOF_BITS 2 +#define BKN_DPP_INTERNAL_FORWARD_CODE_MSB 4 +#define BKN_DPP_INTERNAL_FORWARD_CODE_NOF_BITS 4 +#define BKN_DPP_INTERNAL_FORWARD_CODE_CPU_TRAP 7 +#define BKN_DPP_INTERNAL_FORWARDING_HEADER_OFFSET_MSB 8 +#define BKN_DPP_INTERNAL_FORWARDING_HEADER_OFFSET_NOF_BITS 7 +#define BKN_DPP_INTERNAL_VSI_MSB 22 +#define BKN_DPP_INTERNAL_VSI_NOF_BITS 16 + /* FHEI TRAP/SNOOP 3B */ -#define BKN_DPP_PPH_FHEI_3B_SIZE_BYTE 3 -#define BKN_DPP_PPH_FHEI_5B_SIZE_BYTE 5 -#define BKN_DPP_PPH_FHEI_8B_SIZE_BYTE 8 -#define BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_MSB 0 -#define BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_NOF_BITS 16 -#define BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_MSB 16 -#define BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_NOF_BITS 8 +#define BKN_DPP_INTERNAL_FHEI_3B_SIZE_BYTE 3 +#define BKN_DPP_INTERNAL_FHEI_5B_SIZE_BYTE 5 +#define BKN_DPP_INTERNAL_FHEI_8B_SIZE_BYTE 8 +#define BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_MSB 0 +#define BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_NOF_BITS 16 +#define BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_MSB 16 +#define BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_NOF_BITS 8 /* PPH extension */ -#define BKN_DPP_PPH_EXPLICIT_EDITING_INFOMATION_EXTENSION_SIZE_BYTE 3 -#define BKN_DPP_PPH_LEARN_EXTENSION_SIZE_BYTE 5 +#define BKN_DPP_INTERNAL_EXPLICIT_EDITING_INFOMATION_EXTENSION_SIZE_BYTE 3 +#define BKN_DPP_INTERNAL_LEARN_EXTENSION_SIZE_BYTE 5 + +#define BKN_SAND_SCRATCH_DATA_SIZE 4 /* ftmh action type. */ typedef enum bkn_dpp_ftmh_action_type_e { @@ -792,31 +840,22 @@ typedef enum bkn_dpp_ftmh_action_type_e { /* ftmh dest extension. */ typedef struct bkn_dpp_ftmh_dest_extension_s { - uint8 valid; /* Set if the extension is present */ + uint8_t valid; /* Set if the extension is present */ uint32_t dst_sys_port; /* Destination System Port */ } bkn_dpp_ftmh_dest_extension_t; /* dnx packet */ typedef struct bkn_dune_system_header_info_s { - uint32_t ntwrk_header_ptr; + uint32_t system_header_size; struct { - uint32_t packet_size; /* Packet size in bytes */ uint32_t action_type; /* Indicates if the copy is one of the Forward Snoop or Mirror packet copies */ - uint32_t pph_type; - uint32_t prio; /* Traffic class */ - uint32_t src_sys_port; /* Source System port*/ + uint32_t source_sys_port_aggregate; /* Source System port*/ } ftmh; struct { - uint32_t vsi; - uint32_t trap_qualifier; /* RAW Data */ - uint32_t trap_id; /* RAW Data */ + uint32_t forward_domain; + uint32_t trap_qualifier; + uint32_t trap_id; } internal; - uint32_t system_header_size; - uint32_t ftmh_spa; /* FTMH: Source-System-Port-Aggregate*/ - uint32_t pph_forward_domain; /* PPH: Forward-Domain*/ - uint32_t fhei_qualifier; /* FHEI: Qualifier */ - uint32_t fhei_code; /* FHEI: Code */ - uint32_t fhei_type; /* FHEI: Type */ } bkn_dune_system_header_info_t; #define PREV_IDX(_cur, _max) (((_cur) == 0) ? (_max) - 1 : (_cur) - 1) @@ -874,13 +913,15 @@ typedef struct bkn_priv_s { int id; int type; int port; - uint8_t itmh[4]; int qnum; uint32_t vlan; uint32_t flags; uint32_t cb_user_data; uint8_t system_headers[27]; uint32_t system_headers_size; + int tx_hwts; /* HW timestamp for Tx */ + int rx_hwts; /* HW timestamp for Rx */ + int phys_port; } bkn_priv_t; typedef struct bkn_filter_s { @@ -927,6 +968,7 @@ static knet_hw_tstamp_tx_time_get_cb_f knet_hw_tstamp_tx_time_get_cb = NULL; static knet_hw_tstamp_tx_meta_get_cb_f knet_hw_tstamp_tx_meta_get_cb = NULL; static knet_hw_tstamp_ptp_clock_index_cb_f knet_hw_tstamp_ptp_clock_index_cb = NULL; static knet_hw_tstamp_rx_time_upscale_cb_f knet_hw_tstamp_rx_time_upscale_cb = NULL; +static knet_hw_tstamp_ioctl_cmd_cb_f knet_hw_tstamp_ioctl_cmd_cb = NULL; static knet_netif_cb_f knet_netif_create_cb = NULL; static knet_netif_cb_f knet_netif_destroy_cb = NULL; @@ -935,69 +977,6 @@ static knet_netif_cb_f knet_netif_destroy_cb = NULL; */ #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10)) -/* - * Old style using kernel_thread() - */ -typedef struct { - const char * name; - volatile int pid; - volatile int run; - struct completion completion; - int state; -} bkn_thread_ctrl_t; - -static int -bkn_thread_start(bkn_thread_ctrl_t *tc, const char *name, - int (*threadfn)(void *)) -{ - if (name == NULL) { - return -1; - } - tc->name = name; - tc->pid = kernel_thread(threadfn, tc, 0); - if (tc->pid < 0) { - tc->pid = 0; - return -1; - } - tc->run = 1; - init_completion(&tc->completion); - return 0; -} - -static int -bkn_thread_stop(bkn_thread_ctrl_t *tc) -{ - if (tc->pid == 0) { - return 0; - } - tc->run = 0; - kill_proc(tc->pid, SIGTERM, 1); - wait_for_completion(&tc->completion); - return 0; -} - -static int -bkn_thread_should_stop(bkn_thread_ctrl_t *tc) -{ - if (tc->run) { - return 0; - } - tc->pid = 0; - return 1; -} - -static void -bkn_thread_boot(bkn_thread_ctrl_t *tc) -{ - siginitsetinv(¤t->blocked, sigmask(SIGTERM) | sigmask(SIGKILL)); -} - -static void -bkn_thread_exit(bkn_thread_ctrl_t *tc) -{ - complete_and_exit(&tc->completion, 0); -} - static void bkn_sleep(int clicks) { @@ -1007,60 +986,6 @@ bkn_sleep(int clicks) sleep_on_timeout(&wq, clicks); } #else -/* - * New style using kthread API - */ -#include -typedef struct { - const char * name; - struct task_struct *task; - int state; -} bkn_thread_ctrl_t; - -static int -bkn_thread_start(bkn_thread_ctrl_t *tc, const char *name, - int (*threadfn)(void *)) -{ - if (name == NULL) { - return -1; - } - tc->name = name; - tc->task = kthread_run(threadfn, tc, name); - if (IS_ERR(tc->task)) { - tc->task = NULL; - return -1; - } - return 0; -} - -static int -bkn_thread_stop(bkn_thread_ctrl_t *tc) -{ - if (tc->task == NULL) { - return 0; - } - send_sig(SIGTERM, tc->task, 0); - return kthread_stop(tc->task); -} - -static int -bkn_thread_should_stop(bkn_thread_ctrl_t *tc) -{ - return kthread_should_stop(); -} - -static void -bkn_thread_boot(bkn_thread_ctrl_t *tc) -{ - allow_signal(SIGTERM); - allow_signal(SIGKILL); -} - -static void -bkn_thread_exit(bkn_thread_ctrl_t *tc) -{ -} - static void bkn_sleep(int clicks) { @@ -1071,9 +996,6 @@ bkn_sleep(int clicks) } #endif -static bkn_thread_ctrl_t bkn_cmd_ctrl; -static bkn_thread_ctrl_t bkn_evt_ctrl; - /* * On XGS devices bit 15 fo the Transferred Bytes field in * the DCBs is used to indicate that kernel processing is @@ -1399,7 +1321,7 @@ xgsm_cdma_halt_set(bkn_switch_info_t *sinfo, int chan) MEMORY_BARRIER; } -static int +static int xgsm_dma_chan_init(bkn_switch_info_t *sinfo, int chan, int dir) { uint32_t cdc; @@ -1872,7 +1794,7 @@ bkn_alloc_dcbs(bkn_switch_info_t *sinfo) rx_ring_size = dcb_size * (MAX_RX_DCBS + 1); sinfo->dcb_mem_size = tx_ring_size + rx_ring_size * sinfo->rx_chans; - sinfo->dcb_mem = DMA_ALLOC_COHERENT(sinfo->dma_dev, + sinfo->dcb_mem = BKN_DMA_ALLOC_COHERENT(sinfo->dma_dev, sinfo->dcb_mem_size, &dcb_dma); if (sinfo->dcb_mem == NULL) { @@ -1889,7 +1811,7 @@ static void bkn_free_dcbs(bkn_switch_info_t *sinfo) { if (sinfo->dcb_mem != NULL) { - DMA_FREE_COHERENT(sinfo->dma_dev, sinfo->dcb_mem_size, + BKN_DMA_FREE_COHERENT(sinfo->dma_dev, sinfo->dcb_mem_size, sinfo->dcb_mem, (dma_addr_t)sinfo->dcb_dma); sinfo->dcb_mem = NULL; } @@ -1907,9 +1829,9 @@ bkn_clean_tx_dcbs(bkn_switch_info_t *sinfo) if (desc->skb != NULL) { DBG_SKB(("Cleaning Tx SKB from DCB %d.\n", sinfo->tx.dirty)); - DMA_UNMAP_SINGLE(sinfo->dma_dev, + BKN_DMA_UNMAP_SINGLE(sinfo->dma_dev, desc->skb_dma, desc->dma_size, - DMA_TODEV); + BKN_DMA_TODEV); desc->skb_dma = 0; dev_kfree_skb_any(desc->skb); desc->skb = NULL; @@ -1936,9 +1858,9 @@ bkn_clean_rx_dcbs(bkn_switch_info_t *sinfo, int chan) if (desc->skb != NULL) { DBG_SKB(("Cleaning Rx%d SKB from DCB %d.\n", chan, sinfo->rx[chan].dirty)); - DMA_UNMAP_SINGLE(sinfo->dma_dev, + BKN_DMA_UNMAP_SINGLE(sinfo->dma_dev, desc->skb_dma, desc->dma_size, - DMA_FROMDEV); + BKN_DMA_FROMDEV); desc->skb_dma = 0; dev_kfree_skb_any(desc->skb); desc->skb = NULL; @@ -2327,10 +2249,10 @@ bkn_rx_refill(bkn_switch_info_t *sinfo, int chan) desc->dma_size = 0; } #endif - desc->skb_dma = DMA_MAP_SINGLE(sinfo->dma_dev, + desc->skb_dma = BKN_DMA_MAP_SINGLE(sinfo->dma_dev, skb->data, desc->dma_size, - DMA_FROMDEV); - if (DMA_MAPPING_ERROR(sinfo->dma_dev, desc->skb_dma)) { + BKN_DMA_FROMDEV); + if (BKN_DMA_MAPPING_ERROR(sinfo->dma_dev, desc->skb_dma)) { dev_kfree_skb_any(skb); desc->skb = NULL; break; @@ -2532,8 +2454,7 @@ device_is_dnx(bkn_switch_info_t *sinfo) { int is_dnx = 0; - /* No EP_TO_CPU header for DNX(JR2) */ - is_dnx = ((sinfo->cmic_type == 'x') && (sinfo->pkt_hdr_size ==0)) ? 1 : 0; + is_dnx = (sinfo->dcb_type == 39) ? 1 : 0; return is_dnx; } @@ -2572,7 +2493,7 @@ bkn_match_rx_pkt(bkn_switch_info_t *sinfo, uint8_t *pkt, int pktlen, DBG_VERB(("Filter: size = %d (%d), data = 0x%08x, mask = 0x%08x\n", size, wsize, kf->data.w[0], kf->mask.w[0])); - if (device_is_dnx(sinfo)) { + if (device_is_sand(sinfo)) { DBG_DUNE(("Filter: size = %d (wsize %d)\n", size, wsize)); for (idx = 0; idx < wsize; idx++) { @@ -2587,9 +2508,12 @@ bkn_match_rx_pkt(bkn_switch_info_t *sinfo, uint8_t *pkt, int pktlen, match = 1; if (match) { - if (device_is_sand(sinfo)) + if (device_is_dnx(sinfo)) { - /** priority 0 means no priority check */ + /* + * Mutliple RX channels are enabled on JR2 and above devices + * Bind between priority 0 and RX channel 0 is not checked, then all enabled RX channels can receive packets. + */ if (kf->priority && (kf->priority < (num_rx_prio * sinfo->rx_chans))) { if (kf->priority < (num_rx_prio * chan) || kf->priority >= (num_rx_prio * (chan + 1))) { @@ -2671,51 +2595,37 @@ bkn_netif_lookup(bkn_switch_info_t *sinfo, int id) } static int -bkn_hw_tstamp_rx_set(bkn_switch_info_t *sinfo, struct sk_buff *skb, uint32 *meta) +bkn_hw_tstamp_rx_set(bkn_switch_info_t *sinfo, int phys_port, struct sk_buff *skb, uint32 *meta) { struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); - uint32_t *md = meta; uint64_t ts = 0; - switch (sinfo->dcb_type) { - case 26: - case 32: - case 33: - ts = md[14]; - ts = ts << 32 | md[12]; - break; - case 36: - ts = md[10]; - break; - case 38: - ts = md[4] & 0xffff; - ts = ts << 32 | md[5]; - break; - default: - return -1; - } if (knet_hw_tstamp_rx_time_upscale_cb) { - if (knet_hw_tstamp_rx_time_upscale_cb(sinfo->dev_no, &ts) < 0) { + if (knet_hw_tstamp_rx_time_upscale_cb(sinfo->dev_no, phys_port, skb, meta, &ts) < 0) { return -1; } } memset(shhwtstamps, 0, sizeof(*shhwtstamps)); - shhwtstamps->hwtstamp = ns_to_ktime(be64_to_cpu(ts)); + shhwtstamps->hwtstamp = ns_to_ktime(ts); return 0; } static int -bkn_add_rcpu_encap(bkn_switch_info_t *sinfo, struct sk_buff *skb, void *meta) +bkn_add_rcpu_encap(bkn_switch_info_t *sinfo, struct sk_buff *skb, void *meta, int len) { int pktlen = skb->len; uint32_t *dmeta, *smeta, wsize, psize; int idx; /* Add and clear RCPU encapsulation */ - if (sinfo->cmic_type == 'x') { + if (device_is_sand(sinfo)) { + psize = RCPU_RX_ENCAP_SIZE; + skb_push(skb, psize); + memset(skb->data, 0, RCPU_RX_ENCAP_SIZE); + } else if (sinfo->cmic_type == 'x') { psize = RCPU_HDR_SIZE + sinfo->pkt_hdr_size; skb_push(skb, psize); memset(skb->data, 0, RCPU_HDR_SIZE); @@ -2747,12 +2657,20 @@ bkn_add_rcpu_encap(bkn_switch_info_t *sinfo, struct sk_buff *skb, void *meta) /* Meta data */ dmeta = (uint32_t *)&skb->data[RCPU_HDR_SIZE]; - smeta = sinfo->cmic_type == 'x' ? (uint32_t *)meta : (uint32_t *)meta + 2; - wsize = sinfo->cmic_type == 'x' ? sinfo->pkt_hdr_size / 4 : sinfo->dcb_wsize - 3; - for (idx = 0; idx < wsize; idx++) { - dmeta[idx] = htonl(smeta[idx]); + + if (device_is_sand(sinfo)) { + /* Copy at most 64 bytes system headers */ + len = len > RCPU_RX_META_SIZE ? RCPU_RX_META_SIZE : len; + memcpy(&skb->data[RCPU_HDR_SIZE], (uint8_t *)meta, len); + } else { + smeta = sinfo->cmic_type == 'x' ? (uint32_t *)meta : (uint32_t *)meta + 2; + wsize = sinfo->cmic_type == 'x' ? sinfo->pkt_hdr_size / 4 : sinfo->dcb_wsize - 3; + for (idx = 0; idx < wsize; idx++) { + dmeta[idx] = htonl(smeta[idx]); + } } + return 0; } @@ -2781,7 +2699,6 @@ packet_is_untagged(uint16_t tpid) { int is_untagged = 0; - /* Fixme SDK-111398 */ /* 0x8100 is used in 802.1Q */ /* 0x8848 is used in 802.11ad, the dtag tpid can be set to anything besides 0x8848, 0x9100 is a typical value, but couldn't cover all scenarios. */ is_untagged = ((tpid != 0x8100) && (tpid != 0x8848) && (tpid != 0x9100)); @@ -2866,615 +2783,707 @@ bkn_bitstream_get_field(uint8_t *input_buffer, uint32_t start_bit, uint32_t no } static void -bkn_dpp_packet_parse_ftmh(bkn_switch_info_t *sinfo, uint8_t hdr_buff[], bkn_dune_system_header_info_t *packet_info) -{ - uint32_t header_ptr = 0; - uint32_t dsp_ext_exist=0; +bkn_dpp_packet_parse_ftmh( + bkn_switch_info_t *sinfo, + uint8_t *buf, + uint32_t buf_len, + bkn_dune_system_header_info_t *packet_info, + uint8_t *is_tsh_en, + uint8_t *is_inter_hdr_en) +{ + uint32_t pkt_offset = packet_info->system_header_size; + uint32_t dsp_ext_exist = 0; uint32_t fld_val; - header_ptr = packet_info->ntwrk_header_ptr; - - /* Packet-size */ - bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_FTMH_PKT_SIZE_MSB, - BKN_DPP_FTMH_PKT_SIZE_NOF_BITS, - &fld_val); - packet_info->ftmh.packet_size = fld_val; - /* Traffic-class */ + /* FTMH: Source-system-port-aggregate */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_FTMH_TC_MSB, - BKN_DPP_FTMH_TC_NOF_BITS, - &fld_val); - packet_info->ftmh.prio = fld_val; - /* Source-system-port-aggregate */ - bkn_bitstream_get_field( - &hdr_buff[header_ptr], + &buf[pkt_offset], BKN_DPP_FTMH_SRC_SYS_PORT_MSB, BKN_DPP_FTMH_SRC_SYS_PORT_NOF_BITS, - &fld_val); - packet_info->ftmh.src_sys_port = fld_val; - /* TM-action-type */ + &packet_info->ftmh.source_sys_port_aggregate); + /* FTMH: TM-action-type */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], + &buf[pkt_offset], BKN_DPP_FTMH_ACTION_TYPE_MSB, BKN_DPP_FTMH_ACTION_TYPE_NOF_BITS, - &fld_val); - packet_info->ftmh.action_type = fld_val; - /* PPH-type */ + &packet_info->ftmh.action_type); + /* FTMH: Internal-type */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], + &buf[pkt_offset], BKN_DPP_FTMH_PPH_TYPE_MSB, BKN_DPP_FTMH_PPH_TYPE_NOF_BITS, &fld_val); - packet_info->ftmh.pph_type = fld_val; - - packet_info->ntwrk_header_ptr += BKN_DPP_FTMH_SIZE_BYTE; - DBG_DUNE(("FTMH(%d) Packet-size %d Action-type %d PPH-type %d Source-system-port 0x%x Traffic-class %d\n", - packet_info->ntwrk_header_ptr, packet_info->ftmh.packet_size, packet_info->ftmh.action_type, - packet_info->ftmh.pph_type, packet_info->ftmh.src_sys_port, packet_info->ftmh.prio)); - /* LB-Key ext */ - if ((sinfo->pkt_hdr_size & BKN_DPP_FTMH_LB_EXT_EN) == BKN_DPP_FTMH_LB_EXT_EN) - { - packet_info->ntwrk_header_ptr += BKN_DPP_FTMH_LB_EXT_SIZE_BYTE; - DBG_DUNE(("FTMH(%d) FTMH LB-Key Extension is present\n", packet_info->ntwrk_header_ptr)); - } - /* DSP ext*/ - fld_val = 0; + /* FTMH: DSP Extension */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], + &buf[pkt_offset], BKN_DPP_FTMH_EXT_DSP_EXIST_MSB, BKN_DPP_FTMH_EXT_DSP_EXIST_NOF_BITS, &dsp_ext_exist); + + if (fld_val & 0x1) + { + *is_inter_hdr_en = TRUE; + } + if (fld_val & 0x2) + { + *is_tsh_en = TRUE; + } + + pkt_offset += BKN_DPP_FTMH_SIZE_BYTE; + DBG_DUNE(("FTMH(9-%u): Action-type %d Source-system-port 0x%x\n", pkt_offset, + packet_info->ftmh.action_type, + packet_info->ftmh.source_sys_port_aggregate)); + + /* FTMH LB-Key Extension */ + if (sinfo->ftmh_lb_key_ext_size) + { + pkt_offset += sinfo->ftmh_lb_key_ext_size; + DBG_DUNE(("FTMH LB-Key Extension(1-%u) is present\n", pkt_offset)); + } + if (dsp_ext_exist) { - packet_info->ntwrk_header_ptr += BKN_DPP_FTMH_DEST_EXT_SIZE_BYTE; - DBG_DUNE(("FTMH(%d) DSP-extension-present 1\n", packet_info->ntwrk_header_ptr)); + pkt_offset += BKN_DPP_FTMH_DEST_EXT_SIZE_BYTE; + DBG_DUNE(("FTMH DSP Extension(2-%u) is present\n", pkt_offset)); } - /* stacking ext */ - if ((sinfo->pkt_hdr_size & BKN_DPP_FTMH_STACKING_EXT_EN) == BKN_DPP_FTMH_STACKING_EXT_EN) + /* FTMH Stacking Extension */ + if (sinfo->ftmh_stacking_ext_size) { - packet_info->ntwrk_header_ptr += BKN_DPP_FTMH_STACKING_SIZE_BYTE; - DBG_DUNE(("FTMH(%d) FTMH Stacking Extension is present\n", packet_info->ntwrk_header_ptr)); + pkt_offset += sinfo->ftmh_stacking_ext_size; + DBG_DUNE(("FTMH Stacking Extension(2-%u) is present\n", pkt_offset)); } + + packet_info->system_header_size = pkt_offset; return; } static void -bkn_dpp_packet_parse_internal(bkn_switch_info_t *sinfo, uint8_t hdr_buff[], bkn_dune_system_header_info_t *packet_info) -{ - uint32_t header_ptr = 0; - uint32_t fld_val; +bkn_dpp_packet_parse_otsh( + bkn_switch_info_t *sinfo, + uint8_t *buf, + uint32_t buf_len, + bkn_dune_system_header_info_t *packet_info, + uint8_t *is_oam_dm_tod_en, + uint8_t *is_skip_udh) +{ + uint32_t pkt_offset = packet_info->system_header_size; + uint32_t type = 0; + uint32_t oam_sub_type = 0; + + /* OTSH: TYPE */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DPP_OTSH_TYPE_MSB, + BKN_DPP_OTSH_TYPE_NOF_BITS, + &type); + if (type == BKN_DPP_OTSH_TYPE_OAM) { + /* OTSH: OAM_SUB_TYPE */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DPP_OTSH_OAM_SUB_TYPE_MSB, + BKN_DPP_OTSH_OAM_SUB_TYPE_NOF_BITS, + &oam_sub_type); + if ((oam_sub_type == BKN_DPP_OTSH_OAM_SUB_TYPE_DM_1588) || (oam_sub_type == BKN_DPP_OTSH_OAM_SUB_TYPE_DM_NTP)) { + *is_oam_dm_tod_en = TRUE; + /* Down MEP DM trapped packets will not have UDH present (even if configured), except for QAX when custom_feature_oam_dm_tod_msb_add_enable=0 */ + if (!sinfo->no_skip_udh_check) { + *is_skip_udh = TRUE; + } + } + } + packet_info->system_header_size += BKN_DPP_OTSH_SIZE_BYTE; + + DBG_DUNE(("OTSH(%d): Type 0x%x OAM-Sub-Type 0x%x\n", BKN_DPP_OTSH_SIZE_BYTE, type, oam_sub_type)); + return; +} + +static void +bkn_dpp_packet_parse_internal( + bkn_switch_info_t *sinfo, + uint8_t *buf, + uint32_t buf_len, + bkn_dune_system_header_info_t *packet_info, + uint8_t is_oamp_punted, + uint8_t *is_trapped) +{ + uint32_t pkt_offset = packet_info->system_header_size; + uint32_t fld_val = 0; uint32_t eei_extension_present = 0; uint32_t learn_extension_present = 0; uint32_t fhei_size = 0; - uint32_t forward_code; - uint8_t is_trapped = 0; - - header_ptr = packet_info->ntwrk_header_ptr; + /* Internal: EEI EXT */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_PPH_EEI_EXTENSION_PRESENT_MSB, - BKN_DPP_PPH_EEI_EXTENSION_PRESENT_NOF_BITS, + &buf[pkt_offset], + BKN_DPP_INTERNAL_EEI_EXTENSION_PRESENT_MSB, + BKN_DPP_INTERNAL_EEI_EXTENSION_PRESENT_NOF_BITS, &eei_extension_present); + /* Internal: LERAN EXT */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_PPH_LEARN_EXENSION_PRESENT_MSB, - BKN_DPP_PPH_LEARN_EXENSION_PRESENT_NOF_BITS, + &buf[pkt_offset], + BKN_DPP_INTERNAL_LEARN_EXENSION_PRESENT_MSB, + BKN_DPP_INTERNAL_LEARN_EXENSION_PRESENT_NOF_BITS, &learn_extension_present); + /* Internal: FHEI EXT */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_PPH_FHEI_SIZE_MSB, - BKN_DPP_PPH_FHEI_SIZE_NOF_BITS, + &buf[pkt_offset], + BKN_DPP_INTERNAL_FHEI_SIZE_MSB, + BKN_DPP_INTERNAL_FHEI_SIZE_NOF_BITS, &fhei_size); + /* Internal: FORWARD_CODE */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_PPH_FORWARD_CODE_MSB, - BKN_DPP_PPH_FORWARD_CODE_NOF_BITS, - &forward_code); - /* 7: CPU-Trap */ - is_trapped = (uint8_t)(forward_code == 7); - + &buf[pkt_offset], + BKN_DPP_INTERNAL_FORWARD_CODE_MSB, + BKN_DPP_INTERNAL_FORWARD_CODE_NOF_BITS, + &fld_val); + *is_trapped = (uint8_t)(fld_val == BKN_DPP_INTERNAL_FORWARD_CODE_CPU_TRAP); + /* Internal: VSI */ bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_PPH_VSI_MSB, - BKN_DPP_PPH_VSI_NOF_BITS, + &buf[pkt_offset], + BKN_DPP_INTERNAL_VSI_MSB, + BKN_DPP_INTERNAL_VSI_NOF_BITS, &fld_val); - packet_info->internal.vsi = fld_val; + packet_info->internal.forward_domain = fld_val; - /* size of PPH base is 7 */ - packet_info->ntwrk_header_ptr += BKN_DPP_PPH_SIZE_BYTE; - header_ptr = packet_info->ntwrk_header_ptr; + if (is_oamp_punted && *is_trapped) { + if(fhei_size == 3) { + /* Force to FHEI size 1 when packets are punted by OAMP */ + fhei_size = 1; + } + } - DBG_DUNE(("PPH(%d) Forward-Code %d EEI-Extension %d Learn-Extension %d VSI %d FHEI-size %d\n", packet_info->ntwrk_header_ptr, - forward_code, eei_extension_present, learn_extension_present, packet_info->internal.vsi, fhei_size)); + /* Move forward to end of Internal header */ + pkt_offset += BKN_DPP_INTERNAL_SIZE_BYTE; - /* PPH extension */ - if (is_trapped && (fhei_size == 1)) - { - /* CPU trap code qualifier */ - bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_MSB, - BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_NOF_BITS, - &fld_val); - packet_info->internal.trap_qualifier = fld_val; - /* CPU trap code */ - bkn_bitstream_get_field( - &hdr_buff[header_ptr], - BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_MSB, - BKN_DPP_PPH_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_NOF_BITS, - &fld_val); - packet_info->internal.trap_id = fld_val; - } + DBG_DUNE(("PPH(7-%u): EEI-Extension %d Learn-Extension %d VSI %d FHEI-size %d\n", + pkt_offset, eei_extension_present,learn_extension_present, packet_info->internal.forward_domain, fhei_size)); + + /* Advance header according to FHEI Trap extension */ switch(fhei_size) { case 1: - packet_info->ntwrk_header_ptr += BKN_DPP_PPH_FHEI_3B_SIZE_BYTE; + /* 3B FHEI Extension: do nothing, header poniter is in the right location */ break; case 2: - packet_info->ntwrk_header_ptr += BKN_DPP_PPH_FHEI_5B_SIZE_BYTE; + /* 5B FHEI Extension: adavance header pointer in 2B */ + pkt_offset += 2; break; case 3: - packet_info->ntwrk_header_ptr += BKN_DPP_PPH_FHEI_8B_SIZE_BYTE; + /* 8B FHEI Extension: adavance header pointer in 5B */ + pkt_offset += 5; break; default: break; } + + /* Internal extension */ + if (*is_trapped && fhei_size) + { + /* CPU trap code qualifier */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_MSB, + BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_QUALIFIER_NOF_BITS, + &packet_info->internal.trap_qualifier); + /* CPU trap code */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_MSB, + BKN_DPP_INTERNAL_FHEI_TRAP_SNOOP_3B_CPU_TRAP_CODE_NOF_BITS, + &packet_info->internal.trap_id); + + DBG_DUNE(("FHEI: trap_qualifier 0x%x trap_id 0x%x\n", + packet_info->internal.trap_qualifier, + packet_info->internal.trap_id)); + } + + /* Move forward to end of FHEI Trap extension */ + if (fhei_size) { + pkt_offset += 3; + } + + /* EEI extension */ if (eei_extension_present) { - packet_info->ntwrk_header_ptr += BKN_DPP_PPH_EXPLICIT_EDITING_INFOMATION_EXTENSION_SIZE_BYTE; + pkt_offset += BKN_DPP_INTERNAL_EXPLICIT_EDITING_INFOMATION_EXTENSION_SIZE_BYTE; } + /* Learn extension */ if (learn_extension_present) { - packet_info->ntwrk_header_ptr += BKN_DPP_PPH_LEARN_EXTENSION_SIZE_BYTE; + pkt_offset += BKN_DPP_INTERNAL_LEARN_EXTENSION_SIZE_BYTE; } - DBG_DUNE(("FHEI(%d) trap_qualifier 0x%x trap_id 0x%x\n", packet_info->ntwrk_header_ptr, packet_info->internal.trap_qualifier, packet_info->internal.trap_id)); + packet_info->system_header_size = pkt_offset; return; } static int -bkn_dpp_packet_header_parse(bkn_switch_info_t *sinfo, uint8 *buff, uint32_t buff_len, bkn_dune_system_header_info_t *packet_info) -{ - uint8_t hdr_buff[BKN_DPP_HDR_MAX_SIZE]; - uint32_t hdr_size; - uint8_t has_internal = 0; - - if ((buff == NULL) || (packet_info == NULL)) { +bkn_dpp_packet_header_parse( + bkn_switch_info_t *sinfo, + uint8_t *buff, + uint32_t buff_len, + bkn_dune_system_header_info_t *packet_info) +{ + uint8_t is_inter_hdr_en = FALSE; + uint8_t is_tsh_en = FALSE; + uint8_t is_oamp_punted = FALSE; + uint8_t is_trapped = FALSE; + uint8_t is_oam_dm_tod_en = FALSE; + uint8_t is_skip_udh = FALSE; + + if ((sinfo == NULL) || (buff == NULL) || (packet_info == NULL)) { return -1; } - hdr_size = buff_len < BKN_DPP_HDR_MAX_SIZE ? buff_len: BKN_DPP_HDR_MAX_SIZE; - memcpy(hdr_buff, buff, hdr_size); /* FTMH */ - bkn_dpp_packet_parse_ftmh(sinfo, hdr_buff, packet_info); - if (packet_info->ftmh.packet_size != (buff_len + 2)) { - DBG_DUNE(("FTMH packet size verfication failed, %d-%d\n", packet_info->ftmh.packet_size, buff_len)); - memset(packet_info, 0, sizeof(bkn_dune_system_header_info_t)); - return -1; + bkn_dpp_packet_parse_ftmh(sinfo, buff, buff_len, packet_info, &is_tsh_en, &is_inter_hdr_en); + /* Check if packet is punted from OAMP */ + if (sinfo->oamp_punt && (packet_info->ftmh.source_sys_port_aggregate == sinfo->oamp_punt)) { + is_oamp_punted = TRUE; } - switch (packet_info->ftmh.pph_type) { - case 0: - has_internal = 0; - break; - case 1: - has_internal = 1; - break; - case 2: /* PPH OAM-TS only */ - case 3: /* PPH Base + OAM-TS */ - /* OTSH immediately follows the FTMH when present */ - packet_info->ntwrk_header_ptr += 6; - DBG_DUNE(("FTMH + OAM-TS(%d)\n", packet_info->ntwrk_header_ptr)); - has_internal = 1; - break; - default: - break; + /* OTSH */ + if (is_tsh_en == TRUE) + { + bkn_dpp_packet_parse_otsh(sinfo, buff, buff_len, packet_info, &is_oam_dm_tod_en, &is_skip_udh); + } + /* Internal header is forced to be present if packet was punted to CPU by OAMP */ + if (sinfo->oamp_punt && (packet_info->ftmh.source_sys_port_aggregate == sinfo->oamp_punt)) + { + is_inter_hdr_en = TRUE; + } + /* Internal */ + if (is_inter_hdr_en) + { + bkn_dpp_packet_parse_internal(sinfo, buff, buff_len, packet_info, is_oamp_punted, &is_trapped); + } + /* Skip UDH for the outer layer when packet is punted by OAM for JR2 in JR1 mode */ + if (device_is_dnx(sinfo) && is_oamp_punted) { + is_skip_udh = TRUE; + } + /* UDH */ + if (sinfo->udh_size && !is_skip_udh) { + packet_info->system_header_size += sinfo->udh_size; + } + /* OAM DM TOD header */ + if(is_oam_dm_tod_en) { + packet_info->system_header_size += BKN_DPP_OAM_DM_TOD_SIZE_BYTE; } - if (has_internal) { - bkn_dpp_packet_parse_internal(sinfo, &hdr_buff[0], packet_info); + /* Additional layer of system headers */ + if (is_oamp_punted && is_trapped) + { + is_inter_hdr_en = FALSE; + is_tsh_en = FALSE; + is_oamp_punted = FALSE; + is_trapped = FALSE; + is_oam_dm_tod_en = FALSE; + is_skip_udh = FALSE; + + /* FTMH */ + bkn_dpp_packet_parse_ftmh(sinfo, buff, buff_len, packet_info, &is_tsh_en, &is_inter_hdr_en); + /* OTSH */ + if (is_tsh_en == TRUE) + { + bkn_dpp_packet_parse_otsh(sinfo, buff, buff_len, packet_info, &is_oam_dm_tod_en, &is_skip_udh); + } + /* Internal */ + if (is_inter_hdr_en) + { + bkn_dpp_packet_parse_internal(sinfo, buff, buff_len, packet_info, is_oamp_punted, &is_trapped); + } + /* OAMP Punted packets do not have UDH in the inner header for both JR1 and JR2 in JR1 mode */ + /* OAM DM TOD header */ + if(is_oam_dm_tod_en) { + packet_info->system_header_size += BKN_DPP_OAM_DM_TOD_SIZE_BYTE; + } } - /* FIXME: */ - /* ignore packets with a double set of FTMH,internals */ - /* ignore the user header size */ + DBG_DUNE(("Total length of headers is %u\n", packet_info->system_header_size)); + return 0; } + static int -bkn_dnx_packet_header_parse(bkn_switch_info_t *sinfo, uint8 *buf, uint32_t buf_len, bkn_dune_system_header_info_t *packet_info) +bkn_dnx_packet_parse_ftmh( + bkn_switch_info_t *sinfo, + uint8_t *buf, + uint32_t buf_len, + bkn_dune_system_header_info_t *packet_info, + uint8_t *is_tsh_en, + uint8_t *is_inter_hdr_en) { uint32_t fld_val; - uint32_t hdr_size = 0; - uint32_t pkt_offset_ingress_untrapped =0; + uint32_t pkt_offset = packet_info->system_header_size; uint8_t tm_dst_ext_present = 0; uint8_t app_specific_ext_size = 0; uint8_t flow_id_ext_size = 0; uint8_t bier_bfr_ext_size = 0; - uint8_t is_pph_en = 0; - uint8_t is_tsh_en = 0; - if ((buf == NULL) || (packet_info == NULL)) { + if ((sinfo == NULL) || (buf == NULL) || (packet_info == NULL)) { return -1; } /* FTMH: Source-System-Port-Aggregate */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_FTMH_SRC_SYS_PORT_AGGREGATE_MSB, BKN_DNX_FTMH_SRC_SYS_PORT_AGGREGATE_NOF_BITS, &fld_val); - packet_info->ftmh_spa = fld_val; + packet_info->ftmh.source_sys_port_aggregate = fld_val; + /* FTMH: Action-Type */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DNX_FTMH_ACTION_TYPE_MSB, + BKN_DNX_FTMH_ACTION_TYPE_NOF_BITS, + &fld_val); + packet_info->ftmh.action_type = fld_val; /* FTMH: PPH-Type TSH */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_FTMH_PPH_TYPE_IS_TSH_EN_MSB, BKN_DNX_FTMH_PPH_TYPE_IS_TSH_EN_NOF_BITS, &fld_val); - is_tsh_en = fld_val; + *is_tsh_en = fld_val; /* FTMH: PPH-Type PPH base */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_FTMH_PPH_TYPE_IS_PPH_EN_MSB, BKN_DNX_FTMH_PPH_TYPE_IS_PPH_EN_NOF_BITS, &fld_val); - is_pph_en = fld_val; + *is_inter_hdr_en = fld_val; /* FTMH: TM-Destination-Extension-Present */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_FTMH_TM_DST_EXT_PRESENT_MSB, BKN_DNX_FTMH_TM_DST_EXT_PRESENT_NOF_BITS, &fld_val); tm_dst_ext_present = fld_val; /* FTMH: Application-Specific-Extension-Size */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_FTMH_APP_SPECIFIC_EXT_SIZE_MSB, BKN_DNX_FTMH_APP_SPECIFIC_EXT_SIZE_NOF_BITS, &fld_val); app_specific_ext_size = fld_val; /* FTMH: Flow-ID-Extension-Size */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_FTMH_FLOW_ID_EXT_SIZE_MSB, BKN_DNX_FTMH_FLOW_ID_EXT_SIZE_NOF_BITS, &fld_val); flow_id_ext_size = fld_val; /* FTMH: BIER-BFR-Extension-Size */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_FTMH_BIER_BFR_EXT_SIZE_MSB, BKN_DNX_FTMH_BIER_BFR_EXT_SIZE_NOF_BITS, &fld_val); bier_bfr_ext_size = fld_val; - hdr_size = BKN_DNX_FTMH_BASE_SIZE; - pkt_offset_ingress_untrapped = BKN_DNX_FTMH_BASE_SIZE; + pkt_offset += BKN_DNX_FTMH_BASE_SIZE; - DBG_DUNE(("FTMH(%d) source-system-port 0x%x is_tsh_en %d is_pph_en %d\n", - hdr_size, packet_info->ftmh_spa, is_tsh_en, is_pph_en)); + DBG_DUNE(("FTMH(10-%u): source-system-port 0x%x action_type %u is_tsh_en %u is_inter_hdr_en %u\n", + pkt_offset, packet_info->ftmh.source_sys_port_aggregate, + packet_info->ftmh.action_type, *is_tsh_en, *is_inter_hdr_en)); /* FTMH LB-Key Extension */ if (sinfo->ftmh_lb_key_ext_size > 0) { - hdr_size += sinfo->ftmh_lb_key_ext_size; - DBG_DUNE(("FTMH LB-Key Extension(%d) is present\n", sinfo->ftmh_lb_key_ext_size)); + pkt_offset += sinfo->ftmh_lb_key_ext_size; + DBG_DUNE(("FTMH LB-Key Extension(%u-%u) is present\n", sinfo->ftmh_lb_key_ext_size, pkt_offset)); } /* FTMH Stacking Extension */ if (sinfo->ftmh_stacking_ext_size > 0) { - hdr_size += sinfo->ftmh_stacking_ext_size; - DBG_DUNE(("FTMH Stacking Extension(%d) is present\n", sinfo->ftmh_stacking_ext_size)); + pkt_offset += sinfo->ftmh_stacking_ext_size; + DBG_DUNE(("FTMH Stacking Extension(%u-%u) is present\n", sinfo->ftmh_stacking_ext_size, pkt_offset)); } /* FTMH BIER BFR Extension */ if (bier_bfr_ext_size > 0) { - hdr_size += BKN_DNX_FTMH_BIER_BFR_EXT_SIZE; - DBG_DUNE(("FTMH BIER BFR Extension(2) is present\n")); + pkt_offset += BKN_DNX_FTMH_BIER_BFR_EXT_SIZE; + DBG_DUNE(("FTMH BIER BFR Extension(2-%u) is present\n", pkt_offset)); } /* FTMH TM Destination Extension */ if (tm_dst_ext_present > 0) { - hdr_size += BKN_DNX_FTMH_TM_DST_EXT_SIZE; - DBG_DUNE(("FTMH TM Destination Extension(3) is present\n")); + pkt_offset += BKN_DNX_FTMH_TM_DST_EXT_SIZE; + DBG_DUNE(("FTMH TM Destination Extension(3-%u) is present\n", pkt_offset)); } /* FTMH Application Specific Extension */ if (app_specific_ext_size > 0) { - hdr_size += BKN_DNX_FTMH_APP_SPECIFIC_EXT_SIZE; - DBG_DUNE(("FTMH Application Specific Extension(6) is present\n")); + pkt_offset += BKN_DNX_FTMH_APP_SPECIFIC_EXT_SIZE; + DBG_DUNE(("FTMH Application Specific Extension(6-%u) is present\n", pkt_offset)); } /* FTMH Flow-ID Extension */ if (flow_id_ext_size > 0) { - hdr_size += BKN_DNX_FTMH_FLOW_ID_EXT_SIZE; - DBG_DUNE(("FTMH Flow-ID Extension(3) is present\n")); + pkt_offset += BKN_DNX_FTMH_FLOW_ID_EXT_SIZE; + DBG_DUNE(("FTMH Flow-ID Extension(3-%u) is present\n", pkt_offset)); } - /* Given the packet is trapped to CPU */ + packet_info->system_header_size = pkt_offset; - /* Time-Stamp Header */ - if (is_tsh_en == TRUE) - { - hdr_size += BKN_DNX_TSH_SIZE; - DBG_DUNE(("Time-Stamp Header(4) is present\n")); - } + return 0; +} - /* Packet Processing Header */ - if (is_pph_en) - { - uint8_t learn_ext_present; - uint8_t fhei_size; - uint8_t lif_ext_type; - switch (sinfo->pph_base_size) - { - case BKN_DNX_PPH_BASE_TYPE_9: - /* FTMH: Forward-Domain */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_9_FORWARD_DOMAIN_MSB, - BKN_DNX_PPH_9_FORWARD_DOMAIN_NOF_BITS, - &fld_val); - packet_info->pph_forward_domain = fld_val; - /* FTMH: Learn-Extension-Present */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_9_LEARN_EXT_PRESENT_MSB, - BKN_DNX_PPH_9_LEARN_EXT_PRESENT_NOF_BITS, - &fld_val); - learn_ext_present = fld_val; - /* FTMH: FHEI-Size */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_9_FHEI_SIZE_MSB, - BKN_DNX_PPH_9_FHEI_SIZE_NOF_BITS, - &fld_val); - fhei_size = fld_val; - /* FTMH: LIF-Extension-Type */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_9_LIF_EXT_TYPE_MSB, - BKN_DNX_PPH_9_LIF_EXT_TYPE_NOF_BITS, - &fld_val); - lif_ext_type = fld_val; +static int +bkn_dnx_packet_parse_internal( + bkn_switch_info_t *sinfo, + uint8_t *buf, + uint32_t buf_len, + bkn_dune_system_header_info_t *packet_info, + uint8_t is_oamp_punted, + uint8_t *is_trapped) +{ + uint32_t fld_val; + uint32_t pkt_offset = packet_info->system_header_size; + uint8_t learn_ext_present; + uint8_t fhei_size; + uint8_t lif_ext_type; + uint8_t udh_en = sinfo->udh_enable; - hdr_size += BKN_DNX_PPH_BASE_TYPE_9; - DBG_DUNE(("PPH(10) FWD_DOMAIN %d, LEARN_EXT %d, FHEI_SIZE %d, LIF_EXT %d \n", - packet_info->pph_forward_domain, learn_ext_present, fhei_size, lif_ext_type)); - break; - case BKN_DNX_PPH_BASE_TYPE_10: - /* FTMH: Forward-Domain */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_10_FORWARD_DOMAIN_MSB, - BKN_DNX_PPH_10_FORWARD_DOMAIN_NOF_BITS, - &fld_val); - packet_info->pph_forward_domain = fld_val; - /* FTMH: Learn-Extension-Present */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_10_LEARN_EXT_PRESENT_MSB, - BKN_DNX_PPH_10_LEARN_EXT_PRESENT_NOF_BITS, - &fld_val); - learn_ext_present = fld_val; - /* FTMH: FHEI-Size */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_10_FHEI_SIZE_MSB, - BKN_DNX_PPH_10_FHEI_SIZE_NOF_BITS, - &fld_val); - fhei_size = fld_val; - /* FTMH: LIF-Extension-Type */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_10_LIF_EXT_TYPE_MSB, - BKN_DNX_PPH_10_LIF_EXT_TYPE_NOF_BITS, - &fld_val); - lif_ext_type = fld_val; + if ((sinfo == NULL) || (buf == NULL) || (packet_info == NULL)) { + return -1; + } + + /* Internal: Forward-Domain */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DNX_INTERNAL_12_FORWARD_DOMAIN_MSB, + BKN_DNX_INTERNAL_12_FORWARD_DOMAIN_NOF_BITS, + &fld_val); + packet_info->internal.forward_domain = fld_val; + /* Internal: Learn-Extension-Present */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DNX_INTERNAL_12_LEARN_EXT_PRESENT_MSB, + BKN_DNX_INTERNAL_12_LEARN_EXT_PRESENT_NOF_BITS, + &fld_val); + learn_ext_present = fld_val; + /* Internal: FHEI-Size */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DNX_INTERNAL_12_FHEI_SIZE_MSB, + BKN_DNX_INTERNAL_12_FHEI_SIZE_NOF_BITS, + &fld_val); + fhei_size = fld_val; + /* Internal: LIF-Extension-Type */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DNX_INTERNAL_12_LIF_EXT_TYPE_MSB, + BKN_DNX_INTERNAL_12_LIF_EXT_TYPE_NOF_BITS, + &fld_val); + lif_ext_type = fld_val; - hdr_size += BKN_DNX_PPH_BASE_TYPE_10; - DBG_DUNE(("PPH(10) FWD_DOMAIN %d, LEARN_EXT %d, FHEI_SIZE %d, LIF_EXT %d \n", - packet_info->pph_forward_domain, learn_ext_present, fhei_size, lif_ext_type)); + pkt_offset += BKN_DNX_INTERNAL_BASE_TYPE_12; + DBG_DUNE(("Internal(12-%u): FWD_DOMAIN %d, LEARN_EXT %d, FHEI_SIZE %d, LIF_EXT %d \n", + pkt_offset, packet_info->internal.forward_domain, + learn_ext_present, fhei_size, lif_ext_type)); + + if (fhei_size) + { + switch (fhei_size) + { + case BKN_DNX_INTERNAL_FHEI_TYPE_SZ0: + pkt_offset += BKN_DNX_INTERNAL_FHEI_SZ0_SIZE; + DBG_DUNE(("FHEI(3-%u) is present\n", pkt_offset)); break; - case BKN_DNX_PPH_BASE_TYPE_12: - /* FTMH: Forward-Domain */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_12_FORWARD_DOMAIN_MSB, - BKN_DNX_PPH_12_FORWARD_DOMAIN_NOF_BITS, - &fld_val); - packet_info->pph_forward_domain = fld_val; - /* FTMH: Learn-Extension-Present */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_12_LEARN_EXT_PRESENT_MSB, - BKN_DNX_PPH_12_LEARN_EXT_PRESENT_NOF_BITS, - &fld_val); - learn_ext_present = fld_val; - /* FTMH: FHEI-Size */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_12_FHEI_SIZE_MSB, - BKN_DNX_PPH_12_FHEI_SIZE_NOF_BITS, - &fld_val); - fhei_size = fld_val; - /* FTMH: LIF-Extension-Type */ + case BKN_DNX_INTERNAL_FHEI_TYPE_SZ1: + /* FHEI: Type */ bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_12_LIF_EXT_TYPE_MSB, - BKN_DNX_PPH_12_LIF_EXT_TYPE_NOF_BITS, + &buf[pkt_offset], + BKN_DNX_INTERNAL_FHEI_TRAP_5B_TYPE_MSB, + BKN_DNX_INTERNAL_FHEI_TRAP_5B_TYPE_NOF_BITS, &fld_val); - lif_ext_type = fld_val; - - hdr_size += BKN_DNX_PPH_BASE_TYPE_12; - DBG_DUNE(("PPH(12) FWD_DOMAIN %d, LEARN_EXT %d, FHEI_SIZE %d, LIF_EXT %d \n", - packet_info->pph_forward_domain, learn_ext_present, fhei_size, lif_ext_type)); - break; - default: - fhei_size = 0; - lif_ext_type = 0; - learn_ext_present = 0; - break; - } - if (fhei_size) - { - switch (fhei_size) - { - case BKN_DNX_PPH_FHEI_TYPE_SZ0: - hdr_size += BKN_DNX_PPH_FHEI_SZ0_SIZE; - DBG_DUNE(("FHEI(3) is present\n")); - break; - case BKN_DNX_PPH_FHEI_TYPE_SZ1: + /* FHEI-Size == 5B, FHEI-Type == Trap/Sniff */ + if (fld_val == 0x5) + { + *is_trapped = TRUE; + /* FHEI: Qualifier */ + bkn_bitstream_get_field( + &buf[pkt_offset], + BKN_DNX_INTERNAL_FHEI_TRAP_5B_QUALIFIER_MSB, + BKN_DNX_INTERNAL_FHEI_TRAP_5B_QUALIFIER_NOF_BITS, + &fld_val); + packet_info->internal.trap_qualifier = fld_val; /* FHEI: Code */ bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_FHEI_TRAP_5B_TYPE_MSB, - BKN_DNX_PPH_FHEI_TRAP_5B_TYPE_NOF_BITS, + &buf[pkt_offset], + BKN_DNX_INTERNAL_FHEI_TRAP_5B_CODE_MSB, + BKN_DNX_INTERNAL_FHEI_TRAP_5B_CODE_NOF_BITS, &fld_val); - packet_info->fhei_type = fld_val; - /* FHEI-Size == 5B, FHEI-Type == Trap/Sniff */ - if (packet_info->fhei_type == 0x5) - { - /* FHEI: Qualifier */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_FHEI_TRAP_5B_QUALIFIER_MSB, - BKN_DNX_PPH_FHEI_TRAP_5B_QUALIFIER_NOF_BITS, - &fld_val); - packet_info->fhei_qualifier = fld_val; - /* FHEI: Code */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_FHEI_TRAP_5B_CODE_MSB, - BKN_DNX_PPH_FHEI_TRAP_5B_CODE_NOF_BITS, - &fld_val); - packet_info->fhei_code = fld_val; - } - hdr_size += BKN_DNX_PPH_FHEI_SZ1_SIZE; - DBG_DUNE(("FHEI(5) is present code 0x%x qualifier 0x%x\n", packet_info->fhei_code, packet_info->fhei_qualifier)); - break; - case BKN_DNX_PPH_FHEI_TYPE_SZ2: - hdr_size += BKN_DNX_PPH_FHEI_SZ1_SIZE; - DBG_DUNE(("FHEI(8) is present\n")); - break; - } + packet_info->internal.trap_id= fld_val; + } + pkt_offset += BKN_DNX_INTERNAL_FHEI_SZ1_SIZE; + DBG_DUNE(("FHEI(5-%u): code 0x%x qualifier 0x%x\n", pkt_offset, packet_info->internal.trap_id, packet_info->internal.trap_qualifier)); + break; + case BKN_DNX_INTERNAL_FHEI_TYPE_SZ2: + pkt_offset += BKN_DNX_INTERNAL_FHEI_SZ1_SIZE; + DBG_DUNE(("FHEI(8-%u) is present\n", pkt_offset)); + break; } + } - /* PPH LIF Extension */ - if (lif_ext_type) - { - hdr_size += sinfo->pph_lif_ext_size[lif_ext_type]; - DBG_DUNE(("PPH LIF Extension(%d) is present\n", sinfo->pph_lif_ext_size[lif_ext_type])); - } + /* PPH LIF Extension */ + if (lif_ext_type) + { + pkt_offset += sinfo->pph_lif_ext_size[lif_ext_type]; + DBG_DUNE(("PPH LIF Extension(%d-%u) is present\n", sinfo->pph_lif_ext_size[lif_ext_type], pkt_offset)); + } - /* PPH Learn Extension */ - if (learn_ext_present) - { - hdr_size += BKN_DNX_PPH_LEARN_EXT_SIZE; - DBG_DUNE(("PPH Learn Extension(19) is present\n")); - } + /* PPH Learn Extension */ + if (learn_ext_present) + { + pkt_offset += BKN_DNX_INTERNAL_LEARN_EXT_SIZE; + DBG_DUNE(("PPH Learn Extension(19-%u) is present\n", pkt_offset)); + } + + /** Skip UDH If packet is punted to CPU by OAMP */ + if (is_oamp_punted) { + udh_en = FALSE; } /* UDH Header */ - if (sinfo->udh_enable) + if (udh_en) { - uint8 data_type_0; - uint8 data_type_1; - uint8 data_type_2; - uint8 data_type_3; - - DBG_DUNE(("UDH base(1) is present\n")); + uint8_t data_type_0; + uint8_t data_type_1; + uint8_t data_type_2; + uint8_t data_type_3; /* UDH: UDH-Data-Type[0] */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_UDH_DATA_TYPE_0_MSB, BKN_DNX_UDH_DATA_TYPE_0_NOF_BITS, &fld_val); data_type_0 = fld_val; - hdr_size += sinfo->udh_length_type[data_type_0]; /* UDH: UDH-Data-Type[1] */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_UDH_DATA_TYPE_1_MSB, BKN_DNX_UDH_DATA_TYPE_1_NOF_BITS, &fld_val); data_type_1 = fld_val; - hdr_size += sinfo->udh_length_type[data_type_1]; /* UDH: UDH-Data-Type[2] */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_UDH_DATA_TYPE_2_MSB, BKN_DNX_UDH_DATA_TYPE_2_NOF_BITS, &fld_val); data_type_2 = fld_val; - hdr_size += sinfo->udh_length_type[data_type_2]; /* UDH: UDH-Data-Type[3] */ bkn_bitstream_get_field( - &buf[hdr_size], + &buf[pkt_offset], BKN_DNX_UDH_DATA_TYPE_3_MSB, BKN_DNX_UDH_DATA_TYPE_3_NOF_BITS, &fld_val); data_type_3 = fld_val; - hdr_size += sinfo->udh_length_type[data_type_3]; - hdr_size += BKN_DNX_UDH_BASE_SIZE; + pkt_offset += BKN_DNX_UDH_BASE_SIZE; + pkt_offset += sinfo->udh_length_type[data_type_0]; + pkt_offset += sinfo->udh_length_type[data_type_1]; + pkt_offset += sinfo->udh_length_type[data_type_2]; + pkt_offset += sinfo->udh_length_type[data_type_3]; + DBG_DUNE(("UDH base(1-%u) is present\n", pkt_offset)); } - /* - * Check if fhei_type if of type trap - * There is a RISK that raw packet data is parsed and fhei_type is 0x5 by chance - */ - if (packet_info->fhei_type == 0x5) + packet_info->system_header_size = pkt_offset; + + return 0; +} + +static int +bkn_dnx_packet_header_parse( + bkn_switch_info_t *sinfo, + uint8_t *buff, + uint32_t buff_len, + bkn_dune_system_header_info_t *packet_info) +{ + uint8_t is_inter_hdr_en = FALSE; + uint8_t is_tsh_en = FALSE; + uint8_t is_oamp_punted = FALSE; + uint8_t is_trapped = FALSE; + + if ((sinfo == NULL) || (buff == NULL) || (packet_info == NULL)) { + return -1; + } + + /* FTMH */ + bkn_dnx_packet_parse_ftmh(sinfo, buff, buff_len, packet_info, &is_tsh_en, &is_inter_hdr_en); + + /* Time-Stamp */ + if (is_tsh_en == TRUE) { - /* Done for ingress trapped packets */ - packet_info->system_header_size = hdr_size; - DBG_DUNE(("Total Size of Headers is %d\n", packet_info->system_header_size)); - return 0; + packet_info->system_header_size += BKN_DNX_TSH_SIZE; + DBG_DUNE(("Time-Stamp Header(4-%u) is present\n", packet_info->system_header_size)); } - else + + /* Check if packet was punted to CPU by OAMP */ + if ((packet_info->ftmh.source_sys_port_aggregate == 232) + || (packet_info->ftmh.source_sys_port_aggregate == 233)) { - /* New generated header will be FTMH(80b), TSH(32b), PPH(96b), FHEI(40b) */ + is_oamp_punted = TRUE; + } - /* Revert packet_info except info from FTHM base header */ - packet_info->fhei_qualifier = 0; - packet_info->fhei_code = 0; - packet_info->fhei_type = 0; - hdr_size = pkt_offset_ingress_untrapped; + /* Internal */ + if (is_inter_hdr_en) + { + bkn_dnx_packet_parse_internal(sinfo, buff, buff_len, packet_info, is_oamp_punted, &is_trapped); + } - /* Time-Stamp Header */ - hdr_size += BKN_DNX_TSH_SIZE; - DBG_DUNE(("Time-Stamp Header(4) is present\n")); + if (is_oamp_punted) + { + is_inter_hdr_en = FALSE; + is_tsh_en = FALSE; + is_oamp_punted = FALSE; + is_trapped = FALSE; + + /* FTMH */ + bkn_dnx_packet_parse_ftmh(sinfo, buff, buff_len, packet_info, &is_tsh_en, &is_inter_hdr_en); + /* Time-Stamp */ + if (is_tsh_en == TRUE) + { + packet_info->system_header_size += BKN_DNX_TSH_SIZE; + DBG_DUNE(("Time-Stamp Header(4-%u) is present\n", packet_info->system_header_size)); + } + /* Internal */ + if (is_inter_hdr_en) + { + bkn_dnx_packet_parse_internal(sinfo, buff, buff_len, packet_info, is_oamp_punted, &is_trapped); + } + } - /** Packet Processing Header */ - bkn_bitstream_get_field( - &buf[hdr_size], - BKN_DNX_PPH_12_FORWARD_DOMAIN_MSB, - BKN_DNX_PPH_12_FORWARD_DOMAIN_NOF_BITS, - &fld_val); - packet_info->pph_forward_domain = fld_val; - hdr_size += BKN_DNX_PPH_BASE_TYPE_12; - DBG_DUNE(("PPH(12) is present\n")); + DBG_DUNE(("Total length of headers is %u\n", packet_info->system_header_size)); - /* - * FHEI(Trap,40) - * 5B-FHEI format for sys_hdr_generation_profile:J2-OAM - * 8b' 0 - * 19b'oam_id - * 9b' cpu_trap_code: INGRESS_TRAP_ID is always 0 here - * 4b' type(0x5): J2-Configuration FHEI Type for CPU trap - */ - hdr_size += BKN_DNX_PPH_FHEI_SZ1_SIZE; - DBG_DUNE(("FHEI(5) is present\n")); + return 0; +} + +static int +bkn_packet_header_parse(bkn_switch_info_t *sinfo, uint8_t *buf, uint32_t buf_len, bkn_dune_system_header_info_t *packet_info) +{ + if (device_is_dpp(sinfo)) + { + bkn_dpp_packet_header_parse(sinfo, buf, buf_len, packet_info); + } + else if (device_is_dnx(sinfo)) + { + if (sinfo->system_headers_mode == BKN_DNX_JR2_MODE) + { + /* Jericho 2 mode */ + bkn_dnx_packet_header_parse(sinfo, buf, buf_len, packet_info); + } + else + { + /* Jericho/QMX/QAX mode */ + bkn_dpp_packet_header_parse(sinfo, buf, buf_len, packet_info); + } } - packet_info->system_header_size = hdr_size; - DBG_DUNE(("Total Size of Headers is %d\n", packet_info->system_header_size)); return 0; } - static int bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) { @@ -3492,8 +3501,8 @@ bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) int pktlen; int idx; int dcbs_done = 0; - bkn_dune_system_header_info_t packet_info = {0}; - uint32_t dnx_meta_data[3] = {0}; + bkn_dune_system_header_info_t packet_info; + uint32_t sand_scratch_data[BKN_SAND_SCRATCH_DATA_SIZE] = {0}; dcb_chain = sinfo->rx[chan].api_dcb_chain; if (dcb_chain == NULL) { @@ -3536,84 +3545,76 @@ bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) pkt_dma = dcb[0]; } pkt = (uint8_t *)kernel_bde->p2l(sinfo->dev_no, (sal_paddr_t)pkt_dma); - if (sinfo->cmic_type == 'x') { - if (device_is_dnx(sinfo)){ - meta = &dnx_meta_data[0]; - /* get error bit from last DCB words */ - err_woff = 2; - meta[err_woff] = dcb[sinfo->dcb_wsize-1]; - } else { + + if (device_is_sand(sinfo)) { + err_woff = BKN_SAND_SCRATCH_DATA_SIZE - 1; + sand_scratch_data[err_woff] = dcb[sinfo->dcb_wsize-1]; + meta = (uint32_t *)pkt; + } else { + if (sinfo->cmic_type == 'x') { meta = (uint32_t *)pkt; err_woff = sinfo->pkt_hdr_size / sizeof(uint32_t) - 1; meta[err_woff] = dcb[sinfo->dcb_wsize-1]; + } else { + meta = dcb; + err_woff = sinfo->dcb_wsize - 1; } - } else { - meta = dcb; - err_woff = sinfo->dcb_wsize - 1; } + pktlen = dcb[sinfo->dcb_wsize-1] & SOC_DCB_KNET_COUNT_MASK; bkn_dump_pkt(pkt, pktlen, XGS_DMA_RX_CHAN); - if (device_is_dpp(sinfo)) { - uint16_t tpid = 0; - uint16_t vid = 0; - int res = -1; - + if (device_is_sand(sinfo)) { memset(&packet_info, 0, sizeof(bkn_dune_system_header_info_t)); - res = bkn_dpp_packet_header_parse(sinfo, pkt, (uint32_t)pktlen, &packet_info); - if (res == 0) { - if (packet_info.ftmh.action_type == 0x2) { - bkn_bitstream_set_field((uint32_t *)dcb, 192, 32, 0x8); - } else if (packet_info.ftmh.action_type == 0x1) { - bkn_bitstream_set_field((uint32_t *)dcb, 231, 25, 0x20); - } - bkn_bitstream_set_field((uint32_t *)dcb, 112, 16, packet_info.ftmh.src_sys_port); - bkn_bitstream_set_field((uint32_t *)dcb, 296, 12, packet_info.internal.vsi); - bkn_bitstream_set_field((uint32_t *)dcb, 64, 32, (packet_info.internal.trap_id << 16 | packet_info.internal.trap_qualifier)); - pkt += packet_info.ntwrk_header_ptr; - pktlen -= packet_info.ntwrk_header_ptr; - bkn_dump_pkt(pkt, 32, XGS_DMA_RX_CHAN); - /* check if vlan tag exists */ - tpid = (uint16_t)((pkt[12] << 8) | pkt[13]); - vid = (uint16_t)(packet_info.internal.vsi & 0xfff); + /* decode system headers and fill sratch data */ + bkn_packet_header_parse(sinfo, pkt, (uint32_t)pktlen, &packet_info); + bkn_bitstream_set_field(sand_scratch_data, 0, 16, packet_info.internal.trap_id); + bkn_bitstream_set_field(sand_scratch_data, 16, 16, packet_info.internal.trap_qualifier); + bkn_bitstream_set_field(sand_scratch_data, 32, 16, packet_info.ftmh.source_sys_port_aggregate); + bkn_bitstream_set_field(sand_scratch_data, 48, 16, packet_info.internal.forward_domain); + bkn_bitstream_set_field(sand_scratch_data, 64, 2, packet_info.ftmh.action_type); + + if (force_tagged) { + uint8_t *eth_hdr = pkt + packet_info.system_header_size; + uint16_t tpid = 0; + + tpid = PKT_U16_GET(eth_hdr, 12); if (packet_is_untagged(tpid)) { + int raw_packet_len = pktlen - packet_info.system_header_size; + uint32_t vid = 0; + if ((pktlen + 4) < rx_buffer_size) { - DBG_DUNE(("add vlan tag (%d) to untagged packets\n", vid)); - for (idx = (pktlen-1); idx >= 12; idx--) { - pkt[idx+4] = pkt[idx]; + for (idx = (raw_packet_len - 1); idx >= 12; idx--) { + eth_hdr[idx+4] = eth_hdr[idx]; + } + if (ft_vid) { + vid = ft_vid; + } + else if (packet_info.internal.forward_domain) { + vid = packet_info.internal.forward_domain & 0xfff; + } + else { + vid = 1; } - pkt[12] = 0x81; - pkt[13] = 0x00; - pkt[14] = (vid >> 8); - pkt[15] = (vid & 0xff); + DBG_DUNE(("add vlan tag (%d) to untagged packets\n", vid)); + + eth_hdr[12] = (ft_tpid >> 8) & 0xff; + eth_hdr[13] = ft_tpid & 0xff; + eth_hdr[14] = (((ft_pri & 0x7) << 5) | ((ft_cfi & 0x1) << 4) | ((vid >> 8) & 0xf)) & 0xff; + eth_hdr[15] = vid & 0xff; /* reset packet length in DCB */ pktlen += 4; + bkn_dump_pkt(pkt, pktlen, XGS_DMA_RX_CHAN); dcb[sinfo->dcb_wsize-1] &= ~SOC_DCB_KNET_COUNT_MASK; - dcb[sinfo->dcb_wsize-1] |= ((pktlen + packet_info.ntwrk_header_ptr) & SOC_DCB_KNET_COUNT_MASK); - bkn_dump_pkt(pkt, 32, XGS_DMA_RX_CHAN); + dcb[sinfo->dcb_wsize-1] |= pktlen & SOC_DCB_KNET_COUNT_MASK; } } } } - else if (device_is_dnx(sinfo)) { - int res = -1; - res = bkn_dnx_packet_header_parse(sinfo, pkt, (uint32_t)pktlen, &packet_info); - if (res == 0) { - bkn_bitstream_set_field(meta, 0, 16, packet_info.fhei_code); - bkn_bitstream_set_field(meta, 16, 16, packet_info.fhei_qualifier); - bkn_bitstream_set_field(meta, 32, 16, packet_info.ftmh_spa); - bkn_bitstream_set_field(meta, 48, 16, (packet_info.pph_forward_domain & 0xffff)); - - pkt += packet_info.system_header_size; - pktlen -= packet_info.system_header_size; - bkn_dump_pkt(pkt, 32, XGS_DMA_RX_CHAN); - } - } - if (device_is_dpp(sinfo)) { - filter = bkn_match_rx_pkt(sinfo, pkt, pktlen, dcb, chan, &cbf); - } else if (device_is_dnx(sinfo)) { - filter = bkn_match_rx_pkt(sinfo, pkt, pktlen, meta, chan, &cbf); + if (device_is_sand(sinfo)) { + filter = bkn_match_rx_pkt(sinfo, pkt + packet_info.system_header_size, + pktlen - packet_info.system_header_size, sand_scratch_data, chan, &cbf); } else { filter = bkn_match_rx_pkt(sinfo, pkt + sinfo->pkt_hdr_size, pktlen - sinfo->pkt_hdr_size, meta, chan, &cbf); @@ -3643,7 +3644,10 @@ bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) break; } - if (sinfo->cmic_type == 'x') { + if (device_is_sand(sinfo)) { + pkt += packet_info.system_header_size; + pktlen -= packet_info.system_header_size; + } else if (sinfo->cmic_type == 'x') { pkt += sinfo->pkt_hdr_size; pktlen -= sinfo->pkt_hdr_size; } @@ -3663,12 +3667,14 @@ bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) skb_reserve(skb, 2); /* 16 byte align the IP fields. */ /* Save for RCPU before stripping tag */ - ethertype = (pkt[16] << 8) | pkt[17]; + ethertype = PKT_U16_GET(pkt, 16); if ((priv->flags & KCOM_NETIF_F_KEEP_RX_TAG) == 0) { + uint16_t vlan_proto = PKT_U16_GET(pkt, 12); + if (filter->kf.flags & KCOM_FILTER_F_STRIP_TAG) { /* Strip the VLAN tag */ - uint16_t vlan_proto = (uint16_t)((pkt[12] << 8) | pkt[13]); - if (vlan_proto == 0x8100 || vlan_proto == 0x88a8) { + if (vlan_proto == ETH_P_8021Q || + vlan_proto == ETH_P_8021AD) { DBG_FLTR(("Strip VLAN tag\n")); for (idx = 11; idx >= 0; idx--) { pkt[idx+4] = pkt[idx]; @@ -3681,12 +3687,18 @@ bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) * Mark packet as VLAN-tagged, otherwise newer * kernels will strip the tag. */ - uint16_t tci = (pkt[14] << 8) | pkt[15]; + uint16_t tci = PKT_U16_GET(pkt, 14); + if (priv->flags & KCOM_NETIF_F_RCPU_ENCAP) { bkn_vlan_hwaccel_put_tag(skb, ETH_P_8021Q, tci); } else { - bkn_vlan_hwaccel_put_tag(skb, - ((skb->data[12] << 8) | skb->data[13]), tci); + if (vlan_proto == ETH_P_8021AD) { + bkn_vlan_hwaccel_put_tag + (skb, ETH_P_8021AD, tci); + } else { + bkn_vlan_hwaccel_put_tag + (skb, ETH_P_8021Q, tci); + } } } } @@ -3702,11 +3714,16 @@ bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) priv->stats.rx_bytes += skb->len; /* Optional SKB updates */ + KNET_SKB_CB(skb)->dcb_type = sinfo->dcb_type & 0xFFFF; if (knet_rx_cb != NULL) { KNET_SKB_CB(skb)->netif_user_data = priv->cb_user_data; KNET_SKB_CB(skb)->filter_user_data = filter->kf.cb_user_data; - KNET_SKB_CB(skb)->dcb_type = sinfo->dcb_type & 0xFFFF; - skb = knet_rx_cb(skb, sinfo->dev_no, meta); + if (device_is_sand(sinfo)) { + skb = knet_rx_cb(skb, sinfo->dev_no, sand_scratch_data); + } + else { + skb = knet_rx_cb(skb, sinfo->dev_no, meta); + } if (skb == NULL) { /* Consumed by call-back */ sinfo->rx[chan].pkts_d_callback++; @@ -3715,12 +3732,12 @@ bkn_do_api_rx(bkn_switch_info_t *sinfo, int chan, int budget) } /* Do Rx timestamping */ - if (sinfo->rx_hwts) { - bkn_hw_tstamp_rx_set(sinfo, skb, meta); + if (priv->rx_hwts) { + bkn_hw_tstamp_rx_set(sinfo, priv->phys_port, skb, meta); } if (priv->flags & KCOM_NETIF_F_RCPU_ENCAP) { - bkn_add_rcpu_encap(sinfo, skb, meta); + bkn_add_rcpu_encap(sinfo, skb, meta, packet_info.system_header_size); DBG_PDMP(("After add RCPU ENCAP\n")); bkn_dump_pkt(skb->data, pktlen + RCPU_RX_ENCAP_SIZE, XGS_DMA_RX_CHAN); } @@ -3792,7 +3809,9 @@ bkn_do_skb_rx(bkn_switch_info_t *sinfo, int chan, int budget) int idx; int dcbs_done = 0; bkn_dune_system_header_info_t packet_info = {0}; - uint32_t dnx_meta_data[3] = {0}; + uint32_t sand_scratch_data[BKN_SAND_SCRATCH_DATA_SIZE] = {0}; + uint8_t sand_system_headers[RCPU_RX_META_SIZE] = {0}; + uint8_t *pkt = NULL; if (!sinfo->rx[chan].running) { /* Rx not ready */ @@ -3818,93 +3837,83 @@ bkn_do_skb_rx(bkn_switch_info_t *sinfo, int chan, int budget) } sinfo->rx[chan].pkts++; skb = desc->skb; - if (sinfo->cmic_type == 'x') { - if (device_is_dnx(sinfo)){ - meta = &dnx_meta_data[0]; - /* get error bit from last DCB words */ - err_woff = 2; - meta[err_woff] = dcb[sinfo->dcb_wsize-1]; - } else { + + if (device_is_sand(sinfo)) { + err_woff = BKN_SAND_SCRATCH_DATA_SIZE - 1; + sand_scratch_data[err_woff] = dcb[sinfo->dcb_wsize-1]; + meta = (uint32_t *)skb->data; + pkt = skb->data; + } else { + if (sinfo->cmic_type == 'x') { meta = (uint32_t *)skb->data; err_woff = sinfo->pkt_hdr_size / sizeof(uint32_t) - 1; meta[err_woff] = dcb[sinfo->dcb_wsize-1]; + } else { + meta = dcb; + err_woff = sinfo->dcb_wsize - 1; } - } else { - meta = dcb; - err_woff = sinfo->dcb_wsize - 1; } + pktlen = dcb[sinfo->dcb_wsize-1] & 0xffff; priv = netdev_priv(sinfo->dev); DBG_DCB_RX(("Rx%d SKB DMA done (%d).\n", chan, sinfo->rx[chan].dirty)); - DMA_UNMAP_SINGLE(sinfo->dma_dev, + BKN_DMA_UNMAP_SINGLE(sinfo->dma_dev, desc->skb_dma, desc->dma_size, - DMA_FROMDEV); + BKN_DMA_FROMDEV); desc->skb_dma = 0; bkn_dump_pkt(skb->data, pktlen, XGS_DMA_RX_CHAN); - if (device_is_dpp(sinfo)) { - uint16_t tpid = 0; - uint16_t vid = 0; - uint8_t *pkt = skb->data; - int res = 0; - + if (device_is_sand(sinfo)) { memset(&packet_info, 0, sizeof(bkn_dune_system_header_info_t)); - res = bkn_dpp_packet_header_parse(sinfo, pkt, (uint32_t)pktlen, &packet_info); - if (res == 0) { - if (packet_info.ftmh.action_type == 0x2) { - bkn_bitstream_set_field((uint32_t *)dcb, 192, 32, 0x8); - } else if (packet_info.ftmh.action_type == 0x1) { - bkn_bitstream_set_field((uint32_t *)dcb, 231, 25, 0x20); - } - bkn_bitstream_set_field((uint32_t *)dcb, 112, 16, packet_info.ftmh.src_sys_port); - bkn_bitstream_set_field((uint32_t *)dcb, 296, 12, packet_info.internal.vsi); - bkn_bitstream_set_field((uint32_t *)dcb, 64, 32, (packet_info.internal.trap_id << 16 | packet_info.internal.trap_qualifier)); - pkt = skb->data + packet_info.ntwrk_header_ptr; - /* check if vlan tag exists */ - tpid = (uint16_t)((pkt[12] << 8) | pkt[13]); - vid = (uint16_t)(packet_info.internal.vsi & 0xfff); + /* decode system headers and fill sratch data */ + bkn_packet_header_parse(sinfo, pkt, (uint32_t)pktlen, &packet_info); + bkn_bitstream_set_field(sand_scratch_data, 0, 16, packet_info.internal.trap_id); + bkn_bitstream_set_field(sand_scratch_data, 16, 16, packet_info.internal.trap_qualifier); + bkn_bitstream_set_field(sand_scratch_data, 32, 16, packet_info.ftmh.source_sys_port_aggregate); + bkn_bitstream_set_field(sand_scratch_data, 48, 16, packet_info.internal.forward_domain); + bkn_bitstream_set_field(sand_scratch_data, 64, 2, packet_info.ftmh.action_type); + memcpy(sand_system_headers, pkt, + ((packet_info.system_header_size > RCPU_RX_META_SIZE) ? RCPU_RX_META_SIZE : packet_info.system_header_size)); + meta = (uint32_t *)sand_system_headers; + if (force_tagged) { + uint8_t *eth_hdr = pkt + packet_info.system_header_size; + uint16_t tpid = 0; + + tpid = PKT_U16_GET(eth_hdr, 12); if (packet_is_untagged(tpid)) { + int raw_packet_len = pktlen - packet_info.system_header_size; + uint32_t vid = 0; + if ((pktlen + 4) < rx_buffer_size) { - DBG_DUNE(("add vlan tag to untagged packets\n")); - for (idx = (pktlen-packet_info.ntwrk_header_ptr-1); idx >= 12; idx--) { - pkt[idx+4] = pkt[idx]; - } - pkt[12] = 0x81; - pkt[13] = 0x00; - pkt[14] = (vid >> 8); - pkt[15] = (vid & 0xff); - pktlen += 4; - /* reset packet length in DCB */ - dcb[sinfo->dcb_wsize-1] &= ~SOC_DCB_KNET_COUNT_MASK; - dcb[sinfo->dcb_wsize-1] |= (pktlen & SOC_DCB_KNET_COUNT_MASK); - bkn_dump_pkt(pkt, 32, XGS_DMA_RX_CHAN); + for (idx = (raw_packet_len - 1); idx >= 12; idx--) { + eth_hdr[idx+4] = eth_hdr[idx]; + } + if (ft_vid) { + vid = ft_vid; + } + else if (packet_info.internal.forward_domain) { + vid = packet_info.internal.forward_domain & 0xfff; + } + else { + vid = 1; + } + DBG_DUNE(("add vlan tag (%d) to untagged packets\n", vid)); + eth_hdr[12] = (ft_tpid >> 8) & 0xff; + eth_hdr[13] = ft_tpid & 0xff; + eth_hdr[14] = (((ft_pri & 0x7) << 5) | ((ft_cfi & 0x1) << 4) | ((vid >> 8) & 0xf)) & 0xff; + eth_hdr[15] = vid & 0xff; + /* reset packet length in DCB */ + pktlen += 4; + bkn_dump_pkt(pkt, pktlen, XGS_DMA_RX_CHAN); + dcb[sinfo->dcb_wsize-1] &= ~SOC_DCB_KNET_COUNT_MASK; + dcb[sinfo->dcb_wsize-1] |= pktlen & SOC_DCB_KNET_COUNT_MASK; } } } } - else if (device_is_dnx(sinfo)) { - uint8_t *pkt = skb->data; - int res = -1; - - res = bkn_dnx_packet_header_parse(sinfo, pkt, (uint32_t)pktlen, &packet_info); - if (res == 0) { - bkn_bitstream_set_field(meta, 0, 16, packet_info.fhei_code); - bkn_bitstream_set_field(meta, 16, 16, packet_info.fhei_qualifier); - bkn_bitstream_set_field(meta, 32, 16, packet_info.ftmh_spa); - bkn_bitstream_set_field(meta, 48, 16, (packet_info.pph_forward_domain & 0xffff)); - - pkt += packet_info.system_header_size; - pktlen -= packet_info.ntwrk_header_ptr; - bkn_dump_pkt(pkt, 32, XGS_DMA_RX_CHAN); - } - } - - if (device_is_dpp(sinfo)) { - filter = bkn_match_rx_pkt(sinfo, skb->data + packet_info.ntwrk_header_ptr, - pktlen, dcb, chan, &cbf); - } else if (device_is_dnx(sinfo)) { + if (device_is_sand(sinfo)) { filter = bkn_match_rx_pkt(sinfo, skb->data + packet_info.system_header_size, - pktlen, meta, chan, &cbf); + pktlen - packet_info.system_header_size, sand_scratch_data, chan, &cbf); } else { filter = bkn_match_rx_pkt(sinfo, skb->data + sinfo->pkt_hdr_size, pktlen - sinfo->pkt_hdr_size, meta, chan, &cbf); @@ -3938,55 +3947,51 @@ bkn_do_skb_rx(bkn_switch_info_t *sinfo, int chan, int budget) priv->id, priv->dev->name)); sinfo->rx[chan].pkts_f_netif++; - if (((filter->kf.mirror_type == KCOM_DEST_T_API) && - (!device_is_sand(sinfo))) || dbg_pkt_enable) { + if ((filter->kf.mirror_type == KCOM_DEST_T_API) || dbg_pkt_enable) { sinfo->rx[chan].pkts_m_api++; bkn_api_rx_copy_from_skb(sinfo, chan, desc); } - if (device_is_dpp(sinfo)) { - if (filter->kf.mirror_type == KCOM_DEST_T_API) { - sinfo->rx[chan].pkts_m_api++; - bkn_api_rx_copy_from_skb(sinfo, chan, desc); - } - /* Strip Dune headers */ - skb->data += packet_info.ntwrk_header_ptr; - pktlen -= packet_info.ntwrk_header_ptr; - bkn_dump_pkt(skb->data, 32, XGS_DMA_RX_CHAN); - /* CRC has been stripped on Dune*/ - skb_put(skb, pktlen); - } else if (device_is_dnx(sinfo)) { - if (filter->kf.mirror_type == KCOM_DEST_T_API) { - sinfo->rx[chan].pkts_m_api++; - bkn_api_rx_copy_from_skb(sinfo, chan, desc); - } - /* Strip Dune headers */ - skb->data += packet_info.system_header_size; - pktlen -= packet_info.system_header_size; - bkn_dump_pkt(skb->data, 32, XGS_DMA_RX_CHAN); + if (device_is_sand(sinfo)) { /* CRC has been stripped on Dune*/ skb_put(skb, pktlen); } else { skb_put(skb, pktlen - 4); /* Strip CRC */ } - if (sinfo->cmic_type == 'x' && !device_is_dnx(sinfo)) { + if (device_is_sand(sinfo)) { + skb_pull(skb, packet_info.system_header_size); + } else if (sinfo->cmic_type == 'x') { skb_pull(skb, sinfo->pkt_hdr_size); } + /* Optional SKB updates */ + KNET_SKB_CB(skb)->dcb_type = sinfo->dcb_type & 0xFFFF; + /* Do Rx timestamping */ + if (priv->rx_hwts) { + bkn_hw_tstamp_rx_set(sinfo, priv->phys_port, skb, meta); + } + /* Save for RCPU before stripping tag */ - ethertype = (skb->data[16] << 8) | skb->data[17]; + ethertype = PKT_U16_GET(skb->data, 16); if ((priv->flags & KCOM_NETIF_F_KEEP_RX_TAG) == 0) { + uint16_t vlan_proto; + + vlan_proto = PKT_U16_GET(skb->data, 12); if (filter->kf.flags & KCOM_FILTER_F_STRIP_TAG) { /* Strip VLAN tag */ - uint16_t vlan_proto = (uint16_t)((skb->data[12] << 8) | skb->data[13]); - if (vlan_proto == 0x8100 || vlan_proto == 0x88a8) { + if (vlan_proto == ETH_P_8021Q || + vlan_proto == ETH_P_8021AD) { DBG_FLTR(("Strip VLAN tag\n")); ((u32*)skb->data)[3] = ((u32*)skb->data)[2]; ((u32*)skb->data)[2] = ((u32*)skb->data)[1]; ((u32*)skb->data)[1] = ((u32*)skb->data)[0]; skb_pull(skb, 4); - if (sinfo->cmic_type == 'x' && !device_is_dnx(sinfo)) { + if (device_is_sand(sinfo)) { + for (idx = packet_info.system_header_size; idx >= 4; idx--) { + pkt[idx] = pkt[idx - 4]; + } + } else if (sinfo->cmic_type == 'x') { for (idx = sinfo->pkt_hdr_size / sizeof(uint32_t); idx; idx--) { meta[idx] = meta[idx - 1]; } @@ -3998,25 +4003,35 @@ bkn_do_skb_rx(bkn_switch_info_t *sinfo, int chan, int budget) * Mark packet as VLAN-tagged, otherwise newer * kernels will strip the tag. */ - uint16_t tci = (skb->data[14] << 8) | skb->data[15]; + uint16_t tci = PKT_U16_GET(skb->data, 14); + if (priv->flags & KCOM_NETIF_F_RCPU_ENCAP) { bkn_vlan_hwaccel_put_tag(skb, ETH_P_8021Q, tci); } else { - bkn_vlan_hwaccel_put_tag(skb, - ((skb->data[12] << 8) | skb->data[13]), tci); + if (vlan_proto == ETH_P_8021AD) { + bkn_vlan_hwaccel_put_tag + (skb, ETH_P_8021AD, tci); + } else { + bkn_vlan_hwaccel_put_tag + (skb, ETH_P_8021Q, tci); + } } } } + priv->stats.rx_packets++; priv->stats.rx_bytes += skb->len; skb->dev = priv->dev; - /* Optional SKB updates */ if (knet_rx_cb != NULL) { KNET_SKB_CB(skb)->netif_user_data = priv->cb_user_data; KNET_SKB_CB(skb)->filter_user_data = filter->kf.cb_user_data; - KNET_SKB_CB(skb)->dcb_type = sinfo->dcb_type & 0xFFFF; - skb = knet_rx_cb(skb, sinfo->dev_no, meta); + if (device_is_sand(sinfo)) { + skb = knet_rx_cb(skb, sinfo->dev_no, sand_scratch_data); + } + else { + skb = knet_rx_cb(skb, sinfo->dev_no, meta); + } if (skb == NULL) { /* Consumed by call-back */ sinfo->rx[chan].pkts_d_callback++; @@ -4026,13 +4041,8 @@ bkn_do_skb_rx(bkn_switch_info_t *sinfo, int chan, int budget) } } - /* Do Rx timestamping */ - if (sinfo->rx_hwts) { - bkn_hw_tstamp_rx_set(sinfo, skb, meta); - } - if (priv->flags & KCOM_NETIF_F_RCPU_ENCAP) { - bkn_add_rcpu_encap(sinfo, skb, meta); + bkn_add_rcpu_encap(sinfo, skb, meta, packet_info.system_header_size); DBG_PDMP(("After add RCPU ENCAP\n")); bkn_dump_pkt(skb->data, pktlen + RCPU_RX_ENCAP_SIZE, XGS_DMA_RX_CHAN); } @@ -4228,25 +4238,45 @@ bkn_resume_tx(bkn_switch_info_t *sinfo) } } +static void +bkn_skb_tstamp_copy(struct sk_buff *new_skb, struct sk_buff *skb) +{ + bkn_skb_tx_flags(new_skb) = bkn_skb_tx_flags(skb); + new_skb->sk = skb->sk; + + return; +} + static int bkn_hw_tstamp_tx_set(bkn_switch_info_t *sinfo, struct sk_buff *skb) { - struct skb_shared_hwtstamps shhwtstamps; + int hwts; + int port; uint64_t ts = 0; uint32_t hdrlen = sinfo->cmic_type == 'x' ? PKT_TX_HDR_SIZE : 0; - int port; + struct skb_shared_hwtstamps shhwtstamps; if (!knet_hw_tstamp_tx_time_get_cb) { return -1; } port = KNET_SKB_CB(skb)->port; - if (knet_hw_tstamp_tx_time_get_cb(sinfo->dev_no, port, skb->data + hdrlen, &ts) < 0) { - return -1; + hwts = KNET_SKB_CB(skb)->hwts; + ts = KNET_SKB_CB(skb)->ts; + + + if (hwts == HWTSTAMP_TX_ONESTEP_SYNC) { + if (ts == 0) { + return 1; + } + } else if (hwts == HWTSTAMP_TX_ON) { + if (knet_hw_tstamp_tx_time_get_cb(sinfo->dev_no, port, skb->data + hdrlen, &ts) < 0) { + return -1; + } } memset(&shhwtstamps, 0, sizeof(shhwtstamps)); - shhwtstamps.hwtstamp = ns_to_ktime(be64_to_cpu(ts)); + shhwtstamps.hwtstamp = ns_to_ktime(ts); skb_tstamp_tx(skb, &shhwtstamps); return 0; @@ -4290,9 +4320,19 @@ bkn_do_tx(bkn_switch_info_t *sinfo) } if (desc->skb) { DBG_DCB_TX(("Tx SKB DMA done (%d).\n", sinfo->tx.dirty)); - DMA_UNMAP_SINGLE(sinfo->dma_dev, + BKN_DMA_UNMAP_SINGLE(sinfo->dma_dev, desc->skb_dma, desc->dma_size, - DMA_TODEV); + BKN_DMA_TODEV); + + if ((KNET_SKB_CB(desc->skb)->hwts == HWTSTAMP_TX_ONESTEP_SYNC) && + (bkn_skb_tx_flags(desc->skb) & SKBTX_IN_PROGRESS)) { + + if (bkn_hw_tstamp_tx_set(sinfo, desc->skb) < 0) { + gprintk("Timestamp has not been taken for the current skb.\n"); + } + bkn_skb_tx_flags(desc->skb) &= ~SKBTX_IN_PROGRESS; + } + if (bkn_skb_tx_flags(desc->skb) & SKBTX_IN_PROGRESS) { skb_queue_tail(&sinfo->tx_ptp_queue, desc->skb); schedule_work(&sinfo->tx_ptp_work); @@ -4858,6 +4898,22 @@ xgsx_isr(bkn_switch_info_t *sinfo) /* Not ours */ return; } + + /* Bypass chain_done from Abort */ + if (device_is_dnx(sinfo)) { + uint32_t ctrl = 0; + int chan = 0; + for (chan = 0; chan < NUM_DMA_CHAN; chan++) { + if (irq_stat & CMICX_DS_CMC_CHAIN_DONE(chan)) { + DEV_READ32(sinfo, CMICX_DMA_CTRLr + 0x80 * chan, &ctrl); + if (ctrl & CMICX_DC_CMC_ABORT) { + DBG_IRQ(("chain %d: chain done for Abort\n", chan)); + return; + } + } + } + } + sinfo->interrupts++; DBG_IRQ(("Got interrupt on device %d (0x%08x)\n", @@ -5010,7 +5066,11 @@ bkn_open(struct net_device *dev) static int bkn_set_mac_address(struct net_device *dev, void *addr) { +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,12)) + if (!is_valid_ether_addr((const u8*)(((struct sockaddr *)addr)->sa_data))) { +#else if (!is_valid_ether_addr(((struct sockaddr *)addr)->sa_data)) { +#endif return -EINVAL; } memcpy(dev->dev_addr, ((struct sockaddr *)addr)->sa_data, dev->addr_len); @@ -5033,17 +5093,21 @@ bkn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) if (!knet_hw_tstamp_enable_cb || !knet_hw_tstamp_disable_cb || priv->type != KCOM_NETIF_T_PORT) { - return -ERANGE; + return -ENOSYS; } switch (config.tx_type) { case HWTSTAMP_TX_OFF: - knet_hw_tstamp_disable_cb(sinfo->dev_no, priv->port); - sinfo->tx_hwts = 0; + knet_hw_tstamp_disable_cb(sinfo->dev_no, priv->phys_port, config.tx_type); + priv->tx_hwts = (config.tx_type); break; case HWTSTAMP_TX_ON: - knet_hw_tstamp_enable_cb(sinfo->dev_no, priv->port); - sinfo->tx_hwts = 1; + knet_hw_tstamp_enable_cb(sinfo->dev_no, priv->phys_port, config.tx_type); + priv->tx_hwts = (config.tx_type); + break; + case HWTSTAMP_TX_ONESTEP_SYNC: + knet_hw_tstamp_enable_cb(sinfo->dev_no, priv->phys_port, config.tx_type); + priv->tx_hwts = (config.tx_type); break; default: return -ERANGE; @@ -5051,15 +5115,15 @@ bkn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) switch (config.rx_filter) { case HWTSTAMP_FILTER_NONE: - if (sinfo->rx_hwts) { - knet_hw_tstamp_disable_cb(sinfo->dev_no, priv->port); - sinfo->rx_hwts = 0; + if (priv->rx_hwts) { + knet_hw_tstamp_disable_cb(sinfo->dev_no, priv->phys_port, config.tx_type); + priv->rx_hwts = 0; } break; default: - if (!sinfo->rx_hwts) { - knet_hw_tstamp_enable_cb(sinfo->dev_no, priv->port); - sinfo->rx_hwts = 1; + if (!priv->rx_hwts) { + knet_hw_tstamp_enable_cb(sinfo->dev_no, priv->phys_port, config.tx_type); + priv->rx_hwts = 1; } config.rx_filter = HWTSTAMP_FILTER_ALL; break; @@ -5071,8 +5135,8 @@ bkn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)) if (cmd == SIOCGHWTSTAMP) { config.flags = 0; - config.tx_type = sinfo->tx_hwts ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; - config.rx_filter = sinfo->rx_hwts ? HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE; + config.tx_type = priv->tx_hwts; + config.rx_filter = priv->rx_hwts ? HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE; return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ? -EFAULT : 0; } @@ -5208,7 +5272,9 @@ bkn_set_multicast_list(struct net_device *dev) } static int -bkn_hw_tstamp_tx_config(bkn_switch_info_t *sinfo, struct sk_buff *skb, uint32_t *meta) +bkn_hw_tstamp_tx_config(bkn_switch_info_t *sinfo, + int hwts, int hdrlen, + struct sk_buff *skb, u32 *meta) { uint32_t *md = NULL; @@ -5217,7 +5283,13 @@ bkn_hw_tstamp_tx_config(bkn_switch_info_t *sinfo, struct sk_buff *skb, uint32_t } KNET_SKB_CB(skb)->dcb_type = sinfo->dcb_type & 0xFFFF; - knet_hw_tstamp_tx_meta_get_cb(sinfo->dev_no, skb, &md); + knet_hw_tstamp_tx_meta_get_cb(sinfo->dev_no, hwts, hdrlen, skb, + &(KNET_SKB_CB(skb)->ts), (meta ? &md : NULL)); + + if (!meta) { + return 0; + } + if (!md) { return -1; } @@ -5233,10 +5305,10 @@ bkn_hw_tstamp_tx_config(bkn_switch_info_t *sinfo, struct sk_buff *skb, uint32_t break; case 36: case 38: - meta[0] |= md[0]; - meta[1] |= md[1]; - meta[2] |= md[2]; - meta[3] |= md[3]; + meta[0] |= htonl(md[0]); + meta[1] |= htonl(md[1]); + meta[2] |= htonl(md[2]); + meta[3] |= htonl(md[3]); break; default: return -1; @@ -5257,8 +5329,9 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) uint16_t tpid; uint32_t *metadata; unsigned long flags; + uint32_t cpu_channel = 0; - DBG_VERB(("Netif Tx: Len=%d\n", skb->len)); + DBG_VERB(("Netif Tx: Len=%d priv->id=%d\n", skb->len, priv->id)); if (priv->id <= 0) { /* Do not transmit on base device */ @@ -5267,8 +5340,14 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) return 0; } + if (device_is_dnx(sinfo) && (skb->len == 0)) { + priv->stats.tx_dropped++; + dev_kfree_skb_any(skb); + return 0; + } + if (!netif_carrier_ok(dev)) { - DBG_WARN(("Tx drop: Invalid RCPU encapsulation\n")); + DBG_WARN(("Tx drop: Netif link is down.\n")); priv->stats.tx_dropped++; sinfo->tx.pkts_d_no_link++; dev_kfree_skb_any(skb); @@ -5283,7 +5362,13 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) pktdata = skb->data; pktlen = skb->len; - hdrlen = (sinfo->cmic_type == 'x' ) ? ((device_is_dnx(sinfo)) ? priv->system_headers_size: PKT_TX_HDR_SIZE) : 0; + + if (device_is_sand(sinfo)) { + hdrlen = priv->system_headers_size; + } + else { + hdrlen = (sinfo->cmic_type == 'x' ) ? PKT_TX_HDR_SIZE : 0; + } rcpulen = 0; sop = 0; @@ -5298,7 +5383,7 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) return 0; } if (check_rcpu_signature && - ((skb->data[18] << 8) | skb->data[19]) != sinfo->rcpu_sig) { + PKT_U16_GET(skb->data, 18) != sinfo->rcpu_sig) { DBG_WARN(("Tx drop: Invalid RCPU signature\n")); priv->stats.tx_dropped++; sinfo->tx.pkts_d_rcpu_sig++; @@ -5306,7 +5391,15 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) spin_unlock_irqrestore(&sinfo->lock, flags); return 0; } - if (skb->data[21] & RCPU_F_MODHDR) { + + if (device_is_sand(sinfo)) { + /* Dune devices don't use meta data */ + sop = 0; + /* Get CPU channel from rcpu_hdr_t.reserved */ + cpu_channel = (skb->data[28] << 24) | (skb->data[29] << 16) | (skb->data[30] << 8) | (skb->data[31]); + /* System headers are supposed to be set by users in RCPU mode. */ + hdrlen = 0; + } else if (skb->data[21] & RCPU_F_MODHDR) { sop = skb->data[RCPU_HDR_SIZE]; switch (sop) { case 0xff: @@ -5332,46 +5425,55 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) /* CPU packets require tag */ if (sop == 0) { - hdrlen = 0; - tpid = (pktdata[12] << 8) | pktdata[13]; - if (tpid != 0x8100) { - if (skb_header_cloned(skb)) { - /* Current SKB cannot be modified */ - DBG_SKB(("Realloc Tx SKB\n")); - new_skb = dev_alloc_skb(pktlen + TAG_SZ + FCS_SZ); - if (new_skb == NULL) { - DBG_WARN(("Tx drop: No SKB memory\n")); - priv->stats.tx_dropped++; - sinfo->tx.pkts_d_no_skb++; + if (device_is_sand(sinfo)) { + /* + * There should be Module Header + PTCH_2 + [ITMH] on JR2, + * PTCH_2 +[ITMH] on JR1 + */ + } else { + hdrlen = 0; + tpid = PKT_U16_GET(pktdata, 12); + if (tpid != 0x8100) { + if (skb_header_cloned(skb)) { + /* Current SKB cannot be modified */ + DBG_SKB(("Realloc Tx SKB\n")); + new_skb = dev_alloc_skb(pktlen + TAG_SZ + FCS_SZ); + if (new_skb == NULL) { + DBG_WARN(("Tx drop: No SKB memory\n")); + priv->stats.tx_dropped++; + sinfo->tx.pkts_d_no_skb++; + dev_kfree_skb_any(skb); + spin_unlock_irqrestore(&sinfo->lock, flags); + return 0; + } + memcpy(new_skb->data, pktdata, 12); + memcpy(&new_skb->data[16], &pktdata[12], pktlen - 12); + skb_put(new_skb, pktlen + TAG_SZ); + bkn_skb_tstamp_copy(new_skb, skb); dev_kfree_skb_any(skb); - spin_unlock_irqrestore(&sinfo->lock, flags); - return 0; - } - memcpy(new_skb->data, pktdata, 12); - memcpy(&new_skb->data[16], &pktdata[12], pktlen - 12); - skb_put(new_skb, pktlen + TAG_SZ); - dev_kfree_skb_any(skb); - skb = new_skb; - pktdata = skb->data; - rcpulen = 0; - } else { - /* Add tag to RCPU header space */ - DBG_SKB(("Expand into unused RCPU header\n")); - rcpulen -= TAG_SZ; - pktdata = &skb->data[rcpulen]; - for (idx = 0; idx < 12; idx++) { - pktdata[idx] = pktdata[idx + TAG_SZ]; + skb = new_skb; + pktdata = skb->data; + rcpulen = 0; + } else { + /* Add tag to RCPU header space */ + DBG_SKB(("Expand into unused RCPU header\n")); + rcpulen -= TAG_SZ; + pktdata = &skb->data[rcpulen]; + for (idx = 0; idx < 12; idx++) { + pktdata[idx] = pktdata[idx + TAG_SZ]; + } } + pktdata[12] = 0x81; + pktdata[13] = 0x00; + pktdata[14] = (priv->vlan >> 8) & 0xf; + pktdata[15] = priv->vlan & 0xff; + pktlen += TAG_SZ; } - pktdata[12] = 0x81; - pktdata[13] = 0x00; - pktdata[14] = (priv->vlan >> 8) & 0xf; - pktdata[15] = priv->vlan & 0xff; - pktlen += TAG_SZ; } } } else { - if (sinfo->cmic_type == 'x' && priv->port >= 0) { + if (((sinfo->cmic_type == 'x') && (priv->port >= 0)) + || device_is_sand(sinfo)) { if (skb_header_cloned(skb) || skb_headroom(skb) < hdrlen + 4) { /* Current SKB cannot be modified */ DBG_SKB(("Realloc Tx SKB\n")); @@ -5384,12 +5486,13 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) spin_unlock_irqrestore(&sinfo->lock, flags); return 0; } - if (!device_is_dnx(sinfo)) + if (!device_is_sand(sinfo)) { skb_reserve(new_skb, 4); } memcpy(new_skb->data + hdrlen, skb->data, pktlen); skb_put(new_skb, pktlen + hdrlen); + bkn_skb_tstamp_copy(new_skb, skb); dev_kfree_skb_any(skb); skb = new_skb; } else { @@ -5406,7 +5509,7 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) if (priv->port < 0 || (priv->flags & KCOM_NETIF_F_ADD_TAG)) { DBG_DUNE(("ADD VLAN TAG\n")); /* Need to add VLAN tag if packet is untagged */ - tpid = (skb->data[hdrlen + 12] << 8) | skb->data[hdrlen + 13]; + tpid = PKT_U16_GET(skb->data, hdrlen + 12); if (tpid != 0x8100) { if (skb_header_cloned(skb) || skb_headroom(skb) < 4) { /* Current SKB cannot be modified */ @@ -5424,6 +5527,7 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) memcpy(&new_skb->data[hdrlen + 16], &skb->data[hdrlen + 12], pktlen - hdrlen - 12); skb_put(new_skb, pktlen + TAG_SZ); + bkn_skb_tstamp_copy(new_skb, skb); dev_kfree_skb_any(skb); skb = new_skb; } else { @@ -5446,7 +5550,7 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) /* Pad packet if needed */ taglen = 0; - tpid = (pktdata[hdrlen + 12] << 8) | pktdata[hdrlen + 13]; + tpid = PKT_U16_GET(pktdata, hdrlen + 12); if (tpid == 0x8100) { taglen = 4; } @@ -5478,8 +5582,19 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) meta = (sinfo->cmic_type == 'x') ? (uint32_t *)pktdata : dcb; memset(dcb, 0, sinfo->dcb_wsize * sizeof(uint32_t)); if (priv->flags & KCOM_NETIF_F_RCPU_ENCAP) { - /* If module header SOP is non-zero, use RCPU meta data */ - if (sop != 0) { + if (device_is_sand(sinfo)) { + if (sinfo->cmic_type == 'x') { + dcb[2] |= 1 << 19; + /* Given Module Header exists and set first byte to be CPU channel */ + pktdata[0] = cpu_channel; + } else { + dcb[1] |= 1 << 19; + /* Set CPU channel */ + dcb[2] = (cpu_channel & 0xff) << 24; + } + + } else if (sop != 0) { + /* If module header SOP is non-zero, use RCPU meta data */ if (sinfo->cmic_type == 'x') { dcb[2] |= 1 << 19; } else { @@ -5521,67 +5636,15 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) dcb[4] |= (priv->qnum & 0xfff) << 14; break; case 28: - { - if (priv->type == KCOM_NETIF_T_PORT) { - /* add PTCH ITMH header */ - if (skb_header_cloned(skb) || skb_headroom(skb) < 4) { - /* Current SKB cannot be modified */ - DBG_SKB(("Realloc Tx SKB for DNX ITMH header\n")); - new_skb = dev_alloc_skb(pktlen + 4 + 2 + FCS_SZ); - if (new_skb == NULL) { - DBG_WARN(("Tx drop: No SKB memory for DNX ITMH header\n")); - priv->stats.tx_dropped++; - sinfo->tx.pkts_d_no_skb++; - dev_kfree_skb_any(skb); - spin_unlock_irqrestore(&sinfo->lock, flags); - return 0; - } - memcpy(&new_skb->data[6], skb->data, pktlen); - skb_put(new_skb, pktlen + 6); - dev_kfree_skb_any(skb); - skb = new_skb; - } else { - /* Add tag to existing buffer */ - DBG_SKB(("Expand Tx SKB for DNX ITMH header\n")); - skb_push(skb, 6); - } - pktdata = skb->data; - pktdata[0] = 0x50; - pktdata[1] = 0x00; - memcpy(&pktdata[2], priv->itmh, 4); - pktlen += 6; - } - else if (priv->type == KCOM_NETIF_T_VLAN) { - /* add PTCH header */ - if (skb_header_cloned(skb) || skb_headroom(skb) < 4) { - /* Current SKB cannot be modified */ - DBG_SKB(("Realloc Tx SKB for DNX header\n")); - new_skb = dev_alloc_skb(pktlen + 2 + FCS_SZ); - if (new_skb == NULL) { - DBG_WARN(("Tx drop: No SKB memory for DNX header\n")); - priv->stats.tx_dropped++; - sinfo->tx.pkts_d_no_skb++; - dev_kfree_skb_any(skb); - spin_unlock_irqrestore(&sinfo->lock, flags); - return 0; - } - memcpy(&new_skb->data[2], skb->data, pktlen); - skb_put(new_skb, pktlen + 2); - dev_kfree_skb_any(skb); - skb = new_skb; - } else { - /* Add tag to existing buffer */ - DBG_SKB(("Expand Tx SKB for DNX header\n")); - skb_push(skb, 2); - } - pktdata = skb->data; - pktdata[0] = 0xd0; - pktdata[1] = priv->port; - pktlen += 2; - } - dcb[1] = pktlen; - break; - } + /* + * If KCOM_NETIF_T_PORT, add PTCH+ITMH header + * If KCOM_NETIF_T_VLAN, add PTCH+header + */ + pktdata = skb->data; + memcpy(&pktdata[0], priv->system_headers, priv->system_headers_size); + /* Set CPU channel */ + dcb[2] = ((priv->qnum & 0xff) << 24); + break; case 29: dcb[2] = 0x81000000; dcb[3] = priv->port; @@ -5640,6 +5703,19 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) memcpy(&pktdata[0], priv->system_headers, priv->system_headers_size); } break; + case 40: + if (sinfo->cmic_type == 'x') { + meta[0] = htonl(0x81000000); + meta[1] = htonl(priv->port | (priv->qnum & 0xc00) << 20); + meta[2] = htonl(0x00040000 | (priv->qnum & 0x3ff) << 8); + } else { + dcb[2] = 0x81000000; + dcb[3] = priv->port; + dcb[3] |= (priv->qnum & 0xc00) << 20; + dcb[4] = 0x00040000; + dcb[4] |= (priv->qnum & 0x3ff) << 8; + } + break; default: dcb[2] = 0xff000000; dcb[3] = 0x00000100; @@ -5695,24 +5771,46 @@ bkn_tx(struct sk_buff *skb, struct net_device *dev) } /* Do Tx timestamping */ - if (priv->port >= 0) { - if (bkn_skb_tx_flags(skb) & SKBTX_HW_TSTAMP && sinfo->tx_hwts) { - KNET_SKB_CB(skb)->port = priv->port; - bkn_hw_tstamp_tx_config(sinfo, skb, meta); + if (bkn_skb_tx_flags(skb) & SKBTX_HW_TSTAMP) { + KNET_SKB_CB(skb)->hwts = priv->tx_hwts; + if ((priv->port >= 0) && (priv->tx_hwts & HWTSTAMP_TX_ON)) { + /* TwoStep Processing of ptp-packets */ + KNET_SKB_CB(skb)->port = priv->phys_port; + bkn_hw_tstamp_tx_config(sinfo, priv->tx_hwts, PKT_TX_HDR_SIZE, skb, meta); + bkn_skb_tx_flags(skb) |= SKBTX_IN_PROGRESS; + bkn_skb_tx_timestamp(skb); + + } else if (priv->tx_hwts & HWTSTAMP_TX_ONESTEP_SYNC) { + + /* OneStep Processing of ptp-packets */ + KNET_SKB_CB(skb)->port = priv->phys_port; + KNET_SKB_CB(skb)->ts = 0; + bkn_hw_tstamp_tx_config(sinfo, priv->tx_hwts, PKT_TX_HDR_SIZE, skb, + ((priv->port >= 0) ? meta : NULL)); + + if (KNET_SKB_CB(skb)->ts != 0) { + bkn_skb_tx_flags(skb) |= SKBTX_IN_PROGRESS; + bkn_skb_tx_timestamp(skb); + } + } - bkn_skb_tx_timestamp(skb); } /* Prepare for DMA */ desc->skb = skb; - /* Add FCS bytes */ - pktlen = pktlen + FCS_SZ; + /* + * Add FCS bytes + * FCS bytes are always appended to packet by MAC on Dune devices + */ + if (!device_is_sand(sinfo)) { + pktlen = pktlen + FCS_SZ; + } desc->dma_size = pktlen; - desc->skb_dma = DMA_MAP_SINGLE(sinfo->dma_dev, + desc->skb_dma = BKN_DMA_MAP_SINGLE(sinfo->dma_dev, pktdata, desc->dma_size, - DMA_TODEV); - if (DMA_MAPPING_ERROR(sinfo->dma_dev, desc->skb_dma)) { + BKN_DMA_TODEV); + if (BKN_DMA_MAPPING_ERROR(sinfo->dma_dev, desc->skb_dma)) { priv->stats.tx_dropped++; dev_kfree_skb_any(skb); spin_unlock_irqrestore(&sinfo->lock, flags); @@ -6079,6 +6177,7 @@ bkn_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info) case 33: case 36: case 38: + case 40: info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE | SOF_TIMESTAMPING_TX_SOFTWARE | SOF_TIMESTAMPING_RX_HARDWARE | @@ -6140,10 +6239,6 @@ bkn_init_ndev(u8 *mac, char *name) if (dev->mtu == 0) { dev->mtu = rx_buffer_size; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) - dev->min_mtu = 68; - dev->max_mtu = rx_buffer_size; -#endif /* Device vectors */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)) @@ -6165,9 +6260,7 @@ bkn_init_ndev(u8 *mac, char *name) strncpy(dev->name, name, IFNAMSIZ-1); } -#ifdef CONFIG_NET_NS - dev_net_set(dev, current->nsproxy->net_ns); -#endif + bkn_dev_net_set(dev, current->nsproxy->net_ns); /* Register the kernel Ethernet device */ if (register_netdev(dev)) { @@ -6739,9 +6832,11 @@ bkn_proc_debug_show(struct seq_file *m, void *v) seq_printf(m, " use_napi: %d\n", use_napi); seq_printf(m, " napi_weight: %d\n", napi_weight); seq_printf(m, " basedev_susp: %d\n", basedev_suspend); - seq_printf(m, "Thread states:\n"); - seq_printf(m, " Command thread: %d\n", bkn_cmd_ctrl.state); - seq_printf(m, " Event thread: %d\n", bkn_evt_ctrl.state); + seq_printf(m, " force_tagged: %d\n", force_tagged); + seq_printf(m, " ft_tpid: %d\n", ft_tpid); + seq_printf(m, " ft_pri: %d\n", ft_pri); + seq_printf(m, " ft_pri: %d\n", ft_cfi); + seq_printf(m, " ft_tpid: %d\n", ft_vid); seq_printf(m, "Active IOCTLs:\n"); seq_printf(m, " Command: %d\n", ioctl_cmd); seq_printf(m, " Event: %d\n", ioctl_evt); @@ -7510,6 +7605,27 @@ bkn_knet_hw_init(kcom_msg_hw_init_t *kmsg, int len) } } + if (device_is_sand(sinfo)) { + int idx = 0; + /* Information to parser Dune system headers */ + sinfo->ftmh_lb_key_ext_size = kmsg->ftmh_lb_key_ext_size; + sinfo->ftmh_stacking_ext_size = kmsg->ftmh_stacking_ext_size; + sinfo->pph_base_size = kmsg->pph_base_size; + for (idx = 0; idx < 8; idx++) + { + sinfo->pph_lif_ext_size[idx] = kmsg->pph_lif_ext_size[idx]; + } + for (idx = 0; idx < 4; idx++) + { + sinfo->udh_length_type[idx] = kmsg->udh_length_type[idx]; + } + sinfo->udh_size = kmsg->udh_size; + sinfo->oamp_punt = kmsg->oamp_punted; + sinfo->no_skip_udh_check = kmsg->no_skip_udh_check; + sinfo->system_headers_mode = kmsg->system_headers_mode; + sinfo->udh_enable = kmsg->udh_enable; + } + /* Ensure that we restart properly */ bkn_dma_abort(sinfo); bkn_clean_dcbs(sinfo); @@ -7552,13 +7668,13 @@ bkn_knet_detach(kcom_msg_detach_t *kmsg, int len) } spin_lock_irqsave(&sinfo->lock, flags); - - /* Create dummy event to unblock pending IOCTL */ - sinfo->dma_events |= KCOM_DMA_INFO_F_TX_DONE; - evt = &_bkn_evt[sinfo->evt_idx]; - evt->evt_wq_put++; - wake_up_interruptible(&evt->evt_wq); - + if (sinfo->evt_idx != -1) { + /* Create dummy event to unblock pending IOCTL */ + sinfo->dma_events |= KCOM_DMA_INFO_F_TX_DONE; + evt = &_bkn_evt[sinfo->evt_idx]; + evt->evt_wq_put++; + wake_up_interruptible(&evt->evt_wq); + } spin_unlock_irqrestore(&sinfo->lock, flags); /* Ensure that we return a valid unit number */ @@ -7591,7 +7707,7 @@ bkn_knet_netif_create(kcom_msg_netif_create_t *kmsg, int len) bkn_priv_t *priv, *lpriv; unsigned long flags; int found, id; - uint8 *ma; + uint8_t *ma; kmsg->hdr.type = KCOM_MSG_TYPE_RSP; @@ -7623,26 +7739,25 @@ bkn_knet_netif_create(kcom_msg_netif_create_t *kmsg, int len) priv->sinfo = sinfo; priv->type = kmsg->netif.type; priv->vlan = kmsg->netif.vlan; + /* System headers are prepared at BCM API for Dune headers */ + if (device_is_sand(sinfo)) { + int idx = 0; + for (idx = 0; idx < KCOM_NETIF_SYSTEM_HEADERS_SIZE_MAX; idx++) + { + priv->system_headers[idx] = kmsg->netif.system_headers[idx]; + } + priv->system_headers_size = kmsg->netif.system_headers_size; + } if (priv->type == KCOM_NETIF_T_PORT) { priv->port = kmsg->netif.port; - if (device_is_dpp(sinfo)) { - memcpy(priv->itmh, kmsg->netif.itmh, 4); - } else if (device_is_dnx(sinfo)) { - memcpy(priv->system_headers, kmsg->netif.system_headers, kmsg->netif.system_headers_size); - priv->system_headers_size = kmsg->netif.system_headers_size; - } + priv->phys_port = kmsg->netif.phys_port; priv->qnum = kmsg->netif.qnum; } else { - if (device_is_sand(sinfo)) { - if (device_is_dpp(sinfo)) { - priv->port = kmsg->netif.port; - priv->qnum = kmsg->netif.qnum; - }else if (device_is_dnx(sinfo)) { - memcpy(priv->system_headers, kmsg->netif.system_headers, kmsg->netif.system_headers_size); - priv->system_headers_size = kmsg->netif.system_headers_size; - } - } - else { + if (device_is_sand(sinfo) && (priv->type == KCOM_NETIF_T_VLAN)) { + /* PTCH.SSPA */ + priv->port = kmsg->netif.port; + priv->qnum = kmsg->netif.qnum; + } else { priv->port = -1; } } @@ -7711,17 +7826,17 @@ bkn_knet_netif_create(kcom_msg_netif_create_t *kmsg, int len) kmsg->netif.id = priv->id; memcpy(kmsg->netif.macaddr, dev->dev_addr, 6); memcpy(kmsg->netif.name, dev->name, KCOM_NETIF_NAME_MAX - 1); - + if (knet_netif_create_cb != NULL) { int retv = knet_netif_create_cb(kmsg->hdr.unit, &(kmsg->netif), dev); - if (retv) { + if (retv) { gprintk("Warning: knet_netif_create_cb() returned %d for netif '%s'\n", retv, dev->name); } } spin_unlock_irqrestore(&sinfo->lock, flags); - if (device_is_dnx(sinfo)) { + if (device_is_sand(sinfo)) { int idx = 0; for (idx = 0; idx < priv->system_headers_size; idx++) { DBG_DUNE(("System Header[%d]: 0x%02x\n", idx, priv->system_headers[idx])); @@ -7857,6 +7972,7 @@ bkn_knet_netif_get(kcom_msg_netif_get_t *kmsg, int len) kmsg->netif.type = priv->type; kmsg->netif.id = priv->id; kmsg->netif.flags = priv->flags; + kmsg->netif.cb_user_data = priv->cb_user_data; if (priv->port < 0) { kmsg->netif.port = 0; @@ -7918,7 +8034,6 @@ bkn_knet_filter_create(kcom_msg_filter_create_t *kmsg, int len) kmsg->hdr.status = KCOM_E_RESOURCE; return sizeof(kcom_msg_hdr_t); } - filter = kmalloc(sizeof(*filter), GFP_ATOMIC); if (filter == NULL) { spin_unlock_irqrestore(&sinfo->lock, flags); @@ -7927,17 +8042,6 @@ bkn_knet_filter_create(kcom_msg_filter_create_t *kmsg, int len) } memset(filter, 0, sizeof(*filter)); memcpy(&filter->kf, &kmsg->filter, sizeof(filter->kf)); - - if (device_is_dnx(sinfo)) { - /* Information to parser Dune system headers */ - sinfo->ftmh_lb_key_ext_size = kmsg->filter.ftmh_lb_key_ext_size; - sinfo->ftmh_stacking_ext_size = kmsg->filter.ftmh_stacking_ext_size; - sinfo->pph_base_size = kmsg->filter.pph_base_size; - memcpy(sinfo->pph_lif_ext_size, kmsg->filter.pph_lif_ext_size, sizeof(sinfo->pph_lif_ext_size)); - sinfo->udh_enable = kmsg->filter.udh_enable; - memcpy(sinfo->udh_length_type, kmsg->filter.udh_length_type, sizeof(sinfo->udh_length_type)); - } - filter->kf.id = id; /* Add according to priority */ @@ -7960,8 +8064,7 @@ bkn_knet_filter_create(kcom_msg_filter_create_t *kmsg, int len) DBG_VERB(("Created filter ID %d (%s).\n", filter->kf.id, filter->kf.desc)); - - if (device_is_dnx(sinfo)) { + if (device_is_sand(sinfo)) { int idx, wsize; wsize = BYTES2WORDS(filter->kf.oob_data_size + filter->kf.pkt_data_size); DBG_DUNE(("Filter: oob_data_size = %d pkt_data_size=%d wsize %d\n", filter->kf.oob_data_size, filter->kf.pkt_data_size, wsize)); @@ -7974,7 +8077,6 @@ bkn_knet_filter_create(kcom_msg_filter_create_t *kmsg, int len) sinfo->pph_lif_ext_size[1],sinfo->pph_lif_ext_size[2], sinfo->pph_lif_ext_size[3], sinfo->udh_enable, sinfo->udh_length_type[0], sinfo->udh_length_type[1], sinfo->udh_length_type[2], sinfo->udh_length_type[3])); } - return len; } @@ -8055,7 +8157,6 @@ bkn_knet_filter_list(kcom_msg_filter_list_t *kmsg, int len) kmsg->fcnt = idx; spin_unlock_irqrestore(&sinfo->lock, flags); - return sizeof(*kmsg) - sizeof(kmsg->id) + (idx * sizeof(kmsg->id[0])); } @@ -8254,6 +8355,24 @@ bkn_handle_cmd_req(kcom_msg_t *kmsg, int len) /* Clean up for warmbooting */ len = bkn_knet_wb_cleanup(&kmsg->wb_cleanup, len); break; + case KCOM_M_CLOCK_CMD: + /* PHC clock control*/ + if (knet_hw_tstamp_ioctl_cmd_cb) { + bkn_switch_info_t *sinfo; + sinfo = bkn_sinfo_from_unit(kmsg->hdr.unit); + if (sinfo == NULL) { + /* The device is not probed or initialized yet.*/ + return 0; + } + DBG_CMD(("KCOM_M_CLOCK_CMD\n")); + len = knet_hw_tstamp_ioctl_cmd_cb(&kmsg->clock_cmd, len, sinfo->dcb_type); + } else { + DBG_WARN(("Unsupported command (type=%d, opcode=%d)\n", + kmsg->hdr.type, kmsg->hdr.opcode)); + kmsg->hdr.opcode = 0; + len = sizeof(kcom_msg_hdr_t); + } + break; default: DBG_WARN(("Unsupported command (type=%d, opcode=%d)\n", kmsg->hdr.type, kmsg->hdr.opcode)); @@ -8264,39 +8383,6 @@ bkn_handle_cmd_req(kcom_msg_t *kmsg, int len) return len; } -static int -bkn_cmd_thread(void *context) -{ - bkn_thread_ctrl_t *tc = (bkn_thread_ctrl_t *)context; - kcom_msg_t kmsg; - unsigned int len, rlen; - - bkn_thread_boot(tc); - - DBG_VERB(("Command thread starting\n")); - tc->state = 1; - while (!bkn_thread_should_stop(tc)) { - len = sizeof(kmsg); - tc->state = 2; - if (PROXY_RECV(KCOM_CHAN_KNET, &kmsg, &len) >= 0) { - DBG_VERB(("Received %d bytes from KCOM_CHAN_CMD\n", len)); - tc->state = 3; - rlen = bkn_handle_cmd_req(&kmsg, len); - tc->state = 4; - if (rlen > 0) { - PROXY_SEND(KCOM_CHAN_KNET, &kmsg, rlen); - } - } else { - /* Thread interrupted */ - bkn_sleep(1); - } - } - DBG_VERB(("Command thread done\n")); - - bkn_thread_exit(tc); - return 0; -} - static int bkn_get_next_dma_event(kcom_msg_dma_info_t *kmsg) { @@ -8370,38 +8456,6 @@ bkn_get_next_dma_event(kcom_msg_dma_info_t *kmsg) return sizeof(*kmsg); } -static int -bkn_evt_thread(void *context) -{ - bkn_thread_ctrl_t *tc = (bkn_thread_ctrl_t *)context; - kcom_msg_dma_info_t kmsg; - int len; - - bkn_thread_boot(tc); - - memset(&kmsg, 0, sizeof(kmsg)); - kmsg.hdr.type = KCOM_MSG_TYPE_EVT; - kmsg.hdr.opcode = KCOM_M_DMA_INFO; - - DBG_VERB(("Event thread starting\n")); - tc->state = 1; - while (!bkn_thread_should_stop(tc)) { - tc->state = 2; - len = bkn_get_next_dma_event(&kmsg); - tc->state = 3; - if (len) { - PROXY_SEND(KCOM_CHAN_KNET, &kmsg, len); - } else { - /* Thread interrupted */ - bkn_sleep(1); - } - } - DBG_VERB(("Event thread done\n")); - - bkn_thread_exit(tc); - return 0; -} - static int _cleanup(void) { @@ -8415,15 +8469,6 @@ _cleanup(void) /* Inidicate that we are shutting down */ module_initialized = 0; - /* Shut down event thread */ - bkn_thread_stop(&bkn_evt_ctrl); - - /* Shut down command thread */ - bkn_thread_stop(&bkn_cmd_ctrl); - - /* Remove KCOM channel */ - PROXY_SERVICE_DESTROY(KCOM_CHAN_KNET); - bkn_proc_cleanup(); remove_proc_entry("bcm/knet", NULL); remove_proc_entry("bcm", NULL); @@ -8586,7 +8631,6 @@ bkn_knet_dev_init(int d) priv->sinfo = sinfo; priv->vlan = 1; priv->port = -1; - memset(priv->itmh, 0, sizeof(priv->itmh)); priv->id = -1; } @@ -8659,16 +8703,6 @@ _init(void) evt = &_bkn_evt[0]; init_waitqueue_head(&evt->evt_wq); - if (use_proxy) { - PROXY_SERVICE_CREATE(KCOM_CHAN_KNET, 1, 0); - - DBG_VERB(("Starting command thread\n")); - bkn_thread_start(&bkn_cmd_ctrl, "bkncmd", bkn_cmd_thread); - - DBG_VERB(("Starting event thread\n")); - bkn_thread_start(&bkn_evt_ctrl, "bknevt", bkn_evt_thread); - } - module_initialized = 1; return 0; @@ -8704,7 +8738,7 @@ _ioctl(unsigned int cmd, unsigned long arg) io.len = bkn_handle_cmd_req(&kmsg, io.len); ioctl_cmd--; } else { - memset(&kmsg, 0, sizeof(kcom_msg_dma_info_t)); + memset(&kmsg, 0, sizeof(kcom_msg_t)); /* * Retrive the kmsg.hdr.unit from user space. The dma event queue * selection is based the instance derived from unit. @@ -9018,6 +9052,27 @@ bkn_hw_tstamp_rx_time_upscale_cb_unregister(knet_hw_tstamp_rx_time_upscale_cb_f return 0; } +int +bkn_hw_tstamp_ioctl_cmd_cb_register(knet_hw_tstamp_ioctl_cmd_cb_f hw_tstamp_ioctl_cmd_cb) +{ + if (knet_hw_tstamp_ioctl_cmd_cb != NULL) { + return -1; + } + knet_hw_tstamp_ioctl_cmd_cb = hw_tstamp_ioctl_cmd_cb; + return 0; +} + +int +bkn_hw_tstamp_ioctl_cmd_cb_unregister(knet_hw_tstamp_ioctl_cmd_cb_f hw_tstamp_ioctl_cmd_cb) +{ + if (knet_hw_tstamp_ioctl_cmd_cb == NULL || + knet_hw_tstamp_ioctl_cmd_cb != hw_tstamp_ioctl_cmd_cb) { + return -1; + } + knet_hw_tstamp_ioctl_cmd_cb = NULL; + return 0; +} + LKM_EXPORT_SYM(bkn_rx_skb_cb_register); LKM_EXPORT_SYM(bkn_rx_skb_cb_unregister); LKM_EXPORT_SYM(bkn_tx_skb_cb_register); @@ -9036,6 +9091,8 @@ LKM_EXPORT_SYM(bkn_hw_tstamp_ptp_clock_index_cb_register); LKM_EXPORT_SYM(bkn_hw_tstamp_ptp_clock_index_cb_unregister); LKM_EXPORT_SYM(bkn_hw_tstamp_rx_time_upscale_cb_register); LKM_EXPORT_SYM(bkn_hw_tstamp_rx_time_upscale_cb_unregister); +LKM_EXPORT_SYM(bkn_hw_tstamp_ioctl_cmd_cb_register); +LKM_EXPORT_SYM(bkn_hw_tstamp_ioctl_cmd_cb_unregister); LKM_EXPORT_SYM(bkn_hw_info_get); LKM_EXPORT_SYM(bkn_netif_create_cb_register); LKM_EXPORT_SYM(bkn_netif_create_cb_unregister); diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/bcm-knet.h b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/bcm-knet.h index 477c037a0c43..4c7541e03825 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/bcm-knet.h +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/bcm-knet.h @@ -39,14 +39,14 @@ typedef struct { * Call-back interfaces for other Linux kernel drivers. */ #include -#include -#include typedef struct { uint32 netif_user_data; uint32 filter_user_data; uint16 dcb_type; int port; + uint64_t ts; + uint32 hwts; } knet_skb_cb_t; #define KNET_SKB_CB(_skb) ((knet_skb_cb_t *)_skb->cb) @@ -59,19 +59,22 @@ typedef int int chan, kcom_filter_t *filter); typedef int -(*knet_hw_tstamp_enable_cb_f)(int dev_no, int port); +(*knet_hw_tstamp_enable_cb_f)(int dev_no, int phys_port, int tx_type); typedef int -(*knet_hw_tstamp_tx_time_get_cb_f)(int dev_no, int port, uint8_t *pkt, uint64_t *ts); +(*knet_hw_tstamp_tx_time_get_cb_f)(int dev_no, int phys_port, uint8_t *pkt, uint64_t *ts); typedef int -(*knet_hw_tstamp_tx_meta_get_cb_f)(int dev_no, struct sk_buff *skb, uint32_t **md); +(*knet_hw_tstamp_tx_meta_get_cb_f)(int dev_no, int hwts, int hdrlen, struct sk_buff *skb, uint64_t *ts, uint32_t **md); typedef int (*knet_hw_tstamp_ptp_clock_index_cb_f)(int dev_no); typedef int -(*knet_hw_tstamp_rx_time_upscale_cb_f)(int dev_no, uint64_t *ts); +(*knet_hw_tstamp_rx_time_upscale_cb_f)(int dev_no, int phys_port, struct sk_buff *skb, uint32_t *meta, uint64_t *ts); + +typedef int +(*knet_hw_tstamp_ioctl_cmd_cb_f)(kcom_msg_clock_cmd_t *kmsg, int len, int dcb_type); extern int bkn_rx_skb_cb_register(knet_skb_cb_f rx_cb); @@ -127,6 +130,12 @@ bkn_hw_tstamp_rx_time_upscale_cb_register(knet_hw_tstamp_rx_time_upscale_cb_f hw extern int bkn_hw_tstamp_rx_time_upscale_cb_unregister(knet_hw_tstamp_rx_time_upscale_cb_f hw_tstamp_rx_time_upscale_cb); +extern int +bkn_hw_tstamp_ioctl_cmd_cb_register(knet_hw_tstamp_ioctl_cmd_cb_f hw_tstamp_ioctl_cmd_cb); + +extern int +bkn_hw_tstamp_ioctl_cmd_cb_unregister(knet_hw_tstamp_ioctl_cmd_cb_f hw_tstamp_ioctl_cmd_cb); + typedef struct { uint8 cmic_type; uint8 dcb_type; @@ -153,6 +162,6 @@ bkn_netif_destroy_cb_register(knet_netif_cb_f netif_cb); extern int bkn_netif_destroy_cb_unregister(knet_netif_cb_f netif_cb); -#endif /* __KERNEL__ */ +#endif #endif /* __LINUX_BCM_KNET_H__ */ diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/lkm.h b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/lkm.h index a48cb540adaf..56d641c9c87c 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/lkm.h +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/include/lkm.h @@ -38,6 +38,11 @@ #include #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) +#if defined(INCLUDE_KNET) && LINUX_VERSION_CODE >= KERNEL_VERSION(4,0,0) +#ifdef CONFIG_NF_CONNTRACK_MODULE +#include +#endif +#endif #include #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/Makefile b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/Makefile index 2a167bb9e811..3de3e07080c4 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/Makefile +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/Makefile @@ -36,6 +36,7 @@ KMODULE = $(LIBDIR)/$(THIS_MOD_NAME).ko build: $(MODULE) $(KMODULE) endif +KBUILD_EXTRA_SYMBOLS := ${BLDDIR}/../bcm-knet/kernel_module/Module.symvers ifeq ($(BUILD_PSAMPLE),1) KBUILD_EXTRA_SYMBOLS += ${BLDDIR}/../psample/kernel_module/Module.symvers endif diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/knet-cb.c b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/knet-cb.c index 89d1087212c7..5b3e1fa82ff3 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/knet-cb.c +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/knet-cb.c @@ -1,15 +1,15 @@ /* * Copyright 2017-2019 Broadcom - * + * * 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 (the "GPL"). - * + * * 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 version 2 (GPLv2) for more details. - * + * * You should have received a copy of the GNU General Public License * version 2 (GPLv2) along with this source code. */ @@ -59,6 +59,26 @@ LKM_MOD_PARAM(debug, "i", int, 0); MODULE_PARM_DESC(debug, "Debug level (default 0)"); +static int tpid=0x8100; +LKM_MOD_PARAM(tpid, "i", int, 0); +MODULE_PARM_DESC(debug, +"Tag Protocol Identifier (TPID) indicates the frame type (default 0x8100)"); + +static int pri=0; +LKM_MOD_PARAM(pri, "i", int, 0); +MODULE_PARM_DESC(pri, +"Priority (PRI) indicates the frame priority (default 0)"); + +static int cfi=0; +LKM_MOD_PARAM(cfi, "i", int, 0); +MODULE_PARM_DESC(cfi, +"Canonical Format Indicator (CFI) indicates whether a MAC address is encapsulated in canonical format over different transmission media (default 0)"); + +static int vid=0; +LKM_MOD_PARAM(vid, "i", int, 0); +MODULE_PARM_DESC(vid, +"VLAN ID (VID) indicates the VLAN to which a frame belongs (default 0)"); + /* Module Information */ #define MODULE_MAJOR 121 #define MODULE_NAME "linux-knet-cb" @@ -67,8 +87,8 @@ MODULE_PARM_DESC(debug, #define KNET_CB_DEBUG /* These below need to match incoming enum values */ -#define FILTER_TAG_STRIP 0 -#define FILTER_TAG_KEEP 1 +#define FILTER_TAG_STRIP 0 +#define FILTER_TAG_KEEP 1 #define FILTER_TAG_ORIGINAL 2 /* Maintain tag strip statistics */ @@ -105,6 +125,31 @@ strip_vlan_tag(struct sk_buff *skb) } } +/* Add VLAN tag to untagged packet */ +static void +add_vlan_tag(struct sk_buff *skb, u32 forward_domain) +{ + u32 vlan = 0; + uint16_t vlan_proto = (uint16_t) ((skb->data[12] << 8) | skb->data[13]); + + if ((vlan_proto != 0x8100) && (vlan_proto != 0x88a8) && (vlan_proto != 0x9100)) { + /* If vid is specified, use configued vid as VLAN ID, or, use forward_domain as vid */ + vlan = vid ? vid: forward_domain; + + skb_push(skb, 4); /* Add 4 bytes from start of buffer */ + /* Move first 12 bytes of packet forward by 4 */ + ((u32 *) skb->data)[0] = ((u32 *) skb->data)[1]; + ((u32 *) skb->data)[1] = ((u32 *) skb->data)[2]; + ((u32 *) skb->data)[2] = ((u32 *) skb->data)[3]; + + /* Set VLAN tag */ + skb->data[12] = (tpid >> 8) & 0xff; + skb->data[13] = tpid & 0xff; + skb->data[14] = (((pri & 0x7) << 5) | ((cfi & 0x1) << 4) | ((vlan >> 8) & 0xf)) & 0xff; + skb->data[15] = vlan & 0xff; + } +} + /* * Location of tagging status in select DCB types found below: * @@ -119,6 +164,7 @@ strip_vlan_tag(struct sk_buff *skb) * 1 = Single inner-tag * 2 = Single outer-tag * 3 = Double tagged. + * 4 = Dedicated for Dune device, packets are received with original tag status. * -1 = Unsupported DCB type */ static int @@ -159,6 +205,11 @@ get_tag_status(int dcb_type, void *meta) tag_status = tag_map[(dcb[9] >> 13) & 0x3]; } break; + case 28: + case 39: + tag_status = 4; + break; + break; default: tag_status = -1; break; @@ -188,12 +239,20 @@ strip_tag_rx_cb(struct sk_buff *skb, int dev_no, void *meta) if (debug & 0x1) { gprintk("%s Enter; netif Flags: %08X filter_flags %08X \n", __func__, netif_flags, filter_flags); - } + } #endif + /* Get DCB type for this packet, passed by KNET driver */ + dcb_type = KNET_SKB_CB(skb)->dcb_type; /* KNET implements this already */ if (filter_flags == FILTER_TAG_KEEP) -{ + { + if (dcb_type ==28 || dcb_type == 39) + { + uint32 *meta_buffer = (uint32 *)meta; + uint32 forward_domain = meta_buffer[1] & 0xffff; + add_vlan_tag(skb, forward_domain); + } strip_stats.skipped++; return skb; } @@ -205,18 +264,16 @@ strip_tag_rx_cb(struct sk_buff *skb, int dev_no, void *meta) { strip_tag = 1; } - /* Get DCB type for this packet, passed by KNET driver */ - dcb_type = KNET_SKB_CB(skb)->dcb_type; + + /* Get tag status from DCB */ tag_status = get_tag_status(dcb_type, meta); - #ifdef KNET_CB_DEBUG if (debug & 0x1) { gprintk("%s; DCB Type: %d; tag status: %d\n", __func__, dcb_type, tag_status); } #endif - if (tag_status < 0) { /* Unsupported DCB type */ return skb; @@ -231,12 +288,13 @@ strip_tag_rx_cb(struct sk_buff *skb, int dev_no, void *meta) strip_tag = 1; } } + strip_stats.checked++; if (strip_tag) { #ifdef KNET_CB_DEBUG if (debug & 0x1) { - gprintk("%s; Stripping VLAN\n", __func__); + gprintk("%s; Stripping VLAN tag\n", __func__); } #endif strip_stats.stripped++; @@ -245,10 +303,11 @@ strip_tag_rx_cb(struct sk_buff *skb, int dev_no, void *meta) #ifdef KNET_CB_DEBUG else { if (debug & 0x1) { - gprintk("%s; Preserve VLAN\n", __func__); + gprintk("%s; Keeping VLAN tag\n", __func__); } } #endif + return skb; } @@ -263,7 +322,7 @@ strip_tag_tx_cb(struct sk_buff *skb, int dev_no, void *meta) /* Filter callback not used */ static int strip_tag_filter_cb(uint8_t * pkt, int size, int dev_no, void *meta, - int chan, kcom_filter_t *kf) + int chan, kcom_filter_t *kf) { /* Pass through for now */ return 0; @@ -306,10 +365,9 @@ knet_netif_destroy_cb(int unit, kcom_netif_t *netif, struct net_device *dev) * Get statistics. * % cat /proc/linux-knet-cb */ - static int _pprint(void) -{ +{ pprintf("Broadcom Linux KNET Call-Back: Untagged VLAN Stripper\n"); pprintf(" %lu stripped packets\n", strip_stats.stripped); pprintf(" %lu packets checked\n", strip_stats.checked); @@ -322,7 +380,9 @@ static int _cleanup(void) { bkn_rx_skb_cb_unregister(strip_tag_rx_cb); - /* strip_tag_tx_cb is currently a no-op, so no need to unregister */ + /* strip_tag_tx_cb is currently a noop, so + * no need to unregister. + */ if (0) { bkn_tx_skb_cb_unregister(strip_tag_tx_cb); @@ -336,14 +396,15 @@ _cleanup(void) psample_cleanup(); #endif return 0; -} +} static int _init(void) { - bkn_rx_skb_cb_register(strip_tag_rx_cb); - /* strip_tag_tx_cb is currently a no-op, so no need to register */ + /* strip_tag_tx_cb is currently a noop, so + * no need to register. + */ if (0) { bkn_tx_skb_cb_register(strip_tag_tx_cb); @@ -352,23 +413,24 @@ _init(void) #ifdef PSAMPLE_SUPPORT psample_init(); #endif - + bkn_filter_cb_register(knet_filter_cb); bkn_netif_create_cb_register(knet_netif_create_cb); bkn_netif_destroy_cb_register(knet_netif_destroy_cb); + return 0; } static gmodule_t _gmodule = { - name: MODULE_NAME, - major: MODULE_MAJOR, + name: MODULE_NAME, + major: MODULE_MAJOR, init: _init, - cleanup: _cleanup, - pprint: _pprint, + cleanup: _cleanup, + pprint: _pprint, ioctl: NULL, - open: NULL, - close: NULL, -}; + open: NULL, + close: NULL, +}; gmodule_t* gmodule_get(void) diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/psample-cb.c b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/psample-cb.c index ef6fc102ce78..a95730078a37 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/psample-cb.c +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/knet-cb/psample-cb.c @@ -64,10 +64,24 @@ extern int debug; #define SOC_HIGIG_SRCPORT(x) ((x[1] >> 16) & 0x1f) #define SOC_HIGIG2_SOP (0xfb) //0xfc - TODO: how can we differentiate between Higig and higig2? #define SOC_HIGIG2_START(x) ((x[0] >> 24) & 0xff) +#define SOC_HIGIG2_IS_MC(x) ((x[0] >> 20) & 0x1) #define SOC_HIGIG2_DSTPORT(x) ((x[0] >> 0) & 0xff) #define SOC_HIGIG2_SRCPORT(x) ((x[1] >> 16) & 0xff) #define SOC_DCB32_HG_OFFSET (6) +/* sFlow v5 datagram dst ifindex field type + * dst ifindex encoding bits [31:30] + */ +#define DSTPORT_TYPE_DISCARD 1 +#define DSTPORT_TYPE_MC 2 + +#define DSTPORT_TYPE_OFFSET 30 +#define DSTPORT_TYPE_MASK 0x3 +#define DSTPORT_TYPE_CLR(_dst) (_dst &= ~(DSTPORT_TYPE_MASK << DSTPORT_TYPE_OFFSET)) +#define DSTPORT_TYPE_SET(_dst,_type) (_dst |= ((_type & DSTPORT_TYPE_MASK) << DSTPORT_TYPE_OFFSET)) +#define DSTPORT_TYPE_GET(_dst) ((_dst >> DSTPORT_TYPE_OFFSET) & DSTPORT_TYPE_MASK) +#define DSTPORT_GET(_dst) (_dst & ~(DSTPORT_TYPE_MASK << DSTPORT_TYPE_OFFSET)) + #define FCS_SZ 4 #define PSAMPLE_NLA_PADDING 4 @@ -84,6 +98,7 @@ static struct proc_dir_entry *psample_proc_root = NULL; /* psample general info */ typedef struct { struct list_head netif_list; + int netif_count; knet_hw_info_t hw; struct net *netns; spinlock_t lock; @@ -96,6 +111,7 @@ typedef struct psample_stats_s { unsigned long pkts_f_psample_mod; unsigned long pkts_f_handled; unsigned long pkts_f_pass_through; + unsigned long pkts_f_dst_mc; unsigned long pkts_d_no_group; unsigned long pkts_d_sampling_disabled; unsigned long pkts_d_no_skb; @@ -213,7 +229,15 @@ psample_meta_dstport_get(uint8_t *pkt, void *pkt_meta) if (SOC_HIGIG2_START(metadata) == SOC_HIGIG2_SOP) { - dstport = SOC_HIGIG2_DSTPORT(metadata); + if (SOC_HIGIG2_IS_MC(metadata)) + { + DSTPORT_TYPE_CLR(dstport); + DSTPORT_TYPE_SET(dstport, DSTPORT_TYPE_MC); + } + else + { + dstport = SOC_HIGIG2_DSTPORT(metadata); + } } else if (SOC_HIGIG_START(metadata) == SOC_HIGIG_SOP) { @@ -273,7 +297,7 @@ psample_meta_sample_reason(uint8_t *pkt, void *pkt_meta) static int psample_meta_get(int unit, uint8_t *pkt, void *pkt_meta, psample_meta_t *sflow_meta) { - int srcport, dstport; + int srcport, dstport, dstport_type; int src_ifindex = 0; int dst_ifindex = 0; int sample_rate = PSAMPLE_RATE_DFLT; @@ -313,8 +337,16 @@ psample_meta_get(int unit, uint8_t *pkt, void *pkt_meta, psample_meta_t *sflow_m } } - /* find dst port netif (no need to lookup CPU port) */ - if (dstport != 0) { + dstport_type = DSTPORT_TYPE_GET(dstport); + dstport = DSTPORT_GET(dstport); + + /* set sFlow dst type for MC pkts */ + if (dstport_type == DSTPORT_TYPE_MC) { + DSTPORT_TYPE_SET(dst_ifindex, DSTPORT_TYPE_MC); + g_psample_stats.pkts_f_dst_mc++; + + /* find dst port netif for UC pkts (no need to lookup CPU port) */ + } else if (dstport != 0) { if ((psample_netif = psample_netif_lookup_by_port(unit, dstport))) { dst_ifindex = psample_netif->dev->ifindex; } else { @@ -323,8 +355,9 @@ psample_meta_get(int unit, uint8_t *pkt, void *pkt_meta, psample_meta_t *sflow_m } } - PSAMPLE_CB_DBG_PRINT("%s: srcport %d, dstport %d, src_ifindex %d, dst_ifindex %d, trunc_size %d, sample_rate %d\n", - __func__, srcport, dstport, src_ifindex, dst_ifindex, sample_size, sample_rate); + PSAMPLE_CB_DBG_PRINT("%s: srcport %d, dstport %d, src_ifindex 0x%x, dst_ifindex 0x%x, " + "trunc_size %d, sample_rate %d\n", + __func__, srcport, dstport, src_ifindex, dst_ifindex, sample_size, sample_rate); sflow_meta->src_ifindex = src_ifindex; sflow_meta->dst_ifindex = dst_ifindex; @@ -386,7 +419,7 @@ psample_filter_cb(uint8_t * pkt, int size, int dev_no, void *pkt_meta, meta.trunc_size = size - PSAMPLE_NLA_PADDING; } - PSAMPLE_CB_DBG_PRINT("%s: group 0x%x, trunc_size %d, src_ifdx %d, dst_ifdx %d, sample_rate %d\n", + PSAMPLE_CB_DBG_PRINT("%s: group 0x%x, trunc_size %d, src_ifdx 0x%x, dst_ifdx 0x%x, sample_rate %d\n", __func__, group->group_num, meta.trunc_size, meta.src_ifindex, meta.dst_ifindex, meta.sample_rate); /* drop if configured sample rate is 0 */ @@ -427,7 +460,7 @@ psample_netif_create_cb(int unit, kcom_netif_t *netif, struct net_device *dev) psample_netif_t *psample_netif, *lpsample_netif; unsigned long flags; - if ((psample_netif = kmalloc(sizeof(psample_netif_t), GFP_KERNEL)) == NULL) { + if ((psample_netif = kmalloc(sizeof(psample_netif_t), GFP_ATOMIC)) == NULL) { gprintk("%s: failed to alloc psample mem for netif '%s'\n", __func__, dev->name); return (-1); @@ -449,6 +482,7 @@ psample_netif_create_cb(int unit, kcom_netif_t *netif, struct net_device *dev) lpsample_netif = (psample_netif_t*)list; if (netif->id < lpsample_netif->id) { found = 1; + g_psample_info.netif_count++; break; } } @@ -489,6 +523,7 @@ psample_netif_destroy_cb(int unit, kcom_netif_t *netif, struct net_device *dev) list_del(&psample_netif->list); PSAMPLE_CB_DBG_PRINT("%s: removing psample netif '%s'\n", __func__, dev->name); kfree(psample_netif); + g_psample_info.netif_count--; break; } } @@ -702,6 +737,47 @@ struct file_operations psample_proc_size_file_ops = { release: single_release, }; +/* + * psample map Proc Read Entry + */ +static int +psample_proc_map_show(struct seq_file *m, void *v) +{ + struct list_head *list; + psample_netif_t *psample_netif; + unsigned long flags; + + seq_printf(m, " Interface logical port ifindex\n"); + seq_printf(m, "------------- ------------ -------\n"); + spin_lock_irqsave(&g_psample_info.lock, flags); + + list_for_each(list, &g_psample_info.netif_list) { + psample_netif = (psample_netif_t*)list; + seq_printf(m, " %-14s %-14d %d\n", + psample_netif->dev->name, + psample_netif->port, + psample_netif->dev->ifindex); + } + + spin_unlock_irqrestore(&g_psample_info.lock, flags); + return 0; +} + +static int +psample_proc_map_open(struct inode * inode, struct file * file) +{ + return single_open(file, psample_proc_map_show, NULL); +} + +struct file_operations psample_proc_map_file_ops = { + owner: THIS_MODULE, + open: psample_proc_map_open, + read: seq_read, + llseek: seq_lseek, + write: NULL, + release: single_release, +}; + /* * psample debug Proc Read Entry */ @@ -715,6 +791,7 @@ psample_proc_debug_show(struct seq_file *m, void *v) seq_printf(m, " dcb_size: %d\n", g_psample_info.hw.dcb_size); seq_printf(m, " pkt_hdr_size: %d\n", g_psample_info.hw.pkt_hdr_size); seq_printf(m, " cdma_channels: %d\n", g_psample_info.hw.cdma_channels); + seq_printf(m, " netif_count: %d\n", g_psample_info.netif_count); return 0; } @@ -779,6 +856,7 @@ psample_proc_stats_show(struct seq_file *m, void *v) seq_printf(m, " pkts sent to psample module %10lu\n", g_psample_stats.pkts_f_psample_mod); seq_printf(m, " pkts handled by psample %10lu\n", g_psample_stats.pkts_f_handled); seq_printf(m, " pkts pass through %10lu\n", g_psample_stats.pkts_f_pass_through); + seq_printf(m, " pkts with mc destination %10lu\n", g_psample_stats.pkts_f_dst_mc); seq_printf(m, " pkts drop no psample group %10lu\n", g_psample_stats.pkts_d_no_group); seq_printf(m, " pkts drop sampling disabled %10lu\n", g_psample_stats.pkts_d_sampling_disabled); seq_printf(m, " pkts drop no skb %10lu\n", g_psample_stats.pkts_d_no_skb); @@ -796,12 +874,26 @@ psample_proc_stats_open(struct inode * inode, struct file * file) return single_open(file, psample_proc_stats_show, NULL); } +/* + * psample stats Proc Write Entry + * + * Syntax: + * write any value to clear stats + */ +static ssize_t +psample_proc_stats_write(struct file *file, const char *buf, + size_t count, loff_t *loff) +{ + memset(&g_psample_stats, 0, sizeof(psample_stats_t)); + return count; +} + struct file_operations psample_proc_stats_file_ops = { owner: THIS_MODULE, open: psample_proc_stats_open, read: seq_read, llseek: seq_lseek, - write: NULL, + write: psample_proc_stats_write, release: single_release, }; @@ -847,6 +939,13 @@ int psample_init(void) return -1; } + /* create procfs for getting netdev mapping */ + PROC_CREATE(entry, "map", 0666, psample_proc_root, &psample_proc_map_file_ops); + if (entry == NULL) { + gprintk("%s: Unable to create procfs entry '/procfs/%s/map'\n", __func__, psample_procfs_path); + return -1; + } + /* create procfs for debug log */ PROC_CREATE(entry, "debug", 0666, psample_proc_root, &psample_proc_debug_file_ops); if (entry == NULL) { diff --git a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/psample/psample.c b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/psample/psample.c index e1d4e2353b09..99317cbf30cc 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/psample/psample.c +++ b/platform/broadcom/saibcm-modules/systems/linux/kernel/modules/psample/psample.c @@ -35,7 +35,7 @@ static const struct genl_multicast_group psample_nl_mcgrps[] = { [PSAMPLE_NL_MCGRP_SAMPLE] = { .name = PSAMPLE_NL_MCGRP_SAMPLE_NAME }, }; -static struct genl_family psample_nl_family __ro_after_init; +static struct genl_family psample_nl_family; static int psample_group_nl_fill(struct sk_buff *msg, struct psample_group *group, @@ -106,7 +106,7 @@ static const struct genl_ops psample_nl_ops[] = { } }; -static struct genl_family psample_nl_family __ro_after_init = { +static struct genl_family psample_nl_family = { .name = PSAMPLE_GENL_NAME, .version = PSAMPLE_GENL_VERSION, .maxattr = PSAMPLE_ATTR_MAX, @@ -224,7 +224,7 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, data_len = PSAMPLE_MAX_PACKET_SIZE - meta_len - NLA_HDRLEN - NLA_ALIGNTO; - nl_skb = genlmsg_new(meta_len + data_len, GFP_ATOMIC); + nl_skb = genlmsg_new(meta_len + nla_total_size(data_len), GFP_ATOMIC); if (unlikely(!nl_skb)) return; diff --git a/platform/broadcom/saibcm-modules/systems/linux/user/common/Makefile b/platform/broadcom/saibcm-modules/systems/linux/user/common/Makefile index 20d83735fcce..a35f2f521433 100644 --- a/platform/broadcom/saibcm-modules/systems/linux/user/common/Makefile +++ b/platform/broadcom/saibcm-modules/systems/linux/user/common/Makefile @@ -65,7 +65,7 @@ ifeq (,$(kernel_version)) kernel_version=2_4 endif -ifeq ($(kernel_version),2_6) +ifneq ($(kernel_version),2_4) KOBJ=ko else KOBJ=o diff --git a/platform/broadcom/saibcm-modules/systems/linux/user/gts/Makefile b/platform/broadcom/saibcm-modules/systems/linux/user/gts/Makefile new file mode 100644 index 000000000000..466faf02a515 --- /dev/null +++ b/platform/broadcom/saibcm-modules/systems/linux/user/gts/Makefile @@ -0,0 +1,63 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# -*- Makefile -*- +# $Id: Makefile,v 0.1 Broadcom SDK $ +# $Copyright: (c) 2015 Broadcom Corp. +# All Rights Reserved.$ + +# +# This make job requires the following environment variables to be set: +# +# SDK - path to StrataXGS SDK root directory +# +# Optionally the following environment variables can be set to +# override the default build server configuration: +# +# TOOLS_DIR - path to build tools (if not in PATH already) +# CROSS_COMPILE - cross compile tools prefix +# LINUX_INCLUDE - path to Linux kernel include directory +# + +SDK :=$(shell if [ -n "$$SDK" ] ; then\ + echo $$SDK;\ + else\ + cd $(dir $(lastword $(MAKEFILE_LIST))); while /usr/bin/test ! -e RELEASE ; do \ + dir=`cd ../;pwd`; \ + if [ "$$dir" = "/" ] ; then \ + echo Cannot find SDK in $(lastword $(MAKEFILE_LIST)) 1>&2; \ + exit 1; \ + fi ; \ + cd $$dir; \ + done ; \ + pwd; \ + fi) + +ifeq ($(SDK),) +$(error Please run this in a tree) +endif + +export SDK + +override kernel_version=4_19 +platform=gts +LINUX_MAKE_USER=1 +export LINKER_RELAX = 1 +export ADD_TO_CFLAGS +export BR_NO_CCACHE + + +include ${SDK}/make/Make.linux + diff --git a/platform/broadcom/saibcm-modules/systems/linux/user/iproc-4_4/Makefile b/platform/broadcom/saibcm-modules/systems/linux/user/iproc-4_4/Makefile new file mode 100644 index 000000000000..e8405f5c2a0c --- /dev/null +++ b/platform/broadcom/saibcm-modules/systems/linux/user/iproc-4_4/Makefile @@ -0,0 +1,59 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# -*- Makefile -*- +# $Id: Makefile,v 1.7 Broadcom SDK $ +# $Copyright: (c) 2005 Broadcom Corp. +# All Rights Reserved.$ + +# +# This make job requires the following environment variables to be set: +# +# SDK - path to StrataXGS SDK root directory +# + +SDK :=$(shell if [ -n "$$SDK" ] ; then\ + echo $$SDK;\ + else\ + cd $(dir $(lastword $(MAKEFILE_LIST))); while /usr/bin/test ! -e RELEASE ; do \ + dir=`cd ../;pwd`; \ + if [ "$$dir" = "/" ] ; then \ + echo Cannot find SDK in $(lastword $(MAKEFILE_LIST)) 1>&2; \ + exit 1; \ + fi ; \ + cd $$dir; \ + done ; \ + pwd; \ + fi) + +ifeq ($(SDK),) +$(error Please run this in a tree) +endif + +export SDK + +override kernel_version=4_4 +platform=iproc-$(kernel_version) + +IPROC_BUILD=1 +export IPROC_BUILD +export BUILD_PLATFORM +export ARM_LINUX_VERSION + +LINUX_MAKE_USER=1 +export ADD_TO_CFLAGS +export BR_NO_CCACHE + +include ${SDK}/make/Make.linux diff --git a/platform/broadcom/saibcm-modules/systems/linux/user/iproc_64/Makefile b/platform/broadcom/saibcm-modules/systems/linux/user/iproc_64/Makefile new file mode 100644 index 000000000000..778c85a03bed --- /dev/null +++ b/platform/broadcom/saibcm-modules/systems/linux/user/iproc_64/Makefile @@ -0,0 +1,59 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# -*- Makefile -*- +# $Id: Makefile,v 1.7 Broadcom SDK $ +# $Copyright: (c) 2005 Broadcom Corp. +# All Rights Reserved.$ + +# +# This make job requires the following environment variables to be set: +# +# SDK - path to StrataXGS SDK root directory +# + +SDK :=$(shell if [ -n "$$SDK" ] ; then\ + echo $$SDK;\ + else\ + cd $(dir $(lastword $(MAKEFILE_LIST))); while /usr/bin/test ! -e RELEASE ; do \ + dir=`cd ../;pwd`; \ + if [ "$$dir" = "/" ] ; then \ + echo Cannot find SDK in $(lastword $(MAKEFILE_LIST)) 1>&2; \ + exit 1; \ + fi ; \ + cd $$dir; \ + done ; \ + pwd; \ + fi) + +ifeq ($(SDK),) +$(error Please run this in a tree) +endif + +export SDK + +override kernel_version=4_14 +platform=iproc_64 + +IPROC_BUILD=1 +export IPROC_BUILD +export BUILD_PLATFORM +export ARM_LINUX_VERSION + +LINUX_MAKE_USER=1 +export ADD_TO_CFLAGS +export BR_NO_CCACHE + +include ${SDK}/make/Make.linux diff --git a/platform/broadcom/saibcm-modules/systems/linux/user/slk/Makefile b/platform/broadcom/saibcm-modules/systems/linux/user/slk/Makefile new file mode 100644 index 000000000000..99d49d285145 --- /dev/null +++ b/platform/broadcom/saibcm-modules/systems/linux/user/slk/Makefile @@ -0,0 +1,60 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# -*- Makefile -*- +# $Id: Makefile,v 0.1 Broadcom SDK $ +# $Copyright: (c) 2015 Broadcom Corp. +# All Rights Reserved.$ + +# +# This make job requires the following environment variables to be set: +# +# SDK - path to StrataXGS SDK root directory +# +# Optionally the following environment variables can be set to +# override the default build server configuration: +# +# TOOLS_DIR - path to build tools (if not in PATH already) +# CROSS_COMPILE - cross compile tools prefix +# LINUX_INCLUDE - path to Linux kernel include directory +# + +SDK :=$(shell if [ -n "$$SDK" ] ; then\ + echo $$SDK;\ + else\ + cd $(dir $(lastword $(MAKEFILE_LIST))); while /usr/bin/test ! -e RELEASE ; do \ + dir=`cd ../;pwd`; \ + if [ "$$dir" = "/" ] ; then \ + echo Cannot find SDK in $(lastword $(MAKEFILE_LIST)) 1>&2; \ + exit 1; \ + fi ; \ + cd $$dir; \ + done ; \ + pwd; \ + fi) + +ifeq ($(SDK),) +$(error Please run this in a tree) +endif + +export SDK + +override kernel_version=3_14 +platform=slk +LINUX_MAKE_USER=1 +export LINKER_RELAX = 1 + +include ${SDK}/make/Make.linux + diff --git a/platform/broadcom/saibcm-modules/systems/linux/user/xlr/Makefile b/platform/broadcom/saibcm-modules/systems/linux/user/xlr/Makefile new file mode 100644 index 000000000000..13246d09e78f --- /dev/null +++ b/platform/broadcom/saibcm-modules/systems/linux/user/xlr/Makefile @@ -0,0 +1,63 @@ +# +# Copyright 2017 Broadcom +# +# 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 (the "GPL"). +# +# 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 version 2 (GPLv2) for more details. +# +# You should have received a copy of the GNU General Public License +# version 2 (GPLv2) along with this source code. +# +# -*- Makefile -*- +# $Id: Makefile,v 0.1 Broadcom SDK $ +# $Copyright: (c) 2015 Broadcom Corp. +# All Rights Reserved.$ + +# +# This make job requires the following environment variables to be set: +# +# SDK - path to StrataXGS SDK root directory +# +# Optionally the following environment variables can be set to +# override the default build server configuration: +# +# TOOLS_DIR - path to build tools (if not in PATH already) +# CROSS_COMPILE - cross compile tools prefix +# LINUX_INCLUDE - path to Linux kernel include directory +# + +SDK :=$(shell if [ -n "$$SDK" ] ; then\ + echo $$SDK;\ + else\ + cd $(dir $(lastword $(MAKEFILE_LIST))); while /usr/bin/test ! -e RELEASE ; do \ + dir=`cd ../;pwd`; \ + if [ "$$dir" = "/" ] ; then \ + echo Cannot find SDK in $(lastword $(MAKEFILE_LIST)) 1>&2; \ + exit 1; \ + fi ; \ + cd $$dir; \ + done ; \ + pwd; \ + fi) + +ifeq ($(SDK),) +$(error Please run this in a tree) +endif + +export SDK + +override kernel_version=4_19 +platform=xlr +LINUX_MAKE_USER=1 +export LINKER_RELAX = 1 +export ADD_TO_CFLAGS +export BR_NO_CCACHE + + +include ${SDK}/make/Make.linux +