4 * Copyright(c) 2017 Cavium, Inc.. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Cavium, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include "lio_common.h"
43 #include "lio_response_manager.h"
44 #include "lio_device.h"
45 #include "lio_image.h"
46 #include "lio_mem_ops.h"
49 static void lio_get_uboot_version(struct octeon_device *oct);
50 static void lio_remote_lock(void);
51 static void lio_remote_unlock(void);
52 static uint64_t cvmx_bootmem_phy_named_block_find(struct octeon_device *oct,
55 static int lio_console_read(struct octeon_device *oct,
56 uint32_t console_num, char *buffer,
59 #define CAST_ULL(v) ((unsigned long long)(v))
61 #define LIO_BOOTLOADER_PCI_READ_BUFFER_DATA_ADDR 0x0006c008
62 #define LIO_BOOTLOADER_PCI_READ_BUFFER_LEN_ADDR 0x0006c004
63 #define LIO_BOOTLOADER_PCI_READ_BUFFER_OWNER_ADDR 0x0006c000
64 #define LIO_BOOTLOADER_PCI_READ_DESC_ADDR 0x0006c100
65 #define LIO_BOOTLOADER_PCI_WRITE_BUFFER_STR_LEN 248
67 #define LIO_PCI_IO_BUF_OWNER_OCTEON 0x00000001
68 #define LIO_PCI_IO_BUF_OWNER_HOST 0x00000002
70 #define LIO_PCI_CONSOLE_BLOCK_NAME "__pci_console"
71 #define LIO_CONSOLE_POLL_INTERVAL_MS 100 /* 10 times per second */
74 * First three members of cvmx_bootmem_desc are left in original positions
75 * for backwards compatibility. Assumes big endian target
77 struct cvmx_bootmem_desc {
78 /* lock to control access to list */
81 /* flags for indicating various conditions */
86 /* incremented changed when incompatible changes made */
87 uint32_t major_version;
90 * incremented changed when compatible changes made, reset to zero
91 * when major incremented
93 uint32_t minor_version;
95 uint64_t app_data_addr;
96 uint64_t app_data_size;
98 /* number of elements in named blocks array */
99 uint32_t nb_num_blocks;
101 /* length of name array in bootmem blocks */
102 uint32_t named_block_name_len;
104 /* address of named memory block descriptors */
105 uint64_t named_block_array_addr;
109 * Structure that defines a single console.
111 * Note: when read_index == write_index, the buffer is empty. The actual usable
112 * size of each console is console_buf_size -1;
114 struct lio_pci_console {
115 uint64_t input_base_addr;
116 uint32_t input_read_index;
117 uint32_t input_write_index;
118 uint64_t output_base_addr;
119 uint32_t output_read_index;
120 uint32_t output_write_index;
126 * This is the main container structure that contains all the information
127 * about all PCI consoles. The address of this structure is passed to
128 * various routines that operation on PCI consoles.
130 struct lio_pci_console_desc {
131 uint32_t major_version;
132 uint32_t minor_version;
135 uint32_t num_consoles;
137 /* must be 64 bit aligned here... */
138 /* Array of addresses of octeon_pci_console structures */
139 uint64_t console_addr_array[1];
140 /* Implicit storage for console_addr_array */
144 * This macro returns the size of a member of a structure. Logically it is
145 * the same as "sizeof(s::field)" in C++, but C lacks the "::" operator.
147 #define SIZEOF_FIELD(s, field) sizeof(((s *)NULL)->field)
149 * This function is the implementation of the get macros defined
150 * for individual structure members. The argument are generated
151 * by the macros inorder to read only the needed memory.
153 * @param oct Pointer to current octeon device
154 * @param base 64bit physical address of the complete structure
155 * @param offset Offset from the beginning of the structure to the member being
157 * @param size Size of the structure member.
159 * @return Value of the structure member promoted into a uint64_t.
161 static inline uint64_t
162 __cvmx_bootmem_desc_get(struct octeon_device *oct, uint64_t base,
163 uint32_t offset, uint32_t size)
166 base = (1ull << 63) | (base + offset);
169 return (lio_read_device_mem32(oct, base));
171 return (lio_read_device_mem64(oct, base));
178 * This function retrieves the string name of a named block. It is
179 * more complicated than a simple memcpy() since the named block
180 * descriptor may not be directly accessible.
182 * @param oct Pointer to current octeon device
183 * @param addr Physical address of the named block descriptor
184 * @param str String to receive the named block string name
185 * @param len Length of the string buffer, which must match the length
186 * stored in the bootmem descriptor.
189 lio_bootmem_named_get_name(struct octeon_device *oct, uint64_t addr, char *str,
193 addr += offsetof(struct cvmx_bootmem_named_block_desc, name);
194 lio_pci_read_core_mem(oct, addr, (uint8_t *) str, len);
198 /* See header file for descriptions of functions */
201 * Check the version information on the bootmem descriptor
203 * @param oct Pointer to current octeon device
205 * Exact major version to check against. A zero means
206 * check that the version supports named blocks.
208 * @return Zero if the version is correct. Negative if the version is
209 * incorrect. Failures also cause a message to be displayed.
212 __cvmx_bootmem_check_version(struct octeon_device *oct, uint32_t exact_match)
214 uint32_t major_version;
215 uint32_t minor_version;
217 if (!oct->bootmem_desc_addr)
218 oct->bootmem_desc_addr =
219 lio_read_device_mem64(oct,
220 LIO_BOOTLOADER_PCI_READ_DESC_ADDR);
222 major_version = (uint32_t) __cvmx_bootmem_desc_get(oct,
223 oct->bootmem_desc_addr,
224 offsetof(struct cvmx_bootmem_desc, major_version),
225 SIZEOF_FIELD(struct cvmx_bootmem_desc, major_version));
226 minor_version = (uint32_t) __cvmx_bootmem_desc_get(oct,
227 oct->bootmem_desc_addr,
228 offsetof(struct cvmx_bootmem_desc, minor_version),
229 SIZEOF_FIELD(struct cvmx_bootmem_desc, minor_version));
231 lio_dev_dbg(oct, "%s: major_version=%d\n", __func__, major_version);
232 if ((major_version > 3) ||
233 (exact_match && major_version != exact_match)) {
234 lio_dev_err(oct, "bootmem ver mismatch %d.%d addr:0x%llx\n",
235 major_version, minor_version,
236 CAST_ULL(oct->bootmem_desc_addr));
243 static const struct cvmx_bootmem_named_block_desc *
244 __cvmx_bootmem_find_named_block_flags(struct octeon_device *oct,
245 const char *name, uint32_t flags)
247 struct cvmx_bootmem_named_block_desc *desc =
248 &oct->bootmem_named_block_desc;
251 named_addr = cvmx_bootmem_phy_named_block_find(oct, name,
254 desc->base_addr = __cvmx_bootmem_desc_get(oct, named_addr,
255 offsetof(struct cvmx_bootmem_named_block_desc,
257 SIZEOF_FIELD(struct cvmx_bootmem_named_block_desc,
260 desc->size = __cvmx_bootmem_desc_get(oct, named_addr,
261 offsetof(struct cvmx_bootmem_named_block_desc, size),
262 SIZEOF_FIELD(struct cvmx_bootmem_named_block_desc,
265 strncpy(desc->name, name, sizeof(desc->name));
266 desc->name[sizeof(desc->name) - 1] = 0;
268 return (&oct->bootmem_named_block_desc);
275 cvmx_bootmem_phy_named_block_find(struct octeon_device *oct, const char *name,
280 if (!__cvmx_bootmem_check_version(oct, 3)) {
283 uint64_t named_block_array_addr =
284 __cvmx_bootmem_desc_get(oct, oct->bootmem_desc_addr,
285 offsetof(struct cvmx_bootmem_desc,
286 named_block_array_addr),
287 SIZEOF_FIELD(struct cvmx_bootmem_desc,
288 named_block_array_addr));
289 uint32_t num_blocks =
290 (uint32_t) __cvmx_bootmem_desc_get(oct,
291 oct->bootmem_desc_addr,
292 offsetof(struct cvmx_bootmem_desc,
294 SIZEOF_FIELD(struct cvmx_bootmem_desc,
297 uint32_t name_length =
298 (uint32_t) __cvmx_bootmem_desc_get(oct,
299 oct->bootmem_desc_addr,
300 offsetof(struct cvmx_bootmem_desc,
301 named_block_name_len),
302 SIZEOF_FIELD(struct cvmx_bootmem_desc,
303 named_block_name_len));
305 uint64_t named_addr = named_block_array_addr;
307 for (i = 0; i < num_blocks; i++) {
308 uint64_t named_size =
309 __cvmx_bootmem_desc_get(oct, named_addr,
310 offsetof(struct cvmx_bootmem_named_block_desc,
312 SIZEOF_FIELD(struct cvmx_bootmem_named_block_desc,
315 if (name && named_size) {
316 char *name_tmp = malloc(name_length + 1,
322 lio_bootmem_named_get_name(oct, named_addr,
326 if (!strncmp(name, name_tmp, name_length)) {
328 free(name_tmp, M_DEVBUF);
332 free(name_tmp, M_DEVBUF);
334 } else if (!name && !named_size) {
340 sizeof(struct cvmx_bootmem_named_block_desc);
347 * Find a named block on the remote Octeon
349 * @param oct Pointer to current octeon device
350 * @param name Name of block to find
351 * @param base_addr Address the block is at (OUTPUT)
352 * @param size The size of the block (OUTPUT)
354 * @return Zero on success, One on failure.
357 lio_named_block_find(struct octeon_device *oct, const char *name,
358 uint64_t * base_addr, uint64_t * size)
360 const struct cvmx_bootmem_named_block_desc *named_block;
363 named_block = __cvmx_bootmem_find_named_block_flags(oct, name, 0);
365 if (named_block != NULL) {
366 *base_addr = named_block->base_addr;
367 *size = named_block->size;
376 lio_remote_lock(void)
379 /* fill this in if any sharing is needed */
383 lio_remote_unlock(void)
386 /* fill this in if any sharing is needed */
390 lio_console_send_cmd(struct octeon_device *oct, char *cmd_str,
391 uint32_t wait_hundredths)
393 uint32_t len = (uint32_t) strlen(cmd_str);
395 lio_dev_dbg(oct, "sending \"%s\" to bootloader\n", cmd_str);
397 if (len > LIO_BOOTLOADER_PCI_WRITE_BUFFER_STR_LEN - 1) {
398 lio_dev_err(oct, "Command string too long, max length is: %d\n",
399 LIO_BOOTLOADER_PCI_WRITE_BUFFER_STR_LEN - 1);
403 if (lio_wait_for_bootloader(oct, wait_hundredths)) {
404 lio_dev_err(oct, "Bootloader not ready for command.\n");
408 /* Write command to bootloader */
410 lio_pci_write_core_mem(oct, LIO_BOOTLOADER_PCI_READ_BUFFER_DATA_ADDR,
411 (uint8_t *) cmd_str, len);
412 lio_write_device_mem32(oct, LIO_BOOTLOADER_PCI_READ_BUFFER_LEN_ADDR,
414 lio_write_device_mem32(oct, LIO_BOOTLOADER_PCI_READ_BUFFER_OWNER_ADDR,
415 LIO_PCI_IO_BUF_OWNER_OCTEON);
418 * Bootloader should accept command very quickly if it really was
421 if (lio_wait_for_bootloader(oct, 200)) {
423 lio_dev_err(oct, "Bootloader did not accept command.\n");
432 lio_wait_for_bootloader(struct octeon_device *oct,
433 uint32_t wait_time_hundredths)
435 lio_dev_dbg(oct, "waiting %d0 ms for bootloader\n",
436 wait_time_hundredths);
438 if (lio_mem_access_ok(oct))
441 while (wait_time_hundredths > 0 &&
442 lio_read_device_mem32(oct,
443 LIO_BOOTLOADER_PCI_READ_BUFFER_OWNER_ADDR) !=
444 LIO_PCI_IO_BUF_OWNER_HOST) {
445 if (--wait_time_hundredths <= 0)
448 lio_sleep_timeout(10);
455 lio_console_handle_result(struct octeon_device *oct, size_t console_num)
457 struct lio_console *console;
459 console = &oct->console[console_num];
461 console->waiting = 0;
464 static char console_buffer[LIO_MAX_CONSOLE_READ_BYTES];
467 lio_output_console_line(struct octeon_device *oct, struct lio_console *console,
468 size_t console_num, char *console_buffer,
475 line = console_buffer;
476 for (i = 0; i < bytes_read; i++) {
477 /* Output a line at a time, prefixed */
478 if (console_buffer[i] == '\n') {
479 console_buffer[i] = '\0';
480 /* We need to output 'line', prefaced by 'leftover'.
481 * However, it is possible we're being called to
482 * output 'leftover' by itself (in the case of nothing
483 * having been read from the console).
485 * To avoid duplication, check for this condition.
487 if (console->leftover[0] &&
488 (line != console->leftover)) {
490 (*console->print)(oct,
491 (uint32_t)console_num,
492 console->leftover,line);
493 console->leftover[0] = '\0';
496 (*console->print)(oct,
497 (uint32_t)console_num,
501 line = &console_buffer[i + 1];
505 /* Save off any leftovers */
506 if (line != &console_buffer[bytes_read]) {
507 console_buffer[bytes_read] = '\0';
508 len = strlen(console->leftover);
509 strncpy(&console->leftover[len], line,
510 sizeof(console->leftover) - len);
515 lio_check_console(void *arg)
517 struct lio_console *console;
518 struct lio_callout *console_callout = arg;
519 struct octeon_device *oct =
520 (struct octeon_device *)console_callout->ctxptr;
522 uint32_t console_num = (uint32_t) console_callout->ctxul;
523 int32_t bytes_read, total_read, tries;
525 console = &oct->console[console_num];
529 if (callout_pending(&console_callout->timer) ||
530 (callout_active(&console_callout->timer) == 0))
535 * Take console output regardless of whether it will be
538 bytes_read = lio_console_read(oct, console_num, console_buffer,
539 sizeof(console_buffer) - 1);
540 if (bytes_read > 0) {
541 total_read += bytes_read;
542 if (console->waiting)
543 lio_console_handle_result(oct, console_num);
545 if (console->print) {
546 lio_output_console_line(oct, console,
552 } else if (bytes_read < 0) {
553 lio_dev_err(oct, "Error reading console %u, ret=%d\n",
554 console_num, bytes_read);
558 } while ((bytes_read > 0) && (tries < 16));
561 * If nothing is read after polling the console, output any leftovers
564 if (console->print && (total_read == 0) && (console->leftover[0])) {
565 /* append '\n' as terminator for 'output_console_line' */
566 len = strlen(console->leftover);
567 console->leftover[len] = '\n';
568 lio_output_console_line(oct, console, console_num,
569 console->leftover, (int32_t)(len + 1));
570 console->leftover[0] = '\0';
572 callout_schedule(&oct->console_timer[console_num].timer,
573 lio_ms_to_ticks(LIO_CONSOLE_POLL_INTERVAL_MS));
578 lio_init_consoles(struct octeon_device *oct)
583 ret = lio_mem_access_ok(oct);
585 lio_dev_err(oct, "Memory access not okay'\n");
588 ret = lio_named_block_find(oct, LIO_PCI_CONSOLE_BLOCK_NAME, &addr,
591 lio_dev_err(oct, "Could not find console '%s'\n",
592 LIO_PCI_CONSOLE_BLOCK_NAME);
597 * Use BAR1_INDEX15 to create a static mapping to a region of
598 * Octeon's DRAM that contains the PCI console named block.
600 oct->console_nb_info.bar1_index = 15;
601 oct->fn_list.bar1_idx_setup(oct, addr, oct->console_nb_info.bar1_index,
603 oct->console_nb_info.dram_region_base = addr & 0xFFFFFFFFFFC00000ULL;
606 * num_consoles > 0, is an indication that the consoles are
609 oct->num_consoles = lio_read_device_mem32(oct,
610 addr + offsetof(struct lio_pci_console_desc,
612 oct->console_desc_addr = addr;
614 lio_dev_dbg(oct, "Initialized consoles. %d available\n",
621 lio_add_console(struct octeon_device *oct, uint32_t console_num, char *dbg_enb)
623 struct callout *timer;
624 struct lio_console *console;
628 if (console_num >= oct->num_consoles) {
629 lio_dev_err(oct, "trying to read from console number %d when only 0 to %d exist\n",
630 console_num, oct->num_consoles);
632 console = &oct->console[console_num];
634 console->waiting = 0;
636 coreaddr = oct->console_desc_addr + console_num * 8 +
637 offsetof(struct lio_pci_console_desc,
639 console->addr = lio_read_device_mem64(oct, coreaddr);
640 coreaddr = console->addr + offsetof(struct lio_pci_console,
642 console->buffer_size = lio_read_device_mem32(oct, coreaddr);
643 coreaddr = console->addr + offsetof(struct lio_pci_console,
645 console->input_base_addr = lio_read_device_mem64(oct, coreaddr);
646 coreaddr = console->addr + offsetof(struct lio_pci_console,
648 console->output_base_addr =
649 lio_read_device_mem64(oct, coreaddr);
650 console->leftover[0] = '\0';
652 timer = &oct->console_timer[console_num].timer;
654 if (oct->uboot_len == 0)
655 lio_get_uboot_version(oct);
657 callout_init(timer, 0);
658 oct->console_timer[console_num].ctxptr = (void *)oct;
659 oct->console_timer[console_num].ctxul = console_num;
661 lio_ms_to_ticks(LIO_CONSOLE_POLL_INTERVAL_MS),
662 lio_check_console, timer);
663 /* an empty string means use default debug console enablement */
664 if (dbg_enb && !dbg_enb[0])
665 dbg_enb = "setenv pci_console_active 1";
668 ret = lio_console_send_cmd(oct, dbg_enb, 2000);
677 * Removes all consoles
679 * @param oct octeon device
682 lio_remove_consoles(struct octeon_device *oct)
684 struct lio_console *console;
687 for (i = 0; i < oct->num_consoles; i++) {
688 console = &oct->console[i];
690 if (!console->active)
693 callout_stop(&oct->console_timer[i].timer);
695 console->buffer_size = 0;
696 console->input_base_addr = 0;
697 console->output_base_addr = 0;
700 oct->num_consoles = 0;
704 lio_console_free_bytes(uint32_t buffer_size, uint32_t wr_idx, uint32_t rd_idx)
707 if (rd_idx >= buffer_size || wr_idx >= buffer_size)
710 return (((buffer_size - 1) - (wr_idx - rd_idx)) % buffer_size);
714 lio_console_avail_bytes(uint32_t buffer_size, uint32_t wr_idx, uint32_t rd_idx)
717 if (rd_idx >= buffer_size || wr_idx >= buffer_size)
720 return (buffer_size - 1 -
721 lio_console_free_bytes(buffer_size, wr_idx, rd_idx));
725 lio_console_read(struct octeon_device *oct, uint32_t console_num, char *buffer,
728 struct lio_console *console;
730 uint32_t rd_idx, wr_idx;
732 if (console_num >= oct->num_consoles) {
733 lio_dev_err(oct, "Attempted to read from disabled console %d\n",
738 console = &oct->console[console_num];
741 * Check to see if any data is available. Maybe optimize this with
744 rd_idx = lio_read_device_mem32(oct, console->addr +
745 offsetof(struct lio_pci_console, output_read_index));
746 wr_idx = lio_read_device_mem32(oct, console->addr +
747 offsetof(struct lio_pci_console, output_write_index));
749 bytes_to_read = lio_console_avail_bytes(console->buffer_size,
751 if (bytes_to_read <= 0)
752 return (bytes_to_read);
754 bytes_to_read = min(bytes_to_read, buf_size);
757 * Check to see if what we want to read is not contiguous, and limit
758 * ourselves to the contiguous block
760 if (rd_idx + bytes_to_read >= console->buffer_size)
761 bytes_to_read = console->buffer_size - rd_idx;
763 lio_pci_read_core_mem(oct, console->output_base_addr + rd_idx,
764 (uint8_t *) buffer, bytes_to_read);
765 lio_write_device_mem32(oct, console->addr +
766 offsetof(struct lio_pci_console,
768 (rd_idx + bytes_to_read) % console->buffer_size);
770 return (bytes_to_read);
774 lio_get_uboot_version(struct octeon_device *oct)
776 struct lio_console *console;
777 int32_t bytes_read, total_read, tries;
778 uint32_t console_num = 0;
781 ret = lio_console_send_cmd(oct, "setenv stdout pci", 50);
783 console = &oct->console[console_num];
787 ret = lio_console_send_cmd(oct, "version", 1);
791 * Take console output regardless of whether it will be
794 bytes_read = lio_console_read(oct,
795 console_num, oct->uboot_version +
797 OCTEON_UBOOT_BUFFER_SIZE - 1 -
799 if (bytes_read > 0) {
800 oct->uboot_version[bytes_read] = 0x0;
802 total_read += bytes_read;
803 if (console->waiting)
804 lio_console_handle_result(oct, console_num);
806 } else if (bytes_read < 0) {
807 lio_dev_err(oct, "Error reading console %u, ret=%d\n",
808 console_num, bytes_read);
812 } while ((bytes_read > 0) && (tries < 16));
815 * If nothing is read after polling the console, output any leftovers
818 if ((total_read == 0) && (console->leftover[0])) {
819 lio_dev_dbg(oct, "%u: %s\n", console_num, console->leftover);
820 console->leftover[0] = '\0';
823 ret = lio_console_send_cmd(oct, "setenv stdout serial", 50);
826 for (i = 0; i < (OCTEON_UBOOT_BUFFER_SIZE - 9); i++) {
827 if (oct->uboot_version[i] == 'U' &&
828 oct->uboot_version[i + 2] == 'B' &&
829 oct->uboot_version[i + 3] == 'o' &&
830 oct->uboot_version[i + 4] == 'o' &&
831 oct->uboot_version[i + 5] == 't') {
834 for (; oct->uboot_version[i] != 0x0; i++) {
835 if (oct->uboot_version[i] == 'm' &&
836 oct->uboot_version[i + 1] == 'i' &&
837 oct->uboot_version[i + 2] == 'p' &&
838 oct->uboot_version[i + 3] == 's') {
839 oct->uboot_eidx = i - 1;
840 oct->uboot_version[i - 1] = 0x0;
841 oct->uboot_len = oct->uboot_eidx -
843 lio_dev_info(oct, "%s\n",
854 #define FBUF_SIZE (4 * 1024 * 1024)
857 lio_download_firmware(struct octeon_device *oct, const uint8_t * data,
860 struct lio_firmware_file_header *h;
862 uint32_t crc32_result, i, image_len, rem;
865 if (size < sizeof(struct lio_firmware_file_header)) {
866 lio_dev_err(oct, "Firmware file too small (%d < %d).\n",
868 (uint32_t) sizeof(struct lio_firmware_file_header));
872 h = __DECONST(struct lio_firmware_file_header *, data);
874 if (be32toh(h->magic) != LIO_NIC_MAGIC) {
875 lio_dev_err(oct, "Unrecognized firmware file.\n");
879 crc32_result = crc32(data, sizeof(struct lio_firmware_file_header) -
881 if (crc32_result != be32toh(h->crc32)) {
882 lio_dev_err(oct, "Firmware CRC mismatch (0x%08x != 0x%08x).\n",
883 crc32_result, be32toh(h->crc32));
887 if (memcmp(LIO_BASE_VERSION, h->version,
888 strlen(LIO_BASE_VERSION))) {
889 lio_dev_err(oct, "Unmatched firmware version. Expected %s.x, got %s.\n",
890 LIO_BASE_VERSION, h->version);
894 if (be32toh(h->num_images) > LIO_MAX_IMAGES) {
895 lio_dev_err(oct, "Too many images in firmware file (%d).\n",
896 be32toh(h->num_images));
900 lio_dev_info(oct, "Firmware version: %s\n", h->version);
901 snprintf(oct->fw_info.lio_firmware_version, 32, "LIQUIDIO: %s",
904 data += sizeof(struct lio_firmware_file_header);
906 lio_dev_info(oct, "Loading %d image(s)\n", be32toh(h->num_images));
908 /* load all images */
909 for (i = 0; i < be32toh(h->num_images); i++) {
910 load_addr = be64toh(h->desc[i].addr);
911 image_len = be32toh(h->desc[i].len);
913 lio_dev_info(oct, "Loading firmware %d at %llx\n", image_len,
914 (unsigned long long)load_addr);
916 /* Write in 4MB chunks */
925 /* download the image */
926 lio_pci_write_core_mem(oct, load_addr,
927 __DECONST(uint8_t *, data),
931 rem -= (uint32_t) size;
936 lio_dev_info(oct, "Writing boot command: %s\n", h->bootcmd);
938 /* Invoke the bootcmd */
939 ret = lio_console_send_cmd(oct, h->bootcmd, 50);