xref: /linux/drivers/net/ethernet/brocade/bna/cna_fwimg.c (revision e1e0918fcaea7b8100ed9f96f3ecd9eb9b867102)
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*e1e0918fSstephen hemminger #include "bnad.h"
201bf9fd70SRasesh Mody #include "bfi.h"
21f844a0eaSJeff Kirsher #include "cna.h"
22f844a0eaSJeff Kirsher 
23f844a0eaSJeff Kirsher const struct firmware *bfi_fw;
241bf9fd70SRasesh Mody static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna;
251bf9fd70SRasesh Mody static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size;
26f844a0eaSJeff Kirsher 
27f844a0eaSJeff Kirsher static u32 *
28f844a0eaSJeff Kirsher cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
29f844a0eaSJeff Kirsher 			u32 *bfi_image_size, char *fw_name)
30f844a0eaSJeff Kirsher {
31f844a0eaSJeff Kirsher 	const struct firmware *fw;
32f844a0eaSJeff Kirsher 
33f844a0eaSJeff Kirsher 	if (request_firmware(&fw, fw_name, &pdev->dev)) {
34f844a0eaSJeff Kirsher 		pr_alert("Can't locate firmware %s\n", fw_name);
35f844a0eaSJeff Kirsher 		goto error;
36f844a0eaSJeff Kirsher 	}
37f844a0eaSJeff Kirsher 
38f844a0eaSJeff Kirsher 	*bfi_image = (u32 *)fw->data;
39f844a0eaSJeff Kirsher 	*bfi_image_size = fw->size/sizeof(u32);
40f844a0eaSJeff Kirsher 	bfi_fw = fw;
41f844a0eaSJeff Kirsher 
42f844a0eaSJeff Kirsher 	return *bfi_image;
43f844a0eaSJeff Kirsher error:
44f844a0eaSJeff Kirsher 	return NULL;
45f844a0eaSJeff Kirsher }
46f844a0eaSJeff Kirsher 
47f844a0eaSJeff Kirsher u32 *
48f844a0eaSJeff Kirsher cna_get_firmware_buf(struct pci_dev *pdev)
49f844a0eaSJeff Kirsher {
501bf9fd70SRasesh Mody 	if (pdev->device == BFA_PCI_DEVICE_ID_CT2) {
511bf9fd70SRasesh Mody 		if (bfi_image_ct2_cna_size == 0)
521bf9fd70SRasesh Mody 			cna_read_firmware(pdev, &bfi_image_ct2_cna,
531bf9fd70SRasesh Mody 				&bfi_image_ct2_cna_size, CNA_FW_FILE_CT2);
541bf9fd70SRasesh Mody 		return bfi_image_ct2_cna;
551bf9fd70SRasesh Mody 	} else if (bfa_asic_id_ct(pdev->device)) {
56f844a0eaSJeff Kirsher 		if (bfi_image_ct_cna_size == 0)
57f844a0eaSJeff Kirsher 			cna_read_firmware(pdev, &bfi_image_ct_cna,
58f844a0eaSJeff Kirsher 				&bfi_image_ct_cna_size, CNA_FW_FILE_CT);
59f844a0eaSJeff Kirsher 		return bfi_image_ct_cna;
60f844a0eaSJeff Kirsher 	}
61f844a0eaSJeff Kirsher 
621bf9fd70SRasesh Mody 	return NULL;
631bf9fd70SRasesh Mody }
641bf9fd70SRasesh Mody 
65f844a0eaSJeff Kirsher u32 *
661bf9fd70SRasesh Mody bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off)
67f844a0eaSJeff Kirsher {
681bf9fd70SRasesh Mody 	switch (asic_gen) {
691bf9fd70SRasesh Mody 	case BFI_ASIC_GEN_CT:
70f844a0eaSJeff Kirsher 		return (u32 *)(bfi_image_ct_cna + off);
711bf9fd70SRasesh Mody 		break;
721bf9fd70SRasesh Mody 	case BFI_ASIC_GEN_CT2:
731bf9fd70SRasesh Mody 		return (u32 *)(bfi_image_ct2_cna + off);
741bf9fd70SRasesh Mody 		break;
751bf9fd70SRasesh Mody 	default:
761bf9fd70SRasesh Mody 		return NULL;
771bf9fd70SRasesh Mody 	}
78f844a0eaSJeff Kirsher }
79f844a0eaSJeff Kirsher 
80f844a0eaSJeff Kirsher u32
811bf9fd70SRasesh Mody bfa_cb_image_get_size(enum bfi_asic_gen asic_gen)
82f844a0eaSJeff Kirsher {
831bf9fd70SRasesh Mody 	switch (asic_gen) {
841bf9fd70SRasesh Mody 	case BFI_ASIC_GEN_CT:
85f844a0eaSJeff Kirsher 		return bfi_image_ct_cna_size;
861bf9fd70SRasesh Mody 		break;
871bf9fd70SRasesh Mody 	case BFI_ASIC_GEN_CT2:
881bf9fd70SRasesh Mody 		return bfi_image_ct2_cna_size;
891bf9fd70SRasesh Mody 		break;
901bf9fd70SRasesh Mody 	default:
911bf9fd70SRasesh Mody 		return 0;
921bf9fd70SRasesh Mody 	}
93f844a0eaSJeff Kirsher }
94