11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * Copyright (c) 2000-2001 Adaptec Inc.
31da177e4SLinus Torvalds  * All rights reserved.
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Redistribution and use in source and binary forms, with or without
61da177e4SLinus Torvalds  * modification, are permitted provided that the following conditions
71da177e4SLinus Torvalds  * are met:
81da177e4SLinus Torvalds  * 1. Redistributions of source code must retain the above copyright
91da177e4SLinus Torvalds  *    notice, this list of conditions, and the following disclaimer,
101da177e4SLinus Torvalds  *    without modification.
111da177e4SLinus Torvalds  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
121da177e4SLinus Torvalds  *    substantially similar to the "NO WARRANTY" disclaimer below
131da177e4SLinus Torvalds  *    ("Disclaimer") and any redistribution must be conditioned upon
141da177e4SLinus Torvalds  *    including a substantially similar Disclaimer requirement for further
151da177e4SLinus Torvalds  *    binary redistribution.
161da177e4SLinus Torvalds  * 3. Neither the names of the above-listed copyright holders nor the names
171da177e4SLinus Torvalds  *    of any contributors may be used to endorse or promote products derived
181da177e4SLinus Torvalds  *    from this software without specific prior written permission.
191da177e4SLinus Torvalds  *
201da177e4SLinus Torvalds  * Alternatively, this software may be distributed under the terms of the
211da177e4SLinus Torvalds  * GNU General Public License ("GPL") version 2 as published by the Free
221da177e4SLinus Torvalds  * Software Foundation.
231da177e4SLinus Torvalds  *
241da177e4SLinus Torvalds  * NO WARRANTY
251da177e4SLinus Torvalds  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
261da177e4SLinus Torvalds  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
271da177e4SLinus Torvalds  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
281da177e4SLinus Torvalds  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
291da177e4SLinus Torvalds  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
301da177e4SLinus Torvalds  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
311da177e4SLinus Torvalds  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
321da177e4SLinus Torvalds  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
331da177e4SLinus Torvalds  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
341da177e4SLinus Torvalds  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
351da177e4SLinus Torvalds  * POSSIBILITY OF SUCH DAMAGES.
361da177e4SLinus Torvalds  *
371da177e4SLinus Torvalds  * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
381da177e4SLinus Torvalds  * sym driver.
391da177e4SLinus Torvalds  *
401da177e4SLinus Torvalds  * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_proc.c#19 $
411da177e4SLinus Torvalds  */
421da177e4SLinus Torvalds #include "aic79xx_osm.h"
431da177e4SLinus Torvalds #include "aic79xx_inline.h"
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds static void	copy_mem_info(struct info_str *info, char *data, int len);
461da177e4SLinus Torvalds static int	copy_info(struct info_str *info, char *fmt, ...);
471da177e4SLinus Torvalds static void	ahd_dump_target_state(struct ahd_softc *ahd,
481da177e4SLinus Torvalds 				      struct info_str *info,
491da177e4SLinus Torvalds 				      u_int our_id, char channel,
501da177e4SLinus Torvalds 				      u_int target_id, u_int target_offset);
511da177e4SLinus Torvalds static void	ahd_dump_device_state(struct info_str *info,
5273a25462SHannes Reinecke 				      struct scsi_device *sdev);
531da177e4SLinus Torvalds static int	ahd_proc_write_seeprom(struct ahd_softc *ahd,
541da177e4SLinus Torvalds 				       char *buffer, int length);
551da177e4SLinus Torvalds 
561ff92730SChristoph Hellwig /*
571ff92730SChristoph Hellwig  * Table of syncrates that don't follow the "divisible by 4"
581ff92730SChristoph Hellwig  * rule. This table will be expanded in future SCSI specs.
591ff92730SChristoph Hellwig  */
601ff92730SChristoph Hellwig static struct {
611ff92730SChristoph Hellwig 	u_int period_factor;
621ff92730SChristoph Hellwig 	u_int period;	/* in 100ths of ns */
631ff92730SChristoph Hellwig } scsi_syncrates[] = {
641ff92730SChristoph Hellwig 	{ 0x08, 625 },	/* FAST-160 */
651ff92730SChristoph Hellwig 	{ 0x09, 1250 },	/* FAST-80 */
661ff92730SChristoph Hellwig 	{ 0x0a, 2500 },	/* FAST-40 40MHz */
671ff92730SChristoph Hellwig 	{ 0x0b, 3030 },	/* FAST-40 33MHz */
681ff92730SChristoph Hellwig 	{ 0x0c, 5000 }	/* FAST-20 */
691ff92730SChristoph Hellwig };
701ff92730SChristoph Hellwig 
711ff92730SChristoph Hellwig /*
721ff92730SChristoph Hellwig  * Return the frequency in kHz corresponding to the given
731ff92730SChristoph Hellwig  * sync period factor.
741ff92730SChristoph Hellwig  */
751ff92730SChristoph Hellwig static u_int
761ff92730SChristoph Hellwig ahd_calc_syncsrate(u_int period_factor)
771ff92730SChristoph Hellwig {
781ff92730SChristoph Hellwig 	int i;
791ff92730SChristoph Hellwig 	int num_syncrates;
801ff92730SChristoph Hellwig 
811ff92730SChristoph Hellwig 	num_syncrates = sizeof(scsi_syncrates) / sizeof(scsi_syncrates[0]);
821ff92730SChristoph Hellwig 	/* See if the period is in the "exception" table */
831ff92730SChristoph Hellwig 	for (i = 0; i < num_syncrates; i++) {
841ff92730SChristoph Hellwig 
851ff92730SChristoph Hellwig 		if (period_factor == scsi_syncrates[i].period_factor) {
861ff92730SChristoph Hellwig 			/* Period in kHz */
871ff92730SChristoph Hellwig 			return (100000000 / scsi_syncrates[i].period);
881ff92730SChristoph Hellwig 		}
891ff92730SChristoph Hellwig 	}
901ff92730SChristoph Hellwig 
911ff92730SChristoph Hellwig 	/*
921ff92730SChristoph Hellwig 	 * Wasn't in the table, so use the standard
931ff92730SChristoph Hellwig 	 * 4 times conversion.
941ff92730SChristoph Hellwig 	 */
951ff92730SChristoph Hellwig 	return (10000000 / (period_factor * 4 * 10));
961ff92730SChristoph Hellwig }
971ff92730SChristoph Hellwig 
981ff92730SChristoph Hellwig 
991da177e4SLinus Torvalds static void
1001da177e4SLinus Torvalds copy_mem_info(struct info_str *info, char *data, int len)
1011da177e4SLinus Torvalds {
1021da177e4SLinus Torvalds 	if (info->pos + len > info->offset + info->length)
1031da177e4SLinus Torvalds 		len = info->offset + info->length - info->pos;
1041da177e4SLinus Torvalds 
1051da177e4SLinus Torvalds 	if (info->pos + len < info->offset) {
1061da177e4SLinus Torvalds 		info->pos += len;
1071da177e4SLinus Torvalds 		return;
1081da177e4SLinus Torvalds 	}
1091da177e4SLinus Torvalds 
1101da177e4SLinus Torvalds 	if (info->pos < info->offset) {
1111da177e4SLinus Torvalds 		off_t partial;
1121da177e4SLinus Torvalds 
1131da177e4SLinus Torvalds 		partial = info->offset - info->pos;
1141da177e4SLinus Torvalds 		data += partial;
1151da177e4SLinus Torvalds 		info->pos += partial;
1161da177e4SLinus Torvalds 		len  -= partial;
1171da177e4SLinus Torvalds 	}
1181da177e4SLinus Torvalds 
1191da177e4SLinus Torvalds 	if (len > 0) {
1201da177e4SLinus Torvalds 		memcpy(info->buffer, data, len);
1211da177e4SLinus Torvalds 		info->pos += len;
1221da177e4SLinus Torvalds 		info->buffer += len;
1231da177e4SLinus Torvalds 	}
1241da177e4SLinus Torvalds }
1251da177e4SLinus Torvalds 
1261da177e4SLinus Torvalds static int
1271da177e4SLinus Torvalds copy_info(struct info_str *info, char *fmt, ...)
1281da177e4SLinus Torvalds {
1291da177e4SLinus Torvalds 	va_list args;
1301da177e4SLinus Torvalds 	char buf[256];
1311da177e4SLinus Torvalds 	int len;
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds 	va_start(args, fmt);
1341da177e4SLinus Torvalds 	len = vsprintf(buf, fmt, args);
1351da177e4SLinus Torvalds 	va_end(args);
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds 	copy_mem_info(info, buf, len);
1381da177e4SLinus Torvalds 	return (len);
1391da177e4SLinus Torvalds }
1401da177e4SLinus Torvalds 
1411da177e4SLinus Torvalds void
1421da177e4SLinus Torvalds ahd_format_transinfo(struct info_str *info, struct ahd_transinfo *tinfo)
1431da177e4SLinus Torvalds {
1441da177e4SLinus Torvalds 	u_int speed;
1451da177e4SLinus Torvalds 	u_int freq;
1461da177e4SLinus Torvalds 	u_int mb;
1471da177e4SLinus Torvalds 
1481da177e4SLinus Torvalds 	if (tinfo->period == AHD_PERIOD_UNKNOWN) {
1491da177e4SLinus Torvalds 		copy_info(info, "Renegotiation Pending\n");
1501da177e4SLinus Torvalds 		return;
1511da177e4SLinus Torvalds 	}
1521da177e4SLinus Torvalds         speed = 3300;
1531da177e4SLinus Torvalds         freq = 0;
1541da177e4SLinus Torvalds 	if (tinfo->offset != 0) {
1551ff92730SChristoph Hellwig 		freq = ahd_calc_syncsrate(tinfo->period);
1561da177e4SLinus Torvalds 		speed = freq;
1571da177e4SLinus Torvalds 	}
1581da177e4SLinus Torvalds 	speed *= (0x01 << tinfo->width);
1591da177e4SLinus Torvalds         mb = speed / 1000;
1601da177e4SLinus Torvalds         if (mb > 0)
1611da177e4SLinus Torvalds 		copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
1621da177e4SLinus Torvalds         else
1631da177e4SLinus Torvalds 		copy_info(info, "%dKB/s transfers", speed);
1641da177e4SLinus Torvalds 
1651da177e4SLinus Torvalds 	if (freq != 0) {
1661da177e4SLinus Torvalds 		int	printed_options;
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds 		printed_options = 0;
1691da177e4SLinus Torvalds 		copy_info(info, " (%d.%03dMHz", freq / 1000, freq % 1000);
1701da177e4SLinus Torvalds 		if ((tinfo->ppr_options & MSG_EXT_PPR_RD_STRM) != 0) {
1711da177e4SLinus Torvalds 			copy_info(info, " RDSTRM");
1721da177e4SLinus Torvalds 			printed_options++;
1731da177e4SLinus Torvalds 		}
1741da177e4SLinus Torvalds 		if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
1751da177e4SLinus Torvalds 			copy_info(info, "%s", printed_options ? "|DT" : " DT");
1761da177e4SLinus Torvalds 			printed_options++;
1771da177e4SLinus Torvalds 		}
1781da177e4SLinus Torvalds 		if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
1791da177e4SLinus Torvalds 			copy_info(info, "%s", printed_options ? "|IU" : " IU");
1801da177e4SLinus Torvalds 			printed_options++;
1811da177e4SLinus Torvalds 		}
1821da177e4SLinus Torvalds 		if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) {
1831da177e4SLinus Torvalds 			copy_info(info, "%s",
1841da177e4SLinus Torvalds 				  printed_options ? "|RTI" : " RTI");
1851da177e4SLinus Torvalds 			printed_options++;
1861da177e4SLinus Torvalds 		}
1871da177e4SLinus Torvalds 		if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
1881da177e4SLinus Torvalds 			copy_info(info, "%s",
1891da177e4SLinus Torvalds 				  printed_options ? "|QAS" : " QAS");
1901da177e4SLinus Torvalds 			printed_options++;
1911da177e4SLinus Torvalds 		}
1921da177e4SLinus Torvalds 	}
1931da177e4SLinus Torvalds 
1941da177e4SLinus Torvalds 	if (tinfo->width > 0) {
1951da177e4SLinus Torvalds 		if (freq != 0) {
1961da177e4SLinus Torvalds 			copy_info(info, ", ");
1971da177e4SLinus Torvalds 		} else {
1981da177e4SLinus Torvalds 			copy_info(info, " (");
1991da177e4SLinus Torvalds 		}
2001da177e4SLinus Torvalds 		copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
2011da177e4SLinus Torvalds 	} else if (freq != 0) {
2021da177e4SLinus Torvalds 		copy_info(info, ")");
2031da177e4SLinus Torvalds 	}
2041da177e4SLinus Torvalds 	copy_info(info, "\n");
2051da177e4SLinus Torvalds }
2061da177e4SLinus Torvalds 
2071da177e4SLinus Torvalds static void
2081da177e4SLinus Torvalds ahd_dump_target_state(struct ahd_softc *ahd, struct info_str *info,
2091da177e4SLinus Torvalds 		      u_int our_id, char channel, u_int target_id,
2101da177e4SLinus Torvalds 		      u_int target_offset)
2111da177e4SLinus Torvalds {
2121da177e4SLinus Torvalds 	struct	ahd_linux_target *targ;
21373a25462SHannes Reinecke 	struct  scsi_target *starget;
2141da177e4SLinus Torvalds 	struct	ahd_initiator_tinfo *tinfo;
2151da177e4SLinus Torvalds 	struct	ahd_tmode_tstate *tstate;
2161da177e4SLinus Torvalds 	int	lun;
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds 	tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
2191da177e4SLinus Torvalds 				    target_id, &tstate);
2201da177e4SLinus Torvalds 	copy_info(info, "Target %d Negotiation Settings\n", target_id);
2211da177e4SLinus Torvalds 	copy_info(info, "\tUser: ");
2221da177e4SLinus Torvalds 	ahd_format_transinfo(info, &tinfo->user);
22373a25462SHannes Reinecke 	starget = ahd->platform_data->starget[target_offset];
2243f40d7d6SJames Bottomley 	if (starget == NULL)
2251da177e4SLinus Torvalds 		return;
2263f40d7d6SJames Bottomley 	targ = scsi_transport_target_data(starget);
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds 	copy_info(info, "\tGoal: ");
2291da177e4SLinus Torvalds 	ahd_format_transinfo(info, &tinfo->goal);
2301da177e4SLinus Torvalds 	copy_info(info, "\tCurr: ");
2311da177e4SLinus Torvalds 	ahd_format_transinfo(info, &tinfo->curr);
2321da177e4SLinus Torvalds 
2331da177e4SLinus Torvalds 	for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
23473a25462SHannes Reinecke 		struct scsi_device *dev;
2351da177e4SLinus Torvalds 
23673a25462SHannes Reinecke 		dev = targ->sdev[lun];
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds 		if (dev == NULL)
2391da177e4SLinus Torvalds 			continue;
2401da177e4SLinus Torvalds 
2411da177e4SLinus Torvalds 		ahd_dump_device_state(info, dev);
2421da177e4SLinus Torvalds 	}
2431da177e4SLinus Torvalds }
2441da177e4SLinus Torvalds 
2451da177e4SLinus Torvalds static void
24673a25462SHannes Reinecke ahd_dump_device_state(struct info_str *info, struct scsi_device *sdev)
2471da177e4SLinus Torvalds {
24873a25462SHannes Reinecke 	struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
24973a25462SHannes Reinecke 
2501da177e4SLinus Torvalds 	copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
25173a25462SHannes Reinecke 		  sdev->sdev_target->channel + 'A',
25273a25462SHannes Reinecke 		  sdev->sdev_target->id, sdev->lun);
2531da177e4SLinus Torvalds 
2541da177e4SLinus Torvalds 	copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
2551da177e4SLinus Torvalds 	copy_info(info, "\t\tCommands Active %d\n", dev->active);
2561da177e4SLinus Torvalds 	copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
2571da177e4SLinus Torvalds 	copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
2581da177e4SLinus Torvalds 	copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
2591da177e4SLinus Torvalds }
2601da177e4SLinus Torvalds 
2611da177e4SLinus Torvalds static int
2621da177e4SLinus Torvalds ahd_proc_write_seeprom(struct ahd_softc *ahd, char *buffer, int length)
2631da177e4SLinus Torvalds {
2641da177e4SLinus Torvalds 	ahd_mode_state saved_modes;
2651da177e4SLinus Torvalds 	int have_seeprom;
2661da177e4SLinus Torvalds 	u_long s;
2671da177e4SLinus Torvalds 	int paused;
2681da177e4SLinus Torvalds 	int written;
2691da177e4SLinus Torvalds 
2701da177e4SLinus Torvalds 	/* Default to failure. */
2711da177e4SLinus Torvalds 	written = -EINVAL;
2721da177e4SLinus Torvalds 	ahd_lock(ahd, &s);
2731da177e4SLinus Torvalds 	paused = ahd_is_paused(ahd);
2741da177e4SLinus Torvalds 	if (!paused)
2751da177e4SLinus Torvalds 		ahd_pause(ahd);
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds 	saved_modes = ahd_save_modes(ahd);
2781da177e4SLinus Torvalds 	ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2791da177e4SLinus Torvalds 	if (length != sizeof(struct seeprom_config)) {
2801da177e4SLinus Torvalds 		printf("ahd_proc_write_seeprom: incorrect buffer size\n");
2811da177e4SLinus Torvalds 		goto done;
2821da177e4SLinus Torvalds 	}
2831da177e4SLinus Torvalds 
2841da177e4SLinus Torvalds 	have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer);
2851da177e4SLinus Torvalds 	if (have_seeprom == 0) {
2861da177e4SLinus Torvalds 		printf("ahd_proc_write_seeprom: cksum verification failed\n");
2871da177e4SLinus Torvalds 		goto done;
2881da177e4SLinus Torvalds 	}
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds 	have_seeprom = ahd_acquire_seeprom(ahd);
2911da177e4SLinus Torvalds 	if (!have_seeprom) {
2921da177e4SLinus Torvalds 		printf("ahd_proc_write_seeprom: No Serial EEPROM\n");
2931da177e4SLinus Torvalds 		goto done;
2941da177e4SLinus Torvalds 	} else {
2951da177e4SLinus Torvalds 		u_int start_addr;
2961da177e4SLinus Torvalds 
2971da177e4SLinus Torvalds 		if (ahd->seep_config == NULL) {
2981da177e4SLinus Torvalds 			ahd->seep_config = malloc(sizeof(*ahd->seep_config),
2991da177e4SLinus Torvalds 						  M_DEVBUF, M_NOWAIT);
3001da177e4SLinus Torvalds 			if (ahd->seep_config == NULL) {
3011da177e4SLinus Torvalds 				printf("aic79xx: Unable to allocate serial "
3021da177e4SLinus Torvalds 				       "eeprom buffer.  Write failing\n");
3031da177e4SLinus Torvalds 				goto done;
3041da177e4SLinus Torvalds 			}
3051da177e4SLinus Torvalds 		}
3061da177e4SLinus Torvalds 		printf("aic79xx: Writing Serial EEPROM\n");
3071da177e4SLinus Torvalds 		start_addr = 32 * (ahd->channel - 'A');
3081da177e4SLinus Torvalds 		ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr,
3091da177e4SLinus Torvalds 				  sizeof(struct seeprom_config)/2);
3101da177e4SLinus Torvalds 		ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config,
3111da177e4SLinus Torvalds 				 start_addr, sizeof(struct seeprom_config)/2,
3121da177e4SLinus Torvalds 				 /*ByteStream*/FALSE);
3131da177e4SLinus Torvalds 		ahd_release_seeprom(ahd);
3141da177e4SLinus Torvalds 		written = length;
3151da177e4SLinus Torvalds 	}
3161da177e4SLinus Torvalds 
3171da177e4SLinus Torvalds done:
3181da177e4SLinus Torvalds 	ahd_restore_modes(ahd, saved_modes);
3191da177e4SLinus Torvalds 	if (!paused)
3201da177e4SLinus Torvalds 		ahd_unpause(ahd);
3211da177e4SLinus Torvalds 	ahd_unlock(ahd, &s);
3221da177e4SLinus Torvalds 	return (written);
3231da177e4SLinus Torvalds }
3241da177e4SLinus Torvalds /*
3251da177e4SLinus Torvalds  * Return information to handle /proc support for the driver.
3261da177e4SLinus Torvalds  */
3271da177e4SLinus Torvalds int
3281da177e4SLinus Torvalds ahd_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
3291da177e4SLinus Torvalds 		    off_t offset, int length, int inout)
3301da177e4SLinus Torvalds {
33185a46523SChristoph Hellwig 	struct	ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
3321da177e4SLinus Torvalds 	struct	info_str info;
3331da177e4SLinus Torvalds 	char	ahd_info[256];
3341da177e4SLinus Torvalds 	u_int	max_targ;
3351da177e4SLinus Torvalds 	u_int	i;
3361da177e4SLinus Torvalds 	int	retval;
3371da177e4SLinus Torvalds 
3381da177e4SLinus Torvalds 	 /* Has data been written to the file? */
3391da177e4SLinus Torvalds 	if (inout == TRUE) {
3401da177e4SLinus Torvalds 		retval = ahd_proc_write_seeprom(ahd, buffer, length);
3411da177e4SLinus Torvalds 		goto done;
3421da177e4SLinus Torvalds 	}
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	if (start)
3451da177e4SLinus Torvalds 		*start = buffer;
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds 	info.buffer	= buffer;
3481da177e4SLinus Torvalds 	info.length	= length;
3491da177e4SLinus Torvalds 	info.offset	= offset;
3501da177e4SLinus Torvalds 	info.pos	= 0;
3511da177e4SLinus Torvalds 
3521da177e4SLinus Torvalds 	copy_info(&info, "Adaptec AIC79xx driver version: %s\n",
3531da177e4SLinus Torvalds 		  AIC79XX_DRIVER_VERSION);
3541da177e4SLinus Torvalds 	copy_info(&info, "%s\n", ahd->description);
3551da177e4SLinus Torvalds 	ahd_controller_info(ahd, ahd_info);
3561da177e4SLinus Torvalds 	copy_info(&info, "%s\n", ahd_info);
3571da177e4SLinus Torvalds 	copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
3581da177e4SLinus Torvalds 		  ahd->scb_data.numscbs, AHD_NSEG);
3591da177e4SLinus Torvalds 
3601da177e4SLinus Torvalds 	max_targ = 15;
3611da177e4SLinus Torvalds 
3621da177e4SLinus Torvalds 	if (ahd->seep_config == NULL)
3631da177e4SLinus Torvalds 		copy_info(&info, "No Serial EEPROM\n");
3641da177e4SLinus Torvalds 	else {
3651da177e4SLinus Torvalds 		copy_info(&info, "Serial EEPROM:\n");
3661da177e4SLinus Torvalds 		for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) {
3671da177e4SLinus Torvalds 			if (((i % 8) == 0) && (i != 0)) {
3681da177e4SLinus Torvalds 				copy_info(&info, "\n");
3691da177e4SLinus Torvalds 			}
3701da177e4SLinus Torvalds 			copy_info(&info, "0x%.4x ",
3711da177e4SLinus Torvalds 				  ((uint16_t*)ahd->seep_config)[i]);
3721da177e4SLinus Torvalds 		}
3731da177e4SLinus Torvalds 		copy_info(&info, "\n");
3741da177e4SLinus Torvalds 	}
3751da177e4SLinus Torvalds 	copy_info(&info, "\n");
3761da177e4SLinus Torvalds 
3771da177e4SLinus Torvalds 	if ((ahd->features & AHD_WIDE) == 0)
3781da177e4SLinus Torvalds 		max_targ = 7;
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds 	for (i = 0; i <= max_targ; i++) {
3811da177e4SLinus Torvalds 
3821da177e4SLinus Torvalds 		ahd_dump_target_state(ahd, &info, ahd->our_id, 'A',
3831da177e4SLinus Torvalds 				      /*target_id*/i, /*target_offset*/i);
3841da177e4SLinus Torvalds 	}
3851da177e4SLinus Torvalds 	retval = info.pos > info.offset ? info.pos - info.offset : 0;
3861da177e4SLinus Torvalds done:
3871da177e4SLinus Torvalds 	return (retval);
3881da177e4SLinus Torvalds }
389