3
* mflash.h - Mellanox Technilogies LTD. Flash access lib heared file
4
* ==================================================================
6
* Copyright (c) 2005 Mellanox Technologies Ltd. All rights reserved.
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:
14
* Redistribution and use in source and binary forms, with or
15
* without modification, are permitted provided that the following
18
* - Redistributions of source code must retain the above
19
* copyright notice, this list of conditions and the following
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.
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
43
#include <sys/types.h>
47
#define EXTERN_C_START extern "C" {
48
#define EXTERN_C_END }
50
#define EXTERN_C_START
56
typedef enum MfCommandSet {
60
MCS_STSPI = 0x80 // This is not a "real" CFI command set - it's used as a "Meta" command set number.
63
typedef enum MfError {
70
MFE_UNSUPPORTED_FLASH_TOPOLOGY,
71
MFE_UNSUPPORTED_FLASH_TYPE,
83
MFE_CMD_SUPPORTED_INBAND_ONLY,
89
MFO_AMD_UNLOCK_BYPASS,
96
/////////////////////////////////////////////
98
// Flash attributes struct
100
/////////////////////////////////////////////
101
typedef struct flash_attr {
103
// hw_dev_id hw dev id of the HCA.
108
// size: Total size (in bytes) of all flash devices connected to
109
// the device (forming a contigous address space)
114
// sector_size: Flash sector size (in bytes).
115
// Assuming a single sector size for the flash.
117
u_int32_t sector_size;
119
int num_erase_blocks; // Number of sector defs.
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
127
// bank_size: Different bank means a different chip sellect or gpio settings is needed when crossing
129
// This may indicate a different flash device (for SPI flash in InfiniHostIIILx / ConnectX).
130
// Or GPIO change for parallel flash (in InfiniHostIII / InfiniHost)
136
// Command set (taken from CFI terminology)
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.
147
// page_write - if page write is supported, holds the page size in bytes. 0 otherwise.
154
/////////////////////////////////////////////
156
// MFLASH INTERFACE FUNCTIONS
159
// All functions returns MfError enum values.
161
/////////////////////////////////////////////
164
typedef struct mflash mflash;
167
// open/close functions:
168
// This lib is used pretty much like a C file: open it, use and close when done.
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.
174
// mf_opend(): Same as mf_open, but uses an already opened crspace device.
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).
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)
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);
192
// Flash access functions:
193
// The data buffer should be pre-allocated by caller. The rest is quite self explanatory. .
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);
200
// Crspace access through mflash:
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);
205
// Software reset the target device. Currently supported for InfiniScale4 switch via IB interface only.
206
int mf_sw_reset (mflash* mfl);
208
// mf_get_attr(): Returns the flash_attr struct
210
int mf_get_attr (mflash* mfl, flash_attr* attr);
213
// Set/Get for some options.
215
int mf_set_opt (mflash* mfl, MfOpt opt, int val);
216
int mf_get_opt (mflash* mfl, MfOpt opt, int *val);
219
// err code to string translation for printing.
221
const char* mf_err2str (int err_code);