18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
68c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
78c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
108c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
118c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
128c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
138c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
148c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
158c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
168c2ecf20Sopenharmony_ci * SOFTWARE.
178c2ecf20Sopenharmony_ci */
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/kernel.h>
208c2ecf20Sopenharmony_ci#include <linux/errno.h>
218c2ecf20Sopenharmony_ci#include <linux/types.h>
228c2ecf20Sopenharmony_ci#include <linux/pci.h>
238c2ecf20Sopenharmony_ci#include <linux/delay.h>
248c2ecf20Sopenharmony_ci#include "vnic_dev.h"
258c2ecf20Sopenharmony_ci#include "vnic_intr.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_civoid vnic_intr_free(struct vnic_intr *intr)
288c2ecf20Sopenharmony_ci{
298c2ecf20Sopenharmony_ci	intr->ctrl = NULL;
308c2ecf20Sopenharmony_ci}
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ciint vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
338c2ecf20Sopenharmony_ci	unsigned int index)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	intr->index = index;
368c2ecf20Sopenharmony_ci	intr->vdev = vdev;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	intr->ctrl = vnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index);
398c2ecf20Sopenharmony_ci	if (!intr->ctrl) {
408c2ecf20Sopenharmony_ci		printk(KERN_ERR "Failed to hook INTR[%d].ctrl resource\n",
418c2ecf20Sopenharmony_ci			index);
428c2ecf20Sopenharmony_ci		return -EINVAL;
438c2ecf20Sopenharmony_ci	}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	return 0;
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_civoid vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer,
498c2ecf20Sopenharmony_ci	unsigned int coalescing_type, unsigned int mask_on_assertion)
508c2ecf20Sopenharmony_ci{
518c2ecf20Sopenharmony_ci	iowrite32(coalescing_timer, &intr->ctrl->coalescing_timer);
528c2ecf20Sopenharmony_ci	iowrite32(coalescing_type, &intr->ctrl->coalescing_type);
538c2ecf20Sopenharmony_ci	iowrite32(mask_on_assertion, &intr->ctrl->mask_on_assertion);
548c2ecf20Sopenharmony_ci	iowrite32(0, &intr->ctrl->int_credits);
558c2ecf20Sopenharmony_ci}
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_civoid vnic_intr_clean(struct vnic_intr *intr)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	iowrite32(0, &intr->ctrl->int_credits);
608c2ecf20Sopenharmony_ci}
61