File: /usr/src/linux/drivers/char/rio/list.h

1     /****************************************************************************
2      *******                                                              *******
3      *******                      L I S T                                 *******
4      *******                                                              *******
5      ****************************************************************************
6     
7      Author  : Jeremy Rolls.
8      Date    : 04-Nov-1990
9     
10      *
11      *  (C) 1990 - 2000 Specialix International Ltd., Byfleet, Surrey, UK.
12      *
13      *      This program is free software; you can redistribute it and/or modify
14      *      it under the terms of the GNU General Public License as published by
15      *      the Free Software Foundation; either version 2 of the License, or
16      *      (at your option) any later version.
17      *
18      *      This program is distributed in the hope that it will be useful,
19      *      but WITHOUT ANY WARRANTY; without even the implied warranty of
20      *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21      *      GNU General Public License for more details.
22      *
23      *      You should have received a copy of the GNU General Public License
24      *      along with this program; if not, write to the Free Software
25      *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26     
27      Version : 0.01
28     
29     
30                                 Mods
31      ----------------------------------------------------------------------------
32       Date     By                Description
33      ----------------------------------------------------------------------------
34      ***************************************************************************/
35     
36     #ifndef _list_h
37     #define _list_h 1
38     
39     #ifdef SCCS_LABELS
40     #ifndef lint
41     static char *_rio_list_h_sccs = "@(#)list.h	1.9" ;
42     #endif
43     #endif
44     
45     #define PKT_IN_USE    0x1
46     
47     #ifdef INKERNEL
48     
49     #define ZERO_PTR (ushort) 0x8000
50     #define	CaD	PortP->Caddr
51     
52     /*
53     ** We can add another packet to a transmit queue if the packet pointer pointed
54     ** to by the TxAdd pointer has PKT_IN_USE clear in its address.
55     */
56     
57     #ifndef linux
58     #if defined( MIPS ) && !defined( MIPSEISA )
59     /* May the shoes of the Devil dance on your grave for creating this */
60     #define   can_add_transmit(PacketP,PortP) \
61               (!((uint)(PacketP = (struct PKT *)RIO_PTR(CaD,RINDW(PortP->TxAdd))) \
62               & (PKT_IN_USE<<2)))
63     
64     #elif  defined(MIPSEISA) || defined(nx6000) || \
65            defined(drs6000)  || defined(UWsparc)
66     
67     #define   can_add_transmit(PacketP,PortP) \
68               (!((uint)(PacketP = (struct PKT *)RIO_PTR(CaD,RINDW(PortP->TxAdd))) \
69     	  & PKT_IN_USE))
70     
71     #else
72     #define   can_add_transmit(PacketP,PortP) \
73               (!((uint)(PacketP = (struct PKT *)RIO_PTR(CaD,*PortP->TxAdd)) \
74     	  & PKT_IN_USE))
75     #endif
76     
77     /*
78     ** To add a packet to the queue, you set the PKT_IN_USE bit in the address,
79     ** and then move the TxAdd pointer along one position to point to the next
80     ** packet pointer. You must wrap the pointer from the end back to the start.
81     */
82     #if defined(MIPS) || defined(nx6000) || defined(drs6000) || defined(UWsparc)
83     #   define add_transmit(PortP)  \
84     	WINDW(PortP->TxAdd,RINDW(PortP->TxAdd) | PKT_IN_USE);\
85     	if (PortP->TxAdd == PortP->TxEnd)\
86     	    PortP->TxAdd = PortP->TxStart;\
87     	else\
88     	    PortP->TxAdd++;\
89     	WWORD(PortP->PhbP->tx_add , RIO_OFF(CaD,PortP->TxAdd));
90     #elif defined(AIX)
91     #   define add_transmit(PortP)  \
92     	{\
93     	    register ushort *TxAddP = (ushort *)RIO_PTR(Cad,PortP->TxAddO);\
94     	    WINDW( TxAddP, RINDW( TxAddP ) | PKT_IN_USE );\
95     	    if (PortP->TxAddO == PortP->TxEndO )\
96     		PortP->TxAddO = PortP->TxStartO;\
97     	    else\
98     		PortP->TxAddO += sizeof(ushort);\
99     	    WWORD(((PHB *)RIO_PTR(Cad,PortP->PhbO))->tx_add , PortP->TxAddO );\
100     	}
101     #else
102     #   define add_transmit(PortP)  \
103     	*PortP->TxAdd |= PKT_IN_USE;\
104     	if (PortP->TxAdd == PortP->TxEnd)\
105     	    PortP->TxAdd = PortP->TxStart;\
106     	else\
107     	    PortP->TxAdd++;\
108     	PortP->PhbP->tx_add = RIO_OFF(CaD,PortP->TxAdd);
109     #endif
110     
111     /*
112     ** can_remove_receive( PacketP, PortP ) returns non-zero if PKT_IN_USE is set
113     ** for the next packet on the queue. It will also set PacketP to point to the
114     ** relevent packet, [having cleared the PKT_IN_USE bit]. If PKT_IN_USE is clear,
115     ** then can_remove_receive() returns 0.
116     */
117     #if defined(MIPS) || defined(nx6000) || defined(drs6000) || defined(UWsparc)
118     #   define can_remove_receive(PacketP,PortP) \
119     	((RINDW(PortP->RxRemove) & PKT_IN_USE) ? \
120     	(PacketP=(struct PKT *)RIO_PTR(CaD,(RINDW(PortP->RxRemove) & ~PKT_IN_USE))):0)
121     #elif defined(AIX)
122     #   define can_remove_receive(PacketP,PortP) \
123     	((RINDW((ushort *)RIO_PTR(Cad,PortP->RxRemoveO)) & PKT_IN_USE) ? \
124     	(PacketP=(struct PKT *)RIO_PTR(Cad,RINDW((ushort *)RIO_PTR(Cad,PortP->RxRemoveO)) & ~PKT_IN_USE)):0)
125     #else
126     #   define can_remove_receive(PacketP,PortP) \
127     	((*PortP->RxRemove & PKT_IN_USE) ? \
128     	(PacketP=(struct PKT *)RIO_PTR(CaD,(*PortP->RxRemove & ~PKT_IN_USE))):0)
129     #endif
130     
131     
132     /*
133     ** Will God see it within his heart to forgive us for this thing that
134     ** we have created? To remove a packet from the receive queue you clear
135     ** its PKT_IN_USE bit, and then bump the pointers. Once the pointers
136     ** get to the end, they must be wrapped back to the start.
137     */
138     #if defined(MIPS) || defined(nx6000) || defined(drs6000) || defined(UWsparc)
139     #   define remove_receive(PortP) \
140     	WINDW(PortP->RxRemove, (RINDW(PortP->RxRemove) & ~PKT_IN_USE));\
141     	if (PortP->RxRemove == PortP->RxEnd)\
142     	    PortP->RxRemove = PortP->RxStart;\
143     	else\
144     	    PortP->RxRemove++;\
145     	WWORD(PortP->PhbP->rx_remove , RIO_OFF(CaD,PortP->RxRemove));
146     #elif defined(AIX)
147     #   define remove_receive(PortP) \
148         {\
149             register ushort *RxRemoveP = (ushort *)RIO_PTR(Cad,PortP->RxRemoveO);\
150             WINDW( RxRemoveP, RINDW( RxRemoveP ) & ~PKT_IN_USE );\
151             if (PortP->RxRemoveO == PortP->RxEndO)\
152                 PortP->RxRemoveO = PortP->RxStartO;\
153             else\
154                 PortP->RxRemoveO += sizeof(ushort);\
155             WWORD(((PHB *)RIO_PTR(Cad,PortP->PhbO))->rx_remove, PortP->RxRemoveO );\
156         }
157     #else
158     #   define remove_receive(PortP) \
159     	*PortP->RxRemove &= ~PKT_IN_USE;\
160     	if (PortP->RxRemove == PortP->RxEnd)\
161     	    PortP->RxRemove = PortP->RxStart;\
162     	else\
163     	    PortP->RxRemove++;\
164     	PortP->PhbP->rx_remove = RIO_OFF(CaD,PortP->RxRemove);
165     #endif
166     #endif
167     
168     
169     #else /* !IN_KERNEL */
170     
171     #define ZERO_PTR NULL
172     
173     
174     #ifdef HOST
175     /* #define can_remove_transmit(pkt,phb) ((((char*)pkt = (*(char**)(phb->tx_remove))-1) || 1)) && (*phb->u3.s2.tx_remove_ptr & PKT_IN_USE))   */
176     #define remove_transmit(phb) *phb->u3.s2.tx_remove_ptr &= ~(ushort)PKT_IN_USE;\
177                                  if (phb->tx_remove == phb->tx_end)\
178                                     phb->tx_remove = phb->tx_start;\
179                                  else\
180                                     phb->tx_remove++;
181     #define can_add_receive(phb) !(*phb->u4.s2.rx_add_ptr & PKT_IN_USE)
182     #define add_receive(pkt,phb) *phb->rx_add = pkt;\
183                                  *phb->u4.s2.rx_add_ptr |= PKT_IN_USE;\
184                                  if (phb->rx_add == phb->rx_end)\
185                                     phb->rx_add = phb->rx_start;\
186                                  else\
187                                     phb->rx_add++;
188     #endif
189     #endif
190     
191     #ifdef RTA
192     #define splx(oldspl)    if ((oldspl) == 0) spl0()
193     #endif
194     
195     #endif /* ifndef _list.h */
196     /*********** end of file ***********/
197