11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (c) 2000-2001 Adaptec Inc. 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * All rights reserved. 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Redistribution and use in source and binary forms, with or without 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * modification, are permitted provided that the following conditions 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * are met: 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 1. Redistributions of source code must retain the above copyright 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * notice, this list of conditions, and the following disclaimer, 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * without modification. 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 2. Redistributions in binary form must reproduce at minimum a disclaimer 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * substantially similar to the "NO WARRANTY" disclaimer below 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ("Disclaimer") and any redistribution must be conditioned upon 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * including a substantially similar Disclaimer requirement for further 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * binary redistribution. 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 3. Neither the names of the above-listed copyright holders nor the names 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * of any contributors may be used to endorse or promote products derived 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * from this software without specific prior written permission. 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Alternatively, this software may be distributed under the terms of the 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License ("GPL") version 2 as published by the Free 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Software Foundation. 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * NO WARRANTY 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * POSSIBILITY OF SUCH DAMAGES. 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr> 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * sym driver. 391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_proc.c#29 $ 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "aic7xxx_osm.h" 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "aic7xxx_inline.h" 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "aic7xxx_93cx6.h" 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void copy_mem_info(struct info_str *info, char *data, int len); 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int copy_info(struct info_str *info, char *fmt, ...); 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void ahc_dump_target_state(struct ahc_softc *ahc, 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct info_str *info, 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int our_id, char channel, 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int target_id, u_int target_offset); 521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void ahc_dump_device_state(struct info_str *info, 53b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley struct scsi_device *dev); 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int ahc_proc_write_seeprom(struct ahc_softc *ahc, 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char *buffer, int length); 561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 571ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig/* 581ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig * Table of syncrates that don't follow the "divisible by 4" 591ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig * rule. This table will be expanded in future SCSI specs. 601ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig */ 61980b306a297725d4f25c779ca15086de757acadfDenys Vlasenkostatic const struct { 621ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig u_int period_factor; 631ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig u_int period; /* in 100ths of ns */ 641ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig} scsi_syncrates[] = { 651ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig { 0x08, 625 }, /* FAST-160 */ 661ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig { 0x09, 1250 }, /* FAST-80 */ 671ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig { 0x0a, 2500 }, /* FAST-40 40MHz */ 681ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig { 0x0b, 3030 }, /* FAST-40 33MHz */ 691ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig { 0x0c, 5000 } /* FAST-20 */ 701ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig}; 711ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig 721ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig/* 731ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig * Return the frequency in kHz corresponding to the given 741ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig * sync period factor. 751ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig */ 761ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwigstatic u_int 771ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwigahc_calc_syncsrate(u_int period_factor) 781ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig{ 791ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig int i; 801ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig 811ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig /* See if the period is in the "exception" table */ 826391a11375de5e2bb1eb8481e54619761dc65d9fTobias Klauser for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) { 831ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig 841ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig if (period_factor == scsi_syncrates[i].period_factor) { 851ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig /* Period in kHz */ 861ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig return (100000000 / scsi_syncrates[i].period); 871ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig } 881ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig } 891ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig 901ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig /* 911ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig * Wasn't in the table, so use the standard 921ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig * 4 times conversion. 931ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig */ 941ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig return (10000000 / (period_factor * 4 * 10)); 951ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig} 961ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig 971ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldscopy_mem_info(struct info_str *info, char *data, int len) 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (info->pos + len > info->offset + info->length) 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len = info->offset + info->length - info->pos; 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (info->pos + len < info->offset) { 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info->pos += len; 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (info->pos < info->offset) { 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds off_t partial; 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds partial = info->offset - info->pos; 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds data += partial; 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info->pos += partial; 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len -= partial; 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (len > 0) { 1191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds memcpy(info->buffer, data, len); 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info->pos += len; 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info->buffer += len; 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldscopy_info(struct info_str *info, char *fmt, ...) 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds va_list args; 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char buf[256]; 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int len; 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds va_start(args, fmt); 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds len = vsprintf(buf, fmt, args); 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds va_end(args); 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_mem_info(info, buf, len); 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (len); 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 140d1d7b19d433188e94fc87cc7ca66363cd77a0bbaDenys Vlasenkostatic void 1411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo) 1421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int speed; 1441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int freq; 1451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int mb; 1461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds speed = 3300; 1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds freq = 0; 1491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (tinfo->offset != 0) { 1501ff927306e08b356d764e605eff7c50079550bd2Christoph Hellwig freq = ahc_calc_syncsrate(tinfo->period); 1511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds speed = freq; 1521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds speed *= (0x01 << tinfo->width); 1541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mb = speed / 1000; 1551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (mb > 0) 1561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000); 1571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 1581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "%dKB/s transfers", speed); 1591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (freq != 0) { 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, " (%d.%03dMHz%s, offset %d", 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds freq / 1000, freq % 1000, 1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds (tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0 1641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ? " DT" : "", tinfo->offset); 1651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (tinfo->width > 0) { 1681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (freq != 0) { 1691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, ", "); 1701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 1711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, " ("); 1721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width)); 1741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else if (freq != 0) { 1751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, ")"); 1761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\n"); 1781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 1811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info, 1821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int our_id, char channel, u_int target_id, 1831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int target_offset) 1841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 185b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley struct scsi_target *starget; 1861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct ahc_initiator_tinfo *tinfo; 1871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct ahc_tmode_tstate *tstate; 1881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int lun; 1891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds tinfo = ahc_fetch_transinfo(ahc, channel, our_id, 1911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds target_id, &tstate); 1921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((ahc->features & AHC_TWIN) != 0) 1931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "Channel %c ", channel); 1941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "Target %d Negotiation Settings\n", target_id); 1951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\tUser: "); 1961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_format_transinfo(info, &tinfo->user); 197b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley starget = ahc->platform_data->starget[target_offset]; 198c0df28cfe012652160a530f9aa74b0a49c77eac5James Bottomley if (!starget) 1991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return; 2001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\tGoal: "); 2021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_format_transinfo(info, &tinfo->goal); 2031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\tCurr: "); 2041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_format_transinfo(info, &tinfo->curr); 2051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (lun = 0; lun < AHC_NUM_LUNS; lun++) { 207b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley struct scsi_device *sdev; 2081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2099080063f523b09af63234a21816c825133d48c44Hannes Reinecke sdev = scsi_device_lookup_by_target(starget, lun); 2101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 211b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley if (sdev == NULL) 2121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds continue; 2131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 214b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley ahc_dump_device_state(info, sdev); 2151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void 219b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomleyahc_dump_device_state(struct info_str *info, struct scsi_device *sdev) 2201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 221b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley struct ahc_linux_device *dev = scsi_transport_device_data(sdev); 222b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley 2231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\tChannel %c Target %d Lun %d Settings\n", 224b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley sdev->sdev_target->channel + 'A', 225b1abb4d67f2a706f52a95064001e0c55d9be2d26James Bottomley sdev->sdev_target->id, sdev->lun); 2261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued); 2281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\t\tCommands Active %d\n", dev->active); 2291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\t\tCommand Openings %d\n", dev->openings); 2301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags); 2311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen); 2321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 2331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int 2351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length) 2361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 2371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct seeprom_descriptor sd; 2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int have_seeprom; 2391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_long s; 2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int paused; 2411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int written; 2421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Default to failure. */ 2441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds written = -EINVAL; 2451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_lock(ahc, &s); 2461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds paused = ahc_is_paused(ahc); 2471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!paused) 2481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_pause(ahc); 2491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (length != sizeof(struct seeprom_config)) { 25148813cf989eb8695fe84df30207fc8ff5f15783cPekka Enberg printk("ahc_proc_write_seeprom: incorrect buffer size\n"); 2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto done; 2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer); 2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (have_seeprom == 0) { 25748813cf989eb8695fe84df30207fc8ff5f15783cPekka Enberg printk("ahc_proc_write_seeprom: cksum verification failed\n"); 2581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto done; 2591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_ahc = ahc; 2621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if AHC_PCI_CONFIG > 0 2631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((ahc->chip & AHC_PCI) != 0) { 2641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_control_offset = SEECTL; 2651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_status_offset = SEECTL; 2661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_dataout_offset = SEECTL; 2671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ahc->flags & AHC_LARGE_SEEPROM) 2681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_chip = C56_66; 2691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else 2701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_chip = C46; 2711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_MS = SEEMS; 2721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_RDY = SEERDY; 2731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_CS = SEECS; 2741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_CK = SEECK; 2751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_DO = SEEDO; 2761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_DI = SEEDI; 2771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds have_seeprom = ahc_acquire_seeprom(ahc, &sd); 2781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else 2791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 2801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((ahc->chip & AHC_VL) != 0) { 2811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_control_offset = SEECTL_2840; 2821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_status_offset = STATUS_2840; 2831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_dataout_offset = STATUS_2840; 2841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_chip = C46; 2851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_MS = 0; 2861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_RDY = EEPROM_TF; 2871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_CS = CS_2840; 2881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_CK = CK_2840; 2891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_DO = DO_2840; 2901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sd.sd_DI = DI_2840; 2911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds have_seeprom = TRUE; 2921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 29348813cf989eb8695fe84df30207fc8ff5f15783cPekka Enberg printk("ahc_proc_write_seeprom: unsupported adapter type\n"); 2941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto done; 2951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 2961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 2971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!have_seeprom) { 29848813cf989eb8695fe84df30207fc8ff5f15783cPekka Enberg printk("ahc_proc_write_seeprom: No Serial EEPROM\n"); 2991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto done; 3001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } else { 3011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int start_addr; 3021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ahc->seep_config == NULL) { 30448813cf989eb8695fe84df30207fc8ff5f15783cPekka Enberg ahc->seep_config = kmalloc(sizeof(*ahc->seep_config), GFP_ATOMIC); 3051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ahc->seep_config == NULL) { 30648813cf989eb8695fe84df30207fc8ff5f15783cPekka Enberg printk("aic7xxx: Unable to allocate serial " 3071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds "eeprom buffer. Write failing\n"); 3081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto done; 3091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 31148813cf989eb8695fe84df30207fc8ff5f15783cPekka Enberg printk("aic7xxx: Writing Serial EEPROM\n"); 3121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds start_addr = 32 * (ahc->channel - 'A'); 3131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr, 3141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds sizeof(struct seeprom_config)/2); 3151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config, 3161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds start_addr, sizeof(struct seeprom_config)/2); 3171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if AHC_PCI_CONFIG > 0 3181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((ahc->chip & AHC_VL) == 0) 3191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_release_seeprom(&sd); 3201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 3211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds written = length; 3221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdone: 3251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!paused) 3261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_unpause(ahc); 3271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_unlock(ahc, &s); 3281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (written); 3291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 3301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 3321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Return information to handle /proc support for the driver. 3331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsint 3351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start, 3361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds off_t offset, int length, int inout) 3371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 3383d65692aed727c7fb4105f03795781ace437a84eChristoph Hellwig struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata; 3391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds struct info_str info; 3401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char ahc_info[256]; 3411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int max_targ; 3421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int i; 3431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds int retval; 3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds /* Has data been written to the file? */ 3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (inout == TRUE) { 3471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds retval = ahc_proc_write_seeprom(ahc, buffer, length); 3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds goto done; 3491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (start) 3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *start = buffer; 3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info.buffer = buffer; 3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info.length = length; 3561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info.offset = offset; 3571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds info.pos = 0; 3581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "Adaptec AIC7xxx driver version: %s\n", 3601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds AIC7XXX_DRIVER_VERSION); 3611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "%s\n", ahc->description); 3621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_controller_info(ahc, ahc_info); 3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "%s\n", ahc_info); 3641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n", 3651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc->scb_data->numscbs, AHC_NSEG); 3661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (ahc->seep_config == NULL) 3691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "No Serial EEPROM\n"); 3701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds else { 3711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "Serial EEPROM:\n"); 3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) { 3731da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (((i % 8) == 0) && (i != 0)) { 3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "\n"); 3751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "0x%.4x ", 3771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ((uint16_t*)ahc->seep_config)[i]); 3781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "\n"); 3801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 3811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds copy_info(&info, "\n"); 3821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3839080063f523b09af63234a21816c825133d48c44Hannes Reinecke max_targ = 16; 3841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0) 3859080063f523b09af63234a21816c825133d48c44Hannes Reinecke max_targ = 8; 3861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3879080063f523b09af63234a21816c825133d48c44Hannes Reinecke for (i = 0; i < max_targ; i++) { 3881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int our_id; 3891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds u_int target_id; 3901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds char channel; 3911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds channel = 'A'; 3931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds our_id = ahc->our_id; 3941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds target_id = i; 3951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (i > 7 && (ahc->features & AHC_TWIN) != 0) { 3961da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds channel = 'B'; 3971da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds our_id = ahc->our_id_b; 3981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds target_id = i % 8; 3991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 4011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds ahc_dump_target_state(ahc, &info, our_id, 4021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds channel, target_id, i); 4031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 4041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds retval = info.pos > info.offset ? info.pos - info.offset : 0; 4051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsdone: 4061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return (retval); 4071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 408