Home | History | Annotate | Line # | Download | only in ixgbe
ixgbe_netbsd.c revision 1.9.4.4
      1  1.9.4.4   martin /* $NetBSD: ixgbe_netbsd.c,v 1.9.4.4 2021/09/15 16:30:50 martin Exp $ */
      2      1.1   dyoung /*
      3      1.1   dyoung  * Copyright (c) 2011 The NetBSD Foundation, Inc.
      4      1.1   dyoung  * All rights reserved.
      5      1.1   dyoung  *
      6      1.1   dyoung  * This code is derived from software contributed to The NetBSD Foundation
      7      1.1   dyoung  * by Coyote Point Systems, Inc.
      8      1.1   dyoung  *
      9      1.1   dyoung  * Redistribution and use in source and binary forms, with or without
     10      1.1   dyoung  * modification, are permitted provided that the following conditions
     11      1.1   dyoung  * are met:
     12      1.1   dyoung  * 1. Redistributions of source code must retain the above copyright
     13      1.1   dyoung  *    notice, this list of conditions and the following disclaimer.
     14      1.1   dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     15      1.1   dyoung  *    notice, this list of conditions and the following disclaimer in the
     16      1.1   dyoung  *    documentation and/or other materials provided with the distribution.
     17      1.1   dyoung  *
     18      1.1   dyoung  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     19      1.1   dyoung  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     20      1.1   dyoung  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     21      1.1   dyoung  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     22      1.1   dyoung  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23      1.1   dyoung  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24      1.1   dyoung  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     25      1.1   dyoung  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     26      1.1   dyoung  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     27      1.1   dyoung  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28      1.1   dyoung  * POSSIBILITY OF SUCH DAMAGE.
     29      1.1   dyoung  */
     30  1.9.4.4   martin 
     31  1.9.4.4   martin #include <sys/cdefs.h>
     32  1.9.4.4   martin __KERNEL_RCSID(0, "$NetBSD: ixgbe_netbsd.c,v 1.9.4.4 2021/09/15 16:30:50 martin Exp $");
     33  1.9.4.4   martin 
     34      1.1   dyoung #include <sys/param.h>
     35      1.1   dyoung 
     36      1.1   dyoung #include <sys/atomic.h>
     37      1.1   dyoung #include <sys/bus.h>
     38      1.1   dyoung #include <sys/condvar.h>
     39      1.1   dyoung #include <sys/cpu.h>
     40      1.1   dyoung #include <sys/kmem.h>
     41      1.1   dyoung #include <sys/mbuf.h>
     42      1.1   dyoung #include <sys/mutex.h>
     43      1.1   dyoung #include <sys/queue.h>
     44      1.1   dyoung #include <sys/workqueue.h>
     45      1.4  msaitoh #include <dev/pci/pcivar.h>
     46      1.1   dyoung 
     47      1.7  msaitoh #include "ixgbe.h"
     48      1.1   dyoung 
     49      1.1   dyoung void
     50      1.1   dyoung ixgbe_dma_tag_destroy(ixgbe_dma_tag_t *dt)
     51      1.1   dyoung {
     52      1.1   dyoung 	kmem_free(dt, sizeof(*dt));
     53      1.1   dyoung }
     54      1.1   dyoung 
     55      1.1   dyoung int
     56      1.1   dyoung ixgbe_dma_tag_create(bus_dma_tag_t dmat, bus_size_t alignment,
     57      1.1   dyoung     bus_size_t boundary, bus_size_t maxsize, int nsegments,
     58      1.1   dyoung     bus_size_t maxsegsize, int flags, ixgbe_dma_tag_t **dtp)
     59      1.1   dyoung {
     60      1.1   dyoung 	ixgbe_dma_tag_t *dt;
     61      1.1   dyoung 
     62      1.1   dyoung 	*dtp = NULL;
     63      1.1   dyoung 
     64      1.6      chs 	dt = kmem_zalloc(sizeof(*dt), KM_SLEEP);
     65      1.1   dyoung 	dt->dt_dmat = dmat;
     66      1.1   dyoung 	dt->dt_alignment = alignment;
     67      1.1   dyoung 	dt->dt_boundary = boundary;
     68      1.1   dyoung 	dt->dt_maxsize = maxsize;
     69      1.1   dyoung 	dt->dt_nsegments = nsegments;
     70      1.1   dyoung 	dt->dt_maxsegsize = maxsegsize;
     71      1.1   dyoung 	dt->dt_flags = flags;
     72      1.1   dyoung 	*dtp = dt;
     73      1.1   dyoung 
     74      1.1   dyoung 	return 0;
     75      1.1   dyoung }
     76      1.1   dyoung 
     77      1.1   dyoung void
     78      1.1   dyoung ixgbe_dmamap_destroy(ixgbe_dma_tag_t *dt, bus_dmamap_t dmam)
     79      1.1   dyoung {
     80      1.1   dyoung 	bus_dmamap_destroy(dt->dt_dmat, dmam);
     81      1.1   dyoung }
     82      1.1   dyoung 
     83      1.1   dyoung void
     84      1.1   dyoung ixgbe_dmamap_sync(ixgbe_dma_tag_t *dt, bus_dmamap_t dmam, int ops)
     85      1.1   dyoung {
     86  1.9.4.3   martin 	bus_dmamap_sync(dt->dt_dmat, dmam, 0, dt->dt_maxsize, ops);
     87      1.1   dyoung }
     88      1.1   dyoung 
     89      1.1   dyoung void
     90      1.1   dyoung ixgbe_dmamap_unload(ixgbe_dma_tag_t *dt, bus_dmamap_t dmam)
     91      1.1   dyoung {
     92      1.1   dyoung 	bus_dmamap_unload(dt->dt_dmat, dmam);
     93      1.1   dyoung }
     94      1.1   dyoung 
     95      1.1   dyoung int
     96      1.1   dyoung ixgbe_dmamap_create(ixgbe_dma_tag_t *dt, int flags, bus_dmamap_t *dmamp)
     97      1.1   dyoung {
     98      1.1   dyoung 	return bus_dmamap_create(dt->dt_dmat, dt->dt_maxsize, dt->dt_nsegments,
     99      1.1   dyoung 	    dt->dt_maxsegsize, dt->dt_boundary, flags, dmamp);
    100      1.1   dyoung }
    101      1.1   dyoung 
    102  1.9.4.2   martin 
    103      1.1   dyoung struct mbuf *
    104  1.9.4.4   martin ixgbe_getcl(void)
    105      1.1   dyoung {
    106      1.1   dyoung 	struct mbuf *m;
    107      1.1   dyoung 
    108  1.9.4.4   martin 	MGETHDR(m, M_DONTWAIT, MT_DATA);
    109      1.1   dyoung 
    110      1.1   dyoung 	if (m == NULL)
    111      1.1   dyoung 		return NULL;
    112      1.1   dyoung 
    113  1.9.4.4   martin 	MCLGET(m, M_DONTWAIT);
    114      1.1   dyoung 	if ((m->m_flags & M_EXT) == 0) {
    115      1.1   dyoung 		m_freem(m);
    116      1.1   dyoung 		return NULL;
    117      1.1   dyoung 	}
    118      1.1   dyoung 
    119      1.1   dyoung 	return m;
    120      1.1   dyoung }
    121      1.4  msaitoh 
    122      1.4  msaitoh void
    123      1.4  msaitoh ixgbe_pci_enable_busmaster(pci_chipset_tag_t pc, pcitag_t tag)
    124      1.4  msaitoh {
    125      1.4  msaitoh 	pcireg_t	pci_cmd_word;
    126      1.4  msaitoh 
    127      1.4  msaitoh 	pci_cmd_word = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
    128      1.4  msaitoh 	if (!(pci_cmd_word & PCI_COMMAND_MASTER_ENABLE)) {
    129      1.4  msaitoh 		pci_cmd_word |= PCI_COMMAND_MASTER_ENABLE;
    130      1.4  msaitoh 		pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, pci_cmd_word);
    131      1.4  msaitoh 	}
    132      1.4  msaitoh }
    133      1.9  msaitoh 
    134      1.9  msaitoh u_int
    135      1.9  msaitoh atomic_load_acq_uint(volatile u_int *p)
    136      1.9  msaitoh {
    137  1.9.4.4   martin 	return atomic_load_acquire(p);
    138      1.9  msaitoh }
    139