1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright 2019 Broadcom. 4 */ 5 6 #include <drivers/bcm/bnxt.h> 7 #include <stdint.h> 8 #include <stdlib.h> 9 #include <string.h> 10 #include <util.h> 11 12 #define BNXT_FW_NS3_IMAGE_SIG 0xFF12345A 13 #define BNXT_NS3_CFG_IMAGE_SIG 0xCF54321A 14 15 #define BNXT_BSPD_CFG_LEN 512 16 17 #define QSPI_BASE QSPI_MEM_BASE 18 #define QSPI_BNXT_IMG (QSPI_BASE + 0x400000) 19 #define QSPI_BSPD_ADDR (QSPI_BASE + 0x700000) 20 21 #define BCM_NS3 1 22 23 static struct bnxt_img_header { 24 uint32_t bnxt_fw_ns3_sig; 25 uint32_t bnxt_fw_ns3_size; 26 uint32_t bnxt_ns3_cfg_sig; 27 uint32_t bnxt_ns3_cfg_size; 28 } *img_header; 29 30 int get_bnxt_images_info(struct bnxt_images_info *bnxt_info, int chip_type) 31 { 32 uint32_t len = 0; 33 uint32_t fw_image_offset = sizeof(struct bnxt_img_header); 34 vaddr_t flash_dev_vaddr = 35 (uintptr_t)((vaddr_t)phys_to_virt(QSPI_BNXT_IMG, 36 MEM_AREA_IO_NSEC)); 37 38 bnxt_info->bnxt_bspd_cfg_vaddr = 39 (uintptr_t)((vaddr_t)phys_to_virt(QSPI_BSPD_ADDR, 40 MEM_AREA_IO_NSEC)); 41 42 bnxt_info->bnxt_bspd_cfg_len = BNXT_BSPD_CFG_LEN; 43 44 img_header = (struct bnxt_img_header *)flash_dev_vaddr; 45 46 if (img_header->bnxt_fw_ns3_sig != BNXT_FW_NS3_IMAGE_SIG) { 47 EMSG("Invalid Nitro bin"); 48 return BNXT_FAILURE; 49 } 50 51 len = img_header->bnxt_fw_ns3_size; 52 53 if (chip_type == BCM_NS3) { 54 bnxt_info->bnxt_fw_vaddr = flash_dev_vaddr + fw_image_offset; 55 bnxt_info->bnxt_fw_len = len; 56 } 57 58 fw_image_offset += len; 59 60 if (img_header->bnxt_ns3_cfg_sig != BNXT_NS3_CFG_IMAGE_SIG) { 61 EMSG("Invalid Nitro config"); 62 return BNXT_FAILURE; 63 } 64 65 len = img_header->bnxt_ns3_cfg_size; 66 67 if (chip_type == BCM_NS3) { 68 bnxt_info->bnxt_cfg_vaddr = flash_dev_vaddr + fw_image_offset; 69 bnxt_info->bnxt_cfg_len = len; 70 } 71 72 return BNXT_SUCCESS; 73 } 74