0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef __NET_TULIP_H__
0014 #define __NET_TULIP_H__
0015
0016 #include <linux/kernel.h>
0017 #include <linux/types.h>
0018 #include <linux/spinlock.h>
0019 #include <linux/netdevice.h>
0020 #include <linux/ethtool.h>
0021 #include <linux/timer.h>
0022 #include <linux/delay.h>
0023 #include <linux/pci.h>
0024 #include <asm/io.h>
0025 #include <asm/irq.h>
0026 #include <asm/unaligned.h>
0027
0028
0029
0030
0031 #define TULIP_DEBUG 1
0032
0033 #ifdef CONFIG_TULIP_MMIO
0034 #define TULIP_BAR 1
0035 #else
0036 #define TULIP_BAR 0
0037 #endif
0038
0039
0040
0041 struct tulip_chip_table {
0042 char *chip_name;
0043 int io_size;
0044 int valid_intrs;
0045 int flags;
0046 void (*media_timer) (struct timer_list *);
0047 work_func_t media_task;
0048 };
0049
0050
0051 enum tbl_flag {
0052 HAS_MII = 0x00001,
0053 HAS_MEDIA_TABLE = 0x00002,
0054 CSR12_IN_SROM = 0x00004,
0055 ALWAYS_CHECK_MII = 0x00008,
0056 HAS_ACPI = 0x00010,
0057 MC_HASH_ONLY = 0x00020,
0058 HAS_PNICNWAY = 0x00080,
0059 HAS_NWAY = 0x00040,
0060 HAS_INTR_MITIGATION = 0x00100,
0061 IS_ASIX = 0x00200,
0062 HAS_8023X = 0x00400,
0063 COMET_MAC_ADDR = 0x00800,
0064 HAS_PCI_MWI = 0x01000,
0065 HAS_PHY_IRQ = 0x02000,
0066 HAS_SWAPPED_SEEPROM = 0x04000,
0067 NEEDS_FAKE_MEDIA_TABLE = 0x08000,
0068 COMET_PM = 0x10000,
0069 };
0070
0071
0072
0073
0074
0075 enum chips {
0076 DC21040 = 0,
0077 DC21041 = 1,
0078 DC21140 = 2,
0079 DC21142 = 3, DC21143 = 3,
0080 LC82C168,
0081 MX98713,
0082 MX98715,
0083 MX98725,
0084 AX88140,
0085 PNIC2,
0086 COMET,
0087 COMPEX9881,
0088 I21145,
0089 DM910X,
0090 CONEXANT,
0091 };
0092
0093
0094 enum MediaIs {
0095 MediaIsFD = 1,
0096 MediaAlwaysFD = 2,
0097 MediaIsMII = 4,
0098 MediaIsFx = 8,
0099 MediaIs100 = 16
0100 };
0101
0102
0103
0104
0105 enum tulip_offsets {
0106 CSR0 = 0,
0107 CSR1 = 0x08,
0108 CSR2 = 0x10,
0109 CSR3 = 0x18,
0110 CSR4 = 0x20,
0111 CSR5 = 0x28,
0112 CSR6 = 0x30,
0113 CSR7 = 0x38,
0114 CSR8 = 0x40,
0115 CSR9 = 0x48,
0116 CSR10 = 0x50,
0117 CSR11 = 0x58,
0118 CSR12 = 0x60,
0119 CSR13 = 0x68,
0120 CSR14 = 0x70,
0121 CSR15 = 0x78,
0122 CSR18 = 0x88,
0123 CSR19 = 0x8c,
0124 CSR20 = 0x90,
0125 CSR27 = 0xAC,
0126 CSR28 = 0xB0,
0127 };
0128
0129
0130 enum pci_cfg_driver_reg {
0131 CFDD = 0x40,
0132 CFDD_Sleep = (1 << 31),
0133 CFDD_Snooze = (1 << 30),
0134 };
0135
0136 #define RxPollInt (RxIntr|RxNoBuf|RxDied|RxJabber)
0137
0138
0139 enum status_bits {
0140 TimerInt = 0x800,
0141 SystemError = 0x2000,
0142 TPLnkFail = 0x1000,
0143 TPLnkPass = 0x10,
0144 NormalIntr = 0x10000,
0145 AbnormalIntr = 0x8000,
0146 RxJabber = 0x200,
0147 RxDied = 0x100,
0148 RxNoBuf = 0x80,
0149 RxIntr = 0x40,
0150 TxFIFOUnderflow = 0x20,
0151 RxErrIntr = 0x10,
0152 TxJabber = 0x08,
0153 TxNoBuf = 0x04,
0154 TxDied = 0x02,
0155 TxIntr = 0x01,
0156 };
0157
0158
0159 #define CSR5_TS 0x00700000
0160 #define CSR5_RS 0x000e0000
0161
0162 enum tulip_mode_bits {
0163 TxThreshold = (1 << 22),
0164 FullDuplex = (1 << 9),
0165 TxOn = 0x2000,
0166 AcceptBroadcast = 0x0100,
0167 AcceptAllMulticast = 0x0080,
0168 AcceptAllPhys = 0x0040,
0169 AcceptRunt = 0x0008,
0170 RxOn = 0x0002,
0171 RxTx = (TxOn | RxOn),
0172 };
0173
0174
0175 enum tulip_busconfig_bits {
0176 MWI = (1 << 24),
0177 MRL = (1 << 23),
0178 MRM = (1 << 21),
0179 CALShift = 14,
0180 BurstLenShift = 8,
0181 };
0182
0183
0184
0185 struct tulip_rx_desc {
0186 __le32 status;
0187 __le32 length;
0188 __le32 buffer1;
0189 __le32 buffer2;
0190 };
0191
0192
0193 struct tulip_tx_desc {
0194 __le32 status;
0195 __le32 length;
0196 __le32 buffer1;
0197 __le32 buffer2;
0198 };
0199
0200
0201 enum desc_status_bits {
0202 DescOwned = 0x80000000,
0203 DescWholePkt = 0x60000000,
0204 DescEndPkt = 0x40000000,
0205 DescStartPkt = 0x20000000,
0206 DescEndRing = 0x02000000,
0207 DescUseLink = 0x01000000,
0208
0209
0210
0211
0212
0213
0214 RxDescErrorSummary = 0x8000,
0215 RxDescCRCError = 0x0002,
0216 RxDescCollisionSeen = 0x0040,
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229 RxDescFrameTooLong = 0x0080,
0230 RxDescRunt = 0x0800,
0231 RxDescDescErr = 0x4000,
0232 RxWholePkt = 0x00000300,
0233
0234
0235
0236
0237
0238
0239 RxLengthOver2047 = 0x38000010
0240 };
0241
0242
0243 enum t21143_csr6_bits {
0244 csr6_sc = (1<<31),
0245 csr6_ra = (1<<30),
0246 csr6_ign_dest_msb = (1<<26),
0247 csr6_mbo = (1<<25),
0248 csr6_scr = (1<<24),
0249 csr6_pcs = (1<<23),
0250 csr6_ttm = (1<<22),
0251 csr6_sf = (1<<21),
0252 csr6_hbd = (1<<19),
0253 csr6_ps = (1<<18),
0254 csr6_ca = (1<<17),
0255 csr6_trh = (1<<15),
0256 csr6_trl = (1<<14),
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273 csr6_fc = (1<<12),
0274 csr6_om_int_loop = (1<<10),
0275 csr6_om_ext_loop = (1<<11),
0276
0277 csr6_fd = (1<<9),
0278 csr6_pm = (1<<7),
0279 csr6_pr = (1<<6),
0280 csr6_sb = (1<<5),
0281 csr6_if = (1<<4),
0282 csr6_pb = (1<<3),
0283 csr6_ho = (1<<2),
0284 csr6_hp = (1<<0),
0285
0286 csr6_mask_capture = (csr6_sc | csr6_ca),
0287 csr6_mask_defstate = (csr6_mask_capture | csr6_mbo),
0288 csr6_mask_hdcap = (csr6_mask_defstate | csr6_hbd | csr6_ps),
0289 csr6_mask_hdcaptt = (csr6_mask_hdcap | csr6_trh | csr6_trl),
0290 csr6_mask_fullcap = (csr6_mask_hdcaptt | csr6_fd),
0291 csr6_mask_fullpromisc = (csr6_pr | csr6_pm),
0292 csr6_mask_filters = (csr6_hp | csr6_ho | csr6_if),
0293 csr6_mask_100bt = (csr6_scr | csr6_pcs | csr6_hbd),
0294 };
0295
0296 enum tulip_comet_csr13_bits {
0297
0298
0299
0300 comet_csr13_linkoffe = (1 << 17),
0301 comet_csr13_linkone = (1 << 16),
0302 comet_csr13_wfre = (1 << 10),
0303 comet_csr13_mpre = (1 << 9),
0304 comet_csr13_lsce = (1 << 8),
0305 comet_csr13_wfr = (1 << 2),
0306 comet_csr13_mpr = (1 << 1),
0307 comet_csr13_lsc = (1 << 0),
0308 };
0309
0310 enum tulip_comet_csr18_bits {
0311 comet_csr18_pmes_sticky = (1 << 24),
0312 comet_csr18_pm_mode = (1 << 19),
0313 comet_csr18_apm_mode = (1 << 18),
0314 comet_csr18_d3a = (1 << 7)
0315 };
0316
0317 enum tulip_comet_csr20_bits {
0318 comet_csr20_pmes = (1 << 15),
0319 };
0320
0321
0322
0323
0324
0325
0326 #define TX_RING_SIZE 32
0327 #define RX_RING_SIZE 128
0328 #define MEDIA_MASK 31
0329
0330
0331
0332
0333
0334
0335 #define PKT_BUF_SZ (1536 + 4)
0336
0337 #define TULIP_MIN_CACHE_LINE 8
0338
0339 #if defined(__sparc__) || defined(__hppa__)
0340
0341
0342
0343
0344 #define TULIP_MAX_CACHE_LINE 16
0345 #else
0346 #define TULIP_MAX_CACHE_LINE 32
0347 #endif
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358 #define DESC_RING_WRAP 0x02000000
0359
0360
0361 #define EEPROM_SIZE 512
0362
0363
0364 #define RUN_AT(x) (jiffies + (x))
0365
0366 #define get_u16(ptr) get_unaligned_le16((ptr))
0367
0368 struct medialeaf {
0369 u8 type;
0370 u8 media;
0371 unsigned char *leafdata;
0372 };
0373
0374
0375 struct mediatable {
0376 u16 defaultmedia;
0377 u8 leafcount;
0378 u8 csr12dir;
0379 unsigned has_mii:1;
0380 unsigned has_nonmii:1;
0381 unsigned has_reset:6;
0382 u32 csr15dir;
0383 u32 csr15val;
0384 struct medialeaf mleaf[];
0385 };
0386
0387
0388 struct mediainfo {
0389 struct mediainfo *next;
0390 int info_type;
0391 int index;
0392 unsigned char *info;
0393 };
0394
0395 struct ring_info {
0396 struct sk_buff *skb;
0397 dma_addr_t mapping;
0398 };
0399
0400
0401 struct tulip_private {
0402 const char *product_name;
0403 struct net_device *next_module;
0404 struct tulip_rx_desc *rx_ring;
0405 struct tulip_tx_desc *tx_ring;
0406 dma_addr_t rx_ring_dma;
0407 dma_addr_t tx_ring_dma;
0408
0409 struct ring_info tx_buffers[TX_RING_SIZE];
0410
0411 struct ring_info rx_buffers[RX_RING_SIZE];
0412 u16 setup_frame[96];
0413 int chip_id;
0414 int revision;
0415 int flags;
0416 struct napi_struct napi;
0417 struct timer_list timer;
0418 struct timer_list oom_timer;
0419 u32 mc_filter[2];
0420 spinlock_t lock;
0421 spinlock_t mii_lock;
0422 unsigned int cur_rx, cur_tx;
0423 unsigned int dirty_rx, dirty_tx;
0424
0425 #ifdef CONFIG_TULIP_NAPI_HW_MITIGATION
0426 int mit_on;
0427 #endif
0428 unsigned int full_duplex:1;
0429 unsigned int full_duplex_lock:1;
0430 unsigned int fake_addr:1;
0431 unsigned int default_port:4;
0432 unsigned int media2:4;
0433 unsigned int medialock:1;
0434 unsigned int mediasense:1;
0435 unsigned int nway:1, nwayset:1;
0436 unsigned int timeout_recovery:1;
0437 unsigned int csr0;
0438 unsigned int csr6;
0439 unsigned char eeprom[EEPROM_SIZE];
0440 void (*link_change) (struct net_device * dev, int csr5);
0441 struct ethtool_wolinfo wolinfo;
0442 u16 sym_advertise, mii_advertise;
0443 u16 lpar;
0444 u16 advertising[4];
0445 signed char phys[4], mii_cnt;
0446 struct mediatable *mtable;
0447 int cur_index;
0448 int saved_if_port;
0449 struct pci_dev *pdev;
0450 int ttimer;
0451 int susp_rx;
0452 unsigned long nir;
0453 void __iomem *base_addr;
0454 int csr12_shadow;
0455 int pad0;
0456 struct work_struct media_work;
0457 struct net_device *dev;
0458 };
0459
0460
0461 struct eeprom_fixup {
0462 char *name;
0463 unsigned char addr0;
0464 unsigned char addr1;
0465 unsigned char addr2;
0466 u16 newtable[32];
0467 };
0468
0469
0470
0471 extern u16 t21142_csr14[];
0472 void t21142_media_task(struct work_struct *work);
0473 void t21142_start_nway(struct net_device *dev);
0474 void t21142_lnk_change(struct net_device *dev, int csr5);
0475
0476
0477
0478 void pnic2_lnk_change(struct net_device *dev, int csr5);
0479 void pnic2_timer(struct timer_list *t);
0480 void pnic2_start_nway(struct net_device *dev);
0481
0482
0483 void tulip_parse_eeprom(struct net_device *dev);
0484 int tulip_read_eeprom(struct net_device *dev, int location, int addr_len);
0485
0486
0487 extern unsigned int tulip_max_interrupt_work;
0488 extern int tulip_rx_copybreak;
0489 irqreturn_t tulip_interrupt(int irq, void *dev_instance);
0490 int tulip_refill_rx(struct net_device *dev);
0491 #ifdef CONFIG_TULIP_NAPI
0492 int tulip_poll(struct napi_struct *napi, int budget);
0493 #endif
0494
0495
0496
0497 int tulip_mdio_read(struct net_device *dev, int phy_id, int location);
0498 void tulip_mdio_write(struct net_device *dev, int phy_id, int location, int value);
0499 void tulip_select_media(struct net_device *dev, int startup);
0500 int tulip_check_duplex(struct net_device *dev);
0501 void tulip_find_mii (struct net_device *dev, int board_idx);
0502
0503
0504 void pnic_do_nway(struct net_device *dev);
0505 void pnic_lnk_change(struct net_device *dev, int csr5);
0506 void pnic_timer(struct timer_list *t);
0507
0508
0509 void tulip_media_task(struct work_struct *work);
0510 void mxic_timer(struct timer_list *t);
0511 void comet_timer(struct timer_list *t);
0512
0513
0514 extern int tulip_debug;
0515 extern const char * const medianame[];
0516 extern const char tulip_media_cap[];
0517 extern const struct tulip_chip_table tulip_tbl[];
0518 void oom_timer(struct timer_list *t);
0519 extern u8 t21040_csr13[];
0520
0521 static inline void tulip_start_rxtx(struct tulip_private *tp)
0522 {
0523 void __iomem *ioaddr = tp->base_addr;
0524 iowrite32(tp->csr6 | RxTx, ioaddr + CSR6);
0525 barrier();
0526 (void) ioread32(ioaddr + CSR6);
0527 }
0528
0529 static inline void tulip_stop_rxtx(struct tulip_private *tp)
0530 {
0531 void __iomem *ioaddr = tp->base_addr;
0532 u32 csr6 = ioread32(ioaddr + CSR6);
0533
0534 if (csr6 & RxTx) {
0535 unsigned i=1300/10;
0536 iowrite32(csr6 & ~RxTx, ioaddr + CSR6);
0537 barrier();
0538
0539
0540
0541
0542 while (--i && (ioread32(ioaddr + CSR5) & (CSR5_TS|CSR5_RS)))
0543 udelay(10);
0544
0545 if (!i)
0546 netdev_dbg(tp->dev, "tulip_stop_rxtx() failed (CSR5 0x%x CSR6 0x%x)\n",
0547 ioread32(ioaddr + CSR5),
0548 ioread32(ioaddr + CSR6));
0549 }
0550 }
0551
0552 static inline void tulip_restart_rxtx(struct tulip_private *tp)
0553 {
0554 tulip_stop_rxtx(tp);
0555 udelay(5);
0556 tulip_start_rxtx(tp);
0557 }
0558
0559 static inline void tulip_tx_timeout_complete(struct tulip_private *tp, void __iomem *ioaddr)
0560 {
0561
0562 tulip_restart_rxtx(tp);
0563
0564 iowrite32(0, ioaddr + CSR1);
0565
0566 tp->dev->stats.tx_errors++;
0567 }
0568
0569 #endif