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#ifndef _VNIC_CQ_H_ 198c2ecf20Sopenharmony_ci#define _VNIC_CQ_H_ 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ci#include "cq_desc.h" 228c2ecf20Sopenharmony_ci#include "vnic_dev.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Completion queue control */ 258c2ecf20Sopenharmony_cistruct vnic_cq_ctrl { 268c2ecf20Sopenharmony_ci u64 ring_base; /* 0x00 */ 278c2ecf20Sopenharmony_ci u32 ring_size; /* 0x08 */ 288c2ecf20Sopenharmony_ci u32 pad0; 298c2ecf20Sopenharmony_ci u32 flow_control_enable; /* 0x10 */ 308c2ecf20Sopenharmony_ci u32 pad1; 318c2ecf20Sopenharmony_ci u32 color_enable; /* 0x18 */ 328c2ecf20Sopenharmony_ci u32 pad2; 338c2ecf20Sopenharmony_ci u32 cq_head; /* 0x20 */ 348c2ecf20Sopenharmony_ci u32 pad3; 358c2ecf20Sopenharmony_ci u32 cq_tail; /* 0x28 */ 368c2ecf20Sopenharmony_ci u32 pad4; 378c2ecf20Sopenharmony_ci u32 cq_tail_color; /* 0x30 */ 388c2ecf20Sopenharmony_ci u32 pad5; 398c2ecf20Sopenharmony_ci u32 interrupt_enable; /* 0x38 */ 408c2ecf20Sopenharmony_ci u32 pad6; 418c2ecf20Sopenharmony_ci u32 cq_entry_enable; /* 0x40 */ 428c2ecf20Sopenharmony_ci u32 pad7; 438c2ecf20Sopenharmony_ci u32 cq_message_enable; /* 0x48 */ 448c2ecf20Sopenharmony_ci u32 pad8; 458c2ecf20Sopenharmony_ci u32 interrupt_offset; /* 0x50 */ 468c2ecf20Sopenharmony_ci u32 pad9; 478c2ecf20Sopenharmony_ci u64 cq_message_addr; /* 0x58 */ 488c2ecf20Sopenharmony_ci u32 pad10; 498c2ecf20Sopenharmony_ci}; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistruct vnic_cq { 528c2ecf20Sopenharmony_ci unsigned int index; 538c2ecf20Sopenharmony_ci struct vnic_dev *vdev; 548c2ecf20Sopenharmony_ci struct vnic_cq_ctrl __iomem *ctrl; /* memory-mapped */ 558c2ecf20Sopenharmony_ci struct vnic_dev_ring ring; 568c2ecf20Sopenharmony_ci unsigned int to_clean; 578c2ecf20Sopenharmony_ci unsigned int last_color; 588c2ecf20Sopenharmony_ci}; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cistatic inline unsigned int svnic_cq_service(struct vnic_cq *cq, 618c2ecf20Sopenharmony_ci unsigned int work_to_do, 628c2ecf20Sopenharmony_ci int (*q_service)(struct vnic_dev *vdev, struct cq_desc *cq_desc, 638c2ecf20Sopenharmony_ci u8 type, u16 q_number, u16 completed_index, void *opaque), 648c2ecf20Sopenharmony_ci void *opaque) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci struct cq_desc *cq_desc; 678c2ecf20Sopenharmony_ci unsigned int work_done = 0; 688c2ecf20Sopenharmony_ci u16 q_number, completed_index; 698c2ecf20Sopenharmony_ci u8 type, color; 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs + 728c2ecf20Sopenharmony_ci cq->ring.desc_size * cq->to_clean); 738c2ecf20Sopenharmony_ci cq_desc_dec(cq_desc, &type, &color, 748c2ecf20Sopenharmony_ci &q_number, &completed_index); 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci while (color != cq->last_color) { 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci if ((*q_service)(cq->vdev, cq_desc, type, 798c2ecf20Sopenharmony_ci q_number, completed_index, opaque)) 808c2ecf20Sopenharmony_ci break; 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci cq->to_clean++; 838c2ecf20Sopenharmony_ci if (cq->to_clean == cq->ring.desc_count) { 848c2ecf20Sopenharmony_ci cq->to_clean = 0; 858c2ecf20Sopenharmony_ci cq->last_color = cq->last_color ? 0 : 1; 868c2ecf20Sopenharmony_ci } 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci cq_desc = (struct cq_desc *)((u8 *)cq->ring.descs + 898c2ecf20Sopenharmony_ci cq->ring.desc_size * cq->to_clean); 908c2ecf20Sopenharmony_ci cq_desc_dec(cq_desc, &type, &color, 918c2ecf20Sopenharmony_ci &q_number, &completed_index); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci work_done++; 948c2ecf20Sopenharmony_ci if (work_done >= work_to_do) 958c2ecf20Sopenharmony_ci break; 968c2ecf20Sopenharmony_ci } 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci return work_done; 998c2ecf20Sopenharmony_ci} 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_civoid svnic_cq_free(struct vnic_cq *cq); 1028c2ecf20Sopenharmony_ciint svnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, 1038c2ecf20Sopenharmony_ci unsigned int index, unsigned int desc_count, unsigned int desc_size); 1048c2ecf20Sopenharmony_civoid svnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable, 1058c2ecf20Sopenharmony_ci unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail, 1068c2ecf20Sopenharmony_ci unsigned int cq_tail_color, unsigned int interrupt_enable, 1078c2ecf20Sopenharmony_ci unsigned int cq_entry_enable, unsigned int message_enable, 1088c2ecf20Sopenharmony_ci unsigned int interrupt_offset, u64 message_addr); 1098c2ecf20Sopenharmony_civoid svnic_cq_clean(struct vnic_cq *cq); 1108c2ecf20Sopenharmony_ci#endif /* _VNIC_CQ_H_ */ 111