1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2017 Intel Corporation
5 #include <rte_ethdev_driver.h>
7 #include "base/ixgbe_api.h"
8 #include "base/ixgbe_x550.h"
9 #include "ixgbe_ethdev.h"
10 #include "rte_pmd_ixgbe.h"
13 rte_pmd_ixgbe_set_vf_mac_addr(uint16_t port, uint16_t vf,
14 struct rte_ether_addr *mac_addr)
17 struct ixgbe_vf_info *vfinfo;
19 uint8_t *new_mac = (uint8_t *)(mac_addr);
20 struct rte_eth_dev *dev;
21 struct rte_pci_device *pci_dev;
23 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
25 dev = &rte_eth_devices[port];
26 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
28 if (!is_ixgbe_supported(dev))
31 if (vf >= pci_dev->max_vfs)
34 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
35 vfinfo = *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
36 rar_entry = hw->mac.num_rar_entries - (vf + 1);
38 if (rte_is_valid_assigned_ether_addr(
39 (struct rte_ether_addr *)new_mac)) {
40 rte_memcpy(vfinfo[vf].vf_mac_addresses, new_mac,
42 return hw->mac.ops.set_rar(hw, rar_entry, new_mac, vf,
49 rte_pmd_ixgbe_ping_vf(uint16_t port, uint16_t vf)
52 struct ixgbe_vf_info *vfinfo;
53 struct rte_eth_dev *dev;
54 struct rte_pci_device *pci_dev;
57 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
59 dev = &rte_eth_devices[port];
60 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
62 if (!is_ixgbe_supported(dev))
65 if (vf >= pci_dev->max_vfs)
68 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
69 vfinfo = *(IXGBE_DEV_PRIVATE_TO_P_VFDATA(dev->data->dev_private));
71 ctrl = IXGBE_PF_CONTROL_MSG;
72 if (vfinfo[vf].clear_to_send)
73 ctrl |= IXGBE_VT_MSGTYPE_CTS;
75 ixgbe_write_mbx(hw, &ctrl, 1, vf);
81 rte_pmd_ixgbe_set_vf_vlan_anti_spoof(uint16_t port, uint16_t vf, uint8_t on)
84 struct ixgbe_mac_info *mac;
85 struct rte_eth_dev *dev;
86 struct rte_pci_device *pci_dev;
88 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
90 dev = &rte_eth_devices[port];
91 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
93 if (!is_ixgbe_supported(dev))
96 if (vf >= pci_dev->max_vfs)
102 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
105 mac->ops.set_vlan_anti_spoofing(hw, on, vf);
111 rte_pmd_ixgbe_set_vf_mac_anti_spoof(uint16_t port, uint16_t vf, uint8_t on)
114 struct ixgbe_mac_info *mac;
115 struct rte_eth_dev *dev;
116 struct rte_pci_device *pci_dev;
118 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
120 dev = &rte_eth_devices[port];
121 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
123 if (!is_ixgbe_supported(dev))
126 if (vf >= pci_dev->max_vfs)
132 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
134 mac->ops.set_mac_anti_spoofing(hw, on, vf);
140 rte_pmd_ixgbe_set_vf_vlan_insert(uint16_t port, uint16_t vf, uint16_t vlan_id)
144 struct rte_eth_dev *dev;
145 struct rte_pci_device *pci_dev;
147 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
149 dev = &rte_eth_devices[port];
150 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
152 if (!is_ixgbe_supported(dev))
155 if (vf >= pci_dev->max_vfs)
158 if (vlan_id > RTE_ETHER_MAX_VLAN_ID)
161 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
162 ctrl = IXGBE_READ_REG(hw, IXGBE_VMVIR(vf));
165 ctrl |= IXGBE_VMVIR_VLANA_DEFAULT;
170 IXGBE_WRITE_REG(hw, IXGBE_VMVIR(vf), ctrl);
176 rte_pmd_ixgbe_set_tx_loopback(uint16_t port, uint8_t on)
180 struct rte_eth_dev *dev;
182 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
184 dev = &rte_eth_devices[port];
186 if (!is_ixgbe_supported(dev))
192 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
193 ctrl = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
194 /* enable or disable VMDQ loopback */
196 ctrl |= IXGBE_PFDTXGSWC_VT_LBEN;
198 ctrl &= ~IXGBE_PFDTXGSWC_VT_LBEN;
200 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, ctrl);
206 rte_pmd_ixgbe_set_all_queues_drop_en(uint16_t port, uint8_t on)
211 int num_queues = (int)(IXGBE_QDE_IDX_MASK >> IXGBE_QDE_IDX_SHIFT);
212 struct rte_eth_dev *dev;
214 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
216 dev = &rte_eth_devices[port];
218 if (!is_ixgbe_supported(dev))
224 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
225 for (i = 0; i <= num_queues; i++) {
226 reg_value = IXGBE_QDE_WRITE |
227 (i << IXGBE_QDE_IDX_SHIFT) |
228 (on & IXGBE_QDE_ENABLE);
229 IXGBE_WRITE_REG(hw, IXGBE_QDE, reg_value);
236 rte_pmd_ixgbe_set_vf_split_drop_en(uint16_t port, uint16_t vf, uint8_t on)
240 struct rte_eth_dev *dev;
241 struct rte_pci_device *pci_dev;
243 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
245 dev = &rte_eth_devices[port];
246 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
248 if (!is_ixgbe_supported(dev))
251 /* only support VF's 0 to 63 */
252 if ((vf >= pci_dev->max_vfs) || (vf > 63))
258 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
259 reg_value = IXGBE_READ_REG(hw, IXGBE_SRRCTL(vf));
261 reg_value |= IXGBE_SRRCTL_DROP_EN;
263 reg_value &= ~IXGBE_SRRCTL_DROP_EN;
265 IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(vf), reg_value);
271 rte_pmd_ixgbe_set_vf_vlan_stripq(uint16_t port, uint16_t vf, uint8_t on)
273 struct rte_eth_dev *dev;
274 struct rte_pci_device *pci_dev;
276 uint16_t queues_per_pool;
279 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
281 dev = &rte_eth_devices[port];
282 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
283 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
285 if (!is_ixgbe_supported(dev))
288 if (vf >= pci_dev->max_vfs)
294 RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP);
296 /* The PF has 128 queue pairs and in SRIOV configuration
297 * those queues will be assigned to VF's, so RXDCTL
298 * registers will be dealing with queues which will be
300 * Let's say we have SRIOV configured with 31 VF's then the
301 * first 124 queues 0-123 will be allocated to VF's and only
302 * the last 4 queues 123-127 will be assigned to the PF.
304 if (hw->mac.type == ixgbe_mac_82598EB)
305 queues_per_pool = (uint16_t)hw->mac.max_rx_queues /
308 queues_per_pool = (uint16_t)hw->mac.max_rx_queues /
311 for (q = 0; q < queues_per_pool; q++)
312 (*dev->dev_ops->vlan_strip_queue_set)(dev,
313 q + vf * queues_per_pool, on);
318 rte_pmd_ixgbe_set_vf_rxmode(uint16_t port, uint16_t vf,
319 uint16_t rx_mask, uint8_t on)
322 struct rte_eth_dev *dev;
323 struct rte_pci_device *pci_dev;
327 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
329 dev = &rte_eth_devices[port];
330 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
332 if (!is_ixgbe_supported(dev))
335 if (vf >= pci_dev->max_vfs)
341 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
342 vmolr = IXGBE_READ_REG(hw, IXGBE_VMOLR(vf));
344 if (hw->mac.type == ixgbe_mac_82598EB) {
345 PMD_INIT_LOG(ERR, "setting VF receive mode set should be done"
346 " on 82599 hardware and newer");
349 if (ixgbe_vt_check(hw) < 0)
352 val = ixgbe_convert_vm_rx_mask_to_val(rx_mask, val);
359 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(vf), vmolr);
365 rte_pmd_ixgbe_set_vf_rx(uint16_t port, uint16_t vf, uint8_t on)
367 struct rte_eth_dev *dev;
368 struct rte_pci_device *pci_dev;
371 const uint8_t bit1 = 0x1;
374 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
376 dev = &rte_eth_devices[port];
377 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
379 if (!is_ixgbe_supported(dev))
382 if (vf >= pci_dev->max_vfs)
388 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
390 if (ixgbe_vt_check(hw) < 0)
393 /* for vf >= 32, set bit in PFVFRE[1], otherwise PFVFRE[0] */
395 addr = IXGBE_VFRE(1);
396 val = bit1 << (vf - 32);
398 addr = IXGBE_VFRE(0);
402 reg = IXGBE_READ_REG(hw, addr);
409 IXGBE_WRITE_REG(hw, addr, reg);
415 rte_pmd_ixgbe_set_vf_tx(uint16_t port, uint16_t vf, uint8_t on)
417 struct rte_eth_dev *dev;
418 struct rte_pci_device *pci_dev;
421 const uint8_t bit1 = 0x1;
425 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
427 dev = &rte_eth_devices[port];
428 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
430 if (!is_ixgbe_supported(dev))
433 if (vf >= pci_dev->max_vfs)
439 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
440 if (ixgbe_vt_check(hw) < 0)
443 /* for vf >= 32, set bit in PFVFTE[1], otherwise PFVFTE[0] */
445 addr = IXGBE_VFTE(1);
446 val = bit1 << (vf - 32);
448 addr = IXGBE_VFTE(0);
452 reg = IXGBE_READ_REG(hw, addr);
459 IXGBE_WRITE_REG(hw, addr, reg);
465 rte_pmd_ixgbe_set_vf_vlan_filter(uint16_t port, uint16_t vlan,
466 uint64_t vf_mask, uint8_t vlan_on)
468 struct rte_eth_dev *dev;
473 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
475 dev = &rte_eth_devices[port];
477 if (!is_ixgbe_supported(dev))
480 if (vlan > RTE_ETHER_MAX_VLAN_ID || vf_mask == 0)
483 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
484 if (ixgbe_vt_check(hw) < 0)
487 for (vf_idx = 0; vf_idx < 64; vf_idx++) {
488 if (vf_mask & ((uint64_t)(1ULL << vf_idx))) {
489 ret = hw->mac.ops.set_vfta(hw, vlan, vf_idx,
500 rte_pmd_ixgbe_set_vf_rate_limit(uint16_t port, uint16_t vf,
501 uint16_t tx_rate, uint64_t q_msk)
503 struct rte_eth_dev *dev;
505 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
507 dev = &rte_eth_devices[port];
509 if (!is_ixgbe_supported(dev))
512 return ixgbe_set_vf_rate_limit(dev, vf, tx_rate, q_msk);
516 rte_pmd_ixgbe_macsec_enable(uint16_t port, uint8_t en, uint8_t rp)
518 struct rte_eth_dev *dev;
519 struct ixgbe_macsec_setting macsec_setting;
521 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
523 dev = &rte_eth_devices[port];
525 macsec_setting.offload_en = 1;
526 macsec_setting.encrypt_en = en;
527 macsec_setting.replayprotect_en = rp;
529 ixgbe_dev_macsec_setting_save(dev, &macsec_setting);
531 ixgbe_dev_macsec_register_enable(dev, &macsec_setting);
537 rte_pmd_ixgbe_macsec_disable(uint16_t port)
539 struct rte_eth_dev *dev;
541 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
543 dev = &rte_eth_devices[port];
545 ixgbe_dev_macsec_setting_reset(dev);
547 ixgbe_dev_macsec_register_disable(dev);
553 rte_pmd_ixgbe_macsec_config_txsc(uint16_t port, uint8_t *mac)
556 struct rte_eth_dev *dev;
559 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
561 dev = &rte_eth_devices[port];
563 if (!is_ixgbe_supported(dev))
566 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
568 ctrl = mac[0] | (mac[1] << 8) | (mac[2] << 16) | (mac[3] << 24);
569 IXGBE_WRITE_REG(hw, IXGBE_LSECTXSCL, ctrl);
571 ctrl = mac[4] | (mac[5] << 8);
572 IXGBE_WRITE_REG(hw, IXGBE_LSECTXSCH, ctrl);
578 rte_pmd_ixgbe_macsec_config_rxsc(uint16_t port, uint8_t *mac, uint16_t pi)
581 struct rte_eth_dev *dev;
584 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
586 dev = &rte_eth_devices[port];
588 if (!is_ixgbe_supported(dev))
591 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
593 ctrl = mac[0] | (mac[1] << 8) | (mac[2] << 16) | (mac[3] << 24);
594 IXGBE_WRITE_REG(hw, IXGBE_LSECRXSCL, ctrl);
596 pi = rte_cpu_to_be_16(pi);
597 ctrl = mac[4] | (mac[5] << 8) | (pi << 16);
598 IXGBE_WRITE_REG(hw, IXGBE_LSECRXSCH, ctrl);
604 rte_pmd_ixgbe_macsec_select_txsa(uint16_t port, uint8_t idx, uint8_t an,
605 uint32_t pn, uint8_t *key)
608 struct rte_eth_dev *dev;
611 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
613 dev = &rte_eth_devices[port];
615 if (!is_ixgbe_supported(dev))
618 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
620 if (idx != 0 && idx != 1)
626 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
628 /* Set the PN and key */
629 pn = rte_cpu_to_be_32(pn);
631 IXGBE_WRITE_REG(hw, IXGBE_LSECTXPN0, pn);
633 for (i = 0; i < 4; i++) {
634 ctrl = (key[i * 4 + 0] << 0) |
635 (key[i * 4 + 1] << 8) |
636 (key[i * 4 + 2] << 16) |
637 (key[i * 4 + 3] << 24);
638 IXGBE_WRITE_REG(hw, IXGBE_LSECTXKEY0(i), ctrl);
641 IXGBE_WRITE_REG(hw, IXGBE_LSECTXPN1, pn);
643 for (i = 0; i < 4; i++) {
644 ctrl = (key[i * 4 + 0] << 0) |
645 (key[i * 4 + 1] << 8) |
646 (key[i * 4 + 2] << 16) |
647 (key[i * 4 + 3] << 24);
648 IXGBE_WRITE_REG(hw, IXGBE_LSECTXKEY1(i), ctrl);
652 /* Set AN and select the SA */
653 ctrl = (an << idx * 2) | (idx << 4);
654 IXGBE_WRITE_REG(hw, IXGBE_LSECTXSA, ctrl);
660 rte_pmd_ixgbe_macsec_select_rxsa(uint16_t port, uint8_t idx, uint8_t an,
661 uint32_t pn, uint8_t *key)
664 struct rte_eth_dev *dev;
667 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
669 dev = &rte_eth_devices[port];
671 if (!is_ixgbe_supported(dev))
674 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
676 if (idx != 0 && idx != 1)
683 pn = rte_cpu_to_be_32(pn);
684 IXGBE_WRITE_REG(hw, IXGBE_LSECRXPN(idx), pn);
687 for (i = 0; i < 4; i++) {
688 ctrl = (key[i * 4 + 0] << 0) |
689 (key[i * 4 + 1] << 8) |
690 (key[i * 4 + 2] << 16) |
691 (key[i * 4 + 3] << 24);
692 IXGBE_WRITE_REG(hw, IXGBE_LSECRXKEY(idx, i), ctrl);
695 /* Set the AN and validate the SA */
696 ctrl = an | (1 << 2);
697 IXGBE_WRITE_REG(hw, IXGBE_LSECRXSA(idx), ctrl);
703 rte_pmd_ixgbe_set_tc_bw_alloc(uint16_t port,
707 struct rte_eth_dev *dev;
708 struct ixgbe_dcb_config *dcb_config;
709 struct ixgbe_dcb_tc_config *tc;
710 struct rte_eth_conf *eth_conf;
711 struct ixgbe_bw_conf *bw_conf;
716 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
718 dev = &rte_eth_devices[port];
720 if (!is_ixgbe_supported(dev))
723 if (tc_num > IXGBE_DCB_MAX_TRAFFIC_CLASS) {
724 PMD_DRV_LOG(ERR, "TCs should be no more than %d.",
725 IXGBE_DCB_MAX_TRAFFIC_CLASS);
729 dcb_config = IXGBE_DEV_PRIVATE_TO_DCB_CFG(dev->data->dev_private);
730 bw_conf = IXGBE_DEV_PRIVATE_TO_BW_CONF(dev->data->dev_private);
731 eth_conf = &dev->data->dev_conf;
733 if (eth_conf->txmode.mq_mode == ETH_MQ_TX_DCB) {
734 nb_tcs = eth_conf->tx_adv_conf.dcb_tx_conf.nb_tcs;
735 } else if (eth_conf->txmode.mq_mode == ETH_MQ_TX_VMDQ_DCB) {
736 if (eth_conf->tx_adv_conf.vmdq_dcb_tx_conf.nb_queue_pools ==
745 if (nb_tcs != tc_num) {
747 "Weight should be set for all %d enabled TCs.",
753 for (i = 0; i < nb_tcs; i++)
757 "The summary of the TC weight should be 100.");
761 for (i = 0; i < nb_tcs; i++) {
762 tc = &dcb_config->tc_config[i];
763 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = bw_weight[i];
765 for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
766 tc = &dcb_config->tc_config[i];
767 tc->path[IXGBE_DCB_TX_CONFIG].bwg_percent = 0;
770 bw_conf->tc_num = nb_tcs;
776 rte_pmd_ixgbe_upd_fctrl_sbp(uint16_t port, int enable)
779 struct rte_eth_dev *dev;
782 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
783 dev = &rte_eth_devices[port];
784 if (!is_ixgbe_supported(dev))
787 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
791 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
793 /* If 'enable' set the SBP bit else clear it */
795 fctrl |= IXGBE_FCTRL_SBP;
797 fctrl &= ~(IXGBE_FCTRL_SBP);
799 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
803 #ifdef RTE_LIBRTE_IXGBE_BYPASS
805 rte_pmd_ixgbe_bypass_init(uint16_t port_id)
807 struct rte_eth_dev *dev;
809 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
811 dev = &rte_eth_devices[port_id];
812 if (!is_ixgbe_supported(dev))
815 ixgbe_bypass_init(dev);
820 rte_pmd_ixgbe_bypass_state_show(uint16_t port_id, uint32_t *state)
822 struct rte_eth_dev *dev;
824 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
826 dev = &rte_eth_devices[port_id];
827 if (!is_ixgbe_supported(dev))
830 return ixgbe_bypass_state_show(dev, state);
834 rte_pmd_ixgbe_bypass_state_set(uint16_t port_id, uint32_t *new_state)
836 struct rte_eth_dev *dev;
838 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
840 dev = &rte_eth_devices[port_id];
841 if (!is_ixgbe_supported(dev))
844 return ixgbe_bypass_state_store(dev, new_state);
848 rte_pmd_ixgbe_bypass_event_show(uint16_t port_id,
852 struct rte_eth_dev *dev;
854 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
856 dev = &rte_eth_devices[port_id];
857 if (!is_ixgbe_supported(dev))
860 return ixgbe_bypass_event_show(dev, event, state);
864 rte_pmd_ixgbe_bypass_event_store(uint16_t port_id,
868 struct rte_eth_dev *dev;
870 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
872 dev = &rte_eth_devices[port_id];
873 if (!is_ixgbe_supported(dev))
876 return ixgbe_bypass_event_store(dev, event, state);
880 rte_pmd_ixgbe_bypass_wd_timeout_store(uint16_t port_id, uint32_t timeout)
882 struct rte_eth_dev *dev;
884 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
886 dev = &rte_eth_devices[port_id];
887 if (!is_ixgbe_supported(dev))
890 return ixgbe_bypass_wd_timeout_store(dev, timeout);
894 rte_pmd_ixgbe_bypass_ver_show(uint16_t port_id, uint32_t *ver)
896 struct rte_eth_dev *dev;
898 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
900 dev = &rte_eth_devices[port_id];
901 if (!is_ixgbe_supported(dev))
904 return ixgbe_bypass_ver_show(dev, ver);
908 rte_pmd_ixgbe_bypass_wd_timeout_show(uint16_t port_id, uint32_t *wd_timeout)
910 struct rte_eth_dev *dev;
912 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
914 dev = &rte_eth_devices[port_id];
915 if (!is_ixgbe_supported(dev))
918 return ixgbe_bypass_wd_timeout_show(dev, wd_timeout);
922 rte_pmd_ixgbe_bypass_wd_reset(uint16_t port_id)
924 struct rte_eth_dev *dev;
926 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
928 dev = &rte_eth_devices[port_id];
929 if (!is_ixgbe_supported(dev))
932 return ixgbe_bypass_wd_reset(dev);
937 * rte_pmd_ixgbe_acquire_swfw - Acquire SWFW semaphore
938 * @hw: pointer to hardware structure
939 * @mask: Mask to specify which semaphore to acquire
941 * Acquires the SWFW semaphore and get the shared phy token as needed
943 STATIC s32 rte_pmd_ixgbe_acquire_swfw(struct ixgbe_hw *hw, u32 mask)
945 int retries = FW_PHY_TOKEN_RETRIES;
946 s32 status = IXGBE_SUCCESS;
949 status = ixgbe_acquire_swfw_semaphore(hw, mask);
951 PMD_DRV_LOG(ERR, "Get SWFW sem failed, Status = %d\n",
955 status = ixgbe_get_phy_token(hw);
956 if (status == IXGBE_SUCCESS)
957 return IXGBE_SUCCESS;
959 if (status == IXGBE_ERR_TOKEN_RETRY)
960 PMD_DRV_LOG(ERR, "Get PHY token failed, Status = %d\n",
963 ixgbe_release_swfw_semaphore(hw, mask);
964 if (status != IXGBE_ERR_TOKEN_RETRY) {
966 "Retry get PHY token failed, Status=%d\n",
971 PMD_DRV_LOG(ERR, "swfw acquisition retries failed!: PHY ID = 0x%08X\n",
977 * rte_pmd_ixgbe_release_swfw_sync - Release SWFW semaphore
978 * @hw: pointer to hardware structure
979 * @mask: Mask to specify which semaphore to release
981 * Releases the SWFW semaphore and puts the shared phy token as needed
983 STATIC void rte_pmd_ixgbe_release_swfw(struct ixgbe_hw *hw, u32 mask)
985 ixgbe_put_phy_token(hw);
986 ixgbe_release_swfw_semaphore(hw, mask);
990 rte_pmd_ixgbe_mdio_lock(uint16_t port)
993 struct rte_eth_dev *dev;
996 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
997 dev = &rte_eth_devices[port];
998 if (!is_ixgbe_supported(dev))
1001 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1006 swfw_mask = IXGBE_GSSR_PHY1_SM;
1008 swfw_mask = IXGBE_GSSR_PHY0_SM;
1010 if (rte_pmd_ixgbe_acquire_swfw(hw, swfw_mask))
1011 return IXGBE_ERR_SWFW_SYNC;
1013 return IXGBE_SUCCESS;
1017 rte_pmd_ixgbe_mdio_unlock(uint16_t port)
1019 struct rte_eth_dev *dev;
1020 struct ixgbe_hw *hw;
1023 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1025 dev = &rte_eth_devices[port];
1026 if (!is_ixgbe_supported(dev))
1029 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1034 swfw_mask = IXGBE_GSSR_PHY1_SM;
1036 swfw_mask = IXGBE_GSSR_PHY0_SM;
1038 rte_pmd_ixgbe_release_swfw(hw, swfw_mask);
1040 return IXGBE_SUCCESS;
1044 rte_pmd_ixgbe_mdio_unlocked_read(uint16_t port, uint32_t reg_addr,
1045 uint32_t dev_type, uint16_t *phy_data)
1047 struct ixgbe_hw *hw;
1048 struct rte_eth_dev *dev;
1049 u32 i, data, command;
1051 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1052 dev = &rte_eth_devices[port];
1053 if (!is_ixgbe_supported(dev))
1056 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1060 /* Setup and write the read command */
1061 command = (reg_addr << IXGBE_MSCA_DEV_TYPE_SHIFT) |
1062 (dev_type << IXGBE_MSCA_PHY_ADDR_SHIFT) |
1063 IXGBE_MSCA_OLD_PROTOCOL | IXGBE_MSCA_READ_AUTOINC |
1064 IXGBE_MSCA_MDI_COMMAND;
1066 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
1068 /* Check every 10 usec to see if the access completed.
1069 * The MDI Command bit will clear when the operation is
1072 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
1075 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
1076 if (!(command & IXGBE_MSCA_MDI_COMMAND))
1079 if (command & IXGBE_MSCA_MDI_COMMAND)
1080 return IXGBE_ERR_PHY;
1082 /* Read operation is complete. Get the data from MSRWD */
1083 data = IXGBE_READ_REG(hw, IXGBE_MSRWD);
1084 data >>= IXGBE_MSRWD_READ_DATA_SHIFT;
1085 *phy_data = (u16)data;
1091 rte_pmd_ixgbe_mdio_unlocked_write(uint16_t port, uint32_t reg_addr,
1092 uint32_t dev_type, uint16_t phy_data)
1094 struct ixgbe_hw *hw;
1096 struct rte_eth_dev *dev;
1098 RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
1099 dev = &rte_eth_devices[port];
1100 if (!is_ixgbe_supported(dev))
1103 hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1107 /* Put the data in the MDI single read and write data register*/
1108 IXGBE_WRITE_REG(hw, IXGBE_MSRWD, (u32)phy_data);
1110 /* Setup and write the write command */
1111 command = (reg_addr << IXGBE_MSCA_DEV_TYPE_SHIFT) |
1112 (dev_type << IXGBE_MSCA_PHY_ADDR_SHIFT) |
1113 IXGBE_MSCA_OLD_PROTOCOL | IXGBE_MSCA_WRITE |
1114 IXGBE_MSCA_MDI_COMMAND;
1116 IXGBE_WRITE_REG(hw, IXGBE_MSCA, command);
1118 /* Check every 10 usec to see if the access completed.
1119 * The MDI Command bit will clear when the operation is
1122 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
1125 command = IXGBE_READ_REG(hw, IXGBE_MSCA);
1126 if (!(command & IXGBE_MSCA_MDI_COMMAND))
1129 if (command & IXGBE_MSCA_MDI_COMMAND) {
1130 ERROR_REPORT1(IXGBE_ERROR_POLLING,
1131 "PHY write cmd didn't complete\n");
1132 return IXGBE_ERR_PHY;