xref: /freebsd/sys/dev/rtwn/pci/rtwn_pci_var.h (revision 180f822596ecc49d3074dcc9dfea9628aae1d48d)
1 /*	$OpenBSD: if_rtwnreg.h,v 1.3 2015/06/14 08:02:47 stsp Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2015 Stefan Sperling <stsp@openbsd.org>
6  * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  *
20  * $FreeBSD$
21  */
22 
23 #ifndef RTWN_PCI_VAR_H
24 #define RTWN_PCI_VAR_H
25 
26 #define RTWN_PCI_RX_LIST_COUNT		256
27 #define RTWN_PCI_TX_LIST_COUNT		256
28 
29 /* sizeof(struct rtwn_rx_stat_common) + R88E_INTR_MSG_LEN */
30 #define	RTWN_PCI_RX_TMP_BUF_SIZE	84
31 
32 struct rtwn_rx_data {
33 	bus_dmamap_t		map;
34 	struct mbuf		*m;
35 	bus_addr_t		paddr;
36 };
37 
38 struct rtwn_rx_ring {
39 	struct rtwn_rx_stat_pci	*desc;
40 	bus_addr_t		paddr;
41 	bus_dma_tag_t		desc_dmat;
42 	bus_dmamap_t		desc_map;
43 	bus_dma_tag_t		data_dmat;
44 	bus_dma_segment_t	seg;
45 	struct rtwn_rx_data	rx_data[RTWN_PCI_RX_LIST_COUNT];
46 	int			cur;
47 };
48 
49 struct rtwn_tx_data {
50 	bus_dmamap_t		map;
51 	struct mbuf		*m;
52 	struct ieee80211_node	*ni;
53 };
54 
55 struct rtwn_tx_ring {
56 	bus_addr_t		paddr;
57 	bus_dma_tag_t		desc_dmat;
58 	bus_dmamap_t		desc_map;
59 	bus_dma_tag_t		data_dmat;
60 	bus_dma_segment_t	seg;
61 	void			*desc;
62 	struct rtwn_tx_data	tx_data[RTWN_PCI_TX_LIST_COUNT];
63 	int			queued;
64 	int			cur;
65 	int			last;
66 };
67 
68 /*
69  * TX queue indices.
70  */
71 enum {
72 	RTWN_PCI_BK_QUEUE,
73 	RTWN_PCI_BE_QUEUE,
74 	RTWN_PCI_VI_QUEUE,
75 	RTWN_PCI_VO_QUEUE,
76 	RTWN_PCI_BEACON_QUEUE,
77 	RTWN_PCI_TXCMD_QUEUE,
78 	RTWN_PCI_MGNT_QUEUE,
79 	RTWN_PCI_HIGH_QUEUE,
80 	RTWN_PCI_HCCA_QUEUE,
81 	RTWN_PCI_NTXQUEUES
82 };
83 
84 /*
85  * Interrupt events.
86  */
87 enum {
88 	RTWN_PCI_INTR_RX_ERROR		= 0x00000001,
89 	RTWN_PCI_INTR_RX_OVERFLOW	= 0x00000002,
90 	RTWN_PCI_INTR_RX_DESC_UNAVAIL	= 0x00000004,
91 	RTWN_PCI_INTR_RX_DONE		= 0x00000008,
92 	RTWN_PCI_INTR_TX_ERROR		= 0x00000010,
93 	RTWN_PCI_INTR_TX_OVERFLOW	= 0x00000020,
94 	RTWN_PCI_INTR_TX_REPORT		= 0x00000040,
95 	RTWN_PCI_INTR_PS_TIMEOUT	= 0x00000080
96 };
97 
98 /* Shortcuts */
99 /* Vendor driver treats RX errors like ROK... */
100 #define RTWN_PCI_INTR_RX \
101 	(RTWN_PCI_INTR_RX_ERROR | RTWN_PCI_INTR_RX_OVERFLOW | \
102 	 RTWN_PCI_INTR_RX_DESC_UNAVAIL | RTWN_PCI_INTR_RX_DONE)
103 
104 struct rtwn_pci_softc {
105 	struct rtwn_softc	pc_sc;		/* must be the first */
106 
107 	struct resource		*irq;
108 	struct resource		*mem;
109 	bus_space_tag_t		pc_st;
110 	bus_space_handle_t	pc_sh;
111 	void			*pc_ih;
112 	bus_size_t		pc_mapsize;
113 
114 	uint8_t			pc_rx_buf[RTWN_PCI_RX_TMP_BUF_SIZE];
115 	struct rtwn_rx_ring	rx_ring;
116 	struct rtwn_tx_ring	tx_ring[RTWN_PCI_NTXQUEUES];
117 
118 	/* must be set by the driver. */
119 	uint16_t		pc_qmap;
120 	uint32_t		tcr;
121 
122 	void			(*pc_setup_tx_desc)(struct rtwn_pci_softc *,
123 				    void *, uint32_t);
124 	void			(*pc_tx_postsetup)(struct rtwn_pci_softc *,
125 				    void *, bus_dma_segment_t *);
126 	void			(*pc_copy_tx_desc)(void *, const void *);
127 	void			(*pc_enable_intr)(struct rtwn_pci_softc *);
128 	int			(*pc_get_intr_status)(struct rtwn_pci_softc *,
129 				    int *);
130 };
131 #define RTWN_PCI_SOFTC(sc)	((struct rtwn_pci_softc *)(sc))
132 
133 #define rtwn_pci_setup_tx_desc(_pc, _desc, _addr) \
134 	(((_pc)->pc_setup_tx_desc)((_pc), (_desc), (_addr)))
135 #define rtwn_pci_tx_postsetup(_pc, _txd, _segs) \
136 	(((_pc)->pc_tx_postsetup)((_pc), (_txd), (_segs)))
137 #define rtwn_pci_copy_tx_desc(_pc, _dest, _src) \
138 	(((_pc)->pc_copy_tx_desc)((_dest), (_src)))
139 #define rtwn_pci_enable_intr(_pc) \
140 	(((_pc)->pc_enable_intr)((_pc)))
141 #define rtwn_pci_get_intr_status(_pc, _tx_rings) \
142 	(((_pc)->pc_get_intr_status)((_pc), (_tx_rings)))
143 
144 #endif	/* RTWN_PCI_VAR_H */
145