xref: /freebsd/sys/dev/rtwn/pci/rtwn_pci_var.h (revision a8089ea5aee578e08acab2438e82fc9a9ae50ed8)
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  */
21 
22 #ifndef RTWN_PCI_VAR_H
23 #define RTWN_PCI_VAR_H
24 
25 #define RTWN_PCI_RX_LIST_COUNT		256
26 #define RTWN_PCI_TX_LIST_COUNT		256
27 
28 /* sizeof(struct rtwn_rx_stat_common) + R88E_INTR_MSG_LEN */
29 #define	RTWN_PCI_RX_TMP_BUF_SIZE	84
30 
31 struct rtwn_rx_data {
32 	bus_dmamap_t		map;
33 	struct mbuf		*m;
34 	bus_addr_t		paddr;
35 };
36 
37 struct rtwn_rx_ring {
38 	struct rtwn_rx_stat_pci	*desc;
39 	bus_addr_t		paddr;
40 	bus_dma_tag_t		desc_dmat;
41 	bus_dmamap_t		desc_map;
42 	bus_dma_tag_t		data_dmat;
43 	bus_dma_segment_t	seg;
44 	struct rtwn_rx_data	rx_data[RTWN_PCI_RX_LIST_COUNT];
45 	int			cur;
46 };
47 
48 struct rtwn_tx_data {
49 	bus_dmamap_t		map;
50 	struct mbuf		*m;
51 	struct ieee80211_node	*ni;
52 };
53 
54 struct rtwn_tx_ring {
55 	bus_addr_t		paddr;
56 	bus_dma_tag_t		desc_dmat;
57 	bus_dmamap_t		desc_map;
58 	bus_dma_tag_t		data_dmat;
59 	bus_dma_segment_t	seg;
60 	void			*desc;
61 	struct rtwn_tx_data	tx_data[RTWN_PCI_TX_LIST_COUNT];
62 	int			queued;
63 	int			cur;
64 	int			last;
65 };
66 
67 /*
68  * TX queue indices.
69  */
70 enum {
71 	RTWN_PCI_BK_QUEUE,
72 	RTWN_PCI_BE_QUEUE,
73 	RTWN_PCI_VI_QUEUE,
74 	RTWN_PCI_VO_QUEUE,
75 	RTWN_PCI_BEACON_QUEUE,
76 	RTWN_PCI_TXCMD_QUEUE,
77 	RTWN_PCI_MGNT_QUEUE,
78 	RTWN_PCI_HIGH_QUEUE,
79 	RTWN_PCI_HCCA_QUEUE,
80 	RTWN_PCI_NTXQUEUES
81 };
82 
83 /*
84  * Interrupt events.
85  */
86 enum {
87 	RTWN_PCI_INTR_RX_ERROR		= 0x00000001,
88 	RTWN_PCI_INTR_RX_OVERFLOW	= 0x00000002,
89 	RTWN_PCI_INTR_RX_DESC_UNAVAIL	= 0x00000004,
90 	RTWN_PCI_INTR_RX_DONE		= 0x00000008,
91 	RTWN_PCI_INTR_TX_ERROR		= 0x00000010,
92 	RTWN_PCI_INTR_TX_OVERFLOW	= 0x00000020,
93 	RTWN_PCI_INTR_TX_REPORT		= 0x00000040,
94 	RTWN_PCI_INTR_PS_TIMEOUT	= 0x00000080
95 };
96 
97 /* Shortcuts */
98 /* Vendor driver treats RX errors like ROK... */
99 #define RTWN_PCI_INTR_RX \
100 	(RTWN_PCI_INTR_RX_ERROR | RTWN_PCI_INTR_RX_OVERFLOW | \
101 	 RTWN_PCI_INTR_RX_DESC_UNAVAIL | RTWN_PCI_INTR_RX_DONE)
102 
103 struct rtwn_pci_softc {
104 	struct rtwn_softc	pc_sc;		/* must be the first */
105 
106 	struct resource		*irq;
107 	struct resource		*mem;
108 	bus_space_tag_t		pc_st;
109 	bus_space_handle_t	pc_sh;
110 	void			*pc_ih;
111 	bus_size_t		pc_mapsize;
112 
113 	uint8_t			pc_rx_buf[RTWN_PCI_RX_TMP_BUF_SIZE];
114 	struct rtwn_rx_ring	rx_ring;
115 	struct rtwn_tx_ring	tx_ring[RTWN_PCI_NTXQUEUES];
116 
117 	/* must be set by the driver. */
118 	uint16_t		pc_qmap;
119 	uint32_t		tcr;
120 
121 	void			(*pc_setup_tx_desc)(struct rtwn_pci_softc *,
122 				    void *, uint32_t);
123 	void			(*pc_tx_postsetup)(struct rtwn_pci_softc *,
124 				    void *, bus_dma_segment_t *);
125 	void			(*pc_copy_tx_desc)(void *, const void *);
126 	void			(*pc_enable_intr)(struct rtwn_pci_softc *);
127 	int			(*pc_get_intr_status)(struct rtwn_pci_softc *,
128 				    int *);
129 };
130 #define RTWN_PCI_SOFTC(sc)	((struct rtwn_pci_softc *)(sc))
131 
132 #define rtwn_pci_setup_tx_desc(_pc, _desc, _addr) \
133 	(((_pc)->pc_setup_tx_desc)((_pc), (_desc), (_addr)))
134 #define rtwn_pci_tx_postsetup(_pc, _txd, _segs) \
135 	(((_pc)->pc_tx_postsetup)((_pc), (_txd), (_segs)))
136 #define rtwn_pci_copy_tx_desc(_pc, _dest, _src) \
137 	(((_pc)->pc_copy_tx_desc)((_dest), (_src)))
138 #define rtwn_pci_enable_intr(_pc) \
139 	(((_pc)->pc_enable_intr)((_pc)))
140 #define rtwn_pci_get_intr_status(_pc, _tx_rings) \
141 	(((_pc)->pc_get_intr_status)((_pc), (_tx_rings)))
142 
143 #endif	/* RTWN_PCI_VAR_H */
144