18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright 2008 Cisco Systems, Inc. All rights reserved. 38c2ecf20Sopenharmony_ci * Copyright 2007 Nuova Systems, Inc. All rights reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify 68c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by 78c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 108c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 118c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 128c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 138c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 148c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 158c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 168c2ecf20Sopenharmony_ci * SOFTWARE. 178c2ecf20Sopenharmony_ci */ 188c2ecf20Sopenharmony_ci#ifndef _VNIC_INTR_H_ 198c2ecf20Sopenharmony_ci#define _VNIC_INTR_H_ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include <linux/pci.h> 228c2ecf20Sopenharmony_ci#include "vnic_dev.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* 258c2ecf20Sopenharmony_ci * These defines avoid symbol clash between fnic and enic (Cisco 10G Eth 268c2ecf20Sopenharmony_ci * Driver) when both are built with CONFIG options =y 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ci#define vnic_intr_unmask fnic_intr_unmask 298c2ecf20Sopenharmony_ci#define vnic_intr_mask fnic_intr_mask 308c2ecf20Sopenharmony_ci#define vnic_intr_return_credits fnic_intr_return_credits 318c2ecf20Sopenharmony_ci#define vnic_intr_credits fnic_intr_credits 328c2ecf20Sopenharmony_ci#define vnic_intr_return_all_credits fnic_intr_return_all_credits 338c2ecf20Sopenharmony_ci#define vnic_intr_legacy_pba fnic_intr_legacy_pba 348c2ecf20Sopenharmony_ci#define vnic_intr_free fnic_intr_free 358c2ecf20Sopenharmony_ci#define vnic_intr_alloc fnic_intr_alloc 368c2ecf20Sopenharmony_ci#define vnic_intr_init fnic_intr_init 378c2ecf20Sopenharmony_ci#define vnic_intr_clean fnic_intr_clean 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#define VNIC_INTR_TIMER_MAX 0xffff 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define VNIC_INTR_TIMER_TYPE_ABS 0 428c2ecf20Sopenharmony_ci#define VNIC_INTR_TIMER_TYPE_QUIET 1 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* Interrupt control */ 458c2ecf20Sopenharmony_cistruct vnic_intr_ctrl { 468c2ecf20Sopenharmony_ci u32 coalescing_timer; /* 0x00 */ 478c2ecf20Sopenharmony_ci u32 pad0; 488c2ecf20Sopenharmony_ci u32 coalescing_value; /* 0x08 */ 498c2ecf20Sopenharmony_ci u32 pad1; 508c2ecf20Sopenharmony_ci u32 coalescing_type; /* 0x10 */ 518c2ecf20Sopenharmony_ci u32 pad2; 528c2ecf20Sopenharmony_ci u32 mask_on_assertion; /* 0x18 */ 538c2ecf20Sopenharmony_ci u32 pad3; 548c2ecf20Sopenharmony_ci u32 mask; /* 0x20 */ 558c2ecf20Sopenharmony_ci u32 pad4; 568c2ecf20Sopenharmony_ci u32 int_credits; /* 0x28 */ 578c2ecf20Sopenharmony_ci u32 pad5; 588c2ecf20Sopenharmony_ci u32 int_credit_return; /* 0x30 */ 598c2ecf20Sopenharmony_ci u32 pad6; 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistruct vnic_intr { 638c2ecf20Sopenharmony_ci unsigned int index; 648c2ecf20Sopenharmony_ci struct vnic_dev *vdev; 658c2ecf20Sopenharmony_ci struct vnic_intr_ctrl __iomem *ctrl; /* memory-mapped */ 668c2ecf20Sopenharmony_ci}; 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_cistatic inline void vnic_intr_unmask(struct vnic_intr *intr) 698c2ecf20Sopenharmony_ci{ 708c2ecf20Sopenharmony_ci iowrite32(0, &intr->ctrl->mask); 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic inline void vnic_intr_mask(struct vnic_intr *intr) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci iowrite32(1, &intr->ctrl->mask); 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic inline void vnic_intr_return_credits(struct vnic_intr *intr, 798c2ecf20Sopenharmony_ci unsigned int credits, int unmask, int reset_timer) 808c2ecf20Sopenharmony_ci{ 818c2ecf20Sopenharmony_ci#define VNIC_INTR_UNMASK_SHIFT 16 828c2ecf20Sopenharmony_ci#define VNIC_INTR_RESET_TIMER_SHIFT 17 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci u32 int_credit_return = (credits & 0xffff) | 858c2ecf20Sopenharmony_ci (unmask ? (1 << VNIC_INTR_UNMASK_SHIFT) : 0) | 868c2ecf20Sopenharmony_ci (reset_timer ? (1 << VNIC_INTR_RESET_TIMER_SHIFT) : 0); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci iowrite32(int_credit_return, &intr->ctrl->int_credit_return); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic inline unsigned int vnic_intr_credits(struct vnic_intr *intr) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci return ioread32(&intr->ctrl->int_credits); 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic inline void vnic_intr_return_all_credits(struct vnic_intr *intr) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci unsigned int credits = vnic_intr_credits(intr); 998c2ecf20Sopenharmony_ci int unmask = 1; 1008c2ecf20Sopenharmony_ci int reset_timer = 1; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci vnic_intr_return_credits(intr, credits, unmask, reset_timer); 1038c2ecf20Sopenharmony_ci} 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistatic inline u32 vnic_intr_legacy_pba(u32 __iomem *legacy_pba) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci /* read PBA without clearing */ 1088c2ecf20Sopenharmony_ci return ioread32(legacy_pba); 1098c2ecf20Sopenharmony_ci} 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_civoid vnic_intr_free(struct vnic_intr *intr); 1128c2ecf20Sopenharmony_ciint vnic_intr_alloc(struct vnic_dev *vdev, struct vnic_intr *intr, 1138c2ecf20Sopenharmony_ci unsigned int index); 1148c2ecf20Sopenharmony_civoid vnic_intr_init(struct vnic_intr *intr, unsigned int coalescing_timer, 1158c2ecf20Sopenharmony_ci unsigned int coalescing_type, unsigned int mask_on_assertion); 1168c2ecf20Sopenharmony_civoid vnic_intr_clean(struct vnic_intr *intr); 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#endif /* _VNIC_INTR_H_ */ 119