2 * ipr.c -- driver for IBM Power Linux RAID adapters
4 * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
6 * Copyright (C) 2003, 2004 IBM Corporation
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.
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.
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
27 * This driver is used to control the following SCSI adapters:
29 * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
31 * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
32 * PCI-X Dual Channel Ultra 320 SCSI Adapter
33 * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
34 * Embedded SCSI adapter on p615 and p655 systems
36 * Supported Hardware Features:
37 * - Ultra 320 SCSI controller
38 * - PCI-X host interface
39 * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
40 * - Non-Volatile Write Cache
41 * - Supports attachment of non-RAID disks, tape, and optical devices
42 * - RAID Levels 0, 5, 10
44 * - Background Parity Checking
45 * - Background Data Scrubbing
46 * - Ability to increase the capacity of an existing RAID 5 disk array
50 * - Tagged command queuing
51 * - Adapter microcode download
53 * - SCSI device hot plug
58 #include <linux/init.h>
59 #include <linux/types.h>
60 #include <linux/errno.h>
61 #include <linux/kernel.h>
62 #include <linux/ioport.h>
63 #include <linux/delay.h>
64 #include <linux/pci.h>
65 #include <linux/wait.h>
66 #include <linux/spinlock.h>
67 #include <linux/sched.h>
68 #include <linux/interrupt.h>
69 #include <linux/blkdev.h>
70 #include <linux/firmware.h>
71 #include <linux/module.h>
72 #include <linux/moduleparam.h>
73 #include <linux/libata.h>
74 #include <linux/hdreg.h>
75 #include <linux/reboot.h>
76 #include <linux/stringify.h>
79 #include <asm/processor.h>
80 #include <scsi/scsi.h>
81 #include <scsi/scsi_host.h>
82 #include <scsi/scsi_tcq.h>
83 #include <scsi/scsi_eh.h>
84 #include <scsi/scsi_cmnd.h>
90 static LIST_HEAD(ipr_ioa_head);
91 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
92 static unsigned int ipr_max_speed = 1;
93 static int ipr_testmode = 0;
94 static unsigned int ipr_fastfail = 0;
95 static unsigned int ipr_transop_timeout = 0;
96 static unsigned int ipr_debug = 0;
97 static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
98 static unsigned int ipr_dual_ioa_raid = 1;
99 static DEFINE_SPINLOCK(ipr_driver_lock);
101 /* This table describes the differences between DMA controller chips */
102 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
103 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
105 .cache_line_size = 0x20,
107 .set_interrupt_mask_reg = 0x0022C,
108 .clr_interrupt_mask_reg = 0x00230,
109 .clr_interrupt_mask_reg32 = 0x00230,
110 .sense_interrupt_mask_reg = 0x0022C,
111 .sense_interrupt_mask_reg32 = 0x0022C,
112 .clr_interrupt_reg = 0x00228,
113 .clr_interrupt_reg32 = 0x00228,
114 .sense_interrupt_reg = 0x00224,
115 .sense_interrupt_reg32 = 0x00224,
116 .ioarrin_reg = 0x00404,
117 .sense_uproc_interrupt_reg = 0x00214,
118 .sense_uproc_interrupt_reg32 = 0x00214,
119 .set_uproc_interrupt_reg = 0x00214,
120 .set_uproc_interrupt_reg32 = 0x00214,
121 .clr_uproc_interrupt_reg = 0x00218,
122 .clr_uproc_interrupt_reg32 = 0x00218
125 { /* Snipe and Scamp */
127 .cache_line_size = 0x20,
129 .set_interrupt_mask_reg = 0x00288,
130 .clr_interrupt_mask_reg = 0x0028C,
131 .clr_interrupt_mask_reg32 = 0x0028C,
132 .sense_interrupt_mask_reg = 0x00288,
133 .sense_interrupt_mask_reg32 = 0x00288,
134 .clr_interrupt_reg = 0x00284,
135 .clr_interrupt_reg32 = 0x00284,
136 .sense_interrupt_reg = 0x00280,
137 .sense_interrupt_reg32 = 0x00280,
138 .ioarrin_reg = 0x00504,
139 .sense_uproc_interrupt_reg = 0x00290,
140 .sense_uproc_interrupt_reg32 = 0x00290,
141 .set_uproc_interrupt_reg = 0x00290,
142 .set_uproc_interrupt_reg32 = 0x00290,
143 .clr_uproc_interrupt_reg = 0x00294,
144 .clr_uproc_interrupt_reg32 = 0x00294
149 .cache_line_size = 0x20,
151 .set_interrupt_mask_reg = 0x00010,
152 .clr_interrupt_mask_reg = 0x00018,
153 .clr_interrupt_mask_reg32 = 0x0001C,
154 .sense_interrupt_mask_reg = 0x00010,
155 .sense_interrupt_mask_reg32 = 0x00014,
156 .clr_interrupt_reg = 0x00008,
157 .clr_interrupt_reg32 = 0x0000C,
158 .sense_interrupt_reg = 0x00000,
159 .sense_interrupt_reg32 = 0x00004,
160 .ioarrin_reg = 0x00070,
161 .sense_uproc_interrupt_reg = 0x00020,
162 .sense_uproc_interrupt_reg32 = 0x00024,
163 .set_uproc_interrupt_reg = 0x00020,
164 .set_uproc_interrupt_reg32 = 0x00024,
165 .clr_uproc_interrupt_reg = 0x00028,
166 .clr_uproc_interrupt_reg32 = 0x0002C,
167 .init_feedback_reg = 0x0005C,
168 .dump_addr_reg = 0x00064,
169 .dump_data_reg = 0x00068
174 static const struct ipr_chip_t ipr_chip[] = {
175 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, &ipr_chip_cfg[0] },
176 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, &ipr_chip_cfg[0] },
177 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, &ipr_chip_cfg[0] },
178 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, &ipr_chip_cfg[0] },
179 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, &ipr_chip_cfg[0] },
180 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, &ipr_chip_cfg[1] },
181 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, &ipr_chip_cfg[1] }
184 static int ipr_max_bus_speeds [] = {
185 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
188 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
189 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
190 module_param_named(max_speed, ipr_max_speed, uint, 0);
191 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
192 module_param_named(log_level, ipr_log_level, uint, 0);
193 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
194 module_param_named(testmode, ipr_testmode, int, 0);
195 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
196 module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
197 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
198 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
199 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
200 module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
201 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
202 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
203 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
204 module_param_named(max_devs, ipr_max_devs, int, 0);
205 MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
206 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
207 MODULE_LICENSE("GPL");
208 MODULE_VERSION(IPR_DRIVER_VERSION);
210 /* A constant array of IOASCs/URCs/Error Messages */
212 struct ipr_error_table_t ipr_error_table[] = {
213 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
214 "8155: An unknown error was received"},
216 "Soft underlength error"},
218 "Command to be cancelled not found"},
220 "Qualified success"},
221 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
222 "FFFE: Soft device bus error recovered by the IOA"},
223 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
224 "4101: Soft device bus fabric error"},
225 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
226 "FFFC: Logical block guard error recovered by the device"},
227 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
228 "FFFC: Logical block reference tag error recovered by the device"},
229 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
230 "4171: Recovered scatter list tag / sequence number error"},
231 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
232 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
233 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
234 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
235 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
236 "FFFD: Recovered logical block reference tag error detected by the IOA"},
237 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
238 "FFFD: Logical block guard error recovered by the IOA"},
239 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
240 "FFF9: Device sector reassign successful"},
241 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
242 "FFF7: Media error recovered by device rewrite procedures"},
243 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
244 "7001: IOA sector reassignment successful"},
245 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
246 "FFF9: Soft media error. Sector reassignment recommended"},
247 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
248 "FFF7: Media error recovered by IOA rewrite procedures"},
249 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
250 "FF3D: Soft PCI bus error recovered by the IOA"},
251 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
252 "FFF6: Device hardware error recovered by the IOA"},
253 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
254 "FFF6: Device hardware error recovered by the device"},
255 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
256 "FF3D: Soft IOA error recovered by the IOA"},
257 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
258 "FFFA: Undefined device response recovered by the IOA"},
259 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
260 "FFF6: Device bus error, message or command phase"},
261 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
262 "FFFE: Task Management Function failed"},
263 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
264 "FFF6: Failure prediction threshold exceeded"},
265 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
266 "8009: Impending cache battery pack failure"},
268 "34FF: Disk device format in progress"},
269 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
270 "9070: IOA requested reset"},
272 "Synchronization required"},
274 "No ready, IOA shutdown"},
276 "Not ready, IOA has been shutdown"},
277 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
278 "3020: Storage subsystem configuration error"},
280 "FFF5: Medium error, data unreadable, recommend reassign"},
282 "7000: Medium error, data unreadable, do not reassign"},
283 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
284 "FFF3: Disk media format bad"},
285 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
286 "3002: Addressed device failed to respond to selection"},
287 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
288 "3100: Device bus error"},
289 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
290 "3109: IOA timed out a device command"},
292 "3120: SCSI bus is not operational"},
293 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
294 "4100: Hard device bus fabric error"},
295 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
296 "310C: Logical block guard error detected by the device"},
297 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
298 "310C: Logical block reference tag error detected by the device"},
299 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
300 "4170: Scatter list tag / sequence number error"},
301 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
302 "8150: Logical block CRC error on IOA to Host transfer"},
303 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
304 "4170: Logical block sequence number error on IOA to Host transfer"},
305 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
306 "310D: Logical block reference tag error detected by the IOA"},
307 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
308 "310D: Logical block guard error detected by the IOA"},
309 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
310 "9000: IOA reserved area data check"},
311 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
312 "9001: IOA reserved area invalid data pattern"},
313 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
314 "9002: IOA reserved area LRC error"},
315 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
316 "Hardware Error, IOA metadata access error"},
317 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
318 "102E: Out of alternate sectors for disk storage"},
319 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
320 "FFF4: Data transfer underlength error"},
321 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
322 "FFF4: Data transfer overlength error"},
323 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
324 "3400: Logical unit failure"},
325 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
326 "FFF4: Device microcode is corrupt"},
327 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
328 "8150: PCI bus error"},
330 "Unsupported device bus message received"},
331 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
332 "FFF4: Disk device problem"},
333 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
334 "8150: Permanent IOA failure"},
335 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
336 "3010: Disk device returned wrong response to IOA"},
337 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
338 "8151: IOA microcode error"},
340 "Device bus status error"},
341 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
342 "8157: IOA error requiring IOA reset to recover"},
344 "ATA device status error"},
346 "Message reject received from the device"},
347 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
348 "8008: A permanent cache battery pack failure occurred"},
349 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
350 "9090: Disk unit has been modified after the last known status"},
351 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
352 "9081: IOA detected device error"},
353 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
354 "9082: IOA detected device error"},
355 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
356 "3110: Device bus error, message or command phase"},
357 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
358 "3110: SAS Command / Task Management Function failed"},
359 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
360 "9091: Incorrect hardware configuration change has been detected"},
361 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
362 "9073: Invalid multi-adapter configuration"},
363 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
364 "4010: Incorrect connection between cascaded expanders"},
365 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
366 "4020: Connections exceed IOA design limits"},
367 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
368 "4030: Incorrect multipath connection"},
369 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
370 "4110: Unsupported enclosure function"},
371 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
372 "FFF4: Command to logical unit failed"},
374 "Illegal request, invalid request type or request packet"},
376 "Illegal request, invalid resource handle"},
378 "Illegal request, commands not allowed to this device"},
380 "Illegal request, command not allowed to a secondary adapter"},
382 "Illegal request, command not allowed to a non-optimized resource"},
384 "Illegal request, invalid field in parameter list"},
386 "Illegal request, parameter not supported"},
388 "Illegal request, parameter value invalid"},
390 "Illegal request, command sequence error"},
392 "Illegal request, dual adapter support not enabled"},
393 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
394 "9031: Array protection temporarily suspended, protection resuming"},
395 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
396 "9040: Array protection temporarily suspended, protection resuming"},
397 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
398 "3140: Device bus not ready to ready transition"},
399 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
400 "FFFB: SCSI bus was reset"},
402 "FFFE: SCSI bus transition to single ended"},
404 "FFFE: SCSI bus transition to LVD"},
405 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
406 "FFFB: SCSI bus was reset by another initiator"},
407 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
408 "3029: A device replacement has occurred"},
409 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
410 "9051: IOA cache data exists for a missing or failed device"},
411 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
412 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
413 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
414 "9025: Disk unit is not supported at its physical location"},
415 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
416 "3020: IOA detected a SCSI bus configuration error"},
417 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
418 "3150: SCSI bus configuration error"},
419 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
420 "9074: Asymmetric advanced function disk configuration"},
421 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
422 "4040: Incomplete multipath connection between IOA and enclosure"},
423 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
424 "4041: Incomplete multipath connection between enclosure and device"},
425 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
426 "9075: Incomplete multipath connection between IOA and remote IOA"},
427 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
428 "9076: Configuration error, missing remote IOA"},
429 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
430 "4050: Enclosure does not support a required multipath function"},
431 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
432 "4070: Logically bad block written on device"},
433 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
434 "9041: Array protection temporarily suspended"},
435 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
436 "9042: Corrupt array parity detected on specified device"},
437 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
438 "9030: Array no longer protected due to missing or failed disk unit"},
439 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
440 "9071: Link operational transition"},
441 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
442 "9072: Link not operational transition"},
443 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
444 "9032: Array exposed but still protected"},
445 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
446 "70DD: Device forced failed by disrupt device command"},
447 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
448 "4061: Multipath redundancy level got better"},
449 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
450 "4060: Multipath redundancy level got worse"},
452 "Failure due to other device"},
453 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
454 "9008: IOA does not support functions expected by devices"},
455 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
456 "9010: Cache data associated with attached devices cannot be found"},
457 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
458 "9011: Cache data belongs to devices other than those attached"},
459 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
460 "9020: Array missing 2 or more devices with only 1 device present"},
461 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
462 "9021: Array missing 2 or more devices with 2 or more devices present"},
463 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
464 "9022: Exposed array is missing a required device"},
465 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
466 "9023: Array member(s) not at required physical locations"},
467 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
468 "9024: Array not functional due to present hardware configuration"},
469 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
470 "9026: Array not functional due to present hardware configuration"},
471 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
472 "9027: Array is missing a device and parity is out of sync"},
473 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
474 "9028: Maximum number of arrays already exist"},
475 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
476 "9050: Required cache data cannot be located for a disk unit"},
477 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
478 "9052: Cache data exists for a device that has been modified"},
479 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
480 "9054: IOA resources not available due to previous problems"},
481 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
482 "9092: Disk unit requires initialization before use"},
483 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
484 "9029: Incorrect hardware configuration change has been detected"},
485 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
486 "9060: One or more disk pairs are missing from an array"},
487 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
488 "9061: One or more disks are missing from an array"},
489 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
490 "9062: One or more disks are missing from an array"},
491 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
492 "9063: Maximum number of functional arrays has been exceeded"},
494 "Aborted command, invalid descriptor"},
496 "Command terminated by host"}
499 static const struct ipr_ses_table_entry ipr_ses_table[] = {
500 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
501 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
502 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
503 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
504 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
505 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
506 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
507 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
508 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
509 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
510 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
511 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
512 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
516 * Function Prototypes
518 static int ipr_reset_alert(struct ipr_cmnd *);
519 static void ipr_process_ccn(struct ipr_cmnd *);
520 static void ipr_process_error(struct ipr_cmnd *);
521 static void ipr_reset_ioa_job(struct ipr_cmnd *);
522 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
523 enum ipr_shutdown_type);
525 #ifdef CONFIG_SCSI_IPR_TRACE
527 * ipr_trc_hook - Add a trace entry to the driver trace
528 * @ipr_cmd: ipr command struct
530 * @add_data: additional data
535 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
536 u8 type, u32 add_data)
538 struct ipr_trace_entry *trace_entry;
539 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
541 trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
542 trace_entry->time = jiffies;
543 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
544 trace_entry->type = type;
545 if (ipr_cmd->ioa_cfg->sis64)
546 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
548 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
549 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
550 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
551 trace_entry->u.add_data = add_data;
554 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
558 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
559 * @ipr_cmd: ipr command struct
564 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
566 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
567 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
568 dma_addr_t dma_addr = ipr_cmd->dma_addr;
570 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
571 ioarcb->data_transfer_length = 0;
572 ioarcb->read_data_transfer_length = 0;
573 ioarcb->ioadl_len = 0;
574 ioarcb->read_ioadl_len = 0;
576 if (ipr_cmd->ioa_cfg->sis64)
577 ioarcb->u.sis64_addr_data.data_ioadl_addr =
578 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
580 ioarcb->write_ioadl_addr =
581 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
582 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
586 ioasa->residual_data_len = 0;
587 ioasa->u.gata.status = 0;
589 ipr_cmd->scsi_cmd = NULL;
591 ipr_cmd->sense_buffer[0] = 0;
592 ipr_cmd->dma_use_sg = 0;
596 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
597 * @ipr_cmd: ipr command struct
602 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
604 ipr_reinit_ipr_cmnd(ipr_cmd);
605 ipr_cmd->u.scratch = 0;
606 ipr_cmd->sibling = NULL;
607 init_timer(&ipr_cmd->timer);
611 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
612 * @ioa_cfg: ioa config struct
615 * pointer to ipr command struct
618 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
620 struct ipr_cmnd *ipr_cmd;
622 ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
623 list_del(&ipr_cmd->queue);
624 ipr_init_ipr_cmnd(ipr_cmd);
630 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
631 * @ioa_cfg: ioa config struct
632 * @clr_ints: interrupts to clear
634 * This function masks all interrupts on the adapter, then clears the
635 * interrupts specified in the mask
640 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
643 volatile u32 int_reg;
645 /* Stop new interrupts */
646 ioa_cfg->allow_interrupts = 0;
648 /* Set interrupt mask to stop all new interrupts */
650 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
652 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
654 /* Clear any pending interrupts */
656 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
657 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
658 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
662 * ipr_save_pcix_cmd_reg - Save PCI-X command register
663 * @ioa_cfg: ioa config struct
666 * 0 on success / -EIO on failure
668 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
670 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
672 if (pcix_cmd_reg == 0)
675 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
676 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
677 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
681 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
686 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
687 * @ioa_cfg: ioa config struct
690 * 0 on success / -EIO on failure
692 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
694 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
697 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
698 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
699 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
708 * ipr_sata_eh_done - done function for aborted SATA commands
709 * @ipr_cmd: ipr command struct
711 * This function is invoked for ops generated to SATA
712 * devices which are being aborted.
717 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
719 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
720 struct ata_queued_cmd *qc = ipr_cmd->qc;
721 struct ipr_sata_port *sata_port = qc->ap->private_data;
723 qc->err_mask |= AC_ERR_OTHER;
724 sata_port->ioasa.status |= ATA_BUSY;
725 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
730 * ipr_scsi_eh_done - mid-layer done function for aborted ops
731 * @ipr_cmd: ipr command struct
733 * This function is invoked by the interrupt handler for
734 * ops generated by the SCSI mid-layer which are being aborted.
739 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
741 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
742 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
744 scsi_cmd->result |= (DID_ERROR << 16);
746 scsi_dma_unmap(ipr_cmd->scsi_cmd);
747 scsi_cmd->scsi_done(scsi_cmd);
748 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
752 * ipr_fail_all_ops - Fails all outstanding ops.
753 * @ioa_cfg: ioa config struct
755 * This function fails all outstanding ops.
760 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
762 struct ipr_cmnd *ipr_cmd, *temp;
765 list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
766 list_del(&ipr_cmd->queue);
768 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
769 ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
771 if (ipr_cmd->scsi_cmd)
772 ipr_cmd->done = ipr_scsi_eh_done;
773 else if (ipr_cmd->qc)
774 ipr_cmd->done = ipr_sata_eh_done;
776 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
777 del_timer(&ipr_cmd->timer);
778 ipr_cmd->done(ipr_cmd);
785 * ipr_send_command - Send driver initiated requests.
786 * @ipr_cmd: ipr command struct
788 * This function sends a command to the adapter using the correct write call.
789 * In the case of sis64, calculate the ioarcb size required. Then or in the
795 static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
797 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
798 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
800 if (ioa_cfg->sis64) {
801 /* The default size is 256 bytes */
802 send_dma_addr |= 0x1;
804 /* If the number of ioadls * size of ioadl > 128 bytes,
805 then use a 512 byte ioarcb */
806 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
807 send_dma_addr |= 0x4;
808 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
810 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
814 * ipr_do_req - Send driver initiated requests.
815 * @ipr_cmd: ipr command struct
816 * @done: done function
817 * @timeout_func: timeout function
818 * @timeout: timeout value
820 * This function sends the specified command to the adapter with the
821 * timeout given. The done function is invoked on command completion.
826 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
827 void (*done) (struct ipr_cmnd *),
828 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
830 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
832 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
834 ipr_cmd->done = done;
836 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
837 ipr_cmd->timer.expires = jiffies + timeout;
838 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
840 add_timer(&ipr_cmd->timer);
842 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
846 ipr_send_command(ipr_cmd);
850 * ipr_internal_cmd_done - Op done function for an internally generated op.
851 * @ipr_cmd: ipr command struct
853 * This function is the op done function for an internally generated,
854 * blocking op. It simply wakes the sleeping thread.
859 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
861 if (ipr_cmd->sibling)
862 ipr_cmd->sibling = NULL;
864 complete(&ipr_cmd->completion);
868 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
869 * @ipr_cmd: ipr command struct
870 * @dma_addr: dma address
871 * @len: transfer length
872 * @flags: ioadl flag value
874 * This function initializes an ioadl in the case where there is only a single
880 static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
883 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
884 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
886 ipr_cmd->dma_use_sg = 1;
888 if (ipr_cmd->ioa_cfg->sis64) {
889 ioadl64->flags = cpu_to_be32(flags);
890 ioadl64->data_len = cpu_to_be32(len);
891 ioadl64->address = cpu_to_be64(dma_addr);
893 ipr_cmd->ioarcb.ioadl_len =
894 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
895 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
897 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
898 ioadl->address = cpu_to_be32(dma_addr);
900 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
901 ipr_cmd->ioarcb.read_ioadl_len =
902 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
903 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
905 ipr_cmd->ioarcb.ioadl_len =
906 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
907 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
913 * ipr_send_blocking_cmd - Send command and sleep on its completion.
914 * @ipr_cmd: ipr command struct
915 * @timeout_func: function to invoke if command times out
921 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
922 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
925 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
927 init_completion(&ipr_cmd->completion);
928 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
930 spin_unlock_irq(ioa_cfg->host->host_lock);
931 wait_for_completion(&ipr_cmd->completion);
932 spin_lock_irq(ioa_cfg->host->host_lock);
936 * ipr_send_hcam - Send an HCAM to the adapter.
937 * @ioa_cfg: ioa config struct
939 * @hostrcb: hostrcb struct
941 * This function will send a Host Controlled Async command to the adapter.
942 * If HCAMs are currently not allowed to be issued to the adapter, it will
943 * place the hostrcb on the free queue.
948 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
949 struct ipr_hostrcb *hostrcb)
951 struct ipr_cmnd *ipr_cmd;
952 struct ipr_ioarcb *ioarcb;
954 if (ioa_cfg->allow_cmds) {
955 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
956 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
957 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
959 ipr_cmd->u.hostrcb = hostrcb;
960 ioarcb = &ipr_cmd->ioarcb;
962 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
963 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
964 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
965 ioarcb->cmd_pkt.cdb[1] = type;
966 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
967 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
969 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
970 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
972 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
973 ipr_cmd->done = ipr_process_ccn;
975 ipr_cmd->done = ipr_process_error;
977 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
981 ipr_send_command(ipr_cmd);
983 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
988 * ipr_update_ata_class - Update the ata class in the resource entry
989 * @res: resource entry struct
990 * @proto: cfgte device bus protocol value
995 static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
999 case IPR_PROTO_SAS_STP:
1000 res->ata_class = ATA_DEV_ATA;
1002 case IPR_PROTO_SATA_ATAPI:
1003 case IPR_PROTO_SAS_STP_ATAPI:
1004 res->ata_class = ATA_DEV_ATAPI;
1007 res->ata_class = ATA_DEV_UNKNOWN;
1013 * ipr_init_res_entry - Initialize a resource entry struct.
1014 * @res: resource entry struct
1015 * @cfgtew: config table entry wrapper struct
1020 static void ipr_init_res_entry(struct ipr_resource_entry *res,
1021 struct ipr_config_table_entry_wrapper *cfgtew)
1025 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1026 struct ipr_resource_entry *gscsi_res = NULL;
1028 res->needs_sync_complete = 0;
1031 res->del_from_ml = 0;
1032 res->resetting_device = 0;
1034 res->sata_port = NULL;
1036 if (ioa_cfg->sis64) {
1037 proto = cfgtew->u.cfgte64->proto;
1038 res->res_flags = cfgtew->u.cfgte64->res_flags;
1039 res->qmodel = IPR_QUEUEING_MODEL64(res);
1040 res->type = cfgtew->u.cfgte64->res_type & 0x0f;
1042 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1043 sizeof(res->res_path));
1046 res->lun = scsilun_to_int(&res->dev_lun);
1048 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1049 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1050 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1052 res->target = gscsi_res->target;
1057 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1058 ioa_cfg->max_devs_supported);
1059 set_bit(res->target, ioa_cfg->target_ids);
1062 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1063 sizeof(res->dev_lun.scsi_lun));
1064 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1065 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1067 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1068 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1069 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1070 ioa_cfg->max_devs_supported);
1071 set_bit(res->target, ioa_cfg->array_ids);
1072 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1073 res->bus = IPR_VSET_VIRTUAL_BUS;
1074 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1075 ioa_cfg->max_devs_supported);
1076 set_bit(res->target, ioa_cfg->vset_ids);
1078 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1079 ioa_cfg->max_devs_supported);
1080 set_bit(res->target, ioa_cfg->target_ids);
1083 proto = cfgtew->u.cfgte->proto;
1084 res->qmodel = IPR_QUEUEING_MODEL(res);
1085 res->flags = cfgtew->u.cfgte->flags;
1086 if (res->flags & IPR_IS_IOA_RESOURCE)
1087 res->type = IPR_RES_TYPE_IOAFP;
1089 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1091 res->bus = cfgtew->u.cfgte->res_addr.bus;
1092 res->target = cfgtew->u.cfgte->res_addr.target;
1093 res->lun = cfgtew->u.cfgte->res_addr.lun;
1096 ipr_update_ata_class(res, proto);
1100 * ipr_is_same_device - Determine if two devices are the same.
1101 * @res: resource entry struct
1102 * @cfgtew: config table entry wrapper struct
1105 * 1 if the devices are the same / 0 otherwise
1107 static int ipr_is_same_device(struct ipr_resource_entry *res,
1108 struct ipr_config_table_entry_wrapper *cfgtew)
1110 if (res->ioa_cfg->sis64) {
1111 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1112 sizeof(cfgtew->u.cfgte64->dev_id)) &&
1113 !memcmp(&res->lun, &cfgtew->u.cfgte64->lun,
1114 sizeof(cfgtew->u.cfgte64->lun))) {
1118 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1119 res->target == cfgtew->u.cfgte->res_addr.target &&
1120 res->lun == cfgtew->u.cfgte->res_addr.lun)
1128 * ipr_format_resource_path - Format the resource path for printing.
1129 * @res_path: resource path
1135 static char *ipr_format_resource_path(u8 *res_path, char *buffer)
1139 sprintf(buffer, "%02X", res_path[0]);
1140 for (i=1; res_path[i] != 0xff; i++)
1141 sprintf(buffer, "%s-%02X", buffer, res_path[i]);
1147 * ipr_update_res_entry - Update the resource entry.
1148 * @res: resource entry struct
1149 * @cfgtew: config table entry wrapper struct
1154 static void ipr_update_res_entry(struct ipr_resource_entry *res,
1155 struct ipr_config_table_entry_wrapper *cfgtew)
1157 char buffer[IPR_MAX_RES_PATH_LENGTH];
1161 if (res->ioa_cfg->sis64) {
1162 res->flags = cfgtew->u.cfgte64->flags;
1163 res->res_flags = cfgtew->u.cfgte64->res_flags;
1164 res->type = cfgtew->u.cfgte64->res_type & 0x0f;
1166 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1167 sizeof(struct ipr_std_inq_data));
1169 res->qmodel = IPR_QUEUEING_MODEL64(res);
1170 proto = cfgtew->u.cfgte64->proto;
1171 res->res_handle = cfgtew->u.cfgte64->res_handle;
1172 res->dev_id = cfgtew->u.cfgte64->dev_id;
1174 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1175 sizeof(res->dev_lun.scsi_lun));
1177 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1178 sizeof(res->res_path))) {
1179 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1180 sizeof(res->res_path));
1184 if (res->sdev && new_path)
1185 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1186 ipr_format_resource_path(&res->res_path[0], &buffer[0]));
1188 res->flags = cfgtew->u.cfgte->flags;
1189 if (res->flags & IPR_IS_IOA_RESOURCE)
1190 res->type = IPR_RES_TYPE_IOAFP;
1192 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1194 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1195 sizeof(struct ipr_std_inq_data));
1197 res->qmodel = IPR_QUEUEING_MODEL(res);
1198 proto = cfgtew->u.cfgte->proto;
1199 res->res_handle = cfgtew->u.cfgte->res_handle;
1202 ipr_update_ata_class(res, proto);
1206 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1208 * @res: resource entry struct
1209 * @cfgtew: config table entry wrapper struct
1214 static void ipr_clear_res_target(struct ipr_resource_entry *res)
1216 struct ipr_resource_entry *gscsi_res = NULL;
1217 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1219 if (!ioa_cfg->sis64)
1222 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1223 clear_bit(res->target, ioa_cfg->array_ids);
1224 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1225 clear_bit(res->target, ioa_cfg->vset_ids);
1226 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1227 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1228 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1230 clear_bit(res->target, ioa_cfg->target_ids);
1232 } else if (res->bus == 0)
1233 clear_bit(res->target, ioa_cfg->target_ids);
1237 * ipr_handle_config_change - Handle a config change from the adapter
1238 * @ioa_cfg: ioa config struct
1244 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1245 struct ipr_hostrcb *hostrcb)
1247 struct ipr_resource_entry *res = NULL;
1248 struct ipr_config_table_entry_wrapper cfgtew;
1249 __be32 cc_res_handle;
1253 if (ioa_cfg->sis64) {
1254 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1255 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1257 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1258 cc_res_handle = cfgtew.u.cfgte->res_handle;
1261 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1262 if (res->res_handle == cc_res_handle) {
1269 if (list_empty(&ioa_cfg->free_res_q)) {
1270 ipr_send_hcam(ioa_cfg,
1271 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1276 res = list_entry(ioa_cfg->free_res_q.next,
1277 struct ipr_resource_entry, queue);
1279 list_del(&res->queue);
1280 ipr_init_res_entry(res, &cfgtew);
1281 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1284 ipr_update_res_entry(res, &cfgtew);
1286 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1288 res->del_from_ml = 1;
1289 res->res_handle = IPR_INVALID_RES_HANDLE;
1290 if (ioa_cfg->allow_ml_add_del)
1291 schedule_work(&ioa_cfg->work_q);
1293 ipr_clear_res_target(res);
1294 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1296 } else if (!res->sdev) {
1298 if (ioa_cfg->allow_ml_add_del)
1299 schedule_work(&ioa_cfg->work_q);
1302 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1306 * ipr_process_ccn - Op done function for a CCN.
1307 * @ipr_cmd: ipr command struct
1309 * This function is the op done function for a configuration
1310 * change notification host controlled async from the adapter.
1315 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1317 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1318 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1319 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1321 list_del(&hostrcb->queue);
1322 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1325 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1326 dev_err(&ioa_cfg->pdev->dev,
1327 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1329 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1331 ipr_handle_config_change(ioa_cfg, hostrcb);
1336 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1337 * @i: index into buffer
1338 * @buf: string to modify
1340 * This function will strip all trailing whitespace, pad the end
1341 * of the string with a single space, and NULL terminate the string.
1344 * new length of string
1346 static int strip_and_pad_whitespace(int i, char *buf)
1348 while (i && buf[i] == ' ')
1356 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1357 * @prefix: string to print at start of printk
1358 * @hostrcb: hostrcb pointer
1359 * @vpd: vendor/product id/sn struct
1364 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1365 struct ipr_vpd *vpd)
1367 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1370 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1371 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1373 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1374 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1376 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1377 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1379 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1383 * ipr_log_vpd - Log the passed VPD to the error log.
1384 * @vpd: vendor/product id/sn struct
1389 static void ipr_log_vpd(struct ipr_vpd *vpd)
1391 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1392 + IPR_SERIAL_NUM_LEN];
1394 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1395 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1397 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1398 ipr_err("Vendor/Product ID: %s\n", buffer);
1400 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1401 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1402 ipr_err(" Serial Number: %s\n", buffer);
1406 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1407 * @prefix: string to print at start of printk
1408 * @hostrcb: hostrcb pointer
1409 * @vpd: vendor/product id/sn/wwn struct
1414 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1415 struct ipr_ext_vpd *vpd)
1417 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1418 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1419 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1423 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1424 * @vpd: vendor/product id/sn/wwn struct
1429 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1431 ipr_log_vpd(&vpd->vpd);
1432 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1433 be32_to_cpu(vpd->wwid[1]));
1437 * ipr_log_enhanced_cache_error - Log a cache error.
1438 * @ioa_cfg: ioa config struct
1439 * @hostrcb: hostrcb struct
1444 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1445 struct ipr_hostrcb *hostrcb)
1447 struct ipr_hostrcb_type_12_error *error;
1450 error = &hostrcb->hcam.u.error64.u.type_12_error;
1452 error = &hostrcb->hcam.u.error.u.type_12_error;
1454 ipr_err("-----Current Configuration-----\n");
1455 ipr_err("Cache Directory Card Information:\n");
1456 ipr_log_ext_vpd(&error->ioa_vpd);
1457 ipr_err("Adapter Card Information:\n");
1458 ipr_log_ext_vpd(&error->cfc_vpd);
1460 ipr_err("-----Expected Configuration-----\n");
1461 ipr_err("Cache Directory Card Information:\n");
1462 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1463 ipr_err("Adapter Card Information:\n");
1464 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1466 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1467 be32_to_cpu(error->ioa_data[0]),
1468 be32_to_cpu(error->ioa_data[1]),
1469 be32_to_cpu(error->ioa_data[2]));
1473 * ipr_log_cache_error - Log a cache error.
1474 * @ioa_cfg: ioa config struct
1475 * @hostrcb: hostrcb struct
1480 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1481 struct ipr_hostrcb *hostrcb)
1483 struct ipr_hostrcb_type_02_error *error =
1484 &hostrcb->hcam.u.error.u.type_02_error;
1486 ipr_err("-----Current Configuration-----\n");
1487 ipr_err("Cache Directory Card Information:\n");
1488 ipr_log_vpd(&error->ioa_vpd);
1489 ipr_err("Adapter Card Information:\n");
1490 ipr_log_vpd(&error->cfc_vpd);
1492 ipr_err("-----Expected Configuration-----\n");
1493 ipr_err("Cache Directory Card Information:\n");
1494 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1495 ipr_err("Adapter Card Information:\n");
1496 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1498 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1499 be32_to_cpu(error->ioa_data[0]),
1500 be32_to_cpu(error->ioa_data[1]),
1501 be32_to_cpu(error->ioa_data[2]));
1505 * ipr_log_enhanced_config_error - Log a configuration error.
1506 * @ioa_cfg: ioa config struct
1507 * @hostrcb: hostrcb struct
1512 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1513 struct ipr_hostrcb *hostrcb)
1515 int errors_logged, i;
1516 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1517 struct ipr_hostrcb_type_13_error *error;
1519 error = &hostrcb->hcam.u.error.u.type_13_error;
1520 errors_logged = be32_to_cpu(error->errors_logged);
1522 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1523 be32_to_cpu(error->errors_detected), errors_logged);
1525 dev_entry = error->dev;
1527 for (i = 0; i < errors_logged; i++, dev_entry++) {
1530 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1531 ipr_log_ext_vpd(&dev_entry->vpd);
1533 ipr_err("-----New Device Information-----\n");
1534 ipr_log_ext_vpd(&dev_entry->new_vpd);
1536 ipr_err("Cache Directory Card Information:\n");
1537 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1539 ipr_err("Adapter Card Information:\n");
1540 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1545 * ipr_log_sis64_config_error - Log a device error.
1546 * @ioa_cfg: ioa config struct
1547 * @hostrcb: hostrcb struct
1552 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1553 struct ipr_hostrcb *hostrcb)
1555 int errors_logged, i;
1556 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1557 struct ipr_hostrcb_type_23_error *error;
1558 char buffer[IPR_MAX_RES_PATH_LENGTH];
1560 error = &hostrcb->hcam.u.error64.u.type_23_error;
1561 errors_logged = be32_to_cpu(error->errors_logged);
1563 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1564 be32_to_cpu(error->errors_detected), errors_logged);
1566 dev_entry = error->dev;
1568 for (i = 0; i < errors_logged; i++, dev_entry++) {
1571 ipr_err("Device %d : %s", i + 1,
1572 ipr_format_resource_path(&dev_entry->res_path[0], &buffer[0]));
1573 ipr_log_ext_vpd(&dev_entry->vpd);
1575 ipr_err("-----New Device Information-----\n");
1576 ipr_log_ext_vpd(&dev_entry->new_vpd);
1578 ipr_err("Cache Directory Card Information:\n");
1579 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1581 ipr_err("Adapter Card Information:\n");
1582 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1587 * ipr_log_config_error - Log a configuration error.
1588 * @ioa_cfg: ioa config struct
1589 * @hostrcb: hostrcb struct
1594 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1595 struct ipr_hostrcb *hostrcb)
1597 int errors_logged, i;
1598 struct ipr_hostrcb_device_data_entry *dev_entry;
1599 struct ipr_hostrcb_type_03_error *error;
1601 error = &hostrcb->hcam.u.error.u.type_03_error;
1602 errors_logged = be32_to_cpu(error->errors_logged);
1604 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1605 be32_to_cpu(error->errors_detected), errors_logged);
1607 dev_entry = error->dev;
1609 for (i = 0; i < errors_logged; i++, dev_entry++) {
1612 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1613 ipr_log_vpd(&dev_entry->vpd);
1615 ipr_err("-----New Device Information-----\n");
1616 ipr_log_vpd(&dev_entry->new_vpd);
1618 ipr_err("Cache Directory Card Information:\n");
1619 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1621 ipr_err("Adapter Card Information:\n");
1622 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1624 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1625 be32_to_cpu(dev_entry->ioa_data[0]),
1626 be32_to_cpu(dev_entry->ioa_data[1]),
1627 be32_to_cpu(dev_entry->ioa_data[2]),
1628 be32_to_cpu(dev_entry->ioa_data[3]),
1629 be32_to_cpu(dev_entry->ioa_data[4]));
1634 * ipr_log_enhanced_array_error - Log an array configuration error.
1635 * @ioa_cfg: ioa config struct
1636 * @hostrcb: hostrcb struct
1641 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1642 struct ipr_hostrcb *hostrcb)
1645 struct ipr_hostrcb_type_14_error *error;
1646 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1647 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1649 error = &hostrcb->hcam.u.error.u.type_14_error;
1653 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1654 error->protection_level,
1655 ioa_cfg->host->host_no,
1656 error->last_func_vset_res_addr.bus,
1657 error->last_func_vset_res_addr.target,
1658 error->last_func_vset_res_addr.lun);
1662 array_entry = error->array_member;
1663 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1664 sizeof(error->array_member));
1666 for (i = 0; i < num_entries; i++, array_entry++) {
1667 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1670 if (be32_to_cpu(error->exposed_mode_adn) == i)
1671 ipr_err("Exposed Array Member %d:\n", i);
1673 ipr_err("Array Member %d:\n", i);
1675 ipr_log_ext_vpd(&array_entry->vpd);
1676 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1677 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1678 "Expected Location");
1685 * ipr_log_array_error - Log an array configuration error.
1686 * @ioa_cfg: ioa config struct
1687 * @hostrcb: hostrcb struct
1692 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1693 struct ipr_hostrcb *hostrcb)
1696 struct ipr_hostrcb_type_04_error *error;
1697 struct ipr_hostrcb_array_data_entry *array_entry;
1698 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1700 error = &hostrcb->hcam.u.error.u.type_04_error;
1704 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1705 error->protection_level,
1706 ioa_cfg->host->host_no,
1707 error->last_func_vset_res_addr.bus,
1708 error->last_func_vset_res_addr.target,
1709 error->last_func_vset_res_addr.lun);
1713 array_entry = error->array_member;
1715 for (i = 0; i < 18; i++) {
1716 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1719 if (be32_to_cpu(error->exposed_mode_adn) == i)
1720 ipr_err("Exposed Array Member %d:\n", i);
1722 ipr_err("Array Member %d:\n", i);
1724 ipr_log_vpd(&array_entry->vpd);
1726 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1727 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1728 "Expected Location");
1733 array_entry = error->array_member2;
1740 * ipr_log_hex_data - Log additional hex IOA error data.
1741 * @ioa_cfg: ioa config struct
1742 * @data: IOA error data
1748 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1755 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1756 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1758 for (i = 0; i < len / 4; i += 4) {
1759 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1760 be32_to_cpu(data[i]),
1761 be32_to_cpu(data[i+1]),
1762 be32_to_cpu(data[i+2]),
1763 be32_to_cpu(data[i+3]));
1768 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1769 * @ioa_cfg: ioa config struct
1770 * @hostrcb: hostrcb struct
1775 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1776 struct ipr_hostrcb *hostrcb)
1778 struct ipr_hostrcb_type_17_error *error;
1781 error = &hostrcb->hcam.u.error64.u.type_17_error;
1783 error = &hostrcb->hcam.u.error.u.type_17_error;
1785 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1786 strim(error->failure_reason);
1788 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1789 be32_to_cpu(hostrcb->hcam.u.error.prc));
1790 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1791 ipr_log_hex_data(ioa_cfg, error->data,
1792 be32_to_cpu(hostrcb->hcam.length) -
1793 (offsetof(struct ipr_hostrcb_error, u) +
1794 offsetof(struct ipr_hostrcb_type_17_error, data)));
1798 * ipr_log_dual_ioa_error - Log a dual adapter error.
1799 * @ioa_cfg: ioa config struct
1800 * @hostrcb: hostrcb struct
1805 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1806 struct ipr_hostrcb *hostrcb)
1808 struct ipr_hostrcb_type_07_error *error;
1810 error = &hostrcb->hcam.u.error.u.type_07_error;
1811 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1812 strim(error->failure_reason);
1814 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1815 be32_to_cpu(hostrcb->hcam.u.error.prc));
1816 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1817 ipr_log_hex_data(ioa_cfg, error->data,
1818 be32_to_cpu(hostrcb->hcam.length) -
1819 (offsetof(struct ipr_hostrcb_error, u) +
1820 offsetof(struct ipr_hostrcb_type_07_error, data)));
1823 static const struct {
1826 } path_active_desc[] = {
1827 { IPR_PATH_NO_INFO, "Path" },
1828 { IPR_PATH_ACTIVE, "Active path" },
1829 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1832 static const struct {
1835 } path_state_desc[] = {
1836 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1837 { IPR_PATH_HEALTHY, "is healthy" },
1838 { IPR_PATH_DEGRADED, "is degraded" },
1839 { IPR_PATH_FAILED, "is failed" }
1843 * ipr_log_fabric_path - Log a fabric path error
1844 * @hostrcb: hostrcb struct
1845 * @fabric: fabric descriptor
1850 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1851 struct ipr_hostrcb_fabric_desc *fabric)
1854 u8 path_state = fabric->path_state;
1855 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1856 u8 state = path_state & IPR_PATH_STATE_MASK;
1858 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1859 if (path_active_desc[i].active != active)
1862 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1863 if (path_state_desc[j].state != state)
1866 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
1867 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
1868 path_active_desc[i].desc, path_state_desc[j].desc,
1870 } else if (fabric->cascaded_expander == 0xff) {
1871 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
1872 path_active_desc[i].desc, path_state_desc[j].desc,
1873 fabric->ioa_port, fabric->phy);
1874 } else if (fabric->phy == 0xff) {
1875 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
1876 path_active_desc[i].desc, path_state_desc[j].desc,
1877 fabric->ioa_port, fabric->cascaded_expander);
1879 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
1880 path_active_desc[i].desc, path_state_desc[j].desc,
1881 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1887 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
1888 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
1892 * ipr_log64_fabric_path - Log a fabric path error
1893 * @hostrcb: hostrcb struct
1894 * @fabric: fabric descriptor
1899 static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
1900 struct ipr_hostrcb64_fabric_desc *fabric)
1903 u8 path_state = fabric->path_state;
1904 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1905 u8 state = path_state & IPR_PATH_STATE_MASK;
1906 char buffer[IPR_MAX_RES_PATH_LENGTH];
1908 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1909 if (path_active_desc[i].active != active)
1912 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
1913 if (path_state_desc[j].state != state)
1916 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
1917 path_active_desc[i].desc, path_state_desc[j].desc,
1918 ipr_format_resource_path(&fabric->res_path[0], &buffer[0]));
1923 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
1924 ipr_format_resource_path(&fabric->res_path[0], &buffer[0]));
1927 static const struct {
1930 } path_type_desc[] = {
1931 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
1932 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
1933 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
1934 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
1937 static const struct {
1940 } path_status_desc[] = {
1941 { IPR_PATH_CFG_NO_PROB, "Functional" },
1942 { IPR_PATH_CFG_DEGRADED, "Degraded" },
1943 { IPR_PATH_CFG_FAILED, "Failed" },
1944 { IPR_PATH_CFG_SUSPECT, "Suspect" },
1945 { IPR_PATH_NOT_DETECTED, "Missing" },
1946 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
1949 static const char *link_rate[] = {
1952 "phy reset problem",
1969 * ipr_log_path_elem - Log a fabric path element.
1970 * @hostrcb: hostrcb struct
1971 * @cfg: fabric path element struct
1976 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
1977 struct ipr_hostrcb_config_element *cfg)
1980 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
1981 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
1983 if (type == IPR_PATH_CFG_NOT_EXIST)
1986 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
1987 if (path_type_desc[i].type != type)
1990 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
1991 if (path_status_desc[j].status != status)
1994 if (type == IPR_PATH_CFG_IOA_PORT) {
1995 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
1996 path_status_desc[j].desc, path_type_desc[i].desc,
1997 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
1998 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2000 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2001 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2002 path_status_desc[j].desc, path_type_desc[i].desc,
2003 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2004 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2005 } else if (cfg->cascaded_expander == 0xff) {
2006 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2007 "WWN=%08X%08X\n", path_status_desc[j].desc,
2008 path_type_desc[i].desc, cfg->phy,
2009 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2010 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2011 } else if (cfg->phy == 0xff) {
2012 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2013 "WWN=%08X%08X\n", path_status_desc[j].desc,
2014 path_type_desc[i].desc, cfg->cascaded_expander,
2015 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2016 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2018 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2019 "WWN=%08X%08X\n", path_status_desc[j].desc,
2020 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2021 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2022 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2029 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2030 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2031 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2032 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2036 * ipr_log64_path_elem - Log a fabric path element.
2037 * @hostrcb: hostrcb struct
2038 * @cfg: fabric path element struct
2043 static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2044 struct ipr_hostrcb64_config_element *cfg)
2047 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2048 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2049 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2050 char buffer[IPR_MAX_RES_PATH_LENGTH];
2052 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2055 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2056 if (path_type_desc[i].type != type)
2059 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2060 if (path_status_desc[j].status != status)
2063 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2064 path_status_desc[j].desc, path_type_desc[i].desc,
2065 ipr_format_resource_path(&cfg->res_path[0], &buffer[0]),
2066 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2067 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2071 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2072 "WWN=%08X%08X\n", cfg->type_status,
2073 ipr_format_resource_path(&cfg->res_path[0], &buffer[0]),
2074 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2075 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2079 * ipr_log_fabric_error - Log a fabric error.
2080 * @ioa_cfg: ioa config struct
2081 * @hostrcb: hostrcb struct
2086 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2087 struct ipr_hostrcb *hostrcb)
2089 struct ipr_hostrcb_type_20_error *error;
2090 struct ipr_hostrcb_fabric_desc *fabric;
2091 struct ipr_hostrcb_config_element *cfg;
2094 error = &hostrcb->hcam.u.error.u.type_20_error;
2095 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2096 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2098 add_len = be32_to_cpu(hostrcb->hcam.length) -
2099 (offsetof(struct ipr_hostrcb_error, u) +
2100 offsetof(struct ipr_hostrcb_type_20_error, desc));
2102 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2103 ipr_log_fabric_path(hostrcb, fabric);
2104 for_each_fabric_cfg(fabric, cfg)
2105 ipr_log_path_elem(hostrcb, cfg);
2107 add_len -= be16_to_cpu(fabric->length);
2108 fabric = (struct ipr_hostrcb_fabric_desc *)
2109 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2112 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2116 * ipr_log_sis64_array_error - Log a sis64 array error.
2117 * @ioa_cfg: ioa config struct
2118 * @hostrcb: hostrcb struct
2123 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2124 struct ipr_hostrcb *hostrcb)
2127 struct ipr_hostrcb_type_24_error *error;
2128 struct ipr_hostrcb64_array_data_entry *array_entry;
2129 char buffer[IPR_MAX_RES_PATH_LENGTH];
2130 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2132 error = &hostrcb->hcam.u.error64.u.type_24_error;
2136 ipr_err("RAID %s Array Configuration: %s\n",
2137 error->protection_level,
2138 ipr_format_resource_path(&error->last_res_path[0], &buffer[0]));
2142 array_entry = error->array_member;
2143 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
2144 sizeof(error->array_member));
2146 for (i = 0; i < num_entries; i++, array_entry++) {
2148 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2151 if (error->exposed_mode_adn == i)
2152 ipr_err("Exposed Array Member %d:\n", i);
2154 ipr_err("Array Member %d:\n", i);
2156 ipr_err("Array Member %d:\n", i);
2157 ipr_log_ext_vpd(&array_entry->vpd);
2158 ipr_err("Current Location: %s",
2159 ipr_format_resource_path(&array_entry->res_path[0], &buffer[0]));
2160 ipr_err("Expected Location: %s",
2161 ipr_format_resource_path(&array_entry->expected_res_path[0], &buffer[0]));
2168 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2169 * @ioa_cfg: ioa config struct
2170 * @hostrcb: hostrcb struct
2175 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2176 struct ipr_hostrcb *hostrcb)
2178 struct ipr_hostrcb_type_30_error *error;
2179 struct ipr_hostrcb64_fabric_desc *fabric;
2180 struct ipr_hostrcb64_config_element *cfg;
2183 error = &hostrcb->hcam.u.error64.u.type_30_error;
2185 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2186 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2188 add_len = be32_to_cpu(hostrcb->hcam.length) -
2189 (offsetof(struct ipr_hostrcb64_error, u) +
2190 offsetof(struct ipr_hostrcb_type_30_error, desc));
2192 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2193 ipr_log64_fabric_path(hostrcb, fabric);
2194 for_each_fabric_cfg(fabric, cfg)
2195 ipr_log64_path_elem(hostrcb, cfg);
2197 add_len -= be16_to_cpu(fabric->length);
2198 fabric = (struct ipr_hostrcb64_fabric_desc *)
2199 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2202 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2206 * ipr_log_generic_error - Log an adapter error.
2207 * @ioa_cfg: ioa config struct
2208 * @hostrcb: hostrcb struct
2213 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2214 struct ipr_hostrcb *hostrcb)
2216 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
2217 be32_to_cpu(hostrcb->hcam.length));
2221 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2224 * This function will return the index of into the ipr_error_table
2225 * for the specified IOASC. If the IOASC is not in the table,
2226 * 0 will be returned, which points to the entry used for unknown errors.
2229 * index into the ipr_error_table
2231 static u32 ipr_get_error(u32 ioasc)
2235 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
2236 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
2243 * ipr_handle_log_data - Log an adapter error.
2244 * @ioa_cfg: ioa config struct
2245 * @hostrcb: hostrcb struct
2247 * This function logs an adapter error to the system.
2252 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2253 struct ipr_hostrcb *hostrcb)
2258 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2261 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2262 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2265 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2267 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2269 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2270 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
2271 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2272 scsi_report_bus_reset(ioa_cfg->host,
2273 hostrcb->hcam.u.error.fd_res_addr.bus);
2276 error_index = ipr_get_error(ioasc);
2278 if (!ipr_error_table[error_index].log_hcam)
2281 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
2283 /* Set indication we have logged an error */
2284 ioa_cfg->errors_logged++;
2286 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
2288 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2289 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
2291 switch (hostrcb->hcam.overlay_id) {
2292 case IPR_HOST_RCB_OVERLAY_ID_2:
2293 ipr_log_cache_error(ioa_cfg, hostrcb);
2295 case IPR_HOST_RCB_OVERLAY_ID_3:
2296 ipr_log_config_error(ioa_cfg, hostrcb);
2298 case IPR_HOST_RCB_OVERLAY_ID_4:
2299 case IPR_HOST_RCB_OVERLAY_ID_6:
2300 ipr_log_array_error(ioa_cfg, hostrcb);
2302 case IPR_HOST_RCB_OVERLAY_ID_7:
2303 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2305 case IPR_HOST_RCB_OVERLAY_ID_12:
2306 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2308 case IPR_HOST_RCB_OVERLAY_ID_13:
2309 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2311 case IPR_HOST_RCB_OVERLAY_ID_14:
2312 case IPR_HOST_RCB_OVERLAY_ID_16:
2313 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2315 case IPR_HOST_RCB_OVERLAY_ID_17:
2316 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2318 case IPR_HOST_RCB_OVERLAY_ID_20:
2319 ipr_log_fabric_error(ioa_cfg, hostrcb);
2321 case IPR_HOST_RCB_OVERLAY_ID_23:
2322 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2324 case IPR_HOST_RCB_OVERLAY_ID_24:
2325 case IPR_HOST_RCB_OVERLAY_ID_26:
2326 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2328 case IPR_HOST_RCB_OVERLAY_ID_30:
2329 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2331 case IPR_HOST_RCB_OVERLAY_ID_1:
2332 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
2334 ipr_log_generic_error(ioa_cfg, hostrcb);
2340 * ipr_process_error - Op done function for an adapter error log.
2341 * @ipr_cmd: ipr command struct
2343 * This function is the op done function for an error log host
2344 * controlled async from the adapter. It will log the error and
2345 * send the HCAM back to the adapter.
2350 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2352 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2353 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2354 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
2358 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2360 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2362 list_del(&hostrcb->queue);
2363 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
2366 ipr_handle_log_data(ioa_cfg, hostrcb);
2367 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2368 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2369 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2370 dev_err(&ioa_cfg->pdev->dev,
2371 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2374 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2378 * ipr_timeout - An internally generated op has timed out.
2379 * @ipr_cmd: ipr command struct
2381 * This function blocks host requests and initiates an
2387 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2389 unsigned long lock_flags = 0;
2390 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2393 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2395 ioa_cfg->errors_logged++;
2396 dev_err(&ioa_cfg->pdev->dev,
2397 "Adapter being reset due to command timeout.\n");
2399 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2400 ioa_cfg->sdt_state = GET_DUMP;
2402 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2403 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2405 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2410 * ipr_oper_timeout - Adapter timed out transitioning to operational
2411 * @ipr_cmd: ipr command struct
2413 * This function blocks host requests and initiates an
2419 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2421 unsigned long lock_flags = 0;
2422 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2425 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2427 ioa_cfg->errors_logged++;
2428 dev_err(&ioa_cfg->pdev->dev,
2429 "Adapter timed out transitioning to operational.\n");
2431 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2432 ioa_cfg->sdt_state = GET_DUMP;
2434 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2436 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2437 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2440 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2445 * ipr_reset_reload - Reset/Reload the IOA
2446 * @ioa_cfg: ioa config struct
2447 * @shutdown_type: shutdown type
2449 * This function resets the adapter and re-initializes it.
2450 * This function assumes that all new host commands have been stopped.
2454 static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
2455 enum ipr_shutdown_type shutdown_type)
2457 if (!ioa_cfg->in_reset_reload)
2458 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
2460 spin_unlock_irq(ioa_cfg->host->host_lock);
2461 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2462 spin_lock_irq(ioa_cfg->host->host_lock);
2464 /* If we got hit with a host reset while we were already resetting
2465 the adapter for some reason, and the reset failed. */
2466 if (ioa_cfg->ioa_is_dead) {
2475 * ipr_find_ses_entry - Find matching SES in SES table
2476 * @res: resource entry struct of SES
2479 * pointer to SES table entry / NULL on failure
2481 static const struct ipr_ses_table_entry *
2482 ipr_find_ses_entry(struct ipr_resource_entry *res)
2485 struct ipr_std_inq_vpids *vpids;
2486 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2488 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2489 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2490 if (ste->compare_product_id_byte[j] == 'X') {
2491 vpids = &res->std_inq_data.vpids;
2492 if (vpids->product_id[j] == ste->product_id[j])
2500 if (matches == IPR_PROD_ID_LEN)
2508 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2509 * @ioa_cfg: ioa config struct
2511 * @bus_width: bus width
2514 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2515 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2516 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2517 * max 160MHz = max 320MB/sec).
2519 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2521 struct ipr_resource_entry *res;
2522 const struct ipr_ses_table_entry *ste;
2523 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2525 /* Loop through each config table entry in the config table buffer */
2526 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2527 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
2530 if (bus != res->bus)
2533 if (!(ste = ipr_find_ses_entry(res)))
2536 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2539 return max_xfer_rate;
2543 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2544 * @ioa_cfg: ioa config struct
2545 * @max_delay: max delay in micro-seconds to wait
2547 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2550 * 0 on success / other on failure
2552 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2554 volatile u32 pcii_reg;
2557 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2558 while (delay < max_delay) {
2559 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2561 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2564 /* udelay cannot be used if delay is more than a few milliseconds */
2565 if ((delay / 1000) > MAX_UDELAY_MS)
2566 mdelay(delay / 1000);
2576 * ipr_get_sis64_dump_data_section - Dump IOA memory
2577 * @ioa_cfg: ioa config struct
2578 * @start_addr: adapter address to dump
2579 * @dest: destination kernel buffer
2580 * @length_in_words: length to dump in 4 byte words
2585 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2587 __be32 *dest, u32 length_in_words)
2591 for (i = 0; i < length_in_words; i++) {
2592 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2593 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2601 * ipr_get_ldump_data_section - Dump IOA memory
2602 * @ioa_cfg: ioa config struct
2603 * @start_addr: adapter address to dump
2604 * @dest: destination kernel buffer
2605 * @length_in_words: length to dump in 4 byte words
2608 * 0 on success / -EIO on failure
2610 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2612 __be32 *dest, u32 length_in_words)
2614 volatile u32 temp_pcii_reg;
2618 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2619 dest, length_in_words);
2621 /* Write IOA interrupt reg starting LDUMP state */
2622 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
2623 ioa_cfg->regs.set_uproc_interrupt_reg32);
2625 /* Wait for IO debug acknowledge */
2626 if (ipr_wait_iodbg_ack(ioa_cfg,
2627 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2628 dev_err(&ioa_cfg->pdev->dev,
2629 "IOA dump long data transfer timeout\n");
2633 /* Signal LDUMP interlocked - clear IO debug ack */
2634 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2635 ioa_cfg->regs.clr_interrupt_reg);
2637 /* Write Mailbox with starting address */
2638 writel(start_addr, ioa_cfg->ioa_mailbox);
2640 /* Signal address valid - clear IOA Reset alert */
2641 writel(IPR_UPROCI_RESET_ALERT,
2642 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2644 for (i = 0; i < length_in_words; i++) {
2645 /* Wait for IO debug acknowledge */
2646 if (ipr_wait_iodbg_ack(ioa_cfg,
2647 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2648 dev_err(&ioa_cfg->pdev->dev,
2649 "IOA dump short data transfer timeout\n");
2653 /* Read data from mailbox and increment destination pointer */
2654 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2657 /* For all but the last word of data, signal data received */
2658 if (i < (length_in_words - 1)) {
2659 /* Signal dump data received - Clear IO debug Ack */
2660 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2661 ioa_cfg->regs.clr_interrupt_reg);
2665 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2666 writel(IPR_UPROCI_RESET_ALERT,
2667 ioa_cfg->regs.set_uproc_interrupt_reg32);
2669 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2670 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2672 /* Signal dump data received - Clear IO debug Ack */
2673 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2674 ioa_cfg->regs.clr_interrupt_reg);
2676 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2677 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2679 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
2681 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2691 #ifdef CONFIG_SCSI_IPR_DUMP
2693 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2694 * @ioa_cfg: ioa config struct
2695 * @pci_address: adapter address
2696 * @length: length of data to copy
2698 * Copy data from PCI adapter to kernel buffer.
2699 * Note: length MUST be a 4 byte multiple
2701 * 0 on success / other on failure
2703 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2704 unsigned long pci_address, u32 length)
2706 int bytes_copied = 0;
2707 int cur_len, rc, rem_len, rem_page_len;
2709 unsigned long lock_flags = 0;
2710 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2712 while (bytes_copied < length &&
2713 (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
2714 if (ioa_dump->page_offset >= PAGE_SIZE ||
2715 ioa_dump->page_offset == 0) {
2716 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2720 return bytes_copied;
2723 ioa_dump->page_offset = 0;
2724 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2725 ioa_dump->next_page_index++;
2727 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2729 rem_len = length - bytes_copied;
2730 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2731 cur_len = min(rem_len, rem_page_len);
2733 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2734 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2737 rc = ipr_get_ldump_data_section(ioa_cfg,
2738 pci_address + bytes_copied,
2739 &page[ioa_dump->page_offset / 4],
2740 (cur_len / sizeof(u32)));
2742 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2745 ioa_dump->page_offset += cur_len;
2746 bytes_copied += cur_len;
2754 return bytes_copied;
2758 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2759 * @hdr: dump entry header struct
2764 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2766 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2768 hdr->offset = sizeof(*hdr);
2769 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2773 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2774 * @ioa_cfg: ioa config struct
2775 * @driver_dump: driver dump struct
2780 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2781 struct ipr_driver_dump *driver_dump)
2783 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2785 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2786 driver_dump->ioa_type_entry.hdr.len =
2787 sizeof(struct ipr_dump_ioa_type_entry) -
2788 sizeof(struct ipr_dump_entry_header);
2789 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2790 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2791 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2792 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2793 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2794 ucode_vpd->minor_release[1];
2795 driver_dump->hdr.num_entries++;
2799 * ipr_dump_version_data - Fill in the driver version in the dump.
2800 * @ioa_cfg: ioa config struct
2801 * @driver_dump: driver dump struct
2806 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2807 struct ipr_driver_dump *driver_dump)
2809 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2810 driver_dump->version_entry.hdr.len =
2811 sizeof(struct ipr_dump_version_entry) -
2812 sizeof(struct ipr_dump_entry_header);
2813 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2814 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2815 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2816 driver_dump->hdr.num_entries++;
2820 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2821 * @ioa_cfg: ioa config struct
2822 * @driver_dump: driver dump struct
2827 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2828 struct ipr_driver_dump *driver_dump)
2830 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2831 driver_dump->trace_entry.hdr.len =
2832 sizeof(struct ipr_dump_trace_entry) -
2833 sizeof(struct ipr_dump_entry_header);
2834 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2835 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2836 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2837 driver_dump->hdr.num_entries++;
2841 * ipr_dump_location_data - Fill in the IOA location in the dump.
2842 * @ioa_cfg: ioa config struct
2843 * @driver_dump: driver dump struct
2848 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2849 struct ipr_driver_dump *driver_dump)
2851 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2852 driver_dump->location_entry.hdr.len =
2853 sizeof(struct ipr_dump_location_entry) -
2854 sizeof(struct ipr_dump_entry_header);
2855 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2856 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2857 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
2858 driver_dump->hdr.num_entries++;
2862 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2863 * @ioa_cfg: ioa config struct
2864 * @dump: dump struct
2869 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2871 unsigned long start_addr, sdt_word;
2872 unsigned long lock_flags = 0;
2873 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2874 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2875 u32 num_entries, start_off, end_off;
2876 u32 bytes_to_copy, bytes_copied, rc;
2877 struct ipr_sdt *sdt;
2883 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2885 if (ioa_cfg->sdt_state != GET_DUMP) {
2886 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2890 start_addr = readl(ioa_cfg->ioa_mailbox);
2892 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
2893 dev_err(&ioa_cfg->pdev->dev,
2894 "Invalid dump table format: %lx\n", start_addr);
2895 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2899 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
2901 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
2903 /* Initialize the overall dump header */
2904 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
2905 driver_dump->hdr.num_entries = 1;
2906 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
2907 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
2908 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
2909 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
2911 ipr_dump_version_data(ioa_cfg, driver_dump);
2912 ipr_dump_location_data(ioa_cfg, driver_dump);
2913 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
2914 ipr_dump_trace_data(ioa_cfg, driver_dump);
2916 /* Update dump_header */
2917 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
2919 /* IOA Dump entry */
2920 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
2921 ioa_dump->hdr.len = 0;
2922 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2923 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
2925 /* First entries in sdt are actually a list of dump addresses and
2926 lengths to gather the real dump data. sdt represents the pointer
2927 to the ioa generated dump table. Dump data will be extracted based
2928 on entries in this table */
2929 sdt = &ioa_dump->sdt;
2931 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
2932 sizeof(struct ipr_sdt) / sizeof(__be32));
2934 /* Smart Dump table is ready to use and the first entry is valid */
2935 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
2936 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
2937 dev_err(&ioa_cfg->pdev->dev,
2938 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
2939 rc, be32_to_cpu(sdt->hdr.state));
2940 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
2941 ioa_cfg->sdt_state = DUMP_OBTAINED;
2942 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2946 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
2948 if (num_entries > IPR_NUM_SDT_ENTRIES)
2949 num_entries = IPR_NUM_SDT_ENTRIES;
2951 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2953 for (i = 0; i < num_entries; i++) {
2954 if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
2955 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2959 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
2960 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
2962 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
2964 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
2965 end_off = be32_to_cpu(sdt->entry[i].end_token);
2967 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
2968 bytes_to_copy = end_off - start_off;
2973 if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
2974 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
2978 /* Copy data from adapter to driver buffers */
2979 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
2982 ioa_dump->hdr.len += bytes_copied;
2984 if (bytes_copied != bytes_to_copy) {
2985 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
2992 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
2994 /* Update dump_header */
2995 driver_dump->hdr.len += ioa_dump->hdr.len;
2997 ioa_cfg->sdt_state = DUMP_OBTAINED;
3002 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
3006 * ipr_release_dump - Free adapter dump memory
3007 * @kref: kref struct
3012 static void ipr_release_dump(struct kref *kref)
3014 struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
3015 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3016 unsigned long lock_flags = 0;
3020 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3021 ioa_cfg->dump = NULL;
3022 ioa_cfg->sdt_state = INACTIVE;
3023 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3025 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3026 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3033 * ipr_worker_thread - Worker thread
3034 * @work: ioa config struct
3036 * Called at task level from a work thread. This function takes care
3037 * of adding and removing device from the mid-layer as configuration
3038 * changes are detected by the adapter.
3043 static void ipr_worker_thread(struct work_struct *work)
3045 unsigned long lock_flags;
3046 struct ipr_resource_entry *res;
3047 struct scsi_device *sdev;
3048 struct ipr_dump *dump;
3049 struct ipr_ioa_cfg *ioa_cfg =
3050 container_of(work, struct ipr_ioa_cfg, work_q);
3051 u8 bus, target, lun;
3055 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3057 if (ioa_cfg->sdt_state == GET_DUMP) {
3058 dump = ioa_cfg->dump;
3060 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3063 kref_get(&dump->kref);
3064 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3065 ipr_get_ioa_dump(ioa_cfg, dump);
3066 kref_put(&dump->kref, ipr_release_dump);
3068 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3069 if (ioa_cfg->sdt_state == DUMP_OBTAINED)
3070 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3071 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3078 if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
3079 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3083 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3084 if (res->del_from_ml && res->sdev) {
3087 if (!scsi_device_get(sdev)) {
3088 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3089 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3090 scsi_remove_device(sdev);
3091 scsi_device_put(sdev);
3092 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3099 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3100 if (res->add_to_ml) {
3102 target = res->target;
3105 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3106 scsi_add_device(ioa_cfg->host, bus, target, lun);
3107 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3112 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3113 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
3117 #ifdef CONFIG_SCSI_IPR_TRACE
3119 * ipr_read_trace - Dump the adapter trace
3120 * @kobj: kobject struct
3121 * @bin_attr: bin_attribute struct
3124 * @count: buffer size
3127 * number of bytes printed to buffer
3129 static ssize_t ipr_read_trace(struct kobject *kobj,
3130 struct bin_attribute *bin_attr,
3131 char *buf, loff_t off, size_t count)
3133 struct device *dev = container_of(kobj, struct device, kobj);
3134 struct Scsi_Host *shost = class_to_shost(dev);
3135 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3136 unsigned long lock_flags = 0;
3139 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3140 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3142 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3147 static struct bin_attribute ipr_trace_attr = {
3153 .read = ipr_read_trace,
3158 * ipr_show_fw_version - Show the firmware version
3159 * @dev: class device struct
3163 * number of bytes printed to buffer
3165 static ssize_t ipr_show_fw_version(struct device *dev,
3166 struct device_attribute *attr, char *buf)
3168 struct Scsi_Host *shost = class_to_shost(dev);
3169 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3170 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3171 unsigned long lock_flags = 0;
3174 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3175 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3176 ucode_vpd->major_release, ucode_vpd->card_type,
3177 ucode_vpd->minor_release[0],
3178 ucode_vpd->minor_release[1]);
3179 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3183 static struct device_attribute ipr_fw_version_attr = {
3185 .name = "fw_version",
3188 .show = ipr_show_fw_version,
3192 * ipr_show_log_level - Show the adapter's error logging level
3193 * @dev: class device struct
3197 * number of bytes printed to buffer
3199 static ssize_t ipr_show_log_level(struct device *dev,
3200 struct device_attribute *attr, char *buf)
3202 struct Scsi_Host *shost = class_to_shost(dev);
3203 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3204 unsigned long lock_flags = 0;
3207 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3208 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3209 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3214 * ipr_store_log_level - Change the adapter's error logging level
3215 * @dev: class device struct
3219 * number of bytes printed to buffer
3221 static ssize_t ipr_store_log_level(struct device *dev,
3222 struct device_attribute *attr,
3223 const char *buf, size_t count)
3225 struct Scsi_Host *shost = class_to_shost(dev);
3226 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3227 unsigned long lock_flags = 0;
3229 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3230 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3231 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3235 static struct device_attribute ipr_log_level_attr = {
3237 .name = "log_level",
3238 .mode = S_IRUGO | S_IWUSR,
3240 .show = ipr_show_log_level,
3241 .store = ipr_store_log_level
3245 * ipr_store_diagnostics - IOA Diagnostics interface
3246 * @dev: device struct
3248 * @count: buffer size
3250 * This function will reset the adapter and wait a reasonable
3251 * amount of time for any errors that the adapter might log.
3254 * count on success / other on failure
3256 static ssize_t ipr_store_diagnostics(struct device *dev,
3257 struct device_attribute *attr,
3258 const char *buf, size_t count)
3260 struct Scsi_Host *shost = class_to_shost(dev);
3261 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3262 unsigned long lock_flags = 0;
3265 if (!capable(CAP_SYS_ADMIN))
3268 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3269 while(ioa_cfg->in_reset_reload) {
3270 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3271 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3272 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3275 ioa_cfg->errors_logged = 0;
3276 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3278 if (ioa_cfg->in_reset_reload) {
3279 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3280 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3282 /* Wait for a second for any errors to be logged */
3285 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3289 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3290 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3292 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3297 static struct device_attribute ipr_diagnostics_attr = {
3299 .name = "run_diagnostics",
3302 .store = ipr_store_diagnostics
3306 * ipr_show_adapter_state - Show the adapter's state
3307 * @class_dev: device struct
3311 * number of bytes printed to buffer
3313 static ssize_t ipr_show_adapter_state(struct device *dev,
3314 struct device_attribute *attr, char *buf)
3316 struct Scsi_Host *shost = class_to_shost(dev);
3317 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3318 unsigned long lock_flags = 0;
3321 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3322 if (ioa_cfg->ioa_is_dead)
3323 len = snprintf(buf, PAGE_SIZE, "offline\n");
3325 len = snprintf(buf, PAGE_SIZE, "online\n");
3326 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3331 * ipr_store_adapter_state - Change adapter state
3332 * @dev: device struct
3334 * @count: buffer size
3336 * This function will change the adapter's state.
3339 * count on success / other on failure
3341 static ssize_t ipr_store_adapter_state(struct device *dev,
3342 struct device_attribute *attr,
3343 const char *buf, size_t count)
3345 struct Scsi_Host *shost = class_to_shost(dev);
3346 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3347 unsigned long lock_flags;
3350 if (!capable(CAP_SYS_ADMIN))
3353 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3354 if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
3355 ioa_cfg->ioa_is_dead = 0;
3356 ioa_cfg->reset_retries = 0;
3357 ioa_cfg->in_ioa_bringdown = 0;
3358 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3360 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3361 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3366 static struct device_attribute ipr_ioa_state_attr = {
3368 .name = "online_state",
3369 .mode = S_IRUGO | S_IWUSR,
3371 .show = ipr_show_adapter_state,
3372 .store = ipr_store_adapter_state
3376 * ipr_store_reset_adapter - Reset the adapter
3377 * @dev: device struct
3379 * @count: buffer size
3381 * This function will reset the adapter.
3384 * count on success / other on failure
3386 static ssize_t ipr_store_reset_adapter(struct device *dev,
3387 struct device_attribute *attr,
3388 const char *buf, size_t count)
3390 struct Scsi_Host *shost = class_to_shost(dev);
3391 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3392 unsigned long lock_flags;
3395 if (!capable(CAP_SYS_ADMIN))
3398 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3399 if (!ioa_cfg->in_reset_reload)
3400 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3401 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3402 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3407 static struct device_attribute ipr_ioa_reset_attr = {
3409 .name = "reset_host",
3412 .store = ipr_store_reset_adapter
3416 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3417 * @buf_len: buffer length
3419 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3420 * list to use for microcode download
3423 * pointer to sglist / NULL on failure
3425 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3427 int sg_size, order, bsize_elem, num_elem, i, j;
3428 struct ipr_sglist *sglist;
3429 struct scatterlist *scatterlist;
3432 /* Get the minimum size per scatter/gather element */
3433 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3435 /* Get the actual size per element */
3436 order = get_order(sg_size);
3438 /* Determine the actual number of bytes per element */
3439 bsize_elem = PAGE_SIZE * (1 << order);
3441 /* Determine the actual number of sg entries needed */
3442 if (buf_len % bsize_elem)
3443 num_elem = (buf_len / bsize_elem) + 1;
3445 num_elem = buf_len / bsize_elem;
3447 /* Allocate a scatter/gather list for the DMA */
3448 sglist = kzalloc(sizeof(struct ipr_sglist) +
3449 (sizeof(struct scatterlist) * (num_elem - 1)),
3452 if (sglist == NULL) {
3457 scatterlist = sglist->scatterlist;
3458 sg_init_table(scatterlist, num_elem);
3460 sglist->order = order;
3461 sglist->num_sg = num_elem;
3463 /* Allocate a bunch of sg elements */
3464 for (i = 0; i < num_elem; i++) {
3465 page = alloc_pages(GFP_KERNEL, order);
3469 /* Free up what we already allocated */
3470 for (j = i - 1; j >= 0; j--)
3471 __free_pages(sg_page(&scatterlist[j]), order);
3476 sg_set_page(&scatterlist[i], page, 0, 0);
3483 * ipr_free_ucode_buffer - Frees a microcode download buffer
3484 * @p_dnld: scatter/gather list pointer
3486 * Free a DMA'able ucode download buffer previously allocated with
3487 * ipr_alloc_ucode_buffer
3492 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3496 for (i = 0; i < sglist->num_sg; i++)
3497 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
3503 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3504 * @sglist: scatter/gather list pointer
3505 * @buffer: buffer pointer
3506 * @len: buffer length
3508 * Copy a microcode image from a user buffer into a buffer allocated by
3509 * ipr_alloc_ucode_buffer
3512 * 0 on success / other on failure
3514 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3515 u8 *buffer, u32 len)
3517 int bsize_elem, i, result = 0;
3518 struct scatterlist *scatterlist;
3521 /* Determine the actual number of bytes per element */
3522 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3524 scatterlist = sglist->scatterlist;
3526 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
3527 struct page *page = sg_page(&scatterlist[i]);
3530 memcpy(kaddr, buffer, bsize_elem);
3533 scatterlist[i].length = bsize_elem;
3541 if (len % bsize_elem) {
3542 struct page *page = sg_page(&scatterlist[i]);
3545 memcpy(kaddr, buffer, len % bsize_elem);
3548 scatterlist[i].length = len % bsize_elem;
3551 sglist->buffer_len = len;
3556 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3557 * @ipr_cmd: ipr command struct
3558 * @sglist: scatter/gather list
3560 * Builds a microcode download IOA data list (IOADL).
3563 static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3564 struct ipr_sglist *sglist)
3566 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3567 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3568 struct scatterlist *scatterlist = sglist->scatterlist;
3571 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3572 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3573 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3576 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3577 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3578 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3579 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3580 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3583 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3587 * ipr_build_ucode_ioadl - Build a microcode download IOADL
3588 * @ipr_cmd: ipr command struct
3589 * @sglist: scatter/gather list
3591 * Builds a microcode download IOA data list (IOADL).
3594 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3595 struct ipr_sglist *sglist)
3597 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3598 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
3599 struct scatterlist *scatterlist = sglist->scatterlist;
3602 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3603 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3604 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3607 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3609 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3610 ioadl[i].flags_and_data_len =
3611 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3613 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3616 ioadl[i-1].flags_and_data_len |=
3617 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3621 * ipr_update_ioa_ucode - Update IOA's microcode
3622 * @ioa_cfg: ioa config struct
3623 * @sglist: scatter/gather list
3625 * Initiate an adapter reset to update the IOA's microcode
3628 * 0 on success / -EIO on failure
3630 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3631 struct ipr_sglist *sglist)
3633 unsigned long lock_flags;
3635 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3636 while(ioa_cfg->in_reset_reload) {
3637 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3638 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3639 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3642 if (ioa_cfg->ucode_sglist) {
3643 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3644 dev_err(&ioa_cfg->pdev->dev,
3645 "Microcode download already in progress\n");
3649 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3650 sglist->num_sg, DMA_TO_DEVICE);
3652 if (!sglist->num_dma_sg) {
3653 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3654 dev_err(&ioa_cfg->pdev->dev,
3655 "Failed to map microcode download buffer!\n");
3659 ioa_cfg->ucode_sglist = sglist;
3660 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3661 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3662 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3664 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3665 ioa_cfg->ucode_sglist = NULL;
3666 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3671 * ipr_store_update_fw - Update the firmware on the adapter
3672 * @class_dev: device struct
3674 * @count: buffer size
3676 * This function will update the firmware on the adapter.
3679 * count on success / other on failure
3681 static ssize_t ipr_store_update_fw(struct device *dev,
3682 struct device_attribute *attr,
3683 const char *buf, size_t count)
3685 struct Scsi_Host *shost = class_to_shost(dev);
3686 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3687 struct ipr_ucode_image_header *image_hdr;
3688 const struct firmware *fw_entry;
3689 struct ipr_sglist *sglist;
3692 int len, result, dnld_size;
3694 if (!capable(CAP_SYS_ADMIN))
3697 len = snprintf(fname, 99, "%s", buf);
3698 fname[len-1] = '\0';
3700 if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3701 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3705 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3707 if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
3708 (ioa_cfg->vpd_cbs->page3_data.card_type &&
3709 ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
3710 dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
3711 release_firmware(fw_entry);
3715 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3716 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3717 sglist = ipr_alloc_ucode_buffer(dnld_size);
3720 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3721 release_firmware(fw_entry);
3725 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3728 dev_err(&ioa_cfg->pdev->dev,
3729 "Microcode buffer copy to DMA buffer failed\n");
3733 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3738 ipr_free_ucode_buffer(sglist);
3739 release_firmware(fw_entry);
3743 static struct device_attribute ipr_update_fw_attr = {
3745 .name = "update_fw",
3748 .store = ipr_store_update_fw
3751 static struct device_attribute *ipr_ioa_attrs[] = {
3752 &ipr_fw_version_attr,
3753 &ipr_log_level_attr,
3754 &ipr_diagnostics_attr,
3755 &ipr_ioa_state_attr,
3756 &ipr_ioa_reset_attr,
3757 &ipr_update_fw_attr,
3761 #ifdef CONFIG_SCSI_IPR_DUMP
3763 * ipr_read_dump - Dump the adapter
3764 * @kobj: kobject struct
3765 * @bin_attr: bin_attribute struct
3768 * @count: buffer size
3771 * number of bytes printed to buffer
3773 static ssize_t ipr_read_dump(struct kobject *kobj,
3774 struct bin_attribute *bin_attr,
3775 char *buf, loff_t off, size_t count)
3777 struct device *cdev = container_of(kobj, struct device, kobj);
3778 struct Scsi_Host *shost = class_to_shost(cdev);
3779 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3780 struct ipr_dump *dump;
3781 unsigned long lock_flags = 0;
3786 if (!capable(CAP_SYS_ADMIN))
3789 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3790 dump = ioa_cfg->dump;
3792 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
3793 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3796 kref_get(&dump->kref);
3797 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3799 if (off > dump->driver_dump.hdr.len) {
3800 kref_put(&dump->kref, ipr_release_dump);
3804 if (off + count > dump->driver_dump.hdr.len) {
3805 count = dump->driver_dump.hdr.len - off;
3809 if (count && off < sizeof(dump->driver_dump)) {
3810 if (off + count > sizeof(dump->driver_dump))
3811 len = sizeof(dump->driver_dump) - off;
3814 src = (u8 *)&dump->driver_dump + off;
3815 memcpy(buf, src, len);
3821 off -= sizeof(dump->driver_dump);
3823 if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
3824 if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
3825 len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
3828 src = (u8 *)&dump->ioa_dump + off;
3829 memcpy(buf, src, len);
3835 off -= offsetof(struct ipr_ioa_dump, ioa_data);
3838 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
3839 len = PAGE_ALIGN(off) - off;
3842 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
3843 src += off & ~PAGE_MASK;
3844 memcpy(buf, src, len);
3850 kref_put(&dump->kref, ipr_release_dump);
3855 * ipr_alloc_dump - Prepare for adapter dump
3856 * @ioa_cfg: ioa config struct
3859 * 0 on success / other on failure
3861 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
3863 struct ipr_dump *dump;
3864 unsigned long lock_flags = 0;
3866 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
3869 ipr_err("Dump memory allocation failed\n");
3873 kref_init(&dump->kref);
3874 dump->ioa_cfg = ioa_cfg;
3876 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3878 if (INACTIVE != ioa_cfg->sdt_state) {
3879 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3884 ioa_cfg->dump = dump;
3885 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
3886 if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
3887 ioa_cfg->dump_taken = 1;
3888 schedule_work(&ioa_cfg->work_q);
3890 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3896 * ipr_free_dump - Free adapter dump memory
3897 * @ioa_cfg: ioa config struct
3900 * 0 on success / other on failure
3902 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
3904 struct ipr_dump *dump;
3905 unsigned long lock_flags = 0;
3909 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3910 dump = ioa_cfg->dump;
3912 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3916 ioa_cfg->dump = NULL;
3917 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3919 kref_put(&dump->kref, ipr_release_dump);
3926 * ipr_write_dump - Setup dump state of adapter
3927 * @kobj: kobject struct
3928 * @bin_attr: bin_attribute struct
3931 * @count: buffer size
3934 * number of bytes printed to buffer
3936 static ssize_t ipr_write_dump(struct kobject *kobj,
3937 struct bin_attribute *bin_attr,
3938 char *buf, loff_t off, size_t count)
3940 struct device *cdev = container_of(kobj, struct device, kobj);
3941 struct Scsi_Host *shost = class_to_shost(cdev);
3942 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3945 if (!capable(CAP_SYS_ADMIN))
3949 rc = ipr_alloc_dump(ioa_cfg);
3950 else if (buf[0] == '0')
3951 rc = ipr_free_dump(ioa_cfg);
3961 static struct bin_attribute ipr_dump_attr = {
3964 .mode = S_IRUSR | S_IWUSR,
3967 .read = ipr_read_dump,
3968 .write = ipr_write_dump
3971 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
3975 * ipr_change_queue_depth - Change the device's queue depth
3976 * @sdev: scsi device struct
3977 * @qdepth: depth to set
3978 * @reason: calling context
3983 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
3986 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
3987 struct ipr_resource_entry *res;
3988 unsigned long lock_flags = 0;
3990 if (reason != SCSI_QDEPTH_DEFAULT)
3993 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3994 res = (struct ipr_resource_entry *)sdev->hostdata;
3996 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
3997 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
3998 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4000 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
4001 return sdev->queue_depth;
4005 * ipr_change_queue_type - Change the device's queue type
4006 * @dsev: scsi device struct
4007 * @tag_type: type of tags to use
4010 * actual queue type set
4012 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4014 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4015 struct ipr_resource_entry *res;
4016 unsigned long lock_flags = 0;
4018 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4019 res = (struct ipr_resource_entry *)sdev->hostdata;
4022 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
4024 * We don't bother quiescing the device here since the
4025 * adapter firmware does it for us.
4027 scsi_set_tag_type(sdev, tag_type);
4030 scsi_activate_tcq(sdev, sdev->queue_depth);
4032 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4038 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4043 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4044 * @dev: device struct
4048 * number of bytes printed to buffer
4050 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
4052 struct scsi_device *sdev = to_scsi_device(dev);
4053 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4054 struct ipr_resource_entry *res;
4055 unsigned long lock_flags = 0;
4056 ssize_t len = -ENXIO;
4058 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4059 res = (struct ipr_resource_entry *)sdev->hostdata;
4061 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
4062 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4066 static struct device_attribute ipr_adapter_handle_attr = {
4068 .name = "adapter_handle",
4071 .show = ipr_show_adapter_handle
4075 * ipr_show_resource_path - Show the resource path for this device.
4076 * @dev: device struct
4080 * number of bytes printed to buffer
4082 static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4084 struct scsi_device *sdev = to_scsi_device(dev);
4085 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4086 struct ipr_resource_entry *res;
4087 unsigned long lock_flags = 0;
4088 ssize_t len = -ENXIO;
4089 char buffer[IPR_MAX_RES_PATH_LENGTH];
4091 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4092 res = (struct ipr_resource_entry *)sdev->hostdata;
4094 len = snprintf(buf, PAGE_SIZE, "%s\n",
4095 ipr_format_resource_path(&res->res_path[0], &buffer[0]));
4096 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4100 static struct device_attribute ipr_resource_path_attr = {
4102 .name = "resource_path",
4105 .show = ipr_show_resource_path
4108 static struct device_attribute *ipr_dev_attrs[] = {
4109 &ipr_adapter_handle_attr,
4110 &ipr_resource_path_attr,
4115 * ipr_biosparam - Return the HSC mapping
4116 * @sdev: scsi device struct
4117 * @block_device: block device pointer
4118 * @capacity: capacity of the device
4119 * @parm: Array containing returned HSC values.
4121 * This function generates the HSC parms that fdisk uses.
4122 * We want to make sure we return something that places partitions
4123 * on 4k boundaries for best performance with the IOA.
4128 static int ipr_biosparam(struct scsi_device *sdev,
4129 struct block_device *block_device,
4130 sector_t capacity, int *parm)
4138 cylinders = capacity;
4139 sector_div(cylinders, (128 * 32));
4144 parm[2] = cylinders;
4150 * ipr_find_starget - Find target based on bus/target.
4151 * @starget: scsi target struct
4154 * resource entry pointer if found / NULL if not found
4156 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4158 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4159 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4160 struct ipr_resource_entry *res;
4162 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4163 if ((res->bus == starget->channel) &&
4164 (res->target == starget->id) &&
4173 static struct ata_port_info sata_port_info;
4176 * ipr_target_alloc - Prepare for commands to a SCSI target
4177 * @starget: scsi target struct
4179 * If the device is a SATA device, this function allocates an
4180 * ATA port with libata, else it does nothing.
4183 * 0 on success / non-0 on failure
4185 static int ipr_target_alloc(struct scsi_target *starget)
4187 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4188 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4189 struct ipr_sata_port *sata_port;
4190 struct ata_port *ap;
4191 struct ipr_resource_entry *res;
4192 unsigned long lock_flags;
4194 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4195 res = ipr_find_starget(starget);
4196 starget->hostdata = NULL;
4198 if (res && ipr_is_gata(res)) {
4199 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4200 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4204 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4206 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4207 sata_port->ioa_cfg = ioa_cfg;
4209 sata_port->res = res;
4211 res->sata_port = sata_port;
4212 ap->private_data = sata_port;
4213 starget->hostdata = sata_port;
4219 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4225 * ipr_target_destroy - Destroy a SCSI target
4226 * @starget: scsi target struct
4228 * If the device was a SATA device, this function frees the libata
4229 * ATA port, else it does nothing.
4232 static void ipr_target_destroy(struct scsi_target *starget)
4234 struct ipr_sata_port *sata_port = starget->hostdata;
4235 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4236 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4238 if (ioa_cfg->sis64) {
4239 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4240 clear_bit(starget->id, ioa_cfg->array_ids);
4241 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4242 clear_bit(starget->id, ioa_cfg->vset_ids);
4243 else if (starget->channel == 0)
4244 clear_bit(starget->id, ioa_cfg->target_ids);
4248 starget->hostdata = NULL;
4249 ata_sas_port_destroy(sata_port->ap);
4255 * ipr_find_sdev - Find device based on bus/target/lun.
4256 * @sdev: scsi device struct
4259 * resource entry pointer if found / NULL if not found
4261 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4263 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4264 struct ipr_resource_entry *res;
4266 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4267 if ((res->bus == sdev->channel) &&
4268 (res->target == sdev->id) &&
4269 (res->lun == sdev->lun))
4277 * ipr_slave_destroy - Unconfigure a SCSI device
4278 * @sdev: scsi device struct
4283 static void ipr_slave_destroy(struct scsi_device *sdev)
4285 struct ipr_resource_entry *res;
4286 struct ipr_ioa_cfg *ioa_cfg;
4287 unsigned long lock_flags = 0;
4289 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4291 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4292 res = (struct ipr_resource_entry *) sdev->hostdata;
4295 ata_port_disable(res->sata_port->ap);
4296 sdev->hostdata = NULL;
4298 res->sata_port = NULL;
4300 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4304 * ipr_slave_configure - Configure a SCSI device
4305 * @sdev: scsi device struct
4307 * This function configures the specified scsi device.
4312 static int ipr_slave_configure(struct scsi_device *sdev)
4314 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4315 struct ipr_resource_entry *res;
4316 struct ata_port *ap = NULL;
4317 unsigned long lock_flags = 0;
4318 char buffer[IPR_MAX_RES_PATH_LENGTH];
4320 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4321 res = sdev->hostdata;
4323 if (ipr_is_af_dasd_device(res))
4324 sdev->type = TYPE_RAID;
4325 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
4326 sdev->scsi_level = 4;
4327 sdev->no_uld_attach = 1;
4329 if (ipr_is_vset_device(res)) {
4330 blk_queue_rq_timeout(sdev->request_queue,
4331 IPR_VSET_RW_TIMEOUT);
4332 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
4334 if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
4335 sdev->allow_restart = 1;
4336 if (ipr_is_gata(res) && res->sata_port)
4337 ap = res->sata_port->ap;
4338 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4341 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
4342 ata_sas_slave_configure(sdev, ap);
4344 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4346 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4347 ipr_format_resource_path(&res->res_path[0], &buffer[0]));
4350 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4355 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4356 * @sdev: scsi device struct
4358 * This function initializes an ATA port so that future commands
4359 * sent through queuecommand will work.
4364 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4366 struct ipr_sata_port *sata_port = NULL;
4370 if (sdev->sdev_target)
4371 sata_port = sdev->sdev_target->hostdata;
4373 rc = ata_sas_port_init(sata_port->ap);
4375 ipr_slave_destroy(sdev);
4382 * ipr_slave_alloc - Prepare for commands to a device.
4383 * @sdev: scsi device struct
4385 * This function saves a pointer to the resource entry
4386 * in the scsi device struct if the device exists. We
4387 * can then use this pointer in ipr_queuecommand when
4388 * handling new commands.
4391 * 0 on success / -ENXIO if device does not exist
4393 static int ipr_slave_alloc(struct scsi_device *sdev)
4395 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4396 struct ipr_resource_entry *res;
4397 unsigned long lock_flags;
4400 sdev->hostdata = NULL;
4402 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4404 res = ipr_find_sdev(sdev);
4409 sdev->hostdata = res;
4410 if (!ipr_is_naca_model(res))
4411 res->needs_sync_complete = 1;
4413 if (ipr_is_gata(res)) {
4414 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4415 return ipr_ata_slave_alloc(sdev);
4419 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4425 * ipr_eh_host_reset - Reset the host adapter
4426 * @scsi_cmd: scsi command struct
4431 static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
4433 struct ipr_ioa_cfg *ioa_cfg;
4437 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4439 dev_err(&ioa_cfg->pdev->dev,
4440 "Adapter being reset as a result of error recovery.\n");
4442 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4443 ioa_cfg->sdt_state = GET_DUMP;
4445 rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4451 static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
4455 spin_lock_irq(cmd->device->host->host_lock);
4456 rc = __ipr_eh_host_reset(cmd);
4457 spin_unlock_irq(cmd->device->host->host_lock);
4463 * ipr_device_reset - Reset the device
4464 * @ioa_cfg: ioa config struct
4465 * @res: resource entry struct
4467 * This function issues a device reset to the affected device.
4468 * If the device is a SCSI device, a LUN reset will be sent
4469 * to the device first. If that does not work, a target reset
4470 * will be sent. If the device is a SATA device, a PHY reset will
4474 * 0 on success / non-zero on failure
4476 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4477 struct ipr_resource_entry *res)
4479 struct ipr_cmnd *ipr_cmd;
4480 struct ipr_ioarcb *ioarcb;
4481 struct ipr_cmd_pkt *cmd_pkt;
4482 struct ipr_ioarcb_ata_regs *regs;
4486 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4487 ioarcb = &ipr_cmd->ioarcb;
4488 cmd_pkt = &ioarcb->cmd_pkt;
4490 if (ipr_cmd->ioa_cfg->sis64) {
4491 regs = &ipr_cmd->i.ata_ioadl.regs;
4492 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4494 regs = &ioarcb->u.add_data.u.regs;
4496 ioarcb->res_handle = res->res_handle;
4497 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4498 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4499 if (ipr_is_gata(res)) {
4500 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
4501 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
4502 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4505 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4506 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4507 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4508 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET)
4509 memcpy(&res->sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
4510 sizeof(struct ipr_ioasa_gata));
4513 return (IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0);
4517 * ipr_sata_reset - Reset the SATA port
4518 * @link: SATA link to reset
4519 * @classes: class of the attached device
4521 * This function issues a SATA phy reset to the affected ATA link.
4524 * 0 on success / non-zero on failure
4526 static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
4527 unsigned long deadline)
4529 struct ipr_sata_port *sata_port = link->ap->private_data;
4530 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4531 struct ipr_resource_entry *res;
4532 unsigned long lock_flags = 0;
4536 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4537 while(ioa_cfg->in_reset_reload) {
4538 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4539 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4540 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4543 res = sata_port->res;
4545 rc = ipr_device_reset(ioa_cfg, res);
4546 *classes = res->ata_class;
4549 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4555 * ipr_eh_dev_reset - Reset the device
4556 * @scsi_cmd: scsi command struct
4558 * This function issues a device reset to the affected device.
4559 * A LUN reset will be sent to the device first. If that does
4560 * not work, a target reset will be sent.
4565 static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
4567 struct ipr_cmnd *ipr_cmd;
4568 struct ipr_ioa_cfg *ioa_cfg;
4569 struct ipr_resource_entry *res;
4570 struct ata_port *ap;
4574 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4575 res = scsi_cmd->device->hostdata;
4581 * If we are currently going through reset/reload, return failed. This will force the
4582 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
4585 if (ioa_cfg->in_reset_reload)
4587 if (ioa_cfg->ioa_is_dead)
4590 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4591 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
4592 if (ipr_cmd->scsi_cmd)
4593 ipr_cmd->done = ipr_scsi_eh_done;
4595 ipr_cmd->done = ipr_sata_eh_done;
4596 if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
4597 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
4598 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
4603 res->resetting_device = 1;
4604 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
4606 if (ipr_is_gata(res) && res->sata_port) {
4607 ap = res->sata_port->ap;
4608 spin_unlock_irq(scsi_cmd->device->host->host_lock);
4609 ata_std_error_handler(ap);
4610 spin_lock_irq(scsi_cmd->device->host->host_lock);
4612 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4613 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
4619 rc = ipr_device_reset(ioa_cfg, res);
4620 res->resetting_device = 0;
4623 return (rc ? FAILED : SUCCESS);
4626 static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
4630 spin_lock_irq(cmd->device->host->host_lock);
4631 rc = __ipr_eh_dev_reset(cmd);
4632 spin_unlock_irq(cmd->device->host->host_lock);
4638 * ipr_bus_reset_done - Op done function for bus reset.
4639 * @ipr_cmd: ipr command struct
4641 * This function is the op done function for a bus reset
4646 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
4648 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4649 struct ipr_resource_entry *res;
4652 if (!ioa_cfg->sis64)
4653 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4654 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
4655 scsi_report_bus_reset(ioa_cfg->host, res->bus);
4661 * If abort has not completed, indicate the reset has, else call the
4662 * abort's done function to wake the sleeping eh thread
4664 if (ipr_cmd->sibling->sibling)
4665 ipr_cmd->sibling->sibling = NULL;
4667 ipr_cmd->sibling->done(ipr_cmd->sibling);
4669 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4674 * ipr_abort_timeout - An abort task has timed out
4675 * @ipr_cmd: ipr command struct
4677 * This function handles when an abort task times out. If this
4678 * happens we issue a bus reset since we have resources tied
4679 * up that must be freed before returning to the midlayer.
4684 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
4686 struct ipr_cmnd *reset_cmd;
4687 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
4688 struct ipr_cmd_pkt *cmd_pkt;
4689 unsigned long lock_flags = 0;
4692 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4693 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
4694 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4698 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
4699 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4700 ipr_cmd->sibling = reset_cmd;
4701 reset_cmd->sibling = ipr_cmd;
4702 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
4703 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
4704 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4705 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4706 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
4708 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4709 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4714 * ipr_cancel_op - Cancel specified op
4715 * @scsi_cmd: scsi command struct
4717 * This function cancels specified op.
4722 static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
4724 struct ipr_cmnd *ipr_cmd;
4725 struct ipr_ioa_cfg *ioa_cfg;
4726 struct ipr_resource_entry *res;
4727 struct ipr_cmd_pkt *cmd_pkt;
4732 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
4733 res = scsi_cmd->device->hostdata;
4735 /* If we are currently going through reset/reload, return failed.
4736 * This will force the mid-layer to call ipr_eh_host_reset,
4737 * which will then go to sleep and wait for the reset to complete
4739 if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
4741 if (!res || !ipr_is_gscsi(res))
4744 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
4745 if (ipr_cmd->scsi_cmd == scsi_cmd) {
4746 ipr_cmd->done = ipr_scsi_eh_done;
4755 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4756 ipr_cmd->ioarcb.res_handle = res->res_handle;
4757 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
4758 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4759 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
4760 ipr_cmd->u.sdev = scsi_cmd->device;
4762 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
4764 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
4765 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4768 * If the abort task timed out and we sent a bus reset, we will get
4769 * one the following responses to the abort
4771 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
4776 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
4777 if (!ipr_is_naca_model(res))
4778 res->needs_sync_complete = 1;
4781 return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
4785 * ipr_eh_abort - Abort a single op
4786 * @scsi_cmd: scsi command struct
4791 static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
4793 unsigned long flags;
4798 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
4799 rc = ipr_cancel_op(scsi_cmd);
4800 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
4807 * ipr_handle_other_interrupt - Handle "other" interrupts
4808 * @ioa_cfg: ioa config struct
4809 * @int_reg: interrupt register
4812 * IRQ_NONE / IRQ_HANDLED
4814 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
4815 volatile u32 int_reg)
4817 irqreturn_t rc = IRQ_HANDLED;
4819 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
4820 /* Mask the interrupt */
4821 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
4823 /* Clear the interrupt */
4824 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
4825 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
4827 list_del(&ioa_cfg->reset_cmd->queue);
4828 del_timer(&ioa_cfg->reset_cmd->timer);
4829 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
4831 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
4832 ioa_cfg->ioa_unit_checked = 1;
4834 dev_err(&ioa_cfg->pdev->dev,
4835 "Permanent IOA failure. 0x%08X\n", int_reg);
4837 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4838 ioa_cfg->sdt_state = GET_DUMP;
4840 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
4841 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4848 * ipr_isr_eh - Interrupt service routine error handler
4849 * @ioa_cfg: ioa config struct
4850 * @msg: message to log
4855 static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg)
4857 ioa_cfg->errors_logged++;
4858 dev_err(&ioa_cfg->pdev->dev, "%s\n", msg);
4860 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4861 ioa_cfg->sdt_state = GET_DUMP;
4863 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
4867 * ipr_isr - Interrupt service routine
4869 * @devp: pointer to ioa config struct
4872 * IRQ_NONE / IRQ_HANDLED
4874 static irqreturn_t ipr_isr(int irq, void *devp)
4876 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
4877 unsigned long lock_flags = 0;
4878 volatile u32 int_reg, int_mask_reg;
4882 struct ipr_cmnd *ipr_cmd;
4883 irqreturn_t rc = IRQ_NONE;
4885 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4887 /* If interrupts are disabled, ignore the interrupt */
4888 if (!ioa_cfg->allow_interrupts) {
4889 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4893 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
4894 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32) & ~int_mask_reg;
4896 /* If an interrupt on the adapter did not occur, ignore it.
4897 * Or in the case of SIS 64, check for a stage change interrupt.
4899 if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
4900 if (ioa_cfg->sis64) {
4901 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
4902 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4903 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
4905 /* clear stage change */
4906 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
4907 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
4908 list_del(&ioa_cfg->reset_cmd->queue);
4909 del_timer(&ioa_cfg->reset_cmd->timer);
4910 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
4911 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4916 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4923 while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
4924 ioa_cfg->toggle_bit) {
4926 cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
4927 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
4929 if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
4930 ipr_isr_eh(ioa_cfg, "Invalid response handle from IOA");
4931 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4935 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
4937 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4939 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
4941 list_del(&ipr_cmd->queue);
4942 del_timer(&ipr_cmd->timer);
4943 ipr_cmd->done(ipr_cmd);
4947 if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
4948 ioa_cfg->hrrq_curr++;
4950 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
4951 ioa_cfg->toggle_bit ^= 1u;
4955 if (ipr_cmd != NULL) {
4956 /* Clear the PCI interrupt */
4958 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
4959 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32) & ~int_mask_reg;
4960 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
4961 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
4963 if (int_reg & IPR_PCII_HRRQ_UPDATED) {
4964 ipr_isr_eh(ioa_cfg, "Error clearing HRRQ");
4965 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4973 if (unlikely(rc == IRQ_NONE))
4974 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
4976 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4981 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
4982 * @ioa_cfg: ioa config struct
4983 * @ipr_cmd: ipr command struct
4986 * 0 on success / -1 on failure
4988 static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
4989 struct ipr_cmnd *ipr_cmd)
4992 struct scatterlist *sg;
4994 u32 ioadl_flags = 0;
4995 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4996 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
4997 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
4999 length = scsi_bufflen(scsi_cmd);
5003 nseg = scsi_dma_map(scsi_cmd);
5005 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5009 ipr_cmd->dma_use_sg = nseg;
5011 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5012 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5013 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5014 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5015 ioadl_flags = IPR_IOADL_FLAGS_READ;
5017 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5018 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5019 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5020 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5023 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5028 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5029 * @ioa_cfg: ioa config struct
5030 * @ipr_cmd: ipr command struct
5033 * 0 on success / -1 on failure
5035 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5036 struct ipr_cmnd *ipr_cmd)
5039 struct scatterlist *sg;
5041 u32 ioadl_flags = 0;
5042 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5043 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5044 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5046 length = scsi_bufflen(scsi_cmd);
5050 nseg = scsi_dma_map(scsi_cmd);
5052 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5056 ipr_cmd->dma_use_sg = nseg;
5058 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5059 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5060 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5061 ioarcb->data_transfer_length = cpu_to_be32(length);
5063 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5064 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5065 ioadl_flags = IPR_IOADL_FLAGS_READ;
5066 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5067 ioarcb->read_ioadl_len =
5068 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5071 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5072 ioadl = ioarcb->u.add_data.u.ioadl;
5073 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5074 offsetof(struct ipr_ioarcb, u.add_data));
5075 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5078 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5079 ioadl[i].flags_and_data_len =
5080 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5081 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5084 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5089 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5090 * @scsi_cmd: scsi command struct
5095 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
5098 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
5100 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
5102 case MSG_SIMPLE_TAG:
5103 rc = IPR_FLAGS_LO_SIMPLE_TASK;
5106 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
5108 case MSG_ORDERED_TAG:
5109 rc = IPR_FLAGS_LO_ORDERED_TASK;
5118 * ipr_erp_done - Process completion of ERP for a device
5119 * @ipr_cmd: ipr command struct
5121 * This function copies the sense buffer into the scsi_cmd
5122 * struct and pushes the scsi_done function.
5127 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5129 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5130 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5131 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5132 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5134 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5135 scsi_cmd->result |= (DID_ERROR << 16);
5136 scmd_printk(KERN_ERR, scsi_cmd,
5137 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
5139 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5140 SCSI_SENSE_BUFFERSIZE);
5144 if (!ipr_is_naca_model(res))
5145 res->needs_sync_complete = 1;
5148 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5149 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5150 scsi_cmd->scsi_done(scsi_cmd);
5154 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5155 * @ipr_cmd: ipr command struct
5160 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5162 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5163 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
5164 dma_addr_t dma_addr = ipr_cmd->dma_addr;
5166 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
5167 ioarcb->data_transfer_length = 0;
5168 ioarcb->read_data_transfer_length = 0;
5169 ioarcb->ioadl_len = 0;
5170 ioarcb->read_ioadl_len = 0;
5172 ioasa->residual_data_len = 0;
5174 if (ipr_cmd->ioa_cfg->sis64)
5175 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5176 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5178 ioarcb->write_ioadl_addr =
5179 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5180 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5185 * ipr_erp_request_sense - Send request sense to a device
5186 * @ipr_cmd: ipr command struct
5188 * This function sends a request sense to a device as a result
5189 * of a check condition.
5194 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5196 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5197 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5199 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5200 ipr_erp_done(ipr_cmd);
5204 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5206 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5207 cmd_pkt->cdb[0] = REQUEST_SENSE;
5208 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5209 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5210 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5211 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5213 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5214 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
5216 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5217 IPR_REQUEST_SENSE_TIMEOUT * 2);
5221 * ipr_erp_cancel_all - Send cancel all to a device
5222 * @ipr_cmd: ipr command struct
5224 * This function sends a cancel all to a device to clear the
5225 * queue. If we are running TCQ on the device, QERR is set to 1,
5226 * which means all outstanding ops have been dropped on the floor.
5227 * Cancel all will return them to us.
5232 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5234 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5235 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5236 struct ipr_cmd_pkt *cmd_pkt;
5240 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5242 if (!scsi_get_tag_type(scsi_cmd->device)) {
5243 ipr_erp_request_sense(ipr_cmd);
5247 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5248 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5249 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5251 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5252 IPR_CANCEL_ALL_TIMEOUT);
5256 * ipr_dump_ioasa - Dump contents of IOASA
5257 * @ioa_cfg: ioa config struct
5258 * @ipr_cmd: ipr command struct
5259 * @res: resource entry struct
5261 * This function is invoked by the interrupt handler when ops
5262 * fail. It will log the IOASA if appropriate. Only called
5268 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
5269 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
5273 u32 ioasc, fd_ioasc;
5274 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
5275 __be32 *ioasa_data = (__be32 *)ioasa;
5278 ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
5279 fd_ioasc = be32_to_cpu(ioasa->fd_ioasc) & IPR_IOASC_IOASC_MASK;
5284 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5287 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5288 error_index = ipr_get_error(fd_ioasc);
5290 error_index = ipr_get_error(ioasc);
5292 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5293 /* Don't log an error if the IOA already logged one */
5294 if (ioasa->ilid != 0)
5297 if (!ipr_is_gscsi(res))
5300 if (ipr_error_table[error_index].log_ioasa == 0)
5304 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
5306 if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
5307 data_len = sizeof(struct ipr_ioasa);
5309 data_len = be16_to_cpu(ioasa->ret_stat_len);
5311 ipr_err("IOASA Dump:\n");
5313 for (i = 0; i < data_len / 4; i += 4) {
5314 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5315 be32_to_cpu(ioasa_data[i]),
5316 be32_to_cpu(ioasa_data[i+1]),
5317 be32_to_cpu(ioasa_data[i+2]),
5318 be32_to_cpu(ioasa_data[i+3]));
5323 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5325 * @sense_buf: sense data buffer
5330 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5333 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5334 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
5335 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
5336 u32 ioasc = be32_to_cpu(ioasa->ioasc);
5338 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5340 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5343 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5345 if (ipr_is_vset_device(res) &&
5346 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5347 ioasa->u.vset.failing_lba_hi != 0) {
5348 sense_buf[0] = 0x72;
5349 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5350 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5351 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5355 sense_buf[9] = 0x0A;
5356 sense_buf[10] = 0x80;
5358 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5360 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5361 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5362 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5363 sense_buf[15] = failing_lba & 0x000000ff;
5365 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5367 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5368 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5369 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
5370 sense_buf[19] = failing_lba & 0x000000ff;
5372 sense_buf[0] = 0x70;
5373 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
5374 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
5375 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
5377 /* Illegal request */
5378 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
5379 (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
5380 sense_buf[7] = 10; /* additional length */
5382 /* IOARCB was in error */
5383 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
5384 sense_buf[15] = 0xC0;
5385 else /* Parameter data was invalid */
5386 sense_buf[15] = 0x80;
5389 ((IPR_FIELD_POINTER_MASK &
5390 be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
5392 (IPR_FIELD_POINTER_MASK &
5393 be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
5395 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
5396 if (ipr_is_vset_device(res))
5397 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5399 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
5401 sense_buf[0] |= 0x80; /* Or in the Valid bit */
5402 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
5403 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
5404 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
5405 sense_buf[6] = failing_lba & 0x000000ff;
5408 sense_buf[7] = 6; /* additional length */
5414 * ipr_get_autosense - Copy autosense data to sense buffer
5415 * @ipr_cmd: ipr command struct
5417 * This function copies the autosense buffer to the buffer
5418 * in the scsi_cmd, if there is autosense available.
5421 * 1 if autosense was available / 0 if not
5423 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
5425 struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
5427 if ((be32_to_cpu(ioasa->ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
5430 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
5431 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
5432 SCSI_SENSE_BUFFERSIZE));
5437 * ipr_erp_start - Process an error response for a SCSI op
5438 * @ioa_cfg: ioa config struct
5439 * @ipr_cmd: ipr command struct
5441 * This function determines whether or not to initiate ERP
5442 * on the affected device.
5447 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
5448 struct ipr_cmnd *ipr_cmd)
5450 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5451 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5452 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5453 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
5456 ipr_scsi_eh_done(ipr_cmd);
5460 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
5461 ipr_gen_sense(ipr_cmd);
5463 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5465 switch (masked_ioasc) {
5466 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
5467 if (ipr_is_naca_model(res))
5468 scsi_cmd->result |= (DID_ABORT << 16);
5470 scsi_cmd->result |= (DID_IMM_RETRY << 16);
5472 case IPR_IOASC_IR_RESOURCE_HANDLE:
5473 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
5474 scsi_cmd->result |= (DID_NO_CONNECT << 16);
5476 case IPR_IOASC_HW_SEL_TIMEOUT:
5477 scsi_cmd->result |= (DID_NO_CONNECT << 16);
5478 if (!ipr_is_naca_model(res))
5479 res->needs_sync_complete = 1;
5481 case IPR_IOASC_SYNC_REQUIRED:
5483 res->needs_sync_complete = 1;
5484 scsi_cmd->result |= (DID_IMM_RETRY << 16);
5486 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
5487 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
5488 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
5490 case IPR_IOASC_BUS_WAS_RESET:
5491 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
5493 * Report the bus reset and ask for a retry. The device
5494 * will give CC/UA the next command.
5496 if (!res->resetting_device)
5497 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
5498 scsi_cmd->result |= (DID_ERROR << 16);
5499 if (!ipr_is_naca_model(res))
5500 res->needs_sync_complete = 1;
5502 case IPR_IOASC_HW_DEV_BUS_STATUS:
5503 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
5504 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
5505 if (!ipr_get_autosense(ipr_cmd)) {
5506 if (!ipr_is_naca_model(res)) {
5507 ipr_erp_cancel_all(ipr_cmd);
5512 if (!ipr_is_naca_model(res))
5513 res->needs_sync_complete = 1;
5515 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
5518 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5519 scsi_cmd->result |= (DID_ERROR << 16);
5520 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
5521 res->needs_sync_complete = 1;
5525 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5526 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5527 scsi_cmd->scsi_done(scsi_cmd);
5531 * ipr_scsi_done - mid-layer done function
5532 * @ipr_cmd: ipr command struct
5534 * This function is invoked by the interrupt handler for
5535 * ops generated by the SCSI mid-layer
5540 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
5542 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5543 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5544 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5546 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->ioasa.residual_data_len));
5548 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
5549 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5550 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5551 scsi_cmd->scsi_done(scsi_cmd);
5553 ipr_erp_start(ioa_cfg, ipr_cmd);
5557 * ipr_queuecommand - Queue a mid-layer request
5558 * @scsi_cmd: scsi command struct
5559 * @done: done function
5561 * This function queues a request generated by the mid-layer.
5565 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
5566 * SCSI_MLQUEUE_HOST_BUSY if host is busy
5568 static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
5569 void (*done) (struct scsi_cmnd *))
5571 struct ipr_ioa_cfg *ioa_cfg;
5572 struct ipr_resource_entry *res;
5573 struct ipr_ioarcb *ioarcb;
5574 struct ipr_cmnd *ipr_cmd;
5577 scsi_cmd->scsi_done = done;
5578 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
5579 res = scsi_cmd->device->hostdata;
5580 scsi_cmd->result = (DID_OK << 16);
5583 * We are currently blocking all devices due to a host reset
5584 * We have told the host to stop giving us new requests, but
5585 * ERP ops don't count. FIXME
5587 if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
5588 return SCSI_MLQUEUE_HOST_BUSY;
5591 * FIXME - Create scsi_set_host_offline interface
5592 * and the ioa_is_dead check can be removed
5594 if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
5595 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
5596 scsi_cmd->result = (DID_NO_CONNECT << 16);
5597 scsi_cmd->scsi_done(scsi_cmd);
5601 if (ipr_is_gata(res) && res->sata_port)
5602 return ata_sas_queuecmd(scsi_cmd, done, res->sata_port->ap);
5604 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5605 ioarcb = &ipr_cmd->ioarcb;
5606 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5608 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
5609 ipr_cmd->scsi_cmd = scsi_cmd;
5610 ioarcb->res_handle = res->res_handle;
5611 ipr_cmd->done = ipr_scsi_done;
5612 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
5614 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
5615 if (scsi_cmd->underflow == 0)
5616 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5618 if (res->needs_sync_complete) {
5619 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
5620 res->needs_sync_complete = 0;
5623 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
5624 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
5625 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
5626 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
5629 if (scsi_cmd->cmnd[0] >= 0xC0 &&
5630 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
5631 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
5633 if (likely(rc == 0)) {
5635 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
5637 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
5640 if (likely(rc == 0)) {
5642 ipr_send_command(ipr_cmd);
5644 list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5645 return SCSI_MLQUEUE_HOST_BUSY;
5652 * ipr_ioctl - IOCTL handler
5653 * @sdev: scsi device struct
5658 * 0 on success / other on failure
5660 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
5662 struct ipr_resource_entry *res;
5664 res = (struct ipr_resource_entry *)sdev->hostdata;
5665 if (res && ipr_is_gata(res)) {
5666 if (cmd == HDIO_GET_IDENTITY)
5668 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
5675 * ipr_info - Get information about the card/driver
5676 * @scsi_host: scsi host struct
5679 * pointer to buffer with description string
5681 static const char * ipr_ioa_info(struct Scsi_Host *host)
5683 static char buffer[512];
5684 struct ipr_ioa_cfg *ioa_cfg;
5685 unsigned long lock_flags = 0;
5687 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
5689 spin_lock_irqsave(host->host_lock, lock_flags);
5690 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
5691 spin_unlock_irqrestore(host->host_lock, lock_flags);
5696 static struct scsi_host_template driver_template = {
5697 .module = THIS_MODULE,
5699 .info = ipr_ioa_info,
5701 .queuecommand = ipr_queuecommand,
5702 .eh_abort_handler = ipr_eh_abort,
5703 .eh_device_reset_handler = ipr_eh_dev_reset,
5704 .eh_host_reset_handler = ipr_eh_host_reset,
5705 .slave_alloc = ipr_slave_alloc,
5706 .slave_configure = ipr_slave_configure,
5707 .slave_destroy = ipr_slave_destroy,
5708 .target_alloc = ipr_target_alloc,
5709 .target_destroy = ipr_target_destroy,
5710 .change_queue_depth = ipr_change_queue_depth,
5711 .change_queue_type = ipr_change_queue_type,
5712 .bios_param = ipr_biosparam,
5713 .can_queue = IPR_MAX_COMMANDS,
5715 .sg_tablesize = IPR_MAX_SGLIST,
5716 .max_sectors = IPR_IOA_MAX_SECTORS,
5717 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
5718 .use_clustering = ENABLE_CLUSTERING,
5719 .shost_attrs = ipr_ioa_attrs,
5720 .sdev_attrs = ipr_dev_attrs,
5721 .proc_name = IPR_NAME
5725 * ipr_ata_phy_reset - libata phy_reset handler
5726 * @ap: ata port to reset
5729 static void ipr_ata_phy_reset(struct ata_port *ap)
5731 unsigned long flags;
5732 struct ipr_sata_port *sata_port = ap->private_data;
5733 struct ipr_resource_entry *res = sata_port->res;
5734 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5738 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5739 while(ioa_cfg->in_reset_reload) {
5740 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5741 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5742 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5745 if (!ioa_cfg->allow_cmds)
5748 rc = ipr_device_reset(ioa_cfg, res);
5751 ata_port_disable(ap);
5755 ap->link.device[0].class = res->ata_class;
5756 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
5757 ata_port_disable(ap);
5760 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5765 * ipr_ata_post_internal - Cleanup after an internal command
5766 * @qc: ATA queued command
5771 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
5773 struct ipr_sata_port *sata_port = qc->ap->private_data;
5774 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5775 struct ipr_cmnd *ipr_cmd;
5776 unsigned long flags;
5778 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5779 while(ioa_cfg->in_reset_reload) {
5780 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5781 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
5782 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
5785 list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
5786 if (ipr_cmd->qc == qc) {
5787 ipr_device_reset(ioa_cfg, sata_port->res);
5791 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
5795 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
5796 * @regs: destination
5797 * @tf: source ATA taskfile
5802 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
5803 struct ata_taskfile *tf)
5805 regs->feature = tf->feature;
5806 regs->nsect = tf->nsect;
5807 regs->lbal = tf->lbal;
5808 regs->lbam = tf->lbam;
5809 regs->lbah = tf->lbah;
5810 regs->device = tf->device;
5811 regs->command = tf->command;
5812 regs->hob_feature = tf->hob_feature;
5813 regs->hob_nsect = tf->hob_nsect;
5814 regs->hob_lbal = tf->hob_lbal;
5815 regs->hob_lbam = tf->hob_lbam;
5816 regs->hob_lbah = tf->hob_lbah;
5817 regs->ctl = tf->ctl;
5821 * ipr_sata_done - done function for SATA commands
5822 * @ipr_cmd: ipr command struct
5824 * This function is invoked by the interrupt handler for
5825 * ops generated by the SCSI mid-layer to SATA devices
5830 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
5832 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5833 struct ata_queued_cmd *qc = ipr_cmd->qc;
5834 struct ipr_sata_port *sata_port = qc->ap->private_data;
5835 struct ipr_resource_entry *res = sata_port->res;
5836 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5838 memcpy(&sata_port->ioasa, &ipr_cmd->ioasa.u.gata,
5839 sizeof(struct ipr_ioasa_gata));
5840 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
5842 if (be32_to_cpu(ipr_cmd->ioasa.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
5843 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
5845 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
5846 qc->err_mask |= __ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5848 qc->err_mask |= ac_err_mask(ipr_cmd->ioasa.u.gata.status);
5849 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
5850 ata_qc_complete(qc);
5854 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
5855 * @ipr_cmd: ipr command struct
5856 * @qc: ATA queued command
5859 static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
5860 struct ata_queued_cmd *qc)
5862 u32 ioadl_flags = 0;
5863 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5864 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
5865 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
5866 int len = qc->nbytes;
5867 struct scatterlist *sg;
5869 dma_addr_t dma_addr = ipr_cmd->dma_addr;
5874 if (qc->dma_dir == DMA_TO_DEVICE) {
5875 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5876 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5877 } else if (qc->dma_dir == DMA_FROM_DEVICE)
5878 ioadl_flags = IPR_IOADL_FLAGS_READ;
5880 ioarcb->data_transfer_length = cpu_to_be32(len);
5882 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
5883 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5884 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl));
5886 for_each_sg(qc->sg, sg, qc->n_elem, si) {
5887 ioadl64->flags = cpu_to_be32(ioadl_flags);
5888 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
5889 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
5891 last_ioadl64 = ioadl64;
5895 if (likely(last_ioadl64))
5896 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5900 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
5901 * @ipr_cmd: ipr command struct
5902 * @qc: ATA queued command
5905 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
5906 struct ata_queued_cmd *qc)
5908 u32 ioadl_flags = 0;
5909 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5910 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5911 struct ipr_ioadl_desc *last_ioadl = NULL;
5912 int len = qc->nbytes;
5913 struct scatterlist *sg;
5919 if (qc->dma_dir == DMA_TO_DEVICE) {
5920 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5921 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5922 ioarcb->data_transfer_length = cpu_to_be32(len);
5924 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5925 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
5926 ioadl_flags = IPR_IOADL_FLAGS_READ;
5927 ioarcb->read_data_transfer_length = cpu_to_be32(len);
5928 ioarcb->read_ioadl_len =
5929 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5932 for_each_sg(qc->sg, sg, qc->n_elem, si) {
5933 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5934 ioadl->address = cpu_to_be32(sg_dma_address(sg));
5940 if (likely(last_ioadl))
5941 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5945 * ipr_qc_issue - Issue a SATA qc to a device
5946 * @qc: queued command
5951 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
5953 struct ata_port *ap = qc->ap;
5954 struct ipr_sata_port *sata_port = ap->private_data;
5955 struct ipr_resource_entry *res = sata_port->res;
5956 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
5957 struct ipr_cmnd *ipr_cmd;
5958 struct ipr_ioarcb *ioarcb;
5959 struct ipr_ioarcb_ata_regs *regs;
5961 if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
5962 return AC_ERR_SYSTEM;
5964 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5965 ioarcb = &ipr_cmd->ioarcb;
5967 if (ioa_cfg->sis64) {
5968 regs = &ipr_cmd->i.ata_ioadl.regs;
5969 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
5971 regs = &ioarcb->u.add_data.u.regs;
5973 memset(regs, 0, sizeof(*regs));
5974 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
5976 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
5978 ipr_cmd->done = ipr_sata_done;
5979 ipr_cmd->ioarcb.res_handle = res->res_handle;
5980 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
5981 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
5982 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5983 ipr_cmd->dma_use_sg = qc->n_elem;
5986 ipr_build_ata_ioadl64(ipr_cmd, qc);
5988 ipr_build_ata_ioadl(ipr_cmd, qc);
5990 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
5991 ipr_copy_sata_tf(regs, &qc->tf);
5992 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
5993 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
5995 switch (qc->tf.protocol) {
5996 case ATA_PROT_NODATA:
6001 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6004 case ATAPI_PROT_PIO:
6005 case ATAPI_PROT_NODATA:
6006 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6009 case ATAPI_PROT_DMA:
6010 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6011 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6016 return AC_ERR_INVALID;
6021 ipr_send_command(ipr_cmd);
6027 * ipr_qc_fill_rtf - Read result TF
6028 * @qc: ATA queued command
6033 static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6035 struct ipr_sata_port *sata_port = qc->ap->private_data;
6036 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6037 struct ata_taskfile *tf = &qc->result_tf;
6039 tf->feature = g->error;
6040 tf->nsect = g->nsect;
6044 tf->device = g->device;
6045 tf->command = g->status;
6046 tf->hob_nsect = g->hob_nsect;
6047 tf->hob_lbal = g->hob_lbal;
6048 tf->hob_lbam = g->hob_lbam;
6049 tf->hob_lbah = g->hob_lbah;
6050 tf->ctl = g->alt_status;
6055 static struct ata_port_operations ipr_sata_ops = {
6056 .phy_reset = ipr_ata_phy_reset,
6057 .hardreset = ipr_sata_reset,
6058 .post_internal_cmd = ipr_ata_post_internal,
6059 .qc_prep = ata_noop_qc_prep,
6060 .qc_issue = ipr_qc_issue,
6061 .qc_fill_rtf = ipr_qc_fill_rtf,
6062 .port_start = ata_sas_port_start,
6063 .port_stop = ata_sas_port_stop
6066 static struct ata_port_info sata_port_info = {
6067 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | ATA_FLAG_SATA_RESET |
6068 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
6069 .pio_mask = 0x10, /* pio4 */
6071 .udma_mask = 0x7f, /* udma0-6 */
6072 .port_ops = &ipr_sata_ops
6075 #ifdef CONFIG_PPC_PSERIES
6076 static const u16 ipr_blocked_processors[] = {
6088 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6089 * @ioa_cfg: ioa cfg struct
6091 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6092 * certain pSeries hardware. This function determines if the given
6093 * adapter is in one of these confgurations or not.
6096 * 1 if adapter is not supported / 0 if adapter is supported
6098 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6102 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6103 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
6104 if (__is_processor(ipr_blocked_processors[i]))
6111 #define ipr_invalid_adapter(ioa_cfg) 0
6115 * ipr_ioa_bringdown_done - IOA bring down completion.
6116 * @ipr_cmd: ipr command struct
6118 * This function processes the completion of an adapter bring down.
6119 * It wakes any reset sleepers.
6124 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6126 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6129 ioa_cfg->in_reset_reload = 0;
6130 ioa_cfg->reset_retries = 0;
6131 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6132 wake_up_all(&ioa_cfg->reset_wait_q);
6134 spin_unlock_irq(ioa_cfg->host->host_lock);
6135 scsi_unblock_requests(ioa_cfg->host);
6136 spin_lock_irq(ioa_cfg->host->host_lock);
6139 return IPR_RC_JOB_RETURN;
6143 * ipr_ioa_reset_done - IOA reset completion.
6144 * @ipr_cmd: ipr command struct
6146 * This function processes the completion of an adapter reset.
6147 * It schedules any necessary mid-layer add/removes and
6148 * wakes any reset sleepers.
6153 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6155 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6156 struct ipr_resource_entry *res;
6157 struct ipr_hostrcb *hostrcb, *temp;
6161 ioa_cfg->in_reset_reload = 0;
6162 ioa_cfg->allow_cmds = 1;
6163 ioa_cfg->reset_cmd = NULL;
6164 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
6166 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6167 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
6172 schedule_work(&ioa_cfg->work_q);
6174 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6175 list_del(&hostrcb->queue);
6176 if (i++ < IPR_NUM_LOG_HCAMS)
6177 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6179 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6182 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
6183 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6185 ioa_cfg->reset_retries = 0;
6186 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6187 wake_up_all(&ioa_cfg->reset_wait_q);
6189 spin_unlock(ioa_cfg->host->host_lock);
6190 scsi_unblock_requests(ioa_cfg->host);
6191 spin_lock(ioa_cfg->host->host_lock);
6193 if (!ioa_cfg->allow_cmds)
6194 scsi_block_requests(ioa_cfg->host);
6197 return IPR_RC_JOB_RETURN;
6201 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6202 * @supported_dev: supported device struct
6203 * @vpids: vendor product id struct
6208 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6209 struct ipr_std_inq_vpids *vpids)
6211 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6212 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6213 supported_dev->num_records = 1;
6214 supported_dev->data_length =
6215 cpu_to_be16(sizeof(struct ipr_supported_device));
6216 supported_dev->reserved = 0;
6220 * ipr_set_supported_devs - Send Set Supported Devices for a device
6221 * @ipr_cmd: ipr command struct
6223 * This function sends a Set Supported Devices to the adapter
6226 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6228 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6230 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6231 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
6232 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6233 struct ipr_resource_entry *res = ipr_cmd->u.res;
6235 ipr_cmd->job_step = ipr_ioa_reset_done;
6237 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
6238 if (!ipr_is_scsi_disk(res))
6241 ipr_cmd->u.res = res;
6242 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
6244 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6245 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6246 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6248 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
6249 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
6250 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
6251 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
6253 ipr_init_ioadl(ipr_cmd,
6254 ioa_cfg->vpd_cbs_dma +
6255 offsetof(struct ipr_misc_cbs, supp_dev),
6256 sizeof(struct ipr_supported_device),
6257 IPR_IOADL_FLAGS_WRITE_LAST);
6259 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6260 IPR_SET_SUP_DEVICE_TIMEOUT);
6262 if (!ioa_cfg->sis64)
6263 ipr_cmd->job_step = ipr_set_supported_devs;
6264 return IPR_RC_JOB_RETURN;
6267 return IPR_RC_JOB_CONTINUE;
6271 * ipr_get_mode_page - Locate specified mode page
6272 * @mode_pages: mode page buffer
6273 * @page_code: page code to find
6274 * @len: minimum required length for mode page
6277 * pointer to mode page / NULL on failure
6279 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
6280 u32 page_code, u32 len)
6282 struct ipr_mode_page_hdr *mode_hdr;
6286 if (!mode_pages || (mode_pages->hdr.length == 0))
6289 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
6290 mode_hdr = (struct ipr_mode_page_hdr *)
6291 (mode_pages->data + mode_pages->hdr.block_desc_len);
6294 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
6295 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
6299 page_length = (sizeof(struct ipr_mode_page_hdr) +
6300 mode_hdr->page_length);
6301 length -= page_length;
6302 mode_hdr = (struct ipr_mode_page_hdr *)
6303 ((unsigned long)mode_hdr + page_length);
6310 * ipr_check_term_power - Check for term power errors
6311 * @ioa_cfg: ioa config struct
6312 * @mode_pages: IOAFP mode pages buffer
6314 * Check the IOAFP's mode page 28 for term power errors
6319 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
6320 struct ipr_mode_pages *mode_pages)
6324 struct ipr_dev_bus_entry *bus;
6325 struct ipr_mode_page28 *mode_page;
6327 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6328 sizeof(struct ipr_mode_page28));
6330 entry_length = mode_page->entry_length;
6332 bus = mode_page->bus;
6334 for (i = 0; i < mode_page->num_entries; i++) {
6335 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
6336 dev_err(&ioa_cfg->pdev->dev,
6337 "Term power is absent on scsi bus %d\n",
6341 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
6346 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
6347 * @ioa_cfg: ioa config struct
6349 * Looks through the config table checking for SES devices. If
6350 * the SES device is in the SES table indicating a maximum SCSI
6351 * bus speed, the speed is limited for the bus.
6356 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
6361 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
6362 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
6363 ioa_cfg->bus_attr[i].bus_width);
6365 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
6366 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
6371 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
6372 * @ioa_cfg: ioa config struct
6373 * @mode_pages: mode page 28 buffer
6375 * Updates mode page 28 based on driver configuration
6380 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
6381 struct ipr_mode_pages *mode_pages)
6383 int i, entry_length;
6384 struct ipr_dev_bus_entry *bus;
6385 struct ipr_bus_attributes *bus_attr;
6386 struct ipr_mode_page28 *mode_page;
6388 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6389 sizeof(struct ipr_mode_page28));
6391 entry_length = mode_page->entry_length;
6393 /* Loop for each device bus entry */
6394 for (i = 0, bus = mode_page->bus;
6395 i < mode_page->num_entries;
6396 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
6397 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
6398 dev_err(&ioa_cfg->pdev->dev,
6399 "Invalid resource address reported: 0x%08X\n",
6400 IPR_GET_PHYS_LOC(bus->res_addr));
6404 bus_attr = &ioa_cfg->bus_attr[i];
6405 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
6406 bus->bus_width = bus_attr->bus_width;
6407 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
6408 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
6409 if (bus_attr->qas_enabled)
6410 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
6412 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
6417 * ipr_build_mode_select - Build a mode select command
6418 * @ipr_cmd: ipr command struct
6419 * @res_handle: resource handle to send command to
6420 * @parm: Byte 2 of Mode Sense command
6421 * @dma_addr: DMA buffer address
6422 * @xfer_len: data transfer length
6427 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
6428 __be32 res_handle, u8 parm,
6429 dma_addr_t dma_addr, u8 xfer_len)
6431 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6433 ioarcb->res_handle = res_handle;
6434 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6435 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6436 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
6437 ioarcb->cmd_pkt.cdb[1] = parm;
6438 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6440 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
6444 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
6445 * @ipr_cmd: ipr command struct
6447 * This function sets up the SCSI bus attributes and sends
6448 * a Mode Select for Page 28 to activate them.
6453 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
6455 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6456 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6460 ipr_scsi_bus_speed_limit(ioa_cfg);
6461 ipr_check_term_power(ioa_cfg, mode_pages);
6462 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
6463 length = mode_pages->hdr.length + 1;
6464 mode_pages->hdr.length = 0;
6466 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6467 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6470 ipr_cmd->job_step = ipr_set_supported_devs;
6471 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6472 struct ipr_resource_entry, queue);
6473 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6476 return IPR_RC_JOB_RETURN;
6480 * ipr_build_mode_sense - Builds a mode sense command
6481 * @ipr_cmd: ipr command struct
6482 * @res: resource entry struct
6483 * @parm: Byte 2 of mode sense command
6484 * @dma_addr: DMA address of mode sense buffer
6485 * @xfer_len: Size of DMA buffer
6490 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
6492 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
6494 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6496 ioarcb->res_handle = res_handle;
6497 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
6498 ioarcb->cmd_pkt.cdb[2] = parm;
6499 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6500 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6502 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
6506 * ipr_reset_cmd_failed - Handle failure of IOA reset command
6507 * @ipr_cmd: ipr command struct
6509 * This function handles the failure of an IOA bringup command.
6514 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
6516 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6517 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
6519 dev_err(&ioa_cfg->pdev->dev,
6520 "0x%02X failed with IOASC: 0x%08X\n",
6521 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
6523 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
6524 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
6525 return IPR_RC_JOB_RETURN;
6529 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
6530 * @ipr_cmd: ipr command struct
6532 * This function handles the failure of a Mode Sense to the IOAFP.
6533 * Some adapters do not handle all mode pages.
6536 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6538 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
6540 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6541 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
6543 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6544 ipr_cmd->job_step = ipr_set_supported_devs;
6545 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
6546 struct ipr_resource_entry, queue);
6547 return IPR_RC_JOB_CONTINUE;
6550 return ipr_reset_cmd_failed(ipr_cmd);
6554 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
6555 * @ipr_cmd: ipr command struct
6557 * This function send a Page 28 mode sense to the IOA to
6558 * retrieve SCSI bus attributes.
6563 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
6565 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6568 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6569 0x28, ioa_cfg->vpd_cbs_dma +
6570 offsetof(struct ipr_misc_cbs, mode_pages),
6571 sizeof(struct ipr_mode_pages));
6573 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
6574 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
6576 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6579 return IPR_RC_JOB_RETURN;
6583 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
6584 * @ipr_cmd: ipr command struct
6586 * This function enables dual IOA RAID support if possible.
6591 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
6593 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6594 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
6595 struct ipr_mode_page24 *mode_page;
6599 mode_page = ipr_get_mode_page(mode_pages, 0x24,
6600 sizeof(struct ipr_mode_page24));
6603 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
6605 length = mode_pages->hdr.length + 1;
6606 mode_pages->hdr.length = 0;
6608 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
6609 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
6612 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6613 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6616 return IPR_RC_JOB_RETURN;
6620 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
6621 * @ipr_cmd: ipr command struct
6623 * This function handles the failure of a Mode Sense to the IOAFP.
6624 * Some adapters do not handle all mode pages.
6627 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6629 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
6631 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
6633 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
6634 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6635 return IPR_RC_JOB_CONTINUE;
6638 return ipr_reset_cmd_failed(ipr_cmd);
6642 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
6643 * @ipr_cmd: ipr command struct
6645 * This function send a mode sense to the IOA to retrieve
6646 * the IOA Advanced Function Control mode page.
6651 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
6653 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6656 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
6657 0x24, ioa_cfg->vpd_cbs_dma +
6658 offsetof(struct ipr_misc_cbs, mode_pages),
6659 sizeof(struct ipr_mode_pages));
6661 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
6662 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
6664 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6667 return IPR_RC_JOB_RETURN;
6671 * ipr_init_res_table - Initialize the resource table
6672 * @ipr_cmd: ipr command struct
6674 * This function looks through the existing resource table, comparing
6675 * it with the config table. This function will take care of old/new
6676 * devices and schedule adding/removing them from the mid-layer
6680 * IPR_RC_JOB_CONTINUE
6682 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
6684 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6685 struct ipr_resource_entry *res, *temp;
6686 struct ipr_config_table_entry_wrapper cfgtew;
6687 int entries, found, flag, i;
6692 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
6694 flag = ioa_cfg->u.cfg_table->hdr.flags;
6696 if (flag & IPR_UCODE_DOWNLOAD_REQ)
6697 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
6699 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
6700 list_move_tail(&res->queue, &old_res);
6703 entries = ioa_cfg->u.cfg_table64->hdr64.num_entries;
6705 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
6707 for (i = 0; i < entries; i++) {
6709 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
6711 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
6714 list_for_each_entry_safe(res, temp, &old_res, queue) {
6715 if (ipr_is_same_device(res, &cfgtew)) {
6716 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
6723 if (list_empty(&ioa_cfg->free_res_q)) {
6724 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
6729 res = list_entry(ioa_cfg->free_res_q.next,
6730 struct ipr_resource_entry, queue);
6731 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
6732 ipr_init_res_entry(res, &cfgtew);
6737 ipr_update_res_entry(res, &cfgtew);
6740 list_for_each_entry_safe(res, temp, &old_res, queue) {
6742 res->del_from_ml = 1;
6743 res->res_handle = IPR_INVALID_RES_HANDLE;
6744 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
6748 list_for_each_entry_safe(res, temp, &old_res, queue) {
6749 ipr_clear_res_target(res);
6750 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
6753 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
6754 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
6756 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
6759 return IPR_RC_JOB_CONTINUE;
6763 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
6764 * @ipr_cmd: ipr command struct
6766 * This function sends a Query IOA Configuration command
6767 * to the adapter to retrieve the IOA configuration table.
6772 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
6774 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6775 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6776 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
6777 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
6780 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
6781 ioa_cfg->dual_raid = 1;
6782 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
6783 ucode_vpd->major_release, ucode_vpd->card_type,
6784 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
6785 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6786 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6788 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
6789 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
6790 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
6792 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
6793 IPR_IOADL_FLAGS_READ_LAST);
6795 ipr_cmd->job_step = ipr_init_res_table;
6797 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6800 return IPR_RC_JOB_RETURN;
6804 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
6805 * @ipr_cmd: ipr command struct
6807 * This utility function sends an inquiry to the adapter.
6812 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
6813 dma_addr_t dma_addr, u8 xfer_len)
6815 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6818 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
6819 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6821 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
6822 ioarcb->cmd_pkt.cdb[1] = flags;
6823 ioarcb->cmd_pkt.cdb[2] = page;
6824 ioarcb->cmd_pkt.cdb[4] = xfer_len;
6826 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
6828 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
6833 * ipr_inquiry_page_supported - Is the given inquiry page supported
6834 * @page0: inquiry page 0 buffer
6837 * This function determines if the specified inquiry page is supported.
6840 * 1 if page is supported / 0 if not
6842 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
6846 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
6847 if (page0->page[i] == page)
6854 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
6855 * @ipr_cmd: ipr command struct
6857 * This function sends a Page 0xD0 inquiry to the adapter
6858 * to retrieve adapter capabilities.
6861 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6863 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
6865 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6866 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
6867 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
6870 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
6871 memset(cap, 0, sizeof(*cap));
6873 if (ipr_inquiry_page_supported(page0, 0xD0)) {
6874 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
6875 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
6876 sizeof(struct ipr_inquiry_cap));
6877 return IPR_RC_JOB_RETURN;
6881 return IPR_RC_JOB_CONTINUE;
6885 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
6886 * @ipr_cmd: ipr command struct
6888 * This function sends a Page 3 inquiry to the adapter
6889 * to retrieve software VPD information.
6892 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6894 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
6896 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6900 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
6902 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
6903 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
6904 sizeof(struct ipr_inquiry_page3));
6907 return IPR_RC_JOB_RETURN;
6911 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
6912 * @ipr_cmd: ipr command struct
6914 * This function sends a Page 0 inquiry to the adapter
6915 * to retrieve supported inquiry pages.
6918 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6920 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
6922 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6927 /* Grab the type out of the VPD and store it away */
6928 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
6930 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
6932 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
6934 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
6935 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
6936 sizeof(struct ipr_inquiry_page0));
6939 return IPR_RC_JOB_RETURN;
6943 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
6944 * @ipr_cmd: ipr command struct
6946 * This function sends a standard inquiry to the adapter.
6951 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
6953 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6956 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
6958 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
6959 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
6960 sizeof(struct ipr_ioa_vpd));
6963 return IPR_RC_JOB_RETURN;
6967 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
6968 * @ipr_cmd: ipr command struct
6970 * This function send an Identify Host Request Response Queue
6971 * command to establish the HRRQ with the adapter.
6976 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
6978 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6979 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6982 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
6984 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
6985 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6987 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6989 ioarcb->cmd_pkt.cdb[1] = 0x1;
6990 ioarcb->cmd_pkt.cdb[2] =
6991 ((u64) ioa_cfg->host_rrq_dma >> 24) & 0xff;
6992 ioarcb->cmd_pkt.cdb[3] =
6993 ((u64) ioa_cfg->host_rrq_dma >> 16) & 0xff;
6994 ioarcb->cmd_pkt.cdb[4] =
6995 ((u64) ioa_cfg->host_rrq_dma >> 8) & 0xff;
6996 ioarcb->cmd_pkt.cdb[5] =
6997 ((u64) ioa_cfg->host_rrq_dma) & 0xff;
6998 ioarcb->cmd_pkt.cdb[7] =
6999 ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
7000 ioarcb->cmd_pkt.cdb[8] =
7001 (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
7003 if (ioa_cfg->sis64) {
7004 ioarcb->cmd_pkt.cdb[10] =
7005 ((u64) ioa_cfg->host_rrq_dma >> 56) & 0xff;
7006 ioarcb->cmd_pkt.cdb[11] =
7007 ((u64) ioa_cfg->host_rrq_dma >> 48) & 0xff;
7008 ioarcb->cmd_pkt.cdb[12] =
7009 ((u64) ioa_cfg->host_rrq_dma >> 40) & 0xff;
7010 ioarcb->cmd_pkt.cdb[13] =
7011 ((u64) ioa_cfg->host_rrq_dma >> 32) & 0xff;
7014 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7016 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7019 return IPR_RC_JOB_RETURN;
7023 * ipr_reset_timer_done - Adapter reset timer function
7024 * @ipr_cmd: ipr command struct
7026 * Description: This function is used in adapter reset processing
7027 * for timing events. If the reset_cmd pointer in the IOA
7028 * config struct is not this adapter's we are doing nested
7029 * resets and fail_all_ops will take care of freeing the
7035 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7037 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7038 unsigned long lock_flags = 0;
7040 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7042 if (ioa_cfg->reset_cmd == ipr_cmd) {
7043 list_del(&ipr_cmd->queue);
7044 ipr_cmd->done(ipr_cmd);
7047 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7051 * ipr_reset_start_timer - Start a timer for adapter reset job
7052 * @ipr_cmd: ipr command struct
7053 * @timeout: timeout value
7055 * Description: This function is used in adapter reset processing
7056 * for timing events. If the reset_cmd pointer in the IOA
7057 * config struct is not this adapter's we are doing nested
7058 * resets and fail_all_ops will take care of freeing the
7064 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7065 unsigned long timeout)
7067 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
7068 ipr_cmd->done = ipr_reset_ioa_job;
7070 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7071 ipr_cmd->timer.expires = jiffies + timeout;
7072 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7073 add_timer(&ipr_cmd->timer);
7077 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7078 * @ioa_cfg: ioa cfg struct
7083 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7085 memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
7087 /* Initialize Host RRQ pointers */
7088 ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
7089 ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
7090 ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
7091 ioa_cfg->toggle_bit = 1;
7093 /* Zero out config table */
7094 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
7098 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7099 * @ipr_cmd: ipr command struct
7102 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7104 static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7106 unsigned long stage, stage_time;
7108 volatile u32 int_reg;
7109 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7112 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7113 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7114 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7116 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7118 /* sanity check the stage_time value */
7119 if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
7120 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7121 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7122 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7124 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7125 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7126 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7127 stage_time = ioa_cfg->transop_timeout;
7128 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7129 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
7130 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7131 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7132 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7133 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7134 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7135 return IPR_RC_JOB_CONTINUE;
7138 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7139 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7140 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7141 ipr_cmd->done = ipr_reset_ioa_job;
7142 add_timer(&ipr_cmd->timer);
7143 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7145 return IPR_RC_JOB_RETURN;
7149 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7150 * @ipr_cmd: ipr command struct
7152 * This function reinitializes some control blocks and
7153 * enables destructive diagnostics on the adapter.
7158 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7160 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7161 volatile u32 int_reg;
7164 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7165 ipr_init_ioa_mem(ioa_cfg);
7167 ioa_cfg->allow_interrupts = 1;
7168 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
7170 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7171 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
7172 ioa_cfg->regs.clr_interrupt_mask_reg32);
7173 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7174 return IPR_RC_JOB_CONTINUE;
7177 /* Enable destructive diagnostics on IOA */
7178 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
7180 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
7182 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_mask_reg);
7184 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7186 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
7188 if (ioa_cfg->sis64) {
7189 ipr_cmd->job_step = ipr_reset_next_stage;
7190 return IPR_RC_JOB_CONTINUE;
7193 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7194 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
7195 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7196 ipr_cmd->done = ipr_reset_ioa_job;
7197 add_timer(&ipr_cmd->timer);
7198 list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
7201 return IPR_RC_JOB_RETURN;
7205 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7206 * @ipr_cmd: ipr command struct
7208 * This function is invoked when an adapter dump has run out
7209 * of processing time.
7212 * IPR_RC_JOB_CONTINUE
7214 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
7216 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7218 if (ioa_cfg->sdt_state == GET_DUMP)
7219 ioa_cfg->sdt_state = ABORT_DUMP;
7221 ipr_cmd->job_step = ipr_reset_alert;
7223 return IPR_RC_JOB_CONTINUE;
7227 * ipr_unit_check_no_data - Log a unit check/no data error log
7228 * @ioa_cfg: ioa config struct
7230 * Logs an error indicating the adapter unit checked, but for some
7231 * reason, we were unable to fetch the unit check buffer.
7236 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
7238 ioa_cfg->errors_logged++;
7239 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
7243 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7244 * @ioa_cfg: ioa config struct
7246 * Fetches the unit check buffer from the adapter by clocking the data
7247 * through the mailbox register.
7252 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
7254 unsigned long mailbox;
7255 struct ipr_hostrcb *hostrcb;
7256 struct ipr_uc_sdt sdt;
7260 mailbox = readl(ioa_cfg->ioa_mailbox);
7262 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
7263 ipr_unit_check_no_data(ioa_cfg);
7267 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
7268 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
7269 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
7271 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
7272 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
7273 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
7274 ipr_unit_check_no_data(ioa_cfg);
7278 /* Find length of the first sdt entry (UC buffer) */
7279 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
7280 length = be32_to_cpu(sdt.entry[0].end_token);
7282 length = (be32_to_cpu(sdt.entry[0].end_token) -
7283 be32_to_cpu(sdt.entry[0].start_token)) &
7284 IPR_FMT2_MBX_ADDR_MASK;
7286 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
7287 struct ipr_hostrcb, queue);
7288 list_del(&hostrcb->queue);
7289 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
7291 rc = ipr_get_ldump_data_section(ioa_cfg,
7292 be32_to_cpu(sdt.entry[0].start_token),
7293 (__be32 *)&hostrcb->hcam,
7294 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
7297 ipr_handle_log_data(ioa_cfg, hostrcb);
7298 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
7299 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
7300 ioa_cfg->sdt_state == GET_DUMP)
7301 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7303 ipr_unit_check_no_data(ioa_cfg);
7305 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
7309 * ipr_reset_restore_cfg_space - Restore PCI config space.
7310 * @ipr_cmd: ipr command struct
7312 * Description: This function restores the saved PCI config space of
7313 * the adapter, fails all outstanding ops back to the callers, and
7314 * fetches the dump/unit check if applicable to this reset.
7317 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7319 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
7321 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7325 ioa_cfg->pdev->state_saved = true;
7326 rc = pci_restore_state(ioa_cfg->pdev);
7328 if (rc != PCIBIOS_SUCCESSFUL) {
7329 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7330 return IPR_RC_JOB_CONTINUE;
7333 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
7334 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7335 return IPR_RC_JOB_CONTINUE;
7338 ipr_fail_all_ops(ioa_cfg);
7340 if (ioa_cfg->ioa_unit_checked) {
7341 ioa_cfg->ioa_unit_checked = 0;
7342 ipr_get_unit_check_buffer(ioa_cfg);
7343 ipr_cmd->job_step = ipr_reset_alert;
7344 ipr_reset_start_timer(ipr_cmd, 0);
7345 return IPR_RC_JOB_RETURN;
7348 if (ioa_cfg->in_ioa_bringdown) {
7349 ipr_cmd->job_step = ipr_ioa_bringdown_done;
7351 ipr_cmd->job_step = ipr_reset_enable_ioa;
7353 if (GET_DUMP == ioa_cfg->sdt_state) {
7354 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
7355 ipr_cmd->job_step = ipr_reset_wait_for_dump;
7356 schedule_work(&ioa_cfg->work_q);
7357 return IPR_RC_JOB_RETURN;
7362 return IPR_RC_JOB_CONTINUE;
7366 * ipr_reset_bist_done - BIST has completed on the adapter.
7367 * @ipr_cmd: ipr command struct
7369 * Description: Unblock config space and resume the reset process.
7372 * IPR_RC_JOB_CONTINUE
7374 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
7377 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
7378 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
7380 return IPR_RC_JOB_CONTINUE;
7384 * ipr_reset_start_bist - Run BIST on the adapter.
7385 * @ipr_cmd: ipr command struct
7387 * Description: This function runs BIST on the adapter, then delays 2 seconds.
7390 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7392 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
7394 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7398 pci_block_user_cfg_access(ioa_cfg->pdev);
7399 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
7401 if (rc != PCIBIOS_SUCCESSFUL) {
7402 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
7403 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
7404 rc = IPR_RC_JOB_CONTINUE;
7406 ipr_cmd->job_step = ipr_reset_bist_done;
7407 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7408 rc = IPR_RC_JOB_RETURN;
7416 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
7417 * @ipr_cmd: ipr command struct
7419 * Description: This clears PCI reset to the adapter and delays two seconds.
7424 static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
7427 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
7428 ipr_cmd->job_step = ipr_reset_bist_done;
7429 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
7431 return IPR_RC_JOB_RETURN;
7435 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
7436 * @ipr_cmd: ipr command struct
7438 * Description: This asserts PCI reset to the adapter.
7443 static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
7445 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7446 struct pci_dev *pdev = ioa_cfg->pdev;
7449 pci_block_user_cfg_access(pdev);
7450 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
7451 ipr_cmd->job_step = ipr_reset_slot_reset_done;
7452 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
7454 return IPR_RC_JOB_RETURN;
7458 * ipr_reset_allowed - Query whether or not IOA can be reset
7459 * @ioa_cfg: ioa config struct
7462 * 0 if reset not allowed / non-zero if reset is allowed
7464 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
7466 volatile u32 temp_reg;
7468 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
7469 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
7473 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
7474 * @ipr_cmd: ipr command struct
7476 * Description: This function waits for adapter permission to run BIST,
7477 * then runs BIST. If the adapter does not give permission after a
7478 * reasonable time, we will reset the adapter anyway. The impact of
7479 * resetting the adapter without warning the adapter is the risk of
7480 * losing the persistent error log on the adapter. If the adapter is
7481 * reset while it is writing to the flash on the adapter, the flash
7482 * segment will have bad ECC and be zeroed.
7485 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7487 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
7489 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7490 int rc = IPR_RC_JOB_RETURN;
7492 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
7493 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
7494 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7496 ipr_cmd->job_step = ioa_cfg->reset;
7497 rc = IPR_RC_JOB_CONTINUE;
7504 * ipr_reset_alert_part2 - Alert the adapter of a pending reset
7505 * @ipr_cmd: ipr command struct
7507 * Description: This function alerts the adapter that it will be reset.
7508 * If memory space is not currently enabled, proceed directly
7509 * to running BIST on the adapter. The timer must always be started
7510 * so we guarantee we do not run BIST from ipr_isr.
7515 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
7517 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7522 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
7524 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
7525 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
7526 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
7527 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
7529 ipr_cmd->job_step = ioa_cfg->reset;
7532 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
7533 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
7536 return IPR_RC_JOB_RETURN;
7540 * ipr_reset_ucode_download_done - Microcode download completion
7541 * @ipr_cmd: ipr command struct
7543 * Description: This function unmaps the microcode download buffer.
7546 * IPR_RC_JOB_CONTINUE
7548 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
7550 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7551 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7553 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
7554 sglist->num_sg, DMA_TO_DEVICE);
7556 ipr_cmd->job_step = ipr_reset_alert;
7557 return IPR_RC_JOB_CONTINUE;
7561 * ipr_reset_ucode_download - Download microcode to the adapter
7562 * @ipr_cmd: ipr command struct
7564 * Description: This function checks to see if it there is microcode
7565 * to download to the adapter. If there is, a download is performed.
7568 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7570 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
7572 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7573 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
7576 ipr_cmd->job_step = ipr_reset_alert;
7579 return IPR_RC_JOB_CONTINUE;
7581 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7582 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7583 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
7584 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
7585 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
7586 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
7587 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
7590 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
7592 ipr_build_ucode_ioadl(ipr_cmd, sglist);
7593 ipr_cmd->job_step = ipr_reset_ucode_download_done;
7595 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7596 IPR_WRITE_BUFFER_TIMEOUT);
7599 return IPR_RC_JOB_RETURN;
7603 * ipr_reset_shutdown_ioa - Shutdown the adapter
7604 * @ipr_cmd: ipr command struct
7606 * Description: This function issues an adapter shutdown of the
7607 * specified type to the specified adapter as part of the
7608 * adapter reset job.
7611 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7613 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
7615 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7616 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
7617 unsigned long timeout;
7618 int rc = IPR_RC_JOB_CONTINUE;
7621 if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
7622 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7623 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7624 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
7625 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
7627 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
7628 timeout = IPR_SHUTDOWN_TIMEOUT;
7629 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
7630 timeout = IPR_INTERNAL_TIMEOUT;
7631 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7632 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
7634 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
7636 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
7638 rc = IPR_RC_JOB_RETURN;
7639 ipr_cmd->job_step = ipr_reset_ucode_download;
7641 ipr_cmd->job_step = ipr_reset_alert;
7648 * ipr_reset_ioa_job - Adapter reset job
7649 * @ipr_cmd: ipr command struct
7651 * Description: This function is the job router for the adapter reset job.
7656 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
7659 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7662 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
7664 if (ioa_cfg->reset_cmd != ipr_cmd) {
7666 * We are doing nested adapter resets and this is
7667 * not the current reset job.
7669 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
7673 if (IPR_IOASC_SENSE_KEY(ioasc)) {
7674 rc = ipr_cmd->job_step_failed(ipr_cmd);
7675 if (rc == IPR_RC_JOB_RETURN)
7679 ipr_reinit_ipr_cmnd(ipr_cmd);
7680 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
7681 rc = ipr_cmd->job_step(ipr_cmd);
7682 } while(rc == IPR_RC_JOB_CONTINUE);
7686 * _ipr_initiate_ioa_reset - Initiate an adapter reset
7687 * @ioa_cfg: ioa config struct
7688 * @job_step: first job step of reset job
7689 * @shutdown_type: shutdown type
7691 * Description: This function will initiate the reset of the given adapter
7692 * starting at the selected job step.
7693 * If the caller needs to wait on the completion of the reset,
7694 * the caller must sleep on the reset_wait_q.
7699 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
7700 int (*job_step) (struct ipr_cmnd *),
7701 enum ipr_shutdown_type shutdown_type)
7703 struct ipr_cmnd *ipr_cmd;
7705 ioa_cfg->in_reset_reload = 1;
7706 ioa_cfg->allow_cmds = 0;
7707 scsi_block_requests(ioa_cfg->host);
7709 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
7710 ioa_cfg->reset_cmd = ipr_cmd;
7711 ipr_cmd->job_step = job_step;
7712 ipr_cmd->u.shutdown_type = shutdown_type;
7714 ipr_reset_ioa_job(ipr_cmd);
7718 * ipr_initiate_ioa_reset - Initiate an adapter reset
7719 * @ioa_cfg: ioa config struct
7720 * @shutdown_type: shutdown type
7722 * Description: This function will initiate the reset of the given adapter.
7723 * If the caller needs to wait on the completion of the reset,
7724 * the caller must sleep on the reset_wait_q.
7729 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
7730 enum ipr_shutdown_type shutdown_type)
7732 if (ioa_cfg->ioa_is_dead)
7735 if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
7736 ioa_cfg->sdt_state = ABORT_DUMP;
7738 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
7739 dev_err(&ioa_cfg->pdev->dev,
7740 "IOA taken offline - error recovery failed\n");
7742 ioa_cfg->reset_retries = 0;
7743 ioa_cfg->ioa_is_dead = 1;
7745 if (ioa_cfg->in_ioa_bringdown) {
7746 ioa_cfg->reset_cmd = NULL;
7747 ioa_cfg->in_reset_reload = 0;
7748 ipr_fail_all_ops(ioa_cfg);
7749 wake_up_all(&ioa_cfg->reset_wait_q);
7751 spin_unlock_irq(ioa_cfg->host->host_lock);
7752 scsi_unblock_requests(ioa_cfg->host);
7753 spin_lock_irq(ioa_cfg->host->host_lock);
7756 ioa_cfg->in_ioa_bringdown = 1;
7757 shutdown_type = IPR_SHUTDOWN_NONE;
7761 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
7766 * ipr_reset_freeze - Hold off all I/O activity
7767 * @ipr_cmd: ipr command struct
7769 * Description: If the PCI slot is frozen, hold off all I/O
7770 * activity; then, as soon as the slot is available again,
7771 * initiate an adapter reset.
7773 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
7775 /* Disallow new interrupts, avoid loop */
7776 ipr_cmd->ioa_cfg->allow_interrupts = 0;
7777 list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
7778 ipr_cmd->done = ipr_reset_ioa_job;
7779 return IPR_RC_JOB_RETURN;
7783 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
7784 * @pdev: PCI device struct
7786 * Description: This routine is called to tell us that the PCI bus
7787 * is down. Can't do anything here, except put the device driver
7788 * into a holding pattern, waiting for the PCI bus to come back.
7790 static void ipr_pci_frozen(struct pci_dev *pdev)
7792 unsigned long flags = 0;
7793 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7795 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
7796 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
7797 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
7801 * ipr_pci_slot_reset - Called when PCI slot has been reset.
7802 * @pdev: PCI device struct
7804 * Description: This routine is called by the pci error recovery
7805 * code after the PCI slot has been reset, just before we
7806 * should resume normal operations.
7808 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
7810 unsigned long flags = 0;
7811 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7813 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
7814 if (ioa_cfg->needs_warm_reset)
7815 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7817 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
7819 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
7820 return PCI_ERS_RESULT_RECOVERED;
7824 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
7825 * @pdev: PCI device struct
7827 * Description: This routine is called when the PCI bus has
7828 * permanently failed.
7830 static void ipr_pci_perm_failure(struct pci_dev *pdev)
7832 unsigned long flags = 0;
7833 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
7835 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
7836 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
7837 ioa_cfg->sdt_state = ABORT_DUMP;
7838 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
7839 ioa_cfg->in_ioa_bringdown = 1;
7840 ioa_cfg->allow_cmds = 0;
7841 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7842 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
7846 * ipr_pci_error_detected - Called when a PCI error is detected.
7847 * @pdev: PCI device struct
7848 * @state: PCI channel state
7850 * Description: Called when a PCI error is detected.
7853 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
7855 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
7856 pci_channel_state_t state)
7859 case pci_channel_io_frozen:
7860 ipr_pci_frozen(pdev);
7861 return PCI_ERS_RESULT_NEED_RESET;
7862 case pci_channel_io_perm_failure:
7863 ipr_pci_perm_failure(pdev);
7864 return PCI_ERS_RESULT_DISCONNECT;
7869 return PCI_ERS_RESULT_NEED_RESET;
7873 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
7874 * @ioa_cfg: ioa cfg struct
7876 * Description: This is the second phase of adapter intialization
7877 * This function takes care of initilizing the adapter to the point
7878 * where it can accept new commands.
7881 * 0 on success / -EIO on failure
7883 static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
7886 unsigned long host_lock_flags = 0;
7889 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7890 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
7891 if (ioa_cfg->needs_hard_reset) {
7892 ioa_cfg->needs_hard_reset = 0;
7893 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7895 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
7898 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7899 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7900 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7902 if (ioa_cfg->ioa_is_dead) {
7904 } else if (ipr_invalid_adapter(ioa_cfg)) {
7908 dev_err(&ioa_cfg->pdev->dev,
7909 "Adapter not supported in this hardware configuration.\n");
7912 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7919 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
7920 * @ioa_cfg: ioa config struct
7925 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
7929 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
7930 if (ioa_cfg->ipr_cmnd_list[i])
7931 pci_pool_free(ioa_cfg->ipr_cmd_pool,
7932 ioa_cfg->ipr_cmnd_list[i],
7933 ioa_cfg->ipr_cmnd_list_dma[i]);
7935 ioa_cfg->ipr_cmnd_list[i] = NULL;
7938 if (ioa_cfg->ipr_cmd_pool)
7939 pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
7941 ioa_cfg->ipr_cmd_pool = NULL;
7945 * ipr_free_mem - Frees memory allocated for an adapter
7946 * @ioa_cfg: ioa cfg struct
7951 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
7955 kfree(ioa_cfg->res_entries);
7956 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
7957 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
7958 ipr_free_cmd_blks(ioa_cfg);
7959 pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
7960 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
7961 pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size,
7962 ioa_cfg->u.cfg_table,
7963 ioa_cfg->cfg_table_dma);
7965 for (i = 0; i < IPR_NUM_HCAMS; i++) {
7966 pci_free_consistent(ioa_cfg->pdev,
7967 sizeof(struct ipr_hostrcb),
7968 ioa_cfg->hostrcb[i],
7969 ioa_cfg->hostrcb_dma[i]);
7972 ipr_free_dump(ioa_cfg);
7973 kfree(ioa_cfg->trace);
7977 * ipr_free_all_resources - Free all allocated resources for an adapter.
7978 * @ipr_cmd: ipr command struct
7980 * This function frees all allocated resources for the
7981 * specified adapter.
7986 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
7988 struct pci_dev *pdev = ioa_cfg->pdev;
7991 free_irq(pdev->irq, ioa_cfg);
7992 pci_disable_msi(pdev);
7993 iounmap(ioa_cfg->hdw_dma_regs);
7994 pci_release_regions(pdev);
7995 ipr_free_mem(ioa_cfg);
7996 scsi_host_put(ioa_cfg->host);
7997 pci_disable_device(pdev);
8002 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8003 * @ioa_cfg: ioa config struct
8006 * 0 on success / -ENOMEM on allocation failure
8008 static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8010 struct ipr_cmnd *ipr_cmd;
8011 struct ipr_ioarcb *ioarcb;
8012 dma_addr_t dma_addr;
8015 ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
8016 sizeof(struct ipr_cmnd), 16, 0);
8018 if (!ioa_cfg->ipr_cmd_pool)
8021 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8022 ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
8025 ipr_free_cmd_blks(ioa_cfg);
8029 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
8030 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
8031 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
8033 ioarcb = &ipr_cmd->ioarcb;
8034 ipr_cmd->dma_addr = dma_addr;
8036 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
8038 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
8040 ioarcb->host_response_handle = cpu_to_be32(i << 2);
8041 if (ioa_cfg->sis64) {
8042 ioarcb->u.sis64_addr_data.data_ioadl_addr =
8043 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
8044 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
8045 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, ioasa));
8047 ioarcb->write_ioadl_addr =
8048 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
8049 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
8050 ioarcb->ioasa_host_pci_addr =
8051 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
8053 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
8054 ipr_cmd->cmd_index = i;
8055 ipr_cmd->ioa_cfg = ioa_cfg;
8056 ipr_cmd->sense_buffer_dma = dma_addr +
8057 offsetof(struct ipr_cmnd, sense_buffer);
8059 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8066 * ipr_alloc_mem - Allocate memory for an adapter
8067 * @ioa_cfg: ioa config struct
8070 * 0 on success / non-zero for error
8072 static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
8074 struct pci_dev *pdev = ioa_cfg->pdev;
8075 int i, rc = -ENOMEM;
8078 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
8079 ioa_cfg->max_devs_supported, GFP_KERNEL);
8081 if (!ioa_cfg->res_entries)
8084 if (ioa_cfg->sis64) {
8085 ioa_cfg->target_ids = kzalloc(sizeof(unsigned long) *
8086 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8087 ioa_cfg->array_ids = kzalloc(sizeof(unsigned long) *
8088 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8089 ioa_cfg->vset_ids = kzalloc(sizeof(unsigned long) *
8090 BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
8093 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
8094 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
8095 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
8098 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
8099 sizeof(struct ipr_misc_cbs),
8100 &ioa_cfg->vpd_cbs_dma);
8102 if (!ioa_cfg->vpd_cbs)
8103 goto out_free_res_entries;
8105 if (ipr_alloc_cmd_blks(ioa_cfg))
8106 goto out_free_vpd_cbs;
8108 ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
8109 sizeof(u32) * IPR_NUM_CMD_BLKS,
8110 &ioa_cfg->host_rrq_dma);
8112 if (!ioa_cfg->host_rrq)
8113 goto out_ipr_free_cmd_blocks;
8115 ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
8116 ioa_cfg->cfg_table_size,
8117 &ioa_cfg->cfg_table_dma);
8119 if (!ioa_cfg->u.cfg_table)
8120 goto out_free_host_rrq;
8122 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8123 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
8124 sizeof(struct ipr_hostrcb),
8125 &ioa_cfg->hostrcb_dma[i]);
8127 if (!ioa_cfg->hostrcb[i])
8128 goto out_free_hostrcb_dma;
8130 ioa_cfg->hostrcb[i]->hostrcb_dma =
8131 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
8132 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
8133 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
8136 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
8137 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
8139 if (!ioa_cfg->trace)
8140 goto out_free_hostrcb_dma;
8147 out_free_hostrcb_dma:
8149 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
8150 ioa_cfg->hostrcb[i],
8151 ioa_cfg->hostrcb_dma[i]);
8153 pci_free_consistent(pdev, ioa_cfg->cfg_table_size,
8154 ioa_cfg->u.cfg_table,
8155 ioa_cfg->cfg_table_dma);
8157 pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
8158 ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
8159 out_ipr_free_cmd_blocks:
8160 ipr_free_cmd_blks(ioa_cfg);
8162 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
8163 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8164 out_free_res_entries:
8165 kfree(ioa_cfg->res_entries);
8170 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
8171 * @ioa_cfg: ioa config struct
8176 static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
8180 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
8181 ioa_cfg->bus_attr[i].bus = i;
8182 ioa_cfg->bus_attr[i].qas_enabled = 0;
8183 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
8184 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
8185 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
8187 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
8192 * ipr_init_ioa_cfg - Initialize IOA config struct
8193 * @ioa_cfg: ioa config struct
8194 * @host: scsi host struct
8195 * @pdev: PCI dev struct
8200 static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
8201 struct Scsi_Host *host, struct pci_dev *pdev)
8203 const struct ipr_interrupt_offsets *p;
8204 struct ipr_interrupts *t;
8207 ioa_cfg->host = host;
8208 ioa_cfg->pdev = pdev;
8209 ioa_cfg->log_level = ipr_log_level;
8210 ioa_cfg->doorbell = IPR_DOORBELL;
8211 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
8212 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
8213 sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
8214 sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
8215 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
8216 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
8217 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
8218 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
8220 INIT_LIST_HEAD(&ioa_cfg->free_q);
8221 INIT_LIST_HEAD(&ioa_cfg->pending_q);
8222 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
8223 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
8224 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
8225 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
8226 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
8227 init_waitqueue_head(&ioa_cfg->reset_wait_q);
8228 init_waitqueue_head(&ioa_cfg->msi_wait_q);
8229 ioa_cfg->sdt_state = INACTIVE;
8231 ipr_initialize_bus_attr(ioa_cfg);
8232 ioa_cfg->max_devs_supported = ipr_max_devs;
8234 if (ioa_cfg->sis64) {
8235 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
8236 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
8237 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
8238 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
8240 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
8241 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
8242 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
8243 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
8245 host->max_channel = IPR_MAX_BUS_TO_SCAN;
8246 host->unique_id = host->host_no;
8247 host->max_cmd_len = IPR_MAX_CDB_LEN;
8248 pci_set_drvdata(pdev, ioa_cfg);
8250 p = &ioa_cfg->chip_cfg->regs;
8252 base = ioa_cfg->hdw_dma_regs;
8254 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
8255 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
8256 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
8257 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
8258 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
8259 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
8260 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
8261 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
8262 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
8263 t->ioarrin_reg = base + p->ioarrin_reg;
8264 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
8265 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
8266 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
8267 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
8268 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
8269 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
8271 if (ioa_cfg->sis64) {
8272 t->init_feedback_reg = base + p->init_feedback_reg;
8273 t->dump_addr_reg = base + p->dump_addr_reg;
8274 t->dump_data_reg = base + p->dump_data_reg;
8279 * ipr_get_chip_info - Find adapter chip information
8280 * @dev_id: PCI device id struct
8283 * ptr to chip information on success / NULL on failure
8285 static const struct ipr_chip_t * __devinit
8286 ipr_get_chip_info(const struct pci_device_id *dev_id)
8290 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
8291 if (ipr_chip[i].vendor == dev_id->vendor &&
8292 ipr_chip[i].device == dev_id->device)
8293 return &ipr_chip[i];
8298 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
8299 * @pdev: PCI device struct
8301 * Description: Simply set the msi_received flag to 1 indicating that
8302 * Message Signaled Interrupts are supported.
8305 * 0 on success / non-zero on failure
8307 static irqreturn_t __devinit ipr_test_intr(int irq, void *devp)
8309 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
8310 unsigned long lock_flags = 0;
8311 irqreturn_t rc = IRQ_HANDLED;
8313 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8315 ioa_cfg->msi_received = 1;
8316 wake_up(&ioa_cfg->msi_wait_q);
8318 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8323 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
8324 * @pdev: PCI device struct
8326 * Description: The return value from pci_enable_msi() can not always be
8327 * trusted. This routine sets up and initiates a test interrupt to determine
8328 * if the interrupt is received via the ipr_test_intr() service routine.
8329 * If the tests fails, the driver will fall back to LSI.
8332 * 0 on success / non-zero on failure
8334 static int __devinit ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg,
8335 struct pci_dev *pdev)
8338 volatile u32 int_reg;
8339 unsigned long lock_flags = 0;
8343 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8344 init_waitqueue_head(&ioa_cfg->msi_wait_q);
8345 ioa_cfg->msi_received = 0;
8346 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8347 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
8348 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
8349 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8351 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
8353 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
8355 } else if (ipr_debug)
8356 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
8358 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
8359 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8360 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
8361 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8363 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8364 if (!ioa_cfg->msi_received) {
8365 /* MSI test failed */
8366 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
8368 } else if (ipr_debug)
8369 dev_info(&pdev->dev, "MSI test succeeded.\n");
8371 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8373 free_irq(pdev->irq, ioa_cfg);
8381 * ipr_probe_ioa - Allocates memory and does first stage of initialization
8382 * @pdev: PCI device struct
8383 * @dev_id: PCI device id struct
8386 * 0 on success / non-zero on failure
8388 static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
8389 const struct pci_device_id *dev_id)
8391 struct ipr_ioa_cfg *ioa_cfg;
8392 struct Scsi_Host *host;
8393 unsigned long ipr_regs_pci;
8394 void __iomem *ipr_regs;
8395 int rc = PCIBIOS_SUCCESSFUL;
8396 volatile u32 mask, uproc, interrupts;
8400 if ((rc = pci_enable_device(pdev))) {
8401 dev_err(&pdev->dev, "Cannot enable adapter\n");
8405 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
8407 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
8410 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
8415 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
8416 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
8417 ata_host_init(&ioa_cfg->ata_host, &pdev->dev,
8418 sata_port_info.flags, &ipr_sata_ops);
8420 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
8422 if (!ioa_cfg->ipr_chip) {
8423 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
8424 dev_id->vendor, dev_id->device);
8425 goto out_scsi_host_put;
8428 /* set SIS 32 or SIS 64 */
8429 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
8430 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
8432 if (ipr_transop_timeout)
8433 ioa_cfg->transop_timeout = ipr_transop_timeout;
8434 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
8435 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
8437 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
8439 ioa_cfg->revid = pdev->revision;
8441 ipr_regs_pci = pci_resource_start(pdev, 0);
8443 rc = pci_request_regions(pdev, IPR_NAME);
8446 "Couldn't register memory range of registers\n");
8447 goto out_scsi_host_put;
8450 ipr_regs = pci_ioremap_bar(pdev, 0);
8454 "Couldn't map memory range of registers\n");
8456 goto out_release_regions;
8459 ioa_cfg->hdw_dma_regs = ipr_regs;
8460 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
8461 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
8463 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
8465 pci_set_master(pdev);
8467 if (ioa_cfg->sis64) {
8468 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
8470 dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n");
8471 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8475 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
8478 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
8482 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
8483 ioa_cfg->chip_cfg->cache_line_size);
8485 if (rc != PCIBIOS_SUCCESSFUL) {
8486 dev_err(&pdev->dev, "Write of cache line size failed\n");
8491 /* Enable MSI style interrupts if they are supported. */
8492 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI && !pci_enable_msi(pdev)) {
8493 rc = ipr_test_msi(ioa_cfg, pdev);
8494 if (rc == -EOPNOTSUPP)
8495 pci_disable_msi(pdev);
8497 goto out_msi_disable;
8499 dev_info(&pdev->dev, "MSI enabled with IRQ: %d\n", pdev->irq);
8500 } else if (ipr_debug)
8501 dev_info(&pdev->dev, "Cannot enable MSI.\n");
8503 /* Save away PCI config space for use following IOA reset */
8504 rc = pci_save_state(pdev);
8506 if (rc != PCIBIOS_SUCCESSFUL) {
8507 dev_err(&pdev->dev, "Failed to save PCI config space\n");
8512 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
8515 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
8519 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
8520 + ((sizeof(struct ipr_config_table_entry64)
8521 * ioa_cfg->max_devs_supported)));
8523 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
8524 + ((sizeof(struct ipr_config_table_entry)
8525 * ioa_cfg->max_devs_supported)));
8527 rc = ipr_alloc_mem(ioa_cfg);
8530 "Couldn't allocate enough memory for device driver!\n");
8535 * If HRRQ updated interrupt is not masked, or reset alert is set,
8536 * the card is in an unknown state and needs a hard reset
8538 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
8539 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
8540 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
8541 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
8542 ioa_cfg->needs_hard_reset = 1;
8543 if (interrupts & IPR_PCII_ERROR_INTERRUPTS)
8544 ioa_cfg->needs_hard_reset = 1;
8545 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
8546 ioa_cfg->ioa_unit_checked = 1;
8548 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
8549 rc = request_irq(pdev->irq, ipr_isr,
8550 ioa_cfg->msi_received ? 0 : IRQF_SHARED,
8554 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
8559 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
8560 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
8561 ioa_cfg->needs_warm_reset = 1;
8562 ioa_cfg->reset = ipr_reset_slot_reset;
8564 ioa_cfg->reset = ipr_reset_start_bist;
8566 spin_lock(&ipr_driver_lock);
8567 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
8568 spin_unlock(&ipr_driver_lock);
8575 ipr_free_mem(ioa_cfg);
8579 pci_disable_msi(pdev);
8580 out_release_regions:
8581 pci_release_regions(pdev);
8583 scsi_host_put(host);
8585 pci_disable_device(pdev);
8590 * ipr_scan_vsets - Scans for VSET devices
8591 * @ioa_cfg: ioa config struct
8593 * Description: Since the VSET resources do not follow SAM in that we can have
8594 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
8599 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
8603 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
8604 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
8605 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
8609 * ipr_initiate_ioa_bringdown - Bring down an adapter
8610 * @ioa_cfg: ioa config struct
8611 * @shutdown_type: shutdown type
8613 * Description: This function will initiate bringing down the adapter.
8614 * This consists of issuing an IOA shutdown to the adapter
8615 * to flush the cache, and running BIST.
8616 * If the caller needs to wait on the completion of the reset,
8617 * the caller must sleep on the reset_wait_q.
8622 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
8623 enum ipr_shutdown_type shutdown_type)
8626 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8627 ioa_cfg->sdt_state = ABORT_DUMP;
8628 ioa_cfg->reset_retries = 0;
8629 ioa_cfg->in_ioa_bringdown = 1;
8630 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
8635 * __ipr_remove - Remove a single adapter
8636 * @pdev: pci device struct
8638 * Adapter hot plug remove entry point.
8643 static void __ipr_remove(struct pci_dev *pdev)
8645 unsigned long host_lock_flags = 0;
8646 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8649 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8650 while(ioa_cfg->in_reset_reload) {
8651 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8652 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8653 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8656 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
8658 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8659 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8660 flush_scheduled_work();
8661 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8663 spin_lock(&ipr_driver_lock);
8664 list_del(&ioa_cfg->queue);
8665 spin_unlock(&ipr_driver_lock);
8667 if (ioa_cfg->sdt_state == ABORT_DUMP)
8668 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8669 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8671 ipr_free_all_resources(ioa_cfg);
8677 * ipr_remove - IOA hot plug remove entry point
8678 * @pdev: pci device struct
8680 * Adapter hot plug remove entry point.
8685 static void __devexit ipr_remove(struct pci_dev *pdev)
8687 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8691 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
8693 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
8695 scsi_remove_host(ioa_cfg->host);
8703 * ipr_probe - Adapter hot plug add entry point
8706 * 0 on success / non-zero on failure
8708 static int __devinit ipr_probe(struct pci_dev *pdev,
8709 const struct pci_device_id *dev_id)
8711 struct ipr_ioa_cfg *ioa_cfg;
8714 rc = ipr_probe_ioa(pdev, dev_id);
8719 ioa_cfg = pci_get_drvdata(pdev);
8720 rc = ipr_probe_ioa_part2(ioa_cfg);
8727 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
8734 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
8738 scsi_remove_host(ioa_cfg->host);
8743 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
8747 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
8749 scsi_remove_host(ioa_cfg->host);
8754 scsi_scan_host(ioa_cfg->host);
8755 ipr_scan_vsets(ioa_cfg);
8756 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
8757 ioa_cfg->allow_ml_add_del = 1;
8758 ioa_cfg->host->max_channel = IPR_VSET_BUS;
8759 schedule_work(&ioa_cfg->work_q);
8764 * ipr_shutdown - Shutdown handler.
8765 * @pdev: pci device struct
8767 * This function is invoked upon system shutdown/reboot. It will issue
8768 * an adapter shutdown to the adapter to flush the write cache.
8773 static void ipr_shutdown(struct pci_dev *pdev)
8775 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8776 unsigned long lock_flags = 0;
8778 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8779 while(ioa_cfg->in_reset_reload) {
8780 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8781 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8782 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
8785 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
8786 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
8787 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8790 static struct pci_device_id ipr_pci_table[] __devinitdata = {
8791 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
8792 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
8793 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
8794 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
8795 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
8796 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
8797 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
8798 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
8799 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
8800 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
8801 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
8802 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
8803 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
8804 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
8805 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
8806 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
8807 IPR_USE_LONG_TRANSOP_TIMEOUT },
8808 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
8809 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
8810 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
8811 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
8812 IPR_USE_LONG_TRANSOP_TIMEOUT },
8813 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
8814 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
8815 IPR_USE_LONG_TRANSOP_TIMEOUT },
8816 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
8817 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
8818 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
8819 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
8820 IPR_USE_LONG_TRANSOP_TIMEOUT},
8821 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
8822 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
8823 IPR_USE_LONG_TRANSOP_TIMEOUT },
8824 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
8825 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
8826 IPR_USE_LONG_TRANSOP_TIMEOUT },
8827 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
8828 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575D, 0, 0,
8829 IPR_USE_LONG_TRANSOP_TIMEOUT },
8830 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
8831 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
8832 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
8833 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
8834 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
8835 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
8836 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
8837 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
8838 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
8839 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
8840 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
8841 IPR_USE_LONG_TRANSOP_TIMEOUT },
8842 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
8843 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
8844 IPR_USE_LONG_TRANSOP_TIMEOUT },
8845 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SCAMP_E,
8846 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0,
8847 IPR_USE_LONG_TRANSOP_TIMEOUT },
8850 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
8852 static struct pci_error_handlers ipr_err_handler = {
8853 .error_detected = ipr_pci_error_detected,
8854 .slot_reset = ipr_pci_slot_reset,
8857 static struct pci_driver ipr_driver = {
8859 .id_table = ipr_pci_table,
8861 .remove = __devexit_p(ipr_remove),
8862 .shutdown = ipr_shutdown,
8863 .err_handler = &ipr_err_handler,
8867 * ipr_halt_done - Shutdown prepare completion
8872 static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
8874 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8876 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
8880 * ipr_halt - Issue shutdown prepare to all adapters
8883 * NOTIFY_OK on success / NOTIFY_DONE on failure
8885 static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
8887 struct ipr_cmnd *ipr_cmd;
8888 struct ipr_ioa_cfg *ioa_cfg;
8889 unsigned long flags = 0;
8891 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
8894 spin_lock(&ipr_driver_lock);
8896 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
8897 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8898 if (!ioa_cfg->allow_cmds) {
8899 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8903 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8904 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8905 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8906 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8907 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
8909 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
8910 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8912 spin_unlock(&ipr_driver_lock);
8917 static struct notifier_block ipr_notifier = {
8922 * ipr_init - Module entry point
8925 * 0 on success / negative value on failure
8927 static int __init ipr_init(void)
8929 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
8930 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
8932 register_reboot_notifier(&ipr_notifier);
8933 return pci_register_driver(&ipr_driver);
8937 * ipr_exit - Module unload
8939 * Module unload entry point.
8944 static void __exit ipr_exit(void)
8946 unregister_reboot_notifier(&ipr_notifier);
8947 pci_unregister_driver(&ipr_driver);
8950 module_init(ipr_init);
8951 module_exit(ipr_exit);