core.h 8.0 KB

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