2 * Copyright 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Compatibility file for Linux wireless for kernels 2.6.27
11 #include <linux/compat.h>
13 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27))
15 #include <linux/pci.h>
16 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
17 #include <linux/mmc/sdio.h>
18 #include <linux/mmc/sdio_func.h>
19 #include <linux/mmc/card.h>
20 #include <linux/mmc/host.h>
23 /* rfkill notification chain */
24 #define RFKILL_STATE_CHANGED 0x0001 /* state of a normal rfkill
28 * e5899e1b7d73e67de758a32174a859cc2586c0b9 made pci_pme_capable() external,
29 * it was defined internally, some drivers want access to this information.
31 * Unfortunately the old kernels do not have ->pm_cap or ->pme_support so
32 * we have to call the PCI routines directly.
36 * pci_pme_capable - check the capability of PCI device to generate PME#
37 * @dev: PCI device to handle.
38 * @state: PCI state from which device will issue PME#.
40 * This is the backport code for older kernels for compat-wireless, we read stuff
41 * from the initialization stuff from pci_pm_init().
43 bool pci_pme_capable(struct pci_dev *dev, pci_power_t state)
47 u16 pme_support; /* as from the pci dev */
48 /* find PCI PM capability in list */
49 pm = pci_find_capability(dev, PCI_CAP_ID_PM);
53 if ((pmc & PCI_PM_CAP_VER_MASK) > 3) {
54 dev_err(&dev->dev, "unsupported PM cap regs version (%u)\n",
55 pmc & PCI_PM_CAP_VER_MASK);
59 pmc &= PCI_PM_CAP_PME_MASK;
64 pme_support = pmc >> PCI_PM_CAP_PME_SHIFT;
66 /* Check device's ability to generate PME# */
68 return !!(pme_support & (1 << state));
70 EXPORT_SYMBOL(pci_pme_capable);
72 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
74 * mmc_align_data_size - pads a transfer size to a more optimal value
75 * @card: the MMC card associated with the data transfer
76 * @sz: original transfer size
78 * Pads the original data size with a number of extra bytes in
79 * order to avoid controller bugs and/or performance hits
80 * (e.g. some controllers revert to PIO for certain sizes).
82 * Returns the improved size, which might be unmodified.
84 * Note that this function is only relevant when issuing a
85 * single scatter gather entry.
87 unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz)
90 * FIXME: We don't have a system for the controller to tell
91 * the core about its problems yet, so for now we just 32-bit
94 sz = ((sz + 3) / 4) * 4;
98 EXPORT_SYMBOL(mmc_align_data_size);
101 * Calculate the maximum byte mode transfer size
103 static inline unsigned int sdio_max_byte_size(struct sdio_func *func)
105 unsigned int mval = (unsigned int) min(func->card->host->max_seg_size,
106 func->card->host->max_blk_size);
107 mval = min(mval, func->max_blksize);
108 return min(mval, 512u); /* maximum size for byte mode */
112 * sdio_align_size - pads a transfer size to a more optimal value
113 * @func: SDIO function
114 * @sz: original transfer size
116 * Pads the original data size with a number of extra bytes in
117 * order to avoid controller bugs and/or performance hits
118 * (e.g. some controllers revert to PIO for certain sizes).
120 * If possible, it will also adjust the size so that it can be
121 * handled in just a single request.
123 * Returns the improved size, which might be unmodified.
125 unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz)
127 unsigned int orig_sz;
128 unsigned int blk_sz, byte_sz;
134 * Do a first check with the controller, in case it
135 * wants to increase the size up to a point where it
136 * might need more than one block.
138 sz = mmc_align_data_size(func->card, sz);
141 * If we can still do this with just a byte transfer, then
144 if (sz <= sdio_max_byte_size(func))
147 if (func->card->cccr.multi_block) {
149 * Check if the transfer is already block aligned
151 if ((sz % func->cur_blksize) == 0)
155 * Realign it so that it can be done with one request,
156 * and recheck if the controller still likes it.
158 blk_sz = ((sz + func->cur_blksize - 1) /
159 func->cur_blksize) * func->cur_blksize;
160 blk_sz = mmc_align_data_size(func->card, blk_sz);
163 * This value is only good if it is still just
166 if ((blk_sz % func->cur_blksize) == 0)
170 * We failed to do one request, but at least try to
171 * pad the remainder properly.
173 byte_sz = mmc_align_data_size(func->card,
174 sz % func->cur_blksize);
175 if (byte_sz <= sdio_max_byte_size(func)) {
176 blk_sz = sz / func->cur_blksize;
177 return blk_sz * func->cur_blksize + byte_sz;
181 * We need multiple requests, so first check that the
182 * controller can handle the chunk size;
184 chunk_sz = mmc_align_data_size(func->card,
185 sdio_max_byte_size(func));
186 if (chunk_sz == sdio_max_byte_size(func)) {
188 * Fix up the size of the remainder (if any)
190 byte_sz = orig_sz % chunk_sz;
192 byte_sz = mmc_align_data_size(func->card,
196 return (orig_sz / chunk_sz) * chunk_sz + byte_sz;
201 * The controller is simply incapable of transferring the size
202 * we want in decent manner, so just return the original size.
206 EXPORT_SYMBOL_GPL(sdio_align_size);
207 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) */
209 #ifdef CONFIG_DEBUG_FS
211 * Backport of debugfs_remove_recursive() without using the internals globals
212 * which are used by the kernel's version with:
213 * simple_release_fs(&debugfs_mount, &debugfs_mount_count);
215 void debugfs_remove_recursive(struct dentry *dentry)
217 struct dentry *last = NULL;
220 if (!dentry || !dentry->d_parent || !dentry->d_parent->d_inode)
223 while (dentry != last) {
224 struct dentry *child = dentry;
226 /* Find a child without children */
227 while (!list_empty(&child->d_subdirs))
228 child = list_entry(child->d_subdirs.next,
232 /* Bail out if we already tried to remove that entry */
237 debugfs_remove(child);
240 EXPORT_SYMBOL_GPL(debugfs_remove_recursive);
241 #endif /* CONFIG_DEBUG_FS */
243 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) */