gdth_proc.c 26 KB

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