LCOV - code coverage report
Current view: top level - drivers/net/nfp/nfpcore - nfp_crc.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 10 0.0 %
Date: 2024-01-22 15:35:40 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 14 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2018 Netronome Systems, Inc.
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <stdio.h>
       7                 :            : #include <inttypes.h>
       8                 :            : 
       9                 :            : #include "nfp_crc.h"
      10                 :            : 
      11                 :            : static inline uint32_t
      12                 :            : nfp_crc32_be_generic(uint32_t crc,
      13                 :            :                 unsigned char const *p,
      14                 :            :                 size_t len,
      15                 :            :                 uint32_t polynomial)
      16                 :            : {
      17                 :            :         uint32_t i;
      18                 :            : 
      19   [ #  #  #  # ]:          0 :         while (len--) {
      20                 :          0 :                 crc ^= *p++ << 24;
      21   [ #  #  #  # ]:          0 :                 for (i = 0; i < 8; i++)
      22   [ #  #  #  # ]:          0 :                         crc = (crc << 1) ^ ((crc & 0x80000000) ? polynomial : 0);
      23                 :            :         }
      24                 :            : 
      25                 :            :         return crc;
      26                 :            : }
      27                 :            : 
      28                 :            : static inline uint32_t
      29                 :            : nfp_crc32_be(uint32_t crc,
      30                 :            :                 unsigned char const *p,
      31                 :            :                 size_t len)
      32                 :            : {
      33                 :            :         return nfp_crc32_be_generic(crc, p, len, CRCPOLY_BE);
      34                 :            : }
      35                 :            : 
      36                 :            : static uint32_t
      37                 :            : nfp_crc32_posix_end(uint32_t crc,
      38                 :            :                 size_t total_len)
      39                 :            : {
      40                 :            :         /* Extend with the length of the string. */
      41         [ #  # ]:          0 :         while (total_len != 0) {
      42                 :          0 :                 uint8_t c = total_len & 0xff;
      43                 :            : 
      44                 :            :                 crc = nfp_crc32_be(crc, &c, 1);
      45                 :          0 :                 total_len >>= 8;
      46                 :            :         }
      47                 :            : 
      48                 :          0 :         return ~crc;
      49                 :            : }
      50                 :            : 
      51                 :            : uint32_t
      52                 :          0 : nfp_crc32_posix(const void *buff,
      53                 :            :                 size_t len)
      54                 :            : {
      55                 :          0 :         return nfp_crc32_posix_end(nfp_crc32_be(0, buff, len), len);
      56                 :            : }

Generated by: LCOV version 1.14