18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef _VNIC_CQ_FW_H_
198c2ecf20Sopenharmony_ci#define _VNIC_CQ_FW_H_
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "snic_fwint.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic inline unsigned int
248c2ecf20Sopenharmony_civnic_cq_fw_service(struct vnic_cq *cq,
258c2ecf20Sopenharmony_ci		   int (*q_service)(struct vnic_dev *vdev,
268c2ecf20Sopenharmony_ci				    unsigned int index,
278c2ecf20Sopenharmony_ci				    struct snic_fw_req *desc),
288c2ecf20Sopenharmony_ci		   unsigned int work_to_do)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	struct snic_fw_req *desc;
328c2ecf20Sopenharmony_ci	unsigned int work_done = 0;
338c2ecf20Sopenharmony_ci	u8 color;
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
368c2ecf20Sopenharmony_ci		cq->ring.desc_size * cq->to_clean);
378c2ecf20Sopenharmony_ci	snic_color_dec(desc, &color);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	while (color != cq->last_color) {
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci		if ((*q_service)(cq->vdev, cq->index, desc))
428c2ecf20Sopenharmony_ci			break;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci		cq->to_clean++;
458c2ecf20Sopenharmony_ci		if (cq->to_clean == cq->ring.desc_count) {
468c2ecf20Sopenharmony_ci			cq->to_clean = 0;
478c2ecf20Sopenharmony_ci			cq->last_color = cq->last_color ? 0 : 1;
488c2ecf20Sopenharmony_ci		}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci		desc = (struct snic_fw_req *)((u8 *)cq->ring.descs +
518c2ecf20Sopenharmony_ci			cq->ring.desc_size * cq->to_clean);
528c2ecf20Sopenharmony_ci		snic_color_dec(desc, &color);
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci		work_done++;
558c2ecf20Sopenharmony_ci		if (work_done >= work_to_do)
568c2ecf20Sopenharmony_ci			break;
578c2ecf20Sopenharmony_ci	}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	return work_done;
608c2ecf20Sopenharmony_ci}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci#endif /* _VNIC_CQ_FW_H_ */
63