blob: 0572b9bf4bd6e79c8b7650a4ef970039744a58cf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* gdth_proc.c
Leubner, Achimcbd5f692006-06-09 11:34:29 -07002 * $Id: gdth_proc.c,v 1.43 2006/01/11 16:15:00 achim Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 */
4
5#include <linux/completion.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09006#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Linus Torvalds1da177e2005-04-16 15:20:36 -07008int gdth_proc_info(struct Scsi_Host *host, char *buffer,char **start,off_t offset,int length,
9 int inout)
10{
Boaz Harrosh45f1a412007-10-02 23:05:53 +020011 gdth_ha_str *ha = shost_priv(host);
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13 TRACE2(("gdth_proc_info() length %d offs %d inout %d\n",
14 length,(int)offset,inout));
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 if (inout)
Boaz Harrosh45f1a412007-10-02 23:05:53 +020017 return(gdth_set_info(buffer,length,host,ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 else
Boaz Harrosh45f1a412007-10-02 23:05:53 +020019 return(gdth_get_info(buffer,start,offset,length,host,ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -070020}
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22static int gdth_set_info(char *buffer,int length,struct Scsi_Host *host,
Boaz Harrosh45f1a412007-10-02 23:05:53 +020023 gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Leubner, Achimcbd5f692006-06-09 11:34:29 -070025 int ret_val = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Boaz Harrosh45f1a412007-10-02 23:05:53 +020027 TRACE2(("gdth_set_info() ha %d\n",ha->hanum,));
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29 if (length >= 4) {
30 if (strncmp(buffer,"gdth",4) == 0) {
31 buffer += 5;
32 length -= 5;
Boaz Harrosh45f1a412007-10-02 23:05:53 +020033 ret_val = gdth_set_asc_info(host, buffer, length, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 }
35 }
Leubner, Achimcbd5f692006-06-09 11:34:29 -070036
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 return ret_val;
38}
39
Leubner, Achimcbd5f692006-06-09 11:34:29 -070040static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
Boaz Harrosh45f1a412007-10-02 23:05:53 +020041 int length, gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070042{
Leubner, Achimcbd5f692006-06-09 11:34:29 -070043 int orig_length, drive, wb_mode;
44 int i, found;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 gdth_cmd_str gdtcmd;
46 gdth_cpar_str *pcpar;
Dave Jones1fe6dbf2010-01-04 10:19:34 -050047 u64 paddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 char cmnd[MAX_COMMAND_SIZE];
50 memset(cmnd, 0xff, 12);
51 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
52
Boaz Harrosh45f1a412007-10-02 23:05:53 +020053 TRACE2(("gdth_set_asc_info() ha %d\n",ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 orig_length = length + 5;
55 drive = -1;
56 wb_mode = 0;
57 found = FALSE;
58
59 if (length >= 5 && strncmp(buffer,"flush",5)==0) {
60 buffer += 6;
61 length -= 6;
62 if (length && *buffer>='0' && *buffer<='9') {
63 drive = (int)(*buffer-'0');
64 ++buffer; --length;
65 if (length && *buffer>='0' && *buffer<='9') {
66 drive = drive*10 + (int)(*buffer-'0');
67 ++buffer; --length;
68 }
69 printk("GDT: Flushing host drive %d .. ",drive);
70 } else {
71 printk("GDT: Flushing all host drives .. ");
72 }
73 for (i = 0; i < MAX_HDRIVES; ++i) {
74 if (ha->hdr[i].present) {
75 if (drive != -1 && i != drive)
76 continue;
77 found = TRUE;
78 gdtcmd.Service = CACHESERVICE;
79 gdtcmd.OpCode = GDT_FLUSH;
80 if (ha->cache_feat & GDT_64BIT) {
81 gdtcmd.u.cache64.DeviceNo = i;
82 gdtcmd.u.cache64.BlockNo = 1;
83 } else {
84 gdtcmd.u.cache.DeviceNo = i;
85 gdtcmd.u.cache.BlockNo = 1;
86 }
Leubner, Achimcbd5f692006-06-09 11:34:29 -070087
88 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
90 }
91 if (!found)
92 printk("\nNo host drive found !\n");
93 else
94 printk("Done.\n");
95 return(orig_length);
96 }
97
98 if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {
99 buffer += 8;
100 length -= 8;
101 printk("GDT: Disabling write back permanently .. ");
102 wb_mode = 1;
103 } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {
104 buffer += 7;
105 length -= 7;
106 printk("GDT: Enabling write back permanently .. ");
107 wb_mode = 2;
108 } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {
109 buffer += 7;
110 length -= 7;
111 printk("GDT: Disabling write back commands .. ");
112 if (ha->cache_feat & GDT_WR_THROUGH) {
113 gdth_write_through = TRUE;
114 printk("Done.\n");
115 } else {
116 printk("Not supported !\n");
117 }
118 return(orig_length);
119 } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {
120 buffer += 6;
121 length -= 6;
122 printk("GDT: Enabling write back commands .. ");
123 gdth_write_through = FALSE;
124 printk("Done.\n");
125 return(orig_length);
126 }
127
128 if (wb_mode) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200129 if (!gdth_ioctl_alloc(ha, sizeof(gdth_cpar_str), TRUE, &paddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 return(-EBUSY);
131 pcpar = (gdth_cpar_str *)ha->pscratch;
132 memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );
133 gdtcmd.Service = CACHESERVICE;
134 gdtcmd.OpCode = GDT_IOCTL;
135 gdtcmd.u.ioctl.p_param = paddr;
136 gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
137 gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
138 gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
139 pcpar->write_back = wb_mode==1 ? 0:1;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700140
141 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
142
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200143 gdth_ioctl_free(ha, GDTH_SCRATCH, ha->pscratch, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 printk("Done.\n");
145 return(orig_length);
146 }
147
148 printk("GDT: Unknown command: %s Length: %d\n",buffer,length);
149 return(-EINVAL);
150}
151
152static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200153 struct Scsi_Host *host, gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 int size = 0,len = 0;
Alan Cox238ddbb2009-06-09 13:44:02 +0100156 int hlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 off_t begin = 0,pos = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 int id, i, j, k, sec, flag;
159 int no_mdrv = 0, drv_no, is_mirr;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500160 u32 cnt;
161 u64 paddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 int rc = -ENOMEM;
163
164 gdth_cmd_str *gdtcmd;
165 gdth_evt_str *estr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 char hrec[161];
167 struct timeval tv;
168
169 char *buf;
170 gdth_dskstat_str *pds;
171 gdth_diskinfo_str *pdi;
172 gdth_arrayinf_str *pai;
173 gdth_defcnt_str *pdef;
174 gdth_cdrinfo_str *pcdi;
175 gdth_hget_str *phg;
176 char cmnd[MAX_COMMAND_SIZE];
177
178 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
179 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
180 if (!gdtcmd || !estr)
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700181 goto free_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 memset(cmnd, 0xff, 12);
184 memset(gdtcmd, 0, sizeof(gdth_cmd_str));
185
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200186 TRACE2(("gdth_get_info() ha %d\n",ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 /* request is i.e. "cat /proc/scsi/gdth/0" */
190 /* format: %-15s\t%-10s\t%-15s\t%s */
191 /* driver parameters */
192 size = sprintf(buffer+len,"Driver Parameters:\n");
193 len += size; pos = begin + len;
194 if (reserve_list[0] == 0xff)
195 strcpy(hrec, "--");
196 else {
Alan Cox238ddbb2009-06-09 13:44:02 +0100197 hlen = sprintf(hrec, "%d", reserve_list[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 for (i = 1; i < MAX_RES_ARGS; i++) {
199 if (reserve_list[i] == 0xff)
200 break;
Alan Cox238ddbb2009-06-09 13:44:02 +0100201 hlen += snprintf(hrec + hlen , 161 - hlen, ",%d", reserve_list[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 }
203 }
204 size = sprintf(buffer+len,
205 " reserve_mode: \t%d \treserve_list: \t%s\n",
206 reserve_mode, hrec);
207 len += size; pos = begin + len;
208 size = sprintf(buffer+len,
209 " max_ids: \t%-3d \thdr_channel: \t%d\n",
210 max_ids, hdr_channel);
211 len += size; pos = begin + len;
212
213 /* controller information */
214 size = sprintf(buffer+len,"\nDisk Array Controller Information:\n");
215 len += size; pos = begin + len;
Christoph Hellwig52759e62007-10-02 22:59:53 +0200216 strcpy(hrec, ha->binfo.type_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 size = sprintf(buffer+len,
218 " Number: \t%d \tName: \t%s\n",
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200219 ha->hanum, hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 len += size; pos = begin + len;
221
222 if (ha->more_proc)
223 sprintf(hrec, "%d.%02d.%02d-%c%03X",
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500224 (u8)(ha->binfo.upd_fw_ver>>24),
225 (u8)(ha->binfo.upd_fw_ver>>16),
226 (u8)(ha->binfo.upd_fw_ver),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 ha->bfeat.raid ? 'R':'N',
228 ha->binfo.upd_revision);
229 else
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500230 sprintf(hrec, "%d.%02d", (u8)(ha->cpar.version>>8),
231 (u8)(ha->cpar.version));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 size = sprintf(buffer+len,
234 " Driver Ver.: \t%-10s\tFirmware Ver.: \t%s\n",
235 GDTH_VERSION_STR, hrec);
236 len += size; pos = begin + len;
237
238 if (ha->more_proc) {
239 /* more information: 1. about controller */
240 size = sprintf(buffer+len,
241 " Serial No.: \t0x%8X\tCache RAM size:\t%d KB\n",
242 ha->binfo.ser_no, ha->binfo.memsize / 1024);
243 len += size; pos = begin + len;
244 }
245
246#ifdef GDTH_DMA_STATISTICS
247 /* controller statistics */
248 size = sprintf(buffer+len,"\nController Statistics:\n");
249 len += size; pos = begin + len;
250 size = sprintf(buffer+len,
251 " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu\n",
252 ha->dma32_cnt, ha->dma64_cnt);
253 len += size; pos = begin + len;
254#endif
255
256 if (pos < offset) {
257 len = 0;
258 begin = pos;
259 }
260 if (pos > offset + length)
261 goto stop_output;
262
263 if (ha->more_proc) {
264 /* more information: 2. about physical devices */
265 size = sprintf(buffer+len,"\nPhysical Devices:");
266 len += size; pos = begin + len;
267 flag = FALSE;
268
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200269 buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (!buf)
271 goto stop_output;
272 for (i = 0; i < ha->bus_cnt; ++i) {
273 /* 2.a statistics (and retries/reassigns) */
274 TRACE2(("pdr_statistics() chn %d\n",i));
275 pds = (gdth_dskstat_str *)(buf + GDTH_SCRATCH/4);
276 gdtcmd->Service = CACHESERVICE;
277 gdtcmd->OpCode = GDT_IOCTL;
278 gdtcmd->u.ioctl.p_param = paddr + GDTH_SCRATCH/4;
279 gdtcmd->u.ioctl.param_size = 3*GDTH_SCRATCH/4;
280 gdtcmd->u.ioctl.subfunc = DSK_STATISTICS | L_CTRL_PATTERN;
281 gdtcmd->u.ioctl.channel = ha->raw[i].address | INVALID_CHANNEL;
282 pds->bid = ha->raw[i].local_no;
283 pds->first = 0;
284 pds->entries = ha->raw[i].pdev_cnt;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500285 cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(u32)) /
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 sizeof(pds->list[0]);
287 if (pds->entries > cnt)
288 pds->entries = cnt;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700289
290 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 pds->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* other IOCTLs must fit into area GDTH_SCRATCH/4 */
294 for (j = 0; j < ha->raw[i].pdev_cnt; ++j) {
295 /* 2.b drive info */
296 TRACE2(("scsi_drv_info() chn %d dev %d\n",
297 i, ha->raw[i].id_list[j]));
298 pdi = (gdth_diskinfo_str *)buf;
299 gdtcmd->Service = CACHESERVICE;
300 gdtcmd->OpCode = GDT_IOCTL;
301 gdtcmd->u.ioctl.p_param = paddr;
302 gdtcmd->u.ioctl.param_size = sizeof(gdth_diskinfo_str);
303 gdtcmd->u.ioctl.subfunc = SCSI_DR_INFO | L_CTRL_PATTERN;
304 gdtcmd->u.ioctl.channel =
305 ha->raw[i].address | ha->raw[i].id_list[j];
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700306
307 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 strncpy(hrec,pdi->vendor,8);
309 strncpy(hrec+8,pdi->product,16);
310 strncpy(hrec+24,pdi->revision,4);
311 hrec[28] = 0;
312 size = sprintf(buffer+len,
313 "\n Chn/ID/LUN: \t%c/%02d/%d \tName: \t%s\n",
314 'A'+i,pdi->target_id,pdi->lun,hrec);
315 len += size; pos = begin + len;
316 flag = TRUE;
317 pdi->no_ldrive &= 0xffff;
318 if (pdi->no_ldrive == 0xffff)
319 strcpy(hrec,"--");
320 else
321 sprintf(hrec,"%d",pdi->no_ldrive);
322 size = sprintf(buffer+len,
323 " Capacity [MB]:\t%-6d \tTo Log. Drive: \t%s\n",
324 pdi->blkcnt/(1024*1024/pdi->blksize),
325 hrec);
326 len += size; pos = begin + len;
327 } else {
328 pdi->devtype = 0xff;
329 }
330
331 if (pdi->devtype == 0) {
332 /* search retries/reassigns */
333 for (k = 0; k < pds->count; ++k) {
334 if (pds->list[k].tid == pdi->target_id &&
335 pds->list[k].lun == pdi->lun) {
336 size = sprintf(buffer+len,
337 " Retries: \t%-6d \tReassigns: \t%d\n",
338 pds->list[k].retries,
339 pds->list[k].reassigns);
340 len += size; pos = begin + len;
341 break;
342 }
343 }
344 /* 2.c grown defects */
345 TRACE2(("scsi_drv_defcnt() chn %d dev %d\n",
346 i, ha->raw[i].id_list[j]));
347 pdef = (gdth_defcnt_str *)buf;
348 gdtcmd->Service = CACHESERVICE;
349 gdtcmd->OpCode = GDT_IOCTL;
350 gdtcmd->u.ioctl.p_param = paddr;
351 gdtcmd->u.ioctl.param_size = sizeof(gdth_defcnt_str);
352 gdtcmd->u.ioctl.subfunc = SCSI_DEF_CNT | L_CTRL_PATTERN;
353 gdtcmd->u.ioctl.channel =
354 ha->raw[i].address | ha->raw[i].id_list[j];
355 pdef->sddc_type = 0x08;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700356
357 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 size = sprintf(buffer+len,
359 " Grown Defects:\t%d\n",
360 pdef->sddc_cnt);
361 len += size; pos = begin + len;
362 }
363 }
364 if (pos < offset) {
365 len = 0;
366 begin = pos;
367 }
368 if (pos > offset + length)
369 goto stop_output;
370 }
371 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200372 gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 if (!flag) {
375 size = sprintf(buffer+len, "\n --\n");
376 len += size; pos = begin + len;
377 }
378
379 /* 3. about logical drives */
380 size = sprintf(buffer+len,"\nLogical Drives:");
381 len += size; pos = begin + len;
382 flag = FALSE;
383
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200384 buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 if (!buf)
386 goto stop_output;
387 for (i = 0; i < MAX_LDRIVES; ++i) {
388 if (!ha->hdr[i].is_logdrv)
389 continue;
390 drv_no = i;
391 j = k = 0;
392 is_mirr = FALSE;
393 do {
394 /* 3.a log. drive info */
395 TRACE2(("cache_drv_info() drive no %d\n",drv_no));
396 pcdi = (gdth_cdrinfo_str *)buf;
397 gdtcmd->Service = CACHESERVICE;
398 gdtcmd->OpCode = GDT_IOCTL;
399 gdtcmd->u.ioctl.p_param = paddr;
400 gdtcmd->u.ioctl.param_size = sizeof(gdth_cdrinfo_str);
401 gdtcmd->u.ioctl.subfunc = CACHE_DRV_INFO;
402 gdtcmd->u.ioctl.channel = drv_no;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700403 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 pcdi->ld_dtype >>= 16;
406 j++;
407 if (pcdi->ld_dtype > 2) {
408 strcpy(hrec, "missing");
409 } else if (pcdi->ld_error & 1) {
410 strcpy(hrec, "fault");
411 } else if (pcdi->ld_error & 2) {
412 strcpy(hrec, "invalid");
413 k++; j--;
414 } else {
415 strcpy(hrec, "ok");
416 }
417
418 if (drv_no == i) {
419 size = sprintf(buffer+len,
420 "\n Number: \t%-2d \tStatus: \t%s\n",
421 drv_no, hrec);
422 len += size; pos = begin + len;
423 flag = TRUE;
424 no_mdrv = pcdi->cd_ldcnt;
425 if (no_mdrv > 1 || pcdi->ld_slave != -1) {
426 is_mirr = TRUE;
427 strcpy(hrec, "RAID-1");
428 } else if (pcdi->ld_dtype == 0) {
429 strcpy(hrec, "Disk");
430 } else if (pcdi->ld_dtype == 1) {
431 strcpy(hrec, "RAID-0");
432 } else if (pcdi->ld_dtype == 2) {
433 strcpy(hrec, "Chain");
434 } else {
435 strcpy(hrec, "???");
436 }
437 size = sprintf(buffer+len,
438 " Capacity [MB]:\t%-6d \tType: \t%s\n",
439 pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize),
440 hrec);
441 len += size; pos = begin + len;
442 } else {
443 size = sprintf(buffer+len,
444 " Slave Number: \t%-2d \tStatus: \t%s\n",
445 drv_no & 0x7fff, hrec);
446 len += size; pos = begin + len;
447 }
448 drv_no = pcdi->ld_slave;
449 if (pos < offset) {
450 len = 0;
451 begin = pos;
452 }
453 if (pos > offset + length)
454 goto stop_output;
455 } while (drv_no != -1);
456
457 if (is_mirr) {
458 size = sprintf(buffer+len,
459 " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n",
460 no_mdrv - j - k, k);
461 len += size; pos = begin + len;
462 }
463
464 if (!ha->hdr[i].is_arraydrv)
465 strcpy(hrec, "--");
466 else
467 sprintf(hrec, "%d", ha->hdr[i].master_no);
468 size = sprintf(buffer+len,
469 " To Array Drv.:\t%s\n", hrec);
470 len += size; pos = begin + len;
471 if (pos < offset) {
472 len = 0;
473 begin = pos;
474 }
475 if (pos > offset + length)
476 goto stop_output;
477 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200478 gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 if (!flag) {
481 size = sprintf(buffer+len, "\n --\n");
482 len += size; pos = begin + len;
483 }
484
485 /* 4. about array drives */
486 size = sprintf(buffer+len,"\nArray Drives:");
487 len += size; pos = begin + len;
488 flag = FALSE;
489
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200490 buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 if (!buf)
492 goto stop_output;
493 for (i = 0; i < MAX_LDRIVES; ++i) {
494 if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
495 continue;
496 /* 4.a array drive info */
497 TRACE2(("array_info() drive no %d\n",i));
498 pai = (gdth_arrayinf_str *)buf;
499 gdtcmd->Service = CACHESERVICE;
500 gdtcmd->OpCode = GDT_IOCTL;
501 gdtcmd->u.ioctl.p_param = paddr;
502 gdtcmd->u.ioctl.param_size = sizeof(gdth_arrayinf_str);
503 gdtcmd->u.ioctl.subfunc = ARRAY_INFO | LA_CTRL_PATTERN;
504 gdtcmd->u.ioctl.channel = i;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700505 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 if (pai->ai_state == 0)
507 strcpy(hrec, "idle");
508 else if (pai->ai_state == 2)
509 strcpy(hrec, "build");
510 else if (pai->ai_state == 4)
511 strcpy(hrec, "ready");
512 else if (pai->ai_state == 6)
513 strcpy(hrec, "fail");
514 else if (pai->ai_state == 8 || pai->ai_state == 10)
515 strcpy(hrec, "rebuild");
516 else
517 strcpy(hrec, "error");
518 if (pai->ai_ext_state & 0x10)
519 strcat(hrec, "/expand");
520 else if (pai->ai_ext_state & 0x1)
521 strcat(hrec, "/patch");
522 size = sprintf(buffer+len,
523 "\n Number: \t%-2d \tStatus: \t%s\n",
524 i,hrec);
525 len += size; pos = begin + len;
526 flag = TRUE;
527
528 if (pai->ai_type == 0)
529 strcpy(hrec, "RAID-0");
530 else if (pai->ai_type == 4)
531 strcpy(hrec, "RAID-4");
532 else if (pai->ai_type == 5)
533 strcpy(hrec, "RAID-5");
534 else
535 strcpy(hrec, "RAID-10");
536 size = sprintf(buffer+len,
537 " Capacity [MB]:\t%-6d \tType: \t%s\n",
538 pai->ai_size/(1024*1024/pai->ai_secsize),
539 hrec);
540 len += size; pos = begin + len;
541 if (pos < offset) {
542 len = 0;
543 begin = pos;
544 }
545 if (pos > offset + length)
546 goto stop_output;
547 }
548 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200549 gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 if (!flag) {
552 size = sprintf(buffer+len, "\n --\n");
553 len += size; pos = begin + len;
554 }
555
556 /* 5. about host drives */
557 size = sprintf(buffer+len,"\nHost Drives:");
558 len += size; pos = begin + len;
559 flag = FALSE;
560
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200561 buf = gdth_ioctl_alloc(ha, sizeof(gdth_hget_str), FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (!buf)
563 goto stop_output;
564 for (i = 0; i < MAX_LDRIVES; ++i) {
565 if (!ha->hdr[i].is_logdrv ||
566 (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
567 continue;
568 /* 5.a get host drive list */
569 TRACE2(("host_get() drv_no %d\n",i));
570 phg = (gdth_hget_str *)buf;
571 gdtcmd->Service = CACHESERVICE;
572 gdtcmd->OpCode = GDT_IOCTL;
573 gdtcmd->u.ioctl.p_param = paddr;
574 gdtcmd->u.ioctl.param_size = sizeof(gdth_hget_str);
575 gdtcmd->u.ioctl.subfunc = HOST_GET | LA_CTRL_PATTERN;
576 gdtcmd->u.ioctl.channel = i;
577 phg->entries = MAX_HDRIVES;
578 phg->offset = GDTOFFSOF(gdth_hget_str, entry[0]);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700579 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 ha->hdr[i].ldr_no = i;
581 ha->hdr[i].rw_attribs = 0;
582 ha->hdr[i].start_sec = 0;
583 } else {
584 for (j = 0; j < phg->entries; ++j) {
585 k = phg->entry[j].host_drive;
586 if (k >= MAX_LDRIVES)
587 continue;
588 ha->hdr[k].ldr_no = phg->entry[j].log_drive;
589 ha->hdr[k].rw_attribs = phg->entry[j].rw_attribs;
590 ha->hdr[k].start_sec = phg->entry[j].start_sec;
591 }
592 }
593 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200594 gdth_ioctl_free(ha, sizeof(gdth_hget_str), buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 for (i = 0; i < MAX_HDRIVES; ++i) {
597 if (!(ha->hdr[i].present))
598 continue;
599
600 size = sprintf(buffer+len,
601 "\n Number: \t%-2d \tArr/Log. Drive:\t%d\n",
602 i, ha->hdr[i].ldr_no);
603 len += size; pos = begin + len;
604 flag = TRUE;
605
606 size = sprintf(buffer+len,
607 " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n",
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500608 (u32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 len += size; pos = begin + len;
610 if (pos < offset) {
611 len = 0;
612 begin = pos;
613 }
614 if (pos > offset + length)
615 goto stop_output;
616 }
617
618 if (!flag) {
619 size = sprintf(buffer+len, "\n --\n");
620 len += size; pos = begin + len;
621 }
622 }
623
624 /* controller events */
625 size = sprintf(buffer+len,"\nController Events:\n");
626 len += size; pos = begin + len;
627
628 for (id = -1;;) {
629 id = gdth_read_event(ha, id, estr);
630 if (estr->event_source == 0)
631 break;
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200632 if (estr->event_data.eu.driver.ionode == ha->hanum &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 estr->event_source == ES_ASYNC) {
634 gdth_log_event(&estr->event_data, hrec);
635 do_gettimeofday(&tv);
636 sec = (int)(tv.tv_sec - estr->first_stamp);
637 if (sec < 0) sec = 0;
638 size = sprintf(buffer+len," date- %02d:%02d:%02d\t%s\n",
639 sec/3600, sec%3600/60, sec%60, hrec);
640 len += size; pos = begin + len;
641 if (pos < offset) {
642 len = 0;
643 begin = pos;
644 }
645 if (pos > offset + length)
646 goto stop_output;
647 }
648 if (id == -1)
649 break;
650 }
651
652stop_output:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 *start = buffer +(offset-begin);
654 len -= (offset-begin);
655 if (len > length)
656 len = length;
657 TRACE2(("get_info() len %d pos %d begin %d offset %d length %d size %d\n",
658 len,(int)pos,(int)begin,(int)offset,length,size));
659 rc = len;
660
661free_fail:
662 kfree(gdtcmd);
663 kfree(estr);
664 return rc;
665}
666
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200667static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500668 u64 *paddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500670 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 char *ret_val;
672
673 if (size == 0)
674 return NULL;
675
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 spin_lock_irqsave(&ha->smp_lock, flags);
677
678 if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
679 ha->scratch_busy = TRUE;
680 ret_val = ha->pscratch;
681 *paddr = ha->scratch_phys;
682 } else if (scratch) {
683 ret_val = NULL;
684 } else {
685 dma_addr_t dma_addr;
686
687 ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
688 *paddr = dma_addr;
689 }
690
691 spin_unlock_irqrestore(&ha->smp_lock, flags);
692 return ret_val;
693}
694
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500695static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500697 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 if (buf == ha->pscratch) {
James Bottomleyff83efa2008-02-17 11:24:51 -0600700 spin_lock_irqsave(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 ha->scratch_busy = FALSE;
James Bottomleyff83efa2008-02-17 11:24:51 -0600702 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 } else {
704 pci_free_consistent(ha->pdev, size, buf, paddr);
705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706}
707
708#ifdef GDTH_IOCTL_PROC
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500709static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500711 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 int ret_val;
713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 spin_lock_irqsave(&ha->smp_lock, flags);
715
716 ret_val = FALSE;
717 if (ha->scratch_busy) {
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500718 if (((gdth_iord_str *)ha->pscratch)->size == (u32)size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 ret_val = TRUE;
720 }
721 spin_unlock_irqrestore(&ha->smp_lock, flags);
722 return ret_val;
723}
724#endif
725
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200726static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500728 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 int i;
730 Scsi_Cmnd *scp;
Boaz Harroshf842b642007-10-02 23:16:01 +0200731 struct gdth_cmndinfo *cmndinfo;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500732 u8 b, t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 spin_lock_irqsave(&ha->smp_lock, flags);
735
736 for (i = 0; i < GDTH_MAXCMDS; ++i) {
737 scp = ha->cmd_tab[i].cmnd;
Boaz Harroshf842b642007-10-02 23:16:01 +0200738 cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Christoph Hellwig52759e62007-10-02 22:59:53 +0200740 b = scp->device->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 t = scp->device->id;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500742 if (!SPECIAL_SCP(scp) && t == (u8)id &&
743 b == (u8)busnum) {
Boaz Harroshf842b642007-10-02 23:16:01 +0200744 cmndinfo->wait_for_completion = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 spin_unlock_irqrestore(&ha->smp_lock, flags);
Boaz Harroshf842b642007-10-02 23:16:01 +0200746 while (!cmndinfo->wait_for_completion)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 barrier();
748 spin_lock_irqsave(&ha->smp_lock, flags);
749 }
750 }
751 spin_unlock_irqrestore(&ha->smp_lock, flags);
752}