]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/scsi/gdth_proc.c
[SCSI] gdth: Remove virt hosts
[mirror_ubuntu-artful-kernel.git] / drivers / scsi / gdth_proc.c
1 /* gdth_proc.c
2 * $Id: gdth_proc.c,v 1.43 2006/01/11 16:15:00 achim Exp $
3 */
4
5 #include <linux/completion.h>
6
7 int gdth_proc_info(struct Scsi_Host *host, char *buffer,char **start,off_t offset,int length,
8 int inout)
9 {
10 int hanum;
11
12 TRACE2(("gdth_proc_info() length %d offs %d inout %d\n",
13 length,(int)offset,inout));
14
15 hanum = NUMDATA(host)->hanum;
16
17 if (inout)
18 return(gdth_set_info(buffer,length,host,hanum));
19 else
20 return(gdth_get_info(buffer,start,offset,length,host,hanum));
21 }
22
23 static int gdth_set_info(char *buffer,int length,struct Scsi_Host *host,
24 int hanum)
25 {
26 int ret_val = -EINVAL;
27
28 TRACE2(("gdth_set_info() ha %d\n",hanum,));
29
30 if (length >= 4) {
31 if (strncmp(buffer,"gdth",4) == 0) {
32 buffer += 5;
33 length -= 5;
34 ret_val = gdth_set_asc_info(host, buffer, length, hanum);
35 }
36 }
37
38 return ret_val;
39 }
40
41 static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
42 int length,int hanum)
43 {
44 int orig_length, drive, wb_mode;
45 int i, found;
46 gdth_ha_str *ha;
47 gdth_cmd_str gdtcmd;
48 gdth_cpar_str *pcpar;
49 ulong64 paddr;
50
51 char cmnd[MAX_COMMAND_SIZE];
52 memset(cmnd, 0xff, 12);
53 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
54
55 TRACE2(("gdth_set_asc_info() ha %d\n",hanum));
56 ha = HADATA(gdth_ctr_tab[hanum]);
57 orig_length = length + 5;
58 drive = -1;
59 wb_mode = 0;
60 found = FALSE;
61
62 if (length >= 5 && strncmp(buffer,"flush",5)==0) {
63 buffer += 6;
64 length -= 6;
65 if (length && *buffer>='0' && *buffer<='9') {
66 drive = (int)(*buffer-'0');
67 ++buffer; --length;
68 if (length && *buffer>='0' && *buffer<='9') {
69 drive = drive*10 + (int)(*buffer-'0');
70 ++buffer; --length;
71 }
72 printk("GDT: Flushing host drive %d .. ",drive);
73 } else {
74 printk("GDT: Flushing all host drives .. ");
75 }
76 for (i = 0; i < MAX_HDRIVES; ++i) {
77 if (ha->hdr[i].present) {
78 if (drive != -1 && i != drive)
79 continue;
80 found = TRUE;
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;
86 } else {
87 gdtcmd.u.cache.DeviceNo = i;
88 gdtcmd.u.cache.BlockNo = 1;
89 }
90
91 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
92 }
93 }
94 if (!found)
95 printk("\nNo host drive found !\n");
96 else
97 printk("Done.\n");
98 return(orig_length);
99 }
100
101 if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {
102 buffer += 8;
103 length -= 8;
104 printk("GDT: Disabling write back permanently .. ");
105 wb_mode = 1;
106 } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {
107 buffer += 7;
108 length -= 7;
109 printk("GDT: Enabling write back permanently .. ");
110 wb_mode = 2;
111 } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {
112 buffer += 7;
113 length -= 7;
114 printk("GDT: Disabling write back commands .. ");
115 if (ha->cache_feat & GDT_WR_THROUGH) {
116 gdth_write_through = TRUE;
117 printk("Done.\n");
118 } else {
119 printk("Not supported !\n");
120 }
121 return(orig_length);
122 } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {
123 buffer += 6;
124 length -= 6;
125 printk("GDT: Enabling write back commands .. ");
126 gdth_write_through = FALSE;
127 printk("Done.\n");
128 return(orig_length);
129 }
130
131 if (wb_mode) {
132 if (!gdth_ioctl_alloc(hanum, sizeof(gdth_cpar_str), TRUE, &paddr))
133 return(-EBUSY);
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;
143
144 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
145
146 gdth_ioctl_free(hanum, GDTH_SCRATCH, ha->pscratch, paddr);
147 printk("Done.\n");
148 return(orig_length);
149 }
150
151 printk("GDT: Unknown command: %s Length: %d\n",buffer,length);
152 return(-EINVAL);
153 }
154
155 static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
156 struct Scsi_Host *host,int hanum)
157 {
158 int size = 0,len = 0;
159 off_t begin = 0,pos = 0;
160 gdth_ha_str *ha;
161 int id, i, j, k, sec, flag;
162 int no_mdrv = 0, drv_no, is_mirr;
163 ulong32 cnt;
164 ulong64 paddr;
165 int rc = -ENOMEM;
166
167 gdth_cmd_str *gdtcmd;
168 gdth_evt_str *estr;
169 char hrec[161];
170 struct timeval tv;
171
172 char *buf;
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;
178 gdth_hget_str *phg;
179 char cmnd[MAX_COMMAND_SIZE];
180
181 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
182 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
183 if (!gdtcmd || !estr)
184 goto free_fail;
185
186 memset(cmnd, 0xff, 12);
187 memset(gdtcmd, 0, sizeof(gdth_cmd_str));
188
189 TRACE2(("gdth_get_info() ha %d\n",hanum));
190 ha = HADATA(gdth_ctr_tab[hanum]);
191
192
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)
199 strcpy(hrec, "--");
200 else {
201 sprintf(hrec, "%d", reserve_list[0]);
202 for (i = 1; i < MAX_RES_ARGS; i++) {
203 if (reserve_list[i] == 0xff)
204 break;
205 sprintf(hrec,"%s,%d", hrec, reserve_list[i]);
206 }
207 }
208 size = sprintf(buffer+len,
209 " reserve_mode: \t%d \treserve_list: \t%s\n",
210 reserve_mode, hrec);
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;
216
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",
223 hanum, hrec);
224 len += size; pos = begin + len;
225
226 if (ha->more_proc)
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);
233 else
234 sprintf(hrec, "%d.%02d", (unchar)(ha->cpar.version>>8),
235 (unchar)(ha->cpar.version));
236
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;
241
242 if (ha->more_proc) {
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;
248 }
249
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;
258 #endif
259
260 if (pos < offset) {
261 len = 0;
262 begin = pos;
263 }
264 if (pos > offset + length)
265 goto stop_output;
266
267 if (ha->more_proc) {
268 /* more information: 2. about physical devices */
269 size = sprintf(buffer+len,"\nPhysical Devices:");
270 len += size; pos = begin + len;
271 flag = FALSE;
272
273 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE, &paddr);
274 if (!buf)
275 goto stop_output;
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;
287 pds->first = 0;
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)
292 pds->entries = cnt;
293
294 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
295 pds->count = 0;
296
297 /* other IOCTLs must fit into area GDTH_SCRATCH/4 */
298 for (j = 0; j < ha->raw[i].pdev_cnt; ++j) {
299 /* 2.b drive info */
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];
310
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);
315 hrec[28] = 0;
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;
320 flag = TRUE;
321 pdi->no_ldrive &= 0xffff;
322 if (pdi->no_ldrive == 0xffff)
323 strcpy(hrec,"--");
324 else
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),
329 hrec);
330 len += size; pos = begin + len;
331 } else {
332 pdi->devtype = 0xff;
333 }
334
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;
345 break;
346 }
347 }
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;
360
361 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
362 size = sprintf(buffer+len,
363 " Grown Defects:\t%d\n",
364 pdef->sddc_cnt);
365 len += size; pos = begin + len;
366 }
367 }
368 if (pos < offset) {
369 len = 0;
370 begin = pos;
371 }
372 if (pos > offset + length)
373 goto stop_output;
374 }
375 }
376 gdth_ioctl_free(hanum, GDTH_SCRATCH, buf, paddr);
377
378 if (!flag) {
379 size = sprintf(buffer+len, "\n --\n");
380 len += size; pos = begin + len;
381 }
382
383 /* 3. about logical drives */
384 size = sprintf(buffer+len,"\nLogical Drives:");
385 len += size; pos = begin + len;
386 flag = FALSE;
387
388 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE, &paddr);
389 if (!buf)
390 goto stop_output;
391 for (i = 0; i < MAX_LDRIVES; ++i) {
392 if (!ha->hdr[i].is_logdrv)
393 continue;
394 drv_no = i;
395 j = k = 0;
396 is_mirr = FALSE;
397 do {
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)
408 break;
409 pcdi->ld_dtype >>= 16;
410 j++;
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");
417 k++; j--;
418 } else {
419 strcpy(hrec, "ok");
420 }
421
422 if (drv_no == i) {
423 size = sprintf(buffer+len,
424 "\n Number: \t%-2d \tStatus: \t%s\n",
425 drv_no, hrec);
426 len += size; pos = begin + len;
427 flag = TRUE;
428 no_mdrv = pcdi->cd_ldcnt;
429 if (no_mdrv > 1 || pcdi->ld_slave != -1) {
430 is_mirr = TRUE;
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");
438 } else {
439 strcpy(hrec, "???");
440 }
441 size = sprintf(buffer+len,
442 " Capacity [MB]:\t%-6d \tType: \t%s\n",
443 pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize),
444 hrec);
445 len += size; pos = begin + len;
446 } else {
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;
451 }
452 drv_no = pcdi->ld_slave;
453 if (pos < offset) {
454 len = 0;
455 begin = pos;
456 }
457 if (pos > offset + length)
458 goto stop_output;
459 } while (drv_no != -1);
460
461 if (is_mirr) {
462 size = sprintf(buffer+len,
463 " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n",
464 no_mdrv - j - k, k);
465 len += size; pos = begin + len;
466 }
467
468 if (!ha->hdr[i].is_arraydrv)
469 strcpy(hrec, "--");
470 else
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;
475 if (pos < offset) {
476 len = 0;
477 begin = pos;
478 }
479 if (pos > offset + length)
480 goto stop_output;
481 }
482 gdth_ioctl_free(hanum, GDTH_SCRATCH, buf, paddr);
483
484 if (!flag) {
485 size = sprintf(buffer+len, "\n --\n");
486 len += size; pos = begin + len;
487 }
488
489 /* 4. about array drives */
490 size = sprintf(buffer+len,"\nArray Drives:");
491 len += size; pos = begin + len;
492 flag = FALSE;
493
494 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE, &paddr);
495 if (!buf)
496 goto stop_output;
497 for (i = 0; i < MAX_LDRIVES; ++i) {
498 if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
499 continue;
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");
520 else
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",
528 i,hrec);
529 len += size; pos = begin + len;
530 flag = TRUE;
531
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");
538 else
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),
543 hrec);
544 len += size; pos = begin + len;
545 if (pos < offset) {
546 len = 0;
547 begin = pos;
548 }
549 if (pos > offset + length)
550 goto stop_output;
551 }
552 }
553 gdth_ioctl_free(hanum, GDTH_SCRATCH, buf, paddr);
554
555 if (!flag) {
556 size = sprintf(buffer+len, "\n --\n");
557 len += size; pos = begin + len;
558 }
559
560 /* 5. about host drives */
561 size = sprintf(buffer+len,"\nHost Drives:");
562 len += size; pos = begin + len;
563 flag = FALSE;
564
565 buf = gdth_ioctl_alloc(hanum, sizeof(gdth_hget_str), FALSE, &paddr);
566 if (!buf)
567 goto stop_output;
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))
571 continue;
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;
587 } else {
588 for (j = 0; j < phg->entries; ++j) {
589 k = phg->entry[j].host_drive;
590 if (k >= MAX_LDRIVES)
591 continue;
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;
595 }
596 }
597 }
598 gdth_ioctl_free(hanum, sizeof(gdth_hget_str), buf, paddr);
599
600 for (i = 0; i < MAX_HDRIVES; ++i) {
601 if (!(ha->hdr[i].present))
602 continue;
603
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;
608 flag = TRUE;
609
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;
614 if (pos < offset) {
615 len = 0;
616 begin = pos;
617 }
618 if (pos > offset + length)
619 goto stop_output;
620 }
621
622 if (!flag) {
623 size = sprintf(buffer+len, "\n --\n");
624 len += size; pos = begin + len;
625 }
626 }
627
628 /* controller events */
629 size = sprintf(buffer+len,"\nController Events:\n");
630 len += size; pos = begin + len;
631
632 for (id = -1;;) {
633 id = gdth_read_event(ha, id, estr);
634 if (estr->event_source == 0)
635 break;
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;
645 if (pos < offset) {
646 len = 0;
647 begin = pos;
648 }
649 if (pos > offset + length)
650 goto stop_output;
651 }
652 if (id == -1)
653 break;
654 }
655
656 stop_output:
657 *start = buffer +(offset-begin);
658 len -= (offset-begin);
659 if (len > length)
660 len = length;
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));
663 rc = len;
664
665 free_fail:
666 kfree(gdtcmd);
667 kfree(estr);
668 return rc;
669 }
670
671 static char *gdth_ioctl_alloc(int hanum, int size, int scratch,
672 ulong64 *paddr)
673 {
674 gdth_ha_str *ha;
675 ulong flags;
676 char *ret_val;
677
678 if (size == 0)
679 return NULL;
680
681 ha = HADATA(gdth_ctr_tab[hanum]);
682 spin_lock_irqsave(&ha->smp_lock, flags);
683
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) {
689 ret_val = NULL;
690 } else {
691 dma_addr_t dma_addr;
692
693 ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
694 *paddr = dma_addr;
695 }
696
697 spin_unlock_irqrestore(&ha->smp_lock, flags);
698 return ret_val;
699 }
700
701 static void gdth_ioctl_free(int hanum, int size, char *buf, ulong64 paddr)
702 {
703 gdth_ha_str *ha;
704 ulong flags;
705
706 ha = HADATA(gdth_ctr_tab[hanum]);
707 spin_lock_irqsave(&ha->smp_lock, flags);
708
709 if (buf == ha->pscratch) {
710 ha->scratch_busy = FALSE;
711 } else {
712 pci_free_consistent(ha->pdev, size, buf, paddr);
713 }
714
715 spin_unlock_irqrestore(&ha->smp_lock, flags);
716 }
717
718 #ifdef GDTH_IOCTL_PROC
719 static int gdth_ioctl_check_bin(int hanum, ushort size)
720 {
721 gdth_ha_str *ha;
722 ulong flags;
723 int ret_val;
724
725 ha = HADATA(gdth_ctr_tab[hanum]);
726 spin_lock_irqsave(&ha->smp_lock, flags);
727
728 ret_val = FALSE;
729 if (ha->scratch_busy) {
730 if (((gdth_iord_str *)ha->pscratch)->size == (ulong32)size)
731 ret_val = TRUE;
732 }
733 spin_unlock_irqrestore(&ha->smp_lock, flags);
734 return ret_val;
735 }
736 #endif
737
738 static void gdth_wait_completion(int hanum, int busnum, int id)
739 {
740 gdth_ha_str *ha;
741 ulong flags;
742 int i;
743 Scsi_Cmnd *scp;
744 unchar b, t;
745
746 ha = HADATA(gdth_ctr_tab[hanum]);
747 spin_lock_irqsave(&ha->smp_lock, flags);
748
749 for (i = 0; i < GDTH_MAXCMDS; ++i) {
750 scp = ha->cmd_tab[i].cmnd;
751
752 b = scp->device->channel;
753 t = scp->device->id;
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)
759 barrier();
760 spin_lock_irqsave(&ha->smp_lock, flags);
761 }
762 }
763 spin_unlock_irqrestore(&ha->smp_lock, flags);
764 }
765
766 static void gdth_stop_timeout(int hanum, int busnum, int id)
767 {
768 gdth_ha_str *ha;
769 ulong flags;
770 Scsi_Cmnd *scp;
771 unchar b, t;
772
773 ha = HADATA(gdth_ctr_tab[hanum]);
774 spin_lock_irqsave(&ha->smp_lock, flags);
775
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;
779 t = scp->device->id;
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);
783 }
784 }
785 }
786 spin_unlock_irqrestore(&ha->smp_lock, flags);
787 }
788
789 static void gdth_start_timeout(int hanum, int busnum, int id)
790 {
791 gdth_ha_str *ha;
792 ulong flags;
793 Scsi_Cmnd *scp;
794 unchar b, t;
795
796 ha = HADATA(gdth_ctr_tab[hanum]);
797 spin_lock_irqsave(&ha->smp_lock, flags);
798
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;
802 t = scp->device->id;
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);
806 }
807 }
808 }
809 spin_unlock_irqrestore(&ha->smp_lock, flags);
810 }
811
812 static int gdth_update_timeout(int hanum, Scsi_Cmnd *scp, int timeout)
813 {
814 int oldto;
815
816 oldto = scp->timeout_per_command;
817 scp->timeout_per_command = timeout;
818
819 if (timeout == 0) {
820 del_timer(&scp->eh_timeout);
821 scp->eh_timeout.data = (unsigned long) NULL;
822 scp->eh_timeout.expires = 0;
823 } else {
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);
829 }
830
831 return oldto;
832 }