bfad_fwimg.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_fc_size;
  35. u32 bfi_image_ct_cna_size;
  36. u32 bfi_image_cb_fc_size;
  37. u32 *bfi_image_ct_fc;
  38. u32 *bfi_image_ct_cna;
  39. u32 *bfi_image_cb_fc;
  40. #define BFAD_FW_FILE_CT_FC "ctfw_fc.bin"
  41. #define BFAD_FW_FILE_CT_CNA "ctfw_cna.bin"
  42. #define BFAD_FW_FILE_CB_FC "cbfw_fc.bin"
  43. MODULE_FIRMWARE(BFAD_FW_FILE_CT_FC);
  44. MODULE_FIRMWARE(BFAD_FW_FILE_CT_CNA);
  45. MODULE_FIRMWARE(BFAD_FW_FILE_CB_FC);
  46. u32 *
  47. bfad_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
  48. u32 *bfi_image_size, char *fw_name)
  49. {
  50. const struct firmware *fw;
  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. *bfi_image = vmalloc(fw->size);
  56. if (NULL == *bfi_image) {
  57. printk(KERN_ALERT "Fail to allocate buffer for fw image "
  58. "size=%x!\n", (u32) fw->size);
  59. goto error;
  60. }
  61. memcpy(*bfi_image, fw->data, fw->size);
  62. *bfi_image_size = fw->size/sizeof(u32);
  63. return *bfi_image;
  64. error:
  65. return NULL;
  66. }
  67. u32 *
  68. bfad_get_firmware_buf(struct pci_dev *pdev)
  69. {
  70. if (pdev->device == BFA_PCI_DEVICE_ID_CT_FC) {
  71. if (bfi_image_ct_fc_size == 0)
  72. bfad_read_firmware(pdev, &bfi_image_ct_fc,
  73. &bfi_image_ct_fc_size, BFAD_FW_FILE_CT_FC);
  74. return bfi_image_ct_fc;
  75. } else if (pdev->device == BFA_PCI_DEVICE_ID_CT) {
  76. if (bfi_image_ct_cna_size == 0)
  77. bfad_read_firmware(pdev, &bfi_image_ct_cna,
  78. &bfi_image_ct_cna_size, BFAD_FW_FILE_CT_CNA);
  79. return bfi_image_ct_cna;
  80. } else {
  81. if (bfi_image_cb_fc_size == 0)
  82. bfad_read_firmware(pdev, &bfi_image_cb_fc,
  83. &bfi_image_cb_fc_size, BFAD_FW_FILE_CB_FC);
  84. return bfi_image_cb_fc;
  85. }
  86. }
  87. u32 *
  88. bfi_image_ct_fc_get_chunk(u32 off)
  89. { return (u32 *)(bfi_image_ct_fc + off); }
  90. u32 *
  91. bfi_image_ct_cna_get_chunk(u32 off)
  92. { return (u32 *)(bfi_image_ct_cna + off); }
  93. u32 *
  94. bfi_image_cb_fc_get_chunk(u32 off)
  95. { return (u32 *)(bfi_image_cb_fc + off); }
  96. uint32_t *
  97. bfi_image_get_chunk(int type, uint32_t off)
  98. {
  99. switch (type) {
  100. case BFI_IMAGE_CT_FC: return bfi_image_ct_fc_get_chunk(off); break;
  101. case BFI_IMAGE_CT_CNA: return bfi_image_ct_cna_get_chunk(off); break;
  102. case BFI_IMAGE_CB_FC: return bfi_image_cb_fc_get_chunk(off); break;
  103. default: return 0; break;
  104. }
  105. }
  106. uint32_t
  107. bfi_image_get_size(int type)
  108. {
  109. switch (type) {
  110. case BFI_IMAGE_CT_FC: return bfi_image_ct_fc_size; break;
  111. case BFI_IMAGE_CT_CNA: return bfi_image_ct_cna_size; break;
  112. case BFI_IMAGE_CB_FC: return bfi_image_cb_fc_size; break;
  113. default: return 0; break;
  114. }
  115. }