fmn-config.c 9.6 KB

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