2 * sh_eth.h - Driver for Renesas SuperH ethernet controler.
4 * Copyright (C) 2008 - 2012 Renesas Solutions Corp.
5 * Copyright (c) 2008 - 2012 Nobuhiro Iwamatsu
6 * Copyright (c) 2007 Carlos Munoz <carlos@kenati.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <asm/types.h>
26 #define SHETHER_NAME "sh_eth"
28 #if defined(CONFIG_SH)
29 /* Malloc returns addresses in the P1 area (cacheable). However we need to
30 use area P2 (non-cacheable) */
31 #define ADDR_TO_P2(addr) ((((int)(addr) & ~0xe0000000) | 0xa0000000))
33 /* The ethernet controller needs to use physical addresses */
34 #if defined(CONFIG_SH_32BIT)
35 #define ADDR_TO_PHY(addr) ((((int)(addr) & ~0xe0000000) | 0x40000000))
37 #define ADDR_TO_PHY(addr) ((int)(addr) & ~0xe0000000)
39 #elif defined(CONFIG_ARM)
42 #define ADDR_TO_PHY(addr) ((int)(addr))
43 #define ADDR_TO_P2(addr) (addr)
44 #endif /* defined(CONFIG_SH) */
46 /* Number of supported ports */
47 #define MAX_PORT_NUM 2
49 /* Buffers must be big enough to hold the largest ethernet frame. Also, rx
50 buffers must be a multiple of 32 bytes */
51 #define MAX_BUF_SIZE (48 * 32)
53 /* The number of tx descriptors must be large enough to point to 5 or more
54 frames. If each frame uses 2 descriptors, at least 10 descriptors are needed.
55 We use one descriptor per frame */
58 /* The size of the tx descriptor is determined by how much padding is used.
59 4, 20, or 52 bytes of padding can be used */
60 #define TX_DESC_PADDING 4
61 #define TX_DESC_SIZE (12 + TX_DESC_PADDING)
63 /* Tx descriptor. We always use 3 bytes of padding */
67 u32 td2; /* Buffer start */
71 /* There is no limitation in the number of rx descriptors */
74 /* The size of the rx descriptor is determined by how much padding is used.
75 4, 20, or 52 bytes of padding can be used */
76 #define RX_DESC_PADDING 4
77 #define RX_DESC_SIZE (12 + RX_DESC_PADDING)
79 /* Rx descriptor. We always use 4 bytes of padding */
83 u32 rd2; /* Buffer start */
88 struct tx_desc_s *tx_desc_malloc;
89 struct tx_desc_s *tx_desc_base;
90 struct tx_desc_s *tx_desc_cur;
91 struct rx_desc_s *rx_desc_malloc;
92 struct rx_desc_s *rx_desc_base;
93 struct rx_desc_s *rx_desc_cur;
98 struct eth_device *dev;
99 struct phy_device *phydev;
104 struct sh_eth_info port_info[MAX_PORT_NUM];
107 /* from linux/drivers/net/ethernet/renesas/sh_eth.h */
109 /* E-DMAC registers */
138 /* Ether registers */
177 /* This value must be written at last. */
178 SH_ETH_MAX_REGISTER_OFFSET,
181 static const u16 sh_eth_offset_gigabit[SH_ETH_MAX_REGISTER_OFFSET] = {
235 static const u16 sh_eth_offset_fast_sh4[SH_ETH_MAX_REGISTER_OFFSET] = {
287 /* Register Address */
288 #if defined(CONFIG_CPU_SH7763) || defined(CONFIG_CPU_SH7734)
289 #define SH_ETH_TYPE_GETHER
290 #define BASE_IO_ADDR 0xfee00000
291 #elif defined(CONFIG_CPU_SH7757) || defined(CONFIG_CPU_SH7752)
292 #if defined(CONFIG_SH_ETHER_USE_GETHER)
293 #define SH_ETH_TYPE_GETHER
294 #define BASE_IO_ADDR 0xfee00000
296 #define SH_ETH_TYPE_ETHER
297 #define BASE_IO_ADDR 0xfef00000
299 #elif defined(CONFIG_CPU_SH7724)
300 #define SH_ETH_TYPE_ETHER
301 #define BASE_IO_ADDR 0xA4600000
302 #elif defined(CONFIG_R8A7740)
303 #define SH_ETH_TYPE_GETHER
304 #define BASE_IO_ADDR 0xE9A00000
309 * Copy from Linux driver source code
311 #if defined(SH_ETH_TYPE_GETHER)
314 EDSR_ENT = 0x01, EDSR_ENR = 0x02,
316 #define EDSR_ENALL (EDSR_ENT|EDSR_ENR)
321 EDMR_DL1 = 0x20, EDMR_DL0 = 0x10,
322 #if defined(SH_ETH_TYPE_GETHER)
323 EDMR_SRST = 0x03, /* Receive/Send reset */
324 EMDR_DESC_R = 0x30, /* Descriptor reserve size */
325 EDMR_EL = 0x40, /* Litte endian */
326 #elif defined(SH_ETH_TYPE_ETHER)
328 EMDR_DESC_R = 0x30, /* Descriptor reserve size */
329 EDMR_EL = 0x40, /* Litte endian */
336 #define RFLR_RFL_MIN 0x05EE /* Recv Frame length 1518 byte */
340 #if defined(SH_ETH_TYPE_GETHER)
349 #if defined(CONFIG_CPU_SH7757) || defined(CONFIG_CPU_SH7752)
350 GECMR_1000B = 0x20, GECMR_100B = 0x01, GECMR_10B = 0x00,
352 GECMR_1000B = 0x01, GECMR_100B = 0x04, GECMR_10B = 0x00,
363 TPAUSER_TPAUSE = 0x0000ffff,
364 TPAUSER_UNLIMITED = 0,
369 BCFR_RPAUSE = 0x0000ffff,
375 PIR_MDI = 0x08, PIR_MDO = 0x04, PIR_MMD = 0x02, PIR_MDC = 0x01,
379 enum PHY_STATUS_BIT { PHY_ST_LINK = 0x01, };
384 #if defined(SH_ETH_TYPE_ETHER)
385 EESR_TWB = 0x40000000,
387 EESR_TWB = 0xC0000000,
388 EESR_TC1 = 0x20000000,
389 EESR_TUC = 0x10000000,
390 EESR_ROC = 0x80000000,
392 EESR_TABT = 0x04000000,
393 EESR_RABT = 0x02000000, EESR_RFRMER = 0x01000000,
394 #if defined(SH_ETH_TYPE_ETHER)
395 EESR_ADE = 0x00800000,
397 EESR_ECI = 0x00400000,
398 EESR_FTC = 0x00200000, EESR_TDE = 0x00100000,
399 EESR_TFE = 0x00080000, EESR_FRC = 0x00040000,
400 EESR_RDE = 0x00020000, EESR_RFE = 0x00010000,
401 #if defined(SH_ETH_TYPE_ETHER)
402 EESR_CND = 0x00000800,
404 EESR_DLC = 0x00000400,
405 EESR_CD = 0x00000200, EESR_RTO = 0x00000100,
406 EESR_RMAF = 0x00000080, EESR_CEEF = 0x00000040,
407 EESR_CELF = 0x00000020, EESR_RRF = 0x00000010,
408 rESR_RTLF = 0x00000008, EESR_RTSF = 0x00000004,
409 EESR_PRE = 0x00000002, EESR_CERF = 0x00000001,
413 #if defined(SH_ETH_TYPE_GETHER)
414 # define TX_CHECK (EESR_TC1 | EESR_FTC)
415 # define EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE \
416 | EESR_RFRMER | EESR_TFE | EESR_TDE | EESR_ECI)
417 # define TX_ERROR_CEHCK (EESR_TWB | EESR_TABT | EESR_TDE | EESR_TFE)
420 # define TX_CHECK (EESR_FTC | EESR_CND | EESR_DLC | EESR_CD | EESR_RTO)
421 # define EESR_ERR_CHECK (EESR_TWB | EESR_TABT | EESR_RABT | EESR_RDE \
422 | EESR_RFRMER | EESR_ADE | EESR_TFE | EESR_TDE | EESR_ECI)
423 # define TX_ERROR_CEHCK (EESR_TWB | EESR_TABT | EESR_ADE | EESR_TDE | EESR_TFE)
428 DMAC_M_TWB = 0x40000000, DMAC_M_TABT = 0x04000000,
429 DMAC_M_RABT = 0x02000000,
430 DMAC_M_RFRMER = 0x01000000, DMAC_M_ADF = 0x00800000,
431 DMAC_M_ECI = 0x00400000, DMAC_M_FTC = 0x00200000,
432 DMAC_M_TDE = 0x00100000, DMAC_M_TFE = 0x00080000,
433 DMAC_M_FRC = 0x00040000, DMAC_M_RDE = 0x00020000,
434 DMAC_M_RFE = 0x00010000, DMAC_M_TINT4 = 0x00000800,
435 DMAC_M_TINT3 = 0x00000400, DMAC_M_TINT2 = 0x00000200,
436 DMAC_M_TINT1 = 0x00000100, DMAC_M_RINT8 = 0x00000080,
437 DMAC_M_RINT5 = 0x00000010, DMAC_M_RINT4 = 0x00000008,
438 DMAC_M_RINT3 = 0x00000004, DMAC_M_RINT2 = 0x00000002,
439 DMAC_M_RINT1 = 0x00000001,
442 /* Receive descriptor bit */
444 RD_RACT = 0x80000000, RD_RDLE = 0x40000000,
445 RD_RFP1 = 0x20000000, RD_RFP0 = 0x10000000,
446 RD_RFE = 0x08000000, RD_RFS10 = 0x00000200,
447 RD_RFS9 = 0x00000100, RD_RFS8 = 0x00000080,
448 RD_RFS7 = 0x00000040, RD_RFS6 = 0x00000020,
449 RD_RFS5 = 0x00000010, RD_RFS4 = 0x00000008,
450 RD_RFS3 = 0x00000004, RD_RFS2 = 0x00000002,
451 RD_RFS1 = 0x00000001,
453 #define RDF1ST RD_RFP1
454 #define RDFEND RD_RFP0
455 #define RD_RFP (RD_RFP1|RD_RFP0)
464 FCFTR_RFF2 = 0x00040000, FCFTR_RFF1 = 0x00020000,
465 FCFTR_RFF0 = 0x00010000, FCFTR_RFD2 = 0x00000004,
466 FCFTR_RFD1 = 0x00000002, FCFTR_RFD0 = 0x00000001,
468 #define FIFO_F_D_RFF (FCFTR_RFF2|FCFTR_RFF1|FCFTR_RFF0)
469 #define FIFO_F_D_RFD (FCFTR_RFD2|FCFTR_RFD1|FCFTR_RFD0)
471 /* Transfer descriptor bit */
473 #if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_ETHER)
474 TD_TACT = 0x80000000,
476 TD_TACT = 0x7fffffff,
478 TD_TDLE = 0x40000000, TD_TFP1 = 0x20000000,
479 TD_TFP0 = 0x10000000,
481 #define TDF1ST TD_TFP1
482 #define TDFEND TD_TFP0
483 #define TD_TFP (TD_TFP1|TD_TFP0)
486 enum RECV_RST_BIT { RMCR_RST = 0x01, };
488 enum FELIC_MODE_BIT {
489 #if defined(SH_ETH_TYPE_GETHER)
490 ECMR_TRCCM=0x04000000, ECMR_RCSC= 0x00800000, ECMR_DPAD= 0x00200000,
491 ECMR_RZPF = 0x00100000,
493 ECMR_ZPF = 0x00080000, ECMR_PFR = 0x00040000, ECMR_RXF = 0x00020000,
494 ECMR_TXF = 0x00010000, ECMR_MCT = 0x00002000, ECMR_PRCEF = 0x00001000,
495 ECMR_PMDE = 0x00000200, ECMR_RE = 0x00000040, ECMR_TE = 0x00000020,
496 ECMR_ILB = 0x00000008, ECMR_ELB = 0x00000004, ECMR_DM = 0x00000002,
497 ECMR_PRM = 0x00000001,
498 #ifdef CONFIG_CPU_SH7724
499 ECMR_RTM = 0x00000010,
504 #if defined(SH_ETH_TYPE_GETHER)
505 #define ECMR_CHG_DM (ECMR_TRCCM | ECMR_RZPF | ECMR_ZPF | ECMR_PFR | ECMR_RXF | \
507 #elif defined(SH_ETH_TYPE_ETHER)
508 #define ECMR_CHG_DM (ECMR_ZPF | ECMR_PFR | ECMR_RXF | ECMR_TXF)
510 #define ECMR_CHG_DM (ECMR_ZPF | ECMR_PFR | ECMR_RXF | ECMR_TXF | ECMR_MCT)
514 enum ECSR_STATUS_BIT {
515 #if defined(SH_ETH_TYPE_ETHER)
516 ECSR_BRCRX = 0x20, ECSR_PSRTO = 0x10,
519 ECSR_MPD = 0x02, ECSR_ICD = 0x01,
522 #if defined(SH_ETH_TYPE_GETHER)
523 # define ECSR_INIT (ECSR_ICD | ECSIPR_MPDIP)
525 # define ECSR_INIT (ECSR_BRCRX | ECSR_PSRTO | \
526 ECSR_LCHNG | ECSR_ICD | ECSIPR_MPDIP)
530 enum ECSIPR_STATUS_MASK_BIT {
531 #if defined(SH_ETH_TYPE_ETHER)
532 ECSIPR_BRCRXIP = 0x20,
533 ECSIPR_PSRTOIP = 0x10,
534 #elif defined(SH_ETY_TYPE_GETHER)
535 ECSIPR_PSRTOIP = 0x10,
538 ECSIPR_LCHNGIP = 0x04,
543 #if defined(SH_ETH_TYPE_GETHER)
544 # define ECSIPR_INIT (ECSIPR_LCHNGIP | ECSIPR_ICDIP | ECSIPR_MPDIP)
546 # define ECSIPR_INIT (ECSIPR_BRCRXIP | ECSIPR_PSRTOIP | ECSIPR_LCHNGIP | \
547 ECSIPR_ICDIP | ECSIPR_MPDIP)
562 DESC_I_TINT4 = 0x0800, DESC_I_TINT3 = 0x0400, DESC_I_TINT2 = 0x0200,
563 DESC_I_TINT1 = 0x0100, DESC_I_RINT8 = 0x0080, DESC_I_RINT5 = 0x0010,
564 DESC_I_RINT4 = 0x0008, DESC_I_RINT3 = 0x0004, DESC_I_RINT2 = 0x0002,
565 DESC_I_RINT1 = 0x0001,
570 RPADIR_PADS1 = 0x20000, RPADIR_PADS0 = 0x10000,
571 RPADIR_PADR = 0x0003f,
574 #if defined(SH_ETH_TYPE_GETHER)
575 # define RPADIR_INIT (0x00)
577 # define RPADIR_INIT (RPADIR_PADS1)
582 FIFO_SIZE_T = 0x00000700, FIFO_SIZE_R = 0x00000007,
585 static inline unsigned long sh_eth_reg_addr(struct sh_eth_dev *eth,
588 #if defined(SH_ETH_TYPE_GETHER)
589 const u16 *reg_offset = sh_eth_offset_gigabit;
590 #elif defined(SH_ETH_TYPE_ETHER)
591 const u16 *reg_offset = sh_eth_offset_fast_sh4;
595 return BASE_IO_ADDR + reg_offset[enum_index] + 0x800 * eth->port;
598 static inline void sh_eth_write(struct sh_eth_dev *eth, unsigned long data,
601 outl(data, sh_eth_reg_addr(eth, enum_index));
604 static inline unsigned long sh_eth_read(struct sh_eth_dev *eth,
607 return inl(sh_eth_reg_addr(eth, enum_index));