fmn.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. #ifndef _NLM_FMN_H_
  35. #define _NLM_FMN_H_
  36. #include <asm/netlogic/mips-extns.h> /* for COP2 access */
  37. /* Station IDs */
  38. #define FMN_STNID_CPU0 0x00
  39. #define FMN_STNID_CPU1 0x08
  40. #define FMN_STNID_CPU2 0x10
  41. #define FMN_STNID_CPU3 0x18
  42. #define FMN_STNID_CPU4 0x20
  43. #define FMN_STNID_CPU5 0x28
  44. #define FMN_STNID_CPU6 0x30
  45. #define FMN_STNID_CPU7 0x38
  46. #define FMN_STNID_XGS0_TX 64
  47. #define FMN_STNID_XMAC0_00_TX 64
  48. #define FMN_STNID_XMAC0_01_TX 65
  49. #define FMN_STNID_XMAC0_02_TX 66
  50. #define FMN_STNID_XMAC0_03_TX 67
  51. #define FMN_STNID_XMAC0_04_TX 68
  52. #define FMN_STNID_XMAC0_05_TX 69
  53. #define FMN_STNID_XMAC0_06_TX 70
  54. #define FMN_STNID_XMAC0_07_TX 71
  55. #define FMN_STNID_XMAC0_08_TX 72
  56. #define FMN_STNID_XMAC0_09_TX 73
  57. #define FMN_STNID_XMAC0_10_TX 74
  58. #define FMN_STNID_XMAC0_11_TX 75
  59. #define FMN_STNID_XMAC0_12_TX 76
  60. #define FMN_STNID_XMAC0_13_TX 77
  61. #define FMN_STNID_XMAC0_14_TX 78
  62. #define FMN_STNID_XMAC0_15_TX 79
  63. #define FMN_STNID_XGS1_TX 80
  64. #define FMN_STNID_XMAC1_00_TX 80
  65. #define FMN_STNID_XMAC1_01_TX 81
  66. #define FMN_STNID_XMAC1_02_TX 82
  67. #define FMN_STNID_XMAC1_03_TX 83
  68. #define FMN_STNID_XMAC1_04_TX 84
  69. #define FMN_STNID_XMAC1_05_TX 85
  70. #define FMN_STNID_XMAC1_06_TX 86
  71. #define FMN_STNID_XMAC1_07_TX 87
  72. #define FMN_STNID_XMAC1_08_TX 88
  73. #define FMN_STNID_XMAC1_09_TX 89
  74. #define FMN_STNID_XMAC1_10_TX 90
  75. #define FMN_STNID_XMAC1_11_TX 91
  76. #define FMN_STNID_XMAC1_12_TX 92
  77. #define FMN_STNID_XMAC1_13_TX 93
  78. #define FMN_STNID_XMAC1_14_TX 94
  79. #define FMN_STNID_XMAC1_15_TX 95
  80. #define FMN_STNID_GMAC 96
  81. #define FMN_STNID_GMACJFR_0 96
  82. #define FMN_STNID_GMACRFR_0 97
  83. #define FMN_STNID_GMACTX0 98
  84. #define FMN_STNID_GMACTX1 99
  85. #define FMN_STNID_GMACTX2 100
  86. #define FMN_STNID_GMACTX3 101
  87. #define FMN_STNID_GMACJFR_1 102
  88. #define FMN_STNID_GMACRFR_1 103
  89. #define FMN_STNID_DMA 104
  90. #define FMN_STNID_DMA_0 104
  91. #define FMN_STNID_DMA_1 105
  92. #define FMN_STNID_DMA_2 106
  93. #define FMN_STNID_DMA_3 107
  94. #define FMN_STNID_XGS0FR 112
  95. #define FMN_STNID_XMAC0JFR 112
  96. #define FMN_STNID_XMAC0RFR 113
  97. #define FMN_STNID_XGS1FR 114
  98. #define FMN_STNID_XMAC1JFR 114
  99. #define FMN_STNID_XMAC1RFR 115
  100. #define FMN_STNID_SEC 120
  101. #define FMN_STNID_SEC0 120
  102. #define FMN_STNID_SEC1 121
  103. #define FMN_STNID_SEC2 122
  104. #define FMN_STNID_SEC3 123
  105. #define FMN_STNID_PK0 124
  106. #define FMN_STNID_SEC_RSA 124
  107. #define FMN_STNID_SEC_RSVD0 125
  108. #define FMN_STNID_SEC_RSVD1 126
  109. #define FMN_STNID_SEC_RSVD2 127
  110. #define FMN_STNID_GMAC1 80
  111. #define FMN_STNID_GMAC1_FR_0 81
  112. #define FMN_STNID_GMAC1_TX0 82
  113. #define FMN_STNID_GMAC1_TX1 83
  114. #define FMN_STNID_GMAC1_TX2 84
  115. #define FMN_STNID_GMAC1_TX3 85
  116. #define FMN_STNID_GMAC1_FR_1 87
  117. #define FMN_STNID_GMAC0 96
  118. #define FMN_STNID_GMAC0_FR_0 97
  119. #define FMN_STNID_GMAC0_TX0 98
  120. #define FMN_STNID_GMAC0_TX1 99
  121. #define FMN_STNID_GMAC0_TX2 100
  122. #define FMN_STNID_GMAC0_TX3 101
  123. #define FMN_STNID_GMAC0_FR_1 103
  124. #define FMN_STNID_CMP_0 108
  125. #define FMN_STNID_CMP_1 109
  126. #define FMN_STNID_CMP_2 110
  127. #define FMN_STNID_CMP_3 111
  128. #define FMN_STNID_PCIE_0 116
  129. #define FMN_STNID_PCIE_1 117
  130. #define FMN_STNID_PCIE_2 118
  131. #define FMN_STNID_PCIE_3 119
  132. #define FMN_STNID_XLS_PK0 121
  133. #define nlm_read_c2_cc0(s) __read_32bit_c2_register($16, s)
  134. #define nlm_read_c2_cc1(s) __read_32bit_c2_register($17, s)
  135. #define nlm_read_c2_cc2(s) __read_32bit_c2_register($18, s)
  136. #define nlm_read_c2_cc3(s) __read_32bit_c2_register($19, s)
  137. #define nlm_read_c2_cc4(s) __read_32bit_c2_register($20, s)
  138. #define nlm_read_c2_cc5(s) __read_32bit_c2_register($21, s)
  139. #define nlm_read_c2_cc6(s) __read_32bit_c2_register($22, s)
  140. #define nlm_read_c2_cc7(s) __read_32bit_c2_register($23, s)
  141. #define nlm_read_c2_cc8(s) __read_32bit_c2_register($24, s)
  142. #define nlm_read_c2_cc9(s) __read_32bit_c2_register($25, s)
  143. #define nlm_read_c2_cc10(s) __read_32bit_c2_register($26, s)
  144. #define nlm_read_c2_cc11(s) __read_32bit_c2_register($27, s)
  145. #define nlm_read_c2_cc12(s) __read_32bit_c2_register($28, s)
  146. #define nlm_read_c2_cc13(s) __read_32bit_c2_register($29, s)
  147. #define nlm_read_c2_cc14(s) __read_32bit_c2_register($30, s)
  148. #define nlm_read_c2_cc15(s) __read_32bit_c2_register($31, s)
  149. #define nlm_write_c2_cc0(s, v) __write_32bit_c2_register($16, s, v)
  150. #define nlm_write_c2_cc1(s, v) __write_32bit_c2_register($17, s, v)
  151. #define nlm_write_c2_cc2(s, v) __write_32bit_c2_register($18, s, v)
  152. #define nlm_write_c2_cc3(s, v) __write_32bit_c2_register($19, s, v)
  153. #define nlm_write_c2_cc4(s, v) __write_32bit_c2_register($20, s, v)
  154. #define nlm_write_c2_cc5(s, v) __write_32bit_c2_register($21, s, v)
  155. #define nlm_write_c2_cc6(s, v) __write_32bit_c2_register($22, s, v)
  156. #define nlm_write_c2_cc7(s, v) __write_32bit_c2_register($23, s, v)
  157. #define nlm_write_c2_cc8(s, v) __write_32bit_c2_register($24, s, v)
  158. #define nlm_write_c2_cc9(s, v) __write_32bit_c2_register($25, s, v)
  159. #define nlm_write_c2_cc10(s, v) __write_32bit_c2_register($26, s, v)
  160. #define nlm_write_c2_cc11(s, v) __write_32bit_c2_register($27, s, v)
  161. #define nlm_write_c2_cc12(s, v) __write_32bit_c2_register($28, s, v)
  162. #define nlm_write_c2_cc13(s, v) __write_32bit_c2_register($29, s, v)
  163. #define nlm_write_c2_cc14(s, v) __write_32bit_c2_register($30, s, v)
  164. #define nlm_write_c2_cc15(s, v) __write_32bit_c2_register($31, s, v)
  165. #define nlm_read_c2_status0() __read_32bit_c2_register($2, 0)
  166. #define nlm_write_c2_status0(v) __write_32bit_c2_register($2, 0, v)
  167. #define nlm_read_c2_status1() __read_32bit_c2_register($2, 1)
  168. #define nlm_write_c2_status1(v) __write_32bit_c2_register($2, 1, v)
  169. #define nlm_read_c2_status(sel) __read_32bit_c2_register($2, 0)
  170. #define nlm_read_c2_config() __read_32bit_c2_register($3, 0)
  171. #define nlm_write_c2_config(v) __write_32bit_c2_register($3, 0, v)
  172. #define nlm_read_c2_bucksize(b) __read_32bit_c2_register($4, b)
  173. #define nlm_write_c2_bucksize(b, v) __write_32bit_c2_register($4, b, v)
  174. #define nlm_read_c2_rx_msg0() __read_64bit_c2_register($1, 0)
  175. #define nlm_read_c2_rx_msg1() __read_64bit_c2_register($1, 1)
  176. #define nlm_read_c2_rx_msg2() __read_64bit_c2_register($1, 2)
  177. #define nlm_read_c2_rx_msg3() __read_64bit_c2_register($1, 3)
  178. #define nlm_write_c2_tx_msg0(v) __write_64bit_c2_register($0, 0, v)
  179. #define nlm_write_c2_tx_msg1(v) __write_64bit_c2_register($0, 1, v)
  180. #define nlm_write_c2_tx_msg2(v) __write_64bit_c2_register($0, 2, v)
  181. #define nlm_write_c2_tx_msg3(v) __write_64bit_c2_register($0, 3, v)
  182. #define FMN_STN_RX_QSIZE 256
  183. #define FMN_NSTATIONS 128
  184. #define FMN_CORE_NBUCKETS 8
  185. static inline void nlm_msgsnd(unsigned int stid)
  186. {
  187. __asm__ volatile (
  188. ".set push\n"
  189. ".set noreorder\n"
  190. ".set noat\n"
  191. "move $1, %0\n"
  192. "c2 0x10001\n" /* msgsnd $1 */
  193. ".set pop\n"
  194. : : "r" (stid) : "$1"
  195. );
  196. }
  197. static inline void nlm_msgld(unsigned int pri)
  198. {
  199. __asm__ volatile (
  200. ".set push\n"
  201. ".set noreorder\n"
  202. ".set noat\n"
  203. "move $1, %0\n"
  204. "c2 0x10002\n" /* msgld $1 */
  205. ".set pop\n"
  206. : : "r" (pri) : "$1"
  207. );
  208. }
  209. static inline void nlm_msgwait(unsigned int mask)
  210. {
  211. __asm__ volatile (
  212. ".set push\n"
  213. ".set noreorder\n"
  214. ".set noat\n"
  215. "move $8, %0\n"
  216. "c2 0x10003\n" /* msgwait $1 */
  217. ".set pop\n"
  218. : : "r" (mask) : "$1"
  219. );
  220. }
  221. /*
  222. * Disable interrupts and enable COP2 access
  223. */
  224. static inline uint32_t nlm_cop2_enable_irqsave(void)
  225. {
  226. uint32_t sr = read_c0_status();
  227. write_c0_status((sr & ~ST0_IE) | ST0_CU2);
  228. return sr;
  229. }
  230. static inline void nlm_cop2_disable_irqrestore(uint32_t sr)
  231. {
  232. write_c0_status(sr);
  233. }
  234. static inline void nlm_fmn_setup_intr(int irq, unsigned int tmask)
  235. {
  236. uint32_t config;
  237. config = (1 << 24) /* interrupt water mark - 1 msg */
  238. | (irq << 16) /* irq */
  239. | (tmask << 8) /* thread mask */
  240. | 0x2; /* enable watermark intr, disable empty intr */
  241. nlm_write_c2_config(config);
  242. }
  243. struct nlm_fmn_msg {
  244. uint64_t msg0;
  245. uint64_t msg1;
  246. uint64_t msg2;
  247. uint64_t msg3;
  248. };
  249. static inline int nlm_fmn_send(unsigned int size, unsigned int code,
  250. unsigned int stid, struct nlm_fmn_msg *msg)
  251. {
  252. unsigned int dest;
  253. uint32_t status;
  254. int i;
  255. /*
  256. * Make sure that all the writes pending at the cpu are flushed.
  257. * Any writes pending on CPU will not be see by devices. L1/L2
  258. * caches are coherent with IO, so no cache flush needed.
  259. */
  260. __asm __volatile("sync");
  261. /* Load TX message buffers */
  262. nlm_write_c2_tx_msg0(msg->msg0);
  263. nlm_write_c2_tx_msg1(msg->msg1);
  264. nlm_write_c2_tx_msg2(msg->msg2);
  265. nlm_write_c2_tx_msg3(msg->msg3);
  266. dest = ((size - 1) << 16) | (code << 8) | stid;
  267. /*
  268. * Retry a few times on credit fail, this should be a
  269. * transient condition, unless there is a configuration
  270. * failure, or the receiver is stuck.
  271. */
  272. for (i = 0; i < 8; i++) {
  273. nlm_msgsnd(dest);
  274. status = nlm_read_c2_status0();
  275. if ((status & 0x2) == 1)
  276. pr_info("Send pending fail!\n");
  277. if ((status & 0x4) == 0)
  278. return 0;
  279. }
  280. /* If there is a credit failure, return error */
  281. return status & 0x06;
  282. }
  283. static inline int nlm_fmn_receive(int bucket, int *size, int *code, int *stid,
  284. struct nlm_fmn_msg *msg)
  285. {
  286. uint32_t status, tmp;
  287. nlm_msgld(bucket);
  288. /* wait for load pending to clear */
  289. do {
  290. status = nlm_read_c2_status0();
  291. } while ((status & 0x08) != 0);
  292. /* receive error bits */
  293. tmp = status & 0x30;
  294. if (tmp != 0)
  295. return tmp;
  296. *size = ((status & 0xc0) >> 6) + 1;
  297. *code = (status & 0xff00) >> 8;
  298. *stid = (status & 0x7f0000) >> 16;
  299. msg->msg0 = nlm_read_c2_rx_msg0();
  300. msg->msg1 = nlm_read_c2_rx_msg1();
  301. msg->msg2 = nlm_read_c2_rx_msg2();
  302. msg->msg3 = nlm_read_c2_rx_msg3();
  303. return 0;
  304. }
  305. struct xlr_fmn_info {
  306. int num_buckets;
  307. int start_stn_id;
  308. int end_stn_id;
  309. int credit_config[128];
  310. };
  311. struct xlr_board_fmn_config {
  312. int bucket_size[128]; /* size of buckets for all stations */
  313. struct xlr_fmn_info cpu[8];
  314. struct xlr_fmn_info gmac[2];
  315. struct xlr_fmn_info dma;
  316. struct xlr_fmn_info cmp;
  317. struct xlr_fmn_info sae;
  318. struct xlr_fmn_info xgmac[2];
  319. };
  320. extern int nlm_register_fmn_handler(int start, int end,
  321. void (*fn)(int, int, int, int, struct nlm_fmn_msg *, void *),
  322. void *arg);
  323. extern void xlr_percpu_fmn_init(void);
  324. extern void nlm_setup_fmn_irq(void);
  325. extern void xlr_board_info_setup(void);
  326. extern struct xlr_board_fmn_config xlr_board_fmn_config;
  327. #endif