core.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * drivers/net/ibm_newemac/core.h
  3. *
  4. * Driver for PowerPC 4xx on-chip ethernet controller.
  5. *
  6. * Copyright 2007 Benjamin Herrenschmidt, IBM Corp.
  7. * <benh@kernel.crashing.org>
  8. *
  9. * Based on the arch/ppc version of the driver:
  10. *
  11. * Copyright (c) 2004, 2005 Zultys Technologies.
  12. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  13. *
  14. * Based on original work by
  15. * Armin Kuster <akuster@mvista.com>
  16. * Johnnie Peters <jpeters@mvista.com>
  17. * Copyright 2000, 2001 MontaVista Softare Inc.
  18. *
  19. * This program is free software; you can redistribute it and/or modify it
  20. * under the terms of the GNU General Public License as published by the
  21. * Free Software Foundation; either version 2 of the License, or (at your
  22. * option) any later version.
  23. *
  24. */
  25. #ifndef __IBM_NEWEMAC_CORE_H
  26. #define __IBM_NEWEMAC_CORE_H
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/list.h>
  30. #include <linux/kernel.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/spinlock.h>
  35. #include <asm/of_platform.h>
  36. #include <asm/io.h>
  37. #include <asm/dcr.h>
  38. #include "emac.h"
  39. #include "phy.h"
  40. #include "zmii.h"
  41. #include "rgmii.h"
  42. #include "mal.h"
  43. #include "tah.h"
  44. #include "debug.h"
  45. #define NUM_TX_BUFF CONFIG_IBM_NEW_EMAC_TXB
  46. #define NUM_RX_BUFF CONFIG_IBM_NEW_EMAC_RXB
  47. /* Simple sanity check */
  48. #if NUM_TX_BUFF > 256 || NUM_RX_BUFF > 256
  49. #error Invalid number of buffer descriptors (greater than 256)
  50. #endif
  51. #define EMAC_MIN_MTU 46
  52. /* Maximum L2 header length (VLAN tagged, no FCS) */
  53. #define EMAC_MTU_OVERHEAD (6 * 2 + 2 + 4)
  54. /* RX BD size for the given MTU */
  55. static inline int emac_rx_size(int mtu)
  56. {
  57. if (mtu > ETH_DATA_LEN)
  58. return MAL_MAX_RX_SIZE;
  59. else
  60. return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD);
  61. }
  62. #define EMAC_DMA_ALIGN(x) ALIGN((x), dma_get_cache_alignment())
  63. #define EMAC_RX_SKB_HEADROOM \
  64. EMAC_DMA_ALIGN(CONFIG_IBM_NEW_EMAC_RX_SKB_HEADROOM)
  65. /* Size of RX skb for the given MTU */
  66. static inline int emac_rx_skb_size(int mtu)
  67. {
  68. int size = max(mtu + EMAC_MTU_OVERHEAD, emac_rx_size(mtu));
  69. return EMAC_DMA_ALIGN(size + 2) + EMAC_RX_SKB_HEADROOM;
  70. }
  71. /* RX DMA sync size */
  72. static inline int emac_rx_sync_size(int mtu)
  73. {
  74. return EMAC_DMA_ALIGN(emac_rx_size(mtu) + 2);
  75. }
  76. /* Driver statistcs is split into two parts to make it more cache friendly:
  77. * - normal statistics (packet count, etc)
  78. * - error statistics
  79. *
  80. * When statistics is requested by ethtool, these parts are concatenated,
  81. * normal one goes first.
  82. *
  83. * Please, keep these structures in sync with emac_stats_keys.
  84. */
  85. /* Normal TX/RX Statistics */
  86. struct emac_stats {
  87. u64 rx_packets;
  88. u64 rx_bytes;
  89. u64 tx_packets;
  90. u64 tx_bytes;
  91. u64 rx_packets_csum;
  92. u64 tx_packets_csum;
  93. };
  94. /* Error statistics */
  95. struct emac_error_stats {
  96. u64 tx_undo;
  97. /* Software RX Errors */
  98. u64 rx_dropped_stack;
  99. u64 rx_dropped_oom;
  100. u64 rx_dropped_error;
  101. u64 rx_dropped_resize;
  102. u64 rx_dropped_mtu;
  103. u64 rx_stopped;
  104. /* BD reported RX errors */
  105. u64 rx_bd_errors;
  106. u64 rx_bd_overrun;
  107. u64 rx_bd_bad_packet;
  108. u64 rx_bd_runt_packet;
  109. u64 rx_bd_short_event;
  110. u64 rx_bd_alignment_error;
  111. u64 rx_bd_bad_fcs;
  112. u64 rx_bd_packet_too_long;
  113. u64 rx_bd_out_of_range;
  114. u64 rx_bd_in_range;
  115. /* EMAC IRQ reported RX errors */
  116. u64 rx_parity;
  117. u64 rx_fifo_overrun;
  118. u64 rx_overrun;
  119. u64 rx_bad_packet;
  120. u64 rx_runt_packet;
  121. u64 rx_short_event;
  122. u64 rx_alignment_error;
  123. u64 rx_bad_fcs;
  124. u64 rx_packet_too_long;
  125. u64 rx_out_of_range;
  126. u64 rx_in_range;
  127. /* Software TX Errors */
  128. u64 tx_dropped;
  129. /* BD reported TX errors */
  130. u64 tx_bd_errors;
  131. u64 tx_bd_bad_fcs;
  132. u64 tx_bd_carrier_loss;
  133. u64 tx_bd_excessive_deferral;
  134. u64 tx_bd_excessive_collisions;
  135. u64 tx_bd_late_collision;
  136. u64 tx_bd_multple_collisions;
  137. u64 tx_bd_single_collision;
  138. u64 tx_bd_underrun;
  139. u64 tx_bd_sqe;
  140. /* EMAC IRQ reported TX errors */
  141. u64 tx_parity;
  142. u64 tx_underrun;
  143. u64 tx_sqe;
  144. u64 tx_errors;
  145. };
  146. #define EMAC_ETHTOOL_STATS_COUNT ((sizeof(struct emac_stats) + \
  147. sizeof(struct emac_error_stats)) \
  148. / sizeof(u64))
  149. struct emac_instance {
  150. struct net_device *ndev;
  151. struct resource rsrc_regs;
  152. struct emac_regs __iomem *emacp;
  153. struct of_device *ofdev;
  154. struct device_node **blist; /* bootlist entry */
  155. /* MAL linkage */
  156. u32 mal_ph;
  157. struct of_device *mal_dev;
  158. u32 mal_rx_chan;
  159. u32 mal_tx_chan;
  160. struct mal_instance *mal;
  161. struct mal_commac commac;
  162. /* PHY infos */
  163. u32 phy_mode;
  164. u32 phy_map;
  165. u32 phy_address;
  166. u32 phy_feat_exc;
  167. struct mii_phy phy;
  168. struct mutex link_lock;
  169. struct delayed_work link_work;
  170. int link_polling;
  171. /* Shared MDIO if any */
  172. u32 mdio_ph;
  173. struct of_device *mdio_dev;
  174. struct emac_instance *mdio_instance;
  175. struct mutex mdio_lock;
  176. /* ZMII infos if any */
  177. u32 zmii_ph;
  178. u32 zmii_port;
  179. struct of_device *zmii_dev;
  180. /* RGMII infos if any */
  181. u32 rgmii_ph;
  182. u32 rgmii_port;
  183. struct of_device *rgmii_dev;
  184. /* TAH infos if any */
  185. u32 tah_ph;
  186. u32 tah_port;
  187. struct of_device *tah_dev;
  188. /* IRQs */
  189. int wol_irq;
  190. int emac_irq;
  191. /* OPB bus frequency in Mhz */
  192. u32 opb_bus_freq;
  193. /* Cell index within an ASIC (for clk mgmnt) */
  194. u32 cell_index;
  195. /* Max supported MTU */
  196. u32 max_mtu;
  197. /* Feature bits (from probe table) */
  198. unsigned int features;
  199. /* Tx and Rx fifo sizes & other infos in bytes */
  200. u32 tx_fifo_size;
  201. u32 tx_fifo_size_gige;
  202. u32 rx_fifo_size;
  203. u32 rx_fifo_size_gige;
  204. u32 fifo_entry_size;
  205. u32 mal_burst_size; /* move to MAL ? */
  206. /* Descriptor management
  207. */
  208. struct mal_descriptor *tx_desc;
  209. int tx_cnt;
  210. int tx_slot;
  211. int ack_slot;
  212. struct mal_descriptor *rx_desc;
  213. int rx_slot;
  214. struct sk_buff *rx_sg_skb; /* 1 */
  215. int rx_skb_size;
  216. int rx_sync_size;
  217. struct sk_buff *tx_skb[NUM_TX_BUFF];
  218. struct sk_buff *rx_skb[NUM_RX_BUFF];
  219. /* Stats
  220. */
  221. struct emac_error_stats estats;
  222. struct net_device_stats nstats;
  223. struct emac_stats stats;
  224. /* Misc
  225. */
  226. int reset_failed;
  227. int stop_timeout; /* in us */
  228. int no_mcast;
  229. int mcast_pending;
  230. int opened;
  231. struct work_struct reset_work;
  232. spinlock_t lock;
  233. };
  234. /*
  235. * Features of various EMAC implementations
  236. */
  237. /*
  238. * No flow control on 40x according to the original driver
  239. */
  240. #define EMAC_FTR_NO_FLOW_CONTROL_40x 0x00000001
  241. /*
  242. * Cell is an EMAC4
  243. */
  244. #define EMAC_FTR_EMAC4 0x00000002
  245. /*
  246. * For the 440SPe, AMCC inexplicably changed the polarity of
  247. * the "operation complete" bit in the MII control register.
  248. */
  249. #define EMAC_FTR_STACR_OC_INVERT 0x00000004
  250. /*
  251. * Set if we have a TAH.
  252. */
  253. #define EMAC_FTR_HAS_TAH 0x00000008
  254. /*
  255. * Set if we have a ZMII.
  256. */
  257. #define EMAC_FTR_HAS_ZMII 0x00000010
  258. /*
  259. * Set if we have a RGMII.
  260. */
  261. #define EMAC_FTR_HAS_RGMII 0x00000020
  262. /*
  263. * Set if we have new type STACR with STAOPC
  264. */
  265. #define EMAC_FTR_HAS_NEW_STACR 0x00000040
  266. /*
  267. * Set if we need phy clock workaround for 440gx
  268. */
  269. #define EMAC_FTR_440GX_PHY_CLK_FIX 0x00000080
  270. /*
  271. * Set if we need phy clock workaround for 440ep or 440gr
  272. */
  273. #define EMAC_FTR_440EP_PHY_CLK_FIX 0x00000100
  274. /* Right now, we don't quite handle the always/possible masks on the
  275. * most optimal way as we don't have a way to say something like
  276. * always EMAC4. Patches welcome.
  277. */
  278. enum {
  279. EMAC_FTRS_ALWAYS = 0,
  280. EMAC_FTRS_POSSIBLE =
  281. #ifdef CONFIG_IBM_NEW_EMAC_EMAC4
  282. EMAC_FTR_EMAC4 | EMAC_FTR_HAS_NEW_STACR |
  283. EMAC_FTR_STACR_OC_INVERT | EMAC_FTR_440GX_PHY_CLK_FIX |
  284. #endif
  285. #ifdef CONFIG_IBM_NEW_EMAC_TAH
  286. EMAC_FTR_HAS_TAH |
  287. #endif
  288. #ifdef CONFIG_IBM_NEW_EMAC_ZMII
  289. EMAC_FTR_HAS_ZMII |
  290. #endif
  291. #ifdef CONFIG_IBM_NEW_EMAC_RGMII
  292. EMAC_FTR_HAS_RGMII |
  293. #endif
  294. EMAC_FTR_440EP_PHY_CLK_FIX,
  295. };
  296. static inline int emac_has_feature(struct emac_instance *dev,
  297. unsigned long feature)
  298. {
  299. return (EMAC_FTRS_ALWAYS & feature) ||
  300. (EMAC_FTRS_POSSIBLE & dev->features & feature);
  301. }
  302. /* Ethtool get_regs complex data.
  303. * We want to get not just EMAC registers, but also MAL, ZMII, RGMII, TAH
  304. * when available.
  305. *
  306. * Returned BLOB consists of the ibm_emac_ethtool_regs_hdr,
  307. * MAL registers, EMAC registers and optional ZMII, RGMII, TAH registers.
  308. * Each register component is preceded with emac_ethtool_regs_subhdr.
  309. * Order of the optional headers follows their relative bit posititions
  310. * in emac_ethtool_regs_hdr.components
  311. */
  312. #define EMAC_ETHTOOL_REGS_ZMII 0x00000001
  313. #define EMAC_ETHTOOL_REGS_RGMII 0x00000002
  314. #define EMAC_ETHTOOL_REGS_TAH 0x00000004
  315. struct emac_ethtool_regs_hdr {
  316. u32 components;
  317. };
  318. struct emac_ethtool_regs_subhdr {
  319. u32 version;
  320. u32 index;
  321. };
  322. #endif /* __IBM_NEWEMAC_CORE_H */