gdth_proc.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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. gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
  331. goto stop_output;
  332. }
  333. }
  334. }
  335. gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
  336. if (!flag) {
  337. size = sprintf(buffer+len, "\n --\n");
  338. len += size; pos = begin + len;
  339. }
  340. /* 3. about logical drives */
  341. size = sprintf(buffer+len,"\nLogical Drives:");
  342. len += size; pos = begin + len;
  343. flag = FALSE;
  344. buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
  345. if (!buf)
  346. goto stop_output;
  347. for (i = 0; i < MAX_LDRIVES; ++i) {
  348. if (!ha->hdr[i].is_logdrv)
  349. continue;
  350. drv_no = i;
  351. j = k = 0;
  352. is_mirr = FALSE;
  353. do {
  354. /* 3.a log. drive info */
  355. TRACE2(("cache_drv_info() drive no %d\n",drv_no));
  356. pcdi = (gdth_cdrinfo_str *)buf;
  357. gdtcmd->Service = CACHESERVICE;
  358. gdtcmd->OpCode = GDT_IOCTL;
  359. gdtcmd->u.ioctl.p_param = paddr;
  360. gdtcmd->u.ioctl.param_size = sizeof(gdth_cdrinfo_str);
  361. gdtcmd->u.ioctl.subfunc = CACHE_DRV_INFO;
  362. gdtcmd->u.ioctl.channel = drv_no;
  363. if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) != S_OK)
  364. break;
  365. pcdi->ld_dtype >>= 16;
  366. j++;
  367. if (pcdi->ld_dtype > 2) {
  368. strcpy(hrec, "missing");
  369. } else if (pcdi->ld_error & 1) {
  370. strcpy(hrec, "fault");
  371. } else if (pcdi->ld_error & 2) {
  372. strcpy(hrec, "invalid");
  373. k++; j--;
  374. } else {
  375. strcpy(hrec, "ok");
  376. }
  377. if (drv_no == i) {
  378. size = sprintf(buffer+len,
  379. "\n Number: \t%-2d \tStatus: \t%s\n",
  380. drv_no, hrec);
  381. len += size; pos = begin + len;
  382. flag = TRUE;
  383. no_mdrv = pcdi->cd_ldcnt;
  384. if (no_mdrv > 1 || pcdi->ld_slave != -1) {
  385. is_mirr = TRUE;
  386. strcpy(hrec, "RAID-1");
  387. } else if (pcdi->ld_dtype == 0) {
  388. strcpy(hrec, "Disk");
  389. } else if (pcdi->ld_dtype == 1) {
  390. strcpy(hrec, "RAID-0");
  391. } else if (pcdi->ld_dtype == 2) {
  392. strcpy(hrec, "Chain");
  393. } else {
  394. strcpy(hrec, "???");
  395. }
  396. size = sprintf(buffer+len,
  397. " Capacity [MB]:\t%-6d \tType: \t%s\n",
  398. pcdi->ld_blkcnt/(1024*1024/pcdi->ld_blksize),
  399. hrec);
  400. len += size; pos = begin + len;
  401. } else {
  402. size = sprintf(buffer+len,
  403. " Slave Number: \t%-2d \tStatus: \t%s\n",
  404. drv_no & 0x7fff, hrec);
  405. len += size; pos = begin + len;
  406. }
  407. drv_no = pcdi->ld_slave;
  408. if (pos < offset) {
  409. len = 0;
  410. begin = pos;
  411. }
  412. if (pos > offset + length) {
  413. gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
  414. goto stop_output;
  415. }
  416. } while (drv_no != -1);
  417. if (is_mirr) {
  418. size = sprintf(buffer+len,
  419. " Missing Drv.: \t%-2d \tInvalid Drv.: \t%d\n",
  420. no_mdrv - j - k, k);
  421. len += size; pos = begin + len;
  422. }
  423. if (!ha->hdr[i].is_arraydrv)
  424. strcpy(hrec, "--");
  425. else
  426. sprintf(hrec, "%d", ha->hdr[i].master_no);
  427. size = sprintf(buffer+len,
  428. " To Array Drv.:\t%s\n", hrec);
  429. len += size; pos = begin + len;
  430. if (pos < offset) {
  431. len = 0;
  432. begin = pos;
  433. }
  434. if (pos > offset + length) {
  435. gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
  436. goto stop_output;
  437. }
  438. }
  439. gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
  440. if (!flag) {
  441. size = sprintf(buffer+len, "\n --\n");
  442. len += size; pos = begin + len;
  443. }
  444. /* 4. about array drives */
  445. size = sprintf(buffer+len,"\nArray Drives:");
  446. len += size; pos = begin + len;
  447. flag = FALSE;
  448. buf = gdth_ioctl_alloc(ha, GDTH_SCRATCH, FALSE, &paddr);
  449. if (!buf)
  450. goto stop_output;
  451. for (i = 0; i < MAX_LDRIVES; ++i) {
  452. if (!(ha->hdr[i].is_arraydrv && ha->hdr[i].is_master))
  453. continue;
  454. /* 4.a array drive info */
  455. TRACE2(("array_info() drive no %d\n",i));
  456. pai = (gdth_arrayinf_str *)buf;
  457. gdtcmd->Service = CACHESERVICE;
  458. gdtcmd->OpCode = GDT_IOCTL;
  459. gdtcmd->u.ioctl.p_param = paddr;
  460. gdtcmd->u.ioctl.param_size = sizeof(gdth_arrayinf_str);
  461. gdtcmd->u.ioctl.subfunc = ARRAY_INFO | LA_CTRL_PATTERN;
  462. gdtcmd->u.ioctl.channel = i;
  463. if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
  464. if (pai->ai_state == 0)
  465. strcpy(hrec, "idle");
  466. else if (pai->ai_state == 2)
  467. strcpy(hrec, "build");
  468. else if (pai->ai_state == 4)
  469. strcpy(hrec, "ready");
  470. else if (pai->ai_state == 6)
  471. strcpy(hrec, "fail");
  472. else if (pai->ai_state == 8 || pai->ai_state == 10)
  473. strcpy(hrec, "rebuild");
  474. else
  475. strcpy(hrec, "error");
  476. if (pai->ai_ext_state & 0x10)
  477. strcat(hrec, "/expand");
  478. else if (pai->ai_ext_state & 0x1)
  479. strcat(hrec, "/patch");
  480. size = sprintf(buffer+len,
  481. "\n Number: \t%-2d \tStatus: \t%s\n",
  482. i,hrec);
  483. len += size; pos = begin + len;
  484. flag = TRUE;
  485. if (pai->ai_type == 0)
  486. strcpy(hrec, "RAID-0");
  487. else if (pai->ai_type == 4)
  488. strcpy(hrec, "RAID-4");
  489. else if (pai->ai_type == 5)
  490. strcpy(hrec, "RAID-5");
  491. else
  492. strcpy(hrec, "RAID-10");
  493. size = sprintf(buffer+len,
  494. " Capacity [MB]:\t%-6d \tType: \t%s\n",
  495. pai->ai_size/(1024*1024/pai->ai_secsize),
  496. hrec);
  497. len += size; pos = begin + len;
  498. if (pos < offset) {
  499. len = 0;
  500. begin = pos;
  501. }
  502. if (pos > offset + length) {
  503. gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
  504. goto stop_output;
  505. }
  506. }
  507. }
  508. gdth_ioctl_free(ha, GDTH_SCRATCH, buf, paddr);
  509. if (!flag) {
  510. size = sprintf(buffer+len, "\n --\n");
  511. len += size; pos = begin + len;
  512. }
  513. /* 5. about host drives */
  514. size = sprintf(buffer+len,"\nHost Drives:");
  515. len += size; pos = begin + len;
  516. flag = FALSE;
  517. buf = gdth_ioctl_alloc(ha, sizeof(gdth_hget_str), FALSE, &paddr);
  518. if (!buf)
  519. goto stop_output;
  520. for (i = 0; i < MAX_LDRIVES; ++i) {
  521. if (!ha->hdr[i].is_logdrv ||
  522. (ha->hdr[i].is_arraydrv && !ha->hdr[i].is_master))
  523. continue;
  524. /* 5.a get host drive list */
  525. TRACE2(("host_get() drv_no %d\n",i));
  526. phg = (gdth_hget_str *)buf;
  527. gdtcmd->Service = CACHESERVICE;
  528. gdtcmd->OpCode = GDT_IOCTL;
  529. gdtcmd->u.ioctl.p_param = paddr;
  530. gdtcmd->u.ioctl.param_size = sizeof(gdth_hget_str);
  531. gdtcmd->u.ioctl.subfunc = HOST_GET | LA_CTRL_PATTERN;
  532. gdtcmd->u.ioctl.channel = i;
  533. phg->entries = MAX_HDRIVES;
  534. phg->offset = GDTOFFSOF(gdth_hget_str, entry[0]);
  535. if (gdth_execute(host, gdtcmd, cmnd, 30, NULL) == S_OK) {
  536. ha->hdr[i].ldr_no = i;
  537. ha->hdr[i].rw_attribs = 0;
  538. ha->hdr[i].start_sec = 0;
  539. } else {
  540. for (j = 0; j < phg->entries; ++j) {
  541. k = phg->entry[j].host_drive;
  542. if (k >= MAX_LDRIVES)
  543. continue;
  544. ha->hdr[k].ldr_no = phg->entry[j].log_drive;
  545. ha->hdr[k].rw_attribs = phg->entry[j].rw_attribs;
  546. ha->hdr[k].start_sec = phg->entry[j].start_sec;
  547. }
  548. }
  549. }
  550. gdth_ioctl_free(ha, sizeof(gdth_hget_str), buf, paddr);
  551. for (i = 0; i < MAX_HDRIVES; ++i) {
  552. if (!(ha->hdr[i].present))
  553. continue;
  554. size = sprintf(buffer+len,
  555. "\n Number: \t%-2d \tArr/Log. Drive:\t%d\n",
  556. i, ha->hdr[i].ldr_no);
  557. len += size; pos = begin + len;
  558. flag = TRUE;
  559. size = sprintf(buffer+len,
  560. " Capacity [MB]:\t%-6d \tStart Sector: \t%d\n",
  561. (u32)(ha->hdr[i].size/2048), ha->hdr[i].start_sec);
  562. len += size; pos = begin + len;
  563. if (pos < offset) {
  564. len = 0;
  565. begin = pos;
  566. }
  567. if (pos > offset + length)
  568. goto stop_output;
  569. }
  570. if (!flag) {
  571. size = sprintf(buffer+len, "\n --\n");
  572. len += size; pos = begin + len;
  573. }
  574. }
  575. /* controller events */
  576. size = sprintf(buffer+len,"\nController Events:\n");
  577. len += size; pos = begin + len;
  578. for (id = -1;;) {
  579. id = gdth_read_event(ha, id, estr);
  580. if (estr->event_source == 0)
  581. break;
  582. if (estr->event_data.eu.driver.ionode == ha->hanum &&
  583. estr->event_source == ES_ASYNC) {
  584. gdth_log_event(&estr->event_data, hrec);
  585. do_gettimeofday(&tv);
  586. sec = (int)(tv.tv_sec - estr->first_stamp);
  587. if (sec < 0) sec = 0;
  588. size = sprintf(buffer+len," date- %02d:%02d:%02d\t%s\n",
  589. sec/3600, sec%3600/60, sec%60, hrec);
  590. len += size; pos = begin + len;
  591. if (pos < offset) {
  592. len = 0;
  593. begin = pos;
  594. }
  595. if (pos > offset + length)
  596. goto stop_output;
  597. }
  598. if (id == -1)
  599. break;
  600. }
  601. stop_output:
  602. *start = buffer +(offset-begin);
  603. len -= (offset-begin);
  604. if (len > length)
  605. len = length;
  606. TRACE2(("get_info() len %d pos %d begin %d offset %d length %d size %d\n",
  607. len,(int)pos,(int)begin,(int)offset,length,size));
  608. rc = len;
  609. free_fail:
  610. kfree(gdtcmd);
  611. kfree(estr);
  612. return rc;
  613. }
  614. static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
  615. u64 *paddr)
  616. {
  617. unsigned long flags;
  618. char *ret_val;
  619. if (size == 0)
  620. return NULL;
  621. spin_lock_irqsave(&ha->smp_lock, flags);
  622. if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
  623. ha->scratch_busy = TRUE;
  624. ret_val = ha->pscratch;
  625. *paddr = ha->scratch_phys;
  626. } else if (scratch) {
  627. ret_val = NULL;
  628. } else {
  629. dma_addr_t dma_addr;
  630. ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
  631. *paddr = dma_addr;
  632. }
  633. spin_unlock_irqrestore(&ha->smp_lock, flags);
  634. return ret_val;
  635. }
  636. static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr)
  637. {
  638. unsigned long flags;
  639. if (buf == ha->pscratch) {
  640. spin_lock_irqsave(&ha->smp_lock, flags);
  641. ha->scratch_busy = FALSE;
  642. spin_unlock_irqrestore(&ha->smp_lock, flags);
  643. } else {
  644. pci_free_consistent(ha->pdev, size, buf, paddr);
  645. }
  646. }
  647. #ifdef GDTH_IOCTL_PROC
  648. static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
  649. {
  650. unsigned long flags;
  651. int ret_val;
  652. spin_lock_irqsave(&ha->smp_lock, flags);
  653. ret_val = FALSE;
  654. if (ha->scratch_busy) {
  655. if (((gdth_iord_str *)ha->pscratch)->size == (u32)size)
  656. ret_val = TRUE;
  657. }
  658. spin_unlock_irqrestore(&ha->smp_lock, flags);
  659. return ret_val;
  660. }
  661. #endif
  662. static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
  663. {
  664. unsigned long flags;
  665. int i;
  666. Scsi_Cmnd *scp;
  667. struct gdth_cmndinfo *cmndinfo;
  668. u8 b, t;
  669. spin_lock_irqsave(&ha->smp_lock, flags);
  670. for (i = 0; i < GDTH_MAXCMDS; ++i) {
  671. scp = ha->cmd_tab[i].cmnd;
  672. cmndinfo = gdth_cmnd_priv(scp);
  673. b = scp->device->channel;
  674. t = scp->device->id;
  675. if (!SPECIAL_SCP(scp) && t == (u8)id &&
  676. b == (u8)busnum) {
  677. cmndinfo->wait_for_completion = 0;
  678. spin_unlock_irqrestore(&ha->smp_lock, flags);
  679. while (!cmndinfo->wait_for_completion)
  680. barrier();
  681. spin_lock_irqsave(&ha->smp_lock, flags);
  682. }
  683. }
  684. spin_unlock_irqrestore(&ha->smp_lock, flags);
  685. }