PageRenderTime 425ms CodeModel.GetById 52ms RepoModel.GetById 0ms app.codeStats 2ms

/drivers/scsi/ipr.c

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