blob: 029846a98636323bac69ceacdc04b67092b2085a [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/string.h>
40#include <linux/time.h>
41#include <linux/errno.h>
42#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <linux/mca-legacy.h>
44#include <linux/delay.h>
45#include <linux/netdevice.h>
46#include <linux/etherdevice.h>
47#include <linux/skbuff.h>
48#include <linux/trdevice.h>
49#include <linux/bitops.h>
David Woodhouse0f805b82008-05-29 16:39:16 +030050#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52#include <asm/system.h>
53#include <asm/io.h>
54#include <asm/dma.h>
55#include <asm/irq.h>
56
57#if BITS_PER_LONG == 64
58#error FIXME: driver does not support 64-bit platforms
59#endif
60
61#include "smctr.h" /* Our Stuff */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Hannes Eder1770e432009-02-14 11:44:19 +000063static const char version[] __initdata =
64 KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.org\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -070065static const char cardname[] = "smctr";
66
67
68#define SMCTR_IO_EXTENT 20
69
70#ifdef CONFIG_MCA_LEGACY
71static unsigned int smctr_posid = 0x6ec6;
72#endif
73
74static int ringspeed;
75
76/* SMC Name of the Adapter. */
77static char smctr_name[] = "SMC TokenCard";
Adrian Bunkde70b4c2005-05-02 03:46:43 +020078static char *smctr_model = "Unknown";
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/* Use 0 for production, 1 for verification, 2 for debug, and
81 * 3 for very verbose debug.
82 */
83#ifndef SMCTR_DEBUG
84#define SMCTR_DEBUG 1
85#endif
86static unsigned int smctr_debug = SMCTR_DEBUG;
87
88/* smctr.c prototypes and functions are arranged alphabeticly
89 * for clearity, maintainability and pure old fashion fun.
90 */
91/* A */
92static int smctr_alloc_shared_memory(struct net_device *dev);
93
94/* B */
95static int smctr_bypass_state(struct net_device *dev);
96
97/* C */
98static int smctr_checksum_firmware(struct net_device *dev);
99static int __init smctr_chk_isa(struct net_device *dev);
100static int smctr_chg_rx_mask(struct net_device *dev);
101static int smctr_clear_int(struct net_device *dev);
102static int smctr_clear_trc_reset(int ioaddr);
103static int smctr_close(struct net_device *dev);
104
105/* D */
David Woodhouse0f805b82008-05-29 16:39:16 +0300106static int smctr_decode_firmware(struct net_device *dev,
107 const struct firmware *fw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108static int smctr_disable_16bit(struct net_device *dev);
109static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
110static int smctr_disable_bic_int(struct net_device *dev);
111
112/* E */
113static int smctr_enable_16bit(struct net_device *dev);
114static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
115static int smctr_enable_adapter_ram(struct net_device *dev);
116static int smctr_enable_bic_int(struct net_device *dev);
117
118/* G */
119static int __init smctr_get_boardid(struct net_device *dev, int mca);
120static int smctr_get_group_address(struct net_device *dev);
121static int smctr_get_functional_address(struct net_device *dev);
122static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
123static int smctr_get_physical_drop_number(struct net_device *dev);
124static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
125static int smctr_get_station_id(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
127 __u16 bytes_count);
128static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
129
130/* H */
131static int smctr_hardware_send_packet(struct net_device *dev,
132 struct net_local *tp);
133/* I */
134static int smctr_init_acbs(struct net_device *dev);
135static int smctr_init_adapter(struct net_device *dev);
136static int smctr_init_card_real(struct net_device *dev);
137static int smctr_init_rx_bdbs(struct net_device *dev);
138static int smctr_init_rx_fcbs(struct net_device *dev);
139static int smctr_init_shared_memory(struct net_device *dev);
140static int smctr_init_tx_bdbs(struct net_device *dev);
141static int smctr_init_tx_fcbs(struct net_device *dev);
142static int smctr_internal_self_test(struct net_device *dev);
David Howells7d12e782006-10-05 14:55:46 +0100143static irqreturn_t smctr_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144static int smctr_issue_enable_int_cmd(struct net_device *dev,
145 __u16 interrupt_enable_mask);
146static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
147 __u16 ibits);
148static int smctr_issue_init_timers_cmd(struct net_device *dev);
149static int smctr_issue_init_txrx_cmd(struct net_device *dev);
150static int smctr_issue_insert_cmd(struct net_device *dev);
151static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
152static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
153static int smctr_issue_remove_cmd(struct net_device *dev);
154static int smctr_issue_resume_acb_cmd(struct net_device *dev);
155static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
156static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
157static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
158static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
159static int smctr_issue_test_hic_cmd(struct net_device *dev);
160static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
161static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
162static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
163static int smctr_issue_write_byte_cmd(struct net_device *dev,
164 short aword_cnt, void *byte);
165static int smctr_issue_write_word_cmd(struct net_device *dev,
166 short aword_cnt, void *word);
167
168/* J */
169static int smctr_join_complete_state(struct net_device *dev);
170
171/* L */
172static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
173static int smctr_load_firmware(struct net_device *dev);
174static int smctr_load_node_addr(struct net_device *dev);
175static int smctr_lobe_media_test(struct net_device *dev);
176static int smctr_lobe_media_test_cmd(struct net_device *dev);
177static int smctr_lobe_media_test_state(struct net_device *dev);
178
179/* M */
180static int smctr_make_8025_hdr(struct net_device *dev,
181 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
182static int smctr_make_access_pri(struct net_device *dev,
183 MAC_SUB_VECTOR *tsv);
184static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
185static int smctr_make_auth_funct_class(struct net_device *dev,
186 MAC_SUB_VECTOR *tsv);
187static int smctr_make_corr(struct net_device *dev,
188 MAC_SUB_VECTOR *tsv, __u16 correlator);
189static int smctr_make_funct_addr(struct net_device *dev,
190 MAC_SUB_VECTOR *tsv);
191static int smctr_make_group_addr(struct net_device *dev,
192 MAC_SUB_VECTOR *tsv);
193static int smctr_make_phy_drop_num(struct net_device *dev,
194 MAC_SUB_VECTOR *tsv);
195static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
196static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
197static int smctr_make_ring_station_status(struct net_device *dev,
198 MAC_SUB_VECTOR *tsv);
199static int smctr_make_ring_station_version(struct net_device *dev,
200 MAC_SUB_VECTOR *tsv);
201static int smctr_make_tx_status_code(struct net_device *dev,
202 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
203static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
204 MAC_SUB_VECTOR *tsv);
205static int smctr_make_wrap_data(struct net_device *dev,
206 MAC_SUB_VECTOR *tsv);
207
208/* O */
209static int smctr_open(struct net_device *dev);
210static int smctr_open_tr(struct net_device *dev);
211
212/* P */
213struct net_device *smctr_probe(int unit);
214static int __init smctr_probe1(struct net_device *dev, int ioaddr);
215static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
216 struct net_device *dev, __u16 rx_status);
217
218/* R */
219static int smctr_ram_memory_test(struct net_device *dev);
220static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
221 __u16 *correlator);
222static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
223 __u16 *correlator);
224static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
225static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
226 MAC_HEADER *rmf, __u16 *correlator);
227static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
228 __u16 *correlator);
229static int smctr_reset_adapter(struct net_device *dev);
230static int smctr_restart_tx_chain(struct net_device *dev, short queue);
231static int smctr_ring_status_chg(struct net_device *dev);
232static int smctr_rx_frame(struct net_device *dev);
233
234/* S */
235static int smctr_send_dat(struct net_device *dev);
Stephen Hemminger61a84102009-08-31 19:50:46 +0000236static netdev_tx_t smctr_send_packet(struct sk_buff *skb,
237 struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238static int smctr_send_lobe_media_test(struct net_device *dev);
239static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
240 __u16 correlator);
241static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
242 __u16 correlator);
243static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
244 __u16 correlator);
245static int smctr_send_rpt_tx_forward(struct net_device *dev,
246 MAC_HEADER *rmf, __u16 tx_fstatus);
247static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
248 __u16 rcode, __u16 correlator);
249static int smctr_send_rq_init(struct net_device *dev);
250static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
251 __u16 *tx_fstatus);
252static int smctr_set_auth_access_pri(struct net_device *dev,
253 MAC_SUB_VECTOR *rsv);
254static int smctr_set_auth_funct_class(struct net_device *dev,
255 MAC_SUB_VECTOR *rsv);
256static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
257 __u16 *correlator);
258static int smctr_set_error_timer_value(struct net_device *dev,
259 MAC_SUB_VECTOR *rsv);
260static int smctr_set_frame_forward(struct net_device *dev,
261 MAC_SUB_VECTOR *rsv, __u8 dc_sc);
262static int smctr_set_local_ring_num(struct net_device *dev,
263 MAC_SUB_VECTOR *rsv);
264static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
265static void smctr_set_multicast_list(struct net_device *dev);
266static int smctr_set_page(struct net_device *dev, __u8 *buf);
267static int smctr_set_phy_drop(struct net_device *dev,
268 MAC_SUB_VECTOR *rsv);
269static int smctr_set_ring_speed(struct net_device *dev);
270static int smctr_set_rx_look_ahead(struct net_device *dev);
271static int smctr_set_trc_reset(int ioaddr);
272static int smctr_setup_single_cmd(struct net_device *dev,
273 __u16 command, __u16 subcommand);
274static int smctr_setup_single_cmd_w_data(struct net_device *dev,
275 __u16 command, __u16 subcommand);
276static char *smctr_malloc(struct net_device *dev, __u16 size);
277static int smctr_status_chg(struct net_device *dev);
278
279/* T */
280static void smctr_timeout(struct net_device *dev);
281static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
282 __u16 queue);
283static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
284static unsigned short smctr_tx_move_frame(struct net_device *dev,
285 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
286
287/* U */
288static int smctr_update_err_stats(struct net_device *dev);
289static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
290static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
291 __u16 queue);
292
293/* W */
294static int smctr_wait_cmd(struct net_device *dev);
295static int smctr_wait_while_cbusy(struct net_device *dev);
296
297#define TO_256_BYTE_BOUNDRY(X) (((X + 0xff) & 0xff00) - X)
298#define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
299#define PARAGRAPH_BOUNDRY(X) smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
300
301/* Allocate Adapter Shared Memory.
302 * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
303 * function "get_num_rx_bdbs" below!!!
304 *
305 * Order of memory allocation:
306 *
307 * 0. Initial System Configuration Block Pointer
308 * 1. System Configuration Block
309 * 2. System Control Block
310 * 3. Action Command Block
311 * 4. Interrupt Status Block
312 *
313 * 5. MAC TX FCB'S
314 * 6. NON-MAC TX FCB'S
315 * 7. MAC TX BDB'S
316 * 8. NON-MAC TX BDB'S
317 * 9. MAC RX FCB'S
318 * 10. NON-MAC RX FCB'S
319 * 11. MAC RX BDB'S
320 * 12. NON-MAC RX BDB'S
321 * 13. MAC TX Data Buffer( 1, 256 byte buffer)
322 * 14. MAC RX Data Buffer( 1, 256 byte buffer)
323 *
324 * 15. NON-MAC TX Data Buffer
325 * 16. NON-MAC RX Data Buffer
326 */
327static int smctr_alloc_shared_memory(struct net_device *dev)
328{
329 struct net_local *tp = netdev_priv(dev);
330
331 if(smctr_debug > 10)
332 printk(KERN_DEBUG "%s: smctr_alloc_shared_memory\n", dev->name);
333
334 /* Allocate initial System Control Block pointer.
335 * This pointer is located in the last page, last offset - 4.
336 */
337 tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
338 - (long)ISCP_BLOCK_SIZE);
339
340 /* Allocate System Control Blocks. */
341 tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
342 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
343
344 tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
345 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
346
347 tp->acb_head = (ACBlock *)smctr_malloc(dev,
348 sizeof(ACBlock)*tp->num_acbs);
349 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
350
351 tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
352 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
353
354 tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
355 PARAGRAPH_BOUNDRY(tp->sh_mem_used);
356
357 /* Allocate transmit FCBs. */
358 tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
359 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
360
361 tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
362 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
363
364 tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
365 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
366
367 /* Allocate transmit BDBs. */
368 tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
369 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
370
371 tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
372 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
373
374 tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
375 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
376
377 /* Allocate receive FCBs. */
378 tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
379 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
380
381 tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
382 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
383
384 /* Allocate receive BDBs. */
385 tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
386 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
387
388 tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
389
390 tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
391 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
392
393 tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
394
395 /* Allocate MAC transmit buffers.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300396 * MAC Tx Buffers doen't have to be on an ODD Boundary.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 */
398 tp->tx_buff_head[MAC_QUEUE]
399 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
400 tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
401 tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
402
403 /* Allocate BUG transmit buffers. */
404 tp->tx_buff_head[BUG_QUEUE]
405 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
406 tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
407 tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
408
409 /* Allocate MAC receive data buffers.
410 * MAC Rx buffer doesn't have to be on a 256 byte boundary.
411 */
412 tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
413 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
414 tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
415
416 /* Allocate Non-MAC transmit buffers.
417 * ?? For maximum Netware performance, put Tx Buffers on
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300418 * ODD Boundary and then restore malloc to Even Boundrys.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 */
420 smctr_malloc(dev, 1L);
421 tp->tx_buff_head[NON_MAC_QUEUE]
422 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
423 tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
424 tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
425 smctr_malloc(dev, 1L);
426
427 /* Allocate Non-MAC receive data buffers.
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200428 * To guarantee a minimum of 256 contiguous memory to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 * UM_Receive_Packet's lookahead pointer, before a page
430 * change or ring end is encountered, place each rx buffer on
431 * a 256 byte boundary.
432 */
433 smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
434 tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
435 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
436 tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
437
Eric Dumazet807540b2010-09-23 05:40:09 +0000438 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439}
440
441/* Enter Bypass state. */
442static int smctr_bypass_state(struct net_device *dev)
443{
444 int err;
445
446 if(smctr_debug > 10)
447 printk(KERN_DEBUG "%s: smctr_bypass_state\n", dev->name);
448
449 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE, JS_BYPASS_STATE);
450
Eric Dumazet807540b2010-09-23 05:40:09 +0000451 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454static int smctr_checksum_firmware(struct net_device *dev)
455{
456 struct net_local *tp = netdev_priv(dev);
457 __u16 i, checksum = 0;
458
459 if(smctr_debug > 10)
460 printk(KERN_DEBUG "%s: smctr_checksum_firmware\n", dev->name);
461
462 smctr_enable_adapter_ctrl_store(dev);
463
464 for(i = 0; i < CS_RAM_SIZE; i += 2)
465 checksum += *((__u16 *)(tp->ram_access + i));
466
467 tp->microcode_version = *(__u16 *)(tp->ram_access
468 + CS_RAM_VERSION_OFFSET);
469 tp->microcode_version >>= 8;
470
471 smctr_disable_adapter_ctrl_store(dev);
472
473 if(checksum)
Eric Dumazet807540b2010-09-23 05:40:09 +0000474 return checksum;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
Eric Dumazet807540b2010-09-23 05:40:09 +0000476 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477}
478
479static int __init smctr_chk_mca(struct net_device *dev)
480{
481#ifdef CONFIG_MCA_LEGACY
482 struct net_local *tp = netdev_priv(dev);
483 int current_slot;
484 __u8 r1, r2, r3, r4, r5;
485
486 current_slot = mca_find_unused_adapter(smctr_posid, 0);
487 if(current_slot == MCA_NOTFOUND)
Eric Dumazet807540b2010-09-23 05:40:09 +0000488 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 mca_set_adapter_name(current_slot, smctr_name);
491 mca_mark_as_used(current_slot);
492 tp->slot_num = current_slot;
493
494 r1 = mca_read_stored_pos(tp->slot_num, 2);
495 r2 = mca_read_stored_pos(tp->slot_num, 3);
496
497 if(tp->slot_num)
498 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
499 else
500 outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
501
502 r1 = inb(CNFG_POS_REG1);
503 r2 = inb(CNFG_POS_REG0);
504
505 tp->bic_type = BIC_594_CHIP;
506
507 /* IO */
508 r2 = mca_read_stored_pos(tp->slot_num, 2);
509 r2 &= 0xF0;
510 dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
511 request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
512
513 /* IRQ */
514 r5 = mca_read_stored_pos(tp->slot_num, 5);
515 r5 &= 0xC;
516 switch(r5)
517 {
518 case 0:
519 dev->irq = 3;
520 break;
521
522 case 0x4:
523 dev->irq = 4;
524 break;
525
526 case 0x8:
527 dev->irq = 10;
528 break;
529
530 default:
531 dev->irq = 15;
532 break;
533 }
Thomas Gleixner1fb9df52006-07-01 19:29:39 -0700534 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 release_region(dev->base_addr, SMCTR_IO_EXTENT);
536 return -ENODEV;
537 }
538
539 /* Get RAM base */
540 r3 = mca_read_stored_pos(tp->slot_num, 3);
541 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
542 if (r3 & 0x8)
543 tp->ram_base += 0x010000;
544 if (r3 & 0x80)
545 tp->ram_base += 0xF00000;
546
547 /* Get Ram Size */
548 r3 &= 0x30;
549 r3 >>= 4;
550
551 tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
552 tp->ram_size = (__u16)CNFG_SIZE_64KB;
553 tp->board_id |= TOKEN_MEDIA;
554
555 r4 = mca_read_stored_pos(tp->slot_num, 4);
556 tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0x0C0000;
557 if (r4 & 0x8)
558 tp->rom_base += 0x010000;
559
560 /* Get ROM size. */
561 r4 >>= 4;
562 switch (r4) {
563 case 0:
564 tp->rom_size = CNFG_SIZE_8KB;
565 break;
566 case 1:
567 tp->rom_size = CNFG_SIZE_16KB;
568 break;
569 case 2:
570 tp->rom_size = CNFG_SIZE_32KB;
571 break;
572 default:
573 tp->rom_size = ROM_DISABLE;
574 }
575
576 /* Get Media Type. */
577 r5 = mca_read_stored_pos(tp->slot_num, 5);
578 r5 &= CNFG_MEDIA_TYPE_MASK;
579 switch(r5)
580 {
581 case (0):
582 tp->media_type = MEDIA_STP_4;
583 break;
584
585 case (1):
586 tp->media_type = MEDIA_STP_16;
587 break;
588
589 case (3):
590 tp->media_type = MEDIA_UTP_16;
591 break;
592
593 default:
594 tp->media_type = MEDIA_UTP_4;
595 break;
596 }
597 tp->media_menu = 14;
598
599 r2 = mca_read_stored_pos(tp->slot_num, 2);
600 if(!(r2 & 0x02))
601 tp->mode_bits |= EARLY_TOKEN_REL;
602
603 /* Disable slot */
604 outb(CNFG_POS_CONTROL_REG, 0);
605
606 tp->board_id = smctr_get_boardid(dev, 1);
607 switch(tp->board_id & 0xffff)
608 {
609 case WD8115TA:
610 smctr_model = "8115T/A";
611 break;
612
613 case WD8115T:
614 if(tp->extra_info & CHIP_REV_MASK)
615 smctr_model = "8115T rev XE";
616 else
617 smctr_model = "8115T rev XD";
618 break;
619
620 default:
621 smctr_model = "Unknown";
622 break;
623 }
624
Eric Dumazet807540b2010-09-23 05:40:09 +0000625 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626#else
Eric Dumazet807540b2010-09-23 05:40:09 +0000627 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628#endif /* CONFIG_MCA_LEGACY */
629}
630
631static int smctr_chg_rx_mask(struct net_device *dev)
632{
633 struct net_local *tp = netdev_priv(dev);
634 int err = 0;
635
636 if(smctr_debug > 10)
637 printk(KERN_DEBUG "%s: smctr_chg_rx_mask\n", dev->name);
638
639 smctr_enable_16bit(dev);
640 smctr_set_page(dev, (__u8 *)tp->ram_access);
641
642 if(tp->mode_bits & LOOPING_MODE_MASK)
643 tp->config_word0 |= RX_OWN_BIT;
644 else
645 tp->config_word0 &= ~RX_OWN_BIT;
646
647 if(tp->receive_mask & PROMISCUOUS_MODE)
648 tp->config_word0 |= PROMISCUOUS_BIT;
649 else
650 tp->config_word0 &= ~PROMISCUOUS_BIT;
651
652 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
653 tp->config_word0 |= SAVBAD_BIT;
654 else
655 tp->config_word0 &= ~SAVBAD_BIT;
656
657 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
658 tp->config_word0 |= RXATMAC;
659 else
660 tp->config_word0 &= ~RXATMAC;
661
662 if(tp->receive_mask & ACCEPT_MULTI_PROM)
663 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
664 else
665 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
666
667 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
668 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
669 else
670 {
671 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
672 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
673 else
674 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
675 }
676
677 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
678 &tp->config_word0)))
679 {
Eric Dumazet807540b2010-09-23 05:40:09 +0000680 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
682
683 if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
684 &tp->config_word1)))
685 {
Eric Dumazet807540b2010-09-23 05:40:09 +0000686 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688
689 smctr_disable_16bit(dev);
690
Eric Dumazet807540b2010-09-23 05:40:09 +0000691 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692}
693
694static int smctr_clear_int(struct net_device *dev)
695{
696 struct net_local *tp = netdev_priv(dev);
697
698 outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
699
Eric Dumazet807540b2010-09-23 05:40:09 +0000700 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701}
702
703static int smctr_clear_trc_reset(int ioaddr)
704{
705 __u8 r;
706
707 r = inb(ioaddr + MSR);
708 outb(~MSR_RST & r, ioaddr + MSR);
709
Eric Dumazet807540b2010-09-23 05:40:09 +0000710 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
713/*
714 * The inverse routine to smctr_open().
715 */
716static int smctr_close(struct net_device *dev)
717{
718 struct net_local *tp = netdev_priv(dev);
719 struct sk_buff *skb;
720 int err;
721
722 netif_stop_queue(dev);
723
724 tp->cleanup = 1;
725
726 /* Check to see if adapter is already in a closed state. */
727 if(tp->status != OPEN)
Eric Dumazet807540b2010-09-23 05:40:09 +0000728 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 smctr_enable_16bit(dev);
731 smctr_set_page(dev, (__u8 *)tp->ram_access);
732
733 if((err = smctr_issue_remove_cmd(dev)))
734 {
735 smctr_disable_16bit(dev);
Eric Dumazet807540b2010-09-23 05:40:09 +0000736 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 }
738
739 for(;;)
740 {
741 skb = skb_dequeue(&tp->SendSkbQueue);
742 if(skb == NULL)
743 break;
744 tp->QueueSkb++;
745 dev_kfree_skb(skb);
746 }
747
748
Eric Dumazet807540b2010-09-23 05:40:09 +0000749 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750}
751
David Woodhouse0f805b82008-05-29 16:39:16 +0300752static int smctr_decode_firmware(struct net_device *dev,
753 const struct firmware *fw)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754{
755 struct net_local *tp = netdev_priv(dev);
756 short bit = 0x80, shift = 12;
757 DECODE_TREE_NODE *tree;
758 short branch, tsize;
759 __u16 buff = 0;
760 long weight;
761 __u8 *ucode;
762 __u16 *mem;
763
764 if(smctr_debug > 10)
765 printk(KERN_DEBUG "%s: smctr_decode_firmware\n", dev->name);
766
David Woodhouse0f805b82008-05-29 16:39:16 +0300767 weight = *(long *)(fw->data + WEIGHT_OFFSET);
768 tsize = *(__u8 *)(fw->data + TREE_SIZE_OFFSET);
769 tree = (DECODE_TREE_NODE *)(fw->data + TREE_OFFSET);
770 ucode = (__u8 *)(fw->data + TREE_OFFSET
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 + (tsize * sizeof(DECODE_TREE_NODE)));
772 mem = (__u16 *)(tp->ram_access);
773
774 while(weight)
775 {
776 branch = ROOT;
777 while((tree + branch)->tag != LEAF && weight)
778 {
779 branch = *ucode & bit ? (tree + branch)->llink
780 : (tree + branch)->rlink;
781
782 bit >>= 1;
783 weight--;
784
785 if(bit == 0)
786 {
787 bit = 0x80;
788 ucode++;
789 }
790 }
791
792 buff |= (tree + branch)->info << shift;
793 shift -= 4;
794
795 if(shift < 0)
796 {
797 *(mem++) = SWAP_BYTES(buff);
798 buff = 0;
799 shift = 12;
800 }
801 }
802
803 /* The following assumes the Control Store Memory has
804 * been initialized to zero. If the last partial word
805 * is zero, it will not be written.
806 */
807 if(buff)
808 *(mem++) = SWAP_BYTES(buff);
809
Eric Dumazet807540b2010-09-23 05:40:09 +0000810 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811}
812
813static int smctr_disable_16bit(struct net_device *dev)
814{
Eric Dumazet807540b2010-09-23 05:40:09 +0000815 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816}
817
818/*
819 * On Exit, Adapter is:
820 * 1. TRC is in a reset state and un-initialized.
821 * 2. Adapter memory is enabled.
822 * 3. Control Store memory is out of context (-WCSS is 1).
823 */
824static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
825{
826 struct net_local *tp = netdev_priv(dev);
827 int ioaddr = dev->base_addr;
828
829 if(smctr_debug > 10)
830 printk(KERN_DEBUG "%s: smctr_disable_adapter_ctrl_store\n", dev->name);
831
832 tp->trc_mask |= CSR_WCSS;
833 outb(tp->trc_mask, ioaddr + CSR);
834
Eric Dumazet807540b2010-09-23 05:40:09 +0000835 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836}
837
838static int smctr_disable_bic_int(struct net_device *dev)
839{
840 struct net_local *tp = netdev_priv(dev);
841 int ioaddr = dev->base_addr;
842
843 tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
844 | CSR_MSKTINT | CSR_WCSS;
845 outb(tp->trc_mask, ioaddr + CSR);
846
Eric Dumazet807540b2010-09-23 05:40:09 +0000847 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848}
849
850static int smctr_enable_16bit(struct net_device *dev)
851{
852 struct net_local *tp = netdev_priv(dev);
853 __u8 r;
854
855 if(tp->adapter_bus == BUS_ISA16_TYPE)
856 {
857 r = inb(dev->base_addr + LAAR);
858 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
859 }
860
Eric Dumazet807540b2010-09-23 05:40:09 +0000861 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862}
863
864/*
865 * To enable the adapter control store memory:
866 * 1. Adapter must be in a RESET state.
867 * 2. Adapter memory must be enabled.
868 * 3. Control Store Memory is in context (-WCSS is 0).
869 */
870static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
871{
872 struct net_local *tp = netdev_priv(dev);
873 int ioaddr = dev->base_addr;
874
875 if(smctr_debug > 10)
876 printk(KERN_DEBUG "%s: smctr_enable_adapter_ctrl_store\n", dev->name);
877
878 smctr_set_trc_reset(ioaddr);
879 smctr_enable_adapter_ram(dev);
880
881 tp->trc_mask &= ~CSR_WCSS;
882 outb(tp->trc_mask, ioaddr + CSR);
883
Eric Dumazet807540b2010-09-23 05:40:09 +0000884 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885}
886
887static int smctr_enable_adapter_ram(struct net_device *dev)
888{
889 int ioaddr = dev->base_addr;
890 __u8 r;
891
892 if(smctr_debug > 10)
893 printk(KERN_DEBUG "%s: smctr_enable_adapter_ram\n", dev->name);
894
895 r = inb(ioaddr + MSR);
896 outb(MSR_MEMB | r, ioaddr + MSR);
897
Eric Dumazet807540b2010-09-23 05:40:09 +0000898 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899}
900
901static int smctr_enable_bic_int(struct net_device *dev)
902{
903 struct net_local *tp = netdev_priv(dev);
904 int ioaddr = dev->base_addr;
905 __u8 r;
906
907 switch(tp->bic_type)
908 {
909 case (BIC_584_CHIP):
910 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
911 outb(tp->trc_mask, ioaddr + CSR);
912 r = inb(ioaddr + IRR);
913 outb(r | IRR_IEN, ioaddr + IRR);
914 break;
915
916 case (BIC_594_CHIP):
917 tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
918 outb(tp->trc_mask, ioaddr + CSR);
919 r = inb(ioaddr + IMCCR);
920 outb(r | IMCCR_EIL, ioaddr + IMCCR);
921 break;
922 }
923
Eric Dumazet807540b2010-09-23 05:40:09 +0000924 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925}
926
927static int __init smctr_chk_isa(struct net_device *dev)
928{
929 struct net_local *tp = netdev_priv(dev);
930 int ioaddr = dev->base_addr;
931 __u8 r1, r2, b, chksum = 0;
932 __u16 r;
933 int i;
934 int err = -ENODEV;
935
936 if(smctr_debug > 10)
937 printk(KERN_DEBUG "%s: smctr_chk_isa %#4x\n", dev->name, ioaddr);
938
939 if((ioaddr & 0x1F) != 0)
940 goto out;
941
942 /* Grab the region so that no one else tries to probe our ioports. */
943 if (!request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name)) {
944 err = -EBUSY;
945 goto out;
946 }
947
948 /* Checksum SMC node address */
949 for(i = 0; i < 8; i++)
950 {
951 b = inb(ioaddr + LAR0 + i);
952 chksum += b;
953 }
954
955 if (chksum != NODE_ADDR_CKSUM)
956 goto out2;
957
958 b = inb(ioaddr + BDID);
959 if(b != BRD_ID_8115T)
960 {
961 printk(KERN_ERR "%s: The adapter found is not supported\n", dev->name);
962 goto out2;
963 }
964
965 /* Check for 8115T Board ID */
966 r2 = 0;
967 for(r = 0; r < 8; r++)
968 {
969 r1 = inb(ioaddr + 0x8 + r);
970 r2 += r1;
971 }
972
973 /* value of RegF adds up the sum to 0xFF */
974 if((r2 != 0xFF) && (r2 != 0xEE))
975 goto out2;
976
977 /* Get adapter ID */
978 tp->board_id = smctr_get_boardid(dev, 0);
979 switch(tp->board_id & 0xffff)
980 {
981 case WD8115TA:
982 smctr_model = "8115T/A";
983 break;
984
985 case WD8115T:
986 if(tp->extra_info & CHIP_REV_MASK)
987 smctr_model = "8115T rev XE";
988 else
989 smctr_model = "8115T rev XD";
990 break;
991
992 default:
993 smctr_model = "Unknown";
994 break;
995 }
996
997 /* Store BIC type. */
998 tp->bic_type = BIC_584_CHIP;
999 tp->nic_type = NIC_825_CHIP;
1000
1001 /* Copy Ram Size */
1002 tp->ram_usable = CNFG_SIZE_16KB;
1003 tp->ram_size = CNFG_SIZE_64KB;
1004
1005 /* Get 58x Ram Base */
1006 r1 = inb(ioaddr);
1007 r1 &= 0x3F;
1008
1009 r2 = inb(ioaddr + CNFG_LAAR_584);
1010 r2 &= CNFG_LAAR_MASK;
1011 r2 <<= 3;
1012 r2 |= ((r1 & 0x38) >> 3);
1013
1014 tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
1015
1016 /* Get 584 Irq */
1017 r1 = 0;
1018 r1 = inb(ioaddr + CNFG_ICR_583);
1019 r1 &= CNFG_ICR_IR2_584;
1020
1021 r2 = inb(ioaddr + CNFG_IRR_583);
1022 r2 &= CNFG_IRR_IRQS; /* 0x60 */
1023 r2 >>= 5;
1024
1025 switch(r2)
1026 {
1027 case 0:
1028 if(r1 == 0)
1029 dev->irq = 2;
1030 else
1031 dev->irq = 10;
1032 break;
1033
1034 case 1:
1035 if(r1 == 0)
1036 dev->irq = 3;
1037 else
1038 dev->irq = 11;
1039 break;
1040
1041 case 2:
1042 if(r1 == 0)
1043 {
1044 if(tp->extra_info & ALTERNATE_IRQ_BIT)
1045 dev->irq = 5;
1046 else
1047 dev->irq = 4;
1048 }
1049 else
1050 dev->irq = 15;
1051 break;
1052
1053 case 3:
1054 if(r1 == 0)
1055 dev->irq = 7;
1056 else
1057 dev->irq = 4;
1058 break;
1059
1060 default:
1061 printk(KERN_ERR "%s: No IRQ found aborting\n", dev->name);
1062 goto out2;
1063 }
1064
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07001065 if (request_irq(dev->irq, smctr_interrupt, IRQF_SHARED, smctr_name, dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 goto out2;
1067
1068 /* Get 58x Rom Base */
1069 r1 = inb(ioaddr + CNFG_BIO_583);
1070 r1 &= 0x3E;
1071 r1 |= 0x40;
1072
1073 tp->rom_base = (__u32)r1 << 13;
1074
1075 /* Get 58x Rom Size */
1076 r1 = inb(ioaddr + CNFG_BIO_583);
1077 r1 &= 0xC0;
1078 if(r1 == 0)
1079 tp->rom_size = ROM_DISABLE;
1080 else
1081 {
1082 r1 >>= 6;
1083 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
1084 }
1085
1086 /* Get 58x Boot Status */
1087 r1 = inb(ioaddr + CNFG_GP2);
1088
1089 tp->mode_bits &= (~BOOT_STATUS_MASK);
1090
1091 if(r1 & CNFG_GP2_BOOT_NIBBLE)
1092 tp->mode_bits |= BOOT_TYPE_1;
1093
1094 /* Get 58x Zero Wait State */
1095 tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
1096
1097 r1 = inb(ioaddr + CNFG_IRR_583);
1098
1099 if(r1 & CNFG_IRR_ZWS)
1100 tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
1101
1102 if(tp->board_id & BOARD_16BIT)
1103 {
1104 r1 = inb(ioaddr + CNFG_LAAR_584);
1105
1106 if(r1 & CNFG_LAAR_ZWS)
1107 tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
1108 }
1109
1110 /* Get 584 Media Menu */
1111 tp->media_menu = 14;
1112 r1 = inb(ioaddr + CNFG_IRR_583);
1113
1114 tp->mode_bits &= 0xf8ff; /* (~CNFG_INTERFACE_TYPE_MASK) */
1115 if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
1116 {
1117 /* Get Advanced Features */
1118 if(((r1 & 0x6) >> 1) == 0x3)
1119 tp->media_type |= MEDIA_UTP_16;
1120 else
1121 {
1122 if(((r1 & 0x6) >> 1) == 0x2)
1123 tp->media_type |= MEDIA_STP_16;
1124 else
1125 {
1126 if(((r1 & 0x6) >> 1) == 0x1)
1127 tp->media_type |= MEDIA_UTP_4;
1128
1129 else
1130 tp->media_type |= MEDIA_STP_4;
1131 }
1132 }
1133
1134 r1 = inb(ioaddr + CNFG_GP2);
1135 if(!(r1 & 0x2) ) /* GP2_ETRD */
1136 tp->mode_bits |= EARLY_TOKEN_REL;
1137
1138 /* see if the chip is corrupted
1139 if(smctr_read_584_chksum(ioaddr))
1140 {
1141 printk(KERN_ERR "%s: EEPROM Checksum Failure\n", dev->name);
1142 free_irq(dev->irq, dev);
1143 goto out2;
1144 }
1145 */
1146 }
1147
Eric Dumazet807540b2010-09-23 05:40:09 +00001148 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150out2:
1151 release_region(ioaddr, SMCTR_IO_EXTENT);
1152out:
1153 return err;
1154}
1155
1156static int __init smctr_get_boardid(struct net_device *dev, int mca)
1157{
1158 struct net_local *tp = netdev_priv(dev);
1159 int ioaddr = dev->base_addr;
1160 __u8 r, r1, IdByte;
1161 __u16 BoardIdMask;
1162
1163 tp->board_id = BoardIdMask = 0;
1164
1165 if(mca)
1166 {
1167 BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1168 tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT);
1169 }
1170 else
1171 {
1172 BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
1173 tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K
1174 + NIC_825_BIT + ALTERNATE_IRQ_BIT);
1175 }
1176
1177 if(!mca)
1178 {
1179 r = inb(ioaddr + BID_REG_1);
1180 r &= 0x0c;
1181 outb(r, ioaddr + BID_REG_1);
1182 r = inb(ioaddr + BID_REG_1);
1183
1184 if(r & BID_SIXTEEN_BIT_BIT)
1185 {
1186 tp->extra_info |= SLOT_16BIT;
1187 tp->adapter_bus = BUS_ISA16_TYPE;
1188 }
1189 else
1190 tp->adapter_bus = BUS_ISA8_TYPE;
1191 }
1192 else
1193 tp->adapter_bus = BUS_MCA_TYPE;
1194
1195 /* Get Board Id Byte */
1196 IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
1197
1198 /* if Major version > 1.0 then
1199 * return;
1200 */
1201 if(IdByte & 0xF8)
Eric Dumazet807540b2010-09-23 05:40:09 +00001202 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 r1 = inb(ioaddr + BID_REG_1);
1205 r1 &= BID_ICR_MASK;
1206 r1 |= BID_OTHER_BIT;
1207
1208 outb(r1, ioaddr + BID_REG_1);
1209 r1 = inb(ioaddr + BID_REG_3);
1210
1211 r1 &= BID_EAR_MASK;
1212 r1 |= BID_ENGR_PAGE;
1213
1214 outb(r1, ioaddr + BID_REG_3);
1215 r1 = inb(ioaddr + BID_REG_1);
1216 r1 &= BID_ICR_MASK;
1217 r1 |= (BID_RLA | BID_OTHER_BIT);
1218
1219 outb(r1, ioaddr + BID_REG_1);
1220
1221 r1 = inb(ioaddr + BID_REG_1);
1222 while(r1 & BID_RECALL_DONE_MASK)
1223 r1 = inb(ioaddr + BID_REG_1);
1224
1225 r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
1226
1227 /* clear chip rev bits */
1228 tp->extra_info &= ~CHIP_REV_MASK;
1229 tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
1230
1231 r1 = inb(ioaddr + BID_REG_1);
1232 r1 &= BID_ICR_MASK;
1233 r1 |= BID_OTHER_BIT;
1234
1235 outb(r1, ioaddr + BID_REG_1);
1236 r1 = inb(ioaddr + BID_REG_3);
1237
1238 r1 &= BID_EAR_MASK;
1239 r1 |= BID_EA6;
1240
1241 outb(r1, ioaddr + BID_REG_3);
1242 r1 = inb(ioaddr + BID_REG_1);
1243
1244 r1 &= BID_ICR_MASK;
1245 r1 |= BID_RLA;
1246
1247 outb(r1, ioaddr + BID_REG_1);
1248 r1 = inb(ioaddr + BID_REG_1);
1249
1250 while(r1 & BID_RECALL_DONE_MASK)
1251 r1 = inb(ioaddr + BID_REG_1);
1252
Eric Dumazet807540b2010-09-23 05:40:09 +00001253 return BoardIdMask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254}
1255
1256static int smctr_get_group_address(struct net_device *dev)
1257{
1258 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
1259
Eric Dumazet807540b2010-09-23 05:40:09 +00001260 return smctr_wait_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261}
1262
1263static int smctr_get_functional_address(struct net_device *dev)
1264{
1265 smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
1266
Eric Dumazet807540b2010-09-23 05:40:09 +00001267 return smctr_wait_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
1270/* Calculate number of Non-MAC receive BDB's and data buffers.
1271 * This function must simulate allocateing shared memory exactly
1272 * as the allocate_shared_memory function above.
1273 */
1274static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
1275{
1276 struct net_local *tp = netdev_priv(dev);
1277 unsigned int mem_used = 0;
1278
1279 /* Allocate System Control Blocks. */
1280 mem_used += sizeof(SCGBlock);
1281
1282 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1283 mem_used += sizeof(SCLBlock);
1284
1285 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1286 mem_used += sizeof(ACBlock) * tp->num_acbs;
1287
1288 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1289 mem_used += sizeof(ISBlock);
1290
1291 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1292 mem_used += MISC_DATA_SIZE;
1293
1294 /* Allocate transmit FCB's. */
1295 mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
1296
1297 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE];
1298 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE];
1299 mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE];
1300
1301 /* Allocate transmit BDBs. */
1302 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE];
1303 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE];
1304 mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE];
1305
1306 /* Allocate receive FCBs. */
1307 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE];
1308 mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE];
1309
1310 /* Allocate receive BDBs. */
1311 mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
1312
1313 /* Allocate MAC transmit buffers.
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001314 * MAC transmit buffers don't have to be on an ODD Boundary.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 */
1316 mem_used += tp->tx_buff_size[MAC_QUEUE];
1317
1318 /* Allocate BUG transmit buffers. */
1319 mem_used += tp->tx_buff_size[BUG_QUEUE];
1320
1321 /* Allocate MAC receive data buffers.
1322 * MAC receive buffers don't have to be on a 256 byte boundary.
1323 */
1324 mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
1325
1326 /* Allocate Non-MAC transmit buffers.
1327 * For maximum Netware performance, put Tx Buffers on
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001328 * ODD Boundary,and then restore malloc to Even Boundrys.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 */
1330 mem_used += 1L;
1331 mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
1332 mem_used += 1L;
1333
1334 /* CALCULATE NUMBER OF NON-MAC RX BDB'S
1335 * AND NON-MAC RX DATA BUFFERS
1336 *
1337 * Make sure the mem_used offset at this point is the
1338 * same as in allocate_shared memory or the following
1339 * boundary adjustment will be incorrect (i.e. not allocating
1340 * the non-mac receive buffers above cannot change the 256
1341 * byte offset).
1342 *
1343 * Since this cannot be guaranteed, adding the full 256 bytes
1344 * to the amount of shared memory used at this point will guaranteed
1345 * that the rx data buffers do not overflow shared memory.
1346 */
1347 mem_used += 0x100;
1348
Eric Dumazet807540b2010-09-23 05:40:09 +00001349 return (0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
1352static int smctr_get_physical_drop_number(struct net_device *dev)
1353{
1354 smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
1355
Eric Dumazet807540b2010-09-23 05:40:09 +00001356 return smctr_wait_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357}
1358
1359static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
1360{
1361 struct net_local *tp = netdev_priv(dev);
1362 BDBlock *bdb;
1363
1364 bdb = (BDBlock *)((__u32)tp->ram_access
1365 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
1366
1367 tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
1368
Eric Dumazet807540b2010-09-23 05:40:09 +00001369 return (__u8 *)bdb->data_block_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370}
1371
1372static int smctr_get_station_id(struct net_device *dev)
1373{
1374 smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
1375
Eric Dumazet807540b2010-09-23 05:40:09 +00001376 return smctr_wait_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377}
1378
1379/*
1380 * Get the current statistics. This may be called with the card open
1381 * or closed.
1382 */
1383static struct net_device_stats *smctr_get_stats(struct net_device *dev)
1384{
1385 struct net_local *tp = netdev_priv(dev);
1386
Eric Dumazet807540b2010-09-23 05:40:09 +00001387 return (struct net_device_stats *)&tp->MacStat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
1390static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
1391 __u16 bytes_count)
1392{
1393 struct net_local *tp = netdev_priv(dev);
1394 FCBlock *pFCB;
1395 BDBlock *pbdb;
1396 unsigned short alloc_size;
1397 unsigned short *temp;
1398
1399 if(smctr_debug > 20)
1400 printk(KERN_DEBUG "smctr_get_tx_fcb\n");
1401
1402 /* check if there is enough FCB blocks */
1403 if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue])
Eric Dumazet807540b2010-09-23 05:40:09 +00001404 return (FCBlock *)(-1L);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
1406 /* round off the input pkt size to the nearest even number */
1407 alloc_size = (bytes_count + 1) & 0xfffe;
1408
1409 /* check if enough mem */
1410 if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
Eric Dumazet807540b2010-09-23 05:40:09 +00001411 return (FCBlock *)(-1L);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
1413 /* check if past the end ;
1414 * if exactly enough mem to end of ring, alloc from front.
1415 * this avoids update of curr when curr = end
1416 */
1417 if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
1418 >= (unsigned long)(tp->tx_buff_end[queue]))
1419 {
1420 /* check if enough memory from ring head */
1421 alloc_size = alloc_size +
1422 (__u16)((__u32)tp->tx_buff_end[queue]
1423 - (__u32)tp->tx_buff_curr[queue]);
1424
1425 if((tp->tx_buff_used[queue] + alloc_size)
1426 > tp->tx_buff_size[queue])
1427 {
Eric Dumazet807540b2010-09-23 05:40:09 +00001428 return (FCBlock *)(-1L);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430
1431 /* ring wrap */
1432 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
1433 }
1434
1435 tp->tx_buff_used[queue] += alloc_size;
1436 tp->num_tx_fcbs_used[queue]++;
1437 tp->tx_fcb_curr[queue]->frame_length = bytes_count;
1438 tp->tx_fcb_curr[queue]->memory_alloc = alloc_size;
1439 temp = tp->tx_buff_curr[queue];
1440 tp->tx_buff_curr[queue]
1441 = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe));
1442
1443 pbdb = tp->tx_fcb_curr[queue]->bdb_ptr;
1444 pbdb->buffer_length = bytes_count;
1445 pbdb->data_block_ptr = temp;
1446 pbdb->trc_data_block_ptr = TRC_POINTER(temp);
1447
1448 pFCB = tp->tx_fcb_curr[queue];
1449 tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
1450
Eric Dumazet807540b2010-09-23 05:40:09 +00001451 return pFCB;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452}
1453
1454static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
1455{
1456 smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
1457
Eric Dumazet807540b2010-09-23 05:40:09 +00001458 return smctr_wait_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459}
1460
1461static int smctr_hardware_send_packet(struct net_device *dev,
1462 struct net_local *tp)
1463{
1464 struct tr_statistics *tstat = &tp->MacStat;
1465 struct sk_buff *skb;
1466 FCBlock *fcb;
1467
1468 if(smctr_debug > 10)
1469 printk(KERN_DEBUG"%s: smctr_hardware_send_packet\n", dev->name);
1470
1471 if(tp->status != OPEN)
Eric Dumazet807540b2010-09-23 05:40:09 +00001472 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 if(tp->monitor_state_ready != 1)
Eric Dumazet807540b2010-09-23 05:40:09 +00001475 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 for(;;)
1478 {
1479 /* Send first buffer from queue */
1480 skb = skb_dequeue(&tp->SendSkbQueue);
1481 if(skb == NULL)
Eric Dumazet807540b2010-09-23 05:40:09 +00001482 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484 tp->QueueSkb++;
1485
Eric Dumazet807540b2010-09-23 05:40:09 +00001486 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size)
1487 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
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);
Eric Dumazet807540b2010-09-23 05:40:09 +00001496 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 }
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
Eric Dumazet807540b2010-09-23 05:40:09 +00001512 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
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
Eric Dumazet807540b2010-09-23 05:40:09 +00001556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557}
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 {
Eric Dumazet807540b2010-09-23 05:40:09 +00001594 printk(KERN_ERR "%s: Previously loaded firmware is missing\n",dev->name);
1595 return -ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 }
1597
1598 if((err = smctr_ram_memory_test(dev)))
1599 {
1600 printk(KERN_ERR "%s: RAM memory test failed.\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00001601 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 }
1603
1604 smctr_set_rx_look_ahead(dev);
1605 smctr_load_node_addr(dev);
1606
1607 /* Initialize adapter for Internal Self Test. */
1608 smctr_reset_adapter(dev);
1609 if((err = smctr_init_card_real(dev)))
1610 {
1611 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1612 dev->name, err);
Eric Dumazet807540b2010-09-23 05:40:09 +00001613 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 }
1615
1616 /* This routine clobbers the TRC's internal registers. */
1617 if((err = smctr_internal_self_test(dev)))
1618 {
1619 printk(KERN_ERR "%s: Card failed internal self test (%d)\n",
1620 dev->name, err);
Eric Dumazet807540b2010-09-23 05:40:09 +00001621 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 }
1623
1624 /* Re-Initialize adapter's internal registers */
1625 smctr_reset_adapter(dev);
1626 if((err = smctr_init_card_real(dev)))
1627 {
1628 printk(KERN_ERR "%s: Initialization of card failed (%d)\n",
1629 dev->name, err);
Eric Dumazet807540b2010-09-23 05:40:09 +00001630 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 }
1632
1633 smctr_enable_bic_int(dev);
1634
1635 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001636 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
1638 smctr_disable_16bit(dev);
1639
Eric Dumazet807540b2010-09-23 05:40:09 +00001640 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
1642
1643static int smctr_init_card_real(struct net_device *dev)
1644{
1645 struct net_local *tp = netdev_priv(dev);
1646 int err = 0;
1647
1648 if(smctr_debug > 10)
1649 printk(KERN_DEBUG "%s: smctr_init_card_real\n", dev->name);
1650
1651 tp->sh_mem_used = 0;
1652 tp->num_acbs = NUM_OF_ACBS;
1653
1654 /* Range Check Max Packet Size */
1655 if(tp->max_packet_size < 256)
1656 tp->max_packet_size = 256;
1657 else
1658 {
1659 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
1660 tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
1661 }
1662
1663 tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
1664 / tp->max_packet_size) - 1;
1665
1666 if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
1667 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
1668 else
1669 {
1670 if(tp->num_of_tx_buffs == 0)
1671 tp->num_of_tx_buffs = 1;
1672 }
1673
1674 /* Tx queue constants */
1675 tp->num_tx_fcbs [BUG_QUEUE] = NUM_BUG_TX_FCBS;
1676 tp->num_tx_bdbs [BUG_QUEUE] = NUM_BUG_TX_BDBS;
1677 tp->tx_buff_size [BUG_QUEUE] = BUG_TX_BUFFER_MEMORY;
1678 tp->tx_buff_used [BUG_QUEUE] = 0;
1679 tp->tx_queue_status [BUG_QUEUE] = NOT_TRANSMITING;
1680
1681 tp->num_tx_fcbs [MAC_QUEUE] = NUM_MAC_TX_FCBS;
1682 tp->num_tx_bdbs [MAC_QUEUE] = NUM_MAC_TX_BDBS;
1683 tp->tx_buff_size [MAC_QUEUE] = MAC_TX_BUFFER_MEMORY;
1684 tp->tx_buff_used [MAC_QUEUE] = 0;
1685 tp->tx_queue_status [MAC_QUEUE] = NOT_TRANSMITING;
1686
1687 tp->num_tx_fcbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
1688 tp->num_tx_bdbs [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
1689 tp->tx_buff_size [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
1690 tp->tx_buff_used [NON_MAC_QUEUE] = 0;
1691 tp->tx_queue_status [NON_MAC_QUEUE] = NOT_TRANSMITING;
1692
1693 /* Receive Queue Constants */
1694 tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
1695 tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
1696
1697 if(tp->extra_info & CHIP_REV_MASK)
1698 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78; /* 825 Rev. XE */
1699 else
1700 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7; /* 825 Rev. XD */
1701
1702 tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
1703
1704 smctr_alloc_shared_memory(dev);
1705 smctr_init_shared_memory(dev);
1706
1707 if((err = smctr_issue_init_timers_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001708 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
1710 if((err = smctr_issue_init_txrx_cmd(dev)))
1711 {
1712 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00001713 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 }
1715
Eric Dumazet807540b2010-09-23 05:40:09 +00001716 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
1719static int smctr_init_rx_bdbs(struct net_device *dev)
1720{
1721 struct net_local *tp = netdev_priv(dev);
1722 unsigned int i, j;
1723 BDBlock *bdb;
1724 __u16 *buf;
1725
1726 if(smctr_debug > 10)
1727 printk(KERN_DEBUG "%s: smctr_init_rx_bdbs\n", dev->name);
1728
1729 for(i = 0; i < NUM_RX_QS_USED; i++)
1730 {
1731 bdb = tp->rx_bdb_head[i];
1732 buf = tp->rx_buff_head[i];
1733 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
1734 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1735 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1736 bdb->data_block_ptr = buf;
1737 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1738
1739 if(i == NON_MAC_QUEUE)
1740 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1741 else
1742 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1743
1744 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
1745 {
1746 bdb->next_ptr->back_ptr = bdb;
1747 bdb = bdb->next_ptr;
1748 buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
1749 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1750 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
1751 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1752 bdb->data_block_ptr = buf;
1753 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1754
1755 if(i == NON_MAC_QUEUE)
1756 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
1757 else
1758 bdb->trc_data_block_ptr = TRC_POINTER(buf);
1759 }
1760
1761 bdb->next_ptr = tp->rx_bdb_head[i];
1762 bdb->trc_next_ptr = TRC_POINTER(tp->rx_bdb_head[i]);
1763
1764 tp->rx_bdb_head[i]->back_ptr = bdb;
1765 tp->rx_bdb_curr[i] = tp->rx_bdb_head[i]->next_ptr;
1766 }
1767
Eric Dumazet807540b2010-09-23 05:40:09 +00001768 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769}
1770
1771static int smctr_init_rx_fcbs(struct net_device *dev)
1772{
1773 struct net_local *tp = netdev_priv(dev);
1774 unsigned int i, j;
1775 FCBlock *fcb;
1776
1777 for(i = 0; i < NUM_RX_QS_USED; i++)
1778 {
1779 fcb = tp->rx_fcb_head[i];
1780 fcb->frame_status = 0;
1781 fcb->frame_length = 0;
1782 fcb->info = FCB_CHAIN_END;
1783 fcb->next_ptr = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
1784 if(i == NON_MAC_QUEUE)
1785 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1786 else
1787 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1788
1789 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
1790 {
1791 fcb->next_ptr->back_ptr = fcb;
1792 fcb = fcb->next_ptr;
1793 fcb->frame_status = 0;
1794 fcb->frame_length = 0;
1795 fcb->info = FCB_WARNING;
1796 fcb->next_ptr
1797 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1798
1799 if(i == NON_MAC_QUEUE)
1800 fcb->trc_next_ptr
1801 = RX_FCB_TRC_POINTER(fcb->next_ptr);
1802 else
1803 fcb->trc_next_ptr
1804 = TRC_POINTER(fcb->next_ptr);
1805 }
1806
1807 fcb->next_ptr = tp->rx_fcb_head[i];
1808
1809 if(i == NON_MAC_QUEUE)
1810 fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
1811 else
1812 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1813
1814 tp->rx_fcb_head[i]->back_ptr = fcb;
1815 tp->rx_fcb_curr[i] = tp->rx_fcb_head[i]->next_ptr;
1816 }
1817
Eric Dumazet807540b2010-09-23 05:40:09 +00001818 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819}
1820
1821static int smctr_init_shared_memory(struct net_device *dev)
1822{
1823 struct net_local *tp = netdev_priv(dev);
1824 unsigned int i;
1825 __u32 *iscpb;
1826
1827 if(smctr_debug > 10)
1828 printk(KERN_DEBUG "%s: smctr_init_shared_memory\n", dev->name);
1829
1830 smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
1831
1832 /* Initialize Initial System Configuration Point. (ISCP) */
1833 iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
1834 *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
1835
1836 smctr_set_page(dev, (__u8 *)tp->ram_access);
1837
1838 /* Initialize System Configuration Pointers. (SCP) */
1839 tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
1840 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
1841 | SCGB_BURST_LENGTH);
1842
1843 tp->scgb_ptr->trc_sclb_ptr = TRC_POINTER(tp->sclb_ptr);
1844 tp->scgb_ptr->trc_acb_ptr = TRC_POINTER(tp->acb_head);
1845 tp->scgb_ptr->trc_isb_ptr = TRC_POINTER(tp->isb_ptr);
1846 tp->scgb_ptr->isbsiz = (sizeof(ISBlock)) - 2;
1847
1848 /* Initialize System Control Block. (SCB) */
1849 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_NOP;
1850 tp->sclb_ptr->iack_code = 0;
1851 tp->sclb_ptr->resume_control = 0;
1852 tp->sclb_ptr->int_mask_control = 0;
1853 tp->sclb_ptr->int_mask_state = 0;
1854
1855 /* Initialize Interrupt Status Block. (ISB) */
1856 for(i = 0; i < NUM_OF_INTERRUPTS; i++)
1857 {
1858 tp->isb_ptr->IStatus[i].IType = 0xf0;
1859 tp->isb_ptr->IStatus[i].ISubtype = 0;
1860 }
1861
1862 tp->current_isb_index = 0;
1863
1864 /* Initialize Action Command Block. (ACB) */
1865 smctr_init_acbs(dev);
1866
1867 /* Initialize transmit FCB's and BDB's. */
1868 smctr_link_tx_fcbs_to_bdbs(dev);
1869 smctr_init_tx_bdbs(dev);
1870 smctr_init_tx_fcbs(dev);
1871
1872 /* Initialize receive FCB's and BDB's. */
1873 smctr_init_rx_bdbs(dev);
1874 smctr_init_rx_fcbs(dev);
1875
Eric Dumazet807540b2010-09-23 05:40:09 +00001876 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877}
1878
1879static int smctr_init_tx_bdbs(struct net_device *dev)
1880{
1881 struct net_local *tp = netdev_priv(dev);
1882 unsigned int i, j;
1883 BDBlock *bdb;
1884
1885 for(i = 0; i < NUM_TX_QS_USED; i++)
1886 {
1887 bdb = tp->tx_bdb_head[i];
1888 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1889 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
1890 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1891
1892 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
1893 {
1894 bdb->next_ptr->back_ptr = bdb;
1895 bdb = bdb->next_ptr;
1896 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
1897 bdb->next_ptr
1898 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock)); bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
1899 }
1900
1901 bdb->next_ptr = tp->tx_bdb_head[i];
1902 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
1903 tp->tx_bdb_head[i]->back_ptr = bdb;
1904 }
1905
Eric Dumazet807540b2010-09-23 05:40:09 +00001906 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907}
1908
1909static int smctr_init_tx_fcbs(struct net_device *dev)
1910{
1911 struct net_local *tp = netdev_priv(dev);
1912 unsigned int i, j;
1913 FCBlock *fcb;
1914
1915 for(i = 0; i < NUM_TX_QS_USED; i++)
1916 {
1917 fcb = tp->tx_fcb_head[i];
1918 fcb->frame_status = 0;
1919 fcb->frame_length = 0;
1920 fcb->info = FCB_CHAIN_END;
1921 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1922 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1923
1924 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
1925 {
1926 fcb->next_ptr->back_ptr = fcb;
1927 fcb = fcb->next_ptr;
1928 fcb->frame_status = 0;
1929 fcb->frame_length = 0;
1930 fcb->info = FCB_CHAIN_END;
1931 fcb->next_ptr
1932 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
1933 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
1934 }
1935
1936 fcb->next_ptr = tp->tx_fcb_head[i];
1937 fcb->trc_next_ptr = TRC_POINTER(tp->tx_fcb_head[i]);
1938
1939 tp->tx_fcb_head[i]->back_ptr = fcb;
1940 tp->tx_fcb_end[i] = tp->tx_fcb_head[i]->next_ptr;
1941 tp->tx_fcb_curr[i] = tp->tx_fcb_head[i]->next_ptr;
1942 tp->num_tx_fcbs_used[i] = 0;
1943 }
1944
Eric Dumazet807540b2010-09-23 05:40:09 +00001945 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946}
1947
1948static int smctr_internal_self_test(struct net_device *dev)
1949{
1950 struct net_local *tp = netdev_priv(dev);
1951 int err;
1952
1953 if((err = smctr_issue_test_internal_rom_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001954 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
1956 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001957 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
1959 if(tp->acb_head->cmd_done_status & 0xff)
Eric Dumazet807540b2010-09-23 05:40:09 +00001960 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
1962 if((err = smctr_issue_test_hic_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001963 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
1965 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001966 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
1968 if(tp->acb_head->cmd_done_status & 0xff)
Eric Dumazet807540b2010-09-23 05:40:09 +00001969 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
1971 if((err = smctr_issue_test_mac_reg_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001972 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
1974 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00001975 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
1977 if(tp->acb_head->cmd_done_status & 0xff)
Eric Dumazet807540b2010-09-23 05:40:09 +00001978 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
Eric Dumazet807540b2010-09-23 05:40:09 +00001980 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981}
1982
1983/*
1984 * The typical workload of the driver: Handle the network interface interrupts.
1985 */
David Howells7d12e782006-10-05 14:55:46 +01001986static irqreturn_t smctr_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987{
1988 struct net_device *dev = dev_id;
1989 struct net_local *tp;
1990 int ioaddr;
1991 __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
1992 __u16 err1, err = NOT_MY_INTERRUPT;
1993 __u8 isb_type, isb_subtype;
1994 __u16 isb_index;
1995
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 ioaddr = dev->base_addr;
1997 tp = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998
1999 if(tp->status == NOT_INITIALIZED)
2000 return IRQ_NONE;
2001
2002 spin_lock(&tp->lock);
2003
2004 smctr_disable_bic_int(dev);
2005 smctr_enable_16bit(dev);
2006
2007 smctr_clear_int(dev);
2008
2009 /* First read the LSB */
2010 while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
2011 {
2012 isb_index = tp->current_isb_index;
2013 isb_type = tp->isb_ptr->IStatus[isb_index].IType;
2014 isb_subtype = tp->isb_ptr->IStatus[isb_index].ISubtype;
2015
2016 (tp->current_isb_index)++;
2017 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
2018 tp->current_isb_index = 0;
2019
2020 if(isb_type >= 0x10)
2021 {
2022 smctr_disable_16bit(dev);
2023 spin_unlock(&tp->lock);
2024 return IRQ_HANDLED;
2025 }
2026
2027 err = HARDWARE_FAILED;
2028 interrupt_ack_code = isb_index;
2029 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
2030
2031 interrupt_unmask_bits |= (1 << (__u16)isb_type);
2032
2033 switch(isb_type)
2034 {
2035 case ISB_IMC_MAC_TYPE_3:
2036 smctr_disable_16bit(dev);
2037
2038 switch(isb_subtype)
2039 {
2040 case 0:
2041 tp->monitor_state = MS_MONITOR_FSM_INACTIVE;
2042 break;
2043
2044 case 1:
2045 tp->monitor_state = MS_REPEAT_BEACON_STATE;
2046 break;
2047
2048 case 2:
2049 tp->monitor_state = MS_REPEAT_CLAIM_TOKEN_STATE;
2050 break;
2051
2052 case 3:
2053 tp->monitor_state = MS_TRANSMIT_CLAIM_TOKEN_STATE; break;
2054
2055 case 4:
2056 tp->monitor_state = MS_STANDBY_MONITOR_STATE;
2057 break;
2058
2059 case 5:
2060 tp->monitor_state = MS_TRANSMIT_BEACON_STATE;
2061 break;
2062
2063 case 6:
2064 tp->monitor_state = MS_ACTIVE_MONITOR_STATE;
2065 break;
2066
2067 case 7:
2068 tp->monitor_state = MS_TRANSMIT_RING_PURGE_STATE;
2069 break;
2070
2071 case 8: /* diagnostic state */
2072 break;
2073
2074 case 9:
2075 tp->monitor_state = MS_BEACON_TEST_STATE;
2076 if(smctr_lobe_media_test(dev))
2077 {
2078 tp->ring_status_flags = RING_STATUS_CHANGED;
2079 tp->ring_status = AUTO_REMOVAL_ERROR;
2080 smctr_ring_status_chg(dev);
2081 smctr_bypass_state(dev);
2082 }
2083 else
2084 smctr_issue_insert_cmd(dev);
2085 break;
2086
2087 /* case 0x0a-0xff, illegal states */
2088 default:
2089 break;
2090 }
2091
2092 tp->ring_status_flags = MONITOR_STATE_CHANGED;
2093 err = smctr_ring_status_chg(dev);
2094
2095 smctr_enable_16bit(dev);
2096 break;
2097
2098 /* Type 0x02 - MAC Error Counters Interrupt
2099 * One or more MAC Error Counter is half full
2100 * MAC Error Counters
2101 * Lost_FR_Error_Counter
2102 * RCV_Congestion_Counter
2103 * FR_copied_Error_Counter
2104 * FREQ_Error_Counter
2105 * Token_Error_Counter
2106 * Line_Error_Counter
2107 * Internal_Error_Count
2108 */
2109 case ISB_IMC_MAC_ERROR_COUNTERS:
2110 /* Read 802.5 Error Counters */
2111 err = smctr_issue_read_ring_status_cmd(dev);
2112 break;
2113
2114 /* Type 0x04 - MAC Type 2 Interrupt
2115 * HOST needs to enqueue MAC Frame for transmission
2116 * SubType Bit 15 - RQ_INIT_PDU( Request Initialization) * Changed from RQ_INIT_PDU to
2117 * TRC_Status_Changed_Indicate
2118 */
2119 case ISB_IMC_MAC_TYPE_2:
2120 err = smctr_issue_read_ring_status_cmd(dev);
2121 break;
2122
2123
2124 /* Type 0x05 - TX Frame Interrupt (FI). */
2125 case ISB_IMC_TX_FRAME:
2126 /* BUG QUEUE for TRC stuck receive BUG */
2127 if(isb_subtype & TX_PENDING_PRIORITY_2)
2128 {
2129 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2130 break;
2131 }
2132
2133 /* NON-MAC frames only */
2134 if(isb_subtype & TX_PENDING_PRIORITY_1)
2135 {
2136 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2137 break;
2138 }
2139
2140 /* MAC frames only */
2141 if(isb_subtype & TX_PENDING_PRIORITY_0)
2142 err = smctr_tx_complete(dev, MAC_QUEUE); break;
2143
2144 /* Type 0x06 - TX END OF QUEUE (FE) */
2145 case ISB_IMC_END_OF_TX_QUEUE:
2146 /* BUG queue */
2147 if(isb_subtype & TX_PENDING_PRIORITY_2)
2148 {
2149 /* ok to clear Receive FIFO overrun
2150 * imask send_BUG now completes.
2151 */
2152 interrupt_unmask_bits |= 0x800;
2153
2154 tp->tx_queue_status[BUG_QUEUE] = NOT_TRANSMITING;
2155 if((err = smctr_tx_complete(dev, BUG_QUEUE)) != SUCCESS)
2156 break;
2157 if((err = smctr_restart_tx_chain(dev, BUG_QUEUE)) != SUCCESS)
2158 break;
2159 }
2160
2161 /* NON-MAC queue only */
2162 if(isb_subtype & TX_PENDING_PRIORITY_1)
2163 {
2164 tp->tx_queue_status[NON_MAC_QUEUE] = NOT_TRANSMITING;
2165 if((err = smctr_tx_complete(dev, NON_MAC_QUEUE)) != SUCCESS)
2166 break;
2167 if((err = smctr_restart_tx_chain(dev, NON_MAC_QUEUE)) != SUCCESS)
2168 break;
2169 }
2170
2171 /* MAC queue only */
2172 if(isb_subtype & TX_PENDING_PRIORITY_0)
2173 {
2174 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
2175 if((err = smctr_tx_complete(dev, MAC_QUEUE)) != SUCCESS)
2176 break;
2177
2178 err = smctr_restart_tx_chain(dev, MAC_QUEUE);
2179 }
2180 break;
2181
2182 /* Type 0x07 - NON-MAC RX Resource Interrupt
2183 * Subtype bit 12 - (BW) BDB warning
2184 * Subtype bit 13 - (FW) FCB warning
2185 * Subtype bit 14 - (BE) BDB End of chain
2186 * Subtype bit 15 - (FE) FCB End of chain
2187 */
2188 case ISB_IMC_NON_MAC_RX_RESOURCE:
2189 tp->rx_fifo_overrun_count = 0;
2190 tp->receive_queue_number = NON_MAC_QUEUE;
2191 err1 = smctr_rx_frame(dev);
2192
2193 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
2194 {
2195 if((err = smctr_issue_resume_rx_fcb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2196
2197 if(tp->ptr_rx_fcb_overruns)
2198 (*tp->ptr_rx_fcb_overruns)++;
2199 }
2200
2201 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
2202 {
2203 if((err = smctr_issue_resume_rx_bdb_cmd( dev, NON_MAC_QUEUE)) != SUCCESS) break;
2204
2205 if(tp->ptr_rx_bdb_overruns)
2206 (*tp->ptr_rx_bdb_overruns)++;
2207 }
2208 err = err1;
2209 break;
2210
2211 /* Type 0x08 - MAC RX Resource Interrupt
2212 * Subtype bit 12 - (BW) BDB warning
2213 * Subtype bit 13 - (FW) FCB warning
2214 * Subtype bit 14 - (BE) BDB End of chain
2215 * Subtype bit 15 - (FE) FCB End of chain
2216 */
2217 case ISB_IMC_MAC_RX_RESOURCE:
2218 tp->receive_queue_number = MAC_QUEUE;
2219 err1 = smctr_rx_frame(dev);
2220
2221 if(isb_subtype & MAC_RX_RESOURCE_FE)
2222 {
2223 if((err = smctr_issue_resume_rx_fcb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2224 break;
2225
2226 if(tp->ptr_rx_fcb_overruns)
2227 (*tp->ptr_rx_fcb_overruns)++;
2228 }
2229
2230 if(isb_subtype & MAC_RX_RESOURCE_BE)
2231 {
2232 if((err = smctr_issue_resume_rx_bdb_cmd( dev, MAC_QUEUE)) != SUCCESS)
2233 break;
2234
2235 if(tp->ptr_rx_bdb_overruns)
2236 (*tp->ptr_rx_bdb_overruns)++;
2237 }
2238 err = err1;
2239 break;
2240
2241 /* Type 0x09 - NON_MAC RX Frame Interrupt */
2242 case ISB_IMC_NON_MAC_RX_FRAME:
2243 tp->rx_fifo_overrun_count = 0;
2244 tp->receive_queue_number = NON_MAC_QUEUE;
2245 err = smctr_rx_frame(dev);
2246 break;
2247
2248 /* Type 0x0A - MAC RX Frame Interrupt */
2249 case ISB_IMC_MAC_RX_FRAME:
2250 tp->receive_queue_number = MAC_QUEUE;
2251 err = smctr_rx_frame(dev);
2252 break;
2253
2254 /* Type 0x0B - TRC status
2255 * TRC has encountered an error condition
2256 * subtype bit 14 - transmit FIFO underrun
2257 * subtype bit 15 - receive FIFO overrun
2258 */
2259 case ISB_IMC_TRC_FIFO_STATUS:
2260 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
2261 {
2262 if(tp->ptr_tx_fifo_underruns)
2263 (*tp->ptr_tx_fifo_underruns)++;
2264 }
2265
2266 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
2267 {
2268 /* update overrun stuck receive counter
2269 * if >= 3, has to clear it by sending
2270 * back to back frames. We pick
2271 * DAT(duplicate address MAC frame)
2272 */
2273 tp->rx_fifo_overrun_count++;
2274
2275 if(tp->rx_fifo_overrun_count >= 3)
2276 {
2277 tp->rx_fifo_overrun_count = 0;
2278
2279 /* delay clearing fifo overrun
2280 * imask till send_BUG tx
2281 * complete posted
2282 */
2283 interrupt_unmask_bits &= (~0x800);
2284 printk(KERN_CRIT "Jay please send bug\n");// smctr_send_bug(dev);
2285 }
2286
2287 if(tp->ptr_rx_fifo_overruns)
2288 (*tp->ptr_rx_fifo_overruns)++;
2289 }
2290
2291 err = SUCCESS;
2292 break;
2293
2294 /* Type 0x0C - Action Command Status Interrupt
2295 * Subtype bit 14 - CB end of command chain (CE)
2296 * Subtype bit 15 - CB command interrupt (CI)
2297 */
2298 case ISB_IMC_COMMAND_STATUS:
2299 err = SUCCESS;
2300 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
2301 {
2302 printk(KERN_ERR "i1\n");
2303 smctr_disable_16bit(dev);
2304
2305 /* XXXXXXXXXXXXXXXXX */
2306 /* err = UM_Interrupt(dev); */
2307
2308 smctr_enable_16bit(dev);
2309 }
2310 else
2311 {
2312 if((tp->acb_head->cmd
Joe Perches8e95a202009-12-03 07:58:21 +00002313 == ACB_CMD_READ_TRC_STATUS) &&
2314 (tp->acb_head->subcmd
2315 == RW_TRC_STATUS_BLOCK))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 {
Al Viro79ea13c2008-01-24 02:06:46 -08002317 if(tp->ptr_bcn_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 {
2319 *(tp->ptr_bcn_type)
2320 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
2321 }
2322
2323 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
2324 {
2325 smctr_update_err_stats(dev);
2326 }
2327
2328 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
2329 {
2330 tp->ring_status
2331 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
2332 smctr_disable_16bit(dev);
2333 err = smctr_ring_status_chg(dev);
2334 smctr_enable_16bit(dev);
Joe Perches8e95a202009-12-03 07:58:21 +00002335 if((tp->ring_status & REMOVE_RECEIVED) &&
2336 (tp->config_word0 & NO_AUTOREMOVE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 {
2338 smctr_issue_remove_cmd(dev);
2339 }
2340
2341 if(err != SUCCESS)
2342 {
2343 tp->acb_pending = 0;
2344 break;
2345 }
2346 }
2347
2348 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
2349 {
2350 if(tp->ptr_una)
2351 {
2352 tp->ptr_una[0] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
2353 tp->ptr_una[1] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
2354 tp->ptr_una[2] = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
2355 }
2356
2357 }
2358
2359 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & READY_TO_SEND_RQ_INIT) {
2360 err = smctr_send_rq_init(dev);
2361 }
2362 }
2363 }
2364
2365 tp->acb_pending = 0;
2366 break;
2367
2368 /* Type 0x0D - MAC Type 1 interrupt
2369 * Subtype -- 00 FR_BCN received at S12
2370 * 01 FR_BCN received at S21
2371 * 02 FR_DAT(DA=MA, A<>0) received at S21
2372 * 03 TSM_EXP at S21
2373 * 04 FR_REMOVE received at S42
2374 * 05 TBR_EXP, BR_FLAG_SET at S42
2375 * 06 TBT_EXP at S53
2376 */
2377 case ISB_IMC_MAC_TYPE_1:
2378 if(isb_subtype > 8)
2379 {
2380 err = HARDWARE_FAILED;
2381 break;
2382 }
2383
2384 err = SUCCESS;
2385 switch(isb_subtype)
2386 {
2387 case 0:
2388 tp->join_state = JS_BYPASS_STATE;
2389 if(tp->status != CLOSED)
2390 {
2391 tp->status = CLOSED;
2392 err = smctr_status_chg(dev);
2393 }
2394 break;
2395
2396 case 1:
2397 tp->join_state = JS_LOBE_TEST_STATE;
2398 break;
2399
2400 case 2:
2401 tp->join_state = JS_DETECT_MONITOR_PRESENT_STATE;
2402 break;
2403
2404 case 3:
2405 tp->join_state = JS_AWAIT_NEW_MONITOR_STATE;
2406 break;
2407
2408 case 4:
2409 tp->join_state = JS_DUPLICATE_ADDRESS_TEST_STATE;
2410 break;
2411
2412 case 5:
2413 tp->join_state = JS_NEIGHBOR_NOTIFICATION_STATE;
2414 break;
2415
2416 case 6:
2417 tp->join_state = JS_REQUEST_INITIALIZATION_STATE;
2418 break;
2419
2420 case 7:
2421 tp->join_state = JS_JOIN_COMPLETE_STATE;
2422 tp->status = OPEN;
2423 err = smctr_status_chg(dev);
2424 break;
2425
2426 case 8:
2427 tp->join_state = JS_BYPASS_WAIT_STATE;
2428 break;
2429 }
2430 break ;
2431
2432 /* Type 0x0E - TRC Initialization Sequence Interrupt
2433 * Subtype -- 00-FF Initializatin sequence complete
2434 */
2435 case ISB_IMC_TRC_INTRNL_TST_STATUS:
2436 tp->status = INITIALIZED;
2437 smctr_disable_16bit(dev);
2438 err = smctr_status_chg(dev);
2439 smctr_enable_16bit(dev);
2440 break;
2441
2442 /* other interrupt types, illegal */
2443 default:
2444 break;
2445 }
2446
2447 if(err != SUCCESS)
2448 break;
2449 }
2450
2451 /* Checking the ack code instead of the unmask bits here is because :
2452 * while fixing the stuck receive, DAT frame are sent and mask off
2453 * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
2454 * but we still want to issue ack to ISB
2455 */
2456 if(!(interrupt_ack_code & 0xff00))
2457 smctr_issue_int_ack(dev, interrupt_ack_code, interrupt_unmask_bits);
2458
2459 smctr_disable_16bit(dev);
2460 smctr_enable_bic_int(dev);
2461 spin_unlock(&tp->lock);
2462
2463 return IRQ_HANDLED;
2464}
2465
2466static int smctr_issue_enable_int_cmd(struct net_device *dev,
2467 __u16 interrupt_enable_mask)
2468{
2469 struct net_local *tp = netdev_priv(dev);
2470 int err;
2471
2472 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002473 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 tp->sclb_ptr->int_mask_control = interrupt_enable_mask;
2476 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2477
2478 smctr_set_ctrl_attention(dev);
2479
Eric Dumazet807540b2010-09-23 05:40:09 +00002480 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481}
2482
2483static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code, __u16 ibits)
2484{
2485 struct net_local *tp = netdev_priv(dev);
2486
2487 if(smctr_wait_while_cbusy(dev))
Eric Dumazet807540b2010-09-23 05:40:09 +00002488 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
2490 tp->sclb_ptr->int_mask_control = ibits;
2491 tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */ tp->sclb_ptr->resume_control = 0;
2492 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_IACK_CODE_VALID | SCLB_CMD_CLEAR_INTERRUPT_MASK;
2493
2494 smctr_set_ctrl_attention(dev);
2495
Eric Dumazet807540b2010-09-23 05:40:09 +00002496 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497}
2498
2499static int smctr_issue_init_timers_cmd(struct net_device *dev)
2500{
2501 struct net_local *tp = netdev_priv(dev);
2502 unsigned int i;
2503 int err;
2504 __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
2505
2506 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002507 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
2509 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002510 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
2513 tp->config_word1 = 0;
2514
Joe Perches8e95a202009-12-03 07:58:21 +00002515 if((tp->media_type == MEDIA_STP_16) ||
2516 (tp->media_type == MEDIA_UTP_16) ||
2517 (tp->media_type == MEDIA_STP_16_UTP_16))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 {
2519 tp->config_word0 |= FREQ_16MB_BIT;
2520 }
2521
2522 if(tp->mode_bits & EARLY_TOKEN_REL)
2523 tp->config_word0 |= ETREN;
2524
2525 if(tp->mode_bits & LOOPING_MODE_MASK)
2526 tp->config_word0 |= RX_OWN_BIT;
2527 else
2528 tp->config_word0 &= ~RX_OWN_BIT;
2529
2530 if(tp->receive_mask & PROMISCUOUS_MODE)
2531 tp->config_word0 |= PROMISCUOUS_BIT;
2532 else
2533 tp->config_word0 &= ~PROMISCUOUS_BIT;
2534
2535 if(tp->receive_mask & ACCEPT_ERR_PACKETS)
2536 tp->config_word0 |= SAVBAD_BIT;
2537 else
2538 tp->config_word0 &= ~SAVBAD_BIT;
2539
2540 if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
2541 tp->config_word0 |= RXATMAC;
2542 else
2543 tp->config_word0 &= ~RXATMAC;
2544
2545 if(tp->receive_mask & ACCEPT_MULTI_PROM)
2546 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
2547 else
2548 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
2549
2550 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
2551 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
2552 else
2553 {
2554 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
2555 tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
2556 else
2557 tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
2558 }
2559
Joe Perches8e95a202009-12-03 07:58:21 +00002560 if((tp->media_type == MEDIA_STP_16) ||
2561 (tp->media_type == MEDIA_UTP_16) ||
2562 (tp->media_type == MEDIA_STP_16_UTP_16))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 {
2564 tp->config_word1 |= INTERFRAME_SPACING_16;
2565 }
2566 else
2567 tp->config_word1 |= INTERFRAME_SPACING_4;
2568
2569 *pTimer_Struc++ = tp->config_word0;
2570 *pTimer_Struc++ = tp->config_word1;
2571
Joe Perches8e95a202009-12-03 07:58:21 +00002572 if((tp->media_type == MEDIA_STP_4) ||
2573 (tp->media_type == MEDIA_UTP_4) ||
2574 (tp->media_type == MEDIA_STP_4_UTP_4))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 {
2576 *pTimer_Struc++ = 0x00FA; /* prescale */
2577 *pTimer_Struc++ = 0x2710; /* TPT_limit */
2578 *pTimer_Struc++ = 0x2710; /* TQP_limit */
2579 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2580 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2581 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2582 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2583 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2584 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2585 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2586 *pTimer_Struc++ = 0x1162; /* THT_limit */
2587 *pTimer_Struc++ = 0x07D0; /* TRR_limit */
2588 *pTimer_Struc++ = 0x1388; /* TVX_limit */
2589 *pTimer_Struc++ = 0x0000; /* reserved */
2590 }
2591 else
2592 {
2593 *pTimer_Struc++ = 0x03E8; /* prescale */
2594 *pTimer_Struc++ = 0x9C40; /* TPT_limit */
2595 *pTimer_Struc++ = 0x9C40; /* TQP_limit */
2596 *pTimer_Struc++ = 0x0A28; /* TNT_limit */
2597 *pTimer_Struc++ = 0x3E80; /* TBT_limit */
2598 *pTimer_Struc++ = 0x3A98; /* TSM_limit */
2599 *pTimer_Struc++ = 0x1B58; /* TAM_limit */
2600 *pTimer_Struc++ = 0x00C8; /* TBR_limit */
2601 *pTimer_Struc++ = 0x07D0; /* TER_limit */
2602 *pTimer_Struc++ = 0x000A; /* TGT_limit */
2603 *pTimer_Struc++ = 0x4588; /* THT_limit */
2604 *pTimer_Struc++ = 0x1F40; /* TRR_limit */
2605 *pTimer_Struc++ = 0x4E20; /* TVX_limit */
2606 *pTimer_Struc++ = 0x0000; /* reserved */
2607 }
2608
2609 /* Set node address. */
2610 *pTimer_Struc++ = dev->dev_addr[0] << 8
2611 | (dev->dev_addr[1] & 0xFF);
2612 *pTimer_Struc++ = dev->dev_addr[2] << 8
2613 | (dev->dev_addr[3] & 0xFF);
2614 *pTimer_Struc++ = dev->dev_addr[4] << 8
2615 | (dev->dev_addr[5] & 0xFF);
2616
2617 /* Set group address. */
2618 *pTimer_Struc++ = tp->group_address_0 << 8
2619 | tp->group_address_0 >> 8;
2620 *pTimer_Struc++ = tp->group_address[0] << 8
2621 | tp->group_address[0] >> 8;
2622 *pTimer_Struc++ = tp->group_address[1] << 8
2623 | tp->group_address[1] >> 8;
2624
2625 /* Set functional address. */
2626 *pTimer_Struc++ = tp->functional_address_0 << 8
2627 | tp->functional_address_0 >> 8;
2628 *pTimer_Struc++ = tp->functional_address[0] << 8
2629 | tp->functional_address[0] >> 8;
2630 *pTimer_Struc++ = tp->functional_address[1] << 8
2631 | tp->functional_address[1] >> 8;
2632
2633 /* Set Bit-Wise group address. */
2634 *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
2635 | tp->bitwise_group_address[0] >> 8;
2636 *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
2637 | tp->bitwise_group_address[1] >> 8;
2638
2639 /* Set ring number address. */
2640 *pTimer_Struc++ = tp->source_ring_number;
2641 *pTimer_Struc++ = tp->target_ring_number;
2642
2643 /* Physical drop number. */
2644 *pTimer_Struc++ = (unsigned short)0;
2645 *pTimer_Struc++ = (unsigned short)0;
2646
2647 /* Product instance ID. */
2648 for(i = 0; i < 9; i++)
2649 *pTimer_Struc++ = (unsigned short)0;
2650
2651 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
2652
Eric Dumazet807540b2010-09-23 05:40:09 +00002653 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654}
2655
2656static int smctr_issue_init_txrx_cmd(struct net_device *dev)
2657{
2658 struct net_local *tp = netdev_priv(dev);
2659 unsigned int i;
2660 int err;
2661 void **txrx_ptrs = (void *)tp->misc_command_data;
2662
2663 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002664 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
2666 if((err = smctr_wait_cmd(dev)))
2667 {
2668 printk(KERN_ERR "%s: Hardware failure\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00002669 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 }
2671
2672 /* Initialize Transmit Queue Pointers that are used, to point to
2673 * a single FCB.
2674 */
2675 for(i = 0; i < NUM_TX_QS_USED; i++)
2676 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
2677
2678 /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
2679 for(; i < MAX_TX_QS; i++)
2680 *txrx_ptrs++ = (void *)0;
2681
2682 /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
2683 * used, to point to a single FCB and a BDB chain of buffers.
2684 */
2685 for(i = 0; i < NUM_RX_QS_USED; i++)
2686 {
2687 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
2688 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
2689 }
2690
2691 /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
2692 for(; i < MAX_RX_QS; i++)
2693 {
2694 *txrx_ptrs++ = (void *)0;
2695 *txrx_ptrs++ = (void *)0;
2696 }
2697
2698 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
2699
Eric Dumazet807540b2010-09-23 05:40:09 +00002700 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701}
2702
2703static int smctr_issue_insert_cmd(struct net_device *dev)
2704{
2705 int err;
2706
2707 err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
2708
Eric Dumazet807540b2010-09-23 05:40:09 +00002709 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710}
2711
2712static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
2713{
2714 int err;
2715
2716 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002717 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
2719 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002720 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
2722 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
2723 RW_TRC_STATUS_BLOCK);
2724
Eric Dumazet807540b2010-09-23 05:40:09 +00002725 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726}
2727
2728static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
2729{
2730 int err;
2731
2732 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002733 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
2735 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002736 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
2738 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
2739 aword_cnt);
2740
Eric Dumazet807540b2010-09-23 05:40:09 +00002741 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742}
2743
2744static int smctr_issue_remove_cmd(struct net_device *dev)
2745{
2746 struct net_local *tp = netdev_priv(dev);
2747 int err;
2748
2749 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002750 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
2752 tp->sclb_ptr->resume_control = 0;
2753 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_CMD_REMOVE;
2754
2755 smctr_set_ctrl_attention(dev);
2756
Eric Dumazet807540b2010-09-23 05:40:09 +00002757 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758}
2759
2760static int smctr_issue_resume_acb_cmd(struct net_device *dev)
2761{
2762 struct net_local *tp = netdev_priv(dev);
2763 int err;
2764
2765 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002766 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
2768 tp->sclb_ptr->resume_control = SCLB_RC_ACB;
2769 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2770
2771 tp->acb_pending = 1;
2772
2773 smctr_set_ctrl_attention(dev);
2774
Eric Dumazet807540b2010-09-23 05:40:09 +00002775 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776}
2777
2778static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
2779{
2780 struct net_local *tp = netdev_priv(dev);
2781 int err;
2782
2783 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002784 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785
2786 if(queue == MAC_QUEUE)
2787 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
2788 else
2789 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
2790
2791 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2792
2793 smctr_set_ctrl_attention(dev);
2794
Eric Dumazet807540b2010-09-23 05:40:09 +00002795 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796}
2797
2798static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
2799{
2800 struct net_local *tp = netdev_priv(dev);
2801
2802 if(smctr_debug > 10)
2803 printk(KERN_DEBUG "%s: smctr_issue_resume_rx_fcb_cmd\n", dev->name);
2804
2805 if(smctr_wait_while_cbusy(dev))
Eric Dumazet807540b2010-09-23 05:40:09 +00002806 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 if(queue == MAC_QUEUE)
2809 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
2810 else
2811 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
2812
2813 tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
2814
2815 smctr_set_ctrl_attention(dev);
2816
Eric Dumazet807540b2010-09-23 05:40:09 +00002817 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818}
2819
2820static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
2821{
2822 struct net_local *tp = netdev_priv(dev);
2823
2824 if(smctr_debug > 10)
2825 printk(KERN_DEBUG "%s: smctr_issue_resume_tx_fcb_cmd\n", dev->name);
2826
2827 if(smctr_wait_while_cbusy(dev))
Eric Dumazet807540b2010-09-23 05:40:09 +00002828 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
2830 tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
2831 tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
2832
2833 smctr_set_ctrl_attention(dev);
2834
Eric Dumazet807540b2010-09-23 05:40:09 +00002835 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836}
2837
2838static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
2839{
2840 int err;
2841
2842 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2843 TRC_INTERNAL_ROM_TEST);
2844
Eric Dumazet807540b2010-09-23 05:40:09 +00002845 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846}
2847
2848static int smctr_issue_test_hic_cmd(struct net_device *dev)
2849{
2850 int err;
2851
2852 err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
2853 TRC_HOST_INTERFACE_REG_TEST);
2854
Eric Dumazet807540b2010-09-23 05:40:09 +00002855 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856}
2857
2858static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
2859{
2860 int err;
2861
2862 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2863 TRC_MAC_REGISTERS_TEST);
2864
Eric Dumazet807540b2010-09-23 05:40:09 +00002865 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866}
2867
2868static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
2869{
2870 int err;
2871
2872 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2873 TRC_INTERNAL_LOOPBACK);
2874
Eric Dumazet807540b2010-09-23 05:40:09 +00002875 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876}
2877
2878static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
2879{
2880 int err;
2881
2882 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
2883 TRC_TRI_LOOPBACK);
2884
Eric Dumazet807540b2010-09-23 05:40:09 +00002885 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886}
2887
2888static int smctr_issue_write_byte_cmd(struct net_device *dev,
2889 short aword_cnt, void *byte)
2890{
2891 struct net_local *tp = netdev_priv(dev);
2892 unsigned int iword, ibyte;
2893 int err;
2894
2895 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002896 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
2898 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002899 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
2901 for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
2902 iword++, ibyte += 2)
2903 {
2904 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
2905 | (*((__u8 *)byte + ibyte + 1));
2906 }
2907
Eric Dumazet807540b2010-09-23 05:40:09 +00002908 return smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2909 aword_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910}
2911
2912static int smctr_issue_write_word_cmd(struct net_device *dev,
2913 short aword_cnt, void *word)
2914{
2915 struct net_local *tp = netdev_priv(dev);
2916 unsigned int i, err;
2917
2918 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002919 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920
2921 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00002922 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923
2924 for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
2925 tp->misc_command_data[i] = *((__u16 *)word + i);
2926
2927 err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
2928 aword_cnt);
2929
Eric Dumazet807540b2010-09-23 05:40:09 +00002930 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931}
2932
2933static int smctr_join_complete_state(struct net_device *dev)
2934{
2935 int err;
2936
2937 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
2938 JS_JOIN_COMPLETE_STATE);
2939
Eric Dumazet807540b2010-09-23 05:40:09 +00002940 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941}
2942
2943static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
2944{
2945 struct net_local *tp = netdev_priv(dev);
2946 unsigned int i, j;
2947 FCBlock *fcb;
2948 BDBlock *bdb;
2949
2950 for(i = 0; i < NUM_TX_QS_USED; i++)
2951 {
2952 fcb = tp->tx_fcb_head[i];
2953 bdb = tp->tx_bdb_head[i];
2954
2955 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
2956 {
2957 fcb->bdb_ptr = bdb;
2958 fcb->trc_bdb_ptr = TRC_POINTER(bdb);
2959 fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
2960 bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
2961 }
2962 }
2963
Eric Dumazet807540b2010-09-23 05:40:09 +00002964 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965}
2966
2967static int smctr_load_firmware(struct net_device *dev)
2968{
2969 struct net_local *tp = netdev_priv(dev);
David Woodhouse0f805b82008-05-29 16:39:16 +03002970 const struct firmware *fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 __u16 i, checksum = 0;
2972 int err = 0;
2973
2974 if(smctr_debug > 10)
2975 printk(KERN_DEBUG "%s: smctr_load_firmware\n", dev->name);
2976
David Woodhouse0f805b82008-05-29 16:39:16 +03002977 if (request_firmware(&fw, "tr_smctr.bin", &dev->dev)) {
2978 printk(KERN_ERR "%s: firmware not found\n", dev->name);
Eric Dumazet807540b2010-09-23 05:40:09 +00002979 return UCODE_NOT_PRESENT;
David Woodhouse0f805b82008-05-29 16:39:16 +03002980 }
2981
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 tp->num_of_tx_buffs = 4;
2983 tp->mode_bits |= UMAC;
2984 tp->receive_mask = 0;
2985 tp->max_packet_size = 4177;
2986
2987 /* Can only upload the firmware once per adapter reset. */
David Woodhouse0f805b82008-05-29 16:39:16 +03002988 if (tp->microcode_version != 0) {
2989 err = (UCODE_PRESENT);
2990 goto out;
2991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
2993 /* Verify the firmware exists and is there in the right amount. */
Joe Perches8e95a202009-12-03 07:58:21 +00002994 if (!fw->data ||
2995 (*(fw->data + UCODE_VERSION_OFFSET) < UCODE_VERSION))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 {
David Woodhouse0f805b82008-05-29 16:39:16 +03002997 err = (UCODE_NOT_PRESENT);
2998 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 }
3000
3001 /* UCODE_SIZE is not included in Checksum. */
David Woodhouse0f805b82008-05-29 16:39:16 +03003002 for(i = 0; i < *((__u16 *)(fw->data + UCODE_SIZE_OFFSET)); i += 2)
3003 checksum += *((__u16 *)(fw->data + 2 + i));
3004 if (checksum) {
3005 err = (UCODE_NOT_PRESENT);
3006 goto out;
3007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008
3009 /* At this point we have a valid firmware image, lets kick it on up. */
3010 smctr_enable_adapter_ram(dev);
3011 smctr_enable_16bit(dev);
3012 smctr_set_page(dev, (__u8 *)tp->ram_access);
3013
Joe Perches8e95a202009-12-03 07:58:21 +00003014 if((smctr_checksum_firmware(dev)) ||
3015 (*(fw->data + UCODE_VERSION_OFFSET) > tp->microcode_version))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 {
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);
Eric Dumazet807540b2010-09-23 05:40:09 +00003041 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042}
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
Eric Dumazet807540b2010-09-23 05:40:09 +00003057 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058}
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
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003072 * has any multi-cast or promiscuous bits set, the receive_mask needs to
3073 * be changed to clear the multi-cast or promiscuous mode bits, the lobe_test
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 * 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))
Julia Lawall582b95c2009-08-07 20:47:33 +00003095 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096
3097 /* Tx lobe media test frames. */
3098 for(i = 0; i < 1500; ++i)
3099 {
3100 if(smctr_send_lobe_media_test(dev))
3101 {
3102 if(perror)
Julia Lawall582b95c2009-08-07 20:47:33 +00003103 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 else
3105 {
3106 perror = 1;
3107 if(smctr_lobe_media_test_cmd(dev))
Julia Lawall582b95c2009-08-07 20:47:33 +00003108 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 }
3110 }
3111 }
3112
3113 if(smctr_send_dat(dev))
3114 {
3115 if(smctr_send_dat(dev))
Julia Lawall582b95c2009-08-07 20:47:33 +00003116 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 }
3118
3119 /* Check if any frames received during test. */
Joe Perches8e95a202009-12-03 07:58:21 +00003120 if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status) ||
3121 (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
3122 goto err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
3124 /* Set receive mask to "Promisc" mode. */
3125 tp->receive_mask = saved_rcv_mask;
3126
3127 smctr_chg_rx_mask(dev);
3128
Julia Lawall582b95c2009-08-07 20:47:33 +00003129 return 0;
3130err:
3131 smctr_reset_adapter(dev);
3132 tp->status = CLOSED;
3133 return LOBE_MEDIA_TEST_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134}
3135
3136static int smctr_lobe_media_test_cmd(struct net_device *dev)
3137{
3138 struct net_local *tp = netdev_priv(dev);
3139 int err;
3140
3141 if(smctr_debug > 10)
3142 printk(KERN_DEBUG "%s: smctr_lobe_media_test_cmd\n", dev->name);
3143
3144 /* Change to lobe media test state. */
3145 if(tp->monitor_state != MS_BEACON_TEST_STATE)
3146 {
3147 smctr_lobe_media_test_state(dev);
3148 if(smctr_wait_cmd(dev))
3149 {
3150 printk(KERN_ERR "Lobe Failed test state\n");
Eric Dumazet807540b2010-09-23 05:40:09 +00003151 return LOBE_MEDIA_TEST_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 }
3153 }
3154
3155 err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
3156 TRC_LOBE_MEDIA_TEST);
3157
Eric Dumazet807540b2010-09-23 05:40:09 +00003158 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159}
3160
3161static int smctr_lobe_media_test_state(struct net_device *dev)
3162{
3163 int err;
3164
3165 err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
3166 JS_LOBE_TEST_STATE);
3167
Eric Dumazet807540b2010-09-23 05:40:09 +00003168 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169}
3170
3171static int smctr_make_8025_hdr(struct net_device *dev,
3172 MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
3173{
3174 tmf->ac = MSB(ac_fc); /* msb is access control */
3175 tmf->fc = LSB(ac_fc); /* lsb is frame control */
3176
3177 tmf->sa[0] = dev->dev_addr[0];
3178 tmf->sa[1] = dev->dev_addr[1];
3179 tmf->sa[2] = dev->dev_addr[2];
3180 tmf->sa[3] = dev->dev_addr[3];
3181 tmf->sa[4] = dev->dev_addr[4];
3182 tmf->sa[5] = dev->dev_addr[5];
3183
3184 switch(tmf->vc)
3185 {
3186 /* Send RQ_INIT to RPS */
3187 case RQ_INIT:
3188 tmf->da[0] = 0xc0;
3189 tmf->da[1] = 0x00;
3190 tmf->da[2] = 0x00;
3191 tmf->da[3] = 0x00;
3192 tmf->da[4] = 0x00;
3193 tmf->da[5] = 0x02;
3194 break;
3195
3196 /* Send RPT_TX_FORWARD to CRS */
3197 case RPT_TX_FORWARD:
3198 tmf->da[0] = 0xc0;
3199 tmf->da[1] = 0x00;
3200 tmf->da[2] = 0x00;
3201 tmf->da[3] = 0x00;
3202 tmf->da[4] = 0x00;
3203 tmf->da[5] = 0x10;
3204 break;
3205
3206 /* Everything else goes to sender */
3207 default:
3208 tmf->da[0] = rmf->sa[0];
3209 tmf->da[1] = rmf->sa[1];
3210 tmf->da[2] = rmf->sa[2];
3211 tmf->da[3] = rmf->sa[3];
3212 tmf->da[4] = rmf->sa[4];
3213 tmf->da[5] = rmf->sa[5];
3214 break;
3215 }
3216
Eric Dumazet807540b2010-09-23 05:40:09 +00003217 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218}
3219
3220static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3221{
3222 struct net_local *tp = netdev_priv(dev);
3223
3224 tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
3225 tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
3226
3227 tsv->svv[0] = MSB(tp->authorized_access_priority);
3228 tsv->svv[1] = LSB(tp->authorized_access_priority);
3229
Eric Dumazet807540b2010-09-23 05:40:09 +00003230 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231}
3232
3233static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3234{
3235 tsv->svi = ADDRESS_MODIFER;
3236 tsv->svl = S_ADDRESS_MODIFER;
3237
3238 tsv->svv[0] = 0;
3239 tsv->svv[1] = 0;
3240
Eric Dumazet807540b2010-09-23 05:40:09 +00003241 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242}
3243
3244static int smctr_make_auth_funct_class(struct net_device *dev,
3245 MAC_SUB_VECTOR *tsv)
3246{
3247 struct net_local *tp = netdev_priv(dev);
3248
3249 tsv->svi = AUTHORIZED_FUNCTION_CLASS;
3250 tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
3251
3252 tsv->svv[0] = MSB(tp->authorized_function_classes);
3253 tsv->svv[1] = LSB(tp->authorized_function_classes);
3254
Eric Dumazet807540b2010-09-23 05:40:09 +00003255 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256}
3257
3258static int smctr_make_corr(struct net_device *dev,
3259 MAC_SUB_VECTOR *tsv, __u16 correlator)
3260{
3261 tsv->svi = CORRELATOR;
3262 tsv->svl = S_CORRELATOR;
3263
3264 tsv->svv[0] = MSB(correlator);
3265 tsv->svv[1] = LSB(correlator);
3266
Eric Dumazet807540b2010-09-23 05:40:09 +00003267 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268}
3269
3270static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3271{
3272 struct net_local *tp = netdev_priv(dev);
3273
3274 smctr_get_functional_address(dev);
3275
3276 tsv->svi = FUNCTIONAL_ADDRESS;
3277 tsv->svl = S_FUNCTIONAL_ADDRESS;
3278
3279 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3280 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3281
3282 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3283 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3284
Eric Dumazet807540b2010-09-23 05:40:09 +00003285 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286}
3287
3288static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3289{
3290 struct net_local *tp = netdev_priv(dev);
3291
3292 smctr_get_group_address(dev);
3293
3294 tsv->svi = GROUP_ADDRESS;
3295 tsv->svl = S_GROUP_ADDRESS;
3296
3297 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3298 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3299
3300 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3301 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3302
3303 /* Set Group Address Sub-vector to all zeros if only the
3304 * Group Address/Functional Address Indicator is set.
3305 */
Joe Perches8e95a202009-12-03 07:58:21 +00003306 if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00 &&
3307 tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 tsv->svv[0] = 0x00;
3309
Eric Dumazet807540b2010-09-23 05:40:09 +00003310 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311}
3312
3313static int smctr_make_phy_drop_num(struct net_device *dev,
3314 MAC_SUB_VECTOR *tsv)
3315{
3316 struct net_local *tp = netdev_priv(dev);
3317
3318 smctr_get_physical_drop_number(dev);
3319
3320 tsv->svi = PHYSICAL_DROP;
3321 tsv->svl = S_PHYSICAL_DROP;
3322
3323 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3324 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3325
3326 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3327 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3328
Eric Dumazet807540b2010-09-23 05:40:09 +00003329 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330}
3331
3332static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3333{
3334 int i;
3335
3336 tsv->svi = PRODUCT_INSTANCE_ID;
3337 tsv->svl = S_PRODUCT_INSTANCE_ID;
3338
3339 for(i = 0; i < 18; i++)
3340 tsv->svv[i] = 0xF0;
3341
Eric Dumazet807540b2010-09-23 05:40:09 +00003342 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343}
3344
3345static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3346{
3347 struct net_local *tp = netdev_priv(dev);
3348
3349 smctr_get_station_id(dev);
3350
3351 tsv->svi = STATION_IDENTIFER;
3352 tsv->svl = S_STATION_IDENTIFER;
3353
3354 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3355 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3356
3357 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3358 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3359
3360 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3361 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3362
Eric Dumazet807540b2010-09-23 05:40:09 +00003363 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364}
3365
3366static int smctr_make_ring_station_status(struct net_device *dev,
3367 MAC_SUB_VECTOR * tsv)
3368{
3369 tsv->svi = RING_STATION_STATUS;
3370 tsv->svl = S_RING_STATION_STATUS;
3371
3372 tsv->svv[0] = 0;
3373 tsv->svv[1] = 0;
3374 tsv->svv[2] = 0;
3375 tsv->svv[3] = 0;
3376 tsv->svv[4] = 0;
3377 tsv->svv[5] = 0;
3378
Eric Dumazet807540b2010-09-23 05:40:09 +00003379 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380}
3381
3382static int smctr_make_ring_station_version(struct net_device *dev,
3383 MAC_SUB_VECTOR *tsv)
3384{
3385 struct net_local *tp = netdev_priv(dev);
3386
3387 tsv->svi = RING_STATION_VERSION_NUMBER;
3388 tsv->svl = S_RING_STATION_VERSION_NUMBER;
3389
3390 tsv->svv[0] = 0xe2; /* EBCDIC - S */
3391 tsv->svv[1] = 0xd4; /* EBCDIC - M */
3392 tsv->svv[2] = 0xc3; /* EBCDIC - C */
3393 tsv->svv[3] = 0x40; /* EBCDIC - */
3394 tsv->svv[4] = 0xe5; /* EBCDIC - V */
3395 tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
3396 tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
3397 tsv->svv[7] = 0x40; /* EBCDIC - */
3398 tsv->svv[8] = 0xe7; /* EBCDIC - X */
3399
3400 if(tp->extra_info & CHIP_REV_MASK)
3401 tsv->svv[9] = 0xc5; /* EBCDIC - E */
3402 else
3403 tsv->svv[9] = 0xc4; /* EBCDIC - D */
3404
Eric Dumazet807540b2010-09-23 05:40:09 +00003405 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406}
3407
3408static int smctr_make_tx_status_code(struct net_device *dev,
3409 MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
3410{
3411 tsv->svi = TRANSMIT_STATUS_CODE;
3412 tsv->svl = S_TRANSMIT_STATUS_CODE;
3413
Jay Schulist26c080b2008-03-18 17:53:09 -04003414 tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) | IBM_PASS_SOURCE_ADDR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
3416 /* Stripped frame status of Transmitted Frame */
3417 tsv->svv[1] = tx_fstatus & 0xff;
3418
Eric Dumazet807540b2010-09-23 05:40:09 +00003419 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420}
3421
3422static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
3423 MAC_SUB_VECTOR *tsv)
3424{
3425 struct net_local *tp = netdev_priv(dev);
3426
3427 smctr_get_upstream_neighbor_addr(dev);
3428
3429 tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
3430 tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
3431
3432 tsv->svv[0] = MSB(tp->misc_command_data[0]);
3433 tsv->svv[1] = LSB(tp->misc_command_data[0]);
3434
3435 tsv->svv[2] = MSB(tp->misc_command_data[1]);
3436 tsv->svv[3] = LSB(tp->misc_command_data[1]);
3437
3438 tsv->svv[4] = MSB(tp->misc_command_data[2]);
3439 tsv->svv[5] = LSB(tp->misc_command_data[2]);
3440
Eric Dumazet807540b2010-09-23 05:40:09 +00003441 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442}
3443
3444static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
3445{
3446 tsv->svi = WRAP_DATA;
3447 tsv->svl = S_WRAP_DATA;
3448
Eric Dumazet807540b2010-09-23 05:40:09 +00003449 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450}
3451
3452/*
3453 * Open/initialize the board. This is called sometime after
3454 * booting when the 'ifconfig' program is run.
3455 *
3456 * This routine should set everything up anew at each open, even
3457 * registers that "should" only need to be set once at boot, so that
3458 * there is non-reboot way to recover if something goes wrong.
3459 */
3460static int smctr_open(struct net_device *dev)
3461{
3462 int err;
3463
3464 if(smctr_debug > 10)
3465 printk(KERN_DEBUG "%s: smctr_open\n", dev->name);
3466
3467 err = smctr_init_adapter(dev);
3468 if(err < 0)
Eric Dumazet807540b2010-09-23 05:40:09 +00003469 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
Eric Dumazet807540b2010-09-23 05:40:09 +00003471 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472}
3473
3474/* Interrupt driven open of Token card. */
3475static int smctr_open_tr(struct net_device *dev)
3476{
3477 struct net_local *tp = netdev_priv(dev);
3478 unsigned long flags;
3479 int err;
3480
3481 if(smctr_debug > 10)
3482 printk(KERN_DEBUG "%s: smctr_open_tr\n", dev->name);
3483
3484 /* Now we can actually open the adapter. */
3485 if(tp->status == OPEN)
Eric Dumazet807540b2010-09-23 05:40:09 +00003486 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487 if(tp->status != INITIALIZED)
Eric Dumazet807540b2010-09-23 05:40:09 +00003488 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
3490 /* FIXME: it would work a lot better if we masked the irq sources
3491 on the card here, then we could skip the locking and poll nicely */
3492 spin_lock_irqsave(&tp->lock, flags);
3493
3494 smctr_set_page(dev, (__u8 *)tp->ram_access);
3495
3496 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
3497 goto out;
3498
3499 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
3500 goto out;
3501
3502 if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
3503 goto out;
3504
3505 if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
3506 goto out;
3507
3508 tp->status = CLOSED;
3509
3510 /* Insert into the Ring or Enter Loopback Mode. */
3511 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
3512 {
3513 tp->status = CLOSED;
3514
3515 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
3516 {
3517 if(!(err = smctr_wait_cmd(dev)))
3518 tp->status = OPEN;
3519 }
3520
3521 smctr_status_chg(dev);
3522 }
3523 else
3524 {
3525 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
3526 {
3527 tp->status = CLOSED;
3528 if(!(err = smctr_issue_tri_loopback_cmd(dev)))
3529 {
3530 if(!(err = smctr_wait_cmd(dev)))
3531 tp->status = OPEN;
3532 }
3533
3534 smctr_status_chg(dev);
3535 }
3536 else
3537 {
3538 if((tp->mode_bits & LOOPING_MODE_MASK)
3539 == LOOPBACK_MODE_3)
3540 {
3541 tp->status = CLOSED;
3542 if(!(err = smctr_lobe_media_test_cmd(dev)))
3543 {
3544 if(!(err = smctr_wait_cmd(dev)))
3545 tp->status = OPEN;
3546 }
3547 smctr_status_chg(dev);
3548 }
3549 else
3550 {
3551 if(!(err = smctr_lobe_media_test(dev)))
3552 err = smctr_issue_insert_cmd(dev);
3553 else
3554 {
3555 if(err == LOBE_MEDIA_TEST_FAILED)
3556 printk(KERN_WARNING "%s: Lobe Media Test Failure - Check cable?\n", dev->name);
3557 }
3558 }
3559 }
3560 }
3561
3562out:
3563 spin_unlock_irqrestore(&tp->lock, flags);
3564
Eric Dumazet807540b2010-09-23 05:40:09 +00003565 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566}
3567
3568/* Check for a network adapter of this type,
3569 * and return device structure if one exists.
3570 */
3571struct net_device __init *smctr_probe(int unit)
3572{
3573 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
3574 static const unsigned ports[] = {
3575 0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
3576 0x320, 0x340, 0x360, 0x380, 0
3577 };
3578 const unsigned *port;
3579 int err = 0;
3580
3581 if (!dev)
3582 return ERR_PTR(-ENOMEM);
3583
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 if (unit >= 0) {
3585 sprintf(dev->name, "tr%d", unit);
3586 netdev_boot_setup_check(dev);
3587 }
3588
3589 if (dev->base_addr > 0x1ff) /* Check a single specified location. */
3590 err = smctr_probe1(dev, dev->base_addr);
3591 else if(dev->base_addr != 0) /* Don't probe at all. */
3592 err =-ENXIO;
3593 else {
3594 for (port = ports; *port; port++) {
3595 err = smctr_probe1(dev, *port);
3596 if (!err)
3597 break;
3598 }
3599 }
3600 if (err)
3601 goto out;
3602 err = register_netdev(dev);
3603 if (err)
3604 goto out1;
3605 return dev;
3606out1:
3607#ifdef CONFIG_MCA_LEGACY
3608 { struct net_local *tp = netdev_priv(dev);
3609 if (tp->slot_num)
3610 mca_mark_as_unused(tp->slot_num);
3611 }
3612#endif
3613 release_region(dev->base_addr, SMCTR_IO_EXTENT);
3614 free_irq(dev->irq, dev);
3615out:
3616 free_netdev(dev);
3617 return ERR_PTR(err);
3618}
3619
Stephen Hemmingerf70d5942009-03-26 15:11:24 +00003620static const struct net_device_ops smctr_netdev_ops = {
3621 .ndo_open = smctr_open,
3622 .ndo_stop = smctr_close,
3623 .ndo_start_xmit = smctr_send_packet,
3624 .ndo_tx_timeout = smctr_timeout,
3625 .ndo_get_stats = smctr_get_stats,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003626 .ndo_set_rx_mode = smctr_set_multicast_list,
Stephen Hemmingerf70d5942009-03-26 15:11:24 +00003627};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628
3629static int __init smctr_probe1(struct net_device *dev, int ioaddr)
3630{
3631 static unsigned version_printed;
3632 struct net_local *tp = netdev_priv(dev);
3633 int err;
3634 __u32 *ram;
3635
3636 if(smctr_debug && version_printed++ == 0)
3637 printk(version);
3638
3639 spin_lock_init(&tp->lock);
3640 dev->base_addr = ioaddr;
3641
3642 /* Actually detect an adapter now. */
3643 err = smctr_chk_isa(dev);
3644 if(err < 0)
3645 {
3646 if ((err = smctr_chk_mca(dev)) < 0) {
3647 err = -ENODEV;
3648 goto out;
3649 }
3650 }
3651
3652 tp = netdev_priv(dev);
3653 dev->mem_start = tp->ram_base;
3654 dev->mem_end = dev->mem_start + 0x10000;
3655 ram = (__u32 *)phys_to_virt(dev->mem_start);
3656 tp->ram_access = *(__u32 *)&ram;
3657 tp->status = NOT_INITIALIZED;
3658
3659 err = smctr_load_firmware(dev);
3660 if(err != UCODE_PRESENT && err != SUCCESS)
3661 {
3662 printk(KERN_ERR "%s: Firmware load failed (%d)\n", dev->name, err);
3663 err = -EIO;
3664 goto out;
3665 }
3666
3667 /* Allow user to specify ring speed on module insert. */
3668 if(ringspeed == 4)
3669 tp->media_type = MEDIA_UTP_4;
3670 else
3671 tp->media_type = MEDIA_UTP_16;
3672
3673 printk(KERN_INFO "%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.\n",
3674 dev->name, smctr_name, smctr_model,
3675 (unsigned int)dev->base_addr,
3676 dev->irq, tp->rom_base, tp->ram_base);
3677
Stephen Hemmingerf70d5942009-03-26 15:11:24 +00003678 dev->netdev_ops = &smctr_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679 dev->watchdog_timeo = HZ;
Eric Dumazet807540b2010-09-23 05:40:09 +00003680 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681
3682out:
3683 return err;
3684}
3685
3686static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
3687 struct net_device *dev, __u16 rx_status)
3688{
3689 struct net_local *tp = netdev_priv(dev);
3690 struct sk_buff *skb;
3691 __u16 rcode, correlator;
3692 int err = 0;
3693 __u8 xframe = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003694
3695 rmf->vl = SWAP_BYTES(rmf->vl);
3696 if(rx_status & FCB_RX_STATUS_DA_MATCHED)
3697 {
3698 switch(rmf->vc)
3699 {
3700 /* Received MAC Frames Processed by RS. */
3701 case INIT:
3702 if((rcode = smctr_rcv_init(dev, rmf, &correlator)) == HARDWARE_FAILED)
3703 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003704 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 }
3706
3707 if((err = smctr_send_rsp(dev, rmf, rcode,
3708 correlator)))
3709 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003710 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 }
3712 break;
3713
3714 case CHG_PARM:
3715 if((rcode = smctr_rcv_chg_param(dev, rmf,
3716 &correlator)) ==HARDWARE_FAILED)
3717 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003718 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 }
3720
3721 if((err = smctr_send_rsp(dev, rmf, rcode,
3722 correlator)))
3723 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003724 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003725 }
3726 break;
3727
3728 case RQ_ADDR:
3729 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3730 rmf, &correlator)) != POSITIVE_ACK)
3731 {
3732 if(rcode == HARDWARE_FAILED)
Eric Dumazet807540b2010-09-23 05:40:09 +00003733 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 else
Eric Dumazet807540b2010-09-23 05:40:09 +00003735 return smctr_send_rsp(dev, rmf,
3736 rcode, correlator);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003737 }
3738
3739 if((err = smctr_send_rpt_addr(dev, rmf,
3740 correlator)))
3741 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003742 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 }
3744 break;
3745
3746 case RQ_ATTCH:
3747 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3748 rmf, &correlator)) != POSITIVE_ACK)
3749 {
3750 if(rcode == HARDWARE_FAILED)
Eric Dumazet807540b2010-09-23 05:40:09 +00003751 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 else
Eric Dumazet807540b2010-09-23 05:40:09 +00003753 return smctr_send_rsp(dev, rmf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 rcode,
Eric Dumazet807540b2010-09-23 05:40:09 +00003755 correlator);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 }
3757
3758 if((err = smctr_send_rpt_attch(dev, rmf,
3759 correlator)))
3760 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003761 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 }
3763 break;
3764
3765 case RQ_STATE:
3766 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
3767 rmf, &correlator)) != POSITIVE_ACK)
3768 {
3769 if(rcode == HARDWARE_FAILED)
Eric Dumazet807540b2010-09-23 05:40:09 +00003770 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 else
Eric Dumazet807540b2010-09-23 05:40:09 +00003772 return smctr_send_rsp(dev, rmf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 rcode,
Eric Dumazet807540b2010-09-23 05:40:09 +00003774 correlator);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 }
3776
3777 if((err = smctr_send_rpt_state(dev, rmf,
3778 correlator)))
3779 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003780 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 }
3782 break;
3783
Jeff Garzika6343af2007-07-17 05:39:58 -04003784 case TX_FORWARD: {
3785 __u16 uninitialized_var(tx_fstatus);
3786
Linus Torvalds1da177e2005-04-16 15:20:36 -07003787 if((rcode = smctr_rcv_tx_forward(dev, rmf))
3788 != POSITIVE_ACK)
3789 {
3790 if(rcode == HARDWARE_FAILED)
Eric Dumazet807540b2010-09-23 05:40:09 +00003791 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 else
Eric Dumazet807540b2010-09-23 05:40:09 +00003793 return smctr_send_rsp(dev, rmf,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 rcode,
Eric Dumazet807540b2010-09-23 05:40:09 +00003795 correlator);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 }
3797
3798 if((err = smctr_send_tx_forward(dev, rmf,
3799 &tx_fstatus)) == HARDWARE_FAILED)
3800 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003801 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802 }
3803
3804 if(err == A_FRAME_WAS_FORWARDED)
3805 {
3806 if((err = smctr_send_rpt_tx_forward(dev,
3807 rmf, tx_fstatus))
3808 == HARDWARE_FAILED)
3809 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003810 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 }
3812 }
3813 break;
Jeff Garzika6343af2007-07-17 05:39:58 -04003814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815
3816 /* Received MAC Frames Processed by CRS/REM/RPS. */
3817 case RSP:
3818 case RQ_INIT:
3819 case RPT_NEW_MON:
3820 case RPT_SUA_CHG:
3821 case RPT_ACTIVE_ERR:
3822 case RPT_NN_INCMP:
3823 case RPT_ERROR:
3824 case RPT_ATTCH:
3825 case RPT_STATE:
3826 case RPT_ADDR:
3827 break;
3828
3829 /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
3830 default:
3831 xframe = 0;
3832 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
3833 {
3834 rcode = smctr_rcv_unknown(dev, rmf,
3835 &correlator);
3836 if((err = smctr_send_rsp(dev, rmf,rcode,
3837 correlator)))
3838 {
Eric Dumazet807540b2010-09-23 05:40:09 +00003839 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 }
3841 }
3842
3843 break;
3844 }
3845 }
3846 else
3847 {
3848 /* 1. DA doesn't match (Promiscuous Mode).
3849 * 2. Parse for Extended MAC Frame Type.
3850 */
3851 switch(rmf->vc)
3852 {
3853 case RSP:
3854 case INIT:
3855 case RQ_INIT:
3856 case RQ_ADDR:
3857 case RQ_ATTCH:
3858 case RQ_STATE:
3859 case CHG_PARM:
3860 case RPT_ADDR:
3861 case RPT_ERROR:
3862 case RPT_ATTCH:
3863 case RPT_STATE:
3864 case RPT_NEW_MON:
3865 case RPT_SUA_CHG:
3866 case RPT_NN_INCMP:
3867 case RPT_ACTIVE_ERR:
3868 break;
3869
3870 default:
3871 xframe = 0;
3872 break;
3873 }
3874 }
3875
3876 /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
3877 * ACCEPT_ATT_MAC_FRAMES is set.
3878 */
Joe Perches8e95a202009-12-03 07:58:21 +00003879 if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES) &&
3880 (xframe == (__u8)0)) ||
3881 ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES) &&
3882 (xframe == (__u8)1)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 {
3884 rmf->vl = SWAP_BYTES(rmf->vl);
3885
3886 if (!(skb = dev_alloc_skb(size)))
3887 return -ENOMEM;
3888 skb->len = size;
3889
3890 /* Slide data into a sleek skb. */
3891 skb_put(skb, skb->len);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03003892 skb_copy_to_linear_data(skb, rmf, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893
3894 /* Update Counters */
3895 tp->MacStat.rx_packets++;
3896 tp->MacStat.rx_bytes += skb->len;
3897
3898 /* Kick the packet on up. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 skb->protocol = tr_type_trans(skb, dev);
3900 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003901 err = 0;
3902 }
3903
Eric Dumazet807540b2010-09-23 05:40:09 +00003904 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905}
3906
3907/* Adapter RAM test. Incremental word ODD boundary data test. */
3908static int smctr_ram_memory_test(struct net_device *dev)
3909{
3910 struct net_local *tp = netdev_priv(dev);
3911 __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
3912 word_read = 0, err_word = 0, err_pattern = 0;
3913 unsigned int err_offset;
3914 __u32 j, pword;
3915 __u8 err = 0;
3916
3917 if(smctr_debug > 10)
3918 printk(KERN_DEBUG "%s: smctr_ram_memory_test\n", dev->name);
3919
3920 start_pattern = 0x0001;
3921 pages_of_ram = tp->ram_size / tp->ram_usable;
3922 pword = tp->ram_access;
3923
3924 /* Incremental word ODD boundary test. */
3925 for(page = 0; (page < pages_of_ram) && (~err);
3926 page++, start_pattern += 0x8000)
3927 {
3928 smctr_set_page(dev, (__u8 *)(tp->ram_access
3929 + (page * tp->ram_usable * 1024) + 1));
3930 word_pattern = start_pattern;
3931
3932 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
3933 *(__u16 *)(pword + j) = word_pattern++;
3934
3935 word_pattern = start_pattern;
3936
Joe Perches8e95a202009-12-03 07:58:21 +00003937 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1 && (~err);
3938 j += 2, word_pattern++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939 {
3940 word_read = *(__u16 *)(pword + j);
3941 if(word_read != word_pattern)
3942 {
3943 err = (__u8)1;
3944 err_offset = j;
3945 err_word = word_read;
3946 err_pattern = word_pattern;
Eric Dumazet807540b2010-09-23 05:40:09 +00003947 return RAM_TEST_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 }
3949 }
3950 }
3951
3952 /* Zero out memory. */
3953 for(page = 0; page < pages_of_ram && (~err); page++)
3954 {
3955 smctr_set_page(dev, (__u8 *)(tp->ram_access
3956 + (page * tp->ram_usable * 1024)));
3957 word_pattern = 0;
3958
3959 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
3960 *(__u16 *)(pword + j) = word_pattern;
3961
Joe Perches8e95a202009-12-03 07:58:21 +00003962 for(j =0; j < (__u32)tp->ram_usable * 1024 && (~err); j += 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 {
3964 word_read = *(__u16 *)(pword + j);
3965 if(word_read != word_pattern)
3966 {
3967 err = (__u8)1;
3968 err_offset = j;
3969 err_word = word_read;
3970 err_pattern = word_pattern;
Eric Dumazet807540b2010-09-23 05:40:09 +00003971 return RAM_TEST_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 }
3973 }
3974 }
3975
3976 smctr_set_page(dev, (__u8 *)tp->ram_access);
3977
Eric Dumazet807540b2010-09-23 05:40:09 +00003978 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979}
3980
3981static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
3982 __u16 *correlator)
3983{
3984 MAC_SUB_VECTOR *rsv;
3985 signed short vlen;
3986 __u16 rcode = POSITIVE_ACK;
3987 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
3988
3989 /* This Frame can only come from a CRS */
3990 if((rmf->dc_sc & SC_MASK) != SC_CRS)
Eric Dumazet807540b2010-09-23 05:40:09 +00003991 return E_INAPPROPRIATE_SOURCE_CLASS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992
3993 /* Remove MVID Length from total length. */
3994 vlen = (signed short)rmf->vl - 4;
3995
3996 /* Point to First SVID */
3997 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
3998
3999 /* Search for Appropriate SVID's. */
4000 while((vlen > 0) && (rcode == POSITIVE_ACK))
4001 {
4002 switch(rsv->svi)
4003 {
4004 case CORRELATOR:
4005 svectors |= F_CORRELATOR;
4006 rcode = smctr_set_corr(dev, rsv, correlator);
4007 break;
4008
4009 case LOCAL_RING_NUMBER:
4010 svectors |= F_LOCAL_RING_NUMBER;
4011 rcode = smctr_set_local_ring_num(dev, rsv);
4012 break;
4013
4014 case ASSIGN_PHYSICAL_DROP:
4015 svectors |= F_ASSIGN_PHYSICAL_DROP;
4016 rcode = smctr_set_phy_drop(dev, rsv);
4017 break;
4018
4019 case ERROR_TIMER_VALUE:
4020 svectors |= F_ERROR_TIMER_VALUE;
4021 rcode = smctr_set_error_timer_value(dev, rsv);
4022 break;
4023
4024 case AUTHORIZED_FUNCTION_CLASS:
4025 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
4026 rcode = smctr_set_auth_funct_class(dev, rsv);
4027 break;
4028
4029 case AUTHORIZED_ACCESS_PRIORITY:
4030 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
4031 rcode = smctr_set_auth_access_pri(dev, rsv);
4032 break;
4033
4034 default:
4035 rcode = E_SUB_VECTOR_UNKNOWN;
4036 break;
4037 }
4038
4039 /* Let Sender Know if SUM of SV length's is
4040 * larger then length in MVID length field
4041 */
4042 if((vlen -= rsv->svl) < 0)
4043 rcode = E_VECTOR_LENGTH_ERROR;
4044
4045 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4046 }
4047
4048 if(rcode == POSITIVE_ACK)
4049 {
4050 /* Let Sender Know if MVID length field
4051 * is larger then SUM of SV length's
4052 */
4053 if(vlen != 0)
4054 rcode = E_VECTOR_LENGTH_ERROR;
4055 else
4056 {
4057 /* Let Sender Know if Expected SVID Missing */
4058 if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
4059 rcode = E_MISSING_SUB_VECTOR;
4060 }
4061 }
4062
Eric Dumazet807540b2010-09-23 05:40:09 +00004063 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064}
4065
4066static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
4067 __u16 *correlator)
4068{
4069 MAC_SUB_VECTOR *rsv;
4070 signed short vlen;
4071 __u16 rcode = POSITIVE_ACK;
4072 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4073
4074 /* This Frame can only come from a RPS */
4075 if((rmf->dc_sc & SC_MASK) != SC_RPS)
Eric Dumazet807540b2010-09-23 05:40:09 +00004076 return E_INAPPROPRIATE_SOURCE_CLASS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077
4078 /* Remove MVID Length from total length. */
4079 vlen = (signed short)rmf->vl - 4;
4080
4081 /* Point to First SVID */
4082 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4083
4084 /* Search for Appropriate SVID's */
4085 while((vlen > 0) && (rcode == POSITIVE_ACK))
4086 {
4087 switch(rsv->svi)
4088 {
4089 case CORRELATOR:
4090 svectors |= F_CORRELATOR;
4091 rcode = smctr_set_corr(dev, rsv, correlator);
4092 break;
4093
4094 case LOCAL_RING_NUMBER:
4095 svectors |= F_LOCAL_RING_NUMBER;
4096 rcode = smctr_set_local_ring_num(dev, rsv);
4097 break;
4098
4099 case ASSIGN_PHYSICAL_DROP:
4100 svectors |= F_ASSIGN_PHYSICAL_DROP;
4101 rcode = smctr_set_phy_drop(dev, rsv);
4102 break;
4103
4104 case ERROR_TIMER_VALUE:
4105 svectors |= F_ERROR_TIMER_VALUE;
4106 rcode = smctr_set_error_timer_value(dev, rsv);
4107 break;
4108
4109 default:
4110 rcode = E_SUB_VECTOR_UNKNOWN;
4111 break;
4112 }
4113
4114 /* Let Sender Know if SUM of SV length's is
4115 * larger then length in MVID length field
4116 */
4117 if((vlen -= rsv->svl) < 0)
4118 rcode = E_VECTOR_LENGTH_ERROR;
4119
4120 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4121 }
4122
4123 if(rcode == POSITIVE_ACK)
4124 {
4125 /* Let Sender Know if MVID length field
4126 * is larger then SUM of SV length's
4127 */
4128 if(vlen != 0)
4129 rcode = E_VECTOR_LENGTH_ERROR;
4130 else
4131 {
4132 /* Let Sender Know if Expected SV Missing */
4133 if((svectors & R_INIT) ^ R_INIT)
4134 rcode = E_MISSING_SUB_VECTOR;
4135 }
4136 }
4137
Eric Dumazet807540b2010-09-23 05:40:09 +00004138 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139}
4140
4141static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
4142{
4143 MAC_SUB_VECTOR *rsv;
4144 signed short vlen;
4145 __u16 rcode = POSITIVE_ACK;
4146 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4147
4148 /* This Frame can only come from a CRS */
4149 if((rmf->dc_sc & SC_MASK) != SC_CRS)
Eric Dumazet807540b2010-09-23 05:40:09 +00004150 return E_INAPPROPRIATE_SOURCE_CLASS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151
4152 /* Remove MVID Length from total length */
4153 vlen = (signed short)rmf->vl - 4;
4154
4155 /* Point to First SVID */
4156 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4157
4158 /* Search for Appropriate SVID's */
4159 while((vlen > 0) && (rcode == POSITIVE_ACK))
4160 {
4161 switch(rsv->svi)
4162 {
4163 case FRAME_FORWARD:
4164 svectors |= F_FRAME_FORWARD;
4165 rcode = smctr_set_frame_forward(dev, rsv,
4166 rmf->dc_sc);
4167 break;
4168
4169 default:
4170 rcode = E_SUB_VECTOR_UNKNOWN;
4171 break;
4172 }
4173
4174 /* Let Sender Know if SUM of SV length's is
4175 * larger then length in MVID length field
4176 */
4177 if((vlen -= rsv->svl) < 0)
4178 rcode = E_VECTOR_LENGTH_ERROR;
4179
4180 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4181 }
4182
4183 if(rcode == POSITIVE_ACK)
4184 {
4185 /* Let Sender Know if MVID length field
4186 * is larger then SUM of SV length's
4187 */
4188 if(vlen != 0)
4189 rcode = E_VECTOR_LENGTH_ERROR;
4190 else
4191 {
4192 /* Let Sender Know if Expected SV Missing */
4193 if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
4194 rcode = E_MISSING_SUB_VECTOR;
4195 }
4196 }
4197
Eric Dumazet807540b2010-09-23 05:40:09 +00004198 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199}
4200
4201static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
4202 MAC_HEADER *rmf, __u16 *correlator)
4203{
4204 MAC_SUB_VECTOR *rsv;
4205 signed short vlen;
4206 __u16 rcode = POSITIVE_ACK;
4207 unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
4208
4209 /* Remove MVID Length from total length */
4210 vlen = (signed short)rmf->vl - 4;
4211
4212 /* Point to First SVID */
4213 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4214
4215 /* Search for Appropriate SVID's */
4216 while((vlen > 0) && (rcode == POSITIVE_ACK))
4217 {
4218 switch(rsv->svi)
4219 {
4220 case CORRELATOR:
4221 svectors |= F_CORRELATOR;
4222 rcode = smctr_set_corr(dev, rsv, correlator);
4223 break;
4224
4225 default:
4226 rcode = E_SUB_VECTOR_UNKNOWN;
4227 break;
4228 }
4229
4230 /* Let Sender Know if SUM of SV length's is
4231 * larger then length in MVID length field
4232 */
4233 if((vlen -= rsv->svl) < 0)
4234 rcode = E_VECTOR_LENGTH_ERROR;
4235
4236 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4237 }
4238
4239 if(rcode == POSITIVE_ACK)
4240 {
4241 /* Let Sender Know if MVID length field
4242 * is larger then SUM of SV length's
4243 */
4244 if(vlen != 0)
4245 rcode = E_VECTOR_LENGTH_ERROR;
4246 else
4247 {
4248 /* Let Sender Know if Expected SVID Missing */
4249 if((svectors & R_RQ_ATTCH_STATE_ADDR)
4250 ^ R_RQ_ATTCH_STATE_ADDR)
4251 rcode = E_MISSING_SUB_VECTOR;
4252 }
4253 }
4254
Eric Dumazet807540b2010-09-23 05:40:09 +00004255 return rcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256}
4257
4258static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
4259 __u16 *correlator)
4260{
4261 MAC_SUB_VECTOR *rsv;
4262 signed short vlen;
4263
4264 *correlator = 0;
4265
4266 /* Remove MVID Length from total length */
4267 vlen = (signed short)rmf->vl - 4;
4268
4269 /* Point to First SVID */
4270 rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
4271
4272 /* Search for CORRELATOR for RSP to UNKNOWN */
4273 while((vlen > 0) && (*correlator == 0))
4274 {
4275 switch(rsv->svi)
4276 {
4277 case CORRELATOR:
4278 smctr_set_corr(dev, rsv, correlator);
4279 break;
4280
4281 default:
4282 break;
4283 }
4284
4285 vlen -= rsv->svl;
4286 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
4287 }
4288
Eric Dumazet807540b2010-09-23 05:40:09 +00004289 return E_UNRECOGNIZED_VECTOR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290}
4291
4292/*
4293 * Reset the 825 NIC and exit w:
4294 * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
4295 * 2. TINT masked.
4296 * 3. CBUSY masked.
4297 * 4. TINT clear.
4298 * 5. CBUSY clear.
4299 */
4300static int smctr_reset_adapter(struct net_device *dev)
4301{
4302 struct net_local *tp = netdev_priv(dev);
4303 int ioaddr = dev->base_addr;
4304
4305 /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
4306 mdelay(200); /* ~2 ms */
4307
4308 smctr_clear_trc_reset(ioaddr);
4309 mdelay(200); /* ~2 ms */
4310
4311 /* Remove any latched interrupts that occurred prior to reseting the
4312 * adapter or possibily caused by line glitches due to the reset.
4313 */
4314 outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
4315
Eric Dumazet807540b2010-09-23 05:40:09 +00004316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317}
4318
4319static int smctr_restart_tx_chain(struct net_device *dev, short queue)
4320{
4321 struct net_local *tp = netdev_priv(dev);
4322 int err = 0;
4323
4324 if(smctr_debug > 10)
4325 printk(KERN_DEBUG "%s: smctr_restart_tx_chain\n", dev->name);
4326
Joe Perches8e95a202009-12-03 07:58:21 +00004327 if(tp->num_tx_fcbs_used[queue] != 0 &&
4328 tp->tx_queue_status[queue] == NOT_TRANSMITING)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329 {
4330 tp->tx_queue_status[queue] = TRANSMITING;
4331 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
4332 }
4333
Eric Dumazet807540b2010-09-23 05:40:09 +00004334 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335}
4336
4337static int smctr_ring_status_chg(struct net_device *dev)
4338{
4339 struct net_local *tp = netdev_priv(dev);
4340
4341 if(smctr_debug > 10)
4342 printk(KERN_DEBUG "%s: smctr_ring_status_chg\n", dev->name);
4343
4344 /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
4345 * Bit is set, check value of monitor_state, only then we
4346 * enable and start transmit/receive timeout (if and only
4347 * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
4348 */
4349 if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
4350 {
Joe Perches8e95a202009-12-03 07:58:21 +00004351 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE) ||
4352 (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353 {
4354 tp->monitor_state_ready = 1;
4355 }
4356 else
4357 {
4358 /* if adapter is NOT in either active monitor
4359 * or standby monitor state => Disable
4360 * transmit/receive timeout.
4361 */
4362 tp->monitor_state_ready = 0;
4363
4364 /* Ring speed problem, switching to auto mode. */
Joe Perches8e95a202009-12-03 07:58:21 +00004365 if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE &&
4366 !tp->cleanup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 {
4368 printk(KERN_INFO "%s: Incorrect ring speed switching.\n",
4369 dev->name);
4370 smctr_set_ring_speed(dev);
4371 }
4372 }
4373 }
4374
4375 if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
Eric Dumazet807540b2010-09-23 05:40:09 +00004376 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004377
4378 switch(tp->ring_status)
4379 {
4380 case RING_RECOVERY:
4381 printk(KERN_INFO "%s: Ring Recovery\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 break;
4383
4384 case SINGLE_STATION:
4385 printk(KERN_INFO "%s: Single Statinon\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 break;
4387
4388 case COUNTER_OVERFLOW:
4389 printk(KERN_INFO "%s: Counter Overflow\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 break;
4391
4392 case REMOVE_RECEIVED:
4393 printk(KERN_INFO "%s: Remove Received\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 break;
4395
4396 case AUTO_REMOVAL_ERROR:
4397 printk(KERN_INFO "%s: Auto Remove Error\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 break;
4399
4400 case LOBE_WIRE_FAULT:
4401 printk(KERN_INFO "%s: Lobe Wire Fault\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004402 break;
4403
4404 case TRANSMIT_BEACON:
4405 printk(KERN_INFO "%s: Transmit Beacon\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 break;
4407
4408 case SOFT_ERROR:
4409 printk(KERN_INFO "%s: Soft Error\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004410 break;
4411
4412 case HARD_ERROR:
4413 printk(KERN_INFO "%s: Hard Error\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004414 break;
4415
4416 case SIGNAL_LOSS:
4417 printk(KERN_INFO "%s: Signal Loss\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418 break;
4419
4420 default:
4421 printk(KERN_INFO "%s: Unknown ring status change\n",
4422 dev->name);
4423 break;
4424 }
4425
Eric Dumazet807540b2010-09-23 05:40:09 +00004426 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004427}
4428
4429static int smctr_rx_frame(struct net_device *dev)
4430{
4431 struct net_local *tp = netdev_priv(dev);
4432 __u16 queue, status, rx_size, err = 0;
4433 __u8 *pbuff;
4434
4435 if(smctr_debug > 10)
4436 printk(KERN_DEBUG "%s: smctr_rx_frame\n", dev->name);
4437
4438 queue = tp->receive_queue_number;
4439
4440 while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
4441 {
4442 err = HARDWARE_FAILED;
4443
Joe Perches8e95a202009-12-03 07:58:21 +00004444 if(((status & 0x007f) == 0) ||
4445 ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 {
4447 /* frame length less the CRC (4 bytes) + FS (1 byte) */
4448 rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
4449
4450 pbuff = smctr_get_rx_pointer(dev, queue);
4451
4452 smctr_set_page(dev, pbuff);
4453 smctr_disable_16bit(dev);
4454
4455 /* pbuff points to addr within one page */
4456 pbuff = (__u8 *)PAGE_POINTER(pbuff);
4457
4458 if(queue == NON_MAC_QUEUE)
4459 {
4460 struct sk_buff *skb;
4461
4462 skb = dev_alloc_skb(rx_size);
4463 if (skb) {
4464 skb_put(skb, rx_size);
4465
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -03004466 skb_copy_to_linear_data(skb, pbuff, rx_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004467
4468 /* Update Counters */
4469 tp->MacStat.rx_packets++;
4470 tp->MacStat.rx_bytes += skb->len;
4471
4472 /* Kick the packet on up. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 skb->protocol = tr_type_trans(skb, dev);
4474 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 } else {
4476 }
4477 }
4478 else
4479 smctr_process_rx_packet((MAC_HEADER *)pbuff,
4480 rx_size, dev, status);
4481 }
4482
4483 smctr_enable_16bit(dev);
4484 smctr_set_page(dev, (__u8 *)tp->ram_access);
4485 smctr_update_rx_chain(dev, queue);
4486
4487 if(err != SUCCESS)
4488 break;
4489 }
4490
Eric Dumazet807540b2010-09-23 05:40:09 +00004491 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004492}
4493
4494static int smctr_send_dat(struct net_device *dev)
4495{
4496 struct net_local *tp = netdev_priv(dev);
4497 unsigned int i, err;
4498 MAC_HEADER *tmf;
4499 FCBlock *fcb;
4500
4501 if(smctr_debug > 10)
4502 printk(KERN_DEBUG "%s: smctr_send_dat\n", dev->name);
4503
4504 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
4505 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
4506 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004507 return OUT_OF_RESOURCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 }
4509
4510 /* Initialize DAT Data Fields. */
4511 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4512 tmf->ac = MSB(AC_FC_DAT);
4513 tmf->fc = LSB(AC_FC_DAT);
4514
4515 for(i = 0; i < 6; i++)
4516 {
4517 tmf->sa[i] = dev->dev_addr[i];
4518 tmf->da[i] = dev->dev_addr[i];
4519
4520 }
4521
4522 tmf->vc = DAT;
4523 tmf->dc_sc = DC_RS | SC_RS;
4524 tmf->vl = 4;
4525 tmf->vl = SWAP_BYTES(tmf->vl);
4526
4527 /* Start Transmit. */
4528 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
Eric Dumazet807540b2010-09-23 05:40:09 +00004529 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530
4531 /* Wait for Transmit to Complete */
4532 for(i = 0; i < 10000; i++)
4533 {
4534 if(fcb->frame_status & FCB_COMMAND_DONE)
4535 break;
4536 mdelay(1);
4537 }
4538
4539 /* Check if GOOD frame Tx'ed. */
Joe Perches8e95a202009-12-03 07:58:21 +00004540 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4541 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004542 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004543 return INITIALIZE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004544 }
4545
4546 /* De-allocated Tx FCB and Frame Buffer
4547 * The FCB must be de-allocated manually if executing with
4548 * interrupts disabled, other wise the ISR (LM_Service_Events)
4549 * will de-allocate it when the interrupt occurs.
4550 */
4551 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4552 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4553
Eric Dumazet807540b2010-09-23 05:40:09 +00004554 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555}
4556
4557static void smctr_timeout(struct net_device *dev)
4558{
4559 /*
4560 * If we get here, some higher level has decided we are broken.
4561 * There should really be a "kick me" function call instead.
4562 *
4563 * Resetting the token ring adapter takes a long time so just
4564 * fake transmission time and go on trying. Our own timeout
4565 * routine is in sktr_timer_chk()
4566 */
Eric Dumazet1ae5dc32010-05-10 05:01:31 -07004567 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004568 netif_wake_queue(dev);
4569}
4570
4571/*
4572 * Gets skb from system, queues it and checks if it can be sent
4573 */
Stephen Hemminger61a84102009-08-31 19:50:46 +00004574static netdev_tx_t smctr_send_packet(struct sk_buff *skb,
4575 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576{
4577 struct net_local *tp = netdev_priv(dev);
4578
4579 if(smctr_debug > 10)
4580 printk(KERN_DEBUG "%s: smctr_send_packet\n", dev->name);
4581
4582 /*
4583 * Block a transmit overlap
4584 */
4585
4586 netif_stop_queue(dev);
4587
4588 if(tp->QueueSkb == 0)
Patrick McHardy5b548142009-06-12 06:22:29 +00004589 return NETDEV_TX_BUSY; /* Return with tbusy set: queue full */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004590
4591 tp->QueueSkb--;
4592 skb_queue_tail(&tp->SendSkbQueue, skb);
4593 smctr_hardware_send_packet(dev, tp);
4594 if(tp->QueueSkb > 0)
4595 netif_wake_queue(dev);
4596
Patrick McHardyec634fe2009-07-05 19:23:38 -07004597 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598}
4599
4600static int smctr_send_lobe_media_test(struct net_device *dev)
4601{
4602 struct net_local *tp = netdev_priv(dev);
4603 MAC_SUB_VECTOR *tsv;
4604 MAC_HEADER *tmf;
4605 FCBlock *fcb;
4606 __u32 i;
4607 int err;
4608
4609 if(smctr_debug > 15)
4610 printk(KERN_DEBUG "%s: smctr_send_lobe_media_test\n", dev->name);
4611
4612 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
4613 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
4614 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004615 return OUT_OF_RESOURCES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 }
4617
4618 /* Initialize DAT Data Fields. */
4619 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4620 tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
4621 tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
4622
4623 for(i = 0; i < 6; i++)
4624 {
4625 tmf->da[i] = 0;
4626 tmf->sa[i] = dev->dev_addr[i];
4627 }
4628
4629 tmf->vc = LOBE_MEDIA_TEST;
4630 tmf->dc_sc = DC_RS | SC_RS;
4631 tmf->vl = 4;
4632
4633 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4634 smctr_make_wrap_data(dev, tsv);
4635 tmf->vl += tsv->svl;
4636
4637 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4638 smctr_make_wrap_data(dev, tsv);
4639 tmf->vl += tsv->svl;
4640
4641 /* Start Transmit. */
4642 tmf->vl = SWAP_BYTES(tmf->vl);
4643 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
Eric Dumazet807540b2010-09-23 05:40:09 +00004644 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645
4646 /* Wait for Transmit to Complete. (10 ms). */
4647 for(i=0; i < 10000; i++)
4648 {
4649 if(fcb->frame_status & FCB_COMMAND_DONE)
4650 break;
4651 mdelay(1);
4652 }
4653
4654 /* Check if GOOD frame Tx'ed */
Joe Perches8e95a202009-12-03 07:58:21 +00004655 if(!(fcb->frame_status & FCB_COMMAND_DONE) ||
4656 fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004658 return LOBE_MEDIA_TEST_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004659 }
4660
4661 /* De-allocated Tx FCB and Frame Buffer
4662 * The FCB must be de-allocated manually if executing with
4663 * interrupts disabled, other wise the ISR (LM_Service_Events)
4664 * will de-allocate it when the interrupt occurs.
4665 */
4666 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4667 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4668
Eric Dumazet807540b2010-09-23 05:40:09 +00004669 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670}
4671
4672static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
4673 __u16 correlator)
4674{
4675 MAC_HEADER *tmf;
4676 MAC_SUB_VECTOR *tsv;
4677 FCBlock *fcb;
4678
4679 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4680 + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
4681 + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
4682 == (FCBlock *)(-1L))
4683 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004684 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 }
4686
4687 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4688 tmf->vc = RPT_ADDR;
4689 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4690 tmf->vl = 4;
4691
4692 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
4693
4694 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4695 smctr_make_corr(dev, tsv, correlator);
4696
4697 tmf->vl += tsv->svl;
4698 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4699 smctr_make_phy_drop_num(dev, tsv);
4700
4701 tmf->vl += tsv->svl;
4702 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4703 smctr_make_upstream_neighbor_addr(dev, tsv);
4704
4705 tmf->vl += tsv->svl;
4706 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4707 smctr_make_addr_mod(dev, tsv);
4708
4709 tmf->vl += tsv->svl;
4710 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4711 smctr_make_group_addr(dev, tsv);
4712
4713 tmf->vl += tsv->svl;
4714 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4715 smctr_make_funct_addr(dev, tsv);
4716
4717 tmf->vl += tsv->svl;
4718
4719 /* Subtract out MVID and MVL which is
4720 * include in both vl and MAC_HEADER
4721 */
4722/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4723 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4724*/
4725 tmf->vl = SWAP_BYTES(tmf->vl);
4726
Eric Dumazet807540b2010-09-23 05:40:09 +00004727 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728}
4729
4730static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
4731 __u16 correlator)
4732{
4733 MAC_HEADER *tmf;
4734 MAC_SUB_VECTOR *tsv;
4735 FCBlock *fcb;
4736
4737 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4738 + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
4739 + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
4740 == (FCBlock *)(-1L))
4741 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004742 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004743 }
4744
4745 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4746 tmf->vc = RPT_ATTCH;
4747 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4748 tmf->vl = 4;
4749
4750 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
4751
4752 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4753 smctr_make_corr(dev, tsv, correlator);
4754
4755 tmf->vl += tsv->svl;
4756 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4757 smctr_make_product_id(dev, tsv);
4758
4759 tmf->vl += tsv->svl;
4760 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4761 smctr_make_funct_addr(dev, tsv);
4762
4763 tmf->vl += tsv->svl;
4764 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4765 smctr_make_auth_funct_class(dev, tsv);
4766
4767 tmf->vl += tsv->svl;
4768 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4769 smctr_make_access_pri(dev, tsv);
4770
4771 tmf->vl += tsv->svl;
4772
4773 /* Subtract out MVID and MVL which is
4774 * include in both vl and MAC_HEADER
4775 */
4776/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4777 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4778*/
4779 tmf->vl = SWAP_BYTES(tmf->vl);
4780
Eric Dumazet807540b2010-09-23 05:40:09 +00004781 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004782}
4783
4784static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
4785 __u16 correlator)
4786{
4787 MAC_HEADER *tmf;
4788 MAC_SUB_VECTOR *tsv;
4789 FCBlock *fcb;
4790
4791 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4792 + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
4793 + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
4794 == (FCBlock *)(-1L))
4795 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004796 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004797 }
4798
4799 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4800 tmf->vc = RPT_STATE;
4801 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4802 tmf->vl = 4;
4803
4804 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
4805
4806 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4807 smctr_make_corr(dev, tsv, correlator);
4808
4809 tmf->vl += tsv->svl;
4810 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4811 smctr_make_ring_station_version(dev, tsv);
4812
4813 tmf->vl += tsv->svl;
4814 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4815 smctr_make_ring_station_status(dev, tsv);
4816
4817 tmf->vl += tsv->svl;
4818 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4819 smctr_make_station_id(dev, tsv);
4820
4821 tmf->vl += tsv->svl;
4822
4823 /* Subtract out MVID and MVL which is
4824 * include in both vl and MAC_HEADER
4825 */
4826/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4827 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4828*/
4829 tmf->vl = SWAP_BYTES(tmf->vl);
4830
Eric Dumazet807540b2010-09-23 05:40:09 +00004831 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004832}
4833
4834static int smctr_send_rpt_tx_forward(struct net_device *dev,
4835 MAC_HEADER *rmf, __u16 tx_fstatus)
4836{
4837 MAC_HEADER *tmf;
4838 MAC_SUB_VECTOR *tsv;
4839 FCBlock *fcb;
4840
4841 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4842 + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
4843 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004844 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845 }
4846
4847 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4848 tmf->vc = RPT_TX_FORWARD;
4849 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4850 tmf->vl = 4;
4851
4852 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
4853
4854 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4855 smctr_make_tx_status_code(dev, tsv, tx_fstatus);
4856
4857 tmf->vl += tsv->svl;
4858
4859 /* Subtract out MVID and MVL which is
4860 * include in both vl and MAC_HEADER
4861 */
4862/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4863 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4864*/
4865 tmf->vl = SWAP_BYTES(tmf->vl);
4866
Eric Dumazet807540b2010-09-23 05:40:09 +00004867 return smctr_trc_send_packet(dev, fcb, MAC_QUEUE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868}
4869
4870static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
4871 __u16 rcode, __u16 correlator)
4872{
4873 MAC_HEADER *tmf;
4874 MAC_SUB_VECTOR *tsv;
4875 FCBlock *fcb;
4876
4877 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4878 + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
4879 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004880 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004881 }
4882
4883 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4884 tmf->vc = RSP;
4885 tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
4886 tmf->vl = 4;
4887
4888 smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
4889
4890 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4891 smctr_make_corr(dev, tsv, correlator);
4892
Eric Dumazet807540b2010-09-23 05:40:09 +00004893 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004894}
4895
4896static int smctr_send_rq_init(struct net_device *dev)
4897{
4898 struct net_local *tp = netdev_priv(dev);
4899 MAC_HEADER *tmf;
4900 MAC_SUB_VECTOR *tsv;
4901 FCBlock *fcb;
4902 unsigned int i, count = 0;
4903 __u16 fstatus;
4904 int err;
4905
4906 do {
4907 if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
4908 + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
4909 + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
4910 == (FCBlock *)(-1L)))
4911 {
Eric Dumazet807540b2010-09-23 05:40:09 +00004912 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004913 }
4914
4915 tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
4916 tmf->vc = RQ_INIT;
4917 tmf->dc_sc = DC_RPS | SC_RS;
4918 tmf->vl = 4;
4919
4920 smctr_make_8025_hdr(dev, NULL, tmf, AC_FC_RQ_INIT);
4921
4922 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
4923 smctr_make_product_id(dev, tsv);
4924
4925 tmf->vl += tsv->svl;
4926 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4927 smctr_make_upstream_neighbor_addr(dev, tsv);
4928
4929 tmf->vl += tsv->svl;
4930 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4931 smctr_make_ring_station_version(dev, tsv);
4932
4933 tmf->vl += tsv->svl;
4934 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
4935 smctr_make_addr_mod(dev, tsv);
4936
4937 tmf->vl += tsv->svl;
4938
4939 /* Subtract out MVID and MVL which is
4940 * include in both vl and MAC_HEADER
4941 */
4942/* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4943 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
4944*/
4945 tmf->vl = SWAP_BYTES(tmf->vl);
4946
4947 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
Eric Dumazet807540b2010-09-23 05:40:09 +00004948 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004949
4950 /* Wait for Transmit to Complete */
4951 for(i = 0; i < 10000; i++)
4952 {
4953 if(fcb->frame_status & FCB_COMMAND_DONE)
4954 break;
4955 mdelay(1);
4956 }
4957
4958 /* Check if GOOD frame Tx'ed */
4959 fstatus = fcb->frame_status;
4960
4961 if(!(fstatus & FCB_COMMAND_DONE))
Eric Dumazet807540b2010-09-23 05:40:09 +00004962 return HARDWARE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963
4964 if(!(fstatus & FCB_TX_STATUS_E))
4965 count++;
4966
4967 /* De-allocated Tx FCB and Frame Buffer
4968 * The FCB must be de-allocated manually if executing with
4969 * interrupts disabled, other wise the ISR (LM_Service_Events)
4970 * will de-allocate it when the interrupt occurs.
4971 */
4972 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
4973 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
4974 } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
4975
Eric Dumazet807540b2010-09-23 05:40:09 +00004976 return smctr_join_complete_state(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977}
4978
4979static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
4980 __u16 *tx_fstatus)
4981{
4982 struct net_local *tp = netdev_priv(dev);
4983 FCBlock *fcb;
4984 unsigned int i;
4985 int err;
4986
4987 /* Check if this is the END POINT of the Transmit Forward Chain. */
4988 if(rmf->vl <= 18)
Eric Dumazet807540b2010-09-23 05:40:09 +00004989 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004990
4991 /* Allocate Transmit FCB only by requesting 0 bytes
4992 * of data buffer.
4993 */
4994 if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
Eric Dumazet807540b2010-09-23 05:40:09 +00004995 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996
4997 /* Set pointer to Transmit Frame Buffer to the data
4998 * portion of the received TX Forward frame, making
4999 * sure to skip over the Vector Code (vc) and Vector
5000 * length (vl).
5001 */
5002 fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
5003 + sizeof(MAC_HEADER) + 2);
5004 fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
5005 + sizeof(MAC_HEADER) + 2);
5006
5007 fcb->frame_length = rmf->vl - 4 - 2;
5008 fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
5009
5010 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005011 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012
5013 /* Wait for Transmit to Complete */
5014 for(i = 0; i < 10000; i++)
5015 {
5016 if(fcb->frame_status & FCB_COMMAND_DONE)
5017 break;
5018 mdelay(1);
5019 }
5020
5021 /* Check if GOOD frame Tx'ed */
5022 if(!(fcb->frame_status & FCB_COMMAND_DONE))
5023 {
5024 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005025 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026
5027 for(i = 0; i < 10000; i++)
5028 {
5029 if(fcb->frame_status & FCB_COMMAND_DONE)
5030 break;
5031 mdelay(1);
5032 }
5033
5034 if(!(fcb->frame_status & FCB_COMMAND_DONE))
Eric Dumazet807540b2010-09-23 05:40:09 +00005035 return HARDWARE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 }
5037
5038 *tx_fstatus = fcb->frame_status;
5039
Eric Dumazet807540b2010-09-23 05:40:09 +00005040 return A_FRAME_WAS_FORWARDED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041}
5042
5043static int smctr_set_auth_access_pri(struct net_device *dev,
5044 MAC_SUB_VECTOR *rsv)
5045{
5046 struct net_local *tp = netdev_priv(dev);
5047
5048 if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
Eric Dumazet807540b2010-09-23 05:40:09 +00005049 return E_SUB_VECTOR_LENGTH_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050
5051 tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
5052
Eric Dumazet807540b2010-09-23 05:40:09 +00005053 return POSITIVE_ACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054}
5055
5056static int smctr_set_auth_funct_class(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_FUNCTION_CLASS)
Eric Dumazet807540b2010-09-23 05:40:09 +00005062 return E_SUB_VECTOR_LENGTH_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063
5064 tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
5065
Eric Dumazet807540b2010-09-23 05:40:09 +00005066 return POSITIVE_ACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067}
5068
5069static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
5070 __u16 *correlator)
5071{
5072 if(rsv->svl != S_CORRELATOR)
Eric Dumazet807540b2010-09-23 05:40:09 +00005073 return E_SUB_VECTOR_LENGTH_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074
5075 *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
5076
Eric Dumazet807540b2010-09-23 05:40:09 +00005077 return POSITIVE_ACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078}
5079
5080static int smctr_set_error_timer_value(struct net_device *dev,
5081 MAC_SUB_VECTOR *rsv)
5082{
5083 __u16 err_tval;
5084 int err;
5085
5086 if(rsv->svl != S_ERROR_TIMER_VALUE)
Eric Dumazet807540b2010-09-23 05:40:09 +00005087 return E_SUB_VECTOR_LENGTH_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088
5089 err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
5090
5091 smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
5092
5093 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005094 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095
Eric Dumazet807540b2010-09-23 05:40:09 +00005096 return POSITIVE_ACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097}
5098
5099static int smctr_set_frame_forward(struct net_device *dev,
5100 MAC_SUB_VECTOR *rsv, __u8 dc_sc)
5101{
5102 if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
Eric Dumazet807540b2010-09-23 05:40:09 +00005103 return E_SUB_VECTOR_LENGTH_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104
5105 if((dc_sc & DC_MASK) != DC_CRS)
5106 {
5107 if(rsv->svl >= 2 && rsv->svl < 20)
Eric Dumazet807540b2010-09-23 05:40:09 +00005108 return E_TRANSMIT_FORWARD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109
5110 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
Eric Dumazet807540b2010-09-23 05:40:09 +00005111 return E_TRANSMIT_FORWARD_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 }
5113
Eric Dumazet807540b2010-09-23 05:40:09 +00005114 return POSITIVE_ACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005115}
5116
5117static int smctr_set_local_ring_num(struct net_device *dev,
5118 MAC_SUB_VECTOR *rsv)
5119{
5120 struct net_local *tp = netdev_priv(dev);
5121
5122 if(rsv->svl != S_LOCAL_RING_NUMBER)
Eric Dumazet807540b2010-09-23 05:40:09 +00005123 return E_SUB_VECTOR_LENGTH_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005124
5125 if(tp->ptr_local_ring_num)
5126 *(__u16 *)(tp->ptr_local_ring_num)
5127 = (rsv->svv[0] << 8 | rsv->svv[1]);
5128
Eric Dumazet807540b2010-09-23 05:40:09 +00005129 return POSITIVE_ACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130}
5131
5132static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
5133{
5134 struct net_local *tp = netdev_priv(dev);
5135 int ioaddr = dev->base_addr;
5136
5137 if(tp->bic_type == BIC_585_CHIP)
5138 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
5139 else
5140 {
5141 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
5142 outb(tp->trc_mask, ioaddr + CSR);
5143 }
5144
Eric Dumazet807540b2010-09-23 05:40:09 +00005145 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005146}
5147
5148static void smctr_set_multicast_list(struct net_device *dev)
5149{
5150 if(smctr_debug > 10)
5151 printk(KERN_DEBUG "%s: smctr_set_multicast_list\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152}
5153
5154static int smctr_set_page(struct net_device *dev, __u8 *buf)
5155{
5156 struct net_local *tp = netdev_priv(dev);
5157 __u8 amask;
5158 __u32 tptr;
5159
5160 tptr = (__u32)buf - (__u32)tp->ram_access;
5161 amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
5162 outb(amask, dev->base_addr + PR);
5163
Eric Dumazet807540b2010-09-23 05:40:09 +00005164 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165}
5166
5167static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
5168{
5169 int err;
5170
5171 if(rsv->svl != S_PHYSICAL_DROP)
Eric Dumazet807540b2010-09-23 05:40:09 +00005172 return E_SUB_VECTOR_LENGTH_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173
5174 smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
5175 if((err = smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005176 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005177
Eric Dumazet807540b2010-09-23 05:40:09 +00005178 return POSITIVE_ACK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005179}
5180
5181/* Reset the ring speed to the opposite of what it was. This auto-pilot
5182 * mode requires a complete reset and re-init of the adapter.
5183 */
5184static int smctr_set_ring_speed(struct net_device *dev)
5185{
5186 struct net_local *tp = netdev_priv(dev);
5187 int err;
5188
5189 if(tp->media_type == MEDIA_UTP_16)
5190 tp->media_type = MEDIA_UTP_4;
5191 else
5192 tp->media_type = MEDIA_UTP_16;
5193
5194 smctr_enable_16bit(dev);
5195
5196 /* Re-Initialize adapter's internal registers */
5197 smctr_reset_adapter(dev);
5198
5199 if((err = smctr_init_card_real(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005200 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201
5202 smctr_enable_bic_int(dev);
5203
5204 if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005205 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206
5207 smctr_disable_16bit(dev);
5208
Eric Dumazet807540b2010-09-23 05:40:09 +00005209 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210}
5211
5212static int smctr_set_rx_look_ahead(struct net_device *dev)
5213{
5214 struct net_local *tp = netdev_priv(dev);
5215 __u16 sword, rword;
5216
5217 if(smctr_debug > 10)
5218 printk(KERN_DEBUG "%s: smctr_set_rx_look_ahead_flag\n", dev->name);
5219
5220 tp->adapter_flags &= ~(FORCED_16BIT_MODE);
5221 tp->adapter_flags |= RX_VALID_LOOKAHEAD;
5222
5223 if(tp->adapter_bus == BUS_ISA16_TYPE)
5224 {
5225 sword = *((__u16 *)(tp->ram_access));
5226 *((__u16 *)(tp->ram_access)) = 0x1234;
5227
5228 smctr_disable_16bit(dev);
5229 rword = *((__u16 *)(tp->ram_access));
5230 smctr_enable_16bit(dev);
5231
5232 if(rword != 0x1234)
5233 tp->adapter_flags |= FORCED_16BIT_MODE;
5234
5235 *((__u16 *)(tp->ram_access)) = sword;
5236 }
5237
Eric Dumazet807540b2010-09-23 05:40:09 +00005238 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239}
5240
5241static int smctr_set_trc_reset(int ioaddr)
5242{
5243 __u8 r;
5244
5245 r = inb(ioaddr + MSR);
5246 outb(MSR_RST | r, ioaddr + MSR);
5247
Eric Dumazet807540b2010-09-23 05:40:09 +00005248 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249}
5250
5251/*
5252 * This function can be called if the adapter is busy or not.
5253 */
5254static int smctr_setup_single_cmd(struct net_device *dev,
5255 __u16 command, __u16 subcommand)
5256{
5257 struct net_local *tp = netdev_priv(dev);
5258 unsigned int err;
5259
5260 if(smctr_debug > 10)
5261 printk(KERN_DEBUG "%s: smctr_setup_single_cmd\n", dev->name);
5262
5263 if((err = smctr_wait_while_cbusy(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005264 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005265
5266 if((err = (unsigned int)smctr_wait_cmd(dev)))
Eric Dumazet807540b2010-09-23 05:40:09 +00005267 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005268
5269 tp->acb_head->cmd_done_status = 0;
5270 tp->acb_head->cmd = command;
5271 tp->acb_head->subcmd = subcommand;
5272
5273 err = smctr_issue_resume_acb_cmd(dev);
5274
Eric Dumazet807540b2010-09-23 05:40:09 +00005275 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276}
5277
5278/*
5279 * This function can not be called with the adapter busy.
5280 */
5281static int smctr_setup_single_cmd_w_data(struct net_device *dev,
5282 __u16 command, __u16 subcommand)
5283{
5284 struct net_local *tp = netdev_priv(dev);
5285
5286 tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
5287 tp->acb_head->cmd = command;
5288 tp->acb_head->subcmd = subcommand;
5289 tp->acb_head->data_offset_lo
5290 = (__u16)TRC_POINTER(tp->misc_command_data);
5291
Eric Dumazet807540b2010-09-23 05:40:09 +00005292 return smctr_issue_resume_acb_cmd(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293}
5294
5295static char *smctr_malloc(struct net_device *dev, __u16 size)
5296{
5297 struct net_local *tp = netdev_priv(dev);
5298 char *m;
5299
5300 m = (char *)(tp->ram_access + tp->sh_mem_used);
5301 tp->sh_mem_used += (__u32)size;
5302
Eric Dumazet807540b2010-09-23 05:40:09 +00005303 return m;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005304}
5305
5306static int smctr_status_chg(struct net_device *dev)
5307{
5308 struct net_local *tp = netdev_priv(dev);
5309
5310 if(smctr_debug > 10)
5311 printk(KERN_DEBUG "%s: smctr_status_chg\n", dev->name);
5312
5313 switch(tp->status)
5314 {
5315 case OPEN:
5316 break;
5317
5318 case CLOSED:
5319 break;
5320
5321 /* Interrupt driven open() completion. XXX */
5322 case INITIALIZED:
5323 tp->group_address_0 = 0;
5324 tp->group_address[0] = 0;
5325 tp->group_address[1] = 0;
5326 tp->functional_address_0 = 0;
5327 tp->functional_address[0] = 0;
5328 tp->functional_address[1] = 0;
5329 smctr_open_tr(dev);
5330 break;
5331
5332 default:
5333 printk(KERN_INFO "%s: status change unknown %x\n",
5334 dev->name, tp->status);
5335 break;
5336 }
5337
Eric Dumazet807540b2010-09-23 05:40:09 +00005338 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339}
5340
5341static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
5342 __u16 queue)
5343{
5344 struct net_local *tp = netdev_priv(dev);
5345 int err = 0;
5346
5347 if(smctr_debug > 10)
5348 printk(KERN_DEBUG "%s: smctr_trc_send_packet\n", dev->name);
5349
5350 fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
5351 if(tp->num_tx_fcbs[queue] != 1)
5352 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
5353
5354 if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
5355 {
5356 tp->tx_queue_status[queue] = TRANSMITING;
5357 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
5358 }
5359
Eric Dumazet807540b2010-09-23 05:40:09 +00005360 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361}
5362
5363static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
5364{
5365 struct net_local *tp = netdev_priv(dev);
5366 __u16 status, err = 0;
5367 int cstatus;
5368
5369 if(smctr_debug > 10)
5370 printk(KERN_DEBUG "%s: smctr_tx_complete\n", dev->name);
5371
5372 while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
5373 {
5374 if(status & 0x7e00 )
5375 {
5376 err = HARDWARE_FAILED;
5377 break;
5378 }
5379
5380 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
5381 queue)) != SUCCESS)
5382 break;
5383
5384 smctr_disable_16bit(dev);
5385
5386 if(tp->mode_bits & UMAC)
5387 {
5388 if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
5389 cstatus = NO_SUCH_DESTINATION;
5390 else
5391 {
5392 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
5393 cstatus = DEST_OUT_OF_RESOURCES;
5394 else
5395 {
5396 if(status & FCB_TX_STATUS_E)
5397 cstatus = MAX_COLLISIONS;
5398 else
5399 cstatus = SUCCESS;
5400 }
5401 }
5402 }
5403 else
5404 cstatus = SUCCESS;
5405
5406 if(queue == BUG_QUEUE)
5407 err = SUCCESS;
5408
5409 smctr_enable_16bit(dev);
5410 if(err != SUCCESS)
5411 break;
5412 }
5413
Eric Dumazet807540b2010-09-23 05:40:09 +00005414 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415}
5416
5417static unsigned short smctr_tx_move_frame(struct net_device *dev,
5418 struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
5419{
5420 struct net_local *tp = netdev_priv(dev);
5421 unsigned int ram_usable;
5422 __u32 flen, len, offset = 0;
5423 __u8 *frag, *page;
5424
5425 if(smctr_debug > 10)
5426 printk(KERN_DEBUG "%s: smctr_tx_move_frame\n", dev->name);
5427
5428 ram_usable = ((unsigned int)tp->ram_usable) << 10;
5429 frag = skb->data;
5430 flen = skb->len;
5431
5432 while(flen > 0 && bytes > 0)
5433 {
5434 smctr_set_page(dev, pbuff);
5435
5436 offset = SMC_PAGE_OFFSET(pbuff);
5437
5438 if(offset + flen > ram_usable)
5439 len = ram_usable - offset;
5440 else
5441 len = flen;
5442
5443 if(len > bytes)
5444 len = bytes;
5445
5446 page = (char *) (offset + tp->ram_access);
5447 memcpy(page, frag, len);
5448
5449 flen -=len;
5450 bytes -= len;
5451 frag += len;
5452 pbuff += len;
5453 }
5454
Eric Dumazet807540b2010-09-23 05:40:09 +00005455 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456}
5457
5458/* Update the error statistic counters for this adapter. */
5459static int smctr_update_err_stats(struct net_device *dev)
5460{
5461 struct net_local *tp = netdev_priv(dev);
5462 struct tr_statistics *tstat = &tp->MacStat;
5463
5464 if(tstat->internal_errors)
5465 tstat->internal_errors
5466 += *(tp->misc_command_data + 0) & 0x00ff;
5467
5468 if(tstat->line_errors)
5469 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
5470
5471 if(tstat->A_C_errors)
5472 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
5473
5474 if(tstat->burst_errors)
5475 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
5476
5477 if(tstat->abort_delimiters)
5478 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
5479
5480 if(tstat->recv_congest_count)
5481 tstat->recv_congest_count
5482 += *(tp->misc_command_data + 3) & 0x00ff;
5483
5484 if(tstat->lost_frames)
5485 tstat->lost_frames
5486 += *(tp->misc_command_data + 3) >> 8;
5487
5488 if(tstat->frequency_errors)
5489 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
5490
5491 if(tstat->frame_copied_errors)
5492 tstat->frame_copied_errors
5493 += *(tp->misc_command_data + 4) >> 8;
5494
5495 if(tstat->token_errors)
5496 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
5497
Eric Dumazet807540b2010-09-23 05:40:09 +00005498 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499}
5500
5501static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
5502{
5503 struct net_local *tp = netdev_priv(dev);
5504 FCBlock *fcb;
5505 BDBlock *bdb;
5506 __u16 size, len;
5507
5508 fcb = tp->rx_fcb_curr[queue];
5509 len = fcb->frame_length;
5510
5511 fcb->frame_status = 0;
5512 fcb->info = FCB_CHAIN_END;
5513 fcb->back_ptr->info = FCB_WARNING;
5514
5515 tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
5516
5517 /* update RX BDBs */
5518 size = (len >> RX_BDB_SIZE_SHIFT);
5519 if(len & RX_DATA_BUFFER_SIZE_MASK)
5520 size += sizeof(BDBlock);
5521 size &= (~RX_BDB_SIZE_MASK);
5522
5523 /* check if wrap around */
5524 bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
5525 if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
5526 {
5527 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
5528 + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
5529 }
5530
5531 bdb->back_ptr->info = BDB_CHAIN_END;
5532 tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
5533 tp->rx_bdb_curr[queue] = bdb;
5534
Eric Dumazet807540b2010-09-23 05:40:09 +00005535 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005536}
5537
5538static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
5539 __u16 queue)
5540{
5541 struct net_local *tp = netdev_priv(dev);
5542
5543 if(smctr_debug > 20)
5544 printk(KERN_DEBUG "smctr_update_tx_chain\n");
5545
5546 if(tp->num_tx_fcbs_used[queue] <= 0)
Eric Dumazet807540b2010-09-23 05:40:09 +00005547 return HARDWARE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548 else
5549 {
5550 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
5551 {
5552 tp->tx_buff_used[queue] = 0;
Eric Dumazet807540b2010-09-23 05:40:09 +00005553 return HARDWARE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005554 }
5555
5556 tp->tx_buff_used[queue] -= fcb->memory_alloc;
5557
5558 /* if all transmit buffer are cleared
5559 * need to set the tx_buff_curr[] to tx_buff_head[]
5560 * otherwise, tx buffer will be segregate and cannot
5561 * accommodate and buffer greater than (curr - head) and
5562 * (end - curr) since we do not allow wrap around allocation.
5563 */
5564 if(tp->tx_buff_used[queue] == 0)
5565 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
5566
5567 tp->num_tx_fcbs_used[queue]--;
5568 fcb->frame_status = 0;
5569 tp->tx_fcb_end[queue] = fcb->next_ptr;
5570 netif_wake_queue(dev);
Eric Dumazet807540b2010-09-23 05:40:09 +00005571 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005572 }
5573}
5574
5575static int smctr_wait_cmd(struct net_device *dev)
5576{
5577 struct net_local *tp = netdev_priv(dev);
5578 unsigned int loop_count = 0x20000;
5579
5580 if(smctr_debug > 10)
5581 printk(KERN_DEBUG "%s: smctr_wait_cmd\n", dev->name);
5582
5583 while(loop_count)
5584 {
5585 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
5586 break;
5587 udelay(1);
5588 loop_count--;
5589 }
5590
5591 if(loop_count == 0)
Eric Dumazet807540b2010-09-23 05:40:09 +00005592 return HARDWARE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005593
5594 if(tp->acb_head->cmd_done_status & 0xff)
Eric Dumazet807540b2010-09-23 05:40:09 +00005595 return HARDWARE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005596
Eric Dumazet807540b2010-09-23 05:40:09 +00005597 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005598}
5599
5600static int smctr_wait_while_cbusy(struct net_device *dev)
5601{
5602 struct net_local *tp = netdev_priv(dev);
5603 unsigned int timeout = 0x20000;
5604 int ioaddr = dev->base_addr;
5605 __u8 r;
5606
5607 if(tp->bic_type == BIC_585_CHIP)
5608 {
5609 while(timeout)
5610 {
5611 r = inb(ioaddr + HWR);
5612 if((r & HWR_CBUSY) == 0)
5613 break;
5614 timeout--;
5615 }
5616 }
5617 else
5618 {
5619 while(timeout)
5620 {
5621 r = inb(ioaddr + CSR);
5622 if((r & CSR_CBUSY) == 0)
5623 break;
5624 timeout--;
5625 }
5626 }
5627
5628 if(timeout)
Eric Dumazet807540b2010-09-23 05:40:09 +00005629 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005630 else
Eric Dumazet807540b2010-09-23 05:40:09 +00005631 return HARDWARE_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005632}
5633
5634#ifdef MODULE
5635
5636static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
5637static int io[SMCTR_MAX_ADAPTERS];
5638static int irq[SMCTR_MAX_ADAPTERS];
5639
5640MODULE_LICENSE("GPL");
David Woodhouse0f805b82008-05-29 16:39:16 +03005641MODULE_FIRMWARE("tr_smctr.bin");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005642
5643module_param_array(io, int, NULL, 0);
5644module_param_array(irq, int, NULL, 0);
5645module_param(ringspeed, int, 0);
5646
Andrew Mortondaca7cd2006-08-14 23:00:06 -07005647static struct net_device * __init setup_card(int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005648{
5649 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
5650 int err;
5651
5652 if (!dev)
5653 return ERR_PTR(-ENOMEM);
5654
5655 dev->irq = irq[n];
5656 err = smctr_probe1(dev, io[n]);
5657 if (err)
5658 goto out;
5659
5660 err = register_netdev(dev);
5661 if (err)
5662 goto out1;
5663 return dev;
5664 out1:
5665#ifdef CONFIG_MCA_LEGACY
5666 { struct net_local *tp = netdev_priv(dev);
5667 if (tp->slot_num)
5668 mca_mark_as_unused(tp->slot_num);
5669 }
5670#endif
5671 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5672 free_irq(dev->irq, dev);
5673out:
5674 free_netdev(dev);
5675 return ERR_PTR(err);
5676}
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677
Andrew Mortondaca7cd2006-08-14 23:00:06 -07005678int __init init_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005679{
5680 int i, found = 0;
5681 struct net_device *dev;
5682
5683 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5684 dev = io[0]? setup_card(i) : smctr_probe(-1);
5685 if (!IS_ERR(dev)) {
5686 ++found;
5687 dev_smctr[i] = dev;
5688 }
5689 }
5690
5691 return found ? 0 : -ENODEV;
5692}
5693
Al Viroafc8eb42006-06-14 18:50:53 -04005694void __exit cleanup_module(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695{
5696 int i;
5697
5698 for(i = 0; i < SMCTR_MAX_ADAPTERS; i++) {
5699 struct net_device *dev = dev_smctr[i];
5700
5701 if (dev) {
5702
5703 unregister_netdev(dev);
5704#ifdef CONFIG_MCA_LEGACY
5705 { struct net_local *tp = netdev_priv(dev);
5706 if (tp->slot_num)
5707 mca_mark_as_unused(tp->slot_num);
5708 }
5709#endif
5710 release_region(dev->base_addr, SMCTR_IO_EXTENT);
5711 if (dev->irq)
5712 free_irq(dev->irq, dev);
5713
5714 free_netdev(dev);
5715 }
5716 }
5717}
5718#endif /* MODULE */