vnic_cq_copy.h 1.7 KB

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