Blame view

drivers/scsi/gdth_proc.c 26.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /* gdth_proc.c 
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
2
   * $Id: gdth_proc.c,v 1.43 2006/01/11 16:15:00 achim Exp $
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
   */
  
  #include <linux/completion.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
6
  #include <linux/slab.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
  int gdth_proc_info(struct Scsi_Host *host, char *buffer,char **start,off_t offset,int length,   
                     int inout)
  {
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
11
      gdth_ha_str *ha = shost_priv(host);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
12
13
14
15
  
      TRACE2(("gdth_proc_info() length %d offs %d inout %d
  ",
              length,(int)offset,inout));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
      if (inout)
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
17
          return(gdth_set_info(buffer,length,host,ha));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
      else
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
19
          return(gdth_get_info(buffer,start,offset,length,host,ha));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
  
  static int gdth_set_info(char *buffer,int length,struct Scsi_Host *host,
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
23
                           gdth_ha_str *ha)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
  {
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
25
      int ret_val = -EINVAL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26

45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
27
28
      TRACE2(("gdth_set_info() ha %d
  ",ha->hanum,));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
33
  
      if (length >= 4) {
          if (strncmp(buffer,"gdth",4) == 0) {
              buffer += 5;
              length -= 5;
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
34
              ret_val = gdth_set_asc_info(host, buffer, length, ha);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
          }
      }
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
37

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
40
      return ret_val;
  }
           
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
41
  static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
42
                          int length, gdth_ha_str *ha)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  {
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
44
45
      int orig_length, drive, wb_mode;
      int i, found;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
47
      gdth_cmd_str    gdtcmd;
      gdth_cpar_str   *pcpar;
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
48
      u64         paddr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
51
52
  
      char            cmnd[MAX_COMMAND_SIZE];
      memset(cmnd, 0xff, 12);
      memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
53
54
      TRACE2(("gdth_set_asc_info() ha %d
  ",ha->hanum));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
      orig_length = length + 5;
      drive = -1;
      wb_mode = 0;
      found = FALSE;
  
      if (length >= 5 && strncmp(buffer,"flush",5)==0) {
          buffer += 6;
          length -= 6;
          if (length && *buffer>='0' && *buffer<='9') {
              drive = (int)(*buffer-'0');
              ++buffer; --length;
              if (length && *buffer>='0' && *buffer<='9') {
                  drive = drive*10 + (int)(*buffer-'0');
                  ++buffer; --length;
              }
              printk("GDT: Flushing host drive %d .. ",drive);
          } else {
              printk("GDT: Flushing all host drives .. ");
          }
          for (i = 0; i < MAX_HDRIVES; ++i) {
              if (ha->hdr[i].present) {
                  if (drive != -1 && i != drive)
                      continue;
                  found = TRUE;
                  gdtcmd.Service = CACHESERVICE;
                  gdtcmd.OpCode = GDT_FLUSH;
                  if (ha->cache_feat & GDT_64BIT) {
                      gdtcmd.u.cache64.DeviceNo = i;
                      gdtcmd.u.cache64.BlockNo = 1;
                  } else {
                      gdtcmd.u.cache.DeviceNo = i;
                      gdtcmd.u.cache.BlockNo = 1;
                  }
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
88
89
  
                  gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
              }
          }
          if (!found)
              printk("
  No host drive found !
  ");
          else
              printk("Done.
  ");
          return(orig_length);
      }
  
      if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {
          buffer += 8;
          length -= 8;
          printk("GDT: Disabling write back permanently .. ");
          wb_mode = 1;
      } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {
          buffer += 7;
          length -= 7;
          printk("GDT: Enabling write back permanently .. ");
          wb_mode = 2;
      } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {
          buffer += 7;
          length -= 7;
          printk("GDT: Disabling write back commands .. ");
          if (ha->cache_feat & GDT_WR_THROUGH) {
              gdth_write_through = TRUE;
              printk("Done.
  ");
          } else {
              printk("Not supported !
  ");
          }
          return(orig_length);
      } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {
          buffer += 6;
          length -= 6;
          printk("GDT: Enabling write back commands .. ");
          gdth_write_through = FALSE;
          printk("Done.
  ");
          return(orig_length);
      }
  
      if (wb_mode) {
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
136
          if (!gdth_ioctl_alloc(ha, sizeof(gdth_cpar_str), TRUE, &paddr))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
138
139
140
141
142
143
144
145
146
              return(-EBUSY);
          pcpar = (gdth_cpar_str *)ha->pscratch;
          memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );
          gdtcmd.Service = CACHESERVICE;
          gdtcmd.OpCode = GDT_IOCTL;
          gdtcmd.u.ioctl.p_param = paddr;
          gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
          gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
          gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
          pcpar->write_back = wb_mode==1 ? 0:1;
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
147
148
  
          gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
149
          gdth_ioctl_free(ha, GDTH_SCRATCH, ha->pscratch, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
151
152
153
154
155
156
157
158
159
160
          printk("Done.
  ");
          return(orig_length);
      }
  
      printk("GDT: Unknown command: %s  Length: %d
  ",buffer,length);
      return(-EINVAL);
  }
  
  static int gdth_get_info(char *buffer,char **start,off_t offset,int length,
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
161
                           struct Scsi_Host *host, gdth_ha_str *ha)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
162
163
  {
      int size = 0,len = 0;
238ddbb98   Alan Cox   [SCSI] gdth: fix ...
164
      int hlen;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
      off_t begin = 0,pos = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
166
167
      int id, i, j, k, sec, flag;
      int no_mdrv = 0, drv_no, is_mirr;
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
168
169
      u32 cnt;
      u64 paddr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
171
172
173
      int rc = -ENOMEM;
  
      gdth_cmd_str *gdtcmd;
      gdth_evt_str *estr;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
      char hrec[161];
      struct timeval tv;
  
      char *buf;
      gdth_dskstat_str *pds;
      gdth_diskinfo_str *pdi;
      gdth_arrayinf_str *pai;
      gdth_defcnt_str *pdef;
      gdth_cdrinfo_str *pcdi;
      gdth_hget_str *phg;
      char cmnd[MAX_COMMAND_SIZE];
  
      gdtcmd = kmalloc(sizeof(*gdtcmd), GFP_KERNEL);
      estr = kmalloc(sizeof(*estr), GFP_KERNEL);
      if (!gdtcmd || !estr)
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
189
          goto free_fail;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
191
192
  
      memset(cmnd, 0xff, 12);
      memset(gdtcmd, 0, sizeof(gdth_cmd_str));
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
193
194
      TRACE2(("gdth_get_info() ha %d
  ",ha->hanum));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
197
198
199
200
201
202
203
204
205
      
      /* request is i.e. "cat /proc/scsi/gdth/0" */ 
      /* format: %-15s\t%-10s\t%-15s\t%s */
      /* driver parameters */
      size = sprintf(buffer+len,"Driver Parameters:
  ");
      len += size;  pos = begin + len;
      if (reserve_list[0] == 0xff)
          strcpy(hrec, "--");
      else {
238ddbb98   Alan Cox   [SCSI] gdth: fix ...
206
          hlen = sprintf(hrec, "%d", reserve_list[0]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
          for (i = 1;  i < MAX_RES_ARGS; i++) {
              if (reserve_list[i] == 0xff) 
                  break;
238ddbb98   Alan Cox   [SCSI] gdth: fix ...
210
              hlen += snprintf(hrec + hlen , 161 - hlen, ",%d", reserve_list[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
          }
      }
      size = sprintf(buffer+len,
                     " reserve_mode: \t%d         \treserve_list:  \t%s
  ",
                     reserve_mode, hrec);
      len += size;  pos = begin + len;
      size = sprintf(buffer+len,
                     " max_ids:      \t%-3d       \thdr_channel:   \t%d
  ",
                     max_ids, hdr_channel);
      len += size;  pos = begin + len;
  
      /* controller information */
      size = sprintf(buffer+len,"
  Disk Array Controller Information:
  ");
      len += size;  pos = begin + len;
52759e6ab   Christoph Hellwig   [SCSI] gdth: Remo...
229
      strcpy(hrec, ha->binfo.type_string);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
232
      size = sprintf(buffer+len,
                     " Number:       \t%d         \tName:          \t%s
  ",
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
233
                     ha->hanum, hrec);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
236
237
      len += size;  pos = begin + len;
  
      if (ha->more_proc)
          sprintf(hrec, "%d.%02d.%02d-%c%03X", 
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
238
239
240
                  (u8)(ha->binfo.upd_fw_ver>>24),
                  (u8)(ha->binfo.upd_fw_ver>>16),
                  (u8)(ha->binfo.upd_fw_ver),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241
242
243
                  ha->bfeat.raid ? 'R':'N',
                  ha->binfo.upd_revision);
      else
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
244
245
          sprintf(hrec, "%d.%02d", (u8)(ha->cpar.version>>8),
                  (u8)(ha->cpar.version));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
  
      size = sprintf(buffer+len,
                     " Driver Ver.:  \t%-10s\tFirmware Ver.: \t%s
  ",
                     GDTH_VERSION_STR, hrec);
      len += size;  pos = begin + len;
   
      if (ha->more_proc) {
          /* more information: 1. about controller */
          size = sprintf(buffer+len,
                         " Serial No.:   \t0x%8X\tCache RAM size:\t%d KB
  ",
                         ha->binfo.ser_no, ha->binfo.memsize / 1024);
          len += size;  pos = begin + len;
      }
  
  #ifdef GDTH_DMA_STATISTICS
      /* controller statistics */
      size = sprintf(buffer+len,"
  Controller Statistics:
  ");
      len += size;  pos = begin + len;
      size = sprintf(buffer+len,
                     " 32-bit DMA buffer:\t%lu\t64-bit DMA buffer:\t%lu
  ",
                     ha->dma32_cnt, ha->dma64_cnt);
      len += size;  pos = begin + len;
  #endif
  
      if (pos < offset) {
          len = 0;
          begin = pos;
      }
      if (pos > offset + length)
          goto stop_output;
  
      if (ha->more_proc) {
          /* more information: 2. about physical devices */
          size = sprintf(buffer+len,"
  Physical Devices:");
          len += size;  pos = begin + len;
          flag = FALSE;
              
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
289
          buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
          if (!buf) 
              goto stop_output;
          for (i = 0; i < ha->bus_cnt; ++i) {
              /* 2.a statistics (and retries/reassigns) */
              TRACE2(("pdr_statistics() chn %d
  ",i));                
              pds = (gdth_dskstat_str *)(buf + GDTH_SCRATCH/4);
              gdtcmd->Service = CACHESERVICE;
              gdtcmd->OpCode = GDT_IOCTL;
              gdtcmd->u.ioctl.p_param = paddr + GDTH_SCRATCH/4;
              gdtcmd->u.ioctl.param_size = 3*GDTH_SCRATCH/4;
              gdtcmd->u.ioctl.subfunc = DSK_STATISTICS | L_CTRL_PATTERN;
              gdtcmd->u.ioctl.channel = ha->raw[i].address | INVALID_CHANNEL;
              pds->bid = ha->raw[i].local_no;
              pds->first = 0;
              pds->entries = ha->raw[i].pdev_cnt;
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
306
              cnt = (3*GDTH_SCRATCH/4 - 5 * sizeof(u32)) /
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
308
309
                  sizeof(pds->list[0]);
              if (pds->entries > cnt)
                  pds->entries = cnt;
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
310
311
  
              if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
312
                  pds->count = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  
              /* other IOCTLs must fit into area GDTH_SCRATCH/4 */
              for (j = 0; j < ha->raw[i].pdev_cnt; ++j) {
                  /* 2.b drive info */
                  TRACE2(("scsi_drv_info() chn %d dev %d
  ",
                      i, ha->raw[i].id_list[j]));             
                  pdi = (gdth_diskinfo_str *)buf;
                  gdtcmd->Service = CACHESERVICE;
                  gdtcmd->OpCode = GDT_IOCTL;
                  gdtcmd->u.ioctl.p_param = paddr;
                  gdtcmd->u.ioctl.param_size = sizeof(gdth_diskinfo_str);
                  gdtcmd->u.ioctl.subfunc = SCSI_DR_INFO | L_CTRL_PATTERN;
                  gdtcmd->u.ioctl.channel = 
                      ha->raw[i].address | ha->raw[i].id_list[j];
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
328
329
  
                  if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
                      strncpy(hrec,pdi->vendor,8);
                      strncpy(hrec+8,pdi->product,16);
                      strncpy(hrec+24,pdi->revision,4);
                      hrec[28] = 0;
                      size = sprintf(buffer+len,
                                     "
   Chn/ID/LUN:   \t%c/%02d/%d    \tName:          \t%s
  ",
                                     'A'+i,pdi->target_id,pdi->lun,hrec);
                      len += size;  pos = begin + len;
                      flag = TRUE;
                      pdi->no_ldrive &= 0xffff;
                      if (pdi->no_ldrive == 0xffff)
                          strcpy(hrec,"--");
                      else
                          sprintf(hrec,"%d",pdi->no_ldrive);
                      size = sprintf(buffer+len,
                                     " Capacity [MB]:\t%-6d    \tTo Log. Drive: \t%s
  ",
                                     pdi->blkcnt/(1024*1024/pdi->blksize),
                                     hrec);
                      len += size;  pos = begin + len;
                  } else {
                      pdi->devtype = 0xff;
                  }
                      
                  if (pdi->devtype == 0) {
                      /* search retries/reassigns */
                      for (k = 0; k < pds->count; ++k) {
                          if (pds->list[k].tid == pdi->target_id &&
                              pds->list[k].lun == pdi->lun) {
                              size = sprintf(buffer+len,
                                             " Retries:      \t%-6d    \tReassigns:     \t%d
  ",
                                             pds->list[k].retries,
                                             pds->list[k].reassigns);
                              len += size;  pos = begin + len;
                              break;
                          }
                      }
                      /* 2.c grown defects */
                      TRACE2(("scsi_drv_defcnt() chn %d dev %d
  ",
                              i, ha->raw[i].id_list[j]));             
                      pdef = (gdth_defcnt_str *)buf;
                      gdtcmd->Service = CACHESERVICE;
                      gdtcmd->OpCode = GDT_IOCTL;
                      gdtcmd->u.ioctl.p_param = paddr;
                      gdtcmd->u.ioctl.param_size = sizeof(gdth_defcnt_str);
                      gdtcmd->u.ioctl.subfunc = SCSI_DEF_CNT | L_CTRL_PATTERN;
                      gdtcmd->u.ioctl.channel = 
                          ha->raw[i].address | ha->raw[i].id_list[j];
                      pdef->sddc_type = 0x08;
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
383
384
  
                      if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
385
386
387
388
389
390
391
392
393
394
395
                          size = sprintf(buffer+len,
                                         " Grown Defects:\t%d
  ",
                                         pdef->sddc_cnt);
                          len += size;  pos = begin + len;
                      }
                  }
                  if (pos < offset) {
                      len = 0;
                      begin = pos;
                  }
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
396
397
  		if (pos > offset + length) {
  		    gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
398
                      goto stop_output;
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
399
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
              }
          }
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
402
          gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
403
404
405
406
407
408
409
410
411
412
413
414
415
  
          if (!flag) {
              size = sprintf(buffer+len, "
   --
  ");
              len += size;  pos = begin + len;
          }
  
          /* 3. about logical drives */
          size = sprintf(buffer+len,"
  Logical Drives:");
          len += size;  pos = begin + len;
          flag = FALSE;
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
416
          buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
          if (!buf) 
              goto stop_output;
          for (i = 0; i < MAX_LDRIVES; ++i) {
              if (!ha->hdr[i].is_logdrv)
                  continue;
              drv_no = i;
              j = k = 0;
              is_mirr = FALSE;
              do {
                  /* 3.a log. drive info */
                  TRACE2(("cache_drv_info() drive no %d
  ",drv_no));
                  pcdi = (gdth_cdrinfo_str *)buf;
                  gdtcmd->Service = CACHESERVICE;
                  gdtcmd->OpCode = GDT_IOCTL;
                  gdtcmd->u.ioctl.p_param = paddr;
                  gdtcmd->u.ioctl.param_size = sizeof(gdth_cdrinfo_str);
                  gdtcmd->u.ioctl.subfunc = CACHE_DRV_INFO;
                  gdtcmd->u.ioctl.channel = drv_no;
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
436
                  if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
437
                      break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
                  pcdi->ld_dtype >>= 16;
                  j++;
                  if (pcdi->ld_dtype > 2) {
                      strcpy(hrec, "missing");
                  } else if (pcdi->ld_error & 1) {
                      strcpy(hrec, "fault");
                  } else if (pcdi->ld_error & 2) {
                      strcpy(hrec, "invalid");
                      k++; j--;
                  } else {
                      strcpy(hrec, "ok");
                  }
                      
                  if (drv_no == i) {
                      size = sprintf(buffer+len,
                                     "
   Number:       \t%-2d        \tStatus:        \t%s
  ",
                                     drv_no, hrec);
                      len += size;  pos = begin + len;
                      flag = TRUE;
                      no_mdrv = pcdi->cd_ldcnt;
                      if (no_mdrv > 1 || pcdi->ld_slave != -1) {
                          is_mirr = TRUE;
                          strcpy(hrec, "RAID-1");
                      } else if (pcdi->ld_dtype == 0) {
                          strcpy(hrec, "Disk");
                      } else if (pcdi->ld_dtype == 1) {
                          strcpy(hrec, "RAID-0");
                      } else if (pcdi->ld_dtype == 2) {
                          strcpy(hrec, "Chain");
                      } else {
                          strcpy(hrec, "???");
                      }
                      size = sprintf(buffer+len,
                                     " Capacity [MB]:\t%-6d    \tType:          \t%s
  ",
                                     pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize),
                                     hrec);
                      len += size;  pos = begin + len;
                  } else {
                      size = sprintf(buffer+len,
                                     " Slave Number: \t%-2d        \tStatus:        \t%s
  ",
                                     drv_no & 0x7fff, hrec);
                      len += size;  pos = begin + len;
                  }
                  drv_no = pcdi->ld_slave;
                  if (pos < offset) {
                      len = 0;
                      begin = pos;
                  }
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
490
491
  		if (pos > offset + length) {
  		    gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
492
                      goto stop_output;
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
493
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
              } while (drv_no != -1);
               
              if (is_mirr) {
                  size = sprintf(buffer+len,
                                 " Missing Drv.: \t%-2d        \tInvalid Drv.:  \t%d
  ",
                                 no_mdrv - j - k, k);
                  len += size;  pos = begin + len;
              }
                
              if (!ha->hdr[i].is_arraydrv)
                  strcpy(hrec, "--");
              else
                  sprintf(hrec, "%d", ha->hdr[i].master_no);
              size = sprintf(buffer+len,
                             " To Array Drv.:\t%s
  ", hrec);
              len += size;  pos = begin + len;
              if (pos < offset) {
                  len = 0;
                  begin = pos;
              }
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
516
517
  	    if (pos > offset + length) {
  		gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
518
                  goto stop_output;
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
519
  	    }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
520
          }       
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
521
          gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
522
523
524
525
526
527
528
529
530
531
532
533
534
          
          if (!flag) {
              size = sprintf(buffer+len, "
   --
  ");
              len += size;  pos = begin + len;
          }   
  
          /* 4. about array drives */
          size = sprintf(buffer+len,"
  Array Drives:");
          len += size;  pos = begin + len;
          flag = FALSE;
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
535
          buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
          if (!buf) 
              goto stop_output;
          for (i = 0; i < MAX_LDRIVES; ++i) {
              if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
                  continue;
              /* 4.a array drive info */
              TRACE2(("array_info() drive no %d
  ",i));
              pai = (gdth_arrayinf_str *)buf;
              gdtcmd->Service = CACHESERVICE;
              gdtcmd->OpCode = GDT_IOCTL;
              gdtcmd->u.ioctl.p_param = paddr;
              gdtcmd->u.ioctl.param_size = sizeof(gdth_arrayinf_str);
              gdtcmd->u.ioctl.subfunc = ARRAY_INFO | LA_CTRL_PATTERN;
              gdtcmd->u.ioctl.channel = i;
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
551
              if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
                  if (pai->ai_state == 0)
                      strcpy(hrec, "idle");
                  else if (pai->ai_state == 2)
                      strcpy(hrec, "build");
                  else if (pai->ai_state == 4)
                      strcpy(hrec, "ready");
                  else if (pai->ai_state == 6)
                      strcpy(hrec, "fail");
                  else if (pai->ai_state == 8 || pai->ai_state == 10)
                      strcpy(hrec, "rebuild");
                  else
                      strcpy(hrec, "error");
                  if (pai->ai_ext_state & 0x10)
                      strcat(hrec, "/expand");
                  else if (pai->ai_ext_state & 0x1)
                      strcat(hrec, "/patch");
                  size = sprintf(buffer+len,
                                 "
   Number:       \t%-2d        \tStatus:        \t%s
  ",
                                 i,hrec);
                  len += size;  pos = begin + len;
                  flag = TRUE;
  
                  if (pai->ai_type == 0)
                      strcpy(hrec, "RAID-0");
                  else if (pai->ai_type == 4)
                      strcpy(hrec, "RAID-4");
                  else if (pai->ai_type == 5)
                      strcpy(hrec, "RAID-5");
                  else 
                      strcpy(hrec, "RAID-10");
                  size = sprintf(buffer+len,
                                 " Capacity [MB]:\t%-6d    \tType:          \t%s
  ",
                                 pai->ai_size/(1024*1024/pai->ai_secsize),
                                 hrec);
                  len += size;  pos = begin + len;
                  if (pos < offset) {
                      len = 0;
                      begin = pos;
                  }
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
594
595
  		if (pos > offset + length) {
  		    gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
596
                      goto stop_output;
5c1000756   Julia Lawall   [SCSI] gdth: Add ...
597
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
598
599
              }
          }
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
600
          gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
601
602
603
604
605
606
607
608
609
610
611
612
613
          
          if (!flag) {
              size = sprintf(buffer+len, "
   --
  ");
              len += size;  pos = begin + len;
          }
  
          /* 5. about host drives */
          size = sprintf(buffer+len,"
  Host Drives:");
          len += size;  pos = begin + len;
          flag = FALSE;
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
614
          buf = gdth_ioctl_alloc(ha, sizeof(gdth_hget_str), FALSE, &paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
          if (!buf) 
              goto stop_output;
          for (i = 0; i < MAX_LDRIVES; ++i) {
              if (!ha->hdr[i].is_logdrv || 
                  (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
                  continue;
              /* 5.a get host drive list */
              TRACE2(("host_get() drv_no %d
  ",i));           
              phg = (gdth_hget_str *)buf;
              gdtcmd->Service = CACHESERVICE;
              gdtcmd->OpCode = GDT_IOCTL;
              gdtcmd->u.ioctl.p_param = paddr;
              gdtcmd->u.ioctl.param_size = sizeof(gdth_hget_str);
              gdtcmd->u.ioctl.subfunc = HOST_GET | LA_CTRL_PATTERN;
              gdtcmd->u.ioctl.channel = i;
              phg->entries = MAX_HDRIVES;
              phg->offset = GDTOFFSOF(gdth_hget_str, entry[0]); 
cbd5f69b9   Leubner, Achim   [SCSI] remove the...
633
              if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634
635
636
637
638
639
640
641
642
643
644
645
646
647
                  ha->hdr[i].ldr_no = i;
                  ha->hdr[i].rw_attribs = 0;
                  ha->hdr[i].start_sec = 0;
              } else {
                  for (j = 0; j < phg->entries; ++j) {
                      k = phg->entry[j].host_drive;
                      if (k >= MAX_LDRIVES)
                          continue;
                      ha->hdr[k].ldr_no = phg->entry[j].log_drive;
                      ha->hdr[k].rw_attribs = phg->entry[j].rw_attribs;
                      ha->hdr[k].start_sec = phg->entry[j].start_sec;
                  }
              }
          }
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
648
          gdth_ioctl_free(ha, sizeof(gdth_hget_str), buf, paddr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
  
          for (i = 0; i < MAX_HDRIVES; ++i) {
              if (!(ha->hdr[i].present))
                  continue;
                
              size = sprintf(buffer+len,
                             "
   Number:       \t%-2d        \tArr/Log. Drive:\t%d
  ",
                             i, ha->hdr[i].ldr_no);
              len += size;  pos = begin + len;
              flag = TRUE;
  
              size = sprintf(buffer+len,
                             " Capacity [MB]:\t%-6d    \tStart Sector:  \t%d
  ",
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
665
                             (u32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
              len += size;  pos = begin + len;
              if (pos < offset) {
                  len = 0;
                  begin = pos;
              }
              if (pos > offset + length)
                  goto stop_output;
          }
          
          if (!flag) {
              size = sprintf(buffer+len, "
   --
  ");
              len += size;  pos = begin + len;
          }
      }
  
      /* controller events */
      size = sprintf(buffer+len,"
  Controller Events:
  ");
      len += size;  pos = begin + len;
  
      for (id = -1;;) {
          id = gdth_read_event(ha, id, estr);
          if (estr->event_source == 0)
              break;
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
693
          if (estr->event_data.eu.driver.ionode == ha->hanum &&
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
              estr->event_source == ES_ASYNC) { 
              gdth_log_event(&estr->event_data, hrec);
              do_gettimeofday(&tv);
              sec = (int)(tv.tv_sec - estr->first_stamp);
              if (sec < 0) sec = 0;
              size = sprintf(buffer+len," date- %02d:%02d:%02d\t%s
  ",
                             sec/3600, sec%3600/60, sec%60, hrec);
              len += size;  pos = begin + len;
              if (pos < offset) {
                  len = 0;
                  begin = pos;
              }
              if (pos > offset + length)
                  goto stop_output;
          }
          if (id == -1)
              break;
      }
  
  stop_output:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
715
716
717
718
719
720
721
722
723
724
725
726
727
728
      *start = buffer +(offset-begin);
      len -= (offset-begin);
      if (len > length)
          len = length;
      TRACE2(("get_info() len %d pos %d begin %d offset %d length %d size %d
  ",
              len,(int)pos,(int)begin,(int)offset,length,size));
      rc = len;
  
  free_fail:
      kfree(gdtcmd);
      kfree(estr);
      return rc;
  }
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
729
  static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
730
                                u64 *paddr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
731
  {
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
732
      unsigned long flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
733
734
735
736
      char *ret_val;
  
      if (size == 0)
          return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
      spin_lock_irqsave(&ha->smp_lock, flags);
  
      if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
          ha->scratch_busy = TRUE;
          ret_val = ha->pscratch;
          *paddr = ha->scratch_phys;
      } else if (scratch) {
          ret_val = NULL;
      } else {
          dma_addr_t dma_addr;
  
          ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
          *paddr = dma_addr;
      }
  
      spin_unlock_irqrestore(&ha->smp_lock, flags);
      return ret_val;
  }
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
755
  static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
756
  {
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
757
      unsigned long flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
758

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
759
      if (buf == ha->pscratch) {
ff83efacf   James Bottomley   [SCSI] gdth: don'...
760
  	spin_lock_irqsave(&ha->smp_lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
761
          ha->scratch_busy = FALSE;
ff83efacf   James Bottomley   [SCSI] gdth: don'...
762
  	spin_unlock_irqrestore(&ha->smp_lock, flags);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
763
764
765
      } else {
          pci_free_consistent(ha->pdev, size, buf, paddr);
      }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
766
767
768
  }
  
  #ifdef GDTH_IOCTL_PROC
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
769
  static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
770
  {
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
771
      unsigned long flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
772
      int ret_val;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
773
774
775
776
      spin_lock_irqsave(&ha->smp_lock, flags);
  
      ret_val = FALSE;
      if (ha->scratch_busy) {
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
777
          if (((gdth_iord_str *)ha->pscratch)->size == (u32)size)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
778
779
780
781
782
783
              ret_val = TRUE;
      }
      spin_unlock_irqrestore(&ha->smp_lock, flags);
      return ret_val;
  }
  #endif
45f1a41b2   Boaz Harrosh   [SCSI] gdth: clea...
784
  static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
785
  {
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
786
      unsigned long flags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
787
788
      int i;
      Scsi_Cmnd *scp;
f842b64e0   Boaz Harrosh   [SCSI] gdth: Move...
789
      struct gdth_cmndinfo *cmndinfo;
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
790
      u8 b, t;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
791

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
792
793
794
795
      spin_lock_irqsave(&ha->smp_lock, flags);
  
      for (i = 0; i < GDTH_MAXCMDS; ++i) {
          scp = ha->cmd_tab[i].cmnd;
f842b64e0   Boaz Harrosh   [SCSI] gdth: Move...
796
          cmndinfo = gdth_cmnd_priv(scp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
797

52759e6ab   Christoph Hellwig   [SCSI] gdth: Remo...
798
          b = scp->device->channel;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
799
          t = scp->device->id;
1fe6dbf4d   Dave Jones   [SCSI] gdth: Conv...
800
801
          if (!SPECIAL_SCP(scp) && t == (u8)id && 
              b == (u8)busnum) {
f842b64e0   Boaz Harrosh   [SCSI] gdth: Move...
802
              cmndinfo->wait_for_completion = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
803
              spin_unlock_irqrestore(&ha->smp_lock, flags);
f842b64e0   Boaz Harrosh   [SCSI] gdth: Move...
804
              while (!cmndinfo->wait_for_completion)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
805
806
807
808
809
810
                  barrier();
              spin_lock_irqsave(&ha->smp_lock, flags);
          }
      }
      spin_unlock_irqrestore(&ha->smp_lock, flags);
  }