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