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/aic79xx_proc.c#19 $
42 #include "aic79xx_osm.h"
43 #include "aic79xx_inline.h"
45 static void ahd_dump_target_state(struct ahd_softc
*ahd
,
47 u_int our_id
, char channel
,
49 static void ahd_dump_device_state(struct seq_file
*m
,
50 struct scsi_device
*sdev
);
53 * Table of syncrates that don't follow the "divisible by 4"
54 * rule. This table will be expanded in future SCSI specs.
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 */
68 * Return the frequency in kHz corresponding to the given
72 ahd_calc_syncsrate(u_int period_factor
)
76 /* See if the period is in the "exception" table */
77 for (i
= 0; i
< ARRAY_SIZE(scsi_syncrates
); i
++) {
79 if (period_factor
== scsi_syncrates
[i
].period_factor
) {
81 return (100000000 / scsi_syncrates
[i
].period
);
86 * Wasn't in the table, so use the standard
89 return (10000000 / (period_factor
* 4 * 10));
93 ahd_format_transinfo(struct seq_file
*m
, struct ahd_transinfo
*tinfo
)
99 if (tinfo
->period
== AHD_PERIOD_UNKNOWN
) {
100 seq_printf(m
, "Renegotiation Pending\n");
105 if (tinfo
->offset
!= 0) {
106 freq
= ahd_calc_syncsrate(tinfo
->period
);
109 speed
*= (0x01 << tinfo
->width
);
112 seq_printf(m
, "%d.%03dMB/s transfers", mb
, speed
% 1000);
114 seq_printf(m
, "%dKB/s transfers", speed
);
120 seq_printf(m
, " (%d.%03dMHz", freq
/ 1000, freq
% 1000);
121 if ((tinfo
->ppr_options
& MSG_EXT_PPR_RD_STRM
) != 0) {
122 seq_printf(m
, " RDSTRM");
125 if ((tinfo
->ppr_options
& MSG_EXT_PPR_DT_REQ
) != 0) {
126 seq_printf(m
, "%s", printed_options
? "|DT" : " DT");
129 if ((tinfo
->ppr_options
& MSG_EXT_PPR_IU_REQ
) != 0) {
130 seq_printf(m
, "%s", printed_options
? "|IU" : " IU");
133 if ((tinfo
->ppr_options
& MSG_EXT_PPR_RTI
) != 0) {
135 printed_options
? "|RTI" : " RTI");
138 if ((tinfo
->ppr_options
& MSG_EXT_PPR_QAS_REQ
) != 0) {
140 printed_options
? "|QAS" : " QAS");
145 if (tinfo
->width
> 0) {
151 seq_printf(m
, "%dbit)", 8 * (0x01 << tinfo
->width
));
152 } else if (freq
!= 0) {
159 ahd_dump_target_state(struct ahd_softc
*ahd
, struct seq_file
*m
,
160 u_int our_id
, char channel
, u_int target_id
)
162 struct scsi_target
*starget
;
163 struct ahd_initiator_tinfo
*tinfo
;
164 struct ahd_tmode_tstate
*tstate
;
167 tinfo
= ahd_fetch_transinfo(ahd
, channel
, our_id
,
169 seq_printf(m
, "Target %d Negotiation Settings\n", target_id
);
170 seq_printf(m
, "\tUser: ");
171 ahd_format_transinfo(m
, &tinfo
->user
);
172 starget
= ahd
->platform_data
->starget
[target_id
];
176 seq_printf(m
, "\tGoal: ");
177 ahd_format_transinfo(m
, &tinfo
->goal
);
178 seq_printf(m
, "\tCurr: ");
179 ahd_format_transinfo(m
, &tinfo
->curr
);
181 for (lun
= 0; lun
< AHD_NUM_LUNS
; lun
++) {
182 struct scsi_device
*dev
;
184 dev
= scsi_device_lookup_by_target(starget
, lun
);
189 ahd_dump_device_state(m
, dev
);
194 ahd_dump_device_state(struct seq_file
*m
, struct scsi_device
*sdev
)
196 struct ahd_linux_device
*dev
= scsi_transport_device_data(sdev
);
198 seq_printf(m
, "\tChannel %c Target %d Lun %d Settings\n",
199 sdev
->sdev_target
->channel
+ 'A',
200 sdev
->sdev_target
->id
, sdev
->lun
);
202 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
);
210 ahd_proc_write_seeprom(struct Scsi_Host
*shost
, char *buffer
, int length
)
212 struct ahd_softc
*ahd
= *(struct ahd_softc
**)shost
->hostdata
;
213 ahd_mode_state saved_modes
;
219 /* Default to failure. */
222 paused
= ahd_is_paused(ahd
);
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
)) {
229 printk("ahd_proc_write_seeprom: incorrect buffer size\n");
233 have_seeprom
= ahd_verify_cksum((struct seeprom_config
*)buffer
);
234 if (have_seeprom
== 0) {
235 printk("ahd_proc_write_seeprom: cksum verification failed\n");
239 have_seeprom
= ahd_acquire_seeprom(ahd
);
241 printk("ahd_proc_write_seeprom: No Serial EEPROM\n");
246 if (ahd
->seep_config
== NULL
) {
247 ahd
->seep_config
= kmalloc(sizeof(*ahd
->seep_config
), GFP_ATOMIC
);
248 if (ahd
->seep_config
== NULL
) {
249 printk("aic79xx: Unable to allocate serial "
250 "eeprom buffer. Write failing\n");
254 printk("aic79xx: Writing Serial EEPROM\n");
255 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
);
266 ahd_restore_modes(ahd
, saved_modes
);
273 * Return information to handle /proc support for the driver.
276 ahd_linux_show_info(struct seq_file
*m
, struct Scsi_Host
*shost
)
278 struct ahd_softc
*ahd
= *(struct ahd_softc
**)shost
->hostdata
;
283 seq_printf(m
, "Adaptec AIC79xx driver version: %s\n",
284 AIC79XX_DRIVER_VERSION
);
285 seq_printf(m
, "%s\n", ahd
->description
);
286 ahd_controller_info(ahd
, ahd_info
);
287 seq_printf(m
, "%s\n", ahd_info
);
288 seq_printf(m
, "Allocated SCBs: %d, SG List Length: %d\n\n",
289 ahd
->scb_data
.numscbs
, AHD_NSEG
);
293 if (ahd
->seep_config
== NULL
)
294 seq_printf(m
, "No Serial EEPROM\n");
296 seq_printf(m
, "Serial EEPROM:\n");
297 for (i
= 0; i
< sizeof(*ahd
->seep_config
)/2; i
++) {
298 if (((i
% 8) == 0) && (i
!= 0)) {
301 seq_printf(m
, "0x%.4x ",
302 ((uint16_t*)ahd
->seep_config
)[i
]);
308 if ((ahd
->features
& AHD_WIDE
) == 0)
311 for (i
= 0; i
< max_targ
; i
++) {
313 ahd_dump_target_state(ahd
, m
, ahd
->our_id
, 'A',