Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * lanstreamer.c -- driver for the IBM Auto LANStreamer PCI Adapter |
| 3 | * |
| 4 | * Written By: Mike Sullivan, IBM Corporation |
| 5 | * |
| 6 | * Copyright (C) 1999 IBM Corporation |
| 7 | * |
| 8 | * Linux driver for IBM PCI tokenring cards based on the LanStreamer MPC |
| 9 | * chipset. |
| 10 | * |
| 11 | * This driver is based on the olympic driver for IBM PCI TokenRing cards (Pit/Pit-Phy/Olympic |
| 12 | * chipsets) written by: |
| 13 | * 1999 Peter De Schrijver All Rights Reserved |
| 14 | * 1999 Mike Phillips (phillim@amtrak.com) |
| 15 | * |
| 16 | * Base Driver Skeleton: |
| 17 | * Written 1993-94 by Donald Becker. |
| 18 | * |
| 19 | * Copyright 1993 United States Government as represented by the |
| 20 | * Director, National Security Agency. |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation; either version 2 of the License, or |
| 25 | * (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * NO WARRANTY |
| 33 | * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 34 | * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT |
| 35 | * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, |
| 36 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is |
| 37 | * solely responsible for determining the appropriateness of using and |
| 38 | * distributing the Program and assumes all risks associated with its |
| 39 | * exercise of rights under this Agreement, including but not limited to |
| 40 | * the risks and costs of program errors, damage to or loss of data, |
| 41 | * programs or equipment, and unavailability or interruption of operations. |
| 42 | * |
| 43 | * DISCLAIMER OF LIABILITY |
| 44 | * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY |
| 45 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 46 | * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND |
| 47 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 48 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 49 | * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED |
| 50 | * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES |
| 51 | * |
| 52 | * You should have received a copy of the GNU General Public License |
| 53 | * along with this program; if not, write to the Free Software |
| 54 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 55 | * |
| 56 | * |
| 57 | * 12/10/99 - Alpha Release 0.1.0 |
| 58 | * First release to the public |
| 59 | * 03/03/00 - Merged to kernel, indented -kr -i8 -bri0, fixed some missing |
| 60 | * malloc free checks, reviewed code. <alan@redhat.com> |
| 61 | * 03/13/00 - Added spinlocks for smp |
| 62 | * 03/08/01 - Added support for module_init() and module_exit() |
| 63 | * 08/15/01 - Added ioctl() functionality for debugging, changed netif_*_queue |
| 64 | * calls and other incorrectness - Kent Yoder <yoder1@us.ibm.com> |
| 65 | * 11/05/01 - Restructured the interrupt function, added delays, reduced the |
| 66 | * the number of TX descriptors to 1, which together can prevent |
| 67 | * the card from locking up the box - <yoder1@us.ibm.com> |
| 68 | * 09/27/02 - New PCI interface + bug fix. - <yoder1@us.ibm.com> |
| 69 | * 11/13/02 - Removed free_irq calls which could cause a hang, added |
| 70 | * netif_carrier_{on|off} - <yoder1@us.ibm.com> |
| 71 | * |
| 72 | * To Do: |
| 73 | * |
| 74 | * |
| 75 | * If Problems do Occur |
| 76 | * Most problems can be rectified by either closing and opening the interface |
| 77 | * (ifconfig down and up) or rmmod and insmod'ing the driver (a bit difficult |
| 78 | * if compiled into the kernel). |
| 79 | */ |
| 80 | |
| 81 | /* Change STREAMER_DEBUG to 1 to get verbose, and I mean really verbose, messages */ |
| 82 | |
| 83 | #define STREAMER_DEBUG 0 |
| 84 | #define STREAMER_DEBUG_PACKETS 0 |
| 85 | |
| 86 | /* Change STREAMER_NETWORK_MONITOR to receive mac frames through the arb channel. |
| 87 | * Will also create a /proc/net/streamer_tr entry if proc_fs is compiled into the |
| 88 | * kernel. |
| 89 | * Intended to be used to create a ring-error reporting network module |
| 90 | * i.e. it will give you the source address of beaconers on the ring |
| 91 | */ |
| 92 | |
| 93 | #define STREAMER_NETWORK_MONITOR 0 |
| 94 | |
| 95 | /* #define CONFIG_PROC_FS */ |
| 96 | |
| 97 | /* |
| 98 | * Allow or disallow ioctl's for debugging |
| 99 | */ |
| 100 | |
| 101 | #define STREAMER_IOCTL 0 |
| 102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | #include <linux/module.h> |
| 104 | #include <linux/kernel.h> |
| 105 | #include <linux/errno.h> |
| 106 | #include <linux/timer.h> |
| 107 | #include <linux/in.h> |
| 108 | #include <linux/ioport.h> |
| 109 | #include <linux/string.h> |
| 110 | #include <linux/proc_fs.h> |
| 111 | #include <linux/ptrace.h> |
| 112 | #include <linux/skbuff.h> |
| 113 | #include <linux/interrupt.h> |
| 114 | #include <linux/delay.h> |
| 115 | #include <linux/netdevice.h> |
| 116 | #include <linux/trdevice.h> |
| 117 | #include <linux/stddef.h> |
| 118 | #include <linux/init.h> |
| 119 | #include <linux/pci.h> |
Domen Puncer | 1e7f0bd | 2005-06-26 18:22:14 -0400 | [diff] [blame] | 120 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | #include <linux/spinlock.h> |
| 122 | #include <linux/version.h> |
| 123 | #include <linux/bitops.h> |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 124 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
| 126 | #include <net/checksum.h> |
| 127 | |
| 128 | #include <asm/io.h> |
| 129 | #include <asm/system.h> |
| 130 | |
| 131 | #include "lanstreamer.h" |
| 132 | |
| 133 | #if (BITS_PER_LONG == 64) |
| 134 | #error broken on 64-bit: stores pointer to rx_ring->buffer in 32-bit int |
| 135 | #endif |
| 136 | |
| 137 | |
| 138 | /* I've got to put some intelligence into the version number so that Peter and I know |
| 139 | * which version of the code somebody has got. |
| 140 | * Version Number = a.b.c.d where a.b.c is the level of code and d is the latest author. |
| 141 | * So 0.0.1.pds = Peter, 0.0.1.mlp = Mike |
| 142 | * |
| 143 | * Official releases will only have an a.b.c version number format. |
| 144 | */ |
| 145 | |
| 146 | static char version[] = "LanStreamer.c v0.4.0 03/08/01 - Mike Sullivan\n" |
| 147 | " v0.5.3 11/13/02 - Kent Yoder"; |
| 148 | |
| 149 | static struct pci_device_id streamer_pci_tbl[] = { |
| 150 | { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_TR, PCI_ANY_ID, PCI_ANY_ID,}, |
| 151 | {} /* terminating entry */ |
| 152 | }; |
| 153 | MODULE_DEVICE_TABLE(pci,streamer_pci_tbl); |
| 154 | |
| 155 | |
| 156 | static char *open_maj_error[] = { |
| 157 | "No error", "Lobe Media Test", "Physical Insertion", |
| 158 | "Address Verification", "Neighbor Notification (Ring Poll)", |
| 159 | "Request Parameters", "FDX Registration Request", |
| 160 | "FDX Lobe Media Test", "FDX Duplicate Address Check", |
| 161 | "Unknown stage" |
| 162 | }; |
| 163 | |
| 164 | static char *open_min_error[] = { |
| 165 | "No error", "Function Failure", "Signal Lost", "Wire Fault", |
| 166 | "Ring Speed Mismatch", "Timeout", "Ring Failure", "Ring Beaconing", |
| 167 | "Duplicate Node Address", "Request Parameters", "Remove Received", |
| 168 | "Reserved", "Reserved", "No Monitor Detected for RPL", |
| 169 | "Monitor Contention failer for RPL", "FDX Protocol Error" |
| 170 | }; |
| 171 | |
| 172 | /* Module paramters */ |
| 173 | |
| 174 | /* Ring Speed 0,4,16 |
| 175 | * 0 = Autosense |
| 176 | * 4,16 = Selected speed only, no autosense |
| 177 | * This allows the card to be the first on the ring |
| 178 | * and become the active monitor. |
| 179 | * |
| 180 | * WARNING: Some hubs will allow you to insert |
| 181 | * at the wrong speed |
| 182 | */ |
| 183 | |
| 184 | static int ringspeed[STREAMER_MAX_ADAPTERS] = { 0, }; |
| 185 | |
| 186 | module_param_array(ringspeed, int, NULL, 0); |
| 187 | |
| 188 | /* Packet buffer size */ |
| 189 | |
| 190 | static int pkt_buf_sz[STREAMER_MAX_ADAPTERS] = { 0, }; |
| 191 | |
| 192 | module_param_array(pkt_buf_sz, int, NULL, 0); |
| 193 | |
| 194 | /* Message Level */ |
| 195 | |
| 196 | static int message_level[STREAMER_MAX_ADAPTERS] = { 1, }; |
| 197 | |
| 198 | module_param_array(message_level, int, NULL, 0); |
| 199 | |
| 200 | #if STREAMER_IOCTL |
| 201 | static int streamer_ioctl(struct net_device *, struct ifreq *, int); |
| 202 | #endif |
| 203 | |
| 204 | static int streamer_reset(struct net_device *dev); |
| 205 | static int streamer_open(struct net_device *dev); |
| 206 | static int streamer_xmit(struct sk_buff *skb, struct net_device *dev); |
| 207 | static int streamer_close(struct net_device *dev); |
| 208 | static void streamer_set_rx_mode(struct net_device *dev); |
| 209 | static irqreturn_t streamer_interrupt(int irq, void *dev_id, |
| 210 | struct pt_regs *regs); |
| 211 | static struct net_device_stats *streamer_get_stats(struct net_device *dev); |
| 212 | static int streamer_set_mac_address(struct net_device *dev, void *addr); |
| 213 | static void streamer_arb_cmd(struct net_device *dev); |
| 214 | static int streamer_change_mtu(struct net_device *dev, int mtu); |
| 215 | static void streamer_srb_bh(struct net_device *dev); |
| 216 | static void streamer_asb_bh(struct net_device *dev); |
| 217 | #if STREAMER_NETWORK_MONITOR |
| 218 | #ifdef CONFIG_PROC_FS |
| 219 | static int streamer_proc_info(char *buffer, char **start, off_t offset, |
| 220 | int length, int *eof, void *data); |
| 221 | static int sprintf_info(char *buffer, struct net_device *dev); |
| 222 | struct streamer_private *dev_streamer=NULL; |
| 223 | #endif |
| 224 | #endif |
| 225 | |
| 226 | static int __devinit streamer_init_one(struct pci_dev *pdev, |
| 227 | const struct pci_device_id *ent) |
| 228 | { |
| 229 | struct net_device *dev; |
| 230 | struct streamer_private *streamer_priv; |
| 231 | unsigned long pio_start, pio_end, pio_flags, pio_len; |
| 232 | unsigned long mmio_start, mmio_end, mmio_flags, mmio_len; |
| 233 | int rc = 0; |
| 234 | static int card_no=-1; |
| 235 | u16 pcr; |
| 236 | |
| 237 | #if STREAMER_DEBUG |
| 238 | printk("lanstreamer::streamer_init_one, entry pdev %p\n",pdev); |
| 239 | #endif |
| 240 | |
| 241 | card_no++; |
| 242 | dev = alloc_trdev(sizeof(*streamer_priv)); |
| 243 | if (dev==NULL) { |
| 244 | printk(KERN_ERR "lanstreamer: out of memory.\n"); |
| 245 | return -ENOMEM; |
| 246 | } |
| 247 | |
| 248 | SET_MODULE_OWNER(dev); |
| 249 | streamer_priv = dev->priv; |
| 250 | |
| 251 | #if STREAMER_NETWORK_MONITOR |
| 252 | #ifdef CONFIG_PROC_FS |
| 253 | if (!dev_streamer) |
| 254 | create_proc_read_entry("net/streamer_tr", 0, 0, |
| 255 | streamer_proc_info, NULL); |
| 256 | streamer_priv->next = dev_streamer; |
| 257 | dev_streamer = streamer_priv; |
| 258 | #endif |
| 259 | #endif |
| 260 | |
Domen Puncer | 1e7f0bd | 2005-06-26 18:22:14 -0400 | [diff] [blame] | 261 | rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (rc) { |
| 263 | printk(KERN_ERR "%s: No suitable PCI mapping available.\n", |
| 264 | dev->name); |
| 265 | rc = -ENODEV; |
| 266 | goto err_out; |
| 267 | } |
| 268 | |
| 269 | rc = pci_enable_device(pdev); |
| 270 | if (rc) { |
| 271 | printk(KERN_ERR "lanstreamer: unable to enable pci device\n"); |
| 272 | rc=-EIO; |
| 273 | goto err_out; |
| 274 | } |
| 275 | |
| 276 | pci_set_master(pdev); |
| 277 | |
| 278 | rc = pci_set_mwi(pdev); |
| 279 | if (rc) { |
| 280 | printk(KERN_ERR "lanstreamer: unable to enable MWI on pci device\n"); |
| 281 | goto err_out_disable; |
| 282 | } |
| 283 | |
| 284 | pio_start = pci_resource_start(pdev, 0); |
| 285 | pio_end = pci_resource_end(pdev, 0); |
| 286 | pio_flags = pci_resource_flags(pdev, 0); |
| 287 | pio_len = pci_resource_len(pdev, 0); |
| 288 | |
| 289 | mmio_start = pci_resource_start(pdev, 1); |
| 290 | mmio_end = pci_resource_end(pdev, 1); |
| 291 | mmio_flags = pci_resource_flags(pdev, 1); |
| 292 | mmio_len = pci_resource_len(pdev, 1); |
| 293 | |
| 294 | #if STREAMER_DEBUG |
| 295 | printk("lanstreamer: pio_start %x pio_end %x pio_len %x pio_flags %x\n", |
| 296 | pio_start, pio_end, pio_len, pio_flags); |
| 297 | printk("lanstreamer: mmio_start %x mmio_end %x mmio_len %x mmio_flags %x\n", |
| 298 | mmio_start, mmio_end, mmio_flags, mmio_len); |
| 299 | #endif |
| 300 | |
| 301 | if (!request_region(pio_start, pio_len, "lanstreamer")) { |
| 302 | printk(KERN_ERR "lanstreamer: unable to get pci io addr %lx\n", |
| 303 | pio_start); |
| 304 | rc= -EBUSY; |
| 305 | goto err_out_mwi; |
| 306 | } |
| 307 | |
| 308 | if (!request_mem_region(mmio_start, mmio_len, "lanstreamer")) { |
| 309 | printk(KERN_ERR "lanstreamer: unable to get pci mmio addr %lx\n", |
| 310 | mmio_start); |
| 311 | rc= -EBUSY; |
| 312 | goto err_out_free_pio; |
| 313 | } |
| 314 | |
| 315 | streamer_priv->streamer_mmio=ioremap(mmio_start, mmio_len); |
| 316 | if (streamer_priv->streamer_mmio == NULL) { |
| 317 | printk(KERN_ERR "lanstreamer: unable to remap MMIO %lx\n", |
| 318 | mmio_start); |
| 319 | rc= -EIO; |
| 320 | goto err_out_free_mmio; |
| 321 | } |
| 322 | |
| 323 | init_waitqueue_head(&streamer_priv->srb_wait); |
| 324 | init_waitqueue_head(&streamer_priv->trb_wait); |
| 325 | |
| 326 | dev->open = &streamer_open; |
| 327 | dev->hard_start_xmit = &streamer_xmit; |
| 328 | dev->change_mtu = &streamer_change_mtu; |
| 329 | dev->stop = &streamer_close; |
| 330 | #if STREAMER_IOCTL |
| 331 | dev->do_ioctl = &streamer_ioctl; |
| 332 | #else |
| 333 | dev->do_ioctl = NULL; |
| 334 | #endif |
| 335 | dev->set_multicast_list = &streamer_set_rx_mode; |
| 336 | dev->get_stats = &streamer_get_stats; |
| 337 | dev->set_mac_address = &streamer_set_mac_address; |
| 338 | dev->irq = pdev->irq; |
| 339 | dev->base_addr=pio_start; |
| 340 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 341 | |
| 342 | streamer_priv->streamer_card_name = (char *)pdev->resource[0].name; |
| 343 | streamer_priv->pci_dev = pdev; |
| 344 | |
| 345 | if ((pkt_buf_sz[card_no] < 100) || (pkt_buf_sz[card_no] > 18000)) |
| 346 | streamer_priv->pkt_buf_sz = PKT_BUF_SZ; |
| 347 | else |
| 348 | streamer_priv->pkt_buf_sz = pkt_buf_sz[card_no]; |
| 349 | |
| 350 | streamer_priv->streamer_ring_speed = ringspeed[card_no]; |
| 351 | streamer_priv->streamer_message_level = message_level[card_no]; |
| 352 | |
| 353 | pci_set_drvdata(pdev, dev); |
| 354 | |
| 355 | spin_lock_init(&streamer_priv->streamer_lock); |
| 356 | |
| 357 | pci_read_config_word (pdev, PCI_COMMAND, &pcr); |
| 358 | pcr |= PCI_COMMAND_SERR; |
| 359 | pci_write_config_word (pdev, PCI_COMMAND, pcr); |
| 360 | |
| 361 | printk("%s \n", version); |
| 362 | printk("%s: %s. I/O at %hx, MMIO at %p, using irq %d\n",dev->name, |
| 363 | streamer_priv->streamer_card_name, |
| 364 | (unsigned int) dev->base_addr, |
| 365 | streamer_priv->streamer_mmio, |
| 366 | dev->irq); |
| 367 | |
| 368 | if (streamer_reset(dev)) |
| 369 | goto err_out_unmap; |
| 370 | |
| 371 | rc = register_netdev(dev); |
| 372 | if (rc) |
| 373 | goto err_out_unmap; |
| 374 | return 0; |
| 375 | |
| 376 | err_out_unmap: |
| 377 | iounmap(streamer_priv->streamer_mmio); |
| 378 | err_out_free_mmio: |
| 379 | release_mem_region(mmio_start, mmio_len); |
| 380 | err_out_free_pio: |
| 381 | release_region(pio_start, pio_len); |
| 382 | err_out_mwi: |
| 383 | pci_clear_mwi(pdev); |
| 384 | err_out_disable: |
| 385 | pci_disable_device(pdev); |
| 386 | err_out: |
| 387 | free_netdev(dev); |
| 388 | #if STREAMER_DEBUG |
| 389 | printk("lanstreamer: Exit error %x\n",rc); |
| 390 | #endif |
| 391 | return rc; |
| 392 | } |
| 393 | |
| 394 | static void __devexit streamer_remove_one(struct pci_dev *pdev) |
| 395 | { |
| 396 | struct net_device *dev=pci_get_drvdata(pdev); |
| 397 | struct streamer_private *streamer_priv; |
| 398 | |
| 399 | #if STREAMER_DEBUG |
| 400 | printk("lanstreamer::streamer_remove_one entry pdev %p\n",pdev); |
| 401 | #endif |
| 402 | |
| 403 | if (dev == NULL) { |
| 404 | printk(KERN_ERR "lanstreamer::streamer_remove_one, ERROR dev is NULL\n"); |
| 405 | return; |
| 406 | } |
| 407 | |
| 408 | streamer_priv=dev->priv; |
| 409 | if (streamer_priv == NULL) { |
| 410 | printk(KERN_ERR "lanstreamer::streamer_remove_one, ERROR dev->priv is NULL\n"); |
| 411 | return; |
| 412 | } |
| 413 | |
| 414 | #if STREAMER_NETWORK_MONITOR |
| 415 | #ifdef CONFIG_PROC_FS |
| 416 | { |
| 417 | struct streamer_private **p, **next; |
| 418 | |
| 419 | for (p = &dev_streamer; *p; p = next) { |
| 420 | next = &(*p)->next; |
| 421 | if (*p == streamer_priv) { |
| 422 | *p = *next; |
| 423 | break; |
| 424 | } |
| 425 | } |
| 426 | if (!dev_streamer) |
| 427 | remove_proc_entry("net/streamer_tr", NULL); |
| 428 | } |
| 429 | #endif |
| 430 | #endif |
| 431 | |
| 432 | unregister_netdev(dev); |
| 433 | iounmap(streamer_priv->streamer_mmio); |
| 434 | release_mem_region(pci_resource_start(pdev, 1), pci_resource_len(pdev,1)); |
| 435 | release_region(pci_resource_start(pdev, 0), pci_resource_len(pdev,0)); |
| 436 | pci_clear_mwi(pdev); |
| 437 | pci_disable_device(pdev); |
| 438 | free_netdev(dev); |
| 439 | pci_set_drvdata(pdev, NULL); |
| 440 | } |
| 441 | |
| 442 | |
| 443 | static int streamer_reset(struct net_device *dev) |
| 444 | { |
| 445 | struct streamer_private *streamer_priv; |
| 446 | __u8 __iomem *streamer_mmio; |
| 447 | unsigned long t; |
| 448 | unsigned int uaa_addr; |
| 449 | struct sk_buff *skb = NULL; |
| 450 | __u16 misr; |
| 451 | |
| 452 | streamer_priv = (struct streamer_private *) dev->priv; |
| 453 | streamer_mmio = streamer_priv->streamer_mmio; |
| 454 | |
| 455 | writew(readw(streamer_mmio + BCTL) | BCTL_SOFTRESET, streamer_mmio + BCTL); |
| 456 | t = jiffies; |
| 457 | /* Hold soft reset bit for a while */ |
Nishanth Aravamudan | 4f2ad81 | 2005-06-20 23:53:40 +0200 | [diff] [blame] | 458 | ssleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | writew(readw(streamer_mmio + BCTL) & ~BCTL_SOFTRESET, |
| 461 | streamer_mmio + BCTL); |
| 462 | |
| 463 | #if STREAMER_DEBUG |
| 464 | printk("BCTL: %x\n", readw(streamer_mmio + BCTL)); |
| 465 | printk("GPR: %x\n", readw(streamer_mmio + GPR)); |
| 466 | printk("SISRMASK: %x\n", readw(streamer_mmio + SISR_MASK)); |
| 467 | #endif |
| 468 | writew(readw(streamer_mmio + BCTL) | (BCTL_RX_FIFO_8 | BCTL_TX_FIFO_8), streamer_mmio + BCTL ); |
| 469 | |
| 470 | if (streamer_priv->streamer_ring_speed == 0) { /* Autosense */ |
| 471 | writew(readw(streamer_mmio + GPR) | GPR_AUTOSENSE, |
| 472 | streamer_mmio + GPR); |
| 473 | if (streamer_priv->streamer_message_level) |
| 474 | printk(KERN_INFO "%s: Ringspeed autosense mode on\n", |
| 475 | dev->name); |
| 476 | } else if (streamer_priv->streamer_ring_speed == 16) { |
| 477 | if (streamer_priv->streamer_message_level) |
| 478 | printk(KERN_INFO "%s: Trying to open at 16 Mbps as requested\n", |
| 479 | dev->name); |
| 480 | writew(GPR_16MBPS, streamer_mmio + GPR); |
| 481 | } else if (streamer_priv->streamer_ring_speed == 4) { |
| 482 | if (streamer_priv->streamer_message_level) |
| 483 | printk(KERN_INFO "%s: Trying to open at 4 Mbps as requested\n", |
| 484 | dev->name); |
| 485 | writew(0, streamer_mmio + GPR); |
| 486 | } |
| 487 | |
| 488 | skb = dev_alloc_skb(streamer_priv->pkt_buf_sz); |
| 489 | if (!skb) { |
| 490 | printk(KERN_INFO "%s: skb allocation for diagnostics failed...proceeding\n", |
| 491 | dev->name); |
| 492 | } else { |
| 493 | struct streamer_rx_desc *rx_ring; |
| 494 | u8 *data; |
| 495 | |
| 496 | rx_ring=(struct streamer_rx_desc *)skb->data; |
| 497 | data=((u8 *)skb->data)+sizeof(struct streamer_rx_desc); |
| 498 | rx_ring->forward=0; |
| 499 | rx_ring->status=0; |
| 500 | rx_ring->buffer=cpu_to_le32(pci_map_single(streamer_priv->pci_dev, data, |
| 501 | 512, PCI_DMA_FROMDEVICE)); |
| 502 | rx_ring->framelen_buflen=512; |
| 503 | writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, rx_ring, 512, PCI_DMA_FROMDEVICE)), |
| 504 | streamer_mmio+RXBDA); |
| 505 | } |
| 506 | |
| 507 | #if STREAMER_DEBUG |
| 508 | printk("GPR = %x\n", readw(streamer_mmio + GPR)); |
| 509 | #endif |
| 510 | /* start solo init */ |
| 511 | writew(SISR_MI, streamer_mmio + SISR_MASK_SUM); |
| 512 | |
| 513 | while (!((readw(streamer_mmio + SISR)) & SISR_SRB_REPLY)) { |
Nishanth Aravamudan | 4f2ad81 | 2005-06-20 23:53:40 +0200 | [diff] [blame] | 514 | msleep_interruptible(100); |
Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 515 | if (time_after(jiffies, t + 40 * HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | printk(KERN_ERR |
| 517 | "IBM PCI tokenring card not responding\n"); |
| 518 | release_region(dev->base_addr, STREAMER_IO_SPACE); |
| 519 | if (skb) |
| 520 | dev_kfree_skb(skb); |
| 521 | return -1; |
| 522 | } |
| 523 | } |
| 524 | writew(~SISR_SRB_REPLY, streamer_mmio + SISR_RUM); |
| 525 | misr = readw(streamer_mmio + MISR_RUM); |
| 526 | writew(~misr, streamer_mmio + MISR_RUM); |
| 527 | |
| 528 | if (skb) |
| 529 | dev_kfree_skb(skb); /* release skb used for diagnostics */ |
| 530 | |
| 531 | #if STREAMER_DEBUG |
| 532 | printk("LAPWWO: %x, LAPA: %x LAPE: %x\n", |
| 533 | readw(streamer_mmio + LAPWWO), readw(streamer_mmio + LAPA), |
| 534 | readw(streamer_mmio + LAPE)); |
| 535 | #endif |
| 536 | |
| 537 | #if STREAMER_DEBUG |
| 538 | { |
| 539 | int i; |
| 540 | writew(readw(streamer_mmio + LAPWWO), |
| 541 | streamer_mmio + LAPA); |
| 542 | printk("initialization response srb dump: "); |
| 543 | for (i = 0; i < 10; i++) |
| 544 | printk("%x:", |
| 545 | ntohs(readw(streamer_mmio + LAPDINC))); |
| 546 | printk("\n"); |
| 547 | } |
| 548 | #endif |
| 549 | |
| 550 | writew(readw(streamer_mmio + LAPWWO) + 6, streamer_mmio + LAPA); |
| 551 | if (readw(streamer_mmio + LAPD)) { |
| 552 | printk(KERN_INFO "tokenring card initialization failed. errorcode : %x\n", |
| 553 | ntohs(readw(streamer_mmio + LAPD))); |
| 554 | release_region(dev->base_addr, STREAMER_IO_SPACE); |
| 555 | return -1; |
| 556 | } |
| 557 | |
| 558 | writew(readw(streamer_mmio + LAPWWO) + 8, streamer_mmio + LAPA); |
| 559 | uaa_addr = ntohs(readw(streamer_mmio + LAPDINC)); |
| 560 | readw(streamer_mmio + LAPDINC); /* skip over Level.Addr field */ |
| 561 | streamer_priv->streamer_addr_table_addr = ntohs(readw(streamer_mmio + LAPDINC)); |
| 562 | streamer_priv->streamer_parms_addr = ntohs(readw(streamer_mmio + LAPDINC)); |
| 563 | |
| 564 | #if STREAMER_DEBUG |
| 565 | printk("UAA resides at %x\n", uaa_addr); |
| 566 | #endif |
| 567 | |
| 568 | /* setup uaa area for access with LAPD */ |
| 569 | { |
| 570 | int i; |
| 571 | __u16 addr; |
| 572 | writew(uaa_addr, streamer_mmio + LAPA); |
| 573 | for (i = 0; i < 6; i += 2) { |
| 574 | addr=ntohs(readw(streamer_mmio+LAPDINC)); |
| 575 | dev->dev_addr[i]= (addr >> 8) & 0xff; |
| 576 | dev->dev_addr[i+1]= addr & 0xff; |
| 577 | } |
| 578 | #if STREAMER_DEBUG |
| 579 | printk("Adapter address: "); |
| 580 | for (i = 0; i < 6; i++) { |
| 581 | printk("%02x:", dev->dev_addr[i]); |
| 582 | } |
| 583 | printk("\n"); |
| 584 | #endif |
| 585 | } |
| 586 | return 0; |
| 587 | } |
| 588 | |
| 589 | static int streamer_open(struct net_device *dev) |
| 590 | { |
| 591 | struct streamer_private *streamer_priv = (struct streamer_private *) dev->priv; |
| 592 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 593 | unsigned long flags; |
| 594 | char open_error[255]; |
| 595 | int i, open_finished = 1; |
| 596 | __u16 srb_word; |
| 597 | __u16 srb_open; |
| 598 | int rc; |
| 599 | |
| 600 | if (readw(streamer_mmio+BMCTL_SUM) & BMCTL_RX_ENABLED) { |
| 601 | rc=streamer_reset(dev); |
| 602 | } |
| 603 | |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 604 | if (request_irq(dev->irq, &streamer_interrupt, IRQF_SHARED, "lanstreamer", dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | return -EAGAIN; |
| 606 | } |
| 607 | #if STREAMER_DEBUG |
| 608 | printk("BMCTL: %x\n", readw(streamer_mmio + BMCTL_SUM)); |
| 609 | printk("pending ints: %x\n", readw(streamer_mmio + SISR)); |
| 610 | #endif |
| 611 | |
| 612 | writew(SISR_MI | SISR_SRB_REPLY, streamer_mmio + SISR_MASK); /* more ints later, doesn't stop arb cmd interrupt */ |
| 613 | writew(LISR_LIE, streamer_mmio + LISR); /* more ints later */ |
| 614 | |
| 615 | /* adapter is closed, so SRB is pointed to by LAPWWO */ |
| 616 | writew(readw(streamer_mmio + LAPWWO), streamer_mmio + LAPA); |
| 617 | |
| 618 | #if STREAMER_DEBUG |
| 619 | printk("LAPWWO: %x, LAPA: %x\n", readw(streamer_mmio + LAPWWO), |
| 620 | readw(streamer_mmio + LAPA)); |
| 621 | printk("LAPE: %x\n", readw(streamer_mmio + LAPE)); |
| 622 | printk("SISR Mask = %04x\n", readw(streamer_mmio + SISR_MASK)); |
| 623 | #endif |
| 624 | do { |
| 625 | int i; |
| 626 | |
| 627 | for (i = 0; i < SRB_COMMAND_SIZE; i += 2) { |
| 628 | writew(0, streamer_mmio + LAPDINC); |
| 629 | } |
| 630 | |
| 631 | writew(readw(streamer_mmio+LAPWWO),streamer_mmio+LAPA); |
| 632 | writew(htons(SRB_OPEN_ADAPTER<<8),streamer_mmio+LAPDINC) ; /* open */ |
| 633 | writew(htons(STREAMER_CLEAR_RET_CODE<<8),streamer_mmio+LAPDINC); |
| 634 | writew(STREAMER_CLEAR_RET_CODE, streamer_mmio + LAPDINC); |
| 635 | |
| 636 | writew(readw(streamer_mmio + LAPWWO) + 8, streamer_mmio + LAPA); |
| 637 | #if STREAMER_NETWORK_MONITOR |
| 638 | /* If Network Monitor, instruct card to copy MAC frames through the ARB */ |
| 639 | writew(htons(OPEN_ADAPTER_ENABLE_FDX | OPEN_ADAPTER_PASS_ADC_MAC | OPEN_ADAPTER_PASS_ATT_MAC | OPEN_ADAPTER_PASS_BEACON), streamer_mmio + LAPDINC); /* offset 8 word contains open options */ |
| 640 | #else |
| 641 | writew(htons(OPEN_ADAPTER_ENABLE_FDX), streamer_mmio + LAPDINC); /* Offset 8 word contains Open.Options */ |
| 642 | #endif |
| 643 | |
| 644 | if (streamer_priv->streamer_laa[0]) { |
| 645 | writew(readw(streamer_mmio + LAPWWO) + 12, streamer_mmio + LAPA); |
| 646 | writew(htons((streamer_priv->streamer_laa[0] << 8) | |
| 647 | streamer_priv->streamer_laa[1]),streamer_mmio+LAPDINC); |
| 648 | writew(htons((streamer_priv->streamer_laa[2] << 8) | |
| 649 | streamer_priv->streamer_laa[3]),streamer_mmio+LAPDINC); |
| 650 | writew(htons((streamer_priv->streamer_laa[4] << 8) | |
| 651 | streamer_priv->streamer_laa[5]),streamer_mmio+LAPDINC); |
| 652 | memcpy(dev->dev_addr, streamer_priv->streamer_laa, dev->addr_len); |
| 653 | } |
| 654 | |
| 655 | /* save off srb open offset */ |
| 656 | srb_open = readw(streamer_mmio + LAPWWO); |
| 657 | #if STREAMER_DEBUG |
| 658 | writew(readw(streamer_mmio + LAPWWO), |
| 659 | streamer_mmio + LAPA); |
| 660 | printk("srb open request: \n"); |
| 661 | for (i = 0; i < 16; i++) { |
| 662 | printk("%x:", ntohs(readw(streamer_mmio + LAPDINC))); |
| 663 | } |
| 664 | printk("\n"); |
| 665 | #endif |
| 666 | spin_lock_irqsave(&streamer_priv->streamer_lock, flags); |
| 667 | streamer_priv->srb_queued = 1; |
| 668 | |
| 669 | /* signal solo that SRB command has been issued */ |
| 670 | writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM); |
| 671 | spin_unlock_irqrestore(&streamer_priv->streamer_lock, flags); |
| 672 | |
| 673 | while (streamer_priv->srb_queued) { |
| 674 | interruptible_sleep_on_timeout(&streamer_priv->srb_wait, 5 * HZ); |
| 675 | if (signal_pending(current)) { |
| 676 | printk(KERN_WARNING "%s: SRB timed out.\n", dev->name); |
| 677 | printk(KERN_WARNING "SISR=%x MISR=%x, LISR=%x\n", |
| 678 | readw(streamer_mmio + SISR), |
| 679 | readw(streamer_mmio + MISR_RUM), |
| 680 | readw(streamer_mmio + LISR)); |
| 681 | streamer_priv->srb_queued = 0; |
| 682 | break; |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | #if STREAMER_DEBUG |
| 687 | printk("SISR_MASK: %x\n", readw(streamer_mmio + SISR_MASK)); |
| 688 | printk("srb open response:\n"); |
| 689 | writew(srb_open, streamer_mmio + LAPA); |
| 690 | for (i = 0; i < 10; i++) { |
| 691 | printk("%x:", |
| 692 | ntohs(readw(streamer_mmio + LAPDINC))); |
| 693 | } |
| 694 | #endif |
| 695 | |
| 696 | /* If we get the same return response as we set, the interrupt wasn't raised and the open |
| 697 | * timed out. |
| 698 | */ |
| 699 | writew(srb_open + 2, streamer_mmio + LAPA); |
| 700 | srb_word = ntohs(readw(streamer_mmio + LAPD)) >> 8; |
| 701 | if (srb_word == STREAMER_CLEAR_RET_CODE) { |
| 702 | printk(KERN_WARNING "%s: Adapter Open time out or error.\n", |
| 703 | dev->name); |
| 704 | return -EIO; |
| 705 | } |
| 706 | |
| 707 | if (srb_word != 0) { |
| 708 | if (srb_word == 0x07) { |
| 709 | if (!streamer_priv->streamer_ring_speed && open_finished) { /* Autosense , first time around */ |
| 710 | printk(KERN_WARNING "%s: Retrying at different ring speed \n", |
| 711 | dev->name); |
| 712 | open_finished = 0; |
| 713 | } else { |
| 714 | __u16 error_code; |
| 715 | |
| 716 | writew(srb_open + 6, streamer_mmio + LAPA); |
| 717 | error_code = ntohs(readw(streamer_mmio + LAPD)); |
| 718 | strcpy(open_error, open_maj_error[(error_code & 0xf0) >> 4]); |
| 719 | strcat(open_error, " - "); |
| 720 | strcat(open_error, open_min_error[(error_code & 0x0f)]); |
| 721 | |
| 722 | if (!streamer_priv->streamer_ring_speed |
| 723 | && ((error_code & 0x0f) == 0x0d)) |
| 724 | { |
| 725 | printk(KERN_WARNING "%s: Tried to autosense ring speed with no monitors present\n", dev->name); |
| 726 | printk(KERN_WARNING "%s: Please try again with a specified ring speed \n", dev->name); |
| 727 | free_irq(dev->irq, dev); |
| 728 | return -EIO; |
| 729 | } |
| 730 | |
| 731 | printk(KERN_WARNING "%s: %s\n", |
| 732 | dev->name, open_error); |
| 733 | free_irq(dev->irq, dev); |
| 734 | return -EIO; |
| 735 | |
| 736 | } /* if autosense && open_finished */ |
| 737 | } else { |
| 738 | printk(KERN_WARNING "%s: Bad OPEN response: %x\n", |
| 739 | dev->name, srb_word); |
| 740 | free_irq(dev->irq, dev); |
| 741 | return -EIO; |
| 742 | } |
| 743 | } else |
| 744 | open_finished = 1; |
| 745 | } while (!(open_finished)); /* Will only loop if ring speed mismatch re-open attempted && autosense is on */ |
| 746 | |
| 747 | writew(srb_open + 18, streamer_mmio + LAPA); |
| 748 | srb_word=ntohs(readw(streamer_mmio+LAPD)) >> 8; |
| 749 | if (srb_word & (1 << 3)) |
| 750 | if (streamer_priv->streamer_message_level) |
| 751 | printk(KERN_INFO "%s: Opened in FDX Mode\n", dev->name); |
| 752 | |
| 753 | if (srb_word & 1) |
| 754 | streamer_priv->streamer_ring_speed = 16; |
| 755 | else |
| 756 | streamer_priv->streamer_ring_speed = 4; |
| 757 | |
| 758 | if (streamer_priv->streamer_message_level) |
| 759 | printk(KERN_INFO "%s: Opened in %d Mbps mode\n", |
| 760 | dev->name, |
| 761 | streamer_priv->streamer_ring_speed); |
| 762 | |
| 763 | writew(srb_open + 8, streamer_mmio + LAPA); |
| 764 | streamer_priv->asb = ntohs(readw(streamer_mmio + LAPDINC)); |
| 765 | streamer_priv->srb = ntohs(readw(streamer_mmio + LAPDINC)); |
| 766 | streamer_priv->arb = ntohs(readw(streamer_mmio + LAPDINC)); |
| 767 | readw(streamer_mmio + LAPDINC); /* offset 14 word is rsvd */ |
| 768 | streamer_priv->trb = ntohs(readw(streamer_mmio + LAPDINC)); |
| 769 | |
| 770 | streamer_priv->streamer_receive_options = 0x00; |
| 771 | streamer_priv->streamer_copy_all_options = 0; |
| 772 | |
| 773 | /* setup rx ring */ |
| 774 | /* enable rx channel */ |
| 775 | writew(~BMCTL_RX_DIS, streamer_mmio + BMCTL_RUM); |
| 776 | |
| 777 | /* setup rx descriptors */ |
| 778 | streamer_priv->streamer_rx_ring= |
| 779 | kmalloc( sizeof(struct streamer_rx_desc)* |
| 780 | STREAMER_RX_RING_SIZE,GFP_KERNEL); |
| 781 | if (!streamer_priv->streamer_rx_ring) { |
| 782 | printk(KERN_WARNING "%s ALLOC of streamer rx ring FAILED!!\n",dev->name); |
| 783 | return -EIO; |
| 784 | } |
| 785 | |
| 786 | for (i = 0; i < STREAMER_RX_RING_SIZE; i++) { |
| 787 | struct sk_buff *skb; |
| 788 | |
| 789 | skb = dev_alloc_skb(streamer_priv->pkt_buf_sz); |
| 790 | if (skb == NULL) |
| 791 | break; |
| 792 | |
| 793 | skb->dev = dev; |
| 794 | |
| 795 | streamer_priv->streamer_rx_ring[i].forward = |
| 796 | cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[i + 1], |
| 797 | sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE)); |
| 798 | streamer_priv->streamer_rx_ring[i].status = 0; |
| 799 | streamer_priv->streamer_rx_ring[i].buffer = |
| 800 | cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data, |
| 801 | streamer_priv->pkt_buf_sz, PCI_DMA_FROMDEVICE)); |
| 802 | streamer_priv->streamer_rx_ring[i].framelen_buflen = streamer_priv->pkt_buf_sz; |
| 803 | streamer_priv->rx_ring_skb[i] = skb; |
| 804 | } |
| 805 | streamer_priv->streamer_rx_ring[STREAMER_RX_RING_SIZE - 1].forward = |
| 806 | cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[0], |
| 807 | sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE)); |
| 808 | |
| 809 | if (i == 0) { |
| 810 | printk(KERN_WARNING "%s: Not enough memory to allocate rx buffers. Adapter disabled\n", dev->name); |
| 811 | free_irq(dev->irq, dev); |
| 812 | return -EIO; |
| 813 | } |
| 814 | |
| 815 | streamer_priv->rx_ring_last_received = STREAMER_RX_RING_SIZE - 1; /* last processed rx status */ |
| 816 | |
| 817 | writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[0], |
| 818 | sizeof(struct streamer_rx_desc), PCI_DMA_TODEVICE)), |
| 819 | streamer_mmio + RXBDA); |
| 820 | writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_rx_ring[STREAMER_RX_RING_SIZE - 1], |
| 821 | sizeof(struct streamer_rx_desc), PCI_DMA_TODEVICE)), |
| 822 | streamer_mmio + RXLBDA); |
| 823 | |
| 824 | /* set bus master interrupt event mask */ |
| 825 | writew(MISR_RX_NOBUF | MISR_RX_EOF, streamer_mmio + MISR_MASK); |
| 826 | |
| 827 | |
| 828 | /* setup tx ring */ |
| 829 | streamer_priv->streamer_tx_ring=kmalloc(sizeof(struct streamer_tx_desc)* |
| 830 | STREAMER_TX_RING_SIZE,GFP_KERNEL); |
| 831 | if (!streamer_priv->streamer_tx_ring) { |
| 832 | printk(KERN_WARNING "%s ALLOC of streamer_tx_ring FAILED\n",dev->name); |
| 833 | return -EIO; |
| 834 | } |
| 835 | |
| 836 | writew(~BMCTL_TX2_DIS, streamer_mmio + BMCTL_RUM); /* Enables TX channel 2 */ |
| 837 | for (i = 0; i < STREAMER_TX_RING_SIZE; i++) { |
| 838 | streamer_priv->streamer_tx_ring[i].forward = cpu_to_le32(pci_map_single(streamer_priv->pci_dev, |
| 839 | &streamer_priv->streamer_tx_ring[i + 1], |
| 840 | sizeof(struct streamer_tx_desc), |
| 841 | PCI_DMA_TODEVICE)); |
| 842 | streamer_priv->streamer_tx_ring[i].status = 0; |
| 843 | streamer_priv->streamer_tx_ring[i].bufcnt_framelen = 0; |
| 844 | streamer_priv->streamer_tx_ring[i].buffer = 0; |
| 845 | streamer_priv->streamer_tx_ring[i].buflen = 0; |
| 846 | streamer_priv->streamer_tx_ring[i].rsvd1 = 0; |
| 847 | streamer_priv->streamer_tx_ring[i].rsvd2 = 0; |
| 848 | streamer_priv->streamer_tx_ring[i].rsvd3 = 0; |
| 849 | } |
| 850 | streamer_priv->streamer_tx_ring[STREAMER_TX_RING_SIZE - 1].forward = |
| 851 | cpu_to_le32(pci_map_single(streamer_priv->pci_dev, &streamer_priv->streamer_tx_ring[0], |
| 852 | sizeof(struct streamer_tx_desc), PCI_DMA_TODEVICE)); |
| 853 | |
| 854 | streamer_priv->free_tx_ring_entries = STREAMER_TX_RING_SIZE; |
| 855 | streamer_priv->tx_ring_free = 0; /* next entry in tx ring to use */ |
| 856 | streamer_priv->tx_ring_last_status = STREAMER_TX_RING_SIZE - 1; |
| 857 | |
| 858 | /* set Busmaster interrupt event mask (handle receives on interrupt only */ |
| 859 | writew(MISR_TX2_EOF | MISR_RX_NOBUF | MISR_RX_EOF, streamer_mmio + MISR_MASK); |
| 860 | /* set system event interrupt mask */ |
| 861 | writew(SISR_ADAPTER_CHECK | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_ASB_FREE, streamer_mmio + SISR_MASK_SUM); |
| 862 | |
| 863 | #if STREAMER_DEBUG |
| 864 | printk("BMCTL: %x\n", readw(streamer_mmio + BMCTL_SUM)); |
| 865 | printk("SISR MASK: %x\n", readw(streamer_mmio + SISR_MASK)); |
| 866 | #endif |
| 867 | |
| 868 | #if STREAMER_NETWORK_MONITOR |
| 869 | |
| 870 | writew(streamer_priv->streamer_addr_table_addr, streamer_mmio + LAPA); |
| 871 | printk("%s: Node Address: %04x:%04x:%04x\n", dev->name, |
| 872 | ntohs(readw(streamer_mmio + LAPDINC)), |
| 873 | ntohs(readw(streamer_mmio + LAPDINC)), |
| 874 | ntohs(readw(streamer_mmio + LAPDINC))); |
| 875 | readw(streamer_mmio + LAPDINC); |
| 876 | readw(streamer_mmio + LAPDINC); |
| 877 | printk("%s: Functional Address: %04x:%04x\n", dev->name, |
| 878 | ntohs(readw(streamer_mmio + LAPDINC)), |
| 879 | ntohs(readw(streamer_mmio + LAPDINC))); |
| 880 | |
| 881 | writew(streamer_priv->streamer_parms_addr + 4, |
| 882 | streamer_mmio + LAPA); |
| 883 | printk("%s: NAUN Address: %04x:%04x:%04x\n", dev->name, |
| 884 | ntohs(readw(streamer_mmio + LAPDINC)), |
| 885 | ntohs(readw(streamer_mmio + LAPDINC)), |
| 886 | ntohs(readw(streamer_mmio + LAPDINC))); |
| 887 | #endif |
| 888 | |
| 889 | netif_start_queue(dev); |
| 890 | netif_carrier_on(dev); |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | * When we enter the rx routine we do not know how many frames have been |
| 896 | * queued on the rx channel. Therefore we start at the next rx status |
| 897 | * position and travel around the receive ring until we have completed |
| 898 | * all the frames. |
| 899 | * |
| 900 | * This means that we may process the frame before we receive the end |
| 901 | * of frame interrupt. This is why we always test the status instead |
| 902 | * of blindly processing the next frame. |
| 903 | * |
| 904 | */ |
| 905 | static void streamer_rx(struct net_device *dev) |
| 906 | { |
| 907 | struct streamer_private *streamer_priv = |
| 908 | (struct streamer_private *) dev->priv; |
| 909 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 910 | struct streamer_rx_desc *rx_desc; |
| 911 | int rx_ring_last_received, length, frame_length, buffer_cnt = 0; |
| 912 | struct sk_buff *skb, *skb2; |
| 913 | |
| 914 | /* setup the next rx descriptor to be received */ |
| 915 | rx_desc = &streamer_priv->streamer_rx_ring[(streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1)]; |
| 916 | rx_ring_last_received = streamer_priv->rx_ring_last_received; |
| 917 | |
| 918 | while (rx_desc->status & 0x01000000) { /* While processed descriptors are available */ |
| 919 | if (rx_ring_last_received != streamer_priv->rx_ring_last_received) |
| 920 | { |
| 921 | printk(KERN_WARNING "RX Error 1 rx_ring_last_received not the same %x %x\n", |
| 922 | rx_ring_last_received, streamer_priv->rx_ring_last_received); |
| 923 | } |
| 924 | streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1); |
| 925 | rx_ring_last_received = streamer_priv->rx_ring_last_received; |
| 926 | |
| 927 | length = rx_desc->framelen_buflen & 0xffff; /* buffer length */ |
| 928 | frame_length = (rx_desc->framelen_buflen >> 16) & 0xffff; |
| 929 | |
| 930 | if (rx_desc->status & 0x7E830000) { /* errors */ |
| 931 | if (streamer_priv->streamer_message_level) { |
| 932 | printk(KERN_WARNING "%s: Rx Error %x \n", |
| 933 | dev->name, rx_desc->status); |
| 934 | } |
| 935 | } else { /* received without errors */ |
| 936 | if (rx_desc->status & 0x80000000) { /* frame complete */ |
| 937 | buffer_cnt = 1; |
| 938 | skb = dev_alloc_skb(streamer_priv->pkt_buf_sz); |
| 939 | } else { |
| 940 | skb = dev_alloc_skb(frame_length); |
| 941 | } |
| 942 | |
| 943 | if (skb == NULL) |
| 944 | { |
| 945 | printk(KERN_WARNING "%s: Not enough memory to copy packet to upper layers. \n", dev->name); |
| 946 | streamer_priv->streamer_stats.rx_dropped++; |
| 947 | } else { /* we allocated an skb OK */ |
| 948 | skb->dev = dev; |
| 949 | |
| 950 | if (buffer_cnt == 1) { |
| 951 | /* release the DMA mapping */ |
| 952 | pci_unmap_single(streamer_priv->pci_dev, |
| 953 | le32_to_cpu(streamer_priv->streamer_rx_ring[rx_ring_last_received].buffer), |
| 954 | streamer_priv->pkt_buf_sz, |
| 955 | PCI_DMA_FROMDEVICE); |
| 956 | skb2 = streamer_priv->rx_ring_skb[rx_ring_last_received]; |
| 957 | #if STREAMER_DEBUG_PACKETS |
| 958 | { |
| 959 | int i; |
| 960 | printk("streamer_rx packet print: skb->data2 %p skb->head %p\n", skb2->data, skb2->head); |
| 961 | for (i = 0; i < frame_length; i++) |
| 962 | { |
| 963 | printk("%x:", skb2->data[i]); |
| 964 | if (((i + 1) % 16) == 0) |
| 965 | printk("\n"); |
| 966 | } |
| 967 | printk("\n"); |
| 968 | } |
| 969 | #endif |
| 970 | skb_put(skb2, length); |
| 971 | skb2->protocol = tr_type_trans(skb2, dev); |
| 972 | /* recycle this descriptor */ |
| 973 | streamer_priv->streamer_rx_ring[rx_ring_last_received].status = 0; |
| 974 | streamer_priv->streamer_rx_ring[rx_ring_last_received].framelen_buflen = streamer_priv->pkt_buf_sz; |
| 975 | streamer_priv->streamer_rx_ring[rx_ring_last_received].buffer = |
| 976 | cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data, streamer_priv->pkt_buf_sz, |
| 977 | PCI_DMA_FROMDEVICE)); |
| 978 | streamer_priv->rx_ring_skb[rx_ring_last_received] = skb; |
| 979 | /* place recycled descriptor back on the adapter */ |
| 980 | writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, |
| 981 | &streamer_priv->streamer_rx_ring[rx_ring_last_received], |
| 982 | sizeof(struct streamer_rx_desc), PCI_DMA_FROMDEVICE)), |
| 983 | streamer_mmio + RXLBDA); |
| 984 | /* pass the received skb up to the protocol */ |
| 985 | netif_rx(skb2); |
| 986 | } else { |
| 987 | do { /* Walk the buffers */ |
| 988 | pci_unmap_single(streamer_priv->pci_dev, le32_to_cpu(rx_desc->buffer), length, PCI_DMA_FROMDEVICE), |
| 989 | memcpy(skb_put(skb, length), (void *)rx_desc->buffer, length); /* copy this fragment */ |
| 990 | streamer_priv->streamer_rx_ring[rx_ring_last_received].status = 0; |
| 991 | streamer_priv->streamer_rx_ring[rx_ring_last_received].framelen_buflen = streamer_priv->pkt_buf_sz; |
| 992 | |
| 993 | /* give descriptor back to the adapter */ |
| 994 | writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, |
| 995 | &streamer_priv->streamer_rx_ring[rx_ring_last_received], |
| 996 | length, PCI_DMA_FROMDEVICE)), |
| 997 | streamer_mmio + RXLBDA); |
| 998 | |
| 999 | if (rx_desc->status & 0x80000000) |
| 1000 | break; /* this descriptor completes the frame */ |
| 1001 | |
| 1002 | /* else get the next pending descriptor */ |
| 1003 | if (rx_ring_last_received!= streamer_priv->rx_ring_last_received) |
| 1004 | { |
| 1005 | printk("RX Error rx_ring_last_received not the same %x %x\n", |
| 1006 | rx_ring_last_received, |
| 1007 | streamer_priv->rx_ring_last_received); |
| 1008 | } |
| 1009 | rx_desc = &streamer_priv->streamer_rx_ring[(streamer_priv->rx_ring_last_received+1) & (STREAMER_RX_RING_SIZE-1)]; |
| 1010 | |
| 1011 | length = rx_desc->framelen_buflen & 0xffff; /* buffer length */ |
| 1012 | streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received+1) & (STREAMER_RX_RING_SIZE - 1); |
| 1013 | rx_ring_last_received = streamer_priv->rx_ring_last_received; |
| 1014 | } while (1); |
| 1015 | |
| 1016 | skb->protocol = tr_type_trans(skb, dev); |
| 1017 | /* send up to the protocol */ |
| 1018 | netif_rx(skb); |
| 1019 | } |
| 1020 | dev->last_rx = jiffies; |
| 1021 | streamer_priv->streamer_stats.rx_packets++; |
| 1022 | streamer_priv->streamer_stats.rx_bytes += length; |
| 1023 | } /* if skb == null */ |
| 1024 | } /* end received without errors */ |
| 1025 | |
| 1026 | /* try the next one */ |
| 1027 | rx_desc = &streamer_priv->streamer_rx_ring[(rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1)]; |
| 1028 | } /* end for all completed rx descriptors */ |
| 1029 | } |
| 1030 | |
| 1031 | static irqreturn_t streamer_interrupt(int irq, void *dev_id, struct pt_regs *regs) |
| 1032 | { |
| 1033 | struct net_device *dev = (struct net_device *) dev_id; |
| 1034 | struct streamer_private *streamer_priv = |
| 1035 | (struct streamer_private *) dev->priv; |
| 1036 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1037 | __u16 sisr; |
| 1038 | __u16 misr; |
| 1039 | u8 max_intr = MAX_INTR; |
| 1040 | |
| 1041 | spin_lock(&streamer_priv->streamer_lock); |
| 1042 | sisr = readw(streamer_mmio + SISR); |
| 1043 | |
| 1044 | while((sisr & (SISR_MI | SISR_SRB_REPLY | SISR_ADAPTER_CHECK | SISR_ASB_FREE | |
| 1045 | SISR_ARB_CMD | SISR_TRB_REPLY | SISR_PAR_ERR | SISR_SERR_ERR)) |
| 1046 | && (max_intr > 0)) { |
| 1047 | |
| 1048 | if(sisr & SISR_PAR_ERR) { |
| 1049 | writew(~SISR_PAR_ERR, streamer_mmio + SISR_RUM); |
| 1050 | (void)readw(streamer_mmio + SISR_RUM); |
| 1051 | } |
| 1052 | |
| 1053 | else if(sisr & SISR_SERR_ERR) { |
| 1054 | writew(~SISR_SERR_ERR, streamer_mmio + SISR_RUM); |
| 1055 | (void)readw(streamer_mmio + SISR_RUM); |
| 1056 | } |
| 1057 | |
| 1058 | else if(sisr & SISR_MI) { |
| 1059 | misr = readw(streamer_mmio + MISR_RUM); |
| 1060 | |
| 1061 | if (misr & MISR_TX2_EOF) { |
| 1062 | while(streamer_priv->streamer_tx_ring[(streamer_priv->tx_ring_last_status + 1) & (STREAMER_TX_RING_SIZE - 1)].status) { |
| 1063 | streamer_priv->tx_ring_last_status = (streamer_priv->tx_ring_last_status + 1) & (STREAMER_TX_RING_SIZE - 1); |
| 1064 | streamer_priv->free_tx_ring_entries++; |
| 1065 | streamer_priv->streamer_stats.tx_bytes += streamer_priv->tx_ring_skb[streamer_priv->tx_ring_last_status]->len; |
| 1066 | streamer_priv->streamer_stats.tx_packets++; |
| 1067 | dev_kfree_skb_irq(streamer_priv->tx_ring_skb[streamer_priv->tx_ring_last_status]); |
| 1068 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].buffer = 0xdeadbeef; |
| 1069 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].status = 0; |
| 1070 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].bufcnt_framelen = 0; |
| 1071 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].buflen = 0; |
| 1072 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd1 = 0; |
| 1073 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd2 = 0; |
| 1074 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_last_status].rsvd3 = 0; |
| 1075 | } |
| 1076 | netif_wake_queue(dev); |
| 1077 | } |
| 1078 | |
| 1079 | if (misr & MISR_RX_EOF) { |
| 1080 | streamer_rx(dev); |
| 1081 | } |
| 1082 | /* MISR_RX_EOF */ |
| 1083 | |
| 1084 | if (misr & MISR_RX_NOBUF) { |
| 1085 | /* According to the documentation, we don't have to do anything, |
| 1086 | * but trapping it keeps it out of /var/log/messages. |
| 1087 | */ |
| 1088 | } /* SISR_RX_NOBUF */ |
| 1089 | |
| 1090 | writew(~misr, streamer_mmio + MISR_RUM); |
| 1091 | (void)readw(streamer_mmio + MISR_RUM); |
| 1092 | } |
| 1093 | |
| 1094 | else if (sisr & SISR_SRB_REPLY) { |
| 1095 | if (streamer_priv->srb_queued == 1) { |
| 1096 | wake_up_interruptible(&streamer_priv->srb_wait); |
| 1097 | } else if (streamer_priv->srb_queued == 2) { |
| 1098 | streamer_srb_bh(dev); |
| 1099 | } |
| 1100 | streamer_priv->srb_queued = 0; |
| 1101 | |
| 1102 | writew(~SISR_SRB_REPLY, streamer_mmio + SISR_RUM); |
| 1103 | (void)readw(streamer_mmio + SISR_RUM); |
| 1104 | } |
| 1105 | |
| 1106 | else if (sisr & SISR_ADAPTER_CHECK) { |
| 1107 | printk(KERN_WARNING "%s: Adapter Check Interrupt Raised, 8 bytes of information follow:\n", dev->name); |
| 1108 | writel(readl(streamer_mmio + LAPWWO), streamer_mmio + LAPA); |
| 1109 | printk(KERN_WARNING "%s: Words %x:%x:%x:%x:\n", |
| 1110 | dev->name, readw(streamer_mmio + LAPDINC), |
| 1111 | ntohs(readw(streamer_mmio + LAPDINC)), |
| 1112 | ntohs(readw(streamer_mmio + LAPDINC)), |
| 1113 | ntohs(readw(streamer_mmio + LAPDINC))); |
| 1114 | netif_stop_queue(dev); |
| 1115 | netif_carrier_off(dev); |
| 1116 | printk(KERN_WARNING "%s: Adapter must be manually reset.\n", dev->name); |
| 1117 | } |
| 1118 | |
| 1119 | /* SISR_ADAPTER_CHECK */ |
| 1120 | else if (sisr & SISR_ASB_FREE) { |
| 1121 | /* Wake up anything that is waiting for the asb response */ |
| 1122 | if (streamer_priv->asb_queued) { |
| 1123 | streamer_asb_bh(dev); |
| 1124 | } |
| 1125 | writew(~SISR_ASB_FREE, streamer_mmio + SISR_RUM); |
| 1126 | (void)readw(streamer_mmio + SISR_RUM); |
| 1127 | } |
| 1128 | /* SISR_ASB_FREE */ |
| 1129 | else if (sisr & SISR_ARB_CMD) { |
| 1130 | streamer_arb_cmd(dev); |
| 1131 | writew(~SISR_ARB_CMD, streamer_mmio + SISR_RUM); |
| 1132 | (void)readw(streamer_mmio + SISR_RUM); |
| 1133 | } |
| 1134 | /* SISR_ARB_CMD */ |
| 1135 | else if (sisr & SISR_TRB_REPLY) { |
| 1136 | /* Wake up anything that is waiting for the trb response */ |
| 1137 | if (streamer_priv->trb_queued) { |
| 1138 | wake_up_interruptible(&streamer_priv-> |
| 1139 | trb_wait); |
| 1140 | } |
| 1141 | streamer_priv->trb_queued = 0; |
| 1142 | writew(~SISR_TRB_REPLY, streamer_mmio + SISR_RUM); |
| 1143 | (void)readw(streamer_mmio + SISR_RUM); |
| 1144 | } |
| 1145 | /* SISR_TRB_REPLY */ |
| 1146 | |
| 1147 | sisr = readw(streamer_mmio + SISR); |
| 1148 | max_intr--; |
| 1149 | } /* while() */ |
| 1150 | |
| 1151 | spin_unlock(&streamer_priv->streamer_lock) ; |
| 1152 | return IRQ_HANDLED; |
| 1153 | } |
| 1154 | |
| 1155 | static int streamer_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1156 | { |
| 1157 | struct streamer_private *streamer_priv = |
| 1158 | (struct streamer_private *) dev->priv; |
| 1159 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1160 | unsigned long flags ; |
| 1161 | |
| 1162 | spin_lock_irqsave(&streamer_priv->streamer_lock, flags); |
| 1163 | |
| 1164 | if (streamer_priv->free_tx_ring_entries) { |
| 1165 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].status = 0; |
| 1166 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].bufcnt_framelen = 0x00020000 | skb->len; |
| 1167 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].buffer = |
| 1168 | cpu_to_le32(pci_map_single(streamer_priv->pci_dev, skb->data, skb->len, PCI_DMA_TODEVICE)); |
| 1169 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd1 = skb->len; |
| 1170 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd2 = 0; |
| 1171 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].rsvd3 = 0; |
| 1172 | streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free].buflen = skb->len; |
| 1173 | |
| 1174 | streamer_priv->tx_ring_skb[streamer_priv->tx_ring_free] = skb; |
| 1175 | streamer_priv->free_tx_ring_entries--; |
| 1176 | #if STREAMER_DEBUG_PACKETS |
| 1177 | { |
| 1178 | int i; |
| 1179 | printk("streamer_xmit packet print:\n"); |
| 1180 | for (i = 0; i < skb->len; i++) { |
| 1181 | printk("%x:", skb->data[i]); |
| 1182 | if (((i + 1) % 16) == 0) |
| 1183 | printk("\n"); |
| 1184 | } |
| 1185 | printk("\n"); |
| 1186 | } |
| 1187 | #endif |
| 1188 | |
| 1189 | writel(cpu_to_le32(pci_map_single(streamer_priv->pci_dev, |
| 1190 | &streamer_priv->streamer_tx_ring[streamer_priv->tx_ring_free], |
| 1191 | sizeof(struct streamer_tx_desc), PCI_DMA_TODEVICE)), |
| 1192 | streamer_mmio + TX2LFDA); |
| 1193 | (void)readl(streamer_mmio + TX2LFDA); |
| 1194 | |
| 1195 | streamer_priv->tx_ring_free = (streamer_priv->tx_ring_free + 1) & (STREAMER_TX_RING_SIZE - 1); |
| 1196 | spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags); |
| 1197 | return 0; |
| 1198 | } else { |
| 1199 | netif_stop_queue(dev); |
| 1200 | spin_unlock_irqrestore(&streamer_priv->streamer_lock,flags); |
| 1201 | return 1; |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | |
| 1206 | static int streamer_close(struct net_device *dev) |
| 1207 | { |
| 1208 | struct streamer_private *streamer_priv = |
| 1209 | (struct streamer_private *) dev->priv; |
| 1210 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1211 | unsigned long flags; |
| 1212 | int i; |
| 1213 | |
| 1214 | netif_stop_queue(dev); |
| 1215 | netif_carrier_off(dev); |
| 1216 | writew(streamer_priv->srb, streamer_mmio + LAPA); |
| 1217 | writew(htons(SRB_CLOSE_ADAPTER << 8),streamer_mmio+LAPDINC); |
| 1218 | writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC); |
| 1219 | |
| 1220 | spin_lock_irqsave(&streamer_priv->streamer_lock, flags); |
| 1221 | |
| 1222 | streamer_priv->srb_queued = 1; |
| 1223 | writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM); |
| 1224 | |
| 1225 | spin_unlock_irqrestore(&streamer_priv->streamer_lock, flags); |
| 1226 | |
| 1227 | while (streamer_priv->srb_queued) |
| 1228 | { |
| 1229 | interruptible_sleep_on_timeout(&streamer_priv->srb_wait, |
| 1230 | jiffies + 60 * HZ); |
| 1231 | if (signal_pending(current)) |
| 1232 | { |
| 1233 | printk(KERN_WARNING "%s: SRB timed out.\n", dev->name); |
| 1234 | printk(KERN_WARNING "SISR=%x MISR=%x LISR=%x\n", |
| 1235 | readw(streamer_mmio + SISR), |
| 1236 | readw(streamer_mmio + MISR_RUM), |
| 1237 | readw(streamer_mmio + LISR)); |
| 1238 | streamer_priv->srb_queued = 0; |
| 1239 | break; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1); |
| 1244 | |
| 1245 | for (i = 0; i < STREAMER_RX_RING_SIZE; i++) { |
| 1246 | if (streamer_priv->rx_ring_skb[streamer_priv->rx_ring_last_received]) { |
| 1247 | dev_kfree_skb(streamer_priv->rx_ring_skb[streamer_priv->rx_ring_last_received]); |
| 1248 | } |
| 1249 | streamer_priv->rx_ring_last_received = (streamer_priv->rx_ring_last_received + 1) & (STREAMER_RX_RING_SIZE - 1); |
| 1250 | } |
| 1251 | |
| 1252 | /* reset tx/rx fifo's and busmaster logic */ |
| 1253 | |
| 1254 | /* TBD. Add graceful way to reset the LLC channel without doing a soft reset. |
| 1255 | writel(readl(streamer_mmio+BCTL)|(3<<13),streamer_mmio+BCTL); |
| 1256 | udelay(1); |
| 1257 | writel(readl(streamer_mmio+BCTL)&~(3<<13),streamer_mmio+BCTL); |
| 1258 | */ |
| 1259 | |
| 1260 | #if STREAMER_DEBUG |
| 1261 | writew(streamer_priv->srb, streamer_mmio + LAPA); |
| 1262 | printk("srb): "); |
| 1263 | for (i = 0; i < 2; i++) { |
| 1264 | printk("%x ", ntohs(readw(streamer_mmio + LAPDINC))); |
| 1265 | } |
| 1266 | printk("\n"); |
| 1267 | #endif |
| 1268 | free_irq(dev->irq, dev); |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
| 1272 | static void streamer_set_rx_mode(struct net_device *dev) |
| 1273 | { |
| 1274 | struct streamer_private *streamer_priv = |
| 1275 | (struct streamer_private *) dev->priv; |
| 1276 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1277 | __u8 options = 0; |
| 1278 | struct dev_mc_list *dmi; |
| 1279 | unsigned char dev_mc_address[5]; |
| 1280 | int i; |
| 1281 | |
| 1282 | writel(streamer_priv->srb, streamer_mmio + LAPA); |
| 1283 | options = streamer_priv->streamer_copy_all_options; |
| 1284 | |
| 1285 | if (dev->flags & IFF_PROMISC) |
| 1286 | options |= (3 << 5); /* All LLC and MAC frames, all through the main rx channel */ |
| 1287 | else |
| 1288 | options &= ~(3 << 5); |
| 1289 | |
| 1290 | /* Only issue the srb if there is a change in options */ |
| 1291 | |
| 1292 | if ((options ^ streamer_priv->streamer_copy_all_options)) |
| 1293 | { |
| 1294 | /* Now to issue the srb command to alter the copy.all.options */ |
| 1295 | writew(htons(SRB_MODIFY_RECEIVE_OPTIONS << 8), streamer_mmio+LAPDINC); |
| 1296 | writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC); |
| 1297 | writew(htons((streamer_priv->streamer_receive_options << 8) | options),streamer_mmio+LAPDINC); |
| 1298 | writew(htons(0x4a41),streamer_mmio+LAPDINC); |
| 1299 | writew(htons(0x4d45),streamer_mmio+LAPDINC); |
| 1300 | writew(htons(0x5320),streamer_mmio+LAPDINC); |
| 1301 | writew(0x2020, streamer_mmio + LAPDINC); |
| 1302 | |
| 1303 | streamer_priv->srb_queued = 2; /* Can't sleep, use srb_bh */ |
| 1304 | |
| 1305 | writel(LISR_SRB_CMD, streamer_mmio + LISR_SUM); |
| 1306 | |
| 1307 | streamer_priv->streamer_copy_all_options = options; |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | /* Set the functional addresses we need for multicast */ |
| 1312 | writel(streamer_priv->srb,streamer_mmio+LAPA); |
| 1313 | dev_mc_address[0] = dev_mc_address[1] = dev_mc_address[2] = dev_mc_address[3] = 0 ; |
| 1314 | |
| 1315 | for (i=0,dmi=dev->mc_list;i < dev->mc_count; i++,dmi = dmi->next) |
| 1316 | { |
| 1317 | dev_mc_address[0] |= dmi->dmi_addr[2] ; |
| 1318 | dev_mc_address[1] |= dmi->dmi_addr[3] ; |
| 1319 | dev_mc_address[2] |= dmi->dmi_addr[4] ; |
| 1320 | dev_mc_address[3] |= dmi->dmi_addr[5] ; |
| 1321 | } |
| 1322 | |
| 1323 | writew(htons(SRB_SET_FUNC_ADDRESS << 8),streamer_mmio+LAPDINC); |
| 1324 | writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC); |
| 1325 | writew(0,streamer_mmio+LAPDINC); |
| 1326 | writew(htons( (dev_mc_address[0] << 8) | dev_mc_address[1]),streamer_mmio+LAPDINC); |
| 1327 | writew(htons( (dev_mc_address[2] << 8) | dev_mc_address[3]),streamer_mmio+LAPDINC); |
| 1328 | streamer_priv->srb_queued = 2 ; |
| 1329 | writel(LISR_SRB_CMD,streamer_mmio+LISR_SUM); |
| 1330 | } |
| 1331 | |
| 1332 | static void streamer_srb_bh(struct net_device *dev) |
| 1333 | { |
| 1334 | struct streamer_private *streamer_priv = (struct streamer_private *) dev->priv; |
| 1335 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1336 | __u16 srb_word; |
| 1337 | |
| 1338 | writew(streamer_priv->srb, streamer_mmio + LAPA); |
| 1339 | srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; |
| 1340 | |
| 1341 | switch (srb_word) { |
| 1342 | |
| 1343 | /* SRB_MODIFY_RECEIVE_OPTIONS i.e. set_multicast_list options (promiscuous) |
| 1344 | * At some point we should do something if we get an error, such as |
| 1345 | * resetting the IFF_PROMISC flag in dev |
| 1346 | */ |
| 1347 | |
| 1348 | case SRB_MODIFY_RECEIVE_OPTIONS: |
| 1349 | srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; |
| 1350 | |
| 1351 | switch (srb_word) { |
| 1352 | case 0x01: |
| 1353 | printk(KERN_WARNING "%s: Unrecognized srb command\n", dev->name); |
| 1354 | break; |
| 1355 | case 0x04: |
| 1356 | printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name); |
| 1357 | break; |
| 1358 | default: |
| 1359 | if (streamer_priv->streamer_message_level) |
| 1360 | printk(KERN_WARNING "%s: Receive Options Modified to %x,%x\n", |
| 1361 | dev->name, |
| 1362 | streamer_priv->streamer_copy_all_options, |
| 1363 | streamer_priv->streamer_receive_options); |
| 1364 | break; |
| 1365 | } /* switch srb[2] */ |
| 1366 | break; |
| 1367 | |
| 1368 | |
| 1369 | /* SRB_SET_GROUP_ADDRESS - Multicast group setting |
| 1370 | */ |
| 1371 | case SRB_SET_GROUP_ADDRESS: |
| 1372 | srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; |
| 1373 | switch (srb_word) { |
| 1374 | case 0x00: |
| 1375 | break; |
| 1376 | case 0x01: |
| 1377 | printk(KERN_WARNING "%s: Unrecognized srb command \n",dev->name); |
| 1378 | break; |
| 1379 | case 0x04: |
| 1380 | printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name); |
| 1381 | break; |
| 1382 | case 0x3c: |
| 1383 | printk(KERN_WARNING "%s: Group/Functional address indicator bits not set correctly\n", dev->name); |
| 1384 | break; |
| 1385 | case 0x3e: /* If we ever implement individual multicast addresses, will need to deal with this */ |
| 1386 | printk(KERN_WARNING "%s: Group address registers full\n", dev->name); |
| 1387 | break; |
| 1388 | case 0x55: |
| 1389 | printk(KERN_INFO "%s: Group Address already set.\n", dev->name); |
| 1390 | break; |
| 1391 | default: |
| 1392 | break; |
| 1393 | } /* switch srb[2] */ |
| 1394 | break; |
| 1395 | |
| 1396 | |
| 1397 | /* SRB_RESET_GROUP_ADDRESS - Remove a multicast address from group list |
| 1398 | */ |
| 1399 | case SRB_RESET_GROUP_ADDRESS: |
| 1400 | srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; |
| 1401 | switch (srb_word) { |
| 1402 | case 0x00: |
| 1403 | break; |
| 1404 | case 0x01: |
| 1405 | printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name); |
| 1406 | break; |
| 1407 | case 0x04: |
| 1408 | printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name); |
| 1409 | break; |
| 1410 | case 0x39: /* Must deal with this if individual multicast addresses used */ |
| 1411 | printk(KERN_INFO "%s: Group address not found \n", dev->name); |
| 1412 | break; |
| 1413 | default: |
| 1414 | break; |
| 1415 | } /* switch srb[2] */ |
| 1416 | break; |
| 1417 | |
| 1418 | |
| 1419 | /* SRB_SET_FUNC_ADDRESS - Called by the set_rx_mode |
| 1420 | */ |
| 1421 | |
| 1422 | case SRB_SET_FUNC_ADDRESS: |
| 1423 | srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; |
| 1424 | switch (srb_word) { |
| 1425 | case 0x00: |
| 1426 | if (streamer_priv->streamer_message_level) |
| 1427 | printk(KERN_INFO "%s: Functional Address Mask Set \n", dev->name); |
| 1428 | break; |
| 1429 | case 0x01: |
| 1430 | printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name); |
| 1431 | break; |
| 1432 | case 0x04: |
| 1433 | printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name); |
| 1434 | break; |
| 1435 | default: |
| 1436 | break; |
| 1437 | } /* switch srb[2] */ |
| 1438 | break; |
| 1439 | |
| 1440 | /* SRB_READ_LOG - Read and reset the adapter error counters |
| 1441 | */ |
| 1442 | |
| 1443 | case SRB_READ_LOG: |
| 1444 | srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; |
| 1445 | switch (srb_word) { |
| 1446 | case 0x00: |
| 1447 | { |
| 1448 | int i; |
| 1449 | if (streamer_priv->streamer_message_level) |
| 1450 | printk(KERN_INFO "%s: Read Log command complete\n", dev->name); |
| 1451 | printk("Read Log statistics: "); |
| 1452 | writew(streamer_priv->srb + 6, |
| 1453 | streamer_mmio + LAPA); |
| 1454 | for (i = 0; i < 5; i++) { |
| 1455 | printk("%x:", ntohs(readw(streamer_mmio + LAPDINC))); |
| 1456 | } |
| 1457 | printk("\n"); |
| 1458 | } |
| 1459 | break; |
| 1460 | case 0x01: |
| 1461 | printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name); |
| 1462 | break; |
| 1463 | case 0x04: |
| 1464 | printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name); |
| 1465 | break; |
| 1466 | |
| 1467 | } /* switch srb[2] */ |
| 1468 | break; |
| 1469 | |
| 1470 | /* SRB_READ_SR_COUNTERS - Read and reset the source routing bridge related counters */ |
| 1471 | |
| 1472 | case SRB_READ_SR_COUNTERS: |
| 1473 | srb_word=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; |
| 1474 | switch (srb_word) { |
| 1475 | case 0x00: |
| 1476 | if (streamer_priv->streamer_message_level) |
| 1477 | printk(KERN_INFO "%s: Read Source Routing Counters issued\n", dev->name); |
| 1478 | break; |
| 1479 | case 0x01: |
| 1480 | printk(KERN_WARNING "%s: Unrecognized srb command \n", dev->name); |
| 1481 | break; |
| 1482 | case 0x04: |
| 1483 | printk(KERN_WARNING "%s: Adapter must be open for this operation, doh!!\n", dev->name); |
| 1484 | break; |
| 1485 | default: |
| 1486 | break; |
| 1487 | } /* switch srb[2] */ |
| 1488 | break; |
| 1489 | |
| 1490 | default: |
| 1491 | printk(KERN_WARNING "%s: Unrecognized srb bh return value.\n", dev->name); |
| 1492 | break; |
| 1493 | } /* switch srb[0] */ |
| 1494 | } |
| 1495 | |
| 1496 | static struct net_device_stats *streamer_get_stats(struct net_device *dev) |
| 1497 | { |
| 1498 | struct streamer_private *streamer_priv; |
| 1499 | streamer_priv = (struct streamer_private *) dev->priv; |
| 1500 | return (struct net_device_stats *) &streamer_priv->streamer_stats; |
| 1501 | } |
| 1502 | |
| 1503 | static int streamer_set_mac_address(struct net_device *dev, void *addr) |
| 1504 | { |
| 1505 | struct sockaddr *saddr = addr; |
| 1506 | struct streamer_private *streamer_priv = (struct streamer_private *) dev->priv; |
| 1507 | |
| 1508 | if (netif_running(dev)) |
| 1509 | { |
| 1510 | printk(KERN_WARNING "%s: Cannot set mac/laa address while card is open\n", dev->name); |
| 1511 | return -EIO; |
| 1512 | } |
| 1513 | |
| 1514 | memcpy(streamer_priv->streamer_laa, saddr->sa_data, dev->addr_len); |
| 1515 | |
| 1516 | if (streamer_priv->streamer_message_level) { |
| 1517 | printk(KERN_INFO "%s: MAC/LAA Set to = %x.%x.%x.%x.%x.%x\n", |
| 1518 | dev->name, streamer_priv->streamer_laa[0], |
| 1519 | streamer_priv->streamer_laa[1], |
| 1520 | streamer_priv->streamer_laa[2], |
| 1521 | streamer_priv->streamer_laa[3], |
| 1522 | streamer_priv->streamer_laa[4], |
| 1523 | streamer_priv->streamer_laa[5]); |
| 1524 | } |
| 1525 | return 0; |
| 1526 | } |
| 1527 | |
| 1528 | static void streamer_arb_cmd(struct net_device *dev) |
| 1529 | { |
| 1530 | struct streamer_private *streamer_priv = |
| 1531 | (struct streamer_private *) dev->priv; |
| 1532 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1533 | __u8 header_len; |
| 1534 | __u16 frame_len, buffer_len; |
| 1535 | struct sk_buff *mac_frame; |
| 1536 | __u8 frame_data[256]; |
| 1537 | __u16 buff_off; |
| 1538 | __u16 lan_status = 0, lan_status_diff; /* Initialize to stop compiler warning */ |
| 1539 | __u8 fdx_prot_error; |
| 1540 | __u16 next_ptr; |
| 1541 | __u16 arb_word; |
| 1542 | |
| 1543 | #if STREAMER_NETWORK_MONITOR |
| 1544 | struct trh_hdr *mac_hdr; |
| 1545 | #endif |
| 1546 | |
| 1547 | writew(streamer_priv->arb, streamer_mmio + LAPA); |
| 1548 | arb_word=ntohs(readw(streamer_mmio+LAPD)) >> 8; |
| 1549 | |
| 1550 | if (arb_word == ARB_RECEIVE_DATA) { /* Receive.data, MAC frames */ |
| 1551 | writew(streamer_priv->arb + 6, streamer_mmio + LAPA); |
| 1552 | streamer_priv->mac_rx_buffer = buff_off = ntohs(readw(streamer_mmio + LAPDINC)); |
| 1553 | header_len=ntohs(readw(streamer_mmio+LAPDINC)) >> 8; /* 802.5 Token-Ring Header Length */ |
| 1554 | frame_len = ntohs(readw(streamer_mmio + LAPDINC)); |
| 1555 | |
| 1556 | #if STREAMER_DEBUG |
| 1557 | { |
| 1558 | int i; |
| 1559 | __u16 next; |
| 1560 | __u8 status; |
| 1561 | __u16 len; |
| 1562 | |
| 1563 | writew(ntohs(buff_off), streamer_mmio + LAPA); /*setup window to frame data */ |
| 1564 | next = htons(readw(streamer_mmio + LAPDINC)); |
| 1565 | status = |
| 1566 | ntohs(readw(streamer_mmio + LAPDINC)) & 0xff; |
| 1567 | len = ntohs(readw(streamer_mmio + LAPDINC)); |
| 1568 | |
| 1569 | /* print out 1st 14 bytes of frame data */ |
| 1570 | for (i = 0; i < 7; i++) { |
| 1571 | printk("Loc %d = %04x\n", i, |
| 1572 | ntohs(readw |
| 1573 | (streamer_mmio + LAPDINC))); |
| 1574 | } |
| 1575 | |
| 1576 | printk("next %04x, fs %02x, len %04x \n", next, |
| 1577 | status, len); |
| 1578 | } |
| 1579 | #endif |
| 1580 | if (!(mac_frame = dev_alloc_skb(frame_len))) { |
| 1581 | printk(KERN_WARNING "%s: Memory squeeze, dropping frame.\n", |
| 1582 | dev->name); |
| 1583 | goto drop_frame; |
| 1584 | } |
| 1585 | /* Walk the buffer chain, creating the frame */ |
| 1586 | |
| 1587 | do { |
| 1588 | int i; |
| 1589 | __u16 rx_word; |
| 1590 | |
| 1591 | writew(htons(buff_off), streamer_mmio + LAPA); /* setup window to frame data */ |
| 1592 | next_ptr = ntohs(readw(streamer_mmio + LAPDINC)); |
| 1593 | readw(streamer_mmio + LAPDINC); /* read thru status word */ |
| 1594 | buffer_len = ntohs(readw(streamer_mmio + LAPDINC)); |
| 1595 | |
| 1596 | if (buffer_len > 256) |
| 1597 | break; |
| 1598 | |
| 1599 | i = 0; |
| 1600 | while (i < buffer_len) { |
| 1601 | rx_word=ntohs(readw(streamer_mmio+LAPDINC)); |
| 1602 | frame_data[i]=rx_word >> 8; |
| 1603 | frame_data[i+1]=rx_word & 0xff; |
| 1604 | i += 2; |
| 1605 | } |
| 1606 | |
| 1607 | memcpy(skb_put(mac_frame, buffer_len), |
| 1608 | frame_data, buffer_len); |
| 1609 | } while (next_ptr && (buff_off = next_ptr)); |
| 1610 | |
| 1611 | #if STREAMER_NETWORK_MONITOR |
| 1612 | printk(KERN_WARNING "%s: Received MAC Frame, details: \n", |
| 1613 | dev->name); |
| 1614 | mac_hdr = (struct trh_hdr *) mac_frame->data; |
| 1615 | printk(KERN_WARNING |
| 1616 | "%s: MAC Frame Dest. Addr: %02x:%02x:%02x:%02x:%02x:%02x \n", |
| 1617 | dev->name, mac_hdr->daddr[0], mac_hdr->daddr[1], |
| 1618 | mac_hdr->daddr[2], mac_hdr->daddr[3], |
| 1619 | mac_hdr->daddr[4], mac_hdr->daddr[5]); |
| 1620 | printk(KERN_WARNING |
| 1621 | "%s: MAC Frame Srce. Addr: %02x:%02x:%02x:%02x:%02x:%02x \n", |
| 1622 | dev->name, mac_hdr->saddr[0], mac_hdr->saddr[1], |
| 1623 | mac_hdr->saddr[2], mac_hdr->saddr[3], |
| 1624 | mac_hdr->saddr[4], mac_hdr->saddr[5]); |
| 1625 | #endif |
| 1626 | mac_frame->dev = dev; |
| 1627 | mac_frame->protocol = tr_type_trans(mac_frame, dev); |
| 1628 | netif_rx(mac_frame); |
| 1629 | |
| 1630 | /* Now tell the card we have dealt with the received frame */ |
| 1631 | drop_frame: |
| 1632 | /* Set LISR Bit 1 */ |
| 1633 | writel(LISR_ARB_FREE, streamer_priv->streamer_mmio + LISR_SUM); |
| 1634 | |
| 1635 | /* Is the ASB free ? */ |
| 1636 | |
| 1637 | if (!(readl(streamer_priv->streamer_mmio + SISR) & SISR_ASB_FREE)) |
| 1638 | { |
| 1639 | streamer_priv->asb_queued = 1; |
| 1640 | writel(LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM); |
| 1641 | return; |
| 1642 | /* Drop out and wait for the bottom half to be run */ |
| 1643 | } |
| 1644 | |
| 1645 | |
| 1646 | writew(streamer_priv->asb, streamer_mmio + LAPA); |
| 1647 | writew(htons(ASB_RECEIVE_DATA << 8), streamer_mmio+LAPDINC); |
| 1648 | writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC); |
| 1649 | writew(0, streamer_mmio + LAPDINC); |
| 1650 | writew(htons(streamer_priv->mac_rx_buffer), streamer_mmio + LAPD); |
| 1651 | |
| 1652 | writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM); |
| 1653 | |
| 1654 | streamer_priv->asb_queued = 2; |
| 1655 | return; |
| 1656 | |
| 1657 | } else if (arb_word == ARB_LAN_CHANGE_STATUS) { /* Lan.change.status */ |
| 1658 | writew(streamer_priv->arb + 6, streamer_mmio + LAPA); |
| 1659 | lan_status = ntohs(readw(streamer_mmio + LAPDINC)); |
| 1660 | fdx_prot_error = ntohs(readw(streamer_mmio+LAPD)) >> 8; |
| 1661 | |
| 1662 | /* Issue ARB Free */ |
| 1663 | writew(LISR_ARB_FREE, streamer_priv->streamer_mmio + LISR_SUM); |
| 1664 | |
| 1665 | lan_status_diff = (streamer_priv->streamer_lan_status ^ lan_status) & |
| 1666 | lan_status; |
| 1667 | |
| 1668 | if (lan_status_diff & (LSC_LWF | LSC_ARW | LSC_FPE | LSC_RR)) |
| 1669 | { |
| 1670 | if (lan_status_diff & LSC_LWF) |
| 1671 | printk(KERN_WARNING "%s: Short circuit detected on the lobe\n", dev->name); |
| 1672 | if (lan_status_diff & LSC_ARW) |
| 1673 | printk(KERN_WARNING "%s: Auto removal error\n", dev->name); |
| 1674 | if (lan_status_diff & LSC_FPE) |
| 1675 | printk(KERN_WARNING "%s: FDX Protocol Error\n", dev->name); |
| 1676 | if (lan_status_diff & LSC_RR) |
| 1677 | printk(KERN_WARNING "%s: Force remove MAC frame received\n", dev->name); |
| 1678 | |
| 1679 | /* Adapter has been closed by the hardware */ |
| 1680 | |
| 1681 | /* reset tx/rx fifo's and busmaster logic */ |
| 1682 | |
| 1683 | /* @TBD. no llc reset on autostreamer writel(readl(streamer_mmio+BCTL)|(3<<13),streamer_mmio+BCTL); |
| 1684 | udelay(1); |
| 1685 | writel(readl(streamer_mmio+BCTL)&~(3<<13),streamer_mmio+BCTL); */ |
| 1686 | |
| 1687 | netif_stop_queue(dev); |
| 1688 | netif_carrier_off(dev); |
| 1689 | printk(KERN_WARNING "%s: Adapter must be manually reset.\n", dev->name); |
| 1690 | } |
| 1691 | /* If serious error */ |
| 1692 | if (streamer_priv->streamer_message_level) { |
| 1693 | if (lan_status_diff & LSC_SIG_LOSS) |
| 1694 | printk(KERN_WARNING "%s: No receive signal detected \n", dev->name); |
| 1695 | if (lan_status_diff & LSC_HARD_ERR) |
| 1696 | printk(KERN_INFO "%s: Beaconing \n", dev->name); |
| 1697 | if (lan_status_diff & LSC_SOFT_ERR) |
| 1698 | printk(KERN_WARNING "%s: Adapter transmitted Soft Error Report Mac Frame \n", dev->name); |
| 1699 | if (lan_status_diff & LSC_TRAN_BCN) |
| 1700 | printk(KERN_INFO "%s: We are tranmitting the beacon, aaah\n", dev->name); |
| 1701 | if (lan_status_diff & LSC_SS) |
| 1702 | printk(KERN_INFO "%s: Single Station on the ring \n", dev->name); |
| 1703 | if (lan_status_diff & LSC_RING_REC) |
| 1704 | printk(KERN_INFO "%s: Ring recovery ongoing\n", dev->name); |
| 1705 | if (lan_status_diff & LSC_FDX_MODE) |
| 1706 | printk(KERN_INFO "%s: Operating in FDX mode\n", dev->name); |
| 1707 | } |
| 1708 | |
| 1709 | if (lan_status_diff & LSC_CO) { |
| 1710 | if (streamer_priv->streamer_message_level) |
| 1711 | printk(KERN_INFO "%s: Counter Overflow \n", dev->name); |
| 1712 | |
| 1713 | /* Issue READ.LOG command */ |
| 1714 | |
| 1715 | writew(streamer_priv->srb, streamer_mmio + LAPA); |
| 1716 | writew(htons(SRB_READ_LOG << 8),streamer_mmio+LAPDINC); |
| 1717 | writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC); |
| 1718 | writew(0, streamer_mmio + LAPDINC); |
| 1719 | streamer_priv->srb_queued = 2; /* Can't sleep, use srb_bh */ |
| 1720 | |
| 1721 | writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM); |
| 1722 | } |
| 1723 | |
| 1724 | if (lan_status_diff & LSC_SR_CO) { |
| 1725 | if (streamer_priv->streamer_message_level) |
| 1726 | printk(KERN_INFO "%s: Source routing counters overflow\n", dev->name); |
| 1727 | |
| 1728 | /* Issue a READ.SR.COUNTERS */ |
| 1729 | writew(streamer_priv->srb, streamer_mmio + LAPA); |
| 1730 | writew(htons(SRB_READ_SR_COUNTERS << 8), |
| 1731 | streamer_mmio+LAPDINC); |
| 1732 | writew(htons(STREAMER_CLEAR_RET_CODE << 8), |
| 1733 | streamer_mmio+LAPDINC); |
| 1734 | streamer_priv->srb_queued = 2; /* Can't sleep, use srb_bh */ |
| 1735 | writew(LISR_SRB_CMD, streamer_mmio + LISR_SUM); |
| 1736 | |
| 1737 | } |
| 1738 | streamer_priv->streamer_lan_status = lan_status; |
| 1739 | } /* Lan.change.status */ |
| 1740 | else |
| 1741 | printk(KERN_WARNING "%s: Unknown arb command \n", dev->name); |
| 1742 | } |
| 1743 | |
| 1744 | static void streamer_asb_bh(struct net_device *dev) |
| 1745 | { |
| 1746 | struct streamer_private *streamer_priv = |
| 1747 | (struct streamer_private *) dev->priv; |
| 1748 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1749 | |
| 1750 | if (streamer_priv->asb_queued == 1) |
| 1751 | { |
| 1752 | /* Dropped through the first time */ |
| 1753 | |
| 1754 | writew(streamer_priv->asb, streamer_mmio + LAPA); |
| 1755 | writew(htons(ASB_RECEIVE_DATA << 8),streamer_mmio+LAPDINC); |
| 1756 | writew(htons(STREAMER_CLEAR_RET_CODE << 8), streamer_mmio+LAPDINC); |
| 1757 | writew(0, streamer_mmio + LAPDINC); |
| 1758 | writew(htons(streamer_priv->mac_rx_buffer), streamer_mmio + LAPD); |
| 1759 | |
| 1760 | writel(LISR_ASB_REPLY | LISR_ASB_FREE_REQ, streamer_priv->streamer_mmio + LISR_SUM); |
| 1761 | streamer_priv->asb_queued = 2; |
| 1762 | |
| 1763 | return; |
| 1764 | } |
| 1765 | |
| 1766 | if (streamer_priv->asb_queued == 2) { |
| 1767 | __u8 rc; |
| 1768 | writew(streamer_priv->asb + 2, streamer_mmio + LAPA); |
| 1769 | rc=ntohs(readw(streamer_mmio+LAPD)) >> 8; |
| 1770 | switch (rc) { |
| 1771 | case 0x01: |
| 1772 | printk(KERN_WARNING "%s: Unrecognized command code \n", dev->name); |
| 1773 | break; |
| 1774 | case 0x26: |
| 1775 | printk(KERN_WARNING "%s: Unrecognized buffer address \n", dev->name); |
| 1776 | break; |
| 1777 | case 0xFF: |
| 1778 | /* Valid response, everything should be ok again */ |
| 1779 | break; |
| 1780 | default: |
| 1781 | printk(KERN_WARNING "%s: Invalid return code in asb\n", dev->name); |
| 1782 | break; |
| 1783 | } |
| 1784 | } |
| 1785 | streamer_priv->asb_queued = 0; |
| 1786 | } |
| 1787 | |
| 1788 | static int streamer_change_mtu(struct net_device *dev, int mtu) |
| 1789 | { |
| 1790 | struct streamer_private *streamer_priv = |
| 1791 | (struct streamer_private *) dev->priv; |
| 1792 | __u16 max_mtu; |
| 1793 | |
| 1794 | if (streamer_priv->streamer_ring_speed == 4) |
| 1795 | max_mtu = 4500; |
| 1796 | else |
| 1797 | max_mtu = 18000; |
| 1798 | |
| 1799 | if (mtu > max_mtu) |
| 1800 | return -EINVAL; |
| 1801 | if (mtu < 100) |
| 1802 | return -EINVAL; |
| 1803 | |
| 1804 | dev->mtu = mtu; |
| 1805 | streamer_priv->pkt_buf_sz = mtu + TR_HLEN; |
| 1806 | |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
| 1810 | #if STREAMER_NETWORK_MONITOR |
| 1811 | #ifdef CONFIG_PROC_FS |
| 1812 | static int streamer_proc_info(char *buffer, char **start, off_t offset, |
| 1813 | int length, int *eof, void *data) |
| 1814 | { |
| 1815 | struct streamer_private *sdev=NULL; |
| 1816 | struct pci_dev *pci_device = NULL; |
| 1817 | int len = 0; |
| 1818 | off_t begin = 0; |
| 1819 | off_t pos = 0; |
| 1820 | int size; |
| 1821 | |
| 1822 | struct net_device *dev; |
| 1823 | |
| 1824 | size = sprintf(buffer, "IBM LanStreamer/MPC Chipset Token Ring Adapters\n"); |
| 1825 | |
| 1826 | pos += size; |
| 1827 | len += size; |
| 1828 | |
| 1829 | for(sdev=dev_streamer; sdev; sdev=sdev->next) { |
| 1830 | pci_device=sdev->pci_dev; |
| 1831 | dev=pci_get_drvdata(pci_device); |
| 1832 | |
| 1833 | size = sprintf_info(buffer + len, dev); |
| 1834 | len += size; |
| 1835 | pos = begin + len; |
| 1836 | |
| 1837 | if (pos < offset) { |
| 1838 | len = 0; |
| 1839 | begin = pos; |
| 1840 | } |
| 1841 | if (pos > offset + length) |
| 1842 | break; |
| 1843 | } /* for */ |
| 1844 | |
| 1845 | *start = buffer + (offset - begin); /* Start of wanted data */ |
| 1846 | len -= (offset - begin); /* Start slop */ |
| 1847 | if (len > length) |
| 1848 | len = length; /* Ending slop */ |
| 1849 | return len; |
| 1850 | } |
| 1851 | |
| 1852 | static int sprintf_info(char *buffer, struct net_device *dev) |
| 1853 | { |
| 1854 | struct streamer_private *streamer_priv = |
| 1855 | (struct streamer_private *) dev->priv; |
| 1856 | __u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1857 | struct streamer_adapter_addr_table sat; |
| 1858 | struct streamer_parameters_table spt; |
| 1859 | int size = 0; |
| 1860 | int i; |
| 1861 | |
| 1862 | writew(streamer_priv->streamer_addr_table_addr, streamer_mmio + LAPA); |
| 1863 | for (i = 0; i < 14; i += 2) { |
| 1864 | __u16 io_word; |
| 1865 | __u8 *datap = (__u8 *) & sat; |
| 1866 | io_word=ntohs(readw(streamer_mmio+LAPDINC)); |
| 1867 | datap[size]=io_word >> 8; |
| 1868 | datap[size+1]=io_word & 0xff; |
| 1869 | } |
| 1870 | writew(streamer_priv->streamer_parms_addr, streamer_mmio + LAPA); |
| 1871 | for (i = 0; i < 68; i += 2) { |
| 1872 | __u16 io_word; |
| 1873 | __u8 *datap = (__u8 *) & spt; |
| 1874 | io_word=ntohs(readw(streamer_mmio+LAPDINC)); |
| 1875 | datap[size]=io_word >> 8; |
| 1876 | datap[size+1]=io_word & 0xff; |
| 1877 | } |
| 1878 | |
| 1879 | |
| 1880 | size = sprintf(buffer, "\n%6s: Adapter Address : Node Address : Functional Addr\n", dev->name); |
| 1881 | |
| 1882 | size += sprintf(buffer + size, |
| 1883 | "%6s: %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x\n", |
| 1884 | dev->name, dev->dev_addr[0], dev->dev_addr[1], |
| 1885 | dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4], |
| 1886 | dev->dev_addr[5], sat.node_addr[0], sat.node_addr[1], |
| 1887 | sat.node_addr[2], sat.node_addr[3], sat.node_addr[4], |
| 1888 | sat.node_addr[5], sat.func_addr[0], sat.func_addr[1], |
| 1889 | sat.func_addr[2], sat.func_addr[3]); |
| 1890 | |
| 1891 | size += sprintf(buffer + size, "\n%6s: Token Ring Parameters Table:\n", dev->name); |
| 1892 | |
| 1893 | size += sprintf(buffer + size, "%6s: Physical Addr : Up Node Address : Poll Address : AccPri : Auth Src : Att Code :\n", dev->name); |
| 1894 | |
| 1895 | size += sprintf(buffer + size, |
| 1896 | "%6s: %02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x:%02x:%02x : %04x : %04x : %04x :\n", |
| 1897 | dev->name, spt.phys_addr[0], spt.phys_addr[1], |
| 1898 | spt.phys_addr[2], spt.phys_addr[3], |
| 1899 | spt.up_node_addr[0], spt.up_node_addr[1], |
| 1900 | spt.up_node_addr[2], spt.up_node_addr[3], |
| 1901 | spt.up_node_addr[4], spt.up_node_addr[4], |
| 1902 | spt.poll_addr[0], spt.poll_addr[1], spt.poll_addr[2], |
| 1903 | spt.poll_addr[3], spt.poll_addr[4], spt.poll_addr[5], |
| 1904 | ntohs(spt.acc_priority), ntohs(spt.auth_source_class), |
| 1905 | ntohs(spt.att_code)); |
| 1906 | |
| 1907 | size += sprintf(buffer + size, "%6s: Source Address : Bcn T : Maj. V : Lan St : Lcl Rg : Mon Err : Frame Correl : \n", dev->name); |
| 1908 | |
| 1909 | size += sprintf(buffer + size, |
| 1910 | "%6s: %02x:%02x:%02x:%02x:%02x:%02x : %04x : %04x : %04x : %04x : %04x : %04x : \n", |
| 1911 | dev->name, spt.source_addr[0], spt.source_addr[1], |
| 1912 | spt.source_addr[2], spt.source_addr[3], |
| 1913 | spt.source_addr[4], spt.source_addr[5], |
| 1914 | ntohs(spt.beacon_type), ntohs(spt.major_vector), |
| 1915 | ntohs(spt.lan_status), ntohs(spt.local_ring), |
| 1916 | ntohs(spt.mon_error), ntohs(spt.frame_correl)); |
| 1917 | |
| 1918 | size += sprintf(buffer + size, "%6s: Beacon Details : Tx : Rx : NAUN Node Address : NAUN Node Phys : \n", |
| 1919 | dev->name); |
| 1920 | |
| 1921 | size += sprintf(buffer + size, |
| 1922 | "%6s: : %02x : %02x : %02x:%02x:%02x:%02x:%02x:%02x : %02x:%02x:%02x:%02x : \n", |
| 1923 | dev->name, ntohs(spt.beacon_transmit), |
| 1924 | ntohs(spt.beacon_receive), spt.beacon_naun[0], |
| 1925 | spt.beacon_naun[1], spt.beacon_naun[2], |
| 1926 | spt.beacon_naun[3], spt.beacon_naun[4], |
| 1927 | spt.beacon_naun[5], spt.beacon_phys[0], |
| 1928 | spt.beacon_phys[1], spt.beacon_phys[2], |
| 1929 | spt.beacon_phys[3]); |
| 1930 | return size; |
| 1931 | } |
| 1932 | #endif |
| 1933 | #endif |
| 1934 | |
| 1935 | #if STREAMER_IOCTL && (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) |
| 1936 | static int streamer_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 1937 | { |
| 1938 | int i; |
| 1939 | struct streamer_private *streamer_priv = (struct streamer_private *) dev->priv; |
| 1940 | u8 __iomem *streamer_mmio = streamer_priv->streamer_mmio; |
| 1941 | |
| 1942 | switch(cmd) { |
| 1943 | case IOCTL_SISR_MASK: |
| 1944 | writew(SISR_MI, streamer_mmio + SISR_MASK_SUM); |
| 1945 | break; |
| 1946 | case IOCTL_SPIN_LOCK_TEST: |
| 1947 | printk(KERN_INFO "spin_lock() called.\n"); |
| 1948 | spin_lock(&streamer_priv->streamer_lock); |
| 1949 | spin_unlock(&streamer_priv->streamer_lock); |
| 1950 | printk(KERN_INFO "spin_unlock() finished.\n"); |
| 1951 | break; |
| 1952 | case IOCTL_PRINT_BDAS: |
| 1953 | printk(KERN_INFO "bdas: RXBDA: %x RXLBDA: %x TX2FDA: %x TX2LFDA: %x\n", |
| 1954 | readw(streamer_mmio + RXBDA), |
| 1955 | readw(streamer_mmio + RXLBDA), |
| 1956 | readw(streamer_mmio + TX2FDA), |
| 1957 | readw(streamer_mmio + TX2LFDA)); |
| 1958 | break; |
| 1959 | case IOCTL_PRINT_REGISTERS: |
| 1960 | printk(KERN_INFO "registers:\n"); |
| 1961 | printk(KERN_INFO "SISR: %04x MISR: %04x LISR: %04x BCTL: %04x BMCTL: %04x\nmask %04x mask %04x\n", |
| 1962 | readw(streamer_mmio + SISR), |
| 1963 | readw(streamer_mmio + MISR_RUM), |
| 1964 | readw(streamer_mmio + LISR), |
| 1965 | readw(streamer_mmio + BCTL), |
| 1966 | readw(streamer_mmio + BMCTL_SUM), |
| 1967 | readw(streamer_mmio + SISR_MASK), |
| 1968 | readw(streamer_mmio + MISR_MASK)); |
| 1969 | break; |
| 1970 | case IOCTL_PRINT_RX_BUFS: |
| 1971 | printk(KERN_INFO "Print rx bufs:\n"); |
| 1972 | for(i=0; i<STREAMER_RX_RING_SIZE; i++) |
| 1973 | printk(KERN_INFO "rx_ring %d status: 0x%x\n", i, |
| 1974 | streamer_priv->streamer_rx_ring[i].status); |
| 1975 | break; |
| 1976 | case IOCTL_PRINT_TX_BUFS: |
| 1977 | printk(KERN_INFO "Print tx bufs:\n"); |
| 1978 | for(i=0; i<STREAMER_TX_RING_SIZE; i++) |
| 1979 | printk(KERN_INFO "tx_ring %d status: 0x%x\n", i, |
| 1980 | streamer_priv->streamer_tx_ring[i].status); |
| 1981 | break; |
| 1982 | case IOCTL_RX_CMD: |
| 1983 | streamer_rx(dev); |
| 1984 | printk(KERN_INFO "Sent rx command.\n"); |
| 1985 | break; |
| 1986 | default: |
| 1987 | printk(KERN_INFO "Bad ioctl!\n"); |
| 1988 | } |
| 1989 | return 0; |
| 1990 | } |
| 1991 | #endif |
| 1992 | |
| 1993 | static struct pci_driver streamer_pci_driver = { |
| 1994 | .name = "lanstreamer", |
| 1995 | .id_table = streamer_pci_tbl, |
| 1996 | .probe = streamer_init_one, |
| 1997 | .remove = __devexit_p(streamer_remove_one), |
| 1998 | }; |
| 1999 | |
| 2000 | static int __init streamer_init_module(void) { |
| 2001 | return pci_module_init(&streamer_pci_driver); |
| 2002 | } |
| 2003 | |
| 2004 | static void __exit streamer_cleanup_module(void) { |
| 2005 | pci_unregister_driver(&streamer_pci_driver); |
| 2006 | } |
| 2007 | |
| 2008 | module_init(streamer_init_module); |
| 2009 | module_exit(streamer_cleanup_module); |
| 2010 | MODULE_LICENSE("GPL"); |