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 ahd_dump_target_state(struct ahd_softc *ahd,
46f6f83a6cSAl Viro struct seq_file *m,
471da177e4SLinus Torvalds u_int our_id, char channel,
48f89d0a4eSHannes Reinecke u_int target_id);
49f6f83a6cSAl Viro static void ahd_dump_device_state(struct seq_file *m,
5073a25462SHannes Reinecke struct scsi_device *sdev);
511da177e4SLinus Torvalds
521ff92730SChristoph Hellwig /*
531ff92730SChristoph Hellwig * Table of syncrates that don't follow the "divisible by 4"
541ff92730SChristoph Hellwig * rule. This table will be expanded in future SCSI specs.
551ff92730SChristoph Hellwig */
56980b306aSDenys Vlasenko static const struct {
571ff92730SChristoph Hellwig u_int period_factor;
581ff92730SChristoph Hellwig u_int period; /* in 100ths of ns */
591ff92730SChristoph Hellwig } scsi_syncrates[] = {
601ff92730SChristoph Hellwig { 0x08, 625 }, /* FAST-160 */
611ff92730SChristoph Hellwig { 0x09, 1250 }, /* FAST-80 */
621ff92730SChristoph Hellwig { 0x0a, 2500 }, /* FAST-40 40MHz */
631ff92730SChristoph Hellwig { 0x0b, 3030 }, /* FAST-40 33MHz */
641ff92730SChristoph Hellwig { 0x0c, 5000 } /* FAST-20 */
651ff92730SChristoph Hellwig };
661ff92730SChristoph Hellwig
671ff92730SChristoph Hellwig /*
681ff92730SChristoph Hellwig * Return the frequency in kHz corresponding to the given
691ff92730SChristoph Hellwig * sync period factor.
701ff92730SChristoph Hellwig */
711ff92730SChristoph Hellwig static u_int
ahd_calc_syncsrate(u_int period_factor)721ff92730SChristoph Hellwig ahd_calc_syncsrate(u_int period_factor)
731ff92730SChristoph Hellwig {
741ff92730SChristoph Hellwig int i;
751ff92730SChristoph Hellwig
761ff92730SChristoph Hellwig /* See if the period is in the "exception" table */
776391a113STobias Klauser for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) {
781ff92730SChristoph Hellwig
791ff92730SChristoph Hellwig if (period_factor == scsi_syncrates[i].period_factor) {
801ff92730SChristoph Hellwig /* Period in kHz */
811ff92730SChristoph Hellwig return (100000000 / scsi_syncrates[i].period);
821ff92730SChristoph Hellwig }
831ff92730SChristoph Hellwig }
841ff92730SChristoph Hellwig
851ff92730SChristoph Hellwig /*
861ff92730SChristoph Hellwig * Wasn't in the table, so use the standard
871ff92730SChristoph Hellwig * 4 times conversion.
881ff92730SChristoph Hellwig */
891ff92730SChristoph Hellwig return (10000000 / (period_factor * 4 * 10));
901ff92730SChristoph Hellwig }
911ff92730SChristoph Hellwig
921da177e4SLinus Torvalds static void
ahd_format_transinfo(struct seq_file * m,struct ahd_transinfo * tinfo)93f6f83a6cSAl Viro ahd_format_transinfo(struct seq_file *m, struct ahd_transinfo *tinfo)
941da177e4SLinus Torvalds {
951da177e4SLinus Torvalds u_int speed;
961da177e4SLinus Torvalds u_int freq;
971da177e4SLinus Torvalds u_int mb;
981da177e4SLinus Torvalds
991da177e4SLinus Torvalds if (tinfo->period == AHD_PERIOD_UNKNOWN) {
10091c40f24SRasmus Villemoes seq_puts(m, "Renegotiation Pending\n");
1011da177e4SLinus Torvalds return;
1021da177e4SLinus Torvalds }
1031da177e4SLinus Torvalds speed = 3300;
1041da177e4SLinus Torvalds freq = 0;
1051da177e4SLinus Torvalds if (tinfo->offset != 0) {
1061ff92730SChristoph Hellwig freq = ahd_calc_syncsrate(tinfo->period);
1071da177e4SLinus Torvalds speed = freq;
1081da177e4SLinus Torvalds }
1091da177e4SLinus Torvalds speed *= (0x01 << tinfo->width);
1101da177e4SLinus Torvalds mb = speed / 1000;
1111da177e4SLinus Torvalds if (mb > 0)
112f6f83a6cSAl Viro seq_printf(m, "%d.%03dMB/s transfers", mb, speed % 1000);
1131da177e4SLinus Torvalds else
114f6f83a6cSAl Viro seq_printf(m, "%dKB/s transfers", speed);
1151da177e4SLinus Torvalds
1161da177e4SLinus Torvalds if (freq != 0) {
1171da177e4SLinus Torvalds int printed_options;
1181da177e4SLinus Torvalds
1191da177e4SLinus Torvalds printed_options = 0;
120f6f83a6cSAl Viro seq_printf(m, " (%d.%03dMHz", freq / 1000, freq % 1000);
1211da177e4SLinus Torvalds if ((tinfo->ppr_options & MSG_EXT_PPR_RD_STRM) != 0) {
12291c40f24SRasmus Villemoes seq_puts(m, " RDSTRM");
1231da177e4SLinus Torvalds printed_options++;
1241da177e4SLinus Torvalds }
1251da177e4SLinus Torvalds if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
12691c40f24SRasmus Villemoes seq_puts(m, printed_options ? "|DT" : " DT");
1271da177e4SLinus Torvalds printed_options++;
1281da177e4SLinus Torvalds }
1291da177e4SLinus Torvalds if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
13091c40f24SRasmus Villemoes seq_puts(m, printed_options ? "|IU" : " IU");
1311da177e4SLinus Torvalds printed_options++;
1321da177e4SLinus Torvalds }
1331da177e4SLinus Torvalds if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) {
13491c40f24SRasmus Villemoes seq_puts(m, printed_options ? "|RTI" : " RTI");
1351da177e4SLinus Torvalds printed_options++;
1361da177e4SLinus Torvalds }
1371da177e4SLinus Torvalds if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
13891c40f24SRasmus Villemoes seq_puts(m, printed_options ? "|QAS" : " QAS");
1391da177e4SLinus Torvalds printed_options++;
1401da177e4SLinus Torvalds }
1411da177e4SLinus Torvalds }
1421da177e4SLinus Torvalds
1431da177e4SLinus Torvalds if (tinfo->width > 0) {
1441da177e4SLinus Torvalds if (freq != 0) {
14591c40f24SRasmus Villemoes seq_puts(m, ", ");
1461da177e4SLinus Torvalds } else {
14791c40f24SRasmus Villemoes seq_puts(m, " (");
1481da177e4SLinus Torvalds }
149f6f83a6cSAl Viro seq_printf(m, "%dbit)", 8 * (0x01 << tinfo->width));
1501da177e4SLinus Torvalds } else if (freq != 0) {
151f50332ffSRasmus Villemoes seq_putc(m, ')');
1521da177e4SLinus Torvalds }
153f50332ffSRasmus Villemoes seq_putc(m, '\n');
1541da177e4SLinus Torvalds }
1551da177e4SLinus Torvalds
1561da177e4SLinus Torvalds static void
ahd_dump_target_state(struct ahd_softc * ahd,struct seq_file * m,u_int our_id,char channel,u_int target_id)157f6f83a6cSAl Viro ahd_dump_target_state(struct ahd_softc *ahd, struct seq_file *m,
158f89d0a4eSHannes Reinecke u_int our_id, char channel, u_int target_id)
1591da177e4SLinus Torvalds {
16073a25462SHannes Reinecke struct scsi_target *starget;
1611da177e4SLinus Torvalds struct ahd_initiator_tinfo *tinfo;
1621da177e4SLinus Torvalds struct ahd_tmode_tstate *tstate;
1631da177e4SLinus Torvalds int lun;
1641da177e4SLinus Torvalds
1651da177e4SLinus Torvalds tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
1661da177e4SLinus Torvalds target_id, &tstate);
167f6f83a6cSAl Viro seq_printf(m, "Target %d Negotiation Settings\n", target_id);
16891c40f24SRasmus Villemoes seq_puts(m, "\tUser: ");
169f6f83a6cSAl Viro ahd_format_transinfo(m, &tinfo->user);
170f89d0a4eSHannes Reinecke starget = ahd->platform_data->starget[target_id];
1713f40d7d6SJames Bottomley if (starget == NULL)
1721da177e4SLinus Torvalds return;
1731da177e4SLinus Torvalds
17491c40f24SRasmus Villemoes seq_puts(m, "\tGoal: ");
175f6f83a6cSAl Viro ahd_format_transinfo(m, &tinfo->goal);
17691c40f24SRasmus Villemoes seq_puts(m, "\tCurr: ");
177f6f83a6cSAl Viro ahd_format_transinfo(m, &tinfo->curr);
1781da177e4SLinus Torvalds
1791da177e4SLinus Torvalds for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
18073a25462SHannes Reinecke struct scsi_device *dev;
1811da177e4SLinus Torvalds
182f89d0a4eSHannes Reinecke dev = scsi_device_lookup_by_target(starget, lun);
1831da177e4SLinus Torvalds
1841da177e4SLinus Torvalds if (dev == NULL)
1851da177e4SLinus Torvalds continue;
1861da177e4SLinus Torvalds
187f6f83a6cSAl Viro ahd_dump_device_state(m, dev);
1881da177e4SLinus Torvalds }
1891da177e4SLinus Torvalds }
1901da177e4SLinus Torvalds
1911da177e4SLinus Torvalds static void
ahd_dump_device_state(struct seq_file * m,struct scsi_device * sdev)192f6f83a6cSAl Viro ahd_dump_device_state(struct seq_file *m, struct scsi_device *sdev)
1931da177e4SLinus Torvalds {
19473a25462SHannes Reinecke struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
19573a25462SHannes Reinecke
196f6f83a6cSAl Viro seq_printf(m, "\tChannel %c Target %d Lun %d Settings\n",
19773a25462SHannes Reinecke sdev->sdev_target->channel + 'A',
1989cb78c16SHannes Reinecke sdev->sdev_target->id, (u8)sdev->lun);
1991da177e4SLinus Torvalds
200f6f83a6cSAl Viro seq_printf(m, "\t\tCommands Queued %ld\n", dev->commands_issued);
201f6f83a6cSAl Viro seq_printf(m, "\t\tCommands Active %d\n", dev->active);
202f6f83a6cSAl Viro seq_printf(m, "\t\tCommand Openings %d\n", dev->openings);
203f6f83a6cSAl Viro seq_printf(m, "\t\tMax Tagged Openings %d\n", dev->maxtags);
204f6f83a6cSAl Viro seq_printf(m, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
2051da177e4SLinus Torvalds }
2061da177e4SLinus Torvalds
207f6f83a6cSAl Viro int
ahd_proc_write_seeprom(struct Scsi_Host * shost,char * buffer,int length)208f6f83a6cSAl Viro ahd_proc_write_seeprom(struct Scsi_Host *shost, char *buffer, int length)
2091da177e4SLinus Torvalds {
210f6f83a6cSAl Viro struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
2111da177e4SLinus Torvalds ahd_mode_state saved_modes;
2121da177e4SLinus Torvalds int have_seeprom;
2131da177e4SLinus Torvalds u_long s;
2141da177e4SLinus Torvalds int paused;
2151da177e4SLinus Torvalds int written;
2161da177e4SLinus Torvalds
2171da177e4SLinus Torvalds /* Default to failure. */
2181da177e4SLinus Torvalds written = -EINVAL;
2191da177e4SLinus Torvalds ahd_lock(ahd, &s);
2201da177e4SLinus Torvalds paused = ahd_is_paused(ahd);
2211da177e4SLinus Torvalds if (!paused)
2221da177e4SLinus Torvalds ahd_pause(ahd);
2231da177e4SLinus Torvalds
2241da177e4SLinus Torvalds saved_modes = ahd_save_modes(ahd);
2251da177e4SLinus Torvalds ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
2261da177e4SLinus Torvalds if (length != sizeof(struct seeprom_config)) {
22748813cf9SPekka Enberg printk("ahd_proc_write_seeprom: incorrect buffer size\n");
2281da177e4SLinus Torvalds goto done;
2291da177e4SLinus Torvalds }
2301da177e4SLinus Torvalds
2311da177e4SLinus Torvalds have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer);
2321da177e4SLinus Torvalds if (have_seeprom == 0) {
23348813cf9SPekka Enberg printk("ahd_proc_write_seeprom: cksum verification failed\n");
2341da177e4SLinus Torvalds goto done;
2351da177e4SLinus Torvalds }
2361da177e4SLinus Torvalds
2371da177e4SLinus Torvalds have_seeprom = ahd_acquire_seeprom(ahd);
2381da177e4SLinus Torvalds if (!have_seeprom) {
23948813cf9SPekka Enberg printk("ahd_proc_write_seeprom: No Serial EEPROM\n");
2401da177e4SLinus Torvalds goto done;
2411da177e4SLinus Torvalds } else {
2421da177e4SLinus Torvalds u_int start_addr;
2431da177e4SLinus Torvalds
2441da177e4SLinus Torvalds if (ahd->seep_config == NULL) {
245*7662d923SHannes Reinecke ahd->seep_config = kmalloc(sizeof(*ahd->seep_config),
246*7662d923SHannes Reinecke GFP_ATOMIC);
2471da177e4SLinus Torvalds if (ahd->seep_config == NULL) {
24848813cf9SPekka Enberg printk("aic79xx: Unable to allocate serial "
2491da177e4SLinus Torvalds "eeprom buffer. Write failing\n");
2501da177e4SLinus Torvalds goto done;
2511da177e4SLinus Torvalds }
2521da177e4SLinus Torvalds }
25348813cf9SPekka Enberg printk("aic79xx: Writing Serial EEPROM\n");
2541da177e4SLinus Torvalds start_addr = 32 * (ahd->channel - 'A');
2551da177e4SLinus Torvalds ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr,
2561da177e4SLinus Torvalds sizeof(struct seeprom_config)/2);
2571da177e4SLinus Torvalds ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config,
2581da177e4SLinus Torvalds start_addr, sizeof(struct seeprom_config)/2,
2591da177e4SLinus Torvalds /*ByteStream*/FALSE);
2601da177e4SLinus Torvalds ahd_release_seeprom(ahd);
2611da177e4SLinus Torvalds written = length;
2621da177e4SLinus Torvalds }
2631da177e4SLinus Torvalds
2641da177e4SLinus Torvalds done:
2651da177e4SLinus Torvalds ahd_restore_modes(ahd, saved_modes);
2661da177e4SLinus Torvalds if (!paused)
2671da177e4SLinus Torvalds ahd_unpause(ahd);
2681da177e4SLinus Torvalds ahd_unlock(ahd, &s);
2691da177e4SLinus Torvalds return (written);
2701da177e4SLinus Torvalds }
2711da177e4SLinus Torvalds /*
2721da177e4SLinus Torvalds * Return information to handle /proc support for the driver.
2731da177e4SLinus Torvalds */
2741da177e4SLinus Torvalds int
ahd_linux_show_info(struct seq_file * m,struct Scsi_Host * shost)275f6f83a6cSAl Viro ahd_linux_show_info(struct seq_file *m, struct Scsi_Host *shost)
2761da177e4SLinus Torvalds {
27785a46523SChristoph Hellwig struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
2781da177e4SLinus Torvalds char ahd_info[256];
2791da177e4SLinus Torvalds u_int max_targ;
2801da177e4SLinus Torvalds u_int i;
2811da177e4SLinus Torvalds
282f6f83a6cSAl Viro seq_printf(m, "Adaptec AIC79xx driver version: %s\n",
2831da177e4SLinus Torvalds AIC79XX_DRIVER_VERSION);
284f6f83a6cSAl Viro seq_printf(m, "%s\n", ahd->description);
2851da177e4SLinus Torvalds ahd_controller_info(ahd, ahd_info);
286f6f83a6cSAl Viro seq_printf(m, "%s\n", ahd_info);
287f6f83a6cSAl Viro seq_printf(m, "Allocated SCBs: %d, SG List Length: %d\n\n",
2881da177e4SLinus Torvalds ahd->scb_data.numscbs, AHD_NSEG);
2891da177e4SLinus Torvalds
290f89d0a4eSHannes Reinecke max_targ = 16;
2911da177e4SLinus Torvalds
2921da177e4SLinus Torvalds if (ahd->seep_config == NULL)
29391c40f24SRasmus Villemoes seq_puts(m, "No Serial EEPROM\n");
2941da177e4SLinus Torvalds else {
29591c40f24SRasmus Villemoes seq_puts(m, "Serial EEPROM:\n");
2961da177e4SLinus Torvalds for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) {
2971da177e4SLinus Torvalds if (((i % 8) == 0) && (i != 0)) {
298f50332ffSRasmus Villemoes seq_putc(m, '\n');
2991da177e4SLinus Torvalds }
300f6f83a6cSAl Viro seq_printf(m, "0x%.4x ",
3011da177e4SLinus Torvalds ((uint16_t*)ahd->seep_config)[i]);
3021da177e4SLinus Torvalds }
303f50332ffSRasmus Villemoes seq_putc(m, '\n');
3041da177e4SLinus Torvalds }
305f50332ffSRasmus Villemoes seq_putc(m, '\n');
3061da177e4SLinus Torvalds
3071da177e4SLinus Torvalds if ((ahd->features & AHD_WIDE) == 0)
308f89d0a4eSHannes Reinecke max_targ = 8;
3091da177e4SLinus Torvalds
310f89d0a4eSHannes Reinecke for (i = 0; i < max_targ; i++) {
3111da177e4SLinus Torvalds
312f6f83a6cSAl Viro ahd_dump_target_state(ahd, m, ahd->our_id, 'A',
313f89d0a4eSHannes Reinecke /*target_id*/i);
3141da177e4SLinus Torvalds }
315f6f83a6cSAl Viro return 0;
3161da177e4SLinus Torvalds }
317