vnic_wq_copy.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  4. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  5. */
  6. #include <linux/errno.h>
  7. #include <linux/types.h>
  8. #include <linux/pci.h>
  9. #include <linux/delay.h>
  10. #include "vnic_wq_copy.h"
  11. void vnic_wq_copy_enable(struct vnic_wq_copy *wq)
  12. {
  13. iowrite32(1, &wq->ctrl->enable);
  14. }
  15. int vnic_wq_copy_disable(struct vnic_wq_copy *wq)
  16. {
  17. unsigned int wait;
  18. iowrite32(0, &wq->ctrl->enable);
  19. /* Wait for HW to ACK disable request */
  20. for (wait = 0; wait < 100; wait++) {
  21. if (!(ioread32(&wq->ctrl->running)))
  22. return 0;
  23. udelay(1);
  24. }
  25. printk(KERN_ERR "Failed to disable Copy WQ[%d],"
  26. " fetch index=%d, posted_index=%d\n",
  27. wq->index, ioread32(&wq->ctrl->fetch_index),
  28. ioread32(&wq->ctrl->posted_index));
  29. return -ENODEV;
  30. }
  31. void vnic_wq_copy_clean(struct vnic_wq_copy *wq,
  32. void (*q_clean)(struct vnic_wq_copy *wq,
  33. struct fcpio_host_req *wq_desc))
  34. {
  35. BUG_ON(ioread32(&wq->ctrl->enable));
  36. if (vnic_wq_copy_desc_in_use(wq))
  37. vnic_wq_copy_service(wq, -1, q_clean);
  38. wq->to_use_index = wq->to_clean_index = 0;
  39. iowrite32(0, &wq->ctrl->fetch_index);
  40. iowrite32(0, &wq->ctrl->posted_index);
  41. iowrite32(0, &wq->ctrl->error_status);
  42. vnic_dev_clear_desc_ring(&wq->ring);
  43. }
  44. void vnic_wq_copy_free(struct vnic_wq_copy *wq)
  45. {
  46. struct vnic_dev *vdev;
  47. vdev = wq->vdev;
  48. vnic_dev_free_desc_ring(vdev, &wq->ring);
  49. wq->ctrl = NULL;
  50. }
  51. int vnic_wq_copy_alloc(struct vnic_dev *vdev, struct vnic_wq_copy *wq,
  52. unsigned int index, unsigned int desc_count,
  53. unsigned int desc_size)
  54. {
  55. wq->index = index;
  56. wq->vdev = vdev;
  57. wq->to_use_index = wq->to_clean_index = 0;
  58. wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index);
  59. if (!wq->ctrl) {
  60. printk(KERN_ERR "Failed to hook COPY WQ[%d] resource\n", index);
  61. return -EINVAL;
  62. }
  63. vnic_wq_copy_disable(wq);
  64. return vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size);
  65. }
  66. void vnic_wq_copy_init(struct vnic_wq_copy *wq, unsigned int cq_index,
  67. unsigned int error_interrupt_enable,
  68. unsigned int error_interrupt_offset)
  69. {
  70. u64 paddr;
  71. paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET;
  72. writeq(paddr, &wq->ctrl->ring_base);
  73. iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size);
  74. iowrite32(0, &wq->ctrl->fetch_index);
  75. iowrite32(0, &wq->ctrl->posted_index);
  76. iowrite32(cq_index, &wq->ctrl->cq_index);
  77. iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable);
  78. iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset);
  79. }