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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
// SPDX-License-Identifier: GPL-2.0
/* Marvell Octeon EP (EndPoint) VF Ethernet Driver
*
* Copyright (C) 2020 Marvell.
*
*/
#include <linux/pci.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include "octep_vf_config.h"
#include "octep_vf_main.h"
#include "octep_vf_regs_cnxk.h"
/* Dump useful hardware IQ/OQ CSRs for debug purpose */
static void cnxk_vf_dump_q_regs(struct octep_vf_device *oct, int qno)
{
struct device *dev = &oct->pdev->dev;
dev_info(dev, "IQ-%d register dump\n", qno);
dev_info(dev, "R[%d]_IN_INSTR_DBELL[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_INSTR_DBELL(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_DBELL(qno)));
dev_info(dev, "R[%d]_IN_CONTROL[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_CONTROL(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_CONTROL(qno)));
dev_info(dev, "R[%d]_IN_ENABLE[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_ENABLE(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_ENABLE(qno)));
dev_info(dev, "R[%d]_IN_INSTR_BADDR[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_INSTR_BADDR(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_BADDR(qno)));
dev_info(dev, "R[%d]_IN_INSTR_RSIZE[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_INSTR_RSIZE(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_RSIZE(qno)));
dev_info(dev, "R[%d]_IN_CNTS[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_CNTS(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_CNTS(qno)));
dev_info(dev, "R[%d]_IN_INT_LEVELS[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_INT_LEVELS(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(qno)));
dev_info(dev, "R[%d]_IN_PKT_CNT[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_PKT_CNT(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_PKT_CNT(qno)));
dev_info(dev, "R[%d]_IN_BYTE_CNT[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_IN_BYTE_CNT(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_BYTE_CNT(qno)));
dev_info(dev, "OQ-%d register dump\n", qno);
dev_info(dev, "R[%d]_OUT_SLIST_DBELL[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_SLIST_DBELL(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_SLIST_DBELL(qno)));
dev_info(dev, "R[%d]_OUT_CONTROL[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_CONTROL(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_CONTROL(qno)));
dev_info(dev, "R[%d]_OUT_ENABLE[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_ENABLE(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_ENABLE(qno)));
dev_info(dev, "R[%d]_OUT_SLIST_BADDR[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_SLIST_BADDR(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_SLIST_BADDR(qno)));
dev_info(dev, "R[%d]_OUT_SLIST_RSIZE[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_SLIST_RSIZE(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_SLIST_RSIZE(qno)));
dev_info(dev, "R[%d]_OUT_CNTS[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_CNTS(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_CNTS(qno)));
dev_info(dev, "R[%d]_OUT_INT_LEVELS[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_INT_LEVELS(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(qno)));
dev_info(dev, "R[%d]_OUT_PKT_CNT[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_PKT_CNT(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_PKT_CNT(qno)));
dev_info(dev, "R[%d]_OUT_BYTE_CNT[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_OUT_BYTE_CNT(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_BYTE_CNT(qno)));
dev_info(dev, "R[%d]_ERR_TYPE[0x%llx]: 0x%016llx\n",
qno, CNXK_VF_SDP_R_ERR_TYPE(qno),
octep_vf_read_csr64(oct, CNXK_VF_SDP_R_ERR_TYPE(qno)));
}
/* Reset Hardware Tx queue */
static int cnxk_vf_reset_iq(struct octep_vf_device *oct, int q_no)
{
u64 val = 0ULL;
dev_dbg(&oct->pdev->dev, "Reset VF IQ-%d\n", q_no);
/* Disable the Tx/Instruction Ring */
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_ENABLE(q_no), val);
/* clear the Instruction Ring packet/byte counts and doorbell CSRs */
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(q_no), val);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_PKT_CNT(q_no), val);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_BYTE_CNT(q_no), val);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_BADDR(q_no), val);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_RSIZE(q_no), val);
val = 0xFFFFFFFF;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_DBELL(q_no), val);
val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_CNTS(q_no));
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_CNTS(q_no), val & 0xFFFFFFFF);
return 0;
}
/* Reset Hardware Rx queue */
static void cnxk_vf_reset_oq(struct octep_vf_device *oct, int q_no)
{
u64 val = 0ULL;
/* Disable Output (Rx) Ring */
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_ENABLE(q_no), val);
/* Clear count CSRs */
val = octep_vf_read_csr(oct, CNXK_VF_SDP_R_OUT_CNTS(q_no));
octep_vf_write_csr(oct, CNXK_VF_SDP_R_OUT_CNTS(q_no), val);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_PKT_CNT(q_no), 0xFFFFFFFFFULL);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_SLIST_DBELL(q_no), 0xFFFFFFFF);
}
/* Reset all hardware Tx/Rx queues */
static void octep_vf_reset_io_queues_cnxk(struct octep_vf_device *oct)
{
struct pci_dev *pdev = oct->pdev;
int q;
dev_dbg(&pdev->dev, "Reset OCTEP_CNXK VF IO Queues\n");
for (q = 0; q < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); q++) {
cnxk_vf_reset_iq(oct, q);
cnxk_vf_reset_oq(oct, q);
}
}
/* Initialize configuration limits and initial active config */
static void octep_vf_init_config_cnxk_vf(struct octep_vf_device *oct)
{
struct octep_vf_config *conf = oct->conf;
u64 reg_val;
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_CONTROL(0));
conf->ring_cfg.max_io_rings = (reg_val >> CNXK_VF_R_IN_CTL_RPVF_POS) &
CNXK_VF_R_IN_CTL_RPVF_MASK;
conf->ring_cfg.active_io_rings = conf->ring_cfg.max_io_rings;
conf->iq.num_descs = OCTEP_VF_IQ_MAX_DESCRIPTORS;
conf->iq.instr_type = OCTEP_VF_64BYTE_INSTR;
conf->iq.db_min = OCTEP_VF_DB_MIN;
conf->iq.intr_threshold = OCTEP_VF_IQ_INTR_THRESHOLD;
conf->oq.num_descs = OCTEP_VF_OQ_MAX_DESCRIPTORS;
conf->oq.buf_size = OCTEP_VF_OQ_BUF_SIZE;
conf->oq.refill_threshold = OCTEP_VF_OQ_REFILL_THRESHOLD;
conf->oq.oq_intr_pkt = OCTEP_VF_OQ_INTR_PKT_THRESHOLD;
conf->oq.oq_intr_time = OCTEP_VF_OQ_INTR_TIME_THRESHOLD;
conf->oq.wmark = OCTEP_VF_OQ_WMARK_MIN;
conf->msix_cfg.ioq_msix = conf->ring_cfg.active_io_rings;
}
/* Setup registers for a hardware Tx Queue */
static void octep_vf_setup_iq_regs_cnxk(struct octep_vf_device *oct, int iq_no)
{
struct octep_vf_iq *iq = oct->iq[iq_no];
u32 reset_instr_cnt;
u64 reg_val;
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_CONTROL(iq_no));
/* wait for IDLE to set to 1 */
if (!(reg_val & CNXK_VF_R_IN_CTL_IDLE)) {
do {
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_CONTROL(iq_no));
} while (!(reg_val & CNXK_VF_R_IN_CTL_IDLE));
}
reg_val |= CNXK_VF_R_IN_CTL_RDSIZE;
reg_val |= CNXK_VF_R_IN_CTL_IS_64B;
reg_val |= CNXK_VF_R_IN_CTL_ESR;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_CONTROL(iq_no), reg_val);
/* Write the start of the input queue's ring and its size */
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_BADDR(iq_no), iq->desc_ring_dma);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_RSIZE(iq_no), iq->max_count);
/* Remember the doorbell & instruction count register addr for this queue */
iq->doorbell_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_IN_INSTR_DBELL(iq_no);
iq->inst_cnt_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_IN_CNTS(iq_no);
iq->intr_lvl_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_IN_INT_LEVELS(iq_no);
/* Store the current instruction counter (used in flush_iq calculation) */
reset_instr_cnt = readl(iq->inst_cnt_reg);
writel(reset_instr_cnt, iq->inst_cnt_reg);
/* INTR_THRESHOLD is set to max(FFFFFFFF) to disable the INTR */
reg_val = CFG_GET_IQ_INTR_THRESHOLD(oct->conf) & 0xffffffff;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(iq_no), reg_val);
}
/* Setup registers for a hardware Rx Queue */
static void octep_vf_setup_oq_regs_cnxk(struct octep_vf_device *oct, int oq_no)
{
struct octep_vf_oq *oq = oct->oq[oq_no];
u32 time_threshold = 0;
u64 oq_ctl = 0ULL;
u64 reg_val;
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_CONTROL(oq_no));
/* wait for IDLE to set to 1 */
if (!(reg_val & CNXK_VF_R_OUT_CTL_IDLE)) {
do {
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_CONTROL(oq_no));
} while (!(reg_val & CNXK_VF_R_OUT_CTL_IDLE));
}
reg_val &= ~(CNXK_VF_R_OUT_CTL_IMODE);
reg_val &= ~(CNXK_VF_R_OUT_CTL_ROR_P);
reg_val &= ~(CNXK_VF_R_OUT_CTL_NSR_P);
reg_val &= ~(CNXK_VF_R_OUT_CTL_ROR_I);
reg_val &= ~(CNXK_VF_R_OUT_CTL_NSR_I);
reg_val &= ~(CNXK_VF_R_OUT_CTL_ES_I);
reg_val &= ~(CNXK_VF_R_OUT_CTL_ROR_D);
reg_val &= ~(CNXK_VF_R_OUT_CTL_NSR_D);
reg_val &= ~(CNXK_VF_R_OUT_CTL_ES_D);
reg_val |= (CNXK_VF_R_OUT_CTL_ES_P);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_CONTROL(oq_no), reg_val);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_SLIST_BADDR(oq_no), oq->desc_ring_dma);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_SLIST_RSIZE(oq_no), oq->max_count);
oq_ctl = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_CONTROL(oq_no));
/* Clear the ISIZE and BSIZE (22-0) */
oq_ctl &= ~0x7fffffULL;
/* Populate the BSIZE (15-0) */
oq_ctl |= (oq->buffer_size & 0xffff);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_CONTROL(oq_no), oq_ctl);
/* Get the mapped address of the pkt_sent and pkts_credit regs */
oq->pkts_sent_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_OUT_CNTS(oq_no);
oq->pkts_credit_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_OUT_SLIST_DBELL(oq_no);
time_threshold = CFG_GET_OQ_INTR_TIME(oct->conf);
reg_val = ((u64)time_threshold << 32) | CFG_GET_OQ_INTR_PKT(oct->conf);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(oq_no), reg_val);
/* set watermark for backpressure */
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_WMARK(oq_no));
reg_val &= ~0xFFFFFFFFULL;
reg_val |= CFG_GET_OQ_WMARK(oct->conf);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_WMARK(oq_no), reg_val);
}
/* Setup registers for a VF mailbox */
static void octep_vf_setup_mbox_regs_cnxk(struct octep_vf_device *oct, int q_no)
{
struct octep_vf_mbox *mbox = oct->mbox;
/* PF to VF DATA reg. VF reads from this reg */
mbox->mbox_read_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_MBOX_PF_VF_DATA(q_no);
/* VF mbox interrupt reg */
mbox->mbox_int_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_MBOX_PF_VF_INT(q_no);
/* VF to PF DATA reg. VF writes into this reg */
mbox->mbox_write_reg = oct->mmio.hw_addr + CNXK_VF_SDP_R_MBOX_VF_PF_DATA(q_no);
}
/* Mailbox Interrupt handler */
static void cnxk_handle_vf_mbox_intr(struct octep_vf_device *oct)
{
if (oct->mbox)
schedule_work(&oct->mbox->wk.work);
else
dev_err(&oct->pdev->dev, "cannot schedule work on invalid mbox\n");
}
/* Tx/Rx queue interrupt handler */
static irqreturn_t octep_vf_ioq_intr_handler_cnxk(void *data)
{
struct octep_vf_ioq_vector *vector = (struct octep_vf_ioq_vector *)data;
struct octep_vf_oq *oq = vector->oq;
struct octep_vf_device *oct = vector->octep_vf_dev;
u64 reg_val = 0ULL;
/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */
if (oq->q_no == 0) {
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0));
if (reg_val & CNXK_VF_SDP_R_MBOX_PF_VF_INT_STATUS) {
cnxk_handle_vf_mbox_intr(oct);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0), reg_val);
}
}
napi_schedule_irqoff(oq->napi);
return IRQ_HANDLED;
}
/* Re-initialize Octeon hardware registers */
static void octep_vf_reinit_regs_cnxk(struct octep_vf_device *oct)
{
u32 i;
for (i = 0; i < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); i++)
oct->hw_ops.setup_iq_regs(oct, i);
for (i = 0; i < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); i++)
oct->hw_ops.setup_oq_regs(oct, i);
oct->hw_ops.enable_interrupts(oct);
oct->hw_ops.enable_io_queues(oct);
for (i = 0; i < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); i++)
writel(oct->oq[i]->max_count, oct->oq[i]->pkts_credit_reg);
}
/* Enable all interrupts */
static void octep_vf_enable_interrupts_cnxk(struct octep_vf_device *oct)
{
int num_rings, q;
u64 reg_val;
num_rings = CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf);
for (q = 0; q < num_rings; q++) {
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(q));
reg_val |= (0x1ULL << 62);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(q), reg_val);
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(q));
reg_val |= (0x1ULL << 62);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(q), reg_val);
}
/* Enable PF to VF mbox interrupt by setting 2nd bit*/
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0),
CNXK_VF_SDP_R_MBOX_PF_VF_INT_ENAB);
}
/* Disable all interrupts */
static void octep_vf_disable_interrupts_cnxk(struct octep_vf_device *oct)
{
int num_rings, q;
u64 reg_val;
/* Disable PF to VF mbox interrupt by setting 2nd bit*/
if (oct->mbox)
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0), 0x0);
num_rings = CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf);
for (q = 0; q < num_rings; q++) {
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(q));
reg_val &= ~(0x1ULL << 62);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(q), reg_val);
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(q));
reg_val &= ~(0x1ULL << 62);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(q), reg_val);
}
}
/* Get new Octeon Read Index: index of descriptor that Octeon reads next. */
static u32 octep_vf_update_iq_read_index_cnxk(struct octep_vf_iq *iq)
{
u32 pkt_in_done = readl(iq->inst_cnt_reg);
u32 last_done, new_idx;
last_done = pkt_in_done - iq->pkt_in_done;
iq->pkt_in_done = pkt_in_done;
new_idx = (iq->octep_vf_read_index + last_done) % iq->max_count;
return new_idx;
}
/* Enable a hardware Tx Queue */
static void octep_vf_enable_iq_cnxk(struct octep_vf_device *oct, int iq_no)
{
u64 loop = HZ;
u64 reg_val;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_DBELL(iq_no), 0xFFFFFFFF);
while (octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INSTR_DBELL(iq_no)) &&
loop--) {
schedule_timeout_interruptible(1);
}
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(iq_no));
reg_val |= (0x1ULL << 62);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_INT_LEVELS(iq_no), reg_val);
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_ENABLE(iq_no));
reg_val |= 0x1ULL;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_ENABLE(iq_no), reg_val);
}
/* Enable a hardware Rx Queue */
static void octep_vf_enable_oq_cnxk(struct octep_vf_device *oct, int oq_no)
{
u64 reg_val = 0ULL;
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(oq_no));
reg_val |= (0x1ULL << 62);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_INT_LEVELS(oq_no), reg_val);
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_SLIST_DBELL(oq_no), 0xFFFFFFFF);
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_ENABLE(oq_no));
reg_val |= 0x1ULL;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_ENABLE(oq_no), reg_val);
}
/* Enable all hardware Tx/Rx Queues assigned to VF */
static void octep_vf_enable_io_queues_cnxk(struct octep_vf_device *oct)
{
u8 q;
for (q = 0; q < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); q++) {
octep_vf_enable_iq_cnxk(oct, q);
octep_vf_enable_oq_cnxk(oct, q);
}
}
/* Disable a hardware Tx Queue assigned to VF */
static void octep_vf_disable_iq_cnxk(struct octep_vf_device *oct, int iq_no)
{
u64 reg_val = 0ULL;
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_IN_ENABLE(iq_no));
reg_val &= ~0x1ULL;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_IN_ENABLE(iq_no), reg_val);
}
/* Disable a hardware Rx Queue assigned to VF */
static void octep_vf_disable_oq_cnxk(struct octep_vf_device *oct, int oq_no)
{
u64 reg_val = 0ULL;
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_OUT_ENABLE(oq_no));
reg_val &= ~0x1ULL;
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_OUT_ENABLE(oq_no), reg_val);
}
/* Disable all hardware Tx/Rx Queues assigned to VF */
static void octep_vf_disable_io_queues_cnxk(struct octep_vf_device *oct)
{
int q = 0;
for (q = 0; q < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); q++) {
octep_vf_disable_iq_cnxk(oct, q);
octep_vf_disable_oq_cnxk(oct, q);
}
}
/* Dump hardware registers (including Tx/Rx queues) for debugging. */
static void octep_vf_dump_registers_cnxk(struct octep_vf_device *oct)
{
u8 num_rings, q;
num_rings = CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf);
for (q = 0; q < num_rings; q++)
cnxk_vf_dump_q_regs(oct, q);
}
/**
* octep_vf_device_setup_cnxk() - Setup Octeon device.
*
* @oct: Octeon device private data structure.
*
* - initialize hardware operations.
* - get target side pcie port number for the device.
* - set initial configuration and max limits.
*/
void octep_vf_device_setup_cnxk(struct octep_vf_device *oct)
{
oct->hw_ops.setup_iq_regs = octep_vf_setup_iq_regs_cnxk;
oct->hw_ops.setup_oq_regs = octep_vf_setup_oq_regs_cnxk;
oct->hw_ops.setup_mbox_regs = octep_vf_setup_mbox_regs_cnxk;
oct->hw_ops.ioq_intr_handler = octep_vf_ioq_intr_handler_cnxk;
oct->hw_ops.reinit_regs = octep_vf_reinit_regs_cnxk;
oct->hw_ops.enable_interrupts = octep_vf_enable_interrupts_cnxk;
oct->hw_ops.disable_interrupts = octep_vf_disable_interrupts_cnxk;
oct->hw_ops.update_iq_read_idx = octep_vf_update_iq_read_index_cnxk;
oct->hw_ops.enable_iq = octep_vf_enable_iq_cnxk;
oct->hw_ops.enable_oq = octep_vf_enable_oq_cnxk;
oct->hw_ops.enable_io_queues = octep_vf_enable_io_queues_cnxk;
oct->hw_ops.disable_iq = octep_vf_disable_iq_cnxk;
oct->hw_ops.disable_oq = octep_vf_disable_oq_cnxk;
oct->hw_ops.disable_io_queues = octep_vf_disable_io_queues_cnxk;
oct->hw_ops.reset_io_queues = octep_vf_reset_io_queues_cnxk;
oct->hw_ops.dump_registers = octep_vf_dump_registers_cnxk;
octep_vf_init_config_cnxk_vf(oct);
}
|