Staging: sxg: Fix to load card on low memory machines
[pandora-kernel.git] / drivers / staging / sxg / sxg.h
1 /**************************************************************************
2  *
3  * Copyright © 2000-2008 Alacritech, Inc.  All rights reserved.
4  *
5  * $Id: sxg.h,v 1.3 2008/07/24 17:25:08 chris Exp $
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above
14  *    copyright notice, this list of conditions and the following
15  *    disclaimer in the documentation and/or other materials provided
16  *    with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY ALACRITECH, INC. ``AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ALACRITECH, INC. OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
25  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * The views and conclusions contained in the software and documentation
32  * are those of the authors and should not be interpreted as representing
33  * official policies, either expressed or implied, of Alacritech, Inc.
34  *
35  **************************************************************************/
36
37 /*
38  * FILENAME: sxg.h
39  *
40  * This is the base set of header definitions for the SXG driver.
41  */
42 #ifndef __SXG_DRIVER_H__
43 #define __SXG_DRIVER_H__
44
45 #define SLIC_DUMP_ENABLED               0
46
47 #define SXG_DRV_NAME    "sxg"           /* TBD: This might be removed eventually */
48 #define SXG_DRV_VERSION "1.0.1"
49
50 extern char sxg_driver_name[];
51 /*
52  * struct sxg_stats - Probably move these to someplace where
53  * the slicstat (sxgstat?) program can get them.
54  */
55 struct sxg_stats {
56         /* Xmt */
57         u64     DumbXmtUcastPkts;       /* directed packets */
58         u64     DumbXmtMcastPkts;       /* Multicast packets */
59         u64     DumbXmtBcastPkts;       /* OID_GEN_BROADCAST_FRAMES_RCV */
60         u64     DumbXmtUcastBytes;      /* OID_GEN_DIRECTED_BYTES_XMIT */
61         u64     DumbXmtMcastBytes;      /* OID_GEN_MULTICAST_BYTES_XMIT */
62         u64     DumbXmtBcastBytes;      /* OID_GEN_BROADCAST_BYTES_XMIT */
63         u64     XmtQLen;                /* OID_GEN_TRANSMIT_QUEUE_LENGTH */
64         u64     XmtZeroFull;            /* Transmit ring zero full */
65         /* Rcv */
66         u64     DumbRcvUcastBytes;      /* OID_GEN_DIRECTED_BYTES_RCV */
67         u64     DumbRcvMcastBytes;      /* OID_GEN_MULTICAST_BYTES_RCV */
68         u64     DumbRcvBcastBytes;      /* OID_GEN_BROADCAST_BYTES_RCV */
69         u64     DumbRcvUcastPkts;       /* directed packets */
70         u64     DumbRcvMcastPkts;       /* Multicast packets */
71         u64     DumbRcvBcastPkts;       /* OID_GEN_BROADCAST_FRAMES_RCV */
72         u64     PdqFull;                /* Processed Data Queue Full */
73         u64     EventRingFull;          /* Event ring full */
74         /* Verbose stats */
75         u64     NoSglBuf;               /* SGL buffer allocation failure */
76         u64     NoMem;                  /* Memory allocation failure */
77         u64     NumInts;                /* Interrupts */
78         u64     FalseInts;              /* Interrupt with ISR == 0 */
79         /* Sahara receive status */
80         u64     TransportCsum;          /* SXG_RCV_STATUS_TRANSPORT_CSUM */
81         u64     TransportUflow;         /* SXG_RCV_STATUS_TRANSPORT_UFLOW */
82         u64     TransportHdrLen;        /* SXG_RCV_STATUS_TRANSPORT_HDRLEN */
83         u64     NetworkCsum;            /* SXG_RCV_STATUS_NETWORK_CSUM: */
84         u64     NetworkUflow;           /* SXG_RCV_STATUS_NETWORK_UFLOW: */
85         u64     NetworkHdrLen;          /* SXG_RCV_STATUS_NETWORK_HDRLEN: */
86         u64     Parity;                 /* SXG_RCV_STATUS_PARITY */
87         u64     LinkParity;             /* SXG_RCV_STATUS_LINK_PARITY: */
88         u64     LinkEarly;              /* SXG_RCV_STATUS_LINK_EARLY: */
89         u64     LinkBufOflow;           /* SXG_RCV_STATUS_LINK_BUFOFLOW: */
90         u64     LinkCode;               /* SXG_RCV_STATUS_LINK_CODE: */
91         u64     LinkDribble;            /* SXG_RCV_STATUS_LINK_DRIBBLE: */
92         u64     LinkCrc;                /* SXG_RCV_STATUS_LINK_CRC: */
93         u64     LinkOflow;              /* SXG_RCV_STATUS_LINK_OFLOW: */
94         u64     LinkUflow;              /* SXG_RCV_STATUS_LINK_UFLOW: */
95 };
96
97
98 /* DUMB-NIC Send path definitions */
99
100 #define SXG_COMPLETE_DUMB_SEND(_pAdapt, _skb, _phys_addr, _size) {              \
101         ASSERT(_skb);                                                           \
102         pci_unmap_single(_pAdapt->pcidev, _size, _phys_addr, PCI_DMA_TODEVICE); \
103         dev_kfree_skb_irq(_skb);                                                \
104 }
105
106 #define SXG_DROP_DUMB_SEND(_pAdapt, _skb) {                             \
107         ASSERT(_skb);                                                   \
108     dev_kfree_skb(_skb);                                                \
109 }
110
111 /*
112  * Locate current receive header buffer location.  Use this
113  * instead of RcvDataHdr->VirtualAddress since the data
114  * may have been offset by SXG_ADVANCE_MDL_OFFSET
115  */
116 #define SXG_RECEIVE_DATA_LOCATION(_RcvDataHdr)        (_RcvDataHdr)->skb->data
117
118 /* Dumb-NIC receive processing */
119 /* Define an SXG_PACKET as an NDIS_PACKET */
120 #define PSXG_PACKET       struct sk_buff *
121 /* Indications array size */
122 #define SXG_RCV_ARRAYSIZE       64
123
124 #define SXG_ALLOCATE_RCV_PACKET(_pAdapt, _RcvDataBufferHdr, BufferSize) {\
125     struct sk_buff * skb;                                               \
126     skb = netdev_alloc_skb(_pAdapt->netdev, BufferSize);                \
127     if (skb) {                                                          \
128         (_RcvDataBufferHdr)->skb = skb;                                 \
129         skb->next = NULL;                                               \
130         _RcvDataBufferHdr->PhysicalAddress = pci_map_single(adapter->pcidev,\
131             _RcvDataBufferHdr->skb->data, BufferSize, PCI_DMA_FROMDEVICE);      \
132     } else {                                                            \
133         (_RcvDataBufferHdr)->skb = NULL;                                \
134     }                                                                   \
135 }
136
137 #define SXG_FREE_RCV_PACKET(_RcvDataBufferHdr) {                        \
138         if((_RcvDataBufferHdr)->skb) {                                  \
139                 dev_kfree_skb((_RcvDataBufferHdr)->skb);                \
140     }                                                                   \
141 }
142
143 /*
144  * Macro to add a NDIS_PACKET to an indication array
145  * If we fill up our array of packet pointers, then indicate this
146  * block up now and start on a new one.
147  */
148 #define SXG_ADD_RCV_PACKET(_pAdapt, _Packet, _PrevPacket, _IndicationList, \
149                                 _NumPackets) {                          \
150         (_IndicationList)[_NumPackets] = (_Packet);                     \
151         (_NumPackets)++;                                                \
152         if((_NumPackets) == SXG_RCV_ARRAYSIZE) {                        \
153                 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "IndicRcv",   \
154                                    (_NumPackets), 0, 0, 0);             \
155         netif_rx((_IndicationList),(_NumPackets));                      \
156                 (_NumPackets) = 0;                                      \
157         }                                                               \
158 }
159
160 #define SXG_INDICATE_PACKETS(_pAdapt, _IndicationList, _NumPackets) {   \
161         if(_NumPackets) {                                               \
162                 SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "IndicRcv",   \
163                                    (_NumPackets), 0, 0, 0);             \
164         netif_rx((_IndicationList),(_NumPackets));                      \
165                 (_NumPackets) = 0;                                      \
166         }                                                               \
167 }
168
169 #define SXG_REINIATIALIZE_PACKET(_Packet)                               \
170         {}  /*_NdisReinitializePacket(_Packet)*/
171                  /*  this is not necessary with an skb */
172
173 /* Definitions to initialize Dumb-nic Receive NBLs */
174 #define SXG_RCV_PACKET_BUFFER_HDR(_Packet) (((struct sxg_rcv_nbl_reserved *)\
175                         ((_Packet)->MiniportReservedEx))->RcvDataBufferHdr)
176
177 #define SXG_RCV_SET_CHECKSUM_INFO(_Packet, _Cpi)                                \
178         NDIS_PER_PACKET_INFO_FROM_PACKET((_Packet),                             \
179                         TcpIpChecksumPacketInfo) = (PVOID)(_Cpi)
180
181 #define SXG_RCV_SET_TOEPLITZ(_Packet, _Toeplitz, _Type, _Function) {            \
182         NDIS_PACKET_SET_HASH_VALUE((_Packet), (_Toeplitz));                     \
183         NDIS_PACKET_SET_HASH_TYPE((_Packet), (_Type));                          \
184         NDIS_PACKET_SET_HASH_FUNCTION((_Packet), (_Function));                  \
185 }
186
187 #define SXG_RCV_SET_VLAN_INFO(_Packet, _VlanId, _Priority) {                    \
188         NDIS_PACKET_8021Q_INFO  _Packet8021qInfo;                               \
189         _Packet8021qInfo.TagHeader.VlanId = (_VlanId);                          \
190         _Packet8021qInfo.TagHeader.UserPriority = (_Priority);                  \
191         NDIS_PER_PACKET_INFO_FROM_PACKET((_Packet), Ieee8021QNetBufferListInfo) =       \
192                 _Packet8021qInfo.Value;                                         \
193 }
194
195 #define SXG_ADJUST_RCV_PACKET(_Packet, _RcvDataBufferHdr, _Event) {             \
196         SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "DumbRcv",            \
197                            (_RcvDataBufferHdr), (_Packet),                      \
198                            (_Event)->Status, 0);                                \
199         /* ASSERT((_Event)->Length <= (_RcvDataBufferHdr)->Size); */            \
200         skb_put(Packet, (_Event)->Length);                                      \
201 }
202
203 /*
204  * Macros to free a receive data buffer and receive data descriptor block
205  * NOTE - Lock must be held with RCV macros
206  */
207 #define SXG_GET_RCV_DATA_BUFFER(_pAdapt, _Hdr) {                                \
208         struct list_entry *_ple;                                                \
209         _Hdr = NULL;                                                            \
210         if((_pAdapt)->FreeRcvBufferCount) {                                     \
211                 ASSERT(!(IsListEmpty(&(_pAdapt)->FreeRcvBuffers)));             \
212                 _ple = RemoveHeadList(&(_pAdapt)->FreeRcvBuffers);              \
213                 (_Hdr) = container_of(_ple, struct sxg_rcv_data_buffer_hdr,     \
214                                                 FreeList);                      \
215                 (_pAdapt)->FreeRcvBufferCount--;                                \
216                 ASSERT((_Hdr)->State == SXG_BUFFER_FREE);                       \
217         }                                                                       \
218 }
219
220 #define SXG_FREE_RCV_DATA_BUFFER(_pAdapt, _Hdr) {                               \
221         SXG_TRACE(TRACE_SXG, SxgTraceBuffer, TRACE_NOISY, "RtnDHdr",            \
222                            (_Hdr), (_pAdapt)->FreeRcvBufferCount,               \
223                            (_Hdr)->State, 0/*(_Hdr)->VirtualAddress*/);         \
224 /*      SXG_RESTORE_MDL_OFFSET(_Hdr);   */                                      \
225         (_pAdapt)->FreeRcvBufferCount++;                                        \
226         ASSERT(((_pAdapt)->AllRcvBlockCount * SXG_RCV_DESCRIPTORS_PER_BLOCK)    \
227                                 >= (_pAdapt)->FreeRcvBufferCount);              \
228         ASSERT((_Hdr)->State != SXG_BUFFER_FREE);                               \
229         (_Hdr)->State = SXG_BUFFER_FREE;                                        \
230         InsertTailList(&(_pAdapt)->FreeRcvBuffers, &((_Hdr)->FreeList));        \
231 }
232
233 #define SXG_FREE_RCV_DESCRIPTOR_BLOCK(_pAdapt, _Hdr) {                          \
234         ASSERT((_Hdr)->State != SXG_BUFFER_FREE);                               \
235         (_Hdr)->State = SXG_BUFFER_FREE;                                        \
236         (_pAdapt)->FreeRcvBlockCount++;                                         \
237         ASSERT((_pAdapt)->AllRcvBlockCount >= (_pAdapt)->FreeRcvBlockCount);    \
238         InsertTailList(&(_pAdapt)->FreeRcvBlocks, &(_Hdr)->FreeList);           \
239 }
240
241 /* SGL macros */
242 #define SXG_FREE_SGL_BUFFER(_pAdapt, _Sgl, _NB, _irq) {                         \
243         if(!_irq)                                                               \
244                 spin_lock_irqsave(&(_pAdapt)->SglQLock, sgl_flags);             \
245         else                                                                    \
246                 spin_lock(&(_pAdapt)->SglQLock);                                \
247         (_pAdapt)->FreeSglBufferCount++;                                        \
248         ASSERT((_pAdapt)->AllSglBufferCount >= (_pAdapt)->FreeSglBufferCount);  \
249         ASSERT(!((_Sgl)->State & SXG_BUFFER_FREE));                             \
250         (_Sgl)->State = SXG_BUFFER_FREE;                                        \
251         InsertTailList(&(_pAdapt)->FreeSglBuffers, &(_Sgl)->FreeList);          \
252         if(!_irq)                                                               \
253                 spin_unlock_irqrestore(&(_pAdapt)->SglQLock, sgl_flags);        \
254         else                                                                    \
255                 spin_unlock(&(_pAdapt)->SglQLock);                              \
256 }
257
258 /*
259  * Get an SGL buffer from the free queue.  The first part of this macro
260  * attempts to keep ahead of buffer depletion by allocating more when
261  * we hit a minimum threshold.  Note that we don't grab the lock
262  * until after that.  We're dealing with round numbers here, so we don't need to,
263  * and not grabbing it avoids a possible double-trip.
264  */
265 #define SXG_GET_SGL_BUFFER(_pAdapt, _Sgl, _irq) {                       \
266         struct list_entry *_ple;                                        \
267         if ((_pAdapt->FreeSglBufferCount < SXG_MIN_SGL_BUFFERS) &&      \
268            (_pAdapt->AllSglBufferCount < SXG_MAX_SGL_BUFFERS) &&        \
269            (atomic_read(&_pAdapt->pending_allocations) == 0)) {         \
270                 sxg_allocate_buffer_memory(_pAdapt,                     \
271                         (sizeof(struct sxg_scatter_gather) + SXG_SGL_BUF_SIZE),\
272                         SXG_BUFFER_TYPE_SGL);                           \
273         }                                                               \
274         _Sgl = NULL;                                                    \
275         if(!_irq)                                                       \
276                 spin_lock_irqsave(&(_pAdapt)->SglQLock, sgl_flags);     \
277         else                                                            \
278                 spin_lock(&(_pAdapt)->SglQLock);                        \
279         if((_pAdapt)->FreeSglBufferCount) {                             \
280                 ASSERT(!(IsListEmpty(&(_pAdapt)->FreeSglBuffers)));     \
281                 _ple = RemoveHeadList(&(_pAdapt)->FreeSglBuffers);      \
282                 (_Sgl) = container_of(_ple, struct sxg_scatter_gather,  \
283                                                 FreeList);              \
284             (_pAdapt)->FreeSglBufferCount--;                            \
285                 ASSERT((_Sgl)->State == SXG_BUFFER_FREE);               \
286                 (_Sgl)->State = SXG_BUFFER_BUSY;                        \
287                 (_Sgl)->pSgl = NULL;                                    \
288         }                                                               \
289         if(!_irq)                                                       \
290                 spin_unlock_irqrestore(&(_pAdapt)->SglQLock, sgl_flags);\
291         else                                                            \
292                 spin_unlock(&(_pAdapt)->SglQLock);                      \
293 }
294
295 /*
296  * struct sxg_multicast_address
297  * Linked list of multicast addresses.
298  */
299 struct sxg_multicast_address {
300         unsigned char                   Address[6];
301         struct sxg_multicast_address    *Next;
302 };
303
304 /*
305  * Structure to maintain chimney send and receive buffer queues.
306  * This structure maintains NET_BUFFER_LIST queues that are
307  * given to us via the Chimney MiniportTcpOffloadSend and
308  * MiniportTcpOffloadReceive routines.  This structure DOES NOT
309  * manage our data buffer queue
310  */
311 struct sxg_buffer_queue {
312         u32     Type;                   /* Slow or fast - See below */
313         u32     Direction;              /* Xmt or Rcv */
314         u32     Bytes;                  /* Byte count */
315         u32 *   Head;                   /* Send queue head */
316         u32 *   Tail;                   /* Send queue tail */
317 /*      PNET_BUFFER_LIST        NextNBL;*/      /* Short cut - next NBL */
318 /*      PNET_BUFFER             NextNB; */      /* Short cut - next NB */
319 };
320
321 #define         SXG_SLOW_SEND_BUFFER    0
322 #define         SXG_FAST_SEND_BUFFER    1
323 #define         SXG_RECEIVE_BUFFER              2
324
325 #define SXG_INIT_BUFFER(_Buffer, _Type) {                               \
326         (_Buffer)->Type = (_Type);                                      \
327         if((_Type) == SXG_RECEIVE_BUFFER) {                             \
328                 (_Buffer)->Direction = 0;                               \
329         } else {                                                        \
330                 (_Buffer)->Direction = NDIS_SG_LIST_WRITE_TO_DEVICE;    \
331         }                                                               \
332         (_Buffer)->Bytes = 0;                                           \
333         (_Buffer)->Head = NULL;                                         \
334         (_Buffer)->Tail = NULL;                                         \
335 }
336
337
338 #define SXG_RSS_CPU_COUNT(_pAdapt)                                      \
339         ((_pAdapt)->RssEnabled  ?  NR_CPUS : 1)
340
341 /* DRIVER and ADAPTER structures */
342
343 /*
344  * Adapter states - These states closely match the adapter states
345  * documented in the DDK (with a few exceptions).
346  */
347 enum SXG_STATE {
348         SXG_STATE_INITIALIZING,                 /* Initializing */
349         SXG_STATE_BOOTDIAG,                     /* Boot-Diagnostic mode */
350         SXG_STATE_PAUSING,                      /* Pausing */
351         SXG_STATE_PAUSED,                       /* Paused */
352         SXG_STATE_RUNNING,                      /* Running */
353         SXG_STATE_RESETTING,                    /* Reset in progress */
354         SXG_STATE_SLEEP,                        /* Sleeping */
355         SXG_STATE_DIAG,                         /* Diagnostic mode */
356         SXG_STATE_HALTING,                      /* Halting */
357         SXG_STATE_HALTED,                       /* Down or not-initialized */
358         SXG_STATE_SHUTDOWN                      /* shutdown */
359 };
360
361 /* Link state */
362 enum SXG_LINK_STATE {
363         SXG_LINK_DOWN,
364         SXG_LINK_UP
365 };
366
367 /* Link initialization timeout in 100us units */
368 #define SXG_LINK_TIMEOUT        100000          /* 10 Seconds - REDUCE! */
369
370
371 /* Microcode file selection codes */
372 enum SXG_UCODE_SEL {
373         SXG_UCODE_SAHARA,       /* Sahara ucode */
374         SXG_UCODE_SDIAGCPU,     /* Sahara CPU diagnostic ucode */
375         SXG_UCODE_SDIAGSYS      /* Sahara system diagnostic ucode */
376 };
377
378
379 #define SXG_DISABLE_ALL_INTERRUPTS(_padapt) sxg_disable_interrupt(_padapt)
380 #define SXG_ENABLE_ALL_INTERRUPTS(_padapt) sxg_enable_interrupt(_padapt)
381
382 /* This probably lives in a proto.h file.  Move later */
383 #define SXG_MULTICAST_PACKET(_pether) ((_pether)->ether_dhost[0] & 0x01)
384 #define SXG_BROADCAST_PACKET(_pether)                                   \
385                 ((*(u32 *)(_pether)->ether_dhost == 0xFFFFFFFF) &&      \
386                 (*(u16 *)&(_pether)->ether_dhost[4] == 0xFFFF))
387
388 /* For DbgPrints */
389 #define SXG_ID      DPFLTR_IHVNETWORK_ID
390 #define SXG_ERROR   DPFLTR_ERROR_LEVEL
391
392 /*
393  * struct sxg_driver structure -
394  *
395  * contains information about the sxg driver.  There is only
396  * one of these, and it is defined as a global.
397  */
398
399 struct sxg_driver {
400         struct adapter_t        *Adapters;      /* Linked list of adapters */
401         ushort                  AdapterID;      /* Maintain unique adapter ID */
402 };
403
404 #ifdef STATUS_SUCCESS
405 #undef STATUS_SUCCESS
406 #endif
407
408 /* TODO: We need to try and use NETDEV_TX_* before posting this out */
409 #define STATUS_SUCCESS              0
410 #define STATUS_PENDING              0
411 #define STATUS_FAILURE             -1
412 #define STATUS_ERROR               -2
413 #define STATUS_NOT_SUPPORTED       -3
414 #define STATUS_BUFFER_TOO_SHORT    -4
415 #define STATUS_RESOURCES           -5
416
417 #define SLIC_MAX_CARDS              32
418 #define SLIC_MAX_PORTS              4        /* Max # of ports per card   */
419 #if SLIC_DUMP_ENABLED
420
421 /*
422  * Dump buffer size
423  * This cannot be bigger than the max DMA size the card supports,
424  * given the current code structure in the host and ucode.
425  * Mojave supports 16K, Oasis supports 16K-1, so
426  * just set this at 15K, shouldnt make that much of a diff.
427  */
428 #define DUMP_BUF_SIZE   0x3C00
429 #endif
430
431 #define MIN(a, b) ((u32)(a) < (u32)(b) ? (a) : (b))
432 #define MAX(a, b) ((u32)(a) > (u32)(b) ? (a) : (b))
433
434 struct mcast_address {
435     unsigned char          address[6];
436     struct mcast_address   *next;
437 };
438
439 #define CARD_DOWN                       0x00000000
440 #define CARD_UP                         0x00000001
441 #define CARD_FAIL                       0x00000002
442 #define CARD_DIAG                       0x00000003
443 #define CARD_SLEEP                      0x00000004
444
445 #define ADAPT_DOWN                      0x00
446 #define ADAPT_UP                        0x01
447 #define ADAPT_FAIL                      0x02
448 #define ADAPT_RESET                     0x03
449 #define ADAPT_SLEEP                     0x04
450
451 #define ADAPT_FLAGS_BOOTTIME            0x0001
452 #define ADAPT_FLAGS_IS64BIT             0x0002
453 #define ADAPT_FLAGS_PENDINGLINKDOWN     0x0004
454 #define ADAPT_FLAGS_FIBERMEDIA          0x0008
455 #define ADAPT_FLAGS_LOCKS_ALLOCED       0x0010
456 #define ADAPT_FLAGS_INT_REGISTERED      0x0020
457 #define ADAPT_FLAGS_LOAD_TIMER_SET      0x0040
458 #define ADAPT_FLAGS_STATS_TIMER_SET     0x0080
459 #define ADAPT_FLAGS_RESET_TIMER_SET     0x0100
460
461 #define LINK_DOWN                       0x00
462 #define LINK_CONFIG                     0x01
463 #define LINK_UP                         0x02
464
465 #define LINK_10MB                       0x00
466 #define LINK_100MB                      0x01
467 #define LINK_AUTOSPEED                  0x02
468 #define LINK_1000MB                     0x03
469 #define LINK_10000MB                    0x04
470
471 #define LINK_HALFD                      0x00
472 #define LINK_FULLD                      0x01
473 #define LINK_AUTOD                      0x02
474
475 #define MAC_DIRECTED                    0x00000001
476 #define MAC_BCAST                       0x00000002
477 #define MAC_MCAST                       0x00000004
478 #define MAC_PROMISC                     0x00000008
479 #define MAC_LOOPBACK                    0x00000010
480 #define MAC_ALLMCAST                    0x00000020
481
482 #define SLIC_DUPLEX(x)    ((x==LINK_FULLD) ? "FDX" : "HDX")
483 #define SLIC_SPEED(x)     ((x==LINK_100MB) ? "100Mb" :                  \
484                                 ((x==LINK_1000MB) ? "1000Mb" : " 10Mb"))
485 #define SLIC_LINKSTATE(x) ((x==LINK_DOWN) ? "Down" : "Up  ")
486 #define SLIC_ADAPTER_STATE(x) ((x==ADAPT_UP) ? "UP" : "Down")
487 #define SLIC_CARD_STATE(x)    ((x==CARD_UP) ? "UP" : "Down")
488
489
490 struct ether_header {
491     unsigned char    ether_dhost[6];
492     unsigned char    ether_shost[6];
493     ushort   ether_type;
494 };
495
496
497 #define NUM_CFG_SPACES      2
498 #define NUM_CFG_REGS        64
499
500 /*
501  * We split LSS sends across four microcode queues derived from
502  * destination TCP port (if TCP/IP).
503  */
504 #define SXG_LARGE_SEND_QUEUE_MASK    0x3
505 #define ISCSI_PORT                   0xbc0c                  /* 3260 */
506
507 struct physcard {
508     struct adapter_t            *adapter[SLIC_MAX_PORTS];
509     struct physcard             *next;
510     unsigned int                adapters_allocd;
511 };
512
513 struct sxgbase_driver {
514         spinlock_t      driver_lock;
515         unsigned long   flags;  /* irqsave for spinlock */
516         u32             num_sxg_cards;
517         u32             num_sxg_ports;
518         u32             num_sxg_ports_active;
519         u32             dynamic_intagg;
520         struct physcard *phys_card;
521 };
522
523
524 struct adapter_t {
525         void *               ifp;
526         unsigned int                port;
527         struct physcard        *physcard;
528         unsigned int                physport;
529         unsigned int                slotnumber;
530         unsigned int                functionnumber;
531         ushort              vendid;
532         ushort              devid;
533         ushort              subsysid;
534         u32             irq;
535
536         void __iomem *  base_addr;
537         u32             memorylength;
538         u32             drambase;
539         u32             dramlength;
540         unsigned int                activated;
541         u32             intrregistered;
542         unsigned int                isp_initialized;
543         unsigned char               state;
544         unsigned char               linkstate;
545         unsigned int                flags;
546         unsigned char               macaddr[6];
547         unsigned char               currmacaddr[6];
548         u32             macopts;
549         ushort              devflags_prev;
550         u64             mcastmask;
551         struct mcast_address   *mcastaddrs;
552         struct timer_list   pingtimer;
553         u32             pingtimerset;
554         struct timer_list   statstimer;
555         u32             statstimerset;
556         struct timer_list   vpci_timer;
557         u32             vpci_timerset;
558         struct timer_list   loadtimer;
559         u32             loadtimerset;
560
561         u32             xmitq_full;
562         u32             all_reg_writes;
563         u32             icr_reg_writes;
564         u32             isr_reg_writes;
565         u32             error_interrupts;
566         u32             error_rmiss_interrupts;
567         u32             rx_errors;
568         u32             rcv_drops;
569         u32             rcv_interrupts;
570         u32             xmit_interrupts;
571         u32             linkevent_interrupts;
572         u32             upr_interrupts;
573         u32             num_isrs;
574         u32             false_interrupts;
575         u32             tx_packets;
576         u32             xmit_completes;
577         u32             tx_drops;
578         u32             rcv_broadcasts;
579         u32             rcv_multicasts;
580         u32             rcv_unicasts;
581         u32             max_isr_rcvs;
582         u32             max_isr_xmits;
583         u32             rcv_interrupt_yields;
584         u32             intagg_period;
585         struct net_device_stats stats;
586         u32 *                   MiniportHandle;         /* Our miniport handle */
587         enum SXG_STATE          State;                  /* Adapter state */
588         enum SXG_LINK_STATE     LinkState;              /* Link state */
589         u64                     LinkSpeed;              /* Link Speed */
590         u32                     PowerState;             /* NDIS power state */
591         struct adapter_t        *Next;                  /* Linked list */
592         ushort                  AdapterID;              /* 1..n */
593         struct net_device *         netdev;
594         struct net_device *         next_netdevice;
595         struct pci_dev            *pcidev;
596
597         struct sxg_multicast_address    *MulticastAddrs; /* Multicast list */
598         u64                     MulticastMask;          /* Multicast mask */
599         u32                     *InterruptHandle;       /* Register Interrupt handle */
600         u32                     InterruptLevel;         /* From Resource list */
601         u32                     InterruptVector;        /* From Resource list */
602         spinlock_t              AdapterLock;    /* Serialize access adapter routines */
603         spinlock_t              Bit64RegLock;   /* For writing 64-bit addresses */
604         struct sxg_hw_regs      *HwRegs;        /* Sahara HW Register Memory (BAR0/1) */
605         struct sxg_ucode_regs   *UcodeRegs;     /* Microcode Register Memory (BAR2/3) */
606         struct sxg_tcb_regs     *TcbRegs;       /* Same as Ucode regs - See sxghw.h */
607         ushort          FrameSize;      /* Maximum frame size */
608         u32 *           DmaHandle;      /* NDIS DMA handle */
609         u32 *           PacketPoolHandle;       /* Used with NDIS 5.2 only.  Don't ifdef out */
610         u32 *           BufferPoolHandle;       /* Used with NDIS 5.2 only.  Don't ifdef out */
611         u32             MacFilter;              /* NDIS MAC Filter */
612         struct sxg_event_ring   *EventRings;    /* Host event rings.  1/CPU to 16 max */
613         dma_addr_t              PEventRings;    /* Physical address */
614         u32             NextEvent[SXG_MAX_RSS]; /* Current location in ring */
615         dma_addr_t      PTcbBuffers;            /* TCB Buffers - physical address */
616         dma_addr_t      PTcbCompBuffers;        /* TCB Composite Buffers - phys addr */
617         struct sxg_xmt_ring     *XmtRings;      /* Transmit rings */
618         dma_addr_t              PXmtRings;      /* Transmit rings - physical address */
619         struct sxg_ring_info    XmtRingZeroInfo;        /* Transmit ring 0 info */
620
621         spinlock_t      XmtZeroLock;    /* Transmit ring 0 lock */
622         u32 *           XmtRingZeroIndex;       /* Shared XMT ring 0 index */
623         dma_addr_t      PXmtRingZeroIndex;      /* Shared XMT ring 0 index - physical */
624         struct list_entry       FreeProtocolHeaders;/* Free protocol headers */
625         u32             FreeProtoHdrCount;      /* Count */
626         void *          ProtocolHeaders;        /* Block of protocol header */
627         dma_addr_t      PProtocolHeaders;       /* Block of protocol headers - phys */
628
629         struct sxg_rcv_ring     *RcvRings;      /* Receive rings */
630         dma_addr_t      PRcvRings;              /* Receive rings - physical address */
631         struct sxg_ucode_stats  *ucode_stats;           /* Ucode Stats  */
632         /* Ucode Stats - physical address */
633         dma_addr_t              pucode_stats;
634
635         struct sxg_ring_info    RcvRingZeroInfo;        /* Receive ring 0 info */
636
637         u32 *           Isr;            /* Interrupt status register */
638         dma_addr_t      PIsr;           /* ISR - physical address */
639         u32             IsrCopy[SXG_MAX_RSS];   /* Copy of ISR */
640         ushort          InterruptsEnabled;      /* Bitmask of enabled vectors */
641         unsigned char   *IndirectionTable;      /* RSS indirection table */
642         dma_addr_t      PIndirectionTable;      /* Physical address */
643         ushort          RssTableSize;           /* From NDIS_RECEIVE_SCALE_PARAMETERS */
644         ushort          HashKeySize;            /* From NDIS_RECEIVE_SCALE_PARAMETERS */
645         unsigned char   HashSecretKey[40];      /* rss key */
646         u32             HashInformation;
647         /* Receive buffer queues */
648         spinlock_t      RcvQLock;               /* Receive Queue Lock */
649         struct list_entry       FreeRcvBuffers;         /* Free SXG_DATA_BUFFER queue */
650         struct list_entry       FreeRcvBlocks;          /* Free SXG_RCV_DESCRIPTOR_BLOCK Q */
651         struct list_entry       AllRcvBlocks;           /* All SXG_RCV_BLOCKs */
652         ushort          FreeRcvBufferCount;     /* Number of free rcv data buffers */
653         ushort          FreeRcvBlockCount;      /* # of free rcv descriptor blocks */
654         ushort          AllRcvBlockCount;       /* Number of total receive blocks */
655         ushort          ReceiveBufferSize;      /* SXG_RCV_DATA/JUMBO_BUFFER_SIZE only */
656         /* Converted this to a atomic variable
657         u32                     AllocationsPending;     */
658         atomic_t                pending_allocations;
659         u32             AllocationsPending;     /* Receive allocation pending */
660         u32             RcvBuffersOnCard;       /* SXG_DATA_BUFFERS owned by card */
661         /* SGL buffers */
662         spinlock_t      SglQLock;       /* SGL Queue Lock */
663         struct list_entry       FreeSglBuffers;         /* Free struct sxg_scatter_gather */
664         struct list_entry       AllSglBuffers;          /* All struct sxg_scatter_gather */
665         ushort          FreeSglBufferCount;     /* Number of free SGL buffers */
666         ushort          AllSglBufferCount;      /* Number of total SGL buffers */
667         u32             CurrentTime;            /* Tick count */
668         u32             FastpathConnections;/* # of fastpath connections */
669         /* Various single-bit flags: */
670         u32             BasicAllocations:1;     /* Locks and listheads */
671         u32             IntRegistered:1;        /* Interrupt registered */
672         u32             PingOutstanding:1;      /* Ping outstanding to card */
673         u32             Dead:1;                         /* Card dead */
674         u32             DumpDriver:1;           /* OID_SLIC_DRIVER_DUMP request */
675         u32             DumpCard:1;                     /* OID_SLIC_CARD_DUMP request */
676         u32             DumpCmdRunning:1;       /* Dump command in progress */
677         u32             DebugRunning:1;         /* AGDB debug in progress */
678         u32             JumboEnabled:1;         /* Jumbo frames enabled */
679         u32             MsiEnabled:1;           /* MSI interrupt enabled */
680         u32             RssEnabled:1;           /* RSS Enabled */
681         u32             FailOnBadEeprom:1;      /* Fail on Bad Eeprom */
682         u32             DiagStart:1;            /* Init adapter for diagnostic start */
683         /* Stats */
684         u32             PendingRcvCount;        /* Outstanding rcv indications */
685         u32             PendingXmtCount;        /* Outstanding send requests */
686         struct sxg_stats        Stats;                          /* Statistics */
687         u32             ReassBufs;                      /* Number of reassembly buffers */
688         /* Card Crash Info */
689         ushort          CrashLocation;          /* Microcode crash location */
690         unsigned char   CrashCpu;                       /* Sahara CPU ID */
691         /* Diagnostics */
692         /*      PDIAG_CMD       DiagCmds; */                    /* List of free diagnostic commands */
693         /*      PDIAG_BUFFER    DiagBuffers; */         /* List of free diagnostic buffers */
694         /*      PDIAG_REQ       DiagReqQ; */                    /* List of outstanding (asynchronous) diag requests */
695         /*      u32             DiagCmdTimeout; */              /* Time out for diag cmds (seconds) XXXTODO - replace with SXG_PARAM var? */
696         /*      unsigned char   DiagDmaDesc[DMA_CPU_CTXS]; */           /* Free DMA descriptors bit field (32 CPU ctx * 8 DMA ctx) */
697         /*
698          * Put preprocessor-conditional fields at the end so we don't
699          * have to recompile sxgdbg everytime we reconfigure the driver
700          */
701 #if defined(CONFIG_X86)
702         u32             AddrUpper;                      /* Upper 32 bits of 64-bit register */
703 #endif
704         /*#if SXG_FAILURE_DUMP */
705         /*      NDIS_EVENT      DumpThreadEvent; */     /* syncronize dump thread */
706         /*      BOOLEAN         DumpThreadRunning; */   /* termination flag */
707         /*      PSXG_DUMP_CMD   DumpBuffer; */                  /* 68k - Cmd and Buffer */
708         /*      dma_addr_t      PDumpBuffer; */         /* Physical address */
709         /*#endif */ /* SXG_FAILURE_DUMP */
710 };
711
712 #if SLIC_DUMP_ENABLED
713 #define SLIC_DUMP_REQUESTED      1
714 #define SLIC_DUMP_IN_PROGRESS    2
715 #define SLIC_DUMP_DONE           3
716
717 /*
718  * Microcode crash information structure.  This
719  * structure is written out to the card's SRAM when the microcode panic's.
720  */
721 struct slic_crash_info {
722     ushort  cpu_id;
723     ushort  crash_pc;
724 };
725
726 #define CRASH_INFO_OFFSET   0x155C
727
728 #endif
729
730 #define UPDATE_STATS(largestat, newstat, oldstat)                        \
731 {                                                                        \
732     if ((newstat) < (oldstat))                                           \
733         (largestat) += ((newstat) + (0xFFFFFFFF - oldstat + 1));         \
734     else                                                                 \
735         (largestat) += ((newstat) - (oldstat));                          \
736 }
737
738 #define UPDATE_STATS_GB(largestat, newstat, oldstat)                     \
739 {                                                                        \
740     (largestat) += ((newstat) - (oldstat));                              \
741 }
742
743 #define ETHER_EQ_ADDR(_AddrA, _AddrB, _Result)                          \
744 {                                                                       \
745     _Result = TRUE;                                                     \
746     if (*(u32 *)(_AddrA) != *(u32 *)(_AddrB))                           \
747         _Result = FALSE;                                                \
748     if (*(u16 *)(&((_AddrA)[4])) != *(u16 *)(&((_AddrB)[4])))           \
749         _Result = FALSE;                                                \
750 }
751
752 #define ETHERMAXFRAME   1514
753 #define JUMBOMAXFRAME   9014
754
755 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
756 #define   SXG_GET_ADDR_LOW(_addr)  (u32)((u64)(_addr) & 0x00000000FFFFFFFF)
757 #define   SXG_GET_ADDR_HIGH(_addr)                                      \
758                         (u32)(((u64)(_addr) >> 32) & 0x00000000FFFFFFFF)
759 #else
760 #define   SXG_GET_ADDR_LOW(_addr)   (u32)_addr
761 #define   SXG_GET_ADDR_HIGH(_addr)  (u32)0
762 #endif
763
764 #define FLUSH       TRUE
765 #define DONT_FLUSH  FALSE
766
767 #define SIOCSLICDUMPCARD         (SIOCDEVPRIVATE+9)
768 #define SIOCSLICSETINTAGG        (SIOCDEVPRIVATE+10)
769 #define SIOCSLICTRACEDUMP        (SIOCDEVPRIVATE+11)
770
771 extern struct ethtool_ops sxg_nic_ethtool_ops;
772 #define SXG_COMPLETE_SLOW_SEND_LIMIT    128
773 #endif /*  __SXG_DRIVER_H__ */