Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 2 | * drivers/net/ibm_emac/ibm_emac_core.h |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 4 | * Driver for PowerPC 4xx on-chip ethernet controller. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 6 | * Copyright (c) 2004, 2005 Zultys Technologies. |
| 7 | * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 20 | #ifndef __IBM_EMAC_CORE_H_ |
| 21 | #define __IBM_EMAC_CORE_H_ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 23 | #include <linux/config.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/netdevice.h> |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/ocp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | #include "ibm_emac.h" |
| 29 | #include "ibm_emac_phy.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "ibm_emac_zmii.h" |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 31 | #include "ibm_emac_rgmii.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include "ibm_emac_mal.h" |
| 33 | #include "ibm_emac_tah.h" |
| 34 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 35 | #define NUM_TX_BUFF CONFIG_IBM_EMAC_TXB |
| 36 | #define NUM_RX_BUFF CONFIG_IBM_EMAC_RXB |
| 37 | |
| 38 | /* Simple sanity check */ |
| 39 | #if NUM_TX_BUFF > 256 || NUM_RX_BUFF > 256 |
| 40 | #error Invalid number of buffer descriptors (greater than 256) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #endif |
| 42 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 43 | // XXX |
| 44 | #define EMAC_MIN_MTU 46 |
| 45 | #define EMAC_MAX_MTU 9000 |
| 46 | |
| 47 | /* Maximum L2 header length (VLAN tagged, no FCS) */ |
| 48 | #define EMAC_MTU_OVERHEAD (6 * 2 + 2 + 4) |
| 49 | |
| 50 | /* RX BD size for the given MTU */ |
| 51 | static inline int emac_rx_size(int mtu) |
| 52 | { |
| 53 | if (mtu > ETH_DATA_LEN) |
| 54 | return MAL_MAX_RX_SIZE; |
| 55 | else |
| 56 | return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD); |
| 57 | } |
| 58 | |
| 59 | #define EMAC_DMA_ALIGN(x) ALIGN((x), dma_get_cache_alignment()) |
| 60 | |
| 61 | #define EMAC_RX_SKB_HEADROOM \ |
| 62 | EMAC_DMA_ALIGN(CONFIG_IBM_EMAC_RX_SKB_HEADROOM) |
| 63 | |
| 64 | /* Size of RX skb for the given MTU */ |
| 65 | static inline int emac_rx_skb_size(int mtu) |
| 66 | { |
| 67 | int size = max(mtu + EMAC_MTU_OVERHEAD, emac_rx_size(mtu)); |
| 68 | return EMAC_DMA_ALIGN(size + 2) + EMAC_RX_SKB_HEADROOM; |
| 69 | } |
| 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 | |
| 77 | /* Driver statistcs is split into two parts to make it more cache friendly: |
| 78 | * - normal statistics (packet count, etc) |
| 79 | * - error statistics |
| 80 | * |
| 81 | * When statistics is requested by ethtool, these parts are concatenated, |
| 82 | * normal one goes first. |
| 83 | * |
| 84 | * Please, keep these structures in sync with emac_stats_keys. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 87 | /* Normal TX/RX Statistics */ |
| 88 | struct ibm_emac_stats { |
| 89 | u64 rx_packets; |
| 90 | u64 rx_bytes; |
| 91 | u64 tx_packets; |
| 92 | u64 tx_bytes; |
| 93 | u64 rx_packets_csum; |
| 94 | u64 tx_packets_csum; |
| 95 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 97 | /* Error statistics */ |
| 98 | struct ibm_emac_error_stats { |
| 99 | u64 tx_undo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 101 | /* Software RX Errors */ |
| 102 | u64 rx_dropped_stack; |
| 103 | u64 rx_dropped_oom; |
| 104 | u64 rx_dropped_error; |
| 105 | u64 rx_dropped_resize; |
| 106 | u64 rx_dropped_mtu; |
| 107 | u64 rx_stopped; |
| 108 | /* BD reported RX errors */ |
| 109 | u64 rx_bd_errors; |
| 110 | u64 rx_bd_overrun; |
| 111 | u64 rx_bd_bad_packet; |
| 112 | u64 rx_bd_runt_packet; |
| 113 | u64 rx_bd_short_event; |
| 114 | u64 rx_bd_alignment_error; |
| 115 | u64 rx_bd_bad_fcs; |
| 116 | u64 rx_bd_packet_too_long; |
| 117 | u64 rx_bd_out_of_range; |
| 118 | u64 rx_bd_in_range; |
| 119 | /* EMAC IRQ reported RX errors */ |
| 120 | u64 rx_parity; |
| 121 | u64 rx_fifo_overrun; |
| 122 | u64 rx_overrun; |
| 123 | u64 rx_bad_packet; |
| 124 | u64 rx_runt_packet; |
| 125 | u64 rx_short_event; |
| 126 | u64 rx_alignment_error; |
| 127 | u64 rx_bad_fcs; |
| 128 | u64 rx_packet_too_long; |
| 129 | u64 rx_out_of_range; |
| 130 | u64 rx_in_range; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 132 | /* Software TX Errors */ |
| 133 | u64 tx_dropped; |
| 134 | /* BD reported TX errors */ |
| 135 | u64 tx_bd_errors; |
| 136 | u64 tx_bd_bad_fcs; |
| 137 | u64 tx_bd_carrier_loss; |
| 138 | u64 tx_bd_excessive_deferral; |
| 139 | u64 tx_bd_excessive_collisions; |
| 140 | u64 tx_bd_late_collision; |
| 141 | u64 tx_bd_multple_collisions; |
| 142 | u64 tx_bd_single_collision; |
| 143 | u64 tx_bd_underrun; |
| 144 | u64 tx_bd_sqe; |
| 145 | /* EMAC IRQ reported TX errors */ |
| 146 | u64 tx_parity; |
| 147 | u64 tx_underrun; |
| 148 | u64 tx_sqe; |
| 149 | u64 tx_errors; |
| 150 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 152 | #define EMAC_ETHTOOL_STATS_COUNT ((sizeof(struct ibm_emac_stats) + \ |
| 153 | sizeof(struct ibm_emac_error_stats)) \ |
| 154 | / sizeof(u64)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | struct ocp_enet_private { |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 157 | struct net_device *ndev; /* 0 */ |
| 158 | struct emac_regs *emacp; |
| 159 | |
| 160 | struct mal_descriptor *tx_desc; |
| 161 | int tx_cnt; |
| 162 | int tx_slot; |
| 163 | int ack_slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 165 | struct mal_descriptor *rx_desc; |
| 166 | int rx_slot; |
| 167 | struct sk_buff *rx_sg_skb; /* 1 */ |
| 168 | int rx_skb_size; |
| 169 | int rx_sync_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 171 | struct ibm_emac_stats stats; |
| 172 | struct ocp_device *tah_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 174 | struct ibm_ocp_mal *mal; |
| 175 | struct mal_commac commac; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 177 | struct sk_buff *tx_skb[NUM_TX_BUFF]; |
| 178 | struct sk_buff *rx_skb[NUM_RX_BUFF]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 180 | struct ocp_device *zmii_dev; |
| 181 | int zmii_input; |
| 182 | struct ocp_enet_private *mdio_dev; |
| 183 | struct ocp_device *rgmii_dev; |
| 184 | int rgmii_input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 186 | struct ocp_def *def; |
| 187 | |
| 188 | struct mii_phy phy; |
| 189 | struct timer_list link_timer; |
| 190 | int reset_failed; |
| 191 | |
| 192 | struct ibm_emac_error_stats estats; |
| 193 | struct net_device_stats nstats; |
| 194 | |
| 195 | struct device* ldev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | }; |
Eugene Surovegin | 37448f7 | 2005-10-10 16:58:14 -0700 | [diff] [blame] | 197 | |
| 198 | /* Ethtool get_regs complex data. |
| 199 | * We want to get not just EMAC registers, but also MAL, ZMII, RGMII, TAH |
| 200 | * when available. |
| 201 | * |
| 202 | * Returned BLOB consists of the ibm_emac_ethtool_regs_hdr, |
| 203 | * MAL registers, EMAC registers and optional ZMII, RGMII, TAH registers. |
| 204 | * Each register component is preceded with emac_ethtool_regs_subhdr. |
| 205 | * Order of the optional headers follows their relative bit posititions |
| 206 | * in emac_ethtool_regs_hdr.components |
| 207 | */ |
| 208 | #define EMAC_ETHTOOL_REGS_ZMII 0x00000001 |
| 209 | #define EMAC_ETHTOOL_REGS_RGMII 0x00000002 |
| 210 | #define EMAC_ETHTOOL_REGS_TAH 0x00000004 |
| 211 | |
| 212 | struct emac_ethtool_regs_hdr { |
| 213 | u32 components; |
| 214 | }; |
| 215 | |
| 216 | struct emac_ethtool_regs_subhdr { |
| 217 | u32 version; |
| 218 | u32 index; |
| 219 | }; |
| 220 | |
| 221 | #endif /* __IBM_EMAC_CORE_H_ */ |