1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/types.h>
34#include <linux/fcntl.h>
35#include <linux/interrupt.h>
36#include <linux/ptrace.h>
37#include <linux/ioport.h>
38#include <linux/in.h>
39#include <linux/string.h>
40#include <linux/time.h>
41#include <linux/errno.h>
42#include <linux/init.h>
43#include <linux/mca-legacy.h>
44#include <linux/delay.h>
45#include <linux/netdevice.h>
46#include <linux/etherdevice.h>
47#include <linux/skbuff.h>
48#include <linux/trdevice.h>
49#include <linux/bitops.h>
50#include <linux/firmware.h>
51
52#include <asm/system.h>
53#include <asm/io.h>
54#include <asm/dma.h>
55#include <asm/irq.h>
56
57#if BITS_PER_LONG == 64
58#error FIXME: driver does not support 64-bit platforms
59#endif
60
61#include "smctr.h"
62
63static const char version[] __initdata =
64 KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
65static const char cardname[] = "smctr";
66
67
68#define SMCTR_IO_EXTENT 20
69
70#ifdef CONFIG_MCA_LEGACY
71static unsigned int smctr_posid = 0x6ec6;
72#endif
73
74static int ringspeed;
75
76
77static char smctr_name[] = "SMC TokenCard";
78static char *smctr_model = "Unknown";
79
80
81
82
83#ifndef SMCTR_DEBUG
84#define SMCTR_DEBUG 1
85#endif
86static unsigned int smctr_debug = SMCTR_DEBUG;
87
88
89
90
91
92static int smctr_alloc_shared_memory(struct net_device *dev);
93
94
95static int smctr_bypass_state(struct net_device *dev);
96
97
98static int smctr_checksum_firmware(struct net_device *dev);
99static int __init smctr_chk_isa(struct net_device *dev);
100static int smctr_chg_rx_mask(struct net_device *dev);
101static int smctr_clear_int(struct net_device *dev);
102static int smctr_clear_trc_reset(int ioaddr);
103static int smctr_close(struct net_device *dev);
104
105
106static int smctr_decode_firmware(struct net_device *dev,
107 const struct firmware *fw);
108static int smctr_disable_16bit(struct net_device *dev);
109static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
110static int smctr_disable_bic_int(struct net_device *dev);
111
112
113static int smctr_enable_16bit(struct net_device *dev);
114static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
115static int smctr_enable_adapter_ram(struct net_device *dev);
116static int smctr_enable_bic_int(struct net_device *dev);
117
118
119static int __init smctr_get_boardid(struct net_device *dev, int mca);
120static int smctr_get_group_address(struct net_device *dev);
121static int smctr_get_functional_address(struct net_device *dev);
122static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
123static int smctr_get_physical_drop_number(struct net_device *dev);
124static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
125static int smctr_get_station_id(struct net_device *dev);
126static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
127 __u16 bytes_count);
128static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
129
130
131static int smctr_hardware_send_packet(struct net_device *dev,
132 struct net_local *tp);
133
134static int smctr_init_acbs(struct net_device *dev);
135static int smctr_init_adapter(struct net_device *dev);
136static int smctr_init_card_real(struct net_device *dev);
137static int smctr_init_rx_bdbs(struct net_device *dev);
138static int smctr_init_rx_fcbs(struct net_device *dev);
139static int smctr_init_shared_memory(struct net_device *dev);
140static int smctr_init_tx_bdbs(struct net_device *dev);
141static int smctr_init_tx_fcbs(struct net_device *dev);
142static int smctr_internal_self_test(struct net_device *dev);
143static irqreturn_t smctr_interrupt(int irq, void *dev_id);
144static int smctr_issue_enable_int_cmd(struct net_device *dev,
145 __u16 interrupt_enable_mask);
146static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
147 __u16 ibits);
148static int smctr_issue_init_timers_cmd(struct net_device *dev);
149static int smctr_issue_init_txrx_cmd(struct net_device *dev);
150static int smctr_issue_insert_cmd(struct net_device *dev);
151static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
152static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
153static int smctr_issue_remove_cmd(struct net_device *dev);
154static int smctr_issue_resume_acb_cmd(struct net_device *dev);
155static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
156static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
157static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
158static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
159static int smctr_issue_test_hic_cmd(struct net_device *dev);
160static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
161static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
162static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
163static int smctr_issue_write_byte_cmd(struct net_device *dev,
164 short aword_cnt, void *byte);
165static int smctr_issue_write_word_cmd(struct net_device *dev,
166 short aword_cnt, void *word);
167
168
169static int smctr_join_complete_state(struct net_device *dev);
170
171
172static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
173static int smctr_load_firmware(struct net_device *dev);
174static int smctr_load_node_addr(struct net_device *dev);
175static int smctr_lobe_media_test(struct net_device *dev);
176static int smctr_lobe_media_test_cmd(struct net_device *dev);
177static int smctr_lobe_media_test_state(struct net_device *dev);
178
179
180static int smctr_make_8025_hdr(struct net_device *dev,
181 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
182static int smctr_make_access_pri(struct net_device *dev,
183 MAC_SUB_VECTOR *tsv);
184static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
185static int smctr_make_auth_funct_class(struct net_device *dev,
186 MAC_SUB_VECTOR *tsv);
187static int smctr_make_corr(struct net_device *dev,
188 MAC_SUB_VECTOR *tsv, __u16 correlator);
189static int smctr_make_funct_addr(struct net_device *dev,
190 MAC_SUB_VECTOR *tsv);
191static int smctr_make_group_addr(struct net_device *dev,
192 MAC_SUB_VECTOR *tsv);
193static int smctr_make_phy_drop_num(struct net_device *dev,
194 MAC_SUB_VECTOR *tsv);
195static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
196static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
197static int smctr_make_ring_station_status(struct net_device *dev,
198 MAC_SUB_VECTOR *tsv);
199static int smctr_make_ring_station_version(struct net_device *dev,
200 MAC_SUB_VECTOR *tsv);
201static int smctr_make_tx_status_code(struct net_device *dev,
202 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
203static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
204 MAC_SUB_VECTOR *tsv);
205static int smctr_make_wrap_data(struct net_device *dev,
206 MAC_SUB_VECTOR *tsv);
207
208
209static int smctr_open(struct net_device *dev);
210static int smctr_open_tr(struct net_device *dev);
211
212
213struct net_device *smctr_probe(int unit);
214static int __init smctr_probe1(struct net_device *dev, int ioaddr);
215static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
216 struct net_device *dev, __u16 rx_status);
217
218
219static int smctr_ram_memory_test(struct net_device *dev);
220static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
221 __u16 *correlator);
222static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
223 __u16 *correlator);
224static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
225static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
226 MAC_HEADER *rmf, __u16 *correlator);
227static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
228 __u16 *correlator);
229static int smctr_reset_adapter(struct net_device *dev);
230static int smctr_restart_tx_chain(struct net_device *dev, short queue);
231static int smctr_ring_status_chg(struct net_device *dev);
232static int smctr_rx_frame(struct net_device *dev);
233
234
235static int smctr_send_dat(struct net_device *dev);
236static netdev_tx_t smctr_send_packet(struct sk_buff *skb,
237 struct net_device *dev);
238static int smctr_send_lobe_media_test(struct net_device *dev);
239static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
240 __u16 correlator);
241static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
242 __u16 correlator);
243static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
244 __u16 correlator);
245static int smctr_send_rpt_tx_forward(struct net_device *dev,
246 MAC_HEADER *rmf, __u16 tx_fstatus);
247static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
248 __u16 rcode, __u16 correlator);
249static int smctr_send_rq_init(struct net_device *dev);
250static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
251 __u16 *tx_fstatus);
252static int smctr_set_auth_access_pri(struct net_device *dev,
253 MAC_SUB_VECTOR *rsv);
254static int smctr_set_auth_funct_class(struct net_device *dev,
255 MAC_SUB_VECTOR *rsv);
256static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
257 __u16 *correlator);
258static int smctr_set_error_timer_value(struct net_device *dev,
259 MAC_SUB_VECTOR *rsv);
260static int smctr_set_frame_forward(struct net_device *dev,
261 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
262static int smctr_set_local_ring_num(struct net_device *dev,
263 MAC_SUB_VECTOR *rsv);
264static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
265static void smctr_set_multicast_list(struct net_device *dev);
266static int smctr_set_page(struct net_device *dev, __u8 *buf);
267static int smctr_set_phy_drop(struct net_device *dev,
268 MAC_SUB_VECTOR *rsv);
269static int smctr_set_ring_speed(struct net_device *dev);
270static int smctr_set_rx_look_ahead(struct net_device *dev);
271static int smctr_set_trc_reset(int ioaddr);
272static int smctr_setup_single_cmd(struct net_device *dev,
273 __u16 command, __u16 subcommand);
274static int smctr_setup_single_cmd_w_data(struct net_device *dev,
275 __u16 command, __u16 subcommand);
276static char *smctr_malloc(struct net_device *dev, __u16 size);
277static int smctr_status_chg(struct net_device *dev);
278
279
280static void smctr_timeout(struct net_device *dev);
281static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
282 __u16 queue);
283static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
284static unsigned short smctr_tx_move_frame(struct net_device *dev,
285 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
286
287
288static int smctr_update_err_stats(struct net_device *dev);
289static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
290static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
291 __u16 queue);
292
293
294static int smctr_wait_cmd(struct net_device *dev);
295static int smctr_wait_while_cbusy(struct net_device *dev);
296
297#define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
298#define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
299#define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327static int smctr_alloc_shared_memory(struct net_device *dev)
328{
329 struct net_local *tp = netdev_priv(dev);
330
331 if(smctr_debug > 10)
332 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
333
334
335
336
337 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
338 - (long)ISCP_BLOCK_SIZE);
339
340
341 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
342 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
343
344 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
345 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
346
347 tp->acb_head = (ACBlock *)smctr_malloc(dev,
348 sizeof(ACBlock)*tp->num_acbs);
349 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
350
351 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
352 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
353
354 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
355 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
356
357
358 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
359 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
360
361 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
362 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
363
364 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
365 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
366
367
368 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
369 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
370
371 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
372 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
373
374 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
375 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
376
377
378 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
379 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
380
381 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
382 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
383
384
385 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
386 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
387
388 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
389
390 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
391 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
392
393 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
394
395
396
397
398 tp->tx_buff_head[MAC_QUEUE]
399 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
400 tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
401 tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
402
403
404 tp->tx_buff_head[BUG_QUEUE]
405 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
406 tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
407 tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
408
409
410
411
412 tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
413 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
414 tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
415
416
417
418
419
420 smctr_malloc(dev, 1L);
421 tp->tx_buff_head[NON_MAC_QUEUE]
422 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
423 tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
424 tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
425 smctr_malloc(dev, 1L);
426
427
428
429
430
431
432
433 smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
434 tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
435 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
436 tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
437
438 return 0;
439}
440
441
442static int smctr_bypass_state(struct net_device *dev)
443{
444 int err;
445
446 if(smctr_debug > 10)
447 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
448
449 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
450
451 return err;
452}
453
454static int smctr_checksum_firmware(struct net_device *dev)
455{
456 struct net_local *tp = netdev_priv(dev);
457 __u16 i, checksum = 0;
458
459 if(smctr_debug > 10)
460 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
461
462 smctr_enable_adapter_ctrl_store(dev);
463
464 for(i = 0; i < CS_RAM_SIZE; i += 2)
465 checksum += *((__u16 *)(tp->ram_access + i));
466
467 tp->microcode_version = *(__u16 *)(tp->ram_access
468 + CS_RAM_VERSION_OFFSET);
469 tp->microcode_version >>= 8;
470
471 smctr_disable_adapter_ctrl_store(dev);
472
473 if(checksum)
474 return checksum;
475
476 return 0;
477}
478
479static int __init smctr_chk_mca(struct net_device *dev)
480{
481#ifdef CONFIG_MCA_LEGACY
482 struct net_local *tp = netdev_priv(dev);
483 int current_slot;
484 __u8 r1, r2, r3, r4, r5;
485
486 current_slot = mca_find_unused_adapter(smctr_posid, 0);
487 if(current_slot == MCA_NOTFOUND)
488 return -ENODEV;
489
490 mca_set_adapter_name(current_slot, smctr_name);
491 mca_mark_as_used(current_slot);
492 tp->slot_num = current_slot;
493
494 r1 = mca_read_stored_pos(tp->slot_num, 2);
495 r2 = mca_read_stored_pos(tp->slot_num, 3);
496
497 if(tp->slot_num)
498 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
499 else
500 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
501
502 r1 = inb(CNFG_POS_REG1);
503 r2 = inb(CNFG_POS_REG0);
504
505 tp->bic_type = BIC_594_CHIP;
506
507
508 r2 = mca_read_stored_pos(tp->slot_num, 2);
509 r2 &= 0xF0;
510 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
511 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
512
513
514 r5 = mca_read_stored_pos(tp->slot_num, 5);
515 r5 &= 0xC;
516 switch(r5)
517 {
518 case 0:
519 dev->irq = 3;
520 break;
521
522 case 0x4:
523 dev->irq = 4;
524 break;
525
526 case 0x8:
527 dev->irq = 10;
528 break;
529
530 default:
531 dev->irq = 15;
532 break;
533 }
534 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
535 release_region(dev->base_addr, SMCTR_IO_EXTENT);
536 return -ENODEV;
537 }
538
539
540 r3 = mca_read_stored_pos(tp->slot_num, 3);
541 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
542 if (r3 & 0x8)
543 tp->ram_base += 0x010000;
544 if (r3 & 0x80)
545 tp->ram_base += 0xF00000;
546
547
548 r3 &= 0x30;
549 r3 >>= 4;
550
551 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
552 tp->ram_size = (__u16)CNFG_SIZE_64KB;
553 tp->board_id |= TOKEN_MEDIA;
554
555 r4 = mca_read_stored_pos(tp->slot_num, 4);
556 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
557 if (r4 & 0x8)
558 tp->rom_base += 0x010000;
559
560
561 r4 >>= 4;
562 switch (r4) {
563 case 0:
564 tp->rom_size = CNFG_SIZE_8KB;
565 break;
566 case 1:
567 tp->rom_size = CNFG_SIZE_16KB;
568 break;
569 case 2:
570 tp->rom_size = CNFG_SIZE_32KB;
571 break;
572 default:
573 tp->rom_size = ROM_DISABLE;
574 }
575
576
577 r5 = mca_read_stored_pos(tp->slot_num, 5);
578 r5 &= CNFG_MEDIA_TYPE_MASK;
579 switch(r5)
580 {
581 case (0):
582 tp->media_type = MEDIA_STP_4;
583 break;
584
585 case (1):
586 tp->media_type = MEDIA_STP_16;
587 break;
588
589 case (3):
590 tp->media_type = MEDIA_UTP_16;
591 break;
592
593 default:
594 tp->media_type = MEDIA_UTP_4;
595 break;
596 }
597 tp->media_menu = 14;
598
599 r2 = mca_read_stored_pos(tp->slot_num, 2);
600 if(!(r2 & 0x02))
601 tp->mode_bits |= EARLY_TOKEN_REL;
602
603
604 outb(CNFG_POS_CONTROL_REG, 0);
605
606 tp->board_id = smctr_get_boardid(dev, 1);
607 switch(tp->board_id & 0xffff)
608 {
609 case WD8115TA:
610 smctr_model = "8115T/A";
611 break;
612
613 case WD8115T:
614 if(tp->extra_info & CHIP_REV_MASK)
615 smctr_model = "8115T rev XE";
616 else
617 smctr_model = "8115T rev XD";
618 break;
619
620 default:
621 smctr_model = "Unknown";
622 break;
623 }
624
625 return 0;
626#else
627 return -1;
628#endif
629}
630
631static int smctr_chg_rx_mask(struct net_device *dev)
632{
633 struct net_local *tp = netdev_priv(dev);
634 int err = 0;
635
636 if(smctr_debug > 10)
637 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
638
639 smctr_enable_16bit(dev);
640 smctr_set_page(dev, (__u8 *)tp->ram_access);
641
642 if(tp->mode_bits & LOOPING_MODE_MASK)
643 tp->config_word0 |= RX_OWN_BIT;
644 else
645 tp->config_word0 &= ~RX_OWN_BIT;
646
647 if(tp->receive_mask & PROMISCUOUS_MODE)
648 tp->config_word0 |= PROMISCUOUS_BIT;
649 else
650 tp->config_word0 &= ~PROMISCUOUS_BIT;
651
652 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
653 tp->config_word0 |= SAVBAD_BIT;
654 else
655 tp->config_word0 &= ~SAVBAD_BIT;
656
657 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
658 tp->config_word0 |= RXATMAC;
659 else
660 tp->config_word0 &= ~RXATMAC;
661
662 if(tp->receive_mask & ACCEPT_MULTI_PROM)
663 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
664 else
665 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
666
667 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
668 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
669 else
670 {
671 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
672 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
673 else
674 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
675 }
676
677 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
678 &tp->config_word0)))
679 {
680 return err;
681 }
682
683 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
684 &tp->config_word1)))
685 {
686 return err;
687 }
688
689 smctr_disable_16bit(dev);
690
691 return 0;
692}
693
694static int smctr_clear_int(struct net_device *dev)
695{
696 struct net_local *tp = netdev_priv(dev);
697
698 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
699
700 return 0;
701}
702
703static int smctr_clear_trc_reset(int ioaddr)
704{
705 __u8 r;
706
707 r = inb(ioaddr + MSR);
708 outb(~MSR_RST & r, ioaddr + MSR);
709
710 return 0;
711}
712
713
714
715
716static int smctr_close(struct net_device *dev)
717{
718 struct net_local *tp = netdev_priv(dev);
719 struct sk_buff *skb;
720 int err;
721
722 netif_stop_queue(dev);
723
724 tp->cleanup = 1;
725
726
727 if(tp->status != OPEN)
728 return 0;
729
730 smctr_enable_16bit(dev);
731 smctr_set_page(dev, (__u8 *)tp->ram_access);
732
733 if((err = smctr_issue_remove_cmd(dev)))
734 {
735 smctr_disable_16bit(dev);
736 return err;
737 }
738
739 for(;;)
740 {
741 skb = skb_dequeue(&tp->SendSkbQueue);
742 if(skb == NULL)
743 break;
744 tp->QueueSkb++;
745 dev_kfree_skb(skb);
746 }
747
748
749 return 0;
750}
751
752static int smctr_decode_firmware(struct net_device *dev,
753 const struct firmware *fw)
754{
755 struct net_local *tp = netdev_priv(dev);
756 short bit = 0x80, shift = 12;
757 DECODE_TREE_NODE *tree;
758 short branch, tsize;
759 __u16 buff = 0;
760 long weight;
761 __u8 *ucode;
762 __u16 *mem;
763
764 if(smctr_debug > 10)
765 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
766
767 weight = *(long *)(fw->data + WEIGHT_OFFSET);
768 tsize = *(__u8 *)(fw->data + TREE_SIZE_OFFSET);
769 tree = (DECODE_TREE_NODE *)(fw->data + TREE_OFFSET);
770 ucode = (__u8 *)(fw->data + TREE_OFFSET
771 + (tsize * sizeof(DECODE_TREE_NODE)));
772 mem = (__u16 *)(tp->ram_access);
773
774 while(weight)
775 {
776 branch = ROOT;
777 while((tree + branch)->tag != LEAF && weight)
778 {
779 branch = *ucode & bit ? (tree + branch)->llink
780 : (tree + branch)->rlink;
781
782 bit >>= 1;
783 weight--;
784
785 if(bit == 0)
786 {
787 bit = 0x80;
788 ucode++;
789 }
790 }
791
792 buff |= (tree + branch)->info << shift;
793 shift -= 4;
794
795 if(shift < 0)
796 {
797 *(mem++) = SWAP_BYTES(buff);
798 buff = 0;
799 shift = 12;
800 }
801 }
802
803
804
805
806
807 if(buff)
808 *(mem++) = SWAP_BYTES(buff);
809
810 return 0;
811}
812
813static int smctr_disable_16bit(struct net_device *dev)
814{
815 return 0;
816}
817
818
819
820
821
822
823
824static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
825{
826 struct net_local *tp = netdev_priv(dev);
827 int ioaddr = dev->base_addr;
828
829 if(smctr_debug > 10)
830 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
831
832 tp->trc_mask |= CSR_WCSS;
833 outb(tp->trc_mask, ioaddr + CSR);
834
835 return 0;
836}
837
838static int smctr_disable_bic_int(struct net_device *dev)
839{
840 struct net_local *tp = netdev_priv(dev);
841 int ioaddr = dev->base_addr;
842
843 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
844 | CSR_MSKTINT | CSR_WCSS;
845 outb(tp->trc_mask, ioaddr + CSR);
846
847 return 0;
848}
849
850static int smctr_enable_16bit(struct net_device *dev)
851{
852 struct net_local *tp = netdev_priv(dev);
853 __u8 r;
854
855 if(tp->adapter_bus == BUS_ISA16_TYPE)
856 {
857 r = inb(dev->base_addr + LAAR);
858 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
859 }
860
861 return 0;
862}
863
864
865
866
867
868
869
870static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
871{
872 struct net_local *tp = netdev_priv(dev);
873 int ioaddr = dev->base_addr;
874
875 if(smctr_debug > 10)
876 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
877
878 smctr_set_trc_reset(ioaddr);
879 smctr_enable_adapter_ram(dev);
880
881 tp->trc_mask &= ~CSR_WCSS;
882 outb(tp->trc_mask, ioaddr + CSR);
883
884 return 0;
885}
886
887static int smctr_enable_adapter_ram(struct net_device *dev)
888{
889 int ioaddr = dev->base_addr;
890 __u8 r;
891
892 if(smctr_debug > 10)
893 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
894
895 r = inb(ioaddr + MSR);
896 outb(MSR_MEMB | r, ioaddr + MSR);
897
898 return 0;
899}
900
901static int smctr_enable_bic_int(struct net_device *dev)
902{
903 struct net_local *tp = netdev_priv(dev);
904 int ioaddr = dev->base_addr;
905 __u8 r;
906
907 switch(tp->bic_type)
908 {
909 case (BIC_584_CHIP):
910 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
911 outb(tp->trc_mask, ioaddr + CSR);
912 r = inb(ioaddr + IRR);
913 outb(r | IRR_IEN, ioaddr + IRR);
914 break;
915
916 case (BIC_594_CHIP):
917 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
918 outb(tp->trc_mask, ioaddr + CSR);
919 r = inb(ioaddr + IMCCR);
920 outb(r | IMCCR_EIL, ioaddr + IMCCR);
921 break;
922 }
923
924 return 0;
925}
926
927static int __init smctr_chk_isa(struct net_device *dev)
928{
929 struct net_local *tp = netdev_priv(dev);
930 int ioaddr = dev->base_addr;
931 __u8 r1, r2, b, chksum = 0;
932 __u16 r;
933 int i;
934 int err = -ENODEV;
935
936 if(smctr_debug > 10)
937 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
938
939 if((ioaddr & 0x1F) != 0)
940 goto out;
941
942
943 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
944 err = -EBUSY;
945 goto out;
946 }
947
948
949 for(i = 0; i < 8; i++)
950 {
951 b = inb(ioaddr + LAR0 + i);
952 chksum += b;
953 }
954
955 if (chksum != NODE_ADDR_CKSUM)
956 goto out2;
957
958 b = inb(ioaddr + BDID);
959 if(b != BRD_ID_8115T)
960 {
961 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
962 goto out2;
963 }
964
965
966 r2 = 0;
967 for(r = 0; r < 8; r++)
968 {
969 r1 = inb(ioaddr + 0x8 + r);
970 r2 += r1;
971 }
972
973
974 if((r2 != 0xFF) && (r2 != 0xEE))
975 goto out2;
976
977
978 tp->board_id = smctr_get_boardid(dev, 0);
979 switch(tp->board_id & 0xffff)
980 {
981 case WD8115TA:
982 smctr_model = "8115T/A";
983 break;
984
985 case WD8115T:
986 if(tp->extra_info & CHIP_REV_MASK)
987 smctr_model = "8115T rev XE";
988 else
989 smctr_model = "8115T rev XD";
990 break;
991
992 default:
993 smctr_model = "Unknown";
994 break;
995 }
996
997
998 tp->bic_type = BIC_584_CHIP;
999 tp->nic_type = NIC_825_CHIP;
1000
1001
1002 tp->ram_usable = CNFG_SIZE_16KB;
1003 tp->ram_size = CNFG_SIZE_64KB;
1004
1005
1006 r1 = inb(ioaddr);
1007 r1 &= 0x3F;
1008
1009 r2 = inb(ioaddr + CNFG_LAAR_584);
1010 r2 &= CNFG_LAAR_MASK;
1011 r2 <<= 3;
1012 r2 |= ((r1 & 0x38) >> 3);
1013
1014 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1015
1016
1017 r1 = 0;
1018 r1 = inb(ioaddr + CNFG_ICR_583);
1019 r1 &= CNFG_ICR_IR2_584;
1020
1021 r2 = inb(ioaddr + CNFG_IRR_583);
1022 r2 &= CNFG_IRR_IRQS;
1023 r2 >>= 5;
1024
1025 switch(r2)
1026 {
1027 case 0:
1028 if(r1 == 0)
1029 dev->irq = 2;
1030 else
1031 dev->irq = 10;
1032 break;
1033
1034 case 1:
1035 if(r1 == 0)
1036 dev->irq = 3;
1037 else
1038 dev->irq = 11;
1039 break;
1040
1041 case 2:
1042 if(r1 == 0)
1043 {
1044 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1045 dev->irq = 5;
1046 else
1047 dev->irq = 4;
1048 }
1049 else
1050 dev->irq = 15;
1051 break;
1052
1053 case 3:
1054 if(r1 == 0)
1055 dev->irq = 7;
1056 else
1057 dev->irq = 4;
1058 break;
1059
1060 default:
1061 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1062 goto out2;
1063 }
1064
1065 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
1066 goto out2;
1067
1068
1069 r1 = inb(ioaddr + CNFG_BIO_583);
1070 r1 &= 0x3E;
1071 r1 |= 0x40;
1072
1073 tp->rom_base = (__u32)r1 << 13;
1074
1075
1076 r1 = inb(ioaddr + CNFG_BIO_583);
1077 r1 &= 0xC0;
1078 if(r1 == 0)
1079 tp->rom_size = ROM_DISABLE;
1080 else
1081 {
1082 r1 >>= 6;
1083 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1084 }
1085
1086
1087 r1 = inb(ioaddr + CNFG_GP2);
1088
1089 tp->mode_bits &= (~BOOT_STATUS_MASK);
1090
1091 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1092 tp->mode_bits |= BOOT_TYPE_1;
1093
1094
1095 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1096
1097 r1 = inb(ioaddr + CNFG_IRR_583);
1098
1099 if(r1 & CNFG_IRR_ZWS)
1100 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1101
1102 if(tp->board_id & BOARD_16BIT)
1103 {
1104 r1 = inb(ioaddr + CNFG_LAAR_584);
1105
1106 if(r1 & CNFG_LAAR_ZWS)
1107 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1108 }
1109
1110
1111 tp->media_menu = 14;
1112 r1 = inb(ioaddr + CNFG_IRR_583);
1113
1114 tp->mode_bits &= 0xf8ff;
1115 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1116 {
1117
1118 if(((r1 & 0x6) >> 1) == 0x3)
1119 tp->media_type |= MEDIA_UTP_16;
1120 else
1121 {
1122 if(((r1 & 0x6) >> 1) == 0x2)
1123 tp->media_type |= MEDIA_STP_16;
1124 else
1125 {
1126 if(((r1 & 0x6) >> 1) == 0x1)
1127 tp->media_type |= MEDIA_UTP_4;
1128
1129 else
1130 tp->media_type |= MEDIA_STP_4;
1131 }
1132 }
1133
1134 r1 = inb(ioaddr + CNFG_GP2);
1135 if(!(r1 & 0x2) )
1136 tp->mode_bits |= EARLY_TOKEN_REL;
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146 }
1147
1148 return 0;
1149
1150out2:
1151 release_region(ioaddr, SMCTR_IO_EXTENT);
1152out:
1153 return err;
1154}
1155
1156static int __init smctr_get_boardid(struct net_device *dev, int mca)
1157{
1158 struct net_local *tp = netdev_priv(dev);
1159 int ioaddr = dev->base_addr;
1160 __u8 r, r1, IdByte;
1161 __u16 BoardIdMask;
1162
1163 tp->board_id = BoardIdMask = 0;
1164
1165 if(mca)
1166 {
1167 BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1168 tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT);
1169 }
1170 else
1171 {
1172 BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1173 tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K
1174 + NIC_825_BIT + ALTERNATE_IRQ_BIT);
1175 }
1176
1177 if(!mca)
1178 {
1179 r = inb(ioaddr + BID_REG_1);
1180 r &= 0x0c;
1181 outb(r, ioaddr + BID_REG_1);
1182 r = inb(ioaddr + BID_REG_1);
1183
1184 if(r & BID_SIXTEEN_BIT_BIT)
1185 {
1186 tp->extra_info |= SLOT_16BIT;
1187 tp->adapter_bus = BUS_ISA16_TYPE;
1188 }
1189 else
1190 tp->adapter_bus = BUS_ISA8_TYPE;
1191 }
1192 else
1193 tp->adapter_bus = BUS_MCA_TYPE;
1194
1195
1196 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1197
1198
1199
1200
1201 if(IdByte & 0xF8)
1202 return -1;
1203
1204 r1 = inb(ioaddr + BID_REG_1);
1205 r1 &= BID_ICR_MASK;
1206 r1 |= BID_OTHER_BIT;
1207
1208 outb(r1, ioaddr + BID_REG_1);
1209 r1 = inb(ioaddr + BID_REG_3);
1210
1211 r1 &= BID_EAR_MASK;
1212 r1 |= BID_ENGR_PAGE;
1213
1214 outb(r1, ioaddr + BID_REG_3);
1215 r1 = inb(ioaddr + BID_REG_1);
1216 r1 &= BID_ICR_MASK;
1217 r1 |= (BID_RLA | BID_OTHER_BIT);
1218
1219 outb(r1, ioaddr + BID_REG_1);
1220
1221 r1 = inb(ioaddr + BID_REG_1);
1222 while(r1 & BID_RECALL_DONE_MASK)
1223 r1 = inb(ioaddr + BID_REG_1);
1224
1225 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1226
1227
1228 tp->extra_info &= ~CHIP_REV_MASK;
1229 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1230
1231 r1 = inb(ioaddr + BID_REG_1);
1232 r1 &= BID_ICR_MASK;
1233 r1 |= BID_OTHER_BIT;
1234
1235 outb(r1, ioaddr + BID_REG_1);
1236 r1 = inb(ioaddr + BID_REG_3);
1237
1238 r1 &= BID_EAR_MASK;
1239 r1 |= BID_EA6;
1240
1241 outb(r1, ioaddr + BID_REG_3);
1242 r1 = inb(ioaddr + BID_REG_1);
1243
1244 r1 &= BID_ICR_MASK;
1245 r1 |= BID_RLA;
1246
1247 outb(r1, ioaddr + BID_REG_1);
1248 r1 = inb(ioaddr + BID_REG_1);
1249
1250 while(r1 & BID_RECALL_DONE_MASK)
1251 r1 = inb(ioaddr + BID_REG_1);
1252
1253 return BoardIdMask;
1254}
1255
1256static int smctr_get_group_address(struct net_device *dev)
1257{
1258 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1259
1260 return smctr_wait_cmd(dev);
1261}
1262
1263static int smctr_get_functional_address(struct net_device *dev)
1264{
1265 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1266
1267 return smctr_wait_cmd(dev);
1268}
1269
1270
1271
1272
1273
1274static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1275{
1276 struct net_local *tp = netdev_priv(dev);
1277 unsigned int mem_used = 0;
1278
1279
1280 mem_used += sizeof(SCGBlock);
1281
1282 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1283 mem_used += sizeof(SCLBlock);
1284
1285 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1286 mem_used += sizeof(ACBlock) * tp->num_acbs;
1287
1288 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1289 mem_used += sizeof(ISBlock);
1290
1291 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1292 mem_used += MISC_DATA_SIZE;
1293
1294
1295 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1296
1297 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE];
1298 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE];
1299 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE];
1300
1301
1302 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE];
1303 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE];
1304 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE];
1305
1306
1307 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE];
1308 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE];
1309
1310
1311 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1312
1313
1314
1315
1316 mem_used += tp->tx_buff_size[MAC_QUEUE];
1317
1318
1319 mem_used += tp->tx_buff_size[BUG_QUEUE];
1320
1321
1322
1323
1324 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
1325
1326
1327
1328
1329
1330 mem_used += 1L;
1331 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1332 mem_used += 1L;
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347 mem_used += 0x100;
1348
1349 return (0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock));
1350}
1351
1352static int smctr_get_physical_drop_number(struct net_device *dev)
1353{
1354 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1355
1356 return smctr_wait_cmd(dev);
1357}
1358
1359static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1360{
1361 struct net_local *tp = netdev_priv(dev);
1362 BDBlock *bdb;
1363
1364 bdb = (BDBlock *)((__u32)tp->ram_access
1365 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1366
1367 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1368
1369 return (__u8 *)bdb->data_block_ptr;
1370}
1371
1372static int smctr_get_station_id(struct net_device *dev)
1373{
1374 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1375
1376 return smctr_wait_cmd(dev);
1377}
1378
1379
1380
1381
1382
1383static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1384{
1385 struct net_local *tp = netdev_priv(dev);
1386
1387 return (struct net_device_stats *)&tp->MacStat;
1388}
1389
1390static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1391 __u16 bytes_count)
1392{
1393 struct net_local *tp = netdev_priv(dev);
1394 FCBlock *pFCB;
1395 BDBlock *pbdb;
1396 unsigned short alloc_size;
1397 unsigned short *temp;
1398
1399 if(smctr_debug > 20)
1400 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
1401
1402
1403 if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue])
1404 return (FCBlock *)(-1L);
1405
1406
1407 alloc_size = (bytes_count + 1) & 0xfffe;
1408
1409
1410 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
1411 return (FCBlock *)(-1L);
1412
1413
1414
1415
1416
1417 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1418 >= (unsigned long)(tp->tx_buff_end[queue]))
1419 {
1420
1421 alloc_size = alloc_size +
1422 (__u16)((__u32)tp->tx_buff_end[queue]
1423 - (__u32)tp->tx_buff_curr[queue]);
1424
1425 if((tp->tx_buff_used[queue] + alloc_size)
1426 > tp->tx_buff_size[queue])
1427 {
1428 return (FCBlock *)(-1L);
1429 }
1430
1431
1432 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
1433 }
1434
1435 tp->tx_buff_used[queue] += alloc_size;
1436 tp->num_tx_fcbs_used[queue]++;
1437 tp->tx_fcb_curr[queue]->frame_length = bytes_count;
1438 tp->tx_fcb_curr[queue]->memory_alloc = alloc_size;
1439 temp = tp->tx_buff_curr[queue];
1440 tp->tx_buff_curr[queue]
1441 = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe));
1442
1443 pbdb = tp->tx_fcb_curr[queue]->bdb_ptr;
1444 pbdb->buffer_length = bytes_count;
1445 pbdb->data_block_ptr = temp;
1446 pbdb->trc_data_block_ptr = TRC_POINTER(temp);
1447
1448 pFCB = tp->tx_fcb_curr[queue];
1449 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1450
1451 return pFCB;
1452}
1453
1454static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1455{
1456 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1457
1458 return smctr_wait_cmd(dev);
1459}
1460
1461static int smctr_hardware_send_packet(struct net_device *dev,
1462 struct net_local *tp)
1463{
1464 struct tr_statistics *tstat = &tp->MacStat;
1465 struct sk_buff *skb;
1466 FCBlock *fcb;
1467
1468 if(smctr_debug > 10)
1469 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1470
1471 if(tp->status != OPEN)
1472 return -1;
1473
1474 if(tp->monitor_state_ready != 1)
1475 return -1;
1476
1477 for(;;)
1478 {
1479
1480 skb = skb_dequeue(&tp->SendSkbQueue);
1481 if(skb == NULL)
1482 return -1;
1483
1484 tp->QueueSkb++;
1485
1486 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size)
1487 return -1;
1488
1489 smctr_enable_16bit(dev);
1490 smctr_set_page(dev, (__u8 *)tp->ram_access);
1491
1492 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1493 == (FCBlock *)(-1L))
1494 {
1495 smctr_disable_16bit(dev);
1496 return -1;
1497 }
1498
1499 smctr_tx_move_frame(dev, skb,
1500 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1501
1502 smctr_set_page(dev, (__u8 *)fcb);
1503
1504 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1505 dev_kfree_skb(skb);
1506
1507 tstat->tx_packets++;
1508
1509 smctr_disable_16bit(dev);
1510 }
1511
1512 return 0;
1513}
1514
1515static int smctr_init_acbs(struct net_device *dev)
1516{
1517 struct net_local *tp = netdev_priv(dev);
1518 unsigned int i;
1519 ACBlock *acb;
1520
1521 if(smctr_debug > 10)
1522 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1523
1524 acb = tp->acb_head;
1525 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1526 acb->cmd_info = ACB_CHAIN_END;
1527 acb->cmd = 0;
1528 acb->subcmd = 0;
1529 acb->data_offset_lo = 0;
1530 acb->data_offset_hi = 0;
1531 acb->next_ptr
1532 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1533 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1534
1535 for(i = 1; i < tp->num_acbs; i++)
1536 {
1537 acb = acb->next_ptr;
1538 acb->cmd_done_status
1539 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1540 acb->cmd_info = ACB_CHAIN_END;
1541 acb->cmd = 0;
1542 acb->subcmd = 0;
1543 acb->data_offset_lo = 0;
1544 acb->data_offset_hi = 0;
1545 acb->next_ptr
1546 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1547 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1548 }
1549
1550 acb->next_ptr = tp->acb_head;
1551 acb->trc_next_ptr = TRC_POINTER(tp->acb_head);
1552 tp->acb_next = tp->acb_head->next_ptr;
1553 tp->acb_curr = tp->acb_head->next_ptr;
1554 tp->num_acbs_used = 0;
1555
1556 return 0;
1557}
1558
1559static int smctr_init_adapter(struct net_device *dev)
1560{
1561 struct net_local *tp = netdev_priv(dev);
1562 int err;
1563
1564 if(smctr_debug > 10)
1565 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
1566
1567 tp->status = CLOSED;
1568 tp->page_offset_mask = (tp->ram_usable * 1024) - 1;
1569 skb_queue_head_init(&tp->SendSkbQueue);
1570 tp->QueueSkb = MAX_TX_QUEUE;
1571
1572 if(!(tp->group_address_0 & 0x0080))
1573 tp->group_address_0 |= 0x00C0;
1574
1575 if(!(tp->functional_address_0 & 0x00C0))
1576 tp->functional_address_0 |= 0x00C0;
1577
1578 tp->functional_address[0] &= 0xFF7F;
1579
1580 if(tp->authorized_function_classes == 0)
1581 tp->authorized_function_classes = 0x7FFF;
1582
1583 if(tp->authorized_access_priority == 0)
1584 tp->authorized_access_priority = 0x06;
1585
1586 smctr_disable_bic_int(dev);
1587 smctr_set_trc_reset(dev->base_addr);
1588
1589 smctr_enable_16bit(dev);
1590 smctr_set_page(dev, (__u8 *)tp->ram_access);
1591
1592 if(smctr_checksum_firmware(dev))
1593 {
1594 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name);
1595 return -ENOENT;
1596 }
1597
1598 if((err = smctr_ram_memory_test(dev)))
1599 {
1600 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1601 return -EIO;
1602 }
1603
1604 smctr_set_rx_look_ahead(dev);
1605 smctr_load_node_addr(dev);
1606
1607
1608 smctr_reset_adapter(dev);
1609 if((err = smctr_init_card_real(dev)))
1610 {
1611 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1612 dev->name, err);
1613 return -EINVAL;
1614 }
1615
1616
1617 if((err = smctr_internal_self_test(dev)))
1618 {
1619 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1620 dev->name, err);
1621 return -EINVAL;
1622 }
1623
1624
1625 smctr_reset_adapter(dev);
1626 if((err = smctr_init_card_real(dev)))
1627 {
1628 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1629 dev->name, err);
1630 return -EINVAL;
1631 }
1632
1633 smctr_enable_bic_int(dev);
1634
1635 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1636 return err;
1637
1638 smctr_disable_16bit(dev);
1639
1640 return 0;
1641}
1642
1643static int smctr_init_card_real(struct net_device *dev)
1644{
1645 struct net_local *tp = netdev_priv(dev);
1646 int err = 0;
1647
1648 if(smctr_debug > 10)
1649 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1650
1651 tp->sh_mem_used = 0;
1652 tp->num_acbs = NUM_OF_ACBS;
1653
1654
1655 if(tp->max_packet_size < 256)
1656 tp->max_packet_size = 256;
1657 else
1658 {
1659 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1660 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1661 }
1662
1663 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1664 / tp->max_packet_size) - 1;
1665
1666 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1667 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1668 else
1669 {
1670 if(tp->num_of_tx_buffs == 0)
1671 tp->num_of_tx_buffs = 1;
1672 }
1673
1674
1675 tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS;
1676 tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS;
1677 tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY;
1678 tp->tx_buff_used [BUG_QUEUE] = 0;
1679 tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING;
1680
1681 tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS;
1682 tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS;
1683 tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY;
1684 tp->tx_buff_used [MAC_QUEUE] = 0;
1685 tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING;
1686
1687 tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
1688 tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
1689 tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
1690 tp->tx_buff_used [NON_MAC_QUEUE] = 0;
1691 tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING;
1692
1693
1694 tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
1695 tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
1696
1697 if(tp->extra_info & CHIP_REV_MASK)
1698 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78;
1699 else
1700 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7;
1701
1702 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1703
1704 smctr_alloc_shared_memory(dev);
1705 smctr_init_shared_memory(dev);
1706
1707 if((err = smctr_issue_init_timers_cmd(dev)))
1708 return err;
1709
1710 if((err = smctr_issue_init_txrx_cmd(dev)))
1711 {
1712 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1713 return err;
1714 }
1715
1716 return 0;
1717}
1718
1719static int smctr_init_rx_bdbs(struct net_device *dev)
1720{
1721 struct net_local *tp = netdev_priv(dev);
1722 unsigned int i, j;
1723 BDBlock *bdb;
1724 __u16 *buf;
1725
1726 if(smctr_debug > 10)
1727 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1728
1729 for(i = 0; i < NUM_RX_QS_USED; i++)
1730 {
1731 bdb = tp->rx_bdb_head[i];
1732 buf = tp->rx_buff_head[i];
1733 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
1734 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1735 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1736 bdb->data_block_ptr = buf;
1737 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1738
1739 if(i == NON_MAC_QUEUE)
1740 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1741 else
1742 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1743
1744 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1745 {
1746 bdb->next_ptr->back_ptr = bdb;
1747 bdb = bdb->next_ptr;
1748 buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
1749 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1750 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1751 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1752 bdb->data_block_ptr = buf;
1753 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1754
1755 if(i == NON_MAC_QUEUE)
1756 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1757 else
1758 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1759 }
1760
1761 bdb->next_ptr = tp->rx_bdb_head[i];
1762 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1763
1764 tp->rx_bdb_head[i]->back_ptr = bdb;
1765 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1766 }
1767
1768 return 0;
1769}
1770
1771static int smctr_init_rx_fcbs(struct net_device *dev)
1772{
1773 struct net_local *tp = netdev_priv(dev);
1774 unsigned int i, j;
1775 FCBlock *fcb;
1776
1777 for(i = 0; i < NUM_RX_QS_USED; i++)
1778 {
1779 fcb = tp->rx_fcb_head[i];
1780 fcb->frame_status = 0;
1781 fcb->frame_length = 0;
1782 fcb->info = FCB_CHAIN_END;
1783 fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
1784 if(i == NON_MAC_QUEUE)
1785 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1786 else
1787 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1788
1789 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1790 {
1791 fcb->next_ptr->back_ptr = fcb;
1792 fcb = fcb->next_ptr;
1793 fcb->frame_status = 0;
1794 fcb->frame_length = 0;
1795 fcb->info = FCB_WARNING;
1796 fcb->next_ptr
1797 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1798
1799 if(i == NON_MAC_QUEUE)
1800 fcb->trc_next_ptr
1801 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1802 else
1803 fcb->trc_next_ptr
1804 = TRC_POINTER(fcb->next_ptr);
1805 }
1806
1807 fcb->next_ptr = tp->rx_fcb_head[i];
1808
1809 if(i == NON_MAC_QUEUE)
1810 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1811 else
1812 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1813
1814 tp->rx_fcb_head[i]->back_ptr = fcb;
1815 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1816 }
1817
1818 return 0;
1819}
1820
1821static int smctr_init_shared_memory(struct net_device *dev)
1822{
1823 struct net_local *tp = netdev_priv(dev);
1824 unsigned int i;
1825 __u32 *iscpb;
1826
1827 if(smctr_debug > 10)
1828 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1829
1830 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1831
1832
1833 iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
1834 *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
1835
1836 smctr_set_page(dev, (__u8 *)tp->ram_access);
1837
1838
1839 tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
1840 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
1841 | SCGB_BURST_LENGTH);
1842
1843 tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr);
1844 tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head);
1845 tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr);
1846 tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2;
1847
1848
1849 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP;
1850 tp->sclb_ptr->iack_code = 0;
1851 tp->sclb_ptr->resume_control = 0;
1852 tp->sclb_ptr->int_mask_control = 0;
1853 tp->sclb_ptr->int_mask_state = 0;
1854
1855
1856 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1857 {
1858 tp->isb_ptr->IStatus[i].IType = 0xf0;
1859 tp->isb_ptr->IStatus[i].ISubtype = 0;
1860 }
1861
1862 tp->current_isb_index = 0;
1863
1864
1865 smctr_init_acbs(dev);
1866
1867
1868 smctr_link_tx_fcbs_to_bdbs(dev);
1869 smctr_init_tx_bdbs(dev);
1870 smctr_init_tx_fcbs(dev);
1871
1872
1873 smctr_init_rx_bdbs(dev);
1874 smctr_init_rx_fcbs(dev);
1875
1876 return 0;
1877}
1878
1879static int smctr_init_tx_bdbs(struct net_device *dev)
1880{
1881 struct net_local *tp = netdev_priv(dev);
1882 unsigned int i, j;
1883 BDBlock *bdb;
1884
1885 for(i = 0; i < NUM_TX_QS_USED; i++)
1886 {
1887 bdb = tp->tx_bdb_head[i];
1888 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1889 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1890 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1891
1892 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1893 {
1894 bdb->next_ptr->back_ptr = bdb;
1895 bdb = bdb->next_ptr;
1896 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1897 bdb->next_ptr
1898 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1899 }
1900
1901 bdb->next_ptr = tp->tx_bdb_head[i];
1902 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
1903 tp->tx_bdb_head[i]->back_ptr = bdb;
1904 }
1905
1906 return 0;
1907}
1908
1909static int smctr_init_tx_fcbs(struct net_device *dev)
1910{
1911 struct net_local *tp = netdev_priv(dev);
1912 unsigned int i, j;
1913 FCBlock *fcb;
1914
1915 for(i = 0; i < NUM_TX_QS_USED; i++)
1916 {
1917 fcb = tp->tx_fcb_head[i];
1918 fcb->frame_status = 0;
1919 fcb->frame_length = 0;
1920 fcb->info = FCB_CHAIN_END;
1921 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1922 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1923
1924 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1925 {
1926 fcb->next_ptr->back_ptr = fcb;
1927 fcb = fcb->next_ptr;
1928 fcb->frame_status = 0;
1929 fcb->frame_length = 0;
1930 fcb->info = FCB_CHAIN_END;
1931 fcb->next_ptr
1932 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1933 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1934 }
1935
1936 fcb->next_ptr = tp->tx_fcb_head[i];
1937 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1938
1939 tp->tx_fcb_head[i]->back_ptr = fcb;
1940 tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr;
1941 tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr;
1942 tp->num_tx_fcbs_used[i] = 0;
1943 }
1944
1945 return 0;
1946}
1947
1948static int smctr_internal_self_test(struct net_device *dev)
1949{
1950 struct net_local *tp = netdev_priv(dev);
1951 int err;
1952
1953 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1954 return err;
1955
1956 if((err = smctr_wait_cmd(dev)))
1957 return err;
1958
1959 if(tp->acb_head->cmd_done_status & 0xff)
1960 return -1;
1961
1962 if((err = smctr_issue_test_hic_cmd(dev)))
1963 return err;
1964
1965 if((err = smctr_wait_cmd(dev)))
1966 return err;
1967
1968 if(tp->acb_head->cmd_done_status & 0xff)
1969 return -1;
1970
1971 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1972 return err;
1973
1974 if((err = smctr_wait_cmd(dev)))
1975 return err;
1976
1977 if(tp->acb_head->cmd_done_status & 0xff)
1978 return -1;
1979
1980 return 0;
1981}
1982
1983
1984
1985
1986static irqreturn_t smctr_interrupt(int irq, void *dev_id)
1987{
1988 struct net_device *dev = dev_id;
1989 struct net_local *tp;
1990 int ioaddr;
1991 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1992 __u16 err1, err = NOT_MY_INTERRUPT;
1993 __u8 isb_type, isb_subtype;
1994 __u16 isb_index;
1995
1996 ioaddr = dev->base_addr;
1997 tp = netdev_priv(dev);
1998
1999 if(tp->status == NOT_INITIALIZED)
2000 return IRQ_NONE;
2001
2002 spin_lock(&tp->lock);
2003
2004 smctr_disable_bic_int(dev);
2005 smctr_enable_16bit(dev);
2006
2007 smctr_clear_int(dev);
2008
2009
2010 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2011 {
2012 isb_index = tp->current_isb_index;
2013 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2014 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2015
2016 (tp->current_isb_index)++;
2017 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2018 tp->current_isb_index = 0;
2019
2020 if(isb_type >= 0x10)
2021 {
2022 smctr_disable_16bit(dev);
2023 spin_unlock(&tp->lock);
2024 return IRQ_HANDLED;
2025 }
2026
2027 err = HARDWARE_FAILED;
2028 interrupt_ack_code = isb_index;
2029 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2030
2031 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2032
2033 switch(isb_type)
2034 {
2035 case ISB_IMC_MAC_TYPE_3:
2036 smctr_disable_16bit(dev);
2037
2038 switch(isb_subtype)
2039 {
2040 case 0:
2041 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2042 break;
2043
2044 case 1:
2045 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2046 break;
2047
2048 case 2:
2049 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2050 break;
2051
2052 case 3:
2053 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2054
2055 case 4:
2056 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2057 break;
2058
2059 case 5:
2060 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2061 break;
2062
2063 case 6:
2064 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2065 break;
2066
2067 case 7:
2068 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2069 break;
2070
2071 case 8:
2072 break;
2073
2074 case 9:
2075 tp->monitor_state = MS_BEACON_TEST_STATE;
2076 if(smctr_lobe_media_test(dev))
2077 {
2078 tp->ring_status_flags = RING_STATUS_CHANGED;
2079 tp->ring_status = AUTO_REMOVAL_ERROR;
2080 smctr_ring_status_chg(dev);
2081 smctr_bypass_state(dev);
2082 }
2083 else
2084 smctr_issue_insert_cmd(dev);
2085 break;
2086
2087
2088 default:
2089 break;
2090 }
2091
2092 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2093 err = smctr_ring_status_chg(dev);
2094
2095 smctr_enable_16bit(dev);
2096 break;
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109 case ISB_IMC_MAC_ERROR_COUNTERS:
2110
2111 err = smctr_issue_read_ring_status_cmd(dev);
2112 break;
2113
2114
2115
2116
2117
2118
2119 case ISB_IMC_MAC_TYPE_2:
2120 err = smctr_issue_read_ring_status_cmd(dev);
2121 break;
2122
2123
2124
2125 case ISB_IMC_TX_FRAME:
2126
2127 if(isb_subtype & TX_PENDING_PRIORITY_2)
2128 {
2129 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2130 break;
2131 }
2132
2133
2134 if(isb_subtype & TX_PENDING_PRIORITY_1)
2135 {
2136 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2137 break;
2138 }
2139
2140
2141 if(isb_subtype & TX_PENDING_PRIORITY_0)
2142 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2143
2144
2145 case ISB_IMC_END_OF_TX_QUEUE:
2146
2147 if(isb_subtype & TX_PENDING_PRIORITY_2)
2148 {
2149
2150
2151
2152 interrupt_unmask_bits |= 0x800;
2153
2154 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2155 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2156 break;
2157 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2158 break;
2159 }
2160
2161
2162 if(isb_subtype & TX_PENDING_PRIORITY_1)
2163 {
2164 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2165 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2166 break;
2167 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2168 break;
2169 }
2170
2171
2172 if(isb_subtype & TX_PENDING_PRIORITY_0)
2173 {
2174 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2175 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2176 break;
2177
2178 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2179 }
2180 break;
2181
2182
2183
2184
2185
2186
2187
2188 case ISB_IMC_NON_MAC_RX_RESOURCE:
2189 tp->rx_fifo_overrun_count = 0;
2190 tp->receive_queue_number = NON_MAC_QUEUE;
2191 err1 = smctr_rx_frame(dev);
2192
2193 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2194 {
2195 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2196
2197 if(tp->ptr_rx_fcb_overruns)
2198 (*tp->ptr_rx_fcb_overruns)++;
2199 }
2200
2201 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2202 {
2203 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2204
2205 if(tp->ptr_rx_bdb_overruns)
2206 (*tp->ptr_rx_bdb_overruns)++;
2207 }
2208 err = err1;
2209 break;
2210
2211
2212
2213
2214
2215
2216
2217 case ISB_IMC_MAC_RX_RESOURCE:
2218 tp->receive_queue_number = MAC_QUEUE;
2219 err1 = smctr_rx_frame(dev);
2220
2221 if(isb_subtype & MAC_RX_RESOURCE_FE)
2222 {
2223 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2224 break;
2225
2226 if(tp->ptr_rx_fcb_overruns)
2227 (*tp->ptr_rx_fcb_overruns)++;
2228 }
2229
2230 if(isb_subtype & MAC_RX_RESOURCE_BE)
2231 {
2232 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2233 break;
2234
2235 if(tp->ptr_rx_bdb_overruns)
2236 (*tp->ptr_rx_bdb_overruns)++;
2237 }
2238 err = err1;
2239 break;
2240
2241
2242 case ISB_IMC_NON_MAC_RX_FRAME:
2243 tp->rx_fifo_overrun_count = 0;
2244 tp->receive_queue_number = NON_MAC_QUEUE;
2245 err = smctr_rx_frame(dev);
2246 break;
2247
2248
2249 case ISB_IMC_MAC_RX_FRAME:
2250 tp->receive_queue_number = MAC_QUEUE;
2251 err = smctr_rx_frame(dev);
2252 break;
2253
2254
2255
2256
2257
2258
2259 case ISB_IMC_TRC_FIFO_STATUS:
2260 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2261 {
2262 if(tp->ptr_tx_fifo_underruns)
2263 (*tp->ptr_tx_fifo_underruns)++;
2264 }
2265
2266 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2267 {
2268
2269
2270
2271
2272
2273 tp->rx_fifo_overrun_count++;
2274
2275 if(tp->rx_fifo_overrun_count >= 3)
2276 {
2277 tp->rx_fifo_overrun_count = 0;
2278
2279
2280
2281
2282
2283 interrupt_unmask_bits &= (~0x800);
2284 printk(KERN_CRIT "Jay please send bug\n");
2285 }
2286
2287 if(tp->ptr_rx_fifo_overruns)
2288 (*tp->ptr_rx_fifo_overruns)++;
2289 }
2290
2291 err = SUCCESS;
2292 break;
2293
2294
2295
2296
2297
2298 case ISB_IMC_COMMAND_STATUS:
2299 err = SUCCESS;
2300 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2301 {
2302 printk(KERN_ERR "i1\n");
2303 smctr_disable_16bit(dev);
2304
2305
2306
2307
2308 smctr_enable_16bit(dev);
2309 }
2310 else
2311 {
2312 if((tp->acb_head->cmd
2313 == ACB_CMD_READ_TRC_STATUS) &&
2314 (tp->acb_head->subcmd
2315 == RW_TRC_STATUS_BLOCK))
2316 {
2317 if(tp->ptr_bcn_type)
2318 {
2319 *(tp->ptr_bcn_type)
2320 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2321 }
2322
2323 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2324 {
2325 smctr_update_err_stats(dev);
2326 }
2327
2328 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2329 {
2330 tp->ring_status
2331 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2332 smctr_disable_16bit(dev);
2333 err = smctr_ring_status_chg(dev);
2334 smctr_enable_16bit(dev);
2335 if((tp->ring_status & REMOVE_RECEIVED) &&
2336 (tp->config_word0 & NO_AUTOREMOVE))
2337 {
2338 smctr_issue_remove_cmd(dev);
2339 }
2340
2341 if(err != SUCCESS)
2342 {
2343 tp->acb_pending = 0;
2344 break;
2345 }
2346 }
2347
2348 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2349 {
2350 if(tp->ptr_una)
2351 {
2352 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2353 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2354 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2355 }
2356
2357 }
2358
2359 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2360 err = smctr_send_rq_init(dev);
2361 }
2362 }
2363 }
2364
2365 tp->acb_pending = 0;
2366 break;
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377 case ISB_IMC_MAC_TYPE_1:
2378 if(isb_subtype > 8)
2379 {
2380 err = HARDWARE_FAILED;
2381 break;
2382 }
2383
2384 err = SUCCESS;
2385 switch(isb_subtype)
2386 {
2387 case 0:
2388 tp->join_state = JS_BYPASS_STATE;
2389 if(tp->status != CLOSED)
2390 {
2391 tp->status = CLOSED;
2392 err = smctr_status_chg(dev);
2393 }
2394 break;
2395
2396 case 1:
2397 tp->join_state = JS_LOBE_TEST_STATE;
2398 break;
2399
2400 case 2:
2401 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2402 break;
2403
2404 case 3:
2405 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2406 break;
2407
2408 case 4:
2409 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2410 break;
2411
2412 case 5:
2413 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2414 break;
2415
2416 case 6:
2417 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2418 break;
2419
2420 case 7:
2421 tp->join_state = JS_JOIN_COMPLETE_STATE;
2422 tp->status = OPEN;
2423 err = smctr_status_chg(dev);
2424 break;
2425
2426 case 8:
2427 tp->join_state = JS_BYPASS_WAIT_STATE;
2428 break;
2429 }
2430 break ;
2431
2432
2433
2434
2435 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2436 tp->status = INITIALIZED;
2437 smctr_disable_16bit(dev);
2438 err = smctr_status_chg(dev);
2439 smctr_enable_16bit(dev);
2440 break;
2441
2442
2443 default:
2444 break;
2445 }
2446
2447 if(err != SUCCESS)
2448 break;
2449 }
2450
2451
2452
2453
2454
2455
2456 if(!(interrupt_ack_code & 0xff00))
2457 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2458
2459 smctr_disable_16bit(dev);
2460 smctr_enable_bic_int(dev);
2461 spin_unlock(&tp->lock);
2462
2463 return IRQ_HANDLED;
2464}
2465
2466static int smctr_issue_enable_int_cmd(struct net_device *dev,
2467 __u16 interrupt_enable_mask)
2468{
2469 struct net_local *tp = netdev_priv(dev);
2470 int err;
2471
2472 if((err = smctr_wait_while_cbusy(dev)))
2473 return err;
2474
2475 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2476 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2477
2478 smctr_set_ctrl_attention(dev);
2479
2480 return 0;
2481}
2482
2483static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2484{
2485 struct net_local *tp = netdev_priv(dev);
2486
2487 if(smctr_wait_while_cbusy(dev))
2488 return -1;
2489
2490 tp->sclb_ptr->int_mask_control = ibits;
2491 tp->sclb_ptr->iack_code = iack_code << 1; tp->sclb_ptr->resume_control = 0;
2492 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2493
2494 smctr_set_ctrl_attention(dev);
2495
2496 return 0;
2497}
2498
2499static int smctr_issue_init_timers_cmd(struct net_device *dev)
2500{
2501 struct net_local *tp = netdev_priv(dev);
2502 unsigned int i;
2503 int err;
2504 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2505
2506 if((err = smctr_wait_while_cbusy(dev)))
2507 return err;
2508
2509 if((err = smctr_wait_cmd(dev)))
2510 return err;
2511
2512 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2513 tp->config_word1 = 0;
2514
2515 if((tp->media_type == MEDIA_STP_16) ||
2516 (tp->media_type == MEDIA_UTP_16) ||
2517 (tp->media_type == MEDIA_STP_16_UTP_16))
2518 {
2519 tp->config_word0 |= FREQ_16MB_BIT;
2520 }
2521
2522 if(tp->mode_bits & EARLY_TOKEN_REL)
2523 tp->config_word0 |= ETREN;
2524
2525 if(tp->mode_bits & LOOPING_MODE_MASK)
2526 tp->config_word0 |= RX_OWN_BIT;
2527 else
2528 tp->config_word0 &= ~RX_OWN_BIT;
2529
2530 if(tp->receive_mask & PROMISCUOUS_MODE)
2531 tp->config_word0 |= PROMISCUOUS_BIT;
2532 else
2533 tp->config_word0 &= ~PROMISCUOUS_BIT;
2534
2535 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2536 tp->config_word0 |= SAVBAD_BIT;
2537 else
2538 tp->config_word0 &= ~SAVBAD_BIT;
2539
2540 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2541 tp->config_word0 |= RXATMAC;
2542 else
2543 tp->config_word0 &= ~RXATMAC;
2544
2545 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2546 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2547 else
2548 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2549
2550 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2551 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2552 else
2553 {
2554 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2555 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2556 else
2557 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2558 }
2559
2560 if((tp->media_type == MEDIA_STP_16) ||
2561 (tp->media_type == MEDIA_UTP_16) ||
2562 (tp->media_type == MEDIA_STP_16_UTP_16))
2563 {
2564 tp->config_word1 |= INTERFRAME_SPACING_16;
2565 }
2566 else
2567 tp->config_word1 |= INTERFRAME_SPACING_4;
2568
2569 *pTimer_Struc++ = tp->config_word0;
2570 *pTimer_Struc++ = tp->config_word1;
2571
2572 if((tp->media_type == MEDIA_STP_4) ||
2573 (tp->media_type == MEDIA_UTP_4) ||
2574 (tp->media_type == MEDIA_STP_4_UTP_4))
2575 {
2576 *pTimer_Struc++ = 0x00FA;
2577 *pTimer_Struc++ = 0x2710;
2578 *pTimer_Struc++ = 0x2710;
2579 *pTimer_Struc++ = 0x0A28;
2580 *pTimer_Struc++ = 0x3E80;
2581 *pTimer_Struc++ = 0x3A98;
2582 *pTimer_Struc++ = 0x1B58;
2583 *pTimer_Struc++ = 0x00C8;
2584 *pTimer_Struc++ = 0x07D0;
2585 *pTimer_Struc++ = 0x000A;
2586 *pTimer_Struc++ = 0x1162;
2587 *pTimer_Struc++ = 0x07D0;
2588 *pTimer_Struc++ = 0x1388;
2589 *pTimer_Struc++ = 0x0000;
2590 }
2591 else
2592 {
2593 *pTimer_Struc++ = 0x03E8;
2594 *pTimer_Struc++ = 0x9C40;
2595 *pTimer_Struc++ = 0x9C40;
2596 *pTimer_Struc++ = 0x0A28;
2597 *pTimer_Struc++ = 0x3E80;
2598 *pTimer_Struc++ = 0x3A98;
2599 *pTimer_Struc++ = 0x1B58;
2600 *pTimer_Struc++ = 0x00C8;
2601 *pTimer_Struc++ = 0x07D0;
2602 *pTimer_Struc++ = 0x000A;
2603 *pTimer_Struc++ = 0x4588;
2604 *pTimer_Struc++ = 0x1F40;
2605 *pTimer_Struc++ = 0x4E20;
2606 *pTimer_Struc++ = 0x0000;
2607 }
2608
2609
2610 *pTimer_Struc++ = dev->dev_addr[0] << 8
2611 | (dev->dev_addr[1] & 0xFF);
2612 *pTimer_Struc++ = dev->dev_addr[2] << 8
2613 | (dev->dev_addr[3] & 0xFF);
2614 *pTimer_Struc++ = dev->dev_addr[4] << 8
2615 | (dev->dev_addr[5] & 0xFF);
2616
2617
2618 *pTimer_Struc++ = tp->group_address_0 << 8
2619 | tp->group_address_0 >> 8;
2620 *pTimer_Struc++ = tp->group_address[0] << 8
2621 | tp->group_address[0] >> 8;
2622 *pTimer_Struc++ = tp->group_address[1] << 8
2623 | tp->group_address[1] >> 8;
2624
2625
2626 *pTimer_Struc++ = tp->functional_address_0 << 8
2627 | tp->functional_address_0 >> 8;
2628 *pTimer_Struc++ = tp->functional_address[0] << 8
2629 | tp->functional_address[0] >> 8;
2630 *pTimer_Struc++ = tp->functional_address[1] << 8
2631 | tp->functional_address[1] >> 8;
2632
2633
2634 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2635 | tp->bitwise_group_address[0] >> 8;
2636 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2637 | tp->bitwise_group_address[1] >> 8;
2638
2639
2640 *pTimer_Struc++ = tp->source_ring_number;
2641 *pTimer_Struc++ = tp->target_ring_number;
2642
2643
2644 *pTimer_Struc++ = (unsigned short)0;
2645 *pTimer_Struc++ = (unsigned short)0;
2646
2647
2648 for(i = 0; i < 9; i++)
2649 *pTimer_Struc++ = (unsigned short)0;
2650
2651 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2652
2653 return err;
2654}
2655
2656static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2657{
2658 struct net_local *tp = netdev_priv(dev);
2659 unsigned int i;
2660 int err;
2661 void **txrx_ptrs = (void *)tp->misc_command_data;
2662
2663 if((err = smctr_wait_while_cbusy(dev)))
2664 return err;
2665
2666 if((err = smctr_wait_cmd(dev)))
2667 {
2668 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2669 return err;
2670 }
2671
2672
2673
2674
2675 for(i = 0; i < NUM_TX_QS_USED; i++)
2676 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2677
2678
2679 for(; i < MAX_TX_QS; i++)
2680 *txrx_ptrs++ = (void *)0;
2681
2682
2683
2684
2685 for(i = 0; i < NUM_RX_QS_USED; i++)
2686 {
2687 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2688 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2689 }
2690
2691
2692 for(; i < MAX_RX_QS; i++)
2693 {
2694 *txrx_ptrs++ = (void *)0;
2695 *txrx_ptrs++ = (void *)0;
2696 }
2697
2698 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2699
2700 return err;
2701}
2702
2703static int smctr_issue_insert_cmd(struct net_device *dev)
2704{
2705 int err;
2706
2707 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2708
2709 return err;
2710}
2711
2712static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2713{
2714 int err;
2715
2716 if((err = smctr_wait_while_cbusy(dev)))
2717 return err;
2718
2719 if((err = smctr_wait_cmd(dev)))
2720 return err;
2721
2722 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2723 RW_TRC_STATUS_BLOCK);
2724
2725 return err;
2726}
2727
2728static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2729{
2730 int err;
2731
2732 if((err = smctr_wait_while_cbusy(dev)))
2733 return err;
2734
2735 if((err = smctr_wait_cmd(dev)))
2736 return err;
2737
2738 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2739 aword_cnt);
2740
2741 return err;
2742}
2743
2744static int smctr_issue_remove_cmd(struct net_device *dev)
2745{
2746 struct net_local *tp = netdev_priv(dev);
2747 int err;
2748
2749 if((err = smctr_wait_while_cbusy(dev)))
2750 return err;
2751
2752 tp->sclb_ptr->resume_control = 0;
2753 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2754
2755 smctr_set_ctrl_attention(dev);
2756
2757 return 0;
2758}
2759
2760static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2761{
2762 struct net_local *tp = netdev_priv(dev);
2763 int err;
2764
2765 if((err = smctr_wait_while_cbusy(dev)))
2766 return err;
2767
2768 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2769 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2770
2771 tp->acb_pending = 1;
2772
2773 smctr_set_ctrl_attention(dev);
2774
2775 return 0;
2776}
2777
2778static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2779{
2780 struct net_local *tp = netdev_priv(dev);
2781 int err;
2782
2783 if((err = smctr_wait_while_cbusy(dev)))
2784 return err;
2785
2786 if(queue == MAC_QUEUE)
2787 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2788 else
2789 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2790
2791 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2792
2793 smctr_set_ctrl_attention(dev);
2794
2795 return 0;
2796}
2797
2798static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2799{
2800 struct net_local *tp = netdev_priv(dev);
2801
2802 if(smctr_debug > 10)
2803 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2804
2805 if(smctr_wait_while_cbusy(dev))
2806 return -1;
2807
2808 if(queue == MAC_QUEUE)
2809 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2810 else
2811 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2812
2813 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2814
2815 smctr_set_ctrl_attention(dev);
2816
2817 return 0;
2818}
2819
2820static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2821{
2822 struct net_local *tp = netdev_priv(dev);
2823
2824 if(smctr_debug > 10)
2825 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2826
2827 if(smctr_wait_while_cbusy(dev))
2828 return -1;
2829
2830 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2831 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2832
2833 smctr_set_ctrl_attention(dev);
2834
2835 return 0;
2836}
2837
2838static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2839{
2840 int err;
2841
2842 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2843 TRC_INTERNAL_ROM_TEST);
2844
2845 return err;
2846}
2847
2848static int smctr_issue_test_hic_cmd(struct net_device *dev)
2849{
2850 int err;
2851
2852 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2853 TRC_HOST_INTERFACE_REG_TEST);
2854
2855 return err;
2856}
2857
2858static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2859{
2860 int err;
2861
2862 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2863 TRC_MAC_REGISTERS_TEST);
2864
2865 return err;
2866}
2867
2868static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2869{
2870 int err;
2871
2872 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2873 TRC_INTERNAL_LOOPBACK);
2874
2875 return err;
2876}
2877
2878static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2879{
2880 int err;
2881
2882 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2883 TRC_TRI_LOOPBACK);
2884
2885 return err;
2886}
2887
2888static int smctr_issue_write_byte_cmd(struct net_device *dev,
2889 short aword_cnt, void *byte)
2890{
2891 struct net_local *tp = netdev_priv(dev);
2892 unsigned int iword, ibyte;
2893 int err;
2894
2895 if((err = smctr_wait_while_cbusy(dev)))
2896 return err;
2897
2898 if((err = smctr_wait_cmd(dev)))
2899 return err;
2900
2901 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2902 iword++, ibyte += 2)
2903 {
2904 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2905 | (*((__u8 *)byte + ibyte + 1));
2906 }
2907
2908 return smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2909 aword_cnt);
2910}
2911
2912static int smctr_issue_write_word_cmd(struct net_device *dev,
2913 short aword_cnt, void *word)
2914{
2915 struct net_local *tp = netdev_priv(dev);
2916 unsigned int i, err;
2917
2918 if((err = smctr_wait_while_cbusy(dev)))
2919 return err;
2920
2921 if((err = smctr_wait_cmd(dev)))
2922 return err;
2923
2924 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2925 tp->misc_command_data[i] = *((__u16 *)word + i);
2926
2927 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2928 aword_cnt);
2929
2930 return err;
2931}
2932
2933static int smctr_join_complete_state(struct net_device *dev)
2934{
2935 int err;
2936
2937 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2938 JS_JOIN_COMPLETE_STATE);
2939
2940 return err;
2941}
2942
2943static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2944{
2945 struct net_local *tp = netdev_priv(dev);
2946 unsigned int i, j;
2947 FCBlock *fcb;
2948 BDBlock *bdb;
2949
2950 for(i = 0; i < NUM_TX_QS_USED; i++)
2951 {
2952 fcb = tp->tx_fcb_head[i];
2953 bdb = tp->tx_bdb_head[i];
2954
2955 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2956 {
2957 fcb->bdb_ptr = bdb;
2958 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2959 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2960 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2961 }
2962 }
2963
2964 return 0;
2965}
2966
2967static int smctr_load_firmware(struct net_device *dev)
2968{
2969 struct net_local *tp = netdev_priv(dev);
2970 const struct firmware *fw;
2971 __u16 i, checksum = 0;
2972 int err = 0;
2973
2974 if(smctr_debug > 10)
2975 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2976
2977 if (request_firmware(&fw, "tr_smctr.bin", &dev->dev)) {
2978 printk(KERN_ERR "%s: firmware not found\n", dev->name);
2979 return UCODE_NOT_PRESENT;
2980 }
2981
2982 tp->num_of_tx_buffs = 4;
2983 tp->mode_bits |= UMAC;
2984 tp->receive_mask = 0;
2985 tp->max_packet_size = 4177;
2986
2987
2988 if (tp->microcode_version != 0) {
2989 err = (UCODE_PRESENT);
2990 goto out;
2991 }
2992
2993
2994 if (!fw->data ||
2995 (*(fw->data + UCODE_VERSION_OFFSET) < UCODE_VERSION))
2996 {
2997 err = (UCODE_NOT_PRESENT);
2998 goto out;
2999 }
3000
3001
3002 for(i = 0; i < *((__u16 *)(fw->data + UCODE_SIZE_OFFSET)); i += 2)
3003 checksum += *((__u16 *)(fw->data + 2 + i));
3004 if (checksum) {
3005 err = (UCODE_NOT_PRESENT);
3006 goto out;
3007 }
3008
3009
3010 smctr_enable_adapter_ram(dev);
3011 smctr_enable_16bit(dev);
3012 smctr_set_page(dev, (__u8 *)tp->ram_access);
3013
3014 if((smctr_checksum_firmware(dev)) ||
3015 (*(fw->data + UCODE_VERSION_OFFSET) > tp->microcode_version))
3016 {
3017 smctr_enable_adapter_ctrl_store(dev);
3018
3019
3020 for(i = 0; i < CS_RAM_SIZE; i += 2)
3021 *((__u16 *)(tp->ram_access + i)) = 0;
3022
3023 smctr_decode_firmware(dev, fw);
3024
3025 tp->microcode_version = *(fw->data + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
3026 = (tp->microcode_version << 8);
3027 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3028 = ~(tp->microcode_version << 8) + 1;
3029
3030 smctr_disable_adapter_ctrl_store(dev);
3031
3032 if(smctr_checksum_firmware(dev))
3033 err = HARDWARE_FAILED;
3034 }
3035 else
3036 err = UCODE_PRESENT;
3037
3038 smctr_disable_16bit(dev);
3039 out:
3040 release_firmware(fw);
3041 return err;
3042}
3043
3044static int smctr_load_node_addr(struct net_device *dev)
3045{
3046 int ioaddr = dev->base_addr;
3047 unsigned int i;
3048 __u8 r;
3049
3050 for(i = 0; i < 6; i++)
3051 {
3052 r = inb(ioaddr + LAR0 + i);
3053 dev->dev_addr[i] = (char)r;
3054 }
3055 dev->addr_len = 6;
3056
3057 return 0;
3058}
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077static int smctr_lobe_media_test(struct net_device *dev)
3078{
3079 struct net_local *tp = netdev_priv(dev);
3080 unsigned int i, perror = 0;
3081 unsigned short saved_rcv_mask;
3082
3083 if(smctr_debug > 10)
3084 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3085
3086
3087 saved_rcv_mask = tp->receive_mask;
3088 tp->receive_mask = 0;
3089
3090 smctr_chg_rx_mask(dev);
3091
3092
3093 smctr_lobe_media_test_cmd(dev);
3094 if(smctr_wait_cmd(dev))
3095 goto err;
3096
3097
3098 for(i = 0; i < 1500; ++i)
3099 {
3100 if(smctr_send_lobe_media_test(dev))
3101 {
3102 if(perror)
3103 goto err;
3104 else
3105 {
3106 perror = 1;
3107 if(smctr_lobe_media_test_cmd(dev))
3108 goto err;
3109 }
3110 }
3111 }
3112
3113 if(smctr_send_dat(dev))
3114 {
3115 if(smctr_send_dat(dev))
3116 goto err;
3117 }
3118
3119
3120 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status) ||
3121 (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3122 goto err;
3123
3124
3125 tp->receive_mask = saved_rcv_mask;
3126
3127 smctr_chg_rx_mask(dev);
3128
3129 return 0;
3130err:
3131 smctr_reset_adapter(dev);
3132 tp->status = CLOSED;
3133 return LOBE_MEDIA_TEST_FAILED;
3134}
3135
3136static int smctr_lobe_media_test_cmd(struct net_device *dev)
3137{
3138 struct net_local *tp = netdev_priv(dev);
3139 int err;
3140
3141 if(smctr_debug > 10)
3142 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3143
3144
3145 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3146 {
3147 smctr_lobe_media_test_state(dev);
3148 if(smctr_wait_cmd(dev))
3149 {
3150 printk(KERN_ERR "Lobe Failed test state\n");
3151 return LOBE_MEDIA_TEST_FAILED;
3152 }
3153 }
3154
3155 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3156 TRC_LOBE_MEDIA_TEST);
3157
3158 return err;
3159}
3160
3161static int smctr_lobe_media_test_state(struct net_device *dev)
3162{
3163 int err;
3164
3165 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3166 JS_LOBE_TEST_STATE);
3167
3168 return err;
3169}
3170
3171static int smctr_make_8025_hdr(struct net_device *dev,
3172 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3173{
3174 tmf->ac = MSB(ac_fc);
3175 tmf->fc = LSB(ac_fc);
3176
3177 tmf->sa[0] = dev->dev_addr[0];
3178 tmf->sa[1] = dev->dev_addr[1];
3179 tmf->sa[2] = dev->dev_addr[2];
3180 tmf->sa[3] = dev->dev_addr[3];
3181 tmf->sa[4] = dev->dev_addr[4];
3182 tmf->sa[5] = dev->dev_addr[5];
3183
3184 switch(tmf->vc)
3185 {
3186
3187 case RQ_INIT:
3188 tmf->da[0] = 0xc0;
3189 tmf->da[1] = 0x00;
3190 tmf->da[2] = 0x00;
3191 tmf->da[3] = 0x00;
3192 tmf->da[4] = 0x00;
3193 tmf->da[5] = 0x02;
3194 break;
3195
3196
3197 case RPT_TX_FORWARD:
3198 tmf->da[0] = 0xc0;
3199 tmf->da[1] = 0x00;
3200 tmf->da[2] = 0x00;
3201 tmf->da[3] = 0x00;
3202 tmf->da[4] = 0x00;
3203 tmf->da[5] = 0x10;
3204 break;
3205
3206
3207 default:
3208 tmf->da[0] = rmf->sa[0];
3209 tmf->da[1] = rmf->sa[1];
3210 tmf->da[2] = rmf->sa[2];
3211 tmf->da[3] = rmf->sa[3];
3212 tmf->da[4] = rmf->sa[4];
3213 tmf->da[5] = rmf->sa[5];
3214 break;
3215 }
3216
3217 return 0;
3218}
3219
3220static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3221{
3222 struct net_local *tp = netdev_priv(dev);
3223
3224 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3225 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3226
3227 tsv->svv[0] = MSB(tp->authorized_access_priority);
3228 tsv->svv[1] = LSB(tp->authorized_access_priority);
3229
3230 return 0;
3231}
3232
3233static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3234{
3235 tsv->svi = ADDRESS_MODIFER;
3236 tsv->svl = S_ADDRESS_MODIFER;
3237
3238 tsv->svv[0] = 0;
3239 tsv->svv[1] = 0;
3240
3241 return 0;
3242}
3243
3244static int smctr_make_auth_funct_class(struct net_device *dev,
3245 MAC_SUB_VECTOR *tsv)
3246{
3247 struct net_local *tp = netdev_priv(dev);
3248
3249 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3250 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3251
3252 tsv->svv[0] = MSB(tp->authorized_function_classes);
3253 tsv->svv[1] = LSB(tp->authorized_function_classes);
3254
3255 return 0;
3256}
3257
3258static int smctr_make_corr(struct net_device *dev,
3259 MAC_SUB_VECTOR *tsv, __u16 correlator)
3260{
3261 tsv->svi = CORRELATOR;
3262 tsv->svl = S_CORRELATOR;
3263
3264 tsv->svv[0] = MSB(correlator);
3265 tsv->svv[1] = LSB(correlator);
3266
3267 return 0;
3268}
3269
3270static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3271{
3272 struct net_local *tp = netdev_priv(dev);
3273
3274 smctr_get_functional_address(dev);
3275
3276 tsv->svi = FUNCTIONAL_ADDRESS;
3277 tsv->svl = S_FUNCTIONAL_ADDRESS;
3278
3279 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3280 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3281
3282 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3283 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3284
3285 return 0;
3286}
3287
3288static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3289{
3290 struct net_local *tp = netdev_priv(dev);
3291
3292 smctr_get_group_address(dev);
3293
3294 tsv->svi = GROUP_ADDRESS;
3295 tsv->svl = S_GROUP_ADDRESS;
3296
3297 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3298 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3299
3300 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3301 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3302
3303
3304
3305
3306 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00 &&
3307 tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3308 tsv->svv[0] = 0x00;
3309
3310 return 0;
3311}
3312
3313static int smctr_make_phy_drop_num(struct net_device *dev,
3314 MAC_SUB_VECTOR *tsv)
3315{
3316 struct net_local *tp = netdev_priv(dev);
3317
3318 smctr_get_physical_drop_number(dev);
3319
3320 tsv->svi = PHYSICAL_DROP;
3321 tsv->svl = S_PHYSICAL_DROP;
3322
3323 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3324 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3325
3326 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3327 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3328
3329 return 0;
3330}
3331
3332static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3333{
3334 int i;
3335
3336 tsv->svi = PRODUCT_INSTANCE_ID;
3337 tsv->svl = S_PRODUCT_INSTANCE_ID;
3338
3339 for(i = 0; i < 18; i++)
3340 tsv->svv[i] = 0xF0;
3341
3342 return 0;
3343}
3344
3345static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3346{
3347 struct net_local *tp = netdev_priv(dev);
3348
3349 smctr_get_station_id(dev);
3350
3351 tsv->svi = STATION_IDENTIFER;
3352 tsv->svl = S_STATION_IDENTIFER;
3353
3354 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3355 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3356
3357 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3358 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3359
3360 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3361 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3362
3363 return 0;
3364}
3365
3366static int smctr_make_ring_station_status(struct net_device *dev,
3367 MAC_SUB_VECTOR * tsv)
3368{
3369 tsv->svi = RING_STATION_STATUS;
3370 tsv->svl = S_RING_STATION_STATUS;
3371
3372 tsv->svv[0] = 0;
3373 tsv->svv[1] = 0;
3374 tsv->svv[2] = 0;
3375 tsv->svv[3] = 0;
3376 tsv->svv[4] = 0;
3377 tsv->svv[5] = 0;
3378
3379 return 0;
3380}
3381
3382static int smctr_make_ring_station_version(struct net_device *dev,
3383 MAC_SUB_VECTOR *tsv)
3384{
3385 struct net_local *tp = netdev_priv(dev);
3386
3387 tsv->svi = RING_STATION_VERSION_NUMBER;
3388 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3389
3390 tsv->svv[0] = 0xe2;
3391 tsv->svv[1] = 0xd4;
3392 tsv->svv[2] = 0xc3;
3393 tsv->svv[3] = 0x40;
3394 tsv->svv[4] = 0xe5;
3395 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3396 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3397 tsv->svv[7] = 0x40;
3398 tsv->svv[8] = 0xe7;
3399
3400 if(tp->extra_info & CHIP_REV_MASK)
3401 tsv->svv[9] = 0xc5;
3402 else
3403 tsv->svv[9] = 0xc4;
3404
3405 return 0;
3406}
3407
3408static int smctr_make_tx_status_code(struct net_device *dev,
3409 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3410{
3411 tsv->svi = TRANSMIT_STATUS_CODE;
3412 tsv->svl = S_TRANSMIT_STATUS_CODE;
3413
3414 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) | IBM_PASS_SOURCE_ADDR);
3415
3416
3417 tsv->svv[1] = tx_fstatus & 0xff;
3418
3419 return 0;
3420}
3421
3422static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3423 MAC_SUB_VECTOR *tsv)
3424{
3425 struct net_local *tp = netdev_priv(dev);
3426
3427 smctr_get_upstream_neighbor_addr(dev);
3428
3429 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3430 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3431
3432 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3433 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3434
3435 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3436 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3437
3438 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3439 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3440
3441 return 0;
3442}
3443
3444static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3445{
3446 tsv->svi = WRAP_DATA;
3447 tsv->svl = S_WRAP_DATA;
3448
3449 return 0;
3450}
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460static int smctr_open(struct net_device *dev)
3461{
3462 int err;
3463
3464 if(smctr_debug > 10)
3465 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3466
3467 err = smctr_init_adapter(dev);
3468 if(err < 0)
3469 return err;
3470
3471 return err;
3472}
3473
3474
3475static int smctr_open_tr(struct net_device *dev)
3476{
3477 struct net_local *tp = netdev_priv(dev);
3478 unsigned long flags;
3479 int err;
3480
3481 if(smctr_debug > 10)
3482 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3483
3484
3485 if(tp->status == OPEN)
3486 return 0;
3487 if(tp->status != INITIALIZED)
3488 return -1;
3489
3490
3491
3492 spin_lock_irqsave(&tp->lock, flags);
3493
3494 smctr_set_page(dev, (__u8 *)tp->ram_access);
3495
3496 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3497 goto out;
3498
3499 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3500 goto out;
3501
3502 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3503 goto out;
3504
3505 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3506 goto out;
3507
3508 tp->status = CLOSED;
3509
3510
3511 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3512 {
3513 tp->status = CLOSED;
3514
3515 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3516 {
3517 if(!(err = smctr_wait_cmd(dev)))
3518 tp->status = OPEN;
3519 }
3520
3521 smctr_status_chg(dev);
3522 }
3523 else
3524 {
3525 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3526 {
3527 tp->status = CLOSED;
3528 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3529 {
3530 if(!(err = smctr_wait_cmd(dev)))
3531 tp->status = OPEN;
3532 }
3533
3534 smctr_status_chg(dev);
3535 }
3536 else
3537 {
3538 if((tp->mode_bits & LOOPING_MODE_MASK)
3539 == LOOPBACK_MODE_3)
3540 {
3541 tp->status = CLOSED;
3542 if(!(err = smctr_lobe_media_test_cmd(dev)))
3543 {
3544 if(!(err = smctr_wait_cmd(dev)))
3545 tp->status = OPEN;
3546 }
3547 smctr_status_chg(dev);
3548 }
3549 else
3550 {
3551 if(!(err = smctr_lobe_media_test(dev)))
3552 err = smctr_issue_insert_cmd(dev);
3553 else
3554 {
3555 if(err == LOBE_MEDIA_TEST_FAILED)
3556 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3557 }
3558 }
3559 }
3560 }
3561
3562out:
3563 spin_unlock_irqrestore(&tp->lock, flags);
3564
3565 return err;
3566}
3567
3568
3569
3570
3571struct net_device __init *smctr_probe(int unit)
3572{
3573 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3574 static const unsigned ports[] = {
3575 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3576 0x320, 0x340, 0x360, 0x380, 0
3577 };
3578 const unsigned *port;
3579 int err = 0;
3580
3581 if (!dev)
3582 return ERR_PTR(-ENOMEM);
3583
3584 if (unit >= 0) {
3585 sprintf(dev->name, "tr%d", unit);
3586 netdev_boot_setup_check(dev);
3587 }
3588
3589 if (dev->base_addr > 0x1ff)
3590 err = smctr_probe1(dev, dev->base_addr);
3591 else if(dev->base_addr != 0)
3592 err =-ENXIO;
3593 else {
3594 for (port = ports; *port; port++) {
3595 err = smctr_probe1(dev, *port);
3596 if (!err)
3597 break;
3598 }
3599 }
3600 if (err)
3601 goto out;
3602 err = register_netdev(dev);
3603 if (err)
3604 goto out1;
3605 return dev;
3606out1:
3607#ifdef CONFIG_MCA_LEGACY
3608 { struct net_local *tp = netdev_priv(dev);
3609 if (tp->slot_num)
3610 mca_mark_as_unused(tp->slot_num);
3611 }
3612#endif
3613 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3614 free_irq(dev->irq, dev);
3615out:
3616 free_netdev(dev);
3617 return ERR_PTR(err);
3618}
3619
3620static const struct net_device_ops smctr_netdev_ops = {
3621 .ndo_open = smctr_open,
3622 .ndo_stop = smctr_close,
3623 .ndo_start_xmit = smctr_send_packet,
3624 .ndo_tx_timeout = smctr_timeout,
3625 .ndo_get_stats = smctr_get_stats,
3626 .ndo_set_multicast_list = smctr_set_multicast_list,
3627};
3628
3629static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3630{
3631 static unsigned version_printed;
3632 struct net_local *tp = netdev_priv(dev);
3633 int err;
3634 __u32 *ram;
3635
3636 if(smctr_debug && version_printed++ == 0)
3637 printk(version);
3638
3639 spin_lock_init(&tp->lock);
3640 dev->base_addr = ioaddr;
3641
3642
3643 err = smctr_chk_isa(dev);
3644 if(err < 0)
3645 {
3646 if ((err = smctr_chk_mca(dev)) < 0) {
3647 err = -ENODEV;
3648 goto out;
3649 }
3650 }
3651
3652 tp = netdev_priv(dev);
3653 dev->mem_start = tp->ram_base;
3654 dev->mem_end = dev->mem_start + 0x10000;
3655 ram = (__u32 *)phys_to_virt(dev->mem_start);
3656 tp->ram_access = *(__u32 *)&ram;
3657 tp->status = NOT_INITIALIZED;
3658
3659 err = smctr_load_firmware(dev);
3660 if(err != UCODE_PRESENT && err != SUCCESS)
3661 {
3662 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3663 err = -EIO;
3664 goto out;
3665 }
3666
3667
3668 if(ringspeed == 4)
3669 tp->media_type = MEDIA_UTP_4;
3670 else
3671 tp->media_type = MEDIA_UTP_16;
3672
3673 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3674 dev->name, smctr_name, smctr_model,
3675 (unsigned int)dev->base_addr,
3676 dev->irq, tp->rom_base, tp->ram_base);
3677
3678 dev->netdev_ops = &smctr_netdev_ops;
3679 dev->watchdog_timeo = HZ;
3680 return 0;
3681
3682out:
3683 return err;
3684}
3685
3686static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3687 struct net_device *dev, __u16 rx_status)
3688{
3689 struct net_local *tp = netdev_priv(dev);
3690 struct sk_buff *skb;
3691 __u16 rcode, correlator;
3692 int err = 0;
3693 __u8 xframe = 1;
3694
3695 rmf->vl = SWAP_BYTES(rmf->vl);
3696 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3697 {
3698 switch(rmf->vc)
3699 {
3700
3701 case INIT:
3702 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3703 {
3704 return rcode;
3705 }
3706
3707 if((err = smctr_send_rsp(dev, rmf, rcode,
3708 correlator)))
3709 {
3710 return err;
3711 }
3712 break;
3713
3714 case CHG_PARM:
3715 if((rcode = smctr_rcv_chg_param(dev, rmf,
3716 &correlator)) ==HARDWARE_FAILED)
3717 {
3718 return rcode;
3719 }
3720
3721 if((err = smctr_send_rsp(dev, rmf, rcode,
3722 correlator)))
3723 {
3724 return err;
3725 }
3726 break;
3727
3728 case RQ_ADDR:
3729 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3730 rmf, &correlator)) != POSITIVE_ACK)
3731 {
3732 if(rcode == HARDWARE_FAILED)
3733 return rcode;
3734 else
3735 return smctr_send_rsp(dev, rmf,
3736 rcode, correlator);
3737 }
3738
3739 if((err = smctr_send_rpt_addr(dev, rmf,
3740 correlator)))
3741 {
3742 return err;
3743 }
3744 break;
3745
3746 case RQ_ATTCH:
3747 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3748 rmf, &correlator)) != POSITIVE_ACK)
3749 {
3750 if(rcode == HARDWARE_FAILED)
3751 return rcode;
3752 else
3753 return smctr_send_rsp(dev, rmf,
3754 rcode,
3755 correlator);
3756 }
3757
3758 if((err = smctr_send_rpt_attch(dev, rmf,
3759 correlator)))
3760 {
3761 return err;
3762 }
3763 break;
3764
3765 case RQ_STATE:
3766 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3767 rmf, &correlator)) != POSITIVE_ACK)
3768 {
3769 if(rcode == HARDWARE_FAILED)
3770 return rcode;
3771 else
3772 return smctr_send_rsp(dev, rmf,
3773 rcode,
3774 correlator);
3775 }
3776
3777 if((err = smctr_send_rpt_state(dev, rmf,
3778 correlator)))
3779 {
3780 return err;
3781 }
3782 break;
3783
3784 case TX_FORWARD: {
3785 __u16 uninitialized_var(tx_fstatus);
3786
3787 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3788 != POSITIVE_ACK)
3789 {
3790 if(rcode == HARDWARE_FAILED)
3791 return rcode;
3792 else
3793 return smctr_send_rsp(dev, rmf,
3794 rcode,
3795 correlator);
3796 }
3797
3798 if((err = smctr_send_tx_forward(dev, rmf,
3799 &tx_fstatus)) == HARDWARE_FAILED)
3800 {
3801 return err;
3802 }
3803
3804 if(err == A_FRAME_WAS_FORWARDED)
3805 {
3806 if((err = smctr_send_rpt_tx_forward(dev,
3807 rmf, tx_fstatus))
3808 == HARDWARE_FAILED)
3809 {
3810 return err;
3811 }
3812 }
3813 break;
3814 }
3815
3816
3817 case RSP:
3818 case RQ_INIT:
3819 case RPT_NEW_MON:
3820 case RPT_SUA_CHG:
3821 case RPT_ACTIVE_ERR:
3822 case RPT_NN_INCMP:
3823 case RPT_ERROR:
3824 case RPT_ATTCH:
3825 case RPT_STATE:
3826 case RPT_ADDR:
3827 break;
3828
3829
3830 default:
3831 xframe = 0;
3832 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3833 {
3834 rcode = smctr_rcv_unknown(dev, rmf,
3835 &correlator);
3836 if((err = smctr_send_rsp(dev, rmf,rcode,
3837 correlator)))
3838 {
3839 return err;
3840 }
3841 }
3842
3843 break;
3844 }
3845 }
3846 else
3847 {
3848
3849
3850
3851 switch(rmf->vc)
3852 {
3853 case RSP:
3854 case INIT:
3855 case RQ_INIT:
3856 case RQ_ADDR:
3857 case RQ_ATTCH:
3858 case RQ_STATE:
3859 case CHG_PARM:
3860 case RPT_ADDR:
3861 case RPT_ERROR:
3862 case RPT_ATTCH:
3863 case RPT_STATE:
3864 case RPT_NEW_MON:
3865 case RPT_SUA_CHG:
3866 case RPT_NN_INCMP:
3867 case RPT_ACTIVE_ERR:
3868 break;
3869
3870 default:
3871 xframe = 0;
3872 break;
3873 }
3874 }
3875
3876
3877
3878
3879 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES) &&
3880 (xframe == (__u8)0)) ||
3881 ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES) &&
3882 (xframe == (__u8)1)))
3883 {
3884 rmf->vl = SWAP_BYTES(rmf->vl);
3885
3886 if (!(skb = dev_alloc_skb(size)))
3887 return -ENOMEM;
3888 skb->len = size;
3889
3890
3891 skb_put(skb, skb->len);
3892 skb_copy_to_linear_data(skb, rmf, skb->len);
3893
3894
3895 tp->MacStat.rx_packets++;
3896 tp->MacStat.rx_bytes += skb->len;
3897
3898
3899 skb->protocol = tr_type_trans(skb, dev);
3900 netif_rx(skb);
3901 err = 0;
3902 }
3903
3904 return err;
3905}
3906
3907
3908static int smctr_ram_memory_test(struct net_device *dev)
3909{
3910 struct net_local *tp = netdev_priv(dev);
3911 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3912 word_read = 0, err_word = 0, err_pattern = 0;
3913 unsigned int err_offset;
3914 __u32 j, pword;
3915 __u8 err = 0;
3916
3917 if(smctr_debug > 10)
3918 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3919
3920 start_pattern = 0x0001;
3921 pages_of_ram = tp->ram_size / tp->ram_usable;
3922 pword = tp->ram_access;
3923
3924
3925 for(page = 0; (page < pages_of_ram) && (~err);
3926 page++, start_pattern += 0x8000)
3927 {
3928 smctr_set_page(dev, (__u8 *)(tp->ram_access
3929 + (page * tp->ram_usable * 1024) + 1));
3930 word_pattern = start_pattern;
3931
3932 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3933 *(__u16 *)(pword + j) = word_pattern++;
3934
3935 word_pattern = start_pattern;
3936
3937 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1 && (~err);
3938 j += 2, word_pattern++)
3939 {
3940 word_read = *(__u16 *)(pword + j);
3941 if(word_read != word_pattern)
3942 {
3943 err = (__u8)1;
3944 err_offset = j;
3945 err_word = word_read;
3946 err_pattern = word_pattern;
3947 return RAM_TEST_FAILED;
3948 }
3949 }
3950 }
3951
3952
3953 for(page = 0; page < pages_of_ram && (~err); page++)
3954 {
3955 smctr_set_page(dev, (__u8 *)(tp->ram_access
3956 + (page * tp->ram_usable * 1024)));
3957 word_pattern = 0;
3958
3959 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3960 *(__u16 *)(pword + j) = word_pattern;
3961
3962 for(j =0; j < (__u32)tp->ram_usable * 1024 && (~err); j += 2)
3963 {
3964 word_read = *(__u16 *)(pword + j);
3965 if(word_read != word_pattern)
3966 {
3967 err = (__u8)1;
3968 err_offset = j;
3969 err_word = word_read;
3970 err_pattern = word_pattern;
3971 return RAM_TEST_FAILED;
3972 }
3973 }
3974 }
3975
3976 smctr_set_page(dev, (__u8 *)tp->ram_access);
3977
3978 return 0;
3979}
3980
3981static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3982 __u16 *correlator)
3983{
3984 MAC_SUB_VECTOR *rsv;
3985 signed short vlen;
3986 __u16 rcode = POSITIVE_ACK;
3987 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
3988
3989
3990 if((rmf->dc_sc & SC_MASK) != SC_CRS)
3991 return E_INAPPROPRIATE_SOURCE_CLASS;
3992
3993
3994 vlen = (signed short)rmf->vl - 4;
3995
3996
3997 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
3998
3999
4000 while((vlen > 0) && (rcode == POSITIVE_ACK))
4001 {
4002 switch(rsv->svi)
4003 {
4004 case CORRELATOR:
4005 svectors |= F_CORRELATOR;
4006 rcode = smctr_set_corr(dev, rsv, correlator);
4007 break;
4008
4009 case LOCAL_RING_NUMBER:
4010 svectors |= F_LOCAL_RING_NUMBER;
4011 rcode = smctr_set_local_ring_num(dev, rsv);
4012 break;
4013
4014 case ASSIGN_PHYSICAL_DROP:
4015 svectors |= F_ASSIGN_PHYSICAL_DROP;
4016 rcode = smctr_set_phy_drop(dev, rsv);
4017 break;
4018
4019 case ERROR_TIMER_VALUE:
4020 svectors |= F_ERROR_TIMER_VALUE;
4021 rcode = smctr_set_error_timer_value(dev, rsv);
4022 break;
4023
4024 case AUTHORIZED_FUNCTION_CLASS:
4025 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4026 rcode = smctr_set_auth_funct_class(dev, rsv);
4027 break;
4028
4029 case AUTHORIZED_ACCESS_PRIORITY:
4030 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4031 rcode = smctr_set_auth_access_pri(dev, rsv);
4032 break;
4033
4034 default:
4035 rcode = E_SUB_VECTOR_UNKNOWN;
4036 break;
4037 }
4038
4039
4040
4041
4042 if((vlen -= rsv->svl) < 0)
4043 rcode = E_VECTOR_LENGTH_ERROR;
4044
4045 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4046 }
4047
4048 if(rcode == POSITIVE_ACK)
4049 {
4050
4051
4052
4053 if(vlen != 0)
4054 rcode = E_VECTOR_LENGTH_ERROR;
4055 else
4056 {
4057
4058 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4059 rcode = E_MISSING_SUB_VECTOR;
4060 }
4061 }
4062
4063 return rcode;
4064}
4065
4066static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4067 __u16 *correlator)
4068{
4069 MAC_SUB_VECTOR *rsv;
4070 signed short vlen;
4071 __u16 rcode = POSITIVE_ACK;
4072 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4073
4074
4075 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4076 return E_INAPPROPRIATE_SOURCE_CLASS;
4077
4078
4079 vlen = (signed short)rmf->vl - 4;
4080
4081
4082 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4083
4084
4085 while((vlen > 0) && (rcode == POSITIVE_ACK))
4086 {
4087 switch(rsv->svi)
4088 {
4089 case CORRELATOR:
4090 svectors |= F_CORRELATOR;
4091 rcode = smctr_set_corr(dev, rsv, correlator);
4092 break;
4093
4094 case LOCAL_RING_NUMBER:
4095 svectors |= F_LOCAL_RING_NUMBER;
4096 rcode = smctr_set_local_ring_num(dev, rsv);
4097 break;
4098
4099 case ASSIGN_PHYSICAL_DROP:
4100 svectors |= F_ASSIGN_PHYSICAL_DROP;
4101 rcode = smctr_set_phy_drop(dev, rsv);
4102 break;
4103
4104 case ERROR_TIMER_VALUE:
4105 svectors |= F_ERROR_TIMER_VALUE;
4106 rcode = smctr_set_error_timer_value(dev, rsv);
4107 break;
4108
4109 default:
4110 rcode = E_SUB_VECTOR_UNKNOWN;
4111 break;
4112 }
4113
4114
4115
4116
4117 if((vlen -= rsv->svl) < 0)
4118 rcode = E_VECTOR_LENGTH_ERROR;
4119
4120 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4121 }
4122
4123 if(rcode == POSITIVE_ACK)
4124 {
4125
4126
4127
4128 if(vlen != 0)
4129 rcode = E_VECTOR_LENGTH_ERROR;
4130 else
4131 {
4132
4133 if((svectors & R_INIT) ^ R_INIT)
4134 rcode = E_MISSING_SUB_VECTOR;
4135 }
4136 }
4137
4138 return rcode;
4139}
4140
4141static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4142{
4143 MAC_SUB_VECTOR *rsv;
4144 signed short vlen;
4145 __u16 rcode = POSITIVE_ACK;
4146 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4147
4148
4149 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4150 return E_INAPPROPRIATE_SOURCE_CLASS;
4151
4152
4153 vlen = (signed short)rmf->vl - 4;
4154
4155
4156 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4157
4158
4159 while((vlen > 0) && (rcode == POSITIVE_ACK))
4160 {
4161 switch(rsv->svi)
4162 {
4163 case FRAME_FORWARD:
4164 svectors |= F_FRAME_FORWARD;
4165 rcode = smctr_set_frame_forward(dev, rsv,
4166 rmf->dc_sc);
4167 break;
4168
4169 default:
4170 rcode = E_SUB_VECTOR_UNKNOWN;
4171 break;
4172 }
4173
4174
4175
4176
4177 if((vlen -= rsv->svl) < 0)
4178 rcode = E_VECTOR_LENGTH_ERROR;
4179
4180 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4181 }
4182
4183 if(rcode == POSITIVE_ACK)
4184 {
4185
4186
4187
4188 if(vlen != 0)
4189 rcode = E_VECTOR_LENGTH_ERROR;
4190 else
4191 {
4192
4193 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4194 rcode = E_MISSING_SUB_VECTOR;
4195 }
4196 }
4197
4198 return rcode;
4199}
4200
4201static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4202 MAC_HEADER *rmf, __u16 *correlator)
4203{
4204 MAC_SUB_VECTOR *rsv;
4205 signed short vlen;
4206 __u16 rcode = POSITIVE_ACK;
4207 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4208
4209
4210 vlen = (signed short)rmf->vl - 4;
4211
4212
4213 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4214
4215
4216 while((vlen > 0) && (rcode == POSITIVE_ACK))
4217 {
4218 switch(rsv->svi)
4219 {
4220 case CORRELATOR:
4221 svectors |= F_CORRELATOR;
4222 rcode = smctr_set_corr(dev, rsv, correlator);
4223 break;
4224
4225 default:
4226 rcode = E_SUB_VECTOR_UNKNOWN;
4227 break;
4228 }
4229
4230
4231
4232
4233 if((vlen -= rsv->svl) < 0)
4234 rcode = E_VECTOR_LENGTH_ERROR;
4235
4236 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4237 }
4238
4239 if(rcode == POSITIVE_ACK)
4240 {
4241
4242
4243
4244 if(vlen != 0)
4245 rcode = E_VECTOR_LENGTH_ERROR;
4246 else
4247 {
4248
4249 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4250 ^ R_RQ_ATTCH_STATE_ADDR)
4251 rcode = E_MISSING_SUB_VECTOR;
4252 }
4253 }
4254
4255 return rcode;
4256}
4257
4258static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4259 __u16 *correlator)
4260{
4261 MAC_SUB_VECTOR *rsv;
4262 signed short vlen;
4263
4264 *correlator = 0;
4265
4266
4267 vlen = (signed short)rmf->vl - 4;
4268
4269
4270 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4271
4272
4273 while((vlen > 0) && (*correlator == 0))
4274 {
4275 switch(rsv->svi)
4276 {
4277 case CORRELATOR:
4278 smctr_set_corr(dev, rsv, correlator);
4279 break;
4280
4281 default:
4282 break;
4283 }
4284
4285 vlen -= rsv->svl;
4286 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4287 }
4288
4289 return E_UNRECOGNIZED_VECTOR_ID;
4290}
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300static int smctr_reset_adapter(struct net_device *dev)
4301{
4302 struct net_local *tp = netdev_priv(dev);
4303 int ioaddr = dev->base_addr;
4304
4305 smctr_set_trc_reset(ioaddr);
4306 mdelay(200);
4307
4308 smctr_clear_trc_reset(ioaddr);
4309 mdelay(200);
4310
4311
4312
4313
4314 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4315
4316 return 0;
4317}
4318
4319static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4320{
4321 struct net_local *tp = netdev_priv(dev);
4322 int err = 0;
4323
4324 if(smctr_debug > 10)
4325 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4326
4327 if(tp->num_tx_fcbs_used[queue] != 0 &&
4328 tp->tx_queue_status[queue] == NOT_TRANSMITING)
4329 {
4330 tp->tx_queue_status[queue] = TRANSMITING;
4331 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4332 }
4333
4334 return err;
4335}
4336
4337static int smctr_ring_status_chg(struct net_device *dev)
4338{
4339 struct net_local *tp = netdev_priv(dev);
4340
4341 if(smctr_debug > 10)
4342 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4343
4344
4345
4346
4347
4348
4349 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4350 {
4351 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE) ||
4352 (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4353 {
4354 tp->monitor_state_ready = 1;
4355 }
4356 else
4357 {
4358
4359
4360
4361
4362 tp->monitor_state_ready = 0;
4363
4364
4365 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE &&
4366 !tp->cleanup)
4367 {
4368 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4369 dev->name);
4370 smctr_set_ring_speed(dev);
4371 }
4372 }
4373 }
4374
4375 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4376 return 0;
4377
4378 switch(tp->ring_status)
4379 {
4380 case RING_RECOVERY:
4381 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
4382 break;
4383
4384 case SINGLE_STATION:
4385 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
4386 break;
4387
4388 case COUNTER_OVERFLOW:
4389 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
4390 break;
4391
4392 case REMOVE_RECEIVED:
4393 printk(KERN_INFO "%s: Remove Received\n", dev->name);
4394 break;
4395
4396 case AUTO_REMOVAL_ERROR:
4397 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
4398 break;
4399
4400 case LOBE_WIRE_FAULT:
4401 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
4402 break;
4403
4404 case TRANSMIT_BEACON:
4405 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
4406 break;
4407
4408 case SOFT_ERROR:
4409 printk(KERN_INFO "%s: Soft Error\n", dev->name);
4410 break;
4411
4412 case HARD_ERROR:
4413 printk(KERN_INFO "%s: Hard Error\n", dev->name);
4414 break;
4415
4416 case SIGNAL_LOSS:
4417 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
4418 break;
4419
4420 default:
4421 printk(KERN_INFO "%s: Unknown ring status change\n",
4422 dev->name);
4423 break;
4424 }
4425
4426 return 0;
4427}
4428
4429static int smctr_rx_frame(struct net_device *dev)
4430{
4431 struct net_local *tp = netdev_priv(dev);
4432 __u16 queue, status, rx_size, err = 0;
4433 __u8 *pbuff;
4434
4435 if(smctr_debug > 10)
4436 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4437
4438 queue = tp->receive_queue_number;
4439
4440 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4441 {
4442 err = HARDWARE_FAILED;
4443
4444 if(((status & 0x007f) == 0) ||
4445 ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4446 {
4447
4448 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4449
4450 pbuff = smctr_get_rx_pointer(dev, queue);
4451
4452 smctr_set_page(dev, pbuff);
4453 smctr_disable_16bit(dev);
4454
4455
4456 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4457
4458 if(queue == NON_MAC_QUEUE)
4459 {
4460 struct sk_buff *skb;
4461
4462 skb = dev_alloc_skb(rx_size);
4463 if (skb) {
4464 skb_put(skb, rx_size);
4465
4466 skb_copy_to_linear_data(skb, pbuff, rx_size);
4467
4468
4469 tp->MacStat.rx_packets++;
4470 tp->MacStat.rx_bytes += skb->len;
4471
4472
4473 skb->protocol = tr_type_trans(skb, dev);
4474 netif_rx(skb);
4475 } else {
4476 }
4477 }
4478 else
4479 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4480 rx_size, dev, status);
4481 }
4482
4483 smctr_enable_16bit(dev);
4484 smctr_set_page(dev, (__u8 *)tp->ram_access);
4485 smctr_update_rx_chain(dev, queue);
4486
4487 if(err != SUCCESS)
4488 break;
4489 }
4490
4491 return err;
4492}
4493
4494static int smctr_send_dat(struct net_device *dev)
4495{
4496 struct net_local *tp = netdev_priv(dev);
4497 unsigned int i, err;
4498 MAC_HEADER *tmf;
4499 FCBlock *fcb;
4500
4501 if(smctr_debug > 10)
4502 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4503
4504 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4505 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4506 {
4507 return OUT_OF_RESOURCES;
4508 }
4509
4510
4511 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4512 tmf->ac = MSB(AC_FC_DAT);
4513 tmf->fc = LSB(AC_FC_DAT);
4514
4515 for(i = 0; i < 6; i++)
4516 {
4517 tmf->sa[i] = dev->dev_addr[i];
4518 tmf->da[i] = dev->dev_addr[i];
4519
4520 }
4521
4522 tmf->vc = DAT;
4523 tmf->dc_sc = DC_RS | SC_RS;
4524 tmf->vl = 4;
4525 tmf->vl = SWAP_BYTES(tmf->vl);
4526
4527
4528 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4529 return err;
4530
4531
4532 for(i = 0; i < 10000; i++)
4533 {
4534 if(fcb->frame_status & FCB_COMMAND_DONE)
4535 break;
4536 mdelay(1);
4537 }
4538
4539
4540 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4541 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4542 {
4543 return INITIALIZE_FAILED;
4544 }
4545
4546
4547
4548
4549
4550
4551 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4552 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4553
4554 return 0;
4555}
4556
4557static void smctr_timeout(struct net_device *dev)
4558{
4559
4560
4561
4562
4563
4564
4565
4566
4567 dev->trans_start = jiffies;
4568 netif_wake_queue(dev);
4569}
4570
4571
4572
4573
4574static netdev_tx_t smctr_send_packet(struct sk_buff *skb,
4575 struct net_device *dev)
4576{
4577 struct net_local *tp = netdev_priv(dev);
4578
4579 if(smctr_debug > 10)
4580 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4581
4582
4583
4584
4585
4586 netif_stop_queue(dev);
4587
4588 if(tp->QueueSkb == 0)
4589 return NETDEV_TX_BUSY;
4590
4591 tp->QueueSkb--;
4592 skb_queue_tail(&tp->SendSkbQueue, skb);
4593 smctr_hardware_send_packet(dev, tp);
4594 if(tp->QueueSkb > 0)
4595 netif_wake_queue(dev);
4596
4597 return NETDEV_TX_OK;
4598}
4599
4600static int smctr_send_lobe_media_test(struct net_device *dev)
4601{
4602 struct net_local *tp = netdev_priv(dev);
4603 MAC_SUB_VECTOR *tsv;
4604 MAC_HEADER *tmf;
4605 FCBlock *fcb;
4606 __u32 i;
4607 int err;
4608
4609 if(smctr_debug > 15)
4610 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4611
4612 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4613 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4614 {
4615 return OUT_OF_RESOURCES;
4616 }
4617
4618
4619 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4620 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4621 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4622
4623 for(i = 0; i < 6; i++)
4624 {
4625 tmf->da[i] = 0;
4626 tmf->sa[i] = dev->dev_addr[i];
4627 }
4628
4629 tmf->vc = LOBE_MEDIA_TEST;
4630 tmf->dc_sc = DC_RS | SC_RS;
4631 tmf->vl = 4;
4632
4633 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4634 smctr_make_wrap_data(dev, tsv);
4635 tmf->vl += tsv->svl;
4636
4637 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4638 smctr_make_wrap_data(dev, tsv);
4639 tmf->vl += tsv->svl;
4640
4641
4642 tmf->vl = SWAP_BYTES(tmf->vl);
4643 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4644 return err;
4645
4646
4647 for(i=0; i < 10000; i++)
4648 {
4649 if(fcb->frame_status & FCB_COMMAND_DONE)
4650 break;
4651 mdelay(1);
4652 }
4653
4654
4655 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4656 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4657 {
4658 return LOBE_MEDIA_TEST_FAILED;
4659 }
4660
4661
4662
4663
4664
4665
4666 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4667 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4668
4669 return 0;
4670}
4671
4672static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4673 __u16 correlator)
4674{
4675 MAC_HEADER *tmf;
4676 MAC_SUB_VECTOR *tsv;
4677 FCBlock *fcb;
4678
4679 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4680 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4681 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4682 == (FCBlock *)(-1L))
4683 {
4684 return 0;
4685 }
4686
4687 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4688 tmf->vc = RPT_ADDR;
4689 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4690 tmf->vl = 4;
4691
4692 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4693
4694 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4695 smctr_make_corr(dev, tsv, correlator);
4696
4697 tmf->vl += tsv->svl;
4698 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4699 smctr_make_phy_drop_num(dev, tsv);
4700
4701 tmf->vl += tsv->svl;
4702 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4703 smctr_make_upstream_neighbor_addr(dev, tsv);
4704
4705 tmf->vl += tsv->svl;
4706 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4707 smctr_make_addr_mod(dev, tsv);
4708
4709 tmf->vl += tsv->svl;
4710 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4711 smctr_make_group_addr(dev, tsv);
4712
4713 tmf->vl += tsv->svl;
4714 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4715 smctr_make_funct_addr(dev, tsv);
4716
4717 tmf->vl += tsv->svl;
4718
4719
4720
4721
4722
4723
4724
4725 tmf->vl = SWAP_BYTES(tmf->vl);
4726
4727 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4728}
4729
4730static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4731 __u16 correlator)
4732{
4733 MAC_HEADER *tmf;
4734 MAC_SUB_VECTOR *tsv;
4735 FCBlock *fcb;
4736
4737 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4738 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4739 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4740 == (FCBlock *)(-1L))
4741 {
4742 return 0;
4743 }
4744
4745 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4746 tmf->vc = RPT_ATTCH;
4747 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4748 tmf->vl = 4;
4749
4750 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4751
4752 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4753 smctr_make_corr(dev, tsv, correlator);
4754
4755 tmf->vl += tsv->svl;
4756 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4757 smctr_make_product_id(dev, tsv);
4758
4759 tmf->vl += tsv->svl;
4760 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4761 smctr_make_funct_addr(dev, tsv);
4762
4763 tmf->vl += tsv->svl;
4764 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4765 smctr_make_auth_funct_class(dev, tsv);
4766
4767 tmf->vl += tsv->svl;
4768 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4769 smctr_make_access_pri(dev, tsv);
4770
4771 tmf->vl += tsv->svl;
4772
4773
4774
4775
4776
4777
4778
4779 tmf->vl = SWAP_BYTES(tmf->vl);
4780
4781 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4782}
4783
4784static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4785 __u16 correlator)
4786{
4787 MAC_HEADER *tmf;
4788 MAC_SUB_VECTOR *tsv;
4789 FCBlock *fcb;
4790
4791 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4792 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4793 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4794 == (FCBlock *)(-1L))
4795 {
4796 return 0;
4797 }
4798
4799 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4800 tmf->vc = RPT_STATE;
4801 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4802 tmf->vl = 4;
4803
4804 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4805
4806 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4807 smctr_make_corr(dev, tsv, correlator);
4808
4809 tmf->vl += tsv->svl;
4810 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4811 smctr_make_ring_station_version(dev, tsv);
4812
4813 tmf->vl += tsv->svl;
4814 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4815 smctr_make_ring_station_status(dev, tsv);
4816
4817 tmf->vl += tsv->svl;
4818 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4819 smctr_make_station_id(dev, tsv);
4820
4821 tmf->vl += tsv->svl;
4822
4823
4824
4825
4826
4827
4828
4829 tmf->vl = SWAP_BYTES(tmf->vl);
4830
4831 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4832}
4833
4834static int smctr_send_rpt_tx_forward(struct net_device *dev,
4835 MAC_HEADER *rmf, __u16 tx_fstatus)
4836{
4837 MAC_HEADER *tmf;
4838 MAC_SUB_VECTOR *tsv;
4839 FCBlock *fcb;
4840
4841 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4842 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4843 {
4844 return 0;
4845 }
4846
4847 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4848 tmf->vc = RPT_TX_FORWARD;
4849 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4850 tmf->vl = 4;
4851
4852 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4853
4854 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4855 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4856
4857 tmf->vl += tsv->svl;
4858
4859
4860
4861
4862
4863
4864
4865 tmf->vl = SWAP_BYTES(tmf->vl);
4866
4867 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4868}
4869
4870static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4871 __u16 rcode, __u16 correlator)
4872{
4873 MAC_HEADER *tmf;
4874 MAC_SUB_VECTOR *tsv;
4875 FCBlock *fcb;
4876
4877 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4878 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4879 {
4880 return 0;
4881 }
4882
4883 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4884 tmf->vc = RSP;
4885 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4886 tmf->vl = 4;
4887
4888 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4889
4890 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4891 smctr_make_corr(dev, tsv, correlator);
4892
4893 return 0;
4894}
4895
4896static int smctr_send_rq_init(struct net_device *dev)
4897{
4898 struct net_local *tp = netdev_priv(dev);
4899 MAC_HEADER *tmf;
4900 MAC_SUB_VECTOR *tsv;
4901 FCBlock *fcb;
4902 unsigned int i, count = 0;
4903 __u16 fstatus;
4904 int err;
4905
4906 do {
4907 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4908 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4909 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4910 == (FCBlock *)(-1L)))
4911 {
4912 return 0;
4913 }
4914
4915 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4916 tmf->vc = RQ_INIT;
4917 tmf->dc_sc = DC_RPS | SC_RS;
4918 tmf->vl = 4;
4919
4920 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4921
4922 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4923 smctr_make_product_id(dev, tsv);
4924
4925 tmf->vl += tsv->svl;
4926 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4927 smctr_make_upstream_neighbor_addr(dev, tsv);
4928
4929 tmf->vl += tsv->svl;
4930 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4931 smctr_make_ring_station_version(dev, tsv);
4932
4933 tmf->vl += tsv->svl;
4934 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4935 smctr_make_addr_mod(dev, tsv);
4936
4937 tmf->vl += tsv->svl;
4938
4939
4940
4941
4942
4943
4944
4945 tmf->vl = SWAP_BYTES(tmf->vl);
4946
4947 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4948 return err;
4949
4950
4951 for(i = 0; i < 10000; i++)
4952 {
4953 if(fcb->frame_status & FCB_COMMAND_DONE)
4954 break;
4955 mdelay(1);
4956 }
4957
4958
4959 fstatus = fcb->frame_status;
4960
4961 if(!(fstatus & FCB_COMMAND_DONE))
4962 return HARDWARE_FAILED;
4963
4964 if(!(fstatus & FCB_TX_STATUS_E))
4965 count++;
4966
4967
4968
4969
4970
4971
4972 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4973 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4974 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4975
4976 return smctr_join_complete_state(dev);
4977}
4978
4979static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4980 __u16 *tx_fstatus)
4981{
4982 struct net_local *tp = netdev_priv(dev);
4983 FCBlock *fcb;
4984 unsigned int i;
4985 int err;
4986
4987
4988 if(rmf->vl <= 18)
4989 return 0;
4990
4991
4992
4993
4994 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
4995 return 0;
4996
4997
4998
4999
5000
5001
5002 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5003 + sizeof(MAC_HEADER) + 2);
5004 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5005 + sizeof(MAC_HEADER) + 2);
5006
5007 fcb->frame_length = rmf->vl - 4 - 2;
5008 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5009
5010 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5011 return err;
5012
5013
5014 for(i = 0; i < 10000; i++)
5015 {
5016 if(fcb->frame_status & FCB_COMMAND_DONE)
5017 break;
5018 mdelay(1);
5019 }
5020
5021
5022 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5023 {
5024 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5025 return err;
5026
5027 for(i = 0; i < 10000; i++)
5028 {
5029 if(fcb->frame_status & FCB_COMMAND_DONE)
5030 break;
5031 mdelay(1);
5032 }
5033
5034 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5035 return HARDWARE_FAILED;
5036 }
5037
5038 *tx_fstatus = fcb->frame_status;
5039
5040 return A_FRAME_WAS_FORWARDED;
5041}
5042
5043static int smctr_set_auth_access_pri(struct net_device *dev,
5044 MAC_SUB_VECTOR *rsv)
5045{
5046 struct net_local *tp = netdev_priv(dev);
5047
5048 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5049 return E_SUB_VECTOR_LENGTH_ERROR;
5050
5051 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5052
5053 return POSITIVE_ACK;
5054}
5055
5056static int smctr_set_auth_funct_class(struct net_device *dev,
5057 MAC_SUB_VECTOR *rsv)
5058{
5059 struct net_local *tp = netdev_priv(dev);
5060
5061 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5062 return E_SUB_VECTOR_LENGTH_ERROR;
5063
5064 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5065
5066 return POSITIVE_ACK;
5067}
5068
5069static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5070 __u16 *correlator)
5071{
5072 if(rsv->svl != S_CORRELATOR)
5073 return E_SUB_VECTOR_LENGTH_ERROR;
5074
5075 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5076
5077 return POSITIVE_ACK;
5078}
5079
5080static int smctr_set_error_timer_value(struct net_device *dev,
5081 MAC_SUB_VECTOR *rsv)
5082{
5083 __u16 err_tval;
5084 int err;
5085
5086 if(rsv->svl != S_ERROR_TIMER_VALUE)
5087 return E_SUB_VECTOR_LENGTH_ERROR;
5088
5089 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5090
5091 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5092
5093 if((err = smctr_wait_cmd(dev)))
5094 return err;
5095
5096 return POSITIVE_ACK;
5097}
5098
5099static int smctr_set_frame_forward(struct net_device *dev,
5100 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5101{
5102 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5103 return E_SUB_VECTOR_LENGTH_ERROR;
5104
5105 if((dc_sc & DC_MASK) != DC_CRS)
5106 {
5107 if(rsv->svl >= 2 && rsv->svl < 20)
5108 return E_TRANSMIT_FORWARD_INVALID;
5109
5110 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5111 return E_TRANSMIT_FORWARD_INVALID;
5112 }
5113
5114 return POSITIVE_ACK;
5115}
5116
5117static int smctr_set_local_ring_num(struct net_device *dev,
5118 MAC_SUB_VECTOR *rsv)
5119{
5120 struct net_local *tp = netdev_priv(dev);
5121
5122 if(rsv->svl != S_LOCAL_RING_NUMBER)
5123 return E_SUB_VECTOR_LENGTH_ERROR;
5124
5125 if(tp->ptr_local_ring_num)
5126 *(__u16 *)(tp->ptr_local_ring_num)
5127 = (rsv->svv[0] << 8 | rsv->svv[1]);
5128
5129 return POSITIVE_ACK;
5130}
5131
5132static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5133{
5134 struct net_local *tp = netdev_priv(dev);
5135 int ioaddr = dev->base_addr;
5136
5137 if(tp->bic_type == BIC_585_CHIP)
5138 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5139 else
5140 {
5141 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5142 outb(tp->trc_mask, ioaddr + CSR);
5143 }
5144
5145 return 0;
5146}
5147
5148static void smctr_set_multicast_list(struct net_device *dev)
5149{
5150 if(smctr_debug > 10)
5151 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5152}
5153
5154static int smctr_set_page(struct net_device *dev, __u8 *buf)
5155{
5156 struct net_local *tp = netdev_priv(dev);
5157 __u8 amask;
5158 __u32 tptr;
5159
5160 tptr = (__u32)buf - (__u32)tp->ram_access;
5161 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5162 outb(amask, dev->base_addr + PR);
5163
5164 return 0;
5165}
5166
5167static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5168{
5169 int err;
5170
5171 if(rsv->svl != S_PHYSICAL_DROP)
5172 return E_SUB_VECTOR_LENGTH_ERROR;
5173
5174 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5175 if((err = smctr_wait_cmd(dev)))
5176 return err;
5177
5178 return POSITIVE_ACK;
5179}
5180
5181
5182
5183
5184static int smctr_set_ring_speed(struct net_device *dev)
5185{
5186 struct net_local *tp = netdev_priv(dev);
5187 int err;
5188
5189 if(tp->media_type == MEDIA_UTP_16)
5190 tp->media_type = MEDIA_UTP_4;
5191 else
5192 tp->media_type = MEDIA_UTP_16;
5193
5194 smctr_enable_16bit(dev);
5195
5196
5197 smctr_reset_adapter(dev);
5198
5199 if((err = smctr_init_card_real(dev)))
5200 return err;
5201
5202 smctr_enable_bic_int(dev);
5203
5204 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5205 return err;
5206
5207 smctr_disable_16bit(dev);
5208
5209 return 0;
5210}
5211
5212static int smctr_set_rx_look_ahead(struct net_device *dev)
5213{
5214 struct net_local *tp = netdev_priv(dev);
5215 __u16 sword, rword;
5216
5217 if(smctr_debug > 10)
5218 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5219
5220 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5221 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5222
5223 if(tp->adapter_bus == BUS_ISA16_TYPE)
5224 {
5225 sword = *((__u16 *)(tp->ram_access));
5226 *((__u16 *)(tp->ram_access)) = 0x1234;
5227
5228 smctr_disable_16bit(dev);
5229 rword = *((__u16 *)(tp->ram_access));
5230 smctr_enable_16bit(dev);
5231
5232 if(rword != 0x1234)
5233 tp->adapter_flags |= FORCED_16BIT_MODE;
5234
5235 *((__u16 *)(tp->ram_access)) = sword;
5236 }
5237
5238 return 0;
5239}
5240
5241static int smctr_set_trc_reset(int ioaddr)
5242{
5243 __u8 r;
5244
5245 r = inb(ioaddr + MSR);
5246 outb(MSR_RST | r, ioaddr + MSR);
5247
5248 return 0;
5249}
5250
5251
5252
5253
5254static int smctr_setup_single_cmd(struct net_device *dev,
5255 __u16 command, __u16 subcommand)
5256{
5257 struct net_local *tp = netdev_priv(dev);
5258 unsigned int err;
5259
5260 if(smctr_debug > 10)
5261 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5262
5263 if((err = smctr_wait_while_cbusy(dev)))
5264 return err;
5265
5266 if((err = (unsigned int)smctr_wait_cmd(dev)))
5267 return err;
5268
5269 tp->acb_head->cmd_done_status = 0;
5270 tp->acb_head->cmd = command;
5271 tp->acb_head->subcmd = subcommand;
5272
5273 err = smctr_issue_resume_acb_cmd(dev);
5274
5275 return err;
5276}
5277
5278
5279
5280
5281static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5282 __u16 command, __u16 subcommand)
5283{
5284 struct net_local *tp = netdev_priv(dev);
5285
5286 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5287 tp->acb_head->cmd = command;
5288 tp->acb_head->subcmd = subcommand;
5289 tp->acb_head->data_offset_lo
5290 = (__u16)TRC_POINTER(tp->misc_command_data);
5291
5292 return smctr_issue_resume_acb_cmd(dev);
5293}
5294
5295static char *smctr_malloc(struct net_device *dev, __u16 size)
5296{
5297 struct net_local *tp = netdev_priv(dev);
5298 char *m;
5299
5300 m = (char *)(tp->ram_access + tp->sh_mem_used);
5301 tp->sh_mem_used += (__u32)size;
5302
5303 return m;
5304}
5305
5306static int smctr_status_chg(struct net_device *dev)
5307{
5308 struct net_local *tp = netdev_priv(dev);
5309
5310 if(smctr_debug > 10)
5311 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5312
5313 switch(tp->status)
5314 {
5315 case OPEN:
5316 break;
5317
5318 case CLOSED:
5319 break;
5320
5321
5322 case INITIALIZED:
5323 tp->group_address_0 = 0;
5324 tp->group_address[0] = 0;
5325 tp->group_address[1] = 0;
5326 tp->functional_address_0 = 0;
5327 tp->functional_address[0] = 0;
5328 tp->functional_address[1] = 0;
5329 smctr_open_tr(dev);
5330 break;
5331
5332 default:
5333 printk(KERN_INFO "%s: status change unknown %x\n",
5334 dev->name, tp->status);
5335 break;
5336 }
5337
5338 return 0;
5339}
5340
5341static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5342 __u16 queue)
5343{
5344 struct net_local *tp = netdev_priv(dev);
5345 int err = 0;
5346
5347 if(smctr_debug > 10)
5348 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5349
5350 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5351 if(tp->num_tx_fcbs[queue] != 1)
5352 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5353
5354 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5355 {
5356 tp->tx_queue_status[queue] = TRANSMITING;
5357 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5358 }
5359
5360 return err;
5361}
5362
5363static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5364{
5365 struct net_local *tp = netdev_priv(dev);
5366 __u16 status, err = 0;
5367 int cstatus;
5368
5369 if(smctr_debug > 10)
5370 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5371
5372 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5373 {
5374 if(status & 0x7e00 )
5375 {
5376 err = HARDWARE_FAILED;
5377 break;
5378 }
5379
5380 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5381 queue)) != SUCCESS)
5382 break;
5383
5384 smctr_disable_16bit(dev);
5385
5386 if(tp->mode_bits & UMAC)
5387 {
5388 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5389 cstatus = NO_SUCH_DESTINATION;
5390 else
5391 {
5392 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5393 cstatus = DEST_OUT_OF_RESOURCES;
5394 else
5395 {
5396 if(status & FCB_TX_STATUS_E)
5397 cstatus = MAX_COLLISIONS;
5398 else
5399 cstatus = SUCCESS;
5400 }
5401 }
5402 }
5403 else
5404 cstatus = SUCCESS;
5405
5406 if(queue == BUG_QUEUE)
5407 err = SUCCESS;
5408
5409 smctr_enable_16bit(dev);
5410 if(err != SUCCESS)
5411 break;
5412 }
5413
5414 return err;
5415}
5416
5417static unsigned short smctr_tx_move_frame(struct net_device *dev,
5418 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5419{
5420 struct net_local *tp = netdev_priv(dev);
5421 unsigned int ram_usable;
5422 __u32 flen, len, offset = 0;
5423 __u8 *frag, *page;
5424
5425 if(smctr_debug > 10)
5426 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5427
5428 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5429 frag = skb->data;
5430 flen = skb->len;
5431
5432 while(flen > 0 && bytes > 0)
5433 {
5434 smctr_set_page(dev, pbuff);
5435
5436 offset = SMC_PAGE_OFFSET(pbuff);
5437
5438 if(offset + flen > ram_usable)
5439 len = ram_usable - offset;
5440 else
5441 len = flen;
5442
5443 if(len > bytes)
5444 len = bytes;
5445
5446 page = (char *) (offset + tp->ram_access);
5447 memcpy(page, frag, len);
5448
5449 flen -=len;
5450 bytes -= len;
5451 frag += len;
5452 pbuff += len;
5453 }
5454
5455 return 0;
5456}
5457
5458
5459static int smctr_update_err_stats(struct net_device *dev)
5460{
5461 struct net_local *tp = netdev_priv(dev);
5462 struct tr_statistics *tstat = &tp->MacStat;
5463
5464 if(tstat->internal_errors)
5465 tstat->internal_errors
5466 += *(tp->misc_command_data + 0) & 0x00ff;
5467
5468 if(tstat->line_errors)
5469 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5470
5471 if(tstat->A_C_errors)
5472 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5473
5474 if(tstat->burst_errors)
5475 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5476
5477 if(tstat->abort_delimiters)
5478 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5479
5480 if(tstat->recv_congest_count)
5481 tstat->recv_congest_count
5482 += *(tp->misc_command_data + 3) & 0x00ff;
5483
5484 if(tstat->lost_frames)
5485 tstat->lost_frames
5486 += *(tp->misc_command_data + 3) >> 8;
5487
5488 if(tstat->frequency_errors)
5489 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5490
5491 if(tstat->frame_copied_errors)
5492 tstat->frame_copied_errors
5493 += *(tp->misc_command_data + 4) >> 8;
5494
5495 if(tstat->token_errors)
5496 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5497
5498 return 0;
5499}
5500
5501static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5502{
5503 struct net_local *tp = netdev_priv(dev);
5504 FCBlock *fcb;
5505 BDBlock *bdb;
5506 __u16 size, len;
5507
5508 fcb = tp->rx_fcb_curr[queue];
5509 len = fcb->frame_length;
5510
5511 fcb->frame_status = 0;
5512 fcb->info = FCB_CHAIN_END;
5513 fcb->back_ptr->info = FCB_WARNING;
5514
5515 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5516
5517
5518 size = (len >> RX_BDB_SIZE_SHIFT);
5519 if(len & RX_DATA_BUFFER_SIZE_MASK)
5520 size += sizeof(BDBlock);
5521 size &= (~RX_BDB_SIZE_MASK);
5522
5523
5524 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5525 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5526 {
5527 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5528 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5529 }
5530
5531 bdb->back_ptr->info = BDB_CHAIN_END;
5532 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5533 tp->rx_bdb_curr[queue] = bdb;
5534
5535 return 0;
5536}
5537
5538static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5539 __u16 queue)
5540{
5541 struct net_local *tp = netdev_priv(dev);
5542
5543 if(smctr_debug > 20)
5544 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5545
5546 if(tp->num_tx_fcbs_used[queue] <= 0)
5547 return HARDWARE_FAILED;
5548 else
5549 {
5550 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5551 {
5552 tp->tx_buff_used[queue] = 0;
5553 return HARDWARE_FAILED;
5554 }
5555
5556 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5557
5558
5559
5560
5561
5562
5563
5564 if(tp->tx_buff_used[queue] == 0)
5565 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5566
5567 tp->num_tx_fcbs_used[queue]--;
5568 fcb->frame_status = 0;
5569 tp->tx_fcb_end[queue] = fcb->next_ptr;
5570 netif_wake_queue(dev);
5571 return 0;
5572 }
5573}
5574
5575static int smctr_wait_cmd(struct net_device *dev)
5576{
5577 struct net_local *tp = netdev_priv(dev);
5578 unsigned int loop_count = 0x20000;
5579
5580 if(smctr_debug > 10)
5581 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5582
5583 while(loop_count)
5584 {
5585 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5586 break;
5587 udelay(1);
5588 loop_count--;
5589 }
5590
5591 if(loop_count == 0)
5592 return HARDWARE_FAILED;
5593
5594 if(tp->acb_head->cmd_done_status & 0xff)
5595 return HARDWARE_FAILED;
5596
5597 return 0;
5598}
5599
5600static int smctr_wait_while_cbusy(struct net_device *dev)
5601{
5602 struct net_local *tp = netdev_priv(dev);
5603 unsigned int timeout = 0x20000;
5604 int ioaddr = dev->base_addr;
5605 __u8 r;
5606
5607 if(tp->bic_type == BIC_585_CHIP)
5608 {
5609 while(timeout)
5610 {
5611 r = inb(ioaddr + HWR);
5612 if((r & HWR_CBUSY) == 0)
5613 break;
5614 timeout--;
5615 }
5616 }
5617 else
5618 {
5619 while(timeout)
5620 {
5621 r = inb(ioaddr + CSR);
5622 if((r & CSR_CBUSY) == 0)
5623 break;
5624 timeout--;
5625 }
5626 }
5627
5628 if(timeout)
5629 return 0;
5630 else
5631 return HARDWARE_FAILED;
5632}
5633
5634#ifdef MODULE
5635
5636static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5637static int io[SMCTR_MAX_ADAPTERS];
5638static int irq[SMCTR_MAX_ADAPTERS];
5639
5640MODULE_LICENSE("GPL");
5641MODULE_FIRMWARE("tr_smctr.bin");
5642
5643module_param_array(io, int, NULL, 0);
5644module_param_array(irq, int, NULL, 0);
5645module_param(ringspeed, int, 0);
5646
5647static struct net_device * __init setup_card(int n)
5648{
5649 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5650 int err;
5651
5652 if (!dev)
5653 return ERR_PTR(-ENOMEM);
5654
5655 dev->irq = irq[n];
5656 err = smctr_probe1(dev, io[n]);
5657 if (err)
5658 goto out;
5659
5660 err = register_netdev(dev);
5661 if (err)
5662 goto out1;
5663 return dev;
5664 out1:
5665#ifdef CONFIG_MCA_LEGACY
5666 { struct net_local *tp = netdev_priv(dev);
5667 if (tp->slot_num)
5668 mca_mark_as_unused(tp->slot_num);
5669 }
5670#endif
5671 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5672 free_irq(dev->irq, dev);
5673out:
5674 free_netdev(dev);
5675 return ERR_PTR(err);
5676}
5677
5678int __init init_module(void)
5679{
5680 int i, found = 0;
5681 struct net_device *dev;
5682
5683 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5684 dev = io[0]? setup_card(i) : smctr_probe(-1);
5685 if (!IS_ERR(dev)) {
5686 ++found;
5687 dev_smctr[i] = dev;
5688 }
5689 }
5690
5691 return found ? 0 : -ENODEV;
5692}
5693
5694void __exit cleanup_module(void)
5695{
5696 int i;
5697
5698 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5699 struct net_device *dev = dev_smctr[i];
5700
5701 if (dev) {
5702
5703 unregister_netdev(dev);
5704#ifdef CONFIG_MCA_LEGACY
5705 { struct net_local *tp = netdev_priv(dev);
5706 if (tp->slot_num)
5707 mca_mark_as_unused(tp->slot_num);
5708 }
5709#endif
5710 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5711 if (dev->irq)
5712 free_irq(dev->irq, dev);
5713
5714 free_netdev(dev);
5715 }
5716 }
5717}
5718#endif
5719