aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/rio/list.h
blob: 36aad4c9cb3a2539f85074873ca480c921f67262 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/****************************************************************************
 *******                                                              *******
 *******                      L I S T                                 *******
 *******                                                              *******
 ****************************************************************************

 Author  : Jeremy Rolls.
 Date    : 04-Nov-1990

 *
 *  (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

 Version : 0.01


                            Mods
 ----------------------------------------------------------------------------
  Date     By                Description
 ----------------------------------------------------------------------------
 ***************************************************************************/

#ifndef _list_h
#define _list_h 1

#ifdef SCCS_LABELS
#ifndef lint
static char *_rio_list_h_sccs = "@(#)list.h	1.9";
#endif
#endif

#define PKT_IN_USE    0x1

#ifdef INKERNEL

#define ZERO_PTR (ushort) 0x8000
#define	CaD	PortP->Caddr

/*
** We can add another packet to a transmit queue if the packet pointer pointed
** to by the TxAdd pointer has PKT_IN_USE clear in its address.
*/

#ifndef linux
#if defined( MIPS ) && !defined( MIPSEISA )
/* May the shoes of the Devil dance on your grave for creating this */
#define   can_add_transmit(PacketP,PortP) \
          (!((uint)(PacketP = (struct PKT *)RIO_PTR(CaD,RINDW(PortP->TxAdd))) \
          & (PKT_IN_USE<<2)))

#elif  defined(MIPSEISA) || defined(nx6000) || \
       defined(drs6000)  || defined(UWsparc)

#define   can_add_transmit(PacketP,PortP) \
          (!((uint)(PacketP = (struct PKT *)RIO_PTR(CaD,RINDW(PortP->TxAdd))) \
	  & PKT_IN_USE))

#else
#define   can_add_transmit(PacketP,PortP) \
          (!((uint)(PacketP = (struct PKT *)RIO_PTR(CaD,*PortP->TxAdd)) \
	  & PKT_IN_USE))
#endif

/*
** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
** and then move the TxAdd pointer along one position to point to the next
** packet pointer. You must wrap the pointer from the end back to the start.
*/
#if defined(MIPS) || defined(nx6000) || defined(drs6000) || defined(UWsparc)
#   define add_transmit(PortP)  \
	WINDW(PortP->TxAdd,RINDW(PortP->TxAdd) | PKT_IN_USE);\
	if (PortP->TxAdd == PortP->TxEnd)\
	    PortP->TxAdd = PortP->TxStart;\
	else\
	    PortP->TxAdd++;\
	WWORD(PortP->PhbP->tx_add , RIO_OFF(CaD,PortP->TxAdd));
#elif defined(AIX)
#   define add_transmit(PortP)  \
	{\
	    register ushort *TxAddP = (ushort *)RIO_PTR(Cad,PortP->TxAddO);\
	    WINDW( TxAddP, RINDW( TxAddP ) | PKT_IN_USE );\
	    if (PortP->TxAddO == PortP->TxEndO )\
		PortP->TxAddO = PortP->TxStartO;\
	    else\
		PortP->TxAddO += sizeof(ushort);\
	    WWORD(((PHB *)RIO_PTR(Cad,PortP->PhbO))->tx_add , PortP->TxAddO );\
	}
#else
#   define add_transmit(PortP)  \
	*PortP->TxAdd |= PKT_IN_USE;\
	if (PortP->TxAdd == PortP->TxEnd)\
	    PortP->TxAdd = PortP->TxStart;\
	else\
	    PortP->TxAdd++;\
	PortP->PhbP->tx_add = RIO_OFF(CaD,PortP->TxAdd);
#endif

/*
** can_remove_receive( PacketP, PortP ) returns non-zero if PKT_IN_USE is set
** for the next packet on the queue. It will also set PacketP to point to the
** relevant packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
** then can_remove_receive() returns 0.
*/
#if defined(MIPS) || defined(nx6000) || defined(drs6000) || defined(UWsparc)
#   define can_remove_receive(PacketP,PortP) \
	((RINDW(PortP->RxRemove) & PKT_IN_USE) ? \
	(PacketP=(struct PKT *)RIO_PTR(CaD,(RINDW(PortP->RxRemove) & ~PKT_IN_USE))):0)
#elif defined(AIX)
#   define can_remove_receive(PacketP,PortP) \
	((RINDW((ushort *)RIO_PTR(Cad,PortP->RxRemoveO)) & PKT_IN_USE) ? \
	(PacketP=(struct PKT *)RIO_PTR(Cad,RINDW((ushort *)RIO_PTR(Cad,PortP->RxRemoveO)) & ~PKT_IN_USE)):0)
#else
#   define can_remove_receive(PacketP,PortP) \
	((*PortP->RxRemove & PKT_IN_USE) ? \
	(PacketP=(struct PKT *)RIO_PTR(CaD,(*PortP->RxRemove & ~PKT_IN_USE))):0)
#endif


/*
** Will God see it within his heart to forgive us for this thing that
** we have created? To remove a packet from the receive queue you clear
** its PKT_IN_USE bit, and then bump the pointers. Once the pointers
** get to the end, they must be wrapped back to the start.
*/
#if defined(MIPS) || defined(nx6000) || defined(drs6000) || defined(UWsparc)
#   define remove_receive(PortP) \
	WINDW(PortP->RxRemove, (RINDW(PortP->RxRemove) & ~PKT_IN_USE));\
	if (PortP->RxRemove == PortP->RxEnd)\
	    PortP->RxRemove = PortP->RxStart;\
	else\
	    PortP->RxRemove++;\
	WWORD(PortP->PhbP->rx_remove , RIO_OFF(CaD,PortP->RxRemove));
#elif defined(AIX)
#   define remove_receive(PortP) \
    {\
        register ushort *RxRemoveP = (ushort *)RIO_PTR(Cad,PortP->RxRemoveO);\
        WINDW( RxRemoveP, RINDW( RxRemoveP ) & ~PKT_IN_USE );\
        if (PortP->RxRemoveO == PortP->RxEndO)\
            PortP->RxRemoveO = PortP->RxStartO;\
        else\
            PortP->RxRemoveO += sizeof(ushort);\
        WWORD(((PHB *)RIO_PTR(Cad,PortP->PhbO))->rx_remove, PortP->RxRemoveO );\
    }
#else
#   define remove_receive(PortP) \
	*PortP->RxRemove &= ~PKT_IN_USE;\
	if (PortP->RxRemove == PortP->RxEnd)\
	    PortP->RxRemove = PortP->RxStart;\
	else\
	    PortP->RxRemove++;\
	PortP->PhbP->rx_remove = RIO_OFF(CaD,PortP->RxRemove);
#endif
#endif


#else				/* !IN_KERNEL */

#define ZERO_PTR NULL


#ifdef HOST
/* #define can_remove_transmit(pkt,phb) ((((char*)pkt = (*(char**)(phb->tx_remove))-1) || 1)) && (*phb->u3.s2.tx_remove_ptr & PKT_IN_USE))   */
#define remove_transmit(phb) *phb->u3.s2.tx_remove_ptr &= ~(ushort)PKT_IN_USE;\
                             if (phb->tx_remove == phb->tx_end)\
                                phb->tx_remove = phb->tx_start;\
                             else\
                                phb->tx_remove++;
#define can_add_receive(phb) !(*phb->u4.s2.rx_add_ptr & PKT_IN_USE)
#define add_receive(pkt,phb) *phb->rx_add = pkt;\
                             *phb->u4.s2.rx_add_ptr |= PKT_IN_USE;\
                             if (phb->rx_add == phb->rx_end)\
                                phb->rx_add = phb->rx_start;\
                             else\
                                phb->rx_add++;
#endif
#endif

#ifdef RTA
#define splx(oldspl)    if ((oldspl) == 0) spl0()
#endif

#endif				/* ifndef _list.h */
/*********** end of file ***********/