From owner-p4-projects@FreeBSD.ORG Mon Nov 23 23:50:27 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id E34321065676; Mon, 23 Nov 2009 23:50:26 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8E956106566C for ; Mon, 23 Nov 2009 23:50:26 +0000 (UTC) (envelope-from mav@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 7AB2D8FC1D for ; Mon, 23 Nov 2009 23:50:26 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id nANNoQ0n073789 for ; Mon, 23 Nov 2009 23:50:26 GMT (envelope-from mav@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id nANNoQP0073787 for perforce@freebsd.org; Mon, 23 Nov 2009 23:50:26 GMT (envelope-from mav@freebsd.org) Date: Mon, 23 Nov 2009 23:50:26 GMT Message-Id: <200911232350.nANNoQP0073787@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to mav@freebsd.org using -f From: Alexander Motin To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 170967 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Nov 2009 23:50:27 -0000 http://p4web.freebsd.org/chv.cgi?CH=170967 Change 170967 by mav@mav_mavtest on 2009/11/23 23:49:46 Completely refactor ata(4) mode settings. Remove duplicate code and make it usable for CAM ATA. Make CAM ATA really negotiate and report ATA transfer settings. Affected files ... .. //depot/projects/scottl-camlock/src/sbin/camcontrol/camcontrol.c#31 edit .. //depot/projects/scottl-camlock/src/sys/arm/mv/mv_sata.c#3 edit .. //depot/projects/scottl-camlock/src/sys/cam/ata/ata_all.c#24 edit .. //depot/projects/scottl-camlock/src/sys/cam/ata/ata_all.h#24 edit .. //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#60 edit .. //depot/projects/scottl-camlock/src/sys/cam/cam_ccb.h#33 edit .. //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#131 edit .. //depot/projects/scottl-camlock/src/sys/dev/ahci/ahci.c#83 edit .. //depot/projects/scottl-camlock/src/sys/dev/ahci/ahci.h#29 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-all.c#37 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-all.h#25 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-disk.c#20 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-lowlevel.c#16 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-pci.c#16 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-pci.h#25 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata-sata.c#9 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/ata_if.m#5 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/atapi-cd.c#18 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/atapi-fd.c#12 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/atapi-tape.c#12 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-acard.c#5 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-acerlabs.c#6 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-adaptec.c#5 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-ahci.c#12 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-amd.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-ati.c#6 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-cenatek.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-cypress.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-cyrix.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-highpoint.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-intel.c#11 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-ite.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-jmicron.c#6 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-marvell.c#16 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-micron.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-national.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-netcell.c#4 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-nvidia.c#9 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-promise.c#8 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-serverworks.c#9 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-siliconimage.c#11 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-sis.c#5 edit .. //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-via.c#6 edit .. //depot/projects/scottl-camlock/src/sys/dev/siis/siis.c#22 edit .. //depot/projects/scottl-camlock/src/sys/dev/siis/siis.h#7 edit Differences ... ==== //depot/projects/scottl-camlock/src/sbin/camcontrol/camcontrol.c#31 (text+ko) ==== @@ -960,10 +960,8 @@ struct ccb_trans_settings_ata *ata = &ccb->cts.xport_specific.ata; - if (ata->valid & CTS_ATA_VALID_PIOMODE) - speed = ata_mode2speed(ata->piomode); - if (ata->valid & CTS_ATA_VALID_DMAMODE) - speed = max(speed, ata_mode2speed(ata->dmamode)); + if (ata->valid & CTS_ATA_VALID_MODE) + speed = ata_mode2speed(ata->mode); } else if (ccb->cts.transport == XPORT_SATA) { struct ccb_trans_settings_sata *sata = &ccb->cts.xport_specific.sata; @@ -1010,10 +1008,8 @@ &ccb->cts.xport_specific.ata; printf(" ("); - if (ata->valid & CTS_ATA_VALID_PIOMODE) - printf("%s, ", ata_mode2string(ata->piomode)); - if (ata->valid & CTS_ATA_VALID_DMAMODE) - printf("%s, ", ata_mode2string(ata->dmamode)); + if (ata->valid & CTS_ATA_VALID_MODE) + printf("%s, ", ata_mode2string(ata->mode)); if (ata->valid & CTS_ATA_VALID_BYTECOUNT) printf("PIO size %dbytes", ata->bytecount); printf(")"); @@ -1024,10 +1020,8 @@ printf(" ("); if (sata->valid & CTS_SATA_VALID_REVISION) printf("SATA %d.x, ", sata->revision); - if (sata->valid & CTS_SATA_VALID_PIOMODE) - printf("%s, ", ata_mode2string(sata->piomode)); - if (sata->valid & CTS_SATA_VALID_DMAMODE) - printf("%s, ", ata_mode2string(sata->dmamode)); + if (sata->valid & CTS_SATA_VALID_MODE) + printf("%s, ", ata_mode2string(sata->mode)); if (sata->valid & CTS_SATA_VALID_BYTECOUNT) printf("PIO size %dbytes", sata->bytecount); printf(")"); @@ -2781,7 +2775,44 @@ "enabled" : "disabled"); } } + if (cts->transport == XPORT_ATA) { + struct ccb_trans_settings_ata *ata = + &cts->xport_specific.ata; + if ((ata->valid & CTS_ATA_VALID_MODE) != 0) { + fprintf(stdout, "%sATA mode: %s\n", pathstr, + ata_mode2string(ata->mode)); + } + if ((ata->valid & CTS_ATA_VALID_BYTECOUNT) != 0) { + fprintf(stdout, "%sPIO transaction length: %d\n", + pathstr, ata->bytecount); + } + } + if (cts->transport == XPORT_SATA) { + struct ccb_trans_settings_sata *sata = + &cts->xport_specific.sata; + + if ((sata->valid & CTS_SATA_VALID_REVISION) != 0) { + fprintf(stdout, "%sSATA revision: %d.x\n", pathstr, + sata->revision); + } + if ((sata->valid & CTS_SATA_VALID_MODE) != 0) { + fprintf(stdout, "%sATA mode: %s\n", pathstr, + ata_mode2string(sata->mode)); + } + if ((sata->valid & CTS_SATA_VALID_BYTECOUNT) != 0) { + fprintf(stdout, "%sPIO transaction length: %d\n", + pathstr, sata->bytecount); + } + if ((sata->valid & CTS_SATA_VALID_PM) != 0) { + fprintf(stdout, "%sPMP presence: %d\n", pathstr, + sata->pm_present); + } + if ((sata->valid & CTS_SATA_VALID_TAGS) != 0) { + fprintf(stdout, "%sNumber of tags: %d\n", pathstr, + sata->tags); + } + } if (cts->protocol == PROTO_SCSI) { struct ccb_trans_settings_scsi *scsi= &cts->proto_specific.scsi; ==== //depot/projects/scottl-camlock/src/sys/arm/mv/mv_sata.c#3 (text+ko) ==== @@ -136,7 +136,7 @@ static int sata_channel_begin_transaction(struct ata_request *request); static int sata_channel_end_transaction(struct ata_request *request); static int sata_channel_status(device_t dev); -static void sata_channel_setmode(device_t parent, device_t dev); +static int sata_channel_setmode(device_t dev, int target, int mode); static void sata_channel_reset(device_t dev); static void sata_channel_dmasetprd(void *xsc, bus_dma_segment_t *segs, int nsegs, int error); @@ -748,19 +748,13 @@ SATA_OUTL(sc, SATA_EDMA_IEMR(ch->unit), 0xFFFFFFFF); } -static void -sata_channel_setmode(device_t parent, device_t dev) +static int +sata_channel_setmode(device_t parent, int target, int mode) { - struct ata_device *atadev; - atadev = device_get_softc(dev); - /* Disable EDMA before using legacy registers */ sata_edma_ctrl(parent, 0); - - ata_sata_setmode(dev, ATA_PIO_MAX); - if (atadev->mode >= ATA_DMA) - ata_sata_setmode(dev, atadev->mode); + return (ata_sata_setmode(dev, mode)); } static void ==== //depot/projects/scottl-camlock/src/sys/cam/ata/ata_all.c#24 (text+ko) ==== @@ -501,27 +501,16 @@ } int -ata_max_piomode(struct ata_params *ap, int maxmode) +ata_max_mode(struct ata_params *ap, int maxmode) { if (maxmode == 0) - return (ata_max_pmode(ap)); - return (min(maxmode, ata_max_pmode(ap))); -} - -int -ata_max_dmamode(struct ata_params *ap, int maxmode) -{ - - if (maxmode == 0 && ata_max_umode(ap) > 0) - return (ata_max_umode(ap)); + maxmode = ATA_DMA_MAX; if (maxmode >= ATA_UDMA0 && ata_max_umode(ap) > 0) return (min(maxmode, ata_max_umode(ap))); - if (maxmode == 0 && ata_max_wmode(ap) > 0) - return (ata_max_wmode(ap)); - if (ata_max_wmode(ap) > 0) + if (maxmode >= ATA_WDMA0 && ata_max_wmode(ap) > 0) return (min(maxmode, ata_max_wmode(ap))); - return (-1); + return (min(maxmode, ata_max_pmode(ap))); } char * ==== //depot/projects/scottl-camlock/src/sys/cam/ata/ata_all.h#24 (text+ko) ==== @@ -113,8 +113,7 @@ int ata_max_pmode(struct ata_params *ap); int ata_max_wmode(struct ata_params *ap); int ata_max_umode(struct ata_params *ap); -int ata_max_piomode(struct ata_params *ap, int maxmode); -int ata_max_dmamode(struct ata_params *ap, int maxmode); +int ata_max_mode(struct ata_params *ap, int maxmode); char * ata_mode2string(int mode); u_int ata_mode2speed(int mode); ==== //depot/projects/scottl-camlock/src/sys/cam/ata/ata_xpt.c#60 (text+ko) ==== @@ -334,10 +334,9 @@ break; case PROBE_SETMODE: { - int piomode, dmamode, wantpio, wantdma, mode; + int mode, wantmode; - wantpio = 0; - wantdma = 0; + mode = 0; /* Fetch user modes from SIM. */ bzero(&cts, sizeof(cts)); xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL); @@ -345,35 +344,26 @@ cts.type = CTS_TYPE_USER_SETTINGS; xpt_action((union ccb *)&cts); if (path->device->transport == XPORT_ATA) { - if (cts.xport_specific.ata.valid & CTS_ATA_VALID_PIOMODE) - wantpio = cts.xport_specific.ata.piomode; - if (cts.xport_specific.ata.valid & CTS_ATA_VALID_DMAMODE) - wantdma = cts.xport_specific.ata.dmamode; + if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE) + mode = cts.xport_specific.ata.mode; } else { - if (cts.xport_specific.ata.valid & CTS_SATA_VALID_PIOMODE) - wantpio = cts.xport_specific.sata.piomode; - if (cts.xport_specific.ata.valid & CTS_SATA_VALID_DMAMODE) - wantdma = cts.xport_specific.sata.dmamode; + if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE) + mode = cts.xport_specific.sata.mode; } negotiate: /* Honor device capabilities. */ - wantpio = piomode = ata_max_piomode(ident_buf, wantpio); - wantdma = dmamode = ata_max_dmamode(ident_buf, wantdma); + wantmode = mode = ata_max_mode(ident_buf, mode); /* Report modes to SIM. */ bzero(&cts, sizeof(cts)); xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL); cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; cts.type = CTS_TYPE_CURRENT_SETTINGS; if (path->device->transport == XPORT_ATA) { - cts.xport_specific.ata.piomode = piomode; - cts.xport_specific.ata.dmamode = dmamode; - cts.xport_specific.ata.valid = - CTS_ATA_VALID_PIOMODE | CTS_ATA_VALID_DMAMODE; + cts.xport_specific.ata.mode = mode; + cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE; } else { - cts.xport_specific.sata.piomode = piomode; - cts.xport_specific.sata.dmamode = dmamode; - cts.xport_specific.sata.valid = - CTS_SATA_VALID_PIOMODE | CTS_SATA_VALID_DMAMODE; + cts.xport_specific.sata.mode = mode; + cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE; } xpt_action((union ccb *)&cts); /* Fetch user modes from SIM. */ @@ -383,23 +373,15 @@ cts.type = CTS_TYPE_CURRENT_SETTINGS; xpt_action((union ccb *)&cts); if (path->device->transport == XPORT_ATA) { - if (cts.xport_specific.ata.valid & CTS_ATA_VALID_PIOMODE) - piomode = cts.xport_specific.ata.piomode; - if (cts.xport_specific.ata.valid & CTS_ATA_VALID_DMAMODE) - dmamode = cts.xport_specific.ata.dmamode; + if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE) + mode = cts.xport_specific.ata.mode; } else { - if (cts.xport_specific.ata.valid & CTS_SATA_VALID_PIOMODE) - piomode = cts.xport_specific.sata.piomode; - if (cts.xport_specific.ata.valid & CTS_SATA_VALID_DMAMODE) - dmamode = cts.xport_specific.sata.dmamode; + if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE) + mode = cts.xport_specific.sata.mode; } /* If SIM disagree - renegotiate. */ - if (piomode != wantpio || dmamode != wantdma) + if (mode != wantmode) goto negotiate; - if (dmamode > 0) - mode = dmamode; - else - mode = piomode; cam_fill_ataio(ataio, 1, probedone, ==== //depot/projects/scottl-camlock/src/sys/cam/cam_ccb.h#33 (text+ko) ==== @@ -818,24 +818,20 @@ struct ccb_trans_settings_ata { u_int valid; /* Which fields to honor */ -#define CTS_ATA_VALID_PIOMODE 0x01 -#define CTS_ATA_VALID_DMAMODE 0x02 -#define CTS_ATA_VALID_BYTECOUNT 0x04 - int piomode; /* PIO mode */ - int dmamode; /* DMA mode */ +#define CTS_ATA_VALID_MODE 0x01 +#define CTS_ATA_VALID_BYTECOUNT 0x02 + int mode; /* Mode */ u_int bytecount; /* Length of PIO transaction */ }; struct ccb_trans_settings_sata { u_int valid; /* Which fields to honor */ -#define CTS_SATA_VALID_PIOMODE 0x01 -#define CTS_SATA_VALID_DMAMODE 0x02 -#define CTS_SATA_VALID_BYTECOUNT 0x04 -#define CTS_SATA_VALID_REVISION 0x08 -#define CTS_SATA_VALID_PM 0x10 -#define CTS_SATA_VALID_TAGS 0x20 - int piomode; /* Legacy PATA PIO mode */ - int dmamode; /* Legacy PATA DMA mode */ +#define CTS_SATA_VALID_MODE 0x01 +#define CTS_SATA_VALID_BYTECOUNT 0x02 +#define CTS_SATA_VALID_REVISION 0x04 +#define CTS_SATA_VALID_PM 0x08 +#define CTS_SATA_VALID_TAGS 0x10 + int mode; /* Legacy PATA mode */ u_int bytecount; /* Length of PIO transaction */ u_int revision; /* SATA revision */ u_int pm_present; /* PM is present (XPT->SIM) */ ==== //depot/projects/scottl-camlock/src/sys/cam/cam_xpt.c#131 (text+ko) ==== @@ -1144,10 +1144,8 @@ struct ccb_trans_settings_ata *ata = &cts.xport_specific.ata; - if (ata->valid & CTS_ATA_VALID_PIOMODE) - speed = ata_mode2speed(ata->piomode); - if (ata->valid & CTS_ATA_VALID_DMAMODE) - speed = max(speed, ata_mode2speed(ata->dmamode)); + if (ata->valid & CTS_ATA_VALID_MODE) + speed = ata_mode2speed(ata->mode); } if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) { struct ccb_trans_settings_sata *sata = @@ -1205,10 +1203,8 @@ &cts.xport_specific.ata; printf(" ("); - if (ata->valid & CTS_ATA_VALID_PIOMODE) - printf("%s, ", ata_mode2string(ata->piomode)); - if (ata->valid & CTS_ATA_VALID_DMAMODE) - printf("%s, ", ata_mode2string(ata->dmamode)); + if (ata->valid & CTS_ATA_VALID_MODE) + printf("%s, ", ata_mode2string(ata->mode)); if (ata->valid & CTS_ATA_VALID_BYTECOUNT) printf("PIO size %dbytes", ata->bytecount); printf(")"); @@ -1220,10 +1216,8 @@ printf(" ("); if (sata->valid & CTS_SATA_VALID_REVISION) printf("SATA %d.x, ", sata->revision); - if (sata->valid & CTS_SATA_VALID_PIOMODE) - printf("%s, ", ata_mode2string(sata->piomode)); - if (sata->valid & CTS_SATA_VALID_DMAMODE) - printf("%s, ", ata_mode2string(sata->dmamode)); + if (sata->valid & CTS_SATA_VALID_MODE) + printf("%s, ", ata_mode2string(sata->mode)); if (sata->valid & CTS_SATA_VALID_BYTECOUNT) printf("PIO size %dbytes", sata->bytecount); printf(")"); ==== //depot/projects/scottl-camlock/src/sys/dev/ahci/ahci.c#83 (text+ko) ==== @@ -787,10 +787,9 @@ callout_init_mtx(&ch->pm_timer, &ch->mtx, 0); for (i = 0; i < 16; i++) { ch->user[i].revision = 0; - ch->user[i].piomode = 0; - ch->user[i].dmamode = 0; + ch->user[i].mode = 0; ch->user[i].bytecount = 8192; - ch->user[i].tags = 2; + ch->user[i].tags = ch->numslots; ch->curr[i] = ch->user[i]; } /* Limit speed for my onboard JMicron external port. @@ -2149,10 +2148,8 @@ d = &ch->user[ccb->ccb_h.target_id]; if (cts->xport_specific.sata.valid & CTS_SATA_VALID_REVISION) d->revision = cts->xport_specific.sata.revision; - if (cts->xport_specific.sata.valid & CTS_SATA_VALID_PIOMODE) - d->piomode = cts->xport_specific.sata.piomode; - if (cts->xport_specific.sata.valid & CTS_SATA_VALID_DMAMODE) - d->dmamode = cts->xport_specific.sata.dmamode; + if (cts->xport_specific.sata.valid & CTS_SATA_VALID_MODE) + d->mode = cts->xport_specific.sata.mode; if (cts->xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT) d->bytecount = min(8192, cts->xport_specific.sata.bytecount); if (cts->xport_specific.sata.valid & CTS_SATA_VALID_TAGS) @@ -2190,14 +2187,12 @@ cts->xport_specific.sata.valid |= CTS_SATA_VALID_REVISION; } - } else if (d->revision) { + } else { cts->xport_specific.sata.revision = d->revision; cts->xport_specific.sata.valid |= CTS_SATA_VALID_REVISION; } - cts->xport_specific.sata.piomode = d->piomode; - cts->xport_specific.sata.valid |= CTS_SATA_VALID_PIOMODE; - cts->xport_specific.sata.dmamode = d->dmamode; - cts->xport_specific.sata.valid |= CTS_SATA_VALID_DMAMODE; + cts->xport_specific.sata.mode = d->mode; + cts->xport_specific.sata.valid |= CTS_SATA_VALID_MODE; cts->xport_specific.sata.bytecount = d->bytecount; cts->xport_specific.sata.valid |= CTS_SATA_VALID_BYTECOUNT; cts->xport_specific.sata.pm_present = ch->pm_present; ==== //depot/projects/scottl-camlock/src/sys/dev/ahci/ahci.h#29 (text+ko) ==== @@ -342,8 +342,7 @@ struct ahci_device { u_int revision; - int piomode; - int dmamode; + int mode; u_int bytecount; u_int tags; }; ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-all.c#37 (text+ko) ==== @@ -152,8 +152,7 @@ TASK_INIT(&ch->conntask, 0, ata_conn_event, dev); #ifdef ATA_CAM for (i = 0; i < 16; i++) { - ch->user[i].piomode = 0; - ch->user[i].dmamode = 0; + ch->user[i].mode = 0; ch->user[i].bytecount = 8192; ch->curr[i] = ch->user[i]; } @@ -514,6 +513,52 @@ #endif } +void +ata_print_cable(device_t dev, u_int8_t *who) +{ + device_printf(dev, + "DMA limited to UDMA33, %s found non-ATA66 cable\n", who); +} + +int +ata_check_80pin(device_t dev, int mode) +{ + struct ata_device *atadev = device_get_softc(dev); + + if (!ata_dma_check_80pin) { + if (bootverbose) + device_printf(dev, "Skipping 80pin cable check\n"); + return mode; + } + + if (mode > ATA_UDMA2 && !(atadev->param.hwres & ATA_CABLE_ID)) { + ata_print_cable(dev, "device"); + mode = ATA_UDMA2; + } + return mode; +} + +void +ata_setmode(device_t dev) +{ + struct ata_channel *ch = device_get_softc(device_get_parent(dev)); + struct ata_device *atadev = device_get_softc(dev); + int error, mode, pmode; + + mode = atadev->mode; + do { + pmode = mode = ata_limit_mode(dev, mode, ATA_DMA_MAX); + mode = ATA_SETMODE(device_get_parent(dev), atadev->unit, mode); + if ((ch->flags & (ATA_CHECKS_CABLE | ATA_SATA)) == 0) + mode = ata_check_80pin(dev, mode); + } while (pmode != mode); /* Interate till successfull negotiation. */ + error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); + if (bootverbose) + device_printf(dev, "%ssetting %s\n", + (error) ? "FAILURE " : "", ata_mode2str(mode)); + atadev->mode = mode; +} + /* * device related interfaces */ @@ -682,7 +727,7 @@ case IOCATASMODE: atadev->mode = *mode; - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); return 0; case IOCATAGMODE: @@ -1418,10 +1463,14 @@ d = &ch->user[ccb->ccb_h.target_id]; // if (cts->xport_specific.sata.valid & CTS_SATA_VALID_REVISION) // d->revision = cts->xport_specific.sata.revision; - if (cts->xport_specific.ata.valid & CTS_ATA_VALID_PIOMODE) - d->piomode = cts->xport_specific.ata.piomode; - if (cts->xport_specific.ata.valid & CTS_ATA_VALID_DMAMODE) - d->dmamode = cts->xport_specific.ata.dmamode; + if (cts->xport_specific.ata.valid & CTS_ATA_VALID_MODE) { + if (cts->type == CTS_TYPE_CURRENT_SETTINGS) { + d->mode = ATA_SETMODE(ch->dev, + ccb->ccb_h.target_id, + cts->xport_specific.ata.mode); + } else + d->mode = cts->xport_specific.ata.mode; + } if (cts->xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT) d->bytecount = min(8192, cts->xport_specific.ata.bytecount); ccb->ccb_h.status = CAM_REQ_CMP; @@ -1441,10 +1490,8 @@ cts->protocol_version = PROTO_VERSION_UNSPECIFIED; cts->transport = XPORT_ATA; cts->transport_version = XPORT_VERSION_UNSPECIFIED; - cts->xport_specific.ata.piomode = d->piomode; - cts->xport_specific.ata.valid |= CTS_ATA_VALID_PIOMODE; - cts->xport_specific.ata.dmamode = d->dmamode; - cts->xport_specific.ata.valid |= CTS_ATA_VALID_DMAMODE; + cts->xport_specific.ata.mode = d->mode; + cts->xport_specific.ata.valid |= CTS_ATA_VALID_MODE; cts->xport_specific.ata.bytecount = d->bytecount; cts->xport_specific.ata.valid |= CTS_ATA_VALID_BYTECOUNT; ccb->ccb_h.status = CAM_REQ_CMP; ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-all.h#25 (text+ko) ==== @@ -537,8 +537,7 @@ #ifdef ATA_CAM struct ata_cam_device { u_int revision; - int piomode; - int dmamode; + int mode; u_int bytecount; }; #endif @@ -559,6 +558,9 @@ #define ATA_ATAPI_DMA_RO 0x04 #define ATA_NO_48BIT_DMA 0x08 #define ATA_ALWAYS_DMASTAT 0x10 +#define ATA_CHECKS_CABLE 0x20 +#define ATA_NO_ATAPI_DMA 0x40 +#define ATA_SATA 0x80 int pm_level; /* power management level */ int devices; /* what is present */ @@ -624,6 +626,9 @@ int ata_wmode(struct ata_params *ap); int ata_umode(struct ata_params *ap); int ata_limit_mode(device_t dev, int mode, int maxmode); +void ata_setmode(device_t dev); +void ata_print_cable(device_t dev, u_int8_t *who); +int ata_check_80pin(device_t dev, int mode); #ifdef ATA_CAM void ata_cam_begin_transaction(device_t dev, union ccb *ccb); void ata_cam_end_transaction(device_t dev, struct ata_request *request); @@ -657,7 +662,7 @@ int ata_sata_scr_read(struct ata_channel *ch, int port, int reg, uint32_t *val); int ata_sata_scr_write(struct ata_channel *ch, int port, int reg, uint32_t val); int ata_sata_phy_reset(device_t dev, int port, int quick); -void ata_sata_setmode(device_t dev, int mode); +int ata_sata_setmode(device_t dev, int target, int mode); int ata_request2fis_h2d(struct ata_request *request, u_int8_t *fis); void ata_pm_identify(device_t dev); ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-disk.c#20 (text+ko) ==== @@ -381,7 +381,7 @@ { struct ata_device *atadev = device_get_softc(dev); - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); /* enable readahead caching */ if (atadev->param.support.command1 & ATA_SUPPORT_LOOKAHEAD) ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-lowlevel.c#16 (text+ko) ==== @@ -82,6 +82,9 @@ ATA_DEBUG_RQ(request, "begin transaction"); /* disable ATAPI DMA writes if HW doesn't support it */ + if ((ch->flags & ATA_NO_ATAPI_DMA) && + (request->flags & ATA_R_ATAPI) == ATA_R_ATAPI) + request->flags &= ~ATA_R_DMA; if ((ch->flags & ATA_ATAPI_DMA_RO) && ((request->flags & (ATA_R_ATAPI | ATA_R_DMA | ATA_R_WRITE)) == (ATA_R_ATAPI | ATA_R_DMA | ATA_R_WRITE))) ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-pci.c#16 (text+ko) ==== @@ -55,10 +55,6 @@ /* misc defines */ #define IOMASK 0xfffffffc -/* local prototypes */ -static int ata_generic_chipinit(device_t dev); -static void ata_generic_setmode(device_t dev, int mode); - /* * generic PCI ATA device probe */ @@ -374,18 +370,14 @@ } } -static void -ata_generic_setmode(device_t dev, int mode) +int +ata_generic_setmode(device_t dev, int target, int mode) { - struct ata_device *atadev = device_get_softc(dev); - mode = ata_limit_mode(dev, mode, ATA_UDMA2); - mode = ata_check_80pin(dev, mode); - if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) - atadev->mode = mode; + return (min(mode, ATA_UDMA2)); } -static int +int ata_generic_chipinit(device_t dev) { struct ata_pci_controller *ctlr = device_get_softc(dev); @@ -708,16 +700,15 @@ ata_generic_reset(dev); } -static void -ata_pcichannel_setmode(device_t parent, device_t dev) +static int +ata_pcichannel_setmode(device_t dev, int target, int mode) { - struct ata_pci_controller *ctlr = device_get_softc(GRANDPARENT(dev)); - struct ata_device *atadev = device_get_softc(dev); - int mode = atadev->mode; + struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev)); - ctlr->setmode(dev, ATA_PIO_MAX); - if (mode >= ATA_DMA) - ctlr->setmode(dev, mode); + if (ctlr->setmode) + return (ctlr->setmode(dev, target, mode)); + else + return (ata_generic_setmode(dev, target, mode)); } static device_method_t ata_pcichannel_methods[] = { @@ -859,31 +850,6 @@ return (NULL); } -void -ata_print_cable(device_t dev, u_int8_t *who) -{ - device_printf(dev, - "DMA limited to UDMA33, %s found non-ATA66 cable\n", who); -} - -int -ata_check_80pin(device_t dev, int mode) -{ - struct ata_device *atadev = device_get_softc(dev); - - if (!ata_dma_check_80pin) { - if (bootverbose) - device_printf(dev, "Skipping 80pin cable check\n"); - return mode; - } - - if (mode > ATA_UDMA2 && !(atadev->param.hwres & ATA_CABLE_ID)) { - ata_print_cable(dev, "device"); - mode = ATA_UDMA2; - } - return mode; -} - char * ata_pcivendor2str(device_t dev) { ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-pci.h#25 (text+ko) ==== @@ -63,7 +63,7 @@ int (*ch_resume)(device_t); int (*locking)(device_t, int); void (*reset)(device_t); - void (*setmode)(device_t, int); + int (*setmode)(device_t, int, int); struct { void (*function)(void *); void *argument; @@ -506,12 +506,12 @@ char *ata_pcivendor2str(device_t dev); int ata_legacy(device_t); void ata_generic_intr(void *data); +int ata_generic_chipinit(device_t dev); +int ata_generic_setmode(device_t dev, int target, int mode); int ata_setup_interrupt(device_t dev, void *intr_func); void ata_set_desc(device_t dev); struct ata_chip_id *ata_match_chip(device_t dev, struct ata_chip_id *index); struct ata_chip_id *ata_find_chip(device_t dev, struct ata_chip_id *index, int slot); -void ata_print_cable(device_t dev, u_int8_t *who); -int ata_check_80pin(device_t dev, int mode); int ata_mode2idx(int mode); /* global prototypes from chipsets/ata-*.c */ ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata-sata.c#9 (text+ko) ==== @@ -209,38 +209,20 @@ return 0; } -void -ata_sata_setmode(device_t dev, int mode) +int +ata_sata_setmode(device_t dev, int target, int mode) { - struct ata_device *atadev = device_get_softc(dev); - - /* - * if we detect that the device isn't a real SATA device we limit - * the transfer mode to UDMA5/ATA100. - * this works around the problems some devices has with the - * Marvell 88SX8030 SATA->PATA converters and UDMA6/ATA133. - */ - if (atadev->param.satacapabilities != 0x0000 && - atadev->param.satacapabilities != 0xffff) { - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); - /* on some drives we need to set the transfer mode */ - ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, - ata_limit_mode(dev, mode, ATA_UDMA6)); - /* query SATA STATUS for the speed */ - if (ch->r_io[ATA_SSTATUS].res && +/* if (ch->r_io[ATA_SSTATUS].res && ((ATA_IDX_INL(ch, ATA_SSTATUS) & ATA_SS_CONWELL_MASK) == ATA_SS_CONWELL_GEN2)) atadev->mode = ATA_SA300; else atadev->mode = ATA_SA150; - } - else { - mode = ata_limit_mode(dev, mode, ATA_UDMA5); - if (!ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode)) - atadev->mode = mode; - } +*/ + mode = min(mode, ATA_UDMA5); + return (mode); } int ==== //depot/projects/scottl-camlock/src/sys/dev/ata/ata_if.m#5 (text+ko) ==== @@ -57,17 +57,19 @@ }; CODE { - static void ata_null_setmode(device_t parent, device_t dev) + static int ata_null_setmode(device_t dev, int target, int mode) { - struct ata_device *atadev = device_get_softc(dev); - atadev->mode = ata_limit_mode(dev, atadev->mode, ATA_PIO_MAX); + if (mode > ATA_PIO_MAX) + return (ATA_PIO_MAX); + return (mode); } }; -METHOD void setmode { - device_t channel; +METHOD int setmode { device_t dev; -} DEFAULT ata_null_setmode;; + int target; + int mode; +} DEFAULT ata_null_setmode; METHOD void reset { device_t channel; ==== //depot/projects/scottl-camlock/src/sys/dev/ata/atapi-cd.c#18 (text+ko) ==== @@ -126,7 +126,7 @@ } cdp->block_size = 2048; device_set_ivars(dev, cdp); - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); ata_controlcmd(dev, ATA_DEVICE_RESET, 0, 0, 0); acd_get_cap(dev); g_post_event(acd_geom_attach, dev, M_WAITOK, NULL); @@ -163,7 +163,7 @@ if (!(ch->devices & (ATA_ATAPI_MASTER << atadev->unit))) return 1; - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); return 0; } ==== //depot/projects/scottl-camlock/src/sys/dev/ata/atapi-fd.c#12 (text+ko) ==== @@ -85,7 +85,7 @@ return ENOMEM; } device_set_ivars(dev, fdp); - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); if (afd_sense(dev)) { device_set_ivars(dev, NULL); @@ -152,7 +152,7 @@ if (!(ch->devices & (ATA_ATAPI_MASTER << atadev->unit))) return 1; - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); return 0; } ==== //depot/projects/scottl-camlock/src/sys/dev/ata/atapi-tape.c#12 (text+ko) ==== @@ -111,7 +111,7 @@ return ENOMEM; } device_set_ivars(dev, stp); - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); if (ast_sense(dev)) { device_set_ivars(dev, NULL); @@ -193,7 +193,7 @@ if (!(ch->devices & (ATA_ATAPI_MASTER << atadev->unit))) return 1; - ATA_SETMODE(device_get_parent(dev), dev); + ata_setmode(dev); return 0; } ==== //depot/projects/scottl-camlock/src/sys/dev/ata/chipsets/ata-acard.c#5 (text+ko) ==== @@ -61,8 +61,8 @@ static int ata_acard_chipinit(device_t dev); static int ata_acard_ch_attach(device_t dev); static int ata_acard_status(device_t dev); -static void ata_acard_850_setmode(device_t dev, int mode); -static void ata_acard_86X_setmode(device_t dev, int mode); +static int ata_acard_850_setmode(device_t dev, int target, int mode); +static int ata_acard_86X_setmode(device_t dev, int target, int mode); static int ata_serialize(device_t dev, int flags); static void ata_serialize_init(struct ata_serialize *serial); @@ -130,6 +130,7 @@ return ENXIO; ch->hw.status = ata_acard_status; + ch->flags |= ATA_NO_ATAPI_DMA; return 0; } @@ -162,79 +163,52 @@ return 1; } -static void -ata_acard_850_setmode(device_t dev, int mode) +static int +ata_acard_850_setmode(device_t dev, int target, int mode) { - device_t gparent = GRANDPARENT(dev); - struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); - struct ata_device *atadev = device_get_softc(dev); - int devno = (ch->unit << 1) + atadev->unit; - int error; + device_t parent = device_get_parent(dev); + struct ata_pci_controller *ctlr = device_get_softc(parent); + struct ata_channel *ch = device_get_softc(dev); + int devno = (ch->unit << 1) + target; - mode = ata_limit_mode(dev, mode, - ata_atapi(dev) ? ATA_PIO_MAX : ctlr->chip->max_dma); - + mode = min(mode, ctlr->chip->max_dma); /* XXX SOS missing WDMA0+1 + PIO modes */ if (mode >= ATA_WDMA2) { - error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); - if (bootverbose) - device_printf(dev, "%ssetting %s on %s chip\n", - (error) ? "FAILURE " : "", - ata_mode2str(mode), ctlr->chip->text); - if (!error) { - u_int8_t reg54 = pci_read_config(gparent, 0x54, 1); + u_int8_t reg54 = pci_read_config(parent, 0x54, 1); reg54 &= ~(0x03 << (devno << 1)); if (mode >= ATA_UDMA0) reg54 |= (((mode & ATA_MODE_MASK) + 1) << (devno << 1)); - pci_write_config(gparent, 0x54, reg54, 1); - pci_write_config(gparent, 0x4a, 0xa6, 1); - pci_write_config(gparent, 0x40 + (devno << 1), 0x0301, 2); - atadev->mode = mode; - return; - } + pci_write_config(parent, 0x54, reg54, 1); + pci_write_config(parent, 0x4a, 0xa6, 1); + pci_write_config(parent, 0x40 + (devno << 1), 0x0301, 2); } /* we could set PIO mode timings, but we assume the BIOS did that */ + return (mode); } -static void -ata_acard_86X_setmode(device_t dev, int mode) +static int +ata_acard_86X_setmode(device_t dev, int target, int mode) { - device_t gparent = GRANDPARENT(dev); - struct ata_pci_controller *ctlr = device_get_softc(gparent); - struct ata_channel *ch = device_get_softc(device_get_parent(dev)); - struct ata_device *atadev = device_get_softc(dev); - int devno = (ch->unit << 1) + atadev->unit; - int error; + device_t parent = device_get_parent(dev); + struct ata_pci_controller *ctlr = device_get_softc(parent); + struct ata_channel *ch = device_get_softc(dev); + int devno = (ch->unit << 1) + target; - - mode = ata_limit_mode(dev, mode, - ata_atapi(dev) ? ATA_PIO_MAX : ctlr->chip->max_dma); - - mode = ata_check_80pin(dev, mode); - - /* XXX SOS missing WDMA0+1 + PIO modes */ - if (mode >= ATA_WDMA2) { - error = ata_controlcmd(dev, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode); - if (bootverbose) - device_printf(dev, "%ssetting %s on %s chip\n", - (error) ? "FAILURE " : "", - ata_mode2str(mode), ctlr->chip->text); - if (!error) { - u_int16_t reg44 = pci_read_config(gparent, 0x44, 2); + mode = min(mode, ctlr->chip->max_dma); + /* XXX SOS missing WDMA0+1 + PIO modes */ + if (mode >= ATA_WDMA2) { + u_int16_t reg44 = pci_read_config(parent, 0x44, 2); - reg44 &= ~(0x000f << (devno << 2)); - if (mode >= ATA_UDMA0) >>> TRUNCATED FOR MAIL (1000 lines) <<<