17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate
237c478bd9Sstevel@tonic-gate /*
24*3e1bd7a2Ssjelinek * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25*3e1bd7a2Ssjelinek * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate */
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * This file contains functions that implement the cache menu commands.
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate #include "global.h"
347c478bd9Sstevel@tonic-gate #include <sys/time.h>
357c478bd9Sstevel@tonic-gate #include <sys/resource.h>
367c478bd9Sstevel@tonic-gate #include <sys/wait.h>
377c478bd9Sstevel@tonic-gate #include <signal.h>
387c478bd9Sstevel@tonic-gate #include <string.h>
397c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
407c478bd9Sstevel@tonic-gate #include <sys/stat.h>
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #include <sys/dklabel.h>
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #include "main.h"
457c478bd9Sstevel@tonic-gate #include "analyze.h"
467c478bd9Sstevel@tonic-gate #include "menu.h"
477c478bd9Sstevel@tonic-gate #include "menu_cache.h"
487c478bd9Sstevel@tonic-gate #include "param.h"
497c478bd9Sstevel@tonic-gate #include "misc.h"
507c478bd9Sstevel@tonic-gate #include "label.h"
517c478bd9Sstevel@tonic-gate #include "startup.h"
527c478bd9Sstevel@tonic-gate #include "partition.h"
537c478bd9Sstevel@tonic-gate #include "prompts.h"
54*3e1bd7a2Ssjelinek #include "checkdev.h"
557c478bd9Sstevel@tonic-gate #include "io.h"
567c478bd9Sstevel@tonic-gate #include "ctlr_scsi.h"
577c478bd9Sstevel@tonic-gate #include "auto_sense.h"
587c478bd9Sstevel@tonic-gate #include "hardware_structs.h"
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate extern struct menu_item menu_cache[];
617c478bd9Sstevel@tonic-gate extern struct menu_item menu_write_cache[];
627c478bd9Sstevel@tonic-gate extern struct menu_item menu_read_cache[];
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate int
c_cache()667c478bd9Sstevel@tonic-gate c_cache()
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate cur_menu++;
697c478bd9Sstevel@tonic-gate last_menu = cur_menu;
707c478bd9Sstevel@tonic-gate run_menu(menu_cache, "CACHE", "cache", 0);
717c478bd9Sstevel@tonic-gate cur_menu--;
727c478bd9Sstevel@tonic-gate return (0);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate int
ca_write_cache()767c478bd9Sstevel@tonic-gate ca_write_cache()
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate cur_menu++;
797c478bd9Sstevel@tonic-gate last_menu = cur_menu;
807c478bd9Sstevel@tonic-gate run_menu(menu_write_cache, "WRITE_CACHE", "write_cache", 0);
817c478bd9Sstevel@tonic-gate cur_menu--;
827c478bd9Sstevel@tonic-gate return (0);
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate int
ca_read_cache()867c478bd9Sstevel@tonic-gate ca_read_cache()
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate cur_menu++;
897c478bd9Sstevel@tonic-gate last_menu = cur_menu;
907c478bd9Sstevel@tonic-gate run_menu(menu_read_cache, "READ_CACHE", "read_cache", 0);
917c478bd9Sstevel@tonic-gate cur_menu--;
927c478bd9Sstevel@tonic-gate return (0);
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate int
ca_write_display()967c478bd9Sstevel@tonic-gate ca_write_display()
977c478bd9Sstevel@tonic-gate {
987c478bd9Sstevel@tonic-gate struct mode_cache *page8;
997c478bd9Sstevel@tonic-gate struct scsi_ms_header header;
1007c478bd9Sstevel@tonic-gate int status;
1017c478bd9Sstevel@tonic-gate union {
1027c478bd9Sstevel@tonic-gate struct mode_cache page8;
1037c478bd9Sstevel@tonic-gate char rawbuf[MAX_MODE_SENSE_SIZE];
1047c478bd9Sstevel@tonic-gate } u_page8;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate page8 = &u_page8.page8;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
1097c478bd9Sstevel@tonic-gate MODE_SENSE_PC_CURRENT, (caddr_t)page8,
1107c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate if (status == 0) {
1137c478bd9Sstevel@tonic-gate if (page8->wce) {
1147c478bd9Sstevel@tonic-gate fmt_print("Write Cache is enabled\n");
1157c478bd9Sstevel@tonic-gate } else {
1167c478bd9Sstevel@tonic-gate fmt_print("Write Cache is disabled\n");
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate } else {
1197c478bd9Sstevel@tonic-gate err_print("Mode sense failed.\n");
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate return (0);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate int
ca_write_enable()1257c478bd9Sstevel@tonic-gate ca_write_enable()
1267c478bd9Sstevel@tonic-gate {
1277c478bd9Sstevel@tonic-gate struct mode_cache *page8;
1287c478bd9Sstevel@tonic-gate struct scsi_ms_header header;
1297c478bd9Sstevel@tonic-gate int status;
1307c478bd9Sstevel@tonic-gate int length;
1317c478bd9Sstevel@tonic-gate int sp_flags;
1327c478bd9Sstevel@tonic-gate union {
1337c478bd9Sstevel@tonic-gate struct mode_cache page8;
1347c478bd9Sstevel@tonic-gate char rawbuf[MAX_MODE_SENSE_SIZE];
1357c478bd9Sstevel@tonic-gate } u_page8;
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate page8 = &u_page8.page8;
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
1407c478bd9Sstevel@tonic-gate MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
1417c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate if (status == 0) {
1447c478bd9Sstevel@tonic-gate if (page8->wce) {
1457c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
1467c478bd9Sstevel@tonic-gate MODE_SENSE_PC_SAVED, (caddr_t)page8,
1477c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
1487c478bd9Sstevel@tonic-gate if (status != 0) {
1497c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file,
1507c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
1517c478bd9Sstevel@tonic-gate (caddr_t)page8, MAX_MODE_SENSE_SIZE, &header);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate if (status == 0) {
1557c478bd9Sstevel@tonic-gate length = MODESENSE_PAGE_LEN(page8);
1567c478bd9Sstevel@tonic-gate sp_flags = MODE_SELECT_PF;
1577c478bd9Sstevel@tonic-gate if (page8->mode_page.ps) {
1587c478bd9Sstevel@tonic-gate sp_flags |= MODE_SELECT_SP;
1597c478bd9Sstevel@tonic-gate } else {
1607c478bd9Sstevel@tonic-gate err_print("\
1617c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
1627c478bd9Sstevel@tonic-gate }
1637c478bd9Sstevel@tonic-gate page8->mode_page.ps = 0;
1647c478bd9Sstevel@tonic-gate page8->wce = 1;
1657c478bd9Sstevel@tonic-gate header.mode_header.length = 0;
1667c478bd9Sstevel@tonic-gate header.mode_header.device_specific = 0;
1677c478bd9Sstevel@tonic-gate status = uscsi_mode_select(cur_file,
1687c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, sp_flags,
1697c478bd9Sstevel@tonic-gate (caddr_t)page8, length, &header);
1707c478bd9Sstevel@tonic-gate if (status != 0) {
1717c478bd9Sstevel@tonic-gate err_print("Mode select failed\n");
1727c478bd9Sstevel@tonic-gate return (0);
1737c478bd9Sstevel@tonic-gate }
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate } else {
1767c478bd9Sstevel@tonic-gate err_print("Write cache setting is not changeable\n");
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate if (status != 0) {
1807c478bd9Sstevel@tonic-gate err_print("Mode sense failed.\n");
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate return (0);
1837c478bd9Sstevel@tonic-gate }
1847c478bd9Sstevel@tonic-gate
1857c478bd9Sstevel@tonic-gate int
ca_write_disable()1867c478bd9Sstevel@tonic-gate ca_write_disable()
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate struct mode_cache *page8;
1897c478bd9Sstevel@tonic-gate struct scsi_ms_header header;
1907c478bd9Sstevel@tonic-gate int status;
1917c478bd9Sstevel@tonic-gate int length;
1927c478bd9Sstevel@tonic-gate int sp_flags;
1937c478bd9Sstevel@tonic-gate union {
1947c478bd9Sstevel@tonic-gate struct mode_cache page8;
1957c478bd9Sstevel@tonic-gate char rawbuf[MAX_MODE_SENSE_SIZE];
1967c478bd9Sstevel@tonic-gate } u_page8;
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate page8 = &u_page8.page8;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2017c478bd9Sstevel@tonic-gate MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
2027c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate if (status == 0) {
2057c478bd9Sstevel@tonic-gate if (page8->wce) {
2067c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2077c478bd9Sstevel@tonic-gate MODE_SENSE_PC_SAVED, (caddr_t)page8,
2087c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
2097c478bd9Sstevel@tonic-gate if (status != 0) {
2107c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file,
2117c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
2127c478bd9Sstevel@tonic-gate (caddr_t)page8, MAX_MODE_SENSE_SIZE, &header);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate if (status == 0) {
2167c478bd9Sstevel@tonic-gate length = MODESENSE_PAGE_LEN(page8);
2177c478bd9Sstevel@tonic-gate sp_flags = MODE_SELECT_PF;
2187c478bd9Sstevel@tonic-gate if (page8->mode_page.ps) {
2197c478bd9Sstevel@tonic-gate sp_flags |= MODE_SELECT_SP;
2207c478bd9Sstevel@tonic-gate } else {
2217c478bd9Sstevel@tonic-gate err_print("\
2227c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
2237c478bd9Sstevel@tonic-gate }
2247c478bd9Sstevel@tonic-gate page8->mode_page.ps = 0;
2257c478bd9Sstevel@tonic-gate page8->wce = 0;
2267c478bd9Sstevel@tonic-gate header.mode_header.length = 0;
2277c478bd9Sstevel@tonic-gate header.mode_header.device_specific = 0;
2287c478bd9Sstevel@tonic-gate status = uscsi_mode_select(cur_file,
2297c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, sp_flags,
2307c478bd9Sstevel@tonic-gate (caddr_t)page8, length, &header);
2317c478bd9Sstevel@tonic-gate if (status != 0) {
2327c478bd9Sstevel@tonic-gate err_print("Mode select failed\n");
2337c478bd9Sstevel@tonic-gate return (0);
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate } else {
2377c478bd9Sstevel@tonic-gate err_print("Write cache setting is not changeable\n");
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate if (status != 0) {
2417c478bd9Sstevel@tonic-gate err_print("Mode sense failed.\n");
2427c478bd9Sstevel@tonic-gate }
2437c478bd9Sstevel@tonic-gate return (0);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate int
ca_read_display()2477c478bd9Sstevel@tonic-gate ca_read_display()
2487c478bd9Sstevel@tonic-gate {
2497c478bd9Sstevel@tonic-gate struct mode_cache *page8;
2507c478bd9Sstevel@tonic-gate struct scsi_ms_header header;
2517c478bd9Sstevel@tonic-gate int status;
2527c478bd9Sstevel@tonic-gate union {
2537c478bd9Sstevel@tonic-gate struct mode_cache page8;
2547c478bd9Sstevel@tonic-gate char rawbuf[MAX_MODE_SENSE_SIZE];
2557c478bd9Sstevel@tonic-gate } u_page8;
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate page8 = &u_page8.page8;
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2607c478bd9Sstevel@tonic-gate MODE_SENSE_PC_CURRENT, (caddr_t)page8,
2617c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate if (status == 0) {
2647c478bd9Sstevel@tonic-gate if (page8->rcd) {
2657c478bd9Sstevel@tonic-gate fmt_print("Read Cache is disabled\n");
2667c478bd9Sstevel@tonic-gate } else {
2677c478bd9Sstevel@tonic-gate fmt_print("Read Cache is enabled\n");
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate } else {
2707c478bd9Sstevel@tonic-gate err_print("Mode sense failed.\n");
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate return (0);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate int
ca_read_enable()2767c478bd9Sstevel@tonic-gate ca_read_enable()
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate struct mode_cache *page8;
2797c478bd9Sstevel@tonic-gate struct scsi_ms_header header;
2807c478bd9Sstevel@tonic-gate int status;
2817c478bd9Sstevel@tonic-gate int length;
2827c478bd9Sstevel@tonic-gate int sp_flags;
2837c478bd9Sstevel@tonic-gate union {
2847c478bd9Sstevel@tonic-gate struct mode_cache page8;
2857c478bd9Sstevel@tonic-gate char rawbuf[MAX_MODE_SENSE_SIZE];
2867c478bd9Sstevel@tonic-gate } u_page8;
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate page8 = &u_page8.page8;
2897c478bd9Sstevel@tonic-gate
2907c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2917c478bd9Sstevel@tonic-gate MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
2927c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate if (status == 0) {
2957c478bd9Sstevel@tonic-gate if (page8->rcd) {
2967c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
2977c478bd9Sstevel@tonic-gate MODE_SENSE_PC_SAVED, (caddr_t)page8,
2987c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
2997c478bd9Sstevel@tonic-gate if (status != 0) {
3007c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file,
3017c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
3027c478bd9Sstevel@tonic-gate (caddr_t)page8, MAX_MODE_SENSE_SIZE, &header);
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate if (status == 0) {
3067c478bd9Sstevel@tonic-gate length = MODESENSE_PAGE_LEN(page8);
3077c478bd9Sstevel@tonic-gate sp_flags = MODE_SELECT_PF;
3087c478bd9Sstevel@tonic-gate if (page8->mode_page.ps) {
3097c478bd9Sstevel@tonic-gate sp_flags |= MODE_SELECT_SP;
3107c478bd9Sstevel@tonic-gate } else {
3117c478bd9Sstevel@tonic-gate err_print("\
3127c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate page8->mode_page.ps = 0;
3157c478bd9Sstevel@tonic-gate page8->rcd = 0;
3167c478bd9Sstevel@tonic-gate header.mode_header.length = 0;
3177c478bd9Sstevel@tonic-gate header.mode_header.device_specific = 0;
3187c478bd9Sstevel@tonic-gate status = uscsi_mode_select(cur_file,
3197c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, sp_flags,
3207c478bd9Sstevel@tonic-gate (caddr_t)page8, length, &header);
3217c478bd9Sstevel@tonic-gate if (status != 0) {
3227c478bd9Sstevel@tonic-gate err_print("Mode select failed\n");
3237c478bd9Sstevel@tonic-gate return (0);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate } else {
3277c478bd9Sstevel@tonic-gate err_print("Read cache setting is not changeable\n");
3287c478bd9Sstevel@tonic-gate }
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate if (status != 0) {
3317c478bd9Sstevel@tonic-gate err_print("Mode sense failed.\n");
3327c478bd9Sstevel@tonic-gate }
3337c478bd9Sstevel@tonic-gate return (0);
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate int
ca_read_disable()3377c478bd9Sstevel@tonic-gate ca_read_disable()
3387c478bd9Sstevel@tonic-gate {
3397c478bd9Sstevel@tonic-gate struct mode_cache *page8;
3407c478bd9Sstevel@tonic-gate struct scsi_ms_header header;
3417c478bd9Sstevel@tonic-gate int status;
3427c478bd9Sstevel@tonic-gate int length;
3437c478bd9Sstevel@tonic-gate int sp_flags;
3447c478bd9Sstevel@tonic-gate union {
3457c478bd9Sstevel@tonic-gate struct mode_cache page8;
3467c478bd9Sstevel@tonic-gate char rawbuf[MAX_MODE_SENSE_SIZE];
3477c478bd9Sstevel@tonic-gate } u_page8;
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate page8 = &u_page8.page8;
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
3527c478bd9Sstevel@tonic-gate MODE_SENSE_PC_CHANGEABLE, (caddr_t)page8,
3537c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate if (status == 0) {
3567c478bd9Sstevel@tonic-gate if (page8->rcd) {
3577c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file, DAD_MODE_CACHE,
3587c478bd9Sstevel@tonic-gate MODE_SENSE_PC_SAVED, (caddr_t)page8,
3597c478bd9Sstevel@tonic-gate MAX_MODE_SENSE_SIZE, &header);
3607c478bd9Sstevel@tonic-gate if (status != 0) {
3617c478bd9Sstevel@tonic-gate status = uscsi_mode_sense(cur_file,
3627c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, MODE_SENSE_PC_CURRENT,
3637c478bd9Sstevel@tonic-gate (caddr_t)page8, MAX_MODE_SENSE_SIZE, &header);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate if (status == 0) {
3677c478bd9Sstevel@tonic-gate length = MODESENSE_PAGE_LEN(page8);
3687c478bd9Sstevel@tonic-gate sp_flags = MODE_SELECT_PF;
3697c478bd9Sstevel@tonic-gate if (page8->mode_page.ps) {
3707c478bd9Sstevel@tonic-gate sp_flags |= MODE_SELECT_SP;
3717c478bd9Sstevel@tonic-gate } else {
3727c478bd9Sstevel@tonic-gate err_print("\
3737c478bd9Sstevel@tonic-gate This setting is valid until next reset only. It is not saved permanently.\n");
3747c478bd9Sstevel@tonic-gate }
3757c478bd9Sstevel@tonic-gate page8->mode_page.ps = 0;
3767c478bd9Sstevel@tonic-gate page8->rcd = 1;
3777c478bd9Sstevel@tonic-gate header.mode_header.length = 0;
3787c478bd9Sstevel@tonic-gate header.mode_header.device_specific = 0;
3797c478bd9Sstevel@tonic-gate status = uscsi_mode_select(cur_file,
3807c478bd9Sstevel@tonic-gate DAD_MODE_CACHE, sp_flags,
3817c478bd9Sstevel@tonic-gate (caddr_t)page8, length, &header);
3827c478bd9Sstevel@tonic-gate if (status != 0) {
3837c478bd9Sstevel@tonic-gate err_print("Mode select failed\n");
3847c478bd9Sstevel@tonic-gate return (0);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate }
3877c478bd9Sstevel@tonic-gate } else {
3887c478bd9Sstevel@tonic-gate err_print("Read cache setting is not changeable\n");
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate if (status != 0) {
3927c478bd9Sstevel@tonic-gate err_print("Mode sense failed.\n");
3937c478bd9Sstevel@tonic-gate }
3947c478bd9Sstevel@tonic-gate return (0);
3957c478bd9Sstevel@tonic-gate }
396