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