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/config.h>
33 #include <linux/kernel.h>
34 #include <linux/types.h>
35 #include <linux/fcntl.h>
36 #include <linux/interrupt.h>
37 #include <linux/ptrace.h>
38 #include <linux/ioport.h>
40 #include <linux/slab.h>
41 #include <linux/string.h>
42 #include <linux/time.h>
43 #include <linux/errno.h>
44 #include <linux/init.h>
45 #include <linux/pci.h>
46 #include <linux/mca-legacy.h>
47 #include <linux/delay.h>
48 #include <linux/netdevice.h>
49 #include <linux/etherdevice.h>
50 #include <linux/skbuff.h>
51 #include <linux/trdevice.h>
52 #include <linux/bitops.h>
54 #include <asm/system.h>
59 #if BITS_PER_LONG == 64
60 #error FIXME: driver does not support 64-bit platforms
63 #include "smctr.h" /* Our Stuff */
64 #include "smctr_firmware.h" /* SMC adapter firmware */
66 static char version[] __initdata = KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
67 static const char cardname[] = "smctr";
70 #define SMCTR_IO_EXTENT 20
72 #ifdef CONFIG_MCA_LEGACY
73 static unsigned int smctr_posid = 0x6ec6;
78 /* SMC Name of the Adapter. */
79 static char smctr_name[] = "SMC TokenCard";
80 static char *smctr_model = "Unknown";
82 /* Use 0 for production, 1 for verification, 2 for debug, and
83 * 3 for very verbose debug.
88 static unsigned int smctr_debug = SMCTR_DEBUG;
90 /* smctr.c prototypes and functions are arranged alphabeticly
91 * for clearity, maintainability and pure old fashion fun.
94 static int smctr_alloc_shared_memory(struct net_device *dev);
97 static int smctr_bypass_state(struct net_device *dev);
100 static int smctr_checksum_firmware(struct net_device *dev);
101 static int __init smctr_chk_isa(struct net_device *dev);
102 static int smctr_chg_rx_mask(struct net_device *dev);
103 static int smctr_clear_int(struct net_device *dev);
104 static int smctr_clear_trc_reset(int ioaddr);
105 static int smctr_close(struct net_device *dev);
108 static int smctr_decode_firmware(struct net_device *dev);
109 static int smctr_disable_16bit(struct net_device *dev);
110 static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
111 static int smctr_disable_bic_int(struct net_device *dev);
114 static int smctr_enable_16bit(struct net_device *dev);
115 static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
116 static int smctr_enable_adapter_ram(struct net_device *dev);
117 static int smctr_enable_bic_int(struct net_device *dev);
120 static int __init smctr_get_boardid(struct net_device *dev, int mca);
121 static int smctr_get_group_address(struct net_device *dev);
122 static int smctr_get_functional_address(struct net_device *dev);
123 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
124 static int smctr_get_physical_drop_number(struct net_device *dev);
125 static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
126 static int smctr_get_station_id(struct net_device *dev);
127 static struct net_device_stats *smctr_get_stats(struct net_device *dev);
128 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
130 static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
133 static int smctr_hardware_send_packet(struct net_device *dev,
134 struct net_local *tp);
136 static int smctr_init_acbs(struct net_device *dev);
137 static int smctr_init_adapter(struct net_device *dev);
138 static int smctr_init_card_real(struct net_device *dev);
139 static int smctr_init_rx_bdbs(struct net_device *dev);
140 static int smctr_init_rx_fcbs(struct net_device *dev);
141 static int smctr_init_shared_memory(struct net_device *dev);
142 static int smctr_init_tx_bdbs(struct net_device *dev);
143 static int smctr_init_tx_fcbs(struct net_device *dev);
144 static int smctr_internal_self_test(struct net_device *dev);
145 static irqreturn_t smctr_interrupt(int irq, void *dev_id, struct pt_regs *regs);
146 static int smctr_issue_enable_int_cmd(struct net_device *dev,
147 __u16 interrupt_enable_mask);
148 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
150 static int smctr_issue_init_timers_cmd(struct net_device *dev);
151 static int smctr_issue_init_txrx_cmd(struct net_device *dev);
152 static int smctr_issue_insert_cmd(struct net_device *dev);
153 static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
154 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
155 static int smctr_issue_remove_cmd(struct net_device *dev);
156 static int smctr_issue_resume_acb_cmd(struct net_device *dev);
157 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
158 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
159 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
160 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
161 static int smctr_issue_test_hic_cmd(struct net_device *dev);
162 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
163 static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
164 static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
165 static int smctr_issue_write_byte_cmd(struct net_device *dev,
166 short aword_cnt, void *byte);
167 static int smctr_issue_write_word_cmd(struct net_device *dev,
168 short aword_cnt, void *word);
171 static int smctr_join_complete_state(struct net_device *dev);
174 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
175 static int smctr_load_firmware(struct net_device *dev);
176 static int smctr_load_node_addr(struct net_device *dev);
177 static int smctr_lobe_media_test(struct net_device *dev);
178 static int smctr_lobe_media_test_cmd(struct net_device *dev);
179 static int smctr_lobe_media_test_state(struct net_device *dev);
182 static int smctr_make_8025_hdr(struct net_device *dev,
183 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
184 static int smctr_make_access_pri(struct net_device *dev,
185 MAC_SUB_VECTOR *tsv);
186 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
187 static int smctr_make_auth_funct_class(struct net_device *dev,
188 MAC_SUB_VECTOR *tsv);
189 static int smctr_make_corr(struct net_device *dev,
190 MAC_SUB_VECTOR *tsv, __u16 correlator);
191 static int smctr_make_funct_addr(struct net_device *dev,
192 MAC_SUB_VECTOR *tsv);
193 static int smctr_make_group_addr(struct net_device *dev,
194 MAC_SUB_VECTOR *tsv);
195 static int smctr_make_phy_drop_num(struct net_device *dev,
196 MAC_SUB_VECTOR *tsv);
197 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
198 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
199 static int smctr_make_ring_station_status(struct net_device *dev,
200 MAC_SUB_VECTOR *tsv);
201 static int smctr_make_ring_station_version(struct net_device *dev,
202 MAC_SUB_VECTOR *tsv);
203 static int smctr_make_tx_status_code(struct net_device *dev,
204 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
205 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
206 MAC_SUB_VECTOR *tsv);
207 static int smctr_make_wrap_data(struct net_device *dev,
208 MAC_SUB_VECTOR *tsv);
211 static int smctr_open(struct net_device *dev);
212 static int smctr_open_tr(struct net_device *dev);
215 struct net_device *smctr_probe(int unit);
216 static int __init smctr_probe1(struct net_device *dev, int ioaddr);
217 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
218 struct net_device *dev, __u16 rx_status);
221 static int smctr_ram_memory_test(struct net_device *dev);
222 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
224 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
226 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
227 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
228 MAC_HEADER *rmf, __u16 *correlator);
229 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
231 static int smctr_reset_adapter(struct net_device *dev);
232 static int smctr_restart_tx_chain(struct net_device *dev, short queue);
233 static int smctr_ring_status_chg(struct net_device *dev);
234 static int smctr_rx_frame(struct net_device *dev);
237 static int smctr_send_dat(struct net_device *dev);
238 static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev);
239 static int smctr_send_lobe_media_test(struct net_device *dev);
240 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
242 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
244 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
246 static int smctr_send_rpt_tx_forward(struct net_device *dev,
247 MAC_HEADER *rmf, __u16 tx_fstatus);
248 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
249 __u16 rcode, __u16 correlator);
250 static int smctr_send_rq_init(struct net_device *dev);
251 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
253 static int smctr_set_auth_access_pri(struct net_device *dev,
254 MAC_SUB_VECTOR *rsv);
255 static int smctr_set_auth_funct_class(struct net_device *dev,
256 MAC_SUB_VECTOR *rsv);
257 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
259 static int smctr_set_error_timer_value(struct net_device *dev,
260 MAC_SUB_VECTOR *rsv);
261 static int smctr_set_frame_forward(struct net_device *dev,
262 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
263 static int smctr_set_local_ring_num(struct net_device *dev,
264 MAC_SUB_VECTOR *rsv);
265 static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
266 static void smctr_set_multicast_list(struct net_device *dev);
267 static int smctr_set_page(struct net_device *dev, __u8 *buf);
268 static int smctr_set_phy_drop(struct net_device *dev,
269 MAC_SUB_VECTOR *rsv);
270 static int smctr_set_ring_speed(struct net_device *dev);
271 static int smctr_set_rx_look_ahead(struct net_device *dev);
272 static int smctr_set_trc_reset(int ioaddr);
273 static int smctr_setup_single_cmd(struct net_device *dev,
274 __u16 command, __u16 subcommand);
275 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
276 __u16 command, __u16 subcommand);
277 static char *smctr_malloc(struct net_device *dev, __u16 size);
278 static int smctr_status_chg(struct net_device *dev);
281 static void smctr_timeout(struct net_device *dev);
282 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
284 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
285 static unsigned short smctr_tx_move_frame(struct net_device *dev,
286 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
289 static int smctr_update_err_stats(struct net_device *dev);
290 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
291 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
295 static int smctr_wait_cmd(struct net_device *dev);
296 static int smctr_wait_while_cbusy(struct net_device *dev);
298 #define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
299 #define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
300 #define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
302 /* Allocate Adapter Shared Memory.
303 * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
304 * function "get_num_rx_bdbs" below!!!
306 * Order of memory allocation:
308 * 0. Initial System Configuration Block Pointer
309 * 1. System Configuration Block
310 * 2. System Control Block
311 * 3. Action Command Block
312 * 4. Interrupt Status Block
315 * 6. NON-MAC TX FCB'S
317 * 8. NON-MAC TX BDB'S
319 * 10. NON-MAC RX FCB'S
321 * 12. NON-MAC RX BDB'S
322 * 13. MAC TX Data Buffer( 1, 256 byte buffer)
323 * 14. MAC RX Data Buffer( 1, 256 byte buffer)
325 * 15. NON-MAC TX Data Buffer
326 * 16. NON-MAC RX Data Buffer
328 static int smctr_alloc_shared_memory(struct net_device *dev)
330 struct net_local *tp = netdev_priv(dev);
333 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
335 /* Allocate initial System Control Block pointer.
336 * This pointer is located in the last page, last offset - 4.
338 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
339 - (long)ISCP_BLOCK_SIZE);
341 /* Allocate System Control Blocks. */
342 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
343 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
345 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
346 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
348 tp->acb_head = (ACBlock *)smctr_malloc(dev,
349 sizeof(ACBlock)*tp->num_acbs);
350 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
352 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
353 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
355 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
356 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
358 /* Allocate transmit FCBs. */
359 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
360 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
362 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
363 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
365 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
366 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
368 /* Allocate transmit BDBs. */
369 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
370 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
372 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
373 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
375 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
376 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
378 /* Allocate receive FCBs. */
379 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
380 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
382 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
383 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
385 /* Allocate receive BDBs. */
386 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
387 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
389 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
391 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
392 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
394 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
396 /* Allocate MAC transmit buffers.
397 * MAC Tx Buffers doen't have to be on an ODD Boundry.
399 tp->tx_buff_head[MAC_QUEUE]
400 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
401 tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
402 tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
404 /* Allocate BUG transmit buffers. */
405 tp->tx_buff_head[BUG_QUEUE]
406 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
407 tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
408 tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
410 /* Allocate MAC receive data buffers.
411 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
413 tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
414 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
415 tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
417 /* Allocate Non-MAC transmit buffers.
418 * ?? For maximum Netware performance, put Tx Buffers on
419 * ODD Boundry and then restore malloc to Even Boundrys.
421 smctr_malloc(dev, 1L);
422 tp->tx_buff_head[NON_MAC_QUEUE]
423 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
424 tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
425 tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
426 smctr_malloc(dev, 1L);
428 /* Allocate Non-MAC receive data buffers.
429 * To guarantee a minimum of 256 contigous memory to
430 * UM_Receive_Packet's lookahead pointer, before a page
431 * change or ring end is encountered, place each rx buffer on
432 * a 256 byte boundary.
434 smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
435 tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
436 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
437 tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
442 /* Enter Bypass state. */
443 static int smctr_bypass_state(struct net_device *dev)
448 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
450 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
455 static int smctr_checksum_firmware(struct net_device *dev)
457 struct net_local *tp = netdev_priv(dev);
458 __u16 i, checksum = 0;
461 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
463 smctr_enable_adapter_ctrl_store(dev);
465 for(i = 0; i < CS_RAM_SIZE; i += 2)
466 checksum += *((__u16 *)(tp->ram_access + i));
468 tp->microcode_version = *(__u16 *)(tp->ram_access
469 + CS_RAM_VERSION_OFFSET);
470 tp->microcode_version >>= 8;
472 smctr_disable_adapter_ctrl_store(dev);
480 static int __init smctr_chk_mca(struct net_device *dev)
482 #ifdef CONFIG_MCA_LEGACY
483 struct net_local *tp = netdev_priv(dev);
485 __u8 r1, r2, r3, r4, r5;
487 current_slot = mca_find_unused_adapter(smctr_posid, 0);
488 if(current_slot == MCA_NOTFOUND)
491 mca_set_adapter_name(current_slot, smctr_name);
492 mca_mark_as_used(current_slot);
493 tp->slot_num = current_slot;
495 r1 = mca_read_stored_pos(tp->slot_num, 2);
496 r2 = mca_read_stored_pos(tp->slot_num, 3);
499 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
501 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
503 r1 = inb(CNFG_POS_REG1);
504 r2 = inb(CNFG_POS_REG0);
506 tp->bic_type = BIC_594_CHIP;
509 r2 = mca_read_stored_pos(tp->slot_num, 2);
511 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
512 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
515 r5 = mca_read_stored_pos(tp->slot_num, 5);
535 if (request_irq(dev->irq, smctr_interrupt, SA_SHIRQ, smctr_name, dev)) {
536 release_region(dev->base_addr, SMCTR_IO_EXTENT);
541 r3 = mca_read_stored_pos(tp->slot_num, 3);
542 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
544 tp->ram_base += 0x010000;
546 tp->ram_base += 0xF00000;
552 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
553 tp->ram_size = (__u16)CNFG_SIZE_64KB;
554 tp->board_id |= TOKEN_MEDIA;
556 r4 = mca_read_stored_pos(tp->slot_num, 4);
557 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
559 tp->rom_base += 0x010000;
565 tp->rom_size = CNFG_SIZE_8KB;
568 tp->rom_size = CNFG_SIZE_16KB;
571 tp->rom_size = CNFG_SIZE_32KB;
574 tp->rom_size = ROM_DISABLE;
577 /* Get Media Type. */
578 r5 = mca_read_stored_pos(tp->slot_num, 5);
579 r5 &= CNFG_MEDIA_TYPE_MASK;
583 tp->media_type = MEDIA_STP_4;
587 tp->media_type = MEDIA_STP_16;
591 tp->media_type = MEDIA_UTP_16;
595 tp->media_type = MEDIA_UTP_4;
600 r2 = mca_read_stored_pos(tp->slot_num, 2);
602 tp->mode_bits |= EARLY_TOKEN_REL;
605 outb(CNFG_POS_CONTROL_REG, 0);
607 tp->board_id = smctr_get_boardid(dev, 1);
608 switch(tp->board_id & 0xffff)
611 smctr_model = "8115T/A";
615 if(tp->extra_info & CHIP_REV_MASK)
616 smctr_model = "8115T rev XE";
618 smctr_model = "8115T rev XD";
622 smctr_model = "Unknown";
629 #endif /* CONFIG_MCA_LEGACY */
632 static int smctr_chg_rx_mask(struct net_device *dev)
634 struct net_local *tp = netdev_priv(dev);
638 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
640 smctr_enable_16bit(dev);
641 smctr_set_page(dev, (__u8 *)tp->ram_access);
643 if(tp->mode_bits & LOOPING_MODE_MASK)
644 tp->config_word0 |= RX_OWN_BIT;
646 tp->config_word0 &= ~RX_OWN_BIT;
648 if(tp->receive_mask & PROMISCUOUS_MODE)
649 tp->config_word0 |= PROMISCUOUS_BIT;
651 tp->config_word0 &= ~PROMISCUOUS_BIT;
653 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
654 tp->config_word0 |= SAVBAD_BIT;
656 tp->config_word0 &= ~SAVBAD_BIT;
658 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
659 tp->config_word0 |= RXATMAC;
661 tp->config_word0 &= ~RXATMAC;
663 if(tp->receive_mask & ACCEPT_MULTI_PROM)
664 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
666 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
668 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
669 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
672 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
673 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
675 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
678 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
684 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
690 smctr_disable_16bit(dev);
695 static int smctr_clear_int(struct net_device *dev)
697 struct net_local *tp = netdev_priv(dev);
699 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
704 static int smctr_clear_trc_reset(int ioaddr)
708 r = inb(ioaddr + MSR);
709 outb(~MSR_RST & r, ioaddr + MSR);
715 * The inverse routine to smctr_open().
717 static int smctr_close(struct net_device *dev)
719 struct net_local *tp = netdev_priv(dev);
723 netif_stop_queue(dev);
727 /* Check to see if adapter is already in a closed state. */
728 if(tp->status != OPEN)
731 smctr_enable_16bit(dev);
732 smctr_set_page(dev, (__u8 *)tp->ram_access);
734 if((err = smctr_issue_remove_cmd(dev)))
736 smctr_disable_16bit(dev);
742 skb = skb_dequeue(&tp->SendSkbQueue);
753 static int smctr_decode_firmware(struct net_device *dev)
755 struct net_local *tp = netdev_priv(dev);
756 short bit = 0x80, shift = 12;
757 DECODE_TREE_NODE *tree;
765 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
767 weight = *(long *)(tp->ptr_ucode + WEIGHT_OFFSET);
768 tsize = *(__u8 *)(tp->ptr_ucode + TREE_SIZE_OFFSET);
769 tree = (DECODE_TREE_NODE *)(tp->ptr_ucode + TREE_OFFSET);
770 ucode = (__u8 *)(tp->ptr_ucode + TREE_OFFSET
771 + (tsize * sizeof(DECODE_TREE_NODE)));
772 mem = (__u16 *)(tp->ram_access);
777 while((tree + branch)->tag != LEAF && weight)
779 branch = *ucode & bit ? (tree + branch)->llink
780 : (tree + branch)->rlink;
792 buff |= (tree + branch)->info << shift;
797 *(mem++) = SWAP_BYTES(buff);
803 /* The following assumes the Control Store Memory has
804 * been initialized to zero. If the last partial word
805 * is zero, it will not be written.
808 *(mem++) = SWAP_BYTES(buff);
813 static int smctr_disable_16bit(struct net_device *dev)
819 * On Exit, Adapter is:
820 * 1. TRC is in a reset state and un-initialized.
821 * 2. Adapter memory is enabled.
822 * 3. Control Store memory is out of context (-WCSS is 1).
824 static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
826 struct net_local *tp = netdev_priv(dev);
827 int ioaddr = dev->base_addr;
830 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
832 tp->trc_mask |= CSR_WCSS;
833 outb(tp->trc_mask, ioaddr + CSR);
838 static int smctr_disable_bic_int(struct net_device *dev)
840 struct net_local *tp = netdev_priv(dev);
841 int ioaddr = dev->base_addr;
843 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
844 | CSR_MSKTINT | CSR_WCSS;
845 outb(tp->trc_mask, ioaddr + CSR);
850 static int smctr_enable_16bit(struct net_device *dev)
852 struct net_local *tp = netdev_priv(dev);
855 if(tp->adapter_bus == BUS_ISA16_TYPE)
857 r = inb(dev->base_addr + LAAR);
858 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
865 * To enable the adapter control store memory:
866 * 1. Adapter must be in a RESET state.
867 * 2. Adapter memory must be enabled.
868 * 3. Control Store Memory is in context (-WCSS is 0).
870 static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
872 struct net_local *tp = netdev_priv(dev);
873 int ioaddr = dev->base_addr;
876 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
878 smctr_set_trc_reset(ioaddr);
879 smctr_enable_adapter_ram(dev);
881 tp->trc_mask &= ~CSR_WCSS;
882 outb(tp->trc_mask, ioaddr + CSR);
887 static int smctr_enable_adapter_ram(struct net_device *dev)
889 int ioaddr = dev->base_addr;
893 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
895 r = inb(ioaddr + MSR);
896 outb(MSR_MEMB | r, ioaddr + MSR);
901 static int smctr_enable_bic_int(struct net_device *dev)
903 struct net_local *tp = netdev_priv(dev);
904 int ioaddr = dev->base_addr;
910 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
911 outb(tp->trc_mask, ioaddr + CSR);
912 r = inb(ioaddr + IRR);
913 outb(r | IRR_IEN, ioaddr + IRR);
917 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
918 outb(tp->trc_mask, ioaddr + CSR);
919 r = inb(ioaddr + IMCCR);
920 outb(r | IMCCR_EIL, ioaddr + IMCCR);
927 static int __init smctr_chk_isa(struct net_device *dev)
929 struct net_local *tp = netdev_priv(dev);
930 int ioaddr = dev->base_addr;
931 __u8 r1, r2, b, chksum = 0;
937 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
939 if((ioaddr & 0x1F) != 0)
942 /* Grab the region so that no one else tries to probe our ioports. */
943 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
948 /* Checksum SMC node address */
949 for(i = 0; i < 8; i++)
951 b = inb(ioaddr + LAR0 + i);
955 if (chksum != NODE_ADDR_CKSUM)
958 b = inb(ioaddr + BDID);
959 if(b != BRD_ID_8115T)
961 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
965 /* Check for 8115T Board ID */
967 for(r = 0; r < 8; r++)
969 r1 = inb(ioaddr + 0x8 + r);
973 /* value of RegF adds up the sum to 0xFF */
974 if((r2 != 0xFF) && (r2 != 0xEE))
978 tp->board_id = smctr_get_boardid(dev, 0);
979 switch(tp->board_id & 0xffff)
982 smctr_model = "8115T/A";
986 if(tp->extra_info & CHIP_REV_MASK)
987 smctr_model = "8115T rev XE";
989 smctr_model = "8115T rev XD";
993 smctr_model = "Unknown";
997 /* Store BIC type. */
998 tp->bic_type = BIC_584_CHIP;
999 tp->nic_type = NIC_825_CHIP;
1002 tp->ram_usable = CNFG_SIZE_16KB;
1003 tp->ram_size = CNFG_SIZE_64KB;
1005 /* Get 58x Ram Base */
1009 r2 = inb(ioaddr + CNFG_LAAR_584);
1010 r2 &= CNFG_LAAR_MASK;
1012 r2 |= ((r1 & 0x38) >> 3);
1014 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1018 r1 = inb(ioaddr + CNFG_ICR_583);
1019 r1 &= CNFG_ICR_IR2_584;
1021 r2 = inb(ioaddr + CNFG_IRR_583);
1022 r2 &= CNFG_IRR_IRQS; /* 0x60 */
1044 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1061 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1065 if (request_irq(dev->irq, smctr_interrupt, SA_SHIRQ, smctr_name, dev))
1068 /* Get 58x Rom Base */
1069 r1 = inb(ioaddr + CNFG_BIO_583);
1073 tp->rom_base = (__u32)r1 << 13;
1075 /* Get 58x Rom Size */
1076 r1 = inb(ioaddr + CNFG_BIO_583);
1079 tp->rom_size = ROM_DISABLE;
1083 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1086 /* Get 58x Boot Status */
1087 r1 = inb(ioaddr + CNFG_GP2);
1089 tp->mode_bits &= (~BOOT_STATUS_MASK);
1091 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1092 tp->mode_bits |= BOOT_TYPE_1;
1094 /* Get 58x Zero Wait State */
1095 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1097 r1 = inb(ioaddr + CNFG_IRR_583);
1099 if(r1 & CNFG_IRR_ZWS)
1100 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1102 if(tp->board_id & BOARD_16BIT)
1104 r1 = inb(ioaddr + CNFG_LAAR_584);
1106 if(r1 & CNFG_LAAR_ZWS)
1107 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1110 /* Get 584 Media Menu */
1111 tp->media_menu = 14;
1112 r1 = inb(ioaddr + CNFG_IRR_583);
1114 tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1115 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1117 /* Get Advanced Features */
1118 if(((r1 & 0x6) >> 1) == 0x3)
1119 tp->media_type |= MEDIA_UTP_16;
1122 if(((r1 & 0x6) >> 1) == 0x2)
1123 tp->media_type |= MEDIA_STP_16;
1126 if(((r1 & 0x6) >> 1) == 0x1)
1127 tp->media_type |= MEDIA_UTP_4;
1130 tp->media_type |= MEDIA_STP_4;
1134 r1 = inb(ioaddr + CNFG_GP2);
1135 if(!(r1 & 0x2) ) /* GP2_ETRD */
1136 tp->mode_bits |= EARLY_TOKEN_REL;
1138 /* see if the chip is corrupted
1139 if(smctr_read_584_chksum(ioaddr))
1141 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1142 free_irq(dev->irq, dev);
1151 release_region(ioaddr, SMCTR_IO_EXTENT);
1156 static int __init smctr_get_boardid(struct net_device *dev, int mca)
1158 struct net_local *tp = netdev_priv(dev);
1159 int ioaddr = dev->base_addr;
1163 tp->board_id = BoardIdMask = 0;
1167 BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1168 tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT);
1172 BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1173 tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K
1174 + NIC_825_BIT + ALTERNATE_IRQ_BIT);
1179 r = inb(ioaddr + BID_REG_1);
1181 outb(r, ioaddr + BID_REG_1);
1182 r = inb(ioaddr + BID_REG_1);
1184 if(r & BID_SIXTEEN_BIT_BIT)
1186 tp->extra_info |= SLOT_16BIT;
1187 tp->adapter_bus = BUS_ISA16_TYPE;
1190 tp->adapter_bus = BUS_ISA8_TYPE;
1193 tp->adapter_bus = BUS_MCA_TYPE;
1195 /* Get Board Id Byte */
1196 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1198 /* if Major version > 1.0 then
1204 r1 = inb(ioaddr + BID_REG_1);
1206 r1 |= BID_OTHER_BIT;
1208 outb(r1, ioaddr + BID_REG_1);
1209 r1 = inb(ioaddr + BID_REG_3);
1212 r1 |= BID_ENGR_PAGE;
1214 outb(r1, ioaddr + BID_REG_3);
1215 r1 = inb(ioaddr + BID_REG_1);
1217 r1 |= (BID_RLA | BID_OTHER_BIT);
1219 outb(r1, ioaddr + BID_REG_1);
1221 r1 = inb(ioaddr + BID_REG_1);
1222 while(r1 & BID_RECALL_DONE_MASK)
1223 r1 = inb(ioaddr + BID_REG_1);
1225 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1227 /* clear chip rev bits */
1228 tp->extra_info &= ~CHIP_REV_MASK;
1229 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1231 r1 = inb(ioaddr + BID_REG_1);
1233 r1 |= BID_OTHER_BIT;
1235 outb(r1, ioaddr + BID_REG_1);
1236 r1 = inb(ioaddr + BID_REG_3);
1241 outb(r1, ioaddr + BID_REG_3);
1242 r1 = inb(ioaddr + BID_REG_1);
1247 outb(r1, ioaddr + BID_REG_1);
1248 r1 = inb(ioaddr + BID_REG_1);
1250 while(r1 & BID_RECALL_DONE_MASK)
1251 r1 = inb(ioaddr + BID_REG_1);
1253 return (BoardIdMask);
1256 static int smctr_get_group_address(struct net_device *dev)
1258 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1260 return(smctr_wait_cmd(dev));
1263 static int smctr_get_functional_address(struct net_device *dev)
1265 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1267 return(smctr_wait_cmd(dev));
1270 /* Calculate number of Non-MAC receive BDB's and data buffers.
1271 * This function must simulate allocateing shared memory exactly
1272 * as the allocate_shared_memory function above.
1274 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1276 struct net_local *tp = netdev_priv(dev);
1277 unsigned int mem_used = 0;
1279 /* Allocate System Control Blocks. */
1280 mem_used += sizeof(SCGBlock);
1282 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1283 mem_used += sizeof(SCLBlock);
1285 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1286 mem_used += sizeof(ACBlock) * tp->num_acbs;
1288 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1289 mem_used += sizeof(ISBlock);
1291 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1292 mem_used += MISC_DATA_SIZE;
1294 /* Allocate transmit FCB's. */
1295 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1297 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE];
1298 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE];
1299 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE];
1301 /* Allocate transmit BDBs. */
1302 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE];
1303 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE];
1304 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE];
1306 /* Allocate receive FCBs. */
1307 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE];
1308 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE];
1310 /* Allocate receive BDBs. */
1311 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1313 /* Allocate MAC transmit buffers.
1314 * MAC transmit buffers don't have to be on an ODD Boundry.
1316 mem_used += tp->tx_buff_size[MAC_QUEUE];
1318 /* Allocate BUG transmit buffers. */
1319 mem_used += tp->tx_buff_size[BUG_QUEUE];
1321 /* Allocate MAC receive data buffers.
1322 * MAC receive buffers don't have to be on a 256 byte boundary.
1324 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
1326 /* Allocate Non-MAC transmit buffers.
1327 * For maximum Netware performance, put Tx Buffers on
1328 * ODD Boundry,and then restore malloc to Even Boundrys.
1331 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1334 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1335 * AND NON-MAC RX DATA BUFFERS
1337 * Make sure the mem_used offset at this point is the
1338 * same as in allocate_shared memory or the following
1339 * boundary adjustment will be incorrect (i.e. not allocating
1340 * the non-mac receive buffers above cannot change the 256
1343 * Since this cannot be guaranteed, adding the full 256 bytes
1344 * to the amount of shared memory used at this point will guaranteed
1345 * that the rx data buffers do not overflow shared memory.
1349 return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock)));
1352 static int smctr_get_physical_drop_number(struct net_device *dev)
1354 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1356 return(smctr_wait_cmd(dev));
1359 static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1361 struct net_local *tp = netdev_priv(dev);
1364 bdb = (BDBlock *)((__u32)tp->ram_access
1365 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1367 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1369 return ((__u8 *)bdb->data_block_ptr);
1372 static int smctr_get_station_id(struct net_device *dev)
1374 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1376 return(smctr_wait_cmd(dev));
1380 * Get the current statistics. This may be called with the card open
1383 static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1385 struct net_local *tp = netdev_priv(dev);
1387 return ((struct net_device_stats *)&tp->MacStat);
1390 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1393 struct net_local *tp = netdev_priv(dev);
1396 unsigned short alloc_size;
1397 unsigned short *temp;
1399 if(smctr_debug > 20)
1400 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
1402 /* check if there is enough FCB blocks */
1403 if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue])
1404 return ((FCBlock *)(-1L));
1406 /* round off the input pkt size to the nearest even number */
1407 alloc_size = (bytes_count + 1) & 0xfffe;
1409 /* check if enough mem */
1410 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
1411 return ((FCBlock *)(-1L));
1413 /* check if past the end ;
1414 * if exactly enough mem to end of ring, alloc from front.
1415 * this avoids update of curr when curr = end
1417 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1418 >= (unsigned long)(tp->tx_buff_end[queue]))
1420 /* check if enough memory from ring head */
1421 alloc_size = alloc_size +
1422 (__u16)((__u32)tp->tx_buff_end[queue]
1423 - (__u32)tp->tx_buff_curr[queue]);
1425 if((tp->tx_buff_used[queue] + alloc_size)
1426 > tp->tx_buff_size[queue])
1428 return ((FCBlock *)(-1L));
1432 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
1435 tp->tx_buff_used[queue] += alloc_size;
1436 tp->num_tx_fcbs_used[queue]++;
1437 tp->tx_fcb_curr[queue]->frame_length = bytes_count;
1438 tp->tx_fcb_curr[queue]->memory_alloc = alloc_size;
1439 temp = tp->tx_buff_curr[queue];
1440 tp->tx_buff_curr[queue]
1441 = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe));
1443 pbdb = tp->tx_fcb_curr[queue]->bdb_ptr;
1444 pbdb->buffer_length = bytes_count;
1445 pbdb->data_block_ptr = temp;
1446 pbdb->trc_data_block_ptr = TRC_POINTER(temp);
1448 pFCB = tp->tx_fcb_curr[queue];
1449 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1454 static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1456 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1458 return(smctr_wait_cmd(dev));
1461 static int smctr_hardware_send_packet(struct net_device *dev,
1462 struct net_local *tp)
1464 struct tr_statistics *tstat = &tp->MacStat;
1465 struct sk_buff *skb;
1468 if(smctr_debug > 10)
1469 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1471 if(tp->status != OPEN)
1474 if(tp->monitor_state_ready != 1)
1479 /* Send first buffer from queue */
1480 skb = skb_dequeue(&tp->SendSkbQueue);
1486 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size) return (-1);
1488 smctr_enable_16bit(dev);
1489 smctr_set_page(dev, (__u8 *)tp->ram_access);
1491 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1492 == (FCBlock *)(-1L))
1494 smctr_disable_16bit(dev);
1498 smctr_tx_move_frame(dev, skb,
1499 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1501 smctr_set_page(dev, (__u8 *)fcb);
1503 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1506 tstat->tx_packets++;
1508 smctr_disable_16bit(dev);
1514 static int smctr_init_acbs(struct net_device *dev)
1516 struct net_local *tp = netdev_priv(dev);
1520 if(smctr_debug > 10)
1521 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1524 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1525 acb->cmd_info = ACB_CHAIN_END;
1528 acb->data_offset_lo = 0;
1529 acb->data_offset_hi = 0;
1531 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1532 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1534 for(i = 1; i < tp->num_acbs; i++)
1536 acb = acb->next_ptr;
1537 acb->cmd_done_status
1538 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1539 acb->cmd_info = ACB_CHAIN_END;
1542 acb->data_offset_lo = 0;
1543 acb->data_offset_hi = 0;
1545 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1546 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1549 acb->next_ptr = tp->acb_head;
1550 acb->trc_next_ptr = TRC_POINTER(tp->acb_head);
1551 tp->acb_next = tp->acb_head->next_ptr;
1552 tp->acb_curr = tp->acb_head->next_ptr;
1553 tp->num_acbs_used = 0;
1558 static int smctr_init_adapter(struct net_device *dev)
1560 struct net_local *tp = netdev_priv(dev);
1563 if(smctr_debug > 10)
1564 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
1566 tp->status = CLOSED;
1567 tp->page_offset_mask = (tp->ram_usable * 1024) - 1;
1568 skb_queue_head_init(&tp->SendSkbQueue);
1569 tp->QueueSkb = MAX_TX_QUEUE;
1571 if(!(tp->group_address_0 & 0x0080))
1572 tp->group_address_0 |= 0x00C0;
1574 if(!(tp->functional_address_0 & 0x00C0))
1575 tp->functional_address_0 |= 0x00C0;
1577 tp->functional_address[0] &= 0xFF7F;
1579 if(tp->authorized_function_classes == 0)
1580 tp->authorized_function_classes = 0x7FFF;
1582 if(tp->authorized_access_priority == 0)
1583 tp->authorized_access_priority = 0x06;
1585 smctr_disable_bic_int(dev);
1586 smctr_set_trc_reset(dev->base_addr);
1588 smctr_enable_16bit(dev);
1589 smctr_set_page(dev, (__u8 *)tp->ram_access);
1591 if(smctr_checksum_firmware(dev))
1593 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name); return (-ENOENT);
1596 if((err = smctr_ram_memory_test(dev)))
1598 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1602 smctr_set_rx_look_ahead(dev);
1603 smctr_load_node_addr(dev);
1605 /* Initialize adapter for Internal Self Test. */
1606 smctr_reset_adapter(dev);
1607 if((err = smctr_init_card_real(dev)))
1609 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1614 /* This routine clobbers the TRC's internal registers. */
1615 if((err = smctr_internal_self_test(dev)))
1617 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1622 /* Re-Initialize adapter's internal registers */
1623 smctr_reset_adapter(dev);
1624 if((err = smctr_init_card_real(dev)))
1626 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1631 smctr_enable_bic_int(dev);
1633 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1636 smctr_disable_16bit(dev);
1641 static int smctr_init_card_real(struct net_device *dev)
1643 struct net_local *tp = netdev_priv(dev);
1646 if(smctr_debug > 10)
1647 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1649 tp->sh_mem_used = 0;
1650 tp->num_acbs = NUM_OF_ACBS;
1652 /* Range Check Max Packet Size */
1653 if(tp->max_packet_size < 256)
1654 tp->max_packet_size = 256;
1657 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1658 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1661 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1662 / tp->max_packet_size) - 1;
1664 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1665 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1668 if(tp->num_of_tx_buffs == 0)
1669 tp->num_of_tx_buffs = 1;
1672 /* Tx queue constants */
1673 tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS;
1674 tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS;
1675 tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY;
1676 tp->tx_buff_used [BUG_QUEUE] = 0;
1677 tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING;
1679 tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS;
1680 tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS;
1681 tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY;
1682 tp->tx_buff_used [MAC_QUEUE] = 0;
1683 tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING;
1685 tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
1686 tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
1687 tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
1688 tp->tx_buff_used [NON_MAC_QUEUE] = 0;
1689 tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING;
1691 /* Receive Queue Constants */
1692 tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
1693 tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
1695 if(tp->extra_info & CHIP_REV_MASK)
1696 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1698 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1700 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1702 smctr_alloc_shared_memory(dev);
1703 smctr_init_shared_memory(dev);
1705 if((err = smctr_issue_init_timers_cmd(dev)))
1708 if((err = smctr_issue_init_txrx_cmd(dev)))
1710 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1717 static int smctr_init_rx_bdbs(struct net_device *dev)
1719 struct net_local *tp = netdev_priv(dev);
1724 if(smctr_debug > 10)
1725 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1727 for(i = 0; i < NUM_RX_QS_USED; i++)
1729 bdb = tp->rx_bdb_head[i];
1730 buf = tp->rx_buff_head[i];
1731 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
1732 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1733 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1734 bdb->data_block_ptr = buf;
1735 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1737 if(i == NON_MAC_QUEUE)
1738 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1740 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1742 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1744 bdb->next_ptr->back_ptr = bdb;
1745 bdb = bdb->next_ptr;
1746 buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
1747 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1748 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1749 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1750 bdb->data_block_ptr = buf;
1751 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1753 if(i == NON_MAC_QUEUE)
1754 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1756 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1759 bdb->next_ptr = tp->rx_bdb_head[i];
1760 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1762 tp->rx_bdb_head[i]->back_ptr = bdb;
1763 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1769 static int smctr_init_rx_fcbs(struct net_device *dev)
1771 struct net_local *tp = netdev_priv(dev);
1775 for(i = 0; i < NUM_RX_QS_USED; i++)
1777 fcb = tp->rx_fcb_head[i];
1778 fcb->frame_status = 0;
1779 fcb->frame_length = 0;
1780 fcb->info = FCB_CHAIN_END;
1781 fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
1782 if(i == NON_MAC_QUEUE)
1783 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1785 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1787 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1789 fcb->next_ptr->back_ptr = fcb;
1790 fcb = fcb->next_ptr;
1791 fcb->frame_status = 0;
1792 fcb->frame_length = 0;
1793 fcb->info = FCB_WARNING;
1795 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1797 if(i == NON_MAC_QUEUE)
1799 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1802 = TRC_POINTER(fcb->next_ptr);
1805 fcb->next_ptr = tp->rx_fcb_head[i];
1807 if(i == NON_MAC_QUEUE)
1808 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1810 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1812 tp->rx_fcb_head[i]->back_ptr = fcb;
1813 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1819 static int smctr_init_shared_memory(struct net_device *dev)
1821 struct net_local *tp = netdev_priv(dev);
1825 if(smctr_debug > 10)
1826 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1828 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1830 /* Initialize Initial System Configuration Point. (ISCP) */
1831 iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
1832 *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
1834 smctr_set_page(dev, (__u8 *)tp->ram_access);
1836 /* Initialize System Configuration Pointers. (SCP) */
1837 tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
1838 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
1839 | SCGB_BURST_LENGTH);
1841 tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr);
1842 tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head);
1843 tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr);
1844 tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2;
1846 /* Initialize System Control Block. (SCB) */
1847 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP;
1848 tp->sclb_ptr->iack_code = 0;
1849 tp->sclb_ptr->resume_control = 0;
1850 tp->sclb_ptr->int_mask_control = 0;
1851 tp->sclb_ptr->int_mask_state = 0;
1853 /* Initialize Interrupt Status Block. (ISB) */
1854 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1856 tp->isb_ptr->IStatus[i].IType = 0xf0;
1857 tp->isb_ptr->IStatus[i].ISubtype = 0;
1860 tp->current_isb_index = 0;
1862 /* Initialize Action Command Block. (ACB) */
1863 smctr_init_acbs(dev);
1865 /* Initialize transmit FCB's and BDB's. */
1866 smctr_link_tx_fcbs_to_bdbs(dev);
1867 smctr_init_tx_bdbs(dev);
1868 smctr_init_tx_fcbs(dev);
1870 /* Initialize receive FCB's and BDB's. */
1871 smctr_init_rx_bdbs(dev);
1872 smctr_init_rx_fcbs(dev);
1877 static int smctr_init_tx_bdbs(struct net_device *dev)
1879 struct net_local *tp = netdev_priv(dev);
1883 for(i = 0; i < NUM_TX_QS_USED; i++)
1885 bdb = tp->tx_bdb_head[i];
1886 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1887 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1888 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1890 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1892 bdb->next_ptr->back_ptr = bdb;
1893 bdb = bdb->next_ptr;
1894 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1896 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1899 bdb->next_ptr = tp->tx_bdb_head[i];
1900 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
1901 tp->tx_bdb_head[i]->back_ptr = bdb;
1907 static int smctr_init_tx_fcbs(struct net_device *dev)
1909 struct net_local *tp = netdev_priv(dev);
1913 for(i = 0; i < NUM_TX_QS_USED; i++)
1915 fcb = tp->tx_fcb_head[i];
1916 fcb->frame_status = 0;
1917 fcb->frame_length = 0;
1918 fcb->info = FCB_CHAIN_END;
1919 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1920 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1922 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1924 fcb->next_ptr->back_ptr = fcb;
1925 fcb = fcb->next_ptr;
1926 fcb->frame_status = 0;
1927 fcb->frame_length = 0;
1928 fcb->info = FCB_CHAIN_END;
1930 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1931 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1934 fcb->next_ptr = tp->tx_fcb_head[i];
1935 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1937 tp->tx_fcb_head[i]->back_ptr = fcb;
1938 tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr;
1939 tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr;
1940 tp->num_tx_fcbs_used[i] = 0;
1946 static int smctr_internal_self_test(struct net_device *dev)
1948 struct net_local *tp = netdev_priv(dev);
1951 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1954 if((err = smctr_wait_cmd(dev)))
1957 if(tp->acb_head->cmd_done_status & 0xff)
1960 if((err = smctr_issue_test_hic_cmd(dev)))
1963 if((err = smctr_wait_cmd(dev)))
1966 if(tp->acb_head->cmd_done_status & 0xff)
1969 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1972 if((err = smctr_wait_cmd(dev)))
1975 if(tp->acb_head->cmd_done_status & 0xff)
1982 * The typical workload of the driver: Handle the network interface interrupts.
1984 static irqreturn_t smctr_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1986 struct net_device *dev = dev_id;
1987 struct net_local *tp;
1989 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1990 __u16 err1, err = NOT_MY_INTERRUPT;
1991 __u8 isb_type, isb_subtype;
1996 printk(KERN_CRIT "%s: irq %d for unknown device.\n", dev->name, irq);
2000 ioaddr = dev->base_addr;
2001 tp = netdev_priv(dev);
2004 if(tp->status == NOT_INITIALIZED)
2007 spin_lock(&tp->lock);
2009 smctr_disable_bic_int(dev);
2010 smctr_enable_16bit(dev);
2012 smctr_clear_int(dev);
2014 /* First read the LSB */
2015 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2017 isb_index = tp->current_isb_index;
2018 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2019 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2021 (tp->current_isb_index)++;
2022 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2023 tp->current_isb_index = 0;
2025 if(isb_type >= 0x10)
2027 smctr_disable_16bit(dev);
2028 spin_unlock(&tp->lock);
2032 err = HARDWARE_FAILED;
2033 interrupt_ack_code = isb_index;
2034 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2036 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2040 case ISB_IMC_MAC_TYPE_3:
2041 smctr_disable_16bit(dev);
2046 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2050 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2054 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2058 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2061 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2065 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2069 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2073 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2076 case 8: /* diagnostic state */
2080 tp->monitor_state = MS_BEACON_TEST_STATE;
2081 if(smctr_lobe_media_test(dev))
2083 tp->ring_status_flags = RING_STATUS_CHANGED;
2084 tp->ring_status = AUTO_REMOVAL_ERROR;
2085 smctr_ring_status_chg(dev);
2086 smctr_bypass_state(dev);
2089 smctr_issue_insert_cmd(dev);
2092 /* case 0x0a-0xff, illegal states */
2097 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2098 err = smctr_ring_status_chg(dev);
2100 smctr_enable_16bit(dev);
2103 /* Type 0x02 - MAC Error Counters Interrupt
2104 * One or more MAC Error Counter is half full
2105 * MAC Error Counters
2106 * Lost_FR_Error_Counter
2107 * RCV_Congestion_Counter
2108 * FR_copied_Error_Counter
2109 * FREQ_Error_Counter
2110 * Token_Error_Counter
2111 * Line_Error_Counter
2112 * Internal_Error_Count
2114 case ISB_IMC_MAC_ERROR_COUNTERS:
2115 /* Read 802.5 Error Counters */
2116 err = smctr_issue_read_ring_status_cmd(dev);
2119 /* Type 0x04 - MAC Type 2 Interrupt
2120 * HOST needs to enqueue MAC Frame for transmission
2121 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2122 * TRC_Status_Changed_Indicate
2124 case ISB_IMC_MAC_TYPE_2:
2125 err = smctr_issue_read_ring_status_cmd(dev);
2129 /* Type 0x05 - TX Frame Interrupt (FI). */
2130 case ISB_IMC_TX_FRAME:
2131 /* BUG QUEUE for TRC stuck receive BUG */
2132 if(isb_subtype & TX_PENDING_PRIORITY_2)
2134 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2138 /* NON-MAC frames only */
2139 if(isb_subtype & TX_PENDING_PRIORITY_1)
2141 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2145 /* MAC frames only */
2146 if(isb_subtype & TX_PENDING_PRIORITY_0)
2147 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2149 /* Type 0x06 - TX END OF QUEUE (FE) */
2150 case ISB_IMC_END_OF_TX_QUEUE:
2152 if(isb_subtype & TX_PENDING_PRIORITY_2)
2154 /* ok to clear Receive FIFO overrun
2155 * imask send_BUG now completes.
2157 interrupt_unmask_bits |= 0x800;
2159 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2160 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2162 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2166 /* NON-MAC queue only */
2167 if(isb_subtype & TX_PENDING_PRIORITY_1)
2169 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2170 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2172 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2176 /* MAC queue only */
2177 if(isb_subtype & TX_PENDING_PRIORITY_0)
2179 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2180 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2183 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2187 /* Type 0x07 - NON-MAC RX Resource Interrupt
2188 * Subtype bit 12 - (BW) BDB warning
2189 * Subtype bit 13 - (FW) FCB warning
2190 * Subtype bit 14 - (BE) BDB End of chain
2191 * Subtype bit 15 - (FE) FCB End of chain
2193 case ISB_IMC_NON_MAC_RX_RESOURCE:
2194 tp->rx_fifo_overrun_count = 0;
2195 tp->receive_queue_number = NON_MAC_QUEUE;
2196 err1 = smctr_rx_frame(dev);
2198 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2200 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2202 if(tp->ptr_rx_fcb_overruns)
2203 (*tp->ptr_rx_fcb_overruns)++;
2206 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2208 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2210 if(tp->ptr_rx_bdb_overruns)
2211 (*tp->ptr_rx_bdb_overruns)++;
2216 /* Type 0x08 - MAC RX Resource Interrupt
2217 * Subtype bit 12 - (BW) BDB warning
2218 * Subtype bit 13 - (FW) FCB warning
2219 * Subtype bit 14 - (BE) BDB End of chain
2220 * Subtype bit 15 - (FE) FCB End of chain
2222 case ISB_IMC_MAC_RX_RESOURCE:
2223 tp->receive_queue_number = MAC_QUEUE;
2224 err1 = smctr_rx_frame(dev);
2226 if(isb_subtype & MAC_RX_RESOURCE_FE)
2228 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2231 if(tp->ptr_rx_fcb_overruns)
2232 (*tp->ptr_rx_fcb_overruns)++;
2235 if(isb_subtype & MAC_RX_RESOURCE_BE)
2237 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2240 if(tp->ptr_rx_bdb_overruns)
2241 (*tp->ptr_rx_bdb_overruns)++;
2246 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2247 case ISB_IMC_NON_MAC_RX_FRAME:
2248 tp->rx_fifo_overrun_count = 0;
2249 tp->receive_queue_number = NON_MAC_QUEUE;
2250 err = smctr_rx_frame(dev);
2253 /* Type 0x0A - MAC RX Frame Interrupt */
2254 case ISB_IMC_MAC_RX_FRAME:
2255 tp->receive_queue_number = MAC_QUEUE;
2256 err = smctr_rx_frame(dev);
2259 /* Type 0x0B - TRC status
2260 * TRC has encountered an error condition
2261 * subtype bit 14 - transmit FIFO underrun
2262 * subtype bit 15 - receive FIFO overrun
2264 case ISB_IMC_TRC_FIFO_STATUS:
2265 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2267 if(tp->ptr_tx_fifo_underruns)
2268 (*tp->ptr_tx_fifo_underruns)++;
2271 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2273 /* update overrun stuck receive counter
2274 * if >= 3, has to clear it by sending
2275 * back to back frames. We pick
2276 * DAT(duplicate address MAC frame)
2278 tp->rx_fifo_overrun_count++;
2280 if(tp->rx_fifo_overrun_count >= 3)
2282 tp->rx_fifo_overrun_count = 0;
2284 /* delay clearing fifo overrun
2285 * imask till send_BUG tx
2288 interrupt_unmask_bits &= (~0x800);
2289 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2292 if(tp->ptr_rx_fifo_overruns)
2293 (*tp->ptr_rx_fifo_overruns)++;
2299 /* Type 0x0C - Action Command Status Interrupt
2300 * Subtype bit 14 - CB end of command chain (CE)
2301 * Subtype bit 15 - CB command interrupt (CI)
2303 case ISB_IMC_COMMAND_STATUS:
2305 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2307 printk(KERN_ERR "i1\n");
2308 smctr_disable_16bit(dev);
2310 /* XXXXXXXXXXXXXXXXX */
2311 /* err = UM_Interrupt(dev); */
2313 smctr_enable_16bit(dev);
2317 if((tp->acb_head->cmd
2318 == ACB_CMD_READ_TRC_STATUS)
2319 && (tp->acb_head->subcmd
2320 == RW_TRC_STATUS_BLOCK))
2322 if(tp->ptr_bcn_type != 0)
2325 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2328 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2330 smctr_update_err_stats(dev);
2333 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2336 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2337 smctr_disable_16bit(dev);
2338 err = smctr_ring_status_chg(dev);
2339 smctr_enable_16bit(dev);
2340 if((tp->ring_status & REMOVE_RECEIVED)
2341 && (tp->config_word0 & NO_AUTOREMOVE))
2343 smctr_issue_remove_cmd(dev);
2348 tp->acb_pending = 0;
2353 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2357 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2358 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2359 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2364 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2365 err = smctr_send_rq_init(dev);
2370 tp->acb_pending = 0;
2373 /* Type 0x0D - MAC Type 1 interrupt
2374 * Subtype -- 00 FR_BCN received at S12
2375 * 01 FR_BCN received at S21
2376 * 02 FR_DAT(DA=MA, A<>0) received at S21
2378 * 04 FR_REMOVE received at S42
2379 * 05 TBR_EXP, BR_FLAG_SET at S42
2382 case ISB_IMC_MAC_TYPE_1:
2385 err = HARDWARE_FAILED;
2393 tp->join_state = JS_BYPASS_STATE;
2394 if(tp->status != CLOSED)
2396 tp->status = CLOSED;
2397 err = smctr_status_chg(dev);
2402 tp->join_state = JS_LOBE_TEST_STATE;
2406 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2410 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2414 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2418 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2422 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2426 tp->join_state = JS_JOIN_COMPLETE_STATE;
2428 err = smctr_status_chg(dev);
2432 tp->join_state = JS_BYPASS_WAIT_STATE;
2437 /* Type 0x0E - TRC Initialization Sequence Interrupt
2438 * Subtype -- 00-FF Initializatin sequence complete
2440 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2441 tp->status = INITIALIZED;
2442 smctr_disable_16bit(dev);
2443 err = smctr_status_chg(dev);
2444 smctr_enable_16bit(dev);
2447 /* other interrupt types, illegal */
2456 /* Checking the ack code instead of the unmask bits here is because :
2457 * while fixing the stuck receive, DAT frame are sent and mask off
2458 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2459 * but we still want to issue ack to ISB
2461 if(!(interrupt_ack_code & 0xff00))
2462 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2464 smctr_disable_16bit(dev);
2465 smctr_enable_bic_int(dev);
2466 spin_unlock(&tp->lock);
2471 static int smctr_issue_enable_int_cmd(struct net_device *dev,
2472 __u16 interrupt_enable_mask)
2474 struct net_local *tp = netdev_priv(dev);
2477 if((err = smctr_wait_while_cbusy(dev)))
2480 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2481 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2483 smctr_set_ctrl_attention(dev);
2488 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2490 struct net_local *tp = netdev_priv(dev);
2492 if(smctr_wait_while_cbusy(dev))
2495 tp->sclb_ptr->int_mask_control = ibits;
2496 tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0;
2497 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2499 smctr_set_ctrl_attention(dev);
2504 static int smctr_issue_init_timers_cmd(struct net_device *dev)
2506 struct net_local *tp = netdev_priv(dev);
2509 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2511 if((err = smctr_wait_while_cbusy(dev)))
2514 if((err = smctr_wait_cmd(dev)))
2517 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2518 tp->config_word1 = 0;
2520 if((tp->media_type == MEDIA_STP_16)
2521 || (tp->media_type == MEDIA_UTP_16)
2522 || (tp->media_type == MEDIA_STP_16_UTP_16))
2524 tp->config_word0 |= FREQ_16MB_BIT;
2527 if(tp->mode_bits & EARLY_TOKEN_REL)
2528 tp->config_word0 |= ETREN;
2530 if(tp->mode_bits & LOOPING_MODE_MASK)
2531 tp->config_word0 |= RX_OWN_BIT;
2533 tp->config_word0 &= ~RX_OWN_BIT;
2535 if(tp->receive_mask & PROMISCUOUS_MODE)
2536 tp->config_word0 |= PROMISCUOUS_BIT;
2538 tp->config_word0 &= ~PROMISCUOUS_BIT;
2540 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2541 tp->config_word0 |= SAVBAD_BIT;
2543 tp->config_word0 &= ~SAVBAD_BIT;
2545 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2546 tp->config_word0 |= RXATMAC;
2548 tp->config_word0 &= ~RXATMAC;
2550 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2551 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2553 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2555 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2556 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2559 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2560 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2562 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2565 if((tp->media_type == MEDIA_STP_16)
2566 || (tp->media_type == MEDIA_UTP_16)
2567 || (tp->media_type == MEDIA_STP_16_UTP_16))
2569 tp->config_word1 |= INTERFRAME_SPACING_16;
2572 tp->config_word1 |= INTERFRAME_SPACING_4;
2574 *pTimer_Struc++ = tp->config_word0;
2575 *pTimer_Struc++ = tp->config_word1;
2577 if((tp->media_type == MEDIA_STP_4)
2578 || (tp->media_type == MEDIA_UTP_4)
2579 || (tp->media_type == MEDIA_STP_4_UTP_4))
2581 *pTimer_Struc++ = 0x00FA; /* prescale */
2582 *pTimer_Struc++ = 0x2710; /* TPT_limit */
2583 *pTimer_Struc++ = 0x2710; /* TQP_limit */
2584 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2585 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2586 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2587 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2588 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2589 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2590 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2591 *pTimer_Struc++ = 0x1162; /* THT_limit */
2592 *pTimer_Struc++ = 0x07D0; /* TRR_limit */
2593 *pTimer_Struc++ = 0x1388; /* TVX_limit */
2594 *pTimer_Struc++ = 0x0000; /* reserved */
2598 *pTimer_Struc++ = 0x03E8; /* prescale */
2599 *pTimer_Struc++ = 0x9C40; /* TPT_limit */
2600 *pTimer_Struc++ = 0x9C40; /* TQP_limit */
2601 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2602 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2603 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2604 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2605 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2606 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2607 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2608 *pTimer_Struc++ = 0x4588; /* THT_limit */
2609 *pTimer_Struc++ = 0x1F40; /* TRR_limit */
2610 *pTimer_Struc++ = 0x4E20; /* TVX_limit */
2611 *pTimer_Struc++ = 0x0000; /* reserved */
2614 /* Set node address. */
2615 *pTimer_Struc++ = dev->dev_addr[0] << 8
2616 | (dev->dev_addr[1] & 0xFF);
2617 *pTimer_Struc++ = dev->dev_addr[2] << 8
2618 | (dev->dev_addr[3] & 0xFF);
2619 *pTimer_Struc++ = dev->dev_addr[4] << 8
2620 | (dev->dev_addr[5] & 0xFF);
2622 /* Set group address. */
2623 *pTimer_Struc++ = tp->group_address_0 << 8
2624 | tp->group_address_0 >> 8;
2625 *pTimer_Struc++ = tp->group_address[0] << 8
2626 | tp->group_address[0] >> 8;
2627 *pTimer_Struc++ = tp->group_address[1] << 8
2628 | tp->group_address[1] >> 8;
2630 /* Set functional address. */
2631 *pTimer_Struc++ = tp->functional_address_0 << 8
2632 | tp->functional_address_0 >> 8;
2633 *pTimer_Struc++ = tp->functional_address[0] << 8
2634 | tp->functional_address[0] >> 8;
2635 *pTimer_Struc++ = tp->functional_address[1] << 8
2636 | tp->functional_address[1] >> 8;
2638 /* Set Bit-Wise group address. */
2639 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2640 | tp->bitwise_group_address[0] >> 8;
2641 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2642 | tp->bitwise_group_address[1] >> 8;
2644 /* Set ring number address. */
2645 *pTimer_Struc++ = tp->source_ring_number;
2646 *pTimer_Struc++ = tp->target_ring_number;
2648 /* Physical drop number. */
2649 *pTimer_Struc++ = (unsigned short)0;
2650 *pTimer_Struc++ = (unsigned short)0;
2652 /* Product instance ID. */
2653 for(i = 0; i < 9; i++)
2654 *pTimer_Struc++ = (unsigned short)0;
2656 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2661 static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2663 struct net_local *tp = netdev_priv(dev);
2666 void **txrx_ptrs = (void *)tp->misc_command_data;
2668 if((err = smctr_wait_while_cbusy(dev)))
2671 if((err = smctr_wait_cmd(dev)))
2673 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2677 /* Initialize Transmit Queue Pointers that are used, to point to
2680 for(i = 0; i < NUM_TX_QS_USED; i++)
2681 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2683 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2684 for(; i < MAX_TX_QS; i++)
2685 *txrx_ptrs++ = (void *)0;
2687 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2688 * used, to point to a single FCB and a BDB chain of buffers.
2690 for(i = 0; i < NUM_RX_QS_USED; i++)
2692 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2693 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2696 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2697 for(; i < MAX_RX_QS; i++)
2699 *txrx_ptrs++ = (void *)0;
2700 *txrx_ptrs++ = (void *)0;
2703 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2708 static int smctr_issue_insert_cmd(struct net_device *dev)
2712 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2717 static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2721 if((err = smctr_wait_while_cbusy(dev)))
2724 if((err = smctr_wait_cmd(dev)))
2727 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2728 RW_TRC_STATUS_BLOCK);
2733 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2737 if((err = smctr_wait_while_cbusy(dev)))
2740 if((err = smctr_wait_cmd(dev)))
2743 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2749 static int smctr_issue_remove_cmd(struct net_device *dev)
2751 struct net_local *tp = netdev_priv(dev);
2754 if((err = smctr_wait_while_cbusy(dev)))
2757 tp->sclb_ptr->resume_control = 0;
2758 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2760 smctr_set_ctrl_attention(dev);
2765 static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2767 struct net_local *tp = netdev_priv(dev);
2770 if((err = smctr_wait_while_cbusy(dev)))
2773 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2774 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2776 tp->acb_pending = 1;
2778 smctr_set_ctrl_attention(dev);
2783 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2785 struct net_local *tp = netdev_priv(dev);
2788 if((err = smctr_wait_while_cbusy(dev)))
2791 if(queue == MAC_QUEUE)
2792 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2794 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2796 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2798 smctr_set_ctrl_attention(dev);
2803 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2805 struct net_local *tp = netdev_priv(dev);
2807 if(smctr_debug > 10)
2808 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2810 if(smctr_wait_while_cbusy(dev))
2813 if(queue == MAC_QUEUE)
2814 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2816 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2818 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2820 smctr_set_ctrl_attention(dev);
2825 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2827 struct net_local *tp = netdev_priv(dev);
2829 if(smctr_debug > 10)
2830 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2832 if(smctr_wait_while_cbusy(dev))
2835 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2836 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2838 smctr_set_ctrl_attention(dev);
2843 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2847 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2848 TRC_INTERNAL_ROM_TEST);
2853 static int smctr_issue_test_hic_cmd(struct net_device *dev)
2857 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2858 TRC_HOST_INTERFACE_REG_TEST);
2863 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2867 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2868 TRC_MAC_REGISTERS_TEST);
2873 static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2877 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2878 TRC_INTERNAL_LOOPBACK);
2883 static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2887 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2893 static int smctr_issue_write_byte_cmd(struct net_device *dev,
2894 short aword_cnt, void *byte)
2896 struct net_local *tp = netdev_priv(dev);
2897 unsigned int iword, ibyte;
2900 if((err = smctr_wait_while_cbusy(dev)))
2903 if((err = smctr_wait_cmd(dev)))
2906 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2907 iword++, ibyte += 2)
2909 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2910 | (*((__u8 *)byte + ibyte + 1));
2913 return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2917 static int smctr_issue_write_word_cmd(struct net_device *dev,
2918 short aword_cnt, void *word)
2920 struct net_local *tp = netdev_priv(dev);
2921 unsigned int i, err;
2923 if((err = smctr_wait_while_cbusy(dev)))
2926 if((err = smctr_wait_cmd(dev)))
2929 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2930 tp->misc_command_data[i] = *((__u16 *)word + i);
2932 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2938 static int smctr_join_complete_state(struct net_device *dev)
2942 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2943 JS_JOIN_COMPLETE_STATE);
2948 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2950 struct net_local *tp = netdev_priv(dev);
2955 for(i = 0; i < NUM_TX_QS_USED; i++)
2957 fcb = tp->tx_fcb_head[i];
2958 bdb = tp->tx_bdb_head[i];
2960 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2963 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2964 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2965 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2972 static int smctr_load_firmware(struct net_device *dev)
2974 struct net_local *tp = netdev_priv(dev);
2975 __u16 i, checksum = 0;
2978 if(smctr_debug > 10)
2979 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2981 tp->ptr_ucode = smctr_code;
2982 tp->num_of_tx_buffs = 4;
2983 tp->mode_bits |= UMAC;
2984 tp->receive_mask = 0;
2985 tp->max_packet_size = 4177;
2987 /* Can only upload the firmware once per adapter reset. */
2988 if(tp->microcode_version != 0)
2989 return (UCODE_PRESENT);
2991 /* Verify the firmware exists and is there in the right amount. */
2992 if((tp->ptr_ucode == 0L)
2993 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET) < UCODE_VERSION))
2995 return (UCODE_NOT_PRESENT);
2998 /* UCODE_SIZE is not included in Checksum. */
2999 for(i = 0; i < *((__u16 *)(tp->ptr_ucode + UCODE_SIZE_OFFSET)); i += 2)
3000 checksum += *((__u16 *)(tp->ptr_ucode + 2 + i));
3002 return (UCODE_NOT_PRESENT);
3004 /* At this point we have a valid firmware image, lets kick it on up. */
3005 smctr_enable_adapter_ram(dev);
3006 smctr_enable_16bit(dev);
3007 smctr_set_page(dev, (__u8 *)tp->ram_access);
3009 if((smctr_checksum_firmware(dev))
3010 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET)
3011 > tp->microcode_version))
3013 smctr_enable_adapter_ctrl_store(dev);
3015 /* Zero out ram space for firmware. */
3016 for(i = 0; i < CS_RAM_SIZE; i += 2)
3017 *((__u16 *)(tp->ram_access + i)) = 0;
3019 smctr_decode_firmware(dev);
3021 tp->microcode_version = *(tp->ptr_ucode + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
3022 = (tp->microcode_version << 8);
3023 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3024 = ~(tp->microcode_version << 8) + 1;
3026 smctr_disable_adapter_ctrl_store(dev);
3028 if(smctr_checksum_firmware(dev))
3029 err = HARDWARE_FAILED;
3032 err = UCODE_PRESENT;
3034 smctr_disable_16bit(dev);
3039 static int smctr_load_node_addr(struct net_device *dev)
3041 int ioaddr = dev->base_addr;
3045 for(i = 0; i < 6; i++)
3047 r = inb(ioaddr + LAR0 + i);
3048 dev->dev_addr[i] = (char)r;
3056 * During the transmission of the initial 1500 lobe media MAC frames,
3057 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3058 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3059 * microcode will not transmit any frames given to it by the host, and
3060 * will consequently cause a timeout.
3062 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
3063 * queues other then the one used for the lobe_media_test should be
3066 * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
3067 * has any multi-cast or promiscous bits set, the receive_mask needs to
3068 * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
3069 * run, and then the receive mask set back to its original value if the test
3072 static int smctr_lobe_media_test(struct net_device *dev)
3074 struct net_local *tp = netdev_priv(dev);
3075 unsigned int i, perror = 0;
3076 unsigned short saved_rcv_mask;
3078 if(smctr_debug > 10)
3079 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3081 /* Clear receive mask for lobe test. */
3082 saved_rcv_mask = tp->receive_mask;
3083 tp->receive_mask = 0;
3085 smctr_chg_rx_mask(dev);
3087 /* Setup the lobe media test. */
3088 smctr_lobe_media_test_cmd(dev);
3089 if(smctr_wait_cmd(dev))
3091 smctr_reset_adapter(dev);
3092 tp->status = CLOSED;
3093 return (LOBE_MEDIA_TEST_FAILED);
3096 /* Tx lobe media test frames. */
3097 for(i = 0; i < 1500; ++i)
3099 if(smctr_send_lobe_media_test(dev))
3103 smctr_reset_adapter(dev);
3105 return (LOBE_MEDIA_TEST_FAILED);
3110 if(smctr_lobe_media_test_cmd(dev))
3112 smctr_reset_adapter(dev);
3114 return (LOBE_MEDIA_TEST_FAILED);
3120 if(smctr_send_dat(dev))
3122 if(smctr_send_dat(dev))
3124 smctr_reset_adapter(dev);
3126 return (LOBE_MEDIA_TEST_FAILED);
3130 /* Check if any frames received during test. */
3131 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status)
3132 || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3134 smctr_reset_adapter(dev);
3136 return (LOBE_MEDIA_TEST_FAILED);
3139 /* Set receive mask to "Promisc" mode. */
3140 tp->receive_mask = saved_rcv_mask;
3142 smctr_chg_rx_mask(dev);
3147 static int smctr_lobe_media_test_cmd(struct net_device *dev)
3149 struct net_local *tp = netdev_priv(dev);
3152 if(smctr_debug > 10)
3153 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3155 /* Change to lobe media test state. */
3156 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3158 smctr_lobe_media_test_state(dev);
3159 if(smctr_wait_cmd(dev))
3161 printk(KERN_ERR "Lobe Failed test state\n");
3162 return (LOBE_MEDIA_TEST_FAILED);
3166 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3167 TRC_LOBE_MEDIA_TEST);
3172 static int smctr_lobe_media_test_state(struct net_device *dev)
3176 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3177 JS_LOBE_TEST_STATE);
3182 static int smctr_make_8025_hdr(struct net_device *dev,
3183 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3185 tmf->ac = MSB(ac_fc); /* msb is access control */
3186 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3188 tmf->sa[0] = dev->dev_addr[0];
3189 tmf->sa[1] = dev->dev_addr[1];
3190 tmf->sa[2] = dev->dev_addr[2];
3191 tmf->sa[3] = dev->dev_addr[3];
3192 tmf->sa[4] = dev->dev_addr[4];
3193 tmf->sa[5] = dev->dev_addr[5];
3197 /* Send RQ_INIT to RPS */
3207 /* Send RPT_TX_FORWARD to CRS */
3208 case RPT_TX_FORWARD:
3217 /* Everything else goes to sender */
3219 tmf->da[0] = rmf->sa[0];
3220 tmf->da[1] = rmf->sa[1];
3221 tmf->da[2] = rmf->sa[2];
3222 tmf->da[3] = rmf->sa[3];
3223 tmf->da[4] = rmf->sa[4];
3224 tmf->da[5] = rmf->sa[5];
3231 static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3233 struct net_local *tp = netdev_priv(dev);
3235 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3236 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3238 tsv->svv[0] = MSB(tp->authorized_access_priority);
3239 tsv->svv[1] = LSB(tp->authorized_access_priority);
3244 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3246 tsv->svi = ADDRESS_MODIFER;
3247 tsv->svl = S_ADDRESS_MODIFER;
3255 static int smctr_make_auth_funct_class(struct net_device *dev,
3256 MAC_SUB_VECTOR *tsv)
3258 struct net_local *tp = netdev_priv(dev);
3260 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3261 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3263 tsv->svv[0] = MSB(tp->authorized_function_classes);
3264 tsv->svv[1] = LSB(tp->authorized_function_classes);
3269 static int smctr_make_corr(struct net_device *dev,
3270 MAC_SUB_VECTOR *tsv, __u16 correlator)
3272 tsv->svi = CORRELATOR;
3273 tsv->svl = S_CORRELATOR;
3275 tsv->svv[0] = MSB(correlator);
3276 tsv->svv[1] = LSB(correlator);
3281 static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3283 struct net_local *tp = netdev_priv(dev);
3285 smctr_get_functional_address(dev);
3287 tsv->svi = FUNCTIONAL_ADDRESS;
3288 tsv->svl = S_FUNCTIONAL_ADDRESS;
3290 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3291 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3293 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3294 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3299 static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3301 struct net_local *tp = netdev_priv(dev);
3303 smctr_get_group_address(dev);
3305 tsv->svi = GROUP_ADDRESS;
3306 tsv->svl = S_GROUP_ADDRESS;
3308 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3309 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3311 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3312 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3314 /* Set Group Address Sub-vector to all zeros if only the
3315 * Group Address/Functional Address Indicator is set.
3317 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00
3318 && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3324 static int smctr_make_phy_drop_num(struct net_device *dev,
3325 MAC_SUB_VECTOR *tsv)
3327 struct net_local *tp = netdev_priv(dev);
3329 smctr_get_physical_drop_number(dev);
3331 tsv->svi = PHYSICAL_DROP;
3332 tsv->svl = S_PHYSICAL_DROP;
3334 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3335 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3337 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3338 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3343 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3347 tsv->svi = PRODUCT_INSTANCE_ID;
3348 tsv->svl = S_PRODUCT_INSTANCE_ID;
3350 for(i = 0; i < 18; i++)
3356 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3358 struct net_local *tp = netdev_priv(dev);
3360 smctr_get_station_id(dev);
3362 tsv->svi = STATION_IDENTIFER;
3363 tsv->svl = S_STATION_IDENTIFER;
3365 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3366 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3368 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3369 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3371 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3372 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3377 static int smctr_make_ring_station_status(struct net_device *dev,
3378 MAC_SUB_VECTOR * tsv)
3380 tsv->svi = RING_STATION_STATUS;
3381 tsv->svl = S_RING_STATION_STATUS;
3393 static int smctr_make_ring_station_version(struct net_device *dev,
3394 MAC_SUB_VECTOR *tsv)
3396 struct net_local *tp = netdev_priv(dev);
3398 tsv->svi = RING_STATION_VERSION_NUMBER;
3399 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3401 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3402 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3403 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3404 tsv->svv[3] = 0x40; /* EBCDIC - */
3405 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3406 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3407 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3408 tsv->svv[7] = 0x40; /* EBCDIC - */
3409 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3411 if(tp->extra_info & CHIP_REV_MASK)
3412 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3414 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3419 static int smctr_make_tx_status_code(struct net_device *dev,
3420 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3422 tsv->svi = TRANSMIT_STATUS_CODE;
3423 tsv->svl = S_TRANSMIT_STATUS_CODE;
3425 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) || IBM_PASS_SOURCE_ADDR);
3427 /* Stripped frame status of Transmitted Frame */
3428 tsv->svv[1] = tx_fstatus & 0xff;
3433 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3434 MAC_SUB_VECTOR *tsv)
3436 struct net_local *tp = netdev_priv(dev);
3438 smctr_get_upstream_neighbor_addr(dev);
3440 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3441 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3443 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3444 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3446 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3447 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3449 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3450 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3455 static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3457 tsv->svi = WRAP_DATA;
3458 tsv->svl = S_WRAP_DATA;
3464 * Open/initialize the board. This is called sometime after
3465 * booting when the 'ifconfig' program is run.
3467 * This routine should set everything up anew at each open, even
3468 * registers that "should" only need to be set once at boot, so that
3469 * there is non-reboot way to recover if something goes wrong.
3471 static int smctr_open(struct net_device *dev)
3475 if(smctr_debug > 10)
3476 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3478 err = smctr_init_adapter(dev);
3485 /* Interrupt driven open of Token card. */
3486 static int smctr_open_tr(struct net_device *dev)
3488 struct net_local *tp = netdev_priv(dev);
3489 unsigned long flags;
3492 if(smctr_debug > 10)
3493 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3495 /* Now we can actually open the adapter. */
3496 if(tp->status == OPEN)
3498 if(tp->status != INITIALIZED)
3501 /* FIXME: it would work a lot better if we masked the irq sources
3502 on the card here, then we could skip the locking and poll nicely */
3503 spin_lock_irqsave(&tp->lock, flags);
3505 smctr_set_page(dev, (__u8 *)tp->ram_access);
3507 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3510 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3513 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3516 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3519 tp->status = CLOSED;
3521 /* Insert into the Ring or Enter Loopback Mode. */
3522 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3524 tp->status = CLOSED;
3526 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3528 if(!(err = smctr_wait_cmd(dev)))
3532 smctr_status_chg(dev);
3536 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3538 tp->status = CLOSED;
3539 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3541 if(!(err = smctr_wait_cmd(dev)))
3545 smctr_status_chg(dev);
3549 if((tp->mode_bits & LOOPING_MODE_MASK)
3552 tp->status = CLOSED;
3553 if(!(err = smctr_lobe_media_test_cmd(dev)))
3555 if(!(err = smctr_wait_cmd(dev)))
3558 smctr_status_chg(dev);
3562 if(!(err = smctr_lobe_media_test(dev)))
3563 err = smctr_issue_insert_cmd(dev);
3566 if(err == LOBE_MEDIA_TEST_FAILED)
3567 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3574 spin_unlock_irqrestore(&tp->lock, flags);
3579 /* Check for a network adapter of this type,
3580 * and return device structure if one exists.
3582 struct net_device __init *smctr_probe(int unit)
3584 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3585 static const unsigned ports[] = {
3586 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3587 0x320, 0x340, 0x360, 0x380, 0
3589 const unsigned *port;
3593 return ERR_PTR(-ENOMEM);
3595 SET_MODULE_OWNER(dev);
3598 sprintf(dev->name, "tr%d", unit);
3599 netdev_boot_setup_check(dev);
3602 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3603 err = smctr_probe1(dev, dev->base_addr);
3604 else if(dev->base_addr != 0) /* Don't probe at all. */
3607 for (port = ports; *port; port++) {
3608 err = smctr_probe1(dev, *port);
3615 err = register_netdev(dev);
3620 #ifdef CONFIG_MCA_LEGACY
3621 { struct net_local *tp = netdev_priv(dev);
3623 mca_mark_as_unused(tp->slot_num);
3626 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3627 free_irq(dev->irq, dev);
3630 return ERR_PTR(err);
3634 static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3636 static unsigned version_printed;
3637 struct net_local *tp = netdev_priv(dev);
3641 if(smctr_debug && version_printed++ == 0)
3644 spin_lock_init(&tp->lock);
3645 dev->base_addr = ioaddr;
3647 /* Actually detect an adapter now. */
3648 err = smctr_chk_isa(dev);
3651 if ((err = smctr_chk_mca(dev)) < 0) {
3657 tp = netdev_priv(dev);
3658 dev->mem_start = tp->ram_base;
3659 dev->mem_end = dev->mem_start + 0x10000;
3660 ram = (__u32 *)phys_to_virt(dev->mem_start);
3661 tp->ram_access = *(__u32 *)&ram;
3662 tp->status = NOT_INITIALIZED;
3664 err = smctr_load_firmware(dev);
3665 if(err != UCODE_PRESENT && err != SUCCESS)
3667 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3672 /* Allow user to specify ring speed on module insert. */
3674 tp->media_type = MEDIA_UTP_4;
3676 tp->media_type = MEDIA_UTP_16;
3678 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3679 dev->name, smctr_name, smctr_model,
3680 (unsigned int)dev->base_addr,
3681 dev->irq, tp->rom_base, tp->ram_base);
3683 dev->open = smctr_open;
3684 dev->stop = smctr_close;
3685 dev->hard_start_xmit = smctr_send_packet;
3686 dev->tx_timeout = smctr_timeout;
3687 dev->watchdog_timeo = HZ;
3688 dev->get_stats = smctr_get_stats;
3689 dev->set_multicast_list = &smctr_set_multicast_list;
3696 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3697 struct net_device *dev, __u16 rx_status)
3699 struct net_local *tp = netdev_priv(dev);
3700 struct sk_buff *skb;
3701 __u16 rcode, correlator;
3706 rmf->vl = SWAP_BYTES(rmf->vl);
3707 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3711 /* Received MAC Frames Processed by RS. */
3713 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3718 if((err = smctr_send_rsp(dev, rmf, rcode,
3726 if((rcode = smctr_rcv_chg_param(dev, rmf,
3727 &correlator)) ==HARDWARE_FAILED)
3732 if((err = smctr_send_rsp(dev, rmf, rcode,
3740 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3741 rmf, &correlator)) != POSITIVE_ACK)
3743 if(rcode == HARDWARE_FAILED)
3746 return (smctr_send_rsp(dev, rmf,
3747 rcode, correlator));
3750 if((err = smctr_send_rpt_addr(dev, rmf,
3758 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3759 rmf, &correlator)) != POSITIVE_ACK)
3761 if(rcode == HARDWARE_FAILED)
3764 return (smctr_send_rsp(dev, rmf,
3769 if((err = smctr_send_rpt_attch(dev, rmf,
3777 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3778 rmf, &correlator)) != POSITIVE_ACK)
3780 if(rcode == HARDWARE_FAILED)
3783 return (smctr_send_rsp(dev, rmf,
3788 if((err = smctr_send_rpt_state(dev, rmf,
3796 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3799 if(rcode == HARDWARE_FAILED)
3802 return (smctr_send_rsp(dev, rmf,
3807 if((err = smctr_send_tx_forward(dev, rmf,
3808 &tx_fstatus)) == HARDWARE_FAILED)
3813 if(err == A_FRAME_WAS_FORWARDED)
3815 if((err = smctr_send_rpt_tx_forward(dev,
3824 /* Received MAC Frames Processed by CRS/REM/RPS. */
3829 case RPT_ACTIVE_ERR:
3837 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3840 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3842 rcode = smctr_rcv_unknown(dev, rmf,
3844 if((err = smctr_send_rsp(dev, rmf,rcode,
3856 /* 1. DA doesn't match (Promiscuous Mode).
3857 * 2. Parse for Extended MAC Frame Type.
3875 case RPT_ACTIVE_ERR:
3884 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3885 * ACCEPT_ATT_MAC_FRAMES is set.
3887 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
3888 && (xframe == (__u8)0))
3889 || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES)
3890 && (xframe == (__u8)1)))
3892 rmf->vl = SWAP_BYTES(rmf->vl);
3894 if (!(skb = dev_alloc_skb(size)))
3898 /* Slide data into a sleek skb. */
3899 skb_put(skb, skb->len);
3900 memcpy(skb->data, rmf, skb->len);
3902 /* Update Counters */
3903 tp->MacStat.rx_packets++;
3904 tp->MacStat.rx_bytes += skb->len;
3906 /* Kick the packet on up. */
3908 skb->protocol = tr_type_trans(skb, dev);
3910 dev->last_rx = jiffies;
3917 /* Adapter RAM test. Incremental word ODD boundary data test. */
3918 static int smctr_ram_memory_test(struct net_device *dev)
3920 struct net_local *tp = netdev_priv(dev);
3921 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3922 word_read = 0, err_word = 0, err_pattern = 0;
3923 unsigned int err_offset;
3927 if(smctr_debug > 10)
3928 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3930 start_pattern = 0x0001;
3931 pages_of_ram = tp->ram_size / tp->ram_usable;
3932 pword = tp->ram_access;
3934 /* Incremental word ODD boundary test. */
3935 for(page = 0; (page < pages_of_ram) && (~err);
3936 page++, start_pattern += 0x8000)
3938 smctr_set_page(dev, (__u8 *)(tp->ram_access
3939 + (page * tp->ram_usable * 1024) + 1));
3940 word_pattern = start_pattern;
3942 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3943 *(__u16 *)(pword + j) = word_pattern++;
3945 word_pattern = start_pattern;
3947 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1
3948 && (~err); j += 2, word_pattern++)
3950 word_read = *(__u16 *)(pword + j);
3951 if(word_read != word_pattern)
3955 err_word = word_read;
3956 err_pattern = word_pattern;
3957 return (RAM_TEST_FAILED);
3962 /* Zero out memory. */
3963 for(page = 0; page < pages_of_ram && (~err); page++)
3965 smctr_set_page(dev, (__u8 *)(tp->ram_access
3966 + (page * tp->ram_usable * 1024)));
3969 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3970 *(__u16 *)(pword + j) = word_pattern;
3972 for(j =0; j < (__u32)tp->ram_usable * 1024
3975 word_read = *(__u16 *)(pword + j);
3976 if(word_read != word_pattern)
3980 err_word = word_read;
3981 err_pattern = word_pattern;
3982 return (RAM_TEST_FAILED);
3987 smctr_set_page(dev, (__u8 *)tp->ram_access);
3992 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3995 MAC_SUB_VECTOR *rsv;
3997 __u16 rcode = POSITIVE_ACK;
3998 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4000 /* This Frame can only come from a CRS */
4001 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4002 return(E_INAPPROPRIATE_SOURCE_CLASS);
4004 /* Remove MVID Length from total length. */
4005 vlen = (signed short)rmf->vl - 4;
4007 /* Point to First SVID */
4008 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4010 /* Search for Appropriate SVID's. */
4011 while((vlen > 0) && (rcode == POSITIVE_ACK))
4016 svectors |= F_CORRELATOR;
4017 rcode = smctr_set_corr(dev, rsv, correlator);
4020 case LOCAL_RING_NUMBER:
4021 svectors |= F_LOCAL_RING_NUMBER;
4022 rcode = smctr_set_local_ring_num(dev, rsv);
4025 case ASSIGN_PHYSICAL_DROP:
4026 svectors |= F_ASSIGN_PHYSICAL_DROP;
4027 rcode = smctr_set_phy_drop(dev, rsv);
4030 case ERROR_TIMER_VALUE:
4031 svectors |= F_ERROR_TIMER_VALUE;
4032 rcode = smctr_set_error_timer_value(dev, rsv);
4035 case AUTHORIZED_FUNCTION_CLASS:
4036 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4037 rcode = smctr_set_auth_funct_class(dev, rsv);
4040 case AUTHORIZED_ACCESS_PRIORITY:
4041 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4042 rcode = smctr_set_auth_access_pri(dev, rsv);
4046 rcode = E_SUB_VECTOR_UNKNOWN;
4050 /* Let Sender Know if SUM of SV length's is
4051 * larger then length in MVID length field
4053 if((vlen -= rsv->svl) < 0)
4054 rcode = E_VECTOR_LENGTH_ERROR;
4056 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4059 if(rcode == POSITIVE_ACK)
4061 /* Let Sender Know if MVID length field
4062 * is larger then SUM of SV length's
4065 rcode = E_VECTOR_LENGTH_ERROR;
4068 /* Let Sender Know if Expected SVID Missing */
4069 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4070 rcode = E_MISSING_SUB_VECTOR;
4077 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4080 MAC_SUB_VECTOR *rsv;
4082 __u16 rcode = POSITIVE_ACK;
4083 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4085 /* This Frame can only come from a RPS */
4086 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4087 return (E_INAPPROPRIATE_SOURCE_CLASS);
4089 /* Remove MVID Length from total length. */
4090 vlen = (signed short)rmf->vl - 4;
4092 /* Point to First SVID */
4093 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4095 /* Search for Appropriate SVID's */
4096 while((vlen > 0) && (rcode == POSITIVE_ACK))
4101 svectors |= F_CORRELATOR;
4102 rcode = smctr_set_corr(dev, rsv, correlator);
4105 case LOCAL_RING_NUMBER:
4106 svectors |= F_LOCAL_RING_NUMBER;
4107 rcode = smctr_set_local_ring_num(dev, rsv);
4110 case ASSIGN_PHYSICAL_DROP:
4111 svectors |= F_ASSIGN_PHYSICAL_DROP;
4112 rcode = smctr_set_phy_drop(dev, rsv);
4115 case ERROR_TIMER_VALUE:
4116 svectors |= F_ERROR_TIMER_VALUE;
4117 rcode = smctr_set_error_timer_value(dev, rsv);
4121 rcode = E_SUB_VECTOR_UNKNOWN;
4125 /* Let Sender Know if SUM of SV length's is
4126 * larger then length in MVID length field
4128 if((vlen -= rsv->svl) < 0)
4129 rcode = E_VECTOR_LENGTH_ERROR;
4131 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4134 if(rcode == POSITIVE_ACK)
4136 /* Let Sender Know if MVID length field
4137 * is larger then SUM of SV length's
4140 rcode = E_VECTOR_LENGTH_ERROR;
4143 /* Let Sender Know if Expected SV Missing */
4144 if((svectors & R_INIT) ^ R_INIT)
4145 rcode = E_MISSING_SUB_VECTOR;
4152 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4154 MAC_SUB_VECTOR *rsv;
4156 __u16 rcode = POSITIVE_ACK;
4157 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4159 /* This Frame can only come from a CRS */
4160 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4161 return (E_INAPPROPRIATE_SOURCE_CLASS);
4163 /* Remove MVID Length from total length */
4164 vlen = (signed short)rmf->vl - 4;
4166 /* Point to First SVID */
4167 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4169 /* Search for Appropriate SVID's */
4170 while((vlen > 0) && (rcode == POSITIVE_ACK))
4175 svectors |= F_FRAME_FORWARD;
4176 rcode = smctr_set_frame_forward(dev, rsv,
4181 rcode = E_SUB_VECTOR_UNKNOWN;
4185 /* Let Sender Know if SUM of SV length's is
4186 * larger then length in MVID length field
4188 if((vlen -= rsv->svl) < 0)
4189 rcode = E_VECTOR_LENGTH_ERROR;
4191 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4194 if(rcode == POSITIVE_ACK)
4196 /* Let Sender Know if MVID length field
4197 * is larger then SUM of SV length's
4200 rcode = E_VECTOR_LENGTH_ERROR;
4203 /* Let Sender Know if Expected SV Missing */
4204 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4205 rcode = E_MISSING_SUB_VECTOR;
4212 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4213 MAC_HEADER *rmf, __u16 *correlator)
4215 MAC_SUB_VECTOR *rsv;
4217 __u16 rcode = POSITIVE_ACK;
4218 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4220 /* Remove MVID Length from total length */
4221 vlen = (signed short)rmf->vl - 4;
4223 /* Point to First SVID */
4224 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4226 /* Search for Appropriate SVID's */
4227 while((vlen > 0) && (rcode == POSITIVE_ACK))
4232 svectors |= F_CORRELATOR;
4233 rcode = smctr_set_corr(dev, rsv, correlator);
4237 rcode = E_SUB_VECTOR_UNKNOWN;
4241 /* Let Sender Know if SUM of SV length's is
4242 * larger then length in MVID length field
4244 if((vlen -= rsv->svl) < 0)
4245 rcode = E_VECTOR_LENGTH_ERROR;
4247 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4250 if(rcode == POSITIVE_ACK)
4252 /* Let Sender Know if MVID length field
4253 * is larger then SUM of SV length's
4256 rcode = E_VECTOR_LENGTH_ERROR;
4259 /* Let Sender Know if Expected SVID Missing */
4260 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4261 ^ R_RQ_ATTCH_STATE_ADDR)
4262 rcode = E_MISSING_SUB_VECTOR;
4269 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4272 MAC_SUB_VECTOR *rsv;
4277 /* Remove MVID Length from total length */
4278 vlen = (signed short)rmf->vl - 4;
4280 /* Point to First SVID */
4281 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4283 /* Search for CORRELATOR for RSP to UNKNOWN */
4284 while((vlen > 0) && (*correlator == 0))
4289 smctr_set_corr(dev, rsv, correlator);
4297 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4300 return (E_UNRECOGNIZED_VECTOR_ID);
4304 * Reset the 825 NIC and exit w:
4305 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4311 static int smctr_reset_adapter(struct net_device *dev)
4313 struct net_local *tp = netdev_priv(dev);
4314 int ioaddr = dev->base_addr;
4316 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4317 mdelay(200); /* ~2 ms */
4319 smctr_clear_trc_reset(ioaddr);
4320 mdelay(200); /* ~2 ms */
4322 /* Remove any latched interrupts that occurred prior to reseting the
4323 * adapter or possibily caused by line glitches due to the reset.
4325 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4330 static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4332 struct net_local *tp = netdev_priv(dev);
4335 if(smctr_debug > 10)
4336 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4338 if(tp->num_tx_fcbs_used[queue] != 0
4339 && tp->tx_queue_status[queue] == NOT_TRANSMITING)
4341 tp->tx_queue_status[queue] = TRANSMITING;
4342 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4348 static int smctr_ring_status_chg(struct net_device *dev)
4350 struct net_local *tp = netdev_priv(dev);
4352 if(smctr_debug > 10)
4353 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4355 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4356 * Bit is set, check value of monitor_state, only then we
4357 * enable and start transmit/receive timeout (if and only
4358 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4360 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4362 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE)
4363 || (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4365 tp->monitor_state_ready = 1;
4369 /* if adapter is NOT in either active monitor
4370 * or standby monitor state => Disable
4371 * transmit/receive timeout.
4373 tp->monitor_state_ready = 0;
4375 /* Ring speed problem, switching to auto mode. */
4376 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE
4379 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4381 smctr_set_ring_speed(dev);
4386 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4389 switch(tp->ring_status)
4392 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
4393 tp->current_ring_status |= RING_RECOVERY;
4396 case SINGLE_STATION:
4397 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
4398 tp->current_ring_status |= SINGLE_STATION;
4401 case COUNTER_OVERFLOW:
4402 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
4403 tp->current_ring_status |= COUNTER_OVERFLOW;
4406 case REMOVE_RECEIVED:
4407 printk(KERN_INFO "%s: Remove Received\n", dev->name);
4408 tp->current_ring_status |= REMOVE_RECEIVED;
4411 case AUTO_REMOVAL_ERROR:
4412 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
4413 tp->current_ring_status |= AUTO_REMOVAL_ERROR;
4416 case LOBE_WIRE_FAULT:
4417 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
4418 tp->current_ring_status |= LOBE_WIRE_FAULT;
4421 case TRANSMIT_BEACON:
4422 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
4423 tp->current_ring_status |= TRANSMIT_BEACON;
4427 printk(KERN_INFO "%s: Soft Error\n", dev->name);
4428 tp->current_ring_status |= SOFT_ERROR;
4432 printk(KERN_INFO "%s: Hard Error\n", dev->name);
4433 tp->current_ring_status |= HARD_ERROR;
4437 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
4438 tp->current_ring_status |= SIGNAL_LOSS;
4442 printk(KERN_INFO "%s: Unknown ring status change\n",
4450 static int smctr_rx_frame(struct net_device *dev)
4452 struct net_local *tp = netdev_priv(dev);
4453 __u16 queue, status, rx_size, err = 0;
4456 if(smctr_debug > 10)
4457 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4459 queue = tp->receive_queue_number;
4461 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4463 err = HARDWARE_FAILED;
4465 if(((status & 0x007f) == 0)
4466 || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4468 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4469 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4471 pbuff = smctr_get_rx_pointer(dev, queue);
4473 smctr_set_page(dev, pbuff);
4474 smctr_disable_16bit(dev);
4476 /* pbuff points to addr within one page */
4477 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4479 if(queue == NON_MAC_QUEUE)
4481 struct sk_buff *skb;
4483 skb = dev_alloc_skb(rx_size);
4485 skb_put(skb, rx_size);
4487 memcpy(skb->data, pbuff, rx_size);
4489 /* Update Counters */
4490 tp->MacStat.rx_packets++;
4491 tp->MacStat.rx_bytes += skb->len;
4493 /* Kick the packet on up. */
4495 skb->protocol = tr_type_trans(skb, dev);
4497 dev->last_rx = jiffies;
4502 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4503 rx_size, dev, status);
4506 smctr_enable_16bit(dev);
4507 smctr_set_page(dev, (__u8 *)tp->ram_access);
4508 smctr_update_rx_chain(dev, queue);
4517 static int smctr_send_dat(struct net_device *dev)
4519 struct net_local *tp = netdev_priv(dev);
4520 unsigned int i, err;
4524 if(smctr_debug > 10)
4525 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4527 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4528 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4530 return (OUT_OF_RESOURCES);
4533 /* Initialize DAT Data Fields. */
4534 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4535 tmf->ac = MSB(AC_FC_DAT);
4536 tmf->fc = LSB(AC_FC_DAT);
4538 for(i = 0; i < 6; i++)
4540 tmf->sa[i] = dev->dev_addr[i];
4541 tmf->da[i] = dev->dev_addr[i];
4546 tmf->dc_sc = DC_RS | SC_RS;
4548 tmf->vl = SWAP_BYTES(tmf->vl);
4550 /* Start Transmit. */
4551 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4554 /* Wait for Transmit to Complete */
4555 for(i = 0; i < 10000; i++)
4557 if(fcb->frame_status & FCB_COMMAND_DONE)
4562 /* Check if GOOD frame Tx'ed. */
4563 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4564 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4566 return (INITIALIZE_FAILED);
4569 /* De-allocated Tx FCB and Frame Buffer
4570 * The FCB must be de-allocated manually if executing with
4571 * interrupts disabled, other wise the ISR (LM_Service_Events)
4572 * will de-allocate it when the interrupt occurs.
4574 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4575 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4580 static void smctr_timeout(struct net_device *dev)
4583 * If we get here, some higher level has decided we are broken.
4584 * There should really be a "kick me" function call instead.
4586 * Resetting the token ring adapter takes a long time so just
4587 * fake transmission time and go on trying. Our own timeout
4588 * routine is in sktr_timer_chk()
4590 dev->trans_start = jiffies;
4591 netif_wake_queue(dev);
4595 * Gets skb from system, queues it and checks if it can be sent
4597 static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
4599 struct net_local *tp = netdev_priv(dev);
4601 if(smctr_debug > 10)
4602 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4605 * Block a transmit overlap
4608 netif_stop_queue(dev);
4610 if(tp->QueueSkb == 0)
4611 return (1); /* Return with tbusy set: queue full */
4614 skb_queue_tail(&tp->SendSkbQueue, skb);
4615 smctr_hardware_send_packet(dev, tp);
4616 if(tp->QueueSkb > 0)
4617 netif_wake_queue(dev);
4622 static int smctr_send_lobe_media_test(struct net_device *dev)
4624 struct net_local *tp = netdev_priv(dev);
4625 MAC_SUB_VECTOR *tsv;
4631 if(smctr_debug > 15)
4632 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4634 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4635 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4637 return (OUT_OF_RESOURCES);
4640 /* Initialize DAT Data Fields. */
4641 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4642 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4643 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4645 for(i = 0; i < 6; i++)
4648 tmf->sa[i] = dev->dev_addr[i];
4651 tmf->vc = LOBE_MEDIA_TEST;
4652 tmf->dc_sc = DC_RS | SC_RS;
4655 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4656 smctr_make_wrap_data(dev, tsv);
4657 tmf->vl += tsv->svl;
4659 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4660 smctr_make_wrap_data(dev, tsv);
4661 tmf->vl += tsv->svl;
4663 /* Start Transmit. */
4664 tmf->vl = SWAP_BYTES(tmf->vl);
4665 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4668 /* Wait for Transmit to Complete. (10 ms). */
4669 for(i=0; i < 10000; i++)
4671 if(fcb->frame_status & FCB_COMMAND_DONE)
4676 /* Check if GOOD frame Tx'ed */
4677 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4678 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4680 return (LOBE_MEDIA_TEST_FAILED);
4683 /* De-allocated Tx FCB and Frame Buffer
4684 * The FCB must be de-allocated manually if executing with
4685 * interrupts disabled, other wise the ISR (LM_Service_Events)
4686 * will de-allocate it when the interrupt occurs.
4688 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4689 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4694 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4698 MAC_SUB_VECTOR *tsv;
4701 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4702 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4703 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4704 == (FCBlock *)(-1L))
4709 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4711 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4714 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4716 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4717 smctr_make_corr(dev, tsv, correlator);
4719 tmf->vl += tsv->svl;
4720 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4721 smctr_make_phy_drop_num(dev, tsv);
4723 tmf->vl += tsv->svl;
4724 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4725 smctr_make_upstream_neighbor_addr(dev, tsv);
4727 tmf->vl += tsv->svl;
4728 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4729 smctr_make_addr_mod(dev, tsv);
4731 tmf->vl += tsv->svl;
4732 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4733 smctr_make_group_addr(dev, tsv);
4735 tmf->vl += tsv->svl;
4736 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4737 smctr_make_funct_addr(dev, tsv);
4739 tmf->vl += tsv->svl;
4741 /* Subtract out MVID and MVL which is
4742 * include in both vl and MAC_HEADER
4744 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4745 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4747 tmf->vl = SWAP_BYTES(tmf->vl);
4749 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4752 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4756 MAC_SUB_VECTOR *tsv;
4759 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4760 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4761 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4762 == (FCBlock *)(-1L))
4767 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4768 tmf->vc = RPT_ATTCH;
4769 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4772 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4774 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4775 smctr_make_corr(dev, tsv, correlator);
4777 tmf->vl += tsv->svl;
4778 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4779 smctr_make_product_id(dev, tsv);
4781 tmf->vl += tsv->svl;
4782 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4783 smctr_make_funct_addr(dev, tsv);
4785 tmf->vl += tsv->svl;
4786 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4787 smctr_make_auth_funct_class(dev, tsv);
4789 tmf->vl += tsv->svl;
4790 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4791 smctr_make_access_pri(dev, tsv);
4793 tmf->vl += tsv->svl;
4795 /* Subtract out MVID and MVL which is
4796 * include in both vl and MAC_HEADER
4798 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4799 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4801 tmf->vl = SWAP_BYTES(tmf->vl);
4803 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4806 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4810 MAC_SUB_VECTOR *tsv;
4813 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4814 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4815 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4816 == (FCBlock *)(-1L))
4821 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4822 tmf->vc = RPT_STATE;
4823 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4826 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4828 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4829 smctr_make_corr(dev, tsv, correlator);
4831 tmf->vl += tsv->svl;
4832 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4833 smctr_make_ring_station_version(dev, tsv);
4835 tmf->vl += tsv->svl;
4836 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4837 smctr_make_ring_station_status(dev, tsv);
4839 tmf->vl += tsv->svl;
4840 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4841 smctr_make_station_id(dev, tsv);
4843 tmf->vl += tsv->svl;
4845 /* Subtract out MVID and MVL which is
4846 * include in both vl and MAC_HEADER
4848 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4849 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4851 tmf->vl = SWAP_BYTES(tmf->vl);
4853 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4856 static int smctr_send_rpt_tx_forward(struct net_device *dev,
4857 MAC_HEADER *rmf, __u16 tx_fstatus)
4860 MAC_SUB_VECTOR *tsv;
4863 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4864 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4869 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4870 tmf->vc = RPT_TX_FORWARD;
4871 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4874 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4876 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4877 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4879 tmf->vl += tsv->svl;
4881 /* Subtract out MVID and MVL which is
4882 * include in both vl and MAC_HEADER
4884 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4885 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4887 tmf->vl = SWAP_BYTES(tmf->vl);
4889 return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4892 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4893 __u16 rcode, __u16 correlator)
4896 MAC_SUB_VECTOR *tsv;
4899 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4900 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4905 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4907 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4910 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4912 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4913 smctr_make_corr(dev, tsv, correlator);
4918 static int smctr_send_rq_init(struct net_device *dev)
4920 struct net_local *tp = netdev_priv(dev);
4922 MAC_SUB_VECTOR *tsv;
4924 unsigned int i, count = 0;
4929 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4930 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4931 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4932 == (FCBlock *)(-1L)))
4937 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4939 tmf->dc_sc = DC_RPS | SC_RS;
4942 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4944 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4945 smctr_make_product_id(dev, tsv);
4947 tmf->vl += tsv->svl;
4948 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4949 smctr_make_upstream_neighbor_addr(dev, tsv);
4951 tmf->vl += tsv->svl;
4952 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4953 smctr_make_ring_station_version(dev, tsv);
4955 tmf->vl += tsv->svl;
4956 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4957 smctr_make_addr_mod(dev, tsv);
4959 tmf->vl += tsv->svl;
4961 /* Subtract out MVID and MVL which is
4962 * include in both vl and MAC_HEADER
4964 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4965 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4967 tmf->vl = SWAP_BYTES(tmf->vl);
4969 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4972 /* Wait for Transmit to Complete */
4973 for(i = 0; i < 10000; i++)
4975 if(fcb->frame_status & FCB_COMMAND_DONE)
4980 /* Check if GOOD frame Tx'ed */
4981 fstatus = fcb->frame_status;
4983 if(!(fstatus & FCB_COMMAND_DONE))
4984 return (HARDWARE_FAILED);
4986 if(!(fstatus & FCB_TX_STATUS_E))
4989 /* De-allocated Tx FCB and Frame Buffer
4990 * The FCB must be de-allocated manually if executing with
4991 * interrupts disabled, other wise the ISR (LM_Service_Events)
4992 * will de-allocate it when the interrupt occurs.
4994 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4995 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4996 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4998 return (smctr_join_complete_state(dev));
5001 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
5004 struct net_local *tp = netdev_priv(dev);
5009 /* Check if this is the END POINT of the Transmit Forward Chain. */
5013 /* Allocate Transmit FCB only by requesting 0 bytes
5016 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
5019 /* Set pointer to Transmit Frame Buffer to the data
5020 * portion of the received TX Forward frame, making
5021 * sure to skip over the Vector Code (vc) and Vector
5024 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5025 + sizeof(MAC_HEADER) + 2);
5026 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5027 + sizeof(MAC_HEADER) + 2);
5029 fcb->frame_length = rmf->vl - 4 - 2;
5030 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5032 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5035 /* Wait for Transmit to Complete */
5036 for(i = 0; i < 10000; i++)
5038 if(fcb->frame_status & FCB_COMMAND_DONE)
5043 /* Check if GOOD frame Tx'ed */
5044 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5046 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5049 for(i = 0; i < 10000; i++)
5051 if(fcb->frame_status & FCB_COMMAND_DONE)
5056 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5057 return (HARDWARE_FAILED);
5060 *tx_fstatus = fcb->frame_status;
5062 return (A_FRAME_WAS_FORWARDED);
5065 static int smctr_set_auth_access_pri(struct net_device *dev,
5066 MAC_SUB_VECTOR *rsv)
5068 struct net_local *tp = netdev_priv(dev);
5070 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5071 return (E_SUB_VECTOR_LENGTH_ERROR);
5073 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5075 return (POSITIVE_ACK);
5078 static int smctr_set_auth_funct_class(struct net_device *dev,
5079 MAC_SUB_VECTOR *rsv)
5081 struct net_local *tp = netdev_priv(dev);
5083 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5084 return (E_SUB_VECTOR_LENGTH_ERROR);
5086 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5088 return (POSITIVE_ACK);
5091 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5094 if(rsv->svl != S_CORRELATOR)
5095 return (E_SUB_VECTOR_LENGTH_ERROR);
5097 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5099 return (POSITIVE_ACK);
5102 static int smctr_set_error_timer_value(struct net_device *dev,
5103 MAC_SUB_VECTOR *rsv)
5108 if(rsv->svl != S_ERROR_TIMER_VALUE)
5109 return (E_SUB_VECTOR_LENGTH_ERROR);
5111 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5113 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5115 if((err = smctr_wait_cmd(dev)))
5118 return (POSITIVE_ACK);
5121 static int smctr_set_frame_forward(struct net_device *dev,
5122 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5124 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5125 return (E_SUB_VECTOR_LENGTH_ERROR);
5127 if((dc_sc & DC_MASK) != DC_CRS)
5129 if(rsv->svl >= 2 && rsv->svl < 20)
5130 return (E_TRANSMIT_FORWARD_INVALID);
5132 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5133 return (E_TRANSMIT_FORWARD_INVALID);
5136 return (POSITIVE_ACK);
5139 static int smctr_set_local_ring_num(struct net_device *dev,
5140 MAC_SUB_VECTOR *rsv)
5142 struct net_local *tp = netdev_priv(dev);
5144 if(rsv->svl != S_LOCAL_RING_NUMBER)
5145 return (E_SUB_VECTOR_LENGTH_ERROR);
5147 if(tp->ptr_local_ring_num)
5148 *(__u16 *)(tp->ptr_local_ring_num)
5149 = (rsv->svv[0] << 8 | rsv->svv[1]);
5151 return (POSITIVE_ACK);
5154 static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5156 struct net_local *tp = netdev_priv(dev);
5157 int ioaddr = dev->base_addr;
5159 if(tp->bic_type == BIC_585_CHIP)
5160 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5163 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5164 outb(tp->trc_mask, ioaddr + CSR);
5170 static void smctr_set_multicast_list(struct net_device *dev)
5172 if(smctr_debug > 10)
5173 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5178 static int smctr_set_page(struct net_device *dev, __u8 *buf)
5180 struct net_local *tp = netdev_priv(dev);
5184 tptr = (__u32)buf - (__u32)tp->ram_access;
5185 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5186 outb(amask, dev->base_addr + PR);
5191 static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5195 if(rsv->svl != S_PHYSICAL_DROP)
5196 return (E_SUB_VECTOR_LENGTH_ERROR);
5198 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5199 if((err = smctr_wait_cmd(dev)))
5202 return (POSITIVE_ACK);
5205 /* Reset the ring speed to the opposite of what it was. This auto-pilot
5206 * mode requires a complete reset and re-init of the adapter.
5208 static int smctr_set_ring_speed(struct net_device *dev)
5210 struct net_local *tp = netdev_priv(dev);
5213 if(tp->media_type == MEDIA_UTP_16)
5214 tp->media_type = MEDIA_UTP_4;
5216 tp->media_type = MEDIA_UTP_16;
5218 smctr_enable_16bit(dev);
5220 /* Re-Initialize adapter's internal registers */
5221 smctr_reset_adapter(dev);
5223 if((err = smctr_init_card_real(dev)))
5226 smctr_enable_bic_int(dev);
5228 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5231 smctr_disable_16bit(dev);
5236 static int smctr_set_rx_look_ahead(struct net_device *dev)
5238 struct net_local *tp = netdev_priv(dev);
5241 if(smctr_debug > 10)
5242 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5244 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5245 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5247 if(tp->adapter_bus == BUS_ISA16_TYPE)
5249 sword = *((__u16 *)(tp->ram_access));
5250 *((__u16 *)(tp->ram_access)) = 0x1234;
5252 smctr_disable_16bit(dev);
5253 rword = *((__u16 *)(tp->ram_access));
5254 smctr_enable_16bit(dev);
5257 tp->adapter_flags |= FORCED_16BIT_MODE;
5259 *((__u16 *)(tp->ram_access)) = sword;
5265 static int smctr_set_trc_reset(int ioaddr)
5269 r = inb(ioaddr + MSR);
5270 outb(MSR_RST | r, ioaddr + MSR);
5276 * This function can be called if the adapter is busy or not.
5278 static int smctr_setup_single_cmd(struct net_device *dev,
5279 __u16 command, __u16 subcommand)
5281 struct net_local *tp = netdev_priv(dev);
5284 if(smctr_debug > 10)
5285 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5287 if((err = smctr_wait_while_cbusy(dev)))
5290 if((err = (unsigned int)smctr_wait_cmd(dev)))
5293 tp->acb_head->cmd_done_status = 0;
5294 tp->acb_head->cmd = command;
5295 tp->acb_head->subcmd = subcommand;
5297 err = smctr_issue_resume_acb_cmd(dev);
5303 * This function can not be called with the adapter busy.
5305 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5306 __u16 command, __u16 subcommand)
5308 struct net_local *tp = netdev_priv(dev);
5310 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5311 tp->acb_head->cmd = command;
5312 tp->acb_head->subcmd = subcommand;
5313 tp->acb_head->data_offset_lo
5314 = (__u16)TRC_POINTER(tp->misc_command_data);
5316 return(smctr_issue_resume_acb_cmd(dev));
5319 static char *smctr_malloc(struct net_device *dev, __u16 size)
5321 struct net_local *tp = netdev_priv(dev);
5324 m = (char *)(tp->ram_access + tp->sh_mem_used);
5325 tp->sh_mem_used += (__u32)size;
5330 static int smctr_status_chg(struct net_device *dev)
5332 struct net_local *tp = netdev_priv(dev);
5334 if(smctr_debug > 10)
5335 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5345 /* Interrupt driven open() completion. XXX */
5347 tp->group_address_0 = 0;
5348 tp->group_address[0] = 0;
5349 tp->group_address[1] = 0;
5350 tp->functional_address_0 = 0;
5351 tp->functional_address[0] = 0;
5352 tp->functional_address[1] = 0;
5357 printk(KERN_INFO "%s: status change unknown %x\n",
5358 dev->name, tp->status);
5365 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5368 struct net_local *tp = netdev_priv(dev);
5371 if(smctr_debug > 10)
5372 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5374 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5375 if(tp->num_tx_fcbs[queue] != 1)
5376 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5378 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5380 tp->tx_queue_status[queue] = TRANSMITING;
5381 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5387 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5389 struct net_local *tp = netdev_priv(dev);
5390 __u16 status, err = 0;
5393 if(smctr_debug > 10)
5394 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5396 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5398 if(status & 0x7e00 )
5400 err = HARDWARE_FAILED;
5404 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5408 smctr_disable_16bit(dev);
5410 if(tp->mode_bits & UMAC)
5412 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5413 cstatus = NO_SUCH_DESTINATION;
5416 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5417 cstatus = DEST_OUT_OF_RESOURCES;
5420 if(status & FCB_TX_STATUS_E)
5421 cstatus = MAX_COLLISIONS;
5430 if(queue == BUG_QUEUE)
5433 smctr_enable_16bit(dev);
5441 static unsigned short smctr_tx_move_frame(struct net_device *dev,
5442 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5444 struct net_local *tp = netdev_priv(dev);
5445 unsigned int ram_usable;
5446 __u32 flen, len, offset = 0;
5449 if(smctr_debug > 10)
5450 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5452 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5456 while(flen > 0 && bytes > 0)
5458 smctr_set_page(dev, pbuff);
5460 offset = SMC_PAGE_OFFSET(pbuff);
5462 if(offset + flen > ram_usable)
5463 len = ram_usable - offset;
5470 page = (char *) (offset + tp->ram_access);
5471 memcpy(page, frag, len);
5482 /* Update the error statistic counters for this adapter. */
5483 static int smctr_update_err_stats(struct net_device *dev)
5485 struct net_local *tp = netdev_priv(dev);
5486 struct tr_statistics *tstat = &tp->MacStat;
5488 if(tstat->internal_errors)
5489 tstat->internal_errors
5490 += *(tp->misc_command_data + 0) & 0x00ff;
5492 if(tstat->line_errors)
5493 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5495 if(tstat->A_C_errors)
5496 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5498 if(tstat->burst_errors)
5499 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5501 if(tstat->abort_delimiters)
5502 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5504 if(tstat->recv_congest_count)
5505 tstat->recv_congest_count
5506 += *(tp->misc_command_data + 3) & 0x00ff;
5508 if(tstat->lost_frames)
5510 += *(tp->misc_command_data + 3) >> 8;
5512 if(tstat->frequency_errors)
5513 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5515 if(tstat->frame_copied_errors)
5516 tstat->frame_copied_errors
5517 += *(tp->misc_command_data + 4) >> 8;
5519 if(tstat->token_errors)
5520 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5525 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5527 struct net_local *tp = netdev_priv(dev);
5532 fcb = tp->rx_fcb_curr[queue];
5533 len = fcb->frame_length;
5535 fcb->frame_status = 0;
5536 fcb->info = FCB_CHAIN_END;
5537 fcb->back_ptr->info = FCB_WARNING;
5539 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5541 /* update RX BDBs */
5542 size = (len >> RX_BDB_SIZE_SHIFT);
5543 if(len & RX_DATA_BUFFER_SIZE_MASK)
5544 size += sizeof(BDBlock);
5545 size &= (~RX_BDB_SIZE_MASK);
5547 /* check if wrap around */
5548 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5549 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5551 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5552 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5555 bdb->back_ptr->info = BDB_CHAIN_END;
5556 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5557 tp->rx_bdb_curr[queue] = bdb;
5562 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5565 struct net_local *tp = netdev_priv(dev);
5567 if(smctr_debug > 20)
5568 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5570 if(tp->num_tx_fcbs_used[queue] <= 0)
5571 return (HARDWARE_FAILED);
5574 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5576 tp->tx_buff_used[queue] = 0;
5577 return (HARDWARE_FAILED);
5580 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5582 /* if all transmit buffer are cleared
5583 * need to set the tx_buff_curr[] to tx_buff_head[]
5584 * otherwise, tx buffer will be segregate and cannot
5585 * accommodate and buffer greater than (curr - head) and
5586 * (end - curr) since we do not allow wrap around allocation.
5588 if(tp->tx_buff_used[queue] == 0)
5589 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5591 tp->num_tx_fcbs_used[queue]--;
5592 fcb->frame_status = 0;
5593 tp->tx_fcb_end[queue] = fcb->next_ptr;
5594 netif_wake_queue(dev);
5599 static int smctr_wait_cmd(struct net_device *dev)
5601 struct net_local *tp = netdev_priv(dev);
5602 unsigned int loop_count = 0x20000;
5604 if(smctr_debug > 10)
5605 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5609 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5616 return(HARDWARE_FAILED);
5618 if(tp->acb_head->cmd_done_status & 0xff)
5619 return(HARDWARE_FAILED);
5624 static int smctr_wait_while_cbusy(struct net_device *dev)
5626 struct net_local *tp = netdev_priv(dev);
5627 unsigned int timeout = 0x20000;
5628 int ioaddr = dev->base_addr;
5631 if(tp->bic_type == BIC_585_CHIP)
5635 r = inb(ioaddr + HWR);
5636 if((r & HWR_CBUSY) == 0)
5645 r = inb(ioaddr + CSR);
5646 if((r & CSR_CBUSY) == 0)
5655 return (HARDWARE_FAILED);
5660 static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5661 static int io[SMCTR_MAX_ADAPTERS];
5662 static int irq[SMCTR_MAX_ADAPTERS];
5664 MODULE_LICENSE("GPL");
5666 module_param_array(io, int, NULL, 0);
5667 module_param_array(irq, int, NULL, 0);
5668 module_param(ringspeed, int, 0);
5670 static struct net_device *setup_card(int n)
5672 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5676 return ERR_PTR(-ENOMEM);
5679 err = smctr_probe1(dev, io[n]);
5683 err = register_netdev(dev);
5688 #ifdef CONFIG_MCA_LEGACY
5689 { struct net_local *tp = netdev_priv(dev);
5691 mca_mark_as_unused(tp->slot_num);
5694 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5695 free_irq(dev->irq, dev);
5698 return ERR_PTR(err);
5702 int init_module(void)
5705 struct net_device *dev;
5707 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5708 dev = io[0]? setup_card(i) : smctr_probe(-1);
5715 return found ? 0 : -ENODEV;
5718 void cleanup_module(void)
5722 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5723 struct net_device *dev = dev_smctr[i];
5727 unregister_netdev(dev);
5728 #ifdef CONFIG_MCA_LEGACY
5729 { struct net_local *tp = netdev_priv(dev);
5731 mca_mark_as_unused(tp->slot_num);
5734 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5736 free_irq(dev->irq, dev);