^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright 2008 Cisco Systems, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright 2007 Nuova Systems, Inc. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * This program is free software; you may redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * the Free Software Foundation; version 2 of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "vnic_dev.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "vnic_cq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void vnic_cq_free(struct vnic_cq *cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) vnic_dev_free_desc_ring(cq->vdev, &cq->ring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) cq->ctrl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int vnic_cq_alloc(struct vnic_dev *vdev, struct vnic_cq *cq, unsigned int index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int desc_count, unsigned int desc_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) cq->index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) cq->vdev = vdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) cq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_CQ, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) if (!cq->ctrl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) printk(KERN_ERR "Failed to hook CQ[%d] resource\n", index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) err = vnic_dev_alloc_desc_ring(vdev, &cq->ring, desc_count, desc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) void vnic_cq_init(struct vnic_cq *cq, unsigned int flow_control_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) unsigned int color_enable, unsigned int cq_head, unsigned int cq_tail,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) unsigned int cq_tail_color, unsigned int interrupt_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) unsigned int cq_entry_enable, unsigned int cq_message_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned int interrupt_offset, u64 cq_message_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u64 paddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) paddr = (u64)cq->ring.base_addr | VNIC_PADDR_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) writeq(paddr, &cq->ctrl->ring_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) iowrite32(cq->ring.desc_count, &cq->ctrl->ring_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) iowrite32(flow_control_enable, &cq->ctrl->flow_control_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) iowrite32(color_enable, &cq->ctrl->color_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) iowrite32(cq_head, &cq->ctrl->cq_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) iowrite32(cq_tail, &cq->ctrl->cq_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) iowrite32(cq_tail_color, &cq->ctrl->cq_tail_color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) iowrite32(interrupt_enable, &cq->ctrl->interrupt_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) iowrite32(cq_entry_enable, &cq->ctrl->cq_entry_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) iowrite32(cq_message_enable, &cq->ctrl->cq_message_enable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) iowrite32(interrupt_offset, &cq->ctrl->interrupt_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) writeq(cq_message_addr, &cq->ctrl->cq_message_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) void vnic_cq_clean(struct vnic_cq *cq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) cq->to_clean = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) cq->last_color = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) iowrite32(0, &cq->ctrl->cq_head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) iowrite32(0, &cq->ctrl->cq_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) iowrite32(1, &cq->ctrl->cq_tail_color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) vnic_dev_clear_desc_ring(&cq->ring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }