gdth_proc.c 22 KB

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