]> Pileus Git - ~andy/linux/blob - drivers/staging/et131x/et131x_adapter.h
Staging: et131x: kill unused RCV_REF macros
[~andy/linux] / drivers / staging / et131x / et131x_adapter.h
1 /*
2  * Agere Systems Inc.
3  * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
4  *
5  * Copyright © 2005 Agere Systems Inc.
6  * All rights reserved.
7  *   http://www.agere.com
8  *
9  *------------------------------------------------------------------------------
10  *
11  * et131x_adapter.h - Header which includes the private adapter structure, along
12  *                    with related support structures, macros, definitions, etc.
13  *
14  *------------------------------------------------------------------------------
15  *
16  * SOFTWARE LICENSE
17  *
18  * This software is provided subject to the following terms and conditions,
19  * which you should read carefully before using the software.  Using this
20  * software indicates your acceptance of these terms and conditions.  If you do
21  * not agree with these terms and conditions, do not use the software.
22  *
23  * Copyright © 2005 Agere Systems Inc.
24  * All rights reserved.
25  *
26  * Redistribution and use in source or binary forms, with or without
27  * modifications, are permitted provided that the following conditions are met:
28  *
29  * . Redistributions of source code must retain the above copyright notice, this
30  *    list of conditions and the following Disclaimer as comments in the code as
31  *    well as in the documentation and/or other materials provided with the
32  *    distribution.
33  *
34  * . Redistributions in binary form must reproduce the above copyright notice,
35  *    this list of conditions and the following Disclaimer in the documentation
36  *    and/or other materials provided with the distribution.
37  *
38  * . Neither the name of Agere Systems Inc. nor the names of the contributors
39  *    may be used to endorse or promote products derived from this software
40  *    without specific prior written permission.
41  *
42  * Disclaimer
43  *
44  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
45  * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
46  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  ANY
47  * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
48  * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
49  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
52  * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
55  * DAMAGE.
56  *
57  */
58
59 #ifndef __ET131X_ADAPTER_H__
60 #define __ET131X_ADAPTER_H__
61
62 #include "et1310_address_map.h"
63 #include "et1310_tx.h"
64 #include "et1310_rx.h"
65
66 /*
67  * Do not change these values: if changed, then change also in respective
68  * TXdma and Rxdma engines
69  */
70 #define NUM_DESC_PER_RING_TX         512        /* TX Do not change these values */
71 #define NUM_TCB                      64
72
73 /*
74  * These values are all superseded by registry entries to facilitate tuning.
75  * Once the desired performance has been achieved, the optimal registry values
76  * should be re-populated to these #defines:
77  */
78 #define NUM_TRAFFIC_CLASSES          1
79
80 /*
81  * There are three ways of counting errors - if there are more than X errors
82  * in Y packets (represented by the "SAMPLE" macros), if there are more than
83  * N errors in a S mSec time period (the "PERIOD" macros), or if there are
84  * consecutive packets with errors (CONSEC_ERRORED_THRESH).  This last covers
85  * for "Bursty" errors, and the errored packets may well not be contiguous,
86  * but several errors where the packet counter has changed by less than a
87  * small amount will cause this count to increment.
88  */
89 #define TX_PACKETS_IN_SAMPLE        10000
90 #define TX_MAX_ERRORS_IN_SAMPLE     50
91
92 #define TX_ERROR_PERIOD             1000
93 #define TX_MAX_ERRORS_IN_PERIOD     10
94
95 #define LINK_DETECTION_TIMER        5000
96
97 #define TX_CONSEC_RANGE             5
98 #define TX_CONSEC_ERRORED_THRESH    10
99
100 #define LO_MARK_PERCENT_FOR_PSR     15
101 #define LO_MARK_PERCENT_FOR_RX      15
102
103 /* Macros for flag and ref count operations        */
104 #define MP_SET_FLAG(_M, _F)         ((_M)->Flags |= (_F))
105 #define MP_CLEAR_FLAG(_M, _F)       ((_M)->Flags &= ~(_F))
106 #define MP_CLEAR_FLAGS(_M)          ((_M)->Flags = 0)
107 #define MP_TEST_FLAG(_M, _F)        (((_M)->Flags & (_F)) != 0)
108 #define MP_TEST_FLAGS(_M, _F)       (((_M)->Flags & (_F)) == (_F))
109 #define MP_IS_FLAG_CLEAR(_M, _F)    (((_M)->Flags & (_F)) == 0)
110
111 #define MP_GET_RCV_REF(_A)          atomic_read(&(_A)->RcvRefCount)
112
113 /* Macros specific to the private adapter structure */
114 #define MP_TCB_RESOURCES_AVAILABLE(_M) ((_M)->TxRing.nBusySend < NUM_TCB)
115 #define MP_TCB_RESOURCES_NOT_AVAILABLE(_M) ((_M)->TxRing.nBusySend >= NUM_TCB)
116
117 #define MP_SHOULD_FAIL_SEND(_M)   ((_M)->Flags & fMP_ADAPTER_FAIL_SEND_MASK)
118 #define MP_IS_NOT_READY(_M)       ((_M)->Flags & fMP_ADAPTER_NOT_READY_MASK)
119 #define MP_IS_READY(_M)           (!((_M)->Flags & fMP_ADAPTER_NOT_READY_MASK))
120
121 #define MP_HAS_CABLE(_M)           (!((_M)->Flags & fMP_ADAPTER_NO_CABLE))
122 #define MP_LINK_DETECTED(_M)       (!((_M)->Flags & fMP_ADAPTER_LINK_DETECTION))
123
124 /* Counters for error rate monitoring */
125 typedef struct _MP_ERR_COUNTERS {
126         u32 PktCountTxPackets;
127         u32 PktCountTxErrors;
128         u32 TimerBasedTxErrors;
129         u32 PktCountLastError;
130         u32 ErredConsecPackets;
131 } MP_ERR_COUNTERS, *PMP_ERR_COUNTERS;
132
133 /* RFD (Receive Frame Descriptor) */
134 typedef struct _MP_RFD {
135         struct list_head list_node;
136         struct sk_buff *Packet;
137         u32 PacketSize; /* total size of receive frame */
138         u16 iBufferIndex;
139         u8 iRingIndex;
140 } MP_RFD, *PMP_RFD;
141
142 /* Enum for Flow Control */
143 typedef enum _eflow_control_t {
144         Both = 0,
145         TxOnly = 1,
146         RxOnly = 2,
147         None = 3
148 } eFLOW_CONTROL_t, *PeFLOW_CONTROL_t;
149
150 /* Struct to define some device statistics */
151 typedef struct _ce_stats_t {
152         /* Link Input/Output stats */
153         uint64_t ipackets;      /* # of in packets */
154         uint64_t opackets;      /* # of out packets */
155
156         /* MIB II variables
157          *
158          * NOTE: atomic_t types are only guaranteed to store 24-bits; if we
159          * MUST have 32, then we'll need another way to perform atomic
160          * operations
161          */
162         u32 unircv;     /* # multicast packets received */
163         atomic_t unixmt;        /* # multicast packets for Tx */
164         u32 multircv;   /* # multicast packets received */
165         atomic_t multixmt;      /* # multicast packets for Tx */
166         u32 brdcstrcv;  /* # broadcast packets received */
167         atomic_t brdcstxmt;     /* # broadcast packets for Tx */
168         u32 norcvbuf;   /* # Rx packets discarded */
169         u32 noxmtbuf;   /* # Tx packets discarded */
170
171         /* Transciever state informations. */
172         u8 xcvr_addr;
173         u32 xcvr_id;
174
175         /* Tx Statistics. */
176         u32 tx_uflo;            /* Tx Underruns */
177
178         u32 collisions;
179         u32 excessive_collisions;
180         u32 first_collision;
181         u32 late_collisions;
182         u32 max_pkt_error;
183         u32 tx_deferred;
184
185         /* Rx Statistics. */
186         u32 rx_ov_flow; /* Rx Over Flow */
187
188         u32 length_err;
189         u32 alignment_err;
190         u32 crc_err;
191         u32 code_violations;
192         u32 other_errors;
193
194 #ifdef CONFIG_ET131X_DEBUG
195         u32 UnhandledInterruptsPerSec;
196         u32 RxDmaInterruptsPerSec;
197         u32 TxDmaInterruptsPerSec;
198         u32 WatchDogInterruptsPerSec;
199 #endif  /* CONFIG_ET131X_DEBUG */
200
201         u32 SynchrounousIterations;
202         INTERRUPT_t InterruptStatus;
203 } CE_STATS_t, *PCE_STATS_t;
204
205 /* The private adapter structure */
206 struct et131x_adapter {
207         struct net_device *netdev;
208         struct pci_dev *pdev;
209
210         struct work_struct task;
211
212         /* Flags that indicate current state of the adapter */
213         u32 Flags;
214         u32 HwErrCount;
215
216         /* Configuration  */
217         u8 PermanentAddress[ETH_ALEN];
218         u8 CurrentAddress[ETH_ALEN];
219         bool bOverrideAddress;
220         bool bEepromPresent;
221         u8 eepromData[2];
222
223         /* Spinlocks */
224         spinlock_t Lock;
225
226         spinlock_t TCBSendQLock;
227         spinlock_t TCBReadyQLock;
228         spinlock_t SendHWLock;
229         spinlock_t SendWaitLock;
230
231         spinlock_t RcvLock;
232         spinlock_t RcvPendLock;
233         spinlock_t FbrLock;
234
235         spinlock_t PHYLock;
236
237         /* Packet Filter and look ahead size */
238         u32 PacketFilter;
239         u32 ulLookAhead;
240         u32 uiLinkSpeed;
241         u32 uiDuplexMode;
242         u32 uiAutoNegStatus;
243         u8 ucLinkStatus;
244
245         /* multicast list */
246         u32 MCAddressCount;
247         u8 MCList[NIC_MAX_MCAST_LIST][ETH_ALEN];
248
249         /* MAC test */
250         TXMAC_TXTEST_t TxMacTest;
251
252         /* Pointer to the device's PCI register space */
253         ADDRESS_MAP_t __iomem *CSRAddress;
254
255         /* PCI config space info, for debug purposes only. */
256         u8 RevisionID;
257         u16 VendorID;
258         u16 DeviceID;
259         u16 SubVendorID;
260         u16 SubSystemID;
261         u32 CacheFillSize;
262         u16 PciXDevCtl;
263         u8 pci_lat_timer;
264         u8 pci_hdr_type;
265         u8 pci_bist;
266         u32 pci_cfg_state[64 / sizeof(u32)];
267
268         /* Registry parameters */
269         u8 SpeedDuplex;         /* speed/duplex */
270         eFLOW_CONTROL_t RegistryFlowControl;    /* for 802.3x flow control */
271         u8 RegistryWOLMatch;    /* Enable WOL pattern-matching */
272         u8 RegistryWOLLink;     /* Link state change is independant */
273         u8 RegistryPhyComa;     /* Phy Coma mode enable/disable */
274
275         u32 RegistryRxMemEnd;   /* Size of internal rx memory */
276         u8 RegistryMACStat;     /* If set, read MACSTAT, else don't */
277         u32 RegistryVlanTag;    /* 802.1q Vlan TAG */
278         u32 RegistryJumboPacket;        /* Max supported ethernet packet size */
279
280         u32 RegistryTxNumBuffers;
281         u32 RegistryTxTimeInterval;
282
283         u32 RegistryRxNumBuffers;
284         u32 RegistryRxTimeInterval;
285
286         /* Validation helpers */
287         u8 RegistryPMWOL;
288         u8 RegistryNMIDisable;
289         u32 RegistryDMACache;
290         u32 RegistrySCGain;
291         u8 RegistryPhyLoopbk;   /* Enable Phy loopback */
292
293         /* Derived from the registry: */
294         u8 AiForceDpx;          /* duplex setting */
295         u16 AiForceSpeed;               /* 'Speed', user over-ride of line speed */
296         eFLOW_CONTROL_t FlowControl;    /* flow control validated by the far-end */
297         enum {
298                 NETIF_STATUS_INVALID = 0,
299                 NETIF_STATUS_MEDIA_CONNECT,
300                 NETIF_STATUS_MEDIA_DISCONNECT,
301                 NETIF_STATUS_MAX
302         } MediaState;
303         u8 DriverNoPhyAccess;
304
305         /* Minimize init-time */
306         bool bQueryPending;
307         bool bSetPending;
308         bool bResetPending;
309         struct timer_list ErrorTimer;
310         bool bLinkTimerActive;
311         MP_POWER_MGMT PoMgmt;
312         INTERRUPT_t CachedMaskValue;
313
314         atomic_t RcvRefCount;   /* Num packets not yet returned */
315
316         /* Xcvr status at last poll */
317         MI_BMSR_t Bmsr;
318
319         /* Tx Memory Variables */
320         TX_RING_t TxRing;
321
322         /* Rx Memory Variables */
323         RX_RING_t RxRing;
324
325         /* ET1310 register Access */
326         JAGCORE_ACCESS_REGS JagCoreRegs;
327         PCI_CFG_SPACE_REGS PciCfgRegs;
328
329         /* Loopback specifics */
330         u8 ReplicaPhyLoopbk;    /* Replica Enable */
331         u8 ReplicaPhyLoopbkPF;  /* Replica Enable Pass/Fail */
332
333         /* Stats */
334         CE_STATS_t Stats;
335
336         struct net_device_stats net_stats;
337         struct net_device_stats net_stats_prev;
338 };
339
340 #define MPSendPacketsHandler  MPSendPackets
341 #define MP_FREE_SEND_PACKET_FUN(Adapter, pMpTcb) \
342         et131x_free_send_packet(Adapter, pMpTcb)
343 #define MpSendPacketFun(Adapter, Packet) MpSendPacket(Adapter, Packet)
344
345 #endif /* __ET131X_ADAPTER_H__ */