PageRenderTime 109ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 2ms

/drivers/scsi/ipr.c

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