summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/powerpc/qoriq/network/network.c
blob: 76c9cfacffbb5ea8dd220d89eadb85d96505849b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
 * @file
 *
 * @ingroup QorIQ
 *
 * @brief Network configuration.
 */

/*
 * Copyright (c) 2010 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Obere Lagerstr. 30
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.com/license/LICENSE.
 */

#define __INSIDE_RTEMS_BSD_TCPIP_STACK__ 1
#define __BSD_VISIBLE 1

#include <assert.h>
#include <string.h>

#include <rtems/rtems_bsdnet.h>
#include <rtems/rtems_bsdnet_internal.h>

#include <libcpu/powerpc-utility.h>

#include <bsp.h>
#include <bsp/tsec.h>
#include <bsp/u-boot.h>
#include <bsp/qoriq.h>

int BSP_tsec_attach(
  struct rtems_bsdnet_ifconfig *config,
  int attaching
)
{
  char *unit_name = NULL;
  int unit_number = rtems_bsdnet_parse_driver_name(config, &unit_name);
  tsec_config tsec_cfg;
  bool has_groups = false;

  memset(&tsec_cfg, 0, sizeof(tsec_cfg));
  config->drv_ctrl = &tsec_cfg;

  if (unit_number <= 0 || unit_number > TSEC_COUNT) {
    return 0;
  }

  switch (ppc_fsl_system_version_sid(ppc_fsl_system_version())) {
    /* P1010 and P1020 */
    case 0x0ec:
    case 0x0e4:
    case 0x0ed:
    case 0x0e5:
      has_groups = true;
      break;
  }

  if (config->hardware_address == NULL) {
    #ifdef HAS_UBOOT
      switch (unit_number) {
        case 1:
          config->hardware_address = bsp_uboot_board_info.bi_enetaddr;
          break;
        case 2:
          config->hardware_address = bsp_uboot_board_info.bi_enet1addr;
          break;
        case 3:
          config->hardware_address = bsp_uboot_board_info.bi_enet2addr;
          break;
        default:
	  assert(0);
          break;
      }
    #else
      assert(0);
    #endif
  }

  switch (unit_number) {
    case 1:
      if (has_groups) {
        tsec_cfg.reg_ptr = &qoriq.tsec_1_group_0;
      } else {
        tsec_cfg.reg_ptr = &qoriq.tsec_1;
      }
      tsec_cfg.mdio_ptr = &qoriq.tsec_1;
      tsec_cfg.irq_num_tx = QORIQ_IRQ_ETSEC_TX_1;
      tsec_cfg.irq_num_rx = QORIQ_IRQ_ETSEC_RX_1;
      tsec_cfg.irq_num_err = QORIQ_IRQ_ETSEC_ER_1;
      tsec_cfg.phy_default = QORIQ_ETSEC_1_PHY_ADDR;
      break;
    case 2:
      if (has_groups) {
        tsec_cfg.reg_ptr = &qoriq.tsec_2_group_0;
      } else {
        tsec_cfg.reg_ptr = &qoriq.tsec_2;
      }
      tsec_cfg.mdio_ptr = &qoriq.tsec_1;
      tsec_cfg.irq_num_tx = QORIQ_IRQ_ETSEC_TX_2;
      tsec_cfg.irq_num_rx = QORIQ_IRQ_ETSEC_RX_2;
      tsec_cfg.irq_num_err = QORIQ_IRQ_ETSEC_ER_2;
      tsec_cfg.phy_default = QORIQ_ETSEC_2_PHY_ADDR;
      break;
    case 3:
      if (has_groups) {
        tsec_cfg.reg_ptr = &qoriq.tsec_3_group_0;
      } else {
        tsec_cfg.reg_ptr = &qoriq.tsec_3;
      }
      tsec_cfg.mdio_ptr = &qoriq.tsec_1;
      tsec_cfg.irq_num_tx = QORIQ_IRQ_ETSEC_TX_3;
      tsec_cfg.irq_num_rx = QORIQ_IRQ_ETSEC_RX_3;
      tsec_cfg.irq_num_err = QORIQ_IRQ_ETSEC_ER_3;
      tsec_cfg.phy_default = QORIQ_ETSEC_3_PHY_ADDR;
      break;
    default:
      assert(0);
      break;
  }

  tsec_cfg.unit_number = unit_number;
  tsec_cfg.unit_name = unit_name;

  return tsec_driver_attach_detach(config, attaching);
}