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