net/octeontx_ep: add basic device setup
[dpdk.git] / drivers / net / octeontx_ep / otx_ep_vf.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #include <rte_common.h>
6 #include <rte_cycles.h>
7 #include <rte_io.h>
8 #include <ethdev_driver.h>
9 #include <ethdev_pci.h>
10
11 #include "otx_ep_common.h"
12 #include "otx_ep_vf.h"
13
14
15 static void
16 otx_ep_setup_global_iq_reg(struct otx_ep_device *otx_ep, int q_no)
17 {
18         volatile uint64_t reg_val = 0ull;
19
20         /* Select ES, RO, NS, RDSIZE,DPTR Format#0 for IQs
21          * IS_64B is by default enabled.
22          */
23         reg_val = rte_read64(otx_ep->hw_addr + OTX_EP_R_IN_CONTROL(q_no));
24
25         reg_val |= OTX_EP_R_IN_CTL_RDSIZE;
26         reg_val |= OTX_EP_R_IN_CTL_IS_64B;
27         reg_val |= OTX_EP_R_IN_CTL_ESR;
28
29         otx_ep_write64(reg_val, otx_ep->hw_addr, OTX_EP_R_IN_CONTROL(q_no));
30         reg_val = rte_read64(otx_ep->hw_addr + OTX_EP_R_IN_CONTROL(q_no));
31
32         if (!(reg_val & OTX_EP_R_IN_CTL_IDLE)) {
33                 do {
34                         reg_val = rte_read64(otx_ep->hw_addr +
35                                               OTX_EP_R_IN_CONTROL(q_no));
36                 } while (!(reg_val & OTX_EP_R_IN_CTL_IDLE));
37         }
38 }
39
40 static void
41 otx_ep_setup_global_oq_reg(struct otx_ep_device *otx_ep, int q_no)
42 {
43         volatile uint64_t reg_val = 0ull;
44
45         reg_val = rte_read64(otx_ep->hw_addr + OTX_EP_R_OUT_CONTROL(q_no));
46
47         reg_val &= ~(OTX_EP_R_OUT_CTL_IMODE);
48         reg_val &= ~(OTX_EP_R_OUT_CTL_ROR_P);
49         reg_val &= ~(OTX_EP_R_OUT_CTL_NSR_P);
50         reg_val &= ~(OTX_EP_R_OUT_CTL_ROR_I);
51         reg_val &= ~(OTX_EP_R_OUT_CTL_NSR_I);
52         reg_val &= ~(OTX_EP_R_OUT_CTL_ES_I);
53         reg_val &= ~(OTX_EP_R_OUT_CTL_ROR_D);
54         reg_val &= ~(OTX_EP_R_OUT_CTL_NSR_D);
55         reg_val &= ~(OTX_EP_R_OUT_CTL_ES_D);
56
57         /* INFO/DATA ptr swap is required  */
58         reg_val |= (OTX_EP_R_OUT_CTL_ES_P);
59
60         otx_ep_write64(reg_val, otx_ep->hw_addr, OTX_EP_R_OUT_CONTROL(q_no));
61 }
62
63 static void
64 otx_ep_setup_global_input_regs(struct otx_ep_device *otx_ep)
65 {
66         uint64_t q_no = 0ull;
67
68         for (q_no = 0; q_no < (otx_ep->sriov_info.rings_per_vf); q_no++)
69                 otx_ep_setup_global_iq_reg(otx_ep, q_no);
70 }
71
72 static void
73 otx_ep_setup_global_output_regs(struct otx_ep_device *otx_ep)
74 {
75         uint32_t q_no;
76
77         for (q_no = 0; q_no < (otx_ep->sriov_info.rings_per_vf); q_no++)
78                 otx_ep_setup_global_oq_reg(otx_ep, q_no);
79 }
80
81 static void
82 otx_ep_setup_device_regs(struct otx_ep_device *otx_ep)
83 {
84         otx_ep_setup_global_input_regs(otx_ep);
85         otx_ep_setup_global_output_regs(otx_ep);
86 }
87
88 /* OTX_EP default configuration */
89 static const struct otx_ep_config default_otx_ep_conf = {
90         /* IQ attributes */
91         .iq                        = {
92                 .max_iqs           = OTX_EP_CFG_IO_QUEUES,
93                 .instr_type        = OTX_EP_64BYTE_INSTR,
94                 .pending_list_size = (OTX_EP_MAX_IQ_DESCRIPTORS *
95                                       OTX_EP_CFG_IO_QUEUES),
96         },
97
98         /* OQ attributes */
99         .oq                        = {
100                 .max_oqs           = OTX_EP_CFG_IO_QUEUES,
101                 .info_ptr          = OTX_EP_OQ_INFOPTR_MODE,
102                 .refill_threshold  = OTX_EP_OQ_REFIL_THRESHOLD,
103         },
104
105         .num_iqdef_descs           = OTX_EP_MAX_IQ_DESCRIPTORS,
106         .num_oqdef_descs           = OTX_EP_MAX_OQ_DESCRIPTORS,
107         .oqdef_buf_size            = OTX_EP_OQ_BUF_SIZE,
108
109 };
110
111
112 static const struct otx_ep_config*
113 otx_ep_get_defconf(struct otx_ep_device *otx_ep_dev __rte_unused)
114 {
115         const struct otx_ep_config *default_conf = NULL;
116
117         default_conf = &default_otx_ep_conf;
118
119         return default_conf;
120 }
121
122 int
123 otx_ep_vf_setup_device(struct otx_ep_device *otx_ep)
124 {
125         uint64_t reg_val = 0ull;
126
127         /* If application doesn't provide its conf, use driver default conf */
128         if (otx_ep->conf == NULL) {
129                 otx_ep->conf = otx_ep_get_defconf(otx_ep);
130                 if (otx_ep->conf == NULL) {
131                         otx_ep_err("OTX_EP VF default config not found\n");
132                         return -ENOENT;
133                 }
134                 otx_ep_info("Default config is used\n");
135         }
136
137         /* Get IOQs (RPVF] count */
138         reg_val = rte_read64(otx_ep->hw_addr + OTX_EP_R_IN_CONTROL(0));
139
140         otx_ep->sriov_info.rings_per_vf = ((reg_val >> OTX_EP_R_IN_CTL_RPVF_POS)
141                                           & OTX_EP_R_IN_CTL_RPVF_MASK);
142
143         otx_ep_info("OTX_EP RPVF: %d\n", otx_ep->sriov_info.rings_per_vf);
144
145         otx_ep->fn_list.setup_device_regs   = otx_ep_setup_device_regs;
146
147         return 0;
148 }