aboutsummaryrefslogtreecommitdiff
path: root/src/vendorcode/cavium/include/bdk/libbdk-hal
diff options
context:
space:
mode:
authorDavid Hendricks <dhendricks@fb.com>2018-03-09 13:58:27 -0800
committerPatrick Georgi <pgeorgi@google.com>2018-04-06 06:48:11 +0000
commit2004b93aed993aa02bbc588b8d82c22418ac52ec (patch)
treecdd5e95a154e2e0139474288262835a7f5847665 /src/vendorcode/cavium/include/bdk/libbdk-hal
parent71cbd71eb5c0e8e13b25b5d5dd2f495e7d2967eb (diff)
soc/cavium: import raw BDK sources
This imports common BDK sources that will be used in subsequent patches. The BDK is licensed under BSD and will be reduced in size and optimized to compile under coreboot. Change-Id: Icb32ee670d9fa9e5c10f9abb298cebf616fa67ad Signed-off-by: David Hendricks <dhendricks@fb.com> Reviewed-on: https://review.coreboot.org/25524 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Diffstat (limited to 'src/vendorcode/cavium/include/bdk/libbdk-hal')
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access-native.h155
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access.h133
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-atomic.h541
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-clock.h105
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-config.h357
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-crc.h53
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-ecam.h97
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-error-report.h62
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-fpa.h162
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-gpio.h111
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-hal.h98
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-key.h86
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-l2c.h179
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mdio.h476
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mmc.h89
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mpi.h105
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nic.h107
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nix.h105
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pbus-flash.h111
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie-flash.h109
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie.h236
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pki.h83
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pko.h126
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-power-burn.h67
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-qlm.h508
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rng.h79
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rvu.h66
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sata.h163
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-spinlock.h146
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sso.h69
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-tns.h109
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-twsi.h102
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-usb.h109
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-utils.h206
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-vrm.h66
-rw-r--r--src/vendorcode/cavium/include/bdk/libbdk-hal/device/bdk-device.h259
36 files changed, 5635 insertions, 0 deletions
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access-native.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access-native.h
new file mode 100644
index 0000000000..aa9d87bf37
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access-native.h
@@ -0,0 +1,155 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ * Functions for accessing memory and CSRs when we are compiling
+ * natively.
+ *
+ * <hr>$Revision: 38306 $<hr>
+*/
+
+/**
+ * Convert a memory pointer (void*) into a hardware compatible
+ * memory address (uint64_t). Cavium hardware widgets don't
+ * understand logical addresses.
+ *
+ * @param ptr C style memory pointer
+ * @return Hardware physical address
+ */
+static inline uint64_t bdk_ptr_to_phys(void *ptr) __attribute__ ((pure, always_inline));
+static inline uint64_t bdk_ptr_to_phys(void *ptr)
+{
+ bdk_warn_if(!ptr, "bdk_ptr_to_phys() passed a NULL\n");
+ return (long)ptr;
+}
+
+
+/**
+ * Convert a hardware physical address (uint64_t) into a
+ * memory pointer (void *).
+ *
+ * @param physical_address
+ * Hardware physical address to memory
+ * @return Pointer to memory
+ */
+static inline void *bdk_phys_to_ptr(uint64_t physical_address) __attribute__ ((pure, always_inline));
+static inline void *bdk_phys_to_ptr(uint64_t physical_address)
+{
+ bdk_warn_if(physical_address==0, "bdk_phys_to_ptr() passed a zero address\n");
+ return (void*)(long)physical_address;
+}
+
+
+/* We have a full 64bit ABI. Writing to a 64bit address can be done with
+ a simple volatile pointer */
+#define BDK_BUILD_WRITE64(TYPE) \
+static inline void bdk_write64_##TYPE(uint64_t addr, TYPE##_t val) __attribute__ ((always_inline)); \
+static inline void bdk_write64_##TYPE(uint64_t addr, TYPE##_t val) \
+{ \
+ *(volatile TYPE##_t *)bdk_phys_to_ptr(addr) = val; \
+}
+
+/* We have a full 64bit ABI. Writing to a 64bit address can be done with
+ a simple volatile pointer */
+#define BDK_BUILD_READ64(TYPE) \
+static inline TYPE##_t bdk_read64_##TYPE(uint64_t addr) __attribute__ ((always_inline)); \
+static inline TYPE##_t bdk_read64_##TYPE(uint64_t addr) \
+{ \
+ return *(volatile TYPE##_t *)bdk_phys_to_ptr(addr); \
+}
+
+/* The following defines 8 functions for writing to a 64bit address. Each
+ takes two arguments, the address and the value to write.
+ bdk_write64_int64 bdk_write64_uint64
+ bdk_write64_int32 bdk_write64_uint32
+ bdk_write64_int16 bdk_write64_uint16
+ bdk_write64_int8 bdk_write64_uint8 */
+BDK_BUILD_WRITE64(int64)
+BDK_BUILD_WRITE64(int32)
+BDK_BUILD_WRITE64(int16)
+BDK_BUILD_WRITE64(int8)
+BDK_BUILD_WRITE64(uint64)
+BDK_BUILD_WRITE64(uint32)
+BDK_BUILD_WRITE64(uint16)
+BDK_BUILD_WRITE64(uint8)
+
+/* The following defines 8 functions for reading from a 64bit address. Each
+ takes the address as the only argument
+ bdk_read64_int64 bdk_read64_uint64
+ bdk_read64_int32 bdk_read64_uint32
+ bdk_read64_int16 bdk_read64_uint16
+ bdk_read64_int8 bdk_read64_uint8 */
+BDK_BUILD_READ64(int64)
+BDK_BUILD_READ64(int32)
+BDK_BUILD_READ64(int16)
+BDK_BUILD_READ64(int8)
+BDK_BUILD_READ64(uint64)
+BDK_BUILD_READ64(uint32)
+BDK_BUILD_READ64(uint16)
+BDK_BUILD_READ64(uint8)
+
+
+/**
+ * Returns the number of bits set in the provided value.
+ * Simple wrapper for POP instruction.
+ *
+ * @param val 32 bit value to count set bits in
+ *
+ * @return Number of bits set
+ */
+static inline uint32_t bdk_pop(uint32_t val)
+{
+ return __builtin_popcount(val);
+}
+
+
+/**
+ * Returns the number of bits set in the provided value.
+ * Simple wrapper for DPOP instruction.
+ *
+ * @param val 64 bit value to count set bits in
+ *
+ * @return Number of bits set
+ */
+static inline int bdk_dpop(uint64_t val)
+{
+ return __builtin_popcountl(val);
+}
+
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access.h
new file mode 100644
index 0000000000..d50ecd7e5c
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-access.h
@@ -0,0 +1,133 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ * Function prototypes for accessing memory and CSRs.
+ *
+ * <hr>$Revision: 38306 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+*/
+
+#define BDK_FUNCTION static inline
+
+/**
+ * Convert a memory pointer (void*) into a hardware compatible
+ * memory address (uint64_t). Cavium hardware widgets don't
+ * understand logical addresses.
+ *
+ * @param ptr C style memory pointer
+ * @return Hardware physical address
+ */
+BDK_FUNCTION uint64_t bdk_ptr_to_phys(void *ptr);
+
+/**
+ * Convert a hardware physical address (uint64_t) into a
+ * memory pointer (void *).
+ *
+ * @param physical_address
+ * Hardware physical address to memory
+ * @return Pointer to memory
+ */
+BDK_FUNCTION void *bdk_phys_to_ptr(uint64_t physical_address);
+
+BDK_FUNCTION void bdk_write64_int64(uint64_t address, int64_t value);
+BDK_FUNCTION void bdk_write64_uint64(uint64_t address, uint64_t value);
+BDK_FUNCTION void bdk_write64_int32(uint64_t address, int32_t value);
+BDK_FUNCTION void bdk_write64_uint32(uint64_t address, uint32_t value);
+BDK_FUNCTION void bdk_write64_int16(uint64_t address, int16_t value);
+BDK_FUNCTION void bdk_write64_uint16(uint64_t address, uint16_t value);
+BDK_FUNCTION void bdk_write64_int8(uint64_t address, int8_t value);
+BDK_FUNCTION void bdk_write64_uint8(uint64_t address, uint8_t value);
+
+BDK_FUNCTION int64_t bdk_read64_int64(uint64_t address);
+BDK_FUNCTION uint64_t bdk_read64_uint64(uint64_t address);
+BDK_FUNCTION int32_t bdk_read64_int32(uint64_t address);
+BDK_FUNCTION uint32_t bdk_read64_uint32(uint64_t address);
+BDK_FUNCTION int16_t bdk_read64_int16(uint64_t address);
+BDK_FUNCTION uint16_t bdk_read64_uint16(uint64_t address);
+BDK_FUNCTION int8_t bdk_read64_int8(uint64_t address);
+BDK_FUNCTION uint8_t bdk_read64_uint8(uint64_t address);
+
+/**
+ * Returns the number of bits set in the provided value.
+ * Simple wrapper for POP instruction.
+ *
+ * @param val 32 bit value to count set bits in
+ *
+ * @return Number of bits set
+ */
+BDK_FUNCTION uint32_t bdk_pop(uint32_t val);
+
+/**
+ * Returns the number of bits set in the provided value.
+ * Simple wrapper for DPOP instruction.
+ *
+ * @param val 64 bit value to count set bits in
+ *
+ * @return Number of bits set
+ */
+BDK_FUNCTION int bdk_dpop(uint64_t val);
+
+/**
+ * Wait for the specified number of core clock cycles
+ *
+ * @param cycles
+ */
+extern void bdk_wait(uint64_t cycles);
+
+/**
+ * Wait for the specified number of micro seconds
+ *
+ * @param usec micro seconds to wait
+ */
+extern void bdk_wait_usec(uint64_t usec);
+
+/**
+ * Perform a soft reset of the chip
+ *
+ * @return
+ */
+extern void bdk_reset_chip(bdk_node_t node);
+
+#undef BDK_FUNCTION
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-atomic.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-atomic.h
new file mode 100644
index 0000000000..7f521a67e2
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-atomic.h
@@ -0,0 +1,541 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * This file provides atomic operations
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Atomically adds a signed value to a 32 bit (aligned) memory location.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints. (This should NOT be used for reference counting -
+ * use the standard version instead.)
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ */
+static inline void bdk_atomic_add32_nosync(int32_t *ptr, int32_t incr)
+{
+ /* Atomic add with no ordering */
+ asm volatile ("ldadd %w[i], wzr, [%[b]]"
+ : [r] "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+}
+
+/**
+ * Atomically adds a signed value to a 32 bit (aligned) memory location.
+ *
+ * Memory access ordering is enforced before/after the atomic operation,
+ * so no additional 'sync' instructions are required.
+ *
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ */
+static inline void bdk_atomic_add32(int32_t *ptr, int32_t incr)
+{
+ /* Atomic add with acquire and release */
+ asm volatile ("ldaddal %w[i], wzr, [%[b]]"
+ : "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+}
+
+/**
+ * Atomically sets a 32 bit (aligned) memory location to a value
+ *
+ * @param ptr address of memory to set
+ * @param value value to set memory location to.
+ */
+static inline void bdk_atomic_set32(int32_t *ptr, int32_t value)
+{
+ /* Implies a release */
+ asm volatile ("stlr %w[v], [%[b]]"
+ : "+m" (*ptr)
+ : [v] "r" (value), [b] "r" (ptr)
+ : "memory");
+}
+
+/**
+ * Returns the current value of a 32 bit (aligned) memory
+ * location.
+ *
+ * @param ptr Address of memory to get
+ * @return Value of the memory
+ */
+static inline int32_t bdk_atomic_get32(int32_t *ptr)
+{
+ return *(volatile int32_t *)ptr;
+}
+
+/**
+ * Atomically adds a signed value to a 64 bit (aligned) memory location.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints. (This should NOT be used for reference counting -
+ * use the standard version instead.)
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ */
+static inline void bdk_atomic_add64_nosync(int64_t *ptr, int64_t incr)
+{
+ /* Atomic add with no ordering */
+ asm volatile ("ldadd %x[i], xzr, [%[b]]"
+ : [r] "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+}
+
+/**
+ * Atomically adds a signed value to a 64 bit (aligned) memory location.
+ *
+ * Memory access ordering is enforced before/after the atomic operation,
+ * so no additional 'sync' instructions are required.
+ *
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ */
+static inline void bdk_atomic_add64(int64_t *ptr, int64_t incr)
+{
+ /* Atomic add with acquire and release */
+ asm volatile ("ldaddal %x[i], xzr, [%[b]]"
+ : [r] "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+}
+
+/**
+ * Atomically sets a 64 bit (aligned) memory location to a value
+ *
+ * @param ptr address of memory to set
+ * @param value value to set memory location to.
+ */
+static inline void bdk_atomic_set64(int64_t *ptr, int64_t value)
+{
+ /* Implies a release */
+ asm volatile ("stlr %x[v], [%[b]]"
+ : "+m" (*ptr)
+ : [v] "r" (value), [b] "r" (ptr)
+ : "memory");
+}
+
+/**
+ * Returns the current value of a 64 bit (aligned) memory
+ * location.
+ *
+ * @param ptr Address of memory to get
+ * @return Value of the memory
+ */
+static inline int64_t bdk_atomic_get64(int64_t *ptr)
+{
+ return *(volatile int64_t *)ptr;
+}
+
+/**
+ * Atomically compares the old value with the value at ptr, and if they match,
+ * stores new_val to ptr.
+ * If *ptr and old don't match, function returns failure immediately.
+ * If *ptr and old match, function spins until *ptr updated to new atomically, or
+ * until *ptr and old no longer match
+ *
+ * Does no memory synchronization.
+ *
+ * @return 1 on success (match and store)
+ * 0 on no match
+ */
+static inline int bdk_atomic_compare_and_store32_nosync(uint32_t *ptr, uint32_t old_val, uint32_t new_val) __attribute__((always_inline));
+static inline int bdk_atomic_compare_and_store32_nosync(uint32_t *ptr, uint32_t old_val, uint32_t new_val)
+{
+ uint32_t val = old_val;
+
+ /* CN88XX pass 1.x has errata AP-22500: GlobalSync request during a multi-cycle ATOMIC stalls forever
+ Don't use compare and swap on these chips */
+ if (CAVIUM_IS_MODEL(CAVIUM_CN88XX_PASS1_X))
+ {
+ asm volatile ("1: ldxr %w[v], [%[b]] \n"
+ " cmp %w[v], %w[o] \n"
+ " b.ne 2f \n"
+ " stxr %w[v], %w[n], [%[b]]\n" /* Returns zero on success */
+ " cbnz %w[v], 1b \n"
+ " mov %w[v], %w[o] \n"
+ "2: \n"
+ : [mem] "+m" (*ptr), [v] "=&r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val), [o] "r" (old_val)
+ : );
+ }
+ else
+ {
+ asm volatile ("cas %w[o], %w[n], [%[b]]"
+ : [mem] "+m" (*ptr), [o] "+r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val)
+ : );
+ }
+ return old_val == val;
+}
+
+/**
+ * Atomically compares the old value with the value at ptr, and if they match,
+ * stores new_val to ptr.
+ * If *ptr and old don't match, function returns failure immediately.
+ * If *ptr and old match, function spins until *ptr updated to new atomically, or
+ * until *ptr and old no longer match
+ *
+ * Does memory synchronization that is required to use this as a locking primitive.
+ *
+ * @return 1 on success (match and store)
+ * 0 on no match
+ */
+static inline int bdk_atomic_compare_and_store32(uint32_t *ptr, uint32_t old_val, uint32_t new_val) __attribute__((always_inline));
+static inline int bdk_atomic_compare_and_store32(uint32_t *ptr, uint32_t old_val, uint32_t new_val)
+{
+ uint32_t val = old_val;
+
+ /* CN88XX pass 1.x has errata AP-22500: GlobalSync request during a multi-cycle ATOMIC stalls forever
+ Don't use compare and swap on these chips */
+ if (CAVIUM_IS_MODEL(CAVIUM_CN88XX_PASS1_X))
+ {
+ asm volatile ("1: ldaxr %w[v], [%[b]] \n"
+ " cmp %w[v], %w[o] \n"
+ " b.ne 2f \n"
+ " stlxr %w[v], %w[n], [%[b]]\n" /* Returns zero on success */
+ " cbnz %w[v], 1b \n"
+ " mov %w[v], %w[o] \n"
+ "2: \n"
+ : [mem] "+m" (*ptr), [v] "=&r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val), [o] "r" (old_val)
+ : );
+ }
+ else
+ {
+ asm volatile ("casal %w[o], %w[n], [%[b]]"
+ : [mem] "+m" (*ptr), [o] "+r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val)
+ : );
+ }
+ return old_val == val;
+}
+
+/**
+ * Atomically compares the old value with the value at ptr, and if they match,
+ * stores new_val to ptr.
+ * If *ptr and old don't match, function returns failure immediately.
+ * If *ptr and old match, function spins until *ptr updated to new atomically, or
+ * until *ptr and old no longer match
+ *
+ * Does no memory synchronization.
+ *
+ * @return 1 on success (match and store)
+ * 0 on no match
+ */
+static inline int bdk_atomic_compare_and_store64_nosync(uint64_t *ptr, uint64_t old_val, uint64_t new_val) __attribute__((always_inline));
+static inline int bdk_atomic_compare_and_store64_nosync(uint64_t *ptr, uint64_t old_val, uint64_t new_val)
+{
+ uint32_t val = old_val;
+
+ /* CN88XX pass 1.x has errata AP-22500: GlobalSync request during a multi-cycle ATOMIC stalls forever
+ Don't use compare and swap on these chips */
+ if (CAVIUM_IS_MODEL(CAVIUM_CN88XX_PASS1_X))
+ {
+ asm volatile ("1: ldxr %x[v], [%[b]] \n"
+ " cmp %x[v], %x[o] \n"
+ " b.ne 2f \n"
+ " stxr %x[v], %x[n], [%[b]]\n" /* Returns zero on success */
+ " cbnz %x[v], 1b \n"
+ " mov %x[v], %x[o] \n"
+ "2: \n"
+ : [mem] "+m" (*ptr), [v] "=&r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val), [o] "r" (old_val)
+ : );
+ }
+ else
+ {
+ asm volatile ("cas %x[o], %x[n], [%[b]]"
+ : [mem] "+m" (*ptr), [o] "+r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val)
+ : );
+ }
+ return old_val == val;
+}
+
+/**
+ * Atomically compares the old value with the value at ptr, and if they match,
+ * stores new_val to ptr.
+ * If *ptr and old don't match, function returns failure immediately.
+ * If *ptr and old match, function spins until *ptr updated to new atomically, or
+ * until *ptr and old no longer match
+ *
+ * Does memory synchronization that is required to use this as a locking primitive.
+ *
+ * @return 1 on success (match and store)
+ * 0 on no match
+ */
+static inline int bdk_atomic_compare_and_store64(uint64_t *ptr, uint64_t old_val, uint64_t new_val) __attribute__((always_inline));
+static inline int bdk_atomic_compare_and_store64(uint64_t *ptr, uint64_t old_val, uint64_t new_val)
+{
+ uint32_t val = old_val;
+
+ /* CN88XX pass 1.x has errata AP-22500: GlobalSync request during a multi-cycle ATOMIC stalls forever
+ Don't use compare and swap on these chips */
+ if (CAVIUM_IS_MODEL(CAVIUM_CN88XX_PASS1_X))
+ {
+ asm volatile ("1: ldaxr %x[v], [%[b]] \n"
+ " cmp %x[v], %x[o] \n"
+ " b.ne 2f \n"
+ " stlxr %x[v], %x[n], [%[b]]\n" /* Returns zero on success */
+ " cbnz %x[v], 1b \n"
+ " mov %x[v], %x[o] \n"
+ "2: \n"
+ : [mem] "+m" (*ptr), [v] "=&r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val), [o] "r" (old_val)
+ : );
+ }
+ else
+ {
+ asm volatile ("casal %x[o], %x[n], [%[b]]"
+ : [mem] "+m" (*ptr), [o] "+r" (val)
+ : [b] "r" (ptr), [n] "r" (new_val)
+ : );
+ }
+ return old_val == val;
+}
+
+/**
+ * Atomically adds a signed value to a 64 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints. (This should NOT be used for reference counting -
+ * use the standard version instead.)
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ *
+ * @return Value of memory location before increment
+ */
+static inline int64_t bdk_atomic_fetch_and_add64_nosync(int64_t *ptr, int64_t incr)
+{
+ int64_t result;
+ /* Atomic add with no ordering */
+ asm volatile ("ldadd %x[i], %x[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/**
+ * Atomically adds a signed value to a 64 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * Memory access ordering is enforced before/after the atomic operation,
+ * so no additional 'sync' instructions are required.
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ *
+ * @return Value of memory location before increment
+ */
+static inline int64_t bdk_atomic_fetch_and_add64(int64_t *ptr, int64_t incr)
+{
+ int64_t result;
+ /* Atomic add with acquire/release */
+ asm volatile ("ldaddal %x[i], %x[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/**
+ * Atomically adds a signed value to a 32 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints. (This should NOT be used for reference counting -
+ * use the standard version instead.)
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ *
+ * @return Value of memory location before increment
+ */
+static inline int32_t bdk_atomic_fetch_and_add32_nosync(int32_t *ptr, int32_t incr)
+{
+ int32_t result;
+ /* Atomic add with no ordering */
+ asm volatile ("ldadd %w[i], %w[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/**
+ * Atomically adds a signed value to a 32 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * Memory access ordering is enforced before/after the atomic operation,
+ * so no additional 'sync' instructions are required.
+ *
+ * @param ptr address in memory to add incr to
+ * @param incr amount to increment memory location by (signed)
+ *
+ * @return Value of memory location before increment
+ */
+static inline int32_t bdk_atomic_fetch_and_add32(int32_t *ptr, int32_t incr)
+{
+ int32_t result;
+ /* Atomic add with acquire/release */
+ asm volatile ("ldaddal %w[i], %w[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (incr), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/**
+ * Atomically set bits in a 64 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints.
+ *
+ * @param ptr address in memory
+ * @param mask mask of bits to set
+ *
+ * @return Value of memory location before setting bits
+ */
+static inline uint64_t bdk_atomic_fetch_and_bset64_nosync(uint64_t *ptr, uint64_t mask)
+{
+ uint64_t result;
+ /* Atomic or with no ordering */
+ asm volatile ("ldset %x[i], %x[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (mask), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/**
+ * Atomically set bits in a 32 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints.
+ *
+ * @param ptr address in memory
+ * @param mask mask of bits to set
+ *
+ * @return Value of memory location before setting bits
+ */
+static inline uint32_t bdk_atomic_fetch_and_bset32_nosync(uint32_t *ptr, uint32_t mask)
+{
+ uint32_t result;
+ /* Atomic or with no ordering */
+ asm volatile ("ldset %w[i], %w[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (mask), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/**
+ * Atomically clear bits in a 64 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints.
+ *
+ * @param ptr address in memory
+ * @param mask mask of bits to clear
+ *
+ * @return Value of memory location before clearing bits
+ */
+static inline uint64_t bdk_atomic_fetch_and_bclr64_nosync(uint64_t *ptr, uint64_t mask)
+{
+ uint64_t result;
+ /* Atomic and with no ordering */
+ asm volatile ("ldclr %x[i], %x[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (mask), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/**
+ * Atomically clear bits in a 32 bit (aligned) memory location,
+ * and returns previous value.
+ *
+ * This version does not perform 'sync' operations to enforce memory
+ * operations. This should only be used when there are no memory operation
+ * ordering constraints.
+ *
+ * @param ptr address in memory
+ * @param mask mask of bits to clear
+ *
+ * @return Value of memory location before clearing bits
+ */
+static inline uint32_t bdk_atomic_fetch_and_bclr32_nosync(uint32_t *ptr, uint32_t mask)
+{
+ uint32_t result;
+ /* Atomic and with no ordering */
+ asm volatile ("ldclr %w[i], %w[r], [%[b]]"
+ : [r] "=r" (result), "+m" (*ptr)
+ : [i] "r" (mask), [b] "r" (ptr)
+ : "memory");
+ return result;
+}
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-clock.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-clock.h
new file mode 100644
index 0000000000..d0d117c590
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-clock.h
@@ -0,0 +1,105 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to Core, IO and DDR Clock.
+ *
+ * <hr>$Revision: 45089 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+#define BDK_GTI_RATE 100000000ull
+
+/**
+ * Enumeration of different Clocks.
+ */
+typedef enum{
+ BDK_CLOCK_TIME, /**< Clock for telling time with fast access. Uses GTI in core */
+ BDK_CLOCK_MAIN_REF, /**< Main reference clock */
+ BDK_CLOCK_RCLK, /**< Clock used by cores, coherent bus and L2 cache. */
+ BDK_CLOCK_SCLK, /**< Clock used by IO blocks. */
+} bdk_clock_t;
+
+/**
+ * Called in __bdk_init to setup the global timer
+ */
+extern void bdk_clock_setup();
+
+/**
+ * Get cycle count based on the clock type.
+ *
+ * @param clock - Enumeration of the clock type.
+ * @return - Get the number of cycles executed so far.
+ */
+static inline uint64_t bdk_clock_get_count(bdk_clock_t clock) __attribute__ ((always_inline));
+static inline uint64_t bdk_clock_get_count(bdk_clock_t clock)
+{
+ extern uint64_t __bdk_clock_get_count_slow(bdk_clock_t clock);
+ if (clock == BDK_CLOCK_TIME)
+ {
+ uint64_t clk;
+ BDK_MRS(CNTPCT_EL0, clk);
+ return clk;
+ }
+ else
+ return __bdk_clock_get_count_slow(clock);
+}
+
+/**
+ * Get clock rate based on the clock type.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special value.
+ * @param clock - Enumeration of the clock type.
+ * @return - return the clock rate.
+ */
+static inline uint64_t bdk_clock_get_rate(bdk_node_t node, bdk_clock_t clock) __attribute__ ((always_inline, pure));
+static inline uint64_t bdk_clock_get_rate(bdk_node_t node, bdk_clock_t clock)
+{
+ extern uint64_t __bdk_clock_get_rate_slow(bdk_node_t node, bdk_clock_t clock) __attribute__ ((pure));
+ if (clock == BDK_CLOCK_TIME)
+ return BDK_GTI_RATE; /* Programed as part of setup */
+ else
+ return __bdk_clock_get_rate_slow(node, clock);
+}
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-config.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-config.h
new file mode 100644
index 0000000000..6848fd687c
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-config.h
@@ -0,0 +1,357 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Functions for controlling the system configuration.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+#define BDK_CONFIG_MANUFACTURING_ADDRESS 0xff0000 /* 16MB - 64KB */
+
+typedef enum
+{
+ /* Board manufacturing data */
+ BDK_CONFIG_BOARD_MODEL, /* No parameters */
+ BDK_CONFIG_BOARD_REVISION, /* No parameters */
+ BDK_CONFIG_BOARD_SERIAL, /* No parameters */
+ BDK_CONFIG_MAC_ADDRESS, /* No parameters */
+ BDK_CONFIG_MAC_ADDRESS_NUM, /* No parameters */
+ BDK_CONFIG_MAC_ADDRESS_NUM_OVERRIDE, /* No parameters */
+
+ /* Board generic */
+ BDK_CONFIG_BMC_TWSI, /* No parameters */
+ BDK_CONFIG_WATCHDOG_TIMEOUT, /* No parameters */
+ BDK_CONFIG_TWSI_WRITE, /* Parameters: Write number */
+ BDK_CONFIG_MDIO_WRITE, /* Parameters: Write number */
+
+ /* Board wiring of network ports and PHYs */
+ BDK_CONFIG_PHY_ADDRESS, /* Parameters: Node, Interface, Port */
+ BDK_CONFIG_BGX_ENABLE, /* Parameters: Node, BGX, Port */
+ /* Non-EBB specific SFF8104 board and alike */
+ BDK_CONFIG_AQUANTIA_PHY, /* Parameters: Node, BGX, Port */
+
+ /* BDK Configuration params */
+ BDK_CONFIG_VERSION,
+ BDK_CONFIG_NUM_PACKET_BUFFERS,
+ BDK_CONFIG_PACKET_BUFFER_SIZE,
+ BDK_CONFIG_SHOW_LINK_STATUS,
+ BDK_CONFIG_COREMASK,
+ BDK_CONFIG_BOOT_MENU_TIMEOUT,
+ BDK_CONFIG_BOOT_PATH_OPTION,
+ BDK_CONFIG_BOOT_NEXT_STAGE,
+ BDK_CONFIG_TRACE,
+
+ /* Chip feature items */
+ BDK_CONFIG_MULTI_NODE, /* No parameters */
+ BDK_CONFIG_PCIE_EA, /* No parameters */
+ BDK_CONFIG_PCIE_ORDERING, /* No parameters */
+ BDK_CONFIG_PCIE_PRESET_REQUEST_VECTOR, /* Parameters: Node, Port */
+ BDK_CONFIG_PCIE_WIDTH, /* Parameters: Node, Port */
+ BDK_CONFIG_PCIE_PHYSICAL_SLOT, /* Parameters: Node, Port */
+ BDK_CONFIG_PCIE_FLASH, /* Parameters: Node, Port */
+ BDK_CONFIG_CCPI_LANE_REVERSE, /* No parameters */
+ BDK_CONFIG_CHIP_SKU, /* Parameter: Node */
+ BDK_CONFIG_CHIP_SERIAL, /* Parameter: Node */
+ BDK_CONFIG_CHIP_UNIQUE_ID, /* Parameter: Node */
+
+ /* QLM related config */
+ BDK_CONFIG_QLM_AUTO_CONFIG, /* Parameters: Node */
+ /* SFF8104 related QLM config */
+ BDK_CONFIG_QLM_DIP_AUTO_CONFIG, /* Parameters: Node */
+ BDK_CONFIG_QLM_MODE, /* Parameters: Node, QLM */
+ BDK_CONFIG_QLM_FREQ, /* Parameters: Node, QLM */
+ BDK_CONFIG_QLM_CLK, /* Parameters: Node, QLM */
+ BDK_CONFIG_QLM_TUNING_TX_SWING, /* Parameters: Node, QLM, Lane */
+ BDK_CONFIG_QLM_TUNING_TX_PREMPTAP, /* Parameters: Node, QLM, Lane */
+ BDK_CONFIG_QLM_TUNING_TX_GAIN, /* Parameters: Node, QLM, Lane */
+ BDK_CONFIG_QLM_TUNING_TX_VBOOST, /* Parameters: Node, QLM, Lane */
+ BDK_CONFIG_QLM_CHANNEL_LOSS, /* Parameters: Node, QLM */
+
+ /* DRAM configuration options */
+ BDK_CONFIG_DDR_SPEED, /* Parameters: Node */
+ BDK_CONFIG_DDR_ALT_REFCLK, /* Parameters: Node */
+ BDK_CONFIG_DDR_SPD_ADDR, /* Parameters: DIMM, LMC, Node */
+ BDK_CONFIG_DDR_SPD_DATA, /* Parameters: DIMM, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_DQX_CTL, /* Parameters: Num Ranks, Num DIMMs, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_WODT_MASK, /* Parameters: Num Ranks, Num DIMMs, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE1_PASR, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE1_ASR, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE1_SRT, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE1_RTT_WR, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE1_DIC, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE1_RTT_NOM, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE1_DB_OUTPUT_IMPEDANCE, /* Parameters: Num Ranks, Num DIMMs, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE2_RTT_PARK, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE2_VREF_VALUE, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE2_VREF_RANGE, /* Parameters: Num Ranks, Num DIMMs, Rank, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_MODE2_VREFDQ_TRAIN_EN, /* Parameters: Num Ranks, Num DIMMs, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_RODT_CTL, /* Parameters: Num Ranks, Num DIMMs, LMC, Node */
+ BDK_CONFIG_DDR_RANKS_RODT_MASK, /* Parameters: Num Ranks, Num DIMMs, LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MIN_RTT_NOM_IDX, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MAX_RTT_NOM_IDX, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MIN_RODT_CTL, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MAX_RODT_CTL, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_CK_CTL, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_CMD_CTL, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_CTL_CTL, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MIN_CAS_LATENCY, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_OFFSET_EN, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_OFFSET, /* Parameters: Type(UDIMM,RDIMM), LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_RLEVEL_COMPUTE, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_RLEVEL_COMP_OFFSET, /* Parameters: Type(UDIMM,RDIMM), LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_DDR2T, /* Parameters: Type(UDIMM,RDIMM), LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_DISABLE_SEQUENTIAL_DELAY_CHECK, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MAXIMUM_ADJACENT_RLEVEL_DELAY_INCREMENT, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_PARITY, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_FPRCH2, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MODE32B, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_MEASURED_VREF, /* Parameters: LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_DLL_WRITE_OFFSET, /* Parameters: Byte, LMC, Node */
+ BDK_CONFIG_DDR_CUSTOM_DLL_READ_OFFSET, /* Parameters: Byte, LMC, Node */
+
+ /* High level DRAM options */
+ BDK_CONFIG_DRAM_VERBOSE, /* Parameters: Node */
+ BDK_CONFIG_DRAM_BOOT_TEST, /* Parameters: Node */
+ BDK_CONFIG_DRAM_CONFIG_GPIO, /* No parameters */
+ BDK_CONFIG_DRAM_SCRAMBLE, /* No parameters */
+
+ /* USB */
+ BDK_CONFIG_USB_PWR_GPIO, /* Parameters: Node, Port */
+ BDK_CONFIG_USB_PWR_GPIO_POLARITY, /* Parameters: Node, Port */
+ BDK_CONFIG_USB_REFCLK_SRC, /* Parameters: Node, Port */
+
+ /* Nitrox reset - For CN88XX SC and SNT part. High drives Nitrox DC_OK high */
+ BDK_CONFIG_NITROX_GPIO, /* Parameters: Node */
+
+ /* How EYE diagrams are captured from a QLM */
+ BDK_CONFIG_EYE_ZEROS, /* No parameters */
+ BDK_CONFIG_EYE_SAMPLE_TIME, /* No parameters */
+ BDK_CONFIG_EYE_SETTLE_TIME, /* No parameters */
+
+ /* SGPIO */
+ BDK_CONFIG_SGPIO_SCLOCK_FREQ, /* Parameters: Node */
+ BDK_CONFIG_SGPIO_PIN_POWER, /* Parameters: Node */
+ BDK_CONFIG_SGPIO_PIN_SCLOCK, /* Parameters: Node */
+ BDK_CONFIG_SGPIO_PIN_SLOAD, /* Parameters: Node */
+ BDK_CONFIG_SGPIO_PIN_SDATAOUT, /* Parameters: Node, Dataline */
+
+ /* VRM temperature throttling */
+ BDK_CONFIG_VRM_TEMP_TRIP, /* Parameters: Node */
+ BDK_CONFIG_VRM_TEMP_HIGH, /* Parameters: Node */
+ BDK_CONFIG_VRM_TEMP_LOW, /* Parameters: Node */
+ BDK_CONFIG_VRM_THROTTLE_NORMAL, /* Parameters: Node */
+ BDK_CONFIG_VRM_THROTTLE_THERM, /* Parameters: Node */
+
+ /* Generic GPIO, unrelated to a specific block */
+ BDK_CONFIG_GPIO_PIN_SELECT, /* Parameters: GPIO, Node */
+ BDK_CONFIG_GPIO_POLARITY, /* Parameters: GPIO, Node */
+
+ /* PBUS */
+ BDK_CONFIG_PBUS_CFG, /* Parameters: Region, Node */
+ BDK_CONFIG_PBUS_TIM, /* Parameters: Region, Node */
+
+ /* Trusted boot information */
+ BDK_CONFIG_TRUST_CSIB, /* No parameters */
+ BDK_CONFIG_TRUST_ROT_ADDR, /* No parameters */
+ BDK_CONFIG_TRUST_BSSK_ADDR, /* No parameters */
+
+ __BDK_CONFIG_END
+} bdk_config_t;
+
+/**
+ * Internal BDK function to initialize the config system. Must be called before
+ * any configuration functions are called
+ */
+extern void __bdk_config_init(void);
+
+/**
+ * Return a help string for the given configuration parameter
+ *
+ * @param cfg_item Configuration parameter to get help for
+ *
+ * @return Help string for the user
+ */
+extern const char *bdk_config_get_help(bdk_config_t cfg_item);
+
+/**
+ * Get an integer configuration item
+ *
+ * @param cfg_item Config item to get. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ *
+ * @return The value of the configuration item, or def_value if the item is not set
+ */
+extern int64_t bdk_config_get_int(bdk_config_t cfg_item, ...);
+
+/**
+ * Get a string configuration item
+ *
+ * @param cfg_item Config item to get. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ *
+ * @return The value of the configuration item, or def_value if the item is not set
+ */
+extern const char *bdk_config_get_str(bdk_config_t cfg_item, ...);
+
+/**
+ * Get a binary blob
+ *
+ * @param blob_size Integer to receive the size of the blob
+ * @param cfg_item Config item to get. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ *
+ * @return The value of the configuration item, or def_value if the item is not set
+ */
+extern const void *bdk_config_get_blob(int *blob_size, bdk_config_t cfg_item, ...);
+
+/**
+ * Set an integer configuration item. Note this only sets the item in memory,
+ * persistent storage is not updated. The optional parameters for the setting are
+ * not supplied, meaning this function only changes the global default.
+ *
+ * @param value Configuration item value
+ * @param cfg_item Config item to set. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ */
+extern void bdk_config_set_int_no_param(int64_t value, bdk_config_t cfg_item);
+
+/**
+ * Set an integer configuration item. Note this only sets the item in memory,
+ * persistent storage is not updated.
+ *
+ * @param value Configuration item value
+ * @param cfg_item Config item to set. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ */
+extern void bdk_config_set_int(int64_t value, bdk_config_t cfg_item, ...);
+
+/**
+ * Set an integer configuration item. Note this only sets the item in memory,
+ * persistent storage is not updated.
+ *
+ * @param value Configuration item value
+ * @param cfg_item Config item to set. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ */
+extern void bdk_config_set_str(const char *value, bdk_config_t cfg_item, ...);
+
+/**
+ * Set a blob configuration item. Note this only sets the
+ * item in memory, persistent storage is not updated. The optional
+ * parameters for the setting are not supplied, meaning this function
+ * only changes the global default.
+ *
+ * @param size Size of the item in bytes. A size of zero removes the device tree field
+ * @param value Configuration item value
+ * @param cfg_item Config item to set. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ */
+extern void bdk_config_set_blob_no_param(int size, const void *value, bdk_config_t cfg_item);
+
+/**
+ * Set a blob configuration item. Note this only sets the
+ * item in memory, persistent storage is not updated.
+ *
+ * @param size Size of the item in bytes. A size of zero removes the device tree field
+ * @param value Configuration item value
+ * @param cfg_item Config item to set. If the item takes parameters (see bdk_config_t), then the
+ * parameters are listed following cfg_item.
+ */
+extern void bdk_config_set_blob(int size, const void *value, bdk_config_t cfg_item, ...);
+
+/**
+ * Display the active configuration
+ */
+extern void bdk_config_show(void);
+
+/**
+ * Display a list of all posssible config items with help text
+ */
+extern void bdk_config_help(void);
+
+/**
+ * Save the current configuration to flash
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_config_save(void);
+
+/**
+ * Takes the current live device tree and exports it to a memory address suitable
+ * for passing to the next binary in register X1.
+ *
+ * @return Physical address of the device tree, or 0 on failure
+ */
+extern uint64_t __bdk_config_export_to_mem(void);
+
+/**
+ * Return a pointer to the device tree used for configuration
+ *
+ * @return FDT or NULL on failure
+ */
+extern void* bdk_config_get_fdt(void);
+
+/**
+ * Set the device tree used for configuration
+ *
+ * @param fdt Device tree to use. Memory is assumed to be from malloc() and bdk_config takes
+ * over ownership on success
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_config_set_fdt(void *fdt);
+
+/**
+ * Write all default values to a FDT. Missing config items get defaults in the
+ * BDK config, this function adds those defaults to the FDT. This way other code
+ * gets the default value without needing special code.
+ *
+ * @param fdt FDT structure to fill defaults into
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_config_expand_defaults(void *fdt);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-crc.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-crc.h
new file mode 100644
index 0000000000..05fc59a378
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-crc.h
@@ -0,0 +1,53 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Module to support CRC.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+uint32_t bdk_crc32(const void *ptr, int len, uint32_t iv);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-ecam.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-ecam.h
new file mode 100644
index 0000000000..3f90d11dc2
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-ecam.h
@@ -0,0 +1,97 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the ECAMs.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Read from an ECAM
+ *
+ * @param device Device to read from
+ * @param reg Register to read
+ *
+ * @return Result of the read of -1 on failure
+ */
+extern uint32_t bdk_ecam_read32(const bdk_device_t *device, int reg);
+
+/**
+ * Write to an ECAM register
+ *
+ * @param device Device to write to
+ * @param reg Register to write
+ * @param value Value to write
+ */
+extern void bdk_ecam_write32(const bdk_device_t *device, int reg, uint32_t value);
+
+/**
+ * Build an ECAM config space request address for a device
+ *
+ * @param device Device being accessed
+ * @param reg Register to access
+ *
+ * @return 64bit IO address
+ */
+extern uint64_t __bdk_ecam_build_address(const bdk_device_t *device, int reg);
+
+/**
+ * Return the number of internal ECAMS on a node.
+ *
+ * @param node Node to query
+ *
+ * @return Number of ECAMs available
+ */
+extern int bdk_ecam_get_num(bdk_node_t node);
+
+/**
+ * Scan all ECAMs for devices and add them to bdk-device
+ *
+ * @param node Node to scan
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_ecam_scan_all(bdk_node_t node) BDK_WEAK;
+
+/** @} */
+
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-error-report.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-error-report.h
new file mode 100644
index 0000000000..520780fa0a
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-error-report.h
@@ -0,0 +1,62 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to hardware error reporting.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Call this function to check if any error interrupts are
+ * set in the chip.
+ */
+extern void (*bdk_error_check)(bdk_node_t node) BDK_WEAK;
+
+/**
+ * Call this function to setup error enables.
+ */
+extern void bdk_error_enable(bdk_node_t node) BDK_WEAK;
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-fpa.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-fpa.h
new file mode 100644
index 0000000000..8094cd0fa0
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-fpa.h
@@ -0,0 +1,162 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the hardware Free Pool Allocator.
+ *
+ * @addtogroup hal
+ * @{
+ */
+#define BDK_FPA_NUM_AURAS 128 /* Must not be bigger than FPA_CONST[auras] or NPA_AF_LFX_AURAS_CFG[loc_aura_size] */
+
+/**
+ * This enum represents the FPA hardware pools in use by the BDK
+ */
+typedef enum
+{
+ BDK_FPA_PACKET_POOL, /* Stores PKI packet buffers */
+ BDK_FPA_SSO_POOL, /* Used for internal storage in the SSO, CN83XX and CN9XXX */
+ BDK_FPA_PKO_POOL, /* Used for queue storage in the CN83XX PKO and CN9XXX SQB */
+ BDK_FPA_NUM_POOLS = 16 /* Can be 16, or 32 for CN83XX. Must not be bigger than FPA_CONST[pools] */
+} bdk_fpa_pool_t;
+
+/**
+ * Structure representing the global state of the FPA
+ */
+typedef struct
+{
+ uint16_t buffer_size_pool[BDK_FPA_NUM_POOLS];
+ uint16_t buffer_size_aura[BDK_FPA_NUM_AURAS];
+ int next_free_aura;
+ int next_free_lf; /* Used on CN9XXX for RVU PF allocation */
+ void *npa_auras_ptr; /* Pointer to Aura Context Table: BDK_FPA_NUM_AURAS * (Aura HW context) */
+ void *npa_pools_ptr; /* Pointer to Pool Context Table: BDK_FPA_NUM_POOLS * (Pool HW context) */
+} __bdk_fpa_state_t;
+
+extern __bdk_fpa_state_t __bdk_fpa_node_state[BDK_NUMA_MAX_NODES];
+
+/**
+ * Get a new block from an aura
+ *
+ * @param node Node to use in a Numa setup. See bdk-numa.h
+ * @param aura Aura to get the block from (0-BDK_FPA_NUM_AURAS)
+ *
+ * @return Pointer to the block or NULL on failure
+ */
+extern void* (*bdk_fpa_alloc)(bdk_node_t node, int aura);
+
+/**
+ * Free a block allocated with bdk_fpa_alloc(). Does NOT provide memory ordering
+ * for core stores. Software must insure all pending writes are flushed before
+ * calling this function.
+ *
+ * @param node Node to use in a Numa setup. See bdk-numa.h
+ * @param address Physical address to free to the FPA aura
+ * @param aura Aura number to free to (0-BDK_FPA_NUM_AURAS)
+ * @param num_cache_lines
+ * Cache lines to invalidate. Use this if the data in the buffer is no longer
+ * requires cache coherency. Normally best to set this to zero.
+ */
+extern void (*__bdk_fpa_raw_free)(bdk_node_t node, uint64_t address, int aura, int num_cache_lines);
+
+/**
+ * Fill a pool with buffers
+ *
+ * @param node Node to use in a Numa setup. See bdk-numa.h
+ * @param pool Pool to initialize (0 <= pool < BDK_FPA_NUM_POOLS)
+ * @param num_blocks Number of blocks
+ *
+ * @return Zero on Success, negative on failure
+ */
+extern int (*bdk_fpa_fill_pool)(bdk_node_t node, bdk_fpa_pool_t pool, int num_blocks);
+
+/**
+ * Initialize an Aura for a specific pool
+ *
+ * @param node Node to use in a Numa setup. See bdk-numa.h
+ * @param aura Aura to initialize, or -1 to dynamically allocate a free aura
+ * @param pool Pool this aura is for (0 <= pool < BDK_FPA_NUM_POOLS)
+ * @param num_blocks Number of buffers to allow this aura to contain. This may be different
+ * from the pool
+ *
+ * @return Aura number or negative on failure
+ */
+extern int (*bdk_fpa_init_aura)(bdk_node_t node, int aura, bdk_fpa_pool_t pool, int num_blocks);
+
+/**
+ * Free a block allocated with bdk_fpa_alloc(). Provides memory ordering
+ * for core stores.
+ *
+ * @param node Node to use in a Numa setup. See bdk-numa.h
+ * @param ptr Pointer to the block to free
+ * @param aura Aura number to free to (0-BDK_FPA_NUM_AURAS)
+ * @param num_cache_lines
+ * Cache lines to invalidate. Use this if the data in the buffer is no longer
+ * requires cache coherency. Normally best to set this to zero.
+ */
+static inline void bdk_fpa_free(bdk_node_t node, void *ptr, int aura, int num_cache_lines)
+{
+ BDK_WMB;
+ __bdk_fpa_raw_free(node, bdk_ptr_to_phys(ptr), aura, num_cache_lines);
+}
+
+/**
+ * Get the size of blocks controlled by the aura
+ *
+ * @param node Node to use in a Numa setup. See bdk-numa.h
+ * @param aura Aura number to access (0-BDK_FPA_NUM_AURAS)
+ *
+ * @return Size of the block in bytes
+ */
+static inline int bdk_fpa_get_block_size(bdk_node_t node, int aura)
+{
+ __bdk_fpa_state_t *fpa_state = &__bdk_fpa_node_state[node];
+ return fpa_state->buffer_size_aura[aura];
+}
+
+/**
+ * Global FPA initialization
+ *
+ * @return Zero on success, negative on failure
+ */
+int bdk_fpa_init(bdk_node_t node);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-gpio.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-gpio.h
new file mode 100644
index 0000000000..8be3a4c1ad
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-gpio.h
@@ -0,0 +1,111 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * General Purpose IO interface.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+
+/**
+ * Initialize a single GPIO as either an input or output. If it is
+ * an output, also set its output value.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param gpio GPIO to initialize
+ * @param is_output Non zero if this GPIO should be an output
+ * @param output_value
+ * Value of the GPIO if it should be an output. Not used if the
+ * GPIO isn't an output.
+ *
+ * @return Zero on success, negative ob failure
+ */
+extern int bdk_gpio_initialize(bdk_node_t node, int gpio, int is_output, int output_value);
+
+/**
+ * GPIO Read Data
+ *
+ * @param node Node GPIO block is on
+ * @param gpio_block GPIO block to access. Each block contains up to 64 GPIOs
+ *
+ * @return Status of the GPIO pins for the given block
+ */
+extern uint64_t bdk_gpio_read(bdk_node_t node, int gpio_block);
+
+/**
+ * GPIO Clear pin
+ *
+ * @param node Node GPIO block is on
+ * @param gpio_block GPIO block to access. Each block contains up to 64 GPIOs
+ * @param clear_mask Bit mask to indicate which bits to drive to '0'.
+ */
+extern void bdk_gpio_clear(bdk_node_t node, int gpio_block, uint64_t clear_mask);
+
+/**
+ * GPIO Set pin
+ *
+ * @param node Node GPIO block is on
+ * @param gpio_block GPIO block to access. Each block contains up to 64 GPIOs
+ * @param set_mask Bit mask to indicate which bits to drive to '1'.
+ */
+extern void bdk_gpio_set(bdk_node_t node, int gpio_block, uint64_t set_mask);
+
+/** GPIO Select pin
+ *
+ * @param node CPU node
+ * @param gpio GPIO number
+ * @param pin Pin number
+ */
+extern void bdk_gpio_select_pin(bdk_node_t node, int gpio, int pin);
+
+/**
+ * Return the number of GPIO pins on this chip
+ *
+ * @return Number of GPIO pins
+ */
+extern int bdk_gpio_get_num(void);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-hal.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-hal.h
new file mode 100644
index 0000000000..458ffede7c
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-hal.h
@@ -0,0 +1,98 @@
+#ifndef __BDK_HAL_H__
+#define __BDK_HAL_H__
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Master include file for hardware support. Use bdk.h instead
+ * of including this file directly.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @defgroup hal Hardware abstraction layer
+ */
+
+/* Global define to control if the BDK configures units to send
+ don't write back requests for freed buffers. Set to 1 to enable
+ DWB, 0 to disable them. As the BDK normally fits inside L2, sending
+ DWB just causes more L2 operations without benefit */
+#define BDK_USE_DWB 0
+
+#include "bdk-access.h"
+#include "bdk-utils.h"
+#include "bdk-config.h"
+#include "bdk-atomic.h"
+#include "bdk-spinlock.h"
+#include "bdk-rvu.h"
+#include "bdk-clock.h"
+#include "bdk-crc.h"
+#include "bdk-error-report.h"
+#include "bdk-gpio.h"
+#include "device/bdk-device.h"
+#include "if/bdk-if.h"
+#include "usb/bdk-usb-xhci-intf.h"
+#include "bdk-ecam.h"
+#include "bdk-fpa.h"
+#include "bdk-pbus-flash.h"
+#include "bdk-pki.h"
+#include "bdk-pko.h"
+#include "bdk-power-burn.h"
+#include "bdk-sso.h"
+#include "bdk-nic.h"
+#include "bdk-nix.h"
+#include "bdk-key.h"
+#include "bdk-l2c.h"
+#include "bdk-mdio.h"
+#include "bdk-mpi.h"
+#include "bdk-mmc.h"
+#include "bdk-pcie.h"
+#include "bdk-pcie-flash.h"
+#include "bdk-qlm.h"
+#include "qlm/bdk-qlm-errata-cn8xxx.h"
+#include "bdk-rng.h"
+#include "bdk-sata.h"
+#include "bdk-twsi.h"
+#include "bdk-usb.h"
+#include "bdk-access-native.h"
+#include "bdk-tns.h"
+#include "bdk-vrm.h"
+#include "aq_api/bdk-aqr-support.h"
+#endif
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-key.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-key.h
new file mode 100644
index 0000000000..c16bfd7559
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-key.h
@@ -0,0 +1,86 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the on chip key memory. Key memory is
+ * 8k on chip that is inaccessible from off chip. It can
+ * also be cleared using an external hardware pin.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+#define BDK_KEY_MEM_SIZE 8192 /* Size in bytes */
+
+/**
+ * Read from KEY memory
+ *
+ * @param node Which node to use
+ * @param address Address (byte) in key memory to read
+ * 0 <= address < BDK_KEY_MEM_SIZE
+ * @return Value from key memory
+ */
+extern uint64_t bdk_key_read(bdk_node_t node, uint64_t address);
+
+/**
+ * Write to KEY memory
+ *
+ * @param node Which node to use
+ * @param address Address (byte) in key memory to write
+ * 0 <= address < BDK_KEY_MEM_SIZE
+ * @param value Value to write to key memory
+ */
+extern void bdk_key_write(bdk_node_t node, uint64_t address, uint64_t value);
+
+/**
+ * Allocate an area in key memory for storing data. Return a pointer to the
+ * memory on success.
+ *
+ * @param node Node to allocate on
+ * @param size_bytes Number of bytes to allocate
+ *
+ * @return Pointer to key memory, or NULL on failure
+ */
+extern void* bdk_key_alloc(bdk_node_t node, int size_bytes);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-l2c.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-l2c.h
new file mode 100644
index 0000000000..cf14357f83
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-l2c.h
@@ -0,0 +1,179 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the Level 2 Cache (L2C) control, measurement, and debugging
+ * facilities.
+ *
+ * <hr>$Revision: 50663 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Perform one time initialization of L2 for improved
+ * performance. This can be called after L2 is in use.
+ *
+ * @return Zero on success, negative on failure.
+ */
+int bdk_l2c_initialize(bdk_node_t node);
+
+/**
+ * Return the L2 Cache way partitioning for a given core.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param core The core processor of interest.
+ *
+ * @return The mask specifying the partitioning. 0 bits in mask indicates
+ * the cache 'ways' that a core can evict from.
+ * -1 on error
+ */
+int bdk_l2c_get_core_way_partition(bdk_node_t node, int core);
+
+/**
+ * Partitions the L2 cache for a core
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param core The core that the partitioning applies to.
+ * @param mask The partitioning of the ways expressed as a binary mask. A 0 bit allows the core
+ * to evict cache lines from a way, while a 1 bit blocks the core from evicting any lines
+ * from that way. There must be at least one allowed way (0 bit) in the mask.
+ *
+ * @note If any ways are blocked for all cores and the HW blocks, then those ways will never have
+ * any cache lines evicted from them. All cores and the hardware blocks are free to read from
+ * all ways regardless of the partitioning.
+ */
+int bdk_l2c_set_core_way_partition(bdk_node_t node, int core, uint32_t mask);
+
+/**
+ * Return the L2 Cache way partitioning for the hw blocks.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special value.
+ * @return The mask specifying the reserved way. 0 bits in mask indicates
+ * the cache 'ways' that a core can evict from.
+ * -1 on error
+ */
+int bdk_l2c_get_hw_way_partition(bdk_node_t node);
+
+/**
+ * Partitions the L2 cache for the hardware blocks.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param mask The partitioning of the ways expressed as a binary mask. A 0 bit allows the core
+ * to evict cache lines from a way, while a 1 bit blocks the core from evicting any lines
+ * from that way. There must be at least one allowed way (0 bit) in the mask.
+ *
+ * @note If any ways are blocked for all cores and the HW blocks, then those ways will never have
+ * any cache lines evicted from them. All cores and the hardware blocks are free to read from
+ * all ways regardless of the partitioning.
+ */
+int bdk_l2c_set_hw_way_partition(bdk_node_t node, uint32_t mask);
+
+/**
+ * Locks a specified memory region in the L2 cache.
+ *
+ * Note that if not all lines can be locked, that means that all
+ * but one of the ways (associations) available to the locking
+ * core are locked. Having only 1 association available for
+ * normal caching may have a significant adverse affect on performance.
+ * Care should be taken to ensure that enough of the L2 cache is left
+ * unlocked to allow for normal caching of DRAM.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param start Physical address of the start of the region to lock
+ * @param len Length (in bytes) of region to lock
+ *
+ * @return Number of requested lines that where not locked.
+ * 0 on success (all locked)
+ */
+int bdk_l2c_lock_mem_region(bdk_node_t node, uint64_t start, uint64_t len);
+
+/**
+ * Unlocks a region of memory that is locked in the L2 cache
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param start start physical address
+ * @param len length (in bytes) to unlock
+ *
+ * @return Number of locked lines that the call unlocked
+ */
+int bdk_l2c_unlock_mem_region(bdk_node_t node, uint64_t start, uint64_t len);
+
+/**
+ * Flushes (and unlocks) the entire L2 cache.
+ */
+void bdk_l2c_flush(bdk_node_t node);
+
+/**
+ *
+ * @return Returns the size of the L2 cache in bytes,
+ * -1 on error (unrecognized model)
+ */
+int bdk_l2c_get_cache_size_bytes(bdk_node_t node);
+
+/**
+ * Return the number of sets in the L2 Cache
+ *
+ * @return
+ */
+int bdk_l2c_get_num_sets(bdk_node_t node);
+
+/**
+ * Return the number of associations in the L2 Cache
+ *
+ * @return
+ */
+int bdk_l2c_get_num_assoc(bdk_node_t node);
+
+/**
+ * Return true if the BDK has locked itself in L2
+ *
+ * @return
+ */
+int bdk_l2c_is_locked(bdk_node_t node);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mdio.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mdio.h
new file mode 100644
index 0000000000..889f8d5d56
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mdio.h
@@ -0,0 +1,476 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the SMI/MDIO hardware, including support for both IEEE 802.3
+ * clause 22 and clause 45 operations.
+ *
+ * <hr>$Revision: 51350 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * PHY register 0 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_CONTROL 0
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t reset : 1;
+ uint16_t loopback : 1;
+ uint16_t speed_lsb : 1;
+ uint16_t autoneg_enable : 1;
+ uint16_t power_down : 1;
+ uint16_t isolate : 1;
+ uint16_t restart_autoneg : 1;
+ uint16_t duplex : 1;
+ uint16_t collision_test : 1;
+ uint16_t speed_msb : 1;
+ uint16_t unidirectional_enable : 1;
+ uint16_t reserved_0_4 : 5;
+#else
+ uint16_t reserved_0_4 : 5;
+ uint16_t unidirectional_enable : 1;
+ uint16_t speed_msb : 1;
+ uint16_t collision_test : 1;
+ uint16_t duplex : 1;
+ uint16_t restart_autoneg : 1;
+ uint16_t isolate : 1;
+ uint16_t power_down : 1;
+ uint16_t autoneg_enable : 1;
+ uint16_t speed_lsb : 1;
+ uint16_t loopback : 1;
+ uint16_t reset : 1;
+#endif
+ } s;
+} bdk_mdio_phy_reg_control_t;
+
+/**
+ * PHY register 1 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_STATUS 1
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t capable_100base_t4 : 1;
+ uint16_t capable_100base_x_full : 1;
+ uint16_t capable_100base_x_half : 1;
+ uint16_t capable_10_full : 1;
+ uint16_t capable_10_half : 1;
+ uint16_t capable_100base_t2_full : 1;
+ uint16_t capable_100base_t2_half : 1;
+ uint16_t capable_extended_status : 1;
+ uint16_t capable_unidirectional : 1;
+ uint16_t capable_mf_preamble_suppression : 1;
+ uint16_t autoneg_complete : 1;
+ uint16_t remote_fault : 1;
+ uint16_t capable_autoneg : 1;
+ uint16_t link_status : 1;
+ uint16_t jabber_detect : 1;
+ uint16_t capable_extended_registers : 1;
+#else
+ uint16_t capable_extended_registers : 1;
+ uint16_t jabber_detect : 1;
+ uint16_t link_status : 1;
+ uint16_t capable_autoneg : 1;
+ uint16_t remote_fault : 1;
+ uint16_t autoneg_complete : 1;
+ uint16_t capable_mf_preamble_suppression : 1;
+ uint16_t capable_unidirectional : 1;
+ uint16_t capable_extended_status : 1;
+ uint16_t capable_100base_t2_half : 1;
+ uint16_t capable_100base_t2_full : 1;
+ uint16_t capable_10_half : 1;
+ uint16_t capable_10_full : 1;
+ uint16_t capable_100base_x_half : 1;
+ uint16_t capable_100base_x_full : 1;
+ uint16_t capable_100base_t4 : 1;
+#endif
+ } s;
+} bdk_mdio_phy_reg_status_t;
+
+/**
+ * PHY register 2 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_ID1 2
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+ uint16_t oui_bits_3_18;
+ } s;
+} bdk_mdio_phy_reg_id1_t;
+
+/**
+ * PHY register 3 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_ID2 3
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t oui_bits_19_24 : 6;
+ uint16_t model : 6;
+ uint16_t revision : 4;
+#else
+ uint16_t revision : 4;
+ uint16_t model : 6;
+ uint16_t oui_bits_19_24 : 6;
+#endif
+ } s;
+} bdk_mdio_phy_reg_id2_t;
+
+/**
+ * PHY register 4 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_AUTONEG_ADVER 4
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t next_page : 1;
+ uint16_t reserved_14 : 1;
+ uint16_t remote_fault : 1;
+ uint16_t reserved_12 : 1;
+ uint16_t asymmetric_pause : 1;
+ uint16_t pause : 1;
+ uint16_t advert_100base_t4 : 1;
+ uint16_t advert_100base_tx_full : 1;
+ uint16_t advert_100base_tx_half : 1;
+ uint16_t advert_10base_tx_full : 1;
+ uint16_t advert_10base_tx_half : 1;
+ uint16_t selector : 5;
+#else
+ uint16_t selector : 5;
+ uint16_t advert_10base_tx_half : 1;
+ uint16_t advert_10base_tx_full : 1;
+ uint16_t advert_100base_tx_half : 1;
+ uint16_t advert_100base_tx_full : 1;
+ uint16_t advert_100base_t4 : 1;
+ uint16_t pause : 1;
+ uint16_t asymmetric_pause : 1;
+ uint16_t reserved_12 : 1;
+ uint16_t remote_fault : 1;
+ uint16_t reserved_14 : 1;
+ uint16_t next_page : 1;
+#endif
+ } s;
+} bdk_mdio_phy_reg_autoneg_adver_t;
+
+/**
+ * PHY register 5 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_LINK_PARTNER_ABILITY 5
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t next_page : 1;
+ uint16_t ack : 1;
+ uint16_t remote_fault : 1;
+ uint16_t reserved_12 : 1;
+ uint16_t asymmetric_pause : 1;
+ uint16_t pause : 1;
+ uint16_t advert_100base_t4 : 1;
+ uint16_t advert_100base_tx_full : 1;
+ uint16_t advert_100base_tx_half : 1;
+ uint16_t advert_10base_tx_full : 1;
+ uint16_t advert_10base_tx_half : 1;
+ uint16_t selector : 5;
+#else
+ uint16_t selector : 5;
+ uint16_t advert_10base_tx_half : 1;
+ uint16_t advert_10base_tx_full : 1;
+ uint16_t advert_100base_tx_half : 1;
+ uint16_t advert_100base_tx_full : 1;
+ uint16_t advert_100base_t4 : 1;
+ uint16_t pause : 1;
+ uint16_t asymmetric_pause : 1;
+ uint16_t reserved_12 : 1;
+ uint16_t remote_fault : 1;
+ uint16_t ack : 1;
+ uint16_t next_page : 1;
+#endif
+ } s;
+} bdk_mdio_phy_reg_link_partner_ability_t;
+
+/**
+ * PHY register 6 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_AUTONEG_EXPANSION 6
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t reserved_5_15 : 11;
+ uint16_t parallel_detection_fault : 1;
+ uint16_t link_partner_next_page_capable : 1;
+ uint16_t local_next_page_capable : 1;
+ uint16_t page_received : 1;
+ uint16_t link_partner_autoneg_capable : 1;
+#else
+ uint16_t link_partner_autoneg_capable : 1;
+ uint16_t page_received : 1;
+ uint16_t local_next_page_capable : 1;
+ uint16_t link_partner_next_page_capable : 1;
+ uint16_t parallel_detection_fault : 1;
+ uint16_t reserved_5_15 : 11;
+#endif
+ } s;
+} bdk_mdio_phy_reg_autoneg_expansion_t;
+
+/**
+ * PHY register 9 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_CONTROL_1000 9
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t test_mode : 3;
+ uint16_t manual_master_slave : 1;
+ uint16_t master : 1;
+ uint16_t port_type : 1;
+ uint16_t advert_1000base_t_full : 1;
+ uint16_t advert_1000base_t_half : 1;
+ uint16_t reserved_0_7 : 8;
+#else
+ uint16_t reserved_0_7 : 8;
+ uint16_t advert_1000base_t_half : 1;
+ uint16_t advert_1000base_t_full : 1;
+ uint16_t port_type : 1;
+ uint16_t master : 1;
+ uint16_t manual_master_slave : 1;
+ uint16_t test_mode : 3;
+#endif
+ } s;
+} bdk_mdio_phy_reg_control_1000_t;
+
+/**
+ * PHY register 10 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_STATUS_1000 10
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t master_slave_fault : 1;
+ uint16_t is_master : 1;
+ uint16_t local_receiver_ok : 1;
+ uint16_t remote_receiver_ok : 1;
+ uint16_t remote_capable_1000base_t_full : 1;
+ uint16_t remote_capable_1000base_t_half : 1;
+ uint16_t reserved_8_9 : 2;
+ uint16_t idle_error_count : 8;
+#else
+ uint16_t idle_error_count : 8;
+ uint16_t reserved_8_9 : 2;
+ uint16_t remote_capable_1000base_t_half : 1;
+ uint16_t remote_capable_1000base_t_full : 1;
+ uint16_t remote_receiver_ok : 1;
+ uint16_t local_receiver_ok : 1;
+ uint16_t is_master : 1;
+ uint16_t master_slave_fault : 1;
+#endif
+ } s;
+} bdk_mdio_phy_reg_status_1000_t;
+
+/**
+ * PHY register 15 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_EXTENDED_STATUS 15
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t capable_1000base_x_full : 1;
+ uint16_t capable_1000base_x_half : 1;
+ uint16_t capable_1000base_t_full : 1;
+ uint16_t capable_1000base_t_half : 1;
+ uint16_t reserved_0_11 : 12;
+#else
+ uint16_t reserved_0_11 : 12;
+ uint16_t capable_1000base_t_half : 1;
+ uint16_t capable_1000base_t_full : 1;
+ uint16_t capable_1000base_x_half : 1;
+ uint16_t capable_1000base_x_full : 1;
+#endif
+ } s;
+} bdk_mdio_phy_reg_extended_status_t;
+
+
+/**
+ * PHY register 13 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_MMD_CONTROL 13
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint16_t function : 2;
+ uint16_t reserved_5_13 : 9;
+ uint16_t devad : 5;
+#else
+ uint16_t devad : 5;
+ uint16_t reserved_5_13 : 9;
+ uint16_t function : 2;
+#endif
+ } s;
+} bdk_mdio_phy_reg_mmd_control_t;
+
+/**
+ * PHY register 14 from the 802.3 spec
+ */
+#define BDK_MDIO_PHY_REG_MMD_ADDRESS_DATA 14
+typedef union
+{
+ uint16_t u16;
+ struct
+ {
+ uint16_t address_data : 16;
+ } s;
+} bdk_mdio_phy_reg_mmd_address_data_t;
+
+/* MMD identifiers, mostly for accessing devices within XENPAK modules. */
+#define BDK_MMD_DEVICE_PMA_PMD 1
+#define BDK_MMD_DEVICE_WIS 2
+#define BDK_MMD_DEVICE_PCS 3
+#define BDK_MMD_DEVICE_PHY_XS 4
+#define BDK_MMD_DEVICE_DTS_XS 5
+#define BDK_MMD_DEVICE_TC 6
+#define BDK_MMD_DEVICE_CL22_EXT 29
+#define BDK_MMD_DEVICE_VENDOR_1 30
+#define BDK_MMD_DEVICE_VENDOR_2 31
+
+/**
+ * Perform an MII read. This function is used to read PHY
+ * registers controlling auto negotiation.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param bus_id MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
+ * support multiple busses.
+ * @param phy_id The MII phy id
+ * @param location Register location to read
+ *
+ * @return Result from the read or -1 on failure
+ */
+extern int bdk_mdio_read(bdk_node_t node, int bus_id, int phy_id, int location);
+
+/**
+ * Perform an MII write. This function is used to write PHY
+ * registers controlling auto negotiation.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param bus_id MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
+ * support multiple busses.
+ * @param phy_id The MII phy id
+ * @param location Register location to write
+ * @param val Value to write
+ *
+ * @return -1 on error
+ * 0 on success
+ */
+extern int bdk_mdio_write(bdk_node_t node, int bus_id, int phy_id, int location, int val);
+
+/**
+ * Perform an IEEE 802.3 clause 45 MII read. This function is used to read PHY
+ * registers controlling auto negotiation.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param bus_id MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
+ * support multiple busses.
+ * @param phy_id The MII phy id
+ * @param device MDIO Manageable Device (MMD) id
+ * @param location Register location to read
+ *
+ * @return Result from the read or -1 on failure
+ */
+
+extern int bdk_mdio_45_read(bdk_node_t node, int bus_id, int phy_id, int device, int location);
+
+/**
+ * Perform an IEEE 802.3 clause 45 MII write. This function is used to write PHY
+ * registers controlling auto negotiation.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param bus_id MDIO bus number. Zero on most chips, but some chips (ex CN56XX)
+ * support multiple busses.
+ * @param phy_id The MII phy id
+ * @param device MDIO Manageable Device (MMD) id
+ * @param location Register location to write
+ * @param val Value to write
+ *
+ * @return -1 on error
+ * 0 on success
+ */
+extern int bdk_mdio_45_write(bdk_node_t node, int bus_id, int phy_id, int device, int location,
+ int val);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mmc.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mmc.h
new file mode 100644
index 0000000000..93f3286379
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mmc.h
@@ -0,0 +1,89 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the MMC, eMMC, or SD
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Initialize a MMC for read/write
+ *
+ * @author creese (10/14/2013)
+ * @param chip_sel Chip select to use
+ *
+ * @return Size of the SD card, zero on failure
+ */
+extern int64_t bdk_mmc_initialize(bdk_node_t node, int chip_sel);
+
+/**
+ * Read blocks from a MMC card
+ *
+ * @author creese (10/14/2013)
+ * @param node Node to access
+ * @param chip_sel Chip select to use
+ * @param address Offset into the card in bytes. Must be a multiple of 512
+ * @param buffer Buffer to read into
+ * @param length Length to read in bytes. Must be a multiple of 512
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_mmc_read(bdk_node_t node, int chip_sel, uint64_t address, void *buffer, int length);
+
+/**
+ * Write blocks to a MMC card
+ *
+ * @author creese (10/14/2013)
+ * @param node Node to access
+ * @param chip_sel Chip select to use
+ * @param address Offset into the card in bytes. Must be a multiple of 512
+ * @param buffer Buffer to write
+ * @param length Length to write in bytes. Must be a multiple of 512
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_mmc_write(bdk_node_t node, int chip_sel, uint64_t address, const void *buffer, int length);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mpi.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mpi.h
new file mode 100644
index 0000000000..46da75b019
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-mpi.h
@@ -0,0 +1,105 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the SPI / MPI bus
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+typedef enum
+{
+ BDK_MPI_FLAGS_ENABLE_CS0 = 1<<0, /**< Chip select 0 will be needed */
+ BDK_MPI_FLAGS_ENABLE_CS1 = 1<<1, /**< Chip select 1 will be needed */
+ BDK_MPI_FLAGS_ENABLE_CS2 = 1<<2, /**< Chip select 2 will be needed */
+ BDK_MPI_FLAGS_ENABLE_CS3 = 1<<3, /**< Chip select 3 will be needed */
+ BDK_MPI_FLAGS_CS_ACTIVE_HI = 1<<4, /**< Chip select is active high, else active low */
+ BDK_MPI_FLAGS_ONE_WIRE = 1<<5, /**< Input and output are multiplexed over SPI_DO */
+ BDK_MPI_FLAGS_IDLE_CLOCKS = 1<<7, /**< Continue to clock between commands */
+ BDK_MPI_FLAGS_IDLE_LOW = 1<<8, /**< Clear the clock is idle high, Set the clock is idle low */
+ BDK_MPI_FLAGS_LSB_FIRST = 1<<9, /**< Set to shift the LSB first, otherwise MSB will shift first */
+} bdk_mpi_flags_t;
+
+/**
+ * Initialize MPI/SPI for use. The different configuration
+ * options are encoded as bitmask inside the flags parameter.
+ *
+ * @param node Numa node to use
+ * @param clock_rate_hz
+ * Clock rate in Hz (1-16M)
+ * @param flags Setup flags ORed together
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_mpi_initialize(bdk_node_t node, int clock_rate_hz, bdk_mpi_flags_t flags);
+
+/**
+ * Perform a SPI/MPI transfer. The transfer can contain tx_count
+ * bytes that are transferred out, followed by rx_count bytes
+ * that are read in. Both tx_count and rx_count may be zero if
+ * no transfer is needed. Transmit data is sent most significant
+ * byte first, unless BDK_MPI_FLAGS_LSB_FIRST is set. Receive data
+ * is in the return value with the last byte in the least
+ * signnificant byte.
+ *
+ * @param node Numa node to use
+ * @param chip_select
+ * Which chip select to enable during the transfer
+ * @param leave_cs_enabled
+ * Leave the chip select assert after the transaction. Normally can
+ * be zero. Set to non zero if you want to perform repeated
+ * transactions.
+ * @param tx_count Number of bytes to transfer before startng the rx/shift data.
+ * Can be zero.
+ * @param tx_data Data to transmit. The low order bytes are used for the data. Order
+ * of shift out is controlled by BDK_MPI_FLAGS_LSB_FIRST
+ * @param rx_count Number of bytes to read. These bytes will be in the return value
+ * least significant bytes
+ *
+ * @return Read data
+ */
+extern uint64_t bdk_mpi_transfer(bdk_node_t node, int chip_select,
+ int leave_cs_enabled, int tx_count, uint64_t tx_data, int rx_count);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nic.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nic.h
new file mode 100644
index 0000000000..cdd4aa48a9
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nic.h
@@ -0,0 +1,107 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the NIC.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+typedef enum
+{
+ BDK_NIC_TYPE_BGX, /* All chips */
+ BDK_NIC_TYPE_TNS, /* Only allowed on CN88XX */
+ BDK_NIC_TYPE_LBK, /* CN81XX and CN83XX */
+ BDK_NIC_TYPE_RGMII, /* CN83XX */
+} bdk_nic_type_t;
+
+/**
+ * Configure NIC for a specific port. This is called for each
+ * port on every interface that connects to NIC.
+ *
+ * @param handle Handle for port to config
+ * @param ntype Type of LMAC this NIC connects to
+ * @param lmac_credits
+ * Size of the LMAC buffer in bytes. Used to configure the number of credits to
+ * setup between the NIC and LMAC
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_nic_port_init(bdk_if_handle_t handle, bdk_nic_type_t ntype, int lmac_credits);
+
+/**
+ * Get the current TX queue depth. Note that this operation may be slow
+ * and adversly affect packet IO performance.
+ *
+ * @param handle Port to check
+ *
+ * @return Depth of the queue in packets
+ */
+extern int bdk_nic_get_queue_depth(bdk_if_handle_t handle);
+
+/**
+ * Send a packet
+ *
+ * @param handle Handle of port to send on
+ * @param packet Packet to send
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_nic_transmit(bdk_if_handle_t handle, const bdk_if_packet_t *packet);
+
+/**
+ * Query NIC and fill in the transmit stats for the supplied
+ * interface handle.
+ *
+ * @param handle Port handle
+ */
+extern void bdk_nic_fill_tx_stats(bdk_if_handle_t handle);
+
+/**
+ * Query NIC and fill in the receive stats for the supplied
+ * interface handle.
+ *
+ * @param handle Port handle
+ */
+extern void bdk_nic_fill_rx_stats(bdk_if_handle_t handle);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nix.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nix.h
new file mode 100644
index 0000000000..118ceaebbb
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-nix.h
@@ -0,0 +1,105 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2016 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the NIX.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+typedef enum
+{
+ BDK_NIX_TYPE_CGX,
+ BDK_NIX_TYPE_LBK,
+} bdk_nix_type_t;
+
+/**
+ * Configure NIC for a specific port. This is called for each
+ * port on every interface that connects to NIC.
+ *
+ * @param handle Handle for port to config
+ * @param ntype Type of LMAC this NIC connects to
+ * @param lmac_credits
+ * Size of the LMAC buffer in bytes. Used to configure the number of credits to
+ * setup between the NIC and LMAC
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_nix_port_init(bdk_if_handle_t handle, bdk_nix_type_t ntype, int lmac_credits);
+
+/**
+ * Send a packet
+ *
+ * @param handle Handle of port to send on
+ * @param packet Packet to send
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_nix_transmit(bdk_if_handle_t handle, const bdk_if_packet_t *packet);
+
+/**
+ * Get the current TX queue depth. Note that this operation may be slow
+ * and adversly affect packet IO performance.
+ *
+ * @param handle Port to check
+ *
+ * @return Depth of the queue in packets
+ */
+extern int bdk_nix_get_queue_depth(bdk_if_handle_t handle);
+
+/**
+ * Query NIC and fill in the transmit stats for the supplied
+ * interface handle.
+ *
+ * @param handle Port handle
+ */
+extern void bdk_nix_fill_tx_stats(bdk_if_handle_t handle);
+
+/**
+ * Query NIC and fill in the receive stats for the supplied
+ * interface handle.
+ *
+ * @param handle Port handle
+ */
+extern void bdk_nix_fill_rx_stats(bdk_if_handle_t handle);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pbus-flash.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pbus-flash.h
new file mode 100644
index 0000000000..a5cd2d592d
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pbus-flash.h
@@ -0,0 +1,111 @@
+/***********************license start***********************************
+* Copyright (c) 2016-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * This file provides bootbus flash operations
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+typedef struct
+{
+ int start_offset;
+ int block_size;
+ int num_blocks;
+} bdk_pbus_flash_region_t;
+
+/**
+ * Initialize the flash access library
+ */
+void bdk_pbus_flash_initialize(bdk_node_t node);
+
+/**
+ * Return a pointer to the flash chip
+ *
+ * @param chip_id Chip ID to return
+ * @return Zero if the chip doesn't exist
+ */
+uint64_t bdk_pbus_flash_get_base(int chip_id);
+
+/**
+ * Return the number of erasable regions on the chip
+ *
+ * @param chip_id Chip to return info for
+ * @return Number of regions
+ */
+int bdk_pbus_flash_get_num_regions(int chip_id);
+
+/**
+ * Return information about a flash chips region
+ *
+ * @param chip_id Chip to get info for
+ * @param region Region to get info for
+ * @return Region information
+ */
+const bdk_pbus_flash_region_t *bdk_pbus_flash_get_region_info(int chip_id, int region);
+
+/**
+ * Erase a block on the flash chip
+ *
+ * @param chip_id Chip to erase a block on
+ * @param region Region to erase a block in
+ * @param block Block number to erase
+ * @return Zero on success. Negative on failure
+ */
+int bdk_pbus_flash_erase_block(int chip_id, int region, int block);
+
+/**
+ * Write data to flash. The block must have already been erased. You can call
+ * this multiple times on the same block to piecemeal write it.
+ *
+ * @param chip_id Which flash to write
+ * @param offset Offset into device to start write
+ * @param data Data to write
+ * @param len Length of the data
+ *
+ * @return Zero on success. Negative on failure
+ */
+int bdk_pbus_flash_write(int chip_id, int offset, const void *data, int len);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie-flash.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie-flash.h
new file mode 100644
index 0000000000..6605e419bb
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie-flash.h
@@ -0,0 +1,109 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to programming the PCIe SPI flash used for config overrides
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+#define BDK_PCIE_FLASH_PREAMBLE 0x9da1
+#define BDK_PCIE_FLASH_END 0x6a5d
+#define BDK_PCIE_FLASH_MAX_OFFSET 256
+
+/**
+ * Determine if access to the PCIe SPI flash is available
+ *
+ * @param node Numa node request is for
+ * @param pcie_port PCIe port to access
+ *
+ * @return One if available, zero if not
+ */
+extern int bdk_pcie_flash_is_available(bdk_node_t node, int pcie_port);
+
+/**
+ * Read the specified offset in the PCIe SPI flash and returns its
+ * value. In the case the EEPROM isn't there or can't be read -1
+ * is returned.
+ *
+ * @param node Numa node request is for
+ * @param pcie_port PCIe port to access
+ * @param offset Offset in bytes, Must be a multiple of 8
+ *
+ * @return Value read or -1 if the read failed
+ */
+extern uint64_t bdk_pcie_flash_read(bdk_node_t node, int pcie_port, int offset);
+
+/**
+ * Write a value to the PCIe SPI flash. The value should be of the
+ * format bdk_pemx_spi_data_t.
+ *
+ * @param node Numa node request is for
+ * @param pcie_port PCIe port to access
+ * @param offset Offset to write. Must be a multiple of 8 bytes.
+ * @param value Value to write
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pcie_flash_write(bdk_node_t node, int pcie_port, int offset, uint64_t value);
+
+/**
+ * Erase the PCIe SPI Flash
+ *
+ * @param node Numa node request is for
+ * @param pcie_port PCIe port to access
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pcie_flash_erase(bdk_node_t node, int pcie_port);
+
+/**
+ * Dump the PCIe SPI Flash
+ *
+ * @param node Numa node request is for
+ * @param pcie_port PCIe port to access
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pcie_flash_dump(bdk_node_t node, int pcie_port);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie.h
new file mode 100644
index 0000000000..d68a6d297f
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pcie.h
@@ -0,0 +1,236 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to PCIe as a host(RC) or target(EP)
+ *
+ * <hr>$Revision: 51109 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+typedef enum
+{
+ BDK_PCIE_MEM_CONFIG, /* Config space */
+ BDK_PCIE_MEM_NORMAL, /* Memory, not prefetchable */
+ BDK_PCIE_MEM_PREFETCH, /* Memory, prefetchable */
+ BDK_PCIE_MEM_IO, /* IO */
+} bdk_pcie_mem_t;
+
+/**
+ * Return the number of possible PCIe ports on a node. The actual number
+ * of configured ports may be less and may also be disjoint.
+ *
+ * @param node Node to query
+ *
+ * @return Number of PCIe ports that are possible
+ */
+int bdk_pcie_get_num_ports(bdk_node_t node);
+
+/**
+ * Initialize a PCIe port for use in host(RC) mode. It doesn't enumerate the bus.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port to initialize
+ *
+ * @return Zero on success
+ */
+int bdk_pcie_rc_initialize(bdk_node_t node, int pcie_port);
+
+/**
+ * Shutdown a PCIe port and put it in reset
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port to shutdown
+ *
+ * @return Zero on success
+ */
+int bdk_pcie_rc_shutdown(bdk_node_t node, int pcie_port);
+
+/**
+ * Return the Core physical base address for PCIe MEM access. Memory is
+ * read/written as an offset from this address.
+ *
+ * @param node Node to use in a Numa setup
+ * @param pcie_port PCIe port the memory is on
+ * @param mem_type Type of memory
+ *
+ * @return 64bit physical address for read/write
+ */
+uint64_t bdk_pcie_get_base_address(bdk_node_t node, int pcie_port, bdk_pcie_mem_t mem_type);
+
+/**
+ * Size of the Mem address region returned at address
+ * bdk_pcie_get_base_address()
+ *
+ * @param node Node to use in a Numa setup
+ * @param pcie_port PCIe port the IO is for
+ * @param mem_type Type of memory
+ *
+ * @return Size of the Mem window
+ */
+uint64_t bdk_pcie_get_base_size(bdk_node_t node, int pcie_port, bdk_pcie_mem_t mem_type);
+
+/**
+ * Read 8bits from a Device's config space
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port the device is on
+ * @param bus Sub bus
+ * @param dev Device ID
+ * @param fn Device sub function
+ * @param reg Register to access
+ *
+ * @return Result of the read
+ */
+uint8_t bdk_pcie_config_read8(bdk_node_t node, int pcie_port, int bus, int dev, int fn, int reg);
+
+/**
+ * Read 16bits from a Device's config space
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port the device is on
+ * @param bus Sub bus
+ * @param dev Device ID
+ * @param fn Device sub function
+ * @param reg Register to access
+ *
+ * @return Result of the read
+ */
+uint16_t bdk_pcie_config_read16(bdk_node_t node, int pcie_port, int bus, int dev, int fn, int reg);
+
+/**
+ * Read 32bits from a Device's config space
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port the device is on
+ * @param bus Sub bus
+ * @param dev Device ID
+ * @param fn Device sub function
+ * @param reg Register to access
+ *
+ * @return Result of the read
+ */
+uint32_t bdk_pcie_config_read32(bdk_node_t node, int pcie_port, int bus, int dev, int fn, int reg) BDK_WEAK;
+
+/**
+ * Write 8bits to a Device's config space
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port the device is on
+ * @param bus Sub bus
+ * @param dev Device ID
+ * @param fn Device sub function
+ * @param reg Register to access
+ * @param val Value to write
+ */
+void bdk_pcie_config_write8(bdk_node_t node, int pcie_port, int bus, int dev, int fn, int reg, uint8_t val);
+
+/**
+ * Write 16bits to a Device's config space
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port the device is on
+ * @param bus Sub bus
+ * @param dev Device ID
+ * @param fn Device sub function
+ * @param reg Register to access
+ * @param val Value to write
+ */
+void bdk_pcie_config_write16(bdk_node_t node, int pcie_port, int bus, int dev, int fn, int reg, uint16_t val);
+
+/**
+ * Write 32bits to a Device's config space
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param pcie_port PCIe port the device is on
+ * @param bus Sub bus
+ * @param dev Device ID
+ * @param fn Device sub function
+ * @param reg Register to access
+ * @param val Value to write
+ */
+void bdk_pcie_config_write32(bdk_node_t node, int pcie_port, int bus, int dev, int fn, int reg, uint32_t val) BDK_WEAK;
+
+/**
+ * Read 64bits from PCIe using a memory transaction
+ *
+ * @param node Node to read from
+ * @param pcie_port PCIe port to read
+ * @param address PCIe address to read
+ *
+ * @return Result of the read
+ */
+uint64_t bdk_pcie_mem_read64(bdk_node_t node, int pcie_port, uint64_t address);
+
+/**
+ * Write 64bits to PCIe memory
+ *
+ * @param node Node to write to
+ * @param pcie_port PCIe port to use
+ * @param address Address to write
+ * @param data Data to write
+ */
+void bdk_pcie_mem_write64(bdk_node_t node, int pcie_port, uint64_t address, uint64_t data);
+
+/**
+ * These are the operations defined that can vary per chip generation
+ */
+typedef struct
+{
+ int (*get_num_ports)(bdk_node_t node);
+ int (*rc_initialize)(bdk_node_t node, int pcie_port);
+ int (*rc_shutdown)(bdk_node_t node, int pcie_port);
+ uint64_t (*get_base_address)(bdk_node_t node, int pcie_port, bdk_pcie_mem_t mem_type);
+ uint64_t (*get_base_size)(bdk_node_t node, int pcie_port, bdk_pcie_mem_t mem_type);
+ uint64_t (*build_config_addr)(bdk_node_t node, int pcie_port, int bus, int dev, int fn, int reg);
+} __bdk_pcie_ops_t;
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pki.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pki.h
new file mode 100644
index 0000000000..3379d26644
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pki.h
@@ -0,0 +1,83 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the SSO.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * One time init of global Packet Input
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pki_global_init(bdk_node_t node);
+
+/**
+ * Configure packet input for a specific port. This is called for each
+ * port on every interface that is connected to packet input.
+ *
+ * @param handle Handle for port to config
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pki_port_init(bdk_if_handle_t handle);
+
+/**
+ * Enable PKI after all setup is complete
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pki_enable(bdk_node_t node);
+
+/**
+ * Query PKI and fill in the receive stats for the supplied interface handle. The
+ * interface must use PKI for RX.
+ *
+ * @param handle Port handle
+ *
+ * @return
+ */
+extern void bdk_pki_fill_rx_stats(bdk_if_handle_t handle);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pko.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pko.h
new file mode 100644
index 0000000000..90cd719b06
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-pko.h
@@ -0,0 +1,126 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the PKO.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/* Maximum number of segments which fit flat lmtstore operation.
+ 1) LMTST for PKO can be a maximum of 15 64bit words
+ 2) PKO descriptors are 2 64bit words each
+ 3) Every send requires PKO_SEND_HDR_S for hardware
+ So 15 words / 2 = 7 possible descriptors
+ 7 - HDR = 6 descriptors left for GATHER */
+#define BDK_PKO_SEG_LIMIT 6
+
+/**
+ * Perform global init of PKO
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pko_global_init(bdk_node_t node);
+
+/**
+ * Configure PKO for a specific port. This is called for each
+ * port on every interface that connects to PKO.
+ *
+ * @param handle Handle for port to config
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pko_port_init(bdk_if_handle_t handle);
+
+/**
+ * Enable PKO after all setup is complete
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pko_enable(bdk_node_t node);
+
+/**
+ * Get the current TX queue depth. Note that this operation may be slow
+ * and adversly affect packet IO performance.
+ *
+ * @param handle Port to check
+ *
+ * @return Depth of the queue in packets
+ */
+extern int bdk_pko_get_queue_depth(bdk_if_handle_t handle);
+
+/**
+ * Set PKO shapping as a specific queue level
+ *
+ * @param node Node to shape
+ * @param queue Queue to shape
+ * @param level Level in PKO
+ * @param is_red Non-zero of the rate is for the yellow/red transition. Zero for the
+ * green/yellow transition.
+ * @param is_packets Non-zero if the rate is packets/sec, otherwise rate is bits/sec
+ * @param rate Desired rate. A rate of zero disables shaping
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pko_shape(bdk_node_t node, int queue, int level, int is_red, int is_packets, uint64_t rate);
+
+/**
+ * Send a packet
+ *
+ * @param handle Handle of port to send on
+ * @param packet Packet to send
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_pko_transmit(bdk_if_handle_t handle, const bdk_if_packet_t *packet);
+
+/**
+ * Query PKO and fill in the receive stats for the supplied
+ * interface handle. The interface must use PKO for TX.
+ *
+ * @param handle Port handle
+ *
+ * @return
+ */
+extern void bdk_pko_fill_tx_stats(bdk_if_handle_t handle);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-power-burn.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-power-burn.h
new file mode 100644
index 0000000000..570ef1073c
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-power-burn.h
@@ -0,0 +1,67 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+typedef enum
+{
+ BDK_POWER_BURN_NONE, /* Disable power burn */
+ BDK_POWER_BURN_FULL, /* Continuously burn power */
+ BDK_POWER_BURN_CYCLE_10MS, /* Cycle: Burn for 10ms, idle for 10ms */
+ BDK_POWER_BURN_CYCLE_1S, /* Cycle: Burn for 1s, idle for 1s */
+ BDK_POWER_BURN_CYCLE_5S, /* Cycle: Burn for 5s, idle for 5s */
+ BDK_POWER_BURN_CYCLE_1M, /* Cycle: Burn for 1m, idle for 1m */
+ BDK_POWER_BURN_CYCLE_5M, /* Cycle: Burn for 5m, idle for 5m */
+} bdk_power_burn_type_t;
+
+/**
+ * Set the current power burn mode for a node
+ *
+ * @param node Node to control power burn for
+ * @param burn_type Mode of power burn
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_power_burn(bdk_node_t node, bdk_power_burn_type_t burn_type);
+
+/**
+ * Set the throttle level percent for an entire chip
+ *
+ * @param node Node to set
+ * @param throttle Percent of Throttle level (0-100)
+ */
+extern void bdk_power_throttle(bdk_node_t node, int throttle_percent);
+
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-qlm.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-qlm.h
new file mode 100644
index 0000000000..6cb1364196
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-qlm.h
@@ -0,0 +1,508 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Function and structure definitions for QLM manipulation
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+typedef enum
+{
+ BDK_QLM_MODE_DISABLED, /* QLM is disabled (all chips) */
+ BDK_QLM_MODE_PCIE_1X1, /* 1 PCIe, 1 lane. Other lanes unused */
+ BDK_QLM_MODE_PCIE_2X1, /* 2 PCIe, 1 lane each */
+ BDK_QLM_MODE_PCIE_1X2, /* 1 PCIe, 2 lanes */
+ BDK_QLM_MODE_PCIE_1X4, /* 1 PCIe, 4 lanes */
+ BDK_QLM_MODE_PCIE_1X8, /* 1 PCIe, 8 lanes */
+ BDK_QLM_MODE_PCIE_1X16, /* 1 PCIe, 16 lanes (CN93XX) */
+
+ BDK_QLM_MODE_SATA_4X1, /* SATA, each lane independent (cn88xx) */
+ BDK_QLM_MODE_SATA_2X1, /* SATA, each lane independent (cn83xx) */
+
+ BDK_QLM_MODE_ILK, /* ILK 4 lanes (cn78xx) */
+ BDK_QLM_MODE_SGMII_4X1, /* SGMII, each lane independent (cn88xx) */
+ BDK_QLM_MODE_SGMII_2X1, /* SGMII, each lane independent (cn83xx) */
+ BDK_QLM_MODE_SGMII_1X1, /* SGMII, single lane (cn80xx) */
+ BDK_QLM_MODE_XAUI_1X4, /* 1 XAUI or DXAUI, 4 lanes (cn88xx), use gbaud to tell difference */
+ BDK_QLM_MODE_RXAUI_2X2, /* 2 RXAUI, 2 lanes each (cn88xx) */
+ BDK_QLM_MODE_RXAUI_1X2, /* 1 RXAUI, 2 lanes each (cn83xx) */
+ BDK_QLM_MODE_OCI, /* OCI Multichip interconnect (cn88xx) */
+ BDK_QLM_MODE_XFI_4X1, /* 4 XFI, 1 lane each (cn88xx) */
+ BDK_QLM_MODE_XFI_2X1, /* 2 XFI, 1 lane each (cn83xx) */
+ BDK_QLM_MODE_XFI_1X1, /* 1 XFI, single lane (cn80xx) */
+ BDK_QLM_MODE_XLAUI_1X4, /* 1 XLAUI, 4 lanes each (cn88xx) */
+ BDK_QLM_MODE_10G_KR_4X1, /* 4 10GBASE-KR, 1 lane each (cn88xx) */
+ BDK_QLM_MODE_10G_KR_2X1, /* 2 10GBASE-KR, 1 lane each (cn83xx) */
+ BDK_QLM_MODE_10G_KR_1X1, /* 1 10GBASE-KR, single lane (cn80xx) */
+ BDK_QLM_MODE_40G_KR4_1X4, /* 1 40GBASE-KR4, 4 lanes each (cn88xx) */
+ BDK_QLM_MODE_QSGMII_4X1, /* QSGMII is 4 SGMII on one lane (cn81xx, cn83xx) */
+ BDK_QLM_MODE_25G_4X1, /* 25G, 1 lane each (CN93XX QLMs) */
+ BDK_QLM_MODE_25G_2X1, /* 25G, 1 lane each (CN93XX DLMs) */
+ BDK_QLM_MODE_50G_2X2, /* 50G, 2 lanes each (CN93XX QLMs) */
+ BDK_QLM_MODE_50G_1X2, /* 50G, 2 lanes each (CN93XX DLMs) */
+ BDK_QLM_MODE_100G_1X4, /* 100G, 4 lanes each (CN93XX) */
+ BDK_QLM_MODE_25G_KR_4X1, /* 25G-KR, 1 lane each (CN93XX QLMs) */
+ BDK_QLM_MODE_25G_KR_2X1, /* 25G-KR, 1 lane each (CN93XX DLMs) */
+ BDK_QLM_MODE_50G_KR_2X2, /* 50G-KR, 2 lanes each (CN93XX QLMs) */
+ BDK_QLM_MODE_50G_KR_1X2, /* 50G-KR, 2 lanes each (CN93XX DLMs) */
+ BDK_QLM_MODE_100G_KR4_1X4, /* 100G-KR4, 4 lanes each (CN93XX) */
+ BDK_QLM_MODE_USXGMII_4X1, /* USXGMII, 1 lane each, 10M, 100M, 1G, 2.5G, 5G, 10G, 20G (CN93XX QLMs) */
+ BDK_QLM_MODE_USXGMII_2X1, /* USXGMII, 1 lane each, 10M, 100M, 1G, 2.5G, 5G, 10G, 20G (CN93XX QLMs) */
+ BDK_QLM_MODE_LAST,
+} bdk_qlm_modes_t;
+
+typedef enum
+{
+ BDK_QLM_CLK_COMMON_0,
+ BDK_QLM_CLK_COMMON_1,
+ BDK_QLM_CLK_EXTERNAL,
+ BDK_QLM_CLK_COMMON_2, /* Must be after EXTERNAL as device trees have hard coded values */
+ BDK_QLM_CLK_LAST,
+} bdk_qlm_clock_t;
+
+typedef enum
+{
+ BDK_QLM_MODE_FLAG_ENDPOINT = 1, /* PCIe in EP instead of RC */
+} bdk_qlm_mode_flags_t;
+
+typedef enum
+{
+ BDK_QLM_LOOP_DISABLED, /* No shallow loopback */
+} bdk_qlm_loop_t;
+
+typedef enum
+{
+ BDK_QLM_DIRECTION_TX = 1,
+ BDK_QLM_DIRECTION_RX = 2,
+ BDK_QLM_DIRECTION_BOTH = 3,
+} bdk_qlm_direction_t;
+
+/**
+ * Types of QLM margining supported
+ */
+typedef enum
+{
+ BDK_QLM_MARGIN_VERTICAL,
+ BDK_QLM_MARGIN_HORIZONTAL,
+} bdk_qlm_margin_t;
+
+/**
+ * Eye diagram captures are stored in the following structure
+ */
+typedef struct
+{
+ int width; /* Width in the x direction (time) */
+ int height; /* Height in the y direction (voltage) */
+ uint32_t data[64][128]; /* Error count at location, saturates as max */
+} bdk_qlm_eye_t;
+
+
+/**
+ * How to do the various QLM operations changes greatly
+ * between chips. Each chip has its specific operations
+ * stored in the structure below. The correct structure
+ * is chosen based on the chip we're running on.
+ */
+typedef struct
+{
+ uint32_t chip_model;
+ void (*init)(bdk_node_t node);
+ int (*get_num)(bdk_node_t node);
+ int (*get_lanes)(bdk_node_t node, int qlm);
+ bdk_qlm_modes_t (*get_mode)(bdk_node_t node, int qlm);
+ int (*set_mode)(bdk_node_t node, int qlm, bdk_qlm_modes_t mode, int baud_mhz, bdk_qlm_mode_flags_t flags);
+ int (*get_gbaud_mhz)(bdk_node_t node, int qlm);
+ int (*measure_refclock)(bdk_node_t node, int qlm);
+ int (*get_qlm_num)(bdk_node_t node, bdk_if_t iftype, int interface, int index);
+ int (*reset)(bdk_node_t node, int qlm);
+ int (*enable_prbs)(bdk_node_t node, int qlm, int prbs, bdk_qlm_direction_t dir);
+ int (*disable_prbs)(bdk_node_t node, int qlm);
+ uint64_t (*get_prbs_errors)(bdk_node_t node, int qlm, int lane, int clear);
+ void (*inject_prbs_error)(bdk_node_t node, int qlm, int lane);
+ int (*enable_loop)(bdk_node_t node, int qlm, bdk_qlm_loop_t loop);
+ int (*auto_config)(bdk_node_t node);
+ int (*dip_auto_config)(bdk_node_t node);
+ int (*tune_lane_tx)(bdk_node_t node, int qlm, int lane, int tx_swing, int tx_pre, int tx_post, int tx_gain, int tx_vboost);
+ int (*rx_equalization)(bdk_node_t node, int qlm, int lane);
+ int (*eye_capture)(bdk_node_t node, int qlm, int qlm_lane, bdk_qlm_eye_t *eye);
+} bdk_qlm_ops_t;
+
+/**
+ * Initialize the QLM layer
+ */
+extern void bdk_qlm_init(bdk_node_t node) BDK_WEAK;
+
+/**
+ * Return the number of QLMs supported for the chip
+ *
+ * @return Number of QLMs
+ */
+extern int bdk_qlm_get_num(bdk_node_t node);
+
+/**
+ * Return the number of lanes in a QLM. QLMs normally contain
+ * 4 lanes, except for chips which only have half of a QLM.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param qlm QLM to get lanes number for
+ *
+ * @return Number of lanes on the QLM
+ */
+extern int bdk_qlm_get_lanes(bdk_node_t node, int qlm);
+
+/**
+ * Convert a mode into a configuration variable string value
+ *
+ * @param mode Mode to convert
+ *
+ * @return configuration value string
+ */
+extern const char *bdk_qlm_mode_to_cfg_str(bdk_qlm_modes_t mode);
+
+/**
+ * Convert a mode into a human understandable string
+ *
+ * @param mode Mode to convert
+ *
+ * @return Easy to read string
+ */
+extern const char *bdk_qlm_mode_tostring(bdk_qlm_modes_t mode);
+
+/**
+ * Convert a configuration variable value string into a mode
+ *
+ * @param val Configuration variable value
+ *
+ * @return mode
+ */
+extern bdk_qlm_modes_t bdk_qlm_cfg_string_to_mode(const char *val);
+
+/**
+ * Get the mode of a QLM as a human readable string
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param qlm QLM to examine
+ *
+ * @return String mode
+ */
+extern bdk_qlm_modes_t bdk_qlm_get_mode(bdk_node_t node, int qlm);
+
+/**
+ * For chips that don't use pin strapping, this function programs
+ * the QLM to the specified mode
+ *
+ * @param node Node to use in a Numa setup
+ * @param qlm QLM to configure
+ * @param mode Desired mode
+ * @param baud_mhz Desired speed
+ * @param flags Flags to specify mode specific options
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_set_mode(bdk_node_t node, int qlm, bdk_qlm_modes_t mode, int baud_mhz, bdk_qlm_mode_flags_t flags);
+
+/**
+ * Set the QLM's clock source.
+ *
+ * @param node Node to use in a Numa setup
+ * @param qlm QLM to configure
+ * @param clk Clock source for QLM
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_set_clock(bdk_node_t node, int qlm, bdk_qlm_clock_t clk);
+
+/**
+ * Get the speed (Gbaud) of the QLM in Mhz.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param qlm QLM to examine
+ *
+ * @return Speed in Mhz
+ */
+extern int bdk_qlm_get_gbaud_mhz(bdk_node_t node, int qlm);
+
+/**
+ * Measure the reference clock of a QLM
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param qlm QLM to measure
+ *
+ * @return Clock rate in Hz
+ */
+extern int bdk_qlm_measure_clock(bdk_node_t node, int qlm);
+
+/**
+ * Lookup the hardware QLM number for a given interface type and
+ * index. If the associated interface doesn't map to a QLM,
+ * returns -1.
+ *
+ * @param node Node to use in a Numa setup
+ * @param iftype Interface type
+ * @param interface Interface index number
+ * @param index Port on the interface. Most chips use the
+ * same mode for all ports, but there are
+ * exceptions. For example, BGX2 on CN83XX
+ * spans two DLMs.
+ *
+ * @return QLM number or -1 on failure
+ */
+extern int bdk_qlm_get(bdk_node_t node, bdk_if_t iftype, int interface, int index);
+
+/**
+ * Reset a QLM to its initial state
+ *
+ * @param node Node to use in a numa setup
+ * @param qlm QLM to use
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_reset(bdk_node_t node, int qlm);
+
+/**
+ * Enable PRBS on a QLM
+ *
+ * @param node Node to use in a numa setup
+ * @param qlm QLM to use
+ * @param prbs PRBS mode (31, etc)
+ * @param dir Directions to enable. This is so you can enable TX and later
+ * enable RX after TX has run for a time
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_enable_prbs(bdk_node_t node, int qlm, int prbs, bdk_qlm_direction_t dir);
+
+/**
+ * Disable PRBS on a QLM
+ *
+ * @param node Node to use in a numa setup
+ * @param qlm QLM to use
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_disable_prbs(bdk_node_t node, int qlm);
+
+/**
+ * Return the number of PRBS errors since PRBS started running
+ *
+ * @param node Node to use in numa setup
+ * @param qlm QLM to use
+ * @param lane Which lane
+ * @param clear Clear the counter after returning its value
+ *
+ * @return Number of errors
+ */
+extern uint64_t bdk_qlm_get_prbs_errors(bdk_node_t node, int qlm, int lane, int clear);
+
+/**
+ * Inject an error into PRBS
+ *
+ * @param node Node to use in numa setup
+ * @param qlm QLM to use
+ * @param lane Which lane
+ */
+extern void bdk_qlm_inject_prbs_error(bdk_node_t node, int qlm, int lane);
+
+/**
+ * Enable shallow loopback on a QLM
+ *
+ * @param node Node to use in a numa setup
+ * @param qlm QLM to use
+ * @param loop Type of loopback. Not all QLMs support all modes
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_enable_loop(bdk_node_t node, int qlm, bdk_qlm_loop_t loop);
+
+/**
+ * Configure the TX tuning parameters for a QLM lane. The tuning parameters can
+ * be specified as -1 to maintain their current value
+ *
+ * @param node Node to configure
+ * @param qlm QLM to configure
+ * @param lane Lane to configure
+ * @param tx_swing Transmit swing (coef 0) Range 0-31
+ * @param tx_pre Pre cursor emphasis (Coef -1). Range 0-15
+ * @param tx_post Post cursor emphasis (Coef +1). Range 0-31
+ * @param tx_gain Transmit gain. Range 0-7
+ * @param tx_vboost Transmit voltage boost. Range 0-1
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_tune_lane_tx(bdk_node_t node, int qlm, int lane, int tx_swing, int tx_pre, int tx_post, int tx_gain, int tx_vboost);
+
+/**
+ * Perform RX equalization on a QLM
+ *
+ * @param node Node the QLM is on
+ * @param qlm QLM to perform RX equalization on
+ * @param lane Lane to use, or -1 for all lanes
+ *
+ * @return Zero on success, negative if any lane failed RX equalization
+ */
+extern int bdk_qlm_rx_equalization(bdk_node_t node, int qlm, int lane);
+
+/**
+ * Capture an eye diagram for the given QLM lane. The output data is written
+ * to "eye".
+ *
+ * @param node Node to use in numa setup
+ * @param qlm QLM to use
+ * @param qlm_lane Which lane
+ * @param eye Output eye data
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_eye_capture(bdk_node_t node, int qlm, int qlm_lane, bdk_qlm_eye_t *eye);
+
+/**
+ * Display an eye diagram for the given QLM lane. The eye data can be in "eye", or
+ * captured during the call if "eye" is NULL.
+ *
+ * @param node Node to use in numa setup
+ * @param qlm QLM to use
+ * @param qlm_lane Which lane
+ * @param format Display format. 0 = raw, 1 = Color ASCII
+ * @param eye Eye data to display, or NULL if the data should be captured.
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_eye_display(bdk_node_t node, int qlm, int qlm_lane, int format, const bdk_qlm_eye_t *eye);
+
+/**
+ * Call the board specific method of determining the required QLM configuration
+ * and automatically settign up the QLMs to match. For example, on the EBB8800
+ * this function queries the MCU for the current setup.
+ *
+ * @param node Node to configure
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_auto_config(bdk_node_t node);
+
+/**
+ * Get the current RX margining parameter
+ *
+ * @param node Node to read margin value from
+ * @param qlm QLM to read from
+ * @param qlm_lane Lane to read
+ * @param margin_type
+ * Type of margining parameter to read
+ *
+ * @return Current margining parameter value
+ */
+extern int64_t bdk_qlm_margin_rx_get(bdk_node_t node, int qlm, int qlm_lane, bdk_qlm_margin_t margin_type);
+
+/**
+ * Get the current RX margining parameter minimum value
+ *
+ * @param node Node to read margin value from
+ * @param qlm QLM to read from
+ * @param qlm_lane Lane to read
+ * @param margin_type
+ * Type of margining parameter to read
+ *
+ * @return Current margining parameter minimum value
+ */
+extern int64_t bdk_qlm_margin_rx_get_min(bdk_node_t node, int qlm, int qlm_lane, bdk_qlm_margin_t margin_type);
+
+/**
+ * Get the current RX margining parameter maximum value
+ *
+ * @param node Node to read margin value from
+ * @param qlm QLM to read from
+ * @param qlm_lane Lane to read
+ * @param margin_type
+ * Type of margining parameter to read
+ *
+ * @return Current margining parameter maximum value
+ */
+extern int64_t bdk_qlm_margin_rx_get_max(bdk_node_t node, int qlm, int qlm_lane, bdk_qlm_margin_t margin_type);
+
+/**
+ * Set the current RX margining parameter value
+ *
+ * @param node Node to set margin value on
+ * @param qlm QLM to set
+ * @param qlm_lane Lane to set
+ * @param margin_type
+ * Type of margining parameter to set
+ * @param value Value of margining parameter
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_margin_rx_set(bdk_node_t node, int qlm, int qlm_lane, bdk_qlm_margin_t margin_type, int value);
+
+/**
+ * Restore the supplied RX margining parameter value as if it was never set. This
+ * disables any overrides in the SERDES need to perform margining
+ *
+ * @param node Node to restore margin value on
+ * @param qlm QLM to restore
+ * @param qlm_lane Lane to restore
+ * @param margin_type
+ * Type of margining parameter to restore
+ * @param value Value of margining parameter
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_qlm_margin_rx_restore(bdk_node_t node, int qlm, int qlm_lane, bdk_qlm_margin_t margin_type, int value);
+
+/**
+ * For Cavium SFF query the dip switches to determine the QLM setup. Applying
+ * any configuration found.
+ *
+ * @param node Node to configure
+ *
+ * @return Zero on success, negative on failure
+ */
+
+extern int bdk_qlm_dip_auto_config(bdk_node_t node);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rng.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rng.h
new file mode 100644
index 0000000000..d5a7d0a43b
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rng.h
@@ -0,0 +1,79 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Function and structure definitions for random number generator hardware
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Reads 8 bits of random data from Random number generator
+ *
+ * @return random data
+ */
+extern uint8_t bdk_rng_get_random8(void);
+
+/**
+ * Reads 16 bits of random data from Random number generator
+ *
+ * @return random data
+ */
+extern uint16_t bdk_rng_get_random16(void);
+
+/**
+ * Reads 32 bits of random data from Random number generator
+ *
+ * @return random data
+ */
+extern uint32_t bdk_rng_get_random32(void);
+
+/**
+ * Reads 64 bits of random data from Random number generator
+ *
+ * @return random data
+ */
+extern uint64_t bdk_rng_get_random64(void);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rvu.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rvu.h
new file mode 100644
index 0000000000..53b73ca4aa
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-rvu.h
@@ -0,0 +1,66 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the hardware RVU.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+#define BDK_RVU_PF 0 /* The BDK uses a hard coded PF number for accessing RVU devices */
+
+/**
+ * Allocate a block of MSIX vectors inside RVU
+ *
+ * @param node Node to allocate for
+ * @param msix_count Number to allocate
+ *
+ * @return Starting offset of MSIX vectors. On failure this function calls bdk_fatal(), so
+ * no error checking is needed on the return value.
+ */
+static inline int bdk_rvu_alloc_msix(bdk_node_t node, int msix_count)
+{
+ return 0; /* FIXME: Implement MSIX allocation for RVU */
+}
+
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sata.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sata.h
new file mode 100644
index 0000000000..755a3ba7aa
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sata.h
@@ -0,0 +1,163 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * This file provides a SATA driver
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * SATA pattern generation and loopback supports a number of
+ * modes. This enumeration describes the modes used by
+ * bdk_sata_bist_fir().
+ */
+typedef enum
+{
+ BDK_SATA_BIST_FIS_RETIMED, /* Send FIS to tell device to enter Retimed loopback */
+ BDK_SATA_BIST_FIS_ANALOG, /* Send FIS to tell device to enter Analog loopback */
+ BDK_SATA_BIST_FIS_TX_ONLY, /* Send FIS to tell device to transit only */
+ BDK_SATA_BIST_SW_RETIMED, /* No FIS, just enter local retimed loopback */
+ BDK_SATA_BIST_SW_TX_ONLY_SSOP, /* No FIS, just enter local transit only, SSOP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_HTDP, /* No FIS, just enter local transit only, HTDP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_LTDP, /* No FIS, just enter local transit only, LTDP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_LFSCP, /* No FIS, just enter local transit only, LFSCP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_COMP, /* No FIS, just enter local transit only, COMP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_LBP, /* No FIS, just enter local transit only, LBP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_MFTP, /* No FIS, just enter local transit only, MFTP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_HFTP, /* No FIS, just enter local transit only, HFTP pattern */
+ BDK_SATA_BIST_SW_TX_ONLY_LFTP, /* No FIS, just enter local transit only, LFTP pattern */
+} bdk_sata_bist_fis_t;
+
+/**
+ * Return the number of SATA controllers on the chip
+ *
+ * @param node Node to query
+ *
+ * @return Number of controllers, could be zero.
+ */
+int bdk_sata_get_controllers(bdk_node_t node);
+
+/**
+ * Initialize a SATA controller and begin device detection
+ *
+ * @param node Node to initialize
+ * @param controller Which controller to initialize
+ *
+ * @return Zero on success, negative on failure
+ */
+int bdk_sata_initialize(bdk_node_t node, int controller);
+
+/**
+ * Shutdown a SATA controller
+ *
+ * @param node Node to access
+ * @param controller Controller to shutdown
+ *
+ * @return Zero on success, negative on failure
+ */
+int bdk_sata_shutdown(bdk_node_t node, int controller);
+
+/**
+ * Return the number of SATA ports connected to this AHCI controller
+ *
+ * @param node Node to query
+ * @param controller SATA controller
+ *
+ * @return Number of ports. Zero if the controller doesn't connect to a QLM.
+ */
+int bdk_sata_get_ports(bdk_node_t node, int controller);
+
+/**
+ * Identify the SATA device connected to a controller
+ *
+ * @param node Node to query
+ * @param controller Controller to query
+ * @param port Which SATA port on the controller, zero based
+ *
+ * @return Size of the disk in bytes
+ */
+uint64_t bdk_sata_identify(bdk_node_t node, int controller, int port);
+
+/**
+ * Read data from a SATA device
+ *
+ * @param node Node the controller is on
+ * @param controller Which controller
+ * @param port Which port on the controller, zero based
+ * @param lba 48 bit Block address to read
+ * @param sectors Number of 512 bytes sectors to read
+ * @param buffer Buffer to receive the data. Must be at least 512 * sectors in size
+ *
+ * @return Zero on success, negative on failure
+ */
+int bdk_sata_read(bdk_node_t node, int controller, int port, uint64_t lba, int sectors, void *buffer);
+
+/**
+ * Write data to a SATA device
+ *
+ * @param node Node the controller is on
+ * @param controller Which controller
+ * @param port Which port on the controller, zero based
+ * @param lba 48 bit Block address to write
+ * @param sectors Number of 512 bytes sectors to write
+ * @param buffer Data buffer to write. Must be at least 512 * sectors in size
+ *
+ * @return Zero on success, negative on failure
+ */
+int bdk_sata_write(bdk_node_t node, int controller, int port, uint64_t lba, int sectors, const void *buffer);
+
+/**
+ * Enter one of the SATA pattern generation / loop testing modes
+ *
+ * @param node Node to access
+ * @param controller SATA controller to access
+ * @param port Which port on the controller
+ * @param mode Test mode to enter
+ *
+ * @return Zero on success, negative on failure
+ */
+int bdk_sata_bist_fis(bdk_node_t node, int controller, int port, bdk_sata_bist_fis_t mode);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-spinlock.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-spinlock.h
new file mode 100644
index 0000000000..5e34a4f7b9
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-spinlock.h
@@ -0,0 +1,146 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Implementation of spinlocks.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Spinlocks
+ */
+typedef union
+{
+ uint64_t combined;
+ struct
+ {
+#if __BYTE_ORDER == __BIG_ENDIAN
+ uint32_t ticket;
+ uint32_t serving;
+#else
+ uint32_t serving;
+ uint32_t ticket;
+#endif
+ } s;
+} bdk_spinlock_t;
+
+/**
+ * Initialize a spinlock
+ *
+ * @param lock Lock to initialize
+ */
+static inline void bdk_spinlock_init(bdk_spinlock_t *lock)
+{
+ asm volatile ("str xzr, [%[b]]"
+ : "+m" (lock->combined)
+ : [b] "r" (&lock->combined)
+ : "memory");
+}
+
+/**
+ * Releases lock
+ *
+ * @param lock pointer to lock structure
+ */
+static inline void bdk_spinlock_unlock(bdk_spinlock_t *lock) __attribute__ ((always_inline));
+static inline void bdk_spinlock_unlock(bdk_spinlock_t *lock)
+{
+ /* Implies a release */
+ asm volatile ("stlr %w[v], [%[b]]"
+ : "+m" (lock->s.serving)
+ : [v] "r" (lock->s.serving + 1), [b] "r" (&lock->s.serving)
+ : "memory");
+}
+
+/**
+ * Gets lock, spins until lock is taken
+ *
+ * @param lock pointer to lock structure
+ */
+static inline void bdk_spinlock_lock(bdk_spinlock_t *lock) __attribute__ ((always_inline));
+static inline void bdk_spinlock_lock(bdk_spinlock_t *lock)
+{
+ uint64_t combined;
+ uint32_t ticket;
+ uint32_t serving;
+
+ asm volatile (
+ "mov %x[serving], 1<<32 \n"
+ "ldadda %x[serving], %x[combined], [%[ptr]] \n"
+ "and %x[serving], %x[combined], 0xffffffff \n"
+ "lsr %x[ticket], %x[combined], 32 \n"
+ "cmp %x[ticket], %x[serving] \n"
+ "b.eq 1f \n"
+ "sevl \n"
+ "2: wfe \n"
+ "ldxr %w[serving], [%[ptr2]] \n"
+ "cmp %x[ticket], %x[serving] \n"
+ "b.ne 2b \n"
+ "1: \n"
+ : [serving] "=&r" (serving), [ticket] "=&r" (ticket), [combined] "=&r" (combined), "+m" (lock->combined)
+ : [ptr] "r" (&lock->combined), [ptr2] "r" (&lock->s.serving)
+ : "memory"
+ );
+}
+
+/**
+ * Trys to get the lock, failing if we can't get it immediately
+ *
+ * @param lock pointer to lock structure
+ */
+static inline int bdk_spinlock_trylock(bdk_spinlock_t *lock) __attribute__ ((always_inline));
+static inline int bdk_spinlock_trylock(bdk_spinlock_t *lock)
+{
+ uint64_t combined = *(volatile uint64_t *)&lock->combined;
+ uint32_t ticket = combined >> 32;
+ uint32_t serving = (uint32_t)combined;
+ if (ticket != serving)
+ return -1;
+ uint64_t new_combined = combined + (1ull << 32);
+ bool success = bdk_atomic_compare_and_store64(&lock->combined, combined, new_combined);
+ return success ? 0 : -1;
+}
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sso.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sso.h
new file mode 100644
index 0000000000..a04d5ca3cf
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-sso.h
@@ -0,0 +1,69 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the SSO.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Initialize the SSO
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_sso_init(bdk_node_t node);
+
+/**
+ * Register a bdk-if handle with the SSO code so the SSO can be used to receive
+ * traffic from it.
+ *
+ * @param handle Handle to register
+ */
+extern void bdk_sso_register_handle(bdk_if_handle_t handle);
+
+/**
+ * Function called during bdk_thread_yield() to process work while we're idle
+ */
+extern void bdk_sso_process_work(void);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-tns.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-tns.h
new file mode 100644
index 0000000000..89264c8604
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-tns.h
@@ -0,0 +1,109 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Thunder Network Switch interface.
+ *
+ * $Revision$
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Initialize the TNS block to enable clocks, allow register accesses, and
+ * perform some basic initialization in anticipation of future packet
+ * processing.
+ *
+ * TNS at power-up will be in BYPASS mode where packets from the vNIC pipes
+ * to the BGX ports will be direct, and this will not change that.
+ *
+ * This is normally called automatically in bdk-init-main.c.
+ *
+ * @param node Node to initialize
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_tns_initialize(bdk_node_t node) BDK_WEAK;
+
+/**
+ * Disable TNS from processing packets. After this, TNS must be fully
+ * initialized. The NIC and BGX blocks must already be stopped before
+ * calling this function.
+ *
+ * Nota Bene: In CN88XX_PASS_1 there is a bug that prevents TNS DataPath
+ * from draining packets. So ensure that NIC and BGX have
+ * also drained their packet queues.
+ *
+ * @param node
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_tns_shutdown(bdk_node_t node);
+
+/**
+ * Set the TNS 'profile' to passthru. I.e. do the necessary writes
+ * to the TNS datapath and TNS sst (Search, SDE, and TxQ) registers
+ * to configure the TNS to allow vNIC0..vNIC7 <-> LMAC0..LMAC7 traffic
+ * to flow straight through TNS (although the actual enabling of using
+ * the TNS is done elsewhere (in traffic-gen.))
+ *
+ * @param node Node to configure
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_tns_profile_passthru(bdk_node_t node) BDK_WEAK;
+
+/**
+ * Set the TNS 'profile' to bgxloopback. I.e. do the necessary writes
+ * to the TNS datapath and TNS sst (Search, SDE, and TxQ) registers
+ * to configure the TNS to allow any packets received on LMAC0..LMAC7
+ * (BGX ports) to be reflected back to the same port after hitting the
+ * TNS (although the actual enabling of using the TNS is done elsewhere
+ * (in traffic-gen.))
+ *
+ * @param node Node to configure
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_tns_profile_bgxloopback(bdk_node_t node) BDK_WEAK;
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-twsi.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-twsi.h
new file mode 100644
index 0000000000..2840ca5c96
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-twsi.h
@@ -0,0 +1,102 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the TWSI / I2C bus
+ *
+ * Note: Currently on 7 bit device addresses are supported
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Initialize the TWSI blocks. This just sets the clock rate.
+ * Many times stuff will work without calling this, but some
+ * TWSI devices will fail. This is normally called automatically
+ * in bdk-init-main.c.
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_twsix_initialize(bdk_node_t node) BDK_WEAK;
+
+/**
+ * Do a twsi read from a 7 bit device address using an (optional)
+ * internal address. Up to 4 bytes can be read at a time.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param twsi_id which TWSI bus to use
+ * @param dev_addr Device address (7 bit)
+ * @param internal_addr
+ * Internal address. Can be 0, 1 or 2 bytes in width
+ * @param num_bytes Number of data bytes to read (1-4)
+ * @param ia_width_bytes
+ * Internal address size in bytes (0, 1, or 2)
+ *
+ * @return Read data, or -1 on failure
+ */
+extern int64_t bdk_twsix_read_ia(bdk_node_t node, int twsi_id, uint8_t dev_addr, uint16_t internal_addr, int num_bytes, int ia_width_bytes);
+
+/**
+ * Write 1-8 bytes to a TWSI device using an internal address.
+ *
+ * @param node Node to use in a Numa setup. Can be an exact ID or a special
+ * value.
+ * @param twsi_id which TWSI interface to use
+ * @param dev_addr TWSI device address (7 bit only)
+ * @param internal_addr
+ * TWSI internal address (0, 8, or 16 bits)
+ * @param num_bytes Number of bytes to write (1-8)
+ * @param ia_width_bytes
+ * internal address width, in bytes (0, 1, 2)
+ * @param data Data to write. Data is written MSB first on the twsi bus, and
+ * only the lower num_bytes bytes of the argument are valid. (If
+ * a 2 byte write is done, only the low 2 bytes of the argument is
+ * used.
+ *
+ * @return Zero on success, -1 on error
+ */
+extern int bdk_twsix_write_ia(bdk_node_t node, int twsi_id, uint8_t dev_addr, uint16_t internal_addr, int num_bytes, int ia_width_bytes, uint64_t data);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-usb.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-usb.h
new file mode 100644
index 0000000000..6e78e5db14
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-usb.h
@@ -0,0 +1,109 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to USB3 or USB2.
+ *
+ * <hr>$Revision: 49448 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+typedef enum
+{
+ BDK_USB_TEST_USB2_DISABLE,
+ BDK_USB_TEST_USB2_J_STATE,
+ BDK_USB_TEST_USB2_K_STATE,
+ BDK_USB_TEST_USB2_SE0_NAK,
+ BDK_USB_TEST_USB2_PACKET,
+ BDK_USB_TEST_USB2_FORCE_ENABLE,
+ BDK_USB_XHCI_INIT,
+ BDK_USB_XHCI_LIST_ADDRESSES,
+ BDK_USB_XHCI_POLL_STATUS,
+ BDK_USB_XHCI_TOGGLE_POLLING,
+ BDK_USB_TEST_USB2_LAST,
+} bdk_usb_test_t;
+
+typedef enum
+{
+ BDK_USB_CLOCK_SS_PAD_HS_PAD = 0x0, /* Superspeed and high speed use PAD clock */
+ BDK_USB_CLOCK_SS_REF0_HS_REF0 = 0x1, /* Superspeed and high speed use DLM/QLM ref clock 0 */
+ BDK_USB_CLOCK_SS_REF1_HS_REF1 = 0x2, /* Superspeed and high speed use DLM/QLM ref clock 1 */
+ BDK_USB_CLOCK_SS_PAD_HS_PLL = 0x3, /* Superspeed uses PAD clock, high speed uses PLL ref clock */
+ BDK_USB_CLOCK_SS_REF0_HS_PLL = 0x4, /* Superspeed uses DLM/QLM ref clock 0, high speed uses PLL ref clock */
+ BDK_USB_CLOCK_SS_REF1_HS_PLL = 0x5, /* Superspeed uses DLM/QLM ref clock 1, high speed uses PLL ref clock */
+} bdk_usb_clock_t;
+
+/**
+ * Initialize the clocks for USB such that it is ready for a generic XHCI driver
+ *
+ * @param node Node to init
+ * @param usb_port Port to intialize
+ * @param clock_type Type of clock connected to the usb port
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_usb_initialize(bdk_node_t node, int usb_port, bdk_usb_clock_t clock_type);
+
+/**
+ * Put the USB port into a specific testing mode
+ *
+ * @param node Node to use
+ * @param usb_port Port to use
+ * @param test_mode USB test mode
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_usb_test_mode(bdk_node_t node, int usb_port, bdk_usb_test_t test_mode);
+
+/**
+ * Convert a USB test enumeration into a string for display to the user
+ *
+ * @param node Node to use
+ * @param usb_port Port to use
+ * @param test_mode Mode to convert
+ *
+ * @return String name of test
+ */
+extern const char *bdk_usb_get_test_mode_string(bdk_node_t node, int usb_port, bdk_usb_test_t test_mode);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-utils.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-utils.h
new file mode 100644
index 0000000000..c0ed43582e
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-utils.h
@@ -0,0 +1,206 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+#include "libbdk-arch/bdk-csrs-lmc.h"
+#include "libbdk-arch/bdk-csrs-rst.h"
+
+/**
+ * @file
+ * Small utility functions and macros to ease programming.
+ *
+ * <hr>$Revision: 38306 $<hr>
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/*
+ * The macros bdk_likely and bdk_unlikely use the
+ * __builtin_expect GCC operation to control branch
+ * probabilities for a conditional. For example, an "if"
+ * statement in the code that will almost always be
+ * executed should be written as "if (bdk_likely(...))".
+ * If the "else" section of an if statement is more
+ * probable, use "if (bdk_unlikey(...))".
+ */
+#define bdk_likely(x) __builtin_expect(!!(x), 1)
+#define bdk_unlikely(x) __builtin_expect(!!(x), 0)
+
+#define BDK_DISPLAY_PASS 1 /* Control the display of the detail chip pass info */
+#define BDK_CACHE_LINE_SIZE (128) // In bytes
+#define BDK_CACHE_LINE_MASK (BDK_CACHE_LINE_SIZE - 1) // In bytes
+#define BDK_CACHE_LINE_ALIGNED __attribute__ ((aligned (BDK_CACHE_LINE_SIZE)))
+
+/**
+ * Builds a bit mask given the required size in bits.
+ *
+ * @param bits Number of bits in the mask
+ * @return The mask
+ */
+static inline uint64_t bdk_build_mask(uint64_t bits)
+{
+ if (bits == 64)
+ return -1;
+ else
+ return ~((~0x0ull) << bits);
+}
+
+/**
+ * Extract bits out of a number
+ *
+ * @param input Number to extract from
+ * @param lsb Starting bit, least significant (0-63)
+ * @param width Width in bits (1-64)
+ *
+ * @return Extracted number
+ */
+static inline uint64_t bdk_extract(uint64_t input, int lsb, int width)
+{
+ uint64_t result = input >> lsb;
+ result &= bdk_build_mask(width);
+ return result;
+}
+
+/**
+ * Extract signed bits out of a number
+ *
+ * @param input Number to extract from
+ * @param lsb Starting bit, least significant (0-63)
+ * @param width Width in bits (1-64)
+ *
+ * @return Extracted number
+ */
+static inline int64_t bdk_extracts(uint64_t input, int lsb, int width)
+{
+ int64_t result = input >> lsb;
+ result <<= 64 - width;
+ result >>= 64 - width;
+ return result;
+}
+
+/**
+ * Extract a signed magnatude value. Signed magnatude is a value where the MSB
+ * is treated as a sign bit, not like the normal twos compliment
+ *
+ * @param v Value to extract from
+ * @param lsb LSB of number
+ * @param msb MSB, which is the signed bit
+ *
+ * @return Extracted number
+ */
+static inline int64_t bdk_extract_smag(uint64_t v, int lsb, int msb) __attribute__((always_inline));
+static inline int64_t bdk_extract_smag(uint64_t v, int lsb, int msb)
+{
+ int64_t r = bdk_extract(v, lsb, msb - lsb);
+ if (v & (1ull << msb))
+ r = -r;
+ return r;
+}
+
+/**
+ * Insert bits into a number
+ *
+ * @param original Original data, before insert
+ * @param input Data to insert
+ * @param lsb Starting bit, least significant (0-63)
+ * @param width Width in bits (1-64)
+ *
+ * @return Number with inserted bits
+ */
+static inline uint64_t bdk_insert(uint64_t original, uint64_t input, int lsb, int width) __attribute__((always_inline));
+static inline uint64_t bdk_insert(uint64_t original, uint64_t input, int lsb, int width)
+{
+ uint64_t mask = bdk_build_mask(width);
+ uint64_t result = original & ~(mask << lsb);
+ result |= (input & mask) << lsb;
+ return result;
+}
+
+/**
+ * Return the number of cores available in the chip
+ *
+ * @return
+ */
+static inline int bdk_get_num_cores(bdk_node_t node)
+{
+ uint64_t available = BDK_CSR_READ(node, BDK_RST_PP_AVAILABLE);
+ return bdk_dpop(available);
+}
+
+
+/**
+ * Return true if DRAM has been configured
+ *
+ * @return Boolean
+ */
+static inline int __bdk_is_dram_enabled(bdk_node_t node) __attribute__((always_inline));
+static inline int __bdk_is_dram_enabled(bdk_node_t node)
+{
+ BDK_CSR_INIT(lmcx_ddr_pll_ctl, node, BDK_LMCX_DDR_PLL_CTL(0));
+ if (CAVIUM_IS_MODEL(CAVIUM_CN8XXX))
+ return lmcx_ddr_pll_ctl.cn83xx.reset_n;
+ else
+ return !lmcx_ddr_pll_ctl.cn9.pll_reset;
+}
+
+/**
+ * Zero a block of memory
+ *
+ * @param start
+ * @param length
+ */
+static inline void bdk_zero_memory(void *start, uint64_t length) __attribute__((always_inline));
+static inline void bdk_zero_memory(void *start, uint64_t length)
+{
+ if (((long)start & BDK_CACHE_LINE_MASK) || (length & BDK_CACHE_LINE_MASK))
+ {
+ /* Use slwo memset for unaligned memory */
+ memset(start, 0, length);
+ }
+ else
+ {
+ void *end = start + length;
+ while (start<end)
+ {
+ asm volatile ("dc zva,%0" : : "r"(start));
+ start += BDK_CACHE_LINE_SIZE;
+ }
+ }
+}
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-vrm.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-vrm.h
new file mode 100644
index 0000000000..8e6ec38209
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/bdk-vrm.h
@@ -0,0 +1,66 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * Interface to the VRM.
+ *
+ * @addtogroup hal
+ * @{
+ */
+
+/**
+ * Initialize the VRM
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_vrm_initialize(bdk_node_t node);
+
+/**
+ * The VRM may be reporting temperature or other issues with the system. Poll the
+ * VRM and handle any throttling or other actions needed.
+ *
+ * @param node Node to poll
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_vrm_poll(bdk_node_t node);
+
+/** @} */
diff --git a/src/vendorcode/cavium/include/bdk/libbdk-hal/device/bdk-device.h b/src/vendorcode/cavium/include/bdk/libbdk-hal/device/bdk-device.h
new file mode 100644
index 0000000000..3ca3f00710
--- /dev/null
+++ b/src/vendorcode/cavium/include/bdk/libbdk-hal/device/bdk-device.h
@@ -0,0 +1,259 @@
+/***********************license start***********************************
+* Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). All rights
+* reserved.
+*
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are
+* met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* * Redistributions in binary form must reproduce the above
+* copyright notice, this list of conditions and the following
+* disclaimer in the documentation and/or other materials provided
+* with the distribution.
+*
+* * Neither the name of Cavium Inc. nor the names of
+* its contributors may be used to endorse or promote products
+* derived from this software without specific prior written
+* permission.
+*
+* This Software, including technical data, may be subject to U.S. export
+* control laws, including the U.S. Export Administration Act and its
+* associated regulations, and may be subject to export or import
+* regulations in other countries.
+*
+* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
+* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
+* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
+* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
+* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
+* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
+* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
+* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
+* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
+* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
+***********************license end**************************************/
+
+/**
+ * @file
+ *
+ * bdk_device_t represents devices connected using ECAMs. This
+ * are discover by scanning the ECAMs and instantiating devices
+ * for what is found.
+ *
+ * The discovery process for a device is: Scan all ECAMs:
+ * 1) Device found on an ECAM that doesn't have a bdk_device_t
+ * 2) bdk_device_t created, put in
+ * BDK_DEVICE_STATE_NOT_PROBED state
+ * For all devices in state BDK_DEVICE_STATE_NOT_PROBED:
+ * 1) Lookup driver probe() function. If not found, skip
+ * 2) Call probe() 3) Based on probe(), transition to
+ * either BDK_DEVICE_STATE_PROBED or
+ * BDK_DEVICE_STATE_PROBE_FAIL
+ * For all devices in state BDK_DEVICE_STATE_PROBED:
+ * 1) Lookup driver init() function. If not found, skip
+ * 2) Call init() 3) Based on init(), transition to either
+ * BDK_DEVICE_STATE_READY or BDK_DEVICE_STATE_INIT_FAIL
+ * In general all devices should transition to
+ * BDK_DEVICE_STATE_PROBED before any init() functions are
+ * called. This can be used for synchronization. For example,
+ * the FPA should be functional after a probe() so PKI/PKO can
+ * succeed when calling alloc in init().
+ *
+ * @defgroup device ECAM Attached Devices
+ * @addtogroup device
+ * @{
+ */
+
+/**
+ * Possible states of a device
+ */
+typedef enum
+{
+ BDK_DEVICE_STATE_NOT_PROBED, /* Device is known and offline. We haven't probed it */
+ BDK_DEVICE_STATE_PROBE_FAIL, /* Device failed probing and is offline */
+ BDK_DEVICE_STATE_PROBED, /* Device succeeded probing, about to go online */
+ BDK_DEVICE_STATE_INIT_FAIL, /* Device init call failed, offline */
+ BDK_DEVICE_STATE_READY, /* Device init call success, online */
+} bdk_device_state_t;
+
+/**
+ * The structure of a ECAM BAR entry inside if a device
+ */
+typedef struct
+{
+ uint64_t address; /* Base physical address */
+ uint32_t size2; /* Size in bytes as 2^size */
+ uint32_t flags; /* Type flags for the BAR */
+} bdk_device_bar_t;
+
+/**
+ * Defines the BDK's representation of a ECAM connected device
+ */
+typedef struct
+{
+ char name[16]; /* Name of the device */
+ bdk_device_bar_t bar[4]; /* Device BARs, first for better alignment */
+ bdk_device_state_t state : 8; /* Current state of bdk_device_t */
+ bdk_node_t node : 3; /* Node the device is on */
+ uint8_t ecam : 5; /* ECAM for the device */
+ uint8_t bus; /* ECAM bus number (0-255) */
+ uint8_t dev : 5; /* ECAM device (0-31) */
+ uint8_t func : 3; /* ECAM deivce function (0-7) */
+ uint32_t id; /* ECAM device ID */
+ uint16_t instance; /* Cavium internal instance number */
+} bdk_device_t;
+#define BDK_NO_DEVICE_INSTANCE 0xffffu
+
+/**
+ * Defines the main entry points for a device driver. Full
+ * definition is in bdk-device.h
+ */
+struct bdk_driver_s;
+
+/**
+ * Called to register a new driver with the bdk-device system. Drivers are probed
+ * and initialized as device are found for them. If devices have already been
+ * added before the driver was registered, the driver will be probed and
+ * initialized before this function returns.
+ *
+ * @param driver Driver functions
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_device_add_driver(struct bdk_driver_s *driver);
+
+/**
+ * Called by the ECAM code whan a new device is detected in the system
+ *
+ * @param node Node the ECAM is on
+ * @param ecam ECAM the device is on
+ * @param bus Bus number for the device
+ * @param dev Device number
+ * @param func Function number
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_device_add(bdk_node_t node, int ecam, int bus, int dev, int func);
+
+/**
+ * Rename a device. Called by driver to give devices friendly names
+ *
+ * @param device Device to rename
+ * @param format Printf style format string
+ */
+extern void bdk_device_rename(bdk_device_t *device, const char *format, ...) __attribute__ ((format(printf, 2, 3)));
+
+/**
+ * Called by the ECAM code once all devices have been added
+ *
+ * @return Zero on success, negative on failure
+ */
+extern int bdk_device_init(void);
+
+/**
+ * Lookup a device by ECAM ID and internal instance number. This can be used by
+ * one device to find a handle to an associated device. For example, PKI would
+ * use this function to get a handle to the FPA.
+ *
+ * @param node Node to lookup for
+ * @param id ECAM ID
+ * @param instance Cavium internal instance number
+ *
+ * @return Device pointer, or NULL if the device isn't found
+ */
+extern const bdk_device_t *bdk_device_lookup(bdk_node_t node, uint32_t id, int instance);
+
+/**
+ * Read from a device BAR
+ *
+ * @param device Device to read from
+ * @param bar Which BAR to read from (0-3)
+ * @param size Size of the read
+ * @param offset Offset into the BAR
+ *
+ * @return Value read
+ */
+extern uint64_t bdk_bar_read(const bdk_device_t *device, int bar, int size, uint64_t offset);
+
+/**
+ * Write to a device BAR
+ *
+ * @param device Device to write to
+ * @param bar Which BAR to read from (0-3)
+ * @param size Size of the write
+ * @param offset Offset into the BAR
+ * @param value Value to write
+ */
+extern void bdk_bar_write(const bdk_device_t *device, int bar, int size, uint64_t offset, uint64_t value);
+
+/**
+ * This macro makes it easy to define a variable of the correct
+ * type for a BAR.
+ */
+#define BDK_BAR_DEFINE(name, REG) typedef_##REG name
+
+/**
+ * This macro makes it easy to define a variable and initialize it
+ * with a BAR.
+ */
+#define BDK_BAR_INIT(name, device, REG) typedef_##REG name = {.u = bdk_bar_read(device, device_bar_##REG, sizeof(typedef_##REG), REG)}
+
+/**
+ * Macro to read a BAR
+ */
+#define BDK_BAR_READ(device, REG) bdk_bar_read(device, device_bar_##REG, sizeof(typedef_##REG), REG)
+
+/**
+ * Macro to write a BAR
+ */
+#define BDK_BAR_WRITE(device, REG, value) bdk_bar_write(device, device_bar_##REG, sizeof(typedef_##REG), REG, value)
+
+/**
+ * Macro to make a read, modify, and write sequence easy. The "code_block"
+ * should be replaced with a C code block or a comma separated list of
+ * "name.s.field = value", without the quotes.
+ */
+#define BDK_BAR_MODIFY(name, device, REG, code_block) do { \
+ uint64_t _tmp_address = REG; \
+ typedef_##REG name = {.u = bdk_bar_read(device, device_bar_##REG, sizeof(typedef_##REG), _tmp_address)}; \
+ code_block; \
+ bdk_bar_write(device, device_bar_##REG, sizeof(typedef_##REG), _tmp_address, name.u); \
+ } while (0)
+
+/**
+ * This macro spins on a field waiting for it to reach a value. It
+ * is common in code to need to wait for a specific field in a
+ * REG to match a specific value. Conceptually this macro
+ * expands to:
+ *
+ * 1) read REG
+ * 2) Check if ("type".s."field" "op" "value")
+ * 3) If #2 isn't true loop to #1 unless too much time has passed.
+ */
+#define BDK_BAR_WAIT_FOR_FIELD(device, REG, field, op, value, timeout_usec) \
+ ({int result; \
+ do { \
+ uint64_t done = bdk_clock_get_count(BDK_CLOCK_TIME) + (uint64_t)timeout_usec * \
+ bdk_clock_get_rate(bdk_numa_local(), BDK_CLOCK_TIME) / 1000000; \
+ typedef_##REG c; \
+ uint64_t _tmp_address = REG; \
+ while (1) \
+ { \
+ c.u = bdk_bar_read(device, device_bar_##REG, sizeof(typedef_##REG), _tmp_address); \
+ if ((c.s.field) op (value)) { \
+ result = 0; \
+ break; \
+ } else if (bdk_clock_get_count(BDK_CLOCK_TIME) > done) { \
+ result = -1; \
+ break; \
+ } else \
+ bdk_thread_yield(); \
+ } \
+ } while (0); \
+ result;})
+
+/** @} */