[SCSI] gdth: Reorder scsi_host_template intitializers
[deliverable/linux.git] / drivers / scsi / gdth_proc.c
CommitLineData
1da177e4 1/* gdth_proc.c
cbd5f69b 2 * $Id: gdth_proc.c,v 1.43 2006/01/11 16:15:00 achim Exp $
1da177e4
LT
3 */
4
5#include <linux/completion.h>
6
1da177e4
LT
7int gdth_proc_info(struct Scsi_Host *host, char *buffer,char **start,off_t offset,int length,
8 int inout)
9{
10 int hanum,busnum;
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 busnum= NUMDATA(host)->busnum;
17
18 if (inout)
19 return(gdth_set_info(buffer,length,host,hanum,busnum));
20 else
21 return(gdth_get_info(buffer,start,offset,length,host,hanum,busnum));
22}
1da177e4
LT
23
24static int gdth_set_info(char *buffer,int length,struct Scsi_Host *host,
25 int hanum,int busnum)
26{
cbd5f69b 27 int ret_val = -EINVAL;
1da177e4 28
cbd5f69b 29 TRACE2(("gdth_set_info() ha %d bus %d\n",hanum,busnum));
1da177e4
LT
30
31 if (length >= 4) {
32 if (strncmp(buffer,"gdth",4) == 0) {
33 buffer += 5;
34 length -= 5;
cbd5f69b 35 ret_val = gdth_set_asc_info(host, buffer, length, hanum);
1da177e4
LT
36 }
37 }
cbd5f69b 38
1da177e4
LT
39 return ret_val;
40}
41
cbd5f69b
LA
42static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
43 int length,int hanum)
1da177e4 44{
cbd5f69b
LA
45 int orig_length, drive, wb_mode;
46 int i, found;
1da177e4
LT
47 gdth_ha_str *ha;
48 gdth_cmd_str gdtcmd;
49 gdth_cpar_str *pcpar;
50 ulong64 paddr;
51
52 char cmnd[MAX_COMMAND_SIZE];
53 memset(cmnd, 0xff, 12);
54 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
55
56 TRACE2(("gdth_set_asc_info() ha %d\n",hanum));
57 ha = HADATA(gdth_ctr_tab[hanum]);
58 orig_length = length + 5;
59 drive = -1;
60 wb_mode = 0;
61 found = FALSE;
62
63 if (length >= 5 && strncmp(buffer,"flush",5)==0) {
64 buffer += 6;
65 length -= 6;
66 if (length && *buffer>='0' && *buffer<='9') {
67 drive = (int)(*buffer-'0');
68 ++buffer; --length;
69 if (length && *buffer>='0' && *buffer<='9') {
70 drive = drive*10 + (int)(*buffer-'0');
71 ++buffer; --length;
72 }
73 printk("GDT: Flushing host drive %d .. ",drive);
74 } else {
75 printk("GDT: Flushing all host drives .. ");
76 }
77 for (i = 0; i < MAX_HDRIVES; ++i) {
78 if (ha->hdr[i].present) {
79 if (drive != -1 && i != drive)
80 continue;
81 found = TRUE;
82 gdtcmd.Service = CACHESERVICE;
83 gdtcmd.OpCode = GDT_FLUSH;
84 if (ha->cache_feat & GDT_64BIT) {
85 gdtcmd.u.cache64.DeviceNo = i;
86 gdtcmd.u.cache64.BlockNo = 1;
87 } else {
88 gdtcmd.u.cache.DeviceNo = i;
89 gdtcmd.u.cache.BlockNo = 1;
90 }
cbd5f69b
LA
91
92 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
1da177e4
LT
93 }
94 }
95 if (!found)
96 printk("\nNo host drive found !\n");
97 else
98 printk("Done.\n");
99 return(orig_length);
100 }
101
102 if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {
103 buffer += 8;
104 length -= 8;
105 printk("GDT: Disabling write back permanently .. ");
106 wb_mode = 1;
107 } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {
108 buffer += 7;
109 length -= 7;
110 printk("GDT: Enabling write back permanently .. ");
111 wb_mode = 2;
112 } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {
113 buffer += 7;
114 length -= 7;
115 printk("GDT: Disabling write back commands .. ");
116 if (ha->cache_feat & GDT_WR_THROUGH) {
117 gdth_write_through = TRUE;
118 printk("Done.\n");
119 } else {
120 printk("Not supported !\n");
121 }
122 return(orig_length);
123 } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {
124 buffer += 6;
125 length -= 6;
126 printk("GDT: Enabling write back commands .. ");
127 gdth_write_through = FALSE;
128 printk("Done.\n");
129 return(orig_length);
130 }
131
132 if (wb_mode) {
133 if (!gdth_ioctl_alloc(hanum, sizeof(gdth_cpar_str), TRUE, &paddr))
134 return(-EBUSY);
135 pcpar = (gdth_cpar_str *)ha->pscratch;
136 memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );
137 gdtcmd.Service = CACHESERVICE;
138 gdtcmd.OpCode = GDT_IOCTL;
139 gdtcmd.u.ioctl.p_param = paddr;
140 gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
141 gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
142 gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
143 pcpar->write_back = wb_mode==1 ? 0:1;
cbd5f69b
LA
144
145 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
146
1da177e4
LT
147 gdth_ioctl_free(hanum, GDTH_SCRATCH, ha->pscratch, paddr);
148 printk("Done.\n");
149 return(orig_length);
150 }
151
152 printk("GDT: Unknown command: %s Length: %d\n",buffer,length);
153 return(-EINVAL);
154}
155
156static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
157 struct Scsi_Host *host,int hanum,int busnum)
158{
159 int size = 0,len = 0;
160 off_t begin = 0,pos = 0;
161 gdth_ha_str *ha;
162 int id, i, j, k, sec, flag;
163 int no_mdrv = 0, drv_no, is_mirr;
164 ulong32 cnt;
165 ulong64 paddr;
166 int rc = -ENOMEM;
167
168 gdth_cmd_str *gdtcmd;
169 gdth_evt_str *estr;
1da177e4
LT
170 char hrec[161];
171 struct timeval tv;
172
173 char *buf;
174 gdth_dskstat_str *pds;
175 gdth_diskinfo_str *pdi;
176 gdth_arrayinf_str *pai;
177 gdth_defcnt_str *pdef;
178 gdth_cdrinfo_str *pcdi;
179 gdth_hget_str *phg;
180 char cmnd[MAX_COMMAND_SIZE];
181
182 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
183 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
184 if (!gdtcmd || !estr)
cbd5f69b 185 goto free_fail;
1da177e4
LT
186
187 memset(cmnd, 0xff, 12);
188 memset(gdtcmd, 0, sizeof(gdth_cmd_str));
189
190 TRACE2(("gdth_get_info() ha %d bus %d\n",hanum,busnum));
191 ha = HADATA(gdth_ctr_tab[hanum]);
192
1da177e4
LT
193
194 /* request is i.e. "cat /proc/scsi/gdth/0" */
195 /* format: %-15s\t%-10s\t%-15s\t%s */
196 /* driver parameters */
197 size = sprintf(buffer+len,"Driver Parameters:\n");
198 len += size; pos = begin + len;
199 if (reserve_list[0] == 0xff)
200 strcpy(hrec, "--");
201 else {
202 sprintf(hrec, "%d", reserve_list[0]);
203 for (i = 1; i < MAX_RES_ARGS; i++) {
204 if (reserve_list[i] == 0xff)
205 break;
206 sprintf(hrec,"%s,%d", hrec, reserve_list[i]);
207 }
208 }
209 size = sprintf(buffer+len,
210 " reserve_mode: \t%d \treserve_list: \t%s\n",
211 reserve_mode, hrec);
212 len += size; pos = begin + len;
213 size = sprintf(buffer+len,
214 " max_ids: \t%-3d \thdr_channel: \t%d\n",
215 max_ids, hdr_channel);
216 len += size; pos = begin + len;
217
218 /* controller information */
219 size = sprintf(buffer+len,"\nDisk Array Controller Information:\n");
220 len += size; pos = begin + len;
221 if (virt_ctr)
222 sprintf(hrec, "%s (Bus %d)", ha->binfo.type_string, busnum);
223 else
224 strcpy(hrec, ha->binfo.type_string);
225 size = sprintf(buffer+len,
226 " Number: \t%d \tName: \t%s\n",
227 hanum, hrec);
228 len += size; pos = begin + len;
229
230 if (ha->more_proc)
231 sprintf(hrec, "%d.%02d.%02d-%c%03X",
232 (unchar)(ha->binfo.upd_fw_ver>>24),
233 (unchar)(ha->binfo.upd_fw_ver>>16),
234 (unchar)(ha->binfo.upd_fw_ver),
235 ha->bfeat.raid ? 'R':'N',
236 ha->binfo.upd_revision);
237 else
238 sprintf(hrec, "%d.%02d", (unchar)(ha->cpar.version>>8),
239 (unchar)(ha->cpar.version));
240
241 size = sprintf(buffer+len,
242 " Driver Ver.: \t%-10s\tFirmware Ver.: \t%s\n",
243 GDTH_VERSION_STR, hrec);
244 len += size; pos = begin + len;
245
246 if (ha->more_proc) {
247 /* more information: 1. about controller */
248 size = sprintf(buffer+len,
249 " Serial No.: \t0x%8X\tCache RAM size:\t%d KB\n",
250 ha->binfo.ser_no, ha->binfo.memsize / 1024);
251 len += size; pos = begin + len;
252 }
253
254#ifdef GDTH_DMA_STATISTICS
255 /* controller statistics */
256 size = sprintf(buffer+len,"\nController Statistics:\n");
257 len += size; pos = begin + len;
258 size = sprintf(buffer+len,
259 " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu\n",
260 ha->dma32_cnt, ha->dma64_cnt);
261 len += size; pos = begin + len;
262#endif
263
264 if (pos < offset) {
265 len = 0;
266 begin = pos;
267 }
268 if (pos > offset + length)
269 goto stop_output;
270
271 if (ha->more_proc) {
272 /* more information: 2. about physical devices */
273 size = sprintf(buffer+len,"\nPhysical Devices:");
274 len += size; pos = begin + len;
275 flag = FALSE;
276
277 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE, &paddr);
278 if (!buf)
279 goto stop_output;
280 for (i = 0; i < ha->bus_cnt; ++i) {
281 /* 2.a statistics (and retries/reassigns) */
282 TRACE2(("pdr_statistics() chn %d\n",i));
283 pds = (gdth_dskstat_str *)(buf + GDTH_SCRATCH/4);
284 gdtcmd->Service = CACHESERVICE;
285 gdtcmd->OpCode = GDT_IOCTL;
286 gdtcmd->u.ioctl.p_param = paddr + GDTH_SCRATCH/4;
287 gdtcmd->u.ioctl.param_size = 3*GDTH_SCRATCH/4;
288 gdtcmd->u.ioctl.subfunc = DSK_STATISTICS | L_CTRL_PATTERN;
289 gdtcmd->u.ioctl.channel = ha->raw[i].address | INVALID_CHANNEL;
290 pds->bid = ha->raw[i].local_no;
291 pds->first = 0;
292 pds->entries = ha->raw[i].pdev_cnt;
293 cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(ulong32)) /
294 sizeof(pds->list[0]);
295 if (pds->entries > cnt)
296 pds->entries = cnt;
cbd5f69b
LA
297
298 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
1da177e4 299 pds->count = 0;
1da177e4
LT
300
301 /* other IOCTLs must fit into area GDTH_SCRATCH/4 */
302 for (j = 0; j < ha->raw[i].pdev_cnt; ++j) {
303 /* 2.b drive info */
304 TRACE2(("scsi_drv_info() chn %d dev %d\n",
305 i, ha->raw[i].id_list[j]));
306 pdi = (gdth_diskinfo_str *)buf;
307 gdtcmd->Service = CACHESERVICE;
308 gdtcmd->OpCode = GDT_IOCTL;
309 gdtcmd->u.ioctl.p_param = paddr;
310 gdtcmd->u.ioctl.param_size = sizeof(gdth_diskinfo_str);
311 gdtcmd->u.ioctl.subfunc = SCSI_DR_INFO | L_CTRL_PATTERN;
312 gdtcmd->u.ioctl.channel =
313 ha->raw[i].address | ha->raw[i].id_list[j];
cbd5f69b
LA
314
315 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4
LT
316 strncpy(hrec,pdi->vendor,8);
317 strncpy(hrec+8,pdi->product,16);
318 strncpy(hrec+24,pdi->revision,4);
319 hrec[28] = 0;
320 size = sprintf(buffer+len,
321 "\n Chn/ID/LUN: \t%c/%02d/%d \tName: \t%s\n",
322 'A'+i,pdi->target_id,pdi->lun,hrec);
323 len += size; pos = begin + len;
324 flag = TRUE;
325 pdi->no_ldrive &= 0xffff;
326 if (pdi->no_ldrive == 0xffff)
327 strcpy(hrec,"--");
328 else
329 sprintf(hrec,"%d",pdi->no_ldrive);
330 size = sprintf(buffer+len,
331 " Capacity [MB]:\t%-6d \tTo Log. Drive: \t%s\n",
332 pdi->blkcnt/(1024*1024/pdi->blksize),
333 hrec);
334 len += size; pos = begin + len;
335 } else {
336 pdi->devtype = 0xff;
337 }
338
339 if (pdi->devtype == 0) {
340 /* search retries/reassigns */
341 for (k = 0; k < pds->count; ++k) {
342 if (pds->list[k].tid == pdi->target_id &&
343 pds->list[k].lun == pdi->lun) {
344 size = sprintf(buffer+len,
345 " Retries: \t%-6d \tReassigns: \t%d\n",
346 pds->list[k].retries,
347 pds->list[k].reassigns);
348 len += size; pos = begin + len;
349 break;
350 }
351 }
352 /* 2.c grown defects */
353 TRACE2(("scsi_drv_defcnt() chn %d dev %d\n",
354 i, ha->raw[i].id_list[j]));
355 pdef = (gdth_defcnt_str *)buf;
356 gdtcmd->Service = CACHESERVICE;
357 gdtcmd->OpCode = GDT_IOCTL;
358 gdtcmd->u.ioctl.p_param = paddr;
359 gdtcmd->u.ioctl.param_size = sizeof(gdth_defcnt_str);
360 gdtcmd->u.ioctl.subfunc = SCSI_DEF_CNT | L_CTRL_PATTERN;
361 gdtcmd->u.ioctl.channel =
362 ha->raw[i].address | ha->raw[i].id_list[j];
363 pdef->sddc_type = 0x08;
cbd5f69b
LA
364
365 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4
LT
366 size = sprintf(buffer+len,
367 " Grown Defects:\t%d\n",
368 pdef->sddc_cnt);
369 len += size; pos = begin + len;
370 }
371 }
372 if (pos < offset) {
373 len = 0;
374 begin = pos;
375 }
376 if (pos > offset + length)
377 goto stop_output;
378 }
379 }
380 gdth_ioctl_free(hanum, GDTH_SCRATCH, buf, paddr);
381
382 if (!flag) {
383 size = sprintf(buffer+len, "\n --\n");
384 len += size; pos = begin + len;
385 }
386
387 /* 3. about logical drives */
388 size = sprintf(buffer+len,"\nLogical Drives:");
389 len += size; pos = begin + len;
390 flag = FALSE;
391
392 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE, &paddr);
393 if (!buf)
394 goto stop_output;
395 for (i = 0; i < MAX_LDRIVES; ++i) {
396 if (!ha->hdr[i].is_logdrv)
397 continue;
398 drv_no = i;
399 j = k = 0;
400 is_mirr = FALSE;
401 do {
402 /* 3.a log. drive info */
403 TRACE2(("cache_drv_info() drive no %d\n",drv_no));
404 pcdi = (gdth_cdrinfo_str *)buf;
405 gdtcmd->Service = CACHESERVICE;
406 gdtcmd->OpCode = GDT_IOCTL;
407 gdtcmd->u.ioctl.p_param = paddr;
408 gdtcmd->u.ioctl.param_size = sizeof(gdth_cdrinfo_str);
409 gdtcmd->u.ioctl.subfunc = CACHE_DRV_INFO;
410 gdtcmd->u.ioctl.channel = drv_no;
cbd5f69b 411 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
1da177e4 412 break;
1da177e4
LT
413 pcdi->ld_dtype >>= 16;
414 j++;
415 if (pcdi->ld_dtype > 2) {
416 strcpy(hrec, "missing");
417 } else if (pcdi->ld_error & 1) {
418 strcpy(hrec, "fault");
419 } else if (pcdi->ld_error & 2) {
420 strcpy(hrec, "invalid");
421 k++; j--;
422 } else {
423 strcpy(hrec, "ok");
424 }
425
426 if (drv_no == i) {
427 size = sprintf(buffer+len,
428 "\n Number: \t%-2d \tStatus: \t%s\n",
429 drv_no, hrec);
430 len += size; pos = begin + len;
431 flag = TRUE;
432 no_mdrv = pcdi->cd_ldcnt;
433 if (no_mdrv > 1 || pcdi->ld_slave != -1) {
434 is_mirr = TRUE;
435 strcpy(hrec, "RAID-1");
436 } else if (pcdi->ld_dtype == 0) {
437 strcpy(hrec, "Disk");
438 } else if (pcdi->ld_dtype == 1) {
439 strcpy(hrec, "RAID-0");
440 } else if (pcdi->ld_dtype == 2) {
441 strcpy(hrec, "Chain");
442 } else {
443 strcpy(hrec, "???");
444 }
445 size = sprintf(buffer+len,
446 " Capacity [MB]:\t%-6d \tType: \t%s\n",
447 pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize),
448 hrec);
449 len += size; pos = begin + len;
450 } else {
451 size = sprintf(buffer+len,
452 " Slave Number: \t%-2d \tStatus: \t%s\n",
453 drv_no & 0x7fff, hrec);
454 len += size; pos = begin + len;
455 }
456 drv_no = pcdi->ld_slave;
457 if (pos < offset) {
458 len = 0;
459 begin = pos;
460 }
461 if (pos > offset + length)
462 goto stop_output;
463 } while (drv_no != -1);
464
465 if (is_mirr) {
466 size = sprintf(buffer+len,
467 " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n",
468 no_mdrv - j - k, k);
469 len += size; pos = begin + len;
470 }
471
472 if (!ha->hdr[i].is_arraydrv)
473 strcpy(hrec, "--");
474 else
475 sprintf(hrec, "%d", ha->hdr[i].master_no);
476 size = sprintf(buffer+len,
477 " To Array Drv.:\t%s\n", hrec);
478 len += size; pos = begin + len;
479 if (pos < offset) {
480 len = 0;
481 begin = pos;
482 }
483 if (pos > offset + length)
484 goto stop_output;
485 }
486 gdth_ioctl_free(hanum, GDTH_SCRATCH, buf, paddr);
487
488 if (!flag) {
489 size = sprintf(buffer+len, "\n --\n");
490 len += size; pos = begin + len;
491 }
492
493 /* 4. about array drives */
494 size = sprintf(buffer+len,"\nArray Drives:");
495 len += size; pos = begin + len;
496 flag = FALSE;
497
498 buf = gdth_ioctl_alloc(hanum, GDTH_SCRATCH, FALSE, &paddr);
499 if (!buf)
500 goto stop_output;
501 for (i = 0; i < MAX_LDRIVES; ++i) {
502 if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
503 continue;
504 /* 4.a array drive info */
505 TRACE2(("array_info() drive no %d\n",i));
506 pai = (gdth_arrayinf_str *)buf;
507 gdtcmd->Service = CACHESERVICE;
508 gdtcmd->OpCode = GDT_IOCTL;
509 gdtcmd->u.ioctl.p_param = paddr;
510 gdtcmd->u.ioctl.param_size = sizeof(gdth_arrayinf_str);
511 gdtcmd->u.ioctl.subfunc = ARRAY_INFO | LA_CTRL_PATTERN;
512 gdtcmd->u.ioctl.channel = i;
cbd5f69b 513 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4
LT
514 if (pai->ai_state == 0)
515 strcpy(hrec, "idle");
516 else if (pai->ai_state == 2)
517 strcpy(hrec, "build");
518 else if (pai->ai_state == 4)
519 strcpy(hrec, "ready");
520 else if (pai->ai_state == 6)
521 strcpy(hrec, "fail");
522 else if (pai->ai_state == 8 || pai->ai_state == 10)
523 strcpy(hrec, "rebuild");
524 else
525 strcpy(hrec, "error");
526 if (pai->ai_ext_state & 0x10)
527 strcat(hrec, "/expand");
528 else if (pai->ai_ext_state & 0x1)
529 strcat(hrec, "/patch");
530 size = sprintf(buffer+len,
531 "\n Number: \t%-2d \tStatus: \t%s\n",
532 i,hrec);
533 len += size; pos = begin + len;
534 flag = TRUE;
535
536 if (pai->ai_type == 0)
537 strcpy(hrec, "RAID-0");
538 else if (pai->ai_type == 4)
539 strcpy(hrec, "RAID-4");
540 else if (pai->ai_type == 5)
541 strcpy(hrec, "RAID-5");
542 else
543 strcpy(hrec, "RAID-10");
544 size = sprintf(buffer+len,
545 " Capacity [MB]:\t%-6d \tType: \t%s\n",
546 pai->ai_size/(1024*1024/pai->ai_secsize),
547 hrec);
548 len += size; pos = begin + len;
549 if (pos < offset) {
550 len = 0;
551 begin = pos;
552 }
553 if (pos > offset + length)
554 goto stop_output;
555 }
556 }
557 gdth_ioctl_free(hanum, GDTH_SCRATCH, buf, paddr);
558
559 if (!flag) {
560 size = sprintf(buffer+len, "\n --\n");
561 len += size; pos = begin + len;
562 }
563
564 /* 5. about host drives */
565 size = sprintf(buffer+len,"\nHost Drives:");
566 len += size; pos = begin + len;
567 flag = FALSE;
568
569 buf = gdth_ioctl_alloc(hanum, sizeof(gdth_hget_str), FALSE, &paddr);
570 if (!buf)
571 goto stop_output;
572 for (i = 0; i < MAX_LDRIVES; ++i) {
573 if (!ha->hdr[i].is_logdrv ||
574 (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
575 continue;
576 /* 5.a get host drive list */
577 TRACE2(("host_get() drv_no %d\n",i));
578 phg = (gdth_hget_str *)buf;
579 gdtcmd->Service = CACHESERVICE;
580 gdtcmd->OpCode = GDT_IOCTL;
581 gdtcmd->u.ioctl.p_param = paddr;
582 gdtcmd->u.ioctl.param_size = sizeof(gdth_hget_str);
583 gdtcmd->u.ioctl.subfunc = HOST_GET | LA_CTRL_PATTERN;
584 gdtcmd->u.ioctl.channel = i;
585 phg->entries = MAX_HDRIVES;
586 phg->offset = GDTOFFSOF(gdth_hget_str, entry[0]);
cbd5f69b 587 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4
LT
588 ha->hdr[i].ldr_no = i;
589 ha->hdr[i].rw_attribs = 0;
590 ha->hdr[i].start_sec = 0;
591 } else {
592 for (j = 0; j < phg->entries; ++j) {
593 k = phg->entry[j].host_drive;
594 if (k >= MAX_LDRIVES)
595 continue;
596 ha->hdr[k].ldr_no = phg->entry[j].log_drive;
597 ha->hdr[k].rw_attribs = phg->entry[j].rw_attribs;
598 ha->hdr[k].start_sec = phg->entry[j].start_sec;
599 }
600 }
601 }
602 gdth_ioctl_free(hanum, sizeof(gdth_hget_str), buf, paddr);
603
604 for (i = 0; i < MAX_HDRIVES; ++i) {
605 if (!(ha->hdr[i].present))
606 continue;
607
608 size = sprintf(buffer+len,
609 "\n Number: \t%-2d \tArr/Log. Drive:\t%d\n",
610 i, ha->hdr[i].ldr_no);
611 len += size; pos = begin + len;
612 flag = TRUE;
613
614 size = sprintf(buffer+len,
615 " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n",
616 (ulong32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec);
617 len += size; pos = begin + len;
618 if (pos < offset) {
619 len = 0;
620 begin = pos;
621 }
622 if (pos > offset + length)
623 goto stop_output;
624 }
625
626 if (!flag) {
627 size = sprintf(buffer+len, "\n --\n");
628 len += size; pos = begin + len;
629 }
630 }
631
632 /* controller events */
633 size = sprintf(buffer+len,"\nController Events:\n");
634 len += size; pos = begin + len;
635
636 for (id = -1;;) {
637 id = gdth_read_event(ha, id, estr);
638 if (estr->event_source == 0)
639 break;
640 if (estr->event_data.eu.driver.ionode == hanum &&
641 estr->event_source == ES_ASYNC) {
642 gdth_log_event(&estr->event_data, hrec);
643 do_gettimeofday(&tv);
644 sec = (int)(tv.tv_sec - estr->first_stamp);
645 if (sec < 0) sec = 0;
646 size = sprintf(buffer+len," date- %02d:%02d:%02d\t%s\n",
647 sec/3600, sec%3600/60, sec%60, hrec);
648 len += size; pos = begin + len;
649 if (pos < offset) {
650 len = 0;
651 begin = pos;
652 }
653 if (pos > offset + length)
654 goto stop_output;
655 }
656 if (id == -1)
657 break;
658 }
659
660stop_output:
1da177e4
LT
661 *start = buffer +(offset-begin);
662 len -= (offset-begin);
663 if (len > length)
664 len = length;
665 TRACE2(("get_info() len %d pos %d begin %d offset %d length %d size %d\n",
666 len,(int)pos,(int)begin,(int)offset,length,size));
667 rc = len;
668
669free_fail:
670 kfree(gdtcmd);
671 kfree(estr);
672 return rc;
673}
674
1da177e4
LT
675static char *gdth_ioctl_alloc(int hanum, int size, int scratch,
676 ulong64 *paddr)
677{
678 gdth_ha_str *ha;
679 ulong flags;
680 char *ret_val;
681
682 if (size == 0)
683 return NULL;
684
685 ha = HADATA(gdth_ctr_tab[hanum]);
686 spin_lock_irqsave(&ha->smp_lock, flags);
687
688 if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
689 ha->scratch_busy = TRUE;
690 ret_val = ha->pscratch;
691 *paddr = ha->scratch_phys;
692 } else if (scratch) {
693 ret_val = NULL;
694 } else {
695 dma_addr_t dma_addr;
696
697 ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
698 *paddr = dma_addr;
699 }
700
701 spin_unlock_irqrestore(&ha->smp_lock, flags);
702 return ret_val;
703}
704
705static void gdth_ioctl_free(int hanum, int size, char *buf, ulong64 paddr)
706{
707 gdth_ha_str *ha;
708 ulong flags;
709
710 ha = HADATA(gdth_ctr_tab[hanum]);
711 spin_lock_irqsave(&ha->smp_lock, flags);
712
713 if (buf == ha->pscratch) {
714 ha->scratch_busy = FALSE;
715 } else {
716 pci_free_consistent(ha->pdev, size, buf, paddr);
717 }
718
719 spin_unlock_irqrestore(&ha->smp_lock, flags);
720}
721
722#ifdef GDTH_IOCTL_PROC
723static int gdth_ioctl_check_bin(int hanum, ushort size)
724{
725 gdth_ha_str *ha;
726 ulong flags;
727 int ret_val;
728
729 ha = HADATA(gdth_ctr_tab[hanum]);
730 spin_lock_irqsave(&ha->smp_lock, flags);
731
732 ret_val = FALSE;
733 if (ha->scratch_busy) {
734 if (((gdth_iord_str *)ha->pscratch)->size == (ulong32)size)
735 ret_val = TRUE;
736 }
737 spin_unlock_irqrestore(&ha->smp_lock, flags);
738 return ret_val;
739}
740#endif
741
742static void gdth_wait_completion(int hanum, int busnum, int id)
743{
744 gdth_ha_str *ha;
745 ulong flags;
746 int i;
747 Scsi_Cmnd *scp;
748 unchar b, t;
749
750 ha = HADATA(gdth_ctr_tab[hanum]);
751 spin_lock_irqsave(&ha->smp_lock, flags);
752
753 for (i = 0; i < GDTH_MAXCMDS; ++i) {
754 scp = ha->cmd_tab[i].cmnd;
755
756 b = virt_ctr ? NUMDATA(scp->device->host)->busnum : scp->device->channel;
757 t = scp->device->id;
758 if (!SPECIAL_SCP(scp) && t == (unchar)id &&
759 b == (unchar)busnum) {
760 scp->SCp.have_data_in = 0;
761 spin_unlock_irqrestore(&ha->smp_lock, flags);
762 while (!scp->SCp.have_data_in)
763 barrier();
764 spin_lock_irqsave(&ha->smp_lock, flags);
765 }
766 }
767 spin_unlock_irqrestore(&ha->smp_lock, flags);
768}
769
770static void gdth_stop_timeout(int hanum, int busnum, int id)
771{
772 gdth_ha_str *ha;
773 ulong flags;
774 Scsi_Cmnd *scp;
775 unchar b, t;
776
777 ha = HADATA(gdth_ctr_tab[hanum]);
778 spin_lock_irqsave(&ha->smp_lock, flags);
779
780 for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {
687d2bc4 781 if (!IS_GDTH_INTERNAL_CMD(scp)) {
cbd5f69b
LA
782 b = virt_ctr ?
783 NUMDATA(scp->device->host)->busnum : scp->device->channel;
784 t = scp->device->id;
785 if (t == (unchar)id && b == (unchar)busnum) {
786 TRACE2(("gdth_stop_timeout(): update_timeout()\n"));
787 scp->SCp.buffers_residual = gdth_update_timeout(hanum, scp, 0);
788 }
1da177e4
LT
789 }
790 }
791 spin_unlock_irqrestore(&ha->smp_lock, flags);
792}
793
794static void gdth_start_timeout(int hanum, int busnum, int id)
795{
796 gdth_ha_str *ha;
797 ulong flags;
798 Scsi_Cmnd *scp;
799 unchar b, t;
800
801 ha = HADATA(gdth_ctr_tab[hanum]);
802 spin_lock_irqsave(&ha->smp_lock, flags);
803
804 for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {
687d2bc4 805 if (!IS_GDTH_INTERNAL_CMD(scp)) {
cbd5f69b
LA
806 b = virt_ctr ?
807 NUMDATA(scp->device->host)->busnum : scp->device->channel;
808 t = scp->device->id;
809 if (t == (unchar)id && b == (unchar)busnum) {
810 TRACE2(("gdth_start_timeout(): update_timeout()\n"));
811 gdth_update_timeout(hanum, scp, scp->SCp.buffers_residual);
812 }
1da177e4
LT
813 }
814 }
815 spin_unlock_irqrestore(&ha->smp_lock, flags);
816}
817
818static int gdth_update_timeout(int hanum, Scsi_Cmnd *scp, int timeout)
819{
820 int oldto;
821
822 oldto = scp->timeout_per_command;
823 scp->timeout_per_command = timeout;
824
825 if (timeout == 0) {
826 del_timer(&scp->eh_timeout);
827 scp->eh_timeout.data = (unsigned long) NULL;
828 scp->eh_timeout.expires = 0;
829 } else {
830 if (scp->eh_timeout.data != (unsigned long) NULL)
831 del_timer(&scp->eh_timeout);
832 scp->eh_timeout.data = (unsigned long) scp;
833 scp->eh_timeout.expires = jiffies + timeout;
834 add_timer(&scp->eh_timeout);
835 }
836
837 return oldto;
838}
This page took 0.286307 seconds and 5 git commands to generate.