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@lxorguk.ukuu.org.uk> 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/string.h>
40 #include <linux/time.h>
41 #include <linux/errno.h>
42 #include <linux/init.h>
43 #include <linux/mca-legacy.h>
44 #include <linux/delay.h>
45 #include <linux/netdevice.h>
46 #include <linux/etherdevice.h>
47 #include <linux/skbuff.h>
48 #include <linux/trdevice.h>
49 #include <linux/bitops.h>
50 #include <linux/firmware.h>
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 */
63 static const char version[] __initdata =
64 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 const struct firmware *fw);
108 static int smctr_disable_16bit(struct net_device *dev);
109 static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
110 static int smctr_disable_bic_int(struct net_device *dev);
113 static int smctr_enable_16bit(struct net_device *dev);
114 static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
115 static int smctr_enable_adapter_ram(struct net_device *dev);
116 static int smctr_enable_bic_int(struct net_device *dev);
119 static int __init smctr_get_boardid(struct net_device *dev, int mca);
120 static int smctr_get_group_address(struct net_device *dev);
121 static int smctr_get_functional_address(struct net_device *dev);
122 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
123 static int smctr_get_physical_drop_number(struct net_device *dev);
124 static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
125 static int smctr_get_station_id(struct net_device *dev);
126 static 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 netdev_tx_t smctr_send_packet(struct sk_buff *skb,
237 struct net_device *dev);
238 static int smctr_send_lobe_media_test(struct net_device *dev);
239 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
241 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
243 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
245 static int smctr_send_rpt_tx_forward(struct net_device *dev,
246 MAC_HEADER *rmf, __u16 tx_fstatus);
247 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
248 __u16 rcode, __u16 correlator);
249 static int smctr_send_rq_init(struct net_device *dev);
250 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
252 static int smctr_set_auth_access_pri(struct net_device *dev,
253 MAC_SUB_VECTOR *rsv);
254 static int smctr_set_auth_funct_class(struct net_device *dev,
255 MAC_SUB_VECTOR *rsv);
256 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
258 static int smctr_set_error_timer_value(struct net_device *dev,
259 MAC_SUB_VECTOR *rsv);
260 static int smctr_set_frame_forward(struct net_device *dev,
261 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
262 static int smctr_set_local_ring_num(struct net_device *dev,
263 MAC_SUB_VECTOR *rsv);
264 static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
265 static void smctr_set_multicast_list(struct net_device *dev);
266 static int smctr_set_page(struct net_device *dev, __u8 *buf);
267 static int smctr_set_phy_drop(struct net_device *dev,
268 MAC_SUB_VECTOR *rsv);
269 static int smctr_set_ring_speed(struct net_device *dev);
270 static int smctr_set_rx_look_ahead(struct net_device *dev);
271 static int smctr_set_trc_reset(int ioaddr);
272 static int smctr_setup_single_cmd(struct net_device *dev,
273 __u16 command, __u16 subcommand);
274 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
275 __u16 command, __u16 subcommand);
276 static char *smctr_malloc(struct net_device *dev, __u16 size);
277 static int smctr_status_chg(struct net_device *dev);
280 static void smctr_timeout(struct net_device *dev);
281 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
283 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
284 static unsigned short smctr_tx_move_frame(struct net_device *dev,
285 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
288 static int smctr_update_err_stats(struct net_device *dev);
289 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
290 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
294 static int smctr_wait_cmd(struct net_device *dev);
295 static int smctr_wait_while_cbusy(struct net_device *dev);
297 #define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
298 #define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
299 #define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
301 /* Allocate Adapter Shared Memory.
302 * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
303 * function "get_num_rx_bdbs" below!!!
305 * Order of memory allocation:
307 * 0. Initial System Configuration Block Pointer
308 * 1. System Configuration Block
309 * 2. System Control Block
310 * 3. Action Command Block
311 * 4. Interrupt Status Block
314 * 6. NON-MAC TX FCB'S
316 * 8. NON-MAC TX BDB'S
318 * 10. NON-MAC RX FCB'S
320 * 12. NON-MAC RX BDB'S
321 * 13. MAC TX Data Buffer( 1, 256 byte buffer)
322 * 14. MAC RX Data Buffer( 1, 256 byte buffer)
324 * 15. NON-MAC TX Data Buffer
325 * 16. NON-MAC RX Data Buffer
327 static int smctr_alloc_shared_memory(struct net_device *dev)
329 struct net_local *tp = netdev_priv(dev);
332 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
334 /* Allocate initial System Control Block pointer.
335 * This pointer is located in the last page, last offset - 4.
337 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
338 - (long)ISCP_BLOCK_SIZE);
340 /* Allocate System Control Blocks. */
341 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
342 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
344 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
345 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
347 tp->acb_head = (ACBlock *)smctr_malloc(dev,
348 sizeof(ACBlock)*tp->num_acbs);
349 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
351 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
352 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
354 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
355 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
357 /* Allocate transmit FCBs. */
358 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
359 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
361 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
362 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
364 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
365 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
367 /* Allocate transmit BDBs. */
368 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
369 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
371 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
372 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
374 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
375 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
377 /* Allocate receive FCBs. */
378 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
379 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
381 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
382 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
384 /* Allocate receive BDBs. */
385 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
386 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
388 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
390 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
391 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
393 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
395 /* Allocate MAC transmit buffers.
396 * MAC Tx Buffers doen't have to be on an ODD Boundry.
398 tp->tx_buff_head[MAC_QUEUE]
399 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
400 tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
401 tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
403 /* Allocate BUG transmit buffers. */
404 tp->tx_buff_head[BUG_QUEUE]
405 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
406 tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
407 tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
409 /* Allocate MAC receive data buffers.
410 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
412 tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
413 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
414 tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
416 /* Allocate Non-MAC transmit buffers.
417 * ?? For maximum Netware performance, put Tx Buffers on
418 * ODD Boundry and then restore malloc to Even Boundrys.
420 smctr_malloc(dev, 1L);
421 tp->tx_buff_head[NON_MAC_QUEUE]
422 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
423 tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
424 tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
425 smctr_malloc(dev, 1L);
427 /* Allocate Non-MAC receive data buffers.
428 * To guarantee a minimum of 256 contiguous memory to
429 * UM_Receive_Packet's lookahead pointer, before a page
430 * change or ring end is encountered, place each rx buffer on
431 * a 256 byte boundary.
433 smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
434 tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
435 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
436 tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
441 /* Enter Bypass state. */
442 static int smctr_bypass_state(struct net_device *dev)
447 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
449 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
454 static int smctr_checksum_firmware(struct net_device *dev)
456 struct net_local *tp = netdev_priv(dev);
457 __u16 i, checksum = 0;
460 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
462 smctr_enable_adapter_ctrl_store(dev);
464 for(i = 0; i < CS_RAM_SIZE; i += 2)
465 checksum += *((__u16 *)(tp->ram_access + i));
467 tp->microcode_version = *(__u16 *)(tp->ram_access
468 + CS_RAM_VERSION_OFFSET);
469 tp->microcode_version >>= 8;
471 smctr_disable_adapter_ctrl_store(dev);
479 static int __init smctr_chk_mca(struct net_device *dev)
481 #ifdef CONFIG_MCA_LEGACY
482 struct net_local *tp = netdev_priv(dev);
484 __u8 r1, r2, r3, r4, r5;
486 current_slot = mca_find_unused_adapter(smctr_posid, 0);
487 if(current_slot == MCA_NOTFOUND)
490 mca_set_adapter_name(current_slot, smctr_name);
491 mca_mark_as_used(current_slot);
492 tp->slot_num = current_slot;
494 r1 = mca_read_stored_pos(tp->slot_num, 2);
495 r2 = mca_read_stored_pos(tp->slot_num, 3);
498 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
500 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
502 r1 = inb(CNFG_POS_REG1);
503 r2 = inb(CNFG_POS_REG0);
505 tp->bic_type = BIC_594_CHIP;
508 r2 = mca_read_stored_pos(tp->slot_num, 2);
510 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
511 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
514 r5 = mca_read_stored_pos(tp->slot_num, 5);
534 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
535 release_region(dev->base_addr, SMCTR_IO_EXTENT);
540 r3 = mca_read_stored_pos(tp->slot_num, 3);
541 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
543 tp->ram_base += 0x010000;
545 tp->ram_base += 0xF00000;
551 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
552 tp->ram_size = (__u16)CNFG_SIZE_64KB;
553 tp->board_id |= TOKEN_MEDIA;
555 r4 = mca_read_stored_pos(tp->slot_num, 4);
556 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
558 tp->rom_base += 0x010000;
564 tp->rom_size = CNFG_SIZE_8KB;
567 tp->rom_size = CNFG_SIZE_16KB;
570 tp->rom_size = CNFG_SIZE_32KB;
573 tp->rom_size = ROM_DISABLE;
576 /* Get Media Type. */
577 r5 = mca_read_stored_pos(tp->slot_num, 5);
578 r5 &= CNFG_MEDIA_TYPE_MASK;
582 tp->media_type = MEDIA_STP_4;
586 tp->media_type = MEDIA_STP_16;
590 tp->media_type = MEDIA_UTP_16;
594 tp->media_type = MEDIA_UTP_4;
599 r2 = mca_read_stored_pos(tp->slot_num, 2);
601 tp->mode_bits |= EARLY_TOKEN_REL;
604 outb(CNFG_POS_CONTROL_REG, 0);
606 tp->board_id = smctr_get_boardid(dev, 1);
607 switch(tp->board_id & 0xffff)
610 smctr_model = "8115T/A";
614 if(tp->extra_info & CHIP_REV_MASK)
615 smctr_model = "8115T rev XE";
617 smctr_model = "8115T rev XD";
621 smctr_model = "Unknown";
628 #endif /* CONFIG_MCA_LEGACY */
631 static int smctr_chg_rx_mask(struct net_device *dev)
633 struct net_local *tp = netdev_priv(dev);
637 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
639 smctr_enable_16bit(dev);
640 smctr_set_page(dev, (__u8 *)tp->ram_access);
642 if(tp->mode_bits & LOOPING_MODE_MASK)
643 tp->config_word0 |= RX_OWN_BIT;
645 tp->config_word0 &= ~RX_OWN_BIT;
647 if(tp->receive_mask & PROMISCUOUS_MODE)
648 tp->config_word0 |= PROMISCUOUS_BIT;
650 tp->config_word0 &= ~PROMISCUOUS_BIT;
652 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
653 tp->config_word0 |= SAVBAD_BIT;
655 tp->config_word0 &= ~SAVBAD_BIT;
657 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
658 tp->config_word0 |= RXATMAC;
660 tp->config_word0 &= ~RXATMAC;
662 if(tp->receive_mask & ACCEPT_MULTI_PROM)
663 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
665 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
667 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
668 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
671 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
672 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
674 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
677 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
683 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
689 smctr_disable_16bit(dev);
694 static int smctr_clear_int(struct net_device *dev)
696 struct net_local *tp = netdev_priv(dev);
698 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
703 static int smctr_clear_trc_reset(int ioaddr)
707 r = inb(ioaddr + MSR);
708 outb(~MSR_RST & r, ioaddr + MSR);
714 * The inverse routine to smctr_open().
716 static int smctr_close(struct net_device *dev)
718 struct net_local *tp = netdev_priv(dev);
722 netif_stop_queue(dev);
726 /* Check to see if adapter is already in a closed state. */
727 if(tp->status != OPEN)
730 smctr_enable_16bit(dev);
731 smctr_set_page(dev, (__u8 *)tp->ram_access);
733 if((err = smctr_issue_remove_cmd(dev)))
735 smctr_disable_16bit(dev);
741 skb = skb_dequeue(&tp->SendSkbQueue);
752 static int smctr_decode_firmware(struct net_device *dev,
753 const struct firmware *fw)
755 struct net_local *tp = netdev_priv(dev);
756 short bit = 0x80, shift = 12;
757 DECODE_TREE_NODE *tree;
765 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
767 weight = *(long *)(fw->data + WEIGHT_OFFSET);
768 tsize = *(__u8 *)(fw->data + TREE_SIZE_OFFSET);
769 tree = (DECODE_TREE_NODE *)(fw->data + TREE_OFFSET);
770 ucode = (__u8 *)(fw->data + TREE_OFFSET
771 + (tsize * sizeof(DECODE_TREE_NODE)));
772 mem = (__u16 *)(tp->ram_access);
777 while((tree + branch)->tag != LEAF && weight)
779 branch = *ucode & bit ? (tree + branch)->llink
780 : (tree + branch)->rlink;
792 buff |= (tree + branch)->info << shift;
797 *(mem++) = SWAP_BYTES(buff);
803 /* The following assumes the Control Store Memory has
804 * been initialized to zero. If the last partial word
805 * is zero, it will not be written.
808 *(mem++) = SWAP_BYTES(buff);
813 static int smctr_disable_16bit(struct net_device *dev)
819 * On Exit, Adapter is:
820 * 1. TRC is in a reset state and un-initialized.
821 * 2. Adapter memory is enabled.
822 * 3. Control Store memory is out of context (-WCSS is 1).
824 static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
826 struct net_local *tp = netdev_priv(dev);
827 int ioaddr = dev->base_addr;
830 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
832 tp->trc_mask |= CSR_WCSS;
833 outb(tp->trc_mask, ioaddr + CSR);
838 static int smctr_disable_bic_int(struct net_device *dev)
840 struct net_local *tp = netdev_priv(dev);
841 int ioaddr = dev->base_addr;
843 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
844 | CSR_MSKTINT | CSR_WCSS;
845 outb(tp->trc_mask, ioaddr + CSR);
850 static int smctr_enable_16bit(struct net_device *dev)
852 struct net_local *tp = netdev_priv(dev);
855 if(tp->adapter_bus == BUS_ISA16_TYPE)
857 r = inb(dev->base_addr + LAAR);
858 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
865 * To enable the adapter control store memory:
866 * 1. Adapter must be in a RESET state.
867 * 2. Adapter memory must be enabled.
868 * 3. Control Store Memory is in context (-WCSS is 0).
870 static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
872 struct net_local *tp = netdev_priv(dev);
873 int ioaddr = dev->base_addr;
876 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
878 smctr_set_trc_reset(ioaddr);
879 smctr_enable_adapter_ram(dev);
881 tp->trc_mask &= ~CSR_WCSS;
882 outb(tp->trc_mask, ioaddr + CSR);
887 static int smctr_enable_adapter_ram(struct net_device *dev)
889 int ioaddr = dev->base_addr;
893 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
895 r = inb(ioaddr + MSR);
896 outb(MSR_MEMB | r, ioaddr + MSR);
901 static int smctr_enable_bic_int(struct net_device *dev)
903 struct net_local *tp = netdev_priv(dev);
904 int ioaddr = dev->base_addr;
910 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
911 outb(tp->trc_mask, ioaddr + CSR);
912 r = inb(ioaddr + IRR);
913 outb(r | IRR_IEN, ioaddr + IRR);
917 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
918 outb(tp->trc_mask, ioaddr + CSR);
919 r = inb(ioaddr + IMCCR);
920 outb(r | IMCCR_EIL, ioaddr + IMCCR);
927 static int __init smctr_chk_isa(struct net_device *dev)
929 struct net_local *tp = netdev_priv(dev);
930 int ioaddr = dev->base_addr;
931 __u8 r1, r2, b, chksum = 0;
937 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
939 if((ioaddr & 0x1F) != 0)
942 /* Grab the region so that no one else tries to probe our ioports. */
943 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
948 /* Checksum SMC node address */
949 for(i = 0; i < 8; i++)
951 b = inb(ioaddr + LAR0 + i);
955 if (chksum != NODE_ADDR_CKSUM)
958 b = inb(ioaddr + BDID);
959 if(b != BRD_ID_8115T)
961 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
965 /* Check for 8115T Board ID */
967 for(r = 0; r < 8; r++)
969 r1 = inb(ioaddr + 0x8 + r);
973 /* value of RegF adds up the sum to 0xFF */
974 if((r2 != 0xFF) && (r2 != 0xEE))
978 tp->board_id = smctr_get_boardid(dev, 0);
979 switch(tp->board_id & 0xffff)
982 smctr_model = "8115T/A";
986 if(tp->extra_info & CHIP_REV_MASK)
987 smctr_model = "8115T rev XE";
989 smctr_model = "8115T rev XD";
993 smctr_model = "Unknown";
997 /* Store BIC type. */
998 tp->bic_type = BIC_584_CHIP;
999 tp->nic_type = NIC_825_CHIP;
1002 tp->ram_usable = CNFG_SIZE_16KB;
1003 tp->ram_size = CNFG_SIZE_64KB;
1005 /* Get 58x Ram Base */
1009 r2 = inb(ioaddr + CNFG_LAAR_584);
1010 r2 &= CNFG_LAAR_MASK;
1012 r2 |= ((r1 & 0x38) >> 3);
1014 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1018 r1 = inb(ioaddr + CNFG_ICR_583);
1019 r1 &= CNFG_ICR_IR2_584;
1021 r2 = inb(ioaddr + CNFG_IRR_583);
1022 r2 &= CNFG_IRR_IRQS; /* 0x60 */
1044 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1061 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1065 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
1068 /* Get 58x Rom Base */
1069 r1 = inb(ioaddr + CNFG_BIO_583);
1073 tp->rom_base = (__u32)r1 << 13;
1075 /* Get 58x Rom Size */
1076 r1 = inb(ioaddr + CNFG_BIO_583);
1079 tp->rom_size = ROM_DISABLE;
1083 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1086 /* Get 58x Boot Status */
1087 r1 = inb(ioaddr + CNFG_GP2);
1089 tp->mode_bits &= (~BOOT_STATUS_MASK);
1091 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1092 tp->mode_bits |= BOOT_TYPE_1;
1094 /* Get 58x Zero Wait State */
1095 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1097 r1 = inb(ioaddr + CNFG_IRR_583);
1099 if(r1 & CNFG_IRR_ZWS)
1100 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1102 if(tp->board_id & BOARD_16BIT)
1104 r1 = inb(ioaddr + CNFG_LAAR_584);
1106 if(r1 & CNFG_LAAR_ZWS)
1107 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1110 /* Get 584 Media Menu */
1111 tp->media_menu = 14;
1112 r1 = inb(ioaddr + CNFG_IRR_583);
1114 tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1115 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1117 /* Get Advanced Features */
1118 if(((r1 & 0x6) >> 1) == 0x3)
1119 tp->media_type |= MEDIA_UTP_16;
1122 if(((r1 & 0x6) >> 1) == 0x2)
1123 tp->media_type |= MEDIA_STP_16;
1126 if(((r1 & 0x6) >> 1) == 0x1)
1127 tp->media_type |= MEDIA_UTP_4;
1130 tp->media_type |= MEDIA_STP_4;
1134 r1 = inb(ioaddr + CNFG_GP2);
1135 if(!(r1 & 0x2) ) /* GP2_ETRD */
1136 tp->mode_bits |= EARLY_TOKEN_REL;
1138 /* see if the chip is corrupted
1139 if(smctr_read_584_chksum(ioaddr))
1141 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1142 free_irq(dev->irq, dev);
1151 release_region(ioaddr, SMCTR_IO_EXTENT);
1156 static int __init smctr_get_boardid(struct net_device *dev, int mca)
1158 struct net_local *tp = netdev_priv(dev);
1159 int ioaddr = dev->base_addr;
1163 tp->board_id = BoardIdMask = 0;
1167 BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1168 tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT);
1172 BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1173 tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K
1174 + NIC_825_BIT + ALTERNATE_IRQ_BIT);
1179 r = inb(ioaddr + BID_REG_1);
1181 outb(r, ioaddr + BID_REG_1);
1182 r = inb(ioaddr + BID_REG_1);
1184 if(r & BID_SIXTEEN_BIT_BIT)
1186 tp->extra_info |= SLOT_16BIT;
1187 tp->adapter_bus = BUS_ISA16_TYPE;
1190 tp->adapter_bus = BUS_ISA8_TYPE;
1193 tp->adapter_bus = BUS_MCA_TYPE;
1195 /* Get Board Id Byte */
1196 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1198 /* if Major version > 1.0 then
1204 r1 = inb(ioaddr + BID_REG_1);
1206 r1 |= BID_OTHER_BIT;
1208 outb(r1, ioaddr + BID_REG_1);
1209 r1 = inb(ioaddr + BID_REG_3);
1212 r1 |= BID_ENGR_PAGE;
1214 outb(r1, ioaddr + BID_REG_3);
1215 r1 = inb(ioaddr + BID_REG_1);
1217 r1 |= (BID_RLA | BID_OTHER_BIT);
1219 outb(r1, ioaddr + BID_REG_1);
1221 r1 = inb(ioaddr + BID_REG_1);
1222 while(r1 & BID_RECALL_DONE_MASK)
1223 r1 = inb(ioaddr + BID_REG_1);
1225 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1227 /* clear chip rev bits */
1228 tp->extra_info &= ~CHIP_REV_MASK;
1229 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1231 r1 = inb(ioaddr + BID_REG_1);
1233 r1 |= BID_OTHER_BIT;
1235 outb(r1, ioaddr + BID_REG_1);
1236 r1 = inb(ioaddr + BID_REG_3);
1241 outb(r1, ioaddr + BID_REG_3);
1242 r1 = inb(ioaddr + BID_REG_1);
1247 outb(r1, ioaddr + BID_REG_1);
1248 r1 = inb(ioaddr + BID_REG_1);
1250 while(r1 & BID_RECALL_DONE_MASK)
1251 r1 = inb(ioaddr + BID_REG_1);
1253 return (BoardIdMask);
1256 static int smctr_get_group_address(struct net_device *dev)
1258 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1260 return(smctr_wait_cmd(dev));
1263 static int smctr_get_functional_address(struct net_device *dev)
1265 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1267 return(smctr_wait_cmd(dev));
1270 /* Calculate number of Non-MAC receive BDB's and data buffers.
1271 * This function must simulate allocateing shared memory exactly
1272 * as the allocate_shared_memory function above.
1274 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1276 struct net_local *tp = netdev_priv(dev);
1277 unsigned int mem_used = 0;
1279 /* Allocate System Control Blocks. */
1280 mem_used += sizeof(SCGBlock);
1282 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1283 mem_used += sizeof(SCLBlock);
1285 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1286 mem_used += sizeof(ACBlock) * tp->num_acbs;
1288 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1289 mem_used += sizeof(ISBlock);
1291 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1292 mem_used += MISC_DATA_SIZE;
1294 /* Allocate transmit FCB's. */
1295 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1297 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE];
1298 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE];
1299 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE];
1301 /* Allocate transmit BDBs. */
1302 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE];
1303 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE];
1304 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE];
1306 /* Allocate receive FCBs. */
1307 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE];
1308 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE];
1310 /* Allocate receive BDBs. */
1311 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1313 /* Allocate MAC transmit buffers.
1314 * MAC transmit buffers don't have to be on an ODD Boundry.
1316 mem_used += tp->tx_buff_size[MAC_QUEUE];
1318 /* Allocate BUG transmit buffers. */
1319 mem_used += tp->tx_buff_size[BUG_QUEUE];
1321 /* Allocate MAC receive data buffers.
1322 * MAC receive buffers don't have to be on a 256 byte boundary.
1324 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
1326 /* Allocate Non-MAC transmit buffers.
1327 * For maximum Netware performance, put Tx Buffers on
1328 * ODD Boundry,and then restore malloc to Even Boundrys.
1331 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1334 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1335 * AND NON-MAC RX DATA BUFFERS
1337 * Make sure the mem_used offset at this point is the
1338 * same as in allocate_shared memory or the following
1339 * boundary adjustment will be incorrect (i.e. not allocating
1340 * the non-mac receive buffers above cannot change the 256
1343 * Since this cannot be guaranteed, adding the full 256 bytes
1344 * to the amount of shared memory used at this point will guaranteed
1345 * that the rx data buffers do not overflow shared memory.
1349 return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock)));
1352 static int smctr_get_physical_drop_number(struct net_device *dev)
1354 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1356 return(smctr_wait_cmd(dev));
1359 static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1361 struct net_local *tp = netdev_priv(dev);
1364 bdb = (BDBlock *)((__u32)tp->ram_access
1365 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1367 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1369 return ((__u8 *)bdb->data_block_ptr);
1372 static int smctr_get_station_id(struct net_device *dev)
1374 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1376 return(smctr_wait_cmd(dev));
1380 * Get the current statistics. This may be called with the card open
1383 static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1385 struct net_local *tp = netdev_priv(dev);
1387 return ((struct net_device_stats *)&tp->MacStat);
1390 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1393 struct net_local *tp = netdev_priv(dev);
1396 unsigned short alloc_size;
1397 unsigned short *temp;
1399 if(smctr_debug > 20)
1400 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
1402 /* check if there is enough FCB blocks */
1403 if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue])
1404 return ((FCBlock *)(-1L));
1406 /* round off the input pkt size to the nearest even number */
1407 alloc_size = (bytes_count + 1) & 0xfffe;
1409 /* check if enough mem */
1410 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
1411 return ((FCBlock *)(-1L));
1413 /* check if past the end ;
1414 * if exactly enough mem to end of ring, alloc from front.
1415 * this avoids update of curr when curr = end
1417 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1418 >= (unsigned long)(tp->tx_buff_end[queue]))
1420 /* check if enough memory from ring head */
1421 alloc_size = alloc_size +
1422 (__u16)((__u32)tp->tx_buff_end[queue]
1423 - (__u32)tp->tx_buff_curr[queue]);
1425 if((tp->tx_buff_used[queue] + alloc_size)
1426 > tp->tx_buff_size[queue])
1428 return ((FCBlock *)(-1L));
1432 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
1435 tp->tx_buff_used[queue] += alloc_size;
1436 tp->num_tx_fcbs_used[queue]++;
1437 tp->tx_fcb_curr[queue]->frame_length = bytes_count;
1438 tp->tx_fcb_curr[queue]->memory_alloc = alloc_size;
1439 temp = tp->tx_buff_curr[queue];
1440 tp->tx_buff_curr[queue]
1441 = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe));
1443 pbdb = tp->tx_fcb_curr[queue]->bdb_ptr;
1444 pbdb->buffer_length = bytes_count;
1445 pbdb->data_block_ptr = temp;
1446 pbdb->trc_data_block_ptr = TRC_POINTER(temp);
1448 pFCB = tp->tx_fcb_curr[queue];
1449 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1454 static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1456 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1458 return(smctr_wait_cmd(dev));
1461 static int smctr_hardware_send_packet(struct net_device *dev,
1462 struct net_local *tp)
1464 struct tr_statistics *tstat = &tp->MacStat;
1465 struct sk_buff *skb;
1468 if(smctr_debug > 10)
1469 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1471 if(tp->status != OPEN)
1474 if(tp->monitor_state_ready != 1)
1479 /* Send first buffer from queue */
1480 skb = skb_dequeue(&tp->SendSkbQueue);
1486 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size) return (-1);
1488 smctr_enable_16bit(dev);
1489 smctr_set_page(dev, (__u8 *)tp->ram_access);
1491 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1492 == (FCBlock *)(-1L))
1494 smctr_disable_16bit(dev);
1498 smctr_tx_move_frame(dev, skb,
1499 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1501 smctr_set_page(dev, (__u8 *)fcb);
1503 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1506 tstat->tx_packets++;
1508 smctr_disable_16bit(dev);
1514 static int smctr_init_acbs(struct net_device *dev)
1516 struct net_local *tp = netdev_priv(dev);
1520 if(smctr_debug > 10)
1521 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1524 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1525 acb->cmd_info = ACB_CHAIN_END;
1528 acb->data_offset_lo = 0;
1529 acb->data_offset_hi = 0;
1531 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1532 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1534 for(i = 1; i < tp->num_acbs; i++)
1536 acb = acb->next_ptr;
1537 acb->cmd_done_status
1538 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1539 acb->cmd_info = ACB_CHAIN_END;
1542 acb->data_offset_lo = 0;
1543 acb->data_offset_hi = 0;
1545 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1546 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1549 acb->next_ptr = tp->acb_head;
1550 acb->trc_next_ptr = TRC_POINTER(tp->acb_head);
1551 tp->acb_next = tp->acb_head->next_ptr;
1552 tp->acb_curr = tp->acb_head->next_ptr;
1553 tp->num_acbs_used = 0;
1558 static int smctr_init_adapter(struct net_device *dev)
1560 struct net_local *tp = netdev_priv(dev);
1563 if(smctr_debug > 10)
1564 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
1566 tp->status = CLOSED;
1567 tp->page_offset_mask = (tp->ram_usable * 1024) - 1;
1568 skb_queue_head_init(&tp->SendSkbQueue);
1569 tp->QueueSkb = MAX_TX_QUEUE;
1571 if(!(tp->group_address_0 & 0x0080))
1572 tp->group_address_0 |= 0x00C0;
1574 if(!(tp->functional_address_0 & 0x00C0))
1575 tp->functional_address_0 |= 0x00C0;
1577 tp->functional_address[0] &= 0xFF7F;
1579 if(tp->authorized_function_classes == 0)
1580 tp->authorized_function_classes = 0x7FFF;
1582 if(tp->authorized_access_priority == 0)
1583 tp->authorized_access_priority = 0x06;
1585 smctr_disable_bic_int(dev);
1586 smctr_set_trc_reset(dev->base_addr);
1588 smctr_enable_16bit(dev);
1589 smctr_set_page(dev, (__u8 *)tp->ram_access);
1591 if(smctr_checksum_firmware(dev))
1593 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name); return (-ENOENT);
1596 if((err = smctr_ram_memory_test(dev)))
1598 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1602 smctr_set_rx_look_ahead(dev);
1603 smctr_load_node_addr(dev);
1605 /* Initialize adapter for Internal Self Test. */
1606 smctr_reset_adapter(dev);
1607 if((err = smctr_init_card_real(dev)))
1609 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1614 /* This routine clobbers the TRC's internal registers. */
1615 if((err = smctr_internal_self_test(dev)))
1617 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1622 /* Re-Initialize adapter's internal registers */
1623 smctr_reset_adapter(dev);
1624 if((err = smctr_init_card_real(dev)))
1626 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1631 smctr_enable_bic_int(dev);
1633 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1636 smctr_disable_16bit(dev);
1641 static int smctr_init_card_real(struct net_device *dev)
1643 struct net_local *tp = netdev_priv(dev);
1646 if(smctr_debug > 10)
1647 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1649 tp->sh_mem_used = 0;
1650 tp->num_acbs = NUM_OF_ACBS;
1652 /* Range Check Max Packet Size */
1653 if(tp->max_packet_size < 256)
1654 tp->max_packet_size = 256;
1657 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1658 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1661 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1662 / tp->max_packet_size) - 1;
1664 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1665 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1668 if(tp->num_of_tx_buffs == 0)
1669 tp->num_of_tx_buffs = 1;
1672 /* Tx queue constants */
1673 tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS;
1674 tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS;
1675 tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY;
1676 tp->tx_buff_used [BUG_QUEUE] = 0;
1677 tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING;
1679 tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS;
1680 tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS;
1681 tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY;
1682 tp->tx_buff_used [MAC_QUEUE] = 0;
1683 tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING;
1685 tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
1686 tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
1687 tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
1688 tp->tx_buff_used [NON_MAC_QUEUE] = 0;
1689 tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING;
1691 /* Receive Queue Constants */
1692 tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
1693 tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
1695 if(tp->extra_info & CHIP_REV_MASK)
1696 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1698 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1700 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1702 smctr_alloc_shared_memory(dev);
1703 smctr_init_shared_memory(dev);
1705 if((err = smctr_issue_init_timers_cmd(dev)))
1708 if((err = smctr_issue_init_txrx_cmd(dev)))
1710 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1717 static int smctr_init_rx_bdbs(struct net_device *dev)
1719 struct net_local *tp = netdev_priv(dev);
1724 if(smctr_debug > 10)
1725 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1727 for(i = 0; i < NUM_RX_QS_USED; i++)
1729 bdb = tp->rx_bdb_head[i];
1730 buf = tp->rx_buff_head[i];
1731 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
1732 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1733 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1734 bdb->data_block_ptr = buf;
1735 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1737 if(i == NON_MAC_QUEUE)
1738 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1740 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1742 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1744 bdb->next_ptr->back_ptr = bdb;
1745 bdb = bdb->next_ptr;
1746 buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
1747 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1748 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1749 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1750 bdb->data_block_ptr = buf;
1751 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1753 if(i == NON_MAC_QUEUE)
1754 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1756 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1759 bdb->next_ptr = tp->rx_bdb_head[i];
1760 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1762 tp->rx_bdb_head[i]->back_ptr = bdb;
1763 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1769 static int smctr_init_rx_fcbs(struct net_device *dev)
1771 struct net_local *tp = netdev_priv(dev);
1775 for(i = 0; i < NUM_RX_QS_USED; i++)
1777 fcb = tp->rx_fcb_head[i];
1778 fcb->frame_status = 0;
1779 fcb->frame_length = 0;
1780 fcb->info = FCB_CHAIN_END;
1781 fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
1782 if(i == NON_MAC_QUEUE)
1783 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1785 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1787 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1789 fcb->next_ptr->back_ptr = fcb;
1790 fcb = fcb->next_ptr;
1791 fcb->frame_status = 0;
1792 fcb->frame_length = 0;
1793 fcb->info = FCB_WARNING;
1795 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1797 if(i == NON_MAC_QUEUE)
1799 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1802 = TRC_POINTER(fcb->next_ptr);
1805 fcb->next_ptr = tp->rx_fcb_head[i];
1807 if(i == NON_MAC_QUEUE)
1808 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1810 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1812 tp->rx_fcb_head[i]->back_ptr = fcb;
1813 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1819 static int smctr_init_shared_memory(struct net_device *dev)
1821 struct net_local *tp = netdev_priv(dev);
1825 if(smctr_debug > 10)
1826 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1828 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1830 /* Initialize Initial System Configuration Point. (ISCP) */
1831 iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
1832 *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
1834 smctr_set_page(dev, (__u8 *)tp->ram_access);
1836 /* Initialize System Configuration Pointers. (SCP) */
1837 tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
1838 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
1839 | SCGB_BURST_LENGTH);
1841 tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr);
1842 tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head);
1843 tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr);
1844 tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2;
1846 /* Initialize System Control Block. (SCB) */
1847 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP;
1848 tp->sclb_ptr->iack_code = 0;
1849 tp->sclb_ptr->resume_control = 0;
1850 tp->sclb_ptr->int_mask_control = 0;
1851 tp->sclb_ptr->int_mask_state = 0;
1853 /* Initialize Interrupt Status Block. (ISB) */
1854 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1856 tp->isb_ptr->IStatus[i].IType = 0xf0;
1857 tp->isb_ptr->IStatus[i].ISubtype = 0;
1860 tp->current_isb_index = 0;
1862 /* Initialize Action Command Block. (ACB) */
1863 smctr_init_acbs(dev);
1865 /* Initialize transmit FCB's and BDB's. */
1866 smctr_link_tx_fcbs_to_bdbs(dev);
1867 smctr_init_tx_bdbs(dev);
1868 smctr_init_tx_fcbs(dev);
1870 /* Initialize receive FCB's and BDB's. */
1871 smctr_init_rx_bdbs(dev);
1872 smctr_init_rx_fcbs(dev);
1877 static int smctr_init_tx_bdbs(struct net_device *dev)
1879 struct net_local *tp = netdev_priv(dev);
1883 for(i = 0; i < NUM_TX_QS_USED; i++)
1885 bdb = tp->tx_bdb_head[i];
1886 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1887 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1888 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1890 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1892 bdb->next_ptr->back_ptr = bdb;
1893 bdb = bdb->next_ptr;
1894 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1896 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1899 bdb->next_ptr = tp->tx_bdb_head[i];
1900 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
1901 tp->tx_bdb_head[i]->back_ptr = bdb;
1907 static int smctr_init_tx_fcbs(struct net_device *dev)
1909 struct net_local *tp = netdev_priv(dev);
1913 for(i = 0; i < NUM_TX_QS_USED; i++)
1915 fcb = tp->tx_fcb_head[i];
1916 fcb->frame_status = 0;
1917 fcb->frame_length = 0;
1918 fcb->info = FCB_CHAIN_END;
1919 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1920 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1922 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1924 fcb->next_ptr->back_ptr = fcb;
1925 fcb = fcb->next_ptr;
1926 fcb->frame_status = 0;
1927 fcb->frame_length = 0;
1928 fcb->info = FCB_CHAIN_END;
1930 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1931 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1934 fcb->next_ptr = tp->tx_fcb_head[i];
1935 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1937 tp->tx_fcb_head[i]->back_ptr = fcb;
1938 tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr;
1939 tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr;
1940 tp->num_tx_fcbs_used[i] = 0;
1946 static int smctr_internal_self_test(struct net_device *dev)
1948 struct net_local *tp = netdev_priv(dev);
1951 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1954 if((err = smctr_wait_cmd(dev)))
1957 if(tp->acb_head->cmd_done_status & 0xff)
1960 if((err = smctr_issue_test_hic_cmd(dev)))
1963 if((err = smctr_wait_cmd(dev)))
1966 if(tp->acb_head->cmd_done_status & 0xff)
1969 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1972 if((err = smctr_wait_cmd(dev)))
1975 if(tp->acb_head->cmd_done_status & 0xff)
1982 * The typical workload of the driver: Handle the network interface interrupts.
1984 static irqreturn_t smctr_interrupt(int irq, void *dev_id)
1986 struct net_device *dev = dev_id;
1987 struct net_local *tp;
1989 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1990 __u16 err1, err = NOT_MY_INTERRUPT;
1991 __u8 isb_type, isb_subtype;
1994 ioaddr = dev->base_addr;
1995 tp = netdev_priv(dev);
1997 if(tp->status == NOT_INITIALIZED)
2000 spin_lock(&tp->lock);
2002 smctr_disable_bic_int(dev);
2003 smctr_enable_16bit(dev);
2005 smctr_clear_int(dev);
2007 /* First read the LSB */
2008 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2010 isb_index = tp->current_isb_index;
2011 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2012 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2014 (tp->current_isb_index)++;
2015 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2016 tp->current_isb_index = 0;
2018 if(isb_type >= 0x10)
2020 smctr_disable_16bit(dev);
2021 spin_unlock(&tp->lock);
2025 err = HARDWARE_FAILED;
2026 interrupt_ack_code = isb_index;
2027 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2029 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2033 case ISB_IMC_MAC_TYPE_3:
2034 smctr_disable_16bit(dev);
2039 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2043 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2047 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2051 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2054 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2058 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2062 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2066 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2069 case 8: /* diagnostic state */
2073 tp->monitor_state = MS_BEACON_TEST_STATE;
2074 if(smctr_lobe_media_test(dev))
2076 tp->ring_status_flags = RING_STATUS_CHANGED;
2077 tp->ring_status = AUTO_REMOVAL_ERROR;
2078 smctr_ring_status_chg(dev);
2079 smctr_bypass_state(dev);
2082 smctr_issue_insert_cmd(dev);
2085 /* case 0x0a-0xff, illegal states */
2090 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2091 err = smctr_ring_status_chg(dev);
2093 smctr_enable_16bit(dev);
2096 /* Type 0x02 - MAC Error Counters Interrupt
2097 * One or more MAC Error Counter is half full
2098 * MAC Error Counters
2099 * Lost_FR_Error_Counter
2100 * RCV_Congestion_Counter
2101 * FR_copied_Error_Counter
2102 * FREQ_Error_Counter
2103 * Token_Error_Counter
2104 * Line_Error_Counter
2105 * Internal_Error_Count
2107 case ISB_IMC_MAC_ERROR_COUNTERS:
2108 /* Read 802.5 Error Counters */
2109 err = smctr_issue_read_ring_status_cmd(dev);
2112 /* Type 0x04 - MAC Type 2 Interrupt
2113 * HOST needs to enqueue MAC Frame for transmission
2114 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2115 * TRC_Status_Changed_Indicate
2117 case ISB_IMC_MAC_TYPE_2:
2118 err = smctr_issue_read_ring_status_cmd(dev);
2122 /* Type 0x05 - TX Frame Interrupt (FI). */
2123 case ISB_IMC_TX_FRAME:
2124 /* BUG QUEUE for TRC stuck receive BUG */
2125 if(isb_subtype & TX_PENDING_PRIORITY_2)
2127 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2131 /* NON-MAC frames only */
2132 if(isb_subtype & TX_PENDING_PRIORITY_1)
2134 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2138 /* MAC frames only */
2139 if(isb_subtype & TX_PENDING_PRIORITY_0)
2140 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2142 /* Type 0x06 - TX END OF QUEUE (FE) */
2143 case ISB_IMC_END_OF_TX_QUEUE:
2145 if(isb_subtype & TX_PENDING_PRIORITY_2)
2147 /* ok to clear Receive FIFO overrun
2148 * imask send_BUG now completes.
2150 interrupt_unmask_bits |= 0x800;
2152 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2153 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2155 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2159 /* NON-MAC queue only */
2160 if(isb_subtype & TX_PENDING_PRIORITY_1)
2162 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2163 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2165 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2169 /* MAC queue only */
2170 if(isb_subtype & TX_PENDING_PRIORITY_0)
2172 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2173 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2176 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2180 /* Type 0x07 - NON-MAC RX Resource Interrupt
2181 * Subtype bit 12 - (BW) BDB warning
2182 * Subtype bit 13 - (FW) FCB warning
2183 * Subtype bit 14 - (BE) BDB End of chain
2184 * Subtype bit 15 - (FE) FCB End of chain
2186 case ISB_IMC_NON_MAC_RX_RESOURCE:
2187 tp->rx_fifo_overrun_count = 0;
2188 tp->receive_queue_number = NON_MAC_QUEUE;
2189 err1 = smctr_rx_frame(dev);
2191 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2193 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2195 if(tp->ptr_rx_fcb_overruns)
2196 (*tp->ptr_rx_fcb_overruns)++;
2199 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2201 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2203 if(tp->ptr_rx_bdb_overruns)
2204 (*tp->ptr_rx_bdb_overruns)++;
2209 /* Type 0x08 - MAC RX Resource Interrupt
2210 * Subtype bit 12 - (BW) BDB warning
2211 * Subtype bit 13 - (FW) FCB warning
2212 * Subtype bit 14 - (BE) BDB End of chain
2213 * Subtype bit 15 - (FE) FCB End of chain
2215 case ISB_IMC_MAC_RX_RESOURCE:
2216 tp->receive_queue_number = MAC_QUEUE;
2217 err1 = smctr_rx_frame(dev);
2219 if(isb_subtype & MAC_RX_RESOURCE_FE)
2221 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2224 if(tp->ptr_rx_fcb_overruns)
2225 (*tp->ptr_rx_fcb_overruns)++;
2228 if(isb_subtype & MAC_RX_RESOURCE_BE)
2230 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2233 if(tp->ptr_rx_bdb_overruns)
2234 (*tp->ptr_rx_bdb_overruns)++;
2239 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2240 case ISB_IMC_NON_MAC_RX_FRAME:
2241 tp->rx_fifo_overrun_count = 0;
2242 tp->receive_queue_number = NON_MAC_QUEUE;
2243 err = smctr_rx_frame(dev);
2246 /* Type 0x0A - MAC RX Frame Interrupt */
2247 case ISB_IMC_MAC_RX_FRAME:
2248 tp->receive_queue_number = MAC_QUEUE;
2249 err = smctr_rx_frame(dev);
2252 /* Type 0x0B - TRC status
2253 * TRC has encountered an error condition
2254 * subtype bit 14 - transmit FIFO underrun
2255 * subtype bit 15 - receive FIFO overrun
2257 case ISB_IMC_TRC_FIFO_STATUS:
2258 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2260 if(tp->ptr_tx_fifo_underruns)
2261 (*tp->ptr_tx_fifo_underruns)++;
2264 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2266 /* update overrun stuck receive counter
2267 * if >= 3, has to clear it by sending
2268 * back to back frames. We pick
2269 * DAT(duplicate address MAC frame)
2271 tp->rx_fifo_overrun_count++;
2273 if(tp->rx_fifo_overrun_count >= 3)
2275 tp->rx_fifo_overrun_count = 0;
2277 /* delay clearing fifo overrun
2278 * imask till send_BUG tx
2281 interrupt_unmask_bits &= (~0x800);
2282 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2285 if(tp->ptr_rx_fifo_overruns)
2286 (*tp->ptr_rx_fifo_overruns)++;
2292 /* Type 0x0C - Action Command Status Interrupt
2293 * Subtype bit 14 - CB end of command chain (CE)
2294 * Subtype bit 15 - CB command interrupt (CI)
2296 case ISB_IMC_COMMAND_STATUS:
2298 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2300 printk(KERN_ERR "i1\n");
2301 smctr_disable_16bit(dev);
2303 /* XXXXXXXXXXXXXXXXX */
2304 /* err = UM_Interrupt(dev); */
2306 smctr_enable_16bit(dev);
2310 if((tp->acb_head->cmd
2311 == ACB_CMD_READ_TRC_STATUS) &&
2312 (tp->acb_head->subcmd
2313 == RW_TRC_STATUS_BLOCK))
2315 if(tp->ptr_bcn_type)
2318 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2321 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2323 smctr_update_err_stats(dev);
2326 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2329 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2330 smctr_disable_16bit(dev);
2331 err = smctr_ring_status_chg(dev);
2332 smctr_enable_16bit(dev);
2333 if((tp->ring_status & REMOVE_RECEIVED) &&
2334 (tp->config_word0 & NO_AUTOREMOVE))
2336 smctr_issue_remove_cmd(dev);
2341 tp->acb_pending = 0;
2346 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2350 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2351 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2352 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2357 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2358 err = smctr_send_rq_init(dev);
2363 tp->acb_pending = 0;
2366 /* Type 0x0D - MAC Type 1 interrupt
2367 * Subtype -- 00 FR_BCN received at S12
2368 * 01 FR_BCN received at S21
2369 * 02 FR_DAT(DA=MA, A<>0) received at S21
2371 * 04 FR_REMOVE received at S42
2372 * 05 TBR_EXP, BR_FLAG_SET at S42
2375 case ISB_IMC_MAC_TYPE_1:
2378 err = HARDWARE_FAILED;
2386 tp->join_state = JS_BYPASS_STATE;
2387 if(tp->status != CLOSED)
2389 tp->status = CLOSED;
2390 err = smctr_status_chg(dev);
2395 tp->join_state = JS_LOBE_TEST_STATE;
2399 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2403 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2407 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2411 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2415 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2419 tp->join_state = JS_JOIN_COMPLETE_STATE;
2421 err = smctr_status_chg(dev);
2425 tp->join_state = JS_BYPASS_WAIT_STATE;
2430 /* Type 0x0E - TRC Initialization Sequence Interrupt
2431 * Subtype -- 00-FF Initializatin sequence complete
2433 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2434 tp->status = INITIALIZED;
2435 smctr_disable_16bit(dev);
2436 err = smctr_status_chg(dev);
2437 smctr_enable_16bit(dev);
2440 /* other interrupt types, illegal */
2449 /* Checking the ack code instead of the unmask bits here is because :
2450 * while fixing the stuck receive, DAT frame are sent and mask off
2451 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2452 * but we still want to issue ack to ISB
2454 if(!(interrupt_ack_code & 0xff00))
2455 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2457 smctr_disable_16bit(dev);
2458 smctr_enable_bic_int(dev);
2459 spin_unlock(&tp->lock);
2464 static int smctr_issue_enable_int_cmd(struct net_device *dev,
2465 __u16 interrupt_enable_mask)
2467 struct net_local *tp = netdev_priv(dev);
2470 if((err = smctr_wait_while_cbusy(dev)))
2473 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2474 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2476 smctr_set_ctrl_attention(dev);
2481 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2483 struct net_local *tp = netdev_priv(dev);
2485 if(smctr_wait_while_cbusy(dev))
2488 tp->sclb_ptr->int_mask_control = ibits;
2489 tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0;
2490 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2492 smctr_set_ctrl_attention(dev);
2497 static int smctr_issue_init_timers_cmd(struct net_device *dev)
2499 struct net_local *tp = netdev_priv(dev);
2502 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2504 if((err = smctr_wait_while_cbusy(dev)))
2507 if((err = smctr_wait_cmd(dev)))
2510 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2511 tp->config_word1 = 0;
2513 if((tp->media_type == MEDIA_STP_16) ||
2514 (tp->media_type == MEDIA_UTP_16) ||
2515 (tp->media_type == MEDIA_STP_16_UTP_16))
2517 tp->config_word0 |= FREQ_16MB_BIT;
2520 if(tp->mode_bits & EARLY_TOKEN_REL)
2521 tp->config_word0 |= ETREN;
2523 if(tp->mode_bits & LOOPING_MODE_MASK)
2524 tp->config_word0 |= RX_OWN_BIT;
2526 tp->config_word0 &= ~RX_OWN_BIT;
2528 if(tp->receive_mask & PROMISCUOUS_MODE)
2529 tp->config_word0 |= PROMISCUOUS_BIT;
2531 tp->config_word0 &= ~PROMISCUOUS_BIT;
2533 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2534 tp->config_word0 |= SAVBAD_BIT;
2536 tp->config_word0 &= ~SAVBAD_BIT;
2538 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2539 tp->config_word0 |= RXATMAC;
2541 tp->config_word0 &= ~RXATMAC;
2543 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2544 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2546 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2548 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2549 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2552 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2553 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2555 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2558 if((tp->media_type == MEDIA_STP_16) ||
2559 (tp->media_type == MEDIA_UTP_16) ||
2560 (tp->media_type == MEDIA_STP_16_UTP_16))
2562 tp->config_word1 |= INTERFRAME_SPACING_16;
2565 tp->config_word1 |= INTERFRAME_SPACING_4;
2567 *pTimer_Struc++ = tp->config_word0;
2568 *pTimer_Struc++ = tp->config_word1;
2570 if((tp->media_type == MEDIA_STP_4) ||
2571 (tp->media_type == MEDIA_UTP_4) ||
2572 (tp->media_type == MEDIA_STP_4_UTP_4))
2574 *pTimer_Struc++ = 0x00FA; /* prescale */
2575 *pTimer_Struc++ = 0x2710; /* TPT_limit */
2576 *pTimer_Struc++ = 0x2710; /* TQP_limit */
2577 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2578 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2579 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2580 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2581 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2582 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2583 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2584 *pTimer_Struc++ = 0x1162; /* THT_limit */
2585 *pTimer_Struc++ = 0x07D0; /* TRR_limit */
2586 *pTimer_Struc++ = 0x1388; /* TVX_limit */
2587 *pTimer_Struc++ = 0x0000; /* reserved */
2591 *pTimer_Struc++ = 0x03E8; /* prescale */
2592 *pTimer_Struc++ = 0x9C40; /* TPT_limit */
2593 *pTimer_Struc++ = 0x9C40; /* TQP_limit */
2594 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2595 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2596 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2597 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2598 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2599 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2600 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2601 *pTimer_Struc++ = 0x4588; /* THT_limit */
2602 *pTimer_Struc++ = 0x1F40; /* TRR_limit */
2603 *pTimer_Struc++ = 0x4E20; /* TVX_limit */
2604 *pTimer_Struc++ = 0x0000; /* reserved */
2607 /* Set node address. */
2608 *pTimer_Struc++ = dev->dev_addr[0] << 8
2609 | (dev->dev_addr[1] & 0xFF);
2610 *pTimer_Struc++ = dev->dev_addr[2] << 8
2611 | (dev->dev_addr[3] & 0xFF);
2612 *pTimer_Struc++ = dev->dev_addr[4] << 8
2613 | (dev->dev_addr[5] & 0xFF);
2615 /* Set group address. */
2616 *pTimer_Struc++ = tp->group_address_0 << 8
2617 | tp->group_address_0 >> 8;
2618 *pTimer_Struc++ = tp->group_address[0] << 8
2619 | tp->group_address[0] >> 8;
2620 *pTimer_Struc++ = tp->group_address[1] << 8
2621 | tp->group_address[1] >> 8;
2623 /* Set functional address. */
2624 *pTimer_Struc++ = tp->functional_address_0 << 8
2625 | tp->functional_address_0 >> 8;
2626 *pTimer_Struc++ = tp->functional_address[0] << 8
2627 | tp->functional_address[0] >> 8;
2628 *pTimer_Struc++ = tp->functional_address[1] << 8
2629 | tp->functional_address[1] >> 8;
2631 /* Set Bit-Wise group address. */
2632 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2633 | tp->bitwise_group_address[0] >> 8;
2634 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2635 | tp->bitwise_group_address[1] >> 8;
2637 /* Set ring number address. */
2638 *pTimer_Struc++ = tp->source_ring_number;
2639 *pTimer_Struc++ = tp->target_ring_number;
2641 /* Physical drop number. */
2642 *pTimer_Struc++ = (unsigned short)0;
2643 *pTimer_Struc++ = (unsigned short)0;
2645 /* Product instance ID. */
2646 for(i = 0; i < 9; i++)
2647 *pTimer_Struc++ = (unsigned short)0;
2649 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2654 static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2656 struct net_local *tp = netdev_priv(dev);
2659 void **txrx_ptrs = (void *)tp->misc_command_data;
2661 if((err = smctr_wait_while_cbusy(dev)))
2664 if((err = smctr_wait_cmd(dev)))
2666 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2670 /* Initialize Transmit Queue Pointers that are used, to point to
2673 for(i = 0; i < NUM_TX_QS_USED; i++)
2674 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2676 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2677 for(; i < MAX_TX_QS; i++)
2678 *txrx_ptrs++ = (void *)0;
2680 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2681 * used, to point to a single FCB and a BDB chain of buffers.
2683 for(i = 0; i < NUM_RX_QS_USED; i++)
2685 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2686 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2689 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2690 for(; i < MAX_RX_QS; i++)
2692 *txrx_ptrs++ = (void *)0;
2693 *txrx_ptrs++ = (void *)0;
2696 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2701 static int smctr_issue_insert_cmd(struct net_device *dev)
2705 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2710 static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2714 if((err = smctr_wait_while_cbusy(dev)))
2717 if((err = smctr_wait_cmd(dev)))
2720 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2721 RW_TRC_STATUS_BLOCK);
2726 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2730 if((err = smctr_wait_while_cbusy(dev)))
2733 if((err = smctr_wait_cmd(dev)))
2736 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2742 static int smctr_issue_remove_cmd(struct net_device *dev)
2744 struct net_local *tp = netdev_priv(dev);
2747 if((err = smctr_wait_while_cbusy(dev)))
2750 tp->sclb_ptr->resume_control = 0;
2751 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2753 smctr_set_ctrl_attention(dev);
2758 static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2760 struct net_local *tp = netdev_priv(dev);
2763 if((err = smctr_wait_while_cbusy(dev)))
2766 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2767 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2769 tp->acb_pending = 1;
2771 smctr_set_ctrl_attention(dev);
2776 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2778 struct net_local *tp = netdev_priv(dev);
2781 if((err = smctr_wait_while_cbusy(dev)))
2784 if(queue == MAC_QUEUE)
2785 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2787 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2789 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2791 smctr_set_ctrl_attention(dev);
2796 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2798 struct net_local *tp = netdev_priv(dev);
2800 if(smctr_debug > 10)
2801 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2803 if(smctr_wait_while_cbusy(dev))
2806 if(queue == MAC_QUEUE)
2807 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2809 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2811 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2813 smctr_set_ctrl_attention(dev);
2818 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2820 struct net_local *tp = netdev_priv(dev);
2822 if(smctr_debug > 10)
2823 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2825 if(smctr_wait_while_cbusy(dev))
2828 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2829 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2831 smctr_set_ctrl_attention(dev);
2836 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2840 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2841 TRC_INTERNAL_ROM_TEST);
2846 static int smctr_issue_test_hic_cmd(struct net_device *dev)
2850 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2851 TRC_HOST_INTERFACE_REG_TEST);
2856 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2860 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2861 TRC_MAC_REGISTERS_TEST);
2866 static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2870 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2871 TRC_INTERNAL_LOOPBACK);
2876 static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2880 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2886 static int smctr_issue_write_byte_cmd(struct net_device *dev,
2887 short aword_cnt, void *byte)
2889 struct net_local *tp = netdev_priv(dev);
2890 unsigned int iword, ibyte;
2893 if((err = smctr_wait_while_cbusy(dev)))
2896 if((err = smctr_wait_cmd(dev)))
2899 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2900 iword++, ibyte += 2)
2902 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2903 | (*((__u8 *)byte + ibyte + 1));
2906 return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2910 static int smctr_issue_write_word_cmd(struct net_device *dev,
2911 short aword_cnt, void *word)
2913 struct net_local *tp = netdev_priv(dev);
2914 unsigned int i, err;
2916 if((err = smctr_wait_while_cbusy(dev)))
2919 if((err = smctr_wait_cmd(dev)))
2922 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2923 tp->misc_command_data[i] = *((__u16 *)word + i);
2925 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2931 static int smctr_join_complete_state(struct net_device *dev)
2935 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2936 JS_JOIN_COMPLETE_STATE);
2941 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2943 struct net_local *tp = netdev_priv(dev);
2948 for(i = 0; i < NUM_TX_QS_USED; i++)
2950 fcb = tp->tx_fcb_head[i];
2951 bdb = tp->tx_bdb_head[i];
2953 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2956 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2957 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2958 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2965 static int smctr_load_firmware(struct net_device *dev)
2967 struct net_local *tp = netdev_priv(dev);
2968 const struct firmware *fw;
2969 __u16 i, checksum = 0;
2972 if(smctr_debug > 10)
2973 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2975 if (request_firmware(&fw, "tr_smctr.bin", &dev->dev)) {
2976 printk(KERN_ERR "%s: firmware not found\n", dev->name);
2977 return (UCODE_NOT_PRESENT);
2980 tp->num_of_tx_buffs = 4;
2981 tp->mode_bits |= UMAC;
2982 tp->receive_mask = 0;
2983 tp->max_packet_size = 4177;
2985 /* Can only upload the firmware once per adapter reset. */
2986 if (tp->microcode_version != 0) {
2987 err = (UCODE_PRESENT);
2991 /* Verify the firmware exists and is there in the right amount. */
2993 (*(fw->data + UCODE_VERSION_OFFSET) < UCODE_VERSION))
2995 err = (UCODE_NOT_PRESENT);
2999 /* UCODE_SIZE is not included in Checksum. */
3000 for(i = 0; i < *((__u16 *)(fw->data + UCODE_SIZE_OFFSET)); i += 2)
3001 checksum += *((__u16 *)(fw->data + 2 + i));
3003 err = (UCODE_NOT_PRESENT);
3007 /* At this point we have a valid firmware image, lets kick it on up. */
3008 smctr_enable_adapter_ram(dev);
3009 smctr_enable_16bit(dev);
3010 smctr_set_page(dev, (__u8 *)tp->ram_access);
3012 if((smctr_checksum_firmware(dev)) ||
3013 (*(fw->data + UCODE_VERSION_OFFSET) > tp->microcode_version))
3015 smctr_enable_adapter_ctrl_store(dev);
3017 /* Zero out ram space for firmware. */
3018 for(i = 0; i < CS_RAM_SIZE; i += 2)
3019 *((__u16 *)(tp->ram_access + i)) = 0;
3021 smctr_decode_firmware(dev, fw);
3023 tp->microcode_version = *(fw->data + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
3024 = (tp->microcode_version << 8);
3025 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3026 = ~(tp->microcode_version << 8) + 1;
3028 smctr_disable_adapter_ctrl_store(dev);
3030 if(smctr_checksum_firmware(dev))
3031 err = HARDWARE_FAILED;
3034 err = UCODE_PRESENT;
3036 smctr_disable_16bit(dev);
3038 release_firmware(fw);
3042 static int smctr_load_node_addr(struct net_device *dev)
3044 int ioaddr = dev->base_addr;
3048 for(i = 0; i < 6; i++)
3050 r = inb(ioaddr + LAR0 + i);
3051 dev->dev_addr[i] = (char)r;
3059 * During the transmission of the initial 1500 lobe media MAC frames,
3060 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3061 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3062 * microcode will not transmit any frames given to it by the host, and
3063 * will consequently cause a timeout.
3065 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
3066 * queues other than the one used for the lobe_media_test should be
3069 * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
3070 * has any multi-cast or promiscous bits set, the receive_mask needs to
3071 * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
3072 * run, and then the receive mask set back to its original value if the test
3075 static int smctr_lobe_media_test(struct net_device *dev)
3077 struct net_local *tp = netdev_priv(dev);
3078 unsigned int i, perror = 0;
3079 unsigned short saved_rcv_mask;
3081 if(smctr_debug > 10)
3082 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3084 /* Clear receive mask for lobe test. */
3085 saved_rcv_mask = tp->receive_mask;
3086 tp->receive_mask = 0;
3088 smctr_chg_rx_mask(dev);
3090 /* Setup the lobe media test. */
3091 smctr_lobe_media_test_cmd(dev);
3092 if(smctr_wait_cmd(dev))
3095 /* Tx lobe media test frames. */
3096 for(i = 0; i < 1500; ++i)
3098 if(smctr_send_lobe_media_test(dev))
3105 if(smctr_lobe_media_test_cmd(dev))
3111 if(smctr_send_dat(dev))
3113 if(smctr_send_dat(dev))
3117 /* Check if any frames received during test. */
3118 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status) ||
3119 (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3122 /* Set receive mask to "Promisc" mode. */
3123 tp->receive_mask = saved_rcv_mask;
3125 smctr_chg_rx_mask(dev);
3129 smctr_reset_adapter(dev);
3130 tp->status = CLOSED;
3131 return LOBE_MEDIA_TEST_FAILED;
3134 static int smctr_lobe_media_test_cmd(struct net_device *dev)
3136 struct net_local *tp = netdev_priv(dev);
3139 if(smctr_debug > 10)
3140 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3142 /* Change to lobe media test state. */
3143 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3145 smctr_lobe_media_test_state(dev);
3146 if(smctr_wait_cmd(dev))
3148 printk(KERN_ERR "Lobe Failed test state\n");
3149 return (LOBE_MEDIA_TEST_FAILED);
3153 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3154 TRC_LOBE_MEDIA_TEST);
3159 static int smctr_lobe_media_test_state(struct net_device *dev)
3163 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3164 JS_LOBE_TEST_STATE);
3169 static int smctr_make_8025_hdr(struct net_device *dev,
3170 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3172 tmf->ac = MSB(ac_fc); /* msb is access control */
3173 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3175 tmf->sa[0] = dev->dev_addr[0];
3176 tmf->sa[1] = dev->dev_addr[1];
3177 tmf->sa[2] = dev->dev_addr[2];
3178 tmf->sa[3] = dev->dev_addr[3];
3179 tmf->sa[4] = dev->dev_addr[4];
3180 tmf->sa[5] = dev->dev_addr[5];
3184 /* Send RQ_INIT to RPS */
3194 /* Send RPT_TX_FORWARD to CRS */
3195 case RPT_TX_FORWARD:
3204 /* Everything else goes to sender */
3206 tmf->da[0] = rmf->sa[0];
3207 tmf->da[1] = rmf->sa[1];
3208 tmf->da[2] = rmf->sa[2];
3209 tmf->da[3] = rmf->sa[3];
3210 tmf->da[4] = rmf->sa[4];
3211 tmf->da[5] = rmf->sa[5];
3218 static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3220 struct net_local *tp = netdev_priv(dev);
3222 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3223 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3225 tsv->svv[0] = MSB(tp->authorized_access_priority);
3226 tsv->svv[1] = LSB(tp->authorized_access_priority);
3231 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3233 tsv->svi = ADDRESS_MODIFER;
3234 tsv->svl = S_ADDRESS_MODIFER;
3242 static int smctr_make_auth_funct_class(struct net_device *dev,
3243 MAC_SUB_VECTOR *tsv)
3245 struct net_local *tp = netdev_priv(dev);
3247 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3248 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3250 tsv->svv[0] = MSB(tp->authorized_function_classes);
3251 tsv->svv[1] = LSB(tp->authorized_function_classes);
3256 static int smctr_make_corr(struct net_device *dev,
3257 MAC_SUB_VECTOR *tsv, __u16 correlator)
3259 tsv->svi = CORRELATOR;
3260 tsv->svl = S_CORRELATOR;
3262 tsv->svv[0] = MSB(correlator);
3263 tsv->svv[1] = LSB(correlator);
3268 static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3270 struct net_local *tp = netdev_priv(dev);
3272 smctr_get_functional_address(dev);
3274 tsv->svi = FUNCTIONAL_ADDRESS;
3275 tsv->svl = S_FUNCTIONAL_ADDRESS;
3277 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3278 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3280 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3281 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3286 static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3288 struct net_local *tp = netdev_priv(dev);
3290 smctr_get_group_address(dev);
3292 tsv->svi = GROUP_ADDRESS;
3293 tsv->svl = S_GROUP_ADDRESS;
3295 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3296 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3298 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3299 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3301 /* Set Group Address Sub-vector to all zeros if only the
3302 * Group Address/Functional Address Indicator is set.
3304 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00 &&
3305 tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3311 static int smctr_make_phy_drop_num(struct net_device *dev,
3312 MAC_SUB_VECTOR *tsv)
3314 struct net_local *tp = netdev_priv(dev);
3316 smctr_get_physical_drop_number(dev);
3318 tsv->svi = PHYSICAL_DROP;
3319 tsv->svl = S_PHYSICAL_DROP;
3321 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3322 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3324 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3325 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3330 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3334 tsv->svi = PRODUCT_INSTANCE_ID;
3335 tsv->svl = S_PRODUCT_INSTANCE_ID;
3337 for(i = 0; i < 18; i++)
3343 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3345 struct net_local *tp = netdev_priv(dev);
3347 smctr_get_station_id(dev);
3349 tsv->svi = STATION_IDENTIFER;
3350 tsv->svl = S_STATION_IDENTIFER;
3352 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3353 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3355 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3356 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3358 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3359 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3364 static int smctr_make_ring_station_status(struct net_device *dev,
3365 MAC_SUB_VECTOR * tsv)
3367 tsv->svi = RING_STATION_STATUS;
3368 tsv->svl = S_RING_STATION_STATUS;
3380 static int smctr_make_ring_station_version(struct net_device *dev,
3381 MAC_SUB_VECTOR *tsv)
3383 struct net_local *tp = netdev_priv(dev);
3385 tsv->svi = RING_STATION_VERSION_NUMBER;
3386 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3388 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3389 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3390 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3391 tsv->svv[3] = 0x40; /* EBCDIC - */
3392 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3393 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3394 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3395 tsv->svv[7] = 0x40; /* EBCDIC - */
3396 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3398 if(tp->extra_info & CHIP_REV_MASK)
3399 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3401 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3406 static int smctr_make_tx_status_code(struct net_device *dev,
3407 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3409 tsv->svi = TRANSMIT_STATUS_CODE;
3410 tsv->svl = S_TRANSMIT_STATUS_CODE;
3412 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) | IBM_PASS_SOURCE_ADDR);
3414 /* Stripped frame status of Transmitted Frame */
3415 tsv->svv[1] = tx_fstatus & 0xff;
3420 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3421 MAC_SUB_VECTOR *tsv)
3423 struct net_local *tp = netdev_priv(dev);
3425 smctr_get_upstream_neighbor_addr(dev);
3427 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3428 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3430 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3431 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3433 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3434 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3436 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3437 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3442 static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3444 tsv->svi = WRAP_DATA;
3445 tsv->svl = S_WRAP_DATA;
3451 * Open/initialize the board. This is called sometime after
3452 * booting when the 'ifconfig' program is run.
3454 * This routine should set everything up anew at each open, even
3455 * registers that "should" only need to be set once at boot, so that
3456 * there is non-reboot way to recover if something goes wrong.
3458 static int smctr_open(struct net_device *dev)
3462 if(smctr_debug > 10)
3463 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3465 err = smctr_init_adapter(dev);
3472 /* Interrupt driven open of Token card. */
3473 static int smctr_open_tr(struct net_device *dev)
3475 struct net_local *tp = netdev_priv(dev);
3476 unsigned long flags;
3479 if(smctr_debug > 10)
3480 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3482 /* Now we can actually open the adapter. */
3483 if(tp->status == OPEN)
3485 if(tp->status != INITIALIZED)
3488 /* FIXME: it would work a lot better if we masked the irq sources
3489 on the card here, then we could skip the locking and poll nicely */
3490 spin_lock_irqsave(&tp->lock, flags);
3492 smctr_set_page(dev, (__u8 *)tp->ram_access);
3494 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3497 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3500 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3503 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3506 tp->status = CLOSED;
3508 /* Insert into the Ring or Enter Loopback Mode. */
3509 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3511 tp->status = CLOSED;
3513 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3515 if(!(err = smctr_wait_cmd(dev)))
3519 smctr_status_chg(dev);
3523 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3525 tp->status = CLOSED;
3526 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3528 if(!(err = smctr_wait_cmd(dev)))
3532 smctr_status_chg(dev);
3536 if((tp->mode_bits & LOOPING_MODE_MASK)
3539 tp->status = CLOSED;
3540 if(!(err = smctr_lobe_media_test_cmd(dev)))
3542 if(!(err = smctr_wait_cmd(dev)))
3545 smctr_status_chg(dev);
3549 if(!(err = smctr_lobe_media_test(dev)))
3550 err = smctr_issue_insert_cmd(dev);
3553 if(err == LOBE_MEDIA_TEST_FAILED)
3554 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3561 spin_unlock_irqrestore(&tp->lock, flags);
3566 /* Check for a network adapter of this type,
3567 * and return device structure if one exists.
3569 struct net_device __init *smctr_probe(int unit)
3571 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3572 static const unsigned ports[] = {
3573 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3574 0x320, 0x340, 0x360, 0x380, 0
3576 const unsigned *port;
3580 return ERR_PTR(-ENOMEM);
3583 sprintf(dev->name, "tr%d", unit);
3584 netdev_boot_setup_check(dev);
3587 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3588 err = smctr_probe1(dev, dev->base_addr);
3589 else if(dev->base_addr != 0) /* Don't probe at all. */
3592 for (port = ports; *port; port++) {
3593 err = smctr_probe1(dev, *port);
3600 err = register_netdev(dev);
3605 #ifdef CONFIG_MCA_LEGACY
3606 { struct net_local *tp = netdev_priv(dev);
3608 mca_mark_as_unused(tp->slot_num);
3611 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3612 free_irq(dev->irq, dev);
3615 return ERR_PTR(err);
3618 static const struct net_device_ops smctr_netdev_ops = {
3619 .ndo_open = smctr_open,
3620 .ndo_stop = smctr_close,
3621 .ndo_start_xmit = smctr_send_packet,
3622 .ndo_tx_timeout = smctr_timeout,
3623 .ndo_get_stats = smctr_get_stats,
3624 .ndo_set_multicast_list = smctr_set_multicast_list,
3627 static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3629 static unsigned version_printed;
3630 struct net_local *tp = netdev_priv(dev);
3634 if(smctr_debug && version_printed++ == 0)
3637 spin_lock_init(&tp->lock);
3638 dev->base_addr = ioaddr;
3640 /* Actually detect an adapter now. */
3641 err = smctr_chk_isa(dev);
3644 if ((err = smctr_chk_mca(dev)) < 0) {
3650 tp = netdev_priv(dev);
3651 dev->mem_start = tp->ram_base;
3652 dev->mem_end = dev->mem_start + 0x10000;
3653 ram = (__u32 *)phys_to_virt(dev->mem_start);
3654 tp->ram_access = *(__u32 *)&ram;
3655 tp->status = NOT_INITIALIZED;
3657 err = smctr_load_firmware(dev);
3658 if(err != UCODE_PRESENT && err != SUCCESS)
3660 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3665 /* Allow user to specify ring speed on module insert. */
3667 tp->media_type = MEDIA_UTP_4;
3669 tp->media_type = MEDIA_UTP_16;
3671 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3672 dev->name, smctr_name, smctr_model,
3673 (unsigned int)dev->base_addr,
3674 dev->irq, tp->rom_base, tp->ram_base);
3676 dev->netdev_ops = &smctr_netdev_ops;
3677 dev->watchdog_timeo = HZ;
3684 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3685 struct net_device *dev, __u16 rx_status)
3687 struct net_local *tp = netdev_priv(dev);
3688 struct sk_buff *skb;
3689 __u16 rcode, correlator;
3693 rmf->vl = SWAP_BYTES(rmf->vl);
3694 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3698 /* Received MAC Frames Processed by RS. */
3700 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3705 if((err = smctr_send_rsp(dev, rmf, rcode,
3713 if((rcode = smctr_rcv_chg_param(dev, rmf,
3714 &correlator)) ==HARDWARE_FAILED)
3719 if((err = smctr_send_rsp(dev, rmf, rcode,
3727 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3728 rmf, &correlator)) != POSITIVE_ACK)
3730 if(rcode == HARDWARE_FAILED)
3733 return (smctr_send_rsp(dev, rmf,
3734 rcode, correlator));
3737 if((err = smctr_send_rpt_addr(dev, rmf,
3745 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3746 rmf, &correlator)) != POSITIVE_ACK)
3748 if(rcode == HARDWARE_FAILED)
3751 return (smctr_send_rsp(dev, rmf,
3756 if((err = smctr_send_rpt_attch(dev, rmf,
3764 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3765 rmf, &correlator)) != POSITIVE_ACK)
3767 if(rcode == HARDWARE_FAILED)
3770 return (smctr_send_rsp(dev, rmf,
3775 if((err = smctr_send_rpt_state(dev, rmf,
3783 __u16 uninitialized_var(tx_fstatus);
3785 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3788 if(rcode == HARDWARE_FAILED)
3791 return (smctr_send_rsp(dev, rmf,
3796 if((err = smctr_send_tx_forward(dev, rmf,
3797 &tx_fstatus)) == HARDWARE_FAILED)
3802 if(err == A_FRAME_WAS_FORWARDED)
3804 if((err = smctr_send_rpt_tx_forward(dev,
3814 /* Received MAC Frames Processed by CRS/REM/RPS. */
3819 case RPT_ACTIVE_ERR:
3827 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3830 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3832 rcode = smctr_rcv_unknown(dev, rmf,
3834 if((err = smctr_send_rsp(dev, rmf,rcode,
3846 /* 1. DA doesn't match (Promiscuous Mode).
3847 * 2. Parse for Extended MAC Frame Type.
3865 case RPT_ACTIVE_ERR:
3874 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3875 * ACCEPT_ATT_MAC_FRAMES is set.
3877 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES) &&
3878 (xframe == (__u8)0)) ||
3879 ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES) &&
3880 (xframe == (__u8)1)))
3882 rmf->vl = SWAP_BYTES(rmf->vl);
3884 if (!(skb = dev_alloc_skb(size)))
3888 /* Slide data into a sleek skb. */
3889 skb_put(skb, skb->len);
3890 skb_copy_to_linear_data(skb, rmf, skb->len);
3892 /* Update Counters */
3893 tp->MacStat.rx_packets++;
3894 tp->MacStat.rx_bytes += skb->len;
3896 /* Kick the packet on up. */
3897 skb->protocol = tr_type_trans(skb, dev);
3905 /* Adapter RAM test. Incremental word ODD boundary data test. */
3906 static int smctr_ram_memory_test(struct net_device *dev)
3908 struct net_local *tp = netdev_priv(dev);
3909 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3910 word_read = 0, err_word = 0, err_pattern = 0;
3911 unsigned int err_offset;
3915 if(smctr_debug > 10)
3916 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3918 start_pattern = 0x0001;
3919 pages_of_ram = tp->ram_size / tp->ram_usable;
3920 pword = tp->ram_access;
3922 /* Incremental word ODD boundary test. */
3923 for(page = 0; (page < pages_of_ram) && (~err);
3924 page++, start_pattern += 0x8000)
3926 smctr_set_page(dev, (__u8 *)(tp->ram_access
3927 + (page * tp->ram_usable * 1024) + 1));
3928 word_pattern = start_pattern;
3930 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3931 *(__u16 *)(pword + j) = word_pattern++;
3933 word_pattern = start_pattern;
3935 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1 && (~err);
3936 j += 2, word_pattern++)
3938 word_read = *(__u16 *)(pword + j);
3939 if(word_read != word_pattern)
3943 err_word = word_read;
3944 err_pattern = word_pattern;
3945 return (RAM_TEST_FAILED);
3950 /* Zero out memory. */
3951 for(page = 0; page < pages_of_ram && (~err); page++)
3953 smctr_set_page(dev, (__u8 *)(tp->ram_access
3954 + (page * tp->ram_usable * 1024)));
3957 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3958 *(__u16 *)(pword + j) = word_pattern;
3960 for(j =0; j < (__u32)tp->ram_usable * 1024 && (~err); j += 2)
3962 word_read = *(__u16 *)(pword + j);
3963 if(word_read != word_pattern)
3967 err_word = word_read;
3968 err_pattern = word_pattern;
3969 return (RAM_TEST_FAILED);
3974 smctr_set_page(dev, (__u8 *)tp->ram_access);
3979 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3982 MAC_SUB_VECTOR *rsv;
3984 __u16 rcode = POSITIVE_ACK;
3985 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
3987 /* This Frame can only come from a CRS */
3988 if((rmf->dc_sc & SC_MASK) != SC_CRS)
3989 return(E_INAPPROPRIATE_SOURCE_CLASS);
3991 /* Remove MVID Length from total length. */
3992 vlen = (signed short)rmf->vl - 4;
3994 /* Point to First SVID */
3995 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
3997 /* Search for Appropriate SVID's. */
3998 while((vlen > 0) && (rcode == POSITIVE_ACK))
4003 svectors |= F_CORRELATOR;
4004 rcode = smctr_set_corr(dev, rsv, correlator);
4007 case LOCAL_RING_NUMBER:
4008 svectors |= F_LOCAL_RING_NUMBER;
4009 rcode = smctr_set_local_ring_num(dev, rsv);
4012 case ASSIGN_PHYSICAL_DROP:
4013 svectors |= F_ASSIGN_PHYSICAL_DROP;
4014 rcode = smctr_set_phy_drop(dev, rsv);
4017 case ERROR_TIMER_VALUE:
4018 svectors |= F_ERROR_TIMER_VALUE;
4019 rcode = smctr_set_error_timer_value(dev, rsv);
4022 case AUTHORIZED_FUNCTION_CLASS:
4023 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4024 rcode = smctr_set_auth_funct_class(dev, rsv);
4027 case AUTHORIZED_ACCESS_PRIORITY:
4028 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4029 rcode = smctr_set_auth_access_pri(dev, rsv);
4033 rcode = E_SUB_VECTOR_UNKNOWN;
4037 /* Let Sender Know if SUM of SV length's is
4038 * larger then length in MVID length field
4040 if((vlen -= rsv->svl) < 0)
4041 rcode = E_VECTOR_LENGTH_ERROR;
4043 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4046 if(rcode == POSITIVE_ACK)
4048 /* Let Sender Know if MVID length field
4049 * is larger then SUM of SV length's
4052 rcode = E_VECTOR_LENGTH_ERROR;
4055 /* Let Sender Know if Expected SVID Missing */
4056 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4057 rcode = E_MISSING_SUB_VECTOR;
4064 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4067 MAC_SUB_VECTOR *rsv;
4069 __u16 rcode = POSITIVE_ACK;
4070 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4072 /* This Frame can only come from a RPS */
4073 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4074 return (E_INAPPROPRIATE_SOURCE_CLASS);
4076 /* Remove MVID Length from total length. */
4077 vlen = (signed short)rmf->vl - 4;
4079 /* Point to First SVID */
4080 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4082 /* Search for Appropriate SVID's */
4083 while((vlen > 0) && (rcode == POSITIVE_ACK))
4088 svectors |= F_CORRELATOR;
4089 rcode = smctr_set_corr(dev, rsv, correlator);
4092 case LOCAL_RING_NUMBER:
4093 svectors |= F_LOCAL_RING_NUMBER;
4094 rcode = smctr_set_local_ring_num(dev, rsv);
4097 case ASSIGN_PHYSICAL_DROP:
4098 svectors |= F_ASSIGN_PHYSICAL_DROP;
4099 rcode = smctr_set_phy_drop(dev, rsv);
4102 case ERROR_TIMER_VALUE:
4103 svectors |= F_ERROR_TIMER_VALUE;
4104 rcode = smctr_set_error_timer_value(dev, rsv);
4108 rcode = E_SUB_VECTOR_UNKNOWN;
4112 /* Let Sender Know if SUM of SV length's is
4113 * larger then length in MVID length field
4115 if((vlen -= rsv->svl) < 0)
4116 rcode = E_VECTOR_LENGTH_ERROR;
4118 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4121 if(rcode == POSITIVE_ACK)
4123 /* Let Sender Know if MVID length field
4124 * is larger then SUM of SV length's
4127 rcode = E_VECTOR_LENGTH_ERROR;
4130 /* Let Sender Know if Expected SV Missing */
4131 if((svectors & R_INIT) ^ R_INIT)
4132 rcode = E_MISSING_SUB_VECTOR;
4139 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4141 MAC_SUB_VECTOR *rsv;
4143 __u16 rcode = POSITIVE_ACK;
4144 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4146 /* This Frame can only come from a CRS */
4147 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4148 return (E_INAPPROPRIATE_SOURCE_CLASS);
4150 /* Remove MVID Length from total length */
4151 vlen = (signed short)rmf->vl - 4;
4153 /* Point to First SVID */
4154 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4156 /* Search for Appropriate SVID's */
4157 while((vlen > 0) && (rcode == POSITIVE_ACK))
4162 svectors |= F_FRAME_FORWARD;
4163 rcode = smctr_set_frame_forward(dev, rsv,
4168 rcode = E_SUB_VECTOR_UNKNOWN;
4172 /* Let Sender Know if SUM of SV length's is
4173 * larger then length in MVID length field
4175 if((vlen -= rsv->svl) < 0)
4176 rcode = E_VECTOR_LENGTH_ERROR;
4178 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4181 if(rcode == POSITIVE_ACK)
4183 /* Let Sender Know if MVID length field
4184 * is larger then SUM of SV length's
4187 rcode = E_VECTOR_LENGTH_ERROR;
4190 /* Let Sender Know if Expected SV Missing */
4191 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4192 rcode = E_MISSING_SUB_VECTOR;
4199 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4200 MAC_HEADER *rmf, __u16 *correlator)
4202 MAC_SUB_VECTOR *rsv;
4204 __u16 rcode = POSITIVE_ACK;
4205 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4207 /* Remove MVID Length from total length */
4208 vlen = (signed short)rmf->vl - 4;
4210 /* Point to First SVID */
4211 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4213 /* Search for Appropriate SVID's */
4214 while((vlen > 0) && (rcode == POSITIVE_ACK))
4219 svectors |= F_CORRELATOR;
4220 rcode = smctr_set_corr(dev, rsv, correlator);
4224 rcode = E_SUB_VECTOR_UNKNOWN;
4228 /* Let Sender Know if SUM of SV length's is
4229 * larger then length in MVID length field
4231 if((vlen -= rsv->svl) < 0)
4232 rcode = E_VECTOR_LENGTH_ERROR;
4234 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4237 if(rcode == POSITIVE_ACK)
4239 /* Let Sender Know if MVID length field
4240 * is larger then SUM of SV length's
4243 rcode = E_VECTOR_LENGTH_ERROR;
4246 /* Let Sender Know if Expected SVID Missing */
4247 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4248 ^ R_RQ_ATTCH_STATE_ADDR)
4249 rcode = E_MISSING_SUB_VECTOR;
4256 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4259 MAC_SUB_VECTOR *rsv;
4264 /* Remove MVID Length from total length */
4265 vlen = (signed short)rmf->vl - 4;
4267 /* Point to First SVID */
4268 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4270 /* Search for CORRELATOR for RSP to UNKNOWN */
4271 while((vlen > 0) && (*correlator == 0))
4276 smctr_set_corr(dev, rsv, correlator);
4284 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4287 return (E_UNRECOGNIZED_VECTOR_ID);
4291 * Reset the 825 NIC and exit w:
4292 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4298 static int smctr_reset_adapter(struct net_device *dev)
4300 struct net_local *tp = netdev_priv(dev);
4301 int ioaddr = dev->base_addr;
4303 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4304 mdelay(200); /* ~2 ms */
4306 smctr_clear_trc_reset(ioaddr);
4307 mdelay(200); /* ~2 ms */
4309 /* Remove any latched interrupts that occurred prior to reseting the
4310 * adapter or possibily caused by line glitches due to the reset.
4312 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4317 static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4319 struct net_local *tp = netdev_priv(dev);
4322 if(smctr_debug > 10)
4323 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4325 if(tp->num_tx_fcbs_used[queue] != 0 &&
4326 tp->tx_queue_status[queue] == NOT_TRANSMITING)
4328 tp->tx_queue_status[queue] = TRANSMITING;
4329 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4335 static int smctr_ring_status_chg(struct net_device *dev)
4337 struct net_local *tp = netdev_priv(dev);
4339 if(smctr_debug > 10)
4340 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4342 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4343 * Bit is set, check value of monitor_state, only then we
4344 * enable and start transmit/receive timeout (if and only
4345 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4347 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4349 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE) ||
4350 (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4352 tp->monitor_state_ready = 1;
4356 /* if adapter is NOT in either active monitor
4357 * or standby monitor state => Disable
4358 * transmit/receive timeout.
4360 tp->monitor_state_ready = 0;
4362 /* Ring speed problem, switching to auto mode. */
4363 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE &&
4366 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4368 smctr_set_ring_speed(dev);
4373 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4376 switch(tp->ring_status)
4379 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
4382 case SINGLE_STATION:
4383 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
4386 case COUNTER_OVERFLOW:
4387 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
4390 case REMOVE_RECEIVED:
4391 printk(KERN_INFO "%s: Remove Received\n", dev->name);
4394 case AUTO_REMOVAL_ERROR:
4395 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
4398 case LOBE_WIRE_FAULT:
4399 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
4402 case TRANSMIT_BEACON:
4403 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
4407 printk(KERN_INFO "%s: Soft Error\n", dev->name);
4411 printk(KERN_INFO "%s: Hard Error\n", dev->name);
4415 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
4419 printk(KERN_INFO "%s: Unknown ring status change\n",
4427 static int smctr_rx_frame(struct net_device *dev)
4429 struct net_local *tp = netdev_priv(dev);
4430 __u16 queue, status, rx_size, err = 0;
4433 if(smctr_debug > 10)
4434 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4436 queue = tp->receive_queue_number;
4438 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4440 err = HARDWARE_FAILED;
4442 if(((status & 0x007f) == 0) ||
4443 ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4445 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4446 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4448 pbuff = smctr_get_rx_pointer(dev, queue);
4450 smctr_set_page(dev, pbuff);
4451 smctr_disable_16bit(dev);
4453 /* pbuff points to addr within one page */
4454 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4456 if(queue == NON_MAC_QUEUE)
4458 struct sk_buff *skb;
4460 skb = dev_alloc_skb(rx_size);
4462 skb_put(skb, rx_size);
4464 skb_copy_to_linear_data(skb, pbuff, rx_size);
4466 /* Update Counters */
4467 tp->MacStat.rx_packets++;
4468 tp->MacStat.rx_bytes += skb->len;
4470 /* Kick the packet on up. */
4471 skb->protocol = tr_type_trans(skb, dev);
4477 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4478 rx_size, dev, status);
4481 smctr_enable_16bit(dev);
4482 smctr_set_page(dev, (__u8 *)tp->ram_access);
4483 smctr_update_rx_chain(dev, queue);
4492 static int smctr_send_dat(struct net_device *dev)
4494 struct net_local *tp = netdev_priv(dev);
4495 unsigned int i, err;
4499 if(smctr_debug > 10)
4500 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4502 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4503 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4505 return (OUT_OF_RESOURCES);
4508 /* Initialize DAT Data Fields. */
4509 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4510 tmf->ac = MSB(AC_FC_DAT);
4511 tmf->fc = LSB(AC_FC_DAT);
4513 for(i = 0; i < 6; i++)
4515 tmf->sa[i] = dev->dev_addr[i];
4516 tmf->da[i] = dev->dev_addr[i];
4521 tmf->dc_sc = DC_RS | SC_RS;
4523 tmf->vl = SWAP_BYTES(tmf->vl);
4525 /* Start Transmit. */
4526 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4529 /* Wait for Transmit to Complete */
4530 for(i = 0; i < 10000; i++)
4532 if(fcb->frame_status & FCB_COMMAND_DONE)
4537 /* Check if GOOD frame Tx'ed. */
4538 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4539 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4541 return (INITIALIZE_FAILED);
4544 /* De-allocated Tx FCB and Frame Buffer
4545 * The FCB must be de-allocated manually if executing with
4546 * interrupts disabled, other wise the ISR (LM_Service_Events)
4547 * will de-allocate it when the interrupt occurs.
4549 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4550 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4555 static void smctr_timeout(struct net_device *dev)
4558 * If we get here, some higher level has decided we are broken.
4559 * There should really be a "kick me" function call instead.
4561 * Resetting the token ring adapter takes a long time so just
4562 * fake transmission time and go on trying. Our own timeout
4563 * routine is in sktr_timer_chk()
4565 dev->trans_start = jiffies; /* prevent tx timeout */
4566 netif_wake_queue(dev);
4570 * Gets skb from system, queues it and checks if it can be sent
4572 static netdev_tx_t smctr_send_packet(struct sk_buff *skb,
4573 struct net_device *dev)
4575 struct net_local *tp = netdev_priv(dev);
4577 if(smctr_debug > 10)
4578 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4581 * Block a transmit overlap
4584 netif_stop_queue(dev);
4586 if(tp->QueueSkb == 0)
4587 return NETDEV_TX_BUSY; /* Return with tbusy set: queue full */
4590 skb_queue_tail(&tp->SendSkbQueue, skb);
4591 smctr_hardware_send_packet(dev, tp);
4592 if(tp->QueueSkb > 0)
4593 netif_wake_queue(dev);
4595 return NETDEV_TX_OK;
4598 static int smctr_send_lobe_media_test(struct net_device *dev)
4600 struct net_local *tp = netdev_priv(dev);
4601 MAC_SUB_VECTOR *tsv;
4607 if(smctr_debug > 15)
4608 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4610 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4611 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4613 return (OUT_OF_RESOURCES);
4616 /* Initialize DAT Data Fields. */
4617 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4618 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4619 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4621 for(i = 0; i < 6; i++)
4624 tmf->sa[i] = dev->dev_addr[i];
4627 tmf->vc = LOBE_MEDIA_TEST;
4628 tmf->dc_sc = DC_RS | SC_RS;
4631 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4632 smctr_make_wrap_data(dev, tsv);
4633 tmf->vl += tsv->svl;
4635 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4636 smctr_make_wrap_data(dev, tsv);
4637 tmf->vl += tsv->svl;
4639 /* Start Transmit. */
4640 tmf->vl = SWAP_BYTES(tmf->vl);
4641 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4644 /* Wait for Transmit to Complete. (10 ms). */
4645 for(i=0; i < 10000; i++)
4647 if(fcb->frame_status & FCB_COMMAND_DONE)
4652 /* Check if GOOD frame Tx'ed */
4653 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4654 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4656 return (LOBE_MEDIA_TEST_FAILED);
4659 /* De-allocated Tx FCB and Frame Buffer
4660 * The FCB must be de-allocated manually if executing with
4661 * interrupts disabled, other wise the ISR (LM_Service_Events)
4662 * will de-allocate it when the interrupt occurs.
4664 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4665 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4670 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4674 MAC_SUB_VECTOR *tsv;
4677 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4678 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4679 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4680 == (FCBlock *)(-1L))
4685 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4687 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4690 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4692 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4693 smctr_make_corr(dev, tsv, correlator);
4695 tmf->vl += tsv->svl;
4696 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4697 smctr_make_phy_drop_num(dev, tsv);
4699 tmf->vl += tsv->svl;
4700 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4701 smctr_make_upstream_neighbor_addr(dev, tsv);
4703 tmf->vl += tsv->svl;
4704 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4705 smctr_make_addr_mod(dev, tsv);
4707 tmf->vl += tsv->svl;
4708 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4709 smctr_make_group_addr(dev, tsv);
4711 tmf->vl += tsv->svl;
4712 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4713 smctr_make_funct_addr(dev, tsv);
4715 tmf->vl += tsv->svl;
4717 /* Subtract out MVID and MVL which is
4718 * include in both vl and MAC_HEADER
4720 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4721 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4723 tmf->vl = SWAP_BYTES(tmf->vl);
4725 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4728 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4732 MAC_SUB_VECTOR *tsv;
4735 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4736 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4737 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4738 == (FCBlock *)(-1L))
4743 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4744 tmf->vc = RPT_ATTCH;
4745 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4748 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4750 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4751 smctr_make_corr(dev, tsv, correlator);
4753 tmf->vl += tsv->svl;
4754 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4755 smctr_make_product_id(dev, tsv);
4757 tmf->vl += tsv->svl;
4758 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4759 smctr_make_funct_addr(dev, tsv);
4761 tmf->vl += tsv->svl;
4762 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4763 smctr_make_auth_funct_class(dev, tsv);
4765 tmf->vl += tsv->svl;
4766 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4767 smctr_make_access_pri(dev, tsv);
4769 tmf->vl += tsv->svl;
4771 /* Subtract out MVID and MVL which is
4772 * include in both vl and MAC_HEADER
4774 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4775 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4777 tmf->vl = SWAP_BYTES(tmf->vl);
4779 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4782 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4786 MAC_SUB_VECTOR *tsv;
4789 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4790 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4791 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4792 == (FCBlock *)(-1L))
4797 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4798 tmf->vc = RPT_STATE;
4799 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4802 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4804 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4805 smctr_make_corr(dev, tsv, correlator);
4807 tmf->vl += tsv->svl;
4808 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4809 smctr_make_ring_station_version(dev, tsv);
4811 tmf->vl += tsv->svl;
4812 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4813 smctr_make_ring_station_status(dev, tsv);
4815 tmf->vl += tsv->svl;
4816 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4817 smctr_make_station_id(dev, tsv);
4819 tmf->vl += tsv->svl;
4821 /* Subtract out MVID and MVL which is
4822 * include in both vl and MAC_HEADER
4824 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4825 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4827 tmf->vl = SWAP_BYTES(tmf->vl);
4829 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4832 static int smctr_send_rpt_tx_forward(struct net_device *dev,
4833 MAC_HEADER *rmf, __u16 tx_fstatus)
4836 MAC_SUB_VECTOR *tsv;
4839 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4840 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4845 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4846 tmf->vc = RPT_TX_FORWARD;
4847 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4850 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4852 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4853 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4855 tmf->vl += tsv->svl;
4857 /* Subtract out MVID and MVL which is
4858 * include in both vl and MAC_HEADER
4860 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4861 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4863 tmf->vl = SWAP_BYTES(tmf->vl);
4865 return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4868 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4869 __u16 rcode, __u16 correlator)
4872 MAC_SUB_VECTOR *tsv;
4875 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4876 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4881 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4883 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4886 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4888 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4889 smctr_make_corr(dev, tsv, correlator);
4894 static int smctr_send_rq_init(struct net_device *dev)
4896 struct net_local *tp = netdev_priv(dev);
4898 MAC_SUB_VECTOR *tsv;
4900 unsigned int i, count = 0;
4905 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4906 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4907 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4908 == (FCBlock *)(-1L)))
4913 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4915 tmf->dc_sc = DC_RPS | SC_RS;
4918 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4920 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4921 smctr_make_product_id(dev, tsv);
4923 tmf->vl += tsv->svl;
4924 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4925 smctr_make_upstream_neighbor_addr(dev, tsv);
4927 tmf->vl += tsv->svl;
4928 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4929 smctr_make_ring_station_version(dev, tsv);
4931 tmf->vl += tsv->svl;
4932 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4933 smctr_make_addr_mod(dev, tsv);
4935 tmf->vl += tsv->svl;
4937 /* Subtract out MVID and MVL which is
4938 * include in both vl and MAC_HEADER
4940 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4941 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4943 tmf->vl = SWAP_BYTES(tmf->vl);
4945 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4948 /* Wait for Transmit to Complete */
4949 for(i = 0; i < 10000; i++)
4951 if(fcb->frame_status & FCB_COMMAND_DONE)
4956 /* Check if GOOD frame Tx'ed */
4957 fstatus = fcb->frame_status;
4959 if(!(fstatus & FCB_COMMAND_DONE))
4960 return (HARDWARE_FAILED);
4962 if(!(fstatus & FCB_TX_STATUS_E))
4965 /* De-allocated Tx FCB and Frame Buffer
4966 * The FCB must be de-allocated manually if executing with
4967 * interrupts disabled, other wise the ISR (LM_Service_Events)
4968 * will de-allocate it when the interrupt occurs.
4970 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4971 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4972 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4974 return (smctr_join_complete_state(dev));
4977 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4980 struct net_local *tp = netdev_priv(dev);
4985 /* Check if this is the END POINT of the Transmit Forward Chain. */
4989 /* Allocate Transmit FCB only by requesting 0 bytes
4992 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
4995 /* Set pointer to Transmit Frame Buffer to the data
4996 * portion of the received TX Forward frame, making
4997 * sure to skip over the Vector Code (vc) and Vector
5000 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5001 + sizeof(MAC_HEADER) + 2);
5002 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5003 + sizeof(MAC_HEADER) + 2);
5005 fcb->frame_length = rmf->vl - 4 - 2;
5006 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5008 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5011 /* Wait for Transmit to Complete */
5012 for(i = 0; i < 10000; i++)
5014 if(fcb->frame_status & FCB_COMMAND_DONE)
5019 /* Check if GOOD frame Tx'ed */
5020 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5022 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5025 for(i = 0; i < 10000; i++)
5027 if(fcb->frame_status & FCB_COMMAND_DONE)
5032 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5033 return (HARDWARE_FAILED);
5036 *tx_fstatus = fcb->frame_status;
5038 return (A_FRAME_WAS_FORWARDED);
5041 static int smctr_set_auth_access_pri(struct net_device *dev,
5042 MAC_SUB_VECTOR *rsv)
5044 struct net_local *tp = netdev_priv(dev);
5046 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5047 return (E_SUB_VECTOR_LENGTH_ERROR);
5049 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5051 return (POSITIVE_ACK);
5054 static int smctr_set_auth_funct_class(struct net_device *dev,
5055 MAC_SUB_VECTOR *rsv)
5057 struct net_local *tp = netdev_priv(dev);
5059 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5060 return (E_SUB_VECTOR_LENGTH_ERROR);
5062 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5064 return (POSITIVE_ACK);
5067 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5070 if(rsv->svl != S_CORRELATOR)
5071 return (E_SUB_VECTOR_LENGTH_ERROR);
5073 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5075 return (POSITIVE_ACK);
5078 static int smctr_set_error_timer_value(struct net_device *dev,
5079 MAC_SUB_VECTOR *rsv)
5084 if(rsv->svl != S_ERROR_TIMER_VALUE)
5085 return (E_SUB_VECTOR_LENGTH_ERROR);
5087 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5089 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5091 if((err = smctr_wait_cmd(dev)))
5094 return (POSITIVE_ACK);
5097 static int smctr_set_frame_forward(struct net_device *dev,
5098 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5100 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5101 return (E_SUB_VECTOR_LENGTH_ERROR);
5103 if((dc_sc & DC_MASK) != DC_CRS)
5105 if(rsv->svl >= 2 && rsv->svl < 20)
5106 return (E_TRANSMIT_FORWARD_INVALID);
5108 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5109 return (E_TRANSMIT_FORWARD_INVALID);
5112 return (POSITIVE_ACK);
5115 static int smctr_set_local_ring_num(struct net_device *dev,
5116 MAC_SUB_VECTOR *rsv)
5118 struct net_local *tp = netdev_priv(dev);
5120 if(rsv->svl != S_LOCAL_RING_NUMBER)
5121 return (E_SUB_VECTOR_LENGTH_ERROR);
5123 if(tp->ptr_local_ring_num)
5124 *(__u16 *)(tp->ptr_local_ring_num)
5125 = (rsv->svv[0] << 8 | rsv->svv[1]);
5127 return (POSITIVE_ACK);
5130 static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5132 struct net_local *tp = netdev_priv(dev);
5133 int ioaddr = dev->base_addr;
5135 if(tp->bic_type == BIC_585_CHIP)
5136 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5139 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5140 outb(tp->trc_mask, ioaddr + CSR);
5146 static void smctr_set_multicast_list(struct net_device *dev)
5148 if(smctr_debug > 10)
5149 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5152 static int smctr_set_page(struct net_device *dev, __u8 *buf)
5154 struct net_local *tp = netdev_priv(dev);
5158 tptr = (__u32)buf - (__u32)tp->ram_access;
5159 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5160 outb(amask, dev->base_addr + PR);
5165 static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5169 if(rsv->svl != S_PHYSICAL_DROP)
5170 return (E_SUB_VECTOR_LENGTH_ERROR);
5172 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5173 if((err = smctr_wait_cmd(dev)))
5176 return (POSITIVE_ACK);
5179 /* Reset the ring speed to the opposite of what it was. This auto-pilot
5180 * mode requires a complete reset and re-init of the adapter.
5182 static int smctr_set_ring_speed(struct net_device *dev)
5184 struct net_local *tp = netdev_priv(dev);
5187 if(tp->media_type == MEDIA_UTP_16)
5188 tp->media_type = MEDIA_UTP_4;
5190 tp->media_type = MEDIA_UTP_16;
5192 smctr_enable_16bit(dev);
5194 /* Re-Initialize adapter's internal registers */
5195 smctr_reset_adapter(dev);
5197 if((err = smctr_init_card_real(dev)))
5200 smctr_enable_bic_int(dev);
5202 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5205 smctr_disable_16bit(dev);
5210 static int smctr_set_rx_look_ahead(struct net_device *dev)
5212 struct net_local *tp = netdev_priv(dev);
5215 if(smctr_debug > 10)
5216 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5218 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5219 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5221 if(tp->adapter_bus == BUS_ISA16_TYPE)
5223 sword = *((__u16 *)(tp->ram_access));
5224 *((__u16 *)(tp->ram_access)) = 0x1234;
5226 smctr_disable_16bit(dev);
5227 rword = *((__u16 *)(tp->ram_access));
5228 smctr_enable_16bit(dev);
5231 tp->adapter_flags |= FORCED_16BIT_MODE;
5233 *((__u16 *)(tp->ram_access)) = sword;
5239 static int smctr_set_trc_reset(int ioaddr)
5243 r = inb(ioaddr + MSR);
5244 outb(MSR_RST | r, ioaddr + MSR);
5250 * This function can be called if the adapter is busy or not.
5252 static int smctr_setup_single_cmd(struct net_device *dev,
5253 __u16 command, __u16 subcommand)
5255 struct net_local *tp = netdev_priv(dev);
5258 if(smctr_debug > 10)
5259 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5261 if((err = smctr_wait_while_cbusy(dev)))
5264 if((err = (unsigned int)smctr_wait_cmd(dev)))
5267 tp->acb_head->cmd_done_status = 0;
5268 tp->acb_head->cmd = command;
5269 tp->acb_head->subcmd = subcommand;
5271 err = smctr_issue_resume_acb_cmd(dev);
5277 * This function can not be called with the adapter busy.
5279 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5280 __u16 command, __u16 subcommand)
5282 struct net_local *tp = netdev_priv(dev);
5284 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5285 tp->acb_head->cmd = command;
5286 tp->acb_head->subcmd = subcommand;
5287 tp->acb_head->data_offset_lo
5288 = (__u16)TRC_POINTER(tp->misc_command_data);
5290 return(smctr_issue_resume_acb_cmd(dev));
5293 static char *smctr_malloc(struct net_device *dev, __u16 size)
5295 struct net_local *tp = netdev_priv(dev);
5298 m = (char *)(tp->ram_access + tp->sh_mem_used);
5299 tp->sh_mem_used += (__u32)size;
5304 static int smctr_status_chg(struct net_device *dev)
5306 struct net_local *tp = netdev_priv(dev);
5308 if(smctr_debug > 10)
5309 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5319 /* Interrupt driven open() completion. XXX */
5321 tp->group_address_0 = 0;
5322 tp->group_address[0] = 0;
5323 tp->group_address[1] = 0;
5324 tp->functional_address_0 = 0;
5325 tp->functional_address[0] = 0;
5326 tp->functional_address[1] = 0;
5331 printk(KERN_INFO "%s: status change unknown %x\n",
5332 dev->name, tp->status);
5339 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5342 struct net_local *tp = netdev_priv(dev);
5345 if(smctr_debug > 10)
5346 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5348 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5349 if(tp->num_tx_fcbs[queue] != 1)
5350 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5352 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5354 tp->tx_queue_status[queue] = TRANSMITING;
5355 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5361 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5363 struct net_local *tp = netdev_priv(dev);
5364 __u16 status, err = 0;
5367 if(smctr_debug > 10)
5368 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5370 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5372 if(status & 0x7e00 )
5374 err = HARDWARE_FAILED;
5378 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5382 smctr_disable_16bit(dev);
5384 if(tp->mode_bits & UMAC)
5386 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5387 cstatus = NO_SUCH_DESTINATION;
5390 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5391 cstatus = DEST_OUT_OF_RESOURCES;
5394 if(status & FCB_TX_STATUS_E)
5395 cstatus = MAX_COLLISIONS;
5404 if(queue == BUG_QUEUE)
5407 smctr_enable_16bit(dev);
5415 static unsigned short smctr_tx_move_frame(struct net_device *dev,
5416 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5418 struct net_local *tp = netdev_priv(dev);
5419 unsigned int ram_usable;
5420 __u32 flen, len, offset = 0;
5423 if(smctr_debug > 10)
5424 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5426 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5430 while(flen > 0 && bytes > 0)
5432 smctr_set_page(dev, pbuff);
5434 offset = SMC_PAGE_OFFSET(pbuff);
5436 if(offset + flen > ram_usable)
5437 len = ram_usable - offset;
5444 page = (char *) (offset + tp->ram_access);
5445 memcpy(page, frag, len);
5456 /* Update the error statistic counters for this adapter. */
5457 static int smctr_update_err_stats(struct net_device *dev)
5459 struct net_local *tp = netdev_priv(dev);
5460 struct tr_statistics *tstat = &tp->MacStat;
5462 if(tstat->internal_errors)
5463 tstat->internal_errors
5464 += *(tp->misc_command_data + 0) & 0x00ff;
5466 if(tstat->line_errors)
5467 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5469 if(tstat->A_C_errors)
5470 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5472 if(tstat->burst_errors)
5473 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5475 if(tstat->abort_delimiters)
5476 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5478 if(tstat->recv_congest_count)
5479 tstat->recv_congest_count
5480 += *(tp->misc_command_data + 3) & 0x00ff;
5482 if(tstat->lost_frames)
5484 += *(tp->misc_command_data + 3) >> 8;
5486 if(tstat->frequency_errors)
5487 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5489 if(tstat->frame_copied_errors)
5490 tstat->frame_copied_errors
5491 += *(tp->misc_command_data + 4) >> 8;
5493 if(tstat->token_errors)
5494 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5499 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5501 struct net_local *tp = netdev_priv(dev);
5506 fcb = tp->rx_fcb_curr[queue];
5507 len = fcb->frame_length;
5509 fcb->frame_status = 0;
5510 fcb->info = FCB_CHAIN_END;
5511 fcb->back_ptr->info = FCB_WARNING;
5513 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5515 /* update RX BDBs */
5516 size = (len >> RX_BDB_SIZE_SHIFT);
5517 if(len & RX_DATA_BUFFER_SIZE_MASK)
5518 size += sizeof(BDBlock);
5519 size &= (~RX_BDB_SIZE_MASK);
5521 /* check if wrap around */
5522 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5523 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5525 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5526 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5529 bdb->back_ptr->info = BDB_CHAIN_END;
5530 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5531 tp->rx_bdb_curr[queue] = bdb;
5536 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5539 struct net_local *tp = netdev_priv(dev);
5541 if(smctr_debug > 20)
5542 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5544 if(tp->num_tx_fcbs_used[queue] <= 0)
5545 return (HARDWARE_FAILED);
5548 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5550 tp->tx_buff_used[queue] = 0;
5551 return (HARDWARE_FAILED);
5554 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5556 /* if all transmit buffer are cleared
5557 * need to set the tx_buff_curr[] to tx_buff_head[]
5558 * otherwise, tx buffer will be segregate and cannot
5559 * accommodate and buffer greater than (curr - head) and
5560 * (end - curr) since we do not allow wrap around allocation.
5562 if(tp->tx_buff_used[queue] == 0)
5563 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5565 tp->num_tx_fcbs_used[queue]--;
5566 fcb->frame_status = 0;
5567 tp->tx_fcb_end[queue] = fcb->next_ptr;
5568 netif_wake_queue(dev);
5573 static int smctr_wait_cmd(struct net_device *dev)
5575 struct net_local *tp = netdev_priv(dev);
5576 unsigned int loop_count = 0x20000;
5578 if(smctr_debug > 10)
5579 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5583 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5590 return(HARDWARE_FAILED);
5592 if(tp->acb_head->cmd_done_status & 0xff)
5593 return(HARDWARE_FAILED);
5598 static int smctr_wait_while_cbusy(struct net_device *dev)
5600 struct net_local *tp = netdev_priv(dev);
5601 unsigned int timeout = 0x20000;
5602 int ioaddr = dev->base_addr;
5605 if(tp->bic_type == BIC_585_CHIP)
5609 r = inb(ioaddr + HWR);
5610 if((r & HWR_CBUSY) == 0)
5619 r = inb(ioaddr + CSR);
5620 if((r & CSR_CBUSY) == 0)
5629 return (HARDWARE_FAILED);
5634 static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5635 static int io[SMCTR_MAX_ADAPTERS];
5636 static int irq[SMCTR_MAX_ADAPTERS];
5638 MODULE_LICENSE("GPL");
5639 MODULE_FIRMWARE("tr_smctr.bin");
5641 module_param_array(io, int, NULL, 0);
5642 module_param_array(irq, int, NULL, 0);
5643 module_param(ringspeed, int, 0);
5645 static struct net_device * __init setup_card(int n)
5647 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5651 return ERR_PTR(-ENOMEM);
5654 err = smctr_probe1(dev, io[n]);
5658 err = register_netdev(dev);
5663 #ifdef CONFIG_MCA_LEGACY
5664 { struct net_local *tp = netdev_priv(dev);
5666 mca_mark_as_unused(tp->slot_num);
5669 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5670 free_irq(dev->irq, dev);
5673 return ERR_PTR(err);
5676 int __init init_module(void)
5679 struct net_device *dev;
5681 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5682 dev = io[0]? setup_card(i) : smctr_probe(-1);
5689 return found ? 0 : -ENODEV;
5692 void __exit cleanup_module(void)
5696 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5697 struct net_device *dev = dev_smctr[i];
5701 unregister_netdev(dev);
5702 #ifdef CONFIG_MCA_LEGACY
5703 { struct net_local *tp = netdev_priv(dev);
5705 mca_mark_as_unused(tp->slot_num);
5708 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5710 free_irq(dev->irq, dev);