1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This file is part of the Chelsio T1 Ethernet driver.
*
* Copyright (C) 2003-2005 Chelsio Communications. All rights reserved.
*/
#ifndef _CHELSIO_SGE_H
#define _CHELSIO_SGE_H
#pragma ident "%Z%%M% %I% %E% SMI"
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include "osdep.h"
#define MBLK_MAX 8
#define spin_lock mutex_enter
#define spin_unlock mutex_exit
#define atomic_sub(a, b) atomic_add_32(b, -(a))
#define atomic_add(a, b) atomic_add_32(b, (a))
#define atomic_read(a) (a)
#define atomic_set(a, b) (*(a) = b)
#define spinlock_t kmutex_t
#define dma_addr_t uint64_t
#define wmb() membar_producer()
#define doorbell_pio(sge, cmd) sge_ring_doorbell(sge, cmd)
#define skb_reserve(skb, offset) (skb->b_rptr += offset)
#define __skb_pull(skb, len) (skb->b_rptr += len)
#define skb_put(skb, len) ((skb)->b_wptr = (skb)->b_rptr + (len))
#define skb_pull(skb, len) (skb->b_rptr += len)
#define unlikely(a) (a)
#define likely(a) (a)
#define SKB_DATA_ALIGN(X) (((X) + (sizeof (long)-1)) & ~(sizeof (long)-1))
#define t1_is_T1B(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1B)
#define t1_is_T1C(adap) adapter_matches_type(adap, CHBT_TERM_T1, TERM_T1C)
#define SGE_SM_BUF_SZ(sa) (sa->ch_sm_buf_sz)
#define SGE_BG_BUF_SZ(sa) (sa->ch_bg_buf_sz)
#define SGE_CMDQ_N 2
#define SGE_FREELQ_N 2
#ifdef CONFIG_CHELSIO_T1_OFFLOAD
#define SGE_CMDQ0_E_N 4096
#define SGE_CMDQ1_E_N 128
#define SGE_FREELQ0_E_N 2048
#define SGE_FREELQ1_E_N 1024
#define SGE_RESPQ_E_N 7168 /* |CMDQ0| + |FREELQ0| + |FREELQ1| */
#else
#define SGE_CMDQ0_E_N 2048
#define SGE_CMDQ1_E_N 128
#define SGE_FREELQ0_E_N 4096
#define SGE_FREELQ1_E_N 1024
#define SGE_RESPQ_E_N 7168 /* |CMDQ0| + |FREELQ0| + |FREELQ1| */
#endif /* CONFIG_CHELSIO_T1_OFFLOAD */
#define SGE_BATCH_THRESH 16
#define SGE_INTR_BUCKETSIZE 100
#define SGE_INTR_MAXBUCKETS 11
#define SGE_INTRTIMER0 1
#define SGE_INTRTIMER1 30
#define SGE_INTRTIMER_NRES 10000
#define SGE_RX_COPY_THRESHOLD 256
#define SGE_RX_OFFSET 2
#ifdef CONFIG_CHELSIO_T1_OFFLOAD
#define SGE_RX_SM_BUF_SIZE(sa) 1536
#else
#define SGE_RX_SM_BUF_SIZE(sa) (sa->ch_sm_buf_sz)
#endif
/*
* CPL5 Defines
*/
#define FLITSTOBYTES 8
#define CPL_FORMAT_0_SIZE 8
#define CPL_FORMAT_1_SIZE 16
#define CPL_FORMAT_2_SIZE 24
#define CPL_FORMAT_3_SIZE 32
#define CPL_FORMAT_4_SIZE 40
#define CPL_FORMAT_5_SIZE 48
#define TID_MASK 0xffffff
#define SZ_CPL_RX_PKT CPL_FORMAT_0_SIZE
#if BYTE_ORDER == BIG_ENDIAN
typedef struct {
u32 AddrLow;
u32 GenerationBit: 1;
u32 BufferLength: 31;
u32 RespQueueSelector: 4;
u32 ResponseTokens: 12;
u32 CmdId: 8;
u32 Reserved: 3;
u32 TokenValid: 1;
u32 Eop: 1;
u32 Sop: 1;
u32 DataValid: 1;
u32 GenerationBit2: 1;
u32 AddrHigh;
} CmdQueueEntry;
#elif BYTE_ORDER == LITTLE_ENDIAN
typedef struct {
u32 BufferLength: 31;
u32 GenerationBit: 1;
u32 AddrLow;
u32 AddrHigh;
u32 GenerationBit2: 1;
u32 DataValid: 1;
u32 Sop: 1;
u32 Eop: 1;
u32 TokenValid: 1;
u32 Reserved: 3;
u32 CmdId: 8;
u32 ResponseTokens: 12;
u32 RespQueueSelector: 4;
} CmdQueueEntry;
#endif
typedef CmdQueueEntry cmdQ_e;
#if BYTE_ORDER == BIG_ENDIAN
typedef struct {
u32 Qsleeping: 4;
u32 Cmdq1CreditReturn: 5;
u32 Cmdq1DmaComplete: 5;
u32 Cmdq0CreditReturn: 5;
u32 Cmdq0DmaComplete: 5;
u32 FreelistQid: 2;
u32 CreditValid: 1;
u32 DataValid: 1;
u32 Offload: 1;
u32 Eop: 1;
u32 Sop: 1;
u32 GenerationBit: 1;
u32 BufferLength;
} ResponseQueueEntry;
#elif BYTE_ORDER == LITTLE_ENDIAN
typedef struct {
u32 BufferLength;
u32 GenerationBit: 1;
u32 Sop: 1;
u32 Eop: 1;
u32 Offload: 1;
u32 DataValid: 1;
u32 CreditValid: 1;
u32 FreelistQid: 2;
u32 Cmdq0DmaComplete: 5;
u32 Cmdq0CreditReturn: 5;
u32 Cmdq1DmaComplete: 5;
u32 Cmdq1CreditReturn: 5;
u32 Qsleeping: 4;
} ResponseQueueEntry;
#endif
typedef ResponseQueueEntry respQ_e;
#if BYTE_ORDER == BIG_ENDIAN
typedef struct {
u32 AddrLow;
u32 GenerationBit: 1;
u32 BufferLength: 31;
u32 Reserved: 31;
u32 GenerationBit2: 1;
u32 AddrHigh;
} FLQueueEntry;
#elif BYTE_ORDER == LITTLE_ENDIAN
typedef struct {
u32 BufferLength: 31;
u32 GenerationBit: 1;
u32 AddrLow;
u32 AddrHigh;
u32 GenerationBit2: 1;
u32 Reserved: 31;
} FLQueueEntry;
#endif
typedef FLQueueEntry freelQ_e;
/*
* Command QUEUE meta entry format.
*/
typedef struct cmdQ_ce {
void *ce_mp; /* head mblk of pkt */
free_dh_t *ce_dh; /* ddi dma handle */
uint_t ce_flg; /* flag 0 - NIC descriptor; 1 - TOE */
uint_t ce_len; /* length of mblk component */
uint64_t ce_pa; /* physical address */
} cmdQ_ce_t;
/*
* command queue control structure
*/
typedef struct cmdQ {
u32 cq_credits; /* # available descriptors for Xmit */
u32 cq_asleep; /* HW DMA Fetch status */
u32 cq_pio_pidx; /* Variable updated on Doorbell */
u32 cq_entries_n; /* # entries for Xmit */
u32 cq_pidx; /* producer index (SW) */
u32 cq_complete; /* Shadow consumer index (HW) */
u32 cq_cidx; /* consumer index (HW) */
u32 cq_genbit; /* current generation (=valid) bit */
cmdQ_e *cq_entries;
cmdQ_ce_t *cq_centries;
spinlock_t cq_qlock;
uint64_t cq_pa; /* may not be needed */
ulong_t cq_dh;
ulong_t cq_ah; /* may not be needed */
} cmdQ_t;
/*
* free list queue control structure
*/
typedef struct freelQ {
u32 fq_id; /* 0 queue 0, 1 queue 1 */
u32 fq_credits; /* # available RX buffer descriptors */
u32 fq_entries_n; /* # RX buffer descriptors */
u32 fq_pidx; /* producer index (SW) */
u32 fq_cidx; /* consumer index (HW) */
u32 fq_genbit; /* current generation (=valid) bit */
u32 fq_rx_buffer_size; /* size buffer on this freelist */
freelQ_e *fq_entries; /* HW freelist descriptor Q */
struct freelQ_ce *fq_centries; /* SW freelist conext descriptor Q */
uint64_t fq_pa; /* may not be needed */
ulong_t fq_dh;
ulong_t fq_ah;
u32 fq_pause_on_thresh;
u32 fq_pause_off_thresh;
} freelQ_t;
/*
* response queue control structure
*/
typedef struct respQ {
u32 rq_credits; /* # avail response Q entries */
u32 rq_credits_pend; /* # not yet returned entries */
u32 rq_credits_thresh; /* return threshold */
u32 rq_entries_n; /* # response Q descriptors */
u32 rq_pidx; /* producer index (HW) */
u32 rq_cidx; /* consumer index (SW) */
u32 rq_genbit; /* current generation(=valid) bit */
respQ_e *rq_entries; /* HW response Q */
uint64_t rq_pa; /* may not be needed */
ulong_t rq_dh;
ulong_t rq_ah;
} reapQ_t;
struct sge_intr_counts {
uint32_t respQ_empty; /* # times respQ empty */
uint32_t respQ_overflow; /* # respQ overflow (fatal) */
uint32_t freelistQ_empty; /* # times freelist empty */
uint32_t pkt_too_big; /* packet too large (fatal) */
uint32_t pkt_mismatch;
uint32_t cmdQ_full[2]; /* not HW intr, host cmdQ[] full */
uint32_t tx_reclaims[2];
uint32_t tx_msg_pullups; /* # of tx pkt coelescing events */
uint32_t tx_hdr_pullups; /* # of tx hdr coelescing events */
uint32_t tx_tcp_ip_frag; /* # of ip fragmentes for tcp data */
uint32_t tx_udp_ip_frag; /* # of ip fragmentes for udp data */
uint32_t tx_soft_cksums; /* # of Software checksums done. */
uint32_t tx_need_cpl_space; /* # of allocs for cpl header */
uint32_t tx_multi_mblks; /* # of Multi mblk packets */
uint32_t tx_no_dvma1; /* # of dvma mapping failures */
uint32_t tx_no_dvma2; /* # of dvma mapping failures */
uint32_t tx_no_dma1; /* # of dma mapping failures */
uint32_t tx_no_dma2; /* # of dma mapping failures */
uint32_t rx_cmdq0; /* # of Qsleeping CMDQ0's */
uint32_t rx_cmdq1; /* # of Qsleeping CMDQ1's */
uint32_t rx_flq0; /* # of Qsleeping FL0's */
uint32_t rx_flq1; /* # of Qsleeping FL1's */
uint32_t rx_flq0_sz; /* size of freelist-0 buffers */
uint32_t rx_flq1_sz; /* size of freelist-1 buffers */
uint32_t rx_pkt_drops; /* # intentionally dropped packets */
uint32_t rx_pkt_copied; /* # times packets copied by sge */
uint32_t rx_pause_on; /* # of system pause on's required. */
uint32_t rx_pause_off; /* # of system pauses off's required. */
uint32_t rx_pause_ms; /* micro seconds while paused */
uint32_t rx_pause_spike; /* maximum time paused */
uint32_t rx_fl_credits; /* Current free list credit usage. */
uint32_t rx_flbuf_fails; /* # of freelist buf alloc fails. */
uint32_t rx_flbuf_allocs; /* # of freelist buf allocs. */
uint32_t rx_badEopSop; /* # of times bad Eop/Sop received */
uint32_t rx_flq0_cnt; /* # of times free list Q 0 entry used */
uint32_t rx_flq1_cnt; /* # of times free list Q 1 entry used */
uint32_t arp_sent; /* # times arp packet sent */
#ifdef SUN_KSTATS
uint32_t tx_doorbells;
uint32_t intr_doorbells;
uint32_t intr1_doorbells;
uint32_t sleep_cnt;
uint32_t pe_allocb_cnt;
uint32_t tx_descs[MBLK_MAX];
#endif
};
#ifdef SUN_KSTATS
typedef struct sge_intr_counts *p_ch_stats_t;
/*
* Driver maintained kernel statistics.
*/
typedef struct _ch_kstat_t {
/*
* Link Input/Output stats
*/
kstat_named_t respQ_empty; /* # times respQ empty */
kstat_named_t respQ_overflow; /* # respQ overflow (fatal) */
kstat_named_t freelistQ_empty; /* # times freelist empty */
kstat_named_t pkt_too_big; /* packet too large (fatal) */
kstat_named_t pkt_mismatch;
kstat_named_t cmdQ_full[2]; /* not HW intr, host cmdQ[] full */
kstat_named_t tx_reclaims[2]; /* # of tx reclaims called */
kstat_named_t tx_msg_pullups; /* # of tx pkt coelescing events */
kstat_named_t tx_hdr_pullups; /* # of tx hdr coelescing events */
kstat_named_t tx_tcp_ip_frag; /* # of ip fragmentes for tcp data */
kstat_named_t tx_udp_ip_frag; /* # of ip fragmentes for udp data */
kstat_named_t tx_soft_cksums; /* # of Software checksums done. */
kstat_named_t tx_need_cpl_space; /* # of allocs for cpl header */
kstat_named_t tx_multi_mblks; /* # of multi fragment packets */
kstat_named_t tx_no_dvma1; /* # of dvma mapping failures */
kstat_named_t tx_no_dvma2; /* # of dvma mapping failures */
kstat_named_t tx_no_dma1; /* # of dma mapping failures */
kstat_named_t tx_no_dma2; /* # of dma mapping failures */
kstat_named_t rx_cmdq0; /* # times Qsleeping cmdq0 */
kstat_named_t rx_cmdq1; /* # times Qsleeping cmdq1 */
kstat_named_t rx_flq0; /* # times Qsleeping flq0 */
kstat_named_t rx_flq0_sz; /* size of freelist-0 buffers */
kstat_named_t rx_flq1; /* # times Qsleeping flq1 */
kstat_named_t rx_flq1_sz; /* size of freelist-1 buffers */
kstat_named_t rx_pkt_drops; /* # times packets dropped by sge */
kstat_named_t rx_pkt_copied; /* # intentionally copied packets */
kstat_named_t rx_pause_on; /* # of system pause on's required. */
kstat_named_t rx_pause_off; /* # of system pauses off's required. */
kstat_named_t rx_pause_ms; /* micro seconds while paused. */
kstat_named_t rx_pause_spike; /* maximum time paused. */
kstat_named_t rx_fl_credits; /* Current free list credit usage. */
kstat_named_t rx_flbuf_fails; /* # of freelist buf alloc fails. */
kstat_named_t rx_flbuf_allocs; /* # of freelist buf allocs. */
kstat_named_t rx_badEopSop; /* # of times bad Eop/Sop received */
kstat_named_t rx_flq0_cnt; /* # of times free list Q 0 entry used */
kstat_named_t rx_flq1_cnt; /* # of times free list Q 1 entry used */
kstat_named_t arp_sent; /* # times arp packet sent */
kstat_named_t tx_doorbells;
kstat_named_t intr_doorbells;
kstat_named_t intr1_doorbells;
kstat_named_t sleep_cnt;
kstat_named_t pe_allocb_cnt;
kstat_named_t tx_descs[MBLK_MAX];
} ch_kstat_t;
typedef ch_kstat_t *p_ch_kstat_t;
#endif
typedef struct _pesge {
peobj *obj; /* adapter backpointer */
struct freelQ freelQ[2]; /* freelist Q(s) */
struct respQ respQ; /* response Q instatiation */
uint32_t rx_pkt_pad; /* RX padding for T2 packets (hw) */
uint32_t rx_offset; /* RX padding for T1 packets (sw) */
uint32_t jumbo_fl; /* jumbo freelist Q index */
uint32_t intrtimer[SGE_INTR_MAXBUCKETS]; /* timer values */
uint32_t currIndex; /* current index into intrtimer[] */
uint32_t intrtimer_nres; /* no resource interrupt timer value */
uint32_t sge_control; /* shadow content of sge control reg */
struct sge_intr_counts intr_cnt;
#ifdef SUN_KSTATS
p_kstat_t ksp;
#endif
ch_cyclic_t espi_wa_cyclic;
uint32_t ptimeout;
void *pskb;
struct cmdQ cmdQ[2]; /* command Q(s) */
int do_udp_csum;
int do_tcp_csum;
} _pesge;
/*
* ce_flg flag values
*/
#define DH_DMA 1
#define DH_DVMA 2
#define DH_TOE 3
#define DH_ARP 8
typedef struct freelQ_ce {
void *fe_mp; /* head mblk of pkt */
ulong_t fe_dh; /* ddi dma handle */
uint_t fe_len; /* length of mblk component */
uint64_t fe_pa; /* physical address */
} freelQ_ce_t;
pesge *t1_sge_create(ch_t *, struct sge_params *);
extern int t1_sge_destroy(pesge* sge);
extern int sge_data_out(pesge*, int, mblk_t *, cmdQ_ce_t *, int, uint32_t);
extern int sge_data_in(pesge *);
extern int sge_start(pesge*);
extern int sge_stop(pesge *);
extern int t1_sge_configure(pesge *sge, struct sge_params *p);
extern int t1_sge_intr_error_handler(pesge*);
extern int t1_sge_intr_enable(pesge*);
extern int t1_sge_intr_disable(pesge*);
extern int t1_sge_intr_clear(pesge*);
extern u32 t1_sge_get_ptimeout(ch_t *);
extern void t1_sge_set_ptimeout(ch_t *, u32);
extern struct sge_intr_counts *sge_get_stat(pesge *);
extern void sge_add_fake_arp(pesge *, void *);
/*
* Default SGE settings
*/
#define SGE_CMDQ0_CNT (512)
#define SGE_FLQ0_CNT (512)
#define SGE_RESPQ_CNT (1024)
/*
* the structures below were taken from cpl5_cmd.h. It turns out that there
* is a number of #includes that causes build problems. For now, we're
* putting a private copy here. When the sge code is made common, then this
* problem will need to be resolved.
*/
typedef uint8_t __u8;
typedef uint32_t __u32;
typedef uint16_t __u16;
union opcode_tid {
__u32 opcode_tid;
__u8 opcode;
};
/*
* We want this header's alignment to be no more stringent than 2-byte aligned.
* All fields are u8 or u16 except for the length. However that field is not
* used so we break it into 2 16-bit parts to easily meet our alignment needs.
*/
struct cpl_tx_pkt {
__u8 opcode;
#if BYTE_ORDER == BIG_ENDIAN
__u8 rsvd:1;
__u8 vlan_valid:1;
__u8 l4_csum_dis:1;
__u8 ip_csum_dis:1;
__u8 iff:4;
#else
__u8 iff:4;
__u8 ip_csum_dis:1;
__u8 l4_csum_dis:1;
__u8 vlan_valid:1;
__u8 rsvd:1;
#endif
__u16 vlan;
__u16 len_hi;
__u16 len_lo;
};
#define CPL_TX_PKT 0xb2
#define SZ_CPL_TX_PKT CPL_FORMAT_0_SIZE
struct cpl_rx_data {
union opcode_tid ot;
__u32 len;
__u32 seq;
__u16 urg;
__u8 rsvd;
__u8 status;
};
struct cpl_rx_pkt {
__u8 opcode;
#if BYTE_ORDER == LITTLE_ENDIAN
__u8 iff:4;
__u8 csum_valid:1;
__u8 bad_pkt:1;
__u8 vlan_valid:1;
__u8 rsvd:1;
#else
__u8 rsvd:1;
__u8 vlan_valid:1;
__u8 bad_pkt:1;
__u8 csum_valid:1;
__u8 iff:4;
#endif
__u16 csum;
__u16 vlan;
__u16 len;
};
#ifdef __cplusplus
}
#endif
#endif /* _CHELSIO_SGE_H */
|