]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/mips/cavium/dev/rgmii/octeon_fpa.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / mips / cavium / dev / rgmii / octeon_fpa.h
1 /***********************license start***************
2  *  Copyright (c) 2003-2008 Cavium Networks (support@cavium.com). All rights
3  *  reserved.
4  *
5  *
6  *  Redistribution and use in source and binary forms, with or without
7  *  modification, are permitted provided that the following conditions are
8  *  met:
9  *
10  *      * Redistributions of source code must retain the above copyright
11  *        notice, this list of conditions and the following disclaimer.
12  *
13  *      * Redistributions in binary form must reproduce the above
14  *        copyright notice, this list of conditions and the following
15  *        disclaimer in the documentation and/or other materials provided
16  *        with the distribution.
17  *
18  *      * Neither the name of Cavium Networks nor the names of
19  *        its contributors may be used to endorse or promote products
20  *        derived from this software without specific prior written
21  *        permission.
22  *
23  *  TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24  *  AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25  *  OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26  *  RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27  *  REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28  *  DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29  *  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30  *  PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31  *  POSSESSION OR CORRESPONDENCE TO DESCRIPTION.  THE ENTIRE RISK ARISING OUT
32  *  OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
33  *
34  *
35  *  For any questions regarding licensing please contact marketing@caviumnetworks.com
36  *
37  ***********************license end**************************************/
38
39 /* $FreeBSD$ */
40
41 /*------------------------------------------------------------------
42  * octeon_fpa.h      Free Pool Allocator
43  *
44  *------------------------------------------------------------------
45  */
46
47
48 #ifndef ___OCTEON_FPA__H___
49 #define ___OCTEON_FPA__H___
50
51
52 #define OCTEON_FPA_FPA_OUTPUT_BUFFER_POOL           2    /* Same in octeon_rgmx.h */
53
54
55 /*
56  * OCTEON_FPA_FPF_MARKS = FPA's Queue Free Page FIFO Read Write Marks
57  *
58  * The high and low watermark register that determines when we write and
59  * read free pages from L2C for Queue.
60  */
61 typedef union {
62     uint64_t word64;
63     struct {
64         uint64_t reserved                : 42;      /* Must be zero */
65         uint64_t fpf_wr                  : 11;      /* Write Hi Water mark */
66         uint64_t fpf_rd                  : 11;      /* Read Lo Water mark */
67     } bits;
68 } octeon_fpa_fpf_marks_t;
69
70
71 /*
72  * OCTEON_FPA_CTL_STATUS = FPA's Control/Status Register
73  *
74  * The FPA's interrupt enable register.
75  * - Use with the CVMX_FPA_CTL_STATUS CSR.
76  */
77 typedef union {
78     uint64_t word64;
79     struct {
80         uint64_t reserved                : 49;      /* Must be zero */
81         uint64_t enb                     : 1;       /* Enable */
82         uint64_t mem1_err                : 7;       /* ECC flip 1 */
83         uint64_t mem0_err                : 7;       /* ECC flip 0 */
84     } bits;
85 } octeon_fpa_ctl_status_t;
86
87
88 /*
89  * OCTEON_FPA_FPF_SIZE = FPA's Queue N Free Page FIFO Size
90  *
91  * The number of page pointers that will be kept local to the FPA for
92  *  this Queue. FPA Queues are assigned in order from Queue 0 to
93  *  Queue 7, though only Queue 0 through Queue x can be used.
94  * The sum of the 8 (0-7)OCTEON_FPA_FPF#_SIZE registers must be limited to 2048.
95  * - Use with the CVMX_FPA_FPF0_SIZE CSR.
96  */
97 typedef union {
98     uint64_t word64;
99     struct {
100         uint64_t reserved                : 52;      /* Must be zero */
101       /*
102        * The number of entries assigned in the FPA FIFO (used to hold
103        * page-pointers) for this Queue.
104        * The value of this register must divisable by 2, and the FPA will
105        * ignore bit [0] of this register.
106        * The total of the FPF_SIZ field of the 8 (0-7)OCTEON_FPA_FPF#_MARKS
107        * registers must not exceed 2048.
108        * After writing this field the FPA will need 10 core clock cycles
109        * to be ready for operation. The assignment of location in
110        * the FPA FIFO must start with Queue 0, then 1, 2, etc.
111        * The number of useable entries will be FPF_SIZ-2.
112        */
113         uint64_t fpf_siz                 : 12;
114     } bits;
115 } octeon_fpa_fpf_size_t;
116
117 /*
118  *OCTEON_FPA_INT_ENB = FPA's Interrupt Enable
119  *
120  * The FPA's interrupt enable register.
121  * - Use with the CVMX_FPA_INT_ENB CSR.
122  */
123 typedef union {
124     uint64_t word64;
125     struct {
126         uint64_t reserved                : 60;  /* Must be zero */
127         uint64_t fed1_dbe                : 1;   /* Int iff bit3 Int-Sum set */
128         uint64_t fed1_sbe                : 1;   /* Int iff bit2 Int-Sum set */
129         uint64_t fed0_dbe                : 1;   /* Int iff bit1 Int-Sum set */
130         uint64_t fed0_sbe                : 1;   /* Int iff bit0 Int-Sum set */
131     } bits;
132 } octeon_fpa_int_enb_t;
133
134 /**
135  *OCTEON_FPA_INT_SUM = FPA's Interrupt Summary Register
136  *
137  * Contains the diffrent interrupt summary bits of the FPA.
138  * - Use with the CVMX_FPA_INT_SUM CSR.
139  */
140 typedef union {
141     uint64_t word64;
142     struct {
143         uint64_t reserved                : 60;      /**< Must be zero */
144         uint64_t fed1_dbe                : 1;
145         uint64_t fed1_sbe                : 1;
146         uint64_t fed0_dbe                : 1;
147         uint64_t fed0_sbe                : 1;
148     } bits;
149 } octeon_fpa_int_sum_t;
150
151
152 /*
153  *OCTEON_FPA_QUEUE_PAGES_AVAILABLE = FPA's Queue 0-7 Free Page Available Register
154  *
155  * The number of page pointers that are available in the FPA and local DRAM.
156  * - Use with the CVMX_FPA_QUEX_AVAILABLE(0..7) CSR.
157  */
158 typedef union {
159     uint64_t word64;
160     struct {
161         uint64_t reserved                : 38;      /* Must be zero */
162         uint64_t queue_size              : 26;      /* free pages available */
163     } bits;
164 } octeon_fpa_queue_available_t;
165
166
167 /*
168  *OCTEON_FPA_QUEUE_PAGE_INDEX
169  *
170  */
171 typedef union {
172     uint64_t word64;
173     struct {
174         uint64_t reserved                : 39;      /* Must be zero */
175         uint64_t page_index              : 25;      /* page_index */
176     } bits;
177 } octeon_fpa_queue_page_index_t;
178
179
180 #define OCTEON_DID_FPA                  5ULL
181
182 #define OCTEON_FPA_POOL_ALIGNMENT       (OCTEON_CACHE_LINE_SIZE)
183
184
185 /*
186  * Externs
187  */
188 extern void octeon_dump_fpa(void);
189 extern void octeon_dump_fpa_pool(u_int pool);
190 extern u_int octeon_fpa_pool_size(u_int pool);
191 extern void octeon_enable_fpa(void);
192 extern void octeon_fpa_fill_pool_mem(u_int pool,
193                                      u_int block_size_words,
194                                      u_int block_num);
195
196 /*
197  * octeon_fpa_free
198  *
199  * Free a mem-block to FPA pool.
200  *
201  * Takes away this 'buffer' from SW and passes it to FPA for management.
202  *
203  *  pool is FPA pool num, ptr is block ptr, num_cache_lines is number of
204  *  cache lines to invalidate (not written back).
205  */
206 static inline void octeon_fpa_free (void *ptr, u_int pool,
207                                     u_int num_cache_lines)
208 {
209     octeon_addr_t free_ptr;
210
211     free_ptr.word64 = (uint64_t)OCTEON_PTR2PHYS(ptr);
212
213     free_ptr.sfilldidspace.didspace = OCTEON_ADDR_DIDSPACE(
214         OCTEON_ADDR_FULL_DID(OCTEON_DID_FPA, pool));
215
216     /*
217      * Do not 'sync'
218      *     asm volatile ("sync\n");
219      */
220     oct_write64(free_ptr.word64, num_cache_lines);
221 }
222
223
224
225 /*
226  * octeon_fpa_alloc
227  *
228  * Allocate a new block from the FPA
229  *
230  * Buffer passes away from FPA management to SW control
231  */
232 static inline void *octeon_fpa_alloc (u_int pool)
233 {
234     uint64_t address;
235
236     address = oct_read64(OCTEON_ADDR_DID(OCTEON_ADDR_FULL_DID(OCTEON_DID_FPA,
237                                                               pool)));
238     if (address) {
239
240 /*
241  * 32 bit FPA pointers only
242  */
243         /*
244          * We only use 32 bit pointers at this time
245          */
246 /*XXX mips64 issue */
247         return ((void *) MIPS_PHYS_TO_KSEG0(address & 0xffffffff));
248     }
249     return (NULL);
250 }
251
252 static inline uint64_t octeon_fpa_alloc_phys (u_int pool)
253 {
254
255     return (oct_read64(OCTEON_ADDR_DID(OCTEON_ADDR_FULL_DID(OCTEON_DID_FPA,
256                                                             pool))));
257 }
258
259 #endif /* ___OCTEON_FPA__H___ */