Files
nvethernetrm/osi/common/common.h
rakesh goyal 8829d1a4e5 osi: eqos: only interface APIs accessible form OSD
Issue:	Many non API functions are accessible from
	OSD code which can be used to update/access
	HW registers.
Fix:	Move non API function to local files and
	remove header files from code shared with OSD
	so these function can be accessible only
	within OSI code

Bug 200671160

Change-Id: Ic396b3b34e20cd8ee6b252e745df12f4532d0e10
Signed-off-by: rakesh goyal <rgoyal@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/kernel/nvethernetrm/+/2494297
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
2023-02-13 19:43:20 +05:30

278 lines
6.6 KiB
C

/*
* Copyright (c) 2020-2021, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef INCLUDED_COMMON_H
#define INCLUDED_COMMON_H
#include "../osi/common/type.h"
#include <osi_common.h>
struct osi_core_priv_data;
/**
* @brief osi_lock_init - Initialize lock to unlocked state.
*
* @note
* Algorithm:
* - Set lock to unlocked state.
*
* @param[in] lock - Pointer to lock to be initialized
*
* @note
* API Group:
* - Initialization: Yes
* - Run time: No
* - De-initialization: No
*/
static inline void osi_lock_init(nveu32_t *lock)
{
*lock = OSI_UNLOCKED;
}
/**
* @brief osi_lock_irq_enabled - Spin lock. Busy loop till lock is acquired.
*
* @note
* Algorithm:
* - Atomic compare and swap operation till lock is held.
*
* @param[in] lock - Pointer to lock to be acquired.
*
* @note
* - Does not disable irq. Do not call this API to acquire any
* lock that is shared between top/bottom half. It will result in deadlock.
*
* @note
* API Group:
* - Initialization: No
* - Run time: Yes
* - De-initialization: No
*/
static inline void osi_lock_irq_enabled(nveu32_t *lock)
{
/* __sync_val_compare_and_swap(lock, old value, new value) returns the
* old value if successful.
*/
while (__sync_val_compare_and_swap(lock, OSI_UNLOCKED, OSI_LOCKED) !=
OSI_UNLOCKED) {
/* Spinning.
* Will deadlock if any ISR tried to lock again.
*/
}
}
/**
* @brief osi_unlock_irq_enabled - Release lock.
*
* @note
* Algorithm:
* - Atomic compare and swap operation to release lock.
*
* @param[in] lock - Pointer to lock to be released.
*
* @note
* - Does not disable irq. Do not call this API to release any
* lock that is shared between top/bottom half.
*
* @note
* API Group:
* - Initialization: No
* - Run time: Yes
* - De-initialization: No
*/
static inline void osi_unlock_irq_enabled(nveu32_t *lock)
{
if (__sync_val_compare_and_swap(lock, OSI_LOCKED, OSI_UNLOCKED) !=
OSI_LOCKED) {
/* Do nothing. Already unlocked */
}
}
/**
* @brief osi_readl - Read a memory mapped register.
*
* @param[in] addr: Memory mapped address.
*
* @pre Physical address has to be memory mapped.
*
* @return Data from memory mapped register - success.
*
* @note
* API Group:
* - Initialization: Yes
* - Run time: Yes
* - De-initialization: Yes
*/
static inline nveu32_t osi_readl(void *addr)
{
return *(volatile nveu32_t *)addr;
}
/**
* @brief osi_writel - Write to a memory mapped register.
*
* @param[in] val: Value to be written.
* @param[in] addr: Memory mapped address.
*
* @pre Physical address has to be memory mapped.
*
* @note
* API Group:
* - Initialization: Yes
* - Run time: Yes
* - De-initialization: Yes
*/
static inline void osi_writel(nveu32_t val, void *addr)
{
*(volatile nveu32_t *)addr = val;
}
#ifdef ETHERNET_SERVER
nveu32_t osi_readla(void *priv, void *addr);
void osi_writela(void *priv, nveu32_t val, void *addr);
#else
/**
* @brief osi_readla - Read a memory mapped register.
*
* @ note
* The difference between osi_readla & osi_readl is osi_core argument.
* In case of ethernet server, osi_core used to define policy for each VM.
* In case of non virtualization osi_core argument is ignored.
*
* @param[in] priv: Priv address.
* @param[in] addr: Memory mapped address.
*
* @note Physical address has to be memmory mapped.
*
* @return Data from memory mapped register - success.
*/
static inline nveu32_t osi_readla(void *priv, void *addr)
{
return *(volatile nveu32_t *)addr;
}
/**
*
* @ note
* @brief osi_writela - Write to a memory mapped register.
* The difference between osi_writela & osi_writel is osi_core argument.
* In case of ethernet server, osi_core used to define policy for each VM.
* In case of non virtualization osi_core argument is ignored.
*
* @param[in] priv: Priv address.
* @param[in] val: Value to be written.
* @param[in] addr: Memory mapped address.
*
* @note Physical address has to be memmory mapped.
*/
static inline void osi_writela(void *priv, nveu32_t val, void *addr)
{
*(volatile nveu32_t *)addr = val;
}
#endif
/**
* @brief is_valid_mac_version - Check if read MAC IP is valid or not.
*
* @param[in] mac_ver: MAC version read.
*
* @note MAC has to be out of reset.
*
* @note
* API Group:
* - Initialization: Yes
* - Run time: No
* - De-initialization: No
*
* @retval 0 - for not Valid MAC
* @retval 1 - for Valid MAC
*/
static inline nve32_t is_valid_mac_version(nveu32_t mac_ver)
{
if ((mac_ver == OSI_EQOS_MAC_4_10) ||
(mac_ver == OSI_EQOS_MAC_5_00) ||
(mac_ver == OSI_EQOS_MAC_5_30)) {
return 1;
}
return 0;
}
/**
* @brief osi_memset - osi memset
*
* @param[out] s: source that need to be set
* @param[in] c: value to fill in source
* @param[in] count: first n bytes of source
*
* @note
* API Group:
* - Initialization: No
* - Run time: Yes
* - De-initialization: No
*/
static inline void osi_memset(void *s, nveu32_t c, nveu64_t count)
{
nveu8_t *xs = OSI_NULL;
nveu64_t temp = count;
if (s == OSI_NULL) {
return;
}
xs = (nveu8_t *)s;
while (temp != 0UL) {
if (c < OSI_UCHAR_MAX) {
*xs = (nveu8_t)c;
xs++;
}
temp--;
}
}
/**
* @brief osi_memcpy - osi memcpy
*
* @param[out] dest: destination pointer
* @param[in] src: source pointer
* @param[in] n: number bytes of source
*
* @note
* API Group:
* - Initialization: No
* - Run time: Yes
* - De-initialization: No
*/
static inline void osi_memcpy(void *dest, void *src, int n)
{
char *csrc = (char *)src;
char *cdest = (char *)dest;
int i = 0;
if (src == OSI_NULL || dest == OSI_NULL) {
return;
}
for (i = 0; i < n; i++) {
cdest[i] = csrc[i];
}
}
#endif