jme.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. * JMicron JMC2x0 series PCIe Ethernet Linux Device Driver
  3. *
  4. * Copyright 2008 JMicron Technology Corporation
  5. * http://www.jmicron.com/
  6. * Copyright (c) 2009 - 2010 Guo-Fu Tseng <cooldavid@cooldavid.org>
  7. *
  8. * Author: Guo-Fu Tseng <cooldavid@cooldavid.org>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. *
  23. */
  24. #ifndef __JME_H_INCLUDED__
  25. #define __JME_H_INCLUDED__
  26. #include <linux/interrupt.h>
  27. #define DRV_NAME "jme"
  28. #define DRV_VERSION "1.0.8"
  29. #define PCI_DEVICE_ID_JMICRON_JMC250 0x0250
  30. #define PCI_DEVICE_ID_JMICRON_JMC260 0x0260
  31. /*
  32. * Message related definitions
  33. */
  34. #define JME_DEF_MSG_ENABLE \
  35. (NETIF_MSG_PROBE | \
  36. NETIF_MSG_LINK | \
  37. NETIF_MSG_RX_ERR | \
  38. NETIF_MSG_TX_ERR | \
  39. NETIF_MSG_HW)
  40. #ifdef TX_DEBUG
  41. #define tx_dbg(priv, fmt, args...) \
  42. printk(KERN_DEBUG "%s: " fmt, (priv)->dev->name, ##args)
  43. #else
  44. #define tx_dbg(priv, fmt, args...) \
  45. do { \
  46. if (0) \
  47. printk(KERN_DEBUG "%s: " fmt, (priv)->dev->name, ##args); \
  48. } while (0)
  49. #endif
  50. /*
  51. * Extra PCI Configuration space interface
  52. */
  53. #define PCI_DCSR_MRRS 0x59
  54. #define PCI_DCSR_MRRS_MASK 0x70
  55. enum pci_dcsr_mrrs_vals {
  56. MRRS_128B = 0x00,
  57. MRRS_256B = 0x10,
  58. MRRS_512B = 0x20,
  59. MRRS_1024B = 0x30,
  60. MRRS_2048B = 0x40,
  61. MRRS_4096B = 0x50,
  62. };
  63. #define PCI_SPI 0xB0
  64. enum pci_spi_bits {
  65. SPI_EN = 0x10,
  66. SPI_MISO = 0x08,
  67. SPI_MOSI = 0x04,
  68. SPI_SCLK = 0x02,
  69. SPI_CS = 0x01,
  70. };
  71. struct jme_spi_op {
  72. void __user *uwbuf;
  73. void __user *urbuf;
  74. __u8 wn; /* Number of write actions */
  75. __u8 rn; /* Number of read actions */
  76. __u8 bitn; /* Number of bits per action */
  77. __u8 spd; /* The maxim acceptable speed of controller, in MHz.*/
  78. __u8 mode; /* CPOL, CPHA, and Duplex mode of SPI */
  79. /* Internal use only */
  80. u8 *kwbuf;
  81. u8 *krbuf;
  82. u8 sr;
  83. u16 halfclk; /* Half of clock cycle calculated from spd, in ns */
  84. };
  85. enum jme_spi_op_bits {
  86. SPI_MODE_CPHA = 0x01,
  87. SPI_MODE_CPOL = 0x02,
  88. SPI_MODE_DUP = 0x80,
  89. };
  90. #define HALF_US 500 /* 500 ns */
  91. #define PCI_PRIV_PE1 0xE4
  92. enum pci_priv_pe1_bit_masks {
  93. PE1_ASPMSUPRT = 0x00000003, /*
  94. * RW:
  95. * Aspm_support[1:0]
  96. * (R/W Port of 5C[11:10])
  97. */
  98. PE1_MULTIFUN = 0x00000004, /* RW: Multi_fun_bit */
  99. PE1_RDYDMA = 0x00000008, /* RO: ~link.rdy_for_dma */
  100. PE1_ASPMOPTL = 0x00000030, /* RW: link.rx10s_option[1:0] */
  101. PE1_ASPMOPTH = 0x000000C0, /* RW: 10_req=[3]?HW:[2] */
  102. PE1_GPREG0 = 0x0000FF00, /*
  103. * SRW:
  104. * Cfg_gp_reg0
  105. * [7:6] phy_giga BG control
  106. * [5] CREQ_N as CREQ_N1 (CPPE# as CREQ#)
  107. * [4:0] Reserved
  108. */
  109. PE1_GPREG0_PBG = 0x0000C000, /* phy_giga BG control */
  110. PE1_GPREG1 = 0x00FF0000, /* RW: Cfg_gp_reg1 */
  111. PE1_REVID = 0xFF000000, /* RO: Rev ID */
  112. };
  113. enum pci_priv_pe1_values {
  114. PE1_GPREG0_ENBG = 0x00000000, /* en BG */
  115. PE1_GPREG0_PDD3COLD = 0x00004000, /* giga_PD + d3cold */
  116. PE1_GPREG0_PDPCIESD = 0x00008000, /* giga_PD + pcie_shutdown */
  117. PE1_GPREG0_PDPCIEIDDQ = 0x0000C000, /* giga_PD + pcie_iddq */
  118. };
  119. /*
  120. * Dynamic(adaptive)/Static PCC values
  121. */
  122. enum dynamic_pcc_values {
  123. PCC_OFF = 0,
  124. PCC_P1 = 1,
  125. PCC_P2 = 2,
  126. PCC_P3 = 3,
  127. PCC_OFF_TO = 0,
  128. PCC_P1_TO = 1,
  129. PCC_P2_TO = 64,
  130. PCC_P3_TO = 128,
  131. PCC_OFF_CNT = 0,
  132. PCC_P1_CNT = 1,
  133. PCC_P2_CNT = 16,
  134. PCC_P3_CNT = 32,
  135. };
  136. struct dynpcc_info {
  137. unsigned long last_bytes;
  138. unsigned long last_pkts;
  139. unsigned long intr_cnt;
  140. unsigned char cur;
  141. unsigned char attempt;
  142. unsigned char cnt;
  143. };
  144. #define PCC_INTERVAL_US 100000
  145. #define PCC_INTERVAL (HZ / (1000000 / PCC_INTERVAL_US))
  146. #define PCC_P3_THRESHOLD (2 * 1024 * 1024)
  147. #define PCC_P2_THRESHOLD 800
  148. #define PCC_INTR_THRESHOLD 800
  149. #define PCC_TX_TO 1000
  150. #define PCC_TX_CNT 8
  151. /*
  152. * TX/RX Descriptors
  153. *
  154. * TX/RX Ring DESC Count Must be multiple of 16 and <= 1024
  155. */
  156. #define RING_DESC_ALIGN 16 /* Descriptor alignment */
  157. #define TX_DESC_SIZE 16
  158. #define TX_RING_NR 8
  159. #define TX_RING_ALLOC_SIZE(s) ((s * TX_DESC_SIZE) + RING_DESC_ALIGN)
  160. struct txdesc {
  161. union {
  162. __u8 all[16];
  163. __le32 dw[4];
  164. struct {
  165. /* DW0 */
  166. __le16 vlan;
  167. __u8 rsv1;
  168. __u8 flags;
  169. /* DW1 */
  170. __le16 datalen;
  171. __le16 mss;
  172. /* DW2 */
  173. __le16 pktsize;
  174. __le16 rsv2;
  175. /* DW3 */
  176. __le32 bufaddr;
  177. } desc1;
  178. struct {
  179. /* DW0 */
  180. __le16 rsv1;
  181. __u8 rsv2;
  182. __u8 flags;
  183. /* DW1 */
  184. __le16 datalen;
  185. __le16 rsv3;
  186. /* DW2 */
  187. __le32 bufaddrh;
  188. /* DW3 */
  189. __le32 bufaddrl;
  190. } desc2;
  191. struct {
  192. /* DW0 */
  193. __u8 ehdrsz;
  194. __u8 rsv1;
  195. __u8 rsv2;
  196. __u8 flags;
  197. /* DW1 */
  198. __le16 trycnt;
  199. __le16 segcnt;
  200. /* DW2 */
  201. __le16 pktsz;
  202. __le16 rsv3;
  203. /* DW3 */
  204. __le32 bufaddrl;
  205. } descwb;
  206. };
  207. };
  208. enum jme_txdesc_flags_bits {
  209. TXFLAG_OWN = 0x80,
  210. TXFLAG_INT = 0x40,
  211. TXFLAG_64BIT = 0x20,
  212. TXFLAG_TCPCS = 0x10,
  213. TXFLAG_UDPCS = 0x08,
  214. TXFLAG_IPCS = 0x04,
  215. TXFLAG_LSEN = 0x02,
  216. TXFLAG_TAGON = 0x01,
  217. };
  218. #define TXDESC_MSS_SHIFT 2
  219. enum jme_txwbdesc_flags_bits {
  220. TXWBFLAG_OWN = 0x80,
  221. TXWBFLAG_INT = 0x40,
  222. TXWBFLAG_TMOUT = 0x20,
  223. TXWBFLAG_TRYOUT = 0x10,
  224. TXWBFLAG_COL = 0x08,
  225. TXWBFLAG_ALLERR = TXWBFLAG_TMOUT |
  226. TXWBFLAG_TRYOUT |
  227. TXWBFLAG_COL,
  228. };
  229. #define RX_DESC_SIZE 16
  230. #define RX_RING_NR 4
  231. #define RX_RING_ALLOC_SIZE(s) ((s * RX_DESC_SIZE) + RING_DESC_ALIGN)
  232. #define RX_BUF_DMA_ALIGN 8
  233. #define RX_PREPAD_SIZE 10
  234. #define ETH_CRC_LEN 2
  235. #define RX_VLANHDR_LEN 2
  236. #define RX_EXTRA_LEN (RX_PREPAD_SIZE + \
  237. ETH_HLEN + \
  238. ETH_CRC_LEN + \
  239. RX_VLANHDR_LEN + \
  240. RX_BUF_DMA_ALIGN)
  241. struct rxdesc {
  242. union {
  243. __u8 all[16];
  244. __le32 dw[4];
  245. struct {
  246. /* DW0 */
  247. __le16 rsv2;
  248. __u8 rsv1;
  249. __u8 flags;
  250. /* DW1 */
  251. __le16 datalen;
  252. __le16 wbcpl;
  253. /* DW2 */
  254. __le32 bufaddrh;
  255. /* DW3 */
  256. __le32 bufaddrl;
  257. } desc1;
  258. struct {
  259. /* DW0 */
  260. __le16 vlan;
  261. __le16 flags;
  262. /* DW1 */
  263. __le16 framesize;
  264. __u8 errstat;
  265. __u8 desccnt;
  266. /* DW2 */
  267. __le32 rsshash;
  268. /* DW3 */
  269. __u8 hashfun;
  270. __u8 hashtype;
  271. __le16 resrv;
  272. } descwb;
  273. };
  274. };
  275. enum jme_rxdesc_flags_bits {
  276. RXFLAG_OWN = 0x80,
  277. RXFLAG_INT = 0x40,
  278. RXFLAG_64BIT = 0x20,
  279. };
  280. enum jme_rxwbdesc_flags_bits {
  281. RXWBFLAG_OWN = 0x8000,
  282. RXWBFLAG_INT = 0x4000,
  283. RXWBFLAG_MF = 0x2000,
  284. RXWBFLAG_64BIT = 0x2000,
  285. RXWBFLAG_TCPON = 0x1000,
  286. RXWBFLAG_UDPON = 0x0800,
  287. RXWBFLAG_IPCS = 0x0400,
  288. RXWBFLAG_TCPCS = 0x0200,
  289. RXWBFLAG_UDPCS = 0x0100,
  290. RXWBFLAG_TAGON = 0x0080,
  291. RXWBFLAG_IPV4 = 0x0040,
  292. RXWBFLAG_IPV6 = 0x0020,
  293. RXWBFLAG_PAUSE = 0x0010,
  294. RXWBFLAG_MAGIC = 0x0008,
  295. RXWBFLAG_WAKEUP = 0x0004,
  296. RXWBFLAG_DEST = 0x0003,
  297. RXWBFLAG_DEST_UNI = 0x0001,
  298. RXWBFLAG_DEST_MUL = 0x0002,
  299. RXWBFLAG_DEST_BRO = 0x0003,
  300. };
  301. enum jme_rxwbdesc_desccnt_mask {
  302. RXWBDCNT_WBCPL = 0x80,
  303. RXWBDCNT_DCNT = 0x7F,
  304. };
  305. enum jme_rxwbdesc_errstat_bits {
  306. RXWBERR_LIMIT = 0x80,
  307. RXWBERR_MIIER = 0x40,
  308. RXWBERR_NIBON = 0x20,
  309. RXWBERR_COLON = 0x10,
  310. RXWBERR_ABORT = 0x08,
  311. RXWBERR_SHORT = 0x04,
  312. RXWBERR_OVERUN = 0x02,
  313. RXWBERR_CRCERR = 0x01,
  314. RXWBERR_ALLERR = 0xFF,
  315. };
  316. /*
  317. * Buffer information corresponding to ring descriptors.
  318. */
  319. struct jme_buffer_info {
  320. struct sk_buff *skb;
  321. dma_addr_t mapping;
  322. int len;
  323. int nr_desc;
  324. unsigned long start_xmit;
  325. };
  326. /*
  327. * The structure holding buffer information and ring descriptors all together.
  328. */
  329. struct jme_ring {
  330. void *alloc; /* pointer to allocated memory */
  331. void *desc; /* pointer to ring memory */
  332. dma_addr_t dmaalloc; /* phys address of ring alloc */
  333. dma_addr_t dma; /* phys address for ring dma */
  334. /* Buffer information corresponding to each descriptor */
  335. struct jme_buffer_info *bufinf;
  336. int next_to_use;
  337. atomic_t next_to_clean;
  338. atomic_t nr_free;
  339. };
  340. #define NET_STAT(priv) (priv->dev->stats)
  341. #define NETDEV_GET_STATS(netdev, fun_ptr)
  342. #define DECLARE_NET_DEVICE_STATS
  343. #define DECLARE_NAPI_STRUCT struct napi_struct napi;
  344. #define NETIF_NAPI_SET(dev, napis, pollfn, q) \
  345. netif_napi_add(dev, napis, pollfn, q);
  346. #define JME_NAPI_HOLDER(holder) struct napi_struct *holder
  347. #define JME_NAPI_WEIGHT(w) int w
  348. #define JME_NAPI_WEIGHT_VAL(w) w
  349. #define JME_NAPI_WEIGHT_SET(w, r)
  350. #define JME_RX_COMPLETE(dev, napis) napi_complete(napis)
  351. #define JME_NAPI_ENABLE(priv) napi_enable(&priv->napi);
  352. #define JME_NAPI_DISABLE(priv) \
  353. if (!napi_disable_pending(&priv->napi)) \
  354. napi_disable(&priv->napi);
  355. #define JME_RX_SCHEDULE_PREP(priv) \
  356. napi_schedule_prep(&priv->napi)
  357. #define JME_RX_SCHEDULE(priv) \
  358. __napi_schedule(&priv->napi);
  359. /*
  360. * Jmac Adapter Private data
  361. */
  362. struct jme_adapter {
  363. struct pci_dev *pdev;
  364. struct net_device *dev;
  365. void __iomem *regs;
  366. struct mii_if_info mii_if;
  367. struct jme_ring rxring[RX_RING_NR];
  368. struct jme_ring txring[TX_RING_NR];
  369. spinlock_t phy_lock;
  370. spinlock_t macaddr_lock;
  371. spinlock_t rxmcs_lock;
  372. struct tasklet_struct rxempty_task;
  373. struct tasklet_struct rxclean_task;
  374. struct tasklet_struct txclean_task;
  375. struct tasklet_struct linkch_task;
  376. struct tasklet_struct pcc_task;
  377. unsigned long flags;
  378. u32 reg_txcs;
  379. u32 reg_txpfc;
  380. u32 reg_rxcs;
  381. u32 reg_rxmcs;
  382. u32 reg_ghc;
  383. u32 reg_pmcs;
  384. u32 reg_gpreg1;
  385. u32 phylink;
  386. u32 tx_ring_size;
  387. u32 tx_ring_mask;
  388. u32 tx_wake_threshold;
  389. u32 rx_ring_size;
  390. u32 rx_ring_mask;
  391. u8 mrrs;
  392. unsigned int fpgaver;
  393. u8 chiprev;
  394. u8 chip_main_rev;
  395. u8 chip_sub_rev;
  396. u8 pcirev;
  397. u32 msg_enable;
  398. struct ethtool_cmd old_ecmd;
  399. unsigned int old_mtu;
  400. struct dynpcc_info dpi;
  401. atomic_t intr_sem;
  402. atomic_t link_changing;
  403. atomic_t tx_cleaning;
  404. atomic_t rx_cleaning;
  405. atomic_t rx_empty;
  406. int (*jme_rx)(struct sk_buff *skb);
  407. DECLARE_NAPI_STRUCT
  408. DECLARE_NET_DEVICE_STATS
  409. };
  410. enum jme_flags_bits {
  411. JME_FLAG_MSI = 1,
  412. JME_FLAG_SSET = 2,
  413. JME_FLAG_POLL = 5,
  414. JME_FLAG_SHUTDOWN = 6,
  415. };
  416. #define TX_TIMEOUT (5 * HZ)
  417. #define JME_REG_LEN 0x500
  418. #define MAX_ETHERNET_JUMBO_PACKET_SIZE 9216
  419. static inline struct jme_adapter*
  420. jme_napi_priv(struct napi_struct *napi)
  421. {
  422. struct jme_adapter *jme;
  423. jme = container_of(napi, struct jme_adapter, napi);
  424. return jme;
  425. }
  426. /*
  427. * MMaped I/O Resters
  428. */
  429. enum jme_iomap_offsets {
  430. JME_MAC = 0x0000,
  431. JME_PHY = 0x0400,
  432. JME_MISC = 0x0800,
  433. JME_RSS = 0x0C00,
  434. };
  435. enum jme_iomap_lens {
  436. JME_MAC_LEN = 0x80,
  437. JME_PHY_LEN = 0x58,
  438. JME_MISC_LEN = 0x98,
  439. JME_RSS_LEN = 0xFF,
  440. };
  441. enum jme_iomap_regs {
  442. JME_TXCS = JME_MAC | 0x00, /* Transmit Control and Status */
  443. JME_TXDBA_LO = JME_MAC | 0x04, /* Transmit Queue Desc Base Addr */
  444. JME_TXDBA_HI = JME_MAC | 0x08, /* Transmit Queue Desc Base Addr */
  445. JME_TXQDC = JME_MAC | 0x0C, /* Transmit Queue Desc Count */
  446. JME_TXNDA = JME_MAC | 0x10, /* Transmit Queue Next Desc Addr */
  447. JME_TXMCS = JME_MAC | 0x14, /* Transmit MAC Control Status */
  448. JME_TXPFC = JME_MAC | 0x18, /* Transmit Pause Frame Control */
  449. JME_TXTRHD = JME_MAC | 0x1C, /* Transmit Timer/Retry@Half-Dup */
  450. JME_RXCS = JME_MAC | 0x20, /* Receive Control and Status */
  451. JME_RXDBA_LO = JME_MAC | 0x24, /* Receive Queue Desc Base Addr */
  452. JME_RXDBA_HI = JME_MAC | 0x28, /* Receive Queue Desc Base Addr */
  453. JME_RXQDC = JME_MAC | 0x2C, /* Receive Queue Desc Count */
  454. JME_RXNDA = JME_MAC | 0x30, /* Receive Queue Next Desc Addr */
  455. JME_RXMCS = JME_MAC | 0x34, /* Receive MAC Control Status */
  456. JME_RXUMA_LO = JME_MAC | 0x38, /* Receive Unicast MAC Address */
  457. JME_RXUMA_HI = JME_MAC | 0x3C, /* Receive Unicast MAC Address */
  458. JME_RXMCHT_LO = JME_MAC | 0x40, /* Recv Multicast Addr HashTable */
  459. JME_RXMCHT_HI = JME_MAC | 0x44, /* Recv Multicast Addr HashTable */
  460. JME_WFODP = JME_MAC | 0x48, /* Wakeup Frame Output Data Port */
  461. JME_WFOI = JME_MAC | 0x4C, /* Wakeup Frame Output Interface */
  462. JME_SMI = JME_MAC | 0x50, /* Station Management Interface */
  463. JME_GHC = JME_MAC | 0x54, /* Global Host Control */
  464. JME_PMCS = JME_MAC | 0x60, /* Power Management Control/Stat */
  465. JME_PHY_PWR = JME_PHY | 0x24, /* New PHY Power Ctrl Register */
  466. JME_PHY_CS = JME_PHY | 0x28, /* PHY Ctrl and Status Register */
  467. JME_PHY_LINK = JME_PHY | 0x30, /* PHY Link Status Register */
  468. JME_SMBCSR = JME_PHY | 0x40, /* SMB Control and Status */
  469. JME_SMBINTF = JME_PHY | 0x44, /* SMB Interface */
  470. JME_TMCSR = JME_MISC | 0x00, /* Timer Control/Status Register */
  471. JME_GPREG0 = JME_MISC | 0x08, /* General purpose REG-0 */
  472. JME_GPREG1 = JME_MISC | 0x0C, /* General purpose REG-1 */
  473. JME_IEVE = JME_MISC | 0x20, /* Interrupt Event Status */
  474. JME_IREQ = JME_MISC | 0x24, /* Intr Req Status(For Debug) */
  475. JME_IENS = JME_MISC | 0x28, /* Intr Enable - Setting Port */
  476. JME_IENC = JME_MISC | 0x2C, /* Interrupt Enable - Clear Port */
  477. JME_PCCRX0 = JME_MISC | 0x30, /* PCC Control for RX Queue 0 */
  478. JME_PCCTX = JME_MISC | 0x40, /* PCC Control for TX Queues */
  479. JME_CHIPMODE = JME_MISC | 0x44, /* Identify FPGA Version */
  480. JME_SHBA_HI = JME_MISC | 0x48, /* Shadow Register Base HI */
  481. JME_SHBA_LO = JME_MISC | 0x4C, /* Shadow Register Base LO */
  482. JME_TIMER1 = JME_MISC | 0x70, /* Timer1 */
  483. JME_TIMER2 = JME_MISC | 0x74, /* Timer2 */
  484. JME_APMC = JME_MISC | 0x7C, /* Aggressive Power Mode Control */
  485. JME_PCCSRX0 = JME_MISC | 0x80, /* PCC Status of RX0 */
  486. };
  487. /*
  488. * TX Control/Status Bits
  489. */
  490. enum jme_txcs_bits {
  491. TXCS_QUEUE7S = 0x00008000,
  492. TXCS_QUEUE6S = 0x00004000,
  493. TXCS_QUEUE5S = 0x00002000,
  494. TXCS_QUEUE4S = 0x00001000,
  495. TXCS_QUEUE3S = 0x00000800,
  496. TXCS_QUEUE2S = 0x00000400,
  497. TXCS_QUEUE1S = 0x00000200,
  498. TXCS_QUEUE0S = 0x00000100,
  499. TXCS_FIFOTH = 0x000000C0,
  500. TXCS_DMASIZE = 0x00000030,
  501. TXCS_BURST = 0x00000004,
  502. TXCS_ENABLE = 0x00000001,
  503. };
  504. enum jme_txcs_value {
  505. TXCS_FIFOTH_16QW = 0x000000C0,
  506. TXCS_FIFOTH_12QW = 0x00000080,
  507. TXCS_FIFOTH_8QW = 0x00000040,
  508. TXCS_FIFOTH_4QW = 0x00000000,
  509. TXCS_DMASIZE_64B = 0x00000000,
  510. TXCS_DMASIZE_128B = 0x00000010,
  511. TXCS_DMASIZE_256B = 0x00000020,
  512. TXCS_DMASIZE_512B = 0x00000030,
  513. TXCS_SELECT_QUEUE0 = 0x00000000,
  514. TXCS_SELECT_QUEUE1 = 0x00010000,
  515. TXCS_SELECT_QUEUE2 = 0x00020000,
  516. TXCS_SELECT_QUEUE3 = 0x00030000,
  517. TXCS_SELECT_QUEUE4 = 0x00040000,
  518. TXCS_SELECT_QUEUE5 = 0x00050000,
  519. TXCS_SELECT_QUEUE6 = 0x00060000,
  520. TXCS_SELECT_QUEUE7 = 0x00070000,
  521. TXCS_DEFAULT = TXCS_FIFOTH_4QW |
  522. TXCS_BURST,
  523. };
  524. #define JME_TX_DISABLE_TIMEOUT 10 /* 10 msec */
  525. /*
  526. * TX MAC Control/Status Bits
  527. */
  528. enum jme_txmcs_bit_masks {
  529. TXMCS_IFG2 = 0xC0000000,
  530. TXMCS_IFG1 = 0x30000000,
  531. TXMCS_TTHOLD = 0x00000300,
  532. TXMCS_FBURST = 0x00000080,
  533. TXMCS_CARRIEREXT = 0x00000040,
  534. TXMCS_DEFER = 0x00000020,
  535. TXMCS_BACKOFF = 0x00000010,
  536. TXMCS_CARRIERSENSE = 0x00000008,
  537. TXMCS_COLLISION = 0x00000004,
  538. TXMCS_CRC = 0x00000002,
  539. TXMCS_PADDING = 0x00000001,
  540. };
  541. enum jme_txmcs_values {
  542. TXMCS_IFG2_6_4 = 0x00000000,
  543. TXMCS_IFG2_8_5 = 0x40000000,
  544. TXMCS_IFG2_10_6 = 0x80000000,
  545. TXMCS_IFG2_12_7 = 0xC0000000,
  546. TXMCS_IFG1_8_4 = 0x00000000,
  547. TXMCS_IFG1_12_6 = 0x10000000,
  548. TXMCS_IFG1_16_8 = 0x20000000,
  549. TXMCS_IFG1_20_10 = 0x30000000,
  550. TXMCS_TTHOLD_1_8 = 0x00000000,
  551. TXMCS_TTHOLD_1_4 = 0x00000100,
  552. TXMCS_TTHOLD_1_2 = 0x00000200,
  553. TXMCS_TTHOLD_FULL = 0x00000300,
  554. TXMCS_DEFAULT = TXMCS_IFG2_8_5 |
  555. TXMCS_IFG1_16_8 |
  556. TXMCS_TTHOLD_FULL |
  557. TXMCS_DEFER |
  558. TXMCS_CRC |
  559. TXMCS_PADDING,
  560. };
  561. enum jme_txpfc_bits_masks {
  562. TXPFC_VLAN_TAG = 0xFFFF0000,
  563. TXPFC_VLAN_EN = 0x00008000,
  564. TXPFC_PF_EN = 0x00000001,
  565. };
  566. enum jme_txtrhd_bits_masks {
  567. TXTRHD_TXPEN = 0x80000000,
  568. TXTRHD_TXP = 0x7FFFFF00,
  569. TXTRHD_TXREN = 0x00000080,
  570. TXTRHD_TXRL = 0x0000007F,
  571. };
  572. enum jme_txtrhd_shifts {
  573. TXTRHD_TXP_SHIFT = 8,
  574. TXTRHD_TXRL_SHIFT = 0,
  575. };
  576. enum jme_txtrhd_values {
  577. TXTRHD_FULLDUPLEX = 0x00000000,
  578. TXTRHD_HALFDUPLEX = TXTRHD_TXPEN |
  579. ((0x2000 << TXTRHD_TXP_SHIFT) & TXTRHD_TXP) |
  580. TXTRHD_TXREN |
  581. ((8 << TXTRHD_TXRL_SHIFT) & TXTRHD_TXRL),
  582. };
  583. /*
  584. * RX Control/Status Bits
  585. */
  586. enum jme_rxcs_bit_masks {
  587. /* FIFO full threshold for transmitting Tx Pause Packet */
  588. RXCS_FIFOTHTP = 0x30000000,
  589. /* FIFO threshold for processing next packet */
  590. RXCS_FIFOTHNP = 0x0C000000,
  591. RXCS_DMAREQSZ = 0x03000000, /* DMA Request Size */
  592. RXCS_QUEUESEL = 0x00030000, /* Queue selection */
  593. RXCS_RETRYGAP = 0x0000F000, /* RX Desc full retry gap */
  594. RXCS_RETRYCNT = 0x00000F00, /* RX Desc full retry counter */
  595. RXCS_WAKEUP = 0x00000040, /* Enable receive wakeup packet */
  596. RXCS_MAGIC = 0x00000020, /* Enable receive magic packet */
  597. RXCS_SHORT = 0x00000010, /* Enable receive short packet */
  598. RXCS_ABORT = 0x00000008, /* Enable receive errorr packet */
  599. RXCS_QST = 0x00000004, /* Receive queue start */
  600. RXCS_SUSPEND = 0x00000002,
  601. RXCS_ENABLE = 0x00000001,
  602. };
  603. enum jme_rxcs_values {
  604. RXCS_FIFOTHTP_16T = 0x00000000,
  605. RXCS_FIFOTHTP_32T = 0x10000000,
  606. RXCS_FIFOTHTP_64T = 0x20000000,
  607. RXCS_FIFOTHTP_128T = 0x30000000,
  608. RXCS_FIFOTHNP_16QW = 0x00000000,
  609. RXCS_FIFOTHNP_32QW = 0x04000000,
  610. RXCS_FIFOTHNP_64QW = 0x08000000,
  611. RXCS_FIFOTHNP_128QW = 0x0C000000,
  612. RXCS_DMAREQSZ_16B = 0x00000000,
  613. RXCS_DMAREQSZ_32B = 0x01000000,
  614. RXCS_DMAREQSZ_64B = 0x02000000,
  615. RXCS_DMAREQSZ_128B = 0x03000000,
  616. RXCS_QUEUESEL_Q0 = 0x00000000,
  617. RXCS_QUEUESEL_Q1 = 0x00010000,
  618. RXCS_QUEUESEL_Q2 = 0x00020000,
  619. RXCS_QUEUESEL_Q3 = 0x00030000,
  620. RXCS_RETRYGAP_256ns = 0x00000000,
  621. RXCS_RETRYGAP_512ns = 0x00001000,
  622. RXCS_RETRYGAP_1024ns = 0x00002000,
  623. RXCS_RETRYGAP_2048ns = 0x00003000,
  624. RXCS_RETRYGAP_4096ns = 0x00004000,
  625. RXCS_RETRYGAP_8192ns = 0x00005000,
  626. RXCS_RETRYGAP_16384ns = 0x00006000,
  627. RXCS_RETRYGAP_32768ns = 0x00007000,
  628. RXCS_RETRYCNT_0 = 0x00000000,
  629. RXCS_RETRYCNT_4 = 0x00000100,
  630. RXCS_RETRYCNT_8 = 0x00000200,
  631. RXCS_RETRYCNT_12 = 0x00000300,
  632. RXCS_RETRYCNT_16 = 0x00000400,
  633. RXCS_RETRYCNT_20 = 0x00000500,
  634. RXCS_RETRYCNT_24 = 0x00000600,
  635. RXCS_RETRYCNT_28 = 0x00000700,
  636. RXCS_RETRYCNT_32 = 0x00000800,
  637. RXCS_RETRYCNT_36 = 0x00000900,
  638. RXCS_RETRYCNT_40 = 0x00000A00,
  639. RXCS_RETRYCNT_44 = 0x00000B00,
  640. RXCS_RETRYCNT_48 = 0x00000C00,
  641. RXCS_RETRYCNT_52 = 0x00000D00,
  642. RXCS_RETRYCNT_56 = 0x00000E00,
  643. RXCS_RETRYCNT_60 = 0x00000F00,
  644. RXCS_DEFAULT = RXCS_FIFOTHTP_128T |
  645. RXCS_FIFOTHNP_16QW |
  646. RXCS_DMAREQSZ_128B |
  647. RXCS_RETRYGAP_256ns |
  648. RXCS_RETRYCNT_32,
  649. };
  650. #define JME_RX_DISABLE_TIMEOUT 10 /* 10 msec */
  651. /*
  652. * RX MAC Control/Status Bits
  653. */
  654. enum jme_rxmcs_bits {
  655. RXMCS_ALLFRAME = 0x00000800,
  656. RXMCS_BRDFRAME = 0x00000400,
  657. RXMCS_MULFRAME = 0x00000200,
  658. RXMCS_UNIFRAME = 0x00000100,
  659. RXMCS_ALLMULFRAME = 0x00000080,
  660. RXMCS_MULFILTERED = 0x00000040,
  661. RXMCS_RXCOLLDEC = 0x00000020,
  662. RXMCS_FLOWCTRL = 0x00000008,
  663. RXMCS_VTAGRM = 0x00000004,
  664. RXMCS_PREPAD = 0x00000002,
  665. RXMCS_CHECKSUM = 0x00000001,
  666. RXMCS_DEFAULT = RXMCS_VTAGRM |
  667. RXMCS_PREPAD |
  668. RXMCS_FLOWCTRL |
  669. RXMCS_CHECKSUM,
  670. };
  671. /* Extern PHY common register 2 */
  672. #define PHY_GAD_TEST_MODE_1 0x00002000
  673. #define PHY_GAD_TEST_MODE_MSK 0x0000E000
  674. #define JM_PHY_SPEC_REG_READ 0x00004000
  675. #define JM_PHY_SPEC_REG_WRITE 0x00008000
  676. #define PHY_CALIBRATION_DELAY 20
  677. #define JM_PHY_SPEC_ADDR_REG 0x1E
  678. #define JM_PHY_SPEC_DATA_REG 0x1F
  679. #define JM_PHY_EXT_COMM_0_REG 0x30
  680. #define JM_PHY_EXT_COMM_1_REG 0x31
  681. #define JM_PHY_EXT_COMM_2_REG 0x32
  682. #define JM_PHY_EXT_COMM_2_CALI_ENABLE 0x01
  683. #define JM_PHY_EXT_COMM_2_CALI_MODE_0 0x02
  684. #define JM_PHY_EXT_COMM_2_CALI_LATCH 0x10
  685. #define PCI_PRIV_SHARE_NICCTRL 0xF5
  686. #define JME_FLAG_PHYEA_ENABLE 0x2
  687. /*
  688. * Wakeup Frame setup interface registers
  689. */
  690. #define WAKEUP_FRAME_NR 8
  691. #define WAKEUP_FRAME_MASK_DWNR 4
  692. enum jme_wfoi_bit_masks {
  693. WFOI_MASK_SEL = 0x00000070,
  694. WFOI_CRC_SEL = 0x00000008,
  695. WFOI_FRAME_SEL = 0x00000007,
  696. };
  697. enum jme_wfoi_shifts {
  698. WFOI_MASK_SHIFT = 4,
  699. };
  700. /*
  701. * SMI Related definitions
  702. */
  703. enum jme_smi_bit_mask {
  704. SMI_DATA_MASK = 0xFFFF0000,
  705. SMI_REG_ADDR_MASK = 0x0000F800,
  706. SMI_PHY_ADDR_MASK = 0x000007C0,
  707. SMI_OP_WRITE = 0x00000020,
  708. /* Set to 1, after req done it'll be cleared to 0 */
  709. SMI_OP_REQ = 0x00000010,
  710. SMI_OP_MDIO = 0x00000008, /* Software assess In/Out */
  711. SMI_OP_MDOE = 0x00000004, /* Software Output Enable */
  712. SMI_OP_MDC = 0x00000002, /* Software CLK Control */
  713. SMI_OP_MDEN = 0x00000001, /* Software access Enable */
  714. };
  715. enum jme_smi_bit_shift {
  716. SMI_DATA_SHIFT = 16,
  717. SMI_REG_ADDR_SHIFT = 11,
  718. SMI_PHY_ADDR_SHIFT = 6,
  719. };
  720. static inline u32 smi_reg_addr(int x)
  721. {
  722. return (x << SMI_REG_ADDR_SHIFT) & SMI_REG_ADDR_MASK;
  723. }
  724. static inline u32 smi_phy_addr(int x)
  725. {
  726. return (x << SMI_PHY_ADDR_SHIFT) & SMI_PHY_ADDR_MASK;
  727. }
  728. #define JME_PHY_TIMEOUT 100 /* 100 msec */
  729. #define JME_PHY_REG_NR 32
  730. /*
  731. * Global Host Control
  732. */
  733. enum jme_ghc_bit_mask {
  734. GHC_SWRST = 0x40000000,
  735. GHC_TO_CLK_SRC = 0x00C00000,
  736. GHC_TXMAC_CLK_SRC = 0x00300000,
  737. GHC_DPX = 0x00000040,
  738. GHC_SPEED = 0x00000030,
  739. GHC_LINK_POLL = 0x00000001,
  740. };
  741. enum jme_ghc_speed_val {
  742. GHC_SPEED_10M = 0x00000010,
  743. GHC_SPEED_100M = 0x00000020,
  744. GHC_SPEED_1000M = 0x00000030,
  745. };
  746. enum jme_ghc_to_clk {
  747. GHC_TO_CLK_OFF = 0x00000000,
  748. GHC_TO_CLK_GPHY = 0x00400000,
  749. GHC_TO_CLK_PCIE = 0x00800000,
  750. GHC_TO_CLK_INVALID = 0x00C00000,
  751. };
  752. enum jme_ghc_txmac_clk {
  753. GHC_TXMAC_CLK_OFF = 0x00000000,
  754. GHC_TXMAC_CLK_GPHY = 0x00100000,
  755. GHC_TXMAC_CLK_PCIE = 0x00200000,
  756. GHC_TXMAC_CLK_INVALID = 0x00300000,
  757. };
  758. /*
  759. * Power management control and status register
  760. */
  761. enum jme_pmcs_bit_masks {
  762. PMCS_STMASK = 0xFFFF0000,
  763. PMCS_WF7DET = 0x80000000,
  764. PMCS_WF6DET = 0x40000000,
  765. PMCS_WF5DET = 0x20000000,
  766. PMCS_WF4DET = 0x10000000,
  767. PMCS_WF3DET = 0x08000000,
  768. PMCS_WF2DET = 0x04000000,
  769. PMCS_WF1DET = 0x02000000,
  770. PMCS_WF0DET = 0x01000000,
  771. PMCS_LFDET = 0x00040000,
  772. PMCS_LRDET = 0x00020000,
  773. PMCS_MFDET = 0x00010000,
  774. PMCS_ENMASK = 0x0000FFFF,
  775. PMCS_WF7EN = 0x00008000,
  776. PMCS_WF6EN = 0x00004000,
  777. PMCS_WF5EN = 0x00002000,
  778. PMCS_WF4EN = 0x00001000,
  779. PMCS_WF3EN = 0x00000800,
  780. PMCS_WF2EN = 0x00000400,
  781. PMCS_WF1EN = 0x00000200,
  782. PMCS_WF0EN = 0x00000100,
  783. PMCS_LFEN = 0x00000004,
  784. PMCS_LREN = 0x00000002,
  785. PMCS_MFEN = 0x00000001,
  786. };
  787. /*
  788. * New PHY Power Control Register
  789. */
  790. enum jme_phy_pwr_bit_masks {
  791. PHY_PWR_DWN1SEL = 0x01000000, /* Phy_giga.p_PWR_DOWN1_SEL */
  792. PHY_PWR_DWN1SW = 0x02000000, /* Phy_giga.p_PWR_DOWN1_SW */
  793. PHY_PWR_DWN2 = 0x04000000, /* Phy_giga.p_PWR_DOWN2 */
  794. PHY_PWR_CLKSEL = 0x08000000, /*
  795. * XTL_OUT Clock select
  796. * (an internal free-running clock)
  797. * 0: xtl_out = phy_giga.A_XTL25_O
  798. * 1: xtl_out = phy_giga.PD_OSC
  799. */
  800. };
  801. /*
  802. * Giga PHY Status Registers
  803. */
  804. enum jme_phy_link_bit_mask {
  805. PHY_LINK_SPEED_MASK = 0x0000C000,
  806. PHY_LINK_DUPLEX = 0x00002000,
  807. PHY_LINK_SPEEDDPU_RESOLVED = 0x00000800,
  808. PHY_LINK_UP = 0x00000400,
  809. PHY_LINK_AUTONEG_COMPLETE = 0x00000200,
  810. PHY_LINK_MDI_STAT = 0x00000040,
  811. };
  812. enum jme_phy_link_speed_val {
  813. PHY_LINK_SPEED_10M = 0x00000000,
  814. PHY_LINK_SPEED_100M = 0x00004000,
  815. PHY_LINK_SPEED_1000M = 0x00008000,
  816. };
  817. #define JME_SPDRSV_TIMEOUT 500 /* 500 us */
  818. /*
  819. * SMB Control and Status
  820. */
  821. enum jme_smbcsr_bit_mask {
  822. SMBCSR_CNACK = 0x00020000,
  823. SMBCSR_RELOAD = 0x00010000,
  824. SMBCSR_EEPROMD = 0x00000020,
  825. SMBCSR_INITDONE = 0x00000010,
  826. SMBCSR_BUSY = 0x0000000F,
  827. };
  828. enum jme_smbintf_bit_mask {
  829. SMBINTF_HWDATR = 0xFF000000,
  830. SMBINTF_HWDATW = 0x00FF0000,
  831. SMBINTF_HWADDR = 0x0000FF00,
  832. SMBINTF_HWRWN = 0x00000020,
  833. SMBINTF_HWCMD = 0x00000010,
  834. SMBINTF_FASTM = 0x00000008,
  835. SMBINTF_GPIOSCL = 0x00000004,
  836. SMBINTF_GPIOSDA = 0x00000002,
  837. SMBINTF_GPIOEN = 0x00000001,
  838. };
  839. enum jme_smbintf_vals {
  840. SMBINTF_HWRWN_READ = 0x00000020,
  841. SMBINTF_HWRWN_WRITE = 0x00000000,
  842. };
  843. enum jme_smbintf_shifts {
  844. SMBINTF_HWDATR_SHIFT = 24,
  845. SMBINTF_HWDATW_SHIFT = 16,
  846. SMBINTF_HWADDR_SHIFT = 8,
  847. };
  848. #define JME_EEPROM_RELOAD_TIMEOUT 2000 /* 2000 msec */
  849. #define JME_SMB_BUSY_TIMEOUT 20 /* 20 msec */
  850. #define JME_SMB_LEN 256
  851. #define JME_EEPROM_MAGIC 0x250
  852. /*
  853. * Timer Control/Status Register
  854. */
  855. enum jme_tmcsr_bit_masks {
  856. TMCSR_SWIT = 0x80000000,
  857. TMCSR_EN = 0x01000000,
  858. TMCSR_CNT = 0x00FFFFFF,
  859. };
  860. /*
  861. * General Purpose REG-0
  862. */
  863. enum jme_gpreg0_masks {
  864. GPREG0_DISSH = 0xFF000000,
  865. GPREG0_PCIRLMT = 0x00300000,
  866. GPREG0_PCCNOMUTCLR = 0x00040000,
  867. GPREG0_LNKINTPOLL = 0x00001000,
  868. GPREG0_PCCTMR = 0x00000300,
  869. GPREG0_PHYADDR = 0x0000001F,
  870. };
  871. enum jme_gpreg0_vals {
  872. GPREG0_DISSH_DW7 = 0x80000000,
  873. GPREG0_DISSH_DW6 = 0x40000000,
  874. GPREG0_DISSH_DW5 = 0x20000000,
  875. GPREG0_DISSH_DW4 = 0x10000000,
  876. GPREG0_DISSH_DW3 = 0x08000000,
  877. GPREG0_DISSH_DW2 = 0x04000000,
  878. GPREG0_DISSH_DW1 = 0x02000000,
  879. GPREG0_DISSH_DW0 = 0x01000000,
  880. GPREG0_DISSH_ALL = 0xFF000000,
  881. GPREG0_PCIRLMT_8 = 0x00000000,
  882. GPREG0_PCIRLMT_6 = 0x00100000,
  883. GPREG0_PCIRLMT_5 = 0x00200000,
  884. GPREG0_PCIRLMT_4 = 0x00300000,
  885. GPREG0_PCCTMR_16ns = 0x00000000,
  886. GPREG0_PCCTMR_256ns = 0x00000100,
  887. GPREG0_PCCTMR_1us = 0x00000200,
  888. GPREG0_PCCTMR_1ms = 0x00000300,
  889. GPREG0_PHYADDR_1 = 0x00000001,
  890. GPREG0_DEFAULT = GPREG0_PCIRLMT_4 |
  891. GPREG0_PCCTMR_1us |
  892. GPREG0_PHYADDR_1,
  893. };
  894. /*
  895. * General Purpose REG-1
  896. */
  897. enum jme_gpreg1_bit_masks {
  898. GPREG1_RXCLKOFF = 0x04000000,
  899. GPREG1_PCREQN = 0x00020000,
  900. GPREG1_HALFMODEPATCH = 0x00000040, /* For Chip revision 0x11 only */
  901. GPREG1_RSSPATCH = 0x00000020, /* For Chip revision 0x11 only */
  902. GPREG1_INTRDELAYUNIT = 0x00000018,
  903. GPREG1_INTRDELAYENABLE = 0x00000007,
  904. };
  905. enum jme_gpreg1_vals {
  906. GPREG1_INTDLYUNIT_16NS = 0x00000000,
  907. GPREG1_INTDLYUNIT_256NS = 0x00000008,
  908. GPREG1_INTDLYUNIT_1US = 0x00000010,
  909. GPREG1_INTDLYUNIT_16US = 0x00000018,
  910. GPREG1_INTDLYEN_1U = 0x00000001,
  911. GPREG1_INTDLYEN_2U = 0x00000002,
  912. GPREG1_INTDLYEN_3U = 0x00000003,
  913. GPREG1_INTDLYEN_4U = 0x00000004,
  914. GPREG1_INTDLYEN_5U = 0x00000005,
  915. GPREG1_INTDLYEN_6U = 0x00000006,
  916. GPREG1_INTDLYEN_7U = 0x00000007,
  917. GPREG1_DEFAULT = GPREG1_PCREQN,
  918. };
  919. /*
  920. * Interrupt Status Bits
  921. */
  922. enum jme_interrupt_bits {
  923. INTR_SWINTR = 0x80000000,
  924. INTR_TMINTR = 0x40000000,
  925. INTR_LINKCH = 0x20000000,
  926. INTR_PAUSERCV = 0x10000000,
  927. INTR_MAGICRCV = 0x08000000,
  928. INTR_WAKERCV = 0x04000000,
  929. INTR_PCCRX0TO = 0x02000000,
  930. INTR_PCCRX1TO = 0x01000000,
  931. INTR_PCCRX2TO = 0x00800000,
  932. INTR_PCCRX3TO = 0x00400000,
  933. INTR_PCCTXTO = 0x00200000,
  934. INTR_PCCRX0 = 0x00100000,
  935. INTR_PCCRX1 = 0x00080000,
  936. INTR_PCCRX2 = 0x00040000,
  937. INTR_PCCRX3 = 0x00020000,
  938. INTR_PCCTX = 0x00010000,
  939. INTR_RX3EMP = 0x00008000,
  940. INTR_RX2EMP = 0x00004000,
  941. INTR_RX1EMP = 0x00002000,
  942. INTR_RX0EMP = 0x00001000,
  943. INTR_RX3 = 0x00000800,
  944. INTR_RX2 = 0x00000400,
  945. INTR_RX1 = 0x00000200,
  946. INTR_RX0 = 0x00000100,
  947. INTR_TX7 = 0x00000080,
  948. INTR_TX6 = 0x00000040,
  949. INTR_TX5 = 0x00000020,
  950. INTR_TX4 = 0x00000010,
  951. INTR_TX3 = 0x00000008,
  952. INTR_TX2 = 0x00000004,
  953. INTR_TX1 = 0x00000002,
  954. INTR_TX0 = 0x00000001,
  955. };
  956. static const u32 INTR_ENABLE = INTR_SWINTR |
  957. INTR_TMINTR |
  958. INTR_LINKCH |
  959. INTR_PCCRX0TO |
  960. INTR_PCCRX0 |
  961. INTR_PCCTXTO |
  962. INTR_PCCTX |
  963. INTR_RX0EMP;
  964. /*
  965. * PCC Control Registers
  966. */
  967. enum jme_pccrx_masks {
  968. PCCRXTO_MASK = 0xFFFF0000,
  969. PCCRX_MASK = 0x0000FF00,
  970. };
  971. enum jme_pcctx_masks {
  972. PCCTXTO_MASK = 0xFFFF0000,
  973. PCCTX_MASK = 0x0000FF00,
  974. PCCTX_QS_MASK = 0x000000FF,
  975. };
  976. enum jme_pccrx_shifts {
  977. PCCRXTO_SHIFT = 16,
  978. PCCRX_SHIFT = 8,
  979. };
  980. enum jme_pcctx_shifts {
  981. PCCTXTO_SHIFT = 16,
  982. PCCTX_SHIFT = 8,
  983. };
  984. enum jme_pcctx_bits {
  985. PCCTXQ0_EN = 0x00000001,
  986. PCCTXQ1_EN = 0x00000002,
  987. PCCTXQ2_EN = 0x00000004,
  988. PCCTXQ3_EN = 0x00000008,
  989. PCCTXQ4_EN = 0x00000010,
  990. PCCTXQ5_EN = 0x00000020,
  991. PCCTXQ6_EN = 0x00000040,
  992. PCCTXQ7_EN = 0x00000080,
  993. };
  994. /*
  995. * Chip Mode Register
  996. */
  997. enum jme_chipmode_bit_masks {
  998. CM_FPGAVER_MASK = 0xFFFF0000,
  999. CM_CHIPREV_MASK = 0x0000FF00,
  1000. CM_CHIPMODE_MASK = 0x0000000F,
  1001. };
  1002. enum jme_chipmode_shifts {
  1003. CM_FPGAVER_SHIFT = 16,
  1004. CM_CHIPREV_SHIFT = 8,
  1005. };
  1006. /*
  1007. * Aggressive Power Mode Control
  1008. */
  1009. enum jme_apmc_bits {
  1010. JME_APMC_PCIE_SD_EN = 0x40000000,
  1011. JME_APMC_PSEUDO_HP_EN = 0x20000000,
  1012. JME_APMC_EPIEN = 0x04000000,
  1013. JME_APMC_EPIEN_CTRL = 0x03000000,
  1014. };
  1015. enum jme_apmc_values {
  1016. JME_APMC_EPIEN_CTRL_EN = 0x02000000,
  1017. JME_APMC_EPIEN_CTRL_DIS = 0x01000000,
  1018. };
  1019. #define APMC_PHP_SHUTDOWN_DELAY (10 * 1000 * 1000)
  1020. #ifdef REG_DEBUG
  1021. static char *MAC_REG_NAME[] = {
  1022. "JME_TXCS", "JME_TXDBA_LO", "JME_TXDBA_HI", "JME_TXQDC",
  1023. "JME_TXNDA", "JME_TXMCS", "JME_TXPFC", "JME_TXTRHD",
  1024. "JME_RXCS", "JME_RXDBA_LO", "JME_RXDBA_HI", "JME_RXQDC",
  1025. "JME_RXNDA", "JME_RXMCS", "JME_RXUMA_LO", "JME_RXUMA_HI",
  1026. "JME_RXMCHT_LO", "JME_RXMCHT_HI", "JME_WFODP", "JME_WFOI",
  1027. "JME_SMI", "JME_GHC", "UNKNOWN", "UNKNOWN",
  1028. "JME_PMCS"};
  1029. static char *PE_REG_NAME[] = {
  1030. "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
  1031. "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
  1032. "UNKNOWN", "UNKNOWN", "JME_PHY_CS", "UNKNOWN",
  1033. "JME_PHY_LINK", "UNKNOWN", "UNKNOWN", "UNKNOWN",
  1034. "JME_SMBCSR", "JME_SMBINTF"};
  1035. static char *MISC_REG_NAME[] = {
  1036. "JME_TMCSR", "JME_GPIO", "JME_GPREG0", "JME_GPREG1",
  1037. "JME_IEVE", "JME_IREQ", "JME_IENS", "JME_IENC",
  1038. "JME_PCCRX0", "JME_PCCRX1", "JME_PCCRX2", "JME_PCCRX3",
  1039. "JME_PCCTX0", "JME_CHIPMODE", "JME_SHBA_HI", "JME_SHBA_LO",
  1040. "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
  1041. "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
  1042. "UNKNOWN", "UNKNOWN", "UNKNOWN", "UNKNOWN",
  1043. "JME_TIMER1", "JME_TIMER2", "UNKNOWN", "JME_APMC",
  1044. "JME_PCCSRX0"};
  1045. static inline void reg_dbg(const struct jme_adapter *jme,
  1046. const char *msg, u32 val, u32 reg)
  1047. {
  1048. const char *regname;
  1049. switch (reg & 0xF00) {
  1050. case 0x000:
  1051. regname = MAC_REG_NAME[(reg & 0xFF) >> 2];
  1052. break;
  1053. case 0x400:
  1054. regname = PE_REG_NAME[(reg & 0xFF) >> 2];
  1055. break;
  1056. case 0x800:
  1057. regname = MISC_REG_NAME[(reg & 0xFF) >> 2];
  1058. break;
  1059. default:
  1060. regname = PE_REG_NAME[0];
  1061. }
  1062. printk(KERN_DEBUG "%s: %-20s %08x@%s\n", jme->dev->name,
  1063. msg, val, regname);
  1064. }
  1065. #else
  1066. static inline void reg_dbg(const struct jme_adapter *jme,
  1067. const char *msg, u32 val, u32 reg) {}
  1068. #endif
  1069. /*
  1070. * Read/Write MMaped I/O Registers
  1071. */
  1072. static inline u32 jread32(struct jme_adapter *jme, u32 reg)
  1073. {
  1074. return readl(jme->regs + reg);
  1075. }
  1076. static inline void jwrite32(struct jme_adapter *jme, u32 reg, u32 val)
  1077. {
  1078. reg_dbg(jme, "REG WRITE", val, reg);
  1079. writel(val, jme->regs + reg);
  1080. reg_dbg(jme, "VAL AFTER WRITE", readl(jme->regs + reg), reg);
  1081. }
  1082. static inline void jwrite32f(struct jme_adapter *jme, u32 reg, u32 val)
  1083. {
  1084. /*
  1085. * Read after write should cause flush
  1086. */
  1087. reg_dbg(jme, "REG WRITE FLUSH", val, reg);
  1088. writel(val, jme->regs + reg);
  1089. readl(jme->regs + reg);
  1090. reg_dbg(jme, "VAL AFTER WRITE", readl(jme->regs + reg), reg);
  1091. }
  1092. /*
  1093. * PHY Regs
  1094. */
  1095. enum jme_phy_reg17_bit_masks {
  1096. PREG17_SPEED = 0xC000,
  1097. PREG17_DUPLEX = 0x2000,
  1098. PREG17_SPDRSV = 0x0800,
  1099. PREG17_LNKUP = 0x0400,
  1100. PREG17_MDI = 0x0040,
  1101. };
  1102. enum jme_phy_reg17_vals {
  1103. PREG17_SPEED_10M = 0x0000,
  1104. PREG17_SPEED_100M = 0x4000,
  1105. PREG17_SPEED_1000M = 0x8000,
  1106. };
  1107. #define BMSR_ANCOMP 0x0020
  1108. /*
  1109. * Workaround
  1110. */
  1111. static inline int is_buggy250(unsigned short device, u8 chiprev)
  1112. {
  1113. return device == PCI_DEVICE_ID_JMICRON_JMC250 && chiprev == 0x11;
  1114. }
  1115. static inline int new_phy_power_ctrl(u8 chip_main_rev)
  1116. {
  1117. return chip_main_rev >= 5;
  1118. }
  1119. /*
  1120. * Function prototypes
  1121. */
  1122. static int jme_set_settings(struct net_device *netdev,
  1123. struct ethtool_cmd *ecmd);
  1124. static void jme_set_unicastaddr(struct net_device *netdev);
  1125. static void jme_set_multi(struct net_device *netdev);
  1126. #endif