gdth_proc.c 26 KB

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