84368afc90778bdcba47c5c02a3cd042bd8393ec
[dpdk.git] / lib / librte_pmd_enic / vnic / vnic_intr.c
1 /*
2  * Copyright 2008-2010 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2014, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 #ident "$Id: vnic_intr.c 171146 2014-05-02 07:08:20Z ssujith $"
35
36 #include "vnic_dev.h"
37 #include "vnic_intr.h"
38
39 void vnic_intr_free(struct vnic_intr *intr)
40 {
41         intr->ctrl = NULL;
42 }
43
44 int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
45         unsigned int index)
46 {
47         intr->index = index;
48         intr->vdev = vdev;
49
50         intr->ctrl = vnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index);
51         if (!intr->ctrl) {
52                 pr_err("Failed to hook INTR[%d].ctrl resource\n", index);
53                 return -EINVAL;
54         }
55
56         return 0;
57 }
58
59 void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
60         unsigned int coalescing_type, unsigned int mask_on_assertion)
61 {
62         vnic_intr_coalescing_timer_set(intr, coalescing_timer);
63         iowrite32(coalescing_type, &intr->ctrl->coalescing_type);
64         iowrite32(mask_on_assertion, &intr->ctrl->mask_on_assertion);
65         iowrite32(0, &intr->ctrl->int_credits);
66 }
67
68 void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
69         u32 coalescing_timer)
70 {
71         iowrite32(vnic_dev_intr_coal_timer_usec_to_hw(intr->vdev,
72                 coalescing_timer), &intr->ctrl->coalescing_timer);
73 }
74
75 void vnic_intr_clean(struct vnic_intr *intr)
76 {
77         iowrite32(0, &intr->ctrl->int_credits);
78 }