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