vnic_wq_copy.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  3. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  4. *
  5. * This program is free software; you may redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; version 2 of the License.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  10. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  11. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  12. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  13. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  14. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. * SOFTWARE.
  17. */
  18. #include <linux/errno.h>
  19. #include <linux/types.h>
  20. #include <linux/pci.h>
  21. #include <linux/delay.h>
  22. #include "vnic_wq_copy.h"
  23. void vnic_wq_copy_enable(struct vnic_wq_copy *wq)
  24. {
  25. iowrite32(1, &wq->ctrl->enable);
  26. }
  27. int vnic_wq_copy_disable(struct vnic_wq_copy *wq)
  28. {
  29. unsigned int wait;
  30. iowrite32(0, &wq->ctrl->enable);
  31. /* Wait for HW to ACK disable request */
  32. for (wait = 0; wait < 100; wait++) {
  33. if (!(ioread32(&wq->ctrl->running)))
  34. return 0;
  35. udelay(1);
  36. }
  37. printk(KERN_ERR "Failed to disable Copy WQ[%d],"
  38. " fetch index=%d, posted_index=%d\n",
  39. wq->index, ioread32(&wq->ctrl->fetch_index),
  40. ioread32(&wq->ctrl->posted_index));
  41. return -ENODEV;
  42. }
  43. void vnic_wq_copy_clean(struct vnic_wq_copy *wq,
  44. void (*q_clean)(struct vnic_wq_copy *wq,
  45. struct fcpio_host_req *wq_desc))
  46. {
  47. BUG_ON(ioread32(&wq->ctrl->enable));
  48. if (vnic_wq_copy_desc_in_use(wq))
  49. vnic_wq_copy_service(wq, -1, q_clean);
  50. wq->to_use_index = wq->to_clean_index = 0;
  51. iowrite32(0, &wq->ctrl->fetch_index);
  52. iowrite32(0, &wq->ctrl->posted_index);
  53. iowrite32(0, &wq->ctrl->error_status);
  54. vnic_dev_clear_desc_ring(&wq->ring);
  55. }
  56. void vnic_wq_copy_free(struct vnic_wq_copy *wq)
  57. {
  58. struct vnic_dev *vdev;
  59. vdev = wq->vdev;
  60. vnic_dev_free_desc_ring(vdev, &wq->ring);
  61. wq->ctrl = NULL;
  62. }
  63. int vnic_wq_copy_alloc(struct vnic_dev *vdev, struct vnic_wq_copy *wq,
  64. unsigned int index, unsigned int desc_count,
  65. unsigned int desc_size)
  66. {
  67. int err;
  68. wq->index = index;
  69. wq->vdev = vdev;
  70. wq->to_use_index = wq->to_clean_index = 0;
  71. wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index);
  72. if (!wq->ctrl) {
  73. printk(KERN_ERR "Failed to hook COPY WQ[%d] resource\n", index);
  74. return -EINVAL;
  75. }
  76. vnic_wq_copy_disable(wq);
  77. err = vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size);
  78. if (err)
  79. return err;
  80. return 0;
  81. }
  82. void vnic_wq_copy_init(struct vnic_wq_copy *wq, unsigned int cq_index,
  83. unsigned int error_interrupt_enable,
  84. unsigned int error_interrupt_offset)
  85. {
  86. u64 paddr;
  87. paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET;
  88. writeq(paddr, &wq->ctrl->ring_base);
  89. iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size);
  90. iowrite32(0, &wq->ctrl->fetch_index);
  91. iowrite32(0, &wq->ctrl->posted_index);
  92. iowrite32(cq_index, &wq->ctrl->cq_index);
  93. iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable);
  94. iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset);
  95. }