2 * smctr.c: A network driver for the SMC Token Ring Adapters.
4 * Written by Jay Schulist <jschlst@samba.org>
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
9 * This device driver works with the following SMC adapters:
10 * - SMC TokenCard Elite (8115T, chips 825/584)
11 * - SMC TokenCard Elite/A MCA (8115T/A, chips 825/594)
14 * - SMC TokenCard SDK.
17 * JS Jay Schulist <jschlst@samba.org>
20 * 07102000 JS Fixed a timing problem in smctr_wait_cmd();
21 * Also added a bit more discriptive error msgs.
22 * 07122000 JS Fixed problem with detecting a card with
23 * module io/irq/mem specified.
26 * 1. Multicast support.
28 * Initial 2.5 cleanup Alan Cox <alan@redhat.com> 2002/10/28
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
36 #include <linux/ptrace.h>
37 #include <linux/ioport.h>
39 #include <linux/slab.h>
40 #include <linux/string.h>
41 #include <linux/time.h>
42 #include <linux/errno.h>
43 #include <linux/init.h>
44 #include <linux/mca-legacy.h>
45 #include <linux/delay.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/skbuff.h>
49 #include <linux/trdevice.h>
50 #include <linux/bitops.h>
52 #include <asm/system.h>
57 #if BITS_PER_LONG == 64
58 #error FIXME: driver does not support 64-bit platforms
61 #include "smctr.h" /* Our Stuff */
62 #include "smctr_firmware.h" /* SMC adapter firmware */
64 static char version[] __initdata = KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
65 static const char cardname[] = "smctr";
68 #define SMCTR_IO_EXTENT 20
70 #ifdef CONFIG_MCA_LEGACY
71 static unsigned int smctr_posid = 0x6ec6;
76 /* SMC Name of the Adapter. */
77 static char smctr_name[] = "SMC TokenCard";
78 static char *smctr_model = "Unknown";
80 /* Use 0 for production, 1 for verification, 2 for debug, and
81 * 3 for very verbose debug.
86 static unsigned int smctr_debug = SMCTR_DEBUG;
88 /* smctr.c prototypes and functions are arranged alphabeticly
89 * for clearity, maintainability and pure old fashion fun.
92 static int smctr_alloc_shared_memory(struct net_device *dev);
95 static int smctr_bypass_state(struct net_device *dev);
98 static int smctr_checksum_firmware(struct net_device *dev);
99 static int __init smctr_chk_isa(struct net_device *dev);
100 static int smctr_chg_rx_mask(struct net_device *dev);
101 static int smctr_clear_int(struct net_device *dev);
102 static int smctr_clear_trc_reset(int ioaddr);
103 static int smctr_close(struct net_device *dev);
106 static int smctr_decode_firmware(struct net_device *dev);
107 static int smctr_disable_16bit(struct net_device *dev);
108 static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
109 static int smctr_disable_bic_int(struct net_device *dev);
112 static int smctr_enable_16bit(struct net_device *dev);
113 static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
114 static int smctr_enable_adapter_ram(struct net_device *dev);
115 static int smctr_enable_bic_int(struct net_device *dev);
118 static int __init smctr_get_boardid(struct net_device *dev, int mca);
119 static int smctr_get_group_address(struct net_device *dev);
120 static int smctr_get_functional_address(struct net_device *dev);
121 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
122 static int smctr_get_physical_drop_number(struct net_device *dev);
123 static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
124 static int smctr_get_station_id(struct net_device *dev);
125 static struct net_device_stats *smctr_get_stats(struct net_device *dev);
126 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
128 static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
131 static int smctr_hardware_send_packet(struct net_device *dev,
132 struct net_local *tp);
134 static int smctr_init_acbs(struct net_device *dev);
135 static int smctr_init_adapter(struct net_device *dev);
136 static int smctr_init_card_real(struct net_device *dev);
137 static int smctr_init_rx_bdbs(struct net_device *dev);
138 static int smctr_init_rx_fcbs(struct net_device *dev);
139 static int smctr_init_shared_memory(struct net_device *dev);
140 static int smctr_init_tx_bdbs(struct net_device *dev);
141 static int smctr_init_tx_fcbs(struct net_device *dev);
142 static int smctr_internal_self_test(struct net_device *dev);
143 static irqreturn_t smctr_interrupt(int irq, void *dev_id);
144 static int smctr_issue_enable_int_cmd(struct net_device *dev,
145 __u16 interrupt_enable_mask);
146 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
148 static int smctr_issue_init_timers_cmd(struct net_device *dev);
149 static int smctr_issue_init_txrx_cmd(struct net_device *dev);
150 static int smctr_issue_insert_cmd(struct net_device *dev);
151 static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
152 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
153 static int smctr_issue_remove_cmd(struct net_device *dev);
154 static int smctr_issue_resume_acb_cmd(struct net_device *dev);
155 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
156 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
157 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
158 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
159 static int smctr_issue_test_hic_cmd(struct net_device *dev);
160 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
161 static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
162 static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
163 static int smctr_issue_write_byte_cmd(struct net_device *dev,
164 short aword_cnt, void *byte);
165 static int smctr_issue_write_word_cmd(struct net_device *dev,
166 short aword_cnt, void *word);
169 static int smctr_join_complete_state(struct net_device *dev);
172 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
173 static int smctr_load_firmware(struct net_device *dev);
174 static int smctr_load_node_addr(struct net_device *dev);
175 static int smctr_lobe_media_test(struct net_device *dev);
176 static int smctr_lobe_media_test_cmd(struct net_device *dev);
177 static int smctr_lobe_media_test_state(struct net_device *dev);
180 static int smctr_make_8025_hdr(struct net_device *dev,
181 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
182 static int smctr_make_access_pri(struct net_device *dev,
183 MAC_SUB_VECTOR *tsv);
184 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
185 static int smctr_make_auth_funct_class(struct net_device *dev,
186 MAC_SUB_VECTOR *tsv);
187 static int smctr_make_corr(struct net_device *dev,
188 MAC_SUB_VECTOR *tsv, __u16 correlator);
189 static int smctr_make_funct_addr(struct net_device *dev,
190 MAC_SUB_VECTOR *tsv);
191 static int smctr_make_group_addr(struct net_device *dev,
192 MAC_SUB_VECTOR *tsv);
193 static int smctr_make_phy_drop_num(struct net_device *dev,
194 MAC_SUB_VECTOR *tsv);
195 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
196 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
197 static int smctr_make_ring_station_status(struct net_device *dev,
198 MAC_SUB_VECTOR *tsv);
199 static int smctr_make_ring_station_version(struct net_device *dev,
200 MAC_SUB_VECTOR *tsv);
201 static int smctr_make_tx_status_code(struct net_device *dev,
202 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
203 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
204 MAC_SUB_VECTOR *tsv);
205 static int smctr_make_wrap_data(struct net_device *dev,
206 MAC_SUB_VECTOR *tsv);
209 static int smctr_open(struct net_device *dev);
210 static int smctr_open_tr(struct net_device *dev);
213 struct net_device *smctr_probe(int unit);
214 static int __init smctr_probe1(struct net_device *dev, int ioaddr);
215 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
216 struct net_device *dev, __u16 rx_status);
219 static int smctr_ram_memory_test(struct net_device *dev);
220 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
222 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
224 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
225 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
226 MAC_HEADER *rmf, __u16 *correlator);
227 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
229 static int smctr_reset_adapter(struct net_device *dev);
230 static int smctr_restart_tx_chain(struct net_device *dev, short queue);
231 static int smctr_ring_status_chg(struct net_device *dev);
232 static int smctr_rx_frame(struct net_device *dev);
235 static int smctr_send_dat(struct net_device *dev);
236 static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev);
237 static int smctr_send_lobe_media_test(struct net_device *dev);
238 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
240 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
242 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
244 static int smctr_send_rpt_tx_forward(struct net_device *dev,
245 MAC_HEADER *rmf, __u16 tx_fstatus);
246 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
247 __u16 rcode, __u16 correlator);
248 static int smctr_send_rq_init(struct net_device *dev);
249 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
251 static int smctr_set_auth_access_pri(struct net_device *dev,
252 MAC_SUB_VECTOR *rsv);
253 static int smctr_set_auth_funct_class(struct net_device *dev,
254 MAC_SUB_VECTOR *rsv);
255 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
257 static int smctr_set_error_timer_value(struct net_device *dev,
258 MAC_SUB_VECTOR *rsv);
259 static int smctr_set_frame_forward(struct net_device *dev,
260 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
261 static int smctr_set_local_ring_num(struct net_device *dev,
262 MAC_SUB_VECTOR *rsv);
263 static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
264 static void smctr_set_multicast_list(struct net_device *dev);
265 static int smctr_set_page(struct net_device *dev, __u8 *buf);
266 static int smctr_set_phy_drop(struct net_device *dev,
267 MAC_SUB_VECTOR *rsv);
268 static int smctr_set_ring_speed(struct net_device *dev);
269 static int smctr_set_rx_look_ahead(struct net_device *dev);
270 static int smctr_set_trc_reset(int ioaddr);
271 static int smctr_setup_single_cmd(struct net_device *dev,
272 __u16 command, __u16 subcommand);
273 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
274 __u16 command, __u16 subcommand);
275 static char *smctr_malloc(struct net_device *dev, __u16 size);
276 static int smctr_status_chg(struct net_device *dev);
279 static void smctr_timeout(struct net_device *dev);
280 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
282 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
283 static unsigned short smctr_tx_move_frame(struct net_device *dev,
284 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
287 static int smctr_update_err_stats(struct net_device *dev);
288 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
289 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
293 static int smctr_wait_cmd(struct net_device *dev);
294 static int smctr_wait_while_cbusy(struct net_device *dev);
296 #define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
297 #define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
298 #define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
300 /* Allocate Adapter Shared Memory.
301 * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
302 * function "get_num_rx_bdbs" below!!!
304 * Order of memory allocation:
306 * 0. Initial System Configuration Block Pointer
307 * 1. System Configuration Block
308 * 2. System Control Block
309 * 3. Action Command Block
310 * 4. Interrupt Status Block
313 * 6. NON-MAC TX FCB'S
315 * 8. NON-MAC TX BDB'S
317 * 10. NON-MAC RX FCB'S
319 * 12. NON-MAC RX BDB'S
320 * 13. MAC TX Data Buffer( 1, 256 byte buffer)
321 * 14. MAC RX Data Buffer( 1, 256 byte buffer)
323 * 15. NON-MAC TX Data Buffer
324 * 16. NON-MAC RX Data Buffer
326 static int smctr_alloc_shared_memory(struct net_device *dev)
328 struct net_local *tp = netdev_priv(dev);
331 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
333 /* Allocate initial System Control Block pointer.
334 * This pointer is located in the last page, last offset - 4.
336 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
337 - (long)ISCP_BLOCK_SIZE);
339 /* Allocate System Control Blocks. */
340 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
341 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
343 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
344 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
346 tp->acb_head = (ACBlock *)smctr_malloc(dev,
347 sizeof(ACBlock)*tp->num_acbs);
348 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
350 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
351 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
353 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
354 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
356 /* Allocate transmit FCBs. */
357 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
358 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
360 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
361 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
363 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
364 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
366 /* Allocate transmit BDBs. */
367 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
368 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
370 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
371 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
373 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
374 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
376 /* Allocate receive FCBs. */
377 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
378 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
380 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
381 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
383 /* Allocate receive BDBs. */
384 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
385 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
387 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
389 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
390 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
392 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
394 /* Allocate MAC transmit buffers.
395 * MAC Tx Buffers doen't have to be on an ODD Boundry.
397 tp->tx_buff_head[MAC_QUEUE]
398 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
399 tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
400 tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
402 /* Allocate BUG transmit buffers. */
403 tp->tx_buff_head[BUG_QUEUE]
404 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
405 tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
406 tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
408 /* Allocate MAC receive data buffers.
409 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
411 tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
412 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
413 tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
415 /* Allocate Non-MAC transmit buffers.
416 * ?? For maximum Netware performance, put Tx Buffers on
417 * ODD Boundry and then restore malloc to Even Boundrys.
419 smctr_malloc(dev, 1L);
420 tp->tx_buff_head[NON_MAC_QUEUE]
421 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
422 tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
423 tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
424 smctr_malloc(dev, 1L);
426 /* Allocate Non-MAC receive data buffers.
427 * To guarantee a minimum of 256 contigous memory to
428 * UM_Receive_Packet's lookahead pointer, before a page
429 * change or ring end is encountered, place each rx buffer on
430 * a 256 byte boundary.
432 smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
433 tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
434 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
435 tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
440 /* Enter Bypass state. */
441 static int smctr_bypass_state(struct net_device *dev)
446 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
448 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
453 static int smctr_checksum_firmware(struct net_device *dev)
455 struct net_local *tp = netdev_priv(dev);
456 __u16 i, checksum = 0;
459 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
461 smctr_enable_adapter_ctrl_store(dev);
463 for(i = 0; i < CS_RAM_SIZE; i += 2)
464 checksum += *((__u16 *)(tp->ram_access + i));
466 tp->microcode_version = *(__u16 *)(tp->ram_access
467 + CS_RAM_VERSION_OFFSET);
468 tp->microcode_version >>= 8;
470 smctr_disable_adapter_ctrl_store(dev);
478 static int __init smctr_chk_mca(struct net_device *dev)
480 #ifdef CONFIG_MCA_LEGACY
481 struct net_local *tp = netdev_priv(dev);
483 __u8 r1, r2, r3, r4, r5;
485 current_slot = mca_find_unused_adapter(smctr_posid, 0);
486 if(current_slot == MCA_NOTFOUND)
489 mca_set_adapter_name(current_slot, smctr_name);
490 mca_mark_as_used(current_slot);
491 tp->slot_num = current_slot;
493 r1 = mca_read_stored_pos(tp->slot_num, 2);
494 r2 = mca_read_stored_pos(tp->slot_num, 3);
497 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
499 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
501 r1 = inb(CNFG_POS_REG1);
502 r2 = inb(CNFG_POS_REG0);
504 tp->bic_type = BIC_594_CHIP;
507 r2 = mca_read_stored_pos(tp->slot_num, 2);
509 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
510 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
513 r5 = mca_read_stored_pos(tp->slot_num, 5);
533 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
534 release_region(dev->base_addr, SMCTR_IO_EXTENT);
539 r3 = mca_read_stored_pos(tp->slot_num, 3);
540 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
542 tp->ram_base += 0x010000;
544 tp->ram_base += 0xF00000;
550 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
551 tp->ram_size = (__u16)CNFG_SIZE_64KB;
552 tp->board_id |= TOKEN_MEDIA;
554 r4 = mca_read_stored_pos(tp->slot_num, 4);
555 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
557 tp->rom_base += 0x010000;
563 tp->rom_size = CNFG_SIZE_8KB;
566 tp->rom_size = CNFG_SIZE_16KB;
569 tp->rom_size = CNFG_SIZE_32KB;
572 tp->rom_size = ROM_DISABLE;
575 /* Get Media Type. */
576 r5 = mca_read_stored_pos(tp->slot_num, 5);
577 r5 &= CNFG_MEDIA_TYPE_MASK;
581 tp->media_type = MEDIA_STP_4;
585 tp->media_type = MEDIA_STP_16;
589 tp->media_type = MEDIA_UTP_16;
593 tp->media_type = MEDIA_UTP_4;
598 r2 = mca_read_stored_pos(tp->slot_num, 2);
600 tp->mode_bits |= EARLY_TOKEN_REL;
603 outb(CNFG_POS_CONTROL_REG, 0);
605 tp->board_id = smctr_get_boardid(dev, 1);
606 switch(tp->board_id & 0xffff)
609 smctr_model = "8115T/A";
613 if(tp->extra_info & CHIP_REV_MASK)
614 smctr_model = "8115T rev XE";
616 smctr_model = "8115T rev XD";
620 smctr_model = "Unknown";
627 #endif /* CONFIG_MCA_LEGACY */
630 static int smctr_chg_rx_mask(struct net_device *dev)
632 struct net_local *tp = netdev_priv(dev);
636 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
638 smctr_enable_16bit(dev);
639 smctr_set_page(dev, (__u8 *)tp->ram_access);
641 if(tp->mode_bits & LOOPING_MODE_MASK)
642 tp->config_word0 |= RX_OWN_BIT;
644 tp->config_word0 &= ~RX_OWN_BIT;
646 if(tp->receive_mask & PROMISCUOUS_MODE)
647 tp->config_word0 |= PROMISCUOUS_BIT;
649 tp->config_word0 &= ~PROMISCUOUS_BIT;
651 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
652 tp->config_word0 |= SAVBAD_BIT;
654 tp->config_word0 &= ~SAVBAD_BIT;
656 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
657 tp->config_word0 |= RXATMAC;
659 tp->config_word0 &= ~RXATMAC;
661 if(tp->receive_mask & ACCEPT_MULTI_PROM)
662 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
664 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
666 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
667 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
670 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
671 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
673 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
676 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
682 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
688 smctr_disable_16bit(dev);
693 static int smctr_clear_int(struct net_device *dev)
695 struct net_local *tp = netdev_priv(dev);
697 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
702 static int smctr_clear_trc_reset(int ioaddr)
706 r = inb(ioaddr + MSR);
707 outb(~MSR_RST & r, ioaddr + MSR);
713 * The inverse routine to smctr_open().
715 static int smctr_close(struct net_device *dev)
717 struct net_local *tp = netdev_priv(dev);
721 netif_stop_queue(dev);
725 /* Check to see if adapter is already in a closed state. */
726 if(tp->status != OPEN)
729 smctr_enable_16bit(dev);
730 smctr_set_page(dev, (__u8 *)tp->ram_access);
732 if((err = smctr_issue_remove_cmd(dev)))
734 smctr_disable_16bit(dev);
740 skb = skb_dequeue(&tp->SendSkbQueue);
751 static int smctr_decode_firmware(struct net_device *dev)
753 struct net_local *tp = netdev_priv(dev);
754 short bit = 0x80, shift = 12;
755 DECODE_TREE_NODE *tree;
763 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
765 weight = *(long *)(tp->ptr_ucode + WEIGHT_OFFSET);
766 tsize = *(__u8 *)(tp->ptr_ucode + TREE_SIZE_OFFSET);
767 tree = (DECODE_TREE_NODE *)(tp->ptr_ucode + TREE_OFFSET);
768 ucode = (__u8 *)(tp->ptr_ucode + TREE_OFFSET
769 + (tsize * sizeof(DECODE_TREE_NODE)));
770 mem = (__u16 *)(tp->ram_access);
775 while((tree + branch)->tag != LEAF && weight)
777 branch = *ucode & bit ? (tree + branch)->llink
778 : (tree + branch)->rlink;
790 buff |= (tree + branch)->info << shift;
795 *(mem++) = SWAP_BYTES(buff);
801 /* The following assumes the Control Store Memory has
802 * been initialized to zero. If the last partial word
803 * is zero, it will not be written.
806 *(mem++) = SWAP_BYTES(buff);
811 static int smctr_disable_16bit(struct net_device *dev)
817 * On Exit, Adapter is:
818 * 1. TRC is in a reset state and un-initialized.
819 * 2. Adapter memory is enabled.
820 * 3. Control Store memory is out of context (-WCSS is 1).
822 static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
824 struct net_local *tp = netdev_priv(dev);
825 int ioaddr = dev->base_addr;
828 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
830 tp->trc_mask |= CSR_WCSS;
831 outb(tp->trc_mask, ioaddr + CSR);
836 static int smctr_disable_bic_int(struct net_device *dev)
838 struct net_local *tp = netdev_priv(dev);
839 int ioaddr = dev->base_addr;
841 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
842 | CSR_MSKTINT | CSR_WCSS;
843 outb(tp->trc_mask, ioaddr + CSR);
848 static int smctr_enable_16bit(struct net_device *dev)
850 struct net_local *tp = netdev_priv(dev);
853 if(tp->adapter_bus == BUS_ISA16_TYPE)
855 r = inb(dev->base_addr + LAAR);
856 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
863 * To enable the adapter control store memory:
864 * 1. Adapter must be in a RESET state.
865 * 2. Adapter memory must be enabled.
866 * 3. Control Store Memory is in context (-WCSS is 0).
868 static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
870 struct net_local *tp = netdev_priv(dev);
871 int ioaddr = dev->base_addr;
874 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
876 smctr_set_trc_reset(ioaddr);
877 smctr_enable_adapter_ram(dev);
879 tp->trc_mask &= ~CSR_WCSS;
880 outb(tp->trc_mask, ioaddr + CSR);
885 static int smctr_enable_adapter_ram(struct net_device *dev)
887 int ioaddr = dev->base_addr;
891 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
893 r = inb(ioaddr + MSR);
894 outb(MSR_MEMB | r, ioaddr + MSR);
899 static int smctr_enable_bic_int(struct net_device *dev)
901 struct net_local *tp = netdev_priv(dev);
902 int ioaddr = dev->base_addr;
908 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
909 outb(tp->trc_mask, ioaddr + CSR);
910 r = inb(ioaddr + IRR);
911 outb(r | IRR_IEN, ioaddr + IRR);
915 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
916 outb(tp->trc_mask, ioaddr + CSR);
917 r = inb(ioaddr + IMCCR);
918 outb(r | IMCCR_EIL, ioaddr + IMCCR);
925 static int __init smctr_chk_isa(struct net_device *dev)
927 struct net_local *tp = netdev_priv(dev);
928 int ioaddr = dev->base_addr;
929 __u8 r1, r2, b, chksum = 0;
935 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
937 if((ioaddr & 0x1F) != 0)
940 /* Grab the region so that no one else tries to probe our ioports. */
941 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
946 /* Checksum SMC node address */
947 for(i = 0; i < 8; i++)
949 b = inb(ioaddr + LAR0 + i);
953 if (chksum != NODE_ADDR_CKSUM)
956 b = inb(ioaddr + BDID);
957 if(b != BRD_ID_8115T)
959 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
963 /* Check for 8115T Board ID */
965 for(r = 0; r < 8; r++)
967 r1 = inb(ioaddr + 0x8 + r);
971 /* value of RegF adds up the sum to 0xFF */
972 if((r2 != 0xFF) && (r2 != 0xEE))
976 tp->board_id = smctr_get_boardid(dev, 0);
977 switch(tp->board_id & 0xffff)
980 smctr_model = "8115T/A";
984 if(tp->extra_info & CHIP_REV_MASK)
985 smctr_model = "8115T rev XE";
987 smctr_model = "8115T rev XD";
991 smctr_model = "Unknown";
995 /* Store BIC type. */
996 tp->bic_type = BIC_584_CHIP;
997 tp->nic_type = NIC_825_CHIP;
1000 tp->ram_usable = CNFG_SIZE_16KB;
1001 tp->ram_size = CNFG_SIZE_64KB;
1003 /* Get 58x Ram Base */
1007 r2 = inb(ioaddr + CNFG_LAAR_584);
1008 r2 &= CNFG_LAAR_MASK;
1010 r2 |= ((r1 & 0x38) >> 3);
1012 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1016 r1 = inb(ioaddr + CNFG_ICR_583);
1017 r1 &= CNFG_ICR_IR2_584;
1019 r2 = inb(ioaddr + CNFG_IRR_583);
1020 r2 &= CNFG_IRR_IRQS; /* 0x60 */
1042 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1059 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1063 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
1066 /* Get 58x Rom Base */
1067 r1 = inb(ioaddr + CNFG_BIO_583);
1071 tp->rom_base = (__u32)r1 << 13;
1073 /* Get 58x Rom Size */
1074 r1 = inb(ioaddr + CNFG_BIO_583);
1077 tp->rom_size = ROM_DISABLE;
1081 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1084 /* Get 58x Boot Status */
1085 r1 = inb(ioaddr + CNFG_GP2);
1087 tp->mode_bits &= (~BOOT_STATUS_MASK);
1089 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1090 tp->mode_bits |= BOOT_TYPE_1;
1092 /* Get 58x Zero Wait State */
1093 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1095 r1 = inb(ioaddr + CNFG_IRR_583);
1097 if(r1 & CNFG_IRR_ZWS)
1098 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1100 if(tp->board_id & BOARD_16BIT)
1102 r1 = inb(ioaddr + CNFG_LAAR_584);
1104 if(r1 & CNFG_LAAR_ZWS)
1105 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1108 /* Get 584 Media Menu */
1109 tp->media_menu = 14;
1110 r1 = inb(ioaddr + CNFG_IRR_583);
1112 tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1113 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1115 /* Get Advanced Features */
1116 if(((r1 & 0x6) >> 1) == 0x3)
1117 tp->media_type |= MEDIA_UTP_16;
1120 if(((r1 & 0x6) >> 1) == 0x2)
1121 tp->media_type |= MEDIA_STP_16;
1124 if(((r1 & 0x6) >> 1) == 0x1)
1125 tp->media_type |= MEDIA_UTP_4;
1128 tp->media_type |= MEDIA_STP_4;
1132 r1 = inb(ioaddr + CNFG_GP2);
1133 if(!(r1 & 0x2) ) /* GP2_ETRD */
1134 tp->mode_bits |= EARLY_TOKEN_REL;
1136 /* see if the chip is corrupted
1137 if(smctr_read_584_chksum(ioaddr))
1139 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1140 free_irq(dev->irq, dev);
1149 release_region(ioaddr, SMCTR_IO_EXTENT);
1154 static int __init smctr_get_boardid(struct net_device *dev, int mca)
1156 struct net_local *tp = netdev_priv(dev);
1157 int ioaddr = dev->base_addr;
1161 tp->board_id = BoardIdMask = 0;
1165 BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1166 tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT);
1170 BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1171 tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K
1172 + NIC_825_BIT + ALTERNATE_IRQ_BIT);
1177 r = inb(ioaddr + BID_REG_1);
1179 outb(r, ioaddr + BID_REG_1);
1180 r = inb(ioaddr + BID_REG_1);
1182 if(r & BID_SIXTEEN_BIT_BIT)
1184 tp->extra_info |= SLOT_16BIT;
1185 tp->adapter_bus = BUS_ISA16_TYPE;
1188 tp->adapter_bus = BUS_ISA8_TYPE;
1191 tp->adapter_bus = BUS_MCA_TYPE;
1193 /* Get Board Id Byte */
1194 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1196 /* if Major version > 1.0 then
1202 r1 = inb(ioaddr + BID_REG_1);
1204 r1 |= BID_OTHER_BIT;
1206 outb(r1, ioaddr + BID_REG_1);
1207 r1 = inb(ioaddr + BID_REG_3);
1210 r1 |= BID_ENGR_PAGE;
1212 outb(r1, ioaddr + BID_REG_3);
1213 r1 = inb(ioaddr + BID_REG_1);
1215 r1 |= (BID_RLA | BID_OTHER_BIT);
1217 outb(r1, ioaddr + BID_REG_1);
1219 r1 = inb(ioaddr + BID_REG_1);
1220 while(r1 & BID_RECALL_DONE_MASK)
1221 r1 = inb(ioaddr + BID_REG_1);
1223 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1225 /* clear chip rev bits */
1226 tp->extra_info &= ~CHIP_REV_MASK;
1227 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1229 r1 = inb(ioaddr + BID_REG_1);
1231 r1 |= BID_OTHER_BIT;
1233 outb(r1, ioaddr + BID_REG_1);
1234 r1 = inb(ioaddr + BID_REG_3);
1239 outb(r1, ioaddr + BID_REG_3);
1240 r1 = inb(ioaddr + BID_REG_1);
1245 outb(r1, ioaddr + BID_REG_1);
1246 r1 = inb(ioaddr + BID_REG_1);
1248 while(r1 & BID_RECALL_DONE_MASK)
1249 r1 = inb(ioaddr + BID_REG_1);
1251 return (BoardIdMask);
1254 static int smctr_get_group_address(struct net_device *dev)
1256 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1258 return(smctr_wait_cmd(dev));
1261 static int smctr_get_functional_address(struct net_device *dev)
1263 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1265 return(smctr_wait_cmd(dev));
1268 /* Calculate number of Non-MAC receive BDB's and data buffers.
1269 * This function must simulate allocateing shared memory exactly
1270 * as the allocate_shared_memory function above.
1272 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1274 struct net_local *tp = netdev_priv(dev);
1275 unsigned int mem_used = 0;
1277 /* Allocate System Control Blocks. */
1278 mem_used += sizeof(SCGBlock);
1280 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1281 mem_used += sizeof(SCLBlock);
1283 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1284 mem_used += sizeof(ACBlock) * tp->num_acbs;
1286 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1287 mem_used += sizeof(ISBlock);
1289 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1290 mem_used += MISC_DATA_SIZE;
1292 /* Allocate transmit FCB's. */
1293 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1295 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE];
1296 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE];
1297 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE];
1299 /* Allocate transmit BDBs. */
1300 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE];
1301 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE];
1302 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE];
1304 /* Allocate receive FCBs. */
1305 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE];
1306 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE];
1308 /* Allocate receive BDBs. */
1309 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1311 /* Allocate MAC transmit buffers.
1312 * MAC transmit buffers don't have to be on an ODD Boundry.
1314 mem_used += tp->tx_buff_size[MAC_QUEUE];
1316 /* Allocate BUG transmit buffers. */
1317 mem_used += tp->tx_buff_size[BUG_QUEUE];
1319 /* Allocate MAC receive data buffers.
1320 * MAC receive buffers don't have to be on a 256 byte boundary.
1322 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
1324 /* Allocate Non-MAC transmit buffers.
1325 * For maximum Netware performance, put Tx Buffers on
1326 * ODD Boundry,and then restore malloc to Even Boundrys.
1329 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1332 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1333 * AND NON-MAC RX DATA BUFFERS
1335 * Make sure the mem_used offset at this point is the
1336 * same as in allocate_shared memory or the following
1337 * boundary adjustment will be incorrect (i.e. not allocating
1338 * the non-mac receive buffers above cannot change the 256
1341 * Since this cannot be guaranteed, adding the full 256 bytes
1342 * to the amount of shared memory used at this point will guaranteed
1343 * that the rx data buffers do not overflow shared memory.
1347 return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock)));
1350 static int smctr_get_physical_drop_number(struct net_device *dev)
1352 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1354 return(smctr_wait_cmd(dev));
1357 static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1359 struct net_local *tp = netdev_priv(dev);
1362 bdb = (BDBlock *)((__u32)tp->ram_access
1363 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1365 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1367 return ((__u8 *)bdb->data_block_ptr);
1370 static int smctr_get_station_id(struct net_device *dev)
1372 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1374 return(smctr_wait_cmd(dev));
1378 * Get the current statistics. This may be called with the card open
1381 static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1383 struct net_local *tp = netdev_priv(dev);
1385 return ((struct net_device_stats *)&tp->MacStat);
1388 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1391 struct net_local *tp = netdev_priv(dev);
1394 unsigned short alloc_size;
1395 unsigned short *temp;
1397 if(smctr_debug > 20)
1398 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
1400 /* check if there is enough FCB blocks */
1401 if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue])
1402 return ((FCBlock *)(-1L));
1404 /* round off the input pkt size to the nearest even number */
1405 alloc_size = (bytes_count + 1) & 0xfffe;
1407 /* check if enough mem */
1408 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
1409 return ((FCBlock *)(-1L));
1411 /* check if past the end ;
1412 * if exactly enough mem to end of ring, alloc from front.
1413 * this avoids update of curr when curr = end
1415 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1416 >= (unsigned long)(tp->tx_buff_end[queue]))
1418 /* check if enough memory from ring head */
1419 alloc_size = alloc_size +
1420 (__u16)((__u32)tp->tx_buff_end[queue]
1421 - (__u32)tp->tx_buff_curr[queue]);
1423 if((tp->tx_buff_used[queue] + alloc_size)
1424 > tp->tx_buff_size[queue])
1426 return ((FCBlock *)(-1L));
1430 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
1433 tp->tx_buff_used[queue] += alloc_size;
1434 tp->num_tx_fcbs_used[queue]++;
1435 tp->tx_fcb_curr[queue]->frame_length = bytes_count;
1436 tp->tx_fcb_curr[queue]->memory_alloc = alloc_size;
1437 temp = tp->tx_buff_curr[queue];
1438 tp->tx_buff_curr[queue]
1439 = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe));
1441 pbdb = tp->tx_fcb_curr[queue]->bdb_ptr;
1442 pbdb->buffer_length = bytes_count;
1443 pbdb->data_block_ptr = temp;
1444 pbdb->trc_data_block_ptr = TRC_POINTER(temp);
1446 pFCB = tp->tx_fcb_curr[queue];
1447 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1452 static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1454 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1456 return(smctr_wait_cmd(dev));
1459 static int smctr_hardware_send_packet(struct net_device *dev,
1460 struct net_local *tp)
1462 struct tr_statistics *tstat = &tp->MacStat;
1463 struct sk_buff *skb;
1466 if(smctr_debug > 10)
1467 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1469 if(tp->status != OPEN)
1472 if(tp->monitor_state_ready != 1)
1477 /* Send first buffer from queue */
1478 skb = skb_dequeue(&tp->SendSkbQueue);
1484 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size) return (-1);
1486 smctr_enable_16bit(dev);
1487 smctr_set_page(dev, (__u8 *)tp->ram_access);
1489 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1490 == (FCBlock *)(-1L))
1492 smctr_disable_16bit(dev);
1496 smctr_tx_move_frame(dev, skb,
1497 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1499 smctr_set_page(dev, (__u8 *)fcb);
1501 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1504 tstat->tx_packets++;
1506 smctr_disable_16bit(dev);
1512 static int smctr_init_acbs(struct net_device *dev)
1514 struct net_local *tp = netdev_priv(dev);
1518 if(smctr_debug > 10)
1519 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1522 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1523 acb->cmd_info = ACB_CHAIN_END;
1526 acb->data_offset_lo = 0;
1527 acb->data_offset_hi = 0;
1529 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1530 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1532 for(i = 1; i < tp->num_acbs; i++)
1534 acb = acb->next_ptr;
1535 acb->cmd_done_status
1536 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1537 acb->cmd_info = ACB_CHAIN_END;
1540 acb->data_offset_lo = 0;
1541 acb->data_offset_hi = 0;
1543 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1544 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1547 acb->next_ptr = tp->acb_head;
1548 acb->trc_next_ptr = TRC_POINTER(tp->acb_head);
1549 tp->acb_next = tp->acb_head->next_ptr;
1550 tp->acb_curr = tp->acb_head->next_ptr;
1551 tp->num_acbs_used = 0;
1556 static int smctr_init_adapter(struct net_device *dev)
1558 struct net_local *tp = netdev_priv(dev);
1561 if(smctr_debug > 10)
1562 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
1564 tp->status = CLOSED;
1565 tp->page_offset_mask = (tp->ram_usable * 1024) - 1;
1566 skb_queue_head_init(&tp->SendSkbQueue);
1567 tp->QueueSkb = MAX_TX_QUEUE;
1569 if(!(tp->group_address_0 & 0x0080))
1570 tp->group_address_0 |= 0x00C0;
1572 if(!(tp->functional_address_0 & 0x00C0))
1573 tp->functional_address_0 |= 0x00C0;
1575 tp->functional_address[0] &= 0xFF7F;
1577 if(tp->authorized_function_classes == 0)
1578 tp->authorized_function_classes = 0x7FFF;
1580 if(tp->authorized_access_priority == 0)
1581 tp->authorized_access_priority = 0x06;
1583 smctr_disable_bic_int(dev);
1584 smctr_set_trc_reset(dev->base_addr);
1586 smctr_enable_16bit(dev);
1587 smctr_set_page(dev, (__u8 *)tp->ram_access);
1589 if(smctr_checksum_firmware(dev))
1591 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name); return (-ENOENT);
1594 if((err = smctr_ram_memory_test(dev)))
1596 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1600 smctr_set_rx_look_ahead(dev);
1601 smctr_load_node_addr(dev);
1603 /* Initialize adapter for Internal Self Test. */
1604 smctr_reset_adapter(dev);
1605 if((err = smctr_init_card_real(dev)))
1607 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1612 /* This routine clobbers the TRC's internal registers. */
1613 if((err = smctr_internal_self_test(dev)))
1615 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1620 /* Re-Initialize adapter's internal registers */
1621 smctr_reset_adapter(dev);
1622 if((err = smctr_init_card_real(dev)))
1624 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1629 smctr_enable_bic_int(dev);
1631 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1634 smctr_disable_16bit(dev);
1639 static int smctr_init_card_real(struct net_device *dev)
1641 struct net_local *tp = netdev_priv(dev);
1644 if(smctr_debug > 10)
1645 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1647 tp->sh_mem_used = 0;
1648 tp->num_acbs = NUM_OF_ACBS;
1650 /* Range Check Max Packet Size */
1651 if(tp->max_packet_size < 256)
1652 tp->max_packet_size = 256;
1655 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1656 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1659 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1660 / tp->max_packet_size) - 1;
1662 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1663 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1666 if(tp->num_of_tx_buffs == 0)
1667 tp->num_of_tx_buffs = 1;
1670 /* Tx queue constants */
1671 tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS;
1672 tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS;
1673 tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY;
1674 tp->tx_buff_used [BUG_QUEUE] = 0;
1675 tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING;
1677 tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS;
1678 tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS;
1679 tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY;
1680 tp->tx_buff_used [MAC_QUEUE] = 0;
1681 tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING;
1683 tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
1684 tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
1685 tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
1686 tp->tx_buff_used [NON_MAC_QUEUE] = 0;
1687 tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING;
1689 /* Receive Queue Constants */
1690 tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
1691 tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
1693 if(tp->extra_info & CHIP_REV_MASK)
1694 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1696 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1698 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1700 smctr_alloc_shared_memory(dev);
1701 smctr_init_shared_memory(dev);
1703 if((err = smctr_issue_init_timers_cmd(dev)))
1706 if((err = smctr_issue_init_txrx_cmd(dev)))
1708 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1715 static int smctr_init_rx_bdbs(struct net_device *dev)
1717 struct net_local *tp = netdev_priv(dev);
1722 if(smctr_debug > 10)
1723 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1725 for(i = 0; i < NUM_RX_QS_USED; i++)
1727 bdb = tp->rx_bdb_head[i];
1728 buf = tp->rx_buff_head[i];
1729 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
1730 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1731 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1732 bdb->data_block_ptr = buf;
1733 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1735 if(i == NON_MAC_QUEUE)
1736 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1738 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1740 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1742 bdb->next_ptr->back_ptr = bdb;
1743 bdb = bdb->next_ptr;
1744 buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
1745 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1746 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1747 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1748 bdb->data_block_ptr = buf;
1749 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1751 if(i == NON_MAC_QUEUE)
1752 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1754 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1757 bdb->next_ptr = tp->rx_bdb_head[i];
1758 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1760 tp->rx_bdb_head[i]->back_ptr = bdb;
1761 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1767 static int smctr_init_rx_fcbs(struct net_device *dev)
1769 struct net_local *tp = netdev_priv(dev);
1773 for(i = 0; i < NUM_RX_QS_USED; i++)
1775 fcb = tp->rx_fcb_head[i];
1776 fcb->frame_status = 0;
1777 fcb->frame_length = 0;
1778 fcb->info = FCB_CHAIN_END;
1779 fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
1780 if(i == NON_MAC_QUEUE)
1781 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1783 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1785 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1787 fcb->next_ptr->back_ptr = fcb;
1788 fcb = fcb->next_ptr;
1789 fcb->frame_status = 0;
1790 fcb->frame_length = 0;
1791 fcb->info = FCB_WARNING;
1793 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1795 if(i == NON_MAC_QUEUE)
1797 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1800 = TRC_POINTER(fcb->next_ptr);
1803 fcb->next_ptr = tp->rx_fcb_head[i];
1805 if(i == NON_MAC_QUEUE)
1806 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1808 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1810 tp->rx_fcb_head[i]->back_ptr = fcb;
1811 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1817 static int smctr_init_shared_memory(struct net_device *dev)
1819 struct net_local *tp = netdev_priv(dev);
1823 if(smctr_debug > 10)
1824 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1826 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1828 /* Initialize Initial System Configuration Point. (ISCP) */
1829 iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
1830 *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
1832 smctr_set_page(dev, (__u8 *)tp->ram_access);
1834 /* Initialize System Configuration Pointers. (SCP) */
1835 tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
1836 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
1837 | SCGB_BURST_LENGTH);
1839 tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr);
1840 tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head);
1841 tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr);
1842 tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2;
1844 /* Initialize System Control Block. (SCB) */
1845 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP;
1846 tp->sclb_ptr->iack_code = 0;
1847 tp->sclb_ptr->resume_control = 0;
1848 tp->sclb_ptr->int_mask_control = 0;
1849 tp->sclb_ptr->int_mask_state = 0;
1851 /* Initialize Interrupt Status Block. (ISB) */
1852 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1854 tp->isb_ptr->IStatus[i].IType = 0xf0;
1855 tp->isb_ptr->IStatus[i].ISubtype = 0;
1858 tp->current_isb_index = 0;
1860 /* Initialize Action Command Block. (ACB) */
1861 smctr_init_acbs(dev);
1863 /* Initialize transmit FCB's and BDB's. */
1864 smctr_link_tx_fcbs_to_bdbs(dev);
1865 smctr_init_tx_bdbs(dev);
1866 smctr_init_tx_fcbs(dev);
1868 /* Initialize receive FCB's and BDB's. */
1869 smctr_init_rx_bdbs(dev);
1870 smctr_init_rx_fcbs(dev);
1875 static int smctr_init_tx_bdbs(struct net_device *dev)
1877 struct net_local *tp = netdev_priv(dev);
1881 for(i = 0; i < NUM_TX_QS_USED; i++)
1883 bdb = tp->tx_bdb_head[i];
1884 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1885 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1886 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1888 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1890 bdb->next_ptr->back_ptr = bdb;
1891 bdb = bdb->next_ptr;
1892 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1894 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1897 bdb->next_ptr = tp->tx_bdb_head[i];
1898 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
1899 tp->tx_bdb_head[i]->back_ptr = bdb;
1905 static int smctr_init_tx_fcbs(struct net_device *dev)
1907 struct net_local *tp = netdev_priv(dev);
1911 for(i = 0; i < NUM_TX_QS_USED; i++)
1913 fcb = tp->tx_fcb_head[i];
1914 fcb->frame_status = 0;
1915 fcb->frame_length = 0;
1916 fcb->info = FCB_CHAIN_END;
1917 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1918 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1920 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1922 fcb->next_ptr->back_ptr = fcb;
1923 fcb = fcb->next_ptr;
1924 fcb->frame_status = 0;
1925 fcb->frame_length = 0;
1926 fcb->info = FCB_CHAIN_END;
1928 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1929 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1932 fcb->next_ptr = tp->tx_fcb_head[i];
1933 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1935 tp->tx_fcb_head[i]->back_ptr = fcb;
1936 tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr;
1937 tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr;
1938 tp->num_tx_fcbs_used[i] = 0;
1944 static int smctr_internal_self_test(struct net_device *dev)
1946 struct net_local *tp = netdev_priv(dev);
1949 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1952 if((err = smctr_wait_cmd(dev)))
1955 if(tp->acb_head->cmd_done_status & 0xff)
1958 if((err = smctr_issue_test_hic_cmd(dev)))
1961 if((err = smctr_wait_cmd(dev)))
1964 if(tp->acb_head->cmd_done_status & 0xff)
1967 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1970 if((err = smctr_wait_cmd(dev)))
1973 if(tp->acb_head->cmd_done_status & 0xff)
1980 * The typical workload of the driver: Handle the network interface interrupts.
1982 static irqreturn_t smctr_interrupt(int irq, void *dev_id)
1984 struct net_device *dev = dev_id;
1985 struct net_local *tp;
1987 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1988 __u16 err1, err = NOT_MY_INTERRUPT;
1989 __u8 isb_type, isb_subtype;
1992 ioaddr = dev->base_addr;
1993 tp = netdev_priv(dev);
1995 if(tp->status == NOT_INITIALIZED)
1998 spin_lock(&tp->lock);
2000 smctr_disable_bic_int(dev);
2001 smctr_enable_16bit(dev);
2003 smctr_clear_int(dev);
2005 /* First read the LSB */
2006 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2008 isb_index = tp->current_isb_index;
2009 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2010 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2012 (tp->current_isb_index)++;
2013 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2014 tp->current_isb_index = 0;
2016 if(isb_type >= 0x10)
2018 smctr_disable_16bit(dev);
2019 spin_unlock(&tp->lock);
2023 err = HARDWARE_FAILED;
2024 interrupt_ack_code = isb_index;
2025 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2027 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2031 case ISB_IMC_MAC_TYPE_3:
2032 smctr_disable_16bit(dev);
2037 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2041 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2045 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2049 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2052 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2056 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2060 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2064 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2067 case 8: /* diagnostic state */
2071 tp->monitor_state = MS_BEACON_TEST_STATE;
2072 if(smctr_lobe_media_test(dev))
2074 tp->ring_status_flags = RING_STATUS_CHANGED;
2075 tp->ring_status = AUTO_REMOVAL_ERROR;
2076 smctr_ring_status_chg(dev);
2077 smctr_bypass_state(dev);
2080 smctr_issue_insert_cmd(dev);
2083 /* case 0x0a-0xff, illegal states */
2088 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2089 err = smctr_ring_status_chg(dev);
2091 smctr_enable_16bit(dev);
2094 /* Type 0x02 - MAC Error Counters Interrupt
2095 * One or more MAC Error Counter is half full
2096 * MAC Error Counters
2097 * Lost_FR_Error_Counter
2098 * RCV_Congestion_Counter
2099 * FR_copied_Error_Counter
2100 * FREQ_Error_Counter
2101 * Token_Error_Counter
2102 * Line_Error_Counter
2103 * Internal_Error_Count
2105 case ISB_IMC_MAC_ERROR_COUNTERS:
2106 /* Read 802.5 Error Counters */
2107 err = smctr_issue_read_ring_status_cmd(dev);
2110 /* Type 0x04 - MAC Type 2 Interrupt
2111 * HOST needs to enqueue MAC Frame for transmission
2112 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2113 * TRC_Status_Changed_Indicate
2115 case ISB_IMC_MAC_TYPE_2:
2116 err = smctr_issue_read_ring_status_cmd(dev);
2120 /* Type 0x05 - TX Frame Interrupt (FI). */
2121 case ISB_IMC_TX_FRAME:
2122 /* BUG QUEUE for TRC stuck receive BUG */
2123 if(isb_subtype & TX_PENDING_PRIORITY_2)
2125 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2129 /* NON-MAC frames only */
2130 if(isb_subtype & TX_PENDING_PRIORITY_1)
2132 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2136 /* MAC frames only */
2137 if(isb_subtype & TX_PENDING_PRIORITY_0)
2138 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2140 /* Type 0x06 - TX END OF QUEUE (FE) */
2141 case ISB_IMC_END_OF_TX_QUEUE:
2143 if(isb_subtype & TX_PENDING_PRIORITY_2)
2145 /* ok to clear Receive FIFO overrun
2146 * imask send_BUG now completes.
2148 interrupt_unmask_bits |= 0x800;
2150 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2151 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2153 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2157 /* NON-MAC queue only */
2158 if(isb_subtype & TX_PENDING_PRIORITY_1)
2160 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2161 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2163 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2167 /* MAC queue only */
2168 if(isb_subtype & TX_PENDING_PRIORITY_0)
2170 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2171 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2174 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2178 /* Type 0x07 - NON-MAC RX Resource Interrupt
2179 * Subtype bit 12 - (BW) BDB warning
2180 * Subtype bit 13 - (FW) FCB warning
2181 * Subtype bit 14 - (BE) BDB End of chain
2182 * Subtype bit 15 - (FE) FCB End of chain
2184 case ISB_IMC_NON_MAC_RX_RESOURCE:
2185 tp->rx_fifo_overrun_count = 0;
2186 tp->receive_queue_number = NON_MAC_QUEUE;
2187 err1 = smctr_rx_frame(dev);
2189 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2191 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2193 if(tp->ptr_rx_fcb_overruns)
2194 (*tp->ptr_rx_fcb_overruns)++;
2197 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2199 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2201 if(tp->ptr_rx_bdb_overruns)
2202 (*tp->ptr_rx_bdb_overruns)++;
2207 /* Type 0x08 - MAC RX Resource Interrupt
2208 * Subtype bit 12 - (BW) BDB warning
2209 * Subtype bit 13 - (FW) FCB warning
2210 * Subtype bit 14 - (BE) BDB End of chain
2211 * Subtype bit 15 - (FE) FCB End of chain
2213 case ISB_IMC_MAC_RX_RESOURCE:
2214 tp->receive_queue_number = MAC_QUEUE;
2215 err1 = smctr_rx_frame(dev);
2217 if(isb_subtype & MAC_RX_RESOURCE_FE)
2219 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2222 if(tp->ptr_rx_fcb_overruns)
2223 (*tp->ptr_rx_fcb_overruns)++;
2226 if(isb_subtype & MAC_RX_RESOURCE_BE)
2228 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2231 if(tp->ptr_rx_bdb_overruns)
2232 (*tp->ptr_rx_bdb_overruns)++;
2237 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2238 case ISB_IMC_NON_MAC_RX_FRAME:
2239 tp->rx_fifo_overrun_count = 0;
2240 tp->receive_queue_number = NON_MAC_QUEUE;
2241 err = smctr_rx_frame(dev);
2244 /* Type 0x0A - MAC RX Frame Interrupt */
2245 case ISB_IMC_MAC_RX_FRAME:
2246 tp->receive_queue_number = MAC_QUEUE;
2247 err = smctr_rx_frame(dev);
2250 /* Type 0x0B - TRC status
2251 * TRC has encountered an error condition
2252 * subtype bit 14 - transmit FIFO underrun
2253 * subtype bit 15 - receive FIFO overrun
2255 case ISB_IMC_TRC_FIFO_STATUS:
2256 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2258 if(tp->ptr_tx_fifo_underruns)
2259 (*tp->ptr_tx_fifo_underruns)++;
2262 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2264 /* update overrun stuck receive counter
2265 * if >= 3, has to clear it by sending
2266 * back to back frames. We pick
2267 * DAT(duplicate address MAC frame)
2269 tp->rx_fifo_overrun_count++;
2271 if(tp->rx_fifo_overrun_count >= 3)
2273 tp->rx_fifo_overrun_count = 0;
2275 /* delay clearing fifo overrun
2276 * imask till send_BUG tx
2279 interrupt_unmask_bits &= (~0x800);
2280 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2283 if(tp->ptr_rx_fifo_overruns)
2284 (*tp->ptr_rx_fifo_overruns)++;
2290 /* Type 0x0C - Action Command Status Interrupt
2291 * Subtype bit 14 - CB end of command chain (CE)
2292 * Subtype bit 15 - CB command interrupt (CI)
2294 case ISB_IMC_COMMAND_STATUS:
2296 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2298 printk(KERN_ERR "i1\n");
2299 smctr_disable_16bit(dev);
2301 /* XXXXXXXXXXXXXXXXX */
2302 /* err = UM_Interrupt(dev); */
2304 smctr_enable_16bit(dev);
2308 if((tp->acb_head->cmd
2309 == ACB_CMD_READ_TRC_STATUS)
2310 && (tp->acb_head->subcmd
2311 == RW_TRC_STATUS_BLOCK))
2313 if(tp->ptr_bcn_type != 0)
2316 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2319 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2321 smctr_update_err_stats(dev);
2324 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2327 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2328 smctr_disable_16bit(dev);
2329 err = smctr_ring_status_chg(dev);
2330 smctr_enable_16bit(dev);
2331 if((tp->ring_status & REMOVE_RECEIVED)
2332 && (tp->config_word0 & NO_AUTOREMOVE))
2334 smctr_issue_remove_cmd(dev);
2339 tp->acb_pending = 0;
2344 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2348 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2349 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2350 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2355 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2356 err = smctr_send_rq_init(dev);
2361 tp->acb_pending = 0;
2364 /* Type 0x0D - MAC Type 1 interrupt
2365 * Subtype -- 00 FR_BCN received at S12
2366 * 01 FR_BCN received at S21
2367 * 02 FR_DAT(DA=MA, A<>0) received at S21
2369 * 04 FR_REMOVE received at S42
2370 * 05 TBR_EXP, BR_FLAG_SET at S42
2373 case ISB_IMC_MAC_TYPE_1:
2376 err = HARDWARE_FAILED;
2384 tp->join_state = JS_BYPASS_STATE;
2385 if(tp->status != CLOSED)
2387 tp->status = CLOSED;
2388 err = smctr_status_chg(dev);
2393 tp->join_state = JS_LOBE_TEST_STATE;
2397 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2401 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2405 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2409 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2413 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2417 tp->join_state = JS_JOIN_COMPLETE_STATE;
2419 err = smctr_status_chg(dev);
2423 tp->join_state = JS_BYPASS_WAIT_STATE;
2428 /* Type 0x0E - TRC Initialization Sequence Interrupt
2429 * Subtype -- 00-FF Initializatin sequence complete
2431 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2432 tp->status = INITIALIZED;
2433 smctr_disable_16bit(dev);
2434 err = smctr_status_chg(dev);
2435 smctr_enable_16bit(dev);
2438 /* other interrupt types, illegal */
2447 /* Checking the ack code instead of the unmask bits here is because :
2448 * while fixing the stuck receive, DAT frame are sent and mask off
2449 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2450 * but we still want to issue ack to ISB
2452 if(!(interrupt_ack_code & 0xff00))
2453 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2455 smctr_disable_16bit(dev);
2456 smctr_enable_bic_int(dev);
2457 spin_unlock(&tp->lock);
2462 static int smctr_issue_enable_int_cmd(struct net_device *dev,
2463 __u16 interrupt_enable_mask)
2465 struct net_local *tp = netdev_priv(dev);
2468 if((err = smctr_wait_while_cbusy(dev)))
2471 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2472 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2474 smctr_set_ctrl_attention(dev);
2479 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2481 struct net_local *tp = netdev_priv(dev);
2483 if(smctr_wait_while_cbusy(dev))
2486 tp->sclb_ptr->int_mask_control = ibits;
2487 tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0;
2488 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2490 smctr_set_ctrl_attention(dev);
2495 static int smctr_issue_init_timers_cmd(struct net_device *dev)
2497 struct net_local *tp = netdev_priv(dev);
2500 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2502 if((err = smctr_wait_while_cbusy(dev)))
2505 if((err = smctr_wait_cmd(dev)))
2508 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2509 tp->config_word1 = 0;
2511 if((tp->media_type == MEDIA_STP_16)
2512 || (tp->media_type == MEDIA_UTP_16)
2513 || (tp->media_type == MEDIA_STP_16_UTP_16))
2515 tp->config_word0 |= FREQ_16MB_BIT;
2518 if(tp->mode_bits & EARLY_TOKEN_REL)
2519 tp->config_word0 |= ETREN;
2521 if(tp->mode_bits & LOOPING_MODE_MASK)
2522 tp->config_word0 |= RX_OWN_BIT;
2524 tp->config_word0 &= ~RX_OWN_BIT;
2526 if(tp->receive_mask & PROMISCUOUS_MODE)
2527 tp->config_word0 |= PROMISCUOUS_BIT;
2529 tp->config_word0 &= ~PROMISCUOUS_BIT;
2531 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2532 tp->config_word0 |= SAVBAD_BIT;
2534 tp->config_word0 &= ~SAVBAD_BIT;
2536 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2537 tp->config_word0 |= RXATMAC;
2539 tp->config_word0 &= ~RXATMAC;
2541 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2542 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2544 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2546 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2547 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2550 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2551 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2553 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2556 if((tp->media_type == MEDIA_STP_16)
2557 || (tp->media_type == MEDIA_UTP_16)
2558 || (tp->media_type == MEDIA_STP_16_UTP_16))
2560 tp->config_word1 |= INTERFRAME_SPACING_16;
2563 tp->config_word1 |= INTERFRAME_SPACING_4;
2565 *pTimer_Struc++ = tp->config_word0;
2566 *pTimer_Struc++ = tp->config_word1;
2568 if((tp->media_type == MEDIA_STP_4)
2569 || (tp->media_type == MEDIA_UTP_4)
2570 || (tp->media_type == MEDIA_STP_4_UTP_4))
2572 *pTimer_Struc++ = 0x00FA; /* prescale */
2573 *pTimer_Struc++ = 0x2710; /* TPT_limit */
2574 *pTimer_Struc++ = 0x2710; /* TQP_limit */
2575 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2576 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2577 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2578 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2579 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2580 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2581 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2582 *pTimer_Struc++ = 0x1162; /* THT_limit */
2583 *pTimer_Struc++ = 0x07D0; /* TRR_limit */
2584 *pTimer_Struc++ = 0x1388; /* TVX_limit */
2585 *pTimer_Struc++ = 0x0000; /* reserved */
2589 *pTimer_Struc++ = 0x03E8; /* prescale */
2590 *pTimer_Struc++ = 0x9C40; /* TPT_limit */
2591 *pTimer_Struc++ = 0x9C40; /* TQP_limit */
2592 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2593 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2594 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2595 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2596 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2597 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2598 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2599 *pTimer_Struc++ = 0x4588; /* THT_limit */
2600 *pTimer_Struc++ = 0x1F40; /* TRR_limit */
2601 *pTimer_Struc++ = 0x4E20; /* TVX_limit */
2602 *pTimer_Struc++ = 0x0000; /* reserved */
2605 /* Set node address. */
2606 *pTimer_Struc++ = dev->dev_addr[0] << 8
2607 | (dev->dev_addr[1] & 0xFF);
2608 *pTimer_Struc++ = dev->dev_addr[2] << 8
2609 | (dev->dev_addr[3] & 0xFF);
2610 *pTimer_Struc++ = dev->dev_addr[4] << 8
2611 | (dev->dev_addr[5] & 0xFF);
2613 /* Set group address. */
2614 *pTimer_Struc++ = tp->group_address_0 << 8
2615 | tp->group_address_0 >> 8;
2616 *pTimer_Struc++ = tp->group_address[0] << 8
2617 | tp->group_address[0] >> 8;
2618 *pTimer_Struc++ = tp->group_address[1] << 8
2619 | tp->group_address[1] >> 8;
2621 /* Set functional address. */
2622 *pTimer_Struc++ = tp->functional_address_0 << 8
2623 | tp->functional_address_0 >> 8;
2624 *pTimer_Struc++ = tp->functional_address[0] << 8
2625 | tp->functional_address[0] >> 8;
2626 *pTimer_Struc++ = tp->functional_address[1] << 8
2627 | tp->functional_address[1] >> 8;
2629 /* Set Bit-Wise group address. */
2630 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2631 | tp->bitwise_group_address[0] >> 8;
2632 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2633 | tp->bitwise_group_address[1] >> 8;
2635 /* Set ring number address. */
2636 *pTimer_Struc++ = tp->source_ring_number;
2637 *pTimer_Struc++ = tp->target_ring_number;
2639 /* Physical drop number. */
2640 *pTimer_Struc++ = (unsigned short)0;
2641 *pTimer_Struc++ = (unsigned short)0;
2643 /* Product instance ID. */
2644 for(i = 0; i < 9; i++)
2645 *pTimer_Struc++ = (unsigned short)0;
2647 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2652 static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2654 struct net_local *tp = netdev_priv(dev);
2657 void **txrx_ptrs = (void *)tp->misc_command_data;
2659 if((err = smctr_wait_while_cbusy(dev)))
2662 if((err = smctr_wait_cmd(dev)))
2664 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2668 /* Initialize Transmit Queue Pointers that are used, to point to
2671 for(i = 0; i < NUM_TX_QS_USED; i++)
2672 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2674 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2675 for(; i < MAX_TX_QS; i++)
2676 *txrx_ptrs++ = (void *)0;
2678 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2679 * used, to point to a single FCB and a BDB chain of buffers.
2681 for(i = 0; i < NUM_RX_QS_USED; i++)
2683 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2684 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2687 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2688 for(; i < MAX_RX_QS; i++)
2690 *txrx_ptrs++ = (void *)0;
2691 *txrx_ptrs++ = (void *)0;
2694 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2699 static int smctr_issue_insert_cmd(struct net_device *dev)
2703 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2708 static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2712 if((err = smctr_wait_while_cbusy(dev)))
2715 if((err = smctr_wait_cmd(dev)))
2718 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2719 RW_TRC_STATUS_BLOCK);
2724 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2728 if((err = smctr_wait_while_cbusy(dev)))
2731 if((err = smctr_wait_cmd(dev)))
2734 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2740 static int smctr_issue_remove_cmd(struct net_device *dev)
2742 struct net_local *tp = netdev_priv(dev);
2745 if((err = smctr_wait_while_cbusy(dev)))
2748 tp->sclb_ptr->resume_control = 0;
2749 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2751 smctr_set_ctrl_attention(dev);
2756 static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2758 struct net_local *tp = netdev_priv(dev);
2761 if((err = smctr_wait_while_cbusy(dev)))
2764 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2765 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2767 tp->acb_pending = 1;
2769 smctr_set_ctrl_attention(dev);
2774 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2776 struct net_local *tp = netdev_priv(dev);
2779 if((err = smctr_wait_while_cbusy(dev)))
2782 if(queue == MAC_QUEUE)
2783 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2785 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2787 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2789 smctr_set_ctrl_attention(dev);
2794 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2796 struct net_local *tp = netdev_priv(dev);
2798 if(smctr_debug > 10)
2799 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2801 if(smctr_wait_while_cbusy(dev))
2804 if(queue == MAC_QUEUE)
2805 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2807 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2809 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2811 smctr_set_ctrl_attention(dev);
2816 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2818 struct net_local *tp = netdev_priv(dev);
2820 if(smctr_debug > 10)
2821 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2823 if(smctr_wait_while_cbusy(dev))
2826 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2827 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2829 smctr_set_ctrl_attention(dev);
2834 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2838 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2839 TRC_INTERNAL_ROM_TEST);
2844 static int smctr_issue_test_hic_cmd(struct net_device *dev)
2848 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2849 TRC_HOST_INTERFACE_REG_TEST);
2854 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2858 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2859 TRC_MAC_REGISTERS_TEST);
2864 static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2868 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2869 TRC_INTERNAL_LOOPBACK);
2874 static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2878 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2884 static int smctr_issue_write_byte_cmd(struct net_device *dev,
2885 short aword_cnt, void *byte)
2887 struct net_local *tp = netdev_priv(dev);
2888 unsigned int iword, ibyte;
2891 if((err = smctr_wait_while_cbusy(dev)))
2894 if((err = smctr_wait_cmd(dev)))
2897 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2898 iword++, ibyte += 2)
2900 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2901 | (*((__u8 *)byte + ibyte + 1));
2904 return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2908 static int smctr_issue_write_word_cmd(struct net_device *dev,
2909 short aword_cnt, void *word)
2911 struct net_local *tp = netdev_priv(dev);
2912 unsigned int i, err;
2914 if((err = smctr_wait_while_cbusy(dev)))
2917 if((err = smctr_wait_cmd(dev)))
2920 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2921 tp->misc_command_data[i] = *((__u16 *)word + i);
2923 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2929 static int smctr_join_complete_state(struct net_device *dev)
2933 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2934 JS_JOIN_COMPLETE_STATE);
2939 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2941 struct net_local *tp = netdev_priv(dev);
2946 for(i = 0; i < NUM_TX_QS_USED; i++)
2948 fcb = tp->tx_fcb_head[i];
2949 bdb = tp->tx_bdb_head[i];
2951 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2954 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2955 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2956 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2963 static int smctr_load_firmware(struct net_device *dev)
2965 struct net_local *tp = netdev_priv(dev);
2966 __u16 i, checksum = 0;
2969 if(smctr_debug > 10)
2970 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2972 tp->ptr_ucode = smctr_code;
2973 tp->num_of_tx_buffs = 4;
2974 tp->mode_bits |= UMAC;
2975 tp->receive_mask = 0;
2976 tp->max_packet_size = 4177;
2978 /* Can only upload the firmware once per adapter reset. */
2979 if(tp->microcode_version != 0)
2980 return (UCODE_PRESENT);
2982 /* Verify the firmware exists and is there in the right amount. */
2983 if((tp->ptr_ucode == 0L)
2984 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET) < UCODE_VERSION))
2986 return (UCODE_NOT_PRESENT);
2989 /* UCODE_SIZE is not included in Checksum. */
2990 for(i = 0; i < *((__u16 *)(tp->ptr_ucode + UCODE_SIZE_OFFSET)); i += 2)
2991 checksum += *((__u16 *)(tp->ptr_ucode + 2 + i));
2993 return (UCODE_NOT_PRESENT);
2995 /* At this point we have a valid firmware image, lets kick it on up. */
2996 smctr_enable_adapter_ram(dev);
2997 smctr_enable_16bit(dev);
2998 smctr_set_page(dev, (__u8 *)tp->ram_access);
3000 if((smctr_checksum_firmware(dev))
3001 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET)
3002 > tp->microcode_version))
3004 smctr_enable_adapter_ctrl_store(dev);
3006 /* Zero out ram space for firmware. */
3007 for(i = 0; i < CS_RAM_SIZE; i += 2)
3008 *((__u16 *)(tp->ram_access + i)) = 0;
3010 smctr_decode_firmware(dev);
3012 tp->microcode_version = *(tp->ptr_ucode + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
3013 = (tp->microcode_version << 8);
3014 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3015 = ~(tp->microcode_version << 8) + 1;
3017 smctr_disable_adapter_ctrl_store(dev);
3019 if(smctr_checksum_firmware(dev))
3020 err = HARDWARE_FAILED;
3023 err = UCODE_PRESENT;
3025 smctr_disable_16bit(dev);
3030 static int smctr_load_node_addr(struct net_device *dev)
3032 int ioaddr = dev->base_addr;
3036 for(i = 0; i < 6; i++)
3038 r = inb(ioaddr + LAR0 + i);
3039 dev->dev_addr[i] = (char)r;
3047 * During the transmission of the initial 1500 lobe media MAC frames,
3048 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3049 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3050 * microcode will not transmit any frames given to it by the host, and
3051 * will consequently cause a timeout.
3053 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
3054 * queues other then the one used for the lobe_media_test should be
3057 * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
3058 * has any multi-cast or promiscous bits set, the receive_mask needs to
3059 * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
3060 * run, and then the receive mask set back to its original value if the test
3063 static int smctr_lobe_media_test(struct net_device *dev)
3065 struct net_local *tp = netdev_priv(dev);
3066 unsigned int i, perror = 0;
3067 unsigned short saved_rcv_mask;
3069 if(smctr_debug > 10)
3070 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3072 /* Clear receive mask for lobe test. */
3073 saved_rcv_mask = tp->receive_mask;
3074 tp->receive_mask = 0;
3076 smctr_chg_rx_mask(dev);
3078 /* Setup the lobe media test. */
3079 smctr_lobe_media_test_cmd(dev);
3080 if(smctr_wait_cmd(dev))
3082 smctr_reset_adapter(dev);
3083 tp->status = CLOSED;
3084 return (LOBE_MEDIA_TEST_FAILED);
3087 /* Tx lobe media test frames. */
3088 for(i = 0; i < 1500; ++i)
3090 if(smctr_send_lobe_media_test(dev))
3094 smctr_reset_adapter(dev);
3096 return (LOBE_MEDIA_TEST_FAILED);
3101 if(smctr_lobe_media_test_cmd(dev))
3103 smctr_reset_adapter(dev);
3105 return (LOBE_MEDIA_TEST_FAILED);
3111 if(smctr_send_dat(dev))
3113 if(smctr_send_dat(dev))
3115 smctr_reset_adapter(dev);
3117 return (LOBE_MEDIA_TEST_FAILED);
3121 /* Check if any frames received during test. */
3122 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status)
3123 || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3125 smctr_reset_adapter(dev);
3127 return (LOBE_MEDIA_TEST_FAILED);
3130 /* Set receive mask to "Promisc" mode. */
3131 tp->receive_mask = saved_rcv_mask;
3133 smctr_chg_rx_mask(dev);
3138 static int smctr_lobe_media_test_cmd(struct net_device *dev)
3140 struct net_local *tp = netdev_priv(dev);
3143 if(smctr_debug > 10)
3144 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3146 /* Change to lobe media test state. */
3147 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3149 smctr_lobe_media_test_state(dev);
3150 if(smctr_wait_cmd(dev))
3152 printk(KERN_ERR "Lobe Failed test state\n");
3153 return (LOBE_MEDIA_TEST_FAILED);
3157 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3158 TRC_LOBE_MEDIA_TEST);
3163 static int smctr_lobe_media_test_state(struct net_device *dev)
3167 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3168 JS_LOBE_TEST_STATE);
3173 static int smctr_make_8025_hdr(struct net_device *dev,
3174 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3176 tmf->ac = MSB(ac_fc); /* msb is access control */
3177 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3179 tmf->sa[0] = dev->dev_addr[0];
3180 tmf->sa[1] = dev->dev_addr[1];
3181 tmf->sa[2] = dev->dev_addr[2];
3182 tmf->sa[3] = dev->dev_addr[3];
3183 tmf->sa[4] = dev->dev_addr[4];
3184 tmf->sa[5] = dev->dev_addr[5];
3188 /* Send RQ_INIT to RPS */
3198 /* Send RPT_TX_FORWARD to CRS */
3199 case RPT_TX_FORWARD:
3208 /* Everything else goes to sender */
3210 tmf->da[0] = rmf->sa[0];
3211 tmf->da[1] = rmf->sa[1];
3212 tmf->da[2] = rmf->sa[2];
3213 tmf->da[3] = rmf->sa[3];
3214 tmf->da[4] = rmf->sa[4];
3215 tmf->da[5] = rmf->sa[5];
3222 static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3224 struct net_local *tp = netdev_priv(dev);
3226 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3227 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3229 tsv->svv[0] = MSB(tp->authorized_access_priority);
3230 tsv->svv[1] = LSB(tp->authorized_access_priority);
3235 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3237 tsv->svi = ADDRESS_MODIFER;
3238 tsv->svl = S_ADDRESS_MODIFER;
3246 static int smctr_make_auth_funct_class(struct net_device *dev,
3247 MAC_SUB_VECTOR *tsv)
3249 struct net_local *tp = netdev_priv(dev);
3251 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3252 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3254 tsv->svv[0] = MSB(tp->authorized_function_classes);
3255 tsv->svv[1] = LSB(tp->authorized_function_classes);
3260 static int smctr_make_corr(struct net_device *dev,
3261 MAC_SUB_VECTOR *tsv, __u16 correlator)
3263 tsv->svi = CORRELATOR;
3264 tsv->svl = S_CORRELATOR;
3266 tsv->svv[0] = MSB(correlator);
3267 tsv->svv[1] = LSB(correlator);
3272 static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3274 struct net_local *tp = netdev_priv(dev);
3276 smctr_get_functional_address(dev);
3278 tsv->svi = FUNCTIONAL_ADDRESS;
3279 tsv->svl = S_FUNCTIONAL_ADDRESS;
3281 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3282 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3284 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3285 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3290 static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3292 struct net_local *tp = netdev_priv(dev);
3294 smctr_get_group_address(dev);
3296 tsv->svi = GROUP_ADDRESS;
3297 tsv->svl = S_GROUP_ADDRESS;
3299 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3300 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3302 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3303 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3305 /* Set Group Address Sub-vector to all zeros if only the
3306 * Group Address/Functional Address Indicator is set.
3308 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00
3309 && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3315 static int smctr_make_phy_drop_num(struct net_device *dev,
3316 MAC_SUB_VECTOR *tsv)
3318 struct net_local *tp = netdev_priv(dev);
3320 smctr_get_physical_drop_number(dev);
3322 tsv->svi = PHYSICAL_DROP;
3323 tsv->svl = S_PHYSICAL_DROP;
3325 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3326 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3328 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3329 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3334 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3338 tsv->svi = PRODUCT_INSTANCE_ID;
3339 tsv->svl = S_PRODUCT_INSTANCE_ID;
3341 for(i = 0; i < 18; i++)
3347 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3349 struct net_local *tp = netdev_priv(dev);
3351 smctr_get_station_id(dev);
3353 tsv->svi = STATION_IDENTIFER;
3354 tsv->svl = S_STATION_IDENTIFER;
3356 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3357 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3359 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3360 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3362 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3363 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3368 static int smctr_make_ring_station_status(struct net_device *dev,
3369 MAC_SUB_VECTOR * tsv)
3371 tsv->svi = RING_STATION_STATUS;
3372 tsv->svl = S_RING_STATION_STATUS;
3384 static int smctr_make_ring_station_version(struct net_device *dev,
3385 MAC_SUB_VECTOR *tsv)
3387 struct net_local *tp = netdev_priv(dev);
3389 tsv->svi = RING_STATION_VERSION_NUMBER;
3390 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3392 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3393 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3394 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3395 tsv->svv[3] = 0x40; /* EBCDIC - */
3396 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3397 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3398 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3399 tsv->svv[7] = 0x40; /* EBCDIC - */
3400 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3402 if(tp->extra_info & CHIP_REV_MASK)
3403 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3405 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3410 static int smctr_make_tx_status_code(struct net_device *dev,
3411 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3413 tsv->svi = TRANSMIT_STATUS_CODE;
3414 tsv->svl = S_TRANSMIT_STATUS_CODE;
3416 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) || IBM_PASS_SOURCE_ADDR);
3418 /* Stripped frame status of Transmitted Frame */
3419 tsv->svv[1] = tx_fstatus & 0xff;
3424 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3425 MAC_SUB_VECTOR *tsv)
3427 struct net_local *tp = netdev_priv(dev);
3429 smctr_get_upstream_neighbor_addr(dev);
3431 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3432 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3434 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3435 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3437 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3438 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3440 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3441 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3446 static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3448 tsv->svi = WRAP_DATA;
3449 tsv->svl = S_WRAP_DATA;
3455 * Open/initialize the board. This is called sometime after
3456 * booting when the 'ifconfig' program is run.
3458 * This routine should set everything up anew at each open, even
3459 * registers that "should" only need to be set once at boot, so that
3460 * there is non-reboot way to recover if something goes wrong.
3462 static int smctr_open(struct net_device *dev)
3466 if(smctr_debug > 10)
3467 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3469 err = smctr_init_adapter(dev);
3476 /* Interrupt driven open of Token card. */
3477 static int smctr_open_tr(struct net_device *dev)
3479 struct net_local *tp = netdev_priv(dev);
3480 unsigned long flags;
3483 if(smctr_debug > 10)
3484 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3486 /* Now we can actually open the adapter. */
3487 if(tp->status == OPEN)
3489 if(tp->status != INITIALIZED)
3492 /* FIXME: it would work a lot better if we masked the irq sources
3493 on the card here, then we could skip the locking and poll nicely */
3494 spin_lock_irqsave(&tp->lock, flags);
3496 smctr_set_page(dev, (__u8 *)tp->ram_access);
3498 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3501 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3504 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3507 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3510 tp->status = CLOSED;
3512 /* Insert into the Ring or Enter Loopback Mode. */
3513 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3515 tp->status = CLOSED;
3517 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3519 if(!(err = smctr_wait_cmd(dev)))
3523 smctr_status_chg(dev);
3527 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3529 tp->status = CLOSED;
3530 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3532 if(!(err = smctr_wait_cmd(dev)))
3536 smctr_status_chg(dev);
3540 if((tp->mode_bits & LOOPING_MODE_MASK)
3543 tp->status = CLOSED;
3544 if(!(err = smctr_lobe_media_test_cmd(dev)))
3546 if(!(err = smctr_wait_cmd(dev)))
3549 smctr_status_chg(dev);
3553 if(!(err = smctr_lobe_media_test(dev)))
3554 err = smctr_issue_insert_cmd(dev);
3557 if(err == LOBE_MEDIA_TEST_FAILED)
3558 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3565 spin_unlock_irqrestore(&tp->lock, flags);
3570 /* Check for a network adapter of this type,
3571 * and return device structure if one exists.
3573 struct net_device __init *smctr_probe(int unit)
3575 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3576 static const unsigned ports[] = {
3577 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3578 0x320, 0x340, 0x360, 0x380, 0
3580 const unsigned *port;
3584 return ERR_PTR(-ENOMEM);
3586 SET_MODULE_OWNER(dev);
3589 sprintf(dev->name, "tr%d", unit);
3590 netdev_boot_setup_check(dev);
3593 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3594 err = smctr_probe1(dev, dev->base_addr);
3595 else if(dev->base_addr != 0) /* Don't probe at all. */
3598 for (port = ports; *port; port++) {
3599 err = smctr_probe1(dev, *port);
3606 err = register_netdev(dev);
3611 #ifdef CONFIG_MCA_LEGACY
3612 { struct net_local *tp = netdev_priv(dev);
3614 mca_mark_as_unused(tp->slot_num);
3617 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3618 free_irq(dev->irq, dev);
3621 return ERR_PTR(err);
3625 static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3627 static unsigned version_printed;
3628 struct net_local *tp = netdev_priv(dev);
3632 if(smctr_debug && version_printed++ == 0)
3635 spin_lock_init(&tp->lock);
3636 dev->base_addr = ioaddr;
3638 /* Actually detect an adapter now. */
3639 err = smctr_chk_isa(dev);
3642 if ((err = smctr_chk_mca(dev)) < 0) {
3648 tp = netdev_priv(dev);
3649 dev->mem_start = tp->ram_base;
3650 dev->mem_end = dev->mem_start + 0x10000;
3651 ram = (__u32 *)phys_to_virt(dev->mem_start);
3652 tp->ram_access = *(__u32 *)&ram;
3653 tp->status = NOT_INITIALIZED;
3655 err = smctr_load_firmware(dev);
3656 if(err != UCODE_PRESENT && err != SUCCESS)
3658 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3663 /* Allow user to specify ring speed on module insert. */
3665 tp->media_type = MEDIA_UTP_4;
3667 tp->media_type = MEDIA_UTP_16;
3669 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3670 dev->name, smctr_name, smctr_model,
3671 (unsigned int)dev->base_addr,
3672 dev->irq, tp->rom_base, tp->ram_base);
3674 dev->open = smctr_open;
3675 dev->stop = smctr_close;
3676 dev->hard_start_xmit = smctr_send_packet;
3677 dev->tx_timeout = smctr_timeout;
3678 dev->watchdog_timeo = HZ;
3679 dev->get_stats = smctr_get_stats;
3680 dev->set_multicast_list = &smctr_set_multicast_list;
3687 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3688 struct net_device *dev, __u16 rx_status)
3690 struct net_local *tp = netdev_priv(dev);
3691 struct sk_buff *skb;
3692 __u16 rcode, correlator;
3696 rmf->vl = SWAP_BYTES(rmf->vl);
3697 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3701 /* Received MAC Frames Processed by RS. */
3703 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3708 if((err = smctr_send_rsp(dev, rmf, rcode,
3716 if((rcode = smctr_rcv_chg_param(dev, rmf,
3717 &correlator)) ==HARDWARE_FAILED)
3722 if((err = smctr_send_rsp(dev, rmf, rcode,
3730 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3731 rmf, &correlator)) != POSITIVE_ACK)
3733 if(rcode == HARDWARE_FAILED)
3736 return (smctr_send_rsp(dev, rmf,
3737 rcode, correlator));
3740 if((err = smctr_send_rpt_addr(dev, rmf,
3748 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3749 rmf, &correlator)) != POSITIVE_ACK)
3751 if(rcode == HARDWARE_FAILED)
3754 return (smctr_send_rsp(dev, rmf,
3759 if((err = smctr_send_rpt_attch(dev, rmf,
3767 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3768 rmf, &correlator)) != POSITIVE_ACK)
3770 if(rcode == HARDWARE_FAILED)
3773 return (smctr_send_rsp(dev, rmf,
3778 if((err = smctr_send_rpt_state(dev, rmf,
3786 __u16 uninitialized_var(tx_fstatus);
3788 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3791 if(rcode == HARDWARE_FAILED)
3794 return (smctr_send_rsp(dev, rmf,
3799 if((err = smctr_send_tx_forward(dev, rmf,
3800 &tx_fstatus)) == HARDWARE_FAILED)
3805 if(err == A_FRAME_WAS_FORWARDED)
3807 if((err = smctr_send_rpt_tx_forward(dev,
3817 /* Received MAC Frames Processed by CRS/REM/RPS. */
3822 case RPT_ACTIVE_ERR:
3830 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3833 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3835 rcode = smctr_rcv_unknown(dev, rmf,
3837 if((err = smctr_send_rsp(dev, rmf,rcode,
3849 /* 1. DA doesn't match (Promiscuous Mode).
3850 * 2. Parse for Extended MAC Frame Type.
3868 case RPT_ACTIVE_ERR:
3877 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3878 * ACCEPT_ATT_MAC_FRAMES is set.
3880 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
3881 && (xframe == (__u8)0))
3882 || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES)
3883 && (xframe == (__u8)1)))
3885 rmf->vl = SWAP_BYTES(rmf->vl);
3887 if (!(skb = dev_alloc_skb(size)))
3891 /* Slide data into a sleek skb. */
3892 skb_put(skb, skb->len);
3893 skb_copy_to_linear_data(skb, rmf, skb->len);
3895 /* Update Counters */
3896 tp->MacStat.rx_packets++;
3897 tp->MacStat.rx_bytes += skb->len;
3899 /* Kick the packet on up. */
3900 skb->protocol = tr_type_trans(skb, dev);
3902 dev->last_rx = jiffies;
3909 /* Adapter RAM test. Incremental word ODD boundary data test. */
3910 static int smctr_ram_memory_test(struct net_device *dev)
3912 struct net_local *tp = netdev_priv(dev);
3913 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3914 word_read = 0, err_word = 0, err_pattern = 0;
3915 unsigned int err_offset;
3919 if(smctr_debug > 10)
3920 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3922 start_pattern = 0x0001;
3923 pages_of_ram = tp->ram_size / tp->ram_usable;
3924 pword = tp->ram_access;
3926 /* Incremental word ODD boundary test. */
3927 for(page = 0; (page < pages_of_ram) && (~err);
3928 page++, start_pattern += 0x8000)
3930 smctr_set_page(dev, (__u8 *)(tp->ram_access
3931 + (page * tp->ram_usable * 1024) + 1));
3932 word_pattern = start_pattern;
3934 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3935 *(__u16 *)(pword + j) = word_pattern++;
3937 word_pattern = start_pattern;
3939 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1
3940 && (~err); j += 2, word_pattern++)
3942 word_read = *(__u16 *)(pword + j);
3943 if(word_read != word_pattern)
3947 err_word = word_read;
3948 err_pattern = word_pattern;
3949 return (RAM_TEST_FAILED);
3954 /* Zero out memory. */
3955 for(page = 0; page < pages_of_ram && (~err); page++)
3957 smctr_set_page(dev, (__u8 *)(tp->ram_access
3958 + (page * tp->ram_usable * 1024)));
3961 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3962 *(__u16 *)(pword + j) = word_pattern;
3964 for(j =0; j < (__u32)tp->ram_usable * 1024
3967 word_read = *(__u16 *)(pword + j);
3968 if(word_read != word_pattern)
3972 err_word = word_read;
3973 err_pattern = word_pattern;
3974 return (RAM_TEST_FAILED);
3979 smctr_set_page(dev, (__u8 *)tp->ram_access);
3984 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3987 MAC_SUB_VECTOR *rsv;
3989 __u16 rcode = POSITIVE_ACK;
3990 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
3992 /* This Frame can only come from a CRS */
3993 if((rmf->dc_sc & SC_MASK) != SC_CRS)
3994 return(E_INAPPROPRIATE_SOURCE_CLASS);
3996 /* Remove MVID Length from total length. */
3997 vlen = (signed short)rmf->vl - 4;
3999 /* Point to First SVID */
4000 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4002 /* Search for Appropriate SVID's. */
4003 while((vlen > 0) && (rcode == POSITIVE_ACK))
4008 svectors |= F_CORRELATOR;
4009 rcode = smctr_set_corr(dev, rsv, correlator);
4012 case LOCAL_RING_NUMBER:
4013 svectors |= F_LOCAL_RING_NUMBER;
4014 rcode = smctr_set_local_ring_num(dev, rsv);
4017 case ASSIGN_PHYSICAL_DROP:
4018 svectors |= F_ASSIGN_PHYSICAL_DROP;
4019 rcode = smctr_set_phy_drop(dev, rsv);
4022 case ERROR_TIMER_VALUE:
4023 svectors |= F_ERROR_TIMER_VALUE;
4024 rcode = smctr_set_error_timer_value(dev, rsv);
4027 case AUTHORIZED_FUNCTION_CLASS:
4028 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4029 rcode = smctr_set_auth_funct_class(dev, rsv);
4032 case AUTHORIZED_ACCESS_PRIORITY:
4033 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4034 rcode = smctr_set_auth_access_pri(dev, rsv);
4038 rcode = E_SUB_VECTOR_UNKNOWN;
4042 /* Let Sender Know if SUM of SV length's is
4043 * larger then length in MVID length field
4045 if((vlen -= rsv->svl) < 0)
4046 rcode = E_VECTOR_LENGTH_ERROR;
4048 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4051 if(rcode == POSITIVE_ACK)
4053 /* Let Sender Know if MVID length field
4054 * is larger then SUM of SV length's
4057 rcode = E_VECTOR_LENGTH_ERROR;
4060 /* Let Sender Know if Expected SVID Missing */
4061 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4062 rcode = E_MISSING_SUB_VECTOR;
4069 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4072 MAC_SUB_VECTOR *rsv;
4074 __u16 rcode = POSITIVE_ACK;
4075 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4077 /* This Frame can only come from a RPS */
4078 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4079 return (E_INAPPROPRIATE_SOURCE_CLASS);
4081 /* Remove MVID Length from total length. */
4082 vlen = (signed short)rmf->vl - 4;
4084 /* Point to First SVID */
4085 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4087 /* Search for Appropriate SVID's */
4088 while((vlen > 0) && (rcode == POSITIVE_ACK))
4093 svectors |= F_CORRELATOR;
4094 rcode = smctr_set_corr(dev, rsv, correlator);
4097 case LOCAL_RING_NUMBER:
4098 svectors |= F_LOCAL_RING_NUMBER;
4099 rcode = smctr_set_local_ring_num(dev, rsv);
4102 case ASSIGN_PHYSICAL_DROP:
4103 svectors |= F_ASSIGN_PHYSICAL_DROP;
4104 rcode = smctr_set_phy_drop(dev, rsv);
4107 case ERROR_TIMER_VALUE:
4108 svectors |= F_ERROR_TIMER_VALUE;
4109 rcode = smctr_set_error_timer_value(dev, rsv);
4113 rcode = E_SUB_VECTOR_UNKNOWN;
4117 /* Let Sender Know if SUM of SV length's is
4118 * larger then length in MVID length field
4120 if((vlen -= rsv->svl) < 0)
4121 rcode = E_VECTOR_LENGTH_ERROR;
4123 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4126 if(rcode == POSITIVE_ACK)
4128 /* Let Sender Know if MVID length field
4129 * is larger then SUM of SV length's
4132 rcode = E_VECTOR_LENGTH_ERROR;
4135 /* Let Sender Know if Expected SV Missing */
4136 if((svectors & R_INIT) ^ R_INIT)
4137 rcode = E_MISSING_SUB_VECTOR;
4144 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4146 MAC_SUB_VECTOR *rsv;
4148 __u16 rcode = POSITIVE_ACK;
4149 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4151 /* This Frame can only come from a CRS */
4152 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4153 return (E_INAPPROPRIATE_SOURCE_CLASS);
4155 /* Remove MVID Length from total length */
4156 vlen = (signed short)rmf->vl - 4;
4158 /* Point to First SVID */
4159 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4161 /* Search for Appropriate SVID's */
4162 while((vlen > 0) && (rcode == POSITIVE_ACK))
4167 svectors |= F_FRAME_FORWARD;
4168 rcode = smctr_set_frame_forward(dev, rsv,
4173 rcode = E_SUB_VECTOR_UNKNOWN;
4177 /* Let Sender Know if SUM of SV length's is
4178 * larger then length in MVID length field
4180 if((vlen -= rsv->svl) < 0)
4181 rcode = E_VECTOR_LENGTH_ERROR;
4183 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4186 if(rcode == POSITIVE_ACK)
4188 /* Let Sender Know if MVID length field
4189 * is larger then SUM of SV length's
4192 rcode = E_VECTOR_LENGTH_ERROR;
4195 /* Let Sender Know if Expected SV Missing */
4196 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4197 rcode = E_MISSING_SUB_VECTOR;
4204 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4205 MAC_HEADER *rmf, __u16 *correlator)
4207 MAC_SUB_VECTOR *rsv;
4209 __u16 rcode = POSITIVE_ACK;
4210 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4212 /* Remove MVID Length from total length */
4213 vlen = (signed short)rmf->vl - 4;
4215 /* Point to First SVID */
4216 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4218 /* Search for Appropriate SVID's */
4219 while((vlen > 0) && (rcode == POSITIVE_ACK))
4224 svectors |= F_CORRELATOR;
4225 rcode = smctr_set_corr(dev, rsv, correlator);
4229 rcode = E_SUB_VECTOR_UNKNOWN;
4233 /* Let Sender Know if SUM of SV length's is
4234 * larger then length in MVID length field
4236 if((vlen -= rsv->svl) < 0)
4237 rcode = E_VECTOR_LENGTH_ERROR;
4239 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4242 if(rcode == POSITIVE_ACK)
4244 /* Let Sender Know if MVID length field
4245 * is larger then SUM of SV length's
4248 rcode = E_VECTOR_LENGTH_ERROR;
4251 /* Let Sender Know if Expected SVID Missing */
4252 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4253 ^ R_RQ_ATTCH_STATE_ADDR)
4254 rcode = E_MISSING_SUB_VECTOR;
4261 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4264 MAC_SUB_VECTOR *rsv;
4269 /* Remove MVID Length from total length */
4270 vlen = (signed short)rmf->vl - 4;
4272 /* Point to First SVID */
4273 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4275 /* Search for CORRELATOR for RSP to UNKNOWN */
4276 while((vlen > 0) && (*correlator == 0))
4281 smctr_set_corr(dev, rsv, correlator);
4289 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4292 return (E_UNRECOGNIZED_VECTOR_ID);
4296 * Reset the 825 NIC and exit w:
4297 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4303 static int smctr_reset_adapter(struct net_device *dev)
4305 struct net_local *tp = netdev_priv(dev);
4306 int ioaddr = dev->base_addr;
4308 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4309 mdelay(200); /* ~2 ms */
4311 smctr_clear_trc_reset(ioaddr);
4312 mdelay(200); /* ~2 ms */
4314 /* Remove any latched interrupts that occurred prior to reseting the
4315 * adapter or possibily caused by line glitches due to the reset.
4317 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4322 static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4324 struct net_local *tp = netdev_priv(dev);
4327 if(smctr_debug > 10)
4328 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4330 if(tp->num_tx_fcbs_used[queue] != 0
4331 && tp->tx_queue_status[queue] == NOT_TRANSMITING)
4333 tp->tx_queue_status[queue] = TRANSMITING;
4334 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4340 static int smctr_ring_status_chg(struct net_device *dev)
4342 struct net_local *tp = netdev_priv(dev);
4344 if(smctr_debug > 10)
4345 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4347 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4348 * Bit is set, check value of monitor_state, only then we
4349 * enable and start transmit/receive timeout (if and only
4350 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4352 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4354 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE)
4355 || (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4357 tp->monitor_state_ready = 1;
4361 /* if adapter is NOT in either active monitor
4362 * or standby monitor state => Disable
4363 * transmit/receive timeout.
4365 tp->monitor_state_ready = 0;
4367 /* Ring speed problem, switching to auto mode. */
4368 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE
4371 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4373 smctr_set_ring_speed(dev);
4378 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4381 switch(tp->ring_status)
4384 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
4385 tp->current_ring_status |= RING_RECOVERY;
4388 case SINGLE_STATION:
4389 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
4390 tp->current_ring_status |= SINGLE_STATION;
4393 case COUNTER_OVERFLOW:
4394 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
4395 tp->current_ring_status |= COUNTER_OVERFLOW;
4398 case REMOVE_RECEIVED:
4399 printk(KERN_INFO "%s: Remove Received\n", dev->name);
4400 tp->current_ring_status |= REMOVE_RECEIVED;
4403 case AUTO_REMOVAL_ERROR:
4404 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
4405 tp->current_ring_status |= AUTO_REMOVAL_ERROR;
4408 case LOBE_WIRE_FAULT:
4409 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
4410 tp->current_ring_status |= LOBE_WIRE_FAULT;
4413 case TRANSMIT_BEACON:
4414 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
4415 tp->current_ring_status |= TRANSMIT_BEACON;
4419 printk(KERN_INFO "%s: Soft Error\n", dev->name);
4420 tp->current_ring_status |= SOFT_ERROR;
4424 printk(KERN_INFO "%s: Hard Error\n", dev->name);
4425 tp->current_ring_status |= HARD_ERROR;
4429 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
4430 tp->current_ring_status |= SIGNAL_LOSS;
4434 printk(KERN_INFO "%s: Unknown ring status change\n",
4442 static int smctr_rx_frame(struct net_device *dev)
4444 struct net_local *tp = netdev_priv(dev);
4445 __u16 queue, status, rx_size, err = 0;
4448 if(smctr_debug > 10)
4449 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4451 queue = tp->receive_queue_number;
4453 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4455 err = HARDWARE_FAILED;
4457 if(((status & 0x007f) == 0)
4458 || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4460 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4461 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4463 pbuff = smctr_get_rx_pointer(dev, queue);
4465 smctr_set_page(dev, pbuff);
4466 smctr_disable_16bit(dev);
4468 /* pbuff points to addr within one page */
4469 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4471 if(queue == NON_MAC_QUEUE)
4473 struct sk_buff *skb;
4475 skb = dev_alloc_skb(rx_size);
4477 skb_put(skb, rx_size);
4479 skb_copy_to_linear_data(skb, pbuff, rx_size);
4481 /* Update Counters */
4482 tp->MacStat.rx_packets++;
4483 tp->MacStat.rx_bytes += skb->len;
4485 /* Kick the packet on up. */
4486 skb->protocol = tr_type_trans(skb, dev);
4488 dev->last_rx = jiffies;
4493 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4494 rx_size, dev, status);
4497 smctr_enable_16bit(dev);
4498 smctr_set_page(dev, (__u8 *)tp->ram_access);
4499 smctr_update_rx_chain(dev, queue);
4508 static int smctr_send_dat(struct net_device *dev)
4510 struct net_local *tp = netdev_priv(dev);
4511 unsigned int i, err;
4515 if(smctr_debug > 10)
4516 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4518 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4519 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4521 return (OUT_OF_RESOURCES);
4524 /* Initialize DAT Data Fields. */
4525 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4526 tmf->ac = MSB(AC_FC_DAT);
4527 tmf->fc = LSB(AC_FC_DAT);
4529 for(i = 0; i < 6; i++)
4531 tmf->sa[i] = dev->dev_addr[i];
4532 tmf->da[i] = dev->dev_addr[i];
4537 tmf->dc_sc = DC_RS | SC_RS;
4539 tmf->vl = SWAP_BYTES(tmf->vl);
4541 /* Start Transmit. */
4542 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4545 /* Wait for Transmit to Complete */
4546 for(i = 0; i < 10000; i++)
4548 if(fcb->frame_status & FCB_COMMAND_DONE)
4553 /* Check if GOOD frame Tx'ed. */
4554 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4555 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4557 return (INITIALIZE_FAILED);
4560 /* De-allocated Tx FCB and Frame Buffer
4561 * The FCB must be de-allocated manually if executing with
4562 * interrupts disabled, other wise the ISR (LM_Service_Events)
4563 * will de-allocate it when the interrupt occurs.
4565 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4566 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4571 static void smctr_timeout(struct net_device *dev)
4574 * If we get here, some higher level has decided we are broken.
4575 * There should really be a "kick me" function call instead.
4577 * Resetting the token ring adapter takes a long time so just
4578 * fake transmission time and go on trying. Our own timeout
4579 * routine is in sktr_timer_chk()
4581 dev->trans_start = jiffies;
4582 netif_wake_queue(dev);
4586 * Gets skb from system, queues it and checks if it can be sent
4588 static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
4590 struct net_local *tp = netdev_priv(dev);
4592 if(smctr_debug > 10)
4593 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4596 * Block a transmit overlap
4599 netif_stop_queue(dev);
4601 if(tp->QueueSkb == 0)
4602 return (1); /* Return with tbusy set: queue full */
4605 skb_queue_tail(&tp->SendSkbQueue, skb);
4606 smctr_hardware_send_packet(dev, tp);
4607 if(tp->QueueSkb > 0)
4608 netif_wake_queue(dev);
4613 static int smctr_send_lobe_media_test(struct net_device *dev)
4615 struct net_local *tp = netdev_priv(dev);
4616 MAC_SUB_VECTOR *tsv;
4622 if(smctr_debug > 15)
4623 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4625 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4626 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4628 return (OUT_OF_RESOURCES);
4631 /* Initialize DAT Data Fields. */
4632 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4633 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4634 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4636 for(i = 0; i < 6; i++)
4639 tmf->sa[i] = dev->dev_addr[i];
4642 tmf->vc = LOBE_MEDIA_TEST;
4643 tmf->dc_sc = DC_RS | SC_RS;
4646 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4647 smctr_make_wrap_data(dev, tsv);
4648 tmf->vl += tsv->svl;
4650 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4651 smctr_make_wrap_data(dev, tsv);
4652 tmf->vl += tsv->svl;
4654 /* Start Transmit. */
4655 tmf->vl = SWAP_BYTES(tmf->vl);
4656 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4659 /* Wait for Transmit to Complete. (10 ms). */
4660 for(i=0; i < 10000; i++)
4662 if(fcb->frame_status & FCB_COMMAND_DONE)
4667 /* Check if GOOD frame Tx'ed */
4668 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4669 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4671 return (LOBE_MEDIA_TEST_FAILED);
4674 /* De-allocated Tx FCB and Frame Buffer
4675 * The FCB must be de-allocated manually if executing with
4676 * interrupts disabled, other wise the ISR (LM_Service_Events)
4677 * will de-allocate it when the interrupt occurs.
4679 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4680 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4685 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4689 MAC_SUB_VECTOR *tsv;
4692 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4693 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4694 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4695 == (FCBlock *)(-1L))
4700 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4702 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4705 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4707 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4708 smctr_make_corr(dev, tsv, correlator);
4710 tmf->vl += tsv->svl;
4711 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4712 smctr_make_phy_drop_num(dev, tsv);
4714 tmf->vl += tsv->svl;
4715 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4716 smctr_make_upstream_neighbor_addr(dev, tsv);
4718 tmf->vl += tsv->svl;
4719 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4720 smctr_make_addr_mod(dev, tsv);
4722 tmf->vl += tsv->svl;
4723 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4724 smctr_make_group_addr(dev, tsv);
4726 tmf->vl += tsv->svl;
4727 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4728 smctr_make_funct_addr(dev, tsv);
4730 tmf->vl += tsv->svl;
4732 /* Subtract out MVID and MVL which is
4733 * include in both vl and MAC_HEADER
4735 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4736 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4738 tmf->vl = SWAP_BYTES(tmf->vl);
4740 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4743 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4747 MAC_SUB_VECTOR *tsv;
4750 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4751 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4752 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4753 == (FCBlock *)(-1L))
4758 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4759 tmf->vc = RPT_ATTCH;
4760 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4763 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4765 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4766 smctr_make_corr(dev, tsv, correlator);
4768 tmf->vl += tsv->svl;
4769 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4770 smctr_make_product_id(dev, tsv);
4772 tmf->vl += tsv->svl;
4773 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4774 smctr_make_funct_addr(dev, tsv);
4776 tmf->vl += tsv->svl;
4777 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4778 smctr_make_auth_funct_class(dev, tsv);
4780 tmf->vl += tsv->svl;
4781 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4782 smctr_make_access_pri(dev, tsv);
4784 tmf->vl += tsv->svl;
4786 /* Subtract out MVID and MVL which is
4787 * include in both vl and MAC_HEADER
4789 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4790 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4792 tmf->vl = SWAP_BYTES(tmf->vl);
4794 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4797 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4801 MAC_SUB_VECTOR *tsv;
4804 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4805 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4806 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4807 == (FCBlock *)(-1L))
4812 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4813 tmf->vc = RPT_STATE;
4814 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4817 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4819 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4820 smctr_make_corr(dev, tsv, correlator);
4822 tmf->vl += tsv->svl;
4823 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4824 smctr_make_ring_station_version(dev, tsv);
4826 tmf->vl += tsv->svl;
4827 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4828 smctr_make_ring_station_status(dev, tsv);
4830 tmf->vl += tsv->svl;
4831 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4832 smctr_make_station_id(dev, tsv);
4834 tmf->vl += tsv->svl;
4836 /* Subtract out MVID and MVL which is
4837 * include in both vl and MAC_HEADER
4839 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4840 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4842 tmf->vl = SWAP_BYTES(tmf->vl);
4844 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4847 static int smctr_send_rpt_tx_forward(struct net_device *dev,
4848 MAC_HEADER *rmf, __u16 tx_fstatus)
4851 MAC_SUB_VECTOR *tsv;
4854 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4855 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4860 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4861 tmf->vc = RPT_TX_FORWARD;
4862 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4865 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4867 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4868 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4870 tmf->vl += tsv->svl;
4872 /* Subtract out MVID and MVL which is
4873 * include in both vl and MAC_HEADER
4875 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4876 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4878 tmf->vl = SWAP_BYTES(tmf->vl);
4880 return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4883 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4884 __u16 rcode, __u16 correlator)
4887 MAC_SUB_VECTOR *tsv;
4890 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4891 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4896 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4898 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4901 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4903 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4904 smctr_make_corr(dev, tsv, correlator);
4909 static int smctr_send_rq_init(struct net_device *dev)
4911 struct net_local *tp = netdev_priv(dev);
4913 MAC_SUB_VECTOR *tsv;
4915 unsigned int i, count = 0;
4920 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4921 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4922 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4923 == (FCBlock *)(-1L)))
4928 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4930 tmf->dc_sc = DC_RPS | SC_RS;
4933 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4935 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4936 smctr_make_product_id(dev, tsv);
4938 tmf->vl += tsv->svl;
4939 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4940 smctr_make_upstream_neighbor_addr(dev, tsv);
4942 tmf->vl += tsv->svl;
4943 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4944 smctr_make_ring_station_version(dev, tsv);
4946 tmf->vl += tsv->svl;
4947 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4948 smctr_make_addr_mod(dev, tsv);
4950 tmf->vl += tsv->svl;
4952 /* Subtract out MVID and MVL which is
4953 * include in both vl and MAC_HEADER
4955 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4956 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4958 tmf->vl = SWAP_BYTES(tmf->vl);
4960 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4963 /* Wait for Transmit to Complete */
4964 for(i = 0; i < 10000; i++)
4966 if(fcb->frame_status & FCB_COMMAND_DONE)
4971 /* Check if GOOD frame Tx'ed */
4972 fstatus = fcb->frame_status;
4974 if(!(fstatus & FCB_COMMAND_DONE))
4975 return (HARDWARE_FAILED);
4977 if(!(fstatus & FCB_TX_STATUS_E))
4980 /* De-allocated Tx FCB and Frame Buffer
4981 * The FCB must be de-allocated manually if executing with
4982 * interrupts disabled, other wise the ISR (LM_Service_Events)
4983 * will de-allocate it when the interrupt occurs.
4985 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4986 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4987 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4989 return (smctr_join_complete_state(dev));
4992 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4995 struct net_local *tp = netdev_priv(dev);
5000 /* Check if this is the END POINT of the Transmit Forward Chain. */
5004 /* Allocate Transmit FCB only by requesting 0 bytes
5007 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
5010 /* Set pointer to Transmit Frame Buffer to the data
5011 * portion of the received TX Forward frame, making
5012 * sure to skip over the Vector Code (vc) and Vector
5015 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5016 + sizeof(MAC_HEADER) + 2);
5017 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5018 + sizeof(MAC_HEADER) + 2);
5020 fcb->frame_length = rmf->vl - 4 - 2;
5021 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5023 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5026 /* Wait for Transmit to Complete */
5027 for(i = 0; i < 10000; i++)
5029 if(fcb->frame_status & FCB_COMMAND_DONE)
5034 /* Check if GOOD frame Tx'ed */
5035 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5037 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5040 for(i = 0; i < 10000; i++)
5042 if(fcb->frame_status & FCB_COMMAND_DONE)
5047 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5048 return (HARDWARE_FAILED);
5051 *tx_fstatus = fcb->frame_status;
5053 return (A_FRAME_WAS_FORWARDED);
5056 static int smctr_set_auth_access_pri(struct net_device *dev,
5057 MAC_SUB_VECTOR *rsv)
5059 struct net_local *tp = netdev_priv(dev);
5061 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5062 return (E_SUB_VECTOR_LENGTH_ERROR);
5064 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5066 return (POSITIVE_ACK);
5069 static int smctr_set_auth_funct_class(struct net_device *dev,
5070 MAC_SUB_VECTOR *rsv)
5072 struct net_local *tp = netdev_priv(dev);
5074 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5075 return (E_SUB_VECTOR_LENGTH_ERROR);
5077 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5079 return (POSITIVE_ACK);
5082 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5085 if(rsv->svl != S_CORRELATOR)
5086 return (E_SUB_VECTOR_LENGTH_ERROR);
5088 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5090 return (POSITIVE_ACK);
5093 static int smctr_set_error_timer_value(struct net_device *dev,
5094 MAC_SUB_VECTOR *rsv)
5099 if(rsv->svl != S_ERROR_TIMER_VALUE)
5100 return (E_SUB_VECTOR_LENGTH_ERROR);
5102 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5104 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5106 if((err = smctr_wait_cmd(dev)))
5109 return (POSITIVE_ACK);
5112 static int smctr_set_frame_forward(struct net_device *dev,
5113 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5115 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5116 return (E_SUB_VECTOR_LENGTH_ERROR);
5118 if((dc_sc & DC_MASK) != DC_CRS)
5120 if(rsv->svl >= 2 && rsv->svl < 20)
5121 return (E_TRANSMIT_FORWARD_INVALID);
5123 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5124 return (E_TRANSMIT_FORWARD_INVALID);
5127 return (POSITIVE_ACK);
5130 static int smctr_set_local_ring_num(struct net_device *dev,
5131 MAC_SUB_VECTOR *rsv)
5133 struct net_local *tp = netdev_priv(dev);
5135 if(rsv->svl != S_LOCAL_RING_NUMBER)
5136 return (E_SUB_VECTOR_LENGTH_ERROR);
5138 if(tp->ptr_local_ring_num)
5139 *(__u16 *)(tp->ptr_local_ring_num)
5140 = (rsv->svv[0] << 8 | rsv->svv[1]);
5142 return (POSITIVE_ACK);
5145 static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5147 struct net_local *tp = netdev_priv(dev);
5148 int ioaddr = dev->base_addr;
5150 if(tp->bic_type == BIC_585_CHIP)
5151 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5154 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5155 outb(tp->trc_mask, ioaddr + CSR);
5161 static void smctr_set_multicast_list(struct net_device *dev)
5163 if(smctr_debug > 10)
5164 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5169 static int smctr_set_page(struct net_device *dev, __u8 *buf)
5171 struct net_local *tp = netdev_priv(dev);
5175 tptr = (__u32)buf - (__u32)tp->ram_access;
5176 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5177 outb(amask, dev->base_addr + PR);
5182 static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5186 if(rsv->svl != S_PHYSICAL_DROP)
5187 return (E_SUB_VECTOR_LENGTH_ERROR);
5189 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5190 if((err = smctr_wait_cmd(dev)))
5193 return (POSITIVE_ACK);
5196 /* Reset the ring speed to the opposite of what it was. This auto-pilot
5197 * mode requires a complete reset and re-init of the adapter.
5199 static int smctr_set_ring_speed(struct net_device *dev)
5201 struct net_local *tp = netdev_priv(dev);
5204 if(tp->media_type == MEDIA_UTP_16)
5205 tp->media_type = MEDIA_UTP_4;
5207 tp->media_type = MEDIA_UTP_16;
5209 smctr_enable_16bit(dev);
5211 /* Re-Initialize adapter's internal registers */
5212 smctr_reset_adapter(dev);
5214 if((err = smctr_init_card_real(dev)))
5217 smctr_enable_bic_int(dev);
5219 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5222 smctr_disable_16bit(dev);
5227 static int smctr_set_rx_look_ahead(struct net_device *dev)
5229 struct net_local *tp = netdev_priv(dev);
5232 if(smctr_debug > 10)
5233 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5235 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5236 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5238 if(tp->adapter_bus == BUS_ISA16_TYPE)
5240 sword = *((__u16 *)(tp->ram_access));
5241 *((__u16 *)(tp->ram_access)) = 0x1234;
5243 smctr_disable_16bit(dev);
5244 rword = *((__u16 *)(tp->ram_access));
5245 smctr_enable_16bit(dev);
5248 tp->adapter_flags |= FORCED_16BIT_MODE;
5250 *((__u16 *)(tp->ram_access)) = sword;
5256 static int smctr_set_trc_reset(int ioaddr)
5260 r = inb(ioaddr + MSR);
5261 outb(MSR_RST | r, ioaddr + MSR);
5267 * This function can be called if the adapter is busy or not.
5269 static int smctr_setup_single_cmd(struct net_device *dev,
5270 __u16 command, __u16 subcommand)
5272 struct net_local *tp = netdev_priv(dev);
5275 if(smctr_debug > 10)
5276 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5278 if((err = smctr_wait_while_cbusy(dev)))
5281 if((err = (unsigned int)smctr_wait_cmd(dev)))
5284 tp->acb_head->cmd_done_status = 0;
5285 tp->acb_head->cmd = command;
5286 tp->acb_head->subcmd = subcommand;
5288 err = smctr_issue_resume_acb_cmd(dev);
5294 * This function can not be called with the adapter busy.
5296 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5297 __u16 command, __u16 subcommand)
5299 struct net_local *tp = netdev_priv(dev);
5301 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5302 tp->acb_head->cmd = command;
5303 tp->acb_head->subcmd = subcommand;
5304 tp->acb_head->data_offset_lo
5305 = (__u16)TRC_POINTER(tp->misc_command_data);
5307 return(smctr_issue_resume_acb_cmd(dev));
5310 static char *smctr_malloc(struct net_device *dev, __u16 size)
5312 struct net_local *tp = netdev_priv(dev);
5315 m = (char *)(tp->ram_access + tp->sh_mem_used);
5316 tp->sh_mem_used += (__u32)size;
5321 static int smctr_status_chg(struct net_device *dev)
5323 struct net_local *tp = netdev_priv(dev);
5325 if(smctr_debug > 10)
5326 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5336 /* Interrupt driven open() completion. XXX */
5338 tp->group_address_0 = 0;
5339 tp->group_address[0] = 0;
5340 tp->group_address[1] = 0;
5341 tp->functional_address_0 = 0;
5342 tp->functional_address[0] = 0;
5343 tp->functional_address[1] = 0;
5348 printk(KERN_INFO "%s: status change unknown %x\n",
5349 dev->name, tp->status);
5356 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5359 struct net_local *tp = netdev_priv(dev);
5362 if(smctr_debug > 10)
5363 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5365 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5366 if(tp->num_tx_fcbs[queue] != 1)
5367 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5369 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5371 tp->tx_queue_status[queue] = TRANSMITING;
5372 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5378 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5380 struct net_local *tp = netdev_priv(dev);
5381 __u16 status, err = 0;
5384 if(smctr_debug > 10)
5385 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5387 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5389 if(status & 0x7e00 )
5391 err = HARDWARE_FAILED;
5395 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5399 smctr_disable_16bit(dev);
5401 if(tp->mode_bits & UMAC)
5403 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5404 cstatus = NO_SUCH_DESTINATION;
5407 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5408 cstatus = DEST_OUT_OF_RESOURCES;
5411 if(status & FCB_TX_STATUS_E)
5412 cstatus = MAX_COLLISIONS;
5421 if(queue == BUG_QUEUE)
5424 smctr_enable_16bit(dev);
5432 static unsigned short smctr_tx_move_frame(struct net_device *dev,
5433 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5435 struct net_local *tp = netdev_priv(dev);
5436 unsigned int ram_usable;
5437 __u32 flen, len, offset = 0;
5440 if(smctr_debug > 10)
5441 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5443 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5447 while(flen > 0 && bytes > 0)
5449 smctr_set_page(dev, pbuff);
5451 offset = SMC_PAGE_OFFSET(pbuff);
5453 if(offset + flen > ram_usable)
5454 len = ram_usable - offset;
5461 page = (char *) (offset + tp->ram_access);
5462 memcpy(page, frag, len);
5473 /* Update the error statistic counters for this adapter. */
5474 static int smctr_update_err_stats(struct net_device *dev)
5476 struct net_local *tp = netdev_priv(dev);
5477 struct tr_statistics *tstat = &tp->MacStat;
5479 if(tstat->internal_errors)
5480 tstat->internal_errors
5481 += *(tp->misc_command_data + 0) & 0x00ff;
5483 if(tstat->line_errors)
5484 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5486 if(tstat->A_C_errors)
5487 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5489 if(tstat->burst_errors)
5490 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5492 if(tstat->abort_delimiters)
5493 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5495 if(tstat->recv_congest_count)
5496 tstat->recv_congest_count
5497 += *(tp->misc_command_data + 3) & 0x00ff;
5499 if(tstat->lost_frames)
5501 += *(tp->misc_command_data + 3) >> 8;
5503 if(tstat->frequency_errors)
5504 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5506 if(tstat->frame_copied_errors)
5507 tstat->frame_copied_errors
5508 += *(tp->misc_command_data + 4) >> 8;
5510 if(tstat->token_errors)
5511 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5516 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5518 struct net_local *tp = netdev_priv(dev);
5523 fcb = tp->rx_fcb_curr[queue];
5524 len = fcb->frame_length;
5526 fcb->frame_status = 0;
5527 fcb->info = FCB_CHAIN_END;
5528 fcb->back_ptr->info = FCB_WARNING;
5530 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5532 /* update RX BDBs */
5533 size = (len >> RX_BDB_SIZE_SHIFT);
5534 if(len & RX_DATA_BUFFER_SIZE_MASK)
5535 size += sizeof(BDBlock);
5536 size &= (~RX_BDB_SIZE_MASK);
5538 /* check if wrap around */
5539 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5540 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5542 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5543 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5546 bdb->back_ptr->info = BDB_CHAIN_END;
5547 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5548 tp->rx_bdb_curr[queue] = bdb;
5553 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5556 struct net_local *tp = netdev_priv(dev);
5558 if(smctr_debug > 20)
5559 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5561 if(tp->num_tx_fcbs_used[queue] <= 0)
5562 return (HARDWARE_FAILED);
5565 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5567 tp->tx_buff_used[queue] = 0;
5568 return (HARDWARE_FAILED);
5571 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5573 /* if all transmit buffer are cleared
5574 * need to set the tx_buff_curr[] to tx_buff_head[]
5575 * otherwise, tx buffer will be segregate and cannot
5576 * accommodate and buffer greater than (curr - head) and
5577 * (end - curr) since we do not allow wrap around allocation.
5579 if(tp->tx_buff_used[queue] == 0)
5580 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5582 tp->num_tx_fcbs_used[queue]--;
5583 fcb->frame_status = 0;
5584 tp->tx_fcb_end[queue] = fcb->next_ptr;
5585 netif_wake_queue(dev);
5590 static int smctr_wait_cmd(struct net_device *dev)
5592 struct net_local *tp = netdev_priv(dev);
5593 unsigned int loop_count = 0x20000;
5595 if(smctr_debug > 10)
5596 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5600 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5607 return(HARDWARE_FAILED);
5609 if(tp->acb_head->cmd_done_status & 0xff)
5610 return(HARDWARE_FAILED);
5615 static int smctr_wait_while_cbusy(struct net_device *dev)
5617 struct net_local *tp = netdev_priv(dev);
5618 unsigned int timeout = 0x20000;
5619 int ioaddr = dev->base_addr;
5622 if(tp->bic_type == BIC_585_CHIP)
5626 r = inb(ioaddr + HWR);
5627 if((r & HWR_CBUSY) == 0)
5636 r = inb(ioaddr + CSR);
5637 if((r & CSR_CBUSY) == 0)
5646 return (HARDWARE_FAILED);
5651 static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5652 static int io[SMCTR_MAX_ADAPTERS];
5653 static int irq[SMCTR_MAX_ADAPTERS];
5655 MODULE_LICENSE("GPL");
5657 module_param_array(io, int, NULL, 0);
5658 module_param_array(irq, int, NULL, 0);
5659 module_param(ringspeed, int, 0);
5661 static struct net_device * __init setup_card(int n)
5663 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5667 return ERR_PTR(-ENOMEM);
5670 err = smctr_probe1(dev, io[n]);
5674 err = register_netdev(dev);
5679 #ifdef CONFIG_MCA_LEGACY
5680 { struct net_local *tp = netdev_priv(dev);
5682 mca_mark_as_unused(tp->slot_num);
5685 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5686 free_irq(dev->irq, dev);
5689 return ERR_PTR(err);
5692 int __init init_module(void)
5695 struct net_device *dev;
5697 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5698 dev = io[0]? setup_card(i) : smctr_probe(-1);
5705 return found ? 0 : -ENODEV;
5708 void __exit cleanup_module(void)
5712 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5713 struct net_device *dev = dev_smctr[i];
5717 unregister_netdev(dev);
5718 #ifdef CONFIG_MCA_LEGACY
5719 { struct net_local *tp = netdev_priv(dev);
5721 mca_mark_as_unused(tp->slot_num);
5724 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5726 free_irq(dev->irq, dev);