smctr.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:192k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /*
  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.  */
  28. #ifdef MODULE
  29. #include <linux/module.h>
  30. #include <linux/version.h>
  31. #endif
  32. #include <linux/config.h>
  33. #include <linux/kernel.h>
  34. #include <linux/sched.h>
  35. #include <linux/types.h>
  36. #include <linux/fcntl.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/ptrace.h>
  39. #include <linux/ioport.h>
  40. #include <linux/in.h>
  41. #include <linux/slab.h>
  42. #include <linux/string.h>
  43. #include <linux/time.h>
  44. #include <asm/system.h>
  45. #include <asm/bitops.h>
  46. #include <asm/io.h>
  47. #include <asm/dma.h>
  48. #include <asm/irq.h>
  49. #include <linux/errno.h>
  50. #include <linux/init.h>
  51. #include <linux/pci.h>
  52. #include <linux/mca.h>
  53. #include <linux/delay.h>
  54. #include <linux/netdevice.h>
  55. #include <linux/etherdevice.h>
  56. #include <linux/skbuff.h>
  57. #include <linux/trdevice.h>
  58. #if BITS_PER_LONG == 64
  59. #error FIXME: driver does not support 64-bit platforms
  60. #endif
  61. #include "smctr.h"               /* Our Stuff */
  62. #include "smctr_firmware.h"      /* SMC adapter firmware */
  63. static char version[] __initdata = KERN_INFO "smctr.c: v1.4 7/12/00 by jschlst@samba.orgn";
  64. static const char cardname[] = "smctr";
  65. #define SMCTR_IO_EXTENT   20
  66. /* A zero-terminated list of I/O addresses to be probed. */
  67. static unsigned int smctr_portlist[] __initdata = {
  68.         0x200, 0x220, 0x240, 0x260, 0x280, 0x2A0, 0x2C0, 0x2E0, 0x300,
  69.         0x320, 0x340, 0x360, 0x380,
  70.         0
  71. };
  72. #ifdef CONFIG_MCA
  73. static unsigned int smctr_posid = 0x6ec6;
  74. #endif
  75. static int ringspeed;
  76. /* SMC Name of the Adapter. */
  77. static char smctr_name[] = "SMC TokenCard";
  78. char *smctr_model = "Unknown";
  79. /* Use 0 for production, 1 for verification, 2 for debug, and
  80.  * 3 for very verbose debug.
  81.  */
  82. #ifndef SMCTR_DEBUG
  83. #define SMCTR_DEBUG 1
  84. #endif
  85. static unsigned int smctr_debug = SMCTR_DEBUG;
  86. /* smctr.c prototypes and functions are arranged alphabeticly 
  87.  * for clearity, maintainability and pure old fashion fun. 
  88.  */
  89. /* A */
  90. static int smctr_alloc_shared_memory(struct net_device *dev);
  91. /* B */
  92. static int smctr_bypass_state(struct net_device *dev);
  93. /* C */
  94. static int smctr_checksum_firmware(struct net_device *dev);
  95. static int __init smctr_chk_isa(struct net_device *dev);
  96. static int smctr_chg_rx_mask(struct net_device *dev);
  97. static int smctr_clear_int(struct net_device *dev);
  98. static int smctr_clear_trc_reset(int ioaddr);
  99. static int smctr_close(struct net_device *dev);
  100. /* D */
  101. static int smctr_decode_firmware(struct net_device *dev);
  102. static int smctr_disable_16bit(struct net_device *dev);
  103. static int smctr_disable_adapter_ctrl_store(struct net_device *dev);
  104. static int smctr_disable_bic_int(struct net_device *dev);
  105. /* E */
  106. static int smctr_enable_16bit(struct net_device *dev);
  107. static int smctr_enable_adapter_ctrl_store(struct net_device *dev);
  108. static int smctr_enable_adapter_ram(struct net_device *dev);
  109. static int smctr_enable_bic_int(struct net_device *dev);
  110. /* G */
  111. static int __init smctr_get_boardid(struct net_device *dev, int mca);
  112. static int smctr_get_group_address(struct net_device *dev);
  113. static int smctr_get_functional_address(struct net_device *dev);
  114. static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev);
  115. static int smctr_get_physical_drop_number(struct net_device *dev);
  116. static __u8 *smctr_get_rx_pointer(struct net_device *dev, short queue);
  117. static int smctr_get_station_id(struct net_device *dev);
  118. static struct net_device_stats *smctr_get_stats(struct net_device *dev);
  119. static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
  120.         __u16 bytes_count);
  121. static int smctr_get_upstream_neighbor_addr(struct net_device *dev);
  122. /* H */
  123. static int smctr_hardware_send_packet(struct net_device *dev,
  124.         struct net_local *tp);
  125. /* I */
  126. static int smctr_init_acbs(struct net_device *dev);
  127. static int smctr_init_adapter(struct net_device *dev);
  128. static int __init smctr_init_card(struct net_device *dev);
  129. static int smctr_init_card_real(struct net_device *dev);
  130. static int smctr_init_rx_bdbs(struct net_device *dev);
  131. static int smctr_init_rx_fcbs(struct net_device *dev);
  132. static int smctr_init_shared_memory(struct net_device *dev);
  133. static int smctr_init_tx_bdbs(struct net_device *dev);
  134. static int smctr_init_tx_fcbs(struct net_device *dev);
  135. static int smctr_internal_self_test(struct net_device *dev);
  136. static void smctr_interrupt(int irq, void *dev_id, struct pt_regs *regs);
  137. static int smctr_issue_enable_int_cmd(struct net_device *dev,
  138.         __u16 interrupt_enable_mask);
  139. static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
  140.         __u16 ibits);
  141. static int smctr_issue_init_timers_cmd(struct net_device *dev);
  142. static int smctr_issue_init_txrx_cmd(struct net_device *dev);
  143. static int smctr_issue_insert_cmd(struct net_device *dev);
  144. static int smctr_issue_read_ring_status_cmd(struct net_device *dev);
  145. static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt);
  146. static int smctr_issue_remove_cmd(struct net_device *dev);
  147. static int smctr_issue_resume_acb_cmd(struct net_device *dev);
  148. static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue);
  149. static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue);
  150. static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue);
  151. static int smctr_issue_test_internal_rom_cmd(struct net_device *dev);
  152. static int smctr_issue_test_hic_cmd(struct net_device *dev);
  153. static int smctr_issue_test_mac_reg_cmd(struct net_device *dev);
  154. static int smctr_issue_trc_loopback_cmd(struct net_device *dev);
  155. static int smctr_issue_tri_loopback_cmd(struct net_device *dev);
  156. static int smctr_issue_write_byte_cmd(struct net_device *dev,
  157.         short aword_cnt, void *byte);
  158. static int smctr_issue_write_word_cmd(struct net_device *dev,
  159.         short aword_cnt, void *word);
  160. /* J */
  161. static int smctr_join_complete_state(struct net_device *dev);
  162. /* L */
  163. static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev);
  164. static int smctr_load_firmware(struct net_device *dev);
  165. static int smctr_load_node_addr(struct net_device *dev);
  166. static int smctr_lobe_media_test(struct net_device *dev);
  167. static int smctr_lobe_media_test_cmd(struct net_device *dev);
  168. static int smctr_lobe_media_test_state(struct net_device *dev);
  169. /* M */
  170. static int smctr_make_8025_hdr(struct net_device *dev,
  171.         MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc);
  172. static int smctr_make_access_pri(struct net_device *dev,
  173.         MAC_SUB_VECTOR *tsv);
  174. static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv);
  175. static int smctr_make_auth_funct_class(struct net_device *dev,
  176.         MAC_SUB_VECTOR *tsv);
  177. static int smctr_make_corr(struct net_device *dev,
  178.         MAC_SUB_VECTOR *tsv, __u16 correlator);
  179. static int smctr_make_funct_addr(struct net_device *dev,
  180.         MAC_SUB_VECTOR *tsv);
  181. static int smctr_make_group_addr(struct net_device *dev,
  182.         MAC_SUB_VECTOR *tsv);
  183. static int smctr_make_phy_drop_num(struct net_device *dev,
  184.         MAC_SUB_VECTOR *tsv);
  185. static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
  186. static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv);
  187. static int smctr_make_ring_station_status(struct net_device *dev,
  188.         MAC_SUB_VECTOR *tsv);
  189. static int smctr_make_ring_station_version(struct net_device *dev,
  190.         MAC_SUB_VECTOR *tsv);
  191. static int smctr_make_tx_status_code(struct net_device *dev,
  192.         MAC_SUB_VECTOR *tsv, __u16 tx_fstatus);
  193. static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
  194.         MAC_SUB_VECTOR *tsv);
  195. static int smctr_make_wrap_data(struct net_device *dev,
  196.         MAC_SUB_VECTOR *tsv);
  197. /* O */
  198. static int smctr_open(struct net_device *dev);
  199. static int smctr_open_tr(struct net_device *dev);
  200. /* P */
  201. int __init smctr_probe (struct net_device *dev);
  202. static int __init smctr_probe1(struct net_device *dev, int ioaddr);
  203. static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
  204.         struct net_device *dev, __u16 rx_status);
  205. /* R */
  206. static int smctr_ram_memory_test(struct net_device *dev);
  207. static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
  208.         __u16 *correlator);
  209. static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
  210.         __u16 *correlator);
  211. static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf);
  212. static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
  213.         MAC_HEADER *rmf, __u16 *correlator);
  214. static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
  215.         __u16 *correlator);
  216. static int smctr_reset_adapter(struct net_device *dev);
  217. static int smctr_restart_tx_chain(struct net_device *dev, short queue);
  218. static int smctr_ring_status_chg(struct net_device *dev);
  219. static int smctr_rx_frame(struct net_device *dev);
  220. /* S */
  221. static int smctr_send_dat(struct net_device *dev);
  222. static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev);
  223. static int smctr_send_lobe_media_test(struct net_device *dev);
  224. static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
  225.         __u16 correlator);
  226. static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
  227.         __u16 correlator);
  228. static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
  229.         __u16 correlator);
  230. static int smctr_send_rpt_tx_forward(struct net_device *dev,
  231.         MAC_HEADER *rmf, __u16 tx_fstatus);
  232. static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
  233.         __u16 rcode, __u16 correlator);
  234. static int smctr_send_rq_init(struct net_device *dev);
  235. static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
  236.         __u16 *tx_fstatus);
  237. static int smctr_set_auth_access_pri(struct net_device *dev,
  238.         MAC_SUB_VECTOR *rsv);
  239. static int smctr_set_auth_funct_class(struct net_device *dev,
  240.         MAC_SUB_VECTOR *rsv);
  241. static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
  242. __u16 *correlator);
  243. static int smctr_set_error_timer_value(struct net_device *dev,
  244.         MAC_SUB_VECTOR *rsv);
  245. static int smctr_set_frame_forward(struct net_device *dev,
  246.         MAC_SUB_VECTOR *rsv, __u8 dc_sc);
  247. static int smctr_set_local_ring_num(struct net_device *dev,
  248.         MAC_SUB_VECTOR *rsv);
  249. static unsigned short smctr_set_ctrl_attention(struct net_device *dev);
  250. static void smctr_set_multicast_list(struct net_device *dev);
  251. static int smctr_set_page(struct net_device *dev, __u8 *buf);
  252. static int smctr_set_phy_drop(struct net_device *dev,
  253.         MAC_SUB_VECTOR *rsv);
  254. static int smctr_set_ring_speed(struct net_device *dev);
  255. static int smctr_set_rx_look_ahead(struct net_device *dev);
  256. static int smctr_set_trc_reset(int ioaddr);
  257. static int smctr_setup_single_cmd(struct net_device *dev,
  258.         __u16 command, __u16 subcommand);
  259. static int smctr_setup_single_cmd_w_data(struct net_device *dev,
  260.         __u16 command, __u16 subcommand);
  261. static char *smctr_malloc(struct net_device *dev, __u16 size);
  262. static int smctr_status_chg(struct net_device *dev);
  263. /* T */
  264. static void smctr_timeout(struct net_device *dev);
  265. static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
  266.         __u16 queue);
  267. static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue);
  268. static unsigned short smctr_tx_move_frame(struct net_device *dev,
  269.         struct sk_buff *skb, __u8 *pbuff, unsigned int bytes);
  270. /* U */
  271. static int smctr_update_err_stats(struct net_device *dev);
  272. static int smctr_update_rx_chain(struct net_device *dev, __u16 queue);
  273. static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
  274.         __u16 queue);
  275. /* W */
  276. static int smctr_wait_cmd(struct net_device *dev);
  277. static int smctr_wait_while_cbusy(struct net_device *dev);
  278. #define TO_256_BYTE_BOUNDRY(X)  (((X + 0xff) & 0xff00) - X)
  279. #define TO_PARAGRAPH_BOUNDRY(X) (((X + 0x0f) & 0xfff0) - X)
  280. #define PARAGRAPH_BOUNDRY(X)    smctr_malloc(dev, TO_PARAGRAPH_BOUNDRY(X))
  281. /* Allocate Adapter Shared Memory.
  282.  * IMPORTANT NOTE: Any changes to this function MUST be mirrored in the
  283.  * function "get_num_rx_bdbs" below!!!
  284.  *
  285.  * Order of memory allocation:
  286.  *
  287.  *       0. Initial System Configuration Block Pointer
  288.  *       1. System Configuration Block
  289.  *       2. System Control Block
  290.  *       3. Action Command Block
  291.  *       4. Interrupt Status Block
  292.  *
  293.  *       5. MAC TX FCB'S
  294.  *       6. NON-MAC TX FCB'S
  295.  *       7. MAC TX BDB'S
  296.  *       8. NON-MAC TX BDB'S
  297.  *       9. MAC RX FCB'S
  298.  *      10. NON-MAC RX FCB'S
  299.  *      11. MAC RX BDB'S
  300.  *      12. NON-MAC RX BDB'S
  301.  *      13. MAC TX Data Buffer( 1, 256 byte buffer)
  302.  *      14. MAC RX Data Buffer( 1, 256 byte buffer)
  303.  *
  304.  *      15. NON-MAC TX Data Buffer
  305.  *      16. NON-MAC RX Data Buffer
  306.  */
  307. static int smctr_alloc_shared_memory(struct net_device *dev)
  308. {
  309.         struct net_local *tp = (struct net_local *)dev->priv;
  310.         if(smctr_debug > 10)
  311.                 printk("%s: smctr_alloc_shared_memoryn", dev->name);
  312.         /* Allocate initial System Control Block pointer.
  313.          * This pointer is located in the last page, last offset - 4.
  314.          */
  315.         tp->iscpb_ptr = (ISCPBlock *)(tp->ram_access + ((__u32)64 * 0x400)
  316.                 - (long)ISCP_BLOCK_SIZE);
  317.         /* Allocate System Control Blocks. */
  318.         tp->scgb_ptr = (SCGBlock *)smctr_malloc(dev, sizeof(SCGBlock));
  319.         PARAGRAPH_BOUNDRY(tp->sh_mem_used);
  320.         tp->sclb_ptr = (SCLBlock *)smctr_malloc(dev, sizeof(SCLBlock));
  321.         PARAGRAPH_BOUNDRY(tp->sh_mem_used);
  322.         tp->acb_head = (ACBlock *)smctr_malloc(dev,
  323.                 sizeof(ACBlock)*tp->num_acbs);
  324.         PARAGRAPH_BOUNDRY(tp->sh_mem_used);
  325.         tp->isb_ptr = (ISBlock *)smctr_malloc(dev, sizeof(ISBlock));
  326.         PARAGRAPH_BOUNDRY(tp->sh_mem_used);
  327.         tp->misc_command_data = (__u16 *)smctr_malloc(dev, MISC_DATA_SIZE);
  328.         PARAGRAPH_BOUNDRY(tp->sh_mem_used);
  329.         /* Allocate transmit FCBs. */
  330.         tp->tx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
  331.                 sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE]);
  332.         tp->tx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
  333.                 sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE]);
  334.         tp->tx_fcb_head[BUG_QUEUE] = (FCBlock *)smctr_malloc(dev,
  335.                 sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE]);
  336.         /* Allocate transmit BDBs. */
  337.         tp->tx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
  338.                 sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE]);
  339.         tp->tx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
  340.                 sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE]);
  341.         tp->tx_bdb_head[BUG_QUEUE] = (BDBlock *)smctr_malloc(dev,
  342.                 sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE]);
  343.         /* Allocate receive FCBs. */
  344.         tp->rx_fcb_head[MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
  345.                 sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE]);
  346.         tp->rx_fcb_head[NON_MAC_QUEUE] = (FCBlock *)smctr_malloc(dev,
  347.                 sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE]);
  348.         /* Allocate receive BDBs. */
  349.         tp->rx_bdb_head[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
  350.                 sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE]);
  351.         tp->rx_bdb_end[MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
  352.         tp->rx_bdb_head[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev,
  353.                 sizeof(BDBlock) * tp->num_rx_bdbs[NON_MAC_QUEUE]);
  354.         tp->rx_bdb_end[NON_MAC_QUEUE] = (BDBlock *)smctr_malloc(dev, 0);
  355.         /* Allocate MAC transmit buffers.
  356.          * MAC Tx Buffers doen't have to be on an ODD Boundry.
  357.          */
  358.         tp->tx_buff_head[MAC_QUEUE]
  359.                 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[MAC_QUEUE]);
  360.         tp->tx_buff_curr[MAC_QUEUE] = tp->tx_buff_head[MAC_QUEUE];
  361.         tp->tx_buff_end [MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
  362.         /* Allocate BUG transmit buffers. */
  363.         tp->tx_buff_head[BUG_QUEUE]
  364.                 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[BUG_QUEUE]);
  365.         tp->tx_buff_curr[BUG_QUEUE] = tp->tx_buff_head[BUG_QUEUE];
  366.         tp->tx_buff_end[BUG_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
  367.         /* Allocate MAC receive data buffers.
  368.          * MAC Rx buffer doesn't have to be on a 256 byte boundry.
  369.          */
  370.         tp->rx_buff_head[MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
  371.                 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE]);
  372.         tp->rx_buff_end[MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
  373.         /* Allocate Non-MAC transmit buffers.
  374.          * ?? For maximum Netware performance, put Tx Buffers on
  375.          * ODD Boundry and then restore malloc to Even Boundrys.
  376.          */
  377.         smctr_malloc(dev, 1L);
  378.         tp->tx_buff_head[NON_MAC_QUEUE]
  379.                 = (__u16 *)smctr_malloc(dev, tp->tx_buff_size[NON_MAC_QUEUE]);
  380.         tp->tx_buff_curr[NON_MAC_QUEUE] = tp->tx_buff_head[NON_MAC_QUEUE];
  381.         tp->tx_buff_end [NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
  382.         smctr_malloc(dev, 1L);
  383.         /* Allocate Non-MAC receive data buffers.
  384.          * To guarantee a minimum of 256 contigous memory to
  385.          * UM_Receive_Packet's lookahead pointer, before a page
  386.          * change or ring end is encountered, place each rx buffer on
  387.          * a 256 byte boundry.
  388.          */
  389.         smctr_malloc(dev, TO_256_BYTE_BOUNDRY(tp->sh_mem_used));
  390.         tp->rx_buff_head[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev,
  391.                 RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[NON_MAC_QUEUE]);
  392.         tp->rx_buff_end[NON_MAC_QUEUE] = (__u16 *)smctr_malloc(dev, 0);
  393.         return (0);
  394. }
  395. /* Enter Bypass state. */
  396. static int smctr_bypass_state(struct net_device *dev)
  397. {
  398.         int err;
  399. if(smctr_debug > 10)
  400.          printk("%s: smctr_bypass_staten", dev->name);
  401.         err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
  402.                 JS_BYPASS_STATE);
  403.         return (err);
  404. }
  405. static int smctr_checksum_firmware(struct net_device *dev)
  406. {
  407.         struct net_local *tp = (struct net_local *)dev->priv;
  408.         __u16 i, checksum = 0;
  409.         if(smctr_debug > 10)
  410.                 printk("%s: smctr_checksum_firmwaren", dev->name);
  411.         smctr_enable_adapter_ctrl_store(dev);
  412.         for(i = 0; i < CS_RAM_SIZE; i += 2)
  413.                 checksum += *((__u16 *)(tp->ram_access + i));
  414.         tp->microcode_version = *(__u16 *)(tp->ram_access
  415.                 + CS_RAM_VERSION_OFFSET);
  416.         tp->microcode_version >>= 8;
  417.         smctr_disable_adapter_ctrl_store(dev);
  418.         if(checksum)
  419.                 return (checksum);
  420.         return (0);
  421. }
  422. static int smctr_chk_mca(struct net_device *dev)
  423. {
  424. #ifdef CONFIG_MCA
  425. struct net_local *tp = (struct net_local *)dev->priv;
  426. int current_slot;
  427. __u8 r1, r2, r3, r4, r5;
  428. current_slot = mca_find_unused_adapter(smctr_posid, 0);
  429. if(current_slot == MCA_NOTFOUND)
  430. return (-ENODEV);
  431. mca_set_adapter_name(current_slot, smctr_name);
  432. mca_mark_as_used(current_slot);
  433. tp->slot_num = current_slot;
  434. r1 = mca_read_stored_pos(tp->slot_num, 2);
  435. r2 = mca_read_stored_pos(tp->slot_num, 3);
  436. if(tp->slot_num)
  437. outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num - 1) | CNFG_SLOT_ENABLE_BIT));
  438. else
  439. outb(CNFG_POS_CONTROL_REG, (__u8)((tp->slot_num) | CNFG_SLOT_ENABLE_BIT));
  440. r1 = inb(CNFG_POS_REG1);
  441. r2 = inb(CNFG_POS_REG0);
  442. tp->bic_type = BIC_594_CHIP;
  443. /* IO */
  444. r2 = mca_read_stored_pos(tp->slot_num, 2);
  445. r2 &= 0xF0;
  446. dev->base_addr = ((__u16)r2 << 8) + (__u16)0x800;
  447. request_region(dev->base_addr, SMCTR_IO_EXTENT, smctr_name);
  448. /* IRQ */
  449. r5 = mca_read_stored_pos(tp->slot_num, 5);
  450. r5 &= 0xC;
  451.         switch(r5)
  452. {
  453.              case 0:
  454. dev->irq = 3;
  455.                 break;
  456.              case 0x4:
  457. dev->irq = 4;
  458.                 break;
  459.              case 0x8:
  460. dev->irq = 10;
  461.                 break;
  462.              default:
  463. dev->irq = 15;
  464.                 break;
  465. }
  466. if(request_irq(dev->irq, smctr_interrupt, SA_SHIRQ, smctr_name, dev))
  467.                 return (-ENODEV);
  468. /* Get RAM base */
  469. r3 = mca_read_stored_pos(tp->slot_num, 3);
  470. if(r3 & 0x8) 
  471.          if(r3 & 0x80)
  472.                 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0xFD0000;
  473.              else
  474. tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0D0000;
  475.         }
  476. else 
  477. {
  478.              if(r3 & 0x80)
  479.                 tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0xFC0000;
  480.              else
  481. tp->ram_base = ((__u32)(r3 & 0x7) << 13) + 0x0C0000;
  482.         }
  483. /* Get Ram Size */
  484. r3 &= 0x30;
  485. r3 >>= 4;
  486. tp->ram_usable = (__u16)CNFG_SIZE_8KB << r3;
  487. tp->ram_size = (__u16)CNFG_SIZE_64KB;
  488. tp->board_id |= TOKEN_MEDIA;
  489. r4 = mca_read_stored_pos(tp->slot_num, 4);
  490. if(r4 & 0x8)
  491. tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0xD0000;
  492. else
  493. tp->rom_base = ((__u32)(r4 & 0x7) << 13) + 0xC0000;
  494. /* Get ROM size. */
  495. r4 >>= 4;
  496. if(r4 == 0)
  497. tp->rom_size = CNFG_SIZE_8KB;
  498. else
  499. {
  500. if(r4 == 1)
  501. tp->rom_size = CNFG_SIZE_16KB;
  502. else
  503. {
  504. if(r4 == 2)
  505. tp->rom_size = CNFG_SIZE_32KB;
  506. else
  507. tp->rom_size = ROM_DISABLE;
  508. }
  509. }
  510. /* Get Media Type. */
  511. r5 = mca_read_stored_pos(tp->slot_num, 5);
  512. r5 &= CNFG_MEDIA_TYPE_MASK;
  513. switch(r5)
  514. {
  515. case (0):
  516. tp->media_type = MEDIA_STP_4;
  517. break;
  518. case (1):
  519. tp->media_type = MEDIA_STP_16;
  520. break;
  521. case (3):
  522. tp->media_type = MEDIA_UTP_16;
  523. break;
  524. default:
  525. tp->media_type = MEDIA_UTP_4;
  526. break;
  527. }
  528. tp->media_menu = 14;
  529. r2 = mca_read_stored_pos(tp->slot_num, 2);
  530. if(!(r2 & 0x02))
  531. tp->mode_bits |= EARLY_TOKEN_REL;
  532. /* Disable slot */
  533. outb(CNFG_POS_CONTROL_REG, 0);
  534. tp->board_id = smctr_get_boardid(dev, 1);
  535. switch(tp->board_id & 0xffff)
  536.         {
  537.                 case WD8115TA:
  538.                         smctr_model = "8115T/A";
  539.                         break;
  540.                 case WD8115T:
  541. if(tp->extra_info & CHIP_REV_MASK)
  542.                                 smctr_model = "8115T rev XE";
  543.                         else
  544.                                 smctr_model = "8115T rev XD";
  545.                         break;
  546.                 default:
  547.                         smctr_model = "Unknown";
  548.                         break;
  549.         }
  550. return (0);
  551. #else
  552. return (-1);
  553. #endif /* CONFIG_MCA */
  554. }
  555. static int smctr_chg_rx_mask(struct net_device *dev)
  556. {
  557.         struct net_local *tp = (struct net_local *)dev->priv;
  558.         int err = 0;
  559.         if(smctr_debug > 10)
  560. printk("%s: smctr_chg_rx_maskn", dev->name);
  561.         smctr_enable_16bit(dev);
  562.         smctr_set_page(dev, (__u8 *)tp->ram_access);
  563.         if(tp->mode_bits & LOOPING_MODE_MASK)
  564.                 tp->config_word0 |= RX_OWN_BIT;
  565.         else
  566.                 tp->config_word0 &= ~RX_OWN_BIT;
  567.         if(tp->receive_mask & PROMISCUOUS_MODE)
  568.                 tp->config_word0 |= PROMISCUOUS_BIT;
  569.         else
  570.                 tp->config_word0 &= ~PROMISCUOUS_BIT;
  571.         if(tp->receive_mask & ACCEPT_ERR_PACKETS)
  572.                 tp->config_word0 |= SAVBAD_BIT;
  573.         else
  574.                 tp->config_word0 &= ~SAVBAD_BIT;
  575.         if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
  576.                 tp->config_word0 |= RXATMAC;
  577.         else
  578.                 tp->config_word0 &= ~RXATMAC;
  579.         if(tp->receive_mask & ACCEPT_MULTI_PROM)
  580.                 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
  581.         else
  582.                 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
  583.         if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
  584.                 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
  585.         else
  586.         {
  587.                 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
  588.                         tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
  589.                 else
  590.                         tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
  591.         }
  592.         if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_0,
  593.                 &tp->config_word0)))
  594.         {
  595.                 return (err);
  596.         }
  597.         if((err = smctr_issue_write_word_cmd(dev, RW_CONFIG_REGISTER_1,
  598.                 &tp->config_word1)))
  599.         {
  600.                 return (err);
  601.         }
  602.         smctr_disable_16bit(dev);
  603.         return (0);
  604. }
  605. static int smctr_clear_int(struct net_device *dev)
  606. {
  607.         struct net_local *tp = (struct net_local *)dev->priv;
  608.         outb((tp->trc_mask | CSR_CLRTINT), dev->base_addr + CSR);
  609.         return (0);
  610. }
  611. static int smctr_clear_trc_reset(int ioaddr)
  612. {
  613.         __u8 r;
  614.         r = inb(ioaddr + MSR);
  615.         outb(~MSR_RST & r, ioaddr + MSR);
  616.         return (0);
  617. }
  618. /*
  619.  * The inverse routine to smctr_open().
  620.  */
  621. static int smctr_close(struct net_device *dev)
  622. {
  623.         struct net_local *tp = (struct net_local *)dev->priv;
  624.         struct sk_buff *skb;
  625.         int err;
  626. netif_stop_queue(dev);
  627. #ifdef MODULE
  628.         MOD_DEC_USE_COUNT;
  629. #endif
  630. tp->cleanup = 1;
  631.         /* Check to see if adapter is already in a closed state. */
  632.         if(tp->status != OPEN)
  633.                 return (0);
  634.         smctr_enable_16bit(dev);
  635.         smctr_set_page(dev, (__u8 *)tp->ram_access);
  636.         if((err = smctr_issue_remove_cmd(dev)))
  637.         {
  638.                 smctr_disable_16bit(dev);
  639.                 return (err);
  640.         }
  641.         for(;;)
  642.         {
  643.                 skb = skb_dequeue(&tp->SendSkbQueue);
  644.                 if(skb == NULL)
  645.                         break;
  646.                 tp->QueueSkb++;
  647.                 dev_kfree_skb(skb);
  648.         }
  649.         return (0);
  650. }
  651. static int smctr_decode_firmware(struct net_device *dev)
  652. {
  653.         struct net_local *tp = (struct net_local *)dev->priv;
  654.         short bit = 0x80, shift = 12;
  655.         DECODE_TREE_NODE *tree;
  656.         short branch, tsize;
  657.         __u16 buff = 0;
  658.         long weight;
  659.         __u8 *ucode;
  660.         __u16 *mem;
  661.         if(smctr_debug > 10)
  662.                 printk("%s: smctr_decode_firmwaren", dev->name);
  663.         weight  = *(long *)(tp->ptr_ucode + WEIGHT_OFFSET);
  664.         tsize   = *(__u8 *)(tp->ptr_ucode + TREE_SIZE_OFFSET);
  665.         tree    = (DECODE_TREE_NODE *)(tp->ptr_ucode + TREE_OFFSET);
  666.         ucode   = (__u8 *)(tp->ptr_ucode + TREE_OFFSET
  667.                         + (tsize * sizeof(DECODE_TREE_NODE)));
  668.         mem     = (__u16 *)(tp->ram_access);
  669.         while(weight)
  670.         {
  671.                 branch = ROOT;
  672.                 while((tree + branch)->tag != LEAF && weight)
  673.                 {
  674.                         branch = *ucode & bit ? (tree + branch)->llink
  675.                                 : (tree + branch)->rlink;
  676.                         bit >>= 1;
  677.                         weight--;
  678.                         if(bit == 0)
  679.                         {
  680.                                 bit = 0x80;
  681.                                 ucode++;
  682.                         }
  683.                 }
  684.                 buff |= (tree + branch)->info << shift;
  685.                 shift -= 4;
  686.                 if(shift < 0)
  687.                 {
  688.                         *(mem++) = SWAP_BYTES(buff);
  689.                         buff    = 0;
  690.                         shift   = 12;
  691.                 }
  692.         }
  693.         /* The following assumes the Control Store Memory has
  694.          * been initialized to zero. If the last partial word
  695.          * is zero, it will not be written.
  696.          */
  697.         if(buff)
  698.                 *(mem++) = SWAP_BYTES(buff);
  699.         return (0);
  700. }
  701. static int smctr_disable_16bit(struct net_device *dev)
  702. {
  703.         return (0);
  704. }
  705. /*
  706.  * On Exit, Adapter is:
  707.  * 1. TRC is in a reset state and un-initialized.
  708.  * 2. Adapter memory is enabled.
  709.  * 3. Control Store memory is out of context (-WCSS is 1).
  710.  */
  711. static int smctr_disable_adapter_ctrl_store(struct net_device *dev)
  712. {
  713.         struct net_local *tp = (struct net_local *)dev->priv;
  714.         int ioaddr = dev->base_addr;
  715.         if(smctr_debug > 10)
  716.                 printk("%s: smctr_disable_adapter_ctrl_storen", dev->name);
  717.         tp->trc_mask |= CSR_WCSS;
  718.         outb(tp->trc_mask, ioaddr + CSR);
  719.         return (0);
  720. }
  721. static int smctr_disable_bic_int(struct net_device *dev)
  722. {
  723.         struct net_local *tp = (struct net_local *)dev->priv;
  724.         int ioaddr = dev->base_addr;
  725.         tp->trc_mask = CSR_MSK_ALL | CSR_MSKCBUSY
  726.         | CSR_MSKTINT | CSR_WCSS;
  727.         outb(tp->trc_mask, ioaddr + CSR);
  728.         return (0);
  729. }
  730. static int smctr_enable_16bit(struct net_device *dev)
  731. {
  732.         struct net_local *tp = (struct net_local *)dev->priv;
  733.         __u8    r;
  734.         if(tp->adapter_bus == BUS_ISA16_TYPE)
  735.         {
  736.                 r = inb(dev->base_addr + LAAR);
  737.                 outb((r | LAAR_MEM16ENB), dev->base_addr + LAAR);
  738.         }
  739.         return (0);
  740. }
  741. /*
  742.  * To enable the adapter control store memory:
  743.  * 1. Adapter must be in a RESET state.
  744.  * 2. Adapter memory must be enabled.
  745.  * 3. Control Store Memory is in context (-WCSS is 0).
  746.  */
  747. static int smctr_enable_adapter_ctrl_store(struct net_device *dev)
  748. {
  749.         struct net_local *tp = (struct net_local *)dev->priv;
  750.         int ioaddr = dev->base_addr;
  751.         if(smctr_debug > 10)
  752.                 printk("%s: smctr_enable_adapter_ctrl_storen", dev->name);
  753.         smctr_set_trc_reset(ioaddr);
  754.         smctr_enable_adapter_ram(dev);
  755.         tp->trc_mask &= ~CSR_WCSS;
  756.         outb(tp->trc_mask, ioaddr + CSR);
  757.         return (0);
  758. }
  759. static int smctr_enable_adapter_ram(struct net_device *dev)
  760. {
  761.         int ioaddr = dev->base_addr;
  762.         __u8 r;
  763.         if(smctr_debug > 10)
  764.                 printk("%s: smctr_enable_adapter_ramn", dev->name);
  765.         r = inb(ioaddr + MSR);
  766.         outb(MSR_MEMB | r, ioaddr + MSR);
  767.         return (0);
  768. }
  769. static int smctr_enable_bic_int(struct net_device *dev)
  770. {
  771.         struct net_local *tp = (struct net_local *)dev->priv;
  772.         int ioaddr = dev->base_addr;
  773.         __u8 r;
  774.         switch(tp->bic_type)
  775.         {
  776.                 case (BIC_584_CHIP):
  777.                         tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
  778.                         outb(tp->trc_mask, ioaddr + CSR);
  779.                         r = inb(ioaddr + IRR);
  780.                         outb(r | IRR_IEN, ioaddr + IRR);
  781.                         break;
  782.                 case (BIC_594_CHIP):
  783.                         tp->trc_mask = CSR_MSKCBUSY | CSR_WCSS;
  784.                         outb(tp->trc_mask, ioaddr + CSR);
  785.                         r = inb(ioaddr + IMCCR);
  786.                         outb(r | IMCCR_EIL, ioaddr + IMCCR);
  787.                         break;
  788.         }
  789.         return (0);
  790. }
  791. static int __init smctr_chk_isa(struct net_device *dev)
  792. {
  793.         struct net_local *tp = (struct net_local *)dev->priv;
  794.         int ioaddr = dev->base_addr;
  795.         __u8 r1, r2, b, chksum = 0;
  796.         __u16 r;
  797. int i;
  798.         if(smctr_debug > 10)
  799.                 printk("%s: smctr_chk_isa %#4xn", dev->name, ioaddr);
  800. if((ioaddr & 0x1F) != 0)
  801.                 return (-ENODEV);
  802.         /* Checksum SMC node address */
  803.         for(i = 0; i < 8; i++)
  804.         {
  805.                 b = inb(ioaddr + LAR0 + i);
  806.                 chksum += b;
  807.         }
  808.         if(chksum != NODE_ADDR_CKSUM)
  809.                 return (-ENODEV);            /* Adapter Not Found */
  810.         /* Grab the region so that no one else tries to probe our ioports. */
  811.         request_region(ioaddr, SMCTR_IO_EXTENT, smctr_name);
  812.         b = inb(ioaddr + BDID);
  813. if(b != BRD_ID_8115T)
  814.         {
  815.                 printk("%s: The adapter found is not supportedn", dev->name);
  816.                 return (-1);
  817.         }
  818.         /* Check for 8115T Board ID */
  819.         r2 = 0;
  820.         for(r = 0; r < 8; r++)
  821.         {
  822.             r1 = inb(ioaddr + 0x8 + r);
  823.             r2 += r1;
  824.         }
  825.         /* value of RegF adds up the sum to 0xFF */
  826.         if((r2 != 0xFF) && (r2 != 0xEE))
  827.                 return (-1);
  828.         /* Get adapter ID */
  829.         tp->board_id = smctr_get_boardid(dev, 0);
  830.         switch(tp->board_id & 0xffff)
  831.         {
  832.                 case WD8115TA:
  833.                         smctr_model = "8115T/A";
  834.                         break;
  835.                 case WD8115T:
  836. if(tp->extra_info & CHIP_REV_MASK)
  837.                                 smctr_model = "8115T rev XE";
  838.                         else
  839.                                 smctr_model = "8115T rev XD";
  840.                         break;
  841.                 default:
  842.                         smctr_model = "Unknown";
  843.                         break;
  844.         }
  845.         /* Store BIC type. */
  846.         tp->bic_type = BIC_584_CHIP;
  847.         tp->nic_type = NIC_825_CHIP;
  848.         /* Copy Ram Size */
  849.         tp->ram_usable  = CNFG_SIZE_16KB;
  850.         tp->ram_size    = CNFG_SIZE_64KB;
  851.         /* Get 58x Ram Base */
  852.         r1 = inb(ioaddr);
  853.         r1 &= 0x3F;
  854.         r2 = inb(ioaddr + CNFG_LAAR_584);
  855.         r2 &= CNFG_LAAR_MASK;
  856.         r2 <<= 3;
  857.         r2 |= ((r1 & 0x38) >> 3);
  858.         tp->ram_base = ((__u32)r2 << 16) + (((__u32)(r1 & 0x7)) << 13);
  859.         /* Get 584 Irq */
  860.         r1 = 0;
  861.         r1 = inb(ioaddr + CNFG_ICR_583);
  862.         r1 &= CNFG_ICR_IR2_584;
  863.         r2 = inb(ioaddr + CNFG_IRR_583);
  864.         r2 &= CNFG_IRR_IRQS;     /* 0x60 */
  865.         r2 >>= 5;
  866.         switch(r2)
  867.         {
  868.                 case 0:
  869.                         if(r1 == 0)
  870.                                 dev->irq = 2;
  871.                         else
  872.                                 dev->irq = 10;
  873.                         break;
  874.                 case 1:
  875.                         if(r1 == 0)
  876.                                 dev->irq = 3;
  877.                         else
  878.                                 dev->irq = 11;
  879.                         break;
  880.                 case 2:
  881.                         if(r1 == 0)
  882.                         {
  883.                                 if(tp->extra_info & ALTERNATE_IRQ_BIT)
  884.                                         dev->irq = 5;
  885.                                 else
  886.                                         dev->irq = 4;
  887.                         }
  888.                         else
  889.                                 dev->irq = 15;
  890.                         break;
  891.                 case 3:
  892.                         if(r1 == 0)
  893.                                 dev->irq = 7;
  894.                         else
  895.                                 dev->irq = 4;
  896.                         break;
  897.                 default:
  898.                         printk("%s: No IRQ found abortingn", dev->name);
  899.                         return(-1);
  900.          }
  901.         if(request_irq(dev->irq, smctr_interrupt, SA_SHIRQ, smctr_name, dev))
  902.                 return (-ENODEV);
  903.         /* Get 58x Rom Base */
  904.         r1 = inb(ioaddr + CNFG_BIO_583);
  905.         r1 &= 0x3E;
  906.         r1 |= 0x40;
  907.         tp->rom_base = (__u32)r1 << 13;
  908.         /* Get 58x Rom Size */
  909.         r1 = inb(ioaddr + CNFG_BIO_583);
  910.         r1 &= 0xC0;
  911.         if(r1 == 0)
  912.                 tp->rom_size = ROM_DISABLE;
  913.         else
  914.         {
  915.                 r1 >>= 6;
  916.                 tp->rom_size = (__u16)CNFG_SIZE_8KB << r1;
  917.         }
  918.         /* Get 58x Boot Status */
  919.         r1 = inb(ioaddr + CNFG_GP2);
  920.         tp->mode_bits &= (~BOOT_STATUS_MASK);
  921.         if(r1 & CNFG_GP2_BOOT_NIBBLE)
  922.                 tp->mode_bits |= BOOT_TYPE_1;
  923.         /* Get 58x Zero Wait State */
  924.         tp->mode_bits &= (~ZERO_WAIT_STATE_MASK);
  925.         r1 = inb(ioaddr + CNFG_IRR_583);
  926.         if(r1 & CNFG_IRR_ZWS)
  927.                  tp->mode_bits |= ZERO_WAIT_STATE_8_BIT;
  928.         if(tp->board_id & BOARD_16BIT)
  929.         {
  930.                 r1 = inb(ioaddr + CNFG_LAAR_584);
  931.                 if(r1 & CNFG_LAAR_ZWS)
  932.                         tp->mode_bits |= ZERO_WAIT_STATE_16_BIT;
  933.         }
  934.         /* Get 584 Media Menu */
  935.         tp->media_menu = 14;
  936.         r1 = inb(ioaddr + CNFG_IRR_583);
  937.         tp->mode_bits &= 0xf8ff;       /* (~CNFG_INTERFACE_TYPE_MASK) */
  938.         if((tp->board_id & TOKEN_MEDIA) == TOKEN_MEDIA)
  939.         {
  940.                 /* Get Advanced Features */
  941.                 if(((r1 & 0x6) >> 1) == 0x3)
  942.                         tp->media_type |= MEDIA_UTP_16;
  943.                 else
  944.                 {
  945.                         if(((r1 & 0x6) >> 1) == 0x2)
  946.                                 tp->media_type |= MEDIA_STP_16;
  947.                         else
  948.                         {
  949.                                 if(((r1 & 0x6) >> 1) == 0x1)
  950.                                         tp->media_type |= MEDIA_UTP_4;
  951.                                 else
  952.                                         tp->media_type |= MEDIA_STP_4;
  953.                         }
  954.                 }
  955.                 r1 = inb(ioaddr + CNFG_GP2);
  956.                 if(!(r1 & 0x2) )           /* GP2_ETRD */
  957.                         tp->mode_bits |= EARLY_TOKEN_REL;
  958.                 /* see if the chip is corrupted
  959.                 if(smctr_read_584_chksum(ioaddr))
  960.                 {
  961.                         printk("%s: EEPROM Checksum Failuren", dev->name);
  962.                         return(-1);
  963.                 }
  964. */
  965.         }
  966.         return (0);
  967. }
  968. static int __init smctr_get_boardid(struct net_device *dev, int mca)
  969. {
  970.         struct net_local *tp = (struct net_local *)dev->priv;
  971.         int ioaddr = dev->base_addr;
  972.         __u8 r, r1, IdByte;
  973.         __u16 BoardIdMask;
  974.         tp->board_id = BoardIdMask = 0;
  975. if(mca)
  976. {
  977. BoardIdMask |= (MICROCHANNEL+INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
  978. tp->extra_info |= (INTERFACE_594_CHIP+RAM_SIZE_64K+NIC_825_BIT+ALTERNATE_IRQ_BIT+SLOT_16BIT);
  979. }
  980. else
  981. {
  982.          BoardIdMask|=(INTERFACE_CHIP+TOKEN_MEDIA+PAGED_RAM+BOARD_16BIT);
  983.          tp->extra_info |= (INTERFACE_584_CHIP + RAM_SIZE_64K
  984.                  + NIC_825_BIT + ALTERNATE_IRQ_BIT);
  985. }
  986. if(!mca)
  987. {
  988.          r = inb(ioaddr + BID_REG_1);
  989.          r &= 0x0c;
  990.         outb(r, ioaddr + BID_REG_1);
  991.          r = inb(ioaddr + BID_REG_1);
  992.          if(r & BID_SIXTEEN_BIT_BIT)
  993.          {
  994.                  tp->extra_info |= SLOT_16BIT;
  995.                  tp->adapter_bus = BUS_ISA16_TYPE;
  996.          }
  997.          else
  998.                  tp->adapter_bus = BUS_ISA8_TYPE;
  999. }
  1000. else
  1001. tp->adapter_bus = BUS_MCA_TYPE;
  1002.         /* Get Board Id Byte */
  1003.         IdByte = inb(ioaddr + BID_BOARD_ID_BYTE);
  1004.         /* if Major version > 1.0 then
  1005.          *      return;
  1006.          */
  1007.         if(IdByte & 0xF8)
  1008.                 return (-1);
  1009.         r1 = inb(ioaddr + BID_REG_1);
  1010.         r1 &= BID_ICR_MASK;
  1011.         r1 |= BID_OTHER_BIT;
  1012.         outb(r1, ioaddr + BID_REG_1);
  1013.         r1 = inb(ioaddr + BID_REG_3);
  1014.         r1 &= BID_EAR_MASK;
  1015.         r1 |= BID_ENGR_PAGE;
  1016.         outb(r1, ioaddr + BID_REG_3);
  1017.         r1 = inb(ioaddr + BID_REG_1);
  1018.         r1 &= BID_ICR_MASK;
  1019.         r1 |= (BID_RLA | BID_OTHER_BIT);
  1020.         outb(r1, ioaddr + BID_REG_1);
  1021.         r1 = inb(ioaddr + BID_REG_1);
  1022.         while(r1 & BID_RECALL_DONE_MASK)
  1023.                 r1 = inb(ioaddr + BID_REG_1);
  1024.         r = inb(ioaddr + BID_LAR_0 + BID_REG_6);
  1025.         /* clear chip rev bits */
  1026.         tp->extra_info &= ~CHIP_REV_MASK;
  1027.         tp->extra_info |= ((r & BID_EEPROM_CHIP_REV_MASK) << 6);
  1028.         r1 = inb(ioaddr + BID_REG_1);
  1029.         r1 &= BID_ICR_MASK;
  1030.         r1 |= BID_OTHER_BIT;
  1031.         outb(r1, ioaddr + BID_REG_1);
  1032.         r1 = inb(ioaddr + BID_REG_3);
  1033.         r1 &= BID_EAR_MASK;
  1034.         r1 |= BID_EA6;
  1035.         outb(r1, ioaddr + BID_REG_3);
  1036.         r1 = inb(ioaddr + BID_REG_1);
  1037.         r1 &= BID_ICR_MASK;
  1038.         r1 |= BID_RLA;
  1039.         outb(r1, ioaddr + BID_REG_1);
  1040.         r1 = inb(ioaddr + BID_REG_1);
  1041.         while(r1 & BID_RECALL_DONE_MASK)
  1042.                 r1 = inb(ioaddr + BID_REG_1);
  1043.         return (BoardIdMask);
  1044. }
  1045. static int smctr_get_group_address(struct net_device *dev)
  1046. {
  1047.         smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_GROUP_ADDR);
  1048.         return(smctr_wait_cmd(dev));
  1049. }
  1050. static int smctr_get_functional_address(struct net_device *dev)
  1051. {
  1052.         smctr_issue_read_word_cmd(dev, RW_FUNCTIONAL_ADDR);
  1053.         return(smctr_wait_cmd(dev));
  1054. }
  1055. /* Calculate number of Non-MAC receive BDB's and data buffers.
  1056.  * This function must simulate allocateing shared memory exactly
  1057.  * as the allocate_shared_memory function above.
  1058.  */
  1059. static unsigned int smctr_get_num_rx_bdbs(struct net_device *dev)
  1060. {
  1061.         struct net_local *tp = (struct net_local *)dev->priv;
  1062.         unsigned int mem_used = 0;
  1063.         /* Allocate System Control Blocks. */
  1064.         mem_used += sizeof(SCGBlock);
  1065.         mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
  1066.         mem_used += sizeof(SCLBlock);
  1067.         mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
  1068.         mem_used += sizeof(ACBlock) * tp->num_acbs;
  1069.         mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
  1070.         mem_used += sizeof(ISBlock);
  1071.         mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
  1072.         mem_used += MISC_DATA_SIZE;
  1073.         /* Allocate transmit FCB's. */
  1074.         mem_used += TO_PARAGRAPH_BOUNDRY(mem_used);
  1075.         mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[MAC_QUEUE];
  1076.         mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[NON_MAC_QUEUE];
  1077.         mem_used += sizeof(FCBlock) * tp->num_tx_fcbs[BUG_QUEUE];
  1078.         /* Allocate transmit BDBs. */
  1079.         mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[MAC_QUEUE];
  1080.         mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[NON_MAC_QUEUE];
  1081.         mem_used += sizeof(BDBlock) * tp->num_tx_bdbs[BUG_QUEUE];
  1082.         /* Allocate receive FCBs. */
  1083.         mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[MAC_QUEUE];
  1084.         mem_used += sizeof(FCBlock) * tp->num_rx_fcbs[NON_MAC_QUEUE];
  1085.         /* Allocate receive BDBs. */
  1086.         mem_used += sizeof(BDBlock) * tp->num_rx_bdbs[MAC_QUEUE];
  1087.         /* Allocate MAC transmit buffers.
  1088.          * MAC transmit buffers don't have to be on an ODD Boundry.
  1089.          */
  1090.         mem_used += tp->tx_buff_size[MAC_QUEUE];
  1091.         /* Allocate BUG transmit buffers. */
  1092.         mem_used += tp->tx_buff_size[BUG_QUEUE];
  1093.         /* Allocate MAC receive data buffers.
  1094.          * MAC receive buffers don't have to be on a 256 byte boundry.
  1095.          */
  1096.         mem_used += RX_DATA_BUFFER_SIZE * tp->num_rx_bdbs[MAC_QUEUE];
  1097.         /* Allocate Non-MAC transmit buffers.
  1098.          * For maximum Netware performance, put Tx Buffers on
  1099.          * ODD Boundry,and then restore malloc to Even Boundrys.
  1100.          */
  1101.         mem_used += 1L;
  1102.         mem_used += tp->tx_buff_size[NON_MAC_QUEUE];
  1103.         mem_used += 1L;
  1104.         /* CALCULATE NUMBER OF NON-MAC RX BDB'S
  1105.          * AND NON-MAC RX DATA BUFFERS
  1106.          *
  1107.          * Make sure the mem_used offset at this point is the
  1108.          * same as in allocate_shared memory or the following
  1109.          * boundry adjustment will be incorrect (i.e. not allocating
  1110.          * the non-mac receive buffers above cannot change the 256
  1111.          * byte offset).
  1112.          *
  1113.          * Since this cannot be guaranteed, adding the full 256 bytes
  1114.          * to the amount of shared memory used at this point will guaranteed
  1115.          * that the rx data buffers do not overflow shared memory.
  1116.          */
  1117.         mem_used += 0x100;
  1118.         return((0xffff - mem_used) / (RX_DATA_BUFFER_SIZE + sizeof(BDBlock)));
  1119. }
  1120. static int smctr_get_physical_drop_number(struct net_device *dev)
  1121. {
  1122.         smctr_issue_read_word_cmd(dev, RW_PHYSICAL_DROP_NUMBER);
  1123.         return(smctr_wait_cmd(dev));
  1124. }
  1125. static __u8 * smctr_get_rx_pointer(struct net_device *dev, short queue)
  1126. {
  1127.         struct net_local *tp = (struct net_local *)dev->priv;
  1128.         BDBlock *bdb;
  1129.         bdb = (BDBlock *)((__u32)tp->ram_access
  1130.                 + (__u32)(tp->rx_fcb_curr[queue]->trc_bdb_ptr));
  1131.         tp->rx_fcb_curr[queue]->bdb_ptr = bdb;
  1132.         return ((__u8 *)bdb->data_block_ptr);
  1133. }
  1134. static int smctr_get_station_id(struct net_device *dev)
  1135. {
  1136.         smctr_issue_read_word_cmd(dev, RW_INDIVIDUAL_MAC_ADDRESS);
  1137.         return(smctr_wait_cmd(dev));
  1138. }
  1139. /*
  1140.  * Get the current statistics. This may be called with the card open
  1141.  * or closed.
  1142.  */
  1143. static struct net_device_stats *smctr_get_stats(struct net_device *dev)
  1144. {
  1145.         struct net_local *tp = (struct net_local *)dev->priv;
  1146.         return ((struct net_device_stats *)&tp->MacStat);
  1147. }
  1148. static FCBlock *smctr_get_tx_fcb(struct net_device *dev, __u16 queue,
  1149.         __u16 bytes_count)
  1150. {
  1151.         struct net_local *tp = (struct net_local *)dev->priv;
  1152.         FCBlock *pFCB;
  1153.         BDBlock *pbdb;
  1154.         unsigned short alloc_size;
  1155.         unsigned short *temp;
  1156.         if(smctr_debug > 20)
  1157.                 printk("smctr_get_tx_fcbn");
  1158.         /* check if there is enough FCB blocks */
  1159.         if(tp->num_tx_fcbs_used[queue] >= tp->num_tx_fcbs[queue])
  1160.                 return ((FCBlock *)(-1L));
  1161.         /* round off the input pkt size to the nearest even number */
  1162.         alloc_size = (bytes_count + 1) & 0xfffe;
  1163.         /* check if enough mem */
  1164.         if((tp->tx_buff_used[queue] + alloc_size) > tp->tx_buff_size[queue])
  1165.                 return ((FCBlock *)(-1L));
  1166.         /* check if past the end ;
  1167.          * if exactly enough mem to end of ring, alloc from front.
  1168.          * this avoids update of curr when curr = end
  1169.          */
  1170.         if(((unsigned long)(tp->tx_buff_curr[queue]) + alloc_size)
  1171.                 >= (unsigned long)(tp->tx_buff_end[queue]))
  1172.         {
  1173.                 /* check if enough memory from ring head */
  1174.                 alloc_size = alloc_size +
  1175.                         (__u16)((__u32)tp->tx_buff_end[queue]
  1176.                         - (__u32)tp->tx_buff_curr[queue]);
  1177.                 if((tp->tx_buff_used[queue] + alloc_size)
  1178.                         > tp->tx_buff_size[queue])
  1179.                 {
  1180.                         return ((FCBlock *)(-1L));
  1181.                 }
  1182.                 /* ring wrap */
  1183.                 tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
  1184.         }
  1185.         tp->tx_buff_used[queue] += alloc_size;
  1186.         tp->num_tx_fcbs_used[queue]++;
  1187.         tp->tx_fcb_curr[queue]->frame_length = bytes_count;
  1188.         tp->tx_fcb_curr[queue]->memory_alloc = alloc_size;
  1189.         temp = tp->tx_buff_curr[queue];
  1190.         tp->tx_buff_curr[queue]
  1191.                 = (__u16 *)((__u32)temp + (__u32)((bytes_count + 1) & 0xfffe));
  1192.         pbdb = tp->tx_fcb_curr[queue]->bdb_ptr;
  1193.         pbdb->buffer_length = bytes_count;
  1194.         pbdb->data_block_ptr = temp;
  1195.         pbdb->trc_data_block_ptr = TRC_POINTER(temp);
  1196.         pFCB = tp->tx_fcb_curr[queue];
  1197.         tp->tx_fcb_curr[queue] = tp->tx_fcb_curr[queue]->next_ptr;
  1198.         return (pFCB);
  1199. }
  1200. static int smctr_get_upstream_neighbor_addr(struct net_device *dev)
  1201. {
  1202.         smctr_issue_read_word_cmd(dev, RW_UPSTREAM_NEIGHBOR_ADDRESS);
  1203.         return(smctr_wait_cmd(dev));
  1204. }
  1205. static int smctr_hardware_send_packet(struct net_device *dev,
  1206.         struct net_local *tp)
  1207. {
  1208.         struct tr_statistics *tstat = &tp->MacStat;
  1209.         struct sk_buff *skb;
  1210.         FCBlock *fcb;
  1211.         if(smctr_debug > 10)
  1212.                 printk("%s: smctr_hardware_send_packetn", dev->name);
  1213.         if(tp->status != OPEN)
  1214.                 return (-1);
  1215.         if(tp->monitor_state_ready != 1)
  1216.                 return (-1);
  1217.         for(;;)
  1218.         {
  1219.                 /* Send first buffer from queue */
  1220.                 skb = skb_dequeue(&tp->SendSkbQueue);
  1221.                 if(skb == NULL)
  1222.                         return (-1);
  1223.                 tp->QueueSkb++;
  1224.                 if(skb->len < SMC_HEADER_SIZE || skb->len > tp->max_packet_size)                        return (-1);
  1225.                 smctr_enable_16bit(dev);
  1226.                 smctr_set_page(dev, (__u8 *)tp->ram_access);
  1227.                 if((fcb = smctr_get_tx_fcb(dev, NON_MAC_QUEUE, skb->len))
  1228.                         == (FCBlock *)(-1L))
  1229.                 {
  1230.                         smctr_disable_16bit(dev);
  1231.                         return (-1);
  1232.                 }
  1233.                 smctr_tx_move_frame(dev, skb,
  1234.                         (__u8 *)fcb->bdb_ptr->data_block_ptr, skb->len);
  1235.                 smctr_set_page(dev, (__u8 *)fcb);
  1236.                 smctr_trc_send_packet(dev, fcb, NON_MAC_QUEUE);
  1237.                 dev_kfree_skb(skb);
  1238.                 tstat->tx_packets++;
  1239.                 smctr_disable_16bit(dev);
  1240.         }
  1241.         return (0);
  1242. }
  1243. static int smctr_init_acbs(struct net_device *dev)
  1244. {
  1245.         struct net_local *tp = (struct net_local *)dev->priv;
  1246.         unsigned int i;
  1247.         ACBlock *acb;
  1248.         if(smctr_debug > 10)
  1249.                 printk("%s: smctr_init_acbsn", dev->name);
  1250.         acb                     = tp->acb_head;
  1251.         acb->cmd_done_status    = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
  1252.         acb->cmd_info           = ACB_CHAIN_END;
  1253.         acb->cmd                = 0;
  1254.         acb->subcmd             = 0;
  1255.         acb->data_offset_lo     = 0;
  1256.         acb->data_offset_hi     = 0;
  1257.         acb->next_ptr
  1258.                 = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
  1259.         acb->trc_next_ptr       = TRC_POINTER(acb->next_ptr);
  1260.         for(i = 1; i < tp->num_acbs; i++)
  1261.         {
  1262.                 acb             = acb->next_ptr;
  1263.                 acb->cmd_done_status
  1264.                         = (ACB_COMMAND_DONE | ACB_COMMAND_SUCCESSFUL);
  1265.                 acb->cmd_info = ACB_CHAIN_END;
  1266.                 acb->cmd        = 0;
  1267.                 acb->subcmd     = 0;
  1268.                 acb->data_offset_lo = 0;
  1269.                 acb->data_offset_hi = 0;
  1270.                 acb->next_ptr
  1271.                         = (ACBlock *)(((char *)acb) + sizeof(ACBlock));
  1272.                 acb->trc_next_ptr = TRC_POINTER(acb->next_ptr);
  1273.         }
  1274.         acb->next_ptr           = tp->acb_head;
  1275.         acb->trc_next_ptr       = TRC_POINTER(tp->acb_head);
  1276.         tp->acb_next            = tp->acb_head->next_ptr;
  1277.         tp->acb_curr            = tp->acb_head->next_ptr;
  1278.         tp->num_acbs_used       = 0;
  1279.         return (0);
  1280. }
  1281. static int smctr_init_adapter(struct net_device *dev)
  1282. {
  1283.         struct net_local *tp = (struct net_local *)dev->priv;
  1284.         int err;
  1285.         if(smctr_debug > 10)
  1286.                 printk("%s: smctr_init_adaptern", dev->name);
  1287.         tp->status              = CLOSED;
  1288.         tp->page_offset_mask    = (tp->ram_usable * 1024) - 1;
  1289.         skb_queue_head_init(&tp->SendSkbQueue);
  1290.         tp->QueueSkb = MAX_TX_QUEUE;
  1291.         if(!(tp->group_address_0 & 0x0080))
  1292.                 tp->group_address_0 |= 0x00C0;
  1293.         if(!(tp->functional_address_0 & 0x00C0))
  1294.                 tp->functional_address_0 |= 0x00C0;
  1295.         tp->functional_address[0] &= 0xFF7F;
  1296.         if(tp->authorized_function_classes == 0)
  1297.                 tp->authorized_function_classes = 0x7FFF;
  1298.         if(tp->authorized_access_priority == 0)
  1299.                 tp->authorized_access_priority = 0x06;
  1300.         smctr_disable_bic_int(dev);
  1301.         smctr_set_trc_reset(dev->base_addr);
  1302.         smctr_enable_16bit(dev);
  1303.         smctr_set_page(dev, (__u8 *)tp->ram_access);
  1304.         if(smctr_checksum_firmware(dev))
  1305. {
  1306.                 printk("%s: Previously loaded firmware is missingn",dev->name);                return (-ENOENT);
  1307.         }
  1308.         if((err = smctr_ram_memory_test(dev)))
  1309. {
  1310.                 printk("%s: RAM memory test failed.n", dev->name);
  1311.                 return (-EIO);
  1312.         }
  1313. smctr_set_rx_look_ahead(dev);
  1314.         smctr_load_node_addr(dev);
  1315.         /* Initialize adapter for Internal Self Test. */
  1316.         smctr_reset_adapter(dev);
  1317.         if((err = smctr_init_card_real(dev)))
  1318. {
  1319.                 printk("%s: Initialization of card failed (%d)n",
  1320.                         dev->name, err);
  1321.                 return (-EINVAL);
  1322.         }
  1323.         /* This routine clobbers the TRC's internal registers. */
  1324.         if((err = smctr_internal_self_test(dev)))
  1325. {
  1326.                 printk("%s: Card failed internal self test (%d)n",
  1327.                         dev->name, err);
  1328.                 return (-EINVAL);
  1329.         }
  1330.         /* Re-Initialize adapter's internal registers */
  1331.         smctr_reset_adapter(dev);
  1332.         if((err = smctr_init_card_real(dev)))
  1333. {
  1334.                 printk("%s: Initialization of card failed (%d)n",
  1335.                         dev->name, err);
  1336.                 return (-EINVAL);
  1337.         }
  1338.         smctr_enable_bic_int(dev);
  1339.         if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
  1340.                 return (err);
  1341.         smctr_disable_16bit(dev);
  1342.         return (0);
  1343. }
  1344. /* Dummy function */
  1345. static int __init smctr_init_card(struct net_device *dev)
  1346. {
  1347.         if(smctr_debug > 10)
  1348.                 printk("%s: smctr_init_cardn", dev->name);
  1349.         return (0);
  1350. }
  1351. static int smctr_init_card_real(struct net_device *dev)
  1352. {
  1353.         struct net_local *tp = (struct net_local *)dev->priv;
  1354.         int err = 0;
  1355.         if(smctr_debug > 10)
  1356.                 printk("%s: smctr_init_card_realn", dev->name);
  1357.         tp->sh_mem_used = 0;
  1358.         tp->num_acbs    = NUM_OF_ACBS;
  1359.         /* Range Check Max Packet Size */
  1360.         if(tp->max_packet_size < 256)
  1361.                 tp->max_packet_size = 256;
  1362.         else
  1363.         {
  1364.                 if(tp->max_packet_size > NON_MAC_TX_BUFFER_MEMORY)
  1365.                         tp->max_packet_size = NON_MAC_TX_BUFFER_MEMORY;
  1366.         }
  1367.         tp->num_of_tx_buffs = (NON_MAC_TX_BUFFER_MEMORY
  1368.                 / tp->max_packet_size) - 1;
  1369.         if(tp->num_of_tx_buffs > NUM_NON_MAC_TX_FCBS)
  1370.                 tp->num_of_tx_buffs = NUM_NON_MAC_TX_FCBS;
  1371.         else
  1372.         {
  1373.                 if(tp->num_of_tx_buffs == 0)
  1374.                         tp->num_of_tx_buffs = 1;
  1375.         }
  1376.         /* Tx queue constants */
  1377.         tp->num_tx_fcbs        [BUG_QUEUE]     = NUM_BUG_TX_FCBS;
  1378.         tp->num_tx_bdbs        [BUG_QUEUE]     = NUM_BUG_TX_BDBS;
  1379.         tp->tx_buff_size       [BUG_QUEUE]     = BUG_TX_BUFFER_MEMORY;
  1380.         tp->tx_buff_used       [BUG_QUEUE]     = 0;
  1381.         tp->tx_queue_status    [BUG_QUEUE]     = NOT_TRANSMITING;
  1382.         tp->num_tx_fcbs        [MAC_QUEUE]     = NUM_MAC_TX_FCBS;
  1383.         tp->num_tx_bdbs        [MAC_QUEUE]     = NUM_MAC_TX_BDBS;
  1384.         tp->tx_buff_size       [MAC_QUEUE]     = MAC_TX_BUFFER_MEMORY;
  1385.         tp->tx_buff_used       [MAC_QUEUE]     = 0;
  1386.         tp->tx_queue_status    [MAC_QUEUE]     = NOT_TRANSMITING;
  1387.         tp->num_tx_fcbs        [NON_MAC_QUEUE] = NUM_NON_MAC_TX_FCBS;
  1388.         tp->num_tx_bdbs        [NON_MAC_QUEUE] = NUM_NON_MAC_TX_BDBS;
  1389.         tp->tx_buff_size       [NON_MAC_QUEUE] = NON_MAC_TX_BUFFER_MEMORY;
  1390.         tp->tx_buff_used       [NON_MAC_QUEUE] = 0;
  1391.         tp->tx_queue_status    [NON_MAC_QUEUE] = NOT_TRANSMITING;
  1392.         /* Receive Queue Constants */
  1393.         tp->num_rx_fcbs[MAC_QUEUE] = NUM_MAC_RX_FCBS;
  1394.         tp->num_rx_bdbs[MAC_QUEUE] = NUM_MAC_RX_BDBS;
  1395.         if(tp->extra_info & CHIP_REV_MASK)
  1396.                 tp->num_rx_fcbs[NON_MAC_QUEUE] = 78;    /* 825 Rev. XE */
  1397.         else
  1398.                 tp->num_rx_fcbs[NON_MAC_QUEUE] = 7;     /* 825 Rev. XD */
  1399.         tp->num_rx_bdbs[NON_MAC_QUEUE] = smctr_get_num_rx_bdbs(dev);
  1400.         smctr_alloc_shared_memory(dev);
  1401.         smctr_init_shared_memory(dev);
  1402.         if((err = smctr_issue_init_timers_cmd(dev)))
  1403.                 return (err);
  1404.         if((err = smctr_issue_init_txrx_cmd(dev)))
  1405. {
  1406.                 printk("%s: Hardware failuren", dev->name);
  1407.                 return (err);
  1408.         }
  1409.         return (0);
  1410. }
  1411. static int smctr_init_rx_bdbs(struct net_device *dev)
  1412. {
  1413.         struct net_local *tp = (struct net_local *)dev->priv;
  1414.         unsigned int i, j;
  1415.         BDBlock *bdb;
  1416.         __u16 *buf;
  1417.         if(smctr_debug > 10)
  1418.                 printk("%s: smctr_init_rx_bdbsn", dev->name);
  1419.         for(i = 0; i < NUM_RX_QS_USED; i++)
  1420.         {
  1421.                 bdb = tp->rx_bdb_head[i];
  1422.                 buf = tp->rx_buff_head[i];
  1423.                 bdb->info = (BDB_CHAIN_END | BDB_NO_WARNING);
  1424.                 bdb->buffer_length = RX_DATA_BUFFER_SIZE;
  1425.                 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
  1426.                 bdb->data_block_ptr = buf;
  1427.                 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
  1428.                 if(i == NON_MAC_QUEUE)
  1429.                         bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
  1430.                 else
  1431.                         bdb->trc_data_block_ptr = TRC_POINTER(buf);
  1432.                 for(j = 1; j < tp->num_rx_bdbs[i]; j++)
  1433.                 {
  1434.                         bdb->next_ptr->back_ptr = bdb;
  1435.                         bdb = bdb->next_ptr;
  1436.                         buf = (__u16 *)((char *)buf + RX_DATA_BUFFER_SIZE);
  1437.                         bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
  1438.                         bdb->buffer_length = RX_DATA_BUFFER_SIZE;
  1439.                         bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
  1440.                         bdb->data_block_ptr = buf;
  1441.                         bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
  1442.                         if(i == NON_MAC_QUEUE)
  1443.                                 bdb->trc_data_block_ptr = RX_BUFF_TRC_POINTER(buf);
  1444.                         else
  1445.                                 bdb->trc_data_block_ptr = TRC_POINTER(buf);
  1446.                 }
  1447.                 bdb->next_ptr           = tp->rx_bdb_head[i];
  1448.                 bdb->trc_next_ptr       = TRC_POINTER(tp->rx_bdb_head[i]);
  1449.                 tp->rx_bdb_head[i]->back_ptr    = bdb;
  1450.                 tp->rx_bdb_curr[i]              = tp->rx_bdb_head[i]->next_ptr;
  1451.         }
  1452.         return (0);
  1453. }
  1454. static int smctr_init_rx_fcbs(struct net_device *dev)
  1455. {
  1456.         struct net_local *tp = (struct net_local *)dev->priv;
  1457.         unsigned int i, j;
  1458.         FCBlock *fcb;
  1459.         for(i = 0; i < NUM_RX_QS_USED; i++)
  1460.         {
  1461.                 fcb               = tp->rx_fcb_head[i];
  1462.                 fcb->frame_status = 0;
  1463.                 fcb->frame_length = 0;
  1464.                 fcb->info         = FCB_CHAIN_END;
  1465.                 fcb->next_ptr     = (FCBlock *)(((char*)fcb) + sizeof(FCBlock));
  1466.                 if(i == NON_MAC_QUEUE)
  1467.                         fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
  1468.                 else
  1469.                         fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
  1470.                 for(j = 1; j < tp->num_rx_fcbs[i]; j++)
  1471.                 {
  1472.                         fcb->next_ptr->back_ptr = fcb;
  1473.                         fcb                     = fcb->next_ptr;
  1474.                         fcb->frame_status       = 0;
  1475.                         fcb->frame_length       = 0;
  1476.                         fcb->info               = FCB_WARNING;
  1477.                         fcb->next_ptr
  1478.                                 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
  1479.                         if(i == NON_MAC_QUEUE)
  1480.                                 fcb->trc_next_ptr
  1481.                                         = RX_FCB_TRC_POINTER(fcb->next_ptr);
  1482.                         else
  1483.                                 fcb->trc_next_ptr
  1484.                                         = TRC_POINTER(fcb->next_ptr);
  1485.                 }
  1486.                 fcb->next_ptr = tp->rx_fcb_head[i];
  1487.                 if(i == NON_MAC_QUEUE)
  1488.                         fcb->trc_next_ptr = RX_FCB_TRC_POINTER(fcb->next_ptr);
  1489.                 else
  1490.                         fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
  1491.                 tp->rx_fcb_head[i]->back_ptr    = fcb;
  1492.                 tp->rx_fcb_curr[i]              = tp->rx_fcb_head[i]->next_ptr;
  1493.         }
  1494.         return(0);
  1495. }
  1496. static int smctr_init_shared_memory(struct net_device *dev)
  1497. {
  1498.         struct net_local *tp = (struct net_local *)dev->priv;
  1499.         unsigned int i;
  1500.         __u32 *iscpb;
  1501.         if(smctr_debug > 10)
  1502.                 printk("%s: smctr_init_shared_memoryn", dev->name);
  1503.         smctr_set_page(dev, (__u8 *)(unsigned int)tp->iscpb_ptr);
  1504.         /* Initialize Initial System Configuration Point. (ISCP) */
  1505.         iscpb = (__u32 *)PAGE_POINTER(&tp->iscpb_ptr->trc_scgb_ptr);
  1506.         *iscpb = (__u32)(SWAP_WORDS(TRC_POINTER(tp->scgb_ptr)));
  1507.         smctr_set_page(dev, (__u8 *)tp->ram_access);
  1508.         /* Initialize System Configuration Pointers. (SCP) */
  1509.         tp->scgb_ptr->config = (SCGB_ADDRESS_POINTER_FORMAT
  1510.                 | SCGB_MULTI_WORD_CONTROL | SCGB_DATA_FORMAT
  1511.                 | SCGB_BURST_LENGTH);
  1512.         tp->scgb_ptr->trc_sclb_ptr      = TRC_POINTER(tp->sclb_ptr);
  1513.         tp->scgb_ptr->trc_acb_ptr       = TRC_POINTER(tp->acb_head);
  1514.         tp->scgb_ptr->trc_isb_ptr       = TRC_POINTER(tp->isb_ptr);
  1515.         tp->scgb_ptr->isbsiz            = (sizeof(ISBlock)) - 2;
  1516.         /* Initialize System Control Block. (SCB) */
  1517.         tp->sclb_ptr->valid_command    = SCLB_VALID | SCLB_CMD_NOP;
  1518.         tp->sclb_ptr->iack_code        = 0;
  1519.         tp->sclb_ptr->resume_control   = 0;
  1520.         tp->sclb_ptr->int_mask_control = 0;
  1521.         tp->sclb_ptr->int_mask_state   = 0;
  1522.         /* Initialize Interrupt Status Block. (ISB) */
  1523.         for(i = 0; i < NUM_OF_INTERRUPTS; i++)
  1524.         {
  1525.                 tp->isb_ptr->IStatus[i].IType = 0xf0;
  1526.                 tp->isb_ptr->IStatus[i].ISubtype = 0;
  1527.         }
  1528.         tp->current_isb_index = 0;
  1529.         /* Initialize Action Command Block. (ACB) */
  1530.         smctr_init_acbs(dev);
  1531.         /* Initialize transmit FCB's and BDB's. */
  1532.         smctr_link_tx_fcbs_to_bdbs(dev);
  1533.         smctr_init_tx_bdbs(dev);
  1534.         smctr_init_tx_fcbs(dev);
  1535.         /* Initialize receive FCB's and BDB's. */
  1536.         smctr_init_rx_bdbs(dev);
  1537.         smctr_init_rx_fcbs(dev);
  1538.         return (0);
  1539. }
  1540. static int smctr_init_tx_bdbs(struct net_device *dev)
  1541. {
  1542.         struct net_local *tp = (struct net_local *)dev->priv;
  1543.         unsigned int i, j;
  1544.         BDBlock *bdb;
  1545.         for(i = 0; i < NUM_TX_QS_USED; i++)
  1546.         {
  1547.                 bdb = tp->tx_bdb_head[i];
  1548.                 bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
  1549.                 bdb->next_ptr = (BDBlock *)(((char *)bdb) + sizeof(BDBlock));
  1550.                 bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
  1551.                 for(j = 1; j < tp->num_tx_bdbs[i]; j++)
  1552.                 {
  1553.                         bdb->next_ptr->back_ptr = bdb;
  1554.                         bdb = bdb->next_ptr;
  1555.                         bdb->info = (BDB_NOT_CHAIN_END | BDB_NO_WARNING);
  1556.                         bdb->next_ptr
  1557.                                 = (BDBlock *)(((char *)bdb) + sizeof( BDBlock));                        bdb->trc_next_ptr = TRC_POINTER(bdb->next_ptr);
  1558.                 }
  1559.                 bdb->next_ptr = tp->tx_bdb_head[i];
  1560.                 bdb->trc_next_ptr = TRC_POINTER(tp->tx_bdb_head[i]);
  1561.                 tp->tx_bdb_head[i]->back_ptr = bdb;
  1562.         }
  1563.         return (0);
  1564. }
  1565. static int smctr_init_tx_fcbs(struct net_device *dev)
  1566. {
  1567.         struct net_local *tp = (struct net_local *)dev->priv;
  1568.         unsigned int i, j;
  1569.         FCBlock *fcb;
  1570.         for(i = 0; i < NUM_TX_QS_USED; i++)
  1571.         {
  1572.                 fcb               = tp->tx_fcb_head[i];
  1573.                 fcb->frame_status = 0;
  1574.                 fcb->frame_length = 0;
  1575.                 fcb->info         = FCB_CHAIN_END;
  1576.                 fcb->next_ptr = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
  1577.                 fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
  1578.                 for(j = 1; j < tp->num_tx_fcbs[i]; j++)
  1579.                 {
  1580.                         fcb->next_ptr->back_ptr = fcb;
  1581.                         fcb                     = fcb->next_ptr;
  1582.                         fcb->frame_status       = 0;
  1583.                         fcb->frame_length       = 0;
  1584.                         fcb->info               = FCB_CHAIN_END;
  1585.                         fcb->next_ptr
  1586.                                 = (FCBlock *)(((char *)fcb) + sizeof(FCBlock));
  1587.                         fcb->trc_next_ptr = TRC_POINTER(fcb->next_ptr);
  1588.                 }
  1589.                 fcb->next_ptr           = tp->tx_fcb_head[i];
  1590.                 fcb->trc_next_ptr       = TRC_POINTER(tp->tx_fcb_head[i]);
  1591.                 tp->tx_fcb_head[i]->back_ptr    = fcb;
  1592.                 tp->tx_fcb_end[i]               = tp->tx_fcb_head[i]->next_ptr;
  1593.                 tp->tx_fcb_curr[i]              = tp->tx_fcb_head[i]->next_ptr;
  1594.                 tp->num_tx_fcbs_used[i]         = 0;
  1595.         }
  1596.         return (0);
  1597. }
  1598. static int smctr_internal_self_test(struct net_device *dev)
  1599. {
  1600.         struct net_local *tp = (struct net_local *)dev->priv;
  1601.         int err;
  1602.         if((err = smctr_issue_test_internal_rom_cmd(dev)))
  1603.                 return (err);
  1604.         if((err = smctr_wait_cmd(dev)))
  1605.                 return (err);
  1606.         if(tp->acb_head->cmd_done_status & 0xff)
  1607.                 return (-1);
  1608.         if((err = smctr_issue_test_hic_cmd(dev)))
  1609.                 return (err);
  1610.         if((err = smctr_wait_cmd(dev)))
  1611.                 return (err);
  1612.         if(tp->acb_head->cmd_done_status & 0xff)
  1613.                 return (-1);
  1614.         if((err = smctr_issue_test_mac_reg_cmd(dev)))
  1615.                 return (err);
  1616.         if((err = smctr_wait_cmd(dev)))
  1617.                 return (err);
  1618.         if(tp->acb_head->cmd_done_status & 0xff)
  1619.                 return (-1);
  1620.         return (0);
  1621. }
  1622. /*
  1623.  * The typical workload of the driver: Handle the network interface interrupts.
  1624.  */
  1625. static void smctr_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  1626. {
  1627.         struct net_device *dev = dev_id;
  1628.         struct net_local *tp;
  1629.         int ioaddr;
  1630.         __u16 interrupt_unmask_bits = 0, interrupt_ack_code = 0xff00;
  1631.         __u16 err1, err = NOT_MY_INTERRUPT;
  1632.         __u8 isb_type, isb_subtype;
  1633.         __u16 isb_index;
  1634.         if(dev == NULL)
  1635.         {
  1636.                 printk("%s: irq %d for unknown device.n", dev->name, irq);
  1637.                 return;
  1638.         }
  1639.         ioaddr = dev->base_addr;
  1640.         tp = (struct net_local *)dev->priv;
  1641.         if(tp->status == NOT_INITIALIZED)
  1642.                 return;
  1643.         smctr_disable_bic_int(dev);
  1644.         smctr_enable_16bit(dev);
  1645.         smctr_clear_int(dev);
  1646.         /* First read the LSB */
  1647.         while((tp->isb_ptr->IStatus[tp->current_isb_index].IType & 0xf0) == 0)
  1648.         {
  1649.                 isb_index       = tp->current_isb_index;
  1650.                 isb_type        = tp->isb_ptr->IStatus[isb_index].IType;
  1651.                 isb_subtype     = tp->isb_ptr->IStatus[isb_index].ISubtype;
  1652.                 (tp->current_isb_index)++;
  1653.                 if(tp->current_isb_index == NUM_OF_INTERRUPTS)
  1654.                         tp->current_isb_index = 0;
  1655.                 if(isb_type >= 0x10)
  1656.                 {
  1657.                         smctr_disable_16bit(dev);
  1658.                         return;
  1659.                 }
  1660.                 err = HARDWARE_FAILED;
  1661.                 interrupt_ack_code = isb_index;
  1662.                 tp->isb_ptr->IStatus[isb_index].IType |= 0xf0;
  1663.                 interrupt_unmask_bits |= (1 << (__u16)isb_type);
  1664.                 switch(isb_type)
  1665.                 {
  1666.                         case ISB_IMC_MAC_TYPE_3:
  1667.                                 smctr_disable_16bit(dev);
  1668.                                 switch(isb_subtype)
  1669.                                 {
  1670.                                         case 0:
  1671.                                                 tp->monitor_state
  1672.                                                 = MS_MONITOR_FSM_INACTIVE;
  1673.                                                 break;
  1674.                                         case 1:
  1675.                                                 tp->monitor_state
  1676.                                                 = MS_REPEAT_BEACON_STATE;
  1677.                                                 break;
  1678.                                         case 2:
  1679.                                                 tp->monitor_state
  1680.                                                 = MS_REPEAT_CLAIM_TOKEN_STATE;
  1681.                                                 break;
  1682.                                         case 3:
  1683.                                                 tp->monitor_state
  1684.                                                 = MS_TRANSMIT_CLAIM_TOKEN_STATE;                                                break;
  1685.                                         case 4:
  1686.                                                 tp->monitor_state
  1687.                                                 = MS_STANDBY_MONITOR_STATE;
  1688.                                                 break;
  1689.                                         case 5:
  1690.                                                 tp->monitor_state
  1691.                                                 = MS_TRANSMIT_BEACON_STATE;
  1692.                                                 break;
  1693.                                         case 6:
  1694.                                                 tp->monitor_state
  1695.                                                 = MS_ACTIVE_MONITOR_STATE;
  1696.                                                 break;
  1697.                                         case 7:
  1698.                                                 tp->monitor_state
  1699.                                                 = MS_TRANSMIT_RING_PURGE_STATE;
  1700.                                                 break;
  1701.                                         case 8:   /* diagnostic state */
  1702.                                                 break;
  1703.                                         case 9:
  1704.                                                 tp->monitor_state
  1705.                                                 = MS_BEACON_TEST_STATE;
  1706.                                                 if(smctr_lobe_media_test(dev))
  1707.                                                 {
  1708.                                                         tp->ring_status_flags
  1709.                                                         = RING_STATUS_CHANGED;
  1710.                                                         tp->ring_status
  1711.                                                         = AUTO_REMOVAL_ERROR;
  1712.                                                         smctr_ring_status_chg(dev);
  1713.                                                         smctr_bypass_state(dev);
  1714.                                                 }
  1715.                                                 else
  1716.                                                         smctr_issue_insert_cmd(dev);
  1717.                                                 break;
  1718.                                         /* case 0x0a-0xff, illegal states */
  1719.                                         default:
  1720.                                                 break;
  1721.                                 }
  1722.                                 tp->ring_status_flags = MONITOR_STATE_CHANGED;
  1723.                                 err = smctr_ring_status_chg(dev);
  1724.                                 smctr_enable_16bit(dev);
  1725.                                 break;
  1726.                         /* Type 0x02 - MAC Error Counters Interrupt
  1727.                          * One or more MAC Error Counter is half full
  1728.                          *      MAC Error Counters
  1729.                          *      Lost_FR_Error_Counter
  1730.                          *      RCV_Congestion_Counter
  1731.                          *      FR_copied_Error_Counter
  1732.                          *      FREQ_Error_Counter
  1733.                          *      Token_Error_Counter
  1734.                          *      Line_Error_Counter
  1735.                          *      Internal_Error_Count
  1736.                          */
  1737.                         case ISB_IMC_MAC_ERROR_COUNTERS:
  1738.                                 /* Read 802.5 Error Counters */
  1739.                                 err = smctr_issue_read_ring_status_cmd(dev);
  1740.                                 break;
  1741.                         /* Type 0x04 - MAC Type 2 Interrupt
  1742.                          * HOST needs to enqueue MAC Frame for transmission
  1743.                          * SubType Bit 15 - RQ_INIT_PDU( Request Initialization)                         * Changed from RQ_INIT_PDU to
  1744.                          * TRC_Status_Changed_Indicate
  1745.                          */
  1746.                         case ISB_IMC_MAC_TYPE_2:
  1747.                                 err = smctr_issue_read_ring_status_cmd(dev);
  1748.                                 break;
  1749.                         /* Type 0x05 - TX Frame Interrupt (FI). */
  1750.                         case ISB_IMC_TX_FRAME:
  1751.                                 /* BUG QUEUE for TRC stuck receive BUG */
  1752.                                 if(isb_subtype & TX_PENDING_PRIORITY_2)
  1753.                                 {
  1754.                                         if((err = smctr_tx_complete(dev,
  1755.                                                 BUG_QUEUE)) != SUCCESS)
  1756.                                                 break;
  1757.                                 }
  1758.                                 /* NON-MAC frames only */
  1759.                                 if(isb_subtype & TX_PENDING_PRIORITY_1)
  1760.                                 {
  1761.                                         if((err = smctr_tx_complete(dev,
  1762.                                                 NON_MAC_QUEUE)) != SUCCESS)
  1763.                                                 break;
  1764.                                 }
  1765.                                 /* MAC frames only */
  1766.                                 if(isb_subtype & TX_PENDING_PRIORITY_0)
  1767.                                         err = smctr_tx_complete(dev, MAC_QUEUE);                                break;
  1768.                         /* Type 0x06 - TX END OF QUEUE (FE) */
  1769.                         case ISB_IMC_END_OF_TX_QUEUE:
  1770.                                 /* BUG queue */
  1771.                                 if(isb_subtype & TX_PENDING_PRIORITY_2)
  1772.                                 {
  1773.                                         /* ok to clear Receive FIFO overrun
  1774.                                          * imask send_BUG now completes.
  1775.                                          */
  1776.                                         interrupt_unmask_bits |= 0x800;
  1777.                                         tp->tx_queue_status[BUG_QUEUE]
  1778.                                                 = NOT_TRANSMITING;
  1779.                                         if((err = smctr_tx_complete(dev,
  1780.                                                 BUG_QUEUE)) != SUCCESS)
  1781.                                                 break;
  1782.                                         if((err = smctr_restart_tx_chain(dev,
  1783.                                                 BUG_QUEUE)) != SUCCESS)
  1784.                                                 break;
  1785.                                 }
  1786.                                 /* NON-MAC queue only */
  1787.                                 if(isb_subtype & TX_PENDING_PRIORITY_1)
  1788.                                 {
  1789.                                         tp->tx_queue_status[NON_MAC_QUEUE]
  1790.                                                 = NOT_TRANSMITING;
  1791.                                         if((err = smctr_tx_complete(dev,
  1792.                                                 NON_MAC_QUEUE)) != SUCCESS)
  1793.                                                 break;
  1794.                                         if((err = smctr_restart_tx_chain(dev,
  1795.                                                 NON_MAC_QUEUE)) != SUCCESS)
  1796.                                                 break;
  1797.                                 }
  1798.                                 /* MAC queue only */
  1799.                                 if(isb_subtype & TX_PENDING_PRIORITY_0)
  1800.                                 {
  1801.                                         tp->tx_queue_status[MAC_QUEUE]
  1802.                                                 = NOT_TRANSMITING;
  1803.                                         if((err = smctr_tx_complete(dev,
  1804.                                                 MAC_QUEUE)) != SUCCESS)
  1805.                                                 break;
  1806.                                         err = smctr_restart_tx_chain(dev,
  1807.                                                 MAC_QUEUE);
  1808.                                 }
  1809.                                 break;
  1810.                         /* Type 0x07 - NON-MAC RX Resource Interrupt
  1811.                          *   Subtype bit 12 - (BW) BDB warning
  1812.                          *   Subtype bit 13 - (FW) FCB warning
  1813.                          *   Subtype bit 14 - (BE) BDB End of chain
  1814.                          *   Subtype bit 15 - (FE) FCB End of chain
  1815.                          */
  1816.                         case ISB_IMC_NON_MAC_RX_RESOURCE:
  1817.                                 tp->rx_fifo_overrun_count = 0;
  1818.                                 tp->receive_queue_number = NON_MAC_QUEUE;
  1819.                                 err1 = smctr_rx_frame(dev);
  1820.                                 if(isb_subtype & NON_MAC_RX_RESOURCE_FE)
  1821.                                 {
  1822.                                         if((err = smctr_issue_resume_rx_fcb_cmd(                                                dev, NON_MAC_QUEUE)) != SUCCESS)                                                break;
  1823.                                         if(tp->ptr_rx_fcb_overruns)
  1824.                                                 (*tp->ptr_rx_fcb_overruns)++;
  1825.                                 }
  1826.                                 if(isb_subtype & NON_MAC_RX_RESOURCE_BE)
  1827.                                 {
  1828.                                         if((err = smctr_issue_resume_rx_bdb_cmd(                                                dev, NON_MAC_QUEUE)) != SUCCESS)                                                break;
  1829.                                         if(tp->ptr_rx_bdb_overruns)
  1830.                                                 (*tp->ptr_rx_bdb_overruns)++;
  1831.                                 }
  1832.                                 err = err1;
  1833.                                 break;
  1834.                         /* Type 0x08 - MAC RX Resource Interrupt
  1835.                          *   Subtype bit 12 - (BW) BDB warning
  1836.                          *   Subtype bit 13 - (FW) FCB warning
  1837.                          *   Subtype bit 14 - (BE) BDB End of chain
  1838.                          *   Subtype bit 15 - (FE) FCB End of chain
  1839.                          */
  1840.                         case ISB_IMC_MAC_RX_RESOURCE:
  1841.                                 tp->receive_queue_number = MAC_QUEUE;
  1842.                                 err1 = smctr_rx_frame(dev);
  1843.                                 if(isb_subtype & MAC_RX_RESOURCE_FE)
  1844.                                 {
  1845.                                         if((err = smctr_issue_resume_rx_fcb_cmd(                                                dev, MAC_QUEUE)) != SUCCESS)
  1846.                                                 break;
  1847.                                         if(tp->ptr_rx_fcb_overruns)
  1848.                                                 (*tp->ptr_rx_fcb_overruns)++;
  1849.                                 }
  1850.                                 if(isb_subtype & MAC_RX_RESOURCE_BE)
  1851.                                 {
  1852.                                         if((err = smctr_issue_resume_rx_bdb_cmd(                                                dev, MAC_QUEUE)) != SUCCESS)
  1853.                                                 break;
  1854.                                         if(tp->ptr_rx_bdb_overruns)
  1855.                                                 (*tp->ptr_rx_bdb_overruns)++;
  1856.                                 }
  1857.                                 err = err1;
  1858.                                 break;
  1859.                         /* Type 0x09 - NON_MAC RX Frame Interrupt */
  1860.                         case ISB_IMC_NON_MAC_RX_FRAME:
  1861.                                 tp->rx_fifo_overrun_count = 0;
  1862.                                 tp->receive_queue_number = NON_MAC_QUEUE;
  1863.                                 err = smctr_rx_frame(dev);
  1864.                                 break;
  1865.                         /* Type 0x0A - MAC RX Frame Interrupt */
  1866.                         case ISB_IMC_MAC_RX_FRAME:
  1867.                                 tp->receive_queue_number = MAC_QUEUE;
  1868.                                 err = smctr_rx_frame(dev);
  1869.                                 break;
  1870.                         /* Type 0x0B - TRC status
  1871.                          * TRC has encountered an error condition
  1872.                          * subtype bit 14 - transmit FIFO underrun
  1873.                          * subtype bit 15 - receive FIFO overrun
  1874.                          */
  1875.                         case ISB_IMC_TRC_FIFO_STATUS:
  1876.                                 if(isb_subtype & TRC_FIFO_STATUS_TX_UNDERRUN)
  1877.                                 {
  1878.                                         if(tp->ptr_tx_fifo_underruns)
  1879.                                                 (*tp->ptr_tx_fifo_underruns)++;
  1880.                                 }
  1881.                                 if(isb_subtype & TRC_FIFO_STATUS_RX_OVERRUN)
  1882.                                 {
  1883.                                         /* update overrun stuck receive counter
  1884.                                          * if >= 3, has to clear it by sending
  1885.                                          * back to back frames. We pick
  1886.                                          * DAT(duplicate address MAC frame)
  1887.                                          */
  1888.                                         tp->rx_fifo_overrun_count++;
  1889.                                         if(tp->rx_fifo_overrun_count >= 3)
  1890.                                         {
  1891.                                                 tp->rx_fifo_overrun_count = 0;
  1892.                                                 /* delay clearing fifo overrun
  1893.                                                  * imask till send_BUG tx
  1894.                                                  * complete posted
  1895.                                                  */
  1896.                                                 interrupt_unmask_bits &= (~0x800);
  1897.                                                 printk("Jay please send bugn");//                                              smctr_send_bug(dev);
  1898.                                         }
  1899.                                         if(tp->ptr_rx_fifo_overruns)
  1900.                                                 (*tp->ptr_rx_fifo_overruns)++;
  1901.                                 }
  1902.                                 err = SUCCESS;
  1903.                                 break;
  1904.                         /* Type 0x0C - Action Command Status Interrupt
  1905.                          * Subtype bit 14 - CB end of command chain (CE)
  1906.                          * Subtype bit 15 - CB command interrupt (CI)
  1907.                          */
  1908.                         case ISB_IMC_COMMAND_STATUS:
  1909.                                 err = SUCCESS;
  1910.                                 if(tp->acb_head->cmd == ACB_CMD_HIC_NOP)
  1911.                                 {
  1912.                                         printk("i1n");
  1913.                                         smctr_disable_16bit(dev);
  1914.                                         /* XXXXXXXXXXXXXXXXX */
  1915.                                 /*      err = UM_Interrupt(dev); */
  1916.                                         smctr_enable_16bit(dev);
  1917.                                 }
  1918.                                 else
  1919.                                 {
  1920.                                         if((tp->acb_head->cmd
  1921.                                                 == ACB_CMD_READ_TRC_STATUS)
  1922.                                                 && (tp->acb_head->subcmd
  1923.                                                 == RW_TRC_STATUS_BLOCK))
  1924.                                         {
  1925.                                                 if(tp->ptr_bcn_type != 0)
  1926.                                                 {
  1927.                                                         *(tp->ptr_bcn_type)
  1928.                                                                 = (__u32)((SBlock *)tp->misc_command_data)->BCN_Type;
  1929.                                                 }
  1930.                                                 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & ERROR_COUNTERS_CHANGED)
  1931.                                                 {
  1932.                                                         smctr_update_err_stats(dev);
  1933.                                                 }
  1934.                                                 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & TI_NDIS_RING_STATUS_CHANGED)
  1935.                                                 {
  1936.                                                         tp->ring_status
  1937.                                                                 = ((SBlock*)tp->misc_command_data)->TI_NDIS_Ring_Status;
  1938.                                                         smctr_disable_16bit(dev);
  1939.                                                         err = smctr_ring_status_chg(dev);
  1940.                                                         smctr_enable_16bit(dev);
  1941.                                                         if((tp->ring_status & REMOVE_RECEIVED)
  1942.                                                                 && (tp->config_word0 & NO_AUTOREMOVE))
  1943.                                                         {
  1944.                                                                 smctr_issue_remove_cmd(dev);
  1945.                                                         }
  1946.                                                         if(err != SUCCESS)
  1947.                                                         {
  1948.                                                                 tp->acb_pending
  1949. = 0;
  1950.                                                                 break;
  1951.                                                         }
  1952.                                                 }
  1953.                                                 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate & UNA_CHANGED)
  1954.                                                 {
  1955.                                                         if(tp->ptr_una)
  1956.                                                         {
  1957.                                                                 tp->ptr_una[0]
  1958.                                                                         = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[0]);
  1959.                                                                 tp->ptr_una[1]
  1960.                                                                         = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[1]);
  1961.                                                                 tp->ptr_una[2]
  1962.                                                                         = SWAP_BYTES(((SBlock *)tp->misc_command_data)->UNA[2]);
  1963.                                                         }
  1964.                                                 }
  1965.                                                 if(((SBlock *)tp->misc_command_data)->Status_CHG_Indicate
  1966.                                                         & READY_TO_SEND_RQ_INIT)                                                {
  1967.                                                         err = smctr_send_rq_init(dev);
  1968.                                                 }
  1969.                                         }
  1970.                                 }
  1971.                                 tp->acb_pending = 0;
  1972.                                 break;
  1973.                         /* Type 0x0D - MAC Type 1 interrupt
  1974.                          * Subtype -- 00 FR_BCN received at S12
  1975.                          *            01 FR_BCN received at S21
  1976.                          *            02 FR_DAT(DA=MA, A<>0) received at S21
  1977.                          *            03 TSM_EXP at S21
  1978.                          *            04 FR_REMOVE received at S42
  1979.                          *            05 TBR_EXP, BR_FLAG_SET at S42
  1980.                          *            06 TBT_EXP at S53
  1981.                          */
  1982.                         case ISB_IMC_MAC_TYPE_1:
  1983.                                 if(isb_subtype > 8)
  1984.                                 {
  1985.                                         err = HARDWARE_FAILED;
  1986.                                         break;
  1987.                                 }
  1988.                                 err = SUCCESS;
  1989.                                 switch(isb_subtype)
  1990.                                 {
  1991.                                         case 0:
  1992.                                                 tp->join_state = JS_BYPASS_STATE;
  1993.                                                 if(tp->status != CLOSED)
  1994.                                                 {
  1995.                                                         tp->status = CLOSED;
  1996.                                                         err = smctr_status_chg(dev);
  1997.                                                 }
  1998.                                                 break;
  1999.                                         case 1:
  2000.                                                 tp->join_state
  2001.                                                         = JS_LOBE_TEST_STATE;
  2002.                                                 break;
  2003.                                         case 2:
  2004.                                                 tp->join_state
  2005.                                                         = JS_DETECT_MONITOR_PRESENT_STATE;
  2006.                                                 break;
  2007.                                         case 3:
  2008.                                                 tp->join_state
  2009.                                                         = JS_AWAIT_NEW_MONITOR_STATE;
  2010.                                                 break;
  2011.                                         case 4:
  2012.                                                 tp->join_state
  2013.                                                         = JS_DUPLICATE_ADDRESS_TEST_STATE;
  2014.                                                 break;
  2015.                                         case 5:
  2016.                                                 tp->join_state
  2017.                                                         = JS_NEIGHBOR_NOTIFICATION_STATE;
  2018.                                                 break;
  2019.                                         case 6:
  2020.                                                 tp->join_state
  2021.                                                         = JS_REQUEST_INITIALIZATION_STATE;
  2022.                                                 break;
  2023.                                         case 7:
  2024.                                                 tp->join_state
  2025.                                                         = JS_JOIN_COMPLETE_STATE;
  2026.                                                 tp->status = OPEN;
  2027.                                                 err = smctr_status_chg(dev);
  2028.                                                 break;
  2029.                                         case 8:
  2030.                                                 tp->join_state
  2031.                                                         = JS_BYPASS_WAIT_STATE;
  2032.                                                 break;
  2033.                                 }
  2034.                                 break ;
  2035.                         /* Type 0x0E - TRC Initialization Sequence Interrupt
  2036.                          * Subtype -- 00-FF Initializatin sequence complete
  2037.                          */
  2038.                         case ISB_IMC_TRC_INTRNL_TST_STATUS:
  2039.                                 tp->status = INITIALIZED;
  2040.                                 smctr_disable_16bit(dev);
  2041.                                 err = smctr_status_chg(dev);
  2042.                                 smctr_enable_16bit(dev);
  2043.                                 break;
  2044.                         /* other interrupt types, illegal */
  2045.                         default:
  2046.                                 break;
  2047.                 }
  2048.                 if(err != SUCCESS)
  2049.                         break;
  2050.         }
  2051.         /* Checking the ack code instead of the unmask bits here is because :
  2052.          * while fixing the stuck receive, DAT frame are sent and mask off
  2053.          * FIFO overrun interrupt temporarily (interrupt_unmask_bits = 0)
  2054.          * but we still want to issue ack to ISB
  2055.          */
  2056.         if(!(interrupt_ack_code & 0xff00))
  2057.                 smctr_issue_int_ack(dev, interrupt_ack_code,
  2058.                         interrupt_unmask_bits);
  2059.         smctr_disable_16bit(dev);
  2060.         smctr_enable_bic_int(dev);
  2061.         return;
  2062. }
  2063. static int smctr_issue_enable_int_cmd(struct net_device *dev,
  2064.         __u16 interrupt_enable_mask)
  2065. {
  2066.         struct net_local *tp = (struct net_local *)dev->priv;
  2067.         int err;
  2068.         if((err = smctr_wait_while_cbusy(dev)))
  2069.                 return (err);
  2070.         tp->sclb_ptr->int_mask_control  = interrupt_enable_mask;
  2071.         tp->sclb_ptr->valid_command     = SCLB_VALID
  2072.                 | SCLB_CMD_CLEAR_INTERRUPT_MASK;
  2073.         smctr_set_ctrl_attention(dev);
  2074.         return (0);
  2075. }
  2076. static int smctr_issue_int_ack(struct net_device *dev, __u16 iack_code,
  2077.         __u16 ibits)
  2078. {
  2079.         struct net_local *tp = (struct net_local *)dev->priv;
  2080.         if(smctr_wait_while_cbusy(dev))
  2081.                 return (-1);
  2082.         tp->sclb_ptr->int_mask_control = ibits;
  2083.         tp->sclb_ptr->iack_code = iack_code << 1; /* use the offset from base */        tp->sclb_ptr->resume_control = 0;
  2084.         tp->sclb_ptr->valid_command =
  2085.                 SCLB_VALID | SCLB_IACK_CODE_VALID
  2086.                 | SCLB_CMD_CLEAR_INTERRUPT_MASK;
  2087.         smctr_set_ctrl_attention(dev);
  2088.         return (0);
  2089. }
  2090. static int smctr_issue_init_timers_cmd(struct net_device *dev)
  2091. {
  2092.         struct net_local *tp = (struct net_local *)dev->priv;
  2093.         unsigned int i;
  2094.         int err;
  2095.         __u16 *pTimer_Struc = (__u16 *)tp->misc_command_data;
  2096.         if((err = smctr_wait_while_cbusy(dev)))
  2097.                 return (err);
  2098.         if((err = smctr_wait_cmd(dev)))
  2099.                 return (err);
  2100.         tp->config_word0 = THDREN | DMA_TRIGGER | USETPT | NO_AUTOREMOVE;
  2101.         tp->config_word1 = 0;
  2102.         if((tp->media_type == MEDIA_STP_16)
  2103.                 || (tp->media_type == MEDIA_UTP_16)
  2104.                 || (tp->media_type == MEDIA_STP_16_UTP_16))
  2105.         {
  2106.                 tp->config_word0 |= FREQ_16MB_BIT;
  2107.         }
  2108.         if(tp->mode_bits & EARLY_TOKEN_REL)
  2109.                 tp->config_word0 |= ETREN;
  2110.         if(tp->mode_bits & LOOPING_MODE_MASK)
  2111.                 tp->config_word0 |= RX_OWN_BIT;
  2112.         else
  2113.                 tp->config_word0 &= ~RX_OWN_BIT;
  2114.         if(tp->receive_mask & PROMISCUOUS_MODE)
  2115.                 tp->config_word0 |= PROMISCUOUS_BIT;
  2116.         else
  2117.                 tp->config_word0 &= ~PROMISCUOUS_BIT;
  2118.         if(tp->receive_mask & ACCEPT_ERR_PACKETS)
  2119.                 tp->config_word0 |= SAVBAD_BIT;
  2120.         else
  2121.                 tp->config_word0 &= ~SAVBAD_BIT;
  2122.         if(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
  2123.                 tp->config_word0 |= RXATMAC;
  2124.         else
  2125.                 tp->config_word0 &= ~RXATMAC;
  2126.         if(tp->receive_mask & ACCEPT_MULTI_PROM)
  2127.                 tp->config_word1 |= MULTICAST_ADDRESS_BIT;
  2128.         else
  2129.                 tp->config_word1 &= ~MULTICAST_ADDRESS_BIT;
  2130.         if(tp->receive_mask & ACCEPT_SOURCE_ROUTING_SPANNING)
  2131.                 tp->config_word1 |= SOURCE_ROUTING_SPANNING_BITS;
  2132.         else
  2133.         {
  2134.                 if(tp->receive_mask & ACCEPT_SOURCE_ROUTING)
  2135.                         tp->config_word1 |= SOURCE_ROUTING_EXPLORER_BIT;
  2136.                 else
  2137.                         tp->config_word1 &= ~SOURCE_ROUTING_SPANNING_BITS;
  2138.         }
  2139.         if((tp->media_type == MEDIA_STP_16)
  2140.                 || (tp->media_type == MEDIA_UTP_16)
  2141.                 || (tp->media_type == MEDIA_STP_16_UTP_16))
  2142.         {
  2143.                 tp->config_word1 |= INTERFRAME_SPACING_16;
  2144.         }
  2145.         else
  2146.                 tp->config_word1 |= INTERFRAME_SPACING_4;
  2147.         *pTimer_Struc++ = tp->config_word0;
  2148.         *pTimer_Struc++ = tp->config_word1;
  2149.         if((tp->media_type == MEDIA_STP_4)
  2150.                 || (tp->media_type == MEDIA_UTP_4)
  2151.                 || (tp->media_type == MEDIA_STP_4_UTP_4))
  2152.         {
  2153.                 *pTimer_Struc++ = 0x00FA;       /* prescale */
  2154.                 *pTimer_Struc++ = 0x2710;       /* TPT_limit */
  2155.                 *pTimer_Struc++ = 0x2710;       /* TQP_limit */
  2156.                 *pTimer_Struc++ = 0x0A28;       /* TNT_limit */
  2157.                 *pTimer_Struc++ = 0x3E80;       /* TBT_limit */
  2158.                 *pTimer_Struc++ = 0x3A98;       /* TSM_limit */
  2159.                 *pTimer_Struc++ = 0x1B58;       /* TAM_limit */
  2160.                 *pTimer_Struc++ = 0x00C8;       /* TBR_limit */
  2161.                 *pTimer_Struc++ = 0x07D0;       /* TER_limit */
  2162.                 *pTimer_Struc++ = 0x000A;       /* TGT_limit */
  2163.                 *pTimer_Struc++ = 0x1162;       /* THT_limit */
  2164.                 *pTimer_Struc++ = 0x07D0;       /* TRR_limit */
  2165.                 *pTimer_Struc++ = 0x1388;       /* TVX_limit */
  2166.                 *pTimer_Struc++ = 0x0000;       /* reserved */
  2167.         }
  2168.         else
  2169.         {
  2170.                 *pTimer_Struc++ = 0x03E8;       /* prescale */
  2171.                 *pTimer_Struc++ = 0x9C40;       /* TPT_limit */
  2172.                 *pTimer_Struc++ = 0x9C40;       /* TQP_limit */
  2173.                 *pTimer_Struc++ = 0x0A28;       /* TNT_limit */
  2174.                 *pTimer_Struc++ = 0x3E80;       /* TBT_limit */
  2175.                 *pTimer_Struc++ = 0x3A98;       /* TSM_limit */
  2176.                 *pTimer_Struc++ = 0x1B58;       /* TAM_limit */
  2177.                 *pTimer_Struc++ = 0x00C8;       /* TBR_limit */
  2178.                 *pTimer_Struc++ = 0x07D0;       /* TER_limit */
  2179.                 *pTimer_Struc++ = 0x000A;       /* TGT_limit */
  2180.                 *pTimer_Struc++ = 0x4588;       /* THT_limit */
  2181.                 *pTimer_Struc++ = 0x1F40;       /* TRR_limit */
  2182.                 *pTimer_Struc++ = 0x4E20;       /* TVX_limit */
  2183.                 *pTimer_Struc++ = 0x0000;       /* reserved */
  2184.         }
  2185.         /* Set node address. */
  2186.         *pTimer_Struc++ = dev->dev_addr[0] << 8
  2187.                 | (dev->dev_addr[1] & 0xFF);
  2188.         *pTimer_Struc++ = dev->dev_addr[2] << 8
  2189.                 | (dev->dev_addr[3] & 0xFF);
  2190.         *pTimer_Struc++ = dev->dev_addr[4] << 8
  2191.                 | (dev->dev_addr[5] & 0xFF);
  2192.         /* Set group address. */
  2193.         *pTimer_Struc++ = tp->group_address_0 << 8
  2194.                 | tp->group_address_0 >> 8;
  2195.         *pTimer_Struc++ = tp->group_address[0] << 8
  2196.                 | tp->group_address[0] >> 8;
  2197.         *pTimer_Struc++ = tp->group_address[1] << 8
  2198.                 | tp->group_address[1] >> 8;
  2199.         /* Set functional address. */
  2200.         *pTimer_Struc++ = tp->functional_address_0 << 8
  2201.                 | tp->functional_address_0 >> 8;
  2202.         *pTimer_Struc++ = tp->functional_address[0] << 8
  2203.                 | tp->functional_address[0] >> 8;
  2204.         *pTimer_Struc++ = tp->functional_address[1] << 8
  2205.                 | tp->functional_address[1] >> 8;
  2206.         /* Set Bit-Wise group address. */
  2207.         *pTimer_Struc++ = tp->bitwise_group_address[0] << 8
  2208.                 | tp->bitwise_group_address[0] >> 8;
  2209.         *pTimer_Struc++ = tp->bitwise_group_address[1] << 8
  2210.                 | tp->bitwise_group_address[1] >> 8;
  2211.         /* Set ring number address. */
  2212.         *pTimer_Struc++ = tp->source_ring_number;
  2213.         *pTimer_Struc++ = tp->target_ring_number;
  2214.         /* Physical drop number. */
  2215.         *pTimer_Struc++ = (unsigned short)0;
  2216.         *pTimer_Struc++ = (unsigned short)0;
  2217.         /* Product instance ID. */
  2218.         for(i = 0; i < 9; i++)
  2219.                 *pTimer_Struc++ = (unsigned short)0;
  2220.         err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TRC_TIMERS, 0);
  2221.         return (err);
  2222. }
  2223. static int smctr_issue_init_txrx_cmd(struct net_device *dev)
  2224. {
  2225.         struct net_local *tp = (struct net_local *)dev->priv;
  2226.         unsigned int i;
  2227.         int err;
  2228.         void **txrx_ptrs = (void *)tp->misc_command_data;
  2229.         if((err = smctr_wait_while_cbusy(dev)))
  2230.                 return (err);
  2231.         if((err = smctr_wait_cmd(dev)))
  2232. {
  2233.                 printk("%s: Hardware failuren", dev->name);
  2234.                 return (err);
  2235.         }
  2236.         /* Initialize Transmit Queue Pointers that are used, to point to
  2237.          * a single FCB.
  2238.          */
  2239.         for(i = 0; i < NUM_TX_QS_USED; i++)
  2240.                 *txrx_ptrs++ = (void *)TRC_POINTER(tp->tx_fcb_head[i]);
  2241.         /* Initialize Transmit Queue Pointers that are NOT used to ZERO. */
  2242.         for(; i < MAX_TX_QS; i++)
  2243.                 *txrx_ptrs++ = (void *)0;
  2244.         /* Initialize Receive Queue Pointers (MAC and Non-MAC) that are
  2245.          * used, to point to a single FCB and a BDB chain of buffers.
  2246.          */
  2247.         for(i = 0; i < NUM_RX_QS_USED; i++)
  2248.         {
  2249.                 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_fcb_head[i]);
  2250.                 *txrx_ptrs++ = (void *)TRC_POINTER(tp->rx_bdb_head[i]);
  2251.         }
  2252.         /* Initialize Receive Queue Pointers that are NOT used to ZERO. */
  2253.         for(; i < MAX_RX_QS; i++)
  2254.         {
  2255.                 *txrx_ptrs++ = (void *)0;
  2256.                 *txrx_ptrs++ = (void *)0;
  2257.         }
  2258.         err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_INIT_TX_RX, 0);
  2259.         return (err);
  2260. }
  2261. static int smctr_issue_insert_cmd(struct net_device *dev)
  2262. {
  2263.         int err;
  2264.         err = smctr_setup_single_cmd(dev, ACB_CMD_INSERT, ACB_SUB_CMD_NOP);
  2265.         return (err);
  2266. }
  2267. static int smctr_issue_read_ring_status_cmd(struct net_device *dev)
  2268. {
  2269.         int err;
  2270.         if((err = smctr_wait_while_cbusy(dev)))
  2271.                 return (err);
  2272.         if((err = smctr_wait_cmd(dev)))
  2273.                 return (err);
  2274.         err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_READ_TRC_STATUS,
  2275.                 RW_TRC_STATUS_BLOCK);
  2276.         return (err);
  2277. }
  2278. static int smctr_issue_read_word_cmd(struct net_device *dev, __u16 aword_cnt)
  2279. {
  2280.         int err;
  2281.         if((err = smctr_wait_while_cbusy(dev)))
  2282.                 return (err);
  2283.         if((err = smctr_wait_cmd(dev)))
  2284.                 return (err);
  2285.         err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_READ_VALUE,
  2286.                 aword_cnt);
  2287.         return (err);
  2288. }
  2289. static int smctr_issue_remove_cmd(struct net_device *dev)
  2290. {
  2291.         struct net_local *tp = (struct net_local *)dev->priv;
  2292.         int err;
  2293.         if((err = smctr_wait_while_cbusy(dev)))
  2294.                 return (err);
  2295.         tp->sclb_ptr->resume_control    = 0;
  2296.         tp->sclb_ptr->valid_command     = SCLB_VALID | SCLB_CMD_REMOVE;
  2297.         smctr_set_ctrl_attention(dev);
  2298.         return (0);
  2299. }
  2300. static int smctr_issue_resume_acb_cmd(struct net_device *dev)
  2301. {
  2302.         struct net_local *tp = (struct net_local *)dev->priv;
  2303.         int err;
  2304.         if((err = smctr_wait_while_cbusy(dev)))
  2305.                 return (err);
  2306.         tp->sclb_ptr->resume_control = SCLB_RC_ACB;
  2307.         tp->sclb_ptr->valid_command  = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
  2308.         tp->acb_pending = 1;
  2309.         smctr_set_ctrl_attention(dev);
  2310.         return (0);
  2311. }
  2312. static int smctr_issue_resume_rx_bdb_cmd(struct net_device *dev, __u16 queue)
  2313. {
  2314.         struct net_local *tp = (struct net_local *)dev->priv;
  2315.         int err;
  2316.         if((err = smctr_wait_while_cbusy(dev)))
  2317.                 return (err);
  2318.         if(queue == MAC_QUEUE)
  2319.                 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_BDB;
  2320.         else
  2321.                 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_BDB;
  2322.         tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
  2323.         smctr_set_ctrl_attention(dev);
  2324.         return (0);
  2325. }
  2326. static int smctr_issue_resume_rx_fcb_cmd(struct net_device *dev, __u16 queue)
  2327. {
  2328.         struct net_local *tp = (struct net_local *)dev->priv;
  2329.         if(smctr_debug > 10)
  2330.                 printk("%s: smctr_issue_resume_rx_fcb_cmdn", dev->name);
  2331.         if(smctr_wait_while_cbusy(dev))
  2332.                 return (-1);
  2333.         if(queue == MAC_QUEUE)
  2334.                 tp->sclb_ptr->resume_control = SCLB_RC_RX_MAC_FCB;
  2335.         else
  2336.                 tp->sclb_ptr->resume_control = SCLB_RC_RX_NON_MAC_FCB;
  2337.         tp->sclb_ptr->valid_command = SCLB_VALID | SCLB_RESUME_CONTROL_VALID;
  2338.         smctr_set_ctrl_attention(dev);
  2339.         return (0);
  2340. }
  2341. static int smctr_issue_resume_tx_fcb_cmd(struct net_device *dev, __u16 queue)
  2342. {
  2343.         struct net_local *tp = (struct net_local *)dev->priv;
  2344.         if(smctr_debug > 10)
  2345.                 printk("%s: smctr_issue_resume_tx_fcb_cmdn", dev->name);
  2346.         if(smctr_wait_while_cbusy(dev))
  2347.                 return (-1);
  2348.         tp->sclb_ptr->resume_control = (SCLB_RC_TFCB0 << queue);
  2349.         tp->sclb_ptr->valid_command = SCLB_RESUME_CONTROL_VALID | SCLB_VALID;
  2350.         smctr_set_ctrl_attention(dev);
  2351.         return (0);
  2352. }
  2353. static int smctr_issue_test_internal_rom_cmd(struct net_device *dev)
  2354. {