hinic_hw_wq.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Huawei HiNIC PCI Express Linux driver
  3. * Copyright(c) 2017 Huawei Technologies Co., Ltd
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. */
  15. #ifndef HINIC_HW_WQ_H
  16. #define HINIC_HW_WQ_H
  17. #include <linux/types.h>
  18. #include <linux/semaphore.h>
  19. #include <linux/atomic.h>
  20. #include "hinic_hw_if.h"
  21. #include "hinic_hw_wqe.h"
  22. struct hinic_free_block {
  23. int page_idx;
  24. int block_idx;
  25. };
  26. struct hinic_wq {
  27. struct hinic_hwif *hwif;
  28. int page_idx;
  29. int block_idx;
  30. u16 wqebb_size;
  31. u16 wq_page_size;
  32. u16 q_depth;
  33. u16 max_wqe_size;
  34. u16 num_wqebbs_per_page;
  35. /* The addresses are 64 bit in the HW */
  36. u64 block_paddr;
  37. void **shadow_block_vaddr;
  38. u64 *block_vaddr;
  39. int num_q_pages;
  40. u8 *shadow_wqe;
  41. u16 *shadow_idx;
  42. atomic_t cons_idx;
  43. atomic_t prod_idx;
  44. atomic_t delta;
  45. u16 mask;
  46. };
  47. struct hinic_wqs {
  48. struct hinic_hwif *hwif;
  49. int num_pages;
  50. /* The addresses are 64 bit in the HW */
  51. u64 *page_paddr;
  52. u64 **page_vaddr;
  53. void ***shadow_page_vaddr;
  54. struct hinic_free_block *free_blocks;
  55. int alloc_blk_pos;
  56. int return_blk_pos;
  57. int num_free_blks;
  58. /* Lock for getting a free block from the WQ set */
  59. struct semaphore alloc_blocks_lock;
  60. };
  61. struct hinic_cmdq_pages {
  62. /* The addresses are 64 bit in the HW */
  63. u64 page_paddr;
  64. u64 *page_vaddr;
  65. void **shadow_page_vaddr;
  66. struct hinic_hwif *hwif;
  67. };
  68. int hinic_wqs_cmdq_alloc(struct hinic_cmdq_pages *cmdq_pages,
  69. struct hinic_wq *wq, struct hinic_hwif *hwif,
  70. int cmdq_blocks, u16 wqebb_size, u16 wq_page_size,
  71. u16 q_depth, u16 max_wqe_size);
  72. void hinic_wqs_cmdq_free(struct hinic_cmdq_pages *cmdq_pages,
  73. struct hinic_wq *wq, int cmdq_blocks);
  74. int hinic_wqs_alloc(struct hinic_wqs *wqs, int num_wqs,
  75. struct hinic_hwif *hwif);
  76. void hinic_wqs_free(struct hinic_wqs *wqs);
  77. int hinic_wq_allocate(struct hinic_wqs *wqs, struct hinic_wq *wq,
  78. u16 wqebb_size, u16 wq_page_size, u16 q_depth,
  79. u16 max_wqe_size);
  80. void hinic_wq_free(struct hinic_wqs *wqs, struct hinic_wq *wq);
  81. struct hinic_hw_wqe *hinic_get_wqe(struct hinic_wq *wq, unsigned int wqe_size,
  82. u16 *prod_idx);
  83. void hinic_put_wqe(struct hinic_wq *wq, unsigned int wqe_size);
  84. struct hinic_hw_wqe *hinic_read_wqe(struct hinic_wq *wq, unsigned int wqe_size,
  85. u16 *cons_idx);
  86. struct hinic_hw_wqe *hinic_read_wqe_direct(struct hinic_wq *wq, u16 cons_idx);
  87. void hinic_write_wqe(struct hinic_wq *wq, struct hinic_hw_wqe *wqe,
  88. unsigned int wqe_size);
  89. #endif