2 * Copyright (c) 2000-2001 Adaptec Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
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.
37 * String handling code courtesy of Gerard Roudier's <groudier@club-internet.fr>
40 * $Id: //depot/aic7xxx/linux/drivers/scsi/aic7xxx/aic7xxx_proc.c#29 $
42 #include "aic7xxx_osm.h"
43 #include "aic7xxx_inline.h"
44 #include "aic7xxx_93cx6.h"
46 static void copy_mem_info(struct info_str
*info
, char *data
, int len
);
47 static int copy_info(struct info_str
*info
, char *fmt
, ...);
48 static 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
);
52 static void ahc_dump_device_state(struct info_str
*info
,
53 struct scsi_device
*dev
);
54 static int ahc_proc_write_seeprom(struct ahc_softc
*ahc
,
55 char *buffer
, int length
);
58 copy_mem_info(struct info_str
*info
, char *data
, int len
)
60 if (info
->pos
+ len
> info
->offset
+ info
->length
)
61 len
= info
->offset
+ info
->length
- info
->pos
;
63 if (info
->pos
+ len
< info
->offset
) {
68 if (info
->pos
< info
->offset
) {
71 partial
= info
->offset
- info
->pos
;
78 memcpy(info
->buffer
, data
, len
);
85 copy_info(struct info_str
*info
, char *fmt
, ...)
92 len
= vsprintf(buf
, fmt
, args
);
95 copy_mem_info(info
, buf
, len
);
100 ahc_format_transinfo(struct info_str
*info
, struct ahc_transinfo
*tinfo
)
108 if (tinfo
->offset
!= 0) {
109 freq
= aic_calc_syncsrate(tinfo
->period
);
112 speed
*= (0x01 << tinfo
->width
);
115 copy_info(info
, "%d.%03dMB/s transfers", mb
, speed
% 1000);
117 copy_info(info
, "%dKB/s transfers", speed
);
120 copy_info(info
, " (%d.%03dMHz%s, offset %d",
121 freq
/ 1000, freq
% 1000,
122 (tinfo
->ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0
123 ? " DT" : "", tinfo
->offset
);
126 if (tinfo
->width
> 0) {
128 copy_info(info
, ", ");
130 copy_info(info
, " (");
132 copy_info(info
, "%dbit)", 8 * (0x01 << tinfo
->width
));
133 } else if (freq
!= 0) {
134 copy_info(info
, ")");
136 copy_info(info
, "\n");
140 ahc_dump_target_state(struct ahc_softc
*ahc
, struct info_str
*info
,
141 u_int our_id
, char channel
, u_int target_id
,
144 struct ahc_linux_target
*targ
;
145 struct scsi_target
*starget
;
146 struct ahc_initiator_tinfo
*tinfo
;
147 struct ahc_tmode_tstate
*tstate
;
150 tinfo
= ahc_fetch_transinfo(ahc
, channel
, our_id
,
152 if ((ahc
->features
& AHC_TWIN
) != 0)
153 copy_info(info
, "Channel %c ", channel
);
154 copy_info(info
, "Target %d Negotiation Settings\n", target_id
);
155 copy_info(info
, "\tUser: ");
156 ahc_format_transinfo(info
, &tinfo
->user
);
157 starget
= ahc
->platform_data
->starget
[target_offset
];
160 targ
= scsi_transport_target_data(starget
);
162 copy_info(info
, "\tGoal: ");
163 ahc_format_transinfo(info
, &tinfo
->goal
);
164 copy_info(info
, "\tCurr: ");
165 ahc_format_transinfo(info
, &tinfo
->curr
);
167 for (lun
= 0; lun
< AHC_NUM_LUNS
; lun
++) {
168 struct scsi_device
*sdev
;
170 sdev
= targ
->sdev
[lun
];
175 ahc_dump_device_state(info
, sdev
);
180 ahc_dump_device_state(struct info_str
*info
, struct scsi_device
*sdev
)
182 struct ahc_linux_device
*dev
= scsi_transport_device_data(sdev
);
184 copy_info(info
, "\tChannel %c Target %d Lun %d Settings\n",
185 sdev
->sdev_target
->channel
+ 'A',
186 sdev
->sdev_target
->id
, sdev
->lun
);
188 copy_info(info
, "\t\tCommands Queued %ld\n", dev
->commands_issued
);
189 copy_info(info
, "\t\tCommands Active %d\n", dev
->active
);
190 copy_info(info
, "\t\tCommand Openings %d\n", dev
->openings
);
191 copy_info(info
, "\t\tMax Tagged Openings %d\n", dev
->maxtags
);
192 copy_info(info
, "\t\tDevice Queue Frozen Count %d\n", dev
->qfrozen
);
196 ahc_proc_write_seeprom(struct ahc_softc
*ahc
, char *buffer
, int length
)
198 struct seeprom_descriptor sd
;
204 /* Default to failure. */
207 paused
= ahc_is_paused(ahc
);
211 if (length
!= sizeof(struct seeprom_config
)) {
212 printf("ahc_proc_write_seeprom: incorrect buffer size\n");
216 have_seeprom
= ahc_verify_cksum((struct seeprom_config
*)buffer
);
217 if (have_seeprom
== 0) {
218 printf("ahc_proc_write_seeprom: cksum verification failed\n");
223 #if AHC_PCI_CONFIG > 0
224 if ((ahc
->chip
& AHC_PCI
) != 0) {
225 sd
.sd_control_offset
= SEECTL
;
226 sd
.sd_status_offset
= SEECTL
;
227 sd
.sd_dataout_offset
= SEECTL
;
228 if (ahc
->flags
& AHC_LARGE_SEEPROM
)
238 have_seeprom
= ahc_acquire_seeprom(ahc
, &sd
);
241 if ((ahc
->chip
& AHC_VL
) != 0) {
242 sd
.sd_control_offset
= SEECTL_2840
;
243 sd
.sd_status_offset
= STATUS_2840
;
244 sd
.sd_dataout_offset
= STATUS_2840
;
247 sd
.sd_RDY
= EEPROM_TF
;
254 printf("ahc_proc_write_seeprom: unsupported adapter type\n");
259 printf("ahc_proc_write_seeprom: No Serial EEPROM\n");
264 if (ahc
->seep_config
== NULL
) {
265 ahc
->seep_config
= malloc(sizeof(*ahc
->seep_config
),
267 if (ahc
->seep_config
== NULL
) {
268 printf("aic7xxx: Unable to allocate serial "
269 "eeprom buffer. Write failing\n");
273 printf("aic7xxx: Writing Serial EEPROM\n");
274 start_addr
= 32 * (ahc
->channel
- 'A');
275 ahc_write_seeprom(&sd
, (u_int16_t
*)buffer
, start_addr
,
276 sizeof(struct seeprom_config
)/2);
277 ahc_read_seeprom(&sd
, (uint16_t *)ahc
->seep_config
,
278 start_addr
, sizeof(struct seeprom_config
)/2);
279 #if AHC_PCI_CONFIG > 0
280 if ((ahc
->chip
& AHC_VL
) == 0)
281 ahc_release_seeprom(&sd
);
294 * Return information to handle /proc support for the driver.
297 ahc_linux_proc_info(struct Scsi_Host
*shost
, char *buffer
, char **start
,
298 off_t offset
, int length
, int inout
)
300 struct ahc_softc
*ahc
= *(struct ahc_softc
**)shost
->hostdata
;
301 struct info_str info
;
307 /* Has data been written to the file? */
309 retval
= ahc_proc_write_seeprom(ahc
, buffer
, length
);
316 info
.buffer
= buffer
;
317 info
.length
= length
;
318 info
.offset
= offset
;
321 copy_info(&info
, "Adaptec AIC7xxx driver version: %s\n",
322 AIC7XXX_DRIVER_VERSION
);
323 copy_info(&info
, "%s\n", ahc
->description
);
324 ahc_controller_info(ahc
, ahc_info
);
325 copy_info(&info
, "%s\n", ahc_info
);
326 copy_info(&info
, "Allocated SCBs: %d, SG List Length: %d\n\n",
327 ahc
->scb_data
->numscbs
, AHC_NSEG
);
330 if (ahc
->seep_config
== NULL
)
331 copy_info(&info
, "No Serial EEPROM\n");
333 copy_info(&info
, "Serial EEPROM:\n");
334 for (i
= 0; i
< sizeof(*ahc
->seep_config
)/2; i
++) {
335 if (((i
% 8) == 0) && (i
!= 0)) {
336 copy_info(&info
, "\n");
338 copy_info(&info
, "0x%.4x ",
339 ((uint16_t*)ahc
->seep_config
)[i
]);
341 copy_info(&info
, "\n");
343 copy_info(&info
, "\n");
346 if ((ahc
->features
& (AHC_WIDE
|AHC_TWIN
)) == 0)
349 for (i
= 0; i
<= max_targ
; i
++) {
355 our_id
= ahc
->our_id
;
357 if (i
> 7 && (ahc
->features
& AHC_TWIN
) != 0) {
359 our_id
= ahc
->our_id_b
;
363 ahc_dump_target_state(ahc
, &info
, our_id
,
364 channel
, target_id
, i
);
366 retval
= info
.pos
> info
.offset
? info
.pos
- info
.offset
: 0;