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