USB: Add helper macro for usb_driver boilerplate
[linux/fpc-iii.git] / drivers / net / tokenring / smctr.c
blob029846a98636323bac69ceacdc04b67092b2085a
1 /*
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)
13 * Source(s):
14 * - SMC TokenCard SDK.
16 * Maintainer(s):
17 * JS Jay Schulist <jschlst@samba.org>
19 * Changes:
20 * 07102000 JS Fixed a timing problem in smctr_wait_cmd();
21 * Also added a bit more discriptive error msgs.
22 * 07122000 JS Fixed problem with detecting a card with
23 * module io/irq/mem specified.
25 * To do:
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>
38 #include <linux/in.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>
53 #include <asm/io.h>
54 #include <asm/dma.h>
55 #include <asm/irq.h>
57 #if BITS_PER_LONG == 64
58 #error FIXME: driver does not support 64-bit platforms
59 #endif
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;
72 #endif
74 static int ringspeed;
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.
83 #ifndef SMCTR_DEBUG
84 #define SMCTR_DEBUG 1
85 #endif
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.
91 /* A */
92 static int smctr_alloc_shared_memory(struct net_device *dev);
94 /* B */
95 static int smctr_bypass_state(struct net_device *dev);
97 /* C */
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);
105 /* D */
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);
112 /* E */
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);
118 /* G */
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,
127 __u16 bytes_count);
128 static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
130 /* H */
131 static int smctr_hardware_send_packet(struct net_device *dev,
132 struct net_local *tp);
133 /* I */
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,
147 __u16 ibits);
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);
168 /* J */
169 static int smctr_join_complete_state(struct net_device *dev);
171 /* L */
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);
179 /* M */
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);
208 /* O */
209 static int smctr_open(struct net_device *dev);
210 static int smctr_open_tr(struct net_device *dev);
212 /* P */
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);
218 /* R */
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,
221 __u16 *correlator);
222 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
223 __u16 *correlator);
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,
228 __u16 *correlator);
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);
234 /* S */
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,
240 __u16 correlator);
241 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
242 __u16 correlator);
243 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
244 __u16 correlator);
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,
251 __u16 *tx_fstatus);
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,
257 __u16 *correlator);
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);
279 /* T */
280 static void smctr_timeout(struct net_device *dev);
281 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
282 __u16 queue);
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);
287 /* U */
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,
291 __u16 queue);
293 /* W */
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
313 * 5. MAC TX FCB'S
314 * 6. NON-MAC TX FCB'S
315 * 7. MAC TX BDB'S
316 * 8. NON-MAC TX BDB'S
317 * 9. MAC RX FCB'S
318 * 10. NON-MAC RX FCB'S
319 * 11. MAC RX BDB'S
320 * 12. NON-MAC RX BDB'S
321 * 13. MAC TX Data Buffer( 1, 256 byte buffer)
322 * 14. MAC RX Data Buffer( 1, 256 byte buffer)
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);
331 if(smctr_debug > 10)
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 Boundary.
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 Boundary 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);
438 return 0;
441 /* Enter Bypass state. */
442 static int smctr_bypass_state(struct net_device *dev)
444 int err;
446 if(smctr_debug > 10)
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);
451 return err;
454 static int smctr_checksum_firmware(struct net_device *dev)
456 struct net_local *tp = netdev_priv(dev);
457 __u16 i, checksum = 0;
459 if(smctr_debug > 10)
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);
473 if(checksum)
474 return checksum;
476 return 0;
479 static int __init smctr_chk_mca(struct net_device *dev)
481 #ifdef CONFIG_MCA_LEGACY
482 struct net_local *tp = netdev_priv(dev);
483 int current_slot;
484 __u8 r1, r2, r3, r4, r5;
486 current_slot = mca_find_unused_adapter(smctr_posid, 0);
487 if(current_slot == MCA_NOTFOUND)
488 return -ENODEV;
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);
497 if(tp->slot_num)
498 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
499 else
500 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
502 r1 = inb(CNFG_POS_REG1);
503 r2 = inb(CNFG_POS_REG0);
505 tp->bic_type = BIC_594_CHIP;
507 /* IO */
508 r2 = mca_read_stored_pos(tp->slot_num, 2);
509 r2 &= 0xF0;
510 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
511 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
513 /* IRQ */
514 r5 = mca_read_stored_pos(tp->slot_num, 5);
515 r5 &= 0xC;
516 switch(r5)
518 case 0:
519 dev->irq = 3;
520 break;
522 case 0x4:
523 dev->irq = 4;
524 break;
526 case 0x8:
527 dev->irq = 10;
528 break;
530 default:
531 dev->irq = 15;
532 break;
534 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
535 release_region(dev->base_addr, SMCTR_IO_EXTENT);
536 return -ENODEV;
539 /* Get RAM base */
540 r3 = mca_read_stored_pos(tp->slot_num, 3);
541 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
542 if (r3 & 0x8)
543 tp->ram_base += 0x010000;
544 if (r3 & 0x80)
545 tp->ram_base += 0xF00000;
547 /* Get Ram Size */
548 r3 &= 0x30;
549 r3 >>= 4;
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;
557 if (r4 & 0x8)
558 tp->rom_base += 0x010000;
560 /* Get ROM size. */
561 r4 >>= 4;
562 switch (r4) {
563 case 0:
564 tp->rom_size = CNFG_SIZE_8KB;
565 break;
566 case 1:
567 tp->rom_size = CNFG_SIZE_16KB;
568 break;
569 case 2:
570 tp->rom_size = CNFG_SIZE_32KB;
571 break;
572 default:
573 tp->rom_size = ROM_DISABLE;
576 /* Get Media Type. */
577 r5 = mca_read_stored_pos(tp->slot_num, 5);
578 r5 &= CNFG_MEDIA_TYPE_MASK;
579 switch(r5)
581 case (0):
582 tp->media_type = MEDIA_STP_4;
583 break;
585 case (1):
586 tp->media_type = MEDIA_STP_16;
587 break;
589 case (3):
590 tp->media_type = MEDIA_UTP_16;
591 break;
593 default:
594 tp->media_type = MEDIA_UTP_4;
595 break;
597 tp->media_menu = 14;
599 r2 = mca_read_stored_pos(tp->slot_num, 2);
600 if(!(r2 & 0x02))
601 tp->mode_bits |= EARLY_TOKEN_REL;
603 /* Disable slot */
604 outb(CNFG_POS_CONTROL_REG, 0);
606 tp->board_id = smctr_get_boardid(dev, 1);
607 switch(tp->board_id & 0xffff)
609 case WD8115TA:
610 smctr_model = "8115T/A";
611 break;
613 case WD8115T:
614 if(tp->extra_info & CHIP_REV_MASK)
615 smctr_model = "8115T rev XE";
616 else
617 smctr_model = "8115T rev XD";
618 break;
620 default:
621 smctr_model = "Unknown";
622 break;
625 return 0;
626 #else
627 return -1;
628 #endif /* CONFIG_MCA_LEGACY */
631 static int smctr_chg_rx_mask(struct net_device *dev)
633 struct net_local *tp = netdev_priv(dev);
634 int err = 0;
636 if(smctr_debug > 10)
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;
644 else
645 tp->config_word0 &= ~RX_OWN_BIT;
647 if(tp->receive_mask & PROMISCUOUS_MODE)
648 tp->config_word0 |= PROMISCUOUS_BIT;
649 else
650 tp->config_word0 &= ~PROMISCUOUS_BIT;
652 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
653 tp->config_word0 |= SAVBAD_BIT;
654 else
655 tp->config_word0 &= ~SAVBAD_BIT;
657 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
658 tp->config_word0 |= RXATMAC;
659 else
660 tp->config_word0 &= ~RXATMAC;
662 if(tp->receive_mask & ACCEPT_MULTI_PROM)
663 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
664 else
665 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
667 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
668 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
669 else
671 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
672 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
673 else
674 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
677 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
678 &tp->config_word0)))
680 return err;
683 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
684 &tp->config_word1)))
686 return err;
689 smctr_disable_16bit(dev);
691 return 0;
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);
700 return 0;
703 static int smctr_clear_trc_reset(int ioaddr)
705 __u8 r;
707 r = inb(ioaddr + MSR);
708 outb(~MSR_RST & r, ioaddr + MSR);
710 return 0;
714 * The inverse routine to smctr_open().
716 static int smctr_close(struct net_device *dev)
718 struct net_local *tp = netdev_priv(dev);
719 struct sk_buff *skb;
720 int err;
722 netif_stop_queue(dev);
724 tp->cleanup = 1;
726 /* Check to see if adapter is already in a closed state. */
727 if(tp->status != OPEN)
728 return 0;
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);
736 return err;
739 for(;;)
741 skb = skb_dequeue(&tp->SendSkbQueue);
742 if(skb == NULL)
743 break;
744 tp->QueueSkb++;
745 dev_kfree_skb(skb);
749 return 0;
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;
758 short branch, tsize;
759 __u16 buff = 0;
760 long weight;
761 __u8 *ucode;
762 __u16 *mem;
764 if(smctr_debug > 10)
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);
774 while(weight)
776 branch = ROOT;
777 while((tree + branch)->tag != LEAF && weight)
779 branch = *ucode & bit ? (tree + branch)->llink
780 : (tree + branch)->rlink;
782 bit >>= 1;
783 weight--;
785 if(bit == 0)
787 bit = 0x80;
788 ucode++;
792 buff |= (tree + branch)->info << shift;
793 shift -= 4;
795 if(shift < 0)
797 *(mem++) = SWAP_BYTES(buff);
798 buff = 0;
799 shift = 12;
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.
807 if(buff)
808 *(mem++) = SWAP_BYTES(buff);
810 return 0;
813 static int smctr_disable_16bit(struct net_device *dev)
815 return 0;
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;
829 if(smctr_debug > 10)
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);
835 return 0;
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);
847 return 0;
850 static int smctr_enable_16bit(struct net_device *dev)
852 struct net_local *tp = netdev_priv(dev);
853 __u8 r;
855 if(tp->adapter_bus == BUS_ISA16_TYPE)
857 r = inb(dev->base_addr + LAAR);
858 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
861 return 0;
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;
875 if(smctr_debug > 10)
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);
884 return 0;
887 static int smctr_enable_adapter_ram(struct net_device *dev)
889 int ioaddr = dev->base_addr;
890 __u8 r;
892 if(smctr_debug > 10)
893 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
895 r = inb(ioaddr + MSR);
896 outb(MSR_MEMB | r, ioaddr + MSR);
898 return 0;
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;
905 __u8 r;
907 switch(tp->bic_type)
909 case (BIC_584_CHIP):
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);
914 break;
916 case (BIC_594_CHIP):
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);
921 break;
924 return 0;
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;
932 __u16 r;
933 int i;
934 int err = -ENODEV;
936 if(smctr_debug > 10)
937 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
939 if((ioaddr & 0x1F) != 0)
940 goto out;
942 /* Grab the region so that no one else tries to probe our ioports. */
943 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
944 err = -EBUSY;
945 goto out;
948 /* Checksum SMC node address */
949 for(i = 0; i < 8; i++)
951 b = inb(ioaddr + LAR0 + i);
952 chksum += b;
955 if (chksum != NODE_ADDR_CKSUM)
956 goto out2;
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);
962 goto out2;
965 /* Check for 8115T Board ID */
966 r2 = 0;
967 for(r = 0; r < 8; r++)
969 r1 = inb(ioaddr + 0x8 + r);
970 r2 += r1;
973 /* value of RegF adds up the sum to 0xFF */
974 if((r2 != 0xFF) && (r2 != 0xEE))
975 goto out2;
977 /* Get adapter ID */
978 tp->board_id = smctr_get_boardid(dev, 0);
979 switch(tp->board_id & 0xffff)
981 case WD8115TA:
982 smctr_model = "8115T/A";
983 break;
985 case WD8115T:
986 if(tp->extra_info & CHIP_REV_MASK)
987 smctr_model = "8115T rev XE";
988 else
989 smctr_model = "8115T rev XD";
990 break;
992 default:
993 smctr_model = "Unknown";
994 break;
997 /* Store BIC type. */
998 tp->bic_type = BIC_584_CHIP;
999 tp->nic_type = NIC_825_CHIP;
1001 /* Copy Ram Size */
1002 tp->ram_usable = CNFG_SIZE_16KB;
1003 tp->ram_size = CNFG_SIZE_64KB;
1005 /* Get 58x Ram Base */
1006 r1 = inb(ioaddr);
1007 r1 &= 0x3F;
1009 r2 = inb(ioaddr + CNFG_LAAR_584);
1010 r2 &= CNFG_LAAR_MASK;
1011 r2 <<= 3;
1012 r2 |= ((r1 & 0x38) >> 3);
1014 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1016 /* Get 584 Irq */
1017 r1 = 0;
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 */
1023 r2 >>= 5;
1025 switch(r2)
1027 case 0:
1028 if(r1 == 0)
1029 dev->irq = 2;
1030 else
1031 dev->irq = 10;
1032 break;
1034 case 1:
1035 if(r1 == 0)
1036 dev->irq = 3;
1037 else
1038 dev->irq = 11;
1039 break;
1041 case 2:
1042 if(r1 == 0)
1044 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1045 dev->irq = 5;
1046 else
1047 dev->irq = 4;
1049 else
1050 dev->irq = 15;
1051 break;
1053 case 3:
1054 if(r1 == 0)
1055 dev->irq = 7;
1056 else
1057 dev->irq = 4;
1058 break;
1060 default:
1061 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1062 goto out2;
1065 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
1066 goto out2;
1068 /* Get 58x Rom Base */
1069 r1 = inb(ioaddr + CNFG_BIO_583);
1070 r1 &= 0x3E;
1071 r1 |= 0x40;
1073 tp->rom_base = (__u32)r1 << 13;
1075 /* Get 58x Rom Size */
1076 r1 = inb(ioaddr + CNFG_BIO_583);
1077 r1 &= 0xC0;
1078 if(r1 == 0)
1079 tp->rom_size = ROM_DISABLE;
1080 else
1082 r1 >>= 6;
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;
1120 else
1122 if(((r1 & 0x6) >> 1) == 0x2)
1123 tp->media_type |= MEDIA_STP_16;
1124 else
1126 if(((r1 & 0x6) >> 1) == 0x1)
1127 tp->media_type |= MEDIA_UTP_4;
1129 else
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);
1143 goto out2;
1148 return 0;
1150 out2:
1151 release_region(ioaddr, SMCTR_IO_EXTENT);
1152 out:
1153 return err;
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;
1160 __u8 r, r1, IdByte;
1161 __u16 BoardIdMask;
1163 tp->board_id = BoardIdMask = 0;
1165 if(mca)
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);
1170 else
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);
1177 if(!mca)
1179 r = inb(ioaddr + BID_REG_1);
1180 r &= 0x0c;
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;
1189 else
1190 tp->adapter_bus = BUS_ISA8_TYPE;
1192 else
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
1199 * return;
1201 if(IdByte & 0xF8)
1202 return -1;
1204 r1 = inb(ioaddr + BID_REG_1);
1205 r1 &= BID_ICR_MASK;
1206 r1 |= BID_OTHER_BIT;
1208 outb(r1, ioaddr + BID_REG_1);
1209 r1 = inb(ioaddr + BID_REG_3);
1211 r1 &= BID_EAR_MASK;
1212 r1 |= BID_ENGR_PAGE;
1214 outb(r1, ioaddr + BID_REG_3);
1215 r1 = inb(ioaddr + BID_REG_1);
1216 r1 &= BID_ICR_MASK;
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);
1232 r1 &= BID_ICR_MASK;
1233 r1 |= BID_OTHER_BIT;
1235 outb(r1, ioaddr + BID_REG_1);
1236 r1 = inb(ioaddr + BID_REG_3);
1238 r1 &= BID_EAR_MASK;
1239 r1 |= BID_EA6;
1241 outb(r1, ioaddr + BID_REG_3);
1242 r1 = inb(ioaddr + BID_REG_1);
1244 r1 &= BID_ICR_MASK;
1245 r1 |= BID_RLA;
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 Boundary.
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 Boundary,and then restore malloc to Even Boundrys.
1330 mem_used += 1L;
1331 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1332 mem_used += 1L;
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
1341 * byte offset).
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.
1347 mem_used += 0x100;
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);
1362 BDBlock *bdb;
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
1381 * or closed.
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,
1391 __u16 bytes_count)
1393 struct net_local *tp = netdev_priv(dev);
1394 FCBlock *pFCB;
1395 BDBlock *pbdb;
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);
1431 /* ring wrap */
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;
1451 return pFCB;
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;
1466 FCBlock *fcb;
1468 if(smctr_debug > 10)
1469 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1471 if(tp->status != OPEN)
1472 return -1;
1474 if(tp->monitor_state_ready != 1)
1475 return -1;
1477 for(;;)
1479 /* Send first buffer from queue */
1480 skb = skb_dequeue(&tp->SendSkbQueue);
1481 if(skb == NULL)
1482 return -1;
1484 tp->QueueSkb++;
1486 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size)
1487 return -1;
1489 smctr_enable_16bit(dev);
1490 smctr_set_page(dev, (__u8 *)tp->ram_access);
1492 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1493 == (FCBlock *)(-1L))
1495 smctr_disable_16bit(dev);
1496 return -1;
1499 smctr_tx_move_frame(dev, skb,
1500 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1502 smctr_set_page(dev, (__u8 *)fcb);
1504 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1505 dev_kfree_skb(skb);
1507 tstat->tx_packets++;
1509 smctr_disable_16bit(dev);
1512 return 0;
1515 static int smctr_init_acbs(struct net_device *dev)
1517 struct net_local *tp = netdev_priv(dev);
1518 unsigned int i;
1519 ACBlock *acb;
1521 if(smctr_debug > 10)
1522 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1524 acb = tp->acb_head;
1525 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1526 acb->cmd_info = ACB_CHAIN_END;
1527 acb->cmd = 0;
1528 acb->subcmd = 0;
1529 acb->data_offset_lo = 0;
1530 acb->data_offset_hi = 0;
1531 acb->next_ptr
1532 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1533 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1535 for(i = 1; i < tp->num_acbs; i++)
1537 acb = acb->next_ptr;
1538 acb->cmd_done_status
1539 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1540 acb->cmd_info = ACB_CHAIN_END;
1541 acb->cmd = 0;
1542 acb->subcmd = 0;
1543 acb->data_offset_lo = 0;
1544 acb->data_offset_hi = 0;
1545 acb->next_ptr
1546 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1547 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1550 acb->next_ptr = tp->acb_head;
1551 acb->trc_next_ptr = TRC_POINTER(tp->acb_head);
1552 tp->acb_next = tp->acb_head->next_ptr;
1553 tp->acb_curr = tp->acb_head->next_ptr;
1554 tp->num_acbs_used = 0;
1556 return 0;
1559 static int smctr_init_adapter(struct net_device *dev)
1561 struct net_local *tp = netdev_priv(dev);
1562 int err;
1564 if(smctr_debug > 10)
1565 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
1567 tp->status = CLOSED;
1568 tp->page_offset_mask = (tp->ram_usable * 1024) - 1;
1569 skb_queue_head_init(&tp->SendSkbQueue);
1570 tp->QueueSkb = MAX_TX_QUEUE;
1572 if(!(tp->group_address_0 & 0x0080))
1573 tp->group_address_0 |= 0x00C0;
1575 if(!(tp->functional_address_0 & 0x00C0))
1576 tp->functional_address_0 |= 0x00C0;
1578 tp->functional_address[0] &= 0xFF7F;
1580 if(tp->authorized_function_classes == 0)
1581 tp->authorized_function_classes = 0x7FFF;
1583 if(tp->authorized_access_priority == 0)
1584 tp->authorized_access_priority = 0x06;
1586 smctr_disable_bic_int(dev);
1587 smctr_set_trc_reset(dev->base_addr);
1589 smctr_enable_16bit(dev);
1590 smctr_set_page(dev, (__u8 *)tp->ram_access);
1592 if(smctr_checksum_firmware(dev))
1594 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name);
1595 return -ENOENT;
1598 if((err = smctr_ram_memory_test(dev)))
1600 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1601 return -EIO;
1604 smctr_set_rx_look_ahead(dev);
1605 smctr_load_node_addr(dev);
1607 /* Initialize adapter for Internal Self Test. */
1608 smctr_reset_adapter(dev);
1609 if((err = smctr_init_card_real(dev)))
1611 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1612 dev->name, err);
1613 return -EINVAL;
1616 /* This routine clobbers the TRC's internal registers. */
1617 if((err = smctr_internal_self_test(dev)))
1619 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1620 dev->name, err);
1621 return -EINVAL;
1624 /* Re-Initialize adapter's internal registers */
1625 smctr_reset_adapter(dev);
1626 if((err = smctr_init_card_real(dev)))
1628 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1629 dev->name, err);
1630 return -EINVAL;
1633 smctr_enable_bic_int(dev);
1635 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1636 return err;
1638 smctr_disable_16bit(dev);
1640 return 0;
1643 static int smctr_init_card_real(struct net_device *dev)
1645 struct net_local *tp = netdev_priv(dev);
1646 int err = 0;
1648 if(smctr_debug > 10)
1649 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1651 tp->sh_mem_used = 0;
1652 tp->num_acbs = NUM_OF_ACBS;
1654 /* Range Check Max Packet Size */
1655 if(tp->max_packet_size < 256)
1656 tp->max_packet_size = 256;
1657 else
1659 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1660 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1663 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1664 / tp->max_packet_size) - 1;
1666 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1667 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1668 else
1670 if(tp->num_of_tx_buffs == 0)
1671 tp->num_of_tx_buffs = 1;
1674 /* Tx queue constants */
1675 tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS;
1676 tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS;
1677 tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY;
1678 tp->tx_buff_used [BUG_QUEUE] = 0;
1679 tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING;
1681 tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS;
1682 tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS;
1683 tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY;
1684 tp->tx_buff_used [MAC_QUEUE] = 0;
1685 tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING;
1687 tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
1688 tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
1689 tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
1690 tp->tx_buff_used [NON_MAC_QUEUE] = 0;
1691 tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING;
1693 /* Receive Queue Constants */
1694 tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
1695 tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
1697 if(tp->extra_info & CHIP_REV_MASK)
1698 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1699 else
1700 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1702 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1704 smctr_alloc_shared_memory(dev);
1705 smctr_init_shared_memory(dev);
1707 if((err = smctr_issue_init_timers_cmd(dev)))
1708 return err;
1710 if((err = smctr_issue_init_txrx_cmd(dev)))
1712 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1713 return err;
1716 return 0;
1719 static int smctr_init_rx_bdbs(struct net_device *dev)
1721 struct net_local *tp = netdev_priv(dev);
1722 unsigned int i, j;
1723 BDBlock *bdb;
1724 __u16 *buf;
1726 if(smctr_debug > 10)
1727 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1729 for(i = 0; i < NUM_RX_QS_USED; i++)
1731 bdb = tp->rx_bdb_head[i];
1732 buf = tp->rx_buff_head[i];
1733 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
1734 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1735 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1736 bdb->data_block_ptr = buf;
1737 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1739 if(i == NON_MAC_QUEUE)
1740 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1741 else
1742 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1744 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1746 bdb->next_ptr->back_ptr = bdb;
1747 bdb = bdb->next_ptr;
1748 buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
1749 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1750 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1751 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1752 bdb->data_block_ptr = buf;
1753 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1755 if(i == NON_MAC_QUEUE)
1756 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1757 else
1758 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1761 bdb->next_ptr = tp->rx_bdb_head[i];
1762 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1764 tp->rx_bdb_head[i]->back_ptr = bdb;
1765 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1768 return 0;
1771 static int smctr_init_rx_fcbs(struct net_device *dev)
1773 struct net_local *tp = netdev_priv(dev);
1774 unsigned int i, j;
1775 FCBlock *fcb;
1777 for(i = 0; i < NUM_RX_QS_USED; i++)
1779 fcb = tp->rx_fcb_head[i];
1780 fcb->frame_status = 0;
1781 fcb->frame_length = 0;
1782 fcb->info = FCB_CHAIN_END;
1783 fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
1784 if(i == NON_MAC_QUEUE)
1785 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1786 else
1787 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1789 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1791 fcb->next_ptr->back_ptr = fcb;
1792 fcb = fcb->next_ptr;
1793 fcb->frame_status = 0;
1794 fcb->frame_length = 0;
1795 fcb->info = FCB_WARNING;
1796 fcb->next_ptr
1797 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1799 if(i == NON_MAC_QUEUE)
1800 fcb->trc_next_ptr
1801 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1802 else
1803 fcb->trc_next_ptr
1804 = TRC_POINTER(fcb->next_ptr);
1807 fcb->next_ptr = tp->rx_fcb_head[i];
1809 if(i == NON_MAC_QUEUE)
1810 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1811 else
1812 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1814 tp->rx_fcb_head[i]->back_ptr = fcb;
1815 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1818 return 0;
1821 static int smctr_init_shared_memory(struct net_device *dev)
1823 struct net_local *tp = netdev_priv(dev);
1824 unsigned int i;
1825 __u32 *iscpb;
1827 if(smctr_debug > 10)
1828 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1830 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1832 /* Initialize Initial System Configuration Point. (ISCP) */
1833 iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
1834 *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
1836 smctr_set_page(dev, (__u8 *)tp->ram_access);
1838 /* Initialize System Configuration Pointers. (SCP) */
1839 tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
1840 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
1841 | SCGB_BURST_LENGTH);
1843 tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr);
1844 tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head);
1845 tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr);
1846 tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2;
1848 /* Initialize System Control Block. (SCB) */
1849 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP;
1850 tp->sclb_ptr->iack_code = 0;
1851 tp->sclb_ptr->resume_control = 0;
1852 tp->sclb_ptr->int_mask_control = 0;
1853 tp->sclb_ptr->int_mask_state = 0;
1855 /* Initialize Interrupt Status Block. (ISB) */
1856 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1858 tp->isb_ptr->IStatus[i].IType = 0xf0;
1859 tp->isb_ptr->IStatus[i].ISubtype = 0;
1862 tp->current_isb_index = 0;
1864 /* Initialize Action Command Block. (ACB) */
1865 smctr_init_acbs(dev);
1867 /* Initialize transmit FCB's and BDB's. */
1868 smctr_link_tx_fcbs_to_bdbs(dev);
1869 smctr_init_tx_bdbs(dev);
1870 smctr_init_tx_fcbs(dev);
1872 /* Initialize receive FCB's and BDB's. */
1873 smctr_init_rx_bdbs(dev);
1874 smctr_init_rx_fcbs(dev);
1876 return 0;
1879 static int smctr_init_tx_bdbs(struct net_device *dev)
1881 struct net_local *tp = netdev_priv(dev);
1882 unsigned int i, j;
1883 BDBlock *bdb;
1885 for(i = 0; i < NUM_TX_QS_USED; i++)
1887 bdb = tp->tx_bdb_head[i];
1888 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1889 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1890 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1892 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1894 bdb->next_ptr->back_ptr = bdb;
1895 bdb = bdb->next_ptr;
1896 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1897 bdb->next_ptr
1898 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1901 bdb->next_ptr = tp->tx_bdb_head[i];
1902 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
1903 tp->tx_bdb_head[i]->back_ptr = bdb;
1906 return 0;
1909 static int smctr_init_tx_fcbs(struct net_device *dev)
1911 struct net_local *tp = netdev_priv(dev);
1912 unsigned int i, j;
1913 FCBlock *fcb;
1915 for(i = 0; i < NUM_TX_QS_USED; i++)
1917 fcb = tp->tx_fcb_head[i];
1918 fcb->frame_status = 0;
1919 fcb->frame_length = 0;
1920 fcb->info = FCB_CHAIN_END;
1921 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1922 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1924 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1926 fcb->next_ptr->back_ptr = fcb;
1927 fcb = fcb->next_ptr;
1928 fcb->frame_status = 0;
1929 fcb->frame_length = 0;
1930 fcb->info = FCB_CHAIN_END;
1931 fcb->next_ptr
1932 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1933 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1936 fcb->next_ptr = tp->tx_fcb_head[i];
1937 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1939 tp->tx_fcb_head[i]->back_ptr = fcb;
1940 tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr;
1941 tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr;
1942 tp->num_tx_fcbs_used[i] = 0;
1945 return 0;
1948 static int smctr_internal_self_test(struct net_device *dev)
1950 struct net_local *tp = netdev_priv(dev);
1951 int err;
1953 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1954 return err;
1956 if((err = smctr_wait_cmd(dev)))
1957 return err;
1959 if(tp->acb_head->cmd_done_status & 0xff)
1960 return -1;
1962 if((err = smctr_issue_test_hic_cmd(dev)))
1963 return err;
1965 if((err = smctr_wait_cmd(dev)))
1966 return err;
1968 if(tp->acb_head->cmd_done_status & 0xff)
1969 return -1;
1971 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1972 return err;
1974 if((err = smctr_wait_cmd(dev)))
1975 return err;
1977 if(tp->acb_head->cmd_done_status & 0xff)
1978 return -1;
1980 return 0;
1984 * The typical workload of the driver: Handle the network interface interrupts.
1986 static irqreturn_t smctr_interrupt(int irq, void *dev_id)
1988 struct net_device *dev = dev_id;
1989 struct net_local *tp;
1990 int ioaddr;
1991 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1992 __u16 err1, err = NOT_MY_INTERRUPT;
1993 __u8 isb_type, isb_subtype;
1994 __u16 isb_index;
1996 ioaddr = dev->base_addr;
1997 tp = netdev_priv(dev);
1999 if(tp->status == NOT_INITIALIZED)
2000 return IRQ_NONE;
2002 spin_lock(&tp->lock);
2004 smctr_disable_bic_int(dev);
2005 smctr_enable_16bit(dev);
2007 smctr_clear_int(dev);
2009 /* First read the LSB */
2010 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2012 isb_index = tp->current_isb_index;
2013 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2014 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2016 (tp->current_isb_index)++;
2017 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2018 tp->current_isb_index = 0;
2020 if(isb_type >= 0x10)
2022 smctr_disable_16bit(dev);
2023 spin_unlock(&tp->lock);
2024 return IRQ_HANDLED;
2027 err = HARDWARE_FAILED;
2028 interrupt_ack_code = isb_index;
2029 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2031 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2033 switch(isb_type)
2035 case ISB_IMC_MAC_TYPE_3:
2036 smctr_disable_16bit(dev);
2038 switch(isb_subtype)
2040 case 0:
2041 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2042 break;
2044 case 1:
2045 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2046 break;
2048 case 2:
2049 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2050 break;
2052 case 3:
2053 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2055 case 4:
2056 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2057 break;
2059 case 5:
2060 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2061 break;
2063 case 6:
2064 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2065 break;
2067 case 7:
2068 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2069 break;
2071 case 8: /* diagnostic state */
2072 break;
2074 case 9:
2075 tp->monitor_state = MS_BEACON_TEST_STATE;
2076 if(smctr_lobe_media_test(dev))
2078 tp->ring_status_flags = RING_STATUS_CHANGED;
2079 tp->ring_status = AUTO_REMOVAL_ERROR;
2080 smctr_ring_status_chg(dev);
2081 smctr_bypass_state(dev);
2083 else
2084 smctr_issue_insert_cmd(dev);
2085 break;
2087 /* case 0x0a-0xff, illegal states */
2088 default:
2089 break;
2092 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2093 err = smctr_ring_status_chg(dev);
2095 smctr_enable_16bit(dev);
2096 break;
2098 /* Type 0x02 - MAC Error Counters Interrupt
2099 * One or more MAC Error Counter is half full
2100 * MAC Error Counters
2101 * Lost_FR_Error_Counter
2102 * RCV_Congestion_Counter
2103 * FR_copied_Error_Counter
2104 * FREQ_Error_Counter
2105 * Token_Error_Counter
2106 * Line_Error_Counter
2107 * Internal_Error_Count
2109 case ISB_IMC_MAC_ERROR_COUNTERS:
2110 /* Read 802.5 Error Counters */
2111 err = smctr_issue_read_ring_status_cmd(dev);
2112 break;
2114 /* Type 0x04 - MAC Type 2 Interrupt
2115 * HOST needs to enqueue MAC Frame for transmission
2116 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2117 * TRC_Status_Changed_Indicate
2119 case ISB_IMC_MAC_TYPE_2:
2120 err = smctr_issue_read_ring_status_cmd(dev);
2121 break;
2124 /* Type 0x05 - TX Frame Interrupt (FI). */
2125 case ISB_IMC_TX_FRAME:
2126 /* BUG QUEUE for TRC stuck receive BUG */
2127 if(isb_subtype & TX_PENDING_PRIORITY_2)
2129 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2130 break;
2133 /* NON-MAC frames only */
2134 if(isb_subtype & TX_PENDING_PRIORITY_1)
2136 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2137 break;
2140 /* MAC frames only */
2141 if(isb_subtype & TX_PENDING_PRIORITY_0)
2142 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2144 /* Type 0x06 - TX END OF QUEUE (FE) */
2145 case ISB_IMC_END_OF_TX_QUEUE:
2146 /* BUG queue */
2147 if(isb_subtype & TX_PENDING_PRIORITY_2)
2149 /* ok to clear Receive FIFO overrun
2150 * imask send_BUG now completes.
2152 interrupt_unmask_bits |= 0x800;
2154 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2155 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2156 break;
2157 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2158 break;
2161 /* NON-MAC queue only */
2162 if(isb_subtype & TX_PENDING_PRIORITY_1)
2164 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2165 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2166 break;
2167 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2168 break;
2171 /* MAC queue only */
2172 if(isb_subtype & TX_PENDING_PRIORITY_0)
2174 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2175 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2176 break;
2178 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2180 break;
2182 /* Type 0x07 - NON-MAC RX Resource Interrupt
2183 * Subtype bit 12 - (BW) BDB warning
2184 * Subtype bit 13 - (FW) FCB warning
2185 * Subtype bit 14 - (BE) BDB End of chain
2186 * Subtype bit 15 - (FE) FCB End of chain
2188 case ISB_IMC_NON_MAC_RX_RESOURCE:
2189 tp->rx_fifo_overrun_count = 0;
2190 tp->receive_queue_number = NON_MAC_QUEUE;
2191 err1 = smctr_rx_frame(dev);
2193 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2195 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2197 if(tp->ptr_rx_fcb_overruns)
2198 (*tp->ptr_rx_fcb_overruns)++;
2201 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2203 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2205 if(tp->ptr_rx_bdb_overruns)
2206 (*tp->ptr_rx_bdb_overruns)++;
2208 err = err1;
2209 break;
2211 /* Type 0x08 - MAC RX Resource Interrupt
2212 * Subtype bit 12 - (BW) BDB warning
2213 * Subtype bit 13 - (FW) FCB warning
2214 * Subtype bit 14 - (BE) BDB End of chain
2215 * Subtype bit 15 - (FE) FCB End of chain
2217 case ISB_IMC_MAC_RX_RESOURCE:
2218 tp->receive_queue_number = MAC_QUEUE;
2219 err1 = smctr_rx_frame(dev);
2221 if(isb_subtype & MAC_RX_RESOURCE_FE)
2223 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2224 break;
2226 if(tp->ptr_rx_fcb_overruns)
2227 (*tp->ptr_rx_fcb_overruns)++;
2230 if(isb_subtype & MAC_RX_RESOURCE_BE)
2232 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2233 break;
2235 if(tp->ptr_rx_bdb_overruns)
2236 (*tp->ptr_rx_bdb_overruns)++;
2238 err = err1;
2239 break;
2241 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2242 case ISB_IMC_NON_MAC_RX_FRAME:
2243 tp->rx_fifo_overrun_count = 0;
2244 tp->receive_queue_number = NON_MAC_QUEUE;
2245 err = smctr_rx_frame(dev);
2246 break;
2248 /* Type 0x0A - MAC RX Frame Interrupt */
2249 case ISB_IMC_MAC_RX_FRAME:
2250 tp->receive_queue_number = MAC_QUEUE;
2251 err = smctr_rx_frame(dev);
2252 break;
2254 /* Type 0x0B - TRC status
2255 * TRC has encountered an error condition
2256 * subtype bit 14 - transmit FIFO underrun
2257 * subtype bit 15 - receive FIFO overrun
2259 case ISB_IMC_TRC_FIFO_STATUS:
2260 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2262 if(tp->ptr_tx_fifo_underruns)
2263 (*tp->ptr_tx_fifo_underruns)++;
2266 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2268 /* update overrun stuck receive counter
2269 * if >= 3, has to clear it by sending
2270 * back to back frames. We pick
2271 * DAT(duplicate address MAC frame)
2273 tp->rx_fifo_overrun_count++;
2275 if(tp->rx_fifo_overrun_count >= 3)
2277 tp->rx_fifo_overrun_count = 0;
2279 /* delay clearing fifo overrun
2280 * imask till send_BUG tx
2281 * complete posted
2283 interrupt_unmask_bits &= (~0x800);
2284 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2287 if(tp->ptr_rx_fifo_overruns)
2288 (*tp->ptr_rx_fifo_overruns)++;
2291 err = SUCCESS;
2292 break;
2294 /* Type 0x0C - Action Command Status Interrupt
2295 * Subtype bit 14 - CB end of command chain (CE)
2296 * Subtype bit 15 - CB command interrupt (CI)
2298 case ISB_IMC_COMMAND_STATUS:
2299 err = SUCCESS;
2300 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2302 printk(KERN_ERR "i1\n");
2303 smctr_disable_16bit(dev);
2305 /* XXXXXXXXXXXXXXXXX */
2306 /* err = UM_Interrupt(dev); */
2308 smctr_enable_16bit(dev);
2310 else
2312 if((tp->acb_head->cmd
2313 == ACB_CMD_READ_TRC_STATUS) &&
2314 (tp->acb_head->subcmd
2315 == RW_TRC_STATUS_BLOCK))
2317 if(tp->ptr_bcn_type)
2319 *(tp->ptr_bcn_type)
2320 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2323 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2325 smctr_update_err_stats(dev);
2328 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2330 tp->ring_status
2331 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2332 smctr_disable_16bit(dev);
2333 err = smctr_ring_status_chg(dev);
2334 smctr_enable_16bit(dev);
2335 if((tp->ring_status & REMOVE_RECEIVED) &&
2336 (tp->config_word0 & NO_AUTOREMOVE))
2338 smctr_issue_remove_cmd(dev);
2341 if(err != SUCCESS)
2343 tp->acb_pending = 0;
2344 break;
2348 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2350 if(tp->ptr_una)
2352 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2353 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2354 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2359 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2360 err = smctr_send_rq_init(dev);
2365 tp->acb_pending = 0;
2366 break;
2368 /* Type 0x0D - MAC Type 1 interrupt
2369 * Subtype -- 00 FR_BCN received at S12
2370 * 01 FR_BCN received at S21
2371 * 02 FR_DAT(DA=MA, A<>0) received at S21
2372 * 03 TSM_EXP at S21
2373 * 04 FR_REMOVE received at S42
2374 * 05 TBR_EXP, BR_FLAG_SET at S42
2375 * 06 TBT_EXP at S53
2377 case ISB_IMC_MAC_TYPE_1:
2378 if(isb_subtype > 8)
2380 err = HARDWARE_FAILED;
2381 break;
2384 err = SUCCESS;
2385 switch(isb_subtype)
2387 case 0:
2388 tp->join_state = JS_BYPASS_STATE;
2389 if(tp->status != CLOSED)
2391 tp->status = CLOSED;
2392 err = smctr_status_chg(dev);
2394 break;
2396 case 1:
2397 tp->join_state = JS_LOBE_TEST_STATE;
2398 break;
2400 case 2:
2401 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2402 break;
2404 case 3:
2405 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2406 break;
2408 case 4:
2409 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2410 break;
2412 case 5:
2413 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2414 break;
2416 case 6:
2417 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2418 break;
2420 case 7:
2421 tp->join_state = JS_JOIN_COMPLETE_STATE;
2422 tp->status = OPEN;
2423 err = smctr_status_chg(dev);
2424 break;
2426 case 8:
2427 tp->join_state = JS_BYPASS_WAIT_STATE;
2428 break;
2430 break ;
2432 /* Type 0x0E - TRC Initialization Sequence Interrupt
2433 * Subtype -- 00-FF Initializatin sequence complete
2435 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2436 tp->status = INITIALIZED;
2437 smctr_disable_16bit(dev);
2438 err = smctr_status_chg(dev);
2439 smctr_enable_16bit(dev);
2440 break;
2442 /* other interrupt types, illegal */
2443 default:
2444 break;
2447 if(err != SUCCESS)
2448 break;
2451 /* Checking the ack code instead of the unmask bits here is because :
2452 * while fixing the stuck receive, DAT frame are sent and mask off
2453 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2454 * but we still want to issue ack to ISB
2456 if(!(interrupt_ack_code & 0xff00))
2457 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2459 smctr_disable_16bit(dev);
2460 smctr_enable_bic_int(dev);
2461 spin_unlock(&tp->lock);
2463 return IRQ_HANDLED;
2466 static int smctr_issue_enable_int_cmd(struct net_device *dev,
2467 __u16 interrupt_enable_mask)
2469 struct net_local *tp = netdev_priv(dev);
2470 int err;
2472 if((err = smctr_wait_while_cbusy(dev)))
2473 return err;
2475 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2476 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2478 smctr_set_ctrl_attention(dev);
2480 return 0;
2483 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2485 struct net_local *tp = netdev_priv(dev);
2487 if(smctr_wait_while_cbusy(dev))
2488 return -1;
2490 tp->sclb_ptr->int_mask_control = ibits;
2491 tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0;
2492 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2494 smctr_set_ctrl_attention(dev);
2496 return 0;
2499 static int smctr_issue_init_timers_cmd(struct net_device *dev)
2501 struct net_local *tp = netdev_priv(dev);
2502 unsigned int i;
2503 int err;
2504 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2506 if((err = smctr_wait_while_cbusy(dev)))
2507 return err;
2509 if((err = smctr_wait_cmd(dev)))
2510 return err;
2512 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2513 tp->config_word1 = 0;
2515 if((tp->media_type == MEDIA_STP_16) ||
2516 (tp->media_type == MEDIA_UTP_16) ||
2517 (tp->media_type == MEDIA_STP_16_UTP_16))
2519 tp->config_word0 |= FREQ_16MB_BIT;
2522 if(tp->mode_bits & EARLY_TOKEN_REL)
2523 tp->config_word0 |= ETREN;
2525 if(tp->mode_bits & LOOPING_MODE_MASK)
2526 tp->config_word0 |= RX_OWN_BIT;
2527 else
2528 tp->config_word0 &= ~RX_OWN_BIT;
2530 if(tp->receive_mask & PROMISCUOUS_MODE)
2531 tp->config_word0 |= PROMISCUOUS_BIT;
2532 else
2533 tp->config_word0 &= ~PROMISCUOUS_BIT;
2535 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2536 tp->config_word0 |= SAVBAD_BIT;
2537 else
2538 tp->config_word0 &= ~SAVBAD_BIT;
2540 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2541 tp->config_word0 |= RXATMAC;
2542 else
2543 tp->config_word0 &= ~RXATMAC;
2545 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2546 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2547 else
2548 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2550 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2551 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2552 else
2554 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2555 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2556 else
2557 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2560 if((tp->media_type == MEDIA_STP_16) ||
2561 (tp->media_type == MEDIA_UTP_16) ||
2562 (tp->media_type == MEDIA_STP_16_UTP_16))
2564 tp->config_word1 |= INTERFRAME_SPACING_16;
2566 else
2567 tp->config_word1 |= INTERFRAME_SPACING_4;
2569 *pTimer_Struc++ = tp->config_word0;
2570 *pTimer_Struc++ = tp->config_word1;
2572 if((tp->media_type == MEDIA_STP_4) ||
2573 (tp->media_type == MEDIA_UTP_4) ||
2574 (tp->media_type == MEDIA_STP_4_UTP_4))
2576 *pTimer_Struc++ = 0x00FA; /* prescale */
2577 *pTimer_Struc++ = 0x2710; /* TPT_limit */
2578 *pTimer_Struc++ = 0x2710; /* TQP_limit */
2579 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2580 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2581 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2582 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2583 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2584 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2585 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2586 *pTimer_Struc++ = 0x1162; /* THT_limit */
2587 *pTimer_Struc++ = 0x07D0; /* TRR_limit */
2588 *pTimer_Struc++ = 0x1388; /* TVX_limit */
2589 *pTimer_Struc++ = 0x0000; /* reserved */
2591 else
2593 *pTimer_Struc++ = 0x03E8; /* prescale */
2594 *pTimer_Struc++ = 0x9C40; /* TPT_limit */
2595 *pTimer_Struc++ = 0x9C40; /* TQP_limit */
2596 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2597 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2598 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2599 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2600 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2601 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2602 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2603 *pTimer_Struc++ = 0x4588; /* THT_limit */
2604 *pTimer_Struc++ = 0x1F40; /* TRR_limit */
2605 *pTimer_Struc++ = 0x4E20; /* TVX_limit */
2606 *pTimer_Struc++ = 0x0000; /* reserved */
2609 /* Set node address. */
2610 *pTimer_Struc++ = dev->dev_addr[0] << 8
2611 | (dev->dev_addr[1] & 0xFF);
2612 *pTimer_Struc++ = dev->dev_addr[2] << 8
2613 | (dev->dev_addr[3] & 0xFF);
2614 *pTimer_Struc++ = dev->dev_addr[4] << 8
2615 | (dev->dev_addr[5] & 0xFF);
2617 /* Set group address. */
2618 *pTimer_Struc++ = tp->group_address_0 << 8
2619 | tp->group_address_0 >> 8;
2620 *pTimer_Struc++ = tp->group_address[0] << 8
2621 | tp->group_address[0] >> 8;
2622 *pTimer_Struc++ = tp->group_address[1] << 8
2623 | tp->group_address[1] >> 8;
2625 /* Set functional address. */
2626 *pTimer_Struc++ = tp->functional_address_0 << 8
2627 | tp->functional_address_0 >> 8;
2628 *pTimer_Struc++ = tp->functional_address[0] << 8
2629 | tp->functional_address[0] >> 8;
2630 *pTimer_Struc++ = tp->functional_address[1] << 8
2631 | tp->functional_address[1] >> 8;
2633 /* Set Bit-Wise group address. */
2634 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2635 | tp->bitwise_group_address[0] >> 8;
2636 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2637 | tp->bitwise_group_address[1] >> 8;
2639 /* Set ring number address. */
2640 *pTimer_Struc++ = tp->source_ring_number;
2641 *pTimer_Struc++ = tp->target_ring_number;
2643 /* Physical drop number. */
2644 *pTimer_Struc++ = (unsigned short)0;
2645 *pTimer_Struc++ = (unsigned short)0;
2647 /* Product instance ID. */
2648 for(i = 0; i < 9; i++)
2649 *pTimer_Struc++ = (unsigned short)0;
2651 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2653 return err;
2656 static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2658 struct net_local *tp = netdev_priv(dev);
2659 unsigned int i;
2660 int err;
2661 void **txrx_ptrs = (void *)tp->misc_command_data;
2663 if((err = smctr_wait_while_cbusy(dev)))
2664 return err;
2666 if((err = smctr_wait_cmd(dev)))
2668 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2669 return err;
2672 /* Initialize Transmit Queue Pointers that are used, to point to
2673 * a single FCB.
2675 for(i = 0; i < NUM_TX_QS_USED; i++)
2676 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2678 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2679 for(; i < MAX_TX_QS; i++)
2680 *txrx_ptrs++ = (void *)0;
2682 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2683 * used, to point to a single FCB and a BDB chain of buffers.
2685 for(i = 0; i < NUM_RX_QS_USED; i++)
2687 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2688 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2691 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2692 for(; i < MAX_RX_QS; i++)
2694 *txrx_ptrs++ = (void *)0;
2695 *txrx_ptrs++ = (void *)0;
2698 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2700 return err;
2703 static int smctr_issue_insert_cmd(struct net_device *dev)
2705 int err;
2707 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2709 return err;
2712 static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2714 int err;
2716 if((err = smctr_wait_while_cbusy(dev)))
2717 return err;
2719 if((err = smctr_wait_cmd(dev)))
2720 return err;
2722 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2723 RW_TRC_STATUS_BLOCK);
2725 return err;
2728 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2730 int err;
2732 if((err = smctr_wait_while_cbusy(dev)))
2733 return err;
2735 if((err = smctr_wait_cmd(dev)))
2736 return err;
2738 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2739 aword_cnt);
2741 return err;
2744 static int smctr_issue_remove_cmd(struct net_device *dev)
2746 struct net_local *tp = netdev_priv(dev);
2747 int err;
2749 if((err = smctr_wait_while_cbusy(dev)))
2750 return err;
2752 tp->sclb_ptr->resume_control = 0;
2753 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2755 smctr_set_ctrl_attention(dev);
2757 return 0;
2760 static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2762 struct net_local *tp = netdev_priv(dev);
2763 int err;
2765 if((err = smctr_wait_while_cbusy(dev)))
2766 return err;
2768 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2769 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2771 tp->acb_pending = 1;
2773 smctr_set_ctrl_attention(dev);
2775 return 0;
2778 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2780 struct net_local *tp = netdev_priv(dev);
2781 int err;
2783 if((err = smctr_wait_while_cbusy(dev)))
2784 return err;
2786 if(queue == MAC_QUEUE)
2787 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2788 else
2789 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2791 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2793 smctr_set_ctrl_attention(dev);
2795 return 0;
2798 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2800 struct net_local *tp = netdev_priv(dev);
2802 if(smctr_debug > 10)
2803 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2805 if(smctr_wait_while_cbusy(dev))
2806 return -1;
2808 if(queue == MAC_QUEUE)
2809 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2810 else
2811 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2813 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2815 smctr_set_ctrl_attention(dev);
2817 return 0;
2820 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2822 struct net_local *tp = netdev_priv(dev);
2824 if(smctr_debug > 10)
2825 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2827 if(smctr_wait_while_cbusy(dev))
2828 return -1;
2830 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2831 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2833 smctr_set_ctrl_attention(dev);
2835 return 0;
2838 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2840 int err;
2842 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2843 TRC_INTERNAL_ROM_TEST);
2845 return err;
2848 static int smctr_issue_test_hic_cmd(struct net_device *dev)
2850 int err;
2852 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2853 TRC_HOST_INTERFACE_REG_TEST);
2855 return err;
2858 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2860 int err;
2862 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2863 TRC_MAC_REGISTERS_TEST);
2865 return err;
2868 static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2870 int err;
2872 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2873 TRC_INTERNAL_LOOPBACK);
2875 return err;
2878 static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2880 int err;
2882 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2883 TRC_TRI_LOOPBACK);
2885 return err;
2888 static int smctr_issue_write_byte_cmd(struct net_device *dev,
2889 short aword_cnt, void *byte)
2891 struct net_local *tp = netdev_priv(dev);
2892 unsigned int iword, ibyte;
2893 int err;
2895 if((err = smctr_wait_while_cbusy(dev)))
2896 return err;
2898 if((err = smctr_wait_cmd(dev)))
2899 return err;
2901 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2902 iword++, ibyte += 2)
2904 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2905 | (*((__u8 *)byte + ibyte + 1));
2908 return smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2909 aword_cnt);
2912 static int smctr_issue_write_word_cmd(struct net_device *dev,
2913 short aword_cnt, void *word)
2915 struct net_local *tp = netdev_priv(dev);
2916 unsigned int i, err;
2918 if((err = smctr_wait_while_cbusy(dev)))
2919 return err;
2921 if((err = smctr_wait_cmd(dev)))
2922 return err;
2924 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2925 tp->misc_command_data[i] = *((__u16 *)word + i);
2927 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2928 aword_cnt);
2930 return err;
2933 static int smctr_join_complete_state(struct net_device *dev)
2935 int err;
2937 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2938 JS_JOIN_COMPLETE_STATE);
2940 return err;
2943 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2945 struct net_local *tp = netdev_priv(dev);
2946 unsigned int i, j;
2947 FCBlock *fcb;
2948 BDBlock *bdb;
2950 for(i = 0; i < NUM_TX_QS_USED; i++)
2952 fcb = tp->tx_fcb_head[i];
2953 bdb = tp->tx_bdb_head[i];
2955 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2957 fcb->bdb_ptr = bdb;
2958 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2959 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2960 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2964 return 0;
2967 static int smctr_load_firmware(struct net_device *dev)
2969 struct net_local *tp = netdev_priv(dev);
2970 const struct firmware *fw;
2971 __u16 i, checksum = 0;
2972 int err = 0;
2974 if(smctr_debug > 10)
2975 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2977 if (request_firmware(&fw, "tr_smctr.bin", &dev->dev)) {
2978 printk(KERN_ERR "%s: firmware not found\n", dev->name);
2979 return UCODE_NOT_PRESENT;
2982 tp->num_of_tx_buffs = 4;
2983 tp->mode_bits |= UMAC;
2984 tp->receive_mask = 0;
2985 tp->max_packet_size = 4177;
2987 /* Can only upload the firmware once per adapter reset. */
2988 if (tp->microcode_version != 0) {
2989 err = (UCODE_PRESENT);
2990 goto out;
2993 /* Verify the firmware exists and is there in the right amount. */
2994 if (!fw->data ||
2995 (*(fw->data + UCODE_VERSION_OFFSET) < UCODE_VERSION))
2997 err = (UCODE_NOT_PRESENT);
2998 goto out;
3001 /* UCODE_SIZE is not included in Checksum. */
3002 for(i = 0; i < *((__u16 *)(fw->data + UCODE_SIZE_OFFSET)); i += 2)
3003 checksum += *((__u16 *)(fw->data + 2 + i));
3004 if (checksum) {
3005 err = (UCODE_NOT_PRESENT);
3006 goto out;
3009 /* At this point we have a valid firmware image, lets kick it on up. */
3010 smctr_enable_adapter_ram(dev);
3011 smctr_enable_16bit(dev);
3012 smctr_set_page(dev, (__u8 *)tp->ram_access);
3014 if((smctr_checksum_firmware(dev)) ||
3015 (*(fw->data + UCODE_VERSION_OFFSET) > tp->microcode_version))
3017 smctr_enable_adapter_ctrl_store(dev);
3019 /* Zero out ram space for firmware. */
3020 for(i = 0; i < CS_RAM_SIZE; i += 2)
3021 *((__u16 *)(tp->ram_access + i)) = 0;
3023 smctr_decode_firmware(dev, fw);
3025 tp->microcode_version = *(fw->data + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
3026 = (tp->microcode_version << 8);
3027 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3028 = ~(tp->microcode_version << 8) + 1;
3030 smctr_disable_adapter_ctrl_store(dev);
3032 if(smctr_checksum_firmware(dev))
3033 err = HARDWARE_FAILED;
3035 else
3036 err = UCODE_PRESENT;
3038 smctr_disable_16bit(dev);
3039 out:
3040 release_firmware(fw);
3041 return err;
3044 static int smctr_load_node_addr(struct net_device *dev)
3046 int ioaddr = dev->base_addr;
3047 unsigned int i;
3048 __u8 r;
3050 for(i = 0; i < 6; i++)
3052 r = inb(ioaddr + LAR0 + i);
3053 dev->dev_addr[i] = (char)r;
3055 dev->addr_len = 6;
3057 return 0;
3060 /* Lobe Media Test.
3061 * During the transmission of the initial 1500 lobe media MAC frames,
3062 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3063 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3064 * microcode will not transmit any frames given to it by the host, and
3065 * will consequently cause a timeout.
3067 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
3068 * queues other than the one used for the lobe_media_test should be
3069 * disabled.!?
3071 * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
3072 * has any multi-cast or promiscuous bits set, the receive_mask needs to
3073 * be changed to clear the multi-cast or promiscuous mode bits, the lobe_test
3074 * run, and then the receive mask set back to its original value if the test
3075 * is successful.
3077 static int smctr_lobe_media_test(struct net_device *dev)
3079 struct net_local *tp = netdev_priv(dev);
3080 unsigned int i, perror = 0;
3081 unsigned short saved_rcv_mask;
3083 if(smctr_debug > 10)
3084 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3086 /* Clear receive mask for lobe test. */
3087 saved_rcv_mask = tp->receive_mask;
3088 tp->receive_mask = 0;
3090 smctr_chg_rx_mask(dev);
3092 /* Setup the lobe media test. */
3093 smctr_lobe_media_test_cmd(dev);
3094 if(smctr_wait_cmd(dev))
3095 goto err;
3097 /* Tx lobe media test frames. */
3098 for(i = 0; i < 1500; ++i)
3100 if(smctr_send_lobe_media_test(dev))
3102 if(perror)
3103 goto err;
3104 else
3106 perror = 1;
3107 if(smctr_lobe_media_test_cmd(dev))
3108 goto err;
3113 if(smctr_send_dat(dev))
3115 if(smctr_send_dat(dev))
3116 goto err;
3119 /* Check if any frames received during test. */
3120 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status) ||
3121 (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3122 goto err;
3124 /* Set receive mask to "Promisc" mode. */
3125 tp->receive_mask = saved_rcv_mask;
3127 smctr_chg_rx_mask(dev);
3129 return 0;
3130 err:
3131 smctr_reset_adapter(dev);
3132 tp->status = CLOSED;
3133 return LOBE_MEDIA_TEST_FAILED;
3136 static int smctr_lobe_media_test_cmd(struct net_device *dev)
3138 struct net_local *tp = netdev_priv(dev);
3139 int err;
3141 if(smctr_debug > 10)
3142 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3144 /* Change to lobe media test state. */
3145 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3147 smctr_lobe_media_test_state(dev);
3148 if(smctr_wait_cmd(dev))
3150 printk(KERN_ERR "Lobe Failed test state\n");
3151 return LOBE_MEDIA_TEST_FAILED;
3155 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3156 TRC_LOBE_MEDIA_TEST);
3158 return err;
3161 static int smctr_lobe_media_test_state(struct net_device *dev)
3163 int err;
3165 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3166 JS_LOBE_TEST_STATE);
3168 return err;
3171 static int smctr_make_8025_hdr(struct net_device *dev,
3172 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3174 tmf->ac = MSB(ac_fc); /* msb is access control */
3175 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3177 tmf->sa[0] = dev->dev_addr[0];
3178 tmf->sa[1] = dev->dev_addr[1];
3179 tmf->sa[2] = dev->dev_addr[2];
3180 tmf->sa[3] = dev->dev_addr[3];
3181 tmf->sa[4] = dev->dev_addr[4];
3182 tmf->sa[5] = dev->dev_addr[5];
3184 switch(tmf->vc)
3186 /* Send RQ_INIT to RPS */
3187 case RQ_INIT:
3188 tmf->da[0] = 0xc0;
3189 tmf->da[1] = 0x00;
3190 tmf->da[2] = 0x00;
3191 tmf->da[3] = 0x00;
3192 tmf->da[4] = 0x00;
3193 tmf->da[5] = 0x02;
3194 break;
3196 /* Send RPT_TX_FORWARD to CRS */
3197 case RPT_TX_FORWARD:
3198 tmf->da[0] = 0xc0;
3199 tmf->da[1] = 0x00;
3200 tmf->da[2] = 0x00;
3201 tmf->da[3] = 0x00;
3202 tmf->da[4] = 0x00;
3203 tmf->da[5] = 0x10;
3204 break;
3206 /* Everything else goes to sender */
3207 default:
3208 tmf->da[0] = rmf->sa[0];
3209 tmf->da[1] = rmf->sa[1];
3210 tmf->da[2] = rmf->sa[2];
3211 tmf->da[3] = rmf->sa[3];
3212 tmf->da[4] = rmf->sa[4];
3213 tmf->da[5] = rmf->sa[5];
3214 break;
3217 return 0;
3220 static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3222 struct net_local *tp = netdev_priv(dev);
3224 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3225 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3227 tsv->svv[0] = MSB(tp->authorized_access_priority);
3228 tsv->svv[1] = LSB(tp->authorized_access_priority);
3230 return 0;
3233 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3235 tsv->svi = ADDRESS_MODIFER;
3236 tsv->svl = S_ADDRESS_MODIFER;
3238 tsv->svv[0] = 0;
3239 tsv->svv[1] = 0;
3241 return 0;
3244 static int smctr_make_auth_funct_class(struct net_device *dev,
3245 MAC_SUB_VECTOR *tsv)
3247 struct net_local *tp = netdev_priv(dev);
3249 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3250 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3252 tsv->svv[0] = MSB(tp->authorized_function_classes);
3253 tsv->svv[1] = LSB(tp->authorized_function_classes);
3255 return 0;
3258 static int smctr_make_corr(struct net_device *dev,
3259 MAC_SUB_VECTOR *tsv, __u16 correlator)
3261 tsv->svi = CORRELATOR;
3262 tsv->svl = S_CORRELATOR;
3264 tsv->svv[0] = MSB(correlator);
3265 tsv->svv[1] = LSB(correlator);
3267 return 0;
3270 static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3272 struct net_local *tp = netdev_priv(dev);
3274 smctr_get_functional_address(dev);
3276 tsv->svi = FUNCTIONAL_ADDRESS;
3277 tsv->svl = S_FUNCTIONAL_ADDRESS;
3279 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3280 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3282 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3283 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3285 return 0;
3288 static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3290 struct net_local *tp = netdev_priv(dev);
3292 smctr_get_group_address(dev);
3294 tsv->svi = GROUP_ADDRESS;
3295 tsv->svl = S_GROUP_ADDRESS;
3297 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3298 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3300 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3301 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3303 /* Set Group Address Sub-vector to all zeros if only the
3304 * Group Address/Functional Address Indicator is set.
3306 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00 &&
3307 tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3308 tsv->svv[0] = 0x00;
3310 return 0;
3313 static int smctr_make_phy_drop_num(struct net_device *dev,
3314 MAC_SUB_VECTOR *tsv)
3316 struct net_local *tp = netdev_priv(dev);
3318 smctr_get_physical_drop_number(dev);
3320 tsv->svi = PHYSICAL_DROP;
3321 tsv->svl = S_PHYSICAL_DROP;
3323 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3324 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3326 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3327 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3329 return 0;
3332 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3334 int i;
3336 tsv->svi = PRODUCT_INSTANCE_ID;
3337 tsv->svl = S_PRODUCT_INSTANCE_ID;
3339 for(i = 0; i < 18; i++)
3340 tsv->svv[i] = 0xF0;
3342 return 0;
3345 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3347 struct net_local *tp = netdev_priv(dev);
3349 smctr_get_station_id(dev);
3351 tsv->svi = STATION_IDENTIFER;
3352 tsv->svl = S_STATION_IDENTIFER;
3354 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3355 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3357 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3358 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3360 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3361 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3363 return 0;
3366 static int smctr_make_ring_station_status(struct net_device *dev,
3367 MAC_SUB_VECTOR * tsv)
3369 tsv->svi = RING_STATION_STATUS;
3370 tsv->svl = S_RING_STATION_STATUS;
3372 tsv->svv[0] = 0;
3373 tsv->svv[1] = 0;
3374 tsv->svv[2] = 0;
3375 tsv->svv[3] = 0;
3376 tsv->svv[4] = 0;
3377 tsv->svv[5] = 0;
3379 return 0;
3382 static int smctr_make_ring_station_version(struct net_device *dev,
3383 MAC_SUB_VECTOR *tsv)
3385 struct net_local *tp = netdev_priv(dev);
3387 tsv->svi = RING_STATION_VERSION_NUMBER;
3388 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3390 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3391 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3392 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3393 tsv->svv[3] = 0x40; /* EBCDIC - */
3394 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3395 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3396 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3397 tsv->svv[7] = 0x40; /* EBCDIC - */
3398 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3400 if(tp->extra_info & CHIP_REV_MASK)
3401 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3402 else
3403 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3405 return 0;
3408 static int smctr_make_tx_status_code(struct net_device *dev,
3409 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3411 tsv->svi = TRANSMIT_STATUS_CODE;
3412 tsv->svl = S_TRANSMIT_STATUS_CODE;
3414 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) | IBM_PASS_SOURCE_ADDR);
3416 /* Stripped frame status of Transmitted Frame */
3417 tsv->svv[1] = tx_fstatus & 0xff;
3419 return 0;
3422 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3423 MAC_SUB_VECTOR *tsv)
3425 struct net_local *tp = netdev_priv(dev);
3427 smctr_get_upstream_neighbor_addr(dev);
3429 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3430 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3432 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3433 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3435 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3436 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3438 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3439 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3441 return 0;
3444 static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3446 tsv->svi = WRAP_DATA;
3447 tsv->svl = S_WRAP_DATA;
3449 return 0;
3453 * Open/initialize the board. This is called sometime after
3454 * booting when the 'ifconfig' program is run.
3456 * This routine should set everything up anew at each open, even
3457 * registers that "should" only need to be set once at boot, so that
3458 * there is non-reboot way to recover if something goes wrong.
3460 static int smctr_open(struct net_device *dev)
3462 int err;
3464 if(smctr_debug > 10)
3465 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3467 err = smctr_init_adapter(dev);
3468 if(err < 0)
3469 return err;
3471 return err;
3474 /* Interrupt driven open of Token card. */
3475 static int smctr_open_tr(struct net_device *dev)
3477 struct net_local *tp = netdev_priv(dev);
3478 unsigned long flags;
3479 int err;
3481 if(smctr_debug > 10)
3482 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3484 /* Now we can actually open the adapter. */
3485 if(tp->status == OPEN)
3486 return 0;
3487 if(tp->status != INITIALIZED)
3488 return -1;
3490 /* FIXME: it would work a lot better if we masked the irq sources
3491 on the card here, then we could skip the locking and poll nicely */
3492 spin_lock_irqsave(&tp->lock, flags);
3494 smctr_set_page(dev, (__u8 *)tp->ram_access);
3496 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3497 goto out;
3499 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3500 goto out;
3502 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3503 goto out;
3505 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3506 goto out;
3508 tp->status = CLOSED;
3510 /* Insert into the Ring or Enter Loopback Mode. */
3511 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3513 tp->status = CLOSED;
3515 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3517 if(!(err = smctr_wait_cmd(dev)))
3518 tp->status = OPEN;
3521 smctr_status_chg(dev);
3523 else
3525 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3527 tp->status = CLOSED;
3528 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3530 if(!(err = smctr_wait_cmd(dev)))
3531 tp->status = OPEN;
3534 smctr_status_chg(dev);
3536 else
3538 if((tp->mode_bits & LOOPING_MODE_MASK)
3539 == LOOPBACK_MODE_3)
3541 tp->status = CLOSED;
3542 if(!(err = smctr_lobe_media_test_cmd(dev)))
3544 if(!(err = smctr_wait_cmd(dev)))
3545 tp->status = OPEN;
3547 smctr_status_chg(dev);
3549 else
3551 if(!(err = smctr_lobe_media_test(dev)))
3552 err = smctr_issue_insert_cmd(dev);
3553 else
3555 if(err == LOBE_MEDIA_TEST_FAILED)
3556 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3562 out:
3563 spin_unlock_irqrestore(&tp->lock, flags);
3565 return err;
3568 /* Check for a network adapter of this type,
3569 * and return device structure if one exists.
3571 struct net_device __init *smctr_probe(int unit)
3573 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3574 static const unsigned ports[] = {
3575 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3576 0x320, 0x340, 0x360, 0x380, 0
3578 const unsigned *port;
3579 int err = 0;
3581 if (!dev)
3582 return ERR_PTR(-ENOMEM);
3584 if (unit >= 0) {
3585 sprintf(dev->name, "tr%d", unit);
3586 netdev_boot_setup_check(dev);
3589 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3590 err = smctr_probe1(dev, dev->base_addr);
3591 else if(dev->base_addr != 0) /* Don't probe at all. */
3592 err =-ENXIO;
3593 else {
3594 for (port = ports; *port; port++) {
3595 err = smctr_probe1(dev, *port);
3596 if (!err)
3597 break;
3600 if (err)
3601 goto out;
3602 err = register_netdev(dev);
3603 if (err)
3604 goto out1;
3605 return dev;
3606 out1:
3607 #ifdef CONFIG_MCA_LEGACY
3608 { struct net_local *tp = netdev_priv(dev);
3609 if (tp->slot_num)
3610 mca_mark_as_unused(tp->slot_num);
3612 #endif
3613 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3614 free_irq(dev->irq, dev);
3615 out:
3616 free_netdev(dev);
3617 return ERR_PTR(err);
3620 static const struct net_device_ops smctr_netdev_ops = {
3621 .ndo_open = smctr_open,
3622 .ndo_stop = smctr_close,
3623 .ndo_start_xmit = smctr_send_packet,
3624 .ndo_tx_timeout = smctr_timeout,
3625 .ndo_get_stats = smctr_get_stats,
3626 .ndo_set_rx_mode = smctr_set_multicast_list,
3629 static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3631 static unsigned version_printed;
3632 struct net_local *tp = netdev_priv(dev);
3633 int err;
3634 __u32 *ram;
3636 if(smctr_debug && version_printed++ == 0)
3637 printk(version);
3639 spin_lock_init(&tp->lock);
3640 dev->base_addr = ioaddr;
3642 /* Actually detect an adapter now. */
3643 err = smctr_chk_isa(dev);
3644 if(err < 0)
3646 if ((err = smctr_chk_mca(dev)) < 0) {
3647 err = -ENODEV;
3648 goto out;
3652 tp = netdev_priv(dev);
3653 dev->mem_start = tp->ram_base;
3654 dev->mem_end = dev->mem_start + 0x10000;
3655 ram = (__u32 *)phys_to_virt(dev->mem_start);
3656 tp->ram_access = *(__u32 *)&ram;
3657 tp->status = NOT_INITIALIZED;
3659 err = smctr_load_firmware(dev);
3660 if(err != UCODE_PRESENT && err != SUCCESS)
3662 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3663 err = -EIO;
3664 goto out;
3667 /* Allow user to specify ring speed on module insert. */
3668 if(ringspeed == 4)
3669 tp->media_type = MEDIA_UTP_4;
3670 else
3671 tp->media_type = MEDIA_UTP_16;
3673 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3674 dev->name, smctr_name, smctr_model,
3675 (unsigned int)dev->base_addr,
3676 dev->irq, tp->rom_base, tp->ram_base);
3678 dev->netdev_ops = &smctr_netdev_ops;
3679 dev->watchdog_timeo = HZ;
3680 return 0;
3682 out:
3683 return err;
3686 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3687 struct net_device *dev, __u16 rx_status)
3689 struct net_local *tp = netdev_priv(dev);
3690 struct sk_buff *skb;
3691 __u16 rcode, correlator;
3692 int err = 0;
3693 __u8 xframe = 1;
3695 rmf->vl = SWAP_BYTES(rmf->vl);
3696 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3698 switch(rmf->vc)
3700 /* Received MAC Frames Processed by RS. */
3701 case INIT:
3702 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3704 return rcode;
3707 if((err = smctr_send_rsp(dev, rmf, rcode,
3708 correlator)))
3710 return err;
3712 break;
3714 case CHG_PARM:
3715 if((rcode = smctr_rcv_chg_param(dev, rmf,
3716 &correlator)) ==HARDWARE_FAILED)
3718 return rcode;
3721 if((err = smctr_send_rsp(dev, rmf, rcode,
3722 correlator)))
3724 return err;
3726 break;
3728 case RQ_ADDR:
3729 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3730 rmf, &correlator)) != POSITIVE_ACK)
3732 if(rcode == HARDWARE_FAILED)
3733 return rcode;
3734 else
3735 return smctr_send_rsp(dev, rmf,
3736 rcode, correlator);
3739 if((err = smctr_send_rpt_addr(dev, rmf,
3740 correlator)))
3742 return err;
3744 break;
3746 case RQ_ATTCH:
3747 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3748 rmf, &correlator)) != POSITIVE_ACK)
3750 if(rcode == HARDWARE_FAILED)
3751 return rcode;
3752 else
3753 return smctr_send_rsp(dev, rmf,
3754 rcode,
3755 correlator);
3758 if((err = smctr_send_rpt_attch(dev, rmf,
3759 correlator)))
3761 return err;
3763 break;
3765 case RQ_STATE:
3766 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3767 rmf, &correlator)) != POSITIVE_ACK)
3769 if(rcode == HARDWARE_FAILED)
3770 return rcode;
3771 else
3772 return smctr_send_rsp(dev, rmf,
3773 rcode,
3774 correlator);
3777 if((err = smctr_send_rpt_state(dev, rmf,
3778 correlator)))
3780 return err;
3782 break;
3784 case TX_FORWARD: {
3785 __u16 uninitialized_var(tx_fstatus);
3787 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3788 != POSITIVE_ACK)
3790 if(rcode == HARDWARE_FAILED)
3791 return rcode;
3792 else
3793 return smctr_send_rsp(dev, rmf,
3794 rcode,
3795 correlator);
3798 if((err = smctr_send_tx_forward(dev, rmf,
3799 &tx_fstatus)) == HARDWARE_FAILED)
3801 return err;
3804 if(err == A_FRAME_WAS_FORWARDED)
3806 if((err = smctr_send_rpt_tx_forward(dev,
3807 rmf, tx_fstatus))
3808 == HARDWARE_FAILED)
3810 return err;
3813 break;
3816 /* Received MAC Frames Processed by CRS/REM/RPS. */
3817 case RSP:
3818 case RQ_INIT:
3819 case RPT_NEW_MON:
3820 case RPT_SUA_CHG:
3821 case RPT_ACTIVE_ERR:
3822 case RPT_NN_INCMP:
3823 case RPT_ERROR:
3824 case RPT_ATTCH:
3825 case RPT_STATE:
3826 case RPT_ADDR:
3827 break;
3829 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3830 default:
3831 xframe = 0;
3832 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3834 rcode = smctr_rcv_unknown(dev, rmf,
3835 &correlator);
3836 if((err = smctr_send_rsp(dev, rmf,rcode,
3837 correlator)))
3839 return err;
3843 break;
3846 else
3848 /* 1. DA doesn't match (Promiscuous Mode).
3849 * 2. Parse for Extended MAC Frame Type.
3851 switch(rmf->vc)
3853 case RSP:
3854 case INIT:
3855 case RQ_INIT:
3856 case RQ_ADDR:
3857 case RQ_ATTCH:
3858 case RQ_STATE:
3859 case CHG_PARM:
3860 case RPT_ADDR:
3861 case RPT_ERROR:
3862 case RPT_ATTCH:
3863 case RPT_STATE:
3864 case RPT_NEW_MON:
3865 case RPT_SUA_CHG:
3866 case RPT_NN_INCMP:
3867 case RPT_ACTIVE_ERR:
3868 break;
3870 default:
3871 xframe = 0;
3872 break;
3876 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3877 * ACCEPT_ATT_MAC_FRAMES is set.
3879 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES) &&
3880 (xframe == (__u8)0)) ||
3881 ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES) &&
3882 (xframe == (__u8)1)))
3884 rmf->vl = SWAP_BYTES(rmf->vl);
3886 if (!(skb = dev_alloc_skb(size)))
3887 return -ENOMEM;
3888 skb->len = size;
3890 /* Slide data into a sleek skb. */
3891 skb_put(skb, skb->len);
3892 skb_copy_to_linear_data(skb, rmf, skb->len);
3894 /* Update Counters */
3895 tp->MacStat.rx_packets++;
3896 tp->MacStat.rx_bytes += skb->len;
3898 /* Kick the packet on up. */
3899 skb->protocol = tr_type_trans(skb, dev);
3900 netif_rx(skb);
3901 err = 0;
3904 return err;
3907 /* Adapter RAM test. Incremental word ODD boundary data test. */
3908 static int smctr_ram_memory_test(struct net_device *dev)
3910 struct net_local *tp = netdev_priv(dev);
3911 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3912 word_read = 0, err_word = 0, err_pattern = 0;
3913 unsigned int err_offset;
3914 __u32 j, pword;
3915 __u8 err = 0;
3917 if(smctr_debug > 10)
3918 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3920 start_pattern = 0x0001;
3921 pages_of_ram = tp->ram_size / tp->ram_usable;
3922 pword = tp->ram_access;
3924 /* Incremental word ODD boundary test. */
3925 for(page = 0; (page < pages_of_ram) && (~err);
3926 page++, start_pattern += 0x8000)
3928 smctr_set_page(dev, (__u8 *)(tp->ram_access
3929 + (page * tp->ram_usable * 1024) + 1));
3930 word_pattern = start_pattern;
3932 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3933 *(__u16 *)(pword + j) = word_pattern++;
3935 word_pattern = start_pattern;
3937 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1 && (~err);
3938 j += 2, word_pattern++)
3940 word_read = *(__u16 *)(pword + j);
3941 if(word_read != word_pattern)
3943 err = (__u8)1;
3944 err_offset = j;
3945 err_word = word_read;
3946 err_pattern = word_pattern;
3947 return RAM_TEST_FAILED;
3952 /* Zero out memory. */
3953 for(page = 0; page < pages_of_ram && (~err); page++)
3955 smctr_set_page(dev, (__u8 *)(tp->ram_access
3956 + (page * tp->ram_usable * 1024)));
3957 word_pattern = 0;
3959 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3960 *(__u16 *)(pword + j) = word_pattern;
3962 for(j =0; j < (__u32)tp->ram_usable * 1024 && (~err); j += 2)
3964 word_read = *(__u16 *)(pword + j);
3965 if(word_read != word_pattern)
3967 err = (__u8)1;
3968 err_offset = j;
3969 err_word = word_read;
3970 err_pattern = word_pattern;
3971 return RAM_TEST_FAILED;
3976 smctr_set_page(dev, (__u8 *)tp->ram_access);
3978 return 0;
3981 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3982 __u16 *correlator)
3984 MAC_SUB_VECTOR *rsv;
3985 signed short vlen;
3986 __u16 rcode = POSITIVE_ACK;
3987 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
3989 /* This Frame can only come from a CRS */
3990 if((rmf->dc_sc & SC_MASK) != SC_CRS)
3991 return E_INAPPROPRIATE_SOURCE_CLASS;
3993 /* Remove MVID Length from total length. */
3994 vlen = (signed short)rmf->vl - 4;
3996 /* Point to First SVID */
3997 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
3999 /* Search for Appropriate SVID's. */
4000 while((vlen > 0) && (rcode == POSITIVE_ACK))
4002 switch(rsv->svi)
4004 case CORRELATOR:
4005 svectors |= F_CORRELATOR;
4006 rcode = smctr_set_corr(dev, rsv, correlator);
4007 break;
4009 case LOCAL_RING_NUMBER:
4010 svectors |= F_LOCAL_RING_NUMBER;
4011 rcode = smctr_set_local_ring_num(dev, rsv);
4012 break;
4014 case ASSIGN_PHYSICAL_DROP:
4015 svectors |= F_ASSIGN_PHYSICAL_DROP;
4016 rcode = smctr_set_phy_drop(dev, rsv);
4017 break;
4019 case ERROR_TIMER_VALUE:
4020 svectors |= F_ERROR_TIMER_VALUE;
4021 rcode = smctr_set_error_timer_value(dev, rsv);
4022 break;
4024 case AUTHORIZED_FUNCTION_CLASS:
4025 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4026 rcode = smctr_set_auth_funct_class(dev, rsv);
4027 break;
4029 case AUTHORIZED_ACCESS_PRIORITY:
4030 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4031 rcode = smctr_set_auth_access_pri(dev, rsv);
4032 break;
4034 default:
4035 rcode = E_SUB_VECTOR_UNKNOWN;
4036 break;
4039 /* Let Sender Know if SUM of SV length's is
4040 * larger then length in MVID length field
4042 if((vlen -= rsv->svl) < 0)
4043 rcode = E_VECTOR_LENGTH_ERROR;
4045 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4048 if(rcode == POSITIVE_ACK)
4050 /* Let Sender Know if MVID length field
4051 * is larger then SUM of SV length's
4053 if(vlen != 0)
4054 rcode = E_VECTOR_LENGTH_ERROR;
4055 else
4057 /* Let Sender Know if Expected SVID Missing */
4058 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4059 rcode = E_MISSING_SUB_VECTOR;
4063 return rcode;
4066 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4067 __u16 *correlator)
4069 MAC_SUB_VECTOR *rsv;
4070 signed short vlen;
4071 __u16 rcode = POSITIVE_ACK;
4072 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4074 /* This Frame can only come from a RPS */
4075 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4076 return E_INAPPROPRIATE_SOURCE_CLASS;
4078 /* Remove MVID Length from total length. */
4079 vlen = (signed short)rmf->vl - 4;
4081 /* Point to First SVID */
4082 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4084 /* Search for Appropriate SVID's */
4085 while((vlen > 0) && (rcode == POSITIVE_ACK))
4087 switch(rsv->svi)
4089 case CORRELATOR:
4090 svectors |= F_CORRELATOR;
4091 rcode = smctr_set_corr(dev, rsv, correlator);
4092 break;
4094 case LOCAL_RING_NUMBER:
4095 svectors |= F_LOCAL_RING_NUMBER;
4096 rcode = smctr_set_local_ring_num(dev, rsv);
4097 break;
4099 case ASSIGN_PHYSICAL_DROP:
4100 svectors |= F_ASSIGN_PHYSICAL_DROP;
4101 rcode = smctr_set_phy_drop(dev, rsv);
4102 break;
4104 case ERROR_TIMER_VALUE:
4105 svectors |= F_ERROR_TIMER_VALUE;
4106 rcode = smctr_set_error_timer_value(dev, rsv);
4107 break;
4109 default:
4110 rcode = E_SUB_VECTOR_UNKNOWN;
4111 break;
4114 /* Let Sender Know if SUM of SV length's is
4115 * larger then length in MVID length field
4117 if((vlen -= rsv->svl) < 0)
4118 rcode = E_VECTOR_LENGTH_ERROR;
4120 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4123 if(rcode == POSITIVE_ACK)
4125 /* Let Sender Know if MVID length field
4126 * is larger then SUM of SV length's
4128 if(vlen != 0)
4129 rcode = E_VECTOR_LENGTH_ERROR;
4130 else
4132 /* Let Sender Know if Expected SV Missing */
4133 if((svectors & R_INIT) ^ R_INIT)
4134 rcode = E_MISSING_SUB_VECTOR;
4138 return rcode;
4141 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4143 MAC_SUB_VECTOR *rsv;
4144 signed short vlen;
4145 __u16 rcode = POSITIVE_ACK;
4146 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4148 /* This Frame can only come from a CRS */
4149 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4150 return E_INAPPROPRIATE_SOURCE_CLASS;
4152 /* Remove MVID Length from total length */
4153 vlen = (signed short)rmf->vl - 4;
4155 /* Point to First SVID */
4156 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4158 /* Search for Appropriate SVID's */
4159 while((vlen > 0) && (rcode == POSITIVE_ACK))
4161 switch(rsv->svi)
4163 case FRAME_FORWARD:
4164 svectors |= F_FRAME_FORWARD;
4165 rcode = smctr_set_frame_forward(dev, rsv,
4166 rmf->dc_sc);
4167 break;
4169 default:
4170 rcode = E_SUB_VECTOR_UNKNOWN;
4171 break;
4174 /* Let Sender Know if SUM of SV length's is
4175 * larger then length in MVID length field
4177 if((vlen -= rsv->svl) < 0)
4178 rcode = E_VECTOR_LENGTH_ERROR;
4180 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4183 if(rcode == POSITIVE_ACK)
4185 /* Let Sender Know if MVID length field
4186 * is larger then SUM of SV length's
4188 if(vlen != 0)
4189 rcode = E_VECTOR_LENGTH_ERROR;
4190 else
4192 /* Let Sender Know if Expected SV Missing */
4193 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4194 rcode = E_MISSING_SUB_VECTOR;
4198 return rcode;
4201 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4202 MAC_HEADER *rmf, __u16 *correlator)
4204 MAC_SUB_VECTOR *rsv;
4205 signed short vlen;
4206 __u16 rcode = POSITIVE_ACK;
4207 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4209 /* Remove MVID Length from total length */
4210 vlen = (signed short)rmf->vl - 4;
4212 /* Point to First SVID */
4213 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4215 /* Search for Appropriate SVID's */
4216 while((vlen > 0) && (rcode == POSITIVE_ACK))
4218 switch(rsv->svi)
4220 case CORRELATOR:
4221 svectors |= F_CORRELATOR;
4222 rcode = smctr_set_corr(dev, rsv, correlator);
4223 break;
4225 default:
4226 rcode = E_SUB_VECTOR_UNKNOWN;
4227 break;
4230 /* Let Sender Know if SUM of SV length's is
4231 * larger then length in MVID length field
4233 if((vlen -= rsv->svl) < 0)
4234 rcode = E_VECTOR_LENGTH_ERROR;
4236 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4239 if(rcode == POSITIVE_ACK)
4241 /* Let Sender Know if MVID length field
4242 * is larger then SUM of SV length's
4244 if(vlen != 0)
4245 rcode = E_VECTOR_LENGTH_ERROR;
4246 else
4248 /* Let Sender Know if Expected SVID Missing */
4249 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4250 ^ R_RQ_ATTCH_STATE_ADDR)
4251 rcode = E_MISSING_SUB_VECTOR;
4255 return rcode;
4258 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4259 __u16 *correlator)
4261 MAC_SUB_VECTOR *rsv;
4262 signed short vlen;
4264 *correlator = 0;
4266 /* Remove MVID Length from total length */
4267 vlen = (signed short)rmf->vl - 4;
4269 /* Point to First SVID */
4270 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4272 /* Search for CORRELATOR for RSP to UNKNOWN */
4273 while((vlen > 0) && (*correlator == 0))
4275 switch(rsv->svi)
4277 case CORRELATOR:
4278 smctr_set_corr(dev, rsv, correlator);
4279 break;
4281 default:
4282 break;
4285 vlen -= rsv->svl;
4286 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4289 return E_UNRECOGNIZED_VECTOR_ID;
4293 * Reset the 825 NIC and exit w:
4294 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4295 * 2. TINT masked.
4296 * 3. CBUSY masked.
4297 * 4. TINT clear.
4298 * 5. CBUSY clear.
4300 static int smctr_reset_adapter(struct net_device *dev)
4302 struct net_local *tp = netdev_priv(dev);
4303 int ioaddr = dev->base_addr;
4305 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4306 mdelay(200); /* ~2 ms */
4308 smctr_clear_trc_reset(ioaddr);
4309 mdelay(200); /* ~2 ms */
4311 /* Remove any latched interrupts that occurred prior to reseting the
4312 * adapter or possibily caused by line glitches due to the reset.
4314 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4316 return 0;
4319 static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4321 struct net_local *tp = netdev_priv(dev);
4322 int err = 0;
4324 if(smctr_debug > 10)
4325 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4327 if(tp->num_tx_fcbs_used[queue] != 0 &&
4328 tp->tx_queue_status[queue] == NOT_TRANSMITING)
4330 tp->tx_queue_status[queue] = TRANSMITING;
4331 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4334 return err;
4337 static int smctr_ring_status_chg(struct net_device *dev)
4339 struct net_local *tp = netdev_priv(dev);
4341 if(smctr_debug > 10)
4342 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4344 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4345 * Bit is set, check value of monitor_state, only then we
4346 * enable and start transmit/receive timeout (if and only
4347 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4349 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4351 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE) ||
4352 (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4354 tp->monitor_state_ready = 1;
4356 else
4358 /* if adapter is NOT in either active monitor
4359 * or standby monitor state => Disable
4360 * transmit/receive timeout.
4362 tp->monitor_state_ready = 0;
4364 /* Ring speed problem, switching to auto mode. */
4365 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE &&
4366 !tp->cleanup)
4368 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4369 dev->name);
4370 smctr_set_ring_speed(dev);
4375 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4376 return 0;
4378 switch(tp->ring_status)
4380 case RING_RECOVERY:
4381 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
4382 break;
4384 case SINGLE_STATION:
4385 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
4386 break;
4388 case COUNTER_OVERFLOW:
4389 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
4390 break;
4392 case REMOVE_RECEIVED:
4393 printk(KERN_INFO "%s: Remove Received\n", dev->name);
4394 break;
4396 case AUTO_REMOVAL_ERROR:
4397 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
4398 break;
4400 case LOBE_WIRE_FAULT:
4401 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
4402 break;
4404 case TRANSMIT_BEACON:
4405 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
4406 break;
4408 case SOFT_ERROR:
4409 printk(KERN_INFO "%s: Soft Error\n", dev->name);
4410 break;
4412 case HARD_ERROR:
4413 printk(KERN_INFO "%s: Hard Error\n", dev->name);
4414 break;
4416 case SIGNAL_LOSS:
4417 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
4418 break;
4420 default:
4421 printk(KERN_INFO "%s: Unknown ring status change\n",
4422 dev->name);
4423 break;
4426 return 0;
4429 static int smctr_rx_frame(struct net_device *dev)
4431 struct net_local *tp = netdev_priv(dev);
4432 __u16 queue, status, rx_size, err = 0;
4433 __u8 *pbuff;
4435 if(smctr_debug > 10)
4436 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4438 queue = tp->receive_queue_number;
4440 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4442 err = HARDWARE_FAILED;
4444 if(((status & 0x007f) == 0) ||
4445 ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4447 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4448 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4450 pbuff = smctr_get_rx_pointer(dev, queue);
4452 smctr_set_page(dev, pbuff);
4453 smctr_disable_16bit(dev);
4455 /* pbuff points to addr within one page */
4456 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4458 if(queue == NON_MAC_QUEUE)
4460 struct sk_buff *skb;
4462 skb = dev_alloc_skb(rx_size);
4463 if (skb) {
4464 skb_put(skb, rx_size);
4466 skb_copy_to_linear_data(skb, pbuff, rx_size);
4468 /* Update Counters */
4469 tp->MacStat.rx_packets++;
4470 tp->MacStat.rx_bytes += skb->len;
4472 /* Kick the packet on up. */
4473 skb->protocol = tr_type_trans(skb, dev);
4474 netif_rx(skb);
4475 } else {
4478 else
4479 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4480 rx_size, dev, status);
4483 smctr_enable_16bit(dev);
4484 smctr_set_page(dev, (__u8 *)tp->ram_access);
4485 smctr_update_rx_chain(dev, queue);
4487 if(err != SUCCESS)
4488 break;
4491 return err;
4494 static int smctr_send_dat(struct net_device *dev)
4496 struct net_local *tp = netdev_priv(dev);
4497 unsigned int i, err;
4498 MAC_HEADER *tmf;
4499 FCBlock *fcb;
4501 if(smctr_debug > 10)
4502 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4504 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4505 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4507 return OUT_OF_RESOURCES;
4510 /* Initialize DAT Data Fields. */
4511 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4512 tmf->ac = MSB(AC_FC_DAT);
4513 tmf->fc = LSB(AC_FC_DAT);
4515 for(i = 0; i < 6; i++)
4517 tmf->sa[i] = dev->dev_addr[i];
4518 tmf->da[i] = dev->dev_addr[i];
4522 tmf->vc = DAT;
4523 tmf->dc_sc = DC_RS | SC_RS;
4524 tmf->vl = 4;
4525 tmf->vl = SWAP_BYTES(tmf->vl);
4527 /* Start Transmit. */
4528 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4529 return err;
4531 /* Wait for Transmit to Complete */
4532 for(i = 0; i < 10000; i++)
4534 if(fcb->frame_status & FCB_COMMAND_DONE)
4535 break;
4536 mdelay(1);
4539 /* Check if GOOD frame Tx'ed. */
4540 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4541 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4543 return INITIALIZE_FAILED;
4546 /* De-allocated Tx FCB and Frame Buffer
4547 * The FCB must be de-allocated manually if executing with
4548 * interrupts disabled, other wise the ISR (LM_Service_Events)
4549 * will de-allocate it when the interrupt occurs.
4551 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4552 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4554 return 0;
4557 static void smctr_timeout(struct net_device *dev)
4560 * If we get here, some higher level has decided we are broken.
4561 * There should really be a "kick me" function call instead.
4563 * Resetting the token ring adapter takes a long time so just
4564 * fake transmission time and go on trying. Our own timeout
4565 * routine is in sktr_timer_chk()
4567 dev->trans_start = jiffies; /* prevent tx timeout */
4568 netif_wake_queue(dev);
4572 * Gets skb from system, queues it and checks if it can be sent
4574 static netdev_tx_t smctr_send_packet(struct sk_buff *skb,
4575 struct net_device *dev)
4577 struct net_local *tp = netdev_priv(dev);
4579 if(smctr_debug > 10)
4580 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4583 * Block a transmit overlap
4586 netif_stop_queue(dev);
4588 if(tp->QueueSkb == 0)
4589 return NETDEV_TX_BUSY; /* Return with tbusy set: queue full */
4591 tp->QueueSkb--;
4592 skb_queue_tail(&tp->SendSkbQueue, skb);
4593 smctr_hardware_send_packet(dev, tp);
4594 if(tp->QueueSkb > 0)
4595 netif_wake_queue(dev);
4597 return NETDEV_TX_OK;
4600 static int smctr_send_lobe_media_test(struct net_device *dev)
4602 struct net_local *tp = netdev_priv(dev);
4603 MAC_SUB_VECTOR *tsv;
4604 MAC_HEADER *tmf;
4605 FCBlock *fcb;
4606 __u32 i;
4607 int err;
4609 if(smctr_debug > 15)
4610 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4612 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4613 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4615 return OUT_OF_RESOURCES;
4618 /* Initialize DAT Data Fields. */
4619 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4620 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4621 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4623 for(i = 0; i < 6; i++)
4625 tmf->da[i] = 0;
4626 tmf->sa[i] = dev->dev_addr[i];
4629 tmf->vc = LOBE_MEDIA_TEST;
4630 tmf->dc_sc = DC_RS | SC_RS;
4631 tmf->vl = 4;
4633 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4634 smctr_make_wrap_data(dev, tsv);
4635 tmf->vl += tsv->svl;
4637 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4638 smctr_make_wrap_data(dev, tsv);
4639 tmf->vl += tsv->svl;
4641 /* Start Transmit. */
4642 tmf->vl = SWAP_BYTES(tmf->vl);
4643 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4644 return err;
4646 /* Wait for Transmit to Complete. (10 ms). */
4647 for(i=0; i < 10000; i++)
4649 if(fcb->frame_status & FCB_COMMAND_DONE)
4650 break;
4651 mdelay(1);
4654 /* Check if GOOD frame Tx'ed */
4655 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4656 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4658 return LOBE_MEDIA_TEST_FAILED;
4661 /* De-allocated Tx FCB and Frame Buffer
4662 * The FCB must be de-allocated manually if executing with
4663 * interrupts disabled, other wise the ISR (LM_Service_Events)
4664 * will de-allocate it when the interrupt occurs.
4666 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4667 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4669 return 0;
4672 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4673 __u16 correlator)
4675 MAC_HEADER *tmf;
4676 MAC_SUB_VECTOR *tsv;
4677 FCBlock *fcb;
4679 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4680 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4681 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4682 == (FCBlock *)(-1L))
4684 return 0;
4687 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4688 tmf->vc = RPT_ADDR;
4689 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4690 tmf->vl = 4;
4692 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4694 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4695 smctr_make_corr(dev, tsv, correlator);
4697 tmf->vl += tsv->svl;
4698 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4699 smctr_make_phy_drop_num(dev, tsv);
4701 tmf->vl += tsv->svl;
4702 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4703 smctr_make_upstream_neighbor_addr(dev, tsv);
4705 tmf->vl += tsv->svl;
4706 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4707 smctr_make_addr_mod(dev, tsv);
4709 tmf->vl += tsv->svl;
4710 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4711 smctr_make_group_addr(dev, tsv);
4713 tmf->vl += tsv->svl;
4714 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4715 smctr_make_funct_addr(dev, tsv);
4717 tmf->vl += tsv->svl;
4719 /* Subtract out MVID and MVL which is
4720 * include in both vl and MAC_HEADER
4722 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4723 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4725 tmf->vl = SWAP_BYTES(tmf->vl);
4727 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4730 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4731 __u16 correlator)
4733 MAC_HEADER *tmf;
4734 MAC_SUB_VECTOR *tsv;
4735 FCBlock *fcb;
4737 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4738 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4739 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4740 == (FCBlock *)(-1L))
4742 return 0;
4745 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4746 tmf->vc = RPT_ATTCH;
4747 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4748 tmf->vl = 4;
4750 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4752 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4753 smctr_make_corr(dev, tsv, correlator);
4755 tmf->vl += tsv->svl;
4756 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4757 smctr_make_product_id(dev, tsv);
4759 tmf->vl += tsv->svl;
4760 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4761 smctr_make_funct_addr(dev, tsv);
4763 tmf->vl += tsv->svl;
4764 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4765 smctr_make_auth_funct_class(dev, tsv);
4767 tmf->vl += tsv->svl;
4768 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4769 smctr_make_access_pri(dev, tsv);
4771 tmf->vl += tsv->svl;
4773 /* Subtract out MVID and MVL which is
4774 * include in both vl and MAC_HEADER
4776 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4777 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4779 tmf->vl = SWAP_BYTES(tmf->vl);
4781 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4784 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4785 __u16 correlator)
4787 MAC_HEADER *tmf;
4788 MAC_SUB_VECTOR *tsv;
4789 FCBlock *fcb;
4791 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4792 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4793 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4794 == (FCBlock *)(-1L))
4796 return 0;
4799 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4800 tmf->vc = RPT_STATE;
4801 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4802 tmf->vl = 4;
4804 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4806 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4807 smctr_make_corr(dev, tsv, correlator);
4809 tmf->vl += tsv->svl;
4810 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4811 smctr_make_ring_station_version(dev, tsv);
4813 tmf->vl += tsv->svl;
4814 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4815 smctr_make_ring_station_status(dev, tsv);
4817 tmf->vl += tsv->svl;
4818 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4819 smctr_make_station_id(dev, tsv);
4821 tmf->vl += tsv->svl;
4823 /* Subtract out MVID and MVL which is
4824 * include in both vl and MAC_HEADER
4826 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4827 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4829 tmf->vl = SWAP_BYTES(tmf->vl);
4831 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4834 static int smctr_send_rpt_tx_forward(struct net_device *dev,
4835 MAC_HEADER *rmf, __u16 tx_fstatus)
4837 MAC_HEADER *tmf;
4838 MAC_SUB_VECTOR *tsv;
4839 FCBlock *fcb;
4841 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4842 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4844 return 0;
4847 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4848 tmf->vc = RPT_TX_FORWARD;
4849 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4850 tmf->vl = 4;
4852 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4854 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4855 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4857 tmf->vl += tsv->svl;
4859 /* Subtract out MVID and MVL which is
4860 * include in both vl and MAC_HEADER
4862 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4863 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4865 tmf->vl = SWAP_BYTES(tmf->vl);
4867 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
4870 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4871 __u16 rcode, __u16 correlator)
4873 MAC_HEADER *tmf;
4874 MAC_SUB_VECTOR *tsv;
4875 FCBlock *fcb;
4877 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4878 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4880 return 0;
4883 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4884 tmf->vc = RSP;
4885 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4886 tmf->vl = 4;
4888 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4890 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4891 smctr_make_corr(dev, tsv, correlator);
4893 return 0;
4896 static int smctr_send_rq_init(struct net_device *dev)
4898 struct net_local *tp = netdev_priv(dev);
4899 MAC_HEADER *tmf;
4900 MAC_SUB_VECTOR *tsv;
4901 FCBlock *fcb;
4902 unsigned int i, count = 0;
4903 __u16 fstatus;
4904 int err;
4906 do {
4907 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4908 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4909 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4910 == (FCBlock *)(-1L)))
4912 return 0;
4915 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4916 tmf->vc = RQ_INIT;
4917 tmf->dc_sc = DC_RPS | SC_RS;
4918 tmf->vl = 4;
4920 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4922 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4923 smctr_make_product_id(dev, tsv);
4925 tmf->vl += tsv->svl;
4926 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4927 smctr_make_upstream_neighbor_addr(dev, tsv);
4929 tmf->vl += tsv->svl;
4930 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4931 smctr_make_ring_station_version(dev, tsv);
4933 tmf->vl += tsv->svl;
4934 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4935 smctr_make_addr_mod(dev, tsv);
4937 tmf->vl += tsv->svl;
4939 /* Subtract out MVID and MVL which is
4940 * include in both vl and MAC_HEADER
4942 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4943 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4945 tmf->vl = SWAP_BYTES(tmf->vl);
4947 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4948 return err;
4950 /* Wait for Transmit to Complete */
4951 for(i = 0; i < 10000; i++)
4953 if(fcb->frame_status & FCB_COMMAND_DONE)
4954 break;
4955 mdelay(1);
4958 /* Check if GOOD frame Tx'ed */
4959 fstatus = fcb->frame_status;
4961 if(!(fstatus & FCB_COMMAND_DONE))
4962 return HARDWARE_FAILED;
4964 if(!(fstatus & FCB_TX_STATUS_E))
4965 count++;
4967 /* De-allocated Tx FCB and Frame Buffer
4968 * The FCB must be de-allocated manually if executing with
4969 * interrupts disabled, other wise the ISR (LM_Service_Events)
4970 * will de-allocate it when the interrupt occurs.
4972 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4973 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4974 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4976 return smctr_join_complete_state(dev);
4979 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4980 __u16 *tx_fstatus)
4982 struct net_local *tp = netdev_priv(dev);
4983 FCBlock *fcb;
4984 unsigned int i;
4985 int err;
4987 /* Check if this is the END POINT of the Transmit Forward Chain. */
4988 if(rmf->vl <= 18)
4989 return 0;
4991 /* Allocate Transmit FCB only by requesting 0 bytes
4992 * of data buffer.
4994 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
4995 return 0;
4997 /* Set pointer to Transmit Frame Buffer to the data
4998 * portion of the received TX Forward frame, making
4999 * sure to skip over the Vector Code (vc) and Vector
5000 * length (vl).
5002 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5003 + sizeof(MAC_HEADER) + 2);
5004 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5005 + sizeof(MAC_HEADER) + 2);
5007 fcb->frame_length = rmf->vl - 4 - 2;
5008 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5010 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5011 return err;
5013 /* Wait for Transmit to Complete */
5014 for(i = 0; i < 10000; i++)
5016 if(fcb->frame_status & FCB_COMMAND_DONE)
5017 break;
5018 mdelay(1);
5021 /* Check if GOOD frame Tx'ed */
5022 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5024 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5025 return err;
5027 for(i = 0; i < 10000; i++)
5029 if(fcb->frame_status & FCB_COMMAND_DONE)
5030 break;
5031 mdelay(1);
5034 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5035 return HARDWARE_FAILED;
5038 *tx_fstatus = fcb->frame_status;
5040 return A_FRAME_WAS_FORWARDED;
5043 static int smctr_set_auth_access_pri(struct net_device *dev,
5044 MAC_SUB_VECTOR *rsv)
5046 struct net_local *tp = netdev_priv(dev);
5048 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5049 return E_SUB_VECTOR_LENGTH_ERROR;
5051 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5053 return POSITIVE_ACK;
5056 static int smctr_set_auth_funct_class(struct net_device *dev,
5057 MAC_SUB_VECTOR *rsv)
5059 struct net_local *tp = netdev_priv(dev);
5061 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5062 return E_SUB_VECTOR_LENGTH_ERROR;
5064 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5066 return POSITIVE_ACK;
5069 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5070 __u16 *correlator)
5072 if(rsv->svl != S_CORRELATOR)
5073 return E_SUB_VECTOR_LENGTH_ERROR;
5075 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5077 return POSITIVE_ACK;
5080 static int smctr_set_error_timer_value(struct net_device *dev,
5081 MAC_SUB_VECTOR *rsv)
5083 __u16 err_tval;
5084 int err;
5086 if(rsv->svl != S_ERROR_TIMER_VALUE)
5087 return E_SUB_VECTOR_LENGTH_ERROR;
5089 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5091 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5093 if((err = smctr_wait_cmd(dev)))
5094 return err;
5096 return POSITIVE_ACK;
5099 static int smctr_set_frame_forward(struct net_device *dev,
5100 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5102 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5103 return E_SUB_VECTOR_LENGTH_ERROR;
5105 if((dc_sc & DC_MASK) != DC_CRS)
5107 if(rsv->svl >= 2 && rsv->svl < 20)
5108 return E_TRANSMIT_FORWARD_INVALID;
5110 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5111 return E_TRANSMIT_FORWARD_INVALID;
5114 return POSITIVE_ACK;
5117 static int smctr_set_local_ring_num(struct net_device *dev,
5118 MAC_SUB_VECTOR *rsv)
5120 struct net_local *tp = netdev_priv(dev);
5122 if(rsv->svl != S_LOCAL_RING_NUMBER)
5123 return E_SUB_VECTOR_LENGTH_ERROR;
5125 if(tp->ptr_local_ring_num)
5126 *(__u16 *)(tp->ptr_local_ring_num)
5127 = (rsv->svv[0] << 8 | rsv->svv[1]);
5129 return POSITIVE_ACK;
5132 static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5134 struct net_local *tp = netdev_priv(dev);
5135 int ioaddr = dev->base_addr;
5137 if(tp->bic_type == BIC_585_CHIP)
5138 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5139 else
5141 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5142 outb(tp->trc_mask, ioaddr + CSR);
5145 return 0;
5148 static void smctr_set_multicast_list(struct net_device *dev)
5150 if(smctr_debug > 10)
5151 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5154 static int smctr_set_page(struct net_device *dev, __u8 *buf)
5156 struct net_local *tp = netdev_priv(dev);
5157 __u8 amask;
5158 __u32 tptr;
5160 tptr = (__u32)buf - (__u32)tp->ram_access;
5161 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5162 outb(amask, dev->base_addr + PR);
5164 return 0;
5167 static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5169 int err;
5171 if(rsv->svl != S_PHYSICAL_DROP)
5172 return E_SUB_VECTOR_LENGTH_ERROR;
5174 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5175 if((err = smctr_wait_cmd(dev)))
5176 return err;
5178 return POSITIVE_ACK;
5181 /* Reset the ring speed to the opposite of what it was. This auto-pilot
5182 * mode requires a complete reset and re-init of the adapter.
5184 static int smctr_set_ring_speed(struct net_device *dev)
5186 struct net_local *tp = netdev_priv(dev);
5187 int err;
5189 if(tp->media_type == MEDIA_UTP_16)
5190 tp->media_type = MEDIA_UTP_4;
5191 else
5192 tp->media_type = MEDIA_UTP_16;
5194 smctr_enable_16bit(dev);
5196 /* Re-Initialize adapter's internal registers */
5197 smctr_reset_adapter(dev);
5199 if((err = smctr_init_card_real(dev)))
5200 return err;
5202 smctr_enable_bic_int(dev);
5204 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5205 return err;
5207 smctr_disable_16bit(dev);
5209 return 0;
5212 static int smctr_set_rx_look_ahead(struct net_device *dev)
5214 struct net_local *tp = netdev_priv(dev);
5215 __u16 sword, rword;
5217 if(smctr_debug > 10)
5218 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5220 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5221 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5223 if(tp->adapter_bus == BUS_ISA16_TYPE)
5225 sword = *((__u16 *)(tp->ram_access));
5226 *((__u16 *)(tp->ram_access)) = 0x1234;
5228 smctr_disable_16bit(dev);
5229 rword = *((__u16 *)(tp->ram_access));
5230 smctr_enable_16bit(dev);
5232 if(rword != 0x1234)
5233 tp->adapter_flags |= FORCED_16BIT_MODE;
5235 *((__u16 *)(tp->ram_access)) = sword;
5238 return 0;
5241 static int smctr_set_trc_reset(int ioaddr)
5243 __u8 r;
5245 r = inb(ioaddr + MSR);
5246 outb(MSR_RST | r, ioaddr + MSR);
5248 return 0;
5252 * This function can be called if the adapter is busy or not.
5254 static int smctr_setup_single_cmd(struct net_device *dev,
5255 __u16 command, __u16 subcommand)
5257 struct net_local *tp = netdev_priv(dev);
5258 unsigned int err;
5260 if(smctr_debug > 10)
5261 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5263 if((err = smctr_wait_while_cbusy(dev)))
5264 return err;
5266 if((err = (unsigned int)smctr_wait_cmd(dev)))
5267 return err;
5269 tp->acb_head->cmd_done_status = 0;
5270 tp->acb_head->cmd = command;
5271 tp->acb_head->subcmd = subcommand;
5273 err = smctr_issue_resume_acb_cmd(dev);
5275 return err;
5279 * This function can not be called with the adapter busy.
5281 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5282 __u16 command, __u16 subcommand)
5284 struct net_local *tp = netdev_priv(dev);
5286 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5287 tp->acb_head->cmd = command;
5288 tp->acb_head->subcmd = subcommand;
5289 tp->acb_head->data_offset_lo
5290 = (__u16)TRC_POINTER(tp->misc_command_data);
5292 return smctr_issue_resume_acb_cmd(dev);
5295 static char *smctr_malloc(struct net_device *dev, __u16 size)
5297 struct net_local *tp = netdev_priv(dev);
5298 char *m;
5300 m = (char *)(tp->ram_access + tp->sh_mem_used);
5301 tp->sh_mem_used += (__u32)size;
5303 return m;
5306 static int smctr_status_chg(struct net_device *dev)
5308 struct net_local *tp = netdev_priv(dev);
5310 if(smctr_debug > 10)
5311 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5313 switch(tp->status)
5315 case OPEN:
5316 break;
5318 case CLOSED:
5319 break;
5321 /* Interrupt driven open() completion. XXX */
5322 case INITIALIZED:
5323 tp->group_address_0 = 0;
5324 tp->group_address[0] = 0;
5325 tp->group_address[1] = 0;
5326 tp->functional_address_0 = 0;
5327 tp->functional_address[0] = 0;
5328 tp->functional_address[1] = 0;
5329 smctr_open_tr(dev);
5330 break;
5332 default:
5333 printk(KERN_INFO "%s: status change unknown %x\n",
5334 dev->name, tp->status);
5335 break;
5338 return 0;
5341 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5342 __u16 queue)
5344 struct net_local *tp = netdev_priv(dev);
5345 int err = 0;
5347 if(smctr_debug > 10)
5348 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5350 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5351 if(tp->num_tx_fcbs[queue] != 1)
5352 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5354 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5356 tp->tx_queue_status[queue] = TRANSMITING;
5357 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5360 return err;
5363 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5365 struct net_local *tp = netdev_priv(dev);
5366 __u16 status, err = 0;
5367 int cstatus;
5369 if(smctr_debug > 10)
5370 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5372 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5374 if(status & 0x7e00 )
5376 err = HARDWARE_FAILED;
5377 break;
5380 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5381 queue)) != SUCCESS)
5382 break;
5384 smctr_disable_16bit(dev);
5386 if(tp->mode_bits & UMAC)
5388 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5389 cstatus = NO_SUCH_DESTINATION;
5390 else
5392 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5393 cstatus = DEST_OUT_OF_RESOURCES;
5394 else
5396 if(status & FCB_TX_STATUS_E)
5397 cstatus = MAX_COLLISIONS;
5398 else
5399 cstatus = SUCCESS;
5403 else
5404 cstatus = SUCCESS;
5406 if(queue == BUG_QUEUE)
5407 err = SUCCESS;
5409 smctr_enable_16bit(dev);
5410 if(err != SUCCESS)
5411 break;
5414 return err;
5417 static unsigned short smctr_tx_move_frame(struct net_device *dev,
5418 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5420 struct net_local *tp = netdev_priv(dev);
5421 unsigned int ram_usable;
5422 __u32 flen, len, offset = 0;
5423 __u8 *frag, *page;
5425 if(smctr_debug > 10)
5426 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5428 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5429 frag = skb->data;
5430 flen = skb->len;
5432 while(flen > 0 && bytes > 0)
5434 smctr_set_page(dev, pbuff);
5436 offset = SMC_PAGE_OFFSET(pbuff);
5438 if(offset + flen > ram_usable)
5439 len = ram_usable - offset;
5440 else
5441 len = flen;
5443 if(len > bytes)
5444 len = bytes;
5446 page = (char *) (offset + tp->ram_access);
5447 memcpy(page, frag, len);
5449 flen -=len;
5450 bytes -= len;
5451 frag += len;
5452 pbuff += len;
5455 return 0;
5458 /* Update the error statistic counters for this adapter. */
5459 static int smctr_update_err_stats(struct net_device *dev)
5461 struct net_local *tp = netdev_priv(dev);
5462 struct tr_statistics *tstat = &tp->MacStat;
5464 if(tstat->internal_errors)
5465 tstat->internal_errors
5466 += *(tp->misc_command_data + 0) & 0x00ff;
5468 if(tstat->line_errors)
5469 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5471 if(tstat->A_C_errors)
5472 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5474 if(tstat->burst_errors)
5475 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5477 if(tstat->abort_delimiters)
5478 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5480 if(tstat->recv_congest_count)
5481 tstat->recv_congest_count
5482 += *(tp->misc_command_data + 3) & 0x00ff;
5484 if(tstat->lost_frames)
5485 tstat->lost_frames
5486 += *(tp->misc_command_data + 3) >> 8;
5488 if(tstat->frequency_errors)
5489 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5491 if(tstat->frame_copied_errors)
5492 tstat->frame_copied_errors
5493 += *(tp->misc_command_data + 4) >> 8;
5495 if(tstat->token_errors)
5496 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5498 return 0;
5501 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5503 struct net_local *tp = netdev_priv(dev);
5504 FCBlock *fcb;
5505 BDBlock *bdb;
5506 __u16 size, len;
5508 fcb = tp->rx_fcb_curr[queue];
5509 len = fcb->frame_length;
5511 fcb->frame_status = 0;
5512 fcb->info = FCB_CHAIN_END;
5513 fcb->back_ptr->info = FCB_WARNING;
5515 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5517 /* update RX BDBs */
5518 size = (len >> RX_BDB_SIZE_SHIFT);
5519 if(len & RX_DATA_BUFFER_SIZE_MASK)
5520 size += sizeof(BDBlock);
5521 size &= (~RX_BDB_SIZE_MASK);
5523 /* check if wrap around */
5524 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5525 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5527 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5528 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5531 bdb->back_ptr->info = BDB_CHAIN_END;
5532 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5533 tp->rx_bdb_curr[queue] = bdb;
5535 return 0;
5538 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5539 __u16 queue)
5541 struct net_local *tp = netdev_priv(dev);
5543 if(smctr_debug > 20)
5544 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5546 if(tp->num_tx_fcbs_used[queue] <= 0)
5547 return HARDWARE_FAILED;
5548 else
5550 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5552 tp->tx_buff_used[queue] = 0;
5553 return HARDWARE_FAILED;
5556 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5558 /* if all transmit buffer are cleared
5559 * need to set the tx_buff_curr[] to tx_buff_head[]
5560 * otherwise, tx buffer will be segregate and cannot
5561 * accommodate and buffer greater than (curr - head) and
5562 * (end - curr) since we do not allow wrap around allocation.
5564 if(tp->tx_buff_used[queue] == 0)
5565 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5567 tp->num_tx_fcbs_used[queue]--;
5568 fcb->frame_status = 0;
5569 tp->tx_fcb_end[queue] = fcb->next_ptr;
5570 netif_wake_queue(dev);
5571 return 0;
5575 static int smctr_wait_cmd(struct net_device *dev)
5577 struct net_local *tp = netdev_priv(dev);
5578 unsigned int loop_count = 0x20000;
5580 if(smctr_debug > 10)
5581 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5583 while(loop_count)
5585 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5586 break;
5587 udelay(1);
5588 loop_count--;
5591 if(loop_count == 0)
5592 return HARDWARE_FAILED;
5594 if(tp->acb_head->cmd_done_status & 0xff)
5595 return HARDWARE_FAILED;
5597 return 0;
5600 static int smctr_wait_while_cbusy(struct net_device *dev)
5602 struct net_local *tp = netdev_priv(dev);
5603 unsigned int timeout = 0x20000;
5604 int ioaddr = dev->base_addr;
5605 __u8 r;
5607 if(tp->bic_type == BIC_585_CHIP)
5609 while(timeout)
5611 r = inb(ioaddr + HWR);
5612 if((r & HWR_CBUSY) == 0)
5613 break;
5614 timeout--;
5617 else
5619 while(timeout)
5621 r = inb(ioaddr + CSR);
5622 if((r & CSR_CBUSY) == 0)
5623 break;
5624 timeout--;
5628 if(timeout)
5629 return 0;
5630 else
5631 return HARDWARE_FAILED;
5634 #ifdef MODULE
5636 static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5637 static int io[SMCTR_MAX_ADAPTERS];
5638 static int irq[SMCTR_MAX_ADAPTERS];
5640 MODULE_LICENSE("GPL");
5641 MODULE_FIRMWARE("tr_smctr.bin");
5643 module_param_array(io, int, NULL, 0);
5644 module_param_array(irq, int, NULL, 0);
5645 module_param(ringspeed, int, 0);
5647 static struct net_device * __init setup_card(int n)
5649 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5650 int err;
5652 if (!dev)
5653 return ERR_PTR(-ENOMEM);
5655 dev->irq = irq[n];
5656 err = smctr_probe1(dev, io[n]);
5657 if (err)
5658 goto out;
5660 err = register_netdev(dev);
5661 if (err)
5662 goto out1;
5663 return dev;
5664 out1:
5665 #ifdef CONFIG_MCA_LEGACY
5666 { struct net_local *tp = netdev_priv(dev);
5667 if (tp->slot_num)
5668 mca_mark_as_unused(tp->slot_num);
5670 #endif
5671 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5672 free_irq(dev->irq, dev);
5673 out:
5674 free_netdev(dev);
5675 return ERR_PTR(err);
5678 int __init init_module(void)
5680 int i, found = 0;
5681 struct net_device *dev;
5683 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5684 dev = io[0]? setup_card(i) : smctr_probe(-1);
5685 if (!IS_ERR(dev)) {
5686 ++found;
5687 dev_smctr[i] = dev;
5691 return found ? 0 : -ENODEV;
5694 void __exit cleanup_module(void)
5696 int i;
5698 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5699 struct net_device *dev = dev_smctr[i];
5701 if (dev) {
5703 unregister_netdev(dev);
5704 #ifdef CONFIG_MCA_LEGACY
5705 { struct net_local *tp = netdev_priv(dev);
5706 if (tp->slot_num)
5707 mca_mark_as_unused(tp->slot_num);
5709 #endif
5710 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5711 if (dev->irq)
5712 free_irq(dev->irq, dev);
5714 free_netdev(dev);
5718 #endif /* MODULE */