blob: be609db668075410bf5661fd2837bc13a8b64aa1 [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
Al Viro3e0552e2013-03-31 00:52:08 -04008int gdth_set_info(struct Scsi_Host *host, char *buffer, int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009{
Boaz Harrosh45f1a412007-10-02 23:05:53 +020010 gdth_ha_str *ha = shost_priv(host);
Leubner, Achimcbd5f692006-06-09 11:34:29 -070011 int ret_val = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Boaz Harrosh45f1a412007-10-02 23:05:53 +020013 TRACE2(("gdth_set_info() ha %d\n",ha->hanum,));
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15 if (length >= 4) {
16 if (strncmp(buffer,"gdth",4) == 0) {
17 buffer += 5;
18 length -= 5;
Boaz Harrosh45f1a412007-10-02 23:05:53 +020019 ret_val = gdth_set_asc_info(host, buffer, length, ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 }
21 }
Leubner, Achimcbd5f692006-06-09 11:34:29 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 return ret_val;
24}
25
Leubner, Achimcbd5f692006-06-09 11:34:29 -070026static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
Boaz Harrosh45f1a412007-10-02 23:05:53 +020027 int length, gdth_ha_str *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Leubner, Achimcbd5f692006-06-09 11:34:29 -070029 int orig_length, drive, wb_mode;
30 int i, found;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 gdth_cmd_str gdtcmd;
32 gdth_cpar_str *pcpar;
Dave Jones1fe6dbf2010-01-04 10:19:34 -050033 u64 paddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35 char cmnd[MAX_COMMAND_SIZE];
36 memset(cmnd, 0xff, 12);
37 memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
38
Boaz Harrosh45f1a412007-10-02 23:05:53 +020039 TRACE2(("gdth_set_asc_info() ha %d\n",ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 orig_length = length + 5;
41 drive = -1;
42 wb_mode = 0;
43 found = FALSE;
44
45 if (length >= 5 && strncmp(buffer,"flush",5)==0) {
46 buffer += 6;
47 length -= 6;
48 if (length && *buffer>='0' && *buffer<='9') {
49 drive = (int)(*buffer-'0');
50 ++buffer; --length;
51 if (length && *buffer>='0' && *buffer<='9') {
52 drive = drive*10 + (int)(*buffer-'0');
53 ++buffer; --length;
54 }
55 printk("GDT: Flushing host drive %d .. ",drive);
56 } else {
57 printk("GDT: Flushing all host drives .. ");
58 }
59 for (i = 0; i < MAX_HDRIVES; ++i) {
60 if (ha->hdr[i].present) {
61 if (drive != -1 && i != drive)
62 continue;
63 found = TRUE;
64 gdtcmd.Service = CACHESERVICE;
65 gdtcmd.OpCode = GDT_FLUSH;
66 if (ha->cache_feat & GDT_64BIT) {
67 gdtcmd.u.cache64.DeviceNo = i;
68 gdtcmd.u.cache64.BlockNo = 1;
69 } else {
70 gdtcmd.u.cache.DeviceNo = i;
71 gdtcmd.u.cache.BlockNo = 1;
72 }
Leubner, Achimcbd5f692006-06-09 11:34:29 -070073
74 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76 }
77 if (!found)
78 printk("\nNo host drive found !\n");
79 else
80 printk("Done.\n");
81 return(orig_length);
82 }
83
84 if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {
85 buffer += 8;
86 length -= 8;
87 printk("GDT: Disabling write back permanently .. ");
88 wb_mode = 1;
89 } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {
90 buffer += 7;
91 length -= 7;
92 printk("GDT: Enabling write back permanently .. ");
93 wb_mode = 2;
94 } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {
95 buffer += 7;
96 length -= 7;
97 printk("GDT: Disabling write back commands .. ");
98 if (ha->cache_feat & GDT_WR_THROUGH) {
99 gdth_write_through = TRUE;
100 printk("Done.\n");
101 } else {
102 printk("Not supported !\n");
103 }
104 return(orig_length);
105 } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {
106 buffer += 6;
107 length -= 6;
108 printk("GDT: Enabling write back commands .. ");
109 gdth_write_through = FALSE;
110 printk("Done.\n");
111 return(orig_length);
112 }
113
114 if (wb_mode) {
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200115 if (!gdth_ioctl_alloc(ha, sizeof(gdth_cpar_str), TRUE, &paddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 return(-EBUSY);
117 pcpar = (gdth_cpar_str *)ha->pscratch;
118 memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );
119 gdtcmd.Service = CACHESERVICE;
120 gdtcmd.OpCode = GDT_IOCTL;
121 gdtcmd.u.ioctl.p_param = paddr;
122 gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
123 gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
124 gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
125 pcpar->write_back = wb_mode==1 ? 0:1;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700126
127 gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
128
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200129 gdth_ioctl_free(ha, GDTH_SCRATCH, ha->pscratch, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 printk("Done.\n");
131 return(orig_length);
132 }
133
134 printk("GDT: Unknown command: %s Length: %d\n",buffer,length);
135 return(-EINVAL);
136}
137
Al Viro3e0552e2013-03-31 00:52:08 -0400138int gdth_show_info(struct seq_file *m, struct Scsi_Host *host)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Al Viro3e0552e2013-03-31 00:52:08 -0400140 gdth_ha_str *ha = shost_priv(host);
Alan Cox238ddbb2009-06-09 13:44:02 +0100141 int hlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 int id, i, j, k, sec, flag;
143 int no_mdrv = 0, drv_no, is_mirr;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500144 u32 cnt;
145 u64 paddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 int rc = -ENOMEM;
147
148 gdth_cmd_str *gdtcmd;
149 gdth_evt_str *estr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 char hrec[161];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 char *buf;
153 gdth_dskstat_str *pds;
154 gdth_diskinfo_str *pdi;
155 gdth_arrayinf_str *pai;
156 gdth_defcnt_str *pdef;
157 gdth_cdrinfo_str *pcdi;
158 gdth_hget_str *phg;
159 char cmnd[MAX_COMMAND_SIZE];
160
161 gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
162 estr = kmalloc(sizeof(*estr), GFP_KERNEL);
163 if (!gdtcmd || !estr)
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700164 goto free_fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 memset(cmnd, 0xff, 12);
167 memset(gdtcmd, 0, sizeof(gdth_cmd_str));
168
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200169 TRACE2(("gdth_get_info() ha %d\n",ha->hanum));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 /* request is i.e. "cat /proc/scsi/gdth/0" */
173 /* format: %-15s\t%-10s\t%-15s\t%s */
174 /* driver parameters */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100175 seq_puts(m, "Driver Parameters:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (reserve_list[0] == 0xff)
177 strcpy(hrec, "--");
178 else {
Alan Cox238ddbb2009-06-09 13:44:02 +0100179 hlen = sprintf(hrec, "%d", reserve_list[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 for (i = 1; i < MAX_RES_ARGS; i++) {
181 if (reserve_list[i] == 0xff)
182 break;
Alan Cox238ddbb2009-06-09 13:44:02 +0100183 hlen += snprintf(hrec + hlen , 161 - hlen, ",%d", reserve_list[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 }
185 }
Al Viro3e0552e2013-03-31 00:52:08 -0400186 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 " reserve_mode: \t%d \treserve_list: \t%s\n",
188 reserve_mode, hrec);
Al Viro3e0552e2013-03-31 00:52:08 -0400189 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 " max_ids: \t%-3d \thdr_channel: \t%d\n",
191 max_ids, hdr_channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 /* controller information */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100194 seq_puts(m, "\nDisk Array Controller Information:\n");
Al Viro3e0552e2013-03-31 00:52:08 -0400195 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 " Number: \t%d \tName: \t%s\n",
Al Viro3e0552e2013-03-31 00:52:08 -0400197 ha->hanum, ha->binfo.type_string);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Al Viro3e0552e2013-03-31 00:52:08 -0400199 seq_printf(m,
200 " Driver Ver.: \t%-10s\tFirmware Ver.: \t",
201 GDTH_VERSION_STR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (ha->more_proc)
Al Viro3e0552e2013-03-31 00:52:08 -0400203 seq_printf(m, "%d.%02d.%02d-%c%03X\n",
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500204 (u8)(ha->binfo.upd_fw_ver>>24),
205 (u8)(ha->binfo.upd_fw_ver>>16),
206 (u8)(ha->binfo.upd_fw_ver),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 ha->bfeat.raid ? 'R':'N',
208 ha->binfo.upd_revision);
209 else
Al Viro3e0552e2013-03-31 00:52:08 -0400210 seq_printf(m, "%d.%02d\n", (u8)(ha->cpar.version>>8),
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500211 (u8)(ha->cpar.version));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Al Viro3e0552e2013-03-31 00:52:08 -0400213 if (ha->more_proc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 /* more information: 1. about controller */
Al Viro3e0552e2013-03-31 00:52:08 -0400215 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 " Serial No.: \t0x%8X\tCache RAM size:\t%d KB\n",
217 ha->binfo.ser_no, ha->binfo.memsize / 1024);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219#ifdef GDTH_DMA_STATISTICS
220 /* controller statistics */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100221 seq_puts(m, "\nController Statistics:\n");
Al Viro3e0552e2013-03-31 00:52:08 -0400222 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu\n",
224 ha->dma32_cnt, ha->dma64_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225#endif
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (ha->more_proc) {
228 /* more information: 2. about physical devices */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100229 seq_puts(m, "\nPhysical Devices:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 flag = FALSE;
231
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200232 buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 if (!buf)
234 goto stop_output;
235 for (i = 0; i < ha->bus_cnt; ++i) {
236 /* 2.a statistics (and retries/reassigns) */
237 TRACE2(("pdr_statistics() chn %d\n",i));
238 pds = (gdth_dskstat_str *)(buf + GDTH_SCRATCH/4);
239 gdtcmd->Service = CACHESERVICE;
240 gdtcmd->OpCode = GDT_IOCTL;
241 gdtcmd->u.ioctl.p_param = paddr + GDTH_SCRATCH/4;
242 gdtcmd->u.ioctl.param_size = 3*GDTH_SCRATCH/4;
243 gdtcmd->u.ioctl.subfunc = DSK_STATISTICS | L_CTRL_PATTERN;
244 gdtcmd->u.ioctl.channel = ha->raw[i].address | INVALID_CHANNEL;
245 pds->bid = ha->raw[i].local_no;
246 pds->first = 0;
247 pds->entries = ha->raw[i].pdev_cnt;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500248 cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(u32)) /
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 sizeof(pds->list[0]);
250 if (pds->entries > cnt)
251 pds->entries = cnt;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700252
253 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 pds->count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 /* other IOCTLs must fit into area GDTH_SCRATCH/4 */
257 for (j = 0; j < ha->raw[i].pdev_cnt; ++j) {
258 /* 2.b drive info */
259 TRACE2(("scsi_drv_info() chn %d dev %d\n",
260 i, ha->raw[i].id_list[j]));
261 pdi = (gdth_diskinfo_str *)buf;
262 gdtcmd->Service = CACHESERVICE;
263 gdtcmd->OpCode = GDT_IOCTL;
264 gdtcmd->u.ioctl.p_param = paddr;
265 gdtcmd->u.ioctl.param_size = sizeof(gdth_diskinfo_str);
266 gdtcmd->u.ioctl.subfunc = SCSI_DR_INFO | L_CTRL_PATTERN;
267 gdtcmd->u.ioctl.channel =
268 ha->raw[i].address | ha->raw[i].id_list[j];
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700269
270 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 strncpy(hrec,pdi->vendor,8);
272 strncpy(hrec+8,pdi->product,16);
273 strncpy(hrec+24,pdi->revision,4);
274 hrec[28] = 0;
Al Viro3e0552e2013-03-31 00:52:08 -0400275 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 "\n Chn/ID/LUN: \t%c/%02d/%d \tName: \t%s\n",
277 'A'+i,pdi->target_id,pdi->lun,hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 flag = TRUE;
279 pdi->no_ldrive &= 0xffff;
280 if (pdi->no_ldrive == 0xffff)
281 strcpy(hrec,"--");
282 else
283 sprintf(hrec,"%d",pdi->no_ldrive);
Al Viro3e0552e2013-03-31 00:52:08 -0400284 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 " Capacity [MB]:\t%-6d \tTo Log. Drive: \t%s\n",
286 pdi->blkcnt/(1024*1024/pdi->blksize),
287 hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 } else {
289 pdi->devtype = 0xff;
290 }
291
292 if (pdi->devtype == 0) {
293 /* search retries/reassigns */
294 for (k = 0; k < pds->count; ++k) {
295 if (pds->list[k].tid == pdi->target_id &&
296 pds->list[k].lun == pdi->lun) {
Al Viro3e0552e2013-03-31 00:52:08 -0400297 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 " Retries: \t%-6d \tReassigns: \t%d\n",
299 pds->list[k].retries,
300 pds->list[k].reassigns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 break;
302 }
303 }
304 /* 2.c grown defects */
305 TRACE2(("scsi_drv_defcnt() chn %d dev %d\n",
306 i, ha->raw[i].id_list[j]));
307 pdef = (gdth_defcnt_str *)buf;
308 gdtcmd->Service = CACHESERVICE;
309 gdtcmd->OpCode = GDT_IOCTL;
310 gdtcmd->u.ioctl.p_param = paddr;
311 gdtcmd->u.ioctl.param_size = sizeof(gdth_defcnt_str);
312 gdtcmd->u.ioctl.subfunc = SCSI_DEF_CNT | L_CTRL_PATTERN;
313 gdtcmd->u.ioctl.channel =
314 ha->raw[i].address | ha->raw[i].id_list[j];
315 pdef->sddc_type = 0x08;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700316
317 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Al Viro3e0552e2013-03-31 00:52:08 -0400318 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 " Grown Defects:\t%d\n",
320 pdef->sddc_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 }
322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200325 gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Al Viro3e0552e2013-03-31 00:52:08 -0400327 if (!flag)
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100328 seq_puts(m, "\n --\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /* 3. about logical drives */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100331 seq_puts(m, "\nLogical Drives:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 flag = FALSE;
333
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200334 buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (!buf)
336 goto stop_output;
337 for (i = 0; i < MAX_LDRIVES; ++i) {
338 if (!ha->hdr[i].is_logdrv)
339 continue;
340 drv_no = i;
341 j = k = 0;
342 is_mirr = FALSE;
343 do {
344 /* 3.a log. drive info */
345 TRACE2(("cache_drv_info() drive no %d\n",drv_no));
346 pcdi = (gdth_cdrinfo_str *)buf;
347 gdtcmd->Service = CACHESERVICE;
348 gdtcmd->OpCode = GDT_IOCTL;
349 gdtcmd->u.ioctl.p_param = paddr;
350 gdtcmd->u.ioctl.param_size = sizeof(gdth_cdrinfo_str);
351 gdtcmd->u.ioctl.subfunc = CACHE_DRV_INFO;
352 gdtcmd->u.ioctl.channel = drv_no;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700353 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 pcdi->ld_dtype >>= 16;
356 j++;
357 if (pcdi->ld_dtype > 2) {
358 strcpy(hrec, "missing");
359 } else if (pcdi->ld_error & 1) {
360 strcpy(hrec, "fault");
361 } else if (pcdi->ld_error & 2) {
362 strcpy(hrec, "invalid");
363 k++; j--;
364 } else {
365 strcpy(hrec, "ok");
366 }
367
368 if (drv_no == i) {
Al Viro3e0552e2013-03-31 00:52:08 -0400369 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 "\n Number: \t%-2d \tStatus: \t%s\n",
371 drv_no, hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 flag = TRUE;
373 no_mdrv = pcdi->cd_ldcnt;
374 if (no_mdrv > 1 || pcdi->ld_slave != -1) {
375 is_mirr = TRUE;
376 strcpy(hrec, "RAID-1");
377 } else if (pcdi->ld_dtype == 0) {
378 strcpy(hrec, "Disk");
379 } else if (pcdi->ld_dtype == 1) {
380 strcpy(hrec, "RAID-0");
381 } else if (pcdi->ld_dtype == 2) {
382 strcpy(hrec, "Chain");
383 } else {
384 strcpy(hrec, "???");
385 }
Al Viro3e0552e2013-03-31 00:52:08 -0400386 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 " Capacity [MB]:\t%-6d \tType: \t%s\n",
388 pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize),
389 hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 } else {
Al Viro3e0552e2013-03-31 00:52:08 -0400391 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 " Slave Number: \t%-2d \tStatus: \t%s\n",
393 drv_no & 0x7fff, hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 }
395 drv_no = pcdi->ld_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 } while (drv_no != -1);
397
Al Viro3e0552e2013-03-31 00:52:08 -0400398 if (is_mirr)
399 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n",
401 no_mdrv - j - k, k);
Al Viro3e0552e2013-03-31 00:52:08 -0400402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 if (!ha->hdr[i].is_arraydrv)
404 strcpy(hrec, "--");
405 else
406 sprintf(hrec, "%d", ha->hdr[i].master_no);
Al Viro3e0552e2013-03-31 00:52:08 -0400407 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 " To Array Drv.:\t%s\n", hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200410 gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Al Viro3e0552e2013-03-31 00:52:08 -0400412 if (!flag)
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100413 seq_puts(m, "\n --\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
415 /* 4. about array drives */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100416 seq_puts(m, "\nArray Drives:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 flag = FALSE;
418
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200419 buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (!buf)
421 goto stop_output;
422 for (i = 0; i < MAX_LDRIVES; ++i) {
423 if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
424 continue;
425 /* 4.a array drive info */
426 TRACE2(("array_info() drive no %d\n",i));
427 pai = (gdth_arrayinf_str *)buf;
428 gdtcmd->Service = CACHESERVICE;
429 gdtcmd->OpCode = GDT_IOCTL;
430 gdtcmd->u.ioctl.p_param = paddr;
431 gdtcmd->u.ioctl.param_size = sizeof(gdth_arrayinf_str);
432 gdtcmd->u.ioctl.subfunc = ARRAY_INFO | LA_CTRL_PATTERN;
433 gdtcmd->u.ioctl.channel = i;
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700434 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 if (pai->ai_state == 0)
436 strcpy(hrec, "idle");
437 else if (pai->ai_state == 2)
438 strcpy(hrec, "build");
439 else if (pai->ai_state == 4)
440 strcpy(hrec, "ready");
441 else if (pai->ai_state == 6)
442 strcpy(hrec, "fail");
443 else if (pai->ai_state == 8 || pai->ai_state == 10)
444 strcpy(hrec, "rebuild");
445 else
446 strcpy(hrec, "error");
447 if (pai->ai_ext_state & 0x10)
448 strcat(hrec, "/expand");
449 else if (pai->ai_ext_state & 0x1)
450 strcat(hrec, "/patch");
Al Viro3e0552e2013-03-31 00:52:08 -0400451 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 "\n Number: \t%-2d \tStatus: \t%s\n",
453 i,hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 flag = TRUE;
455
456 if (pai->ai_type == 0)
457 strcpy(hrec, "RAID-0");
458 else if (pai->ai_type == 4)
459 strcpy(hrec, "RAID-4");
460 else if (pai->ai_type == 5)
461 strcpy(hrec, "RAID-5");
462 else
463 strcpy(hrec, "RAID-10");
Al Viro3e0552e2013-03-31 00:52:08 -0400464 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 " Capacity [MB]:\t%-6d \tType: \t%s\n",
466 pai->ai_size/(1024*1024/pai->ai_secsize),
467 hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
469 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200470 gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
Al Viro3e0552e2013-03-31 00:52:08 -0400472 if (!flag)
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100473 seq_puts(m, "\n --\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
475 /* 5. about host drives */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100476 seq_puts(m, "\nHost Drives:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 flag = FALSE;
478
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200479 buf = gdth_ioctl_alloc(ha, sizeof(gdth_hget_str), FALSE, &paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 if (!buf)
481 goto stop_output;
482 for (i = 0; i < MAX_LDRIVES; ++i) {
483 if (!ha->hdr[i].is_logdrv ||
484 (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
485 continue;
486 /* 5.a get host drive list */
487 TRACE2(("host_get() drv_no %d\n",i));
488 phg = (gdth_hget_str *)buf;
489 gdtcmd->Service = CACHESERVICE;
490 gdtcmd->OpCode = GDT_IOCTL;
491 gdtcmd->u.ioctl.p_param = paddr;
492 gdtcmd->u.ioctl.param_size = sizeof(gdth_hget_str);
493 gdtcmd->u.ioctl.subfunc = HOST_GET | LA_CTRL_PATTERN;
494 gdtcmd->u.ioctl.channel = i;
495 phg->entries = MAX_HDRIVES;
496 phg->offset = GDTOFFSOF(gdth_hget_str, entry[0]);
Leubner, Achimcbd5f692006-06-09 11:34:29 -0700497 if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 ha->hdr[i].ldr_no = i;
499 ha->hdr[i].rw_attribs = 0;
500 ha->hdr[i].start_sec = 0;
501 } else {
502 for (j = 0; j < phg->entries; ++j) {
503 k = phg->entry[j].host_drive;
504 if (k >= MAX_LDRIVES)
505 continue;
506 ha->hdr[k].ldr_no = phg->entry[j].log_drive;
507 ha->hdr[k].rw_attribs = phg->entry[j].rw_attribs;
508 ha->hdr[k].start_sec = phg->entry[j].start_sec;
509 }
510 }
511 }
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200512 gdth_ioctl_free(ha, sizeof(gdth_hget_str), buf, paddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513
514 for (i = 0; i < MAX_HDRIVES; ++i) {
515 if (!(ha->hdr[i].present))
516 continue;
517
Al Viro3e0552e2013-03-31 00:52:08 -0400518 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 "\n Number: \t%-2d \tArr/Log. Drive:\t%d\n",
520 i, ha->hdr[i].ldr_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 flag = TRUE;
522
Al Viro3e0552e2013-03-31 00:52:08 -0400523 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n",
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500525 (u32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527
Al Viro3e0552e2013-03-31 00:52:08 -0400528 if (!flag)
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100529 seq_puts(m, "\n --\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531
532 /* controller events */
Rasmus Villemoes91c40f22014-12-03 00:10:52 +0100533 seq_puts(m, "\nController Events:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
535 for (id = -1;;) {
536 id = gdth_read_event(ha, id, estr);
537 if (estr->event_source == 0)
538 break;
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200539 if (estr->event_data.eu.driver.ionode == ha->hanum &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 estr->event_source == ES_ASYNC) {
541 gdth_log_event(&estr->event_data, hrec);
Alison Schofield5a412c32016-02-17 21:29:34 -0800542
543 /*
544 * Elapsed seconds subtraction with unsigned operands is
545 * safe from wrap around in year 2106. Executes as:
546 * operand a + (2's complement operand b) + 1
547 */
548
549 sec = (int)((u32)ktime_get_real_seconds() - estr->first_stamp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (sec < 0) sec = 0;
Al Viro3e0552e2013-03-31 00:52:08 -0400551 seq_printf(m," date- %02d:%02d:%02d\t%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 sec/3600, sec%3600/60, sec%60, hrec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
554 if (id == -1)
555 break;
556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557stop_output:
Al Viro3e0552e2013-03-31 00:52:08 -0400558 rc = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559free_fail:
560 kfree(gdtcmd);
561 kfree(estr);
562 return rc;
563}
564
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200565static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500566 u64 *paddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500568 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 char *ret_val;
570
571 if (size == 0)
572 return NULL;
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 spin_lock_irqsave(&ha->smp_lock, flags);
575
576 if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
577 ha->scratch_busy = TRUE;
578 ret_val = ha->pscratch;
579 *paddr = ha->scratch_phys;
580 } else if (scratch) {
581 ret_val = NULL;
582 } else {
583 dma_addr_t dma_addr;
584
585 ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
586 *paddr = dma_addr;
587 }
588
589 spin_unlock_irqrestore(&ha->smp_lock, flags);
590 return ret_val;
591}
592
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500593static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500595 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 if (buf == ha->pscratch) {
James Bottomleyff83efac2008-02-17 11:24:51 -0600598 spin_lock_irqsave(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 ha->scratch_busy = FALSE;
James Bottomleyff83efac2008-02-17 11:24:51 -0600600 spin_unlock_irqrestore(&ha->smp_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 } else {
602 pci_free_consistent(ha->pdev, size, buf, paddr);
603 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606#ifdef GDTH_IOCTL_PROC
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500607static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500609 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 int ret_val;
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 spin_lock_irqsave(&ha->smp_lock, flags);
613
614 ret_val = FALSE;
615 if (ha->scratch_busy) {
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500616 if (((gdth_iord_str *)ha->pscratch)->size == (u32)size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 ret_val = TRUE;
618 }
619 spin_unlock_irqrestore(&ha->smp_lock, flags);
620 return ret_val;
621}
622#endif
623
Boaz Harrosh45f1a412007-10-02 23:05:53 +0200624static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500626 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 int i;
628 Scsi_Cmnd *scp;
Boaz Harroshf842b642007-10-02 23:16:01 +0200629 struct gdth_cmndinfo *cmndinfo;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500630 u8 b, t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 spin_lock_irqsave(&ha->smp_lock, flags);
633
634 for (i = 0; i < GDTH_MAXCMDS; ++i) {
635 scp = ha->cmd_tab[i].cmnd;
Boaz Harroshf842b642007-10-02 23:16:01 +0200636 cmndinfo = gdth_cmnd_priv(scp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Christoph Hellwig52759e62007-10-02 22:59:53 +0200638 b = scp->device->channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 t = scp->device->id;
Dave Jones1fe6dbf2010-01-04 10:19:34 -0500640 if (!SPECIAL_SCP(scp) && t == (u8)id &&
641 b == (u8)busnum) {
Boaz Harroshf842b642007-10-02 23:16:01 +0200642 cmndinfo->wait_for_completion = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 spin_unlock_irqrestore(&ha->smp_lock, flags);
Boaz Harroshf842b642007-10-02 23:16:01 +0200644 while (!cmndinfo->wait_for_completion)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 barrier();
646 spin_lock_irqsave(&ha->smp_lock, flags);
647 }
648 }
649 spin_unlock_irqrestore(&ha->smp_lock, flags);
650}