Browse Source

[thunderx] Retrieve base MAC address via EFI_THUNDER_CONFIG_PROTOCOL

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
25ae251dd9
2 changed files with 250 additions and 1 deletions
  1. 39
    1
      src/drivers/net/thunderx.c
  2. 211
    0
      src/drivers/net/thunderxcfg.h

+ 39
- 1
src/drivers/net/thunderx.c View File

@@ -40,6 +40,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
40 40
 #include <ipxe/pciea.h>
41 41
 #include <ipxe/umalloc.h>
42 42
 #include "thunderx.h"
43
+#include "thunderxcfg.h"
43 44
 
44 45
 /** @file
45 46
  *
@@ -56,6 +57,10 @@ static LIST_HEAD ( txnic_pfs );
56 57
 /** Debug colour for physical function and BGX messages */
57 58
 #define TXNICCOL(x) ( &txnic_pfs + (x)->node )
58 59
 
60
+/** Board configuration protocol */
61
+static EFI_THUNDER_CONFIG_PROTOCOL *txcfg;
62
+EFI_REQUEST_PROTOCOL ( EFI_THUNDER_CONFIG_PROTOCOL, &txcfg );
63
+
59 64
 /******************************************************************************
60 65
  *
61 66
  * Diagnostics
@@ -1478,6 +1483,39 @@ static void txnic_bgx_init ( struct txnic_bgx *bgx, unsigned int type ) {
1478 1483
 	writeq ( global_config, ( bgx->regs + BGX_CMR_GLOBAL_CONFIG ) );
1479 1484
 }
1480 1485
 
1486
+/**
1487
+ * Get MAC address
1488
+ *
1489
+ * @v lmac		Logical MAC
1490
+ */
1491
+static void txnic_bgx_mac ( struct txnic_lmac *lmac ) {
1492
+	struct txnic_bgx *bgx = lmac->bgx;
1493
+	BOARD_CFG *boardcfg;
1494
+	NODE_CFG *nodecfg;
1495
+	BGX_CFG *bgxcfg;
1496
+	LMAC_CFG *lmaccfg;
1497
+
1498
+	/* Extract MAC from Board Configuration protocol, if available */
1499
+	if ( txcfg ) {
1500
+		boardcfg = txcfg->BoardConfig;
1501
+		nodecfg = &boardcfg->Node[ bgx->node % MAX_NODES ];
1502
+		bgxcfg = &nodecfg->BgxCfg[ bgx->idx % BGX_PER_NODE_COUNT ];
1503
+		lmaccfg = &bgxcfg->Lmacs[ lmac->idx % LMAC_PER_BGX_COUNT ];
1504
+		lmac->mac.be64 = cpu_to_be64 ( lmaccfg->MacAddress );
1505
+	} else {
1506
+		DBGC ( TXNICCOL ( bgx ), "TXNIC %d/%d/%d has no board "
1507
+		       "configuration protocol\n", bgx->node, bgx->idx,
1508
+		       lmac->idx );
1509
+	}
1510
+
1511
+	/* Use random MAC address if none available */
1512
+	if ( ! lmac->mac.be64 ) {
1513
+		DBGC ( TXNICCOL ( bgx ), "TXNIC %d/%d/%d has no MAC address\n",
1514
+		       bgx->node, bgx->idx, lmac->idx );
1515
+		eth_random_addr ( lmac->mac.raw );
1516
+	}
1517
+}
1518
+
1481 1519
 /**
1482 1520
  * Initialise Super PHY Unit (SPU)
1483 1521
  *
@@ -1533,7 +1571,7 @@ static void txnic_bgx_lmac_init ( struct txnic_bgx *bgx,
1533 1571
 	lmac->idx = TXNIC_VNIC_IDX ( bgx->idx, lmac_idx );
1534 1572
 
1535 1573
 	/* Set MAC address */
1536
-	eth_random_addr ( lmac->mac.raw );
1574
+	txnic_bgx_mac ( lmac );
1537 1575
 
1538 1576
 	/* Initialise PHY */
1539 1577
 	txnic_bgx_spu_init ( lmac );

+ 211
- 0
src/drivers/net/thunderxcfg.h View File

@@ -0,0 +1,211 @@
1
+#ifndef _THUNDERXCFG_H
2
+#define _THUNDERXCFG_H
3
+
4
+/** @file
5
+ *
6
+ * Cavium ThunderX Board Configuration
7
+ *
8
+ * The definitions in this section are extracted from BSD-licensed
9
+ * (but non-public) portions of ThunderPkg.
10
+ *
11
+ */
12
+
13
+FILE_LICENCE ( BSD2 );
14
+
15
+#include <ipxe/efi/efi.h>
16
+
17
+/******************************************************************************
18
+ *
19
+ * From ThunderxBoardConfig.h
20
+ *
21
+ ******************************************************************************
22
+ *
23
+ *  Header file for Cavium ThunderX Board Configurations
24
+ *  Copyright (c) 2015, Cavium Inc.
25
+ *  All rights reserved.
26
+ *
27
+ *  Redistribution and use in source and binary forms, with or without
28
+ *  modification, are permitted provided that the following conditions
29
+ *  are met:
30
+ *
31
+ *  1. Redistributions of source code must retain the above copyright
32
+ *     notice, this list of conditions and the following disclaimer.
33
+ *  2. Redistributions in binary form must reproduce the above
34
+ *     copyright notice, this list of conditions and the following
35
+ *     disclaimer in the documentation and/or other materials provided
36
+ *     with the distribution.
37
+ *
38
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
39
+ *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
40
+ *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
41
+ *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42
+ *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
43
+ *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
45
+ *  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
47
+ *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
48
+ *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
49
+ *  THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50
+ *  SUCH DAMAGE.
51
+ *
52
+ */
53
+
54
+#define MAX_NODES		2
55
+#define CLUSTER_COUNT		3
56
+#define CORE_PER_CLUSTER_COUNT  16
57
+#define CORE_COUNT		(CLUSTER_COUNT*CORE_PER_CLUSTER_COUNT)
58
+#define BGX_PER_NODE_COUNT	2
59
+#define LMAC_PER_BGX_COUNT	4
60
+#define PEM_PER_NODE_COUNT	6
61
+#define LMC_PER_NODE_COUNT	4
62
+#define DIMM_PER_LMC_COUNT	2
63
+
64
+#define THUNDERX_CPU_ID(node, cluster, core) (((node) << 16) | ((cluster) << 8) | (core))
65
+
66
+//TODO: Put common type definitions in separate common include file
67
+typedef enum {
68
+    BGX_MODE_SGMII, /* 1 lane, 1.250 Gbaud */
69
+    BGX_MODE_XAUI,  /* 4 lanes, 3.125 Gbaud */
70
+    BGX_MODE_DXAUI, /* 4 lanes, 6.250 Gbaud */
71
+    BGX_MODE_RXAUI, /* 2 lanes, 6.250 Gbaud */
72
+    BGX_MODE_XFI,   /* 1 lane, 10.3125 Gbaud */
73
+    BGX_MODE_XLAUI, /* 4 lanes, 10.3125 Gbaud */
74
+    BGX_MODE_10G_KR,/* 1 lane, 10.3125 Gbaud */
75
+    BGX_MODE_40G_KR,/* 4 lanes, 10.3125 Gbaud */
76
+    BGX_MODE_UNKNOWN
77
+} BGX_MODE_T;
78
+
79
+typedef enum {
80
+    EBB8800,
81
+    EBB8804,
82
+    CRB_1S,
83
+    CRB_2S,
84
+    ASIANCAT,
85
+    GBT_MT60,
86
+    INVENTEC_P3E003,
87
+    BOARD_MAX
88
+} BOARD_TYPE;
89
+
90
+typedef struct {
91
+    BOOLEAN Enabled;
92
+    UINT64  LaneToSds;
93
+    UINT64  MacAddress;
94
+} LMAC_CFG;
95
+
96
+typedef struct {
97
+    BOOLEAN BgxEnabled;
98
+    BGX_MODE_T BgxMode;
99
+    UINTN    LmacCount; //Maximum number of LMAcs
100
+    UINT64   BaseAddress;
101
+    UINT64   LmacType;
102
+    /* Bit mask of QLMs connected to this BGX */
103
+    UINT64   QlmMask;
104
+    UINT64   QlmFreq;
105
+    BOOLEAN  UseTraining;
106
+    LMAC_CFG Lmacs[LMAC_PER_BGX_COUNT];
107
+} BGX_CFG;
108
+
109
+typedef struct {
110
+    BOOLEAN PemUsable;
111
+} PEM_CFG;
112
+
113
+typedef struct {
114
+    enum { NotPresent, Empty, Available } Status;
115
+    UINT8 Type;
116
+    UINT8 SubType;
117
+    UINT8 Rank;
118
+    UINT16 Mfg;
119
+    UINTN SizeMb;
120
+    UINTN Speed;
121
+    CHAR8 Serial[16];
122
+    CHAR8 PartNo[24];
123
+} DIMM_CFG;
124
+
125
+typedef struct {
126
+    DIMM_CFG DimmCfg[DIMM_PER_LMC_COUNT];
127
+} LMC_CFG;
128
+
129
+typedef struct {
130
+    BOOLEAN Core[CORE_COUNT];
131
+    BGX_CFG BgxCfg[BGX_PER_NODE_COUNT];
132
+    PEM_CFG PemCfg[PEM_PER_NODE_COUNT];
133
+    LMC_CFG LmcCfg[LMC_PER_NODE_COUNT];
134
+    UINT64 RamStart;
135
+    UINT64 RamReserve;
136
+    UINT64 RamSize;
137
+    UINTN CPUSpeed;
138
+    UINTN CPUVersion;
139
+} NODE_CFG;
140
+
141
+#define MAX_SERIAL 32
142
+#define MAX_REVISION 32
143
+typedef struct {
144
+    BOARD_TYPE BoardType;
145
+    CHAR8 Serial[MAX_SERIAL];
146
+    CHAR8 Revision[MAX_REVISION];
147
+    UINTN NumNodes;
148
+    UINTN BmcBootTwsiBus;
149
+    UINTN BmcBootTwsiAddr;
150
+    UINTN RtcTwsiBus;
151
+    UINTN RtcTwsiAddr;
152
+    /* IPMI support*/
153
+    UINTN BmcIpmiTwsiBus;
154
+    UINTN BmcIpmiTwsiAddr;
155
+    NODE_CFG Node[MAX_NODES];
156
+    UINT16 CpuClusterCount;
157
+    UINT16 CpuPerClusterCount;
158
+    UINT16 PcieSegmentCount;
159
+    UINT64 MacAddrRangeStart;
160
+    UINTN DdrSpeed;
161
+    UINT64 AcpiOemTableId;
162
+} BOARD_CFG;
163
+
164
+/******************************************************************************
165
+ *
166
+ * From ThunderConfigProtocol.h
167
+ *
168
+ ******************************************************************************
169
+ *
170
+ *  Thunder board Configuration Protocol
171
+ *
172
+ *  Copyright (c) 2015, Cavium Inc. All rights reserved.<BR>
173
+ *
174
+ *  This program and the accompanying materials are licensed and made
175
+ *  available under the terms and conditions of the BSD License which
176
+ *  accompanies this distribution.  The full text of the license may
177
+ *  be found at http://opensource.org/licenses/bsd-license.php
178
+ *
179
+ *  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
180
+ *  BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
181
+ *  EXPRESS OR IMPLIED.
182
+ *
183
+ */
184
+
185
+#define EFI_THUNDER_CONFIG_PROTOCOL_GUID \
186
+  {0xb75a0608, 0x99ff, 0x11e5, {0x9b, 0xeb, 0x00, 0x14, 0xd1, 0xfa, 0x23, 0x5c}}
187
+
188
+///
189
+/// Forward declaration
190
+///
191
+typedef struct _EFI_THUNDER_CONFIG_PROTOCOL EFI_THUNDER_CONFIG_PROTOCOL;
192
+
193
+///
194
+/// Function prototypes
195
+///
196
+typedef
197
+EFI_STATUS
198
+(EFIAPI *EFI_THUNDER_CONFIG_PROTOCOL_GET_CONFIG)(
199
+  IN EFI_THUNDER_CONFIG_PROTOCOL  *This,
200
+  OUT BOARD_CFG** cfg
201
+  );
202
+
203
+///
204
+/// Protocol structure
205
+///
206
+typedef struct _EFI_THUNDER_CONFIG_PROTOCOL {
207
+  EFI_THUNDER_CONFIG_PROTOCOL_GET_CONFIG GetConfig;
208
+  BOARD_CFG* BoardConfig;
209
+} EFI_THUNDER_CONFIG_PROTOCOL;
210
+
211
+#endif /* _THUNDERXCFG_H */

Loading…
Cancel
Save