gdth_proc.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* gdth_proc.c
  3. * $Id: gdth_proc.c,v 1.43 2006/01/11 16:15:00 achim Exp $
  4. */
  5. #include <linux/completion.h>
  6. #include <linux/slab.h>
  7. int gdth_set_info(struct Scsi_Host *host, char *buffer, int length)
  8. {
  9. gdth_ha_str *ha = shost_priv(host);
  10. int ret_val = -EINVAL;
  11. TRACE2(("gdth_set_info() ha %d\n",ha->hanum,));
  12. if (length >= 4) {
  13. if (strncmp(buffer,"gdth",4) == 0) {
  14. buffer += 5;
  15. length -= 5;
  16. ret_val = gdth_set_asc_info(host, buffer, length, ha);
  17. }
  18. }
  19. return ret_val;
  20. }
  21. static int gdth_set_asc_info(struct Scsi_Host *host, char *buffer,
  22. int length, gdth_ha_str *ha)
  23. {
  24. int orig_length, drive, wb_mode;
  25. int i, found;
  26. gdth_cmd_str gdtcmd;
  27. gdth_cpar_str *pcpar;
  28. u64 paddr;
  29. char cmnd[MAX_COMMAND_SIZE];
  30. memset(cmnd, 0xff, 12);
  31. memset(&gdtcmd, 0, sizeof(gdth_cmd_str));
  32. TRACE2(("gdth_set_asc_info() ha %d\n",ha->hanum));
  33. orig_length = length + 5;
  34. drive = -1;
  35. wb_mode = 0;
  36. found = FALSE;
  37. if (length >= 5 && strncmp(buffer,"flush",5)==0) {
  38. buffer += 6;
  39. length -= 6;
  40. if (length && *buffer>='0' && *buffer<='9') {
  41. drive = (int)(*buffer-'0');
  42. ++buffer; --length;
  43. if (length && *buffer>='0' && *buffer<='9') {
  44. drive = drive*10 + (int)(*buffer-'0');
  45. ++buffer; --length;
  46. }
  47. printk("GDT: Flushing host drive %d .. ",drive);
  48. } else {
  49. printk("GDT: Flushing all host drives .. ");
  50. }
  51. for (i = 0; i < MAX_HDRIVES; ++i) {
  52. if (ha->hdr[i].present) {
  53. if (drive != -1 && i != drive)
  54. continue;
  55. found = TRUE;
  56. gdtcmd.Service = CACHESERVICE;
  57. gdtcmd.OpCode = GDT_FLUSH;
  58. if (ha->cache_feat & GDT_64BIT) {
  59. gdtcmd.u.cache64.DeviceNo = i;
  60. gdtcmd.u.cache64.BlockNo = 1;
  61. } else {
  62. gdtcmd.u.cache.DeviceNo = i;
  63. gdtcmd.u.cache.BlockNo = 1;
  64. }
  65. gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
  66. }
  67. }
  68. if (!found)
  69. printk("\nNo host drive found !\n");
  70. else
  71. printk("Done.\n");
  72. return(orig_length);
  73. }
  74. if (length >= 7 && strncmp(buffer,"wbp_off",7)==0) {
  75. buffer += 8;
  76. length -= 8;
  77. printk("GDT: Disabling write back permanently .. ");
  78. wb_mode = 1;
  79. } else if (length >= 6 && strncmp(buffer,"wbp_on",6)==0) {
  80. buffer += 7;
  81. length -= 7;
  82. printk("GDT: Enabling write back permanently .. ");
  83. wb_mode = 2;
  84. } else if (length >= 6 && strncmp(buffer,"wb_off",6)==0) {
  85. buffer += 7;
  86. length -= 7;
  87. printk("GDT: Disabling write back commands .. ");
  88. if (ha->cache_feat & GDT_WR_THROUGH) {
  89. gdth_write_through = TRUE;
  90. printk("Done.\n");
  91. } else {
  92. printk("Not supported !\n");
  93. }
  94. return(orig_length);
  95. } else if (length >= 5 && strncmp(buffer,"wb_on",5)==0) {
  96. buffer += 6;
  97. length -= 6;
  98. printk("GDT: Enabling write back commands .. ");
  99. gdth_write_through = FALSE;
  100. printk("Done.\n");
  101. return(orig_length);
  102. }
  103. if (wb_mode) {
  104. if (!gdth_ioctl_alloc(ha, sizeof(gdth_cpar_str), TRUE, &paddr))
  105. return(-EBUSY);
  106. pcpar = (gdth_cpar_str *)ha->pscratch;
  107. memcpy( pcpar, &ha->cpar, sizeof(gdth_cpar_str) );
  108. gdtcmd.Service = CACHESERVICE;
  109. gdtcmd.OpCode = GDT_IOCTL;
  110. gdtcmd.u.ioctl.p_param = paddr;
  111. gdtcmd.u.ioctl.param_size = sizeof(gdth_cpar_str);
  112. gdtcmd.u.ioctl.subfunc = CACHE_CONFIG;
  113. gdtcmd.u.ioctl.channel = INVALID_CHANNEL;
  114. pcpar->write_back = wb_mode==1 ? 0:1;
  115. gdth_execute(host, &gdtcmd, cmnd, 30, NULL);
  116. gdth_ioctl_free(ha, GDTH_SCRATCH, ha->pscratch, paddr);
  117. printk("Done.\n");
  118. return(orig_length);
  119. }
  120. printk("GDT: Unknown command: %s Length: %d\n",buffer,length);
  121. return(-EINVAL);
  122. }
  123. int gdth_show_info(struct seq_file *m, struct Scsi_Host *host)
  124. {
  125. gdth_ha_str *ha = shost_priv(host);
  126. int hlen;
  127. int id, i, j, k, sec, flag;
  128. int no_mdrv = 0, drv_no, is_mirr;
  129. u32 cnt;
  130. u64 paddr;
  131. int rc = -ENOMEM;
  132. gdth_cmd_str *gdtcmd;
  133. gdth_evt_str *estr;
  134. char hrec[277];
  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. /*
  491. * Elapsed seconds subtraction with unsigned operands is
  492. * safe from wrap around in year 2106. Executes as:
  493. * operand a + (2's complement operand b) + 1
  494. */
  495. sec = (int)((u32)ktime_get_real_seconds() - estr->first_stamp);
  496. if (sec < 0) sec = 0;
  497. seq_printf(m," date- %02d:%02d:%02d\t%s\n",
  498. sec/3600, sec%3600/60, sec%60, hrec);
  499. }
  500. if (id == -1)
  501. break;
  502. }
  503. stop_output:
  504. rc = 0;
  505. free_fail:
  506. kfree(gdtcmd);
  507. kfree(estr);
  508. return rc;
  509. }
  510. static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
  511. u64 *paddr)
  512. {
  513. unsigned long flags;
  514. char *ret_val;
  515. if (size == 0)
  516. return NULL;
  517. spin_lock_irqsave(&ha->smp_lock, flags);
  518. if (!ha->scratch_busy && size <= GDTH_SCRATCH) {
  519. ha->scratch_busy = TRUE;
  520. ret_val = ha->pscratch;
  521. *paddr = ha->scratch_phys;
  522. } else if (scratch) {
  523. ret_val = NULL;
  524. } else {
  525. dma_addr_t dma_addr;
  526. ret_val = pci_alloc_consistent(ha->pdev, size, &dma_addr);
  527. *paddr = dma_addr;
  528. }
  529. spin_unlock_irqrestore(&ha->smp_lock, flags);
  530. return ret_val;
  531. }
  532. static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, u64 paddr)
  533. {
  534. unsigned long flags;
  535. if (buf == ha->pscratch) {
  536. spin_lock_irqsave(&ha->smp_lock, flags);
  537. ha->scratch_busy = FALSE;
  538. spin_unlock_irqrestore(&ha->smp_lock, flags);
  539. } else {
  540. pci_free_consistent(ha->pdev, size, buf, paddr);
  541. }
  542. }
  543. #ifdef GDTH_IOCTL_PROC
  544. static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
  545. {
  546. unsigned long flags;
  547. int ret_val;
  548. spin_lock_irqsave(&ha->smp_lock, flags);
  549. ret_val = FALSE;
  550. if (ha->scratch_busy) {
  551. if (((gdth_iord_str *)ha->pscratch)->size == (u32)size)
  552. ret_val = TRUE;
  553. }
  554. spin_unlock_irqrestore(&ha->smp_lock, flags);
  555. return ret_val;
  556. }
  557. #endif
  558. static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
  559. {
  560. unsigned long flags;
  561. int i;
  562. struct scsi_cmnd *scp;
  563. struct gdth_cmndinfo *cmndinfo;
  564. u8 b, t;
  565. spin_lock_irqsave(&ha->smp_lock, flags);
  566. for (i = 0; i < GDTH_MAXCMDS; ++i) {
  567. scp = ha->cmd_tab[i].cmnd;
  568. cmndinfo = gdth_cmnd_priv(scp);
  569. b = scp->device->channel;
  570. t = scp->device->id;
  571. if (!SPECIAL_SCP(scp) && t == (u8)id &&
  572. b == (u8)busnum) {
  573. cmndinfo->wait_for_completion = 0;
  574. spin_unlock_irqrestore(&ha->smp_lock, flags);
  575. while (!cmndinfo->wait_for_completion)
  576. barrier();
  577. spin_lock_irqsave(&ha->smp_lock, flags);
  578. }
  579. }
  580. spin_unlock_irqrestore(&ha->smp_lock, flags);
  581. }