📄 3c523.c
字号:
break; } /* we didn't find any 3c523 in the slots we checked for */ if (slot == MCA_NOTFOUND) { retval = ((base_addr || irq) ? -ENXIO : -ENODEV); goto err_out; } mca_set_adapter_name(slot, "3Com 3c523 Etherlink/MC"); mca_set_adapter_procfn(slot, (MCA_ProcFn) elmc_getinfo, dev); /* if we get this far, adapter has been found - carry on */ printk(KERN_INFO "%s: 3c523 adapter found in slot %d\n", dev->name, slot + 1); /* Now we extract configuration info from the card. The 3c523 provides information in two of the POS registers, but the second one is only needed if we want to tell the card what IRQ to use. I suspect that whoever sets the thing up initially would prefer we don't screw with those things. Note that we read the status info when we found the card... See 3c523.h for more details. */ /* revision is stored in the first 4 bits of the revision register */ revision = inb(dev->base_addr + ELMC_REVISION) & 0xf; /* according to docs, we read the interrupt and write it back to the IRQ select register, since the POST might not configure the IRQ properly. */ switch (dev->irq) { case 3: mca_write_pos(slot, 3, 0x04); break; case 7: mca_write_pos(slot, 3, 0x02); break; case 9: mca_write_pos(slot, 3, 0x08); break; case 12: mca_write_pos(slot, 3, 0x01); break; } pr = dev->priv = kmalloc(sizeof(struct priv), GFP_KERNEL); if (dev->priv == NULL) { retval = -ENOMEM; goto err_out; } memset(pr, 0, sizeof(struct priv)); pr->slot = slot; printk(KERN_INFO "%s: 3Com 3c523 Rev 0x%x at %#lx\n", dev->name, (int) revision, dev->base_addr); /* Determine if we're using the on-board transceiver (i.e. coax) or an external one. The information is pretty much useless, but I guess it's worth brownie points. */ dev->if_port = (status & ELMC_STATUS_DISABLE_THIN); /* The 3c523 has a 24K chunk of memory. The first 16K is the shared memory, while the last 8K is for the EtherStart BIOS ROM. Which we don't care much about here. We'll just tell Linux that we're using 16K. MCA won't permit address space conflicts caused by not mapping the other 8K. */ dev->mem_start = shm_table[(status & ELMC_STATUS_MEMORY_SELECT) >> 3]; /* We're using MCA, so it's a given that the information about memory size is correct. The Crynwr drivers do something like this. */ elmc_id_reset586(); /* seems like a good idea before checking it... */ size = 0x4000; /* check for 16K mem */ if (!check586(dev, dev->mem_start, size)) { printk(KERN_ERR "%s: memprobe, Can't find memory at 0x%lx!\n", dev->name, dev->mem_start); kfree(dev->priv); dev->priv = NULL; retval = -ENODEV; goto err_out; } dev->mem_end = dev->mem_start + size; /* set mem_end showed by 'ifconfig' */ pr->memtop = bus_to_virt(dev->mem_start) + size; pr->base = (unsigned long) bus_to_virt(dev->mem_start) + size - 0x01000000; alloc586(dev); elmc_id_reset586(); /* make sure it doesn't generate spurious ints */ /* set number of receive-buffs according to memsize */ pr->num_recv_buffs = NUM_RECV_BUFFS_16; /* dump all the assorted information */ printk(KERN_INFO "%s: IRQ %d, %sternal xcvr, memory %#lx-%#lx.\n", dev->name, dev->irq, dev->if_port ? "ex" : "in", dev->mem_start, dev->mem_end - 1); /* The hardware address for the 3c523 is stored in the first six bytes of the IO address. */ printk(KERN_INFO "%s: hardware address ", dev->name); for (i = 0; i < 6; i++) { dev->dev_addr[i] = inb(dev->base_addr + i); printk(" %02x", dev->dev_addr[i]); } printk("\n"); dev->open = &elmc_open; dev->stop = &elmc_close; dev->get_stats = &elmc_get_stats; dev->hard_start_xmit = &elmc_send_packet; dev->tx_timeout = &elmc_timeout; dev->watchdog_timeo = HZ;#ifdef ELMC_MULTICAST dev->set_multicast_list = &set_multicast_list;#else dev->set_multicast_list = NULL;#endif dev->do_ioctl = netdev_ioctl; ether_setup(dev); /* note that we haven't actually requested the IRQ from the kernel. That gets done in elmc_open(). I'm not sure that's such a good idea, but it works, so I'll go with it. */#ifndef ELMC_MULTICAST dev->flags&=~IFF_MULTICAST; /* Multicast doesn't work */#endif return 0;err_out: release_region(dev->base_addr, ELMC_IO_EXTENT); return retval;}/********************************************** * init the chip (elmc-interrupt should be disabled?!) * needs a correct 'allocated' memory */static int init586(struct net_device *dev){ void *ptr; unsigned long s; int i, result = 0; struct priv *p = (struct priv *) dev->priv; volatile struct configure_cmd_struct *cfg_cmd; volatile struct iasetup_cmd_struct *ias_cmd; volatile struct tdr_cmd_struct *tdr_cmd; volatile struct mcsetup_cmd_struct *mc_cmd; struct dev_mc_list *dmi = dev->mc_list; int num_addrs = dev->mc_count; ptr = (void *) ((char *) p->scb + sizeof(struct scb_struct)); cfg_cmd = (struct configure_cmd_struct *) ptr; /* configure-command */ cfg_cmd->cmd_status = 0; cfg_cmd->cmd_cmd = CMD_CONFIGURE | CMD_LAST; cfg_cmd->cmd_link = 0xffff; cfg_cmd->byte_cnt = 0x0a; /* number of cfg bytes */ cfg_cmd->fifo = 0x08; /* fifo-limit (8=tx:32/rx:64) */ cfg_cmd->sav_bf = 0x40; /* hold or discard bad recv frames (bit 7) */ cfg_cmd->adr_len = 0x2e; /* addr_len |!src_insert |pre-len |loopback */ cfg_cmd->priority = 0x00; cfg_cmd->ifs = 0x60; cfg_cmd->time_low = 0x00; cfg_cmd->time_high = 0xf2; cfg_cmd->promisc = 0; if (dev->flags & (IFF_ALLMULTI | IFF_PROMISC)) { cfg_cmd->promisc = 1; dev->flags |= IFF_PROMISC; } cfg_cmd->carr_coll = 0x00; p->scb->cbl_offset = make16(cfg_cmd); p->scb->cmd = CUC_START; /* cmd.-unit start */ elmc_id_attn586(); s = jiffies; /* warning: only active with interrupts on !! */ while (!(cfg_cmd->cmd_status & STAT_COMPL)) { if (jiffies - s > 30*HZ/100) break; } if ((cfg_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_COMPL | STAT_OK)) { printk(KERN_WARNING "%s (elmc): configure command failed: %x\n", dev->name, cfg_cmd->cmd_status); return 1; } /* * individual address setup */ ias_cmd = (struct iasetup_cmd_struct *) ptr; ias_cmd->cmd_status = 0; ias_cmd->cmd_cmd = CMD_IASETUP | CMD_LAST; ias_cmd->cmd_link = 0xffff; memcpy((char *) &ias_cmd->iaddr, (char *) dev->dev_addr, ETH_ALEN); p->scb->cbl_offset = make16(ias_cmd); p->scb->cmd = CUC_START; /* cmd.-unit start */ elmc_id_attn586(); s = jiffies; while (!(ias_cmd->cmd_status & STAT_COMPL)) { if (jiffies - s > 30*HZ/100) break; } if ((ias_cmd->cmd_status & (STAT_OK | STAT_COMPL)) != (STAT_OK | STAT_COMPL)) { printk(KERN_WARNING "%s (elmc): individual address setup command failed: %04x\n", dev->name, ias_cmd->cmd_status); return 1; } /* * TDR, wire check .. e.g. no resistor e.t.c */ tdr_cmd = (struct tdr_cmd_struct *) ptr; tdr_cmd->cmd_status = 0; tdr_cmd->cmd_cmd = CMD_TDR | CMD_LAST; tdr_cmd->cmd_link = 0xffff; tdr_cmd->status = 0; p->scb->cbl_offset = make16(tdr_cmd); p->scb->cmd = CUC_START; /* cmd.-unit start */ elmc_attn586(); s = jiffies; while (!(tdr_cmd->cmd_status & STAT_COMPL)) { if (jiffies - s > 30*HZ/100) { printk(KERN_WARNING "%s: %d Problems while running the TDR.\n", dev->name, __LINE__); result = 1; break; } } if (!result) { DELAY(2); /* wait for result */ result = tdr_cmd->status; p->scb->cmd = p->scb->status & STAT_MASK; elmc_id_attn586(); /* ack the interrupts */ if (result & TDR_LNK_OK) { /* empty */ } else if (result & TDR_XCVR_PRB) { printk(KERN_WARNING "%s: TDR: Transceiver problem!\n", dev->name); } else if (result & TDR_ET_OPN) { printk(KERN_WARNING "%s: TDR: No correct termination %d clocks away.\n", dev->name, result & TDR_TIMEMASK); } else if (result & TDR_ET_SRT) { if (result & TDR_TIMEMASK) /* time == 0 -> strange :-) */ printk(KERN_WARNING "%s: TDR: Detected a short circuit %d clocks away.\n", dev->name, result & TDR_TIMEMASK); } else { printk(KERN_WARNING "%s: TDR: Unknown status %04x\n", dev->name, result); } } /* * ack interrupts */ p->scb->cmd = p->scb->status & STAT_MASK; elmc_id_attn586(); /* * alloc nop/xmit-cmds */#if (NUM_XMIT_BUFFS == 1) for (i = 0; i < 2; i++) { p->nop_cmds[i] = (struct nop_cmd_struct *) ptr; p->nop_cmds[i]->cmd_cmd = CMD_NOP; p->nop_cmds[i]->cmd_status = 0; p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); ptr = (char *) ptr + sizeof(struct nop_cmd_struct); } p->xmit_cmds[0] = (struct transmit_cmd_struct *) ptr; /* transmit cmd/buff 0 */ ptr = (char *) ptr + sizeof(struct transmit_cmd_struct);#else for (i = 0; i < NUM_XMIT_BUFFS; i++) { p->nop_cmds[i] = (struct nop_cmd_struct *) ptr; p->nop_cmds[i]->cmd_cmd = CMD_NOP; p->nop_cmds[i]->cmd_status = 0; p->nop_cmds[i]->cmd_link = make16((p->nop_cmds[i])); ptr = (char *) ptr + sizeof(struct nop_cmd_struct); p->xmit_cmds[i] = (struct transmit_cmd_struct *) ptr; /*transmit cmd/buff 0 */ ptr = (char *) ptr + sizeof(struct transmit_cmd_struct); }#endif ptr = alloc_rfa(dev, (void *) ptr); /* init receive-frame-area */ /* * Multicast setup */ if (dev->mc_count) { /* I don't understand this: do we really need memory after the init? */ int len = ((char *) p->iscp - (char *) ptr - 8) / 6; if (len <= 0) { printk(KERN_ERR "%s: Ooooops, no memory for MC-Setup!\n", dev->name); } else { if (len < num_addrs) { num_addrs = len; printk(KERN_WARNING "%s: Sorry, can only apply %d MC-Address(es).\n", dev->name, num_addrs); } mc_cmd = (struct mcsetup_cmd_struct *) ptr; mc_cmd->cmd_status = 0; mc_cmd->cmd_cmd = CMD_MCSETUP | CMD_LAST; mc_cmd->cmd_link = 0xffff; mc_cmd->mc_cnt = num_addrs * 6; for (i = 0; i < num_addrs; i++) { memcpy((char *) mc_cmd->mc_list[i], dmi->dmi_addr, 6); dmi = dmi->next; } p->scb->cbl_offset = make16(mc_cmd); p->scb->cmd = CUC_START; elmc_id_attn586(); s = jiffies; while (!(mc_cmd->cmd_status & STAT_COMPL)) { if (jiffies - s > 30*HZ/100) break; } if (!(mc_cmd->cmd_status & STAT_COMPL)) { printk(KERN_WARNING "%s: Can't apply multicast-address-list.\n", dev->name); } } } /* * alloc xmit-buffs / init xmit_cmds */ for (i = 0; i < NUM_XMIT_BUFFS; i++) { p->xmit_cbuffs[i] = (char *) ptr; /* char-buffs */ ptr = (char *) ptr + XMIT_BUFF_SIZE; p->xmit_buffs[i] = (struct tbd_struct *) ptr; /* TBD */ ptr = (char *) ptr + sizeof(struct tbd_struct); if ((void *) ptr > (void *) p->iscp) { printk(KERN_ERR "%s: not enough shared-mem for your configuration!\n", dev->name); return 1; } memset((char *) (p->xmit_cmds[i]), 0, sizeof(struct transmit_cmd_struct)); memset((char *) (p->xmit_buffs[i]), 0, sizeof(struct tbd_struct)); p->xmit_cmds[i]->cmd_status = STAT_COMPL; p->xmit_cmds[i]->cmd_cmd = CMD_XMIT | CMD_INT; p->xmit_cmds[i]->tbd_offset = make16((p->xmit_buffs[i])); p->xmit_buffs[i]->next = 0xffff; p->xmit_buffs[i]->buffer = make24((p->xmit_cbuffs[i])); } p->xmit_count = 0; p->xmit_last = 0;#ifndef NO_NOPCOMMANDS p->nop_point = 0;#endif /* * 'start transmitter' (nop-loop) */#ifndef NO_NOPCOMMANDS p->scb->cbl_offset = make16(p->nop_cmds[0]); p->scb->cmd = CUC_START; elmc_id_attn586(); WAIT_4_SCB_CMD();#else p->xmit_cmds[0]->cmd_link = 0xffff; p->xmit_cmds[0]->cmd_cmd = CMD_XMIT | CMD_LAST | CMD_INT;#endif return 0;}/****************************************************** * This is a helper routine for elmc_rnr_int() and init586(). * It sets up the Receive Frame Area (RFA). */static void *alloc_rfa(struct net_device *dev, void *ptr){ volatile struct rfd_struct *rfd = (struct rfd_struct *) ptr; volatile struct rbd_struct *rbd; int i; struct priv *p = (struct priv *) dev->priv; memset((char *) rfd, 0, sizeof(struct rfd_struct) * p->num_recv_buffs); p->rfd_first = rfd; for (i = 0; i < p->num_recv_buffs; i++) { rfd[i].next = make16(rfd + (i + 1) % p->num_recv_buffs); } rfd[p->num_recv_buffs - 1].last = RFD_SUSP; /* RU suspend */ ptr = (void *) (rfd + p->num_recv_buffs); rbd = (struct rbd_struct *) ptr; ptr = (void *) (rbd + p->num_recv_buffs); /* clr descriptors */ memset((char *) rbd, 0, sizeof(struct rbd_struct) * p->num_recv_buffs); for (i = 0; i < p->num_recv_buffs; i++) { rbd[i].next = make16((rbd + (i + 1) % p->num_recv_buffs)); rbd[i].size = RECV_BUFF_SIZE; rbd[i].buffer = make24(ptr); ptr = (char *) ptr + RECV_BUFF_SIZE; } p->rfd_top = p->rfd_first; p->rfd_last = p->rfd_first + p->num_recv_buffs - 1; p->scb->rfa_offset = make16(p->rfd_first); p->rfd_first->rbd_offset = make16(rbd); return ptr;}/************************************************** * Interrupt Handler ... */static void elmc_interrupt(int irq, void *dev_id, struct pt_regs *reg_ptr){ struct net_device *dev = (struct net_device *) dev_id; unsigned short stat; struct priv *p; if (dev == NULL) { printk(KERN_ERR "elmc-interrupt: irq %d for unknown device.\n", (int) -(((struct pt_regs *) reg_ptr)->orig_eax + 2)); return; } else if (!netif_running(dev)) { /* The 3c523 has this habit of generating interrupts during the reset. I'm not sure if the ni52 has this same problem, but it's really annoying if we haven't finished initializing it. I was hoping all the elmc_id_* commands would disable this, but I might have missed a few. */ elmc_id_attn586(); /* ack inter. and disable any more */ return; } else if (!(ELMC_CTRL_INT & inb(dev->base_addr + ELMC_CTRL))) { /* wasn't this device */ return; } /* reading ELMC_CTRL also clears the INT bit. */ p = (struct priv *) dev->priv; while ((stat = p->scb->status & STAT_MASK)) { p->scb->cmd = stat;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -