* Calculate the path cost according to the link speed. */
| 1691 | * Calculate the path cost according to the link speed. |
| 1692 | */ |
| 1693 | static uint32_t |
| 1694 | bstp_calc_path_cost(struct bstp_port *bp) |
| 1695 | { |
| 1696 | struct ifnet *ifp = bp->bp_ifp; |
| 1697 | uint32_t path_cost; |
| 1698 | |
| 1699 | /* If the priority has been manually set then retain the value */ |
| 1700 | if (bp->bp_flags & BSTP_PORT_ADMCOST) |
| 1701 | return bp->bp_path_cost; |
| 1702 | |
| 1703 | if (ifp->if_link_state == LINK_STATE_DOWN) { |
| 1704 | /* Recalc when the link comes up again */ |
| 1705 | bp->bp_flags |= BSTP_PORT_PNDCOST; |
| 1706 | return (BSTP_DEFAULT_PATH_COST); |
| 1707 | } |
| 1708 | |
| 1709 | if (ifp->if_baudrate < 1000) |
| 1710 | return (BSTP_DEFAULT_PATH_COST); |
| 1711 | |
| 1712 | /* formula from section 17.14, IEEE Std 802.1D-2004 */ |
| 1713 | path_cost = 20000000000ULL / (ifp->if_baudrate / 1000); |
| 1714 | |
| 1715 | if (path_cost > BSTP_MAX_PATH_COST) |
| 1716 | path_cost = BSTP_MAX_PATH_COST; |
| 1717 | |
| 1718 | /* STP compat mode only uses 16 bits of the 32 */ |
| 1719 | if (bp->bp_protover == BSTP_PROTO_STP && path_cost > 65535) |
| 1720 | path_cost = 65535; |
| 1721 | |
| 1722 | return (path_cost); |
| 1723 | } |
| 1724 | |
| 1725 | /* |
| 1726 | * Notify the bridge that a port state has changed, we need to do this from a |
no outgoing calls
no test coverage detected