2 * Copyright 2008-2015 Freescale Semiconductor Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of Freescale Semiconductor nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
16 * ALTERNATIVELY, this software may be distributed under the terms of the
17 * GNU General Public License ("GPL") as published by the Free Software
18 * Foundation, either version 2 of that License or (at your option) any
21 * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
35 #include "fman_dtsec.h"
38 #include <linux/slab.h>
39 #include <linux/bitrev.h>
41 #include <linux/delay.h>
42 #include <linux/phy.h>
43 #include <linux/crc32.h>
44 #include <linux/of_mdio.h>
45 #include <linux/mii.h>
47 /* TBI register addresses */
48 #define MII_TBICON 0x11
50 /* TBICON register bit fields */
51 #define TBICON_SOFT_RESET 0x8000 /* Soft reset */
52 #define TBICON_DISABLE_RX_DIS 0x2000 /* Disable receive disparity */
53 #define TBICON_DISABLE_TX_DIS 0x1000 /* Disable transmit disparity */
54 #define TBICON_AN_SENSE 0x0100 /* Auto-negotiation sense enable */
55 #define TBICON_CLK_SELECT 0x0020 /* Clock select */
56 #define TBICON_MI_MODE 0x0010 /* GMII mode (TBI if not set) */
58 #define TBIANA_SGMII 0x4001
59 #define TBIANA_1000X 0x01a0
61 /* Interrupt Mask Register (IMASK) */
62 #define DTSEC_IMASK_BREN 0x80000000
63 #define DTSEC_IMASK_RXCEN 0x40000000
64 #define DTSEC_IMASK_MSROEN 0x04000000
65 #define DTSEC_IMASK_GTSCEN 0x02000000
66 #define DTSEC_IMASK_BTEN 0x01000000
67 #define DTSEC_IMASK_TXCEN 0x00800000
68 #define DTSEC_IMASK_TXEEN 0x00400000
69 #define DTSEC_IMASK_LCEN 0x00040000
70 #define DTSEC_IMASK_CRLEN 0x00020000
71 #define DTSEC_IMASK_XFUNEN 0x00010000
72 #define DTSEC_IMASK_ABRTEN 0x00008000
73 #define DTSEC_IMASK_IFERREN 0x00004000
74 #define DTSEC_IMASK_MAGEN 0x00000800
75 #define DTSEC_IMASK_MMRDEN 0x00000400
76 #define DTSEC_IMASK_MMWREN 0x00000200
77 #define DTSEC_IMASK_GRSCEN 0x00000100
78 #define DTSEC_IMASK_TDPEEN 0x00000002
79 #define DTSEC_IMASK_RDPEEN 0x00000001
81 #define DTSEC_EVENTS_MASK \
82 ((u32)(DTSEC_IMASK_BREN | \
87 DTSEC_IMASK_ABRTEN | \
90 DTSEC_IMASK_XFUNEN | \
91 DTSEC_IMASK_IFERREN | \
93 DTSEC_IMASK_TDPEEN | \
96 /* dtsec timestamp event bits */
97 #define TMR_PEMASK_TSREEN 0x00010000
98 #define TMR_PEVENT_TSRE 0x00010000
100 /* Group address bit indication */
101 #define MAC_GROUP_ADDRESS 0x0000010000000000ULL
104 #define DEFAULT_HALFDUP_RETRANSMIT 0xf
105 #define DEFAULT_HALFDUP_COLL_WINDOW 0x37
106 #define DEFAULT_TX_PAUSE_TIME 0xf000
107 #define DEFAULT_RX_PREPEND 0
108 #define DEFAULT_PREAMBLE_LEN 7
109 #define DEFAULT_TX_PAUSE_TIME_EXTD 0
110 #define DEFAULT_NON_BACK_TO_BACK_IPG1 0x40
111 #define DEFAULT_NON_BACK_TO_BACK_IPG2 0x60
112 #define DEFAULT_MIN_IFG_ENFORCEMENT 0x50
113 #define DEFAULT_BACK_TO_BACK_IPG 0x60
114 #define DEFAULT_MAXIMUM_FRAME 0x600
116 /* register related defines (bits, field offsets..) */
117 #define DTSEC_ID2_INT_REDUCED_OFF 0x00010000
119 #define DTSEC_ECNTRL_GMIIM 0x00000040
120 #define DTSEC_ECNTRL_TBIM 0x00000020
121 #define DTSEC_ECNTRL_SGMIIM 0x00000002
122 #define DTSEC_ECNTRL_RPM 0x00000010
123 #define DTSEC_ECNTRL_R100M 0x00000008
124 #define DTSEC_ECNTRL_QSGMIIM 0x00000001
126 #define TCTRL_TTSE 0x00000040
127 #define TCTRL_GTS 0x00000020
129 #define RCTRL_PAL_MASK 0x001f0000
130 #define RCTRL_PAL_SHIFT 16
131 #define RCTRL_GHTX 0x00000400
132 #define RCTRL_RTSE 0x00000040
133 #define RCTRL_GRS 0x00000020
134 #define RCTRL_MPROM 0x00000008
135 #define RCTRL_RSF 0x00000004
136 #define RCTRL_UPROM 0x00000001
138 #define MACCFG1_SOFT_RESET 0x80000000
139 #define MACCFG1_RX_FLOW 0x00000020
140 #define MACCFG1_TX_FLOW 0x00000010
141 #define MACCFG1_TX_EN 0x00000001
142 #define MACCFG1_RX_EN 0x00000004
144 #define MACCFG2_NIBBLE_MODE 0x00000100
145 #define MACCFG2_BYTE_MODE 0x00000200
146 #define MACCFG2_PAD_CRC_EN 0x00000004
147 #define MACCFG2_FULL_DUPLEX 0x00000001
148 #define MACCFG2_PREAMBLE_LENGTH_MASK 0x0000f000
149 #define MACCFG2_PREAMBLE_LENGTH_SHIFT 12
151 #define IPGIFG_NON_BACK_TO_BACK_IPG_1_SHIFT 24
152 #define IPGIFG_NON_BACK_TO_BACK_IPG_2_SHIFT 16
153 #define IPGIFG_MIN_IFG_ENFORCEMENT_SHIFT 8
155 #define IPGIFG_NON_BACK_TO_BACK_IPG_1 0x7F000000
156 #define IPGIFG_NON_BACK_TO_BACK_IPG_2 0x007F0000
157 #define IPGIFG_MIN_IFG_ENFORCEMENT 0x0000FF00
158 #define IPGIFG_BACK_TO_BACK_IPG 0x0000007F
160 #define HAFDUP_EXCESS_DEFER 0x00010000
161 #define HAFDUP_COLLISION_WINDOW 0x000003ff
162 #define HAFDUP_RETRANSMISSION_MAX_SHIFT 12
163 #define HAFDUP_RETRANSMISSION_MAX 0x0000f000
165 #define NUM_OF_HASH_REGS 8 /* Number of hash table registers */
167 #define PTV_PTE_MASK 0xffff0000
168 #define PTV_PT_MASK 0x0000ffff
169 #define PTV_PTE_SHIFT 16
171 #define MAX_PACKET_ALIGNMENT 31
172 #define MAX_INTER_PACKET_GAP 0x7f
173 #define MAX_RETRANSMISSION 0x0f
174 #define MAX_COLLISION_WINDOW 0x03ff
176 /* Hash table size (32 bits*8 regs) */
177 #define DTSEC_HASH_TABLE_SIZE 256
178 /* Extended Hash table size (32 bits*16 regs) */
179 #define EXTENDED_HASH_TABLE_SIZE 512
181 /* dTSEC Memory Map registers */
183 /* dTSEC General Control and Status Registers */
184 u32 tsec_id
; /* 0x000 ETSEC_ID register */
185 u32 tsec_id2
; /* 0x004 ETSEC_ID2 register */
186 u32 ievent
; /* 0x008 Interrupt event register */
187 u32 imask
; /* 0x00C Interrupt mask register */
189 u32 ecntrl
; /* 0x014 E control register */
190 u32 ptv
; /* 0x018 Pause time value register */
191 u32 tbipa
; /* 0x01C TBI PHY address register */
192 u32 tmr_ctrl
; /* 0x020 Time-stamp Control register */
193 u32 tmr_pevent
; /* 0x024 Time-stamp event register */
194 u32 tmr_pemask
; /* 0x028 Timer event mask register */
196 u32 tctrl
; /* 0x040 Transmit control register */
198 u32 rctrl
; /* 0x050 Receive control register */
199 u32 reserved0054
[11];
200 u32 igaddr
[8]; /* 0x080-0x09C Individual/group address */
201 u32 gaddr
[8]; /* 0x0A0-0x0BC Group address registers 0-7 */
202 u32 reserved00c0
[16];
203 u32 maccfg1
; /* 0x100 MAC configuration #1 */
204 u32 maccfg2
; /* 0x104 MAC configuration #2 */
205 u32 ipgifg
; /* 0x108 IPG/IFG */
206 u32 hafdup
; /* 0x10C Half-duplex */
207 u32 maxfrm
; /* 0x110 Maximum frame */
208 u32 reserved0114
[10];
209 u32 ifstat
; /* 0x13C Interface status */
210 u32 macstnaddr1
; /* 0x140 Station Address,part 1 */
211 u32 macstnaddr2
; /* 0x144 Station Address,part 2 */
213 u32 exact_match1
; /* octets 1-4 */
214 u32 exact_match2
; /* octets 5-6 */
215 } macaddr
[15]; /* 0x148-0x1BC mac exact match addresses 1-15 */
216 u32 reserved01c0
[16];
217 u32 tr64
; /* 0x200 Tx and Rx 64 byte frame counter */
218 u32 tr127
; /* 0x204 Tx and Rx 65 to 127 byte frame counter */
219 u32 tr255
; /* 0x208 Tx and Rx 128 to 255 byte frame counter */
220 u32 tr511
; /* 0x20C Tx and Rx 256 to 511 byte frame counter */
221 u32 tr1k
; /* 0x210 Tx and Rx 512 to 1023 byte frame counter */
222 u32 trmax
; /* 0x214 Tx and Rx 1024 to 1518 byte frame counter */
224 /* 0x218 Tx and Rx 1519 to 1522 byte good VLAN frame count */
225 u32 rbyt
; /* 0x21C receive byte counter */
226 u32 rpkt
; /* 0x220 receive packet counter */
227 u32 rfcs
; /* 0x224 receive FCS error counter */
228 u32 rmca
; /* 0x228 RMCA Rx multicast packet counter */
229 u32 rbca
; /* 0x22C Rx broadcast packet counter */
230 u32 rxcf
; /* 0x230 Rx control frame packet counter */
231 u32 rxpf
; /* 0x234 Rx pause frame packet counter */
232 u32 rxuo
; /* 0x238 Rx unknown OP code counter */
233 u32 raln
; /* 0x23C Rx alignment error counter */
234 u32 rflr
; /* 0x240 Rx frame length error counter */
235 u32 rcde
; /* 0x244 Rx code error counter */
236 u32 rcse
; /* 0x248 Rx carrier sense error counter */
237 u32 rund
; /* 0x24C Rx undersize packet counter */
238 u32 rovr
; /* 0x250 Rx oversize packet counter */
239 u32 rfrg
; /* 0x254 Rx fragments counter */
240 u32 rjbr
; /* 0x258 Rx jabber counter */
241 u32 rdrp
; /* 0x25C Rx drop */
242 u32 tbyt
; /* 0x260 Tx byte counter */
243 u32 tpkt
; /* 0x264 Tx packet counter */
244 u32 tmca
; /* 0x268 Tx multicast packet counter */
245 u32 tbca
; /* 0x26C Tx broadcast packet counter */
246 u32 txpf
; /* 0x270 Tx pause control frame counter */
247 u32 tdfr
; /* 0x274 Tx deferral packet counter */
248 u32 tedf
; /* 0x278 Tx excessive deferral packet counter */
249 u32 tscl
; /* 0x27C Tx single collision packet counter */
250 u32 tmcl
; /* 0x280 Tx multiple collision packet counter */
251 u32 tlcl
; /* 0x284 Tx late collision packet counter */
252 u32 txcl
; /* 0x288 Tx excessive collision packet counter */
253 u32 tncl
; /* 0x28C Tx total collision counter */
255 u32 tdrp
; /* 0x294 Tx drop frame counter */
256 u32 tjbr
; /* 0x298 Tx jabber frame counter */
257 u32 tfcs
; /* 0x29C Tx FCS error counter */
258 u32 txcf
; /* 0x2A0 Tx control frame counter */
259 u32 tovr
; /* 0x2A4 Tx oversize frame counter */
260 u32 tund
; /* 0x2A8 Tx undersize frame counter */
261 u32 tfrg
; /* 0x2AC Tx fragments frame counter */
262 u32 car1
; /* 0x2B0 carry register one register* */
263 u32 car2
; /* 0x2B4 carry register two register* */
264 u32 cam1
; /* 0x2B8 carry register one mask register */
265 u32 cam2
; /* 0x2BC carry register two mask register */
266 u32 reserved02c0
[848];
269 /* struct dtsec_cfg - dTSEC configuration
270 * Transmit half-duplex flow control, under software control for 10/100-Mbps
271 * half-duplex media. If set, back pressure is applied to media by raising
273 * halfdup_retransmit:
274 * Number of retransmission attempts following a collision.
275 * If this is exceeded dTSEC aborts transmission due to excessive collisions.
276 * The standard specifies the attempt limit to be 15.
277 * halfdup_coll_window:
278 * The number of bytes of the frame during which collisions may occur.
279 * The default value of 55 corresponds to the frame byte at the end of the
280 * standard 512-bit slot time window. If collisions are detected after this
281 * byte, the late collision event is asserted and transmission of current
284 * Pad and append CRC. If set, the MAC pads all ransmitted short frames and
285 * appends a CRC to every frame regardless of padding requirement.
287 * Transmit pause time value. This pause value is used as part of the pause
288 * frame to be sent when a transmit pause frame is initiated.
289 * If set to 0 this disables transmission of pause frames.
291 * Length, in bytes, of the preamble field preceding each Ethernet
292 * start-of-frame delimiter byte. The default value of 0x7 should be used in
293 * order to guarantee reliable operation with IEEE 802.3 compliant hardware.
295 * Packet alignment padding length. The specified number of bytes (1-31)
296 * of zero padding are inserted before the start of each received frame.
297 * For Ethernet, where optional preamble extraction is enabled, the padding
298 * appears before the preamble, otherwise the padding precedes the
301 * This structure contains basic dTSEC configuration and must be passed to
302 * init() function. A default set of configuration values can be
303 * obtained by calling set_dflts().
306 u16 halfdup_retransmit
;
307 u16 halfdup_coll_window
;
311 bool ptp_exception_en
;
314 u16 tx_pause_time_extd
;
316 u32 non_back_to_back_ipg1
;
317 u32 non_back_to_back_ipg2
;
318 u32 min_ifg_enforcement
;
319 u32 back_to_back_ipg
;
323 /* pointer to dTSEC memory mapped registers */
324 struct dtsec_regs __iomem
*regs
;
325 /* MAC address of device */
327 /* Ethernet physical interface */
328 phy_interface_t phy_if
;
330 void *dev_id
; /* device cookie used by the exception cbs */
331 fman_mac_exception_cb
*exception_cb
;
332 fman_mac_exception_cb
*event_cb
;
333 /* Number of individual addresses in registers for this station */
334 u8 num_of_ind_addr_in_regs
;
335 /* pointer to driver's global address hash table */
336 struct eth_hash_t
*multicast_addr_hash
;
337 /* pointer to driver's individual address hash table */
338 struct eth_hash_t
*unicast_addr_hash
;
341 bool ptp_tsu_enabled
;
342 bool en_tsu_err_exception
;
343 struct dtsec_cfg
*dtsec_drv_param
;
345 struct fman_rev_info fm_rev_info
;
347 struct phy_device
*tbiphy
;
350 static void set_dflts(struct dtsec_cfg
*cfg
)
352 cfg
->halfdup_retransmit
= DEFAULT_HALFDUP_RETRANSMIT
;
353 cfg
->halfdup_coll_window
= DEFAULT_HALFDUP_COLL_WINDOW
;
354 cfg
->tx_pad_crc
= true;
355 cfg
->tx_pause_time
= DEFAULT_TX_PAUSE_TIME
;
356 /* PHY address 0 is reserved (DPAA RM) */
357 cfg
->rx_prepend
= DEFAULT_RX_PREPEND
;
358 cfg
->ptp_tsu_en
= true;
359 cfg
->ptp_exception_en
= true;
360 cfg
->preamble_len
= DEFAULT_PREAMBLE_LEN
;
361 cfg
->tx_pause_time_extd
= DEFAULT_TX_PAUSE_TIME_EXTD
;
362 cfg
->non_back_to_back_ipg1
= DEFAULT_NON_BACK_TO_BACK_IPG1
;
363 cfg
->non_back_to_back_ipg2
= DEFAULT_NON_BACK_TO_BACK_IPG2
;
364 cfg
->min_ifg_enforcement
= DEFAULT_MIN_IFG_ENFORCEMENT
;
365 cfg
->back_to_back_ipg
= DEFAULT_BACK_TO_BACK_IPG
;
366 cfg
->maximum_frame
= DEFAULT_MAXIMUM_FRAME
;
369 static void set_mac_address(struct dtsec_regs __iomem
*regs
, u8
*adr
)
373 tmp
= (u32
)((adr
[5] << 24) |
374 (adr
[4] << 16) | (adr
[3] << 8) | adr
[2]);
375 iowrite32be(tmp
, ®s
->macstnaddr1
);
377 tmp
= (u32
)((adr
[1] << 24) | (adr
[0] << 16));
378 iowrite32be(tmp
, ®s
->macstnaddr2
);
381 static int init(struct dtsec_regs __iomem
*regs
, struct dtsec_cfg
*cfg
,
382 phy_interface_t iface
, u16 iface_speed
, u64 addr
,
383 u32 exception_mask
, u8 tbi_addr
)
385 bool is_rgmii
, is_sgmii
, is_qsgmii
;
386 enet_addr_t eth_addr
;
391 iowrite32be(MACCFG1_SOFT_RESET
, ®s
->maccfg1
);
392 iowrite32be(0, ®s
->maccfg1
);
395 tmp
= ioread32be(®s
->tsec_id2
);
397 /* check RGMII support */
398 if (iface
== PHY_INTERFACE_MODE_RGMII
||
399 iface
== PHY_INTERFACE_MODE_RGMII_ID
||
400 iface
== PHY_INTERFACE_MODE_RGMII_RXID
||
401 iface
== PHY_INTERFACE_MODE_RGMII_TXID
||
402 iface
== PHY_INTERFACE_MODE_RMII
)
403 if (tmp
& DTSEC_ID2_INT_REDUCED_OFF
)
406 if (iface
== PHY_INTERFACE_MODE_SGMII
||
407 iface
== PHY_INTERFACE_MODE_MII
)
408 if (tmp
& DTSEC_ID2_INT_REDUCED_OFF
)
411 is_rgmii
= iface
== PHY_INTERFACE_MODE_RGMII
||
412 iface
== PHY_INTERFACE_MODE_RGMII_ID
||
413 iface
== PHY_INTERFACE_MODE_RGMII_RXID
||
414 iface
== PHY_INTERFACE_MODE_RGMII_TXID
;
415 is_sgmii
= iface
== PHY_INTERFACE_MODE_SGMII
;
416 is_qsgmii
= iface
== PHY_INTERFACE_MODE_QSGMII
;
419 if (is_rgmii
|| iface
== PHY_INTERFACE_MODE_GMII
)
420 tmp
|= DTSEC_ECNTRL_GMIIM
;
422 tmp
|= (DTSEC_ECNTRL_SGMIIM
| DTSEC_ECNTRL_TBIM
);
424 tmp
|= (DTSEC_ECNTRL_SGMIIM
| DTSEC_ECNTRL_TBIM
|
425 DTSEC_ECNTRL_QSGMIIM
);
427 tmp
|= DTSEC_ECNTRL_RPM
;
428 if (iface_speed
== SPEED_100
)
429 tmp
|= DTSEC_ECNTRL_R100M
;
431 iowrite32be(tmp
, ®s
->ecntrl
);
435 if (cfg
->tx_pause_time
)
436 tmp
|= cfg
->tx_pause_time
;
437 if (cfg
->tx_pause_time_extd
)
438 tmp
|= cfg
->tx_pause_time_extd
<< PTV_PTE_SHIFT
;
439 iowrite32be(tmp
, ®s
->ptv
);
442 tmp
|= (cfg
->rx_prepend
<< RCTRL_PAL_SHIFT
) & RCTRL_PAL_MASK
;
443 /* Accept short frames */
446 iowrite32be(tmp
, ®s
->rctrl
);
448 /* Assign a Phy Address to the TBI (TBIPA).
449 * Done also in cases where TBI is not selected to avoid conflict with
450 * the external PHY's Physical address
452 iowrite32be(tbi_addr
, ®s
->tbipa
);
454 iowrite32be(0, ®s
->tmr_ctrl
);
456 if (cfg
->ptp_tsu_en
) {
458 tmp
|= TMR_PEVENT_TSRE
;
459 iowrite32be(tmp
, ®s
->tmr_pevent
);
461 if (cfg
->ptp_exception_en
) {
463 tmp
|= TMR_PEMASK_TSREEN
;
464 iowrite32be(tmp
, ®s
->tmr_pemask
);
469 tmp
|= MACCFG1_RX_FLOW
;
470 tmp
|= MACCFG1_TX_FLOW
;
471 iowrite32be(tmp
, ®s
->maccfg1
);
475 if (iface_speed
< SPEED_1000
)
476 tmp
|= MACCFG2_NIBBLE_MODE
;
477 else if (iface_speed
== SPEED_1000
)
478 tmp
|= MACCFG2_BYTE_MODE
;
480 tmp
|= (cfg
->preamble_len
<< MACCFG2_PREAMBLE_LENGTH_SHIFT
) &
481 MACCFG2_PREAMBLE_LENGTH_MASK
;
483 tmp
|= MACCFG2_PAD_CRC_EN
;
485 tmp
|= MACCFG2_FULL_DUPLEX
;
486 iowrite32be(tmp
, ®s
->maccfg2
);
488 tmp
= (((cfg
->non_back_to_back_ipg1
<<
489 IPGIFG_NON_BACK_TO_BACK_IPG_1_SHIFT
)
490 & IPGIFG_NON_BACK_TO_BACK_IPG_1
)
491 | ((cfg
->non_back_to_back_ipg2
<<
492 IPGIFG_NON_BACK_TO_BACK_IPG_2_SHIFT
)
493 & IPGIFG_NON_BACK_TO_BACK_IPG_2
)
494 | ((cfg
->min_ifg_enforcement
<< IPGIFG_MIN_IFG_ENFORCEMENT_SHIFT
)
495 & IPGIFG_MIN_IFG_ENFORCEMENT
)
496 | (cfg
->back_to_back_ipg
& IPGIFG_BACK_TO_BACK_IPG
));
497 iowrite32be(tmp
, ®s
->ipgifg
);
500 tmp
|= HAFDUP_EXCESS_DEFER
;
501 tmp
|= ((cfg
->halfdup_retransmit
<< HAFDUP_RETRANSMISSION_MAX_SHIFT
)
502 & HAFDUP_RETRANSMISSION_MAX
);
503 tmp
|= (cfg
->halfdup_coll_window
& HAFDUP_COLLISION_WINDOW
);
505 iowrite32be(tmp
, ®s
->hafdup
);
507 /* Initialize Maximum frame length */
508 iowrite32be(cfg
->maximum_frame
, ®s
->maxfrm
);
510 iowrite32be(0xffffffff, ®s
->cam1
);
511 iowrite32be(0xffffffff, ®s
->cam2
);
513 iowrite32be(exception_mask
, ®s
->imask
);
515 iowrite32be(0xffffffff, ®s
->ievent
);
518 MAKE_ENET_ADDR_FROM_UINT64(addr
, eth_addr
);
519 set_mac_address(regs
, (u8
*)eth_addr
);
523 for (i
= 0; i
< NUM_OF_HASH_REGS
; i
++) {
524 /* Initialize IADDRx */
525 iowrite32be(0, ®s
->igaddr
[i
]);
526 /* Initialize GADDRx */
527 iowrite32be(0, ®s
->gaddr
[i
]);
533 static void set_bucket(struct dtsec_regs __iomem
*regs
, int bucket
,
536 int reg_idx
= (bucket
>> 5) & 0xf;
537 int bit_idx
= bucket
& 0x1f;
538 u32 bit_mask
= 0x80000000 >> bit_idx
;
542 reg
= ®s
->gaddr
[reg_idx
- 8];
544 reg
= ®s
->igaddr
[reg_idx
];
547 iowrite32be(ioread32be(reg
) | bit_mask
, reg
);
549 iowrite32be(ioread32be(reg
) & (~bit_mask
), reg
);
552 static int check_init_parameters(struct fman_mac
*dtsec
)
554 if (dtsec
->max_speed
>= SPEED_10000
) {
555 pr_err("1G MAC driver supports 1G or lower speeds\n");
558 if ((dtsec
->dtsec_drv_param
)->rx_prepend
>
559 MAX_PACKET_ALIGNMENT
) {
560 pr_err("packetAlignmentPadding can't be > than %d\n",
561 MAX_PACKET_ALIGNMENT
);
564 if (((dtsec
->dtsec_drv_param
)->non_back_to_back_ipg1
>
565 MAX_INTER_PACKET_GAP
) ||
566 ((dtsec
->dtsec_drv_param
)->non_back_to_back_ipg2
>
567 MAX_INTER_PACKET_GAP
) ||
568 ((dtsec
->dtsec_drv_param
)->back_to_back_ipg
>
569 MAX_INTER_PACKET_GAP
)) {
570 pr_err("Inter packet gap can't be greater than %d\n",
571 MAX_INTER_PACKET_GAP
);
574 if ((dtsec
->dtsec_drv_param
)->halfdup_retransmit
>
575 MAX_RETRANSMISSION
) {
576 pr_err("maxRetransmission can't be greater than %d\n",
580 if ((dtsec
->dtsec_drv_param
)->halfdup_coll_window
>
581 MAX_COLLISION_WINDOW
) {
582 pr_err("collisionWindow can't be greater than %d\n",
583 MAX_COLLISION_WINDOW
);
585 /* If Auto negotiation process is disabled, need to set up the PHY
586 * using the MII Management Interface
589 if (!dtsec
->exception_cb
) {
590 pr_err("uninitialized exception_cb\n");
593 if (!dtsec
->event_cb
) {
594 pr_err("uninitialized event_cb\n");
601 static int get_exception_flag(enum fman_mac_exceptions exception
)
606 case FM_MAC_EX_1G_BAB_RX
:
607 bit_mask
= DTSEC_IMASK_BREN
;
609 case FM_MAC_EX_1G_RX_CTL
:
610 bit_mask
= DTSEC_IMASK_RXCEN
;
612 case FM_MAC_EX_1G_GRATEFUL_TX_STP_COMPLET
:
613 bit_mask
= DTSEC_IMASK_GTSCEN
;
615 case FM_MAC_EX_1G_BAB_TX
:
616 bit_mask
= DTSEC_IMASK_BTEN
;
618 case FM_MAC_EX_1G_TX_CTL
:
619 bit_mask
= DTSEC_IMASK_TXCEN
;
621 case FM_MAC_EX_1G_TX_ERR
:
622 bit_mask
= DTSEC_IMASK_TXEEN
;
624 case FM_MAC_EX_1G_LATE_COL
:
625 bit_mask
= DTSEC_IMASK_LCEN
;
627 case FM_MAC_EX_1G_COL_RET_LMT
:
628 bit_mask
= DTSEC_IMASK_CRLEN
;
630 case FM_MAC_EX_1G_TX_FIFO_UNDRN
:
631 bit_mask
= DTSEC_IMASK_XFUNEN
;
633 case FM_MAC_EX_1G_MAG_PCKT
:
634 bit_mask
= DTSEC_IMASK_MAGEN
;
636 case FM_MAC_EX_1G_MII_MNG_RD_COMPLET
:
637 bit_mask
= DTSEC_IMASK_MMRDEN
;
639 case FM_MAC_EX_1G_MII_MNG_WR_COMPLET
:
640 bit_mask
= DTSEC_IMASK_MMWREN
;
642 case FM_MAC_EX_1G_GRATEFUL_RX_STP_COMPLET
:
643 bit_mask
= DTSEC_IMASK_GRSCEN
;
645 case FM_MAC_EX_1G_DATA_ERR
:
646 bit_mask
= DTSEC_IMASK_TDPEEN
;
648 case FM_MAC_EX_1G_RX_MIB_CNT_OVFL
:
649 bit_mask
= DTSEC_IMASK_MSROEN
;
659 static bool is_init_done(struct dtsec_cfg
*dtsec_drv_params
)
661 /* Checks if dTSEC driver parameters were initialized */
662 if (!dtsec_drv_params
)
668 static u16
dtsec_get_max_frame_length(struct fman_mac
*dtsec
)
670 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
672 if (is_init_done(dtsec
->dtsec_drv_param
))
675 return (u16
)ioread32be(®s
->maxfrm
);
678 static void dtsec_isr(void *handle
)
680 struct fman_mac
*dtsec
= (struct fman_mac
*)handle
;
681 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
684 /* do not handle MDIO events */
685 event
= ioread32be(®s
->ievent
) &
686 (u32
)(~(DTSEC_IMASK_MMRDEN
| DTSEC_IMASK_MMWREN
));
688 event
&= ioread32be(®s
->imask
);
690 iowrite32be(event
, ®s
->ievent
);
692 if (event
& DTSEC_IMASK_BREN
)
693 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_BAB_RX
);
694 if (event
& DTSEC_IMASK_RXCEN
)
695 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_RX_CTL
);
696 if (event
& DTSEC_IMASK_GTSCEN
)
697 dtsec
->exception_cb(dtsec
->dev_id
,
698 FM_MAC_EX_1G_GRATEFUL_TX_STP_COMPLET
);
699 if (event
& DTSEC_IMASK_BTEN
)
700 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_BAB_TX
);
701 if (event
& DTSEC_IMASK_TXCEN
)
702 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_TX_CTL
);
703 if (event
& DTSEC_IMASK_TXEEN
)
704 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_TX_ERR
);
705 if (event
& DTSEC_IMASK_LCEN
)
706 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_LATE_COL
);
707 if (event
& DTSEC_IMASK_CRLEN
)
708 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_COL_RET_LMT
);
709 if (event
& DTSEC_IMASK_XFUNEN
) {
710 /* FM_TX_LOCKUP_ERRATA_DTSEC6 Errata workaround */
711 if (dtsec
->fm_rev_info
.major
== 2) {
712 u32 tpkt1
, tmp_reg1
, tpkt2
, tmp_reg2
, i
;
713 /* a. Write 0x00E0_0C00 to DTSEC_ID
714 * This is a read only register
715 * b. Read and save the value of TPKT
717 tpkt1
= ioread32be(®s
->tpkt
);
719 /* c. Read the register at dTSEC address offset 0x32C */
720 tmp_reg1
= ioread32be(®s
->reserved02c0
[27]);
722 /* d. Compare bits [9:15] to bits [25:31] of the
723 * register at address offset 0x32C.
725 if ((tmp_reg1
& 0x007F0000) !=
726 (tmp_reg1
& 0x0000007F)) {
727 /* If they are not equal, save the value of
728 * this register and wait for at least
731 usleep_range((u32
)(min
732 (dtsec_get_max_frame_length(dtsec
) *
733 16 / 1000, 1)), (u32
)
734 (min(dtsec_get_max_frame_length
735 (dtsec
) * 16 / 1000, 1) + 1));
738 /* e. Read and save TPKT again and read the register
739 * at dTSEC address offset 0x32C again
741 tpkt2
= ioread32be(®s
->tpkt
);
742 tmp_reg2
= ioread32be(®s
->reserved02c0
[27]);
744 /* f. Compare the value of TPKT saved in step b to
745 * value read in step e. Also compare bits [9:15] of
746 * the register at offset 0x32C saved in step d to the
747 * value of bits [9:15] saved in step e. If the two
748 * registers values are unchanged, then the transmit
749 * portion of the dTSEC controller is locked up and
750 * the user should proceed to the recover sequence.
752 if ((tpkt1
== tpkt2
) && ((tmp_reg1
& 0x007F0000) ==
753 (tmp_reg2
& 0x007F0000))) {
754 /* recover sequence */
756 /* a.Write a 1 to RCTRL[GRS] */
758 iowrite32be(ioread32be(®s
->rctrl
) |
759 RCTRL_GRS
, ®s
->rctrl
);
761 /* b.Wait until IEVENT[GRSC]=1, or at least
762 * 100 us has elapsed.
764 for (i
= 0; i
< 100; i
++) {
765 if (ioread32be(®s
->ievent
) &
770 if (ioread32be(®s
->ievent
) &
772 iowrite32be(DTSEC_IMASK_GRSCEN
,
775 pr_debug("Rx lockup due to Tx lockup\n");
777 /* c.Write a 1 to bit n of FM_RSTC
778 * (offset 0x0CC of FPM)
780 fman_reset_mac(dtsec
->fm
, dtsec
->mac_id
);
782 /* d.Wait 4 Tx clocks (32 ns) */
785 /* e.Write a 0 to bit n of FM_RSTC. */
791 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_TX_FIFO_UNDRN
);
793 if (event
& DTSEC_IMASK_MAGEN
)
794 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_MAG_PCKT
);
795 if (event
& DTSEC_IMASK_GRSCEN
)
796 dtsec
->exception_cb(dtsec
->dev_id
,
797 FM_MAC_EX_1G_GRATEFUL_RX_STP_COMPLET
);
798 if (event
& DTSEC_IMASK_TDPEEN
)
799 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_EX_1G_DATA_ERR
);
800 if (event
& DTSEC_IMASK_RDPEEN
)
801 dtsec
->exception_cb(dtsec
->dev_id
, FM_MAC_1G_RX_DATA_ERR
);
803 /* masked interrupts */
804 WARN_ON(event
& DTSEC_IMASK_ABRTEN
);
805 WARN_ON(event
& DTSEC_IMASK_IFERREN
);
808 static void dtsec_1588_isr(void *handle
)
810 struct fman_mac
*dtsec
= (struct fman_mac
*)handle
;
811 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
814 if (dtsec
->ptp_tsu_enabled
) {
815 event
= ioread32be(®s
->tmr_pevent
);
816 event
&= ioread32be(®s
->tmr_pemask
);
819 iowrite32be(event
, ®s
->tmr_pevent
);
820 WARN_ON(event
& TMR_PEVENT_TSRE
);
821 dtsec
->exception_cb(dtsec
->dev_id
,
822 FM_MAC_EX_1G_1588_TS_RX_ERR
);
827 static void free_init_resources(struct fman_mac
*dtsec
)
829 fman_unregister_intr(dtsec
->fm
, FMAN_MOD_MAC
, dtsec
->mac_id
,
831 fman_unregister_intr(dtsec
->fm
, FMAN_MOD_MAC
, dtsec
->mac_id
,
832 FMAN_INTR_TYPE_NORMAL
);
834 /* release the driver's group hash table */
835 free_hash_table(dtsec
->multicast_addr_hash
);
836 dtsec
->multicast_addr_hash
= NULL
;
838 /* release the driver's individual hash table */
839 free_hash_table(dtsec
->unicast_addr_hash
);
840 dtsec
->unicast_addr_hash
= NULL
;
843 int dtsec_cfg_max_frame_len(struct fman_mac
*dtsec
, u16 new_val
)
845 if (is_init_done(dtsec
->dtsec_drv_param
))
848 dtsec
->dtsec_drv_param
->maximum_frame
= new_val
;
853 int dtsec_cfg_pad_and_crc(struct fman_mac
*dtsec
, bool new_val
)
855 if (is_init_done(dtsec
->dtsec_drv_param
))
858 dtsec
->dtsec_drv_param
->tx_pad_crc
= new_val
;
863 static void graceful_start(struct fman_mac
*dtsec
, enum comm_mode mode
)
865 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
867 if (mode
& COMM_MODE_TX
)
868 iowrite32be(ioread32be(®s
->tctrl
) &
869 ~TCTRL_GTS
, ®s
->tctrl
);
870 if (mode
& COMM_MODE_RX
)
871 iowrite32be(ioread32be(®s
->rctrl
) &
872 ~RCTRL_GRS
, ®s
->rctrl
);
875 static void graceful_stop(struct fman_mac
*dtsec
, enum comm_mode mode
)
877 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
880 /* Graceful stop - Assert the graceful Rx stop bit */
881 if (mode
& COMM_MODE_RX
) {
882 tmp
= ioread32be(®s
->rctrl
) | RCTRL_GRS
;
883 iowrite32be(tmp
, ®s
->rctrl
);
885 if (dtsec
->fm_rev_info
.major
== 2) {
886 /* Workaround for dTSEC Errata A002 */
887 usleep_range(100, 200);
889 /* Workaround for dTSEC Errata A004839 */
890 usleep_range(10, 50);
894 /* Graceful stop - Assert the graceful Tx stop bit */
895 if (mode
& COMM_MODE_TX
) {
896 if (dtsec
->fm_rev_info
.major
== 2) {
897 /* dTSEC Errata A004: Do not use TCTRL[GTS]=1 */
898 pr_debug("GTS not supported due to DTSEC_A004 Errata.\n");
900 tmp
= ioread32be(®s
->tctrl
) | TCTRL_GTS
;
901 iowrite32be(tmp
, ®s
->tctrl
);
903 /* Workaround for dTSEC Errata A0012, A0014 */
904 usleep_range(10, 50);
909 int dtsec_enable(struct fman_mac
*dtsec
, enum comm_mode mode
)
911 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
914 if (!is_init_done(dtsec
->dtsec_drv_param
))
918 tmp
= ioread32be(®s
->maccfg1
);
919 if (mode
& COMM_MODE_RX
)
920 tmp
|= MACCFG1_RX_EN
;
921 if (mode
& COMM_MODE_TX
)
922 tmp
|= MACCFG1_TX_EN
;
924 iowrite32be(tmp
, ®s
->maccfg1
);
926 /* Graceful start - clear the graceful Rx/Tx stop bit */
927 graceful_start(dtsec
, mode
);
932 int dtsec_disable(struct fman_mac
*dtsec
, enum comm_mode mode
)
934 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
937 if (!is_init_done(dtsec
->dtsec_drv_param
))
940 /* Graceful stop - Assert the graceful Rx/Tx stop bit */
941 graceful_stop(dtsec
, mode
);
943 tmp
= ioread32be(®s
->maccfg1
);
944 if (mode
& COMM_MODE_RX
)
945 tmp
&= ~MACCFG1_RX_EN
;
946 if (mode
& COMM_MODE_TX
)
947 tmp
&= ~MACCFG1_TX_EN
;
949 iowrite32be(tmp
, ®s
->maccfg1
);
954 int dtsec_set_tx_pause_frames(struct fman_mac
*dtsec
,
955 u8 __maybe_unused priority
,
956 u16 pause_time
, u16 __maybe_unused thresh_time
)
958 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
959 enum comm_mode mode
= COMM_MODE_NONE
;
962 if (!is_init_done(dtsec
->dtsec_drv_param
))
965 if ((ioread32be(®s
->rctrl
) & RCTRL_GRS
) == 0)
966 mode
|= COMM_MODE_RX
;
967 if ((ioread32be(®s
->tctrl
) & TCTRL_GTS
) == 0)
968 mode
|= COMM_MODE_TX
;
970 graceful_stop(dtsec
, mode
);
973 /* FM_BAD_TX_TS_IN_B_2_B_ERRATA_DTSEC_A003 Errata workaround */
974 if (dtsec
->fm_rev_info
.major
== 2 && pause_time
<= 320) {
975 pr_warn("pause-time: %d illegal.Should be > 320\n",
980 ptv
= ioread32be(®s
->ptv
);
982 ptv
|= pause_time
& PTV_PT_MASK
;
983 iowrite32be(ptv
, ®s
->ptv
);
985 /* trigger the transmission of a flow-control pause frame */
986 iowrite32be(ioread32be(®s
->maccfg1
) | MACCFG1_TX_FLOW
,
989 iowrite32be(ioread32be(®s
->maccfg1
) & ~MACCFG1_TX_FLOW
,
992 graceful_start(dtsec
, mode
);
997 int dtsec_accept_rx_pause_frames(struct fman_mac
*dtsec
, bool en
)
999 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1000 enum comm_mode mode
= COMM_MODE_NONE
;
1003 if (!is_init_done(dtsec
->dtsec_drv_param
))
1006 if ((ioread32be(®s
->rctrl
) & RCTRL_GRS
) == 0)
1007 mode
|= COMM_MODE_RX
;
1008 if ((ioread32be(®s
->tctrl
) & TCTRL_GTS
) == 0)
1009 mode
|= COMM_MODE_TX
;
1011 graceful_stop(dtsec
, mode
);
1013 tmp
= ioread32be(®s
->maccfg1
);
1015 tmp
|= MACCFG1_RX_FLOW
;
1017 tmp
&= ~MACCFG1_RX_FLOW
;
1018 iowrite32be(tmp
, ®s
->maccfg1
);
1020 graceful_start(dtsec
, mode
);
1025 int dtsec_modify_mac_address(struct fman_mac
*dtsec
, enet_addr_t
*enet_addr
)
1027 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1028 enum comm_mode mode
= COMM_MODE_NONE
;
1030 if (!is_init_done(dtsec
->dtsec_drv_param
))
1033 if ((ioread32be(®s
->rctrl
) & RCTRL_GRS
) == 0)
1034 mode
|= COMM_MODE_RX
;
1035 if ((ioread32be(®s
->tctrl
) & TCTRL_GTS
) == 0)
1036 mode
|= COMM_MODE_TX
;
1038 graceful_stop(dtsec
, mode
);
1040 /* Initialize MAC Station Address registers (1 & 2)
1041 * Station address have to be swapped (big endian to little endian
1043 dtsec
->addr
= ENET_ADDR_TO_UINT64(*enet_addr
);
1044 set_mac_address(dtsec
->regs
, (u8
*)(*enet_addr
));
1046 graceful_start(dtsec
, mode
);
1051 int dtsec_add_hash_mac_address(struct fman_mac
*dtsec
, enet_addr_t
*eth_addr
)
1053 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1054 struct eth_hash_entry
*hash_entry
;
1057 u32 crc
= 0xFFFFFFFF;
1060 if (!is_init_done(dtsec
->dtsec_drv_param
))
1063 addr
= ENET_ADDR_TO_UINT64(*eth_addr
);
1065 ghtx
= (bool)((ioread32be(®s
->rctrl
) & RCTRL_GHTX
) ? true : false);
1066 mcast
= (bool)((addr
& MAC_GROUP_ADDRESS
) ? true : false);
1068 /* Cannot handle unicast mac addr when GHTX is on */
1069 if (ghtx
&& !mcast
) {
1070 pr_err("Could not compute hash bucket\n");
1073 crc
= crc32_le(crc
, (u8
*)eth_addr
, ETH_ALEN
);
1074 crc
= bitrev32(crc
);
1076 /* considering the 9 highest order bits in crc H[8:0]:
1077 *if ghtx = 0 H[8:6] (highest order 3 bits) identify the hash register
1078 *and H[5:1] (next 5 bits) identify the hash bit
1079 *if ghts = 1 H[8:5] (highest order 4 bits) identify the hash register
1080 *and H[4:0] (next 5 bits) identify the hash bit.
1082 *In bucket index output the low 5 bits identify the hash register
1083 *bit, while the higher 4 bits identify the hash register
1087 bucket
= (s32
)((crc
>> 23) & 0x1ff);
1089 bucket
= (s32
)((crc
>> 24) & 0xff);
1090 /* if !ghtx and mcast the bit must be set in gaddr instead of
1097 set_bucket(dtsec
->regs
, bucket
, true);
1099 /* Create element to be added to the driver hash table */
1100 hash_entry
= kmalloc(sizeof(*hash_entry
), GFP_ATOMIC
);
1103 hash_entry
->addr
= addr
;
1104 INIT_LIST_HEAD(&hash_entry
->node
);
1106 if (addr
& MAC_GROUP_ADDRESS
)
1108 list_add_tail(&hash_entry
->node
,
1109 &dtsec
->multicast_addr_hash
->lsts
[bucket
]);
1111 list_add_tail(&hash_entry
->node
,
1112 &dtsec
->unicast_addr_hash
->lsts
[bucket
]);
1117 int dtsec_set_allmulti(struct fman_mac
*dtsec
, bool enable
)
1120 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1122 if (!is_init_done(dtsec
->dtsec_drv_param
))
1125 tmp
= ioread32be(®s
->rctrl
);
1129 tmp
&= ~RCTRL_MPROM
;
1131 iowrite32be(tmp
, ®s
->rctrl
);
1136 int dtsec_set_tstamp(struct fman_mac
*dtsec
, bool enable
)
1138 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1141 if (!is_init_done(dtsec
->dtsec_drv_param
))
1144 rctrl
= ioread32be(®s
->rctrl
);
1145 tctrl
= ioread32be(®s
->tctrl
);
1148 rctrl
|= RCTRL_RTSE
;
1149 tctrl
|= TCTRL_TTSE
;
1151 rctrl
&= ~RCTRL_RTSE
;
1152 tctrl
&= ~TCTRL_TTSE
;
1155 iowrite32be(rctrl
, ®s
->rctrl
);
1156 iowrite32be(tctrl
, ®s
->tctrl
);
1161 int dtsec_del_hash_mac_address(struct fman_mac
*dtsec
, enet_addr_t
*eth_addr
)
1163 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1164 struct list_head
*pos
;
1165 struct eth_hash_entry
*hash_entry
= NULL
;
1168 u32 crc
= 0xFFFFFFFF;
1171 if (!is_init_done(dtsec
->dtsec_drv_param
))
1174 addr
= ENET_ADDR_TO_UINT64(*eth_addr
);
1176 ghtx
= (bool)((ioread32be(®s
->rctrl
) & RCTRL_GHTX
) ? true : false);
1177 mcast
= (bool)((addr
& MAC_GROUP_ADDRESS
) ? true : false);
1179 /* Cannot handle unicast mac addr when GHTX is on */
1180 if (ghtx
&& !mcast
) {
1181 pr_err("Could not compute hash bucket\n");
1184 crc
= crc32_le(crc
, (u8
*)eth_addr
, ETH_ALEN
);
1185 crc
= bitrev32(crc
);
1188 bucket
= (s32
)((crc
>> 23) & 0x1ff);
1190 bucket
= (s32
)((crc
>> 24) & 0xff);
1191 /* if !ghtx and mcast the bit must be set
1192 * in gaddr instead of igaddr.
1198 if (addr
& MAC_GROUP_ADDRESS
) {
1201 &dtsec
->multicast_addr_hash
->lsts
[bucket
]) {
1202 hash_entry
= ETH_HASH_ENTRY_OBJ(pos
);
1203 if (hash_entry
&& hash_entry
->addr
== addr
) {
1204 list_del_init(&hash_entry
->node
);
1209 if (list_empty(&dtsec
->multicast_addr_hash
->lsts
[bucket
]))
1210 set_bucket(dtsec
->regs
, bucket
, false);
1212 /* Individual Address */
1214 &dtsec
->unicast_addr_hash
->lsts
[bucket
]) {
1215 hash_entry
= ETH_HASH_ENTRY_OBJ(pos
);
1216 if (hash_entry
&& hash_entry
->addr
== addr
) {
1217 list_del_init(&hash_entry
->node
);
1222 if (list_empty(&dtsec
->unicast_addr_hash
->lsts
[bucket
]))
1223 set_bucket(dtsec
->regs
, bucket
, false);
1226 /* address does not exist */
1227 WARN_ON(!hash_entry
);
1232 int dtsec_set_promiscuous(struct fman_mac
*dtsec
, bool new_val
)
1234 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1237 if (!is_init_done(dtsec
->dtsec_drv_param
))
1240 /* Set unicast promiscuous */
1241 tmp
= ioread32be(®s
->rctrl
);
1245 tmp
&= ~RCTRL_UPROM
;
1247 iowrite32be(tmp
, ®s
->rctrl
);
1249 /* Set multicast promiscuous */
1250 tmp
= ioread32be(®s
->rctrl
);
1254 tmp
&= ~RCTRL_MPROM
;
1256 iowrite32be(tmp
, ®s
->rctrl
);
1261 int dtsec_adjust_link(struct fman_mac
*dtsec
, u16 speed
)
1263 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1264 enum comm_mode mode
= COMM_MODE_NONE
;
1267 if (!is_init_done(dtsec
->dtsec_drv_param
))
1270 if ((ioread32be(®s
->rctrl
) & RCTRL_GRS
) == 0)
1271 mode
|= COMM_MODE_RX
;
1272 if ((ioread32be(®s
->tctrl
) & TCTRL_GTS
) == 0)
1273 mode
|= COMM_MODE_TX
;
1275 graceful_stop(dtsec
, mode
);
1277 tmp
= ioread32be(®s
->maccfg2
);
1280 tmp
|= MACCFG2_FULL_DUPLEX
;
1282 tmp
&= ~(MACCFG2_NIBBLE_MODE
| MACCFG2_BYTE_MODE
);
1283 if (speed
< SPEED_1000
)
1284 tmp
|= MACCFG2_NIBBLE_MODE
;
1285 else if (speed
== SPEED_1000
)
1286 tmp
|= MACCFG2_BYTE_MODE
;
1287 iowrite32be(tmp
, ®s
->maccfg2
);
1289 tmp
= ioread32be(®s
->ecntrl
);
1290 if (speed
== SPEED_100
)
1291 tmp
|= DTSEC_ECNTRL_R100M
;
1293 tmp
&= ~DTSEC_ECNTRL_R100M
;
1294 iowrite32be(tmp
, ®s
->ecntrl
);
1296 graceful_start(dtsec
, mode
);
1301 int dtsec_restart_autoneg(struct fman_mac
*dtsec
)
1305 if (!is_init_done(dtsec
->dtsec_drv_param
))
1308 tmp_reg16
= phy_read(dtsec
->tbiphy
, MII_BMCR
);
1310 tmp_reg16
&= ~(BMCR_SPEED100
| BMCR_SPEED1000
);
1311 tmp_reg16
|= (BMCR_ANENABLE
| BMCR_ANRESTART
|
1312 BMCR_FULLDPLX
| BMCR_SPEED1000
);
1314 phy_write(dtsec
->tbiphy
, MII_BMCR
, tmp_reg16
);
1319 int dtsec_get_version(struct fman_mac
*dtsec
, u32
*mac_version
)
1321 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1323 if (!is_init_done(dtsec
->dtsec_drv_param
))
1326 *mac_version
= ioread32be(®s
->tsec_id
);
1331 int dtsec_set_exception(struct fman_mac
*dtsec
,
1332 enum fman_mac_exceptions exception
, bool enable
)
1334 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1337 if (!is_init_done(dtsec
->dtsec_drv_param
))
1340 if (exception
!= FM_MAC_EX_1G_1588_TS_RX_ERR
) {
1341 bit_mask
= get_exception_flag(exception
);
1344 dtsec
->exceptions
|= bit_mask
;
1346 dtsec
->exceptions
&= ~bit_mask
;
1348 pr_err("Undefined exception\n");
1352 iowrite32be(ioread32be(®s
->imask
) | bit_mask
,
1355 iowrite32be(ioread32be(®s
->imask
) & ~bit_mask
,
1358 if (!dtsec
->ptp_tsu_enabled
) {
1359 pr_err("Exception valid for 1588 only\n");
1362 switch (exception
) {
1363 case FM_MAC_EX_1G_1588_TS_RX_ERR
:
1365 dtsec
->en_tsu_err_exception
= true;
1366 iowrite32be(ioread32be(®s
->tmr_pemask
) |
1370 dtsec
->en_tsu_err_exception
= false;
1371 iowrite32be(ioread32be(®s
->tmr_pemask
) &
1377 pr_err("Undefined exception\n");
1385 int dtsec_init(struct fman_mac
*dtsec
)
1387 struct dtsec_regs __iomem
*regs
= dtsec
->regs
;
1388 struct dtsec_cfg
*dtsec_drv_param
;
1392 if (is_init_done(dtsec
->dtsec_drv_param
))
1395 if (DEFAULT_RESET_ON_INIT
&&
1396 (fman_reset_mac(dtsec
->fm
, dtsec
->mac_id
) != 0)) {
1397 pr_err("Can't reset MAC!\n");
1401 err
= check_init_parameters(dtsec
);
1405 dtsec_drv_param
= dtsec
->dtsec_drv_param
;
1407 err
= init(dtsec
->regs
, dtsec_drv_param
, dtsec
->phy_if
,
1408 dtsec
->max_speed
, dtsec
->addr
, dtsec
->exceptions
,
1409 dtsec
->tbiphy
->mdio
.addr
);
1411 free_init_resources(dtsec
);
1412 pr_err("DTSEC version doesn't support this i/f mode\n");
1416 if (dtsec
->phy_if
== PHY_INTERFACE_MODE_SGMII
) {
1419 /* Configure the TBI PHY Control Register */
1420 tmp_reg16
= TBICON_CLK_SELECT
| TBICON_SOFT_RESET
;
1421 phy_write(dtsec
->tbiphy
, MII_TBICON
, tmp_reg16
);
1423 tmp_reg16
= TBICON_CLK_SELECT
;
1424 phy_write(dtsec
->tbiphy
, MII_TBICON
, tmp_reg16
);
1426 tmp_reg16
= (BMCR_RESET
| BMCR_ANENABLE
|
1427 BMCR_FULLDPLX
| BMCR_SPEED1000
);
1428 phy_write(dtsec
->tbiphy
, MII_BMCR
, tmp_reg16
);
1430 if (dtsec
->basex_if
)
1431 tmp_reg16
= TBIANA_1000X
;
1433 tmp_reg16
= TBIANA_SGMII
;
1434 phy_write(dtsec
->tbiphy
, MII_ADVERTISE
, tmp_reg16
);
1436 tmp_reg16
= (BMCR_ANENABLE
| BMCR_ANRESTART
|
1437 BMCR_FULLDPLX
| BMCR_SPEED1000
);
1439 phy_write(dtsec
->tbiphy
, MII_BMCR
, tmp_reg16
);
1442 /* Max Frame Length */
1443 max_frm_ln
= (u16
)ioread32be(®s
->maxfrm
);
1444 err
= fman_set_mac_max_frame(dtsec
->fm
, dtsec
->mac_id
, max_frm_ln
);
1446 pr_err("Setting max frame length failed\n");
1447 free_init_resources(dtsec
);
1451 dtsec
->multicast_addr_hash
=
1452 alloc_hash_table(EXTENDED_HASH_TABLE_SIZE
);
1453 if (!dtsec
->multicast_addr_hash
) {
1454 free_init_resources(dtsec
);
1455 pr_err("MC hash table is failed\n");
1459 dtsec
->unicast_addr_hash
= alloc_hash_table(DTSEC_HASH_TABLE_SIZE
);
1460 if (!dtsec
->unicast_addr_hash
) {
1461 free_init_resources(dtsec
);
1462 pr_err("UC hash table is failed\n");
1466 /* register err intr handler for dtsec to FPM (err) */
1467 fman_register_intr(dtsec
->fm
, FMAN_MOD_MAC
, dtsec
->mac_id
,
1468 FMAN_INTR_TYPE_ERR
, dtsec_isr
, dtsec
);
1469 /* register 1588 intr handler for TMR to FPM (normal) */
1470 fman_register_intr(dtsec
->fm
, FMAN_MOD_MAC
, dtsec
->mac_id
,
1471 FMAN_INTR_TYPE_NORMAL
, dtsec_1588_isr
, dtsec
);
1473 kfree(dtsec_drv_param
);
1474 dtsec
->dtsec_drv_param
= NULL
;
1479 int dtsec_free(struct fman_mac
*dtsec
)
1481 free_init_resources(dtsec
);
1483 kfree(dtsec
->dtsec_drv_param
);
1484 dtsec
->dtsec_drv_param
= NULL
;
1490 struct fman_mac
*dtsec_config(struct fman_mac_params
*params
)
1492 struct fman_mac
*dtsec
;
1493 struct dtsec_cfg
*dtsec_drv_param
;
1494 void __iomem
*base_addr
;
1496 base_addr
= params
->base_addr
;
1498 /* allocate memory for the UCC GETH data structure. */
1499 dtsec
= kzalloc(sizeof(*dtsec
), GFP_KERNEL
);
1503 /* allocate memory for the d_tsec driver parameters data structure. */
1504 dtsec_drv_param
= kzalloc(sizeof(*dtsec_drv_param
), GFP_KERNEL
);
1505 if (!dtsec_drv_param
)
1508 /* Plant parameter structure pointer */
1509 dtsec
->dtsec_drv_param
= dtsec_drv_param
;
1511 set_dflts(dtsec_drv_param
);
1513 dtsec
->regs
= base_addr
;
1514 dtsec
->addr
= ENET_ADDR_TO_UINT64(params
->addr
);
1515 dtsec
->max_speed
= params
->max_speed
;
1516 dtsec
->phy_if
= params
->phy_if
;
1517 dtsec
->mac_id
= params
->mac_id
;
1518 dtsec
->exceptions
= (DTSEC_IMASK_BREN
|
1523 DTSEC_IMASK_ABRTEN
|
1526 DTSEC_IMASK_XFUNEN
|
1527 DTSEC_IMASK_IFERREN
|
1529 DTSEC_IMASK_TDPEEN
|
1530 DTSEC_IMASK_RDPEEN
);
1531 dtsec
->exception_cb
= params
->exception_cb
;
1532 dtsec
->event_cb
= params
->event_cb
;
1533 dtsec
->dev_id
= params
->dev_id
;
1534 dtsec
->ptp_tsu_enabled
= dtsec
->dtsec_drv_param
->ptp_tsu_en
;
1535 dtsec
->en_tsu_err_exception
= dtsec
->dtsec_drv_param
->ptp_exception_en
;
1537 dtsec
->fm
= params
->fm
;
1538 dtsec
->basex_if
= params
->basex_if
;
1540 if (!params
->internal_phy_node
) {
1541 pr_err("TBI PHY node is not available\n");
1542 goto err_dtsec_drv_param
;
1545 dtsec
->tbiphy
= of_phy_find_device(params
->internal_phy_node
);
1546 if (!dtsec
->tbiphy
) {
1547 pr_err("of_phy_find_device (TBI PHY) failed\n");
1548 goto err_dtsec_drv_param
;
1551 put_device(&dtsec
->tbiphy
->mdio
.dev
);
1553 /* Save FMan revision */
1554 fman_get_revision(dtsec
->fm
, &dtsec
->fm_rev_info
);
1558 err_dtsec_drv_param
:
1559 kfree(dtsec_drv_param
);