Files
nvethernetrm/osi/core/debug.c
Sanath Kumar Gampa db9b81458e nvethernetrm: Fix top-25 MISRA issues
Fixed below rules:
CERT STR31-C
CERT INT32-C
CERT INT30-C
CERT INT08-C
CERT ARR30-C
CERT EXP39-C
OVERFLOW_BEFORE_WIDEN

Jira NET-2045

Change-Id: I2f86e110747a6a4e21b1bf80af2e7a98ad51f3db
Signed-off-by: Sanath Kumar Gampa <sgampa@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/kernel/nvethernetrm/+/3275363
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Reviewed-by: Mohan Thadikamalla <mohant@nvidia.com>
GVS: buildbot_gerritrpt <buildbot_gerritrpt@nvidia.com>
Reviewed-by: svcacv <svcacv@nvidia.com>
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: Ashutosh Jha <ajha@nvidia.com>
2025-02-27 17:03:36 -08:00

151 lines
4.6 KiB
C

// SPDX-License-Identifier: MIT
/* SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. 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.
*/
#ifdef OSI_DEBUG
#include "debug.h"
/**
* @brief core_dump_struct - Dumps a given structure.
*
* @param[in] osi_core: OSI DMA private data structure.
* @param[in] ptr: Pointer to structure.
* @param[in] size: Size of structure to dump.
*
*/
static void core_dump_struct(struct osi_core_priv_data *osi_core,
nveu8_t *ptr,
unsigned long size)
{
nveu32_t i = 0, rem, j = 0;
unsigned long temp;
if (ptr == OSI_NULL) {
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"pointer is NULL\n");
return;
}
rem = i % 4;
temp = size - rem;
for (i = 0; i < temp; i += 4) {
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"%02x%02x%02x%02x", ptr[i], ptr[i + 1],
ptr[i + 2], ptr[i + 3]);
j = i;
}
for (i = j; i < size; i++) {
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS, "%x",
ptr[i]);
}
}
/**
* @brief core_structs_dump - Dumps OSI CORE structure.
*
* @param[in] osi_core: OSI CORE private data structure.
*/
void core_structs_dump(struct osi_core_priv_data *osi_core)
{
struct core_local *l_core = (struct core_local *)((void *)osi_core);
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"CORE struct size = %lu",
sizeof(struct osi_core_priv_data));
core_dump_struct(osi_core, (nveu8_t *)osi_core,
sizeof(struct osi_core_priv_data));
#ifdef MACSEC_SUPPORT
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"MACSEC ops size = %lu",
sizeof(struct osi_macsec_core_ops));
core_dump_struct(osi_core, (nveu8_t *)l_core->macsec_ops,
sizeof(struct osi_macsec_core_ops));
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"MACSEC LUT status size = %lu",
sizeof(struct osi_macsec_lut_status));
core_dump_struct(osi_core, (nveu8_t *)l_core->macsec_ops,
sizeof(struct osi_macsec_lut_status));
#endif
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"HW features size = %lu",
sizeof(struct osi_hw_features));
core_dump_struct(osi_core, (nveu8_t *)&l_core->hw_features,
sizeof(struct osi_hw_features));
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"core local size = %lu",
sizeof(struct core_local));
core_dump_struct(osi_core, (nveu8_t *)l_core,
sizeof(struct core_local));
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"core ops size = %lu",
sizeof(struct core_ops));
core_dump_struct(osi_core, (nveu8_t *)l_core->ops_p,
sizeof(struct core_ops));
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_STRUCTS,
"if_ops_p struct size = %lu",
sizeof(struct if_core_ops));
core_dump_struct(osi_core, (nveu8_t *)l_core->if_ops_p,
sizeof(struct if_core_ops));
}
/**
* @brief reg_dump - Dumps MAC DMA registers
*
* @param[in] osi_core: OSI core private data structure.
*/
void core_reg_dump(struct osi_core_priv_data *osi_core)
{
nveu32_t max_addr;
nveu32_t addr = 0x0;
nveu32_t reg_val;
switch (osi_core->mac_ver) {
case OSI_EQOS_MAC_5_00:
max_addr = 0x12E4;
break;
case OSI_EQOS_MAC_5_30:
case OSI_EQOS_MAC_5_40:
max_addr = 0x14EC;
break;
case OSI_MGBE_MAC_3_10:
case OSI_MGBE_MAC_4_20:
max_addr = 0x35FC;
break;
default:
return;
}
while (1) {
if (addr > max_addr)
break;
reg_val = osi_readla(osi_core,
(nveu8_t *)osi_core->base + addr);
osi_core->osd_ops.printf(osi_core, OSI_DEBUG_TYPE_REG,
"%x: %x\n", addr, reg_val);
addr += 4;
}
}
#endif