cna_fwimg.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Linux network driver for Brocade Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #include <linux/firmware.h>
  19. #include "bnad.h"
  20. #include "bfi.h"
  21. #include "cna.h"
  22. const struct firmware *bfi_fw;
  23. static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna;
  24. static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size;
  25. static u32 *
  26. cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
  27. u32 *bfi_image_size, char *fw_name)
  28. {
  29. const struct firmware *fw;
  30. if (request_firmware(&fw, fw_name, &pdev->dev)) {
  31. pr_alert("Can't locate firmware %s\n", fw_name);
  32. goto error;
  33. }
  34. *bfi_image = (u32 *)fw->data;
  35. *bfi_image_size = fw->size/sizeof(u32);
  36. bfi_fw = fw;
  37. return *bfi_image;
  38. error:
  39. return NULL;
  40. }
  41. u32 *
  42. cna_get_firmware_buf(struct pci_dev *pdev)
  43. {
  44. if (pdev->device == BFA_PCI_DEVICE_ID_CT2) {
  45. if (bfi_image_ct2_cna_size == 0)
  46. cna_read_firmware(pdev, &bfi_image_ct2_cna,
  47. &bfi_image_ct2_cna_size, CNA_FW_FILE_CT2);
  48. return bfi_image_ct2_cna;
  49. } else if (bfa_asic_id_ct(pdev->device)) {
  50. if (bfi_image_ct_cna_size == 0)
  51. cna_read_firmware(pdev, &bfi_image_ct_cna,
  52. &bfi_image_ct_cna_size, CNA_FW_FILE_CT);
  53. return bfi_image_ct_cna;
  54. }
  55. return NULL;
  56. }
  57. u32 *
  58. bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off)
  59. {
  60. switch (asic_gen) {
  61. case BFI_ASIC_GEN_CT:
  62. return (bfi_image_ct_cna + off);
  63. break;
  64. case BFI_ASIC_GEN_CT2:
  65. return (bfi_image_ct2_cna + off);
  66. break;
  67. default:
  68. return NULL;
  69. }
  70. }
  71. u32
  72. bfa_cb_image_get_size(enum bfi_asic_gen asic_gen)
  73. {
  74. switch (asic_gen) {
  75. case BFI_ASIC_GEN_CT:
  76. return bfi_image_ct_cna_size;
  77. break;
  78. case BFI_ASIC_GEN_CT2:
  79. return bfi_image_ct2_cna_size;
  80. break;
  81. default:
  82. return 0;
  83. }
  84. }