PageRenderTime 118ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/scsi/ipr.c

http://github.com/mirrors/linux
C | 10871 lines | 7151 code | 1373 blank | 2347 comment | 1069 complexity | 9130bd96bd4a171be93a408704b4f4ea MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * ipr.c -- driver for IBM Power Linux RAID adapters
  4. *
  5. * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
  6. *
  7. * Copyright (C) 2003, 2004 IBM Corporation
  8. */
  9. /*
  10. * Notes:
  11. *
  12. * This driver is used to control the following SCSI adapters:
  13. *
  14. * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
  15. *
  16. * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
  17. * PCI-X Dual Channel Ultra 320 SCSI Adapter
  18. * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
  19. * Embedded SCSI adapter on p615 and p655 systems
  20. *
  21. * Supported Hardware Features:
  22. * - Ultra 320 SCSI controller
  23. * - PCI-X host interface
  24. * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
  25. * - Non-Volatile Write Cache
  26. * - Supports attachment of non-RAID disks, tape, and optical devices
  27. * - RAID Levels 0, 5, 10
  28. * - Hot spare
  29. * - Background Parity Checking
  30. * - Background Data Scrubbing
  31. * - Ability to increase the capacity of an existing RAID 5 disk array
  32. * by adding disks
  33. *
  34. * Driver Features:
  35. * - Tagged command queuing
  36. * - Adapter microcode download
  37. * - PCI hot plug
  38. * - SCSI device hot plug
  39. *
  40. */
  41. #include <linux/fs.h>
  42. #include <linux/init.h>
  43. #include <linux/types.h>
  44. #include <linux/errno.h>
  45. #include <linux/kernel.h>
  46. #include <linux/slab.h>
  47. #include <linux/vmalloc.h>
  48. #include <linux/ioport.h>
  49. #include <linux/delay.h>
  50. #include <linux/pci.h>
  51. #include <linux/wait.h>
  52. #include <linux/spinlock.h>
  53. #include <linux/sched.h>
  54. #include <linux/interrupt.h>
  55. #include <linux/blkdev.h>
  56. #include <linux/firmware.h>
  57. #include <linux/module.h>
  58. #include <linux/moduleparam.h>
  59. #include <linux/libata.h>
  60. #include <linux/hdreg.h>
  61. #include <linux/reboot.h>
  62. #include <linux/stringify.h>
  63. #include <asm/io.h>
  64. #include <asm/irq.h>
  65. #include <asm/processor.h>
  66. #include <scsi/scsi.h>
  67. #include <scsi/scsi_host.h>
  68. #include <scsi/scsi_tcq.h>
  69. #include <scsi/scsi_eh.h>
  70. #include <scsi/scsi_cmnd.h>
  71. #include "ipr.h"
  72. /*
  73. * Global Data
  74. */
  75. static LIST_HEAD(ipr_ioa_head);
  76. static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  77. static unsigned int ipr_max_speed = 1;
  78. static int ipr_testmode = 0;
  79. static unsigned int ipr_fastfail = 0;
  80. static unsigned int ipr_transop_timeout = 0;
  81. static unsigned int ipr_debug = 0;
  82. static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
  83. static unsigned int ipr_dual_ioa_raid = 1;
  84. static unsigned int ipr_number_of_msix = 16;
  85. static unsigned int ipr_fast_reboot;
  86. static DEFINE_SPINLOCK(ipr_driver_lock);
  87. /* This table describes the differences between DMA controller chips */
  88. static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  89. { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
  90. .mailbox = 0x0042C,
  91. .max_cmds = 100,
  92. .cache_line_size = 0x20,
  93. .clear_isr = 1,
  94. .iopoll_weight = 0,
  95. {
  96. .set_interrupt_mask_reg = 0x0022C,
  97. .clr_interrupt_mask_reg = 0x00230,
  98. .clr_interrupt_mask_reg32 = 0x00230,
  99. .sense_interrupt_mask_reg = 0x0022C,
  100. .sense_interrupt_mask_reg32 = 0x0022C,
  101. .clr_interrupt_reg = 0x00228,
  102. .clr_interrupt_reg32 = 0x00228,
  103. .sense_interrupt_reg = 0x00224,
  104. .sense_interrupt_reg32 = 0x00224,
  105. .ioarrin_reg = 0x00404,
  106. .sense_uproc_interrupt_reg = 0x00214,
  107. .sense_uproc_interrupt_reg32 = 0x00214,
  108. .set_uproc_interrupt_reg = 0x00214,
  109. .set_uproc_interrupt_reg32 = 0x00214,
  110. .clr_uproc_interrupt_reg = 0x00218,
  111. .clr_uproc_interrupt_reg32 = 0x00218
  112. }
  113. },
  114. { /* Snipe and Scamp */
  115. .mailbox = 0x0052C,
  116. .max_cmds = 100,
  117. .cache_line_size = 0x20,
  118. .clear_isr = 1,
  119. .iopoll_weight = 0,
  120. {
  121. .set_interrupt_mask_reg = 0x00288,
  122. .clr_interrupt_mask_reg = 0x0028C,
  123. .clr_interrupt_mask_reg32 = 0x0028C,
  124. .sense_interrupt_mask_reg = 0x00288,
  125. .sense_interrupt_mask_reg32 = 0x00288,
  126. .clr_interrupt_reg = 0x00284,
  127. .clr_interrupt_reg32 = 0x00284,
  128. .sense_interrupt_reg = 0x00280,
  129. .sense_interrupt_reg32 = 0x00280,
  130. .ioarrin_reg = 0x00504,
  131. .sense_uproc_interrupt_reg = 0x00290,
  132. .sense_uproc_interrupt_reg32 = 0x00290,
  133. .set_uproc_interrupt_reg = 0x00290,
  134. .set_uproc_interrupt_reg32 = 0x00290,
  135. .clr_uproc_interrupt_reg = 0x00294,
  136. .clr_uproc_interrupt_reg32 = 0x00294
  137. }
  138. },
  139. { /* CRoC */
  140. .mailbox = 0x00044,
  141. .max_cmds = 1000,
  142. .cache_line_size = 0x20,
  143. .clear_isr = 0,
  144. .iopoll_weight = 64,
  145. {
  146. .set_interrupt_mask_reg = 0x00010,
  147. .clr_interrupt_mask_reg = 0x00018,
  148. .clr_interrupt_mask_reg32 = 0x0001C,
  149. .sense_interrupt_mask_reg = 0x00010,
  150. .sense_interrupt_mask_reg32 = 0x00014,
  151. .clr_interrupt_reg = 0x00008,
  152. .clr_interrupt_reg32 = 0x0000C,
  153. .sense_interrupt_reg = 0x00000,
  154. .sense_interrupt_reg32 = 0x00004,
  155. .ioarrin_reg = 0x00070,
  156. .sense_uproc_interrupt_reg = 0x00020,
  157. .sense_uproc_interrupt_reg32 = 0x00024,
  158. .set_uproc_interrupt_reg = 0x00020,
  159. .set_uproc_interrupt_reg32 = 0x00024,
  160. .clr_uproc_interrupt_reg = 0x00028,
  161. .clr_uproc_interrupt_reg32 = 0x0002C,
  162. .init_feedback_reg = 0x0005C,
  163. .dump_addr_reg = 0x00064,
  164. .dump_data_reg = 0x00068,
  165. .endian_swap_reg = 0x00084
  166. }
  167. },
  168. };
  169. static const struct ipr_chip_t ipr_chip[] = {
  170. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  171. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  172. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  173. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  174. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, true, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  175. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
  176. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, false, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
  177. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
  178. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
  179. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE, true, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
  180. };
  181. static int ipr_max_bus_speeds[] = {
  182. IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
  183. };
  184. MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
  185. MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
  186. module_param_named(max_speed, ipr_max_speed, uint, 0);
  187. MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
  188. module_param_named(log_level, ipr_log_level, uint, 0);
  189. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
  190. module_param_named(testmode, ipr_testmode, int, 0);
  191. MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
  192. module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
  193. MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
  194. module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
  195. MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
  196. module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
  197. MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
  198. module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
  199. MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
  200. module_param_named(max_devs, ipr_max_devs, int, 0);
  201. MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
  202. "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
  203. module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
  204. MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:16)");
  205. module_param_named(fast_reboot, ipr_fast_reboot, int, S_IRUGO | S_IWUSR);
  206. MODULE_PARM_DESC(fast_reboot, "Skip adapter shutdown during reboot. Set to 1 to enable. (default: 0)");
  207. MODULE_LICENSE("GPL");
  208. MODULE_VERSION(IPR_DRIVER_VERSION);
  209. /* A constant array of IOASCs/URCs/Error Messages */
  210. static const
  211. struct ipr_error_table_t ipr_error_table[] = {
  212. {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
  213. "8155: An unknown error was received"},
  214. {0x00330000, 0, 0,
  215. "Soft underlength error"},
  216. {0x005A0000, 0, 0,
  217. "Command to be cancelled not found"},
  218. {0x00808000, 0, 0,
  219. "Qualified success"},
  220. {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
  221. "FFFE: Soft device bus error recovered by the IOA"},
  222. {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
  223. "4101: Soft device bus fabric error"},
  224. {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
  225. "FFFC: Logical block guard error recovered by the device"},
  226. {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
  227. "FFFC: Logical block reference tag error recovered by the device"},
  228. {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
  229. "4171: Recovered scatter list tag / sequence number error"},
  230. {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
  231. "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
  232. {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
  233. "4171: Recovered logical block sequence number error on IOA to Host transfer"},
  234. {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
  235. "FFFD: Recovered logical block reference tag error detected by the IOA"},
  236. {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
  237. "FFFD: Logical block guard error recovered by the IOA"},
  238. {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
  239. "FFF9: Device sector reassign successful"},
  240. {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
  241. "FFF7: Media error recovered by device rewrite procedures"},
  242. {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
  243. "7001: IOA sector reassignment successful"},
  244. {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
  245. "FFF9: Soft media error. Sector reassignment recommended"},
  246. {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
  247. "FFF7: Media error recovered by IOA rewrite procedures"},
  248. {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
  249. "FF3D: Soft PCI bus error recovered by the IOA"},
  250. {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
  251. "FFF6: Device hardware error recovered by the IOA"},
  252. {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
  253. "FFF6: Device hardware error recovered by the device"},
  254. {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
  255. "FF3D: Soft IOA error recovered by the IOA"},
  256. {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
  257. "FFFA: Undefined device response recovered by the IOA"},
  258. {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  259. "FFF6: Device bus error, message or command phase"},
  260. {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
  261. "FFFE: Task Management Function failed"},
  262. {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
  263. "FFF6: Failure prediction threshold exceeded"},
  264. {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
  265. "8009: Impending cache battery pack failure"},
  266. {0x02040100, 0, 0,
  267. "Logical Unit in process of becoming ready"},
  268. {0x02040200, 0, 0,
  269. "Initializing command required"},
  270. {0x02040400, 0, 0,
  271. "34FF: Disk device format in progress"},
  272. {0x02040C00, 0, 0,
  273. "Logical unit not accessible, target port in unavailable state"},
  274. {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
  275. "9070: IOA requested reset"},
  276. {0x023F0000, 0, 0,
  277. "Synchronization required"},
  278. {0x02408500, 0, 0,
  279. "IOA microcode download required"},
  280. {0x02408600, 0, 0,
  281. "Device bus connection is prohibited by host"},
  282. {0x024E0000, 0, 0,
  283. "No ready, IOA shutdown"},
  284. {0x025A0000, 0, 0,
  285. "Not ready, IOA has been shutdown"},
  286. {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
  287. "3020: Storage subsystem configuration error"},
  288. {0x03110B00, 0, 0,
  289. "FFF5: Medium error, data unreadable, recommend reassign"},
  290. {0x03110C00, 0, 0,
  291. "7000: Medium error, data unreadable, do not reassign"},
  292. {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
  293. "FFF3: Disk media format bad"},
  294. {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
  295. "3002: Addressed device failed to respond to selection"},
  296. {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
  297. "3100: Device bus error"},
  298. {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
  299. "3109: IOA timed out a device command"},
  300. {0x04088000, 0, 0,
  301. "3120: SCSI bus is not operational"},
  302. {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
  303. "4100: Hard device bus fabric error"},
  304. {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
  305. "310C: Logical block guard error detected by the device"},
  306. {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
  307. "310C: Logical block reference tag error detected by the device"},
  308. {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
  309. "4170: Scatter list tag / sequence number error"},
  310. {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
  311. "8150: Logical block CRC error on IOA to Host transfer"},
  312. {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
  313. "4170: Logical block sequence number error on IOA to Host transfer"},
  314. {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
  315. "310D: Logical block reference tag error detected by the IOA"},
  316. {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
  317. "310D: Logical block guard error detected by the IOA"},
  318. {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
  319. "9000: IOA reserved area data check"},
  320. {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
  321. "9001: IOA reserved area invalid data pattern"},
  322. {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
  323. "9002: IOA reserved area LRC error"},
  324. {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
  325. "Hardware Error, IOA metadata access error"},
  326. {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
  327. "102E: Out of alternate sectors for disk storage"},
  328. {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
  329. "FFF4: Data transfer underlength error"},
  330. {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
  331. "FFF4: Data transfer overlength error"},
  332. {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
  333. "3400: Logical unit failure"},
  334. {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
  335. "FFF4: Device microcode is corrupt"},
  336. {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
  337. "8150: PCI bus error"},
  338. {0x04430000, 1, 0,
  339. "Unsupported device bus message received"},
  340. {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
  341. "FFF4: Disk device problem"},
  342. {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
  343. "8150: Permanent IOA failure"},
  344. {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
  345. "3010: Disk device returned wrong response to IOA"},
  346. {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
  347. "8151: IOA microcode error"},
  348. {0x04448500, 0, 0,
  349. "Device bus status error"},
  350. {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
  351. "8157: IOA error requiring IOA reset to recover"},
  352. {0x04448700, 0, 0,
  353. "ATA device status error"},
  354. {0x04490000, 0, 0,
  355. "Message reject received from the device"},
  356. {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
  357. "8008: A permanent cache battery pack failure occurred"},
  358. {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
  359. "9090: Disk unit has been modified after the last known status"},
  360. {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
  361. "9081: IOA detected device error"},
  362. {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
  363. "9082: IOA detected device error"},
  364. {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  365. "3110: Device bus error, message or command phase"},
  366. {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
  367. "3110: SAS Command / Task Management Function failed"},
  368. {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
  369. "9091: Incorrect hardware configuration change has been detected"},
  370. {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
  371. "9073: Invalid multi-adapter configuration"},
  372. {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
  373. "4010: Incorrect connection between cascaded expanders"},
  374. {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
  375. "4020: Connections exceed IOA design limits"},
  376. {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
  377. "4030: Incorrect multipath connection"},
  378. {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
  379. "4110: Unsupported enclosure function"},
  380. {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
  381. "4120: SAS cable VPD cannot be read"},
  382. {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
  383. "FFF4: Command to logical unit failed"},
  384. {0x05240000, 1, 0,
  385. "Illegal request, invalid request type or request packet"},
  386. {0x05250000, 0, 0,
  387. "Illegal request, invalid resource handle"},
  388. {0x05258000, 0, 0,
  389. "Illegal request, commands not allowed to this device"},
  390. {0x05258100, 0, 0,
  391. "Illegal request, command not allowed to a secondary adapter"},
  392. {0x05258200, 0, 0,
  393. "Illegal request, command not allowed to a non-optimized resource"},
  394. {0x05260000, 0, 0,
  395. "Illegal request, invalid field in parameter list"},
  396. {0x05260100, 0, 0,
  397. "Illegal request, parameter not supported"},
  398. {0x05260200, 0, 0,
  399. "Illegal request, parameter value invalid"},
  400. {0x052C0000, 0, 0,
  401. "Illegal request, command sequence error"},
  402. {0x052C8000, 1, 0,
  403. "Illegal request, dual adapter support not enabled"},
  404. {0x052C8100, 1, 0,
  405. "Illegal request, another cable connector was physically disabled"},
  406. {0x054E8000, 1, 0,
  407. "Illegal request, inconsistent group id/group count"},
  408. {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
  409. "9031: Array protection temporarily suspended, protection resuming"},
  410. {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
  411. "9040: Array protection temporarily suspended, protection resuming"},
  412. {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
  413. "4080: IOA exceeded maximum operating temperature"},
  414. {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
  415. "4085: Service required"},
  416. {0x060B8100, 0, IPR_DEFAULT_LOG_LEVEL,
  417. "4086: SAS Adapter Hardware Configuration Error"},
  418. {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
  419. "3140: Device bus not ready to ready transition"},
  420. {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
  421. "FFFB: SCSI bus was reset"},
  422. {0x06290500, 0, 0,
  423. "FFFE: SCSI bus transition to single ended"},
  424. {0x06290600, 0, 0,
  425. "FFFE: SCSI bus transition to LVD"},
  426. {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
  427. "FFFB: SCSI bus was reset by another initiator"},
  428. {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
  429. "3029: A device replacement has occurred"},
  430. {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
  431. "4102: Device bus fabric performance degradation"},
  432. {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
  433. "9051: IOA cache data exists for a missing or failed device"},
  434. {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
  435. "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
  436. {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
  437. "9025: Disk unit is not supported at its physical location"},
  438. {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
  439. "3020: IOA detected a SCSI bus configuration error"},
  440. {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
  441. "3150: SCSI bus configuration error"},
  442. {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
  443. "9074: Asymmetric advanced function disk configuration"},
  444. {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
  445. "4040: Incomplete multipath connection between IOA and enclosure"},
  446. {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
  447. "4041: Incomplete multipath connection between enclosure and device"},
  448. {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
  449. "9075: Incomplete multipath connection between IOA and remote IOA"},
  450. {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
  451. "9076: Configuration error, missing remote IOA"},
  452. {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
  453. "4050: Enclosure does not support a required multipath function"},
  454. {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
  455. "4121: Configuration error, required cable is missing"},
  456. {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
  457. "4122: Cable is not plugged into the correct location on remote IOA"},
  458. {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
  459. "4123: Configuration error, invalid cable vital product data"},
  460. {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
  461. "4124: Configuration error, both cable ends are plugged into the same IOA"},
  462. {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
  463. "4070: Logically bad block written on device"},
  464. {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
  465. "9041: Array protection temporarily suspended"},
  466. {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
  467. "9042: Corrupt array parity detected on specified device"},
  468. {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
  469. "9030: Array no longer protected due to missing or failed disk unit"},
  470. {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
  471. "9071: Link operational transition"},
  472. {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
  473. "9072: Link not operational transition"},
  474. {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
  475. "9032: Array exposed but still protected"},
  476. {0x066B8300, 0, IPR_DEBUG_LOG_LEVEL,
  477. "70DD: Device forced failed by disrupt device command"},
  478. {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
  479. "4061: Multipath redundancy level got better"},
  480. {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
  481. "4060: Multipath redundancy level got worse"},
  482. {0x06808100, 0, IPR_DEBUG_LOG_LEVEL,
  483. "9083: Device raw mode enabled"},
  484. {0x06808200, 0, IPR_DEBUG_LOG_LEVEL,
  485. "9084: Device raw mode disabled"},
  486. {0x07270000, 0, 0,
  487. "Failure due to other device"},
  488. {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
  489. "9008: IOA does not support functions expected by devices"},
  490. {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
  491. "9010: Cache data associated with attached devices cannot be found"},
  492. {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
  493. "9011: Cache data belongs to devices other than those attached"},
  494. {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
  495. "9020: Array missing 2 or more devices with only 1 device present"},
  496. {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
  497. "9021: Array missing 2 or more devices with 2 or more devices present"},
  498. {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
  499. "9022: Exposed array is missing a required device"},
  500. {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
  501. "9023: Array member(s) not at required physical locations"},
  502. {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
  503. "9024: Array not functional due to present hardware configuration"},
  504. {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
  505. "9026: Array not functional due to present hardware configuration"},
  506. {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
  507. "9027: Array is missing a device and parity is out of sync"},
  508. {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
  509. "9028: Maximum number of arrays already exist"},
  510. {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
  511. "9050: Required cache data cannot be located for a disk unit"},
  512. {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
  513. "9052: Cache data exists for a device that has been modified"},
  514. {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
  515. "9054: IOA resources not available due to previous problems"},
  516. {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
  517. "9092: Disk unit requires initialization before use"},
  518. {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
  519. "9029: Incorrect hardware configuration change has been detected"},
  520. {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
  521. "9060: One or more disk pairs are missing from an array"},
  522. {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
  523. "9061: One or more disks are missing from an array"},
  524. {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
  525. "9062: One or more disks are missing from an array"},
  526. {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
  527. "9063: Maximum number of functional arrays has been exceeded"},
  528. {0x07279A00, 0, 0,
  529. "Data protect, other volume set problem"},
  530. {0x0B260000, 0, 0,
  531. "Aborted command, invalid descriptor"},
  532. {0x0B3F9000, 0, 0,
  533. "Target operating conditions have changed, dual adapter takeover"},
  534. {0x0B530200, 0, 0,
  535. "Aborted command, medium removal prevented"},
  536. {0x0B5A0000, 0, 0,
  537. "Command terminated by host"},
  538. {0x0B5B8000, 0, 0,
  539. "Aborted command, command terminated by host"}
  540. };
  541. static const struct ipr_ses_table_entry ipr_ses_table[] = {
  542. { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
  543. { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
  544. { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
  545. { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
  546. { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
  547. { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
  548. { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
  549. { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
  550. { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  551. { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  552. { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
  553. { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
  554. { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
  555. };
  556. /*
  557. * Function Prototypes
  558. */
  559. static int ipr_reset_alert(struct ipr_cmnd *);
  560. static void ipr_process_ccn(struct ipr_cmnd *);
  561. static void ipr_process_error(struct ipr_cmnd *);
  562. static void ipr_reset_ioa_job(struct ipr_cmnd *);
  563. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
  564. enum ipr_shutdown_type);
  565. #ifdef CONFIG_SCSI_IPR_TRACE
  566. /**
  567. * ipr_trc_hook - Add a trace entry to the driver trace
  568. * @ipr_cmd: ipr command struct
  569. * @type: trace type
  570. * @add_data: additional data
  571. *
  572. * Return value:
  573. * none
  574. **/
  575. static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
  576. u8 type, u32 add_data)
  577. {
  578. struct ipr_trace_entry *trace_entry;
  579. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  580. unsigned int trace_index;
  581. trace_index = atomic_add_return(1, &ioa_cfg->trace_index) & IPR_TRACE_INDEX_MASK;
  582. trace_entry = &ioa_cfg->trace[trace_index];
  583. trace_entry->time = jiffies;
  584. trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
  585. trace_entry->type = type;
  586. if (ipr_cmd->ioa_cfg->sis64)
  587. trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
  588. else
  589. trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
  590. trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
  591. trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
  592. trace_entry->u.add_data = add_data;
  593. wmb();
  594. }
  595. #else
  596. #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
  597. #endif
  598. /**
  599. * ipr_lock_and_done - Acquire lock and complete command
  600. * @ipr_cmd: ipr command struct
  601. *
  602. * Return value:
  603. * none
  604. **/
  605. static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
  606. {
  607. unsigned long lock_flags;
  608. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  609. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  610. ipr_cmd->done(ipr_cmd);
  611. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  612. }
  613. /**
  614. * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
  615. * @ipr_cmd: ipr command struct
  616. *
  617. * Return value:
  618. * none
  619. **/
  620. static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  621. {
  622. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  623. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  624. struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
  625. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  626. int hrrq_id;
  627. hrrq_id = ioarcb->cmd_pkt.hrrq_id;
  628. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  629. ioarcb->cmd_pkt.hrrq_id = hrrq_id;
  630. ioarcb->data_transfer_length = 0;
  631. ioarcb->read_data_transfer_length = 0;
  632. ioarcb->ioadl_len = 0;
  633. ioarcb->read_ioadl_len = 0;
  634. if (ipr_cmd->ioa_cfg->sis64) {
  635. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  636. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  637. ioasa64->u.gata.status = 0;
  638. } else {
  639. ioarcb->write_ioadl_addr =
  640. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  641. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  642. ioasa->u.gata.status = 0;
  643. }
  644. ioasa->hdr.ioasc = 0;
  645. ioasa->hdr.residual_data_len = 0;
  646. ipr_cmd->scsi_cmd = NULL;
  647. ipr_cmd->qc = NULL;
  648. ipr_cmd->sense_buffer[0] = 0;
  649. ipr_cmd->dma_use_sg = 0;
  650. }
  651. /**
  652. * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
  653. * @ipr_cmd: ipr command struct
  654. *
  655. * Return value:
  656. * none
  657. **/
  658. static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
  659. void (*fast_done) (struct ipr_cmnd *))
  660. {
  661. ipr_reinit_ipr_cmnd(ipr_cmd);
  662. ipr_cmd->u.scratch = 0;
  663. ipr_cmd->sibling = NULL;
  664. ipr_cmd->eh_comp = NULL;
  665. ipr_cmd->fast_done = fast_done;
  666. timer_setup(&ipr_cmd->timer, NULL, 0);
  667. }
  668. /**
  669. * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
  670. * @ioa_cfg: ioa config struct
  671. *
  672. * Return value:
  673. * pointer to ipr command struct
  674. **/
  675. static
  676. struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
  677. {
  678. struct ipr_cmnd *ipr_cmd = NULL;
  679. if (likely(!list_empty(&hrrq->hrrq_free_q))) {
  680. ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
  681. struct ipr_cmnd, queue);
  682. list_del(&ipr_cmd->queue);
  683. }
  684. return ipr_cmd;
  685. }
  686. /**
  687. * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
  688. * @ioa_cfg: ioa config struct
  689. *
  690. * Return value:
  691. * pointer to ipr command struct
  692. **/
  693. static
  694. struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  695. {
  696. struct ipr_cmnd *ipr_cmd =
  697. __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
  698. ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
  699. return ipr_cmd;
  700. }
  701. /**
  702. * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
  703. * @ioa_cfg: ioa config struct
  704. * @clr_ints: interrupts to clear
  705. *
  706. * This function masks all interrupts on the adapter, then clears the
  707. * interrupts specified in the mask
  708. *
  709. * Return value:
  710. * none
  711. **/
  712. static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
  713. u32 clr_ints)
  714. {
  715. volatile u32 int_reg;
  716. int i;
  717. /* Stop new interrupts */
  718. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  719. spin_lock(&ioa_cfg->hrrq[i]._lock);
  720. ioa_cfg->hrrq[i].allow_interrupts = 0;
  721. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  722. }
  723. /* Set interrupt mask to stop all new interrupts */
  724. if (ioa_cfg->sis64)
  725. writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  726. else
  727. writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  728. /* Clear any pending interrupts */
  729. if (ioa_cfg->sis64)
  730. writel(~0, ioa_cfg->regs.clr_interrupt_reg);
  731. writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
  732. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  733. }
  734. /**
  735. * ipr_save_pcix_cmd_reg - Save PCI-X command register
  736. * @ioa_cfg: ioa config struct
  737. *
  738. * Return value:
  739. * 0 on success / -EIO on failure
  740. **/
  741. static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  742. {
  743. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  744. if (pcix_cmd_reg == 0)
  745. return 0;
  746. if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  747. &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  748. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  749. return -EIO;
  750. }
  751. ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
  752. return 0;
  753. }
  754. /**
  755. * ipr_set_pcix_cmd_reg - Setup PCI-X command register
  756. * @ioa_cfg: ioa config struct
  757. *
  758. * Return value:
  759. * 0 on success / -EIO on failure
  760. **/
  761. static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  762. {
  763. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  764. if (pcix_cmd_reg) {
  765. if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  766. ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  767. dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
  768. return -EIO;
  769. }
  770. }
  771. return 0;
  772. }
  773. /**
  774. * __ipr_sata_eh_done - done function for aborted SATA commands
  775. * @ipr_cmd: ipr command struct
  776. *
  777. * This function is invoked for ops generated to SATA
  778. * devices which are being aborted.
  779. *
  780. * Return value:
  781. * none
  782. **/
  783. static void __ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
  784. {
  785. struct ata_queued_cmd *qc = ipr_cmd->qc;
  786. struct ipr_sata_port *sata_port = qc->ap->private_data;
  787. qc->err_mask |= AC_ERR_OTHER;
  788. sata_port->ioasa.status |= ATA_BUSY;
  789. ata_qc_complete(qc);
  790. if (ipr_cmd->eh_comp)
  791. complete(ipr_cmd->eh_comp);
  792. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  793. }
  794. /**
  795. * ipr_sata_eh_done - done function for aborted SATA commands
  796. * @ipr_cmd: ipr command struct
  797. *
  798. * This function is invoked for ops generated to SATA
  799. * devices which are being aborted.
  800. *
  801. * Return value:
  802. * none
  803. **/
  804. static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
  805. {
  806. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  807. unsigned long hrrq_flags;
  808. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  809. __ipr_sata_eh_done(ipr_cmd);
  810. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  811. }
  812. /**
  813. * __ipr_scsi_eh_done - mid-layer done function for aborted ops
  814. * @ipr_cmd: ipr command struct
  815. *
  816. * This function is invoked by the interrupt handler for
  817. * ops generated by the SCSI mid-layer which are being aborted.
  818. *
  819. * Return value:
  820. * none
  821. **/
  822. static void __ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  823. {
  824. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  825. scsi_cmd->result |= (DID_ERROR << 16);
  826. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  827. scsi_cmd->scsi_done(scsi_cmd);
  828. if (ipr_cmd->eh_comp)
  829. complete(ipr_cmd->eh_comp);
  830. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  831. }
  832. /**
  833. * ipr_scsi_eh_done - mid-layer done function for aborted ops
  834. * @ipr_cmd: ipr command struct
  835. *
  836. * This function is invoked by the interrupt handler for
  837. * ops generated by the SCSI mid-layer which are being aborted.
  838. *
  839. * Return value:
  840. * none
  841. **/
  842. static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  843. {
  844. unsigned long hrrq_flags;
  845. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  846. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  847. __ipr_scsi_eh_done(ipr_cmd);
  848. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  849. }
  850. /**
  851. * ipr_fail_all_ops - Fails all outstanding ops.
  852. * @ioa_cfg: ioa config struct
  853. *
  854. * This function fails all outstanding ops.
  855. *
  856. * Return value:
  857. * none
  858. **/
  859. static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
  860. {
  861. struct ipr_cmnd *ipr_cmd, *temp;
  862. struct ipr_hrr_queue *hrrq;
  863. ENTER;
  864. for_each_hrrq(hrrq, ioa_cfg) {
  865. spin_lock(&hrrq->_lock);
  866. list_for_each_entry_safe(ipr_cmd,
  867. temp, &hrrq->hrrq_pending_q, queue) {
  868. list_del(&ipr_cmd->queue);
  869. ipr_cmd->s.ioasa.hdr.ioasc =
  870. cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
  871. ipr_cmd->s.ioasa.hdr.ilid =
  872. cpu_to_be32(IPR_DRIVER_ILID);
  873. if (ipr_cmd->scsi_cmd)
  874. ipr_cmd->done = __ipr_scsi_eh_done;
  875. else if (ipr_cmd->qc)
  876. ipr_cmd->done = __ipr_sata_eh_done;
  877. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
  878. IPR_IOASC_IOA_WAS_RESET);
  879. del_timer(&ipr_cmd->timer);
  880. ipr_cmd->done(ipr_cmd);
  881. }
  882. spin_unlock(&hrrq->_lock);
  883. }
  884. LEAVE;
  885. }
  886. /**
  887. * ipr_send_command - Send driver initiated requests.
  888. * @ipr_cmd: ipr command struct
  889. *
  890. * This function sends a command to the adapter using the correct write call.
  891. * In the case of sis64, calculate the ioarcb size required. Then or in the
  892. * appropriate bits.
  893. *
  894. * Return value:
  895. * none
  896. **/
  897. static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
  898. {
  899. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  900. dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
  901. if (ioa_cfg->sis64) {
  902. /* The default size is 256 bytes */
  903. send_dma_addr |= 0x1;
  904. /* If the number of ioadls * size of ioadl > 128 bytes,
  905. then use a 512 byte ioarcb */
  906. if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
  907. send_dma_addr |= 0x4;
  908. writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
  909. } else
  910. writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
  911. }
  912. /**
  913. * ipr_do_req - Send driver initiated requests.
  914. * @ipr_cmd: ipr command struct
  915. * @done: done function
  916. * @timeout_func: timeout function
  917. * @timeout: timeout value
  918. *
  919. * This function sends the specified command to the adapter with the
  920. * timeout given. The done function is invoked on command completion.
  921. *
  922. * Return value:
  923. * none
  924. **/
  925. static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
  926. void (*done) (struct ipr_cmnd *),
  927. void (*timeout_func) (struct timer_list *), u32 timeout)
  928. {
  929. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  930. ipr_cmd->done = done;
  931. ipr_cmd->timer.expires = jiffies + timeout;
  932. ipr_cmd->timer.function = timeout_func;
  933. add_timer(&ipr_cmd->timer);
  934. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
  935. ipr_send_command(ipr_cmd);
  936. }
  937. /**
  938. * ipr_internal_cmd_done - Op done function for an internally generated op.
  939. * @ipr_cmd: ipr command struct
  940. *
  941. * This function is the op done function for an internally generated,
  942. * blocking op. It simply wakes the sleeping thread.
  943. *
  944. * Return value:
  945. * none
  946. **/
  947. static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
  948. {
  949. if (ipr_cmd->sibling)
  950. ipr_cmd->sibling = NULL;
  951. else
  952. complete(&ipr_cmd->completion);
  953. }
  954. /**
  955. * ipr_init_ioadl - initialize the ioadl for the correct SIS type
  956. * @ipr_cmd: ipr command struct
  957. * @dma_addr: dma address
  958. * @len: transfer length
  959. * @flags: ioadl flag value
  960. *
  961. * This function initializes an ioadl in the case where there is only a single
  962. * descriptor.
  963. *
  964. * Return value:
  965. * nothing
  966. **/
  967. static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
  968. u32 len, int flags)
  969. {
  970. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  971. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  972. ipr_cmd->dma_use_sg = 1;
  973. if (ipr_cmd->ioa_cfg->sis64) {
  974. ioadl64->flags = cpu_to_be32(flags);
  975. ioadl64->data_len = cpu_to_be32(len);
  976. ioadl64->address = cpu_to_be64(dma_addr);
  977. ipr_cmd->ioarcb.ioadl_len =
  978. cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
  979. ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
  980. } else {
  981. ioadl->flags_and_data_len = cpu_to_be32(flags | len);
  982. ioadl->address = cpu_to_be32(dma_addr);
  983. if (flags == IPR_IOADL_FLAGS_READ_LAST) {
  984. ipr_cmd->ioarcb.read_ioadl_len =
  985. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  986. ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
  987. } else {
  988. ipr_cmd->ioarcb.ioadl_len =
  989. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  990. ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
  991. }
  992. }
  993. }
  994. /**
  995. * ipr_send_blocking_cmd - Send command and sleep on its completion.
  996. * @ipr_cmd: ipr command struct
  997. * @timeout_func: function to invoke if command times out
  998. * @timeout: timeout
  999. *
  1000. * Return value:
  1001. * none
  1002. **/
  1003. static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
  1004. void (*timeout_func) (struct timer_list *),
  1005. u32 timeout)
  1006. {
  1007. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1008. init_completion(&ipr_cmd->completion);
  1009. ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
  1010. spin_unlock_irq(ioa_cfg->host->host_lock);
  1011. wait_for_completion(&ipr_cmd->completion);
  1012. spin_lock_irq(ioa_cfg->host->host_lock);
  1013. }
  1014. static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
  1015. {
  1016. unsigned int hrrq;
  1017. if (ioa_cfg->hrrq_num == 1)
  1018. hrrq = 0;
  1019. else {
  1020. hrrq = atomic_add_return(1, &ioa_cfg->hrrq_index);
  1021. hrrq = (hrrq % (ioa_cfg->hrrq_num - 1)) + 1;
  1022. }
  1023. return hrrq;
  1024. }
  1025. /**
  1026. * ipr_send_hcam - Send an HCAM to the adapter.
  1027. * @ioa_cfg: ioa config struct
  1028. * @type: HCAM type
  1029. * @hostrcb: hostrcb struct
  1030. *
  1031. * This function will send a Host Controlled Async command to the adapter.
  1032. * If HCAMs are currently not allowed to be issued to the adapter, it will
  1033. * place the hostrcb on the free queue.
  1034. *
  1035. * Return value:
  1036. * none
  1037. **/
  1038. static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
  1039. struct ipr_hostrcb *hostrcb)
  1040. {
  1041. struct ipr_cmnd *ipr_cmd;
  1042. struct ipr_ioarcb *ioarcb;
  1043. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
  1044. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  1045. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  1046. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
  1047. ipr_cmd->u.hostrcb = hostrcb;
  1048. ioarcb = &ipr_cmd->ioarcb;
  1049. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  1050. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
  1051. ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
  1052. ioarcb->cmd_pkt.cdb[1] = type;
  1053. ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
  1054. ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
  1055. ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
  1056. sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
  1057. if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
  1058. ipr_cmd->done = ipr_process_ccn;
  1059. else
  1060. ipr_cmd->done = ipr_process_error;
  1061. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
  1062. ipr_send_command(ipr_cmd);
  1063. } else {
  1064. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  1065. }
  1066. }
  1067. /**
  1068. * ipr_update_ata_class - Update the ata class in the resource entry
  1069. * @res: resource entry struct
  1070. * @proto: cfgte device bus protocol value
  1071. *
  1072. * Return value:
  1073. * none
  1074. **/
  1075. static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
  1076. {
  1077. switch (proto) {
  1078. case IPR_PROTO_SATA:
  1079. case IPR_PROTO_SAS_STP:
  1080. res->ata_class = ATA_DEV_ATA;
  1081. break;
  1082. case IPR_PROTO_SATA_ATAPI:
  1083. case IPR_PROTO_SAS_STP_ATAPI:
  1084. res->ata_class = ATA_DEV_ATAPI;
  1085. break;
  1086. default:
  1087. res->ata_class = ATA_DEV_UNKNOWN;
  1088. break;
  1089. };
  1090. }
  1091. /**
  1092. * ipr_init_res_entry - Initialize a resource entry struct.
  1093. * @res: resource entry struct
  1094. * @cfgtew: config table entry wrapper struct
  1095. *
  1096. * Return value:
  1097. * none
  1098. **/
  1099. static void ipr_init_res_entry(struct ipr_resource_entry *res,
  1100. struct ipr_config_table_entry_wrapper *cfgtew)
  1101. {
  1102. int found = 0;
  1103. unsigned int proto;
  1104. struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
  1105. struct ipr_resource_entry *gscsi_res = NULL;
  1106. res->needs_sync_complete = 0;
  1107. res->in_erp = 0;
  1108. res->add_to_ml = 0;
  1109. res->del_from_ml = 0;
  1110. res->resetting_device = 0;
  1111. res->reset_occurred = 0;
  1112. res->sdev = NULL;
  1113. res->sata_port = NULL;
  1114. if (ioa_cfg->sis64) {
  1115. proto = cfgtew->u.cfgte64->proto;
  1116. res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
  1117. res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
  1118. res->qmodel = IPR_QUEUEING_MODEL64(res);
  1119. res->type = cfgtew->u.cfgte64->res_type;
  1120. memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
  1121. sizeof(res->res_path));
  1122. res->bus = 0;
  1123. memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1124. sizeof(res->dev_lun.scsi_lun));
  1125. res->lun = scsilun_to_int(&res->dev_lun);
  1126. if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
  1127. list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
  1128. if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
  1129. found = 1;
  1130. res->target = gscsi_res->target;
  1131. break;
  1132. }
  1133. }
  1134. if (!found) {
  1135. res->target = find_first_zero_bit(ioa_cfg->target_ids,
  1136. ioa_cfg->max_devs_supported);
  1137. set_bit(res->target, ioa_cfg->target_ids);
  1138. }
  1139. } else if (res->type == IPR_RES_TYPE_IOAFP) {
  1140. res->bus = IPR_IOAFP_VIRTUAL_BUS;
  1141. res->target = 0;
  1142. } else if (res->type == IPR_RES_TYPE_ARRAY) {
  1143. res->bus = IPR_ARRAY_VIRTUAL_BUS;
  1144. res->target = find_first_zero_bit(ioa_cfg->array_ids,
  1145. ioa_cfg->max_devs_supported);
  1146. set_bit(res->target, ioa_cfg->array_ids);
  1147. } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
  1148. res->bus = IPR_VSET_VIRTUAL_BUS;
  1149. res->target = find_first_zero_bit(ioa_cfg->vset_ids,
  1150. ioa_cfg->max_devs_supported);
  1151. set_bit(res->target, ioa_cfg->vset_ids);
  1152. } else {
  1153. res->target = find_first_zero_bit(ioa_cfg->target_ids,
  1154. ioa_cfg->max_devs_supported);
  1155. set_bit(res->target, ioa_cfg->target_ids);
  1156. }
  1157. } else {
  1158. proto = cfgtew->u.cfgte->proto;
  1159. res->qmodel = IPR_QUEUEING_MODEL(res);
  1160. res->flags = cfgtew->u.cfgte->flags;
  1161. if (res->flags & IPR_IS_IOA_RESOURCE)
  1162. res->type = IPR_RES_TYPE_IOAFP;
  1163. else
  1164. res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
  1165. res->bus = cfgtew->u.cfgte->res_addr.bus;
  1166. res->target = cfgtew->u.cfgte->res_addr.target;
  1167. res->lun = cfgtew->u.cfgte->res_addr.lun;
  1168. res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
  1169. }
  1170. ipr_update_ata_class(res, proto);
  1171. }
  1172. /**
  1173. * ipr_is_same_device - Determine if two devices are the same.
  1174. * @res: resource entry struct
  1175. * @cfgtew: config table entry wrapper struct
  1176. *
  1177. * Return value:
  1178. * 1 if the devices are the same / 0 otherwise
  1179. **/
  1180. static int ipr_is_same_device(struct ipr_resource_entry *res,
  1181. struct ipr_config_table_entry_wrapper *cfgtew)
  1182. {
  1183. if (res->ioa_cfg->sis64) {
  1184. if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
  1185. sizeof(cfgtew->u.cfgte64->dev_id)) &&
  1186. !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1187. sizeof(cfgtew->u.cfgte64->lun))) {
  1188. return 1;
  1189. }
  1190. } else {
  1191. if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
  1192. res->target == cfgtew->u.cfgte->res_addr.target &&
  1193. res->lun == cfgtew->u.cfgte->res_addr.lun)
  1194. return 1;
  1195. }
  1196. return 0;
  1197. }
  1198. /**
  1199. * __ipr_format_res_path - Format the resource path for printing.
  1200. * @res_path: resource path
  1201. * @buf: buffer
  1202. * @len: length of buffer provided
  1203. *
  1204. * Return value:
  1205. * pointer to buffer
  1206. **/
  1207. static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
  1208. {
  1209. int i;
  1210. char *p = buffer;
  1211. *p = '\0';
  1212. p += scnprintf(p, buffer + len - p, "%02X", res_path[0]);
  1213. for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
  1214. p += scnprintf(p, buffer + len - p, "-%02X", res_path[i]);
  1215. return buffer;
  1216. }
  1217. /**
  1218. * ipr_format_res_path - Format the resource path for printing.
  1219. * @ioa_cfg: ioa config struct
  1220. * @res_path: resource path
  1221. * @buf: buffer
  1222. * @len: length of buffer provided
  1223. *
  1224. * Return value:
  1225. * pointer to buffer
  1226. **/
  1227. static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
  1228. u8 *res_path, char *buffer, int len)
  1229. {
  1230. char *p = buffer;
  1231. *p = '\0';
  1232. p += scnprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
  1233. __ipr_format_res_path(res_path, p, len - (buffer - p));
  1234. return buffer;
  1235. }
  1236. /**
  1237. * ipr_update_res_entry - Update the resource entry.
  1238. * @res: resource entry struct
  1239. * @cfgtew: config table entry wrapper struct
  1240. *
  1241. * Return value:
  1242. * none
  1243. **/
  1244. static void ipr_update_res_entry(struct ipr_resource_entry *res,
  1245. struct ipr_config_table_entry_wrapper *cfgtew)
  1246. {
  1247. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1248. unsigned int proto;
  1249. int new_path = 0;
  1250. if (res->ioa_cfg->sis64) {
  1251. res->flags = be16_to_cpu(cfgtew->u.cfgte64->flags);
  1252. res->res_flags = be16_to_cpu(cfgtew->u.cfgte64->res_flags);
  1253. res->type = cfgtew->u.cfgte64->res_type;
  1254. memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
  1255. sizeof(struct ipr_std_inq_data));
  1256. res->qmodel = IPR_QUEUEING_MODEL64(res);
  1257. proto = cfgtew->u.cfgte64->proto;
  1258. res->res_handle = cfgtew->u.cfgte64->res_handle;
  1259. res->dev_id = cfgtew->u.cfgte64->dev_id;
  1260. memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1261. sizeof(res->dev_lun.scsi_lun));
  1262. if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
  1263. sizeof(res->res_path))) {
  1264. memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
  1265. sizeof(res->res_path));
  1266. new_path = 1;
  1267. }
  1268. if (res->sdev && new_path)
  1269. sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
  1270. ipr_format_res_path(res->ioa_cfg,
  1271. res->res_path, buffer, sizeof(buffer)));
  1272. } else {
  1273. res->flags = cfgtew->u.cfgte->flags;
  1274. if (res->flags & IPR_IS_IOA_RESOURCE)
  1275. res->type = IPR_RES_TYPE_IOAFP;
  1276. else
  1277. res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
  1278. memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
  1279. sizeof(struct ipr_std_inq_data));
  1280. res->qmodel = IPR_QUEUEING_MODEL(res);
  1281. proto = cfgtew->u.cfgte->proto;
  1282. res->res_handle = cfgtew->u.cfgte->res_handle;
  1283. }
  1284. ipr_update_ata_class(res, proto);
  1285. }
  1286. /**
  1287. * ipr_clear_res_target - Clear the bit in the bit map representing the target
  1288. * for the resource.
  1289. * @res: resource entry struct
  1290. * @cfgtew: config table entry wrapper struct
  1291. *
  1292. * Return value:
  1293. * none
  1294. **/
  1295. static void ipr_clear_res_target(struct ipr_resource_entry *res)
  1296. {
  1297. struct ipr_resource_entry *gscsi_res = NULL;
  1298. struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
  1299. if (!ioa_cfg->sis64)
  1300. return;
  1301. if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
  1302. clear_bit(res->target, ioa_cfg->array_ids);
  1303. else if (res->bus == IPR_VSET_VIRTUAL_BUS)
  1304. clear_bit(res->target, ioa_cfg->vset_ids);
  1305. else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
  1306. list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
  1307. if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
  1308. return;
  1309. clear_bit(res->target, ioa_cfg->target_ids);
  1310. } else if (res->bus == 0)
  1311. clear_bit(res->target, ioa_cfg->target_ids);
  1312. }
  1313. /**
  1314. * ipr_handle_config_change - Handle a config change from the adapter
  1315. * @ioa_cfg: ioa config struct
  1316. * @hostrcb: hostrcb
  1317. *
  1318. * Return value:
  1319. * none
  1320. **/
  1321. static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
  1322. struct ipr_hostrcb *hostrcb)
  1323. {
  1324. struct ipr_resource_entry *res = NULL;
  1325. struct ipr_config_table_entry_wrapper cfgtew;
  1326. __be32 cc_res_handle;
  1327. u32 is_ndn = 1;
  1328. if (ioa_cfg->sis64) {
  1329. cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
  1330. cc_res_handle = cfgtew.u.cfgte64->res_handle;
  1331. } else {
  1332. cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
  1333. cc_res_handle = cfgtew.u.cfgte->res_handle;
  1334. }
  1335. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1336. if (res->res_handle == cc_res_handle) {
  1337. is_ndn = 0;
  1338. break;
  1339. }
  1340. }
  1341. if (is_ndn) {
  1342. if (list_empty(&ioa_cfg->free_res_q)) {
  1343. ipr_send_hcam(ioa_cfg,
  1344. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  1345. hostrcb);
  1346. return;
  1347. }
  1348. res = list_entry(ioa_cfg->free_res_q.next,
  1349. struct ipr_resource_entry, queue);
  1350. list_del(&res->queue);
  1351. ipr_init_res_entry(res, &cfgtew);
  1352. list_add_tail(&res->queue, &ioa_cfg->used_res_q);
  1353. }
  1354. ipr_update_res_entry(res, &cfgtew);
  1355. if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
  1356. if (res->sdev) {
  1357. res->del_from_ml = 1;
  1358. res->res_handle = IPR_INVALID_RES_HANDLE;
  1359. schedule_work(&ioa_cfg->work_q);
  1360. } else {
  1361. ipr_clear_res_target(res);
  1362. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  1363. }
  1364. } else if (!res->sdev || res->del_from_ml) {
  1365. res->add_to_ml = 1;
  1366. schedule_work(&ioa_cfg->work_q);
  1367. }
  1368. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  1369. }
  1370. /**
  1371. * ipr_process_ccn - Op done function for a CCN.
  1372. * @ipr_cmd: ipr command struct
  1373. *
  1374. * This function is the op done function for a configuration
  1375. * change notification host controlled async from the adapter.
  1376. *
  1377. * Return value:
  1378. * none
  1379. **/
  1380. static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
  1381. {
  1382. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1383. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  1384. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  1385. list_del_init(&hostrcb->queue);
  1386. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  1387. if (ioasc) {
  1388. if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
  1389. ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST)
  1390. dev_err(&ioa_cfg->pdev->dev,
  1391. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  1392. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  1393. } else {
  1394. ipr_handle_config_change(ioa_cfg, hostrcb);
  1395. }
  1396. }
  1397. /**
  1398. * strip_and_pad_whitespace - Strip and pad trailing whitespace.
  1399. * @i: index into buffer
  1400. * @buf: string to modify
  1401. *
  1402. * This function will strip all trailing whitespace, pad the end
  1403. * of the string with a single space, and NULL terminate the string.
  1404. *
  1405. * Return value:
  1406. * new length of string
  1407. **/
  1408. static int strip_and_pad_whitespace(int i, char *buf)
  1409. {
  1410. while (i && buf[i] == ' ')
  1411. i--;
  1412. buf[i+1] = ' ';
  1413. buf[i+2] = '\0';
  1414. return i + 2;
  1415. }
  1416. /**
  1417. * ipr_log_vpd_compact - Log the passed extended VPD compactly.
  1418. * @prefix: string to print at start of printk
  1419. * @hostrcb: hostrcb pointer
  1420. * @vpd: vendor/product id/sn struct
  1421. *
  1422. * Return value:
  1423. * none
  1424. **/
  1425. static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  1426. struct ipr_vpd *vpd)
  1427. {
  1428. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
  1429. int i = 0;
  1430. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  1431. i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
  1432. memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
  1433. i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
  1434. memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
  1435. buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
  1436. ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
  1437. }
  1438. /**
  1439. * ipr_log_vpd - Log the passed VPD to the error log.
  1440. * @vpd: vendor/product id/sn struct
  1441. *
  1442. * Return value:
  1443. * none
  1444. **/
  1445. static void ipr_log_vpd(struct ipr_vpd *vpd)
  1446. {
  1447. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
  1448. + IPR_SERIAL_NUM_LEN];
  1449. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  1450. memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
  1451. IPR_PROD_ID_LEN);
  1452. buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
  1453. ipr_err("Vendor/Product ID: %s\n", buffer);
  1454. memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
  1455. buffer[IPR_SERIAL_NUM_LEN] = '\0';
  1456. ipr_err(" Serial Number: %s\n", buffer);
  1457. }
  1458. /**
  1459. * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
  1460. * @prefix: string to print at start of printk
  1461. * @hostrcb: hostrcb pointer
  1462. * @vpd: vendor/product id/sn/wwn struct
  1463. *
  1464. * Return value:
  1465. * none
  1466. **/
  1467. static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  1468. struct ipr_ext_vpd *vpd)
  1469. {
  1470. ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
  1471. ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
  1472. be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
  1473. }
  1474. /**
  1475. * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
  1476. * @vpd: vendor/product id/sn/wwn struct
  1477. *
  1478. * Return value:
  1479. * none
  1480. **/
  1481. static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
  1482. {
  1483. ipr_log_vpd(&vpd->vpd);
  1484. ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
  1485. be32_to_cpu(vpd->wwid[1]));
  1486. }
  1487. /**
  1488. * ipr_log_enhanced_cache_error - Log a cache error.
  1489. * @ioa_cfg: ioa config struct
  1490. * @hostrcb: hostrcb struct
  1491. *
  1492. * Return value:
  1493. * none
  1494. **/
  1495. static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  1496. struct ipr_hostrcb *hostrcb)
  1497. {
  1498. struct ipr_hostrcb_type_12_error *error;
  1499. if (ioa_cfg->sis64)
  1500. error = &hostrcb->hcam.u.error64.u.type_12_error;
  1501. else
  1502. error = &hostrcb->hcam.u.error.u.type_12_error;
  1503. ipr_err("-----Current Configuration-----\n");
  1504. ipr_err("Cache Directory Card Information:\n");
  1505. ipr_log_ext_vpd(&error->ioa_vpd);
  1506. ipr_err("Adapter Card Information:\n");
  1507. ipr_log_ext_vpd(&error->cfc_vpd);
  1508. ipr_err("-----Expected Configuration-----\n");
  1509. ipr_err("Cache Directory Card Information:\n");
  1510. ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
  1511. ipr_err("Adapter Card Information:\n");
  1512. ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
  1513. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  1514. be32_to_cpu(error->ioa_data[0]),
  1515. be32_to_cpu(error->ioa_data[1]),
  1516. be32_to_cpu(error->ioa_data[2]));
  1517. }
  1518. /**
  1519. * ipr_log_cache_error - Log a cache error.
  1520. * @ioa_cfg: ioa config struct
  1521. * @hostrcb: hostrcb struct
  1522. *
  1523. * Return value:
  1524. * none
  1525. **/
  1526. static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  1527. struct ipr_hostrcb *hostrcb)
  1528. {
  1529. struct ipr_hostrcb_type_02_error *error =
  1530. &hostrcb->hcam.u.error.u.type_02_error;
  1531. ipr_err("-----Current Configuration-----\n");
  1532. ipr_err("Cache Directory Card Information:\n");
  1533. ipr_log_vpd(&error->ioa_vpd);
  1534. ipr_err("Adapter Card Information:\n");
  1535. ipr_log_vpd(&error->cfc_vpd);
  1536. ipr_err("-----Expected Configuration-----\n");
  1537. ipr_err("Cache Directory Card Information:\n");
  1538. ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
  1539. ipr_err("Adapter Card Information:\n");
  1540. ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
  1541. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  1542. be32_to_cpu(error->ioa_data[0]),
  1543. be32_to_cpu(error->ioa_data[1]),
  1544. be32_to_cpu(error->ioa_data[2]));
  1545. }
  1546. /**
  1547. * ipr_log_enhanced_config_error - Log a configuration error.
  1548. * @ioa_cfg: ioa config struct
  1549. * @hostrcb: hostrcb struct
  1550. *
  1551. * Return value:
  1552. * none
  1553. **/
  1554. static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1555. struct ipr_hostrcb *hostrcb)
  1556. {
  1557. int errors_logged, i;
  1558. struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
  1559. struct ipr_hostrcb_type_13_error *error;
  1560. error = &hostrcb->hcam.u.error.u.type_13_error;
  1561. errors_logged = be32_to_cpu(error->errors_logged);
  1562. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1563. be32_to_cpu(error->errors_detected), errors_logged);
  1564. dev_entry = error->dev;
  1565. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1566. ipr_err_separator;
  1567. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1568. ipr_log_ext_vpd(&dev_entry->vpd);
  1569. ipr_err("-----New Device Information-----\n");
  1570. ipr_log_ext_vpd(&dev_entry->new_vpd);
  1571. ipr_err("Cache Directory Card Information:\n");
  1572. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1573. ipr_err("Adapter Card Information:\n");
  1574. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1575. }
  1576. }
  1577. /**
  1578. * ipr_log_sis64_config_error - Log a device error.
  1579. * @ioa_cfg: ioa config struct
  1580. * @hostrcb: hostrcb struct
  1581. *
  1582. * Return value:
  1583. * none
  1584. **/
  1585. static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1586. struct ipr_hostrcb *hostrcb)
  1587. {
  1588. int errors_logged, i;
  1589. struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
  1590. struct ipr_hostrcb_type_23_error *error;
  1591. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1592. error = &hostrcb->hcam.u.error64.u.type_23_error;
  1593. errors_logged = be32_to_cpu(error->errors_logged);
  1594. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1595. be32_to_cpu(error->errors_detected), errors_logged);
  1596. dev_entry = error->dev;
  1597. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1598. ipr_err_separator;
  1599. ipr_err("Device %d : %s", i + 1,
  1600. __ipr_format_res_path(dev_entry->res_path,
  1601. buffer, sizeof(buffer)));
  1602. ipr_log_ext_vpd(&dev_entry->vpd);
  1603. ipr_err("-----New Device Information-----\n");
  1604. ipr_log_ext_vpd(&dev_entry->new_vpd);
  1605. ipr_err("Cache Directory Card Information:\n");
  1606. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1607. ipr_err("Adapter Card Information:\n");
  1608. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1609. }
  1610. }
  1611. /**
  1612. * ipr_log_config_error - Log a configuration error.
  1613. * @ioa_cfg: ioa config struct
  1614. * @hostrcb: hostrcb struct
  1615. *
  1616. * Return value:
  1617. * none
  1618. **/
  1619. static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1620. struct ipr_hostrcb *hostrcb)
  1621. {
  1622. int errors_logged, i;
  1623. struct ipr_hostrcb_device_data_entry *dev_entry;
  1624. struct ipr_hostrcb_type_03_error *error;
  1625. error = &hostrcb->hcam.u.error.u.type_03_error;
  1626. errors_logged = be32_to_cpu(error->errors_logged);
  1627. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1628. be32_to_cpu(error->errors_detected), errors_logged);
  1629. dev_entry = error->dev;
  1630. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1631. ipr_err_separator;
  1632. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1633. ipr_log_vpd(&dev_entry->vpd);
  1634. ipr_err("-----New Device Information-----\n");
  1635. ipr_log_vpd(&dev_entry->new_vpd);
  1636. ipr_err("Cache Directory Card Information:\n");
  1637. ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1638. ipr_err("Adapter Card Information:\n");
  1639. ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1640. ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
  1641. be32_to_cpu(dev_entry->ioa_data[0]),
  1642. be32_to_cpu(dev_entry->ioa_data[1]),
  1643. be32_to_cpu(dev_entry->ioa_data[2]),
  1644. be32_to_cpu(dev_entry->ioa_data[3]),
  1645. be32_to_cpu(dev_entry->ioa_data[4]));
  1646. }
  1647. }
  1648. /**
  1649. * ipr_log_enhanced_array_error - Log an array configuration error.
  1650. * @ioa_cfg: ioa config struct
  1651. * @hostrcb: hostrcb struct
  1652. *
  1653. * Return value:
  1654. * none
  1655. **/
  1656. static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1657. struct ipr_hostrcb *hostrcb)
  1658. {
  1659. int i, num_entries;
  1660. struct ipr_hostrcb_type_14_error *error;
  1661. struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
  1662. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1663. error = &hostrcb->hcam.u.error.u.type_14_error;
  1664. ipr_err_separator;
  1665. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1666. error->protection_level,
  1667. ioa_cfg->host->host_no,
  1668. error->last_func_vset_res_addr.bus,
  1669. error->last_func_vset_res_addr.target,
  1670. error->last_func_vset_res_addr.lun);
  1671. ipr_err_separator;
  1672. array_entry = error->array_member;
  1673. num_entries = min_t(u32, be32_to_cpu(error->num_entries),
  1674. ARRAY_SIZE(error->array_member));
  1675. for (i = 0; i < num_entries; i++, array_entry++) {
  1676. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1677. continue;
  1678. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1679. ipr_err("Exposed Array Member %d:\n", i);
  1680. else
  1681. ipr_err("Array Member %d:\n", i);
  1682. ipr_log_ext_vpd(&array_entry->vpd);
  1683. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1684. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1685. "Expected Location");
  1686. ipr_err_separator;
  1687. }
  1688. }
  1689. /**
  1690. * ipr_log_array_error - Log an array configuration error.
  1691. * @ioa_cfg: ioa config struct
  1692. * @hostrcb: hostrcb struct
  1693. *
  1694. * Return value:
  1695. * none
  1696. **/
  1697. static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1698. struct ipr_hostrcb *hostrcb)
  1699. {
  1700. int i;
  1701. struct ipr_hostrcb_type_04_error *error;
  1702. struct ipr_hostrcb_array_data_entry *array_entry;
  1703. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1704. error = &hostrcb->hcam.u.error.u.type_04_error;
  1705. ipr_err_separator;
  1706. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1707. error->protection_level,
  1708. ioa_cfg->host->host_no,
  1709. error->last_func_vset_res_addr.bus,
  1710. error->last_func_vset_res_addr.target,
  1711. error->last_func_vset_res_addr.lun);
  1712. ipr_err_separator;
  1713. array_entry = error->array_member;
  1714. for (i = 0; i < 18; i++) {
  1715. if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1716. continue;
  1717. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1718. ipr_err("Exposed Array Member %d:\n", i);
  1719. else
  1720. ipr_err("Array Member %d:\n", i);
  1721. ipr_log_vpd(&array_entry->vpd);
  1722. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1723. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1724. "Expected Location");
  1725. ipr_err_separator;
  1726. if (i == 9)
  1727. array_entry = error->array_member2;
  1728. else
  1729. array_entry++;
  1730. }
  1731. }
  1732. /**
  1733. * ipr_log_hex_data - Log additional hex IOA error data.
  1734. * @ioa_cfg: ioa config struct
  1735. * @data: IOA error data
  1736. * @len: data length
  1737. *
  1738. * Return value:
  1739. * none
  1740. **/
  1741. static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, __be32 *data, int len)
  1742. {
  1743. int i;
  1744. if (len == 0)
  1745. return;
  1746. if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
  1747. len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
  1748. for (i = 0; i < len / 4; i += 4) {
  1749. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  1750. be32_to_cpu(data[i]),
  1751. be32_to_cpu(data[i+1]),
  1752. be32_to_cpu(data[i+2]),
  1753. be32_to_cpu(data[i+3]));
  1754. }
  1755. }
  1756. /**
  1757. * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
  1758. * @ioa_cfg: ioa config struct
  1759. * @hostrcb: hostrcb struct
  1760. *
  1761. * Return value:
  1762. * none
  1763. **/
  1764. static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1765. struct ipr_hostrcb *hostrcb)
  1766. {
  1767. struct ipr_hostrcb_type_17_error *error;
  1768. if (ioa_cfg->sis64)
  1769. error = &hostrcb->hcam.u.error64.u.type_17_error;
  1770. else
  1771. error = &hostrcb->hcam.u.error.u.type_17_error;
  1772. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1773. strim(error->failure_reason);
  1774. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1775. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1776. ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1777. ipr_log_hex_data(ioa_cfg, error->data,
  1778. be32_to_cpu(hostrcb->hcam.length) -
  1779. (offsetof(struct ipr_hostrcb_error, u) +
  1780. offsetof(struct ipr_hostrcb_type_17_error, data)));
  1781. }
  1782. /**
  1783. * ipr_log_dual_ioa_error - Log a dual adapter error.
  1784. * @ioa_cfg: ioa config struct
  1785. * @hostrcb: hostrcb struct
  1786. *
  1787. * Return value:
  1788. * none
  1789. **/
  1790. static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1791. struct ipr_hostrcb *hostrcb)
  1792. {
  1793. struct ipr_hostrcb_type_07_error *error;
  1794. error = &hostrcb->hcam.u.error.u.type_07_error;
  1795. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1796. strim(error->failure_reason);
  1797. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1798. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1799. ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1800. ipr_log_hex_data(ioa_cfg, error->data,
  1801. be32_to_cpu(hostrcb->hcam.length) -
  1802. (offsetof(struct ipr_hostrcb_error, u) +
  1803. offsetof(struct ipr_hostrcb_type_07_error, data)));
  1804. }
  1805. static const struct {
  1806. u8 active;
  1807. char *desc;
  1808. } path_active_desc[] = {
  1809. { IPR_PATH_NO_INFO, "Path" },
  1810. { IPR_PATH_ACTIVE, "Active path" },
  1811. { IPR_PATH_NOT_ACTIVE, "Inactive path" }
  1812. };
  1813. static const struct {
  1814. u8 state;
  1815. char *desc;
  1816. } path_state_desc[] = {
  1817. { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
  1818. { IPR_PATH_HEALTHY, "is healthy" },
  1819. { IPR_PATH_DEGRADED, "is degraded" },
  1820. { IPR_PATH_FAILED, "is failed" }
  1821. };
  1822. /**
  1823. * ipr_log_fabric_path - Log a fabric path error
  1824. * @hostrcb: hostrcb struct
  1825. * @fabric: fabric descriptor
  1826. *
  1827. * Return value:
  1828. * none
  1829. **/
  1830. static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
  1831. struct ipr_hostrcb_fabric_desc *fabric)
  1832. {
  1833. int i, j;
  1834. u8 path_state = fabric->path_state;
  1835. u8 active = path_state & IPR_PATH_ACTIVE_MASK;
  1836. u8 state = path_state & IPR_PATH_STATE_MASK;
  1837. for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
  1838. if (path_active_desc[i].active != active)
  1839. continue;
  1840. for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
  1841. if (path_state_desc[j].state != state)
  1842. continue;
  1843. if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
  1844. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
  1845. path_active_desc[i].desc, path_state_desc[j].desc,
  1846. fabric->ioa_port);
  1847. } else if (fabric->cascaded_expander == 0xff) {
  1848. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
  1849. path_active_desc[i].desc, path_state_desc[j].desc,
  1850. fabric->ioa_port, fabric->phy);
  1851. } else if (fabric->phy == 0xff) {
  1852. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
  1853. path_active_desc[i].desc, path_state_desc[j].desc,
  1854. fabric->ioa_port, fabric->cascaded_expander);
  1855. } else {
  1856. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
  1857. path_active_desc[i].desc, path_state_desc[j].desc,
  1858. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1859. }
  1860. return;
  1861. }
  1862. }
  1863. ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
  1864. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1865. }
  1866. /**
  1867. * ipr_log64_fabric_path - Log a fabric path error
  1868. * @hostrcb: hostrcb struct
  1869. * @fabric: fabric descriptor
  1870. *
  1871. * Return value:
  1872. * none
  1873. **/
  1874. static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
  1875. struct ipr_hostrcb64_fabric_desc *fabric)
  1876. {
  1877. int i, j;
  1878. u8 path_state = fabric->path_state;
  1879. u8 active = path_state & IPR_PATH_ACTIVE_MASK;
  1880. u8 state = path_state & IPR_PATH_STATE_MASK;
  1881. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1882. for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
  1883. if (path_active_desc[i].active != active)
  1884. continue;
  1885. for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
  1886. if (path_state_desc[j].state != state)
  1887. continue;
  1888. ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
  1889. path_active_desc[i].desc, path_state_desc[j].desc,
  1890. ipr_format_res_path(hostrcb->ioa_cfg,
  1891. fabric->res_path,
  1892. buffer, sizeof(buffer)));
  1893. return;
  1894. }
  1895. }
  1896. ipr_err("Path state=%02X Resource Path=%s\n", path_state,
  1897. ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
  1898. buffer, sizeof(buffer)));
  1899. }
  1900. static const struct {
  1901. u8 type;
  1902. char *desc;
  1903. } path_type_desc[] = {
  1904. { IPR_PATH_CFG_IOA_PORT, "IOA port" },
  1905. { IPR_PATH_CFG_EXP_PORT, "Expander port" },
  1906. { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
  1907. { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
  1908. };
  1909. static const struct {
  1910. u8 status;
  1911. char *desc;
  1912. } path_status_desc[] = {
  1913. { IPR_PATH_CFG_NO_PROB, "Functional" },
  1914. { IPR_PATH_CFG_DEGRADED, "Degraded" },
  1915. { IPR_PATH_CFG_FAILED, "Failed" },
  1916. { IPR_PATH_CFG_SUSPECT, "Suspect" },
  1917. { IPR_PATH_NOT_DETECTED, "Missing" },
  1918. { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
  1919. };
  1920. static const char *link_rate[] = {
  1921. "unknown",
  1922. "disabled",
  1923. "phy reset problem",
  1924. "spinup hold",
  1925. "port selector",
  1926. "unknown",
  1927. "unknown",
  1928. "unknown",
  1929. "1.5Gbps",
  1930. "3.0Gbps",
  1931. "unknown",
  1932. "unknown",
  1933. "unknown",
  1934. "unknown",
  1935. "unknown",
  1936. "unknown"
  1937. };
  1938. /**
  1939. * ipr_log_path_elem - Log a fabric path element.
  1940. * @hostrcb: hostrcb struct
  1941. * @cfg: fabric path element struct
  1942. *
  1943. * Return value:
  1944. * none
  1945. **/
  1946. static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
  1947. struct ipr_hostrcb_config_element *cfg)
  1948. {
  1949. int i, j;
  1950. u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
  1951. u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
  1952. if (type == IPR_PATH_CFG_NOT_EXIST)
  1953. return;
  1954. for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
  1955. if (path_type_desc[i].type != type)
  1956. continue;
  1957. for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
  1958. if (path_status_desc[j].status != status)
  1959. continue;
  1960. if (type == IPR_PATH_CFG_IOA_PORT) {
  1961. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
  1962. path_status_desc[j].desc, path_type_desc[i].desc,
  1963. cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1964. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1965. } else {
  1966. if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
  1967. ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
  1968. path_status_desc[j].desc, path_type_desc[i].desc,
  1969. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1970. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1971. } else if (cfg->cascaded_expander == 0xff) {
  1972. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
  1973. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1974. path_type_desc[i].desc, cfg->phy,
  1975. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1976. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1977. } else if (cfg->phy == 0xff) {
  1978. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
  1979. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1980. path_type_desc[i].desc, cfg->cascaded_expander,
  1981. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1982. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1983. } else {
  1984. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
  1985. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1986. path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
  1987. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1988. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1989. }
  1990. }
  1991. return;
  1992. }
  1993. }
  1994. ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
  1995. "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
  1996. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1997. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1998. }
  1999. /**
  2000. * ipr_log64_path_elem - Log a fabric path element.
  2001. * @hostrcb: hostrcb struct
  2002. * @cfg: fabric path element struct
  2003. *
  2004. * Return value:
  2005. * none
  2006. **/
  2007. static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
  2008. struct ipr_hostrcb64_config_element *cfg)
  2009. {
  2010. int i, j;
  2011. u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
  2012. u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
  2013. u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
  2014. char buffer[IPR_MAX_RES_PATH_LENGTH];
  2015. if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
  2016. return;
  2017. for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
  2018. if (path_type_desc[i].type != type)
  2019. continue;
  2020. for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
  2021. if (path_status_desc[j].status != status)
  2022. continue;
  2023. ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
  2024. path_status_desc[j].desc, path_type_desc[i].desc,
  2025. ipr_format_res_path(hostrcb->ioa_cfg,
  2026. cfg->res_path, buffer, sizeof(buffer)),
  2027. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  2028. be32_to_cpu(cfg->wwid[0]),
  2029. be32_to_cpu(cfg->wwid[1]));
  2030. return;
  2031. }
  2032. }
  2033. ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
  2034. "WWN=%08X%08X\n", cfg->type_status,
  2035. ipr_format_res_path(hostrcb->ioa_cfg,
  2036. cfg->res_path, buffer, sizeof(buffer)),
  2037. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  2038. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  2039. }
  2040. /**
  2041. * ipr_log_fabric_error - Log a fabric error.
  2042. * @ioa_cfg: ioa config struct
  2043. * @hostrcb: hostrcb struct
  2044. *
  2045. * Return value:
  2046. * none
  2047. **/
  2048. static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
  2049. struct ipr_hostrcb *hostrcb)
  2050. {
  2051. struct ipr_hostrcb_type_20_error *error;
  2052. struct ipr_hostrcb_fabric_desc *fabric;
  2053. struct ipr_hostrcb_config_element *cfg;
  2054. int i, add_len;
  2055. error = &hostrcb->hcam.u.error.u.type_20_error;
  2056. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  2057. ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
  2058. add_len = be32_to_cpu(hostrcb->hcam.length) -
  2059. (offsetof(struct ipr_hostrcb_error, u) +
  2060. offsetof(struct ipr_hostrcb_type_20_error, desc));
  2061. for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
  2062. ipr_log_fabric_path(hostrcb, fabric);
  2063. for_each_fabric_cfg(fabric, cfg)
  2064. ipr_log_path_elem(hostrcb, cfg);
  2065. add_len -= be16_to_cpu(fabric->length);
  2066. fabric = (struct ipr_hostrcb_fabric_desc *)
  2067. ((unsigned long)fabric + be16_to_cpu(fabric->length));
  2068. }
  2069. ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
  2070. }
  2071. /**
  2072. * ipr_log_sis64_array_error - Log a sis64 array error.
  2073. * @ioa_cfg: ioa config struct
  2074. * @hostrcb: hostrcb struct
  2075. *
  2076. * Return value:
  2077. * none
  2078. **/
  2079. static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
  2080. struct ipr_hostrcb *hostrcb)
  2081. {
  2082. int i, num_entries;
  2083. struct ipr_hostrcb_type_24_error *error;
  2084. struct ipr_hostrcb64_array_data_entry *array_entry;
  2085. char buffer[IPR_MAX_RES_PATH_LENGTH];
  2086. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  2087. error = &hostrcb->hcam.u.error64.u.type_24_error;
  2088. ipr_err_separator;
  2089. ipr_err("RAID %s Array Configuration: %s\n",
  2090. error->protection_level,
  2091. ipr_format_res_path(ioa_cfg, error->last_res_path,
  2092. buffer, sizeof(buffer)));
  2093. ipr_err_separator;
  2094. array_entry = error->array_member;
  2095. num_entries = min_t(u32, error->num_entries,
  2096. ARRAY_SIZE(error->array_member));
  2097. for (i = 0; i < num_entries; i++, array_entry++) {
  2098. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  2099. continue;
  2100. if (error->exposed_mode_adn == i)
  2101. ipr_err("Exposed Array Member %d:\n", i);
  2102. else
  2103. ipr_err("Array Member %d:\n", i);
  2104. ipr_err("Array Member %d:\n", i);
  2105. ipr_log_ext_vpd(&array_entry->vpd);
  2106. ipr_err("Current Location: %s\n",
  2107. ipr_format_res_path(ioa_cfg, array_entry->res_path,
  2108. buffer, sizeof(buffer)));
  2109. ipr_err("Expected Location: %s\n",
  2110. ipr_format_res_path(ioa_cfg,
  2111. array_entry->expected_res_path,
  2112. buffer, sizeof(buffer)));
  2113. ipr_err_separator;
  2114. }
  2115. }
  2116. /**
  2117. * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
  2118. * @ioa_cfg: ioa config struct
  2119. * @hostrcb: hostrcb struct
  2120. *
  2121. * Return value:
  2122. * none
  2123. **/
  2124. static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
  2125. struct ipr_hostrcb *hostrcb)
  2126. {
  2127. struct ipr_hostrcb_type_30_error *error;
  2128. struct ipr_hostrcb64_fabric_desc *fabric;
  2129. struct ipr_hostrcb64_config_element *cfg;
  2130. int i, add_len;
  2131. error = &hostrcb->hcam.u.error64.u.type_30_error;
  2132. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  2133. ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
  2134. add_len = be32_to_cpu(hostrcb->hcam.length) -
  2135. (offsetof(struct ipr_hostrcb64_error, u) +
  2136. offsetof(struct ipr_hostrcb_type_30_error, desc));
  2137. for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
  2138. ipr_log64_fabric_path(hostrcb, fabric);
  2139. for_each_fabric_cfg(fabric, cfg)
  2140. ipr_log64_path_elem(hostrcb, cfg);
  2141. add_len -= be16_to_cpu(fabric->length);
  2142. fabric = (struct ipr_hostrcb64_fabric_desc *)
  2143. ((unsigned long)fabric + be16_to_cpu(fabric->length));
  2144. }
  2145. ipr_log_hex_data(ioa_cfg, (__be32 *)fabric, add_len);
  2146. }
  2147. /**
  2148. * ipr_log_sis64_service_required_error - Log a sis64 service required error.
  2149. * @ioa_cfg: ioa config struct
  2150. * @hostrcb: hostrcb struct
  2151. *
  2152. * Return value:
  2153. * none
  2154. **/
  2155. static void ipr_log_sis64_service_required_error(struct ipr_ioa_cfg *ioa_cfg,
  2156. struct ipr_hostrcb *hostrcb)
  2157. {
  2158. struct ipr_hostrcb_type_41_error *error;
  2159. error = &hostrcb->hcam.u.error64.u.type_41_error;
  2160. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  2161. ipr_err("Primary Failure Reason: %s\n", error->failure_reason);
  2162. ipr_log_hex_data(ioa_cfg, error->data,
  2163. be32_to_cpu(hostrcb->hcam.length) -
  2164. (offsetof(struct ipr_hostrcb_error, u) +
  2165. offsetof(struct ipr_hostrcb_type_41_error, data)));
  2166. }
  2167. /**
  2168. * ipr_log_generic_error - Log an adapter error.
  2169. * @ioa_cfg: ioa config struct
  2170. * @hostrcb: hostrcb struct
  2171. *
  2172. * Return value:
  2173. * none
  2174. **/
  2175. static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
  2176. struct ipr_hostrcb *hostrcb)
  2177. {
  2178. ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
  2179. be32_to_cpu(hostrcb->hcam.length));
  2180. }
  2181. /**
  2182. * ipr_log_sis64_device_error - Log a cache error.
  2183. * @ioa_cfg: ioa config struct
  2184. * @hostrcb: hostrcb struct
  2185. *
  2186. * Return value:
  2187. * none
  2188. **/
  2189. static void ipr_log_sis64_device_error(struct ipr_ioa_cfg *ioa_cfg,
  2190. struct ipr_hostrcb *hostrcb)
  2191. {
  2192. struct ipr_hostrcb_type_21_error *error;
  2193. char buffer[IPR_MAX_RES_PATH_LENGTH];
  2194. error = &hostrcb->hcam.u.error64.u.type_21_error;
  2195. ipr_err("-----Failing Device Information-----\n");
  2196. ipr_err("World Wide Unique ID: %08X%08X%08X%08X\n",
  2197. be32_to_cpu(error->wwn[0]), be32_to_cpu(error->wwn[1]),
  2198. be32_to_cpu(error->wwn[2]), be32_to_cpu(error->wwn[3]));
  2199. ipr_err("Device Resource Path: %s\n",
  2200. __ipr_format_res_path(error->res_path,
  2201. buffer, sizeof(buffer)));
  2202. error->primary_problem_desc[sizeof(error->primary_problem_desc) - 1] = '\0';
  2203. error->second_problem_desc[sizeof(error->second_problem_desc) - 1] = '\0';
  2204. ipr_err("Primary Problem Description: %s\n", error->primary_problem_desc);
  2205. ipr_err("Secondary Problem Description: %s\n", error->second_problem_desc);
  2206. ipr_err("SCSI Sense Data:\n");
  2207. ipr_log_hex_data(ioa_cfg, error->sense_data, sizeof(error->sense_data));
  2208. ipr_err("SCSI Command Descriptor Block: \n");
  2209. ipr_log_hex_data(ioa_cfg, error->cdb, sizeof(error->cdb));
  2210. ipr_err("Additional IOA Data:\n");
  2211. ipr_log_hex_data(ioa_cfg, error->ioa_data, be32_to_cpu(error->length_of_error));
  2212. }
  2213. /**
  2214. * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
  2215. * @ioasc: IOASC
  2216. *
  2217. * This function will return the index of into the ipr_error_table
  2218. * for the specified IOASC. If the IOASC is not in the table,
  2219. * 0 will be returned, which points to the entry used for unknown errors.
  2220. *
  2221. * Return value:
  2222. * index into the ipr_error_table
  2223. **/
  2224. static u32 ipr_get_error(u32 ioasc)
  2225. {
  2226. int i;
  2227. for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
  2228. if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
  2229. return i;
  2230. return 0;
  2231. }
  2232. /**
  2233. * ipr_handle_log_data - Log an adapter error.
  2234. * @ioa_cfg: ioa config struct
  2235. * @hostrcb: hostrcb struct
  2236. *
  2237. * This function logs an adapter error to the system.
  2238. *
  2239. * Return value:
  2240. * none
  2241. **/
  2242. static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
  2243. struct ipr_hostrcb *hostrcb)
  2244. {
  2245. u32 ioasc;
  2246. int error_index;
  2247. struct ipr_hostrcb_type_21_error *error;
  2248. if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
  2249. return;
  2250. if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
  2251. dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
  2252. if (ioa_cfg->sis64)
  2253. ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
  2254. else
  2255. ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  2256. if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
  2257. ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
  2258. /* Tell the midlayer we had a bus reset so it will handle the UA properly */
  2259. scsi_report_bus_reset(ioa_cfg->host,
  2260. hostrcb->hcam.u.error.fd_res_addr.bus);
  2261. }
  2262. error_index = ipr_get_error(ioasc);
  2263. if (!ipr_error_table[error_index].log_hcam)
  2264. return;
  2265. if (ioasc == IPR_IOASC_HW_CMD_FAILED &&
  2266. hostrcb->hcam.overlay_id == IPR_HOST_RCB_OVERLAY_ID_21) {
  2267. error = &hostrcb->hcam.u.error64.u.type_21_error;
  2268. if (((be32_to_cpu(error->sense_data[0]) & 0x0000ff00) >> 8) == ILLEGAL_REQUEST &&
  2269. ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
  2270. return;
  2271. }
  2272. ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
  2273. /* Set indication we have logged an error */
  2274. ioa_cfg->errors_logged++;
  2275. if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
  2276. return;
  2277. if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
  2278. hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
  2279. switch (hostrcb->hcam.overlay_id) {
  2280. case IPR_HOST_RCB_OVERLAY_ID_2:
  2281. ipr_log_cache_error(ioa_cfg, hostrcb);
  2282. break;
  2283. case IPR_HOST_RCB_OVERLAY_ID_3:
  2284. ipr_log_config_error(ioa_cfg, hostrcb);
  2285. break;
  2286. case IPR_HOST_RCB_OVERLAY_ID_4:
  2287. case IPR_HOST_RCB_OVERLAY_ID_6:
  2288. ipr_log_array_error(ioa_cfg, hostrcb);
  2289. break;
  2290. case IPR_HOST_RCB_OVERLAY_ID_7:
  2291. ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
  2292. break;
  2293. case IPR_HOST_RCB_OVERLAY_ID_12:
  2294. ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
  2295. break;
  2296. case IPR_HOST_RCB_OVERLAY_ID_13:
  2297. ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
  2298. break;
  2299. case IPR_HOST_RCB_OVERLAY_ID_14:
  2300. case IPR_HOST_RCB_OVERLAY_ID_16:
  2301. ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
  2302. break;
  2303. case IPR_HOST_RCB_OVERLAY_ID_17:
  2304. ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
  2305. break;
  2306. case IPR_HOST_RCB_OVERLAY_ID_20:
  2307. ipr_log_fabric_error(ioa_cfg, hostrcb);
  2308. break;
  2309. case IPR_HOST_RCB_OVERLAY_ID_21:
  2310. ipr_log_sis64_device_error(ioa_cfg, hostrcb);
  2311. break;
  2312. case IPR_HOST_RCB_OVERLAY_ID_23:
  2313. ipr_log_sis64_config_error(ioa_cfg, hostrcb);
  2314. break;
  2315. case IPR_HOST_RCB_OVERLAY_ID_24:
  2316. case IPR_HOST_RCB_OVERLAY_ID_26:
  2317. ipr_log_sis64_array_error(ioa_cfg, hostrcb);
  2318. break;
  2319. case IPR_HOST_RCB_OVERLAY_ID_30:
  2320. ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
  2321. break;
  2322. case IPR_HOST_RCB_OVERLAY_ID_41:
  2323. ipr_log_sis64_service_required_error(ioa_cfg, hostrcb);
  2324. break;
  2325. case IPR_HOST_RCB_OVERLAY_ID_1:
  2326. case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
  2327. default:
  2328. ipr_log_generic_error(ioa_cfg, hostrcb);
  2329. break;
  2330. }
  2331. }
  2332. static struct ipr_hostrcb *ipr_get_free_hostrcb(struct ipr_ioa_cfg *ioa)
  2333. {
  2334. struct ipr_hostrcb *hostrcb;
  2335. hostrcb = list_first_entry_or_null(&ioa->hostrcb_free_q,
  2336. struct ipr_hostrcb, queue);
  2337. if (unlikely(!hostrcb)) {
  2338. dev_info(&ioa->pdev->dev, "Reclaiming async error buffers.");
  2339. hostrcb = list_first_entry_or_null(&ioa->hostrcb_report_q,
  2340. struct ipr_hostrcb, queue);
  2341. }
  2342. list_del_init(&hostrcb->queue);
  2343. return hostrcb;
  2344. }
  2345. /**
  2346. * ipr_process_error - Op done function for an adapter error log.
  2347. * @ipr_cmd: ipr command struct
  2348. *
  2349. * This function is the op done function for an error log host
  2350. * controlled async from the adapter. It will log the error and
  2351. * send the HCAM back to the adapter.
  2352. *
  2353. * Return value:
  2354. * none
  2355. **/
  2356. static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
  2357. {
  2358. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2359. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  2360. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  2361. u32 fd_ioasc;
  2362. if (ioa_cfg->sis64)
  2363. fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
  2364. else
  2365. fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  2366. list_del_init(&hostrcb->queue);
  2367. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  2368. if (!ioasc) {
  2369. ipr_handle_log_data(ioa_cfg, hostrcb);
  2370. if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
  2371. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  2372. } else if (ioasc != IPR_IOASC_IOA_WAS_RESET &&
  2373. ioasc != IPR_IOASC_ABORTED_CMD_TERM_BY_HOST) {
  2374. dev_err(&ioa_cfg->pdev->dev,
  2375. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  2376. }
  2377. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_report_q);
  2378. schedule_work(&ioa_cfg->work_q);
  2379. hostrcb = ipr_get_free_hostrcb(ioa_cfg);
  2380. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  2381. }
  2382. /**
  2383. * ipr_timeout - An internally generated op has timed out.
  2384. * @ipr_cmd: ipr command struct
  2385. *
  2386. * This function blocks host requests and initiates an
  2387. * adapter reset.
  2388. *
  2389. * Return value:
  2390. * none
  2391. **/
  2392. static void ipr_timeout(struct timer_list *t)
  2393. {
  2394. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  2395. unsigned long lock_flags = 0;
  2396. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2397. ENTER;
  2398. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2399. ioa_cfg->errors_logged++;
  2400. dev_err(&ioa_cfg->pdev->dev,
  2401. "Adapter being reset due to command timeout.\n");
  2402. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2403. ioa_cfg->sdt_state = GET_DUMP;
  2404. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
  2405. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2406. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2407. LEAVE;
  2408. }
  2409. /**
  2410. * ipr_oper_timeout - Adapter timed out transitioning to operational
  2411. * @ipr_cmd: ipr command struct
  2412. *
  2413. * This function blocks host requests and initiates an
  2414. * adapter reset.
  2415. *
  2416. * Return value:
  2417. * none
  2418. **/
  2419. static void ipr_oper_timeout(struct timer_list *t)
  2420. {
  2421. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  2422. unsigned long lock_flags = 0;
  2423. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2424. ENTER;
  2425. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2426. ioa_cfg->errors_logged++;
  2427. dev_err(&ioa_cfg->pdev->dev,
  2428. "Adapter timed out transitioning to operational.\n");
  2429. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2430. ioa_cfg->sdt_state = GET_DUMP;
  2431. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
  2432. if (ipr_fastfail)
  2433. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  2434. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2435. }
  2436. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2437. LEAVE;
  2438. }
  2439. /**
  2440. * ipr_find_ses_entry - Find matching SES in SES table
  2441. * @res: resource entry struct of SES
  2442. *
  2443. * Return value:
  2444. * pointer to SES table entry / NULL on failure
  2445. **/
  2446. static const struct ipr_ses_table_entry *
  2447. ipr_find_ses_entry(struct ipr_resource_entry *res)
  2448. {
  2449. int i, j, matches;
  2450. struct ipr_std_inq_vpids *vpids;
  2451. const struct ipr_ses_table_entry *ste = ipr_ses_table;
  2452. for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
  2453. for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
  2454. if (ste->compare_product_id_byte[j] == 'X') {
  2455. vpids = &res->std_inq_data.vpids;
  2456. if (vpids->product_id[j] == ste->product_id[j])
  2457. matches++;
  2458. else
  2459. break;
  2460. } else
  2461. matches++;
  2462. }
  2463. if (matches == IPR_PROD_ID_LEN)
  2464. return ste;
  2465. }
  2466. return NULL;
  2467. }
  2468. /**
  2469. * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
  2470. * @ioa_cfg: ioa config struct
  2471. * @bus: SCSI bus
  2472. * @bus_width: bus width
  2473. *
  2474. * Return value:
  2475. * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
  2476. * For a 2-byte wide SCSI bus, the maximum transfer speed is
  2477. * twice the maximum transfer rate (e.g. for a wide enabled bus,
  2478. * max 160MHz = max 320MB/sec).
  2479. **/
  2480. static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
  2481. {
  2482. struct ipr_resource_entry *res;
  2483. const struct ipr_ses_table_entry *ste;
  2484. u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
  2485. /* Loop through each config table entry in the config table buffer */
  2486. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2487. if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
  2488. continue;
  2489. if (bus != res->bus)
  2490. continue;
  2491. if (!(ste = ipr_find_ses_entry(res)))
  2492. continue;
  2493. max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
  2494. }
  2495. return max_xfer_rate;
  2496. }
  2497. /**
  2498. * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
  2499. * @ioa_cfg: ioa config struct
  2500. * @max_delay: max delay in micro-seconds to wait
  2501. *
  2502. * Waits for an IODEBUG ACK from the IOA, doing busy looping.
  2503. *
  2504. * Return value:
  2505. * 0 on success / other on failure
  2506. **/
  2507. static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
  2508. {
  2509. volatile u32 pcii_reg;
  2510. int delay = 1;
  2511. /* Read interrupt reg until IOA signals IO Debug Acknowledge */
  2512. while (delay < max_delay) {
  2513. pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  2514. if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
  2515. return 0;
  2516. /* udelay cannot be used if delay is more than a few milliseconds */
  2517. if ((delay / 1000) > MAX_UDELAY_MS)
  2518. mdelay(delay / 1000);
  2519. else
  2520. udelay(delay);
  2521. delay += delay;
  2522. }
  2523. return -EIO;
  2524. }
  2525. /**
  2526. * ipr_get_sis64_dump_data_section - Dump IOA memory
  2527. * @ioa_cfg: ioa config struct
  2528. * @start_addr: adapter address to dump
  2529. * @dest: destination kernel buffer
  2530. * @length_in_words: length to dump in 4 byte words
  2531. *
  2532. * Return value:
  2533. * 0 on success
  2534. **/
  2535. static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  2536. u32 start_addr,
  2537. __be32 *dest, u32 length_in_words)
  2538. {
  2539. int i;
  2540. for (i = 0; i < length_in_words; i++) {
  2541. writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
  2542. *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
  2543. dest++;
  2544. }
  2545. return 0;
  2546. }
  2547. /**
  2548. * ipr_get_ldump_data_section - Dump IOA memory
  2549. * @ioa_cfg: ioa config struct
  2550. * @start_addr: adapter address to dump
  2551. * @dest: destination kernel buffer
  2552. * @length_in_words: length to dump in 4 byte words
  2553. *
  2554. * Return value:
  2555. * 0 on success / -EIO on failure
  2556. **/
  2557. static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  2558. u32 start_addr,
  2559. __be32 *dest, u32 length_in_words)
  2560. {
  2561. volatile u32 temp_pcii_reg;
  2562. int i, delay = 0;
  2563. if (ioa_cfg->sis64)
  2564. return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
  2565. dest, length_in_words);
  2566. /* Write IOA interrupt reg starting LDUMP state */
  2567. writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
  2568. ioa_cfg->regs.set_uproc_interrupt_reg32);
  2569. /* Wait for IO debug acknowledge */
  2570. if (ipr_wait_iodbg_ack(ioa_cfg,
  2571. IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
  2572. dev_err(&ioa_cfg->pdev->dev,
  2573. "IOA dump long data transfer timeout\n");
  2574. return -EIO;
  2575. }
  2576. /* Signal LDUMP interlocked - clear IO debug ack */
  2577. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2578. ioa_cfg->regs.clr_interrupt_reg);
  2579. /* Write Mailbox with starting address */
  2580. writel(start_addr, ioa_cfg->ioa_mailbox);
  2581. /* Signal address valid - clear IOA Reset alert */
  2582. writel(IPR_UPROCI_RESET_ALERT,
  2583. ioa_cfg->regs.clr_uproc_interrupt_reg32);
  2584. for (i = 0; i < length_in_words; i++) {
  2585. /* Wait for IO debug acknowledge */
  2586. if (ipr_wait_iodbg_ack(ioa_cfg,
  2587. IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
  2588. dev_err(&ioa_cfg->pdev->dev,
  2589. "IOA dump short data transfer timeout\n");
  2590. return -EIO;
  2591. }
  2592. /* Read data from mailbox and increment destination pointer */
  2593. *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
  2594. dest++;
  2595. /* For all but the last word of data, signal data received */
  2596. if (i < (length_in_words - 1)) {
  2597. /* Signal dump data received - Clear IO debug Ack */
  2598. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2599. ioa_cfg->regs.clr_interrupt_reg);
  2600. }
  2601. }
  2602. /* Signal end of block transfer. Set reset alert then clear IO debug ack */
  2603. writel(IPR_UPROCI_RESET_ALERT,
  2604. ioa_cfg->regs.set_uproc_interrupt_reg32);
  2605. writel(IPR_UPROCI_IO_DEBUG_ALERT,
  2606. ioa_cfg->regs.clr_uproc_interrupt_reg32);
  2607. /* Signal dump data received - Clear IO debug Ack */
  2608. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2609. ioa_cfg->regs.clr_interrupt_reg);
  2610. /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
  2611. while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
  2612. temp_pcii_reg =
  2613. readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
  2614. if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
  2615. return 0;
  2616. udelay(10);
  2617. delay += 10;
  2618. }
  2619. return 0;
  2620. }
  2621. #ifdef CONFIG_SCSI_IPR_DUMP
  2622. /**
  2623. * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
  2624. * @ioa_cfg: ioa config struct
  2625. * @pci_address: adapter address
  2626. * @length: length of data to copy
  2627. *
  2628. * Copy data from PCI adapter to kernel buffer.
  2629. * Note: length MUST be a 4 byte multiple
  2630. * Return value:
  2631. * 0 on success / other on failure
  2632. **/
  2633. static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
  2634. unsigned long pci_address, u32 length)
  2635. {
  2636. int bytes_copied = 0;
  2637. int cur_len, rc, rem_len, rem_page_len, max_dump_size;
  2638. __be32 *page;
  2639. unsigned long lock_flags = 0;
  2640. struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
  2641. if (ioa_cfg->sis64)
  2642. max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
  2643. else
  2644. max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
  2645. while (bytes_copied < length &&
  2646. (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
  2647. if (ioa_dump->page_offset >= PAGE_SIZE ||
  2648. ioa_dump->page_offset == 0) {
  2649. page = (__be32 *)__get_free_page(GFP_ATOMIC);
  2650. if (!page) {
  2651. ipr_trace;
  2652. return bytes_copied;
  2653. }
  2654. ioa_dump->page_offset = 0;
  2655. ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
  2656. ioa_dump->next_page_index++;
  2657. } else
  2658. page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
  2659. rem_len = length - bytes_copied;
  2660. rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
  2661. cur_len = min(rem_len, rem_page_len);
  2662. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2663. if (ioa_cfg->sdt_state == ABORT_DUMP) {
  2664. rc = -EIO;
  2665. } else {
  2666. rc = ipr_get_ldump_data_section(ioa_cfg,
  2667. pci_address + bytes_copied,
  2668. &page[ioa_dump->page_offset / 4],
  2669. (cur_len / sizeof(u32)));
  2670. }
  2671. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2672. if (!rc) {
  2673. ioa_dump->page_offset += cur_len;
  2674. bytes_copied += cur_len;
  2675. } else {
  2676. ipr_trace;
  2677. break;
  2678. }
  2679. schedule();
  2680. }
  2681. return bytes_copied;
  2682. }
  2683. /**
  2684. * ipr_init_dump_entry_hdr - Initialize a dump entry header.
  2685. * @hdr: dump entry header struct
  2686. *
  2687. * Return value:
  2688. * nothing
  2689. **/
  2690. static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
  2691. {
  2692. hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
  2693. hdr->num_elems = 1;
  2694. hdr->offset = sizeof(*hdr);
  2695. hdr->status = IPR_DUMP_STATUS_SUCCESS;
  2696. }
  2697. /**
  2698. * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
  2699. * @ioa_cfg: ioa config struct
  2700. * @driver_dump: driver dump struct
  2701. *
  2702. * Return value:
  2703. * nothing
  2704. **/
  2705. static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
  2706. struct ipr_driver_dump *driver_dump)
  2707. {
  2708. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  2709. ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
  2710. driver_dump->ioa_type_entry.hdr.len =
  2711. sizeof(struct ipr_dump_ioa_type_entry) -
  2712. sizeof(struct ipr_dump_entry_header);
  2713. driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2714. driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
  2715. driver_dump->ioa_type_entry.type = ioa_cfg->type;
  2716. driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
  2717. (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
  2718. ucode_vpd->minor_release[1];
  2719. driver_dump->hdr.num_entries++;
  2720. }
  2721. /**
  2722. * ipr_dump_version_data - Fill in the driver version in the dump.
  2723. * @ioa_cfg: ioa config struct
  2724. * @driver_dump: driver dump struct
  2725. *
  2726. * Return value:
  2727. * nothing
  2728. **/
  2729. static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
  2730. struct ipr_driver_dump *driver_dump)
  2731. {
  2732. ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
  2733. driver_dump->version_entry.hdr.len =
  2734. sizeof(struct ipr_dump_version_entry) -
  2735. sizeof(struct ipr_dump_entry_header);
  2736. driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  2737. driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
  2738. strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
  2739. driver_dump->hdr.num_entries++;
  2740. }
  2741. /**
  2742. * ipr_dump_trace_data - Fill in the IOA trace in the dump.
  2743. * @ioa_cfg: ioa config struct
  2744. * @driver_dump: driver dump struct
  2745. *
  2746. * Return value:
  2747. * nothing
  2748. **/
  2749. static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
  2750. struct ipr_driver_dump *driver_dump)
  2751. {
  2752. ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
  2753. driver_dump->trace_entry.hdr.len =
  2754. sizeof(struct ipr_dump_trace_entry) -
  2755. sizeof(struct ipr_dump_entry_header);
  2756. driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2757. driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
  2758. memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
  2759. driver_dump->hdr.num_entries++;
  2760. }
  2761. /**
  2762. * ipr_dump_location_data - Fill in the IOA location in the dump.
  2763. * @ioa_cfg: ioa config struct
  2764. * @driver_dump: driver dump struct
  2765. *
  2766. * Return value:
  2767. * nothing
  2768. **/
  2769. static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
  2770. struct ipr_driver_dump *driver_dump)
  2771. {
  2772. ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
  2773. driver_dump->location_entry.hdr.len =
  2774. sizeof(struct ipr_dump_location_entry) -
  2775. sizeof(struct ipr_dump_entry_header);
  2776. driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  2777. driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
  2778. strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
  2779. driver_dump->hdr.num_entries++;
  2780. }
  2781. /**
  2782. * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
  2783. * @ioa_cfg: ioa config struct
  2784. * @dump: dump struct
  2785. *
  2786. * Return value:
  2787. * nothing
  2788. **/
  2789. static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
  2790. {
  2791. unsigned long start_addr, sdt_word;
  2792. unsigned long lock_flags = 0;
  2793. struct ipr_driver_dump *driver_dump = &dump->driver_dump;
  2794. struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
  2795. u32 num_entries, max_num_entries, start_off, end_off;
  2796. u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
  2797. struct ipr_sdt *sdt;
  2798. int valid = 1;
  2799. int i;
  2800. ENTER;
  2801. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2802. if (ioa_cfg->sdt_state != READ_DUMP) {
  2803. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2804. return;
  2805. }
  2806. if (ioa_cfg->sis64) {
  2807. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2808. ssleep(IPR_DUMP_DELAY_SECONDS);
  2809. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2810. }
  2811. start_addr = readl(ioa_cfg->ioa_mailbox);
  2812. if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
  2813. dev_err(&ioa_cfg->pdev->dev,
  2814. "Invalid dump table format: %lx\n", start_addr);
  2815. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2816. return;
  2817. }
  2818. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
  2819. driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
  2820. /* Initialize the overall dump header */
  2821. driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
  2822. driver_dump->hdr.num_entries = 1;
  2823. driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
  2824. driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
  2825. driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
  2826. driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
  2827. ipr_dump_version_data(ioa_cfg, driver_dump);
  2828. ipr_dump_location_data(ioa_cfg, driver_dump);
  2829. ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
  2830. ipr_dump_trace_data(ioa_cfg, driver_dump);
  2831. /* Update dump_header */
  2832. driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
  2833. /* IOA Dump entry */
  2834. ipr_init_dump_entry_hdr(&ioa_dump->hdr);
  2835. ioa_dump->hdr.len = 0;
  2836. ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2837. ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
  2838. /* First entries in sdt are actually a list of dump addresses and
  2839. lengths to gather the real dump data. sdt represents the pointer
  2840. to the ioa generated dump table. Dump data will be extracted based
  2841. on entries in this table */
  2842. sdt = &ioa_dump->sdt;
  2843. if (ioa_cfg->sis64) {
  2844. max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
  2845. max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
  2846. } else {
  2847. max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
  2848. max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
  2849. }
  2850. bytes_to_copy = offsetof(struct ipr_sdt, entry) +
  2851. (max_num_entries * sizeof(struct ipr_sdt_entry));
  2852. rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
  2853. bytes_to_copy / sizeof(__be32));
  2854. /* Smart Dump table is ready to use and the first entry is valid */
  2855. if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
  2856. (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
  2857. dev_err(&ioa_cfg->pdev->dev,
  2858. "Dump of IOA failed. Dump table not valid: %d, %X.\n",
  2859. rc, be32_to_cpu(sdt->hdr.state));
  2860. driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
  2861. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2862. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2863. return;
  2864. }
  2865. num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
  2866. if (num_entries > max_num_entries)
  2867. num_entries = max_num_entries;
  2868. /* Update dump length to the actual data to be copied */
  2869. dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
  2870. if (ioa_cfg->sis64)
  2871. dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
  2872. else
  2873. dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
  2874. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2875. for (i = 0; i < num_entries; i++) {
  2876. if (ioa_dump->hdr.len > max_dump_size) {
  2877. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2878. break;
  2879. }
  2880. if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
  2881. sdt_word = be32_to_cpu(sdt->entry[i].start_token);
  2882. if (ioa_cfg->sis64)
  2883. bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
  2884. else {
  2885. start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
  2886. end_off = be32_to_cpu(sdt->entry[i].end_token);
  2887. if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
  2888. bytes_to_copy = end_off - start_off;
  2889. else
  2890. valid = 0;
  2891. }
  2892. if (valid) {
  2893. if (bytes_to_copy > max_dump_size) {
  2894. sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
  2895. continue;
  2896. }
  2897. /* Copy data from adapter to driver buffers */
  2898. bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
  2899. bytes_to_copy);
  2900. ioa_dump->hdr.len += bytes_copied;
  2901. if (bytes_copied != bytes_to_copy) {
  2902. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2903. break;
  2904. }
  2905. }
  2906. }
  2907. }
  2908. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
  2909. /* Update dump_header */
  2910. driver_dump->hdr.len += ioa_dump->hdr.len;
  2911. wmb();
  2912. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2913. LEAVE;
  2914. }
  2915. #else
  2916. #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
  2917. #endif
  2918. /**
  2919. * ipr_release_dump - Free adapter dump memory
  2920. * @kref: kref struct
  2921. *
  2922. * Return value:
  2923. * nothing
  2924. **/
  2925. static void ipr_release_dump(struct kref *kref)
  2926. {
  2927. struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
  2928. struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
  2929. unsigned long lock_flags = 0;
  2930. int i;
  2931. ENTER;
  2932. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2933. ioa_cfg->dump = NULL;
  2934. ioa_cfg->sdt_state = INACTIVE;
  2935. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2936. for (i = 0; i < dump->ioa_dump.next_page_index; i++)
  2937. free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
  2938. vfree(dump->ioa_dump.ioa_data);
  2939. kfree(dump);
  2940. LEAVE;
  2941. }
  2942. static void ipr_add_remove_thread(struct work_struct *work)
  2943. {
  2944. unsigned long lock_flags;
  2945. struct ipr_resource_entry *res;
  2946. struct scsi_device *sdev;
  2947. struct ipr_ioa_cfg *ioa_cfg =
  2948. container_of(work, struct ipr_ioa_cfg, scsi_add_work_q);
  2949. u8 bus, target, lun;
  2950. int did_work;
  2951. ENTER;
  2952. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2953. restart:
  2954. do {
  2955. did_work = 0;
  2956. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
  2957. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2958. return;
  2959. }
  2960. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2961. if (res->del_from_ml && res->sdev) {
  2962. did_work = 1;
  2963. sdev = res->sdev;
  2964. if (!scsi_device_get(sdev)) {
  2965. if (!res->add_to_ml)
  2966. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  2967. else
  2968. res->del_from_ml = 0;
  2969. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2970. scsi_remove_device(sdev);
  2971. scsi_device_put(sdev);
  2972. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2973. }
  2974. break;
  2975. }
  2976. }
  2977. } while (did_work);
  2978. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2979. if (res->add_to_ml) {
  2980. bus = res->bus;
  2981. target = res->target;
  2982. lun = res->lun;
  2983. res->add_to_ml = 0;
  2984. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2985. scsi_add_device(ioa_cfg->host, bus, target, lun);
  2986. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2987. goto restart;
  2988. }
  2989. }
  2990. ioa_cfg->scan_done = 1;
  2991. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2992. kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
  2993. LEAVE;
  2994. }
  2995. /**
  2996. * ipr_worker_thread - Worker thread
  2997. * @work: ioa config struct
  2998. *
  2999. * Called at task level from a work thread. This function takes care
  3000. * of adding and removing device from the mid-layer as configuration
  3001. * changes are detected by the adapter.
  3002. *
  3003. * Return value:
  3004. * nothing
  3005. **/
  3006. static void ipr_worker_thread(struct work_struct *work)
  3007. {
  3008. unsigned long lock_flags;
  3009. struct ipr_dump *dump;
  3010. struct ipr_ioa_cfg *ioa_cfg =
  3011. container_of(work, struct ipr_ioa_cfg, work_q);
  3012. ENTER;
  3013. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3014. if (ioa_cfg->sdt_state == READ_DUMP) {
  3015. dump = ioa_cfg->dump;
  3016. if (!dump) {
  3017. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3018. return;
  3019. }
  3020. kref_get(&dump->kref);
  3021. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3022. ipr_get_ioa_dump(ioa_cfg, dump);
  3023. kref_put(&dump->kref, ipr_release_dump);
  3024. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3025. if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
  3026. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3027. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3028. return;
  3029. }
  3030. if (ioa_cfg->scsi_unblock) {
  3031. ioa_cfg->scsi_unblock = 0;
  3032. ioa_cfg->scsi_blocked = 0;
  3033. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3034. scsi_unblock_requests(ioa_cfg->host);
  3035. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3036. if (ioa_cfg->scsi_blocked)
  3037. scsi_block_requests(ioa_cfg->host);
  3038. }
  3039. if (!ioa_cfg->scan_enabled) {
  3040. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3041. return;
  3042. }
  3043. schedule_work(&ioa_cfg->scsi_add_work_q);
  3044. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3045. LEAVE;
  3046. }
  3047. #ifdef CONFIG_SCSI_IPR_TRACE
  3048. /**
  3049. * ipr_read_trace - Dump the adapter trace
  3050. * @filp: open sysfs file
  3051. * @kobj: kobject struct
  3052. * @bin_attr: bin_attribute struct
  3053. * @buf: buffer
  3054. * @off: offset
  3055. * @count: buffer size
  3056. *
  3057. * Return value:
  3058. * number of bytes printed to buffer
  3059. **/
  3060. static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
  3061. struct bin_attribute *bin_attr,
  3062. char *buf, loff_t off, size_t count)
  3063. {
  3064. struct device *dev = container_of(kobj, struct device, kobj);
  3065. struct Scsi_Host *shost = class_to_shost(dev);
  3066. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3067. unsigned long lock_flags = 0;
  3068. ssize_t ret;
  3069. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3070. ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
  3071. IPR_TRACE_SIZE);
  3072. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3073. return ret;
  3074. }
  3075. static struct bin_attribute ipr_trace_attr = {
  3076. .attr = {
  3077. .name = "trace",
  3078. .mode = S_IRUGO,
  3079. },
  3080. .size = 0,
  3081. .read = ipr_read_trace,
  3082. };
  3083. #endif
  3084. /**
  3085. * ipr_show_fw_version - Show the firmware version
  3086. * @dev: class device struct
  3087. * @buf: buffer
  3088. *
  3089. * Return value:
  3090. * number of bytes printed to buffer
  3091. **/
  3092. static ssize_t ipr_show_fw_version(struct device *dev,
  3093. struct device_attribute *attr, char *buf)
  3094. {
  3095. struct Scsi_Host *shost = class_to_shost(dev);
  3096. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3097. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  3098. unsigned long lock_flags = 0;
  3099. int len;
  3100. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3101. len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
  3102. ucode_vpd->major_release, ucode_vpd->card_type,
  3103. ucode_vpd->minor_release[0],
  3104. ucode_vpd->minor_release[1]);
  3105. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3106. return len;
  3107. }
  3108. static struct device_attribute ipr_fw_version_attr = {
  3109. .attr = {
  3110. .name = "fw_version",
  3111. .mode = S_IRUGO,
  3112. },
  3113. .show = ipr_show_fw_version,
  3114. };
  3115. /**
  3116. * ipr_show_log_level - Show the adapter's error logging level
  3117. * @dev: class device struct
  3118. * @buf: buffer
  3119. *
  3120. * Return value:
  3121. * number of bytes printed to buffer
  3122. **/
  3123. static ssize_t ipr_show_log_level(struct device *dev,
  3124. struct device_attribute *attr, char *buf)
  3125. {
  3126. struct Scsi_Host *shost = class_to_shost(dev);
  3127. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3128. unsigned long lock_flags = 0;
  3129. int len;
  3130. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3131. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
  3132. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3133. return len;
  3134. }
  3135. /**
  3136. * ipr_store_log_level - Change the adapter's error logging level
  3137. * @dev: class device struct
  3138. * @buf: buffer
  3139. *
  3140. * Return value:
  3141. * number of bytes printed to buffer
  3142. **/
  3143. static ssize_t ipr_store_log_level(struct device *dev,
  3144. struct device_attribute *attr,
  3145. const char *buf, size_t count)
  3146. {
  3147. struct Scsi_Host *shost = class_to_shost(dev);
  3148. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3149. unsigned long lock_flags = 0;
  3150. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3151. ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
  3152. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3153. return strlen(buf);
  3154. }
  3155. static struct device_attribute ipr_log_level_attr = {
  3156. .attr = {
  3157. .name = "log_level",
  3158. .mode = S_IRUGO | S_IWUSR,
  3159. },
  3160. .show = ipr_show_log_level,
  3161. .store = ipr_store_log_level
  3162. };
  3163. /**
  3164. * ipr_store_diagnostics - IOA Diagnostics interface
  3165. * @dev: device struct
  3166. * @buf: buffer
  3167. * @count: buffer size
  3168. *
  3169. * This function will reset the adapter and wait a reasonable
  3170. * amount of time for any errors that the adapter might log.
  3171. *
  3172. * Return value:
  3173. * count on success / other on failure
  3174. **/
  3175. static ssize_t ipr_store_diagnostics(struct device *dev,
  3176. struct device_attribute *attr,
  3177. const char *buf, size_t count)
  3178. {
  3179. struct Scsi_Host *shost = class_to_shost(dev);
  3180. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3181. unsigned long lock_flags = 0;
  3182. int rc = count;
  3183. if (!capable(CAP_SYS_ADMIN))
  3184. return -EACCES;
  3185. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3186. while (ioa_cfg->in_reset_reload) {
  3187. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3188. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3189. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3190. }
  3191. ioa_cfg->errors_logged = 0;
  3192. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3193. if (ioa_cfg->in_reset_reload) {
  3194. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3195. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3196. /* Wait for a second for any errors to be logged */
  3197. msleep(1000);
  3198. } else {
  3199. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3200. return -EIO;
  3201. }
  3202. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3203. if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
  3204. rc = -EIO;
  3205. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3206. return rc;
  3207. }
  3208. static struct device_attribute ipr_diagnostics_attr = {
  3209. .attr = {
  3210. .name = "run_diagnostics",
  3211. .mode = S_IWUSR,
  3212. },
  3213. .store = ipr_store_diagnostics
  3214. };
  3215. /**
  3216. * ipr_show_adapter_state - Show the adapter's state
  3217. * @class_dev: device struct
  3218. * @buf: buffer
  3219. *
  3220. * Return value:
  3221. * number of bytes printed to buffer
  3222. **/
  3223. static ssize_t ipr_show_adapter_state(struct device *dev,
  3224. struct device_attribute *attr, char *buf)
  3225. {
  3226. struct Scsi_Host *shost = class_to_shost(dev);
  3227. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3228. unsigned long lock_flags = 0;
  3229. int len;
  3230. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3231. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  3232. len = snprintf(buf, PAGE_SIZE, "offline\n");
  3233. else
  3234. len = snprintf(buf, PAGE_SIZE, "online\n");
  3235. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3236. return len;
  3237. }
  3238. /**
  3239. * ipr_store_adapter_state - Change adapter state
  3240. * @dev: device struct
  3241. * @buf: buffer
  3242. * @count: buffer size
  3243. *
  3244. * This function will change the adapter's state.
  3245. *
  3246. * Return value:
  3247. * count on success / other on failure
  3248. **/
  3249. static ssize_t ipr_store_adapter_state(struct device *dev,
  3250. struct device_attribute *attr,
  3251. const char *buf, size_t count)
  3252. {
  3253. struct Scsi_Host *shost = class_to_shost(dev);
  3254. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3255. unsigned long lock_flags;
  3256. int result = count, i;
  3257. if (!capable(CAP_SYS_ADMIN))
  3258. return -EACCES;
  3259. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3260. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
  3261. !strncmp(buf, "online", 6)) {
  3262. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  3263. spin_lock(&ioa_cfg->hrrq[i]._lock);
  3264. ioa_cfg->hrrq[i].ioa_is_dead = 0;
  3265. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  3266. }
  3267. wmb();
  3268. ioa_cfg->reset_retries = 0;
  3269. ioa_cfg->in_ioa_bringdown = 0;
  3270. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3271. }
  3272. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3273. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3274. return result;
  3275. }
  3276. static struct device_attribute ipr_ioa_state_attr = {
  3277. .attr = {
  3278. .name = "online_state",
  3279. .mode = S_IRUGO | S_IWUSR,
  3280. },
  3281. .show = ipr_show_adapter_state,
  3282. .store = ipr_store_adapter_state
  3283. };
  3284. /**
  3285. * ipr_store_reset_adapter - Reset the adapter
  3286. * @dev: device struct
  3287. * @buf: buffer
  3288. * @count: buffer size
  3289. *
  3290. * This function will reset the adapter.
  3291. *
  3292. * Return value:
  3293. * count on success / other on failure
  3294. **/
  3295. static ssize_t ipr_store_reset_adapter(struct device *dev,
  3296. struct device_attribute *attr,
  3297. const char *buf, size_t count)
  3298. {
  3299. struct Scsi_Host *shost = class_to_shost(dev);
  3300. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3301. unsigned long lock_flags;
  3302. int result = count;
  3303. if (!capable(CAP_SYS_ADMIN))
  3304. return -EACCES;
  3305. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3306. if (!ioa_cfg->in_reset_reload)
  3307. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3308. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3309. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3310. return result;
  3311. }
  3312. static struct device_attribute ipr_ioa_reset_attr = {
  3313. .attr = {
  3314. .name = "reset_host",
  3315. .mode = S_IWUSR,
  3316. },
  3317. .store = ipr_store_reset_adapter
  3318. };
  3319. static int ipr_iopoll(struct irq_poll *iop, int budget);
  3320. /**
  3321. * ipr_show_iopoll_weight - Show ipr polling mode
  3322. * @dev: class device struct
  3323. * @buf: buffer
  3324. *
  3325. * Return value:
  3326. * number of bytes printed to buffer
  3327. **/
  3328. static ssize_t ipr_show_iopoll_weight(struct device *dev,
  3329. struct device_attribute *attr, char *buf)
  3330. {
  3331. struct Scsi_Host *shost = class_to_shost(dev);
  3332. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3333. unsigned long lock_flags = 0;
  3334. int len;
  3335. spin_lock_irqsave(shost->host_lock, lock_flags);
  3336. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
  3337. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  3338. return len;
  3339. }
  3340. /**
  3341. * ipr_store_iopoll_weight - Change the adapter's polling mode
  3342. * @dev: class device struct
  3343. * @buf: buffer
  3344. *
  3345. * Return value:
  3346. * number of bytes printed to buffer
  3347. **/
  3348. static ssize_t ipr_store_iopoll_weight(struct device *dev,
  3349. struct device_attribute *attr,
  3350. const char *buf, size_t count)
  3351. {
  3352. struct Scsi_Host *shost = class_to_shost(dev);
  3353. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3354. unsigned long user_iopoll_weight;
  3355. unsigned long lock_flags = 0;
  3356. int i;
  3357. if (!ioa_cfg->sis64) {
  3358. dev_info(&ioa_cfg->pdev->dev, "irq_poll not supported on this adapter\n");
  3359. return -EINVAL;
  3360. }
  3361. if (kstrtoul(buf, 10, &user_iopoll_weight))
  3362. return -EINVAL;
  3363. if (user_iopoll_weight > 256) {
  3364. dev_info(&ioa_cfg->pdev->dev, "Invalid irq_poll weight. It must be less than 256\n");
  3365. return -EINVAL;
  3366. }
  3367. if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
  3368. dev_info(&ioa_cfg->pdev->dev, "Current irq_poll weight has the same weight\n");
  3369. return strlen(buf);
  3370. }
  3371. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  3372. for (i = 1; i < ioa_cfg->hrrq_num; i++)
  3373. irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
  3374. }
  3375. spin_lock_irqsave(shost->host_lock, lock_flags);
  3376. ioa_cfg->iopoll_weight = user_iopoll_weight;
  3377. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  3378. for (i = 1; i < ioa_cfg->hrrq_num; i++) {
  3379. irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
  3380. ioa_cfg->iopoll_weight, ipr_iopoll);
  3381. }
  3382. }
  3383. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  3384. return strlen(buf);
  3385. }
  3386. static struct device_attribute ipr_iopoll_weight_attr = {
  3387. .attr = {
  3388. .name = "iopoll_weight",
  3389. .mode = S_IRUGO | S_IWUSR,
  3390. },
  3391. .show = ipr_show_iopoll_weight,
  3392. .store = ipr_store_iopoll_weight
  3393. };
  3394. /**
  3395. * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
  3396. * @buf_len: buffer length
  3397. *
  3398. * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
  3399. * list to use for microcode download
  3400. *
  3401. * Return value:
  3402. * pointer to sglist / NULL on failure
  3403. **/
  3404. static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
  3405. {
  3406. int sg_size, order;
  3407. struct ipr_sglist *sglist;
  3408. /* Get the minimum size per scatter/gather element */
  3409. sg_size = buf_len / (IPR_MAX_SGLIST - 1);
  3410. /* Get the actual size per element */
  3411. order = get_order(sg_size);
  3412. /* Allocate a scatter/gather list for the DMA */
  3413. sglist = kzalloc(sizeof(struct ipr_sglist), GFP_KERNEL);
  3414. if (sglist == NULL) {
  3415. ipr_trace;
  3416. return NULL;
  3417. }
  3418. sglist->order = order;
  3419. sglist->scatterlist = sgl_alloc_order(buf_len, order, false, GFP_KERNEL,
  3420. &sglist->num_sg);
  3421. if (!sglist->scatterlist) {
  3422. kfree(sglist);
  3423. return NULL;
  3424. }
  3425. return sglist;
  3426. }
  3427. /**
  3428. * ipr_free_ucode_buffer - Frees a microcode download buffer
  3429. * @p_dnld: scatter/gather list pointer
  3430. *
  3431. * Free a DMA'able ucode download buffer previously allocated with
  3432. * ipr_alloc_ucode_buffer
  3433. *
  3434. * Return value:
  3435. * nothing
  3436. **/
  3437. static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
  3438. {
  3439. sgl_free_order(sglist->scatterlist, sglist->order);
  3440. kfree(sglist);
  3441. }
  3442. /**
  3443. * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
  3444. * @sglist: scatter/gather list pointer
  3445. * @buffer: buffer pointer
  3446. * @len: buffer length
  3447. *
  3448. * Copy a microcode image from a user buffer into a buffer allocated by
  3449. * ipr_alloc_ucode_buffer
  3450. *
  3451. * Return value:
  3452. * 0 on success / other on failure
  3453. **/
  3454. static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
  3455. u8 *buffer, u32 len)
  3456. {
  3457. int bsize_elem, i, result = 0;
  3458. struct scatterlist *sg;
  3459. void *kaddr;
  3460. /* Determine the actual number of bytes per element */
  3461. bsize_elem = PAGE_SIZE * (1 << sglist->order);
  3462. sg = sglist->scatterlist;
  3463. for (i = 0; i < (len / bsize_elem); i++, sg = sg_next(sg),
  3464. buffer += bsize_elem) {
  3465. struct page *page = sg_page(sg);
  3466. kaddr = kmap(page);
  3467. memcpy(kaddr, buffer, bsize_elem);
  3468. kunmap(page);
  3469. sg->length = bsize_elem;
  3470. if (result != 0) {
  3471. ipr_trace;
  3472. return result;
  3473. }
  3474. }
  3475. if (len % bsize_elem) {
  3476. struct page *page = sg_page(sg);
  3477. kaddr = kmap(page);
  3478. memcpy(kaddr, buffer, len % bsize_elem);
  3479. kunmap(page);
  3480. sg->length = len % bsize_elem;
  3481. }
  3482. sglist->buffer_len = len;
  3483. return result;
  3484. }
  3485. /**
  3486. * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
  3487. * @ipr_cmd: ipr command struct
  3488. * @sglist: scatter/gather list
  3489. *
  3490. * Builds a microcode download IOA data list (IOADL).
  3491. *
  3492. **/
  3493. static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
  3494. struct ipr_sglist *sglist)
  3495. {
  3496. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3497. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  3498. struct scatterlist *scatterlist = sglist->scatterlist;
  3499. struct scatterlist *sg;
  3500. int i;
  3501. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  3502. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3503. ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
  3504. ioarcb->ioadl_len =
  3505. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  3506. for_each_sg(scatterlist, sg, ipr_cmd->dma_use_sg, i) {
  3507. ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
  3508. ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
  3509. ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
  3510. }
  3511. ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3512. }
  3513. /**
  3514. * ipr_build_ucode_ioadl - Build a microcode download IOADL
  3515. * @ipr_cmd: ipr command struct
  3516. * @sglist: scatter/gather list
  3517. *
  3518. * Builds a microcode download IOA data list (IOADL).
  3519. *
  3520. **/
  3521. static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
  3522. struct ipr_sglist *sglist)
  3523. {
  3524. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3525. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  3526. struct scatterlist *scatterlist = sglist->scatterlist;
  3527. struct scatterlist *sg;
  3528. int i;
  3529. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  3530. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3531. ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
  3532. ioarcb->ioadl_len =
  3533. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  3534. for_each_sg(scatterlist, sg, ipr_cmd->dma_use_sg, i) {
  3535. ioadl[i].flags_and_data_len =
  3536. cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(sg));
  3537. ioadl[i].address =
  3538. cpu_to_be32(sg_dma_address(sg));
  3539. }
  3540. ioadl[i-1].flags_and_data_len |=
  3541. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3542. }
  3543. /**
  3544. * ipr_update_ioa_ucode - Update IOA's microcode
  3545. * @ioa_cfg: ioa config struct
  3546. * @sglist: scatter/gather list
  3547. *
  3548. * Initiate an adapter reset to update the IOA's microcode
  3549. *
  3550. * Return value:
  3551. * 0 on success / -EIO on failure
  3552. **/
  3553. static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
  3554. struct ipr_sglist *sglist)
  3555. {
  3556. unsigned long lock_flags;
  3557. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3558. while (ioa_cfg->in_reset_reload) {
  3559. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3560. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3561. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3562. }
  3563. if (ioa_cfg->ucode_sglist) {
  3564. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3565. dev_err(&ioa_cfg->pdev->dev,
  3566. "Microcode download already in progress\n");
  3567. return -EIO;
  3568. }
  3569. sglist->num_dma_sg = dma_map_sg(&ioa_cfg->pdev->dev,
  3570. sglist->scatterlist, sglist->num_sg,
  3571. DMA_TO_DEVICE);
  3572. if (!sglist->num_dma_sg) {
  3573. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3574. dev_err(&ioa_cfg->pdev->dev,
  3575. "Failed to map microcode download buffer!\n");
  3576. return -EIO;
  3577. }
  3578. ioa_cfg->ucode_sglist = sglist;
  3579. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3580. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3581. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3582. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3583. ioa_cfg->ucode_sglist = NULL;
  3584. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3585. return 0;
  3586. }
  3587. /**
  3588. * ipr_store_update_fw - Update the firmware on the adapter
  3589. * @class_dev: device struct
  3590. * @buf: buffer
  3591. * @count: buffer size
  3592. *
  3593. * This function will update the firmware on the adapter.
  3594. *
  3595. * Return value:
  3596. * count on success / other on failure
  3597. **/
  3598. static ssize_t ipr_store_update_fw(struct device *dev,
  3599. struct device_attribute *attr,
  3600. const char *buf, size_t count)
  3601. {
  3602. struct Scsi_Host *shost = class_to_shost(dev);
  3603. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3604. struct ipr_ucode_image_header *image_hdr;
  3605. const struct firmware *fw_entry;
  3606. struct ipr_sglist *sglist;
  3607. char fname[100];
  3608. char *src;
  3609. char *endline;
  3610. int result, dnld_size;
  3611. if (!capable(CAP_SYS_ADMIN))
  3612. return -EACCES;
  3613. snprintf(fname, sizeof(fname), "%s", buf);
  3614. endline = strchr(fname, '\n');
  3615. if (endline)
  3616. *endline = '\0';
  3617. if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
  3618. dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
  3619. return -EIO;
  3620. }
  3621. image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
  3622. src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
  3623. dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
  3624. sglist = ipr_alloc_ucode_buffer(dnld_size);
  3625. if (!sglist) {
  3626. dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
  3627. release_firmware(fw_entry);
  3628. return -ENOMEM;
  3629. }
  3630. result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
  3631. if (result) {
  3632. dev_err(&ioa_cfg->pdev->dev,
  3633. "Microcode buffer copy to DMA buffer failed\n");
  3634. goto out;
  3635. }
  3636. ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
  3637. result = ipr_update_ioa_ucode(ioa_cfg, sglist);
  3638. if (!result)
  3639. result = count;
  3640. out:
  3641. ipr_free_ucode_buffer(sglist);
  3642. release_firmware(fw_entry);
  3643. return result;
  3644. }
  3645. static struct device_attribute ipr_update_fw_attr = {
  3646. .attr = {
  3647. .name = "update_fw",
  3648. .mode = S_IWUSR,
  3649. },
  3650. .store = ipr_store_update_fw
  3651. };
  3652. /**
  3653. * ipr_show_fw_type - Show the adapter's firmware type.
  3654. * @dev: class device struct
  3655. * @buf: buffer
  3656. *
  3657. * Return value:
  3658. * number of bytes printed to buffer
  3659. **/
  3660. static ssize_t ipr_show_fw_type(struct device *dev,
  3661. struct device_attribute *attr, char *buf)
  3662. {
  3663. struct Scsi_Host *shost = class_to_shost(dev);
  3664. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3665. unsigned long lock_flags = 0;
  3666. int len;
  3667. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3668. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
  3669. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3670. return len;
  3671. }
  3672. static struct device_attribute ipr_ioa_fw_type_attr = {
  3673. .attr = {
  3674. .name = "fw_type",
  3675. .mode = S_IRUGO,
  3676. },
  3677. .show = ipr_show_fw_type
  3678. };
  3679. static ssize_t ipr_read_async_err_log(struct file *filep, struct kobject *kobj,
  3680. struct bin_attribute *bin_attr, char *buf,
  3681. loff_t off, size_t count)
  3682. {
  3683. struct device *cdev = container_of(kobj, struct device, kobj);
  3684. struct Scsi_Host *shost = class_to_shost(cdev);
  3685. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3686. struct ipr_hostrcb *hostrcb;
  3687. unsigned long lock_flags = 0;
  3688. int ret;
  3689. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3690. hostrcb = list_first_entry_or_null(&ioa_cfg->hostrcb_report_q,
  3691. struct ipr_hostrcb, queue);
  3692. if (!hostrcb) {
  3693. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3694. return 0;
  3695. }
  3696. ret = memory_read_from_buffer(buf, count, &off, &hostrcb->hcam,
  3697. sizeof(hostrcb->hcam));
  3698. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3699. return ret;
  3700. }
  3701. static ssize_t ipr_next_async_err_log(struct file *filep, struct kobject *kobj,
  3702. struct bin_attribute *bin_attr, char *buf,
  3703. loff_t off, size_t count)
  3704. {
  3705. struct device *cdev = container_of(kobj, struct device, kobj);
  3706. struct Scsi_Host *shost = class_to_shost(cdev);
  3707. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3708. struct ipr_hostrcb *hostrcb;
  3709. unsigned long lock_flags = 0;
  3710. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3711. hostrcb = list_first_entry_or_null(&ioa_cfg->hostrcb_report_q,
  3712. struct ipr_hostrcb, queue);
  3713. if (!hostrcb) {
  3714. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3715. return count;
  3716. }
  3717. /* Reclaim hostrcb before exit */
  3718. list_move_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  3719. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3720. return count;
  3721. }
  3722. static struct bin_attribute ipr_ioa_async_err_log = {
  3723. .attr = {
  3724. .name = "async_err_log",
  3725. .mode = S_IRUGO | S_IWUSR,
  3726. },
  3727. .size = 0,
  3728. .read = ipr_read_async_err_log,
  3729. .write = ipr_next_async_err_log
  3730. };
  3731. static struct device_attribute *ipr_ioa_attrs[] = {
  3732. &ipr_fw_version_attr,
  3733. &ipr_log_level_attr,
  3734. &ipr_diagnostics_attr,
  3735. &ipr_ioa_state_attr,
  3736. &ipr_ioa_reset_attr,
  3737. &ipr_update_fw_attr,
  3738. &ipr_ioa_fw_type_attr,
  3739. &ipr_iopoll_weight_attr,
  3740. NULL,
  3741. };
  3742. #ifdef CONFIG_SCSI_IPR_DUMP
  3743. /**
  3744. * ipr_read_dump - Dump the adapter
  3745. * @filp: open sysfs file
  3746. * @kobj: kobject struct
  3747. * @bin_attr: bin_attribute struct
  3748. * @buf: buffer
  3749. * @off: offset
  3750. * @count: buffer size
  3751. *
  3752. * Return value:
  3753. * number of bytes printed to buffer
  3754. **/
  3755. static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
  3756. struct bin_attribute *bin_attr,
  3757. char *buf, loff_t off, size_t count)
  3758. {
  3759. struct device *cdev = container_of(kobj, struct device, kobj);
  3760. struct Scsi_Host *shost = class_to_shost(cdev);
  3761. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3762. struct ipr_dump *dump;
  3763. unsigned long lock_flags = 0;
  3764. char *src;
  3765. int len, sdt_end;
  3766. size_t rc = count;
  3767. if (!capable(CAP_SYS_ADMIN))
  3768. return -EACCES;
  3769. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3770. dump = ioa_cfg->dump;
  3771. if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
  3772. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3773. return 0;
  3774. }
  3775. kref_get(&dump->kref);
  3776. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3777. if (off > dump->driver_dump.hdr.len) {
  3778. kref_put(&dump->kref, ipr_release_dump);
  3779. return 0;
  3780. }
  3781. if (off + count > dump->driver_dump.hdr.len) {
  3782. count = dump->driver_dump.hdr.len - off;
  3783. rc = count;
  3784. }
  3785. if (count && off < sizeof(dump->driver_dump)) {
  3786. if (off + count > sizeof(dump->driver_dump))
  3787. len = sizeof(dump->driver_dump) - off;
  3788. else
  3789. len = count;
  3790. src = (u8 *)&dump->driver_dump + off;
  3791. memcpy(buf, src, len);
  3792. buf += len;
  3793. off += len;
  3794. count -= len;
  3795. }
  3796. off -= sizeof(dump->driver_dump);
  3797. if (ioa_cfg->sis64)
  3798. sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
  3799. (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
  3800. sizeof(struct ipr_sdt_entry));
  3801. else
  3802. sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
  3803. (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
  3804. if (count && off < sdt_end) {
  3805. if (off + count > sdt_end)
  3806. len = sdt_end - off;
  3807. else
  3808. len = count;
  3809. src = (u8 *)&dump->ioa_dump + off;
  3810. memcpy(buf, src, len);
  3811. buf += len;
  3812. off += len;
  3813. count -= len;
  3814. }
  3815. off -= sdt_end;
  3816. while (count) {
  3817. if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
  3818. len = PAGE_ALIGN(off) - off;
  3819. else
  3820. len = count;
  3821. src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
  3822. src += off & ~PAGE_MASK;
  3823. memcpy(buf, src, len);
  3824. buf += len;
  3825. off += len;
  3826. count -= len;
  3827. }
  3828. kref_put(&dump->kref, ipr_release_dump);
  3829. return rc;
  3830. }
  3831. /**
  3832. * ipr_alloc_dump - Prepare for adapter dump
  3833. * @ioa_cfg: ioa config struct
  3834. *
  3835. * Return value:
  3836. * 0 on success / other on failure
  3837. **/
  3838. static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
  3839. {
  3840. struct ipr_dump *dump;
  3841. __be32 **ioa_data;
  3842. unsigned long lock_flags = 0;
  3843. dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
  3844. if (!dump) {
  3845. ipr_err("Dump memory allocation failed\n");
  3846. return -ENOMEM;
  3847. }
  3848. if (ioa_cfg->sis64)
  3849. ioa_data = vmalloc(array_size(IPR_FMT3_MAX_NUM_DUMP_PAGES,
  3850. sizeof(__be32 *)));
  3851. else
  3852. ioa_data = vmalloc(array_size(IPR_FMT2_MAX_NUM_DUMP_PAGES,
  3853. sizeof(__be32 *)));
  3854. if (!ioa_data) {
  3855. ipr_err("Dump memory allocation failed\n");
  3856. kfree(dump);
  3857. return -ENOMEM;
  3858. }
  3859. dump->ioa_dump.ioa_data = ioa_data;
  3860. kref_init(&dump->kref);
  3861. dump->ioa_cfg = ioa_cfg;
  3862. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3863. if (INACTIVE != ioa_cfg->sdt_state) {
  3864. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3865. vfree(dump->ioa_dump.ioa_data);
  3866. kfree(dump);
  3867. return 0;
  3868. }
  3869. ioa_cfg->dump = dump;
  3870. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  3871. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
  3872. ioa_cfg->dump_taken = 1;
  3873. schedule_work(&ioa_cfg->work_q);
  3874. }
  3875. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3876. return 0;
  3877. }
  3878. /**
  3879. * ipr_free_dump - Free adapter dump memory
  3880. * @ioa_cfg: ioa config struct
  3881. *
  3882. * Return value:
  3883. * 0 on success / other on failure
  3884. **/
  3885. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
  3886. {
  3887. struct ipr_dump *dump;
  3888. unsigned long lock_flags = 0;
  3889. ENTER;
  3890. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3891. dump = ioa_cfg->dump;
  3892. if (!dump) {
  3893. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3894. return 0;
  3895. }
  3896. ioa_cfg->dump = NULL;
  3897. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3898. kref_put(&dump->kref, ipr_release_dump);
  3899. LEAVE;
  3900. return 0;
  3901. }
  3902. /**
  3903. * ipr_write_dump - Setup dump state of adapter
  3904. * @filp: open sysfs file
  3905. * @kobj: kobject struct
  3906. * @bin_attr: bin_attribute struct
  3907. * @buf: buffer
  3908. * @off: offset
  3909. * @count: buffer size
  3910. *
  3911. * Return value:
  3912. * number of bytes printed to buffer
  3913. **/
  3914. static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
  3915. struct bin_attribute *bin_attr,
  3916. char *buf, loff_t off, size_t count)
  3917. {
  3918. struct device *cdev = container_of(kobj, struct device, kobj);
  3919. struct Scsi_Host *shost = class_to_shost(cdev);
  3920. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3921. int rc;
  3922. if (!capable(CAP_SYS_ADMIN))
  3923. return -EACCES;
  3924. if (buf[0] == '1')
  3925. rc = ipr_alloc_dump(ioa_cfg);
  3926. else if (buf[0] == '0')
  3927. rc = ipr_free_dump(ioa_cfg);
  3928. else
  3929. return -EINVAL;
  3930. if (rc)
  3931. return rc;
  3932. else
  3933. return count;
  3934. }
  3935. static struct bin_attribute ipr_dump_attr = {
  3936. .attr = {
  3937. .name = "dump",
  3938. .mode = S_IRUSR | S_IWUSR,
  3939. },
  3940. .size = 0,
  3941. .read = ipr_read_dump,
  3942. .write = ipr_write_dump
  3943. };
  3944. #else
  3945. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
  3946. #endif
  3947. /**
  3948. * ipr_change_queue_depth - Change the device's queue depth
  3949. * @sdev: scsi device struct
  3950. * @qdepth: depth to set
  3951. * @reason: calling context
  3952. *
  3953. * Return value:
  3954. * actual depth set
  3955. **/
  3956. static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
  3957. {
  3958. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3959. struct ipr_resource_entry *res;
  3960. unsigned long lock_flags = 0;
  3961. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3962. res = (struct ipr_resource_entry *)sdev->hostdata;
  3963. if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
  3964. qdepth = IPR_MAX_CMD_PER_ATA_LUN;
  3965. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3966. scsi_change_queue_depth(sdev, qdepth);
  3967. return sdev->queue_depth;
  3968. }
  3969. /**
  3970. * ipr_show_adapter_handle - Show the adapter's resource handle for this device
  3971. * @dev: device struct
  3972. * @attr: device attribute structure
  3973. * @buf: buffer
  3974. *
  3975. * Return value:
  3976. * number of bytes printed to buffer
  3977. **/
  3978. static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
  3979. {
  3980. struct scsi_device *sdev = to_scsi_device(dev);
  3981. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3982. struct ipr_resource_entry *res;
  3983. unsigned long lock_flags = 0;
  3984. ssize_t len = -ENXIO;
  3985. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3986. res = (struct ipr_resource_entry *)sdev->hostdata;
  3987. if (res)
  3988. len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
  3989. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3990. return len;
  3991. }
  3992. static struct device_attribute ipr_adapter_handle_attr = {
  3993. .attr = {
  3994. .name = "adapter_handle",
  3995. .mode = S_IRUSR,
  3996. },
  3997. .show = ipr_show_adapter_handle
  3998. };
  3999. /**
  4000. * ipr_show_resource_path - Show the resource path or the resource address for
  4001. * this device.
  4002. * @dev: device struct
  4003. * @attr: device attribute structure
  4004. * @buf: buffer
  4005. *
  4006. * Return value:
  4007. * number of bytes printed to buffer
  4008. **/
  4009. static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
  4010. {
  4011. struct scsi_device *sdev = to_scsi_device(dev);
  4012. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4013. struct ipr_resource_entry *res;
  4014. unsigned long lock_flags = 0;
  4015. ssize_t len = -ENXIO;
  4016. char buffer[IPR_MAX_RES_PATH_LENGTH];
  4017. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4018. res = (struct ipr_resource_entry *)sdev->hostdata;
  4019. if (res && ioa_cfg->sis64)
  4020. len = snprintf(buf, PAGE_SIZE, "%s\n",
  4021. __ipr_format_res_path(res->res_path, buffer,
  4022. sizeof(buffer)));
  4023. else if (res)
  4024. len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
  4025. res->bus, res->target, res->lun);
  4026. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4027. return len;
  4028. }
  4029. static struct device_attribute ipr_resource_path_attr = {
  4030. .attr = {
  4031. .name = "resource_path",
  4032. .mode = S_IRUGO,
  4033. },
  4034. .show = ipr_show_resource_path
  4035. };
  4036. /**
  4037. * ipr_show_device_id - Show the device_id for this device.
  4038. * @dev: device struct
  4039. * @attr: device attribute structure
  4040. * @buf: buffer
  4041. *
  4042. * Return value:
  4043. * number of bytes printed to buffer
  4044. **/
  4045. static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
  4046. {
  4047. struct scsi_device *sdev = to_scsi_device(dev);
  4048. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4049. struct ipr_resource_entry *res;
  4050. unsigned long lock_flags = 0;
  4051. ssize_t len = -ENXIO;
  4052. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4053. res = (struct ipr_resource_entry *)sdev->hostdata;
  4054. if (res && ioa_cfg->sis64)
  4055. len = snprintf(buf, PAGE_SIZE, "0x%llx\n", be64_to_cpu(res->dev_id));
  4056. else if (res)
  4057. len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
  4058. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4059. return len;
  4060. }
  4061. static struct device_attribute ipr_device_id_attr = {
  4062. .attr = {
  4063. .name = "device_id",
  4064. .mode = S_IRUGO,
  4065. },
  4066. .show = ipr_show_device_id
  4067. };
  4068. /**
  4069. * ipr_show_resource_type - Show the resource type for this device.
  4070. * @dev: device struct
  4071. * @attr: device attribute structure
  4072. * @buf: buffer
  4073. *
  4074. * Return value:
  4075. * number of bytes printed to buffer
  4076. **/
  4077. static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
  4078. {
  4079. struct scsi_device *sdev = to_scsi_device(dev);
  4080. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4081. struct ipr_resource_entry *res;
  4082. unsigned long lock_flags = 0;
  4083. ssize_t len = -ENXIO;
  4084. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4085. res = (struct ipr_resource_entry *)sdev->hostdata;
  4086. if (res)
  4087. len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
  4088. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4089. return len;
  4090. }
  4091. static struct device_attribute ipr_resource_type_attr = {
  4092. .attr = {
  4093. .name = "resource_type",
  4094. .mode = S_IRUGO,
  4095. },
  4096. .show = ipr_show_resource_type
  4097. };
  4098. /**
  4099. * ipr_show_raw_mode - Show the adapter's raw mode
  4100. * @dev: class device struct
  4101. * @buf: buffer
  4102. *
  4103. * Return value:
  4104. * number of bytes printed to buffer
  4105. **/
  4106. static ssize_t ipr_show_raw_mode(struct device *dev,
  4107. struct device_attribute *attr, char *buf)
  4108. {
  4109. struct scsi_device *sdev = to_scsi_device(dev);
  4110. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4111. struct ipr_resource_entry *res;
  4112. unsigned long lock_flags = 0;
  4113. ssize_t len;
  4114. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4115. res = (struct ipr_resource_entry *)sdev->hostdata;
  4116. if (res)
  4117. len = snprintf(buf, PAGE_SIZE, "%d\n", res->raw_mode);
  4118. else
  4119. len = -ENXIO;
  4120. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4121. return len;
  4122. }
  4123. /**
  4124. * ipr_store_raw_mode - Change the adapter's raw mode
  4125. * @dev: class device struct
  4126. * @buf: buffer
  4127. *
  4128. * Return value:
  4129. * number of bytes printed to buffer
  4130. **/
  4131. static ssize_t ipr_store_raw_mode(struct device *dev,
  4132. struct device_attribute *attr,
  4133. const char *buf, size_t count)
  4134. {
  4135. struct scsi_device *sdev = to_scsi_device(dev);
  4136. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  4137. struct ipr_resource_entry *res;
  4138. unsigned long lock_flags = 0;
  4139. ssize_t len;
  4140. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4141. res = (struct ipr_resource_entry *)sdev->hostdata;
  4142. if (res) {
  4143. if (ipr_is_af_dasd_device(res)) {
  4144. res->raw_mode = simple_strtoul(buf, NULL, 10);
  4145. len = strlen(buf);
  4146. if (res->sdev)
  4147. sdev_printk(KERN_INFO, res->sdev, "raw mode is %s\n",
  4148. res->raw_mode ? "enabled" : "disabled");
  4149. } else
  4150. len = -EINVAL;
  4151. } else
  4152. len = -ENXIO;
  4153. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4154. return len;
  4155. }
  4156. static struct device_attribute ipr_raw_mode_attr = {
  4157. .attr = {
  4158. .name = "raw_mode",
  4159. .mode = S_IRUGO | S_IWUSR,
  4160. },
  4161. .show = ipr_show_raw_mode,
  4162. .store = ipr_store_raw_mode
  4163. };
  4164. static struct device_attribute *ipr_dev_attrs[] = {
  4165. &ipr_adapter_handle_attr,
  4166. &ipr_resource_path_attr,
  4167. &ipr_device_id_attr,
  4168. &ipr_resource_type_attr,
  4169. &ipr_raw_mode_attr,
  4170. NULL,
  4171. };
  4172. /**
  4173. * ipr_biosparam - Return the HSC mapping
  4174. * @sdev: scsi device struct
  4175. * @block_device: block device pointer
  4176. * @capacity: capacity of the device
  4177. * @parm: Array containing returned HSC values.
  4178. *
  4179. * This function generates the HSC parms that fdisk uses.
  4180. * We want to make sure we return something that places partitions
  4181. * on 4k boundaries for best performance with the IOA.
  4182. *
  4183. * Return value:
  4184. * 0 on success
  4185. **/
  4186. static int ipr_biosparam(struct scsi_device *sdev,
  4187. struct block_device *block_device,
  4188. sector_t capacity, int *parm)
  4189. {
  4190. int heads, sectors;
  4191. sector_t cylinders;
  4192. heads = 128;
  4193. sectors = 32;
  4194. cylinders = capacity;
  4195. sector_div(cylinders, (128 * 32));
  4196. /* return result */
  4197. parm[0] = heads;
  4198. parm[1] = sectors;
  4199. parm[2] = cylinders;
  4200. return 0;
  4201. }
  4202. /**
  4203. * ipr_find_starget - Find target based on bus/target.
  4204. * @starget: scsi target struct
  4205. *
  4206. * Return value:
  4207. * resource entry pointer if found / NULL if not found
  4208. **/
  4209. static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
  4210. {
  4211. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  4212. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4213. struct ipr_resource_entry *res;
  4214. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4215. if ((res->bus == starget->channel) &&
  4216. (res->target == starget->id)) {
  4217. return res;
  4218. }
  4219. }
  4220. return NULL;
  4221. }
  4222. static struct ata_port_info sata_port_info;
  4223. /**
  4224. * ipr_target_alloc - Prepare for commands to a SCSI target
  4225. * @starget: scsi target struct
  4226. *
  4227. * If the device is a SATA device, this function allocates an
  4228. * ATA port with libata, else it does nothing.
  4229. *
  4230. * Return value:
  4231. * 0 on success / non-0 on failure
  4232. **/
  4233. static int ipr_target_alloc(struct scsi_target *starget)
  4234. {
  4235. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  4236. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4237. struct ipr_sata_port *sata_port;
  4238. struct ata_port *ap;
  4239. struct ipr_resource_entry *res;
  4240. unsigned long lock_flags;
  4241. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4242. res = ipr_find_starget(starget);
  4243. starget->hostdata = NULL;
  4244. if (res && ipr_is_gata(res)) {
  4245. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4246. sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
  4247. if (!sata_port)
  4248. return -ENOMEM;
  4249. ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
  4250. if (ap) {
  4251. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4252. sata_port->ioa_cfg = ioa_cfg;
  4253. sata_port->ap = ap;
  4254. sata_port->res = res;
  4255. res->sata_port = sata_port;
  4256. ap->private_data = sata_port;
  4257. starget->hostdata = sata_port;
  4258. } else {
  4259. kfree(sata_port);
  4260. return -ENOMEM;
  4261. }
  4262. }
  4263. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4264. return 0;
  4265. }
  4266. /**
  4267. * ipr_target_destroy - Destroy a SCSI target
  4268. * @starget: scsi target struct
  4269. *
  4270. * If the device was a SATA device, this function frees the libata
  4271. * ATA port, else it does nothing.
  4272. *
  4273. **/
  4274. static void ipr_target_destroy(struct scsi_target *starget)
  4275. {
  4276. struct ipr_sata_port *sata_port = starget->hostdata;
  4277. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  4278. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4279. if (ioa_cfg->sis64) {
  4280. if (!ipr_find_starget(starget)) {
  4281. if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
  4282. clear_bit(starget->id, ioa_cfg->array_ids);
  4283. else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
  4284. clear_bit(starget->id, ioa_cfg->vset_ids);
  4285. else if (starget->channel == 0)
  4286. clear_bit(starget->id, ioa_cfg->target_ids);
  4287. }
  4288. }
  4289. if (sata_port) {
  4290. starget->hostdata = NULL;
  4291. ata_sas_port_destroy(sata_port->ap);
  4292. kfree(sata_port);
  4293. }
  4294. }
  4295. /**
  4296. * ipr_find_sdev - Find device based on bus/target/lun.
  4297. * @sdev: scsi device struct
  4298. *
  4299. * Return value:
  4300. * resource entry pointer if found / NULL if not found
  4301. **/
  4302. static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
  4303. {
  4304. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4305. struct ipr_resource_entry *res;
  4306. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4307. if ((res->bus == sdev->channel) &&
  4308. (res->target == sdev->id) &&
  4309. (res->lun == sdev->lun))
  4310. return res;
  4311. }
  4312. return NULL;
  4313. }
  4314. /**
  4315. * ipr_slave_destroy - Unconfigure a SCSI device
  4316. * @sdev: scsi device struct
  4317. *
  4318. * Return value:
  4319. * nothing
  4320. **/
  4321. static void ipr_slave_destroy(struct scsi_device *sdev)
  4322. {
  4323. struct ipr_resource_entry *res;
  4324. struct ipr_ioa_cfg *ioa_cfg;
  4325. unsigned long lock_flags = 0;
  4326. ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4327. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4328. res = (struct ipr_resource_entry *) sdev->hostdata;
  4329. if (res) {
  4330. if (res->sata_port)
  4331. res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
  4332. sdev->hostdata = NULL;
  4333. res->sdev = NULL;
  4334. res->sata_port = NULL;
  4335. }
  4336. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4337. }
  4338. /**
  4339. * ipr_slave_configure - Configure a SCSI device
  4340. * @sdev: scsi device struct
  4341. *
  4342. * This function configures the specified scsi device.
  4343. *
  4344. * Return value:
  4345. * 0 on success
  4346. **/
  4347. static int ipr_slave_configure(struct scsi_device *sdev)
  4348. {
  4349. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4350. struct ipr_resource_entry *res;
  4351. struct ata_port *ap = NULL;
  4352. unsigned long lock_flags = 0;
  4353. char buffer[IPR_MAX_RES_PATH_LENGTH];
  4354. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4355. res = sdev->hostdata;
  4356. if (res) {
  4357. if (ipr_is_af_dasd_device(res))
  4358. sdev->type = TYPE_RAID;
  4359. if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
  4360. sdev->scsi_level = 4;
  4361. sdev->no_uld_attach = 1;
  4362. }
  4363. if (ipr_is_vset_device(res)) {
  4364. sdev->scsi_level = SCSI_SPC_3;
  4365. sdev->no_report_opcodes = 1;
  4366. blk_queue_rq_timeout(sdev->request_queue,
  4367. IPR_VSET_RW_TIMEOUT);
  4368. blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
  4369. }
  4370. if (ipr_is_gata(res) && res->sata_port)
  4371. ap = res->sata_port->ap;
  4372. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4373. if (ap) {
  4374. scsi_change_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
  4375. ata_sas_slave_configure(sdev, ap);
  4376. }
  4377. if (ioa_cfg->sis64)
  4378. sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
  4379. ipr_format_res_path(ioa_cfg,
  4380. res->res_path, buffer, sizeof(buffer)));
  4381. return 0;
  4382. }
  4383. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4384. return 0;
  4385. }
  4386. /**
  4387. * ipr_ata_slave_alloc - Prepare for commands to a SATA device
  4388. * @sdev: scsi device struct
  4389. *
  4390. * This function initializes an ATA port so that future commands
  4391. * sent through queuecommand will work.
  4392. *
  4393. * Return value:
  4394. * 0 on success
  4395. **/
  4396. static int ipr_ata_slave_alloc(struct scsi_device *sdev)
  4397. {
  4398. struct ipr_sata_port *sata_port = NULL;
  4399. int rc = -ENXIO;
  4400. ENTER;
  4401. if (sdev->sdev_target)
  4402. sata_port = sdev->sdev_target->hostdata;
  4403. if (sata_port) {
  4404. rc = ata_sas_port_init(sata_port->ap);
  4405. if (rc == 0)
  4406. rc = ata_sas_sync_probe(sata_port->ap);
  4407. }
  4408. if (rc)
  4409. ipr_slave_destroy(sdev);
  4410. LEAVE;
  4411. return rc;
  4412. }
  4413. /**
  4414. * ipr_slave_alloc - Prepare for commands to a device.
  4415. * @sdev: scsi device struct
  4416. *
  4417. * This function saves a pointer to the resource entry
  4418. * in the scsi device struct if the device exists. We
  4419. * can then use this pointer in ipr_queuecommand when
  4420. * handling new commands.
  4421. *
  4422. * Return value:
  4423. * 0 on success / -ENXIO if device does not exist
  4424. **/
  4425. static int ipr_slave_alloc(struct scsi_device *sdev)
  4426. {
  4427. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4428. struct ipr_resource_entry *res;
  4429. unsigned long lock_flags;
  4430. int rc = -ENXIO;
  4431. sdev->hostdata = NULL;
  4432. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4433. res = ipr_find_sdev(sdev);
  4434. if (res) {
  4435. res->sdev = sdev;
  4436. res->add_to_ml = 0;
  4437. res->in_erp = 0;
  4438. sdev->hostdata = res;
  4439. if (!ipr_is_naca_model(res))
  4440. res->needs_sync_complete = 1;
  4441. rc = 0;
  4442. if (ipr_is_gata(res)) {
  4443. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4444. return ipr_ata_slave_alloc(sdev);
  4445. }
  4446. }
  4447. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4448. return rc;
  4449. }
  4450. /**
  4451. * ipr_match_lun - Match function for specified LUN
  4452. * @ipr_cmd: ipr command struct
  4453. * @device: device to match (sdev)
  4454. *
  4455. * Returns:
  4456. * 1 if command matches sdev / 0 if command does not match sdev
  4457. **/
  4458. static int ipr_match_lun(struct ipr_cmnd *ipr_cmd, void *device)
  4459. {
  4460. if (ipr_cmd->scsi_cmd && ipr_cmd->scsi_cmd->device == device)
  4461. return 1;
  4462. return 0;
  4463. }
  4464. /**
  4465. * ipr_cmnd_is_free - Check if a command is free or not
  4466. * @ipr_cmd ipr command struct
  4467. *
  4468. * Returns:
  4469. * true / false
  4470. **/
  4471. static bool ipr_cmnd_is_free(struct ipr_cmnd *ipr_cmd)
  4472. {
  4473. struct ipr_cmnd *loop_cmd;
  4474. list_for_each_entry(loop_cmd, &ipr_cmd->hrrq->hrrq_free_q, queue) {
  4475. if (loop_cmd == ipr_cmd)
  4476. return true;
  4477. }
  4478. return false;
  4479. }
  4480. /**
  4481. * ipr_match_res - Match function for specified resource entry
  4482. * @ipr_cmd: ipr command struct
  4483. * @resource: resource entry to match
  4484. *
  4485. * Returns:
  4486. * 1 if command matches sdev / 0 if command does not match sdev
  4487. **/
  4488. static int ipr_match_res(struct ipr_cmnd *ipr_cmd, void *resource)
  4489. {
  4490. struct ipr_resource_entry *res = resource;
  4491. if (res && ipr_cmd->ioarcb.res_handle == res->res_handle)
  4492. return 1;
  4493. return 0;
  4494. }
  4495. /**
  4496. * ipr_wait_for_ops - Wait for matching commands to complete
  4497. * @ipr_cmd: ipr command struct
  4498. * @device: device to match (sdev)
  4499. * @match: match function to use
  4500. *
  4501. * Returns:
  4502. * SUCCESS / FAILED
  4503. **/
  4504. static int ipr_wait_for_ops(struct ipr_ioa_cfg *ioa_cfg, void *device,
  4505. int (*match)(struct ipr_cmnd *, void *))
  4506. {
  4507. struct ipr_cmnd *ipr_cmd;
  4508. int wait, i;
  4509. unsigned long flags;
  4510. struct ipr_hrr_queue *hrrq;
  4511. signed long timeout = IPR_ABORT_TASK_TIMEOUT;
  4512. DECLARE_COMPLETION_ONSTACK(comp);
  4513. ENTER;
  4514. do {
  4515. wait = 0;
  4516. for_each_hrrq(hrrq, ioa_cfg) {
  4517. spin_lock_irqsave(hrrq->lock, flags);
  4518. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4519. ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
  4520. if (!ipr_cmnd_is_free(ipr_cmd)) {
  4521. if (match(ipr_cmd, device)) {
  4522. ipr_cmd->eh_comp = &comp;
  4523. wait++;
  4524. }
  4525. }
  4526. }
  4527. spin_unlock_irqrestore(hrrq->lock, flags);
  4528. }
  4529. if (wait) {
  4530. timeout = wait_for_completion_timeout(&comp, timeout);
  4531. if (!timeout) {
  4532. wait = 0;
  4533. for_each_hrrq(hrrq, ioa_cfg) {
  4534. spin_lock_irqsave(hrrq->lock, flags);
  4535. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4536. ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
  4537. if (!ipr_cmnd_is_free(ipr_cmd)) {
  4538. if (match(ipr_cmd, device)) {
  4539. ipr_cmd->eh_comp = NULL;
  4540. wait++;
  4541. }
  4542. }
  4543. }
  4544. spin_unlock_irqrestore(hrrq->lock, flags);
  4545. }
  4546. if (wait)
  4547. dev_err(&ioa_cfg->pdev->dev, "Timed out waiting for aborted commands\n");
  4548. LEAVE;
  4549. return wait ? FAILED : SUCCESS;
  4550. }
  4551. }
  4552. } while (wait);
  4553. LEAVE;
  4554. return SUCCESS;
  4555. }
  4556. static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
  4557. {
  4558. struct ipr_ioa_cfg *ioa_cfg;
  4559. unsigned long lock_flags = 0;
  4560. int rc = SUCCESS;
  4561. ENTER;
  4562. ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
  4563. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4564. if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
  4565. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  4566. dev_err(&ioa_cfg->pdev->dev,
  4567. "Adapter being reset as a result of error recovery.\n");
  4568. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  4569. ioa_cfg->sdt_state = GET_DUMP;
  4570. }
  4571. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4572. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4573. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4574. /* If we got hit with a host reset while we were already resetting
  4575. the adapter for some reason, and the reset failed. */
  4576. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
  4577. ipr_trace;
  4578. rc = FAILED;
  4579. }
  4580. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4581. LEAVE;
  4582. return rc;
  4583. }
  4584. /**
  4585. * ipr_device_reset - Reset the device
  4586. * @ioa_cfg: ioa config struct
  4587. * @res: resource entry struct
  4588. *
  4589. * This function issues a device reset to the affected device.
  4590. * If the device is a SCSI device, a LUN reset will be sent
  4591. * to the device first. If that does not work, a target reset
  4592. * will be sent. If the device is a SATA device, a PHY reset will
  4593. * be sent.
  4594. *
  4595. * Return value:
  4596. * 0 on success / non-zero on failure
  4597. **/
  4598. static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
  4599. struct ipr_resource_entry *res)
  4600. {
  4601. struct ipr_cmnd *ipr_cmd;
  4602. struct ipr_ioarcb *ioarcb;
  4603. struct ipr_cmd_pkt *cmd_pkt;
  4604. struct ipr_ioarcb_ata_regs *regs;
  4605. u32 ioasc;
  4606. ENTER;
  4607. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4608. ioarcb = &ipr_cmd->ioarcb;
  4609. cmd_pkt = &ioarcb->cmd_pkt;
  4610. if (ipr_cmd->ioa_cfg->sis64) {
  4611. regs = &ipr_cmd->i.ata_ioadl.regs;
  4612. ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
  4613. } else
  4614. regs = &ioarcb->u.add_data.u.regs;
  4615. ioarcb->res_handle = res->res_handle;
  4616. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4617. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  4618. if (ipr_is_gata(res)) {
  4619. cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
  4620. ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
  4621. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  4622. }
  4623. ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  4624. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4625. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  4626. if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
  4627. if (ipr_cmd->ioa_cfg->sis64)
  4628. memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
  4629. sizeof(struct ipr_ioasa_gata));
  4630. else
  4631. memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
  4632. sizeof(struct ipr_ioasa_gata));
  4633. }
  4634. LEAVE;
  4635. return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
  4636. }
  4637. /**
  4638. * ipr_sata_reset - Reset the SATA port
  4639. * @link: SATA link to reset
  4640. * @classes: class of the attached device
  4641. *
  4642. * This function issues a SATA phy reset to the affected ATA link.
  4643. *
  4644. * Return value:
  4645. * 0 on success / non-zero on failure
  4646. **/
  4647. static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
  4648. unsigned long deadline)
  4649. {
  4650. struct ipr_sata_port *sata_port = link->ap->private_data;
  4651. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4652. struct ipr_resource_entry *res;
  4653. unsigned long lock_flags = 0;
  4654. int rc = -ENXIO, ret;
  4655. ENTER;
  4656. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4657. while (ioa_cfg->in_reset_reload) {
  4658. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4659. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4660. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4661. }
  4662. res = sata_port->res;
  4663. if (res) {
  4664. rc = ipr_device_reset(ioa_cfg, res);
  4665. *classes = res->ata_class;
  4666. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4667. ret = ipr_wait_for_ops(ioa_cfg, res, ipr_match_res);
  4668. if (ret != SUCCESS) {
  4669. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4670. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  4671. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4672. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4673. }
  4674. } else
  4675. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4676. LEAVE;
  4677. return rc;
  4678. }
  4679. /**
  4680. * ipr_eh_dev_reset - Reset the device
  4681. * @scsi_cmd: scsi command struct
  4682. *
  4683. * This function issues a device reset to the affected device.
  4684. * A LUN reset will be sent to the device first. If that does
  4685. * not work, a target reset will be sent.
  4686. *
  4687. * Return value:
  4688. * SUCCESS / FAILED
  4689. **/
  4690. static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
  4691. {
  4692. struct ipr_cmnd *ipr_cmd;
  4693. struct ipr_ioa_cfg *ioa_cfg;
  4694. struct ipr_resource_entry *res;
  4695. struct ata_port *ap;
  4696. int rc = 0, i;
  4697. struct ipr_hrr_queue *hrrq;
  4698. ENTER;
  4699. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  4700. res = scsi_cmd->device->hostdata;
  4701. /*
  4702. * If we are currently going through reset/reload, return failed. This will force the
  4703. * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
  4704. * reset to complete
  4705. */
  4706. if (ioa_cfg->in_reset_reload)
  4707. return FAILED;
  4708. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  4709. return FAILED;
  4710. for_each_hrrq(hrrq, ioa_cfg) {
  4711. spin_lock(&hrrq->_lock);
  4712. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4713. ipr_cmd = ioa_cfg->ipr_cmnd_list[i];
  4714. if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
  4715. if (!ipr_cmd->qc)
  4716. continue;
  4717. if (ipr_cmnd_is_free(ipr_cmd))
  4718. continue;
  4719. ipr_cmd->done = ipr_sata_eh_done;
  4720. if (!(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
  4721. ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
  4722. ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
  4723. }
  4724. }
  4725. }
  4726. spin_unlock(&hrrq->_lock);
  4727. }
  4728. res->resetting_device = 1;
  4729. scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
  4730. if (ipr_is_gata(res) && res->sata_port) {
  4731. ap = res->sata_port->ap;
  4732. spin_unlock_irq(scsi_cmd->device->host->host_lock);
  4733. ata_std_error_handler(ap);
  4734. spin_lock_irq(scsi_cmd->device->host->host_lock);
  4735. } else
  4736. rc = ipr_device_reset(ioa_cfg, res);
  4737. res->resetting_device = 0;
  4738. res->reset_occurred = 1;
  4739. LEAVE;
  4740. return rc ? FAILED : SUCCESS;
  4741. }
  4742. static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
  4743. {
  4744. int rc;
  4745. struct ipr_ioa_cfg *ioa_cfg;
  4746. struct ipr_resource_entry *res;
  4747. ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
  4748. res = cmd->device->hostdata;
  4749. if (!res)
  4750. return FAILED;
  4751. spin_lock_irq(cmd->device->host->host_lock);
  4752. rc = __ipr_eh_dev_reset(cmd);
  4753. spin_unlock_irq(cmd->device->host->host_lock);
  4754. if (rc == SUCCESS) {
  4755. if (ipr_is_gata(res) && res->sata_port)
  4756. rc = ipr_wait_for_ops(ioa_cfg, res, ipr_match_res);
  4757. else
  4758. rc = ipr_wait_for_ops(ioa_cfg, cmd->device, ipr_match_lun);
  4759. }
  4760. return rc;
  4761. }
  4762. /**
  4763. * ipr_bus_reset_done - Op done function for bus reset.
  4764. * @ipr_cmd: ipr command struct
  4765. *
  4766. * This function is the op done function for a bus reset
  4767. *
  4768. * Return value:
  4769. * none
  4770. **/
  4771. static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
  4772. {
  4773. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4774. struct ipr_resource_entry *res;
  4775. ENTER;
  4776. if (!ioa_cfg->sis64)
  4777. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4778. if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
  4779. scsi_report_bus_reset(ioa_cfg->host, res->bus);
  4780. break;
  4781. }
  4782. }
  4783. /*
  4784. * If abort has not completed, indicate the reset has, else call the
  4785. * abort's done function to wake the sleeping eh thread
  4786. */
  4787. if (ipr_cmd->sibling->sibling)
  4788. ipr_cmd->sibling->sibling = NULL;
  4789. else
  4790. ipr_cmd->sibling->done(ipr_cmd->sibling);
  4791. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  4792. LEAVE;
  4793. }
  4794. /**
  4795. * ipr_abort_timeout - An abort task has timed out
  4796. * @ipr_cmd: ipr command struct
  4797. *
  4798. * This function handles when an abort task times out. If this
  4799. * happens we issue a bus reset since we have resources tied
  4800. * up that must be freed before returning to the midlayer.
  4801. *
  4802. * Return value:
  4803. * none
  4804. **/
  4805. static void ipr_abort_timeout(struct timer_list *t)
  4806. {
  4807. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  4808. struct ipr_cmnd *reset_cmd;
  4809. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4810. struct ipr_cmd_pkt *cmd_pkt;
  4811. unsigned long lock_flags = 0;
  4812. ENTER;
  4813. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4814. if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
  4815. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4816. return;
  4817. }
  4818. sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
  4819. reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4820. ipr_cmd->sibling = reset_cmd;
  4821. reset_cmd->sibling = ipr_cmd;
  4822. reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
  4823. cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
  4824. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4825. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  4826. cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
  4827. ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  4828. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4829. LEAVE;
  4830. }
  4831. /**
  4832. * ipr_cancel_op - Cancel specified op
  4833. * @scsi_cmd: scsi command struct
  4834. *
  4835. * This function cancels specified op.
  4836. *
  4837. * Return value:
  4838. * SUCCESS / FAILED
  4839. **/
  4840. static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
  4841. {
  4842. struct ipr_cmnd *ipr_cmd;
  4843. struct ipr_ioa_cfg *ioa_cfg;
  4844. struct ipr_resource_entry *res;
  4845. struct ipr_cmd_pkt *cmd_pkt;
  4846. u32 ioasc, int_reg;
  4847. int i, op_found = 0;
  4848. struct ipr_hrr_queue *hrrq;
  4849. ENTER;
  4850. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  4851. res = scsi_cmd->device->hostdata;
  4852. /* If we are currently going through reset/reload, return failed.
  4853. * This will force the mid-layer to call ipr_eh_host_reset,
  4854. * which will then go to sleep and wait for the reset to complete
  4855. */
  4856. if (ioa_cfg->in_reset_reload ||
  4857. ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  4858. return FAILED;
  4859. if (!res)
  4860. return FAILED;
  4861. /*
  4862. * If we are aborting a timed out op, chances are that the timeout was caused
  4863. * by a still not detected EEH error. In such cases, reading a register will
  4864. * trigger the EEH recovery infrastructure.
  4865. */
  4866. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4867. if (!ipr_is_gscsi(res))
  4868. return FAILED;
  4869. for_each_hrrq(hrrq, ioa_cfg) {
  4870. spin_lock(&hrrq->_lock);
  4871. for (i = hrrq->min_cmd_id; i <= hrrq->max_cmd_id; i++) {
  4872. if (ioa_cfg->ipr_cmnd_list[i]->scsi_cmd == scsi_cmd) {
  4873. if (!ipr_cmnd_is_free(ioa_cfg->ipr_cmnd_list[i])) {
  4874. op_found = 1;
  4875. break;
  4876. }
  4877. }
  4878. }
  4879. spin_unlock(&hrrq->_lock);
  4880. }
  4881. if (!op_found)
  4882. return SUCCESS;
  4883. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4884. ipr_cmd->ioarcb.res_handle = res->res_handle;
  4885. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  4886. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4887. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  4888. ipr_cmd->u.sdev = scsi_cmd->device;
  4889. scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
  4890. scsi_cmd->cmnd[0]);
  4891. ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
  4892. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4893. /*
  4894. * If the abort task timed out and we sent a bus reset, we will get
  4895. * one the following responses to the abort
  4896. */
  4897. if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
  4898. ioasc = 0;
  4899. ipr_trace;
  4900. }
  4901. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  4902. if (!ipr_is_naca_model(res))
  4903. res->needs_sync_complete = 1;
  4904. LEAVE;
  4905. return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
  4906. }
  4907. /**
  4908. * ipr_eh_abort - Abort a single op
  4909. * @scsi_cmd: scsi command struct
  4910. *
  4911. * Return value:
  4912. * 0 if scan in progress / 1 if scan is complete
  4913. **/
  4914. static int ipr_scan_finished(struct Scsi_Host *shost, unsigned long elapsed_time)
  4915. {
  4916. unsigned long lock_flags;
  4917. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  4918. int rc = 0;
  4919. spin_lock_irqsave(shost->host_lock, lock_flags);
  4920. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead || ioa_cfg->scan_done)
  4921. rc = 1;
  4922. if ((elapsed_time/HZ) > (ioa_cfg->transop_timeout * 2))
  4923. rc = 1;
  4924. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  4925. return rc;
  4926. }
  4927. /**
  4928. * ipr_eh_host_reset - Reset the host adapter
  4929. * @scsi_cmd: scsi command struct
  4930. *
  4931. * Return value:
  4932. * SUCCESS / FAILED
  4933. **/
  4934. static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
  4935. {
  4936. unsigned long flags;
  4937. int rc;
  4938. struct ipr_ioa_cfg *ioa_cfg;
  4939. ENTER;
  4940. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  4941. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  4942. rc = ipr_cancel_op(scsi_cmd);
  4943. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  4944. if (rc == SUCCESS)
  4945. rc = ipr_wait_for_ops(ioa_cfg, scsi_cmd->device, ipr_match_lun);
  4946. LEAVE;
  4947. return rc;
  4948. }
  4949. /**
  4950. * ipr_handle_other_interrupt - Handle "other" interrupts
  4951. * @ioa_cfg: ioa config struct
  4952. * @int_reg: interrupt register
  4953. *
  4954. * Return value:
  4955. * IRQ_NONE / IRQ_HANDLED
  4956. **/
  4957. static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
  4958. u32 int_reg)
  4959. {
  4960. irqreturn_t rc = IRQ_HANDLED;
  4961. u32 int_mask_reg;
  4962. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
  4963. int_reg &= ~int_mask_reg;
  4964. /* If an interrupt on the adapter did not occur, ignore it.
  4965. * Or in the case of SIS 64, check for a stage change interrupt.
  4966. */
  4967. if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
  4968. if (ioa_cfg->sis64) {
  4969. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  4970. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  4971. if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
  4972. /* clear stage change */
  4973. writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
  4974. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  4975. list_del(&ioa_cfg->reset_cmd->queue);
  4976. del_timer(&ioa_cfg->reset_cmd->timer);
  4977. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  4978. return IRQ_HANDLED;
  4979. }
  4980. }
  4981. return IRQ_NONE;
  4982. }
  4983. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  4984. /* Mask the interrupt */
  4985. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
  4986. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4987. list_del(&ioa_cfg->reset_cmd->queue);
  4988. del_timer(&ioa_cfg->reset_cmd->timer);
  4989. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  4990. } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
  4991. if (ioa_cfg->clear_isr) {
  4992. if (ipr_debug && printk_ratelimit())
  4993. dev_err(&ioa_cfg->pdev->dev,
  4994. "Spurious interrupt detected. 0x%08X\n", int_reg);
  4995. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
  4996. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  4997. return IRQ_NONE;
  4998. }
  4999. } else {
  5000. if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
  5001. ioa_cfg->ioa_unit_checked = 1;
  5002. else if (int_reg & IPR_PCII_NO_HOST_RRQ)
  5003. dev_err(&ioa_cfg->pdev->dev,
  5004. "No Host RRQ. 0x%08X\n", int_reg);
  5005. else
  5006. dev_err(&ioa_cfg->pdev->dev,
  5007. "Permanent IOA failure. 0x%08X\n", int_reg);
  5008. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  5009. ioa_cfg->sdt_state = GET_DUMP;
  5010. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  5011. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5012. }
  5013. return rc;
  5014. }
  5015. /**
  5016. * ipr_isr_eh - Interrupt service routine error handler
  5017. * @ioa_cfg: ioa config struct
  5018. * @msg: message to log
  5019. *
  5020. * Return value:
  5021. * none
  5022. **/
  5023. static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
  5024. {
  5025. ioa_cfg->errors_logged++;
  5026. dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
  5027. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  5028. ioa_cfg->sdt_state = GET_DUMP;
  5029. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5030. }
  5031. static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
  5032. struct list_head *doneq)
  5033. {
  5034. u32 ioasc;
  5035. u16 cmd_index;
  5036. struct ipr_cmnd *ipr_cmd;
  5037. struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
  5038. int num_hrrq = 0;
  5039. /* If interrupts are disabled, ignore the interrupt */
  5040. if (!hrr_queue->allow_interrupts)
  5041. return 0;
  5042. while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  5043. hrr_queue->toggle_bit) {
  5044. cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
  5045. IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
  5046. IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
  5047. if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
  5048. cmd_index < hrr_queue->min_cmd_id)) {
  5049. ipr_isr_eh(ioa_cfg,
  5050. "Invalid response handle from IOA: ",
  5051. cmd_index);
  5052. break;
  5053. }
  5054. ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
  5055. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5056. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
  5057. list_move_tail(&ipr_cmd->queue, doneq);
  5058. if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
  5059. hrr_queue->hrrq_curr++;
  5060. } else {
  5061. hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
  5062. hrr_queue->toggle_bit ^= 1u;
  5063. }
  5064. num_hrrq++;
  5065. if (budget > 0 && num_hrrq >= budget)
  5066. break;
  5067. }
  5068. return num_hrrq;
  5069. }
  5070. static int ipr_iopoll(struct irq_poll *iop, int budget)
  5071. {
  5072. struct ipr_ioa_cfg *ioa_cfg;
  5073. struct ipr_hrr_queue *hrrq;
  5074. struct ipr_cmnd *ipr_cmd, *temp;
  5075. unsigned long hrrq_flags;
  5076. int completed_ops;
  5077. LIST_HEAD(doneq);
  5078. hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
  5079. ioa_cfg = hrrq->ioa_cfg;
  5080. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5081. completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
  5082. if (completed_ops < budget)
  5083. irq_poll_complete(iop);
  5084. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5085. list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
  5086. list_del(&ipr_cmd->queue);
  5087. del_timer(&ipr_cmd->timer);
  5088. ipr_cmd->fast_done(ipr_cmd);
  5089. }
  5090. return completed_ops;
  5091. }
  5092. /**
  5093. * ipr_isr - Interrupt service routine
  5094. * @irq: irq number
  5095. * @devp: pointer to ioa config struct
  5096. *
  5097. * Return value:
  5098. * IRQ_NONE / IRQ_HANDLED
  5099. **/
  5100. static irqreturn_t ipr_isr(int irq, void *devp)
  5101. {
  5102. struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
  5103. struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
  5104. unsigned long hrrq_flags = 0;
  5105. u32 int_reg = 0;
  5106. int num_hrrq = 0;
  5107. int irq_none = 0;
  5108. struct ipr_cmnd *ipr_cmd, *temp;
  5109. irqreturn_t rc = IRQ_NONE;
  5110. LIST_HEAD(doneq);
  5111. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5112. /* If interrupts are disabled, ignore the interrupt */
  5113. if (!hrrq->allow_interrupts) {
  5114. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5115. return IRQ_NONE;
  5116. }
  5117. while (1) {
  5118. if (ipr_process_hrrq(hrrq, -1, &doneq)) {
  5119. rc = IRQ_HANDLED;
  5120. if (!ioa_cfg->clear_isr)
  5121. break;
  5122. /* Clear the PCI interrupt */
  5123. num_hrrq = 0;
  5124. do {
  5125. writel(IPR_PCII_HRRQ_UPDATED,
  5126. ioa_cfg->regs.clr_interrupt_reg32);
  5127. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  5128. } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
  5129. num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
  5130. } else if (rc == IRQ_NONE && irq_none == 0) {
  5131. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  5132. irq_none++;
  5133. } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
  5134. int_reg & IPR_PCII_HRRQ_UPDATED) {
  5135. ipr_isr_eh(ioa_cfg,
  5136. "Error clearing HRRQ: ", num_hrrq);
  5137. rc = IRQ_HANDLED;
  5138. break;
  5139. } else
  5140. break;
  5141. }
  5142. if (unlikely(rc == IRQ_NONE))
  5143. rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
  5144. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5145. list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
  5146. list_del(&ipr_cmd->queue);
  5147. del_timer(&ipr_cmd->timer);
  5148. ipr_cmd->fast_done(ipr_cmd);
  5149. }
  5150. return rc;
  5151. }
  5152. /**
  5153. * ipr_isr_mhrrq - Interrupt service routine
  5154. * @irq: irq number
  5155. * @devp: pointer to ioa config struct
  5156. *
  5157. * Return value:
  5158. * IRQ_NONE / IRQ_HANDLED
  5159. **/
  5160. static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
  5161. {
  5162. struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
  5163. struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
  5164. unsigned long hrrq_flags = 0;
  5165. struct ipr_cmnd *ipr_cmd, *temp;
  5166. irqreturn_t rc = IRQ_NONE;
  5167. LIST_HEAD(doneq);
  5168. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5169. /* If interrupts are disabled, ignore the interrupt */
  5170. if (!hrrq->allow_interrupts) {
  5171. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5172. return IRQ_NONE;
  5173. }
  5174. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  5175. if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  5176. hrrq->toggle_bit) {
  5177. irq_poll_sched(&hrrq->iopoll);
  5178. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5179. return IRQ_HANDLED;
  5180. }
  5181. } else {
  5182. if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  5183. hrrq->toggle_bit)
  5184. if (ipr_process_hrrq(hrrq, -1, &doneq))
  5185. rc = IRQ_HANDLED;
  5186. }
  5187. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5188. list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
  5189. list_del(&ipr_cmd->queue);
  5190. del_timer(&ipr_cmd->timer);
  5191. ipr_cmd->fast_done(ipr_cmd);
  5192. }
  5193. return rc;
  5194. }
  5195. /**
  5196. * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
  5197. * @ioa_cfg: ioa config struct
  5198. * @ipr_cmd: ipr command struct
  5199. *
  5200. * Return value:
  5201. * 0 on success / -1 on failure
  5202. **/
  5203. static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
  5204. struct ipr_cmnd *ipr_cmd)
  5205. {
  5206. int i, nseg;
  5207. struct scatterlist *sg;
  5208. u32 length;
  5209. u32 ioadl_flags = 0;
  5210. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5211. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5212. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  5213. length = scsi_bufflen(scsi_cmd);
  5214. if (!length)
  5215. return 0;
  5216. nseg = scsi_dma_map(scsi_cmd);
  5217. if (nseg < 0) {
  5218. if (printk_ratelimit())
  5219. dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
  5220. return -1;
  5221. }
  5222. ipr_cmd->dma_use_sg = nseg;
  5223. ioarcb->data_transfer_length = cpu_to_be32(length);
  5224. ioarcb->ioadl_len =
  5225. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  5226. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  5227. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  5228. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5229. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
  5230. ioadl_flags = IPR_IOADL_FLAGS_READ;
  5231. scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
  5232. ioadl64[i].flags = cpu_to_be32(ioadl_flags);
  5233. ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
  5234. ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
  5235. }
  5236. ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  5237. return 0;
  5238. }
  5239. /**
  5240. * ipr_build_ioadl - Build a scatter/gather list and map the buffer
  5241. * @ioa_cfg: ioa config struct
  5242. * @ipr_cmd: ipr command struct
  5243. *
  5244. * Return value:
  5245. * 0 on success / -1 on failure
  5246. **/
  5247. static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
  5248. struct ipr_cmnd *ipr_cmd)
  5249. {
  5250. int i, nseg;
  5251. struct scatterlist *sg;
  5252. u32 length;
  5253. u32 ioadl_flags = 0;
  5254. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5255. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5256. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  5257. length = scsi_bufflen(scsi_cmd);
  5258. if (!length)
  5259. return 0;
  5260. nseg = scsi_dma_map(scsi_cmd);
  5261. if (nseg < 0) {
  5262. dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
  5263. return -1;
  5264. }
  5265. ipr_cmd->dma_use_sg = nseg;
  5266. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  5267. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  5268. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5269. ioarcb->data_transfer_length = cpu_to_be32(length);
  5270. ioarcb->ioadl_len =
  5271. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  5272. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  5273. ioadl_flags = IPR_IOADL_FLAGS_READ;
  5274. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  5275. ioarcb->read_ioadl_len =
  5276. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  5277. }
  5278. if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
  5279. ioadl = ioarcb->u.add_data.u.ioadl;
  5280. ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
  5281. offsetof(struct ipr_ioarcb, u.add_data));
  5282. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  5283. }
  5284. scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
  5285. ioadl[i].flags_and_data_len =
  5286. cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  5287. ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
  5288. }
  5289. ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  5290. return 0;
  5291. }
  5292. /**
  5293. * __ipr_erp_done - Process completion of ERP for a device
  5294. * @ipr_cmd: ipr command struct
  5295. *
  5296. * This function copies the sense buffer into the scsi_cmd
  5297. * struct and pushes the scsi_done function.
  5298. *
  5299. * Return value:
  5300. * nothing
  5301. **/
  5302. static void __ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  5303. {
  5304. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5305. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  5306. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5307. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  5308. scsi_cmd->result |= (DID_ERROR << 16);
  5309. scmd_printk(KERN_ERR, scsi_cmd,
  5310. "Request Sense failed with IOASC: 0x%08X\n", ioasc);
  5311. } else {
  5312. memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
  5313. SCSI_SENSE_BUFFERSIZE);
  5314. }
  5315. if (res) {
  5316. if (!ipr_is_naca_model(res))
  5317. res->needs_sync_complete = 1;
  5318. res->in_erp = 0;
  5319. }
  5320. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  5321. scsi_cmd->scsi_done(scsi_cmd);
  5322. if (ipr_cmd->eh_comp)
  5323. complete(ipr_cmd->eh_comp);
  5324. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  5325. }
  5326. /**
  5327. * ipr_erp_done - Process completion of ERP for a device
  5328. * @ipr_cmd: ipr command struct
  5329. *
  5330. * This function copies the sense buffer into the scsi_cmd
  5331. * struct and pushes the scsi_done function.
  5332. *
  5333. * Return value:
  5334. * nothing
  5335. **/
  5336. static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  5337. {
  5338. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  5339. unsigned long hrrq_flags;
  5340. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  5341. __ipr_erp_done(ipr_cmd);
  5342. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  5343. }
  5344. /**
  5345. * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
  5346. * @ipr_cmd: ipr command struct
  5347. *
  5348. * Return value:
  5349. * none
  5350. **/
  5351. static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
  5352. {
  5353. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5354. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5355. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  5356. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  5357. ioarcb->data_transfer_length = 0;
  5358. ioarcb->read_data_transfer_length = 0;
  5359. ioarcb->ioadl_len = 0;
  5360. ioarcb->read_ioadl_len = 0;
  5361. ioasa->hdr.ioasc = 0;
  5362. ioasa->hdr.residual_data_len = 0;
  5363. if (ipr_cmd->ioa_cfg->sis64)
  5364. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  5365. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  5366. else {
  5367. ioarcb->write_ioadl_addr =
  5368. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  5369. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  5370. }
  5371. }
  5372. /**
  5373. * __ipr_erp_request_sense - Send request sense to a device
  5374. * @ipr_cmd: ipr command struct
  5375. *
  5376. * This function sends a request sense to a device as a result
  5377. * of a check condition.
  5378. *
  5379. * Return value:
  5380. * nothing
  5381. **/
  5382. static void __ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  5383. {
  5384. struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  5385. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5386. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  5387. __ipr_erp_done(ipr_cmd);
  5388. return;
  5389. }
  5390. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  5391. cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
  5392. cmd_pkt->cdb[0] = REQUEST_SENSE;
  5393. cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
  5394. cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
  5395. cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5396. cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
  5397. ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
  5398. SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
  5399. ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
  5400. IPR_REQUEST_SENSE_TIMEOUT * 2);
  5401. }
  5402. /**
  5403. * ipr_erp_request_sense - Send request sense to a device
  5404. * @ipr_cmd: ipr command struct
  5405. *
  5406. * This function sends a request sense to a device as a result
  5407. * of a check condition.
  5408. *
  5409. * Return value:
  5410. * nothing
  5411. **/
  5412. static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  5413. {
  5414. struct ipr_hrr_queue *hrrq = ipr_cmd->hrrq;
  5415. unsigned long hrrq_flags;
  5416. spin_lock_irqsave(&hrrq->_lock, hrrq_flags);
  5417. __ipr_erp_request_sense(ipr_cmd);
  5418. spin_unlock_irqrestore(&hrrq->_lock, hrrq_flags);
  5419. }
  5420. /**
  5421. * ipr_erp_cancel_all - Send cancel all to a device
  5422. * @ipr_cmd: ipr command struct
  5423. *
  5424. * This function sends a cancel all to a device to clear the
  5425. * queue. If we are running TCQ on the device, QERR is set to 1,
  5426. * which means all outstanding ops have been dropped on the floor.
  5427. * Cancel all will return them to us.
  5428. *
  5429. * Return value:
  5430. * nothing
  5431. **/
  5432. static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
  5433. {
  5434. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5435. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  5436. struct ipr_cmd_pkt *cmd_pkt;
  5437. res->in_erp = 1;
  5438. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  5439. if (!scsi_cmd->device->simple_tags) {
  5440. __ipr_erp_request_sense(ipr_cmd);
  5441. return;
  5442. }
  5443. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  5444. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  5445. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  5446. ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
  5447. IPR_CANCEL_ALL_TIMEOUT);
  5448. }
  5449. /**
  5450. * ipr_dump_ioasa - Dump contents of IOASA
  5451. * @ioa_cfg: ioa config struct
  5452. * @ipr_cmd: ipr command struct
  5453. * @res: resource entry struct
  5454. *
  5455. * This function is invoked by the interrupt handler when ops
  5456. * fail. It will log the IOASA if appropriate. Only called
  5457. * for GPDD ops.
  5458. *
  5459. * Return value:
  5460. * none
  5461. **/
  5462. static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
  5463. struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
  5464. {
  5465. int i;
  5466. u16 data_len;
  5467. u32 ioasc, fd_ioasc;
  5468. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5469. __be32 *ioasa_data = (__be32 *)ioasa;
  5470. int error_index;
  5471. ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
  5472. fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
  5473. if (0 == ioasc)
  5474. return;
  5475. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  5476. return;
  5477. if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
  5478. error_index = ipr_get_error(fd_ioasc);
  5479. else
  5480. error_index = ipr_get_error(ioasc);
  5481. if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
  5482. /* Don't log an error if the IOA already logged one */
  5483. if (ioasa->hdr.ilid != 0)
  5484. return;
  5485. if (!ipr_is_gscsi(res))
  5486. return;
  5487. if (ipr_error_table[error_index].log_ioasa == 0)
  5488. return;
  5489. }
  5490. ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
  5491. data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
  5492. if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
  5493. data_len = sizeof(struct ipr_ioasa64);
  5494. else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
  5495. data_len = sizeof(struct ipr_ioasa);
  5496. ipr_err("IOASA Dump:\n");
  5497. for (i = 0; i < data_len / 4; i += 4) {
  5498. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  5499. be32_to_cpu(ioasa_data[i]),
  5500. be32_to_cpu(ioasa_data[i+1]),
  5501. be32_to_cpu(ioasa_data[i+2]),
  5502. be32_to_cpu(ioasa_data[i+3]));
  5503. }
  5504. }
  5505. /**
  5506. * ipr_gen_sense - Generate SCSI sense data from an IOASA
  5507. * @ioasa: IOASA
  5508. * @sense_buf: sense data buffer
  5509. *
  5510. * Return value:
  5511. * none
  5512. **/
  5513. static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
  5514. {
  5515. u32 failing_lba;
  5516. u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
  5517. struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
  5518. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5519. u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
  5520. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  5521. if (ioasc >= IPR_FIRST_DRIVER_IOASC)
  5522. return;
  5523. ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
  5524. if (ipr_is_vset_device(res) &&
  5525. ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
  5526. ioasa->u.vset.failing_lba_hi != 0) {
  5527. sense_buf[0] = 0x72;
  5528. sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
  5529. sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
  5530. sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
  5531. sense_buf[7] = 12;
  5532. sense_buf[8] = 0;
  5533. sense_buf[9] = 0x0A;
  5534. sense_buf[10] = 0x80;
  5535. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
  5536. sense_buf[12] = (failing_lba & 0xff000000) >> 24;
  5537. sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
  5538. sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
  5539. sense_buf[15] = failing_lba & 0x000000ff;
  5540. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  5541. sense_buf[16] = (failing_lba & 0xff000000) >> 24;
  5542. sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
  5543. sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
  5544. sense_buf[19] = failing_lba & 0x000000ff;
  5545. } else {
  5546. sense_buf[0] = 0x70;
  5547. sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
  5548. sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
  5549. sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
  5550. /* Illegal request */
  5551. if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
  5552. (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
  5553. sense_buf[7] = 10; /* additional length */
  5554. /* IOARCB was in error */
  5555. if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
  5556. sense_buf[15] = 0xC0;
  5557. else /* Parameter data was invalid */
  5558. sense_buf[15] = 0x80;
  5559. sense_buf[16] =
  5560. ((IPR_FIELD_POINTER_MASK &
  5561. be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
  5562. sense_buf[17] =
  5563. (IPR_FIELD_POINTER_MASK &
  5564. be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
  5565. } else {
  5566. if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
  5567. if (ipr_is_vset_device(res))
  5568. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  5569. else
  5570. failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
  5571. sense_buf[0] |= 0x80; /* Or in the Valid bit */
  5572. sense_buf[3] = (failing_lba & 0xff000000) >> 24;
  5573. sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
  5574. sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
  5575. sense_buf[6] = failing_lba & 0x000000ff;
  5576. }
  5577. sense_buf[7] = 6; /* additional length */
  5578. }
  5579. }
  5580. }
  5581. /**
  5582. * ipr_get_autosense - Copy autosense data to sense buffer
  5583. * @ipr_cmd: ipr command struct
  5584. *
  5585. * This function copies the autosense buffer to the buffer
  5586. * in the scsi_cmd, if there is autosense available.
  5587. *
  5588. * Return value:
  5589. * 1 if autosense was available / 0 if not
  5590. **/
  5591. static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
  5592. {
  5593. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  5594. struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
  5595. if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
  5596. return 0;
  5597. if (ipr_cmd->ioa_cfg->sis64)
  5598. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
  5599. min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
  5600. SCSI_SENSE_BUFFERSIZE));
  5601. else
  5602. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
  5603. min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
  5604. SCSI_SENSE_BUFFERSIZE));
  5605. return 1;
  5606. }
  5607. /**
  5608. * ipr_erp_start - Process an error response for a SCSI op
  5609. * @ioa_cfg: ioa config struct
  5610. * @ipr_cmd: ipr command struct
  5611. *
  5612. * This function determines whether or not to initiate ERP
  5613. * on the affected device.
  5614. *
  5615. * Return value:
  5616. * nothing
  5617. **/
  5618. static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
  5619. struct ipr_cmnd *ipr_cmd)
  5620. {
  5621. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5622. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  5623. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5624. u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
  5625. if (!res) {
  5626. __ipr_scsi_eh_done(ipr_cmd);
  5627. return;
  5628. }
  5629. if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
  5630. ipr_gen_sense(ipr_cmd);
  5631. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  5632. switch (masked_ioasc) {
  5633. case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
  5634. if (ipr_is_naca_model(res))
  5635. scsi_cmd->result |= (DID_ABORT << 16);
  5636. else
  5637. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5638. break;
  5639. case IPR_IOASC_IR_RESOURCE_HANDLE:
  5640. case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
  5641. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  5642. break;
  5643. case IPR_IOASC_HW_SEL_TIMEOUT:
  5644. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  5645. if (!ipr_is_naca_model(res))
  5646. res->needs_sync_complete = 1;
  5647. break;
  5648. case IPR_IOASC_SYNC_REQUIRED:
  5649. if (!res->in_erp)
  5650. res->needs_sync_complete = 1;
  5651. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5652. break;
  5653. case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
  5654. case IPR_IOASA_IR_DUAL_IOA_DISABLED:
  5655. /*
  5656. * exception: do not set DID_PASSTHROUGH on CHECK CONDITION
  5657. * so SCSI mid-layer and upper layers handle it accordingly.
  5658. */
  5659. if (scsi_cmd->result != SAM_STAT_CHECK_CONDITION)
  5660. scsi_cmd->result |= (DID_PASSTHROUGH << 16);
  5661. break;
  5662. case IPR_IOASC_BUS_WAS_RESET:
  5663. case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
  5664. /*
  5665. * Report the bus reset and ask for a retry. The device
  5666. * will give CC/UA the next command.
  5667. */
  5668. if (!res->resetting_device)
  5669. scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
  5670. scsi_cmd->result |= (DID_ERROR << 16);
  5671. if (!ipr_is_naca_model(res))
  5672. res->needs_sync_complete = 1;
  5673. break;
  5674. case IPR_IOASC_HW_DEV_BUS_STATUS:
  5675. scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
  5676. if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
  5677. if (!ipr_get_autosense(ipr_cmd)) {
  5678. if (!ipr_is_naca_model(res)) {
  5679. ipr_erp_cancel_all(ipr_cmd);
  5680. return;
  5681. }
  5682. }
  5683. }
  5684. if (!ipr_is_naca_model(res))
  5685. res->needs_sync_complete = 1;
  5686. break;
  5687. case IPR_IOASC_NR_INIT_CMD_REQUIRED:
  5688. break;
  5689. case IPR_IOASC_IR_NON_OPTIMIZED:
  5690. if (res->raw_mode) {
  5691. res->raw_mode = 0;
  5692. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5693. } else
  5694. scsi_cmd->result |= (DID_ERROR << 16);
  5695. break;
  5696. default:
  5697. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  5698. scsi_cmd->result |= (DID_ERROR << 16);
  5699. if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
  5700. res->needs_sync_complete = 1;
  5701. break;
  5702. }
  5703. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  5704. scsi_cmd->scsi_done(scsi_cmd);
  5705. if (ipr_cmd->eh_comp)
  5706. complete(ipr_cmd->eh_comp);
  5707. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  5708. }
  5709. /**
  5710. * ipr_scsi_done - mid-layer done function
  5711. * @ipr_cmd: ipr command struct
  5712. *
  5713. * This function is invoked by the interrupt handler for
  5714. * ops generated by the SCSI mid-layer
  5715. *
  5716. * Return value:
  5717. * none
  5718. **/
  5719. static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
  5720. {
  5721. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5722. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5723. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5724. unsigned long lock_flags;
  5725. scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
  5726. if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
  5727. scsi_dma_unmap(scsi_cmd);
  5728. spin_lock_irqsave(ipr_cmd->hrrq->lock, lock_flags);
  5729. scsi_cmd->scsi_done(scsi_cmd);
  5730. if (ipr_cmd->eh_comp)
  5731. complete(ipr_cmd->eh_comp);
  5732. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  5733. spin_unlock_irqrestore(ipr_cmd->hrrq->lock, lock_flags);
  5734. } else {
  5735. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5736. spin_lock(&ipr_cmd->hrrq->_lock);
  5737. ipr_erp_start(ioa_cfg, ipr_cmd);
  5738. spin_unlock(&ipr_cmd->hrrq->_lock);
  5739. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5740. }
  5741. }
  5742. /**
  5743. * ipr_queuecommand - Queue a mid-layer request
  5744. * @shost: scsi host struct
  5745. * @scsi_cmd: scsi command struct
  5746. *
  5747. * This function queues a request generated by the mid-layer.
  5748. *
  5749. * Return value:
  5750. * 0 on success
  5751. * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
  5752. * SCSI_MLQUEUE_HOST_BUSY if host is busy
  5753. **/
  5754. static int ipr_queuecommand(struct Scsi_Host *shost,
  5755. struct scsi_cmnd *scsi_cmd)
  5756. {
  5757. struct ipr_ioa_cfg *ioa_cfg;
  5758. struct ipr_resource_entry *res;
  5759. struct ipr_ioarcb *ioarcb;
  5760. struct ipr_cmnd *ipr_cmd;
  5761. unsigned long hrrq_flags, lock_flags;
  5762. int rc;
  5763. struct ipr_hrr_queue *hrrq;
  5764. int hrrq_id;
  5765. ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  5766. scsi_cmd->result = (DID_OK << 16);
  5767. res = scsi_cmd->device->hostdata;
  5768. if (ipr_is_gata(res) && res->sata_port) {
  5769. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5770. rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
  5771. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5772. return rc;
  5773. }
  5774. hrrq_id = ipr_get_hrrq_index(ioa_cfg);
  5775. hrrq = &ioa_cfg->hrrq[hrrq_id];
  5776. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5777. /*
  5778. * We are currently blocking all devices due to a host reset
  5779. * We have told the host to stop giving us new requests, but
  5780. * ERP ops don't count. FIXME
  5781. */
  5782. if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
  5783. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5784. return SCSI_MLQUEUE_HOST_BUSY;
  5785. }
  5786. /*
  5787. * FIXME - Create scsi_set_host_offline interface
  5788. * and the ioa_is_dead check can be removed
  5789. */
  5790. if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
  5791. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5792. goto err_nodev;
  5793. }
  5794. ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
  5795. if (ipr_cmd == NULL) {
  5796. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5797. return SCSI_MLQUEUE_HOST_BUSY;
  5798. }
  5799. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5800. ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
  5801. ioarcb = &ipr_cmd->ioarcb;
  5802. memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
  5803. ipr_cmd->scsi_cmd = scsi_cmd;
  5804. ipr_cmd->done = ipr_scsi_eh_done;
  5805. if (ipr_is_gscsi(res)) {
  5806. if (scsi_cmd->underflow == 0)
  5807. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5808. if (res->reset_occurred) {
  5809. res->reset_occurred = 0;
  5810. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
  5811. }
  5812. }
  5813. if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
  5814. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  5815. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
  5816. if (scsi_cmd->flags & SCMD_TAGGED)
  5817. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
  5818. else
  5819. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
  5820. }
  5821. if (scsi_cmd->cmnd[0] >= 0xC0 &&
  5822. (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
  5823. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5824. }
  5825. if (res->raw_mode && ipr_is_af_dasd_device(res)) {
  5826. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_PIPE;
  5827. if (scsi_cmd->underflow == 0)
  5828. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5829. }
  5830. if (ioa_cfg->sis64)
  5831. rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
  5832. else
  5833. rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
  5834. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5835. if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
  5836. list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
  5837. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5838. if (!rc)
  5839. scsi_dma_unmap(scsi_cmd);
  5840. return SCSI_MLQUEUE_HOST_BUSY;
  5841. }
  5842. if (unlikely(hrrq->ioa_is_dead)) {
  5843. list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
  5844. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5845. scsi_dma_unmap(scsi_cmd);
  5846. goto err_nodev;
  5847. }
  5848. ioarcb->res_handle = res->res_handle;
  5849. if (res->needs_sync_complete) {
  5850. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
  5851. res->needs_sync_complete = 0;
  5852. }
  5853. list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
  5854. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
  5855. ipr_send_command(ipr_cmd);
  5856. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5857. return 0;
  5858. err_nodev:
  5859. spin_lock_irqsave(hrrq->lock, hrrq_flags);
  5860. memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  5861. scsi_cmd->result = (DID_NO_CONNECT << 16);
  5862. scsi_cmd->scsi_done(scsi_cmd);
  5863. spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
  5864. return 0;
  5865. }
  5866. /**
  5867. * ipr_ioctl - IOCTL handler
  5868. * @sdev: scsi device struct
  5869. * @cmd: IOCTL cmd
  5870. * @arg: IOCTL arg
  5871. *
  5872. * Return value:
  5873. * 0 on success / other on failure
  5874. **/
  5875. static int ipr_ioctl(struct scsi_device *sdev, unsigned int cmd,
  5876. void __user *arg)
  5877. {
  5878. struct ipr_resource_entry *res;
  5879. res = (struct ipr_resource_entry *)sdev->hostdata;
  5880. if (res && ipr_is_gata(res)) {
  5881. if (cmd == HDIO_GET_IDENTITY)
  5882. return -ENOTTY;
  5883. return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
  5884. }
  5885. return -EINVAL;
  5886. }
  5887. /**
  5888. * ipr_info - Get information about the card/driver
  5889. * @scsi_host: scsi host struct
  5890. *
  5891. * Return value:
  5892. * pointer to buffer with description string
  5893. **/
  5894. static const char *ipr_ioa_info(struct Scsi_Host *host)
  5895. {
  5896. static char buffer[512];
  5897. struct ipr_ioa_cfg *ioa_cfg;
  5898. unsigned long lock_flags = 0;
  5899. ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
  5900. spin_lock_irqsave(host->host_lock, lock_flags);
  5901. sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
  5902. spin_unlock_irqrestore(host->host_lock, lock_flags);
  5903. return buffer;
  5904. }
  5905. static struct scsi_host_template driver_template = {
  5906. .module = THIS_MODULE,
  5907. .name = "IPR",
  5908. .info = ipr_ioa_info,
  5909. .ioctl = ipr_ioctl,
  5910. #ifdef CONFIG_COMPAT
  5911. .compat_ioctl = ipr_ioctl,
  5912. #endif
  5913. .queuecommand = ipr_queuecommand,
  5914. .eh_abort_handler = ipr_eh_abort,
  5915. .eh_device_reset_handler = ipr_eh_dev_reset,
  5916. .eh_host_reset_handler = ipr_eh_host_reset,
  5917. .slave_alloc = ipr_slave_alloc,
  5918. .slave_configure = ipr_slave_configure,
  5919. .slave_destroy = ipr_slave_destroy,
  5920. .scan_finished = ipr_scan_finished,
  5921. .target_alloc = ipr_target_alloc,
  5922. .target_destroy = ipr_target_destroy,
  5923. .change_queue_depth = ipr_change_queue_depth,
  5924. .bios_param = ipr_biosparam,
  5925. .can_queue = IPR_MAX_COMMANDS,
  5926. .this_id = -1,
  5927. .sg_tablesize = IPR_MAX_SGLIST,
  5928. .max_sectors = IPR_IOA_MAX_SECTORS,
  5929. .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
  5930. .shost_attrs = ipr_ioa_attrs,
  5931. .sdev_attrs = ipr_dev_attrs,
  5932. .proc_name = IPR_NAME,
  5933. };
  5934. /**
  5935. * ipr_ata_phy_reset - libata phy_reset handler
  5936. * @ap: ata port to reset
  5937. *
  5938. **/
  5939. static void ipr_ata_phy_reset(struct ata_port *ap)
  5940. {
  5941. unsigned long flags;
  5942. struct ipr_sata_port *sata_port = ap->private_data;
  5943. struct ipr_resource_entry *res = sata_port->res;
  5944. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  5945. int rc;
  5946. ENTER;
  5947. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5948. while (ioa_cfg->in_reset_reload) {
  5949. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5950. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5951. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5952. }
  5953. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
  5954. goto out_unlock;
  5955. rc = ipr_device_reset(ioa_cfg, res);
  5956. if (rc) {
  5957. ap->link.device[0].class = ATA_DEV_NONE;
  5958. goto out_unlock;
  5959. }
  5960. ap->link.device[0].class = res->ata_class;
  5961. if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
  5962. ap->link.device[0].class = ATA_DEV_NONE;
  5963. out_unlock:
  5964. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5965. LEAVE;
  5966. }
  5967. /**
  5968. * ipr_ata_post_internal - Cleanup after an internal command
  5969. * @qc: ATA queued command
  5970. *
  5971. * Return value:
  5972. * none
  5973. **/
  5974. static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
  5975. {
  5976. struct ipr_sata_port *sata_port = qc->ap->private_data;
  5977. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  5978. struct ipr_cmnd *ipr_cmd;
  5979. struct ipr_hrr_queue *hrrq;
  5980. unsigned long flags;
  5981. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5982. while (ioa_cfg->in_reset_reload) {
  5983. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5984. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5985. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5986. }
  5987. for_each_hrrq(hrrq, ioa_cfg) {
  5988. spin_lock(&hrrq->_lock);
  5989. list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
  5990. if (ipr_cmd->qc == qc) {
  5991. ipr_device_reset(ioa_cfg, sata_port->res);
  5992. break;
  5993. }
  5994. }
  5995. spin_unlock(&hrrq->_lock);
  5996. }
  5997. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5998. }
  5999. /**
  6000. * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
  6001. * @regs: destination
  6002. * @tf: source ATA taskfile
  6003. *
  6004. * Return value:
  6005. * none
  6006. **/
  6007. static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
  6008. struct ata_taskfile *tf)
  6009. {
  6010. regs->feature = tf->feature;
  6011. regs->nsect = tf->nsect;
  6012. regs->lbal = tf->lbal;
  6013. regs->lbam = tf->lbam;
  6014. regs->lbah = tf->lbah;
  6015. regs->device = tf->device;
  6016. regs->command = tf->command;
  6017. regs->hob_feature = tf->hob_feature;
  6018. regs->hob_nsect = tf->hob_nsect;
  6019. regs->hob_lbal = tf->hob_lbal;
  6020. regs->hob_lbam = tf->hob_lbam;
  6021. regs->hob_lbah = tf->hob_lbah;
  6022. regs->ctl = tf->ctl;
  6023. }
  6024. /**
  6025. * ipr_sata_done - done function for SATA commands
  6026. * @ipr_cmd: ipr command struct
  6027. *
  6028. * This function is invoked by the interrupt handler for
  6029. * ops generated by the SCSI mid-layer to SATA devices
  6030. *
  6031. * Return value:
  6032. * none
  6033. **/
  6034. static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
  6035. {
  6036. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6037. struct ata_queued_cmd *qc = ipr_cmd->qc;
  6038. struct ipr_sata_port *sata_port = qc->ap->private_data;
  6039. struct ipr_resource_entry *res = sata_port->res;
  6040. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6041. spin_lock(&ipr_cmd->hrrq->_lock);
  6042. if (ipr_cmd->ioa_cfg->sis64)
  6043. memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
  6044. sizeof(struct ipr_ioasa_gata));
  6045. else
  6046. memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
  6047. sizeof(struct ipr_ioasa_gata));
  6048. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  6049. if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
  6050. scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
  6051. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  6052. qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
  6053. else
  6054. qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
  6055. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6056. spin_unlock(&ipr_cmd->hrrq->_lock);
  6057. ata_qc_complete(qc);
  6058. }
  6059. /**
  6060. * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
  6061. * @ipr_cmd: ipr command struct
  6062. * @qc: ATA queued command
  6063. *
  6064. **/
  6065. static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
  6066. struct ata_queued_cmd *qc)
  6067. {
  6068. u32 ioadl_flags = 0;
  6069. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6070. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ata_ioadl.ioadl64;
  6071. struct ipr_ioadl64_desc *last_ioadl64 = NULL;
  6072. int len = qc->nbytes;
  6073. struct scatterlist *sg;
  6074. unsigned int si;
  6075. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  6076. if (len == 0)
  6077. return;
  6078. if (qc->dma_dir == DMA_TO_DEVICE) {
  6079. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  6080. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6081. } else if (qc->dma_dir == DMA_FROM_DEVICE)
  6082. ioadl_flags = IPR_IOADL_FLAGS_READ;
  6083. ioarcb->data_transfer_length = cpu_to_be32(len);
  6084. ioarcb->ioadl_len =
  6085. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  6086. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  6087. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl.ioadl64));
  6088. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  6089. ioadl64->flags = cpu_to_be32(ioadl_flags);
  6090. ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
  6091. ioadl64->address = cpu_to_be64(sg_dma_address(sg));
  6092. last_ioadl64 = ioadl64;
  6093. ioadl64++;
  6094. }
  6095. if (likely(last_ioadl64))
  6096. last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  6097. }
  6098. /**
  6099. * ipr_build_ata_ioadl - Build an ATA scatter/gather list
  6100. * @ipr_cmd: ipr command struct
  6101. * @qc: ATA queued command
  6102. *
  6103. **/
  6104. static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
  6105. struct ata_queued_cmd *qc)
  6106. {
  6107. u32 ioadl_flags = 0;
  6108. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6109. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  6110. struct ipr_ioadl_desc *last_ioadl = NULL;
  6111. int len = qc->nbytes;
  6112. struct scatterlist *sg;
  6113. unsigned int si;
  6114. if (len == 0)
  6115. return;
  6116. if (qc->dma_dir == DMA_TO_DEVICE) {
  6117. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  6118. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6119. ioarcb->data_transfer_length = cpu_to_be32(len);
  6120. ioarcb->ioadl_len =
  6121. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  6122. } else if (qc->dma_dir == DMA_FROM_DEVICE) {
  6123. ioadl_flags = IPR_IOADL_FLAGS_READ;
  6124. ioarcb->read_data_transfer_length = cpu_to_be32(len);
  6125. ioarcb->read_ioadl_len =
  6126. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  6127. }
  6128. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  6129. ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  6130. ioadl->address = cpu_to_be32(sg_dma_address(sg));
  6131. last_ioadl = ioadl;
  6132. ioadl++;
  6133. }
  6134. if (likely(last_ioadl))
  6135. last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  6136. }
  6137. /**
  6138. * ipr_qc_defer - Get a free ipr_cmd
  6139. * @qc: queued command
  6140. *
  6141. * Return value:
  6142. * 0 if success
  6143. **/
  6144. static int ipr_qc_defer(struct ata_queued_cmd *qc)
  6145. {
  6146. struct ata_port *ap = qc->ap;
  6147. struct ipr_sata_port *sata_port = ap->private_data;
  6148. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  6149. struct ipr_cmnd *ipr_cmd;
  6150. struct ipr_hrr_queue *hrrq;
  6151. int hrrq_id;
  6152. hrrq_id = ipr_get_hrrq_index(ioa_cfg);
  6153. hrrq = &ioa_cfg->hrrq[hrrq_id];
  6154. qc->lldd_task = NULL;
  6155. spin_lock(&hrrq->_lock);
  6156. if (unlikely(hrrq->ioa_is_dead)) {
  6157. spin_unlock(&hrrq->_lock);
  6158. return 0;
  6159. }
  6160. if (unlikely(!hrrq->allow_cmds)) {
  6161. spin_unlock(&hrrq->_lock);
  6162. return ATA_DEFER_LINK;
  6163. }
  6164. ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
  6165. if (ipr_cmd == NULL) {
  6166. spin_unlock(&hrrq->_lock);
  6167. return ATA_DEFER_LINK;
  6168. }
  6169. qc->lldd_task = ipr_cmd;
  6170. spin_unlock(&hrrq->_lock);
  6171. return 0;
  6172. }
  6173. /**
  6174. * ipr_qc_issue - Issue a SATA qc to a device
  6175. * @qc: queued command
  6176. *
  6177. * Return value:
  6178. * 0 if success
  6179. **/
  6180. static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
  6181. {
  6182. struct ata_port *ap = qc->ap;
  6183. struct ipr_sata_port *sata_port = ap->private_data;
  6184. struct ipr_resource_entry *res = sata_port->res;
  6185. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  6186. struct ipr_cmnd *ipr_cmd;
  6187. struct ipr_ioarcb *ioarcb;
  6188. struct ipr_ioarcb_ata_regs *regs;
  6189. if (qc->lldd_task == NULL)
  6190. ipr_qc_defer(qc);
  6191. ipr_cmd = qc->lldd_task;
  6192. if (ipr_cmd == NULL)
  6193. return AC_ERR_SYSTEM;
  6194. qc->lldd_task = NULL;
  6195. spin_lock(&ipr_cmd->hrrq->_lock);
  6196. if (unlikely(!ipr_cmd->hrrq->allow_cmds ||
  6197. ipr_cmd->hrrq->ioa_is_dead)) {
  6198. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6199. spin_unlock(&ipr_cmd->hrrq->_lock);
  6200. return AC_ERR_SYSTEM;
  6201. }
  6202. ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
  6203. ioarcb = &ipr_cmd->ioarcb;
  6204. if (ioa_cfg->sis64) {
  6205. regs = &ipr_cmd->i.ata_ioadl.regs;
  6206. ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
  6207. } else
  6208. regs = &ioarcb->u.add_data.u.regs;
  6209. memset(regs, 0, sizeof(*regs));
  6210. ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
  6211. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  6212. ipr_cmd->qc = qc;
  6213. ipr_cmd->done = ipr_sata_done;
  6214. ipr_cmd->ioarcb.res_handle = res->res_handle;
  6215. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
  6216. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  6217. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  6218. ipr_cmd->dma_use_sg = qc->n_elem;
  6219. if (ioa_cfg->sis64)
  6220. ipr_build_ata_ioadl64(ipr_cmd, qc);
  6221. else
  6222. ipr_build_ata_ioadl(ipr_cmd, qc);
  6223. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  6224. ipr_copy_sata_tf(regs, &qc->tf);
  6225. memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
  6226. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
  6227. switch (qc->tf.protocol) {
  6228. case ATA_PROT_NODATA:
  6229. case ATA_PROT_PIO:
  6230. break;
  6231. case ATA_PROT_DMA:
  6232. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  6233. break;
  6234. case ATAPI_PROT_PIO:
  6235. case ATAPI_PROT_NODATA:
  6236. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  6237. break;
  6238. case ATAPI_PROT_DMA:
  6239. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  6240. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  6241. break;
  6242. default:
  6243. WARN_ON(1);
  6244. spin_unlock(&ipr_cmd->hrrq->_lock);
  6245. return AC_ERR_INVALID;
  6246. }
  6247. ipr_send_command(ipr_cmd);
  6248. spin_unlock(&ipr_cmd->hrrq->_lock);
  6249. return 0;
  6250. }
  6251. /**
  6252. * ipr_qc_fill_rtf - Read result TF
  6253. * @qc: ATA queued command
  6254. *
  6255. * Return value:
  6256. * true
  6257. **/
  6258. static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
  6259. {
  6260. struct ipr_sata_port *sata_port = qc->ap->private_data;
  6261. struct ipr_ioasa_gata *g = &sata_port->ioasa;
  6262. struct ata_taskfile *tf = &qc->result_tf;
  6263. tf->feature = g->error;
  6264. tf->nsect = g->nsect;
  6265. tf->lbal = g->lbal;
  6266. tf->lbam = g->lbam;
  6267. tf->lbah = g->lbah;
  6268. tf->device = g->device;
  6269. tf->command = g->status;
  6270. tf->hob_nsect = g->hob_nsect;
  6271. tf->hob_lbal = g->hob_lbal;
  6272. tf->hob_lbam = g->hob_lbam;
  6273. tf->hob_lbah = g->hob_lbah;
  6274. return true;
  6275. }
  6276. static struct ata_port_operations ipr_sata_ops = {
  6277. .phy_reset = ipr_ata_phy_reset,
  6278. .hardreset = ipr_sata_reset,
  6279. .post_internal_cmd = ipr_ata_post_internal,
  6280. .qc_prep = ata_noop_qc_prep,
  6281. .qc_defer = ipr_qc_defer,
  6282. .qc_issue = ipr_qc_issue,
  6283. .qc_fill_rtf = ipr_qc_fill_rtf,
  6284. .port_start = ata_sas_port_start,
  6285. .port_stop = ata_sas_port_stop
  6286. };
  6287. static struct ata_port_info sata_port_info = {
  6288. .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA |
  6289. ATA_FLAG_SAS_HOST,
  6290. .pio_mask = ATA_PIO4_ONLY,
  6291. .mwdma_mask = ATA_MWDMA2,
  6292. .udma_mask = ATA_UDMA6,
  6293. .port_ops = &ipr_sata_ops
  6294. };
  6295. #ifdef CONFIG_PPC_PSERIES
  6296. static const u16 ipr_blocked_processors[] = {
  6297. PVR_NORTHSTAR,
  6298. PVR_PULSAR,
  6299. PVR_POWER4,
  6300. PVR_ICESTAR,
  6301. PVR_SSTAR,
  6302. PVR_POWER4p,
  6303. PVR_630,
  6304. PVR_630p
  6305. };
  6306. /**
  6307. * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
  6308. * @ioa_cfg: ioa cfg struct
  6309. *
  6310. * Adapters that use Gemstone revision < 3.1 do not work reliably on
  6311. * certain pSeries hardware. This function determines if the given
  6312. * adapter is in one of these confgurations or not.
  6313. *
  6314. * Return value:
  6315. * 1 if adapter is not supported / 0 if adapter is supported
  6316. **/
  6317. static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
  6318. {
  6319. int i;
  6320. if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
  6321. for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
  6322. if (pvr_version_is(ipr_blocked_processors[i]))
  6323. return 1;
  6324. }
  6325. }
  6326. return 0;
  6327. }
  6328. #else
  6329. #define ipr_invalid_adapter(ioa_cfg) 0
  6330. #endif
  6331. /**
  6332. * ipr_ioa_bringdown_done - IOA bring down completion.
  6333. * @ipr_cmd: ipr command struct
  6334. *
  6335. * This function processes the completion of an adapter bring down.
  6336. * It wakes any reset sleepers.
  6337. *
  6338. * Return value:
  6339. * IPR_RC_JOB_RETURN
  6340. **/
  6341. static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
  6342. {
  6343. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6344. int i;
  6345. ENTER;
  6346. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
  6347. ipr_trace;
  6348. ioa_cfg->scsi_unblock = 1;
  6349. schedule_work(&ioa_cfg->work_q);
  6350. }
  6351. ioa_cfg->in_reset_reload = 0;
  6352. ioa_cfg->reset_retries = 0;
  6353. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  6354. spin_lock(&ioa_cfg->hrrq[i]._lock);
  6355. ioa_cfg->hrrq[i].ioa_is_dead = 1;
  6356. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  6357. }
  6358. wmb();
  6359. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6360. wake_up_all(&ioa_cfg->reset_wait_q);
  6361. LEAVE;
  6362. return IPR_RC_JOB_RETURN;
  6363. }
  6364. /**
  6365. * ipr_ioa_reset_done - IOA reset completion.
  6366. * @ipr_cmd: ipr command struct
  6367. *
  6368. * This function processes the completion of an adapter reset.
  6369. * It schedules any necessary mid-layer add/removes and
  6370. * wakes any reset sleepers.
  6371. *
  6372. * Return value:
  6373. * IPR_RC_JOB_RETURN
  6374. **/
  6375. static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
  6376. {
  6377. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6378. struct ipr_resource_entry *res;
  6379. int j;
  6380. ENTER;
  6381. ioa_cfg->in_reset_reload = 0;
  6382. for (j = 0; j < ioa_cfg->hrrq_num; j++) {
  6383. spin_lock(&ioa_cfg->hrrq[j]._lock);
  6384. ioa_cfg->hrrq[j].allow_cmds = 1;
  6385. spin_unlock(&ioa_cfg->hrrq[j]._lock);
  6386. }
  6387. wmb();
  6388. ioa_cfg->reset_cmd = NULL;
  6389. ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
  6390. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  6391. if (res->add_to_ml || res->del_from_ml) {
  6392. ipr_trace;
  6393. break;
  6394. }
  6395. }
  6396. schedule_work(&ioa_cfg->work_q);
  6397. for (j = 0; j < IPR_NUM_HCAMS; j++) {
  6398. list_del_init(&ioa_cfg->hostrcb[j]->queue);
  6399. if (j < IPR_NUM_LOG_HCAMS)
  6400. ipr_send_hcam(ioa_cfg,
  6401. IPR_HCAM_CDB_OP_CODE_LOG_DATA,
  6402. ioa_cfg->hostrcb[j]);
  6403. else
  6404. ipr_send_hcam(ioa_cfg,
  6405. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  6406. ioa_cfg->hostrcb[j]);
  6407. }
  6408. scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
  6409. dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
  6410. ioa_cfg->reset_retries = 0;
  6411. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6412. wake_up_all(&ioa_cfg->reset_wait_q);
  6413. ioa_cfg->scsi_unblock = 1;
  6414. schedule_work(&ioa_cfg->work_q);
  6415. LEAVE;
  6416. return IPR_RC_JOB_RETURN;
  6417. }
  6418. /**
  6419. * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
  6420. * @supported_dev: supported device struct
  6421. * @vpids: vendor product id struct
  6422. *
  6423. * Return value:
  6424. * none
  6425. **/
  6426. static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
  6427. struct ipr_std_inq_vpids *vpids)
  6428. {
  6429. memset(supported_dev, 0, sizeof(struct ipr_supported_device));
  6430. memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
  6431. supported_dev->num_records = 1;
  6432. supported_dev->data_length =
  6433. cpu_to_be16(sizeof(struct ipr_supported_device));
  6434. supported_dev->reserved = 0;
  6435. }
  6436. /**
  6437. * ipr_set_supported_devs - Send Set Supported Devices for a device
  6438. * @ipr_cmd: ipr command struct
  6439. *
  6440. * This function sends a Set Supported Devices to the adapter
  6441. *
  6442. * Return value:
  6443. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6444. **/
  6445. static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
  6446. {
  6447. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6448. struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
  6449. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6450. struct ipr_resource_entry *res = ipr_cmd->u.res;
  6451. ipr_cmd->job_step = ipr_ioa_reset_done;
  6452. list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
  6453. if (!ipr_is_scsi_disk(res))
  6454. continue;
  6455. ipr_cmd->u.res = res;
  6456. ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
  6457. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6458. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6459. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6460. ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
  6461. ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
  6462. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
  6463. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
  6464. ipr_init_ioadl(ipr_cmd,
  6465. ioa_cfg->vpd_cbs_dma +
  6466. offsetof(struct ipr_misc_cbs, supp_dev),
  6467. sizeof(struct ipr_supported_device),
  6468. IPR_IOADL_FLAGS_WRITE_LAST);
  6469. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  6470. IPR_SET_SUP_DEVICE_TIMEOUT);
  6471. if (!ioa_cfg->sis64)
  6472. ipr_cmd->job_step = ipr_set_supported_devs;
  6473. LEAVE;
  6474. return IPR_RC_JOB_RETURN;
  6475. }
  6476. LEAVE;
  6477. return IPR_RC_JOB_CONTINUE;
  6478. }
  6479. /**
  6480. * ipr_get_mode_page - Locate specified mode page
  6481. * @mode_pages: mode page buffer
  6482. * @page_code: page code to find
  6483. * @len: minimum required length for mode page
  6484. *
  6485. * Return value:
  6486. * pointer to mode page / NULL on failure
  6487. **/
  6488. static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
  6489. u32 page_code, u32 len)
  6490. {
  6491. struct ipr_mode_page_hdr *mode_hdr;
  6492. u32 page_length;
  6493. u32 length;
  6494. if (!mode_pages || (mode_pages->hdr.length == 0))
  6495. return NULL;
  6496. length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
  6497. mode_hdr = (struct ipr_mode_page_hdr *)
  6498. (mode_pages->data + mode_pages->hdr.block_desc_len);
  6499. while (length) {
  6500. if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
  6501. if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
  6502. return mode_hdr;
  6503. break;
  6504. } else {
  6505. page_length = (sizeof(struct ipr_mode_page_hdr) +
  6506. mode_hdr->page_length);
  6507. length -= page_length;
  6508. mode_hdr = (struct ipr_mode_page_hdr *)
  6509. ((unsigned long)mode_hdr + page_length);
  6510. }
  6511. }
  6512. return NULL;
  6513. }
  6514. /**
  6515. * ipr_check_term_power - Check for term power errors
  6516. * @ioa_cfg: ioa config struct
  6517. * @mode_pages: IOAFP mode pages buffer
  6518. *
  6519. * Check the IOAFP's mode page 28 for term power errors
  6520. *
  6521. * Return value:
  6522. * nothing
  6523. **/
  6524. static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
  6525. struct ipr_mode_pages *mode_pages)
  6526. {
  6527. int i;
  6528. int entry_length;
  6529. struct ipr_dev_bus_entry *bus;
  6530. struct ipr_mode_page28 *mode_page;
  6531. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  6532. sizeof(struct ipr_mode_page28));
  6533. entry_length = mode_page->entry_length;
  6534. bus = mode_page->bus;
  6535. for (i = 0; i < mode_page->num_entries; i++) {
  6536. if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
  6537. dev_err(&ioa_cfg->pdev->dev,
  6538. "Term power is absent on scsi bus %d\n",
  6539. bus->res_addr.bus);
  6540. }
  6541. bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
  6542. }
  6543. }
  6544. /**
  6545. * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
  6546. * @ioa_cfg: ioa config struct
  6547. *
  6548. * Looks through the config table checking for SES devices. If
  6549. * the SES device is in the SES table indicating a maximum SCSI
  6550. * bus speed, the speed is limited for the bus.
  6551. *
  6552. * Return value:
  6553. * none
  6554. **/
  6555. static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
  6556. {
  6557. u32 max_xfer_rate;
  6558. int i;
  6559. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  6560. max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
  6561. ioa_cfg->bus_attr[i].bus_width);
  6562. if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
  6563. ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
  6564. }
  6565. }
  6566. /**
  6567. * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
  6568. * @ioa_cfg: ioa config struct
  6569. * @mode_pages: mode page 28 buffer
  6570. *
  6571. * Updates mode page 28 based on driver configuration
  6572. *
  6573. * Return value:
  6574. * none
  6575. **/
  6576. static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
  6577. struct ipr_mode_pages *mode_pages)
  6578. {
  6579. int i, entry_length;
  6580. struct ipr_dev_bus_entry *bus;
  6581. struct ipr_bus_attributes *bus_attr;
  6582. struct ipr_mode_page28 *mode_page;
  6583. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  6584. sizeof(struct ipr_mode_page28));
  6585. entry_length = mode_page->entry_length;
  6586. /* Loop for each device bus entry */
  6587. for (i = 0, bus = mode_page->bus;
  6588. i < mode_page->num_entries;
  6589. i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
  6590. if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
  6591. dev_err(&ioa_cfg->pdev->dev,
  6592. "Invalid resource address reported: 0x%08X\n",
  6593. IPR_GET_PHYS_LOC(bus->res_addr));
  6594. continue;
  6595. }
  6596. bus_attr = &ioa_cfg->bus_attr[i];
  6597. bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
  6598. bus->bus_width = bus_attr->bus_width;
  6599. bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
  6600. bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
  6601. if (bus_attr->qas_enabled)
  6602. bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
  6603. else
  6604. bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
  6605. }
  6606. }
  6607. /**
  6608. * ipr_build_mode_select - Build a mode select command
  6609. * @ipr_cmd: ipr command struct
  6610. * @res_handle: resource handle to send command to
  6611. * @parm: Byte 2 of Mode Sense command
  6612. * @dma_addr: DMA buffer address
  6613. * @xfer_len: data transfer length
  6614. *
  6615. * Return value:
  6616. * none
  6617. **/
  6618. static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
  6619. __be32 res_handle, u8 parm,
  6620. dma_addr_t dma_addr, u8 xfer_len)
  6621. {
  6622. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6623. ioarcb->res_handle = res_handle;
  6624. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  6625. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  6626. ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
  6627. ioarcb->cmd_pkt.cdb[1] = parm;
  6628. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  6629. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
  6630. }
  6631. /**
  6632. * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
  6633. * @ipr_cmd: ipr command struct
  6634. *
  6635. * This function sets up the SCSI bus attributes and sends
  6636. * a Mode Select for Page 28 to activate them.
  6637. *
  6638. * Return value:
  6639. * IPR_RC_JOB_RETURN
  6640. **/
  6641. static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
  6642. {
  6643. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6644. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  6645. int length;
  6646. ENTER;
  6647. ipr_scsi_bus_speed_limit(ioa_cfg);
  6648. ipr_check_term_power(ioa_cfg, mode_pages);
  6649. ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
  6650. length = mode_pages->hdr.length + 1;
  6651. mode_pages->hdr.length = 0;
  6652. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  6653. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  6654. length);
  6655. ipr_cmd->job_step = ipr_set_supported_devs;
  6656. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  6657. struct ipr_resource_entry, queue);
  6658. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6659. LEAVE;
  6660. return IPR_RC_JOB_RETURN;
  6661. }
  6662. /**
  6663. * ipr_build_mode_sense - Builds a mode sense command
  6664. * @ipr_cmd: ipr command struct
  6665. * @res: resource entry struct
  6666. * @parm: Byte 2 of mode sense command
  6667. * @dma_addr: DMA address of mode sense buffer
  6668. * @xfer_len: Size of DMA buffer
  6669. *
  6670. * Return value:
  6671. * none
  6672. **/
  6673. static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
  6674. __be32 res_handle,
  6675. u8 parm, dma_addr_t dma_addr, u8 xfer_len)
  6676. {
  6677. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6678. ioarcb->res_handle = res_handle;
  6679. ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
  6680. ioarcb->cmd_pkt.cdb[2] = parm;
  6681. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  6682. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  6683. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
  6684. }
  6685. /**
  6686. * ipr_reset_cmd_failed - Handle failure of IOA reset command
  6687. * @ipr_cmd: ipr command struct
  6688. *
  6689. * This function handles the failure of an IOA bringup command.
  6690. *
  6691. * Return value:
  6692. * IPR_RC_JOB_RETURN
  6693. **/
  6694. static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
  6695. {
  6696. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6697. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6698. dev_err(&ioa_cfg->pdev->dev,
  6699. "0x%02X failed with IOASC: 0x%08X\n",
  6700. ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
  6701. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  6702. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  6703. return IPR_RC_JOB_RETURN;
  6704. }
  6705. /**
  6706. * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
  6707. * @ipr_cmd: ipr command struct
  6708. *
  6709. * This function handles the failure of a Mode Sense to the IOAFP.
  6710. * Some adapters do not handle all mode pages.
  6711. *
  6712. * Return value:
  6713. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6714. **/
  6715. static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
  6716. {
  6717. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6718. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6719. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  6720. ipr_cmd->job_step = ipr_set_supported_devs;
  6721. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  6722. struct ipr_resource_entry, queue);
  6723. return IPR_RC_JOB_CONTINUE;
  6724. }
  6725. return ipr_reset_cmd_failed(ipr_cmd);
  6726. }
  6727. /**
  6728. * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
  6729. * @ipr_cmd: ipr command struct
  6730. *
  6731. * This function send a Page 28 mode sense to the IOA to
  6732. * retrieve SCSI bus attributes.
  6733. *
  6734. * Return value:
  6735. * IPR_RC_JOB_RETURN
  6736. **/
  6737. static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
  6738. {
  6739. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6740. ENTER;
  6741. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  6742. 0x28, ioa_cfg->vpd_cbs_dma +
  6743. offsetof(struct ipr_misc_cbs, mode_pages),
  6744. sizeof(struct ipr_mode_pages));
  6745. ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
  6746. ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
  6747. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6748. LEAVE;
  6749. return IPR_RC_JOB_RETURN;
  6750. }
  6751. /**
  6752. * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
  6753. * @ipr_cmd: ipr command struct
  6754. *
  6755. * This function enables dual IOA RAID support if possible.
  6756. *
  6757. * Return value:
  6758. * IPR_RC_JOB_RETURN
  6759. **/
  6760. static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
  6761. {
  6762. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6763. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  6764. struct ipr_mode_page24 *mode_page;
  6765. int length;
  6766. ENTER;
  6767. mode_page = ipr_get_mode_page(mode_pages, 0x24,
  6768. sizeof(struct ipr_mode_page24));
  6769. if (mode_page)
  6770. mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
  6771. length = mode_pages->hdr.length + 1;
  6772. mode_pages->hdr.length = 0;
  6773. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  6774. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  6775. length);
  6776. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6777. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6778. LEAVE;
  6779. return IPR_RC_JOB_RETURN;
  6780. }
  6781. /**
  6782. * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
  6783. * @ipr_cmd: ipr command struct
  6784. *
  6785. * This function handles the failure of a Mode Sense to the IOAFP.
  6786. * Some adapters do not handle all mode pages.
  6787. *
  6788. * Return value:
  6789. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6790. **/
  6791. static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
  6792. {
  6793. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6794. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  6795. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6796. return IPR_RC_JOB_CONTINUE;
  6797. }
  6798. return ipr_reset_cmd_failed(ipr_cmd);
  6799. }
  6800. /**
  6801. * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
  6802. * @ipr_cmd: ipr command struct
  6803. *
  6804. * This function send a mode sense to the IOA to retrieve
  6805. * the IOA Advanced Function Control mode page.
  6806. *
  6807. * Return value:
  6808. * IPR_RC_JOB_RETURN
  6809. **/
  6810. static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
  6811. {
  6812. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6813. ENTER;
  6814. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  6815. 0x24, ioa_cfg->vpd_cbs_dma +
  6816. offsetof(struct ipr_misc_cbs, mode_pages),
  6817. sizeof(struct ipr_mode_pages));
  6818. ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
  6819. ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
  6820. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6821. LEAVE;
  6822. return IPR_RC_JOB_RETURN;
  6823. }
  6824. /**
  6825. * ipr_init_res_table - Initialize the resource table
  6826. * @ipr_cmd: ipr command struct
  6827. *
  6828. * This function looks through the existing resource table, comparing
  6829. * it with the config table. This function will take care of old/new
  6830. * devices and schedule adding/removing them from the mid-layer
  6831. * as appropriate.
  6832. *
  6833. * Return value:
  6834. * IPR_RC_JOB_CONTINUE
  6835. **/
  6836. static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
  6837. {
  6838. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6839. struct ipr_resource_entry *res, *temp;
  6840. struct ipr_config_table_entry_wrapper cfgtew;
  6841. int entries, found, flag, i;
  6842. LIST_HEAD(old_res);
  6843. ENTER;
  6844. if (ioa_cfg->sis64)
  6845. flag = ioa_cfg->u.cfg_table64->hdr64.flags;
  6846. else
  6847. flag = ioa_cfg->u.cfg_table->hdr.flags;
  6848. if (flag & IPR_UCODE_DOWNLOAD_REQ)
  6849. dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
  6850. list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
  6851. list_move_tail(&res->queue, &old_res);
  6852. if (ioa_cfg->sis64)
  6853. entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
  6854. else
  6855. entries = ioa_cfg->u.cfg_table->hdr.num_entries;
  6856. for (i = 0; i < entries; i++) {
  6857. if (ioa_cfg->sis64)
  6858. cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
  6859. else
  6860. cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
  6861. found = 0;
  6862. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6863. if (ipr_is_same_device(res, &cfgtew)) {
  6864. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6865. found = 1;
  6866. break;
  6867. }
  6868. }
  6869. if (!found) {
  6870. if (list_empty(&ioa_cfg->free_res_q)) {
  6871. dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
  6872. break;
  6873. }
  6874. found = 1;
  6875. res = list_entry(ioa_cfg->free_res_q.next,
  6876. struct ipr_resource_entry, queue);
  6877. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6878. ipr_init_res_entry(res, &cfgtew);
  6879. res->add_to_ml = 1;
  6880. } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
  6881. res->sdev->allow_restart = 1;
  6882. if (found)
  6883. ipr_update_res_entry(res, &cfgtew);
  6884. }
  6885. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6886. if (res->sdev) {
  6887. res->del_from_ml = 1;
  6888. res->res_handle = IPR_INVALID_RES_HANDLE;
  6889. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6890. }
  6891. }
  6892. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6893. ipr_clear_res_target(res);
  6894. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  6895. }
  6896. if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  6897. ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
  6898. else
  6899. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6900. LEAVE;
  6901. return IPR_RC_JOB_CONTINUE;
  6902. }
  6903. /**
  6904. * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
  6905. * @ipr_cmd: ipr command struct
  6906. *
  6907. * This function sends a Query IOA Configuration command
  6908. * to the adapter to retrieve the IOA configuration table.
  6909. *
  6910. * Return value:
  6911. * IPR_RC_JOB_RETURN
  6912. **/
  6913. static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
  6914. {
  6915. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6916. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6917. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  6918. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  6919. ENTER;
  6920. if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
  6921. ioa_cfg->dual_raid = 1;
  6922. dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
  6923. ucode_vpd->major_release, ucode_vpd->card_type,
  6924. ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
  6925. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6926. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6927. ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
  6928. ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
  6929. ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
  6930. ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
  6931. ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
  6932. IPR_IOADL_FLAGS_READ_LAST);
  6933. ipr_cmd->job_step = ipr_init_res_table;
  6934. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6935. LEAVE;
  6936. return IPR_RC_JOB_RETURN;
  6937. }
  6938. static int ipr_ioa_service_action_failed(struct ipr_cmnd *ipr_cmd)
  6939. {
  6940. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6941. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT)
  6942. return IPR_RC_JOB_CONTINUE;
  6943. return ipr_reset_cmd_failed(ipr_cmd);
  6944. }
  6945. static void ipr_build_ioa_service_action(struct ipr_cmnd *ipr_cmd,
  6946. __be32 res_handle, u8 sa_code)
  6947. {
  6948. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6949. ioarcb->res_handle = res_handle;
  6950. ioarcb->cmd_pkt.cdb[0] = IPR_IOA_SERVICE_ACTION;
  6951. ioarcb->cmd_pkt.cdb[1] = sa_code;
  6952. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6953. }
  6954. /**
  6955. * ipr_ioafp_set_caching_parameters - Issue Set Cache parameters service
  6956. * action
  6957. *
  6958. * Return value:
  6959. * none
  6960. **/
  6961. static int ipr_ioafp_set_caching_parameters(struct ipr_cmnd *ipr_cmd)
  6962. {
  6963. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6964. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6965. struct ipr_inquiry_pageC4 *pageC4 = &ioa_cfg->vpd_cbs->pageC4_data;
  6966. ENTER;
  6967. ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
  6968. if (pageC4->cache_cap[0] & IPR_CAP_SYNC_CACHE) {
  6969. ipr_build_ioa_service_action(ipr_cmd,
  6970. cpu_to_be32(IPR_IOA_RES_HANDLE),
  6971. IPR_IOA_SA_CHANGE_CACHE_PARAMS);
  6972. ioarcb->cmd_pkt.cdb[2] = 0x40;
  6973. ipr_cmd->job_step_failed = ipr_ioa_service_action_failed;
  6974. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  6975. IPR_SET_SUP_DEVICE_TIMEOUT);
  6976. LEAVE;
  6977. return IPR_RC_JOB_RETURN;
  6978. }
  6979. LEAVE;
  6980. return IPR_RC_JOB_CONTINUE;
  6981. }
  6982. /**
  6983. * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
  6984. * @ipr_cmd: ipr command struct
  6985. *
  6986. * This utility function sends an inquiry to the adapter.
  6987. *
  6988. * Return value:
  6989. * none
  6990. **/
  6991. static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
  6992. dma_addr_t dma_addr, u8 xfer_len)
  6993. {
  6994. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6995. ENTER;
  6996. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  6997. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6998. ioarcb->cmd_pkt.cdb[0] = INQUIRY;
  6999. ioarcb->cmd_pkt.cdb[1] = flags;
  7000. ioarcb->cmd_pkt.cdb[2] = page;
  7001. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  7002. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
  7003. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  7004. LEAVE;
  7005. }
  7006. /**
  7007. * ipr_inquiry_page_supported - Is the given inquiry page supported
  7008. * @page0: inquiry page 0 buffer
  7009. * @page: page code.
  7010. *
  7011. * This function determines if the specified inquiry page is supported.
  7012. *
  7013. * Return value:
  7014. * 1 if page is supported / 0 if not
  7015. **/
  7016. static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
  7017. {
  7018. int i;
  7019. for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
  7020. if (page0->page[i] == page)
  7021. return 1;
  7022. return 0;
  7023. }
  7024. /**
  7025. * ipr_ioafp_pageC4_inquiry - Send a Page 0xC4 Inquiry to the adapter.
  7026. * @ipr_cmd: ipr command struct
  7027. *
  7028. * This function sends a Page 0xC4 inquiry to the adapter
  7029. * to retrieve software VPD information.
  7030. *
  7031. * Return value:
  7032. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7033. **/
  7034. static int ipr_ioafp_pageC4_inquiry(struct ipr_cmnd *ipr_cmd)
  7035. {
  7036. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7037. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  7038. struct ipr_inquiry_pageC4 *pageC4 = &ioa_cfg->vpd_cbs->pageC4_data;
  7039. ENTER;
  7040. ipr_cmd->job_step = ipr_ioafp_set_caching_parameters;
  7041. memset(pageC4, 0, sizeof(*pageC4));
  7042. if (ipr_inquiry_page_supported(page0, 0xC4)) {
  7043. ipr_ioafp_inquiry(ipr_cmd, 1, 0xC4,
  7044. (ioa_cfg->vpd_cbs_dma
  7045. + offsetof(struct ipr_misc_cbs,
  7046. pageC4_data)),
  7047. sizeof(struct ipr_inquiry_pageC4));
  7048. return IPR_RC_JOB_RETURN;
  7049. }
  7050. LEAVE;
  7051. return IPR_RC_JOB_CONTINUE;
  7052. }
  7053. /**
  7054. * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
  7055. * @ipr_cmd: ipr command struct
  7056. *
  7057. * This function sends a Page 0xD0 inquiry to the adapter
  7058. * to retrieve adapter capabilities.
  7059. *
  7060. * Return value:
  7061. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7062. **/
  7063. static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
  7064. {
  7065. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7066. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  7067. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  7068. ENTER;
  7069. ipr_cmd->job_step = ipr_ioafp_pageC4_inquiry;
  7070. memset(cap, 0, sizeof(*cap));
  7071. if (ipr_inquiry_page_supported(page0, 0xD0)) {
  7072. ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
  7073. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
  7074. sizeof(struct ipr_inquiry_cap));
  7075. return IPR_RC_JOB_RETURN;
  7076. }
  7077. LEAVE;
  7078. return IPR_RC_JOB_CONTINUE;
  7079. }
  7080. /**
  7081. * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
  7082. * @ipr_cmd: ipr command struct
  7083. *
  7084. * This function sends a Page 3 inquiry to the adapter
  7085. * to retrieve software VPD information.
  7086. *
  7087. * Return value:
  7088. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7089. **/
  7090. static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
  7091. {
  7092. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7093. ENTER;
  7094. ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
  7095. ipr_ioafp_inquiry(ipr_cmd, 1, 3,
  7096. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
  7097. sizeof(struct ipr_inquiry_page3));
  7098. LEAVE;
  7099. return IPR_RC_JOB_RETURN;
  7100. }
  7101. /**
  7102. * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
  7103. * @ipr_cmd: ipr command struct
  7104. *
  7105. * This function sends a Page 0 inquiry to the adapter
  7106. * to retrieve supported inquiry pages.
  7107. *
  7108. * Return value:
  7109. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7110. **/
  7111. static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
  7112. {
  7113. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7114. char type[5];
  7115. ENTER;
  7116. /* Grab the type out of the VPD and store it away */
  7117. memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
  7118. type[4] = '\0';
  7119. ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
  7120. if (ipr_invalid_adapter(ioa_cfg)) {
  7121. dev_err(&ioa_cfg->pdev->dev,
  7122. "Adapter not supported in this hardware configuration.\n");
  7123. if (!ipr_testmode) {
  7124. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  7125. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  7126. list_add_tail(&ipr_cmd->queue,
  7127. &ioa_cfg->hrrq->hrrq_free_q);
  7128. return IPR_RC_JOB_RETURN;
  7129. }
  7130. }
  7131. ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
  7132. ipr_ioafp_inquiry(ipr_cmd, 1, 0,
  7133. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
  7134. sizeof(struct ipr_inquiry_page0));
  7135. LEAVE;
  7136. return IPR_RC_JOB_RETURN;
  7137. }
  7138. /**
  7139. * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
  7140. * @ipr_cmd: ipr command struct
  7141. *
  7142. * This function sends a standard inquiry to the adapter.
  7143. *
  7144. * Return value:
  7145. * IPR_RC_JOB_RETURN
  7146. **/
  7147. static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
  7148. {
  7149. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7150. ENTER;
  7151. ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
  7152. ipr_ioafp_inquiry(ipr_cmd, 0, 0,
  7153. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
  7154. sizeof(struct ipr_ioa_vpd));
  7155. LEAVE;
  7156. return IPR_RC_JOB_RETURN;
  7157. }
  7158. /**
  7159. * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
  7160. * @ipr_cmd: ipr command struct
  7161. *
  7162. * This function send an Identify Host Request Response Queue
  7163. * command to establish the HRRQ with the adapter.
  7164. *
  7165. * Return value:
  7166. * IPR_RC_JOB_RETURN
  7167. **/
  7168. static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
  7169. {
  7170. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7171. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  7172. struct ipr_hrr_queue *hrrq;
  7173. ENTER;
  7174. ipr_cmd->job_step = ipr_ioafp_std_inquiry;
  7175. if (ioa_cfg->identify_hrrq_index == 0)
  7176. dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
  7177. if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
  7178. hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
  7179. ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
  7180. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7181. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  7182. if (ioa_cfg->sis64)
  7183. ioarcb->cmd_pkt.cdb[1] = 0x1;
  7184. if (ioa_cfg->nvectors == 1)
  7185. ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
  7186. else
  7187. ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
  7188. ioarcb->cmd_pkt.cdb[2] =
  7189. ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
  7190. ioarcb->cmd_pkt.cdb[3] =
  7191. ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
  7192. ioarcb->cmd_pkt.cdb[4] =
  7193. ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
  7194. ioarcb->cmd_pkt.cdb[5] =
  7195. ((u64) hrrq->host_rrq_dma) & 0xff;
  7196. ioarcb->cmd_pkt.cdb[7] =
  7197. ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
  7198. ioarcb->cmd_pkt.cdb[8] =
  7199. (sizeof(u32) * hrrq->size) & 0xff;
  7200. if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
  7201. ioarcb->cmd_pkt.cdb[9] =
  7202. ioa_cfg->identify_hrrq_index;
  7203. if (ioa_cfg->sis64) {
  7204. ioarcb->cmd_pkt.cdb[10] =
  7205. ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
  7206. ioarcb->cmd_pkt.cdb[11] =
  7207. ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
  7208. ioarcb->cmd_pkt.cdb[12] =
  7209. ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
  7210. ioarcb->cmd_pkt.cdb[13] =
  7211. ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
  7212. }
  7213. if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
  7214. ioarcb->cmd_pkt.cdb[14] =
  7215. ioa_cfg->identify_hrrq_index;
  7216. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  7217. IPR_INTERNAL_TIMEOUT);
  7218. if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
  7219. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7220. LEAVE;
  7221. return IPR_RC_JOB_RETURN;
  7222. }
  7223. LEAVE;
  7224. return IPR_RC_JOB_CONTINUE;
  7225. }
  7226. /**
  7227. * ipr_reset_timer_done - Adapter reset timer function
  7228. * @ipr_cmd: ipr command struct
  7229. *
  7230. * Description: This function is used in adapter reset processing
  7231. * for timing events. If the reset_cmd pointer in the IOA
  7232. * config struct is not this adapter's we are doing nested
  7233. * resets and fail_all_ops will take care of freeing the
  7234. * command block.
  7235. *
  7236. * Return value:
  7237. * none
  7238. **/
  7239. static void ipr_reset_timer_done(struct timer_list *t)
  7240. {
  7241. struct ipr_cmnd *ipr_cmd = from_timer(ipr_cmd, t, timer);
  7242. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7243. unsigned long lock_flags = 0;
  7244. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  7245. if (ioa_cfg->reset_cmd == ipr_cmd) {
  7246. list_del(&ipr_cmd->queue);
  7247. ipr_cmd->done(ipr_cmd);
  7248. }
  7249. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  7250. }
  7251. /**
  7252. * ipr_reset_start_timer - Start a timer for adapter reset job
  7253. * @ipr_cmd: ipr command struct
  7254. * @timeout: timeout value
  7255. *
  7256. * Description: This function is used in adapter reset processing
  7257. * for timing events. If the reset_cmd pointer in the IOA
  7258. * config struct is not this adapter's we are doing nested
  7259. * resets and fail_all_ops will take care of freeing the
  7260. * command block.
  7261. *
  7262. * Return value:
  7263. * none
  7264. **/
  7265. static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
  7266. unsigned long timeout)
  7267. {
  7268. ENTER;
  7269. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  7270. ipr_cmd->done = ipr_reset_ioa_job;
  7271. ipr_cmd->timer.expires = jiffies + timeout;
  7272. ipr_cmd->timer.function = ipr_reset_timer_done;
  7273. add_timer(&ipr_cmd->timer);
  7274. }
  7275. /**
  7276. * ipr_init_ioa_mem - Initialize ioa_cfg control block
  7277. * @ioa_cfg: ioa cfg struct
  7278. *
  7279. * Return value:
  7280. * nothing
  7281. **/
  7282. static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
  7283. {
  7284. struct ipr_hrr_queue *hrrq;
  7285. for_each_hrrq(hrrq, ioa_cfg) {
  7286. spin_lock(&hrrq->_lock);
  7287. memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
  7288. /* Initialize Host RRQ pointers */
  7289. hrrq->hrrq_start = hrrq->host_rrq;
  7290. hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
  7291. hrrq->hrrq_curr = hrrq->hrrq_start;
  7292. hrrq->toggle_bit = 1;
  7293. spin_unlock(&hrrq->_lock);
  7294. }
  7295. wmb();
  7296. ioa_cfg->identify_hrrq_index = 0;
  7297. if (ioa_cfg->hrrq_num == 1)
  7298. atomic_set(&ioa_cfg->hrrq_index, 0);
  7299. else
  7300. atomic_set(&ioa_cfg->hrrq_index, 1);
  7301. /* Zero out config table */
  7302. memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
  7303. }
  7304. /**
  7305. * ipr_reset_next_stage - Process IPL stage change based on feedback register.
  7306. * @ipr_cmd: ipr command struct
  7307. *
  7308. * Return value:
  7309. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7310. **/
  7311. static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
  7312. {
  7313. unsigned long stage, stage_time;
  7314. u32 feedback;
  7315. volatile u32 int_reg;
  7316. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7317. u64 maskval = 0;
  7318. feedback = readl(ioa_cfg->regs.init_feedback_reg);
  7319. stage = feedback & IPR_IPL_INIT_STAGE_MASK;
  7320. stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
  7321. ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
  7322. /* sanity check the stage_time value */
  7323. if (stage_time == 0)
  7324. stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
  7325. else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
  7326. stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
  7327. else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
  7328. stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
  7329. if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
  7330. writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
  7331. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7332. stage_time = ioa_cfg->transop_timeout;
  7333. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7334. } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
  7335. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  7336. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  7337. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7338. maskval = IPR_PCII_IPL_STAGE_CHANGE;
  7339. maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
  7340. writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
  7341. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7342. return IPR_RC_JOB_CONTINUE;
  7343. }
  7344. }
  7345. ipr_cmd->timer.expires = jiffies + stage_time * HZ;
  7346. ipr_cmd->timer.function = ipr_oper_timeout;
  7347. ipr_cmd->done = ipr_reset_ioa_job;
  7348. add_timer(&ipr_cmd->timer);
  7349. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  7350. return IPR_RC_JOB_RETURN;
  7351. }
  7352. /**
  7353. * ipr_reset_enable_ioa - Enable the IOA following a reset.
  7354. * @ipr_cmd: ipr command struct
  7355. *
  7356. * This function reinitializes some control blocks and
  7357. * enables destructive diagnostics on the adapter.
  7358. *
  7359. * Return value:
  7360. * IPR_RC_JOB_RETURN
  7361. **/
  7362. static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
  7363. {
  7364. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7365. volatile u32 int_reg;
  7366. volatile u64 maskval;
  7367. int i;
  7368. ENTER;
  7369. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  7370. ipr_init_ioa_mem(ioa_cfg);
  7371. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  7372. spin_lock(&ioa_cfg->hrrq[i]._lock);
  7373. ioa_cfg->hrrq[i].allow_interrupts = 1;
  7374. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  7375. }
  7376. if (ioa_cfg->sis64) {
  7377. /* Set the adapter to the correct endian mode. */
  7378. writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
  7379. int_reg = readl(ioa_cfg->regs.endian_swap_reg);
  7380. }
  7381. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  7382. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  7383. writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
  7384. ioa_cfg->regs.clr_interrupt_mask_reg32);
  7385. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7386. return IPR_RC_JOB_CONTINUE;
  7387. }
  7388. /* Enable destructive diagnostics on IOA */
  7389. writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
  7390. if (ioa_cfg->sis64) {
  7391. maskval = IPR_PCII_IPL_STAGE_CHANGE;
  7392. maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
  7393. writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
  7394. } else
  7395. writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
  7396. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7397. dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
  7398. if (ioa_cfg->sis64) {
  7399. ipr_cmd->job_step = ipr_reset_next_stage;
  7400. return IPR_RC_JOB_CONTINUE;
  7401. }
  7402. ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
  7403. ipr_cmd->timer.function = ipr_oper_timeout;
  7404. ipr_cmd->done = ipr_reset_ioa_job;
  7405. add_timer(&ipr_cmd->timer);
  7406. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  7407. LEAVE;
  7408. return IPR_RC_JOB_RETURN;
  7409. }
  7410. /**
  7411. * ipr_reset_wait_for_dump - Wait for a dump to timeout.
  7412. * @ipr_cmd: ipr command struct
  7413. *
  7414. * This function is invoked when an adapter dump has run out
  7415. * of processing time.
  7416. *
  7417. * Return value:
  7418. * IPR_RC_JOB_CONTINUE
  7419. **/
  7420. static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
  7421. {
  7422. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7423. if (ioa_cfg->sdt_state == GET_DUMP)
  7424. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  7425. else if (ioa_cfg->sdt_state == READ_DUMP)
  7426. ioa_cfg->sdt_state = ABORT_DUMP;
  7427. ioa_cfg->dump_timeout = 1;
  7428. ipr_cmd->job_step = ipr_reset_alert;
  7429. return IPR_RC_JOB_CONTINUE;
  7430. }
  7431. /**
  7432. * ipr_unit_check_no_data - Log a unit check/no data error log
  7433. * @ioa_cfg: ioa config struct
  7434. *
  7435. * Logs an error indicating the adapter unit checked, but for some
  7436. * reason, we were unable to fetch the unit check buffer.
  7437. *
  7438. * Return value:
  7439. * nothing
  7440. **/
  7441. static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
  7442. {
  7443. ioa_cfg->errors_logged++;
  7444. dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
  7445. }
  7446. /**
  7447. * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
  7448. * @ioa_cfg: ioa config struct
  7449. *
  7450. * Fetches the unit check buffer from the adapter by clocking the data
  7451. * through the mailbox register.
  7452. *
  7453. * Return value:
  7454. * nothing
  7455. **/
  7456. static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
  7457. {
  7458. unsigned long mailbox;
  7459. struct ipr_hostrcb *hostrcb;
  7460. struct ipr_uc_sdt sdt;
  7461. int rc, length;
  7462. u32 ioasc;
  7463. mailbox = readl(ioa_cfg->ioa_mailbox);
  7464. if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
  7465. ipr_unit_check_no_data(ioa_cfg);
  7466. return;
  7467. }
  7468. memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
  7469. rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
  7470. (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
  7471. if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
  7472. ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
  7473. (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
  7474. ipr_unit_check_no_data(ioa_cfg);
  7475. return;
  7476. }
  7477. /* Find length of the first sdt entry (UC buffer) */
  7478. if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
  7479. length = be32_to_cpu(sdt.entry[0].end_token);
  7480. else
  7481. length = (be32_to_cpu(sdt.entry[0].end_token) -
  7482. be32_to_cpu(sdt.entry[0].start_token)) &
  7483. IPR_FMT2_MBX_ADDR_MASK;
  7484. hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
  7485. struct ipr_hostrcb, queue);
  7486. list_del_init(&hostrcb->queue);
  7487. memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
  7488. rc = ipr_get_ldump_data_section(ioa_cfg,
  7489. be32_to_cpu(sdt.entry[0].start_token),
  7490. (__be32 *)&hostrcb->hcam,
  7491. min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
  7492. if (!rc) {
  7493. ipr_handle_log_data(ioa_cfg, hostrcb);
  7494. ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  7495. if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
  7496. ioa_cfg->sdt_state == GET_DUMP)
  7497. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  7498. } else
  7499. ipr_unit_check_no_data(ioa_cfg);
  7500. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  7501. }
  7502. /**
  7503. * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
  7504. * @ipr_cmd: ipr command struct
  7505. *
  7506. * Description: This function will call to get the unit check buffer.
  7507. *
  7508. * Return value:
  7509. * IPR_RC_JOB_RETURN
  7510. **/
  7511. static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
  7512. {
  7513. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7514. ENTER;
  7515. ioa_cfg->ioa_unit_checked = 0;
  7516. ipr_get_unit_check_buffer(ioa_cfg);
  7517. ipr_cmd->job_step = ipr_reset_alert;
  7518. ipr_reset_start_timer(ipr_cmd, 0);
  7519. LEAVE;
  7520. return IPR_RC_JOB_RETURN;
  7521. }
  7522. static int ipr_dump_mailbox_wait(struct ipr_cmnd *ipr_cmd)
  7523. {
  7524. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7525. ENTER;
  7526. if (ioa_cfg->sdt_state != GET_DUMP)
  7527. return IPR_RC_JOB_RETURN;
  7528. if (!ioa_cfg->sis64 || !ipr_cmd->u.time_left ||
  7529. (readl(ioa_cfg->regs.sense_interrupt_reg) &
  7530. IPR_PCII_MAILBOX_STABLE)) {
  7531. if (!ipr_cmd->u.time_left)
  7532. dev_err(&ioa_cfg->pdev->dev,
  7533. "Timed out waiting for Mailbox register.\n");
  7534. ioa_cfg->sdt_state = READ_DUMP;
  7535. ioa_cfg->dump_timeout = 0;
  7536. if (ioa_cfg->sis64)
  7537. ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
  7538. else
  7539. ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
  7540. ipr_cmd->job_step = ipr_reset_wait_for_dump;
  7541. schedule_work(&ioa_cfg->work_q);
  7542. } else {
  7543. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  7544. ipr_reset_start_timer(ipr_cmd,
  7545. IPR_CHECK_FOR_RESET_TIMEOUT);
  7546. }
  7547. LEAVE;
  7548. return IPR_RC_JOB_RETURN;
  7549. }
  7550. /**
  7551. * ipr_reset_restore_cfg_space - Restore PCI config space.
  7552. * @ipr_cmd: ipr command struct
  7553. *
  7554. * Description: This function restores the saved PCI config space of
  7555. * the adapter, fails all outstanding ops back to the callers, and
  7556. * fetches the dump/unit check if applicable to this reset.
  7557. *
  7558. * Return value:
  7559. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7560. **/
  7561. static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
  7562. {
  7563. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7564. u32 int_reg;
  7565. ENTER;
  7566. ioa_cfg->pdev->state_saved = true;
  7567. pci_restore_state(ioa_cfg->pdev);
  7568. if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
  7569. ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  7570. return IPR_RC_JOB_CONTINUE;
  7571. }
  7572. ipr_fail_all_ops(ioa_cfg);
  7573. if (ioa_cfg->sis64) {
  7574. /* Set the adapter to the correct endian mode. */
  7575. writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
  7576. int_reg = readl(ioa_cfg->regs.endian_swap_reg);
  7577. }
  7578. if (ioa_cfg->ioa_unit_checked) {
  7579. if (ioa_cfg->sis64) {
  7580. ipr_cmd->job_step = ipr_reset_get_unit_check_job;
  7581. ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
  7582. return IPR_RC_JOB_RETURN;
  7583. } else {
  7584. ioa_cfg->ioa_unit_checked = 0;
  7585. ipr_get_unit_check_buffer(ioa_cfg);
  7586. ipr_cmd->job_step = ipr_reset_alert;
  7587. ipr_reset_start_timer(ipr_cmd, 0);
  7588. return IPR_RC_JOB_RETURN;
  7589. }
  7590. }
  7591. if (ioa_cfg->in_ioa_bringdown) {
  7592. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  7593. } else if (ioa_cfg->sdt_state == GET_DUMP) {
  7594. ipr_cmd->job_step = ipr_dump_mailbox_wait;
  7595. ipr_cmd->u.time_left = IPR_WAIT_FOR_MAILBOX;
  7596. } else {
  7597. ipr_cmd->job_step = ipr_reset_enable_ioa;
  7598. }
  7599. LEAVE;
  7600. return IPR_RC_JOB_CONTINUE;
  7601. }
  7602. /**
  7603. * ipr_reset_bist_done - BIST has completed on the adapter.
  7604. * @ipr_cmd: ipr command struct
  7605. *
  7606. * Description: Unblock config space and resume the reset process.
  7607. *
  7608. * Return value:
  7609. * IPR_RC_JOB_CONTINUE
  7610. **/
  7611. static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
  7612. {
  7613. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7614. ENTER;
  7615. if (ioa_cfg->cfg_locked)
  7616. pci_cfg_access_unlock(ioa_cfg->pdev);
  7617. ioa_cfg->cfg_locked = 0;
  7618. ipr_cmd->job_step = ipr_reset_restore_cfg_space;
  7619. LEAVE;
  7620. return IPR_RC_JOB_CONTINUE;
  7621. }
  7622. /**
  7623. * ipr_reset_start_bist - Run BIST on the adapter.
  7624. * @ipr_cmd: ipr command struct
  7625. *
  7626. * Description: This function runs BIST on the adapter, then delays 2 seconds.
  7627. *
  7628. * Return value:
  7629. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7630. **/
  7631. static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
  7632. {
  7633. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7634. int rc = PCIBIOS_SUCCESSFUL;
  7635. ENTER;
  7636. if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
  7637. writel(IPR_UPROCI_SIS64_START_BIST,
  7638. ioa_cfg->regs.set_uproc_interrupt_reg32);
  7639. else
  7640. rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
  7641. if (rc == PCIBIOS_SUCCESSFUL) {
  7642. ipr_cmd->job_step = ipr_reset_bist_done;
  7643. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  7644. rc = IPR_RC_JOB_RETURN;
  7645. } else {
  7646. if (ioa_cfg->cfg_locked)
  7647. pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
  7648. ioa_cfg->cfg_locked = 0;
  7649. ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  7650. rc = IPR_RC_JOB_CONTINUE;
  7651. }
  7652. LEAVE;
  7653. return rc;
  7654. }
  7655. /**
  7656. * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
  7657. * @ipr_cmd: ipr command struct
  7658. *
  7659. * Description: This clears PCI reset to the adapter and delays two seconds.
  7660. *
  7661. * Return value:
  7662. * IPR_RC_JOB_RETURN
  7663. **/
  7664. static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
  7665. {
  7666. ENTER;
  7667. ipr_cmd->job_step = ipr_reset_bist_done;
  7668. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  7669. LEAVE;
  7670. return IPR_RC_JOB_RETURN;
  7671. }
  7672. /**
  7673. * ipr_reset_reset_work - Pulse a PCIe fundamental reset
  7674. * @work: work struct
  7675. *
  7676. * Description: This pulses warm reset to a slot.
  7677. *
  7678. **/
  7679. static void ipr_reset_reset_work(struct work_struct *work)
  7680. {
  7681. struct ipr_cmnd *ipr_cmd = container_of(work, struct ipr_cmnd, work);
  7682. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7683. struct pci_dev *pdev = ioa_cfg->pdev;
  7684. unsigned long lock_flags = 0;
  7685. ENTER;
  7686. pci_set_pcie_reset_state(pdev, pcie_warm_reset);
  7687. msleep(jiffies_to_msecs(IPR_PCI_RESET_TIMEOUT));
  7688. pci_set_pcie_reset_state(pdev, pcie_deassert_reset);
  7689. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  7690. if (ioa_cfg->reset_cmd == ipr_cmd)
  7691. ipr_reset_ioa_job(ipr_cmd);
  7692. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  7693. LEAVE;
  7694. }
  7695. /**
  7696. * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
  7697. * @ipr_cmd: ipr command struct
  7698. *
  7699. * Description: This asserts PCI reset to the adapter.
  7700. *
  7701. * Return value:
  7702. * IPR_RC_JOB_RETURN
  7703. **/
  7704. static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
  7705. {
  7706. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7707. ENTER;
  7708. INIT_WORK(&ipr_cmd->work, ipr_reset_reset_work);
  7709. queue_work(ioa_cfg->reset_work_q, &ipr_cmd->work);
  7710. ipr_cmd->job_step = ipr_reset_slot_reset_done;
  7711. LEAVE;
  7712. return IPR_RC_JOB_RETURN;
  7713. }
  7714. /**
  7715. * ipr_reset_block_config_access_wait - Wait for permission to block config access
  7716. * @ipr_cmd: ipr command struct
  7717. *
  7718. * Description: This attempts to block config access to the IOA.
  7719. *
  7720. * Return value:
  7721. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7722. **/
  7723. static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
  7724. {
  7725. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7726. int rc = IPR_RC_JOB_CONTINUE;
  7727. if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
  7728. ioa_cfg->cfg_locked = 1;
  7729. ipr_cmd->job_step = ioa_cfg->reset;
  7730. } else {
  7731. if (ipr_cmd->u.time_left) {
  7732. rc = IPR_RC_JOB_RETURN;
  7733. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  7734. ipr_reset_start_timer(ipr_cmd,
  7735. IPR_CHECK_FOR_RESET_TIMEOUT);
  7736. } else {
  7737. ipr_cmd->job_step = ioa_cfg->reset;
  7738. dev_err(&ioa_cfg->pdev->dev,
  7739. "Timed out waiting to lock config access. Resetting anyway.\n");
  7740. }
  7741. }
  7742. return rc;
  7743. }
  7744. /**
  7745. * ipr_reset_block_config_access - Block config access to the IOA
  7746. * @ipr_cmd: ipr command struct
  7747. *
  7748. * Description: This attempts to block config access to the IOA
  7749. *
  7750. * Return value:
  7751. * IPR_RC_JOB_CONTINUE
  7752. **/
  7753. static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
  7754. {
  7755. ipr_cmd->ioa_cfg->cfg_locked = 0;
  7756. ipr_cmd->job_step = ipr_reset_block_config_access_wait;
  7757. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  7758. return IPR_RC_JOB_CONTINUE;
  7759. }
  7760. /**
  7761. * ipr_reset_allowed - Query whether or not IOA can be reset
  7762. * @ioa_cfg: ioa config struct
  7763. *
  7764. * Return value:
  7765. * 0 if reset not allowed / non-zero if reset is allowed
  7766. **/
  7767. static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
  7768. {
  7769. volatile u32 temp_reg;
  7770. temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  7771. return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
  7772. }
  7773. /**
  7774. * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
  7775. * @ipr_cmd: ipr command struct
  7776. *
  7777. * Description: This function waits for adapter permission to run BIST,
  7778. * then runs BIST. If the adapter does not give permission after a
  7779. * reasonable time, we will reset the adapter anyway. The impact of
  7780. * resetting the adapter without warning the adapter is the risk of
  7781. * losing the persistent error log on the adapter. If the adapter is
  7782. * reset while it is writing to the flash on the adapter, the flash
  7783. * segment will have bad ECC and be zeroed.
  7784. *
  7785. * Return value:
  7786. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7787. **/
  7788. static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
  7789. {
  7790. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7791. int rc = IPR_RC_JOB_RETURN;
  7792. if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
  7793. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  7794. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  7795. } else {
  7796. ipr_cmd->job_step = ipr_reset_block_config_access;
  7797. rc = IPR_RC_JOB_CONTINUE;
  7798. }
  7799. return rc;
  7800. }
  7801. /**
  7802. * ipr_reset_alert - Alert the adapter of a pending reset
  7803. * @ipr_cmd: ipr command struct
  7804. *
  7805. * Description: This function alerts the adapter that it will be reset.
  7806. * If memory space is not currently enabled, proceed directly
  7807. * to running BIST on the adapter. The timer must always be started
  7808. * so we guarantee we do not run BIST from ipr_isr.
  7809. *
  7810. * Return value:
  7811. * IPR_RC_JOB_RETURN
  7812. **/
  7813. static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
  7814. {
  7815. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7816. u16 cmd_reg;
  7817. int rc;
  7818. ENTER;
  7819. rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
  7820. if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
  7821. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  7822. writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
  7823. ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
  7824. } else {
  7825. ipr_cmd->job_step = ipr_reset_block_config_access;
  7826. }
  7827. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  7828. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  7829. LEAVE;
  7830. return IPR_RC_JOB_RETURN;
  7831. }
  7832. /**
  7833. * ipr_reset_quiesce_done - Complete IOA disconnect
  7834. * @ipr_cmd: ipr command struct
  7835. *
  7836. * Description: Freeze the adapter to complete quiesce processing
  7837. *
  7838. * Return value:
  7839. * IPR_RC_JOB_CONTINUE
  7840. **/
  7841. static int ipr_reset_quiesce_done(struct ipr_cmnd *ipr_cmd)
  7842. {
  7843. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7844. ENTER;
  7845. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  7846. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  7847. LEAVE;
  7848. return IPR_RC_JOB_CONTINUE;
  7849. }
  7850. /**
  7851. * ipr_reset_cancel_hcam_done - Check for outstanding commands
  7852. * @ipr_cmd: ipr command struct
  7853. *
  7854. * Description: Ensure nothing is outstanding to the IOA and
  7855. * proceed with IOA disconnect. Otherwise reset the IOA.
  7856. *
  7857. * Return value:
  7858. * IPR_RC_JOB_RETURN / IPR_RC_JOB_CONTINUE
  7859. **/
  7860. static int ipr_reset_cancel_hcam_done(struct ipr_cmnd *ipr_cmd)
  7861. {
  7862. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7863. struct ipr_cmnd *loop_cmd;
  7864. struct ipr_hrr_queue *hrrq;
  7865. int rc = IPR_RC_JOB_CONTINUE;
  7866. int count = 0;
  7867. ENTER;
  7868. ipr_cmd->job_step = ipr_reset_quiesce_done;
  7869. for_each_hrrq(hrrq, ioa_cfg) {
  7870. spin_lock(&hrrq->_lock);
  7871. list_for_each_entry(loop_cmd, &hrrq->hrrq_pending_q, queue) {
  7872. count++;
  7873. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  7874. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  7875. rc = IPR_RC_JOB_RETURN;
  7876. break;
  7877. }
  7878. spin_unlock(&hrrq->_lock);
  7879. if (count)
  7880. break;
  7881. }
  7882. LEAVE;
  7883. return rc;
  7884. }
  7885. /**
  7886. * ipr_reset_cancel_hcam - Cancel outstanding HCAMs
  7887. * @ipr_cmd: ipr command struct
  7888. *
  7889. * Description: Cancel any oustanding HCAMs to the IOA.
  7890. *
  7891. * Return value:
  7892. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7893. **/
  7894. static int ipr_reset_cancel_hcam(struct ipr_cmnd *ipr_cmd)
  7895. {
  7896. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7897. int rc = IPR_RC_JOB_CONTINUE;
  7898. struct ipr_cmd_pkt *cmd_pkt;
  7899. struct ipr_cmnd *hcam_cmd;
  7900. struct ipr_hrr_queue *hrrq = &ioa_cfg->hrrq[IPR_INIT_HRRQ];
  7901. ENTER;
  7902. ipr_cmd->job_step = ipr_reset_cancel_hcam_done;
  7903. if (!hrrq->ioa_is_dead) {
  7904. if (!list_empty(&ioa_cfg->hostrcb_pending_q)) {
  7905. list_for_each_entry(hcam_cmd, &hrrq->hrrq_pending_q, queue) {
  7906. if (hcam_cmd->ioarcb.cmd_pkt.cdb[0] != IPR_HOST_CONTROLLED_ASYNC)
  7907. continue;
  7908. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7909. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  7910. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  7911. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  7912. cmd_pkt->cdb[0] = IPR_CANCEL_REQUEST;
  7913. cmd_pkt->cdb[1] = IPR_CANCEL_64BIT_IOARCB;
  7914. cmd_pkt->cdb[10] = ((u64) hcam_cmd->dma_addr >> 56) & 0xff;
  7915. cmd_pkt->cdb[11] = ((u64) hcam_cmd->dma_addr >> 48) & 0xff;
  7916. cmd_pkt->cdb[12] = ((u64) hcam_cmd->dma_addr >> 40) & 0xff;
  7917. cmd_pkt->cdb[13] = ((u64) hcam_cmd->dma_addr >> 32) & 0xff;
  7918. cmd_pkt->cdb[2] = ((u64) hcam_cmd->dma_addr >> 24) & 0xff;
  7919. cmd_pkt->cdb[3] = ((u64) hcam_cmd->dma_addr >> 16) & 0xff;
  7920. cmd_pkt->cdb[4] = ((u64) hcam_cmd->dma_addr >> 8) & 0xff;
  7921. cmd_pkt->cdb[5] = ((u64) hcam_cmd->dma_addr) & 0xff;
  7922. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  7923. IPR_CANCEL_TIMEOUT);
  7924. rc = IPR_RC_JOB_RETURN;
  7925. ipr_cmd->job_step = ipr_reset_cancel_hcam;
  7926. break;
  7927. }
  7928. }
  7929. } else
  7930. ipr_cmd->job_step = ipr_reset_alert;
  7931. LEAVE;
  7932. return rc;
  7933. }
  7934. /**
  7935. * ipr_reset_ucode_download_done - Microcode download completion
  7936. * @ipr_cmd: ipr command struct
  7937. *
  7938. * Description: This function unmaps the microcode download buffer.
  7939. *
  7940. * Return value:
  7941. * IPR_RC_JOB_CONTINUE
  7942. **/
  7943. static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
  7944. {
  7945. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7946. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  7947. dma_unmap_sg(&ioa_cfg->pdev->dev, sglist->scatterlist,
  7948. sglist->num_sg, DMA_TO_DEVICE);
  7949. ipr_cmd->job_step = ipr_reset_alert;
  7950. return IPR_RC_JOB_CONTINUE;
  7951. }
  7952. /**
  7953. * ipr_reset_ucode_download - Download microcode to the adapter
  7954. * @ipr_cmd: ipr command struct
  7955. *
  7956. * Description: This function checks to see if it there is microcode
  7957. * to download to the adapter. If there is, a download is performed.
  7958. *
  7959. * Return value:
  7960. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7961. **/
  7962. static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
  7963. {
  7964. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7965. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  7966. ENTER;
  7967. ipr_cmd->job_step = ipr_reset_alert;
  7968. if (!sglist)
  7969. return IPR_RC_JOB_CONTINUE;
  7970. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7971. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  7972. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
  7973. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
  7974. ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
  7975. ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
  7976. ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
  7977. if (ioa_cfg->sis64)
  7978. ipr_build_ucode_ioadl64(ipr_cmd, sglist);
  7979. else
  7980. ipr_build_ucode_ioadl(ipr_cmd, sglist);
  7981. ipr_cmd->job_step = ipr_reset_ucode_download_done;
  7982. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  7983. IPR_WRITE_BUFFER_TIMEOUT);
  7984. LEAVE;
  7985. return IPR_RC_JOB_RETURN;
  7986. }
  7987. /**
  7988. * ipr_reset_shutdown_ioa - Shutdown the adapter
  7989. * @ipr_cmd: ipr command struct
  7990. *
  7991. * Description: This function issues an adapter shutdown of the
  7992. * specified type to the specified adapter as part of the
  7993. * adapter reset job.
  7994. *
  7995. * Return value:
  7996. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  7997. **/
  7998. static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
  7999. {
  8000. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  8001. enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
  8002. unsigned long timeout;
  8003. int rc = IPR_RC_JOB_CONTINUE;
  8004. ENTER;
  8005. if (shutdown_type == IPR_SHUTDOWN_QUIESCE)
  8006. ipr_cmd->job_step = ipr_reset_cancel_hcam;
  8007. else if (shutdown_type != IPR_SHUTDOWN_NONE &&
  8008. !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
  8009. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  8010. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  8011. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  8012. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
  8013. if (shutdown_type == IPR_SHUTDOWN_NORMAL)
  8014. timeout = IPR_SHUTDOWN_TIMEOUT;
  8015. else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
  8016. timeout = IPR_INTERNAL_TIMEOUT;
  8017. else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  8018. timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
  8019. else
  8020. timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
  8021. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
  8022. rc = IPR_RC_JOB_RETURN;
  8023. ipr_cmd->job_step = ipr_reset_ucode_download;
  8024. } else
  8025. ipr_cmd->job_step = ipr_reset_alert;
  8026. LEAVE;
  8027. return rc;
  8028. }
  8029. /**
  8030. * ipr_reset_ioa_job - Adapter reset job
  8031. * @ipr_cmd: ipr command struct
  8032. *
  8033. * Description: This function is the job router for the adapter reset job.
  8034. *
  8035. * Return value:
  8036. * none
  8037. **/
  8038. static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
  8039. {
  8040. u32 rc, ioasc;
  8041. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  8042. do {
  8043. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  8044. if (ioa_cfg->reset_cmd != ipr_cmd) {
  8045. /*
  8046. * We are doing nested adapter resets and this is
  8047. * not the current reset job.
  8048. */
  8049. list_add_tail(&ipr_cmd->queue,
  8050. &ipr_cmd->hrrq->hrrq_free_q);
  8051. return;
  8052. }
  8053. if (IPR_IOASC_SENSE_KEY(ioasc)) {
  8054. rc = ipr_cmd->job_step_failed(ipr_cmd);
  8055. if (rc == IPR_RC_JOB_RETURN)
  8056. return;
  8057. }
  8058. ipr_reinit_ipr_cmnd(ipr_cmd);
  8059. ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
  8060. rc = ipr_cmd->job_step(ipr_cmd);
  8061. } while (rc == IPR_RC_JOB_CONTINUE);
  8062. }
  8063. /**
  8064. * _ipr_initiate_ioa_reset - Initiate an adapter reset
  8065. * @ioa_cfg: ioa config struct
  8066. * @job_step: first job step of reset job
  8067. * @shutdown_type: shutdown type
  8068. *
  8069. * Description: This function will initiate the reset of the given adapter
  8070. * starting at the selected job step.
  8071. * If the caller needs to wait on the completion of the reset,
  8072. * the caller must sleep on the reset_wait_q.
  8073. *
  8074. * Return value:
  8075. * none
  8076. **/
  8077. static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  8078. int (*job_step) (struct ipr_cmnd *),
  8079. enum ipr_shutdown_type shutdown_type)
  8080. {
  8081. struct ipr_cmnd *ipr_cmd;
  8082. int i;
  8083. ioa_cfg->in_reset_reload = 1;
  8084. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8085. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8086. ioa_cfg->hrrq[i].allow_cmds = 0;
  8087. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8088. }
  8089. wmb();
  8090. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
  8091. ioa_cfg->scsi_unblock = 0;
  8092. ioa_cfg->scsi_blocked = 1;
  8093. scsi_block_requests(ioa_cfg->host);
  8094. }
  8095. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  8096. ioa_cfg->reset_cmd = ipr_cmd;
  8097. ipr_cmd->job_step = job_step;
  8098. ipr_cmd->u.shutdown_type = shutdown_type;
  8099. ipr_reset_ioa_job(ipr_cmd);
  8100. }
  8101. /**
  8102. * ipr_initiate_ioa_reset - Initiate an adapter reset
  8103. * @ioa_cfg: ioa config struct
  8104. * @shutdown_type: shutdown type
  8105. *
  8106. * Description: This function will initiate the reset of the given adapter.
  8107. * If the caller needs to wait on the completion of the reset,
  8108. * the caller must sleep on the reset_wait_q.
  8109. *
  8110. * Return value:
  8111. * none
  8112. **/
  8113. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  8114. enum ipr_shutdown_type shutdown_type)
  8115. {
  8116. int i;
  8117. if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
  8118. return;
  8119. if (ioa_cfg->in_reset_reload) {
  8120. if (ioa_cfg->sdt_state == GET_DUMP)
  8121. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  8122. else if (ioa_cfg->sdt_state == READ_DUMP)
  8123. ioa_cfg->sdt_state = ABORT_DUMP;
  8124. }
  8125. if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
  8126. dev_err(&ioa_cfg->pdev->dev,
  8127. "IOA taken offline - error recovery failed\n");
  8128. ioa_cfg->reset_retries = 0;
  8129. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8130. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8131. ioa_cfg->hrrq[i].ioa_is_dead = 1;
  8132. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8133. }
  8134. wmb();
  8135. if (ioa_cfg->in_ioa_bringdown) {
  8136. ioa_cfg->reset_cmd = NULL;
  8137. ioa_cfg->in_reset_reload = 0;
  8138. ipr_fail_all_ops(ioa_cfg);
  8139. wake_up_all(&ioa_cfg->reset_wait_q);
  8140. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
  8141. ioa_cfg->scsi_unblock = 1;
  8142. schedule_work(&ioa_cfg->work_q);
  8143. }
  8144. return;
  8145. } else {
  8146. ioa_cfg->in_ioa_bringdown = 1;
  8147. shutdown_type = IPR_SHUTDOWN_NONE;
  8148. }
  8149. }
  8150. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
  8151. shutdown_type);
  8152. }
  8153. /**
  8154. * ipr_reset_freeze - Hold off all I/O activity
  8155. * @ipr_cmd: ipr command struct
  8156. *
  8157. * Description: If the PCI slot is frozen, hold off all I/O
  8158. * activity; then, as soon as the slot is available again,
  8159. * initiate an adapter reset.
  8160. */
  8161. static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
  8162. {
  8163. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  8164. int i;
  8165. /* Disallow new interrupts, avoid loop */
  8166. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8167. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8168. ioa_cfg->hrrq[i].allow_interrupts = 0;
  8169. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8170. }
  8171. wmb();
  8172. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
  8173. ipr_cmd->done = ipr_reset_ioa_job;
  8174. return IPR_RC_JOB_RETURN;
  8175. }
  8176. /**
  8177. * ipr_pci_mmio_enabled - Called when MMIO has been re-enabled
  8178. * @pdev: PCI device struct
  8179. *
  8180. * Description: This routine is called to tell us that the MMIO
  8181. * access to the IOA has been restored
  8182. */
  8183. static pci_ers_result_t ipr_pci_mmio_enabled(struct pci_dev *pdev)
  8184. {
  8185. unsigned long flags = 0;
  8186. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8187. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8188. if (!ioa_cfg->probe_done)
  8189. pci_save_state(pdev);
  8190. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8191. return PCI_ERS_RESULT_NEED_RESET;
  8192. }
  8193. /**
  8194. * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
  8195. * @pdev: PCI device struct
  8196. *
  8197. * Description: This routine is called to tell us that the PCI bus
  8198. * is down. Can't do anything here, except put the device driver
  8199. * into a holding pattern, waiting for the PCI bus to come back.
  8200. */
  8201. static void ipr_pci_frozen(struct pci_dev *pdev)
  8202. {
  8203. unsigned long flags = 0;
  8204. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8205. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8206. if (ioa_cfg->probe_done)
  8207. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
  8208. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8209. }
  8210. /**
  8211. * ipr_pci_slot_reset - Called when PCI slot has been reset.
  8212. * @pdev: PCI device struct
  8213. *
  8214. * Description: This routine is called by the pci error recovery
  8215. * code after the PCI slot has been reset, just before we
  8216. * should resume normal operations.
  8217. */
  8218. static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
  8219. {
  8220. unsigned long flags = 0;
  8221. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8222. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8223. if (ioa_cfg->probe_done) {
  8224. if (ioa_cfg->needs_warm_reset)
  8225. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  8226. else
  8227. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
  8228. IPR_SHUTDOWN_NONE);
  8229. } else
  8230. wake_up_all(&ioa_cfg->eeh_wait_q);
  8231. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8232. return PCI_ERS_RESULT_RECOVERED;
  8233. }
  8234. /**
  8235. * ipr_pci_perm_failure - Called when PCI slot is dead for good.
  8236. * @pdev: PCI device struct
  8237. *
  8238. * Description: This routine is called when the PCI bus has
  8239. * permanently failed.
  8240. */
  8241. static void ipr_pci_perm_failure(struct pci_dev *pdev)
  8242. {
  8243. unsigned long flags = 0;
  8244. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8245. int i;
  8246. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8247. if (ioa_cfg->probe_done) {
  8248. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  8249. ioa_cfg->sdt_state = ABORT_DUMP;
  8250. ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
  8251. ioa_cfg->in_ioa_bringdown = 1;
  8252. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8253. spin_lock(&ioa_cfg->hrrq[i]._lock);
  8254. ioa_cfg->hrrq[i].allow_cmds = 0;
  8255. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  8256. }
  8257. wmb();
  8258. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  8259. } else
  8260. wake_up_all(&ioa_cfg->eeh_wait_q);
  8261. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8262. }
  8263. /**
  8264. * ipr_pci_error_detected - Called when a PCI error is detected.
  8265. * @pdev: PCI device struct
  8266. * @state: PCI channel state
  8267. *
  8268. * Description: Called when a PCI error is detected.
  8269. *
  8270. * Return value:
  8271. * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
  8272. */
  8273. static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
  8274. pci_channel_state_t state)
  8275. {
  8276. switch (state) {
  8277. case pci_channel_io_frozen:
  8278. ipr_pci_frozen(pdev);
  8279. return PCI_ERS_RESULT_CAN_RECOVER;
  8280. case pci_channel_io_perm_failure:
  8281. ipr_pci_perm_failure(pdev);
  8282. return PCI_ERS_RESULT_DISCONNECT;
  8283. break;
  8284. default:
  8285. break;
  8286. }
  8287. return PCI_ERS_RESULT_NEED_RESET;
  8288. }
  8289. /**
  8290. * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
  8291. * @ioa_cfg: ioa cfg struct
  8292. *
  8293. * Description: This is the second phase of adapter initialization
  8294. * This function takes care of initilizing the adapter to the point
  8295. * where it can accept new commands.
  8296. * Return value:
  8297. * 0 on success / -EIO on failure
  8298. **/
  8299. static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
  8300. {
  8301. int rc = 0;
  8302. unsigned long host_lock_flags = 0;
  8303. ENTER;
  8304. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  8305. dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
  8306. ioa_cfg->probe_done = 1;
  8307. if (ioa_cfg->needs_hard_reset) {
  8308. ioa_cfg->needs_hard_reset = 0;
  8309. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  8310. } else
  8311. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
  8312. IPR_SHUTDOWN_NONE);
  8313. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  8314. LEAVE;
  8315. return rc;
  8316. }
  8317. /**
  8318. * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
  8319. * @ioa_cfg: ioa config struct
  8320. *
  8321. * Return value:
  8322. * none
  8323. **/
  8324. static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  8325. {
  8326. int i;
  8327. if (ioa_cfg->ipr_cmnd_list) {
  8328. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  8329. if (ioa_cfg->ipr_cmnd_list[i])
  8330. dma_pool_free(ioa_cfg->ipr_cmd_pool,
  8331. ioa_cfg->ipr_cmnd_list[i],
  8332. ioa_cfg->ipr_cmnd_list_dma[i]);
  8333. ioa_cfg->ipr_cmnd_list[i] = NULL;
  8334. }
  8335. }
  8336. if (ioa_cfg->ipr_cmd_pool)
  8337. dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
  8338. kfree(ioa_cfg->ipr_cmnd_list);
  8339. kfree(ioa_cfg->ipr_cmnd_list_dma);
  8340. ioa_cfg->ipr_cmnd_list = NULL;
  8341. ioa_cfg->ipr_cmnd_list_dma = NULL;
  8342. ioa_cfg->ipr_cmd_pool = NULL;
  8343. }
  8344. /**
  8345. * ipr_free_mem - Frees memory allocated for an adapter
  8346. * @ioa_cfg: ioa cfg struct
  8347. *
  8348. * Return value:
  8349. * nothing
  8350. **/
  8351. static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
  8352. {
  8353. int i;
  8354. kfree(ioa_cfg->res_entries);
  8355. dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_misc_cbs),
  8356. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  8357. ipr_free_cmd_blks(ioa_cfg);
  8358. for (i = 0; i < ioa_cfg->hrrq_num; i++)
  8359. dma_free_coherent(&ioa_cfg->pdev->dev,
  8360. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8361. ioa_cfg->hrrq[i].host_rrq,
  8362. ioa_cfg->hrrq[i].host_rrq_dma);
  8363. dma_free_coherent(&ioa_cfg->pdev->dev, ioa_cfg->cfg_table_size,
  8364. ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
  8365. for (i = 0; i < IPR_MAX_HCAMS; i++) {
  8366. dma_free_coherent(&ioa_cfg->pdev->dev,
  8367. sizeof(struct ipr_hostrcb),
  8368. ioa_cfg->hostrcb[i],
  8369. ioa_cfg->hostrcb_dma[i]);
  8370. }
  8371. ipr_free_dump(ioa_cfg);
  8372. kfree(ioa_cfg->trace);
  8373. }
  8374. /**
  8375. * ipr_free_irqs - Free all allocated IRQs for the adapter.
  8376. * @ioa_cfg: ipr cfg struct
  8377. *
  8378. * This function frees all allocated IRQs for the
  8379. * specified adapter.
  8380. *
  8381. * Return value:
  8382. * none
  8383. **/
  8384. static void ipr_free_irqs(struct ipr_ioa_cfg *ioa_cfg)
  8385. {
  8386. struct pci_dev *pdev = ioa_cfg->pdev;
  8387. int i;
  8388. for (i = 0; i < ioa_cfg->nvectors; i++)
  8389. free_irq(pci_irq_vector(pdev, i), &ioa_cfg->hrrq[i]);
  8390. pci_free_irq_vectors(pdev);
  8391. }
  8392. /**
  8393. * ipr_free_all_resources - Free all allocated resources for an adapter.
  8394. * @ipr_cmd: ipr command struct
  8395. *
  8396. * This function frees all allocated resources for the
  8397. * specified adapter.
  8398. *
  8399. * Return value:
  8400. * none
  8401. **/
  8402. static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
  8403. {
  8404. struct pci_dev *pdev = ioa_cfg->pdev;
  8405. ENTER;
  8406. ipr_free_irqs(ioa_cfg);
  8407. if (ioa_cfg->reset_work_q)
  8408. destroy_workqueue(ioa_cfg->reset_work_q);
  8409. iounmap(ioa_cfg->hdw_dma_regs);
  8410. pci_release_regions(pdev);
  8411. ipr_free_mem(ioa_cfg);
  8412. scsi_host_put(ioa_cfg->host);
  8413. pci_disable_device(pdev);
  8414. LEAVE;
  8415. }
  8416. /**
  8417. * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
  8418. * @ioa_cfg: ioa config struct
  8419. *
  8420. * Return value:
  8421. * 0 on success / -ENOMEM on allocation failure
  8422. **/
  8423. static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  8424. {
  8425. struct ipr_cmnd *ipr_cmd;
  8426. struct ipr_ioarcb *ioarcb;
  8427. dma_addr_t dma_addr;
  8428. int i, entries_each_hrrq, hrrq_id = 0;
  8429. ioa_cfg->ipr_cmd_pool = dma_pool_create(IPR_NAME, &ioa_cfg->pdev->dev,
  8430. sizeof(struct ipr_cmnd), 512, 0);
  8431. if (!ioa_cfg->ipr_cmd_pool)
  8432. return -ENOMEM;
  8433. ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
  8434. ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
  8435. if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
  8436. ipr_free_cmd_blks(ioa_cfg);
  8437. return -ENOMEM;
  8438. }
  8439. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8440. if (ioa_cfg->hrrq_num > 1) {
  8441. if (i == 0) {
  8442. entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
  8443. ioa_cfg->hrrq[i].min_cmd_id = 0;
  8444. ioa_cfg->hrrq[i].max_cmd_id =
  8445. (entries_each_hrrq - 1);
  8446. } else {
  8447. entries_each_hrrq =
  8448. IPR_NUM_BASE_CMD_BLKS/
  8449. (ioa_cfg->hrrq_num - 1);
  8450. ioa_cfg->hrrq[i].min_cmd_id =
  8451. IPR_NUM_INTERNAL_CMD_BLKS +
  8452. (i - 1) * entries_each_hrrq;
  8453. ioa_cfg->hrrq[i].max_cmd_id =
  8454. (IPR_NUM_INTERNAL_CMD_BLKS +
  8455. i * entries_each_hrrq - 1);
  8456. }
  8457. } else {
  8458. entries_each_hrrq = IPR_NUM_CMD_BLKS;
  8459. ioa_cfg->hrrq[i].min_cmd_id = 0;
  8460. ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
  8461. }
  8462. ioa_cfg->hrrq[i].size = entries_each_hrrq;
  8463. }
  8464. BUG_ON(ioa_cfg->hrrq_num == 0);
  8465. i = IPR_NUM_CMD_BLKS -
  8466. ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
  8467. if (i > 0) {
  8468. ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
  8469. ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
  8470. }
  8471. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  8472. ipr_cmd = dma_pool_zalloc(ioa_cfg->ipr_cmd_pool,
  8473. GFP_KERNEL, &dma_addr);
  8474. if (!ipr_cmd) {
  8475. ipr_free_cmd_blks(ioa_cfg);
  8476. return -ENOMEM;
  8477. }
  8478. ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
  8479. ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
  8480. ioarcb = &ipr_cmd->ioarcb;
  8481. ipr_cmd->dma_addr = dma_addr;
  8482. if (ioa_cfg->sis64)
  8483. ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
  8484. else
  8485. ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
  8486. ioarcb->host_response_handle = cpu_to_be32(i << 2);
  8487. if (ioa_cfg->sis64) {
  8488. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  8489. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  8490. ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
  8491. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
  8492. } else {
  8493. ioarcb->write_ioadl_addr =
  8494. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  8495. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  8496. ioarcb->ioasa_host_pci_addr =
  8497. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
  8498. }
  8499. ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
  8500. ipr_cmd->cmd_index = i;
  8501. ipr_cmd->ioa_cfg = ioa_cfg;
  8502. ipr_cmd->sense_buffer_dma = dma_addr +
  8503. offsetof(struct ipr_cmnd, sense_buffer);
  8504. ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
  8505. ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
  8506. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  8507. if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
  8508. hrrq_id++;
  8509. }
  8510. return 0;
  8511. }
  8512. /**
  8513. * ipr_alloc_mem - Allocate memory for an adapter
  8514. * @ioa_cfg: ioa config struct
  8515. *
  8516. * Return value:
  8517. * 0 on success / non-zero for error
  8518. **/
  8519. static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
  8520. {
  8521. struct pci_dev *pdev = ioa_cfg->pdev;
  8522. int i, rc = -ENOMEM;
  8523. ENTER;
  8524. ioa_cfg->res_entries = kcalloc(ioa_cfg->max_devs_supported,
  8525. sizeof(struct ipr_resource_entry),
  8526. GFP_KERNEL);
  8527. if (!ioa_cfg->res_entries)
  8528. goto out;
  8529. for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
  8530. list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
  8531. ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
  8532. }
  8533. ioa_cfg->vpd_cbs = dma_alloc_coherent(&pdev->dev,
  8534. sizeof(struct ipr_misc_cbs),
  8535. &ioa_cfg->vpd_cbs_dma,
  8536. GFP_KERNEL);
  8537. if (!ioa_cfg->vpd_cbs)
  8538. goto out_free_res_entries;
  8539. if (ipr_alloc_cmd_blks(ioa_cfg))
  8540. goto out_free_vpd_cbs;
  8541. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8542. ioa_cfg->hrrq[i].host_rrq = dma_alloc_coherent(&pdev->dev,
  8543. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8544. &ioa_cfg->hrrq[i].host_rrq_dma,
  8545. GFP_KERNEL);
  8546. if (!ioa_cfg->hrrq[i].host_rrq) {
  8547. while (--i > 0)
  8548. dma_free_coherent(&pdev->dev,
  8549. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8550. ioa_cfg->hrrq[i].host_rrq,
  8551. ioa_cfg->hrrq[i].host_rrq_dma);
  8552. goto out_ipr_free_cmd_blocks;
  8553. }
  8554. ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
  8555. }
  8556. ioa_cfg->u.cfg_table = dma_alloc_coherent(&pdev->dev,
  8557. ioa_cfg->cfg_table_size,
  8558. &ioa_cfg->cfg_table_dma,
  8559. GFP_KERNEL);
  8560. if (!ioa_cfg->u.cfg_table)
  8561. goto out_free_host_rrq;
  8562. for (i = 0; i < IPR_MAX_HCAMS; i++) {
  8563. ioa_cfg->hostrcb[i] = dma_alloc_coherent(&pdev->dev,
  8564. sizeof(struct ipr_hostrcb),
  8565. &ioa_cfg->hostrcb_dma[i],
  8566. GFP_KERNEL);
  8567. if (!ioa_cfg->hostrcb[i])
  8568. goto out_free_hostrcb_dma;
  8569. ioa_cfg->hostrcb[i]->hostrcb_dma =
  8570. ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
  8571. ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
  8572. list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
  8573. }
  8574. ioa_cfg->trace = kcalloc(IPR_NUM_TRACE_ENTRIES,
  8575. sizeof(struct ipr_trace_entry),
  8576. GFP_KERNEL);
  8577. if (!ioa_cfg->trace)
  8578. goto out_free_hostrcb_dma;
  8579. rc = 0;
  8580. out:
  8581. LEAVE;
  8582. return rc;
  8583. out_free_hostrcb_dma:
  8584. while (i-- > 0) {
  8585. dma_free_coherent(&pdev->dev, sizeof(struct ipr_hostrcb),
  8586. ioa_cfg->hostrcb[i],
  8587. ioa_cfg->hostrcb_dma[i]);
  8588. }
  8589. dma_free_coherent(&pdev->dev, ioa_cfg->cfg_table_size,
  8590. ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
  8591. out_free_host_rrq:
  8592. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  8593. dma_free_coherent(&pdev->dev,
  8594. sizeof(u32) * ioa_cfg->hrrq[i].size,
  8595. ioa_cfg->hrrq[i].host_rrq,
  8596. ioa_cfg->hrrq[i].host_rrq_dma);
  8597. }
  8598. out_ipr_free_cmd_blocks:
  8599. ipr_free_cmd_blks(ioa_cfg);
  8600. out_free_vpd_cbs:
  8601. dma_free_coherent(&pdev->dev, sizeof(struct ipr_misc_cbs),
  8602. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  8603. out_free_res_entries:
  8604. kfree(ioa_cfg->res_entries);
  8605. goto out;
  8606. }
  8607. /**
  8608. * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
  8609. * @ioa_cfg: ioa config struct
  8610. *
  8611. * Return value:
  8612. * none
  8613. **/
  8614. static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
  8615. {
  8616. int i;
  8617. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  8618. ioa_cfg->bus_attr[i].bus = i;
  8619. ioa_cfg->bus_attr[i].qas_enabled = 0;
  8620. ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
  8621. if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
  8622. ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
  8623. else
  8624. ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
  8625. }
  8626. }
  8627. /**
  8628. * ipr_init_regs - Initialize IOA registers
  8629. * @ioa_cfg: ioa config struct
  8630. *
  8631. * Return value:
  8632. * none
  8633. **/
  8634. static void ipr_init_regs(struct ipr_ioa_cfg *ioa_cfg)
  8635. {
  8636. const struct ipr_interrupt_offsets *p;
  8637. struct ipr_interrupts *t;
  8638. void __iomem *base;
  8639. p = &ioa_cfg->chip_cfg->regs;
  8640. t = &ioa_cfg->regs;
  8641. base = ioa_cfg->hdw_dma_regs;
  8642. t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
  8643. t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
  8644. t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
  8645. t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
  8646. t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
  8647. t->clr_interrupt_reg = base + p->clr_interrupt_reg;
  8648. t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
  8649. t->sense_interrupt_reg = base + p->sense_interrupt_reg;
  8650. t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
  8651. t->ioarrin_reg = base + p->ioarrin_reg;
  8652. t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
  8653. t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
  8654. t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
  8655. t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
  8656. t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
  8657. t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
  8658. if (ioa_cfg->sis64) {
  8659. t->init_feedback_reg = base + p->init_feedback_reg;
  8660. t->dump_addr_reg = base + p->dump_addr_reg;
  8661. t->dump_data_reg = base + p->dump_data_reg;
  8662. t->endian_swap_reg = base + p->endian_swap_reg;
  8663. }
  8664. }
  8665. /**
  8666. * ipr_init_ioa_cfg - Initialize IOA config struct
  8667. * @ioa_cfg: ioa config struct
  8668. * @host: scsi host struct
  8669. * @pdev: PCI dev struct
  8670. *
  8671. * Return value:
  8672. * none
  8673. **/
  8674. static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
  8675. struct Scsi_Host *host, struct pci_dev *pdev)
  8676. {
  8677. int i;
  8678. ioa_cfg->host = host;
  8679. ioa_cfg->pdev = pdev;
  8680. ioa_cfg->log_level = ipr_log_level;
  8681. ioa_cfg->doorbell = IPR_DOORBELL;
  8682. sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
  8683. sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
  8684. sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
  8685. sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
  8686. sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
  8687. sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
  8688. INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
  8689. INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
  8690. INIT_LIST_HEAD(&ioa_cfg->hostrcb_report_q);
  8691. INIT_LIST_HEAD(&ioa_cfg->free_res_q);
  8692. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  8693. INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
  8694. INIT_WORK(&ioa_cfg->scsi_add_work_q, ipr_add_remove_thread);
  8695. init_waitqueue_head(&ioa_cfg->reset_wait_q);
  8696. init_waitqueue_head(&ioa_cfg->msi_wait_q);
  8697. init_waitqueue_head(&ioa_cfg->eeh_wait_q);
  8698. ioa_cfg->sdt_state = INACTIVE;
  8699. ipr_initialize_bus_attr(ioa_cfg);
  8700. ioa_cfg->max_devs_supported = ipr_max_devs;
  8701. if (ioa_cfg->sis64) {
  8702. host->max_channel = IPR_MAX_SIS64_BUSES;
  8703. host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
  8704. host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
  8705. if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
  8706. ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
  8707. ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
  8708. + ((sizeof(struct ipr_config_table_entry64)
  8709. * ioa_cfg->max_devs_supported)));
  8710. } else {
  8711. host->max_channel = IPR_VSET_BUS;
  8712. host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
  8713. host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
  8714. if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
  8715. ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
  8716. ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
  8717. + ((sizeof(struct ipr_config_table_entry)
  8718. * ioa_cfg->max_devs_supported)));
  8719. }
  8720. host->unique_id = host->host_no;
  8721. host->max_cmd_len = IPR_MAX_CDB_LEN;
  8722. host->can_queue = ioa_cfg->max_cmds;
  8723. pci_set_drvdata(pdev, ioa_cfg);
  8724. for (i = 0; i < ARRAY_SIZE(ioa_cfg->hrrq); i++) {
  8725. INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
  8726. INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
  8727. spin_lock_init(&ioa_cfg->hrrq[i]._lock);
  8728. if (i == 0)
  8729. ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
  8730. else
  8731. ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
  8732. }
  8733. }
  8734. /**
  8735. * ipr_get_chip_info - Find adapter chip information
  8736. * @dev_id: PCI device id struct
  8737. *
  8738. * Return value:
  8739. * ptr to chip information on success / NULL on failure
  8740. **/
  8741. static const struct ipr_chip_t *
  8742. ipr_get_chip_info(const struct pci_device_id *dev_id)
  8743. {
  8744. int i;
  8745. for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
  8746. if (ipr_chip[i].vendor == dev_id->vendor &&
  8747. ipr_chip[i].device == dev_id->device)
  8748. return &ipr_chip[i];
  8749. return NULL;
  8750. }
  8751. /**
  8752. * ipr_wait_for_pci_err_recovery - Wait for any PCI error recovery to complete
  8753. * during probe time
  8754. * @ioa_cfg: ioa config struct
  8755. *
  8756. * Return value:
  8757. * None
  8758. **/
  8759. static void ipr_wait_for_pci_err_recovery(struct ipr_ioa_cfg *ioa_cfg)
  8760. {
  8761. struct pci_dev *pdev = ioa_cfg->pdev;
  8762. if (pci_channel_offline(pdev)) {
  8763. wait_event_timeout(ioa_cfg->eeh_wait_q,
  8764. !pci_channel_offline(pdev),
  8765. IPR_PCI_ERROR_RECOVERY_TIMEOUT);
  8766. pci_restore_state(pdev);
  8767. }
  8768. }
  8769. static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
  8770. {
  8771. int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
  8772. for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
  8773. snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
  8774. "host%d-%d", ioa_cfg->host->host_no, vec_idx);
  8775. ioa_cfg->vectors_info[vec_idx].
  8776. desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
  8777. }
  8778. }
  8779. static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg,
  8780. struct pci_dev *pdev)
  8781. {
  8782. int i, rc;
  8783. for (i = 1; i < ioa_cfg->nvectors; i++) {
  8784. rc = request_irq(pci_irq_vector(pdev, i),
  8785. ipr_isr_mhrrq,
  8786. 0,
  8787. ioa_cfg->vectors_info[i].desc,
  8788. &ioa_cfg->hrrq[i]);
  8789. if (rc) {
  8790. while (--i >= 0)
  8791. free_irq(pci_irq_vector(pdev, i),
  8792. &ioa_cfg->hrrq[i]);
  8793. return rc;
  8794. }
  8795. }
  8796. return 0;
  8797. }
  8798. /**
  8799. * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
  8800. * @pdev: PCI device struct
  8801. *
  8802. * Description: Simply set the msi_received flag to 1 indicating that
  8803. * Message Signaled Interrupts are supported.
  8804. *
  8805. * Return value:
  8806. * 0 on success / non-zero on failure
  8807. **/
  8808. static irqreturn_t ipr_test_intr(int irq, void *devp)
  8809. {
  8810. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  8811. unsigned long lock_flags = 0;
  8812. irqreturn_t rc = IRQ_HANDLED;
  8813. dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
  8814. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8815. ioa_cfg->msi_received = 1;
  8816. wake_up(&ioa_cfg->msi_wait_q);
  8817. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8818. return rc;
  8819. }
  8820. /**
  8821. * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
  8822. * @pdev: PCI device struct
  8823. *
  8824. * Description: This routine sets up and initiates a test interrupt to determine
  8825. * if the interrupt is received via the ipr_test_intr() service routine.
  8826. * If the tests fails, the driver will fall back to LSI.
  8827. *
  8828. * Return value:
  8829. * 0 on success / non-zero on failure
  8830. **/
  8831. static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
  8832. {
  8833. int rc;
  8834. volatile u32 int_reg;
  8835. unsigned long lock_flags = 0;
  8836. int irq = pci_irq_vector(pdev, 0);
  8837. ENTER;
  8838. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8839. init_waitqueue_head(&ioa_cfg->msi_wait_q);
  8840. ioa_cfg->msi_received = 0;
  8841. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  8842. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
  8843. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  8844. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8845. rc = request_irq(irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
  8846. if (rc) {
  8847. dev_err(&pdev->dev, "Can not assign irq %d\n", irq);
  8848. return rc;
  8849. } else if (ipr_debug)
  8850. dev_info(&pdev->dev, "IRQ assigned: %d\n", irq);
  8851. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
  8852. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  8853. wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
  8854. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8855. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  8856. if (!ioa_cfg->msi_received) {
  8857. /* MSI test failed */
  8858. dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
  8859. rc = -EOPNOTSUPP;
  8860. } else if (ipr_debug)
  8861. dev_info(&pdev->dev, "MSI test succeeded.\n");
  8862. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8863. free_irq(irq, ioa_cfg);
  8864. LEAVE;
  8865. return rc;
  8866. }
  8867. /* ipr_probe_ioa - Allocates memory and does first stage of initialization
  8868. * @pdev: PCI device struct
  8869. * @dev_id: PCI device id struct
  8870. *
  8871. * Return value:
  8872. * 0 on success / non-zero on failure
  8873. **/
  8874. static int ipr_probe_ioa(struct pci_dev *pdev,
  8875. const struct pci_device_id *dev_id)
  8876. {
  8877. struct ipr_ioa_cfg *ioa_cfg;
  8878. struct Scsi_Host *host;
  8879. unsigned long ipr_regs_pci;
  8880. void __iomem *ipr_regs;
  8881. int rc = PCIBIOS_SUCCESSFUL;
  8882. volatile u32 mask, uproc, interrupts;
  8883. unsigned long lock_flags, driver_lock_flags;
  8884. unsigned int irq_flag;
  8885. ENTER;
  8886. dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
  8887. host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
  8888. if (!host) {
  8889. dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
  8890. rc = -ENOMEM;
  8891. goto out;
  8892. }
  8893. ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
  8894. memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
  8895. ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
  8896. ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
  8897. if (!ioa_cfg->ipr_chip) {
  8898. dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
  8899. dev_id->vendor, dev_id->device);
  8900. goto out_scsi_host_put;
  8901. }
  8902. /* set SIS 32 or SIS 64 */
  8903. ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
  8904. ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
  8905. ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
  8906. ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
  8907. if (ipr_transop_timeout)
  8908. ioa_cfg->transop_timeout = ipr_transop_timeout;
  8909. else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
  8910. ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
  8911. else
  8912. ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
  8913. ioa_cfg->revid = pdev->revision;
  8914. ipr_init_ioa_cfg(ioa_cfg, host, pdev);
  8915. ipr_regs_pci = pci_resource_start(pdev, 0);
  8916. rc = pci_request_regions(pdev, IPR_NAME);
  8917. if (rc < 0) {
  8918. dev_err(&pdev->dev,
  8919. "Couldn't register memory range of registers\n");
  8920. goto out_scsi_host_put;
  8921. }
  8922. rc = pci_enable_device(pdev);
  8923. if (rc || pci_channel_offline(pdev)) {
  8924. if (pci_channel_offline(pdev)) {
  8925. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8926. rc = pci_enable_device(pdev);
  8927. }
  8928. if (rc) {
  8929. dev_err(&pdev->dev, "Cannot enable adapter\n");
  8930. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8931. goto out_release_regions;
  8932. }
  8933. }
  8934. ipr_regs = pci_ioremap_bar(pdev, 0);
  8935. if (!ipr_regs) {
  8936. dev_err(&pdev->dev,
  8937. "Couldn't map memory range of registers\n");
  8938. rc = -ENOMEM;
  8939. goto out_disable;
  8940. }
  8941. ioa_cfg->hdw_dma_regs = ipr_regs;
  8942. ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
  8943. ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
  8944. ipr_init_regs(ioa_cfg);
  8945. if (ioa_cfg->sis64) {
  8946. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  8947. if (rc < 0) {
  8948. dev_dbg(&pdev->dev, "Failed to set 64 bit DMA mask\n");
  8949. rc = dma_set_mask_and_coherent(&pdev->dev,
  8950. DMA_BIT_MASK(32));
  8951. }
  8952. } else
  8953. rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  8954. if (rc < 0) {
  8955. dev_err(&pdev->dev, "Failed to set DMA mask\n");
  8956. goto cleanup_nomem;
  8957. }
  8958. rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  8959. ioa_cfg->chip_cfg->cache_line_size);
  8960. if (rc != PCIBIOS_SUCCESSFUL) {
  8961. dev_err(&pdev->dev, "Write of cache line size failed\n");
  8962. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8963. rc = -EIO;
  8964. goto cleanup_nomem;
  8965. }
  8966. /* Issue MMIO read to ensure card is not in EEH */
  8967. interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
  8968. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8969. if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
  8970. dev_err(&pdev->dev, "The max number of MSIX is %d\n",
  8971. IPR_MAX_MSIX_VECTORS);
  8972. ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
  8973. }
  8974. irq_flag = PCI_IRQ_LEGACY;
  8975. if (ioa_cfg->ipr_chip->has_msi)
  8976. irq_flag |= PCI_IRQ_MSI | PCI_IRQ_MSIX;
  8977. rc = pci_alloc_irq_vectors(pdev, 1, ipr_number_of_msix, irq_flag);
  8978. if (rc < 0) {
  8979. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8980. goto cleanup_nomem;
  8981. }
  8982. ioa_cfg->nvectors = rc;
  8983. if (!pdev->msi_enabled && !pdev->msix_enabled)
  8984. ioa_cfg->clear_isr = 1;
  8985. pci_set_master(pdev);
  8986. if (pci_channel_offline(pdev)) {
  8987. ipr_wait_for_pci_err_recovery(ioa_cfg);
  8988. pci_set_master(pdev);
  8989. if (pci_channel_offline(pdev)) {
  8990. rc = -EIO;
  8991. goto out_msi_disable;
  8992. }
  8993. }
  8994. if (pdev->msi_enabled || pdev->msix_enabled) {
  8995. rc = ipr_test_msi(ioa_cfg, pdev);
  8996. switch (rc) {
  8997. case 0:
  8998. dev_info(&pdev->dev,
  8999. "Request for %d MSI%ss succeeded.", ioa_cfg->nvectors,
  9000. pdev->msix_enabled ? "-X" : "");
  9001. break;
  9002. case -EOPNOTSUPP:
  9003. ipr_wait_for_pci_err_recovery(ioa_cfg);
  9004. pci_free_irq_vectors(pdev);
  9005. ioa_cfg->nvectors = 1;
  9006. ioa_cfg->clear_isr = 1;
  9007. break;
  9008. default:
  9009. goto out_msi_disable;
  9010. }
  9011. }
  9012. ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
  9013. (unsigned int)num_online_cpus(),
  9014. (unsigned int)IPR_MAX_HRRQ_NUM);
  9015. if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
  9016. goto out_msi_disable;
  9017. if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
  9018. goto out_msi_disable;
  9019. rc = ipr_alloc_mem(ioa_cfg);
  9020. if (rc < 0) {
  9021. dev_err(&pdev->dev,
  9022. "Couldn't allocate enough memory for device driver!\n");
  9023. goto out_msi_disable;
  9024. }
  9025. /* Save away PCI config space for use following IOA reset */
  9026. rc = pci_save_state(pdev);
  9027. if (rc != PCIBIOS_SUCCESSFUL) {
  9028. dev_err(&pdev->dev, "Failed to save PCI config space\n");
  9029. rc = -EIO;
  9030. goto cleanup_nolog;
  9031. }
  9032. /*
  9033. * If HRRQ updated interrupt is not masked, or reset alert is set,
  9034. * the card is in an unknown state and needs a hard reset
  9035. */
  9036. mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
  9037. interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
  9038. uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
  9039. if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
  9040. ioa_cfg->needs_hard_reset = 1;
  9041. if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
  9042. ioa_cfg->needs_hard_reset = 1;
  9043. if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
  9044. ioa_cfg->ioa_unit_checked = 1;
  9045. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  9046. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  9047. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  9048. if (pdev->msi_enabled || pdev->msix_enabled) {
  9049. name_msi_vectors(ioa_cfg);
  9050. rc = request_irq(pci_irq_vector(pdev, 0), ipr_isr, 0,
  9051. ioa_cfg->vectors_info[0].desc,
  9052. &ioa_cfg->hrrq[0]);
  9053. if (!rc)
  9054. rc = ipr_request_other_msi_irqs(ioa_cfg, pdev);
  9055. } else {
  9056. rc = request_irq(pdev->irq, ipr_isr,
  9057. IRQF_SHARED,
  9058. IPR_NAME, &ioa_cfg->hrrq[0]);
  9059. }
  9060. if (rc) {
  9061. dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
  9062. pdev->irq, rc);
  9063. goto cleanup_nolog;
  9064. }
  9065. if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
  9066. (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
  9067. ioa_cfg->needs_warm_reset = 1;
  9068. ioa_cfg->reset = ipr_reset_slot_reset;
  9069. ioa_cfg->reset_work_q = alloc_ordered_workqueue("ipr_reset_%d",
  9070. WQ_MEM_RECLAIM, host->host_no);
  9071. if (!ioa_cfg->reset_work_q) {
  9072. dev_err(&pdev->dev, "Couldn't register reset workqueue\n");
  9073. rc = -ENOMEM;
  9074. goto out_free_irq;
  9075. }
  9076. } else
  9077. ioa_cfg->reset = ipr_reset_start_bist;
  9078. spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
  9079. list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
  9080. spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
  9081. LEAVE;
  9082. out:
  9083. return rc;
  9084. out_free_irq:
  9085. ipr_free_irqs(ioa_cfg);
  9086. cleanup_nolog:
  9087. ipr_free_mem(ioa_cfg);
  9088. out_msi_disable:
  9089. ipr_wait_for_pci_err_recovery(ioa_cfg);
  9090. pci_free_irq_vectors(pdev);
  9091. cleanup_nomem:
  9092. iounmap(ipr_regs);
  9093. out_disable:
  9094. pci_disable_device(pdev);
  9095. out_release_regions:
  9096. pci_release_regions(pdev);
  9097. out_scsi_host_put:
  9098. scsi_host_put(host);
  9099. goto out;
  9100. }
  9101. /**
  9102. * ipr_initiate_ioa_bringdown - Bring down an adapter
  9103. * @ioa_cfg: ioa config struct
  9104. * @shutdown_type: shutdown type
  9105. *
  9106. * Description: This function will initiate bringing down the adapter.
  9107. * This consists of issuing an IOA shutdown to the adapter
  9108. * to flush the cache, and running BIST.
  9109. * If the caller needs to wait on the completion of the reset,
  9110. * the caller must sleep on the reset_wait_q.
  9111. *
  9112. * Return value:
  9113. * none
  9114. **/
  9115. static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
  9116. enum ipr_shutdown_type shutdown_type)
  9117. {
  9118. ENTER;
  9119. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  9120. ioa_cfg->sdt_state = ABORT_DUMP;
  9121. ioa_cfg->reset_retries = 0;
  9122. ioa_cfg->in_ioa_bringdown = 1;
  9123. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  9124. LEAVE;
  9125. }
  9126. /**
  9127. * __ipr_remove - Remove a single adapter
  9128. * @pdev: pci device struct
  9129. *
  9130. * Adapter hot plug remove entry point.
  9131. *
  9132. * Return value:
  9133. * none
  9134. **/
  9135. static void __ipr_remove(struct pci_dev *pdev)
  9136. {
  9137. unsigned long host_lock_flags = 0;
  9138. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  9139. int i;
  9140. unsigned long driver_lock_flags;
  9141. ENTER;
  9142. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  9143. while (ioa_cfg->in_reset_reload) {
  9144. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  9145. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9146. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  9147. }
  9148. for (i = 0; i < ioa_cfg->hrrq_num; i++) {
  9149. spin_lock(&ioa_cfg->hrrq[i]._lock);
  9150. ioa_cfg->hrrq[i].removing_ioa = 1;
  9151. spin_unlock(&ioa_cfg->hrrq[i]._lock);
  9152. }
  9153. wmb();
  9154. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  9155. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  9156. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9157. flush_work(&ioa_cfg->work_q);
  9158. if (ioa_cfg->reset_work_q)
  9159. flush_workqueue(ioa_cfg->reset_work_q);
  9160. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  9161. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  9162. spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
  9163. list_del(&ioa_cfg->queue);
  9164. spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
  9165. if (ioa_cfg->sdt_state == ABORT_DUMP)
  9166. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  9167. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  9168. ipr_free_all_resources(ioa_cfg);
  9169. LEAVE;
  9170. }
  9171. /**
  9172. * ipr_remove - IOA hot plug remove entry point
  9173. * @pdev: pci device struct
  9174. *
  9175. * Adapter hot plug remove entry point.
  9176. *
  9177. * Return value:
  9178. * none
  9179. **/
  9180. static void ipr_remove(struct pci_dev *pdev)
  9181. {
  9182. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  9183. ENTER;
  9184. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9185. &ipr_trace_attr);
  9186. ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
  9187. &ipr_dump_attr);
  9188. sysfs_remove_bin_file(&ioa_cfg->host->shost_dev.kobj,
  9189. &ipr_ioa_async_err_log);
  9190. scsi_remove_host(ioa_cfg->host);
  9191. __ipr_remove(pdev);
  9192. LEAVE;
  9193. }
  9194. /**
  9195. * ipr_probe - Adapter hot plug add entry point
  9196. *
  9197. * Return value:
  9198. * 0 on success / non-zero on failure
  9199. **/
  9200. static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
  9201. {
  9202. struct ipr_ioa_cfg *ioa_cfg;
  9203. unsigned long flags;
  9204. int rc, i;
  9205. rc = ipr_probe_ioa(pdev, dev_id);
  9206. if (rc)
  9207. return rc;
  9208. ioa_cfg = pci_get_drvdata(pdev);
  9209. rc = ipr_probe_ioa_part2(ioa_cfg);
  9210. if (rc) {
  9211. __ipr_remove(pdev);
  9212. return rc;
  9213. }
  9214. rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
  9215. if (rc) {
  9216. __ipr_remove(pdev);
  9217. return rc;
  9218. }
  9219. rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9220. &ipr_trace_attr);
  9221. if (rc) {
  9222. scsi_remove_host(ioa_cfg->host);
  9223. __ipr_remove(pdev);
  9224. return rc;
  9225. }
  9226. rc = sysfs_create_bin_file(&ioa_cfg->host->shost_dev.kobj,
  9227. &ipr_ioa_async_err_log);
  9228. if (rc) {
  9229. ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
  9230. &ipr_dump_attr);
  9231. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9232. &ipr_trace_attr);
  9233. scsi_remove_host(ioa_cfg->host);
  9234. __ipr_remove(pdev);
  9235. return rc;
  9236. }
  9237. rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
  9238. &ipr_dump_attr);
  9239. if (rc) {
  9240. sysfs_remove_bin_file(&ioa_cfg->host->shost_dev.kobj,
  9241. &ipr_ioa_async_err_log);
  9242. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  9243. &ipr_trace_attr);
  9244. scsi_remove_host(ioa_cfg->host);
  9245. __ipr_remove(pdev);
  9246. return rc;
  9247. }
  9248. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  9249. ioa_cfg->scan_enabled = 1;
  9250. schedule_work(&ioa_cfg->work_q);
  9251. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  9252. ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
  9253. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  9254. for (i = 1; i < ioa_cfg->hrrq_num; i++) {
  9255. irq_poll_init(&ioa_cfg->hrrq[i].iopoll,
  9256. ioa_cfg->iopoll_weight, ipr_iopoll);
  9257. }
  9258. }
  9259. scsi_scan_host(ioa_cfg->host);
  9260. return 0;
  9261. }
  9262. /**
  9263. * ipr_shutdown - Shutdown handler.
  9264. * @pdev: pci device struct
  9265. *
  9266. * This function is invoked upon system shutdown/reboot. It will issue
  9267. * an adapter shutdown to the adapter to flush the write cache.
  9268. *
  9269. * Return value:
  9270. * none
  9271. **/
  9272. static void ipr_shutdown(struct pci_dev *pdev)
  9273. {
  9274. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  9275. unsigned long lock_flags = 0;
  9276. enum ipr_shutdown_type shutdown_type = IPR_SHUTDOWN_NORMAL;
  9277. int i;
  9278. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  9279. if (ioa_cfg->iopoll_weight && ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
  9280. ioa_cfg->iopoll_weight = 0;
  9281. for (i = 1; i < ioa_cfg->hrrq_num; i++)
  9282. irq_poll_disable(&ioa_cfg->hrrq[i].iopoll);
  9283. }
  9284. while (ioa_cfg->in_reset_reload) {
  9285. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  9286. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9287. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  9288. }
  9289. if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64)
  9290. shutdown_type = IPR_SHUTDOWN_QUIESCE;
  9291. ipr_initiate_ioa_bringdown(ioa_cfg, shutdown_type);
  9292. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  9293. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  9294. if (ipr_fast_reboot && system_state == SYSTEM_RESTART && ioa_cfg->sis64) {
  9295. ipr_free_irqs(ioa_cfg);
  9296. pci_disable_device(ioa_cfg->pdev);
  9297. }
  9298. }
  9299. static struct pci_device_id ipr_pci_table[] = {
  9300. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9301. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
  9302. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9303. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
  9304. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9305. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
  9306. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  9307. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
  9308. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9309. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
  9310. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9311. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
  9312. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9313. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
  9314. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  9315. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
  9316. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9317. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  9318. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  9319. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  9320. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  9321. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9322. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  9323. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  9324. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9325. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  9326. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  9327. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  9328. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  9329. IPR_USE_LONG_TRANSOP_TIMEOUT},
  9330. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  9331. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  9332. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9333. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9334. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
  9335. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9336. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9337. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
  9338. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9339. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
  9340. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  9341. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
  9342. IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
  9343. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
  9344. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
  9345. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  9346. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
  9347. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  9348. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
  9349. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9350. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  9351. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
  9352. IPR_USE_LONG_TRANSOP_TIMEOUT },
  9353. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9354. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
  9355. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9356. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
  9357. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9358. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
  9359. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9360. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
  9361. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9362. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
  9363. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  9364. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
  9365. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9366. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
  9367. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9368. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
  9369. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9370. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
  9371. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9372. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
  9373. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9374. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
  9375. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9376. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
  9377. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9378. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
  9379. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9380. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
  9381. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9382. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
  9383. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9384. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
  9385. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9386. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57DA, 0, 0, 0 },
  9387. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9388. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
  9389. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9390. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
  9391. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9392. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
  9393. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9394. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
  9395. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9396. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
  9397. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9398. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
  9399. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9400. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCA, 0, 0, 0 },
  9401. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9402. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CD2, 0, 0, 0 },
  9403. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  9404. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2CCD, 0, 0, 0 },
  9405. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE,
  9406. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_580A, 0, 0, 0 },
  9407. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_RATTLESNAKE,
  9408. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_580B, 0, 0, 0 },
  9409. { }
  9410. };
  9411. MODULE_DEVICE_TABLE(pci, ipr_pci_table);
  9412. static const struct pci_error_handlers ipr_err_handler = {
  9413. .error_detected = ipr_pci_error_detected,
  9414. .mmio_enabled = ipr_pci_mmio_enabled,
  9415. .slot_reset = ipr_pci_slot_reset,
  9416. };
  9417. static struct pci_driver ipr_driver = {
  9418. .name = IPR_NAME,
  9419. .id_table = ipr_pci_table,
  9420. .probe = ipr_probe,
  9421. .remove = ipr_remove,
  9422. .shutdown = ipr_shutdown,
  9423. .err_handler = &ipr_err_handler,
  9424. };
  9425. /**
  9426. * ipr_halt_done - Shutdown prepare completion
  9427. *
  9428. * Return value:
  9429. * none
  9430. **/
  9431. static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
  9432. {
  9433. list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
  9434. }
  9435. /**
  9436. * ipr_halt - Issue shutdown prepare to all adapters
  9437. *
  9438. * Return value:
  9439. * NOTIFY_OK on success / NOTIFY_DONE on failure
  9440. **/
  9441. static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
  9442. {
  9443. struct ipr_cmnd *ipr_cmd;
  9444. struct ipr_ioa_cfg *ioa_cfg;
  9445. unsigned long flags = 0, driver_lock_flags;
  9446. if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
  9447. return NOTIFY_DONE;
  9448. spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
  9449. list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
  9450. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  9451. if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds ||
  9452. (ipr_fast_reboot && event == SYS_RESTART && ioa_cfg->sis64)) {
  9453. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  9454. continue;
  9455. }
  9456. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  9457. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  9458. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  9459. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  9460. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
  9461. ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  9462. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  9463. }
  9464. spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
  9465. return NOTIFY_OK;
  9466. }
  9467. static struct notifier_block ipr_notifier = {
  9468. ipr_halt, NULL, 0
  9469. };
  9470. /**
  9471. * ipr_init - Module entry point
  9472. *
  9473. * Return value:
  9474. * 0 on success / negative value on failure
  9475. **/
  9476. static int __init ipr_init(void)
  9477. {
  9478. ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
  9479. IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
  9480. register_reboot_notifier(&ipr_notifier);
  9481. return pci_register_driver(&ipr_driver);
  9482. }
  9483. /**
  9484. * ipr_exit - Module unload
  9485. *
  9486. * Module unload entry point.
  9487. *
  9488. * Return value:
  9489. * none
  9490. **/
  9491. static void __exit ipr_exit(void)
  9492. {
  9493. unregister_reboot_notifier(&ipr_notifier);
  9494. pci_unregister_driver(&ipr_driver);
  9495. }
  9496. module_init(ipr_init);
  9497. module_exit(ipr_exit);