1a9ca1c79SSean Bruno /******************************************************************************
2a9ca1c79SSean Bruno
38455e365SKevin Bowling Copyright (c) 2001-2020, Intel Corporation
4a9ca1c79SSean Bruno All rights reserved.
5a9ca1c79SSean Bruno
6a9ca1c79SSean Bruno Redistribution and use in source and binary forms, with or without
7a9ca1c79SSean Bruno modification, are permitted provided that the following conditions are met:
8a9ca1c79SSean Bruno
9a9ca1c79SSean Bruno 1. Redistributions of source code must retain the above copyright notice,
10a9ca1c79SSean Bruno this list of conditions and the following disclaimer.
11a9ca1c79SSean Bruno
12a9ca1c79SSean Bruno 2. Redistributions in binary form must reproduce the above copyright
13a9ca1c79SSean Bruno notice, this list of conditions and the following disclaimer in the
14a9ca1c79SSean Bruno documentation and/or other materials provided with the distribution.
15a9ca1c79SSean Bruno
16a9ca1c79SSean Bruno 3. Neither the name of the Intel Corporation nor the names of its
17a9ca1c79SSean Bruno contributors may be used to endorse or promote products derived from
18a9ca1c79SSean Bruno this software without specific prior written permission.
19a9ca1c79SSean Bruno
20a9ca1c79SSean Bruno THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21a9ca1c79SSean Bruno AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22a9ca1c79SSean Bruno IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23a9ca1c79SSean Bruno ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24a9ca1c79SSean Bruno LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25a9ca1c79SSean Bruno CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26a9ca1c79SSean Bruno SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27a9ca1c79SSean Bruno INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28a9ca1c79SSean Bruno CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29a9ca1c79SSean Bruno ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30a9ca1c79SSean Bruno POSSIBILITY OF SUCH DAMAGE.
31a9ca1c79SSean Bruno
32a9ca1c79SSean Bruno ******************************************************************************/
33a9ca1c79SSean Bruno
34a9ca1c79SSean Bruno #include "ixgbe.h"
35a9ca1c79SSean Bruno
36*bf6f0db8SKevin Bowling inline device_t
ixgbe_dev_from_hw(struct ixgbe_hw * hw)37*bf6f0db8SKevin Bowling ixgbe_dev_from_hw(struct ixgbe_hw *hw)
38*bf6f0db8SKevin Bowling {
39*bf6f0db8SKevin Bowling return ((struct ixgbe_softc *)hw->back)->dev;
40*bf6f0db8SKevin Bowling }
41*bf6f0db8SKevin Bowling
42a9ca1c79SSean Bruno inline u16
ixgbe_read_pci_cfg(struct ixgbe_hw * hw,u32 reg)43a9ca1c79SSean Bruno ixgbe_read_pci_cfg(struct ixgbe_hw *hw, u32 reg)
44a9ca1c79SSean Bruno {
45b1d5caf3SKevin Bowling return pci_read_config(((struct ixgbe_softc *)hw->back)->dev, reg, 2);
46a9ca1c79SSean Bruno }
47a9ca1c79SSean Bruno
48a9ca1c79SSean Bruno inline void
ixgbe_write_pci_cfg(struct ixgbe_hw * hw,u32 reg,u16 value)49a9ca1c79SSean Bruno ixgbe_write_pci_cfg(struct ixgbe_hw *hw, u32 reg, u16 value)
50a9ca1c79SSean Bruno {
51b1d5caf3SKevin Bowling pci_write_config(((struct ixgbe_softc *)hw->back)->dev, reg, value, 2);
52a9ca1c79SSean Bruno }
53a9ca1c79SSean Bruno
54a9ca1c79SSean Bruno inline u32
ixgbe_read_reg(struct ixgbe_hw * hw,u32 reg)55a9ca1c79SSean Bruno ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
56a9ca1c79SSean Bruno {
57b1d5caf3SKevin Bowling return bus_space_read_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
58b1d5caf3SKevin Bowling ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle, reg);
59a9ca1c79SSean Bruno }
60a9ca1c79SSean Bruno
61a9ca1c79SSean Bruno inline void
ixgbe_write_reg(struct ixgbe_hw * hw,u32 reg,u32 val)62a9ca1c79SSean Bruno ixgbe_write_reg(struct ixgbe_hw *hw, u32 reg, u32 val)
63a9ca1c79SSean Bruno {
64b1d5caf3SKevin Bowling bus_space_write_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
65b1d5caf3SKevin Bowling ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle,
66a9ca1c79SSean Bruno reg, val);
67a9ca1c79SSean Bruno }
68a9ca1c79SSean Bruno
69a9ca1c79SSean Bruno inline u32
ixgbe_read_reg_array(struct ixgbe_hw * hw,u32 reg,u32 offset)70a9ca1c79SSean Bruno ixgbe_read_reg_array(struct ixgbe_hw *hw, u32 reg, u32 offset)
71a9ca1c79SSean Bruno {
72b1d5caf3SKevin Bowling return bus_space_read_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
73b1d5caf3SKevin Bowling ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle,
74a9ca1c79SSean Bruno reg + (offset << 2));
75a9ca1c79SSean Bruno }
76a9ca1c79SSean Bruno
77a9ca1c79SSean Bruno inline void
ixgbe_write_reg_array(struct ixgbe_hw * hw,u32 reg,u32 offset,u32 val)78a9ca1c79SSean Bruno ixgbe_write_reg_array(struct ixgbe_hw *hw, u32 reg, u32 offset, u32 val)
79a9ca1c79SSean Bruno {
80b1d5caf3SKevin Bowling bus_space_write_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
81b1d5caf3SKevin Bowling ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle,
82a9ca1c79SSean Bruno reg + (offset << 2), val);
83a9ca1c79SSean Bruno }
84a0302c92SPiotr Pietruszewski
85a0302c92SPiotr Pietruszewski uint64_t
ixgbe_link_speed_to_baudrate(ixgbe_link_speed speed)86a0302c92SPiotr Pietruszewski ixgbe_link_speed_to_baudrate(ixgbe_link_speed speed)
87a0302c92SPiotr Pietruszewski {
88a0302c92SPiotr Pietruszewski uint64_t baudrate;
89a0302c92SPiotr Pietruszewski
90a0302c92SPiotr Pietruszewski switch (speed) {
91a0302c92SPiotr Pietruszewski case IXGBE_LINK_SPEED_10GB_FULL:
92a0302c92SPiotr Pietruszewski baudrate = IF_Gbps(10);
93a0302c92SPiotr Pietruszewski break;
94a0302c92SPiotr Pietruszewski case IXGBE_LINK_SPEED_5GB_FULL:
95a0302c92SPiotr Pietruszewski baudrate = IF_Gbps(5);
96a0302c92SPiotr Pietruszewski break;
97a0302c92SPiotr Pietruszewski case IXGBE_LINK_SPEED_2_5GB_FULL:
98a0302c92SPiotr Pietruszewski baudrate = IF_Mbps(2500);
99a0302c92SPiotr Pietruszewski break;
100a0302c92SPiotr Pietruszewski case IXGBE_LINK_SPEED_1GB_FULL:
101a0302c92SPiotr Pietruszewski baudrate = IF_Gbps(1);
102a0302c92SPiotr Pietruszewski break;
103a0302c92SPiotr Pietruszewski case IXGBE_LINK_SPEED_100_FULL:
104a0302c92SPiotr Pietruszewski baudrate = IF_Mbps(100);
105a0302c92SPiotr Pietruszewski break;
106a0302c92SPiotr Pietruszewski case IXGBE_LINK_SPEED_10_FULL:
107a0302c92SPiotr Pietruszewski baudrate = IF_Mbps(10);
108a0302c92SPiotr Pietruszewski break;
109a0302c92SPiotr Pietruszewski case IXGBE_LINK_SPEED_UNKNOWN:
110a0302c92SPiotr Pietruszewski default:
111a0302c92SPiotr Pietruszewski baudrate = 0;
112a0302c92SPiotr Pietruszewski break;
113a0302c92SPiotr Pietruszewski }
114a0302c92SPiotr Pietruszewski
115a0302c92SPiotr Pietruszewski return baudrate;
116a0302c92SPiotr Pietruszewski }
117