summaryrefslogtreecommitdiff
path: root/Platform/Intel/AdvancedFeaturePkg/Ipmi/SolStatus/SolStatus.c
blob: 6d2dbd5beab5c8fe3fd7394ba9b46eb8cc53227e (plain)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/** @file
  IPMI Serial Over Lan Driver.

Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/IpmiCommandLib.h>
#include <IndustryStandard/Ipmi.h>
#include <IpmiEx.h>

#define SOL_CMD_RETRY_COUNT           10

/*++

Routine Description:

    This routine gets the SOL payload status or settings for a specific channel.

Arguments:
    Channel         - LAN channel naumber.
    ParamSel        - Configuration parameter selection.
    Data            - Information returned from BMC.
Returns:
    EFI_SUCCESS     - SOL configuration parameters are successfully read from BMC.
    Others          - SOL configuration parameters could not be read from BMC.

--*/
EFI_STATUS
GetSOLStatus (
  IN UINT8                             Channel,
  IN UINT8                             ParamSel,
  IN OUT UINT8                         *Data
  )
{
  EFI_STATUS                                     Status = EFI_SUCCESS;
  IPMI_GET_SOL_CONFIGURATION_PARAMETERS_REQUEST  GetConfigurationParametersRequest;
  IPMI_GET_SOL_CONFIGURATION_PARAMETERS_RESPONSE GetConfigurationParametersResponse;
  UINT32                                         DataSize;
  UINT8                                          RetryCount;

  for (RetryCount = 0; RetryCount < SOL_CMD_RETRY_COUNT; RetryCount++) {
    ZeroMem (&GetConfigurationParametersRequest, sizeof(GetConfigurationParametersRequest));
    GetConfigurationParametersRequest.ChannelNumber     = Channel;
    GetConfigurationParametersRequest.ParameterSelector = ParamSel;

    ZeroMem (&GetConfigurationParametersResponse, sizeof(GetConfigurationParametersResponse));

    DataSize = sizeof(GetConfigurationParametersResponse);
    Status = IpmiGetSolConfigurationParameters (
               &GetConfigurationParametersRequest,
               &GetConfigurationParametersResponse,
               &DataSize
               );

	  if (Status == EFI_SUCCESS){
      break;
    } else {
      gBS->Stall(100000);
    }
  }

  if (Status == EFI_SUCCESS) {
    *Data = GetConfigurationParametersResponse.ParameterData[0];
  }
  
  return Status;
}

/*++

Routine Description:

    This routine sets the SOL payload configuration parameters for a specific channel.

Arguments:
    Channel         - LAN channel naumber.
    ParamSel        - Configuration parameter selection.
    Data            - Configuration parameter values.
Returns:
    EFI_SUCCESS     - SOL configuration parameters are sent to BMC.
    Others          - SOL configuration parameters could not be sent to BMC.

--*/
EFI_STATUS
SetSOLParams (
  IN UINT8                             Channel,
  IN UINT8                             ParamSel,
  IN UINT8                             Data
  )
{
  EFI_STATUS                                     Status = EFI_SUCCESS;
  IPMI_SET_SOL_CONFIGURATION_PARAMETERS_REQUEST  SetConfigurationParametersRequest;
  UINT8                                          CompletionCode;
  UINT8                                          RetryCount;

  for (RetryCount = 0; RetryCount < SOL_CMD_RETRY_COUNT; RetryCount++) {
    ZeroMem (&SetConfigurationParametersRequest, sizeof(SetConfigurationParametersRequest));
    SetConfigurationParametersRequest.ChannelNumber     = Channel;
    SetConfigurationParametersRequest.ParameterSelector = ParamSel;
    SetConfigurationParametersRequest.ParameterData[0]  = Data;

    CompletionCode = 0;

    Status = IpmiSetSolConfigurationParameters (
               &SetConfigurationParametersRequest,
               sizeof(SetConfigurationParametersRequest),
               &CompletionCode
               );

	  if (Status == EFI_SUCCESS) {
      break;
    } else {
      gBS->Stall(100000);
    }
  }

  return Status;
}

EFI_STATUS
EFIAPI
SolStatusEntryPoint (
  IN EFI_HANDLE         ImageHandle,
  IN EFI_SYSTEM_TABLE   *SystemTable
  )
/*++
  
  Routine Description:
    This is the standard EFI driver point. This function intitializes
    the private data required for creating SOL Status Driver.
    
  Arguments:
    ImageHandle     - Handle for the image of this driver
    SystemTable     - Pointer to the EFI System Table

  Returns:
    EFI_SUCCESS     - Protocol successfully installed
    EFI_UNSUPPORTED - Protocol can't be installed.

--*/
{
  EFI_STATUS  Status = EFI_SUCCESS;
  UINT8       Channel;
  BOOLEAN     Enabled = FALSE;
  BOOLEAN     SOLEnabled = FALSE;
  
  for (Channel = 1; Channel <= PcdGet8(PcdMaxSOLChannels); Channel++) {
    Status = GetSOLStatus (Channel, IPMI_SOL_CONFIGURATION_PARAMETER_SOL_ENABLE, &Enabled);
    if (Status == EFI_SUCCESS) {
      if (Enabled == TRUE) {
        SOLEnabled = TRUE;
	    }  
      DEBUG ((EFI_D_ERROR, "SOL enabling status for channel %x is %x\n", Channel, Enabled));
    } else {
      DEBUG ((EFI_D_ERROR, "Failed to get channel %x SOL status from BMC!, status is %x\n", Channel, Status));
    }
  }

  return Status;
}