]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/scsi/gdth_proc.c
2 * $Id: gdth_proc.c,v 1.43 2006/01/11 16:15:00 achim Exp $
5 #include <linux/completion.h>
7 int gdth_proc_info(struct Scsi_Host
*host
, char *buffer
,char **start
,off_t offset
,int length
,
12 TRACE2(("gdth_proc_info() length %d offs %d inout %d\n",
13 length
,(int)offset
,inout
));
15 hanum
= NUMDATA(host
)->hanum
;
18 return(gdth_set_info(buffer
,length
,host
,hanum
));
20 return(gdth_get_info(buffer
,start
,offset
,length
,host
,hanum
));
23 static int gdth_set_info(char *buffer
,int length
,struct Scsi_Host
*host
,
26 int ret_val
= -EINVAL
;
28 TRACE2(("gdth_set_info() ha %d\n",hanum
,));
31 if (strncmp(buffer
,"gdth",4) == 0) {
34 ret_val
= gdth_set_asc_info(host
, buffer
, length
, hanum
);
41 static int gdth_set_asc_info(struct Scsi_Host
*host
, char *buffer
,
44 int orig_length
, drive
, wb_mode
;
51 char cmnd
[MAX_COMMAND_SIZE
];
52 memset(cmnd
, 0xff, 12);
53 memset(&gdtcmd
, 0, sizeof(gdth_cmd_str
));
55 TRACE2(("gdth_set_asc_info() ha %d\n",hanum
));
56 ha
= HADATA(gdth_ctr_tab
[hanum
]);
57 orig_length
= length
+ 5;
62 if (length
>= 5 && strncmp(buffer
,"flush",5)==0) {
65 if (length
&& *buffer
>='0' && *buffer
<='9') {
66 drive
= (int)(*buffer
-'0');
68 if (length
&& *buffer
>='0' && *buffer
<='9') {
69 drive
= drive
*10 + (int)(*buffer
-'0');
72 printk("GDT: Flushing host drive %d .. ",drive
);
74 printk("GDT: Flushing all host drives .. ");
76 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
77 if (ha
->hdr
[i
].present
) {
78 if (drive
!= -1 && i
!= drive
)
81 gdtcmd
.Service
= CACHESERVICE
;
82 gdtcmd
.OpCode
= GDT_FLUSH
;
83 if (ha
->cache_feat
& GDT_64BIT
) {
84 gdtcmd
.u
.cache64
.DeviceNo
= i
;
85 gdtcmd
.u
.cache64
.BlockNo
= 1;
87 gdtcmd
.u
.cache
.DeviceNo
= i
;
88 gdtcmd
.u
.cache
.BlockNo
= 1;
91 gdth_execute(host
, &gdtcmd
, cmnd
, 30, NULL
);
95 printk("\nNo host drive found !\n");
101 if (length
>= 7 && strncmp(buffer
,"wbp_off",7)==0) {
104 printk("GDT: Disabling write back permanently .. ");
106 } else if (length
>= 6 && strncmp(buffer
,"wbp_on",6)==0) {
109 printk("GDT: Enabling write back permanently .. ");
111 } else if (length
>= 6 && strncmp(buffer
,"wb_off",6)==0) {
114 printk("GDT: Disabling write back commands .. ");
115 if (ha
->cache_feat
& GDT_WR_THROUGH
) {
116 gdth_write_through
= TRUE
;
119 printk("Not supported !\n");
122 } else if (length
>= 5 && strncmp(buffer
,"wb_on",5)==0) {
125 printk("GDT: Enabling write back commands .. ");
126 gdth_write_through
= FALSE
;
132 if (!gdth_ioctl_alloc(hanum
, sizeof(gdth_cpar_str
), TRUE
, &paddr
))
134 pcpar
= (gdth_cpar_str
*)ha
->pscratch
;
135 memcpy( pcpar
, &ha
->cpar
, sizeof(gdth_cpar_str
) );
136 gdtcmd
.Service
= CACHESERVICE
;
137 gdtcmd
.OpCode
= GDT_IOCTL
;
138 gdtcmd
.u
.ioctl
.p_param
= paddr
;
139 gdtcmd
.u
.ioctl
.param_size
= sizeof(gdth_cpar_str
);
140 gdtcmd
.u
.ioctl
.subfunc
= CACHE_CONFIG
;
141 gdtcmd
.u
.ioctl
.channel
= INVALID_CHANNEL
;
142 pcpar
->write_back
= wb_mode
==1 ? 0:1;
144 gdth_execute(host
, &gdtcmd
, cmnd
, 30, NULL
);
146 gdth_ioctl_free(hanum
, GDTH_SCRATCH
, ha
->pscratch
, paddr
);
151 printk("GDT: Unknown command: %s Length: %d\n",buffer
,length
);
155 static int gdth_get_info(char *buffer
,char **start
,off_t offset
,int length
,
156 struct Scsi_Host
*host
,int hanum
)
158 int size
= 0,len
= 0;
159 off_t begin
= 0,pos
= 0;
161 int id
, i
, j
, k
, sec
, flag
;
162 int no_mdrv
= 0, drv_no
, is_mirr
;
167 gdth_cmd_str
*gdtcmd
;
173 gdth_dskstat_str
*pds
;
174 gdth_diskinfo_str
*pdi
;
175 gdth_arrayinf_str
*pai
;
176 gdth_defcnt_str
*pdef
;
177 gdth_cdrinfo_str
*pcdi
;
179 char cmnd
[MAX_COMMAND_SIZE
];
181 gdtcmd
= kmalloc(sizeof(*gdtcmd
), GFP_KERNEL
);
182 estr
= kmalloc(sizeof(*estr
), GFP_KERNEL
);
183 if (!gdtcmd
|| !estr
)
186 memset(cmnd
, 0xff, 12);
187 memset(gdtcmd
, 0, sizeof(gdth_cmd_str
));
189 TRACE2(("gdth_get_info() ha %d\n",hanum
));
190 ha
= HADATA(gdth_ctr_tab
[hanum
]);
193 /* request is i.e. "cat /proc/scsi/gdth/0" */
194 /* format: %-15s\t%-10s\t%-15s\t%s */
195 /* driver parameters */
196 size
= sprintf(buffer
+len
,"Driver Parameters:\n");
197 len
+= size
; pos
= begin
+ len
;
198 if (reserve_list
[0] == 0xff)
201 sprintf(hrec
, "%d", reserve_list
[0]);
202 for (i
= 1; i
< MAX_RES_ARGS
; i
++) {
203 if (reserve_list
[i
] == 0xff)
205 sprintf(hrec
,"%s,%d", hrec
, reserve_list
[i
]);
208 size
= sprintf(buffer
+len
,
209 " reserve_mode: \t%d \treserve_list: \t%s\n",
211 len
+= size
; pos
= begin
+ len
;
212 size
= sprintf(buffer
+len
,
213 " max_ids: \t%-3d \thdr_channel: \t%d\n",
214 max_ids
, hdr_channel
);
215 len
+= size
; pos
= begin
+ len
;
217 /* controller information */
218 size
= sprintf(buffer
+len
,"\nDisk Array Controller Information:\n");
219 len
+= size
; pos
= begin
+ len
;
220 strcpy(hrec
, ha
->binfo
.type_string
);
221 size
= sprintf(buffer
+len
,
222 " Number: \t%d \tName: \t%s\n",
224 len
+= size
; pos
= begin
+ len
;
227 sprintf(hrec
, "%d.%02d.%02d-%c%03X",
228 (unchar
)(ha
->binfo
.upd_fw_ver
>>24),
229 (unchar
)(ha
->binfo
.upd_fw_ver
>>16),
230 (unchar
)(ha
->binfo
.upd_fw_ver
),
231 ha
->bfeat
.raid
? 'R':'N',
232 ha
->binfo
.upd_revision
);
234 sprintf(hrec
, "%d.%02d", (unchar
)(ha
->cpar
.version
>>8),
235 (unchar
)(ha
->cpar
.version
));
237 size
= sprintf(buffer
+len
,
238 " Driver Ver.: \t%-10s\tFirmware Ver.: \t%s\n",
239 GDTH_VERSION_STR
, hrec
);
240 len
+= size
; pos
= begin
+ len
;
243 /* more information: 1. about controller */
244 size
= sprintf(buffer
+len
,
245 " Serial No.: \t0x%8X\tCache RAM size:\t%d KB\n",
246 ha
->binfo
.ser_no
, ha
->binfo
.memsize
/ 1024);
247 len
+= size
; pos
= begin
+ len
;
250 #ifdef GDTH_DMA_STATISTICS
251 /* controller statistics */
252 size
= sprintf(buffer
+len
,"\nController Statistics:\n");
253 len
+= size
; pos
= begin
+ len
;
254 size
= sprintf(buffer
+len
,
255 " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu\n",
256 ha
->dma32_cnt
, ha
->dma64_cnt
);
257 len
+= size
; pos
= begin
+ len
;
264 if (pos
> offset
+ length
)
268 /* more information: 2. about physical devices */
269 size
= sprintf(buffer
+len
,"\nPhysical Devices:");
270 len
+= size
; pos
= begin
+ len
;
273 buf
= gdth_ioctl_alloc(hanum
, GDTH_SCRATCH
, FALSE
, &paddr
);
276 for (i
= 0; i
< ha
->bus_cnt
; ++i
) {
277 /* 2.a statistics (and retries/reassigns) */
278 TRACE2(("pdr_statistics() chn %d\n",i
));
279 pds
= (gdth_dskstat_str
*)(buf
+ GDTH_SCRATCH
/4);
280 gdtcmd
->Service
= CACHESERVICE
;
281 gdtcmd
->OpCode
= GDT_IOCTL
;
282 gdtcmd
->u
.ioctl
.p_param
= paddr
+ GDTH_SCRATCH
/4;
283 gdtcmd
->u
.ioctl
.param_size
= 3*GDTH_SCRATCH
/4;
284 gdtcmd
->u
.ioctl
.subfunc
= DSK_STATISTICS
| L_CTRL_PATTERN
;
285 gdtcmd
->u
.ioctl
.channel
= ha
->raw
[i
].address
| INVALID_CHANNEL
;
286 pds
->bid
= ha
->raw
[i
].local_no
;
288 pds
->entries
= ha
->raw
[i
].pdev_cnt
;
289 cnt
= (3*GDTH_SCRATCH
/4 - 5 * sizeof(ulong32
)) /
290 sizeof(pds
->list
[0]);
291 if (pds
->entries
> cnt
)
294 if (gdth_execute(host
, gdtcmd
, cmnd
, 30, NULL
) != S_OK
)
297 /* other IOCTLs must fit into area GDTH_SCRATCH/4 */
298 for (j
= 0; j
< ha
->raw
[i
].pdev_cnt
; ++j
) {
300 TRACE2(("scsi_drv_info() chn %d dev %d\n",
301 i
, ha
->raw
[i
].id_list
[j
]));
302 pdi
= (gdth_diskinfo_str
*)buf
;
303 gdtcmd
->Service
= CACHESERVICE
;
304 gdtcmd
->OpCode
= GDT_IOCTL
;
305 gdtcmd
->u
.ioctl
.p_param
= paddr
;
306 gdtcmd
->u
.ioctl
.param_size
= sizeof(gdth_diskinfo_str
);
307 gdtcmd
->u
.ioctl
.subfunc
= SCSI_DR_INFO
| L_CTRL_PATTERN
;
308 gdtcmd
->u
.ioctl
.channel
=
309 ha
->raw
[i
].address
| ha
->raw
[i
].id_list
[j
];
311 if (gdth_execute(host
, gdtcmd
, cmnd
, 30, NULL
) == S_OK
) {
312 strncpy(hrec
,pdi
->vendor
,8);
313 strncpy(hrec
+8,pdi
->product
,16);
314 strncpy(hrec
+24,pdi
->revision
,4);
316 size
= sprintf(buffer
+len
,
317 "\n Chn/ID/LUN: \t%c/%02d/%d \tName: \t%s\n",
318 'A'+i
,pdi
->target_id
,pdi
->lun
,hrec
);
319 len
+= size
; pos
= begin
+ len
;
321 pdi
->no_ldrive
&= 0xffff;
322 if (pdi
->no_ldrive
== 0xffff)
325 sprintf(hrec
,"%d",pdi
->no_ldrive
);
326 size
= sprintf(buffer
+len
,
327 " Capacity [MB]:\t%-6d \tTo Log. Drive: \t%s\n",
328 pdi
->blkcnt
/(1024*1024/pdi
->blksize
),
330 len
+= size
; pos
= begin
+ len
;
335 if (pdi
->devtype
== 0) {
336 /* search retries/reassigns */
337 for (k
= 0; k
< pds
->count
; ++k
) {
338 if (pds
->list
[k
].tid
== pdi
->target_id
&&
339 pds
->list
[k
].lun
== pdi
->lun
) {
340 size
= sprintf(buffer
+len
,
341 " Retries: \t%-6d \tReassigns: \t%d\n",
342 pds
->list
[k
].retries
,
343 pds
->list
[k
].reassigns
);
344 len
+= size
; pos
= begin
+ len
;
348 /* 2.c grown defects */
349 TRACE2(("scsi_drv_defcnt() chn %d dev %d\n",
350 i
, ha
->raw
[i
].id_list
[j
]));
351 pdef
= (gdth_defcnt_str
*)buf
;
352 gdtcmd
->Service
= CACHESERVICE
;
353 gdtcmd
->OpCode
= GDT_IOCTL
;
354 gdtcmd
->u
.ioctl
.p_param
= paddr
;
355 gdtcmd
->u
.ioctl
.param_size
= sizeof(gdth_defcnt_str
);
356 gdtcmd
->u
.ioctl
.subfunc
= SCSI_DEF_CNT
| L_CTRL_PATTERN
;
357 gdtcmd
->u
.ioctl
.channel
=
358 ha
->raw
[i
].address
| ha
->raw
[i
].id_list
[j
];
359 pdef
->sddc_type
= 0x08;
361 if (gdth_execute(host
, gdtcmd
, cmnd
, 30, NULL
) == S_OK
) {
362 size
= sprintf(buffer
+len
,
363 " Grown Defects:\t%d\n",
365 len
+= size
; pos
= begin
+ len
;
372 if (pos
> offset
+ length
)
376 gdth_ioctl_free(hanum
, GDTH_SCRATCH
, buf
, paddr
);
379 size
= sprintf(buffer
+len
, "\n --\n");
380 len
+= size
; pos
= begin
+ len
;
383 /* 3. about logical drives */
384 size
= sprintf(buffer
+len
,"\nLogical Drives:");
385 len
+= size
; pos
= begin
+ len
;
388 buf
= gdth_ioctl_alloc(hanum
, GDTH_SCRATCH
, FALSE
, &paddr
);
391 for (i
= 0; i
< MAX_LDRIVES
; ++i
) {
392 if (!ha
->hdr
[i
].is_logdrv
)
398 /* 3.a log. drive info */
399 TRACE2(("cache_drv_info() drive no %d\n",drv_no
));
400 pcdi
= (gdth_cdrinfo_str
*)buf
;
401 gdtcmd
->Service
= CACHESERVICE
;
402 gdtcmd
->OpCode
= GDT_IOCTL
;
403 gdtcmd
->u
.ioctl
.p_param
= paddr
;
404 gdtcmd
->u
.ioctl
.param_size
= sizeof(gdth_cdrinfo_str
);
405 gdtcmd
->u
.ioctl
.subfunc
= CACHE_DRV_INFO
;
406 gdtcmd
->u
.ioctl
.channel
= drv_no
;
407 if (gdth_execute(host
, gdtcmd
, cmnd
, 30, NULL
) != S_OK
)
409 pcdi
->ld_dtype
>>= 16;
411 if (pcdi
->ld_dtype
> 2) {
412 strcpy(hrec
, "missing");
413 } else if (pcdi
->ld_error
& 1) {
414 strcpy(hrec
, "fault");
415 } else if (pcdi
->ld_error
& 2) {
416 strcpy(hrec
, "invalid");
423 size
= sprintf(buffer
+len
,
424 "\n Number: \t%-2d \tStatus: \t%s\n",
426 len
+= size
; pos
= begin
+ len
;
428 no_mdrv
= pcdi
->cd_ldcnt
;
429 if (no_mdrv
> 1 || pcdi
->ld_slave
!= -1) {
431 strcpy(hrec
, "RAID-1");
432 } else if (pcdi
->ld_dtype
== 0) {
433 strcpy(hrec
, "Disk");
434 } else if (pcdi
->ld_dtype
== 1) {
435 strcpy(hrec
, "RAID-0");
436 } else if (pcdi
->ld_dtype
== 2) {
437 strcpy(hrec
, "Chain");
441 size
= sprintf(buffer
+len
,
442 " Capacity [MB]:\t%-6d \tType: \t%s\n",
443 pcdi
->ld_blkcnt
/(1024*1024/pcdi
->ld_blksize
),
445 len
+= size
; pos
= begin
+ len
;
447 size
= sprintf(buffer
+len
,
448 " Slave Number: \t%-2d \tStatus: \t%s\n",
449 drv_no
& 0x7fff, hrec
);
450 len
+= size
; pos
= begin
+ len
;
452 drv_no
= pcdi
->ld_slave
;
457 if (pos
> offset
+ length
)
459 } while (drv_no
!= -1);
462 size
= sprintf(buffer
+len
,
463 " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n",
465 len
+= size
; pos
= begin
+ len
;
468 if (!ha
->hdr
[i
].is_arraydrv
)
471 sprintf(hrec
, "%d", ha
->hdr
[i
].master_no
);
472 size
= sprintf(buffer
+len
,
473 " To Array Drv.:\t%s\n", hrec
);
474 len
+= size
; pos
= begin
+ len
;
479 if (pos
> offset
+ length
)
482 gdth_ioctl_free(hanum
, GDTH_SCRATCH
, buf
, paddr
);
485 size
= sprintf(buffer
+len
, "\n --\n");
486 len
+= size
; pos
= begin
+ len
;
489 /* 4. about array drives */
490 size
= sprintf(buffer
+len
,"\nArray Drives:");
491 len
+= size
; pos
= begin
+ len
;
494 buf
= gdth_ioctl_alloc(hanum
, GDTH_SCRATCH
, FALSE
, &paddr
);
497 for (i
= 0; i
< MAX_LDRIVES
; ++i
) {
498 if (!(ha
->hdr
[i
].is_arraydrv
&& ha
->hdr
[i
].is_master
))
500 /* 4.a array drive info */
501 TRACE2(("array_info() drive no %d\n",i
));
502 pai
= (gdth_arrayinf_str
*)buf
;
503 gdtcmd
->Service
= CACHESERVICE
;
504 gdtcmd
->OpCode
= GDT_IOCTL
;
505 gdtcmd
->u
.ioctl
.p_param
= paddr
;
506 gdtcmd
->u
.ioctl
.param_size
= sizeof(gdth_arrayinf_str
);
507 gdtcmd
->u
.ioctl
.subfunc
= ARRAY_INFO
| LA_CTRL_PATTERN
;
508 gdtcmd
->u
.ioctl
.channel
= i
;
509 if (gdth_execute(host
, gdtcmd
, cmnd
, 30, NULL
) == S_OK
) {
510 if (pai
->ai_state
== 0)
511 strcpy(hrec
, "idle");
512 else if (pai
->ai_state
== 2)
513 strcpy(hrec
, "build");
514 else if (pai
->ai_state
== 4)
515 strcpy(hrec
, "ready");
516 else if (pai
->ai_state
== 6)
517 strcpy(hrec
, "fail");
518 else if (pai
->ai_state
== 8 || pai
->ai_state
== 10)
519 strcpy(hrec
, "rebuild");
521 strcpy(hrec
, "error");
522 if (pai
->ai_ext_state
& 0x10)
523 strcat(hrec
, "/expand");
524 else if (pai
->ai_ext_state
& 0x1)
525 strcat(hrec
, "/patch");
526 size
= sprintf(buffer
+len
,
527 "\n Number: \t%-2d \tStatus: \t%s\n",
529 len
+= size
; pos
= begin
+ len
;
532 if (pai
->ai_type
== 0)
533 strcpy(hrec
, "RAID-0");
534 else if (pai
->ai_type
== 4)
535 strcpy(hrec
, "RAID-4");
536 else if (pai
->ai_type
== 5)
537 strcpy(hrec
, "RAID-5");
539 strcpy(hrec
, "RAID-10");
540 size
= sprintf(buffer
+len
,
541 " Capacity [MB]:\t%-6d \tType: \t%s\n",
542 pai
->ai_size
/(1024*1024/pai
->ai_secsize
),
544 len
+= size
; pos
= begin
+ len
;
549 if (pos
> offset
+ length
)
553 gdth_ioctl_free(hanum
, GDTH_SCRATCH
, buf
, paddr
);
556 size
= sprintf(buffer
+len
, "\n --\n");
557 len
+= size
; pos
= begin
+ len
;
560 /* 5. about host drives */
561 size
= sprintf(buffer
+len
,"\nHost Drives:");
562 len
+= size
; pos
= begin
+ len
;
565 buf
= gdth_ioctl_alloc(hanum
, sizeof(gdth_hget_str
), FALSE
, &paddr
);
568 for (i
= 0; i
< MAX_LDRIVES
; ++i
) {
569 if (!ha
->hdr
[i
].is_logdrv
||
570 (ha
->hdr
[i
].is_arraydrv
&& !ha
->hdr
[i
].is_master
))
572 /* 5.a get host drive list */
573 TRACE2(("host_get() drv_no %d\n",i
));
574 phg
= (gdth_hget_str
*)buf
;
575 gdtcmd
->Service
= CACHESERVICE
;
576 gdtcmd
->OpCode
= GDT_IOCTL
;
577 gdtcmd
->u
.ioctl
.p_param
= paddr
;
578 gdtcmd
->u
.ioctl
.param_size
= sizeof(gdth_hget_str
);
579 gdtcmd
->u
.ioctl
.subfunc
= HOST_GET
| LA_CTRL_PATTERN
;
580 gdtcmd
->u
.ioctl
.channel
= i
;
581 phg
->entries
= MAX_HDRIVES
;
582 phg
->offset
= GDTOFFSOF(gdth_hget_str
, entry
[0]);
583 if (gdth_execute(host
, gdtcmd
, cmnd
, 30, NULL
) == S_OK
) {
584 ha
->hdr
[i
].ldr_no
= i
;
585 ha
->hdr
[i
].rw_attribs
= 0;
586 ha
->hdr
[i
].start_sec
= 0;
588 for (j
= 0; j
< phg
->entries
; ++j
) {
589 k
= phg
->entry
[j
].host_drive
;
590 if (k
>= MAX_LDRIVES
)
592 ha
->hdr
[k
].ldr_no
= phg
->entry
[j
].log_drive
;
593 ha
->hdr
[k
].rw_attribs
= phg
->entry
[j
].rw_attribs
;
594 ha
->hdr
[k
].start_sec
= phg
->entry
[j
].start_sec
;
598 gdth_ioctl_free(hanum
, sizeof(gdth_hget_str
), buf
, paddr
);
600 for (i
= 0; i
< MAX_HDRIVES
; ++i
) {
601 if (!(ha
->hdr
[i
].present
))
604 size
= sprintf(buffer
+len
,
605 "\n Number: \t%-2d \tArr/Log. Drive:\t%d\n",
606 i
, ha
->hdr
[i
].ldr_no
);
607 len
+= size
; pos
= begin
+ len
;
610 size
= sprintf(buffer
+len
,
611 " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n",
612 (ulong32
)(ha
->hdr
[i
].size
/2048), ha
->hdr
[i
].start_sec
);
613 len
+= size
; pos
= begin
+ len
;
618 if (pos
> offset
+ length
)
623 size
= sprintf(buffer
+len
, "\n --\n");
624 len
+= size
; pos
= begin
+ len
;
628 /* controller events */
629 size
= sprintf(buffer
+len
,"\nController Events:\n");
630 len
+= size
; pos
= begin
+ len
;
633 id
= gdth_read_event(ha
, id
, estr
);
634 if (estr
->event_source
== 0)
636 if (estr
->event_data
.eu
.driver
.ionode
== hanum
&&
637 estr
->event_source
== ES_ASYNC
) {
638 gdth_log_event(&estr
->event_data
, hrec
);
639 do_gettimeofday(&tv
);
640 sec
= (int)(tv
.tv_sec
- estr
->first_stamp
);
641 if (sec
< 0) sec
= 0;
642 size
= sprintf(buffer
+len
," date- %02d:%02d:%02d\t%s\n",
643 sec
/3600, sec
%3600/60, sec
%60, hrec
);
644 len
+= size
; pos
= begin
+ len
;
649 if (pos
> offset
+ length
)
657 *start
= buffer
+(offset
-begin
);
658 len
-= (offset
-begin
);
661 TRACE2(("get_info() len %d pos %d begin %d offset %d length %d size %d\n",
662 len
,(int)pos
,(int)begin
,(int)offset
,length
,size
));
671 static char *gdth_ioctl_alloc(int hanum
, int size
, int scratch
,
681 ha
= HADATA(gdth_ctr_tab
[hanum
]);
682 spin_lock_irqsave(&ha
->smp_lock
, flags
);
684 if (!ha
->scratch_busy
&& size
<= GDTH_SCRATCH
) {
685 ha
->scratch_busy
= TRUE
;
686 ret_val
= ha
->pscratch
;
687 *paddr
= ha
->scratch_phys
;
688 } else if (scratch
) {
693 ret_val
= pci_alloc_consistent(ha
->pdev
, size
, &dma_addr
);
697 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
701 static void gdth_ioctl_free(int hanum
, int size
, char *buf
, ulong64 paddr
)
706 ha
= HADATA(gdth_ctr_tab
[hanum
]);
707 spin_lock_irqsave(&ha
->smp_lock
, flags
);
709 if (buf
== ha
->pscratch
) {
710 ha
->scratch_busy
= FALSE
;
712 pci_free_consistent(ha
->pdev
, size
, buf
, paddr
);
715 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
718 #ifdef GDTH_IOCTL_PROC
719 static int gdth_ioctl_check_bin(int hanum
, ushort size
)
725 ha
= HADATA(gdth_ctr_tab
[hanum
]);
726 spin_lock_irqsave(&ha
->smp_lock
, flags
);
729 if (ha
->scratch_busy
) {
730 if (((gdth_iord_str
*)ha
->pscratch
)->size
== (ulong32
)size
)
733 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
738 static void gdth_wait_completion(int hanum
, int busnum
, int id
)
746 ha
= HADATA(gdth_ctr_tab
[hanum
]);
747 spin_lock_irqsave(&ha
->smp_lock
, flags
);
749 for (i
= 0; i
< GDTH_MAXCMDS
; ++i
) {
750 scp
= ha
->cmd_tab
[i
].cmnd
;
752 b
= scp
->device
->channel
;
754 if (!SPECIAL_SCP(scp
) && t
== (unchar
)id
&&
755 b
== (unchar
)busnum
) {
756 scp
->SCp
.have_data_in
= 0;
757 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
758 while (!scp
->SCp
.have_data_in
)
760 spin_lock_irqsave(&ha
->smp_lock
, flags
);
763 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
766 static void gdth_stop_timeout(int hanum
, int busnum
, int id
)
773 ha
= HADATA(gdth_ctr_tab
[hanum
]);
774 spin_lock_irqsave(&ha
->smp_lock
, flags
);
776 for (scp
= ha
->req_first
; scp
; scp
= (Scsi_Cmnd
*)scp
->SCp
.ptr
) {
777 if (!IS_GDTH_INTERNAL_CMD(scp
)) {
778 b
= scp
->device
->channel
;
780 if (t
== (unchar
)id
&& b
== (unchar
)busnum
) {
781 TRACE2(("gdth_stop_timeout(): update_timeout()\n"));
782 scp
->SCp
.buffers_residual
= gdth_update_timeout(hanum
, scp
, 0);
786 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
789 static void gdth_start_timeout(int hanum
, int busnum
, int id
)
796 ha
= HADATA(gdth_ctr_tab
[hanum
]);
797 spin_lock_irqsave(&ha
->smp_lock
, flags
);
799 for (scp
= ha
->req_first
; scp
; scp
= (Scsi_Cmnd
*)scp
->SCp
.ptr
) {
800 if (!IS_GDTH_INTERNAL_CMD(scp
)) {
801 b
= scp
->device
->channel
;
803 if (t
== (unchar
)id
&& b
== (unchar
)busnum
) {
804 TRACE2(("gdth_start_timeout(): update_timeout()\n"));
805 gdth_update_timeout(hanum
, scp
, scp
->SCp
.buffers_residual
);
809 spin_unlock_irqrestore(&ha
->smp_lock
, flags
);
812 static int gdth_update_timeout(int hanum
, Scsi_Cmnd
*scp
, int timeout
)
816 oldto
= scp
->timeout_per_command
;
817 scp
->timeout_per_command
= timeout
;
820 del_timer(&scp
->eh_timeout
);
821 scp
->eh_timeout
.data
= (unsigned long) NULL
;
822 scp
->eh_timeout
.expires
= 0;
824 if (scp
->eh_timeout
.data
!= (unsigned long) NULL
)
825 del_timer(&scp
->eh_timeout
);
826 scp
->eh_timeout
.data
= (unsigned long) scp
;
827 scp
->eh_timeout
.expires
= jiffies
+ timeout
;
828 add_timer(&scp
->eh_timeout
);