xref: /freebsd/sys/dev/enic/vnic_intr.c (revision 0acab8b3d1336d4db73a9946ef76b4bcd0b0aabe)
1  /* SPDX-License-Identifier: BSD-3-Clause
2   * Copyright 2008-2017 Cisco Systems, Inc.  All rights reserved.
3   * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4   */
5  
6  #include "enic.h"
7  #include "vnic_dev.h"
8  #include "vnic_intr.h"
9  
vnic_intr_free(struct vnic_intr * intr)10  void vnic_intr_free(struct vnic_intr *intr)
11  {
12  	intr->ctrl = NULL;
13  }
14  
vnic_intr_alloc(struct vnic_dev * vdev,struct vnic_intr * intr,unsigned int index)15  int vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr,
16  	unsigned int index)
17  {
18  	intr->index = index;
19  	intr->vdev = vdev;
20  
21  	intr->ctrl = vnic_dev_get_res(vdev, RES_TYPE_INTR_CTRL, index);
22  	if (!intr->ctrl) {
23  		pr_err("Failed to hook INTR[%d].ctrl resource\n", index);
24  		return (EINVAL);
25  	}
26  
27  	return 0;
28  }
29  
vnic_intr_init(struct vnic_intr * intr,u32 coalescing_timer,unsigned int coalescing_type,unsigned int mask_on_assertion)30  void vnic_intr_init(struct vnic_intr *intr, u32 coalescing_timer,
31  	unsigned int coalescing_type, unsigned int mask_on_assertion)
32  {
33  	vnic_intr_coalescing_timer_set(intr, coalescing_timer);
34  	ENIC_BUS_WRITE_4(intr->ctrl, INTR_COALESCING_TYPE, coalescing_type);
35  	ENIC_BUS_WRITE_4(intr->ctrl, INTR_MASK_ON_ASSERTION, mask_on_assertion);
36  	ENIC_BUS_WRITE_4(intr->ctrl, INTR_CREDITS, 0);
37  }
38  
vnic_intr_coalescing_timer_set(struct vnic_intr * intr,u32 coalescing_timer)39  void vnic_intr_coalescing_timer_set(struct vnic_intr *intr,
40  	u32 coalescing_timer)
41  {
42  	ENIC_BUS_WRITE_4(intr->ctrl, INTR_COALESCING_TIMER,
43  	    vnic_dev_intr_coal_timer_usec_to_hw(intr->vdev, coalescing_timer));
44  }
45  
vnic_intr_clean(struct vnic_intr * intr)46  void vnic_intr_clean(struct vnic_intr *intr)
47  {
48  	ENIC_BUS_WRITE_4(intr->ctrl, INTR_CREDITS, 0);
49  }
50