1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2015-2018 Atomic Rules LLC 3 */ 4 5 #include <unistd.h> 6 7 #include "ark_logs.h" 8 #include "ark_ddm.h" 9 10 static_assert(sizeof(union ark_tx_meta) == 8, "Unexpected struct size ark_tx_meta"); 11 12 /* ************************************************************************* */ 13 int 14 ark_ddm_verify(struct ark_ddm_t *ddm) 15 { 16 uint32_t hw_const; 17 uint32_t hw_ver; 18 if (sizeof(struct ark_ddm_t) != ARK_DDM_EXPECTED_SIZE) { 19 ARK_PMD_LOG(ERR, "DDM structure looks incorrect %d vs %zd\n", 20 ARK_DDM_EXPECTED_SIZE, sizeof(struct ark_ddm_t)); 21 return -1; 22 } 23 24 hw_const = ddm->cfg.idnum; 25 hw_ver = ddm->cfg.vernum; 26 if (hw_const == ARK_DDM_MODID && hw_ver == ARK_DDM_MODVER) 27 return 0; 28 29 ARK_PMD_LOG(ERR, 30 "ARK: DDM module not found as expected" 31 " id: %08x ver: %08x\n", 32 hw_const, hw_ver); 33 return -1; 34 } 35 36 void 37 ark_ddm_queue_enable(struct ark_ddm_t *ddm, int enable) 38 { 39 ddm->setup.qcommand = enable ? 1U : 0U; 40 } 41 42 void 43 ark_ddm_queue_setup(struct ark_ddm_t *ddm, rte_iova_t cons_addr) 44 { 45 ddm->setup.cons_write_index_addr = cons_addr; 46 ddm->setup.cons_index = 0; 47 } 48 49 /* Global stats clear */ 50 void 51 ark_ddm_stats_reset(struct ark_ddm_t *ddm) 52 { 53 ddm->cfg.tlp_stats_clear = 1; 54 } 55 56 void 57 ark_ddm_dump_stats(struct ark_ddm_t *ddm, const char *msg) 58 { 59 struct ark_ddm_stats_t *stats = &ddm->stats; 60 61 ARK_PMD_LOG(INFO, "DDM Stats: %s" 62 ARK_SU64 ARK_SU64 ARK_SU64 63 "\n", msg, 64 "Bytes:", stats->tx_byte_count, 65 "Packets:", stats->tx_pkt_count, 66 "MBufs", stats->tx_mbuf_count); 67 } 68 69 uint64_t 70 ark_ddm_queue_byte_count(struct ark_ddm_t *ddm) 71 { 72 return ddm->queue_stats.byte_count; 73 } 74 75 uint64_t 76 ark_ddm_queue_pkt_count(struct ark_ddm_t *ddm) 77 { 78 return ddm->queue_stats.pkt_count; 79 } 80 81 void 82 ark_ddm_queue_reset_stats(struct ark_ddm_t *ddm) 83 { 84 ddm->queue_stats.byte_count = 1; 85 } 86