static int w_write(Ctlr* ctlr, int type, int off, void* buf, ulong len) { int tries; for (tries=0; tries < WTmOut; tries++) { if(w_seek(ctlr, type, off, 0)) { DEBUG("wavelan: w_write: seek failed\n"); return 0; } csr_outss(ctlr, WR_Data0, buf, len/2); csr_outs(ctlr, WR_Data0, 0xdead); csr_outs(ctlr, WR_Data0, 0xbeef); if(w_seek(ctlr, type, off + len, 0)) { DEBUG("wavelan: write seek failed\n"); return 0; } if(csr_ins(ctlr, WR_Data0) == 0xdead) if(csr_ins(ctlr, WR_Data0) == 0xbeef) return len; DEBUG("wavelan: Hermes bug byte.\n"); return 0; } DEBUG("wavelan: tx timeout\n"); return 0; }
int w_inltv(Ctlr* ctlr, Wltv* ltv) { int len; ushort code; if(w_cmd(ctlr, WCmdAccRd, ltv->type)){ DEBUG("wavelan: access read failed\n"); return -1; } if(w_seek(ctlr,ltv->type,0,1)){ DEBUG("wavelan: seek failed\n"); return -1; } len = csr_ins(ctlr, WR_Data1); if(len > ltv->len) return -1; ltv->len = len; if((code=csr_ins(ctlr, WR_Data1)) != ltv->type){ USED(code); DEBUG("wavelan: type %x != code %x\n",ltv->type,code); return -1; } if(ltv->len > 0) csr_inss(ctlr, WR_Data1, <v->val, ltv->len-1); return 0; }
static void w_outltv(Ctlr* ctlr, Wltv* ltv) { if(w_seek(ctlr,ltv->type, 0, 1)) return; csr_outss(ctlr, WR_Data1, ltv, ltv->len+1); w_cmd(ctlr, WCmdAccWr, ltv->type); }
static int w_read(Ctlr* ctlr, int type, int off, void* buf, ulong len) { if(w_seek(ctlr, type, off, 1)){ DEBUG("wavelan: w_read: seek failed"); return 0; } csr_inss(ctlr, WR_Data1, buf, len/2); return len; }
static int w_alloc(Ctlr* ctlr, int len) { int rc; int i,j; if(w_cmd(ctlr, WCmdMalloc, len)==0) for (i = 0; i<WTmOut; i++) if(csr_ins(ctlr, WR_EvSts) & WAllocEv){ csr_ack(ctlr, WAllocEv); rc=csr_ins(ctlr, WR_Alloc); if(w_seek(ctlr, rc, 0, 0)) return -1; len = len/2; for (j=0; j<len; j++) csr_outs(ctlr, WR_Data0, 0); return rc; } return -1; }