fmn-config.c 9.7 KB

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