1f844a0eaSJeff Kirsher /* 2f844a0eaSJeff Kirsher * Linux network driver for Brocade 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 /* 14f844a0eaSJeff Kirsher * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. 15f844a0eaSJeff Kirsher * All rights reserved 16f844a0eaSJeff Kirsher * www.brocade.com 17f844a0eaSJeff Kirsher */ 18f844a0eaSJeff Kirsher #include <linux/firmware.h> 19*1bf9fd70SRasesh Mody #include "bfi.h" 20f844a0eaSJeff Kirsher #include "cna.h" 21f844a0eaSJeff Kirsher 22f844a0eaSJeff Kirsher const struct firmware *bfi_fw; 23*1bf9fd70SRasesh Mody static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna; 24*1bf9fd70SRasesh Mody static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size; 25f844a0eaSJeff Kirsher 26f844a0eaSJeff Kirsher static u32 * 27f844a0eaSJeff Kirsher cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image, 28f844a0eaSJeff Kirsher u32 *bfi_image_size, char *fw_name) 29f844a0eaSJeff Kirsher { 30f844a0eaSJeff Kirsher const struct firmware *fw; 31f844a0eaSJeff Kirsher 32f844a0eaSJeff Kirsher if (request_firmware(&fw, fw_name, &pdev->dev)) { 33f844a0eaSJeff Kirsher pr_alert("Can't locate firmware %s\n", fw_name); 34f844a0eaSJeff Kirsher goto error; 35f844a0eaSJeff Kirsher } 36f844a0eaSJeff Kirsher 37f844a0eaSJeff Kirsher *bfi_image = (u32 *)fw->data; 38f844a0eaSJeff Kirsher *bfi_image_size = fw->size/sizeof(u32); 39f844a0eaSJeff Kirsher bfi_fw = fw; 40f844a0eaSJeff Kirsher 41f844a0eaSJeff Kirsher return *bfi_image; 42f844a0eaSJeff Kirsher error: 43f844a0eaSJeff Kirsher return NULL; 44f844a0eaSJeff Kirsher } 45f844a0eaSJeff Kirsher 46f844a0eaSJeff Kirsher u32 * 47f844a0eaSJeff Kirsher cna_get_firmware_buf(struct pci_dev *pdev) 48f844a0eaSJeff Kirsher { 49*1bf9fd70SRasesh Mody if (pdev->device == BFA_PCI_DEVICE_ID_CT2) { 50*1bf9fd70SRasesh Mody if (bfi_image_ct2_cna_size == 0) 51*1bf9fd70SRasesh Mody cna_read_firmware(pdev, &bfi_image_ct2_cna, 52*1bf9fd70SRasesh Mody &bfi_image_ct2_cna_size, CNA_FW_FILE_CT2); 53*1bf9fd70SRasesh Mody return bfi_image_ct2_cna; 54*1bf9fd70SRasesh Mody } else if (bfa_asic_id_ct(pdev->device)) { 55f844a0eaSJeff Kirsher if (bfi_image_ct_cna_size == 0) 56f844a0eaSJeff Kirsher cna_read_firmware(pdev, &bfi_image_ct_cna, 57f844a0eaSJeff Kirsher &bfi_image_ct_cna_size, CNA_FW_FILE_CT); 58f844a0eaSJeff Kirsher return bfi_image_ct_cna; 59f844a0eaSJeff Kirsher } 60f844a0eaSJeff Kirsher 61*1bf9fd70SRasesh Mody return NULL; 62*1bf9fd70SRasesh Mody } 63*1bf9fd70SRasesh Mody 64f844a0eaSJeff Kirsher u32 * 65*1bf9fd70SRasesh Mody bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off) 66f844a0eaSJeff Kirsher { 67*1bf9fd70SRasesh Mody switch (asic_gen) { 68*1bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT: 69f844a0eaSJeff Kirsher return (u32 *)(bfi_image_ct_cna + off); 70*1bf9fd70SRasesh Mody break; 71*1bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT2: 72*1bf9fd70SRasesh Mody return (u32 *)(bfi_image_ct2_cna + off); 73*1bf9fd70SRasesh Mody break; 74*1bf9fd70SRasesh Mody default: 75*1bf9fd70SRasesh Mody return NULL; 76*1bf9fd70SRasesh Mody } 77f844a0eaSJeff Kirsher } 78f844a0eaSJeff Kirsher 79f844a0eaSJeff Kirsher u32 80*1bf9fd70SRasesh Mody bfa_cb_image_get_size(enum bfi_asic_gen asic_gen) 81f844a0eaSJeff Kirsher { 82*1bf9fd70SRasesh Mody switch (asic_gen) { 83*1bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT: 84f844a0eaSJeff Kirsher return bfi_image_ct_cna_size; 85*1bf9fd70SRasesh Mody break; 86*1bf9fd70SRasesh Mody case BFI_ASIC_GEN_CT2: 87*1bf9fd70SRasesh Mody return bfi_image_ct2_cna_size; 88*1bf9fd70SRasesh Mody break; 89*1bf9fd70SRasesh Mody default: 90*1bf9fd70SRasesh Mody return 0; 91*1bf9fd70SRasesh Mody } 92f844a0eaSJeff Kirsher } 93