~ubuntu-branches/ubuntu/karmic/linux-ports/karmic

« back to all changes in this revision

Viewing changes to drivers/staging/sxg/sxghif.h

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich, Luke Yelavich, Michael Casadevall, Tim Gardner, Upstream Kernel Changes
  • Date: 2009-05-06 18:18:55 UTC
  • Revision ID: james.westby@ubuntu.com-20090506181855-t00baeevpnvd9o7a
Tags: 2.6.30-1.1
[ Luke Yelavich ]
* initial release for karmic
* SAUCE: rebase-ports - adjust for the karmic ports kernel
* SAUCE: rebase-ports - also remove abi dirs/files on rebase
* Update configs after rebase against mainline Jaunty tree
* [Config] Disable CONFIG_BLK_DEV_UB and CONFIG_USB_LIBUSUAL as per
  mainline jaunty
* forward-port patch to drbd for powerpc compilation
* [Config] disable CONFIG_LENOVO_SL_LAPTOP for i386 due to FTBFS
* add .o files found in arch/powerpc/lib to all powerpc kernel header
  packages
* [Config] enable CONFIG_DRM_I915_KMS for i386 as per karmic mainline

[ Michael Casadevall ]

* Disable kgdb on sparc64
* [sparc] [Config] Disable GPIO LEDS
* [ia64] Rename -ia64-generic to -ia64 in line with other architectures
* Correct kernel image path for sparc builds
* [hppa] Fix HPPA config files to build modules for all udebian

Rebase on top of karmic mainline 2.6.30-1.1

[ Tim Gardner ]

* [Config] armel: disable staging drivers, fixes FTBS
* [Config] armel imx51: Disable CONFIG_MTD_NAND_MXC, fixes FTBS

[ Upstream Kernel Changes ]

* mpt2sas: Change reset_type enum to avoid namespace collision.
  Submitted upstream.

* Initial release after rebasing against v2.6.30-rc3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
 
1
/*******************************************************************
2
2
 * Copyright � 1997-2007 Alacritech, Inc. All rights reserved
3
3
 *
4
4
 * $Id: sxghif.h,v 1.5 2008/07/24 19:18:22 chris Exp $
7
7
 *
8
8
 * This file contains structures and definitions for the
9
9
 * Alacritech Sahara host interface
10
 
 */
11
 
 
12
 
/*******************************************************************************
13
 
 * UCODE Registers
14
 
 *******************************************************************************/
15
 
struct SXG_UCODE_REGS {
16
 
        // Address 0 - 0x3F = Command codes 0-15 for TCB 0.  Excode 0
17
 
        u32 Icr;                // Code = 0 (extended), ExCode = 0 - Int control
18
 
        u32 RsvdReg1;           // Code = 1 - TOE -NA
19
 
        u32 RsvdReg2;           // Code = 2 - TOE -NA
20
 
        u32 RsvdReg3;           // Code = 3 - TOE -NA
21
 
        u32 RsvdReg4;           // Code = 4 - TOE -NA
22
 
        u32 RsvdReg5;           // Code = 5 - TOE -NA
23
 
        u32 CardUp;             // Code = 6 - Microcode initialized when 1
24
 
        u32 RsvdReg7;           // Code = 7 - TOE -NA
25
 
        u32 CodeNotUsed[8];     // Codes 8-15 not used.  ExCode = 0
26
 
        // This brings us to ExCode 1 at address 0x40 = Interrupt status pointer
27
 
        u32 Isp;                // Code = 0 (extended), ExCode = 1
28
 
        u32 PadEx1[15];         // Codes 1-15 not used with extended codes
29
 
        // ExCode 2 = Interrupt Status Register
30
 
        u32 Isr;                // Code = 0 (extended), ExCode = 2
 
10
 ******************************************************************/
 
11
 
 
12
#define DBG                             1
 
13
 
 
14
/* UCODE Registers */
 
15
struct sxg_ucode_regs {
 
16
        /* Address 0 - 0x3F = Command codes 0-15 for TCB 0.  Excode 0 */
 
17
        u32     Icr;            /* Code = 0 (extended), ExCode = 0 - Int control */
 
18
        u32     RsvdReg1;       /* Code = 1 - TOE -NA */
 
19
        u32     RsvdReg2;       /* Code = 2 - TOE -NA */
 
20
        u32     RsvdReg3;       /* Code = 3 - TOE -NA */
 
21
        u32     RsvdReg4;       /* Code = 4 - TOE -NA */
 
22
        u32     RsvdReg5;       /* Code = 5 - TOE -NA */
 
23
        u32     CardUp;         /* Code = 6 - Microcode initialized when 1 */
 
24
        u32     RsvdReg7;       /* Code = 7 - TOE -NA */
 
25
        u32     ConfigStat;     /* Code = 8 - Configuration data load status */
 
26
        u32     RsvdReg9;       /* Code = 9 - TOE -NA */
 
27
        u32     CodeNotUsed[6]; /* Codes 10-15 not used.  ExCode = 0 */
 
28
        /* This brings us to ExCode 1 at address 0x40 = Interrupt status pointer */
 
29
        u32     Isp;            /* Code = 0 (extended), ExCode = 1 */
 
30
        u32     PadEx1[15];     /* Codes 1-15 not used with extended codes */
 
31
        /* ExCode 2 = Interrupt Status Register */
 
32
        u32     Isr;            /* Code = 0 (extended), ExCode = 2 */
31
33
        u32 PadEx2[15];
32
 
        // ExCode 3 = Event base register.  Location of event rings
33
 
        u32 EventBase;          // Code = 0 (extended), ExCode = 3
 
34
        /* ExCode 3 = Event base register.  Location of event rings */
 
35
        u32     EventBase;      /* Code = 0 (extended), ExCode = 3 */
34
36
        u32 PadEx3[15];
35
 
        // ExCode 4 = Event ring size
36
 
        u32 EventSize;          // Code = 0 (extended), ExCode = 4
 
37
        /* ExCode 4 = Event ring size */
 
38
        u32     EventSize;      /* Code = 0 (extended), ExCode = 4 */
37
39
        u32 PadEx4[15];
38
 
        // ExCode 5 = TCB Buffers base address
39
 
        u32 TcbBase;            // Code = 0 (extended), ExCode = 5
 
40
        /* ExCode 5 = TCB Buffers base address */
 
41
        u32     TcbBase;        /* Code = 0 (extended), ExCode = 5 */
40
42
        u32 PadEx5[15];
41
 
        // ExCode 6 = TCB Composite Buffers base address
42
 
        u32 TcbCompBase;        // Code = 0 (extended), ExCode = 6
 
43
        /* ExCode 6 = TCB Composite Buffers base address */
 
44
        u32     TcbCompBase;    /* Code = 0 (extended), ExCode = 6 */
43
45
        u32 PadEx6[15];
44
 
        // ExCode 7 = Transmit ring base address
45
 
        u32 XmtBase;            // Code = 0 (extended), ExCode = 7
 
46
        /* ExCode 7 = Transmit ring base address */
 
47
        u32     XmtBase;        /* Code = 0 (extended), ExCode = 7 */
46
48
        u32 PadEx7[15];
47
 
        // ExCode 8 = Transmit ring size
48
 
        u32 XmtSize;            // Code = 0 (extended), ExCode = 8
 
49
        /* ExCode 8 = Transmit ring size */
 
50
        u32     XmtSize;        /* Code = 0 (extended), ExCode = 8 */
49
51
        u32 PadEx8[15];
50
 
        // ExCode 9 = Receive ring base address
51
 
        u32 RcvBase;            // Code = 0 (extended), ExCode = 9
 
52
        /* ExCode 9 = Receive ring base address */
 
53
        u32     RcvBase;        /* Code = 0 (extended), ExCode = 9 */
52
54
        u32 PadEx9[15];
53
 
        // ExCode 10 = Receive ring size
54
 
        u32 RcvSize;            // Code = 0 (extended), ExCode = 10
 
55
        /* ExCode 10 = Receive ring size */
 
56
        u32     RcvSize;        /* Code = 0 (extended), ExCode = 10 */
55
57
        u32 PadEx10[15];
56
 
        // ExCode 11 = Read EEPROM Config
57
 
        u32 Config;             // Code = 0 (extended), ExCode = 11
 
58
        /* ExCode 11 = Read EEPROM/Flash Config */
 
59
        u32     Config;         /* Code = 0 (extended), ExCode = 11 */
58
60
        u32 PadEx11[15];
59
 
        // ExCode 12 = Multicast bits 31:0
60
 
        u32 McastLow;           // Code = 0 (extended), ExCode = 12
 
61
        /* ExCode 12 = Multicast bits 31:0 */
 
62
        u32     McastLow;       /* Code = 0 (extended), ExCode = 12 */
61
63
        u32 PadEx12[15];
62
 
        // ExCode 13 = Multicast bits 63:32
63
 
        u32 McastHigh;          // Code = 0 (extended), ExCode = 13
 
64
        /* ExCode 13 = Multicast bits 63:32 */
 
65
        u32     McastHigh;      /* Code = 0 (extended), ExCode = 13 */
64
66
        u32 PadEx13[15];
65
 
        // ExCode 14 = Ping
66
 
        u32 Ping;               // Code = 0 (extended), ExCode = 14
 
67
        /* ExCode 14 = Ping */
 
68
        u32     Ping;           /* Code = 0 (extended), ExCode = 14 */
67
69
        u32 PadEx14[15];
68
 
        // ExCode 15 = Link MTU
69
 
        u32 LinkMtu;            // Code = 0 (extended), ExCode = 15
 
70
        /* ExCode 15 = Link MTU */
 
71
        u32     LinkMtu;        /* Code = 0 (extended), ExCode = 15 */
70
72
        u32 PadEx15[15];
71
 
        // ExCode 16 = Download synchronization
72
 
        u32 LoadSync;           // Code = 0 (extended), ExCode = 16
 
73
        /* ExCode 16 = Download synchronization */
 
74
        u32     LoadSync;       /* Code = 0 (extended), ExCode = 16 */
73
75
        u32 PadEx16[15];
74
 
        // ExCode 17 = Upper DRAM address bits on 32-bit systems
75
 
        u32 Upper;              // Code = 0 (extended), ExCode = 17
 
76
        /* ExCode 17 = Upper DRAM address bits on 32-bit systems */
 
77
        u32     Upper;          /* Code = 0 (extended), ExCode = 17 */
76
78
        u32 PadEx17[15];
77
 
        // ExCode 18 = Slowpath Send Index Address
78
 
        u32 SPSendIndex;        // Code = 0 (extended), ExCode = 18
 
79
        /* ExCode 18 = Slowpath Send Index Address */
 
80
        u32     SPSendIndex;    /* Code = 0 (extended), ExCode = 18 */
79
81
        u32 PadEx18[15];
80
 
        u32 RsvdXF;             // Code = 0 (extended), ExCode = 19
 
82
        /* ExCode 19 = Get ucode statistics */
 
83
        u32     GetUcodeStats;  /* Code = 0 (extended), ExCode = 19 */
81
84
        u32 PadEx19[15];
82
 
        // ExCode 20 = Aggregation
83
 
        u32 Aggregation;        // Code = 0 (extended), ExCode = 20
 
85
        /* ExCode 20 = Aggregation - See sxgmisc.c:SxgSetInterruptAggregation */
 
86
        u32     Aggregation;    /* Code = 0 (extended), ExCode = 20 */
84
87
        u32 PadEx20[15];
85
 
        // ExCode 21 = Receive MDL push timer
86
 
        u32 PushTicks;          // Code = 0 (extended), ExCode = 21
 
88
        /* ExCode 21 = Receive MDL push timer */
 
89
        u32     PushTicks;      /* Code = 0 (extended), ExCode = 21 */
87
90
        u32 PadEx21[15];
88
 
        // ExCode 22 = TOE NA
89
 
        u32 AckFrequency;       // Code = 0 (extended), ExCode = 22
 
91
        /* ExCode 22 = ACK Frequency */
 
92
        u32     AckFrequency;   /* Code = 0 (extended), ExCode = 22 */
90
93
        u32 PadEx22[15];
91
 
        // ExCode 23 = TOE NA
 
94
        /* ExCode 23 = TOE NA */
92
95
        u32 RsvdReg23;
93
96
        u32 PadEx23[15];
94
 
        // ExCode 24 = TOE NA
 
97
        /* ExCode 24 = TOE NA */
95
98
        u32 RsvdReg24;
96
99
        u32 PadEx24[15];
97
 
        // ExCode 25 = TOE NA
98
 
        u32 RsvdReg25;          // Code = 0 (extended), ExCode = 25
 
100
        /* ExCode 25 = TOE NA */
 
101
        u32     RsvdReg25;      /* Code = 0 (extended), ExCode = 25 */
99
102
        u32 PadEx25[15];
100
 
        // ExCode 26 = Receive checksum requirements
101
 
        u32 ReceiveChecksum;    // Code = 0 (extended), ExCode = 26
 
103
        /* ExCode 26 = Receive checksum requirements */
 
104
        u32     ReceiveChecksum;        /* Code = 0 (extended), ExCode = 26 */
102
105
        u32 PadEx26[15];
103
 
        // ExCode 27 = RSS Requirements
104
 
        u32 Rss;                // Code = 0 (extended), ExCode = 27
 
106
        /* ExCode 27 = RSS Requirements */
 
107
        u32     Rss;            /* Code = 0 (extended), ExCode = 27 */
105
108
        u32 PadEx27[15];
106
 
        // ExCode 28 = RSS Table
107
 
        u32 RssTable;           // Code = 0 (extended), ExCode = 28
 
109
        /* ExCode 28 = RSS Table */
 
110
        u32     RssTable;       /* Code = 0 (extended), ExCode = 28 */
108
111
        u32 PadEx28[15];
109
 
        // ExCode 29 = Event ring release entries
110
 
        u32 EventRelease;       // Code = 0 (extended), ExCode = 29
 
112
        /* ExCode 29 = Event ring release entries */
 
113
        u32     EventRelease;   /* Code = 0 (extended), ExCode = 29 */
111
114
        u32 PadEx29[15];
112
 
        // ExCode 30 = Number of receive bufferlist commands on ring 0
113
 
        u32 RcvCmd;             // Code = 0 (extended), ExCode = 30
 
115
        /* ExCode 30 = Number of receive bufferlist commands on ring 0 */
 
116
        u32     RcvCmd;         /* Code = 0 (extended), ExCode = 30 */
114
117
        u32 PadEx30[15];
115
 
        // ExCode 31 = slowpath transmit command - Data[31:0] = 1
116
 
        u32 XmtCmd;             // Code = 0 (extended), ExCode = 31
 
118
        /* ExCode 31 = slowpath transmit command - Data[31:0] = 1 */
 
119
        u32     XmtCmd;         /* Code = 0 (extended), ExCode = 31 */
117
120
        u32 PadEx31[15];
118
 
        // ExCode 32 = Dump command
119
 
        u32 DumpCmd;            // Code = 0 (extended), ExCode = 32
 
121
        /* ExCode 32 = Dump command */
 
122
        u32     DumpCmd;        /* Code = 0 (extended), ExCode = 32 */
120
123
        u32 PadEx32[15];
121
 
        // ExCode 33 = Debug command
122
 
        u32 DebugCmd;           // Code = 0 (extended), ExCode = 33
 
124
        /* ExCode 33 = Debug command */
 
125
        u32     DebugCmd;       /* Code = 0 (extended), ExCode = 33 */
123
126
        u32 PadEx33[15];
124
 
        // There are 128 possible extended commands - each of account for 16
125
 
        // words (including the non-relevent base command codes 1-15).
126
 
        // Pad for the remainder of these here to bring us to the next CPU
127
 
        // base.  As extended codes are added, reduce the first array value in
128
 
        // the following field
129
 
        u32 PadToNextCpu[94][16];       // 94 = 128 - 34 (34 = Excodes 0 - 33)
 
127
        /*
 
128
         * There are 128 possible extended commands - each of account for 16
 
129
         * words (including the non-relevent base command codes 1-15).
 
130
         * Pad for the remainder of these here to bring us to the next CPU
 
131
         * base.  As extended codes are added, reduce the first array value in
 
132
         * the following field
 
133
         */
 
134
        u32 PadToNextCpu[94][16];       /* 94 = 128 - 34 (34 = Excodes 0 - 33)*/
130
135
};
131
136
 
132
 
// Interrupt control register (0) values
 
137
/* Interrupt control register (0) values */
133
138
#define SXG_ICR_DISABLE                                 0x00000000
134
139
#define SXG_ICR_ENABLE                                  0x00000001
135
140
#define SXG_ICR_MASK                                    0x00000002
139
144
        ((((_MessageId) << SXG_ICR_MSGID_SHIFT) &       \
140
145
          SXG_ICR_MSGID_MASK) | (_Data))
141
146
 
142
 
// The Microcode supports up to 16 RSS queues
143
 
#define SXG_MAX_RSS                             16
144
 
#define SXG_MAX_RSS_TABLE_SIZE  256     // 256-byte max
145
 
 
146
 
#define SXG_RSS_TCP6                            0x00000001      // RSS TCP over IPv6
147
 
#define SXG_RSS_TCP4                            0x00000002      // RSS TCP over IPv4
148
 
#define SXG_RSS_LEGACY                          0x00000004      // Line-base interrupts
149
 
#define SXG_RSS_TABLE_SIZE                      0x0000FF00      // Table size mask
 
147
#define SXG_MIN_AGG_DEFAULT     0x0010  /* Minimum aggregation default */
 
148
#define SXG_MAX_AGG_DEFAULT     0x0040  /* Maximum aggregation default */
 
149
#define SXG_MAX_AGG_SHIFT       16      /* Maximum in top 16 bits of register */
 
150
/* Disable interrupt aggregation on xmt */
 
151
#define SXG_AGG_XMT_DISABLE     0x80000000
 
152
 
 
153
/* The Microcode supports up to 16 RSS queues (RevB) */
 
154
#define SXG_MAX_RSS                     16
 
155
#define SXG_MAX_RSS_REVA                8
 
156
 
 
157
#define SXG_MAX_RSS_TABLE_SIZE  256             /* 256-byte max */
 
158
 
 
159
#define SXG_RSS_REVA_TCP6       0x00000001      /* RSS TCP over IPv6 */
 
160
#define SXG_RSS_REVA_TCP4       0x00000002      /* RSS TCP over IPv4 */
 
161
#define SXG_RSS_IP              0x00000001      /* RSS TCP over IPv6 */
 
162
#define SXG_RSS_TCP             0x00000002      /* RSS TCP over IPv4 */
 
163
#define SXG_RSS_LEGACY          0x00000004      /* Line-base interrupts */
 
164
#define SXG_RSS_TABLE_SIZE      0x0000FF00      /* Table size mask */
 
165
 
150
166
#define SXG_RSS_TABLE_SHIFT                     8
151
 
#define SXG_RSS_BASE_CPU                        0x00FF0000      // Base CPU (not used)
 
167
#define SXG_RSS_BASE_CPU        0x00FF0000      /* Base CPU (not used) */
152
168
#define SXG_RSS_BASE_SHIFT                      16
153
169
 
154
 
#define SXG_RCV_IP_CSUM_ENABLED         0x00000001      // ExCode 26 (ReceiveChecksum)
155
 
#define SXG_RCV_TCP_CSUM_ENABLED        0x00000002      // ExCode 26 (ReceiveChecksum)
 
170
#define SXG_RCV_IP_CSUM_ENABLED         0x00000001      /* ExCode 26 (ReceiveChecksum) */
 
171
#define SXG_RCV_TCP_CSUM_ENABLED        0x00000002      /* ExCode 26 (ReceiveChecksum) */
156
172
 
157
173
#define SXG_XMT_CPUID_SHIFT                     16
158
174
 
159
 
#if VPCI
160
 
#define SXG_CHECK_FOR_HANG_TIME         3000
161
 
#else
 
175
/*
 
176
 * Status returned by ucode in the ConfigStat reg (see above) when attempted
 
177
 * to load configuration data from the EEPROM/Flash.
 
178
 */
 
179
#define SXG_CFG_TIMEOUT         1       /* init value - timeout if unchanged */
 
180
#define SXG_CFG_LOAD_EEPROM     2       /* config data loaded from EEPROM */
 
181
#define SXG_CFG_LOAD_FLASH      3       /* config data loaded from flash */
 
182
#define SXG_CFG_LOAD_INVALID    4       /* no valid config data found */
 
183
#define SXG_CFG_LOAD_ERROR      5       /* hardware error */
 
184
 
162
185
#define SXG_CHECK_FOR_HANG_TIME         5
163
 
#endif
164
186
 
165
187
/*
166
188
 * TCB registers - This is really the same register memory area as UCODE_REGS
167
189
 * above, but defined differently.  Bits 17:06 of the address define the TCB,
168
190
 * which means each TCB area occupies 0x40 (64) bytes, or 16 u32S.  What really
169
191
 * is happening is that these registers occupy the "PadEx[15]" areas in the
170
 
 * SXG_UCODE_REGS definition above
 
192
 * struct sxg_ucode_regs definition above
171
193
 */
172
 
struct SXG_TCB_REGS {
173
 
        u32 ExCode;             /* Extended codes - see SXG_UCODE_REGS */
174
 
        u32 Xmt;                /* Code = 1 - # of Xmt descriptors added to ring */
175
 
        u32 Rcv;                /* Code = 2 - # of Rcv descriptors added to ring */
176
 
        u32 Rsvd1;              /* Code = 3 - TOE NA */
177
 
        u32 Rsvd2;              /* Code = 4 - TOE NA */
178
 
        u32 Rsvd3;              /* Code = 5 - TOE NA */
179
 
        u32 Invalid;            /* Code = 6 - Reserved for "CardUp" see above */
180
 
        u32 Rsvd4;              /* Code = 7 - TOE NA */
181
 
        u32 Rsvd5;              /* Code = 8 - TOE NA */
182
 
        u32 Pad[7];             /* Codes 8-15 - Not used. */
 
194
struct sxg_tcb_regs {
 
195
        u32 ExCode;     /* Extended codes - see SXG_UCODE_REGS */
 
196
        u32 Xmt;        /* Code = 1 - # of Xmt descriptors added to ring */
 
197
        u32 Rcv;        /* Code = 2 - # of Rcv descriptors added to ring */
 
198
        u32 Rsvd1;      /* Code = 3 - TOE NA */
 
199
        u32 Rsvd2;      /* Code = 4 - TOE NA */
 
200
        u32 Rsvd3;      /* Code = 5 - TOE NA */
 
201
        u32 Invalid1;   /* Code = 6 - Reserved for "CardUp" see above */
 
202
        u32 Rsvd4;      /* Code = 7 - TOE NA */
 
203
        u32 Invalid2;   /* Code = 8 - Reserved for "ConfigStat" see above */
 
204
        u32 Rsvd5;      /* Code = 9 - TOE NA */
 
205
        u32 Pad[6];     /* Codes 10-15 - Not used. */
183
206
};
184
207
 
185
208
/***************************************************************************
206
229
 *                                 ||---|-CpuId of crash
207
230
 *                                 |----/
208
231
 ***************************************************************************/
209
 
#define SXG_ISR_ERR             0x80000000      // Error
210
 
#define SXG_ISR_EVENT           0x40000000      // Event ring event
211
 
#define SXG_ISR_NONE1           0x20000000      // Not used
212
 
#define SXG_ISR_UPC             0x10000000      // Dump/debug command complete
213
 
#define SXG_ISR_LINK            0x08000000      // Link event
214
 
#define SXG_ISR_PDQF            0x04000000      // Processed data queue full
215
 
#define SXG_ISR_RMISS           0x02000000      // Drop - no host buf
216
 
#define SXG_ISR_BREAK           0x01000000      // Breakpoint hit
217
 
#define SXG_ISR_PING            0x00800000      // Heartbeat response
218
 
#define SXG_ISR_DEAD            0x00400000      // Card crash
219
 
#define SXG_ISR_ERFULL          0x00200000      // Event ring full
220
 
#define SXG_ISR_XDROP           0x00100000      // XMT Drop - no DRAM bufs or XMT err
221
 
#define SXG_ISR_SPSEND          0x00080000      // Slow send complete
222
 
#define SXG_ISR_CPU             0x00070000      // Dead CPU mask
223
 
#define SXG_ISR_CPU_SHIFT               16      // Dead CPU shift
224
 
#define SXG_ISR_CRASH           0x0000FFFF      // Crash address mask
 
232
#define SXG_ISR_ERR             0x80000000      /* Error */
 
233
#define SXG_ISR_EVENT           0x40000000      /* Event ring event */
 
234
#define SXG_ISR_NONE1           0x20000000      /* Not used */
 
235
#define SXG_ISR_UPC             0x10000000      /* Dump/debug command complete*/
 
236
#define SXG_ISR_LINK            0x08000000      /* Link event */
 
237
#define SXG_ISR_PDQF            0x04000000      /* Processed data queue full */
 
238
#define SXG_ISR_RMISS           0x02000000      /* Drop - no host buf */
 
239
#define SXG_ISR_BREAK           0x01000000      /* Breakpoint hit */
 
240
#define SXG_ISR_PING            0x00800000      /* Heartbeat response */
 
241
#define SXG_ISR_DEAD            0x00400000      /* Card crash */
 
242
#define SXG_ISR_ERFULL          0x00200000      /* Event ring full */
 
243
#define SXG_ISR_XDROP           0x00100000      /* XMT Drop - no DRAM bufs or XMT err */
 
244
#define SXG_ISR_SPSEND          0x00080000      /* Slow send complete */
 
245
#define SXG_ISR_CPU             0x00070000      /* Dead CPU mask */
 
246
#define SXG_ISR_CPU_SHIFT       16              /* Dead CPU shift */
 
247
#define SXG_ISR_CRASH           0x0000FFFF      /* Crash address mask */
225
248
 
226
249
/***************************************************************************
227
 
 *
228
250
 * Event Ring entry
229
251
 *
230
 
 ***************************************************************************/
231
 
/*
232
252
 *  31                  15                 0
233
253
 *  .___________________.___________________.
234
254
 *  |<------------    Pad 0    ------------>|
270
290
 *    ||------- ISTCPIP
271
291
 *    |-------- SCERR
272
292
 *
273
 
 */
 
293
 ************************************************************************/
274
294
#pragma pack(push, 1)
275
 
struct SXG_EVENT {
276
 
        u32 Pad[1];             // not used
277
 
        u32 SndUna;             // SndUna value
278
 
        u32 Resid;              // receive MDL resid
 
295
struct sxg_event {
 
296
        u32                     Pad[1];         /* not used */
 
297
        u32                     SndUna;         /* SndUna value */
 
298
        u32                     Resid;          /* receive MDL resid */
279
299
        union {
280
 
                void *HostHandle;       // Receive host handle
281
 
                u32 Rsvd1;      // TOE NA
 
300
                void *          HostHandle;     /* Receive host handle */
 
301
                u32             Rsvd1;          /* TOE NA */
282
302
                struct {
283
303
                        u32 NotUsed;
284
 
                        u32 Rsvd2;      // TOE NA
 
304
                        u32     Rsvd2;          /* TOE NA */
285
305
                } Flush;
286
306
        };
287
 
        u32 Toeplitz;           // RSS Toeplitz hash
 
307
        u32                     Toeplitz;       /* RSS Toeplitz hash */
288
308
        union {
289
 
                ushort Rsvd3;   // TOE NA
290
 
                ushort HdrOffset;       // Slowpath
 
309
                ushort          Rsvd3;          /* TOE NA */
 
310
                ushort          HdrOffset;      /* Slowpath */
291
311
        };
292
 
        ushort Length;          //
293
 
        unsigned char Rsvd4;    // TOE NA
294
 
        unsigned char Code;     // Event code
295
 
        unsigned char CommandIndex;     // New ring index
296
 
        unsigned char Status;   // Event status
 
312
        ushort                  Length;
 
313
        unsigned char   Rsvd4;          /* TOE NA */
 
314
        unsigned char   Code;           /* Event code */
 
315
        unsigned char   CommandIndex;   /* New ring index */
 
316
        unsigned char   Status;         /* Event status */
297
317
};
298
318
#pragma pack(pop)
299
319
 
300
 
// Event code definitions
301
 
#define EVENT_CODE_BUFFERS      0x01    // Receive buffer list command (ring 0)
302
 
#define EVENT_CODE_SLOWRCV      0x02    // Slowpath receive
303
 
#define EVENT_CODE_UNUSED       0x04    // Was slowpath commands complete
304
 
 
305
 
// Status values
306
 
#define EVENT_STATUS_VALID      0x80    // Entry valid
307
 
 
308
 
// Slowpath status
309
 
#define EVENT_STATUS_ERROR      0x40    // Completed with error. Index in next byte
310
 
#define EVENT_STATUS_TCPIP4     0x20    // TCPIPv4 frame
311
 
#define EVENT_STATUS_TCPBAD     0x10    // Bad TCP checksum
312
 
#define EVENT_STATUS_IPBAD      0x08    // Bad IP checksum
313
 
#define EVENT_STATUS_RCVERR     0x04    // Slowpath receive error
314
 
#define EVENT_STATUS_IPONLY     0x02    // IP frame
315
 
#define EVENT_STATUS_TCPIP6     0x01    // TCPIPv6 frame
316
 
#define EVENT_STATUS_TCPIP      0x21    // Combination of v4 and v6
317
 
 
318
 
// Event ring
319
 
// Size must be power of 2, between 128 and 16k
320
 
#define EVENT_RING_SIZE         4096    // ??
321
 
#define EVENT_RING_BATCH        16      // Hand entries back 16 at a time.
322
 
#define EVENT_BATCH_LIMIT       256     // Stop processing events after 256 (16 * 16)
323
 
 
324
 
struct SXG_EVENT_RING {
325
 
        struct SXG_EVENT Ring[EVENT_RING_SIZE];
 
320
/* Event code definitions */
 
321
#define EVENT_CODE_BUFFERS      0x01    /* Receive buffer list command (ring 0) */
 
322
#define EVENT_CODE_SLOWRCV      0x02    /* Slowpath receive */
 
323
#define EVENT_CODE_UNUSED       0x04    /* Was slowpath commands complete */
 
324
 
 
325
/* Status values */
 
326
#define EVENT_STATUS_VALID      0x80    /* Entry valid */
 
327
 
 
328
/* Slowpath status */
 
329
#define EVENT_STATUS_ERROR      0x40    /* Completed with error. Index in next byte */
 
330
#define EVENT_STATUS_TCPIP4     0x20    /* TCPIPv4 frame */
 
331
#define EVENT_STATUS_TCPBAD     0x10    /* Bad TCP checksum */
 
332
#define EVENT_STATUS_IPBAD      0x08    /* Bad IP checksum */
 
333
#define EVENT_STATUS_RCVERR     0x04    /* Slowpath receive error */
 
334
#define EVENT_STATUS_IPONLY     0x02    /* IP frame */
 
335
#define EVENT_STATUS_TCPIP6     0x01    /* TCPIPv6 frame */
 
336
#define EVENT_STATUS_TCPIP      0x21    /* Combination of v4 and v6 */
 
337
 
 
338
/*
 
339
 * Event ring
 
340
 * Size must be power of 2, between 128 and 16k
 
341
 */
 
342
#define EVENT_RING_SIZE         4096
 
343
#define EVENT_RING_BATCH        16      /* Hand entries back 16 at a time. */
 
344
/* Stop processing events after 4096 (256 * 16) */
 
345
#define EVENT_BATCH_LIMIT       256
 
346
 
 
347
struct sxg_event_ring {
 
348
        struct sxg_event Ring[EVENT_RING_SIZE];
326
349
};
327
350
 
328
 
/***************************************************************************
329
 
 *
330
 
 * TCB Buffers
331
 
 *
332
 
 ***************************************************************************/
333
 
// Maximum number of TCBS supported by hardware/microcode
 
351
/* TCB Buffers */
 
352
/* Maximum number of TCBS supported by hardware/microcode */
334
353
#define SXG_MAX_TCB             4096
335
 
// Minimum TCBs before we fail initialization
 
354
/* Minimum TCBs before we fail initialization */
336
355
#define SXG_MIN_TCB             512
337
 
// TCB Hash
338
 
// The bucket is determined by bits 11:4 of the toeplitz if we support 4k
339
 
// offloaded connections, 10:4 if we support 2k and so on.
 
356
/*
 
357
 * TCB Hash
 
358
 * The bucket is determined by bits 11:4 of the toeplitz if we support 4k
 
359
 * offloaded connections, 10:4 if we support 2k and so on.
 
360
 */
340
361
#define SXG_TCB_BUCKET_SHIFT    4
341
 
#define SXG_TCB_PER_BUCKET              16
342
 
#define SXG_TCB_BUCKET_MASK             0xFF0   // Bucket portion of TCB ID
343
 
#define SXG_TCB_ELEMENT_MASK    0x00F   // Element within bucket
344
 
#define SXG_TCB_BUCKETS                 256     // 256 * 16 = 4k
345
 
 
346
 
#define SXG_TCB_BUFFER_SIZE     512     // ASSERT format is correct
347
 
 
348
 
#define SXG_TCB_RCVQ_SIZE               736
 
362
#define SXG_TCB_PER_BUCKET      16
 
363
#define SXG_TCB_BUCKET_MASK     0xFF0   /* Bucket portion of TCB ID */
 
364
#define SXG_TCB_ELEMENT_MASK    0x00F   /* Element within bucket */
 
365
#define SXG_TCB_BUCKETS         256             /* 256 * 16 = 4k */
 
366
 
 
367
#define SXG_TCB_BUFFER_SIZE     512     /* ASSERT format is correct */
 
368
 
 
369
#define SXG_TCB_RCVQ_SIZE       736
349
370
 
350
371
#define SXG_TCB_COMPOSITE_BUFFER_SIZE   1024
351
372
 
352
 
#define SXG_LOCATE_TCP_FRAME_HDR(_TcpObject, _IPv6)                                                     \
353
 
        (((_TcpObject)->VlanId) ?                                                                                               \
354
 
         ((_IPv6) ?             /* Vlan frame header = yes */                                                   \
355
 
          &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp6.SxgTcp                        :       \
356
 
          &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp.SxgTcp)                        :       \
357
 
         ((_IPv6) ?             /* Vlan frame header = No */                                                    \
358
 
          &(_TcpObject)->CompBuffer->Frame.NoVlan.TcpIp6.SxgTcp                         :       \
 
373
#define SXG_LOCATE_TCP_FRAME_HDR(_TcpObject, _IPv6)                     \
 
374
        (((_TcpObject)->VlanId) ?                                       \
 
375
         ((_IPv6) ?             /* Vlan frame header = yes */           \
 
376
          &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp6.SxgTcp:       \
 
377
          &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp.SxgTcp):       \
 
378
         ((_IPv6) ?             /* Vlan frame header = No */            \
 
379
          &(_TcpObject)->CompBuffer->Frame.NoVlan.TcpIp6.SxgTcp :       \
359
380
          &(_TcpObject)->CompBuffer->Frame.NoVlan.TcpIp.SxgTcp))
360
381
 
361
 
#define SXG_LOCATE_IP_FRAME_HDR(_TcpObject)                                                                     \
362
 
        (_TcpObject)->VlanId ?                                                                                                  \
363
 
        &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp.Ip                               :               \
 
382
#define SXG_LOCATE_IP_FRAME_HDR(_TcpObject)                             \
 
383
        (_TcpObject)->VlanId ?                                          \
 
384
        &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp.Ip:              \
364
385
        &(_TcpObject)->CompBuffer->Frame.NoVlan.TcpIp.Ip
365
386
 
366
 
#define SXG_LOCATE_IP6_FRAME_HDR(_TcpObject)                                                            \
367
 
        (_TcpObject)->VlanId ?                                                                                                  \
368
 
        &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp6.Ip                              :               \
 
387
#define SXG_LOCATE_IP6_FRAME_HDR(TcpObject)                             \
 
388
        (_TcpObject)->VlanId ?                                          \
 
389
        &(_TcpObject)->CompBuffer->Frame.HasVlan.TcpIp6.Ip:             \
369
390
        &(_TcpObject)->CompBuffer->Frame.NoVlan.TcpIp6.Ip
370
391
 
371
392
#if DBG
372
 
// Horrible kludge to distinguish dumb-nic, slowpath, and
373
 
// fastpath traffic.  Decrement the HopLimit by one
374
 
// for slowpath, two for fastpath.  This assumes the limit is measurably
375
 
// greater than two, which I think is reasonable.
376
 
// Obviously this is DBG only.  Maybe remove later, or #if 0 so we
377
 
// can set it when needed
378
 
#define SXG_DBG_HOP_LIMIT(_TcpObject, _FastPath) {                                                              \
379
 
        PIPV6_HDR               _Ip6FrameHdr;                                                                                           \
380
 
        if((_TcpObject)->IPv6) {                                                                                                        \
381
 
                _Ip6FrameHdr = SXG_LOCATE_IP6_FRAME_HDR((_TcpObject));                                  \
382
 
                if(_FastPath) {                                                                                                                 \
383
 
                        _Ip6FrameHdr->HopLimit = (_TcpObject)->Cached.TtlOrHopLimit - 2;        \
384
 
                } else {                                                                                                                                \
385
 
                        _Ip6FrameHdr->HopLimit = (_TcpObject)->Cached.TtlOrHopLimit - 1;        \
386
 
                }                                                                                                                                               \
387
 
        }                                                                                                                                                       \
 
393
/*
 
394
 * Horrible kludge to distinguish dumb-nic, slowpath, and
 
395
 * fastpath traffic.  Decrement the HopLimit by one
 
396
 * for slowpath, two for fastpath.  This assumes the limit is measurably
 
397
 * greater than two, which I think is reasonable.
 
398
 * Obviously this is DBG only.  Maybe remove later, or #if 0 so we
 
399
 * can set it when needed
 
400
 */
 
401
#define SXG_DBG_HOP_LIMIT(_TcpObject, _FastPath) {                      \
 
402
        PIPV6_HDR               _Ip6FrameHdr;                           \
 
403
        if ((_TcpObject)->IPv6) {                                       \
 
404
                _Ip6FrameHdr = SXG_LOCATE_IP6_FRAME_HDR((_TcpObject));  \
 
405
                if (_FastPath) {                                        \
 
406
                        _Ip6FrameHdr->HopLimit =                        \
 
407
                                (_TcpObject)->Cached.TtlOrHopLimit - 2; \
 
408
                } else {                                                \
 
409
                        _Ip6FrameHdr->HopLimit =                        \
 
410
                                (_TcpObject)->Cached.TtlOrHopLimit - 1; \
 
411
                }                                                       \
 
412
        }                                                               \
388
413
}
389
414
#else
390
 
// Do nothing with free build
 
415
/* Do nothing with free build */
391
416
#define SXG_DBG_HOP_LIMIT(_TcpObject, _FastPath)
392
417
#endif
393
418
 
394
 
/***************************************************************************
395
 
 * Receive and transmit rings
396
 
 ***************************************************************************/
 
419
/* Receive and transmit rings */
397
420
#define SXG_MAX_RING_SIZE       256
398
 
#define SXG_XMT_RING_SIZE       128     // Start with 128
399
 
#define SXG_RCV_RING_SIZE       128     // Start with 128
 
421
#define SXG_XMT_RING_SIZE       128             /* Start with 128 */
 
422
#define SXG_RCV_RING_SIZE       128             /* Start with 128 */
400
423
#define SXG_MAX_ENTRIES     4096
 
424
#define SXG_JUMBO_RCV_RING_SIZE       32
401
425
 
402
 
// Structure and macros to manage a ring
403
 
struct SXG_RING_INFO {
404
 
        unsigned char Head;     // Where we add entries - Note unsigned char:RING_SIZE
405
 
        unsigned char Tail;     // Where we pull off completed entries
406
 
        ushort Size;            // Ring size - Must be multiple of 2
407
 
        void *Context[SXG_MAX_RING_SIZE];       // Shadow ring
 
426
/* Structure and macros to manage a ring */
 
427
struct sxg_ring_info {
 
428
        /* Where we add entries - Note unsigned char:RING_SIZE */
 
429
        unsigned char Head;
 
430
        unsigned char Tail;     /* Where we pull off completed entries */
 
431
        ushort  Size;           /* Ring size - Must be multiple of 2 */
 
432
        void *  Context[SXG_MAX_RING_SIZE];     /* Shadow ring */
408
433
};
409
434
 
410
 
#define SXG_INITIALIZE_RING(_ring, _size) {                                                     \
411
 
        (_ring).Head = 0;                                                                                               \
412
 
        (_ring).Tail = 0;                                                                                               \
413
 
        (_ring).Size = (_size);                                                                                 \
 
435
#define SXG_INITIALIZE_RING(_ring, _size) {                             \
 
436
        (_ring).Head = 0;                                               \
 
437
        (_ring).Tail = 0;                                               \
 
438
        (_ring).Size = (_size);                                         \
414
439
}
415
 
#define SXG_ADVANCE_INDEX(_index, _size) ((_index) = ((_index) + 1) & ((_size) - 1))
416
 
#define SXG_PREVIOUS_INDEX(_index, _size) (((_index) - 1) &((_size) - 1))
 
440
 
 
441
#define SXG_ADVANCE_INDEX(_index, _size)                                \
 
442
                        ((_index) = ((_index) + 1) & ((_size) - 1))
 
443
#define SXG_PREVIOUS_INDEX(_index, _size)                               \
 
444
                        (((_index) - 1) &((_size) - 1))
417
445
#define SXG_RING_EMPTY(_ring) ((_ring)->Head == (_ring)->Tail)
418
 
#define SXG_RING_FULL(_ring) ((((_ring)->Head + 1) & ((_ring)->Size - 1)) == (_ring)->Tail)
419
 
#define SXG_RING_ADVANCE_HEAD(_ring) SXG_ADVANCE_INDEX((_ring)->Head, ((_ring)->Size))
420
 
#define SXG_RING_RETREAT_HEAD(_ring) ((_ring)->Head =                           \
421
 
                                                                          SXG_PREVIOUS_INDEX((_ring)->Head, (_ring)->Size))
422
 
#define SXG_RING_ADVANCE_TAIL(_ring) {                                                          \
423
 
        ASSERT((_ring)->Tail != (_ring)->Head);                                                 \
424
 
        SXG_ADVANCE_INDEX((_ring)->Tail, ((_ring)->Size));                              \
 
446
#define SXG_RING_FULL(_ring)                                            \
 
447
                ((((_ring)->Head + 1) & ((_ring)->Size - 1)) == (_ring)->Tail)
 
448
#define SXG_RING_ADVANCE_HEAD(_ring)                                    \
 
449
                SXG_ADVANCE_INDEX((_ring)->Head, ((_ring)->Size))
 
450
#define SXG_RING_RETREAT_HEAD(_ring) ((_ring)->Head =                   \
 
451
                SXG_PREVIOUS_INDEX((_ring)->Head, (_ring)->Size))
 
452
#define SXG_RING_ADVANCE_TAIL(_ring) {                                  \
 
453
        ASSERT((_ring)->Tail != (_ring)->Head);                         \
 
454
        SXG_ADVANCE_INDEX((_ring)->Tail, ((_ring)->Size));              \
425
455
}
426
 
// Set cmd to the next available ring entry, set the shadow context
427
 
// entry and advance the ring.
428
 
// The appropriate lock must be held when calling this macro
429
 
#define SXG_GET_CMD(_ring, _ringinfo, _cmd, _context) {                         \
430
 
        if(SXG_RING_FULL(_ringinfo)) {                                                                  \
431
 
                (_cmd) = NULL;                                                                                          \
432
 
        } else {                                                                                                                \
433
 
                (_cmd) = &(_ring)->Descriptors[(_ringinfo)->Head];                      \
 
456
/*
 
457
 * Set cmd to the next available ring entry, set the shadow context
 
458
 * entry and advance the ring.
 
459
 * The appropriate lock must be held when calling this macro
 
460
 */
 
461
#define SXG_GET_CMD(_ring, _ringinfo, _cmd, _context) {                 \
 
462
        if(SXG_RING_FULL(_ringinfo)) {                                  \
 
463
                (_cmd) = NULL;                                          \
 
464
        } else {                                                        \
 
465
                (_cmd) = &(_ring)->Descriptors[(_ringinfo)->Head];      \
434
466
                (_ringinfo)->Context[(_ringinfo)->Head] = (void *)(_context);\
435
 
                SXG_RING_ADVANCE_HEAD(_ringinfo);                                                       \
436
 
        }                                                                                                                               \
437
 
}
438
 
 
439
 
// Abort the previously allocated command by retreating the head.
440
 
// NOTE - The appopriate lock MUST NOT BE DROPPED between the SXG_GET_CMD
441
 
// and SXG_ABORT_CMD calls.
442
 
#define SXG_ABORT_CMD(_ringinfo) {                                                                      \
443
 
        ASSERT(!(SXG_RING_EMPTY(_ringinfo)));                                                   \
444
 
        SXG_RING_RETREAT_HEAD(_ringinfo);                                                               \
445
 
        (_ringinfo)->Context[(_ringinfo)->Head] = NULL;                                 \
446
 
}
447
 
 
448
 
// For the given ring, return a pointer to the tail cmd and context,
449
 
// clear the context and advance the tail
450
 
#define SXG_RETURN_CMD(_ring, _ringinfo, _cmd, _context) {                      \
451
 
        (_cmd) = &(_ring)->Descriptors[(_ringinfo)->Tail];                              \
 
467
                SXG_RING_ADVANCE_HEAD(_ringinfo);                       \
 
468
        }                                                               \
 
469
}
 
470
 
 
471
/*
 
472
 * Abort the previously allocated command by retreating the head.
 
473
 * NOTE - The appopriate lock MUST NOT BE DROPPED between the SXG_GET_CMD
 
474
 * and SXG_ABORT_CMD calls.
 
475
 */
 
476
#define SXG_ABORT_CMD(_ringinfo) {                                      \
 
477
        ASSERT(!(SXG_RING_EMPTY(_ringinfo)));                           \
 
478
        SXG_RING_RETREAT_HEAD(_ringinfo);                               \
 
479
        (_ringinfo)->Context[(_ringinfo)->Head] = NULL;                 \
 
480
}
 
481
 
 
482
/*
 
483
 * For the given ring, return a pointer to the tail cmd and context,
 
484
 * clear the context and advance the tail
 
485
 */
 
486
#define SXG_RETURN_CMD(_ring, _ringinfo, _cmd, _context) {              \
 
487
        (_cmd) = &(_ring)->Descriptors[(_ringinfo)->Tail];              \
452
488
        (_context) = (_ringinfo)->Context[(_ringinfo)->Tail];           \
453
 
        (_ringinfo)->Context[(_ringinfo)->Tail] = NULL;                                 \
454
 
        SXG_RING_ADVANCE_TAIL(_ringinfo);                                                               \
455
 
}
456
 
 
457
 
/***************************************************************************
458
 
 *
 
489
        (_ringinfo)->Context[(_ringinfo)->Tail] = NULL;                 \
 
490
        SXG_RING_ADVANCE_TAIL(_ringinfo);                               \
 
491
}
 
492
 
 
493
/*
 
494
 * For a given ring find out how much the first pointer is ahead of
 
495
 * the second pointer. "ahead" recognises the fact that the ring can wrap
 
496
 */
 
497
static inline int sxg_ring_get_forward_diff (struct sxg_ring_info *ringinfo,
 
498
                                                int a, int b) {
 
499
        if ((a < 0 || a > ringinfo->Size ) || (b < 0 || b > ringinfo->Size))
 
500
                return -1;
 
501
        if (a > b)      /* _a is lagging _b and _b has not wrapped around */
 
502
                return (a - b);
 
503
        else
 
504
                return ((ringinfo->Size - (b - a)));
 
505
}
 
506
 
 
507
/***************************************************************
459
508
 * Host Command Buffer - commands to INIC via the Cmd Rings
460
509
 *
461
 
 ***************************************************************************/
462
 
/*
463
510
 *  31                  15                 0
464
511
 *  .___________________.___________________.
465
512
 *  |<-------------- Sgl Low -------------->|
479
526
 *  |_________|_________|_________|_________|24         0x18
480
527
 *  |<----- LCnt ------>|<----- Flags ----->|
481
528
 *  |_________|_________|_________|_________|28         0x1c
482
 
 */
 
529
 ****************************************************************/
483
530
#pragma pack(push, 1)
484
 
struct SXG_CMD {
485
 
        dma_addr_t Sgl;         // Physical address of SGL
 
531
struct sxg_cmd {
 
532
        dma64_addr_t    Sgl;            /* Physical address of SGL */
486
533
        union {
487
534
                struct {
488
 
                        dma64_addr_t FirstSgeAddress;   // Address of first SGE
489
 
                        u32 FirstSgeLength;     // Length of first SGE
 
535
                        dma64_addr_t FirstSgeAddress; /* Address of first SGE */
 
536
                        u32          FirstSgeLength;  /* Length of first SGE */
490
537
                        union {
491
 
                                u32 Rsvd1;      // TOE NA
492
 
                                u32 SgeOffset;  // Slowpath - 2nd SGE offset
493
 
                                u32 Resid;      // MDL completion - clobbers update
 
538
                                u32  Rsvd1;        /* TOE NA */
 
539
                                u32  SgeOffset; /* Slowpath - 2nd SGE offset */
 
540
                                /* MDL completion - clobbers update */
 
541
                                u32  Resid;
494
542
                        };
495
543
                        union {
496
 
                                u32 TotalLength;        // Total transfer length
497
 
                                u32 Mss;        // LSO MSS
 
544
                                u32  TotalLength; /* Total transfer length */
 
545
                                u32  Mss;         /* LSO MSS */
498
546
                        };
499
547
                } Buffer;
500
548
        };
501
549
        union {
502
550
                struct {
503
 
                        unsigned char Flags:4;  // slowpath flags
504
 
                        unsigned char IpHl:4;   // Ip header length (>>2)
505
 
                        unsigned char MacLen;   // Mac header len
 
551
                        unsigned char Flags:4;  /* slowpath flags */
 
552
                        unsigned char IpHl:4;   /* Ip header length (>>2) */
 
553
                        unsigned char MacLen;   /* Mac header len */
506
554
                } CsumFlags;
507
555
                struct {
508
 
                        ushort Flags:4; // slowpath flags
509
 
                        ushort TcpHdrOff:7;     // TCP
510
 
                        ushort MacLen:5;        // Mac header len
 
556
                        ushort  Flags:4;        /* slowpath flags */
 
557
                        ushort  TcpHdrOff:7;    /* TCP */
 
558
                        ushort  MacLen:5;       /* Mac header len */
511
559
                } LsoFlags;
512
 
                ushort Flags;   // flags
 
560
                ushort          Flags;          /* flags */
513
561
        };
514
562
        union {
515
 
                ushort SgEntries;       // SG entry count including first sge
 
563
                ushort  SgEntries;      /* SG entry count including first sge */
516
564
                struct {
517
 
                        unsigned char Status;   // Copied from event status
 
565
                        unsigned char Status;   /* Copied from event status */
518
566
                        unsigned char NotUsed;
519
567
                } Status;
520
568
        };
522
570
#pragma pack(pop)
523
571
 
524
572
#pragma pack(push, 1)
525
 
struct VLAN_HDR {
 
573
struct vlan_hdr {
526
574
        ushort VlanTci;
527
575
        ushort VlanTpid;
528
576
};
529
577
#pragma pack(pop)
530
578
 
531
 
/*
 
579
/********************************************************************
532
580
 * Slowpath Flags:
533
581
 *
534
582
 *
558
606
 *  |      LCnt         |MAC hlen |Hlen|Flgs|
559
607
 *  |___________________|____|____|____|____|
560
608
 *
561
 
 */
562
 
// Slowpath CMD flags
563
 
#define SXG_SLOWCMD_CSUM_IP                     0x01    // Checksum IP
564
 
#define SXG_SLOWCMD_CSUM_TCP            0x02    // Checksum TCP
565
 
#define SXG_SLOWCMD_LSO                         0x04    // Large segment send
566
 
 
567
 
struct SXG_XMT_RING {
568
 
        struct SXG_CMD Descriptors[SXG_XMT_RING_SIZE];
569
 
};
570
 
 
571
 
struct SXG_RCV_RING {
572
 
        struct SXG_CMD Descriptors[SXG_RCV_RING_SIZE];
573
 
};
574
 
 
575
 
/***************************************************************************
 
609
 *****************************************************************/
 
610
/* Slowpath CMD flags */
 
611
#define SXG_SLOWCMD_CSUM_IP             0x01    /* Checksum IP */
 
612
#define SXG_SLOWCMD_CSUM_TCP            0x02    /* Checksum TCP */
 
613
#define SXG_SLOWCMD_LSO                 0x04    /* Large segment send */
 
614
 
 
615
struct sxg_xmt_ring {
 
616
        struct sxg_cmd Descriptors[SXG_XMT_RING_SIZE];
 
617
};
 
618
 
 
619
struct sxg_rcv_ring {
 
620
        struct sxg_cmd Descriptors[SXG_RCV_RING_SIZE];
 
621
};
 
622
 
 
623
/*
576
624
 * Share memory buffer types - Used to identify asynchronous
577
625
 * shared memory allocation
578
 
 ***************************************************************************/
579
 
enum SXG_BUFFER_TYPE {
580
 
        SXG_BUFFER_TYPE_RCV,    // Receive buffer
581
 
        SXG_BUFFER_TYPE_SGL     // SGL buffer
 
626
 */
 
627
enum sxg_buffer_type {
 
628
        SXG_BUFFER_TYPE_RCV,            /* Receive buffer */
 
629
        SXG_BUFFER_TYPE_SGL             /* SGL buffer */
582
630
};
583
631
 
584
 
// State for SXG buffers
 
632
/* State for SXG buffers */
585
633
#define SXG_BUFFER_FREE         0x01
586
634
#define SXG_BUFFER_BUSY         0x02
587
635
#define SXG_BUFFER_ONCARD       0x04
588
636
#define SXG_BUFFER_UPSTREAM     0x08
589
637
 
590
 
/***************************************************************************
 
638
/*
591
639
 * Receive data buffers
592
640
 *
593
641
 * Receive data buffers are given to the Sahara card 128 at a time.
597
645
 * DMA data into, and a virtual address, which is given back
598
646
 * to the host in the "HostHandle" portion of an event.
599
647
 * The receive descriptor data structure is defined below
600
 
 * as SXG_RCV_DATA_DESCRIPTOR, and the corresponding block
601
 
 * is defined as SXG_RCV_DESCRIPTOR_BLOCK.
 
648
 * as sxg_rcv_data_descriptor, and the corresponding block
 
649
 * is defined as sxg_rcv_descriptor_block.
602
650
 *
603
651
 * This receive descriptor block is given to the card by filling
604
 
 * in the Sgl field of a SXG_CMD entry from pAdapt->RcvRings[0]
 
652
 * in the Sgl field of a sxg_cmd entry from pAdapt->RcvRings[0]
605
653
 * with the physical address of the receive descriptor block.
606
654
 *
607
655
 * Both the receive buffers and the receive descriptor blocks
608
656
 * require additional data structures to maintain them
609
657
 * on a free queue and contain other information associated with them.
610
 
 * Those data structures are defined as the SXG_RCV_DATA_BUFFER_HDR
611
 
 * and SXG_RCV_DESCRIPTOR_BLOCK_HDR respectively.
 
658
 * Those data structures are defined as the sxg_rcv_data_buffer_hdr
 
659
 * and sxg_rcv_descriptor_block_hdr respectively.
612
660
 *
613
661
 * Since both the receive buffers and the receive descriptor block
614
662
 * must be accessible by the card, both must be allocated out of
615
663
 * shared memory.  To ensure that we always have a descriptor
616
664
 * block available for every 128 buffers, we allocate all of
617
665
 * these resources together in a single block.  This entire
618
 
 * block is managed by a SXG_RCV_BLOCK_HDR, who's sole purpose
 
666
 * block is managed by a struct sxg_rcv_block_hdr, who's sole purpose
619
667
 * is to maintain address information so that the entire block
620
668
 * can be free later.
621
669
 *
622
670
 * Further complicating matters is the fact that the receive
623
671
 * buffers must be variable in length in order to accomodate
624
672
 * jumbo frame configurations.  We configure the buffer
625
 
 * length so that the buffer and it's corresponding SXG_RCV_DATA_BUFFER_HDR
626
 
 * structure add up to an even boundary.  Then we place the
627
 
 * remaining data structures after 128 of them as shown in
628
 
 * the following diagram:
 
673
 * length so that the buffer and it's corresponding struct
 
674
 * sxg_rcv_data_buffer_hdr structure add up to an even
 
675
 * boundary.  Then we place the remaining data structures after 128
 
676
 *  of them as shown in the following diagram:
629
677
 *
630
678
 *  _________________________________________
631
679
 * |                                         |
632
680
 * |    Variable length receive buffer #1    |
633
681
 * |_________________________________________|
634
682
 * |                                         |
635
 
 * |       SXG_RCV_DATA_BUFFER_HDR #1        |
 
683
 * |       sxg_rcv_data_buffer_hdr #1        |
636
684
 * |_________________________________________| <== Even 2k or 10k boundary
637
685
 * |                                         |
638
686
 * |         ... repeat 2-128 ..             |
639
687
 * |_________________________________________|
640
688
 * |                                         |
641
 
 * |      SXG_RCV_DESCRIPTOR_BLOCK           |
642
 
 * |  Contains SXG_RCV_DATA_DESCRIPTOR * 128 |
643
 
 * |_________________________________________|
644
 
 * |                                         |
645
 
 * |      SXG_RCV_DESCRIPTOR_BLOCK_HDR       |
646
 
 * |_________________________________________|
647
 
 * |                                         |
648
 
 * |          SXG_RCV_BLOCK_HDR              |
 
689
 * |      struct sxg_rcv_descriptor_block    |
 
690
 * |  Contains sxg_rcv_data_descriptor * 128 |
 
691
 * |_________________________________________|
 
692
 * |                                         |
 
693
 * |   struct sxg_rcv_descriptor_block_hdr   |
 
694
 * |_________________________________________|
 
695
 * |                                         |
 
696
 * |      struct sxg_rcv_block_hdr           |
649
697
 * |_________________________________________|
650
698
 *
651
699
 * Memory consumption:
652
700
 *        Non-jumbo:
653
 
 *      Buffers and SXG_RCV_DATA_BUFFER_HDR = 2k * 128 = 256k
654
 
 *    + SXG_RCV_DESCRIPTOR_BLOCK = 2k
655
 
 *    + SXG_RCV_DESCRIPTOR_BLOCK_HDR = ~32
656
 
 *    + SXG_RCV_BLOCK_HDR = ~32
 
701
 *      Buffers and sxg_rcv_data_buffer_hdr = 2k * 128 = 256k
 
702
 *    + struct sxg_rcv_descriptor_block = 2k
 
703
 *    + struct sxg_rcv_descriptor_block_hdr = ~32
 
704
 *    + struct sxg_rcv_block_hdr = ~32
657
705
 *    => Total = ~258k/block
658
706
 *
659
707
 *        Jumbo:
660
 
 *      Buffers and SXG_RCV_DATA_BUFFER_HDR = 10k * 128 = 1280k
661
 
 *    + SXG_RCV_DESCRIPTOR_BLOCK = 2k
662
 
 *    + SXG_RCV_DESCRIPTOR_BLOCK_HDR = ~32
663
 
 *    + SXG_RCV_BLOCK_HDR = ~32
 
708
 *      Buffers and sxg_rcv_data_buffer_hdr = 10k * 128 = 1280k
 
709
 *    + struct sxg_rcv_descriptor_block = 2k
 
710
 *    + struct sxg_rcv_descriptor_block_hdr = ~32
 
711
 *    + struct sxg_rcv_block_hdr = ~32
664
712
 *    => Total = ~1282k/block
665
713
 *
666
 
 ***************************************************************************/
667
 
#define SXG_RCV_DATA_BUFFERS                    4096    // Amount to give to the card
668
 
#define SXG_INITIAL_RCV_DATA_BUFFERS    8192    // Initial pool of buffers
669
 
#define SXG_MIN_RCV_DATA_BUFFERS                2048    // Minimum amount and when to get more
670
 
#define SXG_MAX_RCV_BLOCKS                              128     // = 16384 receive buffers
 
714
 */
 
715
#define SXG_RCV_DATA_BUFFERS            8192    /* Amount to give to the card */
 
716
#define SXG_INITIAL_RCV_DATA_BUFFERS    16384   /* Initial pool of buffers */
 
717
/* Minimum amount and when to get more */
 
718
#define SXG_MIN_RCV_DATA_BUFFERS        4096
 
719
#define SXG_MAX_RCV_BLOCKS              256     /* = 32k receive buffers */
 
720
/* Amount to give to the card in case of jumbo frames */
 
721
#define SXG_JUMBO_RCV_DATA_BUFFERS              2048
 
722
/* Initial pool of buffers in case of jumbo buffers */
 
723
#define SXG_INITIAL_JUMBO_RCV_DATA_BUFFERS      4096
 
724
#define SXG_MIN_JUMBO_RCV_DATA_BUFFERS          1024
671
725
 
672
 
// Receive buffer header
673
 
struct SXG_RCV_DATA_BUFFER_HDR {
674
 
        dma_addr_t PhysicalAddress;     // Buffer physical address
675
 
        // Note - DO NOT USE the VirtualAddress field to locate data.
676
 
        // Use the sxg.h:SXG_RECEIVE_DATA_LOCATION macro instead.
677
 
        void *VirtualAddress;   // Start of buffer
678
 
        struct LIST_ENTRY FreeList;     // Free queue of buffers
679
 
        struct SXG_RCV_DATA_BUFFER_HDR *Next;   // Fastpath data buffer queue
680
 
        u32 Size;               // Buffer size
681
 
        u32 ByteOffset;         // See SXG_RESTORE_MDL_OFFSET
682
 
        unsigned char State;    // See SXG_BUFFER state above
683
 
        unsigned char Status;   // Event status (to log PUSH)
684
 
        struct sk_buff *skb;    // Double mapped (nbl and pkt)
 
726
/* Receive buffer header */
 
727
struct sxg_rcv_data_buffer_hdr {
 
728
        dma64_addr_t    PhysicalAddress;        /* Buffer physical address */
 
729
        /*
 
730
         * Note - DO NOT USE the VirtualAddress field to locate data.
 
731
         * Use the sxg.h:SXG_RECEIVE_DATA_LOCATION macro instead.
 
732
         */
 
733
        struct list_entry       FreeList;       /* Free queue of buffers */
 
734
        unsigned char           State;          /* See SXG_BUFFER state above */
 
735
        struct sk_buff          * skb;          /* Double mapped (nbl and pkt)*/
685
736
};
686
737
 
687
 
// SxgSlowReceive uses the PACKET (skb) contained
688
 
// in the SXG_RCV_DATA_BUFFER_HDR when indicating dumb-nic data
 
738
/*
 
739
 * SxgSlowReceive uses the PACKET (skb) contained
 
740
 * in the struct sxg_rcv_data_buffer_hdr when indicating dumb-nic data
 
741
 */
689
742
#define SxgDumbRcvPacket                skb
690
743
 
691
 
#define SXG_RCV_DATA_HDR_SIZE                   256     // Space for SXG_RCV_DATA_BUFFER_HDR
692
 
#define SXG_RCV_DATA_BUFFER_SIZE                2048    // Non jumbo = 2k including HDR
693
 
#define SXG_RCV_JUMBO_BUFFER_SIZE               10240   // jumbo = 10k including HDR
 
744
/* Space for struct sxg_rcv_data_buffer_hdr */
 
745
#define SXG_RCV_DATA_HDR_SIZE           sizeof(struct sxg_rcv_data_buffer_hdr)
 
746
/* Non jumbo = 2k including HDR */
 
747
#define SXG_RCV_DATA_BUFFER_SIZE        2048
 
748
/* jumbo = 10k including HDR */
 
749
#define SXG_RCV_JUMBO_BUFFER_SIZE       10240
694
750
 
695
 
// Receive data descriptor
696
 
struct SXG_RCV_DATA_DESCRIPTOR {
 
751
/* Receive data descriptor */
 
752
struct sxg_rcv_data_descriptor {
697
753
        union {
698
 
                struct sk_buff *VirtualAddress; // Host handle
699
 
                u64 ForceTo8Bytes;      // Force x86 to 8-byte boundary
 
754
                struct sk_buff *VirtualAddress; /* Host handle */
 
755
                u64             ForceTo8Bytes;  /*Force x86 to 8-byte boundary*/
700
756
        };
701
 
        dma_addr_t PhysicalAddress;
 
757
        dma64_addr_t PhysicalAddress;
702
758
};
703
759
 
704
 
// Receive descriptor block
 
760
/* Receive descriptor block */
705
761
#define SXG_RCV_DESCRIPTORS_PER_BLOCK           128
706
 
#define SXG_RCV_DESCRIPTOR_BLOCK_SIZE           2048    // For sanity check
707
 
 
708
 
struct SXG_RCV_DESCRIPTOR_BLOCK {
709
 
        struct SXG_RCV_DATA_DESCRIPTOR Descriptors[SXG_RCV_DESCRIPTORS_PER_BLOCK];
710
 
};
711
 
 
712
 
// Receive descriptor block header
713
 
struct SXG_RCV_DESCRIPTOR_BLOCK_HDR {
714
 
        void *VirtualAddress;   // Start of 2k buffer
715
 
        dma_addr_t PhysicalAddress;     // ..and it's physical address
716
 
        struct LIST_ENTRY FreeList;     // Free queue of descriptor blocks
717
 
        unsigned char State;    // See SXG_BUFFER state above
718
 
};
719
 
 
720
 
// Receive block header
721
 
struct SXG_RCV_BLOCK_HDR {
722
 
        void *VirtualAddress;   // Start of virtual memory
723
 
        dma_addr_t PhysicalAddress;     // ..and it's physical address
724
 
        struct LIST_ENTRY AllList;      // Queue of all SXG_RCV_BLOCKS
725
 
};
726
 
 
727
 
// Macros to determine data structure offsets into receive block
728
 
#define SXG_RCV_BLOCK_SIZE(_Buffersize)                                         \
 
762
#define SXG_RCV_DESCRIPTOR_BLOCK_SIZE           2048    /* For sanity check */
 
763
 
 
764
struct sxg_rcv_descriptor_block {
 
765
        struct sxg_rcv_data_descriptor Descriptors[SXG_RCV_DESCRIPTORS_PER_BLOCK];
 
766
};
 
767
 
 
768
/* Receive descriptor block header */
 
769
struct sxg_rcv_descriptor_block_hdr {
 
770
        void            *VirtualAddress;        /* start of 2k buffer */
 
771
        dma64_addr_t            PhysicalAddress;/* and it's physical address */
 
772
        struct list_entry       FreeList;/* free queue of descriptor blocks */
 
773
        unsigned char   State;  /* see sxg_buffer state above */
 
774
};
 
775
 
 
776
/* Receive block header */
 
777
struct sxg_rcv_block_hdr {
 
778
        void            *VirtualAddress;        /* Start of virtual memory */
 
779
        dma64_addr_t            PhysicalAddress;/* ..and it's physical address*/
 
780
        struct list_entry       AllList;        /* Queue of all SXG_RCV_BLOCKS*/
 
781
};
 
782
 
 
783
/* Macros to determine data structure offsets into receive block */
 
784
#define SXG_RCV_BLOCK_SIZE(_Buffersize)                                 \
729
785
        (((_Buffersize) * SXG_RCV_DESCRIPTORS_PER_BLOCK) +              \
730
 
         (sizeof(struct SXG_RCV_DESCRIPTOR_BLOCK))              +               \
731
 
         (sizeof(struct SXG_RCV_DESCRIPTOR_BLOCK_HDR))          +               \
732
 
         (sizeof(struct SXG_RCV_BLOCK_HDR)))
 
786
         (sizeof(struct sxg_rcv_descriptor_block))              +       \
 
787
         (sizeof(struct sxg_rcv_descriptor_block_hdr))          +       \
 
788
         (sizeof(struct sxg_rcv_block_hdr)))
733
789
#define SXG_RCV_BUFFER_DATA_SIZE(_Buffersize)                           \
734
790
        ((_Buffersize) - SXG_RCV_DATA_HDR_SIZE)
735
791
#define SXG_RCV_DATA_BUFFER_HDR_OFFSET(_Buffersize)                     \
736
792
        ((_Buffersize) - SXG_RCV_DATA_HDR_SIZE)
737
 
#define SXG_RCV_DESCRIPTOR_BLOCK_OFFSET(_Buffersize)            \
 
793
#define SXG_RCV_DESCRIPTOR_BLOCK_OFFSET(_Buffersize)                    \
738
794
        ((_Buffersize) * SXG_RCV_DESCRIPTORS_PER_BLOCK)
739
 
#define SXG_RCV_DESCRIPTOR_BLOCK_HDR_OFFSET(_Buffersize)        \
 
795
#define SXG_RCV_DESCRIPTOR_BLOCK_HDR_OFFSET(_Buffersize)                \
740
796
        (((_Buffersize) * SXG_RCV_DESCRIPTORS_PER_BLOCK) +              \
741
 
         (sizeof(struct SXG_RCV_DESCRIPTOR_BLOCK)))
 
797
         (sizeof(struct sxg_rcv_descriptor_block)))
742
798
#define SXG_RCV_BLOCK_HDR_OFFSET(_Buffersize)                           \
743
799
        (((_Buffersize) * SXG_RCV_DESCRIPTORS_PER_BLOCK) +              \
744
 
         (sizeof(struct SXG_RCV_DESCRIPTOR_BLOCK))              +               \
745
 
         (sizeof(struct SXG_RCV_DESCRIPTOR_BLOCK_HDR)))
746
 
 
747
 
// Use the miniport reserved portion of the NBL to locate
748
 
// our SXG_RCV_DATA_BUFFER_HDR structure.
749
 
struct SXG_RCV_NBL_RESERVED {
750
 
        struct SXG_RCV_DATA_BUFFER_HDR *RcvDataBufferHdr;
751
 
        void *Available;
752
 
};
753
 
 
754
 
#define SXG_RCV_NBL_BUFFER_HDR(_NBL) (((PSXG_RCV_NBL_RESERVED)NET_BUFFER_LIST_MINIPORT_RESERVED(_NBL))->RcvDataBufferHdr)
755
 
 
756
 
/***************************************************************************
757
 
 * Scatter gather list buffer
758
 
 ***************************************************************************/
759
 
#define SXG_INITIAL_SGL_BUFFERS         8192    // Initial pool of SGL buffers
760
 
#define SXG_MIN_SGL_BUFFERS                     2048    // Minimum amount and when to get more
761
 
#define SXG_MAX_SGL_BUFFERS                     16384   // Maximum to allocate (note ADAPT:ushort)
762
 
 
763
 
// Self identifying structure type
 
800
         (sizeof(struct sxg_rcv_descriptor_block))              +       \
 
801
         (sizeof(struct sxg_rcv_descriptor_block_hdr)))
 
802
 
 
803
/* Scatter gather list buffer */
 
804
#define SXG_INITIAL_SGL_BUFFERS 8192    /* Initial pool of SGL buffers */
 
805
#define SXG_MIN_SGL_BUFFERS     2048    /* Minimum amount and when to get more*/
 
806
/* Maximum to allocate (note ADAPT:ushort) */
 
807
#define SXG_MAX_SGL_BUFFERS     16384
 
808
 
 
809
/*
 
810
 * SXG_SGL_POOL_PROPERTIES - This structure is used to define a pool of SGL
 
811
 * buffers. These buffers are allocated out of shared memory and used to
 
812
 * contain a physical scatter gather list structure that is shared
 
813
 * with the card.
 
814
 *
 
815
 * We split our SGL buffers into multiple pools based on size.  The motivation
 
816
 * is that some applications perform very large I/Os (1MB for example), so
 
817
 * we need to be able to allocate an SGL to accommodate such a request.
 
818
 * But such an SGL would require 256 24-byte SG entries - ~6k.
 
819
 * Given that the vast majority of I/Os are much smaller than 1M, allocating
 
820
 * a single pool of SGL buffers would be a horribly inefficient use of
 
821
 * memory.
 
822
 *
 
823
 * The following structure includes two fields relating to its size.
 
824
 * The NBSize field specifies the largest NET_BUFFER that can be handled
 
825
 * by the particular pool.  The SGEntries field defines the size, in
 
826
 * entries, of the SGL for that pool.  The SGEntries is determined by
 
827
 * dividing the NBSize by the expected page size (4k), and then padding
 
828
 * it by some appropriate amount as insurance (20% or so..??).
 
829
 */
 
830
struct sxg_sgl_pool_properties {
 
831
        u32     NBSize;         /* Largest NET_BUFFER size for this pool */
 
832
        ushort  SGEntries;      /* Number of entries in SGL */
 
833
        ushort  InitialBuffers; /* Number to allocate at initializationtime */
 
834
        ushort  MinBuffers;     /* When to get more */
 
835
        ushort  MaxBuffers;     /* When to stop */
 
836
        ushort  PerCpuThreshold;/* See sxgh.h:SXG_RESOURCES */
 
837
};
 
838
 
 
839
/*
 
840
 * At the moment I'm going to statically initialize 4 pools:
 
841
 *      100k buffer pool: The vast majority of the expected buffers are expected
 
842
 *                      to be less than or equal to 100k.  At 30 entries per and
 
843
 *                      8k initial buffers amounts to ~4MB of memory
 
844
 *                 NOTE - This used to be 64K with 20 entries, but during
 
845
 *                        WHQL NDIS 6.0 Testing (2c_mini6stress) MS does their
 
846
 *                        best to send absurd NBL's with ridiculous SGLs, we
 
847
 *                        have received 400byte sends contained in SGL's that
 
848
 *                        have 28 entries
 
849
 *        1M buffer pool: Buffers between 64k and 1M.  Allocate 256 initial
 
850
 *                        buffers with 300 entries each => ~2MB of memory
 
851
 *        5M buffer pool: Not expected often, if at all.  32 initial buffers
 
852
 *                        at 1500 entries each => ~1MB of memory
 
853
 * 10M buffer pool: Not expected at all, except under pathelogical conditions.
 
854
 *                  Allocate one at initialization time.
 
855
 *                Note - 10M is the current limit of what we can realistically
 
856
 *                       support due to the sahara SGL bug described in the
 
857
 *                       SAHARA SGL WORKAROUND below. We will likely adjust the
 
858
 *                       number of pools and/or pool properties over time.
 
859
 */
 
860
#define SXG_NUM_SGL_POOLS       4
 
861
#define INITIALIZE_SGL_POOL_PROPERTIES                                  \
 
862
struct sxg_sgl_pool_properties SxgSglPoolProperties[SXG_NUM_SGL_POOLS] =\
 
863
{                                                                       \
 
864
        {  102400,   30, 8192, 2048, 16384, 256},                       \
 
865
        { 1048576,  300,  256,  128,  1024, 16},                        \
 
866
        { 5252880, 1500,   32,   16,   512, 0},                         \
 
867
        {10485760, 2700,    2,    4,    32, 0},                         \
 
868
};
 
869
 
 
870
extern struct sxg_sgl_pool_properties SxgSglPoolProperties[];
 
871
 
 
872
#define SXG_MAX_SGL_BUFFER_SIZE                                         \
 
873
        SxgSglPoolProperties[SXG_NUM_SGL_POOLS - 1].NBSize
 
874
 
 
875
/*
 
876
 * SAHARA SGL WORKAROUND!!
 
877
 * The current Sahara card uses a 16-bit counter when advancing
 
878
 * SGL address locations.  This means that if an SGL crosses
 
879
 * a 64k boundary, the hardware will actually skip back to
 
880
 * the start of the previous 64k boundary, with obviously
 
881
 * undesirable results.
 
882
 *
 
883
 * We currently workaround this issue by allocating SGL buffers
 
884
 * in 64k blocks and skipping over buffers that straddle the boundary.
 
885
 */
 
886
#define SXG_INVALID_SGL(phys_addr,len) \
 
887
        (((phys_addr >> 16) != ( (phys_addr + len) >> 16 )))
 
888
 
 
889
/*
 
890
 * Allocate SGLs in blocks so we can skip over invalid entries.
 
891
 * We allocation 64k worth of SGL buffers, including the
 
892
 * struct sxg_sgl_block_hdr, plus one for padding
 
893
 */
 
894
#define SXG_SGL_BLOCK_SIZE                              65536
 
895
#define SXG_SGL_ALLOCATION_SIZE(_Pool)                                  \
 
896
        SXG_SGL_BLOCK_SIZE + SXG_SGL_SIZE(_Pool)
 
897
 
 
898
struct sxg_sgl_block_hdr {
 
899
        ushort                  Pool;           /* Associated SGL pool */
 
900
        /* struct sxg_scatter_gather blocks */
 
901
        struct list_entry       List;
 
902
        dma64_addr_t            PhysicalAddress;/* physical address */
 
903
};
 
904
 
 
905
/*
 
906
 * The following definition denotes the maximum block of memory that the
 
907
 * card can DMA to.It is specified in the call to NdisMRegisterScatterGatherDma.
 
908
 * For now, use the same value as used in the Slic/Oasis driver, which
 
909
 * is 128M.  That should cover any expected MDL that I can think of.
 
910
 */
 
911
#define SXG_MAX_PHYS_MAP        (1024 * 1024 * 128)
 
912
 
 
913
/* Self identifying structure type */
764
914
enum SXG_SGL_TYPE {
765
 
        SXG_SGL_DUMB,           // Dumb NIC SGL
766
 
        SXG_SGL_SLOW,           // Slowpath protocol header - see below
767
 
        SXG_SGL_CHIMNEY         // Chimney offload SGL
768
 
};
769
 
 
770
 
// Note - the description below is Microsoft specific
771
 
//
772
 
// The following definition specifies the amount of shared memory to allocate
773
 
// for the SCATTER_GATHER_LIST portion of the SXG_SCATTER_GATHER data structure.
774
 
// The following considerations apply when setting this value:
775
 
// - First, the Sahara card is designed to read the Microsoft SGL structure
776
 
//       straight out of host memory.  This means that the SGL must reside in
777
 
//       shared memory.  If the length here is smaller than the SGL for the
778
 
//       NET_BUFFER, then NDIS will allocate its own buffer.  The buffer
779
 
//       that NDIS allocates is not in shared memory, so when this happens,
780
 
//       the SGL will need to be copied to a set of SXG_SCATTER_GATHER buffers.
781
 
//       In other words.. we don't want this value to be too small.
782
 
// - On the other hand.. we're allocating up to 16k of these things.  If
783
 
//       we make this too big, we start to consume a ton of memory..
784
 
// At the moment, I'm going to limit the number of SG entries to 150.
785
 
// If each entry maps roughly 4k, then this should cover roughly 600kB
786
 
// NET_BUFFERs.  Furthermore, since each entry is 24 bytes, the total
787
 
// SGE portion of the structure consumes 3600 bytes, which should allow
788
 
// the entire SXG_SCATTER_GATHER structure to reside comfortably within
789
 
// a 4k block, providing the remaining fields stay under 500 bytes.
790
 
//
791
 
// So with 150 entries, the SXG_SCATTER_GATHER structure becomes roughly
792
 
// 4k.  At 16k of them, that amounts to 64M of shared memory.  A ton, but
793
 
// manageable.
794
 
#define SXG_SGL_ENTRIES         150
795
 
 
796
 
// The ucode expects an NDIS SGL structure that
797
 
// is formatted for an x64 system.  When running
798
 
// on an x64 system, we can simply hand the NDIS SGL
799
 
// to the card directly.  For x86 systems we must reconstruct
800
 
// the SGL.  The following structure defines an x64
801
 
// formatted SGL entry
802
 
struct SXG_X64_SGE {
803
 
        dma64_addr_t Address;   // same as wdm.h
804
 
        u32 Length;             // same as wdm.h
805
 
        u32 CompilerPad;        // The compiler pads to 8-bytes
806
 
        u64 Reserved;           // u32 * in wdm.h.  Force to 8 bytes
807
 
};
808
 
 
809
 
struct SCATTER_GATHER_ELEMENT {
810
 
        dma64_addr_t Address;   // same as wdm.h
811
 
        u32 Length;             // same as wdm.h
812
 
        u32 CompilerPad;        // The compiler pads to 8-bytes
813
 
        u64 Reserved;           // u32 * in wdm.h.  Force to 8 bytes
814
 
};
815
 
 
816
 
struct SCATTER_GATHER_LIST {
817
 
        u32 NumberOfElements;
818
 
        u32 *Reserved;
819
 
        struct SCATTER_GATHER_ELEMENT Elements[];
820
 
};
821
 
 
822
 
// The card doesn't care about anything except elements, so
823
 
// we can leave the u32 * reserved field alone in the following
824
 
// SGL structure.  But redefine from wdm.h:SCATTER_GATHER_LIST so
825
 
// we can specify SXG_X64_SGE and define a fixed number of elements
826
 
struct SXG_X64_SGL {
827
 
        u32 NumberOfElements;
828
 
        u32 *Reserved;
829
 
        struct SXG_X64_SGE Elements[SXG_SGL_ENTRIES];
830
 
};
831
 
 
832
 
struct SXG_SCATTER_GATHER {
833
 
        enum SXG_SGL_TYPE Type; // FIRST! Dumb-nic or offload
834
 
        void *adapter;          // Back pointer to adapter
835
 
        struct LIST_ENTRY FreeList;     // Free SXG_SCATTER_GATHER blocks
836
 
        struct LIST_ENTRY AllList;      // All SXG_SCATTER_GATHER blocks
837
 
        dma_addr_t PhysicalAddress;     // physical address
838
 
        unsigned char State;    // See SXG_BUFFER state above
839
 
        unsigned char CmdIndex; // Command ring index
840
 
        struct sk_buff *DumbPacket;     // Associated Packet
841
 
        u32 Direction;          // For asynchronous completions
842
 
        u32 CurOffset;          // Current SGL offset
843
 
        u32 SglRef;             // SGL reference count
844
 
        struct VLAN_HDR VlanTag;        // VLAN tag to be inserted into SGL
845
 
        struct SCATTER_GATHER_LIST *pSgl;       // SGL Addr. Possibly &Sgl
846
 
        struct SXG_X64_SGL Sgl; // SGL handed to card
847
 
};
848
 
 
 
915
        SXG_SGL_DUMB,           /* Dumb NIC SGL */
 
916
        SXG_SGL_SLOW,           /* Slowpath protocol header - see below */
 
917
        SXG_SGL_CHIMNEY         /* Chimney offload SGL */
 
918
};
 
919
 
 
920
/*
 
921
 * The ucode expects an NDIS SGL structure that
 
922
 * is formatted for an x64 system.  When running
 
923
 * on an x64 system, we can simply hand the NDIS SGL
 
924
 * to the card directly.  For x86 systems we must reconstruct
 
925
 * the SGL.  The following structure defines an x64
 
926
 * formatted SGL entry
 
927
 */
 
928
struct sxg_x64_sge {
 
929
        dma64_addr_t    Address;        /* same as wdm.h */
 
930
        u32             Length;         /* same as wdm.h */
 
931
        u32             CompilerPad;    /* The compiler pads to 8-bytes */
 
932
        u64             Reserved;       /* u32 * in wdm.h.  Force to 8 bytes */
 
933
};
 
934
 
 
935
/*
 
936
 * Our SGL structure - Essentially the same as
 
937
 * wdm.h:SCATTER_GATHER_LIST.  Note the variable number of
 
938
 * elements based on the pool specified above
 
939
 */
 
940
struct sxg_x64_sgl {
 
941
        u32 NumberOfElements;
 
942
        u32 *Reserved;
 
943
        struct sxg_x64_sge              Elements[1];   /* Variable */
 
944
};
 
945
 
 
946
struct sxg_scatter_gather {
 
947
        enum SXG_SGL_TYPE       Type;           /* FIRST! Dumb-nic or offload */
 
948
        ushort                  Pool;           /* Associated SGL pool */
 
949
        ushort                  Entries;        /* SGL total entries */
 
950
        void *                  adapter;        /* Back pointer to adapter */
 
951
        /* Free struct sxg_scatter_gather blocks */
 
952
        struct list_entry       FreeList;
 
953
        /* All struct sxg_scatter_gather blocks */
 
954
        struct list_entry       AllList;
 
955
        dma64_addr_t            PhysicalAddress;/* physical address */
 
956
        unsigned char           State;          /* See SXG_BUFFER state above */
 
957
        unsigned char           CmdIndex;       /* Command ring index */
 
958
        struct sk_buff          *DumbPacket;    /* Associated Packet */
 
959
        /* For asynchronous completions */
 
960
        u32                     Direction;
 
961
        u32                     CurOffset;      /* Current SGL offset */
 
962
        u32                     SglRef;         /* SGL reference count */
 
963
        struct vlan_hdr         VlanTag;        /* VLAN tag to be inserted into SGL */
 
964
        struct sxg_x64_sgl      *pSgl;          /* SGL Addr. Possibly &Sgl */
 
965
        struct sxg_x64_sgl      Sgl;            /* SGL handed to card */
 
966
};
 
967
 
 
968
/*
 
969
 * Note - the "- 1" is because struct sxg_scatter_gather=>struct sxg_x64_sgl
 
970
 * includes 1 SGE..
 
971
 */
 
972
#define SXG_SGL_SIZE(_Pool)                                             \
 
973
        (sizeof(struct sxg_scatter_gather) +                            \
 
974
         ((SxgSglPoolProperties[_Pool].SGEntries - 1) *                 \
 
975
                                sizeof(struct sxg_x64_sge)))
 
976
 
 
977
/* Force NDIS to give us it's own buffer so we can reformat to our own */
 
978
#define SXG_SGL_BUFFER(_SxgSgl)                 NULL
 
979
#define SXG_SGL_BUFFER_LENGTH(_SxgSgl)          0
 
980
#define SXG_SGL_BUF_SIZE                        0
 
981
 
 
982
/*
849
983
#if defined(CONFIG_X86_64)
850
 
#define SXG_SGL_BUFFER(_SxgSgl)         (&_SxgSgl->Sgl)
851
 
#define SXG_SGL_BUF_SIZE                        sizeof(struct SXG_X64_SGL)
 
984
#define SXG_SGL_BUFFER(_SxgSgl)             (&_SxgSgl->Sgl)
 
985
#define SXG_SGL_BUFFER_LENGTH(_SxgSgl)  ((_SxgSgl)->Entries *           \
 
986
                                        sizeof(struct sxg_x64_sge))
 
987
#define SXG_SGL_BUF_SIZE                            sizeof(struct sxg_x64_sgl)
852
988
#elif defined(CONFIG_X86)
853
989
// Force NDIS to give us it's own buffer so we can reformat to our own
854
 
#define SXG_SGL_BUFFER(_SxgSgl)         NULL
 
990
#define SXG_SGL_BUFFER(_SxgSgl)                 NULL
 
991
#define SXG_SGL_BUFFER_LENGTH(_SxgSgl)          0
855
992
#define SXG_SGL_BUF_SIZE                        0
856
993
#else
857
994
#error staging: sxg: driver is for X86 only!
858
995
#endif
 
996
*/
 
997
/* Microcode statistics */
 
998
struct sxg_ucode_stats {
 
999
        u32  RPDQOflow;         /* PDQ overflow (unframed ie dq & drop 1st) */
 
1000
        u32  XDrops;            /* Xmt drops due to no xmt buffer */
 
1001
        u32  ERDrops;           /* Rcv drops due to ER full */
 
1002
        u32  NBDrops;           /* Rcv drops due to out of host buffers */
 
1003
        u32  PQDrops;           /* Rcv drops due to PDQ full */
 
1004
        /* Rcv drops due to bad frame: no link addr match, frlen > max */
 
1005
        u32  BFDrops;
 
1006
        u32  UPDrops;           /* Rcv drops due to UPFq full */
 
1007
        u32  XNoBufs;           /* Xmt drop due to no DRAM Xmit buffer or PxyBuf */
 
1008
};
 
1009
 
 
1010
/*
 
1011
 * Macros for handling the Offload engine values
 
1012
 */
 
1013
/* Number of positions to shift Network Header Length before passing to card */
 
1014
#define SXG_NW_HDR_LEN_SHIFT            2