📄 siop.c
字号:
}}intsiop_morecbd(sc) struct siop_softc *sc;{ int error, i, j; bus_dma_segment_t seg; int rseg; struct siop_cbd *newcbd; bus_addr_t dsa; u_int32_t *scr; /* allocate a new list head */ newcbd = malloc(sizeof(struct siop_cbd), M_DEVBUF, M_NOWAIT); if (newcbd == NULL) { printf("%s: can't allocate memory for command descriptors " "head\n", sc->sc_dev.dv_xname); return ENOMEM; } memset(newcbd, 0, sizeof(struct siop_cbd)); /* allocate cmd list */ newcbd->cmds = malloc(sizeof(struct siop_cmd) * SIOP_NCMDPB, M_DEVBUF, M_NOWAIT); if (newcbd->cmds == NULL) { printf("%s: can't allocate memory for command descriptors\n", sc->sc_dev.dv_xname); error = ENOMEM; goto bad3; } memset(newcbd->cmds, 0, sizeof(struct siop_cmd) * SIOP_NCMDPB); error = bus_dmamem_alloc(sc->sc_dmat, PAGE_SIZE, PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT); if (error) { printf("%s: unable to allocate cbd DMA memory, error = %d\n", sc->sc_dev.dv_xname, error); goto bad2; } error = bus_dmamem_map(sc->sc_dmat, &seg, rseg, PAGE_SIZE, (caddr_t *)&newcbd->xfers, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); if (error) { printf("%s: unable to map cbd DMA memory, error = %d\n", sc->sc_dev.dv_xname, error); goto bad2; } error = bus_dmamap_create(sc->sc_dmat, PAGE_SIZE, 1, PAGE_SIZE, 0, BUS_DMA_NOWAIT, &newcbd->xferdma); if (error) { printf("%s: unable to create cbd DMA map, error = %d\n", sc->sc_dev.dv_xname, error); goto bad1; } error = bus_dmamap_load(sc->sc_dmat, newcbd->xferdma, newcbd->xfers, PAGE_SIZE, NULL, BUS_DMA_NOWAIT); if (error) { printf("%s: unable to load cbd DMA map, error = %d\n", sc->sc_dev.dv_xname, error); goto bad0; }#ifdef DEBUG printf("%s: alloc newcdb at PHY addr 0x%lx\n", sc->sc_dev.dv_xname, (unsigned long)newcbd->xferdma->dm_segs[0].ds_addr); printf("%s: SIOP_NCMDPB is %d\n", sc->sc_dev.dv_xname, SIOP_NCMDPB);#endif for (i = 0; i < SIOP_NCMDPB; i++) { error = bus_dmamap_create(sc->sc_dmat, MAXPHYS, SIOP_NSG, MAXPHYS, 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &newcbd->cmds[i].dmamap_data); if (error) { printf("%s: unable to create data DMA map for cbd: " "error %d\n", sc->sc_dev.dv_xname, error); goto bad0; } error = bus_dmamap_create(sc->sc_dmat, sizeof(struct scsi_generic), 1, sizeof(struct scsi_generic), 0, BUS_DMA_NOWAIT | BUS_DMA_ALLOCNOW, &newcbd->cmds[i].dmamap_cmd); if (error) { printf("%s: unable to create cmd DMA map for cbd %d\n", sc->sc_dev.dv_xname, error); goto bad0; } newcbd->cmds[i].siop_sc = sc; newcbd->cmds[i].siop_cbdp = newcbd; newcbd->cmds[i].siop_xfer = &newcbd->xfers[i]; memset(newcbd->cmds[i].siop_xfer, 0, sizeof(struct siop_xfer)); newcbd->cmds[i].dsa = newcbd->xferdma->dm_segs[0].ds_addr + i * sizeof(struct siop_xfer); dsa = newcbd->cmds[i].dsa; newcbd->cmds[i].status = CMDST_FREE; newcbd->cmds[i].siop_tables.t_msgout.count= htole32(1); newcbd->cmds[i].siop_tables.t_msgout.addr = htole32(dsa); newcbd->cmds[i].siop_tables.t_msgin.count= htole32(1); newcbd->cmds[i].siop_tables.t_msgin.addr = htole32(dsa + 16); newcbd->cmds[i].siop_tables.t_extmsgin.count= htole32(2); newcbd->cmds[i].siop_tables.t_extmsgin.addr = htole32(dsa + 17); newcbd->cmds[i].siop_tables.t_extmsgdata.addr = htole32(dsa + 19); newcbd->cmds[i].siop_tables.t_status.count= htole32(1); newcbd->cmds[i].siop_tables.t_status.addr = htole32(dsa + 32); /* The select/reselect script */ scr = &newcbd->cmds[i].siop_xfer->resel[0]; for (j = 0; j < sizeof(load_dsa) / sizeof(load_dsa[0]); j++) scr[j] = htole32(load_dsa[j]); /* * 0x78000000 is a 'move data8 to reg'. data8 is the second * octet, reg offset is the third. */ scr[Ent_rdsa0 / 4] = htole32(0x78100000 | ((dsa & 0x000000ff) << 8)); scr[Ent_rdsa1 / 4] = htole32(0x78110000 | ( dsa & 0x0000ff00 )); scr[Ent_rdsa2 / 4] = htole32(0x78120000 | ((dsa & 0x00ff0000) >> 8)); scr[Ent_rdsa3 / 4] = htole32(0x78130000 | ((dsa & 0xff000000) >> 16)); scr[E_ldsa_abs_reselected_Used[0]] = htole32(sc->sc_scriptaddr + Ent_reselected); scr[E_ldsa_abs_reselect_Used[0]] = htole32(sc->sc_scriptaddr + Ent_reselect); scr[E_ldsa_abs_selected_Used[0]] = htole32(sc->sc_scriptaddr + Ent_selected); scr[E_ldsa_abs_data_Used[0]] = htole32(dsa + sizeof(struct siop_xfer_common) + Ent_ldsa_data); /* JUMP foo, IF FALSE - used by MOVE MEMORY to clear the slot */ scr[Ent_ldsa_data / 4] = htole32(0x80000000); TAILQ_INSERT_TAIL(&sc->free_list, &newcbd->cmds[i], next);#ifdef SIOP_DEBUG printf("tables[%d]: in=0x%x out=0x%x status=0x%x\n", i, letoh32(newcbd->cmds[i].siop_tables.t_msgin.addr), letoh32(newcbd->cmds[i].siop_tables.t_msgout.addr), letoh32(newcbd->cmds[i].siop_tables.t_status.addr));#endif } TAILQ_INSERT_TAIL(&sc->cmds, newcbd, next); return 0;bad0: bus_dmamap_destroy(sc->sc_dmat, newcbd->xferdma);bad1: bus_dmamem_free(sc->sc_dmat, &seg, rseg);bad2: free(newcbd->cmds, M_DEVBUF);bad3: free(newcbd, M_DEVBUF); return error;}struct siop_lunsw *siop_get_lunsw(sc) struct siop_softc *sc;{ struct siop_lunsw *lunsw; int i; if (sc->script_free_lo + (sizeof(lun_switch) / sizeof(lun_switch[0])) >= sc->script_free_hi) return NULL; lunsw = TAILQ_FIRST(&sc->lunsw_list); if (lunsw != NULL) {#ifdef SIOP_DEBUG printf("siop_get_lunsw got lunsw at offset %d\n", lunsw->lunsw_off);#endif TAILQ_REMOVE(&sc->lunsw_list, lunsw, next); return lunsw; } lunsw = malloc(sizeof(struct siop_lunsw), M_DEVBUF, M_NOWAIT); if (lunsw == NULL) return NULL; memset(lunsw, 0, sizeof(struct siop_lunsw));#ifdef SIOP_DEBUG printf("allocating lunsw at offset %d\n", sc->script_free_lo);#endif if (sc->features & SF_CHIP_RAM) { bus_space_write_region_4(sc->sc_ramt, sc->sc_ramh, sc->script_free_lo * 4, lun_switch, sizeof(lun_switch) / sizeof(lun_switch[0])); bus_space_write_4(sc->sc_ramt, sc->sc_ramh, (sc->script_free_lo + E_abs_lunsw_return_Used[0]) * 4, sc->sc_scriptaddr + Ent_lunsw_return); } else { for (i = 0; i < sizeof(lun_switch) / sizeof(lun_switch[0]); i++) sc->sc_script[sc->script_free_lo + i] = htole32(lun_switch[i]); sc->sc_script[sc->script_free_lo + E_abs_lunsw_return_Used[0]] = htole32(sc->sc_scriptaddr + Ent_lunsw_return); } lunsw->lunsw_off = sc->script_free_lo; lunsw->lunsw_size = sizeof(lun_switch) / sizeof(lun_switch[0]); sc->script_free_lo += lunsw->lunsw_size; if (sc->script_free_lo > 1024) printf("%s: script_free_lo (%d) > 1024\n", sc->sc_dev.dv_xname, sc->script_free_lo); siop_script_sync(sc, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); return lunsw;}voidsiop_add_reselsw(sc, target) struct siop_softc *sc; int target;{ int i; struct siop_lun *siop_lun; /* * add an entry to resel switch */ siop_script_sync(sc, BUS_DMASYNC_POSTWRITE); for (i = 0; i < 15; i++) { sc->targets[target]->reseloff = Ent_resel_targ0 / 4 + i * 2; if ((siop_script_read(sc, sc->targets[target]->reseloff) & 0xff) == 0xff) { /* it's free */#ifdef SIOP_DEBUG printf("siop: target %d slot %d offset %d\n", target, i, sc->targets[target]->reseloff);#endif /* JUMP abs_foo, IF target | 0x80; */ siop_script_write(sc, sc->targets[target]->reseloff, 0x800c0080 | target); siop_script_write(sc, sc->targets[target]->reseloff + 1, sc->sc_scriptaddr + sc->targets[target]->lunsw->lunsw_off * 4 + Ent_lun_switch_entry); break; } } if (i == 15) /* no free slot, shouldn't happen */ panic("siop: resel switch full"); sc->sc_ntargets++; for (i = 0; i < 8; i++) { siop_lun = sc->targets[target]->siop_lun[i]; if (siop_lun == NULL) continue; if (siop_lun->reseloff > 0) { siop_lun->reseloff = 0; siop_add_dev(sc, target, i); } } siop_update_scntl3(sc, sc->targets[target]); siop_script_sync(sc, BUS_DMASYNC_PREWRITE);}voidsiop_update_scntl3(sc, siop_target) struct siop_softc *sc; struct siop_target *siop_target;{ /* MOVE target->id >> 24 TO SCNTL3 */ siop_script_write(sc, siop_target->lunsw->lunsw_off + (Ent_restore_scntl3 / 4), 0x78030000 | ((siop_target->id >> 16) & 0x0000ff00)); /* MOVE target->id >> 8 TO SXFER */ siop_script_write(sc, siop_target->lunsw->lunsw_off + (Ent_restore_scntl3 / 4) + 2, 0x78050000 | (siop_target->id & 0x0000ff00)); /* If DT, change null op ('MOVE 0xff TO SFBR') to 'MOVE n TO SCNTL4' */ if (siop_target->flags & TARF_ISDT) siop_script_write(sc, siop_target->lunsw->lunsw_off + (Ent_restore_scntl3 / 4) + 4, 0x78bc0000 | ((siop_target->id << 8) & 0x0000ff00)); else siop_script_write(sc, siop_target->lunsw->lunsw_off + (Ent_restore_scntl3 / 4) + 4, 0x7808ff00); siop_script_sync(sc, BUS_DMASYNC_PREWRITE);}voidsiop_add_dev(sc, target, lun) struct siop_softc *sc; int target; int lun;{ struct siop_lunsw *lunsw; struct siop_lun *siop_lun = sc->targets[target]->siop_lun[lun]; int i, ntargets; if (siop_lun->reseloff > 0) return; lunsw = sc->targets[target]->lunsw; if ((lunsw->lunsw_off + lunsw->lunsw_size) < sc->script_free_lo) { /* * Can't extend this slot. Probably not worth trying to deal * with this case. */#ifdef DEBUG printf("%s:%d:%d: can't allocate a lun sw slot\n", sc->sc_dev.dv_xname, target, lun);#endif return; } /* count how many free targets we still have to probe */ ntargets = (sc->sc_link.adapter_buswidth - 1) - 1 - sc->sc_ntargets; /* * We need 8 bytes for the lun sw additional entry, and * eventually sizeof(tag_switch) for the tag switch entry. * Keep enough free space for the free targets that could be * probed later. */ if (sc->script_free_lo + 2 + (ntargets * sizeof(lun_switch) / sizeof(lun_switch[0])) >= ((sc->targets[target]->flags & TARF_TAG) ? sc->script_free_hi - (sizeof(tag_switch) / sizeof(tag_switch[0])) : sc->script_free_hi)) { /* * Not enough space, but probably not worth dealing with it. * We can hold 13 tagged-queuing capable devices in the 4k RAM. */#ifdef DEBUG printf("%s:%d:%d: not enough memory for a lun sw slot\n", sc->sc_dev.dv_xname, target, lun);#endif return; }#ifdef SIOP_DEBUG printf("%s:%d:%d: allocate lun sw entry\n", sc->sc_dev.dv_xname, target, lun);#endif /* INT int_resellun */ siop_script_write(sc, sc->script_free_lo, 0x98080000); siop_script_write(sc, sc->script_free_lo + 1, A_int_resellun); /* Now the slot entry: JUMP abs_foo, IF lun */ siop_script_write(sc, sc->script_free_lo - 2, 0x800c0000 | lun); siop_script_write(sc, sc->script_free_lo - 1, 0); siop_lun->reseloff = sc->script_free_lo - 2; lunsw->lunsw_size += 2; sc->script_free_lo += 2; if (sc->targets[target]->flags & TARF_TAG) { /* we need a tag switch */ sc->script_free_hi -= sizeof(tag_switch) / sizeof(tag_switch[0]); if (sc->features & SF_CHIP_RAM) { bus_space_write_region_4(sc->sc_ramt, sc->sc_ramh, sc->script_free_hi * 4, tag_switch, sizeof(tag_switch) / sizeof(tag_switch[0])); } else { for(i = 0; i < sizeof(tag_switch) / sizeof(tag_switch[0]); i++) { sc->sc_script[sc->script_free_hi + i] = htole32(tag_switch[i]); } } siop_script_write(sc, siop_lun->reseloff + 1, sc->sc_scriptaddr + sc->script_free_hi * 4 + Ent_tag_switch_entry); for (i = 0; i < SIOP_NTAG; i++) { siop_lun->siop_tag[i].reseloff = sc->script_free_hi + (Ent_resel_tag0 / 4) + i * 2; } } else { /* non-tag case; just work with the lun switch */ siop_lun->siop_tag[0].reseloff = sc->targets[target]->siop_lun[lun]->reseloff; } siop_script_sync(sc, BUS_DMASYNC_PREWRITE);}voidsiop_del_dev(sc, target, lun) struct siop_softc *sc; int target; int lun;{ int i;#ifdef SIOP_DEBUG printf("%s:%d:%d: free lun sw entry\n", sc->sc_dev.dv_xname, target, lun);#endif if (sc->targets[target] == NULL) return; free(sc->targets[target]->siop_lun[lun], M_DEVBUF); sc->targets[target]->siop_lun[lun] = NULL; /* XXX compact sw entry too ? */ /* check if we can free the whole target */ for (i = 0; i < 8; i++) { if (sc->targets[target]->siop_lun[i] != NULL) return; }#ifdef SIOP_DEBUG printf("%s: free siop_target for target %d lun %d lunsw offset %d\n", sc->sc_dev.dv_xname, target, lun, sc->targets[target]->lunsw->lunsw_off);#endif /* * nothing here, free the target struct and resel * switch entry */ siop_script_write(sc, sc->targets[target]->reseloff, 0x800c00ff); siop_script_sync(sc, BUS_DMASYNC_PREWRITE); TAILQ_INSERT_TAIL(&sc->lunsw_list, sc->targets[target]->lunsw, next); free(sc->targets[target], M_DEVBUF); sc->targets[target] = NULL; sc->sc_ntargets--;}#ifdef SIOP_STATSvoidsiop_printstats(){ printf("siop_stat_intr %d\n", siop_stat_intr); printf("siop_stat_intr_shortxfer %d\n", siop_stat_intr_shortxfer); printf("siop_stat_intr_xferdisc %d\n", siop_stat_intr_xferdisc); printf("siop_stat_intr_sdp %d\n", siop_stat_intr_sdp); printf("siop_stat_intr_done %d\n", siop_stat_intr_done); printf("siop_stat_intr_lunresel %d\n", siop_stat_intr_lunresel); printf("siop_stat_intr_qfull %d\n", siop_stat_intr_qfull);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -