From owner-svn-src-stable@FreeBSD.ORG Thu Jun 6 11:47:55 2013 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 311DFE2B; Thu, 6 Jun 2013 11:47:55 +0000 (UTC) (envelope-from smh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 22F941B4F; Thu, 6 Jun 2013 11:47:55 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r56Bltu1023570; Thu, 6 Jun 2013 11:47:55 GMT (envelope-from smh@svn.freebsd.org) Received: (from smh@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r56BlshS023569; Thu, 6 Jun 2013 11:47:55 GMT (envelope-from smh@svn.freebsd.org) Message-Id: <201306061147.r56BlshS023569@svn.freebsd.org> From: Steven Hartland Date: Thu, 6 Jun 2013 11:47:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org Subject: svn commit: r251467 - stable/8/sys/cam/ata X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Jun 2013 11:47:55 -0000 Author: smh Date: Thu Jun 6 11:47:54 2013 New Revision: 251467 URL: http://svnweb.freebsd.org/changeset/base/251467 Log: MFC r249934: Updated TRIM calculations in cam/ata to be based off ATA_DSM_* defines Modified: stable/8/sys/cam/ata/ata_da.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/cam/ (props changed) Modified: stable/8/sys/cam/ata/ata_da.c ============================================================================== --- stable/8/sys/cam/ata/ata_da.c Thu Jun 6 11:41:22 2013 (r251466) +++ stable/8/sys/cam/ata/ata_da.c Thu Jun 6 11:47:54 2013 (r251467) @@ -117,10 +117,10 @@ struct disk_params { }; #define TRIM_MAX_BLOCKS 8 -#define TRIM_MAX_RANGES (TRIM_MAX_BLOCKS * 64) +#define TRIM_MAX_RANGES (TRIM_MAX_BLOCKS * ATA_DSM_BLK_RANGES) #define TRIM_MAX_BIOS (TRIM_MAX_RANGES * 4) struct trim_request { - uint8_t data[TRIM_MAX_RANGES * 8]; + uint8_t data[TRIM_MAX_RANGES * ATA_DSM_RANGE_SIZE]; struct bio *bps[TRIM_MAX_BIOS]; }; @@ -1056,8 +1056,8 @@ adaregister(struct cam_periph *periph, v softc->trim_max_ranges = TRIM_MAX_RANGES; if (cgd->ident_data.max_dsm_blocks != 0) { softc->trim_max_ranges = - min(cgd->ident_data.max_dsm_blocks * 64, - softc->trim_max_ranges); + min(cgd->ident_data.max_dsm_blocks * + ATA_DSM_BLK_RANGES, softc->trim_max_ranges); } } if (cgd->ident_data.support.command2 & ATA_SUPPORT_CFA) @@ -1131,10 +1131,12 @@ adaregister(struct cam_periph *periph, v softc->disk->d_flags = 0; if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; - if ((softc->flags & ADA_FLAG_CAN_TRIM) || - ((softc->flags & ADA_FLAG_CAN_CFA) && - !(softc->flags & ADA_FLAG_CAN_48BIT))) + if (softc->flags & ADA_FLAG_CAN_TRIM) { softc->disk->d_flags |= DISKFLAG_CANDELETE; + } else if ((softc->flags & ADA_FLAG_CAN_CFA) && + !(softc->flags & ADA_FLAG_CAN_48BIT)) { + softc->disk->d_flags |= DISKFLAG_CANDELETE; + } strlcpy(softc->disk->d_ident, cgd->serial_num, MIN(sizeof(softc->disk->d_ident), cgd->serial_num_len + 1)); @@ -1284,9 +1286,9 @@ adastart(struct cam_periph *periph, unio /* Try to extend the previous range. */ if (lba == lastlba) { - c = min(count, 0xffff - lastcount); + c = min(count, ATA_DSM_RANGE_MAX - lastcount); lastcount += c; - off = (ranges - 1) * 8; + off = (ranges - 1) * ATA_DSM_RANGE_SIZE; req->data[off + 6] = lastcount & 0xff; req->data[off + 7] = (lastcount >> 8) & 0xff; @@ -1295,8 +1297,8 @@ adastart(struct cam_periph *periph, unio } while (count > 0) { - c = min(count, 0xffff); - off = ranges * 8; + c = min(count, ATA_DSM_RANGE_MAX); + off = ranges * ATA_DSM_RANGE_SIZE; req->data[off + 0] = lba & 0xff; req->data[off + 1] = (lba >> 8) & 0xff; req->data[off + 2] = (lba >> 16) & 0xff; @@ -1309,6 +1311,11 @@ adastart(struct cam_periph *periph, unio count -= c; lastcount = c; ranges++; + /* + * Its the caller's responsibility to ensure the + * request will fit so we don't need to check for + * overrun here + */ } lastlba = lba; req->bps[bps++] = bp1; @@ -1316,7 +1323,8 @@ adastart(struct cam_periph *periph, unio if (bps >= TRIM_MAX_BIOS || bp1 == NULL || bp1->bio_bcount / softc->params.secsize > - (softc->trim_max_ranges - ranges) * 0xffff) + (softc->trim_max_ranges - ranges) * + ATA_DSM_RANGE_MAX) break; } while (1); cam_fill_ataio(ataio, @@ -1325,10 +1333,12 @@ adastart(struct cam_periph *periph, unio CAM_DIR_OUT, 0, req->data, - ((ranges + 63) / 64) * 512, + ((ranges + ATA_DSM_BLK_RANGES - 1) / + ATA_DSM_BLK_RANGES) * ATA_DSM_BLK_SIZE, ada_default_timeout * 1000); ata_48bit_cmd(ataio, ATA_DATA_SET_MANAGEMENT, - ATA_DSM_TRIM, 0, (ranges + 63) / 64); + ATA_DSM_TRIM, 0, (ranges + ATA_DSM_BLK_RANGES - + 1) / ATA_DSM_BLK_RANGES); start_ccb->ccb_h.ccb_state = ADA_CCB_TRIM; goto out; }