0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #ifndef __IBM_NEWEMAC_CORE_H
0021 #define __IBM_NEWEMAC_CORE_H
0022
0023 #include <linux/module.h>
0024 #include <linux/list.h>
0025 #include <linux/kernel.h>
0026 #include <linux/interrupt.h>
0027 #include <linux/netdevice.h>
0028 #include <linux/dma-mapping.h>
0029 #include <linux/spinlock.h>
0030 #include <linux/of_platform.h>
0031 #include <linux/slab.h>
0032
0033 #include <asm/io.h>
0034 #include <asm/dcr.h>
0035
0036 #include "emac.h"
0037 #include "phy.h"
0038 #include "zmii.h"
0039 #include "rgmii.h"
0040 #include "mal.h"
0041 #include "tah.h"
0042 #include "debug.h"
0043
0044 #define NUM_TX_BUFF CONFIG_IBM_EMAC_TXB
0045 #define NUM_RX_BUFF CONFIG_IBM_EMAC_RXB
0046
0047
0048 #if NUM_TX_BUFF > 256 || NUM_RX_BUFF > 256
0049 #error Invalid number of buffer descriptors (greater than 256)
0050 #endif
0051
0052 #define EMAC_MIN_MTU 46
0053
0054
0055 #define EMAC_MTU_OVERHEAD (6 * 2 + 2 + 4)
0056
0057
0058 static inline int emac_rx_size(int mtu)
0059 {
0060 if (mtu > ETH_DATA_LEN)
0061 return MAL_MAX_RX_SIZE;
0062 else
0063 return mal_rx_size(ETH_DATA_LEN + EMAC_MTU_OVERHEAD);
0064 }
0065
0066
0067 static inline int emac_rx_skb_size(int mtu)
0068 {
0069 int size = max(mtu + EMAC_MTU_OVERHEAD, emac_rx_size(mtu));
0070
0071 return SKB_DATA_ALIGN(size + NET_IP_ALIGN) + NET_SKB_PAD;
0072 }
0073
0074
0075 static inline int emac_rx_sync_size(int mtu)
0076 {
0077 return SKB_DATA_ALIGN(emac_rx_size(mtu) + NET_IP_ALIGN);
0078 }
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 struct emac_stats {
0092 u64 rx_packets;
0093 u64 rx_bytes;
0094 u64 tx_packets;
0095 u64 tx_bytes;
0096 u64 rx_packets_csum;
0097 u64 tx_packets_csum;
0098 };
0099
0100
0101 struct emac_error_stats {
0102 u64 tx_undo;
0103
0104
0105 u64 rx_dropped_stack;
0106 u64 rx_dropped_oom;
0107 u64 rx_dropped_error;
0108 u64 rx_dropped_resize;
0109 u64 rx_dropped_mtu;
0110 u64 rx_stopped;
0111
0112 u64 rx_bd_errors;
0113 u64 rx_bd_overrun;
0114 u64 rx_bd_bad_packet;
0115 u64 rx_bd_runt_packet;
0116 u64 rx_bd_short_event;
0117 u64 rx_bd_alignment_error;
0118 u64 rx_bd_bad_fcs;
0119 u64 rx_bd_packet_too_long;
0120 u64 rx_bd_out_of_range;
0121 u64 rx_bd_in_range;
0122
0123 u64 rx_parity;
0124 u64 rx_fifo_overrun;
0125 u64 rx_overrun;
0126 u64 rx_bad_packet;
0127 u64 rx_runt_packet;
0128 u64 rx_short_event;
0129 u64 rx_alignment_error;
0130 u64 rx_bad_fcs;
0131 u64 rx_packet_too_long;
0132 u64 rx_out_of_range;
0133 u64 rx_in_range;
0134
0135
0136 u64 tx_dropped;
0137
0138 u64 tx_bd_errors;
0139 u64 tx_bd_bad_fcs;
0140 u64 tx_bd_carrier_loss;
0141 u64 tx_bd_excessive_deferral;
0142 u64 tx_bd_excessive_collisions;
0143 u64 tx_bd_late_collision;
0144 u64 tx_bd_multple_collisions;
0145 u64 tx_bd_single_collision;
0146 u64 tx_bd_underrun;
0147 u64 tx_bd_sqe;
0148
0149 u64 tx_parity;
0150 u64 tx_underrun;
0151 u64 tx_sqe;
0152 u64 tx_errors;
0153 };
0154
0155 #define EMAC_ETHTOOL_STATS_COUNT ((sizeof(struct emac_stats) + \
0156 sizeof(struct emac_error_stats)) \
0157 / sizeof(u64))
0158
0159 struct emac_instance {
0160 struct net_device *ndev;
0161 struct emac_regs __iomem *emacp;
0162 struct platform_device *ofdev;
0163 struct device_node **blist;
0164
0165
0166 u32 mal_ph;
0167 struct platform_device *mal_dev;
0168 u32 mal_rx_chan;
0169 u32 mal_tx_chan;
0170 struct mal_instance *mal;
0171 struct mal_commac commac;
0172
0173
0174 phy_interface_t phy_mode;
0175 u32 phy_map;
0176 u32 phy_address;
0177 u32 phy_feat_exc;
0178 struct mii_phy phy;
0179 struct mutex link_lock;
0180 struct delayed_work link_work;
0181 int link_polling;
0182
0183
0184 u32 gpcs_address;
0185
0186
0187 u32 mdio_ph;
0188 struct platform_device *mdio_dev;
0189 struct emac_instance *mdio_instance;
0190 struct mutex mdio_lock;
0191
0192
0193 struct mii_bus *mii_bus;
0194 struct phy_device *phy_dev;
0195
0196
0197 u32 zmii_ph;
0198 u32 zmii_port;
0199 struct platform_device *zmii_dev;
0200
0201
0202 u32 rgmii_ph;
0203 u32 rgmii_port;
0204 struct platform_device *rgmii_dev;
0205
0206
0207 u32 tah_ph;
0208 u32 tah_port;
0209 struct platform_device *tah_dev;
0210
0211
0212 int wol_irq;
0213 int emac_irq;
0214
0215
0216 u32 opb_bus_freq;
0217
0218
0219 u32 cell_index;
0220
0221
0222 u32 max_mtu;
0223
0224
0225 unsigned int features;
0226
0227
0228 u32 tx_fifo_size;
0229 u32 tx_fifo_size_gige;
0230 u32 rx_fifo_size;
0231 u32 rx_fifo_size_gige;
0232 u32 fifo_entry_size;
0233 u32 mal_burst_size;
0234
0235
0236 u32 xaht_slots_shift;
0237 u32 xaht_width_shift;
0238
0239
0240
0241 struct mal_descriptor *tx_desc;
0242 int tx_cnt;
0243 int tx_slot;
0244 int ack_slot;
0245
0246 struct mal_descriptor *rx_desc;
0247 int rx_slot;
0248 struct sk_buff *rx_sg_skb;
0249 int rx_skb_size;
0250 int rx_sync_size;
0251
0252 struct sk_buff *tx_skb[NUM_TX_BUFF];
0253 struct sk_buff *rx_skb[NUM_RX_BUFF];
0254
0255
0256
0257 struct emac_error_stats estats;
0258 struct emac_stats stats;
0259
0260
0261
0262 int reset_failed;
0263 int stop_timeout;
0264 int no_mcast;
0265 int mcast_pending;
0266 int opened;
0267 struct work_struct reset_work;
0268 spinlock_t lock;
0269 };
0270
0271
0272
0273
0274
0275
0276
0277
0278 #define EMAC_FTR_NO_FLOW_CONTROL_40x 0x00000001
0279
0280
0281
0282 #define EMAC_FTR_EMAC4 0x00000002
0283
0284
0285
0286
0287 #define EMAC_FTR_STACR_OC_INVERT 0x00000004
0288
0289
0290
0291 #define EMAC_FTR_HAS_TAH 0x00000008
0292
0293
0294
0295 #define EMAC_FTR_HAS_ZMII 0x00000010
0296
0297
0298
0299 #define EMAC_FTR_HAS_RGMII 0x00000020
0300
0301
0302
0303 #define EMAC_FTR_HAS_NEW_STACR 0x00000040
0304
0305
0306
0307 #define EMAC_FTR_440GX_PHY_CLK_FIX 0x00000080
0308
0309
0310
0311 #define EMAC_FTR_440EP_PHY_CLK_FIX 0x00000100
0312
0313
0314
0315 #define EMAC_FTR_EMAC4SYNC 0x00000200
0316
0317
0318
0319 #define EMAC_FTR_460EX_PHY_CLK_FIX 0x00000400
0320
0321
0322
0323 #define EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE 0x00000800
0324
0325
0326
0327 #define EMAC_FTR_APM821XX_NO_HALF_DUPLEX 0x00001000
0328
0329
0330
0331
0332
0333 enum {
0334 EMAC_FTRS_ALWAYS = 0,
0335
0336 EMAC_FTRS_POSSIBLE =
0337 #ifdef CONFIG_IBM_EMAC_EMAC4
0338 EMAC_FTR_EMAC4 | EMAC_FTR_EMAC4SYNC |
0339 EMAC_FTR_HAS_NEW_STACR |
0340 EMAC_FTR_STACR_OC_INVERT | EMAC_FTR_440GX_PHY_CLK_FIX |
0341 #endif
0342 #ifdef CONFIG_IBM_EMAC_TAH
0343 EMAC_FTR_HAS_TAH |
0344 #endif
0345 #ifdef CONFIG_IBM_EMAC_ZMII
0346 EMAC_FTR_HAS_ZMII |
0347 #endif
0348 #ifdef CONFIG_IBM_EMAC_RGMII
0349 EMAC_FTR_HAS_RGMII |
0350 #endif
0351 #ifdef CONFIG_IBM_EMAC_NO_FLOW_CTRL
0352 EMAC_FTR_NO_FLOW_CONTROL_40x |
0353 #endif
0354 EMAC_FTR_460EX_PHY_CLK_FIX |
0355 EMAC_FTR_440EP_PHY_CLK_FIX |
0356 EMAC_APM821XX_REQ_JUMBO_FRAME_SIZE |
0357 EMAC_FTR_APM821XX_NO_HALF_DUPLEX,
0358 };
0359
0360 static inline int emac_has_feature(struct emac_instance *dev,
0361 unsigned long feature)
0362 {
0363 return (EMAC_FTRS_ALWAYS & feature) ||
0364 (EMAC_FTRS_POSSIBLE & dev->features & feature);
0365 }
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378 #define EMAC4_XAHT_SLOTS_SHIFT 6
0379 #define EMAC4_XAHT_WIDTH_SHIFT 4
0380
0381 #define EMAC4SYNC_XAHT_SLOTS_SHIFT 8
0382 #define EMAC4SYNC_XAHT_WIDTH_SHIFT 5
0383
0384
0385 #define EMAC_XAHT_MAX_REGS (1 << 3)
0386
0387 #define EMAC_XAHT_SLOTS(dev) (1 << (dev)->xaht_slots_shift)
0388 #define EMAC_XAHT_WIDTH(dev) (1 << (dev)->xaht_width_shift)
0389 #define EMAC_XAHT_REGS(dev) (1 << ((dev)->xaht_slots_shift - \
0390 (dev)->xaht_width_shift))
0391
0392 #define EMAC_XAHT_CRC_TO_SLOT(dev, crc) \
0393 ((EMAC_XAHT_SLOTS(dev) - 1) - \
0394 ((crc) >> ((sizeof (u32) * BITS_PER_BYTE) - \
0395 (dev)->xaht_slots_shift)))
0396
0397 #define EMAC_XAHT_SLOT_TO_REG(dev, slot) \
0398 ((slot) >> (dev)->xaht_width_shift)
0399
0400 #define EMAC_XAHT_SLOT_TO_MASK(dev, slot) \
0401 ((u32)(1 << (EMAC_XAHT_WIDTH(dev) - 1)) >> \
0402 ((slot) & (u32)(EMAC_XAHT_WIDTH(dev) - 1)))
0403
0404 static inline u32 *emac_xaht_base(struct emac_instance *dev)
0405 {
0406 struct emac_regs __iomem *p = dev->emacp;
0407 int offset;
0408
0409
0410
0411
0412 if (emac_has_feature(dev, EMAC_FTR_EMAC4SYNC))
0413 offset = offsetof(struct emac_regs, u1.emac4sync.iaht1);
0414 else
0415 offset = offsetof(struct emac_regs, u0.emac4.iaht1);
0416
0417 return (u32 *)((ptrdiff_t)p + offset);
0418 }
0419
0420 static inline u32 *emac_gaht_base(struct emac_instance *dev)
0421 {
0422
0423
0424
0425 return emac_xaht_base(dev) + EMAC_XAHT_REGS(dev);
0426 }
0427
0428 static inline u32 *emac_iaht_base(struct emac_instance *dev)
0429 {
0430
0431
0432
0433 return emac_xaht_base(dev);
0434 }
0435
0436
0437
0438
0439
0440
0441
0442
0443
0444
0445
0446 #define EMAC_ETHTOOL_REGS_ZMII 0x00000001
0447 #define EMAC_ETHTOOL_REGS_RGMII 0x00000002
0448 #define EMAC_ETHTOOL_REGS_TAH 0x00000004
0449
0450 struct emac_ethtool_regs_hdr {
0451 u32 components;
0452 };
0453
0454 struct emac_ethtool_regs_subhdr {
0455 u32 version;
0456 u32 index;
0457 };
0458
0459 #define EMAC_ETHTOOL_REGS_VER 3
0460 #define EMAC4_ETHTOOL_REGS_VER 4
0461 #define EMAC4SYNC_ETHTOOL_REGS_VER 5
0462
0463 #endif