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