net/bnxt: add port representor infrastructure
[dpdk.git] / drivers / net / bnxt / bnxt_reps.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2014-2020 Broadcom
3  * All rights reserved.
4  */
5
6 #include "bnxt.h"
7 #include "bnxt_ring.h"
8 #include "bnxt_reps.h"
9 #include "hsi_struct_def_dpdk.h"
10
11 static const struct eth_dev_ops bnxt_vf_rep_dev_ops = {
12         .dev_infos_get = bnxt_vf_rep_dev_info_get_op,
13         .dev_configure = bnxt_vf_rep_dev_configure_op,
14         .dev_start = bnxt_vf_rep_dev_start_op,
15         .rx_queue_setup = bnxt_vf_rep_rx_queue_setup_op,
16         .tx_queue_setup = bnxt_vf_rep_tx_queue_setup_op,
17         .link_update = bnxt_vf_rep_link_update_op,
18         .dev_close = bnxt_vf_rep_dev_close_op,
19         .dev_stop = bnxt_vf_rep_dev_stop_op
20 };
21
22 static uint16_t
23 bnxt_vf_rep_rx_burst(__rte_unused void *rx_queue,
24                      __rte_unused struct rte_mbuf **rx_pkts,
25                      __rte_unused uint16_t nb_pkts)
26 {
27         return 0;
28 }
29
30 static uint16_t
31 bnxt_vf_rep_tx_burst(__rte_unused void *tx_queue,
32                      __rte_unused struct rte_mbuf **tx_pkts,
33                      __rte_unused uint16_t nb_pkts)
34 {
35         return 0;
36 }
37
38 int bnxt_vf_representor_init(struct rte_eth_dev *eth_dev, void *params)
39 {
40         struct bnxt_vf_representor *vf_rep_bp = eth_dev->data->dev_private;
41         struct bnxt_vf_representor *rep_params =
42                                  (struct bnxt_vf_representor *)params;
43         struct rte_eth_link *link;
44         struct bnxt *parent_bp;
45
46         vf_rep_bp->vf_id = rep_params->vf_id;
47         vf_rep_bp->switch_domain_id = rep_params->switch_domain_id;
48         vf_rep_bp->parent_priv = rep_params->parent_priv;
49
50         eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
51         eth_dev->data->representor_id = rep_params->vf_id;
52
53         rte_eth_random_addr(vf_rep_bp->dflt_mac_addr);
54         memcpy(vf_rep_bp->mac_addr, vf_rep_bp->dflt_mac_addr,
55                sizeof(vf_rep_bp->mac_addr));
56         eth_dev->data->mac_addrs =
57                 (struct rte_ether_addr *)&vf_rep_bp->mac_addr;
58         eth_dev->dev_ops = &bnxt_vf_rep_dev_ops;
59
60         /* No data-path, but need stub Rx/Tx functions to avoid crash
61          * when testing with ovs-dpdk
62          */
63         eth_dev->rx_pkt_burst = bnxt_vf_rep_rx_burst;
64         eth_dev->tx_pkt_burst = bnxt_vf_rep_tx_burst;
65         /* Link state. Inherited from PF or trusted VF */
66         parent_bp = vf_rep_bp->parent_priv;
67         link = &parent_bp->eth_dev->data->dev_link;
68
69         eth_dev->data->dev_link.link_speed = link->link_speed;
70         eth_dev->data->dev_link.link_duplex = link->link_duplex;
71         eth_dev->data->dev_link.link_status = link->link_status;
72         eth_dev->data->dev_link.link_autoneg = link->link_autoneg;
73
74         PMD_DRV_LOG(INFO, "calling bnxt_print_link_info\n");
75         bnxt_print_link_info(eth_dev);
76
77         /* Pass the information to the rte_eth_dev_close() that it should also
78          * release the private port resources.
79          */
80         eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
81         PMD_DRV_LOG(INFO,
82                     "Switch domain id %d: Representor Device %d init done\n",
83                     vf_rep_bp->switch_domain_id, vf_rep_bp->vf_id);
84
85         return 0;
86 }
87
88 int bnxt_vf_representor_uninit(struct rte_eth_dev *eth_dev)
89 {
90         struct bnxt *parent_bp;
91         struct bnxt_vf_representor *rep =
92                 (struct bnxt_vf_representor *)eth_dev->data->dev_private;
93
94         uint16_t vf_id;
95
96         eth_dev->data->mac_addrs = NULL;
97
98         parent_bp = rep->parent_priv;
99         if (parent_bp) {
100                 parent_bp->num_reps--;
101                 vf_id = rep->vf_id;
102                 memset(&parent_bp->rep_info[vf_id], 0,
103                        sizeof(parent_bp->rep_info[vf_id]));
104                 /* mark that this representor has been freed */
105         }
106         eth_dev->dev_ops = NULL;
107         return 0;
108 }
109
110 int bnxt_vf_rep_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_compl)
111 {
112         struct bnxt *parent_bp;
113         struct bnxt_vf_representor *rep =
114                 (struct bnxt_vf_representor *)eth_dev->data->dev_private;
115         struct rte_eth_link *link;
116         int rc;
117
118         parent_bp = rep->parent_priv;
119         rc = bnxt_link_update_op(parent_bp->eth_dev, wait_to_compl);
120
121         /* Link state. Inherited from PF or trusted VF */
122         link = &parent_bp->eth_dev->data->dev_link;
123
124         eth_dev->data->dev_link.link_speed = link->link_speed;
125         eth_dev->data->dev_link.link_duplex = link->link_duplex;
126         eth_dev->data->dev_link.link_status = link->link_status;
127         eth_dev->data->dev_link.link_autoneg = link->link_autoneg;
128         bnxt_print_link_info(eth_dev);
129
130         return rc;
131 }
132
133 int bnxt_vf_rep_dev_start_op(struct rte_eth_dev *eth_dev)
134 {
135         bnxt_vf_rep_link_update_op(eth_dev, 1);
136
137         return 0;
138 }
139
140 void bnxt_vf_rep_dev_stop_op(__rte_unused struct rte_eth_dev *eth_dev)
141 {
142 }
143
144 void bnxt_vf_rep_dev_close_op(struct rte_eth_dev *eth_dev)
145 {
146         bnxt_vf_representor_uninit(eth_dev);
147 }
148
149 int bnxt_vf_rep_dev_info_get_op(struct rte_eth_dev *eth_dev,
150                                 struct rte_eth_dev_info *dev_info)
151 {
152         struct bnxt_vf_representor *rep_bp = eth_dev->data->dev_private;
153         struct bnxt *parent_bp;
154         uint16_t max_vnics, i, j, vpool, vrxq;
155         unsigned int max_rx_rings;
156         int rc = 0;
157
158         /* MAC Specifics */
159         parent_bp = rep_bp->parent_priv;
160         if (!parent_bp) {
161                 PMD_DRV_LOG(ERR, "Rep parent NULL!\n");
162                 return rc;
163         }
164         PMD_DRV_LOG(DEBUG, "Representor dev_info_get_op\n");
165         dev_info->max_mac_addrs = parent_bp->max_l2_ctx;
166         dev_info->max_hash_mac_addrs = 0;
167
168         max_rx_rings = BNXT_MAX_VF_REP_RINGS;
169         /* For the sake of symmetry, max_rx_queues = max_tx_queues */
170         dev_info->max_rx_queues = max_rx_rings;
171         dev_info->max_tx_queues = max_rx_rings;
172         dev_info->reta_size = bnxt_rss_hash_tbl_size(parent_bp);
173         dev_info->hash_key_size = 40;
174         max_vnics = parent_bp->max_vnics;
175
176         /* MTU specifics */
177         dev_info->min_mtu = RTE_ETHER_MIN_MTU;
178         dev_info->max_mtu = BNXT_MAX_MTU;
179
180         /* Fast path specifics */
181         dev_info->min_rx_bufsize = 1;
182         dev_info->max_rx_pktlen = BNXT_MAX_PKT_LEN;
183
184         dev_info->rx_offload_capa = BNXT_DEV_RX_OFFLOAD_SUPPORT;
185         if (parent_bp->flags & BNXT_FLAG_PTP_SUPPORTED)
186                 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TIMESTAMP;
187         dev_info->tx_offload_capa = BNXT_DEV_TX_OFFLOAD_SUPPORT;
188         dev_info->flow_type_rss_offloads = BNXT_ETH_RSS_SUPPORT;
189
190         /* *INDENT-OFF* */
191         dev_info->default_rxconf = (struct rte_eth_rxconf) {
192                 .rx_thresh = {
193                         .pthresh = 8,
194                         .hthresh = 8,
195                         .wthresh = 0,
196                 },
197                 .rx_free_thresh = 32,
198                 /* If no descriptors available, pkts are dropped by default */
199                 .rx_drop_en = 1,
200         };
201
202         dev_info->default_txconf = (struct rte_eth_txconf) {
203                 .tx_thresh = {
204                         .pthresh = 32,
205                         .hthresh = 0,
206                         .wthresh = 0,
207                 },
208                 .tx_free_thresh = 32,
209                 .tx_rs_thresh = 32,
210         };
211         eth_dev->data->dev_conf.intr_conf.lsc = 1;
212
213         eth_dev->data->dev_conf.intr_conf.rxq = 1;
214         dev_info->rx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
215         dev_info->rx_desc_lim.nb_max = BNXT_MAX_RX_RING_DESC;
216         dev_info->tx_desc_lim.nb_min = BNXT_MIN_RING_DESC;
217         dev_info->tx_desc_lim.nb_max = BNXT_MAX_TX_RING_DESC;
218
219         /* *INDENT-ON* */
220
221         /*
222          * TODO: default_rxconf, default_txconf, rx_desc_lim, and tx_desc_lim
223          *       need further investigation.
224          */
225
226         /* VMDq resources */
227         vpool = 64; /* ETH_64_POOLS */
228         vrxq = 128; /* ETH_VMDQ_DCB_NUM_QUEUES */
229         for (i = 0; i < 4; vpool >>= 1, i++) {
230                 if (max_vnics > vpool) {
231                         for (j = 0; j < 5; vrxq >>= 1, j++) {
232                                 if (dev_info->max_rx_queues > vrxq) {
233                                         if (vpool > vrxq)
234                                                 vpool = vrxq;
235                                         goto found;
236                                 }
237                         }
238                         /* Not enough resources to support VMDq */
239                         break;
240                 }
241         }
242         /* Not enough resources to support VMDq */
243         vpool = 0;
244         vrxq = 0;
245 found:
246         dev_info->max_vmdq_pools = vpool;
247         dev_info->vmdq_queue_num = vrxq;
248
249         dev_info->vmdq_pool_base = 0;
250         dev_info->vmdq_queue_base = 0;
251
252         return 0;
253 }
254
255 int bnxt_vf_rep_dev_configure_op(__rte_unused struct rte_eth_dev *eth_dev)
256 {
257         PMD_DRV_LOG(DEBUG, "Representor dev_configure_op\n");
258         return 0;
259 }
260
261 int bnxt_vf_rep_rx_queue_setup_op(__rte_unused struct rte_eth_dev *eth_dev,
262                                   __rte_unused uint16_t queue_idx,
263                                   __rte_unused uint16_t nb_desc,
264                                   __rte_unused unsigned int socket_id,
265                                   __rte_unused const struct rte_eth_rxconf *
266                                   rx_conf,
267                                   __rte_unused struct rte_mempool *mp)
268 {
269         return 0;
270 }
271
272 int bnxt_vf_rep_tx_queue_setup_op(__rte_unused struct rte_eth_dev *eth_dev,
273                                   __rte_unused uint16_t queue_idx,
274                                   __rte_unused uint16_t nb_desc,
275                                   __rte_unused unsigned int socket_id,
276                                   __rte_unused const struct rte_eth_txconf *
277                                   tx_conf)
278 {
279         return 0;
280 }