1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3*4882a593Smuzhiyun * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * This program is free software; you may redistribute it and/or modify
6*4882a593Smuzhiyun * it under the terms of the GNU General Public License as published by
7*4882a593Smuzhiyun * the Free Software Foundation; version 2 of the License.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12*4882a593Smuzhiyun * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13*4882a593Smuzhiyun * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14*4882a593Smuzhiyun * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15*4882a593Smuzhiyun * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16*4882a593Smuzhiyun * SOFTWARE.
17*4882a593Smuzhiyun */
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun #include <linux/kernel.h>
20*4882a593Smuzhiyun #include <linux/errno.h>
21*4882a593Smuzhiyun #include <linux/types.h>
22*4882a593Smuzhiyun #include <linux/pci.h>
23*4882a593Smuzhiyun #include <linux/delay.h>
24*4882a593Smuzhiyun #include "vnic_dev.h"
25*4882a593Smuzhiyun #include "vnic_intr.h"
26*4882a593Smuzhiyun
vnic_intr_free(struct vnic_intr * intr)27*4882a593Smuzhiyun void vnic_intr_free(struct vnic_intr *intr)
28*4882a593Smuzhiyun {
29*4882a593Smuzhiyun intr->ctrl = NULL;
30*4882a593Smuzhiyun }
31*4882a593Smuzhiyun
vnic_intr_alloc(struct vnic_dev * vdev,struct vnic_intr * intr,unsigned int index)32*4882a593Smuzhiyun int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
33*4882a593Smuzhiyun unsigned int index)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun intr->index = index;
36*4882a593Smuzhiyun intr->vdev = vdev;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun intr->ctrl = vnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index);
39*4882a593Smuzhiyun if (!intr->ctrl) {
40*4882a593Smuzhiyun printk(KERN_ERR "Failed to hook INTR[%d].ctrl resource\n",
41*4882a593Smuzhiyun index);
42*4882a593Smuzhiyun return -EINVAL;
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun return 0;
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
vnic_intr_init(struct vnic_intr * intr,unsigned int coalescing_timer,unsigned int coalescing_type,unsigned int mask_on_assertion)48*4882a593Smuzhiyun void vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer,
49*4882a593Smuzhiyun unsigned int coalescing_type, unsigned int mask_on_assertion)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun iowrite32(coalescing_timer, &intr->ctrl->coalescing_timer);
52*4882a593Smuzhiyun iowrite32(coalescing_type, &intr->ctrl->coalescing_type);
53*4882a593Smuzhiyun iowrite32(mask_on_assertion, &intr->ctrl->mask_on_assertion);
54*4882a593Smuzhiyun iowrite32(0, &intr->ctrl->int_credits);
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun
vnic_intr_clean(struct vnic_intr * intr)57*4882a593Smuzhiyun void vnic_intr_clean(struct vnic_intr *intr)
58*4882a593Smuzhiyun {
59*4882a593Smuzhiyun iowrite32(0, &intr->ctrl->int_credits);
60*4882a593Smuzhiyun }
61