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