2 * $Id: gdth_proc.c,v 1.1.1.1 2005/04/11 02:50:36 jack Exp $
5 #include "gdth_ioctl.h"
6 #if LINUX_VERSION_CODE >= 0x020407
7 #include <linux/completion.h>
10 int gdth_proc_info(char *buffer,char **start,off_t offset,int length,
15 TRACE2(("gdth_proc_info() length %d ha %d offs %d inout %d\n",
16 length,hostno,(int)offset,inout));
18 for (i=0; i<gdth_ctr_vcount; ++i) {
19 if (gdth_ctr_vtab[i]->host_no == hostno)
22 if (i==gdth_ctr_vcount)
25 hanum = NUMDATA(gdth_ctr_vtab[i])->hanum;
26 busnum= NUMDATA(gdth_ctr_vtab[i])->busnum;
29 return(gdth_set_info(buffer,length,i,hanum,busnum));
31 return(gdth_get_info(buffer,start,offset,length,i,hanum,busnum));
34 static int gdth_set_info(char *buffer,int length,int vh,int hanum,int busnum)
37 #if LINUX_VERSION_CODE >= 0x020322
46 TRACE2(("gdth_set_info() ha %d bus %d\n",hanum,busnum));
47 piowr = (gdth_iowr_str *)buffer;
49 #if LINUX_VERSION_CODE >= 0x020322
50 sdev = scsi_get_host_dev(gdth_ctr_vtab[vh]);
51 scp = scsi_allocate_device(sdev, 1, FALSE);
57 memset(&sdev,0,sizeof(Scsi_Device));
58 memset(&scp, 0,sizeof(Scsi_Cmnd));
59 sdev.host = scp.host = gdth_ctr_vtab[vh];
60 sdev.id = scp.target = sdev.host->this_id;
65 if (strncmp(buffer,"gdth",4) == 0) {
68 ret_val = gdth_set_asc_info( buffer, length, hanum, scp );
69 } else if (piowr->magic == GDTIOCTL_MAGIC) {
70 ret_val = gdth_set_bin_info( buffer, length, hanum, scp );
72 printk("GDT: Wrong signature %x (%x required)!\n",
73 piowr->magic, GDTIOCTL_MAGIC);
74 if (piowr->magic > GDTIOCTL_MAGIC)
75 printk("GDT: Please update your driver.\n");
77 printk("GDT: Please update your tool.\n");
83 #if LINUX_VERSION_CODE >= 0x020322
84 scsi_release_command(scp);
85 scsi_free_host_dev(sdev);
90 #if LINUX_VERSION_CODE >= 0x020322
91 static int gdth_set_asc_info(char *buffer,int length,int hanum,Scsi_Cmnd *scp)
93 static int gdth_set_asc_info(char *buffer,int length,int hanum,Scsi_Cmnd scp)
96 int orig_length, drive, wb_mode;
100 gdth_cpar_str *pcpar;
102 char cmnd[MAX_COMMAND_SIZE];
103 memset(cmnd, 0xff, 12);
104 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
106 TRACE2(("gdth_set_asc_info() ha %d\n",hanum));
107 ha = HADATA(gdth_ctr_tab[hanum]);
108 orig_length = length + 5;
113 if (length >= 5 && strncmp(buffer,"flush",5)==0) {
116 if (length && *buffer>='0' && *buffer<='9') {
117 drive = (int)(*buffer-'0');
119 if (length && *buffer>='0' && *buffer<='9') {
120 drive = drive*10 + (int)(*buffer-'0');
123 printk("GDT: Flushing host drive %d .. ",drive);
125 printk("GDT: Flushing all host drives .. ");
127 for (i = 0; i < MAX_HDRIVES; ++i) {
128 if (ha->hdr[i].present) {
129 if (drive != -1 && i != drive)
132 gdtcmd.Service = CACHESERVICE;
133 gdtcmd.OpCode = GDT_FLUSH;
134 gdtcmd.u.cache.DeviceNo = i;
135 gdtcmd.u.cache.BlockNo = 1;
136 #if LINUX_VERSION_CODE >= 0x020322
137 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
139 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
144 printk("\nNo host drive found !\n");
150 if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {
153 printk("GDT: Disabling write back permanently .. ");
155 } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {
158 printk("GDT: Enabling write back permanently .. ");
160 } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {
163 printk("GDT: Disabling write back commands .. ");
164 if (ha->cache_feat & GDT_WR_THROUGH) {
165 gdth_write_through = TRUE;
168 printk("Not supported !\n");
171 } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {
174 printk("GDT: Enabling write back commands .. ");
175 gdth_write_through = FALSE;
181 if (!gdth_ioctl_alloc(hanum, sizeof(gdth_cpar_str), TRUE))
183 pcpar = (gdth_cpar_str *)ha->pscratch;
184 memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );
185 gdtcmd.Service = CACHESERVICE;
186 gdtcmd.OpCode = GDT_IOCTL;
187 gdtcmd.u.ioctl.p_param = virt_to_bus(pcpar);
188 gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
189 gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
190 gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
191 pcpar->write_back = wb_mode==1 ? 0:1;
192 #if LINUX_VERSION_CODE >= 0x020322
193 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
195 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
197 gdth_ioctl_free(hanum, ha->pscratch);
202 printk("GDT: Unknown command: %s Length: %d\n",buffer,length);
206 #if LINUX_VERSION_CODE >= 0x020322
207 static int gdth_set_bin_info(char *buffer,int length,int hanum,Scsi_Cmnd *scp)
209 static int gdth_set_bin_info(char *buffer,int length,int hanum,Scsi_Cmnd scp)
213 ushort k, hdr_cnt, status;
215 gdth_iowr_str *piowr;
216 gdth_iord_str *piord;
219 ulong32 *ppadd, add_size, *ppadd2, add_size2, info;
222 int drv_cyls, drv_hds, drv_secs;
224 char cmnd[MAX_COMMAND_SIZE];
225 memset(cmnd, 0xff, 12);
226 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
228 TRACE2(("gdth_set_bin_info() ha %d\n",hanum));
229 ha = HADATA(gdth_ctr_tab[hanum]);
230 piowr = (gdth_iowr_str *)buffer;
233 ppadd = ppadd2 = NULL;
234 add_size = add_size2 = 0;
236 if (length < GDTOFFSOF(gdth_iowr_str,iu))
239 switch (piowr->ioctl) {
240 case GDTIOCTL_GENERAL:
241 if (length < GDTOFFSOF(gdth_iowr_str,iu.general.data[0]))
243 pcmd = (gdth_cmd_str *)piowr->iu.general.command;
244 pcmd->Service = piowr->service;
245 if (pcmd->OpCode == GDT_IOCTL) {
246 ppadd = &pcmd->u.ioctl.p_param;
247 add_size = pcmd->u.ioctl.param_size;
248 } else if (piowr->service == CACHESERVICE) {
249 add_size = pcmd->u.cache.BlockCnt * SECTOR_SIZE;
250 if (ha->cache_feat & SCATTER_GATHER) {
251 ppadd = &pcmd->u.cache.sg_lst[0].sg_ptr;
252 pcmd->u.cache.DestAddr = 0xffffffff;
253 pcmd->u.cache.sg_lst[0].sg_len = add_size;
254 pcmd->u.cache.sg_canz = 1;
256 ppadd = &pcmd->u.cache.DestAddr;
257 pcmd->u.cache.sg_canz = 0;
259 } else if (piowr->service == SCSIRAWSERVICE) {
260 add_size = pcmd->u.raw.sdlen;
261 add_size2 = pcmd->u.raw.sense_len;
262 if (ha->raw_feat & SCATTER_GATHER) {
263 ppadd = &pcmd->u.raw.sg_lst[0].sg_ptr;
264 pcmd->u.raw.sdata = 0xffffffff;
265 pcmd->u.raw.sg_lst[0].sg_len = add_size;
266 pcmd->u.raw.sg_ranz = 1;
268 ppadd = &pcmd->u.raw.sdata;
269 pcmd->u.raw.sg_ranz = 0;
271 ppadd2 = &pcmd->u.raw.sense_data;
275 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str)+add_size+add_size2,
278 piord = (gdth_iord_str *)ha->pscratch;
280 piord->size = sizeof(gdth_iord_str) + add_size + add_size2;
282 memcpy(piord->iu.general.data, piowr->iu.general.data, add_size);
283 *ppadd = virt_to_bus(piord->iu.general.data);
286 memcpy(piord->iu.general.data+add_size, piowr->iu.general.data, add_size2);
287 *ppadd2 = virt_to_bus(piord->iu.general.data+add_size);
290 #if LINUX_VERSION_CODE >= 0x020322
291 gdth_do_cmd(scp, pcmd, cmnd, piowr->timeout);
292 piord->status = (scp->SCp.Message<<16)|scp->SCp.Status;
294 gdth_do_cmd(&scp, pcmd, cmnd, piowr->timeout);
295 piord->status = (scp.SCp.Message<<16)|scp.SCp.Status;
299 case GDTIOCTL_DRVERS:
300 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
302 piord = (gdth_iord_str *)ha->pscratch;
303 piord->size = sizeof(gdth_iord_str);
304 piord->status = S_OK;
305 piord->iu.drvers.version = (GDTH_VERSION<<8) | GDTH_SUBVERSION;
308 case GDTIOCTL_CTRTYPE:
309 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
311 piord = (gdth_iord_str *)ha->pscratch;
312 piord->size = sizeof(gdth_iord_str);
313 piord->status = S_OK;
314 if (ha->type == GDT_ISA || ha->type == GDT_EISA) {
315 piord->iu.ctrtype.type = (unchar)((ha->stype>>20) - 0x10);
317 if (ha->type != GDT_PCIMPR) {
318 piord->iu.ctrtype.type = (unchar)((ha->stype<<4) + 6);
320 piord->iu.ctrtype.type =
321 (ha->oem_id == OEM_ID_INTEL ? 0xfd : 0xfe);
322 if (ha->stype >= 0x300)
323 piord->iu.ctrtype.ext_type = 0x6000 | ha->subdevice_id;
325 piord->iu.ctrtype.ext_type = 0x6000 | ha->stype;
327 piord->iu.ctrtype.device_id = ha->stype;
328 piord->iu.ctrtype.sub_device_id = ha->subdevice_id;
330 piord->iu.ctrtype.info = ha->brd_phys;
331 piord->iu.ctrtype.oem_id = ha->oem_id;
334 case GDTIOCTL_CTRCNT:
335 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
337 piord = (gdth_iord_str *)ha->pscratch;
338 piord->size = sizeof(gdth_iord_str);
339 piord->status = S_OK;
340 piord->iu.ctrcnt.count = (ushort)gdth_ctr_count;
343 case GDTIOCTL_OSVERS:
344 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
346 piord = (gdth_iord_str *)ha->pscratch;
347 piord->size = sizeof(gdth_iord_str);
348 piord->status = S_OK;
349 piord->iu.osvers.version = (unchar)(LINUX_VERSION_CODE >> 16);
350 piord->iu.osvers.subversion = (unchar)(LINUX_VERSION_CODE >> 8);
351 piord->iu.osvers.revision = (ushort)(LINUX_VERSION_CODE & 0xff);
354 case GDTIOCTL_LOCKDRV:
355 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
357 piord = (gdth_iord_str *)ha->pscratch;
358 for (i = 0; i < piowr->iu.lockdrv.drive_cnt; ++i) {
359 j = piowr->iu.lockdrv.drives[i];
360 if (j >= MAX_HDRIVES || !ha->hdr[j].present)
362 if (piowr->iu.lockdrv.lock) {
363 GDTH_LOCK_HA(ha, flags);
365 GDTH_UNLOCK_HA(ha, flags);
366 gdth_wait_completion( hanum, ha->bus_cnt, j );
367 gdth_stop_timeout( hanum, ha->bus_cnt, j );
369 GDTH_LOCK_HA(ha, flags);
371 GDTH_UNLOCK_HA(ha, flags);
372 gdth_start_timeout( hanum, ha->bus_cnt, j );
376 piord->size = sizeof(gdth_iord_str);
377 piord->status = S_OK;
380 case GDTIOCTL_LOCKCHN:
381 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
383 i = piowr->iu.lockchn.channel;
384 if (i < ha->bus_cnt) {
385 if (piowr->iu.lockchn.lock) {
386 GDTH_LOCK_HA(ha, flags);
388 GDTH_UNLOCK_HA(ha, flags);
389 for (j = 0; j < ha->tid_cnt; ++j) {
390 gdth_wait_completion( hanum, i, j );
391 gdth_stop_timeout( hanum, i, j );
394 GDTH_LOCK_HA(ha, flags);
396 GDTH_UNLOCK_HA(ha, flags);
397 for (j = 0; j < ha->tid_cnt; ++j) {
398 gdth_start_timeout( hanum, i, j );
403 piord = (gdth_iord_str *)ha->pscratch;
404 piord->size = sizeof(gdth_iord_str);
405 piord->status = S_OK;
409 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
411 piord = (gdth_iord_str *)ha->pscratch;
412 if (piowr->iu.event.erase == 0xff) {
413 pevt = (gdth_evt_str *)piowr->iu.event.evt;
414 if (pevt->event_source == ES_TEST)
415 pevt->event_data.size = sizeof(pevt->event_data.eu.test);
416 else if (pevt->event_source == ES_DRIVER)
417 pevt->event_data.size = sizeof(pevt->event_data.eu.driver);
418 else if (pevt->event_source == ES_SYNC)
419 pevt->event_data.size = sizeof(pevt->event_data.eu.sync);
421 pevt->event_data.size = sizeof(pevt->event_data.eu.async);
422 gdth_log_event(&pevt->event_data, NULL);
424 GDTH_LOCK_HA(ha, flags);
425 gdth_store_event(ha, pevt->event_source, pevt->event_idx,
427 GDTH_UNLOCK_HA(ha, flags);
428 } else if (piowr->iu.event.erase == 0xfe) {
430 } else if (piowr->iu.event.erase == 0) {
431 piord->iu.event.handle =
432 gdth_read_event(ha,piowr->iu.event.handle,
433 (gdth_evt_str *)piord->iu.event.evt);
435 piord->iu.event.handle = piowr->iu.event.handle;
436 gdth_readapp_event(ha, (unchar)piowr->iu.event.erase,
437 (gdth_evt_str *)piord->iu.event.evt);
439 piord->size = sizeof(gdth_iord_str);
440 piord->status = S_OK;
444 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
446 piord = (gdth_iord_str *)ha->pscratch;
447 piord->size = sizeof(gdth_iord_str);
448 memcpy(cmnd, piowr->iu.scsi.cmd, 12);
449 #if LINUX_VERSION_CODE >= 0x020322
450 scp->target = piowr->iu.scsi.target;
451 scp->channel = virt_ctr ? 0 : piowr->iu.scsi.bus;
452 scp->cmd_len = piowr->iu.scsi.cmd_len;
453 gdth_do_cmd(scp, pcmd, cmnd, piowr->timeout);
454 piord->status = (scp->SCp.Message<<16)|scp->SCp.Status;
456 scp.target = piowr->iu.scsi.target;
457 scp.channel = virt_ctr ? 0 : piowr->iu.scsi.bus;
458 scp.cmd_len = piowr->iu.scsi.cmd_len;
459 gdth_do_cmd(&scp, pcmd, cmnd, piowr->timeout);
460 piord->status = (scp.SCp.Message<<16)|scp.SCp.Status;
464 case GDTIOCTL_RESET_BUS:
465 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
467 piord = (gdth_iord_str *)ha->pscratch;
468 piord->size = sizeof(gdth_iord_str);
469 #if LINUX_VERSION_CODE >= 0x020322
470 scp->channel = virt_ctr ? 0 : piowr->iu.scsi.bus;
471 piord->status = (ulong32)gdth_eh_bus_reset( scp );
472 if (piord->status == SUCCESS)
473 piord->status = S_OK;
475 piord->status = S_GENERR;
476 #elif LINUX_VERSION_CODE >= 0x02015F
477 scp.channel = virt_ctr ? 0 : piowr->iu.scsi.bus;
478 piord->status = (ulong32)gdth_eh_bus_reset( &scp );
479 if (piord->status == SUCCESS)
480 piord->status = S_OK;
482 piord->status = S_GENERR;
484 piord->status = S_OK;
488 case GDTIOCTL_HDRLIST:
489 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
491 piord = (gdth_iord_str *)ha->pscratch;
492 piord->size = sizeof(gdth_iord_str);
493 piord->status = S_OK;
494 for (i = 0; i < MAX_HDRIVES; ++i) {
495 if (ha->hdr[i].present) {
496 piord->iu.hdr_list[i].bus = ha->virt_bus;
497 piord->iu.hdr_list[i].target = i;
498 piord->iu.hdr_list[i].lun = 0;
499 piord->iu.hdr_list[i].cluster_type = ha->hdr[i].cluster_type;
500 if (ha->hdr[i].cluster_type & CLUSTER_DRIVE) {
501 gdtcmd.Service = CACHESERVICE;
502 gdtcmd.OpCode = GDT_CLUST_INFO;
503 gdtcmd.u.cache.DeviceNo = i;
504 #if LINUX_VERSION_CODE >= 0x020322
505 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
506 if (scp->SCp.Status == S_OK)
507 piord->iu.hdr_list[i].cluster_type =
508 (unchar)scp->SCp.Message;
510 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
511 if (scp.SCp.Status == S_OK)
512 piord->iu.hdr_list[i].cluster_type =
513 (unchar)scp.SCp.Message;
517 piord->iu.hdr_list[i].bus = 0xff;
522 case GDTIOCTL_RESCAN:
523 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
525 piord = (gdth_iord_str *)ha->pscratch;
526 piord->size = sizeof(gdth_iord_str);
527 piord->status = S_OK;
528 if (piowr->iu.rescan.flag == 0) {
529 /* old method: scan all host drives
530 re-initialize cache service to get host drive count
532 gdtcmd.Service = CACHESERVICE;
533 gdtcmd.OpCode = GDT_INIT;
534 gdtcmd.u.cache.DeviceNo = LINUX_OS;
535 #if LINUX_VERSION_CODE >= 0x020322
536 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
537 status = (ushort)scp->SCp.Status;
538 info = (ulong32)scp->SCp.Message;
540 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
541 status = (ushort)scp.SCp.Status;
542 info = (ulong32)scp.SCp.Message;
547 hdr_cnt = (ushort)info;
549 k = piowr->iu.rescan.hdr_no;
552 if (hdr_cnt > MAX_HDRIVES)
553 hdr_cnt = MAX_HDRIVES;
554 /* scanning for host drives */
555 for (; k < hdr_cnt; ++k) {
556 /* info about host drive */
557 gdtcmd.Service = CACHESERVICE;
558 gdtcmd.OpCode = GDT_INFO;
559 gdtcmd.u.cache.DeviceNo = k;
560 #if LINUX_VERSION_CODE >= 0x020322
561 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
562 status = (ushort)scp->SCp.Status;
563 info = (ulong32)scp->SCp.Message;
565 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
566 status = (ushort)scp.SCp.Status;
567 info = (ulong32)scp.SCp.Message;
569 GDTH_LOCK_HA(ha, flags);
570 piord->iu.hdr_list[k].bus = ha->virt_bus;
571 piord->iu.hdr_list[k].target = k;
572 piord->iu.hdr_list[k].lun = 0;
573 if (status != S_OK) {
574 ha->hdr[k].present = FALSE;
576 ha->hdr[k].present = TRUE;
577 ha->hdr[k].size = info;
578 /* evaluate mapping (sectors per head, heads per cylinder) */
579 ha->hdr[k].size &= ~SECS32;
580 gdth_eval_mapping(ha->hdr[k].size,&drv_cyls,&drv_hds,&drv_secs);
581 ha->hdr[k].heads = (unchar)drv_hds;
582 ha->hdr[k].secs = (unchar)drv_secs;
584 ha->hdr[k].size = drv_cyls * drv_hds * drv_secs;
586 GDTH_UNLOCK_HA(ha, flags);
588 continue; /* next host drive */
590 /* devtype, cluster info, R/W attributes */
591 gdtcmd.Service = CACHESERVICE;
592 gdtcmd.OpCode = GDT_DEVTYPE;
593 gdtcmd.u.cache.DeviceNo = k;
594 #if LINUX_VERSION_CODE >= 0x020322
595 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
596 status = (ushort)scp->SCp.Status;
597 info = (ulong32)scp->SCp.Message;
599 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
600 status = (ushort)scp.SCp.Status;
601 info = (ulong32)scp.SCp.Message;
603 GDTH_LOCK_HA(ha, flags);
604 ha->hdr[k].devtype = 0;
606 ha->hdr[k].devtype = (ushort)info;
607 GDTH_UNLOCK_HA(ha, flags);
609 gdtcmd.Service = CACHESERVICE;
610 gdtcmd.OpCode = GDT_CLUST_INFO;
611 gdtcmd.u.cache.DeviceNo = k;
612 #if LINUX_VERSION_CODE >= 0x020322
613 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
614 status = (ushort)scp->SCp.Status;
615 info = (ulong32)scp->SCp.Message;
617 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
618 status = (ushort)scp.SCp.Status;
619 info = (ulong32)scp.SCp.Message;
621 GDTH_LOCK_HA(ha, flags);
622 ha->hdr[k].cluster_type = 0;
623 if (status == S_OK && !shared_access)
624 ha->hdr[k].cluster_type = (ushort)info;
625 GDTH_UNLOCK_HA(ha, flags);
626 piord->iu.hdr_list[k].cluster_type = ha->hdr[k].cluster_type;
628 gdtcmd.Service = CACHESERVICE;
629 gdtcmd.OpCode = GDT_RW_ATTRIBS;
630 gdtcmd.u.cache.DeviceNo = k;
631 #if LINUX_VERSION_CODE >= 0x020322
632 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
633 status = (ushort)scp->SCp.Status;
634 info = (ulong32)scp->SCp.Message;
636 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
637 status = (ushort)scp.SCp.Status;
638 info = (ulong32)scp.SCp.Message;
640 GDTH_LOCK_HA(ha, flags);
641 ha->hdr[k].rw_attribs = 0;
643 ha->hdr[k].rw_attribs = (ushort)info;
644 GDTH_UNLOCK_HA(ha, flags);
648 case GDTIOCTL_RESET_DRV:
649 if (!gdth_ioctl_alloc( hanum, sizeof(gdth_iord_str), TRUE ))
651 piord = (gdth_iord_str *)ha->pscratch;
652 piord->size = sizeof(gdth_iord_str);
653 piord->status = S_OK;
654 i = piowr->iu.scsi.target;
655 if (ha->hdr[i].present) {
656 gdtcmd.Service = CACHESERVICE;
657 gdtcmd.OpCode = GDT_CLUST_RESET;
658 gdtcmd.u.cache.DeviceNo = i;
659 #if LINUX_VERSION_CODE >= 0x020322
660 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
661 piord->status = (scp->SCp.Message<<16)|scp->SCp.Status;
663 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
664 piord->status = (scp.SCp.Message<<16)|scp.SCp.Status;
675 static int gdth_get_info(char *buffer,char **start,off_t offset,
676 int length,int vh,int hanum,int busnum)
678 int size = 0,len = 0;
679 off_t begin = 0,pos = 0;
681 gdth_iord_str *piord;
682 int id, i, j, k, sec, flag;
683 int no_mdrv = 0, drv_no, is_mirr;
688 #if LINUX_VERSION_CODE >= 0x020322
699 gdth_dskstat_str *pds;
700 gdth_diskinfo_str *pdi;
701 gdth_arrayinf_str *pai;
702 gdth_defcnt_str *pdef;
703 gdth_cdrinfo_str *pcdi;
706 char cmnd[MAX_COMMAND_SIZE];
707 memset(cmnd, 0xff, 12);
708 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
710 TRACE2(("gdth_get_info() ha %d bus %d\n",hanum,busnum));
711 ha = HADATA(gdth_ctr_tab[hanum]);
713 #if LINUX_VERSION_CODE >= 0x020322
714 sdev = scsi_get_host_dev(gdth_ctr_vtab[vh]);
715 scp = scsi_allocate_device(sdev, 1, FALSE);
721 memset(&sdev,0,sizeof(Scsi_Device));
722 memset(&scp, 0,sizeof(Scsi_Cmnd));
723 sdev.host = scp.host = gdth_ctr_vtab[vh];
724 sdev.id = scp.target = sdev.host->this_id;
728 /* ioctl from tool? */
729 if (!gdth_ioctl_check_bin(hanum, (ushort)length)) {
730 /* request is i.e. "cat /proc/scsi/gdth/0" */
731 /* format: %-15s\t%-10s\t%-15s\t%s */
732 /* driver parameters */
733 size = sprintf(buffer+len,"Driver Parameters:\n");
734 len += size; pos = begin + len;
735 if (reserve_list[0] == 0xff)
738 sprintf(hrec, "%d", reserve_list[0]);
739 for (i = 1; i < MAX_RES_ARGS; i++) {
740 if (reserve_list[i] == 0xff)
742 sprintf(hrec,"%s,%d", hrec, reserve_list[i]);
745 size = sprintf(buffer+len,
746 " reserve_mode: \t%d \treserve_list: \t%s\n",
748 len += size; pos = begin + len;
749 size = sprintf(buffer+len,
750 " max_ids: \t%-3d \thdr_channel: \t%d\n",
751 max_ids, hdr_channel);
752 len += size; pos = begin + len;
754 /* controller information */
755 size = sprintf(buffer+len,"\nDisk Array Controller Information:\n");
756 len += size; pos = begin + len;
758 sprintf(hrec, "%s (Bus %d)", ha->binfo.type_string, busnum);
760 strcpy(hrec, ha->binfo.type_string);
761 size = sprintf(buffer+len,
762 " Number: \t%d \tName: \t%s\n",
764 len += size; pos = begin + len;
767 sprintf(hrec, "%d.%02d.%02d-%c%03X",
768 (unchar)(ha->binfo.upd_fw_ver>>24),
769 (unchar)(ha->binfo.upd_fw_ver>>16),
770 (unchar)(ha->binfo.upd_fw_ver),
771 ha->bfeat.raid ? 'R':'N',
772 ha->binfo.upd_revision);
774 sprintf(hrec, "%d.%02d", (unchar)(ha->cpar.version>>8),
775 (unchar)(ha->cpar.version));
777 size = sprintf(buffer+len,
778 " Driver Ver.: \t%-10s\tFirmware Ver.: \t%s\n",
779 GDTH_VERSION_STR, hrec);
780 len += size; pos = begin + len;
786 if (pos > offset + length)
790 /* more information: 1. about controller */
791 size = sprintf(buffer+len,
792 " Serial No.: \t0x%8X\tCache RAM size:\t%d KB\n",
793 ha->binfo.ser_no, ha->binfo.memsize / 1024);
794 len += size; pos = begin + len;
796 /* 2. about physical devices */
797 size = sprintf(buffer+len,"\nPhysical Devices:");
798 len += size; pos = begin + len;
801 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE);
804 for (i = 0; i < ha->bus_cnt; ++i) {
805 /* 2.a statistics (and retries/reassigns) */
806 TRACE2(("pdr_statistics() chn %d\n",i));
807 pds = (gdth_dskstat_str *)(buf + GDTH_SCRATCH/4);
808 gdtcmd.Service = CACHESERVICE;
809 gdtcmd.OpCode = GDT_IOCTL;
810 gdtcmd.u.ioctl.p_param = virt_to_bus(pds);
811 gdtcmd.u.ioctl.param_size = 3*GDTH_SCRATCH/4;
812 gdtcmd.u.ioctl.subfunc = DSK_STATISTICS | L_CTRL_PATTERN;
813 gdtcmd.u.ioctl.channel = ha->raw[i].address | INVALID_CHANNEL;
814 pds->bid = ha->raw[i].local_no;
816 pds->entries = ha->raw[i].pdev_cnt;
817 cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(ulong32)) /
818 sizeof(pds->list[0]);
819 if (pds->entries > cnt)
821 #if LINUX_VERSION_CODE >= 0x020322
822 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
823 if (scp->SCp.Status != S_OK)
825 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
826 if (scp.SCp.Status != S_OK)
832 /* other IOCTLs must fit into area GDTH_SCRATCH/4 */
833 for (j = 0; j < ha->raw[i].pdev_cnt; ++j) {
835 TRACE2(("scsi_drv_info() chn %d dev %d\n",
836 i, ha->raw[i].id_list[j]));
837 pdi = (gdth_diskinfo_str *)buf;
838 gdtcmd.Service = CACHESERVICE;
839 gdtcmd.OpCode = GDT_IOCTL;
840 gdtcmd.u.ioctl.p_param = virt_to_bus(pdi);
841 gdtcmd.u.ioctl.param_size = sizeof(gdth_diskinfo_str);
842 gdtcmd.u.ioctl.subfunc = SCSI_DR_INFO | L_CTRL_PATTERN;
843 gdtcmd.u.ioctl.channel =
844 ha->raw[i].address | ha->raw[i].id_list[j];
845 #if LINUX_VERSION_CODE >= 0x020322
846 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
847 if (scp->SCp.Status == S_OK)
849 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
850 if (scp.SCp.Status == S_OK)
853 strncpy(hrec,pdi->vendor,8);
854 strncpy(hrec+8,pdi->product,16);
855 strncpy(hrec+24,pdi->revision,4);
857 size = sprintf(buffer+len,
858 "\n Chn/ID/LUN: \t%c/%02d/%d \tName: \t%s\n",
859 'A'+i,pdi->target_id,pdi->lun,hrec);
860 len += size; pos = begin + len;
862 pdi->no_ldrive &= 0xffff;
863 if (pdi->no_ldrive == 0xffff)
866 sprintf(hrec,"%d",pdi->no_ldrive);
867 size = sprintf(buffer+len,
868 " Capacity [MB]:\t%-6d \tTo Log. Drive: \t%s\n",
869 pdi->blkcnt/(1024*1024/pdi->blksize),
871 len += size; pos = begin + len;
876 if (pdi->devtype == 0) {
877 /* search retries/reassigns */
878 for (k = 0; k < pds->count; ++k) {
879 if (pds->list[k].tid == pdi->target_id &&
880 pds->list[k].lun == pdi->lun) {
881 size = sprintf(buffer+len,
882 " Retries: \t%-6d \tReassigns: \t%d\n",
883 pds->list[k].retries,
884 pds->list[k].reassigns);
885 len += size; pos = begin + len;
889 /* 2.c grown defects */
890 TRACE2(("scsi_drv_defcnt() chn %d dev %d\n",
891 i, ha->raw[i].id_list[j]));
892 pdef = (gdth_defcnt_str *)buf;
893 gdtcmd.Service = CACHESERVICE;
894 gdtcmd.OpCode = GDT_IOCTL;
895 gdtcmd.u.ioctl.p_param = virt_to_bus(pdef);
896 gdtcmd.u.ioctl.param_size = sizeof(gdth_defcnt_str);
897 gdtcmd.u.ioctl.subfunc = SCSI_DEF_CNT | L_CTRL_PATTERN;
898 gdtcmd.u.ioctl.channel =
899 ha->raw[i].address | ha->raw[i].id_list[j];
900 pdef->sddc_type = 0x08;
901 #if LINUX_VERSION_CODE >= 0x020322
902 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
903 if (scp->SCp.Status == S_OK)
905 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
906 if (scp.SCp.Status == S_OK)
909 size = sprintf(buffer+len,
910 " Grown Defects:\t%d\n",
912 len += size; pos = begin + len;
919 if (pos > offset + length)
923 gdth_ioctl_free(hanum, buf);
926 size = sprintf(buffer+len, "\n --\n");
927 len += size; pos = begin + len;
930 /* 3. about logical drives */
931 size = sprintf(buffer+len,"\nLogical Drives:");
932 len += size; pos = begin + len;
935 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE);
938 for (i = 0; i < MAX_LDRIVES; ++i) {
939 if (!ha->hdr[i].is_logdrv)
945 /* 3.a log. drive info */
946 TRACE2(("cache_drv_info() drive no %d\n",drv_no));
947 pcdi = (gdth_cdrinfo_str *)buf;
948 gdtcmd.Service = CACHESERVICE;
949 gdtcmd.OpCode = GDT_IOCTL;
950 gdtcmd.u.ioctl.p_param = virt_to_bus(pcdi);
951 gdtcmd.u.ioctl.param_size = sizeof(gdth_cdrinfo_str);
952 gdtcmd.u.ioctl.subfunc = CACHE_DRV_INFO;
953 gdtcmd.u.ioctl.channel = drv_no;
954 #if LINUX_VERSION_CODE >= 0x020322
955 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
956 if (scp->SCp.Status != S_OK)
958 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
959 if (scp.SCp.Status != S_OK)
964 pcdi->ld_dtype >>= 16;
966 if (pcdi->ld_dtype > 2) {
967 strcpy(hrec, "missing");
968 } else if (pcdi->ld_error & 1) {
969 strcpy(hrec, "fault");
970 } else if (pcdi->ld_error & 2) {
971 strcpy(hrec, "invalid");
978 size = sprintf(buffer+len,
979 "\n Number: \t%-2d \tStatus: \t%s\n",
981 len += size; pos = begin + len;
983 no_mdrv = pcdi->cd_ldcnt;
984 if (no_mdrv > 1 || pcdi->ld_slave != -1) {
986 strcpy(hrec, "RAID-1");
987 } else if (pcdi->ld_dtype == 0) {
988 strcpy(hrec, "Disk");
989 } else if (pcdi->ld_dtype == 1) {
990 strcpy(hrec, "RAID-0");
991 } else if (pcdi->ld_dtype == 2) {
992 strcpy(hrec, "Chain");
996 size = sprintf(buffer+len,
997 " Capacity [MB]:\t%-6d \tType: \t%s\n",
998 pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize),
1000 len += size; pos = begin + len;
1002 size = sprintf(buffer+len,
1003 " Slave Number: \t%-2d \tStatus: \t%s\n",
1004 drv_no & 0x7fff, hrec);
1005 len += size; pos = begin + len;
1007 drv_no = pcdi->ld_slave;
1012 if (pos > offset + length)
1014 } while (drv_no != -1);
1017 size = sprintf(buffer+len,
1018 " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n",
1019 no_mdrv - j - k, k);
1020 len += size; pos = begin + len;
1023 if (!ha->hdr[i].is_arraydrv)
1026 sprintf(hrec, "%d", ha->hdr[i].master_no);
1027 size = sprintf(buffer+len,
1028 " To Array Drv.:\t%s\n", hrec);
1029 len += size; pos = begin + len;
1034 if (pos > offset + length)
1037 gdth_ioctl_free(hanum, buf);
1040 size = sprintf(buffer+len, "\n --\n");
1041 len += size; pos = begin + len;
1044 /* 4. about array drives */
1045 size = sprintf(buffer+len,"\nArray Drives:");
1046 len += size; pos = begin + len;
1049 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE);
1052 for (i = 0; i < MAX_LDRIVES; ++i) {
1053 if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
1055 /* 4.a array drive info */
1056 TRACE2(("array_info() drive no %d\n",i));
1057 pai = (gdth_arrayinf_str *)buf;
1058 gdtcmd.Service = CACHESERVICE;
1059 gdtcmd.OpCode = GDT_IOCTL;
1060 gdtcmd.u.ioctl.p_param = virt_to_bus(pai);
1061 gdtcmd.u.ioctl.param_size = sizeof(gdth_arrayinf_str);
1062 gdtcmd.u.ioctl.subfunc = ARRAY_INFO | LA_CTRL_PATTERN;
1063 gdtcmd.u.ioctl.channel = i;
1064 #if LINUX_VERSION_CODE >= 0x020322
1065 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
1066 if (scp->SCp.Status == S_OK)
1068 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
1069 if (scp.SCp.Status == S_OK)
1072 if (pai->ai_state == 0)
1073 strcpy(hrec, "idle");
1074 else if (pai->ai_state == 2)
1075 strcpy(hrec, "build");
1076 else if (pai->ai_state == 4)
1077 strcpy(hrec, "ready");
1078 else if (pai->ai_state == 6)
1079 strcpy(hrec, "fail");
1080 else if (pai->ai_state == 8 || pai->ai_state == 10)
1081 strcpy(hrec, "rebuild");
1083 strcpy(hrec, "error");
1084 if (pai->ai_ext_state & 0x10)
1085 strcat(hrec, "/expand");
1086 else if (pai->ai_ext_state & 0x1)
1087 strcat(hrec, "/patch");
1088 size = sprintf(buffer+len,
1089 "\n Number: \t%-2d \tStatus: \t%s\n",
1091 len += size; pos = begin + len;
1094 if (pai->ai_type == 0)
1095 strcpy(hrec, "RAID-0");
1096 else if (pai->ai_type == 4)
1097 strcpy(hrec, "RAID-4");
1098 else if (pai->ai_type == 5)
1099 strcpy(hrec, "RAID-5");
1101 strcpy(hrec, "RAID-10");
1102 size = sprintf(buffer+len,
1103 " Capacity [MB]:\t%-6d \tType: \t%s\n",
1104 pai->ai_size/(1024*1024/pai->ai_secsize),
1106 len += size; pos = begin + len;
1111 if (pos > offset + length)
1115 gdth_ioctl_free(hanum, buf);
1118 size = sprintf(buffer+len, "\n --\n");
1119 len += size; pos = begin + len;
1122 /* 5. about host drives */
1123 size = sprintf(buffer+len,"\nHost Drives:");
1124 len += size; pos = begin + len;
1127 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE);
1130 for (i = 0; i < MAX_LDRIVES; ++i) {
1131 if (!ha->hdr[i].is_logdrv ||
1132 (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
1134 /* 5.a get host drive list */
1135 TRACE2(("host_get() drv_no %d\n",i));
1136 phg = (gdth_hget_str *)buf;
1137 gdtcmd.Service = CACHESERVICE;
1138 gdtcmd.OpCode = GDT_IOCTL;
1139 gdtcmd.u.ioctl.p_param = virt_to_bus(phg);
1140 gdtcmd.u.ioctl.param_size = sizeof(gdth_hget_str);
1141 gdtcmd.u.ioctl.subfunc = HOST_GET | LA_CTRL_PATTERN;
1142 gdtcmd.u.ioctl.channel = i;
1143 phg->entries = MAX_HDRIVES;
1144 phg->offset = GDTOFFSOF(gdth_hget_str, entry[0]);
1145 #if LINUX_VERSION_CODE >= 0x020322
1146 gdth_do_cmd(scp, &gdtcmd, cmnd, 30);
1147 if (scp->SCp.Status != S_OK)
1149 gdth_do_cmd(&scp, &gdtcmd, cmnd, 30);
1150 if (scp.SCp.Status != S_OK)
1153 ha->hdr[i].ldr_no = i;
1154 ha->hdr[i].rw_attribs = 0;
1155 ha->hdr[i].start_sec = 0;
1157 for (j = 0; j < phg->entries; ++j) {
1158 k = phg->entry[j].host_drive;
1159 if (k >= MAX_LDRIVES)
1161 ha->hdr[k].ldr_no = phg->entry[j].log_drive;
1162 ha->hdr[k].rw_attribs = phg->entry[j].rw_attribs;
1163 ha->hdr[k].start_sec = phg->entry[j].start_sec;
1167 gdth_ioctl_free(hanum, buf);
1169 for (i = 0; i < MAX_HDRIVES; ++i) {
1170 if (!(ha->hdr[i].present))
1173 size = sprintf(buffer+len,
1174 "\n Number: \t%-2d \tArr/Log. Drive:\t%d\n",
1175 i, ha->hdr[i].ldr_no);
1176 len += size; pos = begin + len;
1179 size = sprintf(buffer+len,
1180 " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n",
1181 ha->hdr[i].size/2048, ha->hdr[i].start_sec);
1182 len += size; pos = begin + len;
1187 if (pos > offset + length)
1192 size = sprintf(buffer+len, "\n --\n");
1193 len += size; pos = begin + len;
1197 /* controller events */
1198 size = sprintf(buffer+len,"\nController Events:\n");
1199 len += size; pos = begin + len;
1202 id = gdth_read_event(ha, id, &estr);
1203 if (estr.event_source == 0)
1205 if (estr.event_data.eu.driver.ionode == hanum &&
1206 estr.event_source == ES_ASYNC) {
1207 gdth_log_event(&estr.event_data, hrec);
1208 do_gettimeofday(&tv);
1209 sec = (int)(tv.tv_sec - estr.first_stamp);
1210 if (sec < 0) sec = 0;
1211 size = sprintf(buffer+len," date- %02d:%02d:%02d\t%s\n",
1212 sec/3600, sec%3600/60, sec%60, hrec);
1213 len += size; pos = begin + len;
1218 if (pos > offset + length)
1225 /* request from tool (GDTMON,..) */
1226 piord = (gdth_iord_str *)ha->pscratch;
1229 length = piord->size;
1230 memcpy(buffer+len, (char *)piord, length);
1231 gdth_ioctl_free(hanum, ha->pscratch);
1236 #if LINUX_VERSION_CODE >= 0x020322
1237 scsi_release_command(scp);
1238 scsi_free_host_dev(sdev);
1240 *start = buffer +(offset-begin);
1241 len -= (offset-begin);
1244 TRACE2(("get_info() len %d pos %d begin %d offset %d length %d size %d\n",
1245 len,(int)pos,(int)begin,(int)offset,length,size));
1249 static void gdth_do_cmd(Scsi_Cmnd *scp, gdth_cmd_str *gdtcmd,
1250 char *cmnd, int timeout)
1253 #if LINUX_VERSION_CODE >= 0x020407
1254 DECLARE_COMPLETION(wait);
1255 #elif LINUX_VERSION_CODE >= 0x020322
1256 DECLARE_MUTEX_LOCKED(sem);
1258 struct semaphore sem = MUTEX_LOCKED;
1261 TRACE2(("gdth_do_cmd()\n"));
1262 if (gdtcmd != NULL) {
1263 scp->SCp.this_residual = IOCTL_PRI;
1264 bufflen = sizeof(gdth_cmd_str);
1266 scp->SCp.this_residual = DEFAULT_PRI;
1269 scp->request.rq_status = RQ_SCSI_BUSY;
1270 #if LINUX_VERSION_CODE >= 0x020407
1271 scp->request.waiting = &wait;
1272 scsi_do_cmd(scp, cmnd, gdtcmd, bufflen, gdth_scsi_done, timeout*HZ, 1);
1273 wait_for_completion(&wait);
1275 scp->request.sem = &sem;
1276 #if LINUX_VERSION_CODE >= 0x020322
1277 scsi_do_cmd(scp, cmnd, gdtcmd, bufflen, gdth_scsi_done, timeout*HZ, 1);
1279 GDTH_LOCK_SCSI_DOCMD();
1280 scsi_do_cmd(scp, cmnd, gdtcmd, bufflen, gdth_scsi_done, timeout*HZ, 1);
1281 GDTH_UNLOCK_SCSI_DOCMD();
1287 void gdth_scsi_done(Scsi_Cmnd *scp)
1289 TRACE2(("gdth_scsi_done()\n"));
1291 scp->request.rq_status = RQ_SCSI_DONE;
1293 #if LINUX_VERSION_CODE >= 0x020407
1294 if (scp->request.waiting != NULL)
1295 complete(scp->request.waiting);
1297 if (scp->request.sem != NULL)
1298 up(scp->request.sem);
1302 static char *gdth_ioctl_alloc(int hanum, ushort size, int scratch)
1308 if (size == 0 || size > GDTH_SCRATCH)
1311 ha = HADATA(gdth_ctr_tab[hanum]);
1312 GDTH_LOCK_HA(ha, flags);
1315 if (!ha->scratch_busy) {
1316 ha->scratch_busy = TRUE;
1317 ret_val = ha->pscratch;
1321 #if LINUX_VERSION_CODE >= 0x020322
1322 ret_val = (void *) __get_free_pages(GFP_ATOMIC | GFP_DMA,
1325 ret_val = scsi_init_malloc(GDTH_SCRATCH, GFP_ATOMIC | GFP_DMA);
1329 GDTH_UNLOCK_HA(ha, flags);
1333 static void gdth_ioctl_free(int hanum, char *buf)
1338 ha = HADATA(gdth_ctr_tab[hanum]);
1339 GDTH_LOCK_HA(ha, flags);
1341 if (buf == ha->pscratch) {
1342 ha->scratch_busy = FALSE;
1344 #if LINUX_VERSION_CODE >= 0x020322
1345 free_pages((unsigned long)buf, GDTH_SCRATCH_ORD);
1347 scsi_init_free((void *)buf, GDTH_SCRATCH);
1351 GDTH_UNLOCK_HA(ha, flags);
1354 static int gdth_ioctl_check_bin(int hanum, ushort size)
1360 ha = HADATA(gdth_ctr_tab[hanum]);
1361 GDTH_LOCK_HA(ha, flags);
1364 if (ha->scratch_busy) {
1365 if (((gdth_iord_str *)ha->pscratch)->size == (ulong32)size)
1368 GDTH_UNLOCK_HA(ha, flags);
1373 static void gdth_wait_completion(int hanum, int busnum, int id)
1381 ha = HADATA(gdth_ctr_tab[hanum]);
1382 GDTH_LOCK_HA(ha, flags);
1384 for (i = 0; i < GDTH_MAXCMDS; ++i) {
1385 scp = ha->cmd_tab[i].cmnd;
1386 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
1387 if (!SPECIAL_SCP(scp) && scp->target == (unchar)id &&
1388 b == (unchar)busnum) {
1389 scp->SCp.have_data_in = 0;
1390 GDTH_UNLOCK_HA(ha, flags);
1391 while (!scp->SCp.have_data_in)
1393 GDTH_LOCK_SCSI_DONE(flags);
1394 scp->scsi_done(scp);
1395 GDTH_UNLOCK_SCSI_DONE(flags);
1396 GDTH_LOCK_HA(ha, flags);
1399 GDTH_UNLOCK_HA(ha, flags);
1402 static void gdth_stop_timeout(int hanum, int busnum, int id)
1409 ha = HADATA(gdth_ctr_tab[hanum]);
1410 GDTH_LOCK_HA(ha, flags);
1412 for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {
1413 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
1414 if (scp->target == (unchar)id && b == (unchar)busnum) {
1415 TRACE2(("gdth_stop_timeout(): update_timeout()\n"));
1416 scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
1419 GDTH_UNLOCK_HA(ha, flags);
1422 static void gdth_start_timeout(int hanum, int busnum, int id)
1429 ha = HADATA(gdth_ctr_tab[hanum]);
1430 GDTH_LOCK_HA(ha, flags);
1432 for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {
1433 b = virt_ctr ? NUMDATA(scp->host)->busnum : scp->channel;
1434 if (scp->target == (unchar)id && b == (unchar)busnum) {
1435 TRACE2(("gdth_start_timeout(): update_timeout()\n"));
1436 gdth_update_timeout(hanum, scp, scp->SCp.buffers_residual);
1439 GDTH_UNLOCK_HA(ha, flags);
1442 static int gdth_update_timeout(int hanum, Scsi_Cmnd *scp, int timeout)
1446 oldto = scp->timeout_per_command;
1447 scp->timeout_per_command = timeout;
1449 #if LINUX_VERSION_CODE >= 0x02014B
1451 del_timer(&scp->eh_timeout);
1452 scp->eh_timeout.data = (unsigned long) NULL;
1453 scp->eh_timeout.expires = 0;
1455 if (scp->eh_timeout.data != (unsigned long) NULL)
1456 del_timer(&scp->eh_timeout);
1457 scp->eh_timeout.data = (unsigned long) scp;
1458 scp->eh_timeout.expires = jiffies + timeout;
1459 add_timer(&scp->eh_timeout);
1463 if (timer_table[SCSI_TIMER].expires == 0) {
1464 timer_table[SCSI_TIMER].expires = jiffies + timeout;
1465 timer_active |= 1 << SCSI_TIMER;
1467 if (time_before(jiffies + timeout < timer_table[SCSI_TIMER].expires))
1468 timer_table[SCSI_TIMER].expires = jiffies + timeout;