Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <stdio.h>
6 : : #include <errno.h>
7 : : #include <stdint.h>
8 : : #include <stdlib.h>
9 : : #include <unistd.h>
10 : : #include <stdarg.h>
11 : : #include <inttypes.h>
12 : :
13 : : #include <rte_interrupts.h>
14 : : #include <rte_log.h>
15 : : #include <rte_debug.h>
16 : : #include <rte_eal.h>
17 : : #include <rte_ether.h>
18 : : #include <ethdev_driver.h>
19 : : #include <rte_memcpy.h>
20 : : #include <rte_malloc.h>
21 : : #include <rte_random.h>
22 : :
23 : : #include "base/ixgbe_common.h"
24 : : #include "ixgbe_ethdev.h"
25 : : #include "rte_pmd_ixgbe.h"
26 : :
27 : : #define IXGBE_MAX_VFTA (128)
28 : : #define IXGBE_VF_MSG_SIZE_DEFAULT 1
29 : : #define IXGBE_VF_GET_QUEUE_MSG_SIZE 5
30 : : #define IXGBE_ETHERTYPE_FLOW_CTRL 0x8808
31 : :
32 : : static inline uint16_t
33 : : dev_num_vf(struct rte_eth_dev *eth_dev)
34 : : {
35 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
36 : :
37 : 0 : return pci_dev->max_vfs;
38 : : }
39 : :
40 : : static inline
41 : 0 : int ixgbe_vf_perm_addr_gen(struct rte_eth_dev *dev, uint16_t vf_num)
42 : : {
43 : : unsigned char vf_mac_addr[RTE_ETHER_ADDR_LEN];
44 : 0 : struct ixgbe_vf_info *vfinfo =
45 : 0 : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
46 : : uint16_t vfn;
47 : :
48 [ # # ]: 0 : for (vfn = 0; vfn < vf_num; vfn++) {
49 : 0 : rte_eth_random_addr(vf_mac_addr);
50 : : /* keep the random address as default */
51 : 0 : memcpy(vfinfo[vfn].vf_mac_addresses, vf_mac_addr,
52 : : RTE_ETHER_ADDR_LEN);
53 : : }
54 : :
55 : 0 : return 0;
56 : : }
57 : :
58 : : static inline int
59 : : ixgbe_mb_intr_setup(struct rte_eth_dev *dev)
60 : : {
61 : : struct ixgbe_interrupt *intr =
62 : 0 : IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
63 : :
64 : 0 : intr->mask |= IXGBE_EICR_MAILBOX;
65 : :
66 : : return 0;
67 : : }
68 : :
69 : 0 : int ixgbe_pf_host_init(struct rte_eth_dev *eth_dev)
70 : : {
71 : : struct ixgbe_vf_info **vfinfo =
72 : 0 : IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
73 : 0 : struct ixgbe_uta_info *uta_info =
74 : : IXGBE_DEV_PRIVATE_TO_UTA(eth_dev->data->dev_private);
75 : 0 : struct ixgbe_hw *hw =
76 : : IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
77 : : uint16_t vf_num;
78 : : uint8_t nb_queue;
79 : : int ret = 0;
80 : : size_t i;
81 : :
82 : 0 : PMD_INIT_FUNC_TRACE();
83 : :
84 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
85 : : vf_num = dev_num_vf(eth_dev);
86 [ # # ]: 0 : if (vf_num == 0)
87 : : return ret;
88 : :
89 : 0 : *vfinfo = rte_zmalloc("vf_info", sizeof(struct ixgbe_vf_info) * vf_num, 0);
90 [ # # ]: 0 : if (*vfinfo == NULL) {
91 : 0 : PMD_INIT_LOG(ERR,
92 : : "Cannot allocate memory for private VF data");
93 : 0 : return -ENOMEM;
94 : : }
95 : :
96 : 0 : ret = rte_eth_switch_domain_alloc(&(*vfinfo)->switch_domain_id);
97 [ # # ]: 0 : if (ret) {
98 : 0 : PMD_INIT_LOG(ERR,
99 : : "failed to allocate switch domain for device %d", ret);
100 : 0 : rte_free(*vfinfo);
101 : 0 : *vfinfo = NULL;
102 : 0 : return ret;
103 : : }
104 : :
105 : : memset(uta_info, 0, sizeof(struct ixgbe_uta_info));
106 : 0 : hw->mac.mc_filter_type = 0;
107 : :
108 [ # # ]: 0 : if (vf_num >= RTE_ETH_32_POOLS) {
109 : : nb_queue = 2;
110 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).active = RTE_ETH_64_POOLS;
111 [ # # ]: 0 : } else if (vf_num >= RTE_ETH_16_POOLS) {
112 : : nb_queue = 4;
113 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).active = RTE_ETH_32_POOLS;
114 : : } else {
115 : : nb_queue = 8;
116 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).active = RTE_ETH_16_POOLS;
117 : : }
118 : :
119 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = nb_queue;
120 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = vf_num;
121 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = (uint16_t)(vf_num * nb_queue);
122 : :
123 : 0 : ixgbe_vf_perm_addr_gen(eth_dev, vf_num);
124 : :
125 : : /* init_mailbox_params */
126 [ # # ]: 0 : for (i = 0; i < vf_num; i++)
127 : 0 : hw->mbx.ops[i].init_params(hw);
128 : :
129 : : /* set mb interrupt mask */
130 : : ixgbe_mb_intr_setup(eth_dev);
131 : :
132 : 0 : return ret;
133 : : }
134 : :
135 : 0 : void ixgbe_pf_host_uninit(struct rte_eth_dev *eth_dev)
136 : : {
137 : : struct ixgbe_vf_info **vfinfo;
138 : : uint16_t vf_num;
139 : : int ret;
140 : :
141 : 0 : PMD_INIT_FUNC_TRACE();
142 : :
143 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
144 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = 0;
145 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = 0;
146 : 0 : RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = 0;
147 : :
148 : : vf_num = dev_num_vf(eth_dev);
149 [ # # ]: 0 : if (vf_num == 0)
150 : : return;
151 : :
152 : 0 : vfinfo = IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
153 [ # # ]: 0 : if (*vfinfo == NULL)
154 : : return;
155 : :
156 : 0 : ret = rte_eth_switch_domain_free((*vfinfo)->switch_domain_id);
157 [ # # ]: 0 : if (ret)
158 : 0 : PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
159 : :
160 : 0 : rte_free(*vfinfo);
161 : 0 : *vfinfo = NULL;
162 : : }
163 : :
164 : : static void
165 : 0 : ixgbe_add_tx_flow_control_drop_filter(struct rte_eth_dev *eth_dev)
166 : : {
167 : 0 : struct ixgbe_hw *hw =
168 : 0 : IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
169 : : struct ixgbe_filter_info *filter_info =
170 : : IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
171 : : uint16_t vf_num;
172 : : int i;
173 : : struct ixgbe_ethertype_filter ethertype_filter;
174 : :
175 [ # # ]: 0 : if (!hw->mac.ops.set_ethertype_anti_spoofing) {
176 : 0 : PMD_DRV_LOG(INFO, "ether type anti-spoofing is not supported.");
177 : 0 : return;
178 : : }
179 : :
180 : : i = ixgbe_ethertype_filter_lookup(filter_info,
181 : : IXGBE_ETHERTYPE_FLOW_CTRL);
182 [ # # ]: 0 : if (i >= 0) {
183 : 0 : PMD_DRV_LOG(ERR, "A ether type filter entity for flow control already exists!");
184 : 0 : return;
185 : : }
186 : :
187 : : ethertype_filter.ethertype = IXGBE_ETHERTYPE_FLOW_CTRL;
188 : : ethertype_filter.etqf = IXGBE_ETQF_FILTER_EN |
189 : : IXGBE_ETQF_TX_ANTISPOOF |
190 : : IXGBE_ETHERTYPE_FLOW_CTRL;
191 : : ethertype_filter.etqs = 0;
192 : : ethertype_filter.conf = TRUE;
193 : : i = ixgbe_ethertype_filter_insert(filter_info,
194 : : ðertype_filter);
195 [ # # ]: 0 : if (i < 0) {
196 : 0 : PMD_DRV_LOG(ERR, "Cannot find an unused ether type filter entity for flow control.");
197 : 0 : return;
198 : : }
199 : :
200 : 0 : IXGBE_WRITE_REG(hw, IXGBE_ETQF(i),
201 : : (IXGBE_ETQF_FILTER_EN |
202 : : IXGBE_ETQF_TX_ANTISPOOF |
203 : : IXGBE_ETHERTYPE_FLOW_CTRL));
204 : :
205 : : vf_num = dev_num_vf(eth_dev);
206 [ # # ]: 0 : for (i = 0; i < vf_num; i++)
207 : 0 : hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
208 : : }
209 : :
210 : 0 : int ixgbe_pf_host_configure(struct rte_eth_dev *eth_dev)
211 : : {
212 : : uint32_t vtctl, fcrth;
213 : : uint32_t vfre_slot, vfre_offset;
214 : : uint16_t vf_num;
215 : : const uint8_t VFRE_SHIFT = 5; /* VFRE 32 bits per slot */
216 : : const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
217 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
218 : : uint32_t gpie, gcr_ext;
219 : : uint32_t vlanctrl;
220 : : int i;
221 : :
222 : : vf_num = dev_num_vf(eth_dev);
223 [ # # ]: 0 : if (vf_num == 0)
224 : : return -1;
225 : :
226 : : /* enable VMDq and set the default pool for PF */
227 : 0 : vtctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
228 : : vtctl |= IXGBE_VMD_CTL_VMDQ_EN;
229 : 0 : vtctl &= ~IXGBE_VT_CTL_POOL_MASK;
230 : 0 : vtctl |= RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx
231 : 0 : << IXGBE_VT_CTL_POOL_SHIFT;
232 : 0 : vtctl |= IXGBE_VT_CTL_REPLEN;
233 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vtctl);
234 : :
235 : 0 : vfre_offset = vf_num & VFRE_MASK;
236 : 0 : vfre_slot = (vf_num >> VFRE_SHIFT) > 0 ? 1 : 0;
237 : :
238 : : /* Enable pools reserved to PF only */
239 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot), (~0U) << vfre_offset);
240 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot ^ 1), vfre_slot - 1);
241 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot), (~0U) << vfre_offset);
242 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot ^ 1), vfre_slot - 1);
243 : :
244 : : /* PFDMA Tx General Switch Control Enables VMDQ loopback */
245 : 0 : IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
246 : :
247 : : /* clear VMDq map to permanent rar 0 */
248 : 0 : hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
249 : :
250 : : /* clear VMDq map to scan rar 127 */
251 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(hw->mac.num_rar_entries), 0);
252 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(hw->mac.num_rar_entries), 0);
253 : :
254 : : /* set VMDq map to default PF pool */
255 : 0 : hw->mac.ops.set_vmdq(hw, 0, RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx);
256 : :
257 : : /*
258 : : * SW msut set GCR_EXT.VT_Mode the same as GPIE.VT_Mode
259 : : */
260 : 0 : gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
261 : 0 : gcr_ext &= ~IXGBE_GCR_EXT_VT_MODE_MASK;
262 : :
263 : 0 : gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
264 : 0 : gpie &= ~IXGBE_GPIE_VTMODE_MASK;
265 : 0 : gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT;
266 : :
267 [ # # # # ]: 0 : switch (RTE_ETH_DEV_SRIOV(eth_dev).active) {
268 : 0 : case RTE_ETH_64_POOLS:
269 : 0 : gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
270 : 0 : gpie |= IXGBE_GPIE_VTMODE_64;
271 : 0 : break;
272 : 0 : case RTE_ETH_32_POOLS:
273 : 0 : gcr_ext |= IXGBE_GCR_EXT_VT_MODE_32;
274 : 0 : gpie |= IXGBE_GPIE_VTMODE_32;
275 : 0 : break;
276 : 0 : case RTE_ETH_16_POOLS:
277 : 0 : gcr_ext |= IXGBE_GCR_EXT_VT_MODE_16;
278 : 0 : gpie |= IXGBE_GPIE_VTMODE_16;
279 : 0 : break;
280 : : }
281 : :
282 : 0 : IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
283 : 0 : IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
284 : :
285 : : /*
286 : : * enable vlan filtering and allow all vlan tags through
287 : : */
288 : 0 : vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
289 : 0 : vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
290 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
291 : :
292 : : /* VFTA - enable all vlan filters */
293 [ # # ]: 0 : for (i = 0; i < IXGBE_MAX_VFTA; i++)
294 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
295 : :
296 : : /* Enable MAC Anti-Spoofing */
297 : 0 : hw->mac.ops.set_mac_anti_spoofing(hw, FALSE, vf_num);
298 : :
299 : : /* set flow control threshold to max to avoid tx switch hang */
300 [ # # ]: 0 : for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
301 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
302 : 0 : fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
303 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
304 : : }
305 : :
306 : 0 : ixgbe_add_tx_flow_control_drop_filter(eth_dev);
307 : :
308 : 0 : return 0;
309 : : }
310 : :
311 : : static void
312 : 0 : set_rx_mode(struct rte_eth_dev *dev)
313 : : {
314 : 0 : struct rte_eth_dev_data *dev_data = dev->data;
315 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
316 : : u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
317 : : uint16_t vfn = dev_num_vf(dev);
318 : :
319 : : /* Check for Promiscuous and All Multicast modes */
320 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
321 : :
322 : : /* set all bits that we expect to always be set */
323 : : fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
324 : : fctrl |= IXGBE_FCTRL_BAM;
325 : :
326 : : /* clear the bits we are changing the status of */
327 : 0 : fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
328 : :
329 [ # # ]: 0 : if (dev_data->promiscuous) {
330 : 0 : fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
331 : : vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
332 : : } else {
333 [ # # ]: 0 : if (dev_data->all_multicast) {
334 : 0 : fctrl |= IXGBE_FCTRL_MPE;
335 : : vmolr |= IXGBE_VMOLR_MPE;
336 : : } else {
337 : : vmolr |= IXGBE_VMOLR_ROMPE;
338 : : }
339 : : }
340 : :
341 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_82598EB) {
342 : 0 : vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(vfn)) &
343 : : ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
344 : : IXGBE_VMOLR_ROPE);
345 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vfn), vmolr);
346 : : }
347 : :
348 : 0 : IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
349 : :
350 : 0 : ixgbe_vlan_hw_strip_config(dev);
351 : 0 : }
352 : :
353 : : static inline void
354 : 0 : ixgbe_vf_reset_event(struct rte_eth_dev *dev, uint16_t vf)
355 : : {
356 : 0 : struct ixgbe_hw *hw =
357 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
358 : 0 : struct ixgbe_vf_info *vfinfo =
359 : : *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
360 : 0 : int rar_entry = hw->mac.num_rar_entries - (vf + 1);
361 : 0 : uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
362 : :
363 : 0 : vmolr |= (IXGBE_VMOLR_ROPE |
364 : : IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
365 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
366 : :
367 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
368 : :
369 : : /* reset multicast table array for vf */
370 : 0 : vfinfo[vf].num_vf_mc_hashes = 0;
371 : :
372 : : /* reset rx mode */
373 : 0 : set_rx_mode(dev);
374 : :
375 : 0 : hw->mac.ops.clear_rar(hw, rar_entry);
376 : 0 : }
377 : :
378 : : static inline void
379 : 0 : ixgbe_vf_reset_msg(struct rte_eth_dev *dev, uint16_t vf)
380 : : {
381 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
382 : : uint32_t reg;
383 : : uint32_t reg_offset, vf_shift;
384 : : const uint8_t VFRE_SHIFT = 5; /* VFRE 32 bits per slot */
385 : : const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
386 : : uint8_t nb_q_per_pool;
387 : : int i;
388 : :
389 : 0 : vf_shift = vf & VFRE_MASK;
390 : 0 : reg_offset = (vf >> VFRE_SHIFT) > 0 ? 1 : 0;
391 : :
392 : : /* enable transmit for vf */
393 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
394 : 0 : reg |= (reg | (1 << vf_shift));
395 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
396 : :
397 : : /* enable all queue drop for IOV */
398 : 0 : nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
399 [ # # ]: 0 : for (i = vf * nb_q_per_pool; i < (vf + 1) * nb_q_per_pool; i++) {
400 : 0 : IXGBE_WRITE_FLUSH(hw);
401 : : reg = IXGBE_QDE_ENABLE | IXGBE_QDE_WRITE;
402 : 0 : reg |= i << IXGBE_QDE_IDX_SHIFT;
403 : 0 : IXGBE_WRITE_REG(hw, IXGBE_QDE, reg);
404 : : }
405 : :
406 : : /* enable receive for vf */
407 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
408 : 0 : reg |= (reg | (1 << vf_shift));
409 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
410 : :
411 : : /* Enable counting of spoofed packets in the SSVPC register */
412 : 0 : reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
413 : 0 : reg |= (1 << vf_shift);
414 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
415 : :
416 : 0 : ixgbe_vf_reset_event(dev, vf);
417 : 0 : }
418 : :
419 : : static int
420 : 0 : ixgbe_disable_vf_mc_promisc(struct rte_eth_dev *dev, uint32_t vf)
421 : : {
422 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
423 : : uint32_t vmolr;
424 : :
425 : 0 : vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
426 : :
427 : 0 : PMD_DRV_LOG(INFO, "VF %u: disabling multicast promiscuous", vf);
428 : :
429 : 0 : vmolr &= ~IXGBE_VMOLR_MPE;
430 : :
431 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
432 : :
433 : 0 : return 0;
434 : : }
435 : :
436 : : static int
437 : 0 : ixgbe_vf_reset(struct rte_eth_dev *dev, uint16_t vf, uint32_t *msgbuf)
438 : : {
439 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
440 : 0 : struct ixgbe_vf_info *vfinfo =
441 : : *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
442 : 0 : unsigned char *vf_mac = vfinfo[vf].vf_mac_addresses;
443 : 0 : int rar_entry = hw->mac.num_rar_entries - (vf + 1);
444 : 0 : uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
445 : :
446 : 0 : ixgbe_vf_reset_msg(dev, vf);
447 : :
448 : 0 : hw->mac.ops.set_rar(hw, rar_entry, vf_mac, vf, IXGBE_RAH_AV);
449 : :
450 : : /* Disable multicast promiscuous at reset */
451 : 0 : ixgbe_disable_vf_mc_promisc(dev, vf);
452 : :
453 : : /* reply to reset with success and vf mac address */
454 [ # # ]: 0 : msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_SUCCESS;
455 : : rte_memcpy(new_mac, vf_mac, RTE_ETHER_ADDR_LEN);
456 : : /*
457 : : * Piggyback the multicast filter type so VF can compute the
458 : : * correct vectors
459 : : */
460 : 0 : msgbuf[3] = hw->mac.mc_filter_type;
461 : 0 : ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
462 : :
463 : 0 : return 0;
464 : : }
465 : :
466 : : static int
467 : 0 : ixgbe_vf_set_mac_addr(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
468 : : {
469 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
470 : 0 : struct ixgbe_vf_info *vfinfo =
471 : : *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
472 : 0 : int rar_entry = hw->mac.num_rar_entries - (vf + 1);
473 [ # # ]: 0 : uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
474 : :
475 : : if (rte_is_valid_assigned_ether_addr(
476 : : (struct rte_ether_addr *)new_mac)) {
477 [ # # ]: 0 : rte_memcpy(vfinfo[vf].vf_mac_addresses, new_mac, 6);
478 : 0 : return hw->mac.ops.set_rar(hw, rar_entry, new_mac, vf, IXGBE_RAH_AV);
479 : : }
480 : : return -1;
481 : : }
482 : :
483 : : static int
484 : 0 : ixgbe_vf_set_multicast(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
485 : : {
486 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
487 : 0 : struct ixgbe_vf_info *vfinfo =
488 : : *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
489 : 0 : int nb_entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
490 : : IXGBE_VT_MSGINFO_SHIFT;
491 : : uint16_t *hash_list = (uint16_t *)&msgbuf[1];
492 : : uint32_t mta_idx;
493 : : uint32_t mta_shift;
494 : : const uint32_t IXGBE_MTA_INDEX_MASK = 0x7F;
495 : : const uint32_t IXGBE_MTA_BIT_SHIFT = 5;
496 : : const uint32_t IXGBE_MTA_BIT_MASK = (0x1 << IXGBE_MTA_BIT_SHIFT) - 1;
497 : : uint32_t reg_val;
498 : : int i;
499 : 0 : u32 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
500 : :
501 : : /* Disable multicast promiscuous first */
502 : 0 : ixgbe_disable_vf_mc_promisc(dev, vf);
503 : :
504 : : /* only so many hash values supported */
505 : 0 : nb_entries = RTE_MIN(nb_entries, IXGBE_MAX_VF_MC_ENTRIES);
506 : :
507 : : /* store the mc entries */
508 : 0 : vfinfo->num_vf_mc_hashes = (uint16_t)nb_entries;
509 [ # # ]: 0 : for (i = 0; i < nb_entries; i++) {
510 : 0 : vfinfo->vf_mc_hashes[i] = hash_list[i];
511 : : }
512 : :
513 [ # # ]: 0 : if (nb_entries == 0) {
514 : 0 : vmolr &= ~IXGBE_VMOLR_ROMPE;
515 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
516 : 0 : return 0;
517 : : }
518 : :
519 [ # # ]: 0 : for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
520 : 0 : mta_idx = (vfinfo->vf_mc_hashes[i] >> IXGBE_MTA_BIT_SHIFT)
521 : : & IXGBE_MTA_INDEX_MASK;
522 : 0 : mta_shift = vfinfo->vf_mc_hashes[i] & IXGBE_MTA_BIT_MASK;
523 : 0 : reg_val = IXGBE_READ_REG(hw, IXGBE_MTA(mta_idx));
524 : 0 : reg_val |= (1 << mta_shift);
525 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MTA(mta_idx), reg_val);
526 : : }
527 : :
528 : 0 : vmolr |= IXGBE_VMOLR_ROMPE;
529 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
530 : :
531 : 0 : return 0;
532 : : }
533 : :
534 : : static int
535 : 0 : ixgbe_vf_set_vlan(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
536 : : {
537 : : int add, vid;
538 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
539 : 0 : struct ixgbe_vf_info *vfinfo =
540 : : *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
541 : :
542 : 0 : add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
543 : 0 : >> IXGBE_VT_MSGINFO_SHIFT;
544 : 0 : vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
545 : :
546 [ # # ]: 0 : if (add)
547 : 0 : vfinfo[vf].vlan_count++;
548 [ # # ]: 0 : else if (vfinfo[vf].vlan_count)
549 : 0 : vfinfo[vf].vlan_count--;
550 : 0 : return hw->mac.ops.set_vfta(hw, vid, vf, (bool)add, false);
551 : : }
552 : :
553 : : static int
554 : 0 : ixgbe_set_vf_lpe(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
555 : : {
556 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
557 : 0 : uint32_t max_frame = msgbuf[1];
558 : : uint32_t max_frs;
559 : : uint32_t hlreg0;
560 : :
561 : : /* X540, X550, and E610 support jumbo frames in IOV mode */
562 [ # # ]: 0 : if (hw->mac.type != ixgbe_mac_X540 &&
563 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550 &&
564 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_x &&
565 [ # # ]: 0 : hw->mac.type != ixgbe_mac_X550EM_a &&
566 : : hw->mac.type != ixgbe_mac_E610) {
567 : 0 : struct ixgbe_vf_info *vfinfo =
568 : : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
569 : :
570 [ # # ]: 0 : switch (vfinfo[vf].api_version) {
571 : 0 : case ixgbe_mbox_api_11:
572 : : case ixgbe_mbox_api_12:
573 : : case ixgbe_mbox_api_13:
574 : : /**
575 : : * Version 1.1&1.2&1.3 supports jumbo frames on VFs
576 : : * if PF has jumbo frames enabled which means legacy
577 : : * VFs are disabled.
578 : : */
579 [ # # ]: 0 : if (dev->data->mtu > RTE_ETHER_MTU)
580 : : break;
581 : : /* fall through */
582 : : default:
583 : : /**
584 : : * If the PF or VF are running w/ jumbo frames enabled,
585 : : * we return -1 as we cannot support jumbo frames on
586 : : * legacy VFs.
587 : : */
588 [ # # ]: 0 : if (max_frame > IXGBE_ETH_MAX_LEN ||
589 [ # # ]: 0 : dev->data->mtu > RTE_ETHER_MTU)
590 : : return -1;
591 : : break;
592 : : }
593 : : }
594 : :
595 [ # # ]: 0 : if (max_frame < RTE_ETHER_MIN_LEN ||
596 : : max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
597 : : return -1;
598 : :
599 : 0 : max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
600 : 0 : IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
601 [ # # ]: 0 : if (max_frs < max_frame) {
602 : 0 : hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
603 [ # # ]: 0 : if (max_frame > IXGBE_ETH_MAX_LEN)
604 : 0 : hlreg0 |= IXGBE_HLREG0_JUMBOEN;
605 : : else
606 : 0 : hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
607 : 0 : IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
608 : :
609 : 0 : max_frs = max_frame << IXGBE_MHADD_MFS_SHIFT;
610 : 0 : IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
611 : : }
612 : :
613 : : return 0;
614 : : }
615 : :
616 : : static int
617 : 0 : ixgbe_negotiate_vf_api(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
618 : : {
619 : 0 : uint32_t api_version = msgbuf[1];
620 : 0 : struct ixgbe_vf_info *vfinfo =
621 : 0 : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
622 : :
623 [ # # ]: 0 : switch (api_version) {
624 : 0 : case ixgbe_mbox_api_10:
625 : : case ixgbe_mbox_api_11:
626 : : case ixgbe_mbox_api_12:
627 : : case ixgbe_mbox_api_13:
628 : 0 : vfinfo[vf].api_version = (uint8_t)api_version;
629 : 0 : return 0;
630 : : default:
631 : : break;
632 : : }
633 : :
634 : 0 : PMD_DRV_LOG(ERR, "Negotiate invalid api version %u from VF %d",
635 : : api_version, vf);
636 : :
637 : 0 : return -1;
638 : : }
639 : :
640 : : static int
641 : 0 : ixgbe_get_vf_queues(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
642 : : {
643 : 0 : struct ixgbe_vf_info *vfinfo =
644 : 0 : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
645 : 0 : uint32_t default_q = vf * RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
646 : : struct rte_eth_conf *eth_conf;
647 : : struct rte_eth_vmdq_dcb_tx_conf *vmdq_dcb_tx_conf;
648 : : u8 num_tcs;
649 : : struct ixgbe_hw *hw;
650 : : u32 vmvir;
651 : : #define IXGBE_VMVIR_VLANA_MASK 0xC0000000
652 : : #define IXGBE_VMVIR_VLAN_VID_MASK 0x00000FFF
653 : : #define IXGBE_VMVIR_VLAN_UP_MASK 0x0000E000
654 : : #define VLAN_PRIO_SHIFT 13
655 : : u32 vlana;
656 : : u32 vid;
657 : : u32 user_priority;
658 : :
659 : : /* Verify if the PF supports the mbox APIs version or not */
660 [ # # ]: 0 : switch (vfinfo[vf].api_version) {
661 : : case ixgbe_mbox_api_20:
662 : : case ixgbe_mbox_api_11:
663 : : case ixgbe_mbox_api_12:
664 : : case ixgbe_mbox_api_13:
665 : : break;
666 : : default:
667 : : return -1;
668 : : }
669 : :
670 : : /* Notify VF of Rx and Tx queue number */
671 : 0 : msgbuf[IXGBE_VF_RX_QUEUES] = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
672 : 0 : msgbuf[IXGBE_VF_TX_QUEUES] = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
673 : :
674 : : /* Notify VF of default queue */
675 : 0 : msgbuf[IXGBE_VF_DEF_QUEUE] = default_q;
676 : :
677 : : /* Notify VF of number of DCB traffic classes */
678 : : eth_conf = &dev->data->dev_conf;
679 [ # # # # ]: 0 : switch (eth_conf->txmode.mq_mode) {
680 : 0 : case RTE_ETH_MQ_TX_NONE:
681 : : case RTE_ETH_MQ_TX_DCB:
682 : 0 : PMD_DRV_LOG(ERR, "PF must work with virtualization for VF %u"
683 : : ", but its tx mode = %d", vf,
684 : : eth_conf->txmode.mq_mode);
685 : 0 : return -1;
686 : :
687 : 0 : case RTE_ETH_MQ_TX_VMDQ_DCB:
688 : : vmdq_dcb_tx_conf = ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
689 [ # # # ]: 0 : switch (vmdq_dcb_tx_conf->nb_queue_pools) {
690 : : case RTE_ETH_16_POOLS:
691 : : num_tcs = RTE_ETH_8_TCS;
692 : : break;
693 : 0 : case RTE_ETH_32_POOLS:
694 : : num_tcs = RTE_ETH_4_TCS;
695 : 0 : break;
696 : : default:
697 : : return -1;
698 : : }
699 : : break;
700 : :
701 : : /* RTE_ETH_MQ_TX_VMDQ_ONLY, DCB not enabled */
702 : 0 : case RTE_ETH_MQ_TX_VMDQ_ONLY:
703 : : hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
704 : 0 : vmvir = IXGBE_READ_REG(hw, IXGBE_VMVIR(vf));
705 : 0 : vlana = vmvir & IXGBE_VMVIR_VLANA_MASK;
706 : 0 : vid = vmvir & IXGBE_VMVIR_VLAN_VID_MASK;
707 : 0 : user_priority =
708 : 0 : (vmvir & IXGBE_VMVIR_VLAN_UP_MASK) >> VLAN_PRIO_SHIFT;
709 [ # # ]: 0 : if ((vlana == IXGBE_VMVIR_VLANA_DEFAULT) &&
710 [ # # ]: 0 : ((vid != 0) || (user_priority != 0)))
711 : : num_tcs = 1;
712 : : else
713 : : num_tcs = 0;
714 : : break;
715 : :
716 : 0 : default:
717 : 0 : PMD_DRV_LOG(ERR, "PF work with invalid mode = %d",
718 : : eth_conf->txmode.mq_mode);
719 : 0 : return -1;
720 : : }
721 : 0 : msgbuf[IXGBE_VF_TRANS_VLAN] = num_tcs;
722 : :
723 : 0 : return 0;
724 : : }
725 : :
726 : : static int
727 : 0 : ixgbe_set_vf_mc_promisc(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
728 : : {
729 : 0 : struct ixgbe_vf_info *vfinfo =
730 : 0 : *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
731 : : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
732 : 0 : int xcast_mode = msgbuf[1]; /* msgbuf contains the flag to enable */
733 : : u32 vmolr, fctrl, disable, enable;
734 : :
735 [ # # # ]: 0 : switch (vfinfo[vf].api_version) {
736 : 0 : case ixgbe_mbox_api_12:
737 : : /* promisc introduced in 1.3 version */
738 [ # # ]: 0 : if (xcast_mode == IXGBEVF_XCAST_MODE_PROMISC)
739 : : return -EOPNOTSUPP;
740 : : break;
741 : : /* Fall threw */
742 : : case ixgbe_mbox_api_13:
743 : : break;
744 : : default:
745 : : return -1;
746 : : }
747 : :
748 [ # # ]: 0 : if (vfinfo[vf].xcast_mode == xcast_mode)
749 : 0 : goto out;
750 : :
751 [ # # # # : 0 : switch (xcast_mode) {
# ]
752 : : case IXGBEVF_XCAST_MODE_NONE:
753 : : disable = IXGBE_VMOLR_ROMPE |
754 : : IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
755 : : enable = IXGBE_VMOLR_BAM;
756 : : break;
757 : 0 : case IXGBEVF_XCAST_MODE_MULTI:
758 : : disable = IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
759 : : enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE;
760 : 0 : break;
761 : 0 : case IXGBEVF_XCAST_MODE_ALLMULTI:
762 : : disable = IXGBE_VMOLR_UPE | IXGBE_VMOLR_VPE;
763 : : enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE | IXGBE_VMOLR_MPE;
764 : 0 : break;
765 : 0 : case IXGBEVF_XCAST_MODE_PROMISC:
766 [ # # ]: 0 : if (hw->mac.type <= ixgbe_mac_82599EB)
767 : : return -1;
768 : :
769 : 0 : fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
770 [ # # ]: 0 : if (!(fctrl & IXGBE_FCTRL_UPE)) {
771 : : /* VF promisc requires PF in promisc */
772 : 0 : PMD_DRV_LOG(ERR,
773 : : "Enabling VF promisc requires PF in promisc");
774 : 0 : return -1;
775 : : }
776 : :
777 : : disable = IXGBE_VMOLR_VPE;
778 : : enable = IXGBE_VMOLR_BAM | IXGBE_VMOLR_ROMPE |
779 : : IXGBE_VMOLR_MPE | IXGBE_VMOLR_UPE;
780 : : break;
781 : : default:
782 : : return -1;
783 : : }
784 : :
785 : 0 : vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
786 : 0 : vmolr &= ~disable;
787 : 0 : vmolr |= enable;
788 : 0 : IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
789 : 0 : vfinfo[vf].xcast_mode = xcast_mode;
790 : :
791 : 0 : out:
792 : 0 : msgbuf[1] = xcast_mode;
793 : :
794 : 0 : return 0;
795 : : }
796 : :
797 : : static int
798 : 0 : ixgbe_set_vf_macvlan_msg(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
799 : : {
800 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
801 : 0 : struct ixgbe_vf_info *vf_info =
802 : : *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
803 : 0 : uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
804 : 0 : int index = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
805 : : IXGBE_VT_MSGINFO_SHIFT;
806 : :
807 [ # # ]: 0 : if (index) {
808 : : if (!rte_is_valid_assigned_ether_addr(
809 : : (struct rte_ether_addr *)new_mac)) {
810 : 0 : PMD_DRV_LOG(ERR, "set invalid mac vf:%d", vf);
811 : 0 : return -1;
812 : : }
813 : :
814 : 0 : vf_info[vf].mac_count++;
815 : :
816 : 0 : hw->mac.ops.set_rar(hw, vf_info[vf].mac_count,
817 : : new_mac, vf, IXGBE_RAH_AV);
818 : : } else {
819 [ # # ]: 0 : if (vf_info[vf].mac_count) {
820 : 0 : hw->mac.ops.clear_rar(hw, vf_info[vf].mac_count);
821 : 0 : vf_info[vf].mac_count = 0;
822 : : }
823 : : }
824 : : return 0;
825 : : }
826 : :
827 : : static int
828 : 0 : ixgbe_rcv_msg_from_vf(struct rte_eth_dev *dev, uint16_t vf)
829 : : {
830 : : uint16_t mbx_size = IXGBE_VFMAILBOX_SIZE;
831 : : uint16_t msg_size = IXGBE_VF_MSG_SIZE_DEFAULT;
832 : : uint32_t msgbuf[IXGBE_VFMAILBOX_SIZE];
833 : : int32_t retval;
834 : 0 : struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
835 : 0 : struct ixgbe_vf_info *vfinfo =
836 : : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
837 : : struct rte_pmd_ixgbe_mb_event_param ret_param;
838 : :
839 : 0 : retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
840 [ # # ]: 0 : if (retval) {
841 : 0 : PMD_DRV_LOG(ERR, "Error mbx recv msg from VF %d", vf);
842 : 0 : return retval;
843 : : }
844 : :
845 : : /* do nothing with the message already been processed */
846 [ # # ]: 0 : if (msgbuf[0] & (IXGBE_VT_MSGTYPE_SUCCESS | IXGBE_VT_MSGTYPE_FAILURE))
847 : : return retval;
848 : :
849 : : /* flush the ack before we write any messages back */
850 : 0 : IXGBE_WRITE_FLUSH(hw);
851 : :
852 : : /**
853 : : * initialise structure to send to user application
854 : : * will return response from user in retval field
855 : : */
856 : 0 : ret_param.retval = RTE_PMD_IXGBE_MB_EVENT_PROCEED;
857 : 0 : ret_param.vfid = vf;
858 : 0 : ret_param.msg_type = msgbuf[0] & 0xFFFF;
859 : 0 : ret_param.msg = (void *)msgbuf;
860 : :
861 : : /* perform VF reset */
862 [ # # ]: 0 : if (msgbuf[0] == IXGBE_VF_RESET) {
863 : 0 : int ret = ixgbe_vf_reset(dev, vf, msgbuf);
864 : :
865 : 0 : vfinfo[vf].clear_to_send = true;
866 : :
867 : : /* notify application about VF reset */
868 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX,
869 : : &ret_param);
870 : 0 : return ret;
871 : : }
872 : :
873 : : /**
874 : : * ask user application if we allowed to perform those functions
875 : : * if we get ret_param.retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED
876 : : * then business as usual,
877 : : * if 0, do nothing and send ACK to VF
878 : : * if ret_param.retval > 1, do nothing and send NAK to VF
879 : : */
880 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX, &ret_param);
881 : :
882 : 0 : retval = ret_param.retval;
883 : :
884 : : /* check & process VF to PF mailbox message */
885 [ # # # # : 0 : switch ((msgbuf[0] & 0xFFFF)) {
# # # #
# ]
886 : 0 : case IXGBE_VF_SET_MAC_ADDR:
887 [ # # ]: 0 : if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
888 : 0 : retval = ixgbe_vf_set_mac_addr(dev, vf, msgbuf);
889 : : break;
890 : 0 : case IXGBE_VF_SET_MULTICAST:
891 [ # # ]: 0 : if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
892 : 0 : retval = ixgbe_vf_set_multicast(dev, vf, msgbuf);
893 : : break;
894 : 0 : case IXGBE_VF_SET_LPE:
895 [ # # ]: 0 : if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
896 : 0 : retval = ixgbe_set_vf_lpe(dev, vf, msgbuf);
897 : : break;
898 : 0 : case IXGBE_VF_SET_VLAN:
899 [ # # ]: 0 : if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
900 : 0 : retval = ixgbe_vf_set_vlan(dev, vf, msgbuf);
901 : : break;
902 : 0 : case IXGBE_VF_API_NEGOTIATE:
903 : 0 : retval = ixgbe_negotiate_vf_api(dev, vf, msgbuf);
904 : 0 : break;
905 : 0 : case IXGBE_VF_GET_QUEUES:
906 : 0 : retval = ixgbe_get_vf_queues(dev, vf, msgbuf);
907 : : msg_size = IXGBE_VF_GET_QUEUE_MSG_SIZE;
908 : 0 : break;
909 : 0 : case IXGBE_VF_UPDATE_XCAST_MODE:
910 [ # # ]: 0 : if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
911 : 0 : retval = ixgbe_set_vf_mc_promisc(dev, vf, msgbuf);
912 : : break;
913 : 0 : case IXGBE_VF_SET_MACVLAN:
914 [ # # ]: 0 : if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
915 : 0 : retval = ixgbe_set_vf_macvlan_msg(dev, vf, msgbuf);
916 : : break;
917 : 0 : default:
918 : 0 : PMD_DRV_LOG(DEBUG, "Unhandled Msg %8.8x", (unsigned)msgbuf[0]);
919 : : retval = IXGBE_ERR_MBX;
920 : : break;
921 : : }
922 : :
923 : : /* response the VF according to the message process result */
924 [ # # ]: 0 : if (retval)
925 : 0 : msgbuf[0] |= IXGBE_VT_MSGTYPE_FAILURE;
926 : : else
927 : 0 : msgbuf[0] |= IXGBE_VT_MSGTYPE_SUCCESS;
928 : :
929 : 0 : msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
930 : :
931 : 0 : ixgbe_write_mbx(hw, msgbuf, msg_size, vf);
932 : :
933 : 0 : return retval;
934 : : }
935 : :
936 : : static inline void
937 : 0 : ixgbe_rcv_ack_from_vf(struct rte_eth_dev *dev, uint16_t vf)
938 : : {
939 : 0 : uint32_t msg = IXGBE_VT_MSGTYPE_FAILURE;
940 : 0 : struct ixgbe_hw *hw =
941 : 0 : IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
942 : 0 : struct ixgbe_vf_info *vfinfo =
943 : : *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
944 : :
945 [ # # ]: 0 : if (!vfinfo[vf].clear_to_send)
946 : 0 : ixgbe_write_mbx(hw, &msg, 1, vf);
947 : 0 : }
948 : :
949 : 0 : void ixgbe_pf_mbx_process(struct rte_eth_dev *eth_dev)
950 : : {
951 : : uint16_t vf;
952 : 0 : struct ixgbe_hw *hw =
953 : 0 : IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
954 : :
955 [ # # ]: 0 : for (vf = 0; vf < dev_num_vf(eth_dev); vf++) {
956 : : /* check & process vf function level reset */
957 [ # # ]: 0 : if (!ixgbe_check_for_rst(hw, vf))
958 : 0 : ixgbe_vf_reset_event(eth_dev, vf);
959 : :
960 : : /* check & process vf mailbox messages */
961 [ # # ]: 0 : if (!ixgbe_check_for_msg(hw, vf))
962 : 0 : ixgbe_rcv_msg_from_vf(eth_dev, vf);
963 : :
964 : : /* check & process acks from vf */
965 [ # # ]: 0 : if (!ixgbe_check_for_ack(hw, vf))
966 : 0 : ixgbe_rcv_ack_from_vf(eth_dev, vf);
967 : : }
968 : 0 : }
|