blob: 27dbfccea77473c3cb68699abb24752b9e8e2f84 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) 2000-2001 Adaptec Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * substantially similar to the "NO WARRANTY" disclaimer below
13 * ("Disclaimer") and any redistribution must be conditioned upon
14 * including a substantially similar Disclaimer requirement for further
15 * binary redistribution.
16 * 3. Neither the names of the above-listed copyright holders nor the names
17 * of any contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * NO WARRANTY
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGES.
36 *
37 * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
38 * sym driver.
39 *
40 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic79xx_proc.c#19 $
41 */
42#include "aic79xx_osm.h"
43#include "aic79xx_inline.h"
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static void ahd_dump_target_state(struct ahd_softc *ahd,
Al Virof6f83a62013-03-31 03:59:17 -040046 struct seq_file *m,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 u_int our_id, char channel,
Hannes Reineckef89d0a42006-06-22 11:45:00 +020048 u_int target_id);
Al Virof6f83a62013-03-31 03:59:17 -040049static void ahd_dump_device_state(struct seq_file *m,
Hannes Reinecke73a25462005-07-22 16:44:04 +020050 struct scsi_device *sdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Christoph Hellwig1ff92732005-08-19 18:57:13 +020052/*
53 * Table of syncrates that don't follow the "divisible by 4"
54 * rule. This table will be expanded in future SCSI specs.
55 */
Denys Vlasenko980b3062008-04-25 04:36:01 +020056static const struct {
Christoph Hellwig1ff92732005-08-19 18:57:13 +020057 u_int period_factor;
58 u_int period; /* in 100ths of ns */
59} scsi_syncrates[] = {
60 { 0x08, 625 }, /* FAST-160 */
61 { 0x09, 1250 }, /* FAST-80 */
62 { 0x0a, 2500 }, /* FAST-40 40MHz */
63 { 0x0b, 3030 }, /* FAST-40 33MHz */
64 { 0x0c, 5000 } /* FAST-20 */
65};
66
67/*
68 * Return the frequency in kHz corresponding to the given
69 * sync period factor.
70 */
71static u_int
72ahd_calc_syncsrate(u_int period_factor)
73{
74 int i;
Christoph Hellwig1ff92732005-08-19 18:57:13 +020075
Christoph Hellwig1ff92732005-08-19 18:57:13 +020076 /* See if the period is in the "exception" table */
Tobias Klauser6391a112006-06-08 22:23:48 -070077 for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) {
Christoph Hellwig1ff92732005-08-19 18:57:13 +020078
79 if (period_factor == scsi_syncrates[i].period_factor) {
80 /* Period in kHz */
81 return (100000000 / scsi_syncrates[i].period);
82 }
83 }
84
85 /*
86 * Wasn't in the table, so use the standard
87 * 4 times conversion.
88 */
89 return (10000000 / (period_factor * 4 * 10));
90}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static void
Al Virof6f83a62013-03-31 03:59:17 -040093ahd_format_transinfo(struct seq_file *m, struct ahd_transinfo *tinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
95 u_int speed;
96 u_int freq;
97 u_int mb;
98
99 if (tinfo->period == AHD_PERIOD_UNKNOWN) {
Al Virof6f83a62013-03-31 03:59:17 -0400100 seq_printf(m, "Renegotiation Pending\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return;
102 }
103 speed = 3300;
104 freq = 0;
105 if (tinfo->offset != 0) {
Christoph Hellwig1ff92732005-08-19 18:57:13 +0200106 freq = ahd_calc_syncsrate(tinfo->period);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 speed = freq;
108 }
109 speed *= (0x01 << tinfo->width);
110 mb = speed / 1000;
111 if (mb > 0)
Al Virof6f83a62013-03-31 03:59:17 -0400112 seq_printf(m, "%d.%03dMB/s transfers", mb, speed % 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 else
Al Virof6f83a62013-03-31 03:59:17 -0400114 seq_printf(m, "%dKB/s transfers", speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 if (freq != 0) {
117 int printed_options;
118
119 printed_options = 0;
Al Virof6f83a62013-03-31 03:59:17 -0400120 seq_printf(m, " (%d.%03dMHz", freq / 1000, freq % 1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if ((tinfo->ppr_options & MSG_EXT_PPR_RD_STRM) != 0) {
Al Virof6f83a62013-03-31 03:59:17 -0400122 seq_printf(m, " RDSTRM");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 printed_options++;
124 }
125 if ((tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0) {
Al Virof6f83a62013-03-31 03:59:17 -0400126 seq_printf(m, "%s", printed_options ? "|DT" : " DT");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 printed_options++;
128 }
129 if ((tinfo->ppr_options & MSG_EXT_PPR_IU_REQ) != 0) {
Al Virof6f83a62013-03-31 03:59:17 -0400130 seq_printf(m, "%s", printed_options ? "|IU" : " IU");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 printed_options++;
132 }
133 if ((tinfo->ppr_options & MSG_EXT_PPR_RTI) != 0) {
Al Virof6f83a62013-03-31 03:59:17 -0400134 seq_printf(m, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 printed_options ? "|RTI" : " RTI");
136 printed_options++;
137 }
138 if ((tinfo->ppr_options & MSG_EXT_PPR_QAS_REQ) != 0) {
Al Virof6f83a62013-03-31 03:59:17 -0400139 seq_printf(m, "%s",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 printed_options ? "|QAS" : " QAS");
141 printed_options++;
142 }
143 }
144
145 if (tinfo->width > 0) {
146 if (freq != 0) {
Al Virof6f83a62013-03-31 03:59:17 -0400147 seq_printf(m, ", ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 } else {
Al Virof6f83a62013-03-31 03:59:17 -0400149 seq_printf(m, " (");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
Al Virof6f83a62013-03-31 03:59:17 -0400151 seq_printf(m, "%dbit)", 8 * (0x01 << tinfo->width));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 } else if (freq != 0) {
Al Virof6f83a62013-03-31 03:59:17 -0400153 seq_printf(m, ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
Al Virof6f83a62013-03-31 03:59:17 -0400155 seq_printf(m, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
158static void
Al Virof6f83a62013-03-31 03:59:17 -0400159ahd_dump_target_state(struct ahd_softc *ahd, struct seq_file *m,
Hannes Reineckef89d0a42006-06-22 11:45:00 +0200160 u_int our_id, char channel, u_int target_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
Hannes Reinecke73a25462005-07-22 16:44:04 +0200162 struct scsi_target *starget;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 struct ahd_initiator_tinfo *tinfo;
164 struct ahd_tmode_tstate *tstate;
165 int lun;
166
167 tinfo = ahd_fetch_transinfo(ahd, channel, our_id,
168 target_id, &tstate);
Al Virof6f83a62013-03-31 03:59:17 -0400169 seq_printf(m, "Target %d Negotiation Settings\n", target_id);
170 seq_printf(m, "\tUser: ");
171 ahd_format_transinfo(m, &tinfo->user);
Hannes Reineckef89d0a42006-06-22 11:45:00 +0200172 starget = ahd->platform_data->starget[target_id];
James Bottomley3f40d7d2005-08-03 13:25:10 -0500173 if (starget == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return;
175
Al Virof6f83a62013-03-31 03:59:17 -0400176 seq_printf(m, "\tGoal: ");
177 ahd_format_transinfo(m, &tinfo->goal);
178 seq_printf(m, "\tCurr: ");
179 ahd_format_transinfo(m, &tinfo->curr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
181 for (lun = 0; lun < AHD_NUM_LUNS; lun++) {
Hannes Reinecke73a25462005-07-22 16:44:04 +0200182 struct scsi_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Hannes Reineckef89d0a42006-06-22 11:45:00 +0200184 dev = scsi_device_lookup_by_target(starget, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 if (dev == NULL)
187 continue;
188
Al Virof6f83a62013-03-31 03:59:17 -0400189 ahd_dump_device_state(m, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
191}
192
193static void
Al Virof6f83a62013-03-31 03:59:17 -0400194ahd_dump_device_state(struct seq_file *m, struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Hannes Reinecke73a25462005-07-22 16:44:04 +0200196 struct ahd_linux_device *dev = scsi_transport_device_data(sdev);
197
Al Virof6f83a62013-03-31 03:59:17 -0400198 seq_printf(m, "\tChannel %c Target %d Lun %d Settings\n",
Hannes Reinecke73a25462005-07-22 16:44:04 +0200199 sdev->sdev_target->channel + 'A',
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200200 sdev->sdev_target->id, (u8)sdev->lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Al Virof6f83a62013-03-31 03:59:17 -0400202 seq_printf(m, "\t\tCommands Queued %ld\n", dev->commands_issued);
203 seq_printf(m, "\t\tCommands Active %d\n", dev->active);
204 seq_printf(m, "\t\tCommand Openings %d\n", dev->openings);
205 seq_printf(m, "\t\tMax Tagged Openings %d\n", dev->maxtags);
206 seq_printf(m, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
Al Virof6f83a62013-03-31 03:59:17 -0400209int
210ahd_proc_write_seeprom(struct Scsi_Host *shost, char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Al Virof6f83a62013-03-31 03:59:17 -0400212 struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 ahd_mode_state saved_modes;
214 int have_seeprom;
215 u_long s;
216 int paused;
217 int written;
218
219 /* Default to failure. */
220 written = -EINVAL;
221 ahd_lock(ahd, &s);
222 paused = ahd_is_paused(ahd);
223 if (!paused)
224 ahd_pause(ahd);
225
226 saved_modes = ahd_save_modes(ahd);
227 ahd_set_modes(ahd, AHD_MODE_SCSI, AHD_MODE_SCSI);
228 if (length != sizeof(struct seeprom_config)) {
Pekka Enberg48813cf2010-07-14 13:12:57 +0300229 printk("ahd_proc_write_seeprom: incorrect buffer size\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 goto done;
231 }
232
233 have_seeprom = ahd_verify_cksum((struct seeprom_config*)buffer);
234 if (have_seeprom == 0) {
Pekka Enberg48813cf2010-07-14 13:12:57 +0300235 printk("ahd_proc_write_seeprom: cksum verification failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 goto done;
237 }
238
239 have_seeprom = ahd_acquire_seeprom(ahd);
240 if (!have_seeprom) {
Pekka Enberg48813cf2010-07-14 13:12:57 +0300241 printk("ahd_proc_write_seeprom: No Serial EEPROM\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 goto done;
243 } else {
244 u_int start_addr;
245
246 if (ahd->seep_config == NULL) {
Pekka Enberg48813cf2010-07-14 13:12:57 +0300247 ahd->seep_config = kmalloc(sizeof(*ahd->seep_config), GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 if (ahd->seep_config == NULL) {
Pekka Enberg48813cf2010-07-14 13:12:57 +0300249 printk("aic79xx: Unable to allocate serial "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 "eeprom buffer. Write failing\n");
251 goto done;
252 }
253 }
Pekka Enberg48813cf2010-07-14 13:12:57 +0300254 printk("aic79xx: Writing Serial EEPROM\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 start_addr = 32 * (ahd->channel - 'A');
256 ahd_write_seeprom(ahd, (u_int16_t *)buffer, start_addr,
257 sizeof(struct seeprom_config)/2);
258 ahd_read_seeprom(ahd, (uint16_t *)ahd->seep_config,
259 start_addr, sizeof(struct seeprom_config)/2,
260 /*ByteStream*/FALSE);
261 ahd_release_seeprom(ahd);
262 written = length;
263 }
264
265done:
266 ahd_restore_modes(ahd, saved_modes);
267 if (!paused)
268 ahd_unpause(ahd);
269 ahd_unlock(ahd, &s);
270 return (written);
271}
272/*
273 * Return information to handle /proc support for the driver.
274 */
275int
Al Virof6f83a62013-03-31 03:59:17 -0400276ahd_linux_show_info(struct seq_file *m, struct Scsi_Host *shost)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Christoph Hellwig85a46522005-08-15 13:28:46 +0200278 struct ahd_softc *ahd = *(struct ahd_softc **)shost->hostdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 char ahd_info[256];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 u_int max_targ;
281 u_int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Al Virof6f83a62013-03-31 03:59:17 -0400283 seq_printf(m, "Adaptec AIC79xx driver version: %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 AIC79XX_DRIVER_VERSION);
Al Virof6f83a62013-03-31 03:59:17 -0400285 seq_printf(m, "%s\n", ahd->description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 ahd_controller_info(ahd, ahd_info);
Al Virof6f83a62013-03-31 03:59:17 -0400287 seq_printf(m, "%s\n", ahd_info);
288 seq_printf(m, "Allocated SCBs: %d, SG List Length: %d\n\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 ahd->scb_data.numscbs, AHD_NSEG);
290
Hannes Reineckef89d0a42006-06-22 11:45:00 +0200291 max_targ = 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 if (ahd->seep_config == NULL)
Al Virof6f83a62013-03-31 03:59:17 -0400294 seq_printf(m, "No Serial EEPROM\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 else {
Al Virof6f83a62013-03-31 03:59:17 -0400296 seq_printf(m, "Serial EEPROM:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 for (i = 0; i < sizeof(*ahd->seep_config)/2; i++) {
298 if (((i % 8) == 0) && (i != 0)) {
Al Virof6f83a62013-03-31 03:59:17 -0400299 seq_printf(m, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
Al Virof6f83a62013-03-31 03:59:17 -0400301 seq_printf(m, "0x%.4x ",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 ((uint16_t*)ahd->seep_config)[i]);
303 }
Al Virof6f83a62013-03-31 03:59:17 -0400304 seq_printf(m, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
Al Virof6f83a62013-03-31 03:59:17 -0400306 seq_printf(m, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if ((ahd->features & AHD_WIDE) == 0)
Hannes Reineckef89d0a42006-06-22 11:45:00 +0200309 max_targ = 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Hannes Reineckef89d0a42006-06-22 11:45:00 +0200311 for (i = 0; i < max_targ; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Al Virof6f83a62013-03-31 03:59:17 -0400313 ahd_dump_target_state(ahd, m, ahd->our_id, 'A',
Hannes Reineckef89d0a42006-06-22 11:45:00 +0200314 /*target_id*/i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
Al Virof6f83a62013-03-31 03:59:17 -0400316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}