smctr.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:192k
- int err;
- err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
- TRC_INTERNAL_ROM_TEST);
- return (err);
- }
- static int smctr_issue_test_hic_cmd(struct net_device *dev)
- {
- int err;
- err = smctr_setup_single_cmd(dev, ACB_CMD_HIC_TEST,
- TRC_HOST_INTERFACE_REG_TEST);
- return (err);
- }
- static int smctr_issue_test_mac_reg_cmd(struct net_device *dev)
- {
- int err;
- err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
- TRC_MAC_REGISTERS_TEST);
- return (err);
- }
- static int smctr_issue_trc_loopback_cmd(struct net_device *dev)
- {
- int err;
- err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
- TRC_INTERNAL_LOOPBACK);
- return (err);
- }
- static int smctr_issue_tri_loopback_cmd(struct net_device *dev)
- {
- int err;
- err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
- TRC_TRI_LOOPBACK);
- return (err);
- }
- static int smctr_issue_write_byte_cmd(struct net_device *dev,
- short aword_cnt, void *byte)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int iword, ibyte;
- int err;
- if((err = smctr_wait_while_cbusy(dev)))
- return (err);
- if((err = smctr_wait_cmd(dev)))
- return (err);
- for(iword = 0, ibyte = 0; iword < (unsigned int)(aword_cnt & 0xff);
- iword++, ibyte += 2)
- {
- tp->misc_command_data[iword] = (*((__u8 *)byte + ibyte) << 8)
- | (*((__u8 *)byte + ibyte + 1));
- }
- return (smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
- aword_cnt));
- }
- static int smctr_issue_write_word_cmd(struct net_device *dev,
- short aword_cnt, void *word)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int i, err;
- if((err = smctr_wait_while_cbusy(dev)))
- return (err);
- if((err = smctr_wait_cmd(dev)))
- return (err);
- for(i = 0; i < (unsigned int)(aword_cnt & 0xff); i++)
- tp->misc_command_data[i] = *((__u16 *)word + i);
- err = smctr_setup_single_cmd_w_data(dev, ACB_CMD_MCT_WRITE_VALUE,
- aword_cnt);
- return (err);
- }
- static int smctr_join_complete_state(struct net_device *dev)
- {
- int err;
- err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
- JS_JOIN_COMPLETE_STATE);
- return (err);
- }
- static int smctr_link_tx_fcbs_to_bdbs(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int i, j;
- FCBlock *fcb;
- BDBlock *bdb;
- for(i = 0; i < NUM_TX_QS_USED; i++)
- {
- fcb = tp->tx_fcb_head[i];
- bdb = tp->tx_bdb_head[i];
- for(j = 0; j < tp->num_tx_fcbs[i]; j++)
- {
- fcb->bdb_ptr = bdb;
- fcb->trc_bdb_ptr = TRC_POINTER(bdb);
- fcb = (FCBlock *)((char *)fcb + sizeof(FCBlock));
- bdb = (BDBlock *)((char *)bdb + sizeof(BDBlock));
- }
- }
- return (0);
- }
- static int smctr_load_firmware(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- __u16 i, checksum = 0;
- int err = 0;
- if(smctr_debug > 10)
- printk("%s: smctr_load_firmwaren", dev->name);
- tp->ptr_ucode = smctr_code;
- tp->num_of_tx_buffs = 4;
- tp->mode_bits |= UMAC;
- tp->receive_mask = 0;
- tp->max_packet_size = 4177;
- /* Can only upload the firmware once per adapter reset. */
- if(tp->microcode_version != 0)
- return (UCODE_PRESENT);
- /* Verify the firmware exists and is there in the right amount. */
- if((tp->ptr_ucode == 0L)
- || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET) < UCODE_VERSION))
- {
- return (UCODE_NOT_PRESENT);
- }
- /* UCODE_SIZE is not included in Checksum. */
- for(i = 0; i < *((__u16 *)(tp->ptr_ucode + UCODE_SIZE_OFFSET)); i += 2)
- checksum += *((__u16 *)(tp->ptr_ucode + 2 + i));
- if(checksum)
- return (UCODE_NOT_PRESENT);
- /* At this point we have a valid firmware image, lets kick it on up. */
- smctr_enable_adapter_ram(dev);
- smctr_enable_16bit(dev);
- smctr_set_page(dev, (__u8 *)tp->ram_access);
- if((smctr_checksum_firmware(dev))
- || (*(tp->ptr_ucode + UCODE_VERSION_OFFSET)
- > tp->microcode_version))
- {
- smctr_enable_adapter_ctrl_store(dev);
- /* Zero out ram space for firmware. */
- for(i = 0; i < CS_RAM_SIZE; i += 2)
- *((__u16 *)(tp->ram_access + i)) = 0;
- smctr_decode_firmware(dev);
- tp->microcode_version = *(tp->ptr_ucode + UCODE_VERSION_OFFSET); *((__u16 *)(tp->ram_access + CS_RAM_VERSION_OFFSET))
- = (tp->microcode_version << 8);
- *((__u16 *)(tp->ram_access + CS_RAM_CHECKSUM_OFFSET))
- = ~(tp->microcode_version << 8) + 1;
- smctr_disable_adapter_ctrl_store(dev);
- if(smctr_checksum_firmware(dev))
- err = HARDWARE_FAILED;
- }
- else
- err = UCODE_PRESENT;
- smctr_disable_16bit(dev);
- return (err);
- }
- static int smctr_load_node_addr(struct net_device *dev)
- {
- int ioaddr = dev->base_addr;
- unsigned int i;
- __u8 r;
- /* Check if node address has been specified by user. (non-0) */
- for(i = 0; ((i < 6) && (dev->dev_addr[i] == 0)); i++);
- {
- if(i != 6)
- {
- for(i = 0; i < 6; i++)
- {
- r = inb(ioaddr + LAR0 + i);
- dev->dev_addr[i] = (char)r;
- }
- dev->addr_len = 6;
- }
- else /* Node addr. not given by user, read it from board. */
- {
- for(i = 0; i < 6; i++)
- {
- r = inb(ioaddr + LAR0 + i);
- dev->dev_addr[i] = (char)r;
- }
- dev->addr_len = 6;
- }
- }
- return (0);
- }
- /* Lobe Media Test.
- * During the transmission of the initial 1500 lobe media MAC frames,
- * the phase lock loop in the 805 chip may lock, and then un-lock, causing
- * the 825 to go into a PURGE state. When performing a PURGE, the MCT
- * microcode will not transmit any frames given to it by the host, and
- * will consequently cause a timeout.
- *
- * NOTE 1: If the monitor_state is MS_BEACON_TEST_STATE, all transmit
- * queues other then the one used for the lobe_media_test should be
- * disabled.!?
- *
- * NOTE 2: If the monitor_state is MS_BEACON_TEST_STATE and the receive_mask
- * has any multi-cast or promiscous bits set, the receive_mask needs to
- * be changed to clear the multi-cast or promiscous mode bits, the lobe_test
- * run, and then the receive mask set back to its original value if the test
- * is successful.
- */
- static int smctr_lobe_media_test(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int i, perror = 0;
- unsigned short saved_rcv_mask;
- if(smctr_debug > 10)
- printk("%s: smctr_lobe_media_testn", dev->name);
- /* Clear receive mask for lobe test. */
- saved_rcv_mask = tp->receive_mask;
- tp->receive_mask = 0;
- smctr_chg_rx_mask(dev);
- /* Setup the lobe media test. */
- smctr_lobe_media_test_cmd(dev);
- if(smctr_wait_cmd(dev))
- {
- smctr_reset_adapter(dev);
- tp->status = CLOSED;
- return (LOBE_MEDIA_TEST_FAILED);
- }
- /* Tx lobe media test frames. */
- for(i = 0; i < 1500; ++i)
- {
- if(smctr_send_lobe_media_test(dev))
- {
- if(perror)
- {
- smctr_reset_adapter(dev);
- tp->state = CLOSED;
- return (LOBE_MEDIA_TEST_FAILED);
- }
- else
- {
- perror = 1;
- if(smctr_lobe_media_test_cmd(dev))
- {
- smctr_reset_adapter(dev);
- tp->state = CLOSED;
- return (LOBE_MEDIA_TEST_FAILED);
- }
- }
- }
- }
- if(smctr_send_dat(dev))
- {
- if(smctr_send_dat(dev))
- {
- smctr_reset_adapter(dev);
- tp->state = CLOSED;
- return (LOBE_MEDIA_TEST_FAILED);
- }
- }
- /* Check if any frames received during test. */
- if((tp->rx_fcb_curr[MAC_QUEUE]->frame_status)
- || (tp->rx_fcb_curr[NON_MAC_QUEUE]->frame_status))
- {
- smctr_reset_adapter(dev);
- tp->state = CLOSED;
- return (LOBE_MEDIA_TEST_FAILED);
- }
- /* Set receive mask to "Promisc" mode. */
- tp->receive_mask = saved_rcv_mask;
- smctr_chg_rx_mask(dev);
- return (0);
- }
- static int smctr_lobe_media_test_cmd(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- int err;
- if(smctr_debug > 10)
- printk("%s: smctr_lobe_media_test_cmdn", dev->name);
- /* Change to lobe media test state. */
- if(tp->monitor_state != MS_BEACON_TEST_STATE)
- {
- smctr_lobe_media_test_state(dev);
- if(smctr_wait_cmd(dev))
- {
- printk("Lobe Failed test staten");
- return (LOBE_MEDIA_TEST_FAILED);
- }
- }
- err = smctr_setup_single_cmd(dev, ACB_CMD_MCT_TEST,
- TRC_LOBE_MEDIA_TEST);
- return (err);
- }
- static int smctr_lobe_media_test_state(struct net_device *dev)
- {
- int err;
- err = smctr_setup_single_cmd(dev, ACB_CMD_CHANGE_JOIN_STATE,
- JS_LOBE_TEST_STATE);
- return (err);
- }
- static int smctr_make_8025_hdr(struct net_device *dev,
- MAC_HEADER *rmf, MAC_HEADER *tmf, __u16 ac_fc)
- {
- tmf->ac = MSB(ac_fc); /* msb is access control */
- tmf->fc = LSB(ac_fc); /* lsb is frame control */
- tmf->sa[0] = dev->dev_addr[0];
- tmf->sa[1] = dev->dev_addr[1];
- tmf->sa[2] = dev->dev_addr[2];
- tmf->sa[3] = dev->dev_addr[3];
- tmf->sa[4] = dev->dev_addr[4];
- tmf->sa[5] = dev->dev_addr[5];
- switch(tmf->vc)
- {
- /* Send RQ_INIT to RPS */
- case RQ_INIT:
- tmf->da[0] = 0xc0;
- tmf->da[1] = 0x00;
- tmf->da[2] = 0x00;
- tmf->da[3] = 0x00;
- tmf->da[4] = 0x00;
- tmf->da[5] = 0x02;
- break;
- /* Send RPT_TX_FORWARD to CRS */
- case RPT_TX_FORWARD:
- tmf->da[0] = 0xc0;
- tmf->da[1] = 0x00;
- tmf->da[2] = 0x00;
- tmf->da[3] = 0x00;
- tmf->da[4] = 0x00;
- tmf->da[5] = 0x10;
- break;
- /* Everything else goes to sender */
- default:
- tmf->da[0] = rmf->sa[0];
- tmf->da[1] = rmf->sa[1];
- tmf->da[2] = rmf->sa[2];
- tmf->da[3] = rmf->sa[3];
- tmf->da[4] = rmf->sa[4];
- tmf->da[5] = rmf->sa[5];
- break;
- }
- return (0);
- }
- static int smctr_make_access_pri(struct net_device *dev, MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- tsv->svi = AUTHORIZED_ACCESS_PRIORITY;
- tsv->svl = S_AUTHORIZED_ACCESS_PRIORITY;
- tsv->svv[0] = MSB(tp->authorized_access_priority);
- tsv->svv[1] = LSB(tp->authorized_access_priority);
- return (0);
- }
- static int smctr_make_addr_mod(struct net_device *dev, MAC_SUB_VECTOR *tsv)
- {
- tsv->svi = ADDRESS_MODIFER;
- tsv->svl = S_ADDRESS_MODIFER;
- tsv->svv[0] = 0;
- tsv->svv[1] = 0;
- return (0);
- }
- static int smctr_make_auth_funct_class(struct net_device *dev,
- MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- tsv->svi = AUTHORIZED_FUNCTION_CLASS;
- tsv->svl = S_AUTHORIZED_FUNCTION_CLASS;
- tsv->svv[0] = MSB(tp->authorized_function_classes);
- tsv->svv[1] = LSB(tp->authorized_function_classes);
- return (0);
- }
- static int smctr_make_corr(struct net_device *dev,
- MAC_SUB_VECTOR *tsv, __u16 correlator)
- {
- tsv->svi = CORRELATOR;
- tsv->svl = S_CORRELATOR;
- tsv->svv[0] = MSB(correlator);
- tsv->svv[1] = LSB(correlator);
- return (0);
- }
- static int smctr_make_funct_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- smctr_get_functional_address(dev);
- tsv->svi = FUNCTIONAL_ADDRESS;
- tsv->svl = S_FUNCTIONAL_ADDRESS;
- tsv->svv[0] = MSB(tp->misc_command_data[0]);
- tsv->svv[1] = LSB(tp->misc_command_data[0]);
- tsv->svv[2] = MSB(tp->misc_command_data[1]);
- tsv->svv[3] = LSB(tp->misc_command_data[1]);
- return (0);
- }
- static int smctr_make_group_addr(struct net_device *dev, MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- smctr_get_group_address(dev);
- tsv->svi = GROUP_ADDRESS;
- tsv->svl = S_GROUP_ADDRESS;
- tsv->svv[0] = MSB(tp->misc_command_data[0]);
- tsv->svv[1] = LSB(tp->misc_command_data[0]);
- tsv->svv[2] = MSB(tp->misc_command_data[1]);
- tsv->svv[3] = LSB(tp->misc_command_data[1]);
- /* Set Group Address Sub-vector to all zeros if only the
- * Group Address/Functional Address Indicator is set.
- */
- if(tsv->svv[0] == 0x80 && tsv->svv[1] == 0x00
- && tsv->svv[2] == 0x00 && tsv->svv[3] == 0x00)
- tsv->svv[0] = 0x00;
- return (0);
- }
- static int smctr_make_phy_drop_num(struct net_device *dev,
- MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- smctr_get_physical_drop_number(dev);
- tsv->svi = PHYSICAL_DROP;
- tsv->svl = S_PHYSICAL_DROP;
- tsv->svv[0] = MSB(tp->misc_command_data[0]);
- tsv->svv[1] = LSB(tp->misc_command_data[0]);
- tsv->svv[2] = MSB(tp->misc_command_data[1]);
- tsv->svv[3] = LSB(tp->misc_command_data[1]);
- return (0);
- }
- static int smctr_make_product_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
- {
- int i;
- tsv->svi = PRODUCT_INSTANCE_ID;
- tsv->svl = S_PRODUCT_INSTANCE_ID;
- for(i = 0; i < 18; i++)
- tsv->svv[i] = 0xF0;
- return (0);
- }
- static int smctr_make_station_id(struct net_device *dev, MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- smctr_get_station_id(dev);
- tsv->svi = STATION_IDENTIFER;
- tsv->svl = S_STATION_IDENTIFER;
- tsv->svv[0] = MSB(tp->misc_command_data[0]);
- tsv->svv[1] = LSB(tp->misc_command_data[0]);
- tsv->svv[2] = MSB(tp->misc_command_data[1]);
- tsv->svv[3] = LSB(tp->misc_command_data[1]);
- tsv->svv[4] = MSB(tp->misc_command_data[2]);
- tsv->svv[5] = LSB(tp->misc_command_data[2]);
- return (0);
- }
- static int smctr_make_ring_station_status(struct net_device *dev,
- MAC_SUB_VECTOR * tsv)
- {
- tsv->svi = RING_STATION_STATUS;
- tsv->svl = S_RING_STATION_STATUS;
- tsv->svv[0] = 0;
- tsv->svv[1] = 0;
- tsv->svv[2] = 0;
- tsv->svv[3] = 0;
- tsv->svv[4] = 0;
- tsv->svv[5] = 0;
- return (0);
- }
- static int smctr_make_ring_station_version(struct net_device *dev,
- MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- tsv->svi = RING_STATION_VERSION_NUMBER;
- tsv->svl = S_RING_STATION_VERSION_NUMBER;
- tsv->svv[0] = 0xe2; /* EBCDIC - S */
- tsv->svv[1] = 0xd4; /* EBCDIC - M */
- tsv->svv[2] = 0xc3; /* EBCDIC - C */
- tsv->svv[3] = 0x40; /* EBCDIC - */
- tsv->svv[4] = 0xe5; /* EBCDIC - V */
- tsv->svv[5] = 0xF0 + (tp->microcode_version >> 4);
- tsv->svv[6] = 0xF0 + (tp->microcode_version & 0x0f);
- tsv->svv[7] = 0x40; /* EBCDIC - */
- tsv->svv[8] = 0xe7; /* EBCDIC - X */
- if(tp->extra_info & CHIP_REV_MASK)
- tsv->svv[9] = 0xc5; /* EBCDIC - E */
- else
- tsv->svv[9] = 0xc4; /* EBCDIC - D */
- return (0);
- }
- static int smctr_make_tx_status_code(struct net_device *dev,
- MAC_SUB_VECTOR *tsv, __u16 tx_fstatus)
- {
- tsv->svi = TRANSMIT_STATUS_CODE;
- tsv->svl = S_TRANSMIT_STATUS_CODE;
- tsv->svv[0] = ((tx_fstatus & 0x0100 >> 6) || IBM_PASS_SOURCE_ADDR);
- /* Stripped frame status of Transmitted Frame */
- tsv->svv[1] = tx_fstatus & 0xff;
- return (0);
- }
- static int smctr_make_upstream_neighbor_addr(struct net_device *dev,
- MAC_SUB_VECTOR *tsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- smctr_get_upstream_neighbor_addr(dev);
- tsv->svi = UPSTREAM_NEIGHBOR_ADDRESS;
- tsv->svl = S_UPSTREAM_NEIGHBOR_ADDRESS;
- tsv->svv[0] = MSB(tp->misc_command_data[0]);
- tsv->svv[1] = LSB(tp->misc_command_data[0]);
- tsv->svv[2] = MSB(tp->misc_command_data[1]);
- tsv->svv[3] = LSB(tp->misc_command_data[1]);
- tsv->svv[4] = MSB(tp->misc_command_data[2]);
- tsv->svv[5] = LSB(tp->misc_command_data[2]);
- return (0);
- }
- static int smctr_make_wrap_data(struct net_device *dev, MAC_SUB_VECTOR *tsv)
- {
- tsv->svi = WRAP_DATA;
- tsv->svl = S_WRAP_DATA;
- return (0);
- }
- /*
- * Open/initialize the board. This is called sometime after
- * booting when the 'ifconfig' program is run.
- *
- * This routine should set everything up anew at each open, even
- * registers that "should" only need to be set once at boot, so that
- * there is non-reboot way to recover if something goes wrong.
- */
- static int smctr_open(struct net_device *dev)
- {
- int err;
- if(smctr_debug > 10)
- printk("%s: smctr_openn", dev->name);
- err = smctr_init_adapter(dev);
- if(err < 0)
- return (err);
- #ifdef MODULE
- MOD_INC_USE_COUNT;
- #endif
- return (err);
- }
- /* Interrupt driven open of Token card. */
- static int smctr_open_tr(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned long flags;
- int err;
- if(smctr_debug > 10)
- printk("%s: smctr_open_trn", dev->name);
- /* Now we can actually open the adapter. */
- if(tp->status == OPEN)
- return (0);
- if(tp->status != INITIALIZED)
- return (-1);
- save_flags(flags);
- cli();
- smctr_set_page(dev, (__u8 *)tp->ram_access);
- if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)MAC_QUEUE)))
- goto out;
- if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)MAC_QUEUE)))
- goto out;
- if((err = smctr_issue_resume_rx_fcb_cmd(dev, (short)NON_MAC_QUEUE)))
- goto out;
- if((err = smctr_issue_resume_rx_bdb_cmd(dev, (short)NON_MAC_QUEUE)))
- goto out;
- tp->status = CLOSED;
- /* Insert into the Ring or Enter Loopback Mode. */
- if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_1)
- {
- tp->status = CLOSED;
- if(!(err = smctr_issue_trc_loopback_cmd(dev)))
- {
- if(!(err = smctr_wait_cmd(dev)))
- tp->status = OPEN;
- }
- smctr_status_chg(dev);
- }
- else
- {
- if((tp->mode_bits & LOOPING_MODE_MASK) == LOOPBACK_MODE_2)
- {
- tp->status = CLOSED;
- if(!(err = smctr_issue_tri_loopback_cmd(dev)))
- {
- if(!(err = smctr_wait_cmd(dev)))
- tp->status = OPEN;
- }
- smctr_status_chg(dev);
- }
- else
- {
- if((tp->mode_bits & LOOPING_MODE_MASK)
- == LOOPBACK_MODE_3)
- {
- tp->status = CLOSED;
- if(!(err = smctr_lobe_media_test_cmd(dev)))
- {
- if(!(err = smctr_wait_cmd(dev)))
- tp->status = OPEN;
- }
- smctr_status_chg(dev);
- }
- else
- {
- if(!(err = smctr_lobe_media_test(dev)))
- err = smctr_issue_insert_cmd(dev);
- else
- {
- if(err == LOBE_MEDIA_TEST_FAILED)
- printk("%s: Lobe Media Test Failure - Check cable?n", dev->name);
- }
- }
- }
- }
- out:
- restore_flags(flags);
- return (err);
- }
- /* Check for a network adapter of this type, and return '0 if one exists.
- * If dev->base_addr == 0, probe all likely locations.
- * If dev->base_addr == 1, always return failure.
- */
- int __init smctr_probe (struct net_device *dev)
- {
- int i;
- int base_addr = dev ? dev->base_addr : 0;
- if(base_addr > 0x1ff) /* Check a single specified location. */
- return (smctr_probe1(dev, base_addr));
- else if(base_addr != 0) /* Don't probe at all. */
- return (-ENXIO);
- for(i = 0; smctr_portlist[i]; i++)
- {
- int ioaddr = smctr_portlist[i];
- if(check_region(ioaddr, SMCTR_IO_EXTENT))
- continue;
- if (!smctr_probe1(dev, ioaddr))
- return (0);
- }
- return (-ENODEV);
- }
- static int __init smctr_probe1(struct net_device *dev, int ioaddr)
- {
- static unsigned version_printed;
- struct net_local *tp;
- int err;
- __u32 *ram;
- if(smctr_debug && version_printed++ == 0)
- printk(version);
- #ifndef MODULE
- dev = init_trdev(dev, 0);
- if(dev == NULL)
- return (-ENOMEM);
- #endif
- /* Setup this devices private information structure */
- tp = (struct net_local *)kmalloc(sizeof(struct net_local),
- GFP_KERNEL);
- if(tp == NULL) {
- err = -ENOMEM;
- goto out;
- }
- memset(tp, 0, sizeof(struct net_local));
- dev->priv = tp;
- dev->base_addr = ioaddr;
- /* Actually detect an adapter now. */
- err = smctr_chk_isa(dev);
- if(err < 0)
- {
- if ((err = smctr_chk_mca(dev)) < 0) {
- err = -ENODEV;
- goto out_tp;
- }
- }
- tp = (struct net_local *)dev->priv;
- dev->rmem_start = dev->mem_start = tp->ram_base;
- dev->rmem_end = dev->mem_end = dev->mem_start + 0x10000;
- ram = (__u32 *)phys_to_virt(dev->mem_start);
- tp->ram_access = *(__u32 *)&ram;
- tp->status = NOT_INITIALIZED;
- err = smctr_load_firmware(dev);
- if(err != UCODE_PRESENT && err != SUCCESS)
- {
- printk("%s: Firmware load failed (%d)n", dev->name, err);
- err = -EIO;
- goto out_tp;
- }
- /* Allow user to specify ring speed on module insert. */
- if(ringspeed == 4)
- tp->media_type = MEDIA_UTP_4;
- else
- tp->media_type = MEDIA_UTP_16;
- printk("%s: %s %s at Io %#4x, Irq %d, Rom %#4x, Ram %#4x.n",
- dev->name, smctr_name, smctr_model,
- (unsigned int)dev->base_addr,
- dev->irq, tp->rom_base, tp->ram_base);
- /* AKPM: there's no point in this */
- dev->init = smctr_init_card;
- dev->open = smctr_open;
- dev->stop = smctr_close;
- dev->hard_start_xmit = smctr_send_packet;
- dev->tx_timeout = smctr_timeout;
- dev->watchdog_timeo = HZ;
- dev->get_stats = smctr_get_stats;
- dev->set_multicast_list = &smctr_set_multicast_list;
- return (0);
- out_tp:
- kfree(tp);
- out:
- return err;
- }
- static int smctr_process_rx_packet(MAC_HEADER *rmf, __u16 size,
- struct net_device *dev, __u16 rx_status)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- struct sk_buff *skb;
- __u16 rcode, correlator;
- int err = 0;
- __u8 xframe = 1;
- __u16 tx_fstatus;
- rmf->vl = SWAP_BYTES(rmf->vl);
- if(rx_status & FCB_RX_STATUS_DA_MATCHED)
- {
- switch(rmf->vc)
- {
- /* Received MAC Frames Processed by RS. */
- case INIT:
- if((rcode = smctr_rcv_init(dev, rmf,
- &correlator)) == HARDWARE_FAILED)
- {
- return (rcode);
- }
- if((err = smctr_send_rsp(dev, rmf, rcode,
- correlator)))
- {
- return (err);
- }
- break;
- case CHG_PARM:
- if((rcode = smctr_rcv_chg_param(dev, rmf,
- &correlator)) ==HARDWARE_FAILED)
- {
- return (rcode);
- }
- if((err = smctr_send_rsp(dev, rmf, rcode,
- correlator)))
- {
- return (err);
- }
- break;
- case RQ_ADDR:
- if((rcode = smctr_rcv_rq_addr_state_attch(dev,
- rmf, &correlator)) != POSITIVE_ACK)
- {
- if(rcode == HARDWARE_FAILED)
- return (rcode);
- else
- return (smctr_send_rsp(dev, rmf,
- rcode, correlator));
- }
- if((err = smctr_send_rpt_addr(dev, rmf,
- correlator)))
- {
- return (err);
- }
- break;
- case RQ_ATTCH:
- if((rcode = smctr_rcv_rq_addr_state_attch(dev,
- rmf, &correlator)) != POSITIVE_ACK)
- {
- if(rcode == HARDWARE_FAILED)
- return (rcode);
- else
- return (smctr_send_rsp(dev, rmf,
- rcode,
- correlator));
- }
- if((err = smctr_send_rpt_attch(dev, rmf,
- correlator)))
- {
- return (err);
- }
- break;
- case RQ_STATE:
- if((rcode = smctr_rcv_rq_addr_state_attch(dev,
- rmf, &correlator)) != POSITIVE_ACK)
- {
- if(rcode == HARDWARE_FAILED)
- return (rcode);
- else
- return (smctr_send_rsp(dev, rmf,
- rcode,
- correlator));
- }
- if((err = smctr_send_rpt_state(dev, rmf,
- correlator)))
- {
- return (err);
- }
- break;
- case TX_FORWARD:
- if((rcode = smctr_rcv_tx_forward(dev, rmf))
- != POSITIVE_ACK)
- {
- if(rcode == HARDWARE_FAILED)
- return (rcode);
- else
- return (smctr_send_rsp(dev, rmf,
- rcode,
- correlator));
- }
- if((err = smctr_send_tx_forward(dev, rmf,
- &tx_fstatus)) == HARDWARE_FAILED)
- {
- return (err);
- }
- if(err == A_FRAME_WAS_FORWARDED)
- {
- if((err = smctr_send_rpt_tx_forward(dev,
- rmf, tx_fstatus))
- == HARDWARE_FAILED)
- {
- return (err);
- }
- }
- break;
- /* Received MAC Frames Processed by CRS/REM/RPS. */
- case RSP:
- case RQ_INIT:
- case RPT_NEW_MON:
- case RPT_SUA_CHG:
- case RPT_ACTIVE_ERR:
- case RPT_NN_INCMP:
- case RPT_ERROR:
- case RPT_ATTCH:
- case RPT_STATE:
- case RPT_ADDR:
- break;
- /* Rcvd Att. MAC Frame (if RXATMAC set) or UNKNOWN */
- default:
- xframe = 0;
- if(!(tp->receive_mask & ACCEPT_ATT_MAC_FRAMES))
- {
- rcode = smctr_rcv_unknown(dev, rmf,
- &correlator);
- if((err = smctr_send_rsp(dev, rmf,rcode,
- correlator)))
- {
- return (err);
- }
- }
- break;
- }
- }
- else
- {
- /* 1. DA doesn't match (Promiscuous Mode).
- * 2. Parse for Extended MAC Frame Type.
- */
- switch(rmf->vc)
- {
- case RSP:
- case INIT:
- case RQ_INIT:
- case RQ_ADDR:
- case RQ_ATTCH:
- case RQ_STATE:
- case CHG_PARM:
- case RPT_ADDR:
- case RPT_ERROR:
- case RPT_ATTCH:
- case RPT_STATE:
- case RPT_NEW_MON:
- case RPT_SUA_CHG:
- case RPT_NN_INCMP:
- case RPT_ACTIVE_ERR:
- break;
- default:
- xframe = 0;
- break;
- }
- }
- /* NOTE: UNKNOWN MAC frames will NOT be passed up unless
- * ACCEPT_ATT_MAC_FRAMES is set.
- */
- if(((tp->receive_mask & ACCEPT_ATT_MAC_FRAMES)
- && (xframe == (__u8)0))
- || ((tp->receive_mask & ACCEPT_EXT_MAC_FRAMES)
- && (xframe == (__u8)1)))
- {
- rmf->vl = SWAP_BYTES(rmf->vl);
- if (!(skb = dev_alloc_skb(size)))
- return -ENOMEM;
- skb->len = size;
- /* Slide data into a sleek skb. */
- skb_put(skb, skb->len);
- memcpy(skb->data, rmf, skb->len);
- /* Update Counters */
- tp->MacStat.rx_packets++;
- tp->MacStat.rx_bytes += skb->len;
- /* Kick the packet on up. */
- skb->dev = dev;
- skb->protocol = tr_type_trans(skb, dev);
- netif_rx(skb);
- dev->last_rx = jiffies;
- err = 0;
- }
- return (err);
- }
- /* Adapter RAM test. Incremental word ODD boundry data test. */
- static int smctr_ram_memory_test(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- __u16 page, pages_of_ram, start_pattern = 0, word_pattern = 0,
- word_read = 0, err_word = 0, err_pattern = 0;
- unsigned int err_offset;
- __u32 j, pword;
- __u8 err = 0;
- if(smctr_debug > 10)
- printk("%s: smctr_ram_memory_testn", dev->name);
- start_pattern = 0x0001;
- pages_of_ram = tp->ram_size / tp->ram_usable;
- pword = tp->ram_access;
- /* Incremental word ODD boundry test. */
- for(page = 0; (page < pages_of_ram) && (~err);
- page++, start_pattern += 0x8000)
- {
- smctr_set_page(dev, (__u8 *)(tp->ram_access
- + (page * tp->ram_usable * 1024) + 1));
- word_pattern = start_pattern;
- for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1; j += 2)
- *(__u16 *)(pword + j) = word_pattern++;
- word_pattern = start_pattern;
- for(j = 1; j < (__u32)(tp->ram_usable * 1024) - 1
- && (~err); j += 2, word_pattern++)
- {
- word_read = *(__u16 *)(pword + j);
- if(word_read != word_pattern)
- {
- err = (__u8)1;
- err_offset = j;
- err_word = word_read;
- err_pattern = word_pattern;
- return (RAM_TEST_FAILED);
- }
- }
- }
- /* Zero out memory. */
- for(page = 0; page < pages_of_ram && (~err); page++)
- {
- smctr_set_page(dev, (__u8 *)(tp->ram_access
- + (page * tp->ram_usable * 1024)));
- word_pattern = 0;
- for(j = 0; j < (__u32)tp->ram_usable * 1024; j +=2)
- *(__u16 *)(pword + j) = word_pattern;
- for(j =0; j < (__u32)tp->ram_usable * 1024
- && (~err); j += 2)
- {
- word_read = *(__u16 *)(pword + j);
- if(word_read != word_pattern)
- {
- err = (__u8)1;
- err_offset = j;
- err_word = word_read;
- err_pattern = word_pattern;
- return (RAM_TEST_FAILED);
- }
- }
- }
- smctr_set_page(dev, (__u8 *)tp->ram_access);
- return (0);
- }
- static int smctr_rcv_chg_param(struct net_device *dev, MAC_HEADER *rmf,
- __u16 *correlator)
- {
- MAC_SUB_VECTOR *rsv;
- signed short vlen;
- __u16 rcode = POSITIVE_ACK;
- unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
- /* This Frame can only come from a CRS */
- if((rmf->dc_sc & SC_MASK) != SC_CRS)
- return(E_INAPPROPRIATE_SOURCE_CLASS);
- /* Remove MVID Length from total length. */
- vlen = (signed short)rmf->vl - 4;
- /* Point to First SVID */
- rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
- /* Search for Appropriate SVID's. */
- while((vlen > 0) && (rcode == POSITIVE_ACK))
- {
- switch(rsv->svi)
- {
- case CORRELATOR:
- svectors |= F_CORRELATOR;
- rcode = smctr_set_corr(dev, rsv, correlator);
- break;
- case LOCAL_RING_NUMBER:
- svectors |= F_LOCAL_RING_NUMBER;
- rcode = smctr_set_local_ring_num(dev, rsv);
- break;
- case ASSIGN_PHYSICAL_DROP:
- svectors |= F_ASSIGN_PHYSICAL_DROP;
- rcode = smctr_set_phy_drop(dev, rsv);
- break;
- case ERROR_TIMER_VALUE:
- svectors |= F_ERROR_TIMER_VALUE;
- rcode = smctr_set_error_timer_value(dev, rsv);
- break;
- case AUTHORIZED_FUNCTION_CLASS:
- svectors |= F_AUTHORIZED_FUNCTION_CLASS;
- rcode = smctr_set_auth_funct_class(dev, rsv);
- break;
- case AUTHORIZED_ACCESS_PRIORITY:
- svectors |= F_AUTHORIZED_ACCESS_PRIORITY;
- rcode = smctr_set_auth_access_pri(dev, rsv);
- break;
- default:
- rcode = E_SUB_VECTOR_UNKNOWN;
- break;
- }
- /* Let Sender Know if SUM of SV length's is
- * larger then length in MVID length field
- */
- if((vlen -= rsv->svl) < 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
- }
- if(rcode == POSITIVE_ACK)
- {
- /* Let Sender Know if MVID length field
- * is larger then SUM of SV length's
- */
- if(vlen != 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- else
- {
- /* Let Sender Know if Expected SVID Missing */
- if((svectors & R_CHG_PARM) ^ R_CHG_PARM)
- rcode = E_MISSING_SUB_VECTOR;
- }
- }
- return (rcode);
- }
- static int smctr_rcv_init(struct net_device *dev, MAC_HEADER *rmf,
- __u16 *correlator)
- {
- MAC_SUB_VECTOR *rsv;
- signed short vlen;
- __u16 rcode = POSITIVE_ACK;
- unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
- /* This Frame can only come from a RPS */
- if((rmf->dc_sc & SC_MASK) != SC_RPS)
- return (E_INAPPROPRIATE_SOURCE_CLASS);
- /* Remove MVID Length from total length. */
- vlen = (signed short)rmf->vl - 4;
- /* Point to First SVID */
- rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
- /* Search for Appropriate SVID's */
- while((vlen > 0) && (rcode == POSITIVE_ACK))
- {
- switch(rsv->svi)
- {
- case CORRELATOR:
- svectors |= F_CORRELATOR;
- rcode = smctr_set_corr(dev, rsv, correlator);
- break;
- case LOCAL_RING_NUMBER:
- svectors |= F_LOCAL_RING_NUMBER;
- rcode = smctr_set_local_ring_num(dev, rsv);
- break;
- case ASSIGN_PHYSICAL_DROP:
- svectors |= F_ASSIGN_PHYSICAL_DROP;
- rcode = smctr_set_phy_drop(dev, rsv);
- break;
- case ERROR_TIMER_VALUE:
- svectors |= F_ERROR_TIMER_VALUE;
- rcode = smctr_set_error_timer_value(dev, rsv);
- break;
- default:
- rcode = E_SUB_VECTOR_UNKNOWN;
- break;
- }
- /* Let Sender Know if SUM of SV length's is
- * larger then length in MVID length field
- */
- if((vlen -= rsv->svl) < 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
- }
- if(rcode == POSITIVE_ACK)
- {
- /* Let Sender Know if MVID length field
- * is larger then SUM of SV length's
- */
- if(vlen != 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- else
- {
- /* Let Sender Know if Expected SV Missing */
- if((svectors & R_INIT) ^ R_INIT)
- rcode = E_MISSING_SUB_VECTOR;
- }
- }
- return (rcode);
- }
- static int smctr_rcv_tx_forward(struct net_device *dev, MAC_HEADER *rmf)
- {
- MAC_SUB_VECTOR *rsv;
- signed short vlen;
- __u16 rcode = POSITIVE_ACK;
- unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
- /* This Frame can only come from a CRS */
- if((rmf->dc_sc & SC_MASK) != SC_CRS)
- return (E_INAPPROPRIATE_SOURCE_CLASS);
- /* Remove MVID Length from total length */
- vlen = (signed short)rmf->vl - 4;
- /* Point to First SVID */
- rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
- /* Search for Appropriate SVID's */
- while((vlen > 0) && (rcode == POSITIVE_ACK))
- {
- switch(rsv->svi)
- {
- case FRAME_FORWARD:
- svectors |= F_FRAME_FORWARD;
- rcode = smctr_set_frame_forward(dev, rsv,
- rmf->dc_sc);
- break;
- default:
- rcode = E_SUB_VECTOR_UNKNOWN;
- break;
- }
- /* Let Sender Know if SUM of SV length's is
- * larger then length in MVID length field
- */
- if((vlen -= rsv->svl) < 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
- }
- if(rcode == POSITIVE_ACK)
- {
- /* Let Sender Know if MVID length field
- * is larger then SUM of SV length's
- */
- if(vlen != 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- else
- {
- /* Let Sender Know if Expected SV Missing */
- if((svectors & R_TX_FORWARD) ^ R_TX_FORWARD)
- rcode = E_MISSING_SUB_VECTOR;
- }
- }
- return (rcode);
- }
- static int smctr_rcv_rq_addr_state_attch(struct net_device *dev,
- MAC_HEADER *rmf, __u16 *correlator)
- {
- MAC_SUB_VECTOR *rsv;
- signed short vlen;
- __u16 rcode = POSITIVE_ACK;
- unsigned int svectors = F_NO_SUB_VECTORS_FOUND;
- /* Remove MVID Length from total length */
- vlen = (signed short)rmf->vl - 4;
- /* Point to First SVID */
- rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
- /* Search for Appropriate SVID's */
- while((vlen > 0) && (rcode == POSITIVE_ACK))
- {
- switch(rsv->svi)
- {
- case CORRELATOR:
- svectors |= F_CORRELATOR;
- rcode = smctr_set_corr(dev, rsv, correlator);
- break;
- default:
- rcode = E_SUB_VECTOR_UNKNOWN;
- break;
- }
- /* Let Sender Know if SUM of SV length's is
- * larger then length in MVID length field
- */
- if((vlen -= rsv->svl) < 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
- }
- if(rcode == POSITIVE_ACK)
- {
- /* Let Sender Know if MVID length field
- * is larger then SUM of SV length's
- */
- if(vlen != 0)
- rcode = E_VECTOR_LENGTH_ERROR;
- else
- {
- /* Let Sender Know if Expected SVID Missing */
- if((svectors & R_RQ_ATTCH_STATE_ADDR)
- ^ R_RQ_ATTCH_STATE_ADDR)
- rcode = E_MISSING_SUB_VECTOR;
- }
- }
- return (rcode);
- }
- static int smctr_rcv_unknown(struct net_device *dev, MAC_HEADER *rmf,
- __u16 *correlator)
- {
- MAC_SUB_VECTOR *rsv;
- signed short vlen;
- *correlator = 0;
- /* Remove MVID Length from total length */
- vlen = (signed short)rmf->vl - 4;
- /* Point to First SVID */
- rsv = (MAC_SUB_VECTOR *)((__u32)rmf + sizeof(MAC_HEADER));
- /* Search for CORRELATOR for RSP to UNKNOWN */
- while((vlen > 0) && (*correlator == 0))
- {
- switch(rsv->svi)
- {
- case CORRELATOR:
- smctr_set_corr(dev, rsv, correlator);
- break;
- default:
- break;
- }
- vlen -= rsv->svl;
- rsv = (MAC_SUB_VECTOR *)((__u32)rsv + rsv->svl);
- }
- return (E_UNRECOGNIZED_VECTOR_ID);
- }
- /*
- * Reset the 825 NIC and exit w:
- * 1. The NIC reset cleared (non-reset state), halted and un-initialized.
- * 2. TINT masked.
- * 3. CBUSY masked.
- * 4. TINT clear.
- * 5. CBUSY clear.
- */
- static int smctr_reset_adapter(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- int ioaddr = dev->base_addr;
- /* Reseting the NIC will put it in a halted and un-initialized state. */ smctr_set_trc_reset(ioaddr);
- mdelay(200); /* ~2 ms */
- smctr_clear_trc_reset(ioaddr);
- mdelay(200); /* ~2 ms */
- /* Remove any latched interrupts that occurred prior to reseting the
- * adapter or possibily caused by line glitches due to the reset.
- */
- outb(tp->trc_mask | CSR_CLRTINT | CSR_CLRCBUSY, ioaddr + CSR);
- return (0);
- }
- static int smctr_restart_tx_chain(struct net_device *dev, short queue)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- int err = 0;
- if(smctr_debug > 10)
- printk("%s: smctr_restart_tx_chainn", dev->name);
- if(tp->num_tx_fcbs_used[queue] != 0
- && tp->tx_queue_status[queue] == NOT_TRANSMITING)
- {
- tp->tx_queue_status[queue] = TRANSMITING;
- err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
- }
- return (err);
- }
- static int smctr_ring_status_chg(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- if(smctr_debug > 10)
- printk("%s: smctr_ring_status_chgn", dev->name);
- /* Check for ring_status_flag: whenever MONITOR_STATE_BIT
- * Bit is set, check value of monitor_state, only then we
- * enable and start transmit/receive timeout (if and only
- * if it is MS_ACTIVE_MONITOR_STATE or MS_STANDBY_MONITOR_STATE)
- */
- if(tp->ring_status_flags == MONITOR_STATE_CHANGED)
- {
- if((tp->monitor_state == MS_ACTIVE_MONITOR_STATE)
- || (tp->monitor_state == MS_STANDBY_MONITOR_STATE))
- {
- tp->monitor_state_ready = 1;
- }
- else
- {
- /* if adapter is NOT in either active monitor
- * or standby monitor state => Disable
- * transmit/receive timeout.
- */
- tp->monitor_state_ready = 0;
- /* Ring speed problem, switching to auto mode. */
- if(tp->monitor_state == MS_MONITOR_FSM_INACTIVE
- && !tp->cleanup)
- {
- printk(KERN_INFO "%s: Incorrect ring speed switching.n",
- dev->name);
- smctr_set_ring_speed(dev);
- }
- }
- }
- if(!(tp->ring_status_flags & RING_STATUS_CHANGED))
- return (0);
- switch(tp->ring_status)
- {
- case RING_RECOVERY:
- printk(KERN_INFO "%s: Ring Recoveryn", dev->name);
- tp->current_ring_status |= RING_RECOVERY;
- break;
- case SINGLE_STATION:
- printk(KERN_INFO "%s: Single Statinonn", dev->name);
- tp->current_ring_status |= SINGLE_STATION;
- break;
- case COUNTER_OVERFLOW:
- printk(KERN_INFO "%s: Counter Overflown", dev->name);
- tp->current_ring_status |= COUNTER_OVERFLOW;
- break;
- case REMOVE_RECEIVED:
- printk(KERN_INFO "%s: Remove Receivedn", dev->name);
- tp->current_ring_status |= REMOVE_RECEIVED;
- break;
- case AUTO_REMOVAL_ERROR:
- printk(KERN_INFO "%s: Auto Remove Errorn", dev->name);
- tp->current_ring_status |= AUTO_REMOVAL_ERROR;
- break;
- case LOBE_WIRE_FAULT:
- printk(KERN_INFO "%s: Lobe Wire Faultn", dev->name);
- tp->current_ring_status |= LOBE_WIRE_FAULT;
- break;
- case TRANSMIT_BEACON:
- printk(KERN_INFO "%s: Transmit Beaconn", dev->name);
- tp->current_ring_status |= TRANSMIT_BEACON;
- break;
- case SOFT_ERROR:
- printk(KERN_INFO "%s: Soft Errorn", dev->name);
- tp->current_ring_status |= SOFT_ERROR;
- break;
- case HARD_ERROR:
- printk(KERN_INFO "%s: Hard Errorn", dev->name);
- tp->current_ring_status |= HARD_ERROR;
- break;
- case SIGNAL_LOSS:
- printk(KERN_INFO "%s: Singal Lossn", dev->name);
- tp->current_ring_status |= SIGNAL_LOSS;
- break;
- default:
- printk(KERN_INFO "%s: Unknown ring status changen",
- dev->name);
- break;
- }
- return (0);
- }
- static int smctr_rx_frame(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- __u16 queue, status, rx_size, err = 0;
- __u8 *pbuff;
- if(smctr_debug > 10)
- printk("%s: smctr_rx_framen", dev->name);
- cli();
- queue = tp->receive_queue_number;
- while((status = tp->rx_fcb_curr[queue]->frame_status) != SUCCESS)
- {
- err = HARDWARE_FAILED;
- if(((status & 0x007f) == 0)
- || ((tp->receive_mask & ACCEPT_ERR_PACKETS) != 0))
- {
- /* frame length less the CRC (4 bytes) + FS (1 byte) */
- rx_size = tp->rx_fcb_curr[queue]->frame_length - 5;
- pbuff = smctr_get_rx_pointer(dev, queue);
- smctr_set_page(dev, pbuff);
- smctr_disable_16bit(dev);
- /* pbuff points to addr within one page */
- pbuff = (__u8 *)PAGE_POINTER(pbuff);
- if(queue == NON_MAC_QUEUE)
- {
- struct sk_buff *skb;
- skb = dev_alloc_skb(rx_size);
- if (skb) {
- skb_put(skb, rx_size);
- memcpy(skb->data, pbuff, rx_size);
- sti();
- /* Update Counters */
- tp->MacStat.rx_packets++;
- tp->MacStat.rx_bytes += skb->len;
- /* Kick the packet on up. */
- skb->dev = dev;
- skb->protocol = tr_type_trans(skb, dev);
- netif_rx(skb);
- dev->last_rx = jiffies;
- } else {
- sti();
- }
- }
- else
- smctr_process_rx_packet((MAC_HEADER *)pbuff,
- rx_size, dev, status);
- }
- smctr_enable_16bit(dev);
- smctr_set_page(dev, (__u8 *)tp->ram_access);
- smctr_update_rx_chain(dev, queue);
- if(err != SUCCESS)
- break;
- }
- return (err);
- }
- static int smctr_send_dat(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int i, err;
- MAC_HEADER *tmf;
- FCBlock *fcb;
- if(smctr_debug > 10)
- printk("%s: smctr_send_datn", dev->name);
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE,
- sizeof(MAC_HEADER))) == (FCBlock *)(-1L))
- {
- return (OUT_OF_RESOURCES);
- }
- /* Initialize DAT Data Fields. */
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->ac = MSB(AC_FC_DAT);
- tmf->fc = LSB(AC_FC_DAT);
- for(i = 0; i < 6; i++)
- {
- tmf->sa[i] = dev->dev_addr[i];
- tmf->da[i] = dev->dev_addr[i];
- }
- tmf->vc = DAT;
- tmf->dc_sc = DC_RS | SC_RS;
- tmf->vl = 4;
- tmf->vl = SWAP_BYTES(tmf->vl);
- /* Start Transmit. */
- if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
- return (err);
- /* Wait for Transmit to Complete */
- for(i = 0; i < 10000; i++)
- {
- if(fcb->frame_status & FCB_COMMAND_DONE)
- break;
- mdelay(1);
- }
- /* Check if GOOD frame Tx'ed. */
- if(!(fcb->frame_status & FCB_COMMAND_DONE)
- || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
- {
- return (INITIALIZE_FAILED);
- }
- /* De-allocated Tx FCB and Frame Buffer
- * The FCB must be de-allocated manually if executing with
- * interrupts disabled, other wise the ISR (LM_Service_Events)
- * will de-allocate it when the interrupt occurs.
- */
- tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
- smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
- return (0);
- }
- static void smctr_timeout(struct net_device *dev)
- {
- /*
- * If we get here, some higher level has decided we are broken.
- * There should really be a "kick me" function call instead.
- *
- * Resetting the token ring adapter takes a long time so just
- * fake transmission time and go on trying. Our own timeout
- * routine is in sktr_timer_chk()
- */
- dev->trans_start = jiffies;
- netif_wake_queue(dev);
- }
- /*
- * Gets skb from system, queues it and checks if it can be sent
- */
- static int smctr_send_packet(struct sk_buff *skb, struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- if(smctr_debug > 10)
- printk("%s: smctr_send_packetn", dev->name);
- /*
- * Block a transmit overlap
- */
-
- netif_stop_queue(dev);
- if(tp->QueueSkb == 0)
- return (1); /* Return with tbusy set: queue full */
- tp->QueueSkb--;
- skb_queue_tail(&tp->SendSkbQueue, skb);
- smctr_hardware_send_packet(dev, tp);
- if(tp->QueueSkb > 0)
- netif_wake_queue(dev);
-
- return (0);
- }
- static int smctr_send_lobe_media_test(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- MAC_SUB_VECTOR *tsv;
- MAC_HEADER *tmf;
- FCBlock *fcb;
- __u32 i;
- int err;
- if(smctr_debug > 15)
- printk("%s: smctr_send_lobe_media_testn", dev->name);
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(struct trh_hdr)
- + S_WRAP_DATA + S_WRAP_DATA)) == (FCBlock *)(-1L))
- {
- return (OUT_OF_RESOURCES);
- }
- /* Initialize DAT Data Fields. */
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->ac = MSB(AC_FC_LOBE_MEDIA_TEST);
- tmf->fc = LSB(AC_FC_LOBE_MEDIA_TEST);
- for(i = 0; i < 6; i++)
- {
- tmf->da[i] = 0;
- tmf->sa[i] = dev->dev_addr[i];
- }
- tmf->vc = LOBE_MEDIA_TEST;
- tmf->dc_sc = DC_RS | SC_RS;
- tmf->vl = 4;
- tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
- smctr_make_wrap_data(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_wrap_data(dev, tsv);
- tmf->vl += tsv->svl;
- /* Start Transmit. */
- tmf->vl = SWAP_BYTES(tmf->vl);
- if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
- return (err);
- /* Wait for Transmit to Complete. (10 ms). */
- for(i=0; i < 10000; i++)
- {
- if(fcb->frame_status & FCB_COMMAND_DONE)
- break;
- mdelay(1);
- }
- /* Check if GOOD frame Tx'ed */
- if(!(fcb->frame_status & FCB_COMMAND_DONE)
- || fcb->frame_status & (FCB_TX_STATUS_E | FCB_TX_AC_BITS))
- {
- return (LOBE_MEDIA_TEST_FAILED);
- }
- /* De-allocated Tx FCB and Frame Buffer
- * The FCB must be de-allocated manually if executing with
- * interrupts disabled, other wise the ISR (LM_Service_Events)
- * will de-allocate it when the interrupt occurs.
- */
- tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
- smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
- return (0);
- }
- static int smctr_send_rpt_addr(struct net_device *dev, MAC_HEADER *rmf,
- __u16 correlator)
- {
- MAC_HEADER *tmf;
- MAC_SUB_VECTOR *tsv;
- FCBlock *fcb;
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
- + S_CORRELATOR + S_PHYSICAL_DROP + S_UPSTREAM_NEIGHBOR_ADDRESS
- + S_ADDRESS_MODIFER + S_GROUP_ADDRESS + S_FUNCTIONAL_ADDRESS))
- == (FCBlock *)(-1L))
- {
- return (0);
- }
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->vc = RPT_ADDR;
- tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
- tmf->vl = 4;
- smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ADDR);
- tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
- smctr_make_corr(dev, tsv, correlator);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_phy_drop_num(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_upstream_neighbor_addr(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_addr_mod(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_group_addr(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_funct_addr(dev, tsv);
- tmf->vl += tsv->svl;
- /* Subtract out MVID and MVL which is
- * include in both vl and MAC_HEADER
- */
- /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- */
- tmf->vl = SWAP_BYTES(tmf->vl);
- return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
- }
- static int smctr_send_rpt_attch(struct net_device *dev, MAC_HEADER *rmf,
- __u16 correlator)
- {
- MAC_HEADER *tmf;
- MAC_SUB_VECTOR *tsv;
- FCBlock *fcb;
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
- + S_CORRELATOR + S_PRODUCT_INSTANCE_ID + S_FUNCTIONAL_ADDRESS
- + S_AUTHORIZED_FUNCTION_CLASS + S_AUTHORIZED_ACCESS_PRIORITY))
- == (FCBlock *)(-1L))
- {
- return (0);
- }
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->vc = RPT_ATTCH;
- tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
- tmf->vl = 4;
- smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_ATTCH);
- tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
- smctr_make_corr(dev, tsv, correlator);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_product_id(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_funct_addr(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_auth_funct_class(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_access_pri(dev, tsv);
- tmf->vl += tsv->svl;
- /* Subtract out MVID and MVL which is
- * include in both vl and MAC_HEADER
- */
- /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- */
- tmf->vl = SWAP_BYTES(tmf->vl);
- return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
- }
- static int smctr_send_rpt_state(struct net_device *dev, MAC_HEADER *rmf,
- __u16 correlator)
- {
- MAC_HEADER *tmf;
- MAC_SUB_VECTOR *tsv;
- FCBlock *fcb;
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
- + S_CORRELATOR + S_RING_STATION_VERSION_NUMBER
- + S_RING_STATION_STATUS + S_STATION_IDENTIFER))
- == (FCBlock *)(-1L))
- {
- return (0);
- }
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->vc = RPT_STATE;
- tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
- tmf->vl = 4;
- smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_STATE);
- tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
- smctr_make_corr(dev, tsv, correlator);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_ring_station_version(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_ring_station_status(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_station_id(dev, tsv);
- tmf->vl += tsv->svl;
- /* Subtract out MVID and MVL which is
- * include in both vl and MAC_HEADER
- */
- /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- */
- tmf->vl = SWAP_BYTES(tmf->vl);
- return (smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
- }
- static int smctr_send_rpt_tx_forward(struct net_device *dev,
- MAC_HEADER *rmf, __u16 tx_fstatus)
- {
- MAC_HEADER *tmf;
- MAC_SUB_VECTOR *tsv;
- FCBlock *fcb;
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
- + S_TRANSMIT_STATUS_CODE)) == (FCBlock *)(-1L))
- {
- return (0);
- }
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->vc = RPT_TX_FORWARD;
- tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
- tmf->vl = 4;
- smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RPT_TX_FORWARD);
- tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
- smctr_make_tx_status_code(dev, tsv, tx_fstatus);
- tmf->vl += tsv->svl;
- /* Subtract out MVID and MVL which is
- * include in both vl and MAC_HEADER
- */
- /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- */
- tmf->vl = SWAP_BYTES(tmf->vl);
- return(smctr_trc_send_packet(dev, fcb, MAC_QUEUE));
- }
- static int smctr_send_rsp(struct net_device *dev, MAC_HEADER *rmf,
- __u16 rcode, __u16 correlator)
- {
- MAC_HEADER *tmf;
- MAC_SUB_VECTOR *tsv;
- FCBlock *fcb;
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
- + S_CORRELATOR + S_RESPONSE_CODE)) == (FCBlock *)(-1L))
- {
- return (0);
- }
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->vc = RSP;
- tmf->dc_sc = (rmf->dc_sc & SC_MASK) << 4;
- tmf->vl = 4;
- smctr_make_8025_hdr(dev, rmf, tmf, AC_FC_RSP);
- tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
- smctr_make_corr(dev, tsv, correlator);
- return (0);
- }
- static int smctr_send_rq_init(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- MAC_HEADER *tmf;
- MAC_SUB_VECTOR *tsv;
- FCBlock *fcb;
- unsigned int i, count = 0;
- __u16 fstatus;
- int err;
- do {
- if(((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, sizeof(MAC_HEADER)
- + S_PRODUCT_INSTANCE_ID + S_UPSTREAM_NEIGHBOR_ADDRESS
- + S_RING_STATION_VERSION_NUMBER + S_ADDRESS_MODIFER))
- == (FCBlock *)(-1L)))
- {
- return (0);
- }
- tmf = (MAC_HEADER *)fcb->bdb_ptr->data_block_ptr;
- tmf->vc = RQ_INIT;
- tmf->dc_sc = DC_RPS | SC_RS;
- tmf->vl = 4;
- smctr_make_8025_hdr(dev, 0L, tmf, AC_FC_RQ_INIT);
- tsv = (MAC_SUB_VECTOR *)((__u32)tmf + sizeof(MAC_HEADER));
- smctr_make_product_id(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_upstream_neighbor_addr(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_ring_station_version(dev, tsv);
- tmf->vl += tsv->svl;
- tsv = (MAC_SUB_VECTOR *)((__u32)tsv + tsv->svl);
- smctr_make_addr_mod(dev, tsv);
- tmf->vl += tsv->svl;
- /* Subtract out MVID and MVL which is
- * include in both vl and MAC_HEADER
- */
- /* fcb->frame_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- fcb->bdb_ptr->buffer_length = tmf->vl + sizeof(MAC_HEADER) - 4;
- */
- tmf->vl = SWAP_BYTES(tmf->vl);
- if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
- return (err);
- /* Wait for Transmit to Complete */
- for(i = 0; i < 10000; i++)
- {
- if(fcb->frame_status & FCB_COMMAND_DONE)
- break;
- mdelay(1);
- }
- /* Check if GOOD frame Tx'ed */
- fstatus = fcb->frame_status;
- if(!(fstatus & FCB_COMMAND_DONE))
- return (HARDWARE_FAILED);
- if(!(fstatus & FCB_TX_STATUS_E))
- count++;
- /* De-allocated Tx FCB and Frame Buffer
- * The FCB must be de-allocated manually if executing with
- * interrupts disabled, other wise the ISR (LM_Service_Events)
- * will de-allocate it when the interrupt occurs.
- */
- tp->tx_queue_status[MAC_QUEUE] = NOT_TRANSMITING;
- smctr_update_tx_chain(dev, fcb, MAC_QUEUE);
- } while(count < 4 && ((fstatus & FCB_TX_AC_BITS) ^ FCB_TX_AC_BITS));
- return (smctr_join_complete_state(dev));
- }
- static int smctr_send_tx_forward(struct net_device *dev, MAC_HEADER *rmf,
- __u16 *tx_fstatus)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- FCBlock *fcb;
- unsigned int i;
- int err;
- /* Check if this is the END POINT of the Transmit Forward Chain. */
- if(rmf->vl <= 18)
- return (0);
- /* Allocate Transmit FCB only by requesting 0 bytes
- * of data buffer.
- */
- if((fcb = smctr_get_tx_fcb(dev, MAC_QUEUE, 0)) == (FCBlock *)(-1L))
- return (0);
- /* Set pointer to Transmit Frame Buffer to the data
- * portion of the received TX Forward frame, making
- * sure to skip over the Vector Code (vc) and Vector
- * length (vl).
- */
- fcb->bdb_ptr->trc_data_block_ptr = TRC_POINTER((__u32)rmf
- + sizeof(MAC_HEADER) + 2);
- fcb->bdb_ptr->data_block_ptr = (__u16 *)((__u32)rmf
- + sizeof(MAC_HEADER) + 2);
- fcb->frame_length = rmf->vl - 4 - 2;
- fcb->bdb_ptr->buffer_length = rmf->vl - 4 - 2;
- if((err = smctr_trc_send_packet(dev, fcb, MAC_QUEUE)))
- return (err);
- /* Wait for Transmit to Complete */
- for(i = 0; i < 10000; i++)
- {
- if(fcb->frame_status & FCB_COMMAND_DONE)
- break;
- mdelay(1);
- }
- /* Check if GOOD frame Tx'ed */
- if(!(fcb->frame_status & FCB_COMMAND_DONE))
- {
- if((err = smctr_issue_resume_tx_fcb_cmd(dev, MAC_QUEUE)))
- return (err);
- for(i = 0; i < 10000; i++)
- {
- if(fcb->frame_status & FCB_COMMAND_DONE)
- break;
- mdelay(1);
- }
- if(!(fcb->frame_status & FCB_COMMAND_DONE))
- return (HARDWARE_FAILED);
- }
- *tx_fstatus = fcb->frame_status;
- return (A_FRAME_WAS_FORWARDED);
- }
- static int smctr_set_auth_access_pri(struct net_device *dev,
- MAC_SUB_VECTOR *rsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- if(rsv->svl != S_AUTHORIZED_ACCESS_PRIORITY)
- return (E_SUB_VECTOR_LENGTH_ERROR);
- tp->authorized_access_priority = (rsv->svv[0] << 8 | rsv->svv[1]);
- return (POSITIVE_ACK);
- }
- static int smctr_set_auth_funct_class(struct net_device *dev,
- MAC_SUB_VECTOR *rsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- if(rsv->svl != S_AUTHORIZED_FUNCTION_CLASS)
- return (E_SUB_VECTOR_LENGTH_ERROR);
- tp->authorized_function_classes = (rsv->svv[0] << 8 | rsv->svv[1]);
- return (POSITIVE_ACK);
- }
- static int smctr_set_corr(struct net_device *dev, MAC_SUB_VECTOR *rsv,
- __u16 *correlator)
- {
- if(rsv->svl != S_CORRELATOR)
- return (E_SUB_VECTOR_LENGTH_ERROR);
- *correlator = (rsv->svv[0] << 8 | rsv->svv[1]);
- return (POSITIVE_ACK);
- }
- static int smctr_set_error_timer_value(struct net_device *dev,
- MAC_SUB_VECTOR *rsv)
- {
- __u16 err_tval;
- int err;
- if(rsv->svl != S_ERROR_TIMER_VALUE)
- return (E_SUB_VECTOR_LENGTH_ERROR);
- err_tval = (rsv->svv[0] << 8 | rsv->svv[1])*10;
- smctr_issue_write_word_cmd(dev, RW_TER_THRESHOLD, &err_tval);
- if((err = smctr_wait_cmd(dev)))
- return (err);
- return (POSITIVE_ACK);
- }
- static int smctr_set_frame_forward(struct net_device *dev,
- MAC_SUB_VECTOR *rsv, __u8 dc_sc)
- {
- if((rsv->svl < 2) || (rsv->svl > S_FRAME_FORWARD))
- return (E_SUB_VECTOR_LENGTH_ERROR);
- if((dc_sc & DC_MASK) != DC_CRS)
- {
- if(rsv->svl >= 2 && rsv->svl < 20)
- return (E_TRANSMIT_FORWARD_INVALID);
- if((rsv->svv[0] != 0) || (rsv->svv[1] != 0))
- return (E_TRANSMIT_FORWARD_INVALID);
- }
- return (POSITIVE_ACK);
- }
- static int smctr_set_local_ring_num(struct net_device *dev,
- MAC_SUB_VECTOR *rsv)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- if(rsv->svl != S_LOCAL_RING_NUMBER)
- return (E_SUB_VECTOR_LENGTH_ERROR);
- if(tp->ptr_local_ring_num)
- *(__u16 *)(tp->ptr_local_ring_num)
- = (rsv->svv[0] << 8 | rsv->svv[1]);
- return (POSITIVE_ACK);
- }
- static unsigned short smctr_set_ctrl_attention(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- int ioaddr = dev->base_addr;
- if(tp->bic_type == BIC_585_CHIP)
- outb((tp->trc_mask | HWR_CA), ioaddr + HWR);
- else
- {
- outb((tp->trc_mask | CSR_CA), ioaddr + CSR);
- outb(tp->trc_mask, ioaddr + CSR);
- }
- return (0);
- }
- static void smctr_set_multicast_list(struct net_device *dev)
- {
- if(smctr_debug > 10)
- printk("%s: smctr_set_multicast_listn", dev->name);
- return;
- }
- static int smctr_set_page(struct net_device *dev, __u8 *buf)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- __u8 amask;
- __u32 tptr;
- tptr = (__u32)buf - (__u32)tp->ram_access;
- amask = (__u8)((tptr & PR_PAGE_MASK) >> 8);
- outb(amask, dev->base_addr + PR);
- return (0);
- }
- static int smctr_set_phy_drop(struct net_device *dev, MAC_SUB_VECTOR *rsv)
- {
- int err;
- if(rsv->svl != S_PHYSICAL_DROP)
- return (E_SUB_VECTOR_LENGTH_ERROR);
- smctr_issue_write_byte_cmd(dev, RW_PHYSICAL_DROP_NUMBER, &rsv->svv[0]);
- if((err = smctr_wait_cmd(dev)))
- return (err);
- return (POSITIVE_ACK);
- }
- /* Reset the ring speed to the opposite of what it was. This auto-pilot
- * mode requires a complete reset and re-init of the adapter.
- */
- static int smctr_set_ring_speed(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- int err;
- if(tp->media_type == MEDIA_UTP_16)
- tp->media_type = MEDIA_UTP_4;
- else
- tp->media_type = MEDIA_UTP_16;
- smctr_enable_16bit(dev);
- /* Re-Initialize adapter's internal registers */
- smctr_reset_adapter(dev);
- if((err = smctr_init_card_real(dev)))
- return (err);
- smctr_enable_bic_int(dev);
- if((err = smctr_issue_enable_int_cmd(dev, TRC_INTERRUPT_ENABLE_MASK)))
- return (err);
- smctr_disable_16bit(dev);
- return (0);
- }
- static int smctr_set_rx_look_ahead(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- __u16 sword, rword;
- if(smctr_debug > 10)
- printk("%s: smctr_set_rx_look_ahead_flagn", dev->name);
- tp->adapter_flags &= ~(FORCED_16BIT_MODE);
- tp->adapter_flags |= RX_VALID_LOOKAHEAD;
- if(tp->adapter_bus == BUS_ISA16_TYPE)
- {
- sword = *((__u16 *)(tp->ram_access));
- *((__u16 *)(tp->ram_access)) = 0x1234;
- smctr_disable_16bit(dev);
- rword = *((__u16 *)(tp->ram_access));
- smctr_enable_16bit(dev);
- if(rword != 0x1234)
- tp->adapter_flags |= FORCED_16BIT_MODE;
- *((__u16 *)(tp->ram_access)) = sword;
- }
- return (0);
- }
- static int smctr_set_trc_reset(int ioaddr)
- {
- __u8 r;
- r = inb(ioaddr + MSR);
- outb(MSR_RST | r, ioaddr + MSR);
- return (0);
- }
- /*
- * This function can be called if the adapter is busy or not.
- */
- static int smctr_setup_single_cmd(struct net_device *dev,
- __u16 command, __u16 subcommand)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int err;
- if(smctr_debug > 10)
- printk("%s: smctr_setup_single_cmdn", dev->name);
- if((err = smctr_wait_while_cbusy(dev)))
- return (err);
- if((err = (unsigned int)smctr_wait_cmd(dev)))
- return (err);
- tp->acb_head->cmd_done_status = 0;
- tp->acb_head->cmd = command;
- tp->acb_head->subcmd = subcommand;
- err = smctr_issue_resume_acb_cmd(dev);
- return (err);
- }
- /*
- * This function can not be called with the adapter busy.
- */
- static int smctr_setup_single_cmd_w_data(struct net_device *dev,
- __u16 command, __u16 subcommand)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- tp->acb_head->cmd_done_status = ACB_COMMAND_NOT_DONE;
- tp->acb_head->cmd = command;
- tp->acb_head->subcmd = subcommand;
- tp->acb_head->data_offset_lo
- = (__u16)TRC_POINTER(tp->misc_command_data);
- return(smctr_issue_resume_acb_cmd(dev));
- }
- static char *smctr_malloc(struct net_device *dev, __u16 size)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- char *m;
- m = (char *)(tp->ram_access + tp->sh_mem_used);
- tp->sh_mem_used += (__u32)size;
- return (m);
- }
- static int smctr_status_chg(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- if(smctr_debug > 10)
- printk("%s: smctr_status_chgn", dev->name);
- switch(tp->status)
- {
- case OPEN:
- break;
- case CLOSED:
- break;
- /* Interrupt driven open() completion. XXX */
- case INITIALIZED:
- tp->group_address_0 = 0;
- tp->group_address[0] = 0;
- tp->group_address[1] = 0;
- tp->functional_address_0 = 0;
- tp->functional_address[0] = 0;
- tp->functional_address[1] = 0;
- smctr_open_tr(dev);
- break;
- default:
- printk(KERN_INFO "%s: status change unknown %xn",
- dev->name, tp->status);
- break;
- }
- return (0);
- }
- static int smctr_trc_send_packet(struct net_device *dev, FCBlock *fcb,
- __u16 queue)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- int err = 0;
- if(smctr_debug > 10)
- printk("%s: smctr_trc_send_packetn", dev->name);
- fcb->info = FCB_CHAIN_END | FCB_ENABLE_TFS;
- if(tp->num_tx_fcbs[queue] != 1)
- fcb->back_ptr->info = FCB_INTERRUPT_ENABLE | FCB_ENABLE_TFS;
- if(tp->tx_queue_status[queue] == NOT_TRANSMITING)
- {
- tp->tx_queue_status[queue] = TRANSMITING;
- err = smctr_issue_resume_tx_fcb_cmd(dev, queue);
- }
- return (err);
- }
- static __u16 smctr_tx_complete(struct net_device *dev, __u16 queue)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- __u16 status, err = 0;
- int cstatus;
- if(smctr_debug > 10)
- printk("%s: smctr_tx_completen", dev->name);
- while((status = tp->tx_fcb_end[queue]->frame_status) != SUCCESS)
- {
- if(status & 0x7e00 )
- {
- err = HARDWARE_FAILED;
- break;
- }
- if((err = smctr_update_tx_chain(dev, tp->tx_fcb_end[queue],
- queue)) != SUCCESS)
- break;
- smctr_disable_16bit(dev);
- if(tp->mode_bits & UMAC)
- {
- if(!(status & (FCB_TX_STATUS_AR1 | FCB_TX_STATUS_AR2)))
- cstatus = NO_SUCH_DESTINATION;
- else
- {
- if(!(status & (FCB_TX_STATUS_CR1 | FCB_TX_STATUS_CR2)))
- cstatus = DEST_OUT_OF_RESOURCES;
- else
- {
- if(status & FCB_TX_STATUS_E)
- cstatus = MAX_COLLISIONS;
- else
- cstatus = SUCCESS;
- }
- }
- }
- else
- cstatus = SUCCESS;
- if(queue == BUG_QUEUE)
- err = SUCCESS;
- smctr_enable_16bit(dev);
- if(err != SUCCESS)
- break;
- }
- return (err);
- }
- static unsigned short smctr_tx_move_frame(struct net_device *dev,
- struct sk_buff *skb, __u8 *pbuff, unsigned int bytes)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int ram_usable;
- __u32 flen, len, offset = 0;
- __u8 *frag, *page;
- if(smctr_debug > 10)
- printk("%s: smctr_tx_move_framen", dev->name);
- ram_usable = ((unsigned int)tp->ram_usable) << 10;
- frag = skb->data;
- flen = skb->len;
- while(flen > 0 && bytes > 0)
- {
- smctr_set_page(dev, pbuff);
- offset = SMC_PAGE_OFFSET(pbuff);
- if(offset + flen > ram_usable)
- len = ram_usable - offset;
- else
- len = flen;
- if(len > bytes)
- len = bytes;
- page = (char *) (offset + tp->ram_access);
- memcpy(page, frag, len);
- flen -=len;
- bytes -= len;
- frag += len;
- pbuff += len;
- }
- return (0);
- }
- /* Update the error statistic counters for this adapter. */
- static int smctr_update_err_stats(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- struct tr_statistics *tstat = &tp->MacStat;
- if(tstat->internal_errors)
- tstat->internal_errors
- += *(tp->misc_command_data + 0) & 0x00ff;
- if(tstat->line_errors)
- tstat->line_errors += *(tp->misc_command_data + 0) >> 8;
- if(tstat->A_C_errors)
- tstat->A_C_errors += *(tp->misc_command_data + 1) & 0x00ff;
- if(tstat->burst_errors)
- tstat->burst_errors += *(tp->misc_command_data + 1) >> 8;
- if(tstat->abort_delimiters)
- tstat->abort_delimiters += *(tp->misc_command_data + 2) >> 8;
- if(tstat->recv_congest_count)
- tstat->recv_congest_count
- += *(tp->misc_command_data + 3) & 0x00ff;
- if(tstat->lost_frames)
- tstat->lost_frames
- += *(tp->misc_command_data + 3) >> 8;
- if(tstat->frequency_errors)
- tstat->frequency_errors += *(tp->misc_command_data + 4) & 0x00ff;
- if(tstat->frame_copied_errors)
- tstat->frame_copied_errors
- += *(tp->misc_command_data + 4) >> 8;
- if(tstat->token_errors)
- tstat->token_errors += *(tp->misc_command_data + 5) >> 8;
- return (0);
- }
- static int smctr_update_rx_chain(struct net_device *dev, __u16 queue)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- FCBlock *fcb;
- BDBlock *bdb;
- __u16 size, len;
- fcb = tp->rx_fcb_curr[queue];
- len = fcb->frame_length;
- fcb->frame_status = 0;
- fcb->info = FCB_CHAIN_END;
- fcb->back_ptr->info = FCB_WARNING;
- tp->rx_fcb_curr[queue] = tp->rx_fcb_curr[queue]->next_ptr;
- /* update RX BDBs */
- size = (len >> RX_BDB_SIZE_SHIFT);
- if(len & RX_DATA_BUFFER_SIZE_MASK)
- size += sizeof(BDBlock);
- size &= (~RX_BDB_SIZE_MASK);
- /* check if wrap around */
- bdb = (BDBlock *)((__u32)(tp->rx_bdb_curr[queue]) + (__u32)(size));
- if((__u32)bdb >= (__u32)tp->rx_bdb_end[queue])
- {
- bdb = (BDBlock *)((__u32)(tp->rx_bdb_head[queue])
- + (__u32)(bdb) - (__u32)(tp->rx_bdb_end[queue]));
- }
- bdb->back_ptr->info = BDB_CHAIN_END;
- tp->rx_bdb_curr[queue]->back_ptr->info = BDB_NOT_CHAIN_END;
- tp->rx_bdb_curr[queue] = bdb;
- return (0);
- }
- static int smctr_update_tx_chain(struct net_device *dev, FCBlock *fcb,
- __u16 queue)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- if(smctr_debug > 20)
- printk("smctr_update_tx_chainn");
- if(tp->num_tx_fcbs_used[queue] <= 0)
- return (HARDWARE_FAILED);
- else
- {
- if(tp->tx_buff_used[queue] < fcb->memory_alloc)
- {
- tp->tx_buff_used[queue] = 0;
- return (HARDWARE_FAILED);
- }
- tp->tx_buff_used[queue] -= fcb->memory_alloc;
- /* if all transmit buffer are cleared
- * need to set the tx_buff_curr[] to tx_buff_head[]
- * otherwise, tx buffer will be segregate and cannot
- * accomodate and buffer greater than (curr - head) and
- * (end - curr) since we do not allow wrap around allocation.
- */
- if(tp->tx_buff_used[queue] == 0)
- tp->tx_buff_curr[queue] = tp->tx_buff_head[queue];
- tp->num_tx_fcbs_used[queue]--;
- fcb->frame_status = 0;
- tp->tx_fcb_end[queue] = fcb->next_ptr;
- netif_wake_queue(dev);
- return (0);
- }
- }
- static int smctr_wait_cmd(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int loop_count = 0x20000;
- if(smctr_debug > 10)
- printk("%s: smctr_wait_cmdn", dev->name);
- while(loop_count)
- {
- if(tp->acb_head->cmd_done_status & ACB_COMMAND_DONE)
- break;
- udelay(1);
- loop_count--;
- }
- if(loop_count == 0)
- return(HARDWARE_FAILED);
- if(tp->acb_head->cmd_done_status & 0xff)
- return(HARDWARE_FAILED);
- return (0);
- }
- static int smctr_wait_while_cbusy(struct net_device *dev)
- {
- struct net_local *tp = (struct net_local *)dev->priv;
- unsigned int timeout = 0x20000;
- int ioaddr = dev->base_addr;
- __u8 r;
- if(tp->bic_type == BIC_585_CHIP)
- {
- while(timeout)
- {
- r = inb(ioaddr + HWR);
- if((r & HWR_CBUSY) == 0)
- break;
- timeout--;
- }
- }
- else
- {
- while(timeout)
- {
- r = inb(ioaddr + CSR);
- if((r & CSR_CBUSY) == 0)
- break;
- timeout--;
- }
- }
- if(timeout)
- return (0);
- else
- return (HARDWARE_FAILED);
- }
- #ifdef MODULE
- static struct net_device* dev_smctr[SMCTR_MAX_ADAPTERS];
- static int io[SMCTR_MAX_ADAPTERS];
- static int irq[SMCTR_MAX_ADAPTERS];
- static int mem[SMCTR_MAX_ADAPTERS];
- MODULE_LICENSE("GPL");
- MODULE_PARM(io, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
- MODULE_PARM(irq, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
- MODULE_PARM(mem, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
- MODULE_PARM(ringspeed, "1-" __MODULE_STRING(SMCTR_MAX_ADAPTERS) "i");
- int init_module(void)
- {
- int i;
- for(i = 0; i < SMCTR_MAX_ADAPTERS; i++)
- {
- irq[i] = 0;
- mem[i] = 0;
- dev_smctr[i] = NULL;
- dev_smctr[i] = init_trdev(dev_smctr[i], 0);
- if(dev_smctr[i] == NULL)
- return (-ENOMEM);
- dev_smctr[i]->base_addr = io[i];
- dev_smctr[i]->irq = irq[i];
- dev_smctr[i]->mem_start = mem[i];
- dev_smctr[i]->init = &smctr_probe;
- if(register_trdev(dev_smctr[i]) != 0)
- {
- kfree(dev_smctr[i]);
- dev_smctr[i] = NULL;
- if(i == 0)
- {
- printk("%s: register_trdev() returned (<0).n",
- cardname);
- return (-EIO);
- }
- else
- return (0);
- }
- }
- return (0);
- }
- void cleanup_module(void)
- {
- int i;
- for(i = 0; i < SMCTR_MAX_ADAPTERS; i++)
- {
- if(dev_smctr[i])
- {
- #ifdef CONFIG_MCA
- struct net_local *tp
- = (struct net_local *)dev_smctr[i]->priv;
- if(tp->slot_num)
- mca_mark_as_unused(tp->slot_num);
- #endif
- unregister_trdev(dev_smctr[i]);
- release_region(dev_smctr[i]->base_addr,
- SMCTR_IO_EXTENT);
- if(dev_smctr[i]->irq)
- free_irq(dev_smctr[i]->irq, dev_smctr[i]);
- if(dev_smctr[i]->priv)
- kfree(dev_smctr[i]->priv);
- kfree(dev_smctr[i]);
- dev_smctr[i] = NULL;
- }
- }
- }
- #endif /* MODULE */