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 /* ************************************************************************* */ 11 int 12 ark_ddm_verify(struct ark_ddm_t *ddm) 13 { 14 if (sizeof(struct ark_ddm_t) != ARK_DDM_EXPECTED_SIZE) { 15 PMD_DRV_LOG(ERR, "ARK: DDM structure looks incorrect %d vs %zd\n", 16 ARK_DDM_EXPECTED_SIZE, sizeof(struct ark_ddm_t)); 17 return -1; 18 } 19 20 if (ddm->cfg.const0 != ARK_DDM_CONST) { 21 PMD_DRV_LOG(ERR, "ARK: DDM module not found as expected 0x%08x\n", 22 ddm->cfg.const0); 23 return -1; 24 } 25 return 0; 26 } 27 28 void 29 ark_ddm_start(struct ark_ddm_t *ddm) 30 { 31 ddm->cfg.command = 1; 32 } 33 34 int 35 ark_ddm_stop(struct ark_ddm_t *ddm, const int wait) 36 { 37 int cnt = 0; 38 39 ddm->cfg.command = 2; 40 while (wait && (ddm->cfg.stop_flushed & 0x01) == 0) { 41 if (cnt++ > 1000) 42 return 1; 43 44 usleep(10); 45 } 46 return 0; 47 } 48 49 void 50 ark_ddm_reset(struct ark_ddm_t *ddm) 51 { 52 int status; 53 54 /* reset only works if ddm has stopped properly. */ 55 status = ark_ddm_stop(ddm, 1); 56 57 if (status != 0) { 58 PMD_DEBUG_LOG(INFO, "%s stop failed doing forced reset\n", 59 __func__); 60 ddm->cfg.command = 4; 61 usleep(10); 62 } 63 ddm->cfg.command = 3; 64 } 65 66 void 67 ark_ddm_setup(struct ark_ddm_t *ddm, rte_iova_t cons_addr, uint32_t interval) 68 { 69 ddm->setup.cons_write_index_addr = cons_addr; 70 ddm->setup.write_index_interval = interval / 4; /* 4 ns period */ 71 } 72 73 void 74 ark_ddm_stats_reset(struct ark_ddm_t *ddm) 75 { 76 ddm->cfg.tlp_stats_clear = 1; 77 } 78 79 void 80 ark_ddm_dump(struct ark_ddm_t *ddm, const char *msg) 81 { 82 PMD_FUNC_LOG(DEBUG, "%s Stopped: %d\n", msg, 83 ark_ddm_is_stopped(ddm) 84 ); 85 } 86 87 void 88 ark_ddm_dump_stats(struct ark_ddm_t *ddm, const char *msg) 89 { 90 struct ark_ddm_stats_t *stats = &ddm->stats; 91 92 PMD_STATS_LOG(INFO, "DDM Stats: %s" 93 ARK_SU64 ARK_SU64 ARK_SU64 94 "\n", msg, 95 "Bytes:", stats->tx_byte_count, 96 "Packets:", stats->tx_pkt_count, 97 "MBufs", stats->tx_mbuf_count); 98 } 99 100 int 101 ark_ddm_is_stopped(struct ark_ddm_t *ddm) 102 { 103 return (ddm->cfg.stop_flushed & 0x01) != 0; 104 } 105 106 uint64_t 107 ark_ddm_queue_byte_count(struct ark_ddm_t *ddm) 108 { 109 return ddm->queue_stats.byte_count; 110 } 111 112 uint64_t 113 ark_ddm_queue_pkt_count(struct ark_ddm_t *ddm) 114 { 115 return ddm->queue_stats.pkt_count; 116 } 117 118 void 119 ark_ddm_queue_reset_stats(struct ark_ddm_t *ddm) 120 { 121 ddm->queue_stats.byte_count = 1; 122 } 123