vnic_cq.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2008-2010 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. */
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/types.h>
  22. #include <linux/pci.h>
  23. #include "vnic_dev.h"
  24. #include "vnic_cq.h"
  25. #include "enic.h"
  26. void vnic_cq_free(struct vnic_cq *cq)
  27. {
  28. vnic_dev_free_desc_ring(cq->vdev, &cq->ring);
  29. cq->ctrl = NULL;
  30. }
  31. int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
  32. unsigned int desc_count, unsigned int desc_size)
  33. {
  34. int err;
  35. cq->index = index;
  36. cq->vdev = vdev;
  37. cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index);
  38. if (!cq->ctrl) {
  39. vdev_err("Failed to hook CQ[%d] resource\n", index);
  40. return -EINVAL;
  41. }
  42. err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size);
  43. if (err)
  44. return err;
  45. return 0;
  46. }
  47. void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
  48. unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
  49. unsigned int cq_tail_color, unsigned int interrupt_enable,
  50. unsigned int cq_entry_enable, unsigned int cq_message_enable,
  51. unsigned int interrupt_offset, u64 cq_message_addr)
  52. {
  53. u64 paddr;
  54. paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
  55. writeq(paddr, &cq->ctrl->ring_base);
  56. iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
  57. iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
  58. iowrite32(color_enable, &cq->ctrl->color_enable);
  59. iowrite32(cq_head, &cq->ctrl->cq_head);
  60. iowrite32(cq_tail, &cq->ctrl->cq_tail);
  61. iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
  62. iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
  63. iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
  64. iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
  65. iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
  66. writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
  67. cq->interrupt_offset = interrupt_offset;
  68. }
  69. void vnic_cq_clean(struct vnic_cq *cq)
  70. {
  71. cq->to_clean = 0;
  72. cq->last_color = 0;
  73. iowrite32(0, &cq->ctrl->cq_head);
  74. iowrite32(0, &cq->ctrl->cq_tail);
  75. iowrite32(1, &cq->ctrl->cq_tail_color);
  76. vnic_dev_clear_desc_ring(&cq->ring);
  77. }