1f844a0eaSJeff Kirsher /* 22732ba56SRasesh Mody * Linux network driver for QLogic BR-series Converged Network Adapter. 3f844a0eaSJeff Kirsher * 4f844a0eaSJeff Kirsher * This program is free software; you can redistribute it and/or modify it 5f844a0eaSJeff Kirsher * under the terms of the GNU General Public License (GPL) Version 2 as 6f844a0eaSJeff Kirsher * published by the Free Software Foundation 7f844a0eaSJeff Kirsher * 8f844a0eaSJeff Kirsher * This program is distributed in the hope that it will be useful, but 9f844a0eaSJeff Kirsher * WITHOUT ANY WARRANTY; without even the implied warranty of 10f844a0eaSJeff Kirsher * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11f844a0eaSJeff Kirsher * General Public License for more details. 12f844a0eaSJeff Kirsher */ 13f844a0eaSJeff Kirsher /* 142732ba56SRasesh Mody * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. 152732ba56SRasesh Mody * Copyright (c) 2014-2015 QLogic Corporation 16f844a0eaSJeff Kirsher * All rights reserved 172732ba56SRasesh Mody * www.qlogic.com 18f844a0eaSJeff Kirsher */ 19f844a0eaSJeff Kirsher #include <linux/firmware.h> 20e1e0918fSstephen hemminger #include "bnad.h" 211bf9fd70SRasesh Mody #include "bfi.h" 22f844a0eaSJeff Kirsher #include "cna.h" 23f844a0eaSJeff Kirsher 24f844a0eaSJeff Kirsher const struct firmware *bfi_fw; 251bf9fd70SRasesh Mody static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna; 261bf9fd70SRasesh Mody static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size; 27f844a0eaSJeff Kirsher 28f844a0eaSJeff Kirsher static u32 * 29f844a0eaSJeff Kirsher cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image, 30f844a0eaSJeff Kirsher u32 *bfi_image_size, char *fw_name) 31f844a0eaSJeff Kirsher { 32f844a0eaSJeff Kirsher const struct firmware *fw; 33*e236b954SIvan Vecera u32 n; 34f844a0eaSJeff Kirsher 35f844a0eaSJeff Kirsher if (request_firmware(&fw, fw_name, &pdev->dev)) { 36f844a0eaSJeff Kirsher pr_alert("Can't locate firmware %s\n", fw_name); 37f844a0eaSJeff Kirsher goto error; 38f844a0eaSJeff Kirsher } 39f844a0eaSJeff Kirsher 40f844a0eaSJeff Kirsher *bfi_image = (u32 *)fw->data; 41f844a0eaSJeff Kirsher *bfi_image_size = fw->size/sizeof(u32); 42f844a0eaSJeff Kirsher bfi_fw = fw; 43f844a0eaSJeff Kirsher 44*e236b954SIvan Vecera /* Convert loaded firmware to host order as it is stored in file 45*e236b954SIvan Vecera * as sequence of LE32 integers. 46*e236b954SIvan Vecera */ 47*e236b954SIvan Vecera for (n = 0; n < *bfi_image_size; n++) 48*e236b954SIvan Vecera le32_to_cpus(*bfi_image + n); 49*e236b954SIvan Vecera 50f844a0eaSJeff Kirsher return *bfi_image; 51f844a0eaSJeff Kirsher error: 52f844a0eaSJeff Kirsher return NULL; 53f844a0eaSJeff Kirsher } 54f844a0eaSJeff Kirsher 55f844a0eaSJeff Kirsher u32 * 56f844a0eaSJeff Kirsher cna_get_firmware_buf(struct pci_dev *pdev) 57f844a0eaSJeff Kirsher { 581bf9fd70SRasesh Mody if (pdev->device == BFA_PCI_DEVICE_ID_CT2) { 591bf9fd70SRasesh Mody if (bfi_image_ct2_cna_size == 0) 601bf9fd70SRasesh Mody cna_read_firmware(pdev, &bfi_image_ct2_cna, 611bf9fd70SRasesh Mody &bfi_image_ct2_cna_size, CNA_FW_FILE_CT2); 621bf9fd70SRasesh Mody return bfi_image_ct2_cna; 631bf9fd70SRasesh Mody } else if (bfa_asic_id_ct(pdev->device)) { 64f844a0eaSJeff Kirsher if (bfi_image_ct_cna_size == 0) 65f844a0eaSJeff Kirsher cna_read_firmware(pdev, &bfi_image_ct_cna, 66f844a0eaSJeff Kirsher &bfi_image_ct_cna_size, CNA_FW_FILE_CT); 67f844a0eaSJeff Kirsher return bfi_image_ct_cna; 68f844a0eaSJeff Kirsher } 69f844a0eaSJeff Kirsher 701bf9fd70SRasesh Mody return NULL; 711bf9fd70SRasesh Mody } 721bf9fd70SRasesh Mody 73f844a0eaSJeff Kirsher u32 * 741bf9fd70SRasesh Mody bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off) 75f844a0eaSJeff Kirsher { 761bf9fd70SRasesh Mody switch (asic_gen) { 771bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT: 7864699336SJoe Perches return (bfi_image_ct_cna + off); 791bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT2: 8064699336SJoe Perches return (bfi_image_ct2_cna + off); 811bf9fd70SRasesh Mody default: 821bf9fd70SRasesh Mody return NULL; 831bf9fd70SRasesh Mody } 84f844a0eaSJeff Kirsher } 85f844a0eaSJeff Kirsher 86f844a0eaSJeff Kirsher u32 871bf9fd70SRasesh Mody bfa_cb_image_get_size(enum bfi_asic_gen asic_gen) 88f844a0eaSJeff Kirsher { 891bf9fd70SRasesh Mody switch (asic_gen) { 901bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT: 91f844a0eaSJeff Kirsher return bfi_image_ct_cna_size; 921bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT2: 931bf9fd70SRasesh Mody return bfi_image_ct2_cna_size; 941bf9fd70SRasesh Mody default: 951bf9fd70SRasesh Mody return 0; 961bf9fd70SRasesh Mody } 97f844a0eaSJeff Kirsher } 98