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