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