emac.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2004-2013 Synopsys, Inc. (www.synopsys.com)
  4. *
  5. * Registers and bits definitions of ARC EMAC
  6. */
  7. #ifndef ARC_EMAC_H
  8. #define ARC_EMAC_H
  9. #include <linux/device.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/phy.h>
  13. #include <linux/clk.h>
  14. /* STATUS and ENABLE Register bit masks */
  15. #define TXINT_MASK (1 << 0) /* Transmit interrupt */
  16. #define RXINT_MASK (1 << 1) /* Receive interrupt */
  17. #define ERR_MASK (1 << 2) /* Error interrupt */
  18. #define TXCH_MASK (1 << 3) /* Transmit chaining error interrupt */
  19. #define MSER_MASK (1 << 4) /* Missed packet counter error */
  20. #define RXCR_MASK (1 << 8) /* RXCRCERR counter rolled over */
  21. #define RXFR_MASK (1 << 9) /* RXFRAMEERR counter rolled over */
  22. #define RXFL_MASK (1 << 10) /* RXOFLOWERR counter rolled over */
  23. #define MDIO_MASK (1 << 12) /* MDIO complete interrupt */
  24. #define TXPL_MASK (1 << 31) /* Force polling of BD by EMAC */
  25. /* CONTROL Register bit masks */
  26. #define EN_MASK (1 << 0) /* VMAC enable */
  27. #define TXRN_MASK (1 << 3) /* TX enable */
  28. #define RXRN_MASK (1 << 4) /* RX enable */
  29. #define DSBC_MASK (1 << 8) /* Disable receive broadcast */
  30. #define ENFL_MASK (1 << 10) /* Enable Full-duplex */
  31. #define PROM_MASK (1 << 11) /* Promiscuous mode */
  32. /* Buffer descriptor INFO bit masks */
  33. #define OWN_MASK (1 << 31) /* 0-CPU or 1-EMAC owns buffer */
  34. #define FIRST_MASK (1 << 16) /* First buffer in chain */
  35. #define LAST_MASK (1 << 17) /* Last buffer in chain */
  36. #define LEN_MASK 0x000007FF /* last 11 bits */
  37. #define CRLS (1 << 21)
  38. #define DEFR (1 << 22)
  39. #define DROP (1 << 23)
  40. #define RTRY (1 << 24)
  41. #define LTCL (1 << 28)
  42. #define UFLO (1 << 29)
  43. #define FOR_EMAC OWN_MASK
  44. #define FOR_CPU 0
  45. /* ARC EMAC register set combines entries for MAC and MDIO */
  46. enum {
  47. R_ID = 0,
  48. R_STATUS,
  49. R_ENABLE,
  50. R_CTRL,
  51. R_POLLRATE,
  52. R_RXERR,
  53. R_MISS,
  54. R_TX_RING,
  55. R_RX_RING,
  56. R_ADDRL,
  57. R_ADDRH,
  58. R_LAFL,
  59. R_LAFH,
  60. R_MDIO,
  61. };
  62. #define TX_TIMEOUT (400 * HZ / 1000) /* Transmission timeout */
  63. #define ARC_EMAC_NAPI_WEIGHT 40 /* Workload for NAPI */
  64. #define EMAC_BUFFER_SIZE 1536 /* EMAC buffer size */
  65. /**
  66. * struct arc_emac_bd - EMAC buffer descriptor (BD).
  67. *
  68. * @info: Contains status information on the buffer itself.
  69. * @data: 32-bit byte addressable pointer to the packet data.
  70. */
  71. struct arc_emac_bd {
  72. __le32 info;
  73. dma_addr_t data;
  74. };
  75. /* Number of Rx/Tx BD's */
  76. #define RX_BD_NUM 128
  77. #define TX_BD_NUM 128
  78. #define RX_RING_SZ (RX_BD_NUM * sizeof(struct arc_emac_bd))
  79. #define TX_RING_SZ (TX_BD_NUM * sizeof(struct arc_emac_bd))
  80. /**
  81. * struct buffer_state - Stores Rx/Tx buffer state.
  82. * @sk_buff: Pointer to socket buffer.
  83. * @addr: Start address of DMA-mapped memory region.
  84. * @len: Length of DMA-mapped memory region.
  85. */
  86. struct buffer_state {
  87. struct sk_buff *skb;
  88. DEFINE_DMA_UNMAP_ADDR(addr);
  89. DEFINE_DMA_UNMAP_LEN(len);
  90. };
  91. struct arc_emac_mdio_bus_data {
  92. struct gpio_desc *reset_gpio;
  93. int msec;
  94. };
  95. /**
  96. * struct arc_emac_priv - Storage of EMAC's private information.
  97. * @dev: Pointer to the current device.
  98. * @phy_dev: Pointer to attached PHY device.
  99. * @bus: Pointer to the current MII bus.
  100. * @regs: Base address of EMAC memory-mapped control registers.
  101. * @napi: Structure for NAPI.
  102. * @rxbd: Pointer to Rx BD ring.
  103. * @txbd: Pointer to Tx BD ring.
  104. * @rxbd_dma: DMA handle for Rx BD ring.
  105. * @txbd_dma: DMA handle for Tx BD ring.
  106. * @rx_buff: Storage for Rx buffers states.
  107. * @tx_buff: Storage for Tx buffers states.
  108. * @txbd_curr: Index of Tx BD to use on the next "ndo_start_xmit".
  109. * @txbd_dirty: Index of Tx BD to free on the next Tx interrupt.
  110. * @last_rx_bd: Index of the last Rx BD we've got from EMAC.
  111. * @link: PHY's last seen link state.
  112. * @duplex: PHY's last set duplex mode.
  113. * @speed: PHY's last set speed.
  114. */
  115. struct arc_emac_priv {
  116. const char *drv_name;
  117. const char *drv_version;
  118. void (*set_mac_speed)(void *priv, unsigned int speed);
  119. /* Devices */
  120. struct device *dev;
  121. struct mii_bus *bus;
  122. struct arc_emac_mdio_bus_data bus_data;
  123. void __iomem *regs;
  124. struct clk *clk;
  125. struct napi_struct napi;
  126. struct arc_emac_bd *rxbd;
  127. struct arc_emac_bd *txbd;
  128. dma_addr_t rxbd_dma;
  129. dma_addr_t txbd_dma;
  130. struct buffer_state rx_buff[RX_BD_NUM];
  131. struct buffer_state tx_buff[TX_BD_NUM];
  132. unsigned int txbd_curr;
  133. unsigned int txbd_dirty;
  134. unsigned int last_rx_bd;
  135. unsigned int link;
  136. unsigned int duplex;
  137. unsigned int speed;
  138. unsigned int rx_missed_errors;
  139. };
  140. /**
  141. * arc_reg_set - Sets EMAC register with provided value.
  142. * @priv: Pointer to ARC EMAC private data structure.
  143. * @reg: Register offset from base address.
  144. * @value: Value to set in register.
  145. */
  146. static inline void arc_reg_set(struct arc_emac_priv *priv, int reg, int value)
  147. {
  148. iowrite32(value, priv->regs + reg * sizeof(int));
  149. }
  150. /**
  151. * arc_reg_get - Gets value of specified EMAC register.
  152. * @priv: Pointer to ARC EMAC private data structure.
  153. * @reg: Register offset from base address.
  154. *
  155. * returns: Value of requested register.
  156. */
  157. static inline unsigned int arc_reg_get(struct arc_emac_priv *priv, int reg)
  158. {
  159. return ioread32(priv->regs + reg * sizeof(int));
  160. }
  161. /**
  162. * arc_reg_or - Applies mask to specified EMAC register - ("reg" | "mask").
  163. * @priv: Pointer to ARC EMAC private data structure.
  164. * @reg: Register offset from base address.
  165. * @mask: Mask to apply to specified register.
  166. *
  167. * This function reads initial register value, then applies provided mask
  168. * to it and then writes register back.
  169. */
  170. static inline void arc_reg_or(struct arc_emac_priv *priv, int reg, int mask)
  171. {
  172. unsigned int value = arc_reg_get(priv, reg);
  173. arc_reg_set(priv, reg, value | mask);
  174. }
  175. /**
  176. * arc_reg_clr - Applies mask to specified EMAC register - ("reg" & ~"mask").
  177. * @priv: Pointer to ARC EMAC private data structure.
  178. * @reg: Register offset from base address.
  179. * @mask: Mask to apply to specified register.
  180. *
  181. * This function reads initial register value, then applies provided mask
  182. * to it and then writes register back.
  183. */
  184. static inline void arc_reg_clr(struct arc_emac_priv *priv, int reg, int mask)
  185. {
  186. unsigned int value = arc_reg_get(priv, reg);
  187. arc_reg_set(priv, reg, value & ~mask);
  188. }
  189. int arc_mdio_probe(struct arc_emac_priv *priv);
  190. int arc_mdio_remove(struct arc_emac_priv *priv);
  191. int arc_emac_probe(struct net_device *ndev, int interface);
  192. int arc_emac_remove(struct net_device *ndev);
  193. #endif /* ARC_EMAC_H */