gdth_proc.c 22 KB

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