blob: 1baca1a12085f4366f2d05aa64ae91b0d8114edd [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
18/**
19 * bfad_fwimg.c Linux driver PCI interface module.
20 */
21#include <bfa_os_inc.h>
22#include <bfad_drv.h>
23#include <bfad_im_compat.h>
24#include <defs/bfa_defs_version.h>
25#include <linux/errno.h>
26#include <linux/sched.h>
27#include <linux/init.h>
28#include <linux/fs.h>
29#include <asm/uaccess.h>
30#include <asm/fcntl.h>
31#include <linux/pci.h>
32#include <linux/firmware.h>
33#include <bfa_fwimg_priv.h>
34#include <bfa.h>
35
Jing Huang293f82d2010-07-08 19:45:20 -070036u32 bfi_image_ct_fc_size;
37u32 bfi_image_ct_cna_size;
38u32 bfi_image_cb_fc_size;
39u32 *bfi_image_ct_fc;
40u32 *bfi_image_ct_cna;
41u32 *bfi_image_cb_fc;
Jing Huang7725ccf2009-09-23 17:46:15 -070042
43
Jing Huang293f82d2010-07-08 19:45:20 -070044#define BFAD_FW_FILE_CT_FC "ctfw_fc.bin"
45#define BFAD_FW_FILE_CT_CNA "ctfw_cna.bin"
46#define BFAD_FW_FILE_CB_FC "cbfw_fc.bin"
47MODULE_FIRMWARE(BFAD_FW_FILE_CT_FC);
48MODULE_FIRMWARE(BFAD_FW_FILE_CT_CNA);
49MODULE_FIRMWARE(BFAD_FW_FILE_CB_FC);
Jing Huang7725ccf2009-09-23 17:46:15 -070050
51u32 *
52bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
53 u32 *bfi_image_size, char *fw_name)
54{
55 const struct firmware *fw;
56
57 if (request_firmware(&fw, fw_name, &pdev->dev)) {
58 printk(KERN_ALERT "Can't locate firmware %s\n", fw_name);
59 goto error;
60 }
61
62 *bfi_image = vmalloc(fw->size);
63 if (NULL == *bfi_image) {
64 printk(KERN_ALERT "Fail to allocate buffer for fw image "
65 "size=%x!\n", (u32) fw->size);
66 goto error;
67 }
68
69 memcpy(*bfi_image, fw->data, fw->size);
70 *bfi_image_size = fw->size/sizeof(u32);
71
Jing Huangf8ceafd2009-09-25 12:29:54 -070072 return *bfi_image;
Jing Huang7725ccf2009-09-23 17:46:15 -070073
74error:
Jing Huangf8ceafd2009-09-25 12:29:54 -070075 return NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -070076}
77
78u32 *
79bfad_get_firmware_buf(struct pci_dev *pdev)
80{
Jing Huang293f82d2010-07-08 19:45:20 -070081 if (pdev->device == BFA_PCI_DEVICE_ID_CT_FC) {
82 if (bfi_image_ct_fc_size == 0)
83 bfad_read_firmware(pdev, &bfi_image_ct_fc,
84 &bfi_image_ct_fc_size, BFAD_FW_FILE_CT_FC);
85 return bfi_image_ct_fc;
86 } else if (pdev->device == BFA_PCI_DEVICE_ID_CT) {
87 if (bfi_image_ct_cna_size == 0)
88 bfad_read_firmware(pdev, &bfi_image_ct_cna,
89 &bfi_image_ct_cna_size, BFAD_FW_FILE_CT_CNA);
90 return bfi_image_ct_cna;
Jing Huang7725ccf2009-09-23 17:46:15 -070091 } else {
Jing Huang293f82d2010-07-08 19:45:20 -070092 if (bfi_image_cb_fc_size == 0)
93 bfad_read_firmware(pdev, &bfi_image_cb_fc,
94 &bfi_image_cb_fc_size, BFAD_FW_FILE_CB_FC);
95 return bfi_image_cb_fc;
Jing Huang7725ccf2009-09-23 17:46:15 -070096 }
97}
98
99u32 *
Jing Huang293f82d2010-07-08 19:45:20 -0700100bfi_image_ct_fc_get_chunk(u32 off)
101{ return (u32 *)(bfi_image_ct_fc + off); }
Jing Huang7725ccf2009-09-23 17:46:15 -0700102
103u32 *
Jing Huang293f82d2010-07-08 19:45:20 -0700104bfi_image_ct_cna_get_chunk(u32 off)
105{ return (u32 *)(bfi_image_ct_cna + off); }
Jing Huang7725ccf2009-09-23 17:46:15 -0700106
Jing Huang293f82d2010-07-08 19:45:20 -0700107u32 *
108bfi_image_cb_fc_get_chunk(u32 off)
109{ return (u32 *)(bfi_image_cb_fc + off); }
110
111uint32_t *
112bfi_image_get_chunk(int type, uint32_t off)
113{
114 switch (type) {
115 case BFI_IMAGE_CT_FC: return bfi_image_ct_fc_get_chunk(off); break;
116 case BFI_IMAGE_CT_CNA: return bfi_image_ct_cna_get_chunk(off); break;
117 case BFI_IMAGE_CB_FC: return bfi_image_cb_fc_get_chunk(off); break;
118 default: return 0; break;
119 }
120}
121
122uint32_t
123bfi_image_get_size(int type)
124{
125 switch (type) {
126 case BFI_IMAGE_CT_FC: return bfi_image_ct_fc_size; break;
127 case BFI_IMAGE_CT_CNA: return bfi_image_ct_cna_size; break;
128 case BFI_IMAGE_CB_FC: return bfi_image_cb_fc_size; break;
129 default: return 0; break;
130 }
131}