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_INTR_H_
198c2ecf20Sopenharmony_ci#define _VNIC_INTR_H_
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include <linux/pci.h>
228c2ecf20Sopenharmony_ci#include "vnic_dev.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define VNIC_INTR_TIMER_MAX		0xffff
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define VNIC_INTR_TIMER_TYPE_ABS	0
278c2ecf20Sopenharmony_ci#define VNIC_INTR_TIMER_TYPE_QUIET	1
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* Interrupt control */
308c2ecf20Sopenharmony_cistruct vnic_intr_ctrl {
318c2ecf20Sopenharmony_ci	u32 coalescing_timer;		/* 0x00 */
328c2ecf20Sopenharmony_ci	u32 pad0;
338c2ecf20Sopenharmony_ci	u32 coalescing_value;		/* 0x08 */
348c2ecf20Sopenharmony_ci	u32 pad1;
358c2ecf20Sopenharmony_ci	u32 coalescing_type;		/* 0x10 */
368c2ecf20Sopenharmony_ci	u32 pad2;
378c2ecf20Sopenharmony_ci	u32 mask_on_assertion;		/* 0x18 */
388c2ecf20Sopenharmony_ci	u32 pad3;
398c2ecf20Sopenharmony_ci	u32 mask;			/* 0x20 */
408c2ecf20Sopenharmony_ci	u32 pad4;
418c2ecf20Sopenharmony_ci	u32 int_credits;		/* 0x28 */
428c2ecf20Sopenharmony_ci	u32 pad5;
438c2ecf20Sopenharmony_ci	u32 int_credit_return;		/* 0x30 */
448c2ecf20Sopenharmony_ci	u32 pad6;
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistruct vnic_intr {
488c2ecf20Sopenharmony_ci	unsigned int index;
498c2ecf20Sopenharmony_ci	struct vnic_dev *vdev;
508c2ecf20Sopenharmony_ci	struct vnic_intr_ctrl __iomem *ctrl;	/* memory-mapped */
518c2ecf20Sopenharmony_ci};
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic inline void
548c2ecf20Sopenharmony_cisvnic_intr_unmask(struct vnic_intr *intr)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	iowrite32(0, &intr->ctrl->mask);
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic inline void
608c2ecf20Sopenharmony_cisvnic_intr_mask(struct vnic_intr *intr)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	iowrite32(1, &intr->ctrl->mask);
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistatic inline void
668c2ecf20Sopenharmony_cisvnic_intr_return_credits(struct vnic_intr *intr,
678c2ecf20Sopenharmony_ci			  unsigned int credits,
688c2ecf20Sopenharmony_ci			  int unmask,
698c2ecf20Sopenharmony_ci			  int reset_timer)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci#define VNIC_INTR_UNMASK_SHIFT		16
728c2ecf20Sopenharmony_ci#define VNIC_INTR_RESET_TIMER_SHIFT	17
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	u32 int_credit_return = (credits & 0xffff) |
758c2ecf20Sopenharmony_ci		(unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) |
768c2ecf20Sopenharmony_ci		(reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	iowrite32(int_credit_return, &intr->ctrl->int_credit_return);
798c2ecf20Sopenharmony_ci}
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistatic inline unsigned int
828c2ecf20Sopenharmony_cisvnic_intr_credits(struct vnic_intr *intr)
838c2ecf20Sopenharmony_ci{
848c2ecf20Sopenharmony_ci	return ioread32(&intr->ctrl->int_credits);
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic inline void
888c2ecf20Sopenharmony_cisvnic_intr_return_all_credits(struct vnic_intr *intr)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	unsigned int credits = svnic_intr_credits(intr);
918c2ecf20Sopenharmony_ci	int unmask = 1;
928c2ecf20Sopenharmony_ci	int reset_timer = 1;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	svnic_intr_return_credits(intr, credits, unmask, reset_timer);
958c2ecf20Sopenharmony_ci}
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_civoid svnic_intr_free(struct vnic_intr *);
988c2ecf20Sopenharmony_ciint svnic_intr_alloc(struct vnic_dev *, struct vnic_intr *, unsigned int);
998c2ecf20Sopenharmony_civoid svnic_intr_init(struct vnic_intr *intr,
1008c2ecf20Sopenharmony_ci		     unsigned int coalescing_timer,
1018c2ecf20Sopenharmony_ci		     unsigned int coalescing_type,
1028c2ecf20Sopenharmony_ci		     unsigned int mask_on_assertion);
1038c2ecf20Sopenharmony_civoid svnic_intr_clean(struct vnic_intr *);
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#endif /* _VNIC_INTR_H_ */
106