WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / ethernet / brocade / bna / cna_fwimg.c
blob824eaef307043883a4ad9fca175f503ef1dc79d7
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Linux network driver for QLogic BR-series Converged Network Adapter.
4 */
5 /*
6 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
7 * Copyright (c) 2014-2015 QLogic Corporation
8 * All rights reserved
9 * www.qlogic.com
11 #include <linux/firmware.h>
12 #include "bnad.h"
13 #include "bfi.h"
14 #include "cna.h"
16 const struct firmware *bfi_fw;
17 static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna;
18 static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size;
20 static u32 *
21 cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
22 u32 *bfi_image_size, char *fw_name)
24 const struct firmware *fw;
25 u32 n;
27 if (request_firmware(&fw, fw_name, &pdev->dev)) {
28 dev_alert(&pdev->dev, "can't load firmware %s\n", fw_name);
29 goto error;
32 *bfi_image = (u32 *)fw->data;
33 *bfi_image_size = fw->size/sizeof(u32);
34 bfi_fw = fw;
36 /* Convert loaded firmware to host order as it is stored in file
37 * as sequence of LE32 integers.
39 for (n = 0; n < *bfi_image_size; n++)
40 le32_to_cpus(*bfi_image + n);
42 return *bfi_image;
43 error:
44 return NULL;
47 u32 *
48 cna_get_firmware_buf(struct pci_dev *pdev)
50 if (pdev->device == BFA_PCI_DEVICE_ID_CT2) {
51 if (bfi_image_ct2_cna_size == 0)
52 cna_read_firmware(pdev, &bfi_image_ct2_cna,
53 &bfi_image_ct2_cna_size, CNA_FW_FILE_CT2);
54 return bfi_image_ct2_cna;
55 } else if (bfa_asic_id_ct(pdev->device)) {
56 if (bfi_image_ct_cna_size == 0)
57 cna_read_firmware(pdev, &bfi_image_ct_cna,
58 &bfi_image_ct_cna_size, CNA_FW_FILE_CT);
59 return bfi_image_ct_cna;
62 return NULL;
65 u32 *
66 bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off)
68 switch (asic_gen) {
69 case BFI_ASIC_GEN_CT:
70 return (bfi_image_ct_cna + off);
71 case BFI_ASIC_GEN_CT2:
72 return (bfi_image_ct2_cna + off);
73 default:
74 return NULL;
78 u32
79 bfa_cb_image_get_size(enum bfi_asic_gen asic_gen)
81 switch (asic_gen) {
82 case BFI_ASIC_GEN_CT:
83 return bfi_image_ct_cna_size;
84 case BFI_ASIC_GEN_CT2:
85 return bfi_image_ct2_cna_size;
86 default:
87 return 0;