1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
3 */
4
5 #include "qat_common.h"
6 #include "qat_device.h"
7 #include "qat_logs.h"
8
9 #define QAT_LEGACY_CAPA "qat_legacy_capa"
10
11 static const char *const arguments[] = {
12 QAT_LEGACY_CAPA,
13 NULL
14 };
15
16 const char *const *qat_cmdline_defines[QAT_MAX_SERVICES + 1] = {
17 [QAT_MAX_SERVICES] = arguments,
18 };
19
20 const char *
qat_service_get_str(enum qat_service_type type)21 qat_service_get_str(enum qat_service_type type)
22 {
23 switch (type) {
24 case QAT_SERVICE_SYMMETRIC:
25 return "sym";
26 case QAT_SERVICE_ASYMMETRIC:
27 return "asym";
28 case QAT_SERVICE_COMPRESSION:
29 return "comp";
30 default:
31 return "invalid";
32 }
33 }
34
35 int
qat_sgl_fill_array(struct rte_mbuf * buf,int64_t offset,void * list_in,uint32_t data_len,const uint16_t max_segs)36 qat_sgl_fill_array(struct rte_mbuf *buf, int64_t offset,
37 void *list_in, uint32_t data_len,
38 const uint16_t max_segs)
39 {
40 int res = -EINVAL;
41 uint32_t buf_len, nr;
42 struct qat_sgl *list = (struct qat_sgl *)list_in;
43 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
44 uint8_t *virt_addr[max_segs];
45 #endif
46
47 for (nr = buf_len = 0; buf && nr < max_segs; buf = buf->next) {
48 if (offset >= rte_pktmbuf_data_len(buf)) {
49 offset -= rte_pktmbuf_data_len(buf);
50 continue;
51 }
52
53 list->buffers[nr].len = rte_pktmbuf_data_len(buf) - offset;
54 list->buffers[nr].resrvd = 0;
55 list->buffers[nr].addr = rte_pktmbuf_iova_offset(buf, offset);
56
57 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
58 virt_addr[nr] = rte_pktmbuf_mtod_offset(buf, uint8_t*, offset);
59 #endif
60 offset = 0;
61 buf_len += list->buffers[nr].len;
62
63 if (buf_len >= data_len) {
64 list->buffers[nr].len -= buf_len - data_len;
65 res = 0;
66 break;
67 }
68 ++nr;
69 }
70
71 if (unlikely(res != 0)) {
72 if (nr == max_segs) {
73 QAT_DP_LOG(ERR, "Exceeded max segments in QAT SGL (%u)",
74 max_segs);
75 } else {
76 QAT_DP_LOG(ERR, "Mbuf chain is too short");
77 }
78 } else {
79
80 list->num_bufs = ++nr;
81 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
82 QAT_DP_LOG(INFO, "SGL with %d buffers:", list->num_bufs);
83 for (nr = 0; nr < list->num_bufs; nr++) {
84 QAT_DP_LOG(INFO,
85 "QAT SGL buf %d, len = %d, iova = 0x%012"PRIx64,
86 nr, list->buffers[nr].len,
87 list->buffers[nr].addr);
88 QAT_DP_HEXDUMP_LOG(DEBUG, "qat SGL",
89 virt_addr[nr],
90 list->buffers[nr].len);
91 }
92 #endif
93 }
94
95 return res;
96 }
97
qat_stats_get(struct qat_pci_device * dev,struct qat_common_stats * stats,enum qat_service_type service)98 void qat_stats_get(struct qat_pci_device *dev,
99 struct qat_common_stats *stats,
100 enum qat_service_type service)
101 {
102 int i;
103 struct qat_qp **qp;
104
105 if (stats == NULL || dev == NULL || service >= QAT_SERVICE_INVALID) {
106 QAT_LOG(ERR, "invalid param: stats %p, dev %p, service %d",
107 stats, dev, service);
108 return;
109 }
110
111 qp = dev->qps_in_use[service];
112 for (i = 0; i < ADF_MAX_QPS_ON_ANY_SERVICE; i++) {
113 if (qp[i] == NULL) {
114 QAT_LOG(DEBUG, "Service %d Uninitialised qp %d",
115 service, i);
116 continue;
117 }
118
119 stats->enqueued_count += qp[i]->stats.enqueued_count;
120 stats->dequeued_count += qp[i]->stats.dequeued_count;
121 stats->enqueue_err_count += qp[i]->stats.enqueue_err_count;
122 stats->dequeue_err_count += qp[i]->stats.dequeue_err_count;
123 stats->threshold_hit_count += qp[i]->stats.threshold_hit_count;
124 QAT_LOG(DEBUG, "Threshold was used for qp %d %"PRIu64" times",
125 i, stats->threshold_hit_count);
126 }
127 }
128
qat_stats_reset(struct qat_pci_device * dev,enum qat_service_type service)129 void qat_stats_reset(struct qat_pci_device *dev,
130 enum qat_service_type service)
131 {
132 int i;
133 struct qat_qp **qp;
134
135 if (dev == NULL || service >= QAT_SERVICE_INVALID) {
136 QAT_LOG(ERR, "invalid param: dev %p, service %d",
137 dev, service);
138 return;
139 }
140
141 qp = dev->qps_in_use[service];
142 for (i = 0; i < ADF_MAX_QPS_ON_ANY_SERVICE; i++) {
143 if (qp[i] == NULL) {
144 QAT_LOG(DEBUG, "Service %d Uninitialised qp %d",
145 service, i);
146 continue;
147 }
148 memset(&(qp[i]->stats), 0, sizeof(qp[i]->stats));
149 }
150
151 QAT_LOG(DEBUG, "QAT: %d stats cleared", service);
152 }
153