cudbg_common.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2017 Chelsio Communications. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. */
  17. #include "cxgb4.h"
  18. #include "cudbg_if.h"
  19. #include "cudbg_lib_common.h"
  20. int cudbg_get_buff(struct cudbg_init *pdbg_init,
  21. struct cudbg_buffer *pdbg_buff, u32 size,
  22. struct cudbg_buffer *pin_buff)
  23. {
  24. u32 offset;
  25. offset = pdbg_buff->offset;
  26. if (offset + size > pdbg_buff->size)
  27. return CUDBG_STATUS_NO_MEM;
  28. if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE) {
  29. if (size > pdbg_init->compress_buff_size)
  30. return CUDBG_STATUS_NO_MEM;
  31. pin_buff->data = (char *)pdbg_init->compress_buff;
  32. pin_buff->offset = 0;
  33. pin_buff->size = size;
  34. return 0;
  35. }
  36. pin_buff->data = (char *)pdbg_buff->data + offset;
  37. pin_buff->offset = offset;
  38. pin_buff->size = size;
  39. return 0;
  40. }
  41. void cudbg_put_buff(struct cudbg_init *pdbg_init,
  42. struct cudbg_buffer *pin_buff)
  43. {
  44. /* Clear compression buffer for re-use */
  45. if (pdbg_init->compress_type != CUDBG_COMPRESSION_NONE)
  46. memset(pdbg_init->compress_buff, 0,
  47. pdbg_init->compress_buff_size);
  48. pin_buff->data = NULL;
  49. pin_buff->offset = 0;
  50. pin_buff->size = 0;
  51. }
  52. void cudbg_update_buff(struct cudbg_buffer *pin_buff,
  53. struct cudbg_buffer *pout_buff)
  54. {
  55. /* We already write to buffer provided by ethool, so just
  56. * increment offset to next free space.
  57. */
  58. pout_buff->offset += pin_buff->size;
  59. }