1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
13 #include <rte_interrupts.h>
15 #include <rte_debug.h>
17 #include <rte_ether.h>
18 #include <rte_ethdev_driver.h>
19 #include <rte_memcpy.h>
20 #include <rte_malloc.h>
21 #include <rte_random.h>
23 #include "base/ixgbe_common.h"
24 #include "ixgbe_ethdev.h"
25 #include "rte_pmd_ixgbe.h"
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
32 static inline uint16_t
33 dev_num_vf(struct rte_eth_dev *eth_dev)
35 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
37 return pci_dev->max_vfs;
41 int ixgbe_vf_perm_addr_gen(struct rte_eth_dev *dev, uint16_t vf_num)
43 unsigned char vf_mac_addr[ETHER_ADDR_LEN];
44 struct ixgbe_vf_info *vfinfo =
45 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
48 for (vfn = 0; vfn < vf_num; vfn++) {
49 eth_random_addr(vf_mac_addr);
50 /* keep the random address as default */
51 memcpy(vfinfo[vfn].vf_mac_addresses, vf_mac_addr,
59 ixgbe_mb_intr_setup(struct rte_eth_dev *dev)
61 struct ixgbe_interrupt *intr =
62 IXGBE_DEV_PRIVATE_TO_INTR(dev->data->dev_private);
64 intr->mask |= IXGBE_EICR_MAILBOX;
69 void ixgbe_pf_host_init(struct rte_eth_dev *eth_dev)
71 struct ixgbe_vf_info **vfinfo =
72 IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
73 struct ixgbe_mirror_info *mirror_info =
74 IXGBE_DEV_PRIVATE_TO_PFDATA(eth_dev->data->dev_private);
75 struct ixgbe_uta_info *uta_info =
76 IXGBE_DEV_PRIVATE_TO_UTA(eth_dev->data->dev_private);
78 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
82 PMD_INIT_FUNC_TRACE();
84 RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
85 vf_num = dev_num_vf(eth_dev);
89 *vfinfo = rte_zmalloc("vf_info", sizeof(struct ixgbe_vf_info) * vf_num, 0);
91 rte_panic("Cannot allocate memory for private VF data\n");
93 memset(mirror_info, 0, sizeof(struct ixgbe_mirror_info));
94 memset(uta_info, 0, sizeof(struct ixgbe_uta_info));
95 hw->mac.mc_filter_type = 0;
97 if (vf_num >= ETH_32_POOLS) {
99 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_64_POOLS;
100 } else if (vf_num >= ETH_16_POOLS) {
102 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_32_POOLS;
105 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_16_POOLS;
108 RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = nb_queue;
109 RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = vf_num;
110 RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = (uint16_t)(vf_num * nb_queue);
112 ixgbe_vf_perm_addr_gen(eth_dev, vf_num);
114 /* init_mailbox_params */
115 hw->mbx.ops.init_params(hw);
117 /* set mb interrupt mask */
118 ixgbe_mb_intr_setup(eth_dev);
121 void ixgbe_pf_host_uninit(struct rte_eth_dev *eth_dev)
123 struct ixgbe_vf_info **vfinfo;
126 PMD_INIT_FUNC_TRACE();
128 vfinfo = IXGBE_DEV_PRIVATE_TO_P_VFDATA(eth_dev->data->dev_private);
130 RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
131 RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = 0;
132 RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = 0;
133 RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = 0;
135 vf_num = dev_num_vf(eth_dev);
144 ixgbe_add_tx_flow_control_drop_filter(struct rte_eth_dev *eth_dev)
146 struct ixgbe_hw *hw =
147 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
148 struct ixgbe_filter_info *filter_info =
149 IXGBE_DEV_PRIVATE_TO_FILTER_INFO(eth_dev->data->dev_private);
152 struct ixgbe_ethertype_filter ethertype_filter;
154 if (!hw->mac.ops.set_ethertype_anti_spoofing) {
155 RTE_LOG(INFO, PMD, "ether type anti-spoofing is not"
160 i = ixgbe_ethertype_filter_lookup(filter_info,
161 IXGBE_ETHERTYPE_FLOW_CTRL);
163 RTE_LOG(ERR, PMD, "A ether type filter"
164 " entity for flow control already exists!\n");
168 ethertype_filter.ethertype = IXGBE_ETHERTYPE_FLOW_CTRL;
169 ethertype_filter.etqf = IXGBE_ETQF_FILTER_EN |
170 IXGBE_ETQF_TX_ANTISPOOF |
171 IXGBE_ETHERTYPE_FLOW_CTRL;
172 ethertype_filter.etqs = 0;
173 ethertype_filter.conf = TRUE;
174 i = ixgbe_ethertype_filter_insert(filter_info,
177 RTE_LOG(ERR, PMD, "Cannot find an unused ether type filter"
178 " entity for flow control.\n");
182 IXGBE_WRITE_REG(hw, IXGBE_ETQF(i),
183 (IXGBE_ETQF_FILTER_EN |
184 IXGBE_ETQF_TX_ANTISPOOF |
185 IXGBE_ETHERTYPE_FLOW_CTRL));
187 vf_num = dev_num_vf(eth_dev);
188 for (i = 0; i < vf_num; i++)
189 hw->mac.ops.set_ethertype_anti_spoofing(hw, true, i);
192 int ixgbe_pf_host_configure(struct rte_eth_dev *eth_dev)
194 uint32_t vtctl, fcrth;
195 uint32_t vfre_slot, vfre_offset;
197 const uint8_t VFRE_SHIFT = 5; /* VFRE 32 bits per slot */
198 const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
199 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
200 uint32_t gpie, gcr_ext;
204 vf_num = dev_num_vf(eth_dev);
208 /* enable VMDq and set the default pool for PF */
209 vtctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
210 vtctl |= IXGBE_VMD_CTL_VMDQ_EN;
211 vtctl &= ~IXGBE_VT_CTL_POOL_MASK;
212 vtctl |= RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx
213 << IXGBE_VT_CTL_POOL_SHIFT;
214 vtctl |= IXGBE_VT_CTL_REPLEN;
215 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vtctl);
217 vfre_offset = vf_num & VFRE_MASK;
218 vfre_slot = (vf_num >> VFRE_SHIFT) > 0 ? 1 : 0;
220 /* Enable pools reserved to PF only */
221 IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot), (~0U) << vfre_offset);
222 IXGBE_WRITE_REG(hw, IXGBE_VFRE(vfre_slot ^ 1), vfre_slot - 1);
223 IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot), (~0U) << vfre_offset);
224 IXGBE_WRITE_REG(hw, IXGBE_VFTE(vfre_slot ^ 1), vfre_slot - 1);
226 /* PFDMA Tx General Switch Control Enables VMDQ loopback */
227 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
229 /* clear VMDq map to perment rar 0 */
230 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
232 /* clear VMDq map to scan rar 127 */
233 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(hw->mac.num_rar_entries), 0);
234 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(hw->mac.num_rar_entries), 0);
236 /* set VMDq map to default PF pool */
237 hw->mac.ops.set_vmdq(hw, 0, RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx);
240 * SW msut set GCR_EXT.VT_Mode the same as GPIE.VT_Mode
242 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
243 gcr_ext &= ~IXGBE_GCR_EXT_VT_MODE_MASK;
245 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
246 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
247 gpie |= IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT;
249 switch (RTE_ETH_DEV_SRIOV(eth_dev).active) {
251 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
252 gpie |= IXGBE_GPIE_VTMODE_64;
255 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_32;
256 gpie |= IXGBE_GPIE_VTMODE_32;
259 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_16;
260 gpie |= IXGBE_GPIE_VTMODE_16;
264 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
265 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
268 * enable vlan filtering and allow all vlan tags through
270 vlanctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
271 vlanctrl |= IXGBE_VLNCTRL_VFE; /* enable vlan filters */
272 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlanctrl);
274 /* VFTA - enable all vlan filters */
275 for (i = 0; i < IXGBE_MAX_VFTA; i++)
276 IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), 0xFFFFFFFF);
278 /* Enable MAC Anti-Spoofing */
279 hw->mac.ops.set_mac_anti_spoofing(hw, FALSE, vf_num);
281 /* set flow control threshold to max to avoid tx switch hang */
282 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
283 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
284 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
285 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
288 ixgbe_add_tx_flow_control_drop_filter(eth_dev);
294 set_rx_mode(struct rte_eth_dev *dev)
296 struct rte_eth_dev_data *dev_data = dev->data;
297 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
298 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
299 uint16_t vfn = dev_num_vf(dev);
301 /* Check for Promiscuous and All Multicast modes */
302 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
304 /* set all bits that we expect to always be set */
305 fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
306 fctrl |= IXGBE_FCTRL_BAM;
308 /* clear the bits we are changing the status of */
309 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
311 if (dev_data->promiscuous) {
312 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
313 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
315 if (dev_data->all_multicast) {
316 fctrl |= IXGBE_FCTRL_MPE;
317 vmolr |= IXGBE_VMOLR_MPE;
319 vmolr |= IXGBE_VMOLR_ROMPE;
323 if (hw->mac.type != ixgbe_mac_82598EB) {
324 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(vfn)) &
325 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
327 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vfn), vmolr);
330 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
332 ixgbe_vlan_hw_strip_config(dev);
336 ixgbe_vf_reset_event(struct rte_eth_dev *dev, uint16_t vf)
338 struct ixgbe_hw *hw =
339 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
340 struct ixgbe_vf_info *vfinfo =
341 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
342 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
343 uint32_t vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
345 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_ROMPE |
346 IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE);
347 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
349 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), 0);
351 /* reset multicast table array for vf */
352 vfinfo[vf].num_vf_mc_hashes = 0;
357 hw->mac.ops.clear_rar(hw, rar_entry);
361 ixgbe_vf_reset_msg(struct rte_eth_dev *dev, uint16_t vf)
363 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
365 uint32_t reg_offset, vf_shift;
366 const uint8_t VFRE_SHIFT = 5; /* VFRE 32 bits per slot */
367 const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
368 uint8_t nb_q_per_pool;
371 vf_shift = vf & VFRE_MASK;
372 reg_offset = (vf >> VFRE_SHIFT) > 0 ? 1 : 0;
374 /* enable transmit for vf */
375 reg = IXGBE_READ_REG(hw, IXGBE_VFTE(reg_offset));
376 reg |= (reg | (1 << vf_shift));
377 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), reg);
379 /* enable all queue drop for IOV */
380 nb_q_per_pool = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
381 for (i = vf * nb_q_per_pool; i < (vf + 1) * nb_q_per_pool; i++) {
382 IXGBE_WRITE_FLUSH(hw);
383 reg = IXGBE_QDE_ENABLE | IXGBE_QDE_WRITE;
384 reg |= i << IXGBE_QDE_IDX_SHIFT;
385 IXGBE_WRITE_REG(hw, IXGBE_QDE, reg);
388 /* enable receive for vf */
389 reg = IXGBE_READ_REG(hw, IXGBE_VFRE(reg_offset));
390 reg |= (reg | (1 << vf_shift));
391 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), reg);
393 /* Enable counting of spoofed packets in the SSVPC register */
394 reg = IXGBE_READ_REG(hw, IXGBE_VMECM(reg_offset));
395 reg |= (1 << vf_shift);
396 IXGBE_WRITE_REG(hw, IXGBE_VMECM(reg_offset), reg);
398 ixgbe_vf_reset_event(dev, vf);
402 ixgbe_enable_vf_mc_promisc(struct rte_eth_dev *dev, uint32_t vf)
404 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
407 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
409 RTE_LOG(INFO, PMD, "VF %u: enabling multicast promiscuous\n", vf);
411 vmolr |= IXGBE_VMOLR_MPE;
413 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
419 ixgbe_disable_vf_mc_promisc(struct rte_eth_dev *dev, uint32_t vf)
421 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
424 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
426 RTE_LOG(INFO, PMD, "VF %u: disabling multicast promiscuous\n", vf);
428 vmolr &= ~IXGBE_VMOLR_MPE;
430 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
436 ixgbe_vf_reset(struct rte_eth_dev *dev, uint16_t vf, uint32_t *msgbuf)
438 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
439 struct ixgbe_vf_info *vfinfo =
440 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
441 unsigned char *vf_mac = vfinfo[vf].vf_mac_addresses;
442 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
443 uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
445 ixgbe_vf_reset_msg(dev, vf);
447 hw->mac.ops.set_rar(hw, rar_entry, vf_mac, vf, IXGBE_RAH_AV);
449 /* Disable multicast promiscuous at reset */
450 ixgbe_disable_vf_mc_promisc(dev, vf);
452 /* reply to reset with ack and vf mac address */
453 msgbuf[0] = IXGBE_VF_RESET | IXGBE_VT_MSGTYPE_ACK;
454 rte_memcpy(new_mac, vf_mac, ETHER_ADDR_LEN);
456 * Piggyback the multicast filter type so VF can compute the
459 msgbuf[3] = hw->mac.mc_filter_type;
460 ixgbe_write_mbx(hw, msgbuf, IXGBE_VF_PERMADDR_MSG_LEN, vf);
466 ixgbe_vf_set_mac_addr(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
468 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
469 struct ixgbe_vf_info *vfinfo =
470 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
471 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
472 uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
474 if (is_valid_assigned_ether_addr((struct ether_addr *)new_mac)) {
475 rte_memcpy(vfinfo[vf].vf_mac_addresses, new_mac, 6);
476 return hw->mac.ops.set_rar(hw, rar_entry, new_mac, vf, IXGBE_RAH_AV);
482 ixgbe_vf_set_multicast(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
484 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
485 struct ixgbe_vf_info *vfinfo =
486 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
487 int nb_entries = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK) >>
488 IXGBE_VT_MSGINFO_SHIFT;
489 uint16_t *hash_list = (uint16_t *)&msgbuf[1];
492 const uint32_t IXGBE_MTA_INDEX_MASK = 0x7F;
493 const uint32_t IXGBE_MTA_BIT_SHIFT = 5;
494 const uint32_t IXGBE_MTA_BIT_MASK = (0x1 << IXGBE_MTA_BIT_SHIFT) - 1;
498 /* Disable multicast promiscuous first */
499 ixgbe_disable_vf_mc_promisc(dev, vf);
501 /* only so many hash values supported */
502 nb_entries = RTE_MIN(nb_entries, IXGBE_MAX_VF_MC_ENTRIES);
504 /* store the mc entries */
505 vfinfo->num_vf_mc_hashes = (uint16_t)nb_entries;
506 for (i = 0; i < nb_entries; i++) {
507 vfinfo->vf_mc_hashes[i] = hash_list[i];
510 for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
511 mta_idx = (vfinfo->vf_mc_hashes[i] >> IXGBE_MTA_BIT_SHIFT)
512 & IXGBE_MTA_INDEX_MASK;
513 mta_shift = vfinfo->vf_mc_hashes[i] & IXGBE_MTA_BIT_MASK;
514 reg_val = IXGBE_READ_REG(hw, IXGBE_MTA(mta_idx));
515 reg_val |= (1 << mta_shift);
516 IXGBE_WRITE_REG(hw, IXGBE_MTA(mta_idx), reg_val);
523 ixgbe_vf_set_vlan(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
526 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
527 struct ixgbe_vf_info *vfinfo =
528 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
530 add = (msgbuf[0] & IXGBE_VT_MSGINFO_MASK)
531 >> IXGBE_VT_MSGINFO_SHIFT;
532 vid = (msgbuf[1] & IXGBE_VLVF_VLANID_MASK);
535 vfinfo[vf].vlan_count++;
536 else if (vfinfo[vf].vlan_count)
537 vfinfo[vf].vlan_count--;
538 return hw->mac.ops.set_vfta(hw, vid, vf, (bool)add, false);
542 ixgbe_set_vf_lpe(struct rte_eth_dev *dev, __rte_unused uint32_t vf, uint32_t *msgbuf)
544 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
545 uint32_t new_mtu = msgbuf[1];
547 int max_frame = new_mtu + ETHER_HDR_LEN + ETHER_CRC_LEN;
549 /* X540 and X550 support jumbo frames in IOV mode */
550 if (hw->mac.type != ixgbe_mac_X540 &&
551 hw->mac.type != ixgbe_mac_X550 &&
552 hw->mac.type != ixgbe_mac_X550EM_x &&
553 hw->mac.type != ixgbe_mac_X550EM_a)
556 if ((max_frame < ETHER_MIN_LEN) || (max_frame > ETHER_MAX_JUMBO_FRAME_LEN))
559 max_frs = (IXGBE_READ_REG(hw, IXGBE_MAXFRS) &
560 IXGBE_MHADD_MFS_MASK) >> IXGBE_MHADD_MFS_SHIFT;
561 if (max_frs < new_mtu) {
562 max_frs = new_mtu << IXGBE_MHADD_MFS_SHIFT;
563 IXGBE_WRITE_REG(hw, IXGBE_MAXFRS, max_frs);
570 ixgbe_negotiate_vf_api(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
572 uint32_t api_version = msgbuf[1];
573 struct ixgbe_vf_info *vfinfo =
574 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
576 switch (api_version) {
577 case ixgbe_mbox_api_10:
578 case ixgbe_mbox_api_11:
579 case ixgbe_mbox_api_12:
580 vfinfo[vf].api_version = (uint8_t)api_version;
586 RTE_LOG(ERR, PMD, "Negotiate invalid api version %u from VF %d\n",
593 ixgbe_get_vf_queues(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
595 struct ixgbe_vf_info *vfinfo =
596 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
597 uint32_t default_q = vf * RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
598 struct rte_eth_conf *eth_conf;
599 struct rte_eth_vmdq_dcb_tx_conf *vmdq_dcb_tx_conf;
603 #define IXGBE_VMVIR_VLANA_MASK 0xC0000000
604 #define IXGBE_VMVIR_VLAN_VID_MASK 0x00000FFF
605 #define IXGBE_VMVIR_VLAN_UP_MASK 0x0000E000
606 #define VLAN_PRIO_SHIFT 13
611 /* Verify if the PF supports the mbox APIs version or not */
612 switch (vfinfo[vf].api_version) {
613 case ixgbe_mbox_api_20:
614 case ixgbe_mbox_api_11:
615 case ixgbe_mbox_api_12:
621 /* Notify VF of Rx and Tx queue number */
622 msgbuf[IXGBE_VF_RX_QUEUES] = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
623 msgbuf[IXGBE_VF_TX_QUEUES] = RTE_ETH_DEV_SRIOV(dev).nb_q_per_pool;
625 /* Notify VF of default queue */
626 msgbuf[IXGBE_VF_DEF_QUEUE] = default_q;
628 /* Notify VF of number of DCB traffic classes */
629 eth_conf = &dev->data->dev_conf;
630 switch (eth_conf->txmode.mq_mode) {
633 RTE_LOG(ERR, PMD, "PF must work with virtualization for VF %u"
634 ", but its tx mode = %d\n", vf,
635 eth_conf->txmode.mq_mode);
638 case ETH_MQ_TX_VMDQ_DCB:
639 vmdq_dcb_tx_conf = ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
640 switch (vmdq_dcb_tx_conf->nb_queue_pools) {
652 /* ETH_MQ_TX_VMDQ_ONLY, DCB not enabled */
653 case ETH_MQ_TX_VMDQ_ONLY:
654 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
655 vmvir = IXGBE_READ_REG(hw, IXGBE_VMVIR(vf));
656 vlana = vmvir & IXGBE_VMVIR_VLANA_MASK;
657 vid = vmvir & IXGBE_VMVIR_VLAN_VID_MASK;
659 (vmvir & IXGBE_VMVIR_VLAN_UP_MASK) >> VLAN_PRIO_SHIFT;
660 if ((vlana == IXGBE_VMVIR_VLANA_DEFAULT) &&
661 ((vid != 0) || (user_priority != 0)))
668 RTE_LOG(ERR, PMD, "PF work with invalid mode = %d\n",
669 eth_conf->txmode.mq_mode);
672 msgbuf[IXGBE_VF_TRANS_VLAN] = num_tcs;
678 ixgbe_set_vf_mc_promisc(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
680 struct ixgbe_vf_info *vfinfo =
681 *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
682 bool enable = !!msgbuf[1]; /* msgbuf contains the flag to enable */
684 switch (vfinfo[vf].api_version) {
685 case ixgbe_mbox_api_12:
692 return ixgbe_enable_vf_mc_promisc(dev, vf);
694 return ixgbe_disable_vf_mc_promisc(dev, vf);
698 ixgbe_rcv_msg_from_vf(struct rte_eth_dev *dev, uint16_t vf)
700 uint16_t mbx_size = IXGBE_VFMAILBOX_SIZE;
701 uint16_t msg_size = IXGBE_VF_MSG_SIZE_DEFAULT;
702 uint32_t msgbuf[IXGBE_VFMAILBOX_SIZE];
704 struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
705 struct ixgbe_vf_info *vfinfo =
706 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
707 struct rte_pmd_ixgbe_mb_event_param ret_param;
709 retval = ixgbe_read_mbx(hw, msgbuf, mbx_size, vf);
711 PMD_DRV_LOG(ERR, "Error mbx recv msg from VF %d", vf);
715 /* do nothing with the message already been processed */
716 if (msgbuf[0] & (IXGBE_VT_MSGTYPE_ACK | IXGBE_VT_MSGTYPE_NACK))
719 /* flush the ack before we write any messages back */
720 IXGBE_WRITE_FLUSH(hw);
723 * initialise structure to send to user application
724 * will return response from user in retval field
726 ret_param.retval = RTE_PMD_IXGBE_MB_EVENT_PROCEED;
728 ret_param.msg_type = msgbuf[0] & 0xFFFF;
729 ret_param.msg = (void *)msgbuf;
731 /* perform VF reset */
732 if (msgbuf[0] == IXGBE_VF_RESET) {
733 int ret = ixgbe_vf_reset(dev, vf, msgbuf);
735 vfinfo[vf].clear_to_send = true;
737 /* notify application about VF reset */
738 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX,
744 * ask user application if we allowed to perform those functions
745 * if we get ret_param.retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED
746 * then business as usual,
747 * if 0, do nothing and send ACK to VF
748 * if ret_param.retval > 1, do nothing and send NAK to VF
750 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_VF_MBOX,
753 retval = ret_param.retval;
755 /* check & process VF to PF mailbox message */
756 switch ((msgbuf[0] & 0xFFFF)) {
757 case IXGBE_VF_SET_MAC_ADDR:
758 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
759 retval = ixgbe_vf_set_mac_addr(dev, vf, msgbuf);
761 case IXGBE_VF_SET_MULTICAST:
762 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
763 retval = ixgbe_vf_set_multicast(dev, vf, msgbuf);
765 case IXGBE_VF_SET_LPE:
766 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
767 retval = ixgbe_set_vf_lpe(dev, vf, msgbuf);
769 case IXGBE_VF_SET_VLAN:
770 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
771 retval = ixgbe_vf_set_vlan(dev, vf, msgbuf);
773 case IXGBE_VF_API_NEGOTIATE:
774 retval = ixgbe_negotiate_vf_api(dev, vf, msgbuf);
776 case IXGBE_VF_GET_QUEUES:
777 retval = ixgbe_get_vf_queues(dev, vf, msgbuf);
778 msg_size = IXGBE_VF_GET_QUEUE_MSG_SIZE;
780 case IXGBE_VF_UPDATE_XCAST_MODE:
781 if (retval == RTE_PMD_IXGBE_MB_EVENT_PROCEED)
782 retval = ixgbe_set_vf_mc_promisc(dev, vf, msgbuf);
785 PMD_DRV_LOG(DEBUG, "Unhandled Msg %8.8x", (unsigned)msgbuf[0]);
786 retval = IXGBE_ERR_MBX;
790 /* response the VF according to the message process result */
792 msgbuf[0] |= IXGBE_VT_MSGTYPE_NACK;
794 msgbuf[0] |= IXGBE_VT_MSGTYPE_ACK;
796 msgbuf[0] |= IXGBE_VT_MSGTYPE_CTS;
798 ixgbe_write_mbx(hw, msgbuf, msg_size, vf);
804 ixgbe_rcv_ack_from_vf(struct rte_eth_dev *dev, uint16_t vf)
806 uint32_t msg = IXGBE_VT_MSGTYPE_NACK;
807 struct ixgbe_hw *hw =
808 IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
809 struct ixgbe_vf_info *vfinfo =
810 *IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private);
812 if (!vfinfo[vf].clear_to_send)
813 ixgbe_write_mbx(hw, &msg, 1, vf);
816 void ixgbe_pf_mbx_process(struct rte_eth_dev *eth_dev)
819 struct ixgbe_hw *hw =
820 IXGBE_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
822 for (vf = 0; vf < dev_num_vf(eth_dev); vf++) {
823 /* check & process vf function level reset */
824 if (!ixgbe_check_for_rst(hw, vf))
825 ixgbe_vf_reset_event(eth_dev, vf);
827 /* check & process vf mailbox messages */
828 if (!ixgbe_check_for_msg(hw, vf))
829 ixgbe_rcv_msg_from_vf(eth_dev, vf);
831 /* check & process acks from vf */
832 if (!ixgbe_check_for_ack(hw, vf))
833 ixgbe_rcv_ack_from_vf(eth_dev, vf);