Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
0004  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
0005  */
0006 
0007 #include <linux/errno.h>
0008 #include <linux/types.h>
0009 #include <linux/pci.h>
0010 #include <linux/delay.h>
0011 #include "vnic_wq_copy.h"
0012 
0013 void vnic_wq_copy_enable(struct vnic_wq_copy *wq)
0014 {
0015     iowrite32(1, &wq->ctrl->enable);
0016 }
0017 
0018 int vnic_wq_copy_disable(struct vnic_wq_copy *wq)
0019 {
0020     unsigned int wait;
0021 
0022     iowrite32(0, &wq->ctrl->enable);
0023 
0024     /* Wait for HW to ACK disable request */
0025     for (wait = 0; wait < 100; wait++) {
0026         if (!(ioread32(&wq->ctrl->running)))
0027             return 0;
0028         udelay(1);
0029     }
0030 
0031     printk(KERN_ERR "Failed to disable Copy WQ[%d],"
0032            " fetch index=%d, posted_index=%d\n",
0033            wq->index, ioread32(&wq->ctrl->fetch_index),
0034            ioread32(&wq->ctrl->posted_index));
0035 
0036     return -ENODEV;
0037 }
0038 
0039 void vnic_wq_copy_clean(struct vnic_wq_copy *wq,
0040     void (*q_clean)(struct vnic_wq_copy *wq,
0041     struct fcpio_host_req *wq_desc))
0042 {
0043     BUG_ON(ioread32(&wq->ctrl->enable));
0044 
0045     if (vnic_wq_copy_desc_in_use(wq))
0046         vnic_wq_copy_service(wq, -1, q_clean);
0047 
0048     wq->to_use_index = wq->to_clean_index = 0;
0049 
0050     iowrite32(0, &wq->ctrl->fetch_index);
0051     iowrite32(0, &wq->ctrl->posted_index);
0052     iowrite32(0, &wq->ctrl->error_status);
0053 
0054     vnic_dev_clear_desc_ring(&wq->ring);
0055 }
0056 
0057 void vnic_wq_copy_free(struct vnic_wq_copy *wq)
0058 {
0059     struct vnic_dev *vdev;
0060 
0061     vdev = wq->vdev;
0062     vnic_dev_free_desc_ring(vdev, &wq->ring);
0063     wq->ctrl = NULL;
0064 }
0065 
0066 int vnic_wq_copy_alloc(struct vnic_dev *vdev, struct vnic_wq_copy *wq,
0067                unsigned int index, unsigned int desc_count,
0068                unsigned int desc_size)
0069 {
0070     wq->index = index;
0071     wq->vdev = vdev;
0072     wq->to_use_index = wq->to_clean_index = 0;
0073     wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index);
0074     if (!wq->ctrl) {
0075         printk(KERN_ERR "Failed to hook COPY WQ[%d] resource\n", index);
0076         return -EINVAL;
0077     }
0078 
0079     vnic_wq_copy_disable(wq);
0080 
0081     return vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size);
0082 }
0083 
0084 void vnic_wq_copy_init(struct vnic_wq_copy *wq, unsigned int cq_index,
0085     unsigned int error_interrupt_enable,
0086     unsigned int error_interrupt_offset)
0087 {
0088     u64 paddr;
0089 
0090     paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET;
0091     writeq(paddr, &wq->ctrl->ring_base);
0092     iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size);
0093     iowrite32(0, &wq->ctrl->fetch_index);
0094     iowrite32(0, &wq->ctrl->posted_index);
0095     iowrite32(cq_index, &wq->ctrl->cq_index);
0096     iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable);
0097     iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset);
0098 }