1 /*
2 * Linux network driver for Brocade 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-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
17 */
18 #include <linux/firmware.h>
19 #include "bnad.h"
20 #include "bfi.h"
21 #include "cna.h"
22
23 const struct firmware *bfi_fw;
24 static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna;
25 static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size;
26
27 static u32 *
cna_read_firmware(struct pci_dev * pdev,u32 ** bfi_image,u32 * bfi_image_size,char * fw_name)28 cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
29 u32 *bfi_image_size, char *fw_name)
30 {
31 const struct firmware *fw;
32
33 if (request_firmware(&fw, fw_name, &pdev->dev)) {
34 pr_alert("Can't locate firmware %s\n", fw_name);
35 goto error;
36 }
37
38 *bfi_image = (u32 *)fw->data;
39 *bfi_image_size = fw->size/sizeof(u32);
40 bfi_fw = fw;
41
42 return *bfi_image;
43 error:
44 return NULL;
45 }
46
47 u32 *
cna_get_firmware_buf(struct pci_dev * pdev)48 cna_get_firmware_buf(struct pci_dev *pdev)
49 {
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;
60 }
61
62 return NULL;
63 }
64
65 u32 *
bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen,u32 off)66 bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off)
67 {
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;
75 }
76 }
77
78 u32
bfa_cb_image_get_size(enum bfi_asic_gen asic_gen)79 bfa_cb_image_get_size(enum bfi_asic_gen asic_gen)
80 {
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;
88 }
89 }
90