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