2 * smctr.c: A network driver for the SMC Token Ring Adapters.
4 * Written by Jay Schulist <jschlst@samba.org>
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
9 * This device driver works with the following SMC adapters:
10 * - SMC TokenCard Elite (8115T, chips 825/584)
11 * - SMC TokenCard Elite/A MCA (8115T/A, chips 825/594)
14 * - SMC TokenCard SDK.
17 * JS Jay Schulist <jschlst@samba.org>
20 * 07102000 JS Fixed a timing problem in smctr_wait_cmd();
21 * Also added a bit more discriptive error msgs.
22 * 07122000 JS Fixed problem with detecting a card with
23 * module io/irq/mem specified.
26 * 1. Multicast support.
28 * Initial 2.5 cleanup Alan Cox <alan@lxorguk.ukuu.org.uk> 2002/10/28
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/fcntl.h>
35 #include <linux/interrupt.h>
36 #include <linux/ptrace.h>
37 #include <linux/ioport.h>
39 #include <linux/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>
51 #include <linux/firmware.h>
53 #include <asm/system.h>
58 #if BITS_PER_LONG == 64
59 #error FIXME: driver does not support 64-bit platforms
62 #include "smctr.h" /* Our Stuff */
64 static const char version
[] __initdata
=
65 KERN_INFO
"smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
66 static const char cardname
[] = "smctr";
69 #define SMCTR_IO_EXTENT 20
71 #ifdef CONFIG_MCA_LEGACY
72 static unsigned int smctr_posid
= 0x6ec6;
77 /* SMC Name of the Adapter. */
78 static char smctr_name
[] = "SMC TokenCard";
79 static char *smctr_model
= "Unknown";
81 /* Use 0 for production, 1 for verification, 2 for debug, and
82 * 3 for very verbose debug.
87 static unsigned int smctr_debug
= SMCTR_DEBUG
;
89 /* smctr.c prototypes and functions are arranged alphabeticly
90 * for clearity, maintainability and pure old fashion fun.
93 static int smctr_alloc_shared_memory(struct net_device
*dev
);
96 static int smctr_bypass_state(struct net_device
*dev
);
99 static int smctr_checksum_firmware(struct net_device
*dev
);
100 static int __init
smctr_chk_isa(struct net_device
*dev
);
101 static int smctr_chg_rx_mask(struct net_device
*dev
);
102 static int smctr_clear_int(struct net_device
*dev
);
103 static int smctr_clear_trc_reset(int ioaddr
);
104 static int smctr_close(struct net_device
*dev
);
107 static int smctr_decode_firmware(struct net_device
*dev
,
108 const struct firmware
*fw
);
109 static int smctr_disable_16bit(struct net_device
*dev
);
110 static int smctr_disable_adapter_ctrl_store(struct net_device
*dev
);
111 static int smctr_disable_bic_int(struct net_device
*dev
);
114 static int smctr_enable_16bit(struct net_device
*dev
);
115 static int smctr_enable_adapter_ctrl_store(struct net_device
*dev
);
116 static int smctr_enable_adapter_ram(struct net_device
*dev
);
117 static int smctr_enable_bic_int(struct net_device
*dev
);
120 static int __init
smctr_get_boardid(struct net_device
*dev
, int mca
);
121 static int smctr_get_group_address(struct net_device
*dev
);
122 static int smctr_get_functional_address(struct net_device
*dev
);
123 static unsigned int smctr_get_num_rx_bdbs(struct net_device
*dev
);
124 static int smctr_get_physical_drop_number(struct net_device
*dev
);
125 static __u8
*smctr_get_rx_pointer(struct net_device
*dev
, short queue
);
126 static int smctr_get_station_id(struct net_device
*dev
);
127 static FCBlock
*smctr_get_tx_fcb(struct net_device
*dev
, __u16 queue
,
129 static int smctr_get_upstream_neighbor_addr(struct net_device
*dev
);
132 static int smctr_hardware_send_packet(struct net_device
*dev
,
133 struct net_local
*tp
);
135 static int smctr_init_acbs(struct net_device
*dev
);
136 static int smctr_init_adapter(struct net_device
*dev
);
137 static int smctr_init_card_real(struct net_device
*dev
);
138 static int smctr_init_rx_bdbs(struct net_device
*dev
);
139 static int smctr_init_rx_fcbs(struct net_device
*dev
);
140 static int smctr_init_shared_memory(struct net_device
*dev
);
141 static int smctr_init_tx_bdbs(struct net_device
*dev
);
142 static int smctr_init_tx_fcbs(struct net_device
*dev
);
143 static int smctr_internal_self_test(struct net_device
*dev
);
144 static irqreturn_t
smctr_interrupt(int irq
, void *dev_id
);
145 static int smctr_issue_enable_int_cmd(struct net_device
*dev
,
146 __u16 interrupt_enable_mask
);
147 static int smctr_issue_int_ack(struct net_device
*dev
, __u16 iack_code
,
149 static int smctr_issue_init_timers_cmd(struct net_device
*dev
);
150 static int smctr_issue_init_txrx_cmd(struct net_device
*dev
);
151 static int smctr_issue_insert_cmd(struct net_device
*dev
);
152 static int smctr_issue_read_ring_status_cmd(struct net_device
*dev
);
153 static int smctr_issue_read_word_cmd(struct net_device
*dev
, __u16 aword_cnt
);
154 static int smctr_issue_remove_cmd(struct net_device
*dev
);
155 static int smctr_issue_resume_acb_cmd(struct net_device
*dev
);
156 static int smctr_issue_resume_rx_bdb_cmd(struct net_device
*dev
, __u16 queue
);
157 static int smctr_issue_resume_rx_fcb_cmd(struct net_device
*dev
, __u16 queue
);
158 static int smctr_issue_resume_tx_fcb_cmd(struct net_device
*dev
, __u16 queue
);
159 static int smctr_issue_test_internal_rom_cmd(struct net_device
*dev
);
160 static int smctr_issue_test_hic_cmd(struct net_device
*dev
);
161 static int smctr_issue_test_mac_reg_cmd(struct net_device
*dev
);
162 static int smctr_issue_trc_loopback_cmd(struct net_device
*dev
);
163 static int smctr_issue_tri_loopback_cmd(struct net_device
*dev
);
164 static int smctr_issue_write_byte_cmd(struct net_device
*dev
,
165 short aword_cnt
, void *byte
);
166 static int smctr_issue_write_word_cmd(struct net_device
*dev
,
167 short aword_cnt
, void *word
);
170 static int smctr_join_complete_state(struct net_device
*dev
);
173 static int smctr_link_tx_fcbs_to_bdbs(struct net_device
*dev
);
174 static int smctr_load_firmware(struct net_device
*dev
);
175 static int smctr_load_node_addr(struct net_device
*dev
);
176 static int smctr_lobe_media_test(struct net_device
*dev
);
177 static int smctr_lobe_media_test_cmd(struct net_device
*dev
);
178 static int smctr_lobe_media_test_state(struct net_device
*dev
);
181 static int smctr_make_8025_hdr(struct net_device
*dev
,
182 MAC_HEADER
*rmf
, MAC_HEADER
*tmf
, __u16 ac_fc
);
183 static int smctr_make_access_pri(struct net_device
*dev
,
184 MAC_SUB_VECTOR
*tsv
);
185 static int smctr_make_addr_mod(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
);
186 static int smctr_make_auth_funct_class(struct net_device
*dev
,
187 MAC_SUB_VECTOR
*tsv
);
188 static int smctr_make_corr(struct net_device
*dev
,
189 MAC_SUB_VECTOR
*tsv
, __u16 correlator
);
190 static int smctr_make_funct_addr(struct net_device
*dev
,
191 MAC_SUB_VECTOR
*tsv
);
192 static int smctr_make_group_addr(struct net_device
*dev
,
193 MAC_SUB_VECTOR
*tsv
);
194 static int smctr_make_phy_drop_num(struct net_device
*dev
,
195 MAC_SUB_VECTOR
*tsv
);
196 static int smctr_make_product_id(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
);
197 static int smctr_make_station_id(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
);
198 static int smctr_make_ring_station_status(struct net_device
*dev
,
199 MAC_SUB_VECTOR
*tsv
);
200 static int smctr_make_ring_station_version(struct net_device
*dev
,
201 MAC_SUB_VECTOR
*tsv
);
202 static int smctr_make_tx_status_code(struct net_device
*dev
,
203 MAC_SUB_VECTOR
*tsv
, __u16 tx_fstatus
);
204 static int smctr_make_upstream_neighbor_addr(struct net_device
*dev
,
205 MAC_SUB_VECTOR
*tsv
);
206 static int smctr_make_wrap_data(struct net_device
*dev
,
207 MAC_SUB_VECTOR
*tsv
);
210 static int smctr_open(struct net_device
*dev
);
211 static int smctr_open_tr(struct net_device
*dev
);
214 struct net_device
*smctr_probe(int unit
);
215 static int __init
smctr_probe1(struct net_device
*dev
, int ioaddr
);
216 static int smctr_process_rx_packet(MAC_HEADER
*rmf
, __u16 size
,
217 struct net_device
*dev
, __u16 rx_status
);
220 static int smctr_ram_memory_test(struct net_device
*dev
);
221 static int smctr_rcv_chg_param(struct net_device
*dev
, MAC_HEADER
*rmf
,
223 static int smctr_rcv_init(struct net_device
*dev
, MAC_HEADER
*rmf
,
225 static int smctr_rcv_tx_forward(struct net_device
*dev
, MAC_HEADER
*rmf
);
226 static int smctr_rcv_rq_addr_state_attch(struct net_device
*dev
,
227 MAC_HEADER
*rmf
, __u16
*correlator
);
228 static int smctr_rcv_unknown(struct net_device
*dev
, MAC_HEADER
*rmf
,
230 static int smctr_reset_adapter(struct net_device
*dev
);
231 static int smctr_restart_tx_chain(struct net_device
*dev
, short queue
);
232 static int smctr_ring_status_chg(struct net_device
*dev
);
233 static int smctr_rx_frame(struct net_device
*dev
);
236 static int smctr_send_dat(struct net_device
*dev
);
237 static netdev_tx_t
smctr_send_packet(struct sk_buff
*skb
,
238 struct net_device
*dev
);
239 static int smctr_send_lobe_media_test(struct net_device
*dev
);
240 static int smctr_send_rpt_addr(struct net_device
*dev
, MAC_HEADER
*rmf
,
242 static int smctr_send_rpt_attch(struct net_device
*dev
, MAC_HEADER
*rmf
,
244 static int smctr_send_rpt_state(struct net_device
*dev
, MAC_HEADER
*rmf
,
246 static int smctr_send_rpt_tx_forward(struct net_device
*dev
,
247 MAC_HEADER
*rmf
, __u16 tx_fstatus
);
248 static int smctr_send_rsp(struct net_device
*dev
, MAC_HEADER
*rmf
,
249 __u16 rcode
, __u16 correlator
);
250 static int smctr_send_rq_init(struct net_device
*dev
);
251 static int smctr_send_tx_forward(struct net_device
*dev
, MAC_HEADER
*rmf
,
253 static int smctr_set_auth_access_pri(struct net_device
*dev
,
254 MAC_SUB_VECTOR
*rsv
);
255 static int smctr_set_auth_funct_class(struct net_device
*dev
,
256 MAC_SUB_VECTOR
*rsv
);
257 static int smctr_set_corr(struct net_device
*dev
, MAC_SUB_VECTOR
*rsv
,
259 static int smctr_set_error_timer_value(struct net_device
*dev
,
260 MAC_SUB_VECTOR
*rsv
);
261 static int smctr_set_frame_forward(struct net_device
*dev
,
262 MAC_SUB_VECTOR
*rsv
, __u8 dc_sc
);
263 static int smctr_set_local_ring_num(struct net_device
*dev
,
264 MAC_SUB_VECTOR
*rsv
);
265 static unsigned short smctr_set_ctrl_attention(struct net_device
*dev
);
266 static void smctr_set_multicast_list(struct net_device
*dev
);
267 static int smctr_set_page(struct net_device
*dev
, __u8
*buf
);
268 static int smctr_set_phy_drop(struct net_device
*dev
,
269 MAC_SUB_VECTOR
*rsv
);
270 static int smctr_set_ring_speed(struct net_device
*dev
);
271 static int smctr_set_rx_look_ahead(struct net_device
*dev
);
272 static int smctr_set_trc_reset(int ioaddr
);
273 static int smctr_setup_single_cmd(struct net_device
*dev
,
274 __u16 command
, __u16 subcommand
);
275 static int smctr_setup_single_cmd_w_data(struct net_device
*dev
,
276 __u16 command
, __u16 subcommand
);
277 static char *smctr_malloc(struct net_device
*dev
, __u16 size
);
278 static int smctr_status_chg(struct net_device
*dev
);
281 static void smctr_timeout(struct net_device
*dev
);
282 static int smctr_trc_send_packet(struct net_device
*dev
, FCBlock
*fcb
,
284 static __u16
smctr_tx_complete(struct net_device
*dev
, __u16 queue
);
285 static unsigned short smctr_tx_move_frame(struct net_device
*dev
,
286 struct sk_buff
*skb
, __u8
*pbuff
, unsigned int bytes
);
289 static int smctr_update_err_stats(struct net_device
*dev
);
290 static int smctr_update_rx_chain(struct net_device
*dev
, __u16 queue
);
291 static int smctr_update_tx_chain(struct net_device
*dev
, FCBlock
*fcb
,
295 static int smctr_wait_cmd(struct net_device
*dev
);
296 static int smctr_wait_while_cbusy(struct net_device
*dev
);
298 #define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
299 #define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
300 #define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
302 /* Allocate Adapter Shared Memory.
303 * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
304 * function "get_num_rx_bdbs" below!!!
306 * Order of memory allocation:
308 * 0. Initial System Configuration Block Pointer
309 * 1. System Configuration Block
310 * 2. System Control Block
311 * 3. Action Command Block
312 * 4. Interrupt Status Block
315 * 6. NON-MAC TX FCB'S
317 * 8. NON-MAC TX BDB'S
319 * 10. NON-MAC RX FCB'S
321 * 12. NON-MAC RX BDB'S
322 * 13. MAC TX Data Buffer( 1, 256 byte buffer)
323 * 14. MAC RX Data Buffer( 1, 256 byte buffer)
325 * 15. NON-MAC TX Data Buffer
326 * 16. NON-MAC RX Data Buffer
328 static int smctr_alloc_shared_memory(struct net_device
*dev
)
330 struct net_local
*tp
= netdev_priv(dev
);
333 printk(KERN_DEBUG
"%s: smctr_alloc_shared_memory\n", dev
->name
);
335 /* Allocate initial System Control Block pointer.
336 * This pointer is located in the last page, last offset - 4.
338 tp
->iscpb_ptr
= (ISCPBlock
*)(tp
->ram_access
+ ((__u32
)64 * 0x400)
339 - (long)ISCP_BLOCK_SIZE
);
341 /* Allocate System Control Blocks. */
342 tp
->scgb_ptr
= (SCGBlock
*)smctr_malloc(dev
, sizeof(SCGBlock
));
343 PARAGRAPH_BOUNDRY(tp
->sh_mem_used
);
345 tp
->sclb_ptr
= (SCLBlock
*)smctr_malloc(dev
, sizeof(SCLBlock
));
346 PARAGRAPH_BOUNDRY(tp
->sh_mem_used
);
348 tp
->acb_head
= (ACBlock
*)smctr_malloc(dev
,
349 sizeof(ACBlock
)*tp
->num_acbs
);
350 PARAGRAPH_BOUNDRY(tp
->sh_mem_used
);
352 tp
->isb_ptr
= (ISBlock
*)smctr_malloc(dev
, sizeof(ISBlock
));
353 PARAGRAPH_BOUNDRY(tp
->sh_mem_used
);
355 tp
->misc_command_data
= (__u16
*)smctr_malloc(dev
, MISC_DATA_SIZE
);
356 PARAGRAPH_BOUNDRY(tp
->sh_mem_used
);
358 /* Allocate transmit FCBs. */
359 tp
->tx_fcb_head
[MAC_QUEUE
] = (FCBlock
*)smctr_malloc(dev
,
360 sizeof(FCBlock
) * tp
->num_tx_fcbs
[MAC_QUEUE
]);
362 tp
->tx_fcb_head
[NON_MAC_QUEUE
] = (FCBlock
*)smctr_malloc(dev
,
363 sizeof(FCBlock
) * tp
->num_tx_fcbs
[NON_MAC_QUEUE
]);
365 tp
->tx_fcb_head
[BUG_QUEUE
] = (FCBlock
*)smctr_malloc(dev
,
366 sizeof(FCBlock
) * tp
->num_tx_fcbs
[BUG_QUEUE
]);
368 /* Allocate transmit BDBs. */
369 tp
->tx_bdb_head
[MAC_QUEUE
] = (BDBlock
*)smctr_malloc(dev
,
370 sizeof(BDBlock
) * tp
->num_tx_bdbs
[MAC_QUEUE
]);
372 tp
->tx_bdb_head
[NON_MAC_QUEUE
] = (BDBlock
*)smctr_malloc(dev
,
373 sizeof(BDBlock
) * tp
->num_tx_bdbs
[NON_MAC_QUEUE
]);
375 tp
->tx_bdb_head
[BUG_QUEUE
] = (BDBlock
*)smctr_malloc(dev
,
376 sizeof(BDBlock
) * tp
->num_tx_bdbs
[BUG_QUEUE
]);
378 /* Allocate receive FCBs. */
379 tp
->rx_fcb_head
[MAC_QUEUE
] = (FCBlock
*)smctr_malloc(dev
,
380 sizeof(FCBlock
) * tp
->num_rx_fcbs
[MAC_QUEUE
]);
382 tp
->rx_fcb_head
[NON_MAC_QUEUE
] = (FCBlock
*)smctr_malloc(dev
,
383 sizeof(FCBlock
) * tp
->num_rx_fcbs
[NON_MAC_QUEUE
]);
385 /* Allocate receive BDBs. */
386 tp
->rx_bdb_head
[MAC_QUEUE
] = (BDBlock
*)smctr_malloc(dev
,
387 sizeof(BDBlock
) * tp
->num_rx_bdbs
[MAC_QUEUE
]);
389 tp
->rx_bdb_end
[MAC_QUEUE
] = (BDBlock
*)smctr_malloc(dev
, 0);
391 tp
->rx_bdb_head
[NON_MAC_QUEUE
] = (BDBlock
*)smctr_malloc(dev
,
392 sizeof(BDBlock
) * tp
->num_rx_bdbs
[NON_MAC_QUEUE
]);
394 tp
->rx_bdb_end
[NON_MAC_QUEUE
] = (BDBlock
*)smctr_malloc(dev
, 0);
396 /* Allocate MAC transmit buffers.
397 * MAC Tx Buffers doen't have to be on an ODD Boundry.
399 tp
->tx_buff_head
[MAC_QUEUE
]
400 = (__u16
*)smctr_malloc(dev
, tp
->tx_buff_size
[MAC_QUEUE
]);
401 tp
->tx_buff_curr
[MAC_QUEUE
] = tp
->tx_buff_head
[MAC_QUEUE
];
402 tp
->tx_buff_end
[MAC_QUEUE
] = (__u16
*)smctr_malloc(dev
, 0);
404 /* Allocate BUG transmit buffers. */
405 tp
->tx_buff_head
[BUG_QUEUE
]
406 = (__u16
*)smctr_malloc(dev
, tp
->tx_buff_size
[BUG_QUEUE
]);
407 tp
->tx_buff_curr
[BUG_QUEUE
] = tp
->tx_buff_head
[BUG_QUEUE
];
408 tp
->tx_buff_end
[BUG_QUEUE
] = (__u16
*)smctr_malloc(dev
, 0);
410 /* Allocate MAC receive data buffers.
411 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
413 tp
->rx_buff_head
[MAC_QUEUE
] = (__u16
*)smctr_malloc(dev
,
414 RX_DATA_BUFFER_SIZE
* tp
->num_rx_bdbs
[MAC_QUEUE
]);
415 tp
->rx_buff_end
[MAC_QUEUE
] = (__u16
*)smctr_malloc(dev
, 0);
417 /* Allocate Non-MAC transmit buffers.
418 * ?? For maximum Netware performance, put Tx Buffers on
419 * ODD Boundry and then restore malloc to Even Boundrys.
421 smctr_malloc(dev
, 1L);
422 tp
->tx_buff_head
[NON_MAC_QUEUE
]
423 = (__u16
*)smctr_malloc(dev
, tp
->tx_buff_size
[NON_MAC_QUEUE
]);
424 tp
->tx_buff_curr
[NON_MAC_QUEUE
] = tp
->tx_buff_head
[NON_MAC_QUEUE
];
425 tp
->tx_buff_end
[NON_MAC_QUEUE
] = (__u16
*)smctr_malloc(dev
, 0);
426 smctr_malloc(dev
, 1L);
428 /* Allocate Non-MAC receive data buffers.
429 * To guarantee a minimum of 256 contigous memory to
430 * UM_Receive_Packet's lookahead pointer, before a page
431 * change or ring end is encountered, place each rx buffer on
432 * a 256 byte boundary.
434 smctr_malloc(dev
, TO_256_BYTE_BOUNDRY(tp
->sh_mem_used
));
435 tp
->rx_buff_head
[NON_MAC_QUEUE
] = (__u16
*)smctr_malloc(dev
,
436 RX_DATA_BUFFER_SIZE
* tp
->num_rx_bdbs
[NON_MAC_QUEUE
]);
437 tp
->rx_buff_end
[NON_MAC_QUEUE
] = (__u16
*)smctr_malloc(dev
, 0);
442 /* Enter Bypass state. */
443 static int smctr_bypass_state(struct net_device
*dev
)
448 printk(KERN_DEBUG
"%s: smctr_bypass_state\n", dev
->name
);
450 err
= smctr_setup_single_cmd(dev
, ACB_CMD_CHANGE_JOIN_STATE
, JS_BYPASS_STATE
);
455 static int smctr_checksum_firmware(struct net_device
*dev
)
457 struct net_local
*tp
= netdev_priv(dev
);
458 __u16 i
, checksum
= 0;
461 printk(KERN_DEBUG
"%s: smctr_checksum_firmware\n", dev
->name
);
463 smctr_enable_adapter_ctrl_store(dev
);
465 for(i
= 0; i
< CS_RAM_SIZE
; i
+= 2)
466 checksum
+= *((__u16
*)(tp
->ram_access
+ i
));
468 tp
->microcode_version
= *(__u16
*)(tp
->ram_access
469 + CS_RAM_VERSION_OFFSET
);
470 tp
->microcode_version
>>= 8;
472 smctr_disable_adapter_ctrl_store(dev
);
480 static int __init
smctr_chk_mca(struct net_device
*dev
)
482 #ifdef CONFIG_MCA_LEGACY
483 struct net_local
*tp
= netdev_priv(dev
);
485 __u8 r1
, r2
, r3
, r4
, r5
;
487 current_slot
= mca_find_unused_adapter(smctr_posid
, 0);
488 if(current_slot
== MCA_NOTFOUND
)
491 mca_set_adapter_name(current_slot
, smctr_name
);
492 mca_mark_as_used(current_slot
);
493 tp
->slot_num
= current_slot
;
495 r1
= mca_read_stored_pos(tp
->slot_num
, 2);
496 r2
= mca_read_stored_pos(tp
->slot_num
, 3);
499 outb(CNFG_POS_CONTROL_REG
, (__u8
)((tp
->slot_num
- 1) | CNFG_SLOT_ENABLE_BIT
));
501 outb(CNFG_POS_CONTROL_REG
, (__u8
)((tp
->slot_num
) | CNFG_SLOT_ENABLE_BIT
));
503 r1
= inb(CNFG_POS_REG1
);
504 r2
= inb(CNFG_POS_REG0
);
506 tp
->bic_type
= BIC_594_CHIP
;
509 r2
= mca_read_stored_pos(tp
->slot_num
, 2);
511 dev
->base_addr
= ((__u16
)r2
<< 8) + (__u16
)0x800;
512 request_region(dev
->base_addr
, SMCTR_IO_EXTENT
, smctr_name
);
515 r5
= mca_read_stored_pos(tp
->slot_num
, 5);
535 if (request_irq(dev
->irq
, smctr_interrupt
, IRQF_SHARED
, smctr_name
, dev
)) {
536 release_region(dev
->base_addr
, SMCTR_IO_EXTENT
);
541 r3
= mca_read_stored_pos(tp
->slot_num
, 3);
542 tp
->ram_base
= ((__u32
)(r3
& 0x7) << 13) + 0x0C0000;
544 tp
->ram_base
+= 0x010000;
546 tp
->ram_base
+= 0xF00000;
552 tp
->ram_usable
= (__u16
)CNFG_SIZE_8KB
<< r3
;
553 tp
->ram_size
= (__u16
)CNFG_SIZE_64KB
;
554 tp
->board_id
|= TOKEN_MEDIA
;
556 r4
= mca_read_stored_pos(tp
->slot_num
, 4);
557 tp
->rom_base
= ((__u32
)(r4
& 0x7) << 13) + 0x0C0000;
559 tp
->rom_base
+= 0x010000;
565 tp
->rom_size
= CNFG_SIZE_8KB
;
568 tp
->rom_size
= CNFG_SIZE_16KB
;
571 tp
->rom_size
= CNFG_SIZE_32KB
;
574 tp
->rom_size
= ROM_DISABLE
;
577 /* Get Media Type. */
578 r5
= mca_read_stored_pos(tp
->slot_num
, 5);
579 r5
&= CNFG_MEDIA_TYPE_MASK
;
583 tp
->media_type
= MEDIA_STP_4
;
587 tp
->media_type
= MEDIA_STP_16
;
591 tp
->media_type
= MEDIA_UTP_16
;
595 tp
->media_type
= MEDIA_UTP_4
;
600 r2
= mca_read_stored_pos(tp
->slot_num
, 2);
602 tp
->mode_bits
|= EARLY_TOKEN_REL
;
605 outb(CNFG_POS_CONTROL_REG
, 0);
607 tp
->board_id
= smctr_get_boardid(dev
, 1);
608 switch(tp
->board_id
& 0xffff)
611 smctr_model
= "8115T/A";
615 if(tp
->extra_info
& CHIP_REV_MASK
)
616 smctr_model
= "8115T rev XE";
618 smctr_model
= "8115T rev XD";
622 smctr_model
= "Unknown";
629 #endif /* CONFIG_MCA_LEGACY */
632 static int smctr_chg_rx_mask(struct net_device
*dev
)
634 struct net_local
*tp
= netdev_priv(dev
);
638 printk(KERN_DEBUG
"%s: smctr_chg_rx_mask\n", dev
->name
);
640 smctr_enable_16bit(dev
);
641 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
643 if(tp
->mode_bits
& LOOPING_MODE_MASK
)
644 tp
->config_word0
|= RX_OWN_BIT
;
646 tp
->config_word0
&= ~RX_OWN_BIT
;
648 if(tp
->receive_mask
& PROMISCUOUS_MODE
)
649 tp
->config_word0
|= PROMISCUOUS_BIT
;
651 tp
->config_word0
&= ~PROMISCUOUS_BIT
;
653 if(tp
->receive_mask
& ACCEPT_ERR_PACKETS
)
654 tp
->config_word0
|= SAVBAD_BIT
;
656 tp
->config_word0
&= ~SAVBAD_BIT
;
658 if(tp
->receive_mask
& ACCEPT_ATT_MAC_FRAMES
)
659 tp
->config_word0
|= RXATMAC
;
661 tp
->config_word0
&= ~RXATMAC
;
663 if(tp
->receive_mask
& ACCEPT_MULTI_PROM
)
664 tp
->config_word1
|= MULTICAST_ADDRESS_BIT
;
666 tp
->config_word1
&= ~MULTICAST_ADDRESS_BIT
;
668 if(tp
->receive_mask
& ACCEPT_SOURCE_ROUTING_SPANNING
)
669 tp
->config_word1
|= SOURCE_ROUTING_SPANNING_BITS
;
672 if(tp
->receive_mask
& ACCEPT_SOURCE_ROUTING
)
673 tp
->config_word1
|= SOURCE_ROUTING_EXPLORER_BIT
;
675 tp
->config_word1
&= ~SOURCE_ROUTING_SPANNING_BITS
;
678 if((err
= smctr_issue_write_word_cmd(dev
, RW_CONFIG_REGISTER_0
,
684 if((err
= smctr_issue_write_word_cmd(dev
, RW_CONFIG_REGISTER_1
,
690 smctr_disable_16bit(dev
);
695 static int smctr_clear_int(struct net_device
*dev
)
697 struct net_local
*tp
= netdev_priv(dev
);
699 outb((tp
->trc_mask
| CSR_CLRTINT
), dev
->base_addr
+ CSR
);
704 static int smctr_clear_trc_reset(int ioaddr
)
708 r
= inb(ioaddr
+ MSR
);
709 outb(~MSR_RST
& r
, ioaddr
+ MSR
);
715 * The inverse routine to smctr_open().
717 static int smctr_close(struct net_device
*dev
)
719 struct net_local
*tp
= netdev_priv(dev
);
723 netif_stop_queue(dev
);
727 /* Check to see if adapter is already in a closed state. */
728 if(tp
->status
!= OPEN
)
731 smctr_enable_16bit(dev
);
732 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
734 if((err
= smctr_issue_remove_cmd(dev
)))
736 smctr_disable_16bit(dev
);
742 skb
= skb_dequeue(&tp
->SendSkbQueue
);
753 static int smctr_decode_firmware(struct net_device
*dev
,
754 const struct firmware
*fw
)
756 struct net_local
*tp
= netdev_priv(dev
);
757 short bit
= 0x80, shift
= 12;
758 DECODE_TREE_NODE
*tree
;
766 printk(KERN_DEBUG
"%s: smctr_decode_firmware\n", dev
->name
);
768 weight
= *(long *)(fw
->data
+ WEIGHT_OFFSET
);
769 tsize
= *(__u8
*)(fw
->data
+ TREE_SIZE_OFFSET
);
770 tree
= (DECODE_TREE_NODE
*)(fw
->data
+ TREE_OFFSET
);
771 ucode
= (__u8
*)(fw
->data
+ TREE_OFFSET
772 + (tsize
* sizeof(DECODE_TREE_NODE
)));
773 mem
= (__u16
*)(tp
->ram_access
);
778 while((tree
+ branch
)->tag
!= LEAF
&& weight
)
780 branch
= *ucode
& bit
? (tree
+ branch
)->llink
781 : (tree
+ branch
)->rlink
;
793 buff
|= (tree
+ branch
)->info
<< shift
;
798 *(mem
++) = SWAP_BYTES(buff
);
804 /* The following assumes the Control Store Memory has
805 * been initialized to zero. If the last partial word
806 * is zero, it will not be written.
809 *(mem
++) = SWAP_BYTES(buff
);
814 static int smctr_disable_16bit(struct net_device
*dev
)
820 * On Exit, Adapter is:
821 * 1. TRC is in a reset state and un-initialized.
822 * 2. Adapter memory is enabled.
823 * 3. Control Store memory is out of context (-WCSS is 1).
825 static int smctr_disable_adapter_ctrl_store(struct net_device
*dev
)
827 struct net_local
*tp
= netdev_priv(dev
);
828 int ioaddr
= dev
->base_addr
;
831 printk(KERN_DEBUG
"%s: smctr_disable_adapter_ctrl_store\n", dev
->name
);
833 tp
->trc_mask
|= CSR_WCSS
;
834 outb(tp
->trc_mask
, ioaddr
+ CSR
);
839 static int smctr_disable_bic_int(struct net_device
*dev
)
841 struct net_local
*tp
= netdev_priv(dev
);
842 int ioaddr
= dev
->base_addr
;
844 tp
->trc_mask
= CSR_MSK_ALL
| CSR_MSKCBUSY
845 | CSR_MSKTINT
| CSR_WCSS
;
846 outb(tp
->trc_mask
, ioaddr
+ CSR
);
851 static int smctr_enable_16bit(struct net_device
*dev
)
853 struct net_local
*tp
= netdev_priv(dev
);
856 if(tp
->adapter_bus
== BUS_ISA16_TYPE
)
858 r
= inb(dev
->base_addr
+ LAAR
);
859 outb((r
| LAAR_MEM16ENB
), dev
->base_addr
+ LAAR
);
866 * To enable the adapter control store memory:
867 * 1. Adapter must be in a RESET state.
868 * 2. Adapter memory must be enabled.
869 * 3. Control Store Memory is in context (-WCSS is 0).
871 static int smctr_enable_adapter_ctrl_store(struct net_device
*dev
)
873 struct net_local
*tp
= netdev_priv(dev
);
874 int ioaddr
= dev
->base_addr
;
877 printk(KERN_DEBUG
"%s: smctr_enable_adapter_ctrl_store\n", dev
->name
);
879 smctr_set_trc_reset(ioaddr
);
880 smctr_enable_adapter_ram(dev
);
882 tp
->trc_mask
&= ~CSR_WCSS
;
883 outb(tp
->trc_mask
, ioaddr
+ CSR
);
888 static int smctr_enable_adapter_ram(struct net_device
*dev
)
890 int ioaddr
= dev
->base_addr
;
894 printk(KERN_DEBUG
"%s: smctr_enable_adapter_ram\n", dev
->name
);
896 r
= inb(ioaddr
+ MSR
);
897 outb(MSR_MEMB
| r
, ioaddr
+ MSR
);
902 static int smctr_enable_bic_int(struct net_device
*dev
)
904 struct net_local
*tp
= netdev_priv(dev
);
905 int ioaddr
= dev
->base_addr
;
911 tp
->trc_mask
= CSR_MSKCBUSY
| CSR_WCSS
;
912 outb(tp
->trc_mask
, ioaddr
+ CSR
);
913 r
= inb(ioaddr
+ IRR
);
914 outb(r
| IRR_IEN
, ioaddr
+ IRR
);
918 tp
->trc_mask
= CSR_MSKCBUSY
| CSR_WCSS
;
919 outb(tp
->trc_mask
, ioaddr
+ CSR
);
920 r
= inb(ioaddr
+ IMCCR
);
921 outb(r
| IMCCR_EIL
, ioaddr
+ IMCCR
);
928 static int __init
smctr_chk_isa(struct net_device
*dev
)
930 struct net_local
*tp
= netdev_priv(dev
);
931 int ioaddr
= dev
->base_addr
;
932 __u8 r1
, r2
, b
, chksum
= 0;
938 printk(KERN_DEBUG
"%s: smctr_chk_isa %#4x\n", dev
->name
, ioaddr
);
940 if((ioaddr
& 0x1F) != 0)
943 /* Grab the region so that no one else tries to probe our ioports. */
944 if (!request_region(ioaddr
, SMCTR_IO_EXTENT
, smctr_name
)) {
949 /* Checksum SMC node address */
950 for(i
= 0; i
< 8; i
++)
952 b
= inb(ioaddr
+ LAR0
+ i
);
956 if (chksum
!= NODE_ADDR_CKSUM
)
959 b
= inb(ioaddr
+ BDID
);
960 if(b
!= BRD_ID_8115T
)
962 printk(KERN_ERR
"%s: The adapter found is not supported\n", dev
->name
);
966 /* Check for 8115T Board ID */
968 for(r
= 0; r
< 8; r
++)
970 r1
= inb(ioaddr
+ 0x8 + r
);
974 /* value of RegF adds up the sum to 0xFF */
975 if((r2
!= 0xFF) && (r2
!= 0xEE))
979 tp
->board_id
= smctr_get_boardid(dev
, 0);
980 switch(tp
->board_id
& 0xffff)
983 smctr_model
= "8115T/A";
987 if(tp
->extra_info
& CHIP_REV_MASK
)
988 smctr_model
= "8115T rev XE";
990 smctr_model
= "8115T rev XD";
994 smctr_model
= "Unknown";
998 /* Store BIC type. */
999 tp
->bic_type
= BIC_584_CHIP
;
1000 tp
->nic_type
= NIC_825_CHIP
;
1003 tp
->ram_usable
= CNFG_SIZE_16KB
;
1004 tp
->ram_size
= CNFG_SIZE_64KB
;
1006 /* Get 58x Ram Base */
1010 r2
= inb(ioaddr
+ CNFG_LAAR_584
);
1011 r2
&= CNFG_LAAR_MASK
;
1013 r2
|= ((r1
& 0x38) >> 3);
1015 tp
->ram_base
= ((__u32
)r2
<< 16) + (((__u32
)(r1
& 0x7)) << 13);
1019 r1
= inb(ioaddr
+ CNFG_ICR_583
);
1020 r1
&= CNFG_ICR_IR2_584
;
1022 r2
= inb(ioaddr
+ CNFG_IRR_583
);
1023 r2
&= CNFG_IRR_IRQS
; /* 0x60 */
1045 if(tp
->extra_info
& ALTERNATE_IRQ_BIT
)
1062 printk(KERN_ERR
"%s: No IRQ found aborting\n", dev
->name
);
1066 if (request_irq(dev
->irq
, smctr_interrupt
, IRQF_SHARED
, smctr_name
, dev
))
1069 /* Get 58x Rom Base */
1070 r1
= inb(ioaddr
+ CNFG_BIO_583
);
1074 tp
->rom_base
= (__u32
)r1
<< 13;
1076 /* Get 58x Rom Size */
1077 r1
= inb(ioaddr
+ CNFG_BIO_583
);
1080 tp
->rom_size
= ROM_DISABLE
;
1084 tp
->rom_size
= (__u16
)CNFG_SIZE_8KB
<< r1
;
1087 /* Get 58x Boot Status */
1088 r1
= inb(ioaddr
+ CNFG_GP2
);
1090 tp
->mode_bits
&= (~BOOT_STATUS_MASK
);
1092 if(r1
& CNFG_GP2_BOOT_NIBBLE
)
1093 tp
->mode_bits
|= BOOT_TYPE_1
;
1095 /* Get 58x Zero Wait State */
1096 tp
->mode_bits
&= (~ZERO_WAIT_STATE_MASK
);
1098 r1
= inb(ioaddr
+ CNFG_IRR_583
);
1100 if(r1
& CNFG_IRR_ZWS
)
1101 tp
->mode_bits
|= ZERO_WAIT_STATE_8_BIT
;
1103 if(tp
->board_id
& BOARD_16BIT
)
1105 r1
= inb(ioaddr
+ CNFG_LAAR_584
);
1107 if(r1
& CNFG_LAAR_ZWS
)
1108 tp
->mode_bits
|= ZERO_WAIT_STATE_16_BIT
;
1111 /* Get 584 Media Menu */
1112 tp
->media_menu
= 14;
1113 r1
= inb(ioaddr
+ CNFG_IRR_583
);
1115 tp
->mode_bits
&= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1116 if((tp
->board_id
& TOKEN_MEDIA
) == TOKEN_MEDIA
)
1118 /* Get Advanced Features */
1119 if(((r1
& 0x6) >> 1) == 0x3)
1120 tp
->media_type
|= MEDIA_UTP_16
;
1123 if(((r1
& 0x6) >> 1) == 0x2)
1124 tp
->media_type
|= MEDIA_STP_16
;
1127 if(((r1
& 0x6) >> 1) == 0x1)
1128 tp
->media_type
|= MEDIA_UTP_4
;
1131 tp
->media_type
|= MEDIA_STP_4
;
1135 r1
= inb(ioaddr
+ CNFG_GP2
);
1136 if(!(r1
& 0x2) ) /* GP2_ETRD */
1137 tp
->mode_bits
|= EARLY_TOKEN_REL
;
1139 /* see if the chip is corrupted
1140 if(smctr_read_584_chksum(ioaddr))
1142 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1143 free_irq(dev->irq, dev);
1152 release_region(ioaddr
, SMCTR_IO_EXTENT
);
1157 static int __init
smctr_get_boardid(struct net_device
*dev
, int mca
)
1159 struct net_local
*tp
= netdev_priv(dev
);
1160 int ioaddr
= dev
->base_addr
;
1164 tp
->board_id
= BoardIdMask
= 0;
1168 BoardIdMask
|= (MICROCHANNEL
+INTERFACE_CHIP
+TOKEN_MEDIA
+PAGED_RAM
+BOARD_16BIT
);
1169 tp
->extra_info
|= (INTERFACE_594_CHIP
+RAM_SIZE_64K
+NIC_825_BIT
+ALTERNATE_IRQ_BIT
+SLOT_16BIT
);
1173 BoardIdMask
|=(INTERFACE_CHIP
+TOKEN_MEDIA
+PAGED_RAM
+BOARD_16BIT
);
1174 tp
->extra_info
|= (INTERFACE_584_CHIP
+ RAM_SIZE_64K
1175 + NIC_825_BIT
+ ALTERNATE_IRQ_BIT
);
1180 r
= inb(ioaddr
+ BID_REG_1
);
1182 outb(r
, ioaddr
+ BID_REG_1
);
1183 r
= inb(ioaddr
+ BID_REG_1
);
1185 if(r
& BID_SIXTEEN_BIT_BIT
)
1187 tp
->extra_info
|= SLOT_16BIT
;
1188 tp
->adapter_bus
= BUS_ISA16_TYPE
;
1191 tp
->adapter_bus
= BUS_ISA8_TYPE
;
1194 tp
->adapter_bus
= BUS_MCA_TYPE
;
1196 /* Get Board Id Byte */
1197 IdByte
= inb(ioaddr
+ BID_BOARD_ID_BYTE
);
1199 /* if Major version > 1.0 then
1205 r1
= inb(ioaddr
+ BID_REG_1
);
1207 r1
|= BID_OTHER_BIT
;
1209 outb(r1
, ioaddr
+ BID_REG_1
);
1210 r1
= inb(ioaddr
+ BID_REG_3
);
1213 r1
|= BID_ENGR_PAGE
;
1215 outb(r1
, ioaddr
+ BID_REG_3
);
1216 r1
= inb(ioaddr
+ BID_REG_1
);
1218 r1
|= (BID_RLA
| BID_OTHER_BIT
);
1220 outb(r1
, ioaddr
+ BID_REG_1
);
1222 r1
= inb(ioaddr
+ BID_REG_1
);
1223 while(r1
& BID_RECALL_DONE_MASK
)
1224 r1
= inb(ioaddr
+ BID_REG_1
);
1226 r
= inb(ioaddr
+ BID_LAR_0
+ BID_REG_6
);
1228 /* clear chip rev bits */
1229 tp
->extra_info
&= ~CHIP_REV_MASK
;
1230 tp
->extra_info
|= ((r
& BID_EEPROM_CHIP_REV_MASK
) << 6);
1232 r1
= inb(ioaddr
+ BID_REG_1
);
1234 r1
|= BID_OTHER_BIT
;
1236 outb(r1
, ioaddr
+ BID_REG_1
);
1237 r1
= inb(ioaddr
+ BID_REG_3
);
1242 outb(r1
, ioaddr
+ BID_REG_3
);
1243 r1
= inb(ioaddr
+ BID_REG_1
);
1248 outb(r1
, ioaddr
+ BID_REG_1
);
1249 r1
= inb(ioaddr
+ BID_REG_1
);
1251 while(r1
& BID_RECALL_DONE_MASK
)
1252 r1
= inb(ioaddr
+ BID_REG_1
);
1254 return (BoardIdMask
);
1257 static int smctr_get_group_address(struct net_device
*dev
)
1259 smctr_issue_read_word_cmd(dev
, RW_INDIVIDUAL_GROUP_ADDR
);
1261 return(smctr_wait_cmd(dev
));
1264 static int smctr_get_functional_address(struct net_device
*dev
)
1266 smctr_issue_read_word_cmd(dev
, RW_FUNCTIONAL_ADDR
);
1268 return(smctr_wait_cmd(dev
));
1271 /* Calculate number of Non-MAC receive BDB's and data buffers.
1272 * This function must simulate allocateing shared memory exactly
1273 * as the allocate_shared_memory function above.
1275 static unsigned int smctr_get_num_rx_bdbs(struct net_device
*dev
)
1277 struct net_local
*tp
= netdev_priv(dev
);
1278 unsigned int mem_used
= 0;
1280 /* Allocate System Control Blocks. */
1281 mem_used
+= sizeof(SCGBlock
);
1283 mem_used
+= TO_PARAGRAPH_BOUNDRY(mem_used
);
1284 mem_used
+= sizeof(SCLBlock
);
1286 mem_used
+= TO_PARAGRAPH_BOUNDRY(mem_used
);
1287 mem_used
+= sizeof(ACBlock
) * tp
->num_acbs
;
1289 mem_used
+= TO_PARAGRAPH_BOUNDRY(mem_used
);
1290 mem_used
+= sizeof(ISBlock
);
1292 mem_used
+= TO_PARAGRAPH_BOUNDRY(mem_used
);
1293 mem_used
+= MISC_DATA_SIZE
;
1295 /* Allocate transmit FCB's. */
1296 mem_used
+= TO_PARAGRAPH_BOUNDRY(mem_used
);
1298 mem_used
+= sizeof(FCBlock
) * tp
->num_tx_fcbs
[MAC_QUEUE
];
1299 mem_used
+= sizeof(FCBlock
) * tp
->num_tx_fcbs
[NON_MAC_QUEUE
];
1300 mem_used
+= sizeof(FCBlock
) * tp
->num_tx_fcbs
[BUG_QUEUE
];
1302 /* Allocate transmit BDBs. */
1303 mem_used
+= sizeof(BDBlock
) * tp
->num_tx_bdbs
[MAC_QUEUE
];
1304 mem_used
+= sizeof(BDBlock
) * tp
->num_tx_bdbs
[NON_MAC_QUEUE
];
1305 mem_used
+= sizeof(BDBlock
) * tp
->num_tx_bdbs
[BUG_QUEUE
];
1307 /* Allocate receive FCBs. */
1308 mem_used
+= sizeof(FCBlock
) * tp
->num_rx_fcbs
[MAC_QUEUE
];
1309 mem_used
+= sizeof(FCBlock
) * tp
->num_rx_fcbs
[NON_MAC_QUEUE
];
1311 /* Allocate receive BDBs. */
1312 mem_used
+= sizeof(BDBlock
) * tp
->num_rx_bdbs
[MAC_QUEUE
];
1314 /* Allocate MAC transmit buffers.
1315 * MAC transmit buffers don't have to be on an ODD Boundry.
1317 mem_used
+= tp
->tx_buff_size
[MAC_QUEUE
];
1319 /* Allocate BUG transmit buffers. */
1320 mem_used
+= tp
->tx_buff_size
[BUG_QUEUE
];
1322 /* Allocate MAC receive data buffers.
1323 * MAC receive buffers don't have to be on a 256 byte boundary.
1325 mem_used
+= RX_DATA_BUFFER_SIZE
* tp
->num_rx_bdbs
[MAC_QUEUE
];
1327 /* Allocate Non-MAC transmit buffers.
1328 * For maximum Netware performance, put Tx Buffers on
1329 * ODD Boundry,and then restore malloc to Even Boundrys.
1332 mem_used
+= tp
->tx_buff_size
[NON_MAC_QUEUE
];
1335 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1336 * AND NON-MAC RX DATA BUFFERS
1338 * Make sure the mem_used offset at this point is the
1339 * same as in allocate_shared memory or the following
1340 * boundary adjustment will be incorrect (i.e. not allocating
1341 * the non-mac receive buffers above cannot change the 256
1344 * Since this cannot be guaranteed, adding the full 256 bytes
1345 * to the amount of shared memory used at this point will guaranteed
1346 * that the rx data buffers do not overflow shared memory.
1350 return((0xffff - mem_used
) / (RX_DATA_BUFFER_SIZE
+ sizeof(BDBlock
)));
1353 static int smctr_get_physical_drop_number(struct net_device
*dev
)
1355 smctr_issue_read_word_cmd(dev
, RW_PHYSICAL_DROP_NUMBER
);
1357 return(smctr_wait_cmd(dev
));
1360 static __u8
* smctr_get_rx_pointer(struct net_device
*dev
, short queue
)
1362 struct net_local
*tp
= netdev_priv(dev
);
1365 bdb
= (BDBlock
*)((__u32
)tp
->ram_access
1366 + (__u32
)(tp
->rx_fcb_curr
[queue
]->trc_bdb_ptr
));
1368 tp
->rx_fcb_curr
[queue
]->bdb_ptr
= bdb
;
1370 return ((__u8
*)bdb
->data_block_ptr
);
1373 static int smctr_get_station_id(struct net_device
*dev
)
1375 smctr_issue_read_word_cmd(dev
, RW_INDIVIDUAL_MAC_ADDRESS
);
1377 return(smctr_wait_cmd(dev
));
1381 * Get the current statistics. This may be called with the card open
1384 static struct net_device_stats
*smctr_get_stats(struct net_device
*dev
)
1386 struct net_local
*tp
= netdev_priv(dev
);
1388 return ((struct net_device_stats
*)&tp
->MacStat
);
1391 static FCBlock
*smctr_get_tx_fcb(struct net_device
*dev
, __u16 queue
,
1394 struct net_local
*tp
= netdev_priv(dev
);
1397 unsigned short alloc_size
;
1398 unsigned short *temp
;
1400 if(smctr_debug
> 20)
1401 printk(KERN_DEBUG
"smctr_get_tx_fcb\n");
1403 /* check if there is enough FCB blocks */
1404 if(tp
->num_tx_fcbs_used
[queue
] >= tp
->num_tx_fcbs
[queue
])
1405 return ((FCBlock
*)(-1L));
1407 /* round off the input pkt size to the nearest even number */
1408 alloc_size
= (bytes_count
+ 1) & 0xfffe;
1410 /* check if enough mem */
1411 if((tp
->tx_buff_used
[queue
] + alloc_size
) > tp
->tx_buff_size
[queue
])
1412 return ((FCBlock
*)(-1L));
1414 /* check if past the end ;
1415 * if exactly enough mem to end of ring, alloc from front.
1416 * this avoids update of curr when curr = end
1418 if(((unsigned long)(tp
->tx_buff_curr
[queue
]) + alloc_size
)
1419 >= (unsigned long)(tp
->tx_buff_end
[queue
]))
1421 /* check if enough memory from ring head */
1422 alloc_size
= alloc_size
+
1423 (__u16
)((__u32
)tp
->tx_buff_end
[queue
]
1424 - (__u32
)tp
->tx_buff_curr
[queue
]);
1426 if((tp
->tx_buff_used
[queue
] + alloc_size
)
1427 > tp
->tx_buff_size
[queue
])
1429 return ((FCBlock
*)(-1L));
1433 tp
->tx_buff_curr
[queue
] = tp
->tx_buff_head
[queue
];
1436 tp
->tx_buff_used
[queue
] += alloc_size
;
1437 tp
->num_tx_fcbs_used
[queue
]++;
1438 tp
->tx_fcb_curr
[queue
]->frame_length
= bytes_count
;
1439 tp
->tx_fcb_curr
[queue
]->memory_alloc
= alloc_size
;
1440 temp
= tp
->tx_buff_curr
[queue
];
1441 tp
->tx_buff_curr
[queue
]
1442 = (__u16
*)((__u32
)temp
+ (__u32
)((bytes_count
+ 1) & 0xfffe));
1444 pbdb
= tp
->tx_fcb_curr
[queue
]->bdb_ptr
;
1445 pbdb
->buffer_length
= bytes_count
;
1446 pbdb
->data_block_ptr
= temp
;
1447 pbdb
->trc_data_block_ptr
= TRC_POINTER(temp
);
1449 pFCB
= tp
->tx_fcb_curr
[queue
];
1450 tp
->tx_fcb_curr
[queue
] = tp
->tx_fcb_curr
[queue
]->next_ptr
;
1455 static int smctr_get_upstream_neighbor_addr(struct net_device
*dev
)
1457 smctr_issue_read_word_cmd(dev
, RW_UPSTREAM_NEIGHBOR_ADDRESS
);
1459 return(smctr_wait_cmd(dev
));
1462 static int smctr_hardware_send_packet(struct net_device
*dev
,
1463 struct net_local
*tp
)
1465 struct tr_statistics
*tstat
= &tp
->MacStat
;
1466 struct sk_buff
*skb
;
1469 if(smctr_debug
> 10)
1470 printk(KERN_DEBUG
"%s: smctr_hardware_send_packet\n", dev
->name
);
1472 if(tp
->status
!= OPEN
)
1475 if(tp
->monitor_state_ready
!= 1)
1480 /* Send first buffer from queue */
1481 skb
= skb_dequeue(&tp
->SendSkbQueue
);
1487 if(skb
->len
< SMC_HEADER_SIZE
|| skb
->len
> tp
->max_packet_size
) return (-1);
1489 smctr_enable_16bit(dev
);
1490 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
1492 if((fcb
= smctr_get_tx_fcb(dev
, NON_MAC_QUEUE
, skb
->len
))
1493 == (FCBlock
*)(-1L))
1495 smctr_disable_16bit(dev
);
1499 smctr_tx_move_frame(dev
, skb
,
1500 (__u8
*)fcb
->bdb_ptr
->data_block_ptr
, skb
->len
);
1502 smctr_set_page(dev
, (__u8
*)fcb
);
1504 smctr_trc_send_packet(dev
, fcb
, NON_MAC_QUEUE
);
1507 tstat
->tx_packets
++;
1509 smctr_disable_16bit(dev
);
1515 static int smctr_init_acbs(struct net_device
*dev
)
1517 struct net_local
*tp
= netdev_priv(dev
);
1521 if(smctr_debug
> 10)
1522 printk(KERN_DEBUG
"%s: smctr_init_acbs\n", dev
->name
);
1525 acb
->cmd_done_status
= (ACB_COMMAND_DONE
| ACB_COMMAND_SUCCESSFUL
);
1526 acb
->cmd_info
= ACB_CHAIN_END
;
1529 acb
->data_offset_lo
= 0;
1530 acb
->data_offset_hi
= 0;
1532 = (ACBlock
*)(((char *)acb
) + sizeof(ACBlock
));
1533 acb
->trc_next_ptr
= TRC_POINTER(acb
->next_ptr
);
1535 for(i
= 1; i
< tp
->num_acbs
; i
++)
1537 acb
= acb
->next_ptr
;
1538 acb
->cmd_done_status
1539 = (ACB_COMMAND_DONE
| ACB_COMMAND_SUCCESSFUL
);
1540 acb
->cmd_info
= ACB_CHAIN_END
;
1543 acb
->data_offset_lo
= 0;
1544 acb
->data_offset_hi
= 0;
1546 = (ACBlock
*)(((char *)acb
) + sizeof(ACBlock
));
1547 acb
->trc_next_ptr
= TRC_POINTER(acb
->next_ptr
);
1550 acb
->next_ptr
= tp
->acb_head
;
1551 acb
->trc_next_ptr
= TRC_POINTER(tp
->acb_head
);
1552 tp
->acb_next
= tp
->acb_head
->next_ptr
;
1553 tp
->acb_curr
= tp
->acb_head
->next_ptr
;
1554 tp
->num_acbs_used
= 0;
1559 static int smctr_init_adapter(struct net_device
*dev
)
1561 struct net_local
*tp
= netdev_priv(dev
);
1564 if(smctr_debug
> 10)
1565 printk(KERN_DEBUG
"%s: smctr_init_adapter\n", dev
->name
);
1567 tp
->status
= CLOSED
;
1568 tp
->page_offset_mask
= (tp
->ram_usable
* 1024) - 1;
1569 skb_queue_head_init(&tp
->SendSkbQueue
);
1570 tp
->QueueSkb
= MAX_TX_QUEUE
;
1572 if(!(tp
->group_address_0
& 0x0080))
1573 tp
->group_address_0
|= 0x00C0;
1575 if(!(tp
->functional_address_0
& 0x00C0))
1576 tp
->functional_address_0
|= 0x00C0;
1578 tp
->functional_address
[0] &= 0xFF7F;
1580 if(tp
->authorized_function_classes
== 0)
1581 tp
->authorized_function_classes
= 0x7FFF;
1583 if(tp
->authorized_access_priority
== 0)
1584 tp
->authorized_access_priority
= 0x06;
1586 smctr_disable_bic_int(dev
);
1587 smctr_set_trc_reset(dev
->base_addr
);
1589 smctr_enable_16bit(dev
);
1590 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
1592 if(smctr_checksum_firmware(dev
))
1594 printk(KERN_ERR
"%s: Previously loaded firmware is missing\n",dev
->name
); return (-ENOENT
);
1597 if((err
= smctr_ram_memory_test(dev
)))
1599 printk(KERN_ERR
"%s: RAM memory test failed.\n", dev
->name
);
1603 smctr_set_rx_look_ahead(dev
);
1604 smctr_load_node_addr(dev
);
1606 /* Initialize adapter for Internal Self Test. */
1607 smctr_reset_adapter(dev
);
1608 if((err
= smctr_init_card_real(dev
)))
1610 printk(KERN_ERR
"%s: Initialization of card failed (%d)\n",
1615 /* This routine clobbers the TRC's internal registers. */
1616 if((err
= smctr_internal_self_test(dev
)))
1618 printk(KERN_ERR
"%s: Card failed internal self test (%d)\n",
1623 /* Re-Initialize adapter's internal registers */
1624 smctr_reset_adapter(dev
);
1625 if((err
= smctr_init_card_real(dev
)))
1627 printk(KERN_ERR
"%s: Initialization of card failed (%d)\n",
1632 smctr_enable_bic_int(dev
);
1634 if((err
= smctr_issue_enable_int_cmd(dev
, TRC_INTERRUPT_ENABLE_MASK
)))
1637 smctr_disable_16bit(dev
);
1642 static int smctr_init_card_real(struct net_device
*dev
)
1644 struct net_local
*tp
= netdev_priv(dev
);
1647 if(smctr_debug
> 10)
1648 printk(KERN_DEBUG
"%s: smctr_init_card_real\n", dev
->name
);
1650 tp
->sh_mem_used
= 0;
1651 tp
->num_acbs
= NUM_OF_ACBS
;
1653 /* Range Check Max Packet Size */
1654 if(tp
->max_packet_size
< 256)
1655 tp
->max_packet_size
= 256;
1658 if(tp
->max_packet_size
> NON_MAC_TX_BUFFER_MEMORY
)
1659 tp
->max_packet_size
= NON_MAC_TX_BUFFER_MEMORY
;
1662 tp
->num_of_tx_buffs
= (NON_MAC_TX_BUFFER_MEMORY
1663 / tp
->max_packet_size
) - 1;
1665 if(tp
->num_of_tx_buffs
> NUM_NON_MAC_TX_FCBS
)
1666 tp
->num_of_tx_buffs
= NUM_NON_MAC_TX_FCBS
;
1669 if(tp
->num_of_tx_buffs
== 0)
1670 tp
->num_of_tx_buffs
= 1;
1673 /* Tx queue constants */
1674 tp
->num_tx_fcbs
[BUG_QUEUE
] = NUM_BUG_TX_FCBS
;
1675 tp
->num_tx_bdbs
[BUG_QUEUE
] = NUM_BUG_TX_BDBS
;
1676 tp
->tx_buff_size
[BUG_QUEUE
] = BUG_TX_BUFFER_MEMORY
;
1677 tp
->tx_buff_used
[BUG_QUEUE
] = 0;
1678 tp
->tx_queue_status
[BUG_QUEUE
] = NOT_TRANSMITING
;
1680 tp
->num_tx_fcbs
[MAC_QUEUE
] = NUM_MAC_TX_FCBS
;
1681 tp
->num_tx_bdbs
[MAC_QUEUE
] = NUM_MAC_TX_BDBS
;
1682 tp
->tx_buff_size
[MAC_QUEUE
] = MAC_TX_BUFFER_MEMORY
;
1683 tp
->tx_buff_used
[MAC_QUEUE
] = 0;
1684 tp
->tx_queue_status
[MAC_QUEUE
] = NOT_TRANSMITING
;
1686 tp
->num_tx_fcbs
[NON_MAC_QUEUE
] = NUM_NON_MAC_TX_FCBS
;
1687 tp
->num_tx_bdbs
[NON_MAC_QUEUE
] = NUM_NON_MAC_TX_BDBS
;
1688 tp
->tx_buff_size
[NON_MAC_QUEUE
] = NON_MAC_TX_BUFFER_MEMORY
;
1689 tp
->tx_buff_used
[NON_MAC_QUEUE
] = 0;
1690 tp
->tx_queue_status
[NON_MAC_QUEUE
] = NOT_TRANSMITING
;
1692 /* Receive Queue Constants */
1693 tp
->num_rx_fcbs
[MAC_QUEUE
] = NUM_MAC_RX_FCBS
;
1694 tp
->num_rx_bdbs
[MAC_QUEUE
] = NUM_MAC_RX_BDBS
;
1696 if(tp
->extra_info
& CHIP_REV_MASK
)
1697 tp
->num_rx_fcbs
[NON_MAC_QUEUE
] = 78; /* 825 Rev. XE */
1699 tp
->num_rx_fcbs
[NON_MAC_QUEUE
] = 7; /* 825 Rev. XD */
1701 tp
->num_rx_bdbs
[NON_MAC_QUEUE
] = smctr_get_num_rx_bdbs(dev
);
1703 smctr_alloc_shared_memory(dev
);
1704 smctr_init_shared_memory(dev
);
1706 if((err
= smctr_issue_init_timers_cmd(dev
)))
1709 if((err
= smctr_issue_init_txrx_cmd(dev
)))
1711 printk(KERN_ERR
"%s: Hardware failure\n", dev
->name
);
1718 static int smctr_init_rx_bdbs(struct net_device
*dev
)
1720 struct net_local
*tp
= netdev_priv(dev
);
1725 if(smctr_debug
> 10)
1726 printk(KERN_DEBUG
"%s: smctr_init_rx_bdbs\n", dev
->name
);
1728 for(i
= 0; i
< NUM_RX_QS_USED
; i
++)
1730 bdb
= tp
->rx_bdb_head
[i
];
1731 buf
= tp
->rx_buff_head
[i
];
1732 bdb
->info
= (BDB_CHAIN_END
| BDB_NO_WARNING
);
1733 bdb
->buffer_length
= RX_DATA_BUFFER_SIZE
;
1734 bdb
->next_ptr
= (BDBlock
*)(((char *)bdb
) + sizeof(BDBlock
));
1735 bdb
->data_block_ptr
= buf
;
1736 bdb
->trc_next_ptr
= TRC_POINTER(bdb
->next_ptr
);
1738 if(i
== NON_MAC_QUEUE
)
1739 bdb
->trc_data_block_ptr
= RX_BUFF_TRC_POINTER(buf
);
1741 bdb
->trc_data_block_ptr
= TRC_POINTER(buf
);
1743 for(j
= 1; j
< tp
->num_rx_bdbs
[i
]; j
++)
1745 bdb
->next_ptr
->back_ptr
= bdb
;
1746 bdb
= bdb
->next_ptr
;
1747 buf
= (__u16
*)((char *)buf
+ RX_DATA_BUFFER_SIZE
);
1748 bdb
->info
= (BDB_NOT_CHAIN_END
| BDB_NO_WARNING
);
1749 bdb
->buffer_length
= RX_DATA_BUFFER_SIZE
;
1750 bdb
->next_ptr
= (BDBlock
*)(((char *)bdb
) + sizeof(BDBlock
));
1751 bdb
->data_block_ptr
= buf
;
1752 bdb
->trc_next_ptr
= TRC_POINTER(bdb
->next_ptr
);
1754 if(i
== NON_MAC_QUEUE
)
1755 bdb
->trc_data_block_ptr
= RX_BUFF_TRC_POINTER(buf
);
1757 bdb
->trc_data_block_ptr
= TRC_POINTER(buf
);
1760 bdb
->next_ptr
= tp
->rx_bdb_head
[i
];
1761 bdb
->trc_next_ptr
= TRC_POINTER(tp
->rx_bdb_head
[i
]);
1763 tp
->rx_bdb_head
[i
]->back_ptr
= bdb
;
1764 tp
->rx_bdb_curr
[i
] = tp
->rx_bdb_head
[i
]->next_ptr
;
1770 static int smctr_init_rx_fcbs(struct net_device
*dev
)
1772 struct net_local
*tp
= netdev_priv(dev
);
1776 for(i
= 0; i
< NUM_RX_QS_USED
; i
++)
1778 fcb
= tp
->rx_fcb_head
[i
];
1779 fcb
->frame_status
= 0;
1780 fcb
->frame_length
= 0;
1781 fcb
->info
= FCB_CHAIN_END
;
1782 fcb
->next_ptr
= (FCBlock
*)(((char*)fcb
) + sizeof(FCBlock
));
1783 if(i
== NON_MAC_QUEUE
)
1784 fcb
->trc_next_ptr
= RX_FCB_TRC_POINTER(fcb
->next_ptr
);
1786 fcb
->trc_next_ptr
= TRC_POINTER(fcb
->next_ptr
);
1788 for(j
= 1; j
< tp
->num_rx_fcbs
[i
]; j
++)
1790 fcb
->next_ptr
->back_ptr
= fcb
;
1791 fcb
= fcb
->next_ptr
;
1792 fcb
->frame_status
= 0;
1793 fcb
->frame_length
= 0;
1794 fcb
->info
= FCB_WARNING
;
1796 = (FCBlock
*)(((char *)fcb
) + sizeof(FCBlock
));
1798 if(i
== NON_MAC_QUEUE
)
1800 = RX_FCB_TRC_POINTER(fcb
->next_ptr
);
1803 = TRC_POINTER(fcb
->next_ptr
);
1806 fcb
->next_ptr
= tp
->rx_fcb_head
[i
];
1808 if(i
== NON_MAC_QUEUE
)
1809 fcb
->trc_next_ptr
= RX_FCB_TRC_POINTER(fcb
->next_ptr
);
1811 fcb
->trc_next_ptr
= TRC_POINTER(fcb
->next_ptr
);
1813 tp
->rx_fcb_head
[i
]->back_ptr
= fcb
;
1814 tp
->rx_fcb_curr
[i
] = tp
->rx_fcb_head
[i
]->next_ptr
;
1820 static int smctr_init_shared_memory(struct net_device
*dev
)
1822 struct net_local
*tp
= netdev_priv(dev
);
1826 if(smctr_debug
> 10)
1827 printk(KERN_DEBUG
"%s: smctr_init_shared_memory\n", dev
->name
);
1829 smctr_set_page(dev
, (__u8
*)(unsigned int)tp
->iscpb_ptr
);
1831 /* Initialize Initial System Configuration Point. (ISCP) */
1832 iscpb
= (__u32
*)PAGE_POINTER(&tp
->iscpb_ptr
->trc_scgb_ptr
);
1833 *iscpb
= (__u32
)(SWAP_WORDS(TRC_POINTER(tp
->scgb_ptr
)));
1835 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
1837 /* Initialize System Configuration Pointers. (SCP) */
1838 tp
->scgb_ptr
->config
= (SCGB_ADDRESS_POINTER_FORMAT
1839 | SCGB_MULTI_WORD_CONTROL
| SCGB_DATA_FORMAT
1840 | SCGB_BURST_LENGTH
);
1842 tp
->scgb_ptr
->trc_sclb_ptr
= TRC_POINTER(tp
->sclb_ptr
);
1843 tp
->scgb_ptr
->trc_acb_ptr
= TRC_POINTER(tp
->acb_head
);
1844 tp
->scgb_ptr
->trc_isb_ptr
= TRC_POINTER(tp
->isb_ptr
);
1845 tp
->scgb_ptr
->isbsiz
= (sizeof(ISBlock
)) - 2;
1847 /* Initialize System Control Block. (SCB) */
1848 tp
->sclb_ptr
->valid_command
= SCLB_VALID
| SCLB_CMD_NOP
;
1849 tp
->sclb_ptr
->iack_code
= 0;
1850 tp
->sclb_ptr
->resume_control
= 0;
1851 tp
->sclb_ptr
->int_mask_control
= 0;
1852 tp
->sclb_ptr
->int_mask_state
= 0;
1854 /* Initialize Interrupt Status Block. (ISB) */
1855 for(i
= 0; i
< NUM_OF_INTERRUPTS
; i
++)
1857 tp
->isb_ptr
->IStatus
[i
].IType
= 0xf0;
1858 tp
->isb_ptr
->IStatus
[i
].ISubtype
= 0;
1861 tp
->current_isb_index
= 0;
1863 /* Initialize Action Command Block. (ACB) */
1864 smctr_init_acbs(dev
);
1866 /* Initialize transmit FCB's and BDB's. */
1867 smctr_link_tx_fcbs_to_bdbs(dev
);
1868 smctr_init_tx_bdbs(dev
);
1869 smctr_init_tx_fcbs(dev
);
1871 /* Initialize receive FCB's and BDB's. */
1872 smctr_init_rx_bdbs(dev
);
1873 smctr_init_rx_fcbs(dev
);
1878 static int smctr_init_tx_bdbs(struct net_device
*dev
)
1880 struct net_local
*tp
= netdev_priv(dev
);
1884 for(i
= 0; i
< NUM_TX_QS_USED
; i
++)
1886 bdb
= tp
->tx_bdb_head
[i
];
1887 bdb
->info
= (BDB_NOT_CHAIN_END
| BDB_NO_WARNING
);
1888 bdb
->next_ptr
= (BDBlock
*)(((char *)bdb
) + sizeof(BDBlock
));
1889 bdb
->trc_next_ptr
= TRC_POINTER(bdb
->next_ptr
);
1891 for(j
= 1; j
< tp
->num_tx_bdbs
[i
]; j
++)
1893 bdb
->next_ptr
->back_ptr
= bdb
;
1894 bdb
= bdb
->next_ptr
;
1895 bdb
->info
= (BDB_NOT_CHAIN_END
| BDB_NO_WARNING
);
1897 = (BDBlock
*)(((char *)bdb
) + sizeof( BDBlock
)); bdb
->trc_next_ptr
= TRC_POINTER(bdb
->next_ptr
);
1900 bdb
->next_ptr
= tp
->tx_bdb_head
[i
];
1901 bdb
->trc_next_ptr
= TRC_POINTER(tp
->tx_bdb_head
[i
]);
1902 tp
->tx_bdb_head
[i
]->back_ptr
= bdb
;
1908 static int smctr_init_tx_fcbs(struct net_device
*dev
)
1910 struct net_local
*tp
= netdev_priv(dev
);
1914 for(i
= 0; i
< NUM_TX_QS_USED
; i
++)
1916 fcb
= tp
->tx_fcb_head
[i
];
1917 fcb
->frame_status
= 0;
1918 fcb
->frame_length
= 0;
1919 fcb
->info
= FCB_CHAIN_END
;
1920 fcb
->next_ptr
= (FCBlock
*)(((char *)fcb
) + sizeof(FCBlock
));
1921 fcb
->trc_next_ptr
= TRC_POINTER(fcb
->next_ptr
);
1923 for(j
= 1; j
< tp
->num_tx_fcbs
[i
]; j
++)
1925 fcb
->next_ptr
->back_ptr
= fcb
;
1926 fcb
= fcb
->next_ptr
;
1927 fcb
->frame_status
= 0;
1928 fcb
->frame_length
= 0;
1929 fcb
->info
= FCB_CHAIN_END
;
1931 = (FCBlock
*)(((char *)fcb
) + sizeof(FCBlock
));
1932 fcb
->trc_next_ptr
= TRC_POINTER(fcb
->next_ptr
);
1935 fcb
->next_ptr
= tp
->tx_fcb_head
[i
];
1936 fcb
->trc_next_ptr
= TRC_POINTER(tp
->tx_fcb_head
[i
]);
1938 tp
->tx_fcb_head
[i
]->back_ptr
= fcb
;
1939 tp
->tx_fcb_end
[i
] = tp
->tx_fcb_head
[i
]->next_ptr
;
1940 tp
->tx_fcb_curr
[i
] = tp
->tx_fcb_head
[i
]->next_ptr
;
1941 tp
->num_tx_fcbs_used
[i
] = 0;
1947 static int smctr_internal_self_test(struct net_device
*dev
)
1949 struct net_local
*tp
= netdev_priv(dev
);
1952 if((err
= smctr_issue_test_internal_rom_cmd(dev
)))
1955 if((err
= smctr_wait_cmd(dev
)))
1958 if(tp
->acb_head
->cmd_done_status
& 0xff)
1961 if((err
= smctr_issue_test_hic_cmd(dev
)))
1964 if((err
= smctr_wait_cmd(dev
)))
1967 if(tp
->acb_head
->cmd_done_status
& 0xff)
1970 if((err
= smctr_issue_test_mac_reg_cmd(dev
)))
1973 if((err
= smctr_wait_cmd(dev
)))
1976 if(tp
->acb_head
->cmd_done_status
& 0xff)
1983 * The typical workload of the driver: Handle the network interface interrupts.
1985 static irqreturn_t
smctr_interrupt(int irq
, void *dev_id
)
1987 struct net_device
*dev
= dev_id
;
1988 struct net_local
*tp
;
1990 __u16 interrupt_unmask_bits
= 0, interrupt_ack_code
= 0xff00;
1991 __u16 err1
, err
= NOT_MY_INTERRUPT
;
1992 __u8 isb_type
, isb_subtype
;
1995 ioaddr
= dev
->base_addr
;
1996 tp
= netdev_priv(dev
);
1998 if(tp
->status
== NOT_INITIALIZED
)
2001 spin_lock(&tp
->lock
);
2003 smctr_disable_bic_int(dev
);
2004 smctr_enable_16bit(dev
);
2006 smctr_clear_int(dev
);
2008 /* First read the LSB */
2009 while((tp
->isb_ptr
->IStatus
[tp
->current_isb_index
].IType
& 0xf0) == 0)
2011 isb_index
= tp
->current_isb_index
;
2012 isb_type
= tp
->isb_ptr
->IStatus
[isb_index
].IType
;
2013 isb_subtype
= tp
->isb_ptr
->IStatus
[isb_index
].ISubtype
;
2015 (tp
->current_isb_index
)++;
2016 if(tp
->current_isb_index
== NUM_OF_INTERRUPTS
)
2017 tp
->current_isb_index
= 0;
2019 if(isb_type
>= 0x10)
2021 smctr_disable_16bit(dev
);
2022 spin_unlock(&tp
->lock
);
2026 err
= HARDWARE_FAILED
;
2027 interrupt_ack_code
= isb_index
;
2028 tp
->isb_ptr
->IStatus
[isb_index
].IType
|= 0xf0;
2030 interrupt_unmask_bits
|= (1 << (__u16
)isb_type
);
2034 case ISB_IMC_MAC_TYPE_3
:
2035 smctr_disable_16bit(dev
);
2040 tp
->monitor_state
= MS_MONITOR_FSM_INACTIVE
;
2044 tp
->monitor_state
= MS_REPEAT_BEACON_STATE
;
2048 tp
->monitor_state
= MS_REPEAT_CLAIM_TOKEN_STATE
;
2052 tp
->monitor_state
= MS_TRANSMIT_CLAIM_TOKEN_STATE
; break;
2055 tp
->monitor_state
= MS_STANDBY_MONITOR_STATE
;
2059 tp
->monitor_state
= MS_TRANSMIT_BEACON_STATE
;
2063 tp
->monitor_state
= MS_ACTIVE_MONITOR_STATE
;
2067 tp
->monitor_state
= MS_TRANSMIT_RING_PURGE_STATE
;
2070 case 8: /* diagnostic state */
2074 tp
->monitor_state
= MS_BEACON_TEST_STATE
;
2075 if(smctr_lobe_media_test(dev
))
2077 tp
->ring_status_flags
= RING_STATUS_CHANGED
;
2078 tp
->ring_status
= AUTO_REMOVAL_ERROR
;
2079 smctr_ring_status_chg(dev
);
2080 smctr_bypass_state(dev
);
2083 smctr_issue_insert_cmd(dev
);
2086 /* case 0x0a-0xff, illegal states */
2091 tp
->ring_status_flags
= MONITOR_STATE_CHANGED
;
2092 err
= smctr_ring_status_chg(dev
);
2094 smctr_enable_16bit(dev
);
2097 /* Type 0x02 - MAC Error Counters Interrupt
2098 * One or more MAC Error Counter is half full
2099 * MAC Error Counters
2100 * Lost_FR_Error_Counter
2101 * RCV_Congestion_Counter
2102 * FR_copied_Error_Counter
2103 * FREQ_Error_Counter
2104 * Token_Error_Counter
2105 * Line_Error_Counter
2106 * Internal_Error_Count
2108 case ISB_IMC_MAC_ERROR_COUNTERS
:
2109 /* Read 802.5 Error Counters */
2110 err
= smctr_issue_read_ring_status_cmd(dev
);
2113 /* Type 0x04 - MAC Type 2 Interrupt
2114 * HOST needs to enqueue MAC Frame for transmission
2115 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2116 * TRC_Status_Changed_Indicate
2118 case ISB_IMC_MAC_TYPE_2
:
2119 err
= smctr_issue_read_ring_status_cmd(dev
);
2123 /* Type 0x05 - TX Frame Interrupt (FI). */
2124 case ISB_IMC_TX_FRAME
:
2125 /* BUG QUEUE for TRC stuck receive BUG */
2126 if(isb_subtype
& TX_PENDING_PRIORITY_2
)
2128 if((err
= smctr_tx_complete(dev
, BUG_QUEUE
)) != SUCCESS
)
2132 /* NON-MAC frames only */
2133 if(isb_subtype
& TX_PENDING_PRIORITY_1
)
2135 if((err
= smctr_tx_complete(dev
, NON_MAC_QUEUE
)) != SUCCESS
)
2139 /* MAC frames only */
2140 if(isb_subtype
& TX_PENDING_PRIORITY_0
)
2141 err
= smctr_tx_complete(dev
, MAC_QUEUE
); break;
2143 /* Type 0x06 - TX END OF QUEUE (FE) */
2144 case ISB_IMC_END_OF_TX_QUEUE
:
2146 if(isb_subtype
& TX_PENDING_PRIORITY_2
)
2148 /* ok to clear Receive FIFO overrun
2149 * imask send_BUG now completes.
2151 interrupt_unmask_bits
|= 0x800;
2153 tp
->tx_queue_status
[BUG_QUEUE
] = NOT_TRANSMITING
;
2154 if((err
= smctr_tx_complete(dev
, BUG_QUEUE
)) != SUCCESS
)
2156 if((err
= smctr_restart_tx_chain(dev
, BUG_QUEUE
)) != SUCCESS
)
2160 /* NON-MAC queue only */
2161 if(isb_subtype
& TX_PENDING_PRIORITY_1
)
2163 tp
->tx_queue_status
[NON_MAC_QUEUE
] = NOT_TRANSMITING
;
2164 if((err
= smctr_tx_complete(dev
, NON_MAC_QUEUE
)) != SUCCESS
)
2166 if((err
= smctr_restart_tx_chain(dev
, NON_MAC_QUEUE
)) != SUCCESS
)
2170 /* MAC queue only */
2171 if(isb_subtype
& TX_PENDING_PRIORITY_0
)
2173 tp
->tx_queue_status
[MAC_QUEUE
] = NOT_TRANSMITING
;
2174 if((err
= smctr_tx_complete(dev
, MAC_QUEUE
)) != SUCCESS
)
2177 err
= smctr_restart_tx_chain(dev
, MAC_QUEUE
);
2181 /* Type 0x07 - NON-MAC RX Resource Interrupt
2182 * Subtype bit 12 - (BW) BDB warning
2183 * Subtype bit 13 - (FW) FCB warning
2184 * Subtype bit 14 - (BE) BDB End of chain
2185 * Subtype bit 15 - (FE) FCB End of chain
2187 case ISB_IMC_NON_MAC_RX_RESOURCE
:
2188 tp
->rx_fifo_overrun_count
= 0;
2189 tp
->receive_queue_number
= NON_MAC_QUEUE
;
2190 err1
= smctr_rx_frame(dev
);
2192 if(isb_subtype
& NON_MAC_RX_RESOURCE_FE
)
2194 if((err
= smctr_issue_resume_rx_fcb_cmd( dev
, NON_MAC_QUEUE
)) != SUCCESS
) break;
2196 if(tp
->ptr_rx_fcb_overruns
)
2197 (*tp
->ptr_rx_fcb_overruns
)++;
2200 if(isb_subtype
& NON_MAC_RX_RESOURCE_BE
)
2202 if((err
= smctr_issue_resume_rx_bdb_cmd( dev
, NON_MAC_QUEUE
)) != SUCCESS
) break;
2204 if(tp
->ptr_rx_bdb_overruns
)
2205 (*tp
->ptr_rx_bdb_overruns
)++;
2210 /* Type 0x08 - MAC RX Resource Interrupt
2211 * Subtype bit 12 - (BW) BDB warning
2212 * Subtype bit 13 - (FW) FCB warning
2213 * Subtype bit 14 - (BE) BDB End of chain
2214 * Subtype bit 15 - (FE) FCB End of chain
2216 case ISB_IMC_MAC_RX_RESOURCE
:
2217 tp
->receive_queue_number
= MAC_QUEUE
;
2218 err1
= smctr_rx_frame(dev
);
2220 if(isb_subtype
& MAC_RX_RESOURCE_FE
)
2222 if((err
= smctr_issue_resume_rx_fcb_cmd( dev
, MAC_QUEUE
)) != SUCCESS
)
2225 if(tp
->ptr_rx_fcb_overruns
)
2226 (*tp
->ptr_rx_fcb_overruns
)++;
2229 if(isb_subtype
& MAC_RX_RESOURCE_BE
)
2231 if((err
= smctr_issue_resume_rx_bdb_cmd( dev
, MAC_QUEUE
)) != SUCCESS
)
2234 if(tp
->ptr_rx_bdb_overruns
)
2235 (*tp
->ptr_rx_bdb_overruns
)++;
2240 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2241 case ISB_IMC_NON_MAC_RX_FRAME
:
2242 tp
->rx_fifo_overrun_count
= 0;
2243 tp
->receive_queue_number
= NON_MAC_QUEUE
;
2244 err
= smctr_rx_frame(dev
);
2247 /* Type 0x0A - MAC RX Frame Interrupt */
2248 case ISB_IMC_MAC_RX_FRAME
:
2249 tp
->receive_queue_number
= MAC_QUEUE
;
2250 err
= smctr_rx_frame(dev
);
2253 /* Type 0x0B - TRC status
2254 * TRC has encountered an error condition
2255 * subtype bit 14 - transmit FIFO underrun
2256 * subtype bit 15 - receive FIFO overrun
2258 case ISB_IMC_TRC_FIFO_STATUS
:
2259 if(isb_subtype
& TRC_FIFO_STATUS_TX_UNDERRUN
)
2261 if(tp
->ptr_tx_fifo_underruns
)
2262 (*tp
->ptr_tx_fifo_underruns
)++;
2265 if(isb_subtype
& TRC_FIFO_STATUS_RX_OVERRUN
)
2267 /* update overrun stuck receive counter
2268 * if >= 3, has to clear it by sending
2269 * back to back frames. We pick
2270 * DAT(duplicate address MAC frame)
2272 tp
->rx_fifo_overrun_count
++;
2274 if(tp
->rx_fifo_overrun_count
>= 3)
2276 tp
->rx_fifo_overrun_count
= 0;
2278 /* delay clearing fifo overrun
2279 * imask till send_BUG tx
2282 interrupt_unmask_bits
&= (~0x800);
2283 printk(KERN_CRIT
"Jay please send bug\n");// smctr_send_bug(dev);
2286 if(tp
->ptr_rx_fifo_overruns
)
2287 (*tp
->ptr_rx_fifo_overruns
)++;
2293 /* Type 0x0C - Action Command Status Interrupt
2294 * Subtype bit 14 - CB end of command chain (CE)
2295 * Subtype bit 15 - CB command interrupt (CI)
2297 case ISB_IMC_COMMAND_STATUS
:
2299 if(tp
->acb_head
->cmd
== ACB_CMD_HIC_NOP
)
2301 printk(KERN_ERR
"i1\n");
2302 smctr_disable_16bit(dev
);
2304 /* XXXXXXXXXXXXXXXXX */
2305 /* err = UM_Interrupt(dev); */
2307 smctr_enable_16bit(dev
);
2311 if((tp
->acb_head
->cmd
2312 == ACB_CMD_READ_TRC_STATUS
)
2313 && (tp
->acb_head
->subcmd
2314 == RW_TRC_STATUS_BLOCK
))
2316 if(tp
->ptr_bcn_type
)
2319 = (__u32
)((SBlock
*)tp
->misc_command_data
)->BCN_Type
;
2322 if(((SBlock
*)tp
->misc_command_data
)->Status_CHG_Indicate
& ERROR_COUNTERS_CHANGED
)
2324 smctr_update_err_stats(dev
);
2327 if(((SBlock
*)tp
->misc_command_data
)->Status_CHG_Indicate
& TI_NDIS_RING_STATUS_CHANGED
)
2330 = ((SBlock
*)tp
->misc_command_data
)->TI_NDIS_Ring_Status
;
2331 smctr_disable_16bit(dev
);
2332 err
= smctr_ring_status_chg(dev
);
2333 smctr_enable_16bit(dev
);
2334 if((tp
->ring_status
& REMOVE_RECEIVED
)
2335 && (tp
->config_word0
& NO_AUTOREMOVE
))
2337 smctr_issue_remove_cmd(dev
);
2342 tp
->acb_pending
= 0;
2347 if(((SBlock
*)tp
->misc_command_data
)->Status_CHG_Indicate
& UNA_CHANGED
)
2351 tp
->ptr_una
[0] = SWAP_BYTES(((SBlock
*)tp
->misc_command_data
)->UNA
[0]);
2352 tp
->ptr_una
[1] = SWAP_BYTES(((SBlock
*)tp
->misc_command_data
)->UNA
[1]);
2353 tp
->ptr_una
[2] = SWAP_BYTES(((SBlock
*)tp
->misc_command_data
)->UNA
[2]);
2358 if(((SBlock
*)tp
->misc_command_data
)->Status_CHG_Indicate
& READY_TO_SEND_RQ_INIT
) {
2359 err
= smctr_send_rq_init(dev
);
2364 tp
->acb_pending
= 0;
2367 /* Type 0x0D - MAC Type 1 interrupt
2368 * Subtype -- 00 FR_BCN received at S12
2369 * 01 FR_BCN received at S21
2370 * 02 FR_DAT(DA=MA, A<>0) received at S21
2372 * 04 FR_REMOVE received at S42
2373 * 05 TBR_EXP, BR_FLAG_SET at S42
2376 case ISB_IMC_MAC_TYPE_1
:
2379 err
= HARDWARE_FAILED
;
2387 tp
->join_state
= JS_BYPASS_STATE
;
2388 if(tp
->status
!= CLOSED
)
2390 tp
->status
= CLOSED
;
2391 err
= smctr_status_chg(dev
);
2396 tp
->join_state
= JS_LOBE_TEST_STATE
;
2400 tp
->join_state
= JS_DETECT_MONITOR_PRESENT_STATE
;
2404 tp
->join_state
= JS_AWAIT_NEW_MONITOR_STATE
;
2408 tp
->join_state
= JS_DUPLICATE_ADDRESS_TEST_STATE
;
2412 tp
->join_state
= JS_NEIGHBOR_NOTIFICATION_STATE
;
2416 tp
->join_state
= JS_REQUEST_INITIALIZATION_STATE
;
2420 tp
->join_state
= JS_JOIN_COMPLETE_STATE
;
2422 err
= smctr_status_chg(dev
);
2426 tp
->join_state
= JS_BYPASS_WAIT_STATE
;
2431 /* Type 0x0E - TRC Initialization Sequence Interrupt
2432 * Subtype -- 00-FF Initializatin sequence complete
2434 case ISB_IMC_TRC_INTRNL_TST_STATUS
:
2435 tp
->status
= INITIALIZED
;
2436 smctr_disable_16bit(dev
);
2437 err
= smctr_status_chg(dev
);
2438 smctr_enable_16bit(dev
);
2441 /* other interrupt types, illegal */
2450 /* Checking the ack code instead of the unmask bits here is because :
2451 * while fixing the stuck receive, DAT frame are sent and mask off
2452 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2453 * but we still want to issue ack to ISB
2455 if(!(interrupt_ack_code
& 0xff00))
2456 smctr_issue_int_ack(dev
, interrupt_ack_code
, interrupt_unmask_bits
);
2458 smctr_disable_16bit(dev
);
2459 smctr_enable_bic_int(dev
);
2460 spin_unlock(&tp
->lock
);
2465 static int smctr_issue_enable_int_cmd(struct net_device
*dev
,
2466 __u16 interrupt_enable_mask
)
2468 struct net_local
*tp
= netdev_priv(dev
);
2471 if((err
= smctr_wait_while_cbusy(dev
)))
2474 tp
->sclb_ptr
->int_mask_control
= interrupt_enable_mask
;
2475 tp
->sclb_ptr
->valid_command
= SCLB_VALID
| SCLB_CMD_CLEAR_INTERRUPT_MASK
;
2477 smctr_set_ctrl_attention(dev
);
2482 static int smctr_issue_int_ack(struct net_device
*dev
, __u16 iack_code
, __u16 ibits
)
2484 struct net_local
*tp
= netdev_priv(dev
);
2486 if(smctr_wait_while_cbusy(dev
))
2489 tp
->sclb_ptr
->int_mask_control
= ibits
;
2490 tp
->sclb_ptr
->iack_code
= iack_code
<< 1; /* use the offset from base */ tp
->sclb_ptr
->resume_control
= 0;
2491 tp
->sclb_ptr
->valid_command
= SCLB_VALID
| SCLB_IACK_CODE_VALID
| SCLB_CMD_CLEAR_INTERRUPT_MASK
;
2493 smctr_set_ctrl_attention(dev
);
2498 static int smctr_issue_init_timers_cmd(struct net_device
*dev
)
2500 struct net_local
*tp
= netdev_priv(dev
);
2503 __u16
*pTimer_Struc
= (__u16
*)tp
->misc_command_data
;
2505 if((err
= smctr_wait_while_cbusy(dev
)))
2508 if((err
= smctr_wait_cmd(dev
)))
2511 tp
->config_word0
= THDREN
| DMA_TRIGGER
| USETPT
| NO_AUTOREMOVE
;
2512 tp
->config_word1
= 0;
2514 if((tp
->media_type
== MEDIA_STP_16
)
2515 || (tp
->media_type
== MEDIA_UTP_16
)
2516 || (tp
->media_type
== MEDIA_STP_16_UTP_16
))
2518 tp
->config_word0
|= FREQ_16MB_BIT
;
2521 if(tp
->mode_bits
& EARLY_TOKEN_REL
)
2522 tp
->config_word0
|= ETREN
;
2524 if(tp
->mode_bits
& LOOPING_MODE_MASK
)
2525 tp
->config_word0
|= RX_OWN_BIT
;
2527 tp
->config_word0
&= ~RX_OWN_BIT
;
2529 if(tp
->receive_mask
& PROMISCUOUS_MODE
)
2530 tp
->config_word0
|= PROMISCUOUS_BIT
;
2532 tp
->config_word0
&= ~PROMISCUOUS_BIT
;
2534 if(tp
->receive_mask
& ACCEPT_ERR_PACKETS
)
2535 tp
->config_word0
|= SAVBAD_BIT
;
2537 tp
->config_word0
&= ~SAVBAD_BIT
;
2539 if(tp
->receive_mask
& ACCEPT_ATT_MAC_FRAMES
)
2540 tp
->config_word0
|= RXATMAC
;
2542 tp
->config_word0
&= ~RXATMAC
;
2544 if(tp
->receive_mask
& ACCEPT_MULTI_PROM
)
2545 tp
->config_word1
|= MULTICAST_ADDRESS_BIT
;
2547 tp
->config_word1
&= ~MULTICAST_ADDRESS_BIT
;
2549 if(tp
->receive_mask
& ACCEPT_SOURCE_ROUTING_SPANNING
)
2550 tp
->config_word1
|= SOURCE_ROUTING_SPANNING_BITS
;
2553 if(tp
->receive_mask
& ACCEPT_SOURCE_ROUTING
)
2554 tp
->config_word1
|= SOURCE_ROUTING_EXPLORER_BIT
;
2556 tp
->config_word1
&= ~SOURCE_ROUTING_SPANNING_BITS
;
2559 if((tp
->media_type
== MEDIA_STP_16
)
2560 || (tp
->media_type
== MEDIA_UTP_16
)
2561 || (tp
->media_type
== MEDIA_STP_16_UTP_16
))
2563 tp
->config_word1
|= INTERFRAME_SPACING_16
;
2566 tp
->config_word1
|= INTERFRAME_SPACING_4
;
2568 *pTimer_Struc
++ = tp
->config_word0
;
2569 *pTimer_Struc
++ = tp
->config_word1
;
2571 if((tp
->media_type
== MEDIA_STP_4
)
2572 || (tp
->media_type
== MEDIA_UTP_4
)
2573 || (tp
->media_type
== MEDIA_STP_4_UTP_4
))
2575 *pTimer_Struc
++ = 0x00FA; /* prescale */
2576 *pTimer_Struc
++ = 0x2710; /* TPT_limit */
2577 *pTimer_Struc
++ = 0x2710; /* TQP_limit */
2578 *pTimer_Struc
++ = 0x0A28; /* TNT_limit */
2579 *pTimer_Struc
++ = 0x3E80; /* TBT_limit */
2580 *pTimer_Struc
++ = 0x3A98; /* TSM_limit */
2581 *pTimer_Struc
++ = 0x1B58; /* TAM_limit */
2582 *pTimer_Struc
++ = 0x00C8; /* TBR_limit */
2583 *pTimer_Struc
++ = 0x07D0; /* TER_limit */
2584 *pTimer_Struc
++ = 0x000A; /* TGT_limit */
2585 *pTimer_Struc
++ = 0x1162; /* THT_limit */
2586 *pTimer_Struc
++ = 0x07D0; /* TRR_limit */
2587 *pTimer_Struc
++ = 0x1388; /* TVX_limit */
2588 *pTimer_Struc
++ = 0x0000; /* reserved */
2592 *pTimer_Struc
++ = 0x03E8; /* prescale */
2593 *pTimer_Struc
++ = 0x9C40; /* TPT_limit */
2594 *pTimer_Struc
++ = 0x9C40; /* TQP_limit */
2595 *pTimer_Struc
++ = 0x0A28; /* TNT_limit */
2596 *pTimer_Struc
++ = 0x3E80; /* TBT_limit */
2597 *pTimer_Struc
++ = 0x3A98; /* TSM_limit */
2598 *pTimer_Struc
++ = 0x1B58; /* TAM_limit */
2599 *pTimer_Struc
++ = 0x00C8; /* TBR_limit */
2600 *pTimer_Struc
++ = 0x07D0; /* TER_limit */
2601 *pTimer_Struc
++ = 0x000A; /* TGT_limit */
2602 *pTimer_Struc
++ = 0x4588; /* THT_limit */
2603 *pTimer_Struc
++ = 0x1F40; /* TRR_limit */
2604 *pTimer_Struc
++ = 0x4E20; /* TVX_limit */
2605 *pTimer_Struc
++ = 0x0000; /* reserved */
2608 /* Set node address. */
2609 *pTimer_Struc
++ = dev
->dev_addr
[0] << 8
2610 | (dev
->dev_addr
[1] & 0xFF);
2611 *pTimer_Struc
++ = dev
->dev_addr
[2] << 8
2612 | (dev
->dev_addr
[3] & 0xFF);
2613 *pTimer_Struc
++ = dev
->dev_addr
[4] << 8
2614 | (dev
->dev_addr
[5] & 0xFF);
2616 /* Set group address. */
2617 *pTimer_Struc
++ = tp
->group_address_0
<< 8
2618 | tp
->group_address_0
>> 8;
2619 *pTimer_Struc
++ = tp
->group_address
[0] << 8
2620 | tp
->group_address
[0] >> 8;
2621 *pTimer_Struc
++ = tp
->group_address
[1] << 8
2622 | tp
->group_address
[1] >> 8;
2624 /* Set functional address. */
2625 *pTimer_Struc
++ = tp
->functional_address_0
<< 8
2626 | tp
->functional_address_0
>> 8;
2627 *pTimer_Struc
++ = tp
->functional_address
[0] << 8
2628 | tp
->functional_address
[0] >> 8;
2629 *pTimer_Struc
++ = tp
->functional_address
[1] << 8
2630 | tp
->functional_address
[1] >> 8;
2632 /* Set Bit-Wise group address. */
2633 *pTimer_Struc
++ = tp
->bitwise_group_address
[0] << 8
2634 | tp
->bitwise_group_address
[0] >> 8;
2635 *pTimer_Struc
++ = tp
->bitwise_group_address
[1] << 8
2636 | tp
->bitwise_group_address
[1] >> 8;
2638 /* Set ring number address. */
2639 *pTimer_Struc
++ = tp
->source_ring_number
;
2640 *pTimer_Struc
++ = tp
->target_ring_number
;
2642 /* Physical drop number. */
2643 *pTimer_Struc
++ = (unsigned short)0;
2644 *pTimer_Struc
++ = (unsigned short)0;
2646 /* Product instance ID. */
2647 for(i
= 0; i
< 9; i
++)
2648 *pTimer_Struc
++ = (unsigned short)0;
2650 err
= smctr_setup_single_cmd_w_data(dev
, ACB_CMD_INIT_TRC_TIMERS
, 0);
2655 static int smctr_issue_init_txrx_cmd(struct net_device
*dev
)
2657 struct net_local
*tp
= netdev_priv(dev
);
2660 void **txrx_ptrs
= (void *)tp
->misc_command_data
;
2662 if((err
= smctr_wait_while_cbusy(dev
)))
2665 if((err
= smctr_wait_cmd(dev
)))
2667 printk(KERN_ERR
"%s: Hardware failure\n", dev
->name
);
2671 /* Initialize Transmit Queue Pointers that are used, to point to
2674 for(i
= 0; i
< NUM_TX_QS_USED
; i
++)
2675 *txrx_ptrs
++ = (void *)TRC_POINTER(tp
->tx_fcb_head
[i
]);
2677 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2678 for(; i
< MAX_TX_QS
; i
++)
2679 *txrx_ptrs
++ = (void *)0;
2681 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2682 * used, to point to a single FCB and a BDB chain of buffers.
2684 for(i
= 0; i
< NUM_RX_QS_USED
; i
++)
2686 *txrx_ptrs
++ = (void *)TRC_POINTER(tp
->rx_fcb_head
[i
]);
2687 *txrx_ptrs
++ = (void *)TRC_POINTER(tp
->rx_bdb_head
[i
]);
2690 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2691 for(; i
< MAX_RX_QS
; i
++)
2693 *txrx_ptrs
++ = (void *)0;
2694 *txrx_ptrs
++ = (void *)0;
2697 err
= smctr_setup_single_cmd_w_data(dev
, ACB_CMD_INIT_TX_RX
, 0);
2702 static int smctr_issue_insert_cmd(struct net_device
*dev
)
2706 err
= smctr_setup_single_cmd(dev
, ACB_CMD_INSERT
, ACB_SUB_CMD_NOP
);
2711 static int smctr_issue_read_ring_status_cmd(struct net_device
*dev
)
2715 if((err
= smctr_wait_while_cbusy(dev
)))
2718 if((err
= smctr_wait_cmd(dev
)))
2721 err
= smctr_setup_single_cmd_w_data(dev
, ACB_CMD_READ_TRC_STATUS
,
2722 RW_TRC_STATUS_BLOCK
);
2727 static int smctr_issue_read_word_cmd(struct net_device
*dev
, __u16 aword_cnt
)
2731 if((err
= smctr_wait_while_cbusy(dev
)))
2734 if((err
= smctr_wait_cmd(dev
)))
2737 err
= smctr_setup_single_cmd_w_data(dev
, ACB_CMD_MCT_READ_VALUE
,
2743 static int smctr_issue_remove_cmd(struct net_device
*dev
)
2745 struct net_local
*tp
= netdev_priv(dev
);
2748 if((err
= smctr_wait_while_cbusy(dev
)))
2751 tp
->sclb_ptr
->resume_control
= 0;
2752 tp
->sclb_ptr
->valid_command
= SCLB_VALID
| SCLB_CMD_REMOVE
;
2754 smctr_set_ctrl_attention(dev
);
2759 static int smctr_issue_resume_acb_cmd(struct net_device
*dev
)
2761 struct net_local
*tp
= netdev_priv(dev
);
2764 if((err
= smctr_wait_while_cbusy(dev
)))
2767 tp
->sclb_ptr
->resume_control
= SCLB_RC_ACB
;
2768 tp
->sclb_ptr
->valid_command
= SCLB_VALID
| SCLB_RESUME_CONTROL_VALID
;
2770 tp
->acb_pending
= 1;
2772 smctr_set_ctrl_attention(dev
);
2777 static int smctr_issue_resume_rx_bdb_cmd(struct net_device
*dev
, __u16 queue
)
2779 struct net_local
*tp
= netdev_priv(dev
);
2782 if((err
= smctr_wait_while_cbusy(dev
)))
2785 if(queue
== MAC_QUEUE
)
2786 tp
->sclb_ptr
->resume_control
= SCLB_RC_RX_MAC_BDB
;
2788 tp
->sclb_ptr
->resume_control
= SCLB_RC_RX_NON_MAC_BDB
;
2790 tp
->sclb_ptr
->valid_command
= SCLB_VALID
| SCLB_RESUME_CONTROL_VALID
;
2792 smctr_set_ctrl_attention(dev
);
2797 static int smctr_issue_resume_rx_fcb_cmd(struct net_device
*dev
, __u16 queue
)
2799 struct net_local
*tp
= netdev_priv(dev
);
2801 if(smctr_debug
> 10)
2802 printk(KERN_DEBUG
"%s: smctr_issue_resume_rx_fcb_cmd\n", dev
->name
);
2804 if(smctr_wait_while_cbusy(dev
))
2807 if(queue
== MAC_QUEUE
)
2808 tp
->sclb_ptr
->resume_control
= SCLB_RC_RX_MAC_FCB
;
2810 tp
->sclb_ptr
->resume_control
= SCLB_RC_RX_NON_MAC_FCB
;
2812 tp
->sclb_ptr
->valid_command
= SCLB_VALID
| SCLB_RESUME_CONTROL_VALID
;
2814 smctr_set_ctrl_attention(dev
);
2819 static int smctr_issue_resume_tx_fcb_cmd(struct net_device
*dev
, __u16 queue
)
2821 struct net_local
*tp
= netdev_priv(dev
);
2823 if(smctr_debug
> 10)
2824 printk(KERN_DEBUG
"%s: smctr_issue_resume_tx_fcb_cmd\n", dev
->name
);
2826 if(smctr_wait_while_cbusy(dev
))
2829 tp
->sclb_ptr
->resume_control
= (SCLB_RC_TFCB0
<< queue
);
2830 tp
->sclb_ptr
->valid_command
= SCLB_RESUME_CONTROL_VALID
| SCLB_VALID
;
2832 smctr_set_ctrl_attention(dev
);
2837 static int smctr_issue_test_internal_rom_cmd(struct net_device
*dev
)
2841 err
= smctr_setup_single_cmd(dev
, ACB_CMD_MCT_TEST
,
2842 TRC_INTERNAL_ROM_TEST
);
2847 static int smctr_issue_test_hic_cmd(struct net_device
*dev
)
2851 err
= smctr_setup_single_cmd(dev
, ACB_CMD_HIC_TEST
,
2852 TRC_HOST_INTERFACE_REG_TEST
);
2857 static int smctr_issue_test_mac_reg_cmd(struct net_device
*dev
)
2861 err
= smctr_setup_single_cmd(dev
, ACB_CMD_MCT_TEST
,
2862 TRC_MAC_REGISTERS_TEST
);
2867 static int smctr_issue_trc_loopback_cmd(struct net_device
*dev
)
2871 err
= smctr_setup_single_cmd(dev
, ACB_CMD_MCT_TEST
,
2872 TRC_INTERNAL_LOOPBACK
);
2877 static int smctr_issue_tri_loopback_cmd(struct net_device
*dev
)
2881 err
= smctr_setup_single_cmd(dev
, ACB_CMD_MCT_TEST
,
2887 static int smctr_issue_write_byte_cmd(struct net_device
*dev
,
2888 short aword_cnt
, void *byte
)
2890 struct net_local
*tp
= netdev_priv(dev
);
2891 unsigned int iword
, ibyte
;
2894 if((err
= smctr_wait_while_cbusy(dev
)))
2897 if((err
= smctr_wait_cmd(dev
)))
2900 for(iword
= 0, ibyte
= 0; iword
< (unsigned int)(aword_cnt
& 0xff);
2901 iword
++, ibyte
+= 2)
2903 tp
->misc_command_data
[iword
] = (*((__u8
*)byte
+ ibyte
) << 8)
2904 | (*((__u8
*)byte
+ ibyte
+ 1));
2907 return (smctr_setup_single_cmd_w_data(dev
, ACB_CMD_MCT_WRITE_VALUE
,
2911 static int smctr_issue_write_word_cmd(struct net_device
*dev
,
2912 short aword_cnt
, void *word
)
2914 struct net_local
*tp
= netdev_priv(dev
);
2915 unsigned int i
, err
;
2917 if((err
= smctr_wait_while_cbusy(dev
)))
2920 if((err
= smctr_wait_cmd(dev
)))
2923 for(i
= 0; i
< (unsigned int)(aword_cnt
& 0xff); i
++)
2924 tp
->misc_command_data
[i
] = *((__u16
*)word
+ i
);
2926 err
= smctr_setup_single_cmd_w_data(dev
, ACB_CMD_MCT_WRITE_VALUE
,
2932 static int smctr_join_complete_state(struct net_device
*dev
)
2936 err
= smctr_setup_single_cmd(dev
, ACB_CMD_CHANGE_JOIN_STATE
,
2937 JS_JOIN_COMPLETE_STATE
);
2942 static int smctr_link_tx_fcbs_to_bdbs(struct net_device
*dev
)
2944 struct net_local
*tp
= netdev_priv(dev
);
2949 for(i
= 0; i
< NUM_TX_QS_USED
; i
++)
2951 fcb
= tp
->tx_fcb_head
[i
];
2952 bdb
= tp
->tx_bdb_head
[i
];
2954 for(j
= 0; j
< tp
->num_tx_fcbs
[i
]; j
++)
2957 fcb
->trc_bdb_ptr
= TRC_POINTER(bdb
);
2958 fcb
= (FCBlock
*)((char *)fcb
+ sizeof(FCBlock
));
2959 bdb
= (BDBlock
*)((char *)bdb
+ sizeof(BDBlock
));
2966 static int smctr_load_firmware(struct net_device
*dev
)
2968 struct net_local
*tp
= netdev_priv(dev
);
2969 const struct firmware
*fw
;
2970 __u16 i
, checksum
= 0;
2973 if(smctr_debug
> 10)
2974 printk(KERN_DEBUG
"%s: smctr_load_firmware\n", dev
->name
);
2976 if (request_firmware(&fw
, "tr_smctr.bin", &dev
->dev
)) {
2977 printk(KERN_ERR
"%s: firmware not found\n", dev
->name
);
2978 return (UCODE_NOT_PRESENT
);
2981 tp
->num_of_tx_buffs
= 4;
2982 tp
->mode_bits
|= UMAC
;
2983 tp
->receive_mask
= 0;
2984 tp
->max_packet_size
= 4177;
2986 /* Can only upload the firmware once per adapter reset. */
2987 if (tp
->microcode_version
!= 0) {
2988 err
= (UCODE_PRESENT
);
2992 /* Verify the firmware exists and is there in the right amount. */
2994 || (*(fw
->data
+ UCODE_VERSION_OFFSET
) < UCODE_VERSION
))
2996 err
= (UCODE_NOT_PRESENT
);
3000 /* UCODE_SIZE is not included in Checksum. */
3001 for(i
= 0; i
< *((__u16
*)(fw
->data
+ UCODE_SIZE_OFFSET
)); i
+= 2)
3002 checksum
+= *((__u16
*)(fw
->data
+ 2 + i
));
3004 err
= (UCODE_NOT_PRESENT
);
3008 /* At this point we have a valid firmware image, lets kick it on up. */
3009 smctr_enable_adapter_ram(dev
);
3010 smctr_enable_16bit(dev
);
3011 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
3013 if((smctr_checksum_firmware(dev
))
3014 || (*(fw
->data
+ UCODE_VERSION_OFFSET
)
3015 > tp
->microcode_version
))
3017 smctr_enable_adapter_ctrl_store(dev
);
3019 /* Zero out ram space for firmware. */
3020 for(i
= 0; i
< CS_RAM_SIZE
; i
+= 2)
3021 *((__u16
*)(tp
->ram_access
+ i
)) = 0;
3023 smctr_decode_firmware(dev
, fw
);
3025 tp
->microcode_version
= *(fw
->data
+ UCODE_VERSION_OFFSET
); *((__u16
*)(tp
->ram_access
+ CS_RAM_VERSION_OFFSET
))
3026 = (tp
->microcode_version
<< 8);
3027 *((__u16
*)(tp
->ram_access
+ CS_RAM_CHECKSUM_OFFSET
))
3028 = ~(tp
->microcode_version
<< 8) + 1;
3030 smctr_disable_adapter_ctrl_store(dev
);
3032 if(smctr_checksum_firmware(dev
))
3033 err
= HARDWARE_FAILED
;
3036 err
= UCODE_PRESENT
;
3038 smctr_disable_16bit(dev
);
3040 release_firmware(fw
);
3044 static int smctr_load_node_addr(struct net_device
*dev
)
3046 int ioaddr
= dev
->base_addr
;
3050 for(i
= 0; i
< 6; i
++)
3052 r
= inb(ioaddr
+ LAR0
+ i
);
3053 dev
->dev_addr
[i
] = (char)r
;
3061 * During the transmission of the initial 1500 lobe media MAC frames,
3062 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3063 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3064 * microcode will not transmit any frames given to it by the host, and
3065 * will consequently cause a timeout.
3067 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
3068 * queues other than the one used for the lobe_media_test should be
3071 * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
3072 * has any multi-cast or promiscous bits set, the receive_mask needs to
3073 * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
3074 * run, and then the receive mask set back to its original value if the test
3077 static int smctr_lobe_media_test(struct net_device
*dev
)
3079 struct net_local
*tp
= netdev_priv(dev
);
3080 unsigned int i
, perror
= 0;
3081 unsigned short saved_rcv_mask
;
3083 if(smctr_debug
> 10)
3084 printk(KERN_DEBUG
"%s: smctr_lobe_media_test\n", dev
->name
);
3086 /* Clear receive mask for lobe test. */
3087 saved_rcv_mask
= tp
->receive_mask
;
3088 tp
->receive_mask
= 0;
3090 smctr_chg_rx_mask(dev
);
3092 /* Setup the lobe media test. */
3093 smctr_lobe_media_test_cmd(dev
);
3094 if(smctr_wait_cmd(dev
))
3097 /* Tx lobe media test frames. */
3098 for(i
= 0; i
< 1500; ++i
)
3100 if(smctr_send_lobe_media_test(dev
))
3107 if(smctr_lobe_media_test_cmd(dev
))
3113 if(smctr_send_dat(dev
))
3115 if(smctr_send_dat(dev
))
3119 /* Check if any frames received during test. */
3120 if((tp
->rx_fcb_curr
[MAC_QUEUE
]->frame_status
)
3121 || (tp
->rx_fcb_curr
[NON_MAC_QUEUE
]->frame_status
))
3124 /* Set receive mask to "Promisc" mode. */
3125 tp
->receive_mask
= saved_rcv_mask
;
3127 smctr_chg_rx_mask(dev
);
3131 smctr_reset_adapter(dev
);
3132 tp
->status
= CLOSED
;
3133 return LOBE_MEDIA_TEST_FAILED
;
3136 static int smctr_lobe_media_test_cmd(struct net_device
*dev
)
3138 struct net_local
*tp
= netdev_priv(dev
);
3141 if(smctr_debug
> 10)
3142 printk(KERN_DEBUG
"%s: smctr_lobe_media_test_cmd\n", dev
->name
);
3144 /* Change to lobe media test state. */
3145 if(tp
->monitor_state
!= MS_BEACON_TEST_STATE
)
3147 smctr_lobe_media_test_state(dev
);
3148 if(smctr_wait_cmd(dev
))
3150 printk(KERN_ERR
"Lobe Failed test state\n");
3151 return (LOBE_MEDIA_TEST_FAILED
);
3155 err
= smctr_setup_single_cmd(dev
, ACB_CMD_MCT_TEST
,
3156 TRC_LOBE_MEDIA_TEST
);
3161 static int smctr_lobe_media_test_state(struct net_device
*dev
)
3165 err
= smctr_setup_single_cmd(dev
, ACB_CMD_CHANGE_JOIN_STATE
,
3166 JS_LOBE_TEST_STATE
);
3171 static int smctr_make_8025_hdr(struct net_device
*dev
,
3172 MAC_HEADER
*rmf
, MAC_HEADER
*tmf
, __u16 ac_fc
)
3174 tmf
->ac
= MSB(ac_fc
); /* msb is access control */
3175 tmf
->fc
= LSB(ac_fc
); /* lsb is frame control */
3177 tmf
->sa
[0] = dev
->dev_addr
[0];
3178 tmf
->sa
[1] = dev
->dev_addr
[1];
3179 tmf
->sa
[2] = dev
->dev_addr
[2];
3180 tmf
->sa
[3] = dev
->dev_addr
[3];
3181 tmf
->sa
[4] = dev
->dev_addr
[4];
3182 tmf
->sa
[5] = dev
->dev_addr
[5];
3186 /* Send RQ_INIT to RPS */
3196 /* Send RPT_TX_FORWARD to CRS */
3197 case RPT_TX_FORWARD
:
3206 /* Everything else goes to sender */
3208 tmf
->da
[0] = rmf
->sa
[0];
3209 tmf
->da
[1] = rmf
->sa
[1];
3210 tmf
->da
[2] = rmf
->sa
[2];
3211 tmf
->da
[3] = rmf
->sa
[3];
3212 tmf
->da
[4] = rmf
->sa
[4];
3213 tmf
->da
[5] = rmf
->sa
[5];
3220 static int smctr_make_access_pri(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
)
3222 struct net_local
*tp
= netdev_priv(dev
);
3224 tsv
->svi
= AUTHORIZED_ACCESS_PRIORITY
;
3225 tsv
->svl
= S_AUTHORIZED_ACCESS_PRIORITY
;
3227 tsv
->svv
[0] = MSB(tp
->authorized_access_priority
);
3228 tsv
->svv
[1] = LSB(tp
->authorized_access_priority
);
3233 static int smctr_make_addr_mod(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
)
3235 tsv
->svi
= ADDRESS_MODIFER
;
3236 tsv
->svl
= S_ADDRESS_MODIFER
;
3244 static int smctr_make_auth_funct_class(struct net_device
*dev
,
3245 MAC_SUB_VECTOR
*tsv
)
3247 struct net_local
*tp
= netdev_priv(dev
);
3249 tsv
->svi
= AUTHORIZED_FUNCTION_CLASS
;
3250 tsv
->svl
= S_AUTHORIZED_FUNCTION_CLASS
;
3252 tsv
->svv
[0] = MSB(tp
->authorized_function_classes
);
3253 tsv
->svv
[1] = LSB(tp
->authorized_function_classes
);
3258 static int smctr_make_corr(struct net_device
*dev
,
3259 MAC_SUB_VECTOR
*tsv
, __u16 correlator
)
3261 tsv
->svi
= CORRELATOR
;
3262 tsv
->svl
= S_CORRELATOR
;
3264 tsv
->svv
[0] = MSB(correlator
);
3265 tsv
->svv
[1] = LSB(correlator
);
3270 static int smctr_make_funct_addr(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
)
3272 struct net_local
*tp
= netdev_priv(dev
);
3274 smctr_get_functional_address(dev
);
3276 tsv
->svi
= FUNCTIONAL_ADDRESS
;
3277 tsv
->svl
= S_FUNCTIONAL_ADDRESS
;
3279 tsv
->svv
[0] = MSB(tp
->misc_command_data
[0]);
3280 tsv
->svv
[1] = LSB(tp
->misc_command_data
[0]);
3282 tsv
->svv
[2] = MSB(tp
->misc_command_data
[1]);
3283 tsv
->svv
[3] = LSB(tp
->misc_command_data
[1]);
3288 static int smctr_make_group_addr(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
)
3290 struct net_local
*tp
= netdev_priv(dev
);
3292 smctr_get_group_address(dev
);
3294 tsv
->svi
= GROUP_ADDRESS
;
3295 tsv
->svl
= S_GROUP_ADDRESS
;
3297 tsv
->svv
[0] = MSB(tp
->misc_command_data
[0]);
3298 tsv
->svv
[1] = LSB(tp
->misc_command_data
[0]);
3300 tsv
->svv
[2] = MSB(tp
->misc_command_data
[1]);
3301 tsv
->svv
[3] = LSB(tp
->misc_command_data
[1]);
3303 /* Set Group Address Sub-vector to all zeros if only the
3304 * Group Address/Functional Address Indicator is set.
3306 if(tsv
->svv
[0] == 0x80 && tsv
->svv
[1] == 0x00
3307 && tsv
->svv
[2] == 0x00 && tsv
->svv
[3] == 0x00)
3313 static int smctr_make_phy_drop_num(struct net_device
*dev
,
3314 MAC_SUB_VECTOR
*tsv
)
3316 struct net_local
*tp
= netdev_priv(dev
);
3318 smctr_get_physical_drop_number(dev
);
3320 tsv
->svi
= PHYSICAL_DROP
;
3321 tsv
->svl
= S_PHYSICAL_DROP
;
3323 tsv
->svv
[0] = MSB(tp
->misc_command_data
[0]);
3324 tsv
->svv
[1] = LSB(tp
->misc_command_data
[0]);
3326 tsv
->svv
[2] = MSB(tp
->misc_command_data
[1]);
3327 tsv
->svv
[3] = LSB(tp
->misc_command_data
[1]);
3332 static int smctr_make_product_id(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
)
3336 tsv
->svi
= PRODUCT_INSTANCE_ID
;
3337 tsv
->svl
= S_PRODUCT_INSTANCE_ID
;
3339 for(i
= 0; i
< 18; i
++)
3345 static int smctr_make_station_id(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
)
3347 struct net_local
*tp
= netdev_priv(dev
);
3349 smctr_get_station_id(dev
);
3351 tsv
->svi
= STATION_IDENTIFER
;
3352 tsv
->svl
= S_STATION_IDENTIFER
;
3354 tsv
->svv
[0] = MSB(tp
->misc_command_data
[0]);
3355 tsv
->svv
[1] = LSB(tp
->misc_command_data
[0]);
3357 tsv
->svv
[2] = MSB(tp
->misc_command_data
[1]);
3358 tsv
->svv
[3] = LSB(tp
->misc_command_data
[1]);
3360 tsv
->svv
[4] = MSB(tp
->misc_command_data
[2]);
3361 tsv
->svv
[5] = LSB(tp
->misc_command_data
[2]);
3366 static int smctr_make_ring_station_status(struct net_device
*dev
,
3367 MAC_SUB_VECTOR
* tsv
)
3369 tsv
->svi
= RING_STATION_STATUS
;
3370 tsv
->svl
= S_RING_STATION_STATUS
;
3382 static int smctr_make_ring_station_version(struct net_device
*dev
,
3383 MAC_SUB_VECTOR
*tsv
)
3385 struct net_local
*tp
= netdev_priv(dev
);
3387 tsv
->svi
= RING_STATION_VERSION_NUMBER
;
3388 tsv
->svl
= S_RING_STATION_VERSION_NUMBER
;
3390 tsv
->svv
[0] = 0xe2; /* EBCDIC - S */
3391 tsv
->svv
[1] = 0xd4; /* EBCDIC - M */
3392 tsv
->svv
[2] = 0xc3; /* EBCDIC - C */
3393 tsv
->svv
[3] = 0x40; /* EBCDIC - */
3394 tsv
->svv
[4] = 0xe5; /* EBCDIC - V */
3395 tsv
->svv
[5] = 0xF0 + (tp
->microcode_version
>> 4);
3396 tsv
->svv
[6] = 0xF0 + (tp
->microcode_version
& 0x0f);
3397 tsv
->svv
[7] = 0x40; /* EBCDIC - */
3398 tsv
->svv
[8] = 0xe7; /* EBCDIC - X */
3400 if(tp
->extra_info
& CHIP_REV_MASK
)
3401 tsv
->svv
[9] = 0xc5; /* EBCDIC - E */
3403 tsv
->svv
[9] = 0xc4; /* EBCDIC - D */
3408 static int smctr_make_tx_status_code(struct net_device
*dev
,
3409 MAC_SUB_VECTOR
*tsv
, __u16 tx_fstatus
)
3411 tsv
->svi
= TRANSMIT_STATUS_CODE
;
3412 tsv
->svl
= S_TRANSMIT_STATUS_CODE
;
3414 tsv
->svv
[0] = ((tx_fstatus
& 0x0100 >> 6) | IBM_PASS_SOURCE_ADDR
);
3416 /* Stripped frame status of Transmitted Frame */
3417 tsv
->svv
[1] = tx_fstatus
& 0xff;
3422 static int smctr_make_upstream_neighbor_addr(struct net_device
*dev
,
3423 MAC_SUB_VECTOR
*tsv
)
3425 struct net_local
*tp
= netdev_priv(dev
);
3427 smctr_get_upstream_neighbor_addr(dev
);
3429 tsv
->svi
= UPSTREAM_NEIGHBOR_ADDRESS
;
3430 tsv
->svl
= S_UPSTREAM_NEIGHBOR_ADDRESS
;
3432 tsv
->svv
[0] = MSB(tp
->misc_command_data
[0]);
3433 tsv
->svv
[1] = LSB(tp
->misc_command_data
[0]);
3435 tsv
->svv
[2] = MSB(tp
->misc_command_data
[1]);
3436 tsv
->svv
[3] = LSB(tp
->misc_command_data
[1]);
3438 tsv
->svv
[4] = MSB(tp
->misc_command_data
[2]);
3439 tsv
->svv
[5] = LSB(tp
->misc_command_data
[2]);
3444 static int smctr_make_wrap_data(struct net_device
*dev
, MAC_SUB_VECTOR
*tsv
)
3446 tsv
->svi
= WRAP_DATA
;
3447 tsv
->svl
= S_WRAP_DATA
;
3453 * Open/initialize the board. This is called sometime after
3454 * booting when the 'ifconfig' program is run.
3456 * This routine should set everything up anew at each open, even
3457 * registers that "should" only need to be set once at boot, so that
3458 * there is non-reboot way to recover if something goes wrong.
3460 static int smctr_open(struct net_device
*dev
)
3464 if(smctr_debug
> 10)
3465 printk(KERN_DEBUG
"%s: smctr_open\n", dev
->name
);
3467 err
= smctr_init_adapter(dev
);
3474 /* Interrupt driven open of Token card. */
3475 static int smctr_open_tr(struct net_device
*dev
)
3477 struct net_local
*tp
= netdev_priv(dev
);
3478 unsigned long flags
;
3481 if(smctr_debug
> 10)
3482 printk(KERN_DEBUG
"%s: smctr_open_tr\n", dev
->name
);
3484 /* Now we can actually open the adapter. */
3485 if(tp
->status
== OPEN
)
3487 if(tp
->status
!= INITIALIZED
)
3490 /* FIXME: it would work a lot better if we masked the irq sources
3491 on the card here, then we could skip the locking and poll nicely */
3492 spin_lock_irqsave(&tp
->lock
, flags
);
3494 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
3496 if((err
= smctr_issue_resume_rx_fcb_cmd(dev
, (short)MAC_QUEUE
)))
3499 if((err
= smctr_issue_resume_rx_bdb_cmd(dev
, (short)MAC_QUEUE
)))
3502 if((err
= smctr_issue_resume_rx_fcb_cmd(dev
, (short)NON_MAC_QUEUE
)))
3505 if((err
= smctr_issue_resume_rx_bdb_cmd(dev
, (short)NON_MAC_QUEUE
)))
3508 tp
->status
= CLOSED
;
3510 /* Insert into the Ring or Enter Loopback Mode. */
3511 if((tp
->mode_bits
& LOOPING_MODE_MASK
) == LOOPBACK_MODE_1
)
3513 tp
->status
= CLOSED
;
3515 if(!(err
= smctr_issue_trc_loopback_cmd(dev
)))
3517 if(!(err
= smctr_wait_cmd(dev
)))
3521 smctr_status_chg(dev
);
3525 if((tp
->mode_bits
& LOOPING_MODE_MASK
) == LOOPBACK_MODE_2
)
3527 tp
->status
= CLOSED
;
3528 if(!(err
= smctr_issue_tri_loopback_cmd(dev
)))
3530 if(!(err
= smctr_wait_cmd(dev
)))
3534 smctr_status_chg(dev
);
3538 if((tp
->mode_bits
& LOOPING_MODE_MASK
)
3541 tp
->status
= CLOSED
;
3542 if(!(err
= smctr_lobe_media_test_cmd(dev
)))
3544 if(!(err
= smctr_wait_cmd(dev
)))
3547 smctr_status_chg(dev
);
3551 if(!(err
= smctr_lobe_media_test(dev
)))
3552 err
= smctr_issue_insert_cmd(dev
);
3555 if(err
== LOBE_MEDIA_TEST_FAILED
)
3556 printk(KERN_WARNING
"%s: Lobe Media Test Failure - Check cable?\n", dev
->name
);
3563 spin_unlock_irqrestore(&tp
->lock
, flags
);
3568 /* Check for a network adapter of this type,
3569 * and return device structure if one exists.
3571 struct net_device __init
*smctr_probe(int unit
)
3573 struct net_device
*dev
= alloc_trdev(sizeof(struct net_local
));
3574 static const unsigned ports
[] = {
3575 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3576 0x320, 0x340, 0x360, 0x380, 0
3578 const unsigned *port
;
3582 return ERR_PTR(-ENOMEM
);
3585 sprintf(dev
->name
, "tr%d", unit
);
3586 netdev_boot_setup_check(dev
);
3589 if (dev
->base_addr
> 0x1ff) /* Check a single specified location. */
3590 err
= smctr_probe1(dev
, dev
->base_addr
);
3591 else if(dev
->base_addr
!= 0) /* Don't probe at all. */
3594 for (port
= ports
; *port
; port
++) {
3595 err
= smctr_probe1(dev
, *port
);
3602 err
= register_netdev(dev
);
3607 #ifdef CONFIG_MCA_LEGACY
3608 { struct net_local
*tp
= netdev_priv(dev
);
3610 mca_mark_as_unused(tp
->slot_num
);
3613 release_region(dev
->base_addr
, SMCTR_IO_EXTENT
);
3614 free_irq(dev
->irq
, dev
);
3617 return ERR_PTR(err
);
3620 static const struct net_device_ops smctr_netdev_ops
= {
3621 .ndo_open
= smctr_open
,
3622 .ndo_stop
= smctr_close
,
3623 .ndo_start_xmit
= smctr_send_packet
,
3624 .ndo_tx_timeout
= smctr_timeout
,
3625 .ndo_get_stats
= smctr_get_stats
,
3626 .ndo_set_multicast_list
= smctr_set_multicast_list
,
3629 static int __init
smctr_probe1(struct net_device
*dev
, int ioaddr
)
3631 static unsigned version_printed
;
3632 struct net_local
*tp
= netdev_priv(dev
);
3636 if(smctr_debug
&& version_printed
++ == 0)
3639 spin_lock_init(&tp
->lock
);
3640 dev
->base_addr
= ioaddr
;
3642 /* Actually detect an adapter now. */
3643 err
= smctr_chk_isa(dev
);
3646 if ((err
= smctr_chk_mca(dev
)) < 0) {
3652 tp
= netdev_priv(dev
);
3653 dev
->mem_start
= tp
->ram_base
;
3654 dev
->mem_end
= dev
->mem_start
+ 0x10000;
3655 ram
= (__u32
*)phys_to_virt(dev
->mem_start
);
3656 tp
->ram_access
= *(__u32
*)&ram
;
3657 tp
->status
= NOT_INITIALIZED
;
3659 err
= smctr_load_firmware(dev
);
3660 if(err
!= UCODE_PRESENT
&& err
!= SUCCESS
)
3662 printk(KERN_ERR
"%s: Firmware load failed (%d)\n", dev
->name
, err
);
3667 /* Allow user to specify ring speed on module insert. */
3669 tp
->media_type
= MEDIA_UTP_4
;
3671 tp
->media_type
= MEDIA_UTP_16
;
3673 printk(KERN_INFO
"%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3674 dev
->name
, smctr_name
, smctr_model
,
3675 (unsigned int)dev
->base_addr
,
3676 dev
->irq
, tp
->rom_base
, tp
->ram_base
);
3678 dev
->netdev_ops
= &smctr_netdev_ops
;
3679 dev
->watchdog_timeo
= HZ
;
3686 static int smctr_process_rx_packet(MAC_HEADER
*rmf
, __u16 size
,
3687 struct net_device
*dev
, __u16 rx_status
)
3689 struct net_local
*tp
= netdev_priv(dev
);
3690 struct sk_buff
*skb
;
3691 __u16 rcode
, correlator
;
3695 rmf
->vl
= SWAP_BYTES(rmf
->vl
);
3696 if(rx_status
& FCB_RX_STATUS_DA_MATCHED
)
3700 /* Received MAC Frames Processed by RS. */
3702 if((rcode
= smctr_rcv_init(dev
, rmf
, &correlator
)) == HARDWARE_FAILED
)
3707 if((err
= smctr_send_rsp(dev
, rmf
, rcode
,
3715 if((rcode
= smctr_rcv_chg_param(dev
, rmf
,
3716 &correlator
)) ==HARDWARE_FAILED
)
3721 if((err
= smctr_send_rsp(dev
, rmf
, rcode
,
3729 if((rcode
= smctr_rcv_rq_addr_state_attch(dev
,
3730 rmf
, &correlator
)) != POSITIVE_ACK
)
3732 if(rcode
== HARDWARE_FAILED
)
3735 return (smctr_send_rsp(dev
, rmf
,
3736 rcode
, correlator
));
3739 if((err
= smctr_send_rpt_addr(dev
, rmf
,
3747 if((rcode
= smctr_rcv_rq_addr_state_attch(dev
,
3748 rmf
, &correlator
)) != POSITIVE_ACK
)
3750 if(rcode
== HARDWARE_FAILED
)
3753 return (smctr_send_rsp(dev
, rmf
,
3758 if((err
= smctr_send_rpt_attch(dev
, rmf
,
3766 if((rcode
= smctr_rcv_rq_addr_state_attch(dev
,
3767 rmf
, &correlator
)) != POSITIVE_ACK
)
3769 if(rcode
== HARDWARE_FAILED
)
3772 return (smctr_send_rsp(dev
, rmf
,
3777 if((err
= smctr_send_rpt_state(dev
, rmf
,
3785 __u16
uninitialized_var(tx_fstatus
);
3787 if((rcode
= smctr_rcv_tx_forward(dev
, rmf
))
3790 if(rcode
== HARDWARE_FAILED
)
3793 return (smctr_send_rsp(dev
, rmf
,
3798 if((err
= smctr_send_tx_forward(dev
, rmf
,
3799 &tx_fstatus
)) == HARDWARE_FAILED
)
3804 if(err
== A_FRAME_WAS_FORWARDED
)
3806 if((err
= smctr_send_rpt_tx_forward(dev
,
3816 /* Received MAC Frames Processed by CRS/REM/RPS. */
3821 case RPT_ACTIVE_ERR
:
3829 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3832 if(!(tp
->receive_mask
& ACCEPT_ATT_MAC_FRAMES
))
3834 rcode
= smctr_rcv_unknown(dev
, rmf
,
3836 if((err
= smctr_send_rsp(dev
, rmf
,rcode
,
3848 /* 1. DA doesn't match (Promiscuous Mode).
3849 * 2. Parse for Extended MAC Frame Type.
3867 case RPT_ACTIVE_ERR
:
3876 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3877 * ACCEPT_ATT_MAC_FRAMES is set.
3879 if(((tp
->receive_mask
& ACCEPT_ATT_MAC_FRAMES
)
3880 && (xframe
== (__u8
)0))
3881 || ((tp
->receive_mask
& ACCEPT_EXT_MAC_FRAMES
)
3882 && (xframe
== (__u8
)1)))
3884 rmf
->vl
= SWAP_BYTES(rmf
->vl
);
3886 if (!(skb
= dev_alloc_skb(size
)))
3890 /* Slide data into a sleek skb. */
3891 skb_put(skb
, skb
->len
);
3892 skb_copy_to_linear_data(skb
, rmf
, skb
->len
);
3894 /* Update Counters */
3895 tp
->MacStat
.rx_packets
++;
3896 tp
->MacStat
.rx_bytes
+= skb
->len
;
3898 /* Kick the packet on up. */
3899 skb
->protocol
= tr_type_trans(skb
, dev
);
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
;
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
)
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)));
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
3965 word_read
= *(__u16
*)(pword
+ j
);
3966 if(word_read
!= word_pattern
)
3970 err_word
= word_read
;
3971 err_pattern
= word_pattern
;
3972 return (RAM_TEST_FAILED
);
3977 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
3982 static int smctr_rcv_chg_param(struct net_device
*dev
, MAC_HEADER
*rmf
,
3985 MAC_SUB_VECTOR
*rsv
;
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
))
4006 svectors
|= F_CORRELATOR
;
4007 rcode
= smctr_set_corr(dev
, rsv
, correlator
);
4010 case LOCAL_RING_NUMBER
:
4011 svectors
|= F_LOCAL_RING_NUMBER
;
4012 rcode
= smctr_set_local_ring_num(dev
, rsv
);
4015 case ASSIGN_PHYSICAL_DROP
:
4016 svectors
|= F_ASSIGN_PHYSICAL_DROP
;
4017 rcode
= smctr_set_phy_drop(dev
, rsv
);
4020 case ERROR_TIMER_VALUE
:
4021 svectors
|= F_ERROR_TIMER_VALUE
;
4022 rcode
= smctr_set_error_timer_value(dev
, rsv
);
4025 case AUTHORIZED_FUNCTION_CLASS
:
4026 svectors
|= F_AUTHORIZED_FUNCTION_CLASS
;
4027 rcode
= smctr_set_auth_funct_class(dev
, rsv
);
4030 case AUTHORIZED_ACCESS_PRIORITY
:
4031 svectors
|= F_AUTHORIZED_ACCESS_PRIORITY
;
4032 rcode
= smctr_set_auth_access_pri(dev
, rsv
);
4036 rcode
= E_SUB_VECTOR_UNKNOWN
;
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
4055 rcode
= E_VECTOR_LENGTH_ERROR
;
4058 /* Let Sender Know if Expected SVID Missing */
4059 if((svectors
& R_CHG_PARM
) ^ R_CHG_PARM
)
4060 rcode
= E_MISSING_SUB_VECTOR
;
4067 static int smctr_rcv_init(struct net_device
*dev
, MAC_HEADER
*rmf
,
4070 MAC_SUB_VECTOR
*rsv
;
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
))
4091 svectors
|= F_CORRELATOR
;
4092 rcode
= smctr_set_corr(dev
, rsv
, correlator
);
4095 case LOCAL_RING_NUMBER
:
4096 svectors
|= F_LOCAL_RING_NUMBER
;
4097 rcode
= smctr_set_local_ring_num(dev
, rsv
);
4100 case ASSIGN_PHYSICAL_DROP
:
4101 svectors
|= F_ASSIGN_PHYSICAL_DROP
;
4102 rcode
= smctr_set_phy_drop(dev
, rsv
);
4105 case ERROR_TIMER_VALUE
:
4106 svectors
|= F_ERROR_TIMER_VALUE
;
4107 rcode
= smctr_set_error_timer_value(dev
, rsv
);
4111 rcode
= E_SUB_VECTOR_UNKNOWN
;
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
4130 rcode
= E_VECTOR_LENGTH_ERROR
;
4133 /* Let Sender Know if Expected SV Missing */
4134 if((svectors
& R_INIT
) ^ R_INIT
)
4135 rcode
= E_MISSING_SUB_VECTOR
;
4142 static int smctr_rcv_tx_forward(struct net_device
*dev
, MAC_HEADER
*rmf
)
4144 MAC_SUB_VECTOR
*rsv
;
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
))
4165 svectors
|= F_FRAME_FORWARD
;
4166 rcode
= smctr_set_frame_forward(dev
, rsv
,
4171 rcode
= E_SUB_VECTOR_UNKNOWN
;
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
4190 rcode
= E_VECTOR_LENGTH_ERROR
;
4193 /* Let Sender Know if Expected SV Missing */
4194 if((svectors
& R_TX_FORWARD
) ^ R_TX_FORWARD
)
4195 rcode
= E_MISSING_SUB_VECTOR
;
4202 static int smctr_rcv_rq_addr_state_attch(struct net_device
*dev
,
4203 MAC_HEADER
*rmf
, __u16
*correlator
)
4205 MAC_SUB_VECTOR
*rsv
;
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
))
4222 svectors
|= F_CORRELATOR
;
4223 rcode
= smctr_set_corr(dev
, rsv
, correlator
);
4227 rcode
= E_SUB_VECTOR_UNKNOWN
;
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
4246 rcode
= E_VECTOR_LENGTH_ERROR
;
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
;
4259 static int smctr_rcv_unknown(struct net_device
*dev
, MAC_HEADER
*rmf
,
4262 MAC_SUB_VECTOR
*rsv
;
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))
4279 smctr_set_corr(dev
, rsv
, correlator
);
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.
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
);
4320 static int smctr_restart_tx_chain(struct net_device
*dev
, short queue
)
4322 struct net_local
*tp
= netdev_priv(dev
);
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
);
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;
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
4369 printk(KERN_INFO
"%s: Incorrect ring speed switching.\n",
4371 smctr_set_ring_speed(dev
);
4376 if(!(tp
->ring_status_flags
& RING_STATUS_CHANGED
))
4379 switch(tp
->ring_status
)
4382 printk(KERN_INFO
"%s: Ring Recovery\n", dev
->name
);
4385 case SINGLE_STATION
:
4386 printk(KERN_INFO
"%s: Single Statinon\n", dev
->name
);
4389 case COUNTER_OVERFLOW
:
4390 printk(KERN_INFO
"%s: Counter Overflow\n", dev
->name
);
4393 case REMOVE_RECEIVED
:
4394 printk(KERN_INFO
"%s: Remove Received\n", dev
->name
);
4397 case AUTO_REMOVAL_ERROR
:
4398 printk(KERN_INFO
"%s: Auto Remove Error\n", dev
->name
);
4401 case LOBE_WIRE_FAULT
:
4402 printk(KERN_INFO
"%s: Lobe Wire Fault\n", dev
->name
);
4405 case TRANSMIT_BEACON
:
4406 printk(KERN_INFO
"%s: Transmit Beacon\n", dev
->name
);
4410 printk(KERN_INFO
"%s: Soft Error\n", dev
->name
);
4414 printk(KERN_INFO
"%s: Hard Error\n", dev
->name
);
4418 printk(KERN_INFO
"%s: Signal Loss\n", dev
->name
);
4422 printk(KERN_INFO
"%s: Unknown ring status change\n",
4430 static int smctr_rx_frame(struct net_device
*dev
)
4432 struct net_local
*tp
= netdev_priv(dev
);
4433 __u16 queue
, status
, rx_size
, err
= 0;
4436 if(smctr_debug
> 10)
4437 printk(KERN_DEBUG
"%s: smctr_rx_frame\n", dev
->name
);
4439 queue
= tp
->receive_queue_number
;
4441 while((status
= tp
->rx_fcb_curr
[queue
]->frame_status
) != SUCCESS
)
4443 err
= HARDWARE_FAILED
;
4445 if(((status
& 0x007f) == 0)
4446 || ((tp
->receive_mask
& ACCEPT_ERR_PACKETS
) != 0))
4448 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4449 rx_size
= tp
->rx_fcb_curr
[queue
]->frame_length
- 5;
4451 pbuff
= smctr_get_rx_pointer(dev
, queue
);
4453 smctr_set_page(dev
, pbuff
);
4454 smctr_disable_16bit(dev
);
4456 /* pbuff points to addr within one page */
4457 pbuff
= (__u8
*)PAGE_POINTER(pbuff
);
4459 if(queue
== NON_MAC_QUEUE
)
4461 struct sk_buff
*skb
;
4463 skb
= dev_alloc_skb(rx_size
);
4465 skb_put(skb
, rx_size
);
4467 skb_copy_to_linear_data(skb
, pbuff
, rx_size
);
4469 /* Update Counters */
4470 tp
->MacStat
.rx_packets
++;
4471 tp
->MacStat
.rx_bytes
+= skb
->len
;
4473 /* Kick the packet on up. */
4474 skb
->protocol
= tr_type_trans(skb
, dev
);
4480 smctr_process_rx_packet((MAC_HEADER
*)pbuff
,
4481 rx_size
, dev
, status
);
4484 smctr_enable_16bit(dev
);
4485 smctr_set_page(dev
, (__u8
*)tp
->ram_access
);
4486 smctr_update_rx_chain(dev
, queue
);
4495 static int smctr_send_dat(struct net_device
*dev
)
4497 struct net_local
*tp
= netdev_priv(dev
);
4498 unsigned int i
, err
;
4502 if(smctr_debug
> 10)
4503 printk(KERN_DEBUG
"%s: smctr_send_dat\n", dev
->name
);
4505 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
,
4506 sizeof(MAC_HEADER
))) == (FCBlock
*)(-1L))
4508 return (OUT_OF_RESOURCES
);
4511 /* Initialize DAT Data Fields. */
4512 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4513 tmf
->ac
= MSB(AC_FC_DAT
);
4514 tmf
->fc
= LSB(AC_FC_DAT
);
4516 for(i
= 0; i
< 6; i
++)
4518 tmf
->sa
[i
] = dev
->dev_addr
[i
];
4519 tmf
->da
[i
] = dev
->dev_addr
[i
];
4524 tmf
->dc_sc
= DC_RS
| SC_RS
;
4526 tmf
->vl
= SWAP_BYTES(tmf
->vl
);
4528 /* Start Transmit. */
4529 if((err
= smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
)))
4532 /* Wait for Transmit to Complete */
4533 for(i
= 0; i
< 10000; i
++)
4535 if(fcb
->frame_status
& FCB_COMMAND_DONE
)
4540 /* Check if GOOD frame Tx'ed. */
4541 if(!(fcb
->frame_status
& FCB_COMMAND_DONE
)
4542 || fcb
->frame_status
& (FCB_TX_STATUS_E
| FCB_TX_AC_BITS
))
4544 return (INITIALIZE_FAILED
);
4547 /* De-allocated Tx FCB and Frame Buffer
4548 * The FCB must be de-allocated manually if executing with
4549 * interrupts disabled, other wise the ISR (LM_Service_Events)
4550 * will de-allocate it when the interrupt occurs.
4552 tp
->tx_queue_status
[MAC_QUEUE
] = NOT_TRANSMITING
;
4553 smctr_update_tx_chain(dev
, fcb
, MAC_QUEUE
);
4558 static void smctr_timeout(struct net_device
*dev
)
4561 * If we get here, some higher level has decided we are broken.
4562 * There should really be a "kick me" function call instead.
4564 * Resetting the token ring adapter takes a long time so just
4565 * fake transmission time and go on trying. Our own timeout
4566 * routine is in sktr_timer_chk()
4568 dev
->trans_start
= jiffies
;
4569 netif_wake_queue(dev
);
4573 * Gets skb from system, queues it and checks if it can be sent
4575 static netdev_tx_t
smctr_send_packet(struct sk_buff
*skb
,
4576 struct net_device
*dev
)
4578 struct net_local
*tp
= netdev_priv(dev
);
4580 if(smctr_debug
> 10)
4581 printk(KERN_DEBUG
"%s: smctr_send_packet\n", dev
->name
);
4584 * Block a transmit overlap
4587 netif_stop_queue(dev
);
4589 if(tp
->QueueSkb
== 0)
4590 return NETDEV_TX_BUSY
; /* Return with tbusy set: queue full */
4593 skb_queue_tail(&tp
->SendSkbQueue
, skb
);
4594 smctr_hardware_send_packet(dev
, tp
);
4595 if(tp
->QueueSkb
> 0)
4596 netif_wake_queue(dev
);
4598 return NETDEV_TX_OK
;
4601 static int smctr_send_lobe_media_test(struct net_device
*dev
)
4603 struct net_local
*tp
= netdev_priv(dev
);
4604 MAC_SUB_VECTOR
*tsv
;
4610 if(smctr_debug
> 15)
4611 printk(KERN_DEBUG
"%s: smctr_send_lobe_media_test\n", dev
->name
);
4613 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, sizeof(struct trh_hdr
)
4614 + S_WRAP_DATA
+ S_WRAP_DATA
)) == (FCBlock
*)(-1L))
4616 return (OUT_OF_RESOURCES
);
4619 /* Initialize DAT Data Fields. */
4620 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4621 tmf
->ac
= MSB(AC_FC_LOBE_MEDIA_TEST
);
4622 tmf
->fc
= LSB(AC_FC_LOBE_MEDIA_TEST
);
4624 for(i
= 0; i
< 6; i
++)
4627 tmf
->sa
[i
] = dev
->dev_addr
[i
];
4630 tmf
->vc
= LOBE_MEDIA_TEST
;
4631 tmf
->dc_sc
= DC_RS
| SC_RS
;
4634 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tmf
+ sizeof(MAC_HEADER
));
4635 smctr_make_wrap_data(dev
, tsv
);
4636 tmf
->vl
+= tsv
->svl
;
4638 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4639 smctr_make_wrap_data(dev
, tsv
);
4640 tmf
->vl
+= tsv
->svl
;
4642 /* Start Transmit. */
4643 tmf
->vl
= SWAP_BYTES(tmf
->vl
);
4644 if((err
= smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
)))
4647 /* Wait for Transmit to Complete. (10 ms). */
4648 for(i
=0; i
< 10000; i
++)
4650 if(fcb
->frame_status
& FCB_COMMAND_DONE
)
4655 /* Check if GOOD frame Tx'ed */
4656 if(!(fcb
->frame_status
& FCB_COMMAND_DONE
)
4657 || fcb
->frame_status
& (FCB_TX_STATUS_E
| FCB_TX_AC_BITS
))
4659 return (LOBE_MEDIA_TEST_FAILED
);
4662 /* De-allocated Tx FCB and Frame Buffer
4663 * The FCB must be de-allocated manually if executing with
4664 * interrupts disabled, other wise the ISR (LM_Service_Events)
4665 * will de-allocate it when the interrupt occurs.
4667 tp
->tx_queue_status
[MAC_QUEUE
] = NOT_TRANSMITING
;
4668 smctr_update_tx_chain(dev
, fcb
, MAC_QUEUE
);
4673 static int smctr_send_rpt_addr(struct net_device
*dev
, MAC_HEADER
*rmf
,
4677 MAC_SUB_VECTOR
*tsv
;
4680 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, sizeof(MAC_HEADER
)
4681 + S_CORRELATOR
+ S_PHYSICAL_DROP
+ S_UPSTREAM_NEIGHBOR_ADDRESS
4682 + S_ADDRESS_MODIFER
+ S_GROUP_ADDRESS
+ S_FUNCTIONAL_ADDRESS
))
4683 == (FCBlock
*)(-1L))
4688 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4690 tmf
->dc_sc
= (rmf
->dc_sc
& SC_MASK
) << 4;
4693 smctr_make_8025_hdr(dev
, rmf
, tmf
, AC_FC_RPT_ADDR
);
4695 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tmf
+ sizeof(MAC_HEADER
));
4696 smctr_make_corr(dev
, tsv
, correlator
);
4698 tmf
->vl
+= tsv
->svl
;
4699 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4700 smctr_make_phy_drop_num(dev
, tsv
);
4702 tmf
->vl
+= tsv
->svl
;
4703 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4704 smctr_make_upstream_neighbor_addr(dev
, tsv
);
4706 tmf
->vl
+= tsv
->svl
;
4707 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4708 smctr_make_addr_mod(dev
, tsv
);
4710 tmf
->vl
+= tsv
->svl
;
4711 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4712 smctr_make_group_addr(dev
, tsv
);
4714 tmf
->vl
+= tsv
->svl
;
4715 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4716 smctr_make_funct_addr(dev
, tsv
);
4718 tmf
->vl
+= tsv
->svl
;
4720 /* Subtract out MVID and MVL which is
4721 * include in both vl and MAC_HEADER
4723 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4724 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4726 tmf
->vl
= SWAP_BYTES(tmf
->vl
);
4728 return (smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
));
4731 static int smctr_send_rpt_attch(struct net_device
*dev
, MAC_HEADER
*rmf
,
4735 MAC_SUB_VECTOR
*tsv
;
4738 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, sizeof(MAC_HEADER
)
4739 + S_CORRELATOR
+ S_PRODUCT_INSTANCE_ID
+ S_FUNCTIONAL_ADDRESS
4740 + S_AUTHORIZED_FUNCTION_CLASS
+ S_AUTHORIZED_ACCESS_PRIORITY
))
4741 == (FCBlock
*)(-1L))
4746 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4747 tmf
->vc
= RPT_ATTCH
;
4748 tmf
->dc_sc
= (rmf
->dc_sc
& SC_MASK
) << 4;
4751 smctr_make_8025_hdr(dev
, rmf
, tmf
, AC_FC_RPT_ATTCH
);
4753 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tmf
+ sizeof(MAC_HEADER
));
4754 smctr_make_corr(dev
, tsv
, correlator
);
4756 tmf
->vl
+= tsv
->svl
;
4757 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4758 smctr_make_product_id(dev
, tsv
);
4760 tmf
->vl
+= tsv
->svl
;
4761 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4762 smctr_make_funct_addr(dev
, tsv
);
4764 tmf
->vl
+= tsv
->svl
;
4765 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4766 smctr_make_auth_funct_class(dev
, tsv
);
4768 tmf
->vl
+= tsv
->svl
;
4769 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4770 smctr_make_access_pri(dev
, tsv
);
4772 tmf
->vl
+= tsv
->svl
;
4774 /* Subtract out MVID and MVL which is
4775 * include in both vl and MAC_HEADER
4777 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4778 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4780 tmf
->vl
= SWAP_BYTES(tmf
->vl
);
4782 return (smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
));
4785 static int smctr_send_rpt_state(struct net_device
*dev
, MAC_HEADER
*rmf
,
4789 MAC_SUB_VECTOR
*tsv
;
4792 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, sizeof(MAC_HEADER
)
4793 + S_CORRELATOR
+ S_RING_STATION_VERSION_NUMBER
4794 + S_RING_STATION_STATUS
+ S_STATION_IDENTIFER
))
4795 == (FCBlock
*)(-1L))
4800 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4801 tmf
->vc
= RPT_STATE
;
4802 tmf
->dc_sc
= (rmf
->dc_sc
& SC_MASK
) << 4;
4805 smctr_make_8025_hdr(dev
, rmf
, tmf
, AC_FC_RPT_STATE
);
4807 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tmf
+ sizeof(MAC_HEADER
));
4808 smctr_make_corr(dev
, tsv
, correlator
);
4810 tmf
->vl
+= tsv
->svl
;
4811 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4812 smctr_make_ring_station_version(dev
, tsv
);
4814 tmf
->vl
+= tsv
->svl
;
4815 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4816 smctr_make_ring_station_status(dev
, tsv
);
4818 tmf
->vl
+= tsv
->svl
;
4819 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4820 smctr_make_station_id(dev
, tsv
);
4822 tmf
->vl
+= tsv
->svl
;
4824 /* Subtract out MVID and MVL which is
4825 * include in both vl and MAC_HEADER
4827 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4828 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4830 tmf
->vl
= SWAP_BYTES(tmf
->vl
);
4832 return (smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
));
4835 static int smctr_send_rpt_tx_forward(struct net_device
*dev
,
4836 MAC_HEADER
*rmf
, __u16 tx_fstatus
)
4839 MAC_SUB_VECTOR
*tsv
;
4842 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, sizeof(MAC_HEADER
)
4843 + S_TRANSMIT_STATUS_CODE
)) == (FCBlock
*)(-1L))
4848 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4849 tmf
->vc
= RPT_TX_FORWARD
;
4850 tmf
->dc_sc
= (rmf
->dc_sc
& SC_MASK
) << 4;
4853 smctr_make_8025_hdr(dev
, rmf
, tmf
, AC_FC_RPT_TX_FORWARD
);
4855 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tmf
+ sizeof(MAC_HEADER
));
4856 smctr_make_tx_status_code(dev
, tsv
, tx_fstatus
);
4858 tmf
->vl
+= tsv
->svl
;
4860 /* Subtract out MVID and MVL which is
4861 * include in both vl and MAC_HEADER
4863 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4864 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4866 tmf
->vl
= SWAP_BYTES(tmf
->vl
);
4868 return(smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
));
4871 static int smctr_send_rsp(struct net_device
*dev
, MAC_HEADER
*rmf
,
4872 __u16 rcode
, __u16 correlator
)
4875 MAC_SUB_VECTOR
*tsv
;
4878 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, sizeof(MAC_HEADER
)
4879 + S_CORRELATOR
+ S_RESPONSE_CODE
)) == (FCBlock
*)(-1L))
4884 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4886 tmf
->dc_sc
= (rmf
->dc_sc
& SC_MASK
) << 4;
4889 smctr_make_8025_hdr(dev
, rmf
, tmf
, AC_FC_RSP
);
4891 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tmf
+ sizeof(MAC_HEADER
));
4892 smctr_make_corr(dev
, tsv
, correlator
);
4897 static int smctr_send_rq_init(struct net_device
*dev
)
4899 struct net_local
*tp
= netdev_priv(dev
);
4901 MAC_SUB_VECTOR
*tsv
;
4903 unsigned int i
, count
= 0;
4908 if(((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, sizeof(MAC_HEADER
)
4909 + S_PRODUCT_INSTANCE_ID
+ S_UPSTREAM_NEIGHBOR_ADDRESS
4910 + S_RING_STATION_VERSION_NUMBER
+ S_ADDRESS_MODIFER
))
4911 == (FCBlock
*)(-1L)))
4916 tmf
= (MAC_HEADER
*)fcb
->bdb_ptr
->data_block_ptr
;
4918 tmf
->dc_sc
= DC_RPS
| SC_RS
;
4921 smctr_make_8025_hdr(dev
, NULL
, tmf
, AC_FC_RQ_INIT
);
4923 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tmf
+ sizeof(MAC_HEADER
));
4924 smctr_make_product_id(dev
, tsv
);
4926 tmf
->vl
+= tsv
->svl
;
4927 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4928 smctr_make_upstream_neighbor_addr(dev
, tsv
);
4930 tmf
->vl
+= tsv
->svl
;
4931 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4932 smctr_make_ring_station_version(dev
, tsv
);
4934 tmf
->vl
+= tsv
->svl
;
4935 tsv
= (MAC_SUB_VECTOR
*)((__u32
)tsv
+ tsv
->svl
);
4936 smctr_make_addr_mod(dev
, tsv
);
4938 tmf
->vl
+= tsv
->svl
;
4940 /* Subtract out MVID and MVL which is
4941 * include in both vl and MAC_HEADER
4943 /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4944 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4946 tmf
->vl
= SWAP_BYTES(tmf
->vl
);
4948 if((err
= smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
)))
4951 /* Wait for Transmit to Complete */
4952 for(i
= 0; i
< 10000; i
++)
4954 if(fcb
->frame_status
& FCB_COMMAND_DONE
)
4959 /* Check if GOOD frame Tx'ed */
4960 fstatus
= fcb
->frame_status
;
4962 if(!(fstatus
& FCB_COMMAND_DONE
))
4963 return (HARDWARE_FAILED
);
4965 if(!(fstatus
& FCB_TX_STATUS_E
))
4968 /* De-allocated Tx FCB and Frame Buffer
4969 * The FCB must be de-allocated manually if executing with
4970 * interrupts disabled, other wise the ISR (LM_Service_Events)
4971 * will de-allocate it when the interrupt occurs.
4973 tp
->tx_queue_status
[MAC_QUEUE
] = NOT_TRANSMITING
;
4974 smctr_update_tx_chain(dev
, fcb
, MAC_QUEUE
);
4975 } while(count
< 4 && ((fstatus
& FCB_TX_AC_BITS
) ^ FCB_TX_AC_BITS
));
4977 return (smctr_join_complete_state(dev
));
4980 static int smctr_send_tx_forward(struct net_device
*dev
, MAC_HEADER
*rmf
,
4983 struct net_local
*tp
= netdev_priv(dev
);
4988 /* Check if this is the END POINT of the Transmit Forward Chain. */
4992 /* Allocate Transmit FCB only by requesting 0 bytes
4995 if((fcb
= smctr_get_tx_fcb(dev
, MAC_QUEUE
, 0)) == (FCBlock
*)(-1L))
4998 /* Set pointer to Transmit Frame Buffer to the data
4999 * portion of the received TX Forward frame, making
5000 * sure to skip over the Vector Code (vc) and Vector
5003 fcb
->bdb_ptr
->trc_data_block_ptr
= TRC_POINTER((__u32
)rmf
5004 + sizeof(MAC_HEADER
) + 2);
5005 fcb
->bdb_ptr
->data_block_ptr
= (__u16
*)((__u32
)rmf
5006 + sizeof(MAC_HEADER
) + 2);
5008 fcb
->frame_length
= rmf
->vl
- 4 - 2;
5009 fcb
->bdb_ptr
->buffer_length
= rmf
->vl
- 4 - 2;
5011 if((err
= smctr_trc_send_packet(dev
, fcb
, MAC_QUEUE
)))
5014 /* Wait for Transmit to Complete */
5015 for(i
= 0; i
< 10000; i
++)
5017 if(fcb
->frame_status
& FCB_COMMAND_DONE
)
5022 /* Check if GOOD frame Tx'ed */
5023 if(!(fcb
->frame_status
& FCB_COMMAND_DONE
))
5025 if((err
= smctr_issue_resume_tx_fcb_cmd(dev
, MAC_QUEUE
)))
5028 for(i
= 0; i
< 10000; i
++)
5030 if(fcb
->frame_status
& FCB_COMMAND_DONE
)
5035 if(!(fcb
->frame_status
& FCB_COMMAND_DONE
))
5036 return (HARDWARE_FAILED
);
5039 *tx_fstatus
= fcb
->frame_status
;
5041 return (A_FRAME_WAS_FORWARDED
);
5044 static int smctr_set_auth_access_pri(struct net_device
*dev
,
5045 MAC_SUB_VECTOR
*rsv
)
5047 struct net_local
*tp
= netdev_priv(dev
);
5049 if(rsv
->svl
!= S_AUTHORIZED_ACCESS_PRIORITY
)
5050 return (E_SUB_VECTOR_LENGTH_ERROR
);
5052 tp
->authorized_access_priority
= (rsv
->svv
[0] << 8 | rsv
->svv
[1]);
5054 return (POSITIVE_ACK
);
5057 static int smctr_set_auth_funct_class(struct net_device
*dev
,
5058 MAC_SUB_VECTOR
*rsv
)
5060 struct net_local
*tp
= netdev_priv(dev
);
5062 if(rsv
->svl
!= S_AUTHORIZED_FUNCTION_CLASS
)
5063 return (E_SUB_VECTOR_LENGTH_ERROR
);
5065 tp
->authorized_function_classes
= (rsv
->svv
[0] << 8 | rsv
->svv
[1]);
5067 return (POSITIVE_ACK
);
5070 static int smctr_set_corr(struct net_device
*dev
, MAC_SUB_VECTOR
*rsv
,
5073 if(rsv
->svl
!= S_CORRELATOR
)
5074 return (E_SUB_VECTOR_LENGTH_ERROR
);
5076 *correlator
= (rsv
->svv
[0] << 8 | rsv
->svv
[1]);
5078 return (POSITIVE_ACK
);
5081 static int smctr_set_error_timer_value(struct net_device
*dev
,
5082 MAC_SUB_VECTOR
*rsv
)
5087 if(rsv
->svl
!= S_ERROR_TIMER_VALUE
)
5088 return (E_SUB_VECTOR_LENGTH_ERROR
);
5090 err_tval
= (rsv
->svv
[0] << 8 | rsv
->svv
[1])*10;
5092 smctr_issue_write_word_cmd(dev
, RW_TER_THRESHOLD
, &err_tval
);
5094 if((err
= smctr_wait_cmd(dev
)))
5097 return (POSITIVE_ACK
);
5100 static int smctr_set_frame_forward(struct net_device
*dev
,
5101 MAC_SUB_VECTOR
*rsv
, __u8 dc_sc
)
5103 if((rsv
->svl
< 2) || (rsv
->svl
> S_FRAME_FORWARD
))
5104 return (E_SUB_VECTOR_LENGTH_ERROR
);
5106 if((dc_sc
& DC_MASK
) != DC_CRS
)
5108 if(rsv
->svl
>= 2 && rsv
->svl
< 20)
5109 return (E_TRANSMIT_FORWARD_INVALID
);
5111 if((rsv
->svv
[0] != 0) || (rsv
->svv
[1] != 0))
5112 return (E_TRANSMIT_FORWARD_INVALID
);
5115 return (POSITIVE_ACK
);
5118 static int smctr_set_local_ring_num(struct net_device
*dev
,
5119 MAC_SUB_VECTOR
*rsv
)
5121 struct net_local
*tp
= netdev_priv(dev
);
5123 if(rsv
->svl
!= S_LOCAL_RING_NUMBER
)
5124 return (E_SUB_VECTOR_LENGTH_ERROR
);
5126 if(tp
->ptr_local_ring_num
)
5127 *(__u16
*)(tp
->ptr_local_ring_num
)
5128 = (rsv
->svv
[0] << 8 | rsv
->svv
[1]);
5130 return (POSITIVE_ACK
);
5133 static unsigned short smctr_set_ctrl_attention(struct net_device
*dev
)
5135 struct net_local
*tp
= netdev_priv(dev
);
5136 int ioaddr
= dev
->base_addr
;
5138 if(tp
->bic_type
== BIC_585_CHIP
)
5139 outb((tp
->trc_mask
| HWR_CA
), ioaddr
+ HWR
);
5142 outb((tp
->trc_mask
| CSR_CA
), ioaddr
+ CSR
);
5143 outb(tp
->trc_mask
, ioaddr
+ CSR
);
5149 static void smctr_set_multicast_list(struct net_device
*dev
)
5151 if(smctr_debug
> 10)
5152 printk(KERN_DEBUG
"%s: smctr_set_multicast_list\n", dev
->name
);
5157 static int smctr_set_page(struct net_device
*dev
, __u8
*buf
)
5159 struct net_local
*tp
= netdev_priv(dev
);
5163 tptr
= (__u32
)buf
- (__u32
)tp
->ram_access
;
5164 amask
= (__u8
)((tptr
& PR_PAGE_MASK
) >> 8);
5165 outb(amask
, dev
->base_addr
+ PR
);
5170 static int smctr_set_phy_drop(struct net_device
*dev
, MAC_SUB_VECTOR
*rsv
)
5174 if(rsv
->svl
!= S_PHYSICAL_DROP
)
5175 return (E_SUB_VECTOR_LENGTH_ERROR
);
5177 smctr_issue_write_byte_cmd(dev
, RW_PHYSICAL_DROP_NUMBER
, &rsv
->svv
[0]);
5178 if((err
= smctr_wait_cmd(dev
)))
5181 return (POSITIVE_ACK
);
5184 /* Reset the ring speed to the opposite of what it was. This auto-pilot
5185 * mode requires a complete reset and re-init of the adapter.
5187 static int smctr_set_ring_speed(struct net_device
*dev
)
5189 struct net_local
*tp
= netdev_priv(dev
);
5192 if(tp
->media_type
== MEDIA_UTP_16
)
5193 tp
->media_type
= MEDIA_UTP_4
;
5195 tp
->media_type
= MEDIA_UTP_16
;
5197 smctr_enable_16bit(dev
);
5199 /* Re-Initialize adapter's internal registers */
5200 smctr_reset_adapter(dev
);
5202 if((err
= smctr_init_card_real(dev
)))
5205 smctr_enable_bic_int(dev
);
5207 if((err
= smctr_issue_enable_int_cmd(dev
, TRC_INTERRUPT_ENABLE_MASK
)))
5210 smctr_disable_16bit(dev
);
5215 static int smctr_set_rx_look_ahead(struct net_device
*dev
)
5217 struct net_local
*tp
= netdev_priv(dev
);
5220 if(smctr_debug
> 10)
5221 printk(KERN_DEBUG
"%s: smctr_set_rx_look_ahead_flag\n", dev
->name
);
5223 tp
->adapter_flags
&= ~(FORCED_16BIT_MODE
);
5224 tp
->adapter_flags
|= RX_VALID_LOOKAHEAD
;
5226 if(tp
->adapter_bus
== BUS_ISA16_TYPE
)
5228 sword
= *((__u16
*)(tp
->ram_access
));
5229 *((__u16
*)(tp
->ram_access
)) = 0x1234;
5231 smctr_disable_16bit(dev
);
5232 rword
= *((__u16
*)(tp
->ram_access
));
5233 smctr_enable_16bit(dev
);
5236 tp
->adapter_flags
|= FORCED_16BIT_MODE
;
5238 *((__u16
*)(tp
->ram_access
)) = sword
;
5244 static int smctr_set_trc_reset(int ioaddr
)
5248 r
= inb(ioaddr
+ MSR
);
5249 outb(MSR_RST
| r
, ioaddr
+ MSR
);
5255 * This function can be called if the adapter is busy or not.
5257 static int smctr_setup_single_cmd(struct net_device
*dev
,
5258 __u16 command
, __u16 subcommand
)
5260 struct net_local
*tp
= netdev_priv(dev
);
5263 if(smctr_debug
> 10)
5264 printk(KERN_DEBUG
"%s: smctr_setup_single_cmd\n", dev
->name
);
5266 if((err
= smctr_wait_while_cbusy(dev
)))
5269 if((err
= (unsigned int)smctr_wait_cmd(dev
)))
5272 tp
->acb_head
->cmd_done_status
= 0;
5273 tp
->acb_head
->cmd
= command
;
5274 tp
->acb_head
->subcmd
= subcommand
;
5276 err
= smctr_issue_resume_acb_cmd(dev
);
5282 * This function can not be called with the adapter busy.
5284 static int smctr_setup_single_cmd_w_data(struct net_device
*dev
,
5285 __u16 command
, __u16 subcommand
)
5287 struct net_local
*tp
= netdev_priv(dev
);
5289 tp
->acb_head
->cmd_done_status
= ACB_COMMAND_NOT_DONE
;
5290 tp
->acb_head
->cmd
= command
;
5291 tp
->acb_head
->subcmd
= subcommand
;
5292 tp
->acb_head
->data_offset_lo
5293 = (__u16
)TRC_POINTER(tp
->misc_command_data
);
5295 return(smctr_issue_resume_acb_cmd(dev
));
5298 static char *smctr_malloc(struct net_device
*dev
, __u16 size
)
5300 struct net_local
*tp
= netdev_priv(dev
);
5303 m
= (char *)(tp
->ram_access
+ tp
->sh_mem_used
);
5304 tp
->sh_mem_used
+= (__u32
)size
;
5309 static int smctr_status_chg(struct net_device
*dev
)
5311 struct net_local
*tp
= netdev_priv(dev
);
5313 if(smctr_debug
> 10)
5314 printk(KERN_DEBUG
"%s: smctr_status_chg\n", dev
->name
);
5324 /* Interrupt driven open() completion. XXX */
5326 tp
->group_address_0
= 0;
5327 tp
->group_address
[0] = 0;
5328 tp
->group_address
[1] = 0;
5329 tp
->functional_address_0
= 0;
5330 tp
->functional_address
[0] = 0;
5331 tp
->functional_address
[1] = 0;
5336 printk(KERN_INFO
"%s: status change unknown %x\n",
5337 dev
->name
, tp
->status
);
5344 static int smctr_trc_send_packet(struct net_device
*dev
, FCBlock
*fcb
,
5347 struct net_local
*tp
= netdev_priv(dev
);
5350 if(smctr_debug
> 10)
5351 printk(KERN_DEBUG
"%s: smctr_trc_send_packet\n", dev
->name
);
5353 fcb
->info
= FCB_CHAIN_END
| FCB_ENABLE_TFS
;
5354 if(tp
->num_tx_fcbs
[queue
] != 1)
5355 fcb
->back_ptr
->info
= FCB_INTERRUPT_ENABLE
| FCB_ENABLE_TFS
;
5357 if(tp
->tx_queue_status
[queue
] == NOT_TRANSMITING
)
5359 tp
->tx_queue_status
[queue
] = TRANSMITING
;
5360 err
= smctr_issue_resume_tx_fcb_cmd(dev
, queue
);
5366 static __u16
smctr_tx_complete(struct net_device
*dev
, __u16 queue
)
5368 struct net_local
*tp
= netdev_priv(dev
);
5369 __u16 status
, err
= 0;
5372 if(smctr_debug
> 10)
5373 printk(KERN_DEBUG
"%s: smctr_tx_complete\n", dev
->name
);
5375 while((status
= tp
->tx_fcb_end
[queue
]->frame_status
) != SUCCESS
)
5377 if(status
& 0x7e00 )
5379 err
= HARDWARE_FAILED
;
5383 if((err
= smctr_update_tx_chain(dev
, tp
->tx_fcb_end
[queue
],
5387 smctr_disable_16bit(dev
);
5389 if(tp
->mode_bits
& UMAC
)
5391 if(!(status
& (FCB_TX_STATUS_AR1
| FCB_TX_STATUS_AR2
)))
5392 cstatus
= NO_SUCH_DESTINATION
;
5395 if(!(status
& (FCB_TX_STATUS_CR1
| FCB_TX_STATUS_CR2
)))
5396 cstatus
= DEST_OUT_OF_RESOURCES
;
5399 if(status
& FCB_TX_STATUS_E
)
5400 cstatus
= MAX_COLLISIONS
;
5409 if(queue
== BUG_QUEUE
)
5412 smctr_enable_16bit(dev
);
5420 static unsigned short smctr_tx_move_frame(struct net_device
*dev
,
5421 struct sk_buff
*skb
, __u8
*pbuff
, unsigned int bytes
)
5423 struct net_local
*tp
= netdev_priv(dev
);
5424 unsigned int ram_usable
;
5425 __u32 flen
, len
, offset
= 0;
5428 if(smctr_debug
> 10)
5429 printk(KERN_DEBUG
"%s: smctr_tx_move_frame\n", dev
->name
);
5431 ram_usable
= ((unsigned int)tp
->ram_usable
) << 10;
5435 while(flen
> 0 && bytes
> 0)
5437 smctr_set_page(dev
, pbuff
);
5439 offset
= SMC_PAGE_OFFSET(pbuff
);
5441 if(offset
+ flen
> ram_usable
)
5442 len
= ram_usable
- offset
;
5449 page
= (char *) (offset
+ tp
->ram_access
);
5450 memcpy(page
, frag
, len
);
5461 /* Update the error statistic counters for this adapter. */
5462 static int smctr_update_err_stats(struct net_device
*dev
)
5464 struct net_local
*tp
= netdev_priv(dev
);
5465 struct tr_statistics
*tstat
= &tp
->MacStat
;
5467 if(tstat
->internal_errors
)
5468 tstat
->internal_errors
5469 += *(tp
->misc_command_data
+ 0) & 0x00ff;
5471 if(tstat
->line_errors
)
5472 tstat
->line_errors
+= *(tp
->misc_command_data
+ 0) >> 8;
5474 if(tstat
->A_C_errors
)
5475 tstat
->A_C_errors
+= *(tp
->misc_command_data
+ 1) & 0x00ff;
5477 if(tstat
->burst_errors
)
5478 tstat
->burst_errors
+= *(tp
->misc_command_data
+ 1) >> 8;
5480 if(tstat
->abort_delimiters
)
5481 tstat
->abort_delimiters
+= *(tp
->misc_command_data
+ 2) >> 8;
5483 if(tstat
->recv_congest_count
)
5484 tstat
->recv_congest_count
5485 += *(tp
->misc_command_data
+ 3) & 0x00ff;
5487 if(tstat
->lost_frames
)
5489 += *(tp
->misc_command_data
+ 3) >> 8;
5491 if(tstat
->frequency_errors
)
5492 tstat
->frequency_errors
+= *(tp
->misc_command_data
+ 4) & 0x00ff;
5494 if(tstat
->frame_copied_errors
)
5495 tstat
->frame_copied_errors
5496 += *(tp
->misc_command_data
+ 4) >> 8;
5498 if(tstat
->token_errors
)
5499 tstat
->token_errors
+= *(tp
->misc_command_data
+ 5) >> 8;
5504 static int smctr_update_rx_chain(struct net_device
*dev
, __u16 queue
)
5506 struct net_local
*tp
= netdev_priv(dev
);
5511 fcb
= tp
->rx_fcb_curr
[queue
];
5512 len
= fcb
->frame_length
;
5514 fcb
->frame_status
= 0;
5515 fcb
->info
= FCB_CHAIN_END
;
5516 fcb
->back_ptr
->info
= FCB_WARNING
;
5518 tp
->rx_fcb_curr
[queue
] = tp
->rx_fcb_curr
[queue
]->next_ptr
;
5520 /* update RX BDBs */
5521 size
= (len
>> RX_BDB_SIZE_SHIFT
);
5522 if(len
& RX_DATA_BUFFER_SIZE_MASK
)
5523 size
+= sizeof(BDBlock
);
5524 size
&= (~RX_BDB_SIZE_MASK
);
5526 /* check if wrap around */
5527 bdb
= (BDBlock
*)((__u32
)(tp
->rx_bdb_curr
[queue
]) + (__u32
)(size
));
5528 if((__u32
)bdb
>= (__u32
)tp
->rx_bdb_end
[queue
])
5530 bdb
= (BDBlock
*)((__u32
)(tp
->rx_bdb_head
[queue
])
5531 + (__u32
)(bdb
) - (__u32
)(tp
->rx_bdb_end
[queue
]));
5534 bdb
->back_ptr
->info
= BDB_CHAIN_END
;
5535 tp
->rx_bdb_curr
[queue
]->back_ptr
->info
= BDB_NOT_CHAIN_END
;
5536 tp
->rx_bdb_curr
[queue
] = bdb
;
5541 static int smctr_update_tx_chain(struct net_device
*dev
, FCBlock
*fcb
,
5544 struct net_local
*tp
= netdev_priv(dev
);
5546 if(smctr_debug
> 20)
5547 printk(KERN_DEBUG
"smctr_update_tx_chain\n");
5549 if(tp
->num_tx_fcbs_used
[queue
] <= 0)
5550 return (HARDWARE_FAILED
);
5553 if(tp
->tx_buff_used
[queue
] < fcb
->memory_alloc
)
5555 tp
->tx_buff_used
[queue
] = 0;
5556 return (HARDWARE_FAILED
);
5559 tp
->tx_buff_used
[queue
] -= fcb
->memory_alloc
;
5561 /* if all transmit buffer are cleared
5562 * need to set the tx_buff_curr[] to tx_buff_head[]
5563 * otherwise, tx buffer will be segregate and cannot
5564 * accommodate and buffer greater than (curr - head) and
5565 * (end - curr) since we do not allow wrap around allocation.
5567 if(tp
->tx_buff_used
[queue
] == 0)
5568 tp
->tx_buff_curr
[queue
] = tp
->tx_buff_head
[queue
];
5570 tp
->num_tx_fcbs_used
[queue
]--;
5571 fcb
->frame_status
= 0;
5572 tp
->tx_fcb_end
[queue
] = fcb
->next_ptr
;
5573 netif_wake_queue(dev
);
5578 static int smctr_wait_cmd(struct net_device
*dev
)
5580 struct net_local
*tp
= netdev_priv(dev
);
5581 unsigned int loop_count
= 0x20000;
5583 if(smctr_debug
> 10)
5584 printk(KERN_DEBUG
"%s: smctr_wait_cmd\n", dev
->name
);
5588 if(tp
->acb_head
->cmd_done_status
& ACB_COMMAND_DONE
)
5595 return(HARDWARE_FAILED
);
5597 if(tp
->acb_head
->cmd_done_status
& 0xff)
5598 return(HARDWARE_FAILED
);
5603 static int smctr_wait_while_cbusy(struct net_device
*dev
)
5605 struct net_local
*tp
= netdev_priv(dev
);
5606 unsigned int timeout
= 0x20000;
5607 int ioaddr
= dev
->base_addr
;
5610 if(tp
->bic_type
== BIC_585_CHIP
)
5614 r
= inb(ioaddr
+ HWR
);
5615 if((r
& HWR_CBUSY
) == 0)
5624 r
= inb(ioaddr
+ CSR
);
5625 if((r
& CSR_CBUSY
) == 0)
5634 return (HARDWARE_FAILED
);
5639 static struct net_device
* dev_smctr
[SMCTR_MAX_ADAPTERS
];
5640 static int io
[SMCTR_MAX_ADAPTERS
];
5641 static int irq
[SMCTR_MAX_ADAPTERS
];
5643 MODULE_LICENSE("GPL");
5644 MODULE_FIRMWARE("tr_smctr.bin");
5646 module_param_array(io
, int, NULL
, 0);
5647 module_param_array(irq
, int, NULL
, 0);
5648 module_param(ringspeed
, int, 0);
5650 static struct net_device
* __init
setup_card(int n
)
5652 struct net_device
*dev
= alloc_trdev(sizeof(struct net_local
));
5656 return ERR_PTR(-ENOMEM
);
5659 err
= smctr_probe1(dev
, io
[n
]);
5663 err
= register_netdev(dev
);
5668 #ifdef CONFIG_MCA_LEGACY
5669 { struct net_local
*tp
= netdev_priv(dev
);
5671 mca_mark_as_unused(tp
->slot_num
);
5674 release_region(dev
->base_addr
, SMCTR_IO_EXTENT
);
5675 free_irq(dev
->irq
, dev
);
5678 return ERR_PTR(err
);
5681 int __init
init_module(void)
5684 struct net_device
*dev
;
5686 for(i
= 0; i
< SMCTR_MAX_ADAPTERS
; i
++) {
5687 dev
= io
[0]? setup_card(i
) : smctr_probe(-1);
5694 return found
? 0 : -ENODEV
;
5697 void __exit
cleanup_module(void)
5701 for(i
= 0; i
< SMCTR_MAX_ADAPTERS
; i
++) {
5702 struct net_device
*dev
= dev_smctr
[i
];
5706 unregister_netdev(dev
);
5707 #ifdef CONFIG_MCA_LEGACY
5708 { struct net_local
*tp
= netdev_priv(dev
);
5710 mca_mark_as_unused(tp
->slot_num
);
5713 release_region(dev
->base_addr
, SMCTR_IO_EXTENT
);
5715 free_irq(dev
->irq
, dev
);