SLUB: Fix memory leak by not reusing cpu_slab
[pv_ops_mirror.git] / drivers / net / tokenring / smctr.c
blob93da3a36cde8915922579b2ba26f91a571361388
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@redhat.com> 2002/10/28
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
36 #include <linux/ptrace.h>
37 #include <linux/ioport.h>
38 #include <linux/in.h>
39 #include <linux/slab.h>
40 #include <linux/string.h>
41 #include <linux/time.h>
42 #include <linux/errno.h>
43 #include <linux/init.h>
44 #include <linux/mca-legacy.h>
45 #include <linux/delay.h>
46 #include <linux/netdevice.h>
47 #include <linux/etherdevice.h>
48 #include <linux/skbuff.h>
49 #include <linux/trdevice.h>
50 #include <linux/bitops.h>
52 #include <asm/system.h>
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 */
62 #include "smctr_firmware.h" /* SMC adapter firmware */
64 static char version[] __initdata = KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
65 static const char cardname[] = "smctr";
68 #define SMCTR_IO_EXTENT 20
70 #ifdef CONFIG_MCA_LEGACY
71 static unsigned int smctr_posid = 0x6ec6;
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 static int smctr_disable_16bit(struct net_device *dev);
108 static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
109 static int smctr_disable_bic_int(struct net_device *dev);
111 /* E */
112 static int smctr_enable_16bit(struct net_device *dev);
113 static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
114 static int smctr_enable_adapter_ram(struct net_device *dev);
115 static int smctr_enable_bic_int(struct net_device *dev);
117 /* G */
118 static int __init smctr_get_boardid(struct net_device *dev, int mca);
119 static int smctr_get_group_address(struct net_device *dev);
120 static int smctr_get_functional_address(struct net_device *dev);
121 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
122 static int smctr_get_physical_drop_number(struct net_device *dev);
123 static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
124 static int smctr_get_station_id(struct net_device *dev);
125 static struct net_device_stats *smctr_get_stats(struct net_device *dev);
126 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
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 int smctr_send_packet(struct sk_buff *skb, struct net_device *dev);
237 static int smctr_send_lobe_media_test(struct net_device *dev);
238 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
239 __u16 correlator);
240 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
241 __u16 correlator);
242 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
243 __u16 correlator);
244 static int smctr_send_rpt_tx_forward(struct net_device *dev,
245 MAC_HEADER *rmf, __u16 tx_fstatus);
246 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
247 __u16 rcode, __u16 correlator);
248 static int smctr_send_rq_init(struct net_device *dev);
249 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
250 __u16 *tx_fstatus);
251 static int smctr_set_auth_access_pri(struct net_device *dev,
252 MAC_SUB_VECTOR *rsv);
253 static int smctr_set_auth_funct_class(struct net_device *dev,
254 MAC_SUB_VECTOR *rsv);
255 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
256 __u16 *correlator);
257 static int smctr_set_error_timer_value(struct net_device *dev,
258 MAC_SUB_VECTOR *rsv);
259 static int smctr_set_frame_forward(struct net_device *dev,
260 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
261 static int smctr_set_local_ring_num(struct net_device *dev,
262 MAC_SUB_VECTOR *rsv);
263 static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
264 static void smctr_set_multicast_list(struct net_device *dev);
265 static int smctr_set_page(struct net_device *dev, __u8 *buf);
266 static int smctr_set_phy_drop(struct net_device *dev,
267 MAC_SUB_VECTOR *rsv);
268 static int smctr_set_ring_speed(struct net_device *dev);
269 static int smctr_set_rx_look_ahead(struct net_device *dev);
270 static int smctr_set_trc_reset(int ioaddr);
271 static int smctr_setup_single_cmd(struct net_device *dev,
272 __u16 command, __u16 subcommand);
273 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
274 __u16 command, __u16 subcommand);
275 static char *smctr_malloc(struct net_device *dev, __u16 size);
276 static int smctr_status_chg(struct net_device *dev);
278 /* T */
279 static void smctr_timeout(struct net_device *dev);
280 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
281 __u16 queue);
282 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
283 static unsigned short smctr_tx_move_frame(struct net_device *dev,
284 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
286 /* U */
287 static int smctr_update_err_stats(struct net_device *dev);
288 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
289 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
290 __u16 queue);
292 /* W */
293 static int smctr_wait_cmd(struct net_device *dev);
294 static int smctr_wait_while_cbusy(struct net_device *dev);
296 #define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
297 #define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
298 #define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
300 /* Allocate Adapter Shared Memory.
301 * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
302 * function "get_num_rx_bdbs" below!!!
304 * Order of memory allocation:
306 * 0. Initial System Configuration Block Pointer
307 * 1. System Configuration Block
308 * 2. System Control Block
309 * 3. Action Command Block
310 * 4. Interrupt Status Block
312 * 5. MAC TX FCB'S
313 * 6. NON-MAC TX FCB'S
314 * 7. MAC TX BDB'S
315 * 8. NON-MAC TX BDB'S
316 * 9. MAC RX FCB'S
317 * 10. NON-MAC RX FCB'S
318 * 11. MAC RX BDB'S
319 * 12. NON-MAC RX BDB'S
320 * 13. MAC TX Data Buffer( 1, 256 byte buffer)
321 * 14. MAC RX Data Buffer( 1, 256 byte buffer)
323 * 15. NON-MAC TX Data Buffer
324 * 16. NON-MAC RX Data Buffer
326 static int smctr_alloc_shared_memory(struct net_device *dev)
328 struct net_local *tp = netdev_priv(dev);
330 if(smctr_debug > 10)
331 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
333 /* Allocate initial System Control Block pointer.
334 * This pointer is located in the last page, last offset - 4.
336 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
337 - (long)ISCP_BLOCK_SIZE);
339 /* Allocate System Control Blocks. */
340 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
341 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
343 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
344 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
346 tp->acb_head = (ACBlock *)smctr_malloc(dev,
347 sizeof(ACBlock)*tp->num_acbs);
348 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
350 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
351 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
353 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
354 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
356 /* Allocate transmit FCBs. */
357 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
358 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
360 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
361 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
363 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
364 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
366 /* Allocate transmit BDBs. */
367 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
368 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
370 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
371 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
373 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
374 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
376 /* Allocate receive FCBs. */
377 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
378 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
380 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
381 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
383 /* Allocate receive BDBs. */
384 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
385 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
387 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
389 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
390 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
392 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
394 /* Allocate MAC transmit buffers.
395 * MAC Tx Buffers doen't have to be on an ODD Boundry.
397 tp->tx_buff_head[MAC_QUEUE]
398 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
399 tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
400 tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
402 /* Allocate BUG transmit buffers. */
403 tp->tx_buff_head[BUG_QUEUE]
404 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
405 tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
406 tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
408 /* Allocate MAC receive data buffers.
409 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
411 tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
412 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
413 tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
415 /* Allocate Non-MAC transmit buffers.
416 * ?? For maximum Netware performance, put Tx Buffers on
417 * ODD Boundry and then restore malloc to Even Boundrys.
419 smctr_malloc(dev, 1L);
420 tp->tx_buff_head[NON_MAC_QUEUE]
421 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
422 tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
423 tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
424 smctr_malloc(dev, 1L);
426 /* Allocate Non-MAC receive data buffers.
427 * To guarantee a minimum of 256 contigous memory to
428 * UM_Receive_Packet's lookahead pointer, before a page
429 * change or ring end is encountered, place each rx buffer on
430 * a 256 byte boundary.
432 smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
433 tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
434 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
435 tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
437 return (0);
440 /* Enter Bypass state. */
441 static int smctr_bypass_state(struct net_device *dev)
443 int err;
445 if(smctr_debug > 10)
446 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
448 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
450 return (err);
453 static int smctr_checksum_firmware(struct net_device *dev)
455 struct net_local *tp = netdev_priv(dev);
456 __u16 i, checksum = 0;
458 if(smctr_debug > 10)
459 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
461 smctr_enable_adapter_ctrl_store(dev);
463 for(i = 0; i < CS_RAM_SIZE; i += 2)
464 checksum += *((__u16 *)(tp->ram_access + i));
466 tp->microcode_version = *(__u16 *)(tp->ram_access
467 + CS_RAM_VERSION_OFFSET);
468 tp->microcode_version >>= 8;
470 smctr_disable_adapter_ctrl_store(dev);
472 if(checksum)
473 return (checksum);
475 return (0);
478 static int __init smctr_chk_mca(struct net_device *dev)
480 #ifdef CONFIG_MCA_LEGACY
481 struct net_local *tp = netdev_priv(dev);
482 int current_slot;
483 __u8 r1, r2, r3, r4, r5;
485 current_slot = mca_find_unused_adapter(smctr_posid, 0);
486 if(current_slot == MCA_NOTFOUND)
487 return (-ENODEV);
489 mca_set_adapter_name(current_slot, smctr_name);
490 mca_mark_as_used(current_slot);
491 tp->slot_num = current_slot;
493 r1 = mca_read_stored_pos(tp->slot_num, 2);
494 r2 = mca_read_stored_pos(tp->slot_num, 3);
496 if(tp->slot_num)
497 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
498 else
499 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
501 r1 = inb(CNFG_POS_REG1);
502 r2 = inb(CNFG_POS_REG0);
504 tp->bic_type = BIC_594_CHIP;
506 /* IO */
507 r2 = mca_read_stored_pos(tp->slot_num, 2);
508 r2 &= 0xF0;
509 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
510 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
512 /* IRQ */
513 r5 = mca_read_stored_pos(tp->slot_num, 5);
514 r5 &= 0xC;
515 switch(r5)
517 case 0:
518 dev->irq = 3;
519 break;
521 case 0x4:
522 dev->irq = 4;
523 break;
525 case 0x8:
526 dev->irq = 10;
527 break;
529 default:
530 dev->irq = 15;
531 break;
533 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
534 release_region(dev->base_addr, SMCTR_IO_EXTENT);
535 return -ENODEV;
538 /* Get RAM base */
539 r3 = mca_read_stored_pos(tp->slot_num, 3);
540 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
541 if (r3 & 0x8)
542 tp->ram_base += 0x010000;
543 if (r3 & 0x80)
544 tp->ram_base += 0xF00000;
546 /* Get Ram Size */
547 r3 &= 0x30;
548 r3 >>= 4;
550 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
551 tp->ram_size = (__u16)CNFG_SIZE_64KB;
552 tp->board_id |= TOKEN_MEDIA;
554 r4 = mca_read_stored_pos(tp->slot_num, 4);
555 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
556 if (r4 & 0x8)
557 tp->rom_base += 0x010000;
559 /* Get ROM size. */
560 r4 >>= 4;
561 switch (r4) {
562 case 0:
563 tp->rom_size = CNFG_SIZE_8KB;
564 break;
565 case 1:
566 tp->rom_size = CNFG_SIZE_16KB;
567 break;
568 case 2:
569 tp->rom_size = CNFG_SIZE_32KB;
570 break;
571 default:
572 tp->rom_size = ROM_DISABLE;
575 /* Get Media Type. */
576 r5 = mca_read_stored_pos(tp->slot_num, 5);
577 r5 &= CNFG_MEDIA_TYPE_MASK;
578 switch(r5)
580 case (0):
581 tp->media_type = MEDIA_STP_4;
582 break;
584 case (1):
585 tp->media_type = MEDIA_STP_16;
586 break;
588 case (3):
589 tp->media_type = MEDIA_UTP_16;
590 break;
592 default:
593 tp->media_type = MEDIA_UTP_4;
594 break;
596 tp->media_menu = 14;
598 r2 = mca_read_stored_pos(tp->slot_num, 2);
599 if(!(r2 & 0x02))
600 tp->mode_bits |= EARLY_TOKEN_REL;
602 /* Disable slot */
603 outb(CNFG_POS_CONTROL_REG, 0);
605 tp->board_id = smctr_get_boardid(dev, 1);
606 switch(tp->board_id & 0xffff)
608 case WD8115TA:
609 smctr_model = "8115T/A";
610 break;
612 case WD8115T:
613 if(tp->extra_info & CHIP_REV_MASK)
614 smctr_model = "8115T rev XE";
615 else
616 smctr_model = "8115T rev XD";
617 break;
619 default:
620 smctr_model = "Unknown";
621 break;
624 return (0);
625 #else
626 return (-1);
627 #endif /* CONFIG_MCA_LEGACY */
630 static int smctr_chg_rx_mask(struct net_device *dev)
632 struct net_local *tp = netdev_priv(dev);
633 int err = 0;
635 if(smctr_debug > 10)
636 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
638 smctr_enable_16bit(dev);
639 smctr_set_page(dev, (__u8 *)tp->ram_access);
641 if(tp->mode_bits & LOOPING_MODE_MASK)
642 tp->config_word0 |= RX_OWN_BIT;
643 else
644 tp->config_word0 &= ~RX_OWN_BIT;
646 if(tp->receive_mask & PROMISCUOUS_MODE)
647 tp->config_word0 |= PROMISCUOUS_BIT;
648 else
649 tp->config_word0 &= ~PROMISCUOUS_BIT;
651 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
652 tp->config_word0 |= SAVBAD_BIT;
653 else
654 tp->config_word0 &= ~SAVBAD_BIT;
656 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
657 tp->config_word0 |= RXATMAC;
658 else
659 tp->config_word0 &= ~RXATMAC;
661 if(tp->receive_mask & ACCEPT_MULTI_PROM)
662 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
663 else
664 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
666 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
667 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
668 else
670 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
671 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
672 else
673 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
676 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
677 &tp->config_word0)))
679 return (err);
682 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
683 &tp->config_word1)))
685 return (err);
688 smctr_disable_16bit(dev);
690 return (0);
693 static int smctr_clear_int(struct net_device *dev)
695 struct net_local *tp = netdev_priv(dev);
697 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
699 return (0);
702 static int smctr_clear_trc_reset(int ioaddr)
704 __u8 r;
706 r = inb(ioaddr + MSR);
707 outb(~MSR_RST & r, ioaddr + MSR);
709 return (0);
713 * The inverse routine to smctr_open().
715 static int smctr_close(struct net_device *dev)
717 struct net_local *tp = netdev_priv(dev);
718 struct sk_buff *skb;
719 int err;
721 netif_stop_queue(dev);
723 tp->cleanup = 1;
725 /* Check to see if adapter is already in a closed state. */
726 if(tp->status != OPEN)
727 return (0);
729 smctr_enable_16bit(dev);
730 smctr_set_page(dev, (__u8 *)tp->ram_access);
732 if((err = smctr_issue_remove_cmd(dev)))
734 smctr_disable_16bit(dev);
735 return (err);
738 for(;;)
740 skb = skb_dequeue(&tp->SendSkbQueue);
741 if(skb == NULL)
742 break;
743 tp->QueueSkb++;
744 dev_kfree_skb(skb);
748 return (0);
751 static int smctr_decode_firmware(struct net_device *dev)
753 struct net_local *tp = netdev_priv(dev);
754 short bit = 0x80, shift = 12;
755 DECODE_TREE_NODE *tree;
756 short branch, tsize;
757 __u16 buff = 0;
758 long weight;
759 __u8 *ucode;
760 __u16 *mem;
762 if(smctr_debug > 10)
763 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
765 weight = *(long *)(tp->ptr_ucode + WEIGHT_OFFSET);
766 tsize = *(__u8 *)(tp->ptr_ucode + TREE_SIZE_OFFSET);
767 tree = (DECODE_TREE_NODE *)(tp->ptr_ucode + TREE_OFFSET);
768 ucode = (__u8 *)(tp->ptr_ucode + TREE_OFFSET
769 + (tsize * sizeof(DECODE_TREE_NODE)));
770 mem = (__u16 *)(tp->ram_access);
772 while(weight)
774 branch = ROOT;
775 while((tree + branch)->tag != LEAF && weight)
777 branch = *ucode & bit ? (tree + branch)->llink
778 : (tree + branch)->rlink;
780 bit >>= 1;
781 weight--;
783 if(bit == 0)
785 bit = 0x80;
786 ucode++;
790 buff |= (tree + branch)->info << shift;
791 shift -= 4;
793 if(shift < 0)
795 *(mem++) = SWAP_BYTES(buff);
796 buff = 0;
797 shift = 12;
801 /* The following assumes the Control Store Memory has
802 * been initialized to zero. If the last partial word
803 * is zero, it will not be written.
805 if(buff)
806 *(mem++) = SWAP_BYTES(buff);
808 return (0);
811 static int smctr_disable_16bit(struct net_device *dev)
813 return (0);
817 * On Exit, Adapter is:
818 * 1. TRC is in a reset state and un-initialized.
819 * 2. Adapter memory is enabled.
820 * 3. Control Store memory is out of context (-WCSS is 1).
822 static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
824 struct net_local *tp = netdev_priv(dev);
825 int ioaddr = dev->base_addr;
827 if(smctr_debug > 10)
828 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
830 tp->trc_mask |= CSR_WCSS;
831 outb(tp->trc_mask, ioaddr + CSR);
833 return (0);
836 static int smctr_disable_bic_int(struct net_device *dev)
838 struct net_local *tp = netdev_priv(dev);
839 int ioaddr = dev->base_addr;
841 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
842 | CSR_MSKTINT | CSR_WCSS;
843 outb(tp->trc_mask, ioaddr + CSR);
845 return (0);
848 static int smctr_enable_16bit(struct net_device *dev)
850 struct net_local *tp = netdev_priv(dev);
851 __u8 r;
853 if(tp->adapter_bus == BUS_ISA16_TYPE)
855 r = inb(dev->base_addr + LAAR);
856 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
859 return (0);
863 * To enable the adapter control store memory:
864 * 1. Adapter must be in a RESET state.
865 * 2. Adapter memory must be enabled.
866 * 3. Control Store Memory is in context (-WCSS is 0).
868 static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
870 struct net_local *tp = netdev_priv(dev);
871 int ioaddr = dev->base_addr;
873 if(smctr_debug > 10)
874 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
876 smctr_set_trc_reset(ioaddr);
877 smctr_enable_adapter_ram(dev);
879 tp->trc_mask &= ~CSR_WCSS;
880 outb(tp->trc_mask, ioaddr + CSR);
882 return (0);
885 static int smctr_enable_adapter_ram(struct net_device *dev)
887 int ioaddr = dev->base_addr;
888 __u8 r;
890 if(smctr_debug > 10)
891 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
893 r = inb(ioaddr + MSR);
894 outb(MSR_MEMB | r, ioaddr + MSR);
896 return (0);
899 static int smctr_enable_bic_int(struct net_device *dev)
901 struct net_local *tp = netdev_priv(dev);
902 int ioaddr = dev->base_addr;
903 __u8 r;
905 switch(tp->bic_type)
907 case (BIC_584_CHIP):
908 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
909 outb(tp->trc_mask, ioaddr + CSR);
910 r = inb(ioaddr + IRR);
911 outb(r | IRR_IEN, ioaddr + IRR);
912 break;
914 case (BIC_594_CHIP):
915 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
916 outb(tp->trc_mask, ioaddr + CSR);
917 r = inb(ioaddr + IMCCR);
918 outb(r | IMCCR_EIL, ioaddr + IMCCR);
919 break;
922 return (0);
925 static int __init smctr_chk_isa(struct net_device *dev)
927 struct net_local *tp = netdev_priv(dev);
928 int ioaddr = dev->base_addr;
929 __u8 r1, r2, b, chksum = 0;
930 __u16 r;
931 int i;
932 int err = -ENODEV;
934 if(smctr_debug > 10)
935 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
937 if((ioaddr & 0x1F) != 0)
938 goto out;
940 /* Grab the region so that no one else tries to probe our ioports. */
941 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
942 err = -EBUSY;
943 goto out;
946 /* Checksum SMC node address */
947 for(i = 0; i < 8; i++)
949 b = inb(ioaddr + LAR0 + i);
950 chksum += b;
953 if (chksum != NODE_ADDR_CKSUM)
954 goto out2;
956 b = inb(ioaddr + BDID);
957 if(b != BRD_ID_8115T)
959 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
960 goto out2;
963 /* Check for 8115T Board ID */
964 r2 = 0;
965 for(r = 0; r < 8; r++)
967 r1 = inb(ioaddr + 0x8 + r);
968 r2 += r1;
971 /* value of RegF adds up the sum to 0xFF */
972 if((r2 != 0xFF) && (r2 != 0xEE))
973 goto out2;
975 /* Get adapter ID */
976 tp->board_id = smctr_get_boardid(dev, 0);
977 switch(tp->board_id & 0xffff)
979 case WD8115TA:
980 smctr_model = "8115T/A";
981 break;
983 case WD8115T:
984 if(tp->extra_info & CHIP_REV_MASK)
985 smctr_model = "8115T rev XE";
986 else
987 smctr_model = "8115T rev XD";
988 break;
990 default:
991 smctr_model = "Unknown";
992 break;
995 /* Store BIC type. */
996 tp->bic_type = BIC_584_CHIP;
997 tp->nic_type = NIC_825_CHIP;
999 /* Copy Ram Size */
1000 tp->ram_usable = CNFG_SIZE_16KB;
1001 tp->ram_size = CNFG_SIZE_64KB;
1003 /* Get 58x Ram Base */
1004 r1 = inb(ioaddr);
1005 r1 &= 0x3F;
1007 r2 = inb(ioaddr + CNFG_LAAR_584);
1008 r2 &= CNFG_LAAR_MASK;
1009 r2 <<= 3;
1010 r2 |= ((r1 & 0x38) >> 3);
1012 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1014 /* Get 584 Irq */
1015 r1 = 0;
1016 r1 = inb(ioaddr + CNFG_ICR_583);
1017 r1 &= CNFG_ICR_IR2_584;
1019 r2 = inb(ioaddr + CNFG_IRR_583);
1020 r2 &= CNFG_IRR_IRQS; /* 0x60 */
1021 r2 >>= 5;
1023 switch(r2)
1025 case 0:
1026 if(r1 == 0)
1027 dev->irq = 2;
1028 else
1029 dev->irq = 10;
1030 break;
1032 case 1:
1033 if(r1 == 0)
1034 dev->irq = 3;
1035 else
1036 dev->irq = 11;
1037 break;
1039 case 2:
1040 if(r1 == 0)
1042 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1043 dev->irq = 5;
1044 else
1045 dev->irq = 4;
1047 else
1048 dev->irq = 15;
1049 break;
1051 case 3:
1052 if(r1 == 0)
1053 dev->irq = 7;
1054 else
1055 dev->irq = 4;
1056 break;
1058 default:
1059 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1060 goto out2;
1063 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
1064 goto out2;
1066 /* Get 58x Rom Base */
1067 r1 = inb(ioaddr + CNFG_BIO_583);
1068 r1 &= 0x3E;
1069 r1 |= 0x40;
1071 tp->rom_base = (__u32)r1 << 13;
1073 /* Get 58x Rom Size */
1074 r1 = inb(ioaddr + CNFG_BIO_583);
1075 r1 &= 0xC0;
1076 if(r1 == 0)
1077 tp->rom_size = ROM_DISABLE;
1078 else
1080 r1 >>= 6;
1081 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1084 /* Get 58x Boot Status */
1085 r1 = inb(ioaddr + CNFG_GP2);
1087 tp->mode_bits &= (~BOOT_STATUS_MASK);
1089 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1090 tp->mode_bits |= BOOT_TYPE_1;
1092 /* Get 58x Zero Wait State */
1093 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1095 r1 = inb(ioaddr + CNFG_IRR_583);
1097 if(r1 & CNFG_IRR_ZWS)
1098 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1100 if(tp->board_id & BOARD_16BIT)
1102 r1 = inb(ioaddr + CNFG_LAAR_584);
1104 if(r1 & CNFG_LAAR_ZWS)
1105 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1108 /* Get 584 Media Menu */
1109 tp->media_menu = 14;
1110 r1 = inb(ioaddr + CNFG_IRR_583);
1112 tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1113 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1115 /* Get Advanced Features */
1116 if(((r1 & 0x6) >> 1) == 0x3)
1117 tp->media_type |= MEDIA_UTP_16;
1118 else
1120 if(((r1 & 0x6) >> 1) == 0x2)
1121 tp->media_type |= MEDIA_STP_16;
1122 else
1124 if(((r1 & 0x6) >> 1) == 0x1)
1125 tp->media_type |= MEDIA_UTP_4;
1127 else
1128 tp->media_type |= MEDIA_STP_4;
1132 r1 = inb(ioaddr + CNFG_GP2);
1133 if(!(r1 & 0x2) ) /* GP2_ETRD */
1134 tp->mode_bits |= EARLY_TOKEN_REL;
1136 /* see if the chip is corrupted
1137 if(smctr_read_584_chksum(ioaddr))
1139 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1140 free_irq(dev->irq, dev);
1141 goto out2;
1146 return (0);
1148 out2:
1149 release_region(ioaddr, SMCTR_IO_EXTENT);
1150 out:
1151 return err;
1154 static int __init smctr_get_boardid(struct net_device *dev, int mca)
1156 struct net_local *tp = netdev_priv(dev);
1157 int ioaddr = dev->base_addr;
1158 __u8 r, r1, IdByte;
1159 __u16 BoardIdMask;
1161 tp->board_id = BoardIdMask = 0;
1163 if(mca)
1165 BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1166 tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT);
1168 else
1170 BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1171 tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K
1172 + NIC_825_BIT + ALTERNATE_IRQ_BIT);
1175 if(!mca)
1177 r = inb(ioaddr + BID_REG_1);
1178 r &= 0x0c;
1179 outb(r, ioaddr + BID_REG_1);
1180 r = inb(ioaddr + BID_REG_1);
1182 if(r & BID_SIXTEEN_BIT_BIT)
1184 tp->extra_info |= SLOT_16BIT;
1185 tp->adapter_bus = BUS_ISA16_TYPE;
1187 else
1188 tp->adapter_bus = BUS_ISA8_TYPE;
1190 else
1191 tp->adapter_bus = BUS_MCA_TYPE;
1193 /* Get Board Id Byte */
1194 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1196 /* if Major version > 1.0 then
1197 * return;
1199 if(IdByte & 0xF8)
1200 return (-1);
1202 r1 = inb(ioaddr + BID_REG_1);
1203 r1 &= BID_ICR_MASK;
1204 r1 |= BID_OTHER_BIT;
1206 outb(r1, ioaddr + BID_REG_1);
1207 r1 = inb(ioaddr + BID_REG_3);
1209 r1 &= BID_EAR_MASK;
1210 r1 |= BID_ENGR_PAGE;
1212 outb(r1, ioaddr + BID_REG_3);
1213 r1 = inb(ioaddr + BID_REG_1);
1214 r1 &= BID_ICR_MASK;
1215 r1 |= (BID_RLA | BID_OTHER_BIT);
1217 outb(r1, ioaddr + BID_REG_1);
1219 r1 = inb(ioaddr + BID_REG_1);
1220 while(r1 & BID_RECALL_DONE_MASK)
1221 r1 = inb(ioaddr + BID_REG_1);
1223 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1225 /* clear chip rev bits */
1226 tp->extra_info &= ~CHIP_REV_MASK;
1227 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1229 r1 = inb(ioaddr + BID_REG_1);
1230 r1 &= BID_ICR_MASK;
1231 r1 |= BID_OTHER_BIT;
1233 outb(r1, ioaddr + BID_REG_1);
1234 r1 = inb(ioaddr + BID_REG_3);
1236 r1 &= BID_EAR_MASK;
1237 r1 |= BID_EA6;
1239 outb(r1, ioaddr + BID_REG_3);
1240 r1 = inb(ioaddr + BID_REG_1);
1242 r1 &= BID_ICR_MASK;
1243 r1 |= BID_RLA;
1245 outb(r1, ioaddr + BID_REG_1);
1246 r1 = inb(ioaddr + BID_REG_1);
1248 while(r1 & BID_RECALL_DONE_MASK)
1249 r1 = inb(ioaddr + BID_REG_1);
1251 return (BoardIdMask);
1254 static int smctr_get_group_address(struct net_device *dev)
1256 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1258 return(smctr_wait_cmd(dev));
1261 static int smctr_get_functional_address(struct net_device *dev)
1263 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1265 return(smctr_wait_cmd(dev));
1268 /* Calculate number of Non-MAC receive BDB's and data buffers.
1269 * This function must simulate allocateing shared memory exactly
1270 * as the allocate_shared_memory function above.
1272 static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1274 struct net_local *tp = netdev_priv(dev);
1275 unsigned int mem_used = 0;
1277 /* Allocate System Control Blocks. */
1278 mem_used += sizeof(SCGBlock);
1280 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1281 mem_used += sizeof(SCLBlock);
1283 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1284 mem_used += sizeof(ACBlock) * tp->num_acbs;
1286 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1287 mem_used += sizeof(ISBlock);
1289 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1290 mem_used += MISC_DATA_SIZE;
1292 /* Allocate transmit FCB's. */
1293 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1295 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE];
1296 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE];
1297 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE];
1299 /* Allocate transmit BDBs. */
1300 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE];
1301 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE];
1302 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE];
1304 /* Allocate receive FCBs. */
1305 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE];
1306 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE];
1308 /* Allocate receive BDBs. */
1309 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1311 /* Allocate MAC transmit buffers.
1312 * MAC transmit buffers don't have to be on an ODD Boundry.
1314 mem_used += tp->tx_buff_size[MAC_QUEUE];
1316 /* Allocate BUG transmit buffers. */
1317 mem_used += tp->tx_buff_size[BUG_QUEUE];
1319 /* Allocate MAC receive data buffers.
1320 * MAC receive buffers don't have to be on a 256 byte boundary.
1322 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
1324 /* Allocate Non-MAC transmit buffers.
1325 * For maximum Netware performance, put Tx Buffers on
1326 * ODD Boundry,and then restore malloc to Even Boundrys.
1328 mem_used += 1L;
1329 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1330 mem_used += 1L;
1332 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1333 * AND NON-MAC RX DATA BUFFERS
1335 * Make sure the mem_used offset at this point is the
1336 * same as in allocate_shared memory or the following
1337 * boundary adjustment will be incorrect (i.e. not allocating
1338 * the non-mac receive buffers above cannot change the 256
1339 * byte offset).
1341 * Since this cannot be guaranteed, adding the full 256 bytes
1342 * to the amount of shared memory used at this point will guaranteed
1343 * that the rx data buffers do not overflow shared memory.
1345 mem_used += 0x100;
1347 return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock)));
1350 static int smctr_get_physical_drop_number(struct net_device *dev)
1352 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1354 return(smctr_wait_cmd(dev));
1357 static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1359 struct net_local *tp = netdev_priv(dev);
1360 BDBlock *bdb;
1362 bdb = (BDBlock *)((__u32)tp->ram_access
1363 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1365 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1367 return ((__u8 *)bdb->data_block_ptr);
1370 static int smctr_get_station_id(struct net_device *dev)
1372 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1374 return(smctr_wait_cmd(dev));
1378 * Get the current statistics. This may be called with the card open
1379 * or closed.
1381 static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1383 struct net_local *tp = netdev_priv(dev);
1385 return ((struct net_device_stats *)&tp->MacStat);
1388 static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1389 __u16 bytes_count)
1391 struct net_local *tp = netdev_priv(dev);
1392 FCBlock *pFCB;
1393 BDBlock *pbdb;
1394 unsigned short alloc_size;
1395 unsigned short *temp;
1397 if(smctr_debug > 20)
1398 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
1400 /* check if there is enough FCB blocks */
1401 if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue])
1402 return ((FCBlock *)(-1L));
1404 /* round off the input pkt size to the nearest even number */
1405 alloc_size = (bytes_count + 1) & 0xfffe;
1407 /* check if enough mem */
1408 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
1409 return ((FCBlock *)(-1L));
1411 /* check if past the end ;
1412 * if exactly enough mem to end of ring, alloc from front.
1413 * this avoids update of curr when curr = end
1415 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1416 >= (unsigned long)(tp->tx_buff_end[queue]))
1418 /* check if enough memory from ring head */
1419 alloc_size = alloc_size +
1420 (__u16)((__u32)tp->tx_buff_end[queue]
1421 - (__u32)tp->tx_buff_curr[queue]);
1423 if((tp->tx_buff_used[queue] + alloc_size)
1424 > tp->tx_buff_size[queue])
1426 return ((FCBlock *)(-1L));
1429 /* ring wrap */
1430 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
1433 tp->tx_buff_used[queue] += alloc_size;
1434 tp->num_tx_fcbs_used[queue]++;
1435 tp->tx_fcb_curr[queue]->frame_length = bytes_count;
1436 tp->tx_fcb_curr[queue]->memory_alloc = alloc_size;
1437 temp = tp->tx_buff_curr[queue];
1438 tp->tx_buff_curr[queue]
1439 = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe));
1441 pbdb = tp->tx_fcb_curr[queue]->bdb_ptr;
1442 pbdb->buffer_length = bytes_count;
1443 pbdb->data_block_ptr = temp;
1444 pbdb->trc_data_block_ptr = TRC_POINTER(temp);
1446 pFCB = tp->tx_fcb_curr[queue];
1447 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1449 return (pFCB);
1452 static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1454 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1456 return(smctr_wait_cmd(dev));
1459 static int smctr_hardware_send_packet(struct net_device *dev,
1460 struct net_local *tp)
1462 struct tr_statistics *tstat = &tp->MacStat;
1463 struct sk_buff *skb;
1464 FCBlock *fcb;
1466 if(smctr_debug > 10)
1467 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1469 if(tp->status != OPEN)
1470 return (-1);
1472 if(tp->monitor_state_ready != 1)
1473 return (-1);
1475 for(;;)
1477 /* Send first buffer from queue */
1478 skb = skb_dequeue(&tp->SendSkbQueue);
1479 if(skb == NULL)
1480 return (-1);
1482 tp->QueueSkb++;
1484 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size) return (-1);
1486 smctr_enable_16bit(dev);
1487 smctr_set_page(dev, (__u8 *)tp->ram_access);
1489 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1490 == (FCBlock *)(-1L))
1492 smctr_disable_16bit(dev);
1493 return (-1);
1496 smctr_tx_move_frame(dev, skb,
1497 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1499 smctr_set_page(dev, (__u8 *)fcb);
1501 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1502 dev_kfree_skb(skb);
1504 tstat->tx_packets++;
1506 smctr_disable_16bit(dev);
1509 return (0);
1512 static int smctr_init_acbs(struct net_device *dev)
1514 struct net_local *tp = netdev_priv(dev);
1515 unsigned int i;
1516 ACBlock *acb;
1518 if(smctr_debug > 10)
1519 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1521 acb = tp->acb_head;
1522 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1523 acb->cmd_info = ACB_CHAIN_END;
1524 acb->cmd = 0;
1525 acb->subcmd = 0;
1526 acb->data_offset_lo = 0;
1527 acb->data_offset_hi = 0;
1528 acb->next_ptr
1529 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1530 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1532 for(i = 1; i < tp->num_acbs; i++)
1534 acb = acb->next_ptr;
1535 acb->cmd_done_status
1536 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1537 acb->cmd_info = ACB_CHAIN_END;
1538 acb->cmd = 0;
1539 acb->subcmd = 0;
1540 acb->data_offset_lo = 0;
1541 acb->data_offset_hi = 0;
1542 acb->next_ptr
1543 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1544 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1547 acb->next_ptr = tp->acb_head;
1548 acb->trc_next_ptr = TRC_POINTER(tp->acb_head);
1549 tp->acb_next = tp->acb_head->next_ptr;
1550 tp->acb_curr = tp->acb_head->next_ptr;
1551 tp->num_acbs_used = 0;
1553 return (0);
1556 static int smctr_init_adapter(struct net_device *dev)
1558 struct net_local *tp = netdev_priv(dev);
1559 int err;
1561 if(smctr_debug > 10)
1562 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
1564 tp->status = CLOSED;
1565 tp->page_offset_mask = (tp->ram_usable * 1024) - 1;
1566 skb_queue_head_init(&tp->SendSkbQueue);
1567 tp->QueueSkb = MAX_TX_QUEUE;
1569 if(!(tp->group_address_0 & 0x0080))
1570 tp->group_address_0 |= 0x00C0;
1572 if(!(tp->functional_address_0 & 0x00C0))
1573 tp->functional_address_0 |= 0x00C0;
1575 tp->functional_address[0] &= 0xFF7F;
1577 if(tp->authorized_function_classes == 0)
1578 tp->authorized_function_classes = 0x7FFF;
1580 if(tp->authorized_access_priority == 0)
1581 tp->authorized_access_priority = 0x06;
1583 smctr_disable_bic_int(dev);
1584 smctr_set_trc_reset(dev->base_addr);
1586 smctr_enable_16bit(dev);
1587 smctr_set_page(dev, (__u8 *)tp->ram_access);
1589 if(smctr_checksum_firmware(dev))
1591 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name); return (-ENOENT);
1594 if((err = smctr_ram_memory_test(dev)))
1596 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1597 return (-EIO);
1600 smctr_set_rx_look_ahead(dev);
1601 smctr_load_node_addr(dev);
1603 /* Initialize adapter for Internal Self Test. */
1604 smctr_reset_adapter(dev);
1605 if((err = smctr_init_card_real(dev)))
1607 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1608 dev->name, err);
1609 return (-EINVAL);
1612 /* This routine clobbers the TRC's internal registers. */
1613 if((err = smctr_internal_self_test(dev)))
1615 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1616 dev->name, err);
1617 return (-EINVAL);
1620 /* Re-Initialize adapter's internal registers */
1621 smctr_reset_adapter(dev);
1622 if((err = smctr_init_card_real(dev)))
1624 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1625 dev->name, err);
1626 return (-EINVAL);
1629 smctr_enable_bic_int(dev);
1631 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1632 return (err);
1634 smctr_disable_16bit(dev);
1636 return (0);
1639 static int smctr_init_card_real(struct net_device *dev)
1641 struct net_local *tp = netdev_priv(dev);
1642 int err = 0;
1644 if(smctr_debug > 10)
1645 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1647 tp->sh_mem_used = 0;
1648 tp->num_acbs = NUM_OF_ACBS;
1650 /* Range Check Max Packet Size */
1651 if(tp->max_packet_size < 256)
1652 tp->max_packet_size = 256;
1653 else
1655 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1656 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1659 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1660 / tp->max_packet_size) - 1;
1662 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1663 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1664 else
1666 if(tp->num_of_tx_buffs == 0)
1667 tp->num_of_tx_buffs = 1;
1670 /* Tx queue constants */
1671 tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS;
1672 tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS;
1673 tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY;
1674 tp->tx_buff_used [BUG_QUEUE] = 0;
1675 tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING;
1677 tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS;
1678 tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS;
1679 tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY;
1680 tp->tx_buff_used [MAC_QUEUE] = 0;
1681 tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING;
1683 tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
1684 tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
1685 tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
1686 tp->tx_buff_used [NON_MAC_QUEUE] = 0;
1687 tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING;
1689 /* Receive Queue Constants */
1690 tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
1691 tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
1693 if(tp->extra_info & CHIP_REV_MASK)
1694 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1695 else
1696 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1698 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1700 smctr_alloc_shared_memory(dev);
1701 smctr_init_shared_memory(dev);
1703 if((err = smctr_issue_init_timers_cmd(dev)))
1704 return (err);
1706 if((err = smctr_issue_init_txrx_cmd(dev)))
1708 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1709 return (err);
1712 return (0);
1715 static int smctr_init_rx_bdbs(struct net_device *dev)
1717 struct net_local *tp = netdev_priv(dev);
1718 unsigned int i, j;
1719 BDBlock *bdb;
1720 __u16 *buf;
1722 if(smctr_debug > 10)
1723 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1725 for(i = 0; i < NUM_RX_QS_USED; i++)
1727 bdb = tp->rx_bdb_head[i];
1728 buf = tp->rx_buff_head[i];
1729 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
1730 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1731 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1732 bdb->data_block_ptr = buf;
1733 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1735 if(i == NON_MAC_QUEUE)
1736 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1737 else
1738 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1740 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1742 bdb->next_ptr->back_ptr = bdb;
1743 bdb = bdb->next_ptr;
1744 buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
1745 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1746 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1747 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1748 bdb->data_block_ptr = buf;
1749 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1751 if(i == NON_MAC_QUEUE)
1752 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1753 else
1754 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1757 bdb->next_ptr = tp->rx_bdb_head[i];
1758 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1760 tp->rx_bdb_head[i]->back_ptr = bdb;
1761 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1764 return (0);
1767 static int smctr_init_rx_fcbs(struct net_device *dev)
1769 struct net_local *tp = netdev_priv(dev);
1770 unsigned int i, j;
1771 FCBlock *fcb;
1773 for(i = 0; i < NUM_RX_QS_USED; i++)
1775 fcb = tp->rx_fcb_head[i];
1776 fcb->frame_status = 0;
1777 fcb->frame_length = 0;
1778 fcb->info = FCB_CHAIN_END;
1779 fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
1780 if(i == NON_MAC_QUEUE)
1781 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1782 else
1783 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1785 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1787 fcb->next_ptr->back_ptr = fcb;
1788 fcb = fcb->next_ptr;
1789 fcb->frame_status = 0;
1790 fcb->frame_length = 0;
1791 fcb->info = FCB_WARNING;
1792 fcb->next_ptr
1793 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1795 if(i == NON_MAC_QUEUE)
1796 fcb->trc_next_ptr
1797 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1798 else
1799 fcb->trc_next_ptr
1800 = TRC_POINTER(fcb->next_ptr);
1803 fcb->next_ptr = tp->rx_fcb_head[i];
1805 if(i == NON_MAC_QUEUE)
1806 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1807 else
1808 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1810 tp->rx_fcb_head[i]->back_ptr = fcb;
1811 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1814 return(0);
1817 static int smctr_init_shared_memory(struct net_device *dev)
1819 struct net_local *tp = netdev_priv(dev);
1820 unsigned int i;
1821 __u32 *iscpb;
1823 if(smctr_debug > 10)
1824 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1826 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1828 /* Initialize Initial System Configuration Point. (ISCP) */
1829 iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
1830 *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
1832 smctr_set_page(dev, (__u8 *)tp->ram_access);
1834 /* Initialize System Configuration Pointers. (SCP) */
1835 tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
1836 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
1837 | SCGB_BURST_LENGTH);
1839 tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr);
1840 tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head);
1841 tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr);
1842 tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2;
1844 /* Initialize System Control Block. (SCB) */
1845 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP;
1846 tp->sclb_ptr->iack_code = 0;
1847 tp->sclb_ptr->resume_control = 0;
1848 tp->sclb_ptr->int_mask_control = 0;
1849 tp->sclb_ptr->int_mask_state = 0;
1851 /* Initialize Interrupt Status Block. (ISB) */
1852 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1854 tp->isb_ptr->IStatus[i].IType = 0xf0;
1855 tp->isb_ptr->IStatus[i].ISubtype = 0;
1858 tp->current_isb_index = 0;
1860 /* Initialize Action Command Block. (ACB) */
1861 smctr_init_acbs(dev);
1863 /* Initialize transmit FCB's and BDB's. */
1864 smctr_link_tx_fcbs_to_bdbs(dev);
1865 smctr_init_tx_bdbs(dev);
1866 smctr_init_tx_fcbs(dev);
1868 /* Initialize receive FCB's and BDB's. */
1869 smctr_init_rx_bdbs(dev);
1870 smctr_init_rx_fcbs(dev);
1872 return (0);
1875 static int smctr_init_tx_bdbs(struct net_device *dev)
1877 struct net_local *tp = netdev_priv(dev);
1878 unsigned int i, j;
1879 BDBlock *bdb;
1881 for(i = 0; i < NUM_TX_QS_USED; i++)
1883 bdb = tp->tx_bdb_head[i];
1884 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1885 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1886 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1888 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1890 bdb->next_ptr->back_ptr = bdb;
1891 bdb = bdb->next_ptr;
1892 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1893 bdb->next_ptr
1894 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1897 bdb->next_ptr = tp->tx_bdb_head[i];
1898 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
1899 tp->tx_bdb_head[i]->back_ptr = bdb;
1902 return (0);
1905 static int smctr_init_tx_fcbs(struct net_device *dev)
1907 struct net_local *tp = netdev_priv(dev);
1908 unsigned int i, j;
1909 FCBlock *fcb;
1911 for(i = 0; i < NUM_TX_QS_USED; i++)
1913 fcb = tp->tx_fcb_head[i];
1914 fcb->frame_status = 0;
1915 fcb->frame_length = 0;
1916 fcb->info = FCB_CHAIN_END;
1917 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1918 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1920 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1922 fcb->next_ptr->back_ptr = fcb;
1923 fcb = fcb->next_ptr;
1924 fcb->frame_status = 0;
1925 fcb->frame_length = 0;
1926 fcb->info = FCB_CHAIN_END;
1927 fcb->next_ptr
1928 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1929 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1932 fcb->next_ptr = tp->tx_fcb_head[i];
1933 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1935 tp->tx_fcb_head[i]->back_ptr = fcb;
1936 tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr;
1937 tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr;
1938 tp->num_tx_fcbs_used[i] = 0;
1941 return (0);
1944 static int smctr_internal_self_test(struct net_device *dev)
1946 struct net_local *tp = netdev_priv(dev);
1947 int err;
1949 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1950 return (err);
1952 if((err = smctr_wait_cmd(dev)))
1953 return (err);
1955 if(tp->acb_head->cmd_done_status & 0xff)
1956 return (-1);
1958 if((err = smctr_issue_test_hic_cmd(dev)))
1959 return (err);
1961 if((err = smctr_wait_cmd(dev)))
1962 return (err);
1964 if(tp->acb_head->cmd_done_status & 0xff)
1965 return (-1);
1967 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1968 return (err);
1970 if((err = smctr_wait_cmd(dev)))
1971 return (err);
1973 if(tp->acb_head->cmd_done_status & 0xff)
1974 return (-1);
1976 return (0);
1980 * The typical workload of the driver: Handle the network interface interrupts.
1982 static irqreturn_t smctr_interrupt(int irq, void *dev_id)
1984 struct net_device *dev = dev_id;
1985 struct net_local *tp;
1986 int ioaddr;
1987 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1988 __u16 err1, err = NOT_MY_INTERRUPT;
1989 __u8 isb_type, isb_subtype;
1990 __u16 isb_index;
1992 ioaddr = dev->base_addr;
1993 tp = netdev_priv(dev);
1995 if(tp->status == NOT_INITIALIZED)
1996 return IRQ_NONE;
1998 spin_lock(&tp->lock);
2000 smctr_disable_bic_int(dev);
2001 smctr_enable_16bit(dev);
2003 smctr_clear_int(dev);
2005 /* First read the LSB */
2006 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2008 isb_index = tp->current_isb_index;
2009 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2010 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2012 (tp->current_isb_index)++;
2013 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2014 tp->current_isb_index = 0;
2016 if(isb_type >= 0x10)
2018 smctr_disable_16bit(dev);
2019 spin_unlock(&tp->lock);
2020 return IRQ_HANDLED;
2023 err = HARDWARE_FAILED;
2024 interrupt_ack_code = isb_index;
2025 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2027 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2029 switch(isb_type)
2031 case ISB_IMC_MAC_TYPE_3:
2032 smctr_disable_16bit(dev);
2034 switch(isb_subtype)
2036 case 0:
2037 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2038 break;
2040 case 1:
2041 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2042 break;
2044 case 2:
2045 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2046 break;
2048 case 3:
2049 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2051 case 4:
2052 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2053 break;
2055 case 5:
2056 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2057 break;
2059 case 6:
2060 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2061 break;
2063 case 7:
2064 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2065 break;
2067 case 8: /* diagnostic state */
2068 break;
2070 case 9:
2071 tp->monitor_state = MS_BEACON_TEST_STATE;
2072 if(smctr_lobe_media_test(dev))
2074 tp->ring_status_flags = RING_STATUS_CHANGED;
2075 tp->ring_status = AUTO_REMOVAL_ERROR;
2076 smctr_ring_status_chg(dev);
2077 smctr_bypass_state(dev);
2079 else
2080 smctr_issue_insert_cmd(dev);
2081 break;
2083 /* case 0x0a-0xff, illegal states */
2084 default:
2085 break;
2088 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2089 err = smctr_ring_status_chg(dev);
2091 smctr_enable_16bit(dev);
2092 break;
2094 /* Type 0x02 - MAC Error Counters Interrupt
2095 * One or more MAC Error Counter is half full
2096 * MAC Error Counters
2097 * Lost_FR_Error_Counter
2098 * RCV_Congestion_Counter
2099 * FR_copied_Error_Counter
2100 * FREQ_Error_Counter
2101 * Token_Error_Counter
2102 * Line_Error_Counter
2103 * Internal_Error_Count
2105 case ISB_IMC_MAC_ERROR_COUNTERS:
2106 /* Read 802.5 Error Counters */
2107 err = smctr_issue_read_ring_status_cmd(dev);
2108 break;
2110 /* Type 0x04 - MAC Type 2 Interrupt
2111 * HOST needs to enqueue MAC Frame for transmission
2112 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2113 * TRC_Status_Changed_Indicate
2115 case ISB_IMC_MAC_TYPE_2:
2116 err = smctr_issue_read_ring_status_cmd(dev);
2117 break;
2120 /* Type 0x05 - TX Frame Interrupt (FI). */
2121 case ISB_IMC_TX_FRAME:
2122 /* BUG QUEUE for TRC stuck receive BUG */
2123 if(isb_subtype & TX_PENDING_PRIORITY_2)
2125 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2126 break;
2129 /* NON-MAC frames only */
2130 if(isb_subtype & TX_PENDING_PRIORITY_1)
2132 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2133 break;
2136 /* MAC frames only */
2137 if(isb_subtype & TX_PENDING_PRIORITY_0)
2138 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2140 /* Type 0x06 - TX END OF QUEUE (FE) */
2141 case ISB_IMC_END_OF_TX_QUEUE:
2142 /* BUG queue */
2143 if(isb_subtype & TX_PENDING_PRIORITY_2)
2145 /* ok to clear Receive FIFO overrun
2146 * imask send_BUG now completes.
2148 interrupt_unmask_bits |= 0x800;
2150 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2151 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2152 break;
2153 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2154 break;
2157 /* NON-MAC queue only */
2158 if(isb_subtype & TX_PENDING_PRIORITY_1)
2160 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2161 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2162 break;
2163 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2164 break;
2167 /* MAC queue only */
2168 if(isb_subtype & TX_PENDING_PRIORITY_0)
2170 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2171 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2172 break;
2174 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2176 break;
2178 /* Type 0x07 - NON-MAC RX Resource Interrupt
2179 * Subtype bit 12 - (BW) BDB warning
2180 * Subtype bit 13 - (FW) FCB warning
2181 * Subtype bit 14 - (BE) BDB End of chain
2182 * Subtype bit 15 - (FE) FCB End of chain
2184 case ISB_IMC_NON_MAC_RX_RESOURCE:
2185 tp->rx_fifo_overrun_count = 0;
2186 tp->receive_queue_number = NON_MAC_QUEUE;
2187 err1 = smctr_rx_frame(dev);
2189 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2191 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2193 if(tp->ptr_rx_fcb_overruns)
2194 (*tp->ptr_rx_fcb_overruns)++;
2197 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2199 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2201 if(tp->ptr_rx_bdb_overruns)
2202 (*tp->ptr_rx_bdb_overruns)++;
2204 err = err1;
2205 break;
2207 /* Type 0x08 - MAC RX Resource Interrupt
2208 * Subtype bit 12 - (BW) BDB warning
2209 * Subtype bit 13 - (FW) FCB warning
2210 * Subtype bit 14 - (BE) BDB End of chain
2211 * Subtype bit 15 - (FE) FCB End of chain
2213 case ISB_IMC_MAC_RX_RESOURCE:
2214 tp->receive_queue_number = MAC_QUEUE;
2215 err1 = smctr_rx_frame(dev);
2217 if(isb_subtype & MAC_RX_RESOURCE_FE)
2219 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2220 break;
2222 if(tp->ptr_rx_fcb_overruns)
2223 (*tp->ptr_rx_fcb_overruns)++;
2226 if(isb_subtype & MAC_RX_RESOURCE_BE)
2228 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2229 break;
2231 if(tp->ptr_rx_bdb_overruns)
2232 (*tp->ptr_rx_bdb_overruns)++;
2234 err = err1;
2235 break;
2237 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2238 case ISB_IMC_NON_MAC_RX_FRAME:
2239 tp->rx_fifo_overrun_count = 0;
2240 tp->receive_queue_number = NON_MAC_QUEUE;
2241 err = smctr_rx_frame(dev);
2242 break;
2244 /* Type 0x0A - MAC RX Frame Interrupt */
2245 case ISB_IMC_MAC_RX_FRAME:
2246 tp->receive_queue_number = MAC_QUEUE;
2247 err = smctr_rx_frame(dev);
2248 break;
2250 /* Type 0x0B - TRC status
2251 * TRC has encountered an error condition
2252 * subtype bit 14 - transmit FIFO underrun
2253 * subtype bit 15 - receive FIFO overrun
2255 case ISB_IMC_TRC_FIFO_STATUS:
2256 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2258 if(tp->ptr_tx_fifo_underruns)
2259 (*tp->ptr_tx_fifo_underruns)++;
2262 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2264 /* update overrun stuck receive counter
2265 * if >= 3, has to clear it by sending
2266 * back to back frames. We pick
2267 * DAT(duplicate address MAC frame)
2269 tp->rx_fifo_overrun_count++;
2271 if(tp->rx_fifo_overrun_count >= 3)
2273 tp->rx_fifo_overrun_count = 0;
2275 /* delay clearing fifo overrun
2276 * imask till send_BUG tx
2277 * complete posted
2279 interrupt_unmask_bits &= (~0x800);
2280 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2283 if(tp->ptr_rx_fifo_overruns)
2284 (*tp->ptr_rx_fifo_overruns)++;
2287 err = SUCCESS;
2288 break;
2290 /* Type 0x0C - Action Command Status Interrupt
2291 * Subtype bit 14 - CB end of command chain (CE)
2292 * Subtype bit 15 - CB command interrupt (CI)
2294 case ISB_IMC_COMMAND_STATUS:
2295 err = SUCCESS;
2296 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2298 printk(KERN_ERR "i1\n");
2299 smctr_disable_16bit(dev);
2301 /* XXXXXXXXXXXXXXXXX */
2302 /* err = UM_Interrupt(dev); */
2304 smctr_enable_16bit(dev);
2306 else
2308 if((tp->acb_head->cmd
2309 == ACB_CMD_READ_TRC_STATUS)
2310 && (tp->acb_head->subcmd
2311 == RW_TRC_STATUS_BLOCK))
2313 if(tp->ptr_bcn_type != 0)
2315 *(tp->ptr_bcn_type)
2316 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2319 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2321 smctr_update_err_stats(dev);
2324 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2326 tp->ring_status
2327 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2328 smctr_disable_16bit(dev);
2329 err = smctr_ring_status_chg(dev);
2330 smctr_enable_16bit(dev);
2331 if((tp->ring_status & REMOVE_RECEIVED)
2332 && (tp->config_word0 & NO_AUTOREMOVE))
2334 smctr_issue_remove_cmd(dev);
2337 if(err != SUCCESS)
2339 tp->acb_pending = 0;
2340 break;
2344 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2346 if(tp->ptr_una)
2348 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2349 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2350 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2355 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2356 err = smctr_send_rq_init(dev);
2361 tp->acb_pending = 0;
2362 break;
2364 /* Type 0x0D - MAC Type 1 interrupt
2365 * Subtype -- 00 FR_BCN received at S12
2366 * 01 FR_BCN received at S21
2367 * 02 FR_DAT(DA=MA, A<>0) received at S21
2368 * 03 TSM_EXP at S21
2369 * 04 FR_REMOVE received at S42
2370 * 05 TBR_EXP, BR_FLAG_SET at S42
2371 * 06 TBT_EXP at S53
2373 case ISB_IMC_MAC_TYPE_1:
2374 if(isb_subtype > 8)
2376 err = HARDWARE_FAILED;
2377 break;
2380 err = SUCCESS;
2381 switch(isb_subtype)
2383 case 0:
2384 tp->join_state = JS_BYPASS_STATE;
2385 if(tp->status != CLOSED)
2387 tp->status = CLOSED;
2388 err = smctr_status_chg(dev);
2390 break;
2392 case 1:
2393 tp->join_state = JS_LOBE_TEST_STATE;
2394 break;
2396 case 2:
2397 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2398 break;
2400 case 3:
2401 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2402 break;
2404 case 4:
2405 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2406 break;
2408 case 5:
2409 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2410 break;
2412 case 6:
2413 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2414 break;
2416 case 7:
2417 tp->join_state = JS_JOIN_COMPLETE_STATE;
2418 tp->status = OPEN;
2419 err = smctr_status_chg(dev);
2420 break;
2422 case 8:
2423 tp->join_state = JS_BYPASS_WAIT_STATE;
2424 break;
2426 break ;
2428 /* Type 0x0E - TRC Initialization Sequence Interrupt
2429 * Subtype -- 00-FF Initializatin sequence complete
2431 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2432 tp->status = INITIALIZED;
2433 smctr_disable_16bit(dev);
2434 err = smctr_status_chg(dev);
2435 smctr_enable_16bit(dev);
2436 break;
2438 /* other interrupt types, illegal */
2439 default:
2440 break;
2443 if(err != SUCCESS)
2444 break;
2447 /* Checking the ack code instead of the unmask bits here is because :
2448 * while fixing the stuck receive, DAT frame are sent and mask off
2449 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2450 * but we still want to issue ack to ISB
2452 if(!(interrupt_ack_code & 0xff00))
2453 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2455 smctr_disable_16bit(dev);
2456 smctr_enable_bic_int(dev);
2457 spin_unlock(&tp->lock);
2459 return IRQ_HANDLED;
2462 static int smctr_issue_enable_int_cmd(struct net_device *dev,
2463 __u16 interrupt_enable_mask)
2465 struct net_local *tp = netdev_priv(dev);
2466 int err;
2468 if((err = smctr_wait_while_cbusy(dev)))
2469 return (err);
2471 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2472 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2474 smctr_set_ctrl_attention(dev);
2476 return (0);
2479 static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2481 struct net_local *tp = netdev_priv(dev);
2483 if(smctr_wait_while_cbusy(dev))
2484 return (-1);
2486 tp->sclb_ptr->int_mask_control = ibits;
2487 tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0;
2488 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2490 smctr_set_ctrl_attention(dev);
2492 return (0);
2495 static int smctr_issue_init_timers_cmd(struct net_device *dev)
2497 struct net_local *tp = netdev_priv(dev);
2498 unsigned int i;
2499 int err;
2500 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2502 if((err = smctr_wait_while_cbusy(dev)))
2503 return (err);
2505 if((err = smctr_wait_cmd(dev)))
2506 return (err);
2508 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2509 tp->config_word1 = 0;
2511 if((tp->media_type == MEDIA_STP_16)
2512 || (tp->media_type == MEDIA_UTP_16)
2513 || (tp->media_type == MEDIA_STP_16_UTP_16))
2515 tp->config_word0 |= FREQ_16MB_BIT;
2518 if(tp->mode_bits & EARLY_TOKEN_REL)
2519 tp->config_word0 |= ETREN;
2521 if(tp->mode_bits & LOOPING_MODE_MASK)
2522 tp->config_word0 |= RX_OWN_BIT;
2523 else
2524 tp->config_word0 &= ~RX_OWN_BIT;
2526 if(tp->receive_mask & PROMISCUOUS_MODE)
2527 tp->config_word0 |= PROMISCUOUS_BIT;
2528 else
2529 tp->config_word0 &= ~PROMISCUOUS_BIT;
2531 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2532 tp->config_word0 |= SAVBAD_BIT;
2533 else
2534 tp->config_word0 &= ~SAVBAD_BIT;
2536 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2537 tp->config_word0 |= RXATMAC;
2538 else
2539 tp->config_word0 &= ~RXATMAC;
2541 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2542 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2543 else
2544 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2546 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2547 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2548 else
2550 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2551 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2552 else
2553 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2556 if((tp->media_type == MEDIA_STP_16)
2557 || (tp->media_type == MEDIA_UTP_16)
2558 || (tp->media_type == MEDIA_STP_16_UTP_16))
2560 tp->config_word1 |= INTERFRAME_SPACING_16;
2562 else
2563 tp->config_word1 |= INTERFRAME_SPACING_4;
2565 *pTimer_Struc++ = tp->config_word0;
2566 *pTimer_Struc++ = tp->config_word1;
2568 if((tp->media_type == MEDIA_STP_4)
2569 || (tp->media_type == MEDIA_UTP_4)
2570 || (tp->media_type == MEDIA_STP_4_UTP_4))
2572 *pTimer_Struc++ = 0x00FA; /* prescale */
2573 *pTimer_Struc++ = 0x2710; /* TPT_limit */
2574 *pTimer_Struc++ = 0x2710; /* TQP_limit */
2575 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2576 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2577 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2578 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2579 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2580 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2581 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2582 *pTimer_Struc++ = 0x1162; /* THT_limit */
2583 *pTimer_Struc++ = 0x07D0; /* TRR_limit */
2584 *pTimer_Struc++ = 0x1388; /* TVX_limit */
2585 *pTimer_Struc++ = 0x0000; /* reserved */
2587 else
2589 *pTimer_Struc++ = 0x03E8; /* prescale */
2590 *pTimer_Struc++ = 0x9C40; /* TPT_limit */
2591 *pTimer_Struc++ = 0x9C40; /* TQP_limit */
2592 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2593 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2594 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2595 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2596 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2597 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2598 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2599 *pTimer_Struc++ = 0x4588; /* THT_limit */
2600 *pTimer_Struc++ = 0x1F40; /* TRR_limit */
2601 *pTimer_Struc++ = 0x4E20; /* TVX_limit */
2602 *pTimer_Struc++ = 0x0000; /* reserved */
2605 /* Set node address. */
2606 *pTimer_Struc++ = dev->dev_addr[0] << 8
2607 | (dev->dev_addr[1] & 0xFF);
2608 *pTimer_Struc++ = dev->dev_addr[2] << 8
2609 | (dev->dev_addr[3] & 0xFF);
2610 *pTimer_Struc++ = dev->dev_addr[4] << 8
2611 | (dev->dev_addr[5] & 0xFF);
2613 /* Set group address. */
2614 *pTimer_Struc++ = tp->group_address_0 << 8
2615 | tp->group_address_0 >> 8;
2616 *pTimer_Struc++ = tp->group_address[0] << 8
2617 | tp->group_address[0] >> 8;
2618 *pTimer_Struc++ = tp->group_address[1] << 8
2619 | tp->group_address[1] >> 8;
2621 /* Set functional address. */
2622 *pTimer_Struc++ = tp->functional_address_0 << 8
2623 | tp->functional_address_0 >> 8;
2624 *pTimer_Struc++ = tp->functional_address[0] << 8
2625 | tp->functional_address[0] >> 8;
2626 *pTimer_Struc++ = tp->functional_address[1] << 8
2627 | tp->functional_address[1] >> 8;
2629 /* Set Bit-Wise group address. */
2630 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2631 | tp->bitwise_group_address[0] >> 8;
2632 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2633 | tp->bitwise_group_address[1] >> 8;
2635 /* Set ring number address. */
2636 *pTimer_Struc++ = tp->source_ring_number;
2637 *pTimer_Struc++ = tp->target_ring_number;
2639 /* Physical drop number. */
2640 *pTimer_Struc++ = (unsigned short)0;
2641 *pTimer_Struc++ = (unsigned short)0;
2643 /* Product instance ID. */
2644 for(i = 0; i < 9; i++)
2645 *pTimer_Struc++ = (unsigned short)0;
2647 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2649 return (err);
2652 static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2654 struct net_local *tp = netdev_priv(dev);
2655 unsigned int i;
2656 int err;
2657 void **txrx_ptrs = (void *)tp->misc_command_data;
2659 if((err = smctr_wait_while_cbusy(dev)))
2660 return (err);
2662 if((err = smctr_wait_cmd(dev)))
2664 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2665 return (err);
2668 /* Initialize Transmit Queue Pointers that are used, to point to
2669 * a single FCB.
2671 for(i = 0; i < NUM_TX_QS_USED; i++)
2672 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2674 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2675 for(; i < MAX_TX_QS; i++)
2676 *txrx_ptrs++ = (void *)0;
2678 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2679 * used, to point to a single FCB and a BDB chain of buffers.
2681 for(i = 0; i < NUM_RX_QS_USED; i++)
2683 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2684 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2687 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2688 for(; i < MAX_RX_QS; i++)
2690 *txrx_ptrs++ = (void *)0;
2691 *txrx_ptrs++ = (void *)0;
2694 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2696 return (err);
2699 static int smctr_issue_insert_cmd(struct net_device *dev)
2701 int err;
2703 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2705 return (err);
2708 static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2710 int err;
2712 if((err = smctr_wait_while_cbusy(dev)))
2713 return (err);
2715 if((err = smctr_wait_cmd(dev)))
2716 return (err);
2718 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2719 RW_TRC_STATUS_BLOCK);
2721 return (err);
2724 static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2726 int err;
2728 if((err = smctr_wait_while_cbusy(dev)))
2729 return (err);
2731 if((err = smctr_wait_cmd(dev)))
2732 return (err);
2734 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2735 aword_cnt);
2737 return (err);
2740 static int smctr_issue_remove_cmd(struct net_device *dev)
2742 struct net_local *tp = netdev_priv(dev);
2743 int err;
2745 if((err = smctr_wait_while_cbusy(dev)))
2746 return (err);
2748 tp->sclb_ptr->resume_control = 0;
2749 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2751 smctr_set_ctrl_attention(dev);
2753 return (0);
2756 static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2758 struct net_local *tp = netdev_priv(dev);
2759 int err;
2761 if((err = smctr_wait_while_cbusy(dev)))
2762 return (err);
2764 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2765 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2767 tp->acb_pending = 1;
2769 smctr_set_ctrl_attention(dev);
2771 return (0);
2774 static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2776 struct net_local *tp = netdev_priv(dev);
2777 int err;
2779 if((err = smctr_wait_while_cbusy(dev)))
2780 return (err);
2782 if(queue == MAC_QUEUE)
2783 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2784 else
2785 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2787 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2789 smctr_set_ctrl_attention(dev);
2791 return (0);
2794 static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2796 struct net_local *tp = netdev_priv(dev);
2798 if(smctr_debug > 10)
2799 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2801 if(smctr_wait_while_cbusy(dev))
2802 return (-1);
2804 if(queue == MAC_QUEUE)
2805 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2806 else
2807 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2809 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2811 smctr_set_ctrl_attention(dev);
2813 return (0);
2816 static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2818 struct net_local *tp = netdev_priv(dev);
2820 if(smctr_debug > 10)
2821 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2823 if(smctr_wait_while_cbusy(dev))
2824 return (-1);
2826 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2827 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2829 smctr_set_ctrl_attention(dev);
2831 return (0);
2834 static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2836 int err;
2838 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2839 TRC_INTERNAL_ROM_TEST);
2841 return (err);
2844 static int smctr_issue_test_hic_cmd(struct net_device *dev)
2846 int err;
2848 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2849 TRC_HOST_INTERFACE_REG_TEST);
2851 return (err);
2854 static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2856 int err;
2858 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2859 TRC_MAC_REGISTERS_TEST);
2861 return (err);
2864 static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2866 int err;
2868 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2869 TRC_INTERNAL_LOOPBACK);
2871 return (err);
2874 static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2876 int err;
2878 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2879 TRC_TRI_LOOPBACK);
2881 return (err);
2884 static int smctr_issue_write_byte_cmd(struct net_device *dev,
2885 short aword_cnt, void *byte)
2887 struct net_local *tp = netdev_priv(dev);
2888 unsigned int iword, ibyte;
2889 int err;
2891 if((err = smctr_wait_while_cbusy(dev)))
2892 return (err);
2894 if((err = smctr_wait_cmd(dev)))
2895 return (err);
2897 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2898 iword++, ibyte += 2)
2900 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2901 | (*((__u8 *)byte + ibyte + 1));
2904 return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2905 aword_cnt));
2908 static int smctr_issue_write_word_cmd(struct net_device *dev,
2909 short aword_cnt, void *word)
2911 struct net_local *tp = netdev_priv(dev);
2912 unsigned int i, err;
2914 if((err = smctr_wait_while_cbusy(dev)))
2915 return (err);
2917 if((err = smctr_wait_cmd(dev)))
2918 return (err);
2920 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2921 tp->misc_command_data[i] = *((__u16 *)word + i);
2923 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2924 aword_cnt);
2926 return (err);
2929 static int smctr_join_complete_state(struct net_device *dev)
2931 int err;
2933 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2934 JS_JOIN_COMPLETE_STATE);
2936 return (err);
2939 static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2941 struct net_local *tp = netdev_priv(dev);
2942 unsigned int i, j;
2943 FCBlock *fcb;
2944 BDBlock *bdb;
2946 for(i = 0; i < NUM_TX_QS_USED; i++)
2948 fcb = tp->tx_fcb_head[i];
2949 bdb = tp->tx_bdb_head[i];
2951 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2953 fcb->bdb_ptr = bdb;
2954 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2955 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2956 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2960 return (0);
2963 static int smctr_load_firmware(struct net_device *dev)
2965 struct net_local *tp = netdev_priv(dev);
2966 __u16 i, checksum = 0;
2967 int err = 0;
2969 if(smctr_debug > 10)
2970 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2972 tp->ptr_ucode = smctr_code;
2973 tp->num_of_tx_buffs = 4;
2974 tp->mode_bits |= UMAC;
2975 tp->receive_mask = 0;
2976 tp->max_packet_size = 4177;
2978 /* Can only upload the firmware once per adapter reset. */
2979 if(tp->microcode_version != 0)
2980 return (UCODE_PRESENT);
2982 /* Verify the firmware exists and is there in the right amount. */
2983 if((tp->ptr_ucode == 0L)
2984 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET) < UCODE_VERSION))
2986 return (UCODE_NOT_PRESENT);
2989 /* UCODE_SIZE is not included in Checksum. */
2990 for(i = 0; i < *((__u16 *)(tp->ptr_ucode + UCODE_SIZE_OFFSET)); i += 2)
2991 checksum += *((__u16 *)(tp->ptr_ucode + 2 + i));
2992 if(checksum)
2993 return (UCODE_NOT_PRESENT);
2995 /* At this point we have a valid firmware image, lets kick it on up. */
2996 smctr_enable_adapter_ram(dev);
2997 smctr_enable_16bit(dev);
2998 smctr_set_page(dev, (__u8 *)tp->ram_access);
3000 if((smctr_checksum_firmware(dev))
3001 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET)
3002 > tp->microcode_version))
3004 smctr_enable_adapter_ctrl_store(dev);
3006 /* Zero out ram space for firmware. */
3007 for(i = 0; i < CS_RAM_SIZE; i += 2)
3008 *((__u16 *)(tp->ram_access + i)) = 0;
3010 smctr_decode_firmware(dev);
3012 tp->microcode_version = *(tp->ptr_ucode + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
3013 = (tp->microcode_version << 8);
3014 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3015 = ~(tp->microcode_version << 8) + 1;
3017 smctr_disable_adapter_ctrl_store(dev);
3019 if(smctr_checksum_firmware(dev))
3020 err = HARDWARE_FAILED;
3022 else
3023 err = UCODE_PRESENT;
3025 smctr_disable_16bit(dev);
3027 return (err);
3030 static int smctr_load_node_addr(struct net_device *dev)
3032 int ioaddr = dev->base_addr;
3033 unsigned int i;
3034 __u8 r;
3036 for(i = 0; i < 6; i++)
3038 r = inb(ioaddr + LAR0 + i);
3039 dev->dev_addr[i] = (char)r;
3041 dev->addr_len = 6;
3043 return (0);
3046 /* Lobe Media Test.
3047 * During the transmission of the initial 1500 lobe media MAC frames,
3048 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3049 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3050 * microcode will not transmit any frames given to it by the host, and
3051 * will consequently cause a timeout.
3053 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
3054 * queues other then the one used for the lobe_media_test should be
3055 * disabled.!?
3057 * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
3058 * has any multi-cast or promiscous bits set, the receive_mask needs to
3059 * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
3060 * run, and then the receive mask set back to its original value if the test
3061 * is successful.
3063 static int smctr_lobe_media_test(struct net_device *dev)
3065 struct net_local *tp = netdev_priv(dev);
3066 unsigned int i, perror = 0;
3067 unsigned short saved_rcv_mask;
3069 if(smctr_debug > 10)
3070 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3072 /* Clear receive mask for lobe test. */
3073 saved_rcv_mask = tp->receive_mask;
3074 tp->receive_mask = 0;
3076 smctr_chg_rx_mask(dev);
3078 /* Setup the lobe media test. */
3079 smctr_lobe_media_test_cmd(dev);
3080 if(smctr_wait_cmd(dev))
3082 smctr_reset_adapter(dev);
3083 tp->status = CLOSED;
3084 return (LOBE_MEDIA_TEST_FAILED);
3087 /* Tx lobe media test frames. */
3088 for(i = 0; i < 1500; ++i)
3090 if(smctr_send_lobe_media_test(dev))
3092 if(perror)
3094 smctr_reset_adapter(dev);
3095 tp->state = CLOSED;
3096 return (LOBE_MEDIA_TEST_FAILED);
3098 else
3100 perror = 1;
3101 if(smctr_lobe_media_test_cmd(dev))
3103 smctr_reset_adapter(dev);
3104 tp->state = CLOSED;
3105 return (LOBE_MEDIA_TEST_FAILED);
3111 if(smctr_send_dat(dev))
3113 if(smctr_send_dat(dev))
3115 smctr_reset_adapter(dev);
3116 tp->state = CLOSED;
3117 return (LOBE_MEDIA_TEST_FAILED);
3121 /* Check if any frames received during test. */
3122 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status)
3123 || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3125 smctr_reset_adapter(dev);
3126 tp->state = CLOSED;
3127 return (LOBE_MEDIA_TEST_FAILED);
3130 /* Set receive mask to "Promisc" mode. */
3131 tp->receive_mask = saved_rcv_mask;
3133 smctr_chg_rx_mask(dev);
3135 return (0);
3138 static int smctr_lobe_media_test_cmd(struct net_device *dev)
3140 struct net_local *tp = netdev_priv(dev);
3141 int err;
3143 if(smctr_debug > 10)
3144 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3146 /* Change to lobe media test state. */
3147 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3149 smctr_lobe_media_test_state(dev);
3150 if(smctr_wait_cmd(dev))
3152 printk(KERN_ERR "Lobe Failed test state\n");
3153 return (LOBE_MEDIA_TEST_FAILED);
3157 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3158 TRC_LOBE_MEDIA_TEST);
3160 return (err);
3163 static int smctr_lobe_media_test_state(struct net_device *dev)
3165 int err;
3167 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3168 JS_LOBE_TEST_STATE);
3170 return (err);
3173 static int smctr_make_8025_hdr(struct net_device *dev,
3174 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3176 tmf->ac = MSB(ac_fc); /* msb is access control */
3177 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3179 tmf->sa[0] = dev->dev_addr[0];
3180 tmf->sa[1] = dev->dev_addr[1];
3181 tmf->sa[2] = dev->dev_addr[2];
3182 tmf->sa[3] = dev->dev_addr[3];
3183 tmf->sa[4] = dev->dev_addr[4];
3184 tmf->sa[5] = dev->dev_addr[5];
3186 switch(tmf->vc)
3188 /* Send RQ_INIT to RPS */
3189 case RQ_INIT:
3190 tmf->da[0] = 0xc0;
3191 tmf->da[1] = 0x00;
3192 tmf->da[2] = 0x00;
3193 tmf->da[3] = 0x00;
3194 tmf->da[4] = 0x00;
3195 tmf->da[5] = 0x02;
3196 break;
3198 /* Send RPT_TX_FORWARD to CRS */
3199 case RPT_TX_FORWARD:
3200 tmf->da[0] = 0xc0;
3201 tmf->da[1] = 0x00;
3202 tmf->da[2] = 0x00;
3203 tmf->da[3] = 0x00;
3204 tmf->da[4] = 0x00;
3205 tmf->da[5] = 0x10;
3206 break;
3208 /* Everything else goes to sender */
3209 default:
3210 tmf->da[0] = rmf->sa[0];
3211 tmf->da[1] = rmf->sa[1];
3212 tmf->da[2] = rmf->sa[2];
3213 tmf->da[3] = rmf->sa[3];
3214 tmf->da[4] = rmf->sa[4];
3215 tmf->da[5] = rmf->sa[5];
3216 break;
3219 return (0);
3222 static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3224 struct net_local *tp = netdev_priv(dev);
3226 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3227 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3229 tsv->svv[0] = MSB(tp->authorized_access_priority);
3230 tsv->svv[1] = LSB(tp->authorized_access_priority);
3232 return (0);
3235 static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3237 tsv->svi = ADDRESS_MODIFER;
3238 tsv->svl = S_ADDRESS_MODIFER;
3240 tsv->svv[0] = 0;
3241 tsv->svv[1] = 0;
3243 return (0);
3246 static int smctr_make_auth_funct_class(struct net_device *dev,
3247 MAC_SUB_VECTOR *tsv)
3249 struct net_local *tp = netdev_priv(dev);
3251 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3252 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3254 tsv->svv[0] = MSB(tp->authorized_function_classes);
3255 tsv->svv[1] = LSB(tp->authorized_function_classes);
3257 return (0);
3260 static int smctr_make_corr(struct net_device *dev,
3261 MAC_SUB_VECTOR *tsv, __u16 correlator)
3263 tsv->svi = CORRELATOR;
3264 tsv->svl = S_CORRELATOR;
3266 tsv->svv[0] = MSB(correlator);
3267 tsv->svv[1] = LSB(correlator);
3269 return (0);
3272 static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3274 struct net_local *tp = netdev_priv(dev);
3276 smctr_get_functional_address(dev);
3278 tsv->svi = FUNCTIONAL_ADDRESS;
3279 tsv->svl = S_FUNCTIONAL_ADDRESS;
3281 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3282 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3284 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3285 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3287 return (0);
3290 static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3292 struct net_local *tp = netdev_priv(dev);
3294 smctr_get_group_address(dev);
3296 tsv->svi = GROUP_ADDRESS;
3297 tsv->svl = S_GROUP_ADDRESS;
3299 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3300 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3302 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3303 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3305 /* Set Group Address Sub-vector to all zeros if only the
3306 * Group Address/Functional Address Indicator is set.
3308 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00
3309 && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3310 tsv->svv[0] = 0x00;
3312 return (0);
3315 static int smctr_make_phy_drop_num(struct net_device *dev,
3316 MAC_SUB_VECTOR *tsv)
3318 struct net_local *tp = netdev_priv(dev);
3320 smctr_get_physical_drop_number(dev);
3322 tsv->svi = PHYSICAL_DROP;
3323 tsv->svl = S_PHYSICAL_DROP;
3325 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3326 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3328 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3329 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3331 return (0);
3334 static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3336 int i;
3338 tsv->svi = PRODUCT_INSTANCE_ID;
3339 tsv->svl = S_PRODUCT_INSTANCE_ID;
3341 for(i = 0; i < 18; i++)
3342 tsv->svv[i] = 0xF0;
3344 return (0);
3347 static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3349 struct net_local *tp = netdev_priv(dev);
3351 smctr_get_station_id(dev);
3353 tsv->svi = STATION_IDENTIFER;
3354 tsv->svl = S_STATION_IDENTIFER;
3356 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3357 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3359 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3360 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3362 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3363 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3365 return (0);
3368 static int smctr_make_ring_station_status(struct net_device *dev,
3369 MAC_SUB_VECTOR * tsv)
3371 tsv->svi = RING_STATION_STATUS;
3372 tsv->svl = S_RING_STATION_STATUS;
3374 tsv->svv[0] = 0;
3375 tsv->svv[1] = 0;
3376 tsv->svv[2] = 0;
3377 tsv->svv[3] = 0;
3378 tsv->svv[4] = 0;
3379 tsv->svv[5] = 0;
3381 return (0);
3384 static int smctr_make_ring_station_version(struct net_device *dev,
3385 MAC_SUB_VECTOR *tsv)
3387 struct net_local *tp = netdev_priv(dev);
3389 tsv->svi = RING_STATION_VERSION_NUMBER;
3390 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3392 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3393 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3394 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3395 tsv->svv[3] = 0x40; /* EBCDIC - */
3396 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3397 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3398 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3399 tsv->svv[7] = 0x40; /* EBCDIC - */
3400 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3402 if(tp->extra_info & CHIP_REV_MASK)
3403 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3404 else
3405 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3407 return (0);
3410 static int smctr_make_tx_status_code(struct net_device *dev,
3411 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3413 tsv->svi = TRANSMIT_STATUS_CODE;
3414 tsv->svl = S_TRANSMIT_STATUS_CODE;
3416 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) || IBM_PASS_SOURCE_ADDR);
3418 /* Stripped frame status of Transmitted Frame */
3419 tsv->svv[1] = tx_fstatus & 0xff;
3421 return (0);
3424 static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3425 MAC_SUB_VECTOR *tsv)
3427 struct net_local *tp = netdev_priv(dev);
3429 smctr_get_upstream_neighbor_addr(dev);
3431 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3432 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3434 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3435 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3437 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3438 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3440 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3441 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3443 return (0);
3446 static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3448 tsv->svi = WRAP_DATA;
3449 tsv->svl = S_WRAP_DATA;
3451 return (0);
3455 * Open/initialize the board. This is called sometime after
3456 * booting when the 'ifconfig' program is run.
3458 * This routine should set everything up anew at each open, even
3459 * registers that "should" only need to be set once at boot, so that
3460 * there is non-reboot way to recover if something goes wrong.
3462 static int smctr_open(struct net_device *dev)
3464 int err;
3466 if(smctr_debug > 10)
3467 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3469 err = smctr_init_adapter(dev);
3470 if(err < 0)
3471 return (err);
3473 return (err);
3476 /* Interrupt driven open of Token card. */
3477 static int smctr_open_tr(struct net_device *dev)
3479 struct net_local *tp = netdev_priv(dev);
3480 unsigned long flags;
3481 int err;
3483 if(smctr_debug > 10)
3484 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3486 /* Now we can actually open the adapter. */
3487 if(tp->status == OPEN)
3488 return (0);
3489 if(tp->status != INITIALIZED)
3490 return (-1);
3492 /* FIXME: it would work a lot better if we masked the irq sources
3493 on the card here, then we could skip the locking and poll nicely */
3494 spin_lock_irqsave(&tp->lock, flags);
3496 smctr_set_page(dev, (__u8 *)tp->ram_access);
3498 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3499 goto out;
3501 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3502 goto out;
3504 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3505 goto out;
3507 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3508 goto out;
3510 tp->status = CLOSED;
3512 /* Insert into the Ring or Enter Loopback Mode. */
3513 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3515 tp->status = CLOSED;
3517 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3519 if(!(err = smctr_wait_cmd(dev)))
3520 tp->status = OPEN;
3523 smctr_status_chg(dev);
3525 else
3527 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3529 tp->status = CLOSED;
3530 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3532 if(!(err = smctr_wait_cmd(dev)))
3533 tp->status = OPEN;
3536 smctr_status_chg(dev);
3538 else
3540 if((tp->mode_bits & LOOPING_MODE_MASK)
3541 == LOOPBACK_MODE_3)
3543 tp->status = CLOSED;
3544 if(!(err = smctr_lobe_media_test_cmd(dev)))
3546 if(!(err = smctr_wait_cmd(dev)))
3547 tp->status = OPEN;
3549 smctr_status_chg(dev);
3551 else
3553 if(!(err = smctr_lobe_media_test(dev)))
3554 err = smctr_issue_insert_cmd(dev);
3555 else
3557 if(err == LOBE_MEDIA_TEST_FAILED)
3558 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3564 out:
3565 spin_unlock_irqrestore(&tp->lock, flags);
3567 return (err);
3570 /* Check for a network adapter of this type,
3571 * and return device structure if one exists.
3573 struct net_device __init *smctr_probe(int unit)
3575 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3576 static const unsigned ports[] = {
3577 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3578 0x320, 0x340, 0x360, 0x380, 0
3580 const unsigned *port;
3581 int err = 0;
3583 if (!dev)
3584 return ERR_PTR(-ENOMEM);
3586 if (unit >= 0) {
3587 sprintf(dev->name, "tr%d", unit);
3588 netdev_boot_setup_check(dev);
3591 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3592 err = smctr_probe1(dev, dev->base_addr);
3593 else if(dev->base_addr != 0) /* Don't probe at all. */
3594 err =-ENXIO;
3595 else {
3596 for (port = ports; *port; port++) {
3597 err = smctr_probe1(dev, *port);
3598 if (!err)
3599 break;
3602 if (err)
3603 goto out;
3604 err = register_netdev(dev);
3605 if (err)
3606 goto out1;
3607 return dev;
3608 out1:
3609 #ifdef CONFIG_MCA_LEGACY
3610 { struct net_local *tp = netdev_priv(dev);
3611 if (tp->slot_num)
3612 mca_mark_as_unused(tp->slot_num);
3614 #endif
3615 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3616 free_irq(dev->irq, dev);
3617 out:
3618 free_netdev(dev);
3619 return ERR_PTR(err);
3623 static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3625 static unsigned version_printed;
3626 struct net_local *tp = netdev_priv(dev);
3627 int err;
3628 __u32 *ram;
3630 if(smctr_debug && version_printed++ == 0)
3631 printk(version);
3633 spin_lock_init(&tp->lock);
3634 dev->base_addr = ioaddr;
3636 /* Actually detect an adapter now. */
3637 err = smctr_chk_isa(dev);
3638 if(err < 0)
3640 if ((err = smctr_chk_mca(dev)) < 0) {
3641 err = -ENODEV;
3642 goto out;
3646 tp = netdev_priv(dev);
3647 dev->mem_start = tp->ram_base;
3648 dev->mem_end = dev->mem_start + 0x10000;
3649 ram = (__u32 *)phys_to_virt(dev->mem_start);
3650 tp->ram_access = *(__u32 *)&ram;
3651 tp->status = NOT_INITIALIZED;
3653 err = smctr_load_firmware(dev);
3654 if(err != UCODE_PRESENT && err != SUCCESS)
3656 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3657 err = -EIO;
3658 goto out;
3661 /* Allow user to specify ring speed on module insert. */
3662 if(ringspeed == 4)
3663 tp->media_type = MEDIA_UTP_4;
3664 else
3665 tp->media_type = MEDIA_UTP_16;
3667 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3668 dev->name, smctr_name, smctr_model,
3669 (unsigned int)dev->base_addr,
3670 dev->irq, tp->rom_base, tp->ram_base);
3672 dev->open = smctr_open;
3673 dev->stop = smctr_close;
3674 dev->hard_start_xmit = smctr_send_packet;
3675 dev->tx_timeout = smctr_timeout;
3676 dev->watchdog_timeo = HZ;
3677 dev->get_stats = smctr_get_stats;
3678 dev->set_multicast_list = &smctr_set_multicast_list;
3679 return (0);
3681 out:
3682 return err;
3685 static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3686 struct net_device *dev, __u16 rx_status)
3688 struct net_local *tp = netdev_priv(dev);
3689 struct sk_buff *skb;
3690 __u16 rcode, correlator;
3691 int err = 0;
3692 __u8 xframe = 1;
3694 rmf->vl = SWAP_BYTES(rmf->vl);
3695 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3697 switch(rmf->vc)
3699 /* Received MAC Frames Processed by RS. */
3700 case INIT:
3701 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3703 return (rcode);
3706 if((err = smctr_send_rsp(dev, rmf, rcode,
3707 correlator)))
3709 return (err);
3711 break;
3713 case CHG_PARM:
3714 if((rcode = smctr_rcv_chg_param(dev, rmf,
3715 &correlator)) ==HARDWARE_FAILED)
3717 return (rcode);
3720 if((err = smctr_send_rsp(dev, rmf, rcode,
3721 correlator)))
3723 return (err);
3725 break;
3727 case RQ_ADDR:
3728 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3729 rmf, &correlator)) != POSITIVE_ACK)
3731 if(rcode == HARDWARE_FAILED)
3732 return (rcode);
3733 else
3734 return (smctr_send_rsp(dev, rmf,
3735 rcode, correlator));
3738 if((err = smctr_send_rpt_addr(dev, rmf,
3739 correlator)))
3741 return (err);
3743 break;
3745 case RQ_ATTCH:
3746 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3747 rmf, &correlator)) != POSITIVE_ACK)
3749 if(rcode == HARDWARE_FAILED)
3750 return (rcode);
3751 else
3752 return (smctr_send_rsp(dev, rmf,
3753 rcode,
3754 correlator));
3757 if((err = smctr_send_rpt_attch(dev, rmf,
3758 correlator)))
3760 return (err);
3762 break;
3764 case RQ_STATE:
3765 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3766 rmf, &correlator)) != POSITIVE_ACK)
3768 if(rcode == HARDWARE_FAILED)
3769 return (rcode);
3770 else
3771 return (smctr_send_rsp(dev, rmf,
3772 rcode,
3773 correlator));
3776 if((err = smctr_send_rpt_state(dev, rmf,
3777 correlator)))
3779 return (err);
3781 break;
3783 case TX_FORWARD: {
3784 __u16 uninitialized_var(tx_fstatus);
3786 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3787 != POSITIVE_ACK)
3789 if(rcode == HARDWARE_FAILED)
3790 return (rcode);
3791 else
3792 return (smctr_send_rsp(dev, rmf,
3793 rcode,
3794 correlator));
3797 if((err = smctr_send_tx_forward(dev, rmf,
3798 &tx_fstatus)) == HARDWARE_FAILED)
3800 return (err);
3803 if(err == A_FRAME_WAS_FORWARDED)
3805 if((err = smctr_send_rpt_tx_forward(dev,
3806 rmf, tx_fstatus))
3807 == HARDWARE_FAILED)
3809 return (err);
3812 break;
3815 /* Received MAC Frames Processed by CRS/REM/RPS. */
3816 case RSP:
3817 case RQ_INIT:
3818 case RPT_NEW_MON:
3819 case RPT_SUA_CHG:
3820 case RPT_ACTIVE_ERR:
3821 case RPT_NN_INCMP:
3822 case RPT_ERROR:
3823 case RPT_ATTCH:
3824 case RPT_STATE:
3825 case RPT_ADDR:
3826 break;
3828 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3829 default:
3830 xframe = 0;
3831 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3833 rcode = smctr_rcv_unknown(dev, rmf,
3834 &correlator);
3835 if((err = smctr_send_rsp(dev, rmf,rcode,
3836 correlator)))
3838 return (err);
3842 break;
3845 else
3847 /* 1. DA doesn't match (Promiscuous Mode).
3848 * 2. Parse for Extended MAC Frame Type.
3850 switch(rmf->vc)
3852 case RSP:
3853 case INIT:
3854 case RQ_INIT:
3855 case RQ_ADDR:
3856 case RQ_ATTCH:
3857 case RQ_STATE:
3858 case CHG_PARM:
3859 case RPT_ADDR:
3860 case RPT_ERROR:
3861 case RPT_ATTCH:
3862 case RPT_STATE:
3863 case RPT_NEW_MON:
3864 case RPT_SUA_CHG:
3865 case RPT_NN_INCMP:
3866 case RPT_ACTIVE_ERR:
3867 break;
3869 default:
3870 xframe = 0;
3871 break;
3875 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3876 * ACCEPT_ATT_MAC_FRAMES is set.
3878 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
3879 && (xframe == (__u8)0))
3880 || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES)
3881 && (xframe == (__u8)1)))
3883 rmf->vl = SWAP_BYTES(rmf->vl);
3885 if (!(skb = dev_alloc_skb(size)))
3886 return -ENOMEM;
3887 skb->len = size;
3889 /* Slide data into a sleek skb. */
3890 skb_put(skb, skb->len);
3891 skb_copy_to_linear_data(skb, rmf, skb->len);
3893 /* Update Counters */
3894 tp->MacStat.rx_packets++;
3895 tp->MacStat.rx_bytes += skb->len;
3897 /* Kick the packet on up. */
3898 skb->protocol = tr_type_trans(skb, dev);
3899 netif_rx(skb);
3900 dev->last_rx = jiffies;
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
3938 && (~err); 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
3963 && (~err); j += 2)
3965 word_read = *(__u16 *)(pword + j);
3966 if(word_read != word_pattern)
3968 err = (__u8)1;
3969 err_offset = j;
3970 err_word = word_read;
3971 err_pattern = word_pattern;
3972 return (RAM_TEST_FAILED);
3977 smctr_set_page(dev, (__u8 *)tp->ram_access);
3979 return (0);
3982 static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3983 __u16 *correlator)
3985 MAC_SUB_VECTOR *rsv;
3986 signed short vlen;
3987 __u16 rcode = POSITIVE_ACK;
3988 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
3990 /* This Frame can only come from a CRS */
3991 if((rmf->dc_sc & SC_MASK) != SC_CRS)
3992 return(E_INAPPROPRIATE_SOURCE_CLASS);
3994 /* Remove MVID Length from total length. */
3995 vlen = (signed short)rmf->vl - 4;
3997 /* Point to First SVID */
3998 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4000 /* Search for Appropriate SVID's. */
4001 while((vlen > 0) && (rcode == POSITIVE_ACK))
4003 switch(rsv->svi)
4005 case CORRELATOR:
4006 svectors |= F_CORRELATOR;
4007 rcode = smctr_set_corr(dev, rsv, correlator);
4008 break;
4010 case LOCAL_RING_NUMBER:
4011 svectors |= F_LOCAL_RING_NUMBER;
4012 rcode = smctr_set_local_ring_num(dev, rsv);
4013 break;
4015 case ASSIGN_PHYSICAL_DROP:
4016 svectors |= F_ASSIGN_PHYSICAL_DROP;
4017 rcode = smctr_set_phy_drop(dev, rsv);
4018 break;
4020 case ERROR_TIMER_VALUE:
4021 svectors |= F_ERROR_TIMER_VALUE;
4022 rcode = smctr_set_error_timer_value(dev, rsv);
4023 break;
4025 case AUTHORIZED_FUNCTION_CLASS:
4026 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4027 rcode = smctr_set_auth_funct_class(dev, rsv);
4028 break;
4030 case AUTHORIZED_ACCESS_PRIORITY:
4031 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4032 rcode = smctr_set_auth_access_pri(dev, rsv);
4033 break;
4035 default:
4036 rcode = E_SUB_VECTOR_UNKNOWN;
4037 break;
4040 /* Let Sender Know if SUM of SV length's is
4041 * larger then length in MVID length field
4043 if((vlen -= rsv->svl) < 0)
4044 rcode = E_VECTOR_LENGTH_ERROR;
4046 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4049 if(rcode == POSITIVE_ACK)
4051 /* Let Sender Know if MVID length field
4052 * is larger then SUM of SV length's
4054 if(vlen != 0)
4055 rcode = E_VECTOR_LENGTH_ERROR;
4056 else
4058 /* Let Sender Know if Expected SVID Missing */
4059 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4060 rcode = E_MISSING_SUB_VECTOR;
4064 return (rcode);
4067 static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4068 __u16 *correlator)
4070 MAC_SUB_VECTOR *rsv;
4071 signed short vlen;
4072 __u16 rcode = POSITIVE_ACK;
4073 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4075 /* This Frame can only come from a RPS */
4076 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4077 return (E_INAPPROPRIATE_SOURCE_CLASS);
4079 /* Remove MVID Length from total length. */
4080 vlen = (signed short)rmf->vl - 4;
4082 /* Point to First SVID */
4083 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4085 /* Search for Appropriate SVID's */
4086 while((vlen > 0) && (rcode == POSITIVE_ACK))
4088 switch(rsv->svi)
4090 case CORRELATOR:
4091 svectors |= F_CORRELATOR;
4092 rcode = smctr_set_corr(dev, rsv, correlator);
4093 break;
4095 case LOCAL_RING_NUMBER:
4096 svectors |= F_LOCAL_RING_NUMBER;
4097 rcode = smctr_set_local_ring_num(dev, rsv);
4098 break;
4100 case ASSIGN_PHYSICAL_DROP:
4101 svectors |= F_ASSIGN_PHYSICAL_DROP;
4102 rcode = smctr_set_phy_drop(dev, rsv);
4103 break;
4105 case ERROR_TIMER_VALUE:
4106 svectors |= F_ERROR_TIMER_VALUE;
4107 rcode = smctr_set_error_timer_value(dev, rsv);
4108 break;
4110 default:
4111 rcode = E_SUB_VECTOR_UNKNOWN;
4112 break;
4115 /* Let Sender Know if SUM of SV length's is
4116 * larger then length in MVID length field
4118 if((vlen -= rsv->svl) < 0)
4119 rcode = E_VECTOR_LENGTH_ERROR;
4121 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4124 if(rcode == POSITIVE_ACK)
4126 /* Let Sender Know if MVID length field
4127 * is larger then SUM of SV length's
4129 if(vlen != 0)
4130 rcode = E_VECTOR_LENGTH_ERROR;
4131 else
4133 /* Let Sender Know if Expected SV Missing */
4134 if((svectors & R_INIT) ^ R_INIT)
4135 rcode = E_MISSING_SUB_VECTOR;
4139 return (rcode);
4142 static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4144 MAC_SUB_VECTOR *rsv;
4145 signed short vlen;
4146 __u16 rcode = POSITIVE_ACK;
4147 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4149 /* This Frame can only come from a CRS */
4150 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4151 return (E_INAPPROPRIATE_SOURCE_CLASS);
4153 /* Remove MVID Length from total length */
4154 vlen = (signed short)rmf->vl - 4;
4156 /* Point to First SVID */
4157 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4159 /* Search for Appropriate SVID's */
4160 while((vlen > 0) && (rcode == POSITIVE_ACK))
4162 switch(rsv->svi)
4164 case FRAME_FORWARD:
4165 svectors |= F_FRAME_FORWARD;
4166 rcode = smctr_set_frame_forward(dev, rsv,
4167 rmf->dc_sc);
4168 break;
4170 default:
4171 rcode = E_SUB_VECTOR_UNKNOWN;
4172 break;
4175 /* Let Sender Know if SUM of SV length's is
4176 * larger then length in MVID length field
4178 if((vlen -= rsv->svl) < 0)
4179 rcode = E_VECTOR_LENGTH_ERROR;
4181 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4184 if(rcode == POSITIVE_ACK)
4186 /* Let Sender Know if MVID length field
4187 * is larger then SUM of SV length's
4189 if(vlen != 0)
4190 rcode = E_VECTOR_LENGTH_ERROR;
4191 else
4193 /* Let Sender Know if Expected SV Missing */
4194 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4195 rcode = E_MISSING_SUB_VECTOR;
4199 return (rcode);
4202 static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4203 MAC_HEADER *rmf, __u16 *correlator)
4205 MAC_SUB_VECTOR *rsv;
4206 signed short vlen;
4207 __u16 rcode = POSITIVE_ACK;
4208 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4210 /* Remove MVID Length from total length */
4211 vlen = (signed short)rmf->vl - 4;
4213 /* Point to First SVID */
4214 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4216 /* Search for Appropriate SVID's */
4217 while((vlen > 0) && (rcode == POSITIVE_ACK))
4219 switch(rsv->svi)
4221 case CORRELATOR:
4222 svectors |= F_CORRELATOR;
4223 rcode = smctr_set_corr(dev, rsv, correlator);
4224 break;
4226 default:
4227 rcode = E_SUB_VECTOR_UNKNOWN;
4228 break;
4231 /* Let Sender Know if SUM of SV length's is
4232 * larger then length in MVID length field
4234 if((vlen -= rsv->svl) < 0)
4235 rcode = E_VECTOR_LENGTH_ERROR;
4237 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4240 if(rcode == POSITIVE_ACK)
4242 /* Let Sender Know if MVID length field
4243 * is larger then SUM of SV length's
4245 if(vlen != 0)
4246 rcode = E_VECTOR_LENGTH_ERROR;
4247 else
4249 /* Let Sender Know if Expected SVID Missing */
4250 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4251 ^ R_RQ_ATTCH_STATE_ADDR)
4252 rcode = E_MISSING_SUB_VECTOR;
4256 return (rcode);
4259 static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4260 __u16 *correlator)
4262 MAC_SUB_VECTOR *rsv;
4263 signed short vlen;
4265 *correlator = 0;
4267 /* Remove MVID Length from total length */
4268 vlen = (signed short)rmf->vl - 4;
4270 /* Point to First SVID */
4271 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4273 /* Search for CORRELATOR for RSP to UNKNOWN */
4274 while((vlen > 0) && (*correlator == 0))
4276 switch(rsv->svi)
4278 case CORRELATOR:
4279 smctr_set_corr(dev, rsv, correlator);
4280 break;
4282 default:
4283 break;
4286 vlen -= rsv->svl;
4287 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4290 return (E_UNRECOGNIZED_VECTOR_ID);
4294 * Reset the 825 NIC and exit w:
4295 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4296 * 2. TINT masked.
4297 * 3. CBUSY masked.
4298 * 4. TINT clear.
4299 * 5. CBUSY clear.
4301 static int smctr_reset_adapter(struct net_device *dev)
4303 struct net_local *tp = netdev_priv(dev);
4304 int ioaddr = dev->base_addr;
4306 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4307 mdelay(200); /* ~2 ms */
4309 smctr_clear_trc_reset(ioaddr);
4310 mdelay(200); /* ~2 ms */
4312 /* Remove any latched interrupts that occurred prior to reseting the
4313 * adapter or possibily caused by line glitches due to the reset.
4315 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4317 return (0);
4320 static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4322 struct net_local *tp = netdev_priv(dev);
4323 int err = 0;
4325 if(smctr_debug > 10)
4326 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4328 if(tp->num_tx_fcbs_used[queue] != 0
4329 && tp->tx_queue_status[queue] == NOT_TRANSMITING)
4331 tp->tx_queue_status[queue] = TRANSMITING;
4332 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4335 return (err);
4338 static int smctr_ring_status_chg(struct net_device *dev)
4340 struct net_local *tp = netdev_priv(dev);
4342 if(smctr_debug > 10)
4343 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4345 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4346 * Bit is set, check value of monitor_state, only then we
4347 * enable and start transmit/receive timeout (if and only
4348 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4350 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4352 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE)
4353 || (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4355 tp->monitor_state_ready = 1;
4357 else
4359 /* if adapter is NOT in either active monitor
4360 * or standby monitor state => Disable
4361 * transmit/receive timeout.
4363 tp->monitor_state_ready = 0;
4365 /* Ring speed problem, switching to auto mode. */
4366 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE
4367 && !tp->cleanup)
4369 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4370 dev->name);
4371 smctr_set_ring_speed(dev);
4376 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4377 return (0);
4379 switch(tp->ring_status)
4381 case RING_RECOVERY:
4382 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
4383 tp->current_ring_status |= RING_RECOVERY;
4384 break;
4386 case SINGLE_STATION:
4387 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
4388 tp->current_ring_status |= SINGLE_STATION;
4389 break;
4391 case COUNTER_OVERFLOW:
4392 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
4393 tp->current_ring_status |= COUNTER_OVERFLOW;
4394 break;
4396 case REMOVE_RECEIVED:
4397 printk(KERN_INFO "%s: Remove Received\n", dev->name);
4398 tp->current_ring_status |= REMOVE_RECEIVED;
4399 break;
4401 case AUTO_REMOVAL_ERROR:
4402 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
4403 tp->current_ring_status |= AUTO_REMOVAL_ERROR;
4404 break;
4406 case LOBE_WIRE_FAULT:
4407 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
4408 tp->current_ring_status |= LOBE_WIRE_FAULT;
4409 break;
4411 case TRANSMIT_BEACON:
4412 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
4413 tp->current_ring_status |= TRANSMIT_BEACON;
4414 break;
4416 case SOFT_ERROR:
4417 printk(KERN_INFO "%s: Soft Error\n", dev->name);
4418 tp->current_ring_status |= SOFT_ERROR;
4419 break;
4421 case HARD_ERROR:
4422 printk(KERN_INFO "%s: Hard Error\n", dev->name);
4423 tp->current_ring_status |= HARD_ERROR;
4424 break;
4426 case SIGNAL_LOSS:
4427 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
4428 tp->current_ring_status |= SIGNAL_LOSS;
4429 break;
4431 default:
4432 printk(KERN_INFO "%s: Unknown ring status change\n",
4433 dev->name);
4434 break;
4437 return (0);
4440 static int smctr_rx_frame(struct net_device *dev)
4442 struct net_local *tp = netdev_priv(dev);
4443 __u16 queue, status, rx_size, err = 0;
4444 __u8 *pbuff;
4446 if(smctr_debug > 10)
4447 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4449 queue = tp->receive_queue_number;
4451 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4453 err = HARDWARE_FAILED;
4455 if(((status & 0x007f) == 0)
4456 || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4458 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4459 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4461 pbuff = smctr_get_rx_pointer(dev, queue);
4463 smctr_set_page(dev, pbuff);
4464 smctr_disable_16bit(dev);
4466 /* pbuff points to addr within one page */
4467 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4469 if(queue == NON_MAC_QUEUE)
4471 struct sk_buff *skb;
4473 skb = dev_alloc_skb(rx_size);
4474 if (skb) {
4475 skb_put(skb, rx_size);
4477 skb_copy_to_linear_data(skb, pbuff, rx_size);
4479 /* Update Counters */
4480 tp->MacStat.rx_packets++;
4481 tp->MacStat.rx_bytes += skb->len;
4483 /* Kick the packet on up. */
4484 skb->protocol = tr_type_trans(skb, dev);
4485 netif_rx(skb);
4486 dev->last_rx = jiffies;
4487 } else {
4490 else
4491 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4492 rx_size, dev, status);
4495 smctr_enable_16bit(dev);
4496 smctr_set_page(dev, (__u8 *)tp->ram_access);
4497 smctr_update_rx_chain(dev, queue);
4499 if(err != SUCCESS)
4500 break;
4503 return (err);
4506 static int smctr_send_dat(struct net_device *dev)
4508 struct net_local *tp = netdev_priv(dev);
4509 unsigned int i, err;
4510 MAC_HEADER *tmf;
4511 FCBlock *fcb;
4513 if(smctr_debug > 10)
4514 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4516 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4517 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4519 return (OUT_OF_RESOURCES);
4522 /* Initialize DAT Data Fields. */
4523 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4524 tmf->ac = MSB(AC_FC_DAT);
4525 tmf->fc = LSB(AC_FC_DAT);
4527 for(i = 0; i < 6; i++)
4529 tmf->sa[i] = dev->dev_addr[i];
4530 tmf->da[i] = dev->dev_addr[i];
4534 tmf->vc = DAT;
4535 tmf->dc_sc = DC_RS | SC_RS;
4536 tmf->vl = 4;
4537 tmf->vl = SWAP_BYTES(tmf->vl);
4539 /* Start Transmit. */
4540 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4541 return (err);
4543 /* Wait for Transmit to Complete */
4544 for(i = 0; i < 10000; i++)
4546 if(fcb->frame_status & FCB_COMMAND_DONE)
4547 break;
4548 mdelay(1);
4551 /* Check if GOOD frame Tx'ed. */
4552 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4553 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4555 return (INITIALIZE_FAILED);
4558 /* De-allocated Tx FCB and Frame Buffer
4559 * The FCB must be de-allocated manually if executing with
4560 * interrupts disabled, other wise the ISR (LM_Service_Events)
4561 * will de-allocate it when the interrupt occurs.
4563 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4564 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4566 return (0);
4569 static void smctr_timeout(struct net_device *dev)
4572 * If we get here, some higher level has decided we are broken.
4573 * There should really be a "kick me" function call instead.
4575 * Resetting the token ring adapter takes a long time so just
4576 * fake transmission time and go on trying. Our own timeout
4577 * routine is in sktr_timer_chk()
4579 dev->trans_start = jiffies;
4580 netif_wake_queue(dev);
4584 * Gets skb from system, queues it and checks if it can be sent
4586 static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
4588 struct net_local *tp = netdev_priv(dev);
4590 if(smctr_debug > 10)
4591 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4594 * Block a transmit overlap
4597 netif_stop_queue(dev);
4599 if(tp->QueueSkb == 0)
4600 return (1); /* Return with tbusy set: queue full */
4602 tp->QueueSkb--;
4603 skb_queue_tail(&tp->SendSkbQueue, skb);
4604 smctr_hardware_send_packet(dev, tp);
4605 if(tp->QueueSkb > 0)
4606 netif_wake_queue(dev);
4608 return (0);
4611 static int smctr_send_lobe_media_test(struct net_device *dev)
4613 struct net_local *tp = netdev_priv(dev);
4614 MAC_SUB_VECTOR *tsv;
4615 MAC_HEADER *tmf;
4616 FCBlock *fcb;
4617 __u32 i;
4618 int err;
4620 if(smctr_debug > 15)
4621 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4623 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4624 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4626 return (OUT_OF_RESOURCES);
4629 /* Initialize DAT Data Fields. */
4630 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4631 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4632 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4634 for(i = 0; i < 6; i++)
4636 tmf->da[i] = 0;
4637 tmf->sa[i] = dev->dev_addr[i];
4640 tmf->vc = LOBE_MEDIA_TEST;
4641 tmf->dc_sc = DC_RS | SC_RS;
4642 tmf->vl = 4;
4644 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4645 smctr_make_wrap_data(dev, tsv);
4646 tmf->vl += tsv->svl;
4648 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4649 smctr_make_wrap_data(dev, tsv);
4650 tmf->vl += tsv->svl;
4652 /* Start Transmit. */
4653 tmf->vl = SWAP_BYTES(tmf->vl);
4654 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4655 return (err);
4657 /* Wait for Transmit to Complete. (10 ms). */
4658 for(i=0; i < 10000; i++)
4660 if(fcb->frame_status & FCB_COMMAND_DONE)
4661 break;
4662 mdelay(1);
4665 /* Check if GOOD frame Tx'ed */
4666 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4667 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4669 return (LOBE_MEDIA_TEST_FAILED);
4672 /* De-allocated Tx FCB and Frame Buffer
4673 * The FCB must be de-allocated manually if executing with
4674 * interrupts disabled, other wise the ISR (LM_Service_Events)
4675 * will de-allocate it when the interrupt occurs.
4677 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4678 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4680 return (0);
4683 static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4684 __u16 correlator)
4686 MAC_HEADER *tmf;
4687 MAC_SUB_VECTOR *tsv;
4688 FCBlock *fcb;
4690 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4691 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4692 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4693 == (FCBlock *)(-1L))
4695 return (0);
4698 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4699 tmf->vc = RPT_ADDR;
4700 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4701 tmf->vl = 4;
4703 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4705 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4706 smctr_make_corr(dev, tsv, correlator);
4708 tmf->vl += tsv->svl;
4709 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4710 smctr_make_phy_drop_num(dev, tsv);
4712 tmf->vl += tsv->svl;
4713 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4714 smctr_make_upstream_neighbor_addr(dev, tsv);
4716 tmf->vl += tsv->svl;
4717 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4718 smctr_make_addr_mod(dev, tsv);
4720 tmf->vl += tsv->svl;
4721 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4722 smctr_make_group_addr(dev, tsv);
4724 tmf->vl += tsv->svl;
4725 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4726 smctr_make_funct_addr(dev, tsv);
4728 tmf->vl += tsv->svl;
4730 /* Subtract out MVID and MVL which is
4731 * include in both vl and MAC_HEADER
4733 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4734 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4736 tmf->vl = SWAP_BYTES(tmf->vl);
4738 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4741 static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4742 __u16 correlator)
4744 MAC_HEADER *tmf;
4745 MAC_SUB_VECTOR *tsv;
4746 FCBlock *fcb;
4748 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4749 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4750 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4751 == (FCBlock *)(-1L))
4753 return (0);
4756 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4757 tmf->vc = RPT_ATTCH;
4758 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4759 tmf->vl = 4;
4761 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4763 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4764 smctr_make_corr(dev, tsv, correlator);
4766 tmf->vl += tsv->svl;
4767 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4768 smctr_make_product_id(dev, tsv);
4770 tmf->vl += tsv->svl;
4771 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4772 smctr_make_funct_addr(dev, tsv);
4774 tmf->vl += tsv->svl;
4775 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4776 smctr_make_auth_funct_class(dev, tsv);
4778 tmf->vl += tsv->svl;
4779 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4780 smctr_make_access_pri(dev, tsv);
4782 tmf->vl += tsv->svl;
4784 /* Subtract out MVID and MVL which is
4785 * include in both vl and MAC_HEADER
4787 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4788 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4790 tmf->vl = SWAP_BYTES(tmf->vl);
4792 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4795 static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4796 __u16 correlator)
4798 MAC_HEADER *tmf;
4799 MAC_SUB_VECTOR *tsv;
4800 FCBlock *fcb;
4802 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4803 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4804 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4805 == (FCBlock *)(-1L))
4807 return (0);
4810 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4811 tmf->vc = RPT_STATE;
4812 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4813 tmf->vl = 4;
4815 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4817 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4818 smctr_make_corr(dev, tsv, correlator);
4820 tmf->vl += tsv->svl;
4821 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4822 smctr_make_ring_station_version(dev, tsv);
4824 tmf->vl += tsv->svl;
4825 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4826 smctr_make_ring_station_status(dev, tsv);
4828 tmf->vl += tsv->svl;
4829 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4830 smctr_make_station_id(dev, tsv);
4832 tmf->vl += tsv->svl;
4834 /* Subtract out MVID and MVL which is
4835 * include in both vl and MAC_HEADER
4837 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4838 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4840 tmf->vl = SWAP_BYTES(tmf->vl);
4842 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4845 static int smctr_send_rpt_tx_forward(struct net_device *dev,
4846 MAC_HEADER *rmf, __u16 tx_fstatus)
4848 MAC_HEADER *tmf;
4849 MAC_SUB_VECTOR *tsv;
4850 FCBlock *fcb;
4852 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4853 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4855 return (0);
4858 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4859 tmf->vc = RPT_TX_FORWARD;
4860 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4861 tmf->vl = 4;
4863 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4865 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4866 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4868 tmf->vl += tsv->svl;
4870 /* Subtract out MVID and MVL which is
4871 * include in both vl and MAC_HEADER
4873 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4874 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4876 tmf->vl = SWAP_BYTES(tmf->vl);
4878 return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4881 static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4882 __u16 rcode, __u16 correlator)
4884 MAC_HEADER *tmf;
4885 MAC_SUB_VECTOR *tsv;
4886 FCBlock *fcb;
4888 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4889 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4891 return (0);
4894 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4895 tmf->vc = RSP;
4896 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4897 tmf->vl = 4;
4899 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4901 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4902 smctr_make_corr(dev, tsv, correlator);
4904 return (0);
4907 static int smctr_send_rq_init(struct net_device *dev)
4909 struct net_local *tp = netdev_priv(dev);
4910 MAC_HEADER *tmf;
4911 MAC_SUB_VECTOR *tsv;
4912 FCBlock *fcb;
4913 unsigned int i, count = 0;
4914 __u16 fstatus;
4915 int err;
4917 do {
4918 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4919 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4920 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4921 == (FCBlock *)(-1L)))
4923 return (0);
4926 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4927 tmf->vc = RQ_INIT;
4928 tmf->dc_sc = DC_RPS | SC_RS;
4929 tmf->vl = 4;
4931 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4933 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4934 smctr_make_product_id(dev, tsv);
4936 tmf->vl += tsv->svl;
4937 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4938 smctr_make_upstream_neighbor_addr(dev, tsv);
4940 tmf->vl += tsv->svl;
4941 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4942 smctr_make_ring_station_version(dev, tsv);
4944 tmf->vl += tsv->svl;
4945 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4946 smctr_make_addr_mod(dev, tsv);
4948 tmf->vl += tsv->svl;
4950 /* Subtract out MVID and MVL which is
4951 * include in both vl and MAC_HEADER
4953 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4954 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4956 tmf->vl = SWAP_BYTES(tmf->vl);
4958 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4959 return (err);
4961 /* Wait for Transmit to Complete */
4962 for(i = 0; i < 10000; i++)
4964 if(fcb->frame_status & FCB_COMMAND_DONE)
4965 break;
4966 mdelay(1);
4969 /* Check if GOOD frame Tx'ed */
4970 fstatus = fcb->frame_status;
4972 if(!(fstatus & FCB_COMMAND_DONE))
4973 return (HARDWARE_FAILED);
4975 if(!(fstatus & FCB_TX_STATUS_E))
4976 count++;
4978 /* De-allocated Tx FCB and Frame Buffer
4979 * The FCB must be de-allocated manually if executing with
4980 * interrupts disabled, other wise the ISR (LM_Service_Events)
4981 * will de-allocate it when the interrupt occurs.
4983 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4984 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4985 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4987 return (smctr_join_complete_state(dev));
4990 static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4991 __u16 *tx_fstatus)
4993 struct net_local *tp = netdev_priv(dev);
4994 FCBlock *fcb;
4995 unsigned int i;
4996 int err;
4998 /* Check if this is the END POINT of the Transmit Forward Chain. */
4999 if(rmf->vl <= 18)
5000 return (0);
5002 /* Allocate Transmit FCB only by requesting 0 bytes
5003 * of data buffer.
5005 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
5006 return (0);
5008 /* Set pointer to Transmit Frame Buffer to the data
5009 * portion of the received TX Forward frame, making
5010 * sure to skip over the Vector Code (vc) and Vector
5011 * length (vl).
5013 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5014 + sizeof(MAC_HEADER) + 2);
5015 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5016 + sizeof(MAC_HEADER) + 2);
5018 fcb->frame_length = rmf->vl - 4 - 2;
5019 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5021 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5022 return (err);
5024 /* Wait for Transmit to Complete */
5025 for(i = 0; i < 10000; i++)
5027 if(fcb->frame_status & FCB_COMMAND_DONE)
5028 break;
5029 mdelay(1);
5032 /* Check if GOOD frame Tx'ed */
5033 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5035 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5036 return (err);
5038 for(i = 0; i < 10000; i++)
5040 if(fcb->frame_status & FCB_COMMAND_DONE)
5041 break;
5042 mdelay(1);
5045 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5046 return (HARDWARE_FAILED);
5049 *tx_fstatus = fcb->frame_status;
5051 return (A_FRAME_WAS_FORWARDED);
5054 static int smctr_set_auth_access_pri(struct net_device *dev,
5055 MAC_SUB_VECTOR *rsv)
5057 struct net_local *tp = netdev_priv(dev);
5059 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5060 return (E_SUB_VECTOR_LENGTH_ERROR);
5062 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5064 return (POSITIVE_ACK);
5067 static int smctr_set_auth_funct_class(struct net_device *dev,
5068 MAC_SUB_VECTOR *rsv)
5070 struct net_local *tp = netdev_priv(dev);
5072 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5073 return (E_SUB_VECTOR_LENGTH_ERROR);
5075 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5077 return (POSITIVE_ACK);
5080 static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5081 __u16 *correlator)
5083 if(rsv->svl != S_CORRELATOR)
5084 return (E_SUB_VECTOR_LENGTH_ERROR);
5086 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5088 return (POSITIVE_ACK);
5091 static int smctr_set_error_timer_value(struct net_device *dev,
5092 MAC_SUB_VECTOR *rsv)
5094 __u16 err_tval;
5095 int err;
5097 if(rsv->svl != S_ERROR_TIMER_VALUE)
5098 return (E_SUB_VECTOR_LENGTH_ERROR);
5100 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5102 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5104 if((err = smctr_wait_cmd(dev)))
5105 return (err);
5107 return (POSITIVE_ACK);
5110 static int smctr_set_frame_forward(struct net_device *dev,
5111 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5113 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5114 return (E_SUB_VECTOR_LENGTH_ERROR);
5116 if((dc_sc & DC_MASK) != DC_CRS)
5118 if(rsv->svl >= 2 && rsv->svl < 20)
5119 return (E_TRANSMIT_FORWARD_INVALID);
5121 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5122 return (E_TRANSMIT_FORWARD_INVALID);
5125 return (POSITIVE_ACK);
5128 static int smctr_set_local_ring_num(struct net_device *dev,
5129 MAC_SUB_VECTOR *rsv)
5131 struct net_local *tp = netdev_priv(dev);
5133 if(rsv->svl != S_LOCAL_RING_NUMBER)
5134 return (E_SUB_VECTOR_LENGTH_ERROR);
5136 if(tp->ptr_local_ring_num)
5137 *(__u16 *)(tp->ptr_local_ring_num)
5138 = (rsv->svv[0] << 8 | rsv->svv[1]);
5140 return (POSITIVE_ACK);
5143 static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5145 struct net_local *tp = netdev_priv(dev);
5146 int ioaddr = dev->base_addr;
5148 if(tp->bic_type == BIC_585_CHIP)
5149 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5150 else
5152 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5153 outb(tp->trc_mask, ioaddr + CSR);
5156 return (0);
5159 static void smctr_set_multicast_list(struct net_device *dev)
5161 if(smctr_debug > 10)
5162 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5164 return;
5167 static int smctr_set_page(struct net_device *dev, __u8 *buf)
5169 struct net_local *tp = netdev_priv(dev);
5170 __u8 amask;
5171 __u32 tptr;
5173 tptr = (__u32)buf - (__u32)tp->ram_access;
5174 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5175 outb(amask, dev->base_addr + PR);
5177 return (0);
5180 static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5182 int err;
5184 if(rsv->svl != S_PHYSICAL_DROP)
5185 return (E_SUB_VECTOR_LENGTH_ERROR);
5187 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5188 if((err = smctr_wait_cmd(dev)))
5189 return (err);
5191 return (POSITIVE_ACK);
5194 /* Reset the ring speed to the opposite of what it was. This auto-pilot
5195 * mode requires a complete reset and re-init of the adapter.
5197 static int smctr_set_ring_speed(struct net_device *dev)
5199 struct net_local *tp = netdev_priv(dev);
5200 int err;
5202 if(tp->media_type == MEDIA_UTP_16)
5203 tp->media_type = MEDIA_UTP_4;
5204 else
5205 tp->media_type = MEDIA_UTP_16;
5207 smctr_enable_16bit(dev);
5209 /* Re-Initialize adapter's internal registers */
5210 smctr_reset_adapter(dev);
5212 if((err = smctr_init_card_real(dev)))
5213 return (err);
5215 smctr_enable_bic_int(dev);
5217 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5218 return (err);
5220 smctr_disable_16bit(dev);
5222 return (0);
5225 static int smctr_set_rx_look_ahead(struct net_device *dev)
5227 struct net_local *tp = netdev_priv(dev);
5228 __u16 sword, rword;
5230 if(smctr_debug > 10)
5231 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5233 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5234 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5236 if(tp->adapter_bus == BUS_ISA16_TYPE)
5238 sword = *((__u16 *)(tp->ram_access));
5239 *((__u16 *)(tp->ram_access)) = 0x1234;
5241 smctr_disable_16bit(dev);
5242 rword = *((__u16 *)(tp->ram_access));
5243 smctr_enable_16bit(dev);
5245 if(rword != 0x1234)
5246 tp->adapter_flags |= FORCED_16BIT_MODE;
5248 *((__u16 *)(tp->ram_access)) = sword;
5251 return (0);
5254 static int smctr_set_trc_reset(int ioaddr)
5256 __u8 r;
5258 r = inb(ioaddr + MSR);
5259 outb(MSR_RST | r, ioaddr + MSR);
5261 return (0);
5265 * This function can be called if the adapter is busy or not.
5267 static int smctr_setup_single_cmd(struct net_device *dev,
5268 __u16 command, __u16 subcommand)
5270 struct net_local *tp = netdev_priv(dev);
5271 unsigned int err;
5273 if(smctr_debug > 10)
5274 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5276 if((err = smctr_wait_while_cbusy(dev)))
5277 return (err);
5279 if((err = (unsigned int)smctr_wait_cmd(dev)))
5280 return (err);
5282 tp->acb_head->cmd_done_status = 0;
5283 tp->acb_head->cmd = command;
5284 tp->acb_head->subcmd = subcommand;
5286 err = smctr_issue_resume_acb_cmd(dev);
5288 return (err);
5292 * This function can not be called with the adapter busy.
5294 static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5295 __u16 command, __u16 subcommand)
5297 struct net_local *tp = netdev_priv(dev);
5299 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5300 tp->acb_head->cmd = command;
5301 tp->acb_head->subcmd = subcommand;
5302 tp->acb_head->data_offset_lo
5303 = (__u16)TRC_POINTER(tp->misc_command_data);
5305 return(smctr_issue_resume_acb_cmd(dev));
5308 static char *smctr_malloc(struct net_device *dev, __u16 size)
5310 struct net_local *tp = netdev_priv(dev);
5311 char *m;
5313 m = (char *)(tp->ram_access + tp->sh_mem_used);
5314 tp->sh_mem_used += (__u32)size;
5316 return (m);
5319 static int smctr_status_chg(struct net_device *dev)
5321 struct net_local *tp = netdev_priv(dev);
5323 if(smctr_debug > 10)
5324 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5326 switch(tp->status)
5328 case OPEN:
5329 break;
5331 case CLOSED:
5332 break;
5334 /* Interrupt driven open() completion. XXX */
5335 case INITIALIZED:
5336 tp->group_address_0 = 0;
5337 tp->group_address[0] = 0;
5338 tp->group_address[1] = 0;
5339 tp->functional_address_0 = 0;
5340 tp->functional_address[0] = 0;
5341 tp->functional_address[1] = 0;
5342 smctr_open_tr(dev);
5343 break;
5345 default:
5346 printk(KERN_INFO "%s: status change unknown %x\n",
5347 dev->name, tp->status);
5348 break;
5351 return (0);
5354 static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5355 __u16 queue)
5357 struct net_local *tp = netdev_priv(dev);
5358 int err = 0;
5360 if(smctr_debug > 10)
5361 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5363 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5364 if(tp->num_tx_fcbs[queue] != 1)
5365 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5367 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5369 tp->tx_queue_status[queue] = TRANSMITING;
5370 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5373 return (err);
5376 static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5378 struct net_local *tp = netdev_priv(dev);
5379 __u16 status, err = 0;
5380 int cstatus;
5382 if(smctr_debug > 10)
5383 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5385 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5387 if(status & 0x7e00 )
5389 err = HARDWARE_FAILED;
5390 break;
5393 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5394 queue)) != SUCCESS)
5395 break;
5397 smctr_disable_16bit(dev);
5399 if(tp->mode_bits & UMAC)
5401 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5402 cstatus = NO_SUCH_DESTINATION;
5403 else
5405 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5406 cstatus = DEST_OUT_OF_RESOURCES;
5407 else
5409 if(status & FCB_TX_STATUS_E)
5410 cstatus = MAX_COLLISIONS;
5411 else
5412 cstatus = SUCCESS;
5416 else
5417 cstatus = SUCCESS;
5419 if(queue == BUG_QUEUE)
5420 err = SUCCESS;
5422 smctr_enable_16bit(dev);
5423 if(err != SUCCESS)
5424 break;
5427 return (err);
5430 static unsigned short smctr_tx_move_frame(struct net_device *dev,
5431 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5433 struct net_local *tp = netdev_priv(dev);
5434 unsigned int ram_usable;
5435 __u32 flen, len, offset = 0;
5436 __u8 *frag, *page;
5438 if(smctr_debug > 10)
5439 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5441 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5442 frag = skb->data;
5443 flen = skb->len;
5445 while(flen > 0 && bytes > 0)
5447 smctr_set_page(dev, pbuff);
5449 offset = SMC_PAGE_OFFSET(pbuff);
5451 if(offset + flen > ram_usable)
5452 len = ram_usable - offset;
5453 else
5454 len = flen;
5456 if(len > bytes)
5457 len = bytes;
5459 page = (char *) (offset + tp->ram_access);
5460 memcpy(page, frag, len);
5462 flen -=len;
5463 bytes -= len;
5464 frag += len;
5465 pbuff += len;
5468 return (0);
5471 /* Update the error statistic counters for this adapter. */
5472 static int smctr_update_err_stats(struct net_device *dev)
5474 struct net_local *tp = netdev_priv(dev);
5475 struct tr_statistics *tstat = &tp->MacStat;
5477 if(tstat->internal_errors)
5478 tstat->internal_errors
5479 += *(tp->misc_command_data + 0) & 0x00ff;
5481 if(tstat->line_errors)
5482 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5484 if(tstat->A_C_errors)
5485 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5487 if(tstat->burst_errors)
5488 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5490 if(tstat->abort_delimiters)
5491 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5493 if(tstat->recv_congest_count)
5494 tstat->recv_congest_count
5495 += *(tp->misc_command_data + 3) & 0x00ff;
5497 if(tstat->lost_frames)
5498 tstat->lost_frames
5499 += *(tp->misc_command_data + 3) >> 8;
5501 if(tstat->frequency_errors)
5502 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5504 if(tstat->frame_copied_errors)
5505 tstat->frame_copied_errors
5506 += *(tp->misc_command_data + 4) >> 8;
5508 if(tstat->token_errors)
5509 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5511 return (0);
5514 static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5516 struct net_local *tp = netdev_priv(dev);
5517 FCBlock *fcb;
5518 BDBlock *bdb;
5519 __u16 size, len;
5521 fcb = tp->rx_fcb_curr[queue];
5522 len = fcb->frame_length;
5524 fcb->frame_status = 0;
5525 fcb->info = FCB_CHAIN_END;
5526 fcb->back_ptr->info = FCB_WARNING;
5528 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5530 /* update RX BDBs */
5531 size = (len >> RX_BDB_SIZE_SHIFT);
5532 if(len & RX_DATA_BUFFER_SIZE_MASK)
5533 size += sizeof(BDBlock);
5534 size &= (~RX_BDB_SIZE_MASK);
5536 /* check if wrap around */
5537 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5538 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5540 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5541 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5544 bdb->back_ptr->info = BDB_CHAIN_END;
5545 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5546 tp->rx_bdb_curr[queue] = bdb;
5548 return (0);
5551 static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5552 __u16 queue)
5554 struct net_local *tp = netdev_priv(dev);
5556 if(smctr_debug > 20)
5557 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5559 if(tp->num_tx_fcbs_used[queue] <= 0)
5560 return (HARDWARE_FAILED);
5561 else
5563 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5565 tp->tx_buff_used[queue] = 0;
5566 return (HARDWARE_FAILED);
5569 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5571 /* if all transmit buffer are cleared
5572 * need to set the tx_buff_curr[] to tx_buff_head[]
5573 * otherwise, tx buffer will be segregate and cannot
5574 * accommodate and buffer greater than (curr - head) and
5575 * (end - curr) since we do not allow wrap around allocation.
5577 if(tp->tx_buff_used[queue] == 0)
5578 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5580 tp->num_tx_fcbs_used[queue]--;
5581 fcb->frame_status = 0;
5582 tp->tx_fcb_end[queue] = fcb->next_ptr;
5583 netif_wake_queue(dev);
5584 return (0);
5588 static int smctr_wait_cmd(struct net_device *dev)
5590 struct net_local *tp = netdev_priv(dev);
5591 unsigned int loop_count = 0x20000;
5593 if(smctr_debug > 10)
5594 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5596 while(loop_count)
5598 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5599 break;
5600 udelay(1);
5601 loop_count--;
5604 if(loop_count == 0)
5605 return(HARDWARE_FAILED);
5607 if(tp->acb_head->cmd_done_status & 0xff)
5608 return(HARDWARE_FAILED);
5610 return (0);
5613 static int smctr_wait_while_cbusy(struct net_device *dev)
5615 struct net_local *tp = netdev_priv(dev);
5616 unsigned int timeout = 0x20000;
5617 int ioaddr = dev->base_addr;
5618 __u8 r;
5620 if(tp->bic_type == BIC_585_CHIP)
5622 while(timeout)
5624 r = inb(ioaddr + HWR);
5625 if((r & HWR_CBUSY) == 0)
5626 break;
5627 timeout--;
5630 else
5632 while(timeout)
5634 r = inb(ioaddr + CSR);
5635 if((r & CSR_CBUSY) == 0)
5636 break;
5637 timeout--;
5641 if(timeout)
5642 return (0);
5643 else
5644 return (HARDWARE_FAILED);
5647 #ifdef MODULE
5649 static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5650 static int io[SMCTR_MAX_ADAPTERS];
5651 static int irq[SMCTR_MAX_ADAPTERS];
5653 MODULE_LICENSE("GPL");
5655 module_param_array(io, int, NULL, 0);
5656 module_param_array(irq, int, NULL, 0);
5657 module_param(ringspeed, int, 0);
5659 static struct net_device * __init setup_card(int n)
5661 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5662 int err;
5664 if (!dev)
5665 return ERR_PTR(-ENOMEM);
5667 dev->irq = irq[n];
5668 err = smctr_probe1(dev, io[n]);
5669 if (err)
5670 goto out;
5672 err = register_netdev(dev);
5673 if (err)
5674 goto out1;
5675 return dev;
5676 out1:
5677 #ifdef CONFIG_MCA_LEGACY
5678 { struct net_local *tp = netdev_priv(dev);
5679 if (tp->slot_num)
5680 mca_mark_as_unused(tp->slot_num);
5682 #endif
5683 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5684 free_irq(dev->irq, dev);
5685 out:
5686 free_netdev(dev);
5687 return ERR_PTR(err);
5690 int __init init_module(void)
5692 int i, found = 0;
5693 struct net_device *dev;
5695 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5696 dev = io[0]? setup_card(i) : smctr_probe(-1);
5697 if (!IS_ERR(dev)) {
5698 ++found;
5699 dev_smctr[i] = dev;
5703 return found ? 0 : -ENODEV;
5706 void __exit cleanup_module(void)
5708 int i;
5710 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5711 struct net_device *dev = dev_smctr[i];
5713 if (dev) {
5715 unregister_netdev(dev);
5716 #ifdef CONFIG_MCA_LEGACY
5717 { struct net_local *tp = netdev_priv(dev);
5718 if (tp->slot_num)
5719 mca_mark_as_unused(tp->slot_num);
5721 #endif
5722 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5723 if (dev->irq)
5724 free_irq(dev->irq, dev);
5726 free_netdev(dev);
5730 #endif /* MODULE */