blob: d6b60e65bcf91bc47d8d206cb1a2fac22629bcbf [file] [log] [blame]
Roy Zangbafd8032012-10-08 07:44:21 +00001/*
2 * Copyright 2012 Freescale Semiconductor, Inc.
3 * Roy Zang <tie-fei.zang@freescale.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
19 */
20
21#ifndef __MEMAC_H__
22#define __MEMAC_H__
23
24#include <phy.h>
25
26struct memac {
27 /* memac general control and status registers */
28 u32 res_0[2];
29 u32 command_config; /* Control and configuration register */
30 u32 mac_addr_0; /* Lower 32 bits of 48-bit MAC address */
31 u32 mac_addr_1; /* Upper 16 bits of 48-bit MAC address */
32 u32 maxfrm; /* Maximum frame length register */
33 u32 res_18[5];
34 u32 hashtable_ctrl; /* Hash table control register */
35 u32 res_30[4];
36 u32 ievent; /* Interrupt event register */
37 u32 tx_ipg_length; /* Transmitter inter-packet-gap register */
38 u32 res_48;
39 u32 imask; /* interrupt mask register */
40 u32 res_50;
41 u32 cl_pause_quanta[4]; /* CL01-CL67 pause quanta register */
42 u32 cl_pause_thresh[4]; /* CL01-CL67 pause thresh register */
43 u32 rx_pause_status; /* Receive pause status register */
44 u32 res_78[2];
45 u32 mac_addr[14]; /* MAC address */
46 u32 lpwake_timer; /* EEE low power wakeup timer register */
47 u32 sleep_timer; /* Transmit EEE Low Power Timer register */
48 u32 res_c0[8];
49 u32 statn_config; /* Statistics configuration register */
50 u32 res_e4[7];
51
52 /* memac statistics counter registers */
53 u32 rx_eoct_l; /* Rx ethernet octests lower */
54 u32 rx_eoct_u; /* Rx ethernet octests upper */
55 u32 rx_oct_l; /* Rx octests lower */
56 u32 rx_oct_u; /* Rx octests upper */
57 u32 rx_align_err_l; /* Rx alignment error lower */
58 u32 rx_align_err_u; /* Rx alignment error upper */
59 u32 rx_pause_frame_l; /* Rx valid pause frame upper */
60 u32 rx_pause_frame_u; /* Rx valid pause frame upper */
61 u32 rx_frame_l; /* Rx frame counter lower */
62 u32 rx_frame_u; /* Rx frame counter upper */
63 u32 rx_frame_crc_err_l; /* Rx frame check sequence error lower */
64 u32 rx_frame_crc_err_u; /* Rx frame check sequence error upper */
65 u32 rx_vlan_l; /* Rx VLAN frame lower */
66 u32 rx_vlan_u; /* Rx VLAN frame upper */
67 u32 rx_err_l; /* Rx frame error lower */
68 u32 rx_err_u; /* Rx frame error upper */
69 u32 rx_uni_l; /* Rx unicast frame lower */
70 u32 rx_uni_u; /* Rx unicast frame upper */
71 u32 rx_multi_l; /* Rx multicast frame lower */
72 u32 rx_multi_u; /* Rx multicast frame upper */
73 u32 rx_brd_l; /* Rx broadcast frame lower */
74 u32 rx_brd_u; /* Rx broadcast frame upper */
75 u32 rx_drop_l; /* Rx dropped packets lower */
76 u32 rx_drop_u; /* Rx dropped packets upper */
77 u32 rx_pkt_l; /* Rx packets lower */
78 u32 rx_pkt_u; /* Rx packets upper */
79 u32 rx_undsz_l; /* Rx undersized packet lower */
80 u32 rx_undsz_u; /* Rx undersized packet upper */
81 u32 rx_64_l; /* Rx 64 oct packet lower */
82 u32 rx_64_u; /* Rx 64 oct packet upper */
83 u32 rx_127_l; /* Rx 65 to 127 oct packet lower */
84 u32 rx_127_u; /* Rx 65 to 127 oct packet upper */
85 u32 rx_255_l; /* Rx 128 to 255 oct packet lower */
86 u32 rx_255_u; /* Rx 128 to 255 oct packet upper */
87 u32 rx_511_l; /* Rx 256 to 511 oct packet lower */
88 u32 rx_511_u; /* Rx 256 to 511 oct packet upper */
89 u32 rx_1023_l; /* Rx 512 to 1023 oct packet lower */
90 u32 rx_1023_u; /* Rx 512 to 1023 oct packet upper */
91 u32 rx_1518_l; /* Rx 1024 to 1518 oct packet lower */
92 u32 rx_1518_u; /* Rx 1024 to 1518 oct packet upper */
93 u32 rx_1519_l; /* Rx 1519 to max oct packet lower */
94 u32 rx_1519_u; /* Rx 1519 to max oct packet upper */
95 u32 rx_oversz_l; /* Rx oversized packet lower */
96 u32 rx_oversz_u; /* Rx oversized packet upper */
97 u32 rx_jabber_l; /* Rx Jabber packet lower */
98 u32 rx_jabber_u; /* Rx Jabber packet upper */
99 u32 rx_frag_l; /* Rx Fragment packet lower */
100 u32 rx_frag_u; /* Rx Fragment packet upper */
101 u32 rx_cnp_l; /* Rx control packet lower */
102 u32 rx_cnp_u; /* Rx control packet upper */
103 u32 rx_drntp_l; /* Rx dripped not truncated packet lower */
104 u32 rx_drntp_u; /* Rx dripped not truncated packet upper */
105 u32 res_1d0[0xc];
106
107 u32 tx_eoct_l; /* Tx ethernet octests lower */
108 u32 tx_eoct_u; /* Tx ethernet octests upper */
109 u32 tx_oct_l; /* Tx octests lower */
110 u32 tx_oct_u; /* Tx octests upper */
111 u32 res_210[0x2];
112 u32 tx_pause_frame_l; /* Tx valid pause frame lower */
113 u32 tx_pause_frame_u; /* Tx valid pause frame upper */
114 u32 tx_frame_l; /* Tx frame counter lower */
115 u32 tx_frame_u; /* Tx frame counter upper */
116 u32 tx_frame_crc_err_l; /* Tx frame check sequence error lower */
117 u32 tx_frame_crc_err_u; /* Tx frame check sequence error upper */
118 u32 tx_vlan_l; /* Tx VLAN frame lower */
119 u32 tx_vlan_u; /* Tx VLAN frame upper */
120 u32 tx_frame_err_l; /* Tx frame error lower */
121 u32 tx_frame_err_u; /* Tx frame error upper */
122 u32 tx_uni_l; /* Tx unicast frame lower */
123 u32 tx_uni_u; /* Tx unicast frame upper */
124 u32 tx_multi_l; /* Tx multicast frame lower */
125 u32 tx_multi_u; /* Tx multicast frame upper */
126 u32 tx_brd_l; /* Tx broadcast frame lower */
127 u32 tx_brd_u; /* Tx broadcast frame upper */
128 u32 res_258[0x2];
129 u32 tx_pkt_l; /* Tx packets lower */
130 u32 tx_pkt_u; /* Tx packets upper */
131 u32 tx_undsz_l; /* Tx undersized packet lower */
132 u32 tx_undsz_u; /* Tx undersized packet upper */
133 u32 tx_64_l; /* Tx 64 oct packet lower */
134 u32 tx_64_u; /* Tx 64 oct packet upper */
135 u32 tx_127_l; /* Tx 65 to 127 oct packet lower */
136 u32 tx_127_u; /* Tx 65 to 127 oct packet upper */
137 u32 tx_255_l; /* Tx 128 to 255 oct packet lower */
138 u32 tx_255_u; /* Tx 128 to 255 oct packet upper */
139 u32 tx_511_l; /* Tx 256 to 511 oct packet lower */
140 u32 tx_511_u; /* Tx 256 to 511 oct packet upper */
141 u32 tx_1023_l; /* Tx 512 to 1023 oct packet lower */
142 u32 tx_1023_u; /* Tx 512 to 1023 oct packet upper */
143 u32 tx_1518_l; /* Tx 1024 to 1518 oct packet lower */
144 u32 tx_1518_u; /* Tx 1024 to 1518 oct packet upper */
145 u32 tx_1519_l; /* Tx 1519 to max oct packet lower */
146 u32 tx_1519_u; /* Tx 1519 to max oct packet upper */
147 u32 res_2a8[0x6];
148 u32 tx_cnp_l; /* Tx control packet lower */
149 u32 tx_cnp_u; /* Tx control packet upper */
150 u32 res_2c8[0xe];
151
152 /* Line interface control register */
153 u32 if_mode; /* interface mode control */
154 u32 if_status; /* interface status */
155 u32 res_308[0xe];
156
157 /* HiGig/2 Register */
158 u32 hg_config; /* HiGig2 control and configuration */
159 u32 res_344[0x3];
160 u32 hg_pause_quanta; /* HiGig2 pause quanta */
161 u32 res_354[0x3];
162 u32 hg_pause_thresh; /* HiGig2 pause quanta threshold */
163 u32 res_364[0x3];
164 u32 hgrx_pause_status; /* HiGig2 rx pause quanta status */
165 u32 hg_fifos_status; /* HiGig2 fifos status */
166 u32 rhm; /* Rx HiGig2 message counter register */
167 u32 thm;/* Tx HiGig2 message counter register */
168 u32 res_380[0x320];
169};
170
171/* COMMAND_CONFIG - command and configuration register */
172#define MEMAC_CMD_CFG_RX_EN 0x00000002 /* MAC Rx path enable */
173#define MEMAC_CMD_CFG_TX_EN 0x00000001 /* MAC Tx path enable */
174#define MEMAC_CMD_CFG_RXTX_EN (MEMAC_CMD_CFG_RX_EN | MEMAC_CMD_CFG_TX_EN)
175
176/* HASHTABLE_CTRL - Hashtable control register */
177#define HASHTABLE_CTRL_MCAST_EN 0x00000200 /* enable mulitcast Rx hash */
178#define HASHTABLE_CTRL_ADDR_MASK 0x000001ff
179
180/* TX_IPG_LENGTH - Transmit inter-packet gap length register */
181#define TX_IPG_LENGTH_IPG_LEN_MASK 0x000003ff
182
183/* IMASK - interrupt mask register */
184#define IMASK_MDIO_SCAN_EVENT 0x00010000 /* MDIO scan event mask */
185#define IMASK_MDIO_CMD_CMPL 0x00008000 /* MDIO cmd completion mask */
186#define IMASK_REM_FAULT 0x00004000 /* remote fault mask */
187#define IMASK_LOC_FAULT 0x00002000 /* local fault mask */
188#define IMASK_TX_ECC_ER 0x00001000 /* Tx frame ECC error mask */
189#define IMASK_TX_FIFO_UNFL 0x00000800 /* Tx FIFO underflow mask */
190#define IMASK_TX_ER 0x00000200 /* Tx frame error mask */
191#define IMASK_RX_FIFO_OVFL 0x00000100 /* Rx FIFO overflow mask */
192#define IMASK_RX_ECC_ER 0x00000080 /* Rx frame ECC error mask */
193#define IMASK_RX_JAB_FRM 0x00000040 /* Rx jabber frame mask */
194#define IMASK_RX_OVRSZ_FRM 0x00000020 /* Rx oversized frame mask */
195#define IMASK_RX_RUNT_FRM 0x00000010 /* Rx runt frame mask */
196#define IMASK_RX_FRAG_FRM 0x00000008 /* Rx fragment frame mask */
197#define IMASK_RX_LEN_ER 0x00000004 /* Rx payload length error mask */
198#define IMASK_RX_CRC_ER 0x00000002 /* Rx CRC error mask */
199#define IMASK_RX_ALIGN_ER 0x00000001 /* Rx alignment error mask */
200
201#define IMASK_MASK_ALL 0x00000000
202
203/* IEVENT - interrupt event register */
204#define IEVENT_MDIO_SCAN_EVENT 0x00010000 /* MDIO scan event */
205#define IEVENT_MDIO_CMD_CMPL 0x00008000 /* MDIO cmd completion */
206#define IEVENT_REM_FAULT 0x00004000 /* remote fault */
207#define IEVENT_LOC_FAULT 0x00002000 /* local fault */
208#define IEVENT_TX_ECC_ER 0x00001000 /* Tx frame ECC error */
209#define IEVENT_TX_FIFO_UNFL 0x00000800 /* Tx FIFO underflow */
210#define IEVENT_TX_ER 0x00000200 /* Tx frame error */
211#define IEVENT_RX_FIFO_OVFL 0x00000100 /* Rx FIFO overflow */
212#define IEVENT_RX_ECC_ER 0x00000080 /* Rx frame ECC error */
213#define IEVENT_RX_JAB_FRM 0x00000040 /* Rx jabber frame */
214#define IEVENT_RX_OVRSZ_FRM 0x00000020 /* Rx oversized frame */
215#define IEVENT_RX_RUNT_FRM 0x00000010 /* Rx runt frame */
216#define IEVENT_RX_FRAG_FRM 0x00000008 /* Rx fragment frame */
217#define IEVENT_RX_LEN_ER 0x00000004 /* Rx payload length error */
218#define IEVENT_RX_CRC_ER 0x00000002 /* Rx CRC error */
219#define IEVENT_RX_ALIGN_ER 0x00000001 /* Rx alignment error */
220
221#define IEVENT_CLEAR_ALL 0xffffffff
222
223/* IF_MODE - Interface Mode Register */
224#define IF_MODE_EN_AUTO 0x00008000 /* 1 - Enable automatic speed selection */
225#define IF_MODE_XGMII 0x00000000 /* 00- XGMII(10) interface mode */
226#define IF_MODE_GMII 0x00000002 /* 10- GMII interface mode */
227#define IF_MODE_MASK 0x00000003 /* mask for mode interface mode */
228#define IF_MODE_RG 0x00000004 /* 1- RGMII */
229#define IF_MODE_RM 0x00000008 /* 1- RGMII */
230
231#define IF_DEFAULT (IF_GMII)
232
233/* Internal PHY Registers - SGMII */
234#define PHY_SGMII_CR_PHY_RESET 0x8000
235#define PHY_SGMII_CR_RESET_AN 0x0200
236#define PHY_SGMII_CR_DEF_VAL 0x1140
237#define PHY_SGMII_DEV_ABILITY_SGMII 0x4001
238#define PHY_SGMII_IF_MODE_AN 0x0002
239#define PHY_SGMII_IF_MODE_SGMII 0x0001
240
241struct memac_mdio_controller {
242 u32 res0[0xc];
243 u32 mdio_stat; /* MDIO configuration and status */
244 u32 mdio_ctl; /* MDIO control */
245 u32 mdio_data; /* MDIO data */
246 u32 mdio_addr; /* MDIO address */
247};
248
249#define MDIO_STAT_CLKDIV(x) (((x>>1) & 0xff) << 8)
250#define MDIO_STAT_BSY (1 << 0)
251#define MDIO_STAT_RD_ER (1 << 1)
252#define MDIO_STAT_PRE (1 << 5)
253#define MDIO_STAT_ENC (1 << 6)
254#define MDIO_STAT_HOLD_15_CLK (7 << 2)
255
256#define MDIO_CTL_DEV_ADDR(x) (x & 0x1f)
257#define MDIO_CTL_PORT_ADDR(x) ((x & 0x1f) << 5)
258#define MDIO_CTL_PRE_DIS (1 << 10)
259#define MDIO_CTL_SCAN_EN (1 << 11)
260#define MDIO_CTL_POST_INC (1 << 14)
261#define MDIO_CTL_READ (1 << 15)
262
263#define MDIO_DATA(x) (x & 0xffff)
264#define MDIO_DATA_BSY (1 << 31)
265
266struct fsl_enet_mac;
267
268void init_memac(struct fsl_enet_mac *mac, void *base, void *phyregs,
269 int max_rx_len);
270
271#endif