Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
elxu_sky.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 #include <stdio.h>
34 #include <stdint.h>
35 #include <string.h>
36 #include <elxu_device.h>
37 #include <elxu_sky.h>
38 #include <elxu_sli4.h>
39 #include <elxu_mbox.h>
40 #include <elxu_common.h>
41 
42 typedef enum dir_e {
45 } dir_t;
46 
47 static int image_load_common(elxu_device_t *device, dir_t direction, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength);
48 
49 /**
50  * @brief Download UFI flash image component.
51  *
52  * @par Description
53  * The flash image given by 'buffer' for 'bufferLength' is
54  * passed to the flash. 'op_type' defines which flash image
55  * component is to be written.
56  *
57  *
58  * @param device Pointer to device descriptor.
59  * @param op_type flash component to update.
60  * @param buffer Pointer to memory buffer with flash data.
61  * @param bufferlength Length of flash data.
62  *
63  * @return Returns 0 on success; or a negative error code value
64  * on failure.
65  */
66 
67 int ufi_image_download(elxu_device_t *device, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
68 {
69  return image_load_common(device, DIR_WRITE, op_type, buffer, bufferLength);
70 
71 }
72 
73 /**
74  * @brief Upload UFI flash image component.
75  *
76  * @par Description
77  * The flash image 'op_type' is read into 'buffer'
78  *
79  * @param device Pointer to device descriptor.
80  * @param op_type flash component to update.
81  * @param buffer Pointer to memory buffer with flash data.
82  * @param bufferLength Length of flash data.
83  * @return Returns 0 on success; or a negative error code value
84  * on failure.
85  *
86  */
87 int ufi_image_upload(elxu_device_t *device, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
88 {
89  return image_load_common(device, DIR_READ, op_type, buffer, bufferLength);
90 }
91 
92 /**
93  * @brief Read or Write UFI flash image component
94  *
95  * @par Description
96  * Read or write UFI flash image. The request is broken
97  * up into a series of requests.
98  *
99  * @param device Pointer to device descriptor.
100  * @param direction Of transfer.
101  * @param op_type UFI flash component to update.
102  * @param buffer Pointer to memory buffer with flash data.
103  * @param bufferLength Length of flash data.
104  *
105  * @return Returns 0 on success; or a negative error code value
106  * on failure.
107  *
108  */
109 static int image_load_common(elxu_device_t *device, dir_t direction, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
110 {
111  uint32_t n;
112  uint32_t offset = 0;
113  uint32_t op_code;
114  int rval = ELXU_SUCCESS;
115 
116  while (offset < bufferLength) {
117  n = (bufferLength - offset);
118  if (n > MBOX_MAX_BUFFER) {
119  n = MBOX_MAX_BUFFER;
120  }
121 
122  switch (direction) {
123  case DIR_WRITE:
124  op_code = ((offset + n) >= bufferLength) ? MGMT_FLASHROM_OPCODE_FLASH : MGMT_FLASHROM_OPCODE_SAVE;
125  rval = mbox_write_flashrom(device, op_code, op_type, offset, buffer, n);
126  break;
127 
128  case DIR_READ:
129  rval = mbox_read_flashrom(device, MGMT_FLASHROM_OPCODE_REPORT, op_type, offset, buffer, n);
130  break;
131  }
132 
133  if (rval < 0) {
134  break;
135  }
136 
137  offset += n;
138  buffer += n;
139  }
140 
141  return rval;
142 }
143 
144 /**
145  * @brief Return length of FAT.
146  *
147  * @par Description
148  * Issues MANAGE_FAT mailbox command and returns the length of
149  * the FAT.
150  *
151  * @param device Device descriptor.
152  *
153  * @return Returns the length of the FAT on success; negative
154  * error code on failure.
155  */
157 {
158  return mbox_manage_fat(device, FAT_OPERATION_QUERY, 0, NULL, 0);
159 }
160 
161 /**
162  * @brief Read FAT.
163  *
164  * @par Description
165  * Reads FAT into buffer.
166  *
167  *
168  * @param device Device descriptor.
169  * @param buffer Read buffer.
170  * @param bufferLength Read buffer length.
171  *
172  * @return Returns the number of bytes read on success; negative
173  * error code on failure.
174  */
175 int fat_read(elxu_device_t *device, uint8_t *buffer, uint32_t bufferLength)
176 {
177  int rval = 0;
178  int fatLength;
179  uint32_t n;
180  uint32_t offset;
181 
182  // Fetch the log length
183  rval = fat_info(device);
184  if (rval < 0) {
185  return rval;
186  }
187 
188  fatLength = rval;
189  if (fatLength < bufferLength) {
190  bufferLength = fatLength;
191  }
192 
193  offset = 0;
194  while (bufferLength > 0) {
195  n = bufferLength;
196  if (n > MBOX_MAX_BUFFER) {
197  n = MBOX_MAX_BUFFER;
198  }
199 
200  rval = mbox_manage_fat(device, FAT_OPERATION_RETRIEVE, offset, buffer, n);
201  if (rval < 0) {
202  break;
203  }
204 
205  offset += n;
206  buffer += n;
207  bufferLength -= n;
208  }
209 
210  if (rval >= 0) {
211  rval = offset;
212  }
213 
214  return rval;
215 }
216 
217 /**
218  * @brief Issue EFD get capabilities mailbox command.
219  *
220  * @par Description
221  * The COMMON_GET_EXT_FAT_CAPABILIEIS mailbox command is issued.
222  * WARNING: this command will return a variable amount of data
223  * based on the configuration. There are BSG limitations that
224  * may keep all data from being correctly returned.
225  *
226  *
227  * @param device Device descriptor.
228  * @param Parameter_type parameter type (0 for default, 1 for
229  * current set).
230  * @param params Pointer to ext_fat_config_params_t structure.
231  * @param paramsLength Length of parameters structure.
232  *
233  * @return Returns 0 on success; or a negative error code value
234  * on failure.
235  */
236 int get_ext_fat_capabilities(elxu_device_t *device, uint32_t parameter_type,
237  ext_fat_config_params_t *params, uint32_t paramsLength)
238 {
239  mbox_common_get_ext_fat_capabilities_t *mbox = zmalloc(paramsLength);
240  int rval;
241 
242  mbox->params.request.parameter_type = parameter_type;
243 
244  rval = mbox_ext_fat(device, OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES, mbox, paramsLength);
245 
246  if (rval == 0) {
247  memcpy(params, &mbox->params.response, paramsLength);
248  }
249 
250  zfree(mbox);
251  return rval;
252 }
253 
254 /**
255  * @brief Issue configure EFD snapshot mailbox command.
256  *
257  * @par Description
258  * The OPCODE_COMMON_EXT_FAT_CONFIGURATION_SNAPSHOT mailbox
259  * command is issued. The command returns total log entries in
260  * the snapshot buffer.
261  *
262  *
263  * @param device Device descriptor.
264  *
265  * @return Returns the length of snapshot EFD log entries on
266  * success; negative error code on failure.
267  */
269 {
270  int rtval;
271 
273 
275 
276  if (rtval == 0) {
277  rtval = mbox->params.response.total_log_entries;
278  }
279 
280  zfree (mbox);
281  return rtval;
282 }
283 
284 
285 /**
286  * @brief Issue retrieve EFD snapshot mailbox command.
287  *
288  * @par Description
289  * The OPCODE_COMMON_EXT_FAT_RETRIEVE_SHAPSHOT mailbox command
290  * is issued. Because of BSG limitations only 32 logs are
291  * requested per read. Upper layer executing
292  * OPCODE_COMMON_EXT_FAT_CONFIGURATION_SNAPSHOT mailbox command
293  * already knows the total number of log entries.
294  *
295  *
296  * @param device Device descriptor.
297  * @param buf The EFD snapshot data buffer.
298  * @param len The buffer length.
299  * @param numlogs The number of logs to retrieve.
300  *
301  * @return Returns 0 on success; or a negative error code value
302  * on failure.
303  */
304 int ext_fat_retrieve_snapshot (elxu_device_t *device, uint8_t *buf, uint32_t len, uint32_t numlogs)
305 {
306  int rtval;
307  int logs_per_read = 32;
308  int trace_chunk;
309  uint32_t returned_bytes = 0;
310  uint32_t returned_logs = 0;
312  int mbox_len;
313  uint32_t retlogs;
314  uint8_t *rsp;
315  uint32_t struct_len = sizeof(mbox_ioctl_common_ext_fat_retrieve_snapshot_t);
316 
317 
318  mbox_len = struct_len + (logs_per_read * sizeof (arm_trace_record_t));
319 
320  mbox = zmalloc (mbox_len);
321 
322  if (mbox == NULL) {
323  return MALLOC_FAILED;
324  }
325 
326 
327  while (numlogs > 0) {
328  if (numlogs > logs_per_read) {
329  trace_chunk = logs_per_read;
330  } else {
331  trace_chunk = numlogs;
332  }
333  memset (mbox,0,mbox_len);
334 
335  mbox->params.request.snapshot_mode = EXT_FAT_RETRIEVE_MODE_VRAM;
336  mbox->params.request.start_index = returned_logs;
337  mbox->params.request.num_log_entries = trace_chunk;
338 
339  rtval = mbox_ext_fat(device,
341  mbox,
342  mbox_len);
343  if (rtval < 0)
344  {
345  printf ("Retrieving EFD data failure\n");
346  break;
347  }
348 
349  retlogs = mbox->params.response.num_log_entries;
350  rsp = (uint8_t *) &mbox->params.response;
351 
352  if (((returned_logs + retlogs) * sizeof (arm_trace_record_t)) <= len) {
353  memcpy ((buf + returned_bytes),rsp + 4, (retlogs * sizeof (arm_trace_record_t)));
354  }
355  returned_logs += retlogs;
356  returned_bytes = ( returned_logs * sizeof (arm_trace_record_t));
357  numlogs -= retlogs;
358 
359  }
360 
361  zfree (mbox);
362  return rtval;
363 }
364 
365 
366 
367 /**
368  * @brief Issue EXT_FAT_READ_STRING_TABLE mailbox command.
369  *
370  * @par Description
371  * The OPCODE_COMMON_EXT_FAT_READ_STRING_TABLE mailbox command
372  * is issued. The upper layer has to provide a number of bytes
373  * to be retrieved and the number of bytes already retrieved.
374  * The function returns the response param part of
375  * ioctl_common_ext_fat_read_string_table_t structure.
376  *
377  *
378  * @param device Device descriptor.
379  * @param tblinfo Pointer to the param response structure.
380  * @param tbl_info_len Param response structure length.
381  * @param bytes_to_read Bytes to read.
382  * @param bytes_read Bytes already read.
383  *
384  * @return Returns 0 on success; or a negative error code value
385  * on failure.
386  */
388  uint32_t tbl_info_len, uint32_t bytes_to_read, uint32_t bytes_read)
389 {
391  uint32_t ioctl_mbx_len = bytes_to_read + sizeof (*mbox);
392  int rval;
393 
394  mbox = zmalloc(ioctl_mbx_len);
395  if (mbox == NULL)
396  {
397  return MALLOC_FAILED;
398  }
399 
400  mbox->params.request.num_bytes = bytes_to_read;
401  mbox->params.request.byte_offset = bytes_read;
402 
403  rval = mbox_ext_fat(device, OPCODE_COMMON_EXT_FAT_READ_STRING_TABLE,mbox, ioctl_mbx_len);
404  if (rval == 0) {
405  memcpy(tblinfo, &mbox->params.response, tbl_info_len);
406  }
407 
408  zfree(mbox);
409  return rval;
410 }
411 
412 /**
413 * @page elxsdkutil_oce11102.html OCe11102 Adapters
414 *
415 * @section oce11102_fw_download Firmware Download API
416 *
417 * The OCe11102 firmware download API consists of the functions shown in the
418 * following table.
419 *
420 * <table class="dashboard">
421 * <tr><th>Function Name</th><th>Description</th></tr>
422 * <tr><td>ufi_image_download()</td><td>Download OCe11100 flash image component.</td></tr>
423 * <tr><td>ufi_image_upload()</td><td>Upload OCe11100 flash image component.</td></tr>
424 * </table>
425 *
426 *
427 * @section oce11102_fat FAT File API
428 *
429 * The OCe11102 FAT file API consists of the functions shown in the
430 * following table.
431 *
432 * <table class="dashboard">
433 * <tr><th>Function Name</th><th>Description</th></tr>
434 * <tr><td>fat_info()</td><td>Return length of the FAT.</td></tr>
435 * <tr><td>fat_read()</td><td>Read the FAT.</td></tr>
436 * </table>
437 *
438 *
439 * @section oce11102_efd EFD File API
440 *
441 * The OCe11102 EFD file API consists of the functions shown in the
442 * following table.
443 *
444 * <table class="dashboard">
445 * <tr><th>Function Name</th><th>Description</th></tr>
446 * <tr><td>ext_fat_read_string_table()</td><td>Issues the OPCODE_COMMON_EXT_FAT_READ_STRING_TABLE mailbox command.</td></tr>
447 * <tr><td>ext_fat_read_string_table_upld()</td><td>FAT data upload functionality.</td></tr>
448 * <tr><td>ext_fat_retrieve_snapshot()</td><td>Issues the COMMON_EXT_FAT_RETRIEVE_SNAPSHOT command.</td></tr>
449 * <tr><td>ext_fat_snapshot_upload()</td><td>EXT FAT data upload functionality.</td></tr>
450 * </table>
451 *
452 *
453 * @section oce11102_flash Flash Access APIs
454 *
455 * The OCe11102 flash access APIs all result in an associated mailbox command. The
456 * functions shown in the following table provide a generic interface to the required
457 * mailbox commands.
458 *
459 * <table class="dashboard">
460 * <tr><th>Function Name</th><th>Description</th></tr>
461 * <tr><td>get_ext_fat_capabilities()</td><td>Issue EFD get capabilities command.</td></tr>
462 * <tr><td>ext_fat_config_snapshot()</td><td>Get the total number of log entries in the snapshot buffer.
463 * </td></tr>
464 * <tr><td>ext_fat_retrieve_snapshot()</td><td>Retrieve log entries from the snapshot buffer using starting
465 * offset and number of log entries.</td></tr>
466 * <tr><td>ext_fat_read_string_table()</td><td>Read the string table to be placed at the start of the EFD
467 * data file.</td></tr>
468 * </table>
469 *
470 * <br><br>
471 *
472 */
#define OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES
Definition: elxu_sli4.h:89
struct mbox_common_get_ext_fat_capabilities_t::@12::@13 request
struct mbox_ioctl_common_ext_fat_retrieve_snapshot_t::@19::@21 response
union ioctl_common_ext_fat_read_string_table_t::@22 params
union mbox_ioctl_common_ext_fat_retrieve_snapshot_t::@19 params
#define ELXU_SUCCESS
Definition: elxu.h:43
#define MGMT_FLASHROM_OPCODE_SAVE
Definition: elxu_sli4.h:460
#define EXT_FAT_RETRIEVE_MODE_VRAM
Definition: elxu_sli4.h:834
int fat_info(elxu_device_t *device)
Return length of FAT.
Definition: elxu_sky.c:156
struct mbox_common_ext_fat_configure_snapshot_t::@17::@18 response
void * zmalloc(uint32_t len)
Allocates and zeroes memory to be used.
Definition: elxu_common.c:63
int fat_read(elxu_device_t *device, uint8_t *buffer, uint32_t bufferLength)
Read FAT.
Definition: elxu_sky.c:175
int get_ext_fat_capabilities(elxu_device_t *device, uint32_t parameter_type, ext_fat_config_params_t *params, uint32_t paramsLength)
Issue EFD get capabilities mailbox command.
Definition: elxu_sky.c:236
int ufi_image_upload(elxu_device_t *device, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
Upload UFI flash image component.
Definition: elxu_sky.c:87
int ext_fat_retrieve_snapshot(elxu_device_t *device, uint8_t *buf, uint32_t len, uint32_t numlogs)
Issue retrieve EFD snapshot mailbox command.
Definition: elxu_sky.c:304
void zfree(void *p)
Frees memory that has been allocated.
Definition: elxu_common.c:80
union mbox_common_ext_fat_configure_snapshot_t::@17 params
struct mbox_ioctl_common_ext_fat_retrieve_snapshot_t::@19::@20 request
#define OPCODE_COMMON_EXT_FAT_READ_STRING_TABLE
Definition: elxu_sli4.h:93
#define FAT_OPERATION_RETRIEVE
Definition: elxu_sli4.h:513
int ext_fat_read_string_table(elxu_device_t *device, mbox_ext_fat_read_string_params_t *tblinfo, uint32_t tbl_info_len, uint32_t bytes_to_read, uint32_t bytes_read)
Issue EXT_FAT_READ_STRING_TABLE mailbox command.
Definition: elxu_sky.c:387
int mbox_ext_fat(elxu_device_t *device, uint32_t opcode, void *mbox, uint32_t mboxLength)
Issue EFD mailbox command.
Definition: elxu_mbox.c:1604
#define FAT_OPERATION_QUERY
Definition: elxu_sli4.h:514
int mbox_manage_fat(elxu_device_t *device, uint32_t fat_operation, uint32_t read_log_offset, void *buffer, uint32_t bufferLength)
Issue COMMON_MANAGE_FAT mailbox commands.
Definition: elxu_mbox.c:1510
int mbox_read_flashrom(elxu_device_t *device, uint32_t opcode, uint32_t optype, uint32_t offset, void *outbuf, uint32_t outbufLength)
Issue read flashrom mailbox command.
Definition: elxu_mbox.c:1339
struct ioctl_common_ext_fat_read_string_table_t::@22::@24 response
static int image_load_common(elxu_device_t *device, dir_t direction, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
Read or Write UFI flash image component.
Definition: elxu_sky.c:109
#define MALLOC_FAILED
Definition: elxu.h:42
int ufi_image_download(elxu_device_t *device, uint32_t op_type, uint8_t *buffer, uint32_t bufferLength)
Download UFI flash image component.
Definition: elxu_sky.c:67
#define MGMT_FLASHROM_OPCODE_REPORT
Definition: elxu_sli4.h:462
union mbox_common_get_ext_fat_capabilities_t::@12 params
struct mbox_common_get_ext_fat_capabilities_t::@12::@14 response
dir_t
Definition: elxu_sky.c:42
int mbox_write_flashrom(elxu_device_t *device, uint32_t opcode, uint32_t optype, uint32_t offset, void *inbuf, uint32_t inbufLength)
Issue write flashrom mailbox command.
Definition: elxu_mbox.c:1421
#define OPCODE_COMMON_EXT_FAT_CONFIGURE_SNAPSHOT
Definition: elxu_sli4.h:91
#define OPCODE_COMMON_EXT_FAT_RETRIEVE_SHAPSHOT
Definition: elxu_sli4.h:92
#define MBOX_MAX_BUFFER
Definition: elxu_sli4.h:749
#define MGMT_FLASHROM_OPCODE_FLASH
Definition: elxu_sli4.h:459
struct ioctl_common_ext_fat_read_string_table_t::@22::@23 request
int ext_fat_config_snapshot(elxu_device_t *device)
Issue configure EFD snapshot mailbox command.
Definition: elxu_sky.c:268