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/slab.h>
63 #include <linux/vmalloc.h>
64 #include <linux/ioport.h>
65 #include <linux/delay.h>
66 #include <linux/pci.h>
67 #include <linux/wait.h>
68 #include <linux/spinlock.h>
69 #include <linux/sched.h>
70 #include <linux/interrupt.h>
71 #include <linux/blkdev.h>
72 #include <linux/firmware.h>
73 #include <linux/module.h>
74 #include <linux/moduleparam.h>
75 #include <linux/libata.h>
76 #include <linux/hdreg.h>
77 #include <linux/reboot.h>
78 #include <linux/stringify.h>
81 #include <asm/processor.h>
82 #include <scsi/scsi.h>
83 #include <scsi/scsi_host.h>
84 #include <scsi/scsi_tcq.h>
85 #include <scsi/scsi_eh.h>
86 #include <scsi/scsi_cmnd.h>
92 static LIST_HEAD(ipr_ioa_head);
93 static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
94 static unsigned int ipr_max_speed = 1;
95 static int ipr_testmode = 0;
96 static unsigned int ipr_fastfail = 0;
97 static unsigned int ipr_transop_timeout = 0;
98 static unsigned int ipr_debug = 0;
99 static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
100 static unsigned int ipr_dual_ioa_raid = 1;
101 static unsigned int ipr_number_of_msix = 2;
102 static DEFINE_SPINLOCK(ipr_driver_lock);
104 /* This table describes the differences between DMA controller chips */
105 static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
106 { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
109 .cache_line_size = 0x20,
113 .set_interrupt_mask_reg = 0x0022C,
114 .clr_interrupt_mask_reg = 0x00230,
115 .clr_interrupt_mask_reg32 = 0x00230,
116 .sense_interrupt_mask_reg = 0x0022C,
117 .sense_interrupt_mask_reg32 = 0x0022C,
118 .clr_interrupt_reg = 0x00228,
119 .clr_interrupt_reg32 = 0x00228,
120 .sense_interrupt_reg = 0x00224,
121 .sense_interrupt_reg32 = 0x00224,
122 .ioarrin_reg = 0x00404,
123 .sense_uproc_interrupt_reg = 0x00214,
124 .sense_uproc_interrupt_reg32 = 0x00214,
125 .set_uproc_interrupt_reg = 0x00214,
126 .set_uproc_interrupt_reg32 = 0x00214,
127 .clr_uproc_interrupt_reg = 0x00218,
128 .clr_uproc_interrupt_reg32 = 0x00218
131 { /* Snipe and Scamp */
134 .cache_line_size = 0x20,
138 .set_interrupt_mask_reg = 0x00288,
139 .clr_interrupt_mask_reg = 0x0028C,
140 .clr_interrupt_mask_reg32 = 0x0028C,
141 .sense_interrupt_mask_reg = 0x00288,
142 .sense_interrupt_mask_reg32 = 0x00288,
143 .clr_interrupt_reg = 0x00284,
144 .clr_interrupt_reg32 = 0x00284,
145 .sense_interrupt_reg = 0x00280,
146 .sense_interrupt_reg32 = 0x00280,
147 .ioarrin_reg = 0x00504,
148 .sense_uproc_interrupt_reg = 0x00290,
149 .sense_uproc_interrupt_reg32 = 0x00290,
150 .set_uproc_interrupt_reg = 0x00290,
151 .set_uproc_interrupt_reg32 = 0x00290,
152 .clr_uproc_interrupt_reg = 0x00294,
153 .clr_uproc_interrupt_reg32 = 0x00294
159 .cache_line_size = 0x20,
163 .set_interrupt_mask_reg = 0x00010,
164 .clr_interrupt_mask_reg = 0x00018,
165 .clr_interrupt_mask_reg32 = 0x0001C,
166 .sense_interrupt_mask_reg = 0x00010,
167 .sense_interrupt_mask_reg32 = 0x00014,
168 .clr_interrupt_reg = 0x00008,
169 .clr_interrupt_reg32 = 0x0000C,
170 .sense_interrupt_reg = 0x00000,
171 .sense_interrupt_reg32 = 0x00004,
172 .ioarrin_reg = 0x00070,
173 .sense_uproc_interrupt_reg = 0x00020,
174 .sense_uproc_interrupt_reg32 = 0x00024,
175 .set_uproc_interrupt_reg = 0x00020,
176 .set_uproc_interrupt_reg32 = 0x00024,
177 .clr_uproc_interrupt_reg = 0x00028,
178 .clr_uproc_interrupt_reg32 = 0x0002C,
179 .init_feedback_reg = 0x0005C,
180 .dump_addr_reg = 0x00064,
181 .dump_data_reg = 0x00068,
182 .endian_swap_reg = 0x00084
187 static const struct ipr_chip_t ipr_chip[] = {
188 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
189 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
190 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
191 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
192 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
193 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
194 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
195 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
196 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
199 static int ipr_max_bus_speeds[] = {
200 IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
203 MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
204 MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
205 module_param_named(max_speed, ipr_max_speed, uint, 0);
206 MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
207 module_param_named(log_level, ipr_log_level, uint, 0);
208 MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
209 module_param_named(testmode, ipr_testmode, int, 0);
210 MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
211 module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
212 MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
213 module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
214 MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
215 module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
216 MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
217 module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
218 MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
219 module_param_named(max_devs, ipr_max_devs, int, 0);
220 MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
221 "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
222 module_param_named(number_of_msix, ipr_number_of_msix, int, 0);
223 MODULE_PARM_DESC(number_of_msix, "Specify the number of MSIX interrupts to use on capable adapters (1 - 16). (default:2)");
224 MODULE_LICENSE("GPL");
225 MODULE_VERSION(IPR_DRIVER_VERSION);
227 /* A constant array of IOASCs/URCs/Error Messages */
229 struct ipr_error_table_t ipr_error_table[] = {
230 {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
231 "8155: An unknown error was received"},
233 "Soft underlength error"},
235 "Command to be cancelled not found"},
237 "Qualified success"},
238 {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
239 "FFFE: Soft device bus error recovered by the IOA"},
240 {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
241 "4101: Soft device bus fabric error"},
242 {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
243 "FFFC: Logical block guard error recovered by the device"},
244 {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
245 "FFFC: Logical block reference tag error recovered by the device"},
246 {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
247 "4171: Recovered scatter list tag / sequence number error"},
248 {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
249 "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
250 {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
251 "4171: Recovered logical block sequence number error on IOA to Host transfer"},
252 {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
253 "FFFD: Recovered logical block reference tag error detected by the IOA"},
254 {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
255 "FFFD: Logical block guard error recovered by the IOA"},
256 {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
257 "FFF9: Device sector reassign successful"},
258 {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
259 "FFF7: Media error recovered by device rewrite procedures"},
260 {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
261 "7001: IOA sector reassignment successful"},
262 {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
263 "FFF9: Soft media error. Sector reassignment recommended"},
264 {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
265 "FFF7: Media error recovered by IOA rewrite procedures"},
266 {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
267 "FF3D: Soft PCI bus error recovered by the IOA"},
268 {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
269 "FFF6: Device hardware error recovered by the IOA"},
270 {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
271 "FFF6: Device hardware error recovered by the device"},
272 {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
273 "FF3D: Soft IOA error recovered by the IOA"},
274 {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
275 "FFFA: Undefined device response recovered by the IOA"},
276 {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
277 "FFF6: Device bus error, message or command phase"},
278 {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
279 "FFFE: Task Management Function failed"},
280 {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
281 "FFF6: Failure prediction threshold exceeded"},
282 {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
283 "8009: Impending cache battery pack failure"},
285 "Logical Unit in process of becoming ready"},
287 "Initializing command required"},
289 "34FF: Disk device format in progress"},
291 "Logical unit not accessible, target port in unavailable state"},
292 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
293 "9070: IOA requested reset"},
295 "Synchronization required"},
297 "IOA microcode download required"},
299 "Device bus connection is prohibited by host"},
301 "No ready, IOA shutdown"},
303 "Not ready, IOA has been shutdown"},
304 {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
305 "3020: Storage subsystem configuration error"},
307 "FFF5: Medium error, data unreadable, recommend reassign"},
309 "7000: Medium error, data unreadable, do not reassign"},
310 {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
311 "FFF3: Disk media format bad"},
312 {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
313 "3002: Addressed device failed to respond to selection"},
314 {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
315 "3100: Device bus error"},
316 {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
317 "3109: IOA timed out a device command"},
319 "3120: SCSI bus is not operational"},
320 {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
321 "4100: Hard device bus fabric error"},
322 {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
323 "310C: Logical block guard error detected by the device"},
324 {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
325 "310C: Logical block reference tag error detected by the device"},
326 {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
327 "4170: Scatter list tag / sequence number error"},
328 {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
329 "8150: Logical block CRC error on IOA to Host transfer"},
330 {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
331 "4170: Logical block sequence number error on IOA to Host transfer"},
332 {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
333 "310D: Logical block reference tag error detected by the IOA"},
334 {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
335 "310D: Logical block guard error detected by the IOA"},
336 {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
337 "9000: IOA reserved area data check"},
338 {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
339 "9001: IOA reserved area invalid data pattern"},
340 {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
341 "9002: IOA reserved area LRC error"},
342 {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
343 "Hardware Error, IOA metadata access error"},
344 {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
345 "102E: Out of alternate sectors for disk storage"},
346 {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
347 "FFF4: Data transfer underlength error"},
348 {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
349 "FFF4: Data transfer overlength error"},
350 {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
351 "3400: Logical unit failure"},
352 {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
353 "FFF4: Device microcode is corrupt"},
354 {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
355 "8150: PCI bus error"},
357 "Unsupported device bus message received"},
358 {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
359 "FFF4: Disk device problem"},
360 {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
361 "8150: Permanent IOA failure"},
362 {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
363 "3010: Disk device returned wrong response to IOA"},
364 {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
365 "8151: IOA microcode error"},
367 "Device bus status error"},
368 {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
369 "8157: IOA error requiring IOA reset to recover"},
371 "ATA device status error"},
373 "Message reject received from the device"},
374 {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
375 "8008: A permanent cache battery pack failure occurred"},
376 {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
377 "9090: Disk unit has been modified after the last known status"},
378 {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
379 "9081: IOA detected device error"},
380 {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
381 "9082: IOA detected device error"},
382 {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
383 "3110: Device bus error, message or command phase"},
384 {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
385 "3110: SAS Command / Task Management Function failed"},
386 {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
387 "9091: Incorrect hardware configuration change has been detected"},
388 {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
389 "9073: Invalid multi-adapter configuration"},
390 {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
391 "4010: Incorrect connection between cascaded expanders"},
392 {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
393 "4020: Connections exceed IOA design limits"},
394 {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
395 "4030: Incorrect multipath connection"},
396 {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
397 "4110: Unsupported enclosure function"},
398 {0x04679800, 0, IPR_DEFAULT_LOG_LEVEL,
399 "4120: SAS cable VPD cannot be read"},
400 {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
401 "FFF4: Command to logical unit failed"},
403 "Illegal request, invalid request type or request packet"},
405 "Illegal request, invalid resource handle"},
407 "Illegal request, commands not allowed to this device"},
409 "Illegal request, command not allowed to a secondary adapter"},
411 "Illegal request, command not allowed to a non-optimized resource"},
413 "Illegal request, invalid field in parameter list"},
415 "Illegal request, parameter not supported"},
417 "Illegal request, parameter value invalid"},
419 "Illegal request, command sequence error"},
421 "Illegal request, dual adapter support not enabled"},
423 "Illegal request, another cable connector was physically disabled"},
425 "Illegal request, inconsistent group id/group count"},
426 {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
427 "9031: Array protection temporarily suspended, protection resuming"},
428 {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
429 "9040: Array protection temporarily suspended, protection resuming"},
430 {0x060B0100, 0, IPR_DEFAULT_LOG_LEVEL,
431 "4080: IOA exceeded maximum operating temperature"},
432 {0x060B8000, 0, IPR_DEFAULT_LOG_LEVEL,
433 "4085: Service required"},
434 {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
435 "3140: Device bus not ready to ready transition"},
436 {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
437 "FFFB: SCSI bus was reset"},
439 "FFFE: SCSI bus transition to single ended"},
441 "FFFE: SCSI bus transition to LVD"},
442 {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
443 "FFFB: SCSI bus was reset by another initiator"},
444 {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
445 "3029: A device replacement has occurred"},
446 {0x063F8300, 0, IPR_DEFAULT_LOG_LEVEL,
447 "4102: Device bus fabric performance degradation"},
448 {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
449 "9051: IOA cache data exists for a missing or failed device"},
450 {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
451 "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
452 {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
453 "9025: Disk unit is not supported at its physical location"},
454 {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
455 "3020: IOA detected a SCSI bus configuration error"},
456 {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
457 "3150: SCSI bus configuration error"},
458 {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
459 "9074: Asymmetric advanced function disk configuration"},
460 {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
461 "4040: Incomplete multipath connection between IOA and enclosure"},
462 {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
463 "4041: Incomplete multipath connection between enclosure and device"},
464 {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
465 "9075: Incomplete multipath connection between IOA and remote IOA"},
466 {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
467 "9076: Configuration error, missing remote IOA"},
468 {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
469 "4050: Enclosure does not support a required multipath function"},
470 {0x06679800, 0, IPR_DEFAULT_LOG_LEVEL,
471 "4121: Configuration error, required cable is missing"},
472 {0x06679900, 0, IPR_DEFAULT_LOG_LEVEL,
473 "4122: Cable is not plugged into the correct location on remote IOA"},
474 {0x06679A00, 0, IPR_DEFAULT_LOG_LEVEL,
475 "4123: Configuration error, invalid cable vital product data"},
476 {0x06679B00, 0, IPR_DEFAULT_LOG_LEVEL,
477 "4124: Configuration error, both cable ends are plugged into the same IOA"},
478 {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
479 "4070: Logically bad block written on device"},
480 {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
481 "9041: Array protection temporarily suspended"},
482 {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
483 "9042: Corrupt array parity detected on specified device"},
484 {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
485 "9030: Array no longer protected due to missing or failed disk unit"},
486 {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
487 "9071: Link operational transition"},
488 {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
489 "9072: Link not operational transition"},
490 {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
491 "9032: Array exposed but still protected"},
492 {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
493 "70DD: Device forced failed by disrupt device command"},
494 {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
495 "4061: Multipath redundancy level got better"},
496 {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
497 "4060: Multipath redundancy level got worse"},
499 "Failure due to other device"},
500 {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
501 "9008: IOA does not support functions expected by devices"},
502 {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
503 "9010: Cache data associated with attached devices cannot be found"},
504 {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
505 "9011: Cache data belongs to devices other than those attached"},
506 {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
507 "9020: Array missing 2 or more devices with only 1 device present"},
508 {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
509 "9021: Array missing 2 or more devices with 2 or more devices present"},
510 {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
511 "9022: Exposed array is missing a required device"},
512 {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
513 "9023: Array member(s) not at required physical locations"},
514 {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
515 "9024: Array not functional due to present hardware configuration"},
516 {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
517 "9026: Array not functional due to present hardware configuration"},
518 {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
519 "9027: Array is missing a device and parity is out of sync"},
520 {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
521 "9028: Maximum number of arrays already exist"},
522 {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
523 "9050: Required cache data cannot be located for a disk unit"},
524 {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
525 "9052: Cache data exists for a device that has been modified"},
526 {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
527 "9054: IOA resources not available due to previous problems"},
528 {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
529 "9092: Disk unit requires initialization before use"},
530 {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
531 "9029: Incorrect hardware configuration change has been detected"},
532 {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
533 "9060: One or more disk pairs are missing from an array"},
534 {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
535 "9061: One or more disks are missing from an array"},
536 {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
537 "9062: One or more disks are missing from an array"},
538 {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
539 "9063: Maximum number of functional arrays has been exceeded"},
541 "Data protect, other volume set problem"},
543 "Aborted command, invalid descriptor"},
545 "Target operating conditions have changed, dual adapter takeover"},
547 "Aborted command, medium removal prevented"},
549 "Command terminated by host"},
551 "Aborted command, command terminated by host"}
554 static const struct ipr_ses_table_entry ipr_ses_table[] = {
555 { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
556 { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
557 { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
558 { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
559 { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
560 { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
561 { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
562 { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
563 { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
564 { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
565 { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
566 { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
567 { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
571 * Function Prototypes
573 static int ipr_reset_alert(struct ipr_cmnd *);
574 static void ipr_process_ccn(struct ipr_cmnd *);
575 static void ipr_process_error(struct ipr_cmnd *);
576 static void ipr_reset_ioa_job(struct ipr_cmnd *);
577 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
578 enum ipr_shutdown_type);
580 #ifdef CONFIG_SCSI_IPR_TRACE
582 * ipr_trc_hook - Add a trace entry to the driver trace
583 * @ipr_cmd: ipr command struct
585 * @add_data: additional data
590 static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
591 u8 type, u32 add_data)
593 struct ipr_trace_entry *trace_entry;
594 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
596 trace_entry = &ioa_cfg->trace[atomic_add_return
597 (1, &ioa_cfg->trace_index)%IPR_NUM_TRACE_ENTRIES];
598 trace_entry->time = jiffies;
599 trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
600 trace_entry->type = type;
601 if (ipr_cmd->ioa_cfg->sis64)
602 trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
604 trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
605 trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
606 trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
607 trace_entry->u.add_data = add_data;
611 #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
615 * ipr_lock_and_done - Acquire lock and complete command
616 * @ipr_cmd: ipr command struct
621 static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
623 unsigned long lock_flags;
624 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
626 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
627 ipr_cmd->done(ipr_cmd);
628 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
632 * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
633 * @ipr_cmd: ipr command struct
638 static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
640 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
641 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
642 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
643 dma_addr_t dma_addr = ipr_cmd->dma_addr;
646 hrrq_id = ioarcb->cmd_pkt.hrrq_id;
647 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
648 ioarcb->cmd_pkt.hrrq_id = hrrq_id;
649 ioarcb->data_transfer_length = 0;
650 ioarcb->read_data_transfer_length = 0;
651 ioarcb->ioadl_len = 0;
652 ioarcb->read_ioadl_len = 0;
654 if (ipr_cmd->ioa_cfg->sis64) {
655 ioarcb->u.sis64_addr_data.data_ioadl_addr =
656 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
657 ioasa64->u.gata.status = 0;
659 ioarcb->write_ioadl_addr =
660 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
661 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
662 ioasa->u.gata.status = 0;
665 ioasa->hdr.ioasc = 0;
666 ioasa->hdr.residual_data_len = 0;
667 ipr_cmd->scsi_cmd = NULL;
669 ipr_cmd->sense_buffer[0] = 0;
670 ipr_cmd->dma_use_sg = 0;
674 * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
675 * @ipr_cmd: ipr command struct
680 static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
681 void (*fast_done) (struct ipr_cmnd *))
683 ipr_reinit_ipr_cmnd(ipr_cmd);
684 ipr_cmd->u.scratch = 0;
685 ipr_cmd->sibling = NULL;
686 ipr_cmd->fast_done = fast_done;
687 init_timer(&ipr_cmd->timer);
691 * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
692 * @ioa_cfg: ioa config struct
695 * pointer to ipr command struct
698 struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_hrr_queue *hrrq)
700 struct ipr_cmnd *ipr_cmd = NULL;
702 if (likely(!list_empty(&hrrq->hrrq_free_q))) {
703 ipr_cmd = list_entry(hrrq->hrrq_free_q.next,
704 struct ipr_cmnd, queue);
705 list_del(&ipr_cmd->queue);
713 * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
714 * @ioa_cfg: ioa config struct
717 * pointer to ipr command struct
720 struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
722 struct ipr_cmnd *ipr_cmd =
723 __ipr_get_free_ipr_cmnd(&ioa_cfg->hrrq[IPR_INIT_HRRQ]);
724 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
729 * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
730 * @ioa_cfg: ioa config struct
731 * @clr_ints: interrupts to clear
733 * This function masks all interrupts on the adapter, then clears the
734 * interrupts specified in the mask
739 static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
742 volatile u32 int_reg;
745 /* Stop new interrupts */
746 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
747 spin_lock(&ioa_cfg->hrrq[i]._lock);
748 ioa_cfg->hrrq[i].allow_interrupts = 0;
749 spin_unlock(&ioa_cfg->hrrq[i]._lock);
753 /* Set interrupt mask to stop all new interrupts */
755 writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
757 writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
759 /* Clear any pending interrupts */
761 writel(~0, ioa_cfg->regs.clr_interrupt_reg);
762 writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
763 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
767 * ipr_save_pcix_cmd_reg - Save PCI-X command register
768 * @ioa_cfg: ioa config struct
771 * 0 on success / -EIO on failure
773 static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
775 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
777 if (pcix_cmd_reg == 0)
780 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
781 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
782 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
786 ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
791 * ipr_set_pcix_cmd_reg - Setup PCI-X command register
792 * @ioa_cfg: ioa config struct
795 * 0 on success / -EIO on failure
797 static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
799 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
802 if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
803 ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
804 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
813 * ipr_sata_eh_done - done function for aborted SATA commands
814 * @ipr_cmd: ipr command struct
816 * This function is invoked for ops generated to SATA
817 * devices which are being aborted.
822 static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
824 struct ata_queued_cmd *qc = ipr_cmd->qc;
825 struct ipr_sata_port *sata_port = qc->ap->private_data;
827 qc->err_mask |= AC_ERR_OTHER;
828 sata_port->ioasa.status |= ATA_BUSY;
829 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
834 * ipr_scsi_eh_done - mid-layer done function for aborted ops
835 * @ipr_cmd: ipr command struct
837 * This function is invoked by the interrupt handler for
838 * ops generated by the SCSI mid-layer which are being aborted.
843 static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
845 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
847 scsi_cmd->result |= (DID_ERROR << 16);
849 scsi_dma_unmap(ipr_cmd->scsi_cmd);
850 scsi_cmd->scsi_done(scsi_cmd);
851 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
855 * ipr_fail_all_ops - Fails all outstanding ops.
856 * @ioa_cfg: ioa config struct
858 * This function fails all outstanding ops.
863 static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
865 struct ipr_cmnd *ipr_cmd, *temp;
866 struct ipr_hrr_queue *hrrq;
869 for_each_hrrq(hrrq, ioa_cfg) {
870 spin_lock(&hrrq->_lock);
871 list_for_each_entry_safe(ipr_cmd,
872 temp, &hrrq->hrrq_pending_q, queue) {
873 list_del(&ipr_cmd->queue);
875 ipr_cmd->s.ioasa.hdr.ioasc =
876 cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
877 ipr_cmd->s.ioasa.hdr.ilid =
878 cpu_to_be32(IPR_DRIVER_ILID);
880 if (ipr_cmd->scsi_cmd)
881 ipr_cmd->done = ipr_scsi_eh_done;
882 else if (ipr_cmd->qc)
883 ipr_cmd->done = ipr_sata_eh_done;
885 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH,
886 IPR_IOASC_IOA_WAS_RESET);
887 del_timer(&ipr_cmd->timer);
888 ipr_cmd->done(ipr_cmd);
890 spin_unlock(&hrrq->_lock);
896 * ipr_send_command - Send driver initiated requests.
897 * @ipr_cmd: ipr command struct
899 * This function sends a command to the adapter using the correct write call.
900 * In the case of sis64, calculate the ioarcb size required. Then or in the
906 static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
908 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
909 dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
911 if (ioa_cfg->sis64) {
912 /* The default size is 256 bytes */
913 send_dma_addr |= 0x1;
915 /* If the number of ioadls * size of ioadl > 128 bytes,
916 then use a 512 byte ioarcb */
917 if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
918 send_dma_addr |= 0x4;
919 writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
921 writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
925 * ipr_do_req - Send driver initiated requests.
926 * @ipr_cmd: ipr command struct
927 * @done: done function
928 * @timeout_func: timeout function
929 * @timeout: timeout value
931 * This function sends the specified command to the adapter with the
932 * timeout given. The done function is invoked on command completion.
937 static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
938 void (*done) (struct ipr_cmnd *),
939 void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
941 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
943 ipr_cmd->done = done;
945 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
946 ipr_cmd->timer.expires = jiffies + timeout;
947 ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
949 add_timer(&ipr_cmd->timer);
951 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
953 ipr_send_command(ipr_cmd);
957 * ipr_internal_cmd_done - Op done function for an internally generated op.
958 * @ipr_cmd: ipr command struct
960 * This function is the op done function for an internally generated,
961 * blocking op. It simply wakes the sleeping thread.
966 static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
968 if (ipr_cmd->sibling)
969 ipr_cmd->sibling = NULL;
971 complete(&ipr_cmd->completion);
975 * ipr_init_ioadl - initialize the ioadl for the correct SIS type
976 * @ipr_cmd: ipr command struct
977 * @dma_addr: dma address
978 * @len: transfer length
979 * @flags: ioadl flag value
981 * This function initializes an ioadl in the case where there is only a single
987 static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
990 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
991 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
993 ipr_cmd->dma_use_sg = 1;
995 if (ipr_cmd->ioa_cfg->sis64) {
996 ioadl64->flags = cpu_to_be32(flags);
997 ioadl64->data_len = cpu_to_be32(len);
998 ioadl64->address = cpu_to_be64(dma_addr);
1000 ipr_cmd->ioarcb.ioadl_len =
1001 cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
1002 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1004 ioadl->flags_and_data_len = cpu_to_be32(flags | len);
1005 ioadl->address = cpu_to_be32(dma_addr);
1007 if (flags == IPR_IOADL_FLAGS_READ_LAST) {
1008 ipr_cmd->ioarcb.read_ioadl_len =
1009 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1010 ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
1012 ipr_cmd->ioarcb.ioadl_len =
1013 cpu_to_be32(sizeof(struct ipr_ioadl_desc));
1014 ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
1020 * ipr_send_blocking_cmd - Send command and sleep on its completion.
1021 * @ipr_cmd: ipr command struct
1022 * @timeout_func: function to invoke if command times out
1028 static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
1029 void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
1032 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1034 init_completion(&ipr_cmd->completion);
1035 ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
1037 spin_unlock_irq(ioa_cfg->host->host_lock);
1038 wait_for_completion(&ipr_cmd->completion);
1039 spin_lock_irq(ioa_cfg->host->host_lock);
1042 static int ipr_get_hrrq_index(struct ipr_ioa_cfg *ioa_cfg)
1044 if (ioa_cfg->hrrq_num == 1)
1047 return (atomic_add_return(1, &ioa_cfg->hrrq_index) % (ioa_cfg->hrrq_num - 1)) + 1;
1051 * ipr_send_hcam - Send an HCAM to the adapter.
1052 * @ioa_cfg: ioa config struct
1054 * @hostrcb: hostrcb struct
1056 * This function will send a Host Controlled Async command to the adapter.
1057 * If HCAMs are currently not allowed to be issued to the adapter, it will
1058 * place the hostrcb on the free queue.
1063 static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
1064 struct ipr_hostrcb *hostrcb)
1066 struct ipr_cmnd *ipr_cmd;
1067 struct ipr_ioarcb *ioarcb;
1069 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
1070 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
1071 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
1072 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
1074 ipr_cmd->u.hostrcb = hostrcb;
1075 ioarcb = &ipr_cmd->ioarcb;
1077 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
1078 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
1079 ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
1080 ioarcb->cmd_pkt.cdb[1] = type;
1081 ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
1082 ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
1084 ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
1085 sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
1087 if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
1088 ipr_cmd->done = ipr_process_ccn;
1090 ipr_cmd->done = ipr_process_error;
1092 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
1094 ipr_send_command(ipr_cmd);
1096 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
1101 * ipr_update_ata_class - Update the ata class in the resource entry
1102 * @res: resource entry struct
1103 * @proto: cfgte device bus protocol value
1108 static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
1111 case IPR_PROTO_SATA:
1112 case IPR_PROTO_SAS_STP:
1113 res->ata_class = ATA_DEV_ATA;
1115 case IPR_PROTO_SATA_ATAPI:
1116 case IPR_PROTO_SAS_STP_ATAPI:
1117 res->ata_class = ATA_DEV_ATAPI;
1120 res->ata_class = ATA_DEV_UNKNOWN;
1126 * ipr_init_res_entry - Initialize a resource entry struct.
1127 * @res: resource entry struct
1128 * @cfgtew: config table entry wrapper struct
1133 static void ipr_init_res_entry(struct ipr_resource_entry *res,
1134 struct ipr_config_table_entry_wrapper *cfgtew)
1138 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1139 struct ipr_resource_entry *gscsi_res = NULL;
1141 res->needs_sync_complete = 0;
1144 res->del_from_ml = 0;
1145 res->resetting_device = 0;
1147 res->sata_port = NULL;
1149 if (ioa_cfg->sis64) {
1150 proto = cfgtew->u.cfgte64->proto;
1151 res->res_flags = cfgtew->u.cfgte64->res_flags;
1152 res->qmodel = IPR_QUEUEING_MODEL64(res);
1153 res->type = cfgtew->u.cfgte64->res_type;
1155 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1156 sizeof(res->res_path));
1159 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1160 sizeof(res->dev_lun.scsi_lun));
1161 res->lun = scsilun_to_int(&res->dev_lun);
1163 if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1164 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
1165 if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
1167 res->target = gscsi_res->target;
1172 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1173 ioa_cfg->max_devs_supported);
1174 set_bit(res->target, ioa_cfg->target_ids);
1176 } else if (res->type == IPR_RES_TYPE_IOAFP) {
1177 res->bus = IPR_IOAFP_VIRTUAL_BUS;
1179 } else if (res->type == IPR_RES_TYPE_ARRAY) {
1180 res->bus = IPR_ARRAY_VIRTUAL_BUS;
1181 res->target = find_first_zero_bit(ioa_cfg->array_ids,
1182 ioa_cfg->max_devs_supported);
1183 set_bit(res->target, ioa_cfg->array_ids);
1184 } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
1185 res->bus = IPR_VSET_VIRTUAL_BUS;
1186 res->target = find_first_zero_bit(ioa_cfg->vset_ids,
1187 ioa_cfg->max_devs_supported);
1188 set_bit(res->target, ioa_cfg->vset_ids);
1190 res->target = find_first_zero_bit(ioa_cfg->target_ids,
1191 ioa_cfg->max_devs_supported);
1192 set_bit(res->target, ioa_cfg->target_ids);
1195 proto = cfgtew->u.cfgte->proto;
1196 res->qmodel = IPR_QUEUEING_MODEL(res);
1197 res->flags = cfgtew->u.cfgte->flags;
1198 if (res->flags & IPR_IS_IOA_RESOURCE)
1199 res->type = IPR_RES_TYPE_IOAFP;
1201 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1203 res->bus = cfgtew->u.cfgte->res_addr.bus;
1204 res->target = cfgtew->u.cfgte->res_addr.target;
1205 res->lun = cfgtew->u.cfgte->res_addr.lun;
1206 res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
1209 ipr_update_ata_class(res, proto);
1213 * ipr_is_same_device - Determine if two devices are the same.
1214 * @res: resource entry struct
1215 * @cfgtew: config table entry wrapper struct
1218 * 1 if the devices are the same / 0 otherwise
1220 static int ipr_is_same_device(struct ipr_resource_entry *res,
1221 struct ipr_config_table_entry_wrapper *cfgtew)
1223 if (res->ioa_cfg->sis64) {
1224 if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
1225 sizeof(cfgtew->u.cfgte64->dev_id)) &&
1226 !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1227 sizeof(cfgtew->u.cfgte64->lun))) {
1231 if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
1232 res->target == cfgtew->u.cfgte->res_addr.target &&
1233 res->lun == cfgtew->u.cfgte->res_addr.lun)
1241 * __ipr_format_res_path - Format the resource path for printing.
1242 * @res_path: resource path
1244 * @len: length of buffer provided
1249 static char *__ipr_format_res_path(u8 *res_path, char *buffer, int len)
1255 p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
1256 for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
1257 p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
1263 * ipr_format_res_path - Format the resource path for printing.
1264 * @ioa_cfg: ioa config struct
1265 * @res_path: resource path
1267 * @len: length of buffer provided
1272 static char *ipr_format_res_path(struct ipr_ioa_cfg *ioa_cfg,
1273 u8 *res_path, char *buffer, int len)
1278 p += snprintf(p, buffer + len - p, "%d/", ioa_cfg->host->host_no);
1279 __ipr_format_res_path(res_path, p, len - (buffer - p));
1284 * ipr_update_res_entry - Update the resource entry.
1285 * @res: resource entry struct
1286 * @cfgtew: config table entry wrapper struct
1291 static void ipr_update_res_entry(struct ipr_resource_entry *res,
1292 struct ipr_config_table_entry_wrapper *cfgtew)
1294 char buffer[IPR_MAX_RES_PATH_LENGTH];
1298 if (res->ioa_cfg->sis64) {
1299 res->flags = cfgtew->u.cfgte64->flags;
1300 res->res_flags = cfgtew->u.cfgte64->res_flags;
1301 res->type = cfgtew->u.cfgte64->res_type;
1303 memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
1304 sizeof(struct ipr_std_inq_data));
1306 res->qmodel = IPR_QUEUEING_MODEL64(res);
1307 proto = cfgtew->u.cfgte64->proto;
1308 res->res_handle = cfgtew->u.cfgte64->res_handle;
1309 res->dev_id = cfgtew->u.cfgte64->dev_id;
1311 memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
1312 sizeof(res->dev_lun.scsi_lun));
1314 if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
1315 sizeof(res->res_path))) {
1316 memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
1317 sizeof(res->res_path));
1321 if (res->sdev && new_path)
1322 sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
1323 ipr_format_res_path(res->ioa_cfg,
1324 res->res_path, buffer, sizeof(buffer)));
1326 res->flags = cfgtew->u.cfgte->flags;
1327 if (res->flags & IPR_IS_IOA_RESOURCE)
1328 res->type = IPR_RES_TYPE_IOAFP;
1330 res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
1332 memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
1333 sizeof(struct ipr_std_inq_data));
1335 res->qmodel = IPR_QUEUEING_MODEL(res);
1336 proto = cfgtew->u.cfgte->proto;
1337 res->res_handle = cfgtew->u.cfgte->res_handle;
1340 ipr_update_ata_class(res, proto);
1344 * ipr_clear_res_target - Clear the bit in the bit map representing the target
1346 * @res: resource entry struct
1347 * @cfgtew: config table entry wrapper struct
1352 static void ipr_clear_res_target(struct ipr_resource_entry *res)
1354 struct ipr_resource_entry *gscsi_res = NULL;
1355 struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
1357 if (!ioa_cfg->sis64)
1360 if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
1361 clear_bit(res->target, ioa_cfg->array_ids);
1362 else if (res->bus == IPR_VSET_VIRTUAL_BUS)
1363 clear_bit(res->target, ioa_cfg->vset_ids);
1364 else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
1365 list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
1366 if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
1368 clear_bit(res->target, ioa_cfg->target_ids);
1370 } else if (res->bus == 0)
1371 clear_bit(res->target, ioa_cfg->target_ids);
1375 * ipr_handle_config_change - Handle a config change from the adapter
1376 * @ioa_cfg: ioa config struct
1382 static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
1383 struct ipr_hostrcb *hostrcb)
1385 struct ipr_resource_entry *res = NULL;
1386 struct ipr_config_table_entry_wrapper cfgtew;
1387 __be32 cc_res_handle;
1391 if (ioa_cfg->sis64) {
1392 cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
1393 cc_res_handle = cfgtew.u.cfgte64->res_handle;
1395 cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
1396 cc_res_handle = cfgtew.u.cfgte->res_handle;
1399 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
1400 if (res->res_handle == cc_res_handle) {
1407 if (list_empty(&ioa_cfg->free_res_q)) {
1408 ipr_send_hcam(ioa_cfg,
1409 IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
1414 res = list_entry(ioa_cfg->free_res_q.next,
1415 struct ipr_resource_entry, queue);
1417 list_del(&res->queue);
1418 ipr_init_res_entry(res, &cfgtew);
1419 list_add_tail(&res->queue, &ioa_cfg->used_res_q);
1422 ipr_update_res_entry(res, &cfgtew);
1424 if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
1426 res->del_from_ml = 1;
1427 res->res_handle = IPR_INVALID_RES_HANDLE;
1428 if (ioa_cfg->allow_ml_add_del)
1429 schedule_work(&ioa_cfg->work_q);
1431 ipr_clear_res_target(res);
1432 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
1434 } else if (!res->sdev || res->del_from_ml) {
1436 if (ioa_cfg->allow_ml_add_del)
1437 schedule_work(&ioa_cfg->work_q);
1440 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1444 * ipr_process_ccn - Op done function for a CCN.
1445 * @ipr_cmd: ipr command struct
1447 * This function is the op done function for a configuration
1448 * change notification host controlled async from the adapter.
1453 static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
1455 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1456 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1457 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
1459 list_del(&hostrcb->queue);
1460 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
1463 if (ioasc != IPR_IOASC_IOA_WAS_RESET)
1464 dev_err(&ioa_cfg->pdev->dev,
1465 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
1467 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
1469 ipr_handle_config_change(ioa_cfg, hostrcb);
1474 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
1475 * @i: index into buffer
1476 * @buf: string to modify
1478 * This function will strip all trailing whitespace, pad the end
1479 * of the string with a single space, and NULL terminate the string.
1482 * new length of string
1484 static int strip_and_pad_whitespace(int i, char *buf)
1486 while (i && buf[i] == ' ')
1494 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
1495 * @prefix: string to print at start of printk
1496 * @hostrcb: hostrcb pointer
1497 * @vpd: vendor/product id/sn struct
1502 static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1503 struct ipr_vpd *vpd)
1505 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
1508 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1509 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
1511 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
1512 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
1514 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1515 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1517 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1521 * ipr_log_vpd - Log the passed VPD to the error log.
1522 * @vpd: vendor/product id/sn struct
1527 static void ipr_log_vpd(struct ipr_vpd *vpd)
1529 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
1530 + IPR_SERIAL_NUM_LEN];
1532 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
1533 memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
1535 buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
1536 ipr_err("Vendor/Product ID: %s\n", buffer);
1538 memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
1539 buffer[IPR_SERIAL_NUM_LEN] = '\0';
1540 ipr_err(" Serial Number: %s\n", buffer);
1544 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1545 * @prefix: string to print at start of printk
1546 * @hostrcb: hostrcb pointer
1547 * @vpd: vendor/product id/sn/wwn struct
1552 static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1553 struct ipr_ext_vpd *vpd)
1555 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1556 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1557 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1561 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
1562 * @vpd: vendor/product id/sn/wwn struct
1567 static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
1569 ipr_log_vpd(&vpd->vpd);
1570 ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
1571 be32_to_cpu(vpd->wwid[1]));
1575 * ipr_log_enhanced_cache_error - Log a cache error.
1576 * @ioa_cfg: ioa config struct
1577 * @hostrcb: hostrcb struct
1582 static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1583 struct ipr_hostrcb *hostrcb)
1585 struct ipr_hostrcb_type_12_error *error;
1588 error = &hostrcb->hcam.u.error64.u.type_12_error;
1590 error = &hostrcb->hcam.u.error.u.type_12_error;
1592 ipr_err("-----Current Configuration-----\n");
1593 ipr_err("Cache Directory Card Information:\n");
1594 ipr_log_ext_vpd(&error->ioa_vpd);
1595 ipr_err("Adapter Card Information:\n");
1596 ipr_log_ext_vpd(&error->cfc_vpd);
1598 ipr_err("-----Expected Configuration-----\n");
1599 ipr_err("Cache Directory Card Information:\n");
1600 ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
1601 ipr_err("Adapter Card Information:\n");
1602 ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
1604 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1605 be32_to_cpu(error->ioa_data[0]),
1606 be32_to_cpu(error->ioa_data[1]),
1607 be32_to_cpu(error->ioa_data[2]));
1611 * ipr_log_cache_error - Log a cache error.
1612 * @ioa_cfg: ioa config struct
1613 * @hostrcb: hostrcb struct
1618 static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
1619 struct ipr_hostrcb *hostrcb)
1621 struct ipr_hostrcb_type_02_error *error =
1622 &hostrcb->hcam.u.error.u.type_02_error;
1624 ipr_err("-----Current Configuration-----\n");
1625 ipr_err("Cache Directory Card Information:\n");
1626 ipr_log_vpd(&error->ioa_vpd);
1627 ipr_err("Adapter Card Information:\n");
1628 ipr_log_vpd(&error->cfc_vpd);
1630 ipr_err("-----Expected Configuration-----\n");
1631 ipr_err("Cache Directory Card Information:\n");
1632 ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
1633 ipr_err("Adapter Card Information:\n");
1634 ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
1636 ipr_err("Additional IOA Data: %08X %08X %08X\n",
1637 be32_to_cpu(error->ioa_data[0]),
1638 be32_to_cpu(error->ioa_data[1]),
1639 be32_to_cpu(error->ioa_data[2]));
1643 * ipr_log_enhanced_config_error - Log a configuration error.
1644 * @ioa_cfg: ioa config struct
1645 * @hostrcb: hostrcb struct
1650 static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
1651 struct ipr_hostrcb *hostrcb)
1653 int errors_logged, i;
1654 struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
1655 struct ipr_hostrcb_type_13_error *error;
1657 error = &hostrcb->hcam.u.error.u.type_13_error;
1658 errors_logged = be32_to_cpu(error->errors_logged);
1660 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1661 be32_to_cpu(error->errors_detected), errors_logged);
1663 dev_entry = error->dev;
1665 for (i = 0; i < errors_logged; i++, dev_entry++) {
1668 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1669 ipr_log_ext_vpd(&dev_entry->vpd);
1671 ipr_err("-----New Device Information-----\n");
1672 ipr_log_ext_vpd(&dev_entry->new_vpd);
1674 ipr_err("Cache Directory Card Information:\n");
1675 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1677 ipr_err("Adapter Card Information:\n");
1678 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1683 * ipr_log_sis64_config_error - Log a device error.
1684 * @ioa_cfg: ioa config struct
1685 * @hostrcb: hostrcb struct
1690 static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
1691 struct ipr_hostrcb *hostrcb)
1693 int errors_logged, i;
1694 struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
1695 struct ipr_hostrcb_type_23_error *error;
1696 char buffer[IPR_MAX_RES_PATH_LENGTH];
1698 error = &hostrcb->hcam.u.error64.u.type_23_error;
1699 errors_logged = be32_to_cpu(error->errors_logged);
1701 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1702 be32_to_cpu(error->errors_detected), errors_logged);
1704 dev_entry = error->dev;
1706 for (i = 0; i < errors_logged; i++, dev_entry++) {
1709 ipr_err("Device %d : %s", i + 1,
1710 __ipr_format_res_path(dev_entry->res_path,
1711 buffer, sizeof(buffer)));
1712 ipr_log_ext_vpd(&dev_entry->vpd);
1714 ipr_err("-----New Device Information-----\n");
1715 ipr_log_ext_vpd(&dev_entry->new_vpd);
1717 ipr_err("Cache Directory Card Information:\n");
1718 ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
1720 ipr_err("Adapter Card Information:\n");
1721 ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
1726 * ipr_log_config_error - Log a configuration error.
1727 * @ioa_cfg: ioa config struct
1728 * @hostrcb: hostrcb struct
1733 static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
1734 struct ipr_hostrcb *hostrcb)
1736 int errors_logged, i;
1737 struct ipr_hostrcb_device_data_entry *dev_entry;
1738 struct ipr_hostrcb_type_03_error *error;
1740 error = &hostrcb->hcam.u.error.u.type_03_error;
1741 errors_logged = be32_to_cpu(error->errors_logged);
1743 ipr_err("Device Errors Detected/Logged: %d/%d\n",
1744 be32_to_cpu(error->errors_detected), errors_logged);
1746 dev_entry = error->dev;
1748 for (i = 0; i < errors_logged; i++, dev_entry++) {
1751 ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
1752 ipr_log_vpd(&dev_entry->vpd);
1754 ipr_err("-----New Device Information-----\n");
1755 ipr_log_vpd(&dev_entry->new_vpd);
1757 ipr_err("Cache Directory Card Information:\n");
1758 ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
1760 ipr_err("Adapter Card Information:\n");
1761 ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
1763 ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
1764 be32_to_cpu(dev_entry->ioa_data[0]),
1765 be32_to_cpu(dev_entry->ioa_data[1]),
1766 be32_to_cpu(dev_entry->ioa_data[2]),
1767 be32_to_cpu(dev_entry->ioa_data[3]),
1768 be32_to_cpu(dev_entry->ioa_data[4]));
1773 * ipr_log_enhanced_array_error - Log an array configuration error.
1774 * @ioa_cfg: ioa config struct
1775 * @hostrcb: hostrcb struct
1780 static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
1781 struct ipr_hostrcb *hostrcb)
1784 struct ipr_hostrcb_type_14_error *error;
1785 struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
1786 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1788 error = &hostrcb->hcam.u.error.u.type_14_error;
1792 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1793 error->protection_level,
1794 ioa_cfg->host->host_no,
1795 error->last_func_vset_res_addr.bus,
1796 error->last_func_vset_res_addr.target,
1797 error->last_func_vset_res_addr.lun);
1801 array_entry = error->array_member;
1802 num_entries = min_t(u32, be32_to_cpu(error->num_entries),
1803 ARRAY_SIZE(error->array_member));
1805 for (i = 0; i < num_entries; i++, array_entry++) {
1806 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1809 if (be32_to_cpu(error->exposed_mode_adn) == i)
1810 ipr_err("Exposed Array Member %d:\n", i);
1812 ipr_err("Array Member %d:\n", i);
1814 ipr_log_ext_vpd(&array_entry->vpd);
1815 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1816 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1817 "Expected Location");
1824 * ipr_log_array_error - Log an array configuration error.
1825 * @ioa_cfg: ioa config struct
1826 * @hostrcb: hostrcb struct
1831 static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
1832 struct ipr_hostrcb *hostrcb)
1835 struct ipr_hostrcb_type_04_error *error;
1836 struct ipr_hostrcb_array_data_entry *array_entry;
1837 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
1839 error = &hostrcb->hcam.u.error.u.type_04_error;
1843 ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
1844 error->protection_level,
1845 ioa_cfg->host->host_no,
1846 error->last_func_vset_res_addr.bus,
1847 error->last_func_vset_res_addr.target,
1848 error->last_func_vset_res_addr.lun);
1852 array_entry = error->array_member;
1854 for (i = 0; i < 18; i++) {
1855 if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
1858 if (be32_to_cpu(error->exposed_mode_adn) == i)
1859 ipr_err("Exposed Array Member %d:\n", i);
1861 ipr_err("Array Member %d:\n", i);
1863 ipr_log_vpd(&array_entry->vpd);
1865 ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
1866 ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
1867 "Expected Location");
1872 array_entry = error->array_member2;
1879 * ipr_log_hex_data - Log additional hex IOA error data.
1880 * @ioa_cfg: ioa config struct
1881 * @data: IOA error data
1887 static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
1894 if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
1895 len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
1897 for (i = 0; i < len / 4; i += 4) {
1898 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
1899 be32_to_cpu(data[i]),
1900 be32_to_cpu(data[i+1]),
1901 be32_to_cpu(data[i+2]),
1902 be32_to_cpu(data[i+3]));
1907 * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
1908 * @ioa_cfg: ioa config struct
1909 * @hostrcb: hostrcb struct
1914 static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1915 struct ipr_hostrcb *hostrcb)
1917 struct ipr_hostrcb_type_17_error *error;
1920 error = &hostrcb->hcam.u.error64.u.type_17_error;
1922 error = &hostrcb->hcam.u.error.u.type_17_error;
1924 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1925 strim(error->failure_reason);
1927 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1928 be32_to_cpu(hostrcb->hcam.u.error.prc));
1929 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1930 ipr_log_hex_data(ioa_cfg, error->data,
1931 be32_to_cpu(hostrcb->hcam.length) -
1932 (offsetof(struct ipr_hostrcb_error, u) +
1933 offsetof(struct ipr_hostrcb_type_17_error, data)));
1937 * ipr_log_dual_ioa_error - Log a dual adapter error.
1938 * @ioa_cfg: ioa config struct
1939 * @hostrcb: hostrcb struct
1944 static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1945 struct ipr_hostrcb *hostrcb)
1947 struct ipr_hostrcb_type_07_error *error;
1949 error = &hostrcb->hcam.u.error.u.type_07_error;
1950 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1951 strim(error->failure_reason);
1953 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1954 be32_to_cpu(hostrcb->hcam.u.error.prc));
1955 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1956 ipr_log_hex_data(ioa_cfg, error->data,
1957 be32_to_cpu(hostrcb->hcam.length) -
1958 (offsetof(struct ipr_hostrcb_error, u) +
1959 offsetof(struct ipr_hostrcb_type_07_error, data)));
1962 static const struct {
1965 } path_active_desc[] = {
1966 { IPR_PATH_NO_INFO, "Path" },
1967 { IPR_PATH_ACTIVE, "Active path" },
1968 { IPR_PATH_NOT_ACTIVE, "Inactive path" }
1971 static const struct {
1974 } path_state_desc[] = {
1975 { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
1976 { IPR_PATH_HEALTHY, "is healthy" },
1977 { IPR_PATH_DEGRADED, "is degraded" },
1978 { IPR_PATH_FAILED, "is failed" }
1982 * ipr_log_fabric_path - Log a fabric path error
1983 * @hostrcb: hostrcb struct
1984 * @fabric: fabric descriptor
1989 static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
1990 struct ipr_hostrcb_fabric_desc *fabric)
1993 u8 path_state = fabric->path_state;
1994 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
1995 u8 state = path_state & IPR_PATH_STATE_MASK;
1997 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
1998 if (path_active_desc[i].active != active)
2001 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2002 if (path_state_desc[j].state != state)
2005 if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
2006 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
2007 path_active_desc[i].desc, path_state_desc[j].desc,
2009 } else if (fabric->cascaded_expander == 0xff) {
2010 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
2011 path_active_desc[i].desc, path_state_desc[j].desc,
2012 fabric->ioa_port, fabric->phy);
2013 } else if (fabric->phy == 0xff) {
2014 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
2015 path_active_desc[i].desc, path_state_desc[j].desc,
2016 fabric->ioa_port, fabric->cascaded_expander);
2018 ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
2019 path_active_desc[i].desc, path_state_desc[j].desc,
2020 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2026 ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
2027 fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
2031 * ipr_log64_fabric_path - Log a fabric path error
2032 * @hostrcb: hostrcb struct
2033 * @fabric: fabric descriptor
2038 static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
2039 struct ipr_hostrcb64_fabric_desc *fabric)
2042 u8 path_state = fabric->path_state;
2043 u8 active = path_state & IPR_PATH_ACTIVE_MASK;
2044 u8 state = path_state & IPR_PATH_STATE_MASK;
2045 char buffer[IPR_MAX_RES_PATH_LENGTH];
2047 for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
2048 if (path_active_desc[i].active != active)
2051 for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
2052 if (path_state_desc[j].state != state)
2055 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
2056 path_active_desc[i].desc, path_state_desc[j].desc,
2057 ipr_format_res_path(hostrcb->ioa_cfg,
2059 buffer, sizeof(buffer)));
2064 ipr_err("Path state=%02X Resource Path=%s\n", path_state,
2065 ipr_format_res_path(hostrcb->ioa_cfg, fabric->res_path,
2066 buffer, sizeof(buffer)));
2069 static const struct {
2072 } path_type_desc[] = {
2073 { IPR_PATH_CFG_IOA_PORT, "IOA port" },
2074 { IPR_PATH_CFG_EXP_PORT, "Expander port" },
2075 { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
2076 { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
2079 static const struct {
2082 } path_status_desc[] = {
2083 { IPR_PATH_CFG_NO_PROB, "Functional" },
2084 { IPR_PATH_CFG_DEGRADED, "Degraded" },
2085 { IPR_PATH_CFG_FAILED, "Failed" },
2086 { IPR_PATH_CFG_SUSPECT, "Suspect" },
2087 { IPR_PATH_NOT_DETECTED, "Missing" },
2088 { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
2091 static const char *link_rate[] = {
2094 "phy reset problem",
2111 * ipr_log_path_elem - Log a fabric path element.
2112 * @hostrcb: hostrcb struct
2113 * @cfg: fabric path element struct
2118 static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
2119 struct ipr_hostrcb_config_element *cfg)
2122 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2123 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2125 if (type == IPR_PATH_CFG_NOT_EXIST)
2128 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2129 if (path_type_desc[i].type != type)
2132 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2133 if (path_status_desc[j].status != status)
2136 if (type == IPR_PATH_CFG_IOA_PORT) {
2137 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
2138 path_status_desc[j].desc, path_type_desc[i].desc,
2139 cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2140 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2142 if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
2143 ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
2144 path_status_desc[j].desc, path_type_desc[i].desc,
2145 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2146 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2147 } else if (cfg->cascaded_expander == 0xff) {
2148 ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
2149 "WWN=%08X%08X\n", path_status_desc[j].desc,
2150 path_type_desc[i].desc, cfg->phy,
2151 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2152 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2153 } else if (cfg->phy == 0xff) {
2154 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
2155 "WWN=%08X%08X\n", path_status_desc[j].desc,
2156 path_type_desc[i].desc, cfg->cascaded_expander,
2157 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2158 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2160 ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
2161 "WWN=%08X%08X\n", path_status_desc[j].desc,
2162 path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
2163 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2164 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2171 ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
2172 "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
2173 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2174 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2178 * ipr_log64_path_elem - Log a fabric path element.
2179 * @hostrcb: hostrcb struct
2180 * @cfg: fabric path element struct
2185 static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
2186 struct ipr_hostrcb64_config_element *cfg)
2189 u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
2190 u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
2191 u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
2192 char buffer[IPR_MAX_RES_PATH_LENGTH];
2194 if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
2197 for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
2198 if (path_type_desc[i].type != type)
2201 for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
2202 if (path_status_desc[j].status != status)
2205 ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
2206 path_status_desc[j].desc, path_type_desc[i].desc,
2207 ipr_format_res_path(hostrcb->ioa_cfg,
2208 cfg->res_path, buffer, sizeof(buffer)),
2209 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2210 be32_to_cpu(cfg->wwid[0]),
2211 be32_to_cpu(cfg->wwid[1]));
2215 ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
2216 "WWN=%08X%08X\n", cfg->type_status,
2217 ipr_format_res_path(hostrcb->ioa_cfg,
2218 cfg->res_path, buffer, sizeof(buffer)),
2219 link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
2220 be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
2224 * ipr_log_fabric_error - Log a fabric error.
2225 * @ioa_cfg: ioa config struct
2226 * @hostrcb: hostrcb struct
2231 static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2232 struct ipr_hostrcb *hostrcb)
2234 struct ipr_hostrcb_type_20_error *error;
2235 struct ipr_hostrcb_fabric_desc *fabric;
2236 struct ipr_hostrcb_config_element *cfg;
2239 error = &hostrcb->hcam.u.error.u.type_20_error;
2240 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2241 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2243 add_len = be32_to_cpu(hostrcb->hcam.length) -
2244 (offsetof(struct ipr_hostrcb_error, u) +
2245 offsetof(struct ipr_hostrcb_type_20_error, desc));
2247 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2248 ipr_log_fabric_path(hostrcb, fabric);
2249 for_each_fabric_cfg(fabric, cfg)
2250 ipr_log_path_elem(hostrcb, cfg);
2252 add_len -= be16_to_cpu(fabric->length);
2253 fabric = (struct ipr_hostrcb_fabric_desc *)
2254 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2257 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2261 * ipr_log_sis64_array_error - Log a sis64 array error.
2262 * @ioa_cfg: ioa config struct
2263 * @hostrcb: hostrcb struct
2268 static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
2269 struct ipr_hostrcb *hostrcb)
2272 struct ipr_hostrcb_type_24_error *error;
2273 struct ipr_hostrcb64_array_data_entry *array_entry;
2274 char buffer[IPR_MAX_RES_PATH_LENGTH];
2275 const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
2277 error = &hostrcb->hcam.u.error64.u.type_24_error;
2281 ipr_err("RAID %s Array Configuration: %s\n",
2282 error->protection_level,
2283 ipr_format_res_path(ioa_cfg, error->last_res_path,
2284 buffer, sizeof(buffer)));
2288 array_entry = error->array_member;
2289 num_entries = min_t(u32, error->num_entries,
2290 ARRAY_SIZE(error->array_member));
2292 for (i = 0; i < num_entries; i++, array_entry++) {
2294 if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
2297 if (error->exposed_mode_adn == i)
2298 ipr_err("Exposed Array Member %d:\n", i);
2300 ipr_err("Array Member %d:\n", i);
2302 ipr_err("Array Member %d:\n", i);
2303 ipr_log_ext_vpd(&array_entry->vpd);
2304 ipr_err("Current Location: %s\n",
2305 ipr_format_res_path(ioa_cfg, array_entry->res_path,
2306 buffer, sizeof(buffer)));
2307 ipr_err("Expected Location: %s\n",
2308 ipr_format_res_path(ioa_cfg,
2309 array_entry->expected_res_path,
2310 buffer, sizeof(buffer)));
2317 * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
2318 * @ioa_cfg: ioa config struct
2319 * @hostrcb: hostrcb struct
2324 static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
2325 struct ipr_hostrcb *hostrcb)
2327 struct ipr_hostrcb_type_30_error *error;
2328 struct ipr_hostrcb64_fabric_desc *fabric;
2329 struct ipr_hostrcb64_config_element *cfg;
2332 error = &hostrcb->hcam.u.error64.u.type_30_error;
2334 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
2335 ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
2337 add_len = be32_to_cpu(hostrcb->hcam.length) -
2338 (offsetof(struct ipr_hostrcb64_error, u) +
2339 offsetof(struct ipr_hostrcb_type_30_error, desc));
2341 for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
2342 ipr_log64_fabric_path(hostrcb, fabric);
2343 for_each_fabric_cfg(fabric, cfg)
2344 ipr_log64_path_elem(hostrcb, cfg);
2346 add_len -= be16_to_cpu(fabric->length);
2347 fabric = (struct ipr_hostrcb64_fabric_desc *)
2348 ((unsigned long)fabric + be16_to_cpu(fabric->length));
2351 ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
2355 * ipr_log_generic_error - Log an adapter error.
2356 * @ioa_cfg: ioa config struct
2357 * @hostrcb: hostrcb struct
2362 static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
2363 struct ipr_hostrcb *hostrcb)
2365 ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
2366 be32_to_cpu(hostrcb->hcam.length));
2370 * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
2373 * This function will return the index of into the ipr_error_table
2374 * for the specified IOASC. If the IOASC is not in the table,
2375 * 0 will be returned, which points to the entry used for unknown errors.
2378 * index into the ipr_error_table
2380 static u32 ipr_get_error(u32 ioasc)
2384 for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
2385 if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
2392 * ipr_handle_log_data - Log an adapter error.
2393 * @ioa_cfg: ioa config struct
2394 * @hostrcb: hostrcb struct
2396 * This function logs an adapter error to the system.
2401 static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
2402 struct ipr_hostrcb *hostrcb)
2407 if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
2410 if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
2411 dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
2414 ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2416 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2418 if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
2419 ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
2420 /* Tell the midlayer we had a bus reset so it will handle the UA properly */
2421 scsi_report_bus_reset(ioa_cfg->host,
2422 hostrcb->hcam.u.error.fd_res_addr.bus);
2425 error_index = ipr_get_error(ioasc);
2427 if (!ipr_error_table[error_index].log_hcam)
2430 ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
2432 /* Set indication we have logged an error */
2433 ioa_cfg->errors_logged++;
2435 if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
2437 if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
2438 hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
2440 switch (hostrcb->hcam.overlay_id) {
2441 case IPR_HOST_RCB_OVERLAY_ID_2:
2442 ipr_log_cache_error(ioa_cfg, hostrcb);
2444 case IPR_HOST_RCB_OVERLAY_ID_3:
2445 ipr_log_config_error(ioa_cfg, hostrcb);
2447 case IPR_HOST_RCB_OVERLAY_ID_4:
2448 case IPR_HOST_RCB_OVERLAY_ID_6:
2449 ipr_log_array_error(ioa_cfg, hostrcb);
2451 case IPR_HOST_RCB_OVERLAY_ID_7:
2452 ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
2454 case IPR_HOST_RCB_OVERLAY_ID_12:
2455 ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
2457 case IPR_HOST_RCB_OVERLAY_ID_13:
2458 ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
2460 case IPR_HOST_RCB_OVERLAY_ID_14:
2461 case IPR_HOST_RCB_OVERLAY_ID_16:
2462 ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
2464 case IPR_HOST_RCB_OVERLAY_ID_17:
2465 ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
2467 case IPR_HOST_RCB_OVERLAY_ID_20:
2468 ipr_log_fabric_error(ioa_cfg, hostrcb);
2470 case IPR_HOST_RCB_OVERLAY_ID_23:
2471 ipr_log_sis64_config_error(ioa_cfg, hostrcb);
2473 case IPR_HOST_RCB_OVERLAY_ID_24:
2474 case IPR_HOST_RCB_OVERLAY_ID_26:
2475 ipr_log_sis64_array_error(ioa_cfg, hostrcb);
2477 case IPR_HOST_RCB_OVERLAY_ID_30:
2478 ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
2480 case IPR_HOST_RCB_OVERLAY_ID_1:
2481 case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
2483 ipr_log_generic_error(ioa_cfg, hostrcb);
2489 * ipr_process_error - Op done function for an adapter error log.
2490 * @ipr_cmd: ipr command struct
2492 * This function is the op done function for an error log host
2493 * controlled async from the adapter. It will log the error and
2494 * send the HCAM back to the adapter.
2499 static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
2501 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2502 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
2503 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
2507 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
2509 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
2511 list_del(&hostrcb->queue);
2512 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
2515 ipr_handle_log_data(ioa_cfg, hostrcb);
2516 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
2517 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
2518 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
2519 dev_err(&ioa_cfg->pdev->dev,
2520 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
2523 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
2527 * ipr_timeout - An internally generated op has timed out.
2528 * @ipr_cmd: ipr command struct
2530 * This function blocks host requests and initiates an
2536 static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
2538 unsigned long lock_flags = 0;
2539 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2542 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2544 ioa_cfg->errors_logged++;
2545 dev_err(&ioa_cfg->pdev->dev,
2546 "Adapter being reset due to command timeout.\n");
2548 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2549 ioa_cfg->sdt_state = GET_DUMP;
2551 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
2552 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2554 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2559 * ipr_oper_timeout - Adapter timed out transitioning to operational
2560 * @ipr_cmd: ipr command struct
2562 * This function blocks host requests and initiates an
2568 static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
2570 unsigned long lock_flags = 0;
2571 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
2574 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2576 ioa_cfg->errors_logged++;
2577 dev_err(&ioa_cfg->pdev->dev,
2578 "Adapter timed out transitioning to operational.\n");
2580 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
2581 ioa_cfg->sdt_state = GET_DUMP;
2583 if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
2585 ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
2586 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
2589 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2594 * ipr_find_ses_entry - Find matching SES in SES table
2595 * @res: resource entry struct of SES
2598 * pointer to SES table entry / NULL on failure
2600 static const struct ipr_ses_table_entry *
2601 ipr_find_ses_entry(struct ipr_resource_entry *res)
2604 struct ipr_std_inq_vpids *vpids;
2605 const struct ipr_ses_table_entry *ste = ipr_ses_table;
2607 for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
2608 for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
2609 if (ste->compare_product_id_byte[j] == 'X') {
2610 vpids = &res->std_inq_data.vpids;
2611 if (vpids->product_id[j] == ste->product_id[j])
2619 if (matches == IPR_PROD_ID_LEN)
2627 * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
2628 * @ioa_cfg: ioa config struct
2630 * @bus_width: bus width
2633 * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
2634 * For a 2-byte wide SCSI bus, the maximum transfer speed is
2635 * twice the maximum transfer rate (e.g. for a wide enabled bus,
2636 * max 160MHz = max 320MB/sec).
2638 static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
2640 struct ipr_resource_entry *res;
2641 const struct ipr_ses_table_entry *ste;
2642 u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
2644 /* Loop through each config table entry in the config table buffer */
2645 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
2646 if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
2649 if (bus != res->bus)
2652 if (!(ste = ipr_find_ses_entry(res)))
2655 max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
2658 return max_xfer_rate;
2662 * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
2663 * @ioa_cfg: ioa config struct
2664 * @max_delay: max delay in micro-seconds to wait
2666 * Waits for an IODEBUG ACK from the IOA, doing busy looping.
2669 * 0 on success / other on failure
2671 static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
2673 volatile u32 pcii_reg;
2676 /* Read interrupt reg until IOA signals IO Debug Acknowledge */
2677 while (delay < max_delay) {
2678 pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
2680 if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
2683 /* udelay cannot be used if delay is more than a few milliseconds */
2684 if ((delay / 1000) > MAX_UDELAY_MS)
2685 mdelay(delay / 1000);
2695 * ipr_get_sis64_dump_data_section - Dump IOA memory
2696 * @ioa_cfg: ioa config struct
2697 * @start_addr: adapter address to dump
2698 * @dest: destination kernel buffer
2699 * @length_in_words: length to dump in 4 byte words
2704 static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2706 __be32 *dest, u32 length_in_words)
2710 for (i = 0; i < length_in_words; i++) {
2711 writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
2712 *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
2720 * ipr_get_ldump_data_section - Dump IOA memory
2721 * @ioa_cfg: ioa config struct
2722 * @start_addr: adapter address to dump
2723 * @dest: destination kernel buffer
2724 * @length_in_words: length to dump in 4 byte words
2727 * 0 on success / -EIO on failure
2729 static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
2731 __be32 *dest, u32 length_in_words)
2733 volatile u32 temp_pcii_reg;
2737 return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
2738 dest, length_in_words);
2740 /* Write IOA interrupt reg starting LDUMP state */
2741 writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
2742 ioa_cfg->regs.set_uproc_interrupt_reg32);
2744 /* Wait for IO debug acknowledge */
2745 if (ipr_wait_iodbg_ack(ioa_cfg,
2746 IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
2747 dev_err(&ioa_cfg->pdev->dev,
2748 "IOA dump long data transfer timeout\n");
2752 /* Signal LDUMP interlocked - clear IO debug ack */
2753 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2754 ioa_cfg->regs.clr_interrupt_reg);
2756 /* Write Mailbox with starting address */
2757 writel(start_addr, ioa_cfg->ioa_mailbox);
2759 /* Signal address valid - clear IOA Reset alert */
2760 writel(IPR_UPROCI_RESET_ALERT,
2761 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2763 for (i = 0; i < length_in_words; i++) {
2764 /* Wait for IO debug acknowledge */
2765 if (ipr_wait_iodbg_ack(ioa_cfg,
2766 IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
2767 dev_err(&ioa_cfg->pdev->dev,
2768 "IOA dump short data transfer timeout\n");
2772 /* Read data from mailbox and increment destination pointer */
2773 *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
2776 /* For all but the last word of data, signal data received */
2777 if (i < (length_in_words - 1)) {
2778 /* Signal dump data received - Clear IO debug Ack */
2779 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2780 ioa_cfg->regs.clr_interrupt_reg);
2784 /* Signal end of block transfer. Set reset alert then clear IO debug ack */
2785 writel(IPR_UPROCI_RESET_ALERT,
2786 ioa_cfg->regs.set_uproc_interrupt_reg32);
2788 writel(IPR_UPROCI_IO_DEBUG_ALERT,
2789 ioa_cfg->regs.clr_uproc_interrupt_reg32);
2791 /* Signal dump data received - Clear IO debug Ack */
2792 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
2793 ioa_cfg->regs.clr_interrupt_reg);
2795 /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
2796 while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
2798 readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
2800 if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
2810 #ifdef CONFIG_SCSI_IPR_DUMP
2812 * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
2813 * @ioa_cfg: ioa config struct
2814 * @pci_address: adapter address
2815 * @length: length of data to copy
2817 * Copy data from PCI adapter to kernel buffer.
2818 * Note: length MUST be a 4 byte multiple
2820 * 0 on success / other on failure
2822 static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
2823 unsigned long pci_address, u32 length)
2825 int bytes_copied = 0;
2826 int cur_len, rc, rem_len, rem_page_len, max_dump_size;
2828 unsigned long lock_flags = 0;
2829 struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
2832 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
2834 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
2836 while (bytes_copied < length &&
2837 (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
2838 if (ioa_dump->page_offset >= PAGE_SIZE ||
2839 ioa_dump->page_offset == 0) {
2840 page = (__be32 *)__get_free_page(GFP_ATOMIC);
2844 return bytes_copied;
2847 ioa_dump->page_offset = 0;
2848 ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
2849 ioa_dump->next_page_index++;
2851 page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
2853 rem_len = length - bytes_copied;
2854 rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
2855 cur_len = min(rem_len, rem_page_len);
2857 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2858 if (ioa_cfg->sdt_state == ABORT_DUMP) {
2861 rc = ipr_get_ldump_data_section(ioa_cfg,
2862 pci_address + bytes_copied,
2863 &page[ioa_dump->page_offset / 4],
2864 (cur_len / sizeof(u32)));
2866 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2869 ioa_dump->page_offset += cur_len;
2870 bytes_copied += cur_len;
2878 return bytes_copied;
2882 * ipr_init_dump_entry_hdr - Initialize a dump entry header.
2883 * @hdr: dump entry header struct
2888 static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
2890 hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
2892 hdr->offset = sizeof(*hdr);
2893 hdr->status = IPR_DUMP_STATUS_SUCCESS;
2897 * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
2898 * @ioa_cfg: ioa config struct
2899 * @driver_dump: driver dump struct
2904 static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
2905 struct ipr_driver_dump *driver_dump)
2907 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
2909 ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
2910 driver_dump->ioa_type_entry.hdr.len =
2911 sizeof(struct ipr_dump_ioa_type_entry) -
2912 sizeof(struct ipr_dump_entry_header);
2913 driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2914 driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
2915 driver_dump->ioa_type_entry.type = ioa_cfg->type;
2916 driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
2917 (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
2918 ucode_vpd->minor_release[1];
2919 driver_dump->hdr.num_entries++;
2923 * ipr_dump_version_data - Fill in the driver version in the dump.
2924 * @ioa_cfg: ioa config struct
2925 * @driver_dump: driver dump struct
2930 static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
2931 struct ipr_driver_dump *driver_dump)
2933 ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
2934 driver_dump->version_entry.hdr.len =
2935 sizeof(struct ipr_dump_version_entry) -
2936 sizeof(struct ipr_dump_entry_header);
2937 driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2938 driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
2939 strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
2940 driver_dump->hdr.num_entries++;
2944 * ipr_dump_trace_data - Fill in the IOA trace in the dump.
2945 * @ioa_cfg: ioa config struct
2946 * @driver_dump: driver dump struct
2951 static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
2952 struct ipr_driver_dump *driver_dump)
2954 ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
2955 driver_dump->trace_entry.hdr.len =
2956 sizeof(struct ipr_dump_trace_entry) -
2957 sizeof(struct ipr_dump_entry_header);
2958 driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
2959 driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
2960 memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
2961 driver_dump->hdr.num_entries++;
2965 * ipr_dump_location_data - Fill in the IOA location in the dump.
2966 * @ioa_cfg: ioa config struct
2967 * @driver_dump: driver dump struct
2972 static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
2973 struct ipr_driver_dump *driver_dump)
2975 ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
2976 driver_dump->location_entry.hdr.len =
2977 sizeof(struct ipr_dump_location_entry) -
2978 sizeof(struct ipr_dump_entry_header);
2979 driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
2980 driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
2981 strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
2982 driver_dump->hdr.num_entries++;
2986 * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
2987 * @ioa_cfg: ioa config struct
2988 * @dump: dump struct
2993 static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
2995 unsigned long start_addr, sdt_word;
2996 unsigned long lock_flags = 0;
2997 struct ipr_driver_dump *driver_dump = &dump->driver_dump;
2998 struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
2999 u32 num_entries, max_num_entries, start_off, end_off;
3000 u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
3001 struct ipr_sdt *sdt;
3007 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3009 if (ioa_cfg->sdt_state != READ_DUMP) {
3010 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3014 if (ioa_cfg->sis64) {
3015 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3016 ssleep(IPR_DUMP_DELAY_SECONDS);
3017 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3020 start_addr = readl(ioa_cfg->ioa_mailbox);
3022 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
3023 dev_err(&ioa_cfg->pdev->dev,
3024 "Invalid dump table format: %lx\n", start_addr);
3025 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3029 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
3031 driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
3033 /* Initialize the overall dump header */
3034 driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
3035 driver_dump->hdr.num_entries = 1;
3036 driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
3037 driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
3038 driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
3039 driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
3041 ipr_dump_version_data(ioa_cfg, driver_dump);
3042 ipr_dump_location_data(ioa_cfg, driver_dump);
3043 ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
3044 ipr_dump_trace_data(ioa_cfg, driver_dump);
3046 /* Update dump_header */
3047 driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
3049 /* IOA Dump entry */
3050 ipr_init_dump_entry_hdr(&ioa_dump->hdr);
3051 ioa_dump->hdr.len = 0;
3052 ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
3053 ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
3055 /* First entries in sdt are actually a list of dump addresses and
3056 lengths to gather the real dump data. sdt represents the pointer
3057 to the ioa generated dump table. Dump data will be extracted based
3058 on entries in this table */
3059 sdt = &ioa_dump->sdt;
3061 if (ioa_cfg->sis64) {
3062 max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
3063 max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
3065 max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
3066 max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
3069 bytes_to_copy = offsetof(struct ipr_sdt, entry) +
3070 (max_num_entries * sizeof(struct ipr_sdt_entry));
3071 rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
3072 bytes_to_copy / sizeof(__be32));
3074 /* Smart Dump table is ready to use and the first entry is valid */
3075 if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
3076 (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
3077 dev_err(&ioa_cfg->pdev->dev,
3078 "Dump of IOA failed. Dump table not valid: %d, %X.\n",
3079 rc, be32_to_cpu(sdt->hdr.state));
3080 driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
3081 ioa_cfg->sdt_state = DUMP_OBTAINED;
3082 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3086 num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
3088 if (num_entries > max_num_entries)
3089 num_entries = max_num_entries;
3091 /* Update dump length to the actual data to be copied */
3092 dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
3094 dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
3096 dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
3098 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3100 for (i = 0; i < num_entries; i++) {
3101 if (ioa_dump->hdr.len > max_dump_size) {
3102 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3106 if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
3107 sdt_word = be32_to_cpu(sdt->entry[i].start_token);
3109 bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
3111 start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
3112 end_off = be32_to_cpu(sdt->entry[i].end_token);
3114 if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
3115 bytes_to_copy = end_off - start_off;
3120 if (bytes_to_copy > max_dump_size) {
3121 sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
3125 /* Copy data from adapter to driver buffers */
3126 bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
3129 ioa_dump->hdr.len += bytes_copied;
3131 if (bytes_copied != bytes_to_copy) {
3132 driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
3139 dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
3141 /* Update dump_header */
3142 driver_dump->hdr.len += ioa_dump->hdr.len;
3144 ioa_cfg->sdt_state = DUMP_OBTAINED;
3149 #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
3153 * ipr_release_dump - Free adapter dump memory
3154 * @kref: kref struct
3159 static void ipr_release_dump(struct kref *kref)
3161 struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
3162 struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
3163 unsigned long lock_flags = 0;
3167 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3168 ioa_cfg->dump = NULL;
3169 ioa_cfg->sdt_state = INACTIVE;
3170 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3172 for (i = 0; i < dump->ioa_dump.next_page_index; i++)
3173 free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
3175 vfree(dump->ioa_dump.ioa_data);
3181 * ipr_worker_thread - Worker thread
3182 * @work: ioa config struct
3184 * Called at task level from a work thread. This function takes care
3185 * of adding and removing device from the mid-layer as configuration
3186 * changes are detected by the adapter.
3191 static void ipr_worker_thread(struct work_struct *work)
3193 unsigned long lock_flags;
3194 struct ipr_resource_entry *res;
3195 struct scsi_device *sdev;
3196 struct ipr_dump *dump;
3197 struct ipr_ioa_cfg *ioa_cfg =
3198 container_of(work, struct ipr_ioa_cfg, work_q);
3199 u8 bus, target, lun;
3203 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3205 if (ioa_cfg->sdt_state == READ_DUMP) {
3206 dump = ioa_cfg->dump;
3208 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3211 kref_get(&dump->kref);
3212 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3213 ipr_get_ioa_dump(ioa_cfg, dump);
3214 kref_put(&dump->kref, ipr_release_dump);
3216 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3217 if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
3218 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3219 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3226 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds ||
3227 !ioa_cfg->allow_ml_add_del) {
3228 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3232 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3233 if (res->del_from_ml && res->sdev) {
3236 if (!scsi_device_get(sdev)) {
3237 if (!res->add_to_ml)
3238 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
3240 res->del_from_ml = 0;
3241 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3242 scsi_remove_device(sdev);
3243 scsi_device_put(sdev);
3244 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3251 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
3252 if (res->add_to_ml) {
3254 target = res->target;
3257 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3258 scsi_add_device(ioa_cfg->host, bus, target, lun);
3259 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3264 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3265 kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
3269 #ifdef CONFIG_SCSI_IPR_TRACE
3271 * ipr_read_trace - Dump the adapter trace
3272 * @filp: open sysfs file
3273 * @kobj: kobject struct
3274 * @bin_attr: bin_attribute struct
3277 * @count: buffer size
3280 * number of bytes printed to buffer
3282 static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
3283 struct bin_attribute *bin_attr,
3284 char *buf, loff_t off, size_t count)
3286 struct device *dev = container_of(kobj, struct device, kobj);
3287 struct Scsi_Host *shost = class_to_shost(dev);
3288 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3289 unsigned long lock_flags = 0;
3292 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3293 ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
3295 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3300 static struct bin_attribute ipr_trace_attr = {
3306 .read = ipr_read_trace,
3311 * ipr_show_fw_version - Show the firmware version
3312 * @dev: class device struct
3316 * number of bytes printed to buffer
3318 static ssize_t ipr_show_fw_version(struct device *dev,
3319 struct device_attribute *attr, char *buf)
3321 struct Scsi_Host *shost = class_to_shost(dev);
3322 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3323 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
3324 unsigned long lock_flags = 0;
3327 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3328 len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
3329 ucode_vpd->major_release, ucode_vpd->card_type,
3330 ucode_vpd->minor_release[0],
3331 ucode_vpd->minor_release[1]);
3332 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3336 static struct device_attribute ipr_fw_version_attr = {
3338 .name = "fw_version",
3341 .show = ipr_show_fw_version,
3345 * ipr_show_log_level - Show the adapter's error logging level
3346 * @dev: class device struct
3350 * number of bytes printed to buffer
3352 static ssize_t ipr_show_log_level(struct device *dev,
3353 struct device_attribute *attr, char *buf)
3355 struct Scsi_Host *shost = class_to_shost(dev);
3356 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3357 unsigned long lock_flags = 0;
3360 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3361 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
3362 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3367 * ipr_store_log_level - Change the adapter's error logging level
3368 * @dev: class device struct
3372 * number of bytes printed to buffer
3374 static ssize_t ipr_store_log_level(struct device *dev,
3375 struct device_attribute *attr,
3376 const char *buf, size_t count)
3378 struct Scsi_Host *shost = class_to_shost(dev);
3379 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3380 unsigned long lock_flags = 0;
3382 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3383 ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
3384 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3388 static struct device_attribute ipr_log_level_attr = {
3390 .name = "log_level",
3391 .mode = S_IRUGO | S_IWUSR,
3393 .show = ipr_show_log_level,
3394 .store = ipr_store_log_level
3398 * ipr_store_diagnostics - IOA Diagnostics interface
3399 * @dev: device struct
3401 * @count: buffer size
3403 * This function will reset the adapter and wait a reasonable
3404 * amount of time for any errors that the adapter might log.
3407 * count on success / other on failure
3409 static ssize_t ipr_store_diagnostics(struct device *dev,
3410 struct device_attribute *attr,
3411 const char *buf, size_t count)
3413 struct Scsi_Host *shost = class_to_shost(dev);
3414 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3415 unsigned long lock_flags = 0;
3418 if (!capable(CAP_SYS_ADMIN))
3421 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3422 while (ioa_cfg->in_reset_reload) {
3423 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3424 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3425 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3428 ioa_cfg->errors_logged = 0;
3429 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3431 if (ioa_cfg->in_reset_reload) {
3432 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3433 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3435 /* Wait for a second for any errors to be logged */
3438 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3442 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3443 if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
3445 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3450 static struct device_attribute ipr_diagnostics_attr = {
3452 .name = "run_diagnostics",
3455 .store = ipr_store_diagnostics
3459 * ipr_show_adapter_state - Show the adapter's state
3460 * @class_dev: device struct
3464 * number of bytes printed to buffer
3466 static ssize_t ipr_show_adapter_state(struct device *dev,
3467 struct device_attribute *attr, char *buf)
3469 struct Scsi_Host *shost = class_to_shost(dev);
3470 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3471 unsigned long lock_flags = 0;
3474 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3475 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
3476 len = snprintf(buf, PAGE_SIZE, "offline\n");
3478 len = snprintf(buf, PAGE_SIZE, "online\n");
3479 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3484 * ipr_store_adapter_state - Change adapter state
3485 * @dev: device struct
3487 * @count: buffer size
3489 * This function will change the adapter's state.
3492 * count on success / other on failure
3494 static ssize_t ipr_store_adapter_state(struct device *dev,
3495 struct device_attribute *attr,
3496 const char *buf, size_t count)
3498 struct Scsi_Host *shost = class_to_shost(dev);
3499 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3500 unsigned long lock_flags;
3501 int result = count, i;
3503 if (!capable(CAP_SYS_ADMIN))
3506 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3507 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead &&
3508 !strncmp(buf, "online", 6)) {
3509 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
3510 spin_lock(&ioa_cfg->hrrq[i]._lock);
3511 ioa_cfg->hrrq[i].ioa_is_dead = 0;
3512 spin_unlock(&ioa_cfg->hrrq[i]._lock);
3515 ioa_cfg->reset_retries = 0;
3516 ioa_cfg->in_ioa_bringdown = 0;
3517 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
3519 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3520 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3525 static struct device_attribute ipr_ioa_state_attr = {
3527 .name = "online_state",
3528 .mode = S_IRUGO | S_IWUSR,
3530 .show = ipr_show_adapter_state,
3531 .store = ipr_store_adapter_state
3535 * ipr_store_reset_adapter - Reset the adapter
3536 * @dev: device struct
3538 * @count: buffer size
3540 * This function will reset the adapter.
3543 * count on success / other on failure
3545 static ssize_t ipr_store_reset_adapter(struct device *dev,
3546 struct device_attribute *attr,
3547 const char *buf, size_t count)
3549 struct Scsi_Host *shost = class_to_shost(dev);
3550 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3551 unsigned long lock_flags;
3554 if (!capable(CAP_SYS_ADMIN))
3557 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3558 if (!ioa_cfg->in_reset_reload)
3559 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3560 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3561 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3566 static struct device_attribute ipr_ioa_reset_attr = {
3568 .name = "reset_host",
3571 .store = ipr_store_reset_adapter
3574 static int ipr_iopoll(struct blk_iopoll *iop, int budget);
3576 * ipr_show_iopoll_weight - Show ipr polling mode
3577 * @dev: class device struct
3581 * number of bytes printed to buffer
3583 static ssize_t ipr_show_iopoll_weight(struct device *dev,
3584 struct device_attribute *attr, char *buf)
3586 struct Scsi_Host *shost = class_to_shost(dev);
3587 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3588 unsigned long lock_flags = 0;
3591 spin_lock_irqsave(shost->host_lock, lock_flags);
3592 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->iopoll_weight);
3593 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3599 * ipr_store_iopoll_weight - Change the adapter's polling mode
3600 * @dev: class device struct
3604 * number of bytes printed to buffer
3606 static ssize_t ipr_store_iopoll_weight(struct device *dev,
3607 struct device_attribute *attr,
3608 const char *buf, size_t count)
3610 struct Scsi_Host *shost = class_to_shost(dev);
3611 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3612 unsigned long user_iopoll_weight;
3613 unsigned long lock_flags = 0;
3616 if (!ioa_cfg->sis64) {
3617 dev_info(&ioa_cfg->pdev->dev, "blk-iopoll not supported on this adapter\n");
3620 if (kstrtoul(buf, 10, &user_iopoll_weight))
3623 if (user_iopoll_weight > 256) {
3624 dev_info(&ioa_cfg->pdev->dev, "Invalid blk-iopoll weight. It must be less than 256\n");
3628 if (user_iopoll_weight == ioa_cfg->iopoll_weight) {
3629 dev_info(&ioa_cfg->pdev->dev, "Current blk-iopoll weight has the same weight\n");
3633 if (blk_iopoll_enabled && ioa_cfg->iopoll_weight &&
3634 ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3635 for (i = 1; i < ioa_cfg->hrrq_num; i++)
3636 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
3639 spin_lock_irqsave(shost->host_lock, lock_flags);
3640 ioa_cfg->iopoll_weight = user_iopoll_weight;
3641 if (blk_iopoll_enabled && ioa_cfg->iopoll_weight &&
3642 ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
3643 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
3644 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
3645 ioa_cfg->iopoll_weight, ipr_iopoll);
3646 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
3649 spin_unlock_irqrestore(shost->host_lock, lock_flags);
3654 static struct device_attribute ipr_iopoll_weight_attr = {
3656 .name = "iopoll_weight",
3657 .mode = S_IRUGO | S_IWUSR,
3659 .show = ipr_show_iopoll_weight,
3660 .store = ipr_store_iopoll_weight
3664 * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
3665 * @buf_len: buffer length
3667 * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
3668 * list to use for microcode download
3671 * pointer to sglist / NULL on failure
3673 static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
3675 int sg_size, order, bsize_elem, num_elem, i, j;
3676 struct ipr_sglist *sglist;
3677 struct scatterlist *scatterlist;
3680 /* Get the minimum size per scatter/gather element */
3681 sg_size = buf_len / (IPR_MAX_SGLIST - 1);
3683 /* Get the actual size per element */
3684 order = get_order(sg_size);
3686 /* Determine the actual number of bytes per element */
3687 bsize_elem = PAGE_SIZE * (1 << order);
3689 /* Determine the actual number of sg entries needed */
3690 if (buf_len % bsize_elem)
3691 num_elem = (buf_len / bsize_elem) + 1;
3693 num_elem = buf_len / bsize_elem;
3695 /* Allocate a scatter/gather list for the DMA */
3696 sglist = kzalloc(sizeof(struct ipr_sglist) +
3697 (sizeof(struct scatterlist) * (num_elem - 1)),
3700 if (sglist == NULL) {
3705 scatterlist = sglist->scatterlist;
3706 sg_init_table(scatterlist, num_elem);
3708 sglist->order = order;
3709 sglist->num_sg = num_elem;
3711 /* Allocate a bunch of sg elements */
3712 for (i = 0; i < num_elem; i++) {
3713 page = alloc_pages(GFP_KERNEL, order);
3717 /* Free up what we already allocated */
3718 for (j = i - 1; j >= 0; j--)
3719 __free_pages(sg_page(&scatterlist[j]), order);
3724 sg_set_page(&scatterlist[i], page, 0, 0);
3731 * ipr_free_ucode_buffer - Frees a microcode download buffer
3732 * @p_dnld: scatter/gather list pointer
3734 * Free a DMA'able ucode download buffer previously allocated with
3735 * ipr_alloc_ucode_buffer
3740 static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
3744 for (i = 0; i < sglist->num_sg; i++)
3745 __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
3751 * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
3752 * @sglist: scatter/gather list pointer
3753 * @buffer: buffer pointer
3754 * @len: buffer length
3756 * Copy a microcode image from a user buffer into a buffer allocated by
3757 * ipr_alloc_ucode_buffer
3760 * 0 on success / other on failure
3762 static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
3763 u8 *buffer, u32 len)
3765 int bsize_elem, i, result = 0;
3766 struct scatterlist *scatterlist;
3769 /* Determine the actual number of bytes per element */
3770 bsize_elem = PAGE_SIZE * (1 << sglist->order);
3772 scatterlist = sglist->scatterlist;
3774 for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
3775 struct page *page = sg_page(&scatterlist[i]);
3778 memcpy(kaddr, buffer, bsize_elem);
3781 scatterlist[i].length = bsize_elem;
3789 if (len % bsize_elem) {
3790 struct page *page = sg_page(&scatterlist[i]);
3793 memcpy(kaddr, buffer, len % bsize_elem);
3796 scatterlist[i].length = len % bsize_elem;
3799 sglist->buffer_len = len;
3804 * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
3805 * @ipr_cmd: ipr command struct
3806 * @sglist: scatter/gather list
3808 * Builds a microcode download IOA data list (IOADL).
3811 static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
3812 struct ipr_sglist *sglist)
3814 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3815 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
3816 struct scatterlist *scatterlist = sglist->scatterlist;
3819 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3820 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3821 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3824 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
3825 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3826 ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
3827 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
3828 ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
3831 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3835 * ipr_build_ucode_ioadl - Build a microcode download IOADL
3836 * @ipr_cmd: ipr command struct
3837 * @sglist: scatter/gather list
3839 * Builds a microcode download IOA data list (IOADL).
3842 static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
3843 struct ipr_sglist *sglist)
3845 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
3846 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
3847 struct scatterlist *scatterlist = sglist->scatterlist;
3850 ipr_cmd->dma_use_sg = sglist->num_dma_sg;
3851 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
3852 ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
3855 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
3857 for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
3858 ioadl[i].flags_and_data_len =
3859 cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
3861 cpu_to_be32(sg_dma_address(&scatterlist[i]));
3864 ioadl[i-1].flags_and_data_len |=
3865 cpu_to_be32(IPR_IOADL_FLAGS_LAST);
3869 * ipr_update_ioa_ucode - Update IOA's microcode
3870 * @ioa_cfg: ioa config struct
3871 * @sglist: scatter/gather list
3873 * Initiate an adapter reset to update the IOA's microcode
3876 * 0 on success / -EIO on failure
3878 static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3879 struct ipr_sglist *sglist)
3881 unsigned long lock_flags;
3883 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3884 while (ioa_cfg->in_reset_reload) {
3885 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3886 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3887 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3890 if (ioa_cfg->ucode_sglist) {
3891 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3892 dev_err(&ioa_cfg->pdev->dev,
3893 "Microcode download already in progress\n");
3897 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
3898 sglist->num_sg, DMA_TO_DEVICE);
3900 if (!sglist->num_dma_sg) {
3901 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3902 dev_err(&ioa_cfg->pdev->dev,
3903 "Failed to map microcode download buffer!\n");
3907 ioa_cfg->ucode_sglist = sglist;
3908 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
3909 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3910 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3912 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3913 ioa_cfg->ucode_sglist = NULL;
3914 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3919 * ipr_store_update_fw - Update the firmware on the adapter
3920 * @class_dev: device struct
3922 * @count: buffer size
3924 * This function will update the firmware on the adapter.
3927 * count on success / other on failure
3929 static ssize_t ipr_store_update_fw(struct device *dev,
3930 struct device_attribute *attr,
3931 const char *buf, size_t count)
3933 struct Scsi_Host *shost = class_to_shost(dev);
3934 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
3935 struct ipr_ucode_image_header *image_hdr;
3936 const struct firmware *fw_entry;
3937 struct ipr_sglist *sglist;
3940 int len, result, dnld_size;
3942 if (!capable(CAP_SYS_ADMIN))
3945 len = snprintf(fname, 99, "%s", buf);
3946 fname[len-1] = '\0';
3948 if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
3949 dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
3953 image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
3955 src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
3956 dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
3957 sglist = ipr_alloc_ucode_buffer(dnld_size);
3960 dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
3961 release_firmware(fw_entry);
3965 result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
3968 dev_err(&ioa_cfg->pdev->dev,
3969 "Microcode buffer copy to DMA buffer failed\n");
3973 ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
3975 result = ipr_update_ioa_ucode(ioa_cfg, sglist);
3980 ipr_free_ucode_buffer(sglist);
3981 release_firmware(fw_entry);
3985 static struct device_attribute ipr_update_fw_attr = {
3987 .name = "update_fw",
3990 .store = ipr_store_update_fw
3994 * ipr_show_fw_type - Show the adapter's firmware type.
3995 * @dev: class device struct
3999 * number of bytes printed to buffer
4001 static ssize_t ipr_show_fw_type(struct device *dev,
4002 struct device_attribute *attr, char *buf)
4004 struct Scsi_Host *shost = class_to_shost(dev);
4005 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4006 unsigned long lock_flags = 0;
4009 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4010 len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
4011 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4015 static struct device_attribute ipr_ioa_fw_type_attr = {
4020 .show = ipr_show_fw_type
4023 static struct device_attribute *ipr_ioa_attrs[] = {
4024 &ipr_fw_version_attr,
4025 &ipr_log_level_attr,
4026 &ipr_diagnostics_attr,
4027 &ipr_ioa_state_attr,
4028 &ipr_ioa_reset_attr,
4029 &ipr_update_fw_attr,
4030 &ipr_ioa_fw_type_attr,
4031 &ipr_iopoll_weight_attr,
4035 #ifdef CONFIG_SCSI_IPR_DUMP
4037 * ipr_read_dump - Dump the adapter
4038 * @filp: open sysfs file
4039 * @kobj: kobject struct
4040 * @bin_attr: bin_attribute struct
4043 * @count: buffer size
4046 * number of bytes printed to buffer
4048 static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
4049 struct bin_attribute *bin_attr,
4050 char *buf, loff_t off, size_t count)
4052 struct device *cdev = container_of(kobj, struct device, kobj);
4053 struct Scsi_Host *shost = class_to_shost(cdev);
4054 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4055 struct ipr_dump *dump;
4056 unsigned long lock_flags = 0;
4061 if (!capable(CAP_SYS_ADMIN))
4064 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4065 dump = ioa_cfg->dump;
4067 if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
4068 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4071 kref_get(&dump->kref);
4072 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4074 if (off > dump->driver_dump.hdr.len) {
4075 kref_put(&dump->kref, ipr_release_dump);
4079 if (off + count > dump->driver_dump.hdr.len) {
4080 count = dump->driver_dump.hdr.len - off;
4084 if (count && off < sizeof(dump->driver_dump)) {
4085 if (off + count > sizeof(dump->driver_dump))
4086 len = sizeof(dump->driver_dump) - off;
4089 src = (u8 *)&dump->driver_dump + off;
4090 memcpy(buf, src, len);
4096 off -= sizeof(dump->driver_dump);
4099 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4100 (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
4101 sizeof(struct ipr_sdt_entry));
4103 sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
4104 (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
4106 if (count && off < sdt_end) {
4107 if (off + count > sdt_end)
4108 len = sdt_end - off;
4111 src = (u8 *)&dump->ioa_dump + off;
4112 memcpy(buf, src, len);
4121 if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
4122 len = PAGE_ALIGN(off) - off;
4125 src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
4126 src += off & ~PAGE_MASK;
4127 memcpy(buf, src, len);
4133 kref_put(&dump->kref, ipr_release_dump);
4138 * ipr_alloc_dump - Prepare for adapter dump
4139 * @ioa_cfg: ioa config struct
4142 * 0 on success / other on failure
4144 static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
4146 struct ipr_dump *dump;
4148 unsigned long lock_flags = 0;
4150 dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
4153 ipr_err("Dump memory allocation failed\n");
4158 ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4160 ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
4163 ipr_err("Dump memory allocation failed\n");
4168 dump->ioa_dump.ioa_data = ioa_data;
4170 kref_init(&dump->kref);
4171 dump->ioa_cfg = ioa_cfg;
4173 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4175 if (INACTIVE != ioa_cfg->sdt_state) {
4176 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4177 vfree(dump->ioa_dump.ioa_data);
4182 ioa_cfg->dump = dump;
4183 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
4184 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead && !ioa_cfg->dump_taken) {
4185 ioa_cfg->dump_taken = 1;
4186 schedule_work(&ioa_cfg->work_q);
4188 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4194 * ipr_free_dump - Free adapter dump memory
4195 * @ioa_cfg: ioa config struct
4198 * 0 on success / other on failure
4200 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
4202 struct ipr_dump *dump;
4203 unsigned long lock_flags = 0;
4207 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4208 dump = ioa_cfg->dump;
4210 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4214 ioa_cfg->dump = NULL;
4215 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4217 kref_put(&dump->kref, ipr_release_dump);
4224 * ipr_write_dump - Setup dump state of adapter
4225 * @filp: open sysfs file
4226 * @kobj: kobject struct
4227 * @bin_attr: bin_attribute struct
4230 * @count: buffer size
4233 * number of bytes printed to buffer
4235 static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
4236 struct bin_attribute *bin_attr,
4237 char *buf, loff_t off, size_t count)
4239 struct device *cdev = container_of(kobj, struct device, kobj);
4240 struct Scsi_Host *shost = class_to_shost(cdev);
4241 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
4244 if (!capable(CAP_SYS_ADMIN))
4248 rc = ipr_alloc_dump(ioa_cfg);
4249 else if (buf[0] == '0')
4250 rc = ipr_free_dump(ioa_cfg);
4260 static struct bin_attribute ipr_dump_attr = {
4263 .mode = S_IRUSR | S_IWUSR,
4266 .read = ipr_read_dump,
4267 .write = ipr_write_dump
4270 static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4274 * ipr_change_queue_depth - Change the device's queue depth
4275 * @sdev: scsi device struct
4276 * @qdepth: depth to set
4277 * @reason: calling context
4282 static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
4285 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4286 struct ipr_resource_entry *res;
4287 unsigned long lock_flags = 0;
4289 if (reason != SCSI_QDEPTH_DEFAULT)
4292 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4293 res = (struct ipr_resource_entry *)sdev->hostdata;
4295 if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
4296 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4297 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4299 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
4300 return sdev->queue_depth;
4304 * ipr_change_queue_type - Change the device's queue type
4305 * @dsev: scsi device struct
4306 * @tag_type: type of tags to use
4309 * actual queue type set
4311 static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4313 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4314 struct ipr_resource_entry *res;
4315 unsigned long lock_flags = 0;
4317 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4318 res = (struct ipr_resource_entry *)sdev->hostdata;
4321 if (ipr_is_gscsi(res) && sdev->tagged_supported) {
4323 * We don't bother quiescing the device here since the
4324 * adapter firmware does it for us.
4326 scsi_set_tag_type(sdev, tag_type);
4329 scsi_activate_tcq(sdev, sdev->queue_depth);
4331 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4337 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4342 * ipr_show_adapter_handle - Show the adapter's resource handle for this device
4343 * @dev: device struct
4344 * @attr: device attribute structure
4348 * number of bytes printed to buffer
4350 static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
4352 struct scsi_device *sdev = to_scsi_device(dev);
4353 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4354 struct ipr_resource_entry *res;
4355 unsigned long lock_flags = 0;
4356 ssize_t len = -ENXIO;
4358 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4359 res = (struct ipr_resource_entry *)sdev->hostdata;
4361 len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
4362 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4366 static struct device_attribute ipr_adapter_handle_attr = {
4368 .name = "adapter_handle",
4371 .show = ipr_show_adapter_handle
4375 * ipr_show_resource_path - Show the resource path or the resource address for
4377 * @dev: device struct
4378 * @attr: device attribute structure
4382 * number of bytes printed to buffer
4384 static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
4386 struct scsi_device *sdev = to_scsi_device(dev);
4387 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4388 struct ipr_resource_entry *res;
4389 unsigned long lock_flags = 0;
4390 ssize_t len = -ENXIO;
4391 char buffer[IPR_MAX_RES_PATH_LENGTH];
4393 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4394 res = (struct ipr_resource_entry *)sdev->hostdata;
4395 if (res && ioa_cfg->sis64)
4396 len = snprintf(buf, PAGE_SIZE, "%s\n",
4397 __ipr_format_res_path(res->res_path, buffer,
4400 len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
4401 res->bus, res->target, res->lun);
4403 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4407 static struct device_attribute ipr_resource_path_attr = {
4409 .name = "resource_path",
4412 .show = ipr_show_resource_path
4416 * ipr_show_device_id - Show the device_id for this device.
4417 * @dev: device struct
4418 * @attr: device attribute structure
4422 * number of bytes printed to buffer
4424 static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
4426 struct scsi_device *sdev = to_scsi_device(dev);
4427 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4428 struct ipr_resource_entry *res;
4429 unsigned long lock_flags = 0;
4430 ssize_t len = -ENXIO;
4432 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4433 res = (struct ipr_resource_entry *)sdev->hostdata;
4434 if (res && ioa_cfg->sis64)
4435 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
4437 len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
4439 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4443 static struct device_attribute ipr_device_id_attr = {
4445 .name = "device_id",
4448 .show = ipr_show_device_id
4452 * ipr_show_resource_type - Show the resource type for this device.
4453 * @dev: device struct
4454 * @attr: device attribute structure
4458 * number of bytes printed to buffer
4460 static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
4462 struct scsi_device *sdev = to_scsi_device(dev);
4463 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4464 struct ipr_resource_entry *res;
4465 unsigned long lock_flags = 0;
4466 ssize_t len = -ENXIO;
4468 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4469 res = (struct ipr_resource_entry *)sdev->hostdata;
4472 len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
4474 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4478 static struct device_attribute ipr_resource_type_attr = {
4480 .name = "resource_type",
4483 .show = ipr_show_resource_type
4486 static struct device_attribute *ipr_dev_attrs[] = {
4487 &ipr_adapter_handle_attr,
4488 &ipr_resource_path_attr,
4489 &ipr_device_id_attr,
4490 &ipr_resource_type_attr,
4495 * ipr_biosparam - Return the HSC mapping
4496 * @sdev: scsi device struct
4497 * @block_device: block device pointer
4498 * @capacity: capacity of the device
4499 * @parm: Array containing returned HSC values.
4501 * This function generates the HSC parms that fdisk uses.
4502 * We want to make sure we return something that places partitions
4503 * on 4k boundaries for best performance with the IOA.
4508 static int ipr_biosparam(struct scsi_device *sdev,
4509 struct block_device *block_device,
4510 sector_t capacity, int *parm)
4518 cylinders = capacity;
4519 sector_div(cylinders, (128 * 32));
4524 parm[2] = cylinders;
4530 * ipr_find_starget - Find target based on bus/target.
4531 * @starget: scsi target struct
4534 * resource entry pointer if found / NULL if not found
4536 static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
4538 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4539 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4540 struct ipr_resource_entry *res;
4542 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4543 if ((res->bus == starget->channel) &&
4544 (res->target == starget->id)) {
4552 static struct ata_port_info sata_port_info;
4555 * ipr_target_alloc - Prepare for commands to a SCSI target
4556 * @starget: scsi target struct
4558 * If the device is a SATA device, this function allocates an
4559 * ATA port with libata, else it does nothing.
4562 * 0 on success / non-0 on failure
4564 static int ipr_target_alloc(struct scsi_target *starget)
4566 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4567 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4568 struct ipr_sata_port *sata_port;
4569 struct ata_port *ap;
4570 struct ipr_resource_entry *res;
4571 unsigned long lock_flags;
4573 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4574 res = ipr_find_starget(starget);
4575 starget->hostdata = NULL;
4577 if (res && ipr_is_gata(res)) {
4578 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4579 sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
4583 ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
4585 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4586 sata_port->ioa_cfg = ioa_cfg;
4588 sata_port->res = res;
4590 res->sata_port = sata_port;
4591 ap->private_data = sata_port;
4592 starget->hostdata = sata_port;
4598 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4604 * ipr_target_destroy - Destroy a SCSI target
4605 * @starget: scsi target struct
4607 * If the device was a SATA device, this function frees the libata
4608 * ATA port, else it does nothing.
4611 static void ipr_target_destroy(struct scsi_target *starget)
4613 struct ipr_sata_port *sata_port = starget->hostdata;
4614 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
4615 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
4617 if (ioa_cfg->sis64) {
4618 if (!ipr_find_starget(starget)) {
4619 if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
4620 clear_bit(starget->id, ioa_cfg->array_ids);
4621 else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
4622 clear_bit(starget->id, ioa_cfg->vset_ids);
4623 else if (starget->channel == 0)
4624 clear_bit(starget->id, ioa_cfg->target_ids);
4629 starget->hostdata = NULL;
4630 ata_sas_port_destroy(sata_port->ap);
4636 * ipr_find_sdev - Find device based on bus/target/lun.
4637 * @sdev: scsi device struct
4640 * resource entry pointer if found / NULL if not found
4642 static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
4644 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4645 struct ipr_resource_entry *res;
4647 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
4648 if ((res->bus == sdev->channel) &&
4649 (res->target == sdev->id) &&
4650 (res->lun == sdev->lun))
4658 * ipr_slave_destroy - Unconfigure a SCSI device
4659 * @sdev: scsi device struct
4664 static void ipr_slave_destroy(struct scsi_device *sdev)
4666 struct ipr_resource_entry *res;
4667 struct ipr_ioa_cfg *ioa_cfg;
4668 unsigned long lock_flags = 0;
4670 ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4672 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4673 res = (struct ipr_resource_entry *) sdev->hostdata;
4676 res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
4677 sdev->hostdata = NULL;
4679 res->sata_port = NULL;
4681 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4685 * ipr_slave_configure - Configure a SCSI device
4686 * @sdev: scsi device struct
4688 * This function configures the specified scsi device.
4693 static int ipr_slave_configure(struct scsi_device *sdev)
4695 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4696 struct ipr_resource_entry *res;
4697 struct ata_port *ap = NULL;
4698 unsigned long lock_flags = 0;
4699 char buffer[IPR_MAX_RES_PATH_LENGTH];
4701 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4702 res = sdev->hostdata;
4704 if (ipr_is_af_dasd_device(res))
4705 sdev->type = TYPE_RAID;
4706 if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
4707 sdev->scsi_level = 4;
4708 sdev->no_uld_attach = 1;
4710 if (ipr_is_vset_device(res)) {
4711 blk_queue_rq_timeout(sdev->request_queue,
4712 IPR_VSET_RW_TIMEOUT);
4713 blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
4715 if (ipr_is_gata(res) && res->sata_port)
4716 ap = res->sata_port->ap;
4717 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4720 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
4721 ata_sas_slave_configure(sdev, ap);
4723 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4725 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4726 ipr_format_res_path(ioa_cfg,
4727 res->res_path, buffer, sizeof(buffer)));
4730 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4735 * ipr_ata_slave_alloc - Prepare for commands to a SATA device
4736 * @sdev: scsi device struct
4738 * This function initializes an ATA port so that future commands
4739 * sent through queuecommand will work.
4744 static int ipr_ata_slave_alloc(struct scsi_device *sdev)
4746 struct ipr_sata_port *sata_port = NULL;
4750 if (sdev->sdev_target)
4751 sata_port = sdev->sdev_target->hostdata;
4753 rc = ata_sas_port_init(sata_port->ap);
4755 rc = ata_sas_sync_probe(sata_port->ap);
4759 ipr_slave_destroy(sdev);
4766 * ipr_slave_alloc - Prepare for commands to a device.
4767 * @sdev: scsi device struct
4769 * This function saves a pointer to the resource entry
4770 * in the scsi device struct if the device exists. We
4771 * can then use this pointer in ipr_queuecommand when
4772 * handling new commands.
4775 * 0 on success / -ENXIO if device does not exist
4777 static int ipr_slave_alloc(struct scsi_device *sdev)
4779 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
4780 struct ipr_resource_entry *res;
4781 unsigned long lock_flags;
4784 sdev->hostdata = NULL;
4786 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4788 res = ipr_find_sdev(sdev);
4793 sdev->hostdata = res;
4794 if (!ipr_is_naca_model(res))
4795 res->needs_sync_complete = 1;
4797 if (ipr_is_gata(res)) {
4798 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4799 return ipr_ata_slave_alloc(sdev);
4803 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4808 static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
4810 struct ipr_ioa_cfg *ioa_cfg;
4811 unsigned long lock_flags = 0;
4815 ioa_cfg = (struct ipr_ioa_cfg *) cmd->device->host->hostdata;
4816 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4818 if (!ioa_cfg->in_reset_reload && !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4819 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
4820 dev_err(&ioa_cfg->pdev->dev,
4821 "Adapter being reset as a result of error recovery.\n");
4823 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
4824 ioa_cfg->sdt_state = GET_DUMP;
4827 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4828 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4829 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4831 /* If we got hit with a host reset while we were already resetting
4832 the adapter for some reason, and the reset failed. */
4833 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
4838 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4844 * ipr_device_reset - Reset the device
4845 * @ioa_cfg: ioa config struct
4846 * @res: resource entry struct
4848 * This function issues a device reset to the affected device.
4849 * If the device is a SCSI device, a LUN reset will be sent
4850 * to the device first. If that does not work, a target reset
4851 * will be sent. If the device is a SATA device, a PHY reset will
4855 * 0 on success / non-zero on failure
4857 static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
4858 struct ipr_resource_entry *res)
4860 struct ipr_cmnd *ipr_cmd;
4861 struct ipr_ioarcb *ioarcb;
4862 struct ipr_cmd_pkt *cmd_pkt;
4863 struct ipr_ioarcb_ata_regs *regs;
4867 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
4868 ioarcb = &ipr_cmd->ioarcb;
4869 cmd_pkt = &ioarcb->cmd_pkt;
4871 if (ipr_cmd->ioa_cfg->sis64) {
4872 regs = &ipr_cmd->i.ata_ioadl.regs;
4873 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
4875 regs = &ioarcb->u.add_data.u.regs;
4877 ioarcb->res_handle = res->res_handle;
4878 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
4879 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
4880 if (ipr_is_gata(res)) {
4881 cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
4882 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
4883 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
4886 ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
4887 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
4888 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
4889 if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
4890 if (ipr_cmd->ioa_cfg->sis64)
4891 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
4892 sizeof(struct ipr_ioasa_gata));
4894 memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
4895 sizeof(struct ipr_ioasa_gata));
4899 return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
4903 * ipr_sata_reset - Reset the SATA port
4904 * @link: SATA link to reset
4905 * @classes: class of the attached device
4907 * This function issues a SATA phy reset to the affected ATA link.
4910 * 0 on success / non-zero on failure
4912 static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
4913 unsigned long deadline)
4915 struct ipr_sata_port *sata_port = link->ap->private_data;
4916 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
4917 struct ipr_resource_entry *res;
4918 unsigned long lock_flags = 0;
4922 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4923 while (ioa_cfg->in_reset_reload) {
4924 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4925 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
4926 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4929 res = sata_port->res;
4931 rc = ipr_device_reset(ioa_cfg, res);
4932 *classes = res->ata_class;
4935 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4941 * ipr_eh_dev_reset - Reset the device
4942 * @scsi_cmd: scsi command struct
4944 * This function issues a device reset to the affected device.
4945 * A LUN reset will be sent to the device first. If that does
4946 * not work, a target reset will be sent.
4951 static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
4953 struct ipr_cmnd *ipr_cmd;
4954 struct ipr_ioa_cfg *ioa_cfg;
4955 struct ipr_resource_entry *res;
4956 struct ata_port *ap;
4958 struct ipr_hrr_queue *hrrq;
4961 ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
4962 res = scsi_cmd->device->hostdata;
4968 * If we are currently going through reset/reload, return failed. This will force the
4969 * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
4972 if (ioa_cfg->in_reset_reload)
4974 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
4977 for_each_hrrq(hrrq, ioa_cfg) {
4978 spin_lock(&hrrq->_lock);
4979 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
4980 if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
4981 if (ipr_cmd->scsi_cmd)
4982 ipr_cmd->done = ipr_scsi_eh_done;
4984 ipr_cmd->done = ipr_sata_eh_done;
4986 !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
4987 ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
4988 ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
4992 spin_unlock(&hrrq->_lock);
4994 res->resetting_device = 1;
4995 scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
4997 if (ipr_is_gata(res) && res->sata_port) {
4998 ap = res->sata_port->ap;
4999 spin_unlock_irq(scsi_cmd->device->host->host_lock);
5000 ata_std_error_handler(ap);
5001 spin_lock_irq(scsi_cmd->device->host->host_lock);
5003 for_each_hrrq(hrrq, ioa_cfg) {
5004 spin_lock(&hrrq->_lock);
5005 list_for_each_entry(ipr_cmd,
5006 &hrrq->hrrq_pending_q, queue) {
5007 if (ipr_cmd->ioarcb.res_handle ==
5013 spin_unlock(&hrrq->_lock);
5016 rc = ipr_device_reset(ioa_cfg, res);
5017 res->resetting_device = 0;
5020 return rc ? FAILED : SUCCESS;
5023 static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
5027 spin_lock_irq(cmd->device->host->host_lock);
5028 rc = __ipr_eh_dev_reset(cmd);
5029 spin_unlock_irq(cmd->device->host->host_lock);
5035 * ipr_bus_reset_done - Op done function for bus reset.
5036 * @ipr_cmd: ipr command struct
5038 * This function is the op done function for a bus reset
5043 static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
5045 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5046 struct ipr_resource_entry *res;
5049 if (!ioa_cfg->sis64)
5050 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
5051 if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
5052 scsi_report_bus_reset(ioa_cfg->host, res->bus);
5058 * If abort has not completed, indicate the reset has, else call the
5059 * abort's done function to wake the sleeping eh thread
5061 if (ipr_cmd->sibling->sibling)
5062 ipr_cmd->sibling->sibling = NULL;
5064 ipr_cmd->sibling->done(ipr_cmd->sibling);
5066 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5071 * ipr_abort_timeout - An abort task has timed out
5072 * @ipr_cmd: ipr command struct
5074 * This function handles when an abort task times out. If this
5075 * happens we issue a bus reset since we have resources tied
5076 * up that must be freed before returning to the midlayer.
5081 static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
5083 struct ipr_cmnd *reset_cmd;
5084 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5085 struct ipr_cmd_pkt *cmd_pkt;
5086 unsigned long lock_flags = 0;
5089 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
5090 if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
5091 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5095 sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
5096 reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5097 ipr_cmd->sibling = reset_cmd;
5098 reset_cmd->sibling = ipr_cmd;
5099 reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
5100 cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
5101 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5102 cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
5103 cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
5105 ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
5106 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
5111 * ipr_cancel_op - Cancel specified op
5112 * @scsi_cmd: scsi command struct
5114 * This function cancels specified op.
5119 static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
5121 struct ipr_cmnd *ipr_cmd;
5122 struct ipr_ioa_cfg *ioa_cfg;
5123 struct ipr_resource_entry *res;
5124 struct ipr_cmd_pkt *cmd_pkt;
5127 struct ipr_hrr_queue *hrrq;
5130 ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
5131 res = scsi_cmd->device->hostdata;
5133 /* If we are currently going through reset/reload, return failed.
5134 * This will force the mid-layer to call ipr_eh_host_reset,
5135 * which will then go to sleep and wait for the reset to complete
5137 if (ioa_cfg->in_reset_reload ||
5138 ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
5144 * If we are aborting a timed out op, chances are that the timeout was caused
5145 * by a still not detected EEH error. In such cases, reading a register will
5146 * trigger the EEH recovery infrastructure.
5148 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5150 if (!ipr_is_gscsi(res))
5153 for_each_hrrq(hrrq, ioa_cfg) {
5154 spin_lock(&hrrq->_lock);
5155 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
5156 if (ipr_cmd->scsi_cmd == scsi_cmd) {
5157 ipr_cmd->done = ipr_scsi_eh_done;
5162 spin_unlock(&hrrq->_lock);
5168 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
5169 ipr_cmd->ioarcb.res_handle = res->res_handle;
5170 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5171 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5172 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5173 ipr_cmd->u.sdev = scsi_cmd->device;
5175 scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
5177 ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
5178 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5181 * If the abort task timed out and we sent a bus reset, we will get
5182 * one the following responses to the abort
5184 if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
5189 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5190 if (!ipr_is_naca_model(res))
5191 res->needs_sync_complete = 1;
5194 return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
5198 * ipr_eh_abort - Abort a single op
5199 * @scsi_cmd: scsi command struct
5204 static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
5206 unsigned long flags;
5211 spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
5212 rc = ipr_cancel_op(scsi_cmd);
5213 spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
5220 * ipr_handle_other_interrupt - Handle "other" interrupts
5221 * @ioa_cfg: ioa config struct
5222 * @int_reg: interrupt register
5225 * IRQ_NONE / IRQ_HANDLED
5227 static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
5230 irqreturn_t rc = IRQ_HANDLED;
5233 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
5234 int_reg &= ~int_mask_reg;
5236 /* If an interrupt on the adapter did not occur, ignore it.
5237 * Or in the case of SIS 64, check for a stage change interrupt.
5239 if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
5240 if (ioa_cfg->sis64) {
5241 int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
5242 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5243 if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
5245 /* clear stage change */
5246 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
5247 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
5248 list_del(&ioa_cfg->reset_cmd->queue);
5249 del_timer(&ioa_cfg->reset_cmd->timer);
5250 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5258 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
5259 /* Mask the interrupt */
5260 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
5262 /* Clear the interrupt */
5263 writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
5264 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
5266 list_del(&ioa_cfg->reset_cmd->queue);
5267 del_timer(&ioa_cfg->reset_cmd->timer);
5268 ipr_reset_ioa_job(ioa_cfg->reset_cmd);
5269 } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
5270 if (ioa_cfg->clear_isr) {
5271 if (ipr_debug && printk_ratelimit())
5272 dev_err(&ioa_cfg->pdev->dev,
5273 "Spurious interrupt detected. 0x%08X\n", int_reg);
5274 writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
5275 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5279 if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
5280 ioa_cfg->ioa_unit_checked = 1;
5281 else if (int_reg & IPR_PCII_NO_HOST_RRQ)
5282 dev_err(&ioa_cfg->pdev->dev,
5283 "No Host RRQ. 0x%08X\n", int_reg);
5285 dev_err(&ioa_cfg->pdev->dev,
5286 "Permanent IOA failure. 0x%08X\n", int_reg);
5288 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5289 ioa_cfg->sdt_state = GET_DUMP;
5291 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
5292 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5299 * ipr_isr_eh - Interrupt service routine error handler
5300 * @ioa_cfg: ioa config struct
5301 * @msg: message to log
5306 static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg, u16 number)
5308 ioa_cfg->errors_logged++;
5309 dev_err(&ioa_cfg->pdev->dev, "%s %d\n", msg, number);
5311 if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
5312 ioa_cfg->sdt_state = GET_DUMP;
5314 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
5317 static int ipr_process_hrrq(struct ipr_hrr_queue *hrr_queue, int budget,
5318 struct list_head *doneq)
5322 struct ipr_cmnd *ipr_cmd;
5323 struct ipr_ioa_cfg *ioa_cfg = hrr_queue->ioa_cfg;
5326 /* If interrupts are disabled, ignore the interrupt */
5327 if (!hrr_queue->allow_interrupts)
5330 while ((be32_to_cpu(*hrr_queue->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5331 hrr_queue->toggle_bit) {
5333 cmd_index = (be32_to_cpu(*hrr_queue->hrrq_curr) &
5334 IPR_HRRQ_REQ_RESP_HANDLE_MASK) >>
5335 IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
5337 if (unlikely(cmd_index > hrr_queue->max_cmd_id ||
5338 cmd_index < hrr_queue->min_cmd_id)) {
5340 "Invalid response handle from IOA: ",
5345 ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
5346 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5348 ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
5350 list_move_tail(&ipr_cmd->queue, doneq);
5352 if (hrr_queue->hrrq_curr < hrr_queue->hrrq_end) {
5353 hrr_queue->hrrq_curr++;
5355 hrr_queue->hrrq_curr = hrr_queue->hrrq_start;
5356 hrr_queue->toggle_bit ^= 1u;
5359 if (budget > 0 && num_hrrq >= budget)
5366 static int ipr_iopoll(struct blk_iopoll *iop, int budget)
5368 struct ipr_ioa_cfg *ioa_cfg;
5369 struct ipr_hrr_queue *hrrq;
5370 struct ipr_cmnd *ipr_cmd, *temp;
5371 unsigned long hrrq_flags;
5375 hrrq = container_of(iop, struct ipr_hrr_queue, iopoll);
5376 ioa_cfg = hrrq->ioa_cfg;
5378 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5379 completed_ops = ipr_process_hrrq(hrrq, budget, &doneq);
5381 if (completed_ops < budget)
5382 blk_iopoll_complete(iop);
5383 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5385 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5386 list_del(&ipr_cmd->queue);
5387 del_timer(&ipr_cmd->timer);
5388 ipr_cmd->fast_done(ipr_cmd);
5391 return completed_ops;
5395 * ipr_isr - Interrupt service routine
5397 * @devp: pointer to ioa config struct
5400 * IRQ_NONE / IRQ_HANDLED
5402 static irqreturn_t ipr_isr(int irq, void *devp)
5404 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5405 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5406 unsigned long hrrq_flags = 0;
5410 struct ipr_cmnd *ipr_cmd, *temp;
5411 irqreturn_t rc = IRQ_NONE;
5414 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5415 /* If interrupts are disabled, ignore the interrupt */
5416 if (!hrrq->allow_interrupts) {
5417 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5422 if (ipr_process_hrrq(hrrq, -1, &doneq)) {
5425 if (!ioa_cfg->clear_isr)
5428 /* Clear the PCI interrupt */
5431 writel(IPR_PCII_HRRQ_UPDATED,
5432 ioa_cfg->regs.clr_interrupt_reg32);
5433 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5434 } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
5435 num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
5437 } else if (rc == IRQ_NONE && irq_none == 0) {
5438 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
5440 } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
5441 int_reg & IPR_PCII_HRRQ_UPDATED) {
5443 "Error clearing HRRQ: ", num_hrrq);
5450 if (unlikely(rc == IRQ_NONE))
5451 rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
5453 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5454 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5455 list_del(&ipr_cmd->queue);
5456 del_timer(&ipr_cmd->timer);
5457 ipr_cmd->fast_done(ipr_cmd);
5463 * ipr_isr_mhrrq - Interrupt service routine
5465 * @devp: pointer to ioa config struct
5468 * IRQ_NONE / IRQ_HANDLED
5470 static irqreturn_t ipr_isr_mhrrq(int irq, void *devp)
5472 struct ipr_hrr_queue *hrrq = (struct ipr_hrr_queue *)devp;
5473 struct ipr_ioa_cfg *ioa_cfg = hrrq->ioa_cfg;
5474 unsigned long hrrq_flags = 0;
5475 struct ipr_cmnd *ipr_cmd, *temp;
5476 irqreturn_t rc = IRQ_NONE;
5479 spin_lock_irqsave(hrrq->lock, hrrq_flags);
5481 /* If interrupts are disabled, ignore the interrupt */
5482 if (!hrrq->allow_interrupts) {
5483 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5487 if (blk_iopoll_enabled && ioa_cfg->iopoll_weight &&
5488 ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
5489 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5491 if (!blk_iopoll_sched_prep(&hrrq->iopoll))
5492 blk_iopoll_sched(&hrrq->iopoll);
5493 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5497 if ((be32_to_cpu(*hrrq->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
5500 if (ipr_process_hrrq(hrrq, -1, &doneq))
5504 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
5506 list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
5507 list_del(&ipr_cmd->queue);
5508 del_timer(&ipr_cmd->timer);
5509 ipr_cmd->fast_done(ipr_cmd);
5515 * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
5516 * @ioa_cfg: ioa config struct
5517 * @ipr_cmd: ipr command struct
5520 * 0 on success / -1 on failure
5522 static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5523 struct ipr_cmnd *ipr_cmd)
5526 struct scatterlist *sg;
5528 u32 ioadl_flags = 0;
5529 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5530 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5531 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
5533 length = scsi_bufflen(scsi_cmd);
5537 nseg = scsi_dma_map(scsi_cmd);
5539 if (printk_ratelimit())
5540 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5544 ipr_cmd->dma_use_sg = nseg;
5546 ioarcb->data_transfer_length = cpu_to_be32(length);
5548 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
5550 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5551 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5552 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5553 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
5554 ioadl_flags = IPR_IOADL_FLAGS_READ;
5556 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5557 ioadl64[i].flags = cpu_to_be32(ioadl_flags);
5558 ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
5559 ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
5562 ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5567 * ipr_build_ioadl - Build a scatter/gather list and map the buffer
5568 * @ioa_cfg: ioa config struct
5569 * @ipr_cmd: ipr command struct
5572 * 0 on success / -1 on failure
5574 static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5575 struct ipr_cmnd *ipr_cmd)
5578 struct scatterlist *sg;
5580 u32 ioadl_flags = 0;
5581 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5582 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5583 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
5585 length = scsi_bufflen(scsi_cmd);
5589 nseg = scsi_dma_map(scsi_cmd);
5591 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
5595 ipr_cmd->dma_use_sg = nseg;
5597 if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
5598 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
5599 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
5600 ioarcb->data_transfer_length = cpu_to_be32(length);
5602 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5603 } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
5604 ioadl_flags = IPR_IOADL_FLAGS_READ;
5605 ioarcb->read_data_transfer_length = cpu_to_be32(length);
5606 ioarcb->read_ioadl_len =
5607 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
5610 if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
5611 ioadl = ioarcb->u.add_data.u.ioadl;
5612 ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
5613 offsetof(struct ipr_ioarcb, u.add_data));
5614 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5617 scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
5618 ioadl[i].flags_and_data_len =
5619 cpu_to_be32(ioadl_flags | sg_dma_len(sg));
5620 ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
5623 ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
5628 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5629 * @scsi_cmd: scsi command struct
5634 static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
5637 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
5639 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
5641 case MSG_SIMPLE_TAG:
5642 rc = IPR_FLAGS_LO_SIMPLE_TASK;
5645 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
5647 case MSG_ORDERED_TAG:
5648 rc = IPR_FLAGS_LO_ORDERED_TASK;
5657 * ipr_erp_done - Process completion of ERP for a device
5658 * @ipr_cmd: ipr command struct
5660 * This function copies the sense buffer into the scsi_cmd
5661 * struct and pushes the scsi_done function.
5666 static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
5668 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5669 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5670 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5672 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5673 scsi_cmd->result |= (DID_ERROR << 16);
5674 scmd_printk(KERN_ERR, scsi_cmd,
5675 "Request Sense failed with IOASC: 0x%08X\n", ioasc);
5677 memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
5678 SCSI_SENSE_BUFFERSIZE);
5682 if (!ipr_is_naca_model(res))
5683 res->needs_sync_complete = 1;
5686 scsi_dma_unmap(ipr_cmd->scsi_cmd);
5687 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
5688 scsi_cmd->scsi_done(scsi_cmd);
5692 * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
5693 * @ipr_cmd: ipr command struct
5698 static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
5700 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5701 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5702 dma_addr_t dma_addr = ipr_cmd->dma_addr;
5704 memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
5705 ioarcb->data_transfer_length = 0;
5706 ioarcb->read_data_transfer_length = 0;
5707 ioarcb->ioadl_len = 0;
5708 ioarcb->read_ioadl_len = 0;
5709 ioasa->hdr.ioasc = 0;
5710 ioasa->hdr.residual_data_len = 0;
5712 if (ipr_cmd->ioa_cfg->sis64)
5713 ioarcb->u.sis64_addr_data.data_ioadl_addr =
5714 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
5716 ioarcb->write_ioadl_addr =
5717 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
5718 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
5723 * ipr_erp_request_sense - Send request sense to a device
5724 * @ipr_cmd: ipr command struct
5726 * This function sends a request sense to a device as a result
5727 * of a check condition.
5732 static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
5734 struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5735 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5737 if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
5738 ipr_erp_done(ipr_cmd);
5742 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5744 cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
5745 cmd_pkt->cdb[0] = REQUEST_SENSE;
5746 cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
5747 cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
5748 cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
5749 cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
5751 ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
5752 SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
5754 ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
5755 IPR_REQUEST_SENSE_TIMEOUT * 2);
5759 * ipr_erp_cancel_all - Send cancel all to a device
5760 * @ipr_cmd: ipr command struct
5762 * This function sends a cancel all to a device to clear the
5763 * queue. If we are running TCQ on the device, QERR is set to 1,
5764 * which means all outstanding ops have been dropped on the floor.
5765 * Cancel all will return them to us.
5770 static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
5772 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5773 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5774 struct ipr_cmd_pkt *cmd_pkt;
5778 ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
5780 if (!scsi_get_tag_type(scsi_cmd->device)) {
5781 ipr_erp_request_sense(ipr_cmd);
5785 cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
5786 cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
5787 cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
5789 ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
5790 IPR_CANCEL_ALL_TIMEOUT);
5794 * ipr_dump_ioasa - Dump contents of IOASA
5795 * @ioa_cfg: ioa config struct
5796 * @ipr_cmd: ipr command struct
5797 * @res: resource entry struct
5799 * This function is invoked by the interrupt handler when ops
5800 * fail. It will log the IOASA if appropriate. Only called
5806 static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
5807 struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
5811 u32 ioasc, fd_ioasc;
5812 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5813 __be32 *ioasa_data = (__be32 *)ioasa;
5816 ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
5817 fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
5822 if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
5825 if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
5826 error_index = ipr_get_error(fd_ioasc);
5828 error_index = ipr_get_error(ioasc);
5830 if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
5831 /* Don't log an error if the IOA already logged one */
5832 if (ioasa->hdr.ilid != 0)
5835 if (!ipr_is_gscsi(res))
5838 if (ipr_error_table[error_index].log_ioasa == 0)
5842 ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
5844 data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
5845 if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
5846 data_len = sizeof(struct ipr_ioasa64);
5847 else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
5848 data_len = sizeof(struct ipr_ioasa);
5850 ipr_err("IOASA Dump:\n");
5852 for (i = 0; i < data_len / 4; i += 4) {
5853 ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
5854 be32_to_cpu(ioasa_data[i]),
5855 be32_to_cpu(ioasa_data[i+1]),
5856 be32_to_cpu(ioasa_data[i+2]),
5857 be32_to_cpu(ioasa_data[i+3]));
5862 * ipr_gen_sense - Generate SCSI sense data from an IOASA
5864 * @sense_buf: sense data buffer
5869 static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
5872 u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
5873 struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
5874 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5875 u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
5877 memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
5879 if (ioasc >= IPR_FIRST_DRIVER_IOASC)
5882 ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
5884 if (ipr_is_vset_device(res) &&
5885 ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
5886 ioasa->u.vset.failing_lba_hi != 0) {
5887 sense_buf[0] = 0x72;
5888 sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
5889 sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
5890 sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
5894 sense_buf[9] = 0x0A;
5895 sense_buf[10] = 0x80;
5897 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
5899 sense_buf[12] = (failing_lba & 0xff000000) >> 24;
5900 sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
5901 sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
5902 sense_buf[15] = failing_lba & 0x000000ff;
5904 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5906 sense_buf[16] = (failing_lba & 0xff000000) >> 24;
5907 sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
5908 sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
5909 sense_buf[19] = failing_lba & 0x000000ff;
5911 sense_buf[0] = 0x70;
5912 sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
5913 sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
5914 sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
5916 /* Illegal request */
5917 if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
5918 (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
5919 sense_buf[7] = 10; /* additional length */
5921 /* IOARCB was in error */
5922 if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
5923 sense_buf[15] = 0xC0;
5924 else /* Parameter data was invalid */
5925 sense_buf[15] = 0x80;
5928 ((IPR_FIELD_POINTER_MASK &
5929 be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
5931 (IPR_FIELD_POINTER_MASK &
5932 be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
5934 if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
5935 if (ipr_is_vset_device(res))
5936 failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
5938 failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
5940 sense_buf[0] |= 0x80; /* Or in the Valid bit */
5941 sense_buf[3] = (failing_lba & 0xff000000) >> 24;
5942 sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
5943 sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
5944 sense_buf[6] = failing_lba & 0x000000ff;
5947 sense_buf[7] = 6; /* additional length */
5953 * ipr_get_autosense - Copy autosense data to sense buffer
5954 * @ipr_cmd: ipr command struct
5956 * This function copies the autosense buffer to the buffer
5957 * in the scsi_cmd, if there is autosense available.
5960 * 1 if autosense was available / 0 if not
5962 static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
5964 struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
5965 struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
5967 if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
5970 if (ipr_cmd->ioa_cfg->sis64)
5971 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
5972 min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
5973 SCSI_SENSE_BUFFERSIZE));
5975 memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
5976 min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
5977 SCSI_SENSE_BUFFERSIZE));
5982 * ipr_erp_start - Process an error response for a SCSI op
5983 * @ioa_cfg: ioa config struct
5984 * @ipr_cmd: ipr command struct
5986 * This function determines whether or not to initiate ERP
5987 * on the affected device.
5992 static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
5993 struct ipr_cmnd *ipr_cmd)
5995 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
5996 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
5997 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
5998 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
6001 ipr_scsi_eh_done(ipr_cmd);
6005 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
6006 ipr_gen_sense(ipr_cmd);
6008 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6010 switch (masked_ioasc) {
6011 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
6012 if (ipr_is_naca_model(res))
6013 scsi_cmd->result |= (DID_ABORT << 16);
6015 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6017 case IPR_IOASC_IR_RESOURCE_HANDLE:
6018 case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
6019 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6021 case IPR_IOASC_HW_SEL_TIMEOUT:
6022 scsi_cmd->result |= (DID_NO_CONNECT << 16);
6023 if (!ipr_is_naca_model(res))
6024 res->needs_sync_complete = 1;
6026 case IPR_IOASC_SYNC_REQUIRED:
6028 res->needs_sync_complete = 1;
6029 scsi_cmd->result |= (DID_IMM_RETRY << 16);
6031 case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
6032 case IPR_IOASA_IR_DUAL_IOA_DISABLED:
6033 scsi_cmd->result |= (DID_PASSTHROUGH << 16);
6035 case IPR_IOASC_BUS_WAS_RESET:
6036 case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
6038 * Report the bus reset and ask for a retry. The device
6039 * will give CC/UA the next command.
6041 if (!res->resetting_device)
6042 scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
6043 scsi_cmd->result |= (DID_ERROR << 16);
6044 if (!ipr_is_naca_model(res))
6045 res->needs_sync_complete = 1;
6047 case IPR_IOASC_HW_DEV_BUS_STATUS:
6048 scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
6049 if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
6050 if (!ipr_get_autosense(ipr_cmd)) {
6051 if (!ipr_is_naca_model(res)) {
6052 ipr_erp_cancel_all(ipr_cmd);
6057 if (!ipr_is_naca_model(res))
6058 res->needs_sync_complete = 1;
6060 case IPR_IOASC_NR_INIT_CMD_REQUIRED:
6063 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6064 scsi_cmd->result |= (DID_ERROR << 16);
6065 if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
6066 res->needs_sync_complete = 1;
6070 scsi_dma_unmap(ipr_cmd->scsi_cmd);
6071 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6072 scsi_cmd->scsi_done(scsi_cmd);
6076 * ipr_scsi_done - mid-layer done function
6077 * @ipr_cmd: ipr command struct
6079 * This function is invoked by the interrupt handler for
6080 * ops generated by the SCSI mid-layer
6085 static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
6087 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6088 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
6089 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6090 unsigned long hrrq_flags;
6092 scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
6094 if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
6095 scsi_dma_unmap(scsi_cmd);
6097 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
6098 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6099 scsi_cmd->scsi_done(scsi_cmd);
6100 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
6102 spin_lock_irqsave(ipr_cmd->hrrq->lock, hrrq_flags);
6103 ipr_erp_start(ioa_cfg, ipr_cmd);
6104 spin_unlock_irqrestore(ipr_cmd->hrrq->lock, hrrq_flags);
6109 * ipr_queuecommand - Queue a mid-layer request
6110 * @shost: scsi host struct
6111 * @scsi_cmd: scsi command struct
6113 * This function queues a request generated by the mid-layer.
6117 * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
6118 * SCSI_MLQUEUE_HOST_BUSY if host is busy
6120 static int ipr_queuecommand(struct Scsi_Host *shost,
6121 struct scsi_cmnd *scsi_cmd)
6123 struct ipr_ioa_cfg *ioa_cfg;
6124 struct ipr_resource_entry *res;
6125 struct ipr_ioarcb *ioarcb;
6126 struct ipr_cmnd *ipr_cmd;
6127 unsigned long hrrq_flags, lock_flags;
6129 struct ipr_hrr_queue *hrrq;
6132 ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
6134 scsi_cmd->result = (DID_OK << 16);
6135 res = scsi_cmd->device->hostdata;
6137 if (ipr_is_gata(res) && res->sata_port) {
6138 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
6139 rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
6140 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
6144 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6145 hrrq = &ioa_cfg->hrrq[hrrq_id];
6147 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6149 * We are currently blocking all devices due to a host reset
6150 * We have told the host to stop giving us new requests, but
6151 * ERP ops don't count. FIXME
6153 if (unlikely(!hrrq->allow_cmds && !hrrq->ioa_is_dead && !hrrq->removing_ioa)) {
6154 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6155 return SCSI_MLQUEUE_HOST_BUSY;
6159 * FIXME - Create scsi_set_host_offline interface
6160 * and the ioa_is_dead check can be removed
6162 if (unlikely(hrrq->ioa_is_dead || hrrq->removing_ioa || !res)) {
6163 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6167 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6168 if (ipr_cmd == NULL) {
6169 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6170 return SCSI_MLQUEUE_HOST_BUSY;
6172 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6174 ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
6175 ioarcb = &ipr_cmd->ioarcb;
6177 memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
6178 ipr_cmd->scsi_cmd = scsi_cmd;
6179 ipr_cmd->done = ipr_scsi_eh_done;
6181 if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
6182 if (scsi_cmd->underflow == 0)
6183 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6185 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6186 if (ipr_is_gscsi(res))
6187 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
6188 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
6189 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
6192 if (scsi_cmd->cmnd[0] >= 0xC0 &&
6193 (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE)) {
6194 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6198 rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
6200 rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
6202 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6203 if (unlikely(rc || (!hrrq->allow_cmds && !hrrq->ioa_is_dead))) {
6204 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6205 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6207 scsi_dma_unmap(scsi_cmd);
6208 return SCSI_MLQUEUE_HOST_BUSY;
6211 if (unlikely(hrrq->ioa_is_dead)) {
6212 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_free_q);
6213 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6214 scsi_dma_unmap(scsi_cmd);
6218 ioarcb->res_handle = res->res_handle;
6219 if (res->needs_sync_complete) {
6220 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
6221 res->needs_sync_complete = 0;
6223 list_add_tail(&ipr_cmd->queue, &hrrq->hrrq_pending_q);
6224 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6225 ipr_send_command(ipr_cmd);
6226 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6230 spin_lock_irqsave(hrrq->lock, hrrq_flags);
6231 memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
6232 scsi_cmd->result = (DID_NO_CONNECT << 16);
6233 scsi_cmd->scsi_done(scsi_cmd);
6234 spin_unlock_irqrestore(hrrq->lock, hrrq_flags);
6239 * ipr_ioctl - IOCTL handler
6240 * @sdev: scsi device struct
6245 * 0 on success / other on failure
6247 static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
6249 struct ipr_resource_entry *res;
6251 res = (struct ipr_resource_entry *)sdev->hostdata;
6252 if (res && ipr_is_gata(res)) {
6253 if (cmd == HDIO_GET_IDENTITY)
6255 return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
6262 * ipr_info - Get information about the card/driver
6263 * @scsi_host: scsi host struct
6266 * pointer to buffer with description string
6268 static const char *ipr_ioa_info(struct Scsi_Host *host)
6270 static char buffer[512];
6271 struct ipr_ioa_cfg *ioa_cfg;
6272 unsigned long lock_flags = 0;
6274 ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
6276 spin_lock_irqsave(host->host_lock, lock_flags);
6277 sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
6278 spin_unlock_irqrestore(host->host_lock, lock_flags);
6283 static struct scsi_host_template driver_template = {
6284 .module = THIS_MODULE,
6286 .info = ipr_ioa_info,
6288 .queuecommand = ipr_queuecommand,
6289 .eh_abort_handler = ipr_eh_abort,
6290 .eh_device_reset_handler = ipr_eh_dev_reset,
6291 .eh_host_reset_handler = ipr_eh_host_reset,
6292 .slave_alloc = ipr_slave_alloc,
6293 .slave_configure = ipr_slave_configure,
6294 .slave_destroy = ipr_slave_destroy,
6295 .target_alloc = ipr_target_alloc,
6296 .target_destroy = ipr_target_destroy,
6297 .change_queue_depth = ipr_change_queue_depth,
6298 .change_queue_type = ipr_change_queue_type,
6299 .bios_param = ipr_biosparam,
6300 .can_queue = IPR_MAX_COMMANDS,
6302 .sg_tablesize = IPR_MAX_SGLIST,
6303 .max_sectors = IPR_IOA_MAX_SECTORS,
6304 .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
6305 .use_clustering = ENABLE_CLUSTERING,
6306 .shost_attrs = ipr_ioa_attrs,
6307 .sdev_attrs = ipr_dev_attrs,
6308 .proc_name = IPR_NAME,
6313 * ipr_ata_phy_reset - libata phy_reset handler
6314 * @ap: ata port to reset
6317 static void ipr_ata_phy_reset(struct ata_port *ap)
6319 unsigned long flags;
6320 struct ipr_sata_port *sata_port = ap->private_data;
6321 struct ipr_resource_entry *res = sata_port->res;
6322 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6326 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6327 while (ioa_cfg->in_reset_reload) {
6328 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6329 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6330 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6333 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
6336 rc = ipr_device_reset(ioa_cfg, res);
6339 ap->link.device[0].class = ATA_DEV_NONE;
6343 ap->link.device[0].class = res->ata_class;
6344 if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
6345 ap->link.device[0].class = ATA_DEV_NONE;
6348 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6353 * ipr_ata_post_internal - Cleanup after an internal command
6354 * @qc: ATA queued command
6359 static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
6361 struct ipr_sata_port *sata_port = qc->ap->private_data;
6362 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6363 struct ipr_cmnd *ipr_cmd;
6364 struct ipr_hrr_queue *hrrq;
6365 unsigned long flags;
6367 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6368 while (ioa_cfg->in_reset_reload) {
6369 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6370 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
6371 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6374 for_each_hrrq(hrrq, ioa_cfg) {
6375 spin_lock(&hrrq->_lock);
6376 list_for_each_entry(ipr_cmd, &hrrq->hrrq_pending_q, queue) {
6377 if (ipr_cmd->qc == qc) {
6378 ipr_device_reset(ioa_cfg, sata_port->res);
6382 spin_unlock(&hrrq->_lock);
6384 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6388 * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
6389 * @regs: destination
6390 * @tf: source ATA taskfile
6395 static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
6396 struct ata_taskfile *tf)
6398 regs->feature = tf->feature;
6399 regs->nsect = tf->nsect;
6400 regs->lbal = tf->lbal;
6401 regs->lbam = tf->lbam;
6402 regs->lbah = tf->lbah;
6403 regs->device = tf->device;
6404 regs->command = tf->command;
6405 regs->hob_feature = tf->hob_feature;
6406 regs->hob_nsect = tf->hob_nsect;
6407 regs->hob_lbal = tf->hob_lbal;
6408 regs->hob_lbam = tf->hob_lbam;
6409 regs->hob_lbah = tf->hob_lbah;
6410 regs->ctl = tf->ctl;
6414 * ipr_sata_done - done function for SATA commands
6415 * @ipr_cmd: ipr command struct
6417 * This function is invoked by the interrupt handler for
6418 * ops generated by the SCSI mid-layer to SATA devices
6423 static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
6425 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6426 struct ata_queued_cmd *qc = ipr_cmd->qc;
6427 struct ipr_sata_port *sata_port = qc->ap->private_data;
6428 struct ipr_resource_entry *res = sata_port->res;
6429 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
6431 spin_lock(&ipr_cmd->hrrq->_lock);
6432 if (ipr_cmd->ioa_cfg->sis64)
6433 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
6434 sizeof(struct ipr_ioasa_gata));
6436 memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
6437 sizeof(struct ipr_ioasa_gata));
6438 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
6440 if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
6441 scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
6443 if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
6444 qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
6446 qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
6447 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6448 spin_unlock(&ipr_cmd->hrrq->_lock);
6449 ata_qc_complete(qc);
6453 * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
6454 * @ipr_cmd: ipr command struct
6455 * @qc: ATA queued command
6458 static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
6459 struct ata_queued_cmd *qc)
6461 u32 ioadl_flags = 0;
6462 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6463 struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ata_ioadl.ioadl64;
6464 struct ipr_ioadl64_desc *last_ioadl64 = NULL;
6465 int len = qc->nbytes;
6466 struct scatterlist *sg;
6468 dma_addr_t dma_addr = ipr_cmd->dma_addr;
6473 if (qc->dma_dir == DMA_TO_DEVICE) {
6474 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6475 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6476 } else if (qc->dma_dir == DMA_FROM_DEVICE)
6477 ioadl_flags = IPR_IOADL_FLAGS_READ;
6479 ioarcb->data_transfer_length = cpu_to_be32(len);
6481 cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
6482 ioarcb->u.sis64_addr_data.data_ioadl_addr =
6483 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl.ioadl64));
6485 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6486 ioadl64->flags = cpu_to_be32(ioadl_flags);
6487 ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
6488 ioadl64->address = cpu_to_be64(sg_dma_address(sg));
6490 last_ioadl64 = ioadl64;
6494 if (likely(last_ioadl64))
6495 last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6499 * ipr_build_ata_ioadl - Build an ATA scatter/gather list
6500 * @ipr_cmd: ipr command struct
6501 * @qc: ATA queued command
6504 static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
6505 struct ata_queued_cmd *qc)
6507 u32 ioadl_flags = 0;
6508 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6509 struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
6510 struct ipr_ioadl_desc *last_ioadl = NULL;
6511 int len = qc->nbytes;
6512 struct scatterlist *sg;
6518 if (qc->dma_dir == DMA_TO_DEVICE) {
6519 ioadl_flags = IPR_IOADL_FLAGS_WRITE;
6520 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6521 ioarcb->data_transfer_length = cpu_to_be32(len);
6523 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6524 } else if (qc->dma_dir == DMA_FROM_DEVICE) {
6525 ioadl_flags = IPR_IOADL_FLAGS_READ;
6526 ioarcb->read_data_transfer_length = cpu_to_be32(len);
6527 ioarcb->read_ioadl_len =
6528 cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
6531 for_each_sg(qc->sg, sg, qc->n_elem, si) {
6532 ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
6533 ioadl->address = cpu_to_be32(sg_dma_address(sg));
6539 if (likely(last_ioadl))
6540 last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
6544 * ipr_qc_defer - Get a free ipr_cmd
6545 * @qc: queued command
6550 static int ipr_qc_defer(struct ata_queued_cmd *qc)
6552 struct ata_port *ap = qc->ap;
6553 struct ipr_sata_port *sata_port = ap->private_data;
6554 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6555 struct ipr_cmnd *ipr_cmd;
6556 struct ipr_hrr_queue *hrrq;
6559 hrrq_id = ipr_get_hrrq_index(ioa_cfg);
6560 hrrq = &ioa_cfg->hrrq[hrrq_id];
6562 qc->lldd_task = NULL;
6563 spin_lock(&hrrq->_lock);
6564 if (unlikely(hrrq->ioa_is_dead)) {
6565 spin_unlock(&hrrq->_lock);
6569 if (unlikely(!hrrq->allow_cmds)) {
6570 spin_unlock(&hrrq->_lock);
6571 return ATA_DEFER_LINK;
6574 ipr_cmd = __ipr_get_free_ipr_cmnd(hrrq);
6575 if (ipr_cmd == NULL) {
6576 spin_unlock(&hrrq->_lock);
6577 return ATA_DEFER_LINK;
6580 qc->lldd_task = ipr_cmd;
6581 spin_unlock(&hrrq->_lock);
6586 * ipr_qc_issue - Issue a SATA qc to a device
6587 * @qc: queued command
6592 static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
6594 struct ata_port *ap = qc->ap;
6595 struct ipr_sata_port *sata_port = ap->private_data;
6596 struct ipr_resource_entry *res = sata_port->res;
6597 struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
6598 struct ipr_cmnd *ipr_cmd;
6599 struct ipr_ioarcb *ioarcb;
6600 struct ipr_ioarcb_ata_regs *regs;
6602 if (qc->lldd_task == NULL)
6605 ipr_cmd = qc->lldd_task;
6606 if (ipr_cmd == NULL)
6607 return AC_ERR_SYSTEM;
6609 qc->lldd_task = NULL;
6610 spin_lock(&ipr_cmd->hrrq->_lock);
6611 if (unlikely(!ipr_cmd->hrrq->allow_cmds ||
6612 ipr_cmd->hrrq->ioa_is_dead)) {
6613 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6614 spin_unlock(&ipr_cmd->hrrq->_lock);
6615 return AC_ERR_SYSTEM;
6618 ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
6619 ioarcb = &ipr_cmd->ioarcb;
6621 if (ioa_cfg->sis64) {
6622 regs = &ipr_cmd->i.ata_ioadl.regs;
6623 ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
6625 regs = &ioarcb->u.add_data.u.regs;
6627 memset(regs, 0, sizeof(*regs));
6628 ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
6630 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
6632 ipr_cmd->done = ipr_sata_done;
6633 ipr_cmd->ioarcb.res_handle = res->res_handle;
6634 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
6635 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
6636 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
6637 ipr_cmd->dma_use_sg = qc->n_elem;
6640 ipr_build_ata_ioadl64(ipr_cmd, qc);
6642 ipr_build_ata_ioadl(ipr_cmd, qc);
6644 regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
6645 ipr_copy_sata_tf(regs, &qc->tf);
6646 memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
6647 ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
6649 switch (qc->tf.protocol) {
6650 case ATA_PROT_NODATA:
6655 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6658 case ATAPI_PROT_PIO:
6659 case ATAPI_PROT_NODATA:
6660 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6663 case ATAPI_PROT_DMA:
6664 regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
6665 regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
6670 spin_unlock(&ipr_cmd->hrrq->_lock);
6671 return AC_ERR_INVALID;
6674 ipr_send_command(ipr_cmd);
6675 spin_unlock(&ipr_cmd->hrrq->_lock);
6681 * ipr_qc_fill_rtf - Read result TF
6682 * @qc: ATA queued command
6687 static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
6689 struct ipr_sata_port *sata_port = qc->ap->private_data;
6690 struct ipr_ioasa_gata *g = &sata_port->ioasa;
6691 struct ata_taskfile *tf = &qc->result_tf;
6693 tf->feature = g->error;
6694 tf->nsect = g->nsect;
6698 tf->device = g->device;
6699 tf->command = g->status;
6700 tf->hob_nsect = g->hob_nsect;
6701 tf->hob_lbal = g->hob_lbal;
6702 tf->hob_lbam = g->hob_lbam;
6703 tf->hob_lbah = g->hob_lbah;
6708 static struct ata_port_operations ipr_sata_ops = {
6709 .phy_reset = ipr_ata_phy_reset,
6710 .hardreset = ipr_sata_reset,
6711 .post_internal_cmd = ipr_ata_post_internal,
6712 .qc_prep = ata_noop_qc_prep,
6713 .qc_defer = ipr_qc_defer,
6714 .qc_issue = ipr_qc_issue,
6715 .qc_fill_rtf = ipr_qc_fill_rtf,
6716 .port_start = ata_sas_port_start,
6717 .port_stop = ata_sas_port_stop
6720 static struct ata_port_info sata_port_info = {
6721 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
6722 .pio_mask = ATA_PIO4_ONLY,
6723 .mwdma_mask = ATA_MWDMA2,
6724 .udma_mask = ATA_UDMA6,
6725 .port_ops = &ipr_sata_ops
6728 #ifdef CONFIG_PPC_PSERIES
6729 static const u16 ipr_blocked_processors[] = {
6741 * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
6742 * @ioa_cfg: ioa cfg struct
6744 * Adapters that use Gemstone revision < 3.1 do not work reliably on
6745 * certain pSeries hardware. This function determines if the given
6746 * adapter is in one of these confgurations or not.
6749 * 1 if adapter is not supported / 0 if adapter is supported
6751 static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
6755 if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
6756 for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
6757 if (pvr_version_is(ipr_blocked_processors[i]))
6764 #define ipr_invalid_adapter(ioa_cfg) 0
6768 * ipr_ioa_bringdown_done - IOA bring down completion.
6769 * @ipr_cmd: ipr command struct
6771 * This function processes the completion of an adapter bring down.
6772 * It wakes any reset sleepers.
6777 static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
6779 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6783 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
6785 spin_unlock_irq(ioa_cfg->host->host_lock);
6786 scsi_unblock_requests(ioa_cfg->host);
6787 spin_lock_irq(ioa_cfg->host->host_lock);
6790 ioa_cfg->in_reset_reload = 0;
6791 ioa_cfg->reset_retries = 0;
6792 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
6793 spin_lock(&ioa_cfg->hrrq[i]._lock);
6794 ioa_cfg->hrrq[i].ioa_is_dead = 1;
6795 spin_unlock(&ioa_cfg->hrrq[i]._lock);
6799 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6800 wake_up_all(&ioa_cfg->reset_wait_q);
6803 return IPR_RC_JOB_RETURN;
6807 * ipr_ioa_reset_done - IOA reset completion.
6808 * @ipr_cmd: ipr command struct
6810 * This function processes the completion of an adapter reset.
6811 * It schedules any necessary mid-layer add/removes and
6812 * wakes any reset sleepers.
6817 static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
6819 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6820 struct ipr_resource_entry *res;
6821 struct ipr_hostrcb *hostrcb, *temp;
6825 ioa_cfg->in_reset_reload = 0;
6826 for (j = 0; j < ioa_cfg->hrrq_num; j++) {
6827 spin_lock(&ioa_cfg->hrrq[j]._lock);
6828 ioa_cfg->hrrq[j].allow_cmds = 1;
6829 spin_unlock(&ioa_cfg->hrrq[j]._lock);
6832 ioa_cfg->reset_cmd = NULL;
6833 ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
6835 list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
6836 if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
6841 schedule_work(&ioa_cfg->work_q);
6843 list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
6844 list_del(&hostrcb->queue);
6845 if (i++ < IPR_NUM_LOG_HCAMS)
6846 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
6848 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
6851 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
6852 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
6854 ioa_cfg->reset_retries = 0;
6855 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
6856 wake_up_all(&ioa_cfg->reset_wait_q);
6858 spin_unlock(ioa_cfg->host->host_lock);
6859 scsi_unblock_requests(ioa_cfg->host);
6860 spin_lock(ioa_cfg->host->host_lock);
6862 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds)
6863 scsi_block_requests(ioa_cfg->host);
6866 return IPR_RC_JOB_RETURN;
6870 * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
6871 * @supported_dev: supported device struct
6872 * @vpids: vendor product id struct
6877 static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
6878 struct ipr_std_inq_vpids *vpids)
6880 memset(supported_dev, 0, sizeof(struct ipr_supported_device));
6881 memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
6882 supported_dev->num_records = 1;
6883 supported_dev->data_length =
6884 cpu_to_be16(sizeof(struct ipr_supported_device));
6885 supported_dev->reserved = 0;
6889 * ipr_set_supported_devs - Send Set Supported Devices for a device
6890 * @ipr_cmd: ipr command struct
6892 * This function sends a Set Supported Devices to the adapter
6895 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6897 static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
6899 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6900 struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
6901 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
6902 struct ipr_resource_entry *res = ipr_cmd->u.res;
6904 ipr_cmd->job_step = ipr_ioa_reset_done;
6906 list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
6907 if (!ipr_is_scsi_disk(res))
6910 ipr_cmd->u.res = res;
6911 ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
6913 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
6914 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
6915 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
6917 ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
6918 ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
6919 ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
6920 ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
6922 ipr_init_ioadl(ipr_cmd,
6923 ioa_cfg->vpd_cbs_dma +
6924 offsetof(struct ipr_misc_cbs, supp_dev),
6925 sizeof(struct ipr_supported_device),
6926 IPR_IOADL_FLAGS_WRITE_LAST);
6928 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
6929 IPR_SET_SUP_DEVICE_TIMEOUT);
6931 if (!ioa_cfg->sis64)
6932 ipr_cmd->job_step = ipr_set_supported_devs;
6934 return IPR_RC_JOB_RETURN;
6938 return IPR_RC_JOB_CONTINUE;
6942 * ipr_get_mode_page - Locate specified mode page
6943 * @mode_pages: mode page buffer
6944 * @page_code: page code to find
6945 * @len: minimum required length for mode page
6948 * pointer to mode page / NULL on failure
6950 static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
6951 u32 page_code, u32 len)
6953 struct ipr_mode_page_hdr *mode_hdr;
6957 if (!mode_pages || (mode_pages->hdr.length == 0))
6960 length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
6961 mode_hdr = (struct ipr_mode_page_hdr *)
6962 (mode_pages->data + mode_pages->hdr.block_desc_len);
6965 if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
6966 if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
6970 page_length = (sizeof(struct ipr_mode_page_hdr) +
6971 mode_hdr->page_length);
6972 length -= page_length;
6973 mode_hdr = (struct ipr_mode_page_hdr *)
6974 ((unsigned long)mode_hdr + page_length);
6981 * ipr_check_term_power - Check for term power errors
6982 * @ioa_cfg: ioa config struct
6983 * @mode_pages: IOAFP mode pages buffer
6985 * Check the IOAFP's mode page 28 for term power errors
6990 static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
6991 struct ipr_mode_pages *mode_pages)
6995 struct ipr_dev_bus_entry *bus;
6996 struct ipr_mode_page28 *mode_page;
6998 mode_page = ipr_get_mode_page(mode_pages, 0x28,
6999 sizeof(struct ipr_mode_page28));
7001 entry_length = mode_page->entry_length;
7003 bus = mode_page->bus;
7005 for (i = 0; i < mode_page->num_entries; i++) {
7006 if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
7007 dev_err(&ioa_cfg->pdev->dev,
7008 "Term power is absent on scsi bus %d\n",
7012 bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
7017 * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
7018 * @ioa_cfg: ioa config struct
7020 * Looks through the config table checking for SES devices. If
7021 * the SES device is in the SES table indicating a maximum SCSI
7022 * bus speed, the speed is limited for the bus.
7027 static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
7032 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
7033 max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
7034 ioa_cfg->bus_attr[i].bus_width);
7036 if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
7037 ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
7042 * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
7043 * @ioa_cfg: ioa config struct
7044 * @mode_pages: mode page 28 buffer
7046 * Updates mode page 28 based on driver configuration
7051 static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
7052 struct ipr_mode_pages *mode_pages)
7054 int i, entry_length;
7055 struct ipr_dev_bus_entry *bus;
7056 struct ipr_bus_attributes *bus_attr;
7057 struct ipr_mode_page28 *mode_page;
7059 mode_page = ipr_get_mode_page(mode_pages, 0x28,
7060 sizeof(struct ipr_mode_page28));
7062 entry_length = mode_page->entry_length;
7064 /* Loop for each device bus entry */
7065 for (i = 0, bus = mode_page->bus;
7066 i < mode_page->num_entries;
7067 i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
7068 if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
7069 dev_err(&ioa_cfg->pdev->dev,
7070 "Invalid resource address reported: 0x%08X\n",
7071 IPR_GET_PHYS_LOC(bus->res_addr));
7075 bus_attr = &ioa_cfg->bus_attr[i];
7076 bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
7077 bus->bus_width = bus_attr->bus_width;
7078 bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
7079 bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
7080 if (bus_attr->qas_enabled)
7081 bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
7083 bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
7088 * ipr_build_mode_select - Build a mode select command
7089 * @ipr_cmd: ipr command struct
7090 * @res_handle: resource handle to send command to
7091 * @parm: Byte 2 of Mode Sense command
7092 * @dma_addr: DMA buffer address
7093 * @xfer_len: data transfer length
7098 static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
7099 __be32 res_handle, u8 parm,
7100 dma_addr_t dma_addr, u8 xfer_len)
7102 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7104 ioarcb->res_handle = res_handle;
7105 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7106 ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
7107 ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
7108 ioarcb->cmd_pkt.cdb[1] = parm;
7109 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7111 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
7115 * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
7116 * @ipr_cmd: ipr command struct
7118 * This function sets up the SCSI bus attributes and sends
7119 * a Mode Select for Page 28 to activate them.
7124 static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
7126 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7127 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7131 ipr_scsi_bus_speed_limit(ioa_cfg);
7132 ipr_check_term_power(ioa_cfg, mode_pages);
7133 ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
7134 length = mode_pages->hdr.length + 1;
7135 mode_pages->hdr.length = 0;
7137 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7138 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7141 ipr_cmd->job_step = ipr_set_supported_devs;
7142 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7143 struct ipr_resource_entry, queue);
7144 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7147 return IPR_RC_JOB_RETURN;
7151 * ipr_build_mode_sense - Builds a mode sense command
7152 * @ipr_cmd: ipr command struct
7153 * @res: resource entry struct
7154 * @parm: Byte 2 of mode sense command
7155 * @dma_addr: DMA address of mode sense buffer
7156 * @xfer_len: Size of DMA buffer
7161 static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
7163 u8 parm, dma_addr_t dma_addr, u8 xfer_len)
7165 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7167 ioarcb->res_handle = res_handle;
7168 ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
7169 ioarcb->cmd_pkt.cdb[2] = parm;
7170 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7171 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7173 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7177 * ipr_reset_cmd_failed - Handle failure of IOA reset command
7178 * @ipr_cmd: ipr command struct
7180 * This function handles the failure of an IOA bringup command.
7185 static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
7187 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7188 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7190 dev_err(&ioa_cfg->pdev->dev,
7191 "0x%02X failed with IOASC: 0x%08X\n",
7192 ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
7194 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7195 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
7196 return IPR_RC_JOB_RETURN;
7200 * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
7201 * @ipr_cmd: ipr command struct
7203 * This function handles the failure of a Mode Sense to the IOAFP.
7204 * Some adapters do not handle all mode pages.
7207 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7209 static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
7211 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7212 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7214 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7215 ipr_cmd->job_step = ipr_set_supported_devs;
7216 ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
7217 struct ipr_resource_entry, queue);
7218 return IPR_RC_JOB_CONTINUE;
7221 return ipr_reset_cmd_failed(ipr_cmd);
7225 * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
7226 * @ipr_cmd: ipr command struct
7228 * This function send a Page 28 mode sense to the IOA to
7229 * retrieve SCSI bus attributes.
7234 static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
7236 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7239 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7240 0x28, ioa_cfg->vpd_cbs_dma +
7241 offsetof(struct ipr_misc_cbs, mode_pages),
7242 sizeof(struct ipr_mode_pages));
7244 ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
7245 ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
7247 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7250 return IPR_RC_JOB_RETURN;
7254 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
7255 * @ipr_cmd: ipr command struct
7257 * This function enables dual IOA RAID support if possible.
7262 static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
7264 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7265 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
7266 struct ipr_mode_page24 *mode_page;
7270 mode_page = ipr_get_mode_page(mode_pages, 0x24,
7271 sizeof(struct ipr_mode_page24));
7274 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
7276 length = mode_pages->hdr.length + 1;
7277 mode_pages->hdr.length = 0;
7279 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
7280 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
7283 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7284 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7287 return IPR_RC_JOB_RETURN;
7291 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
7292 * @ipr_cmd: ipr command struct
7294 * This function handles the failure of a Mode Sense to the IOAFP.
7295 * Some adapters do not handle all mode pages.
7298 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7300 static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
7302 u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
7304 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
7305 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7306 return IPR_RC_JOB_CONTINUE;
7309 return ipr_reset_cmd_failed(ipr_cmd);
7313 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
7314 * @ipr_cmd: ipr command struct
7316 * This function send a mode sense to the IOA to retrieve
7317 * the IOA Advanced Function Control mode page.
7322 static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
7324 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7327 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
7328 0x24, ioa_cfg->vpd_cbs_dma +
7329 offsetof(struct ipr_misc_cbs, mode_pages),
7330 sizeof(struct ipr_mode_pages));
7332 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
7333 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
7335 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7338 return IPR_RC_JOB_RETURN;
7342 * ipr_init_res_table - Initialize the resource table
7343 * @ipr_cmd: ipr command struct
7345 * This function looks through the existing resource table, comparing
7346 * it with the config table. This function will take care of old/new
7347 * devices and schedule adding/removing them from the mid-layer
7351 * IPR_RC_JOB_CONTINUE
7353 static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
7355 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7356 struct ipr_resource_entry *res, *temp;
7357 struct ipr_config_table_entry_wrapper cfgtew;
7358 int entries, found, flag, i;
7363 flag = ioa_cfg->u.cfg_table64->hdr64.flags;
7365 flag = ioa_cfg->u.cfg_table->hdr.flags;
7367 if (flag & IPR_UCODE_DOWNLOAD_REQ)
7368 dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
7370 list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
7371 list_move_tail(&res->queue, &old_res);
7374 entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
7376 entries = ioa_cfg->u.cfg_table->hdr.num_entries;
7378 for (i = 0; i < entries; i++) {
7380 cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
7382 cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
7385 list_for_each_entry_safe(res, temp, &old_res, queue) {
7386 if (ipr_is_same_device(res, &cfgtew)) {
7387 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7394 if (list_empty(&ioa_cfg->free_res_q)) {
7395 dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
7400 res = list_entry(ioa_cfg->free_res_q.next,
7401 struct ipr_resource_entry, queue);
7402 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7403 ipr_init_res_entry(res, &cfgtew);
7405 } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
7406 res->sdev->allow_restart = 1;
7409 ipr_update_res_entry(res, &cfgtew);
7412 list_for_each_entry_safe(res, temp, &old_res, queue) {
7414 res->del_from_ml = 1;
7415 res->res_handle = IPR_INVALID_RES_HANDLE;
7416 list_move_tail(&res->queue, &ioa_cfg->used_res_q);
7420 list_for_each_entry_safe(res, temp, &old_res, queue) {
7421 ipr_clear_res_target(res);
7422 list_move_tail(&res->queue, &ioa_cfg->free_res_q);
7425 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
7426 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
7428 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
7431 return IPR_RC_JOB_CONTINUE;
7435 * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
7436 * @ipr_cmd: ipr command struct
7438 * This function sends a Query IOA Configuration command
7439 * to the adapter to retrieve the IOA configuration table.
7444 static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
7446 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7447 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7448 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
7449 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7452 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
7453 ioa_cfg->dual_raid = 1;
7454 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
7455 ucode_vpd->major_release, ucode_vpd->card_type,
7456 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
7457 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7458 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7460 ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
7461 ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
7462 ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
7463 ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
7465 ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
7466 IPR_IOADL_FLAGS_READ_LAST);
7468 ipr_cmd->job_step = ipr_init_res_table;
7470 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7473 return IPR_RC_JOB_RETURN;
7477 * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
7478 * @ipr_cmd: ipr command struct
7480 * This utility function sends an inquiry to the adapter.
7485 static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
7486 dma_addr_t dma_addr, u8 xfer_len)
7488 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7491 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
7492 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7494 ioarcb->cmd_pkt.cdb[0] = INQUIRY;
7495 ioarcb->cmd_pkt.cdb[1] = flags;
7496 ioarcb->cmd_pkt.cdb[2] = page;
7497 ioarcb->cmd_pkt.cdb[4] = xfer_len;
7499 ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
7501 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
7506 * ipr_inquiry_page_supported - Is the given inquiry page supported
7507 * @page0: inquiry page 0 buffer
7510 * This function determines if the specified inquiry page is supported.
7513 * 1 if page is supported / 0 if not
7515 static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
7519 for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
7520 if (page0->page[i] == page)
7527 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
7528 * @ipr_cmd: ipr command struct
7530 * This function sends a Page 0xD0 inquiry to the adapter
7531 * to retrieve adapter capabilities.
7534 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7536 static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
7538 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7539 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
7540 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
7543 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
7544 memset(cap, 0, sizeof(*cap));
7546 if (ipr_inquiry_page_supported(page0, 0xD0)) {
7547 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
7548 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
7549 sizeof(struct ipr_inquiry_cap));
7550 return IPR_RC_JOB_RETURN;
7554 return IPR_RC_JOB_CONTINUE;
7558 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
7559 * @ipr_cmd: ipr command struct
7561 * This function sends a Page 3 inquiry to the adapter
7562 * to retrieve software VPD information.
7565 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7567 static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
7569 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7573 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
7575 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
7576 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
7577 sizeof(struct ipr_inquiry_page3));
7580 return IPR_RC_JOB_RETURN;
7584 * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
7585 * @ipr_cmd: ipr command struct
7587 * This function sends a Page 0 inquiry to the adapter
7588 * to retrieve supported inquiry pages.
7591 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7593 static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
7595 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7600 /* Grab the type out of the VPD and store it away */
7601 memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
7603 ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
7605 ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
7607 ipr_ioafp_inquiry(ipr_cmd, 1, 0,
7608 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
7609 sizeof(struct ipr_inquiry_page0));
7612 return IPR_RC_JOB_RETURN;
7616 * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
7617 * @ipr_cmd: ipr command struct
7619 * This function sends a standard inquiry to the adapter.
7624 static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
7626 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7629 ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
7631 ipr_ioafp_inquiry(ipr_cmd, 0, 0,
7632 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
7633 sizeof(struct ipr_ioa_vpd));
7636 return IPR_RC_JOB_RETURN;
7640 * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
7641 * @ipr_cmd: ipr command struct
7643 * This function send an Identify Host Request Response Queue
7644 * command to establish the HRRQ with the adapter.
7649 static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
7651 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7652 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
7653 struct ipr_hrr_queue *hrrq;
7656 ipr_cmd->job_step = ipr_ioafp_std_inquiry;
7657 dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
7659 if (ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num) {
7660 hrrq = &ioa_cfg->hrrq[ioa_cfg->identify_hrrq_index];
7662 ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
7663 ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
7665 ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
7667 ioarcb->cmd_pkt.cdb[1] = 0x1;
7669 if (ioa_cfg->nvectors == 1)
7670 ioarcb->cmd_pkt.cdb[1] &= ~IPR_ID_HRRQ_SELE_ENABLE;
7672 ioarcb->cmd_pkt.cdb[1] |= IPR_ID_HRRQ_SELE_ENABLE;
7674 ioarcb->cmd_pkt.cdb[2] =
7675 ((u64) hrrq->host_rrq_dma >> 24) & 0xff;
7676 ioarcb->cmd_pkt.cdb[3] =
7677 ((u64) hrrq->host_rrq_dma >> 16) & 0xff;
7678 ioarcb->cmd_pkt.cdb[4] =
7679 ((u64) hrrq->host_rrq_dma >> 8) & 0xff;
7680 ioarcb->cmd_pkt.cdb[5] =
7681 ((u64) hrrq->host_rrq_dma) & 0xff;
7682 ioarcb->cmd_pkt.cdb[7] =
7683 ((sizeof(u32) * hrrq->size) >> 8) & 0xff;
7684 ioarcb->cmd_pkt.cdb[8] =
7685 (sizeof(u32) * hrrq->size) & 0xff;
7687 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7688 ioarcb->cmd_pkt.cdb[9] =
7689 ioa_cfg->identify_hrrq_index;
7691 if (ioa_cfg->sis64) {
7692 ioarcb->cmd_pkt.cdb[10] =
7693 ((u64) hrrq->host_rrq_dma >> 56) & 0xff;
7694 ioarcb->cmd_pkt.cdb[11] =
7695 ((u64) hrrq->host_rrq_dma >> 48) & 0xff;
7696 ioarcb->cmd_pkt.cdb[12] =
7697 ((u64) hrrq->host_rrq_dma >> 40) & 0xff;
7698 ioarcb->cmd_pkt.cdb[13] =
7699 ((u64) hrrq->host_rrq_dma >> 32) & 0xff;
7702 if (ioarcb->cmd_pkt.cdb[1] & IPR_ID_HRRQ_SELE_ENABLE)
7703 ioarcb->cmd_pkt.cdb[14] =
7704 ioa_cfg->identify_hrrq_index;
7706 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
7707 IPR_INTERNAL_TIMEOUT);
7709 if (++ioa_cfg->identify_hrrq_index < ioa_cfg->hrrq_num)
7710 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7713 return IPR_RC_JOB_RETURN;
7717 return IPR_RC_JOB_CONTINUE;
7721 * ipr_reset_timer_done - Adapter reset timer function
7722 * @ipr_cmd: ipr command struct
7724 * Description: This function is used in adapter reset processing
7725 * for timing events. If the reset_cmd pointer in the IOA
7726 * config struct is not this adapter's we are doing nested
7727 * resets and fail_all_ops will take care of freeing the
7733 static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
7735 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7736 unsigned long lock_flags = 0;
7738 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7740 if (ioa_cfg->reset_cmd == ipr_cmd) {
7741 list_del(&ipr_cmd->queue);
7742 ipr_cmd->done(ipr_cmd);
7745 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7749 * ipr_reset_start_timer - Start a timer for adapter reset job
7750 * @ipr_cmd: ipr command struct
7751 * @timeout: timeout value
7753 * Description: This function is used in adapter reset processing
7754 * for timing events. If the reset_cmd pointer in the IOA
7755 * config struct is not this adapter's we are doing nested
7756 * resets and fail_all_ops will take care of freeing the
7762 static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
7763 unsigned long timeout)
7767 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7768 ipr_cmd->done = ipr_reset_ioa_job;
7770 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7771 ipr_cmd->timer.expires = jiffies + timeout;
7772 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
7773 add_timer(&ipr_cmd->timer);
7777 * ipr_init_ioa_mem - Initialize ioa_cfg control block
7778 * @ioa_cfg: ioa cfg struct
7783 static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
7785 struct ipr_hrr_queue *hrrq;
7787 for_each_hrrq(hrrq, ioa_cfg) {
7788 spin_lock(&hrrq->_lock);
7789 memset(hrrq->host_rrq, 0, sizeof(u32) * hrrq->size);
7791 /* Initialize Host RRQ pointers */
7792 hrrq->hrrq_start = hrrq->host_rrq;
7793 hrrq->hrrq_end = &hrrq->host_rrq[hrrq->size - 1];
7794 hrrq->hrrq_curr = hrrq->hrrq_start;
7795 hrrq->toggle_bit = 1;
7796 spin_unlock(&hrrq->_lock);
7800 ioa_cfg->identify_hrrq_index = 0;
7801 if (ioa_cfg->hrrq_num == 1)
7802 atomic_set(&ioa_cfg->hrrq_index, 0);
7804 atomic_set(&ioa_cfg->hrrq_index, 1);
7806 /* Zero out config table */
7807 memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
7811 * ipr_reset_next_stage - Process IPL stage change based on feedback register.
7812 * @ipr_cmd: ipr command struct
7815 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
7817 static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
7819 unsigned long stage, stage_time;
7821 volatile u32 int_reg;
7822 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7825 feedback = readl(ioa_cfg->regs.init_feedback_reg);
7826 stage = feedback & IPR_IPL_INIT_STAGE_MASK;
7827 stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
7829 ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
7831 /* sanity check the stage_time value */
7832 if (stage_time == 0)
7833 stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
7834 else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
7835 stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
7836 else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
7837 stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
7839 if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
7840 writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
7841 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7842 stage_time = ioa_cfg->transop_timeout;
7843 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7844 } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
7845 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7846 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7847 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7848 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7849 maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
7850 writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
7851 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7852 return IPR_RC_JOB_CONTINUE;
7856 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7857 ipr_cmd->timer.expires = jiffies + stage_time * HZ;
7858 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7859 ipr_cmd->done = ipr_reset_ioa_job;
7860 add_timer(&ipr_cmd->timer);
7862 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7864 return IPR_RC_JOB_RETURN;
7868 * ipr_reset_enable_ioa - Enable the IOA following a reset.
7869 * @ipr_cmd: ipr command struct
7871 * This function reinitializes some control blocks and
7872 * enables destructive diagnostics on the adapter.
7877 static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
7879 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7880 volatile u32 int_reg;
7881 volatile u64 maskval;
7885 ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
7886 ipr_init_ioa_mem(ioa_cfg);
7888 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
7889 spin_lock(&ioa_cfg->hrrq[i]._lock);
7890 ioa_cfg->hrrq[i].allow_interrupts = 1;
7891 spin_unlock(&ioa_cfg->hrrq[i]._lock);
7894 if (ioa_cfg->sis64) {
7895 /* Set the adapter to the correct endian mode. */
7896 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
7897 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
7900 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
7902 if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
7903 writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
7904 ioa_cfg->regs.clr_interrupt_mask_reg32);
7905 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7906 return IPR_RC_JOB_CONTINUE;
7909 /* Enable destructive diagnostics on IOA */
7910 writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
7912 if (ioa_cfg->sis64) {
7913 maskval = IPR_PCII_IPL_STAGE_CHANGE;
7914 maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
7915 writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
7917 writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
7919 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7921 dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
7923 if (ioa_cfg->sis64) {
7924 ipr_cmd->job_step = ipr_reset_next_stage;
7925 return IPR_RC_JOB_CONTINUE;
7928 ipr_cmd->timer.data = (unsigned long) ipr_cmd;
7929 ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
7930 ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
7931 ipr_cmd->done = ipr_reset_ioa_job;
7932 add_timer(&ipr_cmd->timer);
7933 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
7936 return IPR_RC_JOB_RETURN;
7940 * ipr_reset_wait_for_dump - Wait for a dump to timeout.
7941 * @ipr_cmd: ipr command struct
7943 * This function is invoked when an adapter dump has run out
7944 * of processing time.
7947 * IPR_RC_JOB_CONTINUE
7949 static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
7951 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
7953 if (ioa_cfg->sdt_state == GET_DUMP)
7954 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
7955 else if (ioa_cfg->sdt_state == READ_DUMP)
7956 ioa_cfg->sdt_state = ABORT_DUMP;
7958 ioa_cfg->dump_timeout = 1;
7959 ipr_cmd->job_step = ipr_reset_alert;
7961 return IPR_RC_JOB_CONTINUE;
7965 * ipr_unit_check_no_data - Log a unit check/no data error log
7966 * @ioa_cfg: ioa config struct
7968 * Logs an error indicating the adapter unit checked, but for some
7969 * reason, we were unable to fetch the unit check buffer.
7974 static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
7976 ioa_cfg->errors_logged++;
7977 dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
7981 * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
7982 * @ioa_cfg: ioa config struct
7984 * Fetches the unit check buffer from the adapter by clocking the data
7985 * through the mailbox register.
7990 static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
7992 unsigned long mailbox;
7993 struct ipr_hostrcb *hostrcb;
7994 struct ipr_uc_sdt sdt;
7998 mailbox = readl(ioa_cfg->ioa_mailbox);
8000 if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
8001 ipr_unit_check_no_data(ioa_cfg);
8005 memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
8006 rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
8007 (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
8009 if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
8010 ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
8011 (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
8012 ipr_unit_check_no_data(ioa_cfg);
8016 /* Find length of the first sdt entry (UC buffer) */
8017 if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
8018 length = be32_to_cpu(sdt.entry[0].end_token);
8020 length = (be32_to_cpu(sdt.entry[0].end_token) -
8021 be32_to_cpu(sdt.entry[0].start_token)) &
8022 IPR_FMT2_MBX_ADDR_MASK;
8024 hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
8025 struct ipr_hostrcb, queue);
8026 list_del(&hostrcb->queue);
8027 memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
8029 rc = ipr_get_ldump_data_section(ioa_cfg,
8030 be32_to_cpu(sdt.entry[0].start_token),
8031 (__be32 *)&hostrcb->hcam,
8032 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
8035 ipr_handle_log_data(ioa_cfg, hostrcb);
8036 ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
8037 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
8038 ioa_cfg->sdt_state == GET_DUMP)
8039 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8041 ipr_unit_check_no_data(ioa_cfg);
8043 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
8047 * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
8048 * @ipr_cmd: ipr command struct
8050 * Description: This function will call to get the unit check buffer.
8055 static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
8057 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8060 ioa_cfg->ioa_unit_checked = 0;
8061 ipr_get_unit_check_buffer(ioa_cfg);
8062 ipr_cmd->job_step = ipr_reset_alert;
8063 ipr_reset_start_timer(ipr_cmd, 0);
8066 return IPR_RC_JOB_RETURN;
8070 * ipr_reset_restore_cfg_space - Restore PCI config space.
8071 * @ipr_cmd: ipr command struct
8073 * Description: This function restores the saved PCI config space of
8074 * the adapter, fails all outstanding ops back to the callers, and
8075 * fetches the dump/unit check if applicable to this reset.
8078 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8080 static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
8082 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8086 ioa_cfg->pdev->state_saved = true;
8087 pci_restore_state(ioa_cfg->pdev);
8089 if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
8090 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8091 return IPR_RC_JOB_CONTINUE;
8094 ipr_fail_all_ops(ioa_cfg);
8096 if (ioa_cfg->sis64) {
8097 /* Set the adapter to the correct endian mode. */
8098 writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
8099 int_reg = readl(ioa_cfg->regs.endian_swap_reg);
8102 if (ioa_cfg->ioa_unit_checked) {
8103 if (ioa_cfg->sis64) {
8104 ipr_cmd->job_step = ipr_reset_get_unit_check_job;
8105 ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
8106 return IPR_RC_JOB_RETURN;
8108 ioa_cfg->ioa_unit_checked = 0;
8109 ipr_get_unit_check_buffer(ioa_cfg);
8110 ipr_cmd->job_step = ipr_reset_alert;
8111 ipr_reset_start_timer(ipr_cmd, 0);
8112 return IPR_RC_JOB_RETURN;
8116 if (ioa_cfg->in_ioa_bringdown) {
8117 ipr_cmd->job_step = ipr_ioa_bringdown_done;
8119 ipr_cmd->job_step = ipr_reset_enable_ioa;
8121 if (GET_DUMP == ioa_cfg->sdt_state) {
8122 ioa_cfg->sdt_state = READ_DUMP;
8123 ioa_cfg->dump_timeout = 0;
8125 ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
8127 ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
8128 ipr_cmd->job_step = ipr_reset_wait_for_dump;
8129 schedule_work(&ioa_cfg->work_q);
8130 return IPR_RC_JOB_RETURN;
8135 return IPR_RC_JOB_CONTINUE;
8139 * ipr_reset_bist_done - BIST has completed on the adapter.
8140 * @ipr_cmd: ipr command struct
8142 * Description: Unblock config space and resume the reset process.
8145 * IPR_RC_JOB_CONTINUE
8147 static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
8149 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8152 if (ioa_cfg->cfg_locked)
8153 pci_cfg_access_unlock(ioa_cfg->pdev);
8154 ioa_cfg->cfg_locked = 0;
8155 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
8157 return IPR_RC_JOB_CONTINUE;
8161 * ipr_reset_start_bist - Run BIST on the adapter.
8162 * @ipr_cmd: ipr command struct
8164 * Description: This function runs BIST on the adapter, then delays 2 seconds.
8167 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8169 static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
8171 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8172 int rc = PCIBIOS_SUCCESSFUL;
8175 if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
8176 writel(IPR_UPROCI_SIS64_START_BIST,
8177 ioa_cfg->regs.set_uproc_interrupt_reg32);
8179 rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
8181 if (rc == PCIBIOS_SUCCESSFUL) {
8182 ipr_cmd->job_step = ipr_reset_bist_done;
8183 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8184 rc = IPR_RC_JOB_RETURN;
8186 if (ioa_cfg->cfg_locked)
8187 pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
8188 ioa_cfg->cfg_locked = 0;
8189 ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
8190 rc = IPR_RC_JOB_CONTINUE;
8198 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
8199 * @ipr_cmd: ipr command struct
8201 * Description: This clears PCI reset to the adapter and delays two seconds.
8206 static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
8209 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
8210 ipr_cmd->job_step = ipr_reset_bist_done;
8211 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
8213 return IPR_RC_JOB_RETURN;
8217 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
8218 * @ipr_cmd: ipr command struct
8220 * Description: This asserts PCI reset to the adapter.
8225 static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
8227 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8228 struct pci_dev *pdev = ioa_cfg->pdev;
8231 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
8232 ipr_cmd->job_step = ipr_reset_slot_reset_done;
8233 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
8235 return IPR_RC_JOB_RETURN;
8239 * ipr_reset_block_config_access_wait - Wait for permission to block config access
8240 * @ipr_cmd: ipr command struct
8242 * Description: This attempts to block config access to the IOA.
8245 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8247 static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
8249 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8250 int rc = IPR_RC_JOB_CONTINUE;
8252 if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
8253 ioa_cfg->cfg_locked = 1;
8254 ipr_cmd->job_step = ioa_cfg->reset;
8256 if (ipr_cmd->u.time_left) {
8257 rc = IPR_RC_JOB_RETURN;
8258 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8259 ipr_reset_start_timer(ipr_cmd,
8260 IPR_CHECK_FOR_RESET_TIMEOUT);
8262 ipr_cmd->job_step = ioa_cfg->reset;
8263 dev_err(&ioa_cfg->pdev->dev,
8264 "Timed out waiting to lock config access. Resetting anyway.\n");
8272 * ipr_reset_block_config_access - Block config access to the IOA
8273 * @ipr_cmd: ipr command struct
8275 * Description: This attempts to block config access to the IOA
8278 * IPR_RC_JOB_CONTINUE
8280 static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
8282 ipr_cmd->ioa_cfg->cfg_locked = 0;
8283 ipr_cmd->job_step = ipr_reset_block_config_access_wait;
8284 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8285 return IPR_RC_JOB_CONTINUE;
8289 * ipr_reset_allowed - Query whether or not IOA can be reset
8290 * @ioa_cfg: ioa config struct
8293 * 0 if reset not allowed / non-zero if reset is allowed
8295 static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
8297 volatile u32 temp_reg;
8299 temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
8300 return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
8304 * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
8305 * @ipr_cmd: ipr command struct
8307 * Description: This function waits for adapter permission to run BIST,
8308 * then runs BIST. If the adapter does not give permission after a
8309 * reasonable time, we will reset the adapter anyway. The impact of
8310 * resetting the adapter without warning the adapter is the risk of
8311 * losing the persistent error log on the adapter. If the adapter is
8312 * reset while it is writing to the flash on the adapter, the flash
8313 * segment will have bad ECC and be zeroed.
8316 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8318 static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
8320 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8321 int rc = IPR_RC_JOB_RETURN;
8323 if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
8324 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
8325 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8327 ipr_cmd->job_step = ipr_reset_block_config_access;
8328 rc = IPR_RC_JOB_CONTINUE;
8335 * ipr_reset_alert - Alert the adapter of a pending reset
8336 * @ipr_cmd: ipr command struct
8338 * Description: This function alerts the adapter that it will be reset.
8339 * If memory space is not currently enabled, proceed directly
8340 * to running BIST on the adapter. The timer must always be started
8341 * so we guarantee we do not run BIST from ipr_isr.
8346 static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
8348 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8353 rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
8355 if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
8356 ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
8357 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
8358 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
8360 ipr_cmd->job_step = ipr_reset_block_config_access;
8363 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
8364 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
8367 return IPR_RC_JOB_RETURN;
8371 * ipr_reset_ucode_download_done - Microcode download completion
8372 * @ipr_cmd: ipr command struct
8374 * Description: This function unmaps the microcode download buffer.
8377 * IPR_RC_JOB_CONTINUE
8379 static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
8381 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8382 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8384 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
8385 sglist->num_sg, DMA_TO_DEVICE);
8387 ipr_cmd->job_step = ipr_reset_alert;
8388 return IPR_RC_JOB_CONTINUE;
8392 * ipr_reset_ucode_download - Download microcode to the adapter
8393 * @ipr_cmd: ipr command struct
8395 * Description: This function checks to see if it there is microcode
8396 * to download to the adapter. If there is, a download is performed.
8399 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8401 static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
8403 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8404 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8407 ipr_cmd->job_step = ipr_reset_alert;
8410 return IPR_RC_JOB_CONTINUE;
8412 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8413 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
8414 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
8415 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
8416 ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
8417 ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
8418 ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
8421 ipr_build_ucode_ioadl64(ipr_cmd, sglist);
8423 ipr_build_ucode_ioadl(ipr_cmd, sglist);
8424 ipr_cmd->job_step = ipr_reset_ucode_download_done;
8426 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
8427 IPR_WRITE_BUFFER_TIMEOUT);
8430 return IPR_RC_JOB_RETURN;
8434 * ipr_reset_shutdown_ioa - Shutdown the adapter
8435 * @ipr_cmd: ipr command struct
8437 * Description: This function issues an adapter shutdown of the
8438 * specified type to the specified adapter as part of the
8439 * adapter reset job.
8442 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
8444 static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
8446 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8447 enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
8448 unsigned long timeout;
8449 int rc = IPR_RC_JOB_CONTINUE;
8452 if (shutdown_type != IPR_SHUTDOWN_NONE &&
8453 !ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
8454 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
8455 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
8456 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
8457 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
8459 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
8460 timeout = IPR_SHUTDOWN_TIMEOUT;
8461 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
8462 timeout = IPR_INTERNAL_TIMEOUT;
8463 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
8464 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
8466 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
8468 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
8470 rc = IPR_RC_JOB_RETURN;
8471 ipr_cmd->job_step = ipr_reset_ucode_download;
8473 ipr_cmd->job_step = ipr_reset_alert;
8480 * ipr_reset_ioa_job - Adapter reset job
8481 * @ipr_cmd: ipr command struct
8483 * Description: This function is the job router for the adapter reset job.
8488 static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
8491 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8494 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
8496 if (ioa_cfg->reset_cmd != ipr_cmd) {
8498 * We are doing nested adapter resets and this is
8499 * not the current reset job.
8501 list_add_tail(&ipr_cmd->queue,
8502 &ipr_cmd->hrrq->hrrq_free_q);
8506 if (IPR_IOASC_SENSE_KEY(ioasc)) {
8507 rc = ipr_cmd->job_step_failed(ipr_cmd);
8508 if (rc == IPR_RC_JOB_RETURN)
8512 ipr_reinit_ipr_cmnd(ipr_cmd);
8513 ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
8514 rc = ipr_cmd->job_step(ipr_cmd);
8515 } while (rc == IPR_RC_JOB_CONTINUE);
8519 * _ipr_initiate_ioa_reset - Initiate an adapter reset
8520 * @ioa_cfg: ioa config struct
8521 * @job_step: first job step of reset job
8522 * @shutdown_type: shutdown type
8524 * Description: This function will initiate the reset of the given adapter
8525 * starting at the selected job step.
8526 * If the caller needs to wait on the completion of the reset,
8527 * the caller must sleep on the reset_wait_q.
8532 static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8533 int (*job_step) (struct ipr_cmnd *),
8534 enum ipr_shutdown_type shutdown_type)
8536 struct ipr_cmnd *ipr_cmd;
8539 ioa_cfg->in_reset_reload = 1;
8540 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8541 spin_lock(&ioa_cfg->hrrq[i]._lock);
8542 ioa_cfg->hrrq[i].allow_cmds = 0;
8543 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8546 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa)
8547 scsi_block_requests(ioa_cfg->host);
8549 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
8550 ioa_cfg->reset_cmd = ipr_cmd;
8551 ipr_cmd->job_step = job_step;
8552 ipr_cmd->u.shutdown_type = shutdown_type;
8554 ipr_reset_ioa_job(ipr_cmd);
8558 * ipr_initiate_ioa_reset - Initiate an adapter reset
8559 * @ioa_cfg: ioa config struct
8560 * @shutdown_type: shutdown type
8562 * Description: This function will initiate the reset of the given adapter.
8563 * If the caller needs to wait on the completion of the reset,
8564 * the caller must sleep on the reset_wait_q.
8569 static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
8570 enum ipr_shutdown_type shutdown_type)
8574 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead)
8577 if (ioa_cfg->in_reset_reload) {
8578 if (ioa_cfg->sdt_state == GET_DUMP)
8579 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
8580 else if (ioa_cfg->sdt_state == READ_DUMP)
8581 ioa_cfg->sdt_state = ABORT_DUMP;
8584 if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
8585 dev_err(&ioa_cfg->pdev->dev,
8586 "IOA taken offline - error recovery failed\n");
8588 ioa_cfg->reset_retries = 0;
8589 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8590 spin_lock(&ioa_cfg->hrrq[i]._lock);
8591 ioa_cfg->hrrq[i].ioa_is_dead = 1;
8592 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8596 if (ioa_cfg->in_ioa_bringdown) {
8597 ioa_cfg->reset_cmd = NULL;
8598 ioa_cfg->in_reset_reload = 0;
8599 ipr_fail_all_ops(ioa_cfg);
8600 wake_up_all(&ioa_cfg->reset_wait_q);
8602 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].removing_ioa) {
8603 spin_unlock_irq(ioa_cfg->host->host_lock);
8604 scsi_unblock_requests(ioa_cfg->host);
8605 spin_lock_irq(ioa_cfg->host->host_lock);
8609 ioa_cfg->in_ioa_bringdown = 1;
8610 shutdown_type = IPR_SHUTDOWN_NONE;
8614 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
8619 * ipr_reset_freeze - Hold off all I/O activity
8620 * @ipr_cmd: ipr command struct
8622 * Description: If the PCI slot is frozen, hold off all I/O
8623 * activity; then, as soon as the slot is available again,
8624 * initiate an adapter reset.
8626 static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
8628 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8631 /* Disallow new interrupts, avoid loop */
8632 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8633 spin_lock(&ioa_cfg->hrrq[i]._lock);
8634 ioa_cfg->hrrq[i].allow_interrupts = 0;
8635 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8638 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_pending_q);
8639 ipr_cmd->done = ipr_reset_ioa_job;
8640 return IPR_RC_JOB_RETURN;
8644 * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
8645 * @pdev: PCI device struct
8647 * Description: This routine is called to tell us that the PCI bus
8648 * is down. Can't do anything here, except put the device driver
8649 * into a holding pattern, waiting for the PCI bus to come back.
8651 static void ipr_pci_frozen(struct pci_dev *pdev)
8653 unsigned long flags = 0;
8654 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8656 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8657 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
8658 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8662 * ipr_pci_slot_reset - Called when PCI slot has been reset.
8663 * @pdev: PCI device struct
8665 * Description: This routine is called by the pci error recovery
8666 * code after the PCI slot has been reset, just before we
8667 * should resume normal operations.
8669 static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
8671 unsigned long flags = 0;
8672 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8674 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8675 if (ioa_cfg->needs_warm_reset)
8676 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8678 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
8680 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8681 return PCI_ERS_RESULT_RECOVERED;
8685 * ipr_pci_perm_failure - Called when PCI slot is dead for good.
8686 * @pdev: PCI device struct
8688 * Description: This routine is called when the PCI bus has
8689 * permanently failed.
8691 static void ipr_pci_perm_failure(struct pci_dev *pdev)
8693 unsigned long flags = 0;
8694 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
8697 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
8698 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
8699 ioa_cfg->sdt_state = ABORT_DUMP;
8700 ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES - 1;
8701 ioa_cfg->in_ioa_bringdown = 1;
8702 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8703 spin_lock(&ioa_cfg->hrrq[i]._lock);
8704 ioa_cfg->hrrq[i].allow_cmds = 0;
8705 spin_unlock(&ioa_cfg->hrrq[i]._lock);
8708 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8709 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
8713 * ipr_pci_error_detected - Called when a PCI error is detected.
8714 * @pdev: PCI device struct
8715 * @state: PCI channel state
8717 * Description: Called when a PCI error is detected.
8720 * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
8722 static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
8723 pci_channel_state_t state)
8726 case pci_channel_io_frozen:
8727 ipr_pci_frozen(pdev);
8728 return PCI_ERS_RESULT_NEED_RESET;
8729 case pci_channel_io_perm_failure:
8730 ipr_pci_perm_failure(pdev);
8731 return PCI_ERS_RESULT_DISCONNECT;
8736 return PCI_ERS_RESULT_NEED_RESET;
8740 * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
8741 * @ioa_cfg: ioa cfg struct
8743 * Description: This is the second phase of adapter intialization
8744 * This function takes care of initilizing the adapter to the point
8745 * where it can accept new commands.
8748 * 0 on success / -EIO on failure
8750 static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
8753 unsigned long host_lock_flags = 0;
8756 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8757 dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
8758 if (ioa_cfg->needs_hard_reset) {
8759 ioa_cfg->needs_hard_reset = 0;
8760 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
8762 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
8764 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8765 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
8766 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
8768 if (ioa_cfg->hrrq[IPR_INIT_HRRQ].ioa_is_dead) {
8770 } else if (ipr_invalid_adapter(ioa_cfg)) {
8774 dev_err(&ioa_cfg->pdev->dev,
8775 "Adapter not supported in this hardware configuration.\n");
8778 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
8785 * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
8786 * @ioa_cfg: ioa config struct
8791 static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8795 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8796 if (ioa_cfg->ipr_cmnd_list[i])
8797 pci_pool_free(ioa_cfg->ipr_cmd_pool,
8798 ioa_cfg->ipr_cmnd_list[i],
8799 ioa_cfg->ipr_cmnd_list_dma[i]);
8801 ioa_cfg->ipr_cmnd_list[i] = NULL;
8804 if (ioa_cfg->ipr_cmd_pool)
8805 pci_pool_destroy(ioa_cfg->ipr_cmd_pool);
8807 kfree(ioa_cfg->ipr_cmnd_list);
8808 kfree(ioa_cfg->ipr_cmnd_list_dma);
8809 ioa_cfg->ipr_cmnd_list = NULL;
8810 ioa_cfg->ipr_cmnd_list_dma = NULL;
8811 ioa_cfg->ipr_cmd_pool = NULL;
8815 * ipr_free_mem - Frees memory allocated for an adapter
8816 * @ioa_cfg: ioa cfg struct
8821 static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8825 kfree(ioa_cfg->res_entries);
8826 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
8827 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8828 ipr_free_cmd_blks(ioa_cfg);
8830 for (i = 0; i < ioa_cfg->hrrq_num; i++)
8831 pci_free_consistent(ioa_cfg->pdev,
8832 sizeof(u32) * ioa_cfg->hrrq[i].size,
8833 ioa_cfg->hrrq[i].host_rrq,
8834 ioa_cfg->hrrq[i].host_rrq_dma);
8836 pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size,
8837 ioa_cfg->u.cfg_table,
8838 ioa_cfg->cfg_table_dma);
8840 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8841 pci_free_consistent(ioa_cfg->pdev,
8842 sizeof(struct ipr_hostrcb),
8843 ioa_cfg->hostrcb[i],
8844 ioa_cfg->hostrcb_dma[i]);
8847 ipr_free_dump(ioa_cfg);
8848 kfree(ioa_cfg->trace);
8852 * ipr_free_all_resources - Free all allocated resources for an adapter.
8853 * @ipr_cmd: ipr command struct
8855 * This function frees all allocated resources for the
8856 * specified adapter.
8861 static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
8863 struct pci_dev *pdev = ioa_cfg->pdev;
8866 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
8867 ioa_cfg->intr_flag == IPR_USE_MSIX) {
8869 for (i = 0; i < ioa_cfg->nvectors; i++)
8870 free_irq(ioa_cfg->vectors_info[i].vec,
8873 free_irq(pdev->irq, &ioa_cfg->hrrq[0]);
8875 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
8876 pci_disable_msi(pdev);
8877 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
8878 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
8879 pci_disable_msix(pdev);
8880 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
8883 iounmap(ioa_cfg->hdw_dma_regs);
8884 pci_release_regions(pdev);
8885 ipr_free_mem(ioa_cfg);
8886 scsi_host_put(ioa_cfg->host);
8887 pci_disable_device(pdev);
8892 * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
8893 * @ioa_cfg: ioa config struct
8896 * 0 on success / -ENOMEM on allocation failure
8898 static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8900 struct ipr_cmnd *ipr_cmd;
8901 struct ipr_ioarcb *ioarcb;
8902 dma_addr_t dma_addr;
8903 int i, entries_each_hrrq, hrrq_id = 0;
8905 ioa_cfg->ipr_cmd_pool = pci_pool_create(IPR_NAME, ioa_cfg->pdev,
8906 sizeof(struct ipr_cmnd), 512, 0);
8908 if (!ioa_cfg->ipr_cmd_pool)
8911 ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
8912 ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
8914 if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
8915 ipr_free_cmd_blks(ioa_cfg);
8919 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
8920 if (ioa_cfg->hrrq_num > 1) {
8922 entries_each_hrrq = IPR_NUM_INTERNAL_CMD_BLKS;
8923 ioa_cfg->hrrq[i].min_cmd_id = 0;
8924 ioa_cfg->hrrq[i].max_cmd_id =
8925 (entries_each_hrrq - 1);
8928 IPR_NUM_BASE_CMD_BLKS/
8929 (ioa_cfg->hrrq_num - 1);
8930 ioa_cfg->hrrq[i].min_cmd_id =
8931 IPR_NUM_INTERNAL_CMD_BLKS +
8932 (i - 1) * entries_each_hrrq;
8933 ioa_cfg->hrrq[i].max_cmd_id =
8934 (IPR_NUM_INTERNAL_CMD_BLKS +
8935 i * entries_each_hrrq - 1);
8938 entries_each_hrrq = IPR_NUM_CMD_BLKS;
8939 ioa_cfg->hrrq[i].min_cmd_id = 0;
8940 ioa_cfg->hrrq[i].max_cmd_id = (entries_each_hrrq - 1);
8942 ioa_cfg->hrrq[i].size = entries_each_hrrq;
8945 BUG_ON(ioa_cfg->hrrq_num == 0);
8947 i = IPR_NUM_CMD_BLKS -
8948 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id - 1;
8950 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].size += i;
8951 ioa_cfg->hrrq[ioa_cfg->hrrq_num - 1].max_cmd_id += i;
8954 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8955 ipr_cmd = pci_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
8958 ipr_free_cmd_blks(ioa_cfg);
8962 memset(ipr_cmd, 0, sizeof(*ipr_cmd));
8963 ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
8964 ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
8966 ioarcb = &ipr_cmd->ioarcb;
8967 ipr_cmd->dma_addr = dma_addr;
8969 ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
8971 ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
8973 ioarcb->host_response_handle = cpu_to_be32(i << 2);
8974 if (ioa_cfg->sis64) {
8975 ioarcb->u.sis64_addr_data.data_ioadl_addr =
8976 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
8977 ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
8978 cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
8980 ioarcb->write_ioadl_addr =
8981 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
8982 ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
8983 ioarcb->ioasa_host_pci_addr =
8984 cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
8986 ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
8987 ipr_cmd->cmd_index = i;
8988 ipr_cmd->ioa_cfg = ioa_cfg;
8989 ipr_cmd->sense_buffer_dma = dma_addr +
8990 offsetof(struct ipr_cmnd, sense_buffer);
8992 ipr_cmd->ioarcb.cmd_pkt.hrrq_id = hrrq_id;
8993 ipr_cmd->hrrq = &ioa_cfg->hrrq[hrrq_id];
8994 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
8995 if (i >= ioa_cfg->hrrq[hrrq_id].max_cmd_id)
9003 * ipr_alloc_mem - Allocate memory for an adapter
9004 * @ioa_cfg: ioa config struct
9007 * 0 on success / non-zero for error
9009 static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
9011 struct pci_dev *pdev = ioa_cfg->pdev;
9012 int i, rc = -ENOMEM;
9015 ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
9016 ioa_cfg->max_devs_supported, GFP_KERNEL);
9018 if (!ioa_cfg->res_entries)
9021 for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
9022 list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
9023 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
9026 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
9027 sizeof(struct ipr_misc_cbs),
9028 &ioa_cfg->vpd_cbs_dma);
9030 if (!ioa_cfg->vpd_cbs)
9031 goto out_free_res_entries;
9033 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9034 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_free_q);
9035 INIT_LIST_HEAD(&ioa_cfg->hrrq[i].hrrq_pending_q);
9036 spin_lock_init(&ioa_cfg->hrrq[i]._lock);
9038 ioa_cfg->hrrq[i].lock = ioa_cfg->host->host_lock;
9040 ioa_cfg->hrrq[i].lock = &ioa_cfg->hrrq[i]._lock;
9043 if (ipr_alloc_cmd_blks(ioa_cfg))
9044 goto out_free_vpd_cbs;
9046 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9047 ioa_cfg->hrrq[i].host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
9048 sizeof(u32) * ioa_cfg->hrrq[i].size,
9049 &ioa_cfg->hrrq[i].host_rrq_dma);
9051 if (!ioa_cfg->hrrq[i].host_rrq) {
9053 pci_free_consistent(pdev,
9054 sizeof(u32) * ioa_cfg->hrrq[i].size,
9055 ioa_cfg->hrrq[i].host_rrq,
9056 ioa_cfg->hrrq[i].host_rrq_dma);
9057 goto out_ipr_free_cmd_blocks;
9059 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
9062 ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
9063 ioa_cfg->cfg_table_size,
9064 &ioa_cfg->cfg_table_dma);
9066 if (!ioa_cfg->u.cfg_table)
9067 goto out_free_host_rrq;
9069 for (i = 0; i < IPR_NUM_HCAMS; i++) {
9070 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
9071 sizeof(struct ipr_hostrcb),
9072 &ioa_cfg->hostrcb_dma[i]);
9074 if (!ioa_cfg->hostrcb[i])
9075 goto out_free_hostrcb_dma;
9077 ioa_cfg->hostrcb[i]->hostrcb_dma =
9078 ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
9079 ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
9080 list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
9083 ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
9084 IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
9086 if (!ioa_cfg->trace)
9087 goto out_free_hostrcb_dma;
9094 out_free_hostrcb_dma:
9096 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
9097 ioa_cfg->hostrcb[i],
9098 ioa_cfg->hostrcb_dma[i]);
9100 pci_free_consistent(pdev, ioa_cfg->cfg_table_size,
9101 ioa_cfg->u.cfg_table,
9102 ioa_cfg->cfg_table_dma);
9104 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9105 pci_free_consistent(pdev,
9106 sizeof(u32) * ioa_cfg->hrrq[i].size,
9107 ioa_cfg->hrrq[i].host_rrq,
9108 ioa_cfg->hrrq[i].host_rrq_dma);
9110 out_ipr_free_cmd_blocks:
9111 ipr_free_cmd_blks(ioa_cfg);
9113 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
9114 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
9115 out_free_res_entries:
9116 kfree(ioa_cfg->res_entries);
9121 * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
9122 * @ioa_cfg: ioa config struct
9127 static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
9131 for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
9132 ioa_cfg->bus_attr[i].bus = i;
9133 ioa_cfg->bus_attr[i].qas_enabled = 0;
9134 ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
9135 if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
9136 ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
9138 ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
9143 * ipr_init_ioa_cfg - Initialize IOA config struct
9144 * @ioa_cfg: ioa config struct
9145 * @host: scsi host struct
9146 * @pdev: PCI dev struct
9151 static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
9152 struct Scsi_Host *host, struct pci_dev *pdev)
9154 const struct ipr_interrupt_offsets *p;
9155 struct ipr_interrupts *t;
9158 ioa_cfg->host = host;
9159 ioa_cfg->pdev = pdev;
9160 ioa_cfg->log_level = ipr_log_level;
9161 ioa_cfg->doorbell = IPR_DOORBELL;
9162 sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
9163 sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
9164 sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
9165 sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
9166 sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
9167 sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
9169 INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
9170 INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
9171 INIT_LIST_HEAD(&ioa_cfg->free_res_q);
9172 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9173 INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
9174 init_waitqueue_head(&ioa_cfg->reset_wait_q);
9175 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9176 ioa_cfg->sdt_state = INACTIVE;
9178 ipr_initialize_bus_attr(ioa_cfg);
9179 ioa_cfg->max_devs_supported = ipr_max_devs;
9181 if (ioa_cfg->sis64) {
9182 host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
9183 host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
9184 if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
9185 ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
9187 host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
9188 host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
9189 if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
9190 ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
9192 host->max_channel = IPR_MAX_BUS_TO_SCAN;
9193 host->unique_id = host->host_no;
9194 host->max_cmd_len = IPR_MAX_CDB_LEN;
9195 host->can_queue = ioa_cfg->max_cmds;
9196 pci_set_drvdata(pdev, ioa_cfg);
9198 p = &ioa_cfg->chip_cfg->regs;
9200 base = ioa_cfg->hdw_dma_regs;
9202 t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
9203 t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
9204 t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
9205 t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
9206 t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
9207 t->clr_interrupt_reg = base + p->clr_interrupt_reg;
9208 t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
9209 t->sense_interrupt_reg = base + p->sense_interrupt_reg;
9210 t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
9211 t->ioarrin_reg = base + p->ioarrin_reg;
9212 t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
9213 t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
9214 t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
9215 t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
9216 t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
9217 t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
9219 if (ioa_cfg->sis64) {
9220 t->init_feedback_reg = base + p->init_feedback_reg;
9221 t->dump_addr_reg = base + p->dump_addr_reg;
9222 t->dump_data_reg = base + p->dump_data_reg;
9223 t->endian_swap_reg = base + p->endian_swap_reg;
9228 * ipr_get_chip_info - Find adapter chip information
9229 * @dev_id: PCI device id struct
9232 * ptr to chip information on success / NULL on failure
9234 static const struct ipr_chip_t *
9235 ipr_get_chip_info(const struct pci_device_id *dev_id)
9239 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
9240 if (ipr_chip[i].vendor == dev_id->vendor &&
9241 ipr_chip[i].device == dev_id->device)
9242 return &ipr_chip[i];
9246 static int ipr_enable_msix(struct ipr_ioa_cfg *ioa_cfg)
9248 struct msix_entry entries[IPR_MAX_MSIX_VECTORS];
9249 int i, err, vectors;
9251 for (i = 0; i < ARRAY_SIZE(entries); ++i)
9252 entries[i].entry = i;
9254 vectors = ipr_number_of_msix;
9256 while ((err = pci_enable_msix(ioa_cfg->pdev, entries, vectors)) > 0)
9260 pci_disable_msix(ioa_cfg->pdev);
9265 for (i = 0; i < vectors; i++)
9266 ioa_cfg->vectors_info[i].vec = entries[i].vector;
9267 ioa_cfg->nvectors = vectors;
9273 static int ipr_enable_msi(struct ipr_ioa_cfg *ioa_cfg)
9275 int i, err, vectors;
9277 vectors = ipr_number_of_msix;
9279 while ((err = pci_enable_msi_block(ioa_cfg->pdev, vectors)) > 0)
9283 pci_disable_msi(ioa_cfg->pdev);
9288 for (i = 0; i < vectors; i++)
9289 ioa_cfg->vectors_info[i].vec = ioa_cfg->pdev->irq + i;
9290 ioa_cfg->nvectors = vectors;
9296 static void name_msi_vectors(struct ipr_ioa_cfg *ioa_cfg)
9298 int vec_idx, n = sizeof(ioa_cfg->vectors_info[0].desc) - 1;
9300 for (vec_idx = 0; vec_idx < ioa_cfg->nvectors; vec_idx++) {
9301 snprintf(ioa_cfg->vectors_info[vec_idx].desc, n,
9302 "host%d-%d", ioa_cfg->host->host_no, vec_idx);
9303 ioa_cfg->vectors_info[vec_idx].
9304 desc[strlen(ioa_cfg->vectors_info[vec_idx].desc)] = 0;
9308 static int ipr_request_other_msi_irqs(struct ipr_ioa_cfg *ioa_cfg)
9312 for (i = 1; i < ioa_cfg->nvectors; i++) {
9313 rc = request_irq(ioa_cfg->vectors_info[i].vec,
9316 ioa_cfg->vectors_info[i].desc,
9320 free_irq(ioa_cfg->vectors_info[i].vec,
9329 * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
9330 * @pdev: PCI device struct
9332 * Description: Simply set the msi_received flag to 1 indicating that
9333 * Message Signaled Interrupts are supported.
9336 * 0 on success / non-zero on failure
9338 static irqreturn_t ipr_test_intr(int irq, void *devp)
9340 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
9341 unsigned long lock_flags = 0;
9342 irqreturn_t rc = IRQ_HANDLED;
9344 dev_info(&ioa_cfg->pdev->dev, "Received IRQ : %d\n", irq);
9345 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9347 ioa_cfg->msi_received = 1;
9348 wake_up(&ioa_cfg->msi_wait_q);
9350 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9355 * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
9356 * @pdev: PCI device struct
9358 * Description: The return value from pci_enable_msi() can not always be
9359 * trusted. This routine sets up and initiates a test interrupt to determine
9360 * if the interrupt is received via the ipr_test_intr() service routine.
9361 * If the tests fails, the driver will fall back to LSI.
9364 * 0 on success / non-zero on failure
9366 static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
9369 volatile u32 int_reg;
9370 unsigned long lock_flags = 0;
9374 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9375 init_waitqueue_head(&ioa_cfg->msi_wait_q);
9376 ioa_cfg->msi_received = 0;
9377 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9378 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
9379 int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
9380 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9382 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9383 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9385 rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
9387 dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
9389 } else if (ipr_debug)
9390 dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
9392 writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
9393 int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
9394 wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
9395 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9396 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9398 if (!ioa_cfg->msi_received) {
9399 /* MSI test failed */
9400 dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
9402 } else if (ipr_debug)
9403 dev_info(&pdev->dev, "MSI test succeeded.\n");
9405 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9407 if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9408 free_irq(ioa_cfg->vectors_info[0].vec, ioa_cfg);
9410 free_irq(pdev->irq, ioa_cfg);
9417 /* ipr_probe_ioa - Allocates memory and does first stage of initialization
9418 * @pdev: PCI device struct
9419 * @dev_id: PCI device id struct
9422 * 0 on success / non-zero on failure
9424 static int ipr_probe_ioa(struct pci_dev *pdev,
9425 const struct pci_device_id *dev_id)
9427 struct ipr_ioa_cfg *ioa_cfg;
9428 struct Scsi_Host *host;
9429 unsigned long ipr_regs_pci;
9430 void __iomem *ipr_regs;
9431 int rc = PCIBIOS_SUCCESSFUL;
9432 volatile u32 mask, uproc, interrupts;
9433 unsigned long lock_flags, driver_lock_flags;
9437 if ((rc = pci_enable_device(pdev))) {
9438 dev_err(&pdev->dev, "Cannot enable adapter\n");
9442 dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
9444 host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
9447 dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
9452 ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
9453 memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
9454 ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
9456 ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
9458 if (!ioa_cfg->ipr_chip) {
9459 dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
9460 dev_id->vendor, dev_id->device);
9461 goto out_scsi_host_put;
9464 /* set SIS 32 or SIS 64 */
9465 ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
9466 ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
9467 ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
9468 ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
9470 if (ipr_transop_timeout)
9471 ioa_cfg->transop_timeout = ipr_transop_timeout;
9472 else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
9473 ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
9475 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
9477 ioa_cfg->revid = pdev->revision;
9479 ipr_regs_pci = pci_resource_start(pdev, 0);
9481 rc = pci_request_regions(pdev, IPR_NAME);
9484 "Couldn't register memory range of registers\n");
9485 goto out_scsi_host_put;
9488 ipr_regs = pci_ioremap_bar(pdev, 0);
9492 "Couldn't map memory range of registers\n");
9494 goto out_release_regions;
9497 ioa_cfg->hdw_dma_regs = ipr_regs;
9498 ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
9499 ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
9501 ipr_init_ioa_cfg(ioa_cfg, host, pdev);
9503 pci_set_master(pdev);
9505 if (ioa_cfg->sis64) {
9506 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
9508 dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n");
9509 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
9513 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
9516 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
9520 rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
9521 ioa_cfg->chip_cfg->cache_line_size);
9523 if (rc != PCIBIOS_SUCCESSFUL) {
9524 dev_err(&pdev->dev, "Write of cache line size failed\n");
9529 if (ipr_number_of_msix > IPR_MAX_MSIX_VECTORS) {
9530 dev_err(&pdev->dev, "The max number of MSIX is %d\n",
9531 IPR_MAX_MSIX_VECTORS);
9532 ipr_number_of_msix = IPR_MAX_MSIX_VECTORS;
9535 if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
9536 ipr_enable_msix(ioa_cfg) == 0)
9537 ioa_cfg->intr_flag = IPR_USE_MSIX;
9538 else if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI &&
9539 ipr_enable_msi(ioa_cfg) == 0)
9540 ioa_cfg->intr_flag = IPR_USE_MSI;
9542 ioa_cfg->intr_flag = IPR_USE_LSI;
9543 ioa_cfg->nvectors = 1;
9544 dev_info(&pdev->dev, "Cannot enable MSI.\n");
9547 if (ioa_cfg->intr_flag == IPR_USE_MSI ||
9548 ioa_cfg->intr_flag == IPR_USE_MSIX) {
9549 rc = ipr_test_msi(ioa_cfg, pdev);
9550 if (rc == -EOPNOTSUPP) {
9551 if (ioa_cfg->intr_flag == IPR_USE_MSI) {
9552 ioa_cfg->intr_flag &= ~IPR_USE_MSI;
9553 pci_disable_msi(pdev);
9554 } else if (ioa_cfg->intr_flag == IPR_USE_MSIX) {
9555 ioa_cfg->intr_flag &= ~IPR_USE_MSIX;
9556 pci_disable_msix(pdev);
9559 ioa_cfg->intr_flag = IPR_USE_LSI;
9560 ioa_cfg->nvectors = 1;
9563 goto out_msi_disable;
9565 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9566 dev_info(&pdev->dev,
9567 "Request for %d MSIs succeeded with starting IRQ: %d\n",
9568 ioa_cfg->nvectors, pdev->irq);
9569 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9570 dev_info(&pdev->dev,
9571 "Request for %d MSIXs succeeded.",
9576 ioa_cfg->hrrq_num = min3(ioa_cfg->nvectors,
9577 (unsigned int)num_online_cpus(),
9578 (unsigned int)IPR_MAX_HRRQ_NUM);
9580 /* Save away PCI config space for use following IOA reset */
9581 rc = pci_save_state(pdev);
9583 if (rc != PCIBIOS_SUCCESSFUL) {
9584 dev_err(&pdev->dev, "Failed to save PCI config space\n");
9586 goto out_msi_disable;
9589 if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
9590 goto out_msi_disable;
9592 if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
9593 goto out_msi_disable;
9596 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
9597 + ((sizeof(struct ipr_config_table_entry64)
9598 * ioa_cfg->max_devs_supported)));
9600 ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
9601 + ((sizeof(struct ipr_config_table_entry)
9602 * ioa_cfg->max_devs_supported)));
9604 rc = ipr_alloc_mem(ioa_cfg);
9607 "Couldn't allocate enough memory for device driver!\n");
9608 goto out_msi_disable;
9612 * If HRRQ updated interrupt is not masked, or reset alert is set,
9613 * the card is in an unknown state and needs a hard reset
9615 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
9616 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
9617 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
9618 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
9619 ioa_cfg->needs_hard_reset = 1;
9620 if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
9621 ioa_cfg->needs_hard_reset = 1;
9622 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
9623 ioa_cfg->ioa_unit_checked = 1;
9625 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9626 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
9627 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9629 if (ioa_cfg->intr_flag == IPR_USE_MSI
9630 || ioa_cfg->intr_flag == IPR_USE_MSIX) {
9631 name_msi_vectors(ioa_cfg);
9632 rc = request_irq(ioa_cfg->vectors_info[0].vec, ipr_isr,
9634 ioa_cfg->vectors_info[0].desc,
9637 rc = ipr_request_other_msi_irqs(ioa_cfg);
9639 rc = request_irq(pdev->irq, ipr_isr,
9641 IPR_NAME, &ioa_cfg->hrrq[0]);
9644 dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
9649 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
9650 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
9651 ioa_cfg->needs_warm_reset = 1;
9652 ioa_cfg->reset = ipr_reset_slot_reset;
9654 ioa_cfg->reset = ipr_reset_start_bist;
9656 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
9657 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
9658 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
9665 ipr_free_mem(ioa_cfg);
9667 if (ioa_cfg->intr_flag == IPR_USE_MSI)
9668 pci_disable_msi(pdev);
9669 else if (ioa_cfg->intr_flag == IPR_USE_MSIX)
9670 pci_disable_msix(pdev);
9673 out_release_regions:
9674 pci_release_regions(pdev);
9676 scsi_host_put(host);
9678 pci_disable_device(pdev);
9683 * ipr_scan_vsets - Scans for VSET devices
9684 * @ioa_cfg: ioa config struct
9686 * Description: Since the VSET resources do not follow SAM in that we can have
9687 * sparse LUNs with no LUN 0, we have to scan for these ourselves.
9692 static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
9696 for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
9697 for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++)
9698 scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
9702 * ipr_initiate_ioa_bringdown - Bring down an adapter
9703 * @ioa_cfg: ioa config struct
9704 * @shutdown_type: shutdown type
9706 * Description: This function will initiate bringing down the adapter.
9707 * This consists of issuing an IOA shutdown to the adapter
9708 * to flush the cache, and running BIST.
9709 * If the caller needs to wait on the completion of the reset,
9710 * the caller must sleep on the reset_wait_q.
9715 static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
9716 enum ipr_shutdown_type shutdown_type)
9719 if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
9720 ioa_cfg->sdt_state = ABORT_DUMP;
9721 ioa_cfg->reset_retries = 0;
9722 ioa_cfg->in_ioa_bringdown = 1;
9723 ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
9728 * __ipr_remove - Remove a single adapter
9729 * @pdev: pci device struct
9731 * Adapter hot plug remove entry point.
9736 static void __ipr_remove(struct pci_dev *pdev)
9738 unsigned long host_lock_flags = 0;
9739 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9741 unsigned long driver_lock_flags;
9744 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9745 while (ioa_cfg->in_reset_reload) {
9746 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9747 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9748 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9751 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9752 spin_lock(&ioa_cfg->hrrq[i]._lock);
9753 ioa_cfg->hrrq[i].removing_ioa = 1;
9754 spin_unlock(&ioa_cfg->hrrq[i]._lock);
9757 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9759 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9760 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9761 flush_work(&ioa_cfg->work_q);
9762 INIT_LIST_HEAD(&ioa_cfg->used_res_q);
9763 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
9765 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
9766 list_del(&ioa_cfg->queue);
9767 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
9769 if (ioa_cfg->sdt_state == ABORT_DUMP)
9770 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
9771 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
9773 ipr_free_all_resources(ioa_cfg);
9779 * ipr_remove - IOA hot plug remove entry point
9780 * @pdev: pci device struct
9782 * Adapter hot plug remove entry point.
9787 static void ipr_remove(struct pci_dev *pdev)
9789 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9793 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9795 ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
9797 scsi_remove_host(ioa_cfg->host);
9805 * ipr_probe - Adapter hot plug add entry point
9808 * 0 on success / non-zero on failure
9810 static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
9812 struct ipr_ioa_cfg *ioa_cfg;
9815 rc = ipr_probe_ioa(pdev, dev_id);
9820 ioa_cfg = pci_get_drvdata(pdev);
9821 rc = ipr_probe_ioa_part2(ioa_cfg);
9828 rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
9835 rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
9839 scsi_remove_host(ioa_cfg->host);
9844 rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
9848 ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
9850 scsi_remove_host(ioa_cfg->host);
9855 scsi_scan_host(ioa_cfg->host);
9856 ipr_scan_vsets(ioa_cfg);
9857 scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
9858 ioa_cfg->allow_ml_add_del = 1;
9859 ioa_cfg->host->max_channel = IPR_VSET_BUS;
9860 ioa_cfg->iopoll_weight = ioa_cfg->chip_cfg->iopoll_weight;
9862 if (blk_iopoll_enabled && ioa_cfg->iopoll_weight &&
9863 ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
9864 for (i = 1; i < ioa_cfg->hrrq_num; i++) {
9865 blk_iopoll_init(&ioa_cfg->hrrq[i].iopoll,
9866 ioa_cfg->iopoll_weight, ipr_iopoll);
9867 blk_iopoll_enable(&ioa_cfg->hrrq[i].iopoll);
9871 schedule_work(&ioa_cfg->work_q);
9876 * ipr_shutdown - Shutdown handler.
9877 * @pdev: pci device struct
9879 * This function is invoked upon system shutdown/reboot. It will issue
9880 * an adapter shutdown to the adapter to flush the write cache.
9885 static void ipr_shutdown(struct pci_dev *pdev)
9887 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
9888 unsigned long lock_flags = 0;
9891 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9892 if (blk_iopoll_enabled && ioa_cfg->iopoll_weight &&
9893 ioa_cfg->sis64 && ioa_cfg->nvectors > 1) {
9894 ioa_cfg->iopoll_weight = 0;
9895 for (i = 1; i < ioa_cfg->hrrq_num; i++)
9896 blk_iopoll_disable(&ioa_cfg->hrrq[i].iopoll);
9899 while (ioa_cfg->in_reset_reload) {
9900 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9901 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9902 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
9905 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
9906 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
9907 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
9910 static struct pci_device_id ipr_pci_table[] = {
9911 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9912 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
9913 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9914 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
9915 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9916 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
9917 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
9918 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
9919 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9920 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
9921 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9922 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
9923 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9924 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
9925 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
9926 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
9927 IPR_USE_LONG_TRANSOP_TIMEOUT },
9928 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9929 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
9930 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9931 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9932 IPR_USE_LONG_TRANSOP_TIMEOUT },
9933 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
9934 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9935 IPR_USE_LONG_TRANSOP_TIMEOUT },
9936 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9937 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
9938 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9939 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
9940 IPR_USE_LONG_TRANSOP_TIMEOUT},
9941 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
9942 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
9943 IPR_USE_LONG_TRANSOP_TIMEOUT },
9944 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9945 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
9946 IPR_USE_LONG_TRANSOP_TIMEOUT },
9947 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9948 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
9949 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9950 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
9951 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
9952 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
9953 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
9954 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
9955 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
9956 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9957 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
9958 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9959 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
9960 IPR_USE_LONG_TRANSOP_TIMEOUT },
9961 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
9962 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
9963 IPR_USE_LONG_TRANSOP_TIMEOUT },
9964 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9965 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
9966 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9967 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
9968 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9969 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
9970 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9971 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C0, 0, 0, 0 },
9972 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9973 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
9974 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9975 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
9976 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9977 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
9978 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9979 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
9980 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9981 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
9982 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9983 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
9984 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9985 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
9986 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9987 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D5, 0, 0, 0 },
9988 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9989 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D6, 0, 0, 0 },
9990 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9991 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D7, 0, 0, 0 },
9992 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9993 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D8, 0, 0, 0 },
9994 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9995 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57D9, 0, 0, 0 },
9996 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9997 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EB, 0, 0, 0 },
9998 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
9999 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EC, 0, 0, 0 },
10000 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10001 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57ED, 0, 0, 0 },
10002 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10003 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EE, 0, 0, 0 },
10004 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10005 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57EF, 0, 0, 0 },
10006 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
10007 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57F0, 0, 0, 0 },
10010 MODULE_DEVICE_TABLE(pci, ipr_pci_table);
10012 static const struct pci_error_handlers ipr_err_handler = {
10013 .error_detected = ipr_pci_error_detected,
10014 .slot_reset = ipr_pci_slot_reset,
10017 static struct pci_driver ipr_driver = {
10019 .id_table = ipr_pci_table,
10020 .probe = ipr_probe,
10021 .remove = ipr_remove,
10022 .shutdown = ipr_shutdown,
10023 .err_handler = &ipr_err_handler,
10027 * ipr_halt_done - Shutdown prepare completion
10032 static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
10034 list_add_tail(&ipr_cmd->queue, &ipr_cmd->hrrq->hrrq_free_q);
10038 * ipr_halt - Issue shutdown prepare to all adapters
10041 * NOTIFY_OK on success / NOTIFY_DONE on failure
10043 static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
10045 struct ipr_cmnd *ipr_cmd;
10046 struct ipr_ioa_cfg *ioa_cfg;
10047 unsigned long flags = 0, driver_lock_flags;
10049 if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
10050 return NOTIFY_DONE;
10052 spin_lock_irqsave(&ipr_driver_lock, driver_lock_flags);
10054 list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
10055 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
10056 if (!ioa_cfg->hrrq[IPR_INIT_HRRQ].allow_cmds) {
10057 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10061 ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
10062 ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
10063 ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
10064 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
10065 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
10067 ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
10068 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
10070 spin_unlock_irqrestore(&ipr_driver_lock, driver_lock_flags);
10075 static struct notifier_block ipr_notifier = {
10080 * ipr_init - Module entry point
10083 * 0 on success / negative value on failure
10085 static int __init ipr_init(void)
10087 ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
10088 IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
10090 register_reboot_notifier(&ipr_notifier);
10091 return pci_register_driver(&ipr_driver);
10095 * ipr_exit - Module unload
10097 * Module unload entry point.
10102 static void __exit ipr_exit(void)
10104 unregister_reboot_notifier(&ipr_notifier);
10105 pci_unregister_driver(&ipr_driver);
10108 module_init(ipr_init);
10109 module_exit(ipr_exit);