xref: /linux/drivers/net/fddi/skfp/h/hwmtm.h (revision e58e871becec2d3b04ed91c0c16fe8deac9c9dfa)
1 /******************************************************************************
2  *
3  *	(C)Copyright 1998,1999 SysKonnect,
4  *	a business unit of Schneider & Koch & Co. Datensysteme GmbH.
5  *
6  *	This program is free software; you can redistribute it and/or modify
7  *	it under the terms of the GNU General Public License as published by
8  *	the Free Software Foundation; either version 2 of the License, or
9  *	(at your option) any later version.
10  *
11  *	The information in this file is provided "AS IS" without warranty.
12  *
13  ******************************************************************************/
14 
15 #ifndef	_HWM_
16 #define	_HWM_
17 
18 #include "mbuf.h"
19 
20 /*
21  * MACRO for DMA synchronization:
22  *	The descriptor 'desc' is flushed for the device 'flag'.
23  *	Devices are the CPU (DDI_DMA_SYNC_FORCPU) and the
24  *	adapter (DDI_DMA_SYNC_FORDEV).
25  *
26  *	'desc'	Pointer to a Rx or Tx descriptor.
27  *	'flag'	Flag for direction (view for CPU or DEVICE) that
28  *		should be synchronized.
29  *
30  *	Empty macros and defines are specified here. The real macro
31  *	is os-specific and should be defined in osdef1st.h.
32  */
33 #ifndef DRV_BUF_FLUSH
34 #define DRV_BUF_FLUSH(desc,flag)
35 #define DDI_DMA_SYNC_FORCPU
36 #define DDI_DMA_SYNC_FORDEV
37 #endif
38 
39 	/*
40 	 * hardware modul dependent receive modes
41 	 */
42 #define	RX_ENABLE_PASS_SMT	21
43 #define	RX_DISABLE_PASS_SMT	22
44 #define	RX_ENABLE_PASS_NSA	23
45 #define	RX_DISABLE_PASS_NSA	24
46 #define	RX_ENABLE_PASS_DB	25
47 #define	RX_DISABLE_PASS_DB	26
48 #define	RX_DISABLE_PASS_ALL	27
49 #define	RX_DISABLE_LLC_PROMISC	28
50 #define	RX_ENABLE_LLC_PROMISC	29
51 
52 
53 #ifndef	DMA_RD
54 #define DMA_RD		1	/* memory -> hw */
55 #endif
56 #ifndef DMA_WR
57 #define DMA_WR		2	/* hw -> memory */
58 #endif
59 #define SMT_BUF		0x80
60 
61 	/*
62 	 * bits of the frame status byte
63 	 */
64 #define EN_IRQ_EOF	0x02	/* get IRQ after end of frame transmission */
65 #define	LOC_TX		0x04	/* send frame to the local SMT */
66 #define LAST_FRAG	0x08	/* last TxD of the frame */
67 #define	FIRST_FRAG	0x10	/* first TxD of the frame */
68 #define	LAN_TX		0x20	/* send frame to network if set */
69 #define RING_DOWN	0x40	/* error: unable to send, ring down */
70 #define OUT_OF_TXD	0x80	/* error: not enough TxDs available */
71 
72 
73 #ifndef NULL
74 #define NULL 		0
75 #endif
76 
77 #define C_INDIC		(1L<<25)
78 #define A_INDIC		(1L<<26)
79 #define	RD_FS_LOCAL	0x80
80 
81 	/*
82 	 * DEBUG FLAGS
83 	 */
84 #define	DEBUG_SMTF	1
85 #define	DEBUG_SMT	2
86 #define	DEBUG_ECM	3
87 #define	DEBUG_RMT	4
88 #define	DEBUG_CFM	5
89 #define	DEBUG_PCM	6
90 #define	DEBUG_SBA	7
91 #define	DEBUG_ESS	8
92 
93 #define	DB_HWM_RX	10
94 #define	DB_HWM_TX	11
95 #define DB_HWM_GEN	12
96 
97 struct s_mbuf_pool {
98 #ifndef	MB_OUTSIDE_SMC
99 	SMbuf		mb[MAX_MBUF] ;		/* mbuf pool */
100 #endif
101 	SMbuf		*mb_start ;		/* points to the first mb */
102 	SMbuf		*mb_free ;		/* free queue */
103 } ;
104 
105 struct hwm_r {
106 	/*
107 	 * hardware modul specific receive variables
108 	 */
109 	u_int			len ;		/* length of the whole frame */
110 	char			*mb_pos ;	/* SMbuf receive position */
111 } ;
112 
113 struct hw_modul {
114 	/*
115 	 * All hardware modul specific variables
116 	 */
117 	struct	s_mbuf_pool	mbuf_pool ;
118 	struct	hwm_r	r ;
119 
120 	union s_fp_descr volatile *descr_p ; /* points to the desriptor area */
121 
122 	u_short pass_SMT ;		/* pass SMT frames */
123 	u_short pass_NSA ;		/* pass all NSA frames */
124 	u_short pass_DB ;		/* pass Direct Beacon Frames */
125 	u_short pass_llc_promisc ;	/* pass all llc frames (default ON) */
126 
127 	SMbuf	*llc_rx_pipe ;		/* points to the first queued llc fr */
128 	SMbuf	*llc_rx_tail ;		/* points to the last queued llc fr */
129 	int	queued_rx_frames ;	/* number of queued frames */
130 
131 	SMbuf	*txd_tx_pipe ;		/* points to first mb in the txd ring */
132 	SMbuf	*txd_tx_tail ;		/* points to last mb in the txd ring */
133 	int	queued_txd_mb ;		/* number of SMT MBufs in txd ring */
134 
135 	int	rx_break ;		/* rev. was breaked because ind. off */
136 	int	leave_isr ;		/* leave fddi_isr immedeately if set */
137 	int	isr_flag ;		/* set, when HWM is entered from isr */
138 	/*
139 	 * variables for the current transmit frame
140 	 */
141 	struct s_smt_tx_queue *tx_p ;	/* pointer to the transmit queue */
142 	u_long	tx_descr ;		/* tx descriptor for FORMAC+ */
143 	int	tx_len ;		/* tx frame length */
144 	SMbuf	*tx_mb ;		/* SMT tx MBuf pointer */
145 	char	*tx_data ;		/* data pointer to the SMT tx Mbuf */
146 
147 	int	detec_count ;		/* counter for out of RxD condition */
148 	u_long	rx_len_error ;		/* rx len FORMAC != sum of fragments */
149 } ;
150 
151 
152 /*
153  * DEBUG structs and macros
154  */
155 
156 #ifdef	DEBUG
157 struct os_debug {
158 	int	hwm_rx ;
159 	int	hwm_tx ;
160 	int	hwm_gen ;
161 } ;
162 #endif
163 
164 #ifdef	DEBUG
165 #ifdef	DEBUG_BRD
166 #define	DB_P	smc->debug
167 #else
168 #define DB_P	debug
169 #endif
170 
171 #define DB_RX(lev, fmt, ...)						\
172 do {									\
173 	if (DB_P.d_os.hwm_rx >= (lev))					\
174 		printf(fmt "\n", ##__VA_ARGS__);			\
175 } while (0)
176 #define DB_TX(lev, fmt, ...)						\
177 do {									\
178 	if (DB_P.d_os.hwm_tx >= (lev))					\
179 		printf(fmt "\n", ##__VA_ARGS__);			\
180 } while (0)
181 #define DB_GEN(lev, fmt, ...)						\
182 do {									\
183 	if (DB_P.d_os.hwm_gen >= (lev))					\
184 		printf(fmt "\n", ##__VA_ARGS__);			\
185 } while (0)
186 #else	/* DEBUG */
187 #define DB_RX(lev, fmt, ...)	no_printk(fmt "\n", ##__VA_ARGS__)
188 #define DB_TX(lev, fmt, ...)	no_printk(fmt "\n", ##__VA_ARGS__)
189 #define DB_GEN(lev, fmt, ...)	no_printk(fmt "\n", ##__VA_ARGS__)
190 #endif	/* DEBUG */
191 
192 #ifndef	SK_BREAK
193 #define	SK_BREAK()
194 #endif
195 
196 
197 /*
198  * HWM Macros
199  */
200 
201 /*
202  *	BEGIN_MANUAL_ENTRY(HWM_GET_TX_PHYS)
203  *	u_long HWM_GET_TX_PHYS(txd)
204  *
205  * function	MACRO		(hardware module, hwmtm.h)
206  *		This macro may be invoked by the OS-specific module to read
207  *		the physical address of the specified TxD.
208  *
209  * para	txd	pointer to the TxD
210  *
211  *	END_MANUAL_ENTRY
212  */
213 #define	HWM_GET_TX_PHYS(txd)		(u_long)AIX_REVERSE((txd)->txd_tbadr)
214 
215 /*
216  *	BEGIN_MANUAL_ENTRY(HWM_GET_TX_LEN)
217  *	int HWM_GET_TX_LEN(txd)
218  *
219  * function	MACRO		(hardware module, hwmtm.h)
220  *		This macro may be invoked by the OS-specific module to read
221  *		the fragment length of the specified TxD
222  *
223  * para	rxd	pointer to the TxD
224  *
225  * return	the length of the fragment in bytes
226  *
227  *	END_MANUAL_ENTRY
228  */
229 #define	HWM_GET_TX_LEN(txd)	((int)AIX_REVERSE((txd)->txd_tbctrl)& RD_LENGTH)
230 
231 /*
232  *	BEGIN_MANUAL_ENTRY(HWM_GET_TX_USED)
233  *	txd *HWM_GET_TX_USED(smc,queue)
234  *
235  * function	MACRO		(hardware module, hwmtm.h)
236  *		This macro may be invoked by the OS-specific module to get the
237  *		number of used TxDs for the queue, specified by the index.
238  *
239  * para	queue	the number of the send queue: Can be specified by
240  *		QUEUE_A0, QUEUE_S or (frame_status & QUEUE_A0)
241  *
242  * return	number of used TxDs for this send queue
243  *
244  *	END_MANUAL_ENTRY
245  */
246 #define	HWM_GET_TX_USED(smc,queue)	(int) (smc)->hw.fp.tx_q[queue].tx_used
247 
248 /*
249  *	BEGIN_MANUAL_ENTRY(HWM_GET_CURR_TXD)
250  *	txd *HWM_GET_CURR_TXD(smc,queue)
251  *
252  * function	MACRO		(hardware module, hwmtm.h)
253  *		This macro may be invoked by the OS-specific module to get the
254  *		pointer to the TxD which points to the current queue put
255  *		position.
256  *
257  * para	queue	the number of the send queue: Can be specified by
258  *		QUEUE_A0, QUEUE_S or (frame_status & QUEUE_A0)
259  *
260  * return	pointer to the current TxD
261  *
262  *	END_MANUAL_ENTRY
263  */
264 #define	HWM_GET_CURR_TXD(smc,queue)	(struct s_smt_fp_txd volatile *)\
265 					(smc)->hw.fp.tx_q[queue].tx_curr_put
266 
267 /*
268  *	BEGIN_MANUAL_ENTRY(HWM_GET_RX_FRAG_LEN)
269  *	int HWM_GET_RX_FRAG_LEN(rxd)
270  *
271  * function	MACRO		(hardware module, hwmtm.h)
272  *		This macro may be invoked by the OS-specific module to read
273  *		the fragment length of the specified RxD
274  *
275  * para	rxd	pointer to the RxD
276  *
277  * return	the length of the fragment in bytes
278  *
279  *	END_MANUAL_ENTRY
280  */
281 #define	HWM_GET_RX_FRAG_LEN(rxd)	((int)AIX_REVERSE((rxd)->rxd_rbctrl)& \
282 				RD_LENGTH)
283 
284 /*
285  *	BEGIN_MANUAL_ENTRY(HWM_GET_RX_PHYS)
286  *	u_long HWM_GET_RX_PHYS(rxd)
287  *
288  * function	MACRO		(hardware module, hwmtm.h)
289  *		This macro may be invoked by the OS-specific module to read
290  *		the physical address of the specified RxD.
291  *
292  * para	rxd	pointer to the RxD
293  *
294  * return	the RxD's physical pointer to the data fragment
295  *
296  *	END_MANUAL_ENTRY
297  */
298 #define	HWM_GET_RX_PHYS(rxd)	(u_long)AIX_REVERSE((rxd)->rxd_rbadr)
299 
300 /*
301  *	BEGIN_MANUAL_ENTRY(HWM_GET_RX_USED)
302  *	int HWM_GET_RX_USED(smc)
303  *
304  * function	MACRO		(hardware module, hwmtm.h)
305  *		This macro may be invoked by the OS-specific module to get
306  *		the count of used RXDs in receive queue 1.
307  *
308  * return	the used RXD count of receive queue 1
309  *
310  * NOTE: Remember, because of an ASIC bug at least one RXD should be unused
311  *	 in the descriptor ring !
312  *
313  *	END_MANUAL_ENTRY
314  */
315 #define	HWM_GET_RX_USED(smc)	((int)(smc)->hw.fp.rx_q[QUEUE_R1].rx_used)
316 
317 /*
318  *	BEGIN_MANUAL_ENTRY(HWM_GET_RX_FREE)
319  *	int HWM_GET_RX_FREE(smc)
320  *
321  * function	MACRO		(hardware module, hwmtm.h)
322  *		This macro may be invoked by the OS-specific module to get
323  *		the rxd_free count of receive queue 1.
324  *
325  * return	the rxd_free count of receive queue 1
326  *
327  *	END_MANUAL_ENTRY
328  */
329 #define	HWM_GET_RX_FREE(smc)	((int)(smc)->hw.fp.rx_q[QUEUE_R1].rx_free-1)
330 
331 /*
332  *	BEGIN_MANUAL_ENTRY(HWM_GET_CURR_RXD)
333  *	rxd *HWM_GET_CURR_RXD(smc)
334  *
335  * function	MACRO		(hardware module, hwmtm.h)
336  *		This macro may be invoked by the OS-specific module to get the
337  *		pointer to the RxD which points to the current queue put
338  *		position.
339  *
340  * return	pointer to the current RxD
341  *
342  *	END_MANUAL_ENTRY
343  */
344 #define	HWM_GET_CURR_RXD(smc)	(struct s_smt_fp_rxd volatile *)\
345 				(smc)->hw.fp.rx_q[QUEUE_R1].rx_curr_put
346 
347 /*
348  *	BEGIN_MANUAL_ENTRY(HWM_RX_CHECK)
349  *	void HWM_RX_CHECK(smc,low_water)
350  *
351  * function	MACRO		(hardware module, hwmtm.h)
352  *		This macro is invoked by the OS-specific before it left the
353  *		function mac_drv_rx_complete. This macro calls mac_drv_fill_rxd
354  *		if the number of used RxDs is equal or lower than the
355  *		the given low water mark.
356  *
357  * para	low_water	low water mark of used RxD's
358  *
359  *	END_MANUAL_ENTRY
360  */
361 #ifndef HWM_NO_FLOW_CTL
362 #define	HWM_RX_CHECK(smc,low_water) {\
363 	if ((low_water) >= (smc)->hw.fp.rx_q[QUEUE_R1].rx_used) {\
364 		mac_drv_fill_rxd(smc) ;\
365 	}\
366 }
367 #else
368 #define	HWM_RX_CHECK(smc,low_water)		mac_drv_fill_rxd(smc)
369 #endif
370 
371 #ifndef	HWM_EBASE
372 #define	HWM_EBASE	500
373 #endif
374 
375 #define	HWM_E0001	HWM_EBASE + 1
376 #define	HWM_E0001_MSG	"HWM: Wrong size of s_rxd_os struct"
377 #define	HWM_E0002	HWM_EBASE + 2
378 #define	HWM_E0002_MSG	"HWM: Wrong size of s_txd_os struct"
379 #define	HWM_E0003	HWM_EBASE + 3
380 #define	HWM_E0003_MSG	"HWM: smt_free_mbuf() called with NULL pointer"
381 #define	HWM_E0004	HWM_EBASE + 4
382 #define	HWM_E0004_MSG	"HWM: Parity error rx queue 1"
383 #define	HWM_E0005	HWM_EBASE + 5
384 #define	HWM_E0005_MSG	"HWM: Encoding error rx queue 1"
385 #define	HWM_E0006	HWM_EBASE + 6
386 #define	HWM_E0006_MSG	"HWM: Encoding error async tx queue"
387 #define	HWM_E0007	HWM_EBASE + 7
388 #define	HWM_E0007_MSG	"HWM: Encoding error sync tx queue"
389 #define	HWM_E0008	HWM_EBASE + 8
390 #define	HWM_E0008_MSG	""
391 #define	HWM_E0009	HWM_EBASE + 9
392 #define	HWM_E0009_MSG	"HWM: Out of RxD condition detected"
393 #define	HWM_E0010	HWM_EBASE + 10
394 #define	HWM_E0010_MSG	"HWM: A protocol layer has tried to send a frame with an invalid frame control"
395 #define HWM_E0011	HWM_EBASE + 11
396 #define HWM_E0011_MSG	"HWM: mac_drv_clear_tx_queue was called although the hardware wasn't stopped"
397 #define HWM_E0012	HWM_EBASE + 12
398 #define HWM_E0012_MSG	"HWM: mac_drv_clear_rx_queue was called although the hardware wasn't stopped"
399 #define HWM_E0013	HWM_EBASE + 13
400 #define HWM_E0013_MSG	"HWM: mac_drv_repair_descr was called although the hardware wasn't stopped"
401 
402 #endif
403