source: rtems/bsps/powerpc/gen83xx/net/network.c @ 762fa62

5
Last change on this file since 762fa62 was 031df391, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 23, 2018 at 7:53:31 AM

bsps: Move legacy network drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 7.8 KB
Line 
1/*===============================================================*\
2| Project: RTEMS support for MPC83xx                              |
3+-----------------------------------------------------------------+
4|                    Copyright (c) 2007                           |
5|                    Embedded Brains GmbH                         |
6|                    Obere Lagerstr. 30                           |
7|                    D-82178 Puchheim                             |
8|                    Germany                                      |
9|                    rtems@embedded-brains.de                     |
10+-----------------------------------------------------------------+
11| The license and distribution terms for this file may be         |
12| found in the file LICENSE in this distribution or at            |
13|                                                                 |
14| http://www.rtems.org/license/LICENSE.                           |
15|                                                                 |
16+-----------------------------------------------------------------+
17| this file contains the board specific portion                   |
18| of the network interface driver                                 |
19\*===============================================================*/
20
21#define __INSIDE_RTEMS_BSD_TCPIP_STACK__
22
23#include <rtems.h>
24#include <rtems/rtems_bsdnet.h>
25#include <rtems/rtems_bsdnet_internal.h>
26#include <bsp.h>
27#include <bsp/tsec.h>
28#include <bsp/u-boot.h>
29#include <mpc83xx/mpc83xx.h>
30#include <string.h>
31#include <libcpu/spr.h>
32
33#if MPC83XX_CHIP_TYPE / 10 != 830
34
35#define TSEC_IFMODE_RGMII 0
36#define TSEC_IFMODE_GMII  1
37
38#if defined( MPC83XX_BOARD_MPC8313ERDB)
39
40#define TSEC_IFMODE TSEC_IFMODE_RGMII
41
42#elif defined( MPC83XX_BOARD_MPC8349EAMDS)
43
44#define TSEC_IFMODE TSEC_IFMODE_GMII
45
46#elif defined( MPC83XX_BOARD_HSC_CM01)
47
48#define TSEC_IFMODE TSEC_IFMODE_RGMII
49
50#else
51
52#warning No TSEC configuration available
53
54#endif
55
56/* System Version Register */
57#define SVR 286
58SPR_RO( SVR)
59
60/* Processor Version Register */
61SPR_RO( PPC_PVR)
62
63/*=========================================================================*\
64| Function:                                                                 |
65\*-------------------------------------------------------------------------*/
66int BSP_tsec_attach
67(
68/*-------------------------------------------------------------------------*\
69| Purpose:                                                                  |
70|   attach or detach the driver                                             |
71+---------------------------------------------------------------------------+
72| Input Parameters:                                                         |
73\*-------------------------------------------------------------------------*/
74 struct rtems_bsdnet_ifconfig *config, /* interface configuration          */
75 int attaching                         /* 0 = detach, else attach          */
76)
77/*-------------------------------------------------------------------------*\
78| Return Value:                                                             |
79|    1, if success                                                       |
80\*=========================================================================*/
81{
82  tsec_config tsec_cfg;
83  int    unitNumber;
84  char *unitName;
85  uint32_t svr = _read_SVR();
86  uint32_t pvr = _read_PPC_PVR();
87
88  memset(&tsec_cfg, 0, sizeof(tsec_cfg));
89  config->drv_ctrl = &tsec_cfg;
90
91  /*
92   * Parse driver name
93   */
94  if((unitNumber = rtems_bsdnet_parse_driver_name(config, &unitName)) < 0) {
95    return 0;
96  }
97
98  tsec_cfg.reg_ptr = &mpc83xx.tsec [unitNumber - 1];
99  tsec_cfg.mdio_ptr = &mpc83xx.tsec [0];
100
101  if (attaching) {
102#if (TSEC_IFMODE==TSEC_IFMODE_GMII)
103#if !defined(MPC83XX_BOARD_HSC_CM01)
104
105      /*
106       * do not change system I/O configuration registers on HSC board
107       * because should initialize from RCW
108       */
109
110
111    if (unitNumber == 1) {
112      /*
113       * init system I/O configuration registers
114       * to ensure proper pin functions
115       */
116      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x1F800000;
117      /*
118       * init port registers (GPIO2DIR) for TSEC1
119       */
120      mpc83xx.gpio[1].gpdir = ((mpc83xx.gpio[1].gpdir & ~0x00000FFF)
121                               |                         0x0000001f);
122    }
123    if (unitNumber == 2) {
124      /*
125       * init system I/O configuration registers
126       * to ensure proper pin functions
127       */
128      mpc83xx.syscon.sicrh = mpc83xx.syscon.sicrh & ~0x007f8000;
129      /*
130       * init port registers (GPIO2DIR) for TSEC2
131       */
132      mpc83xx.gpio[0].gpdir = ((mpc83xx.gpio[0].gpdir & ~0x000FFFFF)
133                               |                         0x00087881);
134    }
135#endif /* !defined(MPC83XX_BOARD_HSC_CM01) */
136#endif
137#if (TSEC_IFMODE==TSEC_IFMODE_RGMII)
138
139    /*
140     * Nothing special needed for TSEC1 operation
141     */
142#endif
143  }
144  /*
145   * add MAC address into config->hardware_adderss
146   * FIXME: get the real address we need
147   */
148  if (config->hardware_address == NULL) {
149#if !defined(HAS_UBOOT)
150    static char hw_addr [TSEC_COUNT][6];
151    volatile tsec_registers *reg_ptr = tsec_cfg.reg_ptr;
152
153    /* read MAC address from hardware register */
154    /* we expect it htere from the boot loader */
155    config->hardware_address = hw_addr[unitNumber-1];
156
157    hw_addr[unitNumber-1][5] = (reg_ptr->macstnaddr[0] >> 24) & 0xff;
158    hw_addr[unitNumber-1][4] = (reg_ptr->macstnaddr[0] >> 16) & 0xff;
159    hw_addr[unitNumber-1][3] = (reg_ptr->macstnaddr[0] >>  8) & 0xff;
160    hw_addr[unitNumber-1][2] = (reg_ptr->macstnaddr[0] >>  0) & 0xff;
161    hw_addr[unitNumber-1][1] = (reg_ptr->macstnaddr[1] >> 24) & 0xff;
162    hw_addr[unitNumber-1][0] = (reg_ptr->macstnaddr[1] >> 16) & 0xff;
163#endif
164
165#if defined(HAS_UBOOT)
166    switch (unitNumber) {
167      case 1:
168        config->hardware_address = bsp_uboot_board_info.bi_enetaddr;
169        break;
170
171#ifdef CONFIG_HAS_ETH1
172      case 2:
173        config->hardware_address = bsp_uboot_board_info.bi_enet1addr;
174        break;
175#endif /* CONFIG_HAS_ETH1 */
176
177#ifdef CONFIG_HAS_ETH2
178      case 3:
179        config->hardware_address = bsp_uboot_board_info.bi_enet2addr;
180        break;
181#endif /* CONFIG_HAS_ETH2 */
182
183#ifdef CONFIG_HAS_ETH3
184      case 4:
185        config->hardware_address = bsp_uboot_board_info.bi_enet3addr;
186        break;
187#endif /* CONFIG_HAS_ETH3 */
188
189      default:
190        return 0;
191    }
192
193#endif /* HAS_UBOOT */
194
195  }
196  /*
197   * set interrupt number for given interface
198   */
199  config->irno = (unsigned) (
200      unitNumber == 1
201      ? BSP_IPIC_IRQ_TSEC1_TX
202      : BSP_IPIC_IRQ_TSEC2_TX
203    );
204
205  if (svr == 0x80b00010 && pvr == 0x80850010) {
206    /*
207     * This is a special case for MPC8313ERDB with silicon revision 1.  Look in
208     * "MPC8313ECE Rev. 3, 3/2008" errata for "IPIC 1".
209     */
210    if (unitNumber == 1) {
211      tsec_cfg.irq_num_tx      = 37;
212      tsec_cfg.irq_num_rx      = 36;
213      tsec_cfg.irq_num_err     = 35;
214    } else if (unitNumber == 2) {
215      tsec_cfg.irq_num_tx      = 34;
216      tsec_cfg.irq_num_rx      = 33;
217      tsec_cfg.irq_num_err     = 32;
218    } else {
219      return 0;
220    }
221  } else {
222    rtems_irq_number irno = unitNumber == 1 ?
223      BSP_IPIC_IRQ_TSEC1_TX : BSP_IPIC_IRQ_TSEC2_TX;
224
225    /* get base interrupt number (for Tx irq, Rx=base+1,Err=base+2) */
226    tsec_cfg.irq_num_tx = irno + 0;
227    tsec_cfg.irq_num_rx = irno + 1;
228    tsec_cfg.irq_num_err = irno + 2;
229  }
230
231  /*
232   * XXX: Although most hardware builders will assign the PHY addresses
233   * like this, this should be more configurable
234   */
235#ifdef MPC83XX_BOARD_MPC8313ERDB
236  if (unitNumber == 2) {
237          tsec_cfg.phy_default = 4;
238  } else {
239          /* TODO */
240          return 0;
241  }
242#else /* MPC83XX_BOARD_MPC8313ERDB */
243  tsec_cfg.phy_default = unitNumber-1;
244#endif /* MPC83XX_BOARD_MPC8313ERDB */
245
246  tsec_cfg.unit_number = unitNumber;
247  tsec_cfg.unit_name = unitName;
248
249  /*
250   * call attach function of board independent driver
251   */
252  return tsec_driver_attach_detach(config, attaching);
253}
254
255#endif /* MPC83XX_CHIP_TYPE / 10 != 830 */
Note: See TracBrowser for help on using the repository browser.