linux/arch/mips/netlogic/xlr/fmn-config.c
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2003-2012 Broadcom Corporation
   3 * All Rights Reserved
   4 *
   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
   9 * license below:
  10 *
  11 * Redistribution and use in source and binary forms, with or without
  12 * modification, are permitted provided that the following conditions
  13 * are met:
  14 *
  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
  20 *    distribution.
  21 *
  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.
  33 */
  34
  35#include <asm/cpu-info.h>
  36#include <linux/irq.h>
  37#include <linux/interrupt.h>
  38
  39#include <asm/cpu.h>
  40#include <asm/mipsregs.h>
  41#include <asm/netlogic/xlr/fmn.h>
  42#include <asm/netlogic/xlr/xlr.h>
  43#include <asm/netlogic/common.h>
  44#include <asm/netlogic/haldefs.h>
  45
  46struct xlr_board_fmn_config xlr_board_fmn_config;
  47
  48static void __maybe_unused print_credit_config(struct xlr_fmn_info *fmn_info)
  49{
  50        int bkt;
  51
  52        pr_info("Bucket size :\n");
  53        pr_info("Station\t: Size\n");
  54        for (bkt = 0; bkt < 16; bkt++)
  55                pr_info(" %d  %d  %d  %d  %d  %d  %d %d\n",
  56                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 0],
  57                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 1],
  58                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 2],
  59                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 3],
  60                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 4],
  61                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 5],
  62                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 6],
  63                        xlr_board_fmn_config.bucket_size[(bkt * 8) + 7]);
  64        pr_info("\n");
  65
  66        pr_info("Credits distribution :\n");
  67        pr_info("Station\t: Size\n");
  68        for (bkt = 0; bkt < 16; bkt++)
  69                pr_info(" %d  %d  %d  %d  %d  %d  %d %d\n",
  70                        fmn_info->credit_config[(bkt * 8) + 0],
  71                        fmn_info->credit_config[(bkt * 8) + 1],
  72                        fmn_info->credit_config[(bkt * 8) + 2],
  73                        fmn_info->credit_config[(bkt * 8) + 3],
  74                        fmn_info->credit_config[(bkt * 8) + 4],
  75                        fmn_info->credit_config[(bkt * 8) + 5],
  76                        fmn_info->credit_config[(bkt * 8) + 6],
  77                        fmn_info->credit_config[(bkt * 8) + 7]);
  78        pr_info("\n");
  79}
  80
  81static void check_credit_distribution(void)
  82{
  83        struct xlr_board_fmn_config *cfg = &xlr_board_fmn_config;
  84        int bkt, n, total_credits, ncores;
  85
  86        ncores = hweight32(nlm_current_node()->coremask);
  87        for (bkt = 0; bkt < 128; bkt++) {
  88                total_credits = 0;
  89                for (n = 0; n < ncores; n++)
  90                        total_credits += cfg->cpu[n].credit_config[bkt];
  91                total_credits += cfg->gmac[0].credit_config[bkt];
  92                total_credits += cfg->gmac[1].credit_config[bkt];
  93                total_credits += cfg->dma.credit_config[bkt];
  94                total_credits += cfg->cmp.credit_config[bkt];
  95                total_credits += cfg->sae.credit_config[bkt];
  96                total_credits += cfg->xgmac[0].credit_config[bkt];
  97                total_credits += cfg->xgmac[1].credit_config[bkt];
  98                if (total_credits > cfg->bucket_size[bkt])
  99                        pr_err("ERROR: Bucket %d: credits (%d) > size (%d)\n",
 100                                bkt, total_credits, cfg->bucket_size[bkt]);
 101        }
 102        pr_info("Credit distribution complete.\n");
 103}
 104
 105/**
 106 * setup_fmn_cc -  Configure bucket size and credits for a device.
 107 * @dev_info: FMN information structure for each devices
 108 * @start_stn_id: Starting station id of dev_info
 109 * @end_stn_id: End station id of dev_info
 110 * @num_buckets: Total number of buckets for den_info
 111 * @cpu_credits: Allowed credits to cpu for each devices pointing by dev_info
 112 * @size: Size of the each buckets in the device station
 113 *
 114 * 'size' is the size of the buckets for the device. This size is
 115 * distributed among all the CPUs
 116 * so that all of them can send messages to the device.
 117 *
 118 * The device is also given 'cpu_credits' to send messages to the CPUs
 119 */
 120static void setup_fmn_cc(struct xlr_fmn_info *dev_info, int start_stn_id,
 121                int end_stn_id, int num_buckets, int cpu_credits, int size)
 122{
 123        int i, j, num_core, n, credits_per_cpu;
 124        struct xlr_fmn_info *cpu = xlr_board_fmn_config.cpu;
 125
 126        num_core = hweight32(nlm_current_node()->coremask);
 127        dev_info->num_buckets   = num_buckets;
 128        dev_info->start_stn_id  = start_stn_id;
 129        dev_info->end_stn_id    = end_stn_id;
 130
 131        n = num_core;
 132        if (num_core == 3)
 133                n = 4;
 134
 135        for (i = start_stn_id; i <= end_stn_id; i++) {
 136                xlr_board_fmn_config.bucket_size[i] = size;
 137
 138                /* Dividing device credits equally to cpus */
 139                credits_per_cpu = size / n;
 140                for (j = 0; j < num_core; j++)
 141                        cpu[j].credit_config[i] = credits_per_cpu;
 142
 143                /* credits left to distribute */
 144                credits_per_cpu = size - (credits_per_cpu * num_core);
 145
 146                /* distribute the remaining credits (if any), among cores */
 147                for (j = 0; (j < num_core) && (credits_per_cpu >= 4); j++) {
 148                        cpu[j].credit_config[i] += 4;
 149                        credits_per_cpu -= 4;
 150                }
 151        }
 152
 153        /* Distributing cpu per bucket credits to devices */
 154        for (i = 0; i < num_core; i++) {
 155                for (j = 0; j < FMN_CORE_NBUCKETS; j++)
 156                        dev_info->credit_config[(i * 8) + j] = cpu_credits;
 157        }
 158}
 159
 160/*
 161 * Each core has 256 slots and 8 buckets,
 162 * Configure the 8 buckets each with 32 slots
 163 */
 164static void setup_cpu_fmninfo(struct xlr_fmn_info *cpu, int num_core)
 165{
 166        int i, j;
 167
 168        for (i = 0; i < num_core; i++) {
 169                cpu[i].start_stn_id     = (8 * i);
 170                cpu[i].end_stn_id       = (8 * i + 8);
 171
 172                for (j = cpu[i].start_stn_id; j < cpu[i].end_stn_id; j++)
 173                        xlr_board_fmn_config.bucket_size[j] = 32;
 174        }
 175}
 176
 177/**
 178 * xlr_board_info_setup - Setup FMN details
 179 *
 180 * Setup the FMN details for each devices according to the device available
 181 * in each variant of XLR/XLS processor
 182 */
 183void xlr_board_info_setup(void)
 184{
 185        struct xlr_fmn_info *cpu = xlr_board_fmn_config.cpu;
 186        struct xlr_fmn_info *gmac = xlr_board_fmn_config.gmac;
 187        struct xlr_fmn_info *xgmac = xlr_board_fmn_config.xgmac;
 188        struct xlr_fmn_info *dma = &xlr_board_fmn_config.dma;
 189        struct xlr_fmn_info *cmp = &xlr_board_fmn_config.cmp;
 190        struct xlr_fmn_info *sae = &xlr_board_fmn_config.sae;
 191        int processor_id, num_core;
 192
 193        num_core = hweight32(nlm_current_node()->coremask);
 194        processor_id = read_c0_prid() & PRID_IMP_MASK;
 195
 196        setup_cpu_fmninfo(cpu, num_core);
 197        switch (processor_id) {
 198        case PRID_IMP_NETLOGIC_XLS104:
 199        case PRID_IMP_NETLOGIC_XLS108:
 200                setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
 201                                        FMN_STNID_GMAC0_TX3, 8, 16, 32);
 202                setup_fmn_cc(dma, FMN_STNID_DMA_0,
 203                                        FMN_STNID_DMA_3, 4, 8, 64);
 204                setup_fmn_cc(sae, FMN_STNID_SEC0,
 205                                        FMN_STNID_SEC1, 2, 8, 128);
 206                break;
 207
 208        case PRID_IMP_NETLOGIC_XLS204:
 209        case PRID_IMP_NETLOGIC_XLS208:
 210                setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
 211                                        FMN_STNID_GMAC0_TX3, 8, 16, 32);
 212                setup_fmn_cc(dma, FMN_STNID_DMA_0,
 213                                        FMN_STNID_DMA_3, 4, 8, 64);
 214                setup_fmn_cc(sae, FMN_STNID_SEC0,
 215                                        FMN_STNID_SEC1, 2, 8, 128);
 216                break;
 217
 218        case PRID_IMP_NETLOGIC_XLS404:
 219        case PRID_IMP_NETLOGIC_XLS408:
 220        case PRID_IMP_NETLOGIC_XLS404B:
 221        case PRID_IMP_NETLOGIC_XLS408B:
 222        case PRID_IMP_NETLOGIC_XLS416B:
 223        case PRID_IMP_NETLOGIC_XLS608B:
 224        case PRID_IMP_NETLOGIC_XLS616B:
 225                setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
 226                                        FMN_STNID_GMAC0_TX3, 8, 8, 32);
 227                setup_fmn_cc(&gmac[1], FMN_STNID_GMAC1_FR_0,
 228                                        FMN_STNID_GMAC1_TX3, 8, 8, 32);
 229                setup_fmn_cc(dma, FMN_STNID_DMA_0,
 230                                        FMN_STNID_DMA_3, 4, 4, 64);
 231                setup_fmn_cc(cmp, FMN_STNID_CMP_0,
 232                                        FMN_STNID_CMP_3, 4, 4, 64);
 233                setup_fmn_cc(sae, FMN_STNID_SEC0,
 234                                        FMN_STNID_SEC1, 2, 8, 128);
 235                break;
 236
 237        case PRID_IMP_NETLOGIC_XLS412B:
 238                setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
 239                                        FMN_STNID_GMAC0_TX3, 8, 8, 32);
 240                setup_fmn_cc(&gmac[1], FMN_STNID_GMAC1_FR_0,
 241                                        FMN_STNID_GMAC1_TX3, 8, 8, 32);
 242                setup_fmn_cc(dma, FMN_STNID_DMA_0,
 243                                        FMN_STNID_DMA_3, 4, 4, 64);
 244                setup_fmn_cc(cmp, FMN_STNID_CMP_0,
 245                                        FMN_STNID_CMP_3, 4, 4, 64);
 246                setup_fmn_cc(sae, FMN_STNID_SEC0,
 247                                        FMN_STNID_SEC1, 2, 8, 128);
 248                break;
 249
 250        case PRID_IMP_NETLOGIC_XLR308:
 251        case PRID_IMP_NETLOGIC_XLR308C:
 252                setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
 253                                        FMN_STNID_GMAC0_TX3, 8, 16, 32);
 254                setup_fmn_cc(dma, FMN_STNID_DMA_0,
 255                                        FMN_STNID_DMA_3, 4, 8, 64);
 256                setup_fmn_cc(sae, FMN_STNID_SEC0,
 257                                        FMN_STNID_SEC1, 2, 4, 128);
 258                break;
 259
 260        case PRID_IMP_NETLOGIC_XLR532:
 261        case PRID_IMP_NETLOGIC_XLR532C:
 262        case PRID_IMP_NETLOGIC_XLR516C:
 263        case PRID_IMP_NETLOGIC_XLR508C:
 264                setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
 265                                        FMN_STNID_GMAC0_TX3, 8, 16, 32);
 266                setup_fmn_cc(dma, FMN_STNID_DMA_0,
 267                                        FMN_STNID_DMA_3, 4, 8, 64);
 268                setup_fmn_cc(sae, FMN_STNID_SEC0,
 269                                        FMN_STNID_SEC1, 2, 4, 128);
 270                break;
 271
 272        case PRID_IMP_NETLOGIC_XLR732:
 273        case PRID_IMP_NETLOGIC_XLR716:
 274                setup_fmn_cc(&xgmac[0], FMN_STNID_XMAC0_00_TX,
 275                                        FMN_STNID_XMAC0_15_TX, 8, 0, 32);
 276                setup_fmn_cc(&xgmac[1], FMN_STNID_XMAC1_00_TX,
 277                                        FMN_STNID_XMAC1_15_TX, 8, 0, 32);
 278                setup_fmn_cc(&gmac[0], FMN_STNID_GMAC0,
 279                                        FMN_STNID_GMAC0_TX3, 8, 24, 32);
 280                setup_fmn_cc(dma, FMN_STNID_DMA_0,
 281                                        FMN_STNID_DMA_3, 4, 4, 64);
 282                setup_fmn_cc(sae, FMN_STNID_SEC0,
 283                                        FMN_STNID_SEC1, 2, 4, 128);
 284                break;
 285        default:
 286                pr_err("Unknown CPU with processor ID [%d]\n", processor_id);
 287                pr_err("Error: Cannot initialize FMN credits.\n");
 288        }
 289
 290        check_credit_distribution();
 291
 292#if 0 /* debug */
 293        print_credit_config(&cpu[0]);
 294        print_credit_config(&gmac[0]);
 295#endif
 296}
 297