2 * Copyright (c) 2003-2012 Broadcom Corporation
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the Broadcom
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
22 * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include <asm/cpu-info.h>
36 #include <linux/irq.h>
37 #include <linux/interrupt.h>
39 #include <asm/mipsregs.h>
40 #include <asm/netlogic/xlr/fmn.h>
41 #include <asm/netlogic/xlr/xlr.h>
42 #include <asm/netlogic/common.h>
43 #include <asm/netlogic/haldefs.h>
45 struct xlr_board_fmn_config xlr_board_fmn_config;
47 static void __maybe_unused print_credit_config(struct xlr_fmn_info *fmn_info)
51 pr_info("Bucket size :\n");
52 pr_info("Station\t: Size\n");
53 for (bkt = 0; bkt < 16; bkt++)
54 pr_info(" %d %d %d %d %d %d %d %d\n",
55 xlr_board_fmn_config.bucket_size[(bkt * 8) + 0],
56 xlr_board_fmn_config.bucket_size[(bkt * 8) + 1],
57 xlr_board_fmn_config.bucket_size[(bkt * 8) + 2],
58 xlr_board_fmn_config.bucket_size[(bkt * 8) + 3],
59 xlr_board_fmn_config.bucket_size[(bkt * 8) + 4],
60 xlr_board_fmn_config.bucket_size[(bkt * 8) + 5],
61 xlr_board_fmn_config.bucket_size[(bkt * 8) + 6],
62 xlr_board_fmn_config.bucket_size[(bkt * 8) + 7]);
65 pr_info("Credits distribution :\n");
66 pr_info("Station\t: Size\n");
67 for (bkt = 0; bkt < 16; bkt++)
68 pr_info(" %d %d %d %d %d %d %d %d\n",
69 fmn_info->credit_config[(bkt * 8) + 0],
70 fmn_info->credit_config[(bkt * 8) + 1],
71 fmn_info->credit_config[(bkt * 8) + 2],
72 fmn_info->credit_config[(bkt * 8) + 3],
73 fmn_info->credit_config[(bkt * 8) + 4],
74 fmn_info->credit_config[(bkt * 8) + 5],
75 fmn_info->credit_config[(bkt * 8) + 6],
76 fmn_info->credit_config[(bkt * 8) + 7]);
80 static void check_credit_distribution(void)
82 struct xlr_board_fmn_config *cfg = &xlr_board_fmn_config;
83 int bkt, n, total_credits, ncores;
85 ncores = hweight32(nlm_current_node()->coremask);
86 for (bkt = 0; bkt < 128; bkt++) {
88 for (n = 0; n < ncores; n++)
89 total_credits += cfg->cpu[n].credit_config[bkt];
90 total_credits += cfg->gmac[0].credit_config[bkt];
91 total_credits += cfg->gmac[1].credit_config[bkt];
92 total_credits += cfg->dma.credit_config[bkt];
93 total_credits += cfg->cmp.credit_config[bkt];
94 total_credits += cfg->sae.credit_config[bkt];
95 total_credits += cfg->xgmac[0].credit_config[bkt];
96 total_credits += cfg->xgmac[1].credit_config[bkt];
97 if (total_credits > cfg->bucket_size[bkt])
98 pr_err("ERROR: Bucket %d: credits (%d) > size (%d)\n",
99 bkt, total_credits, cfg->bucket_size[bkt]);
101 pr_info("Credit distribution complete.\n");
105 * Configure bucket size and credits for a device. 'size' is the size of
106 * the buckets for the device. This size is distributed among all the CPUs
107 * so that all of them can send messages to the device.
109 * The device is also given 'cpu_credits' to send messages to the CPUs
111 * @dev_info: FMN information structure for each devices
112 * @start_stn_id: Starting station id of dev_info
113 * @end_stn_id: End station id of dev_info
114 * @num_buckets: Total number of buckets for den_info
115 * @cpu_credits: Allowed credits to cpu for each devices pointing by dev_info
116 * @size: Size of the each buckets in the device station
118 static void setup_fmn_cc(struct xlr_fmn_info *dev_info, int start_stn_id,
119 int end_stn_id, int num_buckets, int cpu_credits, int size)
121 int i, j, num_core, n, credits_per_cpu;
122 struct xlr_fmn_info *cpu = xlr_board_fmn_config.cpu;
124 num_core = hweight32(nlm_current_node()->coremask);
125 dev_info->num_buckets = num_buckets;
126 dev_info->start_stn_id = start_stn_id;
127 dev_info->end_stn_id = end_stn_id;
133 for (i = start_stn_id; i <= end_stn_id; i++) {
134 xlr_board_fmn_config.bucket_size[i] = size;
136 /* Dividing device credits equally to cpus */
137 credits_per_cpu = size / n;
138 for (j = 0; j < num_core; j++)
139 cpu[j].credit_config[i] = credits_per_cpu;
141 /* credits left to distribute */
142 credits_per_cpu = size - (credits_per_cpu * num_core);
144 /* distribute the remaining credits (if any), among cores */
145 for (j = 0; (j < num_core) && (credits_per_cpu >= 4); j++) {
146 cpu[j].credit_config[i] += 4;
147 credits_per_cpu -= 4;
151 /* Distributing cpu per bucket credits to devices */
152 for (i = 0; i < num_core; i++) {
153 for (j = 0; j < FMN_CORE_NBUCKETS; j++)
154 dev_info->credit_config[(i * 8) + j] = cpu_credits;
159 * Each core has 256 slots and 8 buckets,
160 * Configure the 8 buckets each with 32 slots
162 static void setup_cpu_fmninfo(struct xlr_fmn_info *cpu, int num_core)
166 for (i = 0; i < num_core; i++) {
167 cpu[i].start_stn_id = (8 * i);
168 cpu[i].end_stn_id = (8 * i + 8);
170 for (j = cpu[i].start_stn_id; j < cpu[i].end_stn_id; j++)
171 xlr_board_fmn_config.bucket_size[j] = 32;
176 * Setup the FMN details for each devices according to the device available
177 * in each variant of XLR/XLS processor
179 void xlr_board_info_setup(void)
181 struct xlr_fmn_info *cpu = xlr_board_fmn_config.cpu;
182 struct xlr_fmn_info *gmac = xlr_board_fmn_config.gmac;
183 struct xlr_fmn_info *xgmac = xlr_board_fmn_config.xgmac;
184 struct xlr_fmn_info *dma = &xlr_board_fmn_config.dma;
185 struct xlr_fmn_info *cmp = &xlr_board_fmn_config.cmp;
186 struct xlr_fmn_info *sae = &xlr_board_fmn_config.sae;
187 int processor_id, num_core;
189 num_core = hweight32(nlm_current_node()->coremask);
190 processor_id = read_c0_prid() & 0xff00;
192 setup_cpu_fmninfo(cpu, num_core);
193 switch (processor_id) {
194 case PRID_IMP_NETLOGIC_XLS104:
195 case PRID_IMP_NETLOGIC_XLS108:
196 setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
197 FMN_STNID_GMAC0_TX3, 8, 16, 32);
198 setup_fmn_cc(dma, FMN_STNID_DMA_0,
199 FMN_STNID_DMA_3, 4, 8, 64);
200 setup_fmn_cc(sae, FMN_STNID_SEC0,
201 FMN_STNID_SEC1, 2, 8, 128);
204 case PRID_IMP_NETLOGIC_XLS204:
205 case PRID_IMP_NETLOGIC_XLS208:
206 setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
207 FMN_STNID_GMAC0_TX3, 8, 16, 32);
208 setup_fmn_cc(dma, FMN_STNID_DMA_0,
209 FMN_STNID_DMA_3, 4, 8, 64);
210 setup_fmn_cc(sae, FMN_STNID_SEC0,
211 FMN_STNID_SEC1, 2, 8, 128);
214 case PRID_IMP_NETLOGIC_XLS404:
215 case PRID_IMP_NETLOGIC_XLS408:
216 case PRID_IMP_NETLOGIC_XLS404B:
217 case PRID_IMP_NETLOGIC_XLS408B:
218 case PRID_IMP_NETLOGIC_XLS416B:
219 case PRID_IMP_NETLOGIC_XLS608B:
220 case PRID_IMP_NETLOGIC_XLS616B:
221 setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
222 FMN_STNID_GMAC0_TX3, 8, 8, 32);
223 setup_fmn_cc(&gmac[1], FMN_STNID_GMAC1_FR_0,
224 FMN_STNID_GMAC1_TX3, 8, 8, 32);
225 setup_fmn_cc(dma, FMN_STNID_DMA_0,
226 FMN_STNID_DMA_3, 4, 4, 64);
227 setup_fmn_cc(cmp, FMN_STNID_CMP_0,
228 FMN_STNID_CMP_3, 4, 4, 64);
229 setup_fmn_cc(sae, FMN_STNID_SEC0,
230 FMN_STNID_SEC1, 2, 8, 128);
233 case PRID_IMP_NETLOGIC_XLS412B:
234 setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
235 FMN_STNID_GMAC0_TX3, 8, 8, 32);
236 setup_fmn_cc(&gmac[1], FMN_STNID_GMAC1_FR_0,
237 FMN_STNID_GMAC1_TX3, 8, 8, 32);
238 setup_fmn_cc(dma, FMN_STNID_DMA_0,
239 FMN_STNID_DMA_3, 4, 4, 64);
240 setup_fmn_cc(cmp, FMN_STNID_CMP_0,
241 FMN_STNID_CMP_3, 4, 4, 64);
242 setup_fmn_cc(sae, FMN_STNID_SEC0,
243 FMN_STNID_SEC1, 2, 8, 128);
246 case PRID_IMP_NETLOGIC_XLR308:
247 case PRID_IMP_NETLOGIC_XLR308C:
248 setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
249 FMN_STNID_GMAC0_TX3, 8, 16, 32);
250 setup_fmn_cc(dma, FMN_STNID_DMA_0,
251 FMN_STNID_DMA_3, 4, 8, 64);
252 setup_fmn_cc(sae, FMN_STNID_SEC0,
253 FMN_STNID_SEC1, 2, 4, 128);
256 case PRID_IMP_NETLOGIC_XLR532:
257 case PRID_IMP_NETLOGIC_XLR532C:
258 case PRID_IMP_NETLOGIC_XLR516C:
259 case PRID_IMP_NETLOGIC_XLR508C:
260 setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
261 FMN_STNID_GMAC0_TX3, 8, 16, 32);
262 setup_fmn_cc(dma, FMN_STNID_DMA_0,
263 FMN_STNID_DMA_3, 4, 8, 64);
264 setup_fmn_cc(sae, FMN_STNID_SEC0,
265 FMN_STNID_SEC1, 2, 4, 128);
268 case PRID_IMP_NETLOGIC_XLR732:
269 case PRID_IMP_NETLOGIC_XLR716:
270 setup_fmn_cc(&xgmac[0], FMN_STNID_XMAC0_00_TX,
271 FMN_STNID_XMAC0_15_TX, 8, 0, 32);
272 setup_fmn_cc(&xgmac[1], FMN_STNID_XMAC1_00_TX,
273 FMN_STNID_XMAC1_15_TX, 8, 0, 32);
274 setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
275 FMN_STNID_GMAC0_TX3, 8, 24, 32);
276 setup_fmn_cc(dma, FMN_STNID_DMA_0,
277 FMN_STNID_DMA_3, 4, 4, 64);
278 setup_fmn_cc(sae, FMN_STNID_SEC0,
279 FMN_STNID_SEC1, 2, 4, 128);
282 pr_err("Unknown CPU with processor ID [%d]\n", processor_id);
283 pr_err("Error: Cannot initialize FMN credits.\n");
286 check_credit_distribution();
289 print_credit_config(&cpu[0]);
290 print_credit_config(&gmac[0]);