Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 | 2 | /* gdth_proc.c |
cbd5f69b | 3 | * $Id: gdth_proc.c,v 1.43 2006/01/11 16:15:00 achim Exp $ |
1da177e4 LT |
4 | */ |
5 | ||
6 | #include <linux/completion.h> | |
5a0e3ad6 | 7 | #include <linux/slab.h> |
1da177e4 | 8 | |
3e0552ee | 9 | int gdth_set_info(struct Scsi_Host *host, char *buffer, int length) |
1da177e4 | 10 | { |
45f1a41b | 11 | gdth_ha_str *ha = shost_priv(host); |
cbd5f69b | 12 | int ret_val = -EINVAL; |
1da177e4 | 13 | |
45f1a41b | 14 | TRACE2(("gdth_set_info() ha %d\n",ha->hanum,)); |
1da177e4 LT |
15 | |
16 | if (length >= 4) { | |
17 | if (strncmp(buffer,"gdth",4) == 0) { | |
18 | buffer += 5; | |
19 | length -= 5; | |
45f1a41b | 20 | ret_val = gdth_set_asc_info(host, buffer, length, ha); |
1da177e4 LT |
21 | } |
22 | } | |
cbd5f69b | 23 | |
1da177e4 LT |
24 | return ret_val; |
25 | } | |
26 | ||
cbd5f69b | 27 | static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer, |
45f1a41b | 28 | int length, gdth_ha_str *ha) |
1da177e4 | 29 | { |
cbd5f69b LA |
30 | int orig_length, drive, wb_mode; |
31 | int i, found; | |
1da177e4 LT |
32 | gdth_cmd_str gdtcmd; |
33 | gdth_cpar_str *pcpar; | |
1fe6dbf4 | 34 | u64 paddr; |
1da177e4 LT |
35 | |
36 | char cmnd[MAX_COMMAND_SIZE]; | |
37 | memset(cmnd, 0xff, 12); | |
38 | memset(&gdtcmd, 0, sizeof(gdth_cmd_str)); | |
39 | ||
45f1a41b | 40 | TRACE2(("gdth_set_asc_info() ha %d\n",ha->hanum)); |
1da177e4 LT |
41 | orig_length = length + 5; |
42 | drive = -1; | |
43 | wb_mode = 0; | |
44 | found = FALSE; | |
45 | ||
46 | if (length >= 5 && strncmp(buffer,"flush",5)==0) { | |
47 | buffer += 6; | |
48 | length -= 6; | |
49 | if (length && *buffer>='0' && *buffer<='9') { | |
50 | drive = (int)(*buffer-'0'); | |
51 | ++buffer; --length; | |
52 | if (length && *buffer>='0' && *buffer<='9') { | |
53 | drive = drive*10 + (int)(*buffer-'0'); | |
54 | ++buffer; --length; | |
55 | } | |
56 | printk("GDT: Flushing host drive %d .. ",drive); | |
57 | } else { | |
58 | printk("GDT: Flushing all host drives .. "); | |
59 | } | |
60 | for (i = 0; i < MAX_HDRIVES; ++i) { | |
61 | if (ha->hdr[i].present) { | |
62 | if (drive != -1 && i != drive) | |
63 | continue; | |
64 | found = TRUE; | |
65 | gdtcmd.Service = CACHESERVICE; | |
66 | gdtcmd.OpCode = GDT_FLUSH; | |
67 | if (ha->cache_feat & GDT_64BIT) { | |
68 | gdtcmd.u.cache64.DeviceNo = i; | |
69 | gdtcmd.u.cache64.BlockNo = 1; | |
70 | } else { | |
71 | gdtcmd.u.cache.DeviceNo = i; | |
72 | gdtcmd.u.cache.BlockNo = 1; | |
73 | } | |
cbd5f69b LA |
74 | |
75 | gdth_execute(host, &gdtcmd, cmnd, 30, NULL); | |
1da177e4 LT |
76 | } |
77 | } | |
78 | if (!found) | |
79 | printk("\nNo host drive found !\n"); | |
80 | else | |
81 | printk("Done.\n"); | |
82 | return(orig_length); | |
83 | } | |
84 | ||
85 | if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) { | |
86 | buffer += 8; | |
87 | length -= 8; | |
88 | printk("GDT: Disabling write back permanently .. "); | |
89 | wb_mode = 1; | |
90 | } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) { | |
91 | buffer += 7; | |
92 | length -= 7; | |
93 | printk("GDT: Enabling write back permanently .. "); | |
94 | wb_mode = 2; | |
95 | } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) { | |
96 | buffer += 7; | |
97 | length -= 7; | |
98 | printk("GDT: Disabling write back commands .. "); | |
99 | if (ha->cache_feat & GDT_WR_THROUGH) { | |
100 | gdth_write_through = TRUE; | |
101 | printk("Done.\n"); | |
102 | } else { | |
103 | printk("Not supported !\n"); | |
104 | } | |
105 | return(orig_length); | |
106 | } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) { | |
107 | buffer += 6; | |
108 | length -= 6; | |
109 | printk("GDT: Enabling write back commands .. "); | |
110 | gdth_write_through = FALSE; | |
111 | printk("Done.\n"); | |
112 | return(orig_length); | |
113 | } | |
114 | ||
115 | if (wb_mode) { | |
45f1a41b | 116 | if (!gdth_ioctl_alloc(ha, sizeof(gdth_cpar_str), TRUE, &paddr)) |
1da177e4 LT |
117 | return(-EBUSY); |
118 | pcpar = (gdth_cpar_str *)ha->pscratch; | |
119 | memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) ); | |
120 | gdtcmd.Service = CACHESERVICE; | |
121 | gdtcmd.OpCode = GDT_IOCTL; | |
122 | gdtcmd.u.ioctl.p_param = paddr; | |
123 | gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str); | |
124 | gdtcmd.u.ioctl.subfunc = CACHE_CONFIG; | |
125 | gdtcmd.u.ioctl.channel = INVALID_CHANNEL; | |
126 | pcpar->write_back = wb_mode==1 ? 0:1; | |
cbd5f69b LA |
127 | |
128 | gdth_execute(host, &gdtcmd, cmnd, 30, NULL); | |
129 | ||
45f1a41b | 130 | gdth_ioctl_free(ha, GDTH_SCRATCH, ha->pscratch, paddr); |
1da177e4 LT |
131 | printk("Done.\n"); |
132 | return(orig_length); | |
133 | } | |
134 | ||
135 | printk("GDT: Unknown command: %s Length: %d\n",buffer,length); | |
136 | return(-EINVAL); | |
137 | } | |
138 | ||
3e0552ee | 139 | int gdth_show_info(struct seq_file *m, struct Scsi_Host *host) |
1da177e4 | 140 | { |
3e0552ee | 141 | gdth_ha_str *ha = shost_priv(host); |
238ddbb9 | 142 | int hlen; |
1da177e4 LT |
143 | int id, i, j, k, sec, flag; |
144 | int no_mdrv = 0, drv_no, is_mirr; | |
1fe6dbf4 DJ |
145 | u32 cnt; |
146 | u64 paddr; | |
1da177e4 LT |
147 | int rc = -ENOMEM; |
148 | ||
149 | gdth_cmd_str *gdtcmd; | |
150 | gdth_evt_str *estr; | |
345ebae7 | 151 | char hrec[277]; |
1da177e4 LT |
152 | |
153 | char *buf; | |
154 | gdth_dskstat_str *pds; | |
155 | gdth_diskinfo_str *pdi; | |
156 | gdth_arrayinf_str *pai; | |
157 | gdth_defcnt_str *pdef; | |
158 | gdth_cdrinfo_str *pcdi; | |
159 | gdth_hget_str *phg; | |
160 | char cmnd[MAX_COMMAND_SIZE]; | |
161 | ||
162 | gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL); | |
163 | estr = kmalloc(sizeof(*estr), GFP_KERNEL); | |
164 | if (!gdtcmd || !estr) | |
cbd5f69b | 165 | goto free_fail; |
1da177e4 LT |
166 | |
167 | memset(cmnd, 0xff, 12); | |
168 | memset(gdtcmd, 0, sizeof(gdth_cmd_str)); | |
169 | ||
45f1a41b | 170 | TRACE2(("gdth_get_info() ha %d\n",ha->hanum)); |
1da177e4 | 171 | |
1da177e4 LT |
172 | |
173 | /* request is i.e. "cat /proc/scsi/gdth/0" */ | |
174 | /* format: %-15s\t%-10s\t%-15s\t%s */ | |
175 | /* driver parameters */ | |
91c40f24 | 176 | seq_puts(m, "Driver Parameters:\n"); |
1da177e4 LT |
177 | if (reserve_list[0] == 0xff) |
178 | strcpy(hrec, "--"); | |
179 | else { | |
238ddbb9 | 180 | hlen = sprintf(hrec, "%d", reserve_list[0]); |
1da177e4 LT |
181 | for (i = 1; i < MAX_RES_ARGS; i++) { |
182 | if (reserve_list[i] == 0xff) | |
183 | break; | |
238ddbb9 | 184 | hlen += snprintf(hrec + hlen , 161 - hlen, ",%d", reserve_list[i]); |
1da177e4 LT |
185 | } |
186 | } | |
3e0552ee | 187 | seq_printf(m, |
1da177e4 LT |
188 | " reserve_mode: \t%d \treserve_list: \t%s\n", |
189 | reserve_mode, hrec); | |
3e0552ee | 190 | seq_printf(m, |
1da177e4 LT |
191 | " max_ids: \t%-3d \thdr_channel: \t%d\n", |
192 | max_ids, hdr_channel); | |
1da177e4 LT |
193 | |
194 | /* controller information */ | |
91c40f24 | 195 | seq_puts(m, "\nDisk Array Controller Information:\n"); |
3e0552ee | 196 | seq_printf(m, |
1da177e4 | 197 | " Number: \t%d \tName: \t%s\n", |
3e0552ee | 198 | ha->hanum, ha->binfo.type_string); |
1da177e4 | 199 | |
3e0552ee AV |
200 | seq_printf(m, |
201 | " Driver Ver.: \t%-10s\tFirmware Ver.: \t", | |
202 | GDTH_VERSION_STR); | |
1da177e4 | 203 | if (ha->more_proc) |
3e0552ee | 204 | seq_printf(m, "%d.%02d.%02d-%c%03X\n", |
1fe6dbf4 DJ |
205 | (u8)(ha->binfo.upd_fw_ver>>24), |
206 | (u8)(ha->binfo.upd_fw_ver>>16), | |
207 | (u8)(ha->binfo.upd_fw_ver), | |
1da177e4 LT |
208 | ha->bfeat.raid ? 'R':'N', |
209 | ha->binfo.upd_revision); | |
210 | else | |
3e0552ee | 211 | seq_printf(m, "%d.%02d\n", (u8)(ha->cpar.version>>8), |
1fe6dbf4 | 212 | (u8)(ha->cpar.version)); |
1da177e4 | 213 | |
3e0552ee | 214 | if (ha->more_proc) |
1da177e4 | 215 | /* more information: 1. about controller */ |
3e0552ee | 216 | seq_printf(m, |
1da177e4 LT |
217 | " Serial No.: \t0x%8X\tCache RAM size:\t%d KB\n", |
218 | ha->binfo.ser_no, ha->binfo.memsize / 1024); | |
1da177e4 LT |
219 | |
220 | #ifdef GDTH_DMA_STATISTICS | |
221 | /* controller statistics */ | |
91c40f24 | 222 | seq_puts(m, "\nController Statistics:\n"); |
3e0552ee | 223 | seq_printf(m, |
1da177e4 LT |
224 | " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu\n", |
225 | ha->dma32_cnt, ha->dma64_cnt); | |
1da177e4 LT |
226 | #endif |
227 | ||
1da177e4 | 228 | if (ha->more_proc) { |
8d22022c CH |
229 | size_t size = max_t(size_t, GDTH_SCRATCH, sizeof(gdth_hget_str)); |
230 | ||
1da177e4 | 231 | /* more information: 2. about physical devices */ |
91c40f24 | 232 | seq_puts(m, "\nPhysical Devices:"); |
1da177e4 LT |
233 | flag = FALSE; |
234 | ||
8d22022c | 235 | buf = gdth_ioctl_alloc(ha, size, FALSE, &paddr); |
1da177e4 LT |
236 | if (!buf) |
237 | goto stop_output; | |
238 | for (i = 0; i < ha->bus_cnt; ++i) { | |
239 | /* 2.a statistics (and retries/reassigns) */ | |
240 | TRACE2(("pdr_statistics() chn %d\n",i)); | |
241 | pds = (gdth_dskstat_str *)(buf + GDTH_SCRATCH/4); | |
242 | gdtcmd->Service = CACHESERVICE; | |
243 | gdtcmd->OpCode = GDT_IOCTL; | |
244 | gdtcmd->u.ioctl.p_param = paddr + GDTH_SCRATCH/4; | |
245 | gdtcmd->u.ioctl.param_size = 3*GDTH_SCRATCH/4; | |
246 | gdtcmd->u.ioctl.subfunc = DSK_STATISTICS | L_CTRL_PATTERN; | |
247 | gdtcmd->u.ioctl.channel = ha->raw[i].address | INVALID_CHANNEL; | |
248 | pds->bid = ha->raw[i].local_no; | |
249 | pds->first = 0; | |
250 | pds->entries = ha->raw[i].pdev_cnt; | |
1fe6dbf4 | 251 | cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(u32)) / |
1da177e4 LT |
252 | sizeof(pds->list[0]); |
253 | if (pds->entries > cnt) | |
254 | pds->entries = cnt; | |
cbd5f69b LA |
255 | |
256 | if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK) | |
1da177e4 | 257 | pds->count = 0; |
1da177e4 LT |
258 | |
259 | /* other IOCTLs must fit into area GDTH_SCRATCH/4 */ | |
260 | for (j = 0; j < ha->raw[i].pdev_cnt; ++j) { | |
261 | /* 2.b drive info */ | |
262 | TRACE2(("scsi_drv_info() chn %d dev %d\n", | |
263 | i, ha->raw[i].id_list[j])); | |
264 | pdi = (gdth_diskinfo_str *)buf; | |
265 | gdtcmd->Service = CACHESERVICE; | |
266 | gdtcmd->OpCode = GDT_IOCTL; | |
267 | gdtcmd->u.ioctl.p_param = paddr; | |
268 | gdtcmd->u.ioctl.param_size = sizeof(gdth_diskinfo_str); | |
269 | gdtcmd->u.ioctl.subfunc = SCSI_DR_INFO | L_CTRL_PATTERN; | |
270 | gdtcmd->u.ioctl.channel = | |
271 | ha->raw[i].address | ha->raw[i].id_list[j]; | |
cbd5f69b LA |
272 | |
273 | if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) { | |
1da177e4 LT |
274 | strncpy(hrec,pdi->vendor,8); |
275 | strncpy(hrec+8,pdi->product,16); | |
276 | strncpy(hrec+24,pdi->revision,4); | |
277 | hrec[28] = 0; | |
3e0552ee | 278 | seq_printf(m, |
1da177e4 LT |
279 | "\n Chn/ID/LUN: \t%c/%02d/%d \tName: \t%s\n", |
280 | 'A'+i,pdi->target_id,pdi->lun,hrec); | |
1da177e4 LT |
281 | flag = TRUE; |
282 | pdi->no_ldrive &= 0xffff; | |
283 | if (pdi->no_ldrive == 0xffff) | |
284 | strcpy(hrec,"--"); | |
285 | else | |
286 | sprintf(hrec,"%d",pdi->no_ldrive); | |
3e0552ee | 287 | seq_printf(m, |
1da177e4 LT |
288 | " Capacity [MB]:\t%-6d \tTo Log. Drive: \t%s\n", |
289 | pdi->blkcnt/(1024*1024/pdi->blksize), | |
290 | hrec); | |
1da177e4 LT |
291 | } else { |
292 | pdi->devtype = 0xff; | |
293 | } | |
294 | ||
295 | if (pdi->devtype == 0) { | |
296 | /* search retries/reassigns */ | |
297 | for (k = 0; k < pds->count; ++k) { | |
298 | if (pds->list[k].tid == pdi->target_id && | |
299 | pds->list[k].lun == pdi->lun) { | |
3e0552ee | 300 | seq_printf(m, |
1da177e4 LT |
301 | " Retries: \t%-6d \tReassigns: \t%d\n", |
302 | pds->list[k].retries, | |
303 | pds->list[k].reassigns); | |
1da177e4 LT |
304 | break; |
305 | } | |
306 | } | |
307 | /* 2.c grown defects */ | |
308 | TRACE2(("scsi_drv_defcnt() chn %d dev %d\n", | |
309 | i, ha->raw[i].id_list[j])); | |
310 | pdef = (gdth_defcnt_str *)buf; | |
311 | gdtcmd->Service = CACHESERVICE; | |
312 | gdtcmd->OpCode = GDT_IOCTL; | |
313 | gdtcmd->u.ioctl.p_param = paddr; | |
314 | gdtcmd->u.ioctl.param_size = sizeof(gdth_defcnt_str); | |
315 | gdtcmd->u.ioctl.subfunc = SCSI_DEF_CNT | L_CTRL_PATTERN; | |
316 | gdtcmd->u.ioctl.channel = | |
317 | ha->raw[i].address | ha->raw[i].id_list[j]; | |
318 | pdef->sddc_type = 0x08; | |
cbd5f69b LA |
319 | |
320 | if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) { | |
3e0552ee | 321 | seq_printf(m, |
1da177e4 LT |
322 | " Grown Defects:\t%d\n", |
323 | pdef->sddc_cnt); | |
1da177e4 LT |
324 | } |
325 | } | |
1da177e4 LT |
326 | } |
327 | } | |
1da177e4 | 328 | |
3e0552ee | 329 | if (!flag) |
91c40f24 | 330 | seq_puts(m, "\n --\n"); |
1da177e4 LT |
331 | |
332 | /* 3. about logical drives */ | |
91c40f24 | 333 | seq_puts(m, "\nLogical Drives:"); |
1da177e4 LT |
334 | flag = FALSE; |
335 | ||
1da177e4 LT |
336 | for (i = 0; i < MAX_LDRIVES; ++i) { |
337 | if (!ha->hdr[i].is_logdrv) | |
338 | continue; | |
339 | drv_no = i; | |
340 | j = k = 0; | |
341 | is_mirr = FALSE; | |
342 | do { | |
343 | /* 3.a log. drive info */ | |
344 | TRACE2(("cache_drv_info() drive no %d\n",drv_no)); | |
345 | pcdi = (gdth_cdrinfo_str *)buf; | |
346 | gdtcmd->Service = CACHESERVICE; | |
347 | gdtcmd->OpCode = GDT_IOCTL; | |
348 | gdtcmd->u.ioctl.p_param = paddr; | |
349 | gdtcmd->u.ioctl.param_size = sizeof(gdth_cdrinfo_str); | |
350 | gdtcmd->u.ioctl.subfunc = CACHE_DRV_INFO; | |
351 | gdtcmd->u.ioctl.channel = drv_no; | |
cbd5f69b | 352 | if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK) |
1da177e4 | 353 | break; |
1da177e4 LT |
354 | pcdi->ld_dtype >>= 16; |
355 | j++; | |
356 | if (pcdi->ld_dtype > 2) { | |
357 | strcpy(hrec, "missing"); | |
358 | } else if (pcdi->ld_error & 1) { | |
359 | strcpy(hrec, "fault"); | |
360 | } else if (pcdi->ld_error & 2) { | |
361 | strcpy(hrec, "invalid"); | |
362 | k++; j--; | |
363 | } else { | |
364 | strcpy(hrec, "ok"); | |
365 | } | |
366 | ||
367 | if (drv_no == i) { | |
3e0552ee | 368 | seq_printf(m, |
1da177e4 LT |
369 | "\n Number: \t%-2d \tStatus: \t%s\n", |
370 | drv_no, hrec); | |
1da177e4 LT |
371 | flag = TRUE; |
372 | no_mdrv = pcdi->cd_ldcnt; | |
373 | if (no_mdrv > 1 || pcdi->ld_slave != -1) { | |
374 | is_mirr = TRUE; | |
375 | strcpy(hrec, "RAID-1"); | |
376 | } else if (pcdi->ld_dtype == 0) { | |
377 | strcpy(hrec, "Disk"); | |
378 | } else if (pcdi->ld_dtype == 1) { | |
379 | strcpy(hrec, "RAID-0"); | |
380 | } else if (pcdi->ld_dtype == 2) { | |
381 | strcpy(hrec, "Chain"); | |
382 | } else { | |
383 | strcpy(hrec, "???"); | |
384 | } | |
3e0552ee | 385 | seq_printf(m, |
1da177e4 LT |
386 | " Capacity [MB]:\t%-6d \tType: \t%s\n", |
387 | pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize), | |
388 | hrec); | |
1da177e4 | 389 | } else { |
3e0552ee | 390 | seq_printf(m, |
1da177e4 LT |
391 | " Slave Number: \t%-2d \tStatus: \t%s\n", |
392 | drv_no & 0x7fff, hrec); | |
1da177e4 LT |
393 | } |
394 | drv_no = pcdi->ld_slave; | |
1da177e4 LT |
395 | } while (drv_no != -1); |
396 | ||
3e0552ee AV |
397 | if (is_mirr) |
398 | seq_printf(m, | |
1da177e4 LT |
399 | " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n", |
400 | no_mdrv - j - k, k); | |
3e0552ee | 401 | |
1da177e4 LT |
402 | if (!ha->hdr[i].is_arraydrv) |
403 | strcpy(hrec, "--"); | |
404 | else | |
405 | sprintf(hrec, "%d", ha->hdr[i].master_no); | |
3e0552ee | 406 | seq_printf(m, |
1da177e4 | 407 | " To Array Drv.:\t%s\n", hrec); |
1da177e4 | 408 | } |
1da177e4 | 409 | |
3e0552ee | 410 | if (!flag) |
91c40f24 | 411 | seq_puts(m, "\n --\n"); |
1da177e4 LT |
412 | |
413 | /* 4. about array drives */ | |
91c40f24 | 414 | seq_puts(m, "\nArray Drives:"); |
1da177e4 LT |
415 | flag = FALSE; |
416 | ||
1da177e4 LT |
417 | for (i = 0; i < MAX_LDRIVES; ++i) { |
418 | if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master)) | |
419 | continue; | |
420 | /* 4.a array drive info */ | |
421 | TRACE2(("array_info() drive no %d\n",i)); | |
422 | pai = (gdth_arrayinf_str *)buf; | |
423 | gdtcmd->Service = CACHESERVICE; | |
424 | gdtcmd->OpCode = GDT_IOCTL; | |
425 | gdtcmd->u.ioctl.p_param = paddr; | |
426 | gdtcmd->u.ioctl.param_size = sizeof(gdth_arrayinf_str); | |
427 | gdtcmd->u.ioctl.subfunc = ARRAY_INFO | LA_CTRL_PATTERN; | |
428 | gdtcmd->u.ioctl.channel = i; | |
cbd5f69b | 429 | if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) { |
1da177e4 LT |
430 | if (pai->ai_state == 0) |
431 | strcpy(hrec, "idle"); | |
432 | else if (pai->ai_state == 2) | |
433 | strcpy(hrec, "build"); | |
434 | else if (pai->ai_state == 4) | |
435 | strcpy(hrec, "ready"); | |
436 | else if (pai->ai_state == 6) | |
437 | strcpy(hrec, "fail"); | |
438 | else if (pai->ai_state == 8 || pai->ai_state == 10) | |
439 | strcpy(hrec, "rebuild"); | |
440 | else | |
441 | strcpy(hrec, "error"); | |
442 | if (pai->ai_ext_state & 0x10) | |
443 | strcat(hrec, "/expand"); | |
444 | else if (pai->ai_ext_state & 0x1) | |
445 | strcat(hrec, "/patch"); | |
3e0552ee | 446 | seq_printf(m, |
1da177e4 LT |
447 | "\n Number: \t%-2d \tStatus: \t%s\n", |
448 | i,hrec); | |
1da177e4 LT |
449 | flag = TRUE; |
450 | ||
451 | if (pai->ai_type == 0) | |
452 | strcpy(hrec, "RAID-0"); | |
453 | else if (pai->ai_type == 4) | |
454 | strcpy(hrec, "RAID-4"); | |
455 | else if (pai->ai_type == 5) | |
456 | strcpy(hrec, "RAID-5"); | |
457 | else | |
458 | strcpy(hrec, "RAID-10"); | |
3e0552ee | 459 | seq_printf(m, |
1da177e4 LT |
460 | " Capacity [MB]:\t%-6d \tType: \t%s\n", |
461 | pai->ai_size/(1024*1024/pai->ai_secsize), | |
462 | hrec); | |
1da177e4 LT |
463 | } |
464 | } | |
8d22022c | 465 | |
3e0552ee | 466 | if (!flag) |
91c40f24 | 467 | seq_puts(m, "\n --\n"); |
1da177e4 LT |
468 | |
469 | /* 5. about host drives */ | |
91c40f24 | 470 | seq_puts(m, "\nHost Drives:"); |
1da177e4 LT |
471 | flag = FALSE; |
472 | ||
1da177e4 LT |
473 | for (i = 0; i < MAX_LDRIVES; ++i) { |
474 | if (!ha->hdr[i].is_logdrv || | |
475 | (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master)) | |
476 | continue; | |
477 | /* 5.a get host drive list */ | |
478 | TRACE2(("host_get() drv_no %d\n",i)); | |
479 | phg = (gdth_hget_str *)buf; | |
480 | gdtcmd->Service = CACHESERVICE; | |
481 | gdtcmd->OpCode = GDT_IOCTL; | |
482 | gdtcmd->u.ioctl.p_param = paddr; | |
483 | gdtcmd->u.ioctl.param_size = sizeof(gdth_hget_str); | |
484 | gdtcmd->u.ioctl.subfunc = HOST_GET | LA_CTRL_PATTERN; | |
485 | gdtcmd->u.ioctl.channel = i; | |
486 | phg->entries = MAX_HDRIVES; | |
487 | phg->offset = GDTOFFSOF(gdth_hget_str, entry[0]); | |
cbd5f69b | 488 | if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) { |
1da177e4 LT |
489 | ha->hdr[i].ldr_no = i; |
490 | ha->hdr[i].rw_attribs = 0; | |
491 | ha->hdr[i].start_sec = 0; | |
492 | } else { | |
493 | for (j = 0; j < phg->entries; ++j) { | |
494 | k = phg->entry[j].host_drive; | |
495 | if (k >= MAX_LDRIVES) | |
496 | continue; | |
497 | ha->hdr[k].ldr_no = phg->entry[j].log_drive; | |
498 | ha->hdr[k].rw_attribs = phg->entry[j].rw_attribs; | |
499 | ha->hdr[k].start_sec = phg->entry[j].start_sec; | |
500 | } | |
501 | } | |
502 | } | |
8d22022c | 503 | gdth_ioctl_free(ha, size, buf, paddr); |
1da177e4 LT |
504 | |
505 | for (i = 0; i < MAX_HDRIVES; ++i) { | |
506 | if (!(ha->hdr[i].present)) | |
507 | continue; | |
508 | ||
3e0552ee | 509 | seq_printf(m, |
1da177e4 LT |
510 | "\n Number: \t%-2d \tArr/Log. Drive:\t%d\n", |
511 | i, ha->hdr[i].ldr_no); | |
1da177e4 LT |
512 | flag = TRUE; |
513 | ||
3e0552ee | 514 | seq_printf(m, |
1da177e4 | 515 | " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n", |
1fe6dbf4 | 516 | (u32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec); |
1da177e4 LT |
517 | } |
518 | ||
3e0552ee | 519 | if (!flag) |
91c40f24 | 520 | seq_puts(m, "\n --\n"); |
1da177e4 LT |
521 | } |
522 | ||
523 | /* controller events */ | |
91c40f24 | 524 | seq_puts(m, "\nController Events:\n"); |
1da177e4 LT |
525 | |
526 | for (id = -1;;) { | |
527 | id = gdth_read_event(ha, id, estr); | |
528 | if (estr->event_source == 0) | |
529 | break; | |
45f1a41b | 530 | if (estr->event_data.eu.driver.ionode == ha->hanum && |
1da177e4 LT |
531 | estr->event_source == ES_ASYNC) { |
532 | gdth_log_event(&estr->event_data, hrec); | |
5a412c38 AS |
533 | |
534 | /* | |
535 | * Elapsed seconds subtraction with unsigned operands is | |
536 | * safe from wrap around in year 2106. Executes as: | |
537 | * operand a + (2's complement operand b) + 1 | |
538 | */ | |
539 | ||
540 | sec = (int)((u32)ktime_get_real_seconds() - estr->first_stamp); | |
1da177e4 | 541 | if (sec < 0) sec = 0; |
3e0552ee | 542 | seq_printf(m," date- %02d:%02d:%02d\t%s\n", |
1da177e4 | 543 | sec/3600, sec%3600/60, sec%60, hrec); |
1da177e4 LT |
544 | } |
545 | if (id == -1) | |
546 | break; | |
547 | } | |
1da177e4 | 548 | stop_output: |
3e0552ee | 549 | rc = 0; |
1da177e4 LT |
550 | free_fail: |
551 | kfree(gdtcmd); | |
552 | kfree(estr); | |
553 | return rc; | |
554 | } | |
555 | ||
45f1a41b | 556 | static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch, |
1fe6dbf4 | 557 | u64 *paddr) |
1da177e4 | 558 | { |
1fe6dbf4 | 559 | unsigned long flags; |
1da177e4 LT |
560 | char *ret_val; |
561 | ||
562 | if (size == 0) | |
563 | return NULL; | |
564 | ||
1da177e4 LT |
565 | spin_lock_irqsave(&ha->smp_lock, flags); |
566 | ||
567 | if (!ha->scratch_busy && size <= GDTH_SCRATCH) { | |
568 | ha->scratch_busy = TRUE; | |
569 | ret_val = ha->pscratch; | |
570 | *paddr = ha->scratch_phys; | |
571 | } else if (scratch) { | |
572 | ret_val = NULL; | |
573 | } else { | |
574 | dma_addr_t dma_addr; | |
575 | ||
576 | ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr); | |
577 | *paddr = dma_addr; | |
578 | } | |
579 | ||
580 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
581 | return ret_val; | |
582 | } | |
583 | ||
1fe6dbf4 | 584 | static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr) |
1da177e4 | 585 | { |
1fe6dbf4 | 586 | unsigned long flags; |
1da177e4 | 587 | |
1da177e4 | 588 | if (buf == ha->pscratch) { |
ff83efac | 589 | spin_lock_irqsave(&ha->smp_lock, flags); |
1da177e4 | 590 | ha->scratch_busy = FALSE; |
ff83efac | 591 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
1da177e4 LT |
592 | } else { |
593 | pci_free_consistent(ha->pdev, size, buf, paddr); | |
594 | } | |
1da177e4 LT |
595 | } |
596 | ||
597 | #ifdef GDTH_IOCTL_PROC | |
1fe6dbf4 | 598 | static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size) |
1da177e4 | 599 | { |
1fe6dbf4 | 600 | unsigned long flags; |
1da177e4 LT |
601 | int ret_val; |
602 | ||
1da177e4 LT |
603 | spin_lock_irqsave(&ha->smp_lock, flags); |
604 | ||
605 | ret_val = FALSE; | |
606 | if (ha->scratch_busy) { | |
1fe6dbf4 | 607 | if (((gdth_iord_str *)ha->pscratch)->size == (u32)size) |
1da177e4 LT |
608 | ret_val = TRUE; |
609 | } | |
610 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
611 | return ret_val; | |
612 | } | |
613 | #endif | |
614 | ||
45f1a41b | 615 | static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id) |
1da177e4 | 616 | { |
1fe6dbf4 | 617 | unsigned long flags; |
1da177e4 | 618 | int i; |
91ebc1fa | 619 | struct scsi_cmnd *scp; |
f842b64e | 620 | struct gdth_cmndinfo *cmndinfo; |
1fe6dbf4 | 621 | u8 b, t; |
1da177e4 | 622 | |
1da177e4 LT |
623 | spin_lock_irqsave(&ha->smp_lock, flags); |
624 | ||
625 | for (i = 0; i < GDTH_MAXCMDS; ++i) { | |
626 | scp = ha->cmd_tab[i].cmnd; | |
f842b64e | 627 | cmndinfo = gdth_cmnd_priv(scp); |
1da177e4 | 628 | |
52759e6a | 629 | b = scp->device->channel; |
1da177e4 | 630 | t = scp->device->id; |
1fe6dbf4 DJ |
631 | if (!SPECIAL_SCP(scp) && t == (u8)id && |
632 | b == (u8)busnum) { | |
f842b64e | 633 | cmndinfo->wait_for_completion = 0; |
1da177e4 | 634 | spin_unlock_irqrestore(&ha->smp_lock, flags); |
f842b64e | 635 | while (!cmndinfo->wait_for_completion) |
1da177e4 LT |
636 | barrier(); |
637 | spin_lock_irqsave(&ha->smp_lock, flags); | |
638 | } | |
639 | } | |
640 | spin_unlock_irqrestore(&ha->smp_lock, flags); | |
641 | } |