fmn.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 <linux/kernel.h>
  35. #include <linux/irqreturn.h>
  36. #include <linux/irq.h>
  37. #include <linux/interrupt.h>
  38. #include <asm/mipsregs.h>
  39. #include <asm/netlogic/interrupt.h>
  40. #include <asm/netlogic/xlr/fmn.h>
  41. #include <asm/netlogic/common.h>
  42. #define COP2_CC_INIT_CPU_DEST(dest, conf) \
  43. do { \
  44. nlm_write_c2_cc##dest(0, conf[(dest * 8) + 0]); \
  45. nlm_write_c2_cc##dest(1, conf[(dest * 8) + 1]); \
  46. nlm_write_c2_cc##dest(2, conf[(dest * 8) + 2]); \
  47. nlm_write_c2_cc##dest(3, conf[(dest * 8) + 3]); \
  48. nlm_write_c2_cc##dest(4, conf[(dest * 8) + 4]); \
  49. nlm_write_c2_cc##dest(5, conf[(dest * 8) + 5]); \
  50. nlm_write_c2_cc##dest(6, conf[(dest * 8) + 6]); \
  51. nlm_write_c2_cc##dest(7, conf[(dest * 8) + 7]); \
  52. } while (0)
  53. struct fmn_message_handler {
  54. void (*action)(int, int, int, int, struct nlm_fmn_msg *, void *);
  55. void *arg;
  56. } msg_handlers[128];
  57. /*
  58. * FMN interrupt handler. We configure the FMN so that any messages in
  59. * any of the CPU buckets will trigger an interrupt on the CPU.
  60. * The message can be from any device on the FMN (like NAE/SAE/DMA).
  61. * The source station id is used to figure out which of the registered
  62. * handlers have to be called.
  63. */
  64. static irqreturn_t fmn_message_handler(int irq, void *data)
  65. {
  66. struct fmn_message_handler *hndlr;
  67. int bucket, rv;
  68. int size = 0, code = 0, src_stnid = 0;
  69. struct nlm_fmn_msg msg;
  70. uint32_t mflags, bkt_status;
  71. mflags = nlm_cop2_enable_irqsave();
  72. /* Disable message ring interrupt */
  73. nlm_fmn_setup_intr(irq, 0);
  74. while (1) {
  75. /* 8 bkts per core, [24:31] each bit represents one bucket
  76. * Bit is Zero if bucket is not empty */
  77. bkt_status = (nlm_read_c2_status0() >> 24) & 0xff;
  78. if (bkt_status == 0xff)
  79. break;
  80. for (bucket = 0; bucket < 8; bucket++) {
  81. /* Continue on empty bucket */
  82. if (bkt_status & (1 << bucket))
  83. continue;
  84. rv = nlm_fmn_receive(bucket, &size, &code, &src_stnid,
  85. &msg);
  86. if (rv != 0)
  87. continue;
  88. hndlr = &msg_handlers[src_stnid];
  89. if (hndlr->action == NULL)
  90. pr_warn("No msgring handler for stnid %d\n",
  91. src_stnid);
  92. else {
  93. nlm_cop2_disable_irqrestore(mflags);
  94. hndlr->action(bucket, src_stnid, size, code,
  95. &msg, hndlr->arg);
  96. mflags = nlm_cop2_enable_irqsave();
  97. }
  98. }
  99. };
  100. /* Enable message ring intr, to any thread in core */
  101. nlm_fmn_setup_intr(irq, (1 << nlm_threads_per_core) - 1);
  102. nlm_cop2_disable_irqrestore(mflags);
  103. return IRQ_HANDLED;
  104. }
  105. struct irqaction fmn_irqaction = {
  106. .handler = fmn_message_handler,
  107. .flags = IRQF_PERCPU,
  108. .name = "fmn",
  109. };
  110. void xlr_percpu_fmn_init(void)
  111. {
  112. struct xlr_fmn_info *cpu_fmn_info;
  113. int *bucket_sizes;
  114. uint32_t flags;
  115. int id;
  116. BUG_ON(nlm_thread_id() != 0);
  117. id = nlm_core_id();
  118. bucket_sizes = xlr_board_fmn_config.bucket_size;
  119. cpu_fmn_info = &xlr_board_fmn_config.cpu[id];
  120. flags = nlm_cop2_enable_irqsave();
  121. /* Setup bucket sizes for the core. */
  122. nlm_write_c2_bucksize(0, bucket_sizes[id * 8 + 0]);
  123. nlm_write_c2_bucksize(1, bucket_sizes[id * 8 + 1]);
  124. nlm_write_c2_bucksize(2, bucket_sizes[id * 8 + 2]);
  125. nlm_write_c2_bucksize(3, bucket_sizes[id * 8 + 3]);
  126. nlm_write_c2_bucksize(4, bucket_sizes[id * 8 + 4]);
  127. nlm_write_c2_bucksize(5, bucket_sizes[id * 8 + 5]);
  128. nlm_write_c2_bucksize(6, bucket_sizes[id * 8 + 6]);
  129. nlm_write_c2_bucksize(7, bucket_sizes[id * 8 + 7]);
  130. /*
  131. * For sending FMN messages, we need credits on the destination
  132. * bucket. Program the credits this core has on the 128 possible
  133. * destination buckets.
  134. * We cannot use a loop here, because the the first argument has
  135. * to be a constant integer value.
  136. */
  137. COP2_CC_INIT_CPU_DEST(0, cpu_fmn_info->credit_config);
  138. COP2_CC_INIT_CPU_DEST(1, cpu_fmn_info->credit_config);
  139. COP2_CC_INIT_CPU_DEST(2, cpu_fmn_info->credit_config);
  140. COP2_CC_INIT_CPU_DEST(3, cpu_fmn_info->credit_config);
  141. COP2_CC_INIT_CPU_DEST(4, cpu_fmn_info->credit_config);
  142. COP2_CC_INIT_CPU_DEST(5, cpu_fmn_info->credit_config);
  143. COP2_CC_INIT_CPU_DEST(6, cpu_fmn_info->credit_config);
  144. COP2_CC_INIT_CPU_DEST(7, cpu_fmn_info->credit_config);
  145. COP2_CC_INIT_CPU_DEST(8, cpu_fmn_info->credit_config);
  146. COP2_CC_INIT_CPU_DEST(9, cpu_fmn_info->credit_config);
  147. COP2_CC_INIT_CPU_DEST(10, cpu_fmn_info->credit_config);
  148. COP2_CC_INIT_CPU_DEST(11, cpu_fmn_info->credit_config);
  149. COP2_CC_INIT_CPU_DEST(12, cpu_fmn_info->credit_config);
  150. COP2_CC_INIT_CPU_DEST(13, cpu_fmn_info->credit_config);
  151. COP2_CC_INIT_CPU_DEST(14, cpu_fmn_info->credit_config);
  152. COP2_CC_INIT_CPU_DEST(15, cpu_fmn_info->credit_config);
  153. /* enable FMN interrupts on this CPU */
  154. nlm_fmn_setup_intr(IRQ_FMN, (1 << nlm_threads_per_core) - 1);
  155. nlm_cop2_disable_irqrestore(flags);
  156. }
  157. /*
  158. * Register a FMN message handler with respect to the source station id
  159. * @stnid: source station id
  160. * @action: Handler function pointer
  161. */
  162. int nlm_register_fmn_handler(int start_stnid, int end_stnid,
  163. void (*action)(int, int, int, int, struct nlm_fmn_msg *, void *),
  164. void *arg)
  165. {
  166. int sstnid;
  167. for (sstnid = start_stnid; sstnid <= end_stnid; sstnid++) {
  168. msg_handlers[sstnid].arg = arg;
  169. smp_wmb();
  170. msg_handlers[sstnid].action = action;
  171. }
  172. pr_debug("Registered FMN msg handler for stnid %d-%d\n",
  173. start_stnid, end_stnid);
  174. return 0;
  175. }
  176. void nlm_setup_fmn_irq(void)
  177. {
  178. uint32_t flags;
  179. /* setup irq only once */
  180. setup_irq(IRQ_FMN, &fmn_irqaction);
  181. flags = nlm_cop2_enable_irqsave();
  182. nlm_fmn_setup_intr(IRQ_FMN, (1 << nlm_threads_per_core) - 1);
  183. nlm_cop2_disable_irqrestore(flags);
  184. }