blob: b2f6949bc8d33996c0cc294b2f4d98367f2257ec [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
36u32 bfi_image_ct_size;
37u32 bfi_image_cb_size;
38u32 *bfi_image_ct;
39u32 *bfi_image_cb;
40
41
42#define BFAD_FW_FILE_CT "ctfw.bin"
43#define BFAD_FW_FILE_CB "cbfw.bin"
44
45u32 *
46bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
47 u32 *bfi_image_size, char *fw_name)
48{
49 const struct firmware *fw;
50
51 if (request_firmware(&fw, fw_name, &pdev->dev)) {
52 printk(KERN_ALERT "Can't locate firmware %s\n", fw_name);
53 goto error;
54 }
55
56 *bfi_image = vmalloc(fw->size);
57 if (NULL == *bfi_image) {
58 printk(KERN_ALERT "Fail to allocate buffer for fw image "
59 "size=%x!\n", (u32) fw->size);
60 goto error;
61 }
62
63 memcpy(*bfi_image, fw->data, fw->size);
64 *bfi_image_size = fw->size/sizeof(u32);
65
66 return(*bfi_image);
67
68error:
69 return(NULL);
70}
71
72u32 *
73bfad_get_firmware_buf(struct pci_dev *pdev)
74{
75 if (pdev->device == BFA_PCI_DEVICE_ID_CT) {
76 if (bfi_image_ct_size == 0)
77 bfad_read_firmware(pdev, &bfi_image_ct,
78 &bfi_image_ct_size, BFAD_FW_FILE_CT);
79 return(bfi_image_ct);
80 } else {
81 if (bfi_image_cb_size == 0)
82 bfad_read_firmware(pdev, &bfi_image_cb,
83 &bfi_image_cb_size, BFAD_FW_FILE_CB);
84 return(bfi_image_cb);
85 }
86}
87
88u32 *
89bfi_image_ct_get_chunk(u32 off)
90{ return (u32 *)(bfi_image_ct + off); }
91
92u32 *
93bfi_image_cb_get_chunk(u32 off)
94{ return (u32 *)(bfi_image_cb + off); }
95