18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2000-2001 Adaptec Inc. 38c2ecf20Sopenharmony_ci * All rights reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 68c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 78c2ecf20Sopenharmony_ci * are met: 88c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 98c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 108c2ecf20Sopenharmony_ci * without modification. 118c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer 128c2ecf20Sopenharmony_ci * substantially similar to the "NO WARRANTY" disclaimer below 138c2ecf20Sopenharmony_ci * ("Disclaimer") and any redistribution must be conditioned upon 148c2ecf20Sopenharmony_ci * including a substantially similar Disclaimer requirement for further 158c2ecf20Sopenharmony_ci * binary redistribution. 168c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names 178c2ecf20Sopenharmony_ci * of any contributors may be used to endorse or promote products derived 188c2ecf20Sopenharmony_ci * from this software without specific prior written permission. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 218c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 228c2ecf20Sopenharmony_ci * Software Foundation. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * NO WARRANTY 258c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 268c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 278c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 288c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 298c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 308c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 318c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 328c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 338c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 348c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 358c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES. 368c2ecf20Sopenharmony_ci * 378c2ecf20Sopenharmony_ci * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr> 388c2ecf20Sopenharmony_ci * sym driver. 398c2ecf20Sopenharmony_ci * 408c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_proc.c#19 $ 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_ci#include "aic79xx_osm.h" 438c2ecf20Sopenharmony_ci#include "aic79xx_inline.h" 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistatic void ahd_dump_target_state(struct ahd_softc *ahd, 468c2ecf20Sopenharmony_ci struct seq_file *m, 478c2ecf20Sopenharmony_ci u_int our_id, char channel, 488c2ecf20Sopenharmony_ci u_int target_id); 498c2ecf20Sopenharmony_cistatic void ahd_dump_device_state(struct seq_file *m, 508c2ecf20Sopenharmony_ci struct scsi_device *sdev); 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci/* 538c2ecf20Sopenharmony_ci * Table of syncrates that don't follow the "divisible by 4" 548c2ecf20Sopenharmony_ci * rule. This table will be expanded in future SCSI specs. 558c2ecf20Sopenharmony_ci */ 568c2ecf20Sopenharmony_cistatic const struct { 578c2ecf20Sopenharmony_ci u_int period_factor; 588c2ecf20Sopenharmony_ci u_int period; /* in 100ths of ns */ 598c2ecf20Sopenharmony_ci} scsi_syncrates[] = { 608c2ecf20Sopenharmony_ci { 0x08, 625 }, /* FAST-160 */ 618c2ecf20Sopenharmony_ci { 0x09, 1250 }, /* FAST-80 */ 628c2ecf20Sopenharmony_ci { 0x0a, 2500 }, /* FAST-40 40MHz */ 638c2ecf20Sopenharmony_ci { 0x0b, 3030 }, /* FAST-40 33MHz */ 648c2ecf20Sopenharmony_ci { 0x0c, 5000 } /* FAST-20 */ 658c2ecf20Sopenharmony_ci}; 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* 688c2ecf20Sopenharmony_ci * Return the frequency in kHz corresponding to the given 698c2ecf20Sopenharmony_ci * sync period factor. 708c2ecf20Sopenharmony_ci */ 718c2ecf20Sopenharmony_cistatic u_int 728c2ecf20Sopenharmony_ciahd_calc_syncsrate(u_int period_factor) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci int i; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci /* See if the period is in the "exception" table */ 778c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) { 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci if (period_factor == scsi_syncrates[i].period_factor) { 808c2ecf20Sopenharmony_ci /* Period in kHz */ 818c2ecf20Sopenharmony_ci return (100000000 / scsi_syncrates[i].period); 828c2ecf20Sopenharmony_ci } 838c2ecf20Sopenharmony_ci } 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci /* 868c2ecf20Sopenharmony_ci * Wasn't in the table, so use the standard 878c2ecf20Sopenharmony_ci * 4 times conversion. 888c2ecf20Sopenharmony_ci */ 898c2ecf20Sopenharmony_ci return (10000000 / (period_factor * 4 * 10)); 908c2ecf20Sopenharmony_ci} 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_cistatic void 938c2ecf20Sopenharmony_ciahd_format_transinfo(struct seq_file *m, struct ahd_transinfo *tinfo) 948c2ecf20Sopenharmony_ci{ 958c2ecf20Sopenharmony_ci u_int speed; 968c2ecf20Sopenharmony_ci u_int freq; 978c2ecf20Sopenharmony_ci u_int mb; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci if (tinfo->period == AHD_PERIOD_UNKNOWN) { 1008c2ecf20Sopenharmony_ci seq_puts(m, "Renegotiation Pending\n"); 1018c2ecf20Sopenharmony_ci return; 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci speed = 3300; 1048c2ecf20Sopenharmony_ci freq = 0; 1058c2ecf20Sopenharmony_ci if (tinfo->offset != 0) { 1068c2ecf20Sopenharmony_ci freq = ahd_calc_syncsrate(tinfo->period); 1078c2ecf20Sopenharmony_ci speed = freq; 1088c2ecf20Sopenharmony_ci } 1098c2ecf20Sopenharmony_ci speed *= (0x01 << tinfo->width); 1108c2ecf20Sopenharmony_ci mb = speed / 1000; 1118c2ecf20Sopenharmony_ci if (mb > 0) 1128c2ecf20Sopenharmony_ci seq_printf(m, "%d.%03dMB/s transfers", mb, speed % 1000); 1138c2ecf20Sopenharmony_ci else 1148c2ecf20Sopenharmony_ci seq_printf(m, "%dKB/s transfers", speed); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci if (freq != 0) { 1178c2ecf20Sopenharmony_ci int printed_options; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci printed_options = 0; 1208c2ecf20Sopenharmony_ci seq_printf(m, " (%d.%03dMHz", freq / 1000, freq % 1000); 1218c2ecf20Sopenharmony_ci if ((tinfo->ppr_options & MSG_EXT_PPR_RD_STRM) != 0) { 1228c2ecf20Sopenharmony_ci seq_puts(m, " RDSTRM"); 1238c2ecf20Sopenharmony_ci printed_options++; 1248c2ecf20Sopenharmony_ci } 1258c2ecf20Sopenharmony_ci if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) { 1268c2ecf20Sopenharmony_ci seq_puts(m, printed_options ? "|DT" : " DT"); 1278c2ecf20Sopenharmony_ci printed_options++; 1288c2ecf20Sopenharmony_ci } 1298c2ecf20Sopenharmony_ci if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) { 1308c2ecf20Sopenharmony_ci seq_puts(m, printed_options ? "|IU" : " IU"); 1318c2ecf20Sopenharmony_ci printed_options++; 1328c2ecf20Sopenharmony_ci } 1338c2ecf20Sopenharmony_ci if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) { 1348c2ecf20Sopenharmony_ci seq_puts(m, printed_options ? "|RTI" : " RTI"); 1358c2ecf20Sopenharmony_ci printed_options++; 1368c2ecf20Sopenharmony_ci } 1378c2ecf20Sopenharmony_ci if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) { 1388c2ecf20Sopenharmony_ci seq_puts(m, printed_options ? "|QAS" : " QAS"); 1398c2ecf20Sopenharmony_ci printed_options++; 1408c2ecf20Sopenharmony_ci } 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci if (tinfo->width > 0) { 1448c2ecf20Sopenharmony_ci if (freq != 0) { 1458c2ecf20Sopenharmony_ci seq_puts(m, ", "); 1468c2ecf20Sopenharmony_ci } else { 1478c2ecf20Sopenharmony_ci seq_puts(m, " ("); 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci seq_printf(m, "%dbit)", 8 * (0x01 << tinfo->width)); 1508c2ecf20Sopenharmony_ci } else if (freq != 0) { 1518c2ecf20Sopenharmony_ci seq_putc(m, ')'); 1528c2ecf20Sopenharmony_ci } 1538c2ecf20Sopenharmony_ci seq_putc(m, '\n'); 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistatic void 1578c2ecf20Sopenharmony_ciahd_dump_target_state(struct ahd_softc *ahd, struct seq_file *m, 1588c2ecf20Sopenharmony_ci u_int our_id, char channel, u_int target_id) 1598c2ecf20Sopenharmony_ci{ 1608c2ecf20Sopenharmony_ci struct scsi_target *starget; 1618c2ecf20Sopenharmony_ci struct ahd_initiator_tinfo *tinfo; 1628c2ecf20Sopenharmony_ci struct ahd_tmode_tstate *tstate; 1638c2ecf20Sopenharmony_ci int lun; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci tinfo = ahd_fetch_transinfo(ahd, channel, our_id, 1668c2ecf20Sopenharmony_ci target_id, &tstate); 1678c2ecf20Sopenharmony_ci seq_printf(m, "Target %d Negotiation Settings\n", target_id); 1688c2ecf20Sopenharmony_ci seq_puts(m, "\tUser: "); 1698c2ecf20Sopenharmony_ci ahd_format_transinfo(m, &tinfo->user); 1708c2ecf20Sopenharmony_ci starget = ahd->platform_data->starget[target_id]; 1718c2ecf20Sopenharmony_ci if (starget == NULL) 1728c2ecf20Sopenharmony_ci return; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci seq_puts(m, "\tGoal: "); 1758c2ecf20Sopenharmony_ci ahd_format_transinfo(m, &tinfo->goal); 1768c2ecf20Sopenharmony_ci seq_puts(m, "\tCurr: "); 1778c2ecf20Sopenharmony_ci ahd_format_transinfo(m, &tinfo->curr); 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci for (lun = 0; lun < AHD_NUM_LUNS; lun++) { 1808c2ecf20Sopenharmony_ci struct scsi_device *dev; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci dev = scsi_device_lookup_by_target(starget, lun); 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci if (dev == NULL) 1858c2ecf20Sopenharmony_ci continue; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci ahd_dump_device_state(m, dev); 1888c2ecf20Sopenharmony_ci } 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic void 1928c2ecf20Sopenharmony_ciahd_dump_device_state(struct seq_file *m, struct scsi_device *sdev) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci struct ahd_linux_device *dev = scsi_transport_device_data(sdev); 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ci seq_printf(m, "\tChannel %c Target %d Lun %d Settings\n", 1978c2ecf20Sopenharmony_ci sdev->sdev_target->channel + 'A', 1988c2ecf20Sopenharmony_ci sdev->sdev_target->id, (u8)sdev->lun); 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci seq_printf(m, "\t\tCommands Queued %ld\n", dev->commands_issued); 2018c2ecf20Sopenharmony_ci seq_printf(m, "\t\tCommands Active %d\n", dev->active); 2028c2ecf20Sopenharmony_ci seq_printf(m, "\t\tCommand Openings %d\n", dev->openings); 2038c2ecf20Sopenharmony_ci seq_printf(m, "\t\tMax Tagged Openings %d\n", dev->maxtags); 2048c2ecf20Sopenharmony_ci seq_printf(m, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen); 2058c2ecf20Sopenharmony_ci} 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ciint 2088c2ecf20Sopenharmony_ciahd_proc_write_seeprom(struct Scsi_Host *shost, char *buffer, int length) 2098c2ecf20Sopenharmony_ci{ 2108c2ecf20Sopenharmony_ci struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata; 2118c2ecf20Sopenharmony_ci ahd_mode_state saved_modes; 2128c2ecf20Sopenharmony_ci int have_seeprom; 2138c2ecf20Sopenharmony_ci u_long s; 2148c2ecf20Sopenharmony_ci int paused; 2158c2ecf20Sopenharmony_ci int written; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci /* Default to failure. */ 2188c2ecf20Sopenharmony_ci written = -EINVAL; 2198c2ecf20Sopenharmony_ci ahd_lock(ahd, &s); 2208c2ecf20Sopenharmony_ci paused = ahd_is_paused(ahd); 2218c2ecf20Sopenharmony_ci if (!paused) 2228c2ecf20Sopenharmony_ci ahd_pause(ahd); 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci saved_modes = ahd_save_modes(ahd); 2258c2ecf20Sopenharmony_ci ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI); 2268c2ecf20Sopenharmony_ci if (length != sizeof(struct seeprom_config)) { 2278c2ecf20Sopenharmony_ci printk("ahd_proc_write_seeprom: incorrect buffer size\n"); 2288c2ecf20Sopenharmony_ci goto done; 2298c2ecf20Sopenharmony_ci } 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer); 2328c2ecf20Sopenharmony_ci if (have_seeprom == 0) { 2338c2ecf20Sopenharmony_ci printk("ahd_proc_write_seeprom: cksum verification failed\n"); 2348c2ecf20Sopenharmony_ci goto done; 2358c2ecf20Sopenharmony_ci } 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci have_seeprom = ahd_acquire_seeprom(ahd); 2388c2ecf20Sopenharmony_ci if (!have_seeprom) { 2398c2ecf20Sopenharmony_ci printk("ahd_proc_write_seeprom: No Serial EEPROM\n"); 2408c2ecf20Sopenharmony_ci goto done; 2418c2ecf20Sopenharmony_ci } else { 2428c2ecf20Sopenharmony_ci u_int start_addr; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci if (ahd->seep_config == NULL) { 2458c2ecf20Sopenharmony_ci ahd->seep_config = kmalloc(sizeof(*ahd->seep_config), GFP_ATOMIC); 2468c2ecf20Sopenharmony_ci if (ahd->seep_config == NULL) { 2478c2ecf20Sopenharmony_ci printk("aic79xx: Unable to allocate serial " 2488c2ecf20Sopenharmony_ci "eeprom buffer. Write failing\n"); 2498c2ecf20Sopenharmony_ci goto done; 2508c2ecf20Sopenharmony_ci } 2518c2ecf20Sopenharmony_ci } 2528c2ecf20Sopenharmony_ci printk("aic79xx: Writing Serial EEPROM\n"); 2538c2ecf20Sopenharmony_ci start_addr = 32 * (ahd->channel - 'A'); 2548c2ecf20Sopenharmony_ci ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr, 2558c2ecf20Sopenharmony_ci sizeof(struct seeprom_config)/2); 2568c2ecf20Sopenharmony_ci ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config, 2578c2ecf20Sopenharmony_ci start_addr, sizeof(struct seeprom_config)/2, 2588c2ecf20Sopenharmony_ci /*ByteStream*/FALSE); 2598c2ecf20Sopenharmony_ci ahd_release_seeprom(ahd); 2608c2ecf20Sopenharmony_ci written = length; 2618c2ecf20Sopenharmony_ci } 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cidone: 2648c2ecf20Sopenharmony_ci ahd_restore_modes(ahd, saved_modes); 2658c2ecf20Sopenharmony_ci if (!paused) 2668c2ecf20Sopenharmony_ci ahd_unpause(ahd); 2678c2ecf20Sopenharmony_ci ahd_unlock(ahd, &s); 2688c2ecf20Sopenharmony_ci return (written); 2698c2ecf20Sopenharmony_ci} 2708c2ecf20Sopenharmony_ci/* 2718c2ecf20Sopenharmony_ci * Return information to handle /proc support for the driver. 2728c2ecf20Sopenharmony_ci */ 2738c2ecf20Sopenharmony_ciint 2748c2ecf20Sopenharmony_ciahd_linux_show_info(struct seq_file *m, struct Scsi_Host *shost) 2758c2ecf20Sopenharmony_ci{ 2768c2ecf20Sopenharmony_ci struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata; 2778c2ecf20Sopenharmony_ci char ahd_info[256]; 2788c2ecf20Sopenharmony_ci u_int max_targ; 2798c2ecf20Sopenharmony_ci u_int i; 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci seq_printf(m, "Adaptec AIC79xx driver version: %s\n", 2828c2ecf20Sopenharmony_ci AIC79XX_DRIVER_VERSION); 2838c2ecf20Sopenharmony_ci seq_printf(m, "%s\n", ahd->description); 2848c2ecf20Sopenharmony_ci ahd_controller_info(ahd, ahd_info); 2858c2ecf20Sopenharmony_ci seq_printf(m, "%s\n", ahd_info); 2868c2ecf20Sopenharmony_ci seq_printf(m, "Allocated SCBs: %d, SG List Length: %d\n\n", 2878c2ecf20Sopenharmony_ci ahd->scb_data.numscbs, AHD_NSEG); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci max_targ = 16; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci if (ahd->seep_config == NULL) 2928c2ecf20Sopenharmony_ci seq_puts(m, "No Serial EEPROM\n"); 2938c2ecf20Sopenharmony_ci else { 2948c2ecf20Sopenharmony_ci seq_puts(m, "Serial EEPROM:\n"); 2958c2ecf20Sopenharmony_ci for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) { 2968c2ecf20Sopenharmony_ci if (((i % 8) == 0) && (i != 0)) { 2978c2ecf20Sopenharmony_ci seq_putc(m, '\n'); 2988c2ecf20Sopenharmony_ci } 2998c2ecf20Sopenharmony_ci seq_printf(m, "0x%.4x ", 3008c2ecf20Sopenharmony_ci ((uint16_t*)ahd->seep_config)[i]); 3018c2ecf20Sopenharmony_ci } 3028c2ecf20Sopenharmony_ci seq_putc(m, '\n'); 3038c2ecf20Sopenharmony_ci } 3048c2ecf20Sopenharmony_ci seq_putc(m, '\n'); 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci if ((ahd->features & AHD_WIDE) == 0) 3078c2ecf20Sopenharmony_ci max_targ = 8; 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_ci for (i = 0; i < max_targ; i++) { 3108c2ecf20Sopenharmony_ci 3118c2ecf20Sopenharmony_ci ahd_dump_target_state(ahd, m, ahd->our_id, 'A', 3128c2ecf20Sopenharmony_ci /*target_id*/i); 3138c2ecf20Sopenharmony_ci } 3148c2ecf20Sopenharmony_ci return 0; 3158c2ecf20Sopenharmony_ci} 316