1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
14 #include <rte_interrupts.h>
16 #include <rte_debug.h>
18 #include <rte_ether.h>
19 #include <ethdev_driver.h>
20 #include <rte_memcpy.h>
21 #include <rte_malloc.h>
22 #include <rte_random.h>
23 #include <rte_bus_pci.h>
25 #include "base/txgbe.h"
26 #include "txgbe_ethdev.h"
27 #include "rte_pmd_txgbe.h"
29 #define TXGBE_MAX_VFTA (128)
30 #define TXGBE_VF_MSG_SIZE_DEFAULT 1
31 #define TXGBE_VF_GET_QUEUE_MSG_SIZE 5
33 static inline uint16_t
34 dev_num_vf(struct rte_eth_dev *eth_dev)
36 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
38 return pci_dev->max_vfs;
42 int txgbe_vf_perm_addr_gen(struct rte_eth_dev *dev, uint16_t vf_num)
44 unsigned char vf_mac_addr[RTE_ETHER_ADDR_LEN];
45 struct txgbe_vf_info *vfinfo = *TXGBE_DEV_VFDATA(dev);
48 for (vfn = 0; vfn < vf_num; vfn++) {
49 rte_eth_random_addr(vf_mac_addr);
50 /* keep the random address as default */
51 memcpy(vfinfo[vfn].vf_mac_addresses, vf_mac_addr,
59 txgbe_mb_intr_setup(struct rte_eth_dev *dev)
61 struct txgbe_interrupt *intr = TXGBE_DEV_INTR(dev);
63 intr->mask_misc |= TXGBE_ICRMISC_VFMBX;
68 int txgbe_pf_host_init(struct rte_eth_dev *eth_dev)
70 struct txgbe_vf_info **vfinfo = TXGBE_DEV_VFDATA(eth_dev);
71 struct txgbe_uta_info *uta_info = TXGBE_DEV_UTA_INFO(eth_dev);
72 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
77 PMD_INIT_FUNC_TRACE();
79 RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
80 vf_num = dev_num_vf(eth_dev);
84 *vfinfo = rte_zmalloc("vf_info",
85 sizeof(struct txgbe_vf_info) * vf_num, 0);
86 if (*vfinfo == NULL) {
88 "Cannot allocate memory for private VF data\n");
92 ret = rte_eth_switch_domain_alloc(&(*vfinfo)->switch_domain_id);
95 "failed to allocate switch domain for device %d", ret);
101 memset(uta_info, 0, sizeof(struct txgbe_uta_info));
102 hw->mac.mc_filter_type = 0;
104 if (vf_num >= ETH_32_POOLS) {
106 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_64_POOLS;
107 } else if (vf_num >= ETH_16_POOLS) {
109 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_32_POOLS;
112 RTE_ETH_DEV_SRIOV(eth_dev).active = ETH_16_POOLS;
115 RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = nb_queue;
116 RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = vf_num;
117 RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx =
118 (uint16_t)(vf_num * nb_queue);
120 txgbe_vf_perm_addr_gen(eth_dev, vf_num);
122 /* init_mailbox_params */
123 hw->mbx.init_params(hw);
125 /* set mb interrupt mask */
126 txgbe_mb_intr_setup(eth_dev);
131 void txgbe_pf_host_uninit(struct rte_eth_dev *eth_dev)
133 struct txgbe_vf_info **vfinfo;
137 PMD_INIT_FUNC_TRACE();
139 RTE_ETH_DEV_SRIOV(eth_dev).active = 0;
140 RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool = 0;
141 RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx = 0;
142 RTE_ETH_DEV_SRIOV(eth_dev).def_pool_q_idx = 0;
144 vf_num = dev_num_vf(eth_dev);
148 vfinfo = TXGBE_DEV_VFDATA(eth_dev);
152 ret = rte_eth_switch_domain_free((*vfinfo)->switch_domain_id);
154 PMD_INIT_LOG(WARNING, "failed to free switch domain: %d", ret);
161 txgbe_add_tx_flow_control_drop_filter(struct rte_eth_dev *eth_dev)
163 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
164 struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(eth_dev);
167 struct txgbe_ethertype_filter ethertype_filter;
169 if (!hw->mac.set_ethertype_anti_spoofing) {
170 PMD_DRV_LOG(INFO, "ether type anti-spoofing is not supported.\n");
174 i = txgbe_ethertype_filter_lookup(filter_info,
175 TXGBE_ETHERTYPE_FLOW_CTRL);
177 PMD_DRV_LOG(ERR, "A ether type filter entity for flow control already exists!\n");
181 ethertype_filter.ethertype = TXGBE_ETHERTYPE_FLOW_CTRL;
182 ethertype_filter.etqf = TXGBE_ETFLT_ENA |
184 TXGBE_ETHERTYPE_FLOW_CTRL;
185 ethertype_filter.etqs = 0;
186 ethertype_filter.conf = TRUE;
187 i = txgbe_ethertype_filter_insert(filter_info,
190 PMD_DRV_LOG(ERR, "Cannot find an unused ether type filter entity for flow control.\n");
194 wr32(hw, TXGBE_ETFLT(i),
197 TXGBE_ETHERTYPE_FLOW_CTRL));
199 vf_num = dev_num_vf(eth_dev);
200 for (i = 0; i < vf_num; i++)
201 hw->mac.set_ethertype_anti_spoofing(hw, true, i);
204 int txgbe_pf_host_configure(struct rte_eth_dev *eth_dev)
206 uint32_t vtctl, fcrth;
207 uint32_t vfre_slot, vfre_offset;
209 const uint8_t VFRE_SHIFT = 5; /* VFRE 32 bits per slot */
210 const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
211 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
217 vf_num = dev_num_vf(eth_dev);
221 /* enable VMDq and set the default pool for PF */
222 vtctl = rd32(hw, TXGBE_POOLCTL);
223 vtctl &= ~TXGBE_POOLCTL_DEFPL_MASK;
224 vtctl |= TXGBE_POOLCTL_DEFPL(RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx);
225 vtctl |= TXGBE_POOLCTL_RPLEN;
226 wr32(hw, TXGBE_POOLCTL, vtctl);
228 vfre_offset = vf_num & VFRE_MASK;
229 vfre_slot = (vf_num >> VFRE_SHIFT) > 0 ? 1 : 0;
231 /* Enable pools reserved to PF only */
232 wr32(hw, TXGBE_POOLRXENA(vfre_slot), (~0U) << vfre_offset);
233 wr32(hw, TXGBE_POOLRXENA(vfre_slot ^ 1), vfre_slot - 1);
234 wr32(hw, TXGBE_POOLTXENA(vfre_slot), (~0U) << vfre_offset);
235 wr32(hw, TXGBE_POOLTXENA(vfre_slot ^ 1), vfre_slot - 1);
237 wr32(hw, TXGBE_PSRCTL, TXGBE_PSRCTL_LBENA);
239 /* clear VMDq map to perment rar 0 */
240 hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
242 /* clear VMDq map to scan rar 127 */
243 wr32(hw, TXGBE_ETHADDRIDX, hw->mac.num_rar_entries);
244 wr32(hw, TXGBE_ETHADDRASSL, 0);
245 wr32(hw, TXGBE_ETHADDRASSH, 0);
247 /* set VMDq map to default PF pool */
248 hw->mac.set_vmdq(hw, 0, RTE_ETH_DEV_SRIOV(eth_dev).def_vmdq_idx);
251 * SW msut set PORTCTL.VT_Mode the same as GPIE.VT_Mode
253 gpie = rd32(hw, TXGBE_GPIE);
254 gpie |= TXGBE_GPIE_MSIX;
255 gcr_ext = rd32(hw, TXGBE_PORTCTL);
256 gcr_ext &= ~TXGBE_PORTCTL_NUMVT_MASK;
258 switch (RTE_ETH_DEV_SRIOV(eth_dev).active) {
260 gcr_ext |= TXGBE_PORTCTL_NUMVT_64;
263 gcr_ext |= TXGBE_PORTCTL_NUMVT_32;
266 gcr_ext |= TXGBE_PORTCTL_NUMVT_16;
270 wr32(hw, TXGBE_PORTCTL, gcr_ext);
271 wr32(hw, TXGBE_GPIE, gpie);
274 * enable vlan filtering and allow all vlan tags through
276 vlanctrl = rd32(hw, TXGBE_VLANCTL);
277 vlanctrl |= TXGBE_VLANCTL_VFE; /* enable vlan filters */
278 wr32(hw, TXGBE_VLANCTL, vlanctrl);
280 /* enable all vlan filters */
281 for (i = 0; i < TXGBE_MAX_VFTA; i++)
282 wr32(hw, TXGBE_VLANTBL(i), 0xFFFFFFFF);
284 /* Enable MAC Anti-Spoofing */
285 hw->mac.set_mac_anti_spoofing(hw, FALSE, vf_num);
287 /* set flow control threshold to max to avoid tx switch hang */
288 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
289 wr32(hw, TXGBE_FCWTRLO(i), 0);
290 fcrth = rd32(hw, TXGBE_PBRXSIZE(i)) - 32;
291 wr32(hw, TXGBE_FCWTRHI(i), fcrth);
294 txgbe_add_tx_flow_control_drop_filter(eth_dev);
300 txgbe_set_rx_mode(struct rte_eth_dev *eth_dev)
302 struct rte_eth_dev_data *dev_data = eth_dev->data;
303 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
305 uint16_t vfn = dev_num_vf(eth_dev);
307 /* disable store-bad-packets */
308 wr32m(hw, TXGBE_SECRXCTL, TXGBE_SECRXCTL_SAVEBAD, 0);
310 /* Check for Promiscuous and All Multicast modes */
311 fctrl = rd32m(hw, TXGBE_PSRCTL,
312 ~(TXGBE_PSRCTL_UCP | TXGBE_PSRCTL_MCP));
313 fctrl |= TXGBE_PSRCTL_BCA |
314 TXGBE_PSRCTL_MCHFENA;
316 vmolr = rd32m(hw, TXGBE_POOLETHCTL(vfn),
317 ~(TXGBE_POOLETHCTL_UCP |
318 TXGBE_POOLETHCTL_MCP |
319 TXGBE_POOLETHCTL_UCHA |
320 TXGBE_POOLETHCTL_MCHA));
321 vmolr |= TXGBE_POOLETHCTL_BCA |
322 TXGBE_POOLETHCTL_UTA |
323 TXGBE_POOLETHCTL_VLA;
325 if (dev_data->promiscuous) {
326 fctrl |= TXGBE_PSRCTL_UCP |
328 /* pf don't want packets routing to vf, so clear UPE */
329 vmolr |= TXGBE_POOLETHCTL_MCP;
330 } else if (dev_data->all_multicast) {
331 fctrl |= TXGBE_PSRCTL_MCP;
332 vmolr |= TXGBE_POOLETHCTL_MCP;
334 vmolr |= TXGBE_POOLETHCTL_UCHA;
335 vmolr |= TXGBE_POOLETHCTL_MCHA;
338 wr32(hw, TXGBE_POOLETHCTL(vfn), vmolr);
340 wr32(hw, TXGBE_PSRCTL, fctrl);
342 txgbe_vlan_hw_strip_config(eth_dev);
346 txgbe_vf_reset_event(struct rte_eth_dev *eth_dev, uint16_t vf)
348 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
349 struct txgbe_vf_info *vfinfo = *(TXGBE_DEV_VFDATA(eth_dev));
350 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
351 uint32_t vmolr = rd32(hw, TXGBE_POOLETHCTL(vf));
353 vmolr |= (TXGBE_POOLETHCTL_UCHA |
354 TXGBE_POOLETHCTL_BCA | TXGBE_POOLETHCTL_UTA);
355 wr32(hw, TXGBE_POOLETHCTL(vf), vmolr);
357 wr32(hw, TXGBE_POOLTAG(vf), 0);
359 /* reset multicast table array for vf */
360 vfinfo[vf].num_vf_mc_hashes = 0;
363 txgbe_set_rx_mode(eth_dev);
365 hw->mac.clear_rar(hw, rar_entry);
369 txgbe_vf_reset_msg(struct rte_eth_dev *eth_dev, uint16_t vf)
371 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
373 uint32_t reg_offset, vf_shift;
374 const uint8_t VFRE_SHIFT = 5; /* VFRE 32 bits per slot */
375 const uint8_t VFRE_MASK = (uint8_t)((1U << VFRE_SHIFT) - 1);
376 uint8_t nb_q_per_pool;
379 vf_shift = vf & VFRE_MASK;
380 reg_offset = (vf >> VFRE_SHIFT) > 0 ? 1 : 0;
382 /* enable transmit for vf */
383 reg = rd32(hw, TXGBE_POOLTXENA(reg_offset));
384 reg |= (reg | (1 << vf_shift));
385 wr32(hw, TXGBE_POOLTXENA(reg_offset), reg);
387 /* enable all queue drop for IOV */
388 nb_q_per_pool = RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool;
389 for (i = vf * nb_q_per_pool; i < (vf + 1) * nb_q_per_pool; i++) {
392 wr32m(hw, TXGBE_QPRXDROP(i / 32), reg, reg);
395 /* enable receive for vf */
396 reg = rd32(hw, TXGBE_POOLRXENA(reg_offset));
397 reg |= (reg | (1 << vf_shift));
398 wr32(hw, TXGBE_POOLRXENA(reg_offset), reg);
400 txgbe_vf_reset_event(eth_dev, vf);
404 txgbe_disable_vf_mc_promisc(struct rte_eth_dev *eth_dev, uint32_t vf)
406 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
409 vmolr = rd32(hw, TXGBE_POOLETHCTL(vf));
411 PMD_DRV_LOG(INFO, "VF %u: disabling multicast promiscuous\n", vf);
413 vmolr &= ~TXGBE_POOLETHCTL_MCP;
415 wr32(hw, TXGBE_POOLETHCTL(vf), vmolr);
421 txgbe_vf_reset(struct rte_eth_dev *eth_dev, uint16_t vf, uint32_t *msgbuf)
423 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
424 struct txgbe_vf_info *vfinfo = *(TXGBE_DEV_VFDATA(eth_dev));
425 unsigned char *vf_mac = vfinfo[vf].vf_mac_addresses;
426 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
427 uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
429 txgbe_vf_reset_msg(eth_dev, vf);
431 hw->mac.set_rar(hw, rar_entry, vf_mac, vf, true);
433 /* Disable multicast promiscuous at reset */
434 txgbe_disable_vf_mc_promisc(eth_dev, vf);
436 /* reply to reset with ack and vf mac address */
437 msgbuf[0] = TXGBE_VF_RESET | TXGBE_VT_MSGTYPE_ACK;
438 rte_memcpy(new_mac, vf_mac, RTE_ETHER_ADDR_LEN);
440 * Piggyback the multicast filter type so VF can compute the
443 msgbuf[3] = hw->mac.mc_filter_type;
444 txgbe_write_mbx(hw, msgbuf, TXGBE_VF_PERMADDR_MSG_LEN, vf);
450 txgbe_vf_set_mac_addr(struct rte_eth_dev *eth_dev,
451 uint32_t vf, uint32_t *msgbuf)
453 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
454 struct txgbe_vf_info *vfinfo = *(TXGBE_DEV_VFDATA(eth_dev));
455 int rar_entry = hw->mac.num_rar_entries - (vf + 1);
456 uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
457 struct rte_ether_addr *ea = (struct rte_ether_addr *)new_mac;
459 if (rte_is_valid_assigned_ether_addr(ea)) {
460 rte_memcpy(vfinfo[vf].vf_mac_addresses, new_mac, 6);
461 return hw->mac.set_rar(hw, rar_entry, new_mac, vf, true);
467 txgbe_vf_set_multicast(struct rte_eth_dev *eth_dev,
468 uint32_t vf, uint32_t *msgbuf)
470 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
471 struct txgbe_vf_info *vfinfo = *(TXGBE_DEV_VFDATA(eth_dev));
472 int nb_entries = (msgbuf[0] & TXGBE_VT_MSGINFO_MASK) >>
473 TXGBE_VT_MSGINFO_SHIFT;
474 uint16_t *hash_list = (uint16_t *)&msgbuf[1];
477 const uint32_t TXGBE_MTA_INDEX_MASK = 0x7F;
478 const uint32_t TXGBE_MTA_BIT_SHIFT = 5;
479 const uint32_t TXGBE_MTA_BIT_MASK = (0x1 << TXGBE_MTA_BIT_SHIFT) - 1;
482 u32 vmolr = rd32(hw, TXGBE_POOLETHCTL(vf));
484 /* Disable multicast promiscuous first */
485 txgbe_disable_vf_mc_promisc(eth_dev, vf);
487 /* only so many hash values supported */
488 nb_entries = RTE_MIN(nb_entries, TXGBE_MAX_VF_MC_ENTRIES);
490 /* store the mc entries */
491 vfinfo->num_vf_mc_hashes = (uint16_t)nb_entries;
492 for (i = 0; i < nb_entries; i++)
493 vfinfo->vf_mc_hashes[i] = hash_list[i];
495 if (nb_entries == 0) {
496 vmolr &= ~TXGBE_POOLETHCTL_MCHA;
497 wr32(hw, TXGBE_POOLETHCTL(vf), vmolr);
501 for (i = 0; i < vfinfo->num_vf_mc_hashes; i++) {
502 mta_idx = (vfinfo->vf_mc_hashes[i] >> TXGBE_MTA_BIT_SHIFT)
503 & TXGBE_MTA_INDEX_MASK;
504 mta_shift = vfinfo->vf_mc_hashes[i] & TXGBE_MTA_BIT_MASK;
505 reg_val = rd32(hw, TXGBE_MCADDRTBL(mta_idx));
506 reg_val |= (1 << mta_shift);
507 wr32(hw, TXGBE_MCADDRTBL(mta_idx), reg_val);
510 vmolr |= TXGBE_POOLETHCTL_MCHA;
511 wr32(hw, TXGBE_POOLETHCTL(vf), vmolr);
517 txgbe_vf_set_vlan(struct rte_eth_dev *eth_dev, uint32_t vf, uint32_t *msgbuf)
520 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
521 struct txgbe_vf_info *vfinfo = *(TXGBE_DEV_VFDATA(eth_dev));
523 add = (msgbuf[0] & TXGBE_VT_MSGINFO_MASK)
524 >> TXGBE_VT_MSGINFO_SHIFT;
525 vid = TXGBE_PSRVLAN_VID(msgbuf[1]);
528 vfinfo[vf].vlan_count++;
529 else if (vfinfo[vf].vlan_count)
530 vfinfo[vf].vlan_count--;
531 return hw->mac.set_vfta(hw, vid, vf, (bool)add, false);
535 txgbe_set_vf_lpe(struct rte_eth_dev *eth_dev,
536 __rte_unused uint32_t vf, uint32_t *msgbuf)
538 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
539 uint32_t max_frame = msgbuf[1];
542 if (max_frame < RTE_ETHER_MIN_LEN ||
543 max_frame > RTE_ETHER_MAX_JUMBO_FRAME_LEN)
546 max_frs = rd32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK);
547 if (max_frs < max_frame) {
548 wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
549 TXGBE_FRMSZ_MAX(max_frame));
556 txgbe_negotiate_vf_api(struct rte_eth_dev *eth_dev,
557 uint32_t vf, uint32_t *msgbuf)
559 uint32_t api_version = msgbuf[1];
560 struct txgbe_vf_info *vfinfo = *TXGBE_DEV_VFDATA(eth_dev);
562 switch (api_version) {
563 case txgbe_mbox_api_10:
564 case txgbe_mbox_api_11:
565 case txgbe_mbox_api_12:
566 case txgbe_mbox_api_13:
567 vfinfo[vf].api_version = (uint8_t)api_version;
573 PMD_DRV_LOG(ERR, "Negotiate invalid api version %u from VF %d\n",
580 txgbe_get_vf_queues(struct rte_eth_dev *eth_dev, uint32_t vf, uint32_t *msgbuf)
582 struct txgbe_vf_info *vfinfo = *TXGBE_DEV_VFDATA(eth_dev);
583 uint32_t default_q = vf * RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool;
584 struct rte_eth_conf *eth_conf;
585 struct rte_eth_vmdq_dcb_tx_conf *vmdq_dcb_tx_conf;
593 /* Verify if the PF supports the mbox APIs version or not */
594 switch (vfinfo[vf].api_version) {
595 case txgbe_mbox_api_20:
596 case txgbe_mbox_api_11:
597 case txgbe_mbox_api_12:
598 case txgbe_mbox_api_13:
604 /* Notify VF of Rx and Tx queue number */
605 msgbuf[TXGBE_VF_RX_QUEUES] = RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool;
606 msgbuf[TXGBE_VF_TX_QUEUES] = RTE_ETH_DEV_SRIOV(eth_dev).nb_q_per_pool;
608 /* Notify VF of default queue */
609 msgbuf[TXGBE_VF_DEF_QUEUE] = default_q;
611 /* Notify VF of number of DCB traffic classes */
612 eth_conf = ð_dev->data->dev_conf;
613 switch (eth_conf->txmode.mq_mode) {
616 PMD_DRV_LOG(ERR, "PF must work with virtualization for VF %u"
617 ", but its tx mode = %d\n", vf,
618 eth_conf->txmode.mq_mode);
621 case ETH_MQ_TX_VMDQ_DCB:
622 vmdq_dcb_tx_conf = ð_conf->tx_adv_conf.vmdq_dcb_tx_conf;
623 switch (vmdq_dcb_tx_conf->nb_queue_pools) {
635 /* ETH_MQ_TX_VMDQ_ONLY, DCB not enabled */
636 case ETH_MQ_TX_VMDQ_ONLY:
637 hw = TXGBE_DEV_HW(eth_dev);
638 vmvir = rd32(hw, TXGBE_POOLTAG(vf));
639 vlana = vmvir & TXGBE_POOLTAG_ACT_MASK;
640 vid = vmvir & TXGBE_POOLTAG_VTAG_MASK;
642 TXGBD_POOLTAG_VTAG_UP(vmvir);
643 if (vlana == TXGBE_POOLTAG_ACT_ALWAYS &&
644 (vid != 0 || user_priority != 0))
651 PMD_DRV_LOG(ERR, "PF work with invalid mode = %d\n",
652 eth_conf->txmode.mq_mode);
655 msgbuf[TXGBE_VF_TRANS_VLAN] = num_tcs;
661 txgbe_set_vf_mc_promisc(struct rte_eth_dev *eth_dev,
662 uint32_t vf, uint32_t *msgbuf)
664 struct txgbe_vf_info *vfinfo = *(TXGBE_DEV_VFDATA(eth_dev));
665 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
666 int xcast_mode = msgbuf[1]; /* msgbuf contains the flag to enable */
667 u32 vmolr, fctrl, disable, enable;
669 switch (vfinfo[vf].api_version) {
670 case txgbe_mbox_api_12:
671 /* promisc introduced in 1.3 version */
672 if (xcast_mode == TXGBEVF_XCAST_MODE_PROMISC)
676 case txgbe_mbox_api_13:
682 if (vfinfo[vf].xcast_mode == xcast_mode)
685 switch (xcast_mode) {
686 case TXGBEVF_XCAST_MODE_NONE:
687 disable = TXGBE_POOLETHCTL_BCA | TXGBE_POOLETHCTL_MCHA |
688 TXGBE_POOLETHCTL_MCP | TXGBE_POOLETHCTL_UCP |
689 TXGBE_POOLETHCTL_VLP;
692 case TXGBEVF_XCAST_MODE_MULTI:
693 disable = TXGBE_POOLETHCTL_MCP | TXGBE_POOLETHCTL_UCP |
694 TXGBE_POOLETHCTL_VLP;
695 enable = TXGBE_POOLETHCTL_BCA | TXGBE_POOLETHCTL_MCHA;
697 case TXGBEVF_XCAST_MODE_ALLMULTI:
698 disable = TXGBE_POOLETHCTL_UCP | TXGBE_POOLETHCTL_VLP;
699 enable = TXGBE_POOLETHCTL_BCA | TXGBE_POOLETHCTL_MCHA |
700 TXGBE_POOLETHCTL_MCP;
702 case TXGBEVF_XCAST_MODE_PROMISC:
703 fctrl = rd32(hw, TXGBE_PSRCTL);
704 if (!(fctrl & TXGBE_PSRCTL_UCP)) {
705 /* VF promisc requires PF in promisc */
707 "Enabling VF promisc requires PF in promisc\n");
712 enable = TXGBE_POOLETHCTL_BCA | TXGBE_POOLETHCTL_MCHA |
713 TXGBE_POOLETHCTL_MCP | TXGBE_POOLETHCTL_UCP |
714 TXGBE_POOLETHCTL_VLP;
720 vmolr = rd32(hw, TXGBE_POOLETHCTL(vf));
723 wr32(hw, TXGBE_POOLETHCTL(vf), vmolr);
724 vfinfo[vf].xcast_mode = xcast_mode;
727 msgbuf[1] = xcast_mode;
733 txgbe_set_vf_macvlan_msg(struct rte_eth_dev *dev, uint32_t vf, uint32_t *msgbuf)
735 struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
736 struct txgbe_vf_info *vf_info = *(TXGBE_DEV_VFDATA(dev));
737 uint8_t *new_mac = (uint8_t *)(&msgbuf[1]);
738 struct rte_ether_addr *ea = (struct rte_ether_addr *)new_mac;
739 int index = (msgbuf[0] & TXGBE_VT_MSGINFO_MASK) >>
740 TXGBE_VT_MSGINFO_SHIFT;
743 if (!rte_is_valid_assigned_ether_addr(ea)) {
744 PMD_DRV_LOG(ERR, "set invalid mac vf:%d\n", vf);
748 vf_info[vf].mac_count++;
750 hw->mac.set_rar(hw, vf_info[vf].mac_count,
753 if (vf_info[vf].mac_count) {
754 hw->mac.clear_rar(hw, vf_info[vf].mac_count);
755 vf_info[vf].mac_count = 0;
762 txgbe_rcv_msg_from_vf(struct rte_eth_dev *eth_dev, uint16_t vf)
764 uint16_t mbx_size = TXGBE_P2VMBX_SIZE;
765 uint16_t msg_size = TXGBE_VF_MSG_SIZE_DEFAULT;
766 uint32_t msgbuf[TXGBE_P2VMBX_SIZE];
768 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
769 struct txgbe_vf_info *vfinfo = *TXGBE_DEV_VFDATA(eth_dev);
770 struct rte_pmd_txgbe_mb_event_param ret_param;
772 retval = txgbe_read_mbx(hw, msgbuf, mbx_size, vf);
774 PMD_DRV_LOG(ERR, "Error mbx recv msg from VF %d", vf);
778 /* do nothing with the message already been processed */
779 if (msgbuf[0] & (TXGBE_VT_MSGTYPE_ACK | TXGBE_VT_MSGTYPE_NACK))
782 /* flush the ack before we write any messages back */
786 * initialise structure to send to user application
787 * will return response from user in retval field
789 ret_param.retval = RTE_PMD_TXGBE_MB_EVENT_PROCEED;
791 ret_param.msg_type = msgbuf[0] & 0xFFFF;
792 ret_param.msg = (void *)msgbuf;
794 /* perform VF reset */
795 if (msgbuf[0] == TXGBE_VF_RESET) {
796 int ret = txgbe_vf_reset(eth_dev, vf, msgbuf);
798 vfinfo[vf].clear_to_send = true;
800 /* notify application about VF reset */
801 rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_VF_MBOX,
807 * ask user application if we allowed to perform those functions
808 * if we get ret_param.retval == RTE_PMD_TXGBE_MB_EVENT_PROCEED
809 * then business as usual,
810 * if 0, do nothing and send ACK to VF
811 * if ret_param.retval > 1, do nothing and send NAK to VF
813 rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_VF_MBOX,
816 retval = ret_param.retval;
818 /* check & process VF to PF mailbox message */
819 switch ((msgbuf[0] & 0xFFFF)) {
820 case TXGBE_VF_SET_MAC_ADDR:
821 if (retval == RTE_PMD_TXGBE_MB_EVENT_PROCEED)
822 retval = txgbe_vf_set_mac_addr(eth_dev, vf, msgbuf);
824 case TXGBE_VF_SET_MULTICAST:
825 if (retval == RTE_PMD_TXGBE_MB_EVENT_PROCEED)
826 retval = txgbe_vf_set_multicast(eth_dev, vf, msgbuf);
828 case TXGBE_VF_SET_LPE:
829 if (retval == RTE_PMD_TXGBE_MB_EVENT_PROCEED)
830 retval = txgbe_set_vf_lpe(eth_dev, vf, msgbuf);
832 case TXGBE_VF_SET_VLAN:
833 if (retval == RTE_PMD_TXGBE_MB_EVENT_PROCEED)
834 retval = txgbe_vf_set_vlan(eth_dev, vf, msgbuf);
836 case TXGBE_VF_API_NEGOTIATE:
837 retval = txgbe_negotiate_vf_api(eth_dev, vf, msgbuf);
839 case TXGBE_VF_GET_QUEUES:
840 retval = txgbe_get_vf_queues(eth_dev, vf, msgbuf);
841 msg_size = TXGBE_VF_GET_QUEUE_MSG_SIZE;
843 case TXGBE_VF_UPDATE_XCAST_MODE:
844 if (retval == RTE_PMD_TXGBE_MB_EVENT_PROCEED)
845 retval = txgbe_set_vf_mc_promisc(eth_dev, vf, msgbuf);
847 case TXGBE_VF_SET_MACVLAN:
848 if (retval == RTE_PMD_TXGBE_MB_EVENT_PROCEED)
849 retval = txgbe_set_vf_macvlan_msg(eth_dev, vf, msgbuf);
852 PMD_DRV_LOG(DEBUG, "Unhandled Msg %8.8x", (uint32_t)msgbuf[0]);
853 retval = TXGBE_ERR_MBX;
857 /* response the VF according to the message process result */
859 msgbuf[0] |= TXGBE_VT_MSGTYPE_NACK;
861 msgbuf[0] |= TXGBE_VT_MSGTYPE_ACK;
863 msgbuf[0] |= TXGBE_VT_MSGTYPE_CTS;
865 txgbe_write_mbx(hw, msgbuf, msg_size, vf);
871 txgbe_rcv_ack_from_vf(struct rte_eth_dev *eth_dev, uint16_t vf)
873 uint32_t msg = TXGBE_VT_MSGTYPE_NACK;
874 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
875 struct txgbe_vf_info *vfinfo = *TXGBE_DEV_VFDATA(eth_dev);
877 if (!vfinfo[vf].clear_to_send)
878 txgbe_write_mbx(hw, &msg, 1, vf);
881 void txgbe_pf_mbx_process(struct rte_eth_dev *eth_dev)
884 struct txgbe_hw *hw = TXGBE_DEV_HW(eth_dev);
886 for (vf = 0; vf < dev_num_vf(eth_dev); vf++) {
887 /* check & process vf function level reset */
888 if (!txgbe_check_for_rst(hw, vf))
889 txgbe_vf_reset_event(eth_dev, vf);
891 /* check & process vf mailbox messages */
892 if (!txgbe_check_for_msg(hw, vf))
893 txgbe_rcv_msg_from_vf(eth_dev, vf);
895 /* check & process acks from vf */
896 if (!txgbe_check_for_ack(hw, vf))
897 txgbe_rcv_ack_from_vf(eth_dev, vf);