xref: /openbmc/linux/drivers/scsi/fnic/vnic_cq_copy.h (revision 9221b289)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
4  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5  */
6 #ifndef _VNIC_CQ_COPY_H_
7 #define _VNIC_CQ_COPY_H_
8 
9 #include "fcpio.h"
10 
11 static inline unsigned int vnic_cq_copy_service(
12 	struct vnic_cq *cq,
13 	int (*q_service)(struct vnic_dev *vdev,
14 			 unsigned int index,
15 			 struct fcpio_fw_req *desc),
16 	unsigned int work_to_do)
17 
18 {
19 	struct fcpio_fw_req *desc;
20 	unsigned int work_done = 0;
21 	u8 color;
22 
23 	desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs +
24 		cq->ring.desc_size * cq->to_clean);
25 	fcpio_color_dec(desc, &color);
26 
27 	while (color != cq->last_color) {
28 
29 		if ((*q_service)(cq->vdev, cq->index, desc))
30 			break;
31 
32 		cq->to_clean++;
33 		if (cq->to_clean == cq->ring.desc_count) {
34 			cq->to_clean = 0;
35 			cq->last_color = cq->last_color ? 0 : 1;
36 		}
37 
38 		desc = (struct fcpio_fw_req *)((u8 *)cq->ring.descs +
39 			cq->ring.desc_size * cq->to_clean);
40 		fcpio_color_dec(desc, &color);
41 
42 		work_done++;
43 		if (work_done >= work_to_do)
44 			break;
45 	}
46 
47 	return work_done;
48 }
49 
50 #endif /* _VNIC_CQ_COPY_H_ */
51