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>
286 lines
7.6 KiB
C
286 lines
7.6 KiB
C
/*
|
|
* WUSB Wire Adapter: Control/Data Streaming Interface (WUSB[8])
|
|
* MMC (Microscheduled Management Command) handling
|
|
*
|
|
* Copyright (C) 2005-2006 Intel Corporation
|
|
* Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License version
|
|
* 2 as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301, USA.
|
|
*
|
|
*
|
|
* WUIEs and MMC IEs...well, they are almost the same at the end. MMC
|
|
* IEs are Wireless USB IEs that go into the MMC period...[what is
|
|
* that? look in Design-overview.txt].
|
|
*
|
|
*
|
|
* This is a simple subsystem to keep track of which IEs are being
|
|
* sent by the host in the MMC period.
|
|
*
|
|
* For each WUIE we ask to send, we keep it in an array, so we can
|
|
* request its removal later, or replace the content. They are tracked
|
|
* by pointer, so be sure to use the same pointer if you want to
|
|
* remove it or update the contents.
|
|
*
|
|
* FIXME:
|
|
* - add timers that autoremove intervalled IEs?
|
|
*/
|
|
#include <linux/usb/wusb.h>
|
|
#include <linux/slab.h>
|
|
#include "wusbhc.h"
|
|
|
|
/* Initialize the MMCIEs handling mechanism */
|
|
int wusbhc_mmcie_create(struct wusbhc *wusbhc)
|
|
{
|
|
u8 mmcies = wusbhc->mmcies_max;
|
|
wusbhc->mmcie = kcalloc(mmcies, sizeof(wusbhc->mmcie[0]), GFP_KERNEL);
|
|
if (wusbhc->mmcie == NULL)
|
|
return -ENOMEM;
|
|
mutex_init(&wusbhc->mmcie_mutex);
|
|
return 0;
|
|
}
|
|
|
|
/* Release resources used by the MMCIEs handling mechanism */
|
|
void wusbhc_mmcie_destroy(struct wusbhc *wusbhc)
|
|
{
|
|
kfree(wusbhc->mmcie);
|
|
}
|
|
|
|
/*
|
|
* Add or replace an MMC Wireless USB IE.
|
|
*
|
|
* @interval: See WUSB1.0[8.5.3.1]
|
|
* @repeat_cnt: See WUSB1.0[8.5.3.1]
|
|
* @handle: See WUSB1.0[8.5.3.1]
|
|
* @wuie: Pointer to the header of the WUSB IE data to add.
|
|
* MUST BE allocated in a kmalloc buffer (no stack or
|
|
* vmalloc).
|
|
* THE CALLER ALWAYS OWNS THE POINTER (we don't free it
|
|
* on remove, we just forget about it).
|
|
* @returns: 0 if ok, < 0 errno code on error.
|
|
*
|
|
* Goes over the *whole* @wusbhc->mmcie array looking for (a) the
|
|
* first free spot and (b) if @wuie is already in the array (aka:
|
|
* transmitted in the MMCs) the spot were it is.
|
|
*
|
|
* If present, we "overwrite it" (update).
|
|
*
|
|
*
|
|
* NOTE: Need special ordering rules -- see below WUSB1.0 Table 7-38.
|
|
* The host uses the handle as the 'sort' index. We
|
|
* allocate the last one always for the WUIE_ID_HOST_INFO, and
|
|
* the rest, first come first serve in inverse order.
|
|
*
|
|
* Host software must make sure that it adds the other IEs in
|
|
* the right order... the host hardware is responsible for
|
|
* placing the WCTA IEs in the right place with the other IEs
|
|
* set by host software.
|
|
*
|
|
* NOTE: we can access wusbhc->wa_descr without locking because it is
|
|
* read only.
|
|
*/
|
|
int wusbhc_mmcie_set(struct wusbhc *wusbhc, u8 interval, u8 repeat_cnt,
|
|
struct wuie_hdr *wuie)
|
|
{
|
|
int result = -ENOBUFS;
|
|
unsigned handle, itr;
|
|
|
|
/* Search a handle, taking into account the ordering */
|
|
mutex_lock(&wusbhc->mmcie_mutex);
|
|
switch (wuie->bIEIdentifier) {
|
|
case WUIE_ID_HOST_INFO:
|
|
/* Always last */
|
|
handle = wusbhc->mmcies_max - 1;
|
|
break;
|
|
case WUIE_ID_ISOCH_DISCARD:
|
|
dev_err(wusbhc->dev, "Special ordering case for WUIE ID 0x%x "
|
|
"unimplemented\n", wuie->bIEIdentifier);
|
|
result = -ENOSYS;
|
|
goto error_unlock;
|
|
default:
|
|
/* search for it or find the last empty slot */
|
|
handle = ~0;
|
|
for (itr = 0; itr < wusbhc->mmcies_max - 1; itr++) {
|
|
if (wusbhc->mmcie[itr] == wuie) {
|
|
handle = itr;
|
|
break;
|
|
}
|
|
if (wusbhc->mmcie[itr] == NULL)
|
|
handle = itr;
|
|
}
|
|
if (handle == ~0)
|
|
goto error_unlock;
|
|
}
|
|
result = (wusbhc->mmcie_add)(wusbhc, interval, repeat_cnt, handle,
|
|
wuie);
|
|
if (result >= 0)
|
|
wusbhc->mmcie[handle] = wuie;
|
|
error_unlock:
|
|
mutex_unlock(&wusbhc->mmcie_mutex);
|
|
return result;
|
|
}
|
|
EXPORT_SYMBOL_GPL(wusbhc_mmcie_set);
|
|
|
|
/*
|
|
* Remove an MMC IE previously added with wusbhc_mmcie_set()
|
|
*
|
|
* @wuie Pointer used to add the WUIE
|
|
*/
|
|
void wusbhc_mmcie_rm(struct wusbhc *wusbhc, struct wuie_hdr *wuie)
|
|
{
|
|
int result;
|
|
unsigned handle, itr;
|
|
|
|
mutex_lock(&wusbhc->mmcie_mutex);
|
|
for (itr = 0; itr < wusbhc->mmcies_max; itr++) {
|
|
if (wusbhc->mmcie[itr] == wuie) {
|
|
handle = itr;
|
|
goto found;
|
|
}
|
|
}
|
|
mutex_unlock(&wusbhc->mmcie_mutex);
|
|
return;
|
|
|
|
found:
|
|
result = (wusbhc->mmcie_rm)(wusbhc, handle);
|
|
if (result == 0)
|
|
wusbhc->mmcie[itr] = NULL;
|
|
mutex_unlock(&wusbhc->mmcie_mutex);
|
|
}
|
|
EXPORT_SYMBOL_GPL(wusbhc_mmcie_rm);
|
|
|
|
static int wusbhc_mmc_start(struct wusbhc *wusbhc)
|
|
{
|
|
int ret;
|
|
|
|
mutex_lock(&wusbhc->mutex);
|
|
ret = wusbhc->start(wusbhc);
|
|
if (ret >= 0)
|
|
wusbhc->active = 1;
|
|
mutex_unlock(&wusbhc->mutex);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static void wusbhc_mmc_stop(struct wusbhc *wusbhc)
|
|
{
|
|
mutex_lock(&wusbhc->mutex);
|
|
wusbhc->active = 0;
|
|
wusbhc->stop(wusbhc, WUSB_CHANNEL_STOP_DELAY_MS);
|
|
mutex_unlock(&wusbhc->mutex);
|
|
}
|
|
|
|
/*
|
|
* wusbhc_start - start transmitting MMCs and accepting connections
|
|
* @wusbhc: the HC to start
|
|
*
|
|
* Establishes a cluster reservation, enables device connections, and
|
|
* starts MMCs with appropriate DNTS parameters.
|
|
*/
|
|
int wusbhc_start(struct wusbhc *wusbhc)
|
|
{
|
|
int result;
|
|
struct device *dev = wusbhc->dev;
|
|
|
|
WARN_ON(wusbhc->wuie_host_info != NULL);
|
|
|
|
result = wusbhc_rsv_establish(wusbhc);
|
|
if (result < 0) {
|
|
dev_err(dev, "cannot establish cluster reservation: %d\n",
|
|
result);
|
|
goto error_rsv_establish;
|
|
}
|
|
|
|
result = wusbhc_devconnect_start(wusbhc);
|
|
if (result < 0) {
|
|
dev_err(dev, "error enabling device connections: %d\n", result);
|
|
goto error_devconnect_start;
|
|
}
|
|
|
|
result = wusbhc_sec_start(wusbhc);
|
|
if (result < 0) {
|
|
dev_err(dev, "error starting security in the HC: %d\n", result);
|
|
goto error_sec_start;
|
|
}
|
|
/* FIXME: the choice of the DNTS parameters is somewhat
|
|
* arbitrary */
|
|
result = wusbhc->set_num_dnts(wusbhc, 0, 15);
|
|
if (result < 0) {
|
|
dev_err(dev, "Cannot set DNTS parameters: %d\n", result);
|
|
goto error_set_num_dnts;
|
|
}
|
|
result = wusbhc_mmc_start(wusbhc);
|
|
if (result < 0) {
|
|
dev_err(dev, "error starting wusbch: %d\n", result);
|
|
goto error_wusbhc_start;
|
|
}
|
|
|
|
return 0;
|
|
|
|
error_wusbhc_start:
|
|
wusbhc_sec_stop(wusbhc);
|
|
error_set_num_dnts:
|
|
error_sec_start:
|
|
wusbhc_devconnect_stop(wusbhc);
|
|
error_devconnect_start:
|
|
wusbhc_rsv_terminate(wusbhc);
|
|
error_rsv_establish:
|
|
return result;
|
|
}
|
|
|
|
/*
|
|
* wusbhc_stop - stop transmitting MMCs
|
|
* @wusbhc: the HC to stop
|
|
*
|
|
* Stops the WUSB channel and removes the cluster reservation.
|
|
*/
|
|
void wusbhc_stop(struct wusbhc *wusbhc)
|
|
{
|
|
wusbhc_mmc_stop(wusbhc);
|
|
wusbhc_sec_stop(wusbhc);
|
|
wusbhc_devconnect_stop(wusbhc);
|
|
wusbhc_rsv_terminate(wusbhc);
|
|
}
|
|
|
|
/*
|
|
* Set/reset/update a new CHID
|
|
*
|
|
* Depending on the previous state of the MMCs, start, stop or change
|
|
* the sent MMC. This effectively switches the host controller on and
|
|
* off (radio wise).
|
|
*/
|
|
int wusbhc_chid_set(struct wusbhc *wusbhc, const struct wusb_ckhdid *chid)
|
|
{
|
|
int result = 0;
|
|
|
|
if (memcmp(chid, &wusb_ckhdid_zero, sizeof(*chid)) == 0)
|
|
chid = NULL;
|
|
|
|
mutex_lock(&wusbhc->mutex);
|
|
if (chid) {
|
|
if (wusbhc->active) {
|
|
mutex_unlock(&wusbhc->mutex);
|
|
return -EBUSY;
|
|
}
|
|
wusbhc->chid = *chid;
|
|
}
|
|
mutex_unlock(&wusbhc->mutex);
|
|
|
|
if (chid)
|
|
result = uwb_radio_start(&wusbhc->pal);
|
|
else
|
|
uwb_radio_stop(&wusbhc->pal);
|
|
return result;
|
|
}
|
|
EXPORT_SYMBOL_GPL(wusbhc_chid_set);
|