cna_fwimg.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Linux network driver for QLogic BR-series 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-2014 Brocade Communications Systems, Inc.
  15. * Copyright (c) 2014-2015 QLogic Corporation
  16. * All rights reserved
  17. * www.qlogic.com
  18. */
  19. #include <linux/firmware.h>
  20. #include "bnad.h"
  21. #include "bfi.h"
  22. #include "cna.h"
  23. const struct firmware *bfi_fw;
  24. static u32 *bfi_image_ct_cna, *bfi_image_ct2_cna;
  25. static u32 bfi_image_ct_cna_size, bfi_image_ct2_cna_size;
  26. static u32 *
  27. cna_read_firmware(struct pci_dev *pdev, u32 **bfi_image,
  28. u32 *bfi_image_size, char *fw_name)
  29. {
  30. const struct firmware *fw;
  31. u32 n;
  32. if (request_firmware(&fw, fw_name, &pdev->dev)) {
  33. dev_alert(&pdev->dev, "can't load firmware %s\n", fw_name);
  34. goto error;
  35. }
  36. *bfi_image = (u32 *)fw->data;
  37. *bfi_image_size = fw->size/sizeof(u32);
  38. bfi_fw = fw;
  39. /* Convert loaded firmware to host order as it is stored in file
  40. * as sequence of LE32 integers.
  41. */
  42. for (n = 0; n < *bfi_image_size; n++)
  43. le32_to_cpus(*bfi_image + n);
  44. return *bfi_image;
  45. error:
  46. return NULL;
  47. }
  48. u32 *
  49. cna_get_firmware_buf(struct pci_dev *pdev)
  50. {
  51. if (pdev->device == BFA_PCI_DEVICE_ID_CT2) {
  52. if (bfi_image_ct2_cna_size == 0)
  53. cna_read_firmware(pdev, &bfi_image_ct2_cna,
  54. &bfi_image_ct2_cna_size, CNA_FW_FILE_CT2);
  55. return bfi_image_ct2_cna;
  56. } else if (bfa_asic_id_ct(pdev->device)) {
  57. if (bfi_image_ct_cna_size == 0)
  58. cna_read_firmware(pdev, &bfi_image_ct_cna,
  59. &bfi_image_ct_cna_size, CNA_FW_FILE_CT);
  60. return bfi_image_ct_cna;
  61. }
  62. return NULL;
  63. }
  64. u32 *
  65. bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off)
  66. {
  67. switch (asic_gen) {
  68. case BFI_ASIC_GEN_CT:
  69. return (bfi_image_ct_cna + off);
  70. case BFI_ASIC_GEN_CT2:
  71. return (bfi_image_ct2_cna + off);
  72. default:
  73. return NULL;
  74. }
  75. }
  76. u32
  77. bfa_cb_image_get_size(enum bfi_asic_gen asic_gen)
  78. {
  79. switch (asic_gen) {
  80. case BFI_ASIC_GEN_CT:
  81. return bfi_image_ct_cna_size;
  82. case BFI_ASIC_GEN_CT2:
  83. return bfi_image_ct2_cna_size;
  84. default:
  85. return 0;
  86. }
  87. }