summaryrefslogtreecommitdiffstats
path: root/src/occ_gpe0/firdata/ipmidd.H
blob: 18eebbfa1380750f75db41e35ffcc79289745983 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_405/firdata/ipmidd.H $                                */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2018                             */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __IPMI_IPMIDD_H
#define __IPMI_IMPIDD_H

#include <stdint.h>

/** @file ipmidd.h
 *  @brief Provides the interfaces to the IPMI Device Driver
 */

namespace IPMI
{
    enum network_function
    {
        NETFUN_IBM  = (0x3a << 2),
        PNOR_CMD = 0x5a,
    };

    enum completion_code
    {
        CC_OK        = 0x00,
        CC_CMDSPC1   = 0x80, // command specific completion code
        CC_CMDSPC2   = 0x81, // command specific completion code
        CC_BUSY      = 0xc0,
        CC_INVALID   = 0xc1,
        CC_CMDLUN    = 0xc2,
        CC_TIMEOUT   = 0xc3,
        CC_NOSPACE   = 0xc4,
        CC_BADRESV   = 0xc5,
        CC_TRUNC     = 0xc6,
        CC_BADLEN    = 0xc7,
        CC_TOOLONG   = 0xc8,
        CC_OORANGE   = 0xc9,
        CC_LONGREPLY = 0xca,
        CC_BADSENSOR = 0xcb,
        CC_REQINVAL  = 0xcc,
        CC_CMDSENSOR = 0xcd,
        CC_CANTREPLY = 0xce,
        CC_DUPREQ    = 0xcf,
        CC_SDRUPDATE = 0xd0,
        CC_FMWUPDATE = 0xd1,
        CC_BMCINIT   = 0xd2,
        CC_BADDEST   = 0xd3,
        CC_NOPERM    = 0xd4,
        CC_BADSTATE  = 0xd5,
        CC_ILLPARAM  = 0xd6,
        CC_UNKBAD    = 0xff
    };
};

enum {
    // Registers. These are fixed for LPC/BT so we can hard-wire them
    REG_CONTROL = 0xE4,
    REG_HOSTBMC = 0xE5,
    REG_INTMASK = 0xE6,

    // Control register bits. The control register is interesting in that
    // writing 0's never does anything; all registers are either set to 1
    // when written with a 1 or toggled (1/0) when written with a one. So,
    // we don't ever need to read-modify-write, we can just write an or'd
    // mask of bits.
    CTRL_B_BUSY        = (1 << 7),
    CTRL_H_BUSY        = (1 << 6),
    CTRL_OEM0          = (1 << 5),
    CTRL_SMS_ATN       = (1 << 4),
    CTRL_B2H_ATN       = (1 << 3),
    CTRL_H2B_ATN       = (1 << 2),
    CTRL_CLR_RD_PTR    = (1 << 1),
    CTRL_CLR_WR_PTR    = (1 << 0),

    IDLE_STATE = (CTRL_B_BUSY | CTRL_B2H_ATN |
                  CTRL_SMS_ATN | CTRL_H2B_ATN),

    // Bit in the INMASK register which signals to the BMC
    // to reset it's end of things.
    INT_BMC_HWRST      = (1 << 7),

    // How long to sychronously wait for the device to change state
    // (in micro seconds)
    WAIT_TIME_US = 100000,
    MAX_PACKET_DATA_SIZE = 16,
    RC_IPMIDD_IDLE = 10,
    RC_IPMIDD_NOT_IDLE = 11,
    RC_IPMIDD_TIMEOUT = 12,
    RC_BAD_SEQUENCE = 13,
    RC_IPMIDD_INVALID_RESP_SIZE = 14,
    RC_IPMI_EVENT = 15,
    RC_IPMI_BUSY = 16,
};

/**
 *  @brief IPMI Device Driver Class
 *     Provides read/write message capabilities.
 */
class IpmiDD
{
    public: // data

        uint8_t iv_netfun;
        uint8_t iv_seq;
        uint8_t iv_cmd;
        uint8_t iv_cc;
        uint8_t iv_data[MAX_PACKET_DATA_SIZE];
        uint8_t iv_data_len;

  public: // intefaces
    /**
     * @brief Poll the control register
     *
     * @parm void
     */
    int pollCtrl(void);

    /**
     * @brief Performs an IPMI message read operation
     *
     * @param[out] o_msg - Destination buffer for data
     *
     * @return SUCCESS | error code
     */

    int receive(void);
    /**
     * @brief Performs an IPMI message write operation
     *
     * @param[in] i_msg - Location of data to be written
     *
     * @return SUCCESS | error code
     */
    int send(void);

    /**
     * @brief Performs a reset of the BT hardware
     *
     * @param void
     *
     * @return SUCCESS | error code
     */
    int  reset(void);

    /**
     * @brief Constructor
     *
     * @parm void
     */
    IpmiDD(uint8_t i_netfun,
           uint8_t i_cmd,
           uint8_t i_seq,
           uint8_t i_cc,
           uint8_t * i_data,
           uint8_t i_data_len);

  public:

  private:

    /**
     * @brief Read an address from LPC space
     *
     * @parm i_addr  Absolute LPC Address
     * @parm o_data  Buffer to read data into
     *
     * @return Error from operation
     */
    int readLPC(const uint32_t i_addr, uint8_t& o_data);

    /**
     * @brief Write an address from LPC space
     *
     * @parm i_addr  Absolute LPC Address
     * @parm i_data  Data to write
     *
     * @return Error from operation
     */
    int writeLPC(const uint32_t i_addr, uint8_t i_data);

  private: // Variables

    // Disallow copying this class.
    IpmiDD& operator=(const IpmiDD&);
    IpmiDD(const IpmiDD&);
};

#endif
OpenPOWER on IntegriCloud