vnic_cq.c 2.1 KB

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