cleanup
[linux-2.4.21-pre4.git] / drivers / net / tokenring / lanstreamer.h
1 /*
2  *   lanstreamer.h -- driver for the IBM Auto LANStreamer PCI Adapter
3  *
4  *  Written By: Mike Sullivan, IBM Corporation
5  *
6  *  Copyright (C) 1999 IBM Corporation
7  *
8  *  Linux driver for IBM PCI tokenring cards based on the LanStreamer MPC
9  *  chipset. 
10  *
11  *  This driver is based on the olympic driver for IBM PCI TokenRing cards (Pit/Pit-Phy/Olympic
12  *  chipsets) written  by:
13  *      1999 Peter De Schrijver All Rights Reserved
14  *      1999 Mike Phillips (phillim@amtrak.com)
15  *
16  *  Base Driver Skeleton:
17  *      Written 1993-94 by Donald Becker.
18  *
19  *      Copyright 1993 United States Government as represented by the
20  *      Director, National Security Agency.
21  *
22  * This program is free software; you can redistribute it and/or modify      
23  * it under the terms of the GNU General Public License as published by      
24  * the Free Software Foundation; either version 2 of the License, or         
25  * (at your option) any later version.                                       
26  *                                                                           
27  * This program is distributed in the hope that it will be useful,           
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of            
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             
30  * GNU General Public License for more details.                              
31  *                                                                           
32  * NO WARRANTY                                                               
33  * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR        
34  * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT      
35  * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,      
36  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is    
37  * solely responsible for determining the appropriateness of using and       
38  * distributing the Program and assumes all risks associated with its        
39  * exercise of rights under this Agreement, including but not limited to     
40  * the risks and costs of program errors, damage to or loss of data,         
41  * programs or equipment, and unavailability or interruption of operations.  
42  *                                                                           
43  * DISCLAIMER OF LIABILITY                                                   
44  * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY   
45  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL        
46  * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND   
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR     
48  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE    
49  * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED  
50  * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES             
51  *                                                                           
52  * You should have received a copy of the GNU General Public License         
53  * along with this program; if not, write to the Free Software               
54  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
55  *                                                                           
56  * 
57  *  12/10/99 - Alpha Release 0.1.0
58  *            First release to the public
59  *  08/15/01 - Added ioctl() definitions and others - Kent Yoder <yoder1@us.ibm.com>
60  *
61  */
62
63 #if STREAMER_IOCTL && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
64 #include <asm/ioctl.h>
65 #define IOCTL_PRINT_RX_BUFS   SIOCDEVPRIVATE
66 #define IOCTL_PRINT_TX_BUFS   SIOCDEVPRIVATE+1
67 #define IOCTL_RX_CMD          SIOCDEVPRIVATE+2
68 #define IOCTL_TX_CMD          SIOCDEVPRIVATE+3
69 #define IOCTL_PRINT_REGISTERS SIOCDEVPRIVATE+4
70 #define IOCTL_PRINT_BDAS      SIOCDEVPRIVATE+5
71 #define IOCTL_SPIN_LOCK_TEST  SIOCDEVPRIVATE+6
72 #define IOCTL_SISR_MASK       SIOCDEVPRIVATE+7
73 #endif
74
75 /* MAX_INTR - the maximum number of times we can loop
76  * inside the interrupt function before returning
77  * control to the OS (maximum value is 256)
78  */
79 #define MAX_INTR 5
80
81 #define CLS 0x0C
82 #define MLR 0x86
83 #define LTR 0x0D
84
85 #define BCTL 0x60
86 #define BCTL_SOFTRESET (1<<15)
87 #define BCTL_RX_FIFO_8 (1<<1)
88 #define BCTL_TX_FIFO_8 (1<<3)
89
90 #define GPR 0x4a
91 #define GPR_AUTOSENSE (1<<2)
92 #define GPR_16MBPS (1<<3)
93
94 #define LISR 0x10
95 #define LISR_SUM 0x12
96 #define LISR_RUM 0x14
97
98 #define LISR_LIE (1<<15)
99 #define LISR_SLIM (1<<13)
100 #define LISR_SLI (1<<12)
101 #define LISR_BPEI (1<<9)
102 #define LISR_BPE (1<<8)
103 #define LISR_SRB_CMD (1<<5)
104 #define LISR_ASB_REPLY (1<<4)
105 #define LISR_ASB_FREE_REQ (1<<2)
106 #define LISR_ARB_FREE (1<<1)
107 #define LISR_TRB_FRAME (1<<0)
108
109 #define SISR 0x16
110 #define SISR_SUM 0x18
111 #define SISR_RUM 0x1A
112 #define SISR_MASK 0x54
113 #define SISR_MASK_SUM 0x56
114 #define SISR_MASK_RUM 0x58
115
116 #define SISR_MI (1<<15)
117 #define SISR_SERR_ERR (1<<14)
118 #define SISR_TIMER (1<<11)
119 #define SISR_LAP_PAR_ERR (1<<10)
120 #define SISR_LAP_ACC_ERR (1<<9)
121 #define SISR_PAR_ERR (1<<8)
122 #define SISR_ADAPTER_CHECK (1<<6)
123 #define SISR_SRB_REPLY (1<<5)
124 #define SISR_ASB_FREE (1<<4)
125 #define SISR_ARB_CMD (1<<3)
126 #define SISR_TRB_REPLY (1<<2)
127
128 #define MISR_RUM 0x5A
129 #define MISR_MASK 0x5C
130 #define MISR_MASK_RUM 0x5E
131
132 #define MISR_TX2_IDLE (1<<15)
133 #define MISR_TX2_NO_STATUS (1<<14)
134 #define MISR_TX2_HALT (1<<13)
135 #define MISR_TX2_EOF (1<<12)
136 #define MISR_TX1_IDLE (1<<11)
137 #define MISR_TX1_NO_STATUS (1<<10)
138 #define MISR_TX1_HALT (1<<9)
139 #define MISR_TX1_EOF (1<<8)
140 #define MISR_RX_NOBUF (1<<5)
141 #define MISR_RX_EOB (1<<4)
142 #define MISR_RX_NO_STATUS (1<<2)
143 #define MISR_RX_HALT (1<<1)
144 #define MISR_RX_EOF (1<<0)
145
146 #define LAPA 0x62
147 #define LAPE 0x64
148 #define LAPD 0x66
149 #define LAPDINC 0x68
150 #define LAPWWO 0x6A
151 #define LAPWWC 0x6C
152 #define LAPCTL 0x6E
153
154 #define TIMER 0x4E4
155
156 #define BMCTL_SUM 0x50
157 #define BMCTL_RUM 0x52
158 #define BMCTL_TX1_DIS (1<<14)
159 #define BMCTL_TX2_DIS (1<<10)
160 #define BMCTL_RX_DIS (1<<6)
161 #define BMCTL_RX_ENABLED  (1<<5)
162
163 #define RXLBDA  0x90
164 #define RXBDA   0x94
165 #define RXSTAT  0x98
166 #define RXDBA   0x9C
167
168 #define TX1LFDA 0xA0
169 #define TX1FDA  0xA4
170 #define TX1STAT 0xA8
171 #define TX1DBA  0xAC
172 #define TX2LFDA 0xB0
173 #define TX2FDA  0xB4
174 #define TX2STAT 0xB8
175 #define TX2DBA  0xBC
176
177 #define STREAMER_IO_SPACE 256
178
179 #define SRB_COMMAND_SIZE 50
180
181 #define STREAMER_MAX_ADAPTERS 8 /* 0x08 __MODULE_STRING can't hand 0xnn */
182
183 /* Defines for LAN STATUS CHANGE reports */
184 #define LSC_SIG_LOSS 0x8000
185 #define LSC_HARD_ERR 0x4000
186 #define LSC_SOFT_ERR 0x2000
187 #define LSC_TRAN_BCN 0x1000
188 #define LSC_LWF      0x0800
189 #define LSC_ARW      0x0400
190 #define LSC_FPE      0x0200
191 #define LSC_RR       0x0100
192 #define LSC_CO       0x0080
193 #define LSC_SS       0x0040
194 #define LSC_RING_REC 0x0020
195 #define LSC_SR_CO    0x0010
196 #define LSC_FDX_MODE 0x0004
197
198 /* Defines for OPEN ADAPTER command */
199
200 #define OPEN_ADAPTER_EXT_WRAP (1<<15)
201 #define OPEN_ADAPTER_DIS_HARDEE (1<<14)
202 #define OPEN_ADAPTER_DIS_SOFTERR (1<<13)
203 #define OPEN_ADAPTER_PASS_ADC_MAC (1<<12)
204 #define OPEN_ADAPTER_PASS_ATT_MAC (1<<11)
205 #define OPEN_ADAPTER_ENABLE_EC (1<<10)
206 #define OPEN_ADAPTER_CONTENDER (1<<8)
207 #define OPEN_ADAPTER_PASS_BEACON (1<<7)
208 #define OPEN_ADAPTER_ENABLE_FDX (1<<6)
209 #define OPEN_ADAPTER_ENABLE_RPL (1<<5)
210 #define OPEN_ADAPTER_INHIBIT_ETR (1<<4)
211 #define OPEN_ADAPTER_INTERNAL_WRAP (1<<3)
212
213
214 /* Defines for SRB Commands */
215 #define SRB_CLOSE_ADAPTER 0x04
216 #define SRB_CONFIGURE_BRIDGE 0x0c
217 #define SRB_CONFIGURE_HP_CHANNEL 0x13
218 #define SRB_MODIFY_BRIDGE_PARMS 0x15
219 #define SRB_MODIFY_OPEN_OPTIONS 0x01
220 #define SRB_MODIFY_RECEIVE_OPTIONS 0x17
221 #define SRB_NO_OPERATION 0x00
222 #define SRB_OPEN_ADAPTER 0x03
223 #define SRB_READ_LOG 0x08
224 #define SRB_READ_SR_COUNTERS 0x16
225 #define SRB_RESET_GROUP_ADDRESS 0x02
226 #define SRB_RESET_TARGET_SEGMETN 0x14
227 #define SRB_SAVE_CONFIGURATION 0x1b
228 #define SRB_SET_BRIDGE_PARMS 0x09
229 #define SRB_SET_FUNC_ADDRESS 0x07
230 #define SRB_SET_GROUP_ADDRESS 0x06
231 #define SRB_SET_TARGET_SEGMENT 0x05
232
233 /* Clear return code */
234 #define STREAMER_CLEAR_RET_CODE 0xfe
235
236 /* ARB Commands */
237 #define ARB_RECEIVE_DATA 0x81
238 #define ARB_LAN_CHANGE_STATUS 0x84
239
240 /* ASB Response commands */
241 #define ASB_RECEIVE_DATA 0x81
242
243
244 /* Streamer defaults for buffers */
245
246 #define STREAMER_RX_RING_SIZE 16        /* should be a power of 2 */
247 /* Setting the number of TX descriptors to 1 is a workaround for an
248  * undocumented hardware problem with the lanstreamer board. Setting
249  * this to something higher may slightly increase the throughput you
250  * can get from the card, but at the risk of locking up the box. - 
251  * <yoder1@us.ibm.com>
252  */
253 #define STREAMER_TX_RING_SIZE 1 /* should be a power of 2 */
254
255 #define PKT_BUF_SZ 4096         /* Default packet size */
256
257 /* Streamer data structures */
258
259 struct streamer_tx_desc {
260         __u32 forward;
261         __u32 status;
262         __u32 bufcnt_framelen;
263         __u32 buffer;
264         __u32 buflen;
265         __u32 rsvd1;
266         __u32 rsvd2;
267         __u32 rsvd3;
268 };
269
270 struct streamer_rx_desc {
271         __u32 forward;
272         __u32 status;
273         __u32 buffer;
274         __u32 framelen_buflen;
275 };
276
277 struct mac_receive_buffer {
278         __u16 next;
279         __u8 padding;
280         __u8 frame_status;
281         __u16 buffer_length;
282         __u8 frame_data;
283 };
284
285 struct streamer_private {
286
287         __u16 srb;
288         __u16 trb;
289         __u16 arb;
290         __u16 asb;
291
292         struct streamer_private *next;
293         struct pci_dev *pci_dev;
294         __u8 *streamer_mmio;
295         char *streamer_card_name;
296  
297         spinlock_t streamer_lock;
298
299         volatile int srb_queued;        /* True if an SRB is still posted */
300         wait_queue_head_t srb_wait;
301
302         volatile int asb_queued;        /* True if an ASB is posted */
303
304         volatile int trb_queued;        /* True if a TRB is posted */
305         wait_queue_head_t trb_wait;
306
307         struct streamer_rx_desc *streamer_rx_ring;
308         struct streamer_tx_desc *streamer_tx_ring;
309         struct sk_buff *tx_ring_skb[STREAMER_TX_RING_SIZE],
310             *rx_ring_skb[STREAMER_RX_RING_SIZE];
311         int tx_ring_free, tx_ring_last_status, rx_ring_last_received,
312             free_tx_ring_entries;
313
314         struct net_device_stats streamer_stats;
315         __u16 streamer_lan_status;
316         __u8 streamer_ring_speed;
317         __u16 pkt_buf_sz;
318         __u8 streamer_receive_options, streamer_copy_all_options,
319             streamer_message_level;
320         __u16 streamer_addr_table_addr, streamer_parms_addr;
321         __u16 mac_rx_buffer;
322         __u8 streamer_laa[6];
323 };
324
325 struct streamer_adapter_addr_table {
326
327         __u8 node_addr[6];
328         __u8 reserved[4];
329         __u8 func_addr[4];
330 };
331
332 struct streamer_parameters_table {
333
334         __u8 phys_addr[4];
335         __u8 up_node_addr[6];
336         __u8 up_phys_addr[4];
337         __u8 poll_addr[6];
338         __u16 reserved;
339         __u16 acc_priority;
340         __u16 auth_source_class;
341         __u16 att_code;
342         __u8 source_addr[6];
343         __u16 beacon_type;
344         __u16 major_vector;
345         __u16 lan_status;
346         __u16 soft_error_time;
347         __u16 reserved1;
348         __u16 local_ring;
349         __u16 mon_error;
350         __u16 beacon_transmit;
351         __u16 beacon_receive;
352         __u16 frame_correl;
353         __u8 beacon_naun[6];
354         __u32 reserved2;
355         __u8 beacon_phys[4];
356 };