vnic_cq.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. #include <linux/errno.h>
  4. #include <linux/types.h>
  5. #include <linux/pci.h>
  6. #include "vnic_dev.h"
  7. #include "vnic_cq.h"
  8. void svnic_cq_free(struct vnic_cq *cq)
  9. {
  10. svnic_dev_free_desc_ring(cq->vdev, &cq->ring);
  11. cq->ctrl = NULL;
  12. }
  13. int svnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq,
  14. unsigned int index, unsigned int desc_count, unsigned int desc_size)
  15. {
  16. cq->index = index;
  17. cq->vdev = vdev;
  18. cq->ctrl = svnic_dev_get_res(vdev, RES_TYPE_CQ, index);
  19. if (!cq->ctrl) {
  20. pr_err("Failed to hook CQ[%d] resource\n", index);
  21. return -EINVAL;
  22. }
  23. return svnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size);
  24. }
  25. void svnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
  26. unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
  27. unsigned int cq_tail_color, unsigned int interrupt_enable,
  28. unsigned int cq_entry_enable, unsigned int cq_message_enable,
  29. unsigned int interrupt_offset, u64 cq_message_addr)
  30. {
  31. u64 paddr;
  32. paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
  33. writeq(paddr, &cq->ctrl->ring_base);
  34. iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
  35. iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
  36. iowrite32(color_enable, &cq->ctrl->color_enable);
  37. iowrite32(cq_head, &cq->ctrl->cq_head);
  38. iowrite32(cq_tail, &cq->ctrl->cq_tail);
  39. iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
  40. iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
  41. iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
  42. iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
  43. iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
  44. writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
  45. }
  46. void svnic_cq_clean(struct vnic_cq *cq)
  47. {
  48. cq->to_clean = 0;
  49. cq->last_color = 0;
  50. iowrite32(0, &cq->ctrl->cq_head);
  51. iowrite32(0, &cq->ctrl->cq_tail);
  52. iowrite32(1, &cq->ctrl->cq_tail_color);
  53. svnic_dev_clear_desc_ring(&cq->ring);
  54. }