blob: 9d7db2c8d6614ca2627622fcaeffdf8fc87c27fd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * smctr.c: A network driver for the SMC Token Ring Adapters.
3 *
4 * Written by Jay Schulist <jschlst@samba.org>
5 *
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
8 *
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)
12 *
13 * Source(s):
14 * - SMC TokenCard SDK.
15 *
16 * Maintainer(s):
17 * JS Jay Schulist <jschlst@samba.org>
18 *
19 * Changes:
20 * 07102000 JS Fixed a timing problem in smctr_wait_cmd();
21 * Also added a bit more discriptive error msgs.
22 * 07122000 JS Fixed problem with detecting a card with
23 * module io/irq/mem specified.
24 *
25 * To do:
26 * 1. Multicast support.
27 *
Alan Cox113aa832008-10-13 19:01:08 -070028 * Initial 2.5 cleanup Alan Cox <alan@lxorguk.ukuu.org.uk> 2002/10/28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 */
30
31#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/kernel.h>
33#include <linux/types.h>
34#include <linux/fcntl.h>
35#include <linux/interrupt.h>
36#include <linux/ptrace.h>
37#include <linux/ioport.h>
38#include <linux/in.h>
39#include <linux/slab.h>
40#include <linux/string.h>
41#include <linux/time.h>
42#include <linux/errno.h>
43#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#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>
David Woodhouse0f805b82008-05-29 16:39:16 +030051#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#include <asm/system.h>
54#include <asm/io.h>
55#include <asm/dma.h>
56#include <asm/irq.h>
57
58#if BITS_PER_LONG == 64
59#error FIXME: driver does not support 64-bit platforms
60#endif
61
62#include "smctr.h" /* Our Stuff */
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Hannes Eder1770e432009-02-14 11:44:19 +000064static const char version[] __initdata =
65 KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static const char cardname[] = "smctr";
67
68
69#define SMCTR_IO_EXTENT 20
70
71#ifdef CONFIG_MCA_LEGACY
72static unsigned int smctr_posid = 0x6ec6;
73#endif
74
75static int ringspeed;
76
77/* SMC Name of the Adapter. */
78static char smctr_name[] = "SMC TokenCard";
Adrian Bunkde70b4c2005-05-02 03:46:43 +020079static char *smctr_model = "Unknown";
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/* Use 0 for production, 1 for verification, 2 for debug, and
82 * 3 for very verbose debug.
83 */
84#ifndef SMCTR_DEBUG
85#define SMCTR_DEBUG 1
86#endif
87static unsigned int smctr_debug = SMCTR_DEBUG;
88
89/* smctr.c prototypes and functions are arranged alphabeticly
90 * for clearity, maintainability and pure old fashion fun.
91 */
92/* A */
93static int smctr_alloc_shared_memory(struct net_device *dev);
94
95/* B */
96static int smctr_bypass_state(struct net_device *dev);
97
98/* C */
99static int smctr_checksum_firmware(struct net_device *dev);
100static int __init smctr_chk_isa(struct net_device *dev);
101static int smctr_chg_rx_mask(struct net_device *dev);
102static int smctr_clear_int(struct net_device *dev);
103static int smctr_clear_trc_reset(int ioaddr);
104static int smctr_close(struct net_device *dev);
105
106/* D */
David Woodhouse0f805b82008-05-29 16:39:16 +0300107static int smctr_decode_firmware(struct net_device *dev,
108 const struct firmware *fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static int smctr_disable_16bit(struct net_device *dev);
110static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
111static int smctr_disable_bic_int(struct net_device *dev);
112
113/* E */
114static int smctr_enable_16bit(struct net_device *dev);
115static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
116static int smctr_enable_adapter_ram(struct net_device *dev);
117static int smctr_enable_bic_int(struct net_device *dev);
118
119/* G */
120static int __init smctr_get_boardid(struct net_device *dev, int mca);
121static int smctr_get_group_address(struct net_device *dev);
122static int smctr_get_functional_address(struct net_device *dev);
123static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
124static int smctr_get_physical_drop_number(struct net_device *dev);
125static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
126static int smctr_get_station_id(struct net_device *dev);
127static struct net_device_stats *smctr_get_stats(struct net_device *dev);
128static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
129 __u16 bytes_count);
130static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
131
132/* H */
133static int smctr_hardware_send_packet(struct net_device *dev,
134 struct net_local *tp);
135/* I */
136static int smctr_init_acbs(struct net_device *dev);
137static int smctr_init_adapter(struct net_device *dev);
138static int smctr_init_card_real(struct net_device *dev);
139static int smctr_init_rx_bdbs(struct net_device *dev);
140static int smctr_init_rx_fcbs(struct net_device *dev);
141static int smctr_init_shared_memory(struct net_device *dev);
142static int smctr_init_tx_bdbs(struct net_device *dev);
143static int smctr_init_tx_fcbs(struct net_device *dev);
144static int smctr_internal_self_test(struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100145static irqreturn_t smctr_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static int smctr_issue_enable_int_cmd(struct net_device *dev,
147 __u16 interrupt_enable_mask);
148static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
149 __u16 ibits);
150static int smctr_issue_init_timers_cmd(struct net_device *dev);
151static int smctr_issue_init_txrx_cmd(struct net_device *dev);
152static int smctr_issue_insert_cmd(struct net_device *dev);
153static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
154static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
155static int smctr_issue_remove_cmd(struct net_device *dev);
156static int smctr_issue_resume_acb_cmd(struct net_device *dev);
157static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
158static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
159static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
160static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
161static int smctr_issue_test_hic_cmd(struct net_device *dev);
162static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
163static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
164static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
165static int smctr_issue_write_byte_cmd(struct net_device *dev,
166 short aword_cnt, void *byte);
167static int smctr_issue_write_word_cmd(struct net_device *dev,
168 short aword_cnt, void *word);
169
170/* J */
171static int smctr_join_complete_state(struct net_device *dev);
172
173/* L */
174static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
175static int smctr_load_firmware(struct net_device *dev);
176static int smctr_load_node_addr(struct net_device *dev);
177static int smctr_lobe_media_test(struct net_device *dev);
178static int smctr_lobe_media_test_cmd(struct net_device *dev);
179static int smctr_lobe_media_test_state(struct net_device *dev);
180
181/* M */
182static int smctr_make_8025_hdr(struct net_device *dev,
183 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
184static int smctr_make_access_pri(struct net_device *dev,
185 MAC_SUB_VECTOR *tsv);
186static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
187static int smctr_make_auth_funct_class(struct net_device *dev,
188 MAC_SUB_VECTOR *tsv);
189static int smctr_make_corr(struct net_device *dev,
190 MAC_SUB_VECTOR *tsv, __u16 correlator);
191static int smctr_make_funct_addr(struct net_device *dev,
192 MAC_SUB_VECTOR *tsv);
193static int smctr_make_group_addr(struct net_device *dev,
194 MAC_SUB_VECTOR *tsv);
195static int smctr_make_phy_drop_num(struct net_device *dev,
196 MAC_SUB_VECTOR *tsv);
197static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
198static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
199static int smctr_make_ring_station_status(struct net_device *dev,
200 MAC_SUB_VECTOR *tsv);
201static int smctr_make_ring_station_version(struct net_device *dev,
202 MAC_SUB_VECTOR *tsv);
203static int smctr_make_tx_status_code(struct net_device *dev,
204 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
205static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
206 MAC_SUB_VECTOR *tsv);
207static int smctr_make_wrap_data(struct net_device *dev,
208 MAC_SUB_VECTOR *tsv);
209
210/* O */
211static int smctr_open(struct net_device *dev);
212static int smctr_open_tr(struct net_device *dev);
213
214/* P */
215struct net_device *smctr_probe(int unit);
216static int __init smctr_probe1(struct net_device *dev, int ioaddr);
217static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
218 struct net_device *dev, __u16 rx_status);
219
220/* R */
221static int smctr_ram_memory_test(struct net_device *dev);
222static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
223 __u16 *correlator);
224static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
225 __u16 *correlator);
226static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
227static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
228 MAC_HEADER *rmf, __u16 *correlator);
229static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
230 __u16 *correlator);
231static int smctr_reset_adapter(struct net_device *dev);
232static int smctr_restart_tx_chain(struct net_device *dev, short queue);
233static int smctr_ring_status_chg(struct net_device *dev);
234static int smctr_rx_frame(struct net_device *dev);
235
236/* S */
237static int smctr_send_dat(struct net_device *dev);
238static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev);
239static int smctr_send_lobe_media_test(struct net_device *dev);
240static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
241 __u16 correlator);
242static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
243 __u16 correlator);
244static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
245 __u16 correlator);
246static int smctr_send_rpt_tx_forward(struct net_device *dev,
247 MAC_HEADER *rmf, __u16 tx_fstatus);
248static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
249 __u16 rcode, __u16 correlator);
250static int smctr_send_rq_init(struct net_device *dev);
251static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
252 __u16 *tx_fstatus);
253static int smctr_set_auth_access_pri(struct net_device *dev,
254 MAC_SUB_VECTOR *rsv);
255static int smctr_set_auth_funct_class(struct net_device *dev,
256 MAC_SUB_VECTOR *rsv);
257static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
258 __u16 *correlator);
259static int smctr_set_error_timer_value(struct net_device *dev,
260 MAC_SUB_VECTOR *rsv);
261static int smctr_set_frame_forward(struct net_device *dev,
262 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
263static int smctr_set_local_ring_num(struct net_device *dev,
264 MAC_SUB_VECTOR *rsv);
265static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
266static void smctr_set_multicast_list(struct net_device *dev);
267static int smctr_set_page(struct net_device *dev, __u8 *buf);
268static int smctr_set_phy_drop(struct net_device *dev,
269 MAC_SUB_VECTOR *rsv);
270static int smctr_set_ring_speed(struct net_device *dev);
271static int smctr_set_rx_look_ahead(struct net_device *dev);
272static int smctr_set_trc_reset(int ioaddr);
273static int smctr_setup_single_cmd(struct net_device *dev,
274 __u16 command, __u16 subcommand);
275static int smctr_setup_single_cmd_w_data(struct net_device *dev,
276 __u16 command, __u16 subcommand);
277static char *smctr_malloc(struct net_device *dev, __u16 size);
278static int smctr_status_chg(struct net_device *dev);
279
280/* T */
281static void smctr_timeout(struct net_device *dev);
282static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
283 __u16 queue);
284static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
285static unsigned short smctr_tx_move_frame(struct net_device *dev,
286 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
287
288/* U */
289static int smctr_update_err_stats(struct net_device *dev);
290static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
291static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
292 __u16 queue);
293
294/* W */
295static int smctr_wait_cmd(struct net_device *dev);
296static int smctr_wait_while_cbusy(struct net_device *dev);
297
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))
301
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!!!
305 *
306 * Order of memory allocation:
307 *
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
313 *
314 * 5. MAC TX FCB'S
315 * 6. NON-MAC TX FCB'S
316 * 7. MAC TX BDB'S
317 * 8. NON-MAC TX BDB'S
318 * 9. MAC RX FCB'S
319 * 10. NON-MAC RX FCB'S
320 * 11. MAC RX BDB'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)
324 *
325 * 15. NON-MAC TX Data Buffer
326 * 16. NON-MAC RX Data Buffer
327 */
328static int smctr_alloc_shared_memory(struct net_device *dev)
329{
330 struct net_local *tp = netdev_priv(dev);
331
332 if(smctr_debug > 10)
333 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
334
335 /* Allocate initial System Control Block pointer.
336 * This pointer is located in the last page, last offset - 4.
337 */
338 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
339 - (long)ISCP_BLOCK_SIZE);
340
341 /* Allocate System Control Blocks. */
342 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
343 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
344
345 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
346 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
347
348 tp->acb_head = (ACBlock *)smctr_malloc(dev,
349 sizeof(ACBlock)*tp->num_acbs);
350 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
351
352 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
353 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
354
355 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
356 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
357
358 /* Allocate transmit FCBs. */
359 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
360 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
361
362 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
363 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
364
365 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
366 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
367
368 /* Allocate transmit BDBs. */
369 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
370 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
371
372 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
373 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
374
375 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
376 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
377
378 /* Allocate receive FCBs. */
379 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
380 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
381
382 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
383 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
384
385 /* Allocate receive BDBs. */
386 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
387 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
388
389 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
390
391 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
392 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
393
394 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
395
396 /* Allocate MAC transmit buffers.
397 * MAC Tx Buffers doen't have to be on an ODD Boundry.
398 */
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);
403
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);
409
410 /* Allocate MAC receive data buffers.
411 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
412 */
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);
416
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.
420 */
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);
427
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.
433 */
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);
438
439 return (0);
440}
441
442/* Enter Bypass state. */
443static int smctr_bypass_state(struct net_device *dev)
444{
445 int err;
446
447 if(smctr_debug > 10)
448 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
449
450 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
451
452 return (err);
453}
454
455static int smctr_checksum_firmware(struct net_device *dev)
456{
457 struct net_local *tp = netdev_priv(dev);
458 __u16 i, checksum = 0;
459
460 if(smctr_debug > 10)
461 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
462
463 smctr_enable_adapter_ctrl_store(dev);
464
465 for(i = 0; i < CS_RAM_SIZE; i += 2)
466 checksum += *((__u16 *)(tp->ram_access + i));
467
468 tp->microcode_version = *(__u16 *)(tp->ram_access
469 + CS_RAM_VERSION_OFFSET);
470 tp->microcode_version >>= 8;
471
472 smctr_disable_adapter_ctrl_store(dev);
473
474 if(checksum)
475 return (checksum);
476
477 return (0);
478}
479
480static int __init smctr_chk_mca(struct net_device *dev)
481{
482#ifdef CONFIG_MCA_LEGACY
483 struct net_local *tp = netdev_priv(dev);
484 int current_slot;
485 __u8 r1, r2, r3, r4, r5;
486
487 current_slot = mca_find_unused_adapter(smctr_posid, 0);
488 if(current_slot == MCA_NOTFOUND)
489 return (-ENODEV);
490
491 mca_set_adapter_name(current_slot, smctr_name);
492 mca_mark_as_used(current_slot);
493 tp->slot_num = current_slot;
494
495 r1 = mca_read_stored_pos(tp->slot_num, 2);
496 r2 = mca_read_stored_pos(tp->slot_num, 3);
497
498 if(tp->slot_num)
499 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
500 else
501 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
502
503 r1 = inb(CNFG_POS_REG1);
504 r2 = inb(CNFG_POS_REG0);
505
506 tp->bic_type = BIC_594_CHIP;
507
508 /* IO */
509 r2 = mca_read_stored_pos(tp->slot_num, 2);
510 r2 &= 0xF0;
511 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
512 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
513
514 /* IRQ */
515 r5 = mca_read_stored_pos(tp->slot_num, 5);
516 r5 &= 0xC;
517 switch(r5)
518 {
519 case 0:
520 dev->irq = 3;
521 break;
522
523 case 0x4:
524 dev->irq = 4;
525 break;
526
527 case 0x8:
528 dev->irq = 10;
529 break;
530
531 default:
532 dev->irq = 15;
533 break;
534 }
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700535 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 release_region(dev->base_addr, SMCTR_IO_EXTENT);
537 return -ENODEV;
538 }
539
540 /* Get RAM base */
541 r3 = mca_read_stored_pos(tp->slot_num, 3);
542 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
543 if (r3 & 0x8)
544 tp->ram_base += 0x010000;
545 if (r3 & 0x80)
546 tp->ram_base += 0xF00000;
547
548 /* Get Ram Size */
549 r3 &= 0x30;
550 r3 >>= 4;
551
552 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
553 tp->ram_size = (__u16)CNFG_SIZE_64KB;
554 tp->board_id |= TOKEN_MEDIA;
555
556 r4 = mca_read_stored_pos(tp->slot_num, 4);
557 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
558 if (r4 & 0x8)
559 tp->rom_base += 0x010000;
560
561 /* Get ROM size. */
562 r4 >>= 4;
563 switch (r4) {
564 case 0:
565 tp->rom_size = CNFG_SIZE_8KB;
566 break;
567 case 1:
568 tp->rom_size = CNFG_SIZE_16KB;
569 break;
570 case 2:
571 tp->rom_size = CNFG_SIZE_32KB;
572 break;
573 default:
574 tp->rom_size = ROM_DISABLE;
575 }
576
577 /* Get Media Type. */
578 r5 = mca_read_stored_pos(tp->slot_num, 5);
579 r5 &= CNFG_MEDIA_TYPE_MASK;
580 switch(r5)
581 {
582 case (0):
583 tp->media_type = MEDIA_STP_4;
584 break;
585
586 case (1):
587 tp->media_type = MEDIA_STP_16;
588 break;
589
590 case (3):
591 tp->media_type = MEDIA_UTP_16;
592 break;
593
594 default:
595 tp->media_type = MEDIA_UTP_4;
596 break;
597 }
598 tp->media_menu = 14;
599
600 r2 = mca_read_stored_pos(tp->slot_num, 2);
601 if(!(r2 & 0x02))
602 tp->mode_bits |= EARLY_TOKEN_REL;
603
604 /* Disable slot */
605 outb(CNFG_POS_CONTROL_REG, 0);
606
607 tp->board_id = smctr_get_boardid(dev, 1);
608 switch(tp->board_id & 0xffff)
609 {
610 case WD8115TA:
611 smctr_model = "8115T/A";
612 break;
613
614 case WD8115T:
615 if(tp->extra_info & CHIP_REV_MASK)
616 smctr_model = "8115T rev XE";
617 else
618 smctr_model = "8115T rev XD";
619 break;
620
621 default:
622 smctr_model = "Unknown";
623 break;
624 }
625
626 return (0);
627#else
628 return (-1);
629#endif /* CONFIG_MCA_LEGACY */
630}
631
632static int smctr_chg_rx_mask(struct net_device *dev)
633{
634 struct net_local *tp = netdev_priv(dev);
635 int err = 0;
636
637 if(smctr_debug > 10)
638 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
639
640 smctr_enable_16bit(dev);
641 smctr_set_page(dev, (__u8 *)tp->ram_access);
642
643 if(tp->mode_bits & LOOPING_MODE_MASK)
644 tp->config_word0 |= RX_OWN_BIT;
645 else
646 tp->config_word0 &= ~RX_OWN_BIT;
647
648 if(tp->receive_mask & PROMISCUOUS_MODE)
649 tp->config_word0 |= PROMISCUOUS_BIT;
650 else
651 tp->config_word0 &= ~PROMISCUOUS_BIT;
652
653 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
654 tp->config_word0 |= SAVBAD_BIT;
655 else
656 tp->config_word0 &= ~SAVBAD_BIT;
657
658 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
659 tp->config_word0 |= RXATMAC;
660 else
661 tp->config_word0 &= ~RXATMAC;
662
663 if(tp->receive_mask & ACCEPT_MULTI_PROM)
664 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
665 else
666 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
667
668 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
669 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
670 else
671 {
672 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
673 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
674 else
675 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
676 }
677
678 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
679 &tp->config_word0)))
680 {
681 return (err);
682 }
683
684 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
685 &tp->config_word1)))
686 {
687 return (err);
688 }
689
690 smctr_disable_16bit(dev);
691
692 return (0);
693}
694
695static int smctr_clear_int(struct net_device *dev)
696{
697 struct net_local *tp = netdev_priv(dev);
698
699 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
700
701 return (0);
702}
703
704static int smctr_clear_trc_reset(int ioaddr)
705{
706 __u8 r;
707
708 r = inb(ioaddr + MSR);
709 outb(~MSR_RST & r, ioaddr + MSR);
710
711 return (0);
712}
713
714/*
715 * The inverse routine to smctr_open().
716 */
717static int smctr_close(struct net_device *dev)
718{
719 struct net_local *tp = netdev_priv(dev);
720 struct sk_buff *skb;
721 int err;
722
723 netif_stop_queue(dev);
724
725 tp->cleanup = 1;
726
727 /* Check to see if adapter is already in a closed state. */
728 if(tp->status != OPEN)
729 return (0);
730
731 smctr_enable_16bit(dev);
732 smctr_set_page(dev, (__u8 *)tp->ram_access);
733
734 if((err = smctr_issue_remove_cmd(dev)))
735 {
736 smctr_disable_16bit(dev);
737 return (err);
738 }
739
740 for(;;)
741 {
742 skb = skb_dequeue(&tp->SendSkbQueue);
743 if(skb == NULL)
744 break;
745 tp->QueueSkb++;
746 dev_kfree_skb(skb);
747 }
748
749
750 return (0);
751}
752
David Woodhouse0f805b82008-05-29 16:39:16 +0300753static int smctr_decode_firmware(struct net_device *dev,
754 const struct firmware *fw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 struct net_local *tp = netdev_priv(dev);
757 short bit = 0x80, shift = 12;
758 DECODE_TREE_NODE *tree;
759 short branch, tsize;
760 __u16 buff = 0;
761 long weight;
762 __u8 *ucode;
763 __u16 *mem;
764
765 if(smctr_debug > 10)
766 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
767
David Woodhouse0f805b82008-05-29 16:39:16 +0300768 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 + (tsize * sizeof(DECODE_TREE_NODE)));
773 mem = (__u16 *)(tp->ram_access);
774
775 while(weight)
776 {
777 branch = ROOT;
778 while((tree + branch)->tag != LEAF && weight)
779 {
780 branch = *ucode & bit ? (tree + branch)->llink
781 : (tree + branch)->rlink;
782
783 bit >>= 1;
784 weight--;
785
786 if(bit == 0)
787 {
788 bit = 0x80;
789 ucode++;
790 }
791 }
792
793 buff |= (tree + branch)->info << shift;
794 shift -= 4;
795
796 if(shift < 0)
797 {
798 *(mem++) = SWAP_BYTES(buff);
799 buff = 0;
800 shift = 12;
801 }
802 }
803
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.
807 */
808 if(buff)
809 *(mem++) = SWAP_BYTES(buff);
810
811 return (0);
812}
813
814static int smctr_disable_16bit(struct net_device *dev)
815{
816 return (0);
817}
818
819/*
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).
824 */
825static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
826{
827 struct net_local *tp = netdev_priv(dev);
828 int ioaddr = dev->base_addr;
829
830 if(smctr_debug > 10)
831 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
832
833 tp->trc_mask |= CSR_WCSS;
834 outb(tp->trc_mask, ioaddr + CSR);
835
836 return (0);
837}
838
839static int smctr_disable_bic_int(struct net_device *dev)
840{
841 struct net_local *tp = netdev_priv(dev);
842 int ioaddr = dev->base_addr;
843
844 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
845 | CSR_MSKTINT | CSR_WCSS;
846 outb(tp->trc_mask, ioaddr + CSR);
847
848 return (0);
849}
850
851static int smctr_enable_16bit(struct net_device *dev)
852{
853 struct net_local *tp = netdev_priv(dev);
854 __u8 r;
855
856 if(tp->adapter_bus == BUS_ISA16_TYPE)
857 {
858 r = inb(dev->base_addr + LAAR);
859 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
860 }
861
862 return (0);
863}
864
865/*
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).
870 */
871static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
872{
873 struct net_local *tp = netdev_priv(dev);
874 int ioaddr = dev->base_addr;
875
876 if(smctr_debug > 10)
877 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
878
879 smctr_set_trc_reset(ioaddr);
880 smctr_enable_adapter_ram(dev);
881
882 tp->trc_mask &= ~CSR_WCSS;
883 outb(tp->trc_mask, ioaddr + CSR);
884
885 return (0);
886}
887
888static int smctr_enable_adapter_ram(struct net_device *dev)
889{
890 int ioaddr = dev->base_addr;
891 __u8 r;
892
893 if(smctr_debug > 10)
894 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
895
896 r = inb(ioaddr + MSR);
897 outb(MSR_MEMB | r, ioaddr + MSR);
898
899 return (0);
900}
901
902static int smctr_enable_bic_int(struct net_device *dev)
903{
904 struct net_local *tp = netdev_priv(dev);
905 int ioaddr = dev->base_addr;
906 __u8 r;
907
908 switch(tp->bic_type)
909 {
910 case (BIC_584_CHIP):
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);
915 break;
916
917 case (BIC_594_CHIP):
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);
922 break;
923 }
924
925 return (0);
926}
927
928static int __init smctr_chk_isa(struct net_device *dev)
929{
930 struct net_local *tp = netdev_priv(dev);
931 int ioaddr = dev->base_addr;
932 __u8 r1, r2, b, chksum = 0;
933 __u16 r;
934 int i;
935 int err = -ENODEV;
936
937 if(smctr_debug > 10)
938 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
939
940 if((ioaddr & 0x1F) != 0)
941 goto out;
942
943 /* Grab the region so that no one else tries to probe our ioports. */
944 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
945 err = -EBUSY;
946 goto out;
947 }
948
949 /* Checksum SMC node address */
950 for(i = 0; i < 8; i++)
951 {
952 b = inb(ioaddr + LAR0 + i);
953 chksum += b;
954 }
955
956 if (chksum != NODE_ADDR_CKSUM)
957 goto out2;
958
959 b = inb(ioaddr + BDID);
960 if(b != BRD_ID_8115T)
961 {
962 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
963 goto out2;
964 }
965
966 /* Check for 8115T Board ID */
967 r2 = 0;
968 for(r = 0; r < 8; r++)
969 {
970 r1 = inb(ioaddr + 0x8 + r);
971 r2 += r1;
972 }
973
974 /* value of RegF adds up the sum to 0xFF */
975 if((r2 != 0xFF) && (r2 != 0xEE))
976 goto out2;
977
978 /* Get adapter ID */
979 tp->board_id = smctr_get_boardid(dev, 0);
980 switch(tp->board_id & 0xffff)
981 {
982 case WD8115TA:
983 smctr_model = "8115T/A";
984 break;
985
986 case WD8115T:
987 if(tp->extra_info & CHIP_REV_MASK)
988 smctr_model = "8115T rev XE";
989 else
990 smctr_model = "8115T rev XD";
991 break;
992
993 default:
994 smctr_model = "Unknown";
995 break;
996 }
997
998 /* Store BIC type. */
999 tp->bic_type = BIC_584_CHIP;
1000 tp->nic_type = NIC_825_CHIP;
1001
1002 /* Copy Ram Size */
1003 tp->ram_usable = CNFG_SIZE_16KB;
1004 tp->ram_size = CNFG_SIZE_64KB;
1005
1006 /* Get 58x Ram Base */
1007 r1 = inb(ioaddr);
1008 r1 &= 0x3F;
1009
1010 r2 = inb(ioaddr + CNFG_LAAR_584);
1011 r2 &= CNFG_LAAR_MASK;
1012 r2 <<= 3;
1013 r2 |= ((r1 & 0x38) >> 3);
1014
1015 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1016
1017 /* Get 584 Irq */
1018 r1 = 0;
1019 r1 = inb(ioaddr + CNFG_ICR_583);
1020 r1 &= CNFG_ICR_IR2_584;
1021
1022 r2 = inb(ioaddr + CNFG_IRR_583);
1023 r2 &= CNFG_IRR_IRQS; /* 0x60 */
1024 r2 >>= 5;
1025
1026 switch(r2)
1027 {
1028 case 0:
1029 if(r1 == 0)
1030 dev->irq = 2;
1031 else
1032 dev->irq = 10;
1033 break;
1034
1035 case 1:
1036 if(r1 == 0)
1037 dev->irq = 3;
1038 else
1039 dev->irq = 11;
1040 break;
1041
1042 case 2:
1043 if(r1 == 0)
1044 {
1045 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1046 dev->irq = 5;
1047 else
1048 dev->irq = 4;
1049 }
1050 else
1051 dev->irq = 15;
1052 break;
1053
1054 case 3:
1055 if(r1 == 0)
1056 dev->irq = 7;
1057 else
1058 dev->irq = 4;
1059 break;
1060
1061 default:
1062 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1063 goto out2;
1064 }
1065
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07001066 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 goto out2;
1068
1069 /* Get 58x Rom Base */
1070 r1 = inb(ioaddr + CNFG_BIO_583);
1071 r1 &= 0x3E;
1072 r1 |= 0x40;
1073
1074 tp->rom_base = (__u32)r1 << 13;
1075
1076 /* Get 58x Rom Size */
1077 r1 = inb(ioaddr + CNFG_BIO_583);
1078 r1 &= 0xC0;
1079 if(r1 == 0)
1080 tp->rom_size = ROM_DISABLE;
1081 else
1082 {
1083 r1 >>= 6;
1084 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1085 }
1086
1087 /* Get 58x Boot Status */
1088 r1 = inb(ioaddr + CNFG_GP2);
1089
1090 tp->mode_bits &= (~BOOT_STATUS_MASK);
1091
1092 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1093 tp->mode_bits |= BOOT_TYPE_1;
1094
1095 /* Get 58x Zero Wait State */
1096 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1097
1098 r1 = inb(ioaddr + CNFG_IRR_583);
1099
1100 if(r1 & CNFG_IRR_ZWS)
1101 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1102
1103 if(tp->board_id & BOARD_16BIT)
1104 {
1105 r1 = inb(ioaddr + CNFG_LAAR_584);
1106
1107 if(r1 & CNFG_LAAR_ZWS)
1108 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1109 }
1110
1111 /* Get 584 Media Menu */
1112 tp->media_menu = 14;
1113 r1 = inb(ioaddr + CNFG_IRR_583);
1114
1115 tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1116 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1117 {
1118 /* Get Advanced Features */
1119 if(((r1 & 0x6) >> 1) == 0x3)
1120 tp->media_type |= MEDIA_UTP_16;
1121 else
1122 {
1123 if(((r1 & 0x6) >> 1) == 0x2)
1124 tp->media_type |= MEDIA_STP_16;
1125 else
1126 {
1127 if(((r1 & 0x6) >> 1) == 0x1)
1128 tp->media_type |= MEDIA_UTP_4;
1129
1130 else
1131 tp->media_type |= MEDIA_STP_4;
1132 }
1133 }
1134
1135 r1 = inb(ioaddr + CNFG_GP2);
1136 if(!(r1 & 0x2) ) /* GP2_ETRD */
1137 tp->mode_bits |= EARLY_TOKEN_REL;
1138
1139 /* see if the chip is corrupted
1140 if(smctr_read_584_chksum(ioaddr))
1141 {
1142 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1143 free_irq(dev->irq, dev);
1144 goto out2;
1145 }
1146 */
1147 }
1148
1149 return (0);
1150
1151out2:
1152 release_region(ioaddr, SMCTR_IO_EXTENT);
1153out:
1154 return err;
1155}
1156
1157static int __init smctr_get_boardid(struct net_device *dev, int mca)
1158{
1159 struct net_local *tp = netdev_priv(dev);
1160 int ioaddr = dev->base_addr;
1161 __u8 r, r1, IdByte;
1162 __u16 BoardIdMask;
1163
1164 tp->board_id = BoardIdMask = 0;
1165
1166 if(mca)
1167 {
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);
1170 }
1171 else
1172 {
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);
1176 }
1177
1178 if(!mca)
1179 {
1180 r = inb(ioaddr + BID_REG_1);
1181 r &= 0x0c;
1182 outb(r, ioaddr + BID_REG_1);
1183 r = inb(ioaddr + BID_REG_1);
1184
1185 if(r & BID_SIXTEEN_BIT_BIT)
1186 {
1187 tp->extra_info |= SLOT_16BIT;
1188 tp->adapter_bus = BUS_ISA16_TYPE;
1189 }
1190 else
1191 tp->adapter_bus = BUS_ISA8_TYPE;
1192 }
1193 else
1194 tp->adapter_bus = BUS_MCA_TYPE;
1195
1196 /* Get Board Id Byte */
1197 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1198
1199 /* if Major version > 1.0 then
1200 * return;
1201 */
1202 if(IdByte & 0xF8)
1203 return (-1);
1204
1205 r1 = inb(ioaddr + BID_REG_1);
1206 r1 &= BID_ICR_MASK;
1207 r1 |= BID_OTHER_BIT;
1208
1209 outb(r1, ioaddr + BID_REG_1);
1210 r1 = inb(ioaddr + BID_REG_3);
1211
1212 r1 &= BID_EAR_MASK;
1213 r1 |= BID_ENGR_PAGE;
1214
1215 outb(r1, ioaddr + BID_REG_3);
1216 r1 = inb(ioaddr + BID_REG_1);
1217 r1 &= BID_ICR_MASK;
1218 r1 |= (BID_RLA | BID_OTHER_BIT);
1219
1220 outb(r1, ioaddr + BID_REG_1);
1221
1222 r1 = inb(ioaddr + BID_REG_1);
1223 while(r1 & BID_RECALL_DONE_MASK)
1224 r1 = inb(ioaddr + BID_REG_1);
1225
1226 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1227
1228 /* clear chip rev bits */
1229 tp->extra_info &= ~CHIP_REV_MASK;
1230 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1231
1232 r1 = inb(ioaddr + BID_REG_1);
1233 r1 &= BID_ICR_MASK;
1234 r1 |= BID_OTHER_BIT;
1235
1236 outb(r1, ioaddr + BID_REG_1);
1237 r1 = inb(ioaddr + BID_REG_3);
1238
1239 r1 &= BID_EAR_MASK;
1240 r1 |= BID_EA6;
1241
1242 outb(r1, ioaddr + BID_REG_3);
1243 r1 = inb(ioaddr + BID_REG_1);
1244
1245 r1 &= BID_ICR_MASK;
1246 r1 |= BID_RLA;
1247
1248 outb(r1, ioaddr + BID_REG_1);
1249 r1 = inb(ioaddr + BID_REG_1);
1250
1251 while(r1 & BID_RECALL_DONE_MASK)
1252 r1 = inb(ioaddr + BID_REG_1);
1253
1254 return (BoardIdMask);
1255}
1256
1257static int smctr_get_group_address(struct net_device *dev)
1258{
1259 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1260
1261 return(smctr_wait_cmd(dev));
1262}
1263
1264static int smctr_get_functional_address(struct net_device *dev)
1265{
1266 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1267
1268 return(smctr_wait_cmd(dev));
1269}
1270
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.
1274 */
1275static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1276{
1277 struct net_local *tp = netdev_priv(dev);
1278 unsigned int mem_used = 0;
1279
1280 /* Allocate System Control Blocks. */
1281 mem_used += sizeof(SCGBlock);
1282
1283 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1284 mem_used += sizeof(SCLBlock);
1285
1286 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1287 mem_used += sizeof(ACBlock) * tp->num_acbs;
1288
1289 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1290 mem_used += sizeof(ISBlock);
1291
1292 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1293 mem_used += MISC_DATA_SIZE;
1294
1295 /* Allocate transmit FCB's. */
1296 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1297
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];
1301
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];
1306
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];
1310
1311 /* Allocate receive BDBs. */
1312 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1313
1314 /* Allocate MAC transmit buffers.
1315 * MAC transmit buffers don't have to be on an ODD Boundry.
1316 */
1317 mem_used += tp->tx_buff_size[MAC_QUEUE];
1318
1319 /* Allocate BUG transmit buffers. */
1320 mem_used += tp->tx_buff_size[BUG_QUEUE];
1321
1322 /* Allocate MAC receive data buffers.
1323 * MAC receive buffers don't have to be on a 256 byte boundary.
1324 */
1325 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
1326
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.
1330 */
1331 mem_used += 1L;
1332 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1333 mem_used += 1L;
1334
1335 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1336 * AND NON-MAC RX DATA BUFFERS
1337 *
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
1342 * byte offset).
1343 *
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.
1347 */
1348 mem_used += 0x100;
1349
1350 return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock)));
1351}
1352
1353static int smctr_get_physical_drop_number(struct net_device *dev)
1354{
1355 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1356
1357 return(smctr_wait_cmd(dev));
1358}
1359
1360static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1361{
1362 struct net_local *tp = netdev_priv(dev);
1363 BDBlock *bdb;
1364
1365 bdb = (BDBlock *)((__u32)tp->ram_access
1366 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1367
1368 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1369
1370 return ((__u8 *)bdb->data_block_ptr);
1371}
1372
1373static int smctr_get_station_id(struct net_device *dev)
1374{
1375 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1376
1377 return(smctr_wait_cmd(dev));
1378}
1379
1380/*
1381 * Get the current statistics. This may be called with the card open
1382 * or closed.
1383 */
1384static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1385{
1386 struct net_local *tp = netdev_priv(dev);
1387
1388 return ((struct net_device_stats *)&tp->MacStat);
1389}
1390
1391static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1392 __u16 bytes_count)
1393{
1394 struct net_local *tp = netdev_priv(dev);
1395 FCBlock *pFCB;
1396 BDBlock *pbdb;
1397 unsigned short alloc_size;
1398 unsigned short *temp;
1399
1400 if(smctr_debug > 20)
1401 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
1402
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));
1406
1407 /* round off the input pkt size to the nearest even number */
1408 alloc_size = (bytes_count + 1) & 0xfffe;
1409
1410 /* check if enough mem */
1411 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
1412 return ((FCBlock *)(-1L));
1413
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
1417 */
1418 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1419 >= (unsigned long)(tp->tx_buff_end[queue]))
1420 {
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]);
1425
1426 if((tp->tx_buff_used[queue] + alloc_size)
1427 > tp->tx_buff_size[queue])
1428 {
1429 return ((FCBlock *)(-1L));
1430 }
1431
1432 /* ring wrap */
1433 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
1434 }
1435
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));
1443
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);
1448
1449 pFCB = tp->tx_fcb_curr[queue];
1450 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1451
1452 return (pFCB);
1453}
1454
1455static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1456{
1457 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1458
1459 return(smctr_wait_cmd(dev));
1460}
1461
1462static int smctr_hardware_send_packet(struct net_device *dev,
1463 struct net_local *tp)
1464{
1465 struct tr_statistics *tstat = &tp->MacStat;
1466 struct sk_buff *skb;
1467 FCBlock *fcb;
1468
1469 if(smctr_debug > 10)
1470 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1471
1472 if(tp->status != OPEN)
1473 return (-1);
1474
1475 if(tp->monitor_state_ready != 1)
1476 return (-1);
1477
1478 for(;;)
1479 {
1480 /* Send first buffer from queue */
1481 skb = skb_dequeue(&tp->SendSkbQueue);
1482 if(skb == NULL)
1483 return (-1);
1484
1485 tp->QueueSkb++;
1486
1487 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size) return (-1);
1488
1489 smctr_enable_16bit(dev);
1490 smctr_set_page(dev, (__u8 *)tp->ram_access);
1491
1492 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
1493 == (FCBlock *)(-1L))
1494 {
1495 smctr_disable_16bit(dev);
1496 return (-1);
1497 }
1498
1499 smctr_tx_move_frame(dev, skb,
1500 (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
1501
1502 smctr_set_page(dev, (__u8 *)fcb);
1503
1504 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
1505 dev_kfree_skb(skb);
1506
1507 tstat->tx_packets++;
1508
1509 smctr_disable_16bit(dev);
1510 }
1511
1512 return (0);
1513}
1514
1515static int smctr_init_acbs(struct net_device *dev)
1516{
1517 struct net_local *tp = netdev_priv(dev);
1518 unsigned int i;
1519 ACBlock *acb;
1520
1521 if(smctr_debug > 10)
1522 printk(KERN_DEBUG "%s: smctr_init_acbs\n", dev->name);
1523
1524 acb = tp->acb_head;
1525 acb->cmd_done_status = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1526 acb->cmd_info = ACB_CHAIN_END;
1527 acb->cmd = 0;
1528 acb->subcmd = 0;
1529 acb->data_offset_lo = 0;
1530 acb->data_offset_hi = 0;
1531 acb->next_ptr
1532 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1533 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1534
1535 for(i = 1; i < tp->num_acbs; i++)
1536 {
1537 acb = acb->next_ptr;
1538 acb->cmd_done_status
1539 = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
1540 acb->cmd_info = ACB_CHAIN_END;
1541 acb->cmd = 0;
1542 acb->subcmd = 0;
1543 acb->data_offset_lo = 0;
1544 acb->data_offset_hi = 0;
1545 acb->next_ptr
1546 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
1547 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
1548 }
1549
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;
1555
1556 return (0);
1557}
1558
1559static int smctr_init_adapter(struct net_device *dev)
1560{
1561 struct net_local *tp = netdev_priv(dev);
1562 int err;
1563
1564 if(smctr_debug > 10)
1565 printk(KERN_DEBUG "%s: smctr_init_adapter\n", dev->name);
1566
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;
1571
1572 if(!(tp->group_address_0 & 0x0080))
1573 tp->group_address_0 |= 0x00C0;
1574
1575 if(!(tp->functional_address_0 & 0x00C0))
1576 tp->functional_address_0 |= 0x00C0;
1577
1578 tp->functional_address[0] &= 0xFF7F;
1579
1580 if(tp->authorized_function_classes == 0)
1581 tp->authorized_function_classes = 0x7FFF;
1582
1583 if(tp->authorized_access_priority == 0)
1584 tp->authorized_access_priority = 0x06;
1585
1586 smctr_disable_bic_int(dev);
1587 smctr_set_trc_reset(dev->base_addr);
1588
1589 smctr_enable_16bit(dev);
1590 smctr_set_page(dev, (__u8 *)tp->ram_access);
1591
1592 if(smctr_checksum_firmware(dev))
1593 {
1594 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name); return (-ENOENT);
1595 }
1596
1597 if((err = smctr_ram_memory_test(dev)))
1598 {
1599 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
1600 return (-EIO);
1601 }
1602
1603 smctr_set_rx_look_ahead(dev);
1604 smctr_load_node_addr(dev);
1605
1606 /* Initialize adapter for Internal Self Test. */
1607 smctr_reset_adapter(dev);
1608 if((err = smctr_init_card_real(dev)))
1609 {
1610 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1611 dev->name, err);
1612 return (-EINVAL);
1613 }
1614
1615 /* This routine clobbers the TRC's internal registers. */
1616 if((err = smctr_internal_self_test(dev)))
1617 {
1618 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1619 dev->name, err);
1620 return (-EINVAL);
1621 }
1622
1623 /* Re-Initialize adapter's internal registers */
1624 smctr_reset_adapter(dev);
1625 if((err = smctr_init_card_real(dev)))
1626 {
1627 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1628 dev->name, err);
1629 return (-EINVAL);
1630 }
1631
1632 smctr_enable_bic_int(dev);
1633
1634 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
1635 return (err);
1636
1637 smctr_disable_16bit(dev);
1638
1639 return (0);
1640}
1641
1642static int smctr_init_card_real(struct net_device *dev)
1643{
1644 struct net_local *tp = netdev_priv(dev);
1645 int err = 0;
1646
1647 if(smctr_debug > 10)
1648 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1649
1650 tp->sh_mem_used = 0;
1651 tp->num_acbs = NUM_OF_ACBS;
1652
1653 /* Range Check Max Packet Size */
1654 if(tp->max_packet_size < 256)
1655 tp->max_packet_size = 256;
1656 else
1657 {
1658 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1659 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1660 }
1661
1662 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1663 / tp->max_packet_size) - 1;
1664
1665 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1666 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1667 else
1668 {
1669 if(tp->num_of_tx_buffs == 0)
1670 tp->num_of_tx_buffs = 1;
1671 }
1672
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;
1679
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;
1685
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;
1691
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;
1695
1696 if(tp->extra_info & CHIP_REV_MASK)
1697 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1698 else
1699 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1700
1701 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1702
1703 smctr_alloc_shared_memory(dev);
1704 smctr_init_shared_memory(dev);
1705
1706 if((err = smctr_issue_init_timers_cmd(dev)))
1707 return (err);
1708
1709 if((err = smctr_issue_init_txrx_cmd(dev)))
1710 {
1711 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
1712 return (err);
1713 }
1714
1715 return (0);
1716}
1717
1718static int smctr_init_rx_bdbs(struct net_device *dev)
1719{
1720 struct net_local *tp = netdev_priv(dev);
1721 unsigned int i, j;
1722 BDBlock *bdb;
1723 __u16 *buf;
1724
1725 if(smctr_debug > 10)
1726 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1727
1728 for(i = 0; i < NUM_RX_QS_USED; i++)
1729 {
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);
1737
1738 if(i == NON_MAC_QUEUE)
1739 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1740 else
1741 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1742
1743 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1744 {
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);
1753
1754 if(i == NON_MAC_QUEUE)
1755 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1756 else
1757 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1758 }
1759
1760 bdb->next_ptr = tp->rx_bdb_head[i];
1761 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1762
1763 tp->rx_bdb_head[i]->back_ptr = bdb;
1764 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1765 }
1766
1767 return (0);
1768}
1769
1770static int smctr_init_rx_fcbs(struct net_device *dev)
1771{
1772 struct net_local *tp = netdev_priv(dev);
1773 unsigned int i, j;
1774 FCBlock *fcb;
1775
1776 for(i = 0; i < NUM_RX_QS_USED; i++)
1777 {
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);
1785 else
1786 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1787
1788 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1789 {
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;
1795 fcb->next_ptr
1796 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1797
1798 if(i == NON_MAC_QUEUE)
1799 fcb->trc_next_ptr
1800 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1801 else
1802 fcb->trc_next_ptr
1803 = TRC_POINTER(fcb->next_ptr);
1804 }
1805
1806 fcb->next_ptr = tp->rx_fcb_head[i];
1807
1808 if(i == NON_MAC_QUEUE)
1809 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1810 else
1811 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1812
1813 tp->rx_fcb_head[i]->back_ptr = fcb;
1814 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1815 }
1816
1817 return(0);
1818}
1819
1820static int smctr_init_shared_memory(struct net_device *dev)
1821{
1822 struct net_local *tp = netdev_priv(dev);
1823 unsigned int i;
1824 __u32 *iscpb;
1825
1826 if(smctr_debug > 10)
1827 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1828
1829 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1830
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)));
1834
1835 smctr_set_page(dev, (__u8 *)tp->ram_access);
1836
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);
1841
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;
1846
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;
1853
1854 /* Initialize Interrupt Status Block. (ISB) */
1855 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1856 {
1857 tp->isb_ptr->IStatus[i].IType = 0xf0;
1858 tp->isb_ptr->IStatus[i].ISubtype = 0;
1859 }
1860
1861 tp->current_isb_index = 0;
1862
1863 /* Initialize Action Command Block. (ACB) */
1864 smctr_init_acbs(dev);
1865
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);
1870
1871 /* Initialize receive FCB's and BDB's. */
1872 smctr_init_rx_bdbs(dev);
1873 smctr_init_rx_fcbs(dev);
1874
1875 return (0);
1876}
1877
1878static int smctr_init_tx_bdbs(struct net_device *dev)
1879{
1880 struct net_local *tp = netdev_priv(dev);
1881 unsigned int i, j;
1882 BDBlock *bdb;
1883
1884 for(i = 0; i < NUM_TX_QS_USED; i++)
1885 {
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);
1890
1891 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1892 {
1893 bdb->next_ptr->back_ptr = bdb;
1894 bdb = bdb->next_ptr;
1895 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1896 bdb->next_ptr
1897 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1898 }
1899
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;
1903 }
1904
1905 return (0);
1906}
1907
1908static int smctr_init_tx_fcbs(struct net_device *dev)
1909{
1910 struct net_local *tp = netdev_priv(dev);
1911 unsigned int i, j;
1912 FCBlock *fcb;
1913
1914 for(i = 0; i < NUM_TX_QS_USED; i++)
1915 {
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);
1922
1923 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1924 {
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;
1930 fcb->next_ptr
1931 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1932 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1933 }
1934
1935 fcb->next_ptr = tp->tx_fcb_head[i];
1936 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1937
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;
1942 }
1943
1944 return (0);
1945}
1946
1947static int smctr_internal_self_test(struct net_device *dev)
1948{
1949 struct net_local *tp = netdev_priv(dev);
1950 int err;
1951
1952 if((err = smctr_issue_test_internal_rom_cmd(dev)))
1953 return (err);
1954
1955 if((err = smctr_wait_cmd(dev)))
1956 return (err);
1957
1958 if(tp->acb_head->cmd_done_status & 0xff)
1959 return (-1);
1960
1961 if((err = smctr_issue_test_hic_cmd(dev)))
1962 return (err);
1963
1964 if((err = smctr_wait_cmd(dev)))
1965 return (err);
1966
1967 if(tp->acb_head->cmd_done_status & 0xff)
1968 return (-1);
1969
1970 if((err = smctr_issue_test_mac_reg_cmd(dev)))
1971 return (err);
1972
1973 if((err = smctr_wait_cmd(dev)))
1974 return (err);
1975
1976 if(tp->acb_head->cmd_done_status & 0xff)
1977 return (-1);
1978
1979 return (0);
1980}
1981
1982/*
1983 * The typical workload of the driver: Handle the network interface interrupts.
1984 */
David Howells7d12e782006-10-05 14:55:46 +01001985static irqreturn_t smctr_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986{
1987 struct net_device *dev = dev_id;
1988 struct net_local *tp;
1989 int ioaddr;
1990 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1991 __u16 err1, err = NOT_MY_INTERRUPT;
1992 __u8 isb_type, isb_subtype;
1993 __u16 isb_index;
1994
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 ioaddr = dev->base_addr;
1996 tp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
1998 if(tp->status == NOT_INITIALIZED)
1999 return IRQ_NONE;
2000
2001 spin_lock(&tp->lock);
2002
2003 smctr_disable_bic_int(dev);
2004 smctr_enable_16bit(dev);
2005
2006 smctr_clear_int(dev);
2007
2008 /* First read the LSB */
2009 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2010 {
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;
2014
2015 (tp->current_isb_index)++;
2016 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2017 tp->current_isb_index = 0;
2018
2019 if(isb_type >= 0x10)
2020 {
2021 smctr_disable_16bit(dev);
2022 spin_unlock(&tp->lock);
2023 return IRQ_HANDLED;
2024 }
2025
2026 err = HARDWARE_FAILED;
2027 interrupt_ack_code = isb_index;
2028 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2029
2030 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2031
2032 switch(isb_type)
2033 {
2034 case ISB_IMC_MAC_TYPE_3:
2035 smctr_disable_16bit(dev);
2036
2037 switch(isb_subtype)
2038 {
2039 case 0:
2040 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2041 break;
2042
2043 case 1:
2044 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2045 break;
2046
2047 case 2:
2048 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2049 break;
2050
2051 case 3:
2052 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2053
2054 case 4:
2055 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2056 break;
2057
2058 case 5:
2059 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2060 break;
2061
2062 case 6:
2063 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2064 break;
2065
2066 case 7:
2067 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2068 break;
2069
2070 case 8: /* diagnostic state */
2071 break;
2072
2073 case 9:
2074 tp->monitor_state = MS_BEACON_TEST_STATE;
2075 if(smctr_lobe_media_test(dev))
2076 {
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);
2081 }
2082 else
2083 smctr_issue_insert_cmd(dev);
2084 break;
2085
2086 /* case 0x0a-0xff, illegal states */
2087 default:
2088 break;
2089 }
2090
2091 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2092 err = smctr_ring_status_chg(dev);
2093
2094 smctr_enable_16bit(dev);
2095 break;
2096
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
2107 */
2108 case ISB_IMC_MAC_ERROR_COUNTERS:
2109 /* Read 802.5 Error Counters */
2110 err = smctr_issue_read_ring_status_cmd(dev);
2111 break;
2112
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
2117 */
2118 case ISB_IMC_MAC_TYPE_2:
2119 err = smctr_issue_read_ring_status_cmd(dev);
2120 break;
2121
2122
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)
2127 {
2128 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2129 break;
2130 }
2131
2132 /* NON-MAC frames only */
2133 if(isb_subtype & TX_PENDING_PRIORITY_1)
2134 {
2135 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2136 break;
2137 }
2138
2139 /* MAC frames only */
2140 if(isb_subtype & TX_PENDING_PRIORITY_0)
2141 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2142
2143 /* Type 0x06 - TX END OF QUEUE (FE) */
2144 case ISB_IMC_END_OF_TX_QUEUE:
2145 /* BUG queue */
2146 if(isb_subtype & TX_PENDING_PRIORITY_2)
2147 {
2148 /* ok to clear Receive FIFO overrun
2149 * imask send_BUG now completes.
2150 */
2151 interrupt_unmask_bits |= 0x800;
2152
2153 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2154 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2155 break;
2156 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2157 break;
2158 }
2159
2160 /* NON-MAC queue only */
2161 if(isb_subtype & TX_PENDING_PRIORITY_1)
2162 {
2163 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2164 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2165 break;
2166 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2167 break;
2168 }
2169
2170 /* MAC queue only */
2171 if(isb_subtype & TX_PENDING_PRIORITY_0)
2172 {
2173 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2174 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2175 break;
2176
2177 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2178 }
2179 break;
2180
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
2186 */
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);
2191
2192 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2193 {
2194 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2195
2196 if(tp->ptr_rx_fcb_overruns)
2197 (*tp->ptr_rx_fcb_overruns)++;
2198 }
2199
2200 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2201 {
2202 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2203
2204 if(tp->ptr_rx_bdb_overruns)
2205 (*tp->ptr_rx_bdb_overruns)++;
2206 }
2207 err = err1;
2208 break;
2209
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
2215 */
2216 case ISB_IMC_MAC_RX_RESOURCE:
2217 tp->receive_queue_number = MAC_QUEUE;
2218 err1 = smctr_rx_frame(dev);
2219
2220 if(isb_subtype & MAC_RX_RESOURCE_FE)
2221 {
2222 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2223 break;
2224
2225 if(tp->ptr_rx_fcb_overruns)
2226 (*tp->ptr_rx_fcb_overruns)++;
2227 }
2228
2229 if(isb_subtype & MAC_RX_RESOURCE_BE)
2230 {
2231 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2232 break;
2233
2234 if(tp->ptr_rx_bdb_overruns)
2235 (*tp->ptr_rx_bdb_overruns)++;
2236 }
2237 err = err1;
2238 break;
2239
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);
2245 break;
2246
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);
2251 break;
2252
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
2257 */
2258 case ISB_IMC_TRC_FIFO_STATUS:
2259 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2260 {
2261 if(tp->ptr_tx_fifo_underruns)
2262 (*tp->ptr_tx_fifo_underruns)++;
2263 }
2264
2265 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2266 {
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)
2271 */
2272 tp->rx_fifo_overrun_count++;
2273
2274 if(tp->rx_fifo_overrun_count >= 3)
2275 {
2276 tp->rx_fifo_overrun_count = 0;
2277
2278 /* delay clearing fifo overrun
2279 * imask till send_BUG tx
2280 * complete posted
2281 */
2282 interrupt_unmask_bits &= (~0x800);
2283 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2284 }
2285
2286 if(tp->ptr_rx_fifo_overruns)
2287 (*tp->ptr_rx_fifo_overruns)++;
2288 }
2289
2290 err = SUCCESS;
2291 break;
2292
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)
2296 */
2297 case ISB_IMC_COMMAND_STATUS:
2298 err = SUCCESS;
2299 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2300 {
2301 printk(KERN_ERR "i1\n");
2302 smctr_disable_16bit(dev);
2303
2304 /* XXXXXXXXXXXXXXXXX */
2305 /* err = UM_Interrupt(dev); */
2306
2307 smctr_enable_16bit(dev);
2308 }
2309 else
2310 {
2311 if((tp->acb_head->cmd
2312 == ACB_CMD_READ_TRC_STATUS)
2313 && (tp->acb_head->subcmd
2314 == RW_TRC_STATUS_BLOCK))
2315 {
Al Viro79ea13c2008-01-24 02:06:46 -08002316 if(tp->ptr_bcn_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 {
2318 *(tp->ptr_bcn_type)
2319 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2320 }
2321
2322 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2323 {
2324 smctr_update_err_stats(dev);
2325 }
2326
2327 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2328 {
2329 tp->ring_status
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))
2336 {
2337 smctr_issue_remove_cmd(dev);
2338 }
2339
2340 if(err != SUCCESS)
2341 {
2342 tp->acb_pending = 0;
2343 break;
2344 }
2345 }
2346
2347 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2348 {
2349 if(tp->ptr_una)
2350 {
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]);
2354 }
2355
2356 }
2357
2358 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2359 err = smctr_send_rq_init(dev);
2360 }
2361 }
2362 }
2363
2364 tp->acb_pending = 0;
2365 break;
2366
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
2371 * 03 TSM_EXP at S21
2372 * 04 FR_REMOVE received at S42
2373 * 05 TBR_EXP, BR_FLAG_SET at S42
2374 * 06 TBT_EXP at S53
2375 */
2376 case ISB_IMC_MAC_TYPE_1:
2377 if(isb_subtype > 8)
2378 {
2379 err = HARDWARE_FAILED;
2380 break;
2381 }
2382
2383 err = SUCCESS;
2384 switch(isb_subtype)
2385 {
2386 case 0:
2387 tp->join_state = JS_BYPASS_STATE;
2388 if(tp->status != CLOSED)
2389 {
2390 tp->status = CLOSED;
2391 err = smctr_status_chg(dev);
2392 }
2393 break;
2394
2395 case 1:
2396 tp->join_state = JS_LOBE_TEST_STATE;
2397 break;
2398
2399 case 2:
2400 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2401 break;
2402
2403 case 3:
2404 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2405 break;
2406
2407 case 4:
2408 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2409 break;
2410
2411 case 5:
2412 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2413 break;
2414
2415 case 6:
2416 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2417 break;
2418
2419 case 7:
2420 tp->join_state = JS_JOIN_COMPLETE_STATE;
2421 tp->status = OPEN;
2422 err = smctr_status_chg(dev);
2423 break;
2424
2425 case 8:
2426 tp->join_state = JS_BYPASS_WAIT_STATE;
2427 break;
2428 }
2429 break ;
2430
2431 /* Type 0x0E - TRC Initialization Sequence Interrupt
2432 * Subtype -- 00-FF Initializatin sequence complete
2433 */
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);
2439 break;
2440
2441 /* other interrupt types, illegal */
2442 default:
2443 break;
2444 }
2445
2446 if(err != SUCCESS)
2447 break;
2448 }
2449
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
2454 */
2455 if(!(interrupt_ack_code & 0xff00))
2456 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2457
2458 smctr_disable_16bit(dev);
2459 smctr_enable_bic_int(dev);
2460 spin_unlock(&tp->lock);
2461
2462 return IRQ_HANDLED;
2463}
2464
2465static int smctr_issue_enable_int_cmd(struct net_device *dev,
2466 __u16 interrupt_enable_mask)
2467{
2468 struct net_local *tp = netdev_priv(dev);
2469 int err;
2470
2471 if((err = smctr_wait_while_cbusy(dev)))
2472 return (err);
2473
2474 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2475 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2476
2477 smctr_set_ctrl_attention(dev);
2478
2479 return (0);
2480}
2481
2482static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2483{
2484 struct net_local *tp = netdev_priv(dev);
2485
2486 if(smctr_wait_while_cbusy(dev))
2487 return (-1);
2488
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;
2492
2493 smctr_set_ctrl_attention(dev);
2494
2495 return (0);
2496}
2497
2498static int smctr_issue_init_timers_cmd(struct net_device *dev)
2499{
2500 struct net_local *tp = netdev_priv(dev);
2501 unsigned int i;
2502 int err;
2503 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2504
2505 if((err = smctr_wait_while_cbusy(dev)))
2506 return (err);
2507
2508 if((err = smctr_wait_cmd(dev)))
2509 return (err);
2510
2511 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2512 tp->config_word1 = 0;
2513
2514 if((tp->media_type == MEDIA_STP_16)
2515 || (tp->media_type == MEDIA_UTP_16)
2516 || (tp->media_type == MEDIA_STP_16_UTP_16))
2517 {
2518 tp->config_word0 |= FREQ_16MB_BIT;
2519 }
2520
2521 if(tp->mode_bits & EARLY_TOKEN_REL)
2522 tp->config_word0 |= ETREN;
2523
2524 if(tp->mode_bits & LOOPING_MODE_MASK)
2525 tp->config_word0 |= RX_OWN_BIT;
2526 else
2527 tp->config_word0 &= ~RX_OWN_BIT;
2528
2529 if(tp->receive_mask & PROMISCUOUS_MODE)
2530 tp->config_word0 |= PROMISCUOUS_BIT;
2531 else
2532 tp->config_word0 &= ~PROMISCUOUS_BIT;
2533
2534 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2535 tp->config_word0 |= SAVBAD_BIT;
2536 else
2537 tp->config_word0 &= ~SAVBAD_BIT;
2538
2539 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2540 tp->config_word0 |= RXATMAC;
2541 else
2542 tp->config_word0 &= ~RXATMAC;
2543
2544 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2545 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2546 else
2547 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2548
2549 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2550 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2551 else
2552 {
2553 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2554 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2555 else
2556 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2557 }
2558
2559 if((tp->media_type == MEDIA_STP_16)
2560 || (tp->media_type == MEDIA_UTP_16)
2561 || (tp->media_type == MEDIA_STP_16_UTP_16))
2562 {
2563 tp->config_word1 |= INTERFRAME_SPACING_16;
2564 }
2565 else
2566 tp->config_word1 |= INTERFRAME_SPACING_4;
2567
2568 *pTimer_Struc++ = tp->config_word0;
2569 *pTimer_Struc++ = tp->config_word1;
2570
2571 if((tp->media_type == MEDIA_STP_4)
2572 || (tp->media_type == MEDIA_UTP_4)
2573 || (tp->media_type == MEDIA_STP_4_UTP_4))
2574 {
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 */
2589 }
2590 else
2591 {
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 */
2606 }
2607
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);
2615
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;
2623
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;
2631
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;
2637
2638 /* Set ring number address. */
2639 *pTimer_Struc++ = tp->source_ring_number;
2640 *pTimer_Struc++ = tp->target_ring_number;
2641
2642 /* Physical drop number. */
2643 *pTimer_Struc++ = (unsigned short)0;
2644 *pTimer_Struc++ = (unsigned short)0;
2645
2646 /* Product instance ID. */
2647 for(i = 0; i < 9; i++)
2648 *pTimer_Struc++ = (unsigned short)0;
2649
2650 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2651
2652 return (err);
2653}
2654
2655static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2656{
2657 struct net_local *tp = netdev_priv(dev);
2658 unsigned int i;
2659 int err;
2660 void **txrx_ptrs = (void *)tp->misc_command_data;
2661
2662 if((err = smctr_wait_while_cbusy(dev)))
2663 return (err);
2664
2665 if((err = smctr_wait_cmd(dev)))
2666 {
2667 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
2668 return (err);
2669 }
2670
2671 /* Initialize Transmit Queue Pointers that are used, to point to
2672 * a single FCB.
2673 */
2674 for(i = 0; i < NUM_TX_QS_USED; i++)
2675 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2676
2677 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2678 for(; i < MAX_TX_QS; i++)
2679 *txrx_ptrs++ = (void *)0;
2680
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.
2683 */
2684 for(i = 0; i < NUM_RX_QS_USED; i++)
2685 {
2686 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2687 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2688 }
2689
2690 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2691 for(; i < MAX_RX_QS; i++)
2692 {
2693 *txrx_ptrs++ = (void *)0;
2694 *txrx_ptrs++ = (void *)0;
2695 }
2696
2697 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2698
2699 return (err);
2700}
2701
2702static int smctr_issue_insert_cmd(struct net_device *dev)
2703{
2704 int err;
2705
2706 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2707
2708 return (err);
2709}
2710
2711static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2712{
2713 int err;
2714
2715 if((err = smctr_wait_while_cbusy(dev)))
2716 return (err);
2717
2718 if((err = smctr_wait_cmd(dev)))
2719 return (err);
2720
2721 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2722 RW_TRC_STATUS_BLOCK);
2723
2724 return (err);
2725}
2726
2727static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2728{
2729 int err;
2730
2731 if((err = smctr_wait_while_cbusy(dev)))
2732 return (err);
2733
2734 if((err = smctr_wait_cmd(dev)))
2735 return (err);
2736
2737 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2738 aword_cnt);
2739
2740 return (err);
2741}
2742
2743static int smctr_issue_remove_cmd(struct net_device *dev)
2744{
2745 struct net_local *tp = netdev_priv(dev);
2746 int err;
2747
2748 if((err = smctr_wait_while_cbusy(dev)))
2749 return (err);
2750
2751 tp->sclb_ptr->resume_control = 0;
2752 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2753
2754 smctr_set_ctrl_attention(dev);
2755
2756 return (0);
2757}
2758
2759static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2760{
2761 struct net_local *tp = netdev_priv(dev);
2762 int err;
2763
2764 if((err = smctr_wait_while_cbusy(dev)))
2765 return (err);
2766
2767 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2768 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2769
2770 tp->acb_pending = 1;
2771
2772 smctr_set_ctrl_attention(dev);
2773
2774 return (0);
2775}
2776
2777static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2778{
2779 struct net_local *tp = netdev_priv(dev);
2780 int err;
2781
2782 if((err = smctr_wait_while_cbusy(dev)))
2783 return (err);
2784
2785 if(queue == MAC_QUEUE)
2786 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2787 else
2788 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2789
2790 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2791
2792 smctr_set_ctrl_attention(dev);
2793
2794 return (0);
2795}
2796
2797static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2798{
2799 struct net_local *tp = netdev_priv(dev);
2800
2801 if(smctr_debug > 10)
2802 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2803
2804 if(smctr_wait_while_cbusy(dev))
2805 return (-1);
2806
2807 if(queue == MAC_QUEUE)
2808 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2809 else
2810 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2811
2812 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2813
2814 smctr_set_ctrl_attention(dev);
2815
2816 return (0);
2817}
2818
2819static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2820{
2821 struct net_local *tp = netdev_priv(dev);
2822
2823 if(smctr_debug > 10)
2824 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2825
2826 if(smctr_wait_while_cbusy(dev))
2827 return (-1);
2828
2829 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2830 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2831
2832 smctr_set_ctrl_attention(dev);
2833
2834 return (0);
2835}
2836
2837static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2838{
2839 int err;
2840
2841 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2842 TRC_INTERNAL_ROM_TEST);
2843
2844 return (err);
2845}
2846
2847static int smctr_issue_test_hic_cmd(struct net_device *dev)
2848{
2849 int err;
2850
2851 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2852 TRC_HOST_INTERFACE_REG_TEST);
2853
2854 return (err);
2855}
2856
2857static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2858{
2859 int err;
2860
2861 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2862 TRC_MAC_REGISTERS_TEST);
2863
2864 return (err);
2865}
2866
2867static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2868{
2869 int err;
2870
2871 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2872 TRC_INTERNAL_LOOPBACK);
2873
2874 return (err);
2875}
2876
2877static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2878{
2879 int err;
2880
2881 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2882 TRC_TRI_LOOPBACK);
2883
2884 return (err);
2885}
2886
2887static int smctr_issue_write_byte_cmd(struct net_device *dev,
2888 short aword_cnt, void *byte)
2889{
2890 struct net_local *tp = netdev_priv(dev);
2891 unsigned int iword, ibyte;
2892 int err;
2893
2894 if((err = smctr_wait_while_cbusy(dev)))
2895 return (err);
2896
2897 if((err = smctr_wait_cmd(dev)))
2898 return (err);
2899
2900 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2901 iword++, ibyte += 2)
2902 {
2903 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2904 | (*((__u8 *)byte + ibyte + 1));
2905 }
2906
2907 return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2908 aword_cnt));
2909}
2910
2911static int smctr_issue_write_word_cmd(struct net_device *dev,
2912 short aword_cnt, void *word)
2913{
2914 struct net_local *tp = netdev_priv(dev);
2915 unsigned int i, err;
2916
2917 if((err = smctr_wait_while_cbusy(dev)))
2918 return (err);
2919
2920 if((err = smctr_wait_cmd(dev)))
2921 return (err);
2922
2923 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2924 tp->misc_command_data[i] = *((__u16 *)word + i);
2925
2926 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2927 aword_cnt);
2928
2929 return (err);
2930}
2931
2932static int smctr_join_complete_state(struct net_device *dev)
2933{
2934 int err;
2935
2936 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2937 JS_JOIN_COMPLETE_STATE);
2938
2939 return (err);
2940}
2941
2942static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2943{
2944 struct net_local *tp = netdev_priv(dev);
2945 unsigned int i, j;
2946 FCBlock *fcb;
2947 BDBlock *bdb;
2948
2949 for(i = 0; i < NUM_TX_QS_USED; i++)
2950 {
2951 fcb = tp->tx_fcb_head[i];
2952 bdb = tp->tx_bdb_head[i];
2953
2954 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2955 {
2956 fcb->bdb_ptr = bdb;
2957 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2958 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2959 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2960 }
2961 }
2962
2963 return (0);
2964}
2965
2966static int smctr_load_firmware(struct net_device *dev)
2967{
2968 struct net_local *tp = netdev_priv(dev);
David Woodhouse0f805b82008-05-29 16:39:16 +03002969 const struct firmware *fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 __u16 i, checksum = 0;
2971 int err = 0;
2972
2973 if(smctr_debug > 10)
2974 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2975
David Woodhouse0f805b82008-05-29 16:39:16 +03002976 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);
2979 }
2980
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 tp->num_of_tx_buffs = 4;
2982 tp->mode_bits |= UMAC;
2983 tp->receive_mask = 0;
2984 tp->max_packet_size = 4177;
2985
2986 /* Can only upload the firmware once per adapter reset. */
David Woodhouse0f805b82008-05-29 16:39:16 +03002987 if (tp->microcode_version != 0) {
2988 err = (UCODE_PRESENT);
2989 goto out;
2990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991
2992 /* Verify the firmware exists and is there in the right amount. */
David Woodhouse0f805b82008-05-29 16:39:16 +03002993 if (!fw->data
2994 || (*(fw->data + UCODE_VERSION_OFFSET) < UCODE_VERSION))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 {
David Woodhouse0f805b82008-05-29 16:39:16 +03002996 err = (UCODE_NOT_PRESENT);
2997 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 }
2999
3000 /* UCODE_SIZE is not included in Checksum. */
David Woodhouse0f805b82008-05-29 16:39:16 +03003001 for(i = 0; i < *((__u16 *)(fw->data + UCODE_SIZE_OFFSET)); i += 2)
3002 checksum += *((__u16 *)(fw->data + 2 + i));
3003 if (checksum) {
3004 err = (UCODE_NOT_PRESENT);
3005 goto out;
3006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007
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);
3012
3013 if((smctr_checksum_firmware(dev))
David Woodhouse0f805b82008-05-29 16:39:16 +03003014 || (*(fw->data + UCODE_VERSION_OFFSET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 > tp->microcode_version))
3016 {
3017 smctr_enable_adapter_ctrl_store(dev);
3018
3019 /* Zero out ram space for firmware. */
3020 for(i = 0; i < CS_RAM_SIZE; i += 2)
3021 *((__u16 *)(tp->ram_access + i)) = 0;
3022
David Woodhouse0f805b82008-05-29 16:39:16 +03003023 smctr_decode_firmware(dev, fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
David Woodhouse0f805b82008-05-29 16:39:16 +03003025 tp->microcode_version = *(fw->data + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 = (tp->microcode_version << 8);
3027 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
3028 = ~(tp->microcode_version << 8) + 1;
3029
3030 smctr_disable_adapter_ctrl_store(dev);
3031
3032 if(smctr_checksum_firmware(dev))
3033 err = HARDWARE_FAILED;
3034 }
3035 else
3036 err = UCODE_PRESENT;
3037
3038 smctr_disable_16bit(dev);
David Woodhouse0f805b82008-05-29 16:39:16 +03003039 out:
3040 release_firmware(fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 return (err);
3042}
3043
3044static int smctr_load_node_addr(struct net_device *dev)
3045{
3046 int ioaddr = dev->base_addr;
3047 unsigned int i;
3048 __u8 r;
3049
3050 for(i = 0; i < 6; i++)
3051 {
3052 r = inb(ioaddr + LAR0 + i);
3053 dev->dev_addr[i] = (char)r;
3054 }
3055 dev->addr_len = 6;
3056
3057 return (0);
3058}
3059
3060/* Lobe Media Test.
3061 * During the transmission of the initial 1500 lobe media MAC frames,
3062 * the phase lock loop in the 805 chip may lock, and then un-lock, causing
3063 * the 825 to go into a PURGE state. When performing a PURGE, the MCT
3064 * microcode will not transmit any frames given to it by the host, and
3065 * will consequently cause a timeout.
3066 *
3067 * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003068 * queues other than the one used for the lobe_media_test should be
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 * disabled.!?
3070 *
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
3075 * is successful.
3076 */
3077static int smctr_lobe_media_test(struct net_device *dev)
3078{
3079 struct net_local *tp = netdev_priv(dev);
3080 unsigned int i, perror = 0;
3081 unsigned short saved_rcv_mask;
3082
3083 if(smctr_debug > 10)
3084 printk(KERN_DEBUG "%s: smctr_lobe_media_test\n", dev->name);
3085
3086 /* Clear receive mask for lobe test. */
3087 saved_rcv_mask = tp->receive_mask;
3088 tp->receive_mask = 0;
3089
3090 smctr_chg_rx_mask(dev);
3091
3092 /* Setup the lobe media test. */
3093 smctr_lobe_media_test_cmd(dev);
3094 if(smctr_wait_cmd(dev))
3095 {
3096 smctr_reset_adapter(dev);
3097 tp->status = CLOSED;
3098 return (LOBE_MEDIA_TEST_FAILED);
3099 }
3100
3101 /* Tx lobe media test frames. */
3102 for(i = 0; i < 1500; ++i)
3103 {
3104 if(smctr_send_lobe_media_test(dev))
3105 {
3106 if(perror)
3107 {
3108 smctr_reset_adapter(dev);
3109 tp->state = CLOSED;
3110 return (LOBE_MEDIA_TEST_FAILED);
3111 }
3112 else
3113 {
3114 perror = 1;
3115 if(smctr_lobe_media_test_cmd(dev))
3116 {
3117 smctr_reset_adapter(dev);
3118 tp->state = CLOSED;
3119 return (LOBE_MEDIA_TEST_FAILED);
3120 }
3121 }
3122 }
3123 }
3124
3125 if(smctr_send_dat(dev))
3126 {
3127 if(smctr_send_dat(dev))
3128 {
3129 smctr_reset_adapter(dev);
3130 tp->state = CLOSED;
3131 return (LOBE_MEDIA_TEST_FAILED);
3132 }
3133 }
3134
3135 /* Check if any frames received during test. */
3136 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status)
3137 || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3138 {
3139 smctr_reset_adapter(dev);
3140 tp->state = CLOSED;
3141 return (LOBE_MEDIA_TEST_FAILED);
3142 }
3143
3144 /* Set receive mask to "Promisc" mode. */
3145 tp->receive_mask = saved_rcv_mask;
3146
3147 smctr_chg_rx_mask(dev);
3148
3149 return (0);
3150}
3151
3152static int smctr_lobe_media_test_cmd(struct net_device *dev)
3153{
3154 struct net_local *tp = netdev_priv(dev);
3155 int err;
3156
3157 if(smctr_debug > 10)
3158 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3159
3160 /* Change to lobe media test state. */
3161 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3162 {
3163 smctr_lobe_media_test_state(dev);
3164 if(smctr_wait_cmd(dev))
3165 {
3166 printk(KERN_ERR "Lobe Failed test state\n");
3167 return (LOBE_MEDIA_TEST_FAILED);
3168 }
3169 }
3170
3171 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3172 TRC_LOBE_MEDIA_TEST);
3173
3174 return (err);
3175}
3176
3177static int smctr_lobe_media_test_state(struct net_device *dev)
3178{
3179 int err;
3180
3181 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3182 JS_LOBE_TEST_STATE);
3183
3184 return (err);
3185}
3186
3187static int smctr_make_8025_hdr(struct net_device *dev,
3188 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3189{
3190 tmf->ac = MSB(ac_fc); /* msb is access control */
3191 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3192
3193 tmf->sa[0] = dev->dev_addr[0];
3194 tmf->sa[1] = dev->dev_addr[1];
3195 tmf->sa[2] = dev->dev_addr[2];
3196 tmf->sa[3] = dev->dev_addr[3];
3197 tmf->sa[4] = dev->dev_addr[4];
3198 tmf->sa[5] = dev->dev_addr[5];
3199
3200 switch(tmf->vc)
3201 {
3202 /* Send RQ_INIT to RPS */
3203 case RQ_INIT:
3204 tmf->da[0] = 0xc0;
3205 tmf->da[1] = 0x00;
3206 tmf->da[2] = 0x00;
3207 tmf->da[3] = 0x00;
3208 tmf->da[4] = 0x00;
3209 tmf->da[5] = 0x02;
3210 break;
3211
3212 /* Send RPT_TX_FORWARD to CRS */
3213 case RPT_TX_FORWARD:
3214 tmf->da[0] = 0xc0;
3215 tmf->da[1] = 0x00;
3216 tmf->da[2] = 0x00;
3217 tmf->da[3] = 0x00;
3218 tmf->da[4] = 0x00;
3219 tmf->da[5] = 0x10;
3220 break;
3221
3222 /* Everything else goes to sender */
3223 default:
3224 tmf->da[0] = rmf->sa[0];
3225 tmf->da[1] = rmf->sa[1];
3226 tmf->da[2] = rmf->sa[2];
3227 tmf->da[3] = rmf->sa[3];
3228 tmf->da[4] = rmf->sa[4];
3229 tmf->da[5] = rmf->sa[5];
3230 break;
3231 }
3232
3233 return (0);
3234}
3235
3236static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3237{
3238 struct net_local *tp = netdev_priv(dev);
3239
3240 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3241 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3242
3243 tsv->svv[0] = MSB(tp->authorized_access_priority);
3244 tsv->svv[1] = LSB(tp->authorized_access_priority);
3245
3246 return (0);
3247}
3248
3249static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3250{
3251 tsv->svi = ADDRESS_MODIFER;
3252 tsv->svl = S_ADDRESS_MODIFER;
3253
3254 tsv->svv[0] = 0;
3255 tsv->svv[1] = 0;
3256
3257 return (0);
3258}
3259
3260static int smctr_make_auth_funct_class(struct net_device *dev,
3261 MAC_SUB_VECTOR *tsv)
3262{
3263 struct net_local *tp = netdev_priv(dev);
3264
3265 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3266 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3267
3268 tsv->svv[0] = MSB(tp->authorized_function_classes);
3269 tsv->svv[1] = LSB(tp->authorized_function_classes);
3270
3271 return (0);
3272}
3273
3274static int smctr_make_corr(struct net_device *dev,
3275 MAC_SUB_VECTOR *tsv, __u16 correlator)
3276{
3277 tsv->svi = CORRELATOR;
3278 tsv->svl = S_CORRELATOR;
3279
3280 tsv->svv[0] = MSB(correlator);
3281 tsv->svv[1] = LSB(correlator);
3282
3283 return (0);
3284}
3285
3286static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3287{
3288 struct net_local *tp = netdev_priv(dev);
3289
3290 smctr_get_functional_address(dev);
3291
3292 tsv->svi = FUNCTIONAL_ADDRESS;
3293 tsv->svl = S_FUNCTIONAL_ADDRESS;
3294
3295 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3296 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3297
3298 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3299 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3300
3301 return (0);
3302}
3303
3304static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3305{
3306 struct net_local *tp = netdev_priv(dev);
3307
3308 smctr_get_group_address(dev);
3309
3310 tsv->svi = GROUP_ADDRESS;
3311 tsv->svl = S_GROUP_ADDRESS;
3312
3313 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3314 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3315
3316 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3317 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3318
3319 /* Set Group Address Sub-vector to all zeros if only the
3320 * Group Address/Functional Address Indicator is set.
3321 */
3322 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00
3323 && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
3324 tsv->svv[0] = 0x00;
3325
3326 return (0);
3327}
3328
3329static int smctr_make_phy_drop_num(struct net_device *dev,
3330 MAC_SUB_VECTOR *tsv)
3331{
3332 struct net_local *tp = netdev_priv(dev);
3333
3334 smctr_get_physical_drop_number(dev);
3335
3336 tsv->svi = PHYSICAL_DROP;
3337 tsv->svl = S_PHYSICAL_DROP;
3338
3339 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3340 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3341
3342 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3343 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3344
3345 return (0);
3346}
3347
3348static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3349{
3350 int i;
3351
3352 tsv->svi = PRODUCT_INSTANCE_ID;
3353 tsv->svl = S_PRODUCT_INSTANCE_ID;
3354
3355 for(i = 0; i < 18; i++)
3356 tsv->svv[i] = 0xF0;
3357
3358 return (0);
3359}
3360
3361static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3362{
3363 struct net_local *tp = netdev_priv(dev);
3364
3365 smctr_get_station_id(dev);
3366
3367 tsv->svi = STATION_IDENTIFER;
3368 tsv->svl = S_STATION_IDENTIFER;
3369
3370 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3371 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3372
3373 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3374 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3375
3376 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3377 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3378
3379 return (0);
3380}
3381
3382static int smctr_make_ring_station_status(struct net_device *dev,
3383 MAC_SUB_VECTOR * tsv)
3384{
3385 tsv->svi = RING_STATION_STATUS;
3386 tsv->svl = S_RING_STATION_STATUS;
3387
3388 tsv->svv[0] = 0;
3389 tsv->svv[1] = 0;
3390 tsv->svv[2] = 0;
3391 tsv->svv[3] = 0;
3392 tsv->svv[4] = 0;
3393 tsv->svv[5] = 0;
3394
3395 return (0);
3396}
3397
3398static int smctr_make_ring_station_version(struct net_device *dev,
3399 MAC_SUB_VECTOR *tsv)
3400{
3401 struct net_local *tp = netdev_priv(dev);
3402
3403 tsv->svi = RING_STATION_VERSION_NUMBER;
3404 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3405
3406 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3407 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3408 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3409 tsv->svv[3] = 0x40; /* EBCDIC - */
3410 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3411 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3412 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3413 tsv->svv[7] = 0x40; /* EBCDIC - */
3414 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3415
3416 if(tp->extra_info & CHIP_REV_MASK)
3417 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3418 else
3419 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3420
3421 return (0);
3422}
3423
3424static int smctr_make_tx_status_code(struct net_device *dev,
3425 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3426{
3427 tsv->svi = TRANSMIT_STATUS_CODE;
3428 tsv->svl = S_TRANSMIT_STATUS_CODE;
3429
Jay Schulist26c080bf2008-03-18 17:53:09 -04003430 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) | IBM_PASS_SOURCE_ADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431
3432 /* Stripped frame status of Transmitted Frame */
3433 tsv->svv[1] = tx_fstatus & 0xff;
3434
3435 return (0);
3436}
3437
3438static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3439 MAC_SUB_VECTOR *tsv)
3440{
3441 struct net_local *tp = netdev_priv(dev);
3442
3443 smctr_get_upstream_neighbor_addr(dev);
3444
3445 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3446 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3447
3448 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3449 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3450
3451 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3452 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3453
3454 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3455 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3456
3457 return (0);
3458}
3459
3460static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3461{
3462 tsv->svi = WRAP_DATA;
3463 tsv->svl = S_WRAP_DATA;
3464
3465 return (0);
3466}
3467
3468/*
3469 * Open/initialize the board. This is called sometime after
3470 * booting when the 'ifconfig' program is run.
3471 *
3472 * This routine should set everything up anew at each open, even
3473 * registers that "should" only need to be set once at boot, so that
3474 * there is non-reboot way to recover if something goes wrong.
3475 */
3476static int smctr_open(struct net_device *dev)
3477{
3478 int err;
3479
3480 if(smctr_debug > 10)
3481 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3482
3483 err = smctr_init_adapter(dev);
3484 if(err < 0)
3485 return (err);
3486
3487 return (err);
3488}
3489
3490/* Interrupt driven open of Token card. */
3491static int smctr_open_tr(struct net_device *dev)
3492{
3493 struct net_local *tp = netdev_priv(dev);
3494 unsigned long flags;
3495 int err;
3496
3497 if(smctr_debug > 10)
3498 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3499
3500 /* Now we can actually open the adapter. */
3501 if(tp->status == OPEN)
3502 return (0);
3503 if(tp->status != INITIALIZED)
3504 return (-1);
3505
3506 /* FIXME: it would work a lot better if we masked the irq sources
3507 on the card here, then we could skip the locking and poll nicely */
3508 spin_lock_irqsave(&tp->lock, flags);
3509
3510 smctr_set_page(dev, (__u8 *)tp->ram_access);
3511
3512 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3513 goto out;
3514
3515 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3516 goto out;
3517
3518 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3519 goto out;
3520
3521 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3522 goto out;
3523
3524 tp->status = CLOSED;
3525
3526 /* Insert into the Ring or Enter Loopback Mode. */
3527 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3528 {
3529 tp->status = CLOSED;
3530
3531 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3532 {
3533 if(!(err = smctr_wait_cmd(dev)))
3534 tp->status = OPEN;
3535 }
3536
3537 smctr_status_chg(dev);
3538 }
3539 else
3540 {
3541 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3542 {
3543 tp->status = CLOSED;
3544 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3545 {
3546 if(!(err = smctr_wait_cmd(dev)))
3547 tp->status = OPEN;
3548 }
3549
3550 smctr_status_chg(dev);
3551 }
3552 else
3553 {
3554 if((tp->mode_bits & LOOPING_MODE_MASK)
3555 == LOOPBACK_MODE_3)
3556 {
3557 tp->status = CLOSED;
3558 if(!(err = smctr_lobe_media_test_cmd(dev)))
3559 {
3560 if(!(err = smctr_wait_cmd(dev)))
3561 tp->status = OPEN;
3562 }
3563 smctr_status_chg(dev);
3564 }
3565 else
3566 {
3567 if(!(err = smctr_lobe_media_test(dev)))
3568 err = smctr_issue_insert_cmd(dev);
3569 else
3570 {
3571 if(err == LOBE_MEDIA_TEST_FAILED)
3572 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3573 }
3574 }
3575 }
3576 }
3577
3578out:
3579 spin_unlock_irqrestore(&tp->lock, flags);
3580
3581 return (err);
3582}
3583
3584/* Check for a network adapter of this type,
3585 * and return device structure if one exists.
3586 */
3587struct net_device __init *smctr_probe(int unit)
3588{
3589 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3590 static const unsigned ports[] = {
3591 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3592 0x320, 0x340, 0x360, 0x380, 0
3593 };
3594 const unsigned *port;
3595 int err = 0;
3596
3597 if (!dev)
3598 return ERR_PTR(-ENOMEM);
3599
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 if (unit >= 0) {
3601 sprintf(dev->name, "tr%d", unit);
3602 netdev_boot_setup_check(dev);
3603 }
3604
3605 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3606 err = smctr_probe1(dev, dev->base_addr);
3607 else if(dev->base_addr != 0) /* Don't probe at all. */
3608 err =-ENXIO;
3609 else {
3610 for (port = ports; *port; port++) {
3611 err = smctr_probe1(dev, *port);
3612 if (!err)
3613 break;
3614 }
3615 }
3616 if (err)
3617 goto out;
3618 err = register_netdev(dev);
3619 if (err)
3620 goto out1;
3621 return dev;
3622out1:
3623#ifdef CONFIG_MCA_LEGACY
3624 { struct net_local *tp = netdev_priv(dev);
3625 if (tp->slot_num)
3626 mca_mark_as_unused(tp->slot_num);
3627 }
3628#endif
3629 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3630 free_irq(dev->irq, dev);
3631out:
3632 free_netdev(dev);
3633 return ERR_PTR(err);
3634}
3635
3636
3637static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3638{
3639 static unsigned version_printed;
3640 struct net_local *tp = netdev_priv(dev);
3641 int err;
3642 __u32 *ram;
3643
3644 if(smctr_debug && version_printed++ == 0)
3645 printk(version);
3646
3647 spin_lock_init(&tp->lock);
3648 dev->base_addr = ioaddr;
3649
3650 /* Actually detect an adapter now. */
3651 err = smctr_chk_isa(dev);
3652 if(err < 0)
3653 {
3654 if ((err = smctr_chk_mca(dev)) < 0) {
3655 err = -ENODEV;
3656 goto out;
3657 }
3658 }
3659
3660 tp = netdev_priv(dev);
3661 dev->mem_start = tp->ram_base;
3662 dev->mem_end = dev->mem_start + 0x10000;
3663 ram = (__u32 *)phys_to_virt(dev->mem_start);
3664 tp->ram_access = *(__u32 *)&ram;
3665 tp->status = NOT_INITIALIZED;
3666
3667 err = smctr_load_firmware(dev);
3668 if(err != UCODE_PRESENT && err != SUCCESS)
3669 {
3670 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3671 err = -EIO;
3672 goto out;
3673 }
3674
3675 /* Allow user to specify ring speed on module insert. */
3676 if(ringspeed == 4)
3677 tp->media_type = MEDIA_UTP_4;
3678 else
3679 tp->media_type = MEDIA_UTP_16;
3680
3681 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3682 dev->name, smctr_name, smctr_model,
3683 (unsigned int)dev->base_addr,
3684 dev->irq, tp->rom_base, tp->ram_base);
3685
3686 dev->open = smctr_open;
3687 dev->stop = smctr_close;
3688 dev->hard_start_xmit = smctr_send_packet;
3689 dev->tx_timeout = smctr_timeout;
3690 dev->watchdog_timeo = HZ;
3691 dev->get_stats = smctr_get_stats;
3692 dev->set_multicast_list = &smctr_set_multicast_list;
3693 return (0);
3694
3695out:
3696 return err;
3697}
3698
3699static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3700 struct net_device *dev, __u16 rx_status)
3701{
3702 struct net_local *tp = netdev_priv(dev);
3703 struct sk_buff *skb;
3704 __u16 rcode, correlator;
3705 int err = 0;
3706 __u8 xframe = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707
3708 rmf->vl = SWAP_BYTES(rmf->vl);
3709 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3710 {
3711 switch(rmf->vc)
3712 {
3713 /* Received MAC Frames Processed by RS. */
3714 case INIT:
3715 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3716 {
3717 return (rcode);
3718 }
3719
3720 if((err = smctr_send_rsp(dev, rmf, rcode,
3721 correlator)))
3722 {
3723 return (err);
3724 }
3725 break;
3726
3727 case CHG_PARM:
3728 if((rcode = smctr_rcv_chg_param(dev, rmf,
3729 &correlator)) ==HARDWARE_FAILED)
3730 {
3731 return (rcode);
3732 }
3733
3734 if((err = smctr_send_rsp(dev, rmf, rcode,
3735 correlator)))
3736 {
3737 return (err);
3738 }
3739 break;
3740
3741 case RQ_ADDR:
3742 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3743 rmf, &correlator)) != POSITIVE_ACK)
3744 {
3745 if(rcode == HARDWARE_FAILED)
3746 return (rcode);
3747 else
3748 return (smctr_send_rsp(dev, rmf,
3749 rcode, correlator));
3750 }
3751
3752 if((err = smctr_send_rpt_addr(dev, rmf,
3753 correlator)))
3754 {
3755 return (err);
3756 }
3757 break;
3758
3759 case RQ_ATTCH:
3760 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3761 rmf, &correlator)) != POSITIVE_ACK)
3762 {
3763 if(rcode == HARDWARE_FAILED)
3764 return (rcode);
3765 else
3766 return (smctr_send_rsp(dev, rmf,
3767 rcode,
3768 correlator));
3769 }
3770
3771 if((err = smctr_send_rpt_attch(dev, rmf,
3772 correlator)))
3773 {
3774 return (err);
3775 }
3776 break;
3777
3778 case RQ_STATE:
3779 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3780 rmf, &correlator)) != POSITIVE_ACK)
3781 {
3782 if(rcode == HARDWARE_FAILED)
3783 return (rcode);
3784 else
3785 return (smctr_send_rsp(dev, rmf,
3786 rcode,
3787 correlator));
3788 }
3789
3790 if((err = smctr_send_rpt_state(dev, rmf,
3791 correlator)))
3792 {
3793 return (err);
3794 }
3795 break;
3796
Jeff Garzika6343af2007-07-17 05:39:58 -04003797 case TX_FORWARD: {
3798 __u16 uninitialized_var(tx_fstatus);
3799
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3801 != POSITIVE_ACK)
3802 {
3803 if(rcode == HARDWARE_FAILED)
3804 return (rcode);
3805 else
3806 return (smctr_send_rsp(dev, rmf,
3807 rcode,
3808 correlator));
3809 }
3810
3811 if((err = smctr_send_tx_forward(dev, rmf,
3812 &tx_fstatus)) == HARDWARE_FAILED)
3813 {
3814 return (err);
3815 }
3816
3817 if(err == A_FRAME_WAS_FORWARDED)
3818 {
3819 if((err = smctr_send_rpt_tx_forward(dev,
3820 rmf, tx_fstatus))
3821 == HARDWARE_FAILED)
3822 {
3823 return (err);
3824 }
3825 }
3826 break;
Jeff Garzika6343af2007-07-17 05:39:58 -04003827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828
3829 /* Received MAC Frames Processed by CRS/REM/RPS. */
3830 case RSP:
3831 case RQ_INIT:
3832 case RPT_NEW_MON:
3833 case RPT_SUA_CHG:
3834 case RPT_ACTIVE_ERR:
3835 case RPT_NN_INCMP:
3836 case RPT_ERROR:
3837 case RPT_ATTCH:
3838 case RPT_STATE:
3839 case RPT_ADDR:
3840 break;
3841
3842 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3843 default:
3844 xframe = 0;
3845 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3846 {
3847 rcode = smctr_rcv_unknown(dev, rmf,
3848 &correlator);
3849 if((err = smctr_send_rsp(dev, rmf,rcode,
3850 correlator)))
3851 {
3852 return (err);
3853 }
3854 }
3855
3856 break;
3857 }
3858 }
3859 else
3860 {
3861 /* 1. DA doesn't match (Promiscuous Mode).
3862 * 2. Parse for Extended MAC Frame Type.
3863 */
3864 switch(rmf->vc)
3865 {
3866 case RSP:
3867 case INIT:
3868 case RQ_INIT:
3869 case RQ_ADDR:
3870 case RQ_ATTCH:
3871 case RQ_STATE:
3872 case CHG_PARM:
3873 case RPT_ADDR:
3874 case RPT_ERROR:
3875 case RPT_ATTCH:
3876 case RPT_STATE:
3877 case RPT_NEW_MON:
3878 case RPT_SUA_CHG:
3879 case RPT_NN_INCMP:
3880 case RPT_ACTIVE_ERR:
3881 break;
3882
3883 default:
3884 xframe = 0;
3885 break;
3886 }
3887 }
3888
3889 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3890 * ACCEPT_ATT_MAC_FRAMES is set.
3891 */
3892 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
3893 && (xframe == (__u8)0))
3894 || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES)
3895 && (xframe == (__u8)1)))
3896 {
3897 rmf->vl = SWAP_BYTES(rmf->vl);
3898
3899 if (!(skb = dev_alloc_skb(size)))
3900 return -ENOMEM;
3901 skb->len = size;
3902
3903 /* Slide data into a sleek skb. */
3904 skb_put(skb, skb->len);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03003905 skb_copy_to_linear_data(skb, rmf, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906
3907 /* Update Counters */
3908 tp->MacStat.rx_packets++;
3909 tp->MacStat.rx_bytes += skb->len;
3910
3911 /* Kick the packet on up. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 skb->protocol = tr_type_trans(skb, dev);
3913 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 err = 0;
3915 }
3916
3917 return (err);
3918}
3919
3920/* Adapter RAM test. Incremental word ODD boundary data test. */
3921static int smctr_ram_memory_test(struct net_device *dev)
3922{
3923 struct net_local *tp = netdev_priv(dev);
3924 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3925 word_read = 0, err_word = 0, err_pattern = 0;
3926 unsigned int err_offset;
3927 __u32 j, pword;
3928 __u8 err = 0;
3929
3930 if(smctr_debug > 10)
3931 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3932
3933 start_pattern = 0x0001;
3934 pages_of_ram = tp->ram_size / tp->ram_usable;
3935 pword = tp->ram_access;
3936
3937 /* Incremental word ODD boundary test. */
3938 for(page = 0; (page < pages_of_ram) && (~err);
3939 page++, start_pattern += 0x8000)
3940 {
3941 smctr_set_page(dev, (__u8 *)(tp->ram_access
3942 + (page * tp->ram_usable * 1024) + 1));
3943 word_pattern = start_pattern;
3944
3945 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3946 *(__u16 *)(pword + j) = word_pattern++;
3947
3948 word_pattern = start_pattern;
3949
3950 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1
3951 && (~err); j += 2, word_pattern++)
3952 {
3953 word_read = *(__u16 *)(pword + j);
3954 if(word_read != word_pattern)
3955 {
3956 err = (__u8)1;
3957 err_offset = j;
3958 err_word = word_read;
3959 err_pattern = word_pattern;
3960 return (RAM_TEST_FAILED);
3961 }
3962 }
3963 }
3964
3965 /* Zero out memory. */
3966 for(page = 0; page < pages_of_ram && (~err); page++)
3967 {
3968 smctr_set_page(dev, (__u8 *)(tp->ram_access
3969 + (page * tp->ram_usable * 1024)));
3970 word_pattern = 0;
3971
3972 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3973 *(__u16 *)(pword + j) = word_pattern;
3974
3975 for(j =0; j < (__u32)tp->ram_usable * 1024
3976 && (~err); j += 2)
3977 {
3978 word_read = *(__u16 *)(pword + j);
3979 if(word_read != word_pattern)
3980 {
3981 err = (__u8)1;
3982 err_offset = j;
3983 err_word = word_read;
3984 err_pattern = word_pattern;
3985 return (RAM_TEST_FAILED);
3986 }
3987 }
3988 }
3989
3990 smctr_set_page(dev, (__u8 *)tp->ram_access);
3991
3992 return (0);
3993}
3994
3995static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3996 __u16 *correlator)
3997{
3998 MAC_SUB_VECTOR *rsv;
3999 signed short vlen;
4000 __u16 rcode = POSITIVE_ACK;
4001 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4002
4003 /* This Frame can only come from a CRS */
4004 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4005 return(E_INAPPROPRIATE_SOURCE_CLASS);
4006
4007 /* Remove MVID Length from total length. */
4008 vlen = (signed short)rmf->vl - 4;
4009
4010 /* Point to First SVID */
4011 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4012
4013 /* Search for Appropriate SVID's. */
4014 while((vlen > 0) && (rcode == POSITIVE_ACK))
4015 {
4016 switch(rsv->svi)
4017 {
4018 case CORRELATOR:
4019 svectors |= F_CORRELATOR;
4020 rcode = smctr_set_corr(dev, rsv, correlator);
4021 break;
4022
4023 case LOCAL_RING_NUMBER:
4024 svectors |= F_LOCAL_RING_NUMBER;
4025 rcode = smctr_set_local_ring_num(dev, rsv);
4026 break;
4027
4028 case ASSIGN_PHYSICAL_DROP:
4029 svectors |= F_ASSIGN_PHYSICAL_DROP;
4030 rcode = smctr_set_phy_drop(dev, rsv);
4031 break;
4032
4033 case ERROR_TIMER_VALUE:
4034 svectors |= F_ERROR_TIMER_VALUE;
4035 rcode = smctr_set_error_timer_value(dev, rsv);
4036 break;
4037
4038 case AUTHORIZED_FUNCTION_CLASS:
4039 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4040 rcode = smctr_set_auth_funct_class(dev, rsv);
4041 break;
4042
4043 case AUTHORIZED_ACCESS_PRIORITY:
4044 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4045 rcode = smctr_set_auth_access_pri(dev, rsv);
4046 break;
4047
4048 default:
4049 rcode = E_SUB_VECTOR_UNKNOWN;
4050 break;
4051 }
4052
4053 /* Let Sender Know if SUM of SV length's is
4054 * larger then length in MVID length field
4055 */
4056 if((vlen -= rsv->svl) < 0)
4057 rcode = E_VECTOR_LENGTH_ERROR;
4058
4059 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4060 }
4061
4062 if(rcode == POSITIVE_ACK)
4063 {
4064 /* Let Sender Know if MVID length field
4065 * is larger then SUM of SV length's
4066 */
4067 if(vlen != 0)
4068 rcode = E_VECTOR_LENGTH_ERROR;
4069 else
4070 {
4071 /* Let Sender Know if Expected SVID Missing */
4072 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4073 rcode = E_MISSING_SUB_VECTOR;
4074 }
4075 }
4076
4077 return (rcode);
4078}
4079
4080static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4081 __u16 *correlator)
4082{
4083 MAC_SUB_VECTOR *rsv;
4084 signed short vlen;
4085 __u16 rcode = POSITIVE_ACK;
4086 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4087
4088 /* This Frame can only come from a RPS */
4089 if((rmf->dc_sc & SC_MASK) != SC_RPS)
4090 return (E_INAPPROPRIATE_SOURCE_CLASS);
4091
4092 /* Remove MVID Length from total length. */
4093 vlen = (signed short)rmf->vl - 4;
4094
4095 /* Point to First SVID */
4096 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4097
4098 /* Search for Appropriate SVID's */
4099 while((vlen > 0) && (rcode == POSITIVE_ACK))
4100 {
4101 switch(rsv->svi)
4102 {
4103 case CORRELATOR:
4104 svectors |= F_CORRELATOR;
4105 rcode = smctr_set_corr(dev, rsv, correlator);
4106 break;
4107
4108 case LOCAL_RING_NUMBER:
4109 svectors |= F_LOCAL_RING_NUMBER;
4110 rcode = smctr_set_local_ring_num(dev, rsv);
4111 break;
4112
4113 case ASSIGN_PHYSICAL_DROP:
4114 svectors |= F_ASSIGN_PHYSICAL_DROP;
4115 rcode = smctr_set_phy_drop(dev, rsv);
4116 break;
4117
4118 case ERROR_TIMER_VALUE:
4119 svectors |= F_ERROR_TIMER_VALUE;
4120 rcode = smctr_set_error_timer_value(dev, rsv);
4121 break;
4122
4123 default:
4124 rcode = E_SUB_VECTOR_UNKNOWN;
4125 break;
4126 }
4127
4128 /* Let Sender Know if SUM of SV length's is
4129 * larger then length in MVID length field
4130 */
4131 if((vlen -= rsv->svl) < 0)
4132 rcode = E_VECTOR_LENGTH_ERROR;
4133
4134 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4135 }
4136
4137 if(rcode == POSITIVE_ACK)
4138 {
4139 /* Let Sender Know if MVID length field
4140 * is larger then SUM of SV length's
4141 */
4142 if(vlen != 0)
4143 rcode = E_VECTOR_LENGTH_ERROR;
4144 else
4145 {
4146 /* Let Sender Know if Expected SV Missing */
4147 if((svectors & R_INIT) ^ R_INIT)
4148 rcode = E_MISSING_SUB_VECTOR;
4149 }
4150 }
4151
4152 return (rcode);
4153}
4154
4155static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4156{
4157 MAC_SUB_VECTOR *rsv;
4158 signed short vlen;
4159 __u16 rcode = POSITIVE_ACK;
4160 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4161
4162 /* This Frame can only come from a CRS */
4163 if((rmf->dc_sc & SC_MASK) != SC_CRS)
4164 return (E_INAPPROPRIATE_SOURCE_CLASS);
4165
4166 /* Remove MVID Length from total length */
4167 vlen = (signed short)rmf->vl - 4;
4168
4169 /* Point to First SVID */
4170 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4171
4172 /* Search for Appropriate SVID's */
4173 while((vlen > 0) && (rcode == POSITIVE_ACK))
4174 {
4175 switch(rsv->svi)
4176 {
4177 case FRAME_FORWARD:
4178 svectors |= F_FRAME_FORWARD;
4179 rcode = smctr_set_frame_forward(dev, rsv,
4180 rmf->dc_sc);
4181 break;
4182
4183 default:
4184 rcode = E_SUB_VECTOR_UNKNOWN;
4185 break;
4186 }
4187
4188 /* Let Sender Know if SUM of SV length's is
4189 * larger then length in MVID length field
4190 */
4191 if((vlen -= rsv->svl) < 0)
4192 rcode = E_VECTOR_LENGTH_ERROR;
4193
4194 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4195 }
4196
4197 if(rcode == POSITIVE_ACK)
4198 {
4199 /* Let Sender Know if MVID length field
4200 * is larger then SUM of SV length's
4201 */
4202 if(vlen != 0)
4203 rcode = E_VECTOR_LENGTH_ERROR;
4204 else
4205 {
4206 /* Let Sender Know if Expected SV Missing */
4207 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4208 rcode = E_MISSING_SUB_VECTOR;
4209 }
4210 }
4211
4212 return (rcode);
4213}
4214
4215static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4216 MAC_HEADER *rmf, __u16 *correlator)
4217{
4218 MAC_SUB_VECTOR *rsv;
4219 signed short vlen;
4220 __u16 rcode = POSITIVE_ACK;
4221 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4222
4223 /* Remove MVID Length from total length */
4224 vlen = (signed short)rmf->vl - 4;
4225
4226 /* Point to First SVID */
4227 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4228
4229 /* Search for Appropriate SVID's */
4230 while((vlen > 0) && (rcode == POSITIVE_ACK))
4231 {
4232 switch(rsv->svi)
4233 {
4234 case CORRELATOR:
4235 svectors |= F_CORRELATOR;
4236 rcode = smctr_set_corr(dev, rsv, correlator);
4237 break;
4238
4239 default:
4240 rcode = E_SUB_VECTOR_UNKNOWN;
4241 break;
4242 }
4243
4244 /* Let Sender Know if SUM of SV length's is
4245 * larger then length in MVID length field
4246 */
4247 if((vlen -= rsv->svl) < 0)
4248 rcode = E_VECTOR_LENGTH_ERROR;
4249
4250 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4251 }
4252
4253 if(rcode == POSITIVE_ACK)
4254 {
4255 /* Let Sender Know if MVID length field
4256 * is larger then SUM of SV length's
4257 */
4258 if(vlen != 0)
4259 rcode = E_VECTOR_LENGTH_ERROR;
4260 else
4261 {
4262 /* Let Sender Know if Expected SVID Missing */
4263 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4264 ^ R_RQ_ATTCH_STATE_ADDR)
4265 rcode = E_MISSING_SUB_VECTOR;
4266 }
4267 }
4268
4269 return (rcode);
4270}
4271
4272static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4273 __u16 *correlator)
4274{
4275 MAC_SUB_VECTOR *rsv;
4276 signed short vlen;
4277
4278 *correlator = 0;
4279
4280 /* Remove MVID Length from total length */
4281 vlen = (signed short)rmf->vl - 4;
4282
4283 /* Point to First SVID */
4284 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4285
4286 /* Search for CORRELATOR for RSP to UNKNOWN */
4287 while((vlen > 0) && (*correlator == 0))
4288 {
4289 switch(rsv->svi)
4290 {
4291 case CORRELATOR:
4292 smctr_set_corr(dev, rsv, correlator);
4293 break;
4294
4295 default:
4296 break;
4297 }
4298
4299 vlen -= rsv->svl;
4300 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4301 }
4302
4303 return (E_UNRECOGNIZED_VECTOR_ID);
4304}
4305
4306/*
4307 * Reset the 825 NIC and exit w:
4308 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4309 * 2. TINT masked.
4310 * 3. CBUSY masked.
4311 * 4. TINT clear.
4312 * 5. CBUSY clear.
4313 */
4314static int smctr_reset_adapter(struct net_device *dev)
4315{
4316 struct net_local *tp = netdev_priv(dev);
4317 int ioaddr = dev->base_addr;
4318
4319 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4320 mdelay(200); /* ~2 ms */
4321
4322 smctr_clear_trc_reset(ioaddr);
4323 mdelay(200); /* ~2 ms */
4324
4325 /* Remove any latched interrupts that occurred prior to reseting the
4326 * adapter or possibily caused by line glitches due to the reset.
4327 */
4328 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4329
4330 return (0);
4331}
4332
4333static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4334{
4335 struct net_local *tp = netdev_priv(dev);
4336 int err = 0;
4337
4338 if(smctr_debug > 10)
4339 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4340
4341 if(tp->num_tx_fcbs_used[queue] != 0
4342 && tp->tx_queue_status[queue] == NOT_TRANSMITING)
4343 {
4344 tp->tx_queue_status[queue] = TRANSMITING;
4345 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4346 }
4347
4348 return (err);
4349}
4350
4351static int smctr_ring_status_chg(struct net_device *dev)
4352{
4353 struct net_local *tp = netdev_priv(dev);
4354
4355 if(smctr_debug > 10)
4356 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4357
4358 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4359 * Bit is set, check value of monitor_state, only then we
4360 * enable and start transmit/receive timeout (if and only
4361 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4362 */
4363 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4364 {
4365 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE)
4366 || (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
4367 {
4368 tp->monitor_state_ready = 1;
4369 }
4370 else
4371 {
4372 /* if adapter is NOT in either active monitor
4373 * or standby monitor state => Disable
4374 * transmit/receive timeout.
4375 */
4376 tp->monitor_state_ready = 0;
4377
4378 /* Ring speed problem, switching to auto mode. */
4379 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE
4380 && !tp->cleanup)
4381 {
4382 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4383 dev->name);
4384 smctr_set_ring_speed(dev);
4385 }
4386 }
4387 }
4388
4389 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
4390 return (0);
4391
4392 switch(tp->ring_status)
4393 {
4394 case RING_RECOVERY:
4395 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396 break;
4397
4398 case SINGLE_STATION:
4399 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400 break;
4401
4402 case COUNTER_OVERFLOW:
4403 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 break;
4405
4406 case REMOVE_RECEIVED:
4407 printk(KERN_INFO "%s: Remove Received\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 break;
4409
4410 case AUTO_REMOVAL_ERROR:
4411 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 break;
4413
4414 case LOBE_WIRE_FAULT:
4415 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004416 break;
4417
4418 case TRANSMIT_BEACON:
4419 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 break;
4421
4422 case SOFT_ERROR:
4423 printk(KERN_INFO "%s: Soft Error\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 break;
4425
4426 case HARD_ERROR:
4427 printk(KERN_INFO "%s: Hard Error\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 break;
4429
4430 case SIGNAL_LOSS:
4431 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004432 break;
4433
4434 default:
4435 printk(KERN_INFO "%s: Unknown ring status change\n",
4436 dev->name);
4437 break;
4438 }
4439
4440 return (0);
4441}
4442
4443static int smctr_rx_frame(struct net_device *dev)
4444{
4445 struct net_local *tp = netdev_priv(dev);
4446 __u16 queue, status, rx_size, err = 0;
4447 __u8 *pbuff;
4448
4449 if(smctr_debug > 10)
4450 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4451
4452 queue = tp->receive_queue_number;
4453
4454 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4455 {
4456 err = HARDWARE_FAILED;
4457
4458 if(((status & 0x007f) == 0)
4459 || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
4460 {
4461 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4462 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4463
4464 pbuff = smctr_get_rx_pointer(dev, queue);
4465
4466 smctr_set_page(dev, pbuff);
4467 smctr_disable_16bit(dev);
4468
4469 /* pbuff points to addr within one page */
4470 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4471
4472 if(queue == NON_MAC_QUEUE)
4473 {
4474 struct sk_buff *skb;
4475
4476 skb = dev_alloc_skb(rx_size);
4477 if (skb) {
4478 skb_put(skb, rx_size);
4479
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004480 skb_copy_to_linear_data(skb, pbuff, rx_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004481
4482 /* Update Counters */
4483 tp->MacStat.rx_packets++;
4484 tp->MacStat.rx_bytes += skb->len;
4485
4486 /* Kick the packet on up. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 skb->protocol = tr_type_trans(skb, dev);
4488 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 } else {
4490 }
4491 }
4492 else
4493 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4494 rx_size, dev, status);
4495 }
4496
4497 smctr_enable_16bit(dev);
4498 smctr_set_page(dev, (__u8 *)tp->ram_access);
4499 smctr_update_rx_chain(dev, queue);
4500
4501 if(err != SUCCESS)
4502 break;
4503 }
4504
4505 return (err);
4506}
4507
4508static int smctr_send_dat(struct net_device *dev)
4509{
4510 struct net_local *tp = netdev_priv(dev);
4511 unsigned int i, err;
4512 MAC_HEADER *tmf;
4513 FCBlock *fcb;
4514
4515 if(smctr_debug > 10)
4516 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4517
4518 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4519 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4520 {
4521 return (OUT_OF_RESOURCES);
4522 }
4523
4524 /* Initialize DAT Data Fields. */
4525 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4526 tmf->ac = MSB(AC_FC_DAT);
4527 tmf->fc = LSB(AC_FC_DAT);
4528
4529 for(i = 0; i < 6; i++)
4530 {
4531 tmf->sa[i] = dev->dev_addr[i];
4532 tmf->da[i] = dev->dev_addr[i];
4533
4534 }
4535
4536 tmf->vc = DAT;
4537 tmf->dc_sc = DC_RS | SC_RS;
4538 tmf->vl = 4;
4539 tmf->vl = SWAP_BYTES(tmf->vl);
4540
4541 /* Start Transmit. */
4542 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4543 return (err);
4544
4545 /* Wait for Transmit to Complete */
4546 for(i = 0; i < 10000; i++)
4547 {
4548 if(fcb->frame_status & FCB_COMMAND_DONE)
4549 break;
4550 mdelay(1);
4551 }
4552
4553 /* Check if GOOD frame Tx'ed. */
4554 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4555 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4556 {
4557 return (INITIALIZE_FAILED);
4558 }
4559
4560 /* De-allocated Tx FCB and Frame Buffer
4561 * The FCB must be de-allocated manually if executing with
4562 * interrupts disabled, other wise the ISR (LM_Service_Events)
4563 * will de-allocate it when the interrupt occurs.
4564 */
4565 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4566 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4567
4568 return (0);
4569}
4570
4571static void smctr_timeout(struct net_device *dev)
4572{
4573 /*
4574 * If we get here, some higher level has decided we are broken.
4575 * There should really be a "kick me" function call instead.
4576 *
4577 * Resetting the token ring adapter takes a long time so just
4578 * fake transmission time and go on trying. Our own timeout
4579 * routine is in sktr_timer_chk()
4580 */
4581 dev->trans_start = jiffies;
4582 netif_wake_queue(dev);
4583}
4584
4585/*
4586 * Gets skb from system, queues it and checks if it can be sent
4587 */
4588static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
4589{
4590 struct net_local *tp = netdev_priv(dev);
4591
4592 if(smctr_debug > 10)
4593 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4594
4595 /*
4596 * Block a transmit overlap
4597 */
4598
4599 netif_stop_queue(dev);
4600
4601 if(tp->QueueSkb == 0)
4602 return (1); /* Return with tbusy set: queue full */
4603
4604 tp->QueueSkb--;
4605 skb_queue_tail(&tp->SendSkbQueue, skb);
4606 smctr_hardware_send_packet(dev, tp);
4607 if(tp->QueueSkb > 0)
4608 netif_wake_queue(dev);
4609
4610 return (0);
4611}
4612
4613static int smctr_send_lobe_media_test(struct net_device *dev)
4614{
4615 struct net_local *tp = netdev_priv(dev);
4616 MAC_SUB_VECTOR *tsv;
4617 MAC_HEADER *tmf;
4618 FCBlock *fcb;
4619 __u32 i;
4620 int err;
4621
4622 if(smctr_debug > 15)
4623 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4624
4625 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4626 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4627 {
4628 return (OUT_OF_RESOURCES);
4629 }
4630
4631 /* Initialize DAT Data Fields. */
4632 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4633 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4634 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4635
4636 for(i = 0; i < 6; i++)
4637 {
4638 tmf->da[i] = 0;
4639 tmf->sa[i] = dev->dev_addr[i];
4640 }
4641
4642 tmf->vc = LOBE_MEDIA_TEST;
4643 tmf->dc_sc = DC_RS | SC_RS;
4644 tmf->vl = 4;
4645
4646 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4647 smctr_make_wrap_data(dev, tsv);
4648 tmf->vl += tsv->svl;
4649
4650 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4651 smctr_make_wrap_data(dev, tsv);
4652 tmf->vl += tsv->svl;
4653
4654 /* Start Transmit. */
4655 tmf->vl = SWAP_BYTES(tmf->vl);
4656 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4657 return (err);
4658
4659 /* Wait for Transmit to Complete. (10 ms). */
4660 for(i=0; i < 10000; i++)
4661 {
4662 if(fcb->frame_status & FCB_COMMAND_DONE)
4663 break;
4664 mdelay(1);
4665 }
4666
4667 /* Check if GOOD frame Tx'ed */
4668 if(!(fcb->frame_status & FCB_COMMAND_DONE)
4669 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
4670 {
4671 return (LOBE_MEDIA_TEST_FAILED);
4672 }
4673
4674 /* De-allocated Tx FCB and Frame Buffer
4675 * The FCB must be de-allocated manually if executing with
4676 * interrupts disabled, other wise the ISR (LM_Service_Events)
4677 * will de-allocate it when the interrupt occurs.
4678 */
4679 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4680 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4681
4682 return (0);
4683}
4684
4685static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4686 __u16 correlator)
4687{
4688 MAC_HEADER *tmf;
4689 MAC_SUB_VECTOR *tsv;
4690 FCBlock *fcb;
4691
4692 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4693 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4694 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4695 == (FCBlock *)(-1L))
4696 {
4697 return (0);
4698 }
4699
4700 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4701 tmf->vc = RPT_ADDR;
4702 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4703 tmf->vl = 4;
4704
4705 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4706
4707 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4708 smctr_make_corr(dev, tsv, correlator);
4709
4710 tmf->vl += tsv->svl;
4711 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4712 smctr_make_phy_drop_num(dev, tsv);
4713
4714 tmf->vl += tsv->svl;
4715 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4716 smctr_make_upstream_neighbor_addr(dev, tsv);
4717
4718 tmf->vl += tsv->svl;
4719 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4720 smctr_make_addr_mod(dev, tsv);
4721
4722 tmf->vl += tsv->svl;
4723 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4724 smctr_make_group_addr(dev, tsv);
4725
4726 tmf->vl += tsv->svl;
4727 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4728 smctr_make_funct_addr(dev, tsv);
4729
4730 tmf->vl += tsv->svl;
4731
4732 /* Subtract out MVID and MVL which is
4733 * include in both vl and MAC_HEADER
4734 */
4735/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4736 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4737*/
4738 tmf->vl = SWAP_BYTES(tmf->vl);
4739
4740 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4741}
4742
4743static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4744 __u16 correlator)
4745{
4746 MAC_HEADER *tmf;
4747 MAC_SUB_VECTOR *tsv;
4748 FCBlock *fcb;
4749
4750 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4751 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4752 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4753 == (FCBlock *)(-1L))
4754 {
4755 return (0);
4756 }
4757
4758 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4759 tmf->vc = RPT_ATTCH;
4760 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4761 tmf->vl = 4;
4762
4763 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4764
4765 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4766 smctr_make_corr(dev, tsv, correlator);
4767
4768 tmf->vl += tsv->svl;
4769 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4770 smctr_make_product_id(dev, tsv);
4771
4772 tmf->vl += tsv->svl;
4773 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4774 smctr_make_funct_addr(dev, tsv);
4775
4776 tmf->vl += tsv->svl;
4777 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4778 smctr_make_auth_funct_class(dev, tsv);
4779
4780 tmf->vl += tsv->svl;
4781 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4782 smctr_make_access_pri(dev, tsv);
4783
4784 tmf->vl += tsv->svl;
4785
4786 /* Subtract out MVID and MVL which is
4787 * include in both vl and MAC_HEADER
4788 */
4789/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4790 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4791*/
4792 tmf->vl = SWAP_BYTES(tmf->vl);
4793
4794 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4795}
4796
4797static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4798 __u16 correlator)
4799{
4800 MAC_HEADER *tmf;
4801 MAC_SUB_VECTOR *tsv;
4802 FCBlock *fcb;
4803
4804 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4805 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4806 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4807 == (FCBlock *)(-1L))
4808 {
4809 return (0);
4810 }
4811
4812 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4813 tmf->vc = RPT_STATE;
4814 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4815 tmf->vl = 4;
4816
4817 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4818
4819 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4820 smctr_make_corr(dev, tsv, correlator);
4821
4822 tmf->vl += tsv->svl;
4823 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4824 smctr_make_ring_station_version(dev, tsv);
4825
4826 tmf->vl += tsv->svl;
4827 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4828 smctr_make_ring_station_status(dev, tsv);
4829
4830 tmf->vl += tsv->svl;
4831 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4832 smctr_make_station_id(dev, tsv);
4833
4834 tmf->vl += tsv->svl;
4835
4836 /* Subtract out MVID and MVL which is
4837 * include in both vl and MAC_HEADER
4838 */
4839/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4840 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4841*/
4842 tmf->vl = SWAP_BYTES(tmf->vl);
4843
4844 return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4845}
4846
4847static int smctr_send_rpt_tx_forward(struct net_device *dev,
4848 MAC_HEADER *rmf, __u16 tx_fstatus)
4849{
4850 MAC_HEADER *tmf;
4851 MAC_SUB_VECTOR *tsv;
4852 FCBlock *fcb;
4853
4854 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4855 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4856 {
4857 return (0);
4858 }
4859
4860 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4861 tmf->vc = RPT_TX_FORWARD;
4862 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4863 tmf->vl = 4;
4864
4865 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4866
4867 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4868 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4869
4870 tmf->vl += tsv->svl;
4871
4872 /* Subtract out MVID and MVL which is
4873 * include in both vl and MAC_HEADER
4874 */
4875/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4876 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4877*/
4878 tmf->vl = SWAP_BYTES(tmf->vl);
4879
4880 return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
4881}
4882
4883static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4884 __u16 rcode, __u16 correlator)
4885{
4886 MAC_HEADER *tmf;
4887 MAC_SUB_VECTOR *tsv;
4888 FCBlock *fcb;
4889
4890 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4891 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4892 {
4893 return (0);
4894 }
4895
4896 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4897 tmf->vc = RSP;
4898 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4899 tmf->vl = 4;
4900
4901 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4902
4903 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4904 smctr_make_corr(dev, tsv, correlator);
4905
4906 return (0);
4907}
4908
4909static int smctr_send_rq_init(struct net_device *dev)
4910{
4911 struct net_local *tp = netdev_priv(dev);
4912 MAC_HEADER *tmf;
4913 MAC_SUB_VECTOR *tsv;
4914 FCBlock *fcb;
4915 unsigned int i, count = 0;
4916 __u16 fstatus;
4917 int err;
4918
4919 do {
4920 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4921 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4922 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4923 == (FCBlock *)(-1L)))
4924 {
4925 return (0);
4926 }
4927
4928 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4929 tmf->vc = RQ_INIT;
4930 tmf->dc_sc = DC_RPS | SC_RS;
4931 tmf->vl = 4;
4932
4933 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4934
4935 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4936 smctr_make_product_id(dev, tsv);
4937
4938 tmf->vl += tsv->svl;
4939 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4940 smctr_make_upstream_neighbor_addr(dev, tsv);
4941
4942 tmf->vl += tsv->svl;
4943 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4944 smctr_make_ring_station_version(dev, tsv);
4945
4946 tmf->vl += tsv->svl;
4947 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4948 smctr_make_addr_mod(dev, tsv);
4949
4950 tmf->vl += tsv->svl;
4951
4952 /* Subtract out MVID and MVL which is
4953 * include in both vl and MAC_HEADER
4954 */
4955/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4956 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4957*/
4958 tmf->vl = SWAP_BYTES(tmf->vl);
4959
4960 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
4961 return (err);
4962
4963 /* Wait for Transmit to Complete */
4964 for(i = 0; i < 10000; i++)
4965 {
4966 if(fcb->frame_status & FCB_COMMAND_DONE)
4967 break;
4968 mdelay(1);
4969 }
4970
4971 /* Check if GOOD frame Tx'ed */
4972 fstatus = fcb->frame_status;
4973
4974 if(!(fstatus & FCB_COMMAND_DONE))
4975 return (HARDWARE_FAILED);
4976
4977 if(!(fstatus & FCB_TX_STATUS_E))
4978 count++;
4979
4980 /* De-allocated Tx FCB and Frame Buffer
4981 * The FCB must be de-allocated manually if executing with
4982 * interrupts disabled, other wise the ISR (LM_Service_Events)
4983 * will de-allocate it when the interrupt occurs.
4984 */
4985 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4986 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4987 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4988
4989 return (smctr_join_complete_state(dev));
4990}
4991
4992static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4993 __u16 *tx_fstatus)
4994{
4995 struct net_local *tp = netdev_priv(dev);
4996 FCBlock *fcb;
4997 unsigned int i;
4998 int err;
4999
5000 /* Check if this is the END POINT of the Transmit Forward Chain. */
5001 if(rmf->vl <= 18)
5002 return (0);
5003
5004 /* Allocate Transmit FCB only by requesting 0 bytes
5005 * of data buffer.
5006 */
5007 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
5008 return (0);
5009
5010 /* Set pointer to Transmit Frame Buffer to the data
5011 * portion of the received TX Forward frame, making
5012 * sure to skip over the Vector Code (vc) and Vector
5013 * length (vl).
5014 */
5015 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5016 + sizeof(MAC_HEADER) + 2);
5017 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5018 + sizeof(MAC_HEADER) + 2);
5019
5020 fcb->frame_length = rmf->vl - 4 - 2;
5021 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5022
5023 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
5024 return (err);
5025
5026 /* Wait for Transmit to Complete */
5027 for(i = 0; i < 10000; i++)
5028 {
5029 if(fcb->frame_status & FCB_COMMAND_DONE)
5030 break;
5031 mdelay(1);
5032 }
5033
5034 /* Check if GOOD frame Tx'ed */
5035 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5036 {
5037 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
5038 return (err);
5039
5040 for(i = 0; i < 10000; i++)
5041 {
5042 if(fcb->frame_status & FCB_COMMAND_DONE)
5043 break;
5044 mdelay(1);
5045 }
5046
5047 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5048 return (HARDWARE_FAILED);
5049 }
5050
5051 *tx_fstatus = fcb->frame_status;
5052
5053 return (A_FRAME_WAS_FORWARDED);
5054}
5055
5056static int smctr_set_auth_access_pri(struct net_device *dev,
5057 MAC_SUB_VECTOR *rsv)
5058{
5059 struct net_local *tp = netdev_priv(dev);
5060
5061 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
5062 return (E_SUB_VECTOR_LENGTH_ERROR);
5063
5064 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5065
5066 return (POSITIVE_ACK);
5067}
5068
5069static int smctr_set_auth_funct_class(struct net_device *dev,
5070 MAC_SUB_VECTOR *rsv)
5071{
5072 struct net_local *tp = netdev_priv(dev);
5073
5074 if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
5075 return (E_SUB_VECTOR_LENGTH_ERROR);
5076
5077 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5078
5079 return (POSITIVE_ACK);
5080}
5081
5082static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5083 __u16 *correlator)
5084{
5085 if(rsv->svl != S_CORRELATOR)
5086 return (E_SUB_VECTOR_LENGTH_ERROR);
5087
5088 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5089
5090 return (POSITIVE_ACK);
5091}
5092
5093static int smctr_set_error_timer_value(struct net_device *dev,
5094 MAC_SUB_VECTOR *rsv)
5095{
5096 __u16 err_tval;
5097 int err;
5098
5099 if(rsv->svl != S_ERROR_TIMER_VALUE)
5100 return (E_SUB_VECTOR_LENGTH_ERROR);
5101
5102 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5103
5104 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5105
5106 if((err = smctr_wait_cmd(dev)))
5107 return (err);
5108
5109 return (POSITIVE_ACK);
5110}
5111
5112static int smctr_set_frame_forward(struct net_device *dev,
5113 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5114{
5115 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
5116 return (E_SUB_VECTOR_LENGTH_ERROR);
5117
5118 if((dc_sc & DC_MASK) != DC_CRS)
5119 {
5120 if(rsv->svl >= 2 && rsv->svl < 20)
5121 return (E_TRANSMIT_FORWARD_INVALID);
5122
5123 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
5124 return (E_TRANSMIT_FORWARD_INVALID);
5125 }
5126
5127 return (POSITIVE_ACK);
5128}
5129
5130static int smctr_set_local_ring_num(struct net_device *dev,
5131 MAC_SUB_VECTOR *rsv)
5132{
5133 struct net_local *tp = netdev_priv(dev);
5134
5135 if(rsv->svl != S_LOCAL_RING_NUMBER)
5136 return (E_SUB_VECTOR_LENGTH_ERROR);
5137
5138 if(tp->ptr_local_ring_num)
5139 *(__u16 *)(tp->ptr_local_ring_num)
5140 = (rsv->svv[0] << 8 | rsv->svv[1]);
5141
5142 return (POSITIVE_ACK);
5143}
5144
5145static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5146{
5147 struct net_local *tp = netdev_priv(dev);
5148 int ioaddr = dev->base_addr;
5149
5150 if(tp->bic_type == BIC_585_CHIP)
5151 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5152 else
5153 {
5154 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5155 outb(tp->trc_mask, ioaddr + CSR);
5156 }
5157
5158 return (0);
5159}
5160
5161static void smctr_set_multicast_list(struct net_device *dev)
5162{
5163 if(smctr_debug > 10)
5164 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
5165
5166 return;
5167}
5168
5169static int smctr_set_page(struct net_device *dev, __u8 *buf)
5170{
5171 struct net_local *tp = netdev_priv(dev);
5172 __u8 amask;
5173 __u32 tptr;
5174
5175 tptr = (__u32)buf - (__u32)tp->ram_access;
5176 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5177 outb(amask, dev->base_addr + PR);
5178
5179 return (0);
5180}
5181
5182static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5183{
5184 int err;
5185
5186 if(rsv->svl != S_PHYSICAL_DROP)
5187 return (E_SUB_VECTOR_LENGTH_ERROR);
5188
5189 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5190 if((err = smctr_wait_cmd(dev)))
5191 return (err);
5192
5193 return (POSITIVE_ACK);
5194}
5195
5196/* Reset the ring speed to the opposite of what it was. This auto-pilot
5197 * mode requires a complete reset and re-init of the adapter.
5198 */
5199static int smctr_set_ring_speed(struct net_device *dev)
5200{
5201 struct net_local *tp = netdev_priv(dev);
5202 int err;
5203
5204 if(tp->media_type == MEDIA_UTP_16)
5205 tp->media_type = MEDIA_UTP_4;
5206 else
5207 tp->media_type = MEDIA_UTP_16;
5208
5209 smctr_enable_16bit(dev);
5210
5211 /* Re-Initialize adapter's internal registers */
5212 smctr_reset_adapter(dev);
5213
5214 if((err = smctr_init_card_real(dev)))
5215 return (err);
5216
5217 smctr_enable_bic_int(dev);
5218
5219 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
5220 return (err);
5221
5222 smctr_disable_16bit(dev);
5223
5224 return (0);
5225}
5226
5227static int smctr_set_rx_look_ahead(struct net_device *dev)
5228{
5229 struct net_local *tp = netdev_priv(dev);
5230 __u16 sword, rword;
5231
5232 if(smctr_debug > 10)
5233 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5234
5235 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5236 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5237
5238 if(tp->adapter_bus == BUS_ISA16_TYPE)
5239 {
5240 sword = *((__u16 *)(tp->ram_access));
5241 *((__u16 *)(tp->ram_access)) = 0x1234;
5242
5243 smctr_disable_16bit(dev);
5244 rword = *((__u16 *)(tp->ram_access));
5245 smctr_enable_16bit(dev);
5246
5247 if(rword != 0x1234)
5248 tp->adapter_flags |= FORCED_16BIT_MODE;
5249
5250 *((__u16 *)(tp->ram_access)) = sword;
5251 }
5252
5253 return (0);
5254}
5255
5256static int smctr_set_trc_reset(int ioaddr)
5257{
5258 __u8 r;
5259
5260 r = inb(ioaddr + MSR);
5261 outb(MSR_RST | r, ioaddr + MSR);
5262
5263 return (0);
5264}
5265
5266/*
5267 * This function can be called if the adapter is busy or not.
5268 */
5269static int smctr_setup_single_cmd(struct net_device *dev,
5270 __u16 command, __u16 subcommand)
5271{
5272 struct net_local *tp = netdev_priv(dev);
5273 unsigned int err;
5274
5275 if(smctr_debug > 10)
5276 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5277
5278 if((err = smctr_wait_while_cbusy(dev)))
5279 return (err);
5280
5281 if((err = (unsigned int)smctr_wait_cmd(dev)))
5282 return (err);
5283
5284 tp->acb_head->cmd_done_status = 0;
5285 tp->acb_head->cmd = command;
5286 tp->acb_head->subcmd = subcommand;
5287
5288 err = smctr_issue_resume_acb_cmd(dev);
5289
5290 return (err);
5291}
5292
5293/*
5294 * This function can not be called with the adapter busy.
5295 */
5296static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5297 __u16 command, __u16 subcommand)
5298{
5299 struct net_local *tp = netdev_priv(dev);
5300
5301 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5302 tp->acb_head->cmd = command;
5303 tp->acb_head->subcmd = subcommand;
5304 tp->acb_head->data_offset_lo
5305 = (__u16)TRC_POINTER(tp->misc_command_data);
5306
5307 return(smctr_issue_resume_acb_cmd(dev));
5308}
5309
5310static char *smctr_malloc(struct net_device *dev, __u16 size)
5311{
5312 struct net_local *tp = netdev_priv(dev);
5313 char *m;
5314
5315 m = (char *)(tp->ram_access + tp->sh_mem_used);
5316 tp->sh_mem_used += (__u32)size;
5317
5318 return (m);
5319}
5320
5321static int smctr_status_chg(struct net_device *dev)
5322{
5323 struct net_local *tp = netdev_priv(dev);
5324
5325 if(smctr_debug > 10)
5326 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5327
5328 switch(tp->status)
5329 {
5330 case OPEN:
5331 break;
5332
5333 case CLOSED:
5334 break;
5335
5336 /* Interrupt driven open() completion. XXX */
5337 case INITIALIZED:
5338 tp->group_address_0 = 0;
5339 tp->group_address[0] = 0;
5340 tp->group_address[1] = 0;
5341 tp->functional_address_0 = 0;
5342 tp->functional_address[0] = 0;
5343 tp->functional_address[1] = 0;
5344 smctr_open_tr(dev);
5345 break;
5346
5347 default:
5348 printk(KERN_INFO "%s: status change unknown %x\n",
5349 dev->name, tp->status);
5350 break;
5351 }
5352
5353 return (0);
5354}
5355
5356static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5357 __u16 queue)
5358{
5359 struct net_local *tp = netdev_priv(dev);
5360 int err = 0;
5361
5362 if(smctr_debug > 10)
5363 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5364
5365 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5366 if(tp->num_tx_fcbs[queue] != 1)
5367 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5368
5369 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5370 {
5371 tp->tx_queue_status[queue] = TRANSMITING;
5372 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5373 }
5374
5375 return (err);
5376}
5377
5378static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5379{
5380 struct net_local *tp = netdev_priv(dev);
5381 __u16 status, err = 0;
5382 int cstatus;
5383
5384 if(smctr_debug > 10)
5385 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5386
5387 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5388 {
5389 if(status & 0x7e00 )
5390 {
5391 err = HARDWARE_FAILED;
5392 break;
5393 }
5394
5395 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5396 queue)) != SUCCESS)
5397 break;
5398
5399 smctr_disable_16bit(dev);
5400
5401 if(tp->mode_bits & UMAC)
5402 {
5403 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5404 cstatus = NO_SUCH_DESTINATION;
5405 else
5406 {
5407 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5408 cstatus = DEST_OUT_OF_RESOURCES;
5409 else
5410 {
5411 if(status & FCB_TX_STATUS_E)
5412 cstatus = MAX_COLLISIONS;
5413 else
5414 cstatus = SUCCESS;
5415 }
5416 }
5417 }
5418 else
5419 cstatus = SUCCESS;
5420
5421 if(queue == BUG_QUEUE)
5422 err = SUCCESS;
5423
5424 smctr_enable_16bit(dev);
5425 if(err != SUCCESS)
5426 break;
5427 }
5428
5429 return (err);
5430}
5431
5432static unsigned short smctr_tx_move_frame(struct net_device *dev,
5433 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5434{
5435 struct net_local *tp = netdev_priv(dev);
5436 unsigned int ram_usable;
5437 __u32 flen, len, offset = 0;
5438 __u8 *frag, *page;
5439
5440 if(smctr_debug > 10)
5441 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5442
5443 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5444 frag = skb->data;
5445 flen = skb->len;
5446
5447 while(flen > 0 && bytes > 0)
5448 {
5449 smctr_set_page(dev, pbuff);
5450
5451 offset = SMC_PAGE_OFFSET(pbuff);
5452
5453 if(offset + flen > ram_usable)
5454 len = ram_usable - offset;
5455 else
5456 len = flen;
5457
5458 if(len > bytes)
5459 len = bytes;
5460
5461 page = (char *) (offset + tp->ram_access);
5462 memcpy(page, frag, len);
5463
5464 flen -=len;
5465 bytes -= len;
5466 frag += len;
5467 pbuff += len;
5468 }
5469
5470 return (0);
5471}
5472
5473/* Update the error statistic counters for this adapter. */
5474static int smctr_update_err_stats(struct net_device *dev)
5475{
5476 struct net_local *tp = netdev_priv(dev);
5477 struct tr_statistics *tstat = &tp->MacStat;
5478
5479 if(tstat->internal_errors)
5480 tstat->internal_errors
5481 += *(tp->misc_command_data + 0) & 0x00ff;
5482
5483 if(tstat->line_errors)
5484 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5485
5486 if(tstat->A_C_errors)
5487 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5488
5489 if(tstat->burst_errors)
5490 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5491
5492 if(tstat->abort_delimiters)
5493 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5494
5495 if(tstat->recv_congest_count)
5496 tstat->recv_congest_count
5497 += *(tp->misc_command_data + 3) & 0x00ff;
5498
5499 if(tstat->lost_frames)
5500 tstat->lost_frames
5501 += *(tp->misc_command_data + 3) >> 8;
5502
5503 if(tstat->frequency_errors)
5504 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5505
5506 if(tstat->frame_copied_errors)
5507 tstat->frame_copied_errors
5508 += *(tp->misc_command_data + 4) >> 8;
5509
5510 if(tstat->token_errors)
5511 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5512
5513 return (0);
5514}
5515
5516static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5517{
5518 struct net_local *tp = netdev_priv(dev);
5519 FCBlock *fcb;
5520 BDBlock *bdb;
5521 __u16 size, len;
5522
5523 fcb = tp->rx_fcb_curr[queue];
5524 len = fcb->frame_length;
5525
5526 fcb->frame_status = 0;
5527 fcb->info = FCB_CHAIN_END;
5528 fcb->back_ptr->info = FCB_WARNING;
5529
5530 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5531
5532 /* update RX BDBs */
5533 size = (len >> RX_BDB_SIZE_SHIFT);
5534 if(len & RX_DATA_BUFFER_SIZE_MASK)
5535 size += sizeof(BDBlock);
5536 size &= (~RX_BDB_SIZE_MASK);
5537
5538 /* check if wrap around */
5539 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5540 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5541 {
5542 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5543 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5544 }
5545
5546 bdb->back_ptr->info = BDB_CHAIN_END;
5547 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5548 tp->rx_bdb_curr[queue] = bdb;
5549
5550 return (0);
5551}
5552
5553static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5554 __u16 queue)
5555{
5556 struct net_local *tp = netdev_priv(dev);
5557
5558 if(smctr_debug > 20)
5559 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5560
5561 if(tp->num_tx_fcbs_used[queue] <= 0)
5562 return (HARDWARE_FAILED);
5563 else
5564 {
5565 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5566 {
5567 tp->tx_buff_used[queue] = 0;
5568 return (HARDWARE_FAILED);
5569 }
5570
5571 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5572
5573 /* if all transmit buffer are cleared
5574 * need to set the tx_buff_curr[] to tx_buff_head[]
5575 * otherwise, tx buffer will be segregate and cannot
5576 * accommodate and buffer greater than (curr - head) and
5577 * (end - curr) since we do not allow wrap around allocation.
5578 */
5579 if(tp->tx_buff_used[queue] == 0)
5580 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5581
5582 tp->num_tx_fcbs_used[queue]--;
5583 fcb->frame_status = 0;
5584 tp->tx_fcb_end[queue] = fcb->next_ptr;
5585 netif_wake_queue(dev);
5586 return (0);
5587 }
5588}
5589
5590static int smctr_wait_cmd(struct net_device *dev)
5591{
5592 struct net_local *tp = netdev_priv(dev);
5593 unsigned int loop_count = 0x20000;
5594
5595 if(smctr_debug > 10)
5596 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5597
5598 while(loop_count)
5599 {
5600 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5601 break;
5602 udelay(1);
5603 loop_count--;
5604 }
5605
5606 if(loop_count == 0)
5607 return(HARDWARE_FAILED);
5608
5609 if(tp->acb_head->cmd_done_status & 0xff)
5610 return(HARDWARE_FAILED);
5611
5612 return (0);
5613}
5614
5615static int smctr_wait_while_cbusy(struct net_device *dev)
5616{
5617 struct net_local *tp = netdev_priv(dev);
5618 unsigned int timeout = 0x20000;
5619 int ioaddr = dev->base_addr;
5620 __u8 r;
5621
5622 if(tp->bic_type == BIC_585_CHIP)
5623 {
5624 while(timeout)
5625 {
5626 r = inb(ioaddr + HWR);
5627 if((r & HWR_CBUSY) == 0)
5628 break;
5629 timeout--;
5630 }
5631 }
5632 else
5633 {
5634 while(timeout)
5635 {
5636 r = inb(ioaddr + CSR);
5637 if((r & CSR_CBUSY) == 0)
5638 break;
5639 timeout--;
5640 }
5641 }
5642
5643 if(timeout)
5644 return (0);
5645 else
5646 return (HARDWARE_FAILED);
5647}
5648
5649#ifdef MODULE
5650
5651static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5652static int io[SMCTR_MAX_ADAPTERS];
5653static int irq[SMCTR_MAX_ADAPTERS];
5654
5655MODULE_LICENSE("GPL");
David Woodhouse0f805b82008-05-29 16:39:16 +03005656MODULE_FIRMWARE("tr_smctr.bin");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005657
5658module_param_array(io, int, NULL, 0);
5659module_param_array(irq, int, NULL, 0);
5660module_param(ringspeed, int, 0);
5661
Andrew Mortondaca7cd2006-08-14 23:00:06 -07005662static struct net_device * __init setup_card(int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005663{
5664 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5665 int err;
5666
5667 if (!dev)
5668 return ERR_PTR(-ENOMEM);
5669
5670 dev->irq = irq[n];
5671 err = smctr_probe1(dev, io[n]);
5672 if (err)
5673 goto out;
5674
5675 err = register_netdev(dev);
5676 if (err)
5677 goto out1;
5678 return dev;
5679 out1:
5680#ifdef CONFIG_MCA_LEGACY
5681 { struct net_local *tp = netdev_priv(dev);
5682 if (tp->slot_num)
5683 mca_mark_as_unused(tp->slot_num);
5684 }
5685#endif
5686 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5687 free_irq(dev->irq, dev);
5688out:
5689 free_netdev(dev);
5690 return ERR_PTR(err);
5691}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692
Andrew Mortondaca7cd2006-08-14 23:00:06 -07005693int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005694{
5695 int i, found = 0;
5696 struct net_device *dev;
5697
5698 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5699 dev = io[0]? setup_card(i) : smctr_probe(-1);
5700 if (!IS_ERR(dev)) {
5701 ++found;
5702 dev_smctr[i] = dev;
5703 }
5704 }
5705
5706 return found ? 0 : -ENODEV;
5707}
5708
Al Viroafc8eb42006-06-14 18:50:53 -04005709void __exit cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005710{
5711 int i;
5712
5713 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5714 struct net_device *dev = dev_smctr[i];
5715
5716 if (dev) {
5717
5718 unregister_netdev(dev);
5719#ifdef CONFIG_MCA_LEGACY
5720 { struct net_local *tp = netdev_priv(dev);
5721 if (tp->slot_num)
5722 mca_mark_as_unused(tp->slot_num);
5723 }
5724#endif
5725 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5726 if (dev->irq)
5727 free_irq(dev->irq, dev);
5728
5729 free_netdev(dev);
5730 }
5731 }
5732}
5733#endif /* MODULE */