📄 sdladrv.c
字号:
break; case SDLA_S514: if (!detect_s514(hw)) err = -ENODEV; break; default: if (detect_s502a(port)) hw->type = SDLA_S502A; else if (detect_s502e(port)) hw->type = SDLA_S502E; else if (detect_s503(port)) hw->type = SDLA_S503; else if (detect_s507(port)) hw->type = SDLA_S507; else if (detect_s508(port)) hw->type = SDLA_S508; else err = -ENODEV; } return err;}/*============================================================================ * Autoselect memory region. * o try all available DMP address options from the top down until success. */static int sdla_autodpm (sdlahw_t* hw){ int i, err = -EINVAL; unsigned* opt; switch (hw->type) { case SDLA_S502A: opt = s502a_dpmbase_options; break; case SDLA_S502E: case SDLA_S503: case SDLA_S508: opt = s508_dpmbase_options; break; case SDLA_S507: opt = s507_dpmbase_options; break; default: return -EINVAL; } for (i = opt[0]; i && err; --i) { hw->dpmbase = phys_to_virt(opt[i]); err = sdla_setdpm(hw); } return err;}/*============================================================================ * Set up adapter dual-port memory window. * o shut down adapter * o make sure that no physical memory exists in this region, i.e entire * region reads 0xFF and is not writable when adapter is shut down. * o initialize adapter hardware * o make sure that region is usable with SDLA card, i.e. we can write to it * when adapter is configured. */static int sdla_setdpm (sdlahw_t* hw){ int err; /* Shut down card and verify memory region */ sdla_down(hw); if (check_memregion(hw->dpmbase, hw->dpmsize)) return -EINVAL; /* Initialize adapter and test on-board memory segment by segment. * If memory size appears to be less than shared memory window size, * assume that memory region is unusable. */ err = sdla_init(hw); if (err) return err; if (sdla_memtest(hw) < hw->dpmsize) { /* less than window size */ sdla_down(hw); return -EIO; } sdla_mapmem(hw, 0L); /* set window vector at bottom */ return 0;}/*============================================================================ * Load adapter from the memory image of the SDLA firmware module. * o verify firmware integrity and compatibility * o start adapter up */static int sdla_load (sdlahw_t* hw, sfm_t* sfm, unsigned len){ int i; /* Verify firmware signature */ if (strcmp(sfm->signature, SFM_SIGNATURE)) { printk(KERN_ERR "%s: not SDLA firmware!\n", modname); return -EINVAL; } /* Verify firmware module format version */ if (sfm->version != SFM_VERSION) { printk(KERN_ERR "%s: firmware format %u rejected! Expecting %u.\n", modname, sfm->version, SFM_VERSION); return -EINVAL; } /* Verify firmware module length and checksum */ if ((len - offsetof(sfm_t, image) != sfm->info.codesize) || (checksum((void*)&sfm->info, sizeof(sfm_info_t) + sfm->info.codesize) != sfm->checksum)) { printk(KERN_ERR "%s: firmware corrupted!\n", modname); return -EINVAL; } /* Announce */ printk(KERN_INFO "%s: loading %s (ID=%u)...\n", modname, (sfm->descr[0] != '\0') ? sfm->descr : "unknown firmware", sfm->info.codeid); if(hw->type == SDLA_S514) printk(KERN_INFO "%s: loading S514 adapter, CPU %c\n", modname, hw->S514_cpu_no[0]); /* Scan through the list of compatible adapters and make sure our * adapter type is listed. */ for (i = 0; (i < SFM_MAX_SDLA) && (sfm->info.adapter[i] != hw->type); ++i) ; if (i == SFM_MAX_SDLA) { printk(KERN_ERR "%s: firmware is not compatible with S%u!\n", modname, hw->type); ; return -EINVAL; } /* Make sure there is enough on-board memory */ if (hw->memory < sfm->info.memsize) { printk(KERN_ERR "%s: firmware needs %lu bytes of on-board memory!\n", modname, sfm->info.memsize); return -EINVAL; } /* Move code onto adapter */ if (sdla_poke(hw, sfm->info.codeoffs, sfm->image, sfm->info.codesize)) { printk(KERN_ERR "%s: failed to load code segment!\n", modname); return -EIO; } /* Prepare boot-time configuration data and kick-off CPU */ sdla_bootcfg(hw, &sfm->info); if (sdla_start(hw, sfm->info.startoffs)) { printk(KERN_ERR "%s: Damn... Adapter won't start!\n", modname); return -EIO; } /* position DPM window over the mailbox and enable interrupts */ if (sdla_mapmem(hw, sfm->info.winoffs) || sdla_inten(hw)) { printk(KERN_ERR "%s: adapter hardware failure!\n", modname); return -EIO; } hw->fwid = sfm->info.codeid; /* set firmware ID */ return 0;}/*============================================================================ * Initialize SDLA hardware: setup memory window, IRQ, etc. */static int sdla_init (sdlahw_t* hw){ int i; for (i = 0; i < SDLA_MAXIORANGE; ++i) hw->regs[i] = 0; switch (hw->type) { case SDLA_S502A: return init_s502a(hw); case SDLA_S502E: return init_s502e(hw); case SDLA_S503: return init_s503(hw); case SDLA_S507: return init_s507(hw); case SDLA_S508: return init_s508(hw); } return -EINVAL;}/*============================================================================ * Test adapter on-board memory. * o slide DPM window from the bottom up and test adapter memory segment by * segment. * Return adapter memory size. */static unsigned long sdla_memtest (sdlahw_t* hw){ unsigned long memsize; unsigned winsize; for (memsize = 0, winsize = hw->dpmsize; !sdla_mapmem(hw, memsize) && (test_memregion(hw->dpmbase, winsize) == winsize) ; memsize += winsize) ; hw->memory = memsize; return memsize;}/*============================================================================ * Prepare boot-time firmware configuration data. * o position DPM window * o initialize configuration data area */static int sdla_bootcfg (sdlahw_t* hw, sfm_info_t* sfminfo){ unsigned char* data; if (!sfminfo->datasize) return 0; /* nothing to do */ if (sdla_mapmem(hw, sfminfo->dataoffs) != 0) return -EIO; if(hw->type == SDLA_S514) data = (void*)(hw->dpmbase + sfminfo->dataoffs); else data = (void*)((u8 *)hw->dpmbase + (sfminfo->dataoffs - hw->vector)); memset_io (data, 0, sfminfo->datasize); writeb (make_config_byte(hw), &data[0x00]); switch (sfminfo->codeid) { case SFID_X25_502: case SFID_X25_508: writeb (3, &data[0x01]); /* T1 timer */ writeb (10, &data[0x03]); /* N2 */ writeb (7, &data[0x06]); /* HDLC window size */ writeb (1, &data[0x0B]); /* DTE */ writeb (2, &data[0x0C]); /* X.25 packet window size */ writew (128, &data[0x0D]); /* default X.25 data size */ writew (128, &data[0x0F]); /* maximum X.25 data size */ break; } return 0;}/*============================================================================ * Prepare configuration byte identifying adapter type and CPU clock rate. */static unsigned char make_config_byte (sdlahw_t* hw){ unsigned char byte = 0; switch (hw->pclk) { case 5000: byte = 0x01; break; case 7200: byte = 0x02; break; case 8000: byte = 0x03; break; case 10000: byte = 0x04; break; case 16000: byte = 0x05; break; } switch (hw->type) { case SDLA_S502E: byte |= 0x80; break; case SDLA_S503: byte |= 0x40; break; } return byte;}/*============================================================================ * Start adapter's CPU. * o calculate a pointer to adapter's cold boot entry point * o position DPM window * o place boot instruction (jp addr) at cold boot entry point * o start CPU */static int sdla_start (sdlahw_t* hw, unsigned addr){ unsigned port = hw->port; unsigned char *bootp; int err, tmp, i; if (!port && (hw->type != SDLA_S514)) return -EFAULT; switch (hw->type) { case SDLA_S502A: bootp = hw->dpmbase; bootp += 0x66; break; case SDLA_S502E: case SDLA_S503: case SDLA_S507: case SDLA_S508: case SDLA_S514: bootp = hw->dpmbase; break; default: return -EINVAL; } err = sdla_mapmem(hw, 0); if (err) return err; writeb (0xC3, bootp); /* Z80: 'jp' opcode */ bootp ++; writew (addr, bootp); switch (hw->type) { case SDLA_S502A: _OUTB(port, 0x10); /* issue NMI to CPU */ hw->regs[0] = 0x10; break; case SDLA_S502E: _OUTB(port + 3, 0x01); /* start CPU */ hw->regs[3] = 0x01; for (i = 0; i < SDLA_IODELAY; ++i); if (_INB(port) & 0x01) { /* verify */ /* * Enabling CPU changes functionality of the * control register, so we have to reset its * mirror. */ _OUTB(port, 0); /* disable interrupts */ hw->regs[0] = 0; } else return -EIO; break; case SDLA_S503: tmp = hw->regs[0] | 0x09; /* set bits 0 and 3 */ _OUTB(port, tmp); hw->regs[0] = tmp; /* update mirror */ for (i = 0; i < SDLA_IODELAY; ++i); if (!(_INB(port) & 0x01)) /* verify */ return -EIO; break; case SDLA_S507: tmp = hw->regs[0] | 0x02; _OUTB(port, tmp); hw->regs[0] = tmp; /* update mirror */ for (i = 0; i < SDLA_IODELAY; ++i); if (!(_INB(port) & 0x04)) /* verify */ return -EIO; break; case SDLA_S508: tmp = hw->regs[0] | 0x02; _OUTB(port, tmp); hw->regs[0] = tmp; /* update mirror */ for (i = 0; i < SDLA_IODELAY; ++i); if (!(_INB(port + 1) & 0x02)) /* verify */ return -EIO; break; case SDLA_S514: writeb (S514_CPU_START, hw->vector); break; default: return -EINVAL; } return 0;}/*============================================================================ * Initialize S502A adapter. */static int init_s502a (sdlahw_t* hw){ unsigned port = hw->port; int tmp, i; if (!detect_s502a(port)) return -ENODEV; hw->regs[0] = 0x08; hw->regs[1] = 0xFF; /* Verify configuration options */ i = get_option_index(s502a_dpmbase_options, virt_to_phys(hw->dpmbase)); if (i == 0) return -EINVAL; tmp = s502a_hmcr[i - 1]; switch (hw->dpmsize) { case 0x2000: tmp |= 0x01; break; case 0x10000L: break; default: return -EINVAL; } /* Setup dual-port memory window (this also enables memory access) */ _OUTB(port + 1, tmp); hw->regs[1] = tmp; hw->regs[0] = 0x08; return 0;}/*============================================================================ * Initialize S502E adapter. */static int init_s502e (sdlahw_t* hw){ unsigned port = hw->port; int tmp, i; if (!detect_s502e(port)) return -ENODEV; /* Verify configuration options */ i = get_option_index(s508_dpmbase_options, virt_to_phys(hw->dpmbase)); if (i == 0) return -EINVAL; tmp = s502e_hmcr[i - 1]; switch (hw->dpmsize) { case 0x2000: tmp |= 0x01; break; case 0x10000L: break; default: return -EINVAL; } /* Setup dual-port memory window */ _OUTB(port + 1, tmp); hw->regs[1] = tmp; /* Enable memory access */ _OUTB(port, 0x02); hw->regs[0] = 0x02; for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ return (_INB(port) & 0x02) ? 0 : -EIO;}/*============================================================================ * Initialize S503 adapter. * --------------------------------------------------------------------------- */static int init_s503 (sdlahw_t* hw){ unsigned port = hw->port; int tmp, i; if (!detect_s503(port)) return -ENODEV; /* Verify configuration options */ i = get_option_index(s508_dpmbase_options, virt_to_phys(hw->dpmbase)); if (i == 0) return -EINVAL; tmp = s502e_hmcr[i - 1]; switch (hw->dpmsize) { case 0x2000: tmp |= 0x01; break; case 0x10000L: break; default: return -EINVAL; } /* Setup dual-port memory window */ _OUTB(port + 1, tmp); hw->regs[1] = tmp; /* Enable memory access */ _OUTB(port, 0x02); hw->regs[0] = 0x02; /* update mirror */ return 0;}/*============================================================================ * Initialize S507 adapter. */static int init_s507 (sdlahw_t* hw){ unsigned port = hw->port; int tmp, i; if (!detect_s507(port)) return -ENODEV; /* Verify configuration options */ i = get_option_index(s507_dpmbase_options, virt_to_phys(hw->dpmbase)); if (i == 0) return -EINVAL; tmp = s507_hmcr[i - 1]; switch (hw->dpmsize) { case 0x2000: tmp |= 0x01; break; case 0x10000L: break; default: return -EINVAL; } /* Enable adapter's logic */ _OUTB(port, 0x01); hw->regs[0] = 0x01; for (i = 0; i < SDLA_IODELAY; ++i); /* delay */ if (!(_INB(port) & 0x20)) return -EIO;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -