vnic_cq.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2014 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This program is free software; you may redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; version 2 of the License.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  9. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  10. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  11. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  12. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  13. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  14. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  15. * SOFTWARE.
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/types.h>
  19. #include <linux/pci.h>
  20. #include "vnic_dev.h"
  21. #include "vnic_cq.h"
  22. void svnic_cq_free(struct vnic_cq *cq)
  23. {
  24. svnic_dev_free_desc_ring(cq->vdev, &cq->ring);
  25. cq->ctrl = NULL;
  26. }
  27. int svnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq,
  28. unsigned int index, unsigned int desc_count, unsigned int desc_size)
  29. {
  30. int err;
  31. cq->index = index;
  32. cq->vdev = vdev;
  33. cq->ctrl = svnic_dev_get_res(vdev, RES_TYPE_CQ, index);
  34. if (!cq->ctrl) {
  35. pr_err("Failed to hook CQ[%d] resource\n", index);
  36. return -EINVAL;
  37. }
  38. err = svnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size);
  39. if (err)
  40. return err;
  41. return 0;
  42. }
  43. void svnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
  44. unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
  45. unsigned int cq_tail_color, unsigned int interrupt_enable,
  46. unsigned int cq_entry_enable, unsigned int cq_message_enable,
  47. unsigned int interrupt_offset, u64 cq_message_addr)
  48. {
  49. u64 paddr;
  50. paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
  51. writeq(paddr, &cq->ctrl->ring_base);
  52. iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
  53. iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
  54. iowrite32(color_enable, &cq->ctrl->color_enable);
  55. iowrite32(cq_head, &cq->ctrl->cq_head);
  56. iowrite32(cq_tail, &cq->ctrl->cq_tail);
  57. iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
  58. iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
  59. iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
  60. iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
  61. iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
  62. writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
  63. }
  64. void svnic_cq_clean(struct vnic_cq *cq)
  65. {
  66. cq->to_clean = 0;
  67. cq->last_color = 0;
  68. iowrite32(0, &cq->ctrl->cq_head);
  69. iowrite32(0, &cq->ctrl->cq_tail);
  70. iowrite32(1, &cq->ctrl->cq_tail_color);
  71. svnic_dev_clear_desc_ring(&cq->ring);
  72. }