PageRenderTime 54ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/tulip/tulip.h

https://bitbucket.org/wisechild/galaxy-nexus
C++ Header | 573 lines | 390 code | 83 blank | 100 comment | 5 complexity | 135fa82be2a147d0eed68e1d0c5d886c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  1. /*
  2. drivers/net/tulip/tulip.h
  3. Copyright 2000,2001 The Linux Kernel Team
  4. Written/copyright 1994-2001 by Donald Becker.
  5. This software may be used and distributed according to the terms
  6. of the GNU General Public License, incorporated herein by reference.
  7. Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html}
  8. for more information on this driver.
  9. Please submit bugs to http://bugzilla.kernel.org/ .
  10. */
  11. #ifndef __NET_TULIP_H__
  12. #define __NET_TULIP_H__
  13. #include <linux/kernel.h>
  14. #include <linux/types.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/ethtool.h>
  18. #include <linux/timer.h>
  19. #include <linux/delay.h>
  20. #include <linux/pci.h>
  21. #include <asm/io.h>
  22. #include <asm/irq.h>
  23. #include <asm/unaligned.h>
  24. /* undefine, or define to various debugging levels (>4 == obscene levels) */
  25. #define TULIP_DEBUG 1
  26. #ifdef CONFIG_TULIP_MMIO
  27. #define TULIP_BAR 1 /* CBMA */
  28. #else
  29. #define TULIP_BAR 0 /* CBIO */
  30. #endif
  31. struct tulip_chip_table {
  32. char *chip_name;
  33. int io_size;
  34. int valid_intrs; /* CSR7 interrupt enable settings */
  35. int flags;
  36. void (*media_timer) (unsigned long);
  37. work_func_t media_task;
  38. };
  39. enum tbl_flag {
  40. HAS_MII = 0x00001,
  41. HAS_MEDIA_TABLE = 0x00002,
  42. CSR12_IN_SROM = 0x00004,
  43. ALWAYS_CHECK_MII = 0x00008,
  44. HAS_ACPI = 0x00010,
  45. MC_HASH_ONLY = 0x00020, /* Hash-only multicast filter. */
  46. HAS_PNICNWAY = 0x00080,
  47. HAS_NWAY = 0x00040, /* Uses internal NWay xcvr. */
  48. HAS_INTR_MITIGATION = 0x00100,
  49. IS_ASIX = 0x00200,
  50. HAS_8023X = 0x00400,
  51. COMET_MAC_ADDR = 0x00800,
  52. HAS_PCI_MWI = 0x01000,
  53. HAS_PHY_IRQ = 0x02000,
  54. HAS_SWAPPED_SEEPROM = 0x04000,
  55. NEEDS_FAKE_MEDIA_TABLE = 0x08000,
  56. COMET_PM = 0x10000,
  57. };
  58. /* chip types. careful! order is VERY IMPORTANT here, as these
  59. * are used throughout the driver as indices into arrays */
  60. /* Note 21142 == 21143. */
  61. enum chips {
  62. DC21040 = 0,
  63. DC21041 = 1,
  64. DC21140 = 2,
  65. DC21142 = 3, DC21143 = 3,
  66. LC82C168,
  67. MX98713,
  68. MX98715,
  69. MX98725,
  70. AX88140,
  71. PNIC2,
  72. COMET,
  73. COMPEX9881,
  74. I21145,
  75. DM910X,
  76. CONEXANT,
  77. };
  78. enum MediaIs {
  79. MediaIsFD = 1,
  80. MediaAlwaysFD = 2,
  81. MediaIsMII = 4,
  82. MediaIsFx = 8,
  83. MediaIs100 = 16
  84. };
  85. /* Offsets to the Command and Status Registers, "CSRs". All accesses
  86. must be longword instructions and quadword aligned. */
  87. enum tulip_offsets {
  88. CSR0 = 0,
  89. CSR1 = 0x08,
  90. CSR2 = 0x10,
  91. CSR3 = 0x18,
  92. CSR4 = 0x20,
  93. CSR5 = 0x28,
  94. CSR6 = 0x30,
  95. CSR7 = 0x38,
  96. CSR8 = 0x40,
  97. CSR9 = 0x48,
  98. CSR10 = 0x50,
  99. CSR11 = 0x58,
  100. CSR12 = 0x60,
  101. CSR13 = 0x68,
  102. CSR14 = 0x70,
  103. CSR15 = 0x78,
  104. CSR18 = 0x88,
  105. CSR19 = 0x8c,
  106. CSR20 = 0x90,
  107. CSR27 = 0xAC,
  108. CSR28 = 0xB0,
  109. };
  110. /* register offset and bits for CFDD PCI config reg */
  111. enum pci_cfg_driver_reg {
  112. CFDD = 0x40,
  113. CFDD_Sleep = (1 << 31),
  114. CFDD_Snooze = (1 << 30),
  115. };
  116. #define RxPollInt (RxIntr|RxNoBuf|RxDied|RxJabber)
  117. /* The bits in the CSR5 status registers, mostly interrupt sources. */
  118. enum status_bits {
  119. TimerInt = 0x800,
  120. SystemError = 0x2000,
  121. TPLnkFail = 0x1000,
  122. TPLnkPass = 0x10,
  123. NormalIntr = 0x10000,
  124. AbnormalIntr = 0x8000,
  125. RxJabber = 0x200,
  126. RxDied = 0x100,
  127. RxNoBuf = 0x80,
  128. RxIntr = 0x40,
  129. TxFIFOUnderflow = 0x20,
  130. RxErrIntr = 0x10,
  131. TxJabber = 0x08,
  132. TxNoBuf = 0x04,
  133. TxDied = 0x02,
  134. TxIntr = 0x01,
  135. };
  136. /* bit mask for CSR5 TX/RX process state */
  137. #define CSR5_TS 0x00700000
  138. #define CSR5_RS 0x000e0000
  139. enum tulip_mode_bits {
  140. TxThreshold = (1 << 22),
  141. FullDuplex = (1 << 9),
  142. TxOn = 0x2000,
  143. AcceptBroadcast = 0x0100,
  144. AcceptAllMulticast = 0x0080,
  145. AcceptAllPhys = 0x0040,
  146. AcceptRunt = 0x0008,
  147. RxOn = 0x0002,
  148. RxTx = (TxOn | RxOn),
  149. };
  150. enum tulip_busconfig_bits {
  151. MWI = (1 << 24),
  152. MRL = (1 << 23),
  153. MRM = (1 << 21),
  154. CALShift = 14,
  155. BurstLenShift = 8,
  156. };
  157. /* The Tulip Rx and Tx buffer descriptors. */
  158. struct tulip_rx_desc {
  159. __le32 status;
  160. __le32 length;
  161. __le32 buffer1;
  162. __le32 buffer2;
  163. };
  164. struct tulip_tx_desc {
  165. __le32 status;
  166. __le32 length;
  167. __le32 buffer1;
  168. __le32 buffer2; /* We use only buffer 1. */
  169. };
  170. enum desc_status_bits {
  171. DescOwned = 0x80000000,
  172. DescWholePkt = 0x60000000,
  173. DescEndPkt = 0x40000000,
  174. DescStartPkt = 0x20000000,
  175. DescEndRing = 0x02000000,
  176. DescUseLink = 0x01000000,
  177. /*
  178. * Error summary flag is logical or of 'CRC Error', 'Collision Seen',
  179. * 'Frame Too Long', 'Runt' and 'Descriptor Error' flags generated
  180. * within tulip chip.
  181. */
  182. RxDescErrorSummary = 0x8000,
  183. RxDescCRCError = 0x0002,
  184. RxDescCollisionSeen = 0x0040,
  185. /*
  186. * 'Frame Too Long' flag is set if packet length including CRC exceeds
  187. * 1518. However, a full sized VLAN tagged frame is 1522 bytes
  188. * including CRC.
  189. *
  190. * The tulip chip does not block oversized frames, and if this flag is
  191. * set on a receive descriptor it does not indicate the frame has been
  192. * truncated. The receive descriptor also includes the actual length.
  193. * Therefore we can safety ignore this flag and check the length
  194. * ourselves.
  195. */
  196. RxDescFrameTooLong = 0x0080,
  197. RxDescRunt = 0x0800,
  198. RxDescDescErr = 0x4000,
  199. RxWholePkt = 0x00000300,
  200. /*
  201. * Top three bits of 14 bit frame length (status bits 27-29) should
  202. * never be set as that would make frame over 2047 bytes. The Receive
  203. * Watchdog flag (bit 4) may indicate the length is over 2048 and the
  204. * length field is invalid.
  205. */
  206. RxLengthOver2047 = 0x38000010
  207. };
  208. enum t21143_csr6_bits {
  209. csr6_sc = (1<<31),
  210. csr6_ra = (1<<30),
  211. csr6_ign_dest_msb = (1<<26),
  212. csr6_mbo = (1<<25),
  213. csr6_scr = (1<<24), /* scramble mode flag: can't be set */
  214. csr6_pcs = (1<<23), /* Enables PCS functions (symbol mode requires csr6_ps be set) default is set */
  215. csr6_ttm = (1<<22), /* Transmit Threshold Mode, set for 10baseT, 0 for 100BaseTX */
  216. csr6_sf = (1<<21), /* Store and forward. If set ignores TR bits */
  217. csr6_hbd = (1<<19), /* Heart beat disable. Disables SQE function in 10baseT */
  218. csr6_ps = (1<<18), /* Port Select. 0 (defualt) = 10baseT, 1 = 100baseTX: can't be set */
  219. csr6_ca = (1<<17), /* Collision Offset Enable. If set uses special algorithm in low collision situations */
  220. csr6_trh = (1<<15), /* Transmit Threshold high bit */
  221. csr6_trl = (1<<14), /* Transmit Threshold low bit */
  222. /***************************************************************
  223. * This table shows transmit threshold values based on media *
  224. * and these two registers (from PNIC1 & 2 docs) Note: this is *
  225. * all meaningless if sf is set. *
  226. ***************************************************************/
  227. /***********************************
  228. * (trh,trl) * 100BaseTX * 10BaseT *
  229. ***********************************
  230. * (0,0) * 128 * 72 *
  231. * (0,1) * 256 * 96 *
  232. * (1,0) * 512 * 128 *
  233. * (1,1) * 1024 * 160 *
  234. ***********************************/
  235. csr6_fc = (1<<12), /* Forces a collision in next transmission (for testing in loopback mode) */
  236. csr6_om_int_loop = (1<<10), /* internal (FIFO) loopback flag */
  237. csr6_om_ext_loop = (1<<11), /* external (PMD) loopback flag */
  238. /* set both and you get (PHY) loopback */
  239. csr6_fd = (1<<9), /* Full duplex mode, disables hearbeat, no loopback */
  240. csr6_pm = (1<<7), /* Pass All Multicast */
  241. csr6_pr = (1<<6), /* Promiscuous mode */
  242. csr6_sb = (1<<5), /* Start(1)/Stop(0) backoff counter */
  243. csr6_if = (1<<4), /* Inverse Filtering, rejects only addresses in address table: can't be set */
  244. csr6_pb = (1<<3), /* Pass Bad Frames, (1) causes even bad frames to be passed on */
  245. csr6_ho = (1<<2), /* Hash-only filtering mode: can't be set */
  246. csr6_hp = (1<<0), /* Hash/Perfect Receive Filtering Mode: can't be set */
  247. csr6_mask_capture = (csr6_sc | csr6_ca),
  248. csr6_mask_defstate = (csr6_mask_capture | csr6_mbo),
  249. csr6_mask_hdcap = (csr6_mask_defstate | csr6_hbd | csr6_ps),
  250. csr6_mask_hdcaptt = (csr6_mask_hdcap | csr6_trh | csr6_trl),
  251. csr6_mask_fullcap = (csr6_mask_hdcaptt | csr6_fd),
  252. csr6_mask_fullpromisc = (csr6_pr | csr6_pm),
  253. csr6_mask_filters = (csr6_hp | csr6_ho | csr6_if),
  254. csr6_mask_100bt = (csr6_scr | csr6_pcs | csr6_hbd),
  255. };
  256. enum tulip_comet_csr13_bits {
  257. /* The LINKOFFE and LINKONE work in conjunction with LSCE, i.e. they
  258. * determine which link status transition wakes up if LSCE is
  259. * enabled */
  260. comet_csr13_linkoffe = (1 << 17),
  261. comet_csr13_linkone = (1 << 16),
  262. comet_csr13_wfre = (1 << 10),
  263. comet_csr13_mpre = (1 << 9),
  264. comet_csr13_lsce = (1 << 8),
  265. comet_csr13_wfr = (1 << 2),
  266. comet_csr13_mpr = (1 << 1),
  267. comet_csr13_lsc = (1 << 0),
  268. };
  269. enum tulip_comet_csr18_bits {
  270. comet_csr18_pmes_sticky = (1 << 24),
  271. comet_csr18_pm_mode = (1 << 19),
  272. comet_csr18_apm_mode = (1 << 18),
  273. comet_csr18_d3a = (1 << 7)
  274. };
  275. enum tulip_comet_csr20_bits {
  276. comet_csr20_pmes = (1 << 15),
  277. };
  278. /* Keep the ring sizes a power of two for efficiency.
  279. Making the Tx ring too large decreases the effectiveness of channel
  280. bonding and packet priority.
  281. There are no ill effects from too-large receive rings. */
  282. #define TX_RING_SIZE 32
  283. #define RX_RING_SIZE 128
  284. #define MEDIA_MASK 31
  285. /* The receiver on the DC21143 rev 65 can fail to close the last
  286. * receive descriptor in certain circumstances (see errata) when
  287. * using MWI. This can only occur if the receive buffer ends on
  288. * a cache line boundary, so the "+ 4" below ensures it doesn't.
  289. */
  290. #define PKT_BUF_SZ (1536 + 4) /* Size of each temporary Rx buffer. */
  291. #define TULIP_MIN_CACHE_LINE 8 /* in units of 32-bit words */
  292. #if defined(__sparc__) || defined(__hppa__)
  293. /* The UltraSparc PCI controllers will disconnect at every 64-byte
  294. * crossing anyways so it makes no sense to tell Tulip to burst
  295. * any more than that.
  296. */
  297. #define TULIP_MAX_CACHE_LINE 16 /* in units of 32-bit words */
  298. #else
  299. #define TULIP_MAX_CACHE_LINE 32 /* in units of 32-bit words */
  300. #endif
  301. /* Ring-wrap flag in length field, use for last ring entry.
  302. 0x01000000 means chain on buffer2 address,
  303. 0x02000000 means use the ring start address in CSR2/3.
  304. Note: Some work-alike chips do not function correctly in chained mode.
  305. The ASIX chip works only in chained mode.
  306. Thus we indicates ring mode, but always write the 'next' field for
  307. chained mode as well.
  308. */
  309. #define DESC_RING_WRAP 0x02000000
  310. #define EEPROM_SIZE 512 /* 2 << EEPROM_ADDRLEN */
  311. #define RUN_AT(x) (jiffies + (x))
  312. #define get_u16(ptr) get_unaligned_le16((ptr))
  313. struct medialeaf {
  314. u8 type;
  315. u8 media;
  316. unsigned char *leafdata;
  317. };
  318. struct mediatable {
  319. u16 defaultmedia;
  320. u8 leafcount;
  321. u8 csr12dir; /* General purpose pin directions. */
  322. unsigned has_mii:1;
  323. unsigned has_nonmii:1;
  324. unsigned has_reset:6;
  325. u32 csr15dir;
  326. u32 csr15val; /* 21143 NWay setting. */
  327. struct medialeaf mleaf[0];
  328. };
  329. struct mediainfo {
  330. struct mediainfo *next;
  331. int info_type;
  332. int index;
  333. unsigned char *info;
  334. };
  335. struct ring_info {
  336. struct sk_buff *skb;
  337. dma_addr_t mapping;
  338. };
  339. struct tulip_private {
  340. const char *product_name;
  341. struct net_device *next_module;
  342. struct tulip_rx_desc *rx_ring;
  343. struct tulip_tx_desc *tx_ring;
  344. dma_addr_t rx_ring_dma;
  345. dma_addr_t tx_ring_dma;
  346. /* The saved address of a sent-in-place packet/buffer, for skfree(). */
  347. struct ring_info tx_buffers[TX_RING_SIZE];
  348. /* The addresses of receive-in-place skbuffs. */
  349. struct ring_info rx_buffers[RX_RING_SIZE];
  350. u16 setup_frame[96]; /* Pseudo-Tx frame to init address table. */
  351. int chip_id;
  352. int revision;
  353. int flags;
  354. struct napi_struct napi;
  355. struct timer_list timer; /* Media selection timer. */
  356. struct timer_list oom_timer; /* Out of memory timer. */
  357. u32 mc_filter[2];
  358. spinlock_t lock;
  359. spinlock_t mii_lock;
  360. unsigned int cur_rx, cur_tx; /* The next free ring entry */
  361. unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
  362. #ifdef CONFIG_TULIP_NAPI_HW_MITIGATION
  363. int mit_on;
  364. #endif
  365. unsigned int full_duplex:1; /* Full-duplex operation requested. */
  366. unsigned int full_duplex_lock:1;
  367. unsigned int fake_addr:1; /* Multiport board faked address. */
  368. unsigned int default_port:4; /* Last dev->if_port value. */
  369. unsigned int media2:4; /* Secondary monitored media port. */
  370. unsigned int medialock:1; /* Don't sense media type. */
  371. unsigned int mediasense:1; /* Media sensing in progress. */
  372. unsigned int nway:1, nwayset:1; /* 21143 internal NWay. */
  373. unsigned int timeout_recovery:1;
  374. unsigned int csr0; /* CSR0 setting. */
  375. unsigned int csr6; /* Current CSR6 control settings. */
  376. unsigned char eeprom[EEPROM_SIZE]; /* Serial EEPROM contents. */
  377. void (*link_change) (struct net_device * dev, int csr5);
  378. struct ethtool_wolinfo wolinfo; /* WOL settings */
  379. u16 sym_advertise, mii_advertise; /* NWay capabilities advertised. */
  380. u16 lpar; /* 21143 Link partner ability. */
  381. u16 advertising[4];
  382. signed char phys[4], mii_cnt; /* MII device addresses. */
  383. struct mediatable *mtable;
  384. int cur_index; /* Current media index. */
  385. int saved_if_port;
  386. struct pci_dev *pdev;
  387. int ttimer;
  388. int susp_rx;
  389. unsigned long nir;
  390. void __iomem *base_addr;
  391. int csr12_shadow;
  392. int pad0; /* Used for 8-byte alignment */
  393. struct work_struct media_work;
  394. struct net_device *dev;
  395. };
  396. struct eeprom_fixup {
  397. char *name;
  398. unsigned char addr0;
  399. unsigned char addr1;
  400. unsigned char addr2;
  401. u16 newtable[32]; /* Max length below. */
  402. };
  403. /* 21142.c */
  404. extern u16 t21142_csr14[];
  405. void t21142_media_task(struct work_struct *work);
  406. void t21142_start_nway(struct net_device *dev);
  407. void t21142_lnk_change(struct net_device *dev, int csr5);
  408. /* PNIC2.c */
  409. void pnic2_lnk_change(struct net_device *dev, int csr5);
  410. void pnic2_timer(unsigned long data);
  411. void pnic2_start_nway(struct net_device *dev);
  412. void pnic2_lnk_change(struct net_device *dev, int csr5);
  413. /* eeprom.c */
  414. void tulip_parse_eeprom(struct net_device *dev);
  415. int tulip_read_eeprom(struct net_device *dev, int location, int addr_len);
  416. /* interrupt.c */
  417. extern unsigned int tulip_max_interrupt_work;
  418. extern int tulip_rx_copybreak;
  419. irqreturn_t tulip_interrupt(int irq, void *dev_instance);
  420. int tulip_refill_rx(struct net_device *dev);
  421. #ifdef CONFIG_TULIP_NAPI
  422. int tulip_poll(struct napi_struct *napi, int budget);
  423. #endif
  424. /* media.c */
  425. int tulip_mdio_read(struct net_device *dev, int phy_id, int location);
  426. void tulip_mdio_write(struct net_device *dev, int phy_id, int location, int value);
  427. void tulip_select_media(struct net_device *dev, int startup);
  428. int tulip_check_duplex(struct net_device *dev);
  429. void tulip_find_mii (struct net_device *dev, int board_idx);
  430. /* pnic.c */
  431. void pnic_do_nway(struct net_device *dev);
  432. void pnic_lnk_change(struct net_device *dev, int csr5);
  433. void pnic_timer(unsigned long data);
  434. /* timer.c */
  435. void tulip_media_task(struct work_struct *work);
  436. void mxic_timer(unsigned long data);
  437. void comet_timer(unsigned long data);
  438. /* tulip_core.c */
  439. extern int tulip_debug;
  440. extern const char * const medianame[];
  441. extern const char tulip_media_cap[];
  442. extern struct tulip_chip_table tulip_tbl[];
  443. void oom_timer(unsigned long data);
  444. extern u8 t21040_csr13[];
  445. static inline void tulip_start_rxtx(struct tulip_private *tp)
  446. {
  447. void __iomem *ioaddr = tp->base_addr;
  448. iowrite32(tp->csr6 | RxTx, ioaddr + CSR6);
  449. barrier();
  450. (void) ioread32(ioaddr + CSR6); /* mmio sync */
  451. }
  452. static inline void tulip_stop_rxtx(struct tulip_private *tp)
  453. {
  454. void __iomem *ioaddr = tp->base_addr;
  455. u32 csr6 = ioread32(ioaddr + CSR6);
  456. if (csr6 & RxTx) {
  457. unsigned i=1300/10;
  458. iowrite32(csr6 & ~RxTx, ioaddr + CSR6);
  459. barrier();
  460. /* wait until in-flight frame completes.
  461. * Max time @ 10BT: 1500*8b/10Mbps == 1200us (+ 100us margin)
  462. * Typically expect this loop to end in < 50 us on 100BT.
  463. */
  464. while (--i && (ioread32(ioaddr + CSR5) & (CSR5_TS|CSR5_RS)))
  465. udelay(10);
  466. if (!i)
  467. netdev_dbg(tp->dev, "tulip_stop_rxtx() failed (CSR5 0x%x CSR6 0x%x)\n",
  468. ioread32(ioaddr + CSR5),
  469. ioread32(ioaddr + CSR6));
  470. }
  471. }
  472. static inline void tulip_restart_rxtx(struct tulip_private *tp)
  473. {
  474. tulip_stop_rxtx(tp);
  475. udelay(5);
  476. tulip_start_rxtx(tp);
  477. }
  478. static inline void tulip_tx_timeout_complete(struct tulip_private *tp, void __iomem *ioaddr)
  479. {
  480. /* Stop and restart the chip's Tx processes. */
  481. tulip_restart_rxtx(tp);
  482. /* Trigger an immediate transmit demand. */
  483. iowrite32(0, ioaddr + CSR1);
  484. tp->dev->stats.tx_errors++;
  485. }
  486. #endif /* __NET_TULIP_H__ */