xref: /freebsd/sys/dev/ixgbe/ixgbe_osdep.c (revision 71625ec9)
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 
36a9ca1c79SSean Bruno inline u16
ixgbe_read_pci_cfg(struct ixgbe_hw * hw,u32 reg)37a9ca1c79SSean Bruno ixgbe_read_pci_cfg(struct ixgbe_hw *hw, u32 reg)
38a9ca1c79SSean Bruno {
39b1d5caf3SKevin Bowling 	return pci_read_config(((struct ixgbe_softc *)hw->back)->dev, reg, 2);
40a9ca1c79SSean Bruno }
41a9ca1c79SSean Bruno 
42a9ca1c79SSean Bruno inline void
ixgbe_write_pci_cfg(struct ixgbe_hw * hw,u32 reg,u16 value)43a9ca1c79SSean Bruno ixgbe_write_pci_cfg(struct ixgbe_hw *hw, u32 reg, u16 value)
44a9ca1c79SSean Bruno {
45b1d5caf3SKevin Bowling 	pci_write_config(((struct ixgbe_softc *)hw->back)->dev, reg, value, 2);
46a9ca1c79SSean Bruno }
47a9ca1c79SSean Bruno 
48a9ca1c79SSean Bruno inline u32
ixgbe_read_reg(struct ixgbe_hw * hw,u32 reg)49a9ca1c79SSean Bruno ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
50a9ca1c79SSean Bruno {
51b1d5caf3SKevin Bowling 	return bus_space_read_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
52b1d5caf3SKevin Bowling 	    ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle, reg);
53a9ca1c79SSean Bruno }
54a9ca1c79SSean Bruno 
55a9ca1c79SSean Bruno inline void
ixgbe_write_reg(struct ixgbe_hw * hw,u32 reg,u32 val)56a9ca1c79SSean Bruno ixgbe_write_reg(struct ixgbe_hw *hw, u32 reg, u32 val)
57a9ca1c79SSean Bruno {
58b1d5caf3SKevin Bowling 	bus_space_write_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
59b1d5caf3SKevin Bowling 	    ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle,
60a9ca1c79SSean Bruno 	    reg, val);
61a9ca1c79SSean Bruno }
62a9ca1c79SSean Bruno 
63a9ca1c79SSean Bruno inline u32
ixgbe_read_reg_array(struct ixgbe_hw * hw,u32 reg,u32 offset)64a9ca1c79SSean Bruno ixgbe_read_reg_array(struct ixgbe_hw *hw, u32 reg, u32 offset)
65a9ca1c79SSean Bruno {
66b1d5caf3SKevin Bowling 	return bus_space_read_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
67b1d5caf3SKevin Bowling 	    ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle,
68a9ca1c79SSean Bruno 	    reg + (offset << 2));
69a9ca1c79SSean Bruno }
70a9ca1c79SSean Bruno 
71a9ca1c79SSean Bruno inline void
ixgbe_write_reg_array(struct ixgbe_hw * hw,u32 reg,u32 offset,u32 val)72a9ca1c79SSean Bruno ixgbe_write_reg_array(struct ixgbe_hw *hw, u32 reg, u32 offset, u32 val)
73a9ca1c79SSean Bruno {
74b1d5caf3SKevin Bowling 	bus_space_write_4(((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_tag,
75b1d5caf3SKevin Bowling 	    ((struct ixgbe_softc *)hw->back)->osdep.mem_bus_space_handle,
76a9ca1c79SSean Bruno 	    reg + (offset << 2), val);
77a9ca1c79SSean Bruno }
78a0302c92SPiotr Pietruszewski 
79a0302c92SPiotr Pietruszewski uint64_t
ixgbe_link_speed_to_baudrate(ixgbe_link_speed speed)80a0302c92SPiotr Pietruszewski ixgbe_link_speed_to_baudrate(ixgbe_link_speed speed)
81a0302c92SPiotr Pietruszewski {
82a0302c92SPiotr Pietruszewski 	uint64_t baudrate;
83a0302c92SPiotr Pietruszewski 
84a0302c92SPiotr Pietruszewski 	switch (speed) {
85a0302c92SPiotr Pietruszewski 	case IXGBE_LINK_SPEED_10GB_FULL:
86a0302c92SPiotr Pietruszewski 		baudrate = IF_Gbps(10);
87a0302c92SPiotr Pietruszewski 		break;
88a0302c92SPiotr Pietruszewski 	case IXGBE_LINK_SPEED_5GB_FULL:
89a0302c92SPiotr Pietruszewski 		baudrate = IF_Gbps(5);
90a0302c92SPiotr Pietruszewski 		break;
91a0302c92SPiotr Pietruszewski 	case IXGBE_LINK_SPEED_2_5GB_FULL:
92a0302c92SPiotr Pietruszewski 		baudrate = IF_Mbps(2500);
93a0302c92SPiotr Pietruszewski 		break;
94a0302c92SPiotr Pietruszewski 	case IXGBE_LINK_SPEED_1GB_FULL:
95a0302c92SPiotr Pietruszewski 		baudrate = IF_Gbps(1);
96a0302c92SPiotr Pietruszewski 		break;
97a0302c92SPiotr Pietruszewski 	case IXGBE_LINK_SPEED_100_FULL:
98a0302c92SPiotr Pietruszewski 		baudrate = IF_Mbps(100);
99a0302c92SPiotr Pietruszewski 		break;
100a0302c92SPiotr Pietruszewski 	case IXGBE_LINK_SPEED_10_FULL:
101a0302c92SPiotr Pietruszewski 		baudrate = IF_Mbps(10);
102a0302c92SPiotr Pietruszewski 		break;
103a0302c92SPiotr Pietruszewski 	case IXGBE_LINK_SPEED_UNKNOWN:
104a0302c92SPiotr Pietruszewski 	default:
105a0302c92SPiotr Pietruszewski 		baudrate = 0;
106a0302c92SPiotr Pietruszewski 		break;
107a0302c92SPiotr Pietruszewski 	}
108a0302c92SPiotr Pietruszewski 
109a0302c92SPiotr Pietruszewski 	return baudrate;
110a0302c92SPiotr Pietruszewski }
111