xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/cisco/enic/vnic_intr.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2008-2010 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 
20*4882a593Smuzhiyun #include <linux/kernel.h>
21*4882a593Smuzhiyun #include <linux/errno.h>
22*4882a593Smuzhiyun #include <linux/types.h>
23*4882a593Smuzhiyun #include <linux/pci.h>
24*4882a593Smuzhiyun #include <linux/delay.h>
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #include "vnic_dev.h"
27*4882a593Smuzhiyun #include "vnic_intr.h"
28*4882a593Smuzhiyun #include "enic.h"
29*4882a593Smuzhiyun 
vnic_intr_free(struct vnic_intr * intr)30*4882a593Smuzhiyun void vnic_intr_free(struct vnic_intr *intr)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun 	intr->ctrl = NULL;
33*4882a593Smuzhiyun }
34*4882a593Smuzhiyun 
vnic_intr_alloc(struct vnic_dev * vdev,struct vnic_intr * intr,unsigned int index)35*4882a593Smuzhiyun int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
36*4882a593Smuzhiyun 	unsigned int index)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun 	intr->index = index;
39*4882a593Smuzhiyun 	intr->vdev = vdev;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	intr->ctrl = vnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index);
42*4882a593Smuzhiyun 	if (!intr->ctrl) {
43*4882a593Smuzhiyun 		vdev_err(vdev, "Failed to hook INTR[%d].ctrl resource\n",
44*4882a593Smuzhiyun 			 index);
45*4882a593Smuzhiyun 		return -EINVAL;
46*4882a593Smuzhiyun 	}
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	return 0;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun 
vnic_intr_init(struct vnic_intr * intr,u32 coalescing_timer,unsigned int coalescing_type,unsigned int mask_on_assertion)51*4882a593Smuzhiyun void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
52*4882a593Smuzhiyun 	unsigned int coalescing_type, unsigned int mask_on_assertion)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	vnic_intr_coalescing_timer_set(intr, coalescing_timer);
55*4882a593Smuzhiyun 	iowrite32(coalescing_type, &intr->ctrl->coalescing_type);
56*4882a593Smuzhiyun 	iowrite32(mask_on_assertion, &intr->ctrl->mask_on_assertion);
57*4882a593Smuzhiyun 	iowrite32(0, &intr->ctrl->int_credits);
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun 
vnic_intr_coalescing_timer_set(struct vnic_intr * intr,u32 coalescing_timer)60*4882a593Smuzhiyun void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
61*4882a593Smuzhiyun 	u32 coalescing_timer)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun 	iowrite32(vnic_dev_intr_coal_timer_usec_to_hw(intr->vdev,
64*4882a593Smuzhiyun 		coalescing_timer), &intr->ctrl->coalescing_timer);
65*4882a593Smuzhiyun }
66*4882a593Smuzhiyun 
vnic_intr_clean(struct vnic_intr * intr)67*4882a593Smuzhiyun void vnic_intr_clean(struct vnic_intr *intr)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun 	iowrite32(0, &intr->ctrl->int_credits);
70*4882a593Smuzhiyun }
71