1*249b931fSmbuhl /* $OpenBSD: igc_phy.c,v 1.3 2023/02/03 11:31:52 mbuhl Exp $ */
283306792Spatrick /*-
383306792Spatrick * Copyright 2021 Intel Corp
483306792Spatrick * Copyright 2021 Rubicon Communications, LLC (Netgate)
583306792Spatrick * SPDX-License-Identifier: BSD-3-Clause
683306792Spatrick */
783306792Spatrick
883306792Spatrick #include <dev/pci/igc_api.h>
983306792Spatrick
1083306792Spatrick /**
1183306792Spatrick * igc_init_phy_ops_generic - Initialize PHY function pointers
1283306792Spatrick * @hw: pointer to the HW structure
1383306792Spatrick *
1483306792Spatrick * Setups up the function pointers to no-op functions
1583306792Spatrick **/
1683306792Spatrick void
igc_init_phy_ops_generic(struct igc_hw * hw)1783306792Spatrick igc_init_phy_ops_generic(struct igc_hw *hw)
1883306792Spatrick {
1983306792Spatrick struct igc_phy_info *phy = &hw->phy;
2083306792Spatrick DEBUGFUNC("igc_init_phy_ops_generic");
2183306792Spatrick
2283306792Spatrick /* Initialize function pointers */
2383306792Spatrick phy->ops.init_params = igc_null_ops_generic;
2483306792Spatrick phy->ops.acquire = igc_null_ops_generic;
2583306792Spatrick phy->ops.check_reset_block = igc_null_ops_generic;
2683306792Spatrick phy->ops.force_speed_duplex = igc_null_ops_generic;
2783306792Spatrick phy->ops.get_info = igc_null_ops_generic;
2883306792Spatrick phy->ops.set_page = igc_null_set_page;
2983306792Spatrick phy->ops.read_reg = igc_null_read_reg;
3083306792Spatrick phy->ops.read_reg_locked = igc_null_read_reg;
3183306792Spatrick phy->ops.read_reg_page = igc_null_read_reg;
3283306792Spatrick phy->ops.release = igc_null_phy_generic;
3383306792Spatrick phy->ops.reset = igc_null_ops_generic;
3483306792Spatrick phy->ops.set_d0_lplu_state = igc_null_lplu_state;
3583306792Spatrick phy->ops.set_d3_lplu_state = igc_null_lplu_state;
3683306792Spatrick phy->ops.write_reg = igc_null_write_reg;
3783306792Spatrick phy->ops.write_reg_locked = igc_null_write_reg;
3883306792Spatrick phy->ops.write_reg_page = igc_null_write_reg;
3983306792Spatrick phy->ops.power_up = igc_null_phy_generic;
4083306792Spatrick phy->ops.power_down = igc_null_phy_generic;
4183306792Spatrick }
4283306792Spatrick
4383306792Spatrick /**
4483306792Spatrick * igc_null_set_page - No-op function, return 0
4583306792Spatrick * @hw: pointer to the HW structure
4683306792Spatrick * @data: dummy variable
4783306792Spatrick **/
4883306792Spatrick int
igc_null_set_page(struct igc_hw IGC_UNUSEDARG * hw,uint16_t IGC_UNUSEDARG data)4983306792Spatrick igc_null_set_page(struct igc_hw IGC_UNUSEDARG *hw, uint16_t IGC_UNUSEDARG data)
5083306792Spatrick {
5183306792Spatrick DEBUGFUNC("igc_null_set_page");
5283306792Spatrick return IGC_SUCCESS;
5383306792Spatrick }
5483306792Spatrick
5583306792Spatrick /**
5683306792Spatrick * igc_null_read_reg - No-op function, return 0
5783306792Spatrick * @hw: pointer to the HW structure
5883306792Spatrick * @offset: dummy variable
5983306792Spatrick * @data: dummy variable
6083306792Spatrick **/
6183306792Spatrick int
igc_null_read_reg(struct igc_hw IGC_UNUSEDARG * hw,uint32_t IGC_UNUSEDARG offset,uint16_t IGC_UNUSEDARG * data)6283306792Spatrick igc_null_read_reg(struct igc_hw IGC_UNUSEDARG *hw,
6383306792Spatrick uint32_t IGC_UNUSEDARG offset, uint16_t IGC_UNUSEDARG *data)
6483306792Spatrick {
6583306792Spatrick DEBUGFUNC("igc_null_read_reg");
6683306792Spatrick return IGC_SUCCESS;
6783306792Spatrick }
6883306792Spatrick
6983306792Spatrick /**
7083306792Spatrick * igc_null_phy_generic - No-op function, return void
7183306792Spatrick * @hw: pointer to the HW structure
7283306792Spatrick **/
7383306792Spatrick void
igc_null_phy_generic(struct igc_hw IGC_UNUSEDARG * hw)7483306792Spatrick igc_null_phy_generic(struct igc_hw IGC_UNUSEDARG *hw)
7583306792Spatrick {
7683306792Spatrick DEBUGFUNC("igc_null_phy_generic");
7783306792Spatrick return;
7883306792Spatrick }
7983306792Spatrick
8083306792Spatrick /**
8183306792Spatrick * igc_null_lplu_state - No-op function, return 0
8283306792Spatrick * @hw: pointer to the HW structure
8383306792Spatrick * @active: dummy variable
8483306792Spatrick **/
8583306792Spatrick int
igc_null_lplu_state(struct igc_hw IGC_UNUSEDARG * hw,bool IGC_UNUSEDARG active)8683306792Spatrick igc_null_lplu_state(struct igc_hw IGC_UNUSEDARG *hw, bool IGC_UNUSEDARG active)
8783306792Spatrick {
8883306792Spatrick DEBUGFUNC("igc_null_lplu_state");
8983306792Spatrick return IGC_SUCCESS;
9083306792Spatrick }
9183306792Spatrick
9283306792Spatrick /**
9383306792Spatrick * igc_null_write_reg - No-op function, return 0
9483306792Spatrick * @hw: pointer to the HW structure
9583306792Spatrick * @offset: dummy variable
9683306792Spatrick * @data: dummy variable
9783306792Spatrick **/
9883306792Spatrick int
igc_null_write_reg(struct igc_hw IGC_UNUSEDARG * hw,uint32_t IGC_UNUSEDARG offset,uint16_t IGC_UNUSEDARG data)9983306792Spatrick igc_null_write_reg(struct igc_hw IGC_UNUSEDARG *hw,
10083306792Spatrick uint32_t IGC_UNUSEDARG offset, uint16_t IGC_UNUSEDARG data)
10183306792Spatrick {
10283306792Spatrick DEBUGFUNC("igc_null_write_reg");
10383306792Spatrick return IGC_SUCCESS;
10483306792Spatrick }
10583306792Spatrick
10683306792Spatrick /**
10783306792Spatrick * igc_check_reset_block_generic - Check if PHY reset is blocked
10883306792Spatrick * @hw: pointer to the HW structure
10983306792Spatrick *
11083306792Spatrick * Read the PHY management control register and check whether a PHY reset
11183306792Spatrick * is blocked. If a reset is not blocked return IGC_SUCCESS, otherwise
11283306792Spatrick * return IGC_BLK_PHY_RESET (12).
11383306792Spatrick **/
11483306792Spatrick int
igc_check_reset_block_generic(struct igc_hw * hw)11583306792Spatrick igc_check_reset_block_generic(struct igc_hw *hw)
11683306792Spatrick {
11783306792Spatrick uint32_t manc;
11883306792Spatrick
11983306792Spatrick DEBUGFUNC("igc_check_reset_block");
12083306792Spatrick
12183306792Spatrick manc = IGC_READ_REG(hw, IGC_MANC);
12283306792Spatrick
12383306792Spatrick return (manc & IGC_MANC_BLK_PHY_RST_ON_IDE) ?
12483306792Spatrick IGC_BLK_PHY_RESET : IGC_SUCCESS;
12583306792Spatrick }
12683306792Spatrick
12783306792Spatrick /**
12883306792Spatrick * igc_get_phy_id - Retrieve the PHY ID and revision
12983306792Spatrick * @hw: pointer to the HW structure
13083306792Spatrick *
13183306792Spatrick * Reads the PHY registers and stores the PHY ID and possibly the PHY
13283306792Spatrick * revision in the hardware structure.
13383306792Spatrick **/
13483306792Spatrick int
igc_get_phy_id(struct igc_hw * hw)13583306792Spatrick igc_get_phy_id(struct igc_hw *hw)
13683306792Spatrick {
13783306792Spatrick struct igc_phy_info *phy = &hw->phy;
13883306792Spatrick uint16_t phy_id;
13983306792Spatrick int ret_val = IGC_SUCCESS;
14083306792Spatrick
14183306792Spatrick DEBUGFUNC("igc_get_phy_id");
14283306792Spatrick
14383306792Spatrick if (!phy->ops.read_reg)
14483306792Spatrick return IGC_SUCCESS;
14583306792Spatrick
14683306792Spatrick ret_val = phy->ops.read_reg(hw, PHY_ID1, &phy_id);
14783306792Spatrick if (ret_val)
14883306792Spatrick return ret_val;
14983306792Spatrick
15083306792Spatrick phy->id = (uint32_t)(phy_id << 16);
151b7fccf02Skevlo DELAY(200);
15283306792Spatrick ret_val = phy->ops.read_reg(hw, PHY_ID2, &phy_id);
15383306792Spatrick if (ret_val)
15483306792Spatrick return ret_val;
15583306792Spatrick
15683306792Spatrick phy->id |= (uint32_t)(phy_id & PHY_REVISION_MASK);
15783306792Spatrick phy->revision = (uint32_t)(phy_id & ~PHY_REVISION_MASK);
15883306792Spatrick
15983306792Spatrick return IGC_SUCCESS;
16083306792Spatrick }
16183306792Spatrick
16283306792Spatrick /**
16383306792Spatrick * igc_read_phy_reg_mdic - Read MDI control register
16483306792Spatrick * @hw: pointer to the HW structure
16583306792Spatrick * @offset: register offset to be read
16683306792Spatrick * @data: pointer to the read data
16783306792Spatrick *
16883306792Spatrick * Reads the MDI control register in the PHY at offset and stores the
16983306792Spatrick * information read to data.
17083306792Spatrick **/
17183306792Spatrick int
igc_read_phy_reg_mdic(struct igc_hw * hw,uint32_t offset,uint16_t * data)17283306792Spatrick igc_read_phy_reg_mdic(struct igc_hw *hw, uint32_t offset, uint16_t *data)
17383306792Spatrick {
17483306792Spatrick struct igc_phy_info *phy = &hw->phy;
17583306792Spatrick uint32_t i, mdic = 0;
17683306792Spatrick
17783306792Spatrick DEBUGFUNC("igc_read_phy_reg_mdic");
17883306792Spatrick
17983306792Spatrick if (offset > MAX_PHY_REG_ADDRESS) {
18083306792Spatrick DEBUGOUT1("PHY Address %d is out of range\n", offset);
18183306792Spatrick return -IGC_ERR_PARAM;
18283306792Spatrick }
18383306792Spatrick
18483306792Spatrick /* Set up Op-code, Phy Address, and register offset in the MDI
18583306792Spatrick * Control register. The MAC will take care of interfacing with the
18683306792Spatrick * PHY to retrieve the desired data.
18783306792Spatrick */
18883306792Spatrick mdic = ((offset << IGC_MDIC_REG_SHIFT) |
18983306792Spatrick (phy->addr << IGC_MDIC_PHY_SHIFT) | (IGC_MDIC_OP_READ));
19083306792Spatrick
19183306792Spatrick IGC_WRITE_REG(hw, IGC_MDIC, mdic);
19283306792Spatrick
19383306792Spatrick /* Poll the ready bit to see if the MDI read completed
19483306792Spatrick * Increasing the time out as testing showed failures with
19583306792Spatrick * the lower time out
19683306792Spatrick */
19783306792Spatrick for (i = 0; i < (IGC_GEN_POLL_TIMEOUT * 3); i++) {
19883306792Spatrick DELAY(50);
19983306792Spatrick mdic = IGC_READ_REG(hw, IGC_MDIC);
20083306792Spatrick if (mdic & IGC_MDIC_READY)
20183306792Spatrick break;
20283306792Spatrick }
20383306792Spatrick if (!(mdic & IGC_MDIC_READY)) {
20483306792Spatrick DEBUGOUT("MDI Read did not complete\n");
20583306792Spatrick return -IGC_ERR_PHY;
20683306792Spatrick }
20783306792Spatrick if (mdic & IGC_MDIC_ERROR) {
20883306792Spatrick DEBUGOUT("MDI Error\n");
20983306792Spatrick return -IGC_ERR_PHY;
21083306792Spatrick }
21183306792Spatrick if (((mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT) != offset) {
21283306792Spatrick DEBUGOUT2("MDI Read offset error - requested %d, returned %d\n",
21383306792Spatrick offset, (mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT);
21483306792Spatrick return -IGC_ERR_PHY;
21583306792Spatrick }
21683306792Spatrick *data = (uint16_t)mdic;
21783306792Spatrick
21883306792Spatrick return IGC_SUCCESS;
21983306792Spatrick }
22083306792Spatrick
22183306792Spatrick /**
22283306792Spatrick * igc_write_phy_reg_mdic - Write MDI control register
22383306792Spatrick * @hw: pointer to the HW structure
22483306792Spatrick * @offset: register offset to write to
22583306792Spatrick * @data: data to write to register at offset
22683306792Spatrick *
22783306792Spatrick * Writes data to MDI control register in the PHY at offset.
22883306792Spatrick **/
22983306792Spatrick int
igc_write_phy_reg_mdic(struct igc_hw * hw,uint32_t offset,uint16_t data)23083306792Spatrick igc_write_phy_reg_mdic(struct igc_hw *hw, uint32_t offset, uint16_t data)
23183306792Spatrick {
23283306792Spatrick struct igc_phy_info *phy = &hw->phy;
23383306792Spatrick uint32_t i, mdic = 0;
23483306792Spatrick
23583306792Spatrick DEBUGFUNC("igc_write_phy_reg_mdic");
23683306792Spatrick
23783306792Spatrick if (offset > MAX_PHY_REG_ADDRESS) {
23883306792Spatrick DEBUGOUT1("PHY Address %d is out of range\n", offset);
23983306792Spatrick return -IGC_ERR_PARAM;
24083306792Spatrick }
24183306792Spatrick
24283306792Spatrick /* Set up Op-code, Phy Address, and register offset in the MDI
24383306792Spatrick * Control register. The MAC will take care of interfacing with the
24483306792Spatrick * PHY to retrieve the desired data.
24583306792Spatrick */
24683306792Spatrick mdic = (((uint32_t)data) | (offset << IGC_MDIC_REG_SHIFT) |
24783306792Spatrick (phy->addr << IGC_MDIC_PHY_SHIFT) | (IGC_MDIC_OP_WRITE));
24883306792Spatrick
24983306792Spatrick IGC_WRITE_REG(hw, IGC_MDIC, mdic);
25083306792Spatrick
25183306792Spatrick /* Poll the ready bit to see if the MDI read completed
25283306792Spatrick * Increasing the time out as testing showed failures with
25383306792Spatrick * the lower time out
25483306792Spatrick */
25583306792Spatrick for (i = 0; i < (IGC_GEN_POLL_TIMEOUT * 3); i++) {
25683306792Spatrick DELAY(50);
25783306792Spatrick mdic = IGC_READ_REG(hw, IGC_MDIC);
25883306792Spatrick if (mdic & IGC_MDIC_READY)
25983306792Spatrick break;
26083306792Spatrick }
26183306792Spatrick if (!(mdic & IGC_MDIC_READY)) {
26283306792Spatrick DEBUGOUT("MDI Write did not complete\n");
26383306792Spatrick return -IGC_ERR_PHY;
26483306792Spatrick }
26583306792Spatrick if (mdic & IGC_MDIC_ERROR) {
26683306792Spatrick DEBUGOUT("MDI Error\n");
26783306792Spatrick return -IGC_ERR_PHY;
26883306792Spatrick }
26983306792Spatrick if (((mdic & IGC_MDIC_REG_MASK) >> IGC_MDIC_REG_SHIFT) != offset)
27083306792Spatrick return -IGC_ERR_PHY;
27183306792Spatrick
27283306792Spatrick return IGC_SUCCESS;
27383306792Spatrick }
27483306792Spatrick
27583306792Spatrick /**
27683306792Spatrick * igc_phy_setup_autoneg - Configure PHY for auto-negotiation
27783306792Spatrick * @hw: pointer to the HW structure
27883306792Spatrick *
27983306792Spatrick * Reads the MII auto-neg advertisement register and/or the 1000T control
28083306792Spatrick * register and if the PHY is already setup for auto-negotiation, then
28183306792Spatrick * return successful. Otherwise, setup advertisement and flow control to
28283306792Spatrick * the appropriate values for the wanted auto-negotiation.
28383306792Spatrick **/
28483306792Spatrick int
igc_phy_setup_autoneg(struct igc_hw * hw)28583306792Spatrick igc_phy_setup_autoneg(struct igc_hw *hw)
28683306792Spatrick {
28783306792Spatrick struct igc_phy_info *phy = &hw->phy;
28883306792Spatrick uint16_t mii_autoneg_adv_reg;
28983306792Spatrick uint16_t mii_1000t_ctrl_reg = 0;
29083306792Spatrick uint16_t aneg_multigbt_an_ctrl = 0;
29183306792Spatrick int ret_val;
29283306792Spatrick
29383306792Spatrick DEBUGFUNC("igc_phy_setup_autoneg");
29483306792Spatrick
29583306792Spatrick phy->autoneg_advertised &= phy->autoneg_mask;
29683306792Spatrick
29783306792Spatrick /* Read the MII Auto-Neg Advertisement Register (Address 4). */
29883306792Spatrick ret_val = phy->ops.read_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
29983306792Spatrick if (ret_val)
30083306792Spatrick return ret_val;
30183306792Spatrick
30283306792Spatrick if (phy->autoneg_mask & ADVERTISE_1000_FULL) {
30383306792Spatrick /* Read the MII 1000Base-T Control Register (Address 9). */
30483306792Spatrick ret_val = phy->ops.read_reg(hw, PHY_1000T_CTRL,
30583306792Spatrick &mii_1000t_ctrl_reg);
30683306792Spatrick if (ret_val)
30783306792Spatrick return ret_val;
30883306792Spatrick }
30983306792Spatrick
310*249b931fSmbuhl if (phy->autoneg_mask & ADVERTISE_2500_FULL) {
31183306792Spatrick /* Read the MULTI GBT AN Control Register - reg 7.32 */
31283306792Spatrick ret_val = phy->ops.read_reg(hw, (STANDARD_AN_REG_MASK <<
31383306792Spatrick MMD_DEVADDR_SHIFT) | ANEG_MULTIGBT_AN_CTRL,
31483306792Spatrick &aneg_multigbt_an_ctrl);
31583306792Spatrick if (ret_val)
31683306792Spatrick return ret_val;
31783306792Spatrick }
31883306792Spatrick
31983306792Spatrick /* Need to parse both autoneg_advertised and fc and set up
32083306792Spatrick * the appropriate PHY registers. First we will parse for
32183306792Spatrick * autoneg_advertised software override. Since we can advertise
32283306792Spatrick * a plethora of combinations, we need to check each bit
32383306792Spatrick * individually.
32483306792Spatrick */
32583306792Spatrick
32683306792Spatrick /* First we clear all the 10/100 mb speed bits in the Auto-Neg
32783306792Spatrick * Advertisement Register (Address 4) and the 1000 mb speed bits in
32883306792Spatrick * the 1000Base-T Control Register (Address 9).
32983306792Spatrick */
33083306792Spatrick mii_autoneg_adv_reg &= ~(NWAY_AR_100TX_FD_CAPS | NWAY_AR_100TX_HD_CAPS |
33183306792Spatrick NWAY_AR_10T_FD_CAPS | NWAY_AR_10T_HD_CAPS);
33283306792Spatrick mii_1000t_ctrl_reg &= ~(CR_1000T_HD_CAPS | CR_1000T_FD_CAPS);
33383306792Spatrick
33483306792Spatrick DEBUGOUT1("autoneg_advertised %x\n", phy->autoneg_advertised);
33583306792Spatrick
33683306792Spatrick /* Do we want to advertise 10 Mb Half Duplex? */
33783306792Spatrick if (phy->autoneg_advertised & ADVERTISE_10_HALF) {
33883306792Spatrick DEBUGOUT("Advertise 10mb Half duplex\n");
33983306792Spatrick mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
34083306792Spatrick }
34183306792Spatrick
34283306792Spatrick /* Do we want to advertise 10 Mb Full Duplex? */
34383306792Spatrick if (phy->autoneg_advertised & ADVERTISE_10_FULL) {
34483306792Spatrick DEBUGOUT("Advertise 10mb Full duplex\n");
34583306792Spatrick mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
34683306792Spatrick }
34783306792Spatrick
34883306792Spatrick /* Do we want to advertise 100 Mb Half Duplex? */
34983306792Spatrick if (phy->autoneg_advertised & ADVERTISE_100_HALF) {
35083306792Spatrick DEBUGOUT("Advertise 100mb Half duplex\n");
35183306792Spatrick mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
35283306792Spatrick }
35383306792Spatrick
35483306792Spatrick /* Do we want to advertise 100 Mb Full Duplex? */
35583306792Spatrick if (phy->autoneg_advertised & ADVERTISE_100_FULL) {
35683306792Spatrick DEBUGOUT("Advertise 100mb Full duplex\n");
35783306792Spatrick mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
35883306792Spatrick }
35983306792Spatrick
36083306792Spatrick /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
36183306792Spatrick if (phy->autoneg_advertised & ADVERTISE_1000_HALF)
36283306792Spatrick DEBUGOUT("Advertise 1000mb Half duplex request denied!\n");
36383306792Spatrick
36483306792Spatrick /* Do we want to advertise 1000 Mb Full Duplex? */
36583306792Spatrick if (phy->autoneg_advertised & ADVERTISE_1000_FULL) {
36683306792Spatrick DEBUGOUT("Advertise 1000mb Full duplex\n");
36783306792Spatrick mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
36883306792Spatrick }
36983306792Spatrick
37083306792Spatrick /* We do not allow the Phy to advertise 2500 Mb Half Duplex */
37183306792Spatrick if (phy->autoneg_advertised & ADVERTISE_2500_HALF)
37283306792Spatrick DEBUGOUT("Advertise 2500mb Half duplex request denied!\n");
37383306792Spatrick
37483306792Spatrick /* Do we want to advertise 2500 Mb Full Duplex? */
37583306792Spatrick if (phy->autoneg_advertised & ADVERTISE_2500_FULL) {
37683306792Spatrick DEBUGOUT("Advertise 2500mb Full duplex\n");
37783306792Spatrick aneg_multigbt_an_ctrl |= CR_2500T_FD_CAPS;
37883306792Spatrick } else
37983306792Spatrick aneg_multigbt_an_ctrl &= ~CR_2500T_FD_CAPS;
38083306792Spatrick
38183306792Spatrick /* Check for a software override of the flow control settings, and
38283306792Spatrick * setup the PHY advertisement registers accordingly. If
38383306792Spatrick * auto-negotiation is enabled, then software will have to set the
38483306792Spatrick * "PAUSE" bits to the correct value in the Auto-Negotiation
38583306792Spatrick * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-
38683306792Spatrick * negotiation.
38783306792Spatrick *
38883306792Spatrick * The possible values of the "fc" parameter are:
38983306792Spatrick * 0: Flow control is completely disabled
39083306792Spatrick * 1: Rx flow control is enabled (we can receive pause frames
39183306792Spatrick * but not send pause frames).
39283306792Spatrick * 2: Tx flow control is enabled (we can send pause frames
39383306792Spatrick * but we do not support receiving pause frames).
39483306792Spatrick * 3: Both Rx and Tx flow control (symmetric) are enabled.
39583306792Spatrick * other: No software override. The flow control configuration
39683306792Spatrick * in the EEPROM is used.
39783306792Spatrick */
39883306792Spatrick switch (hw->fc.current_mode) {
39983306792Spatrick case igc_fc_none:
40083306792Spatrick /* Flow control (Rx & Tx) is completely disabled by a
40183306792Spatrick * software over-ride.
40283306792Spatrick */
40383306792Spatrick mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
40483306792Spatrick break;
40583306792Spatrick case igc_fc_rx_pause:
40683306792Spatrick /* Rx Flow control is enabled, and Tx Flow control is
40783306792Spatrick * disabled, by a software over-ride.
40883306792Spatrick *
40983306792Spatrick * Since there really isn't a way to advertise that we are
41083306792Spatrick * capable of Rx Pause ONLY, we will advertise that we
41183306792Spatrick * support both symmetric and asymmetric Rx PAUSE. Later
41283306792Spatrick * (in igc_config_fc_after_link_up) we will disable the
41383306792Spatrick * hw's ability to send PAUSE frames.
41483306792Spatrick */
41583306792Spatrick mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
41683306792Spatrick break;
41783306792Spatrick case igc_fc_tx_pause:
41883306792Spatrick /* Tx Flow control is enabled, and Rx Flow control is
41983306792Spatrick * disabled, by a software over-ride.
42083306792Spatrick */
42183306792Spatrick mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
42283306792Spatrick mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
42383306792Spatrick break;
42483306792Spatrick case igc_fc_full:
42583306792Spatrick /* Flow control (both Rx and Tx) is enabled by a software
42683306792Spatrick * over-ride.
42783306792Spatrick */
42883306792Spatrick mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
42983306792Spatrick break;
43083306792Spatrick default:
43183306792Spatrick DEBUGOUT("Flow control param set incorrectly\n");
43283306792Spatrick return -IGC_ERR_CONFIG;
43383306792Spatrick }
43483306792Spatrick
43583306792Spatrick ret_val = phy->ops.write_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
43683306792Spatrick if (ret_val)
43783306792Spatrick return ret_val;
43883306792Spatrick
43983306792Spatrick DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
44083306792Spatrick
44183306792Spatrick if (phy->autoneg_mask & ADVERTISE_1000_FULL)
44283306792Spatrick ret_val = phy->ops.write_reg(hw, PHY_1000T_CTRL,
44383306792Spatrick mii_1000t_ctrl_reg);
44483306792Spatrick
445*249b931fSmbuhl if (phy->autoneg_mask & ADVERTISE_2500_FULL)
44683306792Spatrick ret_val = phy->ops.write_reg(hw,
44783306792Spatrick (STANDARD_AN_REG_MASK << MMD_DEVADDR_SHIFT) |
44883306792Spatrick ANEG_MULTIGBT_AN_CTRL, aneg_multigbt_an_ctrl);
44983306792Spatrick
45083306792Spatrick return ret_val;
45183306792Spatrick }
45283306792Spatrick
45383306792Spatrick /**
45483306792Spatrick * igc_copper_link_autoneg - Setup/Enable autoneg for copper link
45583306792Spatrick * @hw: pointer to the HW structure
45683306792Spatrick *
45783306792Spatrick * Performs initial bounds checking on autoneg advertisement parameter, then
45883306792Spatrick * configure to advertise the full capability. Setup the PHY to autoneg
45983306792Spatrick * and restart the negotiation process between the link partner. If
46083306792Spatrick * autoneg_wait_to_complete, then wait for autoneg to complete before exiting.
46183306792Spatrick **/
46283306792Spatrick int
igc_copper_link_autoneg(struct igc_hw * hw)46383306792Spatrick igc_copper_link_autoneg(struct igc_hw *hw)
46483306792Spatrick {
46583306792Spatrick struct igc_phy_info *phy = &hw->phy;
46683306792Spatrick uint16_t phy_ctrl;
46783306792Spatrick int ret_val;
46883306792Spatrick
46983306792Spatrick DEBUGFUNC("igc_copper_link_autoneg");
47083306792Spatrick
47183306792Spatrick /* Perform some bounds checking on the autoneg advertisement
47283306792Spatrick * parameter.
47383306792Spatrick */
47483306792Spatrick phy->autoneg_advertised &= phy->autoneg_mask;
47583306792Spatrick
47683306792Spatrick /* If autoneg_advertised is zero, we assume it was not defaulted
47783306792Spatrick * by the calling code so we set to advertise full capability.
47883306792Spatrick */
47983306792Spatrick if (!phy->autoneg_advertised)
48083306792Spatrick phy->autoneg_advertised = phy->autoneg_mask;
48183306792Spatrick
48283306792Spatrick DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
48383306792Spatrick ret_val = igc_phy_setup_autoneg(hw);
48483306792Spatrick if (ret_val) {
48583306792Spatrick DEBUGOUT("Error Setting up Auto-Negotiation\n");
48683306792Spatrick return ret_val;
48783306792Spatrick }
48883306792Spatrick DEBUGOUT("Restarting Auto-Neg\n");
48983306792Spatrick
49083306792Spatrick /* Restart auto-negotiation by setting the Auto Neg Enable bit and
49183306792Spatrick * the Auto Neg Restart bit in the PHY control register.
49283306792Spatrick */
49383306792Spatrick ret_val = phy->ops.read_reg(hw, PHY_CONTROL, &phy_ctrl);
49483306792Spatrick if (ret_val)
49583306792Spatrick return ret_val;
49683306792Spatrick
49783306792Spatrick phy_ctrl |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
49883306792Spatrick ret_val = phy->ops.write_reg(hw, PHY_CONTROL, phy_ctrl);
49983306792Spatrick if (ret_val)
50083306792Spatrick return ret_val;
50183306792Spatrick
50283306792Spatrick /* Does the user want to wait for Auto-Neg to complete here, or
50383306792Spatrick * check at a later time (for example, callback routine).
50483306792Spatrick */
50583306792Spatrick if (phy->autoneg_wait_to_complete) {
50683306792Spatrick ret_val = igc_wait_autoneg(hw);
50783306792Spatrick if (ret_val)
50883306792Spatrick return ret_val;
50983306792Spatrick }
51083306792Spatrick
51183306792Spatrick hw->mac.get_link_status = true;
51283306792Spatrick
51383306792Spatrick return ret_val;
51483306792Spatrick }
51583306792Spatrick
51683306792Spatrick /**
51783306792Spatrick * igc_setup_copper_link_generic - Configure copper link settings
51883306792Spatrick * @hw: pointer to the HW structure
51983306792Spatrick *
52083306792Spatrick * Calls the appropriate function to configure the link for auto-neg or forced
52183306792Spatrick * speed and duplex. Then we check for link, once link is established calls
52283306792Spatrick * to configure collision distance and flow control are called. If link is
52383306792Spatrick * not established, we return -IGC_ERR_PHY (-2).
52483306792Spatrick **/
52583306792Spatrick int
igc_setup_copper_link_generic(struct igc_hw * hw)52683306792Spatrick igc_setup_copper_link_generic(struct igc_hw *hw)
52783306792Spatrick {
52883306792Spatrick int ret_val;
52983306792Spatrick bool link;
53083306792Spatrick
53183306792Spatrick DEBUGFUNC("igc_setup_copper_link_generic");
53283306792Spatrick
53383306792Spatrick if (hw->mac.autoneg) {
53483306792Spatrick /* Setup autoneg and flow control advertisement and perform
53583306792Spatrick * autonegotiation.
53683306792Spatrick */
53783306792Spatrick ret_val = igc_copper_link_autoneg(hw);
53883306792Spatrick if (ret_val)
53983306792Spatrick return ret_val;
54083306792Spatrick } else {
54183306792Spatrick /* PHY will be set to 10H, 10F, 100H or 100F
54283306792Spatrick * depending on user settings.
54383306792Spatrick */
54483306792Spatrick DEBUGOUT("Forcing Speed and Duplex\n");
54583306792Spatrick ret_val = hw->phy.ops.force_speed_duplex(hw);
54683306792Spatrick if (ret_val) {
54783306792Spatrick DEBUGOUT("Error Forcing Speed and Duplex\n");
54883306792Spatrick return ret_val;
54983306792Spatrick }
55083306792Spatrick }
55183306792Spatrick
55283306792Spatrick /* Check link status. Wait up to 100 microseconds for link to become
55383306792Spatrick * valid.
55483306792Spatrick */
55583306792Spatrick ret_val = igc_phy_has_link_generic(hw, COPPER_LINK_UP_LIMIT, 10,
55683306792Spatrick &link);
55783306792Spatrick if (ret_val)
55883306792Spatrick return ret_val;
55983306792Spatrick
56083306792Spatrick if (link) {
56183306792Spatrick DEBUGOUT("Valid link established!!!\n");
56283306792Spatrick hw->mac.ops.config_collision_dist(hw);
56383306792Spatrick ret_val = igc_config_fc_after_link_up_generic(hw);
56483306792Spatrick } else
56583306792Spatrick DEBUGOUT("Unable to establish link!!!\n");
56683306792Spatrick
56783306792Spatrick return ret_val;
56883306792Spatrick }
56983306792Spatrick
57083306792Spatrick /**
57183306792Spatrick * igc_check_downshift_generic - Checks whether a downshift in speed occurred
57283306792Spatrick * @hw: pointer to the HW structure
57383306792Spatrick *
57483306792Spatrick * Success returns 0, Failure returns 1
57583306792Spatrick *
57683306792Spatrick * A downshift is detected by querying the PHY link health.
57783306792Spatrick **/
57883306792Spatrick int
igc_check_downshift_generic(struct igc_hw * hw)57983306792Spatrick igc_check_downshift_generic(struct igc_hw *hw)
58083306792Spatrick {
58183306792Spatrick struct igc_phy_info *phy = &hw->phy;
58283306792Spatrick int ret_val;
58383306792Spatrick
58483306792Spatrick DEBUGFUNC("igc_check_downshift_generic");
58583306792Spatrick
58683306792Spatrick switch (phy->type) {
58783306792Spatrick case igc_phy_i225:
58883306792Spatrick default:
58983306792Spatrick /* speed downshift not supported */
59083306792Spatrick phy->speed_downgraded = false;
59183306792Spatrick return IGC_SUCCESS;
59283306792Spatrick }
59383306792Spatrick
59483306792Spatrick return ret_val;
59583306792Spatrick }
59683306792Spatrick
59783306792Spatrick /**
59883306792Spatrick * igc_wait_autoneg - Wait for auto-neg completion
59983306792Spatrick * @hw: pointer to the HW structure
60083306792Spatrick *
60183306792Spatrick * Waits for auto-negotiation to complete or for the auto-negotiation time
60283306792Spatrick * limit to expire, which ever happens first.
60383306792Spatrick **/
60483306792Spatrick int
igc_wait_autoneg(struct igc_hw * hw)60583306792Spatrick igc_wait_autoneg(struct igc_hw *hw)
60683306792Spatrick {
60783306792Spatrick uint16_t i, phy_status;
60883306792Spatrick int ret_val = IGC_SUCCESS;
60983306792Spatrick
61083306792Spatrick DEBUGFUNC("igc_wait_autoneg");
61183306792Spatrick
61283306792Spatrick if (!hw->phy.ops.read_reg)
61383306792Spatrick return IGC_SUCCESS;
61483306792Spatrick
61583306792Spatrick /* Break after autoneg completes or PHY_AUTO_NEG_LIMIT expires. */
61683306792Spatrick for (i = PHY_AUTO_NEG_LIMIT; i > 0; i--) {
61783306792Spatrick ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
61883306792Spatrick if (ret_val)
61983306792Spatrick break;
62083306792Spatrick ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
62183306792Spatrick if (ret_val)
62283306792Spatrick break;
62383306792Spatrick if (phy_status & MII_SR_AUTONEG_COMPLETE)
62483306792Spatrick break;
62583306792Spatrick msec_delay(100);
62683306792Spatrick }
62783306792Spatrick
62883306792Spatrick /* PHY_AUTO_NEG_TIME expiration doesn't guarantee auto-negotiation
62983306792Spatrick * has completed.
63083306792Spatrick */
63183306792Spatrick return ret_val;
63283306792Spatrick }
63383306792Spatrick
63483306792Spatrick /**
63583306792Spatrick * igc_phy_has_link_generic - Polls PHY for link
63683306792Spatrick * @hw: pointer to the HW structure
63783306792Spatrick * @iterations: number of times to poll for link
63883306792Spatrick * @usec_interval: delay between polling attempts
63983306792Spatrick * @success: pointer to whether polling was successful or not
64083306792Spatrick *
64183306792Spatrick * Polls the PHY status register for link, 'iterations' number of times.
64283306792Spatrick **/
64383306792Spatrick int
igc_phy_has_link_generic(struct igc_hw * hw,uint32_t iterations,uint32_t usec_interval,bool * success)64483306792Spatrick igc_phy_has_link_generic(struct igc_hw *hw, uint32_t iterations,
64583306792Spatrick uint32_t usec_interval, bool *success)
64683306792Spatrick {
64783306792Spatrick uint16_t i, phy_status;
64883306792Spatrick int ret_val = IGC_SUCCESS;
64983306792Spatrick
65083306792Spatrick DEBUGFUNC("igc_phy_has_link_generic");
65183306792Spatrick
65283306792Spatrick if (!hw->phy.ops.read_reg)
65383306792Spatrick return IGC_SUCCESS;
65483306792Spatrick
65583306792Spatrick for (i = 0; i < iterations; i++) {
65683306792Spatrick /* Some PHYs require the PHY_STATUS register to be read
65783306792Spatrick * twice due to the link bit being sticky. No harm doing
65883306792Spatrick * it across the board.
65983306792Spatrick */
66083306792Spatrick ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
66183306792Spatrick if (ret_val) {
66283306792Spatrick /* If the first read fails, another entity may have
66383306792Spatrick * ownership of the resources, wait and try again to
66483306792Spatrick * see if they have relinquished the resources yet.
66583306792Spatrick */
66683306792Spatrick if (usec_interval >= 1000)
66783306792Spatrick msec_delay(usec_interval/1000);
66883306792Spatrick else
66983306792Spatrick DELAY(usec_interval);
67083306792Spatrick }
67183306792Spatrick ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &phy_status);
67283306792Spatrick if (ret_val)
67383306792Spatrick break;
67483306792Spatrick if (phy_status & MII_SR_LINK_STATUS)
67583306792Spatrick break;
67683306792Spatrick if (usec_interval >= 1000)
67783306792Spatrick msec_delay(usec_interval/1000);
67883306792Spatrick else
67983306792Spatrick DELAY(usec_interval);
68083306792Spatrick }
68183306792Spatrick
68283306792Spatrick *success = (i < iterations);
68383306792Spatrick
68483306792Spatrick return ret_val;
68583306792Spatrick }
68683306792Spatrick
68783306792Spatrick /**
688b7fccf02Skevlo * igc_phy_hw_reset_generic - PHY hardware reset
68983306792Spatrick * @hw: pointer to the HW structure
69083306792Spatrick *
691b7fccf02Skevlo * Verify the reset block is not blocking us from resetting. Acquire
692b7fccf02Skevlo * semaphore (if necessary) and read/set/write the device control reset
693b7fccf02Skevlo * bit in the PHY. Wait the appropriate delay time for the device to
694b7fccf02Skevlo * reset and release the semaphore (if necessary).
69583306792Spatrick **/
69683306792Spatrick int
igc_phy_hw_reset_generic(struct igc_hw * hw)697b7fccf02Skevlo igc_phy_hw_reset_generic(struct igc_hw *hw)
69883306792Spatrick {
699b7fccf02Skevlo struct igc_phy_info *phy = &hw->phy;
700b7fccf02Skevlo uint32_t ctrl, timeout = 10000, phpm = 0;
70183306792Spatrick int ret_val;
70283306792Spatrick
703b7fccf02Skevlo DEBUGFUNC("igc_phy_hw_reset_generic");
70483306792Spatrick
705b7fccf02Skevlo if (phy->ops.check_reset_block) {
706b7fccf02Skevlo ret_val = phy->ops.check_reset_block(hw);
707b7fccf02Skevlo if (ret_val)
70883306792Spatrick return IGC_SUCCESS;
709b7fccf02Skevlo }
71083306792Spatrick
711b7fccf02Skevlo ret_val = phy->ops.acquire(hw);
71283306792Spatrick if (ret_val)
71383306792Spatrick return ret_val;
71483306792Spatrick
715b7fccf02Skevlo phpm = IGC_READ_REG(hw, IGC_I225_PHPM);
71683306792Spatrick
717b7fccf02Skevlo ctrl = IGC_READ_REG(hw, IGC_CTRL);
718b7fccf02Skevlo IGC_WRITE_REG(hw, IGC_CTRL, ctrl | IGC_CTRL_PHY_RST);
719b7fccf02Skevlo IGC_WRITE_FLUSH(hw);
720b7fccf02Skevlo
721b7fccf02Skevlo DELAY(phy->reset_delay_us);
722b7fccf02Skevlo
723b7fccf02Skevlo IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
724b7fccf02Skevlo IGC_WRITE_FLUSH(hw);
725b7fccf02Skevlo
726b7fccf02Skevlo DELAY(150);
727b7fccf02Skevlo
728b7fccf02Skevlo do {
729b7fccf02Skevlo phpm = IGC_READ_REG(hw, IGC_I225_PHPM);
730b7fccf02Skevlo timeout--;
73183306792Spatrick DELAY(1);
732b7fccf02Skevlo } while (!(phpm & IGC_I225_PHPM_RST_COMPL) && timeout);
733b7fccf02Skevlo
734b7fccf02Skevlo if (!timeout)
735b7fccf02Skevlo DEBUGOUT("Timeout expired after a phy reset\n");
736b7fccf02Skevlo
737b7fccf02Skevlo phy->ops.release(hw);
73883306792Spatrick
73983306792Spatrick return ret_val;
74083306792Spatrick }
74183306792Spatrick
74283306792Spatrick /**
74383306792Spatrick * igc_power_up_phy_copper - Restore copper link in case of PHY power down
74483306792Spatrick * @hw: pointer to the HW structure
74583306792Spatrick *
74683306792Spatrick * In the case of a PHY power down to save power, or to turn off link during a
74783306792Spatrick * driver unload, or wake on lan is not enabled, restore the link to previous
74883306792Spatrick * settings.
74983306792Spatrick **/
75083306792Spatrick void
igc_power_up_phy_copper(struct igc_hw * hw)75183306792Spatrick igc_power_up_phy_copper(struct igc_hw *hw)
75283306792Spatrick {
75383306792Spatrick uint16_t mii_reg = 0;
75483306792Spatrick
75583306792Spatrick /* The PHY will retain its settings across a power down/up cycle */
75683306792Spatrick hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
75783306792Spatrick mii_reg &= ~MII_CR_POWER_DOWN;
75883306792Spatrick hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
75983306792Spatrick DELAY(300);
76083306792Spatrick }
76183306792Spatrick
76283306792Spatrick /**
76383306792Spatrick * igc_power_down_phy_copper - Restore copper link in case of PHY power down
76483306792Spatrick * @hw: pointer to the HW structure
76583306792Spatrick *
76683306792Spatrick * In the case of a PHY power down to save power, or to turn off link during a
76783306792Spatrick * driver unload, or wake on lan is not enabled, restore the link to previous
76883306792Spatrick * settings.
76983306792Spatrick **/
77083306792Spatrick void
igc_power_down_phy_copper(struct igc_hw * hw)77183306792Spatrick igc_power_down_phy_copper(struct igc_hw *hw)
77283306792Spatrick {
77383306792Spatrick uint16_t mii_reg = 0;
77483306792Spatrick
77583306792Spatrick /* The PHY will retain its settings across a power down/up cycle */
77683306792Spatrick hw->phy.ops.read_reg(hw, PHY_CONTROL, &mii_reg);
77783306792Spatrick mii_reg |= MII_CR_POWER_DOWN;
77883306792Spatrick hw->phy.ops.write_reg(hw, PHY_CONTROL, mii_reg);
77983306792Spatrick msec_delay(1);
78083306792Spatrick }
78183306792Spatrick
78283306792Spatrick /**
78383306792Spatrick * igc_write_phy_reg_gpy - Write GPY PHY register
78483306792Spatrick * @hw: pointer to the HW structure
78583306792Spatrick * @offset: register offset to write to
78683306792Spatrick * @data: data to write at register offset
78783306792Spatrick *
78883306792Spatrick * Acquires semaphore, if necessary, then writes the data to PHY register
78983306792Spatrick * at the offset. Release any acquired semaphores before exiting.
79083306792Spatrick **/
79183306792Spatrick int
igc_write_phy_reg_gpy(struct igc_hw * hw,uint32_t offset,uint16_t data)79283306792Spatrick igc_write_phy_reg_gpy(struct igc_hw *hw, uint32_t offset, uint16_t data)
79383306792Spatrick {
79483306792Spatrick uint8_t dev_addr = (offset & GPY_MMD_MASK) >> GPY_MMD_SHIFT;
79583306792Spatrick int ret_val;
79683306792Spatrick
79783306792Spatrick DEBUGFUNC("igc_write_phy_reg_gpy");
79883306792Spatrick
79983306792Spatrick offset = offset & GPY_REG_MASK;
80083306792Spatrick
80183306792Spatrick if (!dev_addr) {
80283306792Spatrick ret_val = hw->phy.ops.acquire(hw);
80383306792Spatrick if (ret_val)
80483306792Spatrick return ret_val;
80583306792Spatrick ret_val = igc_write_phy_reg_mdic(hw, offset, data);
80683306792Spatrick if (ret_val)
80783306792Spatrick return ret_val;
80883306792Spatrick hw->phy.ops.release(hw);
80983306792Spatrick } else {
81083306792Spatrick ret_val = igc_write_xmdio_reg(hw, (uint16_t)offset, dev_addr,
81183306792Spatrick data);
81283306792Spatrick }
81383306792Spatrick
81483306792Spatrick return ret_val;
81583306792Spatrick }
81683306792Spatrick
81783306792Spatrick /**
81883306792Spatrick * igc_read_phy_reg_gpy - Read GPY PHY register
81983306792Spatrick * @hw: pointer to the HW structure
82083306792Spatrick * @offset: lower half is register offset to read to
82183306792Spatrick * upper half is MMD to use.
82283306792Spatrick * @data: data to read at register offset
82383306792Spatrick *
82483306792Spatrick * Acquires semaphore, if necessary, then reads the data in the PHY register
82583306792Spatrick * at the offset. Release any acquired semaphores before exiting.
82683306792Spatrick **/
82783306792Spatrick int
igc_read_phy_reg_gpy(struct igc_hw * hw,uint32_t offset,uint16_t * data)82883306792Spatrick igc_read_phy_reg_gpy(struct igc_hw *hw, uint32_t offset, uint16_t *data)
82983306792Spatrick {
83083306792Spatrick uint8_t dev_addr = (offset & GPY_MMD_MASK) >> GPY_MMD_SHIFT;
83183306792Spatrick int ret_val;
83283306792Spatrick
83383306792Spatrick DEBUGFUNC("igc_read_phy_reg_gpy");
83483306792Spatrick
83583306792Spatrick offset = offset & GPY_REG_MASK;
83683306792Spatrick
83783306792Spatrick if (!dev_addr) {
83883306792Spatrick ret_val = hw->phy.ops.acquire(hw);
83983306792Spatrick if (ret_val)
84083306792Spatrick return ret_val;
84183306792Spatrick ret_val = igc_read_phy_reg_mdic(hw, offset, data);
84283306792Spatrick if (ret_val)
84383306792Spatrick return ret_val;
84483306792Spatrick hw->phy.ops.release(hw);
84583306792Spatrick } else {
84683306792Spatrick ret_val = igc_read_xmdio_reg(hw, (uint16_t)offset, dev_addr,
84783306792Spatrick data);
84883306792Spatrick }
84983306792Spatrick
85083306792Spatrick return ret_val;
85183306792Spatrick }
85283306792Spatrick
85383306792Spatrick /**
85483306792Spatrick * __igc_access_xmdio_reg - Read/write XMDIO register
85583306792Spatrick * @hw: pointer to the HW structure
85683306792Spatrick * @address: XMDIO address to program
85783306792Spatrick * @dev_addr: device address to program
85883306792Spatrick * @data: pointer to value to read/write from/to the XMDIO address
85983306792Spatrick * @read: boolean flag to indicate read or write
86083306792Spatrick **/
86183306792Spatrick int
__igc_access_xmdio_reg(struct igc_hw * hw,uint16_t address,uint8_t dev_addr,uint16_t * data,bool read)86283306792Spatrick __igc_access_xmdio_reg(struct igc_hw *hw, uint16_t address, uint8_t dev_addr,
86383306792Spatrick uint16_t *data, bool read)
86483306792Spatrick {
86583306792Spatrick int ret_val;
86683306792Spatrick
86783306792Spatrick DEBUGFUNC("__igc_access_xmdio_reg");
86883306792Spatrick
86983306792Spatrick ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, dev_addr);
87083306792Spatrick if (ret_val)
87183306792Spatrick return ret_val;
87283306792Spatrick
87383306792Spatrick ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAAD, address);
87483306792Spatrick if (ret_val)
87583306792Spatrick return ret_val;
87683306792Spatrick
87783306792Spatrick ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, IGC_MMDAC_FUNC_DATA |
87883306792Spatrick dev_addr);
87983306792Spatrick if (ret_val)
88083306792Spatrick return ret_val;
88183306792Spatrick
88283306792Spatrick if (read)
88383306792Spatrick ret_val = hw->phy.ops.read_reg(hw, IGC_MMDAAD, data);
88483306792Spatrick else
88583306792Spatrick ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAAD, *data);
88683306792Spatrick if (ret_val)
88783306792Spatrick return ret_val;
88883306792Spatrick
88983306792Spatrick /* Recalibrate the device back to 0 */
89083306792Spatrick ret_val = hw->phy.ops.write_reg(hw, IGC_MMDAC, 0);
89183306792Spatrick if (ret_val)
89283306792Spatrick return ret_val;
89383306792Spatrick
89483306792Spatrick return ret_val;
89583306792Spatrick }
89683306792Spatrick
89783306792Spatrick /**
89883306792Spatrick * igc_read_xmdio_reg - Read XMDIO register
89983306792Spatrick * @hw: pointer to the HW structure
90083306792Spatrick * @addr: XMDIO address to program
90183306792Spatrick * @dev_addr: device address to program
90283306792Spatrick * @data: value to be read from the EMI address
90383306792Spatrick **/
90483306792Spatrick int
igc_read_xmdio_reg(struct igc_hw * hw,uint16_t addr,uint8_t dev_addr,uint16_t * data)90583306792Spatrick igc_read_xmdio_reg(struct igc_hw *hw, uint16_t addr, uint8_t dev_addr,
90683306792Spatrick uint16_t *data)
90783306792Spatrick {
90883306792Spatrick DEBUGFUNC("igc_read_xmdio_reg");
90983306792Spatrick
91083306792Spatrick return __igc_access_xmdio_reg(hw, addr, dev_addr, data, true);
91183306792Spatrick }
91283306792Spatrick
91383306792Spatrick /**
91483306792Spatrick * igc_write_xmdio_reg - Write XMDIO register
91583306792Spatrick * @hw: pointer to the HW structure
91683306792Spatrick * @addr: XMDIO address to program
91783306792Spatrick * @dev_addr: device address to program
91883306792Spatrick * @data: value to be written to the XMDIO address
91983306792Spatrick **/
92083306792Spatrick int
igc_write_xmdio_reg(struct igc_hw * hw,uint16_t addr,uint8_t dev_addr,uint16_t data)92183306792Spatrick igc_write_xmdio_reg(struct igc_hw *hw, uint16_t addr, uint8_t dev_addr,
92283306792Spatrick uint16_t data)
92383306792Spatrick {
92483306792Spatrick DEBUGFUNC("igc_write_xmdio_reg");
92583306792Spatrick
92683306792Spatrick return __igc_access_xmdio_reg(hw, addr, dev_addr, &data, false);
92783306792Spatrick }
928