vnic_cq_fw.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef _VNIC_CQ_FW_H_
  18. #define _VNIC_CQ_FW_H_
  19. #include "snic_fwint.h"
  20. static inline unsigned int
  21. vnic_cq_fw_service(struct vnic_cq *cq,
  22. int (*q_service)(struct vnic_dev *vdev,
  23. unsigned int index,
  24. struct snic_fw_req *desc),
  25. unsigned int work_to_do)
  26. {
  27. struct snic_fw_req *desc;
  28. unsigned int work_done = 0;
  29. u8 color;
  30. desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
  31. cq->ring.desc_size * cq->to_clean);
  32. snic_color_dec(desc, &color);
  33. while (color != cq->last_color) {
  34. if ((*q_service)(cq->vdev, cq->index, desc))
  35. break;
  36. cq->to_clean++;
  37. if (cq->to_clean == cq->ring.desc_count) {
  38. cq->to_clean = 0;
  39. cq->last_color = cq->last_color ? 0 : 1;
  40. }
  41. desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
  42. cq->ring.desc_size * cq->to_clean);
  43. snic_color_dec(desc, &color);
  44. work_done++;
  45. if (work_done >= work_to_do)
  46. break;
  47. }
  48. return work_done;
  49. }
  50. #endif /* _VNIC_CQ_FW_H_ */