[SCSI] HP XP devinfo update
[deliverable/linux.git] / drivers / scsi / aic7xxx / aic7xxx_proc.c
CommitLineData
1da177e4
LT
1/*
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/aic7xxx_proc.c#29 $
41 */
42#include "aic7xxx_osm.h"
43#include "aic7xxx_inline.h"
44#include "aic7xxx_93cx6.h"
45
46static void copy_mem_info(struct info_str *info, char *data, int len);
47static int copy_info(struct info_str *info, char *fmt, ...);
48static void ahc_dump_target_state(struct ahc_softc *ahc,
49 struct info_str *info,
50 u_int our_id, char channel,
51 u_int target_id, u_int target_offset);
52static void ahc_dump_device_state(struct info_str *info,
b1abb4d6 53 struct scsi_device *dev);
1da177e4
LT
54static int ahc_proc_write_seeprom(struct ahc_softc *ahc,
55 char *buffer, int length);
56
1ff92730
CH
57/*
58 * Table of syncrates that don't follow the "divisible by 4"
59 * rule. This table will be expanded in future SCSI specs.
60 */
61static struct {
62 u_int period_factor;
63 u_int period; /* in 100ths of ns */
64} scsi_syncrates[] = {
65 { 0x08, 625 }, /* FAST-160 */
66 { 0x09, 1250 }, /* FAST-80 */
67 { 0x0a, 2500 }, /* FAST-40 40MHz */
68 { 0x0b, 3030 }, /* FAST-40 33MHz */
69 { 0x0c, 5000 } /* FAST-20 */
70};
71
72/*
73 * Return the frequency in kHz corresponding to the given
74 * sync period factor.
75 */
76static u_int
77ahc_calc_syncsrate(u_int period_factor)
78{
79 int i;
1ff92730 80
1ff92730 81 /* See if the period is in the "exception" table */
6391a113 82 for (i = 0; i < ARRAY_SIZE(scsi_syncrates); i++) {
1ff92730
CH
83
84 if (period_factor == scsi_syncrates[i].period_factor) {
85 /* Period in kHz */
86 return (100000000 / scsi_syncrates[i].period);
87 }
88 }
89
90 /*
91 * Wasn't in the table, so use the standard
92 * 4 times conversion.
93 */
94 return (10000000 / (period_factor * 4 * 10));
95}
96
97
1da177e4
LT
98static void
99copy_mem_info(struct info_str *info, char *data, int len)
100{
101 if (info->pos + len > info->offset + info->length)
102 len = info->offset + info->length - info->pos;
103
104 if (info->pos + len < info->offset) {
105 info->pos += len;
106 return;
107 }
108
109 if (info->pos < info->offset) {
110 off_t partial;
111
112 partial = info->offset - info->pos;
113 data += partial;
114 info->pos += partial;
115 len -= partial;
116 }
117
118 if (len > 0) {
119 memcpy(info->buffer, data, len);
120 info->pos += len;
121 info->buffer += len;
122 }
123}
124
125static int
126copy_info(struct info_str *info, char *fmt, ...)
127{
128 va_list args;
129 char buf[256];
130 int len;
131
132 va_start(args, fmt);
133 len = vsprintf(buf, fmt, args);
134 va_end(args);
135
136 copy_mem_info(info, buf, len);
137 return (len);
138}
139
140void
141ahc_format_transinfo(struct info_str *info, struct ahc_transinfo *tinfo)
142{
143 u_int speed;
144 u_int freq;
145 u_int mb;
146
147 speed = 3300;
148 freq = 0;
149 if (tinfo->offset != 0) {
1ff92730 150 freq = ahc_calc_syncsrate(tinfo->period);
1da177e4
LT
151 speed = freq;
152 }
153 speed *= (0x01 << tinfo->width);
154 mb = speed / 1000;
155 if (mb > 0)
156 copy_info(info, "%d.%03dMB/s transfers", mb, speed % 1000);
157 else
158 copy_info(info, "%dKB/s transfers", speed);
159
160 if (freq != 0) {
161 copy_info(info, " (%d.%03dMHz%s, offset %d",
162 freq / 1000, freq % 1000,
163 (tinfo->ppr_options & MSG_EXT_PPR_DT_REQ) != 0
164 ? " DT" : "", tinfo->offset);
165 }
166
167 if (tinfo->width > 0) {
168 if (freq != 0) {
169 copy_info(info, ", ");
170 } else {
171 copy_info(info, " (");
172 }
173 copy_info(info, "%dbit)", 8 * (0x01 << tinfo->width));
174 } else if (freq != 0) {
175 copy_info(info, ")");
176 }
177 copy_info(info, "\n");
178}
179
180static void
181ahc_dump_target_state(struct ahc_softc *ahc, struct info_str *info,
182 u_int our_id, char channel, u_int target_id,
183 u_int target_offset)
184{
185 struct ahc_linux_target *targ;
b1abb4d6 186 struct scsi_target *starget;
1da177e4
LT
187 struct ahc_initiator_tinfo *tinfo;
188 struct ahc_tmode_tstate *tstate;
189 int lun;
190
191 tinfo = ahc_fetch_transinfo(ahc, channel, our_id,
192 target_id, &tstate);
193 if ((ahc->features & AHC_TWIN) != 0)
194 copy_info(info, "Channel %c ", channel);
195 copy_info(info, "Target %d Negotiation Settings\n", target_id);
196 copy_info(info, "\tUser: ");
197 ahc_format_transinfo(info, &tinfo->user);
b1abb4d6 198 starget = ahc->platform_data->starget[target_offset];
c0df28cf 199 if (!starget)
1da177e4 200 return;
c0df28cf 201 targ = scsi_transport_target_data(starget);
1da177e4
LT
202
203 copy_info(info, "\tGoal: ");
204 ahc_format_transinfo(info, &tinfo->goal);
205 copy_info(info, "\tCurr: ");
206 ahc_format_transinfo(info, &tinfo->curr);
207
208 for (lun = 0; lun < AHC_NUM_LUNS; lun++) {
b1abb4d6 209 struct scsi_device *sdev;
1da177e4 210
b1abb4d6 211 sdev = targ->sdev[lun];
1da177e4 212
b1abb4d6 213 if (sdev == NULL)
1da177e4
LT
214 continue;
215
b1abb4d6 216 ahc_dump_device_state(info, sdev);
1da177e4
LT
217 }
218}
219
220static void
b1abb4d6 221ahc_dump_device_state(struct info_str *info, struct scsi_device *sdev)
1da177e4 222{
b1abb4d6
JB
223 struct ahc_linux_device *dev = scsi_transport_device_data(sdev);
224
1da177e4 225 copy_info(info, "\tChannel %c Target %d Lun %d Settings\n",
b1abb4d6
JB
226 sdev->sdev_target->channel + 'A',
227 sdev->sdev_target->id, sdev->lun);
1da177e4
LT
228
229 copy_info(info, "\t\tCommands Queued %ld\n", dev->commands_issued);
230 copy_info(info, "\t\tCommands Active %d\n", dev->active);
231 copy_info(info, "\t\tCommand Openings %d\n", dev->openings);
232 copy_info(info, "\t\tMax Tagged Openings %d\n", dev->maxtags);
233 copy_info(info, "\t\tDevice Queue Frozen Count %d\n", dev->qfrozen);
234}
235
236static int
237ahc_proc_write_seeprom(struct ahc_softc *ahc, char *buffer, int length)
238{
239 struct seeprom_descriptor sd;
240 int have_seeprom;
241 u_long s;
242 int paused;
243 int written;
244
245 /* Default to failure. */
246 written = -EINVAL;
247 ahc_lock(ahc, &s);
248 paused = ahc_is_paused(ahc);
249 if (!paused)
250 ahc_pause(ahc);
251
252 if (length != sizeof(struct seeprom_config)) {
253 printf("ahc_proc_write_seeprom: incorrect buffer size\n");
254 goto done;
255 }
256
257 have_seeprom = ahc_verify_cksum((struct seeprom_config*)buffer);
258 if (have_seeprom == 0) {
259 printf("ahc_proc_write_seeprom: cksum verification failed\n");
260 goto done;
261 }
262
263 sd.sd_ahc = ahc;
264#if AHC_PCI_CONFIG > 0
265 if ((ahc->chip & AHC_PCI) != 0) {
266 sd.sd_control_offset = SEECTL;
267 sd.sd_status_offset = SEECTL;
268 sd.sd_dataout_offset = SEECTL;
269 if (ahc->flags & AHC_LARGE_SEEPROM)
270 sd.sd_chip = C56_66;
271 else
272 sd.sd_chip = C46;
273 sd.sd_MS = SEEMS;
274 sd.sd_RDY = SEERDY;
275 sd.sd_CS = SEECS;
276 sd.sd_CK = SEECK;
277 sd.sd_DO = SEEDO;
278 sd.sd_DI = SEEDI;
279 have_seeprom = ahc_acquire_seeprom(ahc, &sd);
280 } else
281#endif
282 if ((ahc->chip & AHC_VL) != 0) {
283 sd.sd_control_offset = SEECTL_2840;
284 sd.sd_status_offset = STATUS_2840;
285 sd.sd_dataout_offset = STATUS_2840;
286 sd.sd_chip = C46;
287 sd.sd_MS = 0;
288 sd.sd_RDY = EEPROM_TF;
289 sd.sd_CS = CS_2840;
290 sd.sd_CK = CK_2840;
291 sd.sd_DO = DO_2840;
292 sd.sd_DI = DI_2840;
293 have_seeprom = TRUE;
294 } else {
295 printf("ahc_proc_write_seeprom: unsupported adapter type\n");
296 goto done;
297 }
298
299 if (!have_seeprom) {
300 printf("ahc_proc_write_seeprom: No Serial EEPROM\n");
301 goto done;
302 } else {
303 u_int start_addr;
304
305 if (ahc->seep_config == NULL) {
306 ahc->seep_config = malloc(sizeof(*ahc->seep_config),
307 M_DEVBUF, M_NOWAIT);
308 if (ahc->seep_config == NULL) {
309 printf("aic7xxx: Unable to allocate serial "
310 "eeprom buffer. Write failing\n");
311 goto done;
312 }
313 }
314 printf("aic7xxx: Writing Serial EEPROM\n");
315 start_addr = 32 * (ahc->channel - 'A');
316 ahc_write_seeprom(&sd, (u_int16_t *)buffer, start_addr,
317 sizeof(struct seeprom_config)/2);
318 ahc_read_seeprom(&sd, (uint16_t *)ahc->seep_config,
319 start_addr, sizeof(struct seeprom_config)/2);
320#if AHC_PCI_CONFIG > 0
321 if ((ahc->chip & AHC_VL) == 0)
322 ahc_release_seeprom(&sd);
323#endif
324 written = length;
325 }
326
327done:
328 if (!paused)
329 ahc_unpause(ahc);
330 ahc_unlock(ahc, &s);
331 return (written);
332}
333
334/*
335 * Return information to handle /proc support for the driver.
336 */
337int
1da177e4
LT
338ahc_linux_proc_info(struct Scsi_Host *shost, char *buffer, char **start,
339 off_t offset, int length, int inout)
1da177e4 340{
3d65692a 341 struct ahc_softc *ahc = *(struct ahc_softc **)shost->hostdata;
1da177e4
LT
342 struct info_str info;
343 char ahc_info[256];
1da177e4
LT
344 u_int max_targ;
345 u_int i;
346 int retval;
347
1da177e4
LT
348 /* Has data been written to the file? */
349 if (inout == TRUE) {
350 retval = ahc_proc_write_seeprom(ahc, buffer, length);
351 goto done;
352 }
353
354 if (start)
355 *start = buffer;
356
357 info.buffer = buffer;
358 info.length = length;
359 info.offset = offset;
360 info.pos = 0;
361
362 copy_info(&info, "Adaptec AIC7xxx driver version: %s\n",
363 AIC7XXX_DRIVER_VERSION);
364 copy_info(&info, "%s\n", ahc->description);
365 ahc_controller_info(ahc, ahc_info);
366 copy_info(&info, "%s\n", ahc_info);
367 copy_info(&info, "Allocated SCBs: %d, SG List Length: %d\n\n",
368 ahc->scb_data->numscbs, AHC_NSEG);
369
370
371 if (ahc->seep_config == NULL)
372 copy_info(&info, "No Serial EEPROM\n");
373 else {
374 copy_info(&info, "Serial EEPROM:\n");
375 for (i = 0; i < sizeof(*ahc->seep_config)/2; i++) {
376 if (((i % 8) == 0) && (i != 0)) {
377 copy_info(&info, "\n");
378 }
379 copy_info(&info, "0x%.4x ",
380 ((uint16_t*)ahc->seep_config)[i]);
381 }
382 copy_info(&info, "\n");
383 }
384 copy_info(&info, "\n");
385
386 max_targ = 15;
387 if ((ahc->features & (AHC_WIDE|AHC_TWIN)) == 0)
388 max_targ = 7;
389
390 for (i = 0; i <= max_targ; i++) {
391 u_int our_id;
392 u_int target_id;
393 char channel;
394
395 channel = 'A';
396 our_id = ahc->our_id;
397 target_id = i;
398 if (i > 7 && (ahc->features & AHC_TWIN) != 0) {
399 channel = 'B';
400 our_id = ahc->our_id_b;
401 target_id = i % 8;
402 }
403
404 ahc_dump_target_state(ahc, &info, our_id,
405 channel, target_id, i);
406 }
407 retval = info.pos > info.offset ? info.pos - info.offset : 0;
408done:
1da177e4
LT
409 return (retval);
410}
This page took 0.206852 seconds and 5 git commands to generate.