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/errno.h> 198c2ecf20Sopenharmony_ci#include <linux/types.h> 208c2ecf20Sopenharmony_ci#include <linux/pci.h> 218c2ecf20Sopenharmony_ci#include "vnic_dev.h" 228c2ecf20Sopenharmony_ci#include "vnic_cq.h" 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_civoid svnic_cq_free(struct vnic_cq *cq) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci svnic_dev_free_desc_ring(cq->vdev, &cq->ring); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci cq->ctrl = NULL; 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciint svnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, 328c2ecf20Sopenharmony_ci unsigned int index, unsigned int desc_count, unsigned int desc_size) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci cq->index = index; 358c2ecf20Sopenharmony_ci cq->vdev = vdev; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci cq->ctrl = svnic_dev_get_res(vdev, RES_TYPE_CQ, index); 388c2ecf20Sopenharmony_ci if (!cq->ctrl) { 398c2ecf20Sopenharmony_ci pr_err("Failed to hook CQ[%d] resource\n", index); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci return -EINVAL; 428c2ecf20Sopenharmony_ci } 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci return svnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size); 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_civoid svnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable, 488c2ecf20Sopenharmony_ci unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail, 498c2ecf20Sopenharmony_ci unsigned int cq_tail_color, unsigned int interrupt_enable, 508c2ecf20Sopenharmony_ci unsigned int cq_entry_enable, unsigned int cq_message_enable, 518c2ecf20Sopenharmony_ci unsigned int interrupt_offset, u64 cq_message_addr) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci u64 paddr; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET; 568c2ecf20Sopenharmony_ci writeq(paddr, &cq->ctrl->ring_base); 578c2ecf20Sopenharmony_ci iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size); 588c2ecf20Sopenharmony_ci iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable); 598c2ecf20Sopenharmony_ci iowrite32(color_enable, &cq->ctrl->color_enable); 608c2ecf20Sopenharmony_ci iowrite32(cq_head, &cq->ctrl->cq_head); 618c2ecf20Sopenharmony_ci iowrite32(cq_tail, &cq->ctrl->cq_tail); 628c2ecf20Sopenharmony_ci iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color); 638c2ecf20Sopenharmony_ci iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable); 648c2ecf20Sopenharmony_ci iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable); 658c2ecf20Sopenharmony_ci iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable); 668c2ecf20Sopenharmony_ci iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset); 678c2ecf20Sopenharmony_ci writeq(cq_message_addr, &cq->ctrl->cq_message_addr); 688c2ecf20Sopenharmony_ci} 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_civoid svnic_cq_clean(struct vnic_cq *cq) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci cq->to_clean = 0; 738c2ecf20Sopenharmony_ci cq->last_color = 0; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci iowrite32(0, &cq->ctrl->cq_head); 768c2ecf20Sopenharmony_ci iowrite32(0, &cq->ctrl->cq_tail); 778c2ecf20Sopenharmony_ci iowrite32(1, &cq->ctrl->cq_tail_color); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci svnic_dev_clear_desc_ring(&cq->ring); 808c2ecf20Sopenharmony_ci} 81