~ubuntu-branches/ubuntu/wily/mstflint/wily-proposed

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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 *
 * mflash.h - Mellanox Technilogies LTD. Flash access lib heared file
 * ==================================================================
 *
 * Copyright (c) 2005 Mellanox Technologies Ltd.  All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * OpenIB.org BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 *  Version: $Id: $
 *
 */
#ifndef MFLASH_H
#define MFLASH_H

#ifndef __WIN__
#include <sys/types.h>
#endif

#ifdef __cplusplus
#define EXTERN_C_START extern "C" {
#define EXTERN_C_END   }
#else
#define EXTERN_C_START
#define EXTERN_C_END
#endif

EXTERN_C_START

typedef enum MfCommandSet {
    CS_INTEL  = 1,
    CS_AMD    = 2,

    MCS_STSPI = 0x80  // This is not a "real" CFI command set - it's used as a "Meta" command set number.
} MfCommandSet;

typedef enum MfError {
    MFE_OK = 0,
    MFE_ERROR,
    MFE_BAD_PARAMS,
    MFE_CR_ERROR,
    MFE_INVAL,
    MFE_NOT_IMPLEMENTED,
    MFE_UNSUPPORTED_FLASH_TOPOLOGY,
    MFE_UNSUPPORTED_FLASH_TYPE,
    MFE_CFI_FAILED,
    MFE_TIMEOUT,
    MFE_ERASE_TIMEOUT,
    MFE_WRITE_TIMEOUT,
    MFE_ERASE_ERROR,
    MFE_WRITE_ERROR,
    MFE_BAD_ALIGN,
    MFE_SEM_LOCKED,
    MFE_VERIFY_ERROR,
    MFE_NOMEM,
    MFE_OUT_OF_RANGE,
    MFE_CMD_SUPPORTED_INBAND_ONLY,
    MFE_LAST
} MfError;

typedef enum MfOpt {
    MFO_NO_VERIFY = 0,
    MFO_AMD_UNLOCK_BYPASS,
    MFO_AMD_BYTE_MODE,
    MFO_IGNORE_SEM_LOCK,
    MFO_CLOSE_MF_ON_EXIT,
    MFO_LAST
} MfOpt;

/////////////////////////////////////////////
//
// Flash attributes struct
//
/////////////////////////////////////////////
typedef struct flash_attr {
    //
    // hw_dev_id    hw dev id of the HCA.
    //
    u_int32_t hw_dev_id;

    //
    // size:        Total size (in bytes) of all flash devices connected to
    //              the device (forming a contigous address space)
    //
    u_int32_t size;

    //
    // sector_size: Flash sector size (in bytes).
    //              Assuming a single sector size for the flash.
    //
    u_int32_t sector_size;

    int       num_erase_blocks;         // Number of sector defs.
    struct {
        unsigned long sector_size;      // Byte size of sector
        int           num_sectors;      // Num sectors of this size
        u_int32_t     sector_mask;      // Sector mask
    } erase_block[8];

    //
    // bank_size:   Different bank means a different chip sellect or gpio settings is needed when crossing
    //              this alignment.
    //              This may indicate a different flash device (for SPI flash in InfiniHostIIILx / ConnectX).
    //              Or GPIO change for parallel flash (in InfiniHostIII / InfiniHost)
    //
    int bank_size;
    int log2_bank_size;

    //
    // Command set (taken from CFI terminology)
    //
    int command_set;

    //
    // block_write - if block write is supported, holds the block size in bytes. 0 otherwise.
    //               The meaning of "block write" is not the same in parallel and serial flash.
    //
    int block_write;

    //
    // page_write -  if page write is supported, holds the page size in bytes. 0 otherwise.
    //
    int page_write;

} flash_attr;


/////////////////////////////////////////////
//
// MFLASH INTERFACE FUNCTIONS
//
// Return value:
// All functions returns MfError enum values.
//
/////////////////////////////////////////////

struct mfile_t;
typedef struct mflash mflash;

//
// open/close functions:
// This lib is used pretty much like a C file: open it, use and close when done.
//
// mf_open(): Allocates and init the mflash object to be used with the other lib funcs.
//   OUT: pmfl - The opened mflash struct is returned here.
//   IN : dev  - The string name of the crspace device to use.
//
// mf_opend(): Same as mf_open, but uses an already opened crspace device.
//
// mf_open_ignore_lock() :
//   THIS FUNCTION IS NOT SAFE -
//   It ignores the flash semaphore during flash init sequence.
//   Use only after one of the above open() failed because of MFE_SEM_LOCKED
//   and you are absolutely sure that the lock can be overridden (E.G. semaphore
//   remained in locked state due to previous kill of the burning app).
//
// mf_close() : Deallocates mflash resources.
//   Note: User should call mf_close() even if mf_open failed (and the returning mfl is not NULL)
//
int     mf_open        (mflash** pmfl, const char* dev);
int     mf_opend       (mflash** pmfl, struct mfile_t* mf);
int     mf_open_ignore_lock(mflash* mfl);
int     mf_close       (mflash* mfl);

//
// Flash access functions:
// The data buffer should be pre-allocated by caller. The rest is quite self explanatory. .
//
int     mf_read        (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
int     mf_write       (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
int     mf_erase_sector(mflash* mfl, u_int32_t addr);

//
// Crspace access through mflash:
//
int     mf_cr_read     (mflash* mfl, u_int32_t cr_addr, u_int32_t* data);
int     mf_cr_write    (mflash* mfl, u_int32_t cr_addr, u_int32_t  data);

// Software reset the target device. Currently supported for InfiniScale4 switch via IB interface only.
int     mf_sw_reset     (mflash* mfl);
//
// mf_get_attr(): Returns the flash_attr struct
//
int     mf_get_attr    (mflash* mfl, flash_attr* attr);

//
// Set/Get for some options.
//
int     mf_set_opt     (mflash* mfl, MfOpt opt, int  val);
int     mf_get_opt     (mflash* mfl, MfOpt opt, int *val);

//
// err code to string translation for printing.
//
const char* mf_err2str (int err_code);

EXTERN_C_END

#endif // MFLASH_H