[r4182]: madwifi / branches / madwifi-dfs / ath / if_ath_pci.c Maximize Restore History

Download this file

if_ath_pci.c    412 lines (358 with data), 11.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
/*-
* Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
* Copyright (c) 2004-2005 Atheros Communications, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
* redistribution must be conditioned upon including a substantially
* similar Disclaimer requirement for further binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGES.
*
* $Id: if_ath_pci.c 4182 2013-03-06 15:53:15Z proski $
*/
#include "opt_ah.h"
#ifndef EXPORT_SYMTAB
#define EXPORT_SYMTAB
#endif
#if !defined(AUTOCONF_INCLUDED) && !defined(CONFIG_LOCALVERSION)
#include <linux/config.h>
#endif
#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/if.h>
#include <linux/if_arp.h>
#include <linux/netdevice.h>
#include <linux/cache.h>
#include <linux/pci.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include "if_media.h"
#include <net80211/ieee80211_var.h>
#include "if_athvar.h"
#include "ah_devid.h"
#include "if_ath_pci.h"
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
/*
* PCI initialization uses Linux 2.4.x version and
* older kernels do not support this
*/
#error Atheros PCI version requires at least Linux kernel version 2.4.0
#endif /* kernel < 2.4.0 */
struct ath_pci_softc {
struct ath_softc aps_sc;
#ifdef CONFIG_PM
u32 aps_pmstate[16];
#endif
};
/*
* Module glue.
*/
#include "release.h"
static char *version = RELEASE_VERSION;
static char *dev_info = "ath_pci";
#include <linux/ethtool.h>
/*
* User a static table of PCI IDs for now. While this is the
* "new way" to do things, we may want to switch back to having
* the HAL check them by defining a probe method.
*/
static struct pci_device_id ath_pci_id_table[] = {
{ 0x168c, 0x0007, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0012, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0013, PCI_ANY_ID, PCI_ANY_ID },
{ 0xa727, 0x0013, PCI_ANY_ID, PCI_ANY_ID }, /* 3com */
{ 0x10b7, 0x0013, PCI_ANY_ID, PCI_ANY_ID }, /* 3com 3CRDAG675 */
{ 0x168c, 0x1014, PCI_ANY_ID, PCI_ANY_ID }, /* IBM minipci 5212 */
{ 0x168c, 0x101a, PCI_ANY_ID, PCI_ANY_ID }, /* some Griffin-Lite */
{ 0x168c, 0x0015, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0016, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0017, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0018, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0019, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x001a, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x001b, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x001c, PCI_ANY_ID, PCI_ANY_ID }, /* PCI Express 5424 */
{ 0x168c, 0x001d, PCI_ANY_ID, PCI_ANY_ID }, /* PCI Express ??? */
{ 0x168c, 0x0023, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0024, PCI_ANY_ID, PCI_ANY_ID },
{ 0x168c, 0x0027, PCI_ANY_ID, PCI_ANY_ID },
#if 0 /* PCI based AR9280 doesn't work yet */
{ 0x168c, 0x0029, PCI_ANY_ID, PCI_ANY_ID }, /* AR9280 PCI */
#endif
{ 0x168c, 0x002a, PCI_ANY_ID, PCI_ANY_ID }, /* AR9280 PCI Express */
{ 0x168c, 0x9013, PCI_ANY_ID, PCI_ANY_ID }, /* sonicwall */
{ }
};
static u16 ath_devidmap[][2] = {
{ 0x9013, 0x0013 }
};
static int
ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
resource_size_t phymem;
void __iomem *mem;
struct ath_pci_softc *sc;
struct net_device *dev;
const char *athname;
u_int8_t csz;
u32 val;
u16 vdevice;
int i;
if (pci_enable_device(pdev))
return -EIO;
/* XXX 32-bit addressing only */
if (pci_set_dma_mask(pdev, 0xffffffff)) {
printk(KERN_ERR "%s: 32-bit DMA not available\n", dev_info);
goto bad;
}
/*
* Cache line size is used to size and align various
* structures used to communicate with the hardware.
*/
pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
if (csz == 0) {
/*
* Linux 2.4.18 (at least) writes the cache line size
* register as a 16-bit wide register which is wrong.
* We must have this setup properly for rx buffer
* DMA to work so force a reasonable value here if it
* comes up zero.
*/
csz = L1_CACHE_BYTES / sizeof(u_int32_t);
pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
}
/*
* The default setting of latency timer yields poor results,
* set it to the value used by other systems. It may be worth
* tweaking this setting more.
*/
pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x60);
pci_set_master(pdev);
/*
* Disable the RETRY_TIMEOUT register (0x41) to keep
* PCI Tx retries from interfering with C3 CPU state.
*
* Code taken from ipw2100 driver - jg
*/
pci_read_config_dword(pdev, 0x40, &val);
if ((val & 0x0000ff00) != 0)
pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
phymem = pci_resource_start(pdev, 0);
if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "ath")) {
printk(KERN_ERR "%s: cannot reserve PCI memory region\n", dev_info);
goto bad;
}
mem = ioremap(phymem, pci_resource_len(pdev, 0));
if (!mem) {
printk(KERN_ERR "%s: cannot remap PCI memory region\n", dev_info);
goto bad1;
}
dev = alloc_netdev(sizeof(struct ath_pci_softc), "wifi%d", ether_setup);
if (dev == NULL) {
printk(KERN_ERR "%s: no memory for device state\n", dev_info);
goto bad2;
}
sc = netdev_priv(dev);
sc->aps_sc.sc_dev = dev;
sc->aps_sc.sc_iobase = mem;
/*
* Mark the device as detached to avoid processing
* interrupts until setup is complete.
*/
sc->aps_sc.sc_invalid = 1;
dev->irq = pdev->irq;
SET_MODULE_OWNER(dev);
SET_NETDEV_DEV(dev, &pdev->dev);
sc->aps_sc.sc_bdev = (void *)pdev;
pci_set_drvdata(pdev, dev);
if (request_irq(dev->irq, ath_intr, IRQF_SHARED, dev->name, dev)) {
printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
goto bad3;
}
/* looking for device type from broken device id */
vdevice = id->device;
for (i = 0; i < ARRAY_SIZE(ath_devidmap); i++) {
if (id->device == ath_devidmap[i][0]) {
vdevice = ath_devidmap[i][1];
break;
}
}
/*
* Auto-enable soft led processing for IBM cards and for
* 5211 minipci cards. Users can also manually enable/disable
* support with a sysctl.
*/
if (vdevice == AR5212_DEVID_IBM || vdevice == AR5211_DEVID) {
sc->aps_sc.sc_softled = 1;
sc->aps_sc.sc_ledpin = 0;
}
/* Enable softled on PIN1 on HP Compaq nc6xx, nc4000 & nx5000 laptops */
if (pdev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ) {
sc->aps_sc.sc_softled = 1;
sc->aps_sc.sc_ledpin = 1;
}
if (ath_attach(vdevice, dev, NULL) != 0)
goto bad4;
athname = ath_hal_probe(id->vendor, vdevice);
printk(KERN_INFO "%s: %s: %s: mem=0x%llx, irq=%d\n",
dev_info, dev->name, athname ? athname : "Atheros ???",
(unsigned long long)phymem, dev->irq);
if (vdevice == AR5416_DEVID_PCIE)
sc->aps_sc.sc_dmasize_stomp = 1;
/* ready to process interrupts */
sc->aps_sc.sc_invalid = 0;
return 0;
bad4:
free_irq(dev->irq, dev);
bad3:
free_netdev(dev);
bad2:
iounmap(mem);
bad1:
release_mem_region(phymem, pci_resource_len(pdev, 0));
bad:
pci_disable_device(pdev);
return (-ENODEV);
}
static void
ath_pci_remove(struct pci_dev *pdev)
{
struct net_device *dev = pci_get_drvdata(pdev);
struct ath_pci_softc *sc = netdev_priv(dev);
ath_detach(dev);
if (dev->irq)
free_irq(dev->irq, dev);
iounmap(sc->aps_sc.sc_iobase);
release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0));
pci_disable_device(pdev);
free_netdev(dev);
}
#ifdef CONFIG_PM
static int
ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
{
struct net_device *dev = pci_get_drvdata(pdev);
ath_suspend(dev);
PCI_SAVE_STATE(pdev, ((struct ath_pci_softc *)netdev_priv(dev))->aps_pmstate);
pci_disable_device(pdev);
return pci_set_power_state(pdev, PCI_D3hot);
}
static int
ath_pci_resume(struct pci_dev *pdev)
{
struct net_device *dev = pci_get_drvdata(pdev);
u32 val;
int err;
err = pci_set_power_state(pdev, PCI_D0);
if (err)
return err;
/* XXX - Should this return nonzero on fail? */
PCI_RESTORE_STATE(pdev, ((struct ath_pci_softc *)netdev_priv(dev))->aps_pmstate);
err = pci_enable_device(pdev);
if (err)
return err;
pci_set_master(pdev);
/*
* Suspend/Resume resets the PCI configuration space, so we have to
* re-disable the RETRY_TIMEOUT register (0x41) to keep
* PCI Tx retries from interfering with C3 CPU state
*
* Code taken from ipw2100 driver - jg
*/
pci_read_config_dword(pdev, 0x40, &val);
if ((val & 0x0000ff00) != 0)
pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
ath_resume(dev);
return 0;
}
#endif /* CONFIG_PM */
MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
static struct pci_driver ath_pci_driver = {
.name = "ath_pci",
.id_table = ath_pci_id_table,
.probe = ath_pci_probe,
.remove = ath_pci_remove,
#ifdef CONFIG_PM
.suspend = ath_pci_suspend,
.resume = ath_pci_resume,
#endif /* CONFIG_PM */
/* Linux 2.4.6 has save_state and enable_wake that are not used here */
};
int
ath_ioctl_ethtool(struct ath_softc *sc, int cmd, void __user *addr)
{
struct ethtool_drvinfo info;
if (cmd != ETHTOOL_GDRVINFO)
return -EOPNOTSUPP;
memset(&info, 0, sizeof(info));
info.cmd = cmd;
strncpy(info.driver, dev_info, sizeof(info.driver) - 1);
strncpy(info.version, version, sizeof(info.version) - 1);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,22)
/* include the device name so later versions of kudzu DTRT */
strncpy(info.bus_info, pci_name((struct pci_dev *)sc->sc_bdev),
sizeof(info.bus_info) - 1);
#endif
return copy_to_user(addr, &info, sizeof(info)) ? -EFAULT : 0;
}
MODULE_AUTHOR("Errno Consulting, Sam Leffler");
MODULE_DESCRIPTION("Support for Atheros 802.11 wireless LAN cards.");
#ifdef MODULE_VERSION
MODULE_VERSION(RELEASE_VERSION);
#endif
MODULE_SUPPORTED_DEVICE("Atheros WLAN cards");
#ifdef MODULE_LICENSE
MODULE_LICENSE("Dual BSD/GPL");
#endif
static int __init
init_ath_pci(void)
{
int status;
ath_sysctl_register();
if ((status = pci_register_driver(&ath_pci_driver))) {
ath_sysctl_unregister();
return (status);
}
return (0);
}
module_init(init_ath_pci);
static void __exit
exit_ath_pci(void)
{
ath_sysctl_unregister();
pci_unregister_driver(&ath_pci_driver);
}
module_exit(exit_ath_pci);
/* return bus cachesize in 4B word units */
void
bus_read_cachesize(struct ath_softc *sc, u_int8_t *csz)
{
pci_read_config_byte(sc->sc_bdev, PCI_CACHE_LINE_SIZE, csz);
}