Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1 | #define PRISM2_PCI |
| 2 | |
| 3 | /* Host AP driver's support for Intersil Prism2.5 PCI cards is based on |
| 4 | * driver patches from Reyk Floeter <reyk@vantronix.net> and |
| 5 | * Andy Warner <andyw@pobox.com> */ |
| 6 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 7 | #include <linux/module.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/if.h> |
| 10 | #include <linux/skbuff.h> |
| 11 | #include <linux/netdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 13 | #include <linux/workqueue.h> |
| 14 | #include <linux/wireless.h> |
| 15 | #include <net/iw_handler.h> |
| 16 | |
| 17 | #include <linux/ioport.h> |
| 18 | #include <linux/pci.h> |
| 19 | #include <asm/io.h> |
| 20 | |
| 21 | #include "hostap_wlan.h" |
| 22 | |
| 23 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 24 | static char *dev_info = "hostap_pci"; |
| 25 | |
| 26 | |
| 27 | MODULE_AUTHOR("Jouni Malinen"); |
| 28 | MODULE_DESCRIPTION("Support for Intersil Prism2.5-based 802.11 wireless LAN " |
| 29 | "PCI cards."); |
| 30 | MODULE_SUPPORTED_DEVICE("Intersil Prism2.5-based WLAN PCI cards"); |
| 31 | MODULE_LICENSE("GPL"); |
| 32 | |
| 33 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 34 | /* struct local_info::hw_priv */ |
| 35 | struct hostap_pci_priv { |
| 36 | void __iomem *mem_start; |
| 37 | }; |
| 38 | |
| 39 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 40 | /* FIX: do we need mb/wmb/rmb with memory operations? */ |
| 41 | |
| 42 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 43 | static DEFINE_PCI_DEVICE_TABLE(prism2_pci_id_table) = { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 44 | /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */ |
| 45 | { 0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID }, |
| 46 | /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */ |
| 47 | { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID }, |
| 48 | /* Samsung MagicLAN SWL-2210P */ |
| 49 | { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID }, |
| 50 | { 0 } |
| 51 | }; |
| 52 | |
| 53 | |
| 54 | #ifdef PRISM2_IO_DEBUG |
| 55 | |
| 56 | static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v) |
| 57 | { |
| 58 | struct hostap_interface *iface; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 59 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 60 | local_info_t *local; |
| 61 | unsigned long flags; |
| 62 | |
| 63 | iface = netdev_priv(dev); |
| 64 | local = iface->local; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 65 | hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 66 | |
| 67 | spin_lock_irqsave(&local->lock, flags); |
| 68 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 69 | writeb(v, hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 70 | spin_unlock_irqrestore(&local->lock, flags); |
| 71 | } |
| 72 | |
| 73 | static inline u8 hfa384x_inb_debug(struct net_device *dev, int a) |
| 74 | { |
| 75 | struct hostap_interface *iface; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 76 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 77 | local_info_t *local; |
| 78 | unsigned long flags; |
| 79 | u8 v; |
| 80 | |
| 81 | iface = netdev_priv(dev); |
| 82 | local = iface->local; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 83 | hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 84 | |
| 85 | spin_lock_irqsave(&local->lock, flags); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 86 | v = readb(hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 87 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v); |
| 88 | spin_unlock_irqrestore(&local->lock, flags); |
| 89 | return v; |
| 90 | } |
| 91 | |
| 92 | static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v) |
| 93 | { |
| 94 | struct hostap_interface *iface; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 95 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 96 | local_info_t *local; |
| 97 | unsigned long flags; |
| 98 | |
| 99 | iface = netdev_priv(dev); |
| 100 | local = iface->local; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 101 | hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 102 | |
| 103 | spin_lock_irqsave(&local->lock, flags); |
| 104 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 105 | writew(v, hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 106 | spin_unlock_irqrestore(&local->lock, flags); |
| 107 | } |
| 108 | |
| 109 | static inline u16 hfa384x_inw_debug(struct net_device *dev, int a) |
| 110 | { |
| 111 | struct hostap_interface *iface; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 112 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 113 | local_info_t *local; |
| 114 | unsigned long flags; |
| 115 | u16 v; |
| 116 | |
| 117 | iface = netdev_priv(dev); |
| 118 | local = iface->local; |
Jouni Malinen | f7a7444 | 2005-10-02 17:18:59 -0700 | [diff] [blame] | 119 | hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 120 | |
| 121 | spin_lock_irqsave(&local->lock, flags); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 122 | v = readw(hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 123 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v); |
| 124 | spin_unlock_irqrestore(&local->lock, flags); |
| 125 | return v; |
| 126 | } |
| 127 | |
| 128 | #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v)) |
| 129 | #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a)) |
| 130 | #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v)) |
| 131 | #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a)) |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 132 | #define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), le16_to_cpu((v))) |
| 133 | #define HFA384X_INW_DATA(a) cpu_to_le16(hfa384x_inw_debug(dev, (a))) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 134 | |
| 135 | #else /* PRISM2_IO_DEBUG */ |
| 136 | |
| 137 | static inline void hfa384x_outb(struct net_device *dev, int a, u8 v) |
| 138 | { |
| 139 | struct hostap_interface *iface; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 140 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 141 | iface = netdev_priv(dev); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 142 | hw_priv = iface->local->hw_priv; |
| 143 | writeb(v, hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static inline u8 hfa384x_inb(struct net_device *dev, int a) |
| 147 | { |
| 148 | struct hostap_interface *iface; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 149 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 150 | iface = netdev_priv(dev); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 151 | hw_priv = iface->local->hw_priv; |
| 152 | return readb(hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static inline void hfa384x_outw(struct net_device *dev, int a, u16 v) |
| 156 | { |
| 157 | struct hostap_interface *iface; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 158 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 159 | iface = netdev_priv(dev); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 160 | hw_priv = iface->local->hw_priv; |
| 161 | writew(v, hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static inline u16 hfa384x_inw(struct net_device *dev, int a) |
| 165 | { |
| 166 | struct hostap_interface *iface; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 167 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 168 | iface = netdev_priv(dev); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 169 | hw_priv = iface->local->hw_priv; |
| 170 | return readw(hw_priv->mem_start + a); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | #define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v)) |
| 174 | #define HFA384X_INB(a) hfa384x_inb(dev, (a)) |
| 175 | #define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v)) |
| 176 | #define HFA384X_INW(a) hfa384x_inw(dev, (a)) |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 177 | #define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), le16_to_cpu((v))) |
| 178 | #define HFA384X_INW_DATA(a) cpu_to_le16(hfa384x_inw(dev, (a))) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 179 | |
| 180 | #endif /* PRISM2_IO_DEBUG */ |
| 181 | |
| 182 | |
| 183 | static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf, |
| 184 | int len) |
| 185 | { |
| 186 | u16 d_off; |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 187 | __le16 *pos; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 188 | |
| 189 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 190 | pos = (__le16 *) buf; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 191 | |
| 192 | for ( ; len > 1; len -= 2) |
| 193 | *pos++ = HFA384X_INW_DATA(d_off); |
| 194 | |
| 195 | if (len & 1) |
| 196 | *((char *) pos) = HFA384X_INB(d_off); |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len) |
| 203 | { |
| 204 | u16 d_off; |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 205 | __le16 *pos; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 206 | |
| 207 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; |
Al Viro | 8a9faf3 | 2007-12-21 03:30:16 -0500 | [diff] [blame] | 208 | pos = (__le16 *) buf; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 209 | |
| 210 | for ( ; len > 1; len -= 2) |
| 211 | HFA384X_OUTW_DATA(*pos++, d_off); |
| 212 | |
| 213 | if (len & 1) |
| 214 | HFA384X_OUTB(*((char *) pos), d_off); |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | |
| 220 | /* FIX: This might change at some point.. */ |
| 221 | #include "hostap_hw.c" |
| 222 | |
| 223 | static void prism2_pci_cor_sreset(local_info_t *local) |
| 224 | { |
| 225 | struct net_device *dev = local->dev; |
| 226 | u16 reg; |
| 227 | |
| 228 | reg = HFA384X_INB(HFA384X_PCICOR_OFF); |
| 229 | printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg); |
| 230 | |
| 231 | /* linux-wlan-ng uses extremely long hold and settle times for |
| 232 | * COR sreset. A comment in the driver code mentions that the long |
| 233 | * delays appear to be necessary. However, at least IBM 22P6901 seems |
| 234 | * to work fine with shorter delays. |
| 235 | * |
| 236 | * Longer delays can be configured by uncommenting following line: */ |
| 237 | /* #define PRISM2_PCI_USE_LONG_DELAYS */ |
| 238 | |
| 239 | #ifdef PRISM2_PCI_USE_LONG_DELAYS |
| 240 | int i; |
| 241 | |
| 242 | HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF); |
| 243 | mdelay(250); |
| 244 | |
| 245 | HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF); |
| 246 | mdelay(500); |
| 247 | |
| 248 | /* Wait for f/w to complete initialization (CMD:BUSY == 0) */ |
| 249 | i = 2000000 / 10; |
| 250 | while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i) |
| 251 | udelay(10); |
| 252 | |
| 253 | #else /* PRISM2_PCI_USE_LONG_DELAYS */ |
| 254 | |
| 255 | HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF); |
| 256 | mdelay(2); |
| 257 | HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF); |
| 258 | mdelay(2); |
| 259 | |
| 260 | #endif /* PRISM2_PCI_USE_LONG_DELAYS */ |
| 261 | |
| 262 | if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) { |
| 263 | printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name); |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | |
| 268 | static void prism2_pci_genesis_reset(local_info_t *local, int hcr) |
| 269 | { |
| 270 | struct net_device *dev = local->dev; |
| 271 | |
| 272 | HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF); |
| 273 | mdelay(10); |
| 274 | HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF); |
| 275 | mdelay(10); |
| 276 | HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF); |
| 277 | mdelay(10); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static struct prism2_helper_functions prism2_pci_funcs = |
| 282 | { |
| 283 | .card_present = NULL, |
| 284 | .cor_sreset = prism2_pci_cor_sreset, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 285 | .genesis_reset = prism2_pci_genesis_reset, |
| 286 | .hw_type = HOSTAP_HW_PCI, |
| 287 | }; |
| 288 | |
| 289 | |
| 290 | static int prism2_pci_probe(struct pci_dev *pdev, |
| 291 | const struct pci_device_id *id) |
| 292 | { |
| 293 | unsigned long phymem; |
| 294 | void __iomem *mem = NULL; |
| 295 | local_info_t *local = NULL; |
| 296 | struct net_device *dev = NULL; |
| 297 | static int cards_found /* = 0 */; |
| 298 | int irq_registered = 0; |
| 299 | struct hostap_interface *iface; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 300 | struct hostap_pci_priv *hw_priv; |
| 301 | |
Yan Burman | b0471bb7 | 2006-12-02 13:33:40 +0200 | [diff] [blame] | 302 | hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 303 | if (hw_priv == NULL) |
| 304 | return -ENOMEM; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 305 | |
| 306 | if (pci_enable_device(pdev)) |
Jouni Malinen | 9320199 | 2006-03-19 19:21:49 -0800 | [diff] [blame] | 307 | goto err_out_free; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 308 | |
| 309 | phymem = pci_resource_start(pdev, 0); |
| 310 | |
| 311 | if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) { |
| 312 | printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n"); |
| 313 | goto err_out_disable; |
| 314 | } |
| 315 | |
Arjan van de Ven | 275f165 | 2008-10-20 21:42:39 -0700 | [diff] [blame] | 316 | mem = pci_ioremap_bar(pdev, 0); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 317 | if (mem == NULL) { |
| 318 | printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ; |
| 319 | goto fail; |
| 320 | } |
| 321 | |
Dave Hansen | 0cd545d | 2005-07-30 12:49:58 -0700 | [diff] [blame] | 322 | dev = prism2_init_local_data(&prism2_pci_funcs, cards_found, |
| 323 | &pdev->dev); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 324 | if (dev == NULL) |
| 325 | goto fail; |
| 326 | iface = netdev_priv(dev); |
| 327 | local = iface->local; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 328 | local->hw_priv = hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 329 | cards_found++; |
| 330 | |
| 331 | dev->irq = pdev->irq; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 332 | hw_priv->mem_start = mem; |
John W. Linville | 0f4da2d | 2010-07-13 14:06:32 -0400 | [diff] [blame] | 333 | dev->base_addr = (unsigned long) mem; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 334 | |
| 335 | prism2_pci_cor_sreset(local); |
| 336 | |
| 337 | pci_set_drvdata(pdev, dev); |
| 338 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 339 | if (request_irq(dev->irq, prism2_interrupt, IRQF_SHARED, dev->name, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 340 | dev)) { |
| 341 | printk(KERN_WARNING "%s: request_irq failed\n", dev->name); |
| 342 | goto fail; |
| 343 | } else |
| 344 | irq_registered = 1; |
| 345 | |
| 346 | if (!local->pri_only && prism2_hw_config(dev, 1)) { |
| 347 | printk(KERN_DEBUG "%s: hardware initialization failed\n", |
| 348 | dev_info); |
| 349 | goto fail; |
| 350 | } |
| 351 | |
| 352 | printk(KERN_INFO "%s: Intersil Prism2.5 PCI: " |
| 353 | "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq); |
| 354 | |
| 355 | return hostap_hw_ready(dev); |
| 356 | |
| 357 | fail: |
| 358 | if (irq_registered && dev) |
| 359 | free_irq(dev->irq, dev); |
| 360 | |
| 361 | if (mem) |
| 362 | iounmap(mem); |
| 363 | |
| 364 | release_mem_region(phymem, pci_resource_len(pdev, 0)); |
| 365 | |
| 366 | err_out_disable: |
| 367 | pci_disable_device(pdev); |
| 368 | prism2_free_local_data(dev); |
Jouni Malinen | 9320199 | 2006-03-19 19:21:49 -0800 | [diff] [blame] | 369 | |
| 370 | err_out_free: |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 371 | kfree(hw_priv); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 372 | |
| 373 | return -ENODEV; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | static void prism2_pci_remove(struct pci_dev *pdev) |
| 378 | { |
| 379 | struct net_device *dev; |
| 380 | struct hostap_interface *iface; |
| 381 | void __iomem *mem_start; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 382 | struct hostap_pci_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 383 | |
| 384 | dev = pci_get_drvdata(pdev); |
| 385 | iface = netdev_priv(dev); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 386 | hw_priv = iface->local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 387 | |
| 388 | /* Reset the hardware, and ensure interrupts are disabled. */ |
| 389 | prism2_pci_cor_sreset(iface->local); |
| 390 | hfa384x_disable_interrupts(dev); |
| 391 | |
| 392 | if (dev->irq) |
| 393 | free_irq(dev->irq, dev); |
| 394 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 395 | mem_start = hw_priv->mem_start; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 396 | prism2_free_local_data(dev); |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 397 | kfree(hw_priv); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 398 | |
| 399 | iounmap(mem_start); |
| 400 | |
| 401 | release_mem_region(pci_resource_start(pdev, 0), |
| 402 | pci_resource_len(pdev, 0)); |
| 403 | pci_disable_device(pdev); |
| 404 | } |
| 405 | |
| 406 | |
| 407 | #ifdef CONFIG_PM |
Andrew Morton | b2dabd5 | 2005-07-13 00:33:46 -0700 | [diff] [blame] | 408 | static int prism2_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 409 | { |
| 410 | struct net_device *dev = pci_get_drvdata(pdev); |
| 411 | |
| 412 | if (netif_running(dev)) { |
| 413 | netif_stop_queue(dev); |
| 414 | netif_device_detach(dev); |
| 415 | } |
| 416 | prism2_suspend(dev); |
| 417 | pci_save_state(pdev); |
| 418 | pci_disable_device(pdev); |
Pavel Machek | 583a4e8 | 2005-09-03 15:56:58 -0700 | [diff] [blame] | 419 | pci_set_power_state(pdev, PCI_D3hot); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 420 | |
| 421 | return 0; |
| 422 | } |
| 423 | |
| 424 | static int prism2_pci_resume(struct pci_dev *pdev) |
| 425 | { |
| 426 | struct net_device *dev = pci_get_drvdata(pdev); |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 427 | int err; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 428 | |
John W. Linville | 02e0e5e | 2006-11-07 20:53:48 -0500 | [diff] [blame] | 429 | err = pci_enable_device(pdev); |
| 430 | if (err) { |
| 431 | printk(KERN_ERR "%s: pci_enable_device failed on resume\n", |
| 432 | dev->name); |
| 433 | return err; |
| 434 | } |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 435 | pci_restore_state(pdev); |
| 436 | prism2_hw_config(dev, 0); |
| 437 | if (netif_running(dev)) { |
| 438 | netif_device_attach(dev); |
| 439 | netif_start_queue(dev); |
| 440 | } |
| 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | #endif /* CONFIG_PM */ |
| 445 | |
| 446 | |
| 447 | MODULE_DEVICE_TABLE(pci, prism2_pci_id_table); |
| 448 | |
Randy Dunlap | 2493d8e | 2007-10-29 11:20:26 -0700 | [diff] [blame] | 449 | static struct pci_driver prism2_pci_driver = { |
Pavel Roskin | 7a71653 | 2005-09-23 21:58:58 -0700 | [diff] [blame] | 450 | .name = "hostap_pci", |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 451 | .id_table = prism2_pci_id_table, |
| 452 | .probe = prism2_pci_probe, |
| 453 | .remove = prism2_pci_remove, |
| 454 | #ifdef CONFIG_PM |
| 455 | .suspend = prism2_pci_suspend, |
| 456 | .resume = prism2_pci_resume, |
| 457 | #endif /* CONFIG_PM */ |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 458 | }; |
| 459 | |
| 460 | |
| 461 | static int __init init_prism2_pci(void) |
| 462 | { |
Randy Dunlap | 2493d8e | 2007-10-29 11:20:26 -0700 | [diff] [blame] | 463 | return pci_register_driver(&prism2_pci_driver); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | |
| 467 | static void __exit exit_prism2_pci(void) |
| 468 | { |
Randy Dunlap | 2493d8e | 2007-10-29 11:20:26 -0700 | [diff] [blame] | 469 | pci_unregister_driver(&prism2_pci_driver); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | |
| 473 | module_init(init_prism2_pci); |
| 474 | module_exit(exit_prism2_pci); |