gdth_proc.c 30 KB

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