summaryrefslogtreecommitdiffstats
path: root/drivers/atm/he.h
blob: f3f53674ef3fce339664b152ad0a7e7defe07f9d (plain)
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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
/*

  he.h

  ForeRunnerHE ATM Adapter driver for ATM on Linux
  Copyright (C) 1999-2001  Naval Research Laboratory

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

/*

  he.h

  ForeRunnerHE ATM Adapter driver for ATM on Linux
  Copyright (C) 1999-2000  Naval Research Laboratory

  Permission to use, copy, modify and distribute this software and its
  documentation is hereby granted, provided that both the copyright
  notice and this permission notice appear in all copies of the software,
  derivative works or modified versions, and any portions thereof, and
  that both notices appear in supporting documentation.

  NRL ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
  DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
  RESULTING FROM THE USE OF THIS SOFTWARE.

 */

#ifndef _HE_H_
#define _HE_H_

#define DEV_LABEL       "he"

#define CONFIG_DEFAULT_VCIBITS	12
#define CONFIG_DEFAULT_VPIBITS	0

#define CONFIG_IRQ_SIZE		128
#define CONFIG_IRQ_THRESH	(CONFIG_IRQ_SIZE/2)

#define CONFIG_TPDRQ_SIZE	512
#define TPDRQ_MASK(x)		(((unsigned long)(x))&((CONFIG_TPDRQ_SIZE<<3)-1))

#define CONFIG_RBRQ_SIZE	512
#define CONFIG_RBRQ_THRESH	400
#define RBRQ_MASK(x)		(((unsigned long)(x))&((CONFIG_RBRQ_SIZE<<3)-1))

#define CONFIG_TBRQ_SIZE	512
#define CONFIG_TBRQ_THRESH	400
#define TBRQ_MASK(x)		(((unsigned long)(x))&((CONFIG_TBRQ_SIZE<<2)-1))

#define CONFIG_RBPL_SIZE	512
#define CONFIG_RBPL_THRESH	64
#define CONFIG_RBPL_BUFSIZE	4096
#define RBPL_MASK(x)		(((unsigned long)(x))&((CONFIG_RBPL_SIZE<<3)-1))

/* 5.1.3 initialize connection memory */

#define CONFIG_RSRA		0x00000
#define CONFIG_RCMLBM		0x08000
#define CONFIG_RCMABR		0x0d800
#define CONFIG_RSRB		0x0e000

#define CONFIG_TSRA		0x00000
#define CONFIG_TSRB		0x08000
#define CONFIG_TSRC		0x0c000
#define CONFIG_TSRD		0x0e000
#define CONFIG_TMABR		0x0f000
#define CONFIG_TPDBA		0x10000

#define HE_MAXCIDBITS		12

/* 2.9.3.3 interrupt encodings */

struct he_irq {
	volatile u32 isw;
};

#define IRQ_ALIGNMENT		0x1000

#define NEXT_ENTRY(base, tail, mask) \
				(((unsigned long)base)|(((unsigned long)(tail+1))&mask))

#define ITYPE_INVALID		0xffffffff
#define ITYPE_TBRQ_THRESH	(0<<3)
#define ITYPE_TPD_COMPLETE	(1<<3)
#define ITYPE_RBPS_THRESH	(2<<3)
#define ITYPE_RBPL_THRESH	(3<<3)
#define ITYPE_RBRQ_THRESH	(4<<3)
#define ITYPE_RBRQ_TIMER	(5<<3)
#define ITYPE_PHY		(6<<3)
#define ITYPE_OTHER		0x80
#define ITYPE_PARITY		0x81
#define ITYPE_ABORT		0x82

#define ITYPE_GROUP(x)		(x & 0x7)
#define ITYPE_TYPE(x)		(x & 0xf8)

#define HE_NUM_GROUPS 8

/* 2.1.4 transmit packet descriptor */

struct he_tpd {

	/* read by the adapter */

	volatile u32 status;
	volatile u32 reserved;

#define TPD_MAXIOV	3
	struct {
		u32 addr, len;
	} iovec[TPD_MAXIOV];

#define address0 iovec[0].addr
#define length0 iovec[0].len

	/* linux-atm extensions */

	struct sk_buff *skb;
	struct atm_vcc *vcc;

	struct list_head entry;
};

#define TPD_ALIGNMENT	64
#define TPD_LEN_MASK	0xffff

#define TPD_ADDR_SHIFT  6
#define TPD_MASK	0xffffffc0
#define TPD_ADDR(x)	((x) & TPD_MASK)
#define TPD_INDEX(x)	(TPD_ADDR(x) >> TPD_ADDR_SHIFT)


/* table 2.3 transmit buffer return elements */

struct he_tbrq {
	volatile u32 tbre;
};

#define TBRQ_ALIGNMENT	CONFIG_TBRQ_SIZE

#define TBRQ_TPD(tbrq)		((tbrq)->tbre & 0xffffffc0)
#define TBRQ_EOS(tbrq)		((tbrq)->tbre & (1<<3))
#define TBRQ_MULTIPLE(tbrq)	((tbrq)->tbre & (1))

/* table 2.21 receive buffer return queue element field organization */

struct he_rbrq {
	volatile u32 addr;
	volatile u32 cidlen;
};

#define RBRQ_ALIGNMENT	CONFIG_RBRQ_SIZE

#define RBRQ_ADDR(rbrq)		((rbrq)->addr & 0xffffffc0)
#define RBRQ_CRC_ERR(rbrq)	((rbrq)->addr & (1<<5))
#define RBRQ_LEN_ERR(rbrq)	((rbrq)->addr & (1<<4))
#define RBRQ_END_PDU(rbrq)	((rbrq)->addr & (1<<3))
#define RBRQ_AAL5_PROT(rbrq)	((rbrq)->addr & (1<<2))
#define RBRQ_CON_CLOSED(rbrq)	((rbrq)->addr & (1<<1))
#define RBRQ_HBUF_ERR(rbrq)	((rbrq)->addr & 1)
#define RBRQ_CID(rbrq)		(((rbrq)->cidlen >> 16) & 0x1fff)
#define RBRQ_BUFLEN(rbrq)	((rbrq)->cidlen & 0xffff)

/* figure 2.3 transmit packet descriptor ready queue */

struct he_tpdrq {
	volatile u32 tpd;
	volatile u32 cid;
};

#define TPDRQ_ALIGNMENT CONFIG_TPDRQ_SIZE

/* table 2.30 host status page detail */

#define HSP_ALIGNMENT	0x400		/* must align on 1k boundary */

struct he_hsp {
	struct he_hsp_entry {
		volatile u32 tbrq_tail; 
		volatile u32 reserved1[15];
		volatile u32 rbrq_tail; 
		volatile u32 reserved2[15];
	} group[HE_NUM_GROUPS];
};

/*
 * figure 2.9 receive buffer pools
 *
 * since a virtual address might be more than 32 bits, we store an index
 * in the virt member of he_rbp.  NOTE: the lower six bits in the  rbrq
 * addr member are used for buffer status further limiting us to 26 bits.
 */

struct he_rbp {
	volatile u32 phys;
	volatile u32 idx;	/* virt */
};

#define RBP_IDX_OFFSET 6

/*
 * the he dma engine will try to hold an extra 16 buffers in its local
 * caches.  and add a couple buffers for safety.
 */

#define RBPL_TABLE_SIZE (CONFIG_RBPL_SIZE + 16 + 2)

struct he_buff {
	struct list_head entry;
	dma_addr_t mapping;
	unsigned long len;
	u8 data[];
};

#ifdef notyet
struct he_group {
	u32 rpbl_size, rpbl_qsize;
	struct he_rpb_entry *rbpl_ba;
};
#endif

#define HE_LOOKUP_VCC(dev, cid) ((dev)->he_vcc_table[(cid)].vcc)

struct he_vcc_table 
{
	struct atm_vcc *vcc;
};

struct he_cs_stper
{
	long pcr;
	int inuse;
};

#define HE_NUM_CS_STPER		16

struct he_dev {
	unsigned int number;
	unsigned int irq;
	void __iomem *membase;

	char prod_id[30];
	char mac_addr[6];
	int media;

	unsigned int vcibits, vpibits;
	unsigned int cells_per_row;
	unsigned int bytes_per_row;
	unsigned int cells_per_lbuf;
	unsigned int r0_numrows, r0_startrow, r0_numbuffs;
	unsigned int r1_numrows, r1_startrow, r1_numbuffs;
	unsigned int tx_numrows, tx_startrow, tx_numbuffs;
	unsigned int buffer_limit;

	struct he_vcc_table *he_vcc_table;

#ifdef notyet
	struct he_group group[HE_NUM_GROUPS];
#endif
	struct he_cs_stper cs_stper[HE_NUM_CS_STPER];
	unsigned total_bw;

	dma_addr_t irq_phys;
	struct he_irq *irq_base, *irq_head, *irq_tail;
	volatile unsigned *irq_tailoffset;
	int irq_peak;

	struct tasklet_struct tasklet;
	struct dma_pool *tpd_pool;
	struct list_head outstanding_tpds;

	dma_addr_t tpdrq_phys;
	struct he_tpdrq *tpdrq_base, *tpdrq_tail, *tpdrq_head;

	spinlock_t global_lock;		/* 8.1.5 pci transaction ordering
					  error problem */
	dma_addr_t rbrq_phys;
	struct he_rbrq *rbrq_base, *rbrq_head;
	int rbrq_peak;

	struct he_buff **rbpl_virt;
	unsigned long *rbpl_table;
	unsigned long rbpl_hint;
	struct dma_pool *rbpl_pool;
	dma_addr_t rbpl_phys;
	struct he_rbp *rbpl_base, *rbpl_tail;
	struct list_head rbpl_outstanding;
	int rbpl_peak;

	dma_addr_t tbrq_phys;
	struct he_tbrq *tbrq_base, *tbrq_head;
	int tbrq_peak;

	dma_addr_t hsp_phys;
	struct he_hsp *hsp;

	struct pci_dev *pci_dev;
	struct atm_dev *atm_dev;
	struct he_dev *next;
};

#define HE_MAXIOV 20

struct he_vcc
{
	struct list_head buffers;
	int pdu_len;
	int rc_index;

	wait_queue_head_t rx_waitq;
	wait_queue_head_t tx_waitq;
};

#define HE_VCC(vcc)	((struct he_vcc *)(vcc->dev_data))

#define PCI_VENDOR_ID_FORE	0x1127
#define PCI_DEVICE_ID_FORE_HE	0x400

#define GEN_CNTL_0				0x40
#define  INT_PROC_ENBL		(1<<25)
#define  SLAVE_ENDIAN_MODE	(1<<16)
#define  MRL_ENB		(1<<5)
#define  MRM_ENB		(1<<4)
#define  INIT_ENB		(1<<2)
#define  IGNORE_TIMEOUT		(1<<1)
#define  ENBL_64		(1<<0)

#define MIN_PCI_LATENCY		32	/* errata 8.1.3 */

#define HE_DEV(dev) ((struct he_dev *) (dev)->dev_data)

#define he_is622(dev)	((dev)->media & 0x1)
#define he_isMM(dev)	((dev)->media & 0x20)

#define HE_REGMAP_SIZE	0x100000

#define RESET_CNTL	0x80000