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

« back to all changes in this revision

Viewing changes to mflash.h

  • Committer: Bazaar Package Importer
  • Author(s): Benoit Mortier
  • Date: 2010-03-30 00:19:00 UTC
  • Revision ID: james.westby@ubuntu.com-20100330001900-a4oyvb4ioi6w6gvh
Tags: upstream-1.4-OFED-1.4.2
ImportĀ upstreamĀ versionĀ 1.4-OFED-1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * mflash.h - Mellanox Technilogies LTD. Flash access lib heared file
 
4
 * ==================================================================
 
5
 *
 
6
 * Copyright (c) 2005 Mellanox Technologies Ltd.  All rights reserved.
 
7
 *
 
8
 * This software is available to you under a choice of one of two
 
9
 * licenses.  You may choose to be licensed under the terms of the GNU
 
10
 * General Public License (GPL) Version 2, available from the file
 
11
 * COPYING in the main directory of this source tree, or the
 
12
 * OpenIB.org BSD license below:
 
13
 *
 
14
 *     Redistribution and use in source and binary forms, with or
 
15
 *     without modification, are permitted provided that the following
 
16
 *     conditions are met:
 
17
 *
 
18
 *      - Redistributions of source code must retain the above
 
19
 *        copyright notice, this list of conditions and the following
 
20
 *        disclaimer.
 
21
 *
 
22
 *      - Redistributions in binary form must reproduce the above
 
23
 *        copyright notice, this list of conditions and the following
 
24
 *        disclaimer in the documentation and/or other materials
 
25
 *        provided with the distribution.
 
26
 *
 
27
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
28
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
29
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
30
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 
31
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 
32
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
33
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
34
 * SOFTWARE.
 
35
 *
 
36
 *  Version: $Id: $
 
37
 *
 
38
 */
 
39
#ifndef MFLASH_H
 
40
#define MFLASH_H
 
41
 
 
42
#ifndef __WIN__
 
43
#include <sys/types.h>
 
44
#endif
 
45
 
 
46
#ifdef __cplusplus
 
47
#define EXTERN_C_START extern "C" {
 
48
#define EXTERN_C_END   }
 
49
#else
 
50
#define EXTERN_C_START
 
51
#define EXTERN_C_END
 
52
#endif
 
53
 
 
54
EXTERN_C_START
 
55
 
 
56
typedef enum MfCommandSet {
 
57
    CS_INTEL  = 1,
 
58
    CS_AMD    = 2,
 
59
 
 
60
    MCS_STSPI = 0x80  // This is not a "real" CFI command set - it's used as a "Meta" command set number.
 
61
} MfCommandSet;
 
62
 
 
63
typedef enum MfError {
 
64
    MFE_OK = 0,
 
65
    MFE_ERROR,
 
66
    MFE_BAD_PARAMS,
 
67
    MFE_CR_ERROR,
 
68
    MFE_INVAL,
 
69
    MFE_NOT_IMPLEMENTED,
 
70
    MFE_UNSUPPORTED_FLASH_TOPOLOGY,
 
71
    MFE_UNSUPPORTED_FLASH_TYPE,
 
72
    MFE_CFI_FAILED,
 
73
    MFE_TIMEOUT,
 
74
    MFE_ERASE_TIMEOUT,
 
75
    MFE_WRITE_TIMEOUT,
 
76
    MFE_ERASE_ERROR,
 
77
    MFE_WRITE_ERROR,
 
78
    MFE_BAD_ALIGN,
 
79
    MFE_SEM_LOCKED,
 
80
    MFE_VERIFY_ERROR,
 
81
    MFE_NOMEM,
 
82
    MFE_OUT_OF_RANGE,
 
83
    MFE_CMD_SUPPORTED_INBAND_ONLY,
 
84
    MFE_LAST
 
85
} MfError;
 
86
 
 
87
typedef enum MfOpt {
 
88
    MFO_NO_VERIFY = 0,
 
89
    MFO_AMD_UNLOCK_BYPASS,
 
90
    MFO_AMD_BYTE_MODE,
 
91
    MFO_IGNORE_SEM_LOCK,
 
92
    MFO_CLOSE_MF_ON_EXIT,
 
93
    MFO_LAST
 
94
} MfOpt;
 
95
 
 
96
/////////////////////////////////////////////
 
97
//
 
98
// Flash attributes struct
 
99
//
 
100
/////////////////////////////////////////////
 
101
typedef struct flash_attr {
 
102
    //
 
103
    // hw_dev_id    hw dev id of the HCA.
 
104
    //
 
105
    u_int32_t hw_dev_id;
 
106
 
 
107
    //
 
108
    // size:        Total size (in bytes) of all flash devices connected to
 
109
    //              the device (forming a contigous address space)
 
110
    //
 
111
    u_int32_t size;
 
112
 
 
113
    //
 
114
    // sector_size: Flash sector size (in bytes).
 
115
    //              Assuming a single sector size for the flash.
 
116
    //
 
117
    u_int32_t sector_size;
 
118
 
 
119
    int       num_erase_blocks;         // Number of sector defs.
 
120
    struct {
 
121
        unsigned long sector_size;      // Byte size of sector
 
122
        int           num_sectors;      // Num sectors of this size
 
123
        u_int32_t     sector_mask;      // Sector mask
 
124
    } erase_block[8];
 
125
 
 
126
    //
 
127
    // bank_size:   Different bank means a different chip sellect or gpio settings is needed when crossing
 
128
    //              this alignment.
 
129
    //              This may indicate a different flash device (for SPI flash in InfiniHostIIILx / ConnectX).
 
130
    //              Or GPIO change for parallel flash (in InfiniHostIII / InfiniHost)
 
131
    //
 
132
    int bank_size;
 
133
    int log2_bank_size;
 
134
 
 
135
    //
 
136
    // Command set (taken from CFI terminology)
 
137
    //
 
138
    int command_set;
 
139
 
 
140
    //
 
141
    // block_write - if block write is supported, holds the block size in bytes. 0 otherwise.
 
142
    //               The meaning of "block write" is not the same in parallel and serial flash.
 
143
    //
 
144
    int block_write;
 
145
 
 
146
    //
 
147
    // page_write -  if page write is supported, holds the page size in bytes. 0 otherwise.
 
148
    //
 
149
    int page_write;
 
150
 
 
151
} flash_attr;
 
152
 
 
153
 
 
154
/////////////////////////////////////////////
 
155
//
 
156
// MFLASH INTERFACE FUNCTIONS
 
157
//
 
158
// Return value:
 
159
// All functions returns MfError enum values.
 
160
//
 
161
/////////////////////////////////////////////
 
162
 
 
163
struct mfile_t;
 
164
typedef struct mflash mflash;
 
165
 
 
166
//
 
167
// open/close functions:
 
168
// This lib is used pretty much like a C file: open it, use and close when done.
 
169
//
 
170
// mf_open(): Allocates and init the mflash object to be used with the other lib funcs.
 
171
//   OUT: pmfl - The opened mflash struct is returned here.
 
172
//   IN : dev  - The string name of the crspace device to use.
 
173
//
 
174
// mf_opend(): Same as mf_open, but uses an already opened crspace device.
 
175
//
 
176
// mf_open_ignore_lock() :
 
177
//   THIS FUNCTION IS NOT SAFE -
 
178
//   It ignores the flash semaphore during flash init sequence.
 
179
//   Use only after one of the above open() failed because of MFE_SEM_LOCKED
 
180
//   and you are absolutely sure that the lock can be overridden (E.G. semaphore
 
181
//   remained in locked state due to previous kill of the burning app).
 
182
//
 
183
// mf_close() : Deallocates mflash resources.
 
184
//   Note: User should call mf_close() even if mf_open failed (and the returning mfl is not NULL)
 
185
//
 
186
int     mf_open        (mflash** pmfl, const char* dev);
 
187
int     mf_opend       (mflash** pmfl, struct mfile_t* mf);
 
188
int     mf_open_ignore_lock(mflash* mfl);
 
189
int     mf_close       (mflash* mfl);
 
190
 
 
191
//
 
192
// Flash access functions:
 
193
// The data buffer should be pre-allocated by caller. The rest is quite self explanatory. .
 
194
//
 
195
int     mf_read        (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
 
196
int     mf_write       (mflash* mfl, u_int32_t addr, u_int32_t len, u_int8_t* data);
 
197
int     mf_erase_sector(mflash* mfl, u_int32_t addr);
 
198
 
 
199
//
 
200
// Crspace access through mflash:
 
201
//
 
202
int     mf_cr_read     (mflash* mfl, u_int32_t cr_addr, u_int32_t* data);
 
203
int     mf_cr_write    (mflash* mfl, u_int32_t cr_addr, u_int32_t  data);
 
204
 
 
205
// Software reset the target device. Currently supported for InfiniScale4 switch via IB interface only.
 
206
int     mf_sw_reset     (mflash* mfl);
 
207
//
 
208
// mf_get_attr(): Returns the flash_attr struct
 
209
//
 
210
int     mf_get_attr    (mflash* mfl, flash_attr* attr);
 
211
 
 
212
//
 
213
// Set/Get for some options.
 
214
//
 
215
int     mf_set_opt     (mflash* mfl, MfOpt opt, int  val);
 
216
int     mf_get_opt     (mflash* mfl, MfOpt opt, int *val);
 
217
 
 
218
//
 
219
// err code to string translation for printing.
 
220
//
 
221
const char* mf_err2str (int err_code);
 
222
 
 
223
EXTERN_C_END
 
224
 
 
225
#endif // MFLASH_H
 
226
 
 
227
 
 
228