Lines Matching refs:wp

162 #define WDSTOPHYS(wp, a)	( ((u_long)a) - ((u_long)wp->dx) + ((u_long)wp->dx_p) )
163 #define WDSTOVIRT(wp, a) ( ((char *)a) - ((char*)wp->dx_p) + ((char *)wp->dx) )
326 static void wds_intr(struct wds *wp);
331 static int wds_preinit(struct wds *wp);
332 static int wds_init(struct wds *wp);
336 static void wds_free_resources(struct wds *wp);
338 static struct wds_req *wdsr_alloc(struct wds *wp);
341 static void wdsr_ccb_done(struct wds *wp, struct wds_req *r,
344 static void wds_done(struct wds *wp, struct wds_req *r, u_int8_t stat);
345 static int wds_runsense(struct wds *wp, struct wds_req *r);
346 static int wds_getvers(struct wds *wp);
351 static struct wds_req *cmdtovirt(struct wds *wp, u_int32_t phys);
353 static u_int32_t frag_alloc(struct wds *wp, int size, u_int8_t **res,
355 static void frag_free(struct wds *wp, u_int32_t mask);
457 struct wds *wp;
465 wp = (struct wds *) device_get_softc(dev);
466 wp->unit = device_get_unit(dev);
467 wp->dev = dev;
469 wp->addr = bus_get_resource_start(dev, SYS_RES_IOPORT, 0 /*rid*/);
470 if (wp->addr == 0 || wp->addr <0x300
471 || wp->addr > 0x3f8 || wp->addr & 0x7) {
472 device_printf(dev, "invalid port address 0x%x\n", wp->addr);
476 if (bus_set_resource(dev, SYS_RES_IOPORT, 0, wp->addr, WDS_NPORTS) < 0)
480 wp->drq = bus_get_resource_start(dev, SYS_RES_DRQ, 0 /*rid*/);
481 if (wp->drq < 5 || wp->drq > 7) {
482 device_printf(dev, "invalid DRQ %d\n", wp->drq);
493 wp->port_rid = 0;
494 wp->port_r = bus_alloc_resource(dev, SYS_RES_IOPORT, &wp->port_rid,
497 if (wp->port_r == NULL)
500 error = wds_preinit(wp);
506 wds_free_resources(wp);
514 struct wds *wp;
521 wp = (struct wds *)device_get_softc(dev);
523 wp->port_rid = 0;
524 wp->port_r = bus_alloc_resource(dev, SYS_RES_IOPORT, &wp->port_rid,
527 if (wp->port_r == NULL)
532 wp->drq_rid = 0;
533 wp->drq_r = bus_alloc_resource(dev, SYS_RES_DRQ, &wp->drq_rid,
536 if (wp->drq_r == NULL)
539 wp->intr_rid = 0;
540 wp->intr_r = bus_alloc_resource(dev, SYS_RES_IRQ, &wp->intr_rid,
543 if (wp->intr_r == NULL)
545 error = bus_setup_intr(dev, wp->intr_r, INTR_TYPE_CAM | INTR_ENTROPY,
546 NULL, (driver_intr_t *)wds_intr, (void *)wp,
547 &wp->intr_cookie);
557 /*maxsize*/ sizeof(* wp->dx),
559 /*maxsegsz*/ sizeof(* wp->dx), /*flags*/ 0,
562 &wp->bustag);
566 error = bus_dmamem_alloc(wp->bustag, (void **)&wp->dx,
567 /*flags*/ 0, &wp->busmap);
571 bus_dmamap_load(wp->bustag, wp->busmap, (void *)wp->dx,
572 sizeof(* wp->dx), wds_alloc_callback,
573 (void *)&wp->dx_p, /*flags*/0);
577 wp->dx->req[i].id = i;
578 wp->wdsr_free |= 1<<i;
589 wp->data_free = 0;
593 wp->data_free = (wp->data_free << 1) | 1;
597 if (wds_init(wp) != 0)
600 if (wds_getvers(wp) == -1)
609 sim = cam_sim_alloc(wds_action, wds_poll, "wds", (void *) wp,
610 wp->unit, &Giant, 1, 1, devq);
615 wp->sim = sim;
628 wp->path = pathp;
633 wds_free_resources(wp);
648 wds_free_resources(struct wds *wp)
653 if (wp->intr_r) {
654 bus_teardown_intr(wp->dev, wp->intr_r, wp->intr_cookie);
655 bus_release_resource(wp->dev, SYS_RES_IRQ, wp->intr_rid,
656 wp->intr_r);
657 wp->intr_r = 0;
661 if (wp->dx_p) {
662 bus_dmamap_unload(wp->bustag, wp->busmap);
663 wp->dx_p = 0;
665 if (wp->dx) { /* wp->busmap may be legitimately equal to 0 */
667 bus_dmamem_free(wp->bustag, wp->dx, wp->busmap);
668 wp->dx = 0;
670 if (wp->bustag) {
671 bus_dma_tag_destroy(wp->bustag);
672 wp->bustag = 0;
675 if (wp->drq_r) {
676 bus_release_resource(wp->dev, SYS_RES_DRQ,
677 wp->drq_rid, wp->drq_r);
678 wp->drq_r = 0;
680 if (wp->port_r) {
681 bus_release_resource(wp->dev, SYS_RES_IOPORT,
682 wp->port_rid, wp->port_r);
683 wp->port_r = 0;
689 frag_alloc(struct wds *wp, int size, u_int8_t **res, u_int32_t *maskp)
702 free = wp->data_free;
707 wp->data_free &= ~mask; /* mark frags as busy */
709 *res = &wp->dx->data[fragsiz * i];
711 wp->unit, mask);
724 frag_free(struct wds *wp, u_int32_t mask)
726 wp->data_free |= mask; /* mark frags as free */
727 DBG(DBX "wds%d: freed buffer mask=0x%x\n", wp->unit, mask);
731 wdsr_alloc(struct wds *wp)
744 i = ffs(wp->wdsr_free) - 1;
749 wp->wdsr_free &= ~ (1<<i);
750 r = &wp->dx->req[i];
753 wp->dx->ombs[i].stat = 1;
762 wds_intr(struct wds *wp)
768 int addr = wp->addr;
770 DBG(DBX "wds%d: interrupt [\n", wp->unit);
777 in = &wp->dx->imbs[c];
779 rp = cmdtovirt(wp, scsi_3btoul(in->addr));
783 wds_done(wp, rp, stat);
785 device_printf(wp->dev,
791 device_printf(wp->dev,
798 DBG(DBX "wds%d: ]\n", wp->unit);
802 wds_done(struct wds *wp, struct wds_req *r, u_int8_t stat)
811 device_printf(wp->dev,
822 DBG(DBX "wds%d: %s stat=0x%x c->stat=0x%x c->venderr=0x%x\n", wp->unit,
828 DBG(DBX "wds%d: sense 0x%x\n", wp->unit, r->buf[0]);
859 if ( wds_runsense(wp, r) == CAM_REQ_CMP )
892 wp->dx->ombs[r->ombn].stat = 0;
895 wdsr_ccb_done(wp, r, r->ccb, status);
898 frag_free(wp, r->mask);
899 if (wp->want_wdsr) {
900 wp->want_wdsr = 0;
901 xpt_release_simq(wp->sim, /* run queue */ 1);
903 wp->wdsr_free |= (1 << r->id);
906 DBG(DBX "wds%d: request %p done\n", wp->unit, r);
912 wds_runsense(struct wds *wp, struct wds_req *r)
920 scsi_ulto3b(WDSTOPHYS(wp, &r->cmd),
921 wp->dx->ombs[r->ombn].addr);
933 scsi_ulto3b(WDSTOPHYS(wp, r->buf), r->cmd.data);
937 outb(wp->addr + WDS_HCR, WDSH_IRQEN | WDSH_DRQEN);
939 wp->dx->ombs[r->ombn].stat = 1;
942 if (wds_cmd(wp->addr, &c, sizeof c) != 0) {
943 device_printf(wp->dev, "unable to start outgoing sense mbox\n");
944 wp->dx->ombs[r->ombn].stat = 0;
945 wdsr_ccb_done(wp, r, r->ccb, CAM_AUTOSENSE_FAIL);
949 wp->unit, r->cmd.scb[0] & 0xFF, r);
958 wds_getvers(struct wds *wp)
965 base = wp->addr;
967 r = wdsr_alloc(wp);
969 device_printf(wp->dev, "no request slot available!\n");
976 scsi_ulto3b(WDSTOPHYS(wp, &r->cmd), wp->dx->ombs[r->ombn].addr);
985 device_printf(wp->dev, "version request failed\n");
986 wp->wdsr_free |= (1 << r->id);
987 wp->dx->ombs[r->ombn].stat = 0;
995 device_printf(wp->dev, "getvers timeout\n");
999 wds_intr(wp);
1001 device_printf(wp->dev, "firmware version %d.%02d\n",
1003 wp->wdsr_free |= (1 << r->id);
1010 wdsr_ccb_done(struct wds *wp, struct wds_req *r,
1023 frag_free(wp, r->mask);
1024 if (wp->want_wdsr && status != CAM_REQUEUE_REQ) {
1025 wp->want_wdsr = 0;
1029 wp->wdsr_free |= (1 << r->id);
1040 struct wds *wp;
1048 wp = (struct wds *)cam_sim_softc(sim);
1075 base = wp->addr;
1081 if(wp->want_wdsr) {
1091 r = wdsr_alloc(wp);
1093 device_printf(wp->dev, "no request slot available!\n");
1094 wp->want_wdsr = 1;
1105 switch (error = frag_alloc(wp, csio->dxfer_len, &r->buf, &r->mask)) {
1110 wp->want_wdsr = 1;
1113 wdsr_ccb_done(wp, r, r->ccb, CAM_REQUEUE_REQ);
1117 wdsr_ccb_done(wp, r, r->ccb, error);
1124 scsi_ulto3b(WDSTOPHYS(wp, &r->cmd), wp->dx->ombs[r->ombn].addr);
1144 scsi_ulto3b(csio->dxfer_len ? WDSTOPHYS(wp, r->buf) : 0, r->cmd.data);
1158 device_printf(wp->dev, "unable to start outgoing mbox\n");
1159 wp->dx->ombs[r->ombn].stat = 0;
1160 wdsr_ccb_done(wp, r, r->ccb, CAM_RESRC_UNAVAIL);
1252 wds_preinit(struct wds *wp)
1257 base = wp->addr;
1291 wds_init(struct wds *wp)
1298 base = wp->addr;
1302 isa_dmacascade(wp->drq);
1319 scsi_ulto3b(WDSTOPHYS(wp, &wp->dx->ombs), init.mbaddr);
1326 device_printf(wp->dev, "wds_cmd init failed\n");
1336 device_printf(wp->dev, "wds_cmd init2 failed\n");
1370 cmdtovirt(struct wds *wp, u_int32_t phys)
1374 a = WDSTOVIRT(wp, (uintptr_t)phys);
1375 if( a < (char *)&wp->dx->req[0] || a>= (char *)&wp->dx->req[MAXSIMUL]) {
1376 device_printf(wp->dev, "weird phys address 0x%x\n", phys);
1390 struct wds *wp;
1393 wp = (struct wds *) devclass_get_device(wds_devclass, unit);
1394 if (wp == NULL)
1397 unit, wp->want_wdsr, inb(wp->addr + WDS_STAT) & 0xff,
1398 (inb(wp->addr + WDS_STAT) & WDS_IRQ) ? "ready" : "no",
1399 inb(wp->addr + WDS_IRQSTAT) & 0xff);
1401 r = &wp->dx->req[i];
1402 if( wp->wdsr_free & (1 << r->id) ) {
1406 wp->dx->ombs[r->ombn].stat,