bfad_fwimg.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. * bfad_fwimg.c Linux driver PCI interface module.
  19. */
  20. #include <bfa_os_inc.h>
  21. #include <bfad_drv.h>
  22. #include <bfad_im_compat.h>
  23. #include <defs/bfa_defs_version.h>
  24. #include <linux/errno.h>
  25. #include <linux/sched.h>
  26. #include <linux/init.h>
  27. #include <linux/fs.h>
  28. #include <asm/uaccess.h>
  29. #include <asm/fcntl.h>
  30. #include <linux/pci.h>
  31. #include <linux/firmware.h>
  32. #include <bfa_fwimg_priv.h>
  33. #include <bfa.h>
  34. u32 bfi_image_ct_size;
  35. u32 bfi_image_cb_size;
  36. u32 *bfi_image_ct;
  37. u32 *bfi_image_cb;
  38. #define BFAD_FW_FILE_CT "ctfw.bin"
  39. #define BFAD_FW_FILE_CB "cbfw.bin"
  40. MODULE_FIRMWARE(BFAD_FW_FILE_CT);
  41. MODULE_FIRMWARE(BFAD_FW_FILE_CB);
  42. u32 *
  43. bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
  44. u32 *bfi_image_size, char *fw_name)
  45. {
  46. const struct firmware *fw;
  47. if (request_firmware(&fw, fw_name, &pdev->dev)) {
  48. printk(KERN_ALERT "Can't locate firmware %s\n", fw_name);
  49. goto error;
  50. }
  51. *bfi_image = vmalloc(fw->size);
  52. if (NULL == *bfi_image) {
  53. printk(KERN_ALERT "Fail to allocate buffer for fw image "
  54. "size=%x!\n", (u32) fw->size);
  55. goto error;
  56. }
  57. memcpy(*bfi_image, fw->data, fw->size);
  58. *bfi_image_size = fw->size/sizeof(u32);
  59. return *bfi_image;
  60. error:
  61. return NULL;
  62. }
  63. u32 *
  64. bfad_get_firmware_buf(struct pci_dev *pdev)
  65. {
  66. if (pdev->device == BFA_PCI_DEVICE_ID_CT) {
  67. if (bfi_image_ct_size == 0)
  68. bfad_read_firmware(pdev, &bfi_image_ct,
  69. &bfi_image_ct_size, BFAD_FW_FILE_CT);
  70. return bfi_image_ct;
  71. } else {
  72. if (bfi_image_cb_size == 0)
  73. bfad_read_firmware(pdev, &bfi_image_cb,
  74. &bfi_image_cb_size, BFAD_FW_FILE_CB);
  75. return bfi_image_cb;
  76. }
  77. }
  78. u32 *
  79. bfi_image_ct_get_chunk(u32 off)
  80. { return (u32 *)(bfi_image_ct + off); }
  81. u32 *
  82. bfi_image_cb_get_chunk(u32 off)
  83. { return (u32 *)(bfi_image_cb + off); }