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_udm.h" 9 10 static_assert(sizeof(struct ark_rx_meta) == 32, "Unexpected struct size ark_rx_meta"); 11 12 int 13 ark_udm_verify(struct ark_udm_t *udm) 14 { 15 if (sizeof(struct ark_udm_t) != ARK_UDM_EXPECT_SIZE) { 16 ARK_PMD_LOG(ERR, 17 "ARK: UDM structure looks incorrect %d vs %zd\n", 18 ARK_UDM_EXPECT_SIZE, sizeof(struct ark_udm_t)); 19 return -1; 20 } 21 22 if (udm->setup.const0 != ARK_UDM_CONST) { 23 ARK_PMD_LOG(ERR, 24 "ARK: UDM module not found as expected 0x%08x\n", 25 udm->setup.const0); 26 return -1; 27 } 28 return 0; 29 } 30 31 int 32 ark_udm_stop(struct ark_udm_t *udm, const int wait) 33 { 34 int cnt = 0; 35 36 udm->cfg.command = 2; 37 38 while (wait && (udm->cfg.stop_flushed & 0x01) == 0) { 39 if (cnt++ > 1000) 40 return 1; 41 42 usleep(10); 43 } 44 return 0; 45 } 46 47 int 48 ark_udm_reset(struct ark_udm_t *udm) 49 { 50 int status; 51 52 status = ark_udm_stop(udm, 1); 53 if (status != 0) { 54 ARK_PMD_LOG(NOTICE, "%s stop failed doing forced reset\n", 55 __func__); 56 udm->cfg.command = 4; 57 usleep(10); 58 udm->cfg.command = 3; 59 status = ark_udm_stop(udm, 0); 60 ARK_PMD_LOG(INFO, "%s stop status %d post failure" 61 " and forced reset\n", 62 __func__, status); 63 } else { 64 udm->cfg.command = 3; 65 } 66 67 return status; 68 } 69 70 void 71 ark_udm_start(struct ark_udm_t *udm) 72 { 73 udm->cfg.command = 1; 74 } 75 76 void 77 ark_udm_stats_reset(struct ark_udm_t *udm) 78 { 79 udm->pcibp.pci_clear = 1; 80 udm->tlp_ps.tlp_clear = 1; 81 } 82 83 void 84 ark_udm_configure(struct ark_udm_t *udm, 85 uint32_t headroom, 86 uint32_t dataroom, 87 uint32_t write_interval_ns) 88 { 89 /* headroom and data room are in DWords in the UDM */ 90 udm->cfg.dataroom = dataroom / 4; 91 udm->cfg.headroom = headroom / 4; 92 93 /* 4 NS period ns */ 94 udm->rt_cfg.write_interval = write_interval_ns / 4; 95 } 96 97 void 98 ark_udm_write_addr(struct ark_udm_t *udm, rte_iova_t addr) 99 { 100 udm->rt_cfg.hw_prod_addr = addr; 101 } 102 103 int 104 ark_udm_is_flushed(struct ark_udm_t *udm) 105 { 106 return (udm->cfg.stop_flushed & 0x01) != 0; 107 } 108 109 uint64_t 110 ark_udm_dropped(struct ark_udm_t *udm) 111 { 112 return udm->qstats.q_pkt_drop; 113 } 114 115 uint64_t 116 ark_udm_bytes(struct ark_udm_t *udm) 117 { 118 return udm->qstats.q_byte_count; 119 } 120 121 uint64_t 122 ark_udm_packets(struct ark_udm_t *udm) 123 { 124 return udm->qstats.q_ff_packet_count; 125 } 126 127 void 128 ark_udm_dump_stats(struct ark_udm_t *udm, const char *msg) 129 { 130 ARK_PMD_LOG(INFO, "UDM Stats: %s" 131 ARK_SU64 ARK_SU64 ARK_SU64 ARK_SU64 ARK_SU64 "\n", 132 msg, 133 "Pkts Received", udm->stats.rx_packet_count, 134 "Pkts Finalized", udm->stats.rx_sent_packets, 135 "Pkts Dropped", udm->tlp.pkt_drop, 136 "Bytes Count", udm->stats.rx_byte_count, 137 "MBuf Count", udm->stats.rx_mbuf_count); 138 } 139 140 void 141 ark_udm_dump_queue_stats(struct ark_udm_t *udm, const char *msg, uint16_t qid) 142 { 143 ARK_PMD_LOG(INFO, "UDM Queue %3u Stats: %s" 144 ARK_SU64 ARK_SU64 145 ARK_SU64 ARK_SU64 146 ARK_SU64 "\n", 147 qid, msg, 148 "Pkts Received", udm->qstats.q_packet_count, 149 "Pkts Finalized", udm->qstats.q_ff_packet_count, 150 "Pkts Dropped", udm->qstats.q_pkt_drop, 151 "Bytes Count", udm->qstats.q_byte_count, 152 "MBuf Count", udm->qstats.q_mbuf_count); 153 } 154 155 void 156 ark_udm_dump(struct ark_udm_t *udm, const char *msg) 157 { 158 ARK_PMD_LOG(DEBUG, "UDM Dump: %s Stopped: %d\n", msg, 159 udm->cfg.stop_flushed); 160 } 161 162 void 163 ark_udm_dump_setup(struct ark_udm_t *udm, uint16_t q_id) 164 { 165 ARK_PMD_LOG(DEBUG, "UDM Setup Q: %u" 166 ARK_SU64X ARK_SU32 "\n", 167 q_id, 168 "hw_prod_addr", udm->rt_cfg.hw_prod_addr, 169 "prod_idx", udm->rt_cfg.prod_idx); 170 } 171 172 void 173 ark_udm_dump_perf(struct ark_udm_t *udm, const char *msg) 174 { 175 struct ark_udm_pcibp_t *bp = &udm->pcibp; 176 177 ARK_PMD_LOG(INFO, "UDM Performance %s" 178 ARK_SU32 ARK_SU32 ARK_SU32 ARK_SU32 ARK_SU32 ARK_SU32 179 "\n", 180 msg, 181 "PCI Empty", bp->pci_empty, 182 "PCI Q1", bp->pci_q1, 183 "PCI Q2", bp->pci_q2, 184 "PCI Q3", bp->pci_q3, 185 "PCI Q4", bp->pci_q4, 186 "PCI Full", bp->pci_full); 187 } 188 189 void 190 ark_udm_queue_stats_reset(struct ark_udm_t *udm) 191 { 192 udm->qstats.q_byte_count = 1; 193 } 194 195 void 196 ark_udm_queue_enable(struct ark_udm_t *udm, int enable) 197 { 198 udm->qstats.q_enable = enable ? 1 : 0; 199 } 200