sxgbe_core.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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/export.h>
  14. #include <linux/io.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/phy.h>
  17. #include "sxgbe_common.h"
  18. #include "sxgbe_reg.h"
  19. /* MAC core initialization */
  20. static void sxgbe_core_init(void __iomem *ioaddr)
  21. {
  22. u32 regval;
  23. /* TX configuration */
  24. regval = readl(ioaddr + SXGBE_CORE_TX_CONFIG_REG);
  25. /* Other configurable parameters IFP, IPG, ISR, ISM
  26. * needs to be set if needed
  27. */
  28. regval |= SXGBE_TX_JABBER_DISABLE;
  29. writel(regval, ioaddr + SXGBE_CORE_TX_CONFIG_REG);
  30. /* RX configuration */
  31. regval = readl(ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  32. /* Other configurable parameters CST, SPEN, USP, GPSLCE
  33. * WD, LM, S2KP, HDSMS, GPSL, ELEN, ARPEN needs to be
  34. * set if needed
  35. */
  36. regval |= SXGBE_RX_JUMBPKT_ENABLE | SXGBE_RX_ACS_ENABLE;
  37. writel(regval, ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  38. }
  39. /* Dump MAC registers */
  40. static void sxgbe_core_dump_regs(void __iomem *ioaddr)
  41. {
  42. }
  43. static int sxgbe_get_lpi_status(void __iomem *ioaddr, const u32 irq_status)
  44. {
  45. int status = 0;
  46. int lpi_status;
  47. /* Reading this register shall clear all the LPI status bits */
  48. lpi_status = readl(ioaddr + SXGBE_CORE_LPI_CTRL_STATUS);
  49. if (lpi_status & LPI_CTRL_STATUS_TLPIEN)
  50. status |= TX_ENTRY_LPI_MODE;
  51. if (lpi_status & LPI_CTRL_STATUS_TLPIEX)
  52. status |= TX_EXIT_LPI_MODE;
  53. if (lpi_status & LPI_CTRL_STATUS_RLPIEN)
  54. status |= RX_ENTRY_LPI_MODE;
  55. if (lpi_status & LPI_CTRL_STATUS_RLPIEX)
  56. status |= RX_EXIT_LPI_MODE;
  57. return status;
  58. }
  59. /* Handle extra events on specific interrupts hw dependent */
  60. static int sxgbe_core_host_irq_status(void __iomem *ioaddr,
  61. struct sxgbe_extra_stats *x)
  62. {
  63. int irq_status, status = 0;
  64. irq_status = readl(ioaddr + SXGBE_CORE_INT_STATUS_REG);
  65. if (unlikely(irq_status & LPI_INT_STATUS))
  66. status |= sxgbe_get_lpi_status(ioaddr, irq_status);
  67. return status;
  68. }
  69. /* Set power management mode (e.g. magic frame) */
  70. static void sxgbe_core_pmt(void __iomem *ioaddr, unsigned long mode)
  71. {
  72. }
  73. /* Set/Get Unicast MAC addresses */
  74. static void sxgbe_core_set_umac_addr(void __iomem *ioaddr, unsigned char *addr,
  75. unsigned int reg_n)
  76. {
  77. u32 high_word, low_word;
  78. high_word = (addr[5] << 8) | (addr[4]);
  79. low_word = (addr[3] << 24) | (addr[2] << 16) |
  80. (addr[1] << 8) | (addr[0]);
  81. writel(high_word, ioaddr + SXGBE_CORE_ADD_HIGHOFFSET(reg_n));
  82. writel(low_word, ioaddr + SXGBE_CORE_ADD_LOWOFFSET(reg_n));
  83. }
  84. static void sxgbe_core_get_umac_addr(void __iomem *ioaddr, unsigned char *addr,
  85. unsigned int reg_n)
  86. {
  87. u32 high_word, low_word;
  88. high_word = readl(ioaddr + SXGBE_CORE_ADD_HIGHOFFSET(reg_n));
  89. low_word = readl(ioaddr + SXGBE_CORE_ADD_LOWOFFSET(reg_n));
  90. /* extract and assign address */
  91. addr[5] = (high_word & 0x0000FF00) >> 8;
  92. addr[4] = (high_word & 0x000000FF);
  93. addr[3] = (low_word & 0xFF000000) >> 24;
  94. addr[2] = (low_word & 0x00FF0000) >> 16;
  95. addr[1] = (low_word & 0x0000FF00) >> 8;
  96. addr[0] = (low_word & 0x000000FF);
  97. }
  98. static void sxgbe_enable_tx(void __iomem *ioaddr, bool enable)
  99. {
  100. u32 tx_config;
  101. tx_config = readl(ioaddr + SXGBE_CORE_TX_CONFIG_REG);
  102. tx_config &= ~SXGBE_TX_ENABLE;
  103. if (enable)
  104. tx_config |= SXGBE_TX_ENABLE;
  105. writel(tx_config, ioaddr + SXGBE_CORE_TX_CONFIG_REG);
  106. }
  107. static void sxgbe_enable_rx(void __iomem *ioaddr, bool enable)
  108. {
  109. u32 rx_config;
  110. rx_config = readl(ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  111. rx_config &= ~SXGBE_RX_ENABLE;
  112. if (enable)
  113. rx_config |= SXGBE_RX_ENABLE;
  114. writel(rx_config, ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  115. }
  116. static int sxgbe_get_controller_version(void __iomem *ioaddr)
  117. {
  118. return readl(ioaddr + SXGBE_CORE_VERSION_REG);
  119. }
  120. /* If supported then get the optional core features */
  121. static unsigned int sxgbe_get_hw_feature(void __iomem *ioaddr,
  122. unsigned char feature_index)
  123. {
  124. return readl(ioaddr + (SXGBE_CORE_HW_FEA_REG(feature_index)));
  125. }
  126. static void sxgbe_core_set_speed(void __iomem *ioaddr, unsigned char speed)
  127. {
  128. u32 tx_cfg = readl(ioaddr + SXGBE_CORE_TX_CONFIG_REG);
  129. /* clear the speed bits */
  130. tx_cfg &= ~0x60000000;
  131. tx_cfg |= (speed << SXGBE_SPEED_LSHIFT);
  132. /* set the speed */
  133. writel(tx_cfg, ioaddr + SXGBE_CORE_TX_CONFIG_REG);
  134. }
  135. static void sxgbe_core_enable_rxqueue(void __iomem *ioaddr, int queue_num)
  136. {
  137. u32 reg_val;
  138. reg_val = readl(ioaddr + SXGBE_CORE_RX_CTL0_REG);
  139. reg_val &= ~(SXGBE_CORE_RXQ_ENABLE_MASK << queue_num);
  140. reg_val |= SXGBE_CORE_RXQ_ENABLE;
  141. writel(reg_val, ioaddr + SXGBE_CORE_RX_CTL0_REG);
  142. }
  143. static void sxgbe_core_disable_rxqueue(void __iomem *ioaddr, int queue_num)
  144. {
  145. u32 reg_val;
  146. reg_val = readl(ioaddr + SXGBE_CORE_RX_CTL0_REG);
  147. reg_val &= ~(SXGBE_CORE_RXQ_ENABLE_MASK << queue_num);
  148. reg_val |= SXGBE_CORE_RXQ_DISABLE;
  149. writel(reg_val, ioaddr + SXGBE_CORE_RX_CTL0_REG);
  150. }
  151. static void sxgbe_set_eee_mode(void __iomem *ioaddr)
  152. {
  153. u32 ctrl;
  154. /* Enable the LPI mode for transmit path with Tx automate bit set.
  155. * When Tx Automate bit is set, MAC internally handles the entry
  156. * to LPI mode after all outstanding and pending packets are
  157. * transmitted.
  158. */
  159. ctrl = readl(ioaddr + SXGBE_CORE_LPI_CTRL_STATUS);
  160. ctrl |= LPI_CTRL_STATUS_LPIEN | LPI_CTRL_STATUS_TXA;
  161. writel(ctrl, ioaddr + SXGBE_CORE_LPI_CTRL_STATUS);
  162. }
  163. static void sxgbe_reset_eee_mode(void __iomem *ioaddr)
  164. {
  165. u32 ctrl;
  166. ctrl = readl(ioaddr + SXGBE_CORE_LPI_CTRL_STATUS);
  167. ctrl &= ~(LPI_CTRL_STATUS_LPIEN | LPI_CTRL_STATUS_TXA);
  168. writel(ctrl, ioaddr + SXGBE_CORE_LPI_CTRL_STATUS);
  169. }
  170. static void sxgbe_set_eee_pls(void __iomem *ioaddr, const int link)
  171. {
  172. u32 ctrl;
  173. ctrl = readl(ioaddr + SXGBE_CORE_LPI_CTRL_STATUS);
  174. /* If the PHY link status is UP then set PLS */
  175. if (link)
  176. ctrl |= LPI_CTRL_STATUS_PLS;
  177. else
  178. ctrl &= ~LPI_CTRL_STATUS_PLS;
  179. writel(ctrl, ioaddr + SXGBE_CORE_LPI_CTRL_STATUS);
  180. }
  181. static void sxgbe_set_eee_timer(void __iomem *ioaddr,
  182. const int ls, const int tw)
  183. {
  184. int value = ((tw & 0xffff)) | ((ls & 0x7ff) << 16);
  185. /* Program the timers in the LPI timer control register:
  186. * LS: minimum time (ms) for which the link
  187. * status from PHY should be ok before transmitting
  188. * the LPI pattern.
  189. * TW: minimum time (us) for which the core waits
  190. * after it has stopped transmitting the LPI pattern.
  191. */
  192. writel(value, ioaddr + SXGBE_CORE_LPI_TIMER_CTRL);
  193. }
  194. static void sxgbe_enable_rx_csum(void __iomem *ioaddr)
  195. {
  196. u32 ctrl;
  197. ctrl = readl(ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  198. ctrl |= SXGBE_RX_CSUMOFFLOAD_ENABLE;
  199. writel(ctrl, ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  200. }
  201. static void sxgbe_disable_rx_csum(void __iomem *ioaddr)
  202. {
  203. u32 ctrl;
  204. ctrl = readl(ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  205. ctrl &= ~SXGBE_RX_CSUMOFFLOAD_ENABLE;
  206. writel(ctrl, ioaddr + SXGBE_CORE_RX_CONFIG_REG);
  207. }
  208. static const struct sxgbe_core_ops core_ops = {
  209. .core_init = sxgbe_core_init,
  210. .dump_regs = sxgbe_core_dump_regs,
  211. .host_irq_status = sxgbe_core_host_irq_status,
  212. .pmt = sxgbe_core_pmt,
  213. .set_umac_addr = sxgbe_core_set_umac_addr,
  214. .get_umac_addr = sxgbe_core_get_umac_addr,
  215. .enable_rx = sxgbe_enable_rx,
  216. .enable_tx = sxgbe_enable_tx,
  217. .get_controller_version = sxgbe_get_controller_version,
  218. .get_hw_feature = sxgbe_get_hw_feature,
  219. .set_speed = sxgbe_core_set_speed,
  220. .set_eee_mode = sxgbe_set_eee_mode,
  221. .reset_eee_mode = sxgbe_reset_eee_mode,
  222. .set_eee_timer = sxgbe_set_eee_timer,
  223. .set_eee_pls = sxgbe_set_eee_pls,
  224. .enable_rx_csum = sxgbe_enable_rx_csum,
  225. .disable_rx_csum = sxgbe_disable_rx_csum,
  226. .enable_rxqueue = sxgbe_core_enable_rxqueue,
  227. .disable_rxqueue = sxgbe_core_disable_rxqueue,
  228. };
  229. const struct sxgbe_core_ops *sxgbe_get_core_ops(void)
  230. {
  231. return &core_ops;
  232. }