1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
// SPDX-License-Identifier: GPL-2.0
/* Marvell RVU Ethernet driver
*
* Copyright (C) 2024 Marvell.
*
*/
#include <linux/bpf_trace.h>
#include <linux/stringify.h>
#include <net/xdp_sock_drv.h>
#include <net/xdp.h>
#include "otx2_common.h"
#include "otx2_xsk.h"
int otx2_xsk_pool_alloc_buf(struct otx2_nic *pfvf, struct otx2_pool *pool,
dma_addr_t *dma, int idx)
{
struct xdp_buff *xdp;
int delta;
xdp = xsk_buff_alloc(pool->xsk_pool);
if (!xdp)
return -ENOMEM;
pool->xdp[pool->xdp_top++] = xdp;
*dma = OTX2_DATA_ALIGN(xsk_buff_xdp_get_dma(xdp));
/* Adjust xdp->data for unaligned addresses */
delta = *dma - xsk_buff_xdp_get_dma(xdp);
xdp->data += delta;
return 0;
}
static int otx2_xsk_ctx_disable(struct otx2_nic *pfvf, u16 qidx, int aura_id)
{
struct nix_cn10k_aq_enq_req *cn10k_rq_aq;
struct npa_aq_enq_req *aura_aq;
struct npa_aq_enq_req *pool_aq;
struct nix_aq_enq_req *rq_aq;
if (test_bit(CN10K_LMTST, &pfvf->hw.cap_flag)) {
cn10k_rq_aq = otx2_mbox_alloc_msg_nix_cn10k_aq_enq(&pfvf->mbox);
if (!cn10k_rq_aq)
return -ENOMEM;
cn10k_rq_aq->qidx = qidx;
cn10k_rq_aq->rq.ena = 0;
cn10k_rq_aq->rq_mask.ena = 1;
cn10k_rq_aq->ctype = NIX_AQ_CTYPE_RQ;
cn10k_rq_aq->op = NIX_AQ_INSTOP_WRITE;
} else {
rq_aq = otx2_mbox_alloc_msg_nix_aq_enq(&pfvf->mbox);
if (!rq_aq)
return -ENOMEM;
rq_aq->qidx = qidx;
rq_aq->sq.ena = 0;
rq_aq->sq_mask.ena = 1;
rq_aq->ctype = NIX_AQ_CTYPE_RQ;
rq_aq->op = NIX_AQ_INSTOP_WRITE;
}
aura_aq = otx2_mbox_alloc_msg_npa_aq_enq(&pfvf->mbox);
if (!aura_aq)
goto fail;
aura_aq->aura_id = aura_id;
aura_aq->aura.ena = 0;
aura_aq->aura_mask.ena = 1;
aura_aq->ctype = NPA_AQ_CTYPE_AURA;
aura_aq->op = NPA_AQ_INSTOP_WRITE;
pool_aq = otx2_mbox_alloc_msg_npa_aq_enq(&pfvf->mbox);
if (!pool_aq)
goto fail;
pool_aq->aura_id = aura_id;
pool_aq->pool.ena = 0;
pool_aq->pool_mask.ena = 1;
pool_aq->ctype = NPA_AQ_CTYPE_POOL;
pool_aq->op = NPA_AQ_INSTOP_WRITE;
return otx2_sync_mbox_msg(&pfvf->mbox);
fail:
otx2_mbox_reset(&pfvf->mbox.mbox, 0);
return -ENOMEM;
}
static void otx2_clean_up_rq(struct otx2_nic *pfvf, int qidx)
{
struct otx2_qset *qset = &pfvf->qset;
struct otx2_cq_queue *cq;
struct otx2_pool *pool;
u64 iova;
/* If the DOWN flag is set SQs are already freed */
if (pfvf->flags & OTX2_FLAG_INTF_DOWN)
return;
cq = &qset->cq[qidx];
if (cq)
otx2_cleanup_rx_cqes(pfvf, cq, qidx);
pool = &pfvf->qset.pool[qidx];
iova = otx2_aura_allocptr(pfvf, qidx);
while (iova) {
iova -= OTX2_HEAD_ROOM;
otx2_free_bufs(pfvf, pool, iova, pfvf->rbsize);
iova = otx2_aura_allocptr(pfvf, qidx);
}
mutex_lock(&pfvf->mbox.lock);
otx2_xsk_ctx_disable(pfvf, qidx, qidx);
mutex_unlock(&pfvf->mbox.lock);
}
int otx2_xsk_pool_enable(struct otx2_nic *pf, struct xsk_buff_pool *pool, u16 qidx)
{
u16 rx_queues = pf->hw.rx_queues;
u16 tx_queues = pf->hw.tx_queues;
int err;
if (qidx >= rx_queues || qidx >= tx_queues)
return -EINVAL;
err = xsk_pool_dma_map(pool, pf->dev, DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING);
if (err)
return err;
set_bit(qidx, pf->af_xdp_zc_qidx);
otx2_clean_up_rq(pf, qidx);
/* Kick start the NAPI context so that receiving will start */
return otx2_xsk_wakeup(pf->netdev, qidx, XDP_WAKEUP_RX);
}
int otx2_xsk_pool_disable(struct otx2_nic *pf, u16 qidx)
{
struct net_device *netdev = pf->netdev;
struct xsk_buff_pool *pool;
pool = xsk_get_pool_from_qid(netdev, qidx);
if (!pool)
return -EINVAL;
otx2_clean_up_rq(pf, qidx);
clear_bit(qidx, pf->af_xdp_zc_qidx);
xsk_pool_dma_unmap(pool, DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING);
return 0;
}
int otx2_xsk_pool_setup(struct otx2_nic *pf, struct xsk_buff_pool *pool, u16 qidx)
{
if (pool)
return otx2_xsk_pool_enable(pf, pool, qidx);
return otx2_xsk_pool_disable(pf, qidx);
}
int otx2_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags)
{
struct otx2_nic *pf = netdev_priv(dev);
struct otx2_cq_poll *cq_poll = NULL;
struct otx2_qset *qset = &pf->qset;
if (pf->flags & OTX2_FLAG_INTF_DOWN)
return -ENETDOWN;
if (queue_id >= pf->hw.rx_queues)
return -EINVAL;
cq_poll = &qset->napi[queue_id];
if (!cq_poll)
return -EINVAL;
/* Trigger interrupt */
if (!napi_if_scheduled_mark_missed(&cq_poll->napi))
otx2_write64(pf, NIX_LF_CINTX_ENA_W1S(cq_poll->cint_idx), BIT_ULL(0));
return 0;
}
|