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 rte_wmb(); 59 while (wait && (ddm->cfg.stop_flushed & 0x01) == 0) { 60 if (cnt++ > 1000) 61 return 1; 62 63 usleep(10); 64 } 65 return 0; 66 } 67 68 void 69 ark_ddm_reset(struct ark_ddm_t *ddm) 70 { 71 int status; 72 73 /* reset only works if ddm has stopped properly. */ 74 status = ark_ddm_stop(ddm, 1); 75 76 if (status != 0) { 77 ARK_PMD_LOG(NOTICE, "%s stop failed doing forced reset\n", 78 __func__); 79 ddm->cfg.command = 4; 80 usleep(10); 81 } 82 ddm->cfg.command = 3; 83 } 84 85 void 86 ark_ddm_setup(struct ark_ddm_t *ddm, rte_iova_t cons_addr, uint32_t interval) 87 { 88 ddm->setup.cons_write_index_addr = cons_addr; 89 ddm->setup.write_index_interval = interval / 4; /* 4 ns period */ 90 } 91 92 void 93 ark_ddm_stats_reset(struct ark_ddm_t *ddm) 94 { 95 ddm->cfg.tlp_stats_clear = 1; 96 } 97 98 void 99 ark_ddm_dump(struct ark_ddm_t *ddm, const char *msg) 100 { 101 ARK_PMD_LOG(DEBUG, "%s Stopped: %d\n", msg, 102 ark_ddm_is_stopped(ddm) 103 ); 104 } 105 106 void 107 ark_ddm_dump_stats(struct ark_ddm_t *ddm, const char *msg) 108 { 109 struct ark_ddm_stats_t *stats = &ddm->stats; 110 111 ARK_PMD_LOG(INFO, "DDM Stats: %s" 112 ARK_SU64 ARK_SU64 ARK_SU64 113 "\n", msg, 114 "Bytes:", stats->tx_byte_count, 115 "Packets:", stats->tx_pkt_count, 116 "MBufs", stats->tx_mbuf_count); 117 } 118 119 int 120 ark_ddm_is_stopped(struct ark_ddm_t *ddm) 121 { 122 return (ddm->cfg.stop_flushed & 0x01) != 0; 123 } 124 125 uint64_t 126 ark_ddm_queue_byte_count(struct ark_ddm_t *ddm) 127 { 128 return ddm->queue_stats.byte_count; 129 } 130 131 uint64_t 132 ark_ddm_queue_pkt_count(struct ark_ddm_t *ddm) 133 { 134 return ddm->queue_stats.pkt_count; 135 } 136 137 void 138 ark_ddm_queue_reset_stats(struct ark_ddm_t *ddm) 139 { 140 ddm->queue_stats.byte_count = 1; 141 } 142