mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-27 13:05:03 +08:00
5a0e3ad6af
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>
198 lines
4.7 KiB
C
198 lines
4.7 KiB
C
/*
|
|
* Copyright 2008 Cisco Systems, Inc. All rights reserved.
|
|
* 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/errno.h>
|
|
#include <linux/types.h>
|
|
#include <linux/pci.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/slab.h>
|
|
#include "vnic_dev.h"
|
|
#include "vnic_rq.h"
|
|
|
|
static int vnic_rq_alloc_bufs(struct vnic_rq *rq)
|
|
{
|
|
struct vnic_rq_buf *buf;
|
|
struct vnic_dev *vdev;
|
|
unsigned int i, j, count = rq->ring.desc_count;
|
|
unsigned int blks = VNIC_RQ_BUF_BLKS_NEEDED(count);
|
|
|
|
vdev = rq->vdev;
|
|
|
|
for (i = 0; i < blks; i++) {
|
|
rq->bufs[i] = kzalloc(VNIC_RQ_BUF_BLK_SZ, GFP_ATOMIC);
|
|
if (!rq->bufs[i]) {
|
|
printk(KERN_ERR "Failed to alloc rq_bufs\n");
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < blks; i++) {
|
|
buf = rq->bufs[i];
|
|
for (j = 0; j < VNIC_RQ_BUF_BLK_ENTRIES; j++) {
|
|
buf->index = i * VNIC_RQ_BUF_BLK_ENTRIES + j;
|
|
buf->desc = (u8 *)rq->ring.descs +
|
|
rq->ring.desc_size * buf->index;
|
|
if (buf->index + 1 == count) {
|
|
buf->next = rq->bufs[0];
|
|
break;
|
|
} else if (j + 1 == VNIC_RQ_BUF_BLK_ENTRIES) {
|
|
buf->next = rq->bufs[i + 1];
|
|
} else {
|
|
buf->next = buf + 1;
|
|
buf++;
|
|
}
|
|
}
|
|
}
|
|
|
|
rq->to_use = rq->to_clean = rq->bufs[0];
|
|
rq->buf_index = 0;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void vnic_rq_free(struct vnic_rq *rq)
|
|
{
|
|
struct vnic_dev *vdev;
|
|
unsigned int i;
|
|
|
|
vdev = rq->vdev;
|
|
|
|
vnic_dev_free_desc_ring(vdev, &rq->ring);
|
|
|
|
for (i = 0; i < VNIC_RQ_BUF_BLKS_MAX; i++) {
|
|
kfree(rq->bufs[i]);
|
|
rq->bufs[i] = NULL;
|
|
}
|
|
|
|
rq->ctrl = NULL;
|
|
}
|
|
|
|
int vnic_rq_alloc(struct vnic_dev *vdev, struct vnic_rq *rq, unsigned int index,
|
|
unsigned int desc_count, unsigned int desc_size)
|
|
{
|
|
int err;
|
|
|
|
rq->index = index;
|
|
rq->vdev = vdev;
|
|
|
|
rq->ctrl = vnic_dev_get_res(vdev, RES_TYPE_RQ, index);
|
|
if (!rq->ctrl) {
|
|
printk(KERN_ERR "Failed to hook RQ[%d] resource\n", index);
|
|
return -EINVAL;
|
|
}
|
|
|
|
vnic_rq_disable(rq);
|
|
|
|
err = vnic_dev_alloc_desc_ring(vdev, &rq->ring, desc_count, desc_size);
|
|
if (err)
|
|
return err;
|
|
|
|
err = vnic_rq_alloc_bufs(rq);
|
|
if (err) {
|
|
vnic_rq_free(rq);
|
|
return err;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void vnic_rq_init(struct vnic_rq *rq, unsigned int cq_index,
|
|
unsigned int error_interrupt_enable,
|
|
unsigned int error_interrupt_offset)
|
|
{
|
|
u64 paddr;
|
|
u32 fetch_index;
|
|
|
|
paddr = (u64)rq->ring.base_addr | VNIC_PADDR_TARGET;
|
|
writeq(paddr, &rq->ctrl->ring_base);
|
|
iowrite32(rq->ring.desc_count, &rq->ctrl->ring_size);
|
|
iowrite32(cq_index, &rq->ctrl->cq_index);
|
|
iowrite32(error_interrupt_enable, &rq->ctrl->error_interrupt_enable);
|
|
iowrite32(error_interrupt_offset, &rq->ctrl->error_interrupt_offset);
|
|
iowrite32(0, &rq->ctrl->dropped_packet_count);
|
|
iowrite32(0, &rq->ctrl->error_status);
|
|
|
|
/* Use current fetch_index as the ring starting point */
|
|
fetch_index = ioread32(&rq->ctrl->fetch_index);
|
|
rq->to_use = rq->to_clean =
|
|
&rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES]
|
|
[fetch_index % VNIC_RQ_BUF_BLK_ENTRIES];
|
|
iowrite32(fetch_index, &rq->ctrl->posted_index);
|
|
|
|
rq->buf_index = 0;
|
|
}
|
|
|
|
unsigned int vnic_rq_error_status(struct vnic_rq *rq)
|
|
{
|
|
return ioread32(&rq->ctrl->error_status);
|
|
}
|
|
|
|
void vnic_rq_enable(struct vnic_rq *rq)
|
|
{
|
|
iowrite32(1, &rq->ctrl->enable);
|
|
}
|
|
|
|
int vnic_rq_disable(struct vnic_rq *rq)
|
|
{
|
|
unsigned int wait;
|
|
|
|
iowrite32(0, &rq->ctrl->enable);
|
|
|
|
/* Wait for HW to ACK disable request */
|
|
for (wait = 0; wait < 100; wait++) {
|
|
if (!(ioread32(&rq->ctrl->running)))
|
|
return 0;
|
|
udelay(1);
|
|
}
|
|
|
|
printk(KERN_ERR "Failed to disable RQ[%d]\n", rq->index);
|
|
|
|
return -ETIMEDOUT;
|
|
}
|
|
|
|
void vnic_rq_clean(struct vnic_rq *rq,
|
|
void (*buf_clean)(struct vnic_rq *rq, struct vnic_rq_buf *buf))
|
|
{
|
|
struct vnic_rq_buf *buf;
|
|
u32 fetch_index;
|
|
|
|
BUG_ON(ioread32(&rq->ctrl->enable));
|
|
|
|
buf = rq->to_clean;
|
|
|
|
while (vnic_rq_desc_used(rq) > 0) {
|
|
|
|
(*buf_clean)(rq, buf);
|
|
|
|
buf = rq->to_clean = buf->next;
|
|
rq->ring.desc_avail++;
|
|
}
|
|
|
|
/* Use current fetch_index as the ring starting point */
|
|
fetch_index = ioread32(&rq->ctrl->fetch_index);
|
|
rq->to_use = rq->to_clean =
|
|
&rq->bufs[fetch_index / VNIC_RQ_BUF_BLK_ENTRIES]
|
|
[fetch_index % VNIC_RQ_BUF_BLK_ENTRIES];
|
|
iowrite32(fetch_index, &rq->ctrl->posted_index);
|
|
|
|
rq->buf_index = 0;
|
|
|
|
vnic_dev_clear_desc_ring(&rq->ring);
|
|
}
|
|
|