1*6150453fSSepherosa Ziehau /******************************************************************************
2*6150453fSSepherosa Ziehau
3*6150453fSSepherosa Ziehau Copyright (c) 2001-2017, Intel Corporation
4*6150453fSSepherosa Ziehau All rights reserved.
5*6150453fSSepherosa Ziehau
6*6150453fSSepherosa Ziehau Redistribution and use in source and binary forms, with or without
7*6150453fSSepherosa Ziehau modification, are permitted provided that the following conditions are met:
8*6150453fSSepherosa Ziehau
9*6150453fSSepherosa Ziehau 1. Redistributions of source code must retain the above copyright notice,
10*6150453fSSepherosa Ziehau this list of conditions and the following disclaimer.
11*6150453fSSepherosa Ziehau
12*6150453fSSepherosa Ziehau 2. Redistributions in binary form must reproduce the above copyright
13*6150453fSSepherosa Ziehau notice, this list of conditions and the following disclaimer in the
14*6150453fSSepherosa Ziehau documentation and/or other materials provided with the distribution.
15*6150453fSSepherosa Ziehau
16*6150453fSSepherosa Ziehau 3. Neither the name of the Intel Corporation nor the names of its
17*6150453fSSepherosa Ziehau contributors may be used to endorse or promote products derived from
18*6150453fSSepherosa Ziehau this software without specific prior written permission.
19*6150453fSSepherosa Ziehau
20*6150453fSSepherosa Ziehau THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21*6150453fSSepherosa Ziehau AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*6150453fSSepherosa Ziehau IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*6150453fSSepherosa Ziehau ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24*6150453fSSepherosa Ziehau LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25*6150453fSSepherosa Ziehau CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26*6150453fSSepherosa Ziehau SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27*6150453fSSepherosa Ziehau INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28*6150453fSSepherosa Ziehau CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29*6150453fSSepherosa Ziehau ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30*6150453fSSepherosa Ziehau POSSIBILITY OF SUCH DAMAGE.
31*6150453fSSepherosa Ziehau
32*6150453fSSepherosa Ziehau ******************************************************************************/
33*6150453fSSepherosa Ziehau /*$FreeBSD$*/
34*6150453fSSepherosa Ziehau
35*6150453fSSepherosa Ziehau #include <sys/param.h>
36*6150453fSSepherosa Ziehau #include <sys/bus.h>
37*6150453fSSepherosa Ziehau #include <sys/taskqueue.h>
38*6150453fSSepherosa Ziehau
39*6150453fSSepherosa Ziehau #include <net/if.h>
40*6150453fSSepherosa Ziehau #include <net/if_arp.h>
41*6150453fSSepherosa Ziehau #include <net/if_media.h>
42*6150453fSSepherosa Ziehau #include <net/ifq_var.h>
43*6150453fSSepherosa Ziehau
44*6150453fSSepherosa Ziehau #include <dev/netif/ix/ixgbe_api.h>
45*6150453fSSepherosa Ziehau #include <dev/netif/ix/if_ix.h>
46*6150453fSSepherosa Ziehau
47*6150453fSSepherosa Ziehau u16
ixgbe_read_pci_cfg_pf(struct ixgbe_hw * hw,u32 reg)48*6150453fSSepherosa Ziehau ixgbe_read_pci_cfg_pf(struct ixgbe_hw *hw, u32 reg)
49*6150453fSSepherosa Ziehau {
50*6150453fSSepherosa Ziehau return pci_read_config(((struct ix_softc *)hw->back)->dev, reg, 2);
51*6150453fSSepherosa Ziehau }
52*6150453fSSepherosa Ziehau
53*6150453fSSepherosa Ziehau void
ixgbe_write_pci_cfg_pf(struct ixgbe_hw * hw,u32 reg,u16 value)54*6150453fSSepherosa Ziehau ixgbe_write_pci_cfg_pf(struct ixgbe_hw *hw, u32 reg, u16 value)
55*6150453fSSepherosa Ziehau {
56*6150453fSSepherosa Ziehau pci_write_config(((struct ix_softc *)hw->back)->dev, reg, value, 2);
57*6150453fSSepherosa Ziehau }
58*6150453fSSepherosa Ziehau
59*6150453fSSepherosa Ziehau u32
ixgbe_read_reg_pf(struct ixgbe_hw * hw,u32 reg)60*6150453fSSepherosa Ziehau ixgbe_read_reg_pf(struct ixgbe_hw *hw, u32 reg)
61*6150453fSSepherosa Ziehau {
62*6150453fSSepherosa Ziehau struct ix_softc *sc = (struct ix_softc *)hw->back;
63*6150453fSSepherosa Ziehau u32 retval;
64*6150453fSSepherosa Ziehau u8 i;
65*6150453fSSepherosa Ziehau
66*6150453fSSepherosa Ziehau retval = bus_space_read_4(sc->osdep.mem_bus_space_tag,
67*6150453fSSepherosa Ziehau sc->osdep.mem_bus_space_handle, reg);
68*6150453fSSepherosa Ziehau
69*6150453fSSepherosa Ziehau /* Normal... */
70*6150453fSSepherosa Ziehau if ((retval != 0xDEADBEEF) ||
71*6150453fSSepherosa Ziehau !(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE))
72*6150453fSSepherosa Ziehau return retval;
73*6150453fSSepherosa Ziehau
74*6150453fSSepherosa Ziehau /* Unusual... */
75*6150453fSSepherosa Ziehau
76*6150453fSSepherosa Ziehau /*
77*6150453fSSepherosa Ziehau * 10/100 Mb mode has a quirk where it's possible the previous
78*6150453fSSepherosa Ziehau * write to the Phy hasn't completed. So we keep trying.
79*6150453fSSepherosa Ziehau */
80*6150453fSSepherosa Ziehau for (i = 100; retval; i--) {
81*6150453fSSepherosa Ziehau if (!i) {
82*6150453fSSepherosa Ziehau device_printf(sc->dev, "Register (0x%08X) writes did not complete: 0x%08X\n",
83*6150453fSSepherosa Ziehau reg, retval);
84*6150453fSSepherosa Ziehau break;
85*6150453fSSepherosa Ziehau }
86*6150453fSSepherosa Ziehau retval = bus_space_read_4(sc->osdep.mem_bus_space_tag,
87*6150453fSSepherosa Ziehau sc->osdep.mem_bus_space_handle, IXGBE_MAC_SGMII_BUSY);
88*6150453fSSepherosa Ziehau }
89*6150453fSSepherosa Ziehau
90*6150453fSSepherosa Ziehau for (i = 10; retval == 0xDEADBEEF; i--) {
91*6150453fSSepherosa Ziehau if (!i) {
92*6150453fSSepherosa Ziehau device_printf(sc->dev,
93*6150453fSSepherosa Ziehau "Failed to read register 0x%08X.\n", reg);
94*6150453fSSepherosa Ziehau break;
95*6150453fSSepherosa Ziehau }
96*6150453fSSepherosa Ziehau retval = bus_space_read_4(sc->osdep.mem_bus_space_tag,
97*6150453fSSepherosa Ziehau sc->osdep.mem_bus_space_handle, reg);
98*6150453fSSepherosa Ziehau }
99*6150453fSSepherosa Ziehau
100*6150453fSSepherosa Ziehau return retval;
101*6150453fSSepherosa Ziehau }
102*6150453fSSepherosa Ziehau
103*6150453fSSepherosa Ziehau void
ixgbe_write_reg_pf(struct ixgbe_hw * hw,u32 reg,u32 val)104*6150453fSSepherosa Ziehau ixgbe_write_reg_pf(struct ixgbe_hw *hw, u32 reg, u32 val)
105*6150453fSSepherosa Ziehau {
106*6150453fSSepherosa Ziehau bus_space_write_4(((struct ix_softc *)hw->back)->osdep.mem_bus_space_tag,
107*6150453fSSepherosa Ziehau ((struct ix_softc *)hw->back)->osdep.mem_bus_space_handle,
108*6150453fSSepherosa Ziehau reg, val);
109*6150453fSSepherosa Ziehau }
110*6150453fSSepherosa Ziehau
111*6150453fSSepherosa Ziehau u32
ixgbe_read_reg_array_pf(struct ixgbe_hw * hw,u32 reg,u32 offset)112*6150453fSSepherosa Ziehau ixgbe_read_reg_array_pf(struct ixgbe_hw *hw, u32 reg, u32 offset)
113*6150453fSSepherosa Ziehau {
114*6150453fSSepherosa Ziehau return bus_space_read_4(((struct ix_softc *)hw->back)->osdep.mem_bus_space_tag,
115*6150453fSSepherosa Ziehau ((struct ix_softc *)hw->back)->osdep.mem_bus_space_handle,
116*6150453fSSepherosa Ziehau reg + (offset << 2));
117*6150453fSSepherosa Ziehau }
118*6150453fSSepherosa Ziehau
119*6150453fSSepherosa Ziehau void
ixgbe_write_reg_array_pf(struct ixgbe_hw * hw,u32 reg,u32 offset,u32 val)120*6150453fSSepherosa Ziehau ixgbe_write_reg_array_pf(struct ixgbe_hw *hw, u32 reg, u32 offset, u32 val)
121*6150453fSSepherosa Ziehau {
122*6150453fSSepherosa Ziehau bus_space_write_4(((struct ix_softc *)hw->back)->osdep.mem_bus_space_tag,
123*6150453fSSepherosa Ziehau ((struct ix_softc *)hw->back)->osdep.mem_bus_space_handle,
124*6150453fSSepherosa Ziehau reg + (offset << 2), val);
125*6150453fSSepherosa Ziehau }
126