sxgbe_mtl.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* 10G controller driver for Samsung SoCs
  2. *
  3. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Author: Siva Reddy Kallam <siva.kallam@samsung.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/io.h>
  14. #include <linux/errno.h>
  15. #include <linux/export.h>
  16. #include <linux/jiffies.h>
  17. #include "sxgbe_mtl.h"
  18. #include "sxgbe_reg.h"
  19. static void sxgbe_mtl_init(void __iomem *ioaddr, unsigned int etsalg,
  20. unsigned int raa)
  21. {
  22. u32 reg_val;
  23. reg_val = readl(ioaddr + SXGBE_MTL_OP_MODE_REG);
  24. reg_val &= ETS_RST;
  25. /* ETS Algorith */
  26. switch (etsalg & SXGBE_MTL_OPMODE_ESTMASK) {
  27. case ETS_WRR:
  28. reg_val &= ETS_WRR;
  29. break;
  30. case ETS_WFQ:
  31. reg_val |= ETS_WFQ;
  32. break;
  33. case ETS_DWRR:
  34. reg_val |= ETS_DWRR;
  35. break;
  36. }
  37. writel(reg_val, ioaddr + SXGBE_MTL_OP_MODE_REG);
  38. switch (raa & SXGBE_MTL_OPMODE_RAAMASK) {
  39. case RAA_SP:
  40. reg_val &= RAA_SP;
  41. break;
  42. case RAA_WSP:
  43. reg_val |= RAA_WSP;
  44. break;
  45. }
  46. writel(reg_val, ioaddr + SXGBE_MTL_OP_MODE_REG);
  47. }
  48. /* For Dynamic DMA channel mapping for Rx queue */
  49. static void sxgbe_mtl_dma_dm_rxqueue(void __iomem *ioaddr)
  50. {
  51. writel(RX_QUEUE_DYNAMIC, ioaddr + SXGBE_MTL_RXQ_DMAMAP0_REG);
  52. writel(RX_QUEUE_DYNAMIC, ioaddr + SXGBE_MTL_RXQ_DMAMAP1_REG);
  53. writel(RX_QUEUE_DYNAMIC, ioaddr + SXGBE_MTL_RXQ_DMAMAP2_REG);
  54. }
  55. static void sxgbe_mtl_set_txfifosize(void __iomem *ioaddr, int queue_num,
  56. int queue_fifo)
  57. {
  58. u32 fifo_bits, reg_val;
  59. /* 0 means 256 bytes */
  60. fifo_bits = (queue_fifo / SXGBE_MTL_TX_FIFO_DIV) - 1;
  61. reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  62. reg_val |= (fifo_bits << SXGBE_MTL_FIFO_LSHIFT);
  63. writel(reg_val, ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  64. }
  65. static void sxgbe_mtl_set_rxfifosize(void __iomem *ioaddr, int queue_num,
  66. int queue_fifo)
  67. {
  68. u32 fifo_bits, reg_val;
  69. /* 0 means 256 bytes */
  70. fifo_bits = (queue_fifo / SXGBE_MTL_RX_FIFO_DIV)-1;
  71. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  72. reg_val |= (fifo_bits << SXGBE_MTL_FIFO_LSHIFT);
  73. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  74. }
  75. static void sxgbe_mtl_enable_txqueue(void __iomem *ioaddr, int queue_num)
  76. {
  77. u32 reg_val;
  78. reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  79. reg_val |= SXGBE_MTL_ENABLE_QUEUE;
  80. writel(reg_val, ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  81. }
  82. static void sxgbe_mtl_disable_txqueue(void __iomem *ioaddr, int queue_num)
  83. {
  84. u32 reg_val;
  85. reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  86. reg_val &= ~SXGBE_MTL_ENABLE_QUEUE;
  87. writel(reg_val, ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  88. }
  89. static void sxgbe_mtl_fc_active(void __iomem *ioaddr, int queue_num,
  90. int threshold)
  91. {
  92. u32 reg_val;
  93. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  94. reg_val &= ~(SXGBE_MTL_FCMASK << RX_FC_ACTIVE);
  95. reg_val |= (threshold << RX_FC_ACTIVE);
  96. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  97. }
  98. static void sxgbe_mtl_fc_enable(void __iomem *ioaddr, int queue_num)
  99. {
  100. u32 reg_val;
  101. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  102. reg_val |= SXGBE_MTL_ENABLE_FC;
  103. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  104. }
  105. static void sxgbe_mtl_fc_deactive(void __iomem *ioaddr, int queue_num,
  106. int threshold)
  107. {
  108. u32 reg_val;
  109. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  110. reg_val &= ~(SXGBE_MTL_FCMASK << RX_FC_DEACTIVE);
  111. reg_val |= (threshold << RX_FC_DEACTIVE);
  112. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  113. }
  114. static void sxgbe_mtl_fep_enable(void __iomem *ioaddr, int queue_num)
  115. {
  116. u32 reg_val;
  117. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  118. reg_val |= SXGBE_MTL_RXQ_OP_FEP;
  119. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  120. }
  121. static void sxgbe_mtl_fep_disable(void __iomem *ioaddr, int queue_num)
  122. {
  123. u32 reg_val;
  124. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  125. reg_val &= ~(SXGBE_MTL_RXQ_OP_FEP);
  126. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  127. }
  128. static void sxgbe_mtl_fup_enable(void __iomem *ioaddr, int queue_num)
  129. {
  130. u32 reg_val;
  131. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  132. reg_val |= SXGBE_MTL_RXQ_OP_FUP;
  133. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  134. }
  135. static void sxgbe_mtl_fup_disable(void __iomem *ioaddr, int queue_num)
  136. {
  137. u32 reg_val;
  138. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  139. reg_val &= ~(SXGBE_MTL_RXQ_OP_FUP);
  140. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  141. }
  142. static void sxgbe_set_tx_mtl_mode(void __iomem *ioaddr, int queue_num,
  143. int tx_mode)
  144. {
  145. u32 reg_val;
  146. reg_val = readl(ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  147. /* TX specific MTL mode settings */
  148. if (tx_mode == SXGBE_MTL_SFMODE) {
  149. reg_val |= SXGBE_MTL_SFMODE;
  150. } else {
  151. /* set the TTC values */
  152. if (tx_mode <= 64)
  153. reg_val |= MTL_CONTROL_TTC_64;
  154. else if (tx_mode <= 96)
  155. reg_val |= MTL_CONTROL_TTC_96;
  156. else if (tx_mode <= 128)
  157. reg_val |= MTL_CONTROL_TTC_128;
  158. else if (tx_mode <= 192)
  159. reg_val |= MTL_CONTROL_TTC_192;
  160. else if (tx_mode <= 256)
  161. reg_val |= MTL_CONTROL_TTC_256;
  162. else if (tx_mode <= 384)
  163. reg_val |= MTL_CONTROL_TTC_384;
  164. else
  165. reg_val |= MTL_CONTROL_TTC_512;
  166. }
  167. /* write into TXQ operation register */
  168. writel(reg_val, ioaddr + SXGBE_MTL_TXQ_OPMODE_REG(queue_num));
  169. }
  170. static void sxgbe_set_rx_mtl_mode(void __iomem *ioaddr, int queue_num,
  171. int rx_mode)
  172. {
  173. u32 reg_val;
  174. reg_val = readl(ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  175. /* RX specific MTL mode settings */
  176. if (rx_mode == SXGBE_RX_MTL_SFMODE) {
  177. reg_val |= SXGBE_RX_MTL_SFMODE;
  178. } else {
  179. if (rx_mode <= 64)
  180. reg_val |= MTL_CONTROL_RTC_64;
  181. else if (rx_mode <= 96)
  182. reg_val |= MTL_CONTROL_RTC_96;
  183. else if (rx_mode <= 128)
  184. reg_val |= MTL_CONTROL_RTC_128;
  185. }
  186. /* write into RXQ operation register */
  187. writel(reg_val, ioaddr + SXGBE_MTL_RXQ_OPMODE_REG(queue_num));
  188. }
  189. static const struct sxgbe_mtl_ops mtl_ops = {
  190. .mtl_set_txfifosize = sxgbe_mtl_set_txfifosize,
  191. .mtl_set_rxfifosize = sxgbe_mtl_set_rxfifosize,
  192. .mtl_enable_txqueue = sxgbe_mtl_enable_txqueue,
  193. .mtl_disable_txqueue = sxgbe_mtl_disable_txqueue,
  194. .mtl_dynamic_dma_rxqueue = sxgbe_mtl_dma_dm_rxqueue,
  195. .set_tx_mtl_mode = sxgbe_set_tx_mtl_mode,
  196. .set_rx_mtl_mode = sxgbe_set_rx_mtl_mode,
  197. .mtl_init = sxgbe_mtl_init,
  198. .mtl_fc_active = sxgbe_mtl_fc_active,
  199. .mtl_fc_deactive = sxgbe_mtl_fc_deactive,
  200. .mtl_fc_enable = sxgbe_mtl_fc_enable,
  201. .mtl_fep_enable = sxgbe_mtl_fep_enable,
  202. .mtl_fep_disable = sxgbe_mtl_fep_disable,
  203. .mtl_fup_enable = sxgbe_mtl_fup_enable,
  204. .mtl_fup_disable = sxgbe_mtl_fup_disable
  205. };
  206. const struct sxgbe_mtl_ops *sxgbe_get_mtl_ops(void)
  207. {
  208. return &mtl_ops;
  209. }