gdth_proc.c 26 KB

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