Sun May 15 15:37:38 2016 UTC ()
Use _align(2) workaround for PR kern/51141. This fixes odd CD length
reporting.


(reinoud)
diff -r1.330 -r1.331 src/sys/dev/scsipi/cd.c

cvs diff -r1.330 -r1.331 src/sys/dev/scsipi/cd.c (expand / switch to unified diff)

--- src/sys/dev/scsipi/cd.c 2015/04/26 15:15:20 1.330
+++ src/sys/dev/scsipi/cd.c 2016/05/15 15:37:38 1.331
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cd.c,v 1.330 2015/04/26 15:15:20 mlelstv Exp $ */ 1/* $NetBSD: cd.c,v 1.331 2016/05/15 15:37:38 reinoud Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation, 4 * Copyright (c) 1998, 2001, 2003, 2004, 2005, 2008 The NetBSD Foundation,
5 * Inc. All rights reserved. 5 * Inc. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum. 8 * by Charles M. Hannum.
9 * 9 *
10 * MMC framework implemented and contributed to the NetBSD Foundation by 10 * MMC framework implemented and contributed to the NetBSD Foundation by
11 * Reinoud Zandijk. 11 * Reinoud Zandijk.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -40,27 +40,27 @@ @@ -40,27 +40,27 @@
40 * Mellon University, makes this software available to CMU to distribute 40 * Mellon University, makes this software available to CMU to distribute
41 * or use in any manner that they see fit as long as this message is kept with 41 * or use in any manner that they see fit as long as this message is kept with
42 * the software. For this reason TFS also grants any other persons or 42 * the software. For this reason TFS also grants any other persons or
43 * organisations permission to use or modify this software. 43 * organisations permission to use or modify this software.
44 * 44 *
45 * TFS supplies this software to be publicly redistributed 45 * TFS supplies this software to be publicly redistributed
46 * on the understanding that TFS is not responsible for the correct 46 * on the understanding that TFS is not responsible for the correct
47 * functioning of this software in any circumstances. 47 * functioning of this software in any circumstances.
48 * 48 *
49 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 49 * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992
50 */ 50 */
51 51
52#include <sys/cdefs.h> 52#include <sys/cdefs.h>
53__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.330 2015/04/26 15:15:20 mlelstv Exp $"); 53__KERNEL_RCSID(0, "$NetBSD: cd.c,v 1.331 2016/05/15 15:37:38 reinoud Exp $");
54 54
55#include <sys/param.h> 55#include <sys/param.h>
56#include <sys/systm.h> 56#include <sys/systm.h>
57#include <sys/kernel.h> 57#include <sys/kernel.h>
58#include <sys/file.h> 58#include <sys/file.h>
59#include <sys/stat.h> 59#include <sys/stat.h>
60#include <sys/ioctl.h> 60#include <sys/ioctl.h>
61#include <sys/buf.h> 61#include <sys/buf.h>
62#include <sys/bufq.h> 62#include <sys/bufq.h>
63#include <sys/uio.h> 63#include <sys/uio.h>
64#include <sys/malloc.h> 64#include <sys/malloc.h>
65#include <sys/errno.h> 65#include <sys/errno.h>
66#include <sys/device.h> 66#include <sys/device.h>
@@ -1789,29 +1789,29 @@ cdgetdisklabel(struct cd_softc *cd) @@ -1789,29 +1789,29 @@ cdgetdisklabel(struct cd_softc *cd)
1789 * we count. 1789 * we count.
1790 */ 1790 */
1791static int 1791static int
1792read_cd_capacity(struct scsipi_periph *periph, uint32_t *blksize, u_long *last_lba) 1792read_cd_capacity(struct scsipi_periph *periph, uint32_t *blksize, u_long *last_lba)
1793{ 1793{
1794 struct scsipi_read_cd_capacity cap_cmd; 1794 struct scsipi_read_cd_capacity cap_cmd;
1795 /* 1795 /*
1796 * XXX: see PR 48550 and PR 48754: 1796 * XXX: see PR 48550 and PR 48754:
1797 * the ahcisata(4) driver can not deal with unaligned 1797 * the ahcisata(4) driver can not deal with unaligned
1798 * data, so align this "a bit" 1798 * data, so align this "a bit"
1799 */ 1799 */
1800 struct scsipi_read_cd_cap_data cap __aligned(2); 1800 struct scsipi_read_cd_cap_data cap __aligned(2);
1801 struct scsipi_read_discinfo di_cmd; 1801 struct scsipi_read_discinfo di_cmd;
1802 struct scsipi_read_discinfo_data di; 1802 struct scsipi_read_discinfo_data di __aligned(2);
1803 struct scsipi_read_trackinfo ti_cmd; 1803 struct scsipi_read_trackinfo ti_cmd;
1804 struct scsipi_read_trackinfo_data ti; 1804 struct scsipi_read_trackinfo_data ti __aligned(2);
1805 uint32_t track_start, track_size; 1805 uint32_t track_start, track_size;
1806 int error, flags, msb, lsb, last_track; 1806 int error, flags, msb, lsb, last_track;
1807 1807
1808 /* if the device doesn't grok capacity, return the dummies */ 1808 /* if the device doesn't grok capacity, return the dummies */
1809 if (periph->periph_quirks & PQUIRK_NOCAPACITY) 1809 if (periph->periph_quirks & PQUIRK_NOCAPACITY)
1810 return 0; 1810 return 0;
1811 1811
1812 /* first try read CD capacity for blksize and last recorded lba */ 1812 /* first try read CD capacity for blksize and last recorded lba */
1813 /* issue the cd capacity request */ 1813 /* issue the cd capacity request */
1814 flags = XS_CTL_DATA_IN; 1814 flags = XS_CTL_DATA_IN;
1815 memset(&cap_cmd, 0, sizeof(cap_cmd)); 1815 memset(&cap_cmd, 0, sizeof(cap_cmd));
1816 memset(&cap, 0, sizeof(cap)); 1816 memset(&cap, 0, sizeof(cap));
1817 cap_cmd.opcode = READ_CD_CAPACITY; 1817 cap_cmd.opcode = READ_CD_CAPACITY;
@@ -2976,27 +2976,27 @@ mmc_getdiscinfo_dvdrom(struct scsipi_per @@ -2976,27 +2976,27 @@ mmc_getdiscinfo_dvdrom(struct scsipi_per
2976 /* TODO how to handle disc_barcode and disc_id */ 2976 /* TODO how to handle disc_barcode and disc_id */
2977 /* done */ 2977 /* done */
2978 return 0; 2978 return 0;
2979} 2979}
2980 2980
2981static int 2981static int
2982mmc_getdiscinfo(struct scsipi_periph *periph, 2982mmc_getdiscinfo(struct scsipi_periph *periph,
2983 struct mmc_discinfo *mmc_discinfo) 2983 struct mmc_discinfo *mmc_discinfo)
2984{ 2984{
2985 struct scsipi_get_configuration gc_cmd; 2985 struct scsipi_get_configuration gc_cmd;
2986 struct scsipi_get_conf_data *gc; 2986 struct scsipi_get_conf_data *gc;
2987 struct scsipi_get_conf_feature *gcf; 2987 struct scsipi_get_conf_feature *gcf;
2988 struct scsipi_read_discinfo di_cmd; 2988 struct scsipi_read_discinfo di_cmd;
2989 struct scsipi_read_discinfo_data di; 2989 struct scsipi_read_discinfo_data di __aligned(2);
2990 const uint32_t buffer_size = 1024; 2990 const uint32_t buffer_size = 1024;
2991 uint32_t feat_tbl_len, pos; 2991 uint32_t feat_tbl_len, pos;
2992 u_long last_lba = 0; 2992 u_long last_lba = 0;
2993 uint8_t *buffer, *fpos; 2993 uint8_t *buffer, *fpos;
2994 int feature, last_feature, features_len, feature_cur, feature_len; 2994 int feature, last_feature, features_len, feature_cur, feature_len;
2995 int lsb, msb, error, flags; 2995 int lsb, msb, error, flags;
2996 2996
2997 feat_tbl_len = buffer_size; 2997 feat_tbl_len = buffer_size;
2998 2998
2999 buffer = malloc(buffer_size, M_TEMP, M_WAITOK); 2999 buffer = malloc(buffer_size, M_TEMP, M_WAITOK);
3000 3000
3001 /* initialise structure */ 3001 /* initialise structure */
3002 memset(mmc_discinfo, 0, sizeof(struct mmc_discinfo)); 3002 memset(mmc_discinfo, 0, sizeof(struct mmc_discinfo));
@@ -3492,29 +3492,29 @@ mmc_gettrackinfo_dvdrom(struct scsipi_pe @@ -3492,29 +3492,29 @@ mmc_gettrackinfo_dvdrom(struct scsipi_pe
3492 trackinfo->track_size = track_size; 3492 trackinfo->track_size = track_size;
3493 trackinfo->last_recorded = 0; 3493 trackinfo->last_recorded = 0;
3494 3494
3495out: 3495out:
3496 free(buffer, M_TEMP); 3496 free(buffer, M_TEMP);
3497 return error; 3497 return error;
3498} 3498}
3499 3499
3500static int 3500static int
3501mmc_gettrackinfo(struct scsipi_periph *periph,  3501mmc_gettrackinfo(struct scsipi_periph *periph,
3502 struct mmc_trackinfo *trackinfo) 3502 struct mmc_trackinfo *trackinfo)
3503{ 3503{
3504 struct scsipi_read_trackinfo ti_cmd; 3504 struct scsipi_read_trackinfo ti_cmd;
3505 struct scsipi_read_trackinfo_data ti; 3505 struct scsipi_read_trackinfo_data ti __aligned(2);
3506 struct scsipi_get_configuration gc_cmd; 3506 struct scsipi_get_configuration gc_cmd;
3507 struct scsipi_get_conf_data gc; 3507 struct scsipi_get_conf_data gc __aligned(2);
3508 int error, flags; 3508 int error, flags;
3509 int mmc_profile; 3509 int mmc_profile;
3510 3510
3511 /* set up SCSI call with track number from trackinfo.tracknr */ 3511 /* set up SCSI call with track number from trackinfo.tracknr */
3512 flags = XS_CTL_DATA_IN | XS_CTL_SILENT; 3512 flags = XS_CTL_DATA_IN | XS_CTL_SILENT;
3513 memset(&ti_cmd, 0, sizeof(ti_cmd)); 3513 memset(&ti_cmd, 0, sizeof(ti_cmd));
3514 ti_cmd.opcode = READ_TRACKINFO; 3514 ti_cmd.opcode = READ_TRACKINFO;
3515 ti_cmd.addr_type = READ_TRACKINFO_ADDR_TRACK; 3515 ti_cmd.addr_type = READ_TRACKINFO_ADDR_TRACK;
3516 ti_cmd.data_len[1] = READ_TRACKINFO_RETURNSIZE; 3516 ti_cmd.data_len[1] = READ_TRACKINFO_RETURNSIZE;
3517 3517
3518 /* trackinfo.tracknr contains number of tracks to query */ 3518 /* trackinfo.tracknr contains number of tracks to query */
3519 _lto4b(trackinfo->tracknr, ti_cmd.address); 3519 _lto4b(trackinfo->tracknr, ti_cmd.address);
3520 error = scsipi_command(periph, 3520 error = scsipi_command(periph,