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

嵌入式Linux

开发平台:

Unix_Linux

  1.         int err;
  2.         err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
  3.                 TRC_INTERNAL_ROM_TEST);
  4.         return (err);
  5. }
  6. static int smctr_issue_test_hic_cmd(struct net_device *dev)
  7. {
  8.         int err;
  9.         err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
  10.                 TRC_HOST_INTERFACE_REG_TEST);
  11.         return (err);
  12. }
  13. static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
  14. {
  15.         int err;
  16.         err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
  17.                 TRC_MAC_REGISTERS_TEST);
  18.         return (err);
  19. }
  20. static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
  21. {
  22.         int err;
  23.         err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
  24.                 TRC_INTERNAL_LOOPBACK);
  25.         return (err);
  26. }
  27. static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
  28. {
  29.         int err;
  30.         err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
  31.                 TRC_TRI_LOOPBACK);
  32.         return (err);
  33. }
  34. static int smctr_issue_write_byte_cmd(struct net_device *dev,
  35.         short aword_cnt, void *byte)
  36. {
  37. struct net_local *tp = (struct net_local *)dev->priv;
  38.         unsigned int iword, ibyte;
  39. int err;
  40.         if((err = smctr_wait_while_cbusy(dev)))
  41.                 return (err);
  42.         if((err = smctr_wait_cmd(dev)))
  43.                 return (err);
  44.         for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
  45.          iword++, ibyte += 2)
  46.         {
  47.                 tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
  48. | (*((__u8 *)byte + ibyte + 1));
  49.         }
  50.         return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE, 
  51. aword_cnt));
  52. }
  53. static int smctr_issue_write_word_cmd(struct net_device *dev,
  54.         short aword_cnt, void *word)
  55. {
  56.         struct net_local *tp = (struct net_local *)dev->priv;
  57.         unsigned int i, err;
  58.         if((err = smctr_wait_while_cbusy(dev)))
  59.                 return (err);
  60.         if((err = smctr_wait_cmd(dev)))
  61.                 return (err);
  62.         for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
  63.                 tp->misc_command_data[i] = *((__u16 *)word + i);
  64.         err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
  65.                 aword_cnt);
  66.         return (err);
  67. }
  68. static int smctr_join_complete_state(struct net_device *dev)
  69. {
  70.         int err;
  71.         err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
  72.                 JS_JOIN_COMPLETE_STATE);
  73.         return (err);
  74. }
  75. static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
  76. {
  77.         struct net_local *tp = (struct net_local *)dev->priv;
  78.         unsigned int i, j;
  79.         FCBlock *fcb;
  80.         BDBlock *bdb;
  81.         for(i = 0; i < NUM_TX_QS_USED; i++)
  82.         {
  83.                 fcb = tp->tx_fcb_head[i];
  84.                 bdb = tp->tx_bdb_head[i];
  85.                 for(j = 0; j < tp->num_tx_fcbs[i]; j++)
  86.                 {
  87.                         fcb->bdb_ptr            = bdb;
  88.                         fcb->trc_bdb_ptr        = TRC_POINTER(bdb);
  89.                         fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
  90.                         bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
  91.                 }
  92.         }
  93.         return (0);
  94. }
  95. static int smctr_load_firmware(struct net_device *dev)
  96. {
  97.         struct net_local *tp = (struct net_local *)dev->priv;
  98.         __u16 i, checksum = 0;
  99.         int err = 0;
  100.         if(smctr_debug > 10)
  101.                 printk("%s: smctr_load_firmwaren", dev->name);
  102.         tp->ptr_ucode           = smctr_code;
  103.         tp->num_of_tx_buffs     = 4;
  104.         tp->mode_bits          |= UMAC;
  105.         tp->receive_mask        = 0;
  106.         tp->max_packet_size     = 4177;
  107.         /* Can only upload the firmware once per adapter reset. */
  108.         if(tp->microcode_version != 0)
  109.                 return (UCODE_PRESENT);
  110.         /* Verify the firmware exists and is there in the right amount. */
  111.         if((tp->ptr_ucode == 0L)
  112.                 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET) < UCODE_VERSION))
  113.         {
  114.                 return (UCODE_NOT_PRESENT);
  115.         }
  116.         /* UCODE_SIZE is not included in Checksum. */
  117.         for(i = 0; i < *((__u16 *)(tp->ptr_ucode + UCODE_SIZE_OFFSET)); i += 2)
  118.                 checksum += *((__u16 *)(tp->ptr_ucode + 2 + i));
  119.         if(checksum)
  120.                 return (UCODE_NOT_PRESENT);
  121.         /* At this point we have a valid firmware image, lets kick it on up. */
  122.         smctr_enable_adapter_ram(dev);
  123.         smctr_enable_16bit(dev);
  124.         smctr_set_page(dev, (__u8 *)tp->ram_access);
  125.         if((smctr_checksum_firmware(dev))
  126.                 || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET)
  127.                 > tp->microcode_version))
  128.         {
  129.                 smctr_enable_adapter_ctrl_store(dev);
  130.                 /* Zero out ram space for firmware. */
  131.                 for(i = 0; i < CS_RAM_SIZE; i += 2)
  132.                         *((__u16 *)(tp->ram_access + i)) = 0;
  133.                 smctr_decode_firmware(dev);
  134.                 tp->microcode_version = *(tp->ptr_ucode + UCODE_VERSION_OFFSET);                *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
  135.                         = (tp->microcode_version << 8);
  136.                 *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
  137.                         = ~(tp->microcode_version << 8) + 1;
  138.                 smctr_disable_adapter_ctrl_store(dev);
  139.                 if(smctr_checksum_firmware(dev))
  140.                         err = HARDWARE_FAILED;
  141.         }
  142.         else
  143.                 err = UCODE_PRESENT;
  144.         smctr_disable_16bit(dev);
  145.         return (err);
  146. }
  147. static int smctr_load_node_addr(struct net_device *dev)
  148. {
  149.         int ioaddr = dev->base_addr;
  150.         unsigned int i;
  151.         __u8 r;
  152.         /* Check if node address has been specified by user. (non-0) */
  153.         for(i = 0; ((i < 6) && (dev->dev_addr[i] == 0)); i++);
  154.         {
  155.                 if(i != 6)
  156.                 {
  157.                         for(i = 0; i < 6; i++)
  158.                         {
  159.                                 r = inb(ioaddr + LAR0 + i);
  160.                                 dev->dev_addr[i] = (char)r;
  161.                         }
  162.                         dev->addr_len = 6;
  163.                 }
  164.                 else    /* Node addr. not given by user, read it from board. */
  165.                 {
  166.                         for(i = 0; i < 6; i++)
  167.                         {
  168.                                 r = inb(ioaddr + LAR0 + i);
  169.                                 dev->dev_addr[i] = (char)r;
  170.                         }
  171.                         dev->addr_len = 6;
  172.                 }
  173.         }
  174.         return (0);
  175. }
  176. /* Lobe Media Test.
  177.  * During the transmission of the initial 1500 lobe media MAC frames,
  178.  * the phase lock loop in the 805 chip may lock, and then un-lock, causing
  179.  * the 825 to go into a PURGE state. When performing a PURGE, the MCT
  180.  * microcode will not transmit any frames given to it by the host, and
  181.  * will consequently cause a timeout.
  182.  *
  183.  * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
  184.  * queues other then the one used for the lobe_media_test should be
  185.  * disabled.!?
  186.  *
  187.  * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
  188.  * has any multi-cast or promiscous bits set, the receive_mask needs to
  189.  * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
  190.  * run, and then the receive mask set back to its original value if the test
  191.  * is successful.
  192.  */
  193. static int smctr_lobe_media_test(struct net_device *dev)
  194. {
  195.         struct net_local *tp = (struct net_local *)dev->priv;
  196.         unsigned int i, perror = 0;
  197.         unsigned short saved_rcv_mask;
  198.         if(smctr_debug > 10)
  199.                 printk("%s: smctr_lobe_media_testn", dev->name);
  200.         /* Clear receive mask for lobe test. */
  201.         saved_rcv_mask          = tp->receive_mask;
  202.         tp->receive_mask        = 0;
  203.         smctr_chg_rx_mask(dev);
  204.         /* Setup the lobe media test. */
  205.         smctr_lobe_media_test_cmd(dev);
  206.         if(smctr_wait_cmd(dev))
  207.         {
  208.                 smctr_reset_adapter(dev);
  209.                 tp->status = CLOSED;
  210.                 return (LOBE_MEDIA_TEST_FAILED);
  211.         }
  212.         /* Tx lobe media test frames. */
  213.         for(i = 0; i < 1500; ++i)
  214.         {
  215.                 if(smctr_send_lobe_media_test(dev))
  216.                 {
  217.                         if(perror)
  218.                         {
  219.                                 smctr_reset_adapter(dev);
  220.                                 tp->state = CLOSED;
  221.                                 return (LOBE_MEDIA_TEST_FAILED);
  222.                         }
  223.                         else
  224.                         {
  225.                                 perror = 1;
  226.                                 if(smctr_lobe_media_test_cmd(dev))
  227.                                 {
  228.                                         smctr_reset_adapter(dev);
  229.                                         tp->state = CLOSED;
  230.                                         return (LOBE_MEDIA_TEST_FAILED);
  231.                                 }
  232.                         }
  233.                 }
  234.         }
  235.         if(smctr_send_dat(dev))
  236.         {
  237.                 if(smctr_send_dat(dev))
  238.                 {
  239.                         smctr_reset_adapter(dev);
  240.                         tp->state = CLOSED;
  241.                         return (LOBE_MEDIA_TEST_FAILED);
  242.                 }
  243.         }
  244.         /* Check if any frames received during test. */
  245.         if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status)
  246.                 || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
  247.         {
  248.                 smctr_reset_adapter(dev);
  249.                 tp->state = CLOSED;
  250.                 return (LOBE_MEDIA_TEST_FAILED);
  251.         }
  252.         /* Set receive mask to "Promisc" mode. */
  253.         tp->receive_mask = saved_rcv_mask;
  254.         smctr_chg_rx_mask(dev);
  255.         return (0);
  256. }
  257. static int smctr_lobe_media_test_cmd(struct net_device *dev)
  258. {
  259.         struct net_local *tp = (struct net_local *)dev->priv;
  260.         int err;
  261.         if(smctr_debug > 10)
  262.                 printk("%s: smctr_lobe_media_test_cmdn", dev->name);
  263.         /* Change to lobe media test state. */
  264.         if(tp->monitor_state != MS_BEACON_TEST_STATE)
  265.         {
  266.                 smctr_lobe_media_test_state(dev);
  267.                 if(smctr_wait_cmd(dev))
  268.                 {
  269.                         printk("Lobe Failed test staten");
  270.                         return (LOBE_MEDIA_TEST_FAILED);
  271.                 }
  272.         }
  273.         err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
  274.                 TRC_LOBE_MEDIA_TEST);
  275.         return (err);
  276. }
  277. static int smctr_lobe_media_test_state(struct net_device *dev)
  278. {
  279.         int err;
  280.         err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
  281.                 JS_LOBE_TEST_STATE);
  282.         return (err);
  283. }
  284. static int smctr_make_8025_hdr(struct net_device *dev,
  285.         MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
  286. {
  287.         tmf->ac = MSB(ac_fc);                 /* msb is access control */
  288.         tmf->fc = LSB(ac_fc);                 /* lsb is frame control */
  289.         tmf->sa[0] = dev->dev_addr[0];
  290.         tmf->sa[1] = dev->dev_addr[1];
  291.         tmf->sa[2] = dev->dev_addr[2];
  292.         tmf->sa[3] = dev->dev_addr[3];
  293.         tmf->sa[4] = dev->dev_addr[4];
  294.         tmf->sa[5] = dev->dev_addr[5];
  295.         switch(tmf->vc)
  296.         {
  297. /* Send RQ_INIT to RPS */
  298.                 case RQ_INIT:
  299.                         tmf->da[0] = 0xc0;
  300.                         tmf->da[1] = 0x00;
  301.                         tmf->da[2] = 0x00;
  302.                         tmf->da[3] = 0x00;
  303.                         tmf->da[4] = 0x00;
  304.                         tmf->da[5] = 0x02;
  305.                         break;
  306. /* Send RPT_TX_FORWARD to CRS */
  307.                 case RPT_TX_FORWARD:
  308.                         tmf->da[0] = 0xc0;
  309.                         tmf->da[1] = 0x00;
  310.                         tmf->da[2] = 0x00;
  311.                         tmf->da[3] = 0x00;
  312.                         tmf->da[4] = 0x00;
  313.                         tmf->da[5] = 0x10;
  314.                         break;
  315. /* Everything else goes to sender */
  316.                 default:
  317.                         tmf->da[0] = rmf->sa[0];
  318.                         tmf->da[1] = rmf->sa[1];
  319.                         tmf->da[2] = rmf->sa[2];
  320.                         tmf->da[3] = rmf->sa[3];
  321.                         tmf->da[4] = rmf->sa[4];
  322.                         tmf->da[5] = rmf->sa[5];
  323.                         break;
  324.         }
  325.         return (0);
  326. }
  327. static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
  328. {
  329.         struct net_local *tp = (struct net_local *)dev->priv;
  330.         tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
  331.         tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
  332.         tsv->svv[0] = MSB(tp->authorized_access_priority);
  333.         tsv->svv[1] = LSB(tp->authorized_access_priority);
  334. return (0);
  335. }
  336. static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
  337. {
  338.         tsv->svi = ADDRESS_MODIFER;
  339.         tsv->svl = S_ADDRESS_MODIFER;
  340.         tsv->svv[0] = 0;
  341.         tsv->svv[1] = 0;
  342.         return (0);
  343. }
  344. static int smctr_make_auth_funct_class(struct net_device *dev,
  345.         MAC_SUB_VECTOR *tsv)
  346. {
  347.         struct net_local *tp = (struct net_local *)dev->priv;
  348.         tsv->svi = AUTHORIZED_FUNCTION_CLASS;
  349.         tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
  350.         tsv->svv[0] = MSB(tp->authorized_function_classes);
  351.         tsv->svv[1] = LSB(tp->authorized_function_classes);
  352.         return (0);
  353. }
  354. static int smctr_make_corr(struct net_device *dev,
  355.         MAC_SUB_VECTOR *tsv, __u16 correlator)
  356. {
  357.         tsv->svi = CORRELATOR;
  358.         tsv->svl = S_CORRELATOR;
  359.         tsv->svv[0] = MSB(correlator);
  360.         tsv->svv[1] = LSB(correlator);
  361.         return (0);
  362. }
  363. static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
  364. {
  365.         struct net_local *tp = (struct net_local *)dev->priv;
  366.         smctr_get_functional_address(dev);
  367.         tsv->svi = FUNCTIONAL_ADDRESS;
  368.         tsv->svl = S_FUNCTIONAL_ADDRESS;
  369.         tsv->svv[0] = MSB(tp->misc_command_data[0]);
  370.         tsv->svv[1] = LSB(tp->misc_command_data[0]);
  371.         tsv->svv[2] = MSB(tp->misc_command_data[1]);
  372.         tsv->svv[3] = LSB(tp->misc_command_data[1]);
  373.         return (0);
  374. }
  375. static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
  376. {
  377.         struct net_local *tp = (struct net_local *)dev->priv;
  378.         smctr_get_group_address(dev);
  379.         tsv->svi = GROUP_ADDRESS;
  380.         tsv->svl = S_GROUP_ADDRESS;
  381.         tsv->svv[0] = MSB(tp->misc_command_data[0]);
  382.         tsv->svv[1] = LSB(tp->misc_command_data[0]);
  383.         tsv->svv[2] = MSB(tp->misc_command_data[1]);
  384.         tsv->svv[3] = LSB(tp->misc_command_data[1]);
  385.         /* Set Group Address Sub-vector to all zeros if only the
  386.          * Group Address/Functional Address Indicator is set.
  387.          */
  388.         if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00
  389.          && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
  390.                 tsv->svv[0] = 0x00;
  391.         return (0);
  392. }
  393. static int smctr_make_phy_drop_num(struct net_device *dev,
  394.         MAC_SUB_VECTOR *tsv)
  395. {
  396.         struct net_local *tp = (struct net_local *)dev->priv;
  397.         smctr_get_physical_drop_number(dev);
  398.         tsv->svi = PHYSICAL_DROP;
  399.         tsv->svl = S_PHYSICAL_DROP;
  400.         tsv->svv[0] = MSB(tp->misc_command_data[0]);
  401.         tsv->svv[1] = LSB(tp->misc_command_data[0]);
  402.         tsv->svv[2] = MSB(tp->misc_command_data[1]);
  403.         tsv->svv[3] = LSB(tp->misc_command_data[1]);
  404.         return (0);
  405. }
  406. static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
  407. {
  408.         int i;
  409.         tsv->svi = PRODUCT_INSTANCE_ID;
  410.         tsv->svl = S_PRODUCT_INSTANCE_ID;
  411.         for(i = 0; i < 18; i++)
  412.                 tsv->svv[i] = 0xF0;
  413.         return (0);
  414. }
  415. static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
  416. {
  417.         struct net_local *tp = (struct net_local *)dev->priv;
  418.         smctr_get_station_id(dev);
  419.         tsv->svi = STATION_IDENTIFER;
  420.         tsv->svl = S_STATION_IDENTIFER;
  421.         tsv->svv[0] = MSB(tp->misc_command_data[0]);
  422.         tsv->svv[1] = LSB(tp->misc_command_data[0]);
  423.         tsv->svv[2] = MSB(tp->misc_command_data[1]);
  424.         tsv->svv[3] = LSB(tp->misc_command_data[1]);
  425.         tsv->svv[4] = MSB(tp->misc_command_data[2]);
  426.         tsv->svv[5] = LSB(tp->misc_command_data[2]);
  427.         return (0);
  428. }
  429. static int smctr_make_ring_station_status(struct net_device *dev,
  430.         MAC_SUB_VECTOR * tsv)
  431. {
  432.         tsv->svi = RING_STATION_STATUS;
  433.         tsv->svl = S_RING_STATION_STATUS;
  434.         tsv->svv[0] = 0;
  435.         tsv->svv[1] = 0;
  436.         tsv->svv[2] = 0;
  437.         tsv->svv[3] = 0;
  438.         tsv->svv[4] = 0;
  439.         tsv->svv[5] = 0;
  440.         return (0);
  441. }
  442. static int smctr_make_ring_station_version(struct net_device *dev,
  443.         MAC_SUB_VECTOR *tsv)
  444. {
  445.         struct net_local *tp = (struct net_local *)dev->priv;
  446.         tsv->svi = RING_STATION_VERSION_NUMBER;
  447.         tsv->svl = S_RING_STATION_VERSION_NUMBER;
  448.         tsv->svv[0] = 0xe2;            /* EBCDIC - S */
  449.         tsv->svv[1] = 0xd4;            /* EBCDIC - M */
  450.         tsv->svv[2] = 0xc3;            /* EBCDIC - C */
  451.         tsv->svv[3] = 0x40;            /* EBCDIC -   */
  452.         tsv->svv[4] = 0xe5;            /* EBCDIC - V */
  453.         tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
  454.         tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
  455.         tsv->svv[7] = 0x40;            /* EBCDIC -   */
  456.         tsv->svv[8] = 0xe7;            /* EBCDIC - X */
  457.         if(tp->extra_info & CHIP_REV_MASK)
  458.                 tsv->svv[9] = 0xc5;    /* EBCDIC - E */
  459.         else
  460.                 tsv->svv[9] = 0xc4;    /* EBCDIC - D */
  461.         return (0);
  462. }
  463. static int smctr_make_tx_status_code(struct net_device *dev,
  464.         MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
  465. {
  466.         tsv->svi = TRANSMIT_STATUS_CODE;
  467.         tsv->svl = S_TRANSMIT_STATUS_CODE;
  468.         tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) || IBM_PASS_SOURCE_ADDR);
  469.         /* Stripped frame status of Transmitted Frame */
  470.         tsv->svv[1] = tx_fstatus & 0xff;
  471.         return (0);
  472. }
  473. static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
  474.         MAC_SUB_VECTOR *tsv)
  475. {
  476.         struct net_local *tp = (struct net_local *)dev->priv;
  477.         smctr_get_upstream_neighbor_addr(dev);
  478.         tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
  479.         tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
  480.         tsv->svv[0] = MSB(tp->misc_command_data[0]);
  481.         tsv->svv[1] = LSB(tp->misc_command_data[0]);
  482.         tsv->svv[2] = MSB(tp->misc_command_data[1]);
  483.         tsv->svv[3] = LSB(tp->misc_command_data[1]);
  484.         tsv->svv[4] = MSB(tp->misc_command_data[2]);
  485.         tsv->svv[5] = LSB(tp->misc_command_data[2]);
  486.         return (0);
  487. }
  488. static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
  489. {
  490.         tsv->svi = WRAP_DATA;
  491.         tsv->svl = S_WRAP_DATA;
  492.         return (0);
  493. }
  494. /*
  495.  * Open/initialize the board. This is called sometime after
  496.  * booting when the 'ifconfig' program is run.
  497.  *
  498.  * This routine should set everything up anew at each open, even
  499.  * registers that "should" only need to be set once at boot, so that
  500.  * there is non-reboot way to recover if something goes wrong.
  501.  */
  502. static int smctr_open(struct net_device *dev)
  503. {
  504.         int err;
  505.         if(smctr_debug > 10)
  506.                 printk("%s: smctr_openn", dev->name);
  507.         err = smctr_init_adapter(dev);
  508.         if(err < 0)
  509.                 return (err);
  510. #ifdef MODULE
  511.         MOD_INC_USE_COUNT;
  512. #endif
  513.         return (err);
  514. }
  515. /* Interrupt driven open of Token card. */
  516. static int smctr_open_tr(struct net_device *dev)
  517. {
  518.         struct net_local *tp = (struct net_local *)dev->priv;
  519.         unsigned long flags;
  520.         int err;
  521.         if(smctr_debug > 10)
  522.                 printk("%s: smctr_open_trn", dev->name);
  523.         /* Now we can actually open the adapter. */
  524.         if(tp->status == OPEN)
  525.                 return (0);
  526.         if(tp->status != INITIALIZED)
  527.                 return (-1);
  528.         save_flags(flags);
  529.         cli();
  530.         smctr_set_page(dev, (__u8 *)tp->ram_access);
  531.         if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
  532.                 goto out;
  533.         if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
  534.                 goto out;
  535.         if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
  536.                 goto out;
  537.         if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
  538.                 goto out;
  539.         tp->status = CLOSED;
  540.         /* Insert into the Ring or Enter Loopback Mode. */
  541.         if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
  542.         {
  543.                 tp->status = CLOSED;
  544.                 if(!(err = smctr_issue_trc_loopback_cmd(dev)))
  545.                 {
  546.                         if(!(err = smctr_wait_cmd(dev)))
  547.                                 tp->status = OPEN;
  548.                 }
  549.                 smctr_status_chg(dev);
  550.         }
  551.         else
  552.         {
  553.                 if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
  554.                 {
  555.                         tp->status = CLOSED;
  556.                         if(!(err = smctr_issue_tri_loopback_cmd(dev)))
  557.                         {
  558.                                 if(!(err = smctr_wait_cmd(dev)))
  559.                                         tp->status = OPEN;
  560.                         }
  561.                         smctr_status_chg(dev);
  562.                 }
  563.                 else
  564.                 {
  565.                         if((tp->mode_bits & LOOPING_MODE_MASK)
  566.                                 == LOOPBACK_MODE_3)
  567.                         {
  568.                                 tp->status = CLOSED;
  569.                                 if(!(err = smctr_lobe_media_test_cmd(dev)))
  570.                                 {
  571.                                         if(!(err = smctr_wait_cmd(dev)))
  572.                                                 tp->status = OPEN;
  573.                                 }
  574.                                 smctr_status_chg(dev);
  575.                         }
  576.                         else
  577.                         {
  578.                                 if(!(err = smctr_lobe_media_test(dev)))
  579.                                         err = smctr_issue_insert_cmd(dev);
  580. else
  581.                                 {
  582.                                         if(err == LOBE_MEDIA_TEST_FAILED)
  583.                                                 printk("%s: Lobe Media Test Failure - Check cable?n", dev->name);
  584.                                 }
  585.                         }
  586.                 }
  587.         }
  588. out:
  589.         restore_flags(flags);
  590.         return (err);
  591. }
  592. /* Check for a network adapter of this type, and return '0 if one exists.
  593.  * If dev->base_addr == 0, probe all likely locations.
  594.  * If dev->base_addr == 1, always return failure.
  595.  */
  596. int __init smctr_probe (struct net_device *dev)
  597. {
  598.         int i;
  599.         int base_addr = dev ? dev->base_addr : 0;
  600.         if(base_addr > 0x1ff)    /* Check a single specified location. */
  601.                 return (smctr_probe1(dev, base_addr));
  602.         else if(base_addr != 0)  /* Don't probe at all. */
  603.                 return (-ENXIO);
  604.         for(i = 0; smctr_portlist[i]; i++)
  605.         {
  606.                 int ioaddr = smctr_portlist[i];
  607.                 if(check_region(ioaddr, SMCTR_IO_EXTENT))
  608.                         continue;
  609.                 if (!smctr_probe1(dev, ioaddr))
  610.                         return (0);
  611.         }
  612.         return (-ENODEV);
  613. }
  614. static int __init smctr_probe1(struct net_device *dev, int ioaddr)
  615. {
  616.         static unsigned version_printed;
  617.         struct net_local *tp;
  618.         int err;
  619.         __u32 *ram;
  620.         if(smctr_debug && version_printed++ == 0)
  621.                 printk(version);
  622. #ifndef MODULE
  623.         dev = init_trdev(dev, 0);
  624.         if(dev == NULL)
  625.                 return (-ENOMEM);
  626. #endif
  627.         /* Setup this devices private information structure */
  628.         tp = (struct net_local *)kmalloc(sizeof(struct net_local),
  629.                 GFP_KERNEL);
  630.         if(tp == NULL) {
  631. err = -ENOMEM;
  632. goto out;
  633. }
  634.         memset(tp, 0, sizeof(struct net_local));
  635.         dev->priv = tp;
  636.         dev->base_addr = ioaddr;
  637. /* Actually detect an adapter now. */
  638.         err = smctr_chk_isa(dev);
  639.         if(err < 0)
  640.         {
  641. if ((err = smctr_chk_mca(dev)) < 0) {
  642. err = -ENODEV;
  643. goto out_tp;
  644. }
  645.         }
  646.         tp = (struct net_local *)dev->priv;
  647.         dev->rmem_start = dev->mem_start = tp->ram_base;
  648.         dev->rmem_end = dev->mem_end = dev->mem_start + 0x10000;
  649.         ram = (__u32 *)phys_to_virt(dev->mem_start);
  650.         tp->ram_access = *(__u32 *)&ram;
  651. tp->status = NOT_INITIALIZED;
  652.         err = smctr_load_firmware(dev);
  653.         if(err != UCODE_PRESENT && err != SUCCESS)
  654.         {
  655.                 printk("%s: Firmware load failed (%d)n", dev->name, err);
  656. err = -EIO;
  657. goto out_tp;
  658.         }
  659. /* Allow user to specify ring speed on module insert. */
  660. if(ringspeed == 4)
  661. tp->media_type = MEDIA_UTP_4;
  662. else
  663. tp->media_type = MEDIA_UTP_16;
  664.         printk("%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.n",
  665.                 dev->name, smctr_name, smctr_model,
  666.                 (unsigned int)dev->base_addr,
  667.                 dev->irq, tp->rom_base, tp->ram_base);
  668. /* AKPM: there's no point in this */
  669.         dev->init               = smctr_init_card;
  670.         dev->open               = smctr_open;
  671.         dev->stop               = smctr_close;
  672.         dev->hard_start_xmit    = smctr_send_packet;
  673.         dev->tx_timeout = smctr_timeout;
  674.         dev->watchdog_timeo = HZ;
  675.         dev->get_stats          = smctr_get_stats;
  676.         dev->set_multicast_list = &smctr_set_multicast_list;
  677.         return (0);
  678. out_tp:
  679. kfree(tp);
  680. out:
  681. return err;
  682. }
  683. static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
  684.         struct net_device *dev, __u16 rx_status)
  685. {
  686.         struct net_local *tp = (struct net_local *)dev->priv;
  687.         struct sk_buff *skb;
  688.         __u16 rcode, correlator;
  689.         int err = 0;
  690.         __u8 xframe = 1;
  691.         __u16 tx_fstatus;
  692.         rmf->vl = SWAP_BYTES(rmf->vl);
  693.         if(rx_status & FCB_RX_STATUS_DA_MATCHED)
  694.         {
  695.                 switch(rmf->vc)
  696.                 {
  697.                         /* Received MAC Frames Processed by RS. */
  698.                         case INIT:
  699.                                 if((rcode = smctr_rcv_init(dev, rmf,
  700.                                         &correlator)) == HARDWARE_FAILED)
  701.                                 {
  702.                                         return (rcode);
  703.                                 }
  704.                                 if((err = smctr_send_rsp(dev, rmf, rcode,
  705.                                         correlator)))
  706.                                 {
  707.                                         return (err);
  708.                                 }
  709.                                 break;
  710.                         case CHG_PARM:
  711.                                 if((rcode = smctr_rcv_chg_param(dev, rmf,
  712.                                         &correlator)) ==HARDWARE_FAILED)
  713.                                 {
  714.                                         return (rcode);
  715.                                 }
  716.                                 if((err = smctr_send_rsp(dev, rmf, rcode,
  717.                                         correlator)))
  718.                                 {
  719.                                         return (err);
  720.                                 }
  721.                                 break;
  722.                         case RQ_ADDR:
  723.                                 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
  724.                                         rmf, &correlator)) != POSITIVE_ACK)
  725.                                 {
  726.                                         if(rcode == HARDWARE_FAILED)
  727.                                                 return (rcode);
  728.                                         else
  729.                                                 return (smctr_send_rsp(dev, rmf,
  730.                                                         rcode, correlator));
  731.                                 }
  732.                                 if((err = smctr_send_rpt_addr(dev, rmf,
  733.                                         correlator)))
  734.                                 {
  735.                                         return (err);
  736.                                 }
  737.                                 break;
  738.                         case RQ_ATTCH:
  739.                                 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
  740.                                         rmf, &correlator)) != POSITIVE_ACK)
  741.                                 {
  742.                                         if(rcode == HARDWARE_FAILED)
  743.                                                 return (rcode);
  744.                                         else
  745.                                                 return (smctr_send_rsp(dev, rmf,
  746.                                                         rcode,
  747.                                                         correlator));
  748.                                 }
  749.                                 if((err = smctr_send_rpt_attch(dev, rmf,
  750.                                         correlator)))
  751.                                 {
  752.                                         return (err);
  753.                                 }
  754.                                 break;
  755.                         case RQ_STATE:
  756.                                 if((rcode = smctr_rcv_rq_addr_state_attch(dev,
  757.                                         rmf, &correlator)) != POSITIVE_ACK)
  758.                                 {
  759.                                         if(rcode == HARDWARE_FAILED)
  760.                                                 return (rcode);
  761.                                         else
  762.                                                 return (smctr_send_rsp(dev, rmf,
  763.                                                         rcode,
  764.                                                         correlator));
  765.                                 }
  766.                                 if((err = smctr_send_rpt_state(dev, rmf,
  767.                                         correlator)))
  768.                                 {
  769.                                         return (err);
  770.                                 }
  771.                                 break;
  772.                         case TX_FORWARD:
  773.                                 if((rcode = smctr_rcv_tx_forward(dev, rmf))
  774.                                         != POSITIVE_ACK)
  775.                                 {
  776.                                         if(rcode == HARDWARE_FAILED)
  777.                                                 return (rcode);
  778.                                         else
  779.                                                 return (smctr_send_rsp(dev, rmf,
  780.                                                         rcode,
  781.                                                         correlator));
  782.                                 }
  783.                                 if((err = smctr_send_tx_forward(dev, rmf,
  784.                                         &tx_fstatus)) == HARDWARE_FAILED)
  785.                                 {
  786.                                         return (err);
  787.                                 }
  788.                                 if(err == A_FRAME_WAS_FORWARDED)
  789.                                 {
  790.                                         if((err = smctr_send_rpt_tx_forward(dev,
  791. rmf, tx_fstatus))
  792.                                                 == HARDWARE_FAILED)
  793.                                         {
  794.                                                 return (err);
  795.                                         }
  796.                                 }
  797.                                 break;
  798.                         /* Received MAC Frames Processed by CRS/REM/RPS. */
  799.                         case RSP:
  800.                         case RQ_INIT:
  801.                         case RPT_NEW_MON:
  802.                         case RPT_SUA_CHG:
  803.                         case RPT_ACTIVE_ERR:
  804.                         case RPT_NN_INCMP:
  805.                         case RPT_ERROR:
  806.                         case RPT_ATTCH:
  807.                         case RPT_STATE:
  808.                         case RPT_ADDR:
  809.                                 break;
  810.                         /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
  811.                         default:
  812.                                 xframe = 0;
  813.                                 if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
  814.                                 {
  815.                                         rcode = smctr_rcv_unknown(dev, rmf,
  816.                                                 &correlator);
  817.                                         if((err = smctr_send_rsp(dev, rmf,rcode,
  818.                                                 correlator)))
  819.                                         {
  820.                                                 return (err);
  821.                                         }
  822.                                 }
  823.                                 break;
  824.                 }
  825.         }
  826.         else
  827.         {
  828.                 /* 1. DA doesn't match (Promiscuous Mode).
  829.                  * 2. Parse for Extended MAC Frame Type.
  830.                  */
  831.                 switch(rmf->vc)
  832.                 {
  833.                         case RSP:
  834.                         case INIT:
  835.                         case RQ_INIT:
  836.                         case RQ_ADDR:
  837.                         case RQ_ATTCH:
  838.                         case RQ_STATE:
  839.                         case CHG_PARM:
  840.                         case RPT_ADDR:
  841.                         case RPT_ERROR:
  842.                         case RPT_ATTCH:
  843.                         case RPT_STATE:
  844.                         case RPT_NEW_MON:
  845.                         case RPT_SUA_CHG:
  846.                         case RPT_NN_INCMP:
  847.                         case RPT_ACTIVE_ERR:
  848.                                 break;
  849.                         default:
  850.                                 xframe = 0;
  851.                                 break;
  852.                 }
  853.         }
  854.         /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
  855.          * ACCEPT_ATT_MAC_FRAMES is set.
  856.          */
  857.         if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
  858.                 && (xframe == (__u8)0))
  859.                 || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES)
  860.                 && (xframe == (__u8)1)))
  861.         {
  862.                 rmf->vl = SWAP_BYTES(rmf->vl);
  863.                 if (!(skb = dev_alloc_skb(size)))
  864. return -ENOMEM;
  865.                 skb->len = size;
  866.                 /* Slide data into a sleek skb. */
  867.                 skb_put(skb, skb->len);
  868.                 memcpy(skb->data, rmf, skb->len);
  869.                 /* Update Counters */
  870.                 tp->MacStat.rx_packets++;
  871.                 tp->MacStat.rx_bytes += skb->len;
  872.                 /* Kick the packet on up. */
  873.                 skb->dev = dev;
  874.                 skb->protocol = tr_type_trans(skb, dev);
  875.                 netif_rx(skb);
  876. dev->last_rx = jiffies;
  877.                 err = 0;
  878.         }
  879.         return (err);
  880. }
  881. /* Adapter RAM test. Incremental word ODD boundry data test. */
  882. static int smctr_ram_memory_test(struct net_device *dev)
  883. {
  884.         struct net_local *tp = (struct net_local *)dev->priv;
  885.         __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
  886.                 word_read = 0, err_word = 0, err_pattern = 0;
  887.         unsigned int err_offset;
  888.         __u32 j, pword;
  889.         __u8 err = 0;
  890.         if(smctr_debug > 10)
  891.                 printk("%s: smctr_ram_memory_testn", dev->name);
  892.         start_pattern   = 0x0001;
  893.         pages_of_ram    = tp->ram_size / tp->ram_usable;
  894.         pword           = tp->ram_access;
  895.         /* Incremental word ODD boundry test. */
  896.         for(page = 0; (page < pages_of_ram) && (~err);
  897.                 page++, start_pattern += 0x8000)
  898.         {
  899.                 smctr_set_page(dev, (__u8 *)(tp->ram_access
  900.                         + (page * tp->ram_usable * 1024) + 1));
  901.                 word_pattern = start_pattern;
  902.                 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
  903.                         *(__u16 *)(pword + j) = word_pattern++;
  904.                 word_pattern = start_pattern;
  905.                 for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1
  906.                         && (~err); j += 2, word_pattern++)
  907.                 {
  908.                         word_read = *(__u16 *)(pword + j);
  909.                         if(word_read != word_pattern)
  910.                         {
  911.                                 err             = (__u8)1;
  912.                                 err_offset      = j;
  913.                                 err_word        = word_read;
  914.                                 err_pattern     = word_pattern;
  915.                                 return (RAM_TEST_FAILED);
  916.                         }
  917.                 }
  918.         }
  919.         /* Zero out memory. */
  920.         for(page = 0; page < pages_of_ram && (~err); page++)
  921.         {
  922.                 smctr_set_page(dev, (__u8 *)(tp->ram_access
  923.                         + (page * tp->ram_usable * 1024)));
  924.                 word_pattern = 0;
  925.                 for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
  926.                         *(__u16 *)(pword + j) = word_pattern;
  927.                 for(j =0; j < (__u32)tp->ram_usable * 1024
  928.                         && (~err); j += 2)
  929.                 {
  930.                         word_read = *(__u16 *)(pword + j);
  931.                         if(word_read != word_pattern)
  932.                         {
  933.                                 err             = (__u8)1;
  934.                                 err_offset      = j;
  935.                                 err_word        = word_read;
  936.                                 err_pattern     = word_pattern;
  937.                                 return (RAM_TEST_FAILED);
  938.                         }
  939.                 }
  940.         }
  941.         smctr_set_page(dev, (__u8 *)tp->ram_access);
  942.         return (0);
  943. }
  944. static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
  945.         __u16 *correlator)
  946. {
  947.         MAC_SUB_VECTOR *rsv;
  948.         signed short vlen;
  949.         __u16 rcode = POSITIVE_ACK;
  950.         unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
  951.         /* This Frame can only come from a CRS */
  952.         if((rmf->dc_sc & SC_MASK) != SC_CRS)
  953.                 return(E_INAPPROPRIATE_SOURCE_CLASS);
  954.         /* Remove MVID Length from total length. */
  955.         vlen = (signed short)rmf->vl - 4;
  956.         /* Point to First SVID */
  957.         rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
  958.         /* Search for Appropriate SVID's. */
  959.         while((vlen > 0) && (rcode == POSITIVE_ACK))
  960.         {
  961.                 switch(rsv->svi)
  962.                 {
  963.                         case CORRELATOR:
  964.                                 svectors |= F_CORRELATOR;
  965.                                 rcode = smctr_set_corr(dev, rsv, correlator);
  966.                                 break;
  967.                         case LOCAL_RING_NUMBER:
  968.                                 svectors |= F_LOCAL_RING_NUMBER;
  969.                                 rcode = smctr_set_local_ring_num(dev, rsv);
  970.                                 break;
  971.                         case ASSIGN_PHYSICAL_DROP:
  972.                                 svectors |= F_ASSIGN_PHYSICAL_DROP;
  973.                                 rcode = smctr_set_phy_drop(dev, rsv);
  974.                                 break;
  975.                         case ERROR_TIMER_VALUE:
  976.                                 svectors |= F_ERROR_TIMER_VALUE;
  977.                                 rcode = smctr_set_error_timer_value(dev, rsv);
  978.                                 break;
  979.                         case AUTHORIZED_FUNCTION_CLASS:
  980.                                 svectors |= F_AUTHORIZED_FUNCTION_CLASS;
  981.                                 rcode = smctr_set_auth_funct_class(dev, rsv);
  982.                                 break;
  983.                         case AUTHORIZED_ACCESS_PRIORITY:
  984.                                 svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
  985.                                 rcode = smctr_set_auth_access_pri(dev, rsv);
  986.                                 break;
  987.                         default:
  988.                                 rcode = E_SUB_VECTOR_UNKNOWN;
  989.                                 break;
  990.                 }
  991.                 /* Let Sender Know if SUM of SV length's is
  992.                  * larger then length in MVID length field
  993.                  */
  994.                 if((vlen -= rsv->svl) < 0)
  995.                         rcode = E_VECTOR_LENGTH_ERROR;
  996.                 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
  997.         }
  998.         if(rcode == POSITIVE_ACK)
  999.         {
  1000.                 /* Let Sender Know if MVID length field
  1001.                  * is larger then SUM of SV length's
  1002.                  */
  1003.                 if(vlen != 0)
  1004.                         rcode = E_VECTOR_LENGTH_ERROR;
  1005.                 else
  1006. {
  1007.                  /* Let Sender Know if Expected SVID Missing */
  1008.                  if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
  1009.                          rcode = E_MISSING_SUB_VECTOR;
  1010. }
  1011.         }
  1012.         return (rcode);
  1013. }
  1014. static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
  1015.         __u16 *correlator)
  1016. {
  1017.         MAC_SUB_VECTOR *rsv;
  1018.         signed short vlen;
  1019.         __u16 rcode = POSITIVE_ACK;
  1020.         unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
  1021.         /* This Frame can only come from a RPS */
  1022.         if((rmf->dc_sc & SC_MASK) != SC_RPS)
  1023.                 return (E_INAPPROPRIATE_SOURCE_CLASS);
  1024.         /* Remove MVID Length from total length. */
  1025.         vlen = (signed short)rmf->vl - 4;
  1026.         /* Point to First SVID */
  1027.         rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
  1028.         /* Search for Appropriate SVID's */
  1029.         while((vlen > 0) && (rcode == POSITIVE_ACK))
  1030.         {
  1031.                 switch(rsv->svi)
  1032.                 {
  1033.                         case CORRELATOR:
  1034.                                 svectors |= F_CORRELATOR;
  1035.                                 rcode = smctr_set_corr(dev, rsv, correlator);
  1036.                                 break;
  1037.                         case LOCAL_RING_NUMBER:
  1038.                                 svectors |= F_LOCAL_RING_NUMBER;
  1039.                                 rcode = smctr_set_local_ring_num(dev, rsv);
  1040.                                 break;
  1041.                         case ASSIGN_PHYSICAL_DROP:
  1042.                                 svectors |= F_ASSIGN_PHYSICAL_DROP;
  1043.                                 rcode = smctr_set_phy_drop(dev, rsv);
  1044.                                 break;
  1045.                         case ERROR_TIMER_VALUE:
  1046.                                 svectors |= F_ERROR_TIMER_VALUE;
  1047.                                 rcode = smctr_set_error_timer_value(dev, rsv);
  1048.                                 break;
  1049.                         default:
  1050.                                 rcode = E_SUB_VECTOR_UNKNOWN;
  1051.                                 break;
  1052.                 }
  1053.                 /* Let Sender Know if SUM of SV length's is
  1054.                  * larger then length in MVID length field
  1055.  */
  1056.                 if((vlen -= rsv->svl) < 0)
  1057.                         rcode = E_VECTOR_LENGTH_ERROR;
  1058.                 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
  1059.         }
  1060.         if(rcode == POSITIVE_ACK)
  1061.         {
  1062.                 /* Let Sender Know if MVID length field
  1063.                  * is larger then SUM of SV length's
  1064.                  */
  1065.                 if(vlen != 0)
  1066.                         rcode = E_VECTOR_LENGTH_ERROR;
  1067.                 else
  1068. {
  1069.                  /* Let Sender Know if Expected SV Missing */
  1070.                  if((svectors & R_INIT) ^ R_INIT)
  1071.                          rcode = E_MISSING_SUB_VECTOR;
  1072. }
  1073.         }
  1074.         return (rcode);
  1075. }
  1076. static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
  1077. {
  1078.         MAC_SUB_VECTOR *rsv;
  1079.         signed short vlen;
  1080.         __u16 rcode = POSITIVE_ACK;
  1081.         unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
  1082.         /* This Frame can only come from a CRS */
  1083.         if((rmf->dc_sc & SC_MASK) != SC_CRS)
  1084.                 return (E_INAPPROPRIATE_SOURCE_CLASS);
  1085.         /* Remove MVID Length from total length */
  1086.         vlen = (signed short)rmf->vl - 4;
  1087.         /* Point to First SVID */
  1088.         rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
  1089.         /* Search for Appropriate SVID's */
  1090.         while((vlen > 0) && (rcode == POSITIVE_ACK))
  1091.         {
  1092.                 switch(rsv->svi)
  1093.                 {
  1094.                         case FRAME_FORWARD:
  1095.                                 svectors |= F_FRAME_FORWARD;
  1096.                                 rcode = smctr_set_frame_forward(dev, rsv, 
  1097. rmf->dc_sc);
  1098.                                 break;
  1099.                         default:
  1100.                                 rcode = E_SUB_VECTOR_UNKNOWN;
  1101.                                 break;
  1102.                 }
  1103.                 /* Let Sender Know if SUM of SV length's is
  1104.                  * larger then length in MVID length field
  1105.  */
  1106.                 if((vlen -= rsv->svl) < 0)
  1107.                         rcode = E_VECTOR_LENGTH_ERROR;
  1108.                 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
  1109.         }
  1110.         if(rcode == POSITIVE_ACK)
  1111.         {
  1112.                 /* Let Sender Know if MVID length field
  1113.                  * is larger then SUM of SV length's
  1114.                  */
  1115.                 if(vlen != 0)
  1116.                         rcode = E_VECTOR_LENGTH_ERROR;
  1117.                 else
  1118. {
  1119.                  /* Let Sender Know if Expected SV Missing */
  1120.                  if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
  1121.                          rcode = E_MISSING_SUB_VECTOR;
  1122. }
  1123.         }
  1124.         return (rcode);
  1125. }
  1126. static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
  1127.         MAC_HEADER *rmf, __u16 *correlator)
  1128. {
  1129.         MAC_SUB_VECTOR *rsv;
  1130.         signed short vlen;
  1131.         __u16 rcode = POSITIVE_ACK;
  1132.         unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
  1133.         /* Remove MVID Length from total length */
  1134.         vlen = (signed short)rmf->vl - 4;
  1135.         /* Point to First SVID */
  1136.         rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
  1137.         /* Search for Appropriate SVID's */
  1138.         while((vlen > 0) && (rcode == POSITIVE_ACK))
  1139.         {
  1140.                 switch(rsv->svi)
  1141.                 {
  1142.                         case CORRELATOR:
  1143.                                 svectors |= F_CORRELATOR;
  1144.                                 rcode = smctr_set_corr(dev, rsv, correlator);
  1145.                                 break;
  1146.                         default:
  1147.                                 rcode = E_SUB_VECTOR_UNKNOWN;
  1148.                                 break;
  1149.                 }
  1150.                 /* Let Sender Know if SUM of SV length's is
  1151.                  * larger then length in MVID length field
  1152.                  */
  1153.                 if((vlen -= rsv->svl) < 0)
  1154.                         rcode = E_VECTOR_LENGTH_ERROR;
  1155.                 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
  1156.         }
  1157.         if(rcode == POSITIVE_ACK)
  1158.         {
  1159.                 /* Let Sender Know if MVID length field
  1160.                  * is larger then SUM of SV length's
  1161.                  */
  1162.                 if(vlen != 0)
  1163.                         rcode = E_VECTOR_LENGTH_ERROR;
  1164.                 else
  1165. {
  1166.                  /* Let Sender Know if Expected SVID Missing */
  1167.                  if((svectors & R_RQ_ATTCH_STATE_ADDR) 
  1168. ^ R_RQ_ATTCH_STATE_ADDR)
  1169.                          rcode = E_MISSING_SUB_VECTOR;
  1170. }
  1171.         }
  1172.         return (rcode);
  1173. }
  1174. static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
  1175.         __u16 *correlator)
  1176. {
  1177.         MAC_SUB_VECTOR *rsv;
  1178.         signed short vlen;
  1179.         *correlator = 0;
  1180.         /* Remove MVID Length from total length */
  1181.         vlen = (signed short)rmf->vl - 4;
  1182.         /* Point to First SVID */
  1183.         rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
  1184.         /* Search for CORRELATOR for RSP to UNKNOWN */
  1185.         while((vlen > 0) && (*correlator == 0))
  1186.         {
  1187.                 switch(rsv->svi)
  1188.                 {
  1189.                         case CORRELATOR:
  1190.                                 smctr_set_corr(dev, rsv, correlator);
  1191.                                 break;
  1192.                         default:
  1193.                                 break;
  1194.                 }
  1195.                 vlen -= rsv->svl;
  1196.                 rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
  1197.         }
  1198.         return (E_UNRECOGNIZED_VECTOR_ID);
  1199. }
  1200. /*
  1201.  * Reset the 825 NIC and exit w:
  1202.  * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
  1203.  * 2. TINT masked.
  1204.  * 3. CBUSY masked.
  1205.  * 4. TINT clear.
  1206.  * 5. CBUSY clear.
  1207.  */
  1208. static int smctr_reset_adapter(struct net_device *dev)
  1209. {
  1210.         struct net_local *tp = (struct net_local *)dev->priv;
  1211.         int ioaddr = dev->base_addr;
  1212.         /* Reseting the NIC will put it in a halted and un-initialized state. */        smctr_set_trc_reset(ioaddr);
  1213.         mdelay(200); /* ~2 ms */
  1214.         smctr_clear_trc_reset(ioaddr);
  1215.         mdelay(200); /* ~2 ms */
  1216.         /* Remove any latched interrupts that occurred prior to reseting the
  1217.          * adapter or possibily caused by line glitches due to the reset.
  1218.          */
  1219.         outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
  1220.         return (0);
  1221. }
  1222. static int smctr_restart_tx_chain(struct net_device *dev, short queue)
  1223. {
  1224.         struct net_local *tp = (struct net_local *)dev->priv;
  1225.         int err = 0;
  1226.         if(smctr_debug > 10)
  1227.                 printk("%s: smctr_restart_tx_chainn", dev->name);
  1228.         if(tp->num_tx_fcbs_used[queue] != 0
  1229.                 && tp->tx_queue_status[queue] == NOT_TRANSMITING)
  1230.         {
  1231.                 tp->tx_queue_status[queue] = TRANSMITING;
  1232.                 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
  1233.         }
  1234.         return (err);
  1235. }
  1236. static int smctr_ring_status_chg(struct net_device *dev)
  1237. {
  1238.         struct net_local *tp = (struct net_local *)dev->priv;
  1239.         if(smctr_debug > 10)
  1240.                 printk("%s: smctr_ring_status_chgn", dev->name);
  1241.         /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
  1242.          * Bit is set, check value of monitor_state, only then we
  1243.          * enable and start transmit/receive timeout (if and only
  1244.          * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
  1245.          */
  1246.         if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
  1247.         {
  1248.                 if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE)
  1249.                         || (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
  1250.                 {
  1251.                         tp->monitor_state_ready = 1;
  1252.                 }
  1253.                 else
  1254.                 {
  1255.                         /* if adapter is NOT in either active monitor
  1256.                          * or standby monitor state => Disable
  1257.                          * transmit/receive timeout.
  1258.                          */
  1259.                         tp->monitor_state_ready = 0;
  1260. /* Ring speed problem, switching to auto mode. */
  1261. if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE
  1262. && !tp->cleanup)
  1263. {
  1264. printk(KERN_INFO "%s: Incorrect ring speed switching.n",
  1265. dev->name);
  1266. smctr_set_ring_speed(dev);
  1267. }
  1268.                 }
  1269.         }
  1270.         if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
  1271.                 return (0);
  1272.         switch(tp->ring_status)
  1273.         {
  1274.                 case RING_RECOVERY:
  1275.                         printk(KERN_INFO "%s: Ring Recoveryn", dev->name);
  1276.                         tp->current_ring_status |= RING_RECOVERY;
  1277.                         break;
  1278.                 case SINGLE_STATION:
  1279.                         printk(KERN_INFO "%s: Single Statinonn", dev->name);
  1280.                         tp->current_ring_status |= SINGLE_STATION;
  1281.                         break;
  1282.                 case COUNTER_OVERFLOW:
  1283.                         printk(KERN_INFO "%s: Counter Overflown", dev->name);
  1284.                         tp->current_ring_status |= COUNTER_OVERFLOW;
  1285.                         break;
  1286.                 case REMOVE_RECEIVED:
  1287.                         printk(KERN_INFO "%s: Remove Receivedn", dev->name);
  1288.                         tp->current_ring_status |= REMOVE_RECEIVED;
  1289.                         break;
  1290.                 case AUTO_REMOVAL_ERROR:
  1291.                         printk(KERN_INFO "%s: Auto Remove Errorn", dev->name);
  1292.                         tp->current_ring_status |= AUTO_REMOVAL_ERROR;
  1293.                         break;
  1294.                 case LOBE_WIRE_FAULT:
  1295.                         printk(KERN_INFO "%s: Lobe Wire Faultn", dev->name);
  1296.                         tp->current_ring_status |= LOBE_WIRE_FAULT;
  1297.                         break;
  1298.                 case TRANSMIT_BEACON:
  1299.                         printk(KERN_INFO "%s: Transmit Beaconn", dev->name);
  1300.                         tp->current_ring_status |= TRANSMIT_BEACON;
  1301.                         break;
  1302.                 case SOFT_ERROR:
  1303.                         printk(KERN_INFO "%s: Soft Errorn", dev->name);
  1304.                         tp->current_ring_status |= SOFT_ERROR;
  1305.                         break;
  1306.                 case HARD_ERROR:
  1307.                         printk(KERN_INFO "%s: Hard Errorn", dev->name);
  1308.                         tp->current_ring_status |= HARD_ERROR;
  1309.                         break;
  1310.                 case SIGNAL_LOSS:
  1311.                         printk(KERN_INFO "%s: Singal Lossn", dev->name);
  1312.                         tp->current_ring_status |= SIGNAL_LOSS;
  1313.                         break;
  1314.                 default:
  1315. printk(KERN_INFO "%s: Unknown ring status changen",
  1316. dev->name);
  1317.                         break;
  1318.         }
  1319.         return (0);
  1320. }
  1321. static int smctr_rx_frame(struct net_device *dev)
  1322. {
  1323.         struct net_local *tp = (struct net_local *)dev->priv;
  1324.         __u16 queue, status, rx_size, err = 0;
  1325.         __u8 *pbuff;
  1326.         if(smctr_debug > 10)
  1327.                 printk("%s: smctr_rx_framen", dev->name);
  1328.         cli();
  1329.         queue = tp->receive_queue_number;
  1330.         while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
  1331.         {
  1332.                 err = HARDWARE_FAILED;
  1333.                 if(((status & 0x007f) == 0)
  1334.                         || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
  1335.                 {
  1336.                         /* frame length less the CRC (4 bytes) + FS (1 byte) */
  1337.                         rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
  1338.                         pbuff = smctr_get_rx_pointer(dev, queue);
  1339.                         smctr_set_page(dev, pbuff);
  1340.                         smctr_disable_16bit(dev);
  1341.                         /* pbuff points to addr within one page */
  1342.                         pbuff = (__u8 *)PAGE_POINTER(pbuff);
  1343.                         if(queue == NON_MAC_QUEUE)
  1344.                         {
  1345.                                 struct sk_buff *skb;
  1346.                                 skb = dev_alloc_skb(rx_size);
  1347. if (skb) {
  1348.                                  skb_put(skb, rx_size);
  1349.                                  memcpy(skb->data, pbuff, rx_size);
  1350.                                  sti();
  1351.                                  /* Update Counters */
  1352.                                  tp->MacStat.rx_packets++;
  1353.                                  tp->MacStat.rx_bytes += skb->len;
  1354.                                  /* Kick the packet on up. */
  1355.                                  skb->dev = dev;
  1356.                                  skb->protocol = tr_type_trans(skb, dev);
  1357.                                  netif_rx(skb);
  1358. dev->last_rx = jiffies;
  1359. } else {
  1360.                                  sti();
  1361. }
  1362.                         }
  1363.                         else
  1364.                                 smctr_process_rx_packet((MAC_HEADER *)pbuff,
  1365.                                         rx_size, dev, status);
  1366.                 }
  1367.                 smctr_enable_16bit(dev);
  1368.                 smctr_set_page(dev, (__u8 *)tp->ram_access);
  1369.                 smctr_update_rx_chain(dev, queue);
  1370.                 if(err != SUCCESS)
  1371.                         break;
  1372.         }
  1373.         return (err);
  1374. }
  1375. static int smctr_send_dat(struct net_device *dev)
  1376. {
  1377.         struct net_local *tp = (struct net_local *)dev->priv;
  1378.         unsigned int i, err;
  1379.         MAC_HEADER *tmf;
  1380.         FCBlock *fcb;
  1381.         if(smctr_debug > 10)
  1382.                 printk("%s: smctr_send_datn", dev->name);
  1383.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
  1384.                 sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
  1385.         {
  1386.                 return (OUT_OF_RESOURCES);
  1387.         }
  1388.         /* Initialize DAT Data Fields. */
  1389.         tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1390.         tmf->ac = MSB(AC_FC_DAT);
  1391.         tmf->fc = LSB(AC_FC_DAT);
  1392.         for(i = 0; i < 6; i++)
  1393.         {
  1394.                 tmf->sa[i] = dev->dev_addr[i];
  1395.                 tmf->da[i] = dev->dev_addr[i];
  1396.         }
  1397.         tmf->vc        = DAT;
  1398.         tmf->dc_sc     = DC_RS | SC_RS;
  1399.         tmf->vl        = 4;
  1400.         tmf->vl        = SWAP_BYTES(tmf->vl);
  1401.         /* Start Transmit. */
  1402.         if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
  1403.                 return (err);
  1404.         /* Wait for Transmit to Complete */
  1405.         for(i = 0; i < 10000; i++)
  1406.         {
  1407.                 if(fcb->frame_status & FCB_COMMAND_DONE)
  1408.                         break;
  1409.                 mdelay(1);
  1410.         }
  1411.         /* Check if GOOD frame Tx'ed. */
  1412.         if(!(fcb->frame_status &  FCB_COMMAND_DONE)
  1413.                 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
  1414.         {
  1415.                 return (INITIALIZE_FAILED);
  1416.         }
  1417.         /* De-allocated Tx FCB and Frame Buffer
  1418.          * The FCB must be de-allocated manually if executing with
  1419.          * interrupts disabled, other wise the ISR (LM_Service_Events)
  1420.          * will de-allocate it when the interrupt occurs.
  1421.          */
  1422.         tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
  1423.         smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
  1424.         return (0);
  1425. }
  1426. static void smctr_timeout(struct net_device *dev)
  1427. {
  1428. /*
  1429.          * If we get here, some higher level has decided we are broken.
  1430.          * There should really be a "kick me" function call instead.
  1431.          *
  1432.          * Resetting the token ring adapter takes a long time so just
  1433.          * fake transmission time and go on trying. Our own timeout
  1434.          * routine is in sktr_timer_chk()
  1435.          */
  1436.         dev->trans_start = jiffies;
  1437.         netif_wake_queue(dev);
  1438. }
  1439. /*
  1440.  * Gets skb from system, queues it and checks if it can be sent
  1441.  */
  1442. static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
  1443. {
  1444.         struct net_local *tp = (struct net_local *)dev->priv;
  1445.         if(smctr_debug > 10)
  1446.                 printk("%s: smctr_send_packetn", dev->name);
  1447.         /*
  1448.          * Block a transmit overlap
  1449.          */
  1450.          
  1451.         netif_stop_queue(dev);
  1452.         if(tp->QueueSkb == 0)
  1453.                 return (1);     /* Return with tbusy set: queue full */
  1454.         tp->QueueSkb--;
  1455.         skb_queue_tail(&tp->SendSkbQueue, skb);
  1456.         smctr_hardware_send_packet(dev, tp);
  1457.         if(tp->QueueSkb > 0)
  1458. netif_wake_queue(dev);
  1459.         return (0);
  1460. }
  1461. static int smctr_send_lobe_media_test(struct net_device *dev)
  1462. {
  1463.         struct net_local *tp = (struct net_local *)dev->priv;
  1464. MAC_SUB_VECTOR *tsv;
  1465. MAC_HEADER *tmf;
  1466.         FCBlock *fcb;
  1467. __u32 i;
  1468. int err;
  1469.         if(smctr_debug > 15)
  1470.                 printk("%s: smctr_send_lobe_media_testn", dev->name);
  1471.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
  1472.                 + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
  1473.         {
  1474.                 return (OUT_OF_RESOURCES);
  1475.         }
  1476.         /* Initialize DAT Data Fields. */
  1477.         tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1478.         tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
  1479.         tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
  1480.         for(i = 0; i < 6; i++)
  1481.         {
  1482.                 tmf->da[i] = 0;
  1483.                 tmf->sa[i] = dev->dev_addr[i];
  1484.         }
  1485.         tmf->vc        = LOBE_MEDIA_TEST;
  1486.         tmf->dc_sc     = DC_RS | SC_RS;
  1487.         tmf->vl        = 4;
  1488.         tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
  1489.         smctr_make_wrap_data(dev, tsv);
  1490.         tmf->vl += tsv->svl;
  1491.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1492.         smctr_make_wrap_data(dev, tsv);
  1493.         tmf->vl += tsv->svl;
  1494.         /* Start Transmit. */
  1495.         tmf->vl = SWAP_BYTES(tmf->vl);
  1496.         if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
  1497.                 return (err);
  1498.         /* Wait for Transmit to Complete. (10 ms). */
  1499.         for(i=0; i < 10000; i++)
  1500.         {
  1501.                 if(fcb->frame_status & FCB_COMMAND_DONE)
  1502.                         break;
  1503.                 mdelay(1);
  1504.         }
  1505.         /* Check if GOOD frame Tx'ed */
  1506.         if(!(fcb->frame_status & FCB_COMMAND_DONE)
  1507.                 || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
  1508.         {
  1509.                 return (LOBE_MEDIA_TEST_FAILED);
  1510.         }
  1511.         /* De-allocated Tx FCB and Frame Buffer
  1512.          * The FCB must be de-allocated manually if executing with
  1513.          * interrupts disabled, other wise the ISR (LM_Service_Events)
  1514.          * will de-allocate it when the interrupt occurs.
  1515.          */
  1516.         tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
  1517.         smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
  1518.         return (0);
  1519. }
  1520. static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
  1521.         __u16 correlator)
  1522. {
  1523.         MAC_HEADER *tmf;
  1524.         MAC_SUB_VECTOR *tsv;
  1525.         FCBlock *fcb;
  1526.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
  1527. + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
  1528. + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
  1529. == (FCBlock *)(-1L))
  1530.         {
  1531.                 return (0);
  1532.         }
  1533.         tmf  = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1534.         tmf->vc     = RPT_ADDR;
  1535.         tmf->dc_sc  = (rmf->dc_sc & SC_MASK) << 4;
  1536.         tmf->vl     = 4;
  1537.         smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
  1538.         tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
  1539.         smctr_make_corr(dev, tsv, correlator);
  1540.         tmf->vl += tsv->svl;
  1541.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1542.         smctr_make_phy_drop_num(dev, tsv);
  1543.         tmf->vl += tsv->svl;
  1544.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1545.         smctr_make_upstream_neighbor_addr(dev, tsv);
  1546.         tmf->vl += tsv->svl;
  1547.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1548.         smctr_make_addr_mod(dev, tsv);
  1549.         tmf->vl += tsv->svl;
  1550.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1551.         smctr_make_group_addr(dev, tsv);
  1552.         tmf->vl += tsv->svl;
  1553.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1554.         smctr_make_funct_addr(dev, tsv);
  1555.         tmf->vl += tsv->svl;
  1556.         /* Subtract out MVID and MVL which is
  1557.          * include in both vl and MAC_HEADER
  1558.          */
  1559. /*      fcb->frame_length           = tmf->vl + sizeof(MAC_HEADER) - 4;
  1560.         fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
  1561. */
  1562.         tmf->vl = SWAP_BYTES(tmf->vl);
  1563.         return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
  1564. }
  1565. static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
  1566.         __u16 correlator)
  1567. {
  1568.         MAC_HEADER *tmf;
  1569.         MAC_SUB_VECTOR *tsv;
  1570.         FCBlock *fcb;
  1571.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
  1572. + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
  1573. + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
  1574. == (FCBlock *)(-1L))
  1575.         {
  1576.                 return (0);
  1577.         }
  1578.         tmf     = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1579.         tmf->vc    = RPT_ATTCH;
  1580.         tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
  1581.         tmf->vl    = 4;
  1582.         smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
  1583.         tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
  1584.         smctr_make_corr(dev, tsv, correlator);
  1585.         tmf->vl += tsv->svl;
  1586.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1587.         smctr_make_product_id(dev, tsv);
  1588.         tmf->vl += tsv->svl;
  1589.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1590.         smctr_make_funct_addr(dev, tsv);
  1591.         tmf->vl += tsv->svl;
  1592.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1593.         smctr_make_auth_funct_class(dev, tsv);
  1594.         tmf->vl += tsv->svl;
  1595.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1596.         smctr_make_access_pri(dev, tsv);
  1597.         tmf->vl += tsv->svl;
  1598.         /* Subtract out MVID and MVL which is
  1599.          * include in both vl and MAC_HEADER
  1600.          */
  1601. /*      fcb->frame_length           = tmf->vl + sizeof(MAC_HEADER) - 4;
  1602.         fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
  1603. */
  1604.         tmf->vl = SWAP_BYTES(tmf->vl);
  1605.         return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
  1606. }
  1607. static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
  1608.         __u16 correlator)
  1609. {
  1610.         MAC_HEADER *tmf;
  1611.         MAC_SUB_VECTOR *tsv;
  1612.         FCBlock *fcb;
  1613.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
  1614. + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
  1615. + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
  1616. == (FCBlock *)(-1L))
  1617.         {
  1618.                 return (0);
  1619.         }
  1620.         tmf     = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1621.         tmf->vc    = RPT_STATE;
  1622.         tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
  1623.         tmf->vl    = 4;
  1624.         smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
  1625.         tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
  1626.         smctr_make_corr(dev, tsv, correlator);
  1627.         tmf->vl += tsv->svl;
  1628.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1629.         smctr_make_ring_station_version(dev, tsv);
  1630.         tmf->vl += tsv->svl;
  1631.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1632.         smctr_make_ring_station_status(dev, tsv);
  1633.         tmf->vl += tsv->svl;
  1634.         tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1635.         smctr_make_station_id(dev, tsv);
  1636.         tmf->vl += tsv->svl;
  1637.         /* Subtract out MVID and MVL which is
  1638.          * include in both vl and MAC_HEADER
  1639.          */
  1640. /*      fcb->frame_length           = tmf->vl + sizeof(MAC_HEADER) - 4;
  1641.         fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
  1642. */
  1643.         tmf->vl = SWAP_BYTES(tmf->vl);
  1644.         return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
  1645. }
  1646. static int smctr_send_rpt_tx_forward(struct net_device *dev,
  1647.         MAC_HEADER *rmf, __u16 tx_fstatus)
  1648. {
  1649.         MAC_HEADER *tmf;
  1650.         MAC_SUB_VECTOR *tsv;
  1651.         FCBlock *fcb;
  1652.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
  1653. + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
  1654.         {
  1655.                 return (0);
  1656.         }
  1657.         tmf     = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1658.         tmf->vc    = RPT_TX_FORWARD;
  1659.         tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
  1660.         tmf->vl    = 4;
  1661.         smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
  1662.         tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
  1663.         smctr_make_tx_status_code(dev, tsv, tx_fstatus);
  1664.         tmf->vl += tsv->svl;
  1665.         /* Subtract out MVID and MVL which is
  1666.          * include in both vl and MAC_HEADER
  1667.          */
  1668. /*      fcb->frame_length           = tmf->vl + sizeof(MAC_HEADER) - 4;
  1669.         fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
  1670. */
  1671.         tmf->vl = SWAP_BYTES(tmf->vl);
  1672.         return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
  1673. }
  1674. static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
  1675.         __u16 rcode, __u16 correlator)
  1676. {
  1677.         MAC_HEADER *tmf;
  1678.         MAC_SUB_VECTOR *tsv;
  1679.         FCBlock *fcb;
  1680.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
  1681. + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
  1682.         {
  1683.                 return (0);
  1684.         }
  1685.         tmf     = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1686.         tmf->vc    = RSP;
  1687.         tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
  1688.         tmf->vl    = 4;
  1689.         smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
  1690.         tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
  1691.         smctr_make_corr(dev, tsv, correlator);
  1692.         return (0);
  1693. }
  1694. static int smctr_send_rq_init(struct net_device *dev)
  1695. {
  1696.         struct net_local *tp = (struct net_local *)dev->priv;
  1697.         MAC_HEADER *tmf;
  1698.         MAC_SUB_VECTOR *tsv;
  1699.         FCBlock *fcb;
  1700. unsigned int i, count = 0;
  1701. __u16 fstatus;
  1702. int err;
  1703.         do {
  1704.          if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
  1705. + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
  1706. + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
  1707. == (FCBlock *)(-1L)))
  1708.                 {
  1709.                         return (0);
  1710.                 }
  1711.                 tmf     = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
  1712.                 tmf->vc    = RQ_INIT;
  1713.                 tmf->dc_sc = DC_RPS | SC_RS;
  1714.                 tmf->vl    = 4;
  1715.                 smctr_make_8025_hdr(dev, 0L, tmf, AC_FC_RQ_INIT);
  1716.                 tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
  1717.                 smctr_make_product_id(dev, tsv);
  1718.                 tmf->vl += tsv->svl;
  1719.                 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1720.                 smctr_make_upstream_neighbor_addr(dev, tsv);
  1721.                 tmf->vl += tsv->svl;
  1722.                 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1723.                 smctr_make_ring_station_version(dev, tsv);
  1724.                 tmf->vl += tsv->svl;
  1725.                 tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
  1726.                 smctr_make_addr_mod(dev, tsv);
  1727.                 tmf->vl += tsv->svl;
  1728.                 /* Subtract out MVID and MVL which is
  1729.                  * include in both vl and MAC_HEADER
  1730.                  */
  1731. /*              fcb->frame_length           = tmf->vl + sizeof(MAC_HEADER) - 4;
  1732.                 fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
  1733. */
  1734.                 tmf->vl = SWAP_BYTES(tmf->vl);
  1735.                 if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
  1736.                         return (err);
  1737.                 /* Wait for Transmit to Complete */
  1738.        for(i = 0; i < 10000; i++) 
  1739. {
  1740.            if(fcb->frame_status & FCB_COMMAND_DONE)
  1741.                break;
  1742.            mdelay(1);
  1743.        }
  1744.                 /* Check if GOOD frame Tx'ed */
  1745.                 fstatus = fcb->frame_status;
  1746.                 if(!(fstatus & FCB_COMMAND_DONE))
  1747.                         return (HARDWARE_FAILED);
  1748.                 if(!(fstatus & FCB_TX_STATUS_E))
  1749.                         count++;
  1750.                 /* De-allocated Tx FCB and Frame Buffer
  1751.                  * The FCB must be de-allocated manually if executing with
  1752.                  * interrupts disabled, other wise the ISR (LM_Service_Events)
  1753.                  * will de-allocate it when the interrupt occurs.
  1754.                  */
  1755.                 tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
  1756.                 smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
  1757.         } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
  1758. return (smctr_join_complete_state(dev));
  1759. }
  1760. static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
  1761.         __u16 *tx_fstatus)
  1762. {
  1763.         struct net_local *tp = (struct net_local *)dev->priv;
  1764.         FCBlock *fcb;
  1765.         unsigned int i;
  1766. int err;
  1767.         /* Check if this is the END POINT of the Transmit Forward Chain. */
  1768.         if(rmf->vl <= 18)
  1769.                 return (0);
  1770.         /* Allocate Transmit FCB only by requesting 0 bytes
  1771.          * of data buffer.
  1772.          */
  1773.         if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
  1774.                 return (0);
  1775.         /* Set pointer to Transmit Frame Buffer to the data
  1776.          * portion of the received TX Forward frame, making
  1777.          * sure to skip over the Vector Code (vc) and Vector
  1778.          * length (vl).
  1779.          */
  1780.         fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf 
  1781. + sizeof(MAC_HEADER) + 2);
  1782.         fcb->bdb_ptr->data_block_ptr     = (__u16 *)((__u32)rmf 
  1783. + sizeof(MAC_HEADER) + 2);
  1784.         fcb->frame_length                = rmf->vl - 4 - 2;
  1785.         fcb->bdb_ptr->buffer_length      = rmf->vl - 4 - 2;
  1786.         if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
  1787.                 return (err);
  1788.         /* Wait for Transmit to Complete */
  1789.     for(i = 0; i < 10000; i++) 
  1790. {
  1791.         if(fcb->frame_status & FCB_COMMAND_DONE)
  1792.             break;
  1793.          mdelay(1);
  1794.     }
  1795.         /* Check if GOOD frame Tx'ed */
  1796.         if(!(fcb->frame_status & FCB_COMMAND_DONE))
  1797.         {
  1798.                 if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
  1799.                         return (err);
  1800.        for(i = 0; i < 10000; i++) 
  1801. {
  1802.            if(fcb->frame_status & FCB_COMMAND_DONE)
  1803.                break;
  1804.          mdelay(1);
  1805.        }
  1806.                 if(!(fcb->frame_status & FCB_COMMAND_DONE))
  1807.                         return (HARDWARE_FAILED);
  1808.         }
  1809.         *tx_fstatus = fcb->frame_status;
  1810.         return (A_FRAME_WAS_FORWARDED);
  1811. }
  1812. static int smctr_set_auth_access_pri(struct net_device *dev,
  1813.         MAC_SUB_VECTOR *rsv)
  1814. {
  1815.         struct net_local *tp = (struct net_local *)dev->priv;
  1816.         if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
  1817.                 return (E_SUB_VECTOR_LENGTH_ERROR);
  1818.         tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
  1819.         return (POSITIVE_ACK);
  1820. }
  1821. static int smctr_set_auth_funct_class(struct net_device *dev,
  1822.         MAC_SUB_VECTOR *rsv)
  1823. {
  1824.         struct net_local *tp = (struct net_local *)dev->priv;
  1825.         if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
  1826.                 return (E_SUB_VECTOR_LENGTH_ERROR);
  1827.         tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
  1828.         return (POSITIVE_ACK);
  1829. }
  1830. static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
  1831.         __u16 *correlator)
  1832. {
  1833.         if(rsv->svl != S_CORRELATOR)
  1834.                 return (E_SUB_VECTOR_LENGTH_ERROR);
  1835.         *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
  1836.         return (POSITIVE_ACK);
  1837. }
  1838. static int smctr_set_error_timer_value(struct net_device *dev,
  1839.         MAC_SUB_VECTOR *rsv)
  1840. {
  1841. __u16 err_tval;
  1842. int err;
  1843.         if(rsv->svl != S_ERROR_TIMER_VALUE)
  1844.                 return (E_SUB_VECTOR_LENGTH_ERROR);
  1845.         err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
  1846.         smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
  1847.         if((err = smctr_wait_cmd(dev)))
  1848.                 return (err);
  1849.         return (POSITIVE_ACK);
  1850. }
  1851. static int smctr_set_frame_forward(struct net_device *dev,
  1852.         MAC_SUB_VECTOR *rsv, __u8 dc_sc)
  1853. {
  1854.         if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
  1855.                 return (E_SUB_VECTOR_LENGTH_ERROR);
  1856.         if((dc_sc & DC_MASK) != DC_CRS)
  1857.         {
  1858.                 if(rsv->svl >= 2 && rsv->svl < 20)
  1859.                  return (E_TRANSMIT_FORWARD_INVALID);
  1860.                 if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
  1861.                         return (E_TRANSMIT_FORWARD_INVALID);
  1862.         }
  1863.         return (POSITIVE_ACK);
  1864. }
  1865. static int smctr_set_local_ring_num(struct net_device *dev,
  1866.         MAC_SUB_VECTOR *rsv)
  1867. {
  1868.         struct net_local *tp = (struct net_local *)dev->priv;
  1869.         if(rsv->svl != S_LOCAL_RING_NUMBER)
  1870.                 return (E_SUB_VECTOR_LENGTH_ERROR);
  1871.         if(tp->ptr_local_ring_num)
  1872.                 *(__u16 *)(tp->ptr_local_ring_num) 
  1873. = (rsv->svv[0] << 8 | rsv->svv[1]);
  1874.         return (POSITIVE_ACK);
  1875. }
  1876. static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
  1877. {
  1878.         struct net_local *tp = (struct net_local *)dev->priv;
  1879.         int ioaddr = dev->base_addr;
  1880.         if(tp->bic_type == BIC_585_CHIP)
  1881.                 outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
  1882.         else
  1883.         {
  1884.                 outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
  1885.                 outb(tp->trc_mask, ioaddr + CSR);
  1886.         }
  1887.         return (0);
  1888. }
  1889. static void smctr_set_multicast_list(struct net_device *dev)
  1890. {
  1891.         if(smctr_debug > 10)
  1892.                 printk("%s: smctr_set_multicast_listn", dev->name);
  1893.         return;
  1894. }
  1895. static int smctr_set_page(struct net_device *dev, __u8 *buf)
  1896. {
  1897.         struct net_local *tp = (struct net_local *)dev->priv;
  1898.         __u8 amask;
  1899.         __u32 tptr;
  1900.         tptr = (__u32)buf - (__u32)tp->ram_access;
  1901.         amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
  1902.         outb(amask, dev->base_addr + PR);
  1903.         return (0);
  1904. }
  1905. static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
  1906. {
  1907. int err;
  1908.         if(rsv->svl != S_PHYSICAL_DROP)
  1909.                 return (E_SUB_VECTOR_LENGTH_ERROR);
  1910.         smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
  1911.         if((err = smctr_wait_cmd(dev)))
  1912.                 return (err);
  1913.         return (POSITIVE_ACK);
  1914. }
  1915. /* Reset the ring speed to the opposite of what it was. This auto-pilot
  1916.  * mode requires a complete reset and re-init of the adapter.
  1917.  */
  1918. static int smctr_set_ring_speed(struct net_device *dev)
  1919. {
  1920.         struct net_local *tp = (struct net_local *)dev->priv;
  1921. int err;
  1922.         if(tp->media_type == MEDIA_UTP_16)
  1923.                 tp->media_type = MEDIA_UTP_4;
  1924.         else
  1925.                 tp->media_type = MEDIA_UTP_16;
  1926.         smctr_enable_16bit(dev);
  1927.         /* Re-Initialize adapter's internal registers */
  1928.         smctr_reset_adapter(dev);
  1929.         if((err = smctr_init_card_real(dev)))
  1930.                 return (err);
  1931.         smctr_enable_bic_int(dev);
  1932.         if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
  1933.                 return (err);
  1934.         smctr_disable_16bit(dev);
  1935. return (0);
  1936. }
  1937. static int smctr_set_rx_look_ahead(struct net_device *dev)
  1938. {
  1939.         struct net_local *tp = (struct net_local *)dev->priv;
  1940.         __u16 sword, rword;
  1941.         if(smctr_debug > 10)
  1942.                 printk("%s: smctr_set_rx_look_ahead_flagn", dev->name);
  1943.         tp->adapter_flags &= ~(FORCED_16BIT_MODE);
  1944.         tp->adapter_flags |= RX_VALID_LOOKAHEAD;
  1945.         if(tp->adapter_bus == BUS_ISA16_TYPE)
  1946.         {
  1947.                 sword = *((__u16 *)(tp->ram_access));
  1948.                 *((__u16 *)(tp->ram_access)) = 0x1234;
  1949.                 smctr_disable_16bit(dev);
  1950.                 rword = *((__u16 *)(tp->ram_access));
  1951.                 smctr_enable_16bit(dev);
  1952.                 if(rword != 0x1234)
  1953.                         tp->adapter_flags |= FORCED_16BIT_MODE;
  1954.                 *((__u16 *)(tp->ram_access)) = sword;
  1955.         }
  1956.         return (0);
  1957. }
  1958. static int smctr_set_trc_reset(int ioaddr)
  1959. {
  1960.         __u8 r;
  1961.         r = inb(ioaddr + MSR);
  1962.         outb(MSR_RST | r, ioaddr + MSR);
  1963.         return (0);
  1964. }
  1965. /*
  1966.  * This function can be called if the adapter is busy or not.
  1967.  */
  1968. static int smctr_setup_single_cmd(struct net_device *dev,
  1969.         __u16 command, __u16 subcommand)
  1970. {
  1971.         struct net_local *tp = (struct net_local *)dev->priv;
  1972.         unsigned int err;
  1973.         if(smctr_debug > 10)
  1974.                 printk("%s: smctr_setup_single_cmdn", dev->name);
  1975.         if((err = smctr_wait_while_cbusy(dev)))
  1976.                 return (err);
  1977.         if((err = (unsigned int)smctr_wait_cmd(dev)))
  1978.                 return (err);
  1979.         tp->acb_head->cmd_done_status   = 0;
  1980.         tp->acb_head->cmd               = command;
  1981.         tp->acb_head->subcmd            = subcommand;
  1982.         err = smctr_issue_resume_acb_cmd(dev);
  1983.         return (err);
  1984. }
  1985. /*
  1986.  * This function can not be called with the adapter busy.
  1987.  */
  1988. static int smctr_setup_single_cmd_w_data(struct net_device *dev,
  1989.         __u16 command, __u16 subcommand)
  1990. {
  1991.         struct net_local *tp = (struct net_local *)dev->priv;
  1992.         tp->acb_head->cmd_done_status   = ACB_COMMAND_NOT_DONE;
  1993.         tp->acb_head->cmd               = command;
  1994.         tp->acb_head->subcmd            = subcommand;
  1995.         tp->acb_head->data_offset_lo
  1996.                 = (__u16)TRC_POINTER(tp->misc_command_data);
  1997.         return(smctr_issue_resume_acb_cmd(dev));
  1998. }
  1999. static char *smctr_malloc(struct net_device *dev, __u16 size)
  2000. {
  2001.         struct net_local *tp = (struct net_local *)dev->priv;
  2002.         char *m;
  2003.         m = (char *)(tp->ram_access + tp->sh_mem_used);
  2004.         tp->sh_mem_used += (__u32)size;
  2005.         return (m);
  2006. }
  2007. static int smctr_status_chg(struct net_device *dev)
  2008. {
  2009.         struct net_local *tp = (struct net_local *)dev->priv;
  2010.         if(smctr_debug > 10)
  2011.                 printk("%s: smctr_status_chgn", dev->name);
  2012.         switch(tp->status)
  2013.         {
  2014.                 case OPEN:
  2015.                         break;
  2016.                 case CLOSED:
  2017.                         break;
  2018.                 /* Interrupt driven open() completion. XXX */
  2019.                 case INITIALIZED:
  2020.                         tp->group_address_0 = 0;
  2021.                         tp->group_address[0] = 0;
  2022.                         tp->group_address[1] = 0;
  2023.                         tp->functional_address_0 = 0;
  2024.                         tp->functional_address[0] = 0;
  2025.                         tp->functional_address[1] = 0;
  2026.                         smctr_open_tr(dev);
  2027.                         break;
  2028.                 default:
  2029.                         printk(KERN_INFO "%s: status change unknown %xn",
  2030.                                 dev->name, tp->status);
  2031.                         break;
  2032.         }
  2033.         return (0);
  2034. }
  2035. static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
  2036.         __u16 queue)
  2037. {
  2038.         struct net_local *tp = (struct net_local *)dev->priv;
  2039.         int err = 0;
  2040.         if(smctr_debug > 10)
  2041.                 printk("%s: smctr_trc_send_packetn", dev->name);
  2042.         fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
  2043.         if(tp->num_tx_fcbs[queue] != 1)
  2044.                 fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
  2045.         if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
  2046.         {
  2047.                 tp->tx_queue_status[queue] = TRANSMITING;
  2048.                 err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
  2049.         }
  2050.         return (err);
  2051. }
  2052. static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
  2053. {
  2054.         struct net_local *tp = (struct net_local *)dev->priv;
  2055.         __u16 status, err = 0;
  2056.         int cstatus;
  2057.         if(smctr_debug > 10)
  2058.                 printk("%s: smctr_tx_completen", dev->name);
  2059.         while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
  2060.         {
  2061.                 if(status & 0x7e00 )
  2062.                 {
  2063.                         err = HARDWARE_FAILED;
  2064.                         break;
  2065.                 }
  2066.                 if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
  2067.                         queue)) != SUCCESS)
  2068.                         break;
  2069.                 smctr_disable_16bit(dev);
  2070.                 if(tp->mode_bits & UMAC)
  2071.                 {
  2072.                         if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
  2073.                                 cstatus = NO_SUCH_DESTINATION;
  2074.                         else
  2075.                         {
  2076.                                 if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
  2077.                                         cstatus = DEST_OUT_OF_RESOURCES;
  2078.                                 else
  2079.                                 {
  2080.                                         if(status & FCB_TX_STATUS_E)
  2081.                                                 cstatus = MAX_COLLISIONS;
  2082.                                         else
  2083.                                                 cstatus = SUCCESS;
  2084.                                 }
  2085.                         }
  2086.                 }
  2087.                 else
  2088.                         cstatus = SUCCESS;
  2089.                 if(queue == BUG_QUEUE)
  2090.                         err = SUCCESS;
  2091.                 smctr_enable_16bit(dev);
  2092.                 if(err != SUCCESS)
  2093.                         break;
  2094.         }
  2095.         return (err);
  2096. }
  2097. static unsigned short smctr_tx_move_frame(struct net_device *dev,
  2098.         struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
  2099. {
  2100.         struct net_local *tp = (struct net_local *)dev->priv;
  2101.         unsigned int ram_usable;
  2102.         __u32 flen, len, offset = 0;
  2103.         __u8 *frag, *page;
  2104.         if(smctr_debug > 10)
  2105.                 printk("%s: smctr_tx_move_framen", dev->name);
  2106.         ram_usable = ((unsigned int)tp->ram_usable) << 10;
  2107.         frag       = skb->data;
  2108.         flen       = skb->len;
  2109.         while(flen > 0 && bytes > 0)
  2110.         {
  2111.                 smctr_set_page(dev, pbuff);
  2112.                 offset = SMC_PAGE_OFFSET(pbuff);
  2113.                 if(offset + flen > ram_usable)
  2114.                         len = ram_usable - offset;
  2115.                 else
  2116.                         len = flen;
  2117.                 if(len > bytes)
  2118.                         len = bytes;
  2119.                 page = (char *) (offset + tp->ram_access);
  2120.                 memcpy(page, frag, len);
  2121.                 flen -=len;
  2122.                 bytes -= len;
  2123.                 frag += len;
  2124.                 pbuff += len;
  2125.         }
  2126.         return (0);
  2127. }
  2128. /* Update the error statistic counters for this adapter. */
  2129. static int smctr_update_err_stats(struct net_device *dev)
  2130. {
  2131.         struct net_local *tp = (struct net_local *)dev->priv;
  2132.         struct tr_statistics *tstat = &tp->MacStat;
  2133.         if(tstat->internal_errors)
  2134.                 tstat->internal_errors
  2135.                         += *(tp->misc_command_data + 0) & 0x00ff;
  2136.         if(tstat->line_errors)
  2137.                 tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
  2138.         if(tstat->A_C_errors)
  2139.                 tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
  2140.         if(tstat->burst_errors)
  2141.                 tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
  2142.         if(tstat->abort_delimiters)
  2143.                 tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
  2144.         if(tstat->recv_congest_count)
  2145.                 tstat->recv_congest_count
  2146.                         += *(tp->misc_command_data + 3) & 0x00ff;
  2147.         if(tstat->lost_frames)
  2148.                 tstat->lost_frames
  2149.                         += *(tp->misc_command_data + 3) >> 8;
  2150.         if(tstat->frequency_errors)
  2151.                 tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
  2152.         if(tstat->frame_copied_errors)
  2153.                  tstat->frame_copied_errors
  2154.                         += *(tp->misc_command_data + 4) >> 8;
  2155.         if(tstat->token_errors)
  2156.                 tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
  2157.         return (0);
  2158. }
  2159. static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
  2160. {
  2161.         struct net_local *tp = (struct net_local *)dev->priv;
  2162.         FCBlock *fcb;
  2163.         BDBlock *bdb;
  2164.         __u16 size, len;
  2165.         fcb = tp->rx_fcb_curr[queue];
  2166.         len = fcb->frame_length;
  2167.         fcb->frame_status = 0;
  2168.         fcb->info = FCB_CHAIN_END;
  2169.         fcb->back_ptr->info = FCB_WARNING;
  2170.         tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
  2171.         /* update RX BDBs */
  2172.         size = (len >> RX_BDB_SIZE_SHIFT);
  2173.         if(len & RX_DATA_BUFFER_SIZE_MASK)
  2174.                 size += sizeof(BDBlock);
  2175.         size &= (~RX_BDB_SIZE_MASK);
  2176.         /* check if wrap around */
  2177.         bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
  2178.         if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
  2179.         {
  2180.                 bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
  2181.                         + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
  2182.         }
  2183.         bdb->back_ptr->info = BDB_CHAIN_END;
  2184.         tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
  2185.         tp->rx_bdb_curr[queue] = bdb;
  2186.         return (0);
  2187. }
  2188. static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
  2189.         __u16 queue)
  2190. {
  2191.         struct net_local *tp = (struct net_local *)dev->priv;
  2192.         if(smctr_debug > 20)
  2193.                 printk("smctr_update_tx_chainn");
  2194.         if(tp->num_tx_fcbs_used[queue] <= 0)
  2195.                 return (HARDWARE_FAILED);
  2196.         else
  2197.         {
  2198.                 if(tp->tx_buff_used[queue] < fcb->memory_alloc)
  2199.                 {
  2200.                         tp->tx_buff_used[queue] = 0;
  2201.                         return (HARDWARE_FAILED);
  2202.                 }
  2203.                 tp->tx_buff_used[queue] -= fcb->memory_alloc;
  2204.                 /* if all transmit buffer are cleared
  2205.                  * need to set the tx_buff_curr[] to tx_buff_head[]
  2206.                  * otherwise, tx buffer will be segregate and cannot
  2207.                  * accomodate and buffer greater than (curr - head) and
  2208.                  * (end - curr) since we do not allow wrap around allocation.
  2209.                  */
  2210.                 if(tp->tx_buff_used[queue] == 0)
  2211.                         tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
  2212.                 tp->num_tx_fcbs_used[queue]--;
  2213.                 fcb->frame_status = 0;
  2214.                 tp->tx_fcb_end[queue] = fcb->next_ptr;
  2215. netif_wake_queue(dev);
  2216.                 return (0);
  2217.         }
  2218. }
  2219. static int smctr_wait_cmd(struct net_device *dev)
  2220. {
  2221.         struct net_local *tp = (struct net_local *)dev->priv;
  2222.         unsigned int loop_count = 0x20000;
  2223.         if(smctr_debug > 10)
  2224.                 printk("%s: smctr_wait_cmdn", dev->name);
  2225.         while(loop_count)
  2226.         {
  2227.                 if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
  2228.                         break;
  2229. udelay(1);
  2230.                 loop_count--;
  2231.         }
  2232.         if(loop_count == 0)
  2233.                 return(HARDWARE_FAILED);
  2234.         if(tp->acb_head->cmd_done_status & 0xff)
  2235.                 return(HARDWARE_FAILED);
  2236.         return (0);
  2237. }
  2238. static int smctr_wait_while_cbusy(struct net_device *dev)
  2239. {
  2240.         struct net_local *tp = (struct net_local *)dev->priv;
  2241.         unsigned int timeout = 0x20000;
  2242.         int ioaddr = dev->base_addr;
  2243.         __u8 r;
  2244.         if(tp->bic_type == BIC_585_CHIP)
  2245.         {
  2246.                 while(timeout)
  2247.                 {
  2248.                         r = inb(ioaddr + HWR);
  2249.                         if((r & HWR_CBUSY) == 0)
  2250.                                 break;
  2251.                         timeout--;
  2252.                 }
  2253.         }
  2254.         else
  2255.         {
  2256.                 while(timeout)
  2257.                 {
  2258.                         r = inb(ioaddr + CSR);
  2259.                         if((r & CSR_CBUSY) == 0)
  2260.                                 break;
  2261.                         timeout--;
  2262.                 }
  2263.         }
  2264.         if(timeout)
  2265.                 return (0);
  2266.         else
  2267.                 return (HARDWARE_FAILED);
  2268. }
  2269. #ifdef MODULE
  2270. static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
  2271. static int io[SMCTR_MAX_ADAPTERS];
  2272. static int irq[SMCTR_MAX_ADAPTERS];
  2273. static int mem[SMCTR_MAX_ADAPTERS];
  2274. MODULE_LICENSE("GPL");
  2275. MODULE_PARM(io,  "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
  2276. MODULE_PARM(irq, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
  2277. MODULE_PARM(mem, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
  2278. MODULE_PARM(ringspeed, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
  2279. int init_module(void)
  2280. {
  2281.         int i;
  2282.         for(i = 0; i < SMCTR_MAX_ADAPTERS; i++)
  2283.         {
  2284.                 irq[i] = 0;
  2285.                 mem[i] = 0;
  2286.                 dev_smctr[i] = NULL;
  2287.                 dev_smctr[i] = init_trdev(dev_smctr[i], 0);
  2288.                 if(dev_smctr[i] == NULL)
  2289.                         return (-ENOMEM);
  2290.                 dev_smctr[i]->base_addr = io[i];
  2291.                 dev_smctr[i]->irq       = irq[i];
  2292.                 dev_smctr[i]->mem_start = mem[i];
  2293.                 dev_smctr[i]->init      = &smctr_probe;
  2294.                 if(register_trdev(dev_smctr[i]) != 0)
  2295.                 {
  2296.                         kfree(dev_smctr[i]);
  2297.                         dev_smctr[i] = NULL;
  2298.                         if(i == 0)
  2299.                         {
  2300.                                 printk("%s: register_trdev() returned (<0).n",
  2301.                                         cardname);
  2302.                                 return (-EIO);
  2303.                         }
  2304.                         else
  2305.                                 return (0);
  2306.                 }
  2307.         }
  2308.         return (0);
  2309. }
  2310. void cleanup_module(void)
  2311. {
  2312.         int i;
  2313.         for(i = 0; i < SMCTR_MAX_ADAPTERS; i++)
  2314.         {
  2315.                 if(dev_smctr[i])
  2316.                 {
  2317. #ifdef CONFIG_MCA
  2318. struct net_local *tp 
  2319. = (struct net_local *)dev_smctr[i]->priv;
  2320. if(tp->slot_num)
  2321. mca_mark_as_unused(tp->slot_num);
  2322. #endif
  2323.                         unregister_trdev(dev_smctr[i]);
  2324.                         release_region(dev_smctr[i]->base_addr,
  2325.                                 SMCTR_IO_EXTENT);
  2326.                         if(dev_smctr[i]->irq)
  2327.                                 free_irq(dev_smctr[i]->irq, dev_smctr[i]);
  2328.                         if(dev_smctr[i]->priv)
  2329.                                 kfree(dev_smctr[i]->priv);
  2330.                         kfree(dev_smctr[i]);
  2331.                         dev_smctr[i] = NULL;
  2332.                 }
  2333.         }
  2334. }
  2335. #endif /* MODULE */