2 * smctr.c: A network driver for the SMC Token Ring Adapters.
4 * Written by Jay Schulist <jschlst@samba.org>
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
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)
14 * - SMC TokenCard SDK.
17 * JS Jay Schulist <jschlst@samba.org>
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.
26 * 1. Multicast support.
28 * Initial 2.5 cleanup Alan Cox <alan@redhat.com> 2002/10/28
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
36 #include <linux/ptrace.h>
37 #include <linux/ioport.h>
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>
53 #include <asm/system.h>
58 #if BITS_PER_LONG == 64
59 #error FIXME: driver does not support 64-bit platforms
62 #include "smctr.h" /* Our Stuff */
63 #include "smctr_firmware.h" /* SMC adapter firmware */
65 static char version[] __initdata = KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
66 static const char cardname[] = "smctr";
69 #define SMCTR_IO_EXTENT 20
71 #ifdef CONFIG_MCA_LEGACY
72 static unsigned int smctr_posid = 0x6ec6;
77 /* SMC Name of the Adapter. */
78 static char smctr_name[] = "SMC TokenCard";
79 static char *smctr_model = "Unknown";
81 /* Use 0 for production, 1 for verification, 2 for debug, and
82 * 3 for very verbose debug.
87 static unsigned int smctr_debug = SMCTR_DEBUG;
89 /* smctr.c prototypes and functions are arranged alphabeticly
90 * for clearity, maintainability and pure old fashion fun.
93 static int smctr_alloc_shared_memory(struct net_device *dev);
96 static int smctr_bypass_state(struct net_device *dev);
99 static int smctr_checksum_firmware(struct net_device *dev);
100 static int __init smctr_chk_isa(struct net_device *dev);
101 static int smctr_chg_rx_mask(struct net_device *dev);
102 static int smctr_clear_int(struct net_device *dev);
103 static int smctr_clear_trc_reset(int ioaddr);
104 static int smctr_close(struct net_device *dev);
107 static int smctr_decode_firmware(struct net_device *dev);
108 static int smctr_disable_16bit(struct net_device *dev);
109 static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
110 static int smctr_disable_bic_int(struct net_device *dev);
113 static int smctr_enable_16bit(struct net_device *dev);
114 static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
115 static int smctr_enable_adapter_ram(struct net_device *dev);
116 static int smctr_enable_bic_int(struct net_device *dev);
119 static int __init smctr_get_boardid(struct net_device *dev, int mca);
120 static int smctr_get_group_address(struct net_device *dev);
121 static int smctr_get_functional_address(struct net_device *dev);
122 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
123 static int smctr_get_physical_drop_number(struct net_device *dev);
124 static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
125 static int smctr_get_station_id(struct net_device *dev);
126 static struct net_device_stats *smctr_get_stats(struct net_device *dev);
127 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
129 static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
132 static int smctr_hardware_send_packet(struct net_device *dev,
133 struct net_local *tp);
135 static int smctr_init_acbs(struct net_device *dev);
136 static int smctr_init_adapter(struct net_device *dev);
137 static int smctr_init_card_real(struct net_device *dev);
138 static int smctr_init_rx_bdbs(struct net_device *dev);
139 static int smctr_init_rx_fcbs(struct net_device *dev);
140 static int smctr_init_shared_memory(struct net_device *dev);
141 static int smctr_init_tx_bdbs(struct net_device *dev);
142 static int smctr_init_tx_fcbs(struct net_device *dev);
143 static int smctr_internal_self_test(struct net_device *dev);
144 static irqreturn_t smctr_interrupt(int irq, void *dev_id);
145 static int smctr_issue_enable_int_cmd(struct net_device *dev,
146 __u16 interrupt_enable_mask);
147 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
149 static int smctr_issue_init_timers_cmd(struct net_device *dev);
150 static int smctr_issue_init_txrx_cmd(struct net_device *dev);
151 static int smctr_issue_insert_cmd(struct net_device *dev);
152 static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
153 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
154 static int smctr_issue_remove_cmd(struct net_device *dev);
155 static int smctr_issue_resume_acb_cmd(struct net_device *dev);
156 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
157 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
158 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
159 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
160 static int smctr_issue_test_hic_cmd(struct net_device *dev);
161 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
162 static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
163 static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
164 static int smctr_issue_write_byte_cmd(struct net_device *dev,
165 short aword_cnt, void *byte);
166 static int smctr_issue_write_word_cmd(struct net_device *dev,
167 short aword_cnt, void *word);
170 static int smctr_join_complete_state(struct net_device *dev);
173 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
174 static int smctr_load_firmware(struct net_device *dev);
175 static int smctr_load_node_addr(struct net_device *dev);
176 static int smctr_lobe_media_test(struct net_device *dev);
177 static int smctr_lobe_media_test_cmd(struct net_device *dev);
178 static int smctr_lobe_media_test_state(struct net_device *dev);
181 static int smctr_make_8025_hdr(struct net_device *dev,
182 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
183 static int smctr_make_access_pri(struct net_device *dev,
184 MAC_SUB_VECTOR *tsv);
185 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
186 static int smctr_make_auth_funct_class(struct net_device *dev,
187 MAC_SUB_VECTOR *tsv);
188 static int smctr_make_corr(struct net_device *dev,
189 MAC_SUB_VECTOR *tsv, __u16 correlator);
190 static int smctr_make_funct_addr(struct net_device *dev,
191 MAC_SUB_VECTOR *tsv);
192 static int smctr_make_group_addr(struct net_device *dev,
193 MAC_SUB_VECTOR *tsv);
194 static int smctr_make_phy_drop_num(struct net_device *dev,
195 MAC_SUB_VECTOR *tsv);
196 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
197 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
198 static int smctr_make_ring_station_status(struct net_device *dev,
199 MAC_SUB_VECTOR *tsv);
200 static int smctr_make_ring_station_version(struct net_device *dev,
201 MAC_SUB_VECTOR *tsv);
202 static int smctr_make_tx_status_code(struct net_device *dev,
203 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
204 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
205 MAC_SUB_VECTOR *tsv);
206 static int smctr_make_wrap_data(struct net_device *dev,
207 MAC_SUB_VECTOR *tsv);
210 static int smctr_open(struct net_device *dev);
211 static int smctr_open_tr(struct net_device *dev);
214 struct net_device *smctr_probe(int unit);
215 static int __init smctr_probe1(struct net_device *dev, int ioaddr);
216 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
217 struct net_device *dev, __u16 rx_status);
220 static int smctr_ram_memory_test(struct net_device *dev);
221 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
223 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
225 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
226 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
227 MAC_HEADER *rmf, __u16 *correlator);
228 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
230 static int smctr_reset_adapter(struct net_device *dev);
231 static int smctr_restart_tx_chain(struct net_device *dev, short queue);
232 static int smctr_ring_status_chg(struct net_device *dev);
233 static int smctr_rx_frame(struct net_device *dev);
236 static int smctr_send_dat(struct net_device *dev);
237 static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev);
238 static int smctr_send_lobe_media_test(struct net_device *dev);
239 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
241 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
243 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
245 static int smctr_send_rpt_tx_forward(struct net_device *dev,
246 MAC_HEADER *rmf, __u16 tx_fstatus);
247 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
248 __u16 rcode, __u16 correlator);
249 static int smctr_send_rq_init(struct net_device *dev);
250 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
252 static int smctr_set_auth_access_pri(struct net_device *dev,
253 MAC_SUB_VECTOR *rsv);
254 static int smctr_set_auth_funct_class(struct net_device *dev,
255 MAC_SUB_VECTOR *rsv);
256 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
258 static int smctr_set_error_timer_value(struct net_device *dev,
259 MAC_SUB_VECTOR *rsv);
260 static int smctr_set_frame_forward(struct net_device *dev,
261 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
262 static int smctr_set_local_ring_num(struct net_device *dev,
263 MAC_SUB_VECTOR *rsv);
264 static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
265 static void smctr_set_multicast_list(struct net_device *dev);
266 static int smctr_set_page(struct net_device *dev, __u8 *buf);
267 static int smctr_set_phy_drop(struct net_device *dev,
268 MAC_SUB_VECTOR *rsv);
269 static int smctr_set_ring_speed(struct net_device *dev);
270 static int smctr_set_rx_look_ahead(struct net_device *dev);
271 static int smctr_set_trc_reset(int ioaddr);
272 static int smctr_setup_single_cmd(struct net_device *dev,
273 __u16 command, __u16 subcommand);
274 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
275 __u16 command, __u16 subcommand);
276 static char *smctr_malloc(struct net_device *dev, __u16 size);
277 static int smctr_status_chg(struct net_device *dev);
280 static void smctr_timeout(struct net_device *dev);
281 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
283 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
284 static unsigned short smctr_tx_move_frame(struct net_device *dev,
285 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
288 static int smctr_update_err_stats(struct net_device *dev);
289 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
290 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
294 static int smctr_wait_cmd(struct net_device *dev);
295 static int smctr_wait_while_cbusy(struct net_device *dev);
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))
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!!!
305 * Order of memory allocation:
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
314 * 6. NON-MAC TX FCB'S
316 * 8. NON-MAC TX BDB'S
318 * 10. NON-MAC RX FCB'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)
324 * 15. NON-MAC TX Data Buffer
325 * 16. NON-MAC RX Data Buffer
327 static int smctr_alloc_shared_memory(struct net_device *dev)
329 struct net_local *tp = netdev_priv(dev);
332 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
334 /* Allocate initial System Control Block pointer.
335 * This pointer is located in the last page, last offset - 4.
337 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
338 - (long)ISCP_BLOCK_SIZE);
340 /* Allocate System Control Blocks. */
341 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
342 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
344 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
345 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
347 tp->acb_head = (ACBlock *)smctr_malloc(dev,
348 sizeof(ACBlock)*tp->num_acbs);
349 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
351 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
352 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
354 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
355 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
357 /* Allocate transmit FCBs. */
358 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
359 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
361 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
362 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
364 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
365 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
367 /* Allocate transmit BDBs. */
368 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
369 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
371 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
372 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
374 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
375 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
377 /* Allocate receive FCBs. */
378 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
379 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
381 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
382 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
384 /* Allocate receive BDBs. */
385 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
386 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
388 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
390 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
391 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
393 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
395 /* Allocate MAC transmit buffers.
396 * MAC Tx Buffers doen't have to be on an ODD Boundry.
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);
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);
409 /* Allocate MAC receive data buffers.
410 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
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);
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.
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);
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.
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);
441 /* Enter Bypass state. */
442 static int smctr_bypass_state(struct net_device *dev)
447 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
449 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
454 static int smctr_checksum_firmware(struct net_device *dev)
456 struct net_local *tp = netdev_priv(dev);
457 __u16 i, checksum = 0;
460 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
462 smctr_enable_adapter_ctrl_store(dev);
464 for(i = 0; i < CS_RAM_SIZE; i += 2)
465 checksum += *((__u16 *)(tp->ram_access + i));
467 tp->microcode_version = *(__u16 *)(tp->ram_access
468 + CS_RAM_VERSION_OFFSET);
469 tp->microcode_version >>= 8;
471 smctr_disable_adapter_ctrl_store(dev);
479 static int __init smctr_chk_mca(struct net_device *dev)
481 #ifdef CONFIG_MCA_LEGACY
482 struct net_local *tp = netdev_priv(dev);
484 __u8 r1, r2, r3, r4, r5;
486 current_slot = mca_find_unused_adapter(smctr_posid, 0);
487 if(current_slot == MCA_NOTFOUND)
490 mca_set_adapter_name(current_slot, smctr_name);
491 mca_mark_as_used(current_slot);
492 tp->slot_num = current_slot;
494 r1 = mca_read_stored_pos(tp->slot_num, 2);
495 r2 = mca_read_stored_pos(tp->slot_num, 3);
498 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
500 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
502 r1 = inb(CNFG_POS_REG1);
503 r2 = inb(CNFG_POS_REG0);
505 tp->bic_type = BIC_594_CHIP;
508 r2 = mca_read_stored_pos(tp->slot_num, 2);
510 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
511 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
514 r5 = mca_read_stored_pos(tp->slot_num, 5);
534 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
535 release_region(dev->base_addr, SMCTR_IO_EXTENT);
540 r3 = mca_read_stored_pos(tp->slot_num, 3);
541 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
543 tp->ram_base += 0x010000;
545 tp->ram_base += 0xF00000;
551 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
552 tp->ram_size = (__u16)CNFG_SIZE_64KB;
553 tp->board_id |= TOKEN_MEDIA;
555 r4 = mca_read_stored_pos(tp->slot_num, 4);
556 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
558 tp->rom_base += 0x010000;
564 tp->rom_size = CNFG_SIZE_8KB;
567 tp->rom_size = CNFG_SIZE_16KB;
570 tp->rom_size = CNFG_SIZE_32KB;
573 tp->rom_size = ROM_DISABLE;
576 /* Get Media Type. */
577 r5 = mca_read_stored_pos(tp->slot_num, 5);
578 r5 &= CNFG_MEDIA_TYPE_MASK;
582 tp->media_type = MEDIA_STP_4;
586 tp->media_type = MEDIA_STP_16;
590 tp->media_type = MEDIA_UTP_16;
594 tp->media_type = MEDIA_UTP_4;
599 r2 = mca_read_stored_pos(tp->slot_num, 2);
601 tp->mode_bits |= EARLY_TOKEN_REL;
604 outb(CNFG_POS_CONTROL_REG, 0);
606 tp->board_id = smctr_get_boardid(dev, 1);
607 switch(tp->board_id & 0xffff)
610 smctr_model = "8115T/A";
614 if(tp->extra_info & CHIP_REV_MASK)
615 smctr_model = "8115T rev XE";
617 smctr_model = "8115T rev XD";
621 smctr_model = "Unknown";
628 #endif /* CONFIG_MCA_LEGACY */
631 static int smctr_chg_rx_mask(struct net_device *dev)
633 struct net_local *tp = netdev_priv(dev);
637 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
639 smctr_enable_16bit(dev);
640 smctr_set_page(dev, (__u8 *)tp->ram_access);
642 if(tp->mode_bits & LOOPING_MODE_MASK)
643 tp->config_word0 |= RX_OWN_BIT;
645 tp->config_word0 &= ~RX_OWN_BIT;
647 if(tp->receive_mask & PROMISCUOUS_MODE)
648 tp->config_word0 |= PROMISCUOUS_BIT;
650 tp->config_word0 &= ~PROMISCUOUS_BIT;
652 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
653 tp->config_word0 |= SAVBAD_BIT;
655 tp->config_word0 &= ~SAVBAD_BIT;
657 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
658 tp->config_word0 |= RXATMAC;
660 tp->config_word0 &= ~RXATMAC;
662 if(tp->receive_mask & ACCEPT_MULTI_PROM)
663 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
665 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
667 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
668 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
671 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
672 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
674 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
677 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
683 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
689 smctr_disable_16bit(dev);
694 static int smctr_clear_int(struct net_device *dev)
696 struct net_local *tp = netdev_priv(dev);
698 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
703 static int smctr_clear_trc_reset(int ioaddr)
707 r = inb(ioaddr + MSR);
708 outb(~MSR_RST & r, ioaddr + MSR);
714 * The inverse routine to smctr_open().
716 static int smctr_close(struct net_device *dev)
718 struct net_local *tp = netdev_priv(dev);
722 netif_stop_queue(dev);
726 /* Check to see if adapter is already in a closed state. */
727 if(tp->status != OPEN)
730 smctr_enable_16bit(dev);
731 smctr_set_page(dev, (__u8 *)tp->ram_access);
733 if((err = smctr_issue_remove_cmd(dev)))
735 smctr_disable_16bit(dev);
741 skb = skb_dequeue(&tp->SendSkbQueue);
752 static int smctr_decode_firmware(struct net_device *dev)
754 struct net_local *tp = netdev_priv(dev);
755 short bit = 0x80, shift = 12;
756 DECODE_TREE_NODE *tree;
764 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
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);
776 while((tree + branch)->tag != LEAF && weight)
778 branch = *ucode & bit ? (tree + branch)->llink
779 : (tree + branch)->rlink;
791 buff |= (tree + branch)->info << shift;
796 *(mem++) = SWAP_BYTES(buff);
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.
807 *(mem++) = SWAP_BYTES(buff);
812 static int smctr_disable_16bit(struct net_device *dev)
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).
823 static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
825 struct net_local *tp = netdev_priv(dev);
826 int ioaddr = dev->base_addr;
829 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
831 tp->trc_mask |= CSR_WCSS;
832 outb(tp->trc_mask, ioaddr + CSR);
837 static int smctr_disable_bic_int(struct net_device *dev)
839 struct net_local *tp = netdev_priv(dev);
840 int ioaddr = dev->base_addr;
842 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
843 | CSR_MSKTINT | CSR_WCSS;
844 outb(tp->trc_mask, ioaddr + CSR);
849 static int smctr_enable_16bit(struct net_device *dev)
851 struct net_local *tp = netdev_priv(dev);
854 if(tp->adapter_bus == BUS_ISA16_TYPE)
856 r = inb(dev->base_addr + LAAR);
857 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
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).
869 static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
871 struct net_local *tp = netdev_priv(dev);
872 int ioaddr = dev->base_addr;
875 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
877 smctr_set_trc_reset(ioaddr);
878 smctr_enable_adapter_ram(dev);
880 tp->trc_mask &= ~CSR_WCSS;
881 outb(tp->trc_mask, ioaddr + CSR);
886 static int smctr_enable_adapter_ram(struct net_device *dev)
888 int ioaddr = dev->base_addr;
892 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
894 r = inb(ioaddr + MSR);
895 outb(MSR_MEMB | r, ioaddr + MSR);
900 static int smctr_enable_bic_int(struct net_device *dev)
902 struct net_local *tp = netdev_priv(dev);
903 int ioaddr = dev->base_addr;
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);
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);
926 static int __init smctr_chk_isa(struct net_device *dev)
928 struct net_local *tp = netdev_priv(dev);
929 int ioaddr = dev->base_addr;
930 __u8 r1, r2, b, chksum = 0;
936 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
938 if((ioaddr & 0x1F) != 0)
941 /* Grab the region so that no one else tries to probe our ioports. */
942 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
947 /* Checksum SMC node address */
948 for(i = 0; i < 8; i++)
950 b = inb(ioaddr + LAR0 + i);
954 if (chksum != NODE_ADDR_CKSUM)
957 b = inb(ioaddr + BDID);
958 if(b != BRD_ID_8115T)
960 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
964 /* Check for 8115T Board ID */
966 for(r = 0; r < 8; r++)
968 r1 = inb(ioaddr + 0x8 + r);
972 /* value of RegF adds up the sum to 0xFF */
973 if((r2 != 0xFF) && (r2 != 0xEE))
977 tp->board_id = smctr_get_boardid(dev, 0);
978 switch(tp->board_id & 0xffff)
981 smctr_model = "8115T/A";
985 if(tp->extra_info & CHIP_REV_MASK)
986 smctr_model = "8115T rev XE";
988 smctr_model = "8115T rev XD";
992 smctr_model = "Unknown";
996 /* Store BIC type. */
997 tp->bic_type = BIC_584_CHIP;
998 tp->nic_type = NIC_825_CHIP;
1001 tp->ram_usable = CNFG_SIZE_16KB;
1002 tp->ram_size = CNFG_SIZE_64KB;
1004 /* Get 58x Ram Base */
1008 r2 = inb(ioaddr + CNFG_LAAR_584);
1009 r2 &= CNFG_LAAR_MASK;
1011 r2 |= ((r1 & 0x38) >> 3);
1013 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1017 r1 = inb(ioaddr + CNFG_ICR_583);
1018 r1 &= CNFG_ICR_IR2_584;
1020 r2 = inb(ioaddr + CNFG_IRR_583);
1021 r2 &= CNFG_IRR_IRQS; /* 0x60 */
1043 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1060 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1064 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
1067 /* Get 58x Rom Base */
1068 r1 = inb(ioaddr + CNFG_BIO_583);
1072 tp->rom_base = (__u32)r1 << 13;
1074 /* Get 58x Rom Size */
1075 r1 = inb(ioaddr + CNFG_BIO_583);
1078 tp->rom_size = ROM_DISABLE;
1082 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1085 /* Get 58x Boot Status */
1086 r1 = inb(ioaddr + CNFG_GP2);
1088 tp->mode_bits &= (~BOOT_STATUS_MASK);
1090 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1091 tp->mode_bits |= BOOT_TYPE_1;
1093 /* Get 58x Zero Wait State */
1094 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1096 r1 = inb(ioaddr + CNFG_IRR_583);
1098 if(r1 & CNFG_IRR_ZWS)
1099 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1101 if(tp->board_id & BOARD_16BIT)
1103 r1 = inb(ioaddr + CNFG_LAAR_584);
1105 if(r1 & CNFG_LAAR_ZWS)
1106 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1109 /* Get 584 Media Menu */
1110 tp->media_menu = 14;
1111 r1 = inb(ioaddr + CNFG_IRR_583);
1113 tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1114 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1116 /* Get Advanced Features */
1117 if(((r1 & 0x6) >> 1) == 0x3)
1118 tp->media_type |= MEDIA_UTP_16;
1121 if(((r1 & 0x6) >> 1) == 0x2)
1122 tp->media_type |= MEDIA_STP_16;
1125 if(((r1 & 0x6) >> 1) == 0x1)
1126 tp->media_type |= MEDIA_UTP_4;
1129 tp->media_type |= MEDIA_STP_4;
1133 r1 = inb(ioaddr + CNFG_GP2);
1134 if(!(r1 & 0x2) ) /* GP2_ETRD */
1135 tp->mode_bits |= EARLY_TOKEN_REL;
1137 /* see if the chip is corrupted
1138 if(smctr_read_584_chksum(ioaddr))
1140 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1141 free_irq(dev->irq, dev);
1150 release_region(ioaddr, SMCTR_IO_EXTENT);
1155 static int __init smctr_get_boardid(struct net_device *dev, int mca)
1157 struct net_local *tp = netdev_priv(dev);
1158 int ioaddr = dev->base_addr;
1162 tp->board_id = BoardIdMask = 0;
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);
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);
1178 r = inb(ioaddr + BID_REG_1);
1180 outb(r, ioaddr + BID_REG_1);
1181 r = inb(ioaddr + BID_REG_1);
1183 if(r & BID_SIXTEEN_BIT_BIT)
1185 tp->extra_info |= SLOT_16BIT;
1186 tp->adapter_bus = BUS_ISA16_TYPE;
1189 tp->adapter_bus = BUS_ISA8_TYPE;
1192 tp->adapter_bus = BUS_MCA_TYPE;
1194 /* Get Board Id Byte */
1195 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1197 /* if Major version > 1.0 then
1203 r1 = inb(ioaddr + BID_REG_1);
1205 r1 |= BID_OTHER_BIT;
1207 outb(r1, ioaddr + BID_REG_1);
1208 r1 = inb(ioaddr + BID_REG_3);
1211 r1 |= BID_ENGR_PAGE;
1213 outb(r1, ioaddr + BID_REG_3);
1214 r1 = inb(ioaddr + BID_REG_1);
1216 r1 |= (BID_RLA | BID_OTHER_BIT);
1218 outb(r1, ioaddr + BID_REG_1);
1220 r1 = inb(ioaddr + BID_REG_1);
1221 while(r1 & BID_RECALL_DONE_MASK)
1222 r1 = inb(ioaddr + BID_REG_1);
1224 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1226 /* clear chip rev bits */
1227 tp->extra_info &= ~CHIP_REV_MASK;
1228 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1230 r1 = inb(ioaddr + BID_REG_1);
1232 r1 |= BID_OTHER_BIT;
1234 outb(r1, ioaddr + BID_REG_1);
1235 r1 = inb(ioaddr + BID_REG_3);
1240 outb(r1, ioaddr + BID_REG_3);
1241 r1 = inb(ioaddr + BID_REG_1);
1246 outb(r1, ioaddr + BID_REG_1);
1247 r1 = inb(ioaddr + BID_REG_1);
1249 while(r1 & BID_RECALL_DONE_MASK)
1250 r1 = inb(ioaddr + BID_REG_1);
1252 return (BoardIdMask);
1255 static int smctr_get_group_address(struct net_device *dev)
1257 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1259 return(smctr_wait_cmd(dev));
1262 static int smctr_get_functional_address(struct net_device *dev)
1264 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1266 return(smctr_wait_cmd(dev));
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.
1273 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1275 struct net_local *tp = netdev_priv(dev);
1276 unsigned int mem_used = 0;
1278 /* Allocate System Control Blocks. */
1279 mem_used += sizeof(SCGBlock);
1281 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1282 mem_used += sizeof(SCLBlock);
1284 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1285 mem_used += sizeof(ACBlock) * tp->num_acbs;
1287 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1288 mem_used += sizeof(ISBlock);
1290 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1291 mem_used += MISC_DATA_SIZE;
1293 /* Allocate transmit FCB's. */
1294 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
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];
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];
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];
1309 /* Allocate receive BDBs. */
1310 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1312 /* Allocate MAC transmit buffers.
1313 * MAC transmit buffers don't have to be on an ODD Boundry.
1315 mem_used += tp->tx_buff_size[MAC_QUEUE];
1317 /* Allocate BUG transmit buffers. */
1318 mem_used += tp->tx_buff_size[BUG_QUEUE];
1320 /* Allocate MAC receive data buffers.
1321 * MAC receive buffers don't have to be on a 256 byte boundary.
1323 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
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.
1330 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1333 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1334 * AND NON-MAC RX DATA BUFFERS
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
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.
1348 return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock)));
1351 static int smctr_get_physical_drop_number(struct net_device *dev)
1353 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1355 return(smctr_wait_cmd(dev));
1358 static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1360 struct net_local *tp = netdev_priv(dev);
1363 bdb = (BDBlock *)((__u32)tp->ram_access
1364 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1366 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1368 return ((__u8 *)bdb->data_block_ptr);
1371 static int smctr_get_station_id(struct net_device *dev)
1373 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1375 return(smctr_wait_cmd(dev));
1379 * Get the current statistics. This may be called with the card open
1382 static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1384 struct net_local *tp = netdev_priv(dev);
1386 return ((struct net_device_stats *)&tp->MacStat);
1389 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1392 struct net_local *tp = netdev_priv(dev);
1395 unsigned short alloc_size;
1396 unsigned short *temp;
1398 if(smctr_debug > 20)
1399 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
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));
1405 /* round off the input pkt size to the nearest even number */
1406 alloc_size = (bytes_count + 1) & 0xfffe;
1408 /* check if enough mem */
1409 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
1410 return ((FCBlock *)(-1L));
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
1416 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1417 >= (unsigned long)(tp->tx_buff_end[queue]))
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]);
1424 if((tp->tx_buff_used[queue] + alloc_size)
1425 > tp->tx_buff_size[queue])
1427 return ((FCBlock *)(-1L));
1431 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
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));
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);
1447 pFCB = tp->tx_fcb_curr[queue];
1448 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1453 static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1455 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1457 return(smctr_wait_cmd(dev));
1460 static int smctr_hardware_send_packet(struct net_device *dev,
1461 struct net_local *tp)
1463 struct tr_statistics *tstat = &tp->MacStat;
1464 struct sk_buff *skb;
1467 if(smctr_debug > 10)
1468 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1470 if(tp->status != OPEN)
1473 if(tp->monitor_state_ready != 1)
1478 /* Send first buffer from queue */
1479 skb = skb_dequeue(&tp->SendSkbQueue);
1485 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size) return (-1);
1487 smctr_enable_16bit(dev);
1488 smctr_set_page(dev, (__u8 *)tp->ram_access);
1490 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1491 == (FCBlock *)(-1L))
1493 smctr_disable_16bit(dev);
1497 smctr_tx_move_frame(dev, skb,
1498 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1500 smctr_set_page(dev, (__u8 *)fcb);
1502 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1505 tstat->tx_packets++;
1507 smctr_disable_16bit(dev);
1513 static int smctr_init_acbs(struct net_device *dev)
1515 struct net_local *tp = netdev_priv(dev);
1519 if(smctr_debug > 10)
1520 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1523 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1524 acb->cmd_info = ACB_CHAIN_END;
1527 acb->data_offset_lo = 0;
1528 acb->data_offset_hi = 0;
1530 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1531 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1533 for(i = 1; i < tp->num_acbs; i++)
1535 acb = acb->next_ptr;
1536 acb->cmd_done_status
1537 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1538 acb->cmd_info = ACB_CHAIN_END;
1541 acb->data_offset_lo = 0;
1542 acb->data_offset_hi = 0;
1544 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1545 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
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;
1557 static int smctr_init_adapter(struct net_device *dev)
1559 struct net_local *tp = netdev_priv(dev);
1562 if(smctr_debug > 10)
1563 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
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;
1570 if(!(tp->group_address_0 & 0x0080))
1571 tp->group_address_0 |= 0x00C0;
1573 if(!(tp->functional_address_0 & 0x00C0))
1574 tp->functional_address_0 |= 0x00C0;
1576 tp->functional_address[0] &= 0xFF7F;
1578 if(tp->authorized_function_classes == 0)
1579 tp->authorized_function_classes = 0x7FFF;
1581 if(tp->authorized_access_priority == 0)
1582 tp->authorized_access_priority = 0x06;
1584 smctr_disable_bic_int(dev);
1585 smctr_set_trc_reset(dev->base_addr);
1587 smctr_enable_16bit(dev);
1588 smctr_set_page(dev, (__u8 *)tp->ram_access);
1590 if(smctr_checksum_firmware(dev))
1592 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name); return (-ENOENT);
1595 if((err = smctr_ram_memory_test(dev)))
1597 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1601 smctr_set_rx_look_ahead(dev);
1602 smctr_load_node_addr(dev);
1604 /* Initialize adapter for Internal Self Test. */
1605 smctr_reset_adapter(dev);
1606 if((err = smctr_init_card_real(dev)))
1608 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1613 /* This routine clobbers the TRC's internal registers. */
1614 if((err = smctr_internal_self_test(dev)))
1616 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1621 /* Re-Initialize adapter's internal registers */
1622 smctr_reset_adapter(dev);
1623 if((err = smctr_init_card_real(dev)))
1625 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1630 smctr_enable_bic_int(dev);
1632 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1635 smctr_disable_16bit(dev);
1640 static int smctr_init_card_real(struct net_device *dev)
1642 struct net_local *tp = netdev_priv(dev);
1645 if(smctr_debug > 10)
1646 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1648 tp->sh_mem_used = 0;
1649 tp->num_acbs = NUM_OF_ACBS;
1651 /* Range Check Max Packet Size */
1652 if(tp->max_packet_size < 256)
1653 tp->max_packet_size = 256;
1656 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1657 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1660 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1661 / tp->max_packet_size) - 1;
1663 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1664 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1667 if(tp->num_of_tx_buffs == 0)
1668 tp->num_of_tx_buffs = 1;
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;
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;
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;
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;
1694 if(tp->extra_info & CHIP_REV_MASK)
1695 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1697 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1699 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1701 smctr_alloc_shared_memory(dev);
1702 smctr_init_shared_memory(dev);
1704 if((err = smctr_issue_init_timers_cmd(dev)))
1707 if((err = smctr_issue_init_txrx_cmd(dev)))
1709 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1716 static int smctr_init_rx_bdbs(struct net_device *dev)
1718 struct net_local *tp = netdev_priv(dev);
1723 if(smctr_debug > 10)
1724 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1726 for(i = 0; i < NUM_RX_QS_USED; i++)
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);
1736 if(i == NON_MAC_QUEUE)
1737 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1739 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1741 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
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);
1752 if(i == NON_MAC_QUEUE)
1753 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1755 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1758 bdb->next_ptr = tp->rx_bdb_head[i];
1759 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1761 tp->rx_bdb_head[i]->back_ptr = bdb;
1762 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1768 static int smctr_init_rx_fcbs(struct net_device *dev)
1770 struct net_local *tp = netdev_priv(dev);
1774 for(i = 0; i < NUM_RX_QS_USED; i++)
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);
1784 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1786 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
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;
1794 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1796 if(i == NON_MAC_QUEUE)
1798 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1801 = TRC_POINTER(fcb->next_ptr);
1804 fcb->next_ptr = tp->rx_fcb_head[i];
1806 if(i == NON_MAC_QUEUE)
1807 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1809 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1811 tp->rx_fcb_head[i]->back_ptr = fcb;
1812 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1818 static int smctr_init_shared_memory(struct net_device *dev)
1820 struct net_local *tp = netdev_priv(dev);
1824 if(smctr_debug > 10)
1825 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1827 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
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)));
1833 smctr_set_page(dev, (__u8 *)tp->ram_access);
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);
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;
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;
1852 /* Initialize Interrupt Status Block. (ISB) */
1853 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1855 tp->isb_ptr->IStatus[i].IType = 0xf0;
1856 tp->isb_ptr->IStatus[i].ISubtype = 0;
1859 tp->current_isb_index = 0;
1861 /* Initialize Action Command Block. (ACB) */
1862 smctr_init_acbs(dev);
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);
1869 /* Initialize receive FCB's and BDB's. */
1870 smctr_init_rx_bdbs(dev);
1871 smctr_init_rx_fcbs(dev);
1876 static int smctr_init_tx_bdbs(struct net_device *dev)
1878 struct net_local *tp = netdev_priv(dev);
1882 for(i = 0; i < NUM_TX_QS_USED; i++)
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);
1889 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1891 bdb->next_ptr->back_ptr = bdb;
1892 bdb = bdb->next_ptr;
1893 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1895 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
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;
1906 static int smctr_init_tx_fcbs(struct net_device *dev)
1908 struct net_local *tp = netdev_priv(dev);
1912 for(i = 0; i < NUM_TX_QS_USED; i++)
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);
1921 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
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;
1929 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1930 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1933 fcb->next_ptr = tp->tx_fcb_head[i];
1934 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
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;
1945 static int smctr_internal_self_test(struct net_device *dev)
1947 struct net_local *tp = netdev_priv(dev);
1950 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1953 if((err = smctr_wait_cmd(dev)))
1956 if(tp->acb_head->cmd_done_status & 0xff)
1959 if((err = smctr_issue_test_hic_cmd(dev)))
1962 if((err = smctr_wait_cmd(dev)))
1965 if(tp->acb_head->cmd_done_status & 0xff)
1968 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1971 if((err = smctr_wait_cmd(dev)))
1974 if(tp->acb_head->cmd_done_status & 0xff)
1981 * The typical workload of the driver: Handle the network interface interrupts.
1983 static irqreturn_t smctr_interrupt(int irq, void *dev_id)
1985 struct net_device *dev = dev_id;
1986 struct net_local *tp;
1988 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1989 __u16 err1, err = NOT_MY_INTERRUPT;
1990 __u8 isb_type, isb_subtype;
1993 ioaddr = dev->base_addr;
1994 tp = netdev_priv(dev);
1996 if(tp->status == NOT_INITIALIZED)
1999 spin_lock(&tp->lock);
2001 smctr_disable_bic_int(dev);
2002 smctr_enable_16bit(dev);
2004 smctr_clear_int(dev);
2006 /* First read the LSB */
2007 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2009 isb_index = tp->current_isb_index;
2010 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2011 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2013 (tp->current_isb_index)++;
2014 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2015 tp->current_isb_index = 0;
2017 if(isb_type >= 0x10)
2019 smctr_disable_16bit(dev);
2020 spin_unlock(&tp->lock);
2024 err = HARDWARE_FAILED;
2025 interrupt_ack_code = isb_index;
2026 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2028 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2032 case ISB_IMC_MAC_TYPE_3:
2033 smctr_disable_16bit(dev);
2038 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2042 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2046 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2050 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2053 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2057 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2061 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2065 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2068 case 8: /* diagnostic state */
2072 tp->monitor_state = MS_BEACON_TEST_STATE;
2073 if(smctr_lobe_media_test(dev))
2075 tp->ring_status_flags = RING_STATUS_CHANGED;
2076 tp->ring_status = AUTO_REMOVAL_ERROR;
2077 smctr_ring_status_chg(dev);
2078 smctr_bypass_state(dev);
2081 smctr_issue_insert_cmd(dev);
2084 /* case 0x0a-0xff, illegal states */
2089 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2090 err = smctr_ring_status_chg(dev);
2092 smctr_enable_16bit(dev);
2095 /* Type 0x02 - MAC Error Counters Interrupt
2096 * One or more MAC Error Counter is half full
2097 * MAC Error Counters
2098 * Lost_FR_Error_Counter
2099 * RCV_Congestion_Counter
2100 * FR_copied_Error_Counter
2101 * FREQ_Error_Counter
2102 * Token_Error_Counter
2103 * Line_Error_Counter
2104 * Internal_Error_Count
2106 case ISB_IMC_MAC_ERROR_COUNTERS:
2107 /* Read 802.5 Error Counters */
2108 err = smctr_issue_read_ring_status_cmd(dev);
2111 /* Type 0x04 - MAC Type 2 Interrupt
2112 * HOST needs to enqueue MAC Frame for transmission
2113 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2114 * TRC_Status_Changed_Indicate
2116 case ISB_IMC_MAC_TYPE_2:
2117 err = smctr_issue_read_ring_status_cmd(dev);
2121 /* Type 0x05 - TX Frame Interrupt (FI). */
2122 case ISB_IMC_TX_FRAME:
2123 /* BUG QUEUE for TRC stuck receive BUG */
2124 if(isb_subtype & TX_PENDING_PRIORITY_2)
2126 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2130 /* NON-MAC frames only */
2131 if(isb_subtype & TX_PENDING_PRIORITY_1)
2133 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2137 /* MAC frames only */
2138 if(isb_subtype & TX_PENDING_PRIORITY_0)
2139 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2141 /* Type 0x06 - TX END OF QUEUE (FE) */
2142 case ISB_IMC_END_OF_TX_QUEUE:
2144 if(isb_subtype & TX_PENDING_PRIORITY_2)
2146 /* ok to clear Receive FIFO overrun
2147 * imask send_BUG now completes.
2149 interrupt_unmask_bits |= 0x800;
2151 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2152 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2154 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2158 /* NON-MAC queue only */
2159 if(isb_subtype & TX_PENDING_PRIORITY_1)
2161 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2162 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2164 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2168 /* MAC queue only */
2169 if(isb_subtype & TX_PENDING_PRIORITY_0)
2171 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2172 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2175 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2179 /* Type 0x07 - NON-MAC RX Resource Interrupt
2180 * Subtype bit 12 - (BW) BDB warning
2181 * Subtype bit 13 - (FW) FCB warning
2182 * Subtype bit 14 - (BE) BDB End of chain
2183 * Subtype bit 15 - (FE) FCB End of chain
2185 case ISB_IMC_NON_MAC_RX_RESOURCE:
2186 tp->rx_fifo_overrun_count = 0;
2187 tp->receive_queue_number = NON_MAC_QUEUE;
2188 err1 = smctr_rx_frame(dev);
2190 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2192 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2194 if(tp->ptr_rx_fcb_overruns)
2195 (*tp->ptr_rx_fcb_overruns)++;
2198 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2200 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2202 if(tp->ptr_rx_bdb_overruns)
2203 (*tp->ptr_rx_bdb_overruns)++;
2208 /* Type 0x08 - MAC RX Resource Interrupt
2209 * Subtype bit 12 - (BW) BDB warning
2210 * Subtype bit 13 - (FW) FCB warning
2211 * Subtype bit 14 - (BE) BDB End of chain
2212 * Subtype bit 15 - (FE) FCB End of chain
2214 case ISB_IMC_MAC_RX_RESOURCE:
2215 tp->receive_queue_number = MAC_QUEUE;
2216 err1 = smctr_rx_frame(dev);
2218 if(isb_subtype & MAC_RX_RESOURCE_FE)
2220 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2223 if(tp->ptr_rx_fcb_overruns)
2224 (*tp->ptr_rx_fcb_overruns)++;
2227 if(isb_subtype & MAC_RX_RESOURCE_BE)
2229 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2232 if(tp->ptr_rx_bdb_overruns)
2233 (*tp->ptr_rx_bdb_overruns)++;
2238 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2239 case ISB_IMC_NON_MAC_RX_FRAME:
2240 tp->rx_fifo_overrun_count = 0;
2241 tp->receive_queue_number = NON_MAC_QUEUE;
2242 err = smctr_rx_frame(dev);
2245 /* Type 0x0A - MAC RX Frame Interrupt */
2246 case ISB_IMC_MAC_RX_FRAME:
2247 tp->receive_queue_number = MAC_QUEUE;
2248 err = smctr_rx_frame(dev);
2251 /* Type 0x0B - TRC status
2252 * TRC has encountered an error condition
2253 * subtype bit 14 - transmit FIFO underrun
2254 * subtype bit 15 - receive FIFO overrun
2256 case ISB_IMC_TRC_FIFO_STATUS:
2257 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2259 if(tp->ptr_tx_fifo_underruns)
2260 (*tp->ptr_tx_fifo_underruns)++;
2263 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2265 /* update overrun stuck receive counter
2266 * if >= 3, has to clear it by sending
2267 * back to back frames. We pick
2268 * DAT(duplicate address MAC frame)
2270 tp->rx_fifo_overrun_count++;
2272 if(tp->rx_fifo_overrun_count >= 3)
2274 tp->rx_fifo_overrun_count = 0;
2276 /* delay clearing fifo overrun
2277 * imask till send_BUG tx
2280 interrupt_unmask_bits &= (~0x800);
2281 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2284 if(tp->ptr_rx_fifo_overruns)
2285 (*tp->ptr_rx_fifo_overruns)++;
2291 /* Type 0x0C - Action Command Status Interrupt
2292 * Subtype bit 14 - CB end of command chain (CE)
2293 * Subtype bit 15 - CB command interrupt (CI)
2295 case ISB_IMC_COMMAND_STATUS:
2297 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2299 printk(KERN_ERR "i1\n");
2300 smctr_disable_16bit(dev);
2302 /* XXXXXXXXXXXXXXXXX */
2303 /* err = UM_Interrupt(dev); */
2305 smctr_enable_16bit(dev);
2309 if((tp->acb_head->cmd
2310 == ACB_CMD_READ_TRC_STATUS)
2311 && (tp->acb_head->subcmd
2312 == RW_TRC_STATUS_BLOCK))
2314 if(tp->ptr_bcn_type != 0)
2317 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2320 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2322 smctr_update_err_stats(dev);
2325 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2328 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2329 smctr_disable_16bit(dev);
2330 err = smctr_ring_status_chg(dev);
2331 smctr_enable_16bit(dev);
2332 if((tp->ring_status & REMOVE_RECEIVED)
2333 && (tp->config_word0 & NO_AUTOREMOVE))
2335 smctr_issue_remove_cmd(dev);
2340 tp->acb_pending = 0;
2345 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2349 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2350 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2351 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2356 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2357 err = smctr_send_rq_init(dev);
2362 tp->acb_pending = 0;
2365 /* Type 0x0D - MAC Type 1 interrupt
2366 * Subtype -- 00 FR_BCN received at S12
2367 * 01 FR_BCN received at S21
2368 * 02 FR_DAT(DA=MA, A<>0) received at S21
2370 * 04 FR_REMOVE received at S42
2371 * 05 TBR_EXP, BR_FLAG_SET at S42
2374 case ISB_IMC_MAC_TYPE_1:
2377 err = HARDWARE_FAILED;
2385 tp->join_state = JS_BYPASS_STATE;
2386 if(tp->status != CLOSED)
2388 tp->status = CLOSED;
2389 err = smctr_status_chg(dev);
2394 tp->join_state = JS_LOBE_TEST_STATE;
2398 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2402 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2406 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2410 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2414 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2418 tp->join_state = JS_JOIN_COMPLETE_STATE;
2420 err = smctr_status_chg(dev);
2424 tp->join_state = JS_BYPASS_WAIT_STATE;
2429 /* Type 0x0E - TRC Initialization Sequence Interrupt
2430 * Subtype -- 00-FF Initializatin sequence complete
2432 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2433 tp->status = INITIALIZED;
2434 smctr_disable_16bit(dev);
2435 err = smctr_status_chg(dev);
2436 smctr_enable_16bit(dev);
2439 /* other interrupt types, illegal */
2448 /* Checking the ack code instead of the unmask bits here is because :
2449 * while fixing the stuck receive, DAT frame are sent and mask off
2450 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2451 * but we still want to issue ack to ISB
2453 if(!(interrupt_ack_code & 0xff00))
2454 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2456 smctr_disable_16bit(dev);
2457 smctr_enable_bic_int(dev);
2458 spin_unlock(&tp->lock);
2463 static int smctr_issue_enable_int_cmd(struct net_device *dev,
2464 __u16 interrupt_enable_mask)
2466 struct net_local *tp = netdev_priv(dev);
2469 if((err = smctr_wait_while_cbusy(dev)))
2472 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2473 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2475 smctr_set_ctrl_attention(dev);
2480 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2482 struct net_local *tp = netdev_priv(dev);
2484 if(smctr_wait_while_cbusy(dev))
2487 tp->sclb_ptr->int_mask_control = ibits;
2488 tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0;
2489 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2491 smctr_set_ctrl_attention(dev);
2496 static int smctr_issue_init_timers_cmd(struct net_device *dev)
2498 struct net_local *tp = netdev_priv(dev);
2501 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2503 if((err = smctr_wait_while_cbusy(dev)))
2506 if((err = smctr_wait_cmd(dev)))
2509 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2510 tp->config_word1 = 0;
2512 if((tp->media_type == MEDIA_STP_16)
2513 || (tp->media_type == MEDIA_UTP_16)
2514 || (tp->media_type == MEDIA_STP_16_UTP_16))
2516 tp->config_word0 |= FREQ_16MB_BIT;
2519 if(tp->mode_bits & EARLY_TOKEN_REL)
2520 tp->config_word0 |= ETREN;
2522 if(tp->mode_bits & LOOPING_MODE_MASK)
2523 tp->config_word0 |= RX_OWN_BIT;
2525 tp->config_word0 &= ~RX_OWN_BIT;
2527 if(tp->receive_mask & PROMISCUOUS_MODE)
2528 tp->config_word0 |= PROMISCUOUS_BIT;
2530 tp->config_word0 &= ~PROMISCUOUS_BIT;
2532 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2533 tp->config_word0 |= SAVBAD_BIT;
2535 tp->config_word0 &= ~SAVBAD_BIT;
2537 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2538 tp->config_word0 |= RXATMAC;
2540 tp->config_word0 &= ~RXATMAC;
2542 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2543 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2545 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2547 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2548 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2551 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2552 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2554 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2557 if((tp->media_type == MEDIA_STP_16)
2558 || (tp->media_type == MEDIA_UTP_16)
2559 || (tp->media_type == MEDIA_STP_16_UTP_16))
2561 tp->config_word1 |= INTERFRAME_SPACING_16;
2564 tp->config_word1 |= INTERFRAME_SPACING_4;
2566 *pTimer_Struc++ = tp->config_word0;
2567 *pTimer_Struc++ = tp->config_word1;
2569 if((tp->media_type == MEDIA_STP_4)
2570 || (tp->media_type == MEDIA_UTP_4)
2571 || (tp->media_type == MEDIA_STP_4_UTP_4))
2573 *pTimer_Struc++ = 0x00FA; /* prescale */
2574 *pTimer_Struc++ = 0x2710; /* TPT_limit */
2575 *pTimer_Struc++ = 0x2710; /* TQP_limit */
2576 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2577 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2578 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2579 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2580 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2581 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2582 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2583 *pTimer_Struc++ = 0x1162; /* THT_limit */
2584 *pTimer_Struc++ = 0x07D0; /* TRR_limit */
2585 *pTimer_Struc++ = 0x1388; /* TVX_limit */
2586 *pTimer_Struc++ = 0x0000; /* reserved */
2590 *pTimer_Struc++ = 0x03E8; /* prescale */
2591 *pTimer_Struc++ = 0x9C40; /* TPT_limit */
2592 *pTimer_Struc++ = 0x9C40; /* TQP_limit */
2593 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2594 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2595 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2596 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2597 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2598 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2599 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2600 *pTimer_Struc++ = 0x4588; /* THT_limit */
2601 *pTimer_Struc++ = 0x1F40; /* TRR_limit */
2602 *pTimer_Struc++ = 0x4E20; /* TVX_limit */
2603 *pTimer_Struc++ = 0x0000; /* reserved */
2606 /* Set node address. */
2607 *pTimer_Struc++ = dev->dev_addr[0] << 8
2608 | (dev->dev_addr[1] & 0xFF);
2609 *pTimer_Struc++ = dev->dev_addr[2] << 8
2610 | (dev->dev_addr[3] & 0xFF);
2611 *pTimer_Struc++ = dev->dev_addr[4] << 8
2612 | (dev->dev_addr[5] & 0xFF);
2614 /* Set group address. */
2615 *pTimer_Struc++ = tp->group_address_0 << 8
2616 | tp->group_address_0 >> 8;
2617 *pTimer_Struc++ = tp->group_address[0] << 8
2618 | tp->group_address[0] >> 8;
2619 *pTimer_Struc++ = tp->group_address[1] << 8
2620 | tp->group_address[1] >> 8;
2622 /* Set functional address. */
2623 *pTimer_Struc++ = tp->functional_address_0 << 8
2624 | tp->functional_address_0 >> 8;
2625 *pTimer_Struc++ = tp->functional_address[0] << 8
2626 | tp->functional_address[0] >> 8;
2627 *pTimer_Struc++ = tp->functional_address[1] << 8
2628 | tp->functional_address[1] >> 8;
2630 /* Set Bit-Wise group address. */
2631 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2632 | tp->bitwise_group_address[0] >> 8;
2633 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2634 | tp->bitwise_group_address[1] >> 8;
2636 /* Set ring number address. */
2637 *pTimer_Struc++ = tp->source_ring_number;
2638 *pTimer_Struc++ = tp->target_ring_number;
2640 /* Physical drop number. */
2641 *pTimer_Struc++ = (unsigned short)0;
2642 *pTimer_Struc++ = (unsigned short)0;
2644 /* Product instance ID. */
2645 for(i = 0; i < 9; i++)
2646 *pTimer_Struc++ = (unsigned short)0;
2648 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2653 static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2655 struct net_local *tp = netdev_priv(dev);
2658 void **txrx_ptrs = (void *)tp->misc_command_data;
2660 if((err = smctr_wait_while_cbusy(dev)))
2663 if((err = smctr_wait_cmd(dev)))
2665 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2669 /* Initialize Transmit Queue Pointers that are used, to point to
2672 for(i = 0; i < NUM_TX_QS_USED; i++)
2673 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2675 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2676 for(; i < MAX_TX_QS; i++)
2677 *txrx_ptrs++ = (void *)0;
2679 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2680 * used, to point to a single FCB and a BDB chain of buffers.
2682 for(i = 0; i < NUM_RX_QS_USED; i++)
2684 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2685 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2688 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2689 for(; i < MAX_RX_QS; i++)
2691 *txrx_ptrs++ = (void *)0;
2692 *txrx_ptrs++ = (void *)0;
2695 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2700 static int smctr_issue_insert_cmd(struct net_device *dev)
2704 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2709 static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2713 if((err = smctr_wait_while_cbusy(dev)))
2716 if((err = smctr_wait_cmd(dev)))
2719 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2720 RW_TRC_STATUS_BLOCK);
2725 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2729 if((err = smctr_wait_while_cbusy(dev)))
2732 if((err = smctr_wait_cmd(dev)))
2735 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2741 static int smctr_issue_remove_cmd(struct net_device *dev)
2743 struct net_local *tp = netdev_priv(dev);
2746 if((err = smctr_wait_while_cbusy(dev)))
2749 tp->sclb_ptr->resume_control = 0;
2750 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2752 smctr_set_ctrl_attention(dev);
2757 static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2759 struct net_local *tp = netdev_priv(dev);
2762 if((err = smctr_wait_while_cbusy(dev)))
2765 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2766 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2768 tp->acb_pending = 1;
2770 smctr_set_ctrl_attention(dev);
2775 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2777 struct net_local *tp = netdev_priv(dev);
2780 if((err = smctr_wait_while_cbusy(dev)))
2783 if(queue == MAC_QUEUE)
2784 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2786 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2788 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2790 smctr_set_ctrl_attention(dev);
2795 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2797 struct net_local *tp = netdev_priv(dev);
2799 if(smctr_debug > 10)
2800 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2802 if(smctr_wait_while_cbusy(dev))
2805 if(queue == MAC_QUEUE)
2806 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2808 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2810 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2812 smctr_set_ctrl_attention(dev);
2817 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2819 struct net_local *tp = netdev_priv(dev);
2821 if(smctr_debug > 10)
2822 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2824 if(smctr_wait_while_cbusy(dev))
2827 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2828 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2830 smctr_set_ctrl_attention(dev);
2835 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2839 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2840 TRC_INTERNAL_ROM_TEST);
2845 static int smctr_issue_test_hic_cmd(struct net_device *dev)
2849 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2850 TRC_HOST_INTERFACE_REG_TEST);
2855 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2859 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2860 TRC_MAC_REGISTERS_TEST);
2865 static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2869 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2870 TRC_INTERNAL_LOOPBACK);
2875 static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2879 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2885 static int smctr_issue_write_byte_cmd(struct net_device *dev,
2886 short aword_cnt, void *byte)
2888 struct net_local *tp = netdev_priv(dev);
2889 unsigned int iword, ibyte;
2892 if((err = smctr_wait_while_cbusy(dev)))
2895 if((err = smctr_wait_cmd(dev)))
2898 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2899 iword++, ibyte += 2)
2901 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2902 | (*((__u8 *)byte + ibyte + 1));
2905 return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2909 static int smctr_issue_write_word_cmd(struct net_device *dev,
2910 short aword_cnt, void *word)
2912 struct net_local *tp = netdev_priv(dev);
2913 unsigned int i, err;
2915 if((err = smctr_wait_while_cbusy(dev)))
2918 if((err = smctr_wait_cmd(dev)))
2921 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2922 tp->misc_command_data[i] = *((__u16 *)word + i);
2924 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2930 static int smctr_join_complete_state(struct net_device *dev)
2934 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2935 JS_JOIN_COMPLETE_STATE);
2940 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2942 struct net_local *tp = netdev_priv(dev);
2947 for(i = 0; i < NUM_TX_QS_USED; i++)
2949 fcb = tp->tx_fcb_head[i];
2950 bdb = tp->tx_bdb_head[i];
2952 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2955 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2956 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2957 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2964 static int smctr_load_firmware(struct net_device *dev)
2966 struct net_local *tp = netdev_priv(dev);
2967 __u16 i, checksum = 0;
2970 if(smctr_debug > 10)
2971 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2973 tp->ptr_ucode = smctr_code;
2974 tp->num_of_tx_buffs = 4;
2975 tp->mode_bits |= UMAC;
2976 tp->receive_mask = 0;
2977 tp->max_packet_size = 4177;
2979 /* Can only upload the firmware once per adapter reset. */
2980 if(tp->microcode_version != 0)
2981 return (UCODE_PRESENT);
2983 /* Verify the firmware exists and is there in the right amount. */
2984 if((tp->ptr_ucode == 0L)
2985 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET) < UCODE_VERSION))
2987 return (UCODE_NOT_PRESENT);
2990 /* UCODE_SIZE is not included in Checksum. */
2991 for(i = 0; i < *((__u16 *)(tp->ptr_ucode + UCODE_SIZE_OFFSET)); i += 2)
2992 checksum += *((__u16 *)(tp->ptr_ucode + 2 + i));
2994 return (UCODE_NOT_PRESENT);
2996 /* At this point we have a valid firmware image, lets kick it on up. */
2997 smctr_enable_adapter_ram(dev);
2998 smctr_enable_16bit(dev);
2999 smctr_set_page(dev, (__u8 *)tp->ram_access);
3001 if((smctr_checksum_firmware(dev))
3002 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET)
3003 > tp->microcode_version))
3005 smctr_enable_adapter_ctrl_store(dev);
3007 /* Zero out ram space for firmware. */
3008 for(i = 0; i < CS_RAM_SIZE; i += 2)
3009 *((__u16 *)(tp->ram_access + i)) = 0;
3011 smctr_decode_firmware(dev);
3013 tp->microcode_version = *(tp->ptr_ucode + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
3014 = (tp->microcode_version << 8);
3015 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3016 = ~(tp->microcode_version << 8) + 1;
3018 smctr_disable_adapter_ctrl_store(dev);
3020 if(smctr_checksum_firmware(dev))
3021 err = HARDWARE_FAILED;
3024 err = UCODE_PRESENT;
3026 smctr_disable_16bit(dev);
3031 static int smctr_load_node_addr(struct net_device *dev)
3033 int ioaddr = dev->base_addr;
3037 for(i = 0; i < 6; i++)
3039 r = inb(ioaddr + LAR0 + i);
3040 dev->dev_addr[i] = (char)r;
3048 * During the transmission of the initial 1500 lobe media MAC frames,
3049 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3050 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3051 * microcode will not transmit any frames given to it by the host, and
3052 * will consequently cause a timeout.
3054 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
3055 * queues other then the one used for the lobe_media_test should be
3058 * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
3059 * has any multi-cast or promiscous bits set, the receive_mask needs to
3060 * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
3061 * run, and then the receive mask set back to its original value if the test
3064 static int smctr_lobe_media_test(struct net_device *dev)
3066 struct net_local *tp = netdev_priv(dev);
3067 unsigned int i, perror = 0;
3068 unsigned short saved_rcv_mask;
3070 if(smctr_debug > 10)
3071 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3073 /* Clear receive mask for lobe test. */
3074 saved_rcv_mask = tp->receive_mask;
3075 tp->receive_mask = 0;
3077 smctr_chg_rx_mask(dev);
3079 /* Setup the lobe media test. */
3080 smctr_lobe_media_test_cmd(dev);
3081 if(smctr_wait_cmd(dev))
3083 smctr_reset_adapter(dev);
3084 tp->status = CLOSED;
3085 return (LOBE_MEDIA_TEST_FAILED);
3088 /* Tx lobe media test frames. */
3089 for(i = 0; i < 1500; ++i)
3091 if(smctr_send_lobe_media_test(dev))
3095 smctr_reset_adapter(dev);
3097 return (LOBE_MEDIA_TEST_FAILED);
3102 if(smctr_lobe_media_test_cmd(dev))
3104 smctr_reset_adapter(dev);
3106 return (LOBE_MEDIA_TEST_FAILED);
3112 if(smctr_send_dat(dev))
3114 if(smctr_send_dat(dev))
3116 smctr_reset_adapter(dev);
3118 return (LOBE_MEDIA_TEST_FAILED);
3122 /* Check if any frames received during test. */
3123 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status)
3124 || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3126 smctr_reset_adapter(dev);
3128 return (LOBE_MEDIA_TEST_FAILED);
3131 /* Set receive mask to "Promisc" mode. */
3132 tp->receive_mask = saved_rcv_mask;
3134 smctr_chg_rx_mask(dev);
3139 static int smctr_lobe_media_test_cmd(struct net_device *dev)
3141 struct net_local *tp = netdev_priv(dev);
3144 if(smctr_debug > 10)
3145 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3147 /* Change to lobe media test state. */
3148 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3150 smctr_lobe_media_test_state(dev);
3151 if(smctr_wait_cmd(dev))
3153 printk(KERN_ERR "Lobe Failed test state\n");
3154 return (LOBE_MEDIA_TEST_FAILED);
3158 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3159 TRC_LOBE_MEDIA_TEST);
3164 static int smctr_lobe_media_test_state(struct net_device *dev)
3168 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3169 JS_LOBE_TEST_STATE);
3174 static int smctr_make_8025_hdr(struct net_device *dev,
3175 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3177 tmf->ac = MSB(ac_fc); /* msb is access control */
3178 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3180 tmf->sa[0] = dev->dev_addr[0];
3181 tmf->sa[1] = dev->dev_addr[1];
3182 tmf->sa[2] = dev->dev_addr[2];
3183 tmf->sa[3] = dev->dev_addr[3];
3184 tmf->sa[4] = dev->dev_addr[4];
3185 tmf->sa[5] = dev->dev_addr[5];
3189 /* Send RQ_INIT to RPS */
3199 /* Send RPT_TX_FORWARD to CRS */
3200 case RPT_TX_FORWARD:
3209 /* Everything else goes to sender */
3211 tmf->da[0] = rmf->sa[0];
3212 tmf->da[1] = rmf->sa[1];
3213 tmf->da[2] = rmf->sa[2];
3214 tmf->da[3] = rmf->sa[3];
3215 tmf->da[4] = rmf->sa[4];
3216 tmf->da[5] = rmf->sa[5];
3223 static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3225 struct net_local *tp = netdev_priv(dev);
3227 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3228 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3230 tsv->svv[0] = MSB(tp->authorized_access_priority);
3231 tsv->svv[1] = LSB(tp->authorized_access_priority);
3236 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3238 tsv->svi = ADDRESS_MODIFER;
3239 tsv->svl = S_ADDRESS_MODIFER;
3247 static int smctr_make_auth_funct_class(struct net_device *dev,
3248 MAC_SUB_VECTOR *tsv)
3250 struct net_local *tp = netdev_priv(dev);
3252 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3253 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3255 tsv->svv[0] = MSB(tp->authorized_function_classes);
3256 tsv->svv[1] = LSB(tp->authorized_function_classes);
3261 static int smctr_make_corr(struct net_device *dev,
3262 MAC_SUB_VECTOR *tsv, __u16 correlator)
3264 tsv->svi = CORRELATOR;
3265 tsv->svl = S_CORRELATOR;
3267 tsv->svv[0] = MSB(correlator);
3268 tsv->svv[1] = LSB(correlator);
3273 static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3275 struct net_local *tp = netdev_priv(dev);
3277 smctr_get_functional_address(dev);
3279 tsv->svi = FUNCTIONAL_ADDRESS;
3280 tsv->svl = S_FUNCTIONAL_ADDRESS;
3282 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3283 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3285 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3286 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3291 static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3293 struct net_local *tp = netdev_priv(dev);
3295 smctr_get_group_address(dev);
3297 tsv->svi = GROUP_ADDRESS;
3298 tsv->svl = S_GROUP_ADDRESS;
3300 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3301 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3303 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3304 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3306 /* Set Group Address Sub-vector to all zeros if only the
3307 * Group Address/Functional Address Indicator is set.
3309 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00
3310 && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3316 static int smctr_make_phy_drop_num(struct net_device *dev,
3317 MAC_SUB_VECTOR *tsv)
3319 struct net_local *tp = netdev_priv(dev);
3321 smctr_get_physical_drop_number(dev);
3323 tsv->svi = PHYSICAL_DROP;
3324 tsv->svl = S_PHYSICAL_DROP;
3326 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3327 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3329 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3330 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3335 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3339 tsv->svi = PRODUCT_INSTANCE_ID;
3340 tsv->svl = S_PRODUCT_INSTANCE_ID;
3342 for(i = 0; i < 18; i++)
3348 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3350 struct net_local *tp = netdev_priv(dev);
3352 smctr_get_station_id(dev);
3354 tsv->svi = STATION_IDENTIFER;
3355 tsv->svl = S_STATION_IDENTIFER;
3357 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3358 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3360 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3361 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3363 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3364 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3369 static int smctr_make_ring_station_status(struct net_device *dev,
3370 MAC_SUB_VECTOR * tsv)
3372 tsv->svi = RING_STATION_STATUS;
3373 tsv->svl = S_RING_STATION_STATUS;
3385 static int smctr_make_ring_station_version(struct net_device *dev,
3386 MAC_SUB_VECTOR *tsv)
3388 struct net_local *tp = netdev_priv(dev);
3390 tsv->svi = RING_STATION_VERSION_NUMBER;
3391 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3393 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3394 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3395 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3396 tsv->svv[3] = 0x40; /* EBCDIC - */
3397 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3398 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3399 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3400 tsv->svv[7] = 0x40; /* EBCDIC - */
3401 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3403 if(tp->extra_info & CHIP_REV_MASK)
3404 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3406 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3411 static int smctr_make_tx_status_code(struct net_device *dev,
3412 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3414 tsv->svi = TRANSMIT_STATUS_CODE;
3415 tsv->svl = S_TRANSMIT_STATUS_CODE;
3417 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) || IBM_PASS_SOURCE_ADDR);
3419 /* Stripped frame status of Transmitted Frame */
3420 tsv->svv[1] = tx_fstatus & 0xff;
3425 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3426 MAC_SUB_VECTOR *tsv)
3428 struct net_local *tp = netdev_priv(dev);
3430 smctr_get_upstream_neighbor_addr(dev);
3432 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3433 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3435 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3436 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3438 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3439 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3441 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3442 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3447 static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3449 tsv->svi = WRAP_DATA;
3450 tsv->svl = S_WRAP_DATA;
3456 * Open/initialize the board. This is called sometime after
3457 * booting when the 'ifconfig' program is run.
3459 * This routine should set everything up anew at each open, even
3460 * registers that "should" only need to be set once at boot, so that
3461 * there is non-reboot way to recover if something goes wrong.
3463 static int smctr_open(struct net_device *dev)
3467 if(smctr_debug > 10)
3468 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3470 err = smctr_init_adapter(dev);
3477 /* Interrupt driven open of Token card. */
3478 static int smctr_open_tr(struct net_device *dev)
3480 struct net_local *tp = netdev_priv(dev);
3481 unsigned long flags;
3484 if(smctr_debug > 10)
3485 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3487 /* Now we can actually open the adapter. */
3488 if(tp->status == OPEN)
3490 if(tp->status != INITIALIZED)
3493 /* FIXME: it would work a lot better if we masked the irq sources
3494 on the card here, then we could skip the locking and poll nicely */
3495 spin_lock_irqsave(&tp->lock, flags);
3497 smctr_set_page(dev, (__u8 *)tp->ram_access);
3499 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3502 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3505 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3508 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3511 tp->status = CLOSED;
3513 /* Insert into the Ring or Enter Loopback Mode. */
3514 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3516 tp->status = CLOSED;
3518 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3520 if(!(err = smctr_wait_cmd(dev)))
3524 smctr_status_chg(dev);
3528 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3530 tp->status = CLOSED;
3531 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3533 if(!(err = smctr_wait_cmd(dev)))
3537 smctr_status_chg(dev);
3541 if((tp->mode_bits & LOOPING_MODE_MASK)
3544 tp->status = CLOSED;
3545 if(!(err = smctr_lobe_media_test_cmd(dev)))
3547 if(!(err = smctr_wait_cmd(dev)))
3550 smctr_status_chg(dev);
3554 if(!(err = smctr_lobe_media_test(dev)))
3555 err = smctr_issue_insert_cmd(dev);
3558 if(err == LOBE_MEDIA_TEST_FAILED)
3559 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3566 spin_unlock_irqrestore(&tp->lock, flags);
3571 /* Check for a network adapter of this type,
3572 * and return device structure if one exists.
3574 struct net_device __init *smctr_probe(int unit)
3576 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3577 static const unsigned ports[] = {
3578 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3579 0x320, 0x340, 0x360, 0x380, 0
3581 const unsigned *port;
3585 return ERR_PTR(-ENOMEM);
3587 SET_MODULE_OWNER(dev);
3590 sprintf(dev->name, "tr%d", unit);
3591 netdev_boot_setup_check(dev);
3594 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3595 err = smctr_probe1(dev, dev->base_addr);
3596 else if(dev->base_addr != 0) /* Don't probe at all. */
3599 for (port = ports; *port; port++) {
3600 err = smctr_probe1(dev, *port);
3607 err = register_netdev(dev);
3612 #ifdef CONFIG_MCA_LEGACY
3613 { struct net_local *tp = netdev_priv(dev);
3615 mca_mark_as_unused(tp->slot_num);
3618 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3619 free_irq(dev->irq, dev);
3622 return ERR_PTR(err);
3626 static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3628 static unsigned version_printed;
3629 struct net_local *tp = netdev_priv(dev);
3633 if(smctr_debug && version_printed++ == 0)
3636 spin_lock_init(&tp->lock);
3637 dev->base_addr = ioaddr;
3639 /* Actually detect an adapter now. */
3640 err = smctr_chk_isa(dev);
3643 if ((err = smctr_chk_mca(dev)) < 0) {
3649 tp = netdev_priv(dev);
3650 dev->mem_start = tp->ram_base;
3651 dev->mem_end = dev->mem_start + 0x10000;
3652 ram = (__u32 *)phys_to_virt(dev->mem_start);
3653 tp->ram_access = *(__u32 *)&ram;
3654 tp->status = NOT_INITIALIZED;
3656 err = smctr_load_firmware(dev);
3657 if(err != UCODE_PRESENT && err != SUCCESS)
3659 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3664 /* Allow user to specify ring speed on module insert. */
3666 tp->media_type = MEDIA_UTP_4;
3668 tp->media_type = MEDIA_UTP_16;
3670 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3671 dev->name, smctr_name, smctr_model,
3672 (unsigned int)dev->base_addr,
3673 dev->irq, tp->rom_base, tp->ram_base);
3675 dev->open = smctr_open;
3676 dev->stop = smctr_close;
3677 dev->hard_start_xmit = smctr_send_packet;
3678 dev->tx_timeout = smctr_timeout;
3679 dev->watchdog_timeo = HZ;
3680 dev->get_stats = smctr_get_stats;
3681 dev->set_multicast_list = &smctr_set_multicast_list;
3688 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3689 struct net_device *dev, __u16 rx_status)
3691 struct net_local *tp = netdev_priv(dev);
3692 struct sk_buff *skb;
3693 __u16 rcode, correlator;
3698 rmf->vl = SWAP_BYTES(rmf->vl);
3699 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3703 /* Received MAC Frames Processed by RS. */
3705 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3710 if((err = smctr_send_rsp(dev, rmf, rcode,
3718 if((rcode = smctr_rcv_chg_param(dev, rmf,
3719 &correlator)) ==HARDWARE_FAILED)
3724 if((err = smctr_send_rsp(dev, rmf, rcode,
3732 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3733 rmf, &correlator)) != POSITIVE_ACK)
3735 if(rcode == HARDWARE_FAILED)
3738 return (smctr_send_rsp(dev, rmf,
3739 rcode, correlator));
3742 if((err = smctr_send_rpt_addr(dev, rmf,
3750 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3751 rmf, &correlator)) != POSITIVE_ACK)
3753 if(rcode == HARDWARE_FAILED)
3756 return (smctr_send_rsp(dev, rmf,
3761 if((err = smctr_send_rpt_attch(dev, rmf,
3769 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3770 rmf, &correlator)) != POSITIVE_ACK)
3772 if(rcode == HARDWARE_FAILED)
3775 return (smctr_send_rsp(dev, rmf,
3780 if((err = smctr_send_rpt_state(dev, rmf,
3788 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3791 if(rcode == HARDWARE_FAILED)
3794 return (smctr_send_rsp(dev, rmf,
3799 if((err = smctr_send_tx_forward(dev, rmf,
3800 &tx_fstatus)) == HARDWARE_FAILED)
3805 if(err == A_FRAME_WAS_FORWARDED)
3807 if((err = smctr_send_rpt_tx_forward(dev,
3816 /* Received MAC Frames Processed by CRS/REM/RPS. */
3821 case RPT_ACTIVE_ERR:
3829 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3832 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3834 rcode = smctr_rcv_unknown(dev, rmf,
3836 if((err = smctr_send_rsp(dev, rmf,rcode,
3848 /* 1. DA doesn't match (Promiscuous Mode).
3849 * 2. Parse for Extended MAC Frame Type.
3867 case RPT_ACTIVE_ERR:
3876 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3877 * ACCEPT_ATT_MAC_FRAMES is set.
3879 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
3880 && (xframe == (__u8)0))
3881 || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES)
3882 && (xframe == (__u8)1)))
3884 rmf->vl = SWAP_BYTES(rmf->vl);
3886 if (!(skb = dev_alloc_skb(size)))
3890 /* Slide data into a sleek skb. */
3891 skb_put(skb, skb->len);
3892 memcpy(skb->data, rmf, skb->len);
3894 /* Update Counters */
3895 tp->MacStat.rx_packets++;
3896 tp->MacStat.rx_bytes += skb->len;
3898 /* Kick the packet on up. */
3900 skb->protocol = tr_type_trans(skb, dev);
3902 dev->last_rx = jiffies;
3909 /* Adapter RAM test. Incremental word ODD boundary data test. */
3910 static int smctr_ram_memory_test(struct net_device *dev)
3912 struct net_local *tp = netdev_priv(dev);
3913 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3914 word_read = 0, err_word = 0, err_pattern = 0;
3915 unsigned int err_offset;
3919 if(smctr_debug > 10)
3920 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3922 start_pattern = 0x0001;
3923 pages_of_ram = tp->ram_size / tp->ram_usable;
3924 pword = tp->ram_access;
3926 /* Incremental word ODD boundary test. */
3927 for(page = 0; (page < pages_of_ram) && (~err);
3928 page++, start_pattern += 0x8000)
3930 smctr_set_page(dev, (__u8 *)(tp->ram_access
3931 + (page * tp->ram_usable * 1024) + 1));
3932 word_pattern = start_pattern;
3934 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3935 *(__u16 *)(pword + j) = word_pattern++;
3937 word_pattern = start_pattern;
3939 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1
3940 && (~err); j += 2, word_pattern++)
3942 word_read = *(__u16 *)(pword + j);
3943 if(word_read != word_pattern)
3947 err_word = word_read;
3948 err_pattern = word_pattern;
3949 return (RAM_TEST_FAILED);
3954 /* Zero out memory. */
3955 for(page = 0; page < pages_of_ram && (~err); page++)
3957 smctr_set_page(dev, (__u8 *)(tp->ram_access
3958 + (page * tp->ram_usable * 1024)));
3961 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3962 *(__u16 *)(pword + j) = word_pattern;
3964 for(j =0; j < (__u32)tp->ram_usable * 1024
3967 word_read = *(__u16 *)(pword + j);
3968 if(word_read != word_pattern)
3972 err_word = word_read;
3973 err_pattern = word_pattern;
3974 return (RAM_TEST_FAILED);
3979 smctr_set_page(dev, (__u8 *)tp->ram_access);
3984 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3987 MAC_SUB_VECTOR *rsv;
3989 __u16 rcode = POSITIVE_ACK;
3990 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
3992 /* This Frame can only come from a CRS */
3993 if((rmf->dc_sc & SC_MASK) != SC_CRS)
3994 return(E_INAPPROPRIATE_SOURCE_CLASS);
3996 /* Remove MVID Length from total length. */
3997 vlen = (signed short)rmf->vl - 4;
3999 /* Point to First SVID */
4000 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4002 /* Search for Appropriate SVID's. */
4003 while((vlen > 0) && (rcode == POSITIVE_ACK))
4008 svectors |= F_CORRELATOR;
4009 rcode = smctr_set_corr(dev, rsv, correlator);
4012 case LOCAL_RING_NUMBER:
4013 svectors |= F_LOCAL_RING_NUMBER;
4014 rcode = smctr_set_local_ring_num(dev, rsv);
4017 case ASSIGN_PHYSICAL_DROP:
4018 svectors |= F_ASSIGN_PHYSICAL_DROP;
4019 rcode = smctr_set_phy_drop(dev, rsv);
4022 case ERROR_TIMER_VALUE:
4023 svectors |= F_ERROR_TIMER_VALUE;
4024 rcode = smctr_set_error_timer_value(dev, rsv);
4027 case AUTHORIZED_FUNCTION_CLASS:
4028 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4029 rcode = smctr_set_auth_funct_class(dev, rsv);
4032 case AUTHORIZED_ACCESS_PRIORITY:
4033 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4034 rcode = smctr_set_auth_access_pri(dev, rsv);
4038 rcode = E_SUB_VECTOR_UNKNOWN;
4042 /* Let Sender Know if SUM of SV length's is
4043 * larger then length in MVID length field
4045 if((vlen -= rsv->svl) < 0)
4046 rcode = E_VECTOR_LENGTH_ERROR;
4048 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4051 if(rcode == POSITIVE_ACK)
4053 /* Let Sender Know if MVID length field
4054 * is larger then SUM of SV length's
4057 rcode = E_VECTOR_LENGTH_ERROR;
4060 /* Let Sender Know if Expected SVID Missing */
4061 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4062 rcode = E_MISSING_SUB_VECTOR;
4069 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4072 MAC_SUB_VECTOR *rsv;
4074 __u16 rcode = POSITIVE_ACK;
4075 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4077 /* This Frame can only come from a RPS */
4078 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4079 return (E_INAPPROPRIATE_SOURCE_CLASS);
4081 /* Remove MVID Length from total length. */
4082 vlen = (signed short)rmf->vl - 4;
4084 /* Point to First SVID */
4085 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4087 /* Search for Appropriate SVID's */
4088 while((vlen > 0) && (rcode == POSITIVE_ACK))
4093 svectors |= F_CORRELATOR;
4094 rcode = smctr_set_corr(dev, rsv, correlator);
4097 case LOCAL_RING_NUMBER:
4098 svectors |= F_LOCAL_RING_NUMBER;
4099 rcode = smctr_set_local_ring_num(dev, rsv);
4102 case ASSIGN_PHYSICAL_DROP:
4103 svectors |= F_ASSIGN_PHYSICAL_DROP;
4104 rcode = smctr_set_phy_drop(dev, rsv);
4107 case ERROR_TIMER_VALUE:
4108 svectors |= F_ERROR_TIMER_VALUE;
4109 rcode = smctr_set_error_timer_value(dev, rsv);
4113 rcode = E_SUB_VECTOR_UNKNOWN;
4117 /* Let Sender Know if SUM of SV length's is
4118 * larger then length in MVID length field
4120 if((vlen -= rsv->svl) < 0)
4121 rcode = E_VECTOR_LENGTH_ERROR;
4123 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4126 if(rcode == POSITIVE_ACK)
4128 /* Let Sender Know if MVID length field
4129 * is larger then SUM of SV length's
4132 rcode = E_VECTOR_LENGTH_ERROR;
4135 /* Let Sender Know if Expected SV Missing */
4136 if((svectors & R_INIT) ^ R_INIT)
4137 rcode = E_MISSING_SUB_VECTOR;
4144 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4146 MAC_SUB_VECTOR *rsv;
4148 __u16 rcode = POSITIVE_ACK;
4149 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4151 /* This Frame can only come from a CRS */
4152 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4153 return (E_INAPPROPRIATE_SOURCE_CLASS);
4155 /* Remove MVID Length from total length */
4156 vlen = (signed short)rmf->vl - 4;
4158 /* Point to First SVID */
4159 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4161 /* Search for Appropriate SVID's */
4162 while((vlen > 0) && (rcode == POSITIVE_ACK))
4167 svectors |= F_FRAME_FORWARD;
4168 rcode = smctr_set_frame_forward(dev, rsv,
4173 rcode = E_SUB_VECTOR_UNKNOWN;
4177 /* Let Sender Know if SUM of SV length's is
4178 * larger then length in MVID length field
4180 if((vlen -= rsv->svl) < 0)
4181 rcode = E_VECTOR_LENGTH_ERROR;
4183 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4186 if(rcode == POSITIVE_ACK)
4188 /* Let Sender Know if MVID length field
4189 * is larger then SUM of SV length's
4192 rcode = E_VECTOR_LENGTH_ERROR;
4195 /* Let Sender Know if Expected SV Missing */
4196 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4197 rcode = E_MISSING_SUB_VECTOR;
4204 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4205 MAC_HEADER *rmf, __u16 *correlator)
4207 MAC_SUB_VECTOR *rsv;
4209 __u16 rcode = POSITIVE_ACK;
4210 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4212 /* Remove MVID Length from total length */
4213 vlen = (signed short)rmf->vl - 4;
4215 /* Point to First SVID */
4216 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4218 /* Search for Appropriate SVID's */
4219 while((vlen > 0) && (rcode == POSITIVE_ACK))
4224 svectors |= F_CORRELATOR;
4225 rcode = smctr_set_corr(dev, rsv, correlator);
4229 rcode = E_SUB_VECTOR_UNKNOWN;
4233 /* Let Sender Know if SUM of SV length's is
4234 * larger then length in MVID length field
4236 if((vlen -= rsv->svl) < 0)
4237 rcode = E_VECTOR_LENGTH_ERROR;
4239 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4242 if(rcode == POSITIVE_ACK)
4244 /* Let Sender Know if MVID length field
4245 * is larger then SUM of SV length's
4248 rcode = E_VECTOR_LENGTH_ERROR;
4251 /* Let Sender Know if Expected SVID Missing */
4252 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4253 ^ R_RQ_ATTCH_STATE_ADDR)
4254 rcode = E_MISSING_SUB_VECTOR;
4261 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4264 MAC_SUB_VECTOR *rsv;
4269 /* Remove MVID Length from total length */
4270 vlen = (signed short)rmf->vl - 4;
4272 /* Point to First SVID */
4273 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4275 /* Search for CORRELATOR for RSP to UNKNOWN */
4276 while((vlen > 0) && (*correlator == 0))
4281 smctr_set_corr(dev, rsv, correlator);
4289 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4292 return (E_UNRECOGNIZED_VECTOR_ID);
4296 * Reset the 825 NIC and exit w:
4297 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4303 static int smctr_reset_adapter(struct net_device *dev)
4305 struct net_local *tp = netdev_priv(dev);
4306 int ioaddr = dev->base_addr;
4308 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4309 mdelay(200); /* ~2 ms */
4311 smctr_clear_trc_reset(ioaddr);
4312 mdelay(200); /* ~2 ms */
4314 /* Remove any latched interrupts that occurred prior to reseting the
4315 * adapter or possibily caused by line glitches due to the reset.
4317 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4322 static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4324 struct net_local *tp = netdev_priv(dev);
4327 if(smctr_debug > 10)
4328 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4330 if(tp->num_tx_fcbs_used[queue] != 0
4331 && tp->tx_queue_status[queue] == NOT_TRANSMITING)
4333 tp->tx_queue_status[queue] = TRANSMITING;
4334 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4340 static int smctr_ring_status_chg(struct net_device *dev)
4342 struct net_local *tp = netdev_priv(dev);
4344 if(smctr_debug > 10)
4345 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4347 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4348 * Bit is set, check value of monitor_state, only then we
4349 * enable and start transmit/receive timeout (if and only
4350 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4352 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4354 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE)
4355 || (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4357 tp->monitor_state_ready = 1;
4361 /* if adapter is NOT in either active monitor
4362 * or standby monitor state => Disable
4363 * transmit/receive timeout.
4365 tp->monitor_state_ready = 0;
4367 /* Ring speed problem, switching to auto mode. */
4368 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE
4371 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4373 smctr_set_ring_speed(dev);
4378 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4381 switch(tp->ring_status)
4384 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
4385 tp->current_ring_status |= RING_RECOVERY;
4388 case SINGLE_STATION:
4389 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
4390 tp->current_ring_status |= SINGLE_STATION;
4393 case COUNTER_OVERFLOW:
4394 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
4395 tp->current_ring_status |= COUNTER_OVERFLOW;
4398 case REMOVE_RECEIVED:
4399 printk(KERN_INFO "%s: Remove Received\n", dev->name);
4400 tp->current_ring_status |= REMOVE_RECEIVED;
4403 case AUTO_REMOVAL_ERROR:
4404 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
4405 tp->current_ring_status |= AUTO_REMOVAL_ERROR;
4408 case LOBE_WIRE_FAULT:
4409 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
4410 tp->current_ring_status |= LOBE_WIRE_FAULT;
4413 case TRANSMIT_BEACON:
4414 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
4415 tp->current_ring_status |= TRANSMIT_BEACON;
4419 printk(KERN_INFO "%s: Soft Error\n", dev->name);
4420 tp->current_ring_status |= SOFT_ERROR;
4424 printk(KERN_INFO "%s: Hard Error\n", dev->name);
4425 tp->current_ring_status |= HARD_ERROR;
4429 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
4430 tp->current_ring_status |= SIGNAL_LOSS;
4434 printk(KERN_INFO "%s: Unknown ring status change\n",
4442 static int smctr_rx_frame(struct net_device *dev)
4444 struct net_local *tp = netdev_priv(dev);
4445 __u16 queue, status, rx_size, err = 0;
4448 if(smctr_debug > 10)
4449 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4451 queue = tp->receive_queue_number;
4453 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4455 err = HARDWARE_FAILED;
4457 if(((status & 0x007f) == 0)
4458 || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4460 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4461 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4463 pbuff = smctr_get_rx_pointer(dev, queue);
4465 smctr_set_page(dev, pbuff);
4466 smctr_disable_16bit(dev);
4468 /* pbuff points to addr within one page */
4469 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4471 if(queue == NON_MAC_QUEUE)
4473 struct sk_buff *skb;
4475 skb = dev_alloc_skb(rx_size);
4477 skb_put(skb, rx_size);
4479 memcpy(skb->data, pbuff, rx_size);
4481 /* Update Counters */
4482 tp->MacStat.rx_packets++;
4483 tp->MacStat.rx_bytes += skb->len;
4485 /* Kick the packet on up. */
4487 skb->protocol = tr_type_trans(skb, dev);
4489 dev->last_rx = jiffies;
4494 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4495 rx_size, dev, status);
4498 smctr_enable_16bit(dev);
4499 smctr_set_page(dev, (__u8 *)tp->ram_access);
4500 smctr_update_rx_chain(dev, queue);
4509 static int smctr_send_dat(struct net_device *dev)
4511 struct net_local *tp = netdev_priv(dev);
4512 unsigned int i, err;
4516 if(smctr_debug > 10)
4517 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4519 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4520 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4522 return (OUT_OF_RESOURCES);
4525 /* Initialize DAT Data Fields. */
4526 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4527 tmf->ac = MSB(AC_FC_DAT);
4528 tmf->fc = LSB(AC_FC_DAT);
4530 for(i = 0; i < 6; i++)
4532 tmf->sa[i] = dev->dev_addr[i];
4533 tmf->da[i] = dev->dev_addr[i];
4538 tmf->dc_sc = DC_RS | SC_RS;
4540 tmf->vl = SWAP_BYTES(tmf->vl);
4542 /* Start Transmit. */
4543 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4546 /* Wait for Transmit to Complete */
4547 for(i = 0; i < 10000; i++)
4549 if(fcb->frame_status & FCB_COMMAND_DONE)
4554 /* Check if GOOD frame Tx'ed. */
4555 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4556 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4558 return (INITIALIZE_FAILED);
4561 /* De-allocated Tx FCB and Frame Buffer
4562 * The FCB must be de-allocated manually if executing with
4563 * interrupts disabled, other wise the ISR (LM_Service_Events)
4564 * will de-allocate it when the interrupt occurs.
4566 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4567 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4572 static void smctr_timeout(struct net_device *dev)
4575 * If we get here, some higher level has decided we are broken.
4576 * There should really be a "kick me" function call instead.
4578 * Resetting the token ring adapter takes a long time so just
4579 * fake transmission time and go on trying. Our own timeout
4580 * routine is in sktr_timer_chk()
4582 dev->trans_start = jiffies;
4583 netif_wake_queue(dev);
4587 * Gets skb from system, queues it and checks if it can be sent
4589 static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
4591 struct net_local *tp = netdev_priv(dev);
4593 if(smctr_debug > 10)
4594 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4597 * Block a transmit overlap
4600 netif_stop_queue(dev);
4602 if(tp->QueueSkb == 0)
4603 return (1); /* Return with tbusy set: queue full */
4606 skb_queue_tail(&tp->SendSkbQueue, skb);
4607 smctr_hardware_send_packet(dev, tp);
4608 if(tp->QueueSkb > 0)
4609 netif_wake_queue(dev);
4614 static int smctr_send_lobe_media_test(struct net_device *dev)
4616 struct net_local *tp = netdev_priv(dev);
4617 MAC_SUB_VECTOR *tsv;
4623 if(smctr_debug > 15)
4624 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4626 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4627 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4629 return (OUT_OF_RESOURCES);
4632 /* Initialize DAT Data Fields. */
4633 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4634 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4635 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4637 for(i = 0; i < 6; i++)
4640 tmf->sa[i] = dev->dev_addr[i];
4643 tmf->vc = LOBE_MEDIA_TEST;
4644 tmf->dc_sc = DC_RS | SC_RS;
4647 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4648 smctr_make_wrap_data(dev, tsv);
4649 tmf->vl += tsv->svl;
4651 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4652 smctr_make_wrap_data(dev, tsv);
4653 tmf->vl += tsv->svl;
4655 /* Start Transmit. */
4656 tmf->vl = SWAP_BYTES(tmf->vl);
4657 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4660 /* Wait for Transmit to Complete. (10 ms). */
4661 for(i=0; i < 10000; i++)
4663 if(fcb->frame_status & FCB_COMMAND_DONE)
4668 /* Check if GOOD frame Tx'ed */
4669 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4670 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4672 return (LOBE_MEDIA_TEST_FAILED);
4675 /* De-allocated Tx FCB and Frame Buffer
4676 * The FCB must be de-allocated manually if executing with
4677 * interrupts disabled, other wise the ISR (LM_Service_Events)
4678 * will de-allocate it when the interrupt occurs.
4680 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4681 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4686 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4690 MAC_SUB_VECTOR *tsv;
4693 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4694 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4695 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4696 == (FCBlock *)(-1L))
4701 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4703 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4706 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4708 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4709 smctr_make_corr(dev, tsv, correlator);
4711 tmf->vl += tsv->svl;
4712 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4713 smctr_make_phy_drop_num(dev, tsv);
4715 tmf->vl += tsv->svl;
4716 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4717 smctr_make_upstream_neighbor_addr(dev, tsv);
4719 tmf->vl += tsv->svl;
4720 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4721 smctr_make_addr_mod(dev, tsv);
4723 tmf->vl += tsv->svl;
4724 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4725 smctr_make_group_addr(dev, tsv);
4727 tmf->vl += tsv->svl;
4728 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4729 smctr_make_funct_addr(dev, tsv);
4731 tmf->vl += tsv->svl;
4733 /* Subtract out MVID and MVL which is
4734 * include in both vl and MAC_HEADER
4736 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4737 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4739 tmf->vl = SWAP_BYTES(tmf->vl);
4741 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4744 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4748 MAC_SUB_VECTOR *tsv;
4751 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4752 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4753 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4754 == (FCBlock *)(-1L))
4759 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4760 tmf->vc = RPT_ATTCH;
4761 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4764 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4766 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4767 smctr_make_corr(dev, tsv, correlator);
4769 tmf->vl += tsv->svl;
4770 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4771 smctr_make_product_id(dev, tsv);
4773 tmf->vl += tsv->svl;
4774 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4775 smctr_make_funct_addr(dev, tsv);
4777 tmf->vl += tsv->svl;
4778 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4779 smctr_make_auth_funct_class(dev, tsv);
4781 tmf->vl += tsv->svl;
4782 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4783 smctr_make_access_pri(dev, tsv);
4785 tmf->vl += tsv->svl;
4787 /* Subtract out MVID and MVL which is
4788 * include in both vl and MAC_HEADER
4790 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4791 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4793 tmf->vl = SWAP_BYTES(tmf->vl);
4795 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4798 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4802 MAC_SUB_VECTOR *tsv;
4805 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4806 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4807 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4808 == (FCBlock *)(-1L))
4813 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4814 tmf->vc = RPT_STATE;
4815 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4818 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4820 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4821 smctr_make_corr(dev, tsv, correlator);
4823 tmf->vl += tsv->svl;
4824 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4825 smctr_make_ring_station_version(dev, tsv);
4827 tmf->vl += tsv->svl;
4828 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4829 smctr_make_ring_station_status(dev, tsv);
4831 tmf->vl += tsv->svl;
4832 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4833 smctr_make_station_id(dev, tsv);
4835 tmf->vl += tsv->svl;
4837 /* Subtract out MVID and MVL which is
4838 * include in both vl and MAC_HEADER
4840 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4841 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4843 tmf->vl = SWAP_BYTES(tmf->vl);
4845 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4848 static int smctr_send_rpt_tx_forward(struct net_device *dev,
4849 MAC_HEADER *rmf, __u16 tx_fstatus)
4852 MAC_SUB_VECTOR *tsv;
4855 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4856 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4861 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4862 tmf->vc = RPT_TX_FORWARD;
4863 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4866 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4868 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4869 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4871 tmf->vl += tsv->svl;
4873 /* Subtract out MVID and MVL which is
4874 * include in both vl and MAC_HEADER
4876 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4877 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4879 tmf->vl = SWAP_BYTES(tmf->vl);
4881 return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4884 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4885 __u16 rcode, __u16 correlator)
4888 MAC_SUB_VECTOR *tsv;
4891 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4892 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4897 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4899 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4902 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4904 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4905 smctr_make_corr(dev, tsv, correlator);
4910 static int smctr_send_rq_init(struct net_device *dev)
4912 struct net_local *tp = netdev_priv(dev);
4914 MAC_SUB_VECTOR *tsv;
4916 unsigned int i, count = 0;
4921 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4922 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4923 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4924 == (FCBlock *)(-1L)))
4929 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4931 tmf->dc_sc = DC_RPS | SC_RS;
4934 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4936 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4937 smctr_make_product_id(dev, tsv);
4939 tmf->vl += tsv->svl;
4940 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4941 smctr_make_upstream_neighbor_addr(dev, tsv);
4943 tmf->vl += tsv->svl;
4944 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4945 smctr_make_ring_station_version(dev, tsv);
4947 tmf->vl += tsv->svl;
4948 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4949 smctr_make_addr_mod(dev, tsv);
4951 tmf->vl += tsv->svl;
4953 /* Subtract out MVID and MVL which is
4954 * include in both vl and MAC_HEADER
4956 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4957 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4959 tmf->vl = SWAP_BYTES(tmf->vl);
4961 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4964 /* Wait for Transmit to Complete */
4965 for(i = 0; i < 10000; i++)
4967 if(fcb->frame_status & FCB_COMMAND_DONE)
4972 /* Check if GOOD frame Tx'ed */
4973 fstatus = fcb->frame_status;
4975 if(!(fstatus & FCB_COMMAND_DONE))
4976 return (HARDWARE_FAILED);
4978 if(!(fstatus & FCB_TX_STATUS_E))
4981 /* De-allocated Tx FCB and Frame Buffer
4982 * The FCB must be de-allocated manually if executing with
4983 * interrupts disabled, other wise the ISR (LM_Service_Events)
4984 * will de-allocate it when the interrupt occurs.
4986 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4987 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4988 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4990 return (smctr_join_complete_state(dev));
4993 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4996 struct net_local *tp = netdev_priv(dev);
5001 /* Check if this is the END POINT of the Transmit Forward Chain. */
5005 /* Allocate Transmit FCB only by requesting 0 bytes
5008 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
5011 /* Set pointer to Transmit Frame Buffer to the data
5012 * portion of the received TX Forward frame, making
5013 * sure to skip over the Vector Code (vc) and Vector
5016 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5017 + sizeof(MAC_HEADER) + 2);
5018 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5019 + sizeof(MAC_HEADER) + 2);
5021 fcb->frame_length = rmf->vl - 4 - 2;
5022 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5024 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5027 /* Wait for Transmit to Complete */
5028 for(i = 0; i < 10000; i++)
5030 if(fcb->frame_status & FCB_COMMAND_DONE)
5035 /* Check if GOOD frame Tx'ed */
5036 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5038 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5041 for(i = 0; i < 10000; i++)
5043 if(fcb->frame_status & FCB_COMMAND_DONE)
5048 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5049 return (HARDWARE_FAILED);
5052 *tx_fstatus = fcb->frame_status;
5054 return (A_FRAME_WAS_FORWARDED);
5057 static int smctr_set_auth_access_pri(struct net_device *dev,
5058 MAC_SUB_VECTOR *rsv)
5060 struct net_local *tp = netdev_priv(dev);
5062 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5063 return (E_SUB_VECTOR_LENGTH_ERROR);
5065 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5067 return (POSITIVE_ACK);
5070 static int smctr_set_auth_funct_class(struct net_device *dev,
5071 MAC_SUB_VECTOR *rsv)
5073 struct net_local *tp = netdev_priv(dev);
5075 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5076 return (E_SUB_VECTOR_LENGTH_ERROR);
5078 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5080 return (POSITIVE_ACK);
5083 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5086 if(rsv->svl != S_CORRELATOR)
5087 return (E_SUB_VECTOR_LENGTH_ERROR);
5089 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5091 return (POSITIVE_ACK);
5094 static int smctr_set_error_timer_value(struct net_device *dev,
5095 MAC_SUB_VECTOR *rsv)
5100 if(rsv->svl != S_ERROR_TIMER_VALUE)
5101 return (E_SUB_VECTOR_LENGTH_ERROR);
5103 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5105 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5107 if((err = smctr_wait_cmd(dev)))
5110 return (POSITIVE_ACK);
5113 static int smctr_set_frame_forward(struct net_device *dev,
5114 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5116 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5117 return (E_SUB_VECTOR_LENGTH_ERROR);
5119 if((dc_sc & DC_MASK) != DC_CRS)
5121 if(rsv->svl >= 2 && rsv->svl < 20)
5122 return (E_TRANSMIT_FORWARD_INVALID);
5124 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5125 return (E_TRANSMIT_FORWARD_INVALID);
5128 return (POSITIVE_ACK);
5131 static int smctr_set_local_ring_num(struct net_device *dev,
5132 MAC_SUB_VECTOR *rsv)
5134 struct net_local *tp = netdev_priv(dev);
5136 if(rsv->svl != S_LOCAL_RING_NUMBER)
5137 return (E_SUB_VECTOR_LENGTH_ERROR);
5139 if(tp->ptr_local_ring_num)
5140 *(__u16 *)(tp->ptr_local_ring_num)
5141 = (rsv->svv[0] << 8 | rsv->svv[1]);
5143 return (POSITIVE_ACK);
5146 static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5148 struct net_local *tp = netdev_priv(dev);
5149 int ioaddr = dev->base_addr;
5151 if(tp->bic_type == BIC_585_CHIP)
5152 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5155 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5156 outb(tp->trc_mask, ioaddr + CSR);
5162 static void smctr_set_multicast_list(struct net_device *dev)
5164 if(smctr_debug > 10)
5165 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5170 static int smctr_set_page(struct net_device *dev, __u8 *buf)
5172 struct net_local *tp = netdev_priv(dev);
5176 tptr = (__u32)buf - (__u32)tp->ram_access;
5177 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5178 outb(amask, dev->base_addr + PR);
5183 static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5187 if(rsv->svl != S_PHYSICAL_DROP)
5188 return (E_SUB_VECTOR_LENGTH_ERROR);
5190 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5191 if((err = smctr_wait_cmd(dev)))
5194 return (POSITIVE_ACK);
5197 /* Reset the ring speed to the opposite of what it was. This auto-pilot
5198 * mode requires a complete reset and re-init of the adapter.
5200 static int smctr_set_ring_speed(struct net_device *dev)
5202 struct net_local *tp = netdev_priv(dev);
5205 if(tp->media_type == MEDIA_UTP_16)
5206 tp->media_type = MEDIA_UTP_4;
5208 tp->media_type = MEDIA_UTP_16;
5210 smctr_enable_16bit(dev);
5212 /* Re-Initialize adapter's internal registers */
5213 smctr_reset_adapter(dev);
5215 if((err = smctr_init_card_real(dev)))
5218 smctr_enable_bic_int(dev);
5220 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5223 smctr_disable_16bit(dev);
5228 static int smctr_set_rx_look_ahead(struct net_device *dev)
5230 struct net_local *tp = netdev_priv(dev);
5233 if(smctr_debug > 10)
5234 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5236 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5237 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5239 if(tp->adapter_bus == BUS_ISA16_TYPE)
5241 sword = *((__u16 *)(tp->ram_access));
5242 *((__u16 *)(tp->ram_access)) = 0x1234;
5244 smctr_disable_16bit(dev);
5245 rword = *((__u16 *)(tp->ram_access));
5246 smctr_enable_16bit(dev);
5249 tp->adapter_flags |= FORCED_16BIT_MODE;
5251 *((__u16 *)(tp->ram_access)) = sword;
5257 static int smctr_set_trc_reset(int ioaddr)
5261 r = inb(ioaddr + MSR);
5262 outb(MSR_RST | r, ioaddr + MSR);
5268 * This function can be called if the adapter is busy or not.
5270 static int smctr_setup_single_cmd(struct net_device *dev,
5271 __u16 command, __u16 subcommand)
5273 struct net_local *tp = netdev_priv(dev);
5276 if(smctr_debug > 10)
5277 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5279 if((err = smctr_wait_while_cbusy(dev)))
5282 if((err = (unsigned int)smctr_wait_cmd(dev)))
5285 tp->acb_head->cmd_done_status = 0;
5286 tp->acb_head->cmd = command;
5287 tp->acb_head->subcmd = subcommand;
5289 err = smctr_issue_resume_acb_cmd(dev);
5295 * This function can not be called with the adapter busy.
5297 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5298 __u16 command, __u16 subcommand)
5300 struct net_local *tp = netdev_priv(dev);
5302 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5303 tp->acb_head->cmd = command;
5304 tp->acb_head->subcmd = subcommand;
5305 tp->acb_head->data_offset_lo
5306 = (__u16)TRC_POINTER(tp->misc_command_data);
5308 return(smctr_issue_resume_acb_cmd(dev));
5311 static char *smctr_malloc(struct net_device *dev, __u16 size)
5313 struct net_local *tp = netdev_priv(dev);
5316 m = (char *)(tp->ram_access + tp->sh_mem_used);
5317 tp->sh_mem_used += (__u32)size;
5322 static int smctr_status_chg(struct net_device *dev)
5324 struct net_local *tp = netdev_priv(dev);
5326 if(smctr_debug > 10)
5327 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5337 /* Interrupt driven open() completion. XXX */
5339 tp->group_address_0 = 0;
5340 tp->group_address[0] = 0;
5341 tp->group_address[1] = 0;
5342 tp->functional_address_0 = 0;
5343 tp->functional_address[0] = 0;
5344 tp->functional_address[1] = 0;
5349 printk(KERN_INFO "%s: status change unknown %x\n",
5350 dev->name, tp->status);
5357 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5360 struct net_local *tp = netdev_priv(dev);
5363 if(smctr_debug > 10)
5364 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5366 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5367 if(tp->num_tx_fcbs[queue] != 1)
5368 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5370 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5372 tp->tx_queue_status[queue] = TRANSMITING;
5373 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5379 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5381 struct net_local *tp = netdev_priv(dev);
5382 __u16 status, err = 0;
5385 if(smctr_debug > 10)
5386 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5388 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5390 if(status & 0x7e00 )
5392 err = HARDWARE_FAILED;
5396 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5400 smctr_disable_16bit(dev);
5402 if(tp->mode_bits & UMAC)
5404 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5405 cstatus = NO_SUCH_DESTINATION;
5408 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5409 cstatus = DEST_OUT_OF_RESOURCES;
5412 if(status & FCB_TX_STATUS_E)
5413 cstatus = MAX_COLLISIONS;
5422 if(queue == BUG_QUEUE)
5425 smctr_enable_16bit(dev);
5433 static unsigned short smctr_tx_move_frame(struct net_device *dev,
5434 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5436 struct net_local *tp = netdev_priv(dev);
5437 unsigned int ram_usable;
5438 __u32 flen, len, offset = 0;
5441 if(smctr_debug > 10)
5442 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5444 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5448 while(flen > 0 && bytes > 0)
5450 smctr_set_page(dev, pbuff);
5452 offset = SMC_PAGE_OFFSET(pbuff);
5454 if(offset + flen > ram_usable)
5455 len = ram_usable - offset;
5462 page = (char *) (offset + tp->ram_access);
5463 memcpy(page, frag, len);
5474 /* Update the error statistic counters for this adapter. */
5475 static int smctr_update_err_stats(struct net_device *dev)
5477 struct net_local *tp = netdev_priv(dev);
5478 struct tr_statistics *tstat = &tp->MacStat;
5480 if(tstat->internal_errors)
5481 tstat->internal_errors
5482 += *(tp->misc_command_data + 0) & 0x00ff;
5484 if(tstat->line_errors)
5485 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5487 if(tstat->A_C_errors)
5488 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5490 if(tstat->burst_errors)
5491 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5493 if(tstat->abort_delimiters)
5494 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5496 if(tstat->recv_congest_count)
5497 tstat->recv_congest_count
5498 += *(tp->misc_command_data + 3) & 0x00ff;
5500 if(tstat->lost_frames)
5502 += *(tp->misc_command_data + 3) >> 8;
5504 if(tstat->frequency_errors)
5505 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5507 if(tstat->frame_copied_errors)
5508 tstat->frame_copied_errors
5509 += *(tp->misc_command_data + 4) >> 8;
5511 if(tstat->token_errors)
5512 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5517 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5519 struct net_local *tp = netdev_priv(dev);
5524 fcb = tp->rx_fcb_curr[queue];
5525 len = fcb->frame_length;
5527 fcb->frame_status = 0;
5528 fcb->info = FCB_CHAIN_END;
5529 fcb->back_ptr->info = FCB_WARNING;
5531 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5533 /* update RX BDBs */
5534 size = (len >> RX_BDB_SIZE_SHIFT);
5535 if(len & RX_DATA_BUFFER_SIZE_MASK)
5536 size += sizeof(BDBlock);
5537 size &= (~RX_BDB_SIZE_MASK);
5539 /* check if wrap around */
5540 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5541 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5543 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5544 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5547 bdb->back_ptr->info = BDB_CHAIN_END;
5548 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5549 tp->rx_bdb_curr[queue] = bdb;
5554 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5557 struct net_local *tp = netdev_priv(dev);
5559 if(smctr_debug > 20)
5560 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5562 if(tp->num_tx_fcbs_used[queue] <= 0)
5563 return (HARDWARE_FAILED);
5566 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5568 tp->tx_buff_used[queue] = 0;
5569 return (HARDWARE_FAILED);
5572 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5574 /* if all transmit buffer are cleared
5575 * need to set the tx_buff_curr[] to tx_buff_head[]
5576 * otherwise, tx buffer will be segregate and cannot
5577 * accommodate and buffer greater than (curr - head) and
5578 * (end - curr) since we do not allow wrap around allocation.
5580 if(tp->tx_buff_used[queue] == 0)
5581 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5583 tp->num_tx_fcbs_used[queue]--;
5584 fcb->frame_status = 0;
5585 tp->tx_fcb_end[queue] = fcb->next_ptr;
5586 netif_wake_queue(dev);
5591 static int smctr_wait_cmd(struct net_device *dev)
5593 struct net_local *tp = netdev_priv(dev);
5594 unsigned int loop_count = 0x20000;
5596 if(smctr_debug > 10)
5597 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5601 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5608 return(HARDWARE_FAILED);
5610 if(tp->acb_head->cmd_done_status & 0xff)
5611 return(HARDWARE_FAILED);
5616 static int smctr_wait_while_cbusy(struct net_device *dev)
5618 struct net_local *tp = netdev_priv(dev);
5619 unsigned int timeout = 0x20000;
5620 int ioaddr = dev->base_addr;
5623 if(tp->bic_type == BIC_585_CHIP)
5627 r = inb(ioaddr + HWR);
5628 if((r & HWR_CBUSY) == 0)
5637 r = inb(ioaddr + CSR);
5638 if((r & CSR_CBUSY) == 0)
5647 return (HARDWARE_FAILED);
5652 static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5653 static int io[SMCTR_MAX_ADAPTERS];
5654 static int irq[SMCTR_MAX_ADAPTERS];
5656 MODULE_LICENSE("GPL");
5658 module_param_array(io, int, NULL, 0);
5659 module_param_array(irq, int, NULL, 0);
5660 module_param(ringspeed, int, 0);
5662 static struct net_device * __init setup_card(int n)
5664 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5668 return ERR_PTR(-ENOMEM);
5671 err = smctr_probe1(dev, io[n]);
5675 err = register_netdev(dev);
5680 #ifdef CONFIG_MCA_LEGACY
5681 { struct net_local *tp = netdev_priv(dev);
5683 mca_mark_as_unused(tp->slot_num);
5686 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5687 free_irq(dev->irq, dev);
5690 return ERR_PTR(err);
5693 int __init init_module(void)
5696 struct net_device *dev;
5698 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5699 dev = io[0]? setup_card(i) : smctr_probe(-1);
5706 return found ? 0 : -ENODEV;
5709 void __exit cleanup_module(void)
5713 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5714 struct net_device *dev = dev_smctr[i];
5718 unregister_netdev(dev);
5719 #ifdef CONFIG_MCA_LEGACY
5720 { struct net_local *tp = netdev_priv(dev);
5722 mca_mark_as_unused(tp->slot_num);
5725 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5727 free_irq(dev->irq, dev);