mirror of
https://github.com/torvalds/linux.git
synced 2024-11-13 23:51:39 +00: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>
184 lines
4.3 KiB
C
184 lines
4.3 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_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++) {
|
|
wq->bufs[i] = kzalloc(VNIC_WQ_BUF_BLK_SZ, GFP_ATOMIC);
|
|
if (!wq->bufs[i]) {
|
|
printk(KERN_ERR "Failed to alloc wq_bufs\n");
|
|
return -ENOMEM;
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < blks; i++) {
|
|
buf = wq->bufs[i];
|
|
for (j = 0; j < VNIC_WQ_BUF_BLK_ENTRIES; j++) {
|
|
buf->index = i * VNIC_WQ_BUF_BLK_ENTRIES + j;
|
|
buf->desc = (u8 *)wq->ring.descs +
|
|
wq->ring.desc_size * buf->index;
|
|
if (buf->index + 1 == count) {
|
|
buf->next = wq->bufs[0];
|
|
break;
|
|
} else if (j + 1 == VNIC_WQ_BUF_BLK_ENTRIES) {
|
|
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++) {
|
|
kfree(wq->bufs[i]);
|
|
wq->bufs[i] = NULL;
|
|
}
|
|
|
|
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) {
|
|
printk(KERN_ERR "Failed to hook WQ[%d] resource\n", index);
|
|
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;
|
|
}
|
|
|
|
void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index,
|
|
unsigned int error_interrupt_enable,
|
|
unsigned int error_interrupt_offset)
|
|
{
|
|
u64 paddr;
|
|
|
|
paddr = (u64)wq->ring.base_addr | VNIC_PADDR_TARGET;
|
|
writeq(paddr, &wq->ctrl->ring_base);
|
|
iowrite32(wq->ring.desc_count, &wq->ctrl->ring_size);
|
|
iowrite32(0, &wq->ctrl->fetch_index);
|
|
iowrite32(0, &wq->ctrl->posted_index);
|
|
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);
|
|
}
|
|
|
|
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 */
|
|
for (wait = 0; wait < 100; wait++) {
|
|
if (!(ioread32(&wq->ctrl->running)))
|
|
return 0;
|
|
udelay(1);
|
|
}
|
|
|
|
printk(KERN_ERR "Failed to disable WQ[%d]\n", wq->index);
|
|
|
|
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;
|
|
|
|
BUG_ON(ioread32(&wq->ctrl->enable));
|
|
|
|
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);
|
|
}
|