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