summaryrefslogtreecommitdiff
path: root/drivers/scsi/snic/vnic_cq_fw.h
blob: d74954bc70e3ce14f2295b7f6937ed3dee553640 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright 2014 Cisco Systems, Inc.  All rights reserved. */

#ifndef _VNIC_CQ_FW_H_
#define _VNIC_CQ_FW_H_

#include "snic_fwint.h"

static inline unsigned int
vnic_cq_fw_service(struct vnic_cq *cq,
		   int (*q_service)(struct vnic_dev *vdev,
				    unsigned int index,
				    struct snic_fw_req *desc),
		   unsigned int work_to_do)

{
	struct snic_fw_req *desc;
	unsigned int work_done = 0;
	u8 color;

	desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
		cq->ring.desc_size * cq->to_clean);
	snic_color_dec(desc, &color);

	while (color != cq->last_color) {

		if ((*q_service)(cq->vdev, cq->index, desc))
			break;

		cq->to_clean++;
		if (cq->to_clean == cq->ring.desc_count) {
			cq->to_clean = 0;
			cq->last_color = cq->last_color ? 0 : 1;
		}

		desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
			cq->ring.desc_size * cq->to_clean);
		snic_color_dec(desc, &color);

		work_done++;
		if (work_done >= work_to_do)
			break;
	}

	return work_done;
}

#endif /* _VNIC_CQ_FW_H_ */