1/* 2 * Linux network driver for QLogic BR-series Converged Network Adapter. 3 * 4 * This program is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License (GPL) Version 2 as 6 * published by the Free Software Foundation 7 * 8 * This program is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * General Public License for more details. 12 */ 13/* 14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. 15 * Copyright (c) 2014-2015 QLogic Corporation 16 * All rights reserved 17 * www.qlogic.com 18 */ 19#include <linux/firmware.h> 20#include "bnad.h" 21#include "bfi.h" 22#include "cna.h" 23 24const struct firmware *bfi_fw; 25static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna; 26static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size; 27 28static u32 * 29cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image, 30 u32 *bfi_image_size, char *fw_name) 31{ 32 const struct firmware *fw; 33 u32 n; 34 35 if (request_firmware(&fw, fw_name, &pdev->dev)) { 36 pr_alert("Can't locate firmware %s\n", fw_name); 37 goto error; 38 } 39 40 *bfi_image = (u32 *)fw->data; 41 *bfi_image_size = fw->size/sizeof(u32); 42 bfi_fw = fw; 43 44 /* Convert loaded firmware to host order as it is stored in file 45 * as sequence of LE32 integers. 46 */ 47 for (n = 0; n < *bfi_image_size; n++) 48 le32_to_cpus(*bfi_image + n); 49 50 return *bfi_image; 51error: 52 return NULL; 53} 54 55u32 * 56cna_get_firmware_buf(struct pci_dev *pdev) 57{ 58 if (pdev->device == BFA_PCI_DEVICE_ID_CT2) { 59 if (bfi_image_ct2_cna_size == 0) 60 cna_read_firmware(pdev, &bfi_image_ct2_cna, 61 &bfi_image_ct2_cna_size, CNA_FW_FILE_CT2); 62 return bfi_image_ct2_cna; 63 } else if (bfa_asic_id_ct(pdev->device)) { 64 if (bfi_image_ct_cna_size == 0) 65 cna_read_firmware(pdev, &bfi_image_ct_cna, 66 &bfi_image_ct_cna_size, CNA_FW_FILE_CT); 67 return bfi_image_ct_cna; 68 } 69 70 return NULL; 71} 72 73u32 * 74bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off) 75{ 76 switch (asic_gen) { 77 case BFI_ASIC_GEN_CT: 78 return (bfi_image_ct_cna + off); 79 case BFI_ASIC_GEN_CT2: 80 return (bfi_image_ct2_cna + off); 81 default: 82 return NULL; 83 } 84} 85 86u32 87bfa_cb_image_get_size(enum bfi_asic_gen asic_gen) 88{ 89 switch (asic_gen) { 90 case BFI_ASIC_GEN_CT: 91 return bfi_image_ct_cna_size; 92 case BFI_ASIC_GEN_CT2: 93 return bfi_image_ct2_cna_size; 94 default: 95 return 0; 96 } 97} 98