2008-09-15 20:17:11 +04:00
|
|
|
/*
|
2010-06-24 14:52:26 +04:00
|
|
|
* Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
|
2008-09-15 20:17:11 +04:00
|
|
|
* Copyright 2007 Nuova Systems, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you may redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/delay.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 11:04:11 +03:00
|
|
|
#include <linux/slab.h>
|
2008-09-15 20:17:11 +04:00
|
|
|
|
|
|
|
#include "vnic_dev.h"
|
|
|
|
#include "vnic_wq.h"
|
|
|
|
|
|
|
|
static int vnic_wq_alloc_bufs(struct vnic_wq *wq)
|
|
|
|
{
|
|
|
|
struct vnic_wq_buf *buf;
|
|
|
|
struct vnic_dev *vdev;
|
|
|
|
unsigned int i, j, count = wq->ring.desc_count;
|
|
|
|
unsigned int blks = VNIC_WQ_BUF_BLKS_NEEDED(count);
|
|
|
|
|
|
|
|
vdev = wq->vdev;
|
|
|
|
|
|
|
|
for (i = 0; i < blks; i++) {
|
2010-06-24 14:51:51 +04:00
|
|
|
wq->bufs[i] = kzalloc(VNIC_WQ_BUF_BLK_SZ(count), GFP_ATOMIC);
|
2008-09-15 20:17:11 +04:00
|
|
|
if (!wq->bufs[i]) {
|
2010-06-24 14:50:56 +04:00
|
|
|
pr_err("Failed to alloc wq_bufs\n");
|
2008-09-15 20:17:11 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < blks; i++) {
|
|
|
|
buf = wq->bufs[i];
|
2010-06-24 14:51:51 +04:00
|
|
|
for (j = 0; j < VNIC_WQ_BUF_BLK_ENTRIES(count); j++) {
|
|
|
|
buf->index = i * VNIC_WQ_BUF_BLK_ENTRIES(count) + j;
|
2008-09-15 20:17:11 +04:00
|
|
|
buf->desc = (u8 *)wq->ring.descs +
|
|
|
|
wq->ring.desc_size * buf->index;
|
|
|
|
if (buf->index + 1 == count) {
|
|
|
|
buf->next = wq->bufs[0];
|
|
|
|
break;
|
2010-06-24 14:51:51 +04:00
|
|
|
} else if (j + 1 == VNIC_WQ_BUF_BLK_ENTRIES(count)) {
|
2008-09-15 20:17:11 +04:00
|
|
|
buf->next = wq->bufs[i + 1];
|
|
|
|
} else {
|
|
|
|
buf->next = buf + 1;
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wq->to_use = wq->to_clean = wq->bufs[0];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vnic_wq_free(struct vnic_wq *wq)
|
|
|
|
{
|
|
|
|
struct vnic_dev *vdev;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
vdev = wq->vdev;
|
|
|
|
|
|
|
|
vnic_dev_free_desc_ring(vdev, &wq->ring);
|
|
|
|
|
|
|
|
for (i = 0; i < VNIC_WQ_BUF_BLKS_MAX; i++) {
|
2010-08-10 22:55:20 +04:00
|
|
|
if (wq->bufs[i]) {
|
|
|
|
kfree(wq->bufs[i]);
|
|
|
|
wq->bufs[i] = NULL;
|
|
|
|
}
|
2008-09-15 20:17:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
wq->ctrl = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index,
|
|
|
|
unsigned int desc_count, unsigned int desc_size)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
wq->index = index;
|
|
|
|
wq->vdev = vdev;
|
|
|
|
|
|
|
|
wq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_WQ, index);
|
|
|
|
if (!wq->ctrl) {
|
2010-06-24 14:50:56 +04:00
|
|
|
pr_err("Failed to hook WQ[%d] resource\n", index);
|
2008-09-15 20:17:11 +04:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
vnic_wq_disable(wq);
|
|
|
|
|
|
|
|
err = vnic_dev_alloc_desc_ring(vdev, &wq->ring, desc_count, desc_size);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = vnic_wq_alloc_bufs(wq);
|
|
|
|
if (err) {
|
|
|
|
vnic_wq_free(wq);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-30 17:35:45 +04:00
|
|
|
static void vnic_wq_init_start(struct vnic_wq *wq, unsigned int cq_index,
|
2009-09-03 21:02:45 +04:00
|
|
|
unsigned int fetch_index, unsigned int posted_index,
|
2008-09-15 20:17:11 +04:00
|
|
|
unsigned int error_interrupt_enable,
|
|
|
|
unsigned int error_interrupt_offset)
|
|
|
|
{
|
|
|
|
u64 paddr;
|
2010-06-24 14:51:51 +04:00
|
|
|
unsigned int count = wq->ring.desc_count;
|
2008-09-15 20:17:11 +04:00
|
|
|
|
|
|
|
paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET;
|
|
|
|
writeq(paddr, &wq->ctrl->ring_base);
|
2010-06-24 14:51:51 +04:00
|
|
|
iowrite32(count, &wq->ctrl->ring_size);
|
2009-09-03 21:02:45 +04:00
|
|
|
iowrite32(fetch_index, &wq->ctrl->fetch_index);
|
|
|
|
iowrite32(posted_index, &wq->ctrl->posted_index);
|
2008-09-15 20:17:11 +04:00
|
|
|
iowrite32(cq_index, &wq->ctrl->cq_index);
|
|
|
|
iowrite32(error_interrupt_enable, &wq->ctrl->error_interrupt_enable);
|
|
|
|
iowrite32(error_interrupt_offset, &wq->ctrl->error_interrupt_offset);
|
|
|
|
iowrite32(0, &wq->ctrl->error_status);
|
2009-09-03 21:02:45 +04:00
|
|
|
|
|
|
|
wq->to_use = wq->to_clean =
|
2010-06-24 14:51:51 +04:00
|
|
|
&wq->bufs[fetch_index / VNIC_WQ_BUF_BLK_ENTRIES(count)]
|
|
|
|
[fetch_index % VNIC_WQ_BUF_BLK_ENTRIES(count)];
|
2009-09-03 21:02:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
|
|
|
|
unsigned int error_interrupt_enable,
|
|
|
|
unsigned int error_interrupt_offset)
|
|
|
|
{
|
|
|
|
vnic_wq_init_start(wq, cq_index, 0, 0,
|
|
|
|
error_interrupt_enable,
|
|
|
|
error_interrupt_offset);
|
2008-09-15 20:17:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int vnic_wq_error_status(struct vnic_wq *wq)
|
|
|
|
{
|
|
|
|
return ioread32(&wq->ctrl->error_status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void vnic_wq_enable(struct vnic_wq *wq)
|
|
|
|
{
|
|
|
|
iowrite32(1, &wq->ctrl->enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
int vnic_wq_disable(struct vnic_wq *wq)
|
|
|
|
{
|
|
|
|
unsigned int wait;
|
|
|
|
|
|
|
|
iowrite32(0, &wq->ctrl->enable);
|
|
|
|
|
|
|
|
/* Wait for HW to ACK disable request */
|
2010-03-18 19:19:49 +03:00
|
|
|
for (wait = 0; wait < 1000; wait++) {
|
2008-09-15 20:17:11 +04:00
|
|
|
if (!(ioread32(&wq->ctrl->running)))
|
|
|
|
return 0;
|
2010-03-18 19:19:49 +03:00
|
|
|
udelay(10);
|
2008-09-15 20:17:11 +04:00
|
|
|
}
|
|
|
|
|
2010-06-24 14:50:56 +04:00
|
|
|
pr_err("Failed to disable WQ[%d]\n", wq->index);
|
2008-09-15 20:17:11 +04:00
|
|
|
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void vnic_wq_clean(struct vnic_wq *wq,
|
|
|
|
void (*buf_clean)(struct vnic_wq *wq, struct vnic_wq_buf *buf))
|
|
|
|
{
|
|
|
|
struct vnic_wq_buf *buf;
|
|
|
|
|
|
|
|
buf = wq->to_clean;
|
|
|
|
|
|
|
|
while (vnic_wq_desc_used(wq) > 0) {
|
|
|
|
|
|
|
|
(*buf_clean)(wq, buf);
|
|
|
|
|
|
|
|
buf = wq->to_clean = buf->next;
|
|
|
|
wq->ring.desc_avail++;
|
|
|
|
}
|
|
|
|
|
|
|
|
wq->to_use = wq->to_clean = wq->bufs[0];
|
|
|
|
|
|
|
|
iowrite32(0, &wq->ctrl->fetch_index);
|
|
|
|
iowrite32(0, &wq->ctrl->posted_index);
|
|
|
|
iowrite32(0, &wq->ctrl->error_status);
|
|
|
|
|
|
|
|
vnic_dev_clear_desc_ring(&wq->ring);
|
|
|
|
}
|