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#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 vnic_cq_free(struct vnic_cq *cq) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci vnic_dev_free_desc_ring(cq->vdev, &cq->ring); 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci cq->ctrl = NULL; 298c2ecf20Sopenharmony_ci} 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciint vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index, 328c2ecf20Sopenharmony_ci unsigned int desc_count, unsigned int desc_size) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci int err; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci cq->index = index; 378c2ecf20Sopenharmony_ci cq->vdev = vdev; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index); 408c2ecf20Sopenharmony_ci if (!cq->ctrl) { 418c2ecf20Sopenharmony_ci printk(KERN_ERR "Failed to hook CQ[%d] resource\n", index); 428c2ecf20Sopenharmony_ci return -EINVAL; 438c2ecf20Sopenharmony_ci } 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size); 468c2ecf20Sopenharmony_ci if (err) 478c2ecf20Sopenharmony_ci return err; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci return 0; 508c2ecf20Sopenharmony_ci} 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_civoid vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable, 538c2ecf20Sopenharmony_ci unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail, 548c2ecf20Sopenharmony_ci unsigned int cq_tail_color, unsigned int interrupt_enable, 558c2ecf20Sopenharmony_ci unsigned int cq_entry_enable, unsigned int cq_message_enable, 568c2ecf20Sopenharmony_ci unsigned int interrupt_offset, u64 cq_message_addr) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci u64 paddr; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET; 618c2ecf20Sopenharmony_ci writeq(paddr, &cq->ctrl->ring_base); 628c2ecf20Sopenharmony_ci iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size); 638c2ecf20Sopenharmony_ci iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable); 648c2ecf20Sopenharmony_ci iowrite32(color_enable, &cq->ctrl->color_enable); 658c2ecf20Sopenharmony_ci iowrite32(cq_head, &cq->ctrl->cq_head); 668c2ecf20Sopenharmony_ci iowrite32(cq_tail, &cq->ctrl->cq_tail); 678c2ecf20Sopenharmony_ci iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color); 688c2ecf20Sopenharmony_ci iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable); 698c2ecf20Sopenharmony_ci iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable); 708c2ecf20Sopenharmony_ci iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable); 718c2ecf20Sopenharmony_ci iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset); 728c2ecf20Sopenharmony_ci writeq(cq_message_addr, &cq->ctrl->cq_message_addr); 738c2ecf20Sopenharmony_ci} 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_civoid vnic_cq_clean(struct vnic_cq *cq) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci cq->to_clean = 0; 788c2ecf20Sopenharmony_ci cq->last_color = 0; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci iowrite32(0, &cq->ctrl->cq_head); 818c2ecf20Sopenharmony_ci iowrite32(0, &cq->ctrl->cq_tail); 828c2ecf20Sopenharmony_ci iowrite32(1, &cq->ctrl->cq_tail_color); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci vnic_dev_clear_desc_ring(&cq->ring); 858c2ecf20Sopenharmony_ci} 86