2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008 Nathan Whitehorn
5 * Copyright (c) 2003 Peter Grehan
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Number of transmit/receive DBDMA descriptors.
34 * XXX allow override with a tuneable ?
36 #define BM_MAX_DMA_COMMANDS 256
39 #define BM_MAX_TX_PACKETS 100
40 #define BM_MAX_RX_PACKETS 100
45 #define BM_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx)
46 #define BM_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx)
49 * software state for transmit job mbufs (may be elements of mbuf chains)
52 struct mbuf *txs_mbuf; /* head of our mbuf chain */
53 bus_dmamap_t txs_dmamap; /* our DMA map */
54 int txs_firstdesc; /* first descriptor in packet */
55 int txs_lastdesc; /* last descriptor in packet */
56 int txs_stopdesc; /* the location of the closing STOP */
58 int txs_ndescs; /* number of descriptors */
59 STAILQ_ENTRY(bm_txsoft) txs_q;
62 STAILQ_HEAD(bm_txsq, bm_txsoft);
65 * software state for receive jobs
68 struct mbuf *rxs_mbuf; /* head of our mbuf chain */
69 bus_dmamap_t rxs_dmamap; /* our DMA map */
72 bus_dma_segment_t segment;
78 u_char sc_enaddr[ETHER_ADDR_LEN];
85 struct callout sc_tick_ch;
87 device_t sc_dev; /* back ptr to dev */
88 struct resource *sc_memr; /* macio bus mem resource */
92 struct mii_data *sc_mii;
94 struct resource *sc_txdmar, *sc_rxdmar;
95 int sc_txdmarid, sc_rxdmarid;
97 struct resource *sc_txdmairq, *sc_rxdmairq;
98 void *sc_txihtx, *sc_rxih;
99 int sc_txdmairqid, sc_rxdmairqid;
101 bus_dma_tag_t sc_pdma_tag;
103 bus_dma_tag_t sc_tdma_tag;
104 struct bm_txsoft sc_txsoft[BM_MAX_TX_PACKETS];
105 int first_used_txdma_slot, next_txdma_slot;
107 struct bm_txsq sc_txfreeq;
108 struct bm_txsq sc_txdirtyq;
110 bus_dma_tag_t sc_rdma_tag;
111 struct bm_rxsoft sc_rxsoft[BM_MAX_TX_PACKETS];
112 int next_rxdma_slot, rxdma_loop_slot;
114 dbdma_channel_t *sc_txdma, *sc_rxdma;