ethdev: make device operations struct private
[dpdk.git] / drivers / net / ixgbe / ixgbe_vf_representor.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation.
3  */
4
5 #include <rte_ethdev.h>
6 #include <rte_pci.h>
7 #include <rte_malloc.h>
8
9 #include "rte_ethdev_driver.h"
10 #include "base/ixgbe_type.h"
11 #include "base/ixgbe_vf.h"
12 #include "ixgbe_ethdev.h"
13 #include "ixgbe_rxtx.h"
14 #include "rte_pmd_ixgbe.h"
15
16
17 static int
18 ixgbe_vf_representor_link_update(struct rte_eth_dev *ethdev,
19         int wait_to_complete)
20 {
21         struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
22
23         return ixgbe_dev_link_update_share(representor->pf_ethdev,
24                 wait_to_complete, 0);
25 }
26
27 static int
28 ixgbe_vf_representor_mac_addr_set(struct rte_eth_dev *ethdev,
29         struct rte_ether_addr *mac_addr)
30 {
31         struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
32
33         return rte_pmd_ixgbe_set_vf_mac_addr(
34                 representor->pf_ethdev->data->port_id,
35                 representor->vf_id, mac_addr);
36 }
37
38 static int
39 ixgbe_vf_representor_dev_infos_get(struct rte_eth_dev *ethdev,
40         struct rte_eth_dev_info *dev_info)
41 {
42         struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
43
44         struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(
45                 representor->pf_ethdev->data->dev_private);
46
47         dev_info->device = representor->pf_ethdev->device;
48
49         dev_info->min_rx_bufsize = 1024;
50         /**< Minimum size of RX buffer. */
51         dev_info->max_rx_pktlen = 9728;
52         /**< Maximum configurable length of RX pkt. */
53         dev_info->max_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
54         /**< Maximum number of RX queues. */
55         dev_info->max_tx_queues = IXGBE_VF_MAX_TX_QUEUES;
56         /**< Maximum number of TX queues. */
57
58         dev_info->max_mac_addrs = hw->mac.num_rar_entries;
59         /**< Maximum number of MAC addresses. */
60
61         dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
62                 DEV_RX_OFFLOAD_IPV4_CKSUM |     DEV_RX_OFFLOAD_UDP_CKSUM  |
63                 DEV_RX_OFFLOAD_TCP_CKSUM;
64         /**< Device RX offload capabilities. */
65
66         dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT |
67                 DEV_TX_OFFLOAD_IPV4_CKSUM | DEV_TX_OFFLOAD_UDP_CKSUM |
68                 DEV_TX_OFFLOAD_TCP_CKSUM | DEV_TX_OFFLOAD_SCTP_CKSUM |
69                 DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_MULTI_SEGS;
70         /**< Device TX offload capabilities. */
71
72         dev_info->speed_capa =
73                 representor->pf_ethdev->data->dev_link.link_speed;
74         /**< Supported speeds bitmap (ETH_LINK_SPEED_). */
75
76         dev_info->switch_info.name =
77                 representor->pf_ethdev->device->name;
78         dev_info->switch_info.domain_id = representor->switch_domain_id;
79         dev_info->switch_info.port_id = representor->vf_id;
80
81         return 0;
82 }
83
84 static int ixgbe_vf_representor_dev_configure(
85                 __rte_unused struct rte_eth_dev *dev)
86 {
87         return 0;
88 }
89
90 static int ixgbe_vf_representor_rx_queue_setup(
91         __rte_unused struct rte_eth_dev *dev,
92         __rte_unused uint16_t rx_queue_id,
93         __rte_unused uint16_t nb_rx_desc,
94         __rte_unused unsigned int socket_id,
95         __rte_unused const struct rte_eth_rxconf *rx_conf,
96         __rte_unused struct rte_mempool *mb_pool)
97 {
98         return 0;
99 }
100
101 static int ixgbe_vf_representor_tx_queue_setup(
102         __rte_unused struct rte_eth_dev *dev,
103         __rte_unused uint16_t rx_queue_id,
104         __rte_unused uint16_t nb_rx_desc,
105         __rte_unused unsigned int socket_id,
106         __rte_unused const struct rte_eth_txconf *tx_conf)
107 {
108         return 0;
109 }
110
111 static int ixgbe_vf_representor_dev_start(__rte_unused struct rte_eth_dev *dev)
112 {
113         return 0;
114 }
115
116 static void ixgbe_vf_representor_dev_stop(__rte_unused struct rte_eth_dev *dev)
117 {
118 }
119
120 static int
121 ixgbe_vf_representor_vlan_filter_set(struct rte_eth_dev *ethdev,
122         uint16_t vlan_id, int on)
123 {
124         struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
125         uint64_t vf_mask = 1ULL << representor->vf_id;
126
127         return rte_pmd_ixgbe_set_vf_vlan_filter(
128                 representor->pf_ethdev->data->port_id, vlan_id, vf_mask, on);
129 }
130
131 static void
132 ixgbe_vf_representor_vlan_strip_queue_set(struct rte_eth_dev *ethdev,
133         __rte_unused uint16_t rx_queue_id, int on)
134 {
135         struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
136
137         rte_pmd_ixgbe_set_vf_vlan_stripq(representor->pf_ethdev->data->port_id,
138                 representor->vf_id, on);
139 }
140
141 static const struct eth_dev_ops ixgbe_vf_representor_dev_ops = {
142         .dev_infos_get          = ixgbe_vf_representor_dev_infos_get,
143
144         .dev_start              = ixgbe_vf_representor_dev_start,
145         .dev_configure          = ixgbe_vf_representor_dev_configure,
146         .dev_stop               = ixgbe_vf_representor_dev_stop,
147
148         .rx_queue_setup         = ixgbe_vf_representor_rx_queue_setup,
149         .tx_queue_setup         = ixgbe_vf_representor_tx_queue_setup,
150
151         .link_update            = ixgbe_vf_representor_link_update,
152
153         .vlan_filter_set        = ixgbe_vf_representor_vlan_filter_set,
154         .vlan_strip_queue_set   = ixgbe_vf_representor_vlan_strip_queue_set,
155
156         .mac_addr_set           = ixgbe_vf_representor_mac_addr_set,
157 };
158
159 static uint16_t
160 ixgbe_vf_representor_rx_burst(__rte_unused void *rx_queue,
161         __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts)
162 {
163         return 0;
164 }
165
166 static uint16_t
167 ixgbe_vf_representor_tx_burst(__rte_unused void *tx_queue,
168         __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts)
169 {
170         return 0;
171 }
172
173 int
174 ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params)
175 {
176         struct ixgbe_vf_representor *representor = ethdev->data->dev_private;
177
178         struct ixgbe_vf_info *vf_data;
179         struct rte_pci_device *pci_dev;
180         struct rte_eth_link *link;
181
182         if (!representor)
183                 return -ENOMEM;
184
185         representor->vf_id =
186                 ((struct ixgbe_vf_representor *)init_params)->vf_id;
187         representor->switch_domain_id =
188                 ((struct ixgbe_vf_representor *)init_params)->switch_domain_id;
189         representor->pf_ethdev =
190                 ((struct ixgbe_vf_representor *)init_params)->pf_ethdev;
191
192         pci_dev = RTE_ETH_DEV_TO_PCI(representor->pf_ethdev);
193
194         if (representor->vf_id >= pci_dev->max_vfs)
195                 return -ENODEV;
196
197         ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
198         ethdev->data->representor_id = representor->vf_id;
199
200         /* Set representor device ops */
201         ethdev->dev_ops = &ixgbe_vf_representor_dev_ops;
202
203         /* No data-path, but need stub Rx/Tx functions to avoid crash
204          * when testing with the likes of testpmd.
205          */
206         ethdev->rx_pkt_burst = ixgbe_vf_representor_rx_burst;
207         ethdev->tx_pkt_burst = ixgbe_vf_representor_tx_burst;
208
209         /* Setting the number queues allocated to the VF */
210         ethdev->data->nb_rx_queues = IXGBE_VF_MAX_RX_QUEUES;
211         ethdev->data->nb_tx_queues = IXGBE_VF_MAX_RX_QUEUES;
212
213         /* Reference VF mac address from PF data structure */
214         vf_data = *IXGBE_DEV_PRIVATE_TO_P_VFDATA(
215                 representor->pf_ethdev->data->dev_private);
216
217         ethdev->data->mac_addrs = (struct rte_ether_addr *)
218                 vf_data[representor->vf_id].vf_mac_addresses;
219
220         /* Link state. Inherited from PF */
221         link = &representor->pf_ethdev->data->dev_link;
222
223         ethdev->data->dev_link.link_speed = link->link_speed;
224         ethdev->data->dev_link.link_duplex = link->link_duplex;
225         ethdev->data->dev_link.link_status = link->link_status;
226         ethdev->data->dev_link.link_autoneg = link->link_autoneg;
227
228         return 0;
229 }
230
231 int
232 ixgbe_vf_representor_uninit(struct rte_eth_dev *ethdev)
233 {
234         /* mac_addrs must not be freed because part of ixgbe_vf_info */
235         ethdev->data->mac_addrs = NULL;
236
237         return 0;
238 }