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