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