Home | History | Annotate | Line # | Download | only in ic
dwc_gmac_var.h revision 1.8.2.2
      1  1.8.2.2    martin /* $NetBSD: dwc_gmac_var.h,v 1.8.2.2 2020/04/13 08:04:21 martin Exp $ */
      2      1.4  jmcneill 
      3      1.1    martin /*-
      4      1.1    martin  * Copyright (c) 2013, 2014 The NetBSD Foundation, Inc.
      5      1.1    martin  * All rights reserved.
      6      1.1    martin  *
      7      1.1    martin  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1    martin  * by Matt Thomas of 3am Software Foundry and Martin Husemann.
      9      1.1    martin  *
     10      1.1    martin  * Redistribution and use in source and binary forms, with or without
     11      1.1    martin  * modification, are permitted provided that the following conditions
     12      1.1    martin  * are met:
     13      1.1    martin  * 1. Redistributions of source code must retain the above copyright
     14      1.1    martin  *    notice, this list of conditions and the following disclaimer.
     15      1.1    martin  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1    martin  *    notice, this list of conditions and the following disclaimer in the
     17      1.1    martin  *    documentation and/or other materials provided with the distribution.
     18      1.1    martin  *
     19      1.1    martin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20      1.1    martin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21      1.1    martin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22      1.1    martin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23      1.1    martin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24      1.1    martin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25      1.1    martin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26      1.1    martin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27      1.1    martin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28      1.1    martin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29      1.1    martin  * POSSIBILITY OF SUCH DAMAGE.
     30      1.1    martin  */
     31      1.1    martin 
     32  1.8.2.2    martin #ifdef _KERNEL_OPT
     33  1.8.2.2    martin #include "opt_net_mpsafe.h"
     34  1.8.2.2    martin #endif
     35  1.8.2.2    martin 
     36  1.8.2.2    martin /* Use DWCGMAC_MPSAFE inside the front-ends for interrupt handlers.  */
     37  1.8.2.2    martin #ifdef NET_MPSAFE
     38  1.8.2.2    martin #define DWCGMAC_MPSAFE	1
     39  1.8.2.2    martin #endif
     40  1.8.2.2    martin 
     41  1.8.2.2    martin #ifdef DWCGMAC_MPSAFE
     42  1.8.2.2    martin #define DWCGMAC_FDT_INTR_MPSAFE FDT_INTR_MPSAFE
     43  1.8.2.2    martin #else
     44  1.8.2.2    martin #define DWCGMAC_FDT_INTR_MPSAFE 0
     45  1.8.2.2    martin #endif
     46      1.1    martin 
     47      1.1    martin /*
     48      1.1    martin  * We could use 1024 DMA descriptors to fill up an 8k page (each is 16 byte).
     49      1.1    martin  * However, on TX we probably will not need that many, and on RX we allocate
     50      1.1    martin  * a full mbuf cluster for each, so secondary memory consumption will grow
     51      1.1    martin  * rapidly.
     52      1.1    martin  * So currently we waste half a page of dma memory and consume 512k Byte of
     53      1.1    martin  * RAM for mbuf clusters.
     54      1.1    martin  * XXX Maybe fine-tune later, or reconsider unsharing of RX/TX dmamap.
     55      1.1    martin  */
     56      1.1    martin #define		AWGE_RX_RING_COUNT	256
     57      1.1    martin #define		AWGE_TX_RING_COUNT	256
     58      1.1    martin #define		AWGE_TOTAL_RING_COUNT	\
     59      1.1    martin 			(AWGE_RX_RING_COUNT + AWGE_TX_RING_COUNT)
     60      1.1    martin 
     61      1.6  jmcneill #define		AWGE_MAX_PACKET		0x7ff
     62      1.1    martin 
     63  1.8.2.1  christos struct dwc_gmac_dev_dmadesc;
     64      1.1    martin 
     65  1.8.2.1  christos struct dwc_gmac_desc_methods {
     66  1.8.2.1  christos 	void (*tx_init_flags)(struct dwc_gmac_dev_dmadesc *);
     67  1.8.2.1  christos 	void (*tx_set_owned_by_dev)(struct dwc_gmac_dev_dmadesc *);
     68  1.8.2.1  christos 	int  (*tx_is_owned_by_dev)(struct dwc_gmac_dev_dmadesc *);
     69  1.8.2.1  christos 	void (*tx_set_len)(struct dwc_gmac_dev_dmadesc *, int);
     70  1.8.2.1  christos 	void (*tx_set_first_frag)(struct dwc_gmac_dev_dmadesc *);
     71  1.8.2.1  christos 	void (*tx_set_last_frag)(struct dwc_gmac_dev_dmadesc *);
     72  1.8.2.1  christos 
     73  1.8.2.1  christos 	void (*rx_init_flags)(struct dwc_gmac_dev_dmadesc *);
     74  1.8.2.1  christos 	void (*rx_set_owned_by_dev)(struct dwc_gmac_dev_dmadesc *);
     75  1.8.2.1  christos 	int  (*rx_is_owned_by_dev)(struct dwc_gmac_dev_dmadesc *);
     76  1.8.2.1  christos 	void (*rx_set_len)(struct dwc_gmac_dev_dmadesc *, int);
     77  1.8.2.1  christos 	uint32_t  (*rx_get_len)(struct dwc_gmac_dev_dmadesc *);
     78  1.8.2.1  christos 	int  (*rx_has_error)(struct dwc_gmac_dev_dmadesc *);
     79  1.8.2.1  christos };
     80      1.1    martin 
     81      1.1    martin struct dwc_gmac_rx_data {
     82      1.1    martin 	bus_dmamap_t	rd_map;
     83      1.1    martin 	struct mbuf	*rd_m;
     84      1.1    martin };
     85      1.1    martin 
     86      1.1    martin struct dwc_gmac_tx_data {
     87      1.1    martin 	bus_dmamap_t	td_map;
     88      1.1    martin 	bus_dmamap_t	td_active;
     89      1.1    martin 	struct mbuf	*td_m;
     90      1.1    martin };
     91      1.1    martin 
     92      1.1    martin struct dwc_gmac_tx_ring {
     93      1.1    martin 	bus_addr_t			t_physaddr; /* PA of TX ring start */
     94      1.1    martin 	struct dwc_gmac_dev_dmadesc	*t_desc;    /* VA of TX ring start */
     95      1.1    martin 	struct dwc_gmac_tx_data	t_data[AWGE_TX_RING_COUNT];
     96      1.1    martin 	int				t_cur, t_next, t_queued;
     97      1.7     skrll 	kmutex_t			t_mtx;
     98      1.1    martin };
     99      1.1    martin 
    100      1.1    martin struct dwc_gmac_rx_ring {
    101      1.1    martin 	bus_addr_t			r_physaddr; /* PA of RX ring start */
    102      1.1    martin 	struct dwc_gmac_dev_dmadesc	*r_desc;    /* VA of RX ring start */
    103      1.1    martin 	struct dwc_gmac_rx_data	r_data[AWGE_RX_RING_COUNT];
    104      1.1    martin 	int				r_cur, r_next;
    105      1.1    martin 	kmutex_t			r_mtx;
    106      1.1    martin };
    107      1.1    martin 
    108      1.1    martin struct dwc_gmac_softc {
    109      1.1    martin 	device_t sc_dev;
    110      1.1    martin 	bus_space_tag_t sc_bst;
    111      1.1    martin 	bus_space_handle_t sc_bsh;
    112      1.1    martin 	bus_dma_tag_t sc_dmat;
    113      1.8  jmcneill 	uint32_t sc_flags;
    114      1.8  jmcneill #define	DWC_GMAC_FORCE_THRESH_DMA_MODE	0x01	/* force DMA to use threshold mode */
    115      1.1    martin 	struct ethercom sc_ec;
    116      1.1    martin 	struct mii_data sc_mii;
    117      1.1    martin 	kmutex_t sc_mdio_lock;
    118      1.1    martin 	bus_dmamap_t sc_dma_ring_map;		/* common dma memory for RX */
    119      1.1    martin 	bus_dma_segment_t sc_dma_ring_seg;	/* and TX ring */
    120      1.1    martin 	struct dwc_gmac_rx_ring sc_rxq;
    121      1.1    martin 	struct dwc_gmac_tx_ring sc_txq;
    122  1.8.2.1  christos 	const struct dwc_gmac_desc_methods *sc_descm;
    123  1.8.2.2    martin 	u_short sc_if_flags;			/* shadow of ether flags */
    124      1.2    martin 	uint16_t sc_mii_clk;
    125      1.7     skrll 	bool sc_stopping;
    126  1.8.2.2    martin 	krndsource_t rnd_source;
    127      1.7     skrll 	kmutex_t *sc_lock;			/* lock for softc operations */
    128      1.7     skrll 
    129      1.7     skrll 	struct if_percpuq *sc_ipq;		/* softint-based input queues */
    130      1.8  jmcneill 
    131      1.8  jmcneill 	void (*sc_set_speed)(struct dwc_gmac_softc *, int);
    132      1.1    martin };
    133      1.1    martin 
    134  1.8.2.1  christos int dwc_gmac_attach(struct dwc_gmac_softc*, int /*phy_id*/,
    135  1.8.2.1  christos     uint32_t /*mii_clk*/);
    136      1.1    martin int dwc_gmac_intr(struct dwc_gmac_softc*);
    137