1*e6550b3eSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
25df6d737SAbhijeet Joglekar /*
35df6d737SAbhijeet Joglekar * Copyright 2008 Cisco Systems, Inc. All rights reserved.
45df6d737SAbhijeet Joglekar * Copyright 2007 Nuova Systems, Inc. All rights reserved.
55df6d737SAbhijeet Joglekar */
65df6d737SAbhijeet Joglekar #ifndef _VNIC_CQ_COPY_H_
75df6d737SAbhijeet Joglekar #define _VNIC_CQ_COPY_H_
85df6d737SAbhijeet Joglekar
95df6d737SAbhijeet Joglekar #include "fcpio.h"
105df6d737SAbhijeet Joglekar
vnic_cq_copy_service(struct vnic_cq * cq,int (* q_service)(struct vnic_dev * vdev,unsigned int index,struct fcpio_fw_req * desc),unsigned int work_to_do)115df6d737SAbhijeet Joglekar static inline unsigned int vnic_cq_copy_service(
125df6d737SAbhijeet Joglekar struct vnic_cq *cq,
135df6d737SAbhijeet Joglekar int (*q_service)(struct vnic_dev *vdev,
145df6d737SAbhijeet Joglekar unsigned int index,
155df6d737SAbhijeet Joglekar struct fcpio_fw_req *desc),
165df6d737SAbhijeet Joglekar unsigned int work_to_do)
175df6d737SAbhijeet Joglekar
185df6d737SAbhijeet Joglekar {
195df6d737SAbhijeet Joglekar struct fcpio_fw_req *desc;
205df6d737SAbhijeet Joglekar unsigned int work_done = 0;
215df6d737SAbhijeet Joglekar u8 color;
225df6d737SAbhijeet Joglekar
235df6d737SAbhijeet Joglekar desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs +
245df6d737SAbhijeet Joglekar cq->ring.desc_size * cq->to_clean);
255df6d737SAbhijeet Joglekar fcpio_color_dec(desc, &color);
265df6d737SAbhijeet Joglekar
275df6d737SAbhijeet Joglekar while (color != cq->last_color) {
285df6d737SAbhijeet Joglekar
295df6d737SAbhijeet Joglekar if ((*q_service)(cq->vdev, cq->index, desc))
305df6d737SAbhijeet Joglekar break;
315df6d737SAbhijeet Joglekar
325df6d737SAbhijeet Joglekar cq->to_clean++;
335df6d737SAbhijeet Joglekar if (cq->to_clean == cq->ring.desc_count) {
345df6d737SAbhijeet Joglekar cq->to_clean = 0;
355df6d737SAbhijeet Joglekar cq->last_color = cq->last_color ? 0 : 1;
365df6d737SAbhijeet Joglekar }
375df6d737SAbhijeet Joglekar
385df6d737SAbhijeet Joglekar desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs +
395df6d737SAbhijeet Joglekar cq->ring.desc_size * cq->to_clean);
405df6d737SAbhijeet Joglekar fcpio_color_dec(desc, &color);
415df6d737SAbhijeet Joglekar
425df6d737SAbhijeet Joglekar work_done++;
435df6d737SAbhijeet Joglekar if (work_done >= work_to_do)
445df6d737SAbhijeet Joglekar break;
455df6d737SAbhijeet Joglekar }
465df6d737SAbhijeet Joglekar
475df6d737SAbhijeet Joglekar return work_done;
485df6d737SAbhijeet Joglekar }
495df6d737SAbhijeet Joglekar
505df6d737SAbhijeet Joglekar #endif /* _VNIC_CQ_COPY_H_ */
51