gdth_proc.c 29 KB

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