summaryrefslogtreecommitdiff
path: root/ManageabilityPkg/Universal/IpmiSolStatus/SolStatus.c
blob: 7212c1582bb64ac3fce276dd12dc2296aa95dd2d (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
/** @file
  IPMI Serial Over Lan Driver.

Copyright (c) 2018 - 2019, Intel Corporation. All rights reserved.<BR>
Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#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>

#define SOL_CMD_RETRY_COUNT  10

/**

Routine Description:

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

Arguments:
    @param[in] Channel  LAN channel number.
    @param[in] ParamSel Configuration parameter selection.
    @param[in, out] Data     Information returned from BMC.
Returns:
    @retval EFI_SUCCESS     SOL configuration parameters are successfully read from BMC.
    @retval 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;
  IPMI_GET_SOL_CONFIGURATION_PARAMETERS_REQUEST   GetConfigurationParametersRequest;
  IPMI_GET_SOL_CONFIGURATION_PARAMETERS_RESPONSE  GetConfigurationParametersResponse;
  UINT32                                          DataSize;
  UINT8                                           RetryCount;

  Status = EFI_SUCCESS;
  for (RetryCount = 0; RetryCount < SOL_CMD_RETRY_COUNT; RetryCount++) {
    ZeroMem (&GetConfigurationParametersRequest, sizeof (GetConfigurationParametersRequest));
    GetConfigurationParametersRequest.ChannelNumber.Bits.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:
    @param[in] Channel   LAN channel number.
    @param[in] ParamSel  Configuration parameter selection.
    @param[in] Data      Configuration parameter values.
Returns:
    @retval EFI_SUCCESS     SOL configuration parameters are sent to BMC.
    @retval 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;
  IPMI_SET_SOL_CONFIGURATION_PARAMETERS_REQUEST  SetConfigurationParametersRequest;
  UINT8                                          CompletionCode;
  UINT8                                          RetryCount;

  Status = EFI_SUCCESS;
  for (RetryCount = 0; RetryCount < SOL_CMD_RETRY_COUNT; RetryCount++) {
    ZeroMem (&SetConfigurationParametersRequest, sizeof (SetConfigurationParametersRequest));
    SetConfigurationParametersRequest.ChannelNumber.Bits.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;
}

/**

  Routine Description:
    This is the standard EFI driver point. This function initializes
    the private data required for creating SOL Status Driver.

  @param[in] ImageHandle - Handle of this driver image
  @param[in] SystemTable - Table containing standard EFI services

  @retval EFI_SUCCESS    - SOL status is initialized successfully.
  @retval Otherwise      - Other errors.

**/
EFI_STATUS
EFIAPI
SolStatusEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS  Status;
  UINT8       Channel;
  BOOLEAN     SolEnabled;

  Status     = EFI_SUCCESS;
  SolEnabled = FALSE;
  for (Channel = 1; Channel <= PcdGet8 (PcdMaxSolChannels); Channel++) {
    Status = GetSolStatus (Channel, IPMI_SOL_CONFIGURATION_PARAMETER_SOL_ENABLE, &SolEnabled);
    if (Status == EFI_SUCCESS) {
      DEBUG ((DEBUG_ERROR, "SOL enabling status for channel %x is %x\n", Channel, SolEnabled));
    } else {
      DEBUG ((DEBUG_ERROR, "Failed to get channel %x SOL status from BMC!, status is %x\n", Channel, Status));
    }
  }

  return Status;
}