Merge tag 'bcachefs-2023-11-5' of https://evilpiepirate.org/git/bcachefs
[linux-block.git] / drivers / scsi / snic / vnic_cq_fw.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */
3
4 #ifndef _VNIC_CQ_FW_H_
5 #define _VNIC_CQ_FW_H_
6
7 #include "snic_fwint.h"
8
9 static inline unsigned int
10 vnic_cq_fw_service(struct vnic_cq *cq,
11                    int (*q_service)(struct vnic_dev *vdev,
12                                     unsigned int index,
13                                     struct snic_fw_req *desc),
14                    unsigned int work_to_do)
15
16 {
17         struct snic_fw_req *desc;
18         unsigned int work_done = 0;
19         u8 color;
20
21         desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
22                 cq->ring.desc_size * cq->to_clean);
23         snic_color_dec(desc, &color);
24
25         while (color != cq->last_color) {
26
27                 if ((*q_service)(cq->vdev, cq->index, desc))
28                         break;
29
30                 cq->to_clean++;
31                 if (cq->to_clean == cq->ring.desc_count) {
32                         cq->to_clean = 0;
33                         cq->last_color = cq->last_color ? 0 : 1;
34                 }
35
36                 desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
37                         cq->ring.desc_size * cq->to_clean);
38                 snic_color_dec(desc, &color);
39
40                 work_done++;
41                 if (work_done >= work_to_do)
42                         break;
43         }
44
45         return work_done;
46 }
47
48 #endif /* _VNIC_CQ_FW_H_ */