gdth_proc.c 28 KB

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