summaryrefslogtreecommitdiffstats
path: root/private/ntos/fw/mips/jzether.c
blob: 013c5156db2d9a368883faa9033df14b4a1906aa (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*++

Copyright (c) 1991  Microsoft Corporation

Module Name:

    jzether.c

Abstract:

    This module contains the Jazz ethernet address setup code.

Author:

    David M. Robinson (davidro) 9-Aug-1991

Revision History:

--*/



#include "jzsetup.h"

VOID
JzSetEthernet (
    VOID
    )

/*++

Routine Description:

Arguments:

Return Value:

--*/
{
    ARC_STATUS Status;
    UCHAR Address[8];
    ULONG Index;
    UCHAR Character;
    ULONG Count;
    ULONG Protected;
    PUCHAR NvramAddress = (PUCHAR)NVRAM_SYSTEM_ID;
    ULONG Nibble, ByteSum, CheckSum;
    CHAR PromptAddress[16];
    PCONFIGURATION_COMPONENT ParentComponent, NetworkComponent;
    UCHAR Data[sizeof(CM_PARTIAL_RESOURCE_LIST) +
               sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 8 +
               sizeof(CM_FLOPPY_DEVICE_DATA)];
    PCM_PARTIAL_RESOURCE_LIST List = (PCM_PARTIAL_RESOURCE_LIST)Data;
    PCM_SONIC_DEVICE_DATA SonicDeviceData;

    //
    // Get and display current ethernet address.
    //

    for (Index = 0; Index < 8 ; Index++ ) {
        Address[Index] = READ_REGISTER_UCHAR(&NvramAddress[Index]);
    }
    JzSetPosition( 3, 5);

    JzPrint(JZ_CURRENT_ENET_MSG);
    for (Index = 0; Index < 6 ; Index++) {
        JzPrint("%02lx", Address[Index]);
    }

    JzSetPosition( 4, 5);

//    Protected = READ_REGISTER_ULONG (&DMA_CONTROL->SystemSecurity.Long);
//    if ((Protected & (~READ_ONLY_DISABLE_WRITE))==0) {
//        JzPrint("The NVRAM is ReadOnly, cannot write new address\r\n");
//    } else {

        JzPrint(JZ_NEW_ENET_MSG);
        while (FwGetString( PromptAddress,
                            sizeof(PromptAddress),
                            NULL,
                            4,
                            5 + strlen(JZ_NEW_ENET_MSG)) > GetStringEscape ) {
        }

        if (*PromptAddress == 0) {
            return;
        }

        JzSetPosition( 5, 5);
        if (strlen(PromptAddress) == 12) {
            CheckSum=0;
            for (Index = 0; Index < 12; Index += 2) {

                //
                // Convert each nibble pair to a byte.
                //

                Nibble = ((PromptAddress[Index] >= '0') && (PromptAddress[Index] <= '9')) ?
                         PromptAddress[Index] - '0' :
                         tolower(PromptAddress[Index]) - 'a' + 10;
                ByteSum = (Nibble << 4);
                Nibble = ((PromptAddress[Index+1] >= '0') && (PromptAddress[Index+1] <= '9')) ?
                         PromptAddress[Index+1] - '0' :
                         tolower(PromptAddress[Index+1]) - 'a' + 10;

                ByteSum |= Nibble;
                WRITE_REGISTER_UCHAR( &NvramAddress[Index/2], ByteSum);

                CheckSum += ByteSum;
                if (CheckSum >= 256) {          // carry
                    CheckSum++;                 // Add the carry
                    CheckSum &= 0xFF;           // remove it from bit 9
                }
            }

            WRITE_REGISTER_UCHAR( &NvramAddress[6], 0);
            WRITE_REGISTER_UCHAR( &NvramAddress[7], 0xFF - CheckSum);

            for (Index = 0; Index < 8 ; Index++ ) {
                Address[Index] = READ_REGISTER_UCHAR(&NvramAddress[Index]);
            }

            JzPrint(JZ_WRITTEN_ENET_MSG);

            for (Index = 0; Index < 8 ; Index++) {
                JzPrint("%02lx", Address[Index]);
            }

            JzSetPosition( 6, 5);
            NetworkComponent = ArcGetComponent("multi()net()");
            if ((NetworkComponent != NULL) &&
                (NetworkComponent->Type == NetworkController)) {
                JzPrint(JZ_FOUND_NET_MSG);
                ParentComponent = ArcGetParent(NetworkComponent);
                if (ArcDeleteComponent(NetworkComponent) == ESUCCESS) {
                    JzAddNetwork( ParentComponent );
                    JzPrint(JZ_FIXED_MSG);
                } else {
                    JzPrint(JZ_NOT_FIXED_MSG);
                }
            }

        } else {
            JzPrint(JZ_INVALID_ENET_MSG);
        }
//    }

    //
    // Save configuration in Nvram.
    //

    JzSetPosition( 7, 4);
    JzPrint(JZ_SAVE_CONFIG_MSG);
    ArcSaveConfiguration();

    JzSetPosition( 8, 4);
    FwWaitForKeypress();
}