2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 #include <linux/errno.h>
20 #include <linux/types.h>
21 #include <linux/pci.h>
22 #include <linux/delay.h>
23 #include "vnic_wq_copy.h"
25 void vnic_wq_copy_enable(struct vnic_wq_copy
*wq
)
27 iowrite32(1, &wq
->ctrl
->enable
);
30 int vnic_wq_copy_disable(struct vnic_wq_copy
*wq
)
34 iowrite32(0, &wq
->ctrl
->enable
);
36 /* Wait for HW to ACK disable request */
37 for (wait
= 0; wait
< 100; wait
++) {
38 if (!(ioread32(&wq
->ctrl
->running
)))
43 printk(KERN_ERR
"Failed to disable Copy WQ[%d],"
44 " fetch index=%d, posted_index=%d\n",
45 wq
->index
, ioread32(&wq
->ctrl
->fetch_index
),
46 ioread32(&wq
->ctrl
->posted_index
));
51 void vnic_wq_copy_clean(struct vnic_wq_copy
*wq
,
52 void (*q_clean
)(struct vnic_wq_copy
*wq
,
53 struct fcpio_host_req
*wq_desc
))
55 BUG_ON(ioread32(&wq
->ctrl
->enable
));
57 if (vnic_wq_copy_desc_in_use(wq
))
58 vnic_wq_copy_service(wq
, -1, q_clean
);
60 wq
->to_use_index
= wq
->to_clean_index
= 0;
62 iowrite32(0, &wq
->ctrl
->fetch_index
);
63 iowrite32(0, &wq
->ctrl
->posted_index
);
64 iowrite32(0, &wq
->ctrl
->error_status
);
66 vnic_dev_clear_desc_ring(&wq
->ring
);
69 void vnic_wq_copy_free(struct vnic_wq_copy
*wq
)
71 struct vnic_dev
*vdev
;
74 vnic_dev_free_desc_ring(vdev
, &wq
->ring
);
78 int vnic_wq_copy_alloc(struct vnic_dev
*vdev
, struct vnic_wq_copy
*wq
,
79 unsigned int index
, unsigned int desc_count
,
80 unsigned int desc_size
)
84 wq
->to_use_index
= wq
->to_clean_index
= 0;
85 wq
->ctrl
= vnic_dev_get_res(vdev
, RES_TYPE_WQ
, index
);
87 printk(KERN_ERR
"Failed to hook COPY WQ[%d] resource\n", index
);
91 vnic_wq_copy_disable(wq
);
93 return vnic_dev_alloc_desc_ring(vdev
, &wq
->ring
, desc_count
, desc_size
);
96 void vnic_wq_copy_init(struct vnic_wq_copy
*wq
, unsigned int cq_index
,
97 unsigned int error_interrupt_enable
,
98 unsigned int error_interrupt_offset
)
102 paddr
= (u64
)wq
->ring
.base_addr
| VNIC_PADDR_TARGET
;
103 writeq(paddr
, &wq
->ctrl
->ring_base
);
104 iowrite32(wq
->ring
.desc_count
, &wq
->ctrl
->ring_size
);
105 iowrite32(0, &wq
->ctrl
->fetch_index
);
106 iowrite32(0, &wq
->ctrl
->posted_index
);
107 iowrite32(cq_index
, &wq
->ctrl
->cq_index
);
108 iowrite32(error_interrupt_enable
, &wq
->ctrl
->error_interrupt_enable
);
109 iowrite32(error_interrupt_offset
, &wq
->ctrl
->error_interrupt_offset
);