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