Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(C) 2021 Marvell. 3 : : */ 4 : : 5 : : #include "cnxk_ethdev.h" 6 : : 7 : : void 8 : 0 : cnxk_nix_toggle_flag_link_cfg(struct cnxk_eth_dev *dev, bool set) 9 : : { 10 [ # # ]: 0 : if (set) 11 : 0 : dev->flags |= CNXK_LINK_CFG_IN_PROGRESS_F; 12 : : else 13 : 0 : dev->flags &= ~CNXK_LINK_CFG_IN_PROGRESS_F; 14 : : 15 : : /* Update link info for LBK */ 16 [ # # # # ]: 0 : if (!set && 17 [ # # # # ]: 0 : (roc_nix_is_lbk(&dev->nix) || roc_nix_is_sdp(&dev->nix) || roc_nix_is_esw(&dev->nix))) { 18 : : struct rte_eth_link link; 19 : : 20 : 0 : link.link_status = RTE_ETH_LINK_UP; 21 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100G; 22 : 0 : link.link_autoneg = RTE_ETH_LINK_FIXED; 23 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX; 24 : 0 : rte_eth_linkstatus_set(dev->eth_dev, &link); 25 : : } 26 : : 27 : : rte_wmb(); 28 : 0 : } 29 : : 30 : : static inline int 31 : 0 : nix_wait_for_link_cfg(struct cnxk_eth_dev *dev) 32 : : { 33 : : uint16_t wait = 1000; 34 : : 35 : : do { 36 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE); 37 [ # # ]: 0 : if (!(dev->flags & CNXK_LINK_CFG_IN_PROGRESS_F)) 38 : : break; 39 : 0 : wait--; 40 : : rte_delay_ms(1); 41 [ # # ]: 0 : } while (wait); 42 : : 43 [ # # ]: 0 : return wait ? 0 : -1; 44 : : } 45 : : 46 : : static void 47 : 0 : nix_link_status_print(struct rte_eth_dev *eth_dev, struct rte_eth_link *link) 48 : : { 49 [ # # # # ]: 0 : if (link && link->link_status) 50 [ # # ]: 0 : plt_info("Port %d: Link Up - speed %u Mbps - %s", 51 : : (int)(eth_dev->data->port_id), 52 : : (uint32_t)link->link_speed, 53 : : link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX 54 : : ? "full-duplex" 55 : : : "half-duplex"); 56 : : else 57 : 0 : plt_info("Port %d: Link Down", (int)(eth_dev->data->port_id)); 58 : 0 : } 59 : : 60 : : void 61 : 0 : cnxk_eth_dev_link_status_get_cb(struct roc_nix *nix, 62 : : struct roc_nix_link_info *link) 63 : : { 64 : : struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix; 65 : : struct rte_eth_link eth_link; 66 : : struct rte_eth_dev *eth_dev; 67 : : 68 [ # # ]: 0 : if (!link || !nix) 69 : 0 : return; 70 : : 71 : 0 : eth_dev = dev->eth_dev; 72 [ # # ]: 0 : if (!eth_dev) 73 : : return; 74 : : 75 : 0 : rte_eth_linkstatus_get(eth_dev, ð_link); 76 : : 77 : 0 : link->status = eth_link.link_status; 78 : 0 : link->speed = eth_link.link_speed; 79 : 0 : link->autoneg = eth_link.link_autoneg; 80 : 0 : link->full_duplex = eth_link.link_duplex; 81 : : } 82 : : 83 : : void 84 : 0 : cnxk_eth_dev_link_status_cb(struct roc_nix *nix, struct roc_nix_link_info *link) 85 : : { 86 : : struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix; 87 : : struct rte_eth_link eth_link; 88 : : struct rte_eth_dev *eth_dev; 89 : : 90 [ # # ]: 0 : if (!link || !nix) 91 : 0 : return; 92 : : 93 : 0 : eth_dev = dev->eth_dev; 94 [ # # # # ]: 0 : if (!eth_dev || !eth_dev->data->dev_conf.intr_conf.lsc) 95 : : return; 96 : : 97 [ # # ]: 0 : if (nix_wait_for_link_cfg(dev)) { 98 : 0 : plt_err("Timeout waiting for link_cfg to complete"); 99 : 0 : return; 100 : : } 101 : : 102 : 0 : eth_link.link_status = link->status; 103 : 0 : eth_link.link_speed = link->speed; 104 : 0 : eth_link.link_autoneg = RTE_ETH_LINK_AUTONEG; 105 : 0 : eth_link.link_duplex = link->full_duplex; 106 : : 107 : : /* Print link info */ 108 : 0 : nix_link_status_print(eth_dev, ð_link); 109 : : 110 : : /* Update link info */ 111 : 0 : rte_eth_linkstatus_set(eth_dev, ð_link); 112 : : 113 : : /* Set the flag and execute application callbacks */ 114 : 0 : rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_LSC, NULL); 115 : : } 116 : : 117 : : int 118 [ # # ]: 0 : cnxk_nix_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete) 119 : : { 120 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev); 121 : : struct roc_nix_link_info info; 122 : : struct rte_eth_link link; 123 : : int rc; 124 : : 125 : : RTE_SET_USED(wait_to_complete); 126 : : memset(&link, 0, sizeof(struct rte_eth_link)); 127 : : 128 [ # # ]: 0 : if (!eth_dev->data->dev_started) 129 : : return 0; 130 : : 131 [ # # # # ]: 0 : if (roc_nix_is_lbk(&dev->nix) || roc_nix_is_sdp(&dev->nix)) { 132 : 0 : link.link_status = RTE_ETH_LINK_UP; 133 : 0 : link.link_speed = RTE_ETH_SPEED_NUM_100G; 134 : : link.link_autoneg = RTE_ETH_LINK_FIXED; 135 : 0 : link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX; 136 : : } else { 137 : 0 : rc = roc_nix_mac_link_info_get(&dev->nix, &info); 138 [ # # ]: 0 : if (rc) 139 : : return rc; 140 : 0 : link.link_status = info.status; 141 : 0 : link.link_speed = info.speed; 142 : 0 : link.link_autoneg = RTE_ETH_LINK_AUTONEG; 143 [ # # ]: 0 : if (info.full_duplex) 144 : 0 : link.link_duplex = info.full_duplex; 145 : : } 146 : : 147 : : return rte_eth_linkstatus_set(eth_dev, &link); 148 : : }